9
0
Fork 0

Merge branch 'for-next/misc'

This commit is contained in:
Sascha Hauer 2017-03-13 08:16:44 +01:00
commit e0093dcf23
9 changed files with 105 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

14
fs/fs.c
View File

@ -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)

View File

@ -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;
}

View File

@ -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 */

View File

@ -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

View File

@ -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);