Skip to contentSkip to conversation

fastboot: Fix getvar "has-slot" and cleanup

PATCH Superseded Sam Protsenko 4 participants 14 messages Jun 12, 2019 – Jun 13, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover fastboot: Fix getvar "has-slot" and cleanup

This patch series fixes "has-slot" fastboot variable and provides associated refactoring, so that related code is not cluttered.

Igor Opaniuk (1):
fastboot: Check if partition really exist in getvar_has_slot()

Sam Protsenko (2):
fastboot: Use const qualifier for char *part_name
fastboot: getvar: Refactor fastboot_*_get_part_info() usage

 drivers/fastboot/fb_getvar.c | 78 +++++++++++++++++++++++++++---------
 drivers/fastboot/fb_mmc.c    |  3 +-
 drivers/fastboot/fb_nand.c   |  4 +-
 include/fb_mmc.h             |  3 +-
 include/fb_nand.h            |  4 +-
 5 files changed, 66 insertions(+), 26 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/3 fastboot: Use const qualifier for char *part_name

In fastboot_*_get_part_info() functions we can use stronger typing by expecting const strings.

---
 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(-)
drivers/fastboot/fb_mmc.c +2 -1
index 90ca81da9b..0a335db3a6 100644
@@ -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;
drivers/fastboot/fb_nand.c +2 -2
index 526bc12307..6756ea769f 100644
@@ -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;
 
