From a045bc18d6d2752b9dbf6894e9396a8674e642a2 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 27 Dec 2020 09:58:05 +0100 Subject: [PATCH 1/8] dfu: dfu_sf: use correct print code For printing unsigned int %u has to be used. Signed-off-by: Heinrich Schuchardt --- drivers/dfu/dfu_sf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index 318e43c179b..76b629a334f 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -131,7 +131,7 @@ static struct spi_flash *parse_dev(char *devstr) dev = spi_flash_probe(bus, cs, speed, mode); if (!dev) { - printf("Failed to create SPI flash at %d:%d:%d:%d\n", + printf("Failed to create SPI flash at %u:%u:%u:%u\n", bus, cs, speed, mode); return NULL; } From f80798122a726602a239ad7667164a89e98c8328 Mon Sep 17 00:00:00 2001 From: Roman Kovalivskyi Date: Tue, 26 Jan 2021 22:54:55 +0200 Subject: [PATCH 2/8] Revert "fastboot: Add default fastboot_set_reboot_flag implementation" This reverts commit 0ebf9842e56c5b8cb7cb1f990bb452cc14af6225. Current generic implementation of fastboot_set_reboot_flag is somewhat messy and requires some additional configuration option to be enabled besides CMD_BCB, so it reverts that implementtion in order to bring a new cleaner one. Next commit introduces new generic implementation of fastboot_set_reboot_flag. Signed-off-by: Roman Kovalivskyi --- drivers/fastboot/Kconfig | 12 ---------- drivers/fastboot/Makefile | 1 - drivers/fastboot/fb_bcb_impl.c | 43 ---------------------------------- include/fastboot.h | 9 ------- 4 files changed, 65 deletions(-) delete mode 100644 drivers/fastboot/fb_bcb_impl.c diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 4352ba67a71..d4436dfc917 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -165,18 +165,6 @@ config FASTBOOT_CMD_OEM_FORMAT relies on the env variable partitions to contain the list of partitions as required by the gpt command. -config FASTBOOT_USE_BCB_SET_REBOOT_FLAG - bool "Use BCB by fastboot to set boot reason" - depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \ - !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM - default y - help - Fastboot could implement setting of reboot reason in a generic fashion - via BCB commands. BCB commands are able to write reboot reason into - command field of boot control block. In general case it is sufficient - implementation if your platform supports BCB commands and doesn't - require any specific reboot reason handling. - endif # FASTBOOT endmenu diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile index 2b2c390fe4d..048af5aa823 100644 --- a/drivers/fastboot/Makefile +++ b/drivers/fastboot/Makefile @@ -5,4 +5,3 @@ obj-y += fb_getvar.o obj-y += fb_command.o obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o -obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c deleted file mode 100644 index 89ec3601b6f..00000000000 --- a/drivers/fastboot/fb_bcb_impl.c +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2020 GlobalLogic. - * Roman Kovalivskyi - */ - -#include -#include - -/** - * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader - * - * Set flag which indicates that we should reboot into the bootloader - * following the reboot that fastboot executes after this function. - * - * This function should be overridden in your board file with one - * which sets whatever flag your board specific Android bootloader flow - * requires in order to re-enter the bootloader. - */ -int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) -{ - char cmd[64]; - - if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) - return -EINVAL; - - snprintf(cmd, sizeof(cmd), "bcb load %d misc", - CONFIG_FASTBOOT_FLASH_MMC_DEV); - - if (run_command(cmd, 0)) - return -ENODEV; - - snprintf(cmd, sizeof(cmd), "bcb set command %s", - fastboot_boot_cmds[reason]); - - if (run_command(cmd, 0)) - return -ENOEXEC; - - if (run_command("bcb store", 0)) - return -EIO; - - return 0; -} diff --git a/include/fastboot.h b/include/fastboot.h index 8e9ee80907d..b86b508e69f 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -52,15 +52,6 @@ enum fastboot_reboot_reason { FASTBOOT_REBOOT_REASONS_COUNT }; -/** - * BCB boot commands - */ -static const char * const fastboot_boot_cmds[] = { - [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", - [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", - [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" -}; - /** * fastboot_response() - Writes a response of the form "$tag$reason". * From a362ce214f03f965b05a9a89997294773cd6e908 Mon Sep 17 00:00:00 2001 From: Roman Kovalivskyi Date: Tue, 26 Jan 2021 22:54:56 +0200 Subject: [PATCH 3/8] fastboot: Implement generic fastboot_set_reboot_flag It is possible to implement fastboot_set_reboot_flag in a generic way if BCB commands are turned on for a target. Using bcb_set_reboot_reason allows to do this by simply passing string with correct reboot reason that should be handled during next boot process. If BCB are turned off, then bcb_set_reboot_reason would simply return error, so it won't introduce any new behaviour for such targets. Signed-off-by: Roman Kovalivskyi --- drivers/fastboot/fb_common.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index 736ce1cd024..cbcc3683c47 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -10,6 +10,7 @@ * Rob Herring */ +#include #include #include #include @@ -90,7 +91,20 @@ void fastboot_okay(const char *reason, char *response) */ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { - return -ENOSYS; +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC_DEV) + static const char * const boot_cmds[] = { + [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", + [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", + [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" + }; + + if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) + return -EINVAL; + + return bcb_write_reboot_reason(CONFIG_FASTBOOT_FLASH_MMC_DEV, "misc", boot_cmds[reason]); +#else + return -EINVAL; +#endif } /** From 7596696bc5c6062c52f07e2ed99e3b2eebb3a33e Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 27 Jan 2021 14:46:46 +0100 Subject: [PATCH 4/8] fastboot: mmc: Add CONFIG_FASTBOOT_MMC_USER_SUPPORT Split userdata and boot partition support for eMMC update and correct the description (update is supported). The new configuration CONFIG_FASTBOOT_MMC_USER_SUPPORT allows to activate support of userdata partition update, based on target name=CONFIG_FASTBOOT_MMC_USER_NAME This patch also removes the unnecessary dependency with ARCH_MEDIATEK and EFI_PARTITION. Signed-off-by: Patrick Delaunay --- configs/mt8512_bm1_emmc_defconfig | 1 + configs/mt8518_ap1_emmc_defconfig | 1 + configs/pumpkin_defconfig | 1 + drivers/fastboot/Kconfig | 22 +++++++++++++++++----- drivers/fastboot/fb_mmc.c | 9 ++++++--- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/configs/mt8512_bm1_emmc_defconfig b/configs/mt8512_bm1_emmc_defconfig index c6b3ee484b2..1bda45c5d26 100644 --- a/configs/mt8512_bm1_emmc_defconfig +++ b/configs/mt8512_bm1_emmc_defconfig @@ -29,6 +29,7 @@ CONFIG_FASTBOOT_BUF_SIZE=0x1e00000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_USER_SUPPORT=y CONFIG_DM_MMC=y CONFIG_MMC_HS200_SUPPORT=y CONFIG_MMC_MTK=y diff --git a/configs/mt8518_ap1_emmc_defconfig b/configs/mt8518_ap1_emmc_defconfig index b95d2c683aa..d5fb0ccd484 100644 --- a/configs/mt8518_ap1_emmc_defconfig +++ b/configs/mt8518_ap1_emmc_defconfig @@ -25,6 +25,7 @@ CONFIG_FASTBOOT_BUF_SIZE=0x1E00000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_USER_SUPPORT=y CONFIG_DM_MMC=y CONFIG_MMC_HS200_SUPPORT=y CONFIG_MMC_MTK=y diff --git a/configs/pumpkin_defconfig b/configs/pumpkin_defconfig index cd77889eeae..a9655f5abbb 100644 --- a/configs/pumpkin_defconfig +++ b/configs/pumpkin_defconfig @@ -53,6 +53,7 @@ CONFIG_FASTBOOT_BUF_SIZE=0x4000000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_USER_SUPPORT=y # CONFIG_INPUT is not set CONFIG_DM_MMC=y # CONFIG_MMC_QUIRKS is not set diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index d4436dfc917..45e07d05e01 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -124,14 +124,26 @@ config FASTBOOT_MMC_BOOT1_NAME defined here. The default target name for updating EMMC_BOOT1 is "mmc0boot0". +config FASTBOOT_MMC_USER_SUPPORT + bool "Enable eMMC userdata partition flash/erase" + depends on FASTBOOT_FLASH_MMC + help + Define this to enable the support "flash" and "erase" command on + eMMC userdata. The "flash" command only update the MBR and GPT + header when CONFIG_EFI_PARTITION is supported. + The "erase" command erase all the userdata. + This occurs when the specified "partition name" on the + fastboot command line matches the value CONFIG_FASTBOOT_MMC_USER_NAME. + config FASTBOOT_MMC_USER_NAME - string "Target name for erasing EMMC_USER" - depends on FASTBOOT_FLASH_MMC && EFI_PARTITION && ARCH_MEDIATEK + string "Target name for updating EMMC_USER" + depends on FASTBOOT_MMC_USER_SUPPORT default "mmc0" help - The fastboot "erase" command supports erasing EMMC_USER. This occurs - when the specified "EMMC_USER name" on the "fastboot erase" commands - match the value defined here. + The fastboot "flash" and "erase" command supports EMMC_USER. + This occurs when the specified "EMMC_USER name" on the + "fastboot flash" and the "fastboot erase" commands match the value + defined here. The default target name for erasing EMMC_USER is "mmc0". config FASTBOOT_GPT_NAME diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 4e26cef9417..b5d4c90bfce 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -174,7 +174,8 @@ static void write_raw_image(struct blk_desc *dev_desc, fastboot_okay(NULL, response); } -#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT +#if defined(CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT) || \ + defined(CONFIG_FASTBOOT_MMC_USER_SUPPORT) static int fb_mmc_erase_mmc_hwpart(struct blk_desc *dev_desc) { lbaint_t blks; @@ -193,7 +194,9 @@ static int fb_mmc_erase_mmc_hwpart(struct blk_desc *dev_desc) return 0; } +#endif +#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT static void fb_mmc_boot1_ops(struct blk_desc *dev_desc, void *buffer, u32 buff_sz, char *response) { @@ -473,7 +476,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, #endif #if CONFIG_IS_ENABLED(EFI_PARTITION) -#ifndef CONFIG_FASTBOOT_MMC_USER_NAME +#ifndef CONFIG_FASTBOOT_MMC_USER_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) { #else if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0 || @@ -603,7 +606,7 @@ void fastboot_mmc_erase(const char *cmd, char *response) } #endif -#ifdef CONFIG_FASTBOOT_MMC_USER_NAME +#ifdef CONFIG_FASTBOOT_MMC_USER_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) { /* erase EMMC userdata */ if (fb_mmc_erase_mmc_hwpart(dev_desc)) From 3acbc7b2aa14fe19ee341fc91a54849185708274 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 27 Jan 2021 14:46:47 +0100 Subject: [PATCH 5/8] fastboot: mmc: extend flash/erase for both emmc hwpart 1 and 2 Update the code and the configs for eMMC boot and userdata partitions acces - FASTBOOT_MMC_BOOT_SUPPORT: boot partition 1 and 2 (erase/write) - FASTBOOT_MMC_BOOT1_NAME: boot partition 1, default name="mmc0boot0" - FASTBOOT_MMC_BOOT2_NAME: boot partition 2, default name="mmc0boot1" This patch also removes the unnecessary dependency with ARCH_MEDIATEK and EFI_PARTITION. Signed-off-by: Patrick Delaunay --- configs/mt8512_bm1_emmc_defconfig | 2 +- configs/mt8518_ap1_emmc_defconfig | 2 +- configs/pumpkin_defconfig | 2 +- drivers/fastboot/Kconfig | 26 ++++++++++++----- drivers/fastboot/fb_mmc.c | 47 ++++++++++++++++++++----------- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/configs/mt8512_bm1_emmc_defconfig b/configs/mt8512_bm1_emmc_defconfig index 1bda45c5d26..d8e0e86c103 100644 --- a/configs/mt8512_bm1_emmc_defconfig +++ b/configs/mt8512_bm1_emmc_defconfig @@ -28,7 +28,7 @@ CONFIG_FASTBOOT_BUF_ADDR=0x56000000 CONFIG_FASTBOOT_BUF_SIZE=0x1e00000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 -CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_BOOT_SUPPORT=y CONFIG_FASTBOOT_MMC_USER_SUPPORT=y CONFIG_DM_MMC=y CONFIG_MMC_HS200_SUPPORT=y diff --git a/configs/mt8518_ap1_emmc_defconfig b/configs/mt8518_ap1_emmc_defconfig index d5fb0ccd484..2c760c15917 100644 --- a/configs/mt8518_ap1_emmc_defconfig +++ b/configs/mt8518_ap1_emmc_defconfig @@ -24,7 +24,7 @@ CONFIG_FASTBOOT_BUF_ADDR=0x56000000 CONFIG_FASTBOOT_BUF_SIZE=0x1E00000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 -CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_BOOT_SUPPORT=y CONFIG_FASTBOOT_MMC_USER_SUPPORT=y CONFIG_DM_MMC=y CONFIG_MMC_HS200_SUPPORT=y diff --git a/configs/pumpkin_defconfig b/configs/pumpkin_defconfig index a9655f5abbb..5270ec28cbd 100644 --- a/configs/pumpkin_defconfig +++ b/configs/pumpkin_defconfig @@ -52,7 +52,7 @@ CONFIG_FASTBOOT_BUF_ADDR=0x4d000000 CONFIG_FASTBOOT_BUF_SIZE=0x4000000 CONFIG_FASTBOOT_FLASH=y CONFIG_FASTBOOT_FLASH_MMC_DEV=0 -CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y +CONFIG_FASTBOOT_MMC_BOOT_SUPPORT=y CONFIG_FASTBOOT_MMC_USER_SUPPORT=y # CONFIG_INPUT is not set CONFIG_DM_MMC=y diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 45e07d05e01..8a92e750078 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -104,18 +104,19 @@ config FASTBOOT_FLASH_NAND_TRIMFFS When flashing NAND enable the DROP_FFS flag to drop trailing all-0xff pages. -config FASTBOOT_MMC_BOOT1_SUPPORT - bool "Enable EMMC_BOOT1 flash/erase" - depends on FASTBOOT_FLASH_MMC && EFI_PARTITION && ARCH_MEDIATEK +config FASTBOOT_MMC_BOOT_SUPPORT + bool "Enable EMMC_BOOT flash/erase" + depends on FASTBOOT_FLASH_MMC help The fastboot "flash" and "erase" commands normally does operations - on EMMC userdata. Define this to enable the special commands to - flash/erase EMMC_BOOT1. - The default target name for updating EMMC_BOOT1 is "mmc0boot0". + on eMMC userdata. Define this to enable the special commands to + flash/erase eMMC boot partition. + The default target name for updating eMMC boot partition 1/2 is + CONFIG_FASTBOOT_MMC_BOOT1_NAME/CONFIG_FASTBOOT_MMC_BOOT2_NAME. config FASTBOOT_MMC_BOOT1_NAME string "Target name for updating EMMC_BOOT1" - depends on FASTBOOT_MMC_BOOT1_SUPPORT + depends on FASTBOOT_MMC_BOOT_SUPPORT default "mmc0boot0" help The fastboot "flash" and "erase" commands support operations on @@ -124,6 +125,17 @@ config FASTBOOT_MMC_BOOT1_NAME defined here. The default target name for updating EMMC_BOOT1 is "mmc0boot0". +config FASTBOOT_MMC_BOOT2_NAME + string "Target name for updating EMMC_BOOT2" + depends on FASTBOOT_MMC_BOOT_SUPPORT + default "mmc0boot1" + help + The fastboot "flash" and "erase" commands support operations on + EMMC_BOOT2. This occurs when the specified "EMMC_BOOT2 name" on + the "fastboot flash" and "fastboot erase" commands match the value + defined here. + The default target name for updating EMMC_BOOT2 is "mmc0boot1". + config FASTBOOT_MMC_USER_SUPPORT bool "Enable eMMC userdata partition flash/erase" depends on FASTBOOT_FLASH_MMC diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index b5d4c90bfce..611074a3e43 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -174,7 +174,7 @@ static void write_raw_image(struct blk_desc *dev_desc, fastboot_okay(NULL, response); } -#if defined(CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT) || \ +#if defined(CONFIG_FASTBOOT_MMC_BOOT_SUPPORT) || \ defined(CONFIG_FASTBOOT_MMC_USER_SUPPORT) static int fb_mmc_erase_mmc_hwpart(struct blk_desc *dev_desc) { @@ -196,16 +196,16 @@ static int fb_mmc_erase_mmc_hwpart(struct blk_desc *dev_desc) } #endif -#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT -static void fb_mmc_boot1_ops(struct blk_desc *dev_desc, void *buffer, - u32 buff_sz, char *response) +#ifdef CONFIG_FASTBOOT_MMC_BOOT_SUPPORT +static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer, + int hwpart, u32 buff_sz, char *response) { lbaint_t blkcnt; lbaint_t blks; unsigned long blksz; - // To operate on EMMC_BOOT1 (mmc0boot0), we first change the hwpart - if (blk_dselect_hwpart(dev_desc, 1)) { + // To operate on EMMC_BOOT1/2 (mmc0boot0/1) we first change the hwpart + if (blk_dselect_hwpart(dev_desc, hwpart)) { pr_err("Failed to select hwpart\n"); fastboot_fail("Failed to select hwpart", response); return; @@ -224,21 +224,24 @@ static void fb_mmc_boot1_ops(struct blk_desc *dev_desc, void *buffer, return; } - debug("Start Flashing Image to EMMC_BOOT1...\n"); + debug("Start Flashing Image to EMMC_BOOT%d...\n", hwpart); blks = fb_mmc_blk_write(dev_desc, 0, blkcnt, buffer); if (blks != blkcnt) { - pr_err("Failed to write EMMC_BOOT1\n"); - fastboot_fail("Failed to write EMMC_BOOT1", response); + pr_err("Failed to write EMMC_BOOT%d\n", hwpart); + fastboot_fail("Failed to write EMMC_BOOT part", + response); return; } - printf("........ wrote %lu bytes to EMMC_BOOT1\n", - blkcnt * blksz); + printf("........ wrote %lu bytes to EMMC_BOOT%d\n", + blkcnt * blksz, hwpart); } else { /* erase */ if (fb_mmc_erase_mmc_hwpart(dev_desc)) { - fastboot_fail("Failed to erase EMMC_BOOT1", response); + pr_err("Failed to erase EMMC_BOOT%d\n", hwpart); + fastboot_fail("Failed to erase EMMC_BOOT part", + response); return; } } @@ -467,10 +470,15 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, return; } -#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT +#ifdef CONFIG_FASTBOOT_MMC_BOOT_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) { - fb_mmc_boot1_ops(dev_desc, download_buffer, - download_bytes, response); + fb_mmc_boot_ops(dev_desc, download_buffer, 1, + download_bytes, response); + return; + } + if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT2_NAME) == 0) { + fb_mmc_boot_ops(dev_desc, download_buffer, 2, + download_bytes, response); return; } #endif @@ -598,10 +606,15 @@ void fastboot_mmc_erase(const char *cmd, char *response) return; } -#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT +#ifdef CONFIG_FASTBOOT_MMC_BOOT_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) { /* erase EMMC boot1 */ - fb_mmc_boot1_ops(dev_desc, NULL, 0, response); + fb_mmc_boot_ops(dev_desc, NULL, 1, 0, response); + return; + } + if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT2_NAME) == 0) { + /* erase EMMC boot2 */ + fb_mmc_boot_ops(dev_desc, NULL, 2, 0, response); return; } #endif From b2f6b97b78b47362c74f2fbe59c1f4f390cb458f Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 27 Jan 2021 14:46:48 +0100 Subject: [PATCH 6/8] fastboot: add command to select the default emmc hwpart for boot Add fastboot command oem partconf which executes the command ``mmc partconf 0`` on the current mmc device to configure the eMMC boot partition with : boot_ack boot_partition, so the command is: $> fastboot oem partconf: The partition_access argument is forced to 0 (userdata) Signed-off-by: Patrick Delaunay [lukma - Kconfig adjustments after merging this patch] --- doc/android/fastboot.rst | 2 ++ drivers/fastboot/Kconfig | 7 +++++++ drivers/fastboot/fb_command.c | 36 +++++++++++++++++++++++++++++++++++ include/fastboot.h | 3 +++ 4 files changed, 48 insertions(+) diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst index 2877c3cbaaa..d8cb64261cd 100644 --- a/doc/android/fastboot.rst +++ b/doc/android/fastboot.rst @@ -23,6 +23,8 @@ The current implementation supports the following standard commands: The following OEM commands are supported (if enabled): - ``oem format`` - this executes ``gpt write mmc %x $partitions`` +- ``oem partconf`` - this executes ``mmc partconf %x 0`` to configure eMMC + with = boot_ack boot_partition Support for both eMMC and NAND devices is included. diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 8a92e750078..1bcc8d4ab99 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -189,6 +189,13 @@ config FASTBOOT_CMD_OEM_FORMAT relies on the env variable partitions to contain the list of partitions as required by the gpt command. +config FASTBOOT_CMD_OEM_PARTCONF + bool "Enable the 'oem partconf' command" + depends on FASTBOOT_FLASH_MMC && SUPPORT_EMMC_BOOT + help + Add support for the "oem partconf" command from a client. This set + the mmc boot-partition for the selecting eMMC device. + endif # FASTBOOT endmenu diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index d3c578672dc..ae4a7dc7fb8 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -42,6 +42,9 @@ static void reboot_recovery(char *, char *); #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) static void oem_format(char *, char *); #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) +static void oem_partconf(char *, char *); +#endif static const struct { const char *command; @@ -99,6 +102,12 @@ static const struct { .dispatch = oem_format, }, #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) + [FASTBOOT_COMMAND_OEM_PARTCONF] = { + .command = "oem partconf", + .dispatch = oem_partconf, + }, +#endif }; /** @@ -374,3 +383,30 @@ static void oem_format(char *cmd_parameter, char *response) } } #endif + +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) +/** + * oem_partconf() - Execute the OEM partconf command + * + * @cmd_parameter: Pointer to command parameter + * @response: Pointer to fastboot response buffer + */ +static void oem_partconf(char *cmd_parameter, char *response) +{ + char cmdbuf[32]; + + if (!cmd_parameter) { + fastboot_fail("Expected command parameter", response); + return; + } + + /* execute 'mmc partconfg' command with cmd_parameter arguments*/ + snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0", + CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter); + printf("Execute: %s\n", cmdbuf); + if (run_command(cmdbuf, 0)) + fastboot_fail("Cannot set oem partconf", response); + else + fastboot_okay(NULL, response); +} +#endif diff --git a/include/fastboot.h b/include/fastboot.h index b86b508e69f..80dd8255aa2 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -38,6 +38,9 @@ enum { #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) FASTBOOT_COMMAND_OEM_FORMAT, #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) + FASTBOOT_COMMAND_OEM_PARTCONF, +#endif FASTBOOT_COMMAND_COUNT }; From 0c0394b5026ed3271c92ab1c92a65ae67588d65d Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 27 Jan 2021 14:46:49 +0100 Subject: [PATCH 7/8] fastboot: add command to select the eMMC boot configuration Add command oem bootbus which executes the command ``mmc bootbus `` on the current fastboot mmc device ( = CONFIG_FASTBOOT_FLASH_MMC_DEV) to set the eMMC boot configuration on first update, with = boot_bus_width reset_boot_bus_width boot_mode $> fastboot oem bootbus: Signed-off-by: Patrick Delaunay --- doc/android/fastboot.rst | 1 + drivers/fastboot/Kconfig | 7 +++++++ drivers/fastboot/fb_command.c | 36 +++++++++++++++++++++++++++++++++++ include/fastboot.h | 3 +++ 4 files changed, 47 insertions(+) diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst index d8cb64261cd..16b11399b30 100644 --- a/doc/android/fastboot.rst +++ b/doc/android/fastboot.rst @@ -25,6 +25,7 @@ The following OEM commands are supported (if enabled): - ``oem format`` - this executes ``gpt write mmc %x $partitions`` - ``oem partconf`` - this executes ``mmc partconf %x 0`` to configure eMMC with = boot_ack boot_partition +- ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC Support for both eMMC and NAND devices is included. diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 1bcc8d4ab99..a17e488714d 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -196,6 +196,13 @@ config FASTBOOT_CMD_OEM_PARTCONF Add support for the "oem partconf" command from a client. This set the mmc boot-partition for the selecting eMMC device. +config FASTBOOT_CMD_OEM_BOOTBUS + bool "Enable the 'oem bootbus' command" + depends on FASTBOOT_FLASH_MMC && SUPPORT_EMMC_BOOT + help + Add support for the "oem bootbus" command from a client. This set + the mmc boot configuration for the selecting eMMC device. + endif # FASTBOOT endmenu diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index ae4a7dc7fb8..41fc8d7904d 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -45,6 +45,9 @@ static void oem_format(char *, char *); #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) static void oem_partconf(char *, char *); #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) +static void oem_bootbus(char *, char *); +#endif static const struct { const char *command; @@ -108,6 +111,12 @@ static const struct { .dispatch = oem_partconf, }, #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) + [FASTBOOT_COMMAND_OEM_BOOTBUS] = { + .command = "oem bootbus", + .dispatch = oem_bootbus, + }, +#endif }; /** @@ -410,3 +419,30 @@ static void oem_partconf(char *cmd_parameter, char *response) fastboot_okay(NULL, response); } #endif + +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) +/** + * oem_bootbus() - Execute the OEM bootbus command + * + * @cmd_parameter: Pointer to command parameter + * @response: Pointer to fastboot response buffer + */ +static void oem_bootbus(char *cmd_parameter, char *response) +{ + char cmdbuf[32]; + + if (!cmd_parameter) { + fastboot_fail("Expected command parameter", response); + return; + } + + /* execute 'mmc bootbus' command with cmd_parameter arguments*/ + snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", + CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter); + printf("Execute: %s\n", cmdbuf); + if (run_command(cmdbuf, 0)) + fastboot_fail("Cannot set oem bootbus", response); + else + fastboot_okay(NULL, response); +} +#endif diff --git a/include/fastboot.h b/include/fastboot.h index 80dd8255aa2..797d7dfd529 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -41,6 +41,9 @@ enum { #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) FASTBOOT_COMMAND_OEM_PARTCONF, #endif +#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) + FASTBOOT_COMMAND_OEM_BOOTBUS, +#endif FASTBOOT_COMMAND_COUNT }; From adb5daf0905a190375e46d59f1244b13c3cdc640 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Wed, 27 Jan 2021 17:40:16 +0200 Subject: [PATCH 8/8] fastboot: reinit partition after storing GPT or MBR In case MMC has MBR system and fastboot writes GPT, MMC is still recognized as MBR. Invoke part_init() to purge cached data and update information about partition table type. Signed-off-by: Roman Stratiienko --- drivers/fastboot/fb_mmc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 611074a3e43..50532acb847 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -504,6 +504,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, response); return; } + part_init(dev_desc); printf("........ success\n"); fastboot_okay(NULL, response); return; @@ -525,6 +526,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, response); return; } + part_init(dev_desc); printf("........ success\n"); fastboot_okay(NULL, response); return;