[PATCH v3 1/3] cmd: bcb: introduce optional interface parameter to bcb
Andrii Chepurnyi
andrii.chepurnyi82 at gmail.com
Wed Jul 20 16:59:54 CEST 2022
From: Andrii Chepurnyi <andrii.chepurnyi82 at gmail.com>
From: Andrii Chepurnyi <andrii_chepurnyi at epam.com>
Originally, bcb implementation relay on mmc block devices.
The interface parameter will give the ability to use bcb with
various block devices by choosing the exact interface type.
By default (if no interface parameter is provided) mmc interface
will be used.
Reviewed-by: Igor Opaniuk <igor.opaniuk at gmail.com>
Signed-off-by: Andrii Chepurnyi <andrii_chepurnyi at epam.com>
---
cmd/bcb.c | 65 +++++++++++++++++++++++----------------------
doc/android/bcb.rst | 33 ++++++++++++-----------
2 files changed, 51 insertions(+), 47 deletions(-)
diff --git a/cmd/bcb.c b/cmd/bcb.c
index 92f4d27990..bfe395558e 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -26,6 +26,7 @@ enum bcb_cmd {
static int bcb_dev = -1;
static int bcb_part = -1;
static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
+static struct blk_desc *bcb_blk_desc;
static int bcb_cmd_get(char *cmd)
{
@@ -51,6 +52,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,25 +119,23 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
static int __bcb_load(int devnum, const char *partp)
{
- struct blk_desc *desc;
struct disk_partition info;
u64 cnt;
char *endp;
int part, ret;
- desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum);
- if (!desc) {
+ if (!bcb_blk_desc) {
ret = -ENODEV;
goto err_read_fail;
}
part = simple_strtoul(partp, &endp, 0);
if (*endp == '\0') {
- ret = part_get_info(desc, part, &info);
+ ret = part_get_info(bcb_blk_desc, part, &info);
if (ret)
goto err_read_fail;
} else {
- part = part_get_info_by_name(desc, partp, &info);
+ part = part_get_info_by_name(bcb_blk_desc, partp, &info);
if (part < 0) {
ret = part;
goto err_read_fail;
@@ -144,12 +146,12 @@ static int __bcb_load(int devnum, const char *partp)
if (cnt > info.size)
goto err_too_small;
- if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
+ if (blk_dread(bcb_blk_desc, info.start, cnt, &bcb) != cnt) {
ret = -EIO;
goto err_read_fail;
}
- bcb_dev = desc->devnum;
+ bcb_dev = bcb_blk_desc->devnum;
bcb_part = part;
debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
@@ -170,15 +172,15 @@ err:
static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
char * const argv[])
{
- char *endp;
- int devnum = simple_strtoul(argv[1], &endp, 0);
+ int ret = blk_get_device_by_str((argv[3]) ? argv[3] : "mmc", argv[1], &bcb_blk_desc);
- if (*endp != '\0') {
- printf("Error: Device id '%s' not a number\n", argv[1]);
+ if (ret < 0) {
+ printf("Error: Device id '%s' or interface '%s' is not valid\n", argv[1],
+ (argv[3]) ? argv[3] : "mmc");
return CMD_RET_FAILURE;
}
- return __bcb_load(devnum, argv[2]);
+ return __bcb_load(bcb_blk_desc->devnum, argv[2]);
}
static int __bcb_set(char *fieldp, const char *valp)
@@ -281,24 +283,22 @@ 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_type(IF_TYPE_MMC, bcb_dev);
- if (!desc) {
+ if (!bcb_blk_desc) {
ret = -ENODEV;
goto err;
}
- ret = part_get_info(desc, bcb_part, &info);
+ ret = part_get_info(bcb_blk_desc, bcb_part, &info);
if (ret)
goto err;
cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
- if (blk_dwrite(desc, info.start, cnt, &bcb) != cnt) {
+ if (blk_dwrite(bcb_blk_desc, info.start, cnt, &bcb) != cnt) {
ret = -EIO;
goto err;
}
@@ -373,21 +373,22 @@ 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 <dev> <part> [<interface>] - load BCB from <dev>:<part>[<interface>]\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"
"\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"
+ "<dev> - device index containing the BCB partition\n"
+ "<part> - partition index or name containing the BCB\n"
+ "<interface> - interface name of the block device 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"
);
diff --git a/doc/android/bcb.rst b/doc/android/bcb.rst
index 8861608300..e6d201f439 100644
--- a/doc/android/bcb.rst
+++ b/doc/android/bcb.rst
@@ -41,23 +41,26 @@ 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 <dev> <part> [<iftype>] - load BCB from <dev>:<part>[<iftype>]
+ 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 <iftype>
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
+ <dev> - device index containing the BCB partition
+ <iftype> - Optional parameter of the interface type for the specified
+ block device like: mmc,sd,virtio see blk.h for details.
+ The default value is mmc.
+ <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
--
2.25.1
More information about the U-Boot
mailing list