[PATCH 00/15] blk: sandbox: Support binding a device with a given logical block size

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Sep 26 10:58:36 CEST 2023


On 9/26/23 10:43, Bin Meng wrote:
> 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.

It is really good to have an easy way to test other block sizes.

We can also use QEMU for alternative block sizes:

$ qemu-system-riscv64 -device nvme,help
logical_block_size=<size>
physical_block_size=<size>

In the commit messages, please, make it clear that you refer to logical
block sizes and not to the physical block size.

Best regards

Heinrich

>
> 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
>
>
> Bin Meng (15):
>    blk: Use a macro for the typical block size
>    cmd: host: Mandate the filename parameter in the 'bind' command
>    blk: sandbox: Support binding a device with a given logical block size
>    blk: host_dev: Make host_sb_detach_file() and host_sb_ops static
>    blk: host_dev: Sanity check on the size of host backing file
>    cmd: host: Print out the block size of the host device
>    blk: blkmap: Make bind/unbind routines static
>    cmd: blkmap: Make map_handlers[] and its .fn static
>    blk: blkmap: Support mapping to device of any block size
>    cmd: blk_common: Use macros for the return values
>    dm: blk: Rename get_desc() and make it externally visible
>    cmd: blk_common: Stop using hard-coded block size for Sandbox
>      operations
>    dm: blk: Drop blk_{read,write}_devnum()
>    disk: part: Print out the unknown device uclass id
>    disk: part: Handle blkmap device in print_part_header()
>
>   cmd/blk_common.c            | 34 +++++++++++++++----------
>   cmd/blkmap.c                |  7 ++---
>   cmd/host.c                  | 25 +++++++++++++-----
>   common/usb_storage.c        |  4 +--
>   disk/part.c                 |  5 +++-
>   drivers/ata/dwc_ahsata.c    |  3 ++-
>   drivers/ata/fsl_sata.c      |  3 ++-
>   drivers/ata/sata_mv.c       |  3 ++-
>   drivers/ata/sata_sil.c      |  3 ++-
>   drivers/block/blk-uclass.c  | 51 +++++--------------------------------
>   drivers/block/blkmap.c      | 16 ++++++------
>   drivers/block/host-uclass.c | 15 ++++++++---
>   drivers/block/host_dev.c    | 11 +++++---
>   drivers/mmc/mmc-uclass.c    |  2 +-
>   drivers/nvme/nvme.c         |  2 +-
>   include/blk.h               | 40 ++++++++++-------------------
>   include/sandbox_host.h      |  7 +++--
>   test/dm/blk.c               |  7 ++---
>   test/dm/host.c              | 26 +++++++++----------
>   19 files changed, 129 insertions(+), 135 deletions(-)
>



More information about the U-Boot mailing list