[PATCH v2 1/2] cmd: bcb: introduce optional interface parameter to bcb
From: Andrii Chepurnyi From: Andrii Chepurnyi 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. Signed-off-by: Andrii Chepurnyi --- 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 - load BCB from mmc :\n" - "bcb set - set BCB to \n" - "bcb clear [] - clear BCB or all fields\n" - "bcb test - test BCB against \n" - "bcb dump - dump BCB \n" - "bcb store- store BCB back to mmc\n" + "load[] - load BCB from :[]\n" + "bcb set- set BCB to \n" + "bcb c
Re: [PATCH v2 1/2] cmd: bcb: introduce optional interface parameter to bcb
Hi Andrii, On Tue, Apr 19, 2022 at 9:46 AM Andrii Chepurnyi wrote: > > From: Andrii Chepurnyi > > From: Andrii Chepurnyi > > 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. > > Signed-off-by: Andrii Chepurnyi > --- > 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 - load BCB from mmc :\n" > - "bcb set - set BCB to \n" > - "