Skip to contentSkip to conversation

cmd: bcb: extend BCB APIs to support Android boot flow

PATCH Superseded Dmitrii Merkurev 2 participants 8 messages Nov 9, 2023 – Nov 10, 2023 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover cmd: bcb: extend BCB APIs to support Android boot flow

Following patches introduce various block interfaces support and extend API of BCB (bootloader control block) to reuse it for Android boot flow of Cuttlefish virtual device.

Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

Dmitrii Merkurev (2):
cmd: bcb: support various block device interfaces for BCB command
cmd: bcb: extend BCB C API to allow read/write the fields

 cmd/Kconfig                  |   1 -
 cmd/bcb.c                    | 206 +++++++++++++++++++++++------------
 doc/android/bcb.rst          |  34 +++---
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h                |  59 +++++++++-
 5 files changed, 227 insertions(+), 87 deletions(-)
Signature · 1 line
2.42.0.869.gea05f2083d-goog
#1 lore raw

PATCH 1/2 cmd: bcb: support various block device interfaces for BCB command

Currently BCB command-line, C APIs and implementation only support MMC interface. Extend it to allow various block device interfaces.

Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>
---
 cmd/Kconfig                  |  1 -
 cmd/bcb.c                    | 70 ++++++++++++++++++++++--------------
 doc/android/bcb.rst          | 34 +++++++++---------
 drivers/fastboot/fb_common.c |  2 +-
 include/bcb.h                |  5 +--
 5 files changed, 65 insertions(+), 47 deletions(-)
cmd/Kconfig +0 -1
index df6d71c103..ce2435bbb8 100644
@@ -981,7 +981,6 @@ config CMD_ADC
 
 config CMD_BCB
 	bool "bcb"
-	depends on MMC
 	depends on PARTITIONS
 	help
 	  Read/modify/write the fields of Bootloader Control Block, usually
cmd/bcb.c +43 -27

155 lines not on this page · raw message

doc/android/bcb.rst +18 -16
index 8861608300..2226517d39 100644
@@ -41,23 +41,25 @@ requirements enumerated above. Below is the command's help message::
    bcb - Load/set/clear/test/dump/store Android BCB fields
 
    Usage:
-   bcb load  <dev> <part>       - load  BCB from mmc <dev>:<part>
-   bcb set   <field> <val>      - set   BCB <field> to <val>
-   bcb clear [<field>]          - clear BCB <field> or all fields
-   bcb test  <field> <op> <val> - test  BCB <field> against <val>
-   bcb dump  <field>            - dump  BCB <field>
-   bcb store                    - store BCB back to mmc
+   bcb load <interface> <dev> <part>  - load  BCB from <interface> <dev>:<part>
+   load <dev> <part>              - load  BCB from mmc <dev>:<part>
+   bcb set   <field> <val>        - set   BCB <field> to <val>
+   bcb clear [<field>]            - clear BCB <field> or all fields
+   bcb test  <field> <op> <val>   - test  BCB <field> against <val>
+   bcb dump  <field>              - dump  BCB <field>
+   bcb store                      - store BCB back to <interface>
 
    Legend:
-   <dev>   - MMC device index containing the BCB partition
-   <part>  - MMC partition index or name containing the BCB
-   <field> - one of {command,status,recovery,stage,reserved}
-   <op>    - the binary operator used in 'bcb test':
-             '=' returns true if <val> matches the string stored in <field>
-             '~' returns true if <val> matches a subset of <field>'s string
-   <val>   - string/text provided as input to bcb {set,test}
-             NOTE: any ':' character in <val> will be replaced by line feed
-             during 'bcb set' and used as separator by upper layers
+   <interface> - storage device interface (virtio, mmc, etc)
+   <dev>       - storage device index containing the BCB partition
+   <part>      - partition index or name containing the BCB
+   <field>     - one of {command,status,recovery,stage,reserved}
+   <op>        - the binary operator used in 'bcb test':
+                 '=' returns true if <val> matches the string stored in <field>
+                 '~' returns true if <val> matches a subset of <field>'s string
+   <val>       - string/text provided as input to bcb {set,test}
+                 NOTE: any ':' character in <val> will be replaced by line feed
+                 during 'bcb set' and used as separator by upper layers
 
 
 'bcb'. Example of getting reboot reason
@@ -91,7 +93,7 @@ The following Kconfig options must be enabled::
 
    CONFIG_PARTITIONS=y
    CONFIG_MMC=y
-   CONFIG_BCB=y
+   CONFIG_CMD_BCB=y
 
 .. [1] https://android.googlesource.com/platform/bootable/recovery
 .. [2] https://source.android.com/devices/bootloader
drivers/fastboot/fb_common.c +1 -1
index 4e9d9b719c..2a6608b28c 100644
@@ -105,7 +105,7 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
 		return -EINVAL;
 
-	return bcb_write_reboot_reason(mmc_dev, "misc", boot_cmds[reason]);
+	return bcb_write_reboot_reason("mmc", mmc_dev, "misc", boot_cmds[reason]);
 }
 
 /**
include/bcb.h +3 -2
index 5edb17aa47..a6326523c4 100644
@@ -9,10 +9,11 @@
 #define __BCB_H__
 
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp);
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp);
 #else
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+static inline int bcb_write_reboot_reason(const char *iface, int devnum,
+					  char *partp, const char *reasonp)
 {
 	return -EOPNOTSUPP;
 }
Signature · 1 line
2.42.0.869.gea05f2083d-goog
#2 lore raw

Re: [PATCH 1/2] cmd: bcb: support various block device interfaces for BCB command

Hi Dmitrii,

Thank you for your patch.

Thank you as well for taking the time to upstream things from:
https://android.googlesource.com/platform/external/u-boot/

Quoted 11 lines · Dmitrii Merkurev

Currently BCB command-line, C APIs and implementation only support MMC interface. Extend it to allow various block device interfaces.

Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

This breaks vim3/vim3l android boot flow because both rely on the usage of the bcb command in their U-Boot environment:

Error: 1572575691 110528528: read failed (-19)
Warning: BCB is corrupted or does not exist

The following diff fixes it:

include/configs/meson64_android.h +2 -2
index c0e977abb01f..442233e827d8 100644
@@ -164,7 +164,7 @@
                        "fi; " \
                "fi;" \
                "if test \"${run_fastboot}\" -eq 0; then " \
-                       "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+                       "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                        CONTROL_PARTITION "; then " \
                                "if bcb test command = bootonce-bootloader; then " \
                                        "echo BCB: Bootloader boot...; " \
@@ -195,7 +195,7 @@
                        "echo Recovery button is pressed;" \
                        "setenv run_recovery 1;" \
                "fi; " \
-               "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+               "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                CONTROL_PARTITION "; then " \
                        "if bcb test command = boot-recovery; then " \
                                "echo BCB: Recovery boot...; " \
include/configs/ti_omap5_common.h +1 -1
index 4e5aa74147d4..f571744adaf8 100644
@@ -168,7 +168,7 @@
                "mmc dev $mmcdev; " \
                "mmc rescan; " \
                AB_SELECT_SLOT \
-               "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+               "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                CONTROL_PARTITION "; then " \
                        "setenv ardaddr -; " \
                        "if bcb test command = bootonce-bootloader; then " \

Can you consider including this as part of this patch ?

Quoted 93 lines
---
 cmd/Kconfig                  |  1 -
 cmd/bcb.c                    | 70 ++++++++++++++++++++++--------------
 doc/android/bcb.rst          | 34 +++++++++---------
 drivers/fastboot/fb_common.c |  2 +-
 include/bcb.h                |  5 +--
 5 files changed, 65 insertions(+), 47 deletions(-)
cmd/Kconfig +0 -1
index df6d71c103..ce2435bbb8 100644
@@ -981,7 +981,6 @@ config CMD_ADC
 
 config CMD_BCB
 	bool "bcb"
-	depends on MMC
 	depends on PARTITIONS
 	help
 	  Read/modify/write the fields of Bootloader Control Block, usually
cmd/bcb.c +12 -6
index 02d0c70d87..5d8c232663 100644
@@ -25,6 +25,7 @@ enum bcb_cmd {
 	BCB_CMD_STORE,
 };
 
+static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
 static int bcb_dev = -1;
 static int bcb_part = -1;
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
@@ -53,6 +54,9 @@ static int bcb_is_misused(int argc, char *const argv[])
 
 	switch (cmd) {
 	case BCB_CMD_LOAD:
+		if (argc != 3 && argc != 4)
+			goto err;
+		break;
 	case BCB_CMD_FIELD_SET:
 		if (argc != 3)
 			goto err;
@@ -115,7 +119,7 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
 	return 0;
 }
 
-static int __bcb_load(int devnum, const char *partp)
+static int __bcb_load(const char *iface, int devnum, const char *partp)
 {
 	struct blk_desc *desc;
 	struct disk_partition info;
@@ -123,14 +127,14 @@ static int __bcb_load(int devnum, const char *partp)
 	char *endp;
 	int part, ret;
 
-	desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, devnum);
+	desc = blk_get_dev(iface, devnum);
 	if (!desc) {
 		ret = -ENODEV;
 		goto err_read_fail;
 	}
 
 	/*
-	 * always select the USER mmc hwpart in case another
+	 * always select the first hwpart in case another
 	 * blk operation selected a different hwpart
 	 */
 	ret = blk_dselect_hwpart(desc, 0);
@@ -161,18 +165,20 @@ static int __bcb_load(int devnum, const char *partp)
 		goto err_read_fail;
 	}
 
+	bcb_uclass_id = desc->uclass_id;
 	bcb_dev = desc->devnum;
 	bcb_part = part;
-	debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
+	debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
 
 	return CMD_RET_SUCCESS;
 err_read_fail:
-	printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
+	printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
 	goto err;
 err_too_small:
-	printf("Error: mmc %d:%s too small!", devnum, partp);
+	printf("Error: %s %d:%s too small!", iface, devnum, partp);
 	goto err;
 err:
+	bcb_uclass_id = UCLASS_INVALID;
 	bcb_dev = -1;
 	bcb_part = -1;
 

cmd/bcb.c err: · line 193

Quoted 7 lines
cmd/bcb.c +2 -1
@@ -182,15 +188,23 @@ err:
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	int devnum;
 	char *endp;
-	int devnum = simple_strtoul(argv[1], &endp, 0);
+	char *iface = "mcc";

Should this be mmc instead of mcc ?

Quoted 176 lines
cmd/bcb.c +29 -20
+
+	if (argc == 4) {
+		iface = argv[1];
+		argc--;
+		argv++;
+	}
 
+	devnum = simple_strtoul(argv[1], &endp, 0);
 	if (*endp != '\0') {
 		printf("Error: Device id '%s' not a number\n", argv[1]);
 		return CMD_RET_FAILURE;
 	}
 
-	return __bcb_load(devnum, argv[2]);
+	return __bcb_load(iface, devnum, argv[2]);
 }
 
 static int __bcb_set(char *fieldp, const char *valp)
