summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-03-13 08:16:44 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-03-13 08:16:44 +0100
commite0093dcf236cdc1d4faef95189c9376ef6610ae7 (patch)
treead41b7daf6e194ad32b0b6a7b33e652c45bd9d38
parent4e11672653a4ad639ca2d2158b1266b258951f93 (diff)
parent939d3a7684ed3138f5e2bfff7cd2876c1e050ca8 (diff)
downloadbarebox-e0093dcf236cdc1d4faef95189c9376ef6610ae7.tar.gz
barebox-e0093dcf236cdc1d4faef95189c9376ef6610ae7.tar.xz
Merge branch 'for-next/misc'
-rw-r--r--commands/timeout.c8
-rw-r--r--common/bbu.c9
-rw-r--r--common/console_countdown.c19
-rw-r--r--drivers/usb/gadget/f_fastboot.c4
-rw-r--r--fs/fs.c14
-rw-r--r--fs/tftp.c37
-rw-r--r--include/console_countdown.h2
-rw-r--r--lib/Kconfig24
-rw-r--r--lib/parameter.c4
9 files changed, 105 insertions, 16 deletions
diff --git a/commands/timeout.c b/commands/timeout.c
index ef1a037c19..d197cedd8b 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 <VARIABLE>", "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/bbu.c b/common/bbu.c
index c5dda8c8bd..031c433820 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -113,6 +113,15 @@ static struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
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 c0c8c95022..03b9b33538 100644
--- a/common/console_countdown.c
+++ b/common/console_countdown.c
@@ -23,6 +23,13 @@
#include <console_countdown.h>
#include <stdio.h>
+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 @@ 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()) {
@@ -48,13 +55,20 @@ 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%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 @@ 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/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index a6192b9ebd..ef5f7ec6e0 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -36,6 +36,7 @@
#include <environment.h>
#include <globalvar.h>
#include <restart.h>
+#include <console_countdown.h>
#include <usb/ch9.h>
#include <usb/gadget.h>
#include <usb/fastboot.h>
@@ -597,6 +598,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);
@@ -814,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;
diff --git a/fs/fs.c b/fs/fs.c
index 2b4659cfbb..1901c94ad1 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,15 +920,21 @@ 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;
}
- 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 56d4365d77..847921aa56 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);
@@ -591,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;
}
diff --git a/include/console_countdown.h b/include/console_countdown.h
index cb46964bc4..c6c2d5c00e 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 f9f25bdef8..8a94ce09fb 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
diff --git a/lib/parameter.c b/lib/parameter.c
index 9f96d0760d..65d6c7c0df 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);