From 5fe7702eccf1bae5b10f0309cef03e02bfdfa6ef Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 9 Jun 2017 16:45:18 +0200 Subject: blk: dm: make blk_create_device() take a number of block instead of a size There is an overflow problem when taking the size instead of the number of blocks in blk_create_device(). This results in a wrong device size: the device apparent size is its real size modulo 4GB. Using the number of blocks instead of the device size fixes the problem and is more coherent with the internals of the block layer. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Simon Glass --- drivers/block/blk-uclass.c | 8 ++++---- drivers/block/sandbox.c | 2 +- drivers/scsi/scsi.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 3c5a87b60a..aee2a50d62 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -546,7 +546,7 @@ static int blk_claim_devnum(enum if_type if_type, int devnum) 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) + lbaint_t lba, struct udevice **devp) { struct blk_desc *desc; struct udevice *dev; @@ -567,7 +567,7 @@ int blk_create_device(struct udevice *parent, const char *drv_name, desc = dev_get_uclass_platdata(dev); desc->if_type = if_type; desc->blksz = blksz; - desc->lba = size / blksz; + desc->lba = lba; desc->part_type = PART_TYPE_UNKNOWN; desc->bdev = dev; desc->devnum = devnum; @@ -578,7 +578,7 @@ int blk_create_device(struct udevice *parent, const char *drv_name, int blk_create_devicef(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, - lbaint_t size, struct udevice **devp) + lbaint_t lba, struct udevice **devp) { char dev_name[30], *str; int ret; @@ -589,7 +589,7 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name, return -ENOMEM; ret = blk_create_device(parent, drv_name, str, if_type, devnum, - blksz, size, devp); + blksz, lba, devp); if (ret) { free(str); return ret; diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c index 34d1c638bc..98df6b33b6 100644 --- a/drivers/block/sandbox.c +++ b/drivers/block/sandbox.c @@ -129,7 +129,7 @@ int host_dev_bind(int devnum, char *filename) } ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str, IF_TYPE_HOST, devnum, 512, - os_lseek(fd, 0, OS_SEEK_END), &dev); + os_lseek(fd, 0, OS_SEEK_END) / 512, &dev); if (ret) goto err_file; ret = device_probe(dev); diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 1a65a3f9b9..df998921f5 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -580,7 +580,7 @@ static int do_scsi_scan_one(struct udevice *dev, int id, int lun, bool verbose) */ snprintf(str, sizeof(str), "id%dlun%d", id, lun); ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1, - bd.blksz, bd.blksz * bd.lba, &bdev); + bd.blksz, bd.lba, &bdev); if (ret) { debug("Can't create device\n"); return ret; -- cgit From a0f9acb08bd6f3b4a6f3adcb02c8170e522c074a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 2 Aug 2017 12:12:01 -0600 Subject: dm: core: Drop use of strlcpy() We can use printf() to limit the string width. Adjust the code to do this instead of using strlcpy() which is a bit clumbsy. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- drivers/core/dump.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/core/dump.c b/drivers/core/dump.c index c3e109e7ed..1bb64098f4 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -14,11 +14,9 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) { int i, is_last; struct udevice *child; - char class_name[12]; /* print the first 11 characters to not break the tree-format. */ - strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name)); - printf(" %-11s [ %c ] ", class_name, + printf(" %-10.10s [ %c ] ", dev->uclass->uc_drv->name, dev->flags & DM_FLAG_ACTIVATED ? '+' : ' '); for (i = depth; i >= 0; i--) { @@ -50,7 +48,7 @@ void dm_dump_all(void) root = dm_root(); if (root) { - printf(" Class Probed Name\n"); + printf(" Class Probed Name\n"); printf("----------------------------------------\n"); show_devices(root, -1, 0); } -- cgit From ee3e520dad0b368df4541cd0af0d4011cf481e5b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 2 Aug 2017 12:12:02 -0600 Subject: dm: core: Show driver name with 'dm tree' It is often useful to see which driver was actually selected for each device. Add a new 'Driver' column to provide this information. Sample output: Class Probed Driver Name ---------------------------------------- root [ + ] root_drive root_driver keyboard [ + ] i8042_kbd |-- keyboard serial [ + ] ns16550_se |-- serial rtc [ ] rtc_mc1468 |-- rtc timer [ + ] tsc_timer |-- tsc-timer syscon [ + ] ich6_pinct |-- pch_pinctrl pci [ + ] pci_x86 |-- pci northbridge [ + ] bd82x6x_no | |-- northbridge@0,0 video [ + ] bd82x6x_vi | |-- gma@2,0 vidconsole0 [ + ] vidconsole | | `-- gma@2,0.vidconsole0 ... Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- drivers/core/dump.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 1bb64098f4..6c6b944453 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -16,8 +16,8 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) struct udevice *child; /* print the first 11 characters to not break the tree-format. */ - printf(" %-10.10s [ %c ] ", dev->uclass->uc_drv->name, - dev->flags & DM_FLAG_ACTIVATED ? '+' : ' '); + printf(" %-10.10s [ %c ] %-10.10s ", dev->uclass->uc_drv->name, + dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); for (i = depth; i >= 0; i--) { is_last = (last_flag >> i) & 1; @@ -48,7 +48,7 @@ void dm_dump_all(void) root = dm_root(); if (root) { - printf(" Class Probed Name\n"); + printf(" Class Probed Driver Name\n"); printf("----------------------------------------\n"); show_devices(root, -1, 0); } -- cgit From 3991f42ed2e38aff28ba3c24369bfbd90620bea7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 5 Aug 2017 15:45:54 -0600 Subject: dm: core: Add ofnode_for_each_subnode() Add a convenience macro to iterate over subnodes of a node. Make use of this where appropriate in the code. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 9 +++++---- drivers/misc/cros_ec.c | 3 +-- drivers/power/pmic/pmic-uclass.c | 4 +--- 3 files changed, 7 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 0685b689d8..c6ca13fabf 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -390,10 +390,11 @@ int ofnode_decode_display_timing(ofnode parent, int index, if (!ofnode_valid(timings)) return -EINVAL; - for (i = 0, node = ofnode_first_subnode(timings); - ofnode_valid(node) && i != index; - node = ofnode_first_subnode(node)) - i++; + i = 0; + ofnode_for_each_subnode(node, timings) { + if (i++ == index) + break; + } if (!ofnode_valid(node)) return -EINVAL; diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index feaa5d8567..eefaaa53ad 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1038,8 +1038,7 @@ int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config) config->flash_erase_value = ofnode_read_s32_default(flash_node, "erase-value", -1); - for (node = ofnode_first_subnode(flash_node); ofnode_valid(node); - node = ofnode_next_subnode(node)) { + ofnode_for_each_subnode(node, flash_node) { const char *name = ofnode_get_name(node); enum ec_flash_region region; diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c index 953bbe5026..64964e4e96 100644 --- a/drivers/power/pmic/pmic-uclass.c +++ b/drivers/power/pmic/pmic-uclass.c @@ -34,9 +34,7 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent, debug("%s for '%s' at node offset: %d\n", __func__, pmic->name, dev_of_offset(pmic)); - for (node = ofnode_first_subnode(parent); - ofnode_valid(node); - node = ofnode_next_subnode(node)) { + ofnode_for_each_subnode(node, parent) { node_name = ofnode_get_name(node); debug("* Found child node: '%s'\n", node_name); -- cgit From e81c98649b7a67d43c5baae407430a242d3b26b9 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Mon, 4 Sep 2017 14:55:56 +0200 Subject: dm: core: add clocks node scan Currently, all fixed-clock declared in "clocks" node in device tree can be binded by clk_fixed_rate.c driver only if each of them have the "simple-bus" compatible string. This constraint has been invoked here [1]. This patch offers a solution to avoid adding "simple-bus" compatible string to nodes that are not busses. [1] https://patchwork.ozlabs.org/patch/558837/ Signed-off-by: Patrice Chotard Reviewed-by: Simon Glass --- drivers/core/root.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/core/root.c b/drivers/core/root.c index d691d6ff94..757d109e57 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -312,8 +312,38 @@ int dm_scan_fdt(const void *blob, bool pre_reloc_only) #endif return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only); } +#else +static int dm_scan_fdt_node(struct udevice *parent, const void *blob, + int offset, bool pre_reloc_only) +{ + return 0; +} #endif +int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only) +{ + int node, ret; + + ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); + if (ret) { + debug("dm_scan_fdt() failed: %d\n", ret); + return ret; + } + + /* bind fixed-clock */ + node = ofnode_to_offset(ofnode_path("/clocks")); + /* if no DT "clocks" node, no need to go further */ + if (node < 0) + return ret; + + ret = dm_scan_fdt_node(gd->dm_root, gd->fdt_blob, node, + pre_reloc_only); + if (ret) + debug("dm_scan_fdt_node() failed: %d\n", ret); + + return ret; +} + __weak int dm_scan_other(bool pre_reloc_only) { return 0; @@ -335,9 +365,9 @@ int dm_init_and_scan(bool pre_reloc_only) } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { - ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); + ret = dm_extended_scan_fdt(gd->fdt_blob, pre_reloc_only); if (ret) { - debug("dm_scan_fdt() failed: %d\n", ret); + debug("dm_extended_scan_dt() failed: %d\n", ret); return ret; } } -- cgit