diff options
author | Xingyu Wu <xingyu.wu@starfivetech.com> | 2023-09-06 10:14:01 +0300 |
---|---|---|
committer | Xingyu Wu <xingyu.wu@starfivetech.com> | 2023-09-07 04:34:13 +0300 |
commit | fe15334eb1ad300a0b094c1ce9968c4ba4a200c6 (patch) | |
tree | 7cbeaef211fa53f0b2baf63efcbc08f1d3d80cec | |
parent | 67df54127e38f1351c38293abd08d817e33394c7 (diff) | |
download | u-boot-fe15334eb1ad300a0b094c1ce9968c4ba4a200c6.tar.xz |
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>
-rw-r--r-- | common/Kconfig.boot | 7 | ||||
-rw-r--r-- | common/autoboot.c | 59 | ||||
-rw-r--r-- | common/main.c | 9 | ||||
-rw-r--r-- | include/autoboot.h | 1 |
4 files changed, 75 insertions, 1 deletions
diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 902a5b8fbe..ac0c9d3614 100644 --- a/common/Kconfig.boot +++ b/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 diff --git a/common/autoboot.c b/common/autoboot.c index 5bb2e19089..c2210be7ae 100644 --- a/common/autoboot.c +++ b/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; +} diff --git a/common/main.c b/common/main.c index ae5bcdb32f..06312c87bf 100644 --- a/common/main.c +++ b/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"); diff --git a/include/autoboot.h b/include/autoboot.h index d6915dd0cc..26dd9c1700 100644 --- a/include/autoboot.h +++ b/include/autoboot.h @@ -79,4 +79,5 @@ static inline void autoboot_command(const char *s) } #endif +int autofastboot_command(void); #endif |