summaryrefslogtreecommitdiff
path: root/cmd/blk_common.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-10-10 21:47:50 -0400
committerTom Rini <trini@konsulko.com>2023-10-10 21:47:50 -0400
commitbe98a786b67dfcccde1f18ec7cbfe1584e03cebe (patch)
tree8a5006ab4a8b4c96494c0973706e0fe8eb738aed /cmd/blk_common.c
parent833ff23047c50e4053fb1bda21f4e2c9f6a3aa6a (diff)
parent5fdd48066e8a055576294c3846be8ea3914e7902 (diff)
Merge branch '2023-10-10-blk-sandbox-support-binding-a-device-with-a-given-logical-block-size'
To quote the author: At present on Sandbox when binding to a host backing file, the host block device is created with a hard-coded 512 bytes block size. Such assumption works for most cases, but for situation that with a raw image file dump from a pre-formatted GPT partitioned disk image from a 4KiB block size device, when binding this file to a host device and mapping this device to a blkmap, "blkmap" command like "blkmap part" won't work correctly, due to block size mismatch during parsing the partition table. This series updates Sandbox block driver, as well as the blkmap driver, to get rid of the hard-coded 512 bytes block size assumption. This series is available at u-boot-x86/blk for testing. Test log (512 block size): => host bind 0 test.img => host info dev blocks blksz label path 0 262144 512 0 test.img => blkmap create 0 Created "0" => blkmap map 0 0 40000 linear host 0 0 Block 0x0+0x40000 mapped to block 0x0 of "host 0" => blkmap info Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap Type: Hard Disk Capacity: 128.0 MB = 0.1 GB (262144 x 512) => blkmap part Partition Map for BLKMAP device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00000022 0x000000bd "u-boot-spl" attrs: 0x0000000000000000 type: 5b193300-fc78-40cd-8002-e86c45580b47 (5b193300-fc78-40cd-8002-e86c45580b47) guid: 0bb6bb6e-4aac-4c27-be03-016b01e7b941 2 0x00000822 0x00000c84 "u-boot" attrs: 0x0000000000000000 type: 2e54b353-1271-4842-806f-e436d6af6985 (2e54b353-1271-4842-806f-e436d6af6985) guid: 91d50814-8e31-4cc0-97dc-779e1dc59056 3 0x00000c85 0x0000cc84 "rootfs" attrs: 0x0000000000000004 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 (linux) guid: 42799722-6e55-46e6-afa9-529e7af3f03b Test log (4096 block size): => host bind 0 test.img 4096 => host info dev blocks blksz label path 0 32768 4096 0 test.img => blkmap create 0 Created "0" => blkmap map 0 0 8000 linear host 0 0 Block 0x0+0x8000 mapped to block 0x0 of "host 0" => blkmap info Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap Type: Hard Disk Capacity: 128.0 MB = 0.1 GB (32768 x 4096) => blkmap part Partition Map for BLKMAP device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00000100 0x00001fff "primary" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 (linux) guid: eba904d7-72c1-4dbd-bb4e-36be49cba5e3 2 0x00002000 0x00007ffa "primary" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 (linux) guid: c48c360e-db47-46da-ab87-26416fad3cd3
Diffstat (limited to 'cmd/blk_common.c')
-rw-r--r--cmd/blk_common.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/cmd/blk_common.c b/cmd/blk_common.c
index 9f9d4327a99..02ac92837b6 100644
--- a/cmd/blk_common.c
+++ b/cmd/blk_common.c
@@ -25,18 +25,18 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
case 2:
if (strncmp(argv[1], "inf", 3) == 0) {
blk_list_devices(uclass_id);
- return 0;
+ return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "dev", 3) == 0) {
if (blk_print_device_num(uclass_id, *cur_devnump)) {
printf("\nno %s devices available\n", if_name);
return CMD_RET_FAILURE;
}
- return 0;
+ return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "part", 4) == 0) {
if (blk_list_part(uclass_id))
printf("\nno %s partition table available\n",
if_name);
- return 0;
+ return CMD_RET_SUCCESS;
}
return CMD_RET_USAGE;
case 3:
@@ -49,7 +49,7 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
} else {
return CMD_RET_FAILURE;
}
- return 0;
+ return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "part", 4) == 0) {
int dev = (int)dectoul(argv[2], NULL);
@@ -58,7 +58,7 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
if_name, dev);
return CMD_RET_FAILURE;
}
- return 0;
+ return CMD_RET_SUCCESS;
}
return CMD_RET_USAGE;
@@ -67,38 +67,46 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
+ struct blk_desc *desc;
void *vaddr;
ulong n;
+ int ret;
printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
- vaddr = map_sysmem(paddr, 512 * cnt);
- n = blk_read_devnum(uclass_id, *cur_devnump, blk, cnt,
- vaddr);
+ ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
+ if (ret)
+ return CMD_RET_FAILURE;
+ vaddr = map_sysmem(paddr, desc->blksz * cnt);
+ n = blk_dread(desc, blk, cnt, vaddr);
unmap_sysmem(vaddr);
printf("%ld blocks read: %s\n", n,
n == cnt ? "OK" : "ERROR");
- return n == cnt ? 0 : 1;
+ return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
} else if (strcmp(argv[1], "write") == 0) {
phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
+ struct blk_desc *desc;
void *vaddr;
ulong n;
+ int ret;
printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
- vaddr = map_sysmem(paddr, 512 * cnt);
- n = blk_write_devnum(uclass_id, *cur_devnump, blk, cnt,
- vaddr);
+ ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
+ if (ret)
+ return CMD_RET_FAILURE;
+ vaddr = map_sysmem(paddr, desc->blksz * cnt);
+ n = blk_dwrite(desc, blk, cnt, vaddr);
unmap_sysmem(vaddr);
printf("%ld blocks written: %s\n", n,
n == cnt ? "OK" : "ERROR");
- return n == cnt ? 0 : 1;
+ return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}