From 68ba1f1536d717b8e0036c6775ffe2485e8425c4 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Wed, 22 Feb 2017 11:33:19 +0100 Subject: [PATCH 01/11] lib: xz: add support for bcj filters Add missing configuration options for various bcj filters. Without these options the lib/xz/xz_dec_bcj.c file will be compiled, but all filters will be disabled. Signed-off-by: Yegor Yefremov Signed-off-by: Sascha Hauer --- lib/Kconfig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index f9f25bdef..8a94ce09f 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -21,6 +21,30 @@ config LZ4_DECOMPRESS 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 From fc6ce94cdae01776b995496ec7286e46705108e9 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 16 Feb 2017 14:50:04 +0100 Subject: [PATCH 02/11] usb: gadget: fastboot: close fd after download The fd for the downloaded file is never closed. Fix this. Signed-off-by: Sascha Hauer --- drivers/usb/gadget/f_fastboot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index a6192b9eb..974b0b32e 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -597,6 +597,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) 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); From 711bb18961e2c8b8f2fb5ae13a2399740e71a974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Thu, 23 Feb 2017 22:28:41 +0100 Subject: [PATCH 03/11] lseek: ensure errno is set on failure and return -1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All error paths before calling the driver's lseek callback return -1 and set errno. Do the same if the callback returns an error. Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- fs/fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/fs.c b/fs/fs.c index 2b4659cfb..e7b696591 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -926,7 +926,13 @@ loff_t lseek(int fildes, loff_t offset, int whence) 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) From 2eacc573df81ca35dd40d7a853d4a7c37c72857f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Thu, 2 Mar 2017 15:37:03 +0100 Subject: [PATCH 04/11] lseek: tighten error checking and allow negative offsets for SEEK_END MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- fs/fs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index e7b696591..1901c94ad 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -910,6 +910,8 @@ loff_t lseek(int fildes, loff_t offset, int whence) 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,9 +920,9 @@ loff_t lseek(int fildes, loff_t offset, int whence) 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; From 74f750fe65587dc0c46100a0f2b94879b2b1f863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Thu, 2 Mar 2017 17:01:36 +0100 Subject: [PATCH 05/11] tftp: trivial code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- fs/tftp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/tftp.c b/fs/tftp.c index 56d4365d7..ebb81e9fc 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -568,13 +568,11 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize) 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); From ce0cc7fee618306624b34d7c14a492c336d7129c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Fri, 3 Mar 2017 09:48:41 +0100 Subject: [PATCH 06/11] tftp: implement forward seeking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just abuse tftp_read to step forward. Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- fs/tftp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/tftp.c b/fs/tftp.c index ebb81e9fc..847921aa5 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -589,7 +589,32 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize) 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; } From be0c9a3fadedcb784c32fcc6a583e7308b9c76ae Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Thu, 9 Mar 2017 10:57:20 +0100 Subject: [PATCH 07/11] parameter: fix read only int support pass PARAM_FLAG_RO flag for read only it so we can not change them Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- lib/parameter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/parameter.c b/lib/parameter.c index 9f96d0760..65d6c7c0d 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -692,7 +692,7 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name, 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 @@ struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name, 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); From dfcfb5b831e4e229ec84163a9757250b709274ee Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 8 Mar 2017 10:24:01 +0100 Subject: [PATCH 08/11] bbu: Search for cdev names aswell In bbu_find_handler_by_device() search for cdev names aswell since some update handlers are registered with their cdev name and not the full path. Signed-off-by: Sascha Hauer --- common/bbu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/bbu.c b/common/bbu.c index c5dda8c8b..031c43382 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -109,6 +109,15 @@ static struct bbu_handler *bbu_find_handler_by_device(const char *devicepath) if (!devicepath) return NULL; + list_for_each_entry(handler, &bbu_image_handlers, list) + 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; From 3d92ea473884cddad18ab6f0554492f4468bc25f Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Fri, 10 Mar 2017 07:05:21 +0100 Subject: [PATCH 09/11] console_countdown: width to of countdown to 4 digits This patch increases the displayed width of the countdown to 4 digits, otherwise waiting for more then 99 seconds doesn't look good. Signed-off-by: Marc Kleine-Budde Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- common/console_countdown.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/console_countdown.c b/common/console_countdown.c index c0c8c9502..b2eec72b2 100644 --- a/common/console_countdown.c +++ b/common/console_countdown.c @@ -35,7 +35,7 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) countdown = timeout_s; if (!(flags & CONSOLE_COUNTDOWN_SILENT)) - printf("%2d", countdown--); + printf("%4d", countdown--); do { if (tstc()) { @@ -50,7 +50,7 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) } 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)); From e3dda8553eea825e11df4aef80407c66eb2c0df8 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Fri, 10 Mar 2017 07:05:22 +0100 Subject: [PATCH 10/11] console_countdown: add possibility to abort countdown by external commands This patch makes it possible to abort a console countdown by an external command, for example when fastboot is used. This requires additional modifications in the external commands, a call to "console_countdown_abort()" has to be inserted. Signed-off-by: Marc Kleine-Budde Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- commands/timeout.c | 8 ++++++-- common/console_countdown.c | 15 +++++++++++++++ include/console_countdown.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/commands/timeout.c b/commands/timeout.c index ef1a037c1..d197cedd8 100644 --- a/commands/timeout.c +++ b/commands/timeout.c @@ -32,7 +32,7 @@ static int do_timeout(int argc, char *argv[]) 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 @@ static int do_timeout(int argc, char *argv[]) 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_TEXT("Options:") 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_HELP_END 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/console_countdown.c b/common/console_countdown.c index b2eec72b2..03b9b3353 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; @@ -48,6 +55,9 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) 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\b\b%4d", countdown--); @@ -55,6 +65,10 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) } } 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 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) printf("\n"); if (key && out_key) *out_key = key; + console_countdown_timeout_abort = false; return ret; } diff --git a/include/console_countdown.h b/include/console_countdown.h index cb46964bc..c6c2d5c00 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 */ From 939d3a7684ed3138f5e2bfff7cd2876c1e050ca8 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Fri, 10 Mar 2017 07:05:23 +0100 Subject: [PATCH 11/11] fastboot: abort autoboot timeout when fastboot gadget is activated This patch adds a call to "console_countdown_abort()" to abort a currently or upcoming running console timeout. Signed-off-by: Marc Kleine-Budde Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- drivers/usb/gadget/f_fastboot.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 974b0b32e..ef5f7ec6e 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 @@ -815,6 +816,8 @@ static void fb_run_command(struct usb_ep *ep, struct usb_request *req, const cha 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;