aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2016-03-14 19:21:44 -0400
committerTom Rini <trini@konsulko.com>2016-03-14 19:21:44 -0400
commit88033d737d9f46e7eebda6a8f9770957eb9aae9c (patch)
tree0b7c3bc6caa5ab4b7f8e88f05ce51ace87f25890
parent9f0f432c0aea1e70959a0c06938459d3175a36b0 (diff)
parent608e399fdef82e983db44c5cb8f5e772bba870e2 (diff)
downloadu-boot-88033d737d9f46e7eebda6a8f9770957eb9aae9c.zip
u-boot-88033d737d9f46e7eebda6a8f9770957eb9aae9c.tar.gz
u-boot-88033d737d9f46e7eebda6a8f9770957eb9aae9c.tar.bz2
Merge git://git.denx.de/u-boot-dm
-rw-r--r--api/api.c2
-rw-r--r--api/api_storage.c26
-rw-r--r--arch/arm/mach-rockchip/rk3288/sdram_rk3288.c2
-rw-r--r--arch/nios2/cpu/cpu.c4
-rw-r--r--arch/x86/cpu/interrupts.c2
-rw-r--r--arch/x86/cpu/ivybridge/cpu.c14
-rw-r--r--arch/x86/cpu/ivybridge/gma.c6
-rw-r--r--arch/x86/cpu/ivybridge/sata.c4
-rw-r--r--arch/x86/cpu/ivybridge/sdram.c4
-rw-r--r--arch/x86/lib/mpspec.c2
-rw-r--r--board/cm5200/fwupdate.c4
-rw-r--r--board/mpl/pip405/README4
-rw-r--r--board/sunxi/board.c4
-rw-r--r--cmd/bmp.c12
-rw-r--r--cmd/cbfs.c5
-rw-r--r--cmd/cramfs.c5
-rw-r--r--cmd/disk.c12
-rw-r--r--cmd/fat.c12
-rw-r--r--cmd/gpt.c10
-rw-r--r--cmd/host.c13
-rw-r--r--cmd/ide.c44
-rw-r--r--cmd/mmc.c4
-rw-r--r--cmd/mmc_spi.c4
-rw-r--r--cmd/part.c24
-rw-r--r--cmd/read.c10
-rw-r--r--cmd/reiser.c12
-rw-r--r--cmd/sata.c22
-rw-r--r--cmd/scsi.c24
-rw-r--r--cmd/tpm.c4
-rw-r--r--cmd/unzip.c4
-rw-r--r--cmd/usb.c12
-rw-r--r--cmd/usb_mass_storage.c10
-rw-r--r--cmd/zfs.c10
-rw-r--r--common/env_fat.c12
-rw-r--r--common/fb_mmc.c33
-rw-r--r--common/spl/spl_ext.c12
-rw-r--r--common/spl/spl_fat.c8
-rw-r--r--common/spl/spl_mmc.c2
-rw-r--r--common/spl/spl_sata.c2
-rw-r--r--common/spl/spl_usb.c2
-rw-r--r--common/usb_storage.c276
-rw-r--r--disk/part.c230
-rw-r--r--disk/part_amiga.c47
-rw-r--r--disk/part_dos.c66
-rw-r--r--disk/part_efi.c101
-rw-r--r--disk/part_iso.c72
-rw-r--r--disk/part_mac.c58
-rw-r--r--drivers/block/Kconfig11
-rw-r--r--drivers/block/Makefile2
-rw-r--r--drivers/block/blk-uclass.c175
-rw-r--r--drivers/block/dwc_ahsata.c4
-rw-r--r--drivers/block/pata_bfin.c2
-rw-r--r--drivers/block/sandbox.c166
-rw-r--r--drivers/block/systemace.c12
-rw-r--r--drivers/core/simple-bus.c1
-rw-r--r--drivers/core/uclass.c13
-rw-r--r--drivers/dfu/dfu_mmc.c4
-rw-r--r--drivers/gpio/rk_gpio.c4
-rw-r--r--drivers/misc/altera_sysid.c4
-rw-r--r--drivers/mmc/arm_pl180_mmci.c2
-rw-r--r--drivers/mmc/mmc.c14
-rw-r--r--drivers/mmc/mmc_private.h8
-rw-r--r--drivers/mmc/mmc_write.c8
-rw-r--r--drivers/mmc/mxsmmc.c24
-rw-r--r--drivers/mmc/omap_hsmmc.c4
-rw-r--r--drivers/mmc/sdhci.c2
-rw-r--r--drivers/pci/pci-uclass.c4
-rw-r--r--drivers/pci/pci_auto_common.c51
-rw-r--r--drivers/power/regulator/regulator-uclass.c2
-rw-r--r--drivers/serial/serial-uclass.c5
-rw-r--r--drivers/serial/serial_arc.c3
-rw-r--r--drivers/serial/serial_lpuart.c6
-rw-r--r--drivers/serial/serial_mxc.c8
-rw-r--r--drivers/serial/serial_pxa.c8
-rw-r--r--drivers/serial/serial_s3c24x0.c8
-rw-r--r--drivers/serial/usbtty.c7
-rw-r--r--drivers/timer/timer-uclass.c4
-rw-r--r--drivers/video/vidconsole-uclass.c6
-rw-r--r--fs/ext4/dev.c54
-rw-r--r--fs/ext4/ext4_common.c27
-rw-r--r--fs/ext4/ext4fs.c2
-rw-r--r--fs/fat/fat.c18
-rw-r--r--fs/fat/fat_write.c5
-rw-r--r--fs/fs.c8
-rw-r--r--fs/reiserfs/dev.c33
-rw-r--r--fs/sandbox/sandboxfs.c4
-rw-r--r--fs/ubifs/ubifs.c4
-rw-r--r--fs/zfs/dev.c35
-rw-r--r--fs/zfs/zfs.c2
-rw-r--r--include/blk.h248
-rw-r--r--include/common.h2
-rw-r--r--include/configs/UCP1020.h1
-rw-r--r--include/configs/km/keymile-common.h1
-rw-r--r--include/configs/sandbox.h7
-rw-r--r--include/debug_uart.h4
-rw-r--r--include/dm/uclass-id.h1
-rw-r--r--include/dm/uclass.h15
-rw-r--r--include/ext4fs.h6
-rw-r--r--include/fat.h4
-rw-r--r--include/ide.h18
-rw-r--r--include/mmc.h2
-rw-r--r--include/part.h308
-rw-r--r--include/reiserfs.h2
-rw-r--r--include/sandboxblockdev.h4
-rw-r--r--include/sandboxfs.h2
-rw-r--r--include/sata.h2
-rw-r--r--include/spl.h10
-rw-r--r--include/systemace.h2
-rw-r--r--include/ubifs_uboot.h2
-rw-r--r--include/usb.h2
-rw-r--r--include/usb_mass_storage.h2
-rw-r--r--include/zfs_common.h4
-rw-r--r--lib/fdtdec.c5
-rw-r--r--lib/gunzip.c2
-rw-r--r--lib/tpm.c6
-rw-r--r--test/dm/usb.c8
-rw-r--r--tools/buildman/control.py3
-rw-r--r--tools/buildman/toolchain.py50
-rw-r--r--tools/fdtgrep.c14
-rw-r--r--tools/patman/patchstream.py2
-rwxr-xr-xtools/patman/patman.py3
121 files changed, 1737 insertions, 1021 deletions
diff --git a/api/api.c b/api/api.c
index 6b114f0..457dc36 100644
--- a/api/api.c
+++ b/api/api.c
@@ -189,7 +189,7 @@ static int API_get_timer(va_list ap)
*
* - net: &eth_device struct address from list pointed to by eth_devices
*
- * - storage: block_dev_desc_t struct address from &ide_dev_desc[n],
+ * - storage: struct blk_desc struct address from &ide_dev_desc[n],
* &scsi_dev_desc[n] and similar tables
*
****************************************************************************/
diff --git a/api/api_storage.c b/api/api_storage.c
index bc2b4d6..8c30c56 100644
--- a/api/api_storage.c
+++ b/api/api_storage.c
@@ -103,10 +103,10 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di)
int i;
- block_dev_desc_t *dd;
+ struct blk_desc *dd;
if (first) {
- di->cookie = (void *)get_dev(specs[type].name, 0);
+ di->cookie = (void *)blk_get_dev(specs[type].name, 0);
if (di->cookie == NULL)
return 0;
else
@@ -119,7 +119,8 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di)
} else {
for (i = 0; i < specs[type].max_dev; i++)
- if (di->cookie == (void *)get_dev(specs[type].name, i)) {
+ if (di->cookie ==
+ (void *)blk_get_dev(specs[type].name, i)) {
/* previous cookie found -- advance to the
* next device, if possible */
@@ -129,7 +130,8 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di)
break;
}
- di->cookie = (void *)get_dev(specs[type].name, i);
+ di->cookie = (void *)blk_get_dev(
+ specs[type].name, i);
if (di->cookie == NULL)
return 0;
else
@@ -148,7 +150,7 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di)
di->type = specs[type].type;
if (di->cookie != NULL) {
- dd = (block_dev_desc_t *)di->cookie;
+ dd = (struct blk_desc *)di->cookie;
if (dd->type == DEV_TYPE_UNKNOWN) {
debugf("device instance exists, but is not active..");
found = 0;
@@ -166,15 +168,15 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di)
/*
- * returns: ENUM_IDE, ENUM_USB etc. based on block_dev_desc_t
+ * returns: ENUM_IDE, ENUM_USB etc. based on struct blk_desc
*/
-static int dev_stor_type(block_dev_desc_t *dd)
+static int dev_stor_type(struct blk_desc *dd)
{
int i, j;
for (i = ENUM_IDE; i < ENUM_MAX; i++)
for (j = 0; j < specs[i].max_dev; j++)
- if (dd == get_dev(specs[i].name, j))
+ if (dd == blk_get_dev(specs[i].name, j))
return i;
return ENUM_MAX;
@@ -308,12 +310,12 @@ int dev_enum_storage(struct device_info *di)
return 0;
}
-static int dev_stor_is_valid(int type, block_dev_desc_t *dd)
+static int dev_stor_is_valid(int type, struct blk_desc *dd)
{
int i;
for (i = 0; i < specs[type].max_dev; i++)
- if (dd == get_dev(specs[type].name, i))
+ if (dd == blk_get_dev(specs[type].name, i))
if (dd->type != DEV_TYPE_UNKNOWN)
return 1;
@@ -328,7 +330,7 @@ int dev_open_stor(void *cookie)
if (type == ENUM_MAX)
return API_ENODEV;
- if (dev_stor_is_valid(type, (block_dev_desc_t *)cookie))
+ if (dev_stor_is_valid(type, (struct blk_desc *)cookie))
return 0;
return API_ENODEV;
@@ -348,7 +350,7 @@ int dev_close_stor(void *cookie)
lbasize_t dev_read_stor(void *cookie, void *buf, lbasize_t len, lbastart_t start)
{
int type;
- block_dev_desc_t *dd = (block_dev_desc_t *)cookie;
+ struct blk_desc *dd = (struct blk_desc *)cookie;
if ((type = dev_stor_type(dd)) == ENUM_MAX)
return 0;
diff --git a/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c b/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
index 17daeca..71330cb 100644
--- a/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
@@ -756,7 +756,7 @@ static int veyron_init(struct dram_info *priv)
struct udevice *pmic;
int ret;
- ret = uclass_first_device(UCLASS_PMIC, &pmic);
+ ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
if (ret)
return ret;
diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index be7f99c..4f0f8fc 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -63,11 +63,9 @@ int arch_cpu_init_dm(void)
struct udevice *dev;
int ret;
- ret = uclass_first_device(UCLASS_CPU, &dev);
+ ret = uclass_first_device_err(UCLASS_CPU, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
#ifndef CONFIG_ROM_STUBS
diff --git a/arch/x86/cpu/interrupts.c b/arch/x86/cpu/interrupts.c
index c40200b..10dc4d4 100644
--- a/arch/x86/cpu/interrupts.c
+++ b/arch/x86/cpu/interrupts.c
@@ -249,7 +249,7 @@ int interrupt_init(void)
int ret;
/* Try to set up the interrupt router, but don't require one */
- ret = uclass_first_device(UCLASS_IRQ, &dev);
+ ret = uclass_first_device_err(UCLASS_IRQ, &dev);
if (ret && ret != -ENODEV)
return ret;
diff --git a/arch/x86/cpu/ivybridge/cpu.c b/arch/x86/cpu/ivybridge/cpu.c
index 948833c..5d839a7 100644
--- a/arch/x86/cpu/ivybridge/cpu.c
+++ b/arch/x86/cpu/ivybridge/cpu.c
@@ -104,9 +104,9 @@ int arch_cpu_init_dm(void)
/* TODO(sjg@chromium.org): Get rid of gd->hose */
gd->hose = hose;
- ret = uclass_first_device(UCLASS_LPC, &dev);
- if (!dev)
- return -ENODEV;
+ ret = uclass_first_device_err(UCLASS_LPC, &dev);
+ if (ret)
+ return ret;
/*
* We should do as little as possible before the serial console is
@@ -210,11 +210,9 @@ int print_cpuinfo(void)
/* Early chipset init required before RAM init can work */
uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
- ret = uclass_first_device(UCLASS_LPC, &lpc);
+ ret = uclass_first_device_err(UCLASS_LPC, &lpc);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
/* Cause the SATA device to do its early init */
uclass_first_device(UCLASS_DISK, &dev);
@@ -236,11 +234,9 @@ int print_cpuinfo(void)
post_code(POST_EARLY_INIT);
/* Enable SPD ROMs and DDR-III DRAM */
- ret = uclass_first_device(UCLASS_I2C, &dev);
+ ret = uclass_first_device_err(UCLASS_I2C, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
/* Prepare USB controller early in S3 resume */
if (boot_mode == PEI_BOOT_RESUME)
diff --git a/arch/x86/cpu/ivybridge/gma.c b/arch/x86/cpu/ivybridge/gma.c
index 3b6291e..91a57f9 100644
--- a/arch/x86/cpu/ivybridge/gma.c
+++ b/arch/x86/cpu/ivybridge/gma.c
@@ -812,9 +812,9 @@ int gma_func0_init(struct udevice *dev)
writew(0x0010, RCB_REG(DISPBDF));
setbits_le32(RCB_REG(FD2), PCH_ENABLE_DBDF);
- ret = uclass_first_device(UCLASS_NORTHBRIDGE, &nbridge);
- if (!nbridge)
- return -ENODEV;
+ ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &nbridge);
+ if (ret)
+ return ret;
rev = bridge_silicon_revision(nbridge);
sandybridge_setup_graphics(nbridge, dev);
diff --git a/arch/x86/cpu/ivybridge/sata.c b/arch/x86/cpu/ivybridge/sata.c
index a59d9ed..da6455b 100644
--- a/arch/x86/cpu/ivybridge/sata.c
+++ b/arch/x86/cpu/ivybridge/sata.c
@@ -229,11 +229,9 @@ static int bd82x6x_sata_probe(struct udevice *dev)
struct udevice *pch;
int ret;
- ret = uclass_first_device(UCLASS_PCH, &pch);
+ ret = uclass_first_device_err(UCLASS_PCH, &pch);
if (ret)
return ret;
- if (!pch)
- return -ENODEV;
if (!(gd->flags & GD_FLG_RELOC))
bd82x6x_sata_enable(dev);
diff --git a/arch/x86/cpu/ivybridge/sdram.c b/arch/x86/cpu/ivybridge/sdram.c
index e23c422..0ebcc2c 100644
--- a/arch/x86/cpu/ivybridge/sdram.c
+++ b/arch/x86/cpu/ivybridge/sdram.c
@@ -736,11 +736,9 @@ int dram_init(void)
struct udevice *dev, *me_dev;
int ret;
- ret = uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
+ ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev);
if (ret)
return ret;
diff --git a/arch/x86/lib/mpspec.c b/arch/x86/lib/mpspec.c
index 0faa582..6ab43f1 100644
--- a/arch/x86/lib/mpspec.c
+++ b/arch/x86/lib/mpspec.c
@@ -297,7 +297,7 @@ static int mptable_add_intsrc(struct mp_config_table *mc,
const u32 *cell;
int i, ret;
- ret = uclass_first_device(UCLASS_IRQ, &dev);
+ ret = uclass_first_device_err(UCLASS_IRQ, &dev);
if (ret && ret != -ENODEV) {
debug("%s: Cannot find irq router node\n", __func__);
return ret;
diff --git a/board/cm5200/fwupdate.c b/board/cm5200/fwupdate.c
index 2b92362..2ed90de 100644
--- a/board/cm5200/fwupdate.c
+++ b/board/cm5200/fwupdate.c
@@ -81,7 +81,7 @@ static int load_rescue_image(ulong addr)
char dev[7];
char addr_str[16];
char * const argv[6] = { "fatload", "usb", dev, addr_str, nxri, NULL };
- block_dev_desc_t *stor_dev = NULL;
+ struct blk_desc *stor_dev = NULL;
cmd_tbl_t *bcmd;
/* Get name of firmware directory */
@@ -117,7 +117,7 @@ static int load_rescue_image(ulong addr)
/* Detect partition */
for (partno = -1, i = 0; i < 6; i++) {
- if (get_partition_info(stor_dev, i, &info) == 0) {
+ if (part_get_info(stor_dev, i, &info) == 0) {
if (fat_register_device(stor_dev, i) == 0) {
/* Check if rescue image is present */
FW_DEBUG("Looking for firmware directory '%s'"
diff --git a/board/mpl/pip405/README b/board/mpl/pip405/README
index 1b73dbe..e900c56 100644
--- a/board/mpl/pip405/README
+++ b/board/mpl/pip405/README
@@ -217,8 +217,8 @@ Added files:
Block device changes:
---------------------
To allow the use of dos_part.c, mac_part.c and iso_part.c, the parameter
-block_dev_desc will be used when accessing the functions in these files. The block
-device descriptor (block_dev_desc) contains a pointer to the read routine of the
+blk_desc will be used when accessing the functions in these files. The block
+device descriptor (blk_desc) contains a pointer to the read routine of the
device, which will be used to read blocks from the device.
Renamed function ide_print to dev_print and moved it to the file disk/part.c to use
it for IDE ATAPI and SCSI devices.
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 15b7af6..80eae9c 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -337,8 +337,8 @@ int board_mmc_init(bd_t *bis)
if (!sunxi_mmc_has_egon_boot_signature(mmc0) &&
sunxi_mmc_has_egon_boot_signature(mmc1)) {
/* Booting from emmc / mmc2, swap */
- mmc0->block_dev.dev = 1;
- mmc1->block_dev.dev = 0;
+ mmc0->block_dev.devnum = 1;
+ mmc1->block_dev.devnum = 0;
}
#endif
diff --git a/cmd/bmp.c b/cmd/bmp.c
index 01b3d39..fb6fe3f 100644
--- a/cmd/bmp.c
+++ b/cmd/bmp.c
@@ -246,18 +246,14 @@ int bmp_display(ulong addr, int x, int y)
addr = map_to_sysmem(bmp);
#ifdef CONFIG_DM_VIDEO
- ret = uclass_first_device(UCLASS_VIDEO, &dev);
+ ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
if (!ret) {
- if (!dev)
- ret = -ENODEV;
- if (!ret) {
- bool align = false;
+ bool align = false;
# ifdef CONFIG_SPLASH_SCREEN_ALIGN
- align = true;
+ align = true;
# endif /* CONFIG_SPLASH_SCREEN_ALIGN */
- ret = video_bmp_display(dev, addr, x, y, align);
- }
+ ret = video_bmp_display(dev, addr, x, y, align);
}
#elif defined(CONFIG_LCD)
ret = lcd_display_bitmap(addr, x, y);
diff --git a/cmd/cbfs.c b/cmd/cbfs.c
index 35d8a7a..779e9c0 100644
--- a/cmd/cbfs.c
+++ b/cmd/cbfs.c
@@ -103,7 +103,7 @@ int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
printf(" size type name\n");
printf("------------------------------------------\n");
while (file) {
- u32 type = file_cbfs_type(file);
+ int type = file_cbfs_type(file);
char *type_name = NULL;
const char *filename = file_cbfs_name(file);
@@ -140,7 +140,8 @@ int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
case CBFS_COMPONENT_CMOS_LAYOUT:
type_name = "cmos layout";
break;
- case -1UL:
+ case -1:
+ case 0:
type_name = "null";
break;
}
diff --git a/cmd/cramfs.c b/cmd/cramfs.c
index 270701b..c103491 100644
--- a/cmd/cramfs.c
+++ b/cmd/cramfs.c
@@ -29,7 +29,6 @@
# define DEBUGF(fmt, args...)
#endif
-#ifdef CONFIG_CRAMFS_CMDLINE
#include <flash.h>
#ifdef CONFIG_SYS_NO_FLASH
@@ -201,7 +200,3 @@ U_BOOT_CMD(
"[ directory ]\n"
" - list files in a directory.\n"
);
-
-#endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
-
-/***************************************************/
diff --git a/cmd/disk.c b/cmd/disk.c
index 106f2d1..2fd1717 100644
--- a/cmd/disk.c
+++ b/cmd/disk.c
@@ -20,7 +20,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
image_header_t *hdr;
#endif
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
#if CONFIG_IS_ENABLED(FIT)
const void *fit_hdr = NULL;
@@ -38,14 +38,14 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
- part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
+ part = blk_get_device_part_str(intf, (argc == 3) ? argv[2] : NULL,
&dev_desc, &info, 1);
if (part < 0) {
bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
return 1;
}
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
printf("\nLoading from %s device %d, partition %d: "
@@ -56,7 +56,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
", Block Size: %ld\n",
info.start, info.size, info.blksz);
- if (dev_desc->block_read(dev_desc, info.start, 1, (ulong *)addr) != 1) {
+ if (blk_dread(dev_desc, info.start, 1, (ulong *)addr) != 1) {
printf("** Read error on %d:%d\n", dev, part);
bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
return 1;
@@ -100,8 +100,8 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
cnt /= info.blksz;
cnt -= 1;
- if (dev_desc->block_read(dev_desc, info.start + 1, cnt,
- (ulong *)(addr + info.blksz)) != cnt) {
+ if (blk_dread(dev_desc, info.start + 1, cnt,
+ (ulong *)(addr + info.blksz)) != cnt) {
printf("** Read error on %d:%d\n", dev, part);
bootstage_error(BOOTSTAGE_ID_IDE_READ);
return 1;
diff --git a/cmd/fat.c b/cmd/fat.c
index aae993d..4e20746 100644
--- a/cmd/fat.c
+++ b/cmd/fat.c
@@ -69,7 +69,7 @@ static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
int dev, part;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
disk_partition_t info;
if (argc < 2) {
@@ -77,11 +77,11 @@ static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
return 0;
}
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
if (fat_set_blk_dev(dev_desc, &info) != 0) {
printf("\n** Unable to use %s %d:%d for fatinfo **\n",
argv[1], dev, part);
@@ -105,7 +105,7 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
int ret;
unsigned long addr;
unsigned long count;
- block_dev_desc_t *dev_desc = NULL;
+ struct blk_desc *dev_desc = NULL;
disk_partition_t info;
int dev = 0;
int part = 1;
@@ -114,11 +114,11 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
if (argc < 5)
return cmd_usage(cmdtp);
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
if (fat_set_blk_dev(dev_desc, &info) != 0) {
printf("\n** Unable to use %s %d:%d for fatwrite **\n",
diff --git a/cmd/gpt.c b/cmd/gpt.c
index d94d553..8ffaef3 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -168,7 +168,7 @@ static bool found_key(const char *str, const char *key)
* @return - zero on success, otherwise error
*
*/
-static int set_gpt_info(block_dev_desc_t *dev_desc,
+static int set_gpt_info(struct blk_desc *dev_desc,
const char *str_part,
char **str_disk_guid,
disk_partition_t **partitions,
@@ -328,7 +328,7 @@ err:
return errno;
}
-static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
+static int gpt_default(struct blk_desc *blk_dev_desc, const char *str_part)
{
int ret;
char *str_disk_guid;
@@ -356,7 +356,7 @@ static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
return ret;
}
-static int gpt_verify(block_dev_desc_t *blk_dev_desc, const char *str_part)
+static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part)
{
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
blk_dev_desc->blksz);
@@ -408,7 +408,7 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int ret = CMD_RET_SUCCESS;
int dev = 0;
char *ep;
- block_dev_desc_t *blk_dev_desc = NULL;
+ struct blk_desc *blk_dev_desc = NULL;
if (argc < 4 || argc > 5)
return CMD_RET_USAGE;
@@ -418,7 +418,7 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("'%s' is not a number\n", argv[3]);
return CMD_RET_USAGE;
}
- blk_dev_desc = get_dev(argv[2], dev);
+ blk_dev_desc = blk_get_dev(argv[2], dev);
if (!blk_dev_desc) {
printf("%s: %s dev %d NOT available\n",
__func__, argv[2], dev);
diff --git a/cmd/host.c b/cmd/host.c
index ba1460e..8d84415 100644
--- a/cmd/host.c
+++ b/cmd/host.c
@@ -5,6 +5,7 @@
*/
#include <common.h>
+#include <dm.h>
#include <fs.h>
#include <part.h>
#include <sandboxblockdev.h>
@@ -67,7 +68,7 @@ static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
int dev;
printf("%3s %12s %s\n", "dev", "blocks", "path");
for (dev = min_dev; dev <= max_dev; dev++) {
- block_dev_desc_t *blk_dev;
+ struct blk_desc *blk_dev;
int ret;
printf("%3d ", dev);
@@ -80,7 +81,13 @@ static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
continue;
}
- struct host_block_dev *host_dev = blk_dev->priv;
+ struct host_block_dev *host_dev;
+
+#ifdef CONFIG_BLK
+ host_dev = dev_get_priv(blk_dev->bdev);
+#else
+ host_dev = blk_dev->priv;
+#endif
printf("%12lu %s\n", (unsigned long)blk_dev->lba,
host_dev->filename);
}
@@ -92,7 +99,7 @@ static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
{
int dev;
char *ep;
- block_dev_desc_t *blk_dev;
+ struct blk_desc *blk_dev;
int ret;
if (argc < 1 || argc > 3)
diff --git a/cmd/ide.c b/cmd/ide.c
index f19a7ce..c4c08c8 100644
--- a/cmd/ide.c
+++ b/cmd/ide.c
@@ -10,6 +10,7 @@
*/
#include <common.h>
+#include <blk.h>
#include <config.h>
#include <watchdog.h>
#include <command.h>
@@ -53,7 +54,7 @@ ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
-block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
+struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
/* ------------------------------------------------------------------------- */
#ifdef CONFIG_IDE_RESET
@@ -62,7 +63,7 @@ static void ide_reset (void);
#define ide_reset() /* dummy */
#endif
-static void ide_ident (block_dev_desc_t *dev_desc);
+static void ide_ident(struct blk_desc *dev_desc);
static uchar ide_wait (int dev, ulong t);
#define IDE_TIME_OUT 2000 /* 2 sec timeout */
@@ -78,8 +79,8 @@ static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len
#endif
#ifdef CONFIG_ATAPI
-static void atapi_inquiry(block_dev_desc_t *dev_desc);
-static ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+static void atapi_inquiry(struct blk_desc *dev_desc);
+static ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, void *buffer);
#endif
@@ -137,7 +138,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
++ok;
if (dev)
putc('\n');
- print_part(&ide_dev_desc[dev]);
+ part_print(&ide_dev_desc[dev]);
}
}
if (!ok) {
@@ -171,7 +172,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
int dev = (int) simple_strtoul(argv[2], NULL, 10);
if (ide_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
- print_part(&ide_dev_desc[dev]);
+ part_print(&ide_dev_desc[dev]);
} else {
printf("\nIDE device %d not available\n",
dev);
@@ -187,7 +188,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
if (strcmp(argv[1], "read") == 0) {
ulong addr = simple_strtoul(argv[2], NULL, 16);
ulong cnt = simple_strtoul(argv[4], NULL, 16);
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
ulong n;
#ifdef CONFIG_SYS_64BIT_LBA
@@ -203,8 +204,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
#endif
dev_desc = &ide_dev_desc[curr_device];
- n = dev_desc->block_read(dev_desc, blk, cnt,
- (ulong *)addr);
+ n = blk_dread(dev_desc, blk, cnt, (ulong *)addr);
/* flush cache after read */
flush_cache(addr,
cnt * ide_dev_desc[curr_device].blksz);
@@ -418,7 +418,7 @@ void ide_init(void)
int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;
ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
ide_dev_desc[i].if_type = IF_TYPE_IDE;
- ide_dev_desc[i].dev = i;
+ ide_dev_desc[i].devnum = i;
ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
ide_dev_desc[i].blksz = 0;
ide_dev_desc[i].log2blksz =
@@ -435,7 +435,7 @@ void ide_init(void)
if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
/* initialize partition type */
- init_part(&ide_dev_desc[i]);
+ part_init(&ide_dev_desc[i]);
if (curr_device < 0)
curr_device = i;
}
@@ -446,7 +446,7 @@ void ide_init(void)
/* ------------------------------------------------------------------------- */
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *ide_get_dev(int dev)
+struct blk_desc *ide_get_dev(int dev)
{
return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
}
@@ -541,7 +541,7 @@ __weak void ide_input_data(int dev, ulong *sect_buf, int words)
/* -------------------------------------------------------------------------
*/
-static void ide_ident(block_dev_desc_t *dev_desc)
+static void ide_ident(struct blk_desc *dev_desc)
{
unsigned char c;
hd_driveid_t iop;
@@ -551,7 +551,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
#endif
int device;
- device = dev_desc->dev;
+ device = dev_desc->devnum;
printf(" Device %d: ", device);
ide_led(DEVICE_LED(device), 1); /* LED on */
@@ -713,10 +713,10 @@ static void ide_ident(block_dev_desc_t *dev_desc)
/* ------------------------------------------------------------------------- */
-ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
void *buffer)
{
- int device = block_dev->dev;
+ int device = block_dev->devnum;
ulong n = 0;
unsigned char c;
unsigned char pwrsave = 0; /* power save */
@@ -839,10 +839,10 @@ IDE_READ_E:
/* ------------------------------------------------------------------------- */
-ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer)
{
- int device = block_dev->dev;
+ int device = block_dev->devnum;
ulong n = 0;
unsigned char c;
@@ -1301,14 +1301,14 @@ error:
}
-static void atapi_inquiry(block_dev_desc_t *dev_desc)
+static void atapi_inquiry(struct blk_desc *dev_desc)
{
unsigned char ccb[12]; /* Command descriptor block */
unsigned char iobuf[64]; /* temp buf */
unsigned char c;
int device;
- device = dev_desc->dev;
+ device = dev_desc->devnum;
dev_desc->type = DEV_TYPE_UNKNOWN; /* not yet valid */
dev_desc->block_read = atapi_read;
@@ -1394,10 +1394,10 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
#define ATAPI_READ_BLOCK_SIZE 2048 /* assuming CD part */
#define ATAPI_READ_MAX_BLOCK (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
-ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
void *buffer)
{
- int device = block_dev->dev;
+ int device = block_dev->devnum;
ulong n = 0;
unsigned char ccb[12]; /* Command descriptor block */
ulong cnt;
diff --git a/cmd/mmc.c b/cmd/mmc.c
index 1c7156f..fb4382e 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -424,7 +424,7 @@ static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
- block_dev_desc_t *mmc_dev;
+ struct blk_desc *mmc_dev;
struct mmc *mmc;
mmc = init_mmc_device(curr_device, false);
@@ -433,7 +433,7 @@ static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
mmc_dev = mmc_get_dev(curr_device);
if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
- print_part(mmc_dev);
+ part_print(mmc_dev);
return CMD_RET_SUCCESS;
}
diff --git a/cmd/mmc_spi.c b/cmd/mmc_spi.c
index a2138b8..0c44d06 100644
--- a/cmd/mmc_spi.c
+++ b/cmd/mmc_spi.c
@@ -72,8 +72,8 @@ static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("Failed to create MMC Device\n");
return 1;
}
- printf("%s: %d at %u:%u hz %u mode %u\n", mmc->cfg->name, mmc->block_dev.dev,
- bus, cs, speed, mode);
+ printf("%s: %d at %u:%u hz %u mode %u\n", mmc->cfg->name,
+ mmc->block_dev.devnum, bus, cs, speed, mode);
mmc_init(mmc);
return 0;
diff --git a/cmd/part.c b/cmd/part.c
index 5599509..414031e 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -29,7 +29,7 @@
static int do_part_uuid(int argc, char * const argv[])
{
int part;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
disk_partition_t info;
if (argc < 2)
@@ -37,7 +37,7 @@ static int do_part_uuid(int argc, char * const argv[])
if (argc > 3)
return CMD_RET_USAGE;
- part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
+ part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
if (part < 0)
return 1;
@@ -52,7 +52,7 @@ static int do_part_uuid(int argc, char * const argv[])
static int do_part_list(int argc, char * const argv[])
{
int ret;
- block_dev_desc_t *desc;
+ struct blk_desc *desc;
char *var = NULL;
bool bootable = false;
int i;
@@ -81,7 +81,7 @@ static int do_part_list(int argc, char * const argv[])
return CMD_RET_USAGE;
}
- ret = get_device(argv[0], argv[1], &desc);
+ ret = blk_get_device_by_str(argv[0], argv[1], &desc);
if (ret < 0)
return 1;
@@ -92,7 +92,7 @@ static int do_part_list(int argc, char * const argv[])
for (p = 1; p < 128; p++) {
char t[5];
- int r = get_partition_info(desc, p, &info);
+ int r = part_get_info(desc, p, &info);
if (r != 0)
continue;
@@ -107,14 +107,14 @@ static int do_part_list(int argc, char * const argv[])
return 0;
}
- print_part(desc);
+ part_print(desc);
return 0;
}
static int do_part_start(int argc, char * const argv[])
{
- block_dev_desc_t *desc;
+ struct blk_desc *desc;
disk_partition_t info;
char buf[512] = { 0 };
int part;
@@ -128,11 +128,11 @@ static int do_part_start(int argc, char * const argv[])
part = simple_strtoul(argv[2], NULL, 0);
- ret = get_device(argv[0], argv[1], &desc);
+ ret = blk_get_device_by_str(argv[0], argv[1], &desc);
if (ret < 0)
return 1;
- err = get_partition_info(desc, part, &info);
+ err = part_get_info(desc, part, &info);
if (err)
return 1;
@@ -148,7 +148,7 @@ static int do_part_start(int argc, char * const argv[])
static int do_part_size(int argc, char * const argv[])
{
- block_dev_desc_t *desc;
+ struct blk_desc *desc;
disk_partition_t info;
char buf[512] = { 0 };
int part;
@@ -162,11 +162,11 @@ static int do_part_size(int argc, char * const argv[])
part = simple_strtoul(argv[2], NULL, 0);
- ret = get_device(argv[0], argv[1], &desc);
+ ret = blk_get_device_by_str(argv[0], argv[1], &desc);
if (ret < 0)
return 1;
- err = get_partition_info(desc, part, &info);
+ err = part_get_info(desc, part, &info);
if (err)
return 1;
diff --git a/cmd/read.c b/cmd/read.c
index 8710288..61d8ce7 100644
--- a/cmd/read.c
+++ b/cmd/read.c
@@ -15,7 +15,7 @@
int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *ep;
- block_dev_desc_t *dev_desc = NULL;
+ struct blk_desc *dev_desc = NULL;
int dev;
int part = 0;
disk_partition_t part_info;
@@ -39,7 +39,7 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
part = (int)simple_strtoul(++ep, NULL, 16);
}
- dev_desc = get_dev(argv[1], dev);
+ dev_desc = blk_get_dev(argv[1], dev);
if (dev_desc == NULL) {
printf("Block device %s %d not supported\n", argv[1], dev);
return 1;
@@ -50,14 +50,14 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
cnt = simple_strtoul(argv[5], NULL, 16);
if (part != 0) {
- if (get_partition_info(dev_desc, part, &part_info)) {
+ if (part_get_info(dev_desc, part, &part_info)) {
printf("Cannot find partition %d\n", part);
return 1;
}
offset = part_info.start;
limit = part_info.size;
} else {
- /* Largest address not available in block_dev_desc_t. */
+ /* Largest address not available in struct blk_desc. */
limit = ~0;
}
@@ -66,7 +66,7 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1;
}
- if (dev_desc->block_read(dev_desc, offset + blk, cnt, addr) < 0) {
+ if (blk_read(dev_desc, offset + blk, cnt, addr) < 0) {
printf("Error reading blocks\n");
return 1;
}
diff --git a/cmd/reiser.c b/cmd/reiser.c
index 8871564..cbdad36 100644
--- a/cmd/reiser.c
+++ b/cmd/reiser.c
@@ -34,13 +34,13 @@ int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *filename = "/";
int dev, part;
- block_dev_desc_t *dev_desc=NULL;
+ struct blk_desc *dev_desc = NULL;
disk_partition_t info;
if (argc < 3)
return CMD_RET_USAGE;
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
@@ -48,7 +48,7 @@ int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
filename = argv[3];
}
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
reiserfs_set_blk_dev(dev_desc, &info);
@@ -82,7 +82,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int dev, part;
ulong addr = 0, filelen;
disk_partition_t info;
- block_dev_desc_t *dev_desc = NULL;
+ struct blk_desc *dev_desc = NULL;
unsigned long count;
char *addr_str;
@@ -122,11 +122,11 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1;
}
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
printf("Loading file \"%s\" from %s device %d%c%c\n",
filename, argv[1], dev,
diff --git a/cmd/sata.c b/cmd/sata.c
index 76bacea..c8de9a3 100644
--- a/cmd/sata.c
+++ b/cmd/sata.c
@@ -16,18 +16,18 @@
#include <sata.h>
static int sata_curr_device = -1;
-block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
+struct blk_desc sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
-static unsigned long sata_bread(block_dev_desc_t *block_dev, lbaint_t start,
+static unsigned long sata_bread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *dst)
{
- return sata_read(block_dev->dev, start, blkcnt, dst);
+ return sata_read(block_dev->devnum, start, blkcnt, dst);
}
-static unsigned long sata_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+static unsigned long sata_bwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer)
{
- return sata_write(block_dev->dev, start, blkcnt, buffer);
+ return sata_write(block_dev->devnum, start, blkcnt, buffer);
}
int __sata_initialize(void)
@@ -36,9 +36,9 @@ int __sata_initialize(void)
int i;
for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
- memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc));
+ memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc));
sata_dev_desc[i].if_type = IF_TYPE_SATA;
- sata_dev_desc[i].dev = i;
+ sata_dev_desc[i].devnum = i;
sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
sata_dev_desc[i].lba = 0;
@@ -52,7 +52,7 @@ int __sata_initialize(void)
rc = scan_sata(i);
if (!rc && (sata_dev_desc[i].lba > 0) &&
(sata_dev_desc[i].blksz > 0))
- init_part(&sata_dev_desc[i]);
+ part_init(&sata_dev_desc[i]);
}
}
sata_curr_device = 0;
@@ -75,7 +75,7 @@ __weak int __sata_stop(void)
int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *sata_get_dev(int dev)
+struct blk_desc *sata_get_dev(int dev)
{
return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL;
}
@@ -131,7 +131,7 @@ static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
++ok;
if (dev)
putc ('\n');
- print_part(&sata_dev_desc[dev]);
+ part_print(&sata_dev_desc[dev]);
}
}
if (!ok) {
@@ -164,7 +164,7 @@ static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int dev = (int)simple_strtoul(argv[2], NULL, 10);
if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
- print_part(&sata_dev_desc[dev]);
+ part_print(&sata_dev_desc[dev]);
} else {
printf("\nSATA device %d not available\n", dev);
rc = 1;
diff --git a/cmd/scsi.c b/cmd/scsi.c
index bc7d1b6..951d1e5 100644
--- a/cmd/scsi.c
+++ b/cmd/scsi.c
@@ -48,7 +48,7 @@ static int scsi_max_devs; /* number of highest available scsi device */
static int scsi_curr_dev; /* current device */
-static block_dev_desc_t scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];
+static struct blk_desc scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];
/********************************************************************************
* forward declerations of some Setup Routines
@@ -66,9 +66,9 @@ void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
static int scsi_read_capacity(ccb *pccb, lbaint_t *capacity,
unsigned long *blksz);
-static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, void *buffer);
-static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, const void *buffer);
@@ -99,7 +99,7 @@ void scsi_scan(int mode)
scsi_dev_desc[i].revision[0]=0;
scsi_dev_desc[i].removable = false;
scsi_dev_desc[i].if_type=IF_TYPE_SCSI;
- scsi_dev_desc[i].dev=i;
+ scsi_dev_desc[i].devnum = i;
scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN;
scsi_dev_desc[i].block_read=scsi_read;
scsi_dev_desc[i].block_write = scsi_write;
@@ -156,7 +156,7 @@ void scsi_scan(int mode)
scsi_dev_desc[scsi_max_devs].log2blksz =
LOG2(scsi_dev_desc[scsi_max_devs].blksz);
scsi_dev_desc[scsi_max_devs].type=perq;
- init_part(&scsi_dev_desc[scsi_max_devs]);
+ part_init(&scsi_dev_desc[scsi_max_devs]);
removable:
if(mode==1) {
printf (" Device %d: ", scsi_max_devs);
@@ -239,7 +239,7 @@ void scsi_init(void)
#endif
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t * scsi_get_dev(int dev)
+struct blk_desc *scsi_get_dev(int dev)
{
return (dev < CONFIG_SYS_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL;
}
@@ -301,7 +301,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (dev)
printf("\n");
debug ("print_part of %x\n",dev);
- print_part(&scsi_dev_desc[dev]);
+ part_print(&scsi_dev_desc[dev]);
}
}
if (!ok)
@@ -329,7 +329,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (strncmp(argv[1],"part",4) == 0) {
int dev = (int)simple_strtoul(argv[2], NULL, 10);
if(scsi_dev_desc[dev].type != DEV_TYPE_UNKNOWN) {
- print_part(&scsi_dev_desc[dev]);
+ part_print(&scsi_dev_desc[dev]);
}
else {
printf ("\nSCSI device %d not available\n", dev);
@@ -376,10 +376,10 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#define SCSI_MAX_READ_BLK 0xFFFF
#define SCSI_LBA48_READ 0xFFFFFFF
-static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, void *buffer)
{
- int device = block_dev->dev;
+ int device = block_dev->devnum;
lbaint_t start, blks;
uintptr_t buf_addr;
unsigned short smallblks = 0;
@@ -443,10 +443,10 @@ static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
/* Almost the maximum amount of the scsi_ext command.. */
#define SCSI_MAX_WRITE_BLK 0xFFFF
-static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, const void *buffer)
{
- int device = block_dev->dev;
+ int device = block_dev->devnum;
lbaint_t start, blks;
uintptr_t buf_addr;
unsigned short smallblks;
diff --git a/cmd/tpm.c b/cmd/tpm.c
index 6edf3e9..312503f 100644
--- a/cmd/tpm.c
+++ b/cmd/tpm.c
@@ -447,8 +447,8 @@ static int get_tpm(struct udevice **devp)
{
int rc;
- rc = uclass_first_device(UCLASS_TPM, devp);
- if (rc || !*devp) {
+ rc = uclass_first_device_err(UCLASS_TPM, devp);
+ if (rc) {
printf("Could not find TPM (ret=%d)\n", rc);
return CMD_RET_FAILURE;
}
diff --git a/cmd/unzip.c b/cmd/unzip.c
index 0686be6..a8bcb1f 100644
--- a/cmd/unzip.c
+++ b/cmd/unzip.c
@@ -43,7 +43,7 @@ U_BOOT_CMD(
static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
- block_dev_desc_t *bdev;
+ struct blk_desc *bdev;
int ret;
unsigned char *addr;
unsigned long length;
@@ -53,7 +53,7 @@ static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
if (argc < 5)
return CMD_RET_USAGE;
- ret = get_device(argv[1], argv[2], &bdev);
+ ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
if (ret < 0)
return CMD_RET_FAILURE;
diff --git a/cmd/usb.c b/cmd/usb.c
index c7b642c..9ed5dc6 100644
--- a/cmd/usb.c
+++ b/cmd/usb.c
@@ -625,7 +625,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int i;
extern char usb_started;
#ifdef CONFIG_USB_STORAGE
- block_dev_desc_t *stor_dev;
+ struct blk_desc *stor_dev;
#endif
if (argc < 2)
@@ -727,7 +727,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (devno)
printf("\n");
debug("print_part of %x\n", devno);
- print_part(stor_dev);
+ part_print(stor_dev);
}
}
} else {
@@ -737,7 +737,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stor_dev->type != DEV_TYPE_UNKNOWN) {
ok++;
debug("print_part of %x\n", devno);
- print_part(stor_dev);
+ part_print(stor_dev);
}
}
if (!ok) {
@@ -759,8 +759,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("\nUSB read: device %d block # %ld, count %ld"
" ... ", usb_stor_curr_dev, blk, cnt);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
- n = stor_dev->block_read(stor_dev, blk, cnt,
- (ulong *)addr);
+ n = blk_dread(stor_dev, blk, cnt, (ulong *)addr);
printf("%ld blocks read: %s\n", n,
(n == cnt) ? "OK" : "ERROR");
if (n == cnt)
@@ -781,8 +780,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("\nUSB write: device %d block # %ld, count %ld"
" ... ", usb_stor_curr_dev, blk, cnt);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
- n = stor_dev->block_write(stor_dev, blk, cnt,
- (ulong *)addr);
+ n = blk_dwrite(stor_dev, blk, cnt, (ulong *)addr);
printf("%ld blocks write: %s\n", n,
(n == cnt) ? "OK" : "ERROR");
if (n == cnt)
diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c
index 0415591..14eed98 100644
--- a/cmd/usb_mass_storage.c
+++ b/cmd/usb_mass_storage.c
@@ -19,7 +19,7 @@
static int ums_read_sector(struct ums *ums_dev,
ulong start, lbaint_t blkcnt, void *buf)
{
- block_dev_desc_t *block_dev = &ums_dev->block_dev;
+ struct blk_desc *block_dev = &ums_dev->block_dev;
lbaint_t blkstart = start + ums_dev->start_sector;
return block_dev->block_read(block_dev, blkstart, blkcnt, buf);
@@ -28,7 +28,7 @@ static int ums_read_sector(struct ums *ums_dev,
static int ums_write_sector(struct ums *ums_dev,
ulong start, lbaint_t blkcnt, const void *buf)
{
- block_dev_desc_t *block_dev = &ums_dev->block_dev;
+ struct blk_desc *block_dev = &ums_dev->block_dev;
lbaint_t blkstart = start + ums_dev->start_sector;
return block_dev->block_write(block_dev, blkstart, blkcnt, buf);
@@ -53,7 +53,7 @@ static void ums_fini(void)
static int ums_init(const char *devtype, const char *devnums)
{
char *s, *t, *devnum, *name;
- block_dev_desc_t *block_dev;
+ struct blk_desc *block_dev;
int ret;
struct ums *ums_new;
@@ -69,7 +69,7 @@ static int ums_init(const char *devtype, const char *devnums)
if (!devnum)
break;
- ret = get_device(devtype, devnum, &block_dev);
+ ret = blk_get_device_by_str(devtype, devnum, &block_dev);
if (ret < 0)
goto cleanup;
@@ -100,7 +100,7 @@ static int ums_init(const char *devtype, const char *devnums)
ums[ums_count].block_dev = *block_dev;
printf("UMS: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n",
- ums_count, ums[ums_count].block_dev.dev,
+ ums_count, ums[ums_count].block_dev.devnum,
ums[ums_count].block_dev.hwpart,
ums[ums_count].start_sector,
ums[ums_count].num_sectors);
diff --git a/cmd/zfs.c b/cmd/zfs.c
index 0aed29e..93067a9 100644
--- a/cmd/zfs.c
+++ b/cmd/zfs.c
@@ -39,7 +39,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
int part;
ulong addr = 0;
disk_partition_t info;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
char buf[12];
unsigned long count;
const char *addr_str;
@@ -80,11 +80,11 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
return 1;
}
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
printf("Loading file \"%s\" from %s device %d%c%c\n",
filename, argv[1], dev,
part ? ':' : ' ', part ? part + '0' : ' ');
@@ -135,7 +135,7 @@ static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
const char *filename = "/";
int part;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
disk_partition_t info;
struct device_s vdev;
@@ -145,7 +145,7 @@ static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc == 4)
filename = argv[3];
- part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
diff --git a/common/env_fat.c b/common/env_fat.c
index d79d864..75616d4 100644
--- a/common/env_fat.c
+++ b/common/env_fat.c
@@ -38,7 +38,7 @@ int env_init(void)
int saveenv(void)
{
env_t env_new;
- block_dev_desc_t *dev_desc = NULL;
+ struct blk_desc *dev_desc = NULL;
disk_partition_t info;
int dev, part;
int err;
@@ -48,13 +48,13 @@ int saveenv(void)
if (err)
return err;
- part = get_device_and_partition(FAT_ENV_INTERFACE,
+ part = blk_get_device_part_str(FAT_ENV_INTERFACE,
FAT_ENV_DEVICE_AND_PART,
&dev_desc, &info, 1);
if (part < 0)
return 1;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
if (fat_set_blk_dev(dev_desc, &info) != 0) {
printf("\n** Unable to use %s %d:%d for saveenv **\n",
FAT_ENV_INTERFACE, dev, part);
@@ -77,18 +77,18 @@ int saveenv(void)
void env_relocate_spec(void)
{
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
- block_dev_desc_t *dev_desc = NULL;
+ struct blk_desc *dev_desc = NULL;
disk_partition_t info;
int dev, part;
int err;
- part = get_device_and_partition(FAT_ENV_INTERFACE,
+ part = blk_get_device_part_str(FAT_ENV_INTERFACE,
FAT_ENV_DEVICE_AND_PART,
&dev_desc, &info, 1);
if (part < 0)
goto err_env_relocate;
- dev = dev_desc->dev;
+ dev = dev_desc->devnum;
if (fat_set_blk_dev(dev_desc, &info) != 0) {
printf("\n** Unable to use %s %d:%d for loading the env **\n",
FAT_ENV_INTERFACE, dev, part);
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 6e742da..e3abcc8 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -6,6 +6,7 @@
#include <config.h>
#include <common.h>
+#include <blk.h>
#include <errno.h>
#include <fastboot.h>
#include <fb_mmc.h>
@@ -22,15 +23,15 @@
static char *response_str;
struct fb_mmc_sparse {
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
};
-static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc,
+static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
const char *name, disk_partition_t *info)
{
int ret;
- ret = get_partition_info_efi_by_name(dev_desc, name, info);
+ ret = part_get_info_efi_by_name(dev_desc, name, info);
if (ret) {
/* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
char env_alias_name[25 + 32 + 1];
@@ -41,7 +42,7 @@ static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc,
strncat(env_alias_name, name, 32);
aliased_part_name = getenv(env_alias_name);
if (aliased_part_name != NULL)
- ret = get_partition_info_efi_by_name(dev_desc,
+ ret = part_get_info_efi_by_name(dev_desc,
aliased_part_name, info);
}
return ret;
@@ -55,17 +56,17 @@ static int fb_mmc_sparse_write(struct sparse_storage *storage,
char *data)
{
struct fb_mmc_sparse *sparse = priv;
- block_dev_desc_t *dev_desc = sparse->dev_desc;
+ struct blk_desc *dev_desc = sparse->dev_desc;
int ret;
- ret = dev_desc->block_write(dev_desc, offset, size, data);
+ ret = blk_dwrite(dev_desc, offset, size, data);
if (!ret)
return -EIO;
return ret;
}
-static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
+static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
const char *part_name, void *buffer,
unsigned int download_bytes)
{
@@ -84,9 +85,9 @@ static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
puts("Flashing Raw Image\n");
- blks = dev_desc->block_write(dev_desc, info->start, blkcnt, buffer);
+ blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
if (blks != blkcnt) {
- error("failed writing to device %d\n", dev_desc->dev);
+ error("failed writing to device %d\n", dev_desc->devnum);
fastboot_fail(response_str, "failed writing to device");
return;
}
@@ -100,13 +101,13 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id,
void *download_buffer, unsigned int download_bytes,
char *response)
{
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
disk_partition_t info;
/* initialize the response buffer */
response_str = response;
- dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+ dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
error("invalid mmc device\n");
fastboot_fail(response_str, "invalid mmc device");
@@ -131,7 +132,7 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id,
printf("........ success\n");
fastboot_okay(response_str, "");
return;
- } else if (get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
+ } else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
error("cannot find partition: '%s'\n", cmd);
fastboot_fail(response_str, "cannot find partition");
return;
@@ -165,7 +166,7 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id,
void fb_mmc_erase(const char *cmd, char *response)
{
int ret;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
disk_partition_t info;
lbaint_t blks, blks_start, blks_size, grp_size;
struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
@@ -179,14 +180,14 @@ void fb_mmc_erase(const char *cmd, char *response)
/* initialize the response buffer */
response_str = response;
- dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+ dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
error("invalid mmc device");
fastboot_fail(response_str, "invalid mmc device");
return;
}
- ret = get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info);
+ ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info);
if (ret) {
error("cannot find partition: '%s'", cmd);
fastboot_fail(response_str, "cannot find partition");
@@ -207,7 +208,7 @@ void fb_mmc_erase(const char *cmd, char *response)
blks = dev_desc->block_erase(dev_desc, blks_start, blks_size);
if (blks != blks_size) {
- error("failed erasing from device %d", dev_desc->dev);
+ error("failed erasing from device %d", dev_desc->devnum);
fastboot_fail(response_str, "failed erasing from device");
return;
}
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index a42fbd0..b77dbf4 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -10,7 +10,7 @@
#include <image.h>
#ifdef CONFIG_SPL_EXT_SUPPORT
-int spl_load_image_ext(block_dev_desc_t *block_dev,
+int spl_load_image_ext(struct blk_desc *block_dev,
int partition,
const char *filename)
{
@@ -22,8 +22,7 @@ int spl_load_image_ext(block_dev_desc_t *block_dev,
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));
- if (get_partition_info(block_dev,
- partition, &part_info)) {
+ if (part_get_info(block_dev, partition, &part_info)) {
printf("spl: no partition table found\n");
return -1;
}
@@ -64,15 +63,14 @@ end:
}
#ifdef CONFIG_SPL_OS_BOOT
-int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition)
+int spl_load_image_ext_os(struct blk_desc *block_dev, int partition)
{
int err;
__maybe_unused loff_t filelen, actlen;
disk_partition_t part_info = {};
__maybe_unused char *file;
- if (get_partition_info(block_dev,
- partition, &part_info)) {
+ if (part_get_info(block_dev, partition, &part_info)) {
printf("spl: no partition table found\n");
return -1;
}
@@ -137,7 +135,7 @@ defaults:
CONFIG_SPL_FS_LOAD_KERNEL_NAME);
}
#else
-int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition)
+int spl_load_image_ext_os(struct blk_desc *block_dev, int partition)
{
return -ENOSYS;
}
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 0daadbe..d761b26 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -19,7 +19,7 @@
static int fat_registered;
#ifdef CONFIG_SPL_FAT_SUPPORT
-static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
+static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
{
int err = 0;
@@ -39,7 +39,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
return err;
}
-int spl_load_image_fat(block_dev_desc_t *block_dev,
+int spl_load_image_fat(struct blk_desc *block_dev,
int partition,
const char *filename)
{
@@ -72,7 +72,7 @@ end:
}
#ifdef CONFIG_SPL_OS_BOOT
-int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
+int spl_load_image_fat_os(struct blk_desc *block_dev, int partition)
{
int err;
__maybe_unused char *file;
@@ -121,7 +121,7 @@ defaults:
CONFIG_SPL_FS_LOAD_KERNEL_NAME);
}
#else
-int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
+int spl_load_image_fat_os(struct blk_desc *block_dev, int partition)
{
return -ENOSYS;
}
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 9482142..c0e76be 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -161,7 +161,7 @@ static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
disk_partition_t info;
int err;
- err = get_partition_info(&mmc->block_dev, partition, &info);
+ err = part_get_info(&mmc->block_dev, partition, &info);
if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
puts("spl: partition error\n");
diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c
index 3ba4c24..1719946 100644
--- a/common/spl/spl_sata.c
+++ b/common/spl/spl_sata.c
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
int spl_sata_load_image(void)
{
int err;
- block_dev_desc_t *stor_dev;
+ struct blk_desc *stor_dev;
err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
if (err) {
diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c
index 588b85c..c42848e 100644
--- a/common/spl/spl_usb.c
+++ b/common/spl/spl_usb.c
@@ -25,7 +25,7 @@ static int usb_stor_curr_dev = -1; /* current device */
int spl_usb_load_image(void)
{
int err;
- block_dev_desc_t *stor_dev;
+ struct blk_desc *stor_dev;
usb_stop();
err = usb_init();
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 8737cf7..1472824 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -43,6 +43,7 @@
#include <asm/byteorder.h>
#include <asm/processor.h>
#include <dm/device-internal.h>
+#include <dm/lists.h>
#include <part.h>
#include <usb.h>
@@ -67,7 +68,9 @@ static __u32 CBWTag;
static int usb_max_devs; /* number of highest available usb device */
-static block_dev_desc_t usb_dev_desc[USB_MAX_STOR_DEV];
+#ifndef CONFIG_BLK
+static struct blk_desc usb_dev_desc[USB_MAX_STOR_DEV];
+#endif
struct us_data;
typedef int (*trans_cmnd)(ccb *cb, struct us_data *data);
@@ -108,26 +111,45 @@ struct us_data {
#define USB_MAX_XFER_BLK 20
#endif
+#ifndef CONFIG_BLK
static struct us_data usb_stor[USB_MAX_STOR_DEV];
+#endif
#define USB_STOR_TRANSPORT_GOOD 0
#define USB_STOR_TRANSPORT_FAILED -1
#define USB_STOR_TRANSPORT_ERROR -2
int usb_stor_get_info(struct usb_device *dev, struct us_data *us,
- block_dev_desc_t *dev_desc);
+ struct blk_desc *dev_desc);
int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
struct us_data *ss);
-static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+#ifdef CONFIG_BLK
+static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr,
+ lbaint_t blkcnt, void *buffer);
+static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr,
+ lbaint_t blkcnt, const void *buffer);
+#else
+static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, void *buffer);
-static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
lbaint_t blkcnt, const void *buffer);
+#endif
void uhci_show_temp_int_td(void);
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *usb_stor_get_dev(int index)
+struct blk_desc *usb_stor_get_dev(int index)
{
+#ifdef CONFIG_BLK
+ struct udevice *dev;
+ int ret;
+
+ ret = blk_get_device(IF_TYPE_USB, index, &dev);
+ if (ret)
+ return NULL;
+ return dev_get_uclass_platdata(dev);
+#else
return (index < usb_max_devs) ? &usb_dev_desc[index] : NULL;
+#endif
}
#endif
@@ -142,6 +164,20 @@ static void usb_show_progress(void)
*/
int usb_stor_info(void)
{
+ int count = 0;
+#ifdef CONFIG_BLK
+ struct udevice *dev;
+
+ for (blk_first_device(IF_TYPE_USB, &dev);
+ dev;
+ blk_next_device(&dev)) {
+ struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+ printf(" Device %d: ", desc->devnum);
+ dev_print(desc);
+ count++;
+ }
+#else
int i;
if (usb_max_devs > 0) {
@@ -151,8 +187,12 @@ int usb_stor_info(void)
}
return 0;
}
+#endif
+ if (!count) {
+ printf("No storage devices, perhaps not 'usb start'ed..?\n");
+ return 1;
+ }
- printf("No storage devices, perhaps not 'usb start'ed..?\n");
return 1;
}
@@ -171,52 +211,110 @@ static unsigned int usb_get_max_lun(struct us_data *us)
return (len > 0) ? *result : 0;
}
-static int usb_stor_probe_device(struct usb_device *dev)
+static int usb_stor_probe_device(struct usb_device *udev)
{
- if (dev == NULL)
+ int lun, max_lun;
+
+#ifdef CONFIG_BLK
+ struct us_data *data;
+ char dev_name[30], *str;
+ int ret;
+#else
+ int start;
+
+ if (udev == NULL)
return -ENOENT; /* no more devices available */
+#endif
debug("\n\nProbing for storage\n");
- if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
- /* OK, it's a storage device. Iterate over its LUNs
- * and populate `usb_dev_desc'.
- */
- int lun, max_lun, start = usb_max_devs;
-
- max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
- for (lun = 0;
- lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
- lun++) {
- struct block_dev_desc *blkdev;
-
- blkdev = &usb_dev_desc[usb_max_devs];
- memset(blkdev, '\0', sizeof(block_dev_desc_t));
- blkdev->if_type = IF_TYPE_USB;
- blkdev->dev = usb_max_devs;
- blkdev->part_type = PART_TYPE_UNKNOWN;
- blkdev->target = 0xff;
- blkdev->type = DEV_TYPE_UNKNOWN;
- blkdev->block_read = usb_stor_read;
- blkdev->block_write = usb_stor_write;
- blkdev->lun = lun;
- blkdev->priv = dev;
-
- if (usb_stor_get_info(dev, &usb_stor[start],
- &usb_dev_desc[usb_max_devs]) ==
- 1) {
- usb_max_devs++;
- debug("%s: Found device %p\n", __func__, dev);
- }
+#ifdef CONFIG_BLK
+ /*
+ * We store the us_data in the mass storage device's platdata. It
+ * is shared by all LUNs (block devices) attached to this mass storage
+ * device.
+ */
+ data = dev_get_platdata(udev->dev);
+ if (!usb_storage_probe(udev, 0, data))
+ return 0;
+ max_lun = usb_get_max_lun(data);
+ for (lun = 0; lun <= max_lun; lun++) {
+ struct blk_desc *blkdev;
+ struct udevice *dev;
+
+ snprintf(dev_name, sizeof(dev_name), "%s.lun%d",
+ udev->dev->name, lun);
+ str = strdup(dev_name);
+ if (!str)
+ return -ENOMEM;
+ ret = blk_create_device(udev->dev, "usb_storage_blk", str,
+ IF_TYPE_USB, usb_max_devs, 512, 0, &dev);
+ if (ret) {
+ debug("Cannot bind driver\n");
+ return ret;
}
- }
- /* if storage device */
+ blkdev = dev_get_uclass_platdata(dev);
+ blkdev->target = 0xff;
+ blkdev->lun = lun;
+
+ ret = usb_stor_get_info(udev, data, blkdev);
+ if (ret == 1)
+ ret = blk_prepare_device(dev);
+ if (!ret) {
+ usb_max_devs++;
+ debug("%s: Found device %p\n", __func__, udev);
+ } else {
+ debug("usb_stor_get_info: Invalid device\n");
+ ret = device_unbind(dev);
+ if (ret)
+ return ret;
+ }
+ }
+#else
+ /* We don't have space to even probe if we hit the maximum */
if (usb_max_devs == USB_MAX_STOR_DEV) {
printf("max USB Storage Device reached: %d stopping\n",
usb_max_devs);
return -ENOSPC;
}
+ if (!usb_storage_probe(udev, 0, &usb_stor[usb_max_devs]))
+ return 0;
+
+ /*
+ * OK, it's a storage device. Iterate over its LUNs and populate
+ * usb_dev_desc'
+ */
+ start = usb_max_devs;
+
+ max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
+ for (lun = 0; lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
+ lun++) {
+ struct blk_desc *blkdev;
+
+ blkdev = &usb_dev_desc[usb_max_devs];
+ memset(blkdev, '\0', sizeof(struct blk_desc));
+ blkdev->if_type = IF_TYPE_USB;
+ blkdev->devnum = usb_max_devs;
+ blkdev->part_type = PART_TYPE_UNKNOWN;
+ blkdev->target = 0xff;
+ blkdev->type = DEV_TYPE_UNKNOWN;
+ blkdev->block_read = usb_stor_read;
+ blkdev->block_write = usb_stor_write;
+ blkdev->lun = lun;
+ blkdev->priv = udev;
+
+ if (usb_stor_get_info(udev, &usb_stor[start],
+ &usb_dev_desc[usb_max_devs]) == 1) {
+ debug("partype: %d\n", blkdev->part_type);
+ part_init(blkdev);
+ debug("partype: %d\n", blkdev->part_type);
+ usb_max_devs++;
+ debug("%s: Found device %p\n", __func__, udev);
+ }
+ }
+#endif
+
return 0;
}
@@ -1011,7 +1109,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start,
* device with proper values (as reported by 'usb info').
*
* Vendor and product length limits are taken from the definition of
- * block_dev_desc_t in include/part.h.
+ * struct blk_desc in include/part.h.
*/
static void usb_bin_fixup(struct usb_device_descriptor descriptor,
unsigned char vendor[],
@@ -1026,39 +1124,50 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor,
}
#endif /* CONFIG_USB_BIN_FIXUP */
-static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+#ifdef CONFIG_BLK
+static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr,
lbaint_t blkcnt, void *buffer)
+#else
+static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
+ lbaint_t blkcnt, void *buffer)
+#endif
{
- int device = block_dev->dev;
lbaint_t start, blks;
uintptr_t buf_addr;
unsigned short smallblks;
- struct usb_device *dev;
+ struct usb_device *udev;
struct us_data *ss;
int retry;
ccb *srb = &usb_ccb;
+#ifdef CONFIG_BLK
+ struct blk_desc *block_dev;
+#endif
if (blkcnt == 0)
return 0;
-
- device &= 0xff;
/* Setup device */
- debug("\nusb_read: dev %d\n", device);
- dev = usb_dev_desc[device].priv;
- if (!dev) {
+#ifdef CONFIG_BLK
+ block_dev = dev_get_uclass_platdata(dev);
+ udev = dev_get_parent_priv(dev_get_parent(dev));
+ debug("\nusb_read: udev %d\n", block_dev->devnum);
+#else
+ debug("\nusb_read: udev %d\n", block_dev->devnum);
+ udev = usb_dev_desc[block_dev->devnum].priv;
+ if (!udev) {
debug("%s: No device\n", __func__);
return 0;
}
- ss = (struct us_data *)dev->privptr;
+#endif
+ ss = (struct us_data *)udev->privptr;
usb_disable_asynch(1); /* asynch transfer not allowed */
- srb->lun = usb_dev_desc[device].lun;
+ srb->lun = block_dev->lun;
buf_addr = (uintptr_t)buffer;
start = blknr;
blks = blkcnt;
- debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF
- " buffer %" PRIxPTR "\n", device, start, blks, buf_addr);
+ debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %"
+ PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr);
do {
/* XXX need some comment here */
@@ -1071,7 +1180,7 @@ static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr,
retry_it:
if (smallblks == USB_MAX_XFER_BLK)
usb_show_progress();
- srb->datalen = usb_dev_desc[device].blksz * smallblks;
+ srb->datalen = block_dev->blksz * smallblks;
srb->pdata = (unsigned char *)buf_addr;
if (usb_read_10(srb, ss, start, smallblks)) {
debug("Read ERROR\n");
@@ -1097,38 +1206,52 @@ retry_it:
return blkcnt;
}
-static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+#ifdef CONFIG_BLK
+static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr,
lbaint_t blkcnt, const void *buffer)
+#else
+static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
+ lbaint_t blkcnt, const void *buffer)
+#endif
{
- int device = block_dev->dev;
lbaint_t start, blks;
uintptr_t buf_addr;
unsigned short smallblks;
- struct usb_device *dev;
+ struct usb_device *udev;
struct us_data *ss;
int retry;
ccb *srb = &usb_ccb;
+#ifdef CONFIG_BLK
+ struct blk_desc *block_dev;
+#endif
if (blkcnt == 0)
return 0;
- device &= 0xff;
/* Setup device */
- debug("\nusb_write: dev %d\n", device);
- dev = usb_dev_desc[device].priv;
- if (!dev)
+#ifdef CONFIG_BLK
+ block_dev = dev_get_uclass_platdata(dev);
+ udev = dev_get_parent_priv(dev_get_parent(dev));
+ debug("\nusb_read: udev %d\n", block_dev->devnum);
+#else
+ debug("\nusb_read: udev %d\n", block_dev->devnum);
+ udev = usb_dev_desc[block_dev->devnum].priv;
+ if (!udev) {
+ debug("%s: No device\n", __func__);
return 0;
- ss = (struct us_data *)dev->privptr;
+ }
+#endif
+ ss = (struct us_data *)udev->privptr;
usb_disable_asynch(1); /* asynch transfer not allowed */
- srb->lun = usb_dev_desc[device].lun;
+ srb->lun = block_dev->lun;
buf_addr = (uintptr_t)buffer;
start = blknr;
blks = blkcnt;
- debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF
- " buffer %" PRIxPTR "\n", device, start, blks, buf_addr);
+ debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %"
+ PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr);
do {
/* If write fails retry for max retry count else
@@ -1143,7 +1266,7 @@ static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr,
retry_it:
if (smallblks == USB_MAX_XFER_BLK)
usb_show_progress();
- srb->datalen = usb_dev_desc[device].blksz * smallblks;
+ srb->datalen = block_dev->blksz * smallblks;
srb->pdata = (unsigned char *)buf_addr;
if (usb_write_10(srb, ss, start, smallblks)) {
debug("Write ERROR\n");
@@ -1289,7 +1412,7 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
}
int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
- block_dev_desc_t *dev_desc)
+ struct blk_desc *dev_desc)
{
unsigned char perq, modi;
ALLOC_CACHE_ALIGN_BUFFER(u32, cap, 2);
@@ -1372,11 +1495,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
dev_desc->log2blksz = LOG2(dev_desc->blksz);
dev_desc->type = perq;
debug(" address %d\n", dev_desc->target);
- debug("partype: %d\n", dev_desc->part_type);
-
- init_part(dev_desc);
- debug("partype: %d\n", dev_desc->part_type);
return 1;
}
@@ -1404,6 +1523,9 @@ U_BOOT_DRIVER(usb_mass_storage) = {
.id = UCLASS_MASS_STORAGE,
.of_match = usb_mass_storage_ids,
.probe = usb_mass_storage_probe,
+#ifdef CONFIG_BLK
+ .platdata_auto_alloc_size = sizeof(struct us_data),
+#endif
};
UCLASS_DRIVER(usb_mass_storage) = {
@@ -1420,5 +1542,17 @@ static const struct usb_device_id mass_storage_id_table[] = {
};
U_BOOT_USB_DEVICE(usb_mass_storage, mass_storage_id_table);
+#endif
+#ifdef CONFIG_BLK
+static const struct blk_ops usb_storage_ops = {
+ .read = usb_stor_read,
+ .write = usb_stor_write,
+};
+
+U_BOOT_DRIVER(usb_storage_blk) = {
+ .name = "usb_storage_blk",
+ .id = UCLASS_BLK,
+ .ops = &usb_storage_ops,
+};
#endif
diff --git a/disk/part.c b/disk/part.c
index 1935b28..2a46050 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -7,6 +7,7 @@
#include <common.h>
#include <command.h>
+#include <errno.h>
#include <ide.h>
#include <malloc.h>
#include <part.h>
@@ -22,7 +23,7 @@
struct block_drvr {
char *name;
- block_dev_desc_t* (*get_dev)(int dev);
+ struct blk_desc* (*get_dev)(int dev);
int (*select_hwpart)(int dev_num, int hwpart);
};
@@ -58,10 +59,26 @@ static const struct block_drvr block_drvr[] = {
DECLARE_GLOBAL_DATA_PTR;
#ifdef HAVE_BLOCK_DEVICE
-static block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
+static struct part_driver *part_driver_lookup_type(int part_type)
+{
+ struct part_driver *drv =
+ ll_entry_start(struct part_driver, part_driver);
+ const int n_ents = ll_entry_count(struct part_driver, part_driver);
+ struct part_driver *entry;
+
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ if (part_type == entry->part_type)
+ return entry;
+ }
+
+ /* Not found */
+ return NULL;
+}
+
+static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
{
const struct block_drvr *drvr = block_drvr;
- block_dev_desc_t* (*reloc_get_dev)(int dev);
+ struct blk_desc* (*reloc_get_dev)(int dev);
int (*select_hwpart)(int dev_num, int hwpart);
char *name;
int ret;
@@ -84,14 +101,14 @@ static block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
select_hwpart += gd->reloc_off;
#endif
if (strncmp(ifname, name, strlen(name)) == 0) {
- block_dev_desc_t *dev_desc = reloc_get_dev(dev);
+ struct blk_desc *dev_desc = reloc_get_dev(dev);
if (!dev_desc)
return NULL;
if (hwpart == 0 && !select_hwpart)
return dev_desc;
if (!select_hwpart)
return NULL;
- ret = select_hwpart(dev_desc->dev, hwpart);
+ ret = select_hwpart(dev_desc->devnum, hwpart);
if (ret < 0)
return NULL;
return dev_desc;
@@ -101,17 +118,17 @@ static block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
return NULL;
}
-block_dev_desc_t *get_dev(const char *ifname, int dev)
+struct blk_desc *blk_get_dev(const char *ifname, int dev)
{
return get_dev_hwpart(ifname, dev, 0);
}
#else
-block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
+struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
{
return NULL;
}
-block_dev_desc_t *get_dev(const char *ifname, int dev)
+struct blk_desc *blk_get_dev(const char *ifname, int dev)
{
return NULL;
}
@@ -144,7 +161,7 @@ static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by, lba512_t di
return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
}
-void dev_print (block_dev_desc_t *dev_desc)
+void dev_print (struct blk_desc *dev_desc)
{
lba512_t lba512; /* number of blocks if 512bytes block size */
@@ -250,55 +267,33 @@ void dev_print (block_dev_desc_t *dev_desc)
#ifdef HAVE_BLOCK_DEVICE
-void init_part(block_dev_desc_t *dev_desc)
+void part_init(struct blk_desc *dev_desc)
{
-#ifdef CONFIG_ISO_PARTITION
- if (test_part_iso(dev_desc) == 0) {
- dev_desc->part_type = PART_TYPE_ISO;
- return;
- }
-#endif
+ struct part_driver *drv =
+ ll_entry_start(struct part_driver, part_driver);
+ const int n_ents = ll_entry_count(struct part_driver, part_driver);
+ struct part_driver *entry;
-#ifdef CONFIG_MAC_PARTITION
- if (test_part_mac(dev_desc) == 0) {
- dev_desc->part_type = PART_TYPE_MAC;
- return;
- }
-#endif
-
-/* must be placed before DOS partition detection */
-#ifdef CONFIG_EFI_PARTITION
- if (test_part_efi(dev_desc) == 0) {
- dev_desc->part_type = PART_TYPE_EFI;
- return;
- }
-#endif
-
-#ifdef CONFIG_DOS_PARTITION
- if (test_part_dos(dev_desc) == 0) {
- dev_desc->part_type = PART_TYPE_DOS;
- return;
- }
-#endif
-
-#ifdef CONFIG_AMIGA_PARTITION
- if (test_part_amiga(dev_desc) == 0) {
- dev_desc->part_type = PART_TYPE_AMIGA;
- return;
- }
-#endif
dev_desc->part_type = PART_TYPE_UNKNOWN;
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ int ret;
+
+ ret = entry->test(dev_desc);
+ debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret);
+ if (!ret) {
+ dev_desc->part_type = entry->part_type;
+ break;
+ }
+ }
}
-
+static void print_part_header(const char *type, struct blk_desc *dev_desc)
+{
#if defined(CONFIG_MAC_PARTITION) || \
defined(CONFIG_DOS_PARTITION) || \
defined(CONFIG_ISO_PARTITION) || \
defined(CONFIG_AMIGA_PARTITION) || \
defined(CONFIG_EFI_PARTITION)
-
-static void print_part_header(const char *type, block_dev_desc_t *dev_desc)
-{
puts ("\nPartition Map for ");
switch (dev_desc->if_type) {
case IF_TYPE_IDE:
@@ -330,63 +325,34 @@ static void print_part_header(const char *type, block_dev_desc_t *dev_desc)
break;
}
printf (" device %d -- Partition Type: %s\n\n",
- dev_desc->dev, type);
-}
-
+ dev_desc->devnum, type);
#endif /* any CONFIG_..._PARTITION */
+}
-void print_part(block_dev_desc_t * dev_desc)
+void part_print(struct blk_desc *dev_desc)
{
+ struct part_driver *drv;
- switch (dev_desc->part_type) {
-#ifdef CONFIG_MAC_PARTITION
- case PART_TYPE_MAC:
- PRINTF ("## Testing for valid MAC partition ##\n");
- print_part_header ("MAC", dev_desc);
- print_part_mac (dev_desc);
- return;
-#endif
-#ifdef CONFIG_DOS_PARTITION
- case PART_TYPE_DOS:
- PRINTF ("## Testing for valid DOS partition ##\n");
- print_part_header ("DOS", dev_desc);
- print_part_dos (dev_desc);
- return;
-#endif
-
-#ifdef CONFIG_ISO_PARTITION
- case PART_TYPE_ISO:
- PRINTF ("## Testing for valid ISO Boot partition ##\n");
- print_part_header ("ISO", dev_desc);
- print_part_iso (dev_desc);
+ drv = part_driver_lookup_type(dev_desc->part_type);
+ if (!drv) {
+ printf("## Unknown partition table type %x\n",
+ dev_desc->part_type);
return;
-#endif
-
-#ifdef CONFIG_AMIGA_PARTITION
- case PART_TYPE_AMIGA:
- PRINTF ("## Testing for a valid Amiga partition ##\n");
- print_part_header ("AMIGA", dev_desc);
- print_part_amiga (dev_desc);
- return;
-#endif
-
-#ifdef CONFIG_EFI_PARTITION
- case PART_TYPE_EFI:
- PRINTF ("## Testing for valid EFI partition ##\n");
- print_part_header ("EFI", dev_desc);
- print_part_efi (dev_desc);
- return;
-#endif
}
- puts ("## Unknown partition table\n");
+
+ PRINTF("## Testing for valid %s partition ##\n", drv->name);
+ print_part_header(drv->name, dev_desc);
+ if (drv->print)
+ drv->print(dev_desc);
}
#endif /* HAVE_BLOCK_DEVICE */
-int get_partition_info(block_dev_desc_t *dev_desc, int part,
+int part_get_info(struct blk_desc *dev_desc, int part,
disk_partition_t *info)
{
#ifdef HAVE_BLOCK_DEVICE
+ struct part_driver *drv;
#ifdef CONFIG_PARTITION_UUIDS
/* The common case is no UUID support */
@@ -396,61 +362,27 @@ int get_partition_info(block_dev_desc_t *dev_desc, int part,
info->type_guid[0] = 0;
#endif
- switch (dev_desc->part_type) {
-#ifdef CONFIG_MAC_PARTITION
- case PART_TYPE_MAC:
- if (get_partition_info_mac(dev_desc, part, info) == 0) {
- PRINTF("## Valid MAC partition found ##\n");
- return 0;
- }
- break;
-#endif
-
-#ifdef CONFIG_DOS_PARTITION
- case PART_TYPE_DOS:
- if (get_partition_info_dos(dev_desc, part, info) == 0) {
- PRINTF("## Valid DOS partition found ##\n");
- return 0;
- }
- break;
-#endif
-
-#ifdef CONFIG_ISO_PARTITION
- case PART_TYPE_ISO:
- if (get_partition_info_iso(dev_desc, part, info) == 0) {
- PRINTF("## Valid ISO boot partition found ##\n");
- return 0;
- }
- break;
-#endif
-
-#ifdef CONFIG_AMIGA_PARTITION
- case PART_TYPE_AMIGA:
- if (get_partition_info_amiga(dev_desc, part, info) == 0) {
- PRINTF("## Valid Amiga partition found ##\n");
- return 0;
- }
- break;
-#endif
-
-#ifdef CONFIG_EFI_PARTITION
- case PART_TYPE_EFI:
- if (get_partition_info_efi(dev_desc, part, info) == 0) {
- PRINTF("## Valid EFI partition found ##\n");
- return 0;
- }
- break;
-#endif
- default:
- break;
+ drv = part_driver_lookup_type(dev_desc->part_type);
+ if (!drv) {
+ debug("## Unknown partition table type %x\n",
+ dev_desc->part_type);
+ return -EPROTONOSUPPORT;
+ }
+ if (!drv->get_info) {
+ PRINTF("## Driver %s does not have the get_info() method\n");
+ return -ENOSYS;
+ }
+ if (drv->get_info(dev_desc, part, info) == 0) {
+ PRINTF("## Valid %s partition found ##\n", drv->name);
+ return 0;
}
#endif /* HAVE_BLOCK_DEVICE */
return -1;
}
-int get_device(const char *ifname, const char *dev_hwpart_str,
- block_dev_desc_t **dev_desc)
+int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,
+ struct blk_desc **dev_desc)
{
char *ep;
char *dup_str = NULL;
@@ -500,7 +432,7 @@ int get_device(const char *ifname, const char *dev_hwpart_str,
* already loaded.
*/
if(hwpart != 0)
- init_part(*dev_desc);
+ part_init(*dev_desc);
#endif
cleanup:
@@ -511,8 +443,8 @@ cleanup:
#define PART_UNSPECIFIED -2
#define PART_AUTO -1
#define MAX_SEARCH_PARTITIONS 16
-int get_device_and_partition(const char *ifname, const char *dev_part_str,
- block_dev_desc_t **dev_desc,
+int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
+ struct blk_desc **dev_desc,
disk_partition_t *info, int allow_whole_dev)
{
int ret = -1;
@@ -525,10 +457,6 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,
int part;
disk_partition_t tmpinfo;
-#if defined CONFIG_SANDBOX && defined CONFIG_CMD_UBIFS
-#error Only one of CONFIG_SANDBOX and CONFIG_CMD_UBIFS may be selected
-#endif
-
#ifdef CONFIG_SANDBOX
/*
* Special-case a pseudo block device "hostfs", to allow access to the
@@ -598,7 +526,7 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,
}
/* Look up the device */
- dev = get_device(ifname, dev_str, dev_desc);
+ dev = blk_get_device_by_str(ifname, dev_str, dev_desc);
if (dev < 0)
goto cleanup;
@@ -675,7 +603,7 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,
* other than "auto", use that partition number directly.
*/
if (part != PART_AUTO) {
- ret = get_partition_info(*dev_desc, part, info);
+ ret = part_get_info(*dev_desc, part, info);
if (ret) {
printf("** Invalid partition %d **\n", part);
goto cleanup;
@@ -687,7 +615,7 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,
*/
part = 0;
for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
- ret = get_partition_info(*dev_desc, p, info);
+ ret = part_get_info(*dev_desc, p, info);
if (ret)
continue;
diff --git a/disk/part_amiga.c b/disk/part_amiga.c
index 57c1b9d..d4316b8 100644
--- a/disk/part_amiga.c
+++ b/disk/part_amiga.c
@@ -126,7 +126,7 @@ static void print_part_info(struct partition_block *p)
* the ID AMIGA_ID_RDISK ('RDSK') and needs to have a valid
* sum-to-zero checksum
*/
-struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc)
+struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)
{
int i;
int limit;
@@ -140,7 +140,7 @@ struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc)
for (i=0; i<limit; i++)
{
- ulong res = dev_desc->block_read(dev_desc, i, 1, (ulong *)block_buffer);
+ ulong res = blk_dread(dev_desc, i, 1, (ulong *)block_buffer);
if (res == 1)
{
struct rigid_disk_block *trdb = (struct rigid_disk_block *)block_buffer;
@@ -166,7 +166,7 @@ struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc)
* Ridgid disk block
*/
-struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
+struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)
{
int i;
int limit;
@@ -182,7 +182,7 @@ struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
for (i = 0; i < limit; i++)
{
- ulong res = dev_desc->block_read(dev_desc, i, 1, (ulong *)block_buffer);
+ ulong res = blk_dread(dev_desc, i, 1, (ulong *)block_buffer);
if (res == 1)
{
struct bootcode_block *boot = (struct bootcode_block *)block_buffer;
@@ -207,27 +207,27 @@ struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
* Test if the given partition has an Amiga partition table/Rigid
* Disk block
*/
-int test_part_amiga(block_dev_desc_t *dev_desc)
+static int part_test_amiga(struct blk_desc *dev_desc)
{
struct rigid_disk_block *rdb;
struct bootcode_block *bootcode;
- PRINTF("test_part_amiga: Testing for an Amiga RDB partition\n");
+ PRINTF("part_test_amiga: Testing for an Amiga RDB partition\n");
rdb = get_rdisk(dev_desc);
if (rdb)
{
bootcode = get_bootcode(dev_desc);
if (bootcode)
- PRINTF("test_part_amiga: bootable Amiga disk\n");
+ PRINTF("part_test_amiga: bootable Amiga disk\n");
else
- PRINTF("test_part_amiga: non-bootable Amiga disk\n");
+ PRINTF("part_test_amiga: non-bootable Amiga disk\n");
return 0;
}
else
{
- PRINTF("test_part_amiga: no RDB found\n");
+ PRINTF("part_test_amiga: no RDB found\n");
return -1;
}
@@ -236,7 +236,8 @@ int test_part_amiga(block_dev_desc_t *dev_desc)
/*
* Find partition number partnum on the given drive.
*/
-static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int partnum)
+static struct partition_block *find_partition(struct blk_desc *dev_desc,
+ int partnum)
{
struct rigid_disk_block *rdb;
struct partition_block *p;
@@ -257,8 +258,7 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
while (block != 0xFFFFFFFF)
{
- ulong res = dev_desc->block_read(dev_desc, block, 1,
- (ulong *)block_buffer);
+ ulong res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer);
if (res == 1)
{
p = (struct partition_block *)block_buffer;
@@ -290,7 +290,8 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
/*
* Get info about a partition
*/
-int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
+static int part_get_info_amiga(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info)
{
struct partition_block *p = find_partition(dev_desc, part-1);
struct amiga_part_geometry *g;
@@ -302,7 +303,7 @@ int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partiti
info->start = g->low_cyl * g->block_per_track * g->surfaces;
info->size = (g->high_cyl - g->low_cyl + 1) * g->block_per_track * g->surfaces - 1;
info->blksz = rdb.block_bytes;
- bcpl_strcpy(info->name, p->drive_name);
+ bcpl_strcpy((char *)info->name, p->drive_name);
disk_type = g->dos_type;
@@ -317,7 +318,7 @@ int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partiti
return 0;
}
-void print_part_amiga (block_dev_desc_t *dev_desc)
+static void part_print_amiga(struct blk_desc *dev_desc)
{
struct rigid_disk_block *rdb;
struct bootcode_block *boot;
@@ -328,14 +329,14 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
rdb = get_rdisk(dev_desc);
if (!rdb)
{
- PRINTF("print_part_amiga: no rdb found\n");
+ PRINTF("part_print_amiga: no rdb found\n");
return;
}
- PRINTF("print_part_amiga: Scanning partition list\n");
+ PRINTF("part_print_amiga: Scanning partition list\n");
block = rdb->partition_list;
- PRINTF("print_part_amiga: partition list at 0x%x\n", block);
+ PRINTF("part_print_amiga: partition list at 0x%x\n", block);
printf("Summary: DiskBlockSize: %d\n"
" Cylinders : %d\n"
@@ -353,7 +354,7 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
PRINTF("Trying to load block #0x%X\n", block);
- res = dev_desc->block_read(dev_desc, block, 1, (ulong *)block_buffer);
+ res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer);
if (res == 1)
{
p = (struct partition_block *)block_buffer;
@@ -377,4 +378,12 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
}
}
+U_BOOT_PART_TYPE(amiga) = {
+ .name = "AMIGA",
+ .part_type = PART_TYPE_AMIGA,
+ .get_info = part_get_info_amiga,
+ .print = part_print_amiga,
+ .test = part_test_amiga,
+};
+
#endif
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 08872d6..511917a 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -87,11 +87,11 @@ static int test_block_type(unsigned char *buffer)
}
-int test_part_dos (block_dev_desc_t *dev_desc)
+static int part_test_dos(struct blk_desc *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
- if (dev_desc->block_read(dev_desc, 0, 1, (ulong *)buffer) != 1)
+ if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
return -1;
if (test_block_type(buffer) != DOS_MBR)
@@ -102,7 +102,7 @@ int test_part_dos (block_dev_desc_t *dev_desc)
/* Print a partition that is relative to its Extended partition table
*/
-static void print_partition_extended(block_dev_desc_t *dev_desc,
+static void print_partition_extended(struct blk_desc *dev_desc,
lbaint_t ext_part_sector,
lbaint_t relative,
int part_num, unsigned int disksig)
@@ -111,10 +111,9 @@ static void print_partition_extended(block_dev_desc_t *dev_desc,
dos_partition_t *pt;
int i;
- if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
- (ulong *)buffer) != 1) {
+ if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
- dev_desc->dev, ext_part_sector);
+ dev_desc->devnum, ext_part_sector);
return;
}
i=test_block_type(buffer);
@@ -167,21 +166,19 @@ static void print_partition_extended(block_dev_desc_t *dev_desc,
/* Print a partition that is relative to its Extended partition table
*/
-static int get_partition_info_extended (block_dev_desc_t *dev_desc,
- lbaint_t ext_part_sector,
- lbaint_t relative, int part_num,
- int which_part, disk_partition_t *info,
- unsigned int disksig)
+static int part_get_info_extended(struct blk_desc *dev_desc,
+ lbaint_t ext_part_sector, lbaint_t relative,
+ int part_num, int which_part,
+ disk_partition_t *info, unsigned int disksig)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
dos_partition_t *pt;
int i;
int dos_type;
- if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
- (ulong *)buffer) != 1) {
+ if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
- dev_desc->dev, ext_part_sector);
+ dev_desc->devnum, ext_part_sector);
return -1;
}
if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
@@ -216,24 +213,29 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
case IF_TYPE_IDE:
case IF_TYPE_SATA:
case IF_TYPE_ATAPI:
- sprintf ((char *)info->name, "hd%c%d",
- 'a' + dev_desc->dev, part_num);
+ sprintf((char *)info->name, "hd%c%d",
+ 'a' + dev_desc->devnum,
+ part_num);
break;
case IF_TYPE_SCSI:
- sprintf ((char *)info->name, "sd%c%d",
- 'a' + dev_desc->dev, part_num);
+ sprintf((char *)info->name, "sd%c%d",
+ 'a' + dev_desc->devnum,
+ part_num);
break;
case IF_TYPE_USB:
- sprintf ((char *)info->name, "usbd%c%d",
- 'a' + dev_desc->dev, part_num);
+ sprintf((char *)info->name, "usbd%c%d",
+ 'a' + dev_desc->devnum,
+ part_num);
break;
case IF_TYPE_DOC:
- sprintf ((char *)info->name, "docd%c%d",
- 'a' + dev_desc->dev, part_num);
+ sprintf((char *)info->name, "docd%c%d",
+ 'a' + dev_desc->devnum,
+ part_num);
break;
default:
- sprintf ((char *)info->name, "xx%c%d",
- 'a' + dev_desc->dev, part_num);
+ sprintf((char *)info->name, "xx%c%d",
+ 'a' + dev_desc->devnum,
+ part_num);
break;
}
/* sprintf(info->type, "%d, pt->sys_ind); */
@@ -259,7 +261,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
lbaint_t lba_start
= le32_to_int (pt->start4) + relative;
- return get_partition_info_extended (dev_desc, lba_start,
+ return part_get_info_extended(dev_desc, lba_start,
ext_part_sector == 0 ? lba_start : relative,
part_num, which_part, info, disksig);
}
@@ -283,16 +285,24 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
return -1;
}
-void print_part_dos (block_dev_desc_t *dev_desc)
+void part_print_dos(struct blk_desc *dev_desc)
{
printf("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n");
print_partition_extended(dev_desc, 0, 0, 1, 0);
}
-int get_partition_info_dos (block_dev_desc_t *dev_desc, int part, disk_partition_t * info)
+int part_get_info_dos(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info)
{
- return get_partition_info_extended(dev_desc, 0, 0, 1, part, info, 0);
+ return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0);
}
+U_BOOT_PART_TYPE(dos) = {
+ .name = "DOS",
+ .part_type = PART_TYPE_DOS,
+ .get_info = part_get_info_ptr(part_get_info_dos),
+ .print = part_print_ptr(part_print_dos),
+ .test = part_test_dos,
+};
#endif
diff --git a/disk/part_efi.c b/disk/part_efi.c
index e1b58c5..77bdfcb 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -41,10 +41,10 @@ static inline u32 efi_crc32(const void *buf, u32 len)
static int pmbr_part_valid(struct partition *part);
static int is_pmbr_valid(legacy_mbr * mbr);
-static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
+static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
gpt_header *pgpt_head, gpt_entry **pgpt_pte);
-static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
- gpt_header * pgpt_head);
+static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,
+ gpt_header *pgpt_head);
static int is_pte_valid(gpt_entry * pte);
static char *print_efiname(gpt_entry *pte)
@@ -176,7 +176,7 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
* Public Functions (include/part.h)
*/
-void print_part_efi(block_dev_desc_t * dev_desc)
+void part_print_efi(struct blk_desc *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
gpt_entry *gpt_pte = NULL;
@@ -237,8 +237,8 @@ void print_part_efi(block_dev_desc_t * dev_desc)
return;
}
-int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
- disk_partition_t * info)
+int part_get_info_efi(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info)
{
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
gpt_entry *gpt_pte = NULL;
@@ -300,13 +300,13 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
return 0;
}
-int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc,
+int part_get_info_efi_by_name(struct blk_desc *dev_desc,
const char *name, disk_partition_t *info)
{
int ret;
int i;
for (i = 1; i < GPT_ENTRY_NUMBERS; i++) {
- ret = get_partition_info_efi(dev_desc, i, info);
+ ret = part_get_info_efi(dev_desc, i, info);
if (ret != 0) {
/* no more entries in table */
return -1;
@@ -319,12 +319,12 @@ int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc,
return -2;
}
-int test_part_efi(block_dev_desc_t * dev_desc)
+static int part_test_efi(struct blk_desc *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
/* Read legacy MBR from block 0 and validate it */
- if ((dev_desc->block_read(dev_desc, 0, 1, (ulong *)legacymbr) != 1)
+ if ((blk_dread(dev_desc, 0, 1, (ulong *)legacymbr) != 1)
|| (is_pmbr_valid(legacymbr) != 1)) {
return -1;
}
@@ -337,7 +337,7 @@ int test_part_efi(block_dev_desc_t * dev_desc)
*
* @return - zero on success, otherwise error
*/
-static int set_protective_mbr(block_dev_desc_t *dev_desc)
+static int set_protective_mbr(struct blk_desc *dev_desc)
{
/* Setup the Protective MBR */
ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, p_mbr, 1);
@@ -354,16 +354,16 @@ static int set_protective_mbr(block_dev_desc_t *dev_desc)
p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1;
/* Write MBR sector to the MMC device */
- if (dev_desc->block_write(dev_desc, 0, 1, p_mbr) != 1) {
+ if (blk_dwrite(dev_desc, 0, 1, p_mbr) != 1) {
printf("** Can't write to device %d **\n",
- dev_desc->dev);
+ dev_desc->devnum);
return -1;
}
return 0;
}
-int write_gpt_table(block_dev_desc_t *dev_desc,
+int write_gpt_table(struct blk_desc *dev_desc,
gpt_header *gpt_h, gpt_entry *gpt_e)
{
const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries
@@ -386,31 +386,28 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
gpt_h->header_crc32 = cpu_to_le32(calc_crc32);
/* Write the First GPT to the block right after the Legacy MBR */
- if (dev_desc->block_write(dev_desc, 1, 1, gpt_h) != 1)
+ if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1)
goto err;
- if (dev_desc->block_write(dev_desc, 2, pte_blk_cnt, gpt_e)
+ if (blk_dwrite(dev_desc, 2, pte_blk_cnt, gpt_e)
!= pte_blk_cnt)
goto err;
prepare_backup_gpt_header(gpt_h);
- if (dev_desc->block_write(dev_desc,
- (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba)
- + 1,
- pte_blk_cnt, gpt_e) != pte_blk_cnt)
+ if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba)
+ + 1, pte_blk_cnt, gpt_e) != pte_blk_cnt)
goto err;
- if (dev_desc->block_write(dev_desc,
- (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1,
- gpt_h) != 1)
+ if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1,
+ gpt_h) != 1)
goto err;
debug("GPT successfully written to block device!\n");
return 0;
err:
- printf("** Can't write to device %d **\n", dev_desc->dev);
+ printf("** Can't write to device %d **\n", dev_desc->devnum);
return -1;
}
@@ -517,7 +514,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
return 0;
}
-int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
+int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,
char *str_guid, int parts_count)
{
gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE);
@@ -539,7 +536,7 @@ int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
return 0;
}
-int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
+int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,
disk_partition_t *partitions, int parts_count)
{
int ret;
@@ -595,7 +592,7 @@ static void gpt_convert_efi_name_to_char(char *s, efi_char16_t *es, int n)
}
}
-int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head,
+int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
gpt_entry **gpt_pte)
{
/*
@@ -619,7 +616,7 @@ int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head,
return 0;
}
-int gpt_verify_partitions(block_dev_desc_t *dev_desc,
+int gpt_verify_partitions(struct blk_desc *dev_desc,
disk_partition_t *partitions, int parts,
gpt_header *gpt_head, gpt_entry **gpt_pte)
{
@@ -658,11 +655,13 @@ int gpt_verify_partitions(block_dev_desc_t *dev_desc,
gpt_part_size = le64_to_cpu(gpt_e[i].ending_lba) -
le64_to_cpu(gpt_e[i].starting_lba) + 1;
debug("size(LBA) - GPT: %8llu, ENV: %8llu ",
- gpt_part_size, (u64) partitions[i].size);
+ (unsigned long long)gpt_part_size,
+ (unsigned long long)partitions[i].size);
if (le64_to_cpu(gpt_part_size) != partitions[i].size) {
error("Partition %s size: %llu does not match %llu!\n",
- efi_str, gpt_part_size, (u64) partitions[i].size);
+ efi_str, (unsigned long long)gpt_part_size,
+ (unsigned long long)partitions[i].size);
return -1;
}
@@ -678,12 +677,12 @@ int gpt_verify_partitions(block_dev_desc_t *dev_desc,
/* Check if GPT and ENV start LBAs match */
debug("start LBA - GPT: %8llu, ENV: %8llu\n",
le64_to_cpu(gpt_e[i].starting_lba),
- (u64) partitions[i].start);
+ (unsigned long long)partitions[i].start);
if (le64_to_cpu(gpt_e[i].starting_lba) != partitions[i].start) {
error("Partition %s start: %llu does not match %llu!\n",
efi_str, le64_to_cpu(gpt_e[i].starting_lba),
- (u64) partitions[i].start);
+ (unsigned long long)partitions[i].start);
return -1;
}
}
@@ -691,7 +690,7 @@ int gpt_verify_partitions(block_dev_desc_t *dev_desc,
return 0;
}
-int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf)
+int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf)
{
gpt_header *gpt_h;
gpt_entry *gpt_e;
@@ -712,7 +711,7 @@ int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf)
return 0;
}
-int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
+int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf)
{
gpt_header *gpt_h;
gpt_entry *gpt_e;
@@ -737,7 +736,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
/* write MBR */
lba = 0; /* MBR is always at 0 */
cnt = 1; /* MBR (1 block) */
- if (dev_desc->block_write(dev_desc, lba, cnt, buf) != cnt) {
+ if (blk_dwrite(dev_desc, lba, cnt, buf) != cnt) {
printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
__func__, "MBR", cnt, lba);
return 1;
@@ -746,7 +745,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
/* write Primary GPT */
lba = GPT_PRIMARY_PARTITION_TABLE_LBA;
cnt = 1; /* GPT Header (1 block) */
- if (dev_desc->block_write(dev_desc, lba, cnt, gpt_h) != cnt) {
+ if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) {
printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
__func__, "Primary GPT Header", cnt, lba);
return 1;
@@ -754,7 +753,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
lba = le64_to_cpu(gpt_h->partition_entry_lba);
cnt = gpt_e_blk_cnt;
- if (dev_desc->block_write(dev_desc, lba, cnt, gpt_e) != cnt) {
+ if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) {
printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
__func__, "Primary GPT Entries", cnt, lba);
return 1;
@@ -765,7 +764,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
/* write Backup GPT */
lba = le64_to_cpu(gpt_h->partition_entry_lba);
cnt = gpt_e_blk_cnt;
- if (dev_desc->block_write(dev_desc, lba, cnt, gpt_e) != cnt) {
+ if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) {
printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
__func__, "Backup GPT Entries", cnt, lba);
return 1;
@@ -773,7 +772,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf)
lba = le64_to_cpu(gpt_h->my_lba);
cnt = 1; /* GPT Header (1 block) */
- if (dev_desc->block_write(dev_desc, lba, cnt, gpt_h) != cnt) {
+ if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) {
printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
__func__, "Backup GPT Header", cnt, lba);
return 1;
@@ -834,7 +833,7 @@ static int is_pmbr_valid(legacy_mbr * mbr)
* Description: returns 1 if valid, 0 on error.
* If valid, returns pointers to PTEs.
*/
-static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
+static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
gpt_header *pgpt_head, gpt_entry **pgpt_pte)
{
if (!dev_desc || !pgpt_head) {
@@ -843,7 +842,7 @@ static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
}
/* Read GPT Header from device */
- if (dev_desc->block_read(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
+ if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
printf("*** ERROR: Can't read GPT header ***\n");
return 0;
}
@@ -876,8 +875,8 @@ static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
* Allocates space for PTEs based on information found in @gpt.
* Notes: remember to free pte when you're done!
*/
-static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
- gpt_header * pgpt_head)
+static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,
+ gpt_header *pgpt_head)
{
size_t count = 0, blk_cnt;
lbaint_t blk;
@@ -911,8 +910,7 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
/* Read GPT Entries from device */
blk = le64_to_cpu(pgpt_head->partition_entry_lba);
blk_cnt = BLOCK_CNT(count, dev_desc);
- if (dev_desc->block_read(dev_desc, blk, (lbaint_t)blk_cnt, pte)
- != blk_cnt) {
+ if (blk_dread(dev_desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) {
printf("*** ERROR: Can't read GPT Entries ***\n");
free(pte);
return NULL;
@@ -951,4 +949,17 @@ static int is_pte_valid(gpt_entry * pte)
return 1;
}
}
+
+/*
+ * Add an 'a_' prefix so it comes before 'dos' in the linker list. We need to
+ * check EFI first, since a DOS partition is often used as a 'protective MBR'
+ * with EFI.
+ */
+U_BOOT_PART_TYPE(a_efi) = {
+ .name = "EFI",
+ .part_type = PART_TYPE_EFI,
+ .get_info = part_get_info_ptr(part_get_info_efi),
+ .print = part_print_ptr(part_print_efi),
+ .test = part_test_efi,
+};
#endif
diff --git a/disk/part_iso.c b/disk/part_iso.c
index 5f4bb18..b83983b 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -46,7 +46,8 @@ static inline unsigned short le16_to_int(unsigned char *le16)
/* only boot records will be listed as valid partitions */
-int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info, int verb)
+int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
+ disk_partition_t *info, int verb)
{
int i,offset,entry_num;
unsigned short *chksumbuf;
@@ -62,18 +63,18 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
/* the first sector (sector 0x10) must be a primary volume desc */
blkaddr=PVD_OFFSET;
- if (dev_desc->block_read(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
+ if (blk_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
return -1;
if(ppr->desctype!=0x01) {
if(verb)
printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
- dev_desc->dev, part_num);
+ dev_desc->devnum, part_num);
return (-1);
}
if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
if(verb)
printf ("** Wrong ISO Ident: %s on %d:%d **\n",
- ppr->stand_ident,dev_desc->dev, part_num);
+ ppr->stand_ident, dev_desc->devnum, part_num);
return (-1);
}
lastsect= ((ppr->firstsek_LEpathtab1_LE & 0x000000ff)<<24) +
@@ -84,14 +85,14 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
PRINTF(" Lastsect:%08lx\n",lastsect);
for(i=blkaddr;i<lastsect;i++) {
PRINTF("Reading block %d\n", i);
- if (dev_desc->block_read(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
+ if (blk_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
return -1;
if(ppr->desctype==0x00)
break; /* boot entry found */
if(ppr->desctype==0xff) {
if(verb)
printf ("** No valid boot catalog found on %d:%d **\n",
- dev_desc->dev, part_num);
+ dev_desc->devnum, part_num);
return (-1);
}
}
@@ -99,15 +100,15 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
if(verb)
printf ("** Wrong El Torito ident: %s on %d:%d **\n",
- pbr->ident_str,dev_desc->dev, part_num);
+ pbr->ident_str, dev_desc->devnum, part_num);
return (-1);
}
bootaddr=le32_to_int(pbr->pointer);
PRINTF(" Boot Entry at: %08lX\n",bootaddr);
- if (dev_desc->block_read(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
+ if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
if(verb)
printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
- bootaddr,dev_desc->dev, part_num);
+ bootaddr, dev_desc->devnum, part_num);
return (-1);
}
chksum=0;
@@ -116,21 +117,21 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8);
if(chksum!=0) {
if(verb)
- printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n",
- dev_desc->dev, part_num);
+ printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
+ dev_desc->devnum, part_num);
return (-1);
}
if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
if(verb)
printf ("** Key 0x55 0xAA error on %d:%d **\n",
- dev_desc->dev, part_num);
+ dev_desc->devnum, part_num);
return(-1);
}
#ifdef CHECK_FOR_POWERPC_PLATTFORM
if(pve->platform!=0x01) {
if(verb)
printf ("** No PowerPC platform CD on %d:%d **\n",
- dev_desc->dev, part_num);
+ dev_desc->devnum, part_num);
return(-1);
}
#endif
@@ -143,23 +144,23 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
case IF_TYPE_SATA:
case IF_TYPE_ATAPI:
sprintf ((char *)info->name, "hd%c%d",
- 'a' + dev_desc->dev, part_num);
+ 'a' + dev_desc->devnum, part_num);
break;
case IF_TYPE_SCSI:
sprintf ((char *)info->name, "sd%c%d",
- 'a' + dev_desc->dev, part_num);
+ 'a' + dev_desc->devnum, part_num);
break;
case IF_TYPE_USB:
sprintf ((char *)info->name, "usbd%c%d",
- 'a' + dev_desc->dev, part_num);
+ 'a' + dev_desc->devnum, part_num);
break;
case IF_TYPE_DOC:
sprintf ((char *)info->name, "docd%c%d",
- 'a' + dev_desc->dev, part_num);
+ 'a' + dev_desc->devnum, part_num);
break;
default:
sprintf ((char *)info->name, "xx%c%d",
- 'a' + dev_desc->dev, part_num);
+ 'a' + dev_desc->devnum, part_num);
break;
}
/* the bootcatalog (including validation Entry) is limited to 2048Bytes
@@ -183,7 +184,7 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
else {
if(verb)
printf ("** Partition %d not found on device %d **\n",
- part_num,dev_desc->dev);
+ part_num, dev_desc->devnum);
return(-1);
}
}
@@ -191,13 +192,13 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
* searched w/o succsess */
if(verb)
printf ("** Partition %d not found on device %d **\n",
- part_num,dev_desc->dev);
+ part_num, dev_desc->devnum);
return(-1);
found:
if(pide->boot_ind!=0x88) {
if(verb)
- printf ("** Partition %d is not bootable on device %d **\n",
- part_num,dev_desc->dev);
+ printf("** Partition %d is not bootable on device %d **\n",
+ part_num, dev_desc->devnum);
return (-1);
}
switch(pide->boot_media) {
@@ -216,18 +217,20 @@ found:
return 0;
}
-int get_partition_info_iso(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info)
+static int part_get_info_iso(struct blk_desc *dev_desc, int part_num,
+ disk_partition_t *info)
{
- return(get_partition_info_iso_verb(dev_desc, part_num, info, 1));
+ return part_get_info_iso_verb(dev_desc, part_num, info, 1);
}
-
-void print_part_iso(block_dev_desc_t * dev_desc)
+static void part_print_iso(struct blk_desc *dev_desc)
{
disk_partition_t info;
int i;
- if(get_partition_info_iso_verb(dev_desc,0,&info,0)==-1) {
- printf("** No boot partition found on device %d **\n",dev_desc->dev);
+
+ if (part_get_info_iso_verb(dev_desc, 0, &info, 0) == -1) {
+ printf("** No boot partition found on device %d **\n",
+ dev_desc->devnum);
return;
}
printf("Part Start Sect x Size Type\n");
@@ -236,14 +239,21 @@ void print_part_iso(block_dev_desc_t * dev_desc)
printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n",
i, info.start, info.size, info.blksz, info.type);
i++;
- } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);
+ } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1);
}
-int test_part_iso (block_dev_desc_t *dev_desc)
+static int part_test_iso(struct blk_desc *dev_desc)
{
disk_partition_t info;
- return(get_partition_info_iso_verb(dev_desc,0,&info,0));
+ return part_get_info_iso_verb(dev_desc, 0, &info, 0);
}
+U_BOOT_PART_TYPE(iso) = {
+ .name = "ISO",
+ .part_type = PART_TYPE_ISO,
+ .get_info = part_get_info_iso,
+ .print = part_print_iso,
+ .test = part_test_iso,
+};
#endif
diff --git a/disk/part_mac.c b/disk/part_mac.c
index f3bc8dd..3952b8d 100644
--- a/disk/part_mac.c
+++ b/disk/part_mac.c
@@ -32,13 +32,15 @@ extern ldiv_t ldiv (long int __numer, long int __denom);
#endif
-static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p);
-static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p);
+static int part_mac_read_ddb(struct blk_desc *dev_desc,
+ mac_driver_desc_t *ddb_p);
+static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
+ mac_partition_t *pdb_p);
/*
* Test for a valid MAC partition
*/
-int test_part_mac (block_dev_desc_t *dev_desc)
+static int part_test_mac(struct blk_desc *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
@@ -51,8 +53,7 @@ int test_part_mac (block_dev_desc_t *dev_desc)
n = 1; /* assuming at least one partition */
for (i=1; i<=n; ++i) {
- if ((dev_desc->block_read(dev_desc, i, 1,
- (ulong *)mpart) != 1) ||
+ if ((blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) ||
(mpart->signature != MAC_PARTITION_MAGIC) ) {
return (-1);
}
@@ -62,8 +63,7 @@ int test_part_mac (block_dev_desc_t *dev_desc)
return (0);
}
-
-void print_part_mac (block_dev_desc_t *dev_desc)
+static void part_print_mac(struct blk_desc *dev_desc)
{
ulong i, n;
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
@@ -105,16 +105,16 @@ void print_part_mac (block_dev_desc_t *dev_desc)
char c;
printf ("%4ld: ", i);
- if (dev_desc->block_read(dev_desc, i, 1, (ulong *)mpart) != 1) {
+ if (blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) {
printf ("** Can't read Partition Map on %d:%ld **\n",
- dev_desc->dev, i);
+ dev_desc->devnum, i);
return;
}
if (mpart->signature != MAC_PARTITION_MAGIC) {
- printf ("** Bad Signature on %d:%ld - "
- "expected 0x%04x, got 0x%04x\n",
- dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart->signature);
+ printf("** Bad Signature on %d:%ld - expected 0x%04x, got 0x%04x\n",
+ dev_desc->devnum, i, MAC_PARTITION_MAGIC,
+ mpart->signature);
return;
}
@@ -149,9 +149,10 @@ void print_part_mac (block_dev_desc_t *dev_desc)
/*
* Read Device Descriptor Block
*/
-static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)
+static int part_mac_read_ddb(struct blk_desc *dev_desc,
+ mac_driver_desc_t *ddb_p)
{
- if (dev_desc->block_read(dev_desc, 0, 1, (ulong *)ddb_p) != 1) {
+ if (blk_dread(dev_desc, 0, 1, (ulong *)ddb_p) != 1) {
printf ("** Can't read Driver Desriptor Block **\n");
return (-1);
}
@@ -169,7 +170,8 @@ static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb
/*
* Read Partition Descriptor Block
*/
-static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p)
+static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
+ mac_partition_t *pdb_p)
{
int n = 1;
@@ -179,16 +181,16 @@ static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partitio
* partition 1 first since this is the only way to
* know how many partitions we have.
*/
- if (dev_desc->block_read(dev_desc, n, 1, (ulong *)pdb_p) != 1) {
+ if (blk_dread(dev_desc, n, 1, (ulong *)pdb_p) != 1) {
printf ("** Can't read Partition Map on %d:%d **\n",
- dev_desc->dev, n);
+ dev_desc->devnum, n);
return (-1);
}
if (pdb_p->signature != MAC_PARTITION_MAGIC) {
- printf ("** Bad Signature on %d:%d: "
- "expected 0x%04x, got 0x%04x\n",
- dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature);
+ printf("** Bad Signature on %d:%d: expected 0x%04x, got 0x%04x\n",
+ dev_desc->devnum, n, MAC_PARTITION_MAGIC,
+ pdb_p->signature);
return (-1);
}
@@ -197,9 +199,9 @@ static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partitio
if ((part < 1) || (part > pdb_p->map_count)) {
printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n",
- dev_desc->dev, part,
- dev_desc->dev,
- dev_desc->dev, pdb_p->map_count);
+ dev_desc->devnum, part,
+ dev_desc->devnum,
+ dev_desc->devnum, pdb_p->map_count);
return (-1);
}
@@ -210,7 +212,8 @@ static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partitio
/* NOTREACHED */
}
-int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
+static int part_get_info_mac(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info)
{
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
@@ -233,4 +236,11 @@ int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition
return (0);
}
+U_BOOT_PART_TYPE(mac) = {
+ .name = "MAC",
+ .part_type = PART_TYPE_MAC,
+ .get_info = part_get_info_mac,
+ .print = part_print_mac,
+ .test = part_test_mac,
+};
#endif
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 990f768..f35c4d4 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -1,3 +1,14 @@
+config BLK
+ bool "Support block devices"
+ depends on DM
+ help
+ Enable support for block devices, such as SCSI, MMC and USB
+ flash sticks. These provide a block-level interface which permits
+ reading, writing and (in some cases) erasing blocks. Block
+ devices often have a partition table which allows the device to
+ be partitioned into several areas, called 'partitions' in U-Boot.
+ A filesystem can be placed in each partition.
+
config DISK
bool "Support disk controllers with driver model"
depends on DM
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 5eb87e0..b5c7ae1 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -5,6 +5,8 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_BLK) += blk-uclass.o
+
obj-$(CONFIG_DISK) += disk-uclass.o
obj-$(CONFIG_SCSI_AHCI) += ahci.o
obj-$(CONFIG_DWC_AHSATA) += dwc_ahsata.o
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
new file mode 100644
index 0000000..49df2a6
--- /dev/null
+++ b/drivers/block/blk-uclass.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <blk.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
+
+int blk_first_device(int if_type, struct udevice **devp)
+{
+ struct blk_desc *desc;
+ int ret;
+
+ ret = uclass_first_device(UCLASS_BLK, devp);
+ if (ret)
+ return ret;
+ if (!*devp)
+ return -ENODEV;
+ do {
+ desc = dev_get_uclass_platdata(*devp);
+ if (desc->if_type == if_type)
+ return 0;
+ ret = uclass_next_device(devp);
+ if (ret)
+ return ret;
+ } while (*devp);
+
+ return -ENODEV;
+}
+
+int blk_next_device(struct udevice **devp)
+{
+ struct blk_desc *desc;
+ int ret, if_type;
+
+ desc = dev_get_uclass_platdata(*devp);
+ if_type = desc->if_type;
+ do {
+ ret = uclass_next_device(devp);
+ if (ret)
+ return ret;
+ if (!*devp)
+ return -ENODEV;
+ desc = dev_get_uclass_platdata(*devp);
+ if (desc->if_type == if_type)
+ return 0;
+ } while (1);
+}
+
+int blk_get_device(int if_type, int devnum, struct udevice **devp)
+{
+ struct uclass *uc;
+ struct udevice *dev;
+ int ret;
+
+ ret = uclass_get(UCLASS_BLK, &uc);
+ if (ret)
+ return ret;
+ uclass_foreach_dev(dev, uc) {
+ struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+ debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
+ if_type, devnum, dev->name, desc->if_type, desc->devnum);
+ if (desc->if_type == if_type && desc->devnum == devnum) {
+ *devp = dev;
+ return device_probe(dev);
+ }
+ }
+
+ return -ENODEV;
+}
+
+unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, void *buffer)
+{
+ struct udevice *dev = block_dev->bdev;
+ const struct blk_ops *ops = blk_get_ops(dev);
+
+ if (!ops->read)
+ return -ENOSYS;
+
+ return ops->read(dev, start, blkcnt, buffer);
+}
+
+unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, const void *buffer)
+{
+ struct udevice *dev = block_dev->bdev;
+ const struct blk_ops *ops = blk_get_ops(dev);
+
+ if (!ops->write)
+ return -ENOSYS;
+
+ return ops->write(dev, start, blkcnt, buffer);
+}
+
+unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt)
+{
+ struct udevice *dev = block_dev->bdev;
+ const struct blk_ops *ops = blk_get_ops(dev);
+
+ if (!ops->erase)
+ return -ENOSYS;
+
+ return ops->erase(dev, start, blkcnt);
+}
+
+int blk_prepare_device(struct udevice *dev)
+{
+ struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+ part_init(desc);
+
+ return 0;
+}
+
+int blk_create_device(struct udevice *parent, const char *drv_name,
+ const char *name, int if_type, int devnum, int blksz,
+ lbaint_t size, struct udevice **devp)
+{
+ struct blk_desc *desc;
+ struct udevice *dev;
+ int ret;
+
+ ret = device_bind_driver(parent, drv_name, name, &dev);
+ if (ret)
+ return ret;
+ desc = dev_get_uclass_platdata(dev);
+ desc->if_type = if_type;
+ desc->blksz = blksz;
+ desc->lba = size / blksz;
+ desc->part_type = PART_TYPE_UNKNOWN;
+ desc->bdev = dev;
+ desc->devnum = devnum;
+ *devp = dev;
+
+ return 0;
+}
+
+int blk_unbind_all(int if_type)
+{
+ struct uclass *uc;
+ struct udevice *dev, *next;
+ int ret;
+
+ ret = uclass_get(UCLASS_BLK, &uc);
+ if (ret)
+ return ret;
+ uclass_foreach_dev_safe(dev, next, uc) {
+ struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+ if (desc->if_type == if_type) {
+ ret = device_remove(dev);
+ if (ret)
+ return ret;
+ ret = device_unbind(dev);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+UCLASS_DRIVER(blk) = {
+ .id = UCLASS_BLK,
+ .name = "blk",
+ .per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
+};
diff --git a/drivers/block/dwc_ahsata.c b/drivers/block/dwc_ahsata.c
index bc072f3..6ec52a9 100644
--- a/drivers/block/dwc_ahsata.c
+++ b/drivers/block/dwc_ahsata.c
@@ -620,7 +620,7 @@ int reset_sata(int dev)
static void dwc_ahsata_print_info(int dev)
{
- block_dev_desc_t *pdev = &(sata_dev_desc[dev]);
+ struct blk_desc *pdev = &(sata_dev_desc[dev]);
printf("SATA Device Info:\n\r");
#ifdef CONFIG_SYS_64BIT_LBA
@@ -956,7 +956,7 @@ int scan_sata(int dev)
struct ahci_probe_ent *probe_ent =
(struct ahci_probe_ent *)sata_dev_desc[dev].priv;
u8 port = probe_ent->hard_port_no;
- block_dev_desc_t *pdev = &(sata_dev_desc[dev]);
+ struct blk_desc *pdev = &(sata_dev_desc[dev]);
id = (u16 *)memalign(ARCH_DMA_MINALIGN,
roundup(ARCH_DMA_MINALIGN,
diff --git a/drivers/block/pata_bfin.c b/drivers/block/pata_bfin.c
index c2673bd..26569d7 100644
--- a/drivers/block/pata_bfin.c
+++ b/drivers/block/pata_bfin.c
@@ -965,7 +965,7 @@ int scan_sata(int dev)
/* Probe device and set xfer mode */
bfin_ata_identify(ap, dev%PATA_DEV_NUM_PER_PORT);
bfin_ata_set_Feature_cmd(ap, dev%PATA_DEV_NUM_PER_PORT);
- init_part(&sata_dev_desc[dev]);
+ part_init(&sata_dev_desc[dev]);
return 0;
}
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 170f0fa..6d41508 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -4,14 +4,20 @@
* SPDX-License-Identifier: GPL-2.0+
*/
-#include <config.h>
#include <common.h>
+#include <blk.h>
+#include <dm.h>
+#include <fdtdec.h>
#include <part.h>
#include <os.h>
#include <malloc.h>
#include <sandboxblockdev.h>
#include <asm/errno.h>
+#include <dm/device-internal.h>
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifndef CONFIG_BLK
static struct host_block_dev host_devices[CONFIG_HOST_MAX_DEVICES];
static struct host_block_dev *find_host_device(int dev)
@@ -21,48 +27,130 @@ static struct host_block_dev *find_host_device(int dev)
return NULL;
}
+#endif
-static unsigned long host_block_read(block_dev_desc_t *block_dev,
+#ifdef CONFIG_BLK
+static unsigned long host_block_read(struct udevice *dev,
unsigned long start, lbaint_t blkcnt,
void *buffer)
{
- int dev = block_dev->dev;
+ struct host_block_dev *host_dev = dev_get_priv(dev);
+ struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
+
+#else
+static unsigned long host_block_read(struct blk_desc *block_dev,
+ unsigned long start, lbaint_t blkcnt,
+ void *buffer)
+{
+ int dev = block_dev->devnum;
struct host_block_dev *host_dev = find_host_device(dev);
if (!host_dev)
return -1;
- if (os_lseek(host_dev->fd,
- start * host_dev->blk_dev.blksz,
- OS_SEEK_SET) == -1) {
- printf("ERROR: Invalid position\n");
+#endif
+
+ if (os_lseek(host_dev->fd, start * block_dev->blksz, OS_SEEK_SET) ==
+ -1) {
+ printf("ERROR: Invalid block %lx\n", start);
return -1;
}
- ssize_t len = os_read(host_dev->fd, buffer,
- blkcnt * host_dev->blk_dev.blksz);
+ ssize_t len = os_read(host_dev->fd, buffer, blkcnt * block_dev->blksz);
if (len >= 0)
- return len / host_dev->blk_dev.blksz;
+ return len / block_dev->blksz;
return -1;
}
-static unsigned long host_block_write(block_dev_desc_t *block_dev,
+#ifdef CONFIG_BLK
+static unsigned long host_block_write(struct udevice *dev,
unsigned long start, lbaint_t blkcnt,
const void *buffer)
{
- int dev = block_dev->dev;
+ struct host_block_dev *host_dev = dev_get_priv(dev);
+ struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
+#else
+static unsigned long host_block_write(struct blk_desc *block_dev,
+ unsigned long start, lbaint_t blkcnt,
+ const void *buffer)
+{
+ int dev = block_dev->devnum;
struct host_block_dev *host_dev = find_host_device(dev);
- if (os_lseek(host_dev->fd,
- start * host_dev->blk_dev.blksz,
- OS_SEEK_SET) == -1) {
- printf("ERROR: Invalid position\n");
+#endif
+
+ if (os_lseek(host_dev->fd, start * block_dev->blksz, OS_SEEK_SET) ==
+ -1) {
+ printf("ERROR: Invalid block %lx\n", start);
return -1;
}
- ssize_t len = os_write(host_dev->fd, buffer, blkcnt *
- host_dev->blk_dev.blksz);
+ ssize_t len = os_write(host_dev->fd, buffer, blkcnt * block_dev->blksz);
if (len >= 0)
- return len / host_dev->blk_dev.blksz;
+ return len / block_dev->blksz;
return -1;
}
+#ifdef CONFIG_BLK
+int host_dev_bind(int devnum, char *filename)
+{
+ struct host_block_dev *host_dev;
+ struct udevice *dev;
+ char dev_name[20], *str, *fname;
+ int ret, fd;
+
+ /* Remove and unbind the old device, if any */
+ ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ if (ret == 0) {
+ ret = device_remove(dev);
+ if (ret)
+ return ret;
+ ret = device_unbind(dev);
+ if (ret)
+ return ret;
+ } else if (ret != -ENODEV) {
+ return ret;
+ }
+
+ if (!filename)
+ return 0;
+
+ snprintf(dev_name, sizeof(dev_name), "host%d", devnum);
+ str = strdup(dev_name);
+ if (!str)
+ return -ENOMEM;
+ fname = strdup(filename);
+ if (!fname) {
+ free(str);
+ return -ENOMEM;
+ }
+
+ fd = os_open(filename, OS_O_RDWR);
+ if (fd == -1) {
+ printf("Failed to access host backing file '%s'\n", filename);
+ ret = -ENOENT;
+ goto err;
+ }
+ ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str,
+ IF_TYPE_HOST, devnum, 512,
+ os_lseek(fd, 0, OS_SEEK_END), &dev);
+ if (ret)
+ goto err_file;
+ ret = device_probe(dev);
+ if (ret) {
+ device_unbind(dev);
+ goto err_file;
+ }
+
+ host_dev = dev_get_priv(dev);
+ host_dev->fd = fd;
+ host_dev->filename = fname;
+
+ return blk_prepare_device(dev);
+err_file:
+ os_close(fd);
+err:
+ free(fname);
+ free(str);
+ return ret;
+}
+#else
int host_dev_bind(int dev, char *filename)
{
struct host_block_dev *host_dev = find_host_device(dev);
@@ -89,23 +177,33 @@ int host_dev_bind(int dev, char *filename)
return 1;
}
- block_dev_desc_t *blk_dev = &host_dev->blk_dev;
+ struct blk_desc *blk_dev = &host_dev->blk_dev;
blk_dev->if_type = IF_TYPE_HOST;
blk_dev->priv = host_dev;
blk_dev->blksz = 512;
blk_dev->lba = os_lseek(host_dev->fd, 0, OS_SEEK_END) / blk_dev->blksz;
blk_dev->block_read = host_block_read;
blk_dev->block_write = host_block_write;
- blk_dev->dev = dev;
+ blk_dev->devnum = dev;
blk_dev->part_type = PART_TYPE_UNKNOWN;
- init_part(blk_dev);
+ part_init(blk_dev);
return 0;
}
+#endif
-int host_get_dev_err(int dev, block_dev_desc_t **blk_devp)
+int host_get_dev_err(int devnum, struct blk_desc **blk_devp)
{
- struct host_block_dev *host_dev = find_host_device(dev);
+#ifdef CONFIG_BLK
+ struct udevice *dev;
+ int ret;
+
+ ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ if (ret)
+ return ret;
+ *blk_devp = dev_get_uclass_platdata(dev);
+#else
+ struct host_block_dev *host_dev = find_host_device(devnum);
if (!host_dev)
return -ENODEV;
@@ -114,15 +212,31 @@ int host_get_dev_err(int dev, block_dev_desc_t **blk_devp)
return -ENOENT;
*blk_devp = &host_dev->blk_dev;
+#endif
+
return 0;
}
-block_dev_desc_t *host_get_dev(int dev)
+struct blk_desc *host_get_dev(int dev)
{
- block_dev_desc_t *blk_dev;
+ struct blk_desc *blk_dev;
if (host_get_dev_err(dev, &blk_dev))
return NULL;
return blk_dev;
}
+
+#ifdef CONFIG_BLK
+static const struct blk_ops sandbox_host_blk_ops = {
+ .read = host_block_read,
+ .write = host_block_write,
+};
+
+U_BOOT_DRIVER(sandbox_host_blk) = {
+ .name = "sandbox_host_blk",
+ .id = UCLASS_BLK,
+ .ops = &sandbox_host_blk_ops,
+ .priv_auto_alloc_size = sizeof(struct host_block_dev),
+};
+#endif
diff --git a/drivers/block/systemace.c b/drivers/block/systemace.c
index b974e80..09fe834 100644
--- a/drivers/block/systemace.c
+++ b/drivers/block/systemace.c
@@ -69,11 +69,11 @@ static u16 ace_readw(unsigned off)
return in16(base + off);
}
-static unsigned long systemace_read(block_dev_desc_t *block_dev,
+static unsigned long systemace_read(struct blk_desc *block_dev,
unsigned long start, lbaint_t blkcnt,
void *buffer);
-static block_dev_desc_t systemace_dev = { 0 };
+static struct blk_desc systemace_dev = { 0 };
static int get_cf_lock(void)
{
@@ -105,13 +105,13 @@ static void release_cf_lock(void)
}
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *systemace_get_dev(int dev)
+struct blk_desc *systemace_get_dev(int dev)
{
/* The first time through this, the systemace_dev object is
not yet initialized. In that case, fill it in. */
if (systemace_dev.blksz == 0) {
systemace_dev.if_type = IF_TYPE_UNKNOWN;
- systemace_dev.dev = 0;
+ systemace_dev.devnum = 0;
systemace_dev.part_type = PART_TYPE_UNKNOWN;
systemace_dev.type = DEV_TYPE_HARDDISK;
systemace_dev.blksz = 512;
@@ -124,7 +124,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
*/
ace_writew(width == 8 ? 0 : 0x0001, 0);
- init_part(&systemace_dev);
+ part_init(&systemace_dev);
}
@@ -137,7 +137,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
* the dev_desc) to read blocks of data. The return value is the
* number of blocks read. A zero return indicates an error.
*/
-static unsigned long systemace_read(block_dev_desc_t *block_dev,
+static unsigned long systemace_read(struct blk_desc *block_dev,
unsigned long start, lbaint_t blkcnt,
void *buffer)
{
diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c
index 913c3cc..1a9c864 100644
--- a/drivers/core/simple-bus.c
+++ b/drivers/core/simple-bus.c
@@ -53,6 +53,7 @@ UCLASS_DRIVER(simple_bus) = {
static const struct udevice_id generic_simple_bus_ids[] = {
{ .compatible = "simple-bus" },
+ { .compatible = "simple-mfd" },
{ }
};
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 12095e7..1141ce1 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -401,6 +401,19 @@ int uclass_first_device(enum uclass_id id, struct udevice **devp)
return uclass_get_device_tail(dev, ret, devp);
}
+int uclass_first_device_err(enum uclass_id id, struct udevice **devp)
+{
+ int ret;
+
+ ret = uclass_first_device(id, devp);
+ if (ret)
+ return ret;
+ else if (!*devp)
+ return -ENODEV;
+
+ return 0;
+}
+
int uclass_next_device(struct udevice **devp)
{
struct udevice *dev = *devp;
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 395d472..faece88 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -351,11 +351,11 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
} else if (!strcmp(entity_type, "part")) {
disk_partition_t partinfo;
- block_dev_desc_t *blk_dev = &mmc->block_dev;
+ struct blk_desc *blk_dev = &mmc->block_dev;
int mmcdev = second_arg;
int mmcpart = third_arg;
- if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) {
+ if (part_get_info(blk_dev, mmcpart, &partinfo) != 0) {
error("Couldn't find part #%d on mmc device #%d\n",
mmcpart, mmcdev);
return -ENODEV;
diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index c62f025..40e87bd 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -116,11 +116,9 @@ static int rockchip_gpio_probe(struct udevice *dev)
/* This only supports RK3288 at present */
priv->regs = (struct rockchip_gpio_regs *)dev_get_addr(dev);
- ret = uclass_first_device(UCLASS_PINCTRL, &priv->pinctrl);
+ ret = uclass_first_device_err(UCLASS_PINCTRL, &priv->pinctrl);
if (ret)
return ret;
- if (!priv->pinctrl)
- return -ENODEV;
uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
end = strrchr(dev->name, '@');
diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c
index 2d0fa2a..ed6d462 100644
--- a/drivers/misc/altera_sysid.c
+++ b/drivers/misc/altera_sysid.c
@@ -32,11 +32,9 @@ void display_sysid(void)
int ret;
/* the first misc device will be used */
- ret = uclass_first_device(UCLASS_MISC, &dev);
+ ret = uclass_first_device_err(UCLASS_MISC, &dev);
if (ret)
return;
- if (!dev)
- return;
ret = misc_read(dev, 0, &sysid, sizeof(sysid));
if (ret)
return;
diff --git a/drivers/mmc/arm_pl180_mmci.c b/drivers/mmc/arm_pl180_mmci.c
index 5ef7ff7..8f2694f 100644
--- a/drivers/mmc/arm_pl180_mmci.c
+++ b/drivers/mmc/arm_pl180_mmci.c
@@ -375,7 +375,7 @@ int arm_pl180_mmci_init(struct pl180_mmc_host *host)
if (mmc == NULL)
return -1;
- debug("registered mmc interface number is:%d\n", mmc->block_dev.dev);
+ debug("registered mmc interface number is:%d\n", mmc->block_dev.devnum);
return 0;
}
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index ede5d6e..8b2e606 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -182,7 +182,7 @@ struct mmc *find_mmc_device(int dev_num)
list_for_each(entry, &mmc_devices) {
m = list_entry(entry, struct mmc, link);
- if (m->block_dev.dev == dev_num)
+ if (m->block_dev.devnum == dev_num)
return m;
}
@@ -234,10 +234,10 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
return blkcnt;
}
-static ulong mmc_bread(block_dev_desc_t *block_dev, lbaint_t start,
+static ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *dst)
{
- int dev_num = block_dev->dev;
+ int dev_num = block_dev->devnum;
int err;
lbaint_t cur, blocks_todo = blkcnt;
@@ -1495,7 +1495,7 @@ static int mmc_startup(struct mmc *mmc)
mmc->block_dev.revision[0] = 0;
#endif
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
- init_part(&mmc->block_dev);
+ part_init(&mmc->block_dev);
#endif
return 0;
@@ -1556,7 +1556,7 @@ struct mmc *mmc_create(const struct mmc_config *cfg, void *priv)
mmc->dsr = 0xffffffff;
/* Setup the universal parts of the block interface just once */
mmc->block_dev.if_type = IF_TYPE_MMC;
- mmc->block_dev.dev = cur_dev_num++;
+ mmc->block_dev.devnum = cur_dev_num++;
mmc->block_dev.removable = 1;
mmc->block_dev.block_read = mmc_bread;
mmc->block_dev.block_write = mmc_bwrite;
@@ -1579,7 +1579,7 @@ void mmc_destroy(struct mmc *mmc)
}
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *mmc_get_dev(int dev)
+struct blk_desc *mmc_get_dev(int dev)
{
struct mmc *mmc = find_mmc_device(dev);
if (!mmc || mmc_init(mmc))
@@ -1728,7 +1728,7 @@ void print_mmc_devices(char separator)
else
mmc_type = NULL;
- printf("%s: %d", m->cfg->name, m->block_dev.dev);
+ printf("%s: %d", m->cfg->name, m->block_dev.devnum);
if (mmc_type)
printf(" (%s)", mmc_type);
diff --git a/drivers/mmc/mmc_private.h b/drivers/mmc/mmc_private.h
index 6a70639..d3f6bfe 100644
--- a/drivers/mmc/mmc_private.h
+++ b/drivers/mmc/mmc_private.h
@@ -22,23 +22,23 @@ void mmc_adapter_card_type_ident(void);
#ifndef CONFIG_SPL_BUILD
-unsigned long mmc_berase(block_dev_desc_t *block_dev, lbaint_t start,
+unsigned long mmc_berase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
-unsigned long mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+unsigned long mmc_bwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *src);
#else /* CONFIG_SPL_BUILD */
/* SPL will never write or erase, declare dummies to reduce code size. */
-static inline unsigned long mmc_berase(block_dev_desc_t *block_dev,
+static inline unsigned long mmc_berase(struct blk_desc *block_dev,
lbaint_t start, lbaint_t blkcnt)
{
return 0;
}
-static inline ulong mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+static inline ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *src)
{
return 0;
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index 79b8c4d..7b186f8 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -65,10 +65,10 @@ err_out:
return err;
}
-unsigned long mmc_berase(block_dev_desc_t *block_dev, lbaint_t start,
+unsigned long mmc_berase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt)
{
- int dev_num = block_dev->dev;
+ int dev_num = block_dev->devnum;
int err = 0;
u32 start_rem, blkcnt_rem;
struct mmc *mmc = find_mmc_device(dev_num);
@@ -171,10 +171,10 @@ static ulong mmc_write_blocks(struct mmc *mmc, lbaint_t start,
return blkcnt;
}
-ulong mmc_bwrite(block_dev_desc_t *block_dev, lbaint_t start, lbaint_t blkcnt,
+ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
const void *src)
{
- int dev_num = block_dev->dev;
+ int dev_num = block_dev->devnum;
lbaint_t cur, blocks_todo = blkcnt;
int err;
diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c
index 31fb3ab..9fa87d5 100644
--- a/drivers/mmc/mxsmmc.c
+++ b/drivers/mmc/mxsmmc.c
@@ -142,7 +142,7 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
uint32_t ctrl0;
int ret;
- debug("MMC%d: CMD%d\n", mmc->block_dev.dev, cmd->cmdidx);
+ debug("MMC%d: CMD%d\n", mmc->block_dev.devnum, cmd->cmdidx);
/* Check bus busy */
timeout = MXSMMC_MAX_TIMEOUT;
@@ -157,13 +157,13 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
}
if (!timeout) {
- printf("MMC%d: Bus busy timeout!\n", mmc->block_dev.dev);
+ printf("MMC%d: Bus busy timeout!\n", mmc->block_dev.devnum);
return TIMEOUT;
}
/* See if card is present */
if (!mxsmmc_cd(priv)) {
- printf("MMC%d: No card detected!\n", mmc->block_dev.dev);
+ printf("MMC%d: No card detected!\n", mmc->block_dev.devnum);
return NO_CARD_ERR;
}
@@ -200,9 +200,9 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
if (data->flags & MMC_DATA_READ) {
ctrl0 |= SSP_CTRL0_READ;
} else if (priv->mmc_is_wp &&
- priv->mmc_is_wp(mmc->block_dev.dev)) {
+ priv->mmc_is_wp(mmc->block_dev.devnum)) {
printf("MMC%d: Can not write a locked card!\n",
- mmc->block_dev.dev);
+ mmc->block_dev.devnum);
return UNUSABLE_ERR;
}
@@ -243,21 +243,21 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
if (!timeout) {
printf("MMC%d: Command %d busy\n",
- mmc->block_dev.dev, cmd->cmdidx);
+ mmc->block_dev.devnum, cmd->cmdidx);
return TIMEOUT;
}
/* Check command timeout */
if (reg & SSP_STATUS_RESP_TIMEOUT) {
printf("MMC%d: Command %d timeout (status 0x%08x)\n",
- mmc->block_dev.dev, cmd->cmdidx, reg);
+ mmc->block_dev.devnum, cmd->cmdidx, reg);
return TIMEOUT;
}
/* Check command errors */
if (reg & (SSP_STATUS_RESP_CRC_ERR | SSP_STATUS_RESP_ERR)) {
printf("MMC%d: Command %d error (status 0x%08x)!\n",
- mmc->block_dev.dev, cmd->cmdidx, reg);
+ mmc->block_dev.devnum, cmd->cmdidx, reg);
return COMM_ERR;
}
@@ -279,14 +279,14 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
if (ret) {
printf("MMC%d: Data timeout with command %d "
"(status 0x%08x)!\n",
- mmc->block_dev.dev, cmd->cmdidx, reg);
+ mmc->block_dev.devnum, cmd->cmdidx, reg);
return ret;
}
} else {
ret = mxsmmc_send_cmd_dma(priv, data);
if (ret) {
printf("MMC%d: DMA transfer failed\n",
- mmc->block_dev.dev);
+ mmc->block_dev.devnum);
return ret;
}
}
@@ -297,7 +297,7 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
(SSP_STATUS_TIMEOUT | SSP_STATUS_DATA_CRC_ERR |
SSP_STATUS_FIFO_OVRFLW | SSP_STATUS_FIFO_UNDRFLW)) {
printf("MMC%d: Data error with command %d (status 0x%08x)!\n",
- mmc->block_dev.dev, cmd->cmdidx, reg);
+ mmc->block_dev.devnum, cmd->cmdidx, reg);
return COMM_ERR;
}
@@ -330,7 +330,7 @@ static void mxsmmc_set_ios(struct mmc *mmc)
SSP_CTRL0_BUS_WIDTH_MASK, priv->buswidth);
debug("MMC%d: Set %d bits bus width\n",
- mmc->block_dev.dev, mmc->bus_width);
+ mmc->block_dev.devnum, mmc->bus_width);
}
static int mxsmmc_init(struct mmc *mmc)
diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c
index 5038a9f..5f2db3b 100644
--- a/drivers/mmc/omap_hsmmc.c
+++ b/drivers/mmc/omap_hsmmc.c
@@ -177,11 +177,11 @@ static unsigned char mmc_board_init(struct mmc *mmc)
#if defined(CONFIG_OMAP44XX) && defined(CONFIG_TWL6030_POWER)
/* PBIAS config needed for MMC1 only */
- if (mmc->block_dev.dev == 0)
+ if (mmc->block_dev.devnum == 0)
omap4_vmmc_pbias_config(mmc);
#endif
#if defined(CONFIG_OMAP54XX) && defined(CONFIG_PALMAS_POWER)
- if (mmc->block_dev.dev == 0)
+ if (mmc->block_dev.devnum == 0)
omap5_pbias_config(mmc);
#endif
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 8586d89..ef7e615 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -137,7 +137,7 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
int trans_bytes = 0, is_aligned = 1;
u32 mask, flags, mode;
unsigned int time = 0, start_addr = 0;
- int mmc_dev = mmc->block_dev.dev;
+ int mmc_dev = mmc->block_dev.devnum;
unsigned start = get_timer(0);
/* Timeout unit - ms */
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index d01bfc1..519052e 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -30,11 +30,9 @@ int pci_get_bus(int busnum, struct udevice **busp)
/* Since buses may not be numbered yet try a little harder with bus 0 */
if (ret == -ENODEV) {
- ret = uclass_first_device(UCLASS_PCI, busp);
+ ret = uclass_first_device_err(UCLASS_PCI, busp);
if (ret)
return ret;
- else if (!*busp)
- return -ENODEV;
ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp);
}
diff --git a/drivers/pci/pci_auto_common.c b/drivers/pci/pci_auto_common.c
index 85c419e..677f094 100644
--- a/drivers/pci/pci_auto_common.c
+++ b/drivers/pci/pci_auto_common.c
@@ -62,6 +62,17 @@ int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
return -1;
}
+static void pciauto_show_region(const char *name, struct pci_region *region)
+{
+ pciauto_region_init(region);
+ debug("PCI Autoconfig: Bus %s region: [%llx-%llx],\n"
+ "\t\tPhysical Memory [%llx-%llxx]\n", name,
+ (unsigned long long)region->bus_start,
+ (unsigned long long)(region->bus_start + region->size - 1),
+ (unsigned long long)region->phys_start,
+ (unsigned long long)(region->phys_start + region->size - 1));
+}
+
void pciauto_config_init(struct pci_controller *hose)
{
int i;
@@ -91,38 +102,10 @@ void pciauto_config_init(struct pci_controller *hose)
}
- if (hose->pci_mem) {
- pciauto_region_init(hose->pci_mem);
-
- debug("PCI Autoconfig: Bus Memory region: [0x%llx-0x%llx],\n"
- "\t\tPhysical Memory [%llx-%llxx]\n",
- (u64)hose->pci_mem->bus_start,
- (u64)(hose->pci_mem->bus_start + hose->pci_mem->size - 1),
- (u64)hose->pci_mem->phys_start,
- (u64)(hose->pci_mem->phys_start + hose->pci_mem->size - 1));
- }
-
- if (hose->pci_prefetch) {
- pciauto_region_init(hose->pci_prefetch);
-
- debug("PCI Autoconfig: Bus Prefetchable Mem: [0x%llx-0x%llx],\n"
- "\t\tPhysical Memory [%llx-%llx]\n",
- (u64)hose->pci_prefetch->bus_start,
- (u64)(hose->pci_prefetch->bus_start +
- hose->pci_prefetch->size - 1),
- (u64)hose->pci_prefetch->phys_start,
- (u64)(hose->pci_prefetch->phys_start +
- hose->pci_prefetch->size - 1));
- }
-
- if (hose->pci_io) {
- pciauto_region_init(hose->pci_io);
-
- debug("PCI Autoconfig: Bus I/O region: [0x%llx-0x%llx],\n"
- "\t\tPhysical Memory: [%llx-%llx]\n",
- (u64)hose->pci_io->bus_start,
- (u64)(hose->pci_io->bus_start + hose->pci_io->size - 1),
- (u64)hose->pci_io->phys_start,
- (u64)(hose->pci_io->phys_start + hose->pci_io->size - 1));
- }
+ if (hose->pci_mem)
+ pciauto_show_region("Memory", hose->pci_mem);
+ if (hose->pci_prefetch)
+ pciauto_show_region("Prefetchable Mem", hose->pci_prefetch);
+ if (hose->pci_io)
+ pciauto_show_region("I/O", hose->pci_io);
}
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 9fe07f2..4434e36 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -325,7 +325,7 @@ int regulators_enable_boot_on(bool verbose)
if (ret)
return ret;
for (uclass_first_device(UCLASS_REGULATOR, &dev);
- dev && !ret;
+ dev;
uclass_next_device(&dev)) {
ret = regulator_autoset(dev);
if (ret == -EMEDIUMTYPE) {
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 1c447ff..f154eb1 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -123,11 +123,12 @@ static void _serial_putc(struct udevice *dev, char ch)
struct dm_serial_ops *ops = serial_get_ops(dev);
int err;
+ if (ch == '\n')
+ _serial_putc(dev, '\r');
+
do {
err = ops->putc(dev, ch);
} while (err == -EAGAIN);
- if (ch == '\n')
- _serial_putc(dev, '\r');
}
static void _serial_puts(struct udevice *dev, const char *str)
diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c
index 7dbb49f..6292eb1 100644
--- a/drivers/serial/serial_arc.c
+++ b/drivers/serial/serial_arc.c
@@ -68,9 +68,6 @@ static int arc_serial_putc(struct udevice *dev, const char c)
struct arc_serial_platdata *plat = dev->platdata;
struct arc_serial_regs *const regs = plat->reg;
- if (c == '\n')
- arc_serial_putc(dev, '\r');
-
while (!(readb(&regs->status) & UART_TXEMPTY))
;
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index fc3321f..042e9a2 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -77,9 +77,6 @@ static int _lpuart_serial_getc(struct lpuart_fsl *base)
static void _lpuart_serial_putc(struct lpuart_fsl *base, const char c)
{
- if (c == '\n')
- _lpuart_serial_putc(base, '\r');
-
while (!(__raw_readb(&base->us1) & US1_TDRE))
WATCHDOG_RESET();
@@ -198,9 +195,6 @@ static int _lpuart32_serial_getc(struct lpuart_fsl *base)
static void _lpuart32_serial_putc(struct lpuart_fsl *base, const char c)
{
- if (c == '\n')
- _lpuart32_serial_putc(base, '\r');
-
while (!(in_be32(&base->stat) & STAT_TDRE))
WATCHDOG_RESET();
diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index 51485c0..1563bb3 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -164,15 +164,15 @@ static int mxc_serial_getc(void)
static void mxc_serial_putc(const char c)
{
+ /* If \n, also do \r */
+ if (c == '\n')
+ serial_putc('\r');
+
__REG(UART_PHYS + UTXD) = c;
/* wait for transmitter to be ready */
while (!(__REG(UART_PHYS + UTS) & UTS_TXEMPTY))
WATCHDOG_RESET();
-
- /* If \n, also do \r */
- if (c == '\n')
- serial_putc ('\r');
}
/*
diff --git a/drivers/serial/serial_pxa.c b/drivers/serial/serial_pxa.c
index 8fbcc10..1eb19ec 100644
--- a/drivers/serial/serial_pxa.c
+++ b/drivers/serial/serial_pxa.c
@@ -156,6 +156,10 @@ void pxa_putc_dev(unsigned int uart_index, const char c)
{
struct pxa_uart_regs *uart_regs;
+ /* If \n, also do \r */
+ if (c == '\n')
+ pxa_putc_dev(uart_index, '\r');
+
uart_regs = pxa_uart_index_to_regs(uart_index);
if (!uart_regs)
hang();
@@ -163,10 +167,6 @@ void pxa_putc_dev(unsigned int uart_index, const char c)
while (!(readl(&uart_regs->lsr) & LSR_TEMT))
WATCHDOG_RESET();
writel(c, &uart_regs->thr);
-
- /* If \n, also do \r */
- if (c == '\n')
- pxa_putc_dev (uart_index,'\r');
}
/*
diff --git a/drivers/serial/serial_s3c24x0.c b/drivers/serial/serial_s3c24x0.c
index d4e7df2..0f0878a 100644
--- a/drivers/serial/serial_s3c24x0.c
+++ b/drivers/serial/serial_s3c24x0.c
@@ -135,14 +135,14 @@ static void _serial_putc(const char c, const int dev_index)
{
struct s3c24x0_uart *uart = s3c24x0_get_base_uart(dev_index);
+ /* If \n, also do \r */
+ if (c == '\n')
+ serial_putc('\r');
+
while (!(readl(&uart->utrstat) & 0x2))
/* wait for room in the tx FIFO */ ;
writeb(c, &uart->utxh);
-
- /* If \n, also do \r */
- if (c == '\n')
- serial_putc('\r');
}
static inline void serial_putc_dev(unsigned int dev_index, const char c)
diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
index 75f0ec3..2e19813 100644
--- a/drivers/serial/usbtty.c
+++ b/drivers/serial/usbtty.c
@@ -434,11 +434,12 @@ void usbtty_putc(struct stdio_dev *dev, const char c)
if (!usbtty_configured ())
return;
- buf_push (&usbtty_output, &c, 1);
/* If \n, also do \r */
if (c == '\n')
buf_push (&usbtty_output, "\r", 1);
+ buf_push(&usbtty_output, &c, 1);
+
/* Poll at end to handle new data... */
if ((usbtty_output.size + 2) >= usbtty_output.totalsize) {
usbtty_poll ();
@@ -498,8 +499,8 @@ void usbtty_puts(struct stdio_dev *dev, const char *str)
n = next_nl_pos (str);
if (str[n] == '\n') {
- __usbtty_puts (str, n + 1);
- __usbtty_puts ("\r", 1);
+ __usbtty_puts("\r", 1);
+ __usbtty_puts(str, n + 1);
str += (n + 1);
len -= (n + 1);
} else {
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index 382c0f2..f8ddf93 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -82,11 +82,9 @@ int notrace dm_timer_init(void)
node = fdtdec_get_chosen_node(blob, "tick-timer");
if (node < 0) {
/* No chosen timer, trying first available timer */
- ret = uclass_first_device(UCLASS_TIMER, &dev);
+ ret = uclass_first_device_err(UCLASS_TIMER, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
} else {
if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) {
/*
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 832e90a..c8cc05e 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -240,8 +240,7 @@ static int do_video_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 3)
return CMD_RET_USAGE;
- uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
- if (!dev)
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
col = simple_strtoul(argv[1], NULL, 10);
row = simple_strtoul(argv[2], NULL, 10);
@@ -259,8 +258,7 @@ static int do_video_puts(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 2)
return CMD_RET_USAGE;
- uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
- if (!dev)
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
for (s = argv[1]; *s; s++)
vidconsole_put_char(dev, *s);
diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
index 9fd10de..ee84d3f 100644
--- a/fs/ext4/dev.c
+++ b/fs/ext4/dev.c
@@ -24,6 +24,7 @@
*/
#include <common.h>
+#include <blk.h>
#include <config.h>
#include <memalign.h>
#include <ext4fs.h>
@@ -32,13 +33,13 @@
lbaint_t part_offset;
-static block_dev_desc_t *ext4fs_block_dev_desc;
+static struct blk_desc *ext4fs_blk_desc;
static disk_partition_t *part_info;
-void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
{
assert(rbdd->blksz == (1 << rbdd->log2blksz));
- ext4fs_block_dev_desc = rbdd;
+ ext4fs_blk_desc = rbdd;
get_fs()->dev_desc = rbdd;
part_info = info;
part_offset = info->start;
@@ -49,11 +50,11 @@ void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
{
unsigned block_len;
- int log2blksz = ext4fs_block_dev_desc->log2blksz;
- ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (ext4fs_block_dev_desc ?
- ext4fs_block_dev_desc->blksz :
+ int log2blksz = ext4fs_blk_desc->log2blksz;
+ ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (ext4fs_blk_desc ?
+ ext4fs_blk_desc->blksz :
0));
- if (ext4fs_block_dev_desc == NULL) {
+ if (ext4fs_blk_desc == NULL) {
printf("** Invalid Block Device Descriptor (NULL)\n");
return 0;
}
@@ -69,21 +70,19 @@ int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
/* Get the read to the beginning of a partition */
sector += byte_offset >> log2blksz;
- byte_offset &= ext4fs_block_dev_desc->blksz - 1;
+ byte_offset &= ext4fs_blk_desc->blksz - 1;
debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len);
if (byte_offset != 0) {
int readlen;
/* read first part which isn't aligned with start of sector */
- if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
- part_info->start + sector,
- 1, (void *)sec_buf)
- != 1) {
+ if (blk_dread(ext4fs_blk_desc, part_info->start + sector, 1,
+ (void *)sec_buf) != 1) {
printf(" ** ext2fs_devread() read error **\n");
return 0;
}
- readlen = min((int)ext4fs_block_dev_desc->blksz - byte_offset,
+ readlen = min((int)ext4fs_blk_desc->blksz - byte_offset,
byte_len);
memcpy(buf, sec_buf + byte_offset, readlen);
buf += readlen;
@@ -95,38 +94,33 @@ int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
return 1;
/* read sector aligned part */
- block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
+ block_len = byte_len & ~(ext4fs_blk_desc->blksz - 1);
if (block_len == 0) {
- ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_block_dev_desc->blksz);
+ ALLOC_CACHE_ALIGN_BUFFER(u8, p, ext4fs_blk_desc->blksz);
- block_len = ext4fs_block_dev_desc->blksz;
- ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
- part_info->start + sector,
- 1, (void *)p);
+ block_len = ext4fs_blk_desc->blksz;
+ blk_dread(ext4fs_blk_desc, part_info->start + sector, 1,
+ (void *)p);
memcpy(buf, p, byte_len);
return 1;
}
- if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
- part_info->start + sector,
- block_len >> log2blksz,
- (void *)buf) !=
- block_len >> log2blksz) {
+ if (blk_dread(ext4fs_blk_desc, part_info->start + sector,
+ block_len >> log2blksz, (void *)buf) !=
+ block_len >> log2blksz) {
printf(" ** %s read error - block\n", __func__);
return 0;
}
- block_len = byte_len & ~(ext4fs_block_dev_desc->blksz - 1);
+ block_len = byte_len & ~(ext4fs_blk_desc->blksz - 1);
buf += block_len;
byte_len -= block_len;
- sector += block_len / ext4fs_block_dev_desc->blksz;
+ sector += block_len / ext4fs_blk_desc->blksz;
if (byte_len != 0) {
/* read rest of data which are not in whole sector */
- if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc,
- part_info->start + sector,
- 1, (void *)sec_buf)
- != 1) {
+ if (blk_dread(ext4fs_blk_desc, part_info->start + sector, 1,
+ (void *)sec_buf) != 1) {
printf("* %s read error - last part\n", __func__);
return 0;
}
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 294a46e..84fba76 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -81,29 +81,20 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
}
if (remainder) {
- if (fs->dev_desc->block_read) {
- fs->dev_desc->block_read(fs->dev_desc,
- startblock, 1, sec_buf);
- temp_ptr = sec_buf;
- memcpy((temp_ptr + remainder),
- (unsigned char *)buf, size);
- fs->dev_desc->block_write(fs->dev_desc,
- startblock, 1, sec_buf);
- }
+ blk_dread(fs->dev_desc, startblock, 1, sec_buf);
+ temp_ptr = sec_buf;
+ memcpy((temp_ptr + remainder), (unsigned char *)buf, size);
+ blk_dwrite(fs->dev_desc, startblock, 1, sec_buf);
} else {
if (size >> log2blksz != 0) {
- fs->dev_desc->block_write(fs->dev_desc,
- startblock,
- size >> log2blksz,
- (unsigned long *)buf);
+ blk_dwrite(fs->dev_desc, startblock, size >> log2blksz,
+ (unsigned long *)buf);
} else {
- fs->dev_desc->block_read(fs->dev_desc,
- startblock, 1, sec_buf);
+ blk_dread(fs->dev_desc, startblock, 1, sec_buf);
temp_ptr = sec_buf;
memcpy(temp_ptr, buf, size);
- fs->dev_desc->block_write(fs->dev_desc,
- startblock, 1,
- (unsigned long *)sec_buf);
+ blk_dwrite(fs->dev_desc, startblock, 1,
+ (unsigned long *)sec_buf);
}
}
}
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 258b937..43c8897 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -198,7 +198,7 @@ int ext4fs_read(char *buf, loff_t len, loff_t *actread)
return ext4fs_read_file(ext4fs_file, 0, len, buf, actread);
}
-int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
+int ext4fs_probe(struct blk_desc *fs_dev_desc,
disk_partition_t *fs_partition)
{
ext4fs_set_blk_dev(fs_dev_desc, fs_partition);
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 472a63e..600a90e 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -10,6 +10,7 @@
*/
#include <common.h>
+#include <blk.h>
#include <config.h>
#include <exports.h>
#include <fat.h>
@@ -37,7 +38,7 @@ static void downcase(char *str)
}
}
-static block_dev_desc_t *cur_dev;
+static struct blk_desc *cur_dev;
static disk_partition_t cur_part_info;
#define DOS_BOOT_MAGIC_OFFSET 0x1fe
@@ -48,11 +49,10 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
{
ulong ret;
- if (!cur_dev || !cur_dev->block_read)
+ if (!cur_dev)
return -1;
- ret = cur_dev->block_read(cur_dev, cur_part_info.start + block,
- nr_blocks, buf);
+ ret = blk_dread(cur_dev, cur_part_info.start + block, nr_blocks, buf);
if (nr_blocks && ret == 0)
return -1;
@@ -60,7 +60,7 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
return ret;
}
-int fat_set_blk_dev(block_dev_desc_t *dev_desc, disk_partition_t *info)
+int fat_set_blk_dev(struct blk_desc *dev_desc, disk_partition_t *info)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
@@ -89,7 +89,7 @@ int fat_set_blk_dev(block_dev_desc_t *dev_desc, disk_partition_t *info)
return -1;
}
-int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
+int fat_register_device(struct blk_desc *dev_desc, int part_no)
{
disk_partition_t info;
@@ -97,10 +97,10 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
cur_dev = NULL;
/* Read the partition table, if present */
- if (get_partition_info(dev_desc, part_no, &info)) {
+ if (part_get_info(dev_desc, part_no, &info)) {
if (part_no != 0) {
printf("** Partition %d not valid on device %d **\n",
- part_no, dev_desc->dev);
+ part_no, dev_desc->devnum);
return -1;
}
@@ -1284,7 +1284,7 @@ int file_fat_detectfs(void)
printf("Unknown");
}
- printf("\n Device %d: ", cur_dev->dev);
+ printf("\n Device %d: ", cur_dev->devnum);
dev_print(cur_dev);
#endif
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 5ed324c..baa85ec 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -32,7 +32,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
{
ulong ret;
- if (!cur_dev || !cur_dev->block_write)
+ if (!cur_dev)
return -1;
if (cur_part_info.start + block + nr_blocks >
@@ -41,8 +41,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
return -1;
}
- ret = cur_dev->block_write(cur_dev, cur_part_info.start + block,
- nr_blocks, buf);
+ ret = blk_dwrite(cur_dev, cur_part_info.start + block, nr_blocks, buf);
if (nr_blocks && ret == 0)
return -1;
diff --git a/fs/fs.c b/fs/fs.c
index d123d29..595ff1f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -20,11 +20,11 @@
DECLARE_GLOBAL_DATA_PTR;
-static block_dev_desc_t *fs_dev_desc;
+static struct blk_desc *fs_dev_desc;
static disk_partition_t fs_partition;
static int fs_type = FS_TYPE_ANY;
-static inline int fs_probe_unsupported(block_dev_desc_t *fs_dev_desc,
+static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
disk_partition_t *fs_partition)
{
printf("** Unrecognized filesystem type **\n");
@@ -81,7 +81,7 @@ struct fstype_info {
* filesystem.
*/
bool null_dev_desc_ok;
- int (*probe)(block_dev_desc_t *fs_dev_desc,
+ int (*probe)(struct blk_desc *fs_dev_desc,
disk_partition_t *fs_partition);
int (*ls)(const char *dirname);
int (*exists)(const char *filename);
@@ -213,7 +213,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
}
#endif
- part = get_device_and_partition(ifname, dev_part_str, &fs_dev_desc,
+ part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc,
&fs_partition, 1);
if (part < 0)
return -1;
diff --git a/fs/reiserfs/dev.c b/fs/reiserfs/dev.c
index 7b24d6a..5a1ab0a 100644
--- a/fs/reiserfs/dev.c
+++ b/fs/reiserfs/dev.c
@@ -12,13 +12,13 @@
#include "reiserfs_private.h"
-static block_dev_desc_t *reiserfs_block_dev_desc;
+static struct blk_desc *reiserfs_blk_desc;
static disk_partition_t *part_info;
-void reiserfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+void reiserfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
{
- reiserfs_block_dev_desc = rbdd;
+ reiserfs_blk_desc = rbdd;
part_info = info;
}
@@ -53,17 +53,15 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
#endif
- if (reiserfs_block_dev_desc == NULL)
+ if (reiserfs_blk_desc == NULL)
return 0;
if (byte_offset != 0) {
/* read first part which isn't aligned with start of sector */
- if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
- part_info->start +
- sector,
- 1, (void *)sec_buf)
- != 1) {
+ if (reiserfs_blk_desc->block_read(reiserfs_blk_desc,
+ part_info->start + sector,
+ 1, (void *)sec_buf) != 1) {
printf (" ** reiserfs_devread() read error\n");
return 0;
}
@@ -75,11 +73,10 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
/* read sector aligned part */
block_len = byte_len & ~(SECTOR_SIZE-1);
- if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
- part_info->start + sector,
- block_len / SECTOR_SIZE,
- (void *)buf)
- != block_len/SECTOR_SIZE) {
+ if (reiserfs_blk_desc->block_read(reiserfs_blk_desc,
+ part_info->start + sector,
+ block_len / SECTOR_SIZE, (void *)buf)
+ != block_len/SECTOR_SIZE) {
printf (" ** reiserfs_devread() read error - block\n");
return 0;
}
@@ -89,11 +86,9 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
if ( byte_len != 0 ) {
/* read rest of data which are not in whole sector */
- if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc,
- part_info->start +
- sector,
- 1, (void *)sec_buf)
- != 1) {
+ if (reiserfs_blk_desc->block_read(reiserfs_blk_desc,
+ part_info->start + sector,
+ 1, (void *)sec_buf) != 1) {
printf (" ** reiserfs_devread() read error - last part\n");
return 0;
}
diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
index 5acfc03..2703eed 100644
--- a/fs/sandbox/sandboxfs.c
+++ b/fs/sandbox/sandboxfs.c
@@ -8,10 +8,10 @@
#include <fs.h>
#include <os.h>
-int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
{
/*
- * Only accept a NULL block_dev_desc_t for the sandbox, which is when
+ * Only accept a NULL struct blk_desc for the sandbox, which is when
* hostfs interface is used
*/
return rbdd != NULL;
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index a992a00..cdc04c6 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -561,7 +561,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
return 0;
}
-int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+int ubifs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
{
if (rbdd) {
debug("UBIFS cannot be used with normal block devices\n");
@@ -569,7 +569,7 @@ int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
}
/*
- * Should never happen since get_device_and_partition() already checks
+ * Should never happen since blk_get_device_part_str() already checks
* this, but better safe then sorry.
*/
if (!ubifs_is_mounted()) {
diff --git a/fs/zfs/dev.c b/fs/zfs/dev.c
index 67d1265..2f409e6 100644
--- a/fs/zfs/dev.c
+++ b/fs/zfs/dev.c
@@ -13,12 +13,12 @@
#include <config.h>
#include <zfs_common.h>
-static block_dev_desc_t *zfs_block_dev_desc;
+static struct blk_desc *zfs_blk_desc;
static disk_partition_t *part_info;
-void zfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
+void zfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
{
- zfs_block_dev_desc = rbdd;
+ zfs_blk_desc = rbdd;
part_info = info;
}
@@ -48,17 +48,16 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
- if (zfs_block_dev_desc == NULL) {
+ if (zfs_blk_desc == NULL) {
printf("** Invalid Block Device Descriptor (NULL)\n");
return 1;
}
if (byte_offset != 0) {
/* read first part which isn't aligned with start of sector */
- if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
- part_info->start + sector, 1,
- (void *)sec_buf)
- != 1) {
+ if (zfs_blk_desc->block_read(zfs_blk_desc,
+ part_info->start + sector, 1,
+ (void *)sec_buf) != 1) {
printf(" ** zfs_devread() read error **\n");
return 1;
}
@@ -79,18 +78,16 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
u8 p[SECTOR_SIZE];
block_len = SECTOR_SIZE;
- zfs_block_dev_desc->block_read(zfs_block_dev_desc,
- part_info->start + sector,
- 1, (void *)p);
+ zfs_blk_desc->block_read(zfs_blk_desc,
+ part_info->start + sector,
+ 1, (void *)p);
memcpy(buf, p, byte_len);
return 0;
}
- if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
- part_info->start + sector,
- block_len / SECTOR_SIZE,
- (void *)buf)
- != block_len / SECTOR_SIZE) {
+ if (zfs_blk_desc->block_read(zfs_blk_desc, part_info->start + sector,
+ block_len / SECTOR_SIZE,
+ (void *)buf) != block_len / SECTOR_SIZE) {
printf(" ** zfs_devread() read error - block\n");
return 1;
}
@@ -102,9 +99,9 @@ int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
if (byte_len != 0) {
/* read rest of data which are not in whole sector */
- if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
- part_info->start + sector,
- 1, (void *)sec_buf) != 1) {
+ if (zfs_blk_desc->block_read(zfs_blk_desc,
+ part_info->start + sector,
+ 1, (void *)sec_buf) != 1) {
printf(" ** zfs_devread() read error - last part\n");
return 1;
}
diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c
index fb2b3ee..ca67afb 100644
--- a/fs/zfs/zfs.c
+++ b/fs/zfs/zfs.c
@@ -20,7 +20,7 @@
#include "zfs_common.h"
#include "div64.h"
-block_dev_desc_t *zfs_dev_desc;
+struct blk_desc *zfs_dev_desc;
/*
* The zfs plug-in routines for GRUB are:
diff --git a/include/blk.h b/include/blk.h
new file mode 100644
index 0000000..e83c144
--- /dev/null
+++ b/include/blk.h
@@ -0,0 +1,248 @@
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef BLK_H
+#define BLK_H
+
+#ifdef CONFIG_SYS_64BIT_LBA
+typedef uint64_t lbaint_t;
+#define LBAFlength "ll"
+#else
+typedef ulong lbaint_t;
+#define LBAFlength "l"
+#endif
+#define LBAF "%" LBAFlength "x"
+#define LBAFU "%" LBAFlength "u"
+
+/* Interface types: */
+enum if_type {
+ IF_TYPE_UNKNOWN = 0,
+ IF_TYPE_IDE,
+ IF_TYPE_SCSI,
+ IF_TYPE_ATAPI,
+ IF_TYPE_USB,
+ IF_TYPE_DOC,
+ IF_TYPE_MMC,
+ IF_TYPE_SD,
+ IF_TYPE_SATA,
+ IF_TYPE_HOST,
+
+ IF_TYPE_COUNT, /* Number of interface types */
+};
+
+/*
+ * With driver model (CONFIG_BLK) this is uclass platform data, accessible
+ * with dev_get_uclass_platdata(dev)
+ */
+struct blk_desc {
+ /*
+ * TODO: With driver model we should be able to use the parent
+ * device's uclass instead.
+ */
+ enum if_type if_type; /* type of the interface */
+ int devnum; /* device number */
+ unsigned char part_type; /* partition type */
+ unsigned char target; /* target SCSI ID */
+ unsigned char lun; /* target LUN */
+ unsigned char hwpart; /* HW partition, e.g. for eMMC */
+ unsigned char type; /* device type */
+ unsigned char removable; /* removable device */
+#ifdef CONFIG_LBA48
+ /* device can use 48bit addr (ATA/ATAPI v7) */
+ unsigned char lba48;
+#endif
+ lbaint_t lba; /* number of blocks */
+ unsigned long blksz; /* block size */
+ int log2blksz; /* for convenience: log2(blksz) */
+ char vendor[40+1]; /* IDE model, SCSI Vendor */
+ char product[20+1]; /* IDE Serial no, SCSI product */
+ char revision[8+1]; /* firmware revision */
+#ifdef CONFIG_BLK
+ struct udevice *bdev;
+#else
+ unsigned long (*block_read)(struct blk_desc *block_dev,
+ lbaint_t start,
+ lbaint_t blkcnt,
+ void *buffer);
+ unsigned long (*block_write)(struct blk_desc *block_dev,
+ lbaint_t start,
+ lbaint_t blkcnt,
+ const void *buffer);
+ unsigned long (*block_erase)(struct blk_desc *block_dev,
+ lbaint_t start,
+ lbaint_t blkcnt);
+ void *priv; /* driver private struct pointer */
+#endif
+};
+
+#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
+#define PAD_TO_BLOCKSIZE(size, blk_desc) \
+ (PAD_SIZE(size, blk_desc->blksz))
+
+#ifdef CONFIG_BLK
+struct udevice;
+
+/* Operations on block devices */
+struct blk_ops {
+ /**
+ * read() - read from a block device
+ *
+ * @dev: Device to read from
+ * @start: Start block number to read (0=first)
+ * @blkcnt: Number of blocks to read
+ * @buffer: Destination buffer for data read
+ * @return number of blocks read, or -ve error number (see the
+ * IS_ERR_VALUE() macro
+ */
+ unsigned long (*read)(struct udevice *dev, lbaint_t start,
+ lbaint_t blkcnt, void *buffer);
+
+ /**
+ * write() - write to a block device
+ *
+ * @dev: Device to write to
+ * @start: Start block number to write (0=first)
+ * @blkcnt: Number of blocks to write
+ * @buffer: Source buffer for data to write
+ * @return number of blocks written, or -ve error number (see the
+ * IS_ERR_VALUE() macro
+ */
+ unsigned long (*write)(struct udevice *dev, lbaint_t start,
+ lbaint_t blkcnt, const void *buffer);
+
+ /**
+ * erase() - erase a section of a block device
+ *
+ * @dev: Device to (partially) erase
+ * @start: Start block number to erase (0=first)
+ * @blkcnt: Number of blocks to erase
+ * @return number of blocks erased, or -ve error number (see the
+ * IS_ERR_VALUE() macro
+ */
+ unsigned long (*erase)(struct udevice *dev, lbaint_t start,
+ lbaint_t blkcnt);
+};
+
+#define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops)
+
+/*
+ * These functions should take struct udevice instead of struct blk_desc,
+ * but this is convenient for migration to driver model. Add a 'd' prefix
+ * to the function operations, so that blk_read(), etc. can be reserved for
+ * functions with the correct arguments.
+ */
+unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, void *buffer);
+unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, const void *buffer);
+unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt);
+
+/**
+ * blk_get_device() - Find and probe a block device ready for use
+ *
+ * @if_type: Interface type (enum if_type_t)
+ * @devnum: Device number (specific to each interface type)
+ * @devp: the device, if found
+ * @return - if found, -ENODEV if no device found, or other -ve error value
+ */
+int blk_get_device(int if_type, int devnum, struct udevice **devp);
+
+/**
+ * blk_first_device() - Find the first device for a given interface
+ *
+ * The device is probed ready for use
+ *
+ * @devnum: Device number (specific to each interface type)
+ * @devp: the device, if found
+ * @return 0 if found, -ENODEV if no device, or other -ve error value
+ */
+int blk_first_device(int if_type, struct udevice **devp);
+
+/**
+ * blk_next_device() - Find the next device for a given interface
+ *
+ * This can be called repeatedly after blk_first_device() to iterate through
+ * all devices of the given interface type.
+ *
+ * The device is probed ready for use
+ *
+ * @devp: On entry, the previous device returned. On exit, the next
+ * device, if found
+ * @return 0 if found, -ENODEV if no device, or other -ve error value
+ */
+int blk_next_device(struct udevice **devp);
+
+/**
+ * blk_create_device() - Create a new block device
+ *
+ * @parent: Parent of the new device
+ * @drv_name: Driver name to use for the block device
+ * @name: Name for the device
+ * @if_type: Interface type (enum if_type_t)
+ * @devnum: Device number, specific to the interface type
+ * @blksz: Block size of the device in bytes (typically 512)
+ * @size: Total size of the device in bytes
+ * @devp: the new device (which has not been probed)
+ */
+int blk_create_device(struct udevice *parent, const char *drv_name,
+ const char *name, int if_type, int devnum, int blksz,
+ lbaint_t size, struct udevice **devp);
+
+/**
+ * blk_prepare_device() - Prepare a block device for use
+ *
+ * This reads partition information from the device if supported.
+ *
+ * @dev: Device to prepare
+ * @return 0 if ok, -ve on error
+ */
+int blk_prepare_device(struct udevice *dev);
+
+/**
+ * blk_unbind_all() - Unbind all device of the given interface type
+ *
+ * The devices are removed and then unbound.
+ *
+ * @if_type: Interface type to unbind
+ * @return 0 if OK, -ve on error
+ */
+int blk_unbind_all(int if_type);
+
+#else
+#include <errno.h>
+/*
+ * These functions should take struct udevice instead of struct blk_desc,
+ * but this is convenient for migration to driver model. Add a 'd' prefix
+ * to the function operations, so that blk_read(), etc. can be reserved for
+ * functions with the correct arguments.
+ */
+static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, void *buffer)
+{
+ /*
+ * We could check if block_read is NULL and return -ENOSYS. But this
+ * bloats the code slightly (cause some board to fail to build), and
+ * it would be an error to try an operation that does not exist.
+ */
+ return block_dev->block_read(block_dev, start, blkcnt, buffer);
+}
+
+static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt, const void *buffer)
+{
+ return block_dev->block_write(block_dev, start, blkcnt, buffer);
+}
+
+static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
+ lbaint_t blkcnt)
+{
+ return block_dev->block_erase(block_dev, start, blkcnt);
+}
+#endif /* !CONFIG_BLK */
+
+#endif
diff --git a/include/common.h b/include/common.h
index 3e1a4c9..f9f4605 100644
--- a/include/common.h
+++ b/include/common.h
@@ -807,7 +807,7 @@ void gzwrite_progress_finish(int retcode,
* for files under 4GiB
*/
int gzwrite(unsigned char *src, int len,
- struct block_dev_desc *dev,
+ struct blk_desc *dev,
unsigned long szwritebuf,
u64 startoffs,
u64 szexpected);
diff --git a/include/configs/UCP1020.h b/include/configs/UCP1020.h
index b080724..139e629 100644
--- a/include/configs/UCP1020.h
+++ b/include/configs/UCP1020.h
@@ -484,7 +484,6 @@
#define CONFIG_CMD_REGINFO
#define CONFIG_CMD_ERRATA
#define CONFIG_CMD_CRAMFS
-#define CONFIG_CRAMFS_CMDLINE
/*
* USB
diff --git a/include/configs/km/keymile-common.h b/include/configs/km/keymile-common.h
index 91b29b3..5edc8f6 100644
--- a/include/configs/km/keymile-common.h
+++ b/include/configs/km/keymile-common.h
@@ -83,7 +83,6 @@
#define CONFIG_MTD_CONCAT
#define CONFIG_CMD_CRAMFS
-#define CONFIG_CRAMFS_CMDLINE
#ifndef CONFIG_KM_DEF_ENV_BOOTPARAMS
#define CONFIG_KM_DEF_ENV_BOOTPARAMS \
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index d59beb8..cc22467 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -43,6 +43,8 @@
#define CONFIG_CMD_FAT
#define CONFIG_CMD_EXT4
#define CONFIG_CMD_EXT4_WRITE
+#define CONFIG_CMD_CBFS
+#define CONFIG_CMD_CRAMFS
#define CONFIG_CMD_PART
#define CONFIG_DOS_PARTITION
#define CONFIG_HOST_MAX_DEVICES 4
@@ -52,8 +54,11 @@
#define CONFIG_CMD_GPT
#define CONFIG_PARTITION_UUIDS
-#define CONFIG_EFI_PARTITION
+#define CONFIG_AMIGA_PARTITION
#define CONFIG_DOS_PARTITION
+#define CONFIG_EFI_PARTITION
+#define CONFIG_ISO_PARTITION
+#define CONFIG_MAC_PARTITION
/*
* Size of malloc() pool, before and after relocation
diff --git a/include/debug_uart.h b/include/debug_uart.h
index 5d5349b..0d640b9 100644
--- a/include/debug_uart.h
+++ b/include/debug_uart.h
@@ -117,13 +117,15 @@ void printhex8(uint value);
#define DEBUG_UART_FUNCS \
void printch(int ch) \
{ \
+ if (ch == '\n') \
+ _debug_uart_putc('\r'); \
_debug_uart_putc(ch); \
} \
\
void printascii(const char *str) \
{ \
while (*str) \
- _debug_uart_putc(*str++); \
+ printch(*str++); \
} \
\
static inline void printhex1(uint digit) \
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 3bea308..37c4176 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -26,6 +26,7 @@ enum uclass_id {
/* U-Boot uclasses start here - in alphabetical order */
UCLASS_ADC, /* Analog-to-digital converter */
+ UCLASS_BLK, /* Block device */
UCLASS_CLK, /* Clock source, e.g. used by peripherals */
UCLASS_CPU, /* CPU, typically part of an SoC */
UCLASS_CROS_EC, /* Chrome OS EC */
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index bfbd27a..fd368b6 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -200,18 +200,29 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
*
* @id: Uclass ID to look up
* @devp: Returns pointer to the first device in that uclass, or NULL if none
- * @return 0 if OK (found or not found), -1 on error
+ * @return 0 if OK (found or not found), other -ve on error
*/
int uclass_first_device(enum uclass_id id, struct udevice **devp);
/**
+ * uclass_first_device_err() - Get the first device in a uclass
+ *
+ * The device returned is probed if necessary, and ready for use
+ *
+ * @id: Uclass ID to look up
+ * @devp: Returns pointer to the first device in that uclass, or NULL if none
+ * @return 0 if found, -ENODEV if not found, other -ve on error
+ */
+int uclass_first_device_err(enum uclass_id id, struct udevice **devp);
+
+/**
* uclass_next_device() - Get the next device in a uclass
*
* The device returned is probed if necessary, and ready for use
*
* @devp: On entry, pointer to device to lookup. On exit, returns pointer
* to the next device in the same uclass, or NULL if none
- * @return 0 if OK (found or not found), -1 on error
+ * @return 0 if OK (found or not found), other -ve on error
*/
int uclass_next_device(struct udevice **devp);
diff --git a/include/ext4fs.h b/include/ext4fs.h
index 6888adc..cc765ae 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -110,7 +110,7 @@ struct ext_filesystem {
/* Journal Related */
/* Block Device Descriptor */
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
};
extern struct ext2_data *ext4fs_root;
@@ -141,9 +141,9 @@ int ext4fs_exists(const char *filename);
int ext4fs_size(const char *filename, loff_t *size);
void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
-void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+void ext4fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
long int read_allocated_block(struct ext2_inode *inode, int fileblock);
-int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
+int ext4fs_probe(struct blk_desc *fs_dev_desc,
disk_partition_t *fs_partition);
int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actread);
diff --git a/include/fat.h b/include/fat.h
index 3038bd7..9d053e6 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -203,8 +203,8 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
loff_t maxsize, loff_t *actread);
int file_fat_read(const char *filename, void *buffer, int maxsize);
const char *file_getfsname(int idx);
-int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
-int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
+int fat_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
+int fat_register_device(struct blk_desc *dev_desc, int part_no);
int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actwrite);
diff --git a/include/ide.h b/include/ide.h
index f9357be..a4e65cf 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -8,6 +8,8 @@
#ifndef _IDE_H
#define _IDE_H
+#include <blk.h>
+
#define IDE_BUS(dev) (dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS))
#define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)])
@@ -26,25 +28,15 @@ extern ulong ide_bus_offset[];
void ide_led(uchar led, uchar status);
#endif /* CONFIG_IDE_LED */
-#ifdef CONFIG_SYS_64BIT_LBA
-typedef uint64_t lbaint_t;
-#define LBAFlength "ll"
-#else
-typedef ulong lbaint_t;
-#define LBAFlength "l"
-#endif
-#define LBAF "%" LBAFlength "x"
-#define LBAFU "%" LBAFlength "u"
-
/*
* Function Prototypes
*/
void ide_init(void);
-typedef struct block_dev_desc block_dev_desc_t;
-ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+struct blk_desc;
+ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
void *buffer);
-ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer);
#ifdef CONFIG_IDE_PREINIT
diff --git a/include/mmc.h b/include/mmc.h
index d652c14..cdb56e7 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -376,7 +376,7 @@ struct mmc {
u64 capacity_gp[4];
u64 enh_user_start;
u64 enh_user_size;
- block_dev_desc_t block_dev;
+ struct blk_desc block_dev;
char op_cond_pending; /* 1 if we are waiting on an op_cond command */
char init_in_progress; /* 1 if we have done mmc_start_init() */
char preinit; /* start init as early as possible */
diff --git a/include/part.h b/include/part.h
index dc23949..6d8f520 100644
--- a/include/part.h
+++ b/include/part.h
@@ -7,62 +7,14 @@
#ifndef _PART_H
#define _PART_H
+#include <blk.h>
#include <ide.h>
-#include <common.h>
-struct block_dev_desc {
- int if_type; /* type of the interface */
- int dev; /* device number */
- unsigned char part_type; /* partition type */
- unsigned char target; /* target SCSI ID */
- unsigned char lun; /* target LUN */
- unsigned char hwpart; /* HW partition, e.g. for eMMC */
- unsigned char type; /* device type */
- unsigned char removable; /* removable device */
-#ifdef CONFIG_LBA48
- unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */
-#endif
- lbaint_t lba; /* number of blocks */
- unsigned long blksz; /* block size */
- int log2blksz; /* for convenience: log2(blksz) */
- char vendor [40+1]; /* IDE model, SCSI Vendor */
- char product[20+1]; /* IDE Serial no, SCSI product */
- char revision[8+1]; /* firmware revision */
- unsigned long (*block_read)(block_dev_desc_t *block_dev,
- lbaint_t start,
- lbaint_t blkcnt,
- void *buffer);
- unsigned long (*block_write)(block_dev_desc_t *block_dev,
- lbaint_t start,
- lbaint_t blkcnt,
- const void *buffer);
- unsigned long (*block_erase)(block_dev_desc_t *block_dev,
- lbaint_t start,
- lbaint_t blkcnt);
- void *priv; /* driver private struct pointer */
-};
-
-#define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
-#define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
- (PAD_SIZE(size, block_dev_desc->blksz))
#define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
((x & 0xffff0000) ? 16 : 0))
#define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
-/* Interface types: */
-#define IF_TYPE_UNKNOWN 0
-#define IF_TYPE_IDE 1
-#define IF_TYPE_SCSI 2
-#define IF_TYPE_ATAPI 3
-#define IF_TYPE_USB 4
-#define IF_TYPE_DOC 5
-#define IF_TYPE_MMC 6
-#define IF_TYPE_SD 7
-#define IF_TYPE_SATA 8
-#define IF_TYPE_HOST 9
-#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */
-
/* Part types */
#define PART_TYPE_UNKNOWN 0x00
#define PART_TYPE_MAC 0x01
@@ -101,91 +53,205 @@ typedef struct disk_partition {
/* Misc _get_dev functions */
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *get_dev(const char *ifname, int dev);
-block_dev_desc_t* ide_get_dev(int dev);
-block_dev_desc_t* sata_get_dev(int dev);
-block_dev_desc_t* scsi_get_dev(int dev);
-block_dev_desc_t* usb_stor_get_dev(int dev);
-block_dev_desc_t* mmc_get_dev(int dev);
+/**
+ * blk_get_dev() - get a pointer to a block device given its type and number
+ *
+ * Each interface allocates its own devices and typically struct blk_desc is
+ * contained with the interface's data structure. There is no global
+ * numbering for block devices, so the interface name must be provided.
+ *
+ * @ifname: Interface name (e.g. "ide", "scsi")
+ * @dev: Device number (0 for first device on that interface, 1 for
+ * second, etc.
+ * @return pointer to the block device, or NULL if not available, or an
+ * error occurred.
+ */
+struct blk_desc *blk_get_dev(const char *ifname, int dev);
+struct blk_desc *ide_get_dev(int dev);
+struct blk_desc *sata_get_dev(int dev);
+struct blk_desc *scsi_get_dev(int dev);
+struct blk_desc *usb_stor_get_dev(int dev);
+struct blk_desc *mmc_get_dev(int dev);
+
+/**
+ * mmc_select_hwpart() - Select the MMC hardware partiion on an MMC device
+ *
+ * MMC devices can support partitioning at the hardware level. This is quite
+ * separate from the normal idea of software-based partitions. MMC hardware
+ * partitions must be explicitly selected. Once selected only the region of
+ * the device covered by that partition is accessible.
+ *
+ * The MMC standard provides for two boot partitions (numbered 1 and 2),
+ * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
+ *
+ * @dev_num: Block device number (struct blk_desc->dev value)
+ * @hwpart: Hardware partition number to select. 0 means the raw device,
+ * 1 is the first partition, 2 is the second, etc.
+ * @return 0 if OK, other value for an error
+ */
int mmc_select_hwpart(int dev_num, int hwpart);
-block_dev_desc_t* systemace_get_dev(int dev);
-block_dev_desc_t* mg_disk_get_dev(int dev);
-block_dev_desc_t *host_get_dev(int dev);
-int host_get_dev_err(int dev, block_dev_desc_t **blk_devp);
+struct blk_desc *systemace_get_dev(int dev);
+struct blk_desc *mg_disk_get_dev(int dev);
+struct blk_desc *host_get_dev(int dev);
+int host_get_dev_err(int dev, struct blk_desc **blk_devp);
/* disk/part.c */
-int get_partition_info (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
-void print_part (block_dev_desc_t *dev_desc);
-void init_part (block_dev_desc_t *dev_desc);
-void dev_print(block_dev_desc_t *dev_desc);
-int get_device(const char *ifname, const char *dev_str,
- block_dev_desc_t **dev_desc);
-int get_device_and_partition(const char *ifname, const char *dev_part_str,
- block_dev_desc_t **dev_desc,
- disk_partition_t *info, int allow_whole_dev);
+int part_get_info(struct blk_desc *dev_desc, int part, disk_partition_t *info);
+void part_print(struct blk_desc *dev_desc);
+void part_init(struct blk_desc *dev_desc);
+void dev_print(struct blk_desc *dev_desc);
+
+/**
+ * blk_get_device_by_str() - Get a block device given its interface/hw partition
+ *
+ * Each interface allocates its own devices and typically struct blk_desc is
+ * contained with the interface's data structure. There is no global
+ * numbering for block devices, so the interface name must be provided.
+ *
+ * The hardware parition is not related to the normal software partitioning
+ * of a device - each hardware partition is effectively a separately
+ * accessible block device. When a hardware parition is selected on MMC the
+ * other hardware partitions become inaccessible. The same block device is
+ * used to access all hardware partitions, but its capacity may change when a
+ * different hardware partition is selected.
+ *
+ * When a hardware partition number is given, the block device switches to
+ * that hardware partition.
+ *
+ * @ifname: Interface name (e.g. "ide", "scsi")
+ * @dev_str: Device and optional hw partition. This can either be a string
+ * containing the device number (e.g. "2") or the device number
+ * and hardware partition number (e.g. "2.4") for devices that
+ * support it (currently only MMC).
+ * @dev_desc: Returns a pointer to the block device on success
+ * @return block device number (local to the interface), or -1 on error
+ */
+int blk_get_device_by_str(const char *ifname, const char *dev_str,
+ struct blk_desc **dev_desc);
+
+/**
+ * blk_get_device_part_str() - Get a block device and partition
+ *
+ * This calls blk_get_device_by_str() to look up a device. It also looks up
+ * a partition and returns information about it.
+ *
+ * @dev_part_str is in the format:
+ * <dev>.<hw_part>:<part> where <dev> is the device number,
+ * <hw_part> is the optional hardware partition number and
+ * <part> is the partition number
+ *
+ * If ifname is "hostfs" then this function returns the sandbox host block
+ * device.
+ *
+ * If ifname is ubi, then this function returns 0, with @info set to a
+ * special UBI device.
+ *
+ * If @dev_part_str is NULL or empty or "-", then this function looks up
+ * the "bootdevice" environment variable and uses that string instead.
+ *
+ * If the partition string is empty then the first partition is used. If the
+ * partition string is "auto" then the first bootable partition is used.
+ *
+ * @ifname: Interface name (e.g. "ide", "scsi")
+ * @dev_part_str: Device and partition string
+ * @dev_desc: Returns a pointer to the block device on success
+ * @info: Returns partition information
+ * @allow_whole_dev: true to allow the user to select partition 0
+ * (which means the whole device), false to require a valid
+ * partition number >= 1
+ * @return partition number, or -1 on error
+ *
+ */
+int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
+ struct blk_desc **dev_desc,
+ disk_partition_t *info, int allow_whole_dev);
#else
-static inline block_dev_desc_t *get_dev(const char *ifname, int dev)
+static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
{ return NULL; }
-static inline block_dev_desc_t* ide_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t* sata_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t* scsi_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t* usb_stor_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t* mmc_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *ide_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *sata_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *scsi_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *usb_stor_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *mmc_get_dev(int dev) { return NULL; }
static inline int mmc_select_hwpart(int dev_num, int hwpart) { return -1; }
-static inline block_dev_desc_t* systemace_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t* mg_disk_get_dev(int dev) { return NULL; }
-static inline block_dev_desc_t *host_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *systemace_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; }
+static inline struct blk_desc *host_get_dev(int dev) { return NULL; }
-static inline int get_partition_info (block_dev_desc_t * dev_desc, int part,
- disk_partition_t *info) { return -1; }
-static inline void print_part (block_dev_desc_t *dev_desc) {}
-static inline void init_part (block_dev_desc_t *dev_desc) {}
-static inline void dev_print(block_dev_desc_t *dev_desc) {}
-static inline int get_device(const char *ifname, const char *dev_str,
- block_dev_desc_t **dev_desc)
+static inline int part_get_info(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info) { return -1; }
+static inline void part_print(struct blk_desc *dev_desc) {}
+static inline void part_init(struct blk_desc *dev_desc) {}
+static inline void dev_print(struct blk_desc *dev_desc) {}
+static inline int blk_get_device_by_str(const char *ifname, const char *dev_str,
+ struct blk_desc **dev_desc)
{ return -1; }
-static inline int get_device_and_partition(const char *ifname,
+static inline int blk_get_device_part_str(const char *ifname,
const char *dev_part_str,
- block_dev_desc_t **dev_desc,
+ struct blk_desc **dev_desc,
disk_partition_t *info,
int allow_whole_dev)
{ *dev_desc = NULL; return -1; }
#endif
-#ifdef CONFIG_MAC_PARTITION
-/* disk/part_mac.c */
-int get_partition_info_mac (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
-void print_part_mac (block_dev_desc_t *dev_desc);
-int test_part_mac (block_dev_desc_t *dev_desc);
+/*
+ * We don't support printing partition information in SPL and only support
+ * getting partition information in a few cases.
+ */
+#ifdef CONFIG_SPL_BUILD
+# define part_print_ptr(x) NULL
+# if defined(CONFIG_SPL_EXT_SUPPORT) || \
+ defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
+# define part_get_info_ptr(x) x
+# else
+# define part_get_info_ptr(x) NULL
+# endif
+#else
+#define part_print_ptr(x) x
+#define part_get_info_ptr(x) x
#endif
-#ifdef CONFIG_DOS_PARTITION
-/* disk/part_dos.c */
-int get_partition_info_dos (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
-void print_part_dos (block_dev_desc_t *dev_desc);
-int test_part_dos (block_dev_desc_t *dev_desc);
-#endif
-#ifdef CONFIG_ISO_PARTITION
-/* disk/part_iso.c */
-int get_partition_info_iso (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
-void print_part_iso (block_dev_desc_t *dev_desc);
-int test_part_iso (block_dev_desc_t *dev_desc);
-#endif
+struct part_driver {
+ const char *name;
+ int part_type;
-#ifdef CONFIG_AMIGA_PARTITION
-/* disk/part_amiga.c */
-int get_partition_info_amiga (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
-void print_part_amiga (block_dev_desc_t *dev_desc);
-int test_part_amiga (block_dev_desc_t *dev_desc);
-#endif
+ /**
+ * get_info() - Get information about a partition
+ *
+ * @dev_desc: Block device descriptor
+ * @part: Partition number (1 = first)
+ * @info: Returns partition information
+ */
+ int (*get_info)(struct blk_desc *dev_desc, int part,
+ disk_partition_t *info);
+
+ /**
+ * print() - Print partition information
+ *
+ * @dev_desc: Block device descriptor
+ */
+ void (*print)(struct blk_desc *dev_desc);
+
+ /**
+ * test() - Test if a device contains this partition type
+ *
+ * @dev_desc: Block device descriptor
+ * @return 0 if the block device appears to contain this partition
+ * type, -ve if not
+ */
+ int (*test)(struct blk_desc *dev_desc);
+};
+
+/* Declare a new U-Boot partition 'driver' */
+#define U_BOOT_PART_TYPE(__name) \
+ ll_entry_declare(struct part_driver, __name, part_driver)
#ifdef CONFIG_EFI_PARTITION
#include <part_efi.h>
/* disk/part_efi.c */
-int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
/**
- * get_partition_info_efi_by_name() - Find the specified GPT partition table entry
+ * part_get_info_efi_by_name() - Find the specified GPT partition table entry
*
* @param dev_desc - block device descriptor
* @param gpt_name - the specified table entry name
@@ -193,10 +259,8 @@ int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partitio
*
* @return - '0' on match, '-1' on no match, otherwise error
*/
-int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc,
- const char *name, disk_partition_t *info);
-void print_part_efi (block_dev_desc_t *dev_desc);
-int test_part_efi (block_dev_desc_t *dev_desc);
+int part_get_info_efi_by_name(struct blk_desc *dev_desc,
+ const char *name, disk_partition_t *info);
/**
* write_gpt_table() - Write the GUID Partition Table to disk
@@ -207,7 +271,7 @@ int test_part_efi (block_dev_desc_t *dev_desc);
*
* @return - zero on success, otherwise error
*/
-int write_gpt_table(block_dev_desc_t *dev_desc,
+int write_gpt_table(struct blk_desc *dev_desc,
gpt_header *gpt_h, gpt_entry *gpt_e);
/**
@@ -233,7 +297,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
*
* @return - error on str_guid conversion error
*/
-int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
+int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,
char *str_guid, int parts_count);
/**
@@ -246,7 +310,7 @@ int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
*
* @return zero on success
*/
-int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
+int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,
disk_partition_t *partitions, const int parts_count);
/**
@@ -257,7 +321,7 @@ int gpt_restore(block_dev_desc_t *dev_desc, char *str_disk_guid,
*
* @return - '0' on success, otherwise error
*/
-int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf);
+int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf);
/**
* write_mbr_and_gpt_partitions() - write MBR, Primary GPT and Backup GPT
@@ -267,7 +331,7 @@ int is_valid_gpt_buf(block_dev_desc_t *dev_desc, void *buf);
*
* @return - '0' on success, otherwise error
*/
-int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf);
+int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf);
/**
* gpt_verify_headers() - Function to read and CRC32 check of the GPT's header
@@ -281,7 +345,7 @@ int write_mbr_and_gpt_partitions(block_dev_desc_t *dev_desc, void *buf);
*
* @return - '0' on success, otherwise error
*/
-int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head,
+int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
gpt_entry **gpt_pte);
/**
@@ -300,7 +364,7 @@ int gpt_verify_headers(block_dev_desc_t *dev_desc, gpt_header *gpt_head,
*
* @return - '0' on success, otherwise error
*/
-int gpt_verify_partitions(block_dev_desc_t *dev_desc,
+int gpt_verify_partitions(struct blk_desc *dev_desc,
disk_partition_t *partitions, int parts,
gpt_header *gpt_head, gpt_entry **gpt_pte);
#endif
diff --git a/include/reiserfs.h b/include/reiserfs.h
index 2d14d48..ffe4e46 100644
--- a/include/reiserfs.h
+++ b/include/reiserfs.h
@@ -63,7 +63,7 @@ typedef enum
} reiserfs_error_t;
-extern void reiserfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+void reiserfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
extern int reiserfs_ls (char *dirname);
extern int reiserfs_open (char *filename);
extern int reiserfs_read (char *buf, unsigned len);
diff --git a/include/sandboxblockdev.h b/include/sandboxblockdev.h
index 627787a..5174f45 100644
--- a/include/sandboxblockdev.h
+++ b/include/sandboxblockdev.h
@@ -8,7 +8,9 @@
#define __SANDBOX_BLOCK_DEV__
struct host_block_dev {
- block_dev_desc_t blk_dev;
+#ifndef CONFIG_BLK
+ struct blk_desc blk_dev;
+#endif
char *filename;
int fd;
};
diff --git a/include/sandboxfs.h b/include/sandboxfs.h
index 4c7745d..6e6e3c6 100644
--- a/include/sandboxfs.h
+++ b/include/sandboxfs.h
@@ -18,7 +18,7 @@
#ifndef __SANDBOX_FS__
#define __SANDBOX_FS__
-int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
loff_t maxsize, loff_t *actread);
diff --git a/include/sata.h b/include/sata.h
index fa61da8..b35359a 100644
--- a/include/sata.h
+++ b/include/sata.h
@@ -14,6 +14,6 @@ int sata_stop(void);
int __sata_stop(void);
int sata_port_status(int dev, int port);
-extern block_dev_desc_t sata_dev_desc[];
+extern struct blk_desc sata_dev_desc[];
#endif
diff --git a/include/spl.h b/include/spl.h
index 16f2f6a..de4f70a 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -90,14 +90,16 @@ int spl_usb_load_image(void);
int spl_sata_load_image(void);
/* SPL FAT image functions */
-int spl_load_image_fat(block_dev_desc_t *block_dev, int partition, const char *filename);
-int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition);
+int spl_load_image_fat(struct blk_desc *block_dev, int partition,
+ const char *filename);
+int spl_load_image_fat_os(struct blk_desc *block_dev, int partition);
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
/* SPL EXT image functions */
-int spl_load_image_ext(block_dev_desc_t *block_dev, int partition, const char *filename);
-int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition);
+int spl_load_image_ext(struct blk_desc *block_dev, int partition,
+ const char *filename);
+int spl_load_image_ext_os(struct blk_desc *block_dev, int partition);
/**
* spl_init() - Set up device tree and driver model in SPL if enabled
diff --git a/include/systemace.h b/include/systemace.h
index 3f342d5..3b6ec7d 100644
--- a/include/systemace.h
+++ b/include/systemace.h
@@ -11,7 +11,7 @@
# include <part.h>
-block_dev_desc_t * systemace_get_dev(int dev);
+struct blk_desc *systemace_get_dev(int dev);
#endif /* CONFIG_SYSTEMACE */
#endif /* __SYSTEMACE_H */
diff --git a/include/ubifs_uboot.h b/include/ubifs_uboot.h
index dab433a..d86da27 100644
--- a/include/ubifs_uboot.h
+++ b/include/ubifs_uboot.h
@@ -21,7 +21,7 @@ void uboot_ubifs_umount(void);
int ubifs_is_mounted(void);
int ubifs_load(char *filename, u32 addr, u32 size);
-int ubifs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+int ubifs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
int ubifs_ls(const char *dir_name);
int ubifs_exists(const char *filename);
int ubifs_size(const char *filename, loff_t *size);
diff --git a/include/usb.h b/include/usb.h
index 0b410b6..c2fa684 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -228,7 +228,7 @@ int board_usb_cleanup(int index, enum usb_init_type init);
#ifdef CONFIG_USB_STORAGE
#define USB_MAX_STOR_DEV 7
-block_dev_desc_t *usb_stor_get_dev(int index);
+struct blk_desc *usb_stor_get_dev(int index);
int usb_stor_scan(int mode);
int usb_stor_info(void);
diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h
index 5804b70..8229f62 100644
--- a/include/usb_mass_storage.h
+++ b/include/usb_mass_storage.h
@@ -23,7 +23,7 @@ struct ums {
unsigned int start_sector;
unsigned int num_sectors;
const char *name;
- block_dev_desc_t block_dev;
+ struct blk_desc block_dev;
};
int fsg_init(struct ums *ums_devs, int count);
diff --git a/include/zfs_common.h b/include/zfs_common.h
index 3bd575e..bca3dff 100644
--- a/include/zfs_common.h
+++ b/include/zfs_common.h
@@ -63,7 +63,7 @@ enum zfs_errors {
struct zfs_filesystem {
/* Block Device Descriptor */
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
};
struct device_s {
@@ -98,7 +98,7 @@ int zfs_close(zfs_file_t);
int zfs_ls(device_t dev, const char *path,
int (*hook) (const char *, const struct zfs_dirhook_info *));
int zfs_devread(int sector, int byte_offset, int byte_len, char *buf);
-void zfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+void zfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info);
void zfs_unmount(struct zfs_data *data);
int lzjb_decompress(void *, void *, uint32_t, uint32_t);
#endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index b361a25..0cb255f 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -123,9 +123,10 @@ fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
if (sizep) {
*sizep = fdtdec_get_number(prop_size, ns);
- debug("addr=%08llx, size=%llx\n", (u64)addr, (u64)*sizep);
+ debug("addr=%08llx, size=%llx\n", (unsigned long long)addr,
+ (unsigned long long)*sizep);
} else {
- debug("addr=%08llx\n", (u64)addr);
+ debug("addr=%08llx\n", (unsigned long long)addr);
}
return addr;
diff --git a/lib/gunzip.c b/lib/gunzip.c
index da0c76c..6d65ccc 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -105,7 +105,7 @@ void gzwrite_progress_finish(int returnval,
}
int gzwrite(unsigned char *src, int len,
- struct block_dev_desc *dev,
+ struct blk_desc *dev,
unsigned long szwritebuf,
u64 startoffs,
u64 szexpected)
diff --git a/lib/tpm.c b/lib/tpm.c
index f428d45..88f2406 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -242,7 +242,7 @@ static uint32_t tpm_sendrecv_command(const void *command,
response_length = sizeof(response_buffer);
}
- ret = uclass_first_device(UCLASS_TPM, &dev);
+ ret = uclass_first_device_err(UCLASS_TPM, &dev);
if (ret)
return ret;
err = tpm_xfer(dev, command, tpm_command_size(command),
@@ -261,8 +261,8 @@ int tpm_init(void)
int err;
struct udevice *dev;
- err = uclass_first_device(UCLASS_TPM, &dev);
- if (err || !dev)
+ err = uclass_first_device_err(UCLASS_TPM, &dev);
+ if (err)
return err;
return tpm_open(dev);
}
diff --git a/test/dm/usb.c b/test/dm/usb.c
index 3a2e52b..b46ae60 100644
--- a/test/dm/usb.c
+++ b/test/dm/usb.c
@@ -39,19 +39,20 @@ DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
static int dm_test_usb_flash(struct unit_test_state *uts)
{
struct udevice *dev;
- block_dev_desc_t *dev_desc;
+ struct blk_desc *dev_desc;
char cmp[1024];
state_set_skip_delays(true);
ut_assertok(usb_init());
ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
- ut_assertok(get_device("usb", "0", &dev_desc));
+ ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc));
/* Read a few blocks and look for the string we expect */
ut_asserteq(512, dev_desc->blksz);
memset(cmp, '\0', sizeof(cmp));
- ut_asserteq(2, dev_desc->block_read(dev_desc, 0, 2, cmp));
+ ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp));
ut_assertok(strcmp(cmp, "this is a test"));
+ ut_assertok(usb_stop());
return 0;
}
@@ -67,6 +68,7 @@ static int dm_test_usb_multi(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 1, &dev));
ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev));
+ ut_assertok(usb_stop());
return 0;
}
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 8b3cd30..c2c54bf 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -101,7 +101,8 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
pager = os.getenv('PAGER')
if not pager:
pager = 'more'
- fname = os.path.join(os.path.dirname(sys.argv[0]), 'README')
+ fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
+ 'README')
command.Run(pager, fname)
return 0
diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index e33e105..7bcc0af 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -14,6 +14,8 @@ import urllib2
import bsettings
import command
+PRIORITY_CALC = 0
+
# Simple class to collect links from a page
class MyHTMLParser(HTMLParser):
def __init__(self, arch):
@@ -50,13 +52,18 @@ class Toolchain:
cross: Cross compile string, e.g. 'arm-linux-'
arch: Architecture of toolchain as determined from the first
component of the filename. E.g. arm-linux-gcc becomes arm
+ priority: Toolchain priority (0=highest, 20=lowest)
"""
- def __init__(self, fname, test, verbose=False):
+ def __init__(self, fname, test, verbose=False, priority=PRIORITY_CALC,
+ arch=None):
"""Create a new toolchain object.
Args:
fname: Filename of the gcc component
test: True to run the toolchain to test it
+ verbose: True to print out the information
+ priority: Priority to use for this toolchain, or PRIORITY_CALC to
+ calculate it
"""
self.gcc = fname
self.path = os.path.dirname(fname)
@@ -69,12 +76,19 @@ class Toolchain:
# The architecture is the first part of the name
pos = self.cross.find('-')
- self.arch = self.cross[:pos] if pos != -1 else 'sandbox'
+ if arch:
+ self.arch = arch
+ else:
+ self.arch = self.cross[:pos] if pos != -1 else 'sandbox'
env = self.MakeEnvironment(False)
# As a basic sanity check, run the C compiler with --version
cmd = [fname, '--version']
+ if priority == PRIORITY_CALC:
+ self.priority = self.GetPriority(fname)
+ else:
+ self.priority = priority
if test:
result = command.RunPipe([cmd], capture=True, env=env,
raise_on_error=False)
@@ -82,7 +96,8 @@ class Toolchain:
if verbose:
print 'Tool chain test: ',
if self.ok:
- print 'OK'
+ print "OK, arch='%s', priority %d" % (self.arch,
+ self.priority)
else:
print 'BAD'
print 'Command: ', cmd
@@ -90,7 +105,6 @@ class Toolchain:
print result.stderr
else:
self.ok = True
- self.priority = self.GetPriority(fname)
def GetPriority(self, fname):
"""Return the priority of the toolchain.
@@ -101,15 +115,15 @@ class Toolchain:
Args:
fname: Filename of toolchain
Returns:
- Priority of toolchain, 0=highest, 20=lowest.
+ Priority of toolchain, PRIORITY_CALC=highest, 20=lowest.
"""
priority_list = ['-elf', '-unknown-linux-gnu', '-linux',
'-none-linux-gnueabi', '-uclinux', '-none-eabi',
'-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux']
for prio in range(len(priority_list)):
if priority_list[prio] in fname:
- return prio
- return prio
+ return PRIORITY_CALC + prio
+ return PRIORITY_CALC + prio
def MakeEnvironment(self, full_path):
"""Returns an environment for using the toolchain.
@@ -155,8 +169,8 @@ class Toolchains:
"""
toolchains = bsettings.GetItems('toolchain')
if not toolchains:
- print ("Warning: No tool chains - please add a [toolchain] section"
- " to your buildman config file %s. See README for details" %
+ print ('Warning: No tool chains - please add a [toolchain] section'
+ ' to your buildman config file %s. See README for details' %
bsettings.config_fname)
paths = []
@@ -170,7 +184,8 @@ class Toolchains:
def GetSettings(self):
self.paths += self.GetPathList()
- def Add(self, fname, test=True, verbose=False):
+ def Add(self, fname, test=True, verbose=False, priority=PRIORITY_CALC,
+ arch=None):
"""Add a toolchain to our list
We select the given toolchain as our preferred one for its
@@ -179,14 +194,21 @@ class Toolchains:
Args:
fname: Filename of toolchain's gcc driver
test: True to run the toolchain to test it
+ priority: Priority to use for this toolchain
+ arch: Toolchain architecture, or None if not known
"""
- toolchain = Toolchain(fname, test, verbose)
+ toolchain = Toolchain(fname, test, verbose, priority, arch)
add_it = toolchain.ok
if toolchain.arch in self.toolchains:
add_it = (toolchain.priority <
self.toolchains[toolchain.arch].priority)
if add_it:
self.toolchains[toolchain.arch] = toolchain
+ elif verbose:
+ print ("Toolchain '%s' at priority %d will be ignored because "
+ "another toolchain for arch '%s' has priority %d" %
+ (toolchain.gcc, toolchain.priority, toolchain.arch,
+ self.toolchains[toolchain.arch].priority))
def ScanPath(self, path, verbose):
"""Scan a path for a valid toolchain
@@ -367,14 +389,14 @@ class Toolchains:
Full path to the downloaded archive file in that directory,
or None if there was an error while downloading
"""
- print "Downloading: %s" % url
+ print 'Downloading: %s' % url
leaf = url.split('/')[-1]
tmpdir = tempfile.mkdtemp('.buildman')
response = urllib2.urlopen(url)
fname = os.path.join(tmpdir, leaf)
fd = open(fname, 'wb')
meta = response.info()
- size = int(meta.getheaders("Content-Length")[0])
+ size = int(meta.getheaders('Content-Length')[0])
done = 0
block_size = 1 << 16
status = ''
@@ -388,7 +410,7 @@ class Toolchains:
done += len(buffer)
fd.write(buffer)
- status = r"%10d MiB [%3d%%]" % (done / 1024 / 1024,
+ status = r'%10d MiB [%3d%%]' % (done / 1024 / 1024,
done * 100 / size)
status = status + chr(8) * (len(status) + 1)
print status,
diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
index 67aa41a..8d3fef4 100644
--- a/tools/fdtgrep.c
+++ b/tools/fdtgrep.c
@@ -660,6 +660,8 @@ static int fdtgrep_find_regions(const void *fdt,
if (!ret)
count++;
}
+ if (ret && ret != -FDT_ERR_NOTFOUND)
+ return ret;
/* Find all the aliases and add those regions back in */
if (disp->add_aliases && count < max_regions) {
@@ -667,7 +669,11 @@ static int fdtgrep_find_regions(const void *fdt,
new_count = fdt_add_alias_regions(fdt, region, count,
max_regions, &state);
- if (new_count <= max_regions) {
+ if (new_count == -FDT_ERR_NOTFOUND) {
+ /* No alias node found */
+ } else if (new_count < 0) {
+ return new_count;
+ } else if (new_count <= max_regions) {
/*
* The alias regions will now be at the end of the list.
* Sort the regions by offset to get things into the
@@ -679,9 +685,6 @@ static int fdtgrep_find_regions(const void *fdt,
}
}
- if (ret != -FDT_ERR_NOTFOUND)
- return ret;
-
return count;
}
@@ -807,6 +810,9 @@ static int do_fdtgrep(struct display_info *disp, const char *filename)
disp->flags);
if (count < 0) {
report_error("fdt_find_regions", count);
+ if (count == -FDT_ERR_BADLAYOUT)
+ fprintf(stderr,
+ "/aliases node must come before all other nodes\n");
return -1;
}
if (count <= max_regions)
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index 6d3c41f..27d031e 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -376,7 +376,7 @@ def GetMetaDataForList(commit_range, git_dir=None, count=None,
if not series:
series = Series()
series.allow_overwrite = allow_overwrite
- params = gitutil.LogCmd(commit_range,reverse=True, count=count,
+ params = gitutil.LogCmd(commit_range, reverse=True, count=count,
git_dir=git_dir)
stdout = command.RunPipe([params], capture=True).stdout
ps = PatchStream(series, is_log=True)
diff --git a/tools/patman/patman.py b/tools/patman/patman.py
index d05c5ff..fe50eb4 100755
--- a/tools/patman/patman.py
+++ b/tools/patman/patman.py
@@ -117,7 +117,8 @@ elif options.full_help:
pager = os.getenv('PAGER')
if not pager:
pager = 'more'
- fname = os.path.join(os.path.dirname(sys.argv[0]), 'README')
+ fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
+ 'README')
command.Run(pager, fname)
# Process commits, produce patches files, check them, email them