diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-11-07 14:26:42 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-11-07 14:26:42 +0100 |
commit | 422d0ae2cd4a4a4cb38eac3526a704ae94f96646 (patch) | |
tree | 997389eb927cbc2a4ab02ef73d727ca1211415ee | |
parent | 989ca04ca49a023de81b6a7cdda8f2650e17d7ee (diff) | |
parent | 361ecbfff18fe2051b69dbbfa6efe6a2d054863f (diff) | |
download | barebox-422d0ae2cd4a4a4cb38eac3526a704ae94f96646.tar.gz barebox-422d0ae2cd4a4a4cb38eac3526a704ae94f96646.tar.xz |
Merge branch 'for-next/misc'
-rw-r--r-- | arch/sandbox/board/dev-random.c | 7 | ||||
-rw-r--r-- | arch/sandbox/mach-sandbox/include/mach/linux.h | 1 | ||||
-rw-r--r-- | arch/sandbox/os/common.c | 10 | ||||
-rw-r--r-- | commands/Kconfig | 6 | ||||
-rw-r--r-- | commands/cp.c | 3 | ||||
-rw-r--r-- | commands/edit.c | 166 | ||||
-rw-r--r-- | common/Kconfig | 6 | ||||
-rw-r--r-- | common/partitions.c | 4 | ||||
-rw-r--r-- | drivers/hw_random/Kconfig | 6 | ||||
-rw-r--r-- | drivers/mfd/superio.c | 2 | ||||
-rw-r--r-- | drivers/of/of_gpio.c | 6 | ||||
-rw-r--r-- | drivers/of/of_path.c | 2 | ||||
-rw-r--r-- | drivers/usb/storage/usb.c | 7 | ||||
-rw-r--r-- | fs/devfs-core.c | 2 | ||||
-rw-r--r-- | fs/ubootvarfs.c | 2 | ||||
-rw-r--r-- | include/param.h | 6 | ||||
-rw-r--r-- | lib/libfile.c | 17 | ||||
-rw-r--r-- | lib/parameter.c | 5 | ||||
-rw-r--r-- | lib/readline.c | 8 | ||||
-rw-r--r-- | scripts/Kbuild.include | 5 |
20 files changed, 212 insertions, 59 deletions
diff --git a/arch/sandbox/board/dev-random.c b/arch/sandbox/board/dev-random.c index f65e5ef6e5..60295e9fce 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 @@ devrandom_t *devrandom_init(void) { 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 1e64d41c6a..9759a376ec 100644 --- a/arch/sandbox/mach-sandbox/include/mach/linux.h +++ b/arch/sandbox/mach-sandbox/include/mach/linux.h @@ -52,7 +52,6 @@ int barebox_libftdi1_update(struct ft2232_bitbang *ftbb); 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 86118822a1..3ad12b4a30 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -39,6 +39,8 @@ #include <signal.h> #include <sys/select.h> #include <sys/wait.h> +#include <sys/ioctl.h> +#include <linux/fs.h> /* * ...except the ones needed to connect with barebox */ @@ -260,11 +262,17 @@ static int add_image(char *str, char *devname_template, int *devname_number) 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 0189b4715b..a6db52ae54 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -1389,8 +1389,10 @@ config CMD_PASSWD 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 54934dd64f..845dae6b15 100644 --- a/commands/cp.c +++ b/commands/cp.c @@ -100,13 +100,14 @@ BAREBOX_CMD_HELP_START(cp) 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 ba6a8c7cdd..4e661df14f 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -55,7 +55,7 @@ static int scrcol = 0; /* the first column on screen */ 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 @@ static void refresh_line(struct line *line, int ypos) 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 @@ static void refresh(int full) 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 @@ static void refresh(int full) } 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 @@ static void getwinsize(void) 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 @@ static int do_edit(int argc, char *argv[]) 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 @@ static int do_edit(int argc, char *argv[]) lastscrline = scrline; lastscrcol = 0; - printf("%c[2J", 27); + printf("\x1b[2J"); pos(0, -1); - printf("%c[7m %-25s <ctrl-d>: Save and quit <ctrl-c>: quit %c[0m", - 27, argv[1], 27); - printf("%c[2;%dr", 27, screenheight); - - screenheight--; /* status line */ + 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 <ctrl-d>: Save and quit <ctrl-c>: quit \x1b[0m", + argv[1]); + } + printf("\x1b[2;%dr", screenheight); pos(0, 0); + screenheight--; /* status line */ + refresh(1); while (1) { @@ -469,7 +601,11 @@ static int do_edit(int argc, char *argv[]) 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 @@ static int do_edit(int argc, char *argv[]) } 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 b840242ac9..d397d8bc4d 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -959,11 +959,11 @@ config STATE_CRYPTO 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 574b31fbbe..4162e86804 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -54,8 +54,8 @@ static int register_one_partition(struct block_device *blk, 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 c57928204d..242a7ef278 100644 --- a/drivers/hw_random/Kconfig +++ b/drivers/hw_random/Kconfig @@ -15,11 +15,11 @@ config HWRNG_MXC_RNGC 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 0f08d56cb3..12d74b40f6 100644 --- a/drivers/mfd/superio.c +++ b/drivers/mfd/superio.c @@ -88,7 +88,7 @@ void superio_chip_add(struct superio_chip *siochip) &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 9a8331ed18..7cbeeaf69e 100644 --- a/drivers/of/of_gpio.c +++ b/drivers/of/of_gpio.c @@ -19,18 +19,20 @@ static void of_gpio_flags_quirks(struct device_node *np, (!(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 f8bbf2cba1..5c3a020345 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -83,7 +83,7 @@ static int __of_find_path(struct device_node *node, const char *part, char **out } 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 63d624e91b..e0ef4f5ef3 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -87,8 +87,7 @@ static int usb_stor_transport(struct us_blk_dev *usb_blkdev, 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 @@ static int usb_stor_transport(struct us_blk_dev *usb_blkdev, 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 @@ static int usb_stor_io_10(struct us_blk_dev *usb_blkdev, u8 opcode, 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 258bb2dbaa..5341e39e67 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -104,7 +104,7 @@ struct cdev *cdev_by_partuuid(const char *partuuid) 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 81ec05d5ef..475e4b7a79 100644 --- a/fs/ubootvarfs.c +++ b/fs/ubootvarfs.c @@ -409,7 +409,7 @@ static void ubootvarfs_parse(struct ubootvarfs_data *data, char *blob, 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 dea6990497..4ac502e726 100644 --- a/include/param.h +++ b/include/param.h @@ -264,8 +264,6 @@ static inline struct param_d *dev_add_param_bool_ro(struct device_d *dev, const } 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_enum_ro(struct device_d *dev, const } 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 02078dd43d..5a1817e32a 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -332,7 +332,7 @@ int copy_file(const char *src, const char *dst, int verbose) { 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 @@ int copy_file(const char *src, const char *dst, int verbose) 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 @@ int copy_file(const char *src, const char *dst, int verbose) 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 00e9a9ff4e..fdbb2e71d1 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -253,11 +253,14 @@ static int param_string_set(struct device_d *dev, struct param_d *p, const char 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 d026af1104..3d16c1838c 100644 --- a/lib/readline.c +++ b/lib/readline.c @@ -290,9 +290,17 @@ int readline(const char *prompt, char *buf, int len) insert = !insert; break; case BB_KEY_ERASE_LINE: + 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: diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index fe0de87240..919f286162 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -134,11 +134,6 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3)) 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)) - ###### ### |