@@ -298,7 +312,7 @@ static int __bcb_store(void)
 	u64 cnt;
 	int ret;
 
-	desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, bcb_dev);
+	desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
 	if (!desc) {
 		ret = -ENODEV;
 		goto err;
@@ -317,7 +331,7 @@ static int __bcb_store(void)
 
 	return CMD_RET_SUCCESS;
 err:
-	printf("Error: mmc %d:%d write failed (%d)\n", bcb_dev, bcb_part, ret);
+	printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id, bcb_dev, bcb_part, ret);
 
 	return CMD_RET_FAILURE;
 }
@@ -328,11 +342,11 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
 	return __bcb_store();
 }
 
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp)
 {
 	int ret;
 
-	ret = __bcb_load(devnum, partp);
+	ret = __bcb_load(iface, devnum, partp);
 	if (ret != CMD_RET_SUCCESS)
 		return ret;
 
@@ -385,21 +399,23 @@ static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 U_BOOT_CMD(
 	bcb, CONFIG_SYS_MAXARGS, 1, do_bcb,
 	"Load/set/clear/test/dump/store Android BCB fields",
-	"load  <dev> <part>       - load  BCB from mmc <dev>:<part>\n"
-	"bcb set   <field> <val>      - set   BCB <field> to <val>\n"
-	"bcb clear [<field>]          - clear BCB <field> or all fields\n"
-	"bcb test  <field> <op> <val> - test  BCB <field> against <val>\n"
-	"bcb dump  <field>            - dump  BCB <field>\n"
-	"bcb store                    - store BCB back to mmc\n"
+	"load <interface> <dev> <part>  - load  BCB from <interface> <dev>:<part>\n"
+	"load <dev> <part>              - load  BCB from mmc <dev>:<part>\n"
+	"bcb set   <field> <val>        - set   BCB <field> to <val>\n"
+	"bcb clear [<field>]            - clear BCB <field> or all fields\n"
+	"bcb test  <field> <op> <val>   - test  BCB <field> against <val>\n"
+	"bcb dump  <field>              - dump  BCB <field>\n"
+	"bcb store                      - store BCB back to <interface>\n"
 	"\n"
 	"Legend:\n"
-	"<dev>   - MMC device index containing the BCB partition\n"
-	"<part>  - MMC partition index or name containing the BCB\n"
-	"<field> - one of {command,status,recovery,stage,reserved}\n"
-	"<op>    - the binary operator used in 'bcb test':\n"
-	"          '=' returns true if <val> matches the string stored in <field>\n"
-	"          '~' returns true if <val> matches a subset of <field>'s string\n"
-	"<val>   - string/text provided as input to bcb {set,test}\n"
-	"          NOTE: any ':' character in <val> will be replaced by line feed\n"
-	"          during 'bcb set' and used as separator by upper layers\n"
+	"<interface> - storage device interface (virtio, mmc, etc)\n"
+	"<dev>       - storage device index containing the BCB partition\n"
+	"<part>      - partition index or name containing the BCB\n"
+	"<field>     - one of {command,status,recovery,stage,reserved}\n"
+	"<op>        - the binary operator used in 'bcb test':\n"
+	"              '=' returns true if <val> matches the string stored in <field>\n"
+	"              '~' returns true if <val> matches a subset of <field>'s string\n"
+	"<val>       - string/text provided as input to bcb {set,test}\n"
+	"              NOTE: any ':' character in <val> will be replaced by line feed\n"
+	"              during 'bcb set' and used as separator by upper layers\n"
 );
doc/android/bcb.rst +18 -16
index 8861608300..2226517d39 100644
@@ -41,23 +41,25 @@ requirements enumerated above. Below is the command's help message::
    bcb - Load/set/clear/test/dump/store Android BCB fields
 
    Usage:
-   bcb load  <dev> <part>       - load  BCB from mmc <dev>:<part>
-   bcb set   <field> <val>      - set   BCB <field> to <val>
-   bcb clear [<field>]          - clear BCB <field> or all fields
-   bcb test  <field> <op> <val> - test  BCB <field> against <val>
-   bcb dump  <field>            - dump  BCB <field>
-   bcb store                    - store BCB back to mmc
+   bcb load <interface> <dev> <part>  - load  BCB from <interface> <dev>:<part>
+   load <dev> <part>              - load  BCB from mmc <dev>:<part>
+   bcb set   <field> <val>        - set   BCB <field> to <val>
+   bcb clear [<field>]            - clear BCB <field> or all fields
+   bcb test  <field> <op> <val>   - test  BCB <field> against <val>
+   bcb dump  <field>              - dump  BCB <field>
+   bcb store                      - store BCB back to <interface>
 
    Legend:
-   <dev>   - MMC device index containing the BCB partition
-   <part>  - MMC partition index or name containing the BCB
-   <field> - one of {command,status,recovery,stage,reserved}
-   <op>    - the binary operator used in 'bcb test':
-             '=' returns true if <val> matches the string stored in <field>
-             '~' returns true if <val> matches a subset of <field>'s string
-   <val>   - string/text provided as input to bcb {set,test}
-             NOTE: any ':' character in <val> will be replaced by line feed
-             during 'bcb set' and used as separator by upper layers
+   <interface> - storage device interface (virtio, mmc, etc)
+   <dev>       - storage device index containing the BCB partition
+   <part>      - partition index or name containing the BCB
+   <field>     - one of {command,status,recovery,stage,reserved}
+   <op>        - the binary operator used in 'bcb test':
+                 '=' returns true if <val> matches the string stored in <field>
+                 '~' returns true if <val> matches a subset of <field>'s string
+   <val>       - string/text provided as input to bcb {set,test}
+                 NOTE: any ':' character in <val> will be replaced by line feed
+                 during 'bcb set' and used as separator by upper layers
 
 
 'bcb'. Example of getting reboot reason
@@ -91,7 +93,7 @@ The following Kconfig options must be enabled::
 
    CONFIG_PARTITIONS=y
    CONFIG_MMC=y
-   CONFIG_BCB=y
+   CONFIG_CMD_BCB=y
 
 .. [1] https://android.googlesource.com/platform/bootable/recovery
 .. [2] https://source.android.com/devices/bootloader
drivers/fastboot/fb_common.c +1 -1
index 4e9d9b719c..2a6608b28c 100644
@@ -105,7 +105,7 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
 		return -EINVAL;
 
-	return bcb_write_reboot_reason(mmc_dev, "misc", boot_cmds[reason]);
+	return bcb_write_reboot_reason("mmc", mmc_dev, "misc", boot_cmds[reason]);
 }
 
 /**
include/bcb.h +3 -2
index 5edb17aa47..a6326523c4 100644
@@ -9,10 +9,11 @@
 #define __BCB_H__
 
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp);
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp);
 #else
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+static inline int bcb_write_reboot_reason(const char *iface, int devnum,
+					  char *partp, const char *reasonp)
 {
 	return -EOPNOTSUPP;
 }
Signature · 1 line
2.42.0.869.gea05f2083d-goog
#3 lore raw

Re: [PATCH 1/2] cmd: bcb: support various block device interfaces for BCB command

Quoted 159 lines · Mattijs Korpershoek

Hi Dmitrii,

Thank you for your patch.

Thank you as well for taking the time to upstream things from:
https://android.googlesource.com/platform/external/u-boot/

Quoted 11 lines · Dmitrii Merkurev

Currently BCB command-line, C APIs and implementation only support MMC interface. Extend it to allow various block device interfaces.

Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

This breaks vim3/vim3l android boot flow because both rely on the usage of the bcb command in their U-Boot environment:

Error: 1572575691 110528528: read failed (-19)
Warning: BCB is corrupted or does not exist

The following diff fixes it:

include/configs/meson64_android.h +2 -2
index c0e977abb01f..442233e827d8 100644
@@ -164,7 +164,7 @@
                        "fi; " \
                "fi;" \
                "if test \"${run_fastboot}\" -eq 0; then " \
-                       "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+                       "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                        CONTROL_PARTITION "; then " \
                                "if bcb test command = bootonce-bootloader; then " \
                                        "echo BCB: Bootloader boot...; " \
@@ -195,7 +195,7 @@
                        "echo Recovery button is pressed;" \
                        "setenv run_recovery 1;" \
                "fi; " \
-               "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+               "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                CONTROL_PARTITION "; then " \
                        "if bcb test command = boot-recovery; then " \
                                "echo BCB: Recovery boot...; " \
include/configs/ti_omap5_common.h +1 -1
index 4e5aa74147d4..f571744adaf8 100644
@@ -168,7 +168,7 @@
                "mmc dev $mmcdev; " \
                "mmc rescan; " \
                AB_SELECT_SLOT \
-               "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
+               "if bcb load mmc " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
                CONTROL_PARTITION "; then " \
                        "setenv ardaddr -; " \
                        "if bcb test command = bootonce-bootloader; then " \

Can you consider including this as part of this patch ?

Quoted 92 lines
---
 cmd/Kconfig                  |  1 -
 cmd/bcb.c                    | 70 ++++++++++++++++++++++--------------
 doc/android/bcb.rst          | 34 +++++++++---------
 drivers/fastboot/fb_common.c |  2 +-
 include/bcb.h                |  5 +--
 5 files changed, 65 insertions(+), 47 deletions(-)
cmd/Kconfig +0 -1
index df6d71c103..ce2435bbb8 100644
@@ -981,7 +981,6 @@ config CMD_ADC
 
 config CMD_BCB
 	bool "bcb"
-	depends on MMC
 	depends on PARTITIONS
 	help
 	  Read/modify/write the fields of Bootloader Control Block, usually
cmd/bcb.c +12 -6
index 02d0c70d87..5d8c232663 100644
@@ -25,6 +25,7 @@ enum bcb_cmd {
 	BCB_CMD_STORE,
 };
 
+static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
 static int bcb_dev = -1;
 static int bcb_part = -1;
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
@@ -53,6 +54,9 @@ static int bcb_is_misused(int argc, char *const argv[])
 
 	switch (cmd) {
 	case BCB_CMD_LOAD:
+		if (argc != 3 && argc != 4)
+			goto err;
+		break;
 	case BCB_CMD_FIELD_SET:
 		if (argc != 3)
 			goto err;
@@ -115,7 +119,7 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
 	return 0;
 }
 
-static int __bcb_load(int devnum, const char *partp)
+static int __bcb_load(const char *iface, int devnum, const char *partp)
 {
 	struct blk_desc *desc;
 	struct disk_partition info;
@@ -123,14 +127,14 @@ static int __bcb_load(int devnum, const char *partp)
 	char *endp;
 	int part, ret;
 
-	desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, devnum);
+	desc = blk_get_dev(iface, devnum);
 	if (!desc) {
 		ret = -ENODEV;
 		goto err_read_fail;
 	}
 
 	/*
-	 * always select the USER mmc hwpart in case another
+	 * always select the first hwpart in case another
 	 * blk operation selected a different hwpart
 	 */
 	ret = blk_dselect_hwpart(desc, 0);