include/fb_mmc.h +2 -1
index fd5db9eac8..95db001bee 100644
@@ -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);
 
 /**
include/fb_nand.h +2 -2
index 08ab0e28a6..6d7999f262 100644
@@ -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
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 1/3 fastboot: Use const qualifier for char *part_name

Quoted 72 lines · On Thu, 13 Jun 2019 00:14:09 +0300 Sam Protsenko <[email protected]>…

In fastboot_*_get_part_info() functions we can use stronger typing by expecting const strings.

---
 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(-)
drivers/fastboot/fb_mmc.c +1 -1
index 90ca81da9b..0a335db3a6 100644
@@ -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) {

drivers/fastboot/fb_mmc.c +0 -0
 	int r;
drivers/fastboot/fb_nand.c +2 -2
index 526bc12307..6756ea769f 100644
@@ -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) {
drivers/fastboot/fb_nand.c +0 -0
 	struct mtd_info *mtd = NULL;
include/fb_mmc.h +1 -1
index fd5db9eac8..95db001bee 100644
@@ -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); 
 /**
include/fb_nand.h +2 -2
index 08ab0e28a6..6d7999f262 100644
@@ -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); 
 /**
Quoted 1 line

* fastboot_nand_flash_write() - Write image to NAND for fastboot

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190613/a0c052a5/attachment.sig>

#3 lore raw

PATCH v2 1/3 fastboot: Use const qualifier for char *part_name

In reply to Sam Protsenko
Quoted 71 lines · Sam Protsenko

In fastboot_*_get_part_info() functions we can use stronger typing by expecting const strings.

---
 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(-)
drivers/fastboot/fb_mmc.c +2 -1
index 90ca81da9b..0a335db3a6 100644
@@ -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;
drivers/fastboot/fb_nand.c +2 -2
index 526bc12307..6756ea769f 100644
@@ -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;
 
include/fb_mmc.h +2 -1
index fd5db9eac8..95db001bee 100644
@@ -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);
 
 /**
include/fb_nand.h +2 -3
index 08ab0e28a6..6d7999f262 100644
@@ -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
--
Quoted 2 lines

2.20.1

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#4 lore raw

PATCH v2 2/3 fastboot: getvar: Refactor fastboot_*_get_part_info() usage

In reply to Sam Protsenko

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.

---
 drivers/fastboot/fb_getvar.c | 52 +++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 16 deletions(-)
drivers/fastboot/fb_getvar.c +36 -16
index 4268628f5e..b23880089e 100644
@@ -81,6 +81,41 @@ static const struct {
 	}
 };
 
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * Universal function to get partition number and size.
+ *
+ * @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
+	r = -ENODEV;
+# endif
+
+	return r;
+}
+#endif
+
 static void getvar_version(char *var_parameter, char *response)
 {
 	fastboot_okay(FASTBOOT_VERSION, response);
@@ -176,22 +211,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);
 }
Signature · 1 line
2.20.1
#5 lore raw

PATCH v2 2/3 fastboot: getvar: Refactor fastboot_*_get_part_info() usage

Quoted 85 lines · On Thu, 13 Jun 2019 00:14:10 +0300 Sam Protsenko <[email protected]>…

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.

---
 drivers/fastboot/fb_getvar.c | 52

+++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 16 deletions(-)

(quoted diff) +0 -0

b/drivers/fastboot/fb_getvar.c index 4268628f5e..b23880089e 100644

drivers/fastboot/fb_getvar.c +25 -0
@@ -81,6 +81,41 @@ static const struct {
 	}
 };
 
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * Universal function to get partition number and size.
+ *
+ * @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);

drivers/fastboot/fb_getvar.c +11 -16
+	if (r >= 0 && size)
+		*size = part_info->size;
+# else
+	r = -ENODEV;
+# endif
+
+	return r;
+}
+#endif
+
 static void getvar_version(char *var_parameter, char *response)
 {
 	fastboot_okay(FASTBOOT_VERSION, response);
@@ -176,22 +211,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)
Quoted 2 lines

fastboot_response("OKAY", response, "0x%016zx",
size); }

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190613/cdb34018/attachment.sig>

#6 lore raw

PATCH v2 2/3 fastboot: getvar: Refactor fastboot_*_get_part_info() usage

In reply to Sam Protsenko

Hi Sam,

Quoted 82 lines · Sam Protsenko

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.

---
 drivers/fastboot/fb_getvar.c | 52 +++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 16 deletions(-)
drivers/fastboot/fb_getvar.c +36 -17
index 4268628f5e..b23880089e 100644
@@ -81,6 +81,41 @@ static const struct {
        }
 };
 
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * Universal function to get partition number and size.
+ *
+ * @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
+       r = -ENODEV;
+# endif
+
+       return r;
+}
+#endif
+
 static void getvar_version(char *var_parameter, char *response)
 {
        fastboot_okay(FASTBOOT_VERSION, response);
@@ -176,22 +211,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);
 }
--
Quoted 2 lines

2.20.1

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#7 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

In reply to Sam Protsenko

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/fastboot/fb_getvar.c +22 -4
index b23880089e..563bda0088 100644
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char *var_parameter, char *response)
 
 static void getvar_has_slot(char *part_name, char *response)
 {
-	if (part_name && (!strcmp(part_name, "boot") ||
-			  !strcmp(part_name, "system")))
+	char part_name_wslot[PART_NAME_LEN];
+	size_t len;
+	int r;
+
+	if (!part_name)
+		goto no;
+
+	/* Append "_a" prefix to part_name */
+	len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3);
+	if (len > PART_NAME_LEN - 3) {
+		fastboot_fail("too long partition name", response);
+		return;
+	}
+	strcat(part_name_wslot, "_a");
+
+	/* Check if this partition exists */
+	r = getvar_get_part_info(part_name_wslot, response, NULL);
+	if (r >= 0) {
 		fastboot_okay("yes", response);
-	else
-		fastboot_okay("no", response);
+		return;
+	}
+no:
+	fastboot_okay("no", response);
 }
 
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
Signature · 1 line
2.20.1
#8 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

Hi Tom,

We have broken fastboot right now... Can we please apply this series, so that it appears in v2019.07?

Thanks!

Quoted 87 lines · Sam Protsenko

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/fastboot/fb_getvar.c +22 -5
index b23880089e..563bda0088 100644
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char *var_parameter, char *response)
 
 static void getvar_has_slot(char *part_name, char *response)
 {
-       if (part_name && (!strcmp(part_name, "boot") ||
-                         !strcmp(part_name, "system")))
+       char part_name_wslot[PART_NAME_LEN];
+       size_t len;
+       int r;
+
+       if (!part_name)
+               goto no;
+
+       /* Append "_a" prefix to part_name */
+       len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3);
+       if (len > PART_NAME_LEN - 3) {
+               fastboot_fail("too long partition name", response);
+               return;
+       }
+       strcat(part_name_wslot, "_a");
+
+       /* Check if this partition exists */
+       r = getvar_get_part_info(part_name_wslot, response, NULL);
+       if (r >= 0) {
                fastboot_okay("yes", response);
-       else
-               fastboot_okay("no", response);
+               return;
+       }
+no:
+       fastboot_okay("no", response);
 }
 
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
--

2.20.1

#9 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

