From 9102efae6ab7d8ee2607b842f2cdf6cbffaadb86 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 11 Jan 2019 21:58:14 -0800 Subject: block: Alias block_op_close() to block_op_flush() The two functions are identical, so there's no need to keep two copies of the same code around. Alias block_op_close() to block_op_flush() and drop standalone definition for the former. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/block.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'common') diff --git a/common/block.c b/common/block.c index 8d0de42d90..549df71a9d 100644 --- a/common/block.c +++ b/common/block.c @@ -329,13 +329,6 @@ static ssize_t block_op_write(struct cdev *cdev, const void *buf, size_t count, } #endif -static int block_op_close(struct cdev *cdev) -{ - struct block_device *blk = cdev->priv; - - return writebuffer_flush(blk); -} - static int block_op_flush(struct cdev *cdev) { struct block_device *blk = cdev->priv; @@ -343,6 +336,8 @@ static int block_op_flush(struct cdev *cdev) return writebuffer_flush(blk); } +static int block_op_close(struct cdev *cdev) __alias(block_op_flush); + static struct cdev_operations block_ops = { .read = block_op_read, #ifdef CONFIG_BLOCK_WRITE -- cgit v1.2.3 From c19b36aeb723493489ed84930824b65712906dae Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 11 Jan 2019 21:58:15 -0800 Subject: block: Replace debug() with dev_dbg() All of the functions using debug() in that file have enough info to use dev_dbg instead. Convert all of the uses of debug() to dev_dbg() in order to get more informative debug output. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/block.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/block.c b/common/block.c index 549df71a9d..35173c65f1 100644 --- a/common/block.c +++ b/common/block.c @@ -76,7 +76,8 @@ static struct chunk *chunk_get_cached(struct block_device *blk, int block) list_for_each_entry(chunk, &blk->buffered_blocks, list) { if (block >= chunk->block_start && block < chunk->block_start + blk->rdbufsize) { - debug("%s: found %d in %d\n", __func__, block, chunk->num); + dev_dbg(blk->dev, "%s: found %d in %d\n", __func__, + block, chunk->num); /* * move most recently used entry to the head of the list */ @@ -153,8 +154,8 @@ static int block_cache(struct block_device *blk, int block) chunk->block_start = block & ~blk->blkmask; - debug("%s: %d to %d\n", __func__, chunk->block_start, - chunk->num); + dev_dbg(blk->dev, "%s: %d to %d\n", __func__, chunk->block_start, + chunk->num); num_blocks = min(blk->rdbufsize, blk->num_blocks - chunk->block_start); @@ -364,8 +365,8 @@ int blockdevice_register(struct block_device *blk) INIT_LIST_HEAD(&blk->idle_blocks); blk->blkmask = blk->rdbufsize - 1; - debug("%s: rdbufsize: %d blockbits: %d blkmask: 0x%08x\n", __func__, blk->rdbufsize, blk->blockbits, - blk->blkmask); + dev_dbg(blk->dev, "rdbufsize: %d blockbits: %d blkmask: 0x%08x\n", + blk->rdbufsize, blk->blockbits, blk->blkmask); for (i = 0; i < 32; i++) { struct chunk *chunk = xzalloc(sizeof(*chunk)); -- cgit v1.2.3 From 167c14cc36e00314341492941b3d41506b53bf22 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sun, 20 Jan 2019 09:23:52 +0300 Subject: treewide: Remove trailing whitespaces and tabs Just a cleanup over barebox tree Signed-off-by: Alexander Shiyan Signed-off-by: Sascha Hauer --- arch/arm/boards/nxp-imx8mq-evk/ddr_init.c | 4 ++-- arch/arm/mach-imx/include/mach/iomux-mx8.h | 2 +- arch/arm/mach-mvebu/armada-370-xp.c | 6 +++--- common/image-fit.c | 2 +- drivers/clk/imx/clk-imx7.c | 2 +- drivers/efi/efi-device.c | 2 +- drivers/pci/pcie-designware-host.c | 2 +- fs/cramfs/cramfs.c | 2 +- scripts/kconfig/gconf.c | 2 +- scripts/socfpga_mkimage.c | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) (limited to 'common') diff --git a/arch/arm/boards/nxp-imx8mq-evk/ddr_init.c b/arch/arm/boards/nxp-imx8mq-evk/ddr_init.c index 44103b5e26..39addea973 100644 --- a/arch/arm/boards/nxp-imx8mq-evk/ddr_init.c +++ b/arch/arm/boards/nxp-imx8mq-evk/ddr_init.c @@ -12,7 +12,7 @@ void ddr_cfg_phy(void); void ddr_init(void) { volatile unsigned int tmp, tmp_t; - + /** Initialize DDR clock and DDRC registers **/ reg32_write(0x3038a088,0x7070000); reg32_write(0x3038a084,0x4030000); @@ -177,7 +177,7 @@ void ddr_init(void) reg32_write(DDRC_SWCTL(0), 0x0000); /* * ------------------- 9 ------------------- - * Set DFIMISC.dfi_init_start to 1 + * Set DFIMISC.dfi_init_start to 1 * ----------------------------------------- */ reg32_write(DDRC_DFIMISC(0), 0x00000030); diff --git a/arch/arm/mach-imx/include/mach/iomux-mx8.h b/arch/arm/mach-imx/include/mach/iomux-mx8.h index 1caa2235b1..9660697d96 100644 --- a/arch/arm/mach-imx/include/mach/iomux-mx8.h +++ b/arch/arm/mach-imx/include/mach/iomux-mx8.h @@ -163,7 +163,7 @@ enum { IMX8MQ_PAD_SD1_DATA5__USDHC1_DATA5 = IOMUX_PAD(0x0324, 0x00BC, 0, 0x0000, 0, 0), IMX8MQ_PAD_SD1_DATA5__GPIO2_IO7 = IOMUX_PAD(0x0324, 0x00BC, 5, 0x0000, 0, 0), - IMX8MQ_PAD_SD1_DATA6__USDHC1_DATA6 = IOMUX_PAD(0x0328, 0x00C0, 0, 0x0000, 0, 0), + IMX8MQ_PAD_SD1_DATA6__USDHC1_DATA6 = IOMUX_PAD(0x0328, 0x00C0, 0, 0x0000, 0, 0), IMX8MQ_PAD_SD1_DATA6__GPIO2_IO8 = IOMUX_PAD(0x0328, 0x00C0, 5, 0x0000, 0, 0), IMX8MQ_PAD_SD1_DATA7__USDHC1_DATA7 = IOMUX_PAD(0x032C, 0x00C4, 0, 0x0000, 0, 0), diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c index 0612830025..2589f4fe72 100644 --- a/arch/arm/mach-mvebu/armada-370-xp.c +++ b/arch/arm/mach-mvebu/armada-370-xp.c @@ -105,12 +105,12 @@ static void setup_usb_phys(void) /* Power up PLL and PHY channel */ setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9)); - + /* Assert VCOCAL_START */ setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21)); - + mdelay(1); - + /* * USB PHY init (change from defaults) specific for 40nm (78X30 78X60) */ diff --git a/common/image-fit.c b/common/image-fit.c index 87a55b7e27..6ac4644686 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -368,7 +368,7 @@ static int fit_verify_signature(struct device_node *sig_node, const void *fit) out_sl: string_list_free(&inc_nodes); string_list_free(&exc_props); - + return ret; } diff --git a/drivers/clk/imx/clk-imx7.c b/drivers/clk/imx/clk-imx7.c index 97fe7abda2..781bc43e09 100644 --- a/drivers/clk/imx/clk-imx7.c +++ b/drivers/clk/imx/clk-imx7.c @@ -743,7 +743,7 @@ static int imx7_ccm_probe(struct device_d *dev) "enet_axi_post_div", base + 0x4700, 0); clks[IMX7D_ENET1_TIME_ROOT_CLK] = imx_clk_gate2_shared2("enet1_time_root_clk", "enet1_time_post_div", base + 0x4700, 0); - clks[IMX7D_ENET2_IPG_ROOT_CLK] = imx_clk_gate2_shared2("enet2_ipg_root_clk", + clks[IMX7D_ENET2_IPG_ROOT_CLK] = imx_clk_gate2_shared2("enet2_ipg_root_clk", "enet_axi_post_div", base + 0x4710, 0); clks[IMX7D_ENET2_TIME_ROOT_CLK] = imx_clk_gate2_shared2("enet2_time_root_clk", "enet2_time_post_div", base + 0x4710, 0); diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c index b7dea7c822..5cc68fb781 100644 --- a/drivers/efi/efi-device.c +++ b/drivers/efi/efi-device.c @@ -551,7 +551,7 @@ static int do_efi_protocol_dump(int argc, char **argv) if (len != 36) return -EINVAL; - + read_xbit(s, a, 32); if (*s != '-') return -EINVAL; diff --git a/drivers/pci/pcie-designware-host.c b/drivers/pci/pcie-designware-host.c index 6cc4b93a31..cc6a41be0c 100644 --- a/drivers/pci/pcie-designware-host.c +++ b/drivers/pci/pcie-designware-host.c @@ -391,7 +391,7 @@ void dw_pcie_setup_rc(struct pcie_port *pp) pci->iatu_unroll_enabled = dw_pcie_iatu_unroll_enabled(pci); dev_dbg(pci->dev, "iATU unroll: %s\n", pci->iatu_unroll_enabled ? "enabled" : "disabled"); - + dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0, PCIE_ATU_TYPE_MEM, pp->mem_mod_base, pp->mem_bus_addr, pp->mem_size); diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c index a3ce354c92..093657f62c 100644 --- a/fs/cramfs/cramfs.c +++ b/fs/cramfs/cramfs.c @@ -335,7 +335,7 @@ static struct inode *cramfs_alloc_inode(struct super_block *sb) struct cramfs_inode_info *info; info = xzalloc(sizeof(*info)); - + return &info->i_inode; } diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c index 36f578415c..0ac700bf12 100644 --- a/scripts/kconfig/gconf.c +++ b/scripts/kconfig/gconf.c @@ -640,7 +640,7 @@ on_set_option_mode3_activate(GtkMenuItem *menuitem, gpointer user_data) void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data) { GtkWidget *dialog; - const gchar *intro_text = + const gchar *intro_text = "Welcome to gkc, the GTK+ graphical configuration tool\n" "For each option, a blank box indicates the feature is disabled, a\n" "check indicates it is enabled, and a dot indicates that it is to\n" diff --git a/scripts/socfpga_mkimage.c b/scripts/socfpga_mkimage.c index fedcfb5b6f..03150cce8d 100644 --- a/scripts/socfpga_mkimage.c +++ b/scripts/socfpga_mkimage.c @@ -157,7 +157,7 @@ uint32_t crc32(uint32_t crc, void *_buf, int length) return crc; } -/* Create an ARM relative branch instuction +/* Create an ARM relative branch instuction * branch is where the instruction will be placed and dest points to where * it should branch too. */ static void branch(uint8_t *branch, uint8_t *dest) -- cgit v1.2.3 From 662ff5a3558e81e3f15678acb7999669c03ac75e Mon Sep 17 00:00:00 2001 From: Vivien Didelot Date: Fri, 18 Jan 2019 19:50:51 -0500 Subject: boot: make it a little bit less verbose The current boot code prints too much error messages without much value in them. This patch prints the error string when it makes sense and simplifies the return path of bootscript_boot(). Make use of pr_err() in boot_entry() which is the shared code responsible for calling the boot_entry->boot callback. Remove the unnecessary print statement from bootsource_action() as well. This removes a single print statement ATM, allowing us to go from this: booting 'sd' Cannot set parameter mci0.probe: No such device running automount command 'mci${global.sd}.probe=1 && mount /dev/disk${global.sd}.0 /mnt/sd' failed could not open /mnt/sd/zImage: No such device ERROR: Booting 'sd' failed: No such device booting 'sd' failed: No such device boot: No such device to this: Booting entry 'sd' Cannot set parameter mci0.probe: No such device running automount command 'mci${global.sd}.probe=1 && mount /dev/disk${global.sd}.0 /mnt/sd' failed could not open /mnt/sd/zImage: No such device ERROR: Booting entry 'sd' failed boot: No such device Signed-off-by: Vivien Didelot Signed-off-by: Sascha Hauer --- common/boot.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'common') diff --git a/common/boot.c b/common/boot.c index 41bf1ce64b..974eaf5d02 100644 --- a/common/boot.c +++ b/common/boot.c @@ -96,8 +96,8 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun) ret = run_command(bs->scriptpath); if (ret) { - printf("Running %s failed\n", bs->scriptpath); - goto out; + pr_err("Running script '%s' failed: %s\n", bs->scriptpath, strerror(-ret)); + return ret; } bootm_data_init_defaults(&data); @@ -107,11 +107,7 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun) if (dryrun) data.dryrun = dryrun; - ret = bootm_boot(&data); - if (ret) - pr_err("Booting '%s' failed: %s\n", basename(bs->scriptpath), strerror(-ret)); -out: - return ret; + return bootm_boot(&data); } static unsigned int boot_watchdog_timeout; @@ -135,7 +131,7 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun) { int ret; - printf("booting '%s'\n", be->title); + printf("Booting entry '%s'\n", be->title); if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) { ret = watchdog_set_timeout(boot_watchdog_timeout); @@ -144,9 +140,8 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun) } ret = be->boot(be, verbose, dryrun); - if (ret) - printf("booting '%s' failed: %s\n", be->title, strerror(-ret)); + pr_err("Booting entry '%s' failed\n", be->title); return ret; } @@ -154,11 +149,8 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun) static void bootsource_action(struct menu *m, struct menu_entry *me) { struct bootentry *be = container_of(me, struct bootentry, me); - int ret; - ret = boot_entry(be, 0, 0); - if (ret) - printf("Booting failed with: %s\n", strerror(-ret)); + boot_entry(be, 0, 0); printf("Press any key to continue\n"); -- cgit v1.2.3 From 17c4b989a5d00fe5fc84c528bbd59583c45d80d0 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 21 Jan 2019 22:06:24 -0800 Subject: block: Do not write past block device boundary during a flush When calling I/O functions of underlying block device driver we always need to make sure that its size is small enough to not go past device's boundary. Not only in get_chunk() and block_cache(), but in writebuffer_flush() as well. Since the same code is used in three different places, move it into a subroutine and adjust all of the calls to ->write()/->read() accordingly. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/block.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/block.c b/common/block.c index 35173c65f1..3a031a4fc7 100644 --- a/common/block.c +++ b/common/block.c @@ -38,6 +38,11 @@ struct chunk { #define BUFSIZE (PAGE_SIZE * 4) +static int writebuffer_io_len(struct block_device *blk, struct chunk *chunk) +{ + return min(blk->rdbufsize, blk->num_blocks - chunk->block_start); +} + /* * Write all dirty chunks back to the device */ @@ -51,7 +56,9 @@ static int writebuffer_flush(struct block_device *blk) list_for_each_entry(chunk, &blk->buffered_blocks, list) { if (chunk->dirty) { - ret = blk->ops->write(blk, chunk->data, chunk->block_start, blk->rdbufsize); + ret = blk->ops->write(blk, chunk->data, + chunk->block_start, + writebuffer_io_len(blk, chunk)); if (ret < 0) return ret; @@ -118,10 +125,9 @@ static struct chunk *get_chunk(struct block_device *blk) /* use last entry which is the most unused */ chunk = list_last_entry(&blk->buffered_blocks, struct chunk, list); if (chunk->dirty) { - size_t num_blocks = min(blk->rdbufsize, - blk->num_blocks - chunk->block_start); - ret = blk->ops->write(blk, chunk->data, chunk->block_start, - num_blocks); + ret = blk->ops->write(blk, chunk->data, + chunk->block_start, + writebuffer_io_len(blk, chunk)); if (ret < 0) return ERR_PTR(ret); @@ -145,7 +151,6 @@ static struct chunk *get_chunk(struct block_device *blk) static int block_cache(struct block_device *blk, int block) { struct chunk *chunk; - size_t num_blocks; int ret; chunk = get_chunk(blk); @@ -157,9 +162,8 @@ static int block_cache(struct block_device *blk, int block) dev_dbg(blk->dev, "%s: %d to %d\n", __func__, chunk->block_start, chunk->num); - num_blocks = min(blk->rdbufsize, blk->num_blocks - chunk->block_start); - - ret = blk->ops->read(blk, chunk->data, chunk->block_start, num_blocks); + ret = blk->ops->read(blk, chunk->data, chunk->block_start, + writebuffer_io_len(blk, chunk)); if (ret) { list_add_tail(&chunk->list, &blk->idle_blocks); return ret; -- cgit v1.2.3 From f24245742636ef9996aae66e92244aed659b7d72 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 21 Jan 2019 22:06:25 -0800 Subject: block: Move shared code in get_chunk() out of if statement Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/block.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/block.c b/common/block.c index 3a031a4fc7..2917218762 100644 --- a/common/block.c +++ b/common/block.c @@ -133,13 +133,12 @@ static struct chunk *get_chunk(struct block_device *blk) chunk->dirty = 0; } - - list_del(&chunk->list); } else { chunk = list_first_entry(&blk->idle_blocks, struct chunk, list); - list_del(&chunk->list); } + list_del(&chunk->list); + return chunk; } -- cgit v1.2.3 From 75df7ff694572cdc1380b045bab3c56f9f2b671b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 28 Jan 2019 12:05:15 +0100 Subject: usb: fastboot: ubiformat: Fix bad block handling When fastboot handles UBI images in sparse file format then bad blocks of the underlying mtd device are not skipped. This patch fixes this. Signed-off-by: Sascha Hauer --- common/ubiformat.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'common') diff --git a/common/ubiformat.c b/common/ubiformat.c index 0811525bd2..1968bd98f8 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -710,8 +710,10 @@ int ubiformat_write(struct mtd_info *mtd, const void *buf, size_t count, loff_t offset) { int writesize = mtd->writesize >> mtd->subpage_sft; - size_t retlen; int ret; + int peb = 0; + int n_skip_blocks = mtd_div_by_eb(offset, mtd); + int offset_in_peb = mtd_mod_by_eb(offset, mtd); if (offset & (mtd->writesize - 1)) return -EINVAL; @@ -719,27 +721,44 @@ int ubiformat_write(struct mtd_info *mtd, const void *buf, size_t count, if (count & (mtd->writesize - 1)) return -EINVAL; + /* Seek forward to the first PEB we actually want to write */ + while (1) { + ret = mtd_skip_bad(mtd, &peb); + if (ret) + return ret; + + if (!n_skip_blocks) + break; + + peb++; + n_skip_blocks--; + } + while (count) { - size_t now; + size_t now = mtd->erasesize - offset_in_peb; - now = ALIGN(offset, mtd->erasesize) - offset; if (now > count) now = count; - if (!now) { + if (!offset_in_peb) { const struct ubi_ec_hdr *ec = buf; const struct ubi_vid_hdr *vid; + ret = mtd_skip_bad(mtd, &peb); + if (ret) + return ret; + if (be32_to_cpu(ec->magic) != UBI_EC_HDR_MAGIC) { pr_err("bad UBI magic %#08x, should be %#08x", be32_to_cpu(ec->magic), UBI_EC_HDR_MAGIC); return -EINVAL; } - /* skip ec header */ - offset += writesize; + /* skip ec header in both flash and image */ + offset_in_peb = writesize; buf += writesize; count -= writesize; + now -= writesize; if (!count) break; @@ -750,19 +769,16 @@ int ubiformat_write(struct mtd_info *mtd, const void *buf, size_t count, be32_to_cpu(vid->magic), UBI_VID_HDR_MAGIC); return -EINVAL; } - - continue; } - ret = mtd_write(mtd, offset, now, &retlen, buf); + ret = mtd_peb_write(mtd, buf, peb, offset_in_peb, now); if (ret < 0) return ret; - if (retlen != now) - return -EIO; buf += now; count -= now; - offset += now; + offset_in_peb = 0; + peb++; } return 0; -- cgit v1.2.3 From 69b16bcc850c9eef0f399f531d0b0cfdacb9b4e4 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Wed, 6 Feb 2019 11:34:02 +0100 Subject: common: state: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_format_raw.c | 4 ++-- common/state/state.c | 2 +- common/state/state.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c index 4369f76e37..5a71149d34 100644 --- a/common/state/backend_format_raw.c +++ b/common/state/backend_format_raw.c @@ -127,7 +127,7 @@ static int backend_format_raw_verify(struct state_backend_format *format, return -EINVAL; } - if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTIFICATION)) { + if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTICATION)) { ret = backend_raw_digest_init(backend_raw); if (ret) return ret; @@ -153,7 +153,7 @@ static int backend_format_raw_verify(struct state_backend_format *format, *lenp = header->data_len + sizeof(*header); - if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTIFICATION)) { + if (backend_raw->algo && !(flags & STATE_FLAG_NO_AUTHENTICATION)) { const void *hmac = data + header->data_len; /* hmac over header and data */ diff --git a/common/state/state.c b/common/state/state.c index 54c57232e6..d3e048b990 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -128,7 +128,7 @@ int state_load(struct state *state) int state_load_no_auth(struct state *state) { - return state_do_load(state, STATE_FLAG_NO_AUTHENTIFICATION); + return state_do_load(state, STATE_FLAG_NO_AUTHENTICATION); } static int state_format_init(struct state *state, const char *backend_format, diff --git a/common/state/state.h b/common/state/state.h index 3a0662fd25..912d6d4848 100644 --- a/common/state/state.h +++ b/common/state/state.h @@ -6,7 +6,7 @@ struct state; struct mtd_info_user; enum state_flags { - STATE_FLAG_NO_AUTHENTIFICATION = (1 << 0), + STATE_FLAG_NO_AUTHENTICATION = (1 << 0), }; enum state_variable_type { -- cgit v1.2.3 From b34b27edaea649b22d17c9be8d8d9f0b0b077471 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:20 +0100 Subject: common: state: fix compiler warnings about wrong type conversion in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To harmonize the common codebase this ports the remaining hunks of the following dt-utils commit, as the residual hunks have independently already been done before in barebox commit 1afbf6b5680e ("state: fix compile warnings for dev_err expansion"): | commit 9f1db73234b40f4ea071421e8179065df16211ec | Author: Philipp Rosenberger | Date: Thu Oct 18 09:17:23 2018 +0200 | | Fix compiler warnings about wrong type conversion in messages. | | These warning were observed with gcc-6.3 on x86-64. | | Signed-off-by: Philipp Rosenberger | Signed-off-by: Sascha Hauer Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'common') diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 4b71d8751d..5a85650f40 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -165,13 +165,13 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ return ret; } - dev_dbg(circ->dev, "Read state from %ld length %zd\n", offset, + dev_dbg(circ->dev, "Read state from %ld length %d\n", offset, len); ret = read_full(circ->fd, buf, len); if (ret < 0) { - dev_err(circ->dev, "Failed to read circular storage len %zd, %d\n", + dev_err(circ->dev, "Failed to read circular storage len %d, %d\n", len, ret); free(buf); } @@ -196,7 +196,7 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir ret = write_full(circ->fd, buf, len); if (ret < 0) { - dev_err(circ->dev, "Failed to write circular to %ld length %zd, %d\n", + dev_err(circ->dev, "Failed to write circular to %ld length %d, %d\n", offset, len, ret); return ret; } @@ -207,7 +207,7 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir */ flush(circ->fd); - dev_dbg(circ->dev, "Written state to offset %ld length %zd data length %zd\n", + dev_dbg(circ->dev, "Written state to offset %ld length %d data length %d\n", offset, len, len); return 0; @@ -298,7 +298,7 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck void *write_buf; if (written_length > circ->max_size) { - dev_err(circ->dev, "Error, state data too big to be written, to write: %zd, writesize: %zd, length: %zd, available: %zd\n", + dev_err(circ->dev, "Error, state data too big to be written, to write: %d, writesize: %zd, length: %zd, available: %zd\n", written_length, circ->writesize, len, circ->max_size); return -E2BIG; } @@ -345,12 +345,12 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck ret = state_mtd_peb_write(circ, write_buf, offset, written_length); if (ret < 0 && ret != -EUCLEAN) { - dev_err(circ->dev, "Failed to write circular to %ld length %zd, %d\n", + dev_err(circ->dev, "Failed to write circular to %ld length %d, %d\n", offset, written_length, ret); goto out_free; } - dev_dbg(circ->dev, "Written state to PEB %u offset %ld length %zd data length %zd\n", + dev_dbg(circ->dev, "Written state to PEB %u offset %ld length %d data length %zd\n", circ->eraseblock, offset, written_length, len); out_free: -- cgit v1.2.3 From 0019513c41b0641c6582668f0356663a65ad36d4 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:21 +0100 Subject: common: state: fix formatting of "off_t" variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To harmonize the common codebase this ports the following dt-utils commit: | commit 89d033284cb69f834c1f2195c9e99a3d7f585cf1 | Author: Ulrich Ölmann | Date: Sun Feb 3 22:48:06 2019 +0100 | | state: fix formatting of "off_t" variables | | Explicitely casting an "off_t" variable to "long long" and formatting it via | "%lld" or "%llx" respectively makes 32- as well as 64-bit compilers | happy (tested with gcc-8.2.1 and clang-7.0.1). | | Signed-off-by: Ulrich Ölmann | Signed-off-by: Roland Hieber Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 32 ++++++++++++++++---------------- common/state/backend_storage.c | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'common') diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 5a85650f40..ae15fa2529 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -161,11 +161,11 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ ret = lseek(circ->fd, offset, SEEK_SET); if (ret < 0) { dev_err(circ->dev, "Failed to set circular read position to %lld, %d\n", - offset, ret); + (long long) offset, ret); return ret; } - dev_dbg(circ->dev, "Read state from %ld length %d\n", offset, + dev_dbg(circ->dev, "Read state from %lld length %d\n", (long long) offset, len); @@ -189,15 +189,15 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir ret = lseek(circ->fd, offset, SEEK_SET); if (ret < 0) { - dev_err(circ->dev, "Failed to set position for circular write %ld, %d\n", - offset, ret); + dev_err(circ->dev, "Failed to set position for circular write %lld, %d\n", + (long long) offset, ret); return ret; } ret = write_full(circ->fd, buf, len); if (ret < 0) { - dev_err(circ->dev, "Failed to write circular to %ld length %d, %d\n", - offset, len, ret); + dev_err(circ->dev, "Failed to write circular to %lld length %d, %d\n", + (long long) offset, len, ret); return ret; } @@ -207,8 +207,8 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir */ flush(circ->fd); - dev_dbg(circ->dev, "Written state to offset %ld length %d data length %d\n", - offset, len, len); + dev_dbg(circ->dev, "Written state to offset %lld length %d data length %d\n", + (long long) offset, len, len); return 0; } @@ -265,8 +265,8 @@ static int state_backend_bucket_circular_read(struct state_backend_storage_bucke if (!buf) return -ENOMEM; - dev_dbg(circ->dev, "Read state from PEB %u global offset %ld length %zd\n", - circ->eraseblock, offset, read_len); + dev_dbg(circ->dev, "Read state from PEB %u global offset %lld length %zd\n", + circ->eraseblock, (long long) offset, read_len); ret = state_mtd_peb_read(circ, buf, offset, read_len); if (ret < 0 && ret != -EUCLEAN) { @@ -345,13 +345,13 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck ret = state_mtd_peb_write(circ, write_buf, offset, written_length); if (ret < 0 && ret != -EUCLEAN) { - dev_err(circ->dev, "Failed to write circular to %ld length %d, %d\n", - offset, written_length, ret); + dev_err(circ->dev, "Failed to write circular to %lld length %d, %d\n", + (long long) offset, written_length, ret); goto out_free; } - dev_dbg(circ->dev, "Written state to PEB %u offset %ld length %d data length %zd\n", - circ->eraseblock, offset, written_length, len); + dev_dbg(circ->dev, "Written state to PEB %u offset %lld length %d data length %zd\n", + circ->eraseblock, (long long) offset, written_length, len); out_free: free(write_buf); @@ -445,8 +445,8 @@ static int bucket_circular_is_block_bad(struct state_backend_storage_bucket_circ ret = ioctl(circ->fd, MEMGETBADBLOCK, &offs); if (ret < 0) - dev_err(circ->dev, "Failed to use ioctl to check for bad block at offset %ld, %d\n", - offs, ret); + dev_err(circ->dev, "Failed to use ioctl to check for bad block at offset %lld, %d\n", + (long long) offs, ret); return ret; } diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c index c6ebe86244..8cd822eec4 100644 --- a/common/state/backend_storage.c +++ b/common/state/backend_storage.c @@ -111,11 +111,11 @@ refresh: ret = bucket->write(bucket, buf, len); if (ret) { - dev_warn(storage->dev, "Failed to restore bucket %d@0x%08lx\n", - bucket->num, bucket->offset); + dev_warn(storage->dev, "Failed to restore bucket %d@0x%08llx\n", + bucket->num, (long long) bucket->offset); } else { - dev_info(storage->dev, "restored bucket %d@0x%08lx\n", - bucket->num, bucket->offset); + dev_info(storage->dev, "restored bucket %d@0x%08llx\n", + bucket->num, (long long) bucket->offset); bucket->needs_refresh = 0; } @@ -166,7 +166,7 @@ int state_storage_read(struct state_backend_storage *storage, if (!ret && !bucket_used) bucket_used = bucket; if (ret) - dev_info(storage->dev, "Ignoring broken bucket %d@0x%08lx...\n", bucket->num, bucket->offset); + dev_info(storage->dev, "Ignoring broken bucket %d@0x%08llx...\n", bucket->num, (long long) bucket->offset); } dev_dbg(storage->dev, "Checking redundant buckets finished.\n"); @@ -177,7 +177,7 @@ int state_storage_read(struct state_backend_storage *storage, return -ENOENT; } - dev_info(storage->dev, "Using bucket %d@0x%08lx\n", bucket_used->num, bucket_used->offset); + dev_info(storage->dev, "Using bucket %d@0x%08llx\n", bucket_used->num, (long long) bucket_used->offset); /* * Restore/refresh all buckets except the one we currently use (in case @@ -252,8 +252,8 @@ static int state_storage_mtd_buckets_init(struct state_backend_storage *storage, end = meminfo->size; if (!IS_ALIGNED(storage->offset, meminfo->erasesize)) { - dev_err(storage->dev, "Offset within the device is not aligned to eraseblocks. Offset is %ld, erasesize %u\n", - storage->offset, meminfo->erasesize); + dev_err(storage->dev, "Offset within the device is not aligned to eraseblocks. Offset is %lld, erasesize %u\n", + (long long) storage->offset, meminfo->erasesize); return -EINVAL; } @@ -326,8 +326,8 @@ static int state_storage_file_buckets_init(struct state_backend_storage *storage &bucket, offset, stridesize); if (ret) { - dev_warn(storage->dev, "Failed to create direct bucket at '%s' offset %ld\n", - storage->path, offset); + dev_warn(storage->dev, "Failed to create direct bucket at '%s' offset %lld\n", + storage->path, (long long) offset); continue; } -- cgit v1.2.3 From ed86bd67ef9bda914c99c6ee939de836eff1dc10 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:22 +0100 Subject: common: state: fix formatting of "uint32_t" variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To harmonize the common codebase this ports the following dt-utils commit: | commit 5588a6c32d54bc4a1ef0b9f72807c46dd00bc20e | Author: Ulrich Ölmann | Date: Sun Feb 3 22:48:07 2019 +0100 | | state: fix formatting of "uint32_t" variables | | The format specifier "%zd" is for "size_t" typed variables and produces a | warning with gcc, so use "%u" instead. | | Signed-off-by: Ulrich Ölmann | Signed-off-by: Roland Hieber Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index ae15fa2529..059a531aa4 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -298,7 +298,7 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck void *write_buf; if (written_length > circ->max_size) { - dev_err(circ->dev, "Error, state data too big to be written, to write: %d, writesize: %zd, length: %zd, available: %zd\n", + dev_err(circ->dev, "Error, state data too big to be written, to write: %u, writesize: %zd, length: %zd, available: %zd\n", written_length, circ->writesize, len, circ->max_size); return -E2BIG; } @@ -345,12 +345,12 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck ret = state_mtd_peb_write(circ, write_buf, offset, written_length); if (ret < 0 && ret != -EUCLEAN) { - dev_err(circ->dev, "Failed to write circular to %lld length %d, %d\n", + dev_err(circ->dev, "Failed to write circular to %lld length %u, %d\n", (long long) offset, written_length, ret); goto out_free; } - dev_dbg(circ->dev, "Written state to PEB %u offset %lld length %d data length %zd\n", + dev_dbg(circ->dev, "Written state to PEB %u offset %lld length %u data length %zd\n", circ->eraseblock, (long long) offset, written_length, len); out_free: -- cgit v1.2.3 From 04657b6af779bcf7ac06f36ffa0707f216a88b45 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:23 +0100 Subject: common: state: harmonize code with dt-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Other than in barebox the offset and size of a state's backend device do not necessarily equal zero in Linux userspace (EEPROMs & block devices), so barebox' and dt-utils' state code differ here. Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/state.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/state/state.c b/common/state/state.c index d3e048b990..3f5d43ecbf 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -596,6 +596,8 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) const char *alias; uint32_t stridesize; struct device_node *partition_node; + off_t offset = 0; + size_t size = 0; alias = of_alias_get(node); if (!alias) { @@ -614,7 +616,11 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) goto out_release_state; } +#ifdef __BAREBOX__ ret = of_find_path_by_node(partition_node, &state->backend_path, 0); +#else + ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size); +#endif if (ret) { if (ret != -EPROBE_DEFER) dev_err(&state->dev, "state failed to parse path to backend: %s\n", @@ -645,8 +651,8 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) if (ret) goto out_release_state; - ret = state_storage_init(state, state->backend_path, 0, - 0, stridesize, storage_type); + ret = state_storage_init(state, state->backend_path, offset, + size, stridesize, storage_type); if (ret) goto out_release_state; -- cgit v1.2.3 From 240abfe2224f3701c2f81a3baeed1206f5539f24 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:24 +0100 Subject: common: state: harmonize code with dt-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linux userspace needs sys/param.h to have the definition of roundup(). Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'common') diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 059a531aa4..da7c8421ae 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -23,6 +23,10 @@ #include #include +#ifndef __BAREBOX__ +#include +#endif + #include "state.h" /* -- cgit v1.2.3 From b525657cd5360a4737df9c09169ef54d33420a99 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:25 +0100 Subject: common: state: harmonize code with dt-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linux userspace with recent glibc versions lets barebox-state suffer from linux/stat.h redefining 'struct statx' and because of that switched to the inclusion of sys/stat.h instead, see dt-utils commit 1c80e31872ae ("src: fix compilation for glibc version 2.27.9000-36.fc29 and newer"). We can follow this switch in barebox without any problems, too, as in barebox sys/stat.h includes linux/stat.h (and adds some more definitions on top that don't hurt us here). Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c index 8cd822eec4..fca887e93f 100644 --- a/common/state/backend_storage.c +++ b/common/state/backend_storage.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From 5033b4f58f71e1535ab83d35dfcd8bb1b0384e22 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:26 +0100 Subject: common: state: harmonize code with dt-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Insert a helpful size check that is an outcome of the following dt-utils commits: | commit a6eb5350be0f7a5673162d20f2dd72569d5a4d0c | Author: Markus Pargmann | Date: Fri May 27 13:53:40 2016 +0200 | | barebox-state: Import updated state code | | Signed-off-by: Markus Pargmann | commit 583acea6669550ffa7ffb465301ddb3529206afc | Author: Sascha Hauer | Date: Thu Mar 23 11:29:50 2017 +0100 | | state: backend-direct: Fix max_size | | The max_size in the direct backend includes the meta data, so | substract its size when determing the max data size we can store. | | Signed-off-by: Sascha Hauer | commit dcf781f1b3d15aff5f5ff0b604bff447dee2040c | Author: Sascha Hauer | Date: Thu Mar 23 12:59:48 2017 +0100 | | state: backend_bucket_direct: max_size is always given | | max_size is always != 0, so if(direct->max_size) can be skipped. | | Signed-off-by: Sascha Hauer Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_direct.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common') diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 9d6a337e66..1f00b0fb2f 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -110,6 +110,9 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket int ret; struct state_backend_storage_bucket_direct_meta meta; + if (len > direct->max_size - sizeof(meta)) + return -E2BIG; + ret = lseek(direct->fd, direct->offset, SEEK_SET); if (ret < 0) { dev_err(direct->dev, "Failed to seek file, %d\n", ret); -- cgit v1.2.3 From 8a29e7b493c8c2aa57174c9e79c14b93c9807a4b Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Tue, 12 Feb 2019 16:10:41 +0100 Subject: memory: of_fixup: adapt to new memory layout Since kernel 4.16 the memory nodes got a @ suffix so the fixup won't work correctly anymore, because instead of adapting the extisting one the fixup creates a new node and keeps the old (maybe incorrect) node. To be compatible with the old and new layout delete the found memory node and create a new one. The new node follows the new @ style. The patch also renames the node parameter to make it clearer. Signed-off-by: Marco Felsch Signed-off-by: Sascha Hauer --- common/memory.c | 75 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/memory.c b/common/memory.c index 00fa7c50ff..21b2b4f63a 100644 --- a/common/memory.c +++ b/common/memory.c @@ -224,39 +224,78 @@ int memory_bank_first_find_space(resource_size_t *retstart, #ifdef CONFIG_OFTREE -static int of_memory_fixup(struct device_node *node, void *unused) +static int of_memory_fixup(struct device_node *root, void *unused) { struct memory_bank *bank; int err; - int addr_cell_len, size_cell_len, len = 0; - struct device_node *memnode; - u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */ + int addr_cell_len, size_cell_len; + struct device_node *memnode, *tmp, *np; + char *memnode_name; - memnode = of_create_node(node, "/memory"); - if (!memnode) - return -ENOMEM; + /* + * Since kernel 4.16 the memory node got a @ suffix. To support + * the old and the new style delete any found memory node and add it + * again to be sure that the memory node exists only once. It shouldn't + * bother older kernels if the memory node has this suffix so adding it + * following the new style. + */ - err = of_property_write_string(memnode, "device_type", "memory"); - if (err) - return err; + for_each_child_of_node_safe(root, tmp, np) { + const char *device_type; - addr_cell_len = of_n_addr_cells(memnode); - size_cell_len = of_n_size_cells(memnode); + err = of_property_read_string(np, "device_type", &device_type); + if (err || of_node_cmp("memory", device_type)) + continue; + + /* delete every found memory node */ + of_delete_node(np); + } + + addr_cell_len = of_n_addr_cells(root); + size_cell_len = of_n_size_cells(root); for_each_memory_bank(bank) { - of_write_number(tmp + len, bank->start, addr_cell_len); + u8 tmp[16]; /* Up to 64-bit address + 64-bit size */ + int len = 0; + + /* Create a /memory node for each bank */ + memnode_name = basprintf("/memory@%lx", bank->start); + if (!memnode_name) { + err = -ENOMEM; + goto err_out; + } + + memnode = of_create_node(root, memnode_name); + if (!memnode) { + err = -ENOMEM; + goto err_free; + } + + err = of_property_write_string(memnode, "device_type", + "memory"); + if (err) + goto err_free; + + of_write_number(tmp, bank->start, addr_cell_len); len += addr_cell_len * 4; of_write_number(tmp + len, bank->size, size_cell_len); len += size_cell_len * 4; - } - err = of_set_property(memnode, "reg", tmp, len, 1); - if (err) { - pr_err("could not set reg %s.\n", strerror(-err)); - return err; + err = of_set_property(memnode, "reg", tmp, len, 1); + if (err) { + pr_err("could not set reg %s.\n", strerror(-err)); + goto err_free; + } + + free(memnode_name); } return 0; + +err_free: + free(memnode_name); +err_out: + return err; } static int of_register_memory_fixup(void) -- cgit v1.2.3