@@ -161,18 +165,20 @@ static int __bcb_load(int devnum, const char *partp)
 		goto err_read_fail;
 	}
 
+	bcb_uclass_id = desc->uclass_id;
 	bcb_dev = desc->devnum;
 	bcb_part = part;
-	debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
+	debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
 
 	return CMD_RET_SUCCESS;
 err_read_fail:
-	printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
+	printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
 	goto err;
 err_too_small:
-	printf("Error: mmc %d:%s too small!", devnum, partp);
+	printf("Error: %s %d:%s too small!", iface, devnum, partp);
 	goto err;
 err:
+	bcb_uclass_id = UCLASS_INVALID;
 	bcb_dev = -1;
 	bcb_part = -1;
 
Quoted 10 lines

cmd/bcb.c err: · line 193

Quoted 8 lines
cmd/bcb.c +2 -1
@@ -182,15 +188,23 @@ err:
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	int devnum;
 	char *endp;
-	int devnum = simple_strtoul(argv[1], &endp, 0);
+	char *iface = "mcc";

Should this be mmc instead of mcc ?

Just to clarify: having "mmc" instead of "mcc" also fixes the bcb reading on vim3.

Quoted 177 lines
Quoted 177 lines
cmd/bcb.c +29 -20
+
+	if (argc == 4) {
+		iface = argv[1];
+		argc--;
+		argv++;
+	}
 
+	devnum = simple_strtoul(argv[1], &endp, 0);
 	if (*endp != '\0') {
 		printf("Error: Device id '%s' not a number\n", argv[1]);
 		return CMD_RET_FAILURE;
 	}
 
-	return __bcb_load(devnum, argv[2]);
+	return __bcb_load(iface, devnum, argv[2]);
 }
 
 static int __bcb_set(char *fieldp, const char *valp)
@@ -298,7 +312,7 @@ static int __bcb_store(void)
 	u64 cnt;
 	int ret;
 
-	desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, bcb_dev);
+	desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
 	if (!desc) {
 		ret = -ENODEV;
 		goto err;
@@ -317,7 +331,7 @@ static int __bcb_store(void)
 
 	return CMD_RET_SUCCESS;
 err:
-	printf("Error: mmc %d:%d write failed (%d)\n", bcb_dev, bcb_part, ret);
+	printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id, bcb_dev, bcb_part, ret);
 
 	return CMD_RET_FAILURE;
 }
@@ -328,11 +342,11 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
 	return __bcb_store();
 }
 
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp)
 {
 	int ret;
 
-	ret = __bcb_load(devnum, partp);
+	ret = __bcb_load(iface, devnum, partp);
 	if (ret != CMD_RET_SUCCESS)
 		return ret;
 
@@ -385,21 +399,23 @@ static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 U_BOOT_CMD(
 	bcb, CONFIG_SYS_MAXARGS, 1, do_bcb,
 	"Load/set/clear/test/dump/store Android BCB fields",
-	"load  <dev> <part>       - load  BCB from mmc <dev>:<part>\n"
-	"bcb set   <field> <val>      - set   BCB <field> to <val>\n"
-	"bcb clear [<field>]          - clear BCB <field> or all fields\n"
-	"bcb test  <field> <op> <val> - test  BCB <field> against <val>\n"
-	"bcb dump  <field>            - dump  BCB <field>\n"
-	"bcb store                    - store BCB back to mmc\n"
+	"load <interface> <dev> <part>  - load  BCB from <interface> <dev>:<part>\n"
+	"load <dev> <part>              - load  BCB from mmc <dev>:<part>\n"
+	"bcb set   <field> <val>        - set   BCB <field> to <val>\n"
+	"bcb clear [<field>]            - clear BCB <field> or all fields\n"
+	"bcb test  <field> <op> <val>   - test  BCB <field> against <val>\n"
+	"bcb dump  <field>              - dump  BCB <field>\n"
+	"bcb store                      - store BCB back to <interface>\n"
 	"\n"
 	"Legend:\n"
-	"<dev>   - MMC device index containing the BCB partition\n"
-	"<part>  - MMC partition index or name containing the BCB\n"
-	"<field> - one of {command,status,recovery,stage,reserved}\n"
-	"<op>    - the binary operator used in 'bcb test':\n"
-	"          '=' returns true if <val> matches the string stored in <field>\n"
-	"          '~' returns true if <val> matches a subset of <field>'s string\n"
-	"<val>   - string/text provided as input to bcb {set,test}\n"
-	"          NOTE: any ':' character in <val> will be replaced by line feed\n"
-	"          during 'bcb set' and used as separator by upper layers\n"
+	"<interface> - storage device interface (virtio, mmc, etc)\n"
+	"<dev>       - storage device index containing the BCB partition\n"
+	"<part>      - partition index or name containing the BCB\n"
+	"<field>     - one of {command,status,recovery,stage,reserved}\n"
+	"<op>        - the binary operator used in 'bcb test':\n"
+	"              '=' returns true if <val> matches the string stored in <field>\n"
+	"              '~' returns true if <val> matches a subset of <field>'s string\n"
+	"<val>       - string/text provided as input to bcb {set,test}\n"
+	"              NOTE: any ':' character in <val> will be replaced by line feed\n"
+	"              during 'bcb set' and used as separator by upper layers\n"
 );
doc/android/bcb.rst +18 -16
index 8861608300..2226517d39 100644
@@ -41,23 +41,25 @@ requirements enumerated above. Below is the command's help message::
    bcb - Load/set/clear/test/dump/store Android BCB fields
 
    Usage:
-   bcb load  <dev> <part>       - load  BCB from mmc <dev>:<part>
-   bcb set   <field> <val>      - set   BCB <field> to <val>
-   bcb clear [<field>]          - clear BCB <field> or all fields
-   bcb test  <field> <op> <val> - test  BCB <field> against <val>
-   bcb dump  <field>            - dump  BCB <field>
-   bcb store                    - store BCB back to mmc
+   bcb load <interface> <dev> <part>  - load  BCB from <interface> <dev>:<part>
+   load <dev> <part>              - load  BCB from mmc <dev>:<part>
+   bcb set   <field> <val>        - set   BCB <field> to <val>
+   bcb clear [<field>]            - clear BCB <field> or all fields
+   bcb test  <field> <op> <val>   - test  BCB <field> against <val>
+   bcb dump  <field>              - dump  BCB <field>
+   bcb store                      - store BCB back to <interface>
 
    Legend:
-   <dev>   - MMC device index containing the BCB partition
-   <part>  - MMC partition index or name containing the BCB
-   <field> - one of {command,status,recovery,stage,reserved}
-   <op>    - the binary operator used in 'bcb test':
-             '=' returns true if <val> matches the string stored in <field>
-             '~' returns true if <val> matches a subset of <field>'s string
-   <val>   - string/text provided as input to bcb {set,test}
-             NOTE: any ':' character in <val> will be replaced by line feed
-             during 'bcb set' and used as separator by upper layers
+   <interface> - storage device interface (virtio, mmc, etc)
+   <dev>       - storage device index containing the BCB partition
+   <part>      - partition index or name containing the BCB
+   <field>     - one of {command,status,recovery,stage,reserved}
+   <op>        - the binary operator used in 'bcb test':
+                 '=' returns true if <val> matches the string stored in <field>
+                 '~' returns true if <val> matches a subset of <field>'s string
+   <val>       - string/text provided as input to bcb {set,test}
+                 NOTE: any ':' character in <val> will be replaced by line feed
+                 during 'bcb set' and used as separator by upper layers
 
 
 'bcb'. Example of getting reboot reason
@@ -91,7 +93,7 @@ The following Kconfig options must be enabled::
 
    CONFIG_PARTITIONS=y
    CONFIG_MMC=y
-   CONFIG_BCB=y
+   CONFIG_CMD_BCB=y
 
 .. [1] https://android.googlesource.com/platform/bootable/recovery
 .. [2] https://source.android.com/devices/bootloader
drivers/fastboot/fb_common.c +1 -1
index 4e9d9b719c..2a6608b28c 100644
@@ -105,7 +105,7 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
 		return -EINVAL;
 
-	return bcb_write_reboot_reason(mmc_dev, "misc", boot_cmds[reason]);
+	return bcb_write_reboot_reason("mmc", mmc_dev, "misc", boot_cmds[reason]);
 }
 
 /**
include/bcb.h +3 -2
index 5edb17aa47..a6326523c4 100644
@@ -9,10 +9,11 @@
 #define __BCB_H__
 
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp);
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp);
 #else
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+static inline int bcb_write_reboot_reason(const char *iface, int devnum,
+					  char *partp, const char *reasonp)
 {
 	return -EOPNOTSUPP;
 }
Signature · 1 line
2.42.0.869.gea05f2083d-goog
#4 lore raw

Re: [PATCH 1/2] cmd: bcb: support various block device interfaces for BCB command

Thank you Mattijs for taking time to verify it, uploaded v2 with "mcc" thing fixed

Quoted 405 lines · Mattijs Korpershoek
Quoted 8 lines · Mattijs Korpershoek

Hi Dmitrii,

Thank you for your patch.

Thank you as well for taking the time to upstream things from:
https://android.googlesource.com/platform/external/u-boot/

On jeu., nov. 09, 2023 at 00:36, Dmitrii Merkurev <[email protected]>

Quoted 16 lines · wrote:
Quoted 5 lines

Currently BCB command-line, C APIs and implementation only support MMC interface. Extend it to allow various block device interfaces.

Quoted 7 lines
Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

This breaks vim3/vim3l android boot flow because both rely on the usage of the bcb command in their U-Boot environment:

Review

Quoted 6 lines

Error: 1572575691 110528528: read failed (-19)
Warning: BCB is corrupted or does not exist

The following diff fixes it:

(quoted diff) +0 -0

b/include/configs/meson64_android.h

include/configs/meson64_android.h line 167

Quoted 8 lines

index c0e977abb01f..442233e827d8 100644

include/configs/meson64_android.h +0 -1
@@ -164,7 +164,7 @@
                        "fi; " \
                "fi;" \
                "if test \"${run_fastboot}\" -eq 0; then " \
-                       "if bcb load "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

include/configs/meson64_android.h line 167

Quoted 1 line
include/configs/meson64_android.h +1 -0
+                       "if bcb load mmc "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

include/configs/meson64_android.h line 169

Quoted 2 lines
include/configs/meson64_android.h +0 -0
                        CONTROL_PARTITION "; then " \
                                "if bcb test command =

bootonce-bootloader; then " \

include/configs/meson64_android.h line 170

Quoted 1 line
include/configs/meson64_android.h +0 -0
                                        "echo BCB: Bootloader boot...; "

\

include/configs/meson64_android.h line 198

Quoted 5 lines
include/configs/meson64_android.h +0 -1
@@ -195,7 +195,7 @@
                        "echo Recovery button is pressed;" \
                        "setenv run_recovery 1;" \
                "fi; " \
-               "if bcb load "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

include/configs/meson64_android.h line 198

Quoted 1 line
include/configs/meson64_android.h +1 -0
+               "if bcb load mmc "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

Review

Quoted 4 lines
include/configs/meson64_android.h +0 -0
                CONTROL_PARTITION "; then " \
                        "if bcb test command = boot-recovery; then " \
                                "echo BCB: Recovery boot...; " \
(quoted diff) +0 -0

b/include/configs/ti_omap5_common.h

include/configs/ti_omap5_common.h line 171

Quoted 8 lines

index 4e5aa74147d4..f571744adaf8 100644

include/configs/ti_omap5_common.h +0 -1
@@ -168,7 +168,7 @@
                "mmc dev $mmcdev; " \
                "mmc rescan; " \
                AB_SELECT_SLOT \
-               "if bcb load "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

include/configs/ti_omap5_common.h line 171

Quoted 1 line
include/configs/ti_omap5_common.h +1 -0
+               "if bcb load mmc "

__stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \

include/configs/ti_omap5_common.h

Quoted 3 lines
include/configs/ti_omap5_common.h +0 -0
                CONTROL_PARTITION "; then " \
                        "setenv ardaddr -; " \
                        "if bcb test command = bootonce-bootloader; then

" \

Quoted 31 lines

Can you consider including this as part of this patch ?

Quoted 28 lines
---
 cmd/Kconfig                  |  1 -
 cmd/bcb.c                    | 70 ++++++++++++++++++++++--------------
 doc/android/bcb.rst          | 34 +++++++++---------
 drivers/fastboot/fb_common.c |  2 +-
 include/bcb.h                |  5 +--
 5 files changed, 65 insertions(+), 47 deletions(-)
cmd/Kconfig +0 -1
index df6d71c103..ce2435bbb8 100644
@@ -981,7 +981,6 @@ config CMD_ADC
 
 config CMD_BCB
     bool "bcb"
-    depends on MMC
     depends on PARTITIONS
     help
       Read/modify/write the fields of Bootloader Control Block, usually
cmd/bcb.c +0 -0
index 02d0c70d87..5d8c232663 100644
@@ -25,6 +25,7 @@ enum bcb_cmd {
     BCB_CMD_STORE,
 };
 
Quoted 4 lines

cmd/bcb.c enum bcb_cmd { · line 31

Quoted 4 lines
cmd/bcb.c +1 -0
+static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
 static int bcb_dev = -1;
 static int bcb_part = -1;
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = {

{ 0 } };

Quoted 1 line

cmd/bcb.c static int bcb_is_misused(int argc, char *const

Quoted 1 line
cmd/bcb.c +0 -0
@@ -53,6 +54,9 @@ static int bcb_is_misused(int argc, char *const

argv[])

Quoted 10 lines

cmd/bcb.c static int bcb_field_get(char *name, char **fieldp,

Quoted 10 lines
cmd/bcb.c +3 -0
     switch (cmd) {
     case BCB_CMD_LOAD:
+            if (argc != 3 && argc != 4)
+                    goto err;
+            break;
     case BCB_CMD_FIELD_SET:
             if (argc != 3)
                     goto err;
@@ -115,7 +119,7 @@ static int bcb_field_get(char *name, char **fieldp,

int *sizep)

Quoted 9 lines

cmd/bcb.c static int __bcb_load(int devnum, const char

Quoted 9 lines
cmd/bcb.c +1 -1
     return 0;
 }
 
-static int __bcb_load(int devnum, const char *partp)
+static int __bcb_load(const char *iface, int devnum, const char *partp)
 {
     struct blk_desc *desc;
     struct disk_partition info;
@@ -123,14 +127,14 @@ static int __bcb_load(int devnum, const char

*partp)

Quoted 10 lines
Quoted 10 lines
cmd/bcb.c +1 -1
     char *endp;
     int part, ret;
 
-    desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, devnum);
+    desc = blk_get_dev(iface, devnum);
     if (!desc) {
             ret = -ENODEV;
             goto err_read_fail;
     }
 
Quoted 7 lines

cmd/bcb.c static int __bcb_load(int devnum, const char

Quoted 7 lines
cmd/bcb.c +1 -1
     /*
-     * always select the USER mmc hwpart in case another
+     * always select the first hwpart in case another
      * blk operation selected a different hwpart
      */
     ret = blk_dselect_hwpart(desc, 0);