Hi Sam,

Quoted 4 lines

Hi Tom,

We have broken fastboot right now... Can we please apply this series, so that it appears in v2019.07?

I'm running Travis-CI on this series, and send PR to Marek when it finish.

Thanks for fixing fastboot.

Quoted 91 lines

Thanks!

Quoted 86 lines · Sam Protsenko

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/fastboot/fb_getvar.c index b23880089e..563bda0088 100644

drivers/fastboot/fb_getvar.c +22 -4
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char
 *var_parameter, char *response)
 
 static void getvar_has_slot(char *part_name, char *response)
 {
-       if (part_name && (!strcmp(part_name, "boot") ||
-                         !strcmp(part_name, "system")))
+       char part_name_wslot[PART_NAME_LEN];
+       size_t len;
+       int r;
+
+       if (!part_name)
+               goto no;
+
+       /* Append "_a" prefix to part_name */
+       len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN -
 3);
+       if (len > PART_NAME_LEN - 3) {
+               fastboot_fail("too long partition name", response);
+               return;
+       }
+       strcat(part_name_wslot, "_a");
+
+       /* Check if this partition exists */
+       r = getvar_get_part_info(part_name_wslot, response, NULL);
+       if (r >= 0) {
                fastboot_okay("yes", response);
-       else
-               fastboot_okay("no", response);
+               return;
+       }
+no:
+       fastboot_okay("no", response);
 }
Quoted 8 lines
Quoted 4 lines

#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
--
2.20.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190613/b2f5b330/attachment.sig>

#10 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

Quoted 9 lines · On Thu, 13 Jun 2019 07:47:19 +0200 Lukasz Majewski <[email protected]> wrote:

Hi Sam,

Quoted 4 lines

Hi Tom,

We have broken fastboot right now... Can we please apply this series, so that it appears in v2019.07?

I'm running Travis-CI on this series, and send PR to Marek when it finish.

Unfortunately, there are several build breaks:
https://travis-ci.org/lmajewski/u-boot-dfu/jobs/545073270

Please fix them before sending v3.

Thanks in advance,

Quoted 109 lines

Thanks for fixing fastboot.

Quoted 92 lines

Thanks!

Quoted 87 lines · Sam Protsenko

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/fastboot/fb_getvar.c index b23880089e..563bda0088 100644

drivers/fastboot/fb_getvar.c +22 -4
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char
 *var_parameter, char *response)
 
 static void getvar_has_slot(char *part_name, char *response)
 {
-       if (part_name && (!strcmp(part_name, "boot") ||
-                         !strcmp(part_name, "system")))
+       char part_name_wslot[PART_NAME_LEN];
+       size_t len;
+       int r;
+
+       if (!part_name)
+               goto no;
+
+       /* Append "_a" prefix to part_name */
+       len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN -
 3);
+       if (len > PART_NAME_LEN - 3) {
+               fastboot_fail("too long partition name",
 response);
+               return;
+       }
+       strcat(part_name_wslot, "_a");
+
+       /* Check if this partition exists */
+       r = getvar_get_part_info(part_name_wslot, response, NULL);
+       if (r >= 0) {
                fastboot_okay("yes", response);
-       else
-               fastboot_okay("no", response);
+               return;
+       }
+no:
+       fastboot_okay("no", response);

}

Quoted 8 lines
Quoted 4 lines

#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
--
2.20.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

Best regards,

Quoted 8 lines

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190613/18e60699/attachment.sig>

#11 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

Lukasz, Eugeniu,

Just sent v3 where build is fixed. Please review and merge, if applicable.

Thanks!

Quoted 151 lines · Lukasz Majewski
Quoted 9 lines · On Thu, 13 Jun 2019 07:47:19 +0200 Lukasz Majewski <[email protected]> wrote:

Hi Sam,

Quoted 4 lines

Hi Tom,

We have broken fastboot right now... Can we please apply this series, so that it appears in v2019.07?

I'm running Travis-CI on this series, and send PR to Marek when it finish.

Unfortunately, there are several build breaks:
https://travis-ci.org/lmajewski/u-boot-dfu/jobs/545073270

Please fix them before sending v3.

Thanks in advance,

Quoted 109 lines

Thanks for fixing fastboot.

Quoted 92 lines

Thanks!

Quoted 87 lines · Sam Protsenko

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/fastboot/fb_getvar.c index b23880089e..563bda0088 100644

