Re: [PATCH v4 1/3] cmd: bcb: introduce optional interface parameter to bcb
Hello Tom, I've used a doker from mentioned job to reproduce issue. I am able to see same errors and test fail as in jobs/490627. Here is my investigation: The error that appeared is not related to AVB: fs_devread read outside partition 2 Failed to mount ext2 filesystem... BTRFS: superblock end 69632 is larger than device size 512 fs_devread read outside partition 0 fs_devread read outside partition 2 Failed to mount ext2 filesystem... BTRFS: superblock end 69632 is larger than device size 512 fs_devread read outside partition 0 I found a test case that caused this situation: dm_test_part. So if you run all tests with -k "not dm_test_part" - all tests will pass, including AVB tests. dm_test_part modify GPT (during testing used mmc1.img for emulation, as I understand), and after if some part of code touch blk you may see a mentioned error. I.e. run only dm_test_part test, start u-boot and run "part list mmc 1" you will see the same error. So I suppose this problem(if it is a problem since I see it like a test case that didn't restore the environment back) was present prior to my patches. But why it appears after my patches? Because I've changed the internal logic of avb command and now on avb init will interact with blk(blk_get_device_by_str) which causes those prints. In the previous versions of avb commands "avb init" and "avb read_rb " will not touch blk, so no error is present. So from my point of view, this is more like dm_test_part problem, but not bcb or avb patches. Andrii. On 03.09.22 04:55, Tom Rini wrote: > On Mon, Aug 01, 2022 at 11:07:15AM +0300, 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. >> >> Reviewed-by: Igor Opaniuk >> Signed-off-by: Andrii Chepurnyi > The tests now fail: > https://source.denx.de/u-boot/u-boot/-/jobs/490627 >
[PATCH v1 0/1] virtio-blk support for xen board
Hello. This patch adds the ability to use virtio-blk in the guest domain under Xen hypervisor. To do such you need to build U-boot with xenguest_arm64_virtio_defconfig. The patch was tested on a specific build for rcar-gen3 hardware, with multiple Linux domains running under Xen and QEMU as a block backend. Andrii Chepurnyi (1): board: xen: introduce virtio-blk support board/xen/xenguest_arm64/xenguest_arm64.c | 108 +- configs/xenguest_arm64_virtio_defconfig | 63 + doc/board/xen/xenguest_arm64.rst | 2 + include/configs/xenguest_arm64.h | 10 +- 4 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 configs/xenguest_arm64_virtio_defconfig -- 2.25.1
[PATCH v1 1/1] board: xen: introduce virtio-blk support
Added new xenguest_arm64_virtio_defconfig which enables support for virtio-blk using various types of transport like virtio-pci, vrtio-mmio. Currently supported: up to 2 PCI host bridges and 10 MMIO devices. Note: DT parsing code was partly taken from pci-uclass.c Limitation: All memory regions should be below 4GB address space. Signed-off-by: Andrii Chepurnyi --- board/xen/xenguest_arm64/xenguest_arm64.c | 108 +- configs/xenguest_arm64_virtio_defconfig | 63 + doc/board/xen/xenguest_arm64.rst | 2 + include/configs/xenguest_arm64.h | 10 +- 4 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 configs/xenguest_arm64_virtio_defconfig diff --git a/board/xen/xenguest_arm64/xenguest_arm64.c b/board/xen/xenguest_arm64/xenguest_arm64.c index 6e10bba76b..244070a242 100644 --- a/board/xen/xenguest_arm64/xenguest_arm64.c +++ b/board/xen/xenguest_arm64/xenguest_arm64.c @@ -8,12 +8,15 @@ */ #include +#include #include #include #include #include #include #include +#include +#include #include #include @@ -49,7 +52,14 @@ void *board_fdt_blob_setup(int *err) return (void *)rom_pointer[0]; } -#define MAX_MEM_MAP_REGIONS 5 +/* + * MAX_MEM_MAP_REGIONS should respect to: + * 3 Xen related regions + * 6 regions for 2 PCI Host bridges + * 10 regions for MMIO devices + * 2 memory regions + */ +#define MAX_MEM_MAP_REGIONS 22 static struct mm_region xen_mem_map[MAX_MEM_MAP_REGIONS]; struct mm_region *mem_map = xen_mem_map; @@ -63,6 +73,93 @@ static int get_next_memory_node(const void *blob, int mem) return mem; } +#ifdef CONFIG_VIRTIO_BLK +#ifdef CONFIG_VIRTIO_PCI +static void add_pci_mem_map(const void *blob, int *cnt) +{ + struct fdt_resource reg_res; + int node = -1, len = 0, cells_per_record = 0, max_regions = 0; + int pci_addr_cells = 0, addr_cells = 0, size_cells = 0; + + while ((node = fdt_node_offset_by_prop_value(blob, node, "compatible", +"pci-host-ecam-generic", + sizeof("pci-host-ecam-generic"))) >= 0) { + if ((*cnt) >= MAX_MEM_MAP_REGIONS || + fdt_get_resource(blob, node, "reg", 0, ®_res) < 0) + return; + + xen_mem_map[*cnt].virt = reg_res.start; + xen_mem_map[*cnt].phys = reg_res.start; + xen_mem_map[*cnt].size = fdt_resource_size(®_res); + xen_mem_map[*cnt].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE); + (*cnt)++; + + const u32 *prop = fdt_getprop(blob, node, "ranges", &len); + + if (!prop) + return; + + pci_addr_cells = fdt_address_cells(blob, node); + addr_cells = fdt_address_cells(blob, 0); + size_cells = fdt_size_cells(blob, node); + + /* PCI addresses are always 3-cells */ + len /= sizeof(u32); + cells_per_record = pci_addr_cells + addr_cells + size_cells; + max_regions = len / cells_per_record + CONFIG_NR_DRAM_BANKS; + + for (int i = 0; i < max_regions; i++, len -= cells_per_record) { + u64 pci_addr, addr, size; + int space_code; + u32 flags; + + if (((*cnt) >= MAX_MEM_MAP_REGIONS) || len < cells_per_record) + return; + + flags = fdt32_to_cpu(prop[0]); + space_code = (flags >> 24) & 3; + pci_addr = fdtdec_get_number(prop + 1, 2); + prop += pci_addr_cells; + addr = fdtdec_get_number(prop, addr_cells); + prop += addr_cells; + size = fdtdec_get_number(prop, size_cells); + prop += size_cells; + + xen_mem_map[*cnt].virt = addr; + xen_mem_map[*cnt].phys = addr; + xen_mem_map[*cnt].size = size; + xen_mem_map[*cnt].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE); + (*cnt)++; + } + } +} +#endif + +#ifdef CONFIG_VIRTIO_MMIO +static void add_mmio_mem_map(const void *blob, int *cnt) +{ + int node = -1; + struct fdt_resource reg_res; + + if ((*cnt) >= MAX_MEM_MAP_REGIONS) + return; + while ((node = fdt_node_offset_by_prop_value(blob, node, "compatible", "virtio,mmio", +sizeof("virtio,mmio"
[PATCH v2 0/2] Support various block interfaces for avb and bcb
Hello. Originally bcb and avb utilities implementation relay on mmc block devices. This patch series adds an optional interface parameter to those utilities, which gives the ability to use bcb and avb on various block devices. The patch set was tested using xenguest_arm64 based board and pvblock interface. Changes for v2: - Removed patch #3 as not actual for mainline Andrii Chepurnyi (2): cmd: bcb: introduce optional interface parameter to bcb cmd: avb: introduce optional interface parameter to avb init cmd/avb.c| 13 - cmd/bcb.c| 65 ++-- common/avb_verify.c | 28 +++ doc/android/avb2.rst | 2 +- doc/android/bcb.rst | 33 -- include/avb_verify.h | 11 +++- 6 files changed, 77 insertions(+), 75 deletions(-) -- 2.25.1
[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&q
[PATCH v2 2/2] cmd: avb: introduce optional interface parameter to avb init
From: Andrii Chepurnyi From: Andrii Chepurnyi Originally, avb implementation relay on mmc block devices. The interface parameter will give the ability to use avb 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/avb.c| 13 + common/avb_verify.c | 28 ++-- doc/android/avb2.rst | 2 +- include/avb_verify.h | 11 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 783f51b816..6fdbdc708f 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -17,17 +17,14 @@ static struct AvbOps *avb_ops; int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - unsigned long mmc_dev; - - if (argc != 2) + if (argc != 2 && argc != 3) return CMD_RET_USAGE; - mmc_dev = hextoul(argv[1], NULL); - if (avb_ops) avb_ops_free(avb_ops); - avb_ops = avb_ops_alloc(mmc_dev); + avb_ops = avb_ops_alloc(argv[1], (argc == 3) ? argv[2] : "mmc"); + if (avb_ops) return CMD_RET_SUCCESS; @@ -419,7 +416,7 @@ int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_avb[] = { - U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""), + U_BOOT_CMD_MKENT(init, 3, 0, do_avb_init, "", ""), U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""), U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""), U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""), @@ -455,7 +452,7 @@ static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( avb, 29, 0, do_avb, "Provides commands for testing Android Verified Boot 2.0 functionality", - "init - initialize avb2 for \n" + "init [] - initialize avb2 for []\n" "avb read_rb - read rollback index at location \n" "avb write_rb - write rollback index to \n" "avb is_unlocked - returns unlock status of the device\n" diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..e086dc6760 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -338,7 +338,6 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - int part_num = 0; struct mmc_part *part; struct blk_desc *mmc_blk; @@ -347,22 +346,8 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) return NULL; dev_num = get_boot_device(ops); - part->mmc = find_mmc_device(dev_num); - if (!part->mmc) { - printf("No MMC device at slot %x\n", dev_num); - goto err; - } - - if (mmc_init(part->mmc)) { - printf("MMC initialization failed\n"); - goto err; - } + mmc_blk = get_blk(ops); - ret = mmc_switch_part(part->mmc, part_num); - if (ret) - goto err; - - mmc_blk = mmc_get_blk_desc(part->mmc); if (!mmc_blk) { printf("Error - failed to obtain block descriptor\n"); goto err; @@ -976,7 +961,8 @@ free_name: * AVB2.0 AvbOps alloc/initialisation/free * */ -AvbOps *avb_ops_alloc(int boot_device) + +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface) { struct AvbOpsData *ops_data; @@ -999,7 +985,13 @@ AvbOps *avb_ops_alloc(int boot_device) ops_data->ops.read_persistent_value = read_persistent_value; #endif ops_data->ops.get_size_of_partition = get_size_of_partition; - ops_data->mmc_dev = boot_device; + ops_data->mmc_dev = simple_strtoul(boot_device, NULL, 16); + ops_data->blk = NULL; + if (interface && (blk_get_device_by_str(interface, boot_device, &ops_data->blk) < 0)) { + printf("Error - failed to obtain block descriptor for devce=%s if=%s\n", + boot_device, interface); + return NULL; + } return &ops_data->ops; } diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst index a072119574..8fa54338fd 100644 --- a/doc/android/avb2.rst +++ b/doc/android/avb2.rst @@ -38,7 +38,7 @@ AVB 2.0 U-Boot shell commands Provides CLI interface to invoke AVB 2.0 verification + misc. commands for different testing purposes:: -avb init - initialize avb 2.0 for +avb init [] - initialize avb2 for [] avb verify - run verification process using hash d
[PATCH v3 0/3] Support various block interfaces for avb and bcb
Hello. Originally bcb and avb utilities implementation relay on mmc block devices. This patch series adds an optional interface parameter to those utilities, which gives the ability to use bcb and avb on various block devices. The patch set was tested using xenguest_arm64 based board and pvblock interface. Changes for v3: - Added RB and ACK - Added patch #3 by the request Changes for v2: - Removed patch #3 as not actual for mainline Andrii Chepurnyi (3): cmd: bcb: introduce optional interface parameter to bcb cmd: avb: introduce optional interface parameter to avb init cmd: avb: remove mmc naming from generic block code cmd/avb.c| 13 +++- cmd/bcb.c| 65 ++--- common/avb_verify.c | 76 doc/android/avb2.rst | 2 +- doc/android/bcb.rst | 33 ++- include/avb_verify.h | 24 +- 6 files changed, 107 insertions(+), 106 deletions(-) -- 2.25.1
[PATCH v3 1/3] 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. Reviewed-by: Igor Opaniuk 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
[PATCH v3 2/3] cmd: avb: introduce optional interface parameter to avb init
From: Andrii Chepurnyi From: Andrii Chepurnyi Originally, avb implementation relay on mmc block devices. The interface parameter will give the ability to use avb with various block devices by choosing the exact interface type. By default (if no interface parameter is provided) mmc interface will be used. Acked-by: Igor Opaniuk Signed-off-by: Andrii Chepurnyi --- cmd/avb.c| 13 + common/avb_verify.c | 28 ++-- doc/android/avb2.rst | 2 +- include/avb_verify.h | 11 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 783f51b816..6fdbdc708f 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -17,17 +17,14 @@ static struct AvbOps *avb_ops; int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - unsigned long mmc_dev; - - if (argc != 2) + if (argc != 2 && argc != 3) return CMD_RET_USAGE; - mmc_dev = hextoul(argv[1], NULL); - if (avb_ops) avb_ops_free(avb_ops); - avb_ops = avb_ops_alloc(mmc_dev); + avb_ops = avb_ops_alloc(argv[1], (argc == 3) ? argv[2] : "mmc"); + if (avb_ops) return CMD_RET_SUCCESS; @@ -419,7 +416,7 @@ int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_avb[] = { - U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""), + U_BOOT_CMD_MKENT(init, 3, 0, do_avb_init, "", ""), U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""), U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""), U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""), @@ -455,7 +452,7 @@ static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( avb, 29, 0, do_avb, "Provides commands for testing Android Verified Boot 2.0 functionality", - "init - initialize avb2 for \n" + "init [] - initialize avb2 for []\n" "avb read_rb - read rollback index at location \n" "avb write_rb - write rollback index to \n" "avb is_unlocked - returns unlock status of the device\n" diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..e086dc6760 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -338,7 +338,6 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - int part_num = 0; struct mmc_part *part; struct blk_desc *mmc_blk; @@ -347,22 +346,8 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) return NULL; dev_num = get_boot_device(ops); - part->mmc = find_mmc_device(dev_num); - if (!part->mmc) { - printf("No MMC device at slot %x\n", dev_num); - goto err; - } - - if (mmc_init(part->mmc)) { - printf("MMC initialization failed\n"); - goto err; - } + mmc_blk = get_blk(ops); - ret = mmc_switch_part(part->mmc, part_num); - if (ret) - goto err; - - mmc_blk = mmc_get_blk_desc(part->mmc); if (!mmc_blk) { printf("Error - failed to obtain block descriptor\n"); goto err; @@ -976,7 +961,8 @@ free_name: * AVB2.0 AvbOps alloc/initialisation/free * */ -AvbOps *avb_ops_alloc(int boot_device) + +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface) { struct AvbOpsData *ops_data; @@ -999,7 +985,13 @@ AvbOps *avb_ops_alloc(int boot_device) ops_data->ops.read_persistent_value = read_persistent_value; #endif ops_data->ops.get_size_of_partition = get_size_of_partition; - ops_data->mmc_dev = boot_device; + ops_data->mmc_dev = simple_strtoul(boot_device, NULL, 16); + ops_data->blk = NULL; + if (interface && (blk_get_device_by_str(interface, boot_device, &ops_data->blk) < 0)) { + printf("Error - failed to obtain block descriptor for devce=%s if=%s\n", + boot_device, interface); + return NULL; + } return &ops_data->ops; } diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst index a072119574..8fa54338fd 100644 --- a/doc/android/avb2.rst +++ b/doc/android/avb2.rst @@ -38,7 +38,7 @@ AVB 2.0 U-Boot shell commands Provides CLI interface to invoke AVB 2.0 verification + misc. commands for different testing purposes:: -avb init - initialize avb 2.0 for +avb init [] - initialize avb2 for [] avb verify - run verification
[PATCH v3 3/3] cmd: avb: remove mmc naming from generic block code
From: Andrii Chepurnyi From: Andrii Chepurnyi Part of avb code uses mmc notation, but in fact it uses generic block functions. Signed-off-by: Andrii Chepurnyi --- common/avb_verify.c | 52 ++-- include/avb_verify.h | 13 +-- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/common/avb_verify.c b/common/avb_verify.c index e086dc6760..3c9594d6d7 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -253,10 +253,10 @@ char *avb_set_enforce_verity(const char *cmdline) /** * - * IO(mmc) auxiliary functions + * IO auxiliary functions * */ -static unsigned long mmc_read_and_flush(struct mmc_part *part, +static unsigned long blk_read_and_flush(struct blk_part *part, lbaint_t start, lbaint_t sectors, void *buffer) @@ -291,7 +291,7 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part, tmp_buf = buffer; } - blks = blk_dread(part->mmc_blk, + blks = blk_dread(part->blk, start, sectors, tmp_buf); /* flush cache after read */ flush_cache((ulong)tmp_buf, sectors * part->info.blksz); @@ -302,7 +302,7 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part, return blks; } -static unsigned long mmc_write(struct mmc_part *part, lbaint_t start, +static unsigned long blk_write(struct blk_part *part, lbaint_t start, lbaint_t sectors, void *buffer) { void *tmp_buf; @@ -330,37 +330,37 @@ static unsigned long mmc_write(struct mmc_part *part, lbaint_t start, tmp_buf = buffer; } - return blk_dwrite(part->mmc_blk, + return blk_dwrite(part->blk, start, sectors, tmp_buf); } -static struct mmc_part *get_partition(AvbOps *ops, const char *partition) +static struct blk_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - struct mmc_part *part; - struct blk_desc *mmc_blk; + struct blk_part *part; + struct blk_desc *blk; - part = malloc(sizeof(struct mmc_part)); + part = malloc(sizeof(struct blk_part)); if (!part) return NULL; dev_num = get_boot_device(ops); - mmc_blk = get_blk(ops); + blk = get_blk(ops); - if (!mmc_blk) { + if (!blk) { printf("Error - failed to obtain block descriptor\n"); goto err; } - ret = part_get_info_by_name(mmc_blk, partition, &part->info); + ret = part_get_info_by_name(blk, partition, &part->info); if (ret < 0) { printf("Can't find partition '%s'\n", partition); goto err; } part->dev_num = dev_num; - part->mmc_blk = mmc_blk; + part->blk = blk; return part; err: @@ -368,16 +368,16 @@ err: return NULL; } -static AvbIOResult mmc_byte_io(AvbOps *ops, +static AvbIOResult blk_byte_io(AvbOps *ops, const char *partition, s64 offset, size_t num_bytes, void *buffer, size_t *out_num_read, - enum mmc_io_type io_type) + enum io_type io_type) { ulong ret; - struct mmc_part *part; + struct blk_part *part; u64 start_offset, start_sector, sectors, residue; u8 *tmp_buf; size_t io_cnt = 0; @@ -410,7 +410,7 @@ static AvbIOResult mmc_byte_io(AvbOps *ops, } if (io_type == IO_READ) { - ret = mmc_read_and_flush(part, + ret = blk_read_and_flush(part, part->info.start + start_sector, 1, tmp_buf); @@ -427,7 +427,7 @@ static AvbIOResult mmc_byte_io(AvbOps *ops, tmp_buf += (start_offset % part->info.blksz); memcpy(buffer, (void *)tmp_buf, residue); } else { - ret = mmc_read_and_flush(part, + ret = blk_read_and_flush(part, part->info.start + start_sector,
[PATCH v4 0/3] Support various block interfaces for avb and bcb
Hello. Originally bcb and avb utilities implementation relay on mmc block devices. This patch series adds an optional interface parameter to those utilities, which gives the ability to use bcb and avb on various block devices. The patch set was tested using xenguest_arm64 based board and pvblock interface. Changes for v4: - Added RB to all patches Changes for v3: - Added RB and ACK - Added patch #3 by the request Changes for v2: - Removed patch #3 as not actual for mainline Andrii Chepurnyi (3): cmd: bcb: introduce optional interface parameter to bcb cmd: avb: introduce optional interface parameter to avb init cmd: avb: remove mmc naming from generic block code cmd/avb.c| 13 +++- cmd/bcb.c| 65 ++--- common/avb_verify.c | 76 doc/android/avb2.rst | 2 +- doc/android/bcb.rst | 33 ++- include/avb_verify.h | 24 +- 6 files changed, 107 insertions(+), 106 deletions(-) -- 2.25.1
[PATCH v4 1/3] 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. Reviewed-by: Igor Opaniuk 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
[PATCH v4 2/3] cmd: avb: introduce optional interface parameter to avb init
From: Andrii Chepurnyi From: Andrii Chepurnyi Originally, avb implementation relay on mmc block devices. The interface parameter will give the ability to use avb 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 Signed-off-by: Andrii Chepurnyi --- cmd/avb.c| 13 + common/avb_verify.c | 28 ++-- doc/android/avb2.rst | 2 +- include/avb_verify.h | 11 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 783f51b816..6fdbdc708f 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -17,17 +17,14 @@ static struct AvbOps *avb_ops; int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - unsigned long mmc_dev; - - if (argc != 2) + if (argc != 2 && argc != 3) return CMD_RET_USAGE; - mmc_dev = hextoul(argv[1], NULL); - if (avb_ops) avb_ops_free(avb_ops); - avb_ops = avb_ops_alloc(mmc_dev); + avb_ops = avb_ops_alloc(argv[1], (argc == 3) ? argv[2] : "mmc"); + if (avb_ops) return CMD_RET_SUCCESS; @@ -419,7 +416,7 @@ int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_avb[] = { - U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""), + U_BOOT_CMD_MKENT(init, 3, 0, do_avb_init, "", ""), U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""), U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""), U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""), @@ -455,7 +452,7 @@ static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( avb, 29, 0, do_avb, "Provides commands for testing Android Verified Boot 2.0 functionality", - "init - initialize avb2 for \n" + "init [] - initialize avb2 for []\n" "avb read_rb - read rollback index at location \n" "avb write_rb - write rollback index to \n" "avb is_unlocked - returns unlock status of the device\n" diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..e086dc6760 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -338,7 +338,6 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - int part_num = 0; struct mmc_part *part; struct blk_desc *mmc_blk; @@ -347,22 +346,8 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) return NULL; dev_num = get_boot_device(ops); - part->mmc = find_mmc_device(dev_num); - if (!part->mmc) { - printf("No MMC device at slot %x\n", dev_num); - goto err; - } - - if (mmc_init(part->mmc)) { - printf("MMC initialization failed\n"); - goto err; - } + mmc_blk = get_blk(ops); - ret = mmc_switch_part(part->mmc, part_num); - if (ret) - goto err; - - mmc_blk = mmc_get_blk_desc(part->mmc); if (!mmc_blk) { printf("Error - failed to obtain block descriptor\n"); goto err; @@ -976,7 +961,8 @@ free_name: * AVB2.0 AvbOps alloc/initialisation/free * */ -AvbOps *avb_ops_alloc(int boot_device) + +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface) { struct AvbOpsData *ops_data; @@ -999,7 +985,13 @@ AvbOps *avb_ops_alloc(int boot_device) ops_data->ops.read_persistent_value = read_persistent_value; #endif ops_data->ops.get_size_of_partition = get_size_of_partition; - ops_data->mmc_dev = boot_device; + ops_data->mmc_dev = simple_strtoul(boot_device, NULL, 16); + ops_data->blk = NULL; + if (interface && (blk_get_device_by_str(interface, boot_device, &ops_data->blk) < 0)) { + printf("Error - failed to obtain block descriptor for devce=%s if=%s\n", + boot_device, interface); + return NULL; + } return &ops_data->ops; } diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst index a072119574..8fa54338fd 100644 --- a/doc/android/avb2.rst +++ b/doc/android/avb2.rst @@ -38,7 +38,7 @@ AVB 2.0 U-Boot shell commands Provides CLI interface to invoke AVB 2.0 verification + misc. commands for different testing purposes:: -avb init - initialize avb 2.0 for +avb init [] - initialize avb2 for [] avb verify - run verification
[PATCH v4 3/3] cmd: avb: remove mmc naming from generic block code
From: Andrii Chepurnyi From: Andrii Chepurnyi Part of avb code uses mmc notation, but in fact it uses generic block functions. Reviewed-by: Igor Opaniuk Signed-off-by: Andrii Chepurnyi --- common/avb_verify.c | 52 ++-- include/avb_verify.h | 13 +-- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/common/avb_verify.c b/common/avb_verify.c index e086dc6760..3c9594d6d7 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -253,10 +253,10 @@ char *avb_set_enforce_verity(const char *cmdline) /** * - * IO(mmc) auxiliary functions + * IO auxiliary functions * */ -static unsigned long mmc_read_and_flush(struct mmc_part *part, +static unsigned long blk_read_and_flush(struct blk_part *part, lbaint_t start, lbaint_t sectors, void *buffer) @@ -291,7 +291,7 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part, tmp_buf = buffer; } - blks = blk_dread(part->mmc_blk, + blks = blk_dread(part->blk, start, sectors, tmp_buf); /* flush cache after read */ flush_cache((ulong)tmp_buf, sectors * part->info.blksz); @@ -302,7 +302,7 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part, return blks; } -static unsigned long mmc_write(struct mmc_part *part, lbaint_t start, +static unsigned long blk_write(struct blk_part *part, lbaint_t start, lbaint_t sectors, void *buffer) { void *tmp_buf; @@ -330,37 +330,37 @@ static unsigned long mmc_write(struct mmc_part *part, lbaint_t start, tmp_buf = buffer; } - return blk_dwrite(part->mmc_blk, + return blk_dwrite(part->blk, start, sectors, tmp_buf); } -static struct mmc_part *get_partition(AvbOps *ops, const char *partition) +static struct blk_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - struct mmc_part *part; - struct blk_desc *mmc_blk; + struct blk_part *part; + struct blk_desc *blk; - part = malloc(sizeof(struct mmc_part)); + part = malloc(sizeof(struct blk_part)); if (!part) return NULL; dev_num = get_boot_device(ops); - mmc_blk = get_blk(ops); + blk = get_blk(ops); - if (!mmc_blk) { + if (!blk) { printf("Error - failed to obtain block descriptor\n"); goto err; } - ret = part_get_info_by_name(mmc_blk, partition, &part->info); + ret = part_get_info_by_name(blk, partition, &part->info); if (ret < 0) { printf("Can't find partition '%s'\n", partition); goto err; } part->dev_num = dev_num; - part->mmc_blk = mmc_blk; + part->blk = blk; return part; err: @@ -368,16 +368,16 @@ err: return NULL; } -static AvbIOResult mmc_byte_io(AvbOps *ops, +static AvbIOResult blk_byte_io(AvbOps *ops, const char *partition, s64 offset, size_t num_bytes, void *buffer, size_t *out_num_read, - enum mmc_io_type io_type) + enum io_type io_type) { ulong ret; - struct mmc_part *part; + struct blk_part *part; u64 start_offset, start_sector, sectors, residue; u8 *tmp_buf; size_t io_cnt = 0; @@ -410,7 +410,7 @@ static AvbIOResult mmc_byte_io(AvbOps *ops, } if (io_type == IO_READ) { - ret = mmc_read_and_flush(part, + ret = blk_read_and_flush(part, part->info.start + start_sector, 1, tmp_buf); @@ -427,7 +427,7 @@ static AvbIOResult mmc_byte_io(AvbOps *ops, tmp_buf += (start_offset % part->info.blksz); memcpy(buffer, (void *)tmp_buf, residue); } else { - ret = mmc_read_and_flush(part, + ret = blk_read_and_flush(part, part->info.start + start_sector,
[PATCH v1 0/3] Support various block interfaces for avb and bcb
Hello. Originally bcb and avb utilities implementation relay on mmc block devices. This patch series adds an optional interface parameter to those utilities, which gives the ability to use bcb and avb on various block devices. The patch set was tested using xenguest_arm64 based board and pvblock interface. Andrii Chepurnyi (3): cmd: bcb: introduce optional interface parameter to bcb cmd: avb: introduce optional interface parameter to avb init cmd: avb: remove warning during avb build cmd/avb.c| 15 -- cmd/bcb.c| 65 ++-- common/avb_verify.c | 28 +++ doc/android/avb2.rst | 2 +- doc/android/bcb.rst | 33 -- include/avb_verify.h | 11 +++- 6 files changed, 77 insertions(+), 77 deletions(-) -- 2.25.1
[PATCH v1 1/3] 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&q
[PATCH v1 2/3] cmd: avb: introduce optional interface parameter to avb init
From: Andrii Chepurnyi From: Andrii Chepurnyi Originally, avb implementation relay on mmc block devices. The interface parameter will give the ability to use avb 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/avb.c| 13 + common/avb_verify.c | 28 ++-- doc/android/avb2.rst | 2 +- include/avb_verify.h | 11 ++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 783f51b816..6fdbdc708f 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -17,17 +17,14 @@ static struct AvbOps *avb_ops; int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - unsigned long mmc_dev; - - if (argc != 2) + if (argc != 2 && argc != 3) return CMD_RET_USAGE; - mmc_dev = hextoul(argv[1], NULL); - if (avb_ops) avb_ops_free(avb_ops); - avb_ops = avb_ops_alloc(mmc_dev); + avb_ops = avb_ops_alloc(argv[1], (argc == 3) ? argv[2] : "mmc"); + if (avb_ops) return CMD_RET_SUCCESS; @@ -419,7 +416,7 @@ int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_avb[] = { - U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""), + U_BOOT_CMD_MKENT(init, 3, 0, do_avb_init, "", ""), U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""), U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""), U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""), @@ -455,7 +452,7 @@ static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( avb, 29, 0, do_avb, "Provides commands for testing Android Verified Boot 2.0 functionality", - "init - initialize avb2 for \n" + "init [] - initialize avb2 for []\n" "avb read_rb - read rollback index at location \n" "avb write_rb - write rollback index to \n" "avb is_unlocked - returns unlock status of the device\n" diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..e086dc6760 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -338,7 +338,6 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - int part_num = 0; struct mmc_part *part; struct blk_desc *mmc_blk; @@ -347,22 +346,8 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) return NULL; dev_num = get_boot_device(ops); - part->mmc = find_mmc_device(dev_num); - if (!part->mmc) { - printf("No MMC device at slot %x\n", dev_num); - goto err; - } - - if (mmc_init(part->mmc)) { - printf("MMC initialization failed\n"); - goto err; - } + mmc_blk = get_blk(ops); - ret = mmc_switch_part(part->mmc, part_num); - if (ret) - goto err; - - mmc_blk = mmc_get_blk_desc(part->mmc); if (!mmc_blk) { printf("Error - failed to obtain block descriptor\n"); goto err; @@ -976,7 +961,8 @@ free_name: * AVB2.0 AvbOps alloc/initialisation/free * */ -AvbOps *avb_ops_alloc(int boot_device) + +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface) { struct AvbOpsData *ops_data; @@ -999,7 +985,13 @@ AvbOps *avb_ops_alloc(int boot_device) ops_data->ops.read_persistent_value = read_persistent_value; #endif ops_data->ops.get_size_of_partition = get_size_of_partition; - ops_data->mmc_dev = boot_device; + ops_data->mmc_dev = simple_strtoul(boot_device, NULL, 16); + ops_data->blk = NULL; + if (interface && (blk_get_device_by_str(interface, boot_device, &ops_data->blk) < 0)) { + printf("Error - failed to obtain block descriptor for devce=%s if=%s\n", + boot_device, interface); + return NULL; + } return &ops_data->ops; } diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst index a072119574..8fa54338fd 100644 --- a/doc/android/avb2.rst +++ b/doc/android/avb2.rst @@ -38,7 +38,7 @@ AVB 2.0 U-Boot shell commands Provides CLI interface to invoke AVB 2.0 verification + misc. commands for different testing purposes:: -avb init - initialize avb 2.0 for +avb init [] - initialize avb2 for [] avb verify - run verification process using hash d
[PATCH v1 3/3] cmd: avb: remove warning during avb build
From: Andrii Chepurnyi From: Andrii Chepurnyi Remove warning during avb build: cmd/avb.c:247:8: warning: unused variable ‘extra_args’ [-Wunused-variable] 247 | char *extra_args; |^~ cmd/avb.c:246:8: warning: unused variable ‘cmdline’ [-Wunused-variable] 246 | char *cmdline; |^~~ Signed-off-by: Andrii Chepurnyi --- cmd/avb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 6fdbdc708f..a5ac224b22 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -231,8 +231,6 @@ int do_avb_verify_part(struct cmd_tbl *cmdtp, int flag, const char * const requested_partitions[] = {"boot", NULL}; AvbSlotVerifyResult slot_result; AvbSlotVerifyData *out_data; - char *cmdline; - char *extra_args; char *slot_suffix = ""; bool unlocked = false; -- 2.25.1