diff --git a/arch/sandbox/board/dev-random.c b/arch/sandbox/board/dev-random.c index f65e5ef..60295e9 100644 --- a/arch/sandbox/board/dev-random.c +++ b/arch/sandbox/board/dev-random.c @@ -4,10 +4,6 @@ devrandom_t *devrandom_init(void) { devrandom_t *fds = xzalloc(sizeof(*fds)); - fds->randomfd = linux_open("/dev/random", false); - if (fds->randomfd < 0) - return ERR_PTR(-EPERM); - fds->urandomfd = linux_open("/dev/urandom", false); if (fds->urandomfd < 0) return ERR_PTR(-EPERM); @@ -17,8 +13,7 @@ int devrandom_read(devrandom_t *devrandom, void *buf, size_t len, int wait) { - if (wait) - return linux_read(devrandom->randomfd, buf, len); + (void)wait; /* /dev/urandom won't block */ return linux_read(devrandom->urandomfd, buf, len); } diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h index 1e64d41..9759a37 100644 --- a/arch/sandbox/mach-sandbox/include/mach/linux.h +++ b/arch/sandbox/mach-sandbox/include/mach/linux.h @@ -52,7 +52,6 @@ void barebox_libftdi1_close(void); typedef struct { - int randomfd; int urandomfd; } devrandom_t; devrandom_t *devrandom_init(void); diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 8611882..3ad12b4 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include /* * ...except the ones needed to connect with barebox */ @@ -260,11 +262,17 @@ hf->size = s.st_size; hf->devname = strdup(devname); + if (S_ISBLK(s.st_mode)) { + if (ioctl(fd, BLKGETSIZE64, &hf->size) == -1) { + perror("ioctl"); + goto err_out; + } + } hf->base = (unsigned long)mmap(NULL, hf->size, PROT_READ | (readonly ? 0 : PROT_WRITE), MAP_SHARED, fd, 0); if ((void *)hf->base == MAP_FAILED) - printf("warning: mmapping %s failed\n", filename); + printf("warning: mmapping %s failed: %s\n", filename, strerror(errno)); ret = barebox_register_filedev(hf); if (ret) diff --git a/commands/Kconfig b/commands/Kconfig index 0189b47..a6db52a 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -1389,8 +1389,10 @@ help Set password - 'Interactively asks for a password. The digest of this password will be - stored in /env/etc//passwd. This is then used by the 'login' command. + Interactively asks for a password. The digest of this password will be + stored in /env/etc/passwd. This is then used by the 'login' command. + + Passwords can be generated on the host machine using barebox sandbox. Entering an empty string will disable the password function. diff --git a/commands/cp.c b/commands/cp.c index 54934dd..845dae6 100644 --- a/commands/cp.c +++ b/commands/cp.c @@ -100,13 +100,14 @@ BAREBOX_CMD_HELP_TEXT("Copy file from SRC to DEST.") BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("Options:") +BAREBOX_CMD_HELP_OPT ("-r", "recursive") BAREBOX_CMD_HELP_OPT ("-v", "verbose") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(cp) .cmd = do_cp, BAREBOX_CMD_DESC("copy files") - BAREBOX_CMD_OPTS("[-v] SRC DEST") + BAREBOX_CMD_OPTS("[-rv] SRC DEST") BAREBOX_CMD_GROUP(CMD_GRP_FILE) BAREBOX_CMD_HELP(cmd_cp_help) BAREBOX_CMD_END diff --git a/commands/edit.c b/commands/edit.c index ba6a8c7..4e661df 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -55,7 +55,7 @@ static void pos(int x, int y) { - printf("%c[%d;%dH", 27, y + 2, x + 1); + printf("\x1b[%d;%dH", y + 2, x + 1); } static char *screenline(char *line, int *pos) @@ -110,7 +110,7 @@ char *str = screenline(line->data, NULL) + scrcol; pos(0, ypos); str[screenwidth] = 0; - printf("%s%c[K", str, 27); + printf("%s\x1b[K", str); pos(cursx, cursy); } @@ -130,7 +130,7 @@ if (!full) { if (smartscroll) { if (scrline->next == lastscrline) { - printf("%c[1T", 27); + printf("\x1b[1T"); refresh_line(scrline, 0); pos(0, screenheight); printf("%*s", screenwidth, ""); @@ -138,7 +138,7 @@ } if (scrline->prev == lastscrline) { - printf("%c[1S", 27); + printf("\x1b[1S"); for (i = 0; i < screenheight - 1; i++) { l = l->next; if (!l) @@ -378,8 +378,128 @@ pos(0, 0); } +static void statusbar(const char *str) +{ + pos(0, screenheight+1); + printf("%*c\r%s", screenwidth, ' ', str); + pos(cursx, cursy); +} + +static int read_modal_key(bool is_modal) +{ + static enum { MODE_INSERT, MODE_NORMAL } mode = MODE_NORMAL; + static int backlog[2] = { -1, -1 }; + int c; + + if (backlog[0] >= 0) { + /* pop a character */ + c = backlog[0]; + backlog[0] = backlog[1]; + backlog[1] = -1; + } else { + c = read_key(); + } + + if (is_modal && mode == MODE_INSERT && (c == -1 || c == CTL_CH('c'))) { + mode = MODE_NORMAL; + statusbar(""); + return -EAGAIN; + } + + if (!is_modal || mode == MODE_INSERT) + return c; + + switch (c) { + case -1: /* invalid escape, e.g. two escapes in a row */ + break; + case 'i': + statusbar("-- INSERT --"); + mode = MODE_INSERT; + break; + case 'h': + return BB_KEY_LEFT; + case 'j': + return BB_KEY_DOWN; + case 'k': + return BB_KEY_UP; + case 'a': + statusbar("-- INSERT --"); + mode = MODE_INSERT; + /* fall through */ + case 'l': + return BB_KEY_RIGHT; + case 'O': + backlog[0] = '\n'; + backlog[1] = BB_KEY_UP; + /* fall through */ + case 'I': + statusbar("-- INSERT --"); + mode = MODE_INSERT; + /* fall through */ + case '^': + case '0': + return BB_KEY_HOME; + case 'g': + c = read_key(); + if (c != 'g') + break; + backlog[0] = CTL_CH('u'); + backlog[1] = CTL_CH('u'); + /* fall through */ + case CTL_CH('u'): + return BB_KEY_PAGEUP; + case 'G': + backlog[0] = CTL_CH('d'); + backlog[1] = CTL_CH('d'); + /* fall through */ + case CTL_CH('d'): + return BB_KEY_PAGEDOWN; + case 'o': + backlog[0] = '\n'; + /* fall through */ + case 'A': + statusbar("-- INSERT --"); + mode = MODE_INSERT; + /* fall through */ + case '$': + return BB_KEY_END; + case CTL_CH('c'): + statusbar("Type ZQ to abandon all changes and exit vi." + "Type ZZ to exit while saving them."); + break; + case 'x': + return BB_KEY_DEL; + case 'X': + return '\b'; + case BB_KEY_PAGEUP: + case BB_KEY_PAGEDOWN: + case BB_KEY_HOME: + case BB_KEY_END: + case BB_KEY_UP: + case BB_KEY_DOWN: + case BB_KEY_RIGHT: + case BB_KEY_LEFT: + return c; + case ':': + statusbar("ERROR: command mode not supported"); + break; + case 'Z': + c = read_key(); + if (c == 'Z') + return CTL_CH('d'); + if (c == 'Q') + return CTL_CH('c'); + default: + statusbar("ERROR: not implemented"); + break; + } + + return -EAGAIN; +} + static int do_edit(int argc, char *argv[]) { + bool is_vi = false; int lastscrcol; int i; int linepos; @@ -401,10 +521,14 @@ else screenheight = 25; - /* check if we are called as "sedit" instead of "edit" */ - if (*argv[0] == 's') { + /* check if we are not called as "edit" */ + if (*argv[0] != 'e') { smartscroll = 1; getwinsize(); + + /* check if we are called as "vi" */ + if (*argv[0] == 'v') + is_vi = true; } buffer = NULL; @@ -420,18 +544,26 @@ lastscrline = scrline; lastscrcol = 0; - printf("%c[2J", 27); + printf("\x1b[2J"); pos(0, -1); - printf("%c[7m %-25s : Save and quit : quit %c[0m", - 27, argv[1], 27); - printf("%c[2;%dr", 27, screenheight); + if (is_vi) { + screenheight -= 2; + printf("\x1b[7m%*c\x1b[0m", screenwidth , ' '); + pos(0, screenheight-1); + printf("\x1b[7m%*c\x1b[0m", screenwidth , ' '); + printf("\r\x1b[7m%-25s\x1b[0m", argv[1]); + } else { + printf("\x1b[7m %-25s : Save and quit : quit \x1b[0m", + argv[1]); + } + + printf("\x1b[2;%dr", screenheight); + pos(0, 0); screenheight--; /* status line */ - pos(0, 0); - refresh(1); while (1) { @@ -469,7 +601,11 @@ lastscrline = scrline; pos(cursx, cursy); - c = read_key(); +again: + c = read_modal_key(is_vi); + if (c == -EAGAIN) + goto again; + switch (c) { case BB_KEY_UP: if (!curline->prev) @@ -554,12 +690,12 @@ } out: free_buffer(); - printf("%c[2J%c[r", 27, 27); + printf("\x1b[2J\x1b[r"); printf("\n"); return ret; } -static const char * const edit_aliases[] = { "sedit", NULL}; +static const char * const edit_aliases[] = { "sedit", "vi", NULL}; BAREBOX_CMD_HELP_START(edit) BAREBOX_CMD_HELP_TEXT("Use cursor keys, Ctrl-C to exit and Ctrl-D to exit-with-save.") diff --git a/common/Kconfig b/common/Kconfig index b840242..d397d8b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -959,11 +959,11 @@ for more information. config STATE_BACKWARD_COMPATIBLE - bool "backward compatible 'direct storage backend'" + bool "backward compatible 'direct' storage backend" depends on STATE help - With this option enabled the 'direct' storage backend keeps backward - compatibility with older revisions of the state framework. Newer + With this option enabled, the 'direct' storage backend keeps backward + compatibility with the state framework of barebox <= v2016.08.0. Newer revisions expect an additional 'meta header' and fail otherwise. config BOOTCHOOSER diff --git a/common/partitions.c b/common/partitions.c index 574b31f..4162e86 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -54,8 +54,8 @@ partition_name = basprintf("%s.%d", blk->cdev.name, no); if (!partition_name) return -ENOMEM; - dev_dbg(blk->dev, "Registering partition %s on drive %s\n", - partition_name, blk->cdev.name); + dev_dbg(blk->dev, "Registering partition %s on drive %s (partuuid=%s)\n", + partition_name, blk->cdev.name, part->partuuid); cdev = devfs_add_partition(blk->cdev.name, start, size, 0, partition_name); if (IS_ERR(cdev)) { diff --git a/drivers/hw_random/Kconfig b/drivers/hw_random/Kconfig index c579282..242a7ef 100644 --- a/drivers/hw_random/Kconfig +++ b/drivers/hw_random/Kconfig @@ -15,11 +15,11 @@ Generator hardware found on some Freescale i.MX processors. config HWRNG_DEV_RANDOM - tristate "Linux /dev/random and /dev/urandom RNG" + tristate "Linux /dev/urandom RNG" depends on SANDBOX default y help - This driver allows use of the host provided /dev/random - and /dev/urandom as barebox HWRNGs. + This driver allows use of the host provided /dev/urandom + as barebox HWRNGs. endif diff --git a/drivers/mfd/superio.c b/drivers/mfd/superio.c index 0f08d56..12d74b4 100644 --- a/drivers/mfd/superio.c +++ b/drivers/mfd/superio.c @@ -88,7 +88,7 @@ &superio_regmap_config); if (IS_ERR(regmap)) pr_warn("creating %s regmap failed: %s\n", - chipname, strerror(-PTR_ERR(regmap))); + chipname, strerrorp(regmap)); ret = regmap_register_cdev(regmap, chipname); if (ret) diff --git a/drivers/of/of_gpio.c b/drivers/of/of_gpio.c index 9a8331e..7cbeeaf 100644 --- a/drivers/of/of_gpio.c +++ b/drivers/of/of_gpio.c @@ -19,18 +19,20 @@ (!(strcmp(propname, "enable-gpio") && strcmp(propname, "enable-gpios")) && of_device_is_compatible(np, "regulator-gpio")))) { + bool active_low = !of_property_read_bool(np, + "enable-active-high"); /* * The regulator GPIO handles are specified such that the * presence or absence of "enable-active-high" solely controls * the polarity of the GPIO line. Any phandle flags must * be actively ignored. */ - if (*flags & OF_GPIO_ACTIVE_LOW) { + if ((*flags & OF_GPIO_ACTIVE_LOW) && !active_low) { pr_warn("%s GPIO handle specifies active low - ignored\n", np->full_name); *flags &= ~OF_GPIO_ACTIVE_LOW; } - if (!of_property_read_bool(np, "enable-active-high")) + if (active_low) *flags |= OF_GPIO_ACTIVE_LOW; } } diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c index f8bbf2c..5c3a020 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -83,7 +83,7 @@ } if (dev->bus && !dev->driver) - return -ENODEV; + return -EPROBE_DEFER; device_detect(dev); diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 63d624e..e0ef4f5 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -87,8 +87,7 @@ struct device_d *dev = &us->pusb_dev->dev; int i, ret; - - for (i = 0; i < retries; i++) { + for (i = 0; i <= retries; i++) { dev_dbg(dev, "%s\n", usb_stor_opcode_name(cmd[0])); ret = us->transport(usb_blkdev, cmd, cmdlen, data, datalen); dev_dbg(dev, "%s returns %d\n", usb_stor_opcode_name(cmd[0]), @@ -105,6 +104,8 @@ mdelay(request_sense_delay_ms); } + dev_dbg(dev, "Retried %s %d times, and failed.\n", usb_stor_opcode_name(cmd[0]), retries); + return -EIO; } @@ -194,7 +195,7 @@ put_unaligned_be16(blocks, &cmd[7]); return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data, - blocks * SECTOR_SIZE, 2, 0); + blocks * SECTOR_SIZE, 10, 0); } /*********************************************************************** diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 258bb2d..5341e39 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -104,7 +104,7 @@ return NULL; list_for_each_entry(cdev, &cdev_list, list) { - if (!strcmp(cdev->partuuid, partuuid)) + if (!strcasecmp(cdev->partuuid, partuuid)) return cdev; } return NULL; diff --git a/fs/ubootvarfs.c b/fs/ubootvarfs.c index 81ec05d..475e4b7 100644 --- a/fs/ubootvarfs.c +++ b/fs/ubootvarfs.c @@ -409,7 +409,7 @@ list_add_tail(&var->list, &data->var_list); } else { - pr_err("No separator in data @ 0x%08x. Skipped.", + pr_err("No separator in data @ 0x%08tx. Skipped.", blob - start); free(var); } diff --git a/include/param.h b/include/param.h index dea6990..4ac502e 100644 --- a/include/param.h +++ b/include/param.h @@ -264,8 +264,6 @@ } static inline struct param_d *dev_add_param_string_ro(struct device_d *dev, const char *name, - int (*set)(struct param_d *p, void *priv), - int (*get)(struct param_d *p, void *priv), char **value, void *priv) { return dev_add_param_string(dev, name, param_set_readonly, NULL, value, NULL); @@ -285,9 +283,7 @@ } static inline struct param_d *dev_add_param_bitmask_ro(struct device_d *dev, const char *name, - int (*set)(struct param_d *p, void *priv), - int (*get)(struct param_d *p, void *priv), - unsigned long *value, const char * const *names, int max, void *priv) + unsigned long *value, const char * const *names, int max) { return dev_add_param_bitmask(dev, name, param_set_readonly, NULL, value, names, max, NULL); diff --git a/lib/libfile.c b/lib/libfile.c index 02078dd..5a1817e 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -332,7 +332,7 @@ { char *rw_buf = NULL; int srcfd = 0, dstfd = 0; - int r; + int r, s; int ret = 1, err1 = 0; int mode; int total = 0; @@ -343,22 +343,27 @@ srcfd = open(src, O_RDONLY); if (srcfd < 0) { printf("could not open %s: %s\n", src, errno_str()); + ret = srcfd; goto out; } mode = O_WRONLY | O_CREAT; - ret = stat(dst, &dststat); - if (ret && ret != -ENOENT) + s = stat(dst, &dststat); + if (s && s != -ENOENT) { + printf("could not stat %s: %s\n", dst, errno_str()); + ret = s; goto out; + } /* Set O_TRUNC only if file exist and is a regular file */ - if (!ret && S_ISREG(dststat.st_mode)) + if (!s && S_ISREG(dststat.st_mode)) mode |= O_TRUNC; dstfd = open(dst, mode); if (dstfd < 0) { printf("could not open %s: %s\n", dst, errno_str()); + ret = dstfd; goto out; } @@ -373,12 +378,14 @@ r = read(srcfd, rw_buf, RW_BUF_SIZE); if (r < 0) { perror("read"); + ret = r; goto out; } if (!r) break; - if (write_full(dstfd, rw_buf, r) < 0) { + ret = write_full(dstfd, rw_buf, r); + if (ret < 0) { perror("write"); goto out; } diff --git a/lib/parameter.c b/lib/parameter.c index 00e9a9f..fdbb2e7 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -253,11 +253,14 @@ struct param_string *ps = to_param_string(p); int ret; char *value_save = *ps->value; + char *value_new; if (!val) val = ""; - *ps->value = xstrdup(val); + value_new = xstrdup(val); + value_new = strim(value_new); + *ps->value = value_new; if (!ps->set) return 0; diff --git a/lib/readline.c b/lib/readline.c index d026af1..3d16c18 100644 --- a/lib/readline.c +++ b/lib/readline.c @@ -290,10 +290,18 @@ insert = !insert; break; case BB_KEY_ERASE_LINE: - case CTL_CH('u'): BEGINNING_OF_LINE(); ERASE_TO_EOL(); break; + case CTL_CH('u'): + wlen = eol_num - num; + memmove(buf, buf+num, wlen); + BEGINNING_OF_LINE(); + ERASE_TO_EOL(); + eol_num = wlen; + REFRESH_TO_EOL(); + BEGINNING_OF_LINE(); + break; case DEL: case BB_KEY_DEL7: case 8: diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index fe0de87..919f286 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -134,11 +134,6 @@ ld-option = $(call try-run,\ $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) -# ar-option -# Usage: KBUILD_ARFLAGS := $(call ar-option,D) -# Important: no spaces around options -ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) - ###### ###