diff --git a/commands/timeout.c b/commands/timeout.c index ef1a037..d197ced 100644 --- a/commands/timeout.c +++ b/commands/timeout.c @@ -32,7 +32,7 @@ char str[2] = { }; const char *varname = NULL; - while((opt = getopt(argc, argv, "crsav:")) > 0) { + while ((opt = getopt(argc, argv, "crsav:e")) > 0) { switch(opt) { case 'r': flags |= CONSOLE_COUNTDOWN_RETURN; @@ -46,6 +46,9 @@ case 's': flags |= CONSOLE_COUNTDOWN_SILENT; break; + case 'e': + flags |= CONSOLE_COUNTDOWN_EXTERN; + break; case 'v': varname = optarg; break; @@ -73,6 +76,7 @@ BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key") BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C") BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN") +BAREBOX_CMD_HELP_OPT("-e", "interrupt on external commands (i.e. fastboot") BAREBOX_CMD_HELP_OPT("-s", "silent mode") BAREBOX_CMD_HELP_OPT("-v ", "export pressed key to environment") BAREBOX_CMD_HELP_END @@ -80,7 +84,7 @@ BAREBOX_CMD_START(timeout) .cmd = do_timeout, BAREBOX_CMD_DESC("wait for a specified timeout") - BAREBOX_CMD_OPTS("[-acrsv] SECONDS") + BAREBOX_CMD_OPTS("[-acrsev] SECONDS") BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE) BAREBOX_CMD_HELP(cmd_timeout_help) BAREBOX_CMD_END diff --git a/common/bbu.c b/common/bbu.c index c5dda8c..031c433 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -113,6 +113,15 @@ if (!strcmp(handler->devicefile, devicepath)) return handler; + if (strncmp(devicepath, "/dev/", 5)) + return NULL; + + devicepath += 5; + + list_for_each_entry(handler, &bbu_image_handlers, list) + if (!strcmp(handler->devicefile, devicepath)) + return handler; + return NULL; } diff --git a/common/console_countdown.c b/common/console_countdown.c index c0c8c95..03b9b33 100644 --- a/common/console_countdown.c +++ b/common/console_countdown.c @@ -23,6 +23,13 @@ #include #include +static bool console_countdown_timeout_abort; + +void console_countdown_abort(void) +{ + console_countdown_timeout_abort = true; +} + int console_countdown(int timeout_s, unsigned flags, char *out_key) { uint64_t start, second; @@ -35,7 +42,7 @@ countdown = timeout_s; if (!(flags & CONSOLE_COUNTDOWN_SILENT)) - printf("%2d", countdown--); + printf("%4d", countdown--); do { if (tstc()) { @@ -48,13 +55,20 @@ goto out; key = 0; } + if ((flags & CONSOLE_COUNTDOWN_EXTERN) && + console_countdown_timeout_abort) + goto out; if (!(flags & CONSOLE_COUNTDOWN_SILENT) && is_timeout(second, SECOND)) { - printf("\b\b%2d", countdown--); + printf("\b\b\b\b%4d", countdown--); second += SECOND; } } while (!is_timeout(start, timeout_s * SECOND)); + if ((flags & CONSOLE_COUNTDOWN_EXTERN) && + console_countdown_timeout_abort) + goto out; + ret = 0; out: @@ -62,6 +76,7 @@ printf("\n"); if (key && out_key) *out_key = key; + console_countdown_timeout_abort = false; return ret; } diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index a6192b9..ef5f7ec 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -597,6 +598,7 @@ if (f_fb->download_bytes >= f_fb->download_size) { req->complete = rx_handler_command; req->length = EP_BUFFER_SIZE; + close(f_fb->download_fd); fastboot_tx_print(f_fb, "INFODownloading %d bytes finished", f_fb->download_bytes); @@ -814,6 +816,8 @@ struct f_fastboot *f_fb = req->context; int i; + console_countdown_abort(); + for (i = 0; i < num_commands; i++) { if (!strcmp_l1(cmds[i].cmd, cmd)) { func_cb = cmds[i].cb; diff --git a/fs/fs.c b/fs/fs.c index 2b4659c..1901c94 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -910,6 +910,8 @@ case SEEK_SET: if (f->size != FILE_SIZE_STREAM && offset > f->size) goto out; + if (offset < 0) + goto out; pos = offset; break; case SEEK_CUR: @@ -918,15 +920,21 @@ pos = f->pos + offset; break; case SEEK_END: - if (offset) + if (offset > 0) goto out; - pos = f->size; + pos = f->size + offset; break; default: goto out; } - return fsdrv->lseek(&f->fsdev->dev, f, pos); + pos = fsdrv->lseek(&f->fsdev->dev, f, pos); + if (pos < 0) { + errno = -pos; + return -1; + } + + return pos; out: if (ret) diff --git a/fs/tftp.c b/fs/tftp.c index 56d4365..847921a 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -568,13 +568,11 @@ while (insize) { now = kfifo_get(priv->fifo, buf, insize); + outsize += now; + buf += now; + insize -= now; if (priv->state == STATE_DONE) - return outsize + now; - if (now) { - outsize += now; - buf += now; - insize -= now; - } + return outsize; if (TFTP_FIFO_SIZE - kfifo_len(priv->fifo) >= priv->blocksize) tftp_send(priv); @@ -591,7 +589,32 @@ static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos) { - /* not implemented in tftp protocol */ + /* We cannot seek backwards without reloading or caching the file */ + if (pos >= f->pos) { + loff_t ret; + char *buf = xmalloc(1024); + + while (pos > f->pos) { + size_t len = min_t(size_t, 1024, pos - f->pos); + + ret = tftp_read(dev, f, buf, len); + + if (!ret) + /* EOF, so the desired pos is invalid. */ + ret = -EINVAL; + if (ret < 0) + goto out_free; + + f->pos += ret; + } + + ret = pos; + +out_free: + free(buf); + return ret; + } + return -ENOSYS; } diff --git a/include/console_countdown.h b/include/console_countdown.h index cb46964..c6c2d5c 100644 --- a/include/console_countdown.h +++ b/include/console_countdown.h @@ -5,7 +5,9 @@ #define CONSOLE_COUNTDOWN_ANYKEY (1 << 1) #define CONSOLE_COUNTDOWN_RETURN (1 << 3) #define CONSOLE_COUNTDOWN_CTRLC (1 << 4) +#define CONSOLE_COUNTDOWN_EXTERN (1 << 5) int console_countdown(int timeout_s, unsigned flags, char *out_key); +void console_countdown_abort(void); #endif /* __CONSOLE_COUNTDOWN_H */ diff --git a/lib/Kconfig b/lib/Kconfig index f9f25bd..8a94ce0 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -21,6 +21,30 @@ config XZ_DECOMPRESS bool "include xz uncompression support" select UNCOMPRESS + select XZ_DEC_X86 + select XZ_DEC_POWERPC + select XZ_DEC_IA64 + select XZ_DEC_ARM + select XZ_DEC_ARMTHUMB + select XZ_DEC_SPARC + +config XZ_DEC_X86 + bool + +config XZ_DEC_POWERPC + bool + +config XZ_DEC_IA64 + bool + +config XZ_DEC_ARM + bool + +config XZ_DEC_ARMTHUMB + bool + +config XZ_DEC_SPARC + bool config REED_SOLOMON bool diff --git a/lib/parameter.c b/lib/parameter.c index 9f96d07..65d6c7c 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -692,7 +692,7 @@ piro = xzalloc(sizeof(*piro)); - ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, 0); + ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, PARAM_FLAG_RO); if (ret) { free(piro); return ERR_PTR(ret); @@ -718,7 +718,7 @@ piro = xzalloc(sizeof(*piro)); - ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, 0); + ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, PARAM_FLAG_RO); if (ret) { free(piro); return ERR_PTR(ret);