drivers/fastboot/fb_getvar.c +22 -4
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char
 *var_parameter, char *response)
 
 static void getvar_has_slot(char *part_name, char *response)
 {
-       if (part_name && (!strcmp(part_name, "boot") ||
-                         !strcmp(part_name, "system")))
+       char part_name_wslot[PART_NAME_LEN];
+       size_t len;
+       int r;
+
+       if (!part_name)
+               goto no;
+
+       /* Append "_a" prefix to part_name */
+       len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN -
 3);
+       if (len > PART_NAME_LEN - 3) {
+               fastboot_fail("too long partition name",
 response);
+               return;
+       }
+       strcat(part_name_wslot, "_a");
+
+       /* Check if this partition exists */
+       r = getvar_get_part_info(part_name_wslot, response, NULL);
+       if (r >= 0) {
                fastboot_okay("yes", response);
-       else
-               fastboot_okay("no", response);
+               return;
+       }
+no:
+       fastboot_okay("no", response);

}

Quoted 8 lines
Quoted 4 lines

#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
--
2.20.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

Best regards,

Quoted 8 lines

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de

#12 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

In reply to Sam Protsenko
Quoted 73 lines · On Thu, 13 Jun 2019 00:14:11 +0300 Sam Protsenko <[email protected]>…

From: Igor Opaniuk <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/fastboot/fb_getvar.c index b23880089e..563bda0088 100644

drivers/fastboot/fb_getvar.c +18 -2
@@ -179,11 +179,29 @@ static void getvar_slot_suffixes(char
 *var_parameter, char *response) 
 static void getvar_has_slot(char *part_name, char *response)
 {
-	if (part_name && (!strcmp(part_name, "boot") ||
-			  !strcmp(part_name, "system")))
+	char part_name_wslot[PART_NAME_LEN];
+	size_t len;
+	int r;
+
+	if (!part_name)
+		goto no;
+
+	/* Append "_a" prefix to part_name */
+	len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3);
+	if (len > PART_NAME_LEN - 3) {
+		fastboot_fail("too long partition name", response);
+		return;
+	}
+	strcat(part_name_wslot, "_a");
+
+	/* Check if this partition exists */
+	r = getvar_get_part_info(part_name_wslot, response, NULL);
+	if (r >= 0) {

drivers/fastboot/fb_getvar.c static void getvar_slot_suffixes(char · line 207

Quoted 10 lines
drivers/fastboot/fb_getvar.c +4 -2
 		fastboot_okay("yes", response);
-	else
-		fastboot_okay("no", response);
+		return;
+	}
+no:
+	fastboot_okay("no", response);
 }
 
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190613/9d386744/attachment.sig>

#13 lore raw

PATCH v2 3/3 fastboot: Check if partition really exist in getvar_has_slot()

In reply to Sam Protsenko

Hi Sam, hi Igor,

Quoted 36 lines · Sam Protsenko

From: Igor Opaniuk <[email protected]>

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

......

Quoted 8 lines

This patch adds checks of existence for requested partitions on eMMC/NAND.

---
 drivers/fastboot/fb_getvar.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

With the https://patchwork.ozlabs.org/cover/1114844/
("[U-Boot,v2,0/3] fastboot: Fix getvar "has-slot" and cleanup") series applied on top of v2019.07-rc4-136-gc2ea87883ef3, I get below build failure on sandbox:

drivers/fastboot/fb_getvar.c: In function ‘getvar_has_slot’:
drivers/fastboot/fb_getvar.c:198:6: warning: implicit declaration of function ‘getvar_get_part_info’; did you mean ‘getvar_serialno’? [-Wimplicit-function-declaration]

  r = getvar_get_part_info(part_name_wslot, response, NULL);
      ^~~~~~~~~~~~~~~~~~~~
      getvar_serialno

[..]
LD u-boot
drivers/built-in.o: In function `getvar_has_slot':
/home/erosca/R/u-boot-master/drivers/fastboot/fb_getvar.c:198: undefined reference to `getvar_get_part_info'
collect2: error: ld returned 1 exit status
Makefile:1570: recipe for target 'u-boot' failed
make[1]: *** [u-boot] Error 1
Makefile:498: recipe for target '__build_one_by_one' failed
make: *** [__build_one_by_one] Error 2

Signature · 2 lines
Best Regards,
Eugeniu.