diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-03-07 09:25:09 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-03-07 09:25:09 +0100 |
commit | a8a08f88cc8c2c78bcc421cd55144813b081bcec (patch) | |
tree | 67e818ea7ce5ab531251467e13fa3ec3e18e11c7 /commands | |
parent | 2331b1d8e8d7aabe52b4fd65ca200cf8288aec88 (diff) | |
parent | d0343211a27b982c3ef61597b68a6bf76df887af (diff) | |
download | barebox-a8a08f88cc8c2c78bcc421cd55144813b081bcec.tar.gz barebox-a8a08f88cc8c2c78bcc421cd55144813b081bcec.tar.xz |
Merge branch 'for-next/misc'
Conflicts:
common/environment.c
Diffstat (limited to 'commands')
-rw-r--r-- | commands/Kconfig | 6 | ||||
-rw-r--r-- | commands/Makefile | 1 | ||||
-rw-r--r-- | commands/boot.c | 2 | ||||
-rw-r--r-- | commands/dfu.c | 11 | ||||
-rw-r--r-- | commands/edit.c | 2 | ||||
-rw-r--r-- | commands/readf.c | 63 |
6 files changed, 80 insertions, 5 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 1e07b5b7ac..352e8bf46f 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -57,6 +57,12 @@ config CMD_READLINE tristate prompt "readline" +config CMD_READF + tristate + prompt "readf" + help + The readf command is used to read a files content into a shell variable. + config CMD_LET tristate prompt "let" diff --git a/commands/Makefile b/commands/Makefile index 58d27fa905..91ec0e9fa9 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -93,3 +93,4 @@ obj-$(CONFIG_CMD_MIITOOL) += miitool.o obj-$(CONFIG_CMD_DETECT) += detect.o obj-$(CONFIG_CMD_BOOT) += boot.o obj-$(CONFIG_CMD_DEVINFO) += devinfo.o +obj-$(CONFIG_CMD_READF) += readf.o diff --git a/commands/boot.c b/commands/boot.c index c4b49a9035..ccf5827a59 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -308,7 +308,7 @@ static int boot(const char *name) { struct blspec *blspec; struct blspec_entry *entry; - int ret = -ENOENT; + int ret; blspec = blspec_alloc(); ret = bootentry_parse_one(blspec, name); diff --git a/commands/dfu.c b/commands/dfu.c index 99a381f18a..2513ed883b 100644 --- a/commands/dfu.c +++ b/commands/dfu.c @@ -128,9 +128,14 @@ static int do_dfu(int argc, char *argv[]) argstr = argv[optind]; - if (!idProduct || !idVendor) { - printf("productid or vendorid not given\n"); - return 1; + if (!idProduct && !idVendor) { + idVendor = 0x1d50; /* Openmoko, Inc */ + idProduct = 0x60a2; /* barebox bootloader USB DFU Mode */ + } + + if ((idProduct && !idVendor) || (!idProduct && idVendor)) { + printf("Only one of vendor id or product id given\n"); + return -EINVAL; } for (n = 0; *argstr; n++) { diff --git a/commands/edit.c b/commands/edit.c index 6764e84efd..b0fcf69fdd 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -266,7 +266,7 @@ static int save_file(const char *path) fd = open(path, O_WRONLY | O_TRUNC | O_CREAT); if (fd < 0) { printf("could not open file for writing: %s\n", errno_str()); - return -1; + return fd; } line = buffer; diff --git a/commands/readf.c b/commands/readf.c new file mode 100644 index 0000000000..6314c7ef23 --- /dev/null +++ b/commands/readf.c @@ -0,0 +1,63 @@ +#include <common.h> +#include <command.h> +#include <fs.h> +#include <malloc.h> +#include <linux/stat.h> +#include <linux/ctype.h> +#include <environment.h> + +static int do_readf(int argc, char *argv[]) +{ + unsigned char *buf = NULL, *val; + char *variable, *filename; + struct stat s; + size_t size; + int ret, i; + + if (argc != 3) + return COMMAND_ERROR_USAGE; + + filename = argv[1]; + variable = argv[2]; + + ret = stat(filename, &s); + if (ret) + goto out; + + if (s.st_size > 1024) { + ret = -EFBIG; + goto out; + } + + buf = read_file(filename, &size); + if (!buf) + goto out; + + for (i = 0; i < size; i++) { + if (!isprint(buf[i])) { + buf[i] = '\0'; + break; + } + } + + val = strim(buf); + + ret = setenv(variable, val); +out: + free(buf); + + return ret; +} + +BAREBOX_CMD_HELP_START(readf) +BAREBOX_CMD_HELP_USAGE("readf <file> <variable>\n") +BAREBOX_CMD_HELP_SHORT("Read a single line of a file into a shell variable. Leading and trailing whitespaces\n") +BAREBOX_CMD_HELP_SHORT("are removed, nonvisible characters are stripped. Input is limited to 1024\n") +BAREBOX_CMD_HELP_SHORT("characters.\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(readf) + .cmd = do_readf, + .usage = "read file into variable", + BAREBOX_CMD_HELP(cmd_readf_help) +BAREBOX_CMD_END |