diff options
author | Andy Hu <andy.hu@starfivetech.com> | 2023-09-07 08:58:32 +0300 |
---|---|---|
committer | Andy Hu <andy.hu@starfivetech.com> | 2023-09-07 08:58:32 +0300 |
commit | 948a4d3f04542d4bda65d8bcb8537a63e92f7b61 (patch) | |
tree | 5ae49f24479408a70e11a7a879b9f5f2e3cf68ce | |
parent | a987443e92c93f0b623d9e28481d191775dc5a1b (diff) | |
parent | 081aa0e676156437fe6326402936c4d1f07818c1 (diff) | |
download | u-boot-948a4d3f04542d4bda65d8bcb8537a63e92f7b61.tar.xz |
Merge tag 'JH7110_515_SDK_v5.7.2' into vf2-devel
-rw-r--r-- | arch/riscv/dts/starfive_evb.dts | 1 | ||||
-rw-r--r-- | cmd/fastboot.c | 8 | ||||
-rw-r--r-- | common/Kconfig.boot | 7 | ||||
-rw-r--r-- | common/autoboot.c | 59 | ||||
-rw-r--r-- | common/main.c | 9 | ||||
-rw-r--r-- | configs/starfive_evb_defconfig | 11 | ||||
-rw-r--r-- | drivers/fastboot/Kconfig | 3 | ||||
-rw-r--r-- | drivers/fastboot/fb_getvar.c | 18 | ||||
-rw-r--r-- | drivers/fastboot/fb_mmc.c | 51 | ||||
-rw-r--r-- | drivers/usb/cdns3/cdns3-starfive.c | 57 | ||||
-rw-r--r-- | drivers/usb/cdns3/core.c | 6 | ||||
-rw-r--r-- | include/autoboot.h | 1 | ||||
-rw-r--r-- | include/fastboot.h | 1 |
13 files changed, 229 insertions, 3 deletions
diff --git a/arch/riscv/dts/starfive_evb.dts b/arch/riscv/dts/starfive_evb.dts index dc6f8b2097..58c3174572 100644 --- a/arch/riscv/dts/starfive_evb.dts +++ b/arch/riscv/dts/starfive_evb.dts @@ -312,6 +312,7 @@ <&rstgen RSTN_U0_CDN_USB_UTMI_APB>, <&rstgen RSTN_U0_PLDA_PCIE_APB>; reset-names = "pwrup","apb","axi","utmi", "phy"; + starfive,usb2-only = <0>; status = "okay"; }; 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; 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/configs/starfive_evb_defconfig b/configs/starfive_evb_defconfig index 96ca7efe18..11c95a86cf 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_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/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index cbb3f7b1de..ef51a5ed67 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -20,7 +20,11 @@ #include <linux/compat.h> #include <android_image.h> +#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" @@ -513,6 +517,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 +611,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; diff --git a/drivers/usb/cdns3/cdns3-starfive.c b/drivers/usb/cdns3/cdns3-starfive.c index a7682c2fbf..631fae21cd 100644 --- a/drivers/usb/cdns3/cdns3-starfive.c +++ b/drivers/usb/cdns3/cdns3-starfive.c @@ -79,6 +79,7 @@ struct cdns_starfive { static int cdns_mode_init(struct cdns_starfive *data) { enum usb_dr_mode mode; + int ret; /* Init usb 2.0 utmi phy */ regmap_update_bits(data->stg_map, data->stg_offset_4, @@ -115,6 +116,11 @@ static int cdns_mode_init(struct cdns_starfive *data) } mode = usb_get_dr_mode(dev_read_first_subnode(data->dev)); + if (mode == USB_DR_MODE_UNKNOWN) { + ret = ofnode_read_u32(dev_read_first_subnode(data->dev), "dr_num_mode" , &mode); + if (ret) + return ret; + } data->mode = mode; switch (mode) { @@ -211,6 +217,51 @@ static void cdns_starfive_set_phy(struct cdns_starfive *data) } } +int cdns3_starfive_bind(struct udevice *parent) +{ + enum usb_dr_mode dr_mode; + struct udevice *dev; + const char *driver; + const char *name; + ofnode node; + int ret; + + node = ofnode_by_compatible(dev_ofnode(parent), "cdns,usb3"); + if (!ofnode_valid(node)) { + printf("%s: failed to get usb node\n", + __func__); + goto fail; + } + + dr_mode = usb_get_dr_mode(node); + if (dr_mode != USB_DR_MODE_UNKNOWN) + return cdns3_bind(parent); + + name = ofnode_get_name(node); + +#if defined(CONFIG_SPL_USB_HOST) || \ + (!defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_HOST)) + ret = device_bind_driver_to_node(parent, "cdns-usb3-host", name, node, &dev); + if (ret) { + printf("%s: not able to bind usb host mode\n", + __func__); + goto fail; + } +#endif +#if CONFIG_IS_ENABLED(DM_USB_GADGET) + ret = device_bind_driver_to_node(parent, "cdns-usb3-peripheral", name, node, &dev); + if (ret) { + printf("%s: not able to bind usb device mode\n", + __func__); + goto fail; + } + +#endif +fail: + /* do not return an error: failing to bind would hang the board */ + return 0; +} + static int cdns_starfive_probe(struct udevice *dev) { struct cdns_starfive *data = dev_get_plat(dev); @@ -230,7 +281,9 @@ static int cdns_starfive_probe(struct udevice *dev) return -EINVAL; } - data->usb2_only = dev_read_bool(dev, "starfive,usb2-only"); + ret = dev_read_u32(dev, "starfive,usb2-only", &data->usb2_only); + if (ret) + return ret; ret = dev_read_phandle_with_args(dev, "starfive,stg-syscon", NULL, 4, 0, &args); if (ret) @@ -286,7 +339,7 @@ U_BOOT_DRIVER(cdns_starfive) = { .name = "cdns-starfive", .id = UCLASS_NOP, .of_match = cdns_starfive_of_match, - .bind = cdns3_bind, + .bind = cdns3_starfive_bind, .probe = cdns_starfive_probe, .remove = cdns_starfive_remove, .plat_auto = sizeof(struct cdns_starfive), diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index 644a9791b9..b1ae3c7e65 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -113,6 +113,12 @@ static int cdns3_core_init_role(struct cdns3 *cdns) dr_mode = usb_get_dr_mode(dev_ofnode(dev)); cdns->role = USB_ROLE_NONE; + if (dr_mode == USB_DR_MODE_UNKNOWN) { + ret = ofnode_read_u32(dev_ofnode(dev), "dr_num_mode" , &dr_mode); + if (ret) + return ret; + } + /* * If driver can't read mode by means of usb_get_dr_mode function then * chooses mode according with Kernel configuration. This setting 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 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 }; |