From 0c23a7095f57bc91df7980f7597f3fb84e223d57 Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Wed, 6 Sep 2023 16:58:00 +0800 Subject: driver: fastboot: Add new flag to load image file without partition Add new flag to load image file to preset address without partition. Signed-off-by: Xingyu Wu --- drivers/fastboot/fb_mmc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index cbb3f7b1de..d645ab4d86 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -513,6 +513,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, { struct blk_desc *dev_desc; struct disk_partition info = {0}; + char *fastboot_env; #ifdef CONFIG_FASTBOOT_MMC_BOOT_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) { @@ -606,6 +607,52 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, } #endif + /* Fastboot for StarFive JH7110 SoC */ + fastboot_env = env_get("fb_sf_flag"); + if (fastboot_env) { + dev_desc = blk_get_dev("mmc", 0); + if (!dev_desc) + return; + + if (strcmp(cmd, "all") == 0) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = 0x0; + info.size = 0x80000000; + info.blksz = 0x200; + } else if (strcmp(cmd, "part") == 0) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = 0x0; + info.size = 0x1000; + info.blksz = 0x200; + } else if (strcmp(cmd, "spl") == 0) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = 0x1000; + info.size = 0x1000; + info.blksz = 0x200; + } else if (strcmp(cmd, "uboot") == 0) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = 0x2000; + info.size = 0x2000; + info.blksz = 0x200; + } else if (strcmp(cmd, "image") == 0) { + fastboot_env = env_get("fb_sf_image_addr"); + if (fastboot_env) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = simple_strtoul(fastboot_env, NULL, 16); + info.size = 0x92000; + info.blksz = 0x200; + } + } else if (strcmp(cmd, "root") == 0) { + fastboot_env = env_get("fb_sf_root_addr"); + if (fastboot_env) { + strlcpy((char *)&info.name, cmd, sizeof(info.name)); + info.start = simple_strtoul(fastboot_env, NULL, 16); + info.size = 0x80000000; + info.blksz = 0x200; + } + } + } + if (!info.name[0] && fastboot_mmc_get_part_info(cmd, &dev_desc, &info, response) < 0) return; -- cgit v1.2.3 From 92543ed1f3dc9ec0f70767115170719e93f2833f Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Wed, 6 Sep 2023 16:59:49 +0800 Subject: drivers: fastboot: Add logical-block-size in getvar command Add a new parameter to get "logical-block-size" in getvar command. Signed-off-by: Xingyu Wu --- drivers/fastboot/fb_getvar.c | 18 ++++++++++++++++++ include/fastboot.h | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index d43f2cfee6..4e5536d611 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -31,6 +31,7 @@ static void getvar_partition_type(char *part_name, char *response); static void getvar_partition_size(char *part_name, char *response); #endif static void getvar_is_userspace(char *var_parameter, char *response); +static void getvar_logical_block_size(char *var_parameter, char *response); static const struct { const char *variable; @@ -81,6 +82,9 @@ static const struct { }, { .variable = "is-userspace", .dispatch = getvar_is_userspace + }, { + .variable = "logical-block-size", + .dispatch = getvar_logical_block_size } }; @@ -251,6 +255,20 @@ static void getvar_is_userspace(char *var_parameter, char *response) fastboot_okay("no", response); } +static void getvar_logical_block_size(char *var_parameter, char *response) +{ + struct blk_desc *dev_desc; + + dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { + pr_err("invalid mmc device\n"); + fastboot_fail("invalid mmc device", response); + return; + } + + fastboot_response("OKAY", response, "0x%08lx", dev_desc->blksz); +} + /** * fastboot_getvar() - Writes variable indicated by cmd_parameter to response. * diff --git a/include/fastboot.h b/include/fastboot.h index 57daaf1298..816c01b8fd 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -48,6 +48,7 @@ enum { FASTBOOT_COMMAND_ACMD, FASTBOOT_COMMAND_UCMD, #endif + FASTBOOT_COMMAND_BLOCK_SIZE, FASTBOOT_COMMAND_COUNT }; -- cgit v1.2.3 From 706fab8ccb290393c721c1f7e4e26bc0fa9e8d57 Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Wed, 6 Sep 2023 17:01:51 +0800 Subject: drivers: fastboot: Fix the error of writing sparse file with fastboot Add config for max block size to write in MMC with sparse file. Signed-off-by: Xingyu Wu --- configs/starfive_evb_defconfig | 11 +++++++++++ drivers/fastboot/Kconfig | 3 +++ drivers/fastboot/fb_mmc.c | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/configs/starfive_evb_defconfig b/configs/starfive_evb_defconfig index 1e879dabb3..fa4ce76af3 100644 --- a/configs/starfive_evb_defconfig +++ b/configs/starfive_evb_defconfig @@ -72,6 +72,17 @@ CONFIG_SPL_CLK_COMPOSITE_CCF=y CONFIG_CLK_CCF=y CONFIG_CLK_COMPOSITE_CCF=y CONFIG_SPL_CLK_JH7110=y +CONFIG_USB_FUNCTION_FASTBOOT=y +CONFIG_FASTBOOT_BUF_ADDR=0x60000000 +CONFIG_FASTBOOT_BUF_SIZE=0x80000000 +CONFIG_FASTBOOT_USB_DEV=1 +CONFIG_FASTBOOT_FLASH=y +CONFIG_FASTBOOT_UUU_SUPPORT=y +CONFIG_FASTBOOT_FLASH_MMC_DEV=0 +CONFIG_FASTBOOT_MMC_BOOT_SUPPORT=y +CONFIG_FASTBOOT_MMC_USER_SUPPORT=y +CONFIG_FASTBOOT_CMD_OEM_FORMAT=y +CONFIG_FASTBOOT_STARFIVE_MAX_BLK_WRITE=8192 CONFIG_SYS_I2C_DW=y CONFIG_MMC_HS200_SUPPORT=y CONFIG_SPL_MMC_HS200_SUPPORT=y diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 2d1836a80e..eb4bad24f5 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -212,6 +212,9 @@ config FASTBOOT_CMD_OEM_BOOTBUS Add support for the "oem bootbus" command from a client. This set the mmc boot configuration for the selecting eMMC device. +config FASTBOOT_STARFIVE_MAX_BLK_WRITE + int "The max size of block writing with sparse file on StarFive JH7110 SoC" + endif # FASTBOOT endmenu diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index d645ab4d86..ef51a5ed67 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -20,7 +20,11 @@ #include #include +#ifdef CONFIG_FASTBOOT_STARFIVE_MAX_BLK_WRITE +#define FASTBOOT_MAX_BLK_WRITE CONFIG_FASTBOOT_STARFIVE_MAX_BLK_WRITE /* = 8192 */ +#else #define FASTBOOT_MAX_BLK_WRITE 16384 +#endif #define BOOT_PARTITION_NAME "boot" -- cgit v1.2.3 From 67df54127e38f1351c38293abd08d817e33394c7 Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Wed, 6 Sep 2023 14:42:02 +0800 Subject: cmd: fastboot: Add presetting on StarFive SoC before fastboot Add the presetting about usb as device in fastboot function. Signed-off-by: Xingyu Wu --- cmd/fastboot.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/fastboot.c b/cmd/fastboot.c index 033a2c95e8..fa6863ccc7 100644 --- a/cmd/fastboot.c +++ b/cmd/fastboot.c @@ -43,6 +43,14 @@ static int do_fastboot_usb(int argc, char *const argv[], char *endp; int ret; +#ifdef CONFIG_FASTBOOT_STARFIVE_MAX_BLK_WRITE +#define RUN_FB_SF_PRESETTING \ + "fdt set /soc/usbdrd starfive,usb2-only <0x1>;" \ + "fdt set /soc/usbdrd/usb@10100000 dr_num_mode <0x2>;" + + run_command_list(RUN_FB_SF_PRESETTING, -1, 0); +#endif + if (argc < 2) return CMD_RET_USAGE; -- cgit v1.2.3 From fe15334eb1ad300a0b094c1ce9968c4ba4a200c6 Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Wed, 6 Sep 2023 15:14:01 +0800 Subject: 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 --- common/Kconfig.boot | 7 +++++++ common/autoboot.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ common/main.c | 9 +++++++- include/autoboot.h | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3