From b2c5310d4da56237571bb8ea8d24b030c941030f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 5 Jul 2007 18:02:14 +0200 Subject: svn_rev_653 restructure tree, add reginfo command --- commands/Kconfig | 56 +++++++ commands/Makefile | 13 +- commands/bootm.c | 18 --- commands/cat.c | 64 ++++++++ commands/cd.c | 32 ++++ commands/cp.c | 68 +++++++++ commands/environment.c | 17 ++- commands/flash.c | 125 ++++++++++++++++ commands/fs.c | 391 ------------------------------------------------- commands/ls.c | 122 +++++++++++++++ commands/mem.c | 103 ------------- commands/mkdir.c | 35 +++++ commands/mount.c | 53 +++++++ commands/pwd.c | 15 ++ commands/reginfo.c | 14 ++ commands/rm.c | 30 ++++ commands/rmdir.c | 35 +++++ commands/umount.c | 31 ++++ 18 files changed, 707 insertions(+), 515 deletions(-) create mode 100644 commands/cat.c create mode 100644 commands/cd.c create mode 100644 commands/cp.c create mode 100644 commands/flash.c delete mode 100644 commands/fs.c create mode 100644 commands/ls.c create mode 100644 commands/mkdir.c create mode 100644 commands/mount.c create mode 100644 commands/pwd.c create mode 100644 commands/reginfo.c create mode 100644 commands/rm.c create mode 100644 commands/rmdir.c create mode 100644 commands/umount.c (limited to 'commands') diff --git a/commands/Kconfig b/commands/Kconfig index 530c9e4f83..61ee8c549e 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -1,3 +1,6 @@ +config REGINFO + bool + menu "Commands " menu "scripting " @@ -25,6 +28,49 @@ config CMD_HELP endmenu +menu "file commands " + +config CMD_LS + bool + prompt "ls" + +config CMD_RM + bool + prompt "rm" + +config CMD_CAT + bool + prompt "cat" + +config CMD_MKDIR + bool + prompt "mkdir" + +config CMD_RMDIR + bool + prompt "rmdir" + +config CMD_CP + bool + prompt "cp" + +config CMD_PWD + bool + prompt "pwd" + +config CMD_CD + bool + prompt "cd" + +config CMD_MOUNT + bool + prompt "mount" + +config CMD_UMOUNT + bool + prompt "umount" + +endmenu menu "console " @@ -151,4 +197,14 @@ config CMD_GO endmenu +config CMD_PARTITION + bool + prompt "addpart/delpart" + +config CMD_REGINFO + depends on HAS_REGINFO + select REGINFO + bool + prompt "reginfo" + endmenu diff --git a/commands/Makefile b/commands/Makefile index 776a2019ea..e4c38c12ec 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -2,7 +2,6 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o obj-$(CONFIG_CMD_LOADB) += loadb.o xyzModem.o obj-$(CONFIG_CMD_LOADS) += loads.o obj-$(CONFIG_CMD_ECHO) += echo.o -#obj-$(CONFIG_CMD_FLASH) += flash.o obj-$(CONFIG_CMD_MEMORY) += mem.o obj-$(CONFIG_CMD_MII) += mii.o obj-$(CONFIG_CMD_I2C) += i2c.o @@ -15,6 +14,16 @@ obj-$(CONFIG_CMD_SLEEP) += sleep.o obj-$(CONFIG_CMD_RESET) += reset.o obj-$(CONFIG_CMD_GO) += go.o obj-$(CONFIG_CMD_ENVIRONMENT) += environment.o -obj-y += fs.o obj-$(CONFIG_NET) += net.o obj-$(CONFIG_CMD_PARTITION) += partition.o +obj-$(CONFIG_CMD_LS) += ls.o +obj-$(CONFIG_CMD_CD) += cd.o +obj-$(CONFIG_CMD_PWD) += pwd.o +obj-$(CONFIG_CMD_MKDIR) += mkdir.o +obj-$(CONFIG_CMD_RMDIR) += rmdir.o +obj-$(CONFIG_CMD_CP) += cp.o +obj-$(CONFIG_CMD_RM) += rm.o +obj-$(CONFIG_CMD_CAT) += cat.o +obj-$(CONFIG_CMD_MOUNT) += mount.o +obj-$(CONFIG_CMD_UMOUNT) += umount.o +obj-$(CONFIG_CMD_REGINFO) += reginfo.o diff --git a/commands/bootm.c b/commands/bootm.c index 02ddf20fdb..a929986fbd 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -632,24 +632,6 @@ do_bootm_artos (cmd_tbl_t *cmdtp, int flag, } #endif -int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int rcode = 0; -#ifndef CONFIG_HUSH_PARSER - if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1; -#else - if (parse_string_outer(getenv("bootcmd"), - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1; -#endif - return rcode; -} - -U_BOOT_CMD_START(boot) - .maxargs = 1, - .cmd = do_bootd, - .usage = "boot default, i.e., run 'bootcmd'", -U_BOOT_CMD_END - #if 0 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { diff --git a/commands/cat.c b/commands/cat.c new file mode 100644 index 0000000000..72baae2e5e --- /dev/null +++ b/commands/cat.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include + +static int do_cat(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int ret; + int fd, i; + char *buf; + int err = 0; + int args = 1; + + if (argc < 2) { + perror("cat"); + return 1; + } + + buf = xmalloc(1024); + + while (args < argc) { + fd = open(argv[args], 0); + if (fd < 0) { + printf("could not open %s: %s\n", argv[args], errno_str()); + goto out; + } + + while((ret = read(fd, buf, 1024)) > 0) { + for(i = 0; i < ret; i++) { + if (isprint(buf[i]) || buf[i] == '\n' || buf[i] == '\t') + putc(buf[i]); + else + putc('.'); + } + if(ctrlc()) { + err = 1; + close(fd); + goto out; + } + } + close(fd); + args++; + } + +out: + free(buf); + + return err; +} + +static __maybe_unused char cmd_cat_help[] = +"Usage: cat [FILES]\n" +"Concatenate files on stdout. Currently only printable characters\n" +"and \\n and \\t are printed, but this should be optional\n"; + +U_BOOT_CMD_START(cat) + .maxargs = CONFIG_MAXARGS, + .cmd = do_cat, + .usage = "concatenate file(s)", + U_BOOT_CMD_HELP(cmd_cat_help) +U_BOOT_CMD_END diff --git a/commands/cd.c b/commands/cd.c new file mode 100644 index 0000000000..0a45cbb63d --- /dev/null +++ b/commands/cd.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +static int do_cd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int ret; + + if (argc == 1) + ret = chdir("/"); + else + ret = chdir(argv[1]); + + if (ret) { + perror("chdir"); + return 1; + } + + return 0; +} + +static __maybe_unused char cmd_cd_help[] = +"Usage: cd [directory]\n" +"change to directory. If called without argument, change to /\n"; + +U_BOOT_CMD_START(cd) + .maxargs = 2, + .cmd = do_cd, + .usage = "change working directory", + U_BOOT_CMD_HELP(cmd_cd_help) +U_BOOT_CMD_END diff --git a/commands/cp.c b/commands/cp.c new file mode 100644 index 0000000000..d014cd4a0b --- /dev/null +++ b/commands/cp.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include +#include + +#define RW_BUF_SIZE (ulong)4096 + +int do_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int r, w, ret = 1; + int src = 0, dst = 0; + char *rw_buf = NULL; + + rw_buf = xmalloc(RW_BUF_SIZE); + + src = open(argv[1], O_RDONLY); + if (src < 0) { + printf("could not open %s: %s\n", src, errno_str()); + goto out; + } + + dst = open(argv[2], O_WRONLY | O_CREAT); + if ( dst < 0) { + printf("could not open %s: %s\n", dst, errno_str()); + goto out; + } + + while(1) { + r = read(src, rw_buf, RW_BUF_SIZE); + if (read < 0) { + perror("read"); + goto out; + } + if (!r) + break; + w = write(dst, rw_buf, r); + if (w < 0) { + perror("write"); + goto out; + } + } + ret = 0; +out: + free(rw_buf); + if (src) + close(src); + if (dst) + close(dst); + return ret; +} + +static __maybe_unused char cmd_cp_help[] = +"Usage: cp \n" +"cp copies file to .\n" +"Currently only this form is supported and you have to specify the exact target\n" +"filename (not a target directory).\n" +"Note: This command was previously used as memory copy. Currently there is no\n" +"equivalent command for this. This must be fixed of course.\n"; + +U_BOOT_CMD_START(cp) + .maxargs = CONFIG_MAXARGS, + .cmd = do_cp, + .usage = "copy files", + U_BOOT_CMD_HELP(cmd_cp_help) +U_BOOT_CMD_END diff --git a/commands/environment.c b/commands/environment.c index 148b6e9d6e..aef52c4f43 100644 --- a/commands/environment.c +++ b/commands/environment.c @@ -97,7 +97,7 @@ out: #ifdef __U_BOOT__ int do_saveenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int ret; + int ret, fd; char *filename, *dirname; printf("saving environment\n"); @@ -110,9 +110,24 @@ int do_saveenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) else filename = argv[1]; + fd = open(filename, O_WRONLY); + if (fd < 0) { + printf("could not open %s: %s", filename, errno_str()); + return 1; + } + + ret = erase(fd, ~0, 0); + if (ret && errno != -EINVAL) { + printf("could not erase %s: %s\n", filename, errno_str()); + close(fd); + return 1; + } + ret = envfs_save(filename, dirname); if (ret) printf("saveenv failed\n"); + + close(fd); return ret; } diff --git a/commands/flash.c b/commands/flash.c new file mode 100644 index 0000000000..db059dba58 --- /dev/null +++ b/commands/flash.c @@ -0,0 +1,125 @@ +/* + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * FLASH support + */ +#include +#include +#include +#include +#include +#include +#include +#include + +int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int opt, fd; + char *filename = NULL; + struct stat s; + unsigned long start = 0, size = ~0; + + getopt_reset(); + + while((opt = getopt(argc, argv, "f:")) > 0) { + switch(opt) { + case 'f': + filename = optarg; + break; + } + } + + if (stat(filename, &s)) { + printf("stat %s:", filename, errno_str()); + return 1; + } + + size = s.st_size; + + if (!filename) { + printf("missing filename\n"); + return 1; + } + + fd = open(filename, O_WRONLY); + if (fd < 0) { + printf("open %s:", filename, errno_str()); + return 1; + } + + if (optind < argc) + parse_area_spec(argv[optind], &start, &size); + + if(erase(fd, size, start)) { + perror("erase"); + return 1; + } + + close(fd); + + return 0; +} + +U_BOOT_CMD_START(erase) + .maxargs = CONFIG_MAXARGS, + .cmd = do_flerase, + .usage = "erase FLASH memory", + U_BOOT_CMD_HELP("write me\n") +U_BOOT_CMD_END + +int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int p; + int rcode = 0; + struct memarea_info mem_info; + + if (argc < 3) { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + if (strcmp(argv[1], "off") == 0) { + p = 0; + } else if (strcmp(argv[1], "on") == 0) { + p = 1; + } else { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + if (spec_str_to_info(argv[2], &mem_info)) { + printf ("-EPARSE\n"); + return 1; + } + +// rcode = flash_sect_protect (p, addr_first, addr_last); + return rcode; +} + +U_BOOT_CMD_START(protect) + .maxargs = 4, + .cmd = do_protect, + .usage = "enable or disable FLASH write protection", + U_BOOT_CMD_HELP("write me\n") +U_BOOT_CMD_END diff --git a/commands/fs.c b/commands/fs.c deleted file mode 100644 index 2eca365016..0000000000 --- a/commands/fs.c +++ /dev/null @@ -1,391 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void ls_one(const char *path, struct stat *s) -{ - char modestr[11]; - unsigned long namelen = strlen(path); - - mkmodestr(s->st_mode, modestr); - printf("%s %8d %*.*s\n",modestr, s->st_size, namelen, namelen, path); -} - -int ls(const char *path, ulong flags) -{ - DIR *dir; - struct dirent *d; - char tmp[PATH_MAX]; - struct stat s; - - if (flags & LS_SHOWARG) - printf("%s:\n", path); - - if (stat(path, &s)) { - perror("stat"); - return errno; - } - - if (!(s.st_mode & S_IFDIR)) { - ls_one(path, &s); - return 0; - } - - dir = opendir(path); - if (!dir) - return errno; - - while ((d = readdir(dir))) { - sprintf(tmp, "%s/%s", path, d->d_name); - if (stat(tmp, &s)) - goto out; - ls_one(d->d_name, &s); - } - - closedir(dir); - - if (!(flags & LS_RECURSIVE)) - return 0; - - dir = opendir(path); - if (!dir) { - errno = -ENOENT; - return -ENOENT; - } - - while ((d = readdir(dir))) { - sprintf(tmp, "%s/%s", path, d->d_name); - normalise_path(tmp); - if (stat(tmp, &s)) - goto out; - if (!strcmp(d->d_name, ".")) - continue; - if (!strcmp(d->d_name, "..")) - continue; - if (s.st_mode & S_IFDIR) - ls(tmp, flags); - } -out: - closedir(dir); - - return 0; -} - -static int do_ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int ret, opt; - ulong flags = 0; - - getopt_reset(); - - while((opt = getopt(argc, argv, "R")) > 0) { - switch(opt) { - case 'R': - flags |= LS_RECURSIVE | LS_SHOWARG; - break; - } - } - - if (argc - optind > 1) - flags |= LS_SHOWARG; - - if (optind == argc) { - ret = ls(getcwd(), flags); - return ret ? 1 : 0; - } - - while (optind < argc) { - ret = ls(argv[optind], flags); - if (ret) { - perror("ls"); - return 1; - } - optind++; - } - - return 0; -} - -static __maybe_unused char cmd_ls_help[] = -"Usage: ls [OPTION]... [FILE]...\n" -"List information about the FILEs (the current directory by default).\n" -" -R list subdirectories recursively\n"; - -U_BOOT_CMD_START(ls) - .maxargs = CONFIG_MAXARGS, - .cmd = do_ls, - .usage = "list a file or directory", - U_BOOT_CMD_HELP(cmd_ls_help) -U_BOOT_CMD_END - -static int do_cd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int ret; - - if (argc == 1) - ret = chdir("/"); - else - ret = chdir(argv[1]); - - if (ret) { - perror("chdir"); - return 1; - } - - return 0; -} - -static __maybe_unused char cmd_cd_help[] = -"Usage: cd [directory]\n" -"change to directory. If called without argument, change to /\n"; - -U_BOOT_CMD_START(cd) - .maxargs = 2, - .cmd = do_cd, - .usage = "change working directory", - U_BOOT_CMD_HELP(cmd_cd_help) -U_BOOT_CMD_END - -static int do_pwd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - printf("%s\n", getcwd()); - return 0; -} - -U_BOOT_CMD_START(pwd) - .maxargs = 2, - .cmd = do_pwd, - .usage = "print working directory", -U_BOOT_CMD_END - -static int do_mkdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int i = 1; - - if (argc < 2) { - u_boot_cmd_usage(cmdtp); - return 1; - } - - while (i < argc) { - if (mkdir(argv[i])) { - printf("could not create %s: %s\n", argv[i], errno_str()); - return 1; - } - i++; - } - - return 0; -} - -static __maybe_unused char cmd_mkdir_help[] = -"Usage: mkdir [directories]\n" -"Create new directories\n"; - -U_BOOT_CMD_START(mkdir) - .maxargs = CONFIG_MAXARGS, - .cmd = do_mkdir, - .usage = "make directories", - U_BOOT_CMD_HELP(cmd_mkdir_help) -U_BOOT_CMD_END - -static int do_rm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int i = 1; - - if (argc < 2) { - u_boot_cmd_usage(cmdtp); - return 1; - } - - while (i < argc) { - if (unlink(argv[i])) { - printf("could not remove %s: %s\n", argv[i], errno_str()); - return 1; - } - i++; - } - - return 0; -} - -static __maybe_unused char cmd_rm_help[] = -"Usage: rm [FILES]\n" -"Remove files\n"; - -U_BOOT_CMD_START(rm) - .maxargs = CONFIG_MAXARGS, - .cmd = do_rm, - .usage = "remove files", - U_BOOT_CMD_HELP(cmd_rm_help) -U_BOOT_CMD_END - -static int do_rmdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int i = 1; - - if (argc < 2) { - u_boot_cmd_usage(cmdtp); - return 1; - } - - while (i < argc) { - if (rmdir(argv[i])) { - printf("could not remove %s: %s\n", argv[i], errno_str()); - return 1; - } - i++; - } - - return 0; -} - -static __maybe_unused char cmd_rmdir_help[] = -"Usage: rmdir [directories]\n" -"Remove directories. The directories have to be empty.\n"; - -U_BOOT_CMD_START(rmdir) - .maxargs = CONFIG_MAXARGS, - .cmd = do_rmdir, - .usage = "remove directorie(s)", - U_BOOT_CMD_HELP(cmd_rmdir_help) -U_BOOT_CMD_END - -static int do_mount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int ret = 0; - struct mtab_entry *entry = NULL; - - if (argc == 1) { - do { - entry = mtab_next_entry(entry); - if (entry) { - printf("%s on %s type %s\n", - entry->parent_device ? entry->parent_device->id : "none", - entry->path, - entry->dev->name); - } - } while (entry); - return 0; - } - - if (argc != 4) { - u_boot_cmd_usage(cmdtp); - return 1; - } - - if ((ret = mount(argv[1], argv[2], argv[3]))) { - perror("mount"); - return 1; - } - return 0; -} - -static __maybe_unused char cmd_mount_help[] = -"Usage: mount: list mounted filesystems\n" -"or: mount \n" -"\n" -"Mount a filesystem of a given type to a mountpoint.\n" -" can be one of /dev/* or some arbitrary string if no\n" -"device is needed for this driver (for example ramfs).\n" -" is the filesystem driver to use. Try the 'devinfo' command\n" -"for a list of available drivers.\n" -" must be an empty directory descending directly from the\n" -"root directory.\n"; - -U_BOOT_CMD_START(mount) - .maxargs = 4, - .cmd = do_mount, - .usage = "mount a filesystem to a device", - U_BOOT_CMD_HELP(cmd_mount_help) -U_BOOT_CMD_END - -static int do_umount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int ret = 0; - - if (argc != 2) { - u_boot_cmd_usage(cmdtp); - return 1; - } - - if ((ret = umount(argv[1]))) { - perror("umount"); - return 1; - } - return 0; -} - -static __maybe_unused char cmd_umount_help[] = -"Usage: umount \n" -"umount a filesystem mounted on a specific mountpoint\n"; - -U_BOOT_CMD_START(umount) - .maxargs = 2, - .cmd = do_umount, - .usage = "umount a filesystem", - U_BOOT_CMD_HELP(cmd_umount_help) -U_BOOT_CMD_END - -static int do_cat(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int ret; - int fd, i; - char *buf; - int err = 0; - int args = 1; - - if (argc < 2) { - perror("cat"); - return 1; - } - - buf = xmalloc(1024); - - while (args < argc) { - fd = open(argv[args], 0); - if (fd < 0) { - printf("could not open %s: %s\n", argv[args], errno_str()); - goto out; - } - - while((ret = read(fd, buf, 1024)) > 0) { - for(i = 0; i < ret; i++) { - if (isprint(buf[i]) || buf[i] == '\n' || buf[i] == '\t') - putc(buf[i]); - else - putc('.'); - } - if(ctrlc()) { - err = 1; - close(fd); - goto out; - } - } - close(fd); - args++; - } - -out: - free(buf); - - return err; -} - -static __maybe_unused char cmd_cat_help[] = -"Usage: cat [FILES]\n" -"Concatenate files on stdout. Currently only printable characters\n" -"and \\n and \\t are printed, but this should be optional\n"; - -U_BOOT_CMD_START(cat) - .maxargs = CONFIG_MAXARGS, - .cmd = do_cat, - .usage = "concatenate file(s)", - U_BOOT_CMD_HELP(cmd_cat_help) -U_BOOT_CMD_END diff --git a/commands/ls.c b/commands/ls.c new file mode 100644 index 0000000000..7cdbbb790e --- /dev/null +++ b/commands/ls.c @@ -0,0 +1,122 @@ +#include +#include +#include +#include +#include +#include + +static void ls_one(const char *path, struct stat *s) +{ + char modestr[11]; + unsigned long namelen = strlen(path); + + mkmodestr(s->st_mode, modestr); + printf("%s %8d %*.*s\n",modestr, s->st_size, namelen, namelen, path); +} + +int ls(const char *path, ulong flags) +{ + DIR *dir; + struct dirent *d; + char tmp[PATH_MAX]; + struct stat s; + + if (flags & LS_SHOWARG) + printf("%s:\n", path); + + if (stat(path, &s)) { + perror("stat"); + return errno; + } + + if (!(s.st_mode & S_IFDIR)) { + ls_one(path, &s); + return 0; + } + + dir = opendir(path); + if (!dir) + return errno; + + while ((d = readdir(dir))) { + sprintf(tmp, "%s/%s", path, d->d_name); + if (stat(tmp, &s)) + goto out; + ls_one(d->d_name, &s); + } + + closedir(dir); + + if (!(flags & LS_RECURSIVE)) + return 0; + + dir = opendir(path); + if (!dir) { + errno = -ENOENT; + return -ENOENT; + } + + while ((d = readdir(dir))) { + sprintf(tmp, "%s/%s", path, d->d_name); + normalise_path(tmp); + if (stat(tmp, &s)) + goto out; + if (!strcmp(d->d_name, ".")) + continue; + if (!strcmp(d->d_name, "..")) + continue; + if (s.st_mode & S_IFDIR) + ls(tmp, flags); + } +out: + closedir(dir); + + return 0; +} + +static int do_ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int ret, opt; + ulong flags = 0; + + getopt_reset(); + + while((opt = getopt(argc, argv, "R")) > 0) { + switch(opt) { + case 'R': + flags |= LS_RECURSIVE | LS_SHOWARG; + break; + } + } + + if (argc - optind > 1) + flags |= LS_SHOWARG; + + if (optind == argc) { + ret = ls(getcwd(), flags); + return ret ? 1 : 0; + } + + while (optind < argc) { + ret = ls(argv[optind], flags); + if (ret) { + perror("ls"); + return 1; + } + optind++; + } + + return 0; +} + +static __maybe_unused char cmd_ls_help[] = +"Usage: ls [OPTION]... [FILE]...\n" +"List information about the FILEs (the current directory by default).\n" +" -R list subdirectories recursively\n"; + +U_BOOT_CMD_START(ls) + .maxargs = CONFIG_MAXARGS, + .cmd = do_ls, + .usage = "list a file or directory", + U_BOOT_CMD_HELP(cmd_ls_help) +U_BOOT_CMD_END diff --git a/commands/mem.c b/commands/mem.c index d7cd7fb96d..e0f83608d3 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -427,60 +427,6 @@ U_BOOT_CMD( ); #endif -int do_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - int r, w, ret = 1; - int src, dst; - - src = open(argv[1], O_RDONLY); - if (src < 0) { - perror("open"); - return 1; - } - - dst = open(argv[2], O_WRONLY | O_CREAT); - if ( dst < 0) { - perror("open"); - close(src); - return 1; - } - - while(1) { - r = read(src, rw_buf, RW_BUF_SIZE); - if (read < 0) { - perror("read"); - goto out; - } - if (!r) - break; - w = write(dst, rw_buf, r); - if (w < 0) { - perror("write"); - goto out; - } - } - ret = 0; -out: - close(src); - close(dst); - return ret; -} - -static __maybe_unused char cmd_cp_help[] = -"Usage: cp \n" -"cp copies file to .\n" -"Currently only this form is supported and you have to specify the exact target\n" -"filename (not a target directory).\n" -"Note: This command was previously used as memory copy. Currently there is no\n" -"equivalent command for this. This must be fixed of course.\n"; - -U_BOOT_CMD_START(cp) - .maxargs = CONFIG_MAXARGS, - .cmd = do_cp, - .usage = "copy files", - U_BOOT_CMD_HELP(cmd_cp_help) -U_BOOT_CMD_END - #ifndef CONFIG_CRC32_VERIFY int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) @@ -566,55 +512,6 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif /* CONFIG_CRC32_VERIFY */ -static void memcpy_sz(void *_dst, const void *_src, ulong count, ulong rwsize) -{ - ulong dst = (ulong)_dst; - ulong src = (ulong)_src; - - /* no rwsize specification given. Do whatever memcpy likes best */ - if (!rwsize) { - memcpy(_dst, _src, count); - return; - } - - rwsize = rwsize >> O_RWSIZE_SHIFT; - - count /= rwsize; - - while (count-- > 0) { - switch (rwsize) { - case 1: - *((u_char *)dst) = *((u_char *)src); - break; - case 2: - *((ushort *)dst) = *((ushort *)src); - break; - case 4: - *((ulong *)dst) = *((ulong *)src); - break; - } - dst += rwsize; - src += rwsize; - } -} - -ssize_t mem_read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags) -{ - ulong size; - size = min(count, dev->size - offset); - printf("mem_read: dev->map_base: %p size: %d offset: %d\n",dev->map_base, size, offset); - memcpy_sz(buf, (void *)(dev->map_base + offset), size, flags & O_RWSIZE_MASK); - return size; -} - -ssize_t mem_write(struct device_d *dev, const void *buf, size_t count, ulong offset, ulong flags) -{ - ulong size; - size = min(count, dev->size - offset); - memcpy_sz((void *)(dev->map_base + offset), buf, size, flags & O_RWSIZE_MASK); - return size; -} - static struct device_d mem_dev = { .name = "mem", .id = "mem", diff --git a/commands/mkdir.c b/commands/mkdir.c new file mode 100644 index 0000000000..3be742a942 --- /dev/null +++ b/commands/mkdir.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +static int do_mkdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i = 1; + + if (argc < 2) { + u_boot_cmd_usage(cmdtp); + return 1; + } + + while (i < argc) { + if (mkdir(argv[i])) { + printf("could not create %s: %s\n", argv[i], errno_str()); + return 1; + } + i++; + } + + return 0; +} + +static __maybe_unused char cmd_mkdir_help[] = +"Usage: mkdir [directories]\n" +"Create new directories\n"; + +U_BOOT_CMD_START(mkdir) + .maxargs = CONFIG_MAXARGS, + .cmd = do_mkdir, + .usage = "make directories", + U_BOOT_CMD_HELP(cmd_mkdir_help) +U_BOOT_CMD_END diff --git a/commands/mount.c b/commands/mount.c new file mode 100644 index 0000000000..e4c567357b --- /dev/null +++ b/commands/mount.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +static int do_mount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int ret = 0; + struct mtab_entry *entry = NULL; + + if (argc == 1) { + do { + entry = mtab_next_entry(entry); + if (entry) { + printf("%s on %s type %s\n", + entry->parent_device ? entry->parent_device->id : "none", + entry->path, + entry->dev->name); + } + } while (entry); + return 0; + } + + if (argc != 4) { + u_boot_cmd_usage(cmdtp); + return 1; + } + + if ((ret = mount(argv[1], argv[2], argv[3]))) { + perror("mount"); + return 1; + } + return 0; +} + +static __maybe_unused char cmd_mount_help[] = +"Usage: mount: list mounted filesystems\n" +"or: mount \n" +"\n" +"Mount a filesystem of a given type to a mountpoint.\n" +" can be one of /dev/* or some arbitrary string if no\n" +"device is needed for this driver (for example ramfs).\n" +" is the filesystem driver to use. Try the 'devinfo' command\n" +"for a list of available drivers.\n" +" must be an empty directory descending directly from the\n" +"root directory.\n"; + +U_BOOT_CMD_START(mount) + .maxargs = 4, + .cmd = do_mount, + .usage = "mount a filesystem to a device", + U_BOOT_CMD_HELP(cmd_mount_help) +U_BOOT_CMD_END diff --git a/commands/pwd.c b/commands/pwd.c new file mode 100644 index 0000000000..a0aa4b70f6 --- /dev/null +++ b/commands/pwd.c @@ -0,0 +1,15 @@ +#include +#include +#include + +static int do_pwd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + printf("%s\n", getcwd()); + return 0; +} + +U_BOOT_CMD_START(pwd) + .maxargs = 2, + .cmd = do_pwd, + .usage = "print working directory", +U_BOOT_CMD_END diff --git a/commands/reginfo.c b/commands/reginfo.c new file mode 100644 index 0000000000..856beaed9f --- /dev/null +++ b/commands/reginfo.c @@ -0,0 +1,14 @@ +#include +#include + +int do_reginfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + reginfo(); + return 0; +} + +U_BOOT_CMD_START(reginfo) + .maxargs = 1, + .cmd = do_reginfo, + .usage = "print register information", +U_BOOT_CMD_END diff --git a/commands/rm.c b/commands/rm.c new file mode 100644 index 0000000000..7199580485 --- /dev/null +++ b/commands/rm.c @@ -0,0 +1,30 @@ +static int do_rm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i = 1; + + if (argc < 2) { + u_boot_cmd_usage(cmdtp); + return 1; + } + + while (i < argc) { + if (unlink(argv[i])) { + printf("could not remove %s: %s\n", argv[i], errno_str()); + return 1; + } + i++; + } + + return 0; +} + +static __maybe_unused char cmd_rm_help[] = +"Usage: rm [FILES]\n" +"Remove files\n"; + +U_BOOT_CMD_START(rm) + .maxargs = CONFIG_MAXARGS, + .cmd = do_rm, + .usage = "remove files", + U_BOOT_CMD_HELP(cmd_rm_help) +U_BOOT_CMD_END diff --git a/commands/rmdir.c b/commands/rmdir.c new file mode 100644 index 0000000000..cad0862d86 --- /dev/null +++ b/commands/rmdir.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +static int do_rmdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i = 1; + + if (argc < 2) { + u_boot_cmd_usage(cmdtp); + return 1; + } + + while (i < argc) { + if (rmdir(argv[i])) { + printf("could not remove %s: %s\n", argv[i], errno_str()); + return 1; + } + i++; + } + + return 0; +} + +static __maybe_unused char cmd_rmdir_help[] = +"Usage: rmdir [directories]\n" +"Remove directories. The directories have to be empty.\n"; + +U_BOOT_CMD_START(rmdir) + .maxargs = CONFIG_MAXARGS, + .cmd = do_rmdir, + .usage = "remove directorie(s)", + U_BOOT_CMD_HELP(cmd_rmdir_help) +U_BOOT_CMD_END diff --git a/commands/umount.c b/commands/umount.c new file mode 100644 index 0000000000..8f4a4b445e --- /dev/null +++ b/commands/umount.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +static int do_umount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int ret = 0; + + if (argc != 2) { + u_boot_cmd_usage(cmdtp); + return 1; + } + + if ((ret = umount(argv[1]))) { + perror("umount"); + return 1; + } + return 0; +} + +static __maybe_unused char cmd_umount_help[] = +"Usage: umount \n" +"umount a filesystem mounted on a specific mountpoint\n"; + +U_BOOT_CMD_START(umount) + .maxargs = 2, + .cmd = do_umount, + .usage = "umount a filesystem", + U_BOOT_CMD_HELP(cmd_umount_help) +U_BOOT_CMD_END -- cgit v1.2.3