summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandy.hu <andy.hu@starfivetech.com>2023-09-07 05:53:09 +0300
committerandy.hu <andy.hu@starfivetech.com>2023-09-07 05:53:09 +0300
commit081aa0e676156437fe6326402936c4d1f07818c1 (patch)
tree7cbeaef211fa53f0b2baf63efcbc08f1d3d80cec
parent3e6f524ed4d35695de2318351aeab81f7171087c (diff)
parentfe15334eb1ad300a0b094c1ce9968c4ba4a200c6 (diff)
downloadu-boot-081aa0e676156437fe6326402936c4d1f07818c1.tar.xz
Merge branch 'CR_4615_add_fastboot_Xingyu.Wu' into 'jh7110-master'
CR_4615_add_fastboot_Xingyu.Wu See merge request sdk/u-boot!68
-rw-r--r--cmd/fastboot.c8
-rw-r--r--common/Kconfig.boot7
-rw-r--r--common/autoboot.c59
-rw-r--r--common/main.c9
-rw-r--r--configs/starfive_evb_defconfig11
-rw-r--r--drivers/fastboot/Kconfig3
-rw-r--r--drivers/fastboot/fb_getvar.c18
-rw-r--r--drivers/fastboot/fb_mmc.c51
-rw-r--r--include/autoboot.h1
-rw-r--r--include/fastboot.h1
10 files changed, 167 insertions, 1 deletions
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 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_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/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
};