From 7020b2eca49e2c902bb443273ba21df2050d7f1e Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Tue, 26 Sep 2023 16:43:31 +0800 Subject: [PATCH 01/15] blk: Use a macro for the typical block size Avoid using the magic number 512 directly. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- common/usb_storage.c | 4 ++-- 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/blkmap.c | 2 +- drivers/block/host_dev.c | 2 +- drivers/mmc/mmc-uclass.c | 2 +- drivers/nvme/nvme.c | 2 +- include/blk.h | 2 ++ 10 files changed, 16 insertions(+), 10 deletions(-) diff --git a/common/usb_storage.c b/common/usb_storage.c index 85774220ef..35c656db0d 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -219,8 +219,8 @@ static int usb_stor_probe_device(struct usb_device *udev) snprintf(str, sizeof(str), "lun%d", lun); ret = blk_create_devicef(udev->dev, "usb_storage_blk", str, - UCLASS_USB, usb_max_devs, 512, 0, - &dev); + UCLASS_USB, usb_max_devs, + DEFAULT_BLKSZ, 0, &dev); if (ret) { debug("Cannot bind driver\n"); return ret; diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c index 6a4d861bf1..b4d4e39c9b 100644 --- a/drivers/ata/dwc_ahsata.c +++ b/drivers/ata/dwc_ahsata.c @@ -880,7 +880,8 @@ int dwc_ahsata_scan(struct udevice *dev) device_find_first_child(dev, &blk); if (!blk) { ret = blk_create_devicef(dev, "dwc_ahsata_blk", "blk", - UCLASS_AHCI, -1, 512, 0, &blk); + UCLASS_AHCI, -1, DEFAULT_BLKSZ, + 0, &blk); if (ret) { debug("Can't create device\n"); return ret; diff --git a/drivers/ata/fsl_sata.c b/drivers/ata/fsl_sata.c index 972101b29c..969bc191f8 100644 --- a/drivers/ata/fsl_sata.c +++ b/drivers/ata/fsl_sata.c @@ -888,7 +888,8 @@ static int fsl_ata_probe(struct udevice *dev) for (i = 0; i < nr_ports; i++) { snprintf(sata_name, sizeof(sata_name), "fsl_sata%d", i); ret = blk_create_devicef(dev, "sata_fsl_blk", sata_name, - UCLASS_AHCI, -1, 512, 0, &blk); + UCLASS_AHCI, -1, DEFAULT_BLKSZ, + 0, &blk); if (ret) { debug("Can't create device\n"); return ret; diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index 18c7a66db1..1abea0b309 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -1076,7 +1076,8 @@ static int sata_mv_probe(struct udevice *dev) for (i = 0; i < nr_ports; i++) { ret = blk_create_devicef(dev, "sata_mv_blk", "blk", - UCLASS_AHCI, -1, 512, 0, &blk); + UCLASS_AHCI, -1, DEFAULT_BLKSZ, + 0, &blk); if (ret) { debug("Can't create device\n"); continue; diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c index b5e150d568..43a91a7912 100644 --- a/drivers/ata/sata_sil.c +++ b/drivers/ata/sata_sil.c @@ -730,7 +730,8 @@ static int sil_pci_probe(struct udevice *dev) for (i = sata_info.portbase; i < sata_info.maxport; i++) { snprintf(sata_name, sizeof(sata_name), "sil_sata%d", i); ret = blk_create_devicef(dev, "sata_sil_blk", sata_name, - UCLASS_AHCI, -1, 512, 0, &blk); + UCLASS_AHCI, -1, DEFAULT_BLKSZ, + 0, &blk); if (ret) { debug("Can't create device\n"); return ret; diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 2bb0acc20f..409aa46de2 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -390,7 +390,7 @@ int blkmap_dev_bind(struct udevice *dev) int err; err = blk_create_devicef(dev, "blkmap_blk", "blk", UCLASS_BLKMAP, - dev_seq(dev), 512, 0, &bm->blk); + dev_seq(dev), DEFAULT_BLKSZ, 0, &bm->blk); if (err) return log_msg_ret("blk", err); diff --git a/drivers/block/host_dev.c b/drivers/block/host_dev.c index 64422417b7..31c7814054 100644 --- a/drivers/block/host_dev.c +++ b/drivers/block/host_dev.c @@ -105,7 +105,7 @@ static int host_sb_bind(struct udevice *dev) int ret; ret = blk_create_devicef(dev, "sandbox_host_blk", "blk", UCLASS_HOST, - dev_seq(dev), 512, 0, &blk); + dev_seq(dev), DEFAULT_BLKSZ, 0, &blk); if (ret) return log_msg_ret("blk", ret); diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index 0e157672ea..328456831d 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -412,7 +412,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) debug("%s: alias devnum=%d\n", __func__, dev_seq(dev)); ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC, - dev_seq(dev), 512, 0, &bdev); + dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev); if (ret) { debug("Cannot create block device\n"); return ret; diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index 20dc910d8a..c39cd41aa3 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -906,7 +906,7 @@ int nvme_init(struct udevice *udev) /* The real blksz and size will be set by nvme_blk_probe() */ ret = blk_create_devicef(udev, "nvme-blk", name, UCLASS_NVME, - -1, 512, 0, &ns_udev); + -1, DEFAULT_BLKSZ, 0, &ns_udev); if (ret) goto free_id; diff --git a/include/blk.h b/include/blk.h index 95e86e2d5d..bbff057aed 100644 --- a/include/blk.h +++ b/include/blk.h @@ -21,6 +21,8 @@ typedef ulong lbaint_t; #define LBAF "%" LBAFlength "x" #define LBAFU "%" LBAFlength "u" +#define DEFAULT_BLKSZ 512 + struct udevice; static inline bool blk_enabled(void) From 77ca9d74571e92969591d39df134ccd72296f4d9 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Tue, 26 Sep 2023 16:43:32 +0800 Subject: [PATCH 02/15] cmd: host: Mandate the filename parameter in the 'bind' command At present the host bind command does not require filename to be provided. When it is not given NULL is passed to the host device driver, which ends up failure afterwards. Change to mandate the filename so that it is useful. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- cmd/host.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/host.c b/cmd/host.c index fb1cb1fdd1..b924940ffb 100644 --- a/cmd/host.c +++ b/cmd/host.c @@ -59,10 +59,10 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, argv++; } - if (argc > 2) + if (argc != 2) return CMD_RET_USAGE; label = argv[0]; - file = argc > 1 ? argv[1] : NULL; + file = argv[1]; ret = host_create_attach_file(label, file, removable, &dev); if (ret) { @@ -253,7 +253,7 @@ U_BOOT_CMD( "host save hostfs - [] - " "save a file to host\n" "host size hostfs - - determine size of file on host\n" - "host bind [-r]