diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/Kconfig | 3 | ||||
-rw-r--r-- | commands/Makefile | 1 | ||||
-rw-r--r-- | commands/bootm.c | 1 | ||||
-rw-r--r-- | commands/dhcp.c | 78 | ||||
-rw-r--r-- | commands/loadb.c | 39 | ||||
-rw-r--r-- | commands/loadxy.c | 81 | ||||
-rw-r--r-- | commands/md.c | 11 | ||||
-rw-r--r-- | commands/mem.c | 3 | ||||
-rw-r--r-- | commands/memcmp.c | 3 | ||||
-rw-r--r-- | commands/memcpy.c | 3 | ||||
-rw-r--r-- | commands/memset.c | 3 | ||||
-rw-r--r-- | commands/mm.c | 20 | ||||
-rw-r--r-- | commands/mw.c | 10 |
13 files changed, 164 insertions, 92 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 847ff76d1d..bb6674e6c2 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -385,7 +385,7 @@ config CMD_BOOTM_OFTREE Add support to pass a device tree (a.k.a Open Firmware Tree, oftree). Adds this command line option: - -o DTS specify device tre + -o DTS specify device tree config CMD_BOOTM_OFTREE_UIMAGE bool @@ -1183,6 +1183,7 @@ menu "Network" config CMD_DHCP bool + select NET_DHCP prompt "dhcp" help DHCP client to obtain IP or boot params diff --git a/commands/Makefile b/commands/Makefile index b902f58ec5..36983477be 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -111,3 +111,4 @@ obj-$(CONFIG_CMD_CMP) += cmp.o obj-$(CONFIG_CMD_NV) += nv.o obj-$(CONFIG_CMD_DEFAULTENV) += defaultenv.o obj-$(CONFIG_CMD_STATE) += state.o +obj-$(CONFIG_CMD_DHCP) += dhcp.o diff --git a/commands/bootm.c b/commands/bootm.c index a65864a6db..75849a1bac 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -183,6 +183,7 @@ BAREBOX_MAGICVAR_NAMED(global_bootm_image, global.bootm.image, "bootm default bo BAREBOX_MAGICVAR_NAMED(global_bootm_image_loadaddr, global.bootm.image.loadaddr, "bootm default boot image loadaddr"); BAREBOX_MAGICVAR_NAMED(global_bootm_initrd, global.bootm.initrd, "bootm default initrd"); BAREBOX_MAGICVAR_NAMED(global_bootm_initrd_loadaddr, global.bootm.initrd.loadaddr, "bootm default initrd loadaddr"); +BAREBOX_MAGICVAR_NAMED(global_bootm_oftree, global.bootm.oftree, "bootm default oftree"); static struct binfmt_hook binfmt_uimage_hook = { .type = filetype_uimage, diff --git a/commands/dhcp.c b/commands/dhcp.c new file mode 100644 index 0000000000..eb98bfc2a7 --- /dev/null +++ b/commands/dhcp.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2015 PHYTEC Messtechnik GmbH, + * Author: Wadim Egorov <w.egorov@phytec.de> + * + * Based on work of Sascha Hauer <s.hauer@pengutronix.de>. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <common.h> +#include <command.h> +#include <complete.h> +#include <environment.h> +#include <getopt.h> +#include <dhcp.h> + +static int do_dhcp(int argc, char *argv[]) +{ + int ret, opt; + int retries = DHCP_DEFAULT_RETRY; + struct dhcp_req_param dhcp_param; + + memset(&dhcp_param, 0, sizeof(struct dhcp_req_param)); + getenv_uint("global.dhcp.retries", &retries); + + while ((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) { + switch (opt) { + case 'H': + dhcp_param.hostname = optarg; + break; + case 'v': + dhcp_param.vendor_id = optarg; + break; + case 'c': + dhcp_param.client_id = optarg; + break; + case 'u': + dhcp_param.client_uuid = optarg; + break; + case 'U': + dhcp_param.user_class = optarg; + break; + case 'r': + retries = simple_strtoul(optarg, NULL, 10); + break; + } + } + + if (!retries) { + printf("retries is set to zero, set it to %d\n", DHCP_DEFAULT_RETRY); + retries = DHCP_DEFAULT_RETRY; + } + + ret = dhcp(retries, &dhcp_param); + + return ret; +} + +BAREBOX_CMD_HELP_START(dhcp) +BAREBOX_CMD_HELP_TEXT("Options:") +BAREBOX_CMD_HELP_OPT("-H HOSTNAME", "hostname to send to the DHCP server") +BAREBOX_CMD_HELP_OPT("-v ID\t", "DHCP Vendor ID (code 60) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-c ID\t", "DHCP Client ID (code 61) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-u UUID\t", "DHCP Client UUID (code 97) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-U CLASS", "DHCP User class (code 77) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-r RETRY", "retry limit (default 20)"); +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(dhcp) + .cmd = do_dhcp, + BAREBOX_CMD_DESC("DHCP client to obtain IP or boot params") + BAREBOX_CMD_OPTS("[-HvcuUr]") + BAREBOX_CMD_GROUP(CMD_GRP_NET) + BAREBOX_CMD_HELP(cmd_dhcp_help) + BAREBOX_CMD_COMPLETE(empty_complete) +BAREBOX_CMD_END diff --git a/commands/loadb.c b/commands/loadb.c index 7424bcc08c..be5830da32 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -604,9 +604,8 @@ static int do_load_serial_bin(int argc, char *argv[]) ulong offset = 0; ulong addr; int load_baudrate = 0, current_baudrate; - int rcode = 0; + int rcode = 0, ret; int opt; - int open_mode = O_WRONLY; char *output_file = NULL; struct console_device *cdev = NULL; @@ -621,9 +620,6 @@ static int do_load_serial_bin(int argc, char *argv[]) case 'o': offset = (int)simple_strtoul(optarg, NULL, 10); break; - case 'c': - open_mode |= O_CREAT; - break; default: perror(argv[0]); return 1; @@ -635,7 +631,7 @@ static int do_load_serial_bin(int argc, char *argv[]) printf("%s:No console device with STDIN and STDOUT\n", argv[0]); return -ENODEV; } - current_baudrate = (int)simple_strtoul(dev_get_param(&cdev->class_dev, "baudrate"), NULL, 10); + current_baudrate = console_get_baudrate(cdev); /* Load Defaults */ if (load_baudrate == 0) @@ -644,7 +640,7 @@ static int do_load_serial_bin(int argc, char *argv[]) output_file = DEF_FILE; /* File should exist */ - ofd = open(output_file, open_mode); + ofd = open(output_file, O_WRONLY | O_CREAT); if (ofd < 0) { perror(argv[0]); return 3; @@ -660,17 +656,9 @@ static int do_load_serial_bin(int argc, char *argv[]) } } - if (load_baudrate != current_baudrate) { - printf("## Switch baudrate to %d bps and press ENTER ...\n", - load_baudrate); - udelay(50000); - cdev->setbrg(cdev, load_baudrate); - udelay(50000); - for (;;) { - if (getc() == '\r') - break; - } - } + ret = console_set_baudrate(cdev, load_baudrate); + if (ret) + return ret; printf("## Ready for binary (kermit) download " "to 0x%08lX offset on %s device at %d bps...\n", offset, @@ -681,17 +669,9 @@ static int do_load_serial_bin(int argc, char *argv[]) rcode = 1; } - if (load_baudrate != current_baudrate) { - printf("## Switch baudrate to %d bps and press ESC ...\n", - current_baudrate); - udelay(50000); - cdev->setbrg(cdev, current_baudrate); - udelay(50000); - for (;;) { - if (getc() == 0x1B) /* ESC */ - break; - } - } + ret = console_set_baudrate(cdev, current_baudrate); + if (ret) + return ret; close(ofd); ofd = 0; @@ -704,7 +684,6 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin") BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)") BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate") -BAREBOX_CMD_HELP_OPT("-c", "create file if not present") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(loadb) diff --git a/commands/loadxy.c b/commands/loadxy.c index 1e65cb6221..a4b1bec94d 100644 --- a/commands/loadxy.c +++ b/commands/loadxy.c @@ -40,45 +40,6 @@ #define DEF_FILE "image.bin" -static int console_change_speed(struct console_device *cdev, int baudrate) -{ - int current_baudrate; - const char *bstr; - - bstr = dev_get_param(&cdev->class_dev, "baudrate"); - current_baudrate = bstr ? (int)simple_strtoul(bstr, NULL, 10) : 0; - if (baudrate && baudrate != current_baudrate) { - printf("## Switch baudrate from %d to %d bps and press ENTER ...\n", - current_baudrate, baudrate); - mdelay(50); - cdev->setbrg(cdev, baudrate); - mdelay(50); - } - return current_baudrate; -} - -static struct console_device *get_named_console(const char *cname) -{ - struct console_device *cdev; - const char *target; - - /* - * Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the - * same output console - */ - for_each_console(cdev) { - target = dev_id(&cdev->class_dev); - if (strlen(target) != strlen(cname)) - continue; - printf("RJK: looking for %s in console name %s\n", - cname, target); - if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) - && !strcmp(cname, target)) - return cdev; - } - return NULL; -} - /** * @brief provide the loady(Y-Modem or Y-Modem/G) support * @@ -112,7 +73,7 @@ static int do_loady(int argc, char *argv[]) } if (cname) - cdev = get_named_console(cname); + cdev = console_get_by_name(cname); else cdev = console_get_first_active(); if (!cdev) { @@ -121,7 +82,15 @@ static int do_loady(int argc, char *argv[]) return -ENODEV; } - current_baudrate = console_change_speed(cdev, load_baudrate); + current_baudrate = console_get_baudrate(cdev); + + if (!load_baudrate) + load_baudrate = current_baudrate; + + rc = console_set_baudrate(cdev, load_baudrate); + if (rc) + return rc; + printf("## Ready for binary (ymodem) download at %d bps...\n", load_baudrate ? load_baudrate : current_baudrate); @@ -135,7 +104,9 @@ static int do_loady(int argc, char *argv[]) rcode = 1; } - console_change_speed(cdev, current_baudrate); + rc = console_set_baudrate(cdev, current_baudrate); + if (rc) + return rc; return rcode; } @@ -167,8 +138,7 @@ BAREBOX_CMD_END static int do_loadx(int argc, char *argv[]) { ulong offset = 0; - int load_baudrate = 0, current_baudrate, ofd, opt, rcode = 0; - int open_mode = O_WRONLY; + int load_baudrate = 0, current_baudrate, rc, ofd, opt, rcode = 0; char *output_file = NULL, *cname = NULL; struct console_device *cdev = NULL; @@ -183,9 +153,6 @@ static int do_loadx(int argc, char *argv[]) case 'o': offset = (int)simple_strtoul(optarg, NULL, 10); break; - case 'c': - open_mode |= O_CREAT; - break; case 't': cname = optarg; break; @@ -196,7 +163,7 @@ static int do_loadx(int argc, char *argv[]) } if (cname) - cdev = get_named_console(cname); + cdev = console_get_by_name(cname); else cdev = console_get_first_active(); if (!cdev) { @@ -210,7 +177,7 @@ static int do_loadx(int argc, char *argv[]) output_file = DEF_FILE; /* File should exist */ - ofd = open(output_file, open_mode); + ofd = open(output_file, O_WRONLY | O_CREAT); if (ofd < 0) { perror(argv[0]); return 3; @@ -226,7 +193,15 @@ static int do_loadx(int argc, char *argv[]) } } - current_baudrate = console_change_speed(cdev, load_baudrate); + current_baudrate = console_get_baudrate(cdev); + + if (!load_baudrate) + load_baudrate = current_baudrate; + + rc = console_set_baudrate(cdev, load_baudrate); + if (rc) + return rc; + printf("## Ready for binary (xmodem) download " "to 0x%08lX offset on %s device at %d bps...\n", offset, output_file, load_baudrate ? load_baudrate : current_baudrate); @@ -235,7 +210,10 @@ static int do_loadx(int argc, char *argv[]) printf("## Binary (xmodem) download aborted (%d)\n", rcode); rcode = 1; } - console_change_speed(cdev, current_baudrate); + + rc = console_set_baudrate(cdev, current_baudrate); + if (rc) + return rc; return rcode; } @@ -246,7 +224,6 @@ BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin") BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)") BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate") BAREBOX_CMD_HELP_OPT("-t NAME", "console name to use (default: current)") -BAREBOX_CMD_HELP_OPT("-c", "create file if not present") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(loadx) diff --git a/commands/md.c b/commands/md.c index c1361a6a21..c88259a3f8 100644 --- a/commands/md.c +++ b/commands/md.c @@ -44,11 +44,12 @@ static int do_mem_md(int argc, char *argv[]) char *filename = "/dev/mem"; int mode = O_RWSIZE_4; int swab = 0; + void *map; if (argc < 2) return COMMAND_ERROR_USAGE; - if (mem_parse_options(argc, argv, "bwls:x", &mode, &filename, NULL, + if (mem_parse_options(argc, argv, "bwlqs:x", &mode, &filename, NULL, &swab) < 0) return 1; @@ -65,6 +66,13 @@ static int do_mem_md(int argc, char *argv[]) if (fd < 0) return 1; + map = memmap(fd, PROT_READ); + if (map != (void *)-1) { + ret = memory_display(map + start, start, size, + mode >> O_RWSIZE_SHIFT, swab); + goto out; + } + do { now = min(size, (loff_t)RW_BUF_SIZE); r = read(fd, mem_rw_buf, now); @@ -97,6 +105,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-s FILE", "display file (default /dev/mem)") BAREBOX_CMD_HELP_OPT ("-x", "swap bytes at output") BAREBOX_CMD_HELP_TEXT("") diff --git a/commands/mem.c b/commands/mem.c index 568050d34b..23c703f0b5 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -84,6 +84,9 @@ int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, case 'l': *mode = O_RWSIZE_4; break; + case 'q': + *mode = O_RWSIZE_8; + break; case 's': *sourcefile = optarg; break; diff --git a/commands/memcmp.c b/commands/memcmp.c index d048150672..e079d5f78e 100644 --- a/commands/memcmp.c +++ b/commands/memcmp.c @@ -49,7 +49,7 @@ static int do_memcmp(int argc, char *argv[]) int offset = 0; struct stat statbuf; - if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile, + if (mem_parse_options(argc, argv, "bwlqs:d:", &mode, &sourcefile, &destfile, NULL) < 0) return 1; @@ -138,6 +138,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-s FILE", "source file (default /dev/mem)") BAREBOX_CMD_HELP_OPT ("-d FILE", "destination file (default /dev/mem)") BAREBOX_CMD_HELP_END diff --git a/commands/memcpy.c b/commands/memcpy.c index 78716b1bbc..9c8b64525c 100644 --- a/commands/memcpy.c +++ b/commands/memcpy.c @@ -47,7 +47,7 @@ static int do_memcpy(int argc, char *argv[]) struct stat statbuf; int ret = 0; - if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile, + if (mem_parse_options(argc, argv, "bwlqs:d:", &mode, &sourcefile, &destfile, NULL) < 0) return 1; @@ -135,6 +135,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-s FILE", "source file (default /dev/mem)") BAREBOX_CMD_HELP_OPT ("-d FILE", "write file (default /dev/mem)") BAREBOX_CMD_HELP_END diff --git a/commands/memset.c b/commands/memset.c index bb5f46de7a..fc5b659b9b 100644 --- a/commands/memset.c +++ b/commands/memset.c @@ -44,7 +44,7 @@ static int do_memset(int argc, char *argv[]) int ret = 1; char *file = "/dev/mem"; - if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &file, + if (mem_parse_options(argc, argv, "bwlqd:", &mode, NULL, &file, NULL) < 0) return 1; @@ -92,6 +92,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-d FILE", "write file (default /dev/mem)") BAREBOX_CMD_HELP_END diff --git a/commands/mm.c b/commands/mm.c index ff2e746670..7c890a6696 100644 --- a/commands/mm.c +++ b/commands/mm.c @@ -38,9 +38,10 @@ static int do_mem_mm(int argc, char *argv[]) u8 val8; u16 val16; u32 val32; - u32 value, mask; + u64 val64; + u64 value, mask; - if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename, + if (mem_parse_options(argc, argv, "bwlqd:", &mode, NULL, &filename, &swab) < 0) return 1; @@ -48,8 +49,8 @@ static int do_mem_mm(int argc, char *argv[]) return COMMAND_ERROR_USAGE; adr = strtoull_suffix(argv[optind++], NULL, 0); - value = simple_strtoul(argv[optind++], NULL, 0); - mask = simple_strtoul(argv[optind++], NULL, 0); + value = simple_strtoull(argv[optind++], NULL, 0); + mask = simple_strtoull(argv[optind++], NULL, 0); fd = open_and_lseek(filename, mode | O_RDWR, adr); if (fd < 0) @@ -86,6 +87,16 @@ static int do_mem_mm(int argc, char *argv[]) if (ret < 0) goto out_write; break; + case O_RWSIZE_8: + if (ret < 0) + goto out_read; + ret = pread(fd, &val64, 8, adr); + val64 &= ~mask; + val64 |= (value & mask); + ret = pwrite(fd, &val64, 8, adr); + if (ret < 0) + goto out_write; + break; } close(fd); @@ -110,6 +121,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-d FILE", "write file (default /dev/mem)") BAREBOX_CMD_HELP_END diff --git a/commands/mw.c b/commands/mw.c index f0384f6435..8ca3c61d7f 100644 --- a/commands/mw.c +++ b/commands/mw.c @@ -42,7 +42,7 @@ static int do_mem_mw(int argc, char *argv[]) loff_t adr; int swab = 0; - if (mem_parse_options(argc, argv, "bwld:x", &mode, NULL, &filename, + if (mem_parse_options(argc, argv, "bwlqd:x", &mode, NULL, &filename, &swab) < 0) return 1; @@ -59,6 +59,7 @@ static int do_mem_mw(int argc, char *argv[]) u8 val8; u16 val16; u32 val32; + u64 val64; switch (mode) { case O_RWSIZE_1: val8 = simple_strtoul(argv[optind], NULL, 0); @@ -76,6 +77,12 @@ static int do_mem_mw(int argc, char *argv[]) val32 = __swab32(val32); ret = write(fd, &val32, 4); break; + case O_RWSIZE_8: + val64 = simple_strtoull(argv[optind], NULL, 0); + if (swab) + val64 = __swab64(val64); + ret = write(fd, &val64, 8); + break; } if (ret < 0) { perror("write"); @@ -97,6 +104,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-b", "byte access") BAREBOX_CMD_HELP_OPT ("-w", "word access (16 bit)") BAREBOX_CMD_HELP_OPT ("-l", "long access (32 bit)") +BAREBOX_CMD_HELP_OPT ("-q", "quad access (64 bit)") BAREBOX_CMD_HELP_OPT ("-d FILE", "write file (default /dev/mem)") BAREBOX_CMD_HELP_END |