diff --git a/Makefile b/Makefile index 5770f2d..1029dc1 100644 --- a/Makefile +++ b/Makefile @@ -484,6 +484,9 @@ barebox-flash-image: $(KBUILD_IMAGE) FORCE $(call if_changed,ln) +barebox-flash-images: $(KBUILD_IMAGE) + @echo $^ > $@ + images: barebox.bin FORCE $(Q)$(MAKE) $(build)=images $@ images/%.s: barebox.bin FORCE @@ -492,7 +495,7 @@ ifdef CONFIG_PBL_MULTI_IMAGES all: barebox.bin images else -all: barebox-flash-image +all: barebox-flash-image barebox-flash-images endif common-$(CONFIG_PBL_IMAGE) += pbl/ diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 721aa9b..cae05ff 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -13,6 +13,13 @@ LD += -EL endif +# Unaligned access is not supported when MMU is disabled, so given how +# at least some of the code would be executed with MMU off, lets be +# conservative and instruct the compiler not to generate any unaligned +# accesses +CFLAGS += -mno-unaligned-access + + # This selects which instruction set is used. # Note that GCC does not numerically define an architecture version # macro, but instead defines a whole series of macros which makes diff --git a/commands/clk.c b/commands/clk.c index 4e7ca60..e9459a3 100644 --- a/commands/clk.c +++ b/commands/clk.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include static int do_clk_enable(int argc, char *argv[]) { @@ -38,7 +40,7 @@ clk_disable(clk); - return 0; + return COMMAND_SUCCESS; } BAREBOX_CMD_START(clk_disable) @@ -77,6 +79,59 @@ BAREBOX_CMD_HELP(cmd_clk_set_rate_help) BAREBOX_CMD_END +static int do_clk_get_rate(int argc, char *argv[]) +{ + int opt; + struct clk *clk; + unsigned long rate; + const char *variable_name = NULL; + + while ((opt = getopt(argc, argv, "s:")) > 0) { + switch (opt) { + case 's': + variable_name = optarg; + break; + default: + return COMMAND_ERROR_USAGE; + } + } + + if (optind == argc) { + fprintf(stderr, "No clock name given\n"); + return COMMAND_ERROR_USAGE; + } + + clk = clk_lookup(argv[optind]); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + rate = clk_get_rate(clk); + + if (variable_name) { + char *t; + + t = asprintf("%lu", rate); + setenv(variable_name, t); + free(t); + } else + printf("%lu\n", rate); + + return COMMAND_SUCCESS; +} + +BAREBOX_CMD_HELP_START(clk_get_rate) +BAREBOX_CMD_HELP_TEXT("Show clock CLK rate") +BAREBOX_CMD_HELP_OPT("-s VARNAME", "set variable VARNAME instead of showing information") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(clk_get_rate) + .cmd = do_clk_get_rate, + BAREBOX_CMD_DESC("get a clocks rate") + BAREBOX_CMD_OPTS("[-s VARNAME] CLK") + BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP) + BAREBOX_CMD_HELP(cmd_clk_get_rate_help) +BAREBOX_CMD_END + static int do_clk_dump(int argc, char *argv[]) { int opt, verbose = 0; @@ -94,7 +149,7 @@ clk_dump(verbose); - return 0; + return COMMAND_SUCCESS; } BAREBOX_CMD_HELP_START(clk_dump) diff --git a/commands/edit.c b/commands/edit.c index b28e2b9..c014892 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -258,6 +258,7 @@ { struct line *line, *tmp; int fd; + int ret = 0; fd = open(path, O_WRONLY | O_TRUNC | O_CREAT); if (fd < 0) { @@ -269,12 +270,20 @@ while(line) { tmp = line->next; - write(fd, line->data, strlen(line->data)); - write(fd, "\n", 1); + ret = write_full(fd, line->data, strlen(line->data)); + if (ret < 0) + goto out; + ret = write_full(fd, "\n", 1); + if (ret < 0) + goto out; line = tmp; } + + ret = 0; + +out: close(fd); - return 0; + return ret; } static void insert_char(char c) @@ -375,6 +384,7 @@ int i; int linepos; int c; + int ret = COMMAND_SUCCESS; if (argc != 2) return COMMAND_ERROR_USAGE; @@ -533,7 +543,7 @@ } break; case 4: - save_file(argv[1]); + ret = save_file(argv[1]); goto out; case 3: goto out; @@ -546,7 +556,7 @@ free_buffer(); printf("%c[2J%c[r", 27, 27); printf("\n"); - return 0; + return ret; } static const char *edit_aliases[] = { "sedit", NULL}; diff --git a/commands/loadb.c b/commands/loadb.c index be5830d..aabb00a 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -681,9 +681,9 @@ BAREBOX_CMD_HELP_START(loadb) BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("Options:") -BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin") +BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin)") BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)") -BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate") +BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate)") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(loadb) diff --git a/commands/memtest.c b/commands/memtest.c index 691b388..d784a5c 100644 --- a/commands/memtest.c +++ b/commands/memtest.c @@ -129,8 +129,11 @@ goto out; for (i = 1; (i <= max_i) || !max_i; i++) { + printf("Start iteration %u", i); if (max_i) - printf("Start iteration %u of %u.\n", i, max_i); + printf(" of %u.\n", max_i); + else + putchar('\n'); if (cached) { printf("Do memtest with caching enabled.\n"); diff --git a/commands/of_dump.c b/commands/of_dump.c index 513a4b8..b15f54a 100644 --- a/commands/of_dump.c +++ b/commands/of_dump.c @@ -31,6 +31,16 @@ #include #include +static void of_print_nodenames(struct device_node *node) +{ + struct device_node *n; + + printf("%s\n", node->full_name); + + list_for_each_entry(n, &node->children, parent_list) + of_print_nodenames(n); +} + static int do_of_dump(int argc, char *argv[]) { int opt; @@ -40,8 +50,9 @@ char *dtbfile = NULL; size_t size; const char *nodename; + int names_only = 0; - while ((opt = getopt(argc, argv, "Ff:")) > 0) { + while ((opt = getopt(argc, argv, "Ff:n")) > 0) { switch (opt) { case 'f': dtbfile = optarg; @@ -49,6 +60,9 @@ case 'F': fix = 1; break; + case 'n': + names_only = 1; + break; default: return COMMAND_ERROR_USAGE; } @@ -111,7 +125,10 @@ goto out; } - of_print_nodes(node, 0); + if (names_only) + of_print_nodenames(node); + else + of_print_nodes(node, 0); out: if (of_free) diff --git a/common/command.c b/common/command.c index dc2cb88..03c7083 100644 --- a/common/command.c +++ b/common/command.c @@ -83,7 +83,7 @@ #else printf ("Unknown command '%s'\n", argv[0]); #endif - ret = 1; /* give up after bad command */ + ret = COMMAND_ERROR; /* give up after bad command */ } getopt_context_restore(&gc); diff --git a/common/filetype.c b/common/filetype.c index dc2ff3f..9ec8ebf 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -369,9 +369,10 @@ struct cdev *cdev; void *buf; - cdev = cdev_by_name(name); + cdev = cdev_open(name, O_RDONLY); if (!cdev) return type; + buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE); ret = cdev_read(cdev, buf, FILE_TYPE_SAFE_BUFSIZE, 0, 0); if (ret < 0) @@ -396,5 +397,6 @@ err_out: free(buf); + cdev_close(cdev); return type; } diff --git a/common/parser.c b/common/parser.c index ed414d0..6136dbf 100644 --- a/common/parser.c +++ b/common/parser.c @@ -253,7 +253,8 @@ continue; } - rc = execute_command(argc, argv); + if (execute_command(argc, argv) != COMMAND_SUCCESS) + rc = -1; } return rc; @@ -265,7 +266,6 @@ { static char lastcommand[CONFIG_CBSIZE] = { 0, }; int len; - int rc = 1; login(); @@ -275,14 +275,14 @@ if (len > 0) strcpy (lastcommand, console_buffer); - if (len == -1) + if (len == -1) { puts ("\n"); - else - rc = run_command(lastcommand); - - if (rc <= 0) { - /* invalid command or not repeatable, forget it */ - lastcommand[0] = 0; + } else { + const int rc = run_command(lastcommand); + if (rc < 0) { + /* invalid command or not repeatable, forget it */ + lastcommand[0] = 0; + } } } return 0; diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c index ee1709e..d30d0ad 100644 --- a/drivers/ata/disk_ata_drive.c +++ b/drivers/ata/disk_ata_drive.c @@ -26,16 +26,6 @@ #include #include -static int ata_id_is_valid(const uint16_t *id) -{ - if ((id[ATA_ID_FIELD_VALID] & 1) == 0) { - pr_debug("Drive's ID seems invalid\n"); - return -EINVAL; - } - - return 0; -} - static uint64_t ata_id_n_sectors(uint16_t *id) { if (ata_id_has_lba(id)) { @@ -244,13 +234,6 @@ ata_fix_endianess(port->id, SECTOR_SIZE / sizeof(uint16_t)); - rc = ata_id_is_valid(port->id); - if (rc) { - dev_err(dev, "ata id invalid\n"); - free(port->id); - return rc; - } - #ifdef DEBUG ata_dump_id(port->id); #endif diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 9000115..29c0d54 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -947,14 +947,13 @@ static char *mci_version_string(struct mci *mci) { static char version[sizeof("x.xx")]; - unsigned major, minor, micro; + unsigned major, minor; major = (mci->version >> 8) & 0xf; - minor = (mci->version >> 4) & 0xf; - micro = mci->version & 0xf; + minor = mci->version & 0xff; - sprintf(version, "%u.%u", major, - micro ? (minor << 4) | micro : minor); + /* Shift off last digit of minor if it's 0 */ + sprintf(version, "%u.%x", major, minor & 0xf ? minor : minor >> 4); return version; } diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 3672c44..d159d60 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -31,6 +31,12 @@ return 0; } +static void fb_release_shadowfb(struct fb_info *info) +{ + free(info->screen_base_shadow); + info->screen_base_shadow = NULL; +} + static int fb_alloc_shadowfb(struct fb_info *info) { if (info->screen_base_shadow && info->shadowfb) @@ -47,8 +53,7 @@ memcpy(info->screen_base_shadow, info->screen_base, info->line_length * info->yres); } else { - free(info->screen_base_shadow); - info->screen_base_shadow = NULL; + fb_release_shadowfb(info); } return 0; @@ -79,6 +84,8 @@ info->fbops->fb_disable(info); + fb_release_shadowfb(info); + info->enabled = false; return 0; @@ -92,9 +99,9 @@ enable = info->p_enable; if (enable) - info->fbops->fb_enable(info); + fb_enable(info); else - info->fbops->fb_disable(info); + fb_disable(info); return 0; } diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c index b10503e..c38d13c 100644 --- a/drivers/video/fbconsole.c +++ b/drivers/video/fbconsole.c @@ -192,8 +192,9 @@ buf = gui_screen_render_buffer(priv->sc); - memcpy(buf, buf + line_height, line_height * (priv->rows + 1)); + memcpy(buf, buf + line_height, line_height * priv->rows); memset(buf + line_height * priv->rows, 0, line_height); + gu_screen_blit(priv->sc); priv->y = priv->rows; } diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 62571fb..2541ea3 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -121,9 +121,13 @@ struct cdev *cdev_open(const char *name, unsigned long flags) { - struct cdev *cdev = cdev_by_name(name); + struct cdev *cdev; int ret; + if (!strncmp(name, "/dev/", 5)) + name += 5; + + cdev = cdev_by_name(name); if (!cdev) return NULL; diff --git a/fs/devfs.c b/fs/devfs.c index c6db25c..5c96682 100644 --- a/fs/devfs.c +++ b/fs/devfs.c @@ -228,6 +228,13 @@ static int devfs_probe(struct device_d *dev) { + struct fs_device_d *fsdev = dev_to_fs_device(dev); + + if (strcmp(fsdev->path, "/dev")) { + dev_err(dev, "devfs can only be mounted on /dev/\n"); + return -EINVAL; + } + return 0; } diff --git a/fs/fs.c b/fs/fs.c index c2a20e1..4983fc7 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -1205,8 +1205,6 @@ struct driver_d *drv; struct fs_driver_d *fdrv; - if (!strncmp(filename, "/dev/", 5)) - filename += 5; type = cdev_detect_type(filename); if (type == filetype_unknown) @@ -1224,12 +1222,7 @@ int fsdev_open_cdev(struct fs_device_d *fsdev) { - const char *backingstore = fsdev->backingstore; - - if (!strncmp(backingstore , "/dev/", 5)) - backingstore += 5; - - fsdev->cdev = cdev_open(backingstore, O_RDWR); + fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR); if (!fsdev->cdev) return -EINVAL; diff --git a/images/Makefile b/images/Makefile index a5f589b..6a44511 100644 --- a/images/Makefile +++ b/images/Makefile @@ -121,10 +121,26 @@ SECONDARY: $(addprefix $(obj)/,$(targets)) -images: $(addprefix $(obj)/, $(image-y)) FORCE +# Images with full paths +image-y-path := $(addprefix $(obj)/,$(image-y)) +# File will have a list of images generated +flash-list := $(obj)/../barebox-flash-images +# Symlink, which will point to non-existent 'multi-image-build' if there are +# multiple images +flash-link := $(obj)/../barebox-flash-image +link-dest := $(if $(filter 1,$(words $(image-y))),$(image-y-path),multi-image-build) +multi-image-build: + +images: $(image-y-path) $(flash-link) $(flash-list) FORCE @echo "images built:" @for i in $(image-y); do echo $$i; done +$(flash-link): $(link-dest) FORCE + $(call if_changed,ln) + +$(flash-list): $(image-y-path) + @for i in $^; do echo $$i; done > $@ + clean-files := *.pbl *.pblb *.pblx *.map start_*.imximg *.img barebox.z start_*.kwbimg \ start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \ *.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd diff --git a/include/clock.h b/include/clock.h index 7f0f1ec..d65e404 100644 --- a/include/clock.h +++ b/include/clock.h @@ -1,8 +1,7 @@ -#include - #ifndef CLOCK_H #define CLOCK_H +#include #include #define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) diff --git a/lib/logo/Makefile b/lib/logo/Makefile index f5f229f..eb7aee0 100644 --- a/lib/logo/Makefile +++ b/lib/logo/Makefile @@ -41,7 +41,6 @@ quiet_cmd_logo = LOGO.S $@ cmd_logo = \ ( \ - echo OPTS: $(OPTS_$(@F)); \ inkscape -z $(OPTS_$(@F)) -e $@ $< > /dev/null; \ ) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 8d96434..f3fd339 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2013,8 +2013,8 @@ # function brace can't be on same line, except for #defines of do while, # or if closed on same line - if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and - !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { + if (($line=~/$Type\s*$Ident\(.*\).*\s\{/) and + !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) { ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); } @@ -2264,8 +2264,8 @@ ## } #need space before brace following if, while, etc - if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || - $line =~ /do{/) { + if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\){/) || + $line =~ /do\{/) { ERROR("space required before the open brace '{'\n" . $herecurr); }