Skip to content

Commit 4e34565

Browse files
lbmengtrini
authored andcommitted
cmd: blk_common: Stop using hard-coded block size for Sandbox operations
commit 3d2fc79 ("cmd: blk: Allow generic read/write operations to work in sandbox") used the hard-coded block size (512) for accessing the sandbox host device. Now that we have added support for non-512 block size for both Sandbox host device and blkmap driver, let's stop using the hard-coded block size. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent a9bf25c commit 4e34565

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

cmd/blk_common.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,19 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
6767
phys_addr_t paddr = hextoul(argv[2], NULL);
6868
lbaint_t blk = hextoul(argv[3], NULL);
6969
ulong cnt = hextoul(argv[4], NULL);
70+
struct blk_desc *desc;
7071
void *vaddr;
7172
ulong n;
73+
int ret;
7274

7375
printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
7476
if_name, *cur_devnump, blk, cnt);
7577

76-
vaddr = map_sysmem(paddr, 512 * cnt);
77-
n = blk_read_devnum(uclass_id, *cur_devnump, blk, cnt,
78-
vaddr);
78+
ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
79+
if (ret)
80+
return CMD_RET_FAILURE;
81+
vaddr = map_sysmem(paddr, desc->blksz * cnt);
82+
n = blk_dread(desc, blk, cnt, vaddr);
7983
unmap_sysmem(vaddr);
8084

8185
printf("%ld blocks read: %s\n", n,
@@ -85,15 +89,19 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
8589
phys_addr_t paddr = hextoul(argv[2], NULL);
8690
lbaint_t blk = hextoul(argv[3], NULL);
8791
ulong cnt = hextoul(argv[4], NULL);
92+
struct blk_desc *desc;
8893
void *vaddr;
8994
ulong n;
95+
int ret;
9096

9197
printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
9298
if_name, *cur_devnump, blk, cnt);
9399

94-
vaddr = map_sysmem(paddr, 512 * cnt);
95-
n = blk_write_devnum(uclass_id, *cur_devnump, blk, cnt,
96-
vaddr);
100+
ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
101+
if (ret)
102+
return CMD_RET_FAILURE;
103+
vaddr = map_sysmem(paddr, desc->blksz * cnt);
104+
n = blk_dwrite(desc, blk, cnt, vaddr);
97105
unmap_sysmem(vaddr);
98106

99107
printf("%ld blocks written: %s\n", n,

0 commit comments

Comments
 (0)