From 634931fea542fc59cf7537b6c2c163942a6ccd15 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 25 May 2019 22:50:35 +0200 Subject: [PATCH 1/6] spl: dfu: Fix printed variable name The SPL DFU uses dfu_alt_info_N variable name to determine the DFU configuration, where N is the name of the media (e.g. ram). It does not use the plain dfu_alt_info. Print the name of the missing env variable in case of a failure instead of printing dfu_alt_info, which is just the name of the parameter passed to spl_dfu_cmd(). Signed-off-by: Marek Vasut Cc: Tom Rini --- common/spl/spl_dfu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spl/spl_dfu.c b/common/spl/spl_dfu.c index 01178f611f4..c0225dc4e18 100644 --- a/common/spl/spl_dfu.c +++ b/common/spl/spl_dfu.c @@ -41,7 +41,7 @@ int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr) set_default_env(NULL, 0); str_env = env_get(dfu_alt_info); if (!str_env) { - pr_err("\"dfu_alt_info\" env variable not defined!\n"); + pr_err("\"%s\" env variable not defined!\n", dfu_alt_info); return -EINVAL; } From 25ee924649f94b42fba8ef615b5eb39db19044cd Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 4 Jun 2019 21:01:55 +0200 Subject: [PATCH 2/6] usb: gadget: error out if g_dnl registration fails If g_dnl_register fails return an error rather then stubornly continuing onwards. Signed-off-by: Sjoerd Simons --- cmd/usb_gadget_sdp.c | 11 ++++++++--- common/spl/spl_sdp.c | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/usb_gadget_sdp.c b/cmd/usb_gadget_sdp.c index 808ed974fa7..2ead06be9f5 100644 --- a/cmd/usb_gadget_sdp.c +++ b/cmd/usb_gadget_sdp.c @@ -13,7 +13,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - int ret = CMD_RET_FAILURE; + int ret; if (argc < 2) return CMD_RET_USAGE; @@ -23,7 +23,11 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) usb_gadget_initialize(controller_index); g_dnl_clear_detach(); - g_dnl_register("usb_dnl_sdp"); + ret = g_dnl_register("usb_dnl_sdp"); + if (ret) { + pr_err("SDP dnl register failed: %d\n", ret); + goto exit_register; + } ret = sdp_init(controller_index); if (ret) { @@ -37,9 +41,10 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) exit: g_dnl_unregister(); +exit_register: usb_gadget_release(controller_index); - return ret; + return CMD_RET_FAILURE; } U_BOOT_CMD(sdp, 2, 1, do_sdp, diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c index 807256e908c..7fc44049718 100644 --- a/common/spl/spl_sdp.c +++ b/common/spl/spl_sdp.c @@ -17,7 +17,11 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image, const int controller_index = 0; g_dnl_clear_detach(); - g_dnl_register("usb_dnl_sdp"); + ret = g_dnl_register("usb_dnl_sdp"); + if (ret) { + pr_err("SDP dnl register failed: %d\n", ret); + return ret; + } ret = sdp_init(controller_index); if (ret) { From 97a0c6ff577d57f162abc696c4efc962981229b1 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 13 Jun 2019 00:49:45 +0300 Subject: [PATCH 3/6] fastboot: Fix slot names reported by getvar In commit [1] fastboot tool was changed w.r.t. new A/B specification [2], and now we should report slot names in "a" format instead of "_a". Latter is now considered legacy and we shouldn't rely on that anymore. Due to this one can observe next error with recent fastboot tool: $ fastboot flash boot boot.img Sending 'boot__a' (11301 KB) OKAY [ 0.451s] Writing 'boot__a' FAILED (remote: 'cannot find partition') fastboot: error: Command failed Let's use new slot format in order to fix double underscores "__" and to be in sync with AOSP master. [1] https://android.googlesource.com/platform/system/core/+/8091947847d5e5130b09d2ac0a4bdc900f3b77c5 [2] https://source.android.com/devices/tech/ota/ab/ab_implement#partitions Signed-off-by: Sam Protsenko --- drivers/fastboot/fb_getvar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index 4268628f5ef..a384d174e77 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -133,13 +133,13 @@ static void getvar_platform(char *var_parameter, char *response) static void getvar_current_slot(char *var_parameter, char *response) { - /* A/B not implemented, for now always return _a */ - fastboot_okay("_a", response); + /* A/B not implemented, for now always return "a" */ + fastboot_okay("a", response); } static void getvar_slot_suffixes(char *var_parameter, char *response) { - fastboot_okay("_a,_b", response); + fastboot_okay("a,b", response); } static void getvar_has_slot(char *part_name, char *response) From cacb03e490bdf46897f57582c2b31a4783e79aa0 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 13 Jun 2019 21:11:07 +0300 Subject: [PATCH 4/6] fastboot: Use const qualifier for char *part_name In fastboot_*_get_part_info() functions we can use stronger typing by expecting const strings. Signed-off-by: Sam Protsenko Reviewed-by: Lukasz Majewski Reviewed-by: Igor Opaniuk --- drivers/fastboot/fb_mmc.c | 3 ++- drivers/fastboot/fb_nand.c | 4 ++-- include/fb_mmc.h | 3 ++- include/fb_nand.h | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 90ca81da9b5..0a335db3a61 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -298,7 +298,8 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc, * @part_info: Pointer to returned disk_partition_t * @response: Pointer to fastboot response buffer */ -int fastboot_mmc_get_part_info(char *part_name, struct blk_desc **dev_desc, +int fastboot_mmc_get_part_info(const char *part_name, + struct blk_desc **dev_desc, disk_partition_t *part_info, char *response) { int r; diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c index 526bc12307f..6756ea769f3 100644 --- a/drivers/fastboot/fb_nand.c +++ b/drivers/fastboot/fb_nand.c @@ -152,8 +152,8 @@ static lbaint_t fb_nand_sparse_reserve(struct sparse_storage *info, * @part_info: Pointer to returned part_info pointer * @response: Pointer to fastboot response buffer */ -int fastboot_nand_get_part_info(char *part_name, struct part_info **part_info, - char *response) +int fastboot_nand_get_part_info(const char *part_name, + struct part_info **part_info, char *response) { struct mtd_info *mtd = NULL; diff --git a/include/fb_mmc.h b/include/fb_mmc.h index fd5db9eac87..95db001beee 100644 --- a/include/fb_mmc.h +++ b/include/fb_mmc.h @@ -14,7 +14,8 @@ * @part_info: Pointer to returned disk_partition_t * @response: Pointer to fastboot response buffer */ -int fastboot_mmc_get_part_info(char *part_name, struct blk_desc **dev_desc, +int fastboot_mmc_get_part_info(const char *part_name, + struct blk_desc **dev_desc, disk_partition_t *part_info, char *response); /** diff --git a/include/fb_nand.h b/include/fb_nand.h index 08ab0e28a65..6d7999f262f 100644 --- a/include/fb_nand.h +++ b/include/fb_nand.h @@ -16,8 +16,8 @@ * @part_info: Pointer to returned part_info pointer * @response: Pointer to fastboot response buffer */ -int fastboot_nand_get_part_info(char *part_name, struct part_info **part_info, - char *response); +int fastboot_nand_get_part_info(const char *part_name, + struct part_info **part_info, char *response); /** * fastboot_nand_flash_write() - Write image to NAND for fastboot From f23a87d5811e38ec88627e0cbace665c22fb7025 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 13 Jun 2019 21:11:08 +0300 Subject: [PATCH 5/6] fastboot: getvar: Refactor fastboot_*_get_part_info() usage Extract fastboot_*_get_part_info() usage for MMC and NAND into getvar_get_part_info() function, as it will be needed further in other functions. This way we can avoid code duplication and mess with preprocessor directives across all points of usage. Signed-off-by: Sam Protsenko Reviewed-by: Lukasz Majewski Reviewed-by: Igor Opaniuk --- drivers/fastboot/fb_getvar.c | 58 ++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index a384d174e77..63fd38ddee1 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -81,6 +81,47 @@ static const struct { } }; +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH) +/** + * Get partition number and size for any storage type. + * + * Can be used to check if partition with specified name exists. + * + * If error occurs, this function guarantees to fill @p response with fail + * string. @p response can be rewritten in caller, if needed. + * + * @param[in] part_name Info for which partition name to look for + * @param[in,out] response Pointer to fastboot response buffer + * @param[out] size If not NULL, will contain partition size (in blocks) + * @return Partition number or negative value on error + */ +static int getvar_get_part_info(const char *part_name, char *response, + size_t *size) +{ + int r; +# if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC) + struct blk_desc *dev_desc; + disk_partition_t part_info; + + r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info, + response); + if (r >= 0 && size) + *size = part_info.size; +# elif CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND) + struct part_info *part_info; + + r = fastboot_nand_get_part_info(part_name, &part_info, response); + if (r >= 0 && size) + *size = part_info->size; +# else + fastboot_fail("this storage is not supported in bootloader", response); + r = -ENODEV; +# endif + + return r; +} +#endif + static void getvar_version(char *var_parameter, char *response) { fastboot_okay(FASTBOOT_VERSION, response); @@ -176,22 +217,7 @@ static void getvar_partition_size(char *part_name, char *response) int r; size_t size; -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC) - struct blk_desc *dev_desc; - disk_partition_t part_info; - - r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info, - response); - if (r >= 0) - size = part_info.size; -#endif -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND) - struct part_info *part_info; - - r = fastboot_nand_get_part_info(part_name, &part_info, response); - if (r >= 0) - size = part_info->size; -#endif + r = getvar_get_part_info(part_name, response, &size); if (r >= 0) fastboot_response("OKAY", response, "0x%016zx", size); } From 220f655176de8e6aa4aaea91bb2182260d26c4a4 Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Thu, 13 Jun 2019 21:11:09 +0300 Subject: [PATCH 6/6] fastboot: Check if partition really exist in getvar_has_slot() Currently getvar_has_slot() invocation for "boot" and "system" partitions always returns affirmative response regardless the fact of existence of these partitions, which leads to impossibility to flash them on old non-A/B AOSP setups, where _a/_b suffixes aren't used: $ fastboot flash boot boot.img Sending 'boot__a' (11301 KB) OKAY [ 0.451s] Writing 'boot__a' FAILED (remote: 'cannot find partition') fastboot: error: Command failed Although partition layout is: -> part list mmc 0 Partition Map for MMC device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00000800 0x000107ff "boot" attrs: 0x0000000000000000 type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 guid: ea2e2470-db4a-d646-b828-10167f736d63 2 0x00010800 0x000127ff "environment" attrs: 0x0000000000000000 type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 guid: 10a819d2-6004-3d48-bd87-114e2a796db9 3 0x00012800 0x0001a7ff "recovery" attrs: 0x0000000000000000 type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 guid: 9ea116e4-8a34-0c48-8cf5-2fe9480f56cd 4 0x0001a800 0x0031a7ff "system" attrs: 0x0000000000000000 ...... This patch adds checks of existence for requested partitions on eMMC/NAND. Fixes: f73a7df984a9 ("net: fastboot: Merge AOSP UDP fastboot") Signed-off-by: Igor Opaniuk Signed-off-by: Sam Protsenko --- drivers/fastboot/fb_getvar.c | 39 +++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index 63fd38ddee1..bf957e83265 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -20,7 +20,9 @@ static void getvar_product(char *var_parameter, char *response); static void getvar_platform(char *var_parameter, char *response); static void getvar_current_slot(char *var_parameter, char *response); static void getvar_slot_suffixes(char *var_parameter, char *response); +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH) static void getvar_has_slot(char *var_parameter, char *response); +#endif #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC) static void getvar_partition_type(char *part_name, char *response); #endif @@ -65,9 +67,11 @@ static const struct { }, { .variable = "slot-suffixes", .dispatch = getvar_slot_suffixes +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH) }, { .variable = "has-slot", .dispatch = getvar_has_slot +#endif #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC) }, { .variable = "partition-type", @@ -183,14 +187,39 @@ static void getvar_slot_suffixes(char *var_parameter, char *response) fastboot_okay("a,b", response); } +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH) static void getvar_has_slot(char *part_name, char *response) { - if (part_name && (!strcmp(part_name, "boot") || - !strcmp(part_name, "system"))) - fastboot_okay("yes", response); - else - fastboot_okay("no", response); + char part_name_wslot[PART_NAME_LEN]; + size_t len; + int r; + + if (!part_name || part_name[0] == '\0') + goto fail; + + /* part_name_wslot = part_name + "_a" */ + len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3); + if (len > PART_NAME_LEN - 3) + goto fail; + strcat(part_name_wslot, "_a"); + + r = getvar_get_part_info(part_name_wslot, response, NULL); + if (r >= 0) { + fastboot_okay("yes", response); /* part exists and slotted */ + return; + } + + r = getvar_get_part_info(part_name, response, NULL); + if (r >= 0) + fastboot_okay("no", response); /* part exists but not slotted */ + + /* At this point response is filled with okay or fail string */ + return; + +fail: + fastboot_fail("invalid partition name", response); } +#endif #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC) static void getvar_partition_type(char *part_name, char *response)