@@ -161,18 +165,20 @@ static int __bcb_load(int devnum, const char

*partp)

Quoted 8 lines

cmd/bcb.c static int __bcb_load(int devnum, const char · line 171

Quoted 8 lines
cmd/bcb.c +2 -1
             goto err_read_fail;
     }
 
+    bcb_uclass_id = desc->uclass_id;
     bcb_dev = desc->devnum;
     bcb_part = part;
-    debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
+    debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev,

bcb_part);

Quoted 5 lines

cmd/bcb.c static int __bcb_load(int devnum, const char · line 174

Quoted 5 lines
cmd/bcb.c +1 -1
     return CMD_RET_SUCCESS;
 err_read_fail:
-    printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
+    printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp,

ret);

Quoted 10 lines
Quoted 10 lines
cmd/bcb.c +2 -1
     goto err;
 err_too_small:
-    printf("Error: mmc %d:%s too small!", devnum, partp);
+    printf("Error: %s %d:%s too small!", iface, devnum, partp);
     goto err;
 err:
+    bcb_uclass_id = UCLASS_INVALID;
     bcb_dev = -1;
     bcb_part = -1;
 
Quoted 10 lines

cmd/bcb.c err: · line 193

Quoted 8 lines
cmd/bcb.c +2 -1
@@ -182,15 +188,23 @@ err:
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
                    char * const argv[])
 {
+    int devnum;
     char *endp;
-    int devnum = simple_strtoul(argv[1], &endp, 0);
+    char *iface = "mcc";

Should this be mmc instead of mcc ?

Just to clarify: having "mmc" instead of "mcc" also fixes the bcb reading on vim3.

Quoted 30 lines
Quoted 30 lines
cmd/bcb.c +9 -2
+
+    if (argc == 4) {
+            iface = argv[1];
+            argc--;
+            argv++;
+    }
 
+    devnum = simple_strtoul(argv[1], &endp, 0);
     if (*endp != '\0') {
             printf("Error: Device id '%s' not a number\n", argv[1]);
             return CMD_RET_FAILURE;
     }
 
-    return __bcb_load(devnum, argv[2]);
+    return __bcb_load(iface, devnum, argv[2]);
 }
 
 static int __bcb_set(char *fieldp, const char *valp)
@@ -298,7 +312,7 @@ static int __bcb_store(void)
     u64 cnt;
     int ret;
 
-    desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, bcb_dev);
+    desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
     if (!desc) {
             ret = -ENODEV;
             goto err;
@@ -317,7 +331,7 @@ static int __bcb_store(void)
 
Quoted 3 lines

cmd/bcb.c static int __bcb_store(void) · line 320

Quoted 3 lines
cmd/bcb.c +0 -1
     return CMD_RET_SUCCESS;
 err:
-    printf("Error: mmc %d:%d write failed (%d)\n", bcb_dev, bcb_part,

ret);

Quoted 1 line

cmd/bcb.c static int __bcb_store(void) · line 334

Quoted 1 line
cmd/bcb.c +1 -0
+    printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id,

bcb_dev, bcb_part, ret);

Quoted 4 lines

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp,

Quoted 4 lines
cmd/bcb.c +0 -0
     return CMD_RET_FAILURE;
 }
@@ -328,11 +342,11 @@ static int do_bcb_store(struct cmd_tbl *cmdtp,

int flag, int argc,

Quoted 4 lines

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, · line 331

Quoted 4 lines
cmd/bcb.c +0 -1
     return __bcb_store();
 }
 
-int bcb_write_reboot_reason(int devnum, char *partp, const char

*reasonp)

Quoted 1 line

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, · line 345

Quoted 1 line
cmd/bcb.c +1 -0
+int bcb_write_reboot_reason(const char *iface, int devnum, char

*partp, const char *reasonp)

Quoted 9 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int

