diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S index 0954c89..d7a3cc5 100644 --- a/arch/arm/lib/pbl.lds.S +++ b/arch/arm/lib/pbl.lds.S @@ -54,6 +54,7 @@ /DISCARD/ : { *(.ARM.ex*) } BAREBOX_BARE_INIT_SIZE + BAREBOX_PBL_SIZE . = ALIGN(4); .rodata : { *(.rodata*) } diff --git a/arch/arm/mach-clps711x/devices.c b/arch/arm/mach-clps711x/devices.c index c7a2fbd..e27476d 100644 --- a/arch/arm/mach-clps711x/devices.c +++ b/arch/arm/mach-clps711x/devices.c @@ -124,9 +124,6 @@ /* SYSCON2, SYSFLG2 */ add_generic_device("syscon", 2, NULL, SYSCON2, SZ_128, IORESOURCE_MEM, NULL); - /* SYSCON3 */ - add_generic_device("syscon", 3, NULL, SYSCON3, SZ_64, - IORESOURCE_MEM, NULL); return 0; } diff --git a/arch/arm/mach-socfpga/include/mach/sequencer.c b/arch/arm/mach-socfpga/include/mach/sequencer.c index fa955ce..6e69d1b 100644 --- a/arch/arm/mach-socfpga/include/mach/sequencer.c +++ b/arch/arm/mach-socfpga/include/mach/sequencer.c @@ -3151,7 +3151,6 @@ tmp_delay += IO_DELAY_PER_DCHAIN_TAP; } dtaps_per_ptap--; - tmp_delay = 0; #endif /* starting phases */ diff --git a/commands/Kconfig b/commands/Kconfig index 1e07b5b..352e8bf 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -57,6 +57,12 @@ tristate prompt "readline" +config CMD_READF + tristate + prompt "readf" + help + The readf command is used to read a files content into a shell variable. + config CMD_LET tristate prompt "let" diff --git a/commands/Makefile b/commands/Makefile index 58d27fa..91ec0e9 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -93,3 +93,4 @@ obj-$(CONFIG_CMD_DETECT) += detect.o obj-$(CONFIG_CMD_BOOT) += boot.o obj-$(CONFIG_CMD_DEVINFO) += devinfo.o +obj-$(CONFIG_CMD_READF) += readf.o diff --git a/commands/boot.c b/commands/boot.c index c4b49a9..ccf5827 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -308,7 +308,7 @@ { struct blspec *blspec; struct blspec_entry *entry; - int ret = -ENOENT; + int ret; blspec = blspec_alloc(); ret = bootentry_parse_one(blspec, name); diff --git a/commands/dfu.c b/commands/dfu.c index 99a381f..2513ed8 100644 --- a/commands/dfu.c +++ b/commands/dfu.c @@ -128,9 +128,14 @@ argstr = argv[optind]; - if (!idProduct || !idVendor) { - printf("productid or vendorid not given\n"); - return 1; + if (!idProduct && !idVendor) { + idVendor = 0x1d50; /* Openmoko, Inc */ + idProduct = 0x60a2; /* barebox bootloader USB DFU Mode */ + } + + if ((idProduct && !idVendor) || (!idProduct && idVendor)) { + printf("Only one of vendor id or product id given\n"); + return -EINVAL; } for (n = 0; *argstr; n++) { diff --git a/commands/edit.c b/commands/edit.c index 6764e84..b0fcf69 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -266,7 +266,7 @@ fd = open(path, O_WRONLY | O_TRUNC | O_CREAT); if (fd < 0) { printf("could not open file for writing: %s\n", errno_str()); - return -1; + return fd; } line = buffer; diff --git a/commands/readf.c b/commands/readf.c new file mode 100644 index 0000000..6314c7e --- /dev/null +++ b/commands/readf.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include + +static int do_readf(int argc, char *argv[]) +{ + unsigned char *buf = NULL, *val; + char *variable, *filename; + struct stat s; + size_t size; + int ret, i; + + if (argc != 3) + return COMMAND_ERROR_USAGE; + + filename = argv[1]; + variable = argv[2]; + + ret = stat(filename, &s); + if (ret) + goto out; + + if (s.st_size > 1024) { + ret = -EFBIG; + goto out; + } + + buf = read_file(filename, &size); + if (!buf) + goto out; + + for (i = 0; i < size; i++) { + if (!isprint(buf[i])) { + buf[i] = '\0'; + break; + } + } + + val = strim(buf); + + ret = setenv(variable, val); +out: + free(buf); + + return ret; +} + +BAREBOX_CMD_HELP_START(readf) +BAREBOX_CMD_HELP_USAGE("readf \n") +BAREBOX_CMD_HELP_SHORT("Read a single line of a file into a shell variable. Leading and trailing whitespaces\n") +BAREBOX_CMD_HELP_SHORT("are removed, nonvisible characters are stripped. Input is limited to 1024\n") +BAREBOX_CMD_HELP_SHORT("characters.\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(readf) + .cmd = do_readf, + .usage = "read file into variable", + BAREBOX_CMD_HELP(cmd_readf_help) +BAREBOX_CMD_END diff --git a/common/Kconfig b/common/Kconfig index b9cbe19..5224838 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -145,13 +145,24 @@ help Define the maximum size of barebox -config BAREBOX_MAX_BARE_INIT_SIZE - prompt "Maximum bare_init size" +config BAREBOX_MAX_PBL_SIZE + depends on PBL_IMAGE + prompt "Maximum pre-bootloader size" hex default 0xffffffff help + On some hardware the ROM code can load the pbl into SRAM, but not + the whole image. This option specifies how big the pbl may get. + +config BAREBOX_MAX_BARE_INIT_SIZE + prompt "Maximum bare_init size" + hex + range 0x0 BAREBOX_MAX_PBL_SIZE if LOAD_PBL_SRAM + default BAREBOX_MAX_PBL_SIZE if LOAD_PBL_SRAM + default 0xffffffff + help Define the maximum size of bare_init - this will allow your bare_init will fit in SRAM as example + this will allow your bare_init to fit in SRAM as example ARCH can overwrite it via ARCH_BAREBOX_MAX_BARE_INIT_SIZE config HAVE_CONFIGURABLE_MEMORY_LAYOUT diff --git a/common/kallsyms.c b/common/kallsyms.c index 94dfcdc..121b77c 100644 --- a/common/kallsyms.c +++ b/common/kallsyms.c @@ -167,10 +167,10 @@ * It resides in a module. * - We also guarantee that modname will be valid until rescheduled. */ -const char *kallsyms_lookup(unsigned long addr, - unsigned long *symbolsize, - unsigned long *offset, - char **modname, char *namebuf) +static const char *kallsyms_lookup(unsigned long addr, + unsigned long *symbolsize, + unsigned long *offset, + char **modname, char *namebuf) { namebuf[KSYM_NAME_LEN - 1] = 0; namebuf[0] = 0; diff --git a/drivers/clk/clk-divider-table.c b/drivers/clk/clk-divider-table.c index 204e24d..fd2d3fc 100644 --- a/drivers/clk/clk-divider-table.c +++ b/drivers/clk/clk-divider-table.c @@ -78,7 +78,7 @@ return parent_rate / div->table[val].div; } -struct clk_ops clk_divider_table_ops = { +static struct clk_ops clk_divider_table_ops = { .set_rate = clk_divider_set_rate, .recalc_rate = clk_divider_recalc_rate, }; diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 52e7c16..f0ecbd3 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -35,7 +35,7 @@ return (parent_rate / f->div) * f->mult; } -struct clk_ops clk_fixed_factor_ops = { +static struct clk_ops clk_fixed_factor_ops = { .recalc_rate = clk_fixed_factor_recalc_rate, }; diff --git a/drivers/clk/clk-fixed.c b/drivers/clk/clk-fixed.c index 3a38865..8164005 100644 --- a/drivers/clk/clk-fixed.c +++ b/drivers/clk/clk-fixed.c @@ -32,7 +32,7 @@ return fix->rate; } -struct clk_ops clk_fixed_ops = { +static struct clk_ops clk_fixed_ops = { .recalc_rate = clk_fixed_recalc_rate, .is_enabled = clk_is_enabled_always, }; diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index f33effd..baec855 100644 --- a/drivers/clk/clk-gate.c +++ b/drivers/clk/clk-gate.c @@ -76,7 +76,7 @@ return g->flags & CLK_GATE_INVERTED ? 1 : 0; } -struct clk_ops clk_gate_ops = { +static struct clk_ops clk_gate_ops = { .enable = clk_gate_enable, .disable = clk_gate_disable, .is_enabled = clk_gate_is_enabled, diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index 47efe12..b22bdd1 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -50,7 +50,7 @@ return 0; } -struct clk_ops clk_mux_ops = { +static struct clk_ops clk_mux_ops = { .get_parent = clk_mux_get_parent, .set_parent = clk_mux_set_parent, }; diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 66cd832..d9a1c21 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -179,9 +179,11 @@ if (!IS_ERR(clk)) return clk; - clk = of_clk_get_by_name(dev->device_node, con_id); - if (!IS_ERR(clk)) - return clk; + if (dev) { + clk = of_clk_get_by_name(dev->device_node, con_id); + if (!IS_ERR(clk)) + return clk; + } return clk_get_sys(dev_id, con_id); } diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c index 68b4710..0a099e1 100644 --- a/drivers/eeprom/at25.c +++ b/drivers/eeprom/at25.c @@ -294,8 +294,7 @@ return 0; fail: - if (at25) - free(at25); + free(at25); return err; } diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 3b9f601..f8785cb 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -243,8 +243,8 @@ * * Returns the new device, or NULL. */ -struct i2c_client *i2c_new_device(struct i2c_adapter *adapter, - struct i2c_board_info *chip) +static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter, + struct i2c_board_info *chip) { struct i2c_client *client; int status; @@ -269,9 +269,8 @@ return client; } -EXPORT_SYMBOL(i2c_new_device); -void of_i2c_register_devices(struct i2c_adapter *adap) +static void of_i2c_register_devices(struct i2c_adapter *adap) { struct device_node *n; diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 6db1c6d..3439a38 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -404,7 +404,8 @@ } devfs_create(&mtd->cdev); - of_parse_partitions(&mtd->cdev, mtd->parent->device_node); + if (mtd->parent) + of_parse_partitions(&mtd->cdev, mtd->parent->device_node); list_for_each_entry(hook, &mtd_register_hooks, hook) if (hook->add_mtd_device) diff --git a/drivers/mtd/nand/nand_imx.c b/drivers/mtd/nand/nand_imx.c index 6ca8911..e2aaa15 100644 --- a/drivers/mtd/nand/nand_imx.c +++ b/drivers/mtd/nand/nand_imx.c @@ -518,7 +518,7 @@ struct nand_chip *nand_chip = mtd->priv; struct imx_nand_host *host = nand_chip->priv; u32 ecc_stat, err; - int no_subpages = 1; + int no_subpages; int ret = 0; u8 ecc_bit_mask, err_limit; diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c index b58db5d..37057a7 100644 --- a/drivers/net/usb/asix.c +++ b/drivers/net/usb/asix.c @@ -382,7 +382,7 @@ if (ret < 0) { debug("Failed to read MAC address: %d\n", ret); - return -1; + return ret; } return 0; @@ -403,7 +403,7 @@ if ((ret = asix_read_cmd(udev, AX88172_CMD_READ_NODE_ID, 0, 0, 6, adr)) < 0) { debug("read AX_CMD_READ_NODE_ID failed: %d\n", ret); - return -1; + return ret; } return 0; diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 38ca12f..eb8f0be 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -447,7 +447,7 @@ udelay(10 * 1000); bmcr = smsc95xx_mdio_read(&dev->miibus, phy_id, MII_BMCR); timeout++; - } while ((bmcr & MII_BMCR) && (timeout < 100)); + } while ((bmcr & BMCR_RESET) && (timeout < 100)); if (timeout >= 100) { netdev_warn(dev->net, "timeout on PHY Reset"); diff --git a/drivers/of/base.c b/drivers/of/base.c index 6e5e7d6..104b6da 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -67,9 +67,9 @@ static LIST_HEAD(aliases_lookup); -struct device_node *root_node; +static struct device_node *root_node; -struct device_node *of_aliases; +static struct device_node *of_aliases; #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 @@ -1721,8 +1721,8 @@ return 0; } -struct device_node *of_chosen; -const char *of_model; +static struct device_node *of_chosen; +static const char *of_model; const char *of_get_model(void) { diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c index 60e124f..8803d9e 100644 --- a/drivers/spi/altera_spi.c +++ b/drivers/spi/altera_spi.c @@ -112,7 +112,7 @@ static unsigned altera_spi_do_xfer(struct spi_device *spi, struct spi_transfer *t) { struct altera_spi *altera_spi = container_of(spi->master, struct altera_spi, master); - int word_len = spi->bits_per_word; + int word_len; unsigned retval = 0; u32 txval; u32 rxval; diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 68a51d1..fe1ac02 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -504,8 +504,7 @@ list_del(&dev->list); unregister_device(&dev->dev); - if (dev->hub) - free(dev->hub); + free(dev->hub); dma_free(dev->setup_packet); dma_free(dev->descriptor); free(dev); diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 9af115e..11b6c18 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -204,7 +204,7 @@ static int config_buf(struct usb_configuration *config, enum usb_device_speed speed, void *buf, u8 type) { - struct usb_config_descriptor *c = buf; + struct usb_config_descriptor *c; void *next = buf + USB_DT_CONFIG_SIZE; int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE; struct usb_function *f; diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c index f885602..76b5def 100644 --- a/drivers/usb/gadget/dfu.c +++ b/drivers/usb/gadget/dfu.c @@ -607,8 +607,10 @@ func->disable = dfu_disable; dfu->dnreq = usb_ep_alloc_request(c->cdev->gadget->ep0); - if (!dfu->dnreq) + if (!dfu->dnreq) { printf("usb_ep_alloc_request failed\n"); + goto out; + } dfu->dnreq->buf = dma_alloc(CONFIG_USBD_DFU_XFER_SIZE); dfu->dnreq->complete = dn_complete; dfu->dnreq->zero = 0; diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c index e0aa201..6fef5f2 100644 --- a/drivers/usb/otg/ulpi.c +++ b/drivers/usb/otg/ulpi.c @@ -51,7 +51,7 @@ int ret; /* make sure interface is running */ - if (!(readl(view) && ULPIVW_SS)) { + if (!(readl(view) & ULPIVW_SS)) { writel(ULPIVW_WU, view); /* wait for wakeup */ @@ -73,7 +73,7 @@ int ret; /* make sure the interface is running */ - if (!(readl(view) && ULPIVW_SS)) { + if (!(readl(view) & ULPIVW_SS)) { writel(ULPIVW_WU, view); /* wait for wakeup */ ret = ulpi_poll(view, ULPIVW_WU); diff --git a/fs/bpkfs.c b/fs/bpkfs.c index b3b45be..8352307 100644 --- a/fs/bpkfs.c +++ b/fs/bpkfs.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -438,7 +437,7 @@ dev_dbg(dev, "%d: type = 0x%x => %s\n", i, d->type, d->name); dev_dbg(dev, "%d: size = %llu\n", i, d->size); - dev_dbg(dev, "%d: offset = %d\n", i, d->offset); + dev_dbg(dev, "%d: offset = %zu\n", i, d->offset); dev_dbg(dev, "%d: hw_id = 0x%x => %s\n", i, h->hw_id, h->name); diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h index 6d3a69e..5dabda3 100644 --- a/include/asm-generic/barebox.lds.h +++ b/include/asm-generic/barebox.lds.h @@ -60,6 +60,13 @@ #define MAX_BARE_INIT_SIZE CONFIG_BAREBOX_MAX_BARE_INIT_SIZE #endif +#if defined(CONFIG_ARCH_BAREBOX_MAX_PBL_SIZE) && \ +CONFIG_ARCH_BAREBOX_MAX_PBL_SIZE < CONFIG_BAREBOX_MAX_PBL_SIZE +#define MAX_PBL_SIZE CONFIG_ARCH_BAREBOX_MAX_PBL_SIZE +#else +#define MAX_PBL_SIZE CONFIG_BAREBOX_MAX_PBL_SIZE +#endif + #include /* use 2 ASSERT because ld can not accept '"size" "10"' format */ #define BAREBOX_BARE_INIT_SIZE \ @@ -67,3 +74,9 @@ ASSERT(_barebox_bare_init_size < MAX_BARE_INIT_SIZE, "Barebox bare_init size > ") \ ASSERT(_barebox_bare_init_size < MAX_BARE_INIT_SIZE, __stringify(MAX_BARE_INIT_SIZE)) \ +#define BAREBOX_PBL_SIZE \ + _barebox_pbl_size = __bss_start - _text; \ + ASSERT(MAX_BARE_INIT_SIZE <= MAX_PBL_SIZE, "bare_init cannot be bigger than pbl") \ + ASSERT(_barebox_pbl_size < MAX_PBL_SIZE, "Barebox pbl size > ") \ + ASSERT(_barebox_pbl_size < MAX_PBL_SIZE, __stringify(MAX_PBL_SIZE)) \ + diff --git a/lib/libbb.c b/lib/libbb.c index 189a170..dd42e66 100644 --- a/lib/libbb.c +++ b/lib/libbb.c @@ -43,7 +43,7 @@ char *concat_subpath_file(const char *path, const char *f) { - if (f && DOT_OR_DOTDOT(f)) + if (DOT_OR_DOTDOT(f)) return NULL; return concat_path_file(path, f); } diff --git a/lib/math.c b/lib/math.c index a4731ed..19c8f08 100644 --- a/lib/math.c +++ b/lib/math.c @@ -306,7 +306,7 @@ /* treat undefined var as 0 */ t->val = 0; } - return 0; + return NULL; } /* "Applying" a token means performing it on the top elements on the integer @@ -546,8 +546,8 @@ arith_t result; if (numstack == NULL || stack == NULL) { - errmsg = "out of memory"; - goto err_with_custom_msg; + math_state->errmsg = "out of memory"; + return -1; } /* Start with a left paren */ diff --git a/lib/parameter.c b/lib/parameter.c index c5c6426..a0bae3e 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -108,8 +108,7 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p, const char *val) { - if (p->value) - free(p->value); + free(p->value); if (!val) { p->value = NULL; return 0; diff --git a/net/eth.c b/net/eth.c index 37dd9e0..cb59e76 100644 --- a/net/eth.c +++ b/net/eth.c @@ -382,7 +382,7 @@ dev_remove_parameters(&edev->dev); - if (IS_ENABLED(CONFIG_OFDEVICE) && edev->nodepath) + if (IS_ENABLED(CONFIG_OFDEVICE)) free(edev->nodepath); unregister_device(&edev->dev); diff --git a/scripts/kwboot.c b/scripts/kwboot.c index 81da3e8..e068660 100644 --- a/scripts/kwboot.c +++ b/scripts/kwboot.c @@ -552,7 +552,6 @@ void *img; rc = -1; - fd = -1; img = NULL; fd = open(path, O_RDONLY);