Преглед на файлове

common: autoboot: Add auto-fastboot on StarFive SoC

Add auto-fastboot function before autoboot on StarFive SoC
and add a config to enable or disable this.

In the auto-fastboot, it check a environment flag of 'fb_sf_completed'
first. The flag is NULL and then the fastboot will work.
The flag will be set from USB tool to indicate done after flashing the
image.

Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
Xingyu Wu преди 8 месеца
родител
ревизия
fe15334eb1
променени са 4 файла, в които са добавени 75 реда и са изтрити 1 реда
  1. 7 0
      common/Kconfig.boot
  2. 59 0
      common/autoboot.c
  3. 8 1
      common/main.c
  4. 1 0
      include/autoboot.h

+ 7 - 0
common/Kconfig.boot

@@ -921,6 +921,13 @@ config AUTOBOOT_MENU_SHOW
 
 endmenu
 
+config AUTO_FASTBOOT_STARFIVE
+	bool "Auto fastboot on StarFive SoCs"
+	default 0
+	depends on CMD_FASTBOOT && FASTBOOT && STARFIVE_JH7110
+	help
+	  This enables the function of auto-fastboot before autoboot on StarFive SoC.
+
 config USE_BOOTARGS
 	bool "Enable boot arguments"
 	help

+ 59 - 0
common/autoboot.c

@@ -499,3 +499,62 @@ void autoboot_command(const char *s)
 			run_command_list(s, -1, 0);
 	}
 }
+
+static int abortfastboot(int bootdelay)
+{
+	int abort = 0;
+	unsigned long ts;
+
+	printf("Hit any key to stop auto-fastboot: %2d ", bootdelay);
+
+	/*
+	 * Check if key already pressed
+	 */
+	if (tstc()) {	/* we got a key press	*/
+		getchar();	/* consume input	*/
+		puts("\b\b\b 0");
+		abort = 1;	/* don't auto fastboot	*/
+	}
+
+	while ((bootdelay > 0) && (!abort)) {
+		--bootdelay;
+		/* delay 1000 ms */
+		ts = get_timer(0);
+		do {
+			if (tstc()) {	/* we got a key press	*/
+				int key;
+
+				abort  = 1;	/* don't auto fastboot	*/
+				bootdelay = 0;	/* no more delay	*/
+				key = getchar();/* consume input	*/
+				break;
+			}
+			udelay(10000);
+		} while (!abort && get_timer(ts) < 1000);
+
+		printf("\b\b\b%2d ", bootdelay);
+	}
+
+	putc('\n');
+
+	return abort;
+}
+
+int autofastboot_command(void)
+{
+	char *s = env_get("fb_sf_completed");
+
+	if (s != NULL) {
+		printf("EMMC had loaded img and do not use auto-fastboot.\n");
+		return -ENOENT; /* had loaded */
+	}
+
+	if (IS_ENABLED(CONFIG_USB_FUNCTION_FASTBOOT)) {
+		if (!abortfastboot(2)) {
+			s = "fastboot usb 0";
+			return run_command_list(s, -1, 0);
+		}
+	}
+
+	return -ENOENT;
+}

+ 8 - 1
common/main.c

@@ -39,6 +39,7 @@ static void run_preboot_environment_command(void)
 /* We come here after U-Boot is initialised and ready to process commands */
 void main_loop(void)
 {
+	int ret = 1;
 	const char *s;
 
 	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
@@ -61,7 +62,13 @@ void main_loop(void)
 	if (cli_process_fdt(&s))
 		cli_secure_boot_cmd(s);
 
-	autoboot_command(s);
+	if (IS_ENABLED(CONFIG_AUTO_FASTBOOT_STARFIVE)) {
+		ret = autofastboot_command();
+		s = bootdelay_process();
+	}
+
+	if (ret)
+		autoboot_command(s);
 
 	cli_loop();
 	panic("No CLI available");

+ 1 - 0
include/autoboot.h

@@ -79,4 +79,5 @@ static inline void autoboot_command(const char *s)
 }
 #endif
 
+int autofastboot_command(void);
 #endif