Quoted 9 lines
cmd/bcb.c +1 -1
 {
     int ret;
 
-    ret = __bcb_load(devnum, partp);
+    ret = __bcb_load(iface, devnum, partp);
     if (ret != CMD_RET_SUCCESS)
             return ret;
 
@@ -385,21 +399,23 @@ static int do_bcb(struct cmd_tbl *cmdtp, int

flag, int argc, char *const argv[])

Quoted 10 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 402

Quoted 10 lines
cmd/bcb.c +1 -6
 U_BOOT_CMD(
     bcb, CONFIG_SYS_MAXARGS, 1, do_bcb,
     "Load/set/clear/test/dump/store Android BCB fields",
-    "load  <dev> <part>       - load  BCB from mmc <dev>:<part>\n"
-    "bcb set   <field> <val>      - set   BCB <field> to <val>\n"
-    "bcb clear [<field>]          - clear BCB <field> or all fields\n"
-    "bcb test  <field> <op> <val> - test  BCB <field> against <val>\n"
-    "bcb dump  <field>            - dump  BCB <field>\n"
-    "bcb store                    - store BCB back to mmc\n"
+    "load <interface> <dev> <part>  - load  BCB from <interface>

<dev>:<part>\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 403

Quoted 1 line
cmd/bcb.c +1 -0
+    "load <dev> <part>              - load  BCB from mmc

<dev>:<part>\n"

Quoted 2 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 405

Quoted 2 lines
cmd/bcb.c +2 -0
+    "bcb set   <field> <val>        - set   BCB <field> to <val>\n"
+    "bcb clear [<field>]            - clear BCB <field> or all

fields\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 406

Quoted 1 line
cmd/bcb.c +1 -0
+    "bcb test  <field> <op> <val>   - test  BCB <field> against

<val>\n"

Quoted 9 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 400

Quoted 9 lines
cmd/bcb.c +2 -5
+    "bcb dump  <field>              - dump  BCB <field>\n"
+    "bcb store                      - store BCB back to <interface>\n"
     "\n"
     "Legend:\n"
-    "<dev>   - MMC device index containing the BCB partition\n"
-    "<part>  - MMC partition index or name containing the BCB\n"
-    "<field> - one of {command,status,recovery,stage,reserved}\n"
-    "<op>    - the binary operator used in 'bcb test':\n"
-    "          '=' returns true if <val> matches the string stored in

<field>\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 401

Quoted 1 line
cmd/bcb.c +0 -1
-    "          '~' returns true if <val> matches a subset of <field>'s

string\n"

Quoted 2 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 403

Quoted 2 lines
cmd/bcb.c +0 -2
-    "<val>   - string/text provided as input to bcb {set,test}\n"
-    "          NOTE: any ':' character in <val> will be replaced by

line feed\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 404

Quoted 1 line
cmd/bcb.c +0 -1
-    "          during 'bcb set' and used as separator by upper

layers\n"

Quoted 6 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 416

Quoted 6 lines
cmd/bcb.c +6 -0
+    "<interface> - storage device interface (virtio, mmc, etc)\n"
+    "<dev>       - storage device index containing the BCB partition\n"
+    "<part>      - partition index or name containing the BCB\n"
+    "<field>     - one of {command,status,recovery,stage,reserved}\n"
+    "<op>        - the binary operator used in 'bcb test':\n"
+    "              '=' returns true if <val> matches the string stored

in <field>\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 417

Quoted 1 line
cmd/bcb.c +1 -0
+    "              '~' returns true if <val> matches a subset of

<field>'s string\n"

Quoted 2 lines

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 419

Quoted 2 lines
cmd/bcb.c +2 -0
+    "<val>       - string/text provided as input to bcb {set,test}\n"
+    "              NOTE: any ':' character in <val> will be replaced

by line feed\n"

Quoted 1 line

cmd/bcb.c static int do_bcb(struct cmd_tbl *cmdtp, int · line 420

Quoted 1 line
cmd/bcb.c +1 -0
+    "              during 'bcb set' and used as separator by upper

layers\n"

Quoted 6 lines

doc/android/bcb.rst requirements enumerated above. Below is the

Quoted 6 lines
cmd/bcb.c +0 -0
 );
doc/android/bcb.rst +0 -0
index 8861608300..2226517d39 100644
@@ -41,23 +41,25 @@ requirements enumerated above. Below is the

command's help message::

Quoted 10 lines

doc/android/bcb.rst requirements enumerated above. Below is the · line 44

Quoted 10 lines
doc/android/bcb.rst +1 -6
    bcb - Load/set/clear/test/dump/store Android BCB fields
 
    Usage:
-   bcb load  <dev> <part>       - load  BCB from mmc <dev>:<part>
-   bcb set   <field> <val>      - set   BCB <field> to <val>
-   bcb clear [<field>]          - clear BCB <field> or all fields
-   bcb test  <field> <op> <val> - test  BCB <field> against <val>
-   bcb dump  <field>            - dump  BCB <field>
-   bcb store                    - store BCB back to mmc
+   bcb load <interface> <dev> <part>  - load  BCB from <interface>

<dev>:<part>

Quoted 7 lines
Quoted 7 lines
doc/android/bcb.rst +6 -0
+   load <dev> <part>              - load  BCB from mmc <dev>:<part>
+   bcb set   <field> <val>        - set   BCB <field> to <val>
+   bcb clear [<field>]            - clear BCB <field> or all fields
+   bcb test  <field> <op> <val>   - test  BCB <field> against <val>
+   bcb dump  <field>              - dump  BCB <field>
+   bcb store                      - store BCB back to <interface>
 
Quoted 6 lines

doc/android/bcb.rst requirements enumerated above. Below is the · line 56

Quoted 6 lines
doc/android/bcb.rst +0 -5
    Legend:
-   <dev>   - MMC device index containing the BCB partition
-   <part>  - MMC partition index or name containing the BCB
-   <field> - one of {command,status,recovery,stage,reserved}
-   <op>    - the binary operator used in 'bcb test':
-             '=' returns true if <val> matches the string stored in

<field>

Quoted 1 line

doc/android/bcb.rst requirements enumerated above. Below is the · line 57

Quoted 1 line
doc/android/bcb.rst +0 -1
-             '~' returns true if <val> matches a subset of <field>'s

string

Quoted 2 lines

doc/android/bcb.rst requirements enumerated above. Below is the · line 59

Quoted 2 lines
doc/android/bcb.rst +0 -2
-   <val>   - string/text provided as input to bcb {set,test}
-             NOTE: any ':' character in <val> will be replaced by line

feed

Quoted 7 lines

doc/android/bcb.rst requirements enumerated above. Below is the · line 58

Quoted 7 lines
doc/android/bcb.rst +6 -1
-             during 'bcb set' and used as separator by upper layers
+   <interface> - storage device interface (virtio, mmc, etc)
+   <dev>       - storage device index containing the BCB partition
+   <part>      - partition index or name containing the BCB
+   <field>     - one of {command,status,recovery,stage,reserved}
+   <op>        - the binary operator used in 'bcb test':
+                 '=' returns true if <val> matches the string stored

in <field>

Quoted 1 line

doc/android/bcb.rst requirements enumerated above. Below is the · line 59

Quoted 1 line
doc/android/bcb.rst +1 -0
+                 '~' returns true if <val> matches a subset of

<field>'s string

Quoted 2 lines

doc/android/bcb.rst requirements enumerated above. Below is the · line 61

Quoted 2 lines
doc/android/bcb.rst +2 -0
+   <val>       - string/text provided as input to bcb {set,test}
+                 NOTE: any ':' character in <val> will be replaced by

line feed

Quoted 11 lines
Quoted 11 lines
doc/android/bcb.rst +2 -1
+                 during 'bcb set' and used as separator by upper layers
 
 
 'bcb'. Example of getting reboot reason
@@ -91,7 +93,7 @@ The following Kconfig options must be enabled::
 
    CONFIG_PARTITIONS=y
    CONFIG_MMC=y
-   CONFIG_BCB=y
+   CONFIG_CMD_BCB=y
 
Quoted 7 lines

drivers/fastboot/fb_common.c int __weak fastboot_set_reboot_flag(enum

Quoted 7 lines
doc/android/bcb.rst +0 -0
 .. [1] https://android.googlesource.com/platform/bootable/recovery
 .. [2] https://source.android.com/devices/bootloader
drivers/fastboot/fb_common.c +0 -0
index 4e9d9b719c..2a6608b28c 100644
@@ -105,7 +105,7 @@ int __weak fastboot_set_reboot_flag(enum

fastboot_reboot_reason reason)

Quoted 5 lines

drivers/fastboot/fb_common.c int __weak fastboot_set_reboot_flag(enum · line 108

Quoted 5 lines
drivers/fastboot/fb_common.c +1 -1
     if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
             return -EINVAL;
 
-    return bcb_write_reboot_reason(mmc_dev, "misc", boot_cmds[reason]);
+    return bcb_write_reboot_reason("mmc", mmc_dev, "misc",

boot_cmds[reason]);

Quoted 10 lines
Quoted 10 lines
drivers/fastboot/fb_common.c +0 -0
 }
 
 /**
include/bcb.h +0 -0
index 5edb17aa47..a6326523c4 100644
@@ -9,10 +9,11 @@
 #define __BCB_H__
 
Quoted 2 lines

include/bcb.h line 12

Quoted 2 lines
include/bcb.h +0 -1
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(int devnum, char *partp, const char

*reasonp);

Quoted 1 line

include/bcb.h line 12

Quoted 1 line
include/bcb.h +1 -0
+int bcb_write_reboot_reason(const char *iface, int devnum, char

*partp, const char *reasonp);

Quoted 3 lines

include/bcb.h line 15

Quoted 3 lines
include/bcb.h +0 -1
 #else
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(int devnum, char *partp,

const char *reasonp)

Quoted 1 line

include/bcb.h line 15

Quoted 1 line
include/bcb.h +1 -0
+static inline int bcb_write_reboot_reason(const char *iface, int

devnum,

Quoted 6 lines
Quoted 6 lines
include/bcb.h +1 -1
+                                      char *partp, const char *reasonp)
 {
     return -EOPNOTSUPP;
 }
--

2.42.0.869.gea05f2083d-goog

#5 lore raw

PATCH 2/2 cmd: bcb: extend BCB C API to allow read/write the fields

In reply to Dmitrii Merkurev

Currently BCB C API only allows to modify 'command' BCB field. Extend it so that we can also read and modify all the available BCB fields (command, status, recovery, stage).

Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>
---
 cmd/bcb.c                    | 162 +++++++++++++++++++++++------------
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h                |  60 ++++++++++++-
 3 files changed, 179 insertions(+), 57 deletions(-)
cmd/bcb.c +109 -53
index 5d8c232663..7a77b7f7b0 100644
@@ -25,10 +25,18 @@ enum bcb_cmd {
 	BCB_CMD_STORE,
 };
 
-static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
-static int bcb_dev = -1;
-static int bcb_part = -1;
+static const char * const fields[] = {
+	"command",
+	"status",
+	"recovery",
+	"stage"
+};
+
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
+static struct disk_partition partition_data;
+
+static struct blk_desc *block;
+static struct disk_partition *partition = &partition_data;
 
 static int bcb_cmd_get(char *cmd)
 {
@@ -82,7 +90,7 @@ static int bcb_is_misused(int argc, char *const argv[])
 		return -1;
 	}
 
-	if (cmd != BCB_CMD_LOAD && (bcb_dev < 0 || bcb_part < 0)) {
+	if (cmd != BCB_CMD_LOAD && !block) {
 		printf("Error: Please, load BCB first!\n");
 		return -1;
 	}
@@ -94,7 +102,7 @@ err:
 	return -1;
 }
 
-static int bcb_field_get(char *name, char **fieldp, int *sizep)
+static int bcb_field_get(const char *name, char **fieldp, int *sizep)
 {
 	if (!strcmp(name, "command")) {
 		*fieldp = bcb.command;
@@ -119,16 +127,21 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
 	return 0;
 }
 
-static int __bcb_load(const char *iface, int devnum, const char *partp)
+static void __bcb_reset(void)
+{
+	block = NULL;
+	partition = &partition_data;
+	memset(&partition_data, 0, sizeof(struct disk_partition));
+	memset(&bcb, 0, sizeof(struct bootloader_message));
+}
+
+static int __bcb_initialize(const char *iface, int devnum, const char *partp)
 {
-	struct blk_desc *desc;
-	struct disk_partition info;
-	u64 cnt;
 	char *endp;
 	int part, ret;
 
-	desc = blk_get_dev(iface, devnum);
-	if (!desc) {
+	block = blk_get_dev(iface, devnum);
+	if (!block) {
 		ret = -ENODEV;
 		goto err_read_fail;
 	}
@@ -137,7 +150,7 @@ static int __bcb_load(const char *iface, int devnum, const char *partp)
 	 * always select the first hwpart in case another
 	 * blk operation selected a different hwpart
 	 */
-	ret = blk_dselect_hwpart(desc, 0);
+	ret = blk_dselect_hwpart(block, 0);
 	if (IS_ERR_VALUE(ret)) {
 		ret = -ENODEV;
 		goto err_read_fail;
@@ -145,49 +158,63 @@ static int __bcb_load(const char *iface, int devnum, const char *partp)
 
 	part = simple_strtoul(partp, &endp, 0);
 	if (*endp == '\0') {
-		ret = part_get_info(desc, part, &info);
+		ret = part_get_info(block, part, partition);
 		if (ret)
 			goto err_read_fail;
 	} else {
-		part = part_get_info_by_name(desc, partp, &info);
+		part = part_get_info_by_name(block, partp, partition);
 		if (part < 0) {
 			ret = part;
 			goto err_read_fail;
 		}
 	}
 
-	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
-	if (cnt > info.size)
+	return CMD_RET_SUCCESS;
+
+err_read_fail:
+	printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
+	goto err;
+err:
+	__bcb_reset();
+	return CMD_RET_FAILURE;
+}
+
+static int __bcb_load(void)
+{
+	u64 cnt;
+	int ret;
+
+	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
+	if (cnt > partition->size)
 		goto err_too_small;
 
-	if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
+	if (blk_dread(block, partition->start, cnt, &bcb) != cnt) {
 		ret = -EIO;
 		goto err_read_fail;
 	}
 
-	bcb_uclass_id = desc->uclass_id;
-	bcb_dev = desc->devnum;
-	bcb_part = part;
-	debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
+	debug("%s: Loaded from %d %d:%s\n", __func__, block->uclass_id,
+	      block->devnum, partition->name);
 
 	return CMD_RET_SUCCESS;
 err_read_fail:
-	printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
+	printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
 	goto err;
 err_too_small:
-	printf("Error: %s %d:%s too small!", iface, devnum, partp);
+	printf("Error: %d %d:%s too small!", block->uclass_id,
+	       block->devnum, partition->name);
 	goto err;
 err:
-	bcb_uclass_id = UCLASS_INVALID;
-	bcb_dev = -1;
-	bcb_part = -1;
-
+	__bcb_reset();
 	return CMD_RET_FAILURE;
 }
 
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	int ret;
 	int devnum;
 	char *endp;
 	char *iface = "mcc";
@@ -204,10 +231,14 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 
-	return __bcb_load(iface, devnum, argv[2]);
+	ret = __bcb_initialize(iface, devnum, argv[2]);
+	if (ret != CMD_RET_SUCCESS)
+		return ret;
+
+	return __bcb_load();
 }
 
-static int __bcb_set(char *fieldp, const char *valp)
+static int __bcb_set(const char *fieldp, const char *valp)
 {
 	int size, len;
 	char *field, *str, *found, *tmp;
@@ -307,31 +338,20 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,
 
 static int __bcb_store(void)
 {
-	struct blk_desc *desc;
-	struct disk_partition info;
 	u64 cnt;
 	int ret;
 
-	desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
-	if (!desc) {
-		ret = -ENODEV;
-		goto err;
-	}
-
-	ret = part_get_info(desc, bcb_part, &info);
-	if (ret)
-		goto err;
-
-	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
+	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
 
-	if (blk_dwrite(desc, info.start, cnt, &bcb) != cnt) {
+	if (blk_dwrite(block, partition->start, cnt, &bcb) != cnt) {
 		ret = -EIO;
 		goto err;
 	}
 
 	return CMD_RET_SUCCESS;
 err:
-	printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id, bcb_dev, bcb_part, ret);
+	printf("Error: %d %d:%s write failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
 
 	return CMD_RET_FAILURE;
 }
@@ -342,23 +362,59 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
 	return __bcb_store();
 }
 
-int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp)
+int bcb_find_partition_and_load(const char *iface, int devnum, char *partp)
 {
 	int ret;
 
-	ret = __bcb_load(iface, devnum, partp);
-	if (ret != CMD_RET_SUCCESS)
-		return ret;
+	__bcb_reset();
 
-	ret = __bcb_set("command", reasonp);
+	ret = __bcb_initialize(iface, devnum, partp);
 	if (ret != CMD_RET_SUCCESS)
 		return ret;
 
-	ret = __bcb_store();
-	if (ret != CMD_RET_SUCCESS)
-		return ret;
+	return __bcb_load();
+}
 
-	return 0;
+int bcb_load(struct blk_desc *block_description, struct disk_partition *disk_partition)
+{
+	__bcb_reset();
+
+	block = block_description;
+	partition = disk_partition;
+
+	return __bcb_load();
+}
+
+int bcb_set(enum bcb_field field, const char *value)
+{
+	if (field > BCB_FIELD_STAGE)
+		return CMD_RET_FAILURE;
+	return __bcb_set(fields[field], value);
+}
+
+int bcb_get(enum bcb_field field, char *value_out, size_t value_size)
+{
+	int size;
+	char *field_value;
+
+	if (field > BCB_FIELD_STAGE)
+		return CMD_RET_FAILURE;
+	if (bcb_field_get(fields[field], &field_value, &size))
+		return CMD_RET_FAILURE;
+
+	strlcpy(value_out, field_value, value_size);
+
+	return CMD_RET_SUCCESS;
+}
+
+int bcb_store(void)
+{
+	return __bcb_store();
+}
+
+void bcb_reset(void)
+{
+	__bcb_reset();
 }
 
 static struct cmd_tbl cmd_bcb_sub[] = {
drivers/fastboot/fb_common.c +13 -1
index 2a6608b28c..3576b06772 100644
@@ -91,6 +91,7 @@ void fastboot_okay(const char *reason, char *response)
  */
 int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 {
+	int ret;
 	static const char * const boot_cmds[] = {
 		[FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
 		[FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
@@ -105,7 +106,18 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
 		return -EINVAL;
 
-	return bcb_write_reboot_reason("mmc", mmc_dev, "misc", boot_cmds[reason]);
+	ret = bcb_find_partition_and_load("mmc", mmc_dev, "misc");
+	if (ret)
+		goto out;
+
+	ret = bcb_set(BCB_FIELD_COMMAND, boot_cmds[reason]);
+	if (ret)
+		goto out;
+
+	ret = bcb_store();
+out:
+	bcb_reset();
+	return ret;
 }
 
 /**
include/bcb.h +57 -3

72 lines not on this page · raw message

Signature · 1 line
2.42.0.869.gea05f2083d-goog
Tested-by Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] cmd: bcb: extend BCB C API to allow read/write the fields

Hi Dmitrii,

Thank you for your patch.

Quoted 4 lines · Dmitrii Merkurev

Currently BCB C API only allows to modify 'command' BCB field. Extend it so that we can also read and modify all the available BCB fields (command, status, recovery, stage).

Quoted 9 lines
Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

I could test this after applying the diffs from:
https://lore.kernel.org/all/[email protected]/

I tested with:

$ fastboot reboot bootloader
=> bcb load mmc 2 misc
=> bcb dump command

I also tested
=> bcb set status hello
=> bcb dump status

Some small nitpicks below.
The nitpick do not have to be adressed if you don't want to.

Quoted 102 lines
---
 cmd/bcb.c                    | 162 +++++++++++++++++++++++------------
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h                |  60 ++++++++++++-
 3 files changed, 179 insertions(+), 57 deletions(-)
cmd/bcb.c +27 -14
index 5d8c232663..7a77b7f7b0 100644
@@ -25,10 +25,18 @@ enum bcb_cmd {
 	BCB_CMD_STORE,
 };
 
-static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
-static int bcb_dev = -1;
-static int bcb_part = -1;
+static const char * const fields[] = {
+	"command",
+	"status",
+	"recovery",
+	"stage"
+};
+
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
+static struct disk_partition partition_data;
+
+static struct blk_desc *block;
+static struct disk_partition *partition = &partition_data;
 
 static int bcb_cmd_get(char *cmd)
 {
@@ -82,7 +90,7 @@ static int bcb_is_misused(int argc, char *const argv[])
 		return -1;
 	}
 
-	if (cmd != BCB_CMD_LOAD && (bcb_dev < 0 || bcb_part < 0)) {
+	if (cmd != BCB_CMD_LOAD && !block) {
 		printf("Error: Please, load BCB first!\n");
 		return -1;
 	}
@@ -94,7 +102,7 @@ err:
 	return -1;
 }
 
-static int bcb_field_get(char *name, char **fieldp, int *sizep)
+static int bcb_field_get(const char *name, char **fieldp, int *sizep)
 {
 	if (!strcmp(name, "command")) {
 		*fieldp = bcb.command;
@@ -119,16 +127,21 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
 	return 0;
 }
 
-static int __bcb_load(const char *iface, int devnum, const char *partp)
+static void __bcb_reset(void)
+{
+	block = NULL;
+	partition = &partition_data;
+	memset(&partition_data, 0, sizeof(struct disk_partition));
+	memset(&bcb, 0, sizeof(struct bootloader_message));
+}
+
+static int __bcb_initialize(const char *iface, int devnum, const char *partp)
 {
-	struct blk_desc *desc;
-	struct disk_partition info;
-	u64 cnt;
 	char *endp;
 	int part, ret;
 
-	desc = blk_get_dev(iface, devnum);
-	if (!desc) {
+	block = blk_get_dev(iface, devnum);
+	if (!block) {
 		ret = -ENODEV;
 		goto err_read_fail;
 	}
@@ -137,7 +150,7 @@ static int __bcb_load(const char *iface, int devnum, const char *partp)
 	 * always select the first hwpart in case another
 	 * blk operation selected a different hwpart
 	 */
-	ret = blk_dselect_hwpart(desc, 0);
+	ret = blk_dselect_hwpart(block, 0);
 	if (IS_ERR_VALUE(ret)) {
 		ret = -ENODEV;
 		goto err_read_fail;
@@ -145,49 +158,63 @@ static int __bcb_load(const char *iface, int devnum, const char *partp)
 
 	part = simple_strtoul(partp, &endp, 0);
 	if (*endp == '\0') {
-		ret = part_get_info(desc, part, &info);
+		ret = part_get_info(block, part, partition);
 		if (ret)
 			goto err_read_fail;
 	} else {
-		part = part_get_info_by_name(desc, partp, &info);
+		part = part_get_info_by_name(block, partp, partition);
 		if (part < 0) {
 			ret = part;
 			goto err_read_fail;
 		}

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp) · line 177

Quoted 10 lines
cmd/bcb.c +6 -2
 	}
 
-	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
-	if (cnt > info.size)
+	return CMD_RET_SUCCESS;
+
+err_read_fail:
+	printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
+	goto err;

Nitpick: No need for this goto, we can just fall-through.

Quoted 34 lines
cmd/bcb.c +17 -6
+err:
+	__bcb_reset();
+	return CMD_RET_FAILURE;
+}
+
+static int __bcb_load(void)
+{
+	u64 cnt;
+	int ret;
+
+	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
+	if (cnt > partition->size)
 		goto err_too_small;
 
-	if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
+	if (blk_dread(block, partition->start, cnt, &bcb) != cnt) {
 		ret = -EIO;
 		goto err_read_fail;
 	}
 
-	bcb_uclass_id = desc->uclass_id;
-	bcb_dev = desc->devnum;
-	bcb_part = part;
-	debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
+	debug("%s: Loaded from %d %d:%s\n", __func__, block->uclass_id,
+	      block->devnum, partition->name);
 
 	return CMD_RET_SUCCESS;
 err_read_fail:
-	printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
+	printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
 	goto err;
 err_too_small:

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp) · line 210

Quoted 10 lines
cmd/bcb.c +3 -5
-	printf("Error: %s %d:%s too small!", iface, devnum, partp);
+	printf("Error: %d %d:%s too small!", block->uclass_id,
+	       block->devnum, partition->name);
 	goto err;
 err:
-	bcb_uclass_id = UCLASS_INVALID;
-	bcb_dev = -1;
-	bcb_part = -1;
-
+	__bcb_reset();

Nitpick: __bcb_reset() introduction could have been done in a separate patch

Quoted 243 lines
cmd/bcb.c +56 -26
 	return CMD_RET_FAILURE;
 }
 
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
+	int ret;
 	int devnum;
 	char *endp;
 	char *iface = "mcc";
@@ -204,10 +231,14 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 
-	return __bcb_load(iface, devnum, argv[2]);
+	ret = __bcb_initialize(iface, devnum, argv[2]);
+	if (ret != CMD_RET_SUCCESS)
+		return ret;
+
+	return __bcb_load();
 }
 
-static int __bcb_set(char *fieldp, const char *valp)
+static int __bcb_set(const char *fieldp, const char *valp)
 {
 	int size, len;
 	char *field, *str, *found, *tmp;
@@ -307,31 +338,20 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,
 
 static int __bcb_store(void)
 {
-	struct blk_desc *desc;
-	struct disk_partition info;
 	u64 cnt;
 	int ret;
 
-	desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
-	if (!desc) {
-		ret = -ENODEV;
-		goto err;
-	}
-
-	ret = part_get_info(desc, bcb_part, &info);
-	if (ret)
-		goto err;
-
-	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
+	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
 
-	if (blk_dwrite(desc, info.start, cnt, &bcb) != cnt) {
+	if (blk_dwrite(block, partition->start, cnt, &bcb) != cnt) {
 		ret = -EIO;
 		goto err;
 	}
 
 	return CMD_RET_SUCCESS;
 err:
-	printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id, bcb_dev, bcb_part, ret);
+	printf("Error: %d %d:%s write failed (%d)\n", block->uclass_id,
+	       block->devnum, partition->name, ret);
 
 	return CMD_RET_FAILURE;
 }
@@ -342,23 +362,59 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
 	return __bcb_store();
 }
 
-int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp)
+int bcb_find_partition_and_load(const char *iface, int devnum, char *partp)
 {
 	int ret;
 
-	ret = __bcb_load(iface, devnum, partp);
-	if (ret != CMD_RET_SUCCESS)
-		return ret;
+	__bcb_reset();
 
-	ret = __bcb_set("command", reasonp);
+	ret = __bcb_initialize(iface, devnum, partp);
 	if (ret != CMD_RET_SUCCESS)
 		return ret;
 
-	ret = __bcb_store();
-	if (ret != CMD_RET_SUCCESS)
-		return ret;
+	return __bcb_load();
+}
 
-	return 0;
+int bcb_load(struct blk_desc *block_description, struct disk_partition *disk_partition)
+{
+	__bcb_reset();
+
+	block = block_description;
+	partition = disk_partition;
+
+	return __bcb_load();
+}
+
+int bcb_set(enum bcb_field field, const char *value)
+{
+	if (field > BCB_FIELD_STAGE)
+		return CMD_RET_FAILURE;
+	return __bcb_set(fields[field], value);
+}
+
+int bcb_get(enum bcb_field field, char *value_out, size_t value_size)
+{
+	int size;
+	char *field_value;
+
+	if (field > BCB_FIELD_STAGE)
+		return CMD_RET_FAILURE;
+	if (bcb_field_get(fields[field], &field_value, &size))
+		return CMD_RET_FAILURE;
+
+	strlcpy(value_out, field_value, value_size);
+
+	return CMD_RET_SUCCESS;
+}
+
+int bcb_store(void)
+{
+	return __bcb_store();
+}
+
+void bcb_reset(void)
+{
+	__bcb_reset();
 }
 
 static struct cmd_tbl cmd_bcb_sub[] = {
drivers/fastboot/fb_common.c +13 -1
index 2a6608b28c..3576b06772 100644
@@ -91,6 +91,7 @@ void fastboot_okay(const char *reason, char *response)
  */
 int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 {
+	int ret;
 	static const char * const boot_cmds[] = {
 		[FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
 		[FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
@@ -105,7 +106,18 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
 		return -EINVAL;
 
-	return bcb_write_reboot_reason("mmc", mmc_dev, "misc", boot_cmds[reason]);
+	ret = bcb_find_partition_and_load("mmc", mmc_dev, "misc");
+	if (ret)
+		goto out;
+
+	ret = bcb_set(BCB_FIELD_COMMAND, boot_cmds[reason]);
+	if (ret)
+		goto out;
+
+	ret = bcb_store();
+out:
+	bcb_reset();
+	return ret;
 }
 
 /**
include/bcb.h +57 -3
index a6326523c4..1941d8c28b 100644
@@ -8,15 +8,69 @@
 #ifndef __BCB_H__
 #define __BCB_H__
 
+#include <part.h>
+
+enum bcb_field {
+	BCB_FIELD_COMMAND,
+	BCB_FIELD_STATUS,
+	BCB_FIELD_RECOVERY,
+	BCB_FIELD_STAGE
+};
+
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const char *reasonp);
+
+int bcb_find_partition_and_load(const char *iface,
+				int devnum, char *partp);
+int bcb_load(struct blk_desc *block_description,
+	     struct disk_partition *disk_partition);
+int bcb_set(enum bcb_field field, const char *value);
+
+/**
+ * bcb_get() - get the field value.
+ * @field: field to get
+ * @value_out: buffer to copy bcb field value to
+ * @value_size: buffer size to avoid overflow in case
+ *              value_out is smaller then the field value
+ */
+int bcb_get(enum bcb_field field, char *value_out, size_t value_size);
+
+int bcb_store(void);
+void bcb_reset(void);
+
 #else
+
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(const char *iface, int devnum,
-					  char *partp, const char *reasonp)
+
+static inline int bcb_load(struct blk_desc *block_description,
+			   struct disk_partition *disk_partition)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline int bcb_find_partition_and_load(const char *iface,
+					      int devnum, char *partp)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline int bcb_set(enum bcb_field field, const char *value)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline int bcb_get(enum bcb_field field, char *value_out)
 {
 	return -EOPNOTSUPP;
 }
+
+static inline int bcb_store(void)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void bcb_reset(void)
+{
+}
 #endif
 
 #endif /* __BCB_H__ */
Signature · 1 line
2.42.0.869.gea05f2083d-goog
#7 lore raw

Re: [PATCH 2/2] cmd: bcb: extend BCB C API to allow read/write the fields

Uploaded v2 with fixes

Quoted 467 lines · Mattijs Korpershoek

Hi Dmitrii,

Thank you for your patch.

Quoted 4 lines · Dmitrii Merkurev

Currently BCB C API only allows to modify 'command' BCB field. Extend it so that we can also read and modify all the available BCB fields (command, status, recovery, stage).

Quoted 9 lines
Cc Eugeniu Rosca <[email protected]>
Cc Ying-Chun Liu (PaulLiu) <[email protected]>
Cc Simon Glass <[email protected]>
Cc Mattijs Korpershoek <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Cody Schuffelen <[email protected]>

I could test this after applying the diffs from:
https://lore.kernel.org/all/[email protected]/

I tested with:

$ fastboot reboot bootloader
=> bcb load mmc 2 misc
=> bcb dump command

I also tested
=> bcb set status hello
=> bcb dump status

Some small nitpicks below.
The nitpick do not have to be adressed if you don't want to.

Quoted 15 lines
---
 cmd/bcb.c                    | 162 +++++++++++++++++++++++------------
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h                |  60 ++++++++++++-
 3 files changed, 179 insertions(+), 57 deletions(-)
cmd/bcb.c +0 -1
index 5d8c232663..7a77b7f7b0 100644
@@ -25,10 +25,18 @@ enum bcb_cmd {
      BCB_CMD_STORE,
 };
 
-static enum uclass_id bcb_uclass_id = UCLASS_INVALID;

cmd/bcb.c enum bcb_cmd { · line 35

Quoted 10 lines
cmd/bcb.c +7 -2
-static int bcb_dev = -1;
-static int bcb_part = -1;
+static const char * const fields[] = {
+     "command",
+     "status",
+     "recovery",
+     "stage"
+};
+
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { {

0 } };

cmd/bcb.c static int bcb_field_get(char *name, char

Quoted 26 lines
cmd/bcb.c +6 -2
+static struct disk_partition partition_data;
+
+static struct blk_desc *block;
+static struct disk_partition *partition = &partition_data;
 
 static int bcb_cmd_get(char *cmd)
 {
@@ -82,7 +90,7 @@ static int bcb_is_misused(int argc, char *const argv[])
              return -1;
      }
 
-     if (cmd != BCB_CMD_LOAD && (bcb_dev < 0 || bcb_part < 0)) {
+     if (cmd != BCB_CMD_LOAD && !block) {
              printf("Error: Please, load BCB first!\n");
              return -1;
      }
@@ -94,7 +102,7 @@ err:
      return -1;
 }
 
-static int bcb_field_get(char *name, char **fieldp, int *sizep)
+static int bcb_field_get(const char *name, char **fieldp, int *sizep)
 {
      if (!strcmp(name, "command")) {
              *fieldp = bcb.command;
@@ -119,16 +127,21 @@ static int bcb_field_get(char *name, char

**fieldp, int *sizep)

cmd/bcb.c static int bcb_field_get(char *name, char **fieldp, int *sizep)

Quoted 13 lines
cmd/bcb.c +9 -1
      return 0;
 }
 
-static int __bcb_load(const char *iface, int devnum, const char *partp)
+static void __bcb_reset(void)
+{
+     block = NULL;
+     partition = &partition_data;
+     memset(&partition_data, 0, sizeof(struct disk_partition));
+     memset(&bcb, 0, sizeof(struct bootloader_message));
+}
+
+static int __bcb_initialize(const char *iface, int devnum, const char

*partp)

cmd/bcb.c static int __bcb_load(const char *iface, int devnum,

Quoted 15 lines
cmd/bcb.c +2 -5
 {
-     struct blk_desc *desc;
-     struct disk_partition info;
-     u64 cnt;
      char *endp;
      int part, ret;
 
-     desc = blk_get_dev(iface, devnum);
-     if (!desc) {
+     block = blk_get_dev(iface, devnum);
+     if (!block) {
              ret = -ENODEV;
              goto err_read_fail;
      }
@@ -137,7 +150,7 @@ static int __bcb_load(const char *iface, int devnum,

const char *partp)

cmd/bcb.c static int __bcb_load(const char *iface, int

Quoted 9 lines
cmd/bcb.c +1 -1
       * always select the first hwpart in case another
       * blk operation selected a different hwpart
       */
-     ret = blk_dselect_hwpart(desc, 0);
+     ret = blk_dselect_hwpart(block, 0);
      if (IS_ERR_VALUE(ret)) {
              ret = -ENODEV;
              goto err_read_fail;
@@ -145,49 +158,63 @@ static int __bcb_load(const char *iface, int

devnum, const char *partp)

Quoted 14 lines
cmd/bcb.c +2 -2
      part = simple_strtoul(partp, &endp, 0);
      if (*endp == '\0') {
-             ret = part_get_info(desc, part, &info);
+             ret = part_get_info(block, part, partition);
              if (ret)
                      goto err_read_fail;
      } else {
-             part = part_get_info_by_name(desc, partp, &info);
+             part = part_get_info_by_name(block, partp, partition);
              if (part < 0) {
                      ret = part;
                      goto err_read_fail;
              }

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp) · line 177

Quoted 10 lines
cmd/bcb.c +6 -2
      }
 
-     cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
-     if (cnt > info.size)
+     return CMD_RET_SUCCESS;
+
+err_read_fail:
+     printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+            block->devnum, partition->name, ret);
+     goto err;

Nitpick: No need for this goto, we can just fall-through.

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp)

Quoted 11 lines
cmd/bcb.c +11 -0
+err:
+     __bcb_reset();
+     return CMD_RET_FAILURE;
+}
+
+static int __bcb_load(void)
+{
+     u64 cnt;
+     int ret;
+
+     cnt = DIV_ROUND_UP(sizeof(struct bootloader_message),

partition->blksz);

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp)

Quoted 13 lines
cmd/bcb.c +2 -5
+     if (cnt > partition->size)
              goto err_too_small;
 
-     if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
+     if (blk_dread(block, partition->start, cnt, &bcb) != cnt) {
              ret = -EIO;
              goto err_read_fail;
      }
 
-     bcb_uclass_id = desc->uclass_id;
-     bcb_dev = desc->devnum;
-     bcb_part = part;
-     debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev,

bcb_part);

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp)

Quoted 6 lines
cmd/bcb.c +2 -1
+     debug("%s: Loaded from %d %d:%s\n", __func__, block->uclass_id,
+           block->devnum, partition->name);
 
      return CMD_RET_SUCCESS;
 err_read_fail:
-     printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp,

ret);

Quoted 4 lines
cmd/bcb.c +2 -0
+     printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+            block->devnum, partition->name, ret);
      goto err;
 err_too_small:

cmd/bcb.c static int __bcb_load(const char *iface, int devnum, const char *partp) · line 210

Quoted 10 lines
cmd/bcb.c +3 -5
-     printf("Error: %s %d:%s too small!", iface, devnum, partp);
+     printf("Error: %d %d:%s too small!", block->uclass_id,
+            block->devnum, partition->name);
      goto err;
 err:
-     bcb_uclass_id = UCLASS_INVALID;
-     bcb_dev = -1;
-     bcb_part = -1;
-
+     __bcb_reset();

Nitpick: __bcb_reset() introduction could have been done in a separate patch

cmd/bcb.c static int do_bcb_load(struct cmd_tbl *cmdtp, int

Quoted 11 lines
cmd/bcb.c +1 -0
      return CMD_RET_FAILURE;
 }
 
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
                     char * const argv[])
 {
+     int ret;
      int devnum;
      char *endp;
      char *iface = "mcc";
@@ -204,10 +231,14 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int

flag, int argc,

cmd/bcb.c static int do_bcb_dump(struct cmd_tbl *cmdtp, int

Quoted 17 lines
cmd/bcb.c +6 -2
              return CMD_RET_FAILURE;
      }
 
-     return __bcb_load(iface, devnum, argv[2]);
+     ret = __bcb_initialize(iface, devnum, argv[2]);
+     if (ret != CMD_RET_SUCCESS)
+             return ret;
+
+     return __bcb_load();
 }
 
-static int __bcb_set(char *fieldp, const char *valp)
+static int __bcb_set(const char *fieldp, const char *valp)
 {
      int size, len;
      char *field, *str, *found, *tmp;
@@ -307,31 +338,20 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int

flag, int argc,

Quoted 10 lines
cmd/bcb.c +0 -4
 static int __bcb_store(void)
 {
-     struct blk_desc *desc;
-     struct disk_partition info;
      u64 cnt;
      int ret;
 
-     desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
-     if (!desc) {

cmd/bcb.c static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,

Quoted 10 lines
cmd/bcb.c +1 -9
-             ret = -ENODEV;
-             goto err;
-     }
-
-     ret = part_get_info(desc, bcb_part, &info);
-     if (ret)
-             goto err;
-
-     cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
+     cnt = DIV_ROUND_UP(sizeof(struct bootloader_message),

partition->blksz);

cmd/bcb.c static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,

Quoted 10 lines
cmd/bcb.c +1 -2
-     if (blk_dwrite(desc, info.start, cnt, &bcb) != cnt) {
+     if (blk_dwrite(block, partition->start, cnt, &bcb) != cnt) {
              ret = -EIO;
              goto err;
      }
 
      return CMD_RET_SUCCESS;
 err:
-     printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id,

bcb_dev, bcb_part, ret);

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, int

Quoted 6 lines
cmd/bcb.c +2 -0
+     printf("Error: %d %d:%s write failed (%d)\n", block->uclass_id,
+            block->devnum, partition->name, ret);
 
      return CMD_RET_FAILURE;
 }
@@ -342,23 +362,59 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int

flag, int argc,

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,

Quoted 4 lines
cmd/bcb.c +0 -1
      return __bcb_store();
 }
 
-int bcb_write_reboot_reason(const char *iface, int devnum, char *partp,

const char *reasonp)

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, int · line 365

Quoted 1 line
cmd/bcb.c +1 -0
+int bcb_find_partition_and_load(const char *iface, int devnum, char

*partp)

Quoted 11 lines
cmd/bcb.c +2 -4
 {
      int ret;
 
-     ret = __bcb_load(iface, devnum, partp);
-     if (ret != CMD_RET_SUCCESS)
-             return ret;
+     __bcb_reset();
 
-     ret = __bcb_set("command", reasonp);
+     ret = __bcb_initialize(iface, devnum, partp);
      if (ret != CMD_RET_SUCCESS)

cmd/bcb.c static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,

Quoted 10 lines
cmd/bcb.c +3 -4
              return ret;
 
-     ret = __bcb_store();
-     if (ret != CMD_RET_SUCCESS)
-             return ret;
+     return __bcb_load();
+}
 
-     return 0;
+int bcb_load(struct blk_desc *block_description, struct disk_partition

*disk_partition)

Quoted 47 lines
cmd/bcb.c +39 -0
+{
+     __bcb_reset();
+
+     block = block_description;
+     partition = disk_partition;
+
+     return __bcb_load();
+}
+
+int bcb_set(enum bcb_field field, const char *value)
+{
+     if (field > BCB_FIELD_STAGE)
+             return CMD_RET_FAILURE;
+     return __bcb_set(fields[field], value);
+}
+
+int bcb_get(enum bcb_field field, char *value_out, size_t value_size)
+{
+     int size;
+     char *field_value;
+
+     if (field > BCB_FIELD_STAGE)
+             return CMD_RET_FAILURE;
+     if (bcb_field_get(fields[field], &field_value, &size))
+             return CMD_RET_FAILURE;
+
+     strlcpy(value_out, field_value, value_size);
+
+     return CMD_RET_SUCCESS;
+}
+
+int bcb_store(void)
+{
+     return __bcb_store();
+}
+
+void bcb_reset(void)
+{
+     __bcb_reset();
 }
 
 static struct cmd_tbl cmd_bcb_sub[] = {
drivers/fastboot/fb_common.c +0 -0
index 2a6608b28c..3576b06772 100644

drivers/fastboot/fb_common.c void fastboot_okay(const char *reason, char *response) · line 96

Quoted 6 lines
drivers/fastboot/fb_common.c +1 -0
@@ -91,6 +91,7 @@ void fastboot_okay(const char *reason, char *response)
  */
 int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 {
+     int ret;
      static const char * const boot_cmds[] = {
              [FASTBOOT_REBOOT_REASON_BOOTLOADER] =

"bootonce-bootloader",

drivers/fastboot/fb_common.c int __weak fastboot_set_reboot_flag(enum

Quoted 2 lines
drivers/fastboot/fb_common.c +0 -0
              [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
@@ -105,7 +106,18 @@ int __weak fastboot_set_reboot_flag(enum

fastboot_reboot_reason reason)

drivers/fastboot/fb_common.c int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)

Quoted 4 lines
drivers/fastboot/fb_common.c +0 -1
      if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
              return -EINVAL;
 
-     return bcb_write_reboot_reason("mmc", mmc_dev, "misc",

boot_cmds[reason]);

Quoted 24 lines
drivers/fastboot/fb_common.c +12 -0
+     ret = bcb_find_partition_and_load("mmc", mmc_dev, "misc");
+     if (ret)
+             goto out;
+
+     ret = bcb_set(BCB_FIELD_COMMAND, boot_cmds[reason]);
+     if (ret)
+             goto out;
+
+     ret = bcb_store();
+out:
+     bcb_reset();
+     return ret;
 }
 
 /**
include/bcb.h +1 -0
index a6326523c4..1941d8c28b 100644
@@ -8,15 +8,69 @@
 #ifndef __BCB_H__
 #define __BCB_H__
 
+#include <part.h>

include/bcb.h line 12

Quoted 10 lines
include/bcb.h +8 -1
+
+enum bcb_field {
+     BCB_FIELD_COMMAND,
+     BCB_FIELD_STATUS,
+     BCB_FIELD_RECOVERY,
+     BCB_FIELD_STAGE
+};
+
 #if IS_ENABLED(CONFIG_CMD_BCB)
-int bcb_write_reboot_reason(const char *iface, int devnum, char *partp,

const char *reasonp);

Quoted 60 lines
include/bcb.h +48 -3
+
+int bcb_find_partition_and_load(const char *iface,
+                             int devnum, char *partp);
+int bcb_load(struct blk_desc *block_description,
+          struct disk_partition *disk_partition);
+int bcb_set(enum bcb_field field, const char *value);
+
+/**
+ * bcb_get() - get the field value.
+ * @field: field to get
+ * @value_out: buffer to copy bcb field value to
+ * @value_size: buffer size to avoid overflow in case
+ *              value_out is smaller then the field value
+ */
+int bcb_get(enum bcb_field field, char *value_out, size_t value_size);
+
+int bcb_store(void);
+void bcb_reset(void);
+
 #else
+
 #include <linux/errno.h>
-static inline int bcb_write_reboot_reason(const char *iface, int devnum,
-                                       char *partp, const char *reasonp)
+
+static inline int bcb_load(struct blk_desc *block_description,
+                        struct disk_partition *disk_partition)
+{
+     return -EOPNOTSUPP;
+}
+
+static inline int bcb_find_partition_and_load(const char *iface,
+                                           int devnum, char *partp)
+{
+     return -EOPNOTSUPP;
+}
+
+static inline int bcb_set(enum bcb_field field, const char *value)
+{
+     return -EOPNOTSUPP;
+}
+
+static inline int bcb_get(enum bcb_field field, char *value_out)
 {
      return -EOPNOTSUPP;
 }
+
+static inline int bcb_store(void)
+{
+     return -EOPNOTSUPP;
+}
+
+static inline void bcb_reset(void)
+{
+}
 #endif
 
 #endif /* __BCB_H__ */
--

2.42.0.869.gea05f2083d-goog