William Juul | e24ebad | 2007-11-15 12:23:57 +0100 | [diff] [blame] | 1 | #include <common.h> |
| 2 | |
| 3 | #include <config.h> |
| 4 | #include <command.h> |
| 5 | |
| 6 | #ifdef YAFFS2_DEBUG |
| 7 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 8 | #else |
| 9 | #define PRINTF(fmt,args...) |
| 10 | #endif |
| 11 | |
| 12 | extern void cmd_yaffs_mount(char *mp); |
| 13 | extern void cmd_yaffs_umount(char *mp); |
| 14 | extern void cmd_yaffs_read_file(char *fn); |
| 15 | extern void cmd_yaffs_write_file(char *fn,char bval,int sizeOfFile); |
| 16 | extern void cmd_yaffs_ls(const char *mountpt, int longlist); |
| 17 | extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size); |
| 18 | extern void cmd_yaffs_mread_file(char *fn, char *addr); |
| 19 | extern void cmd_yaffs_mkdir(const char *dir); |
| 20 | extern void cmd_yaffs_rmdir(const char *dir); |
| 21 | extern void cmd_yaffs_rm(const char *path); |
| 22 | extern void cmd_yaffs_mv(const char *oldPath, const char *newPath); |
| 23 | |
| 24 | extern int yaffs_DumpDevStruct(const char *path); |
| 25 | |
| 26 | |
| 27 | int do_ymount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 28 | { |
| 29 | char *mtpoint = argv[1]; |
| 30 | cmd_yaffs_mount(mtpoint); |
| 31 | |
| 32 | return(0); |
| 33 | } |
| 34 | |
| 35 | int do_yumount (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 36 | { |
| 37 | char *mtpoint = argv[1]; |
| 38 | cmd_yaffs_umount(mtpoint); |
| 39 | |
| 40 | return(0); |
| 41 | } |
| 42 | |
| 43 | int do_yls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 44 | { |
| 45 | char *dirname = argv[argc-1]; |
| 46 | |
| 47 | cmd_yaffs_ls(dirname, (argc>2)?1:0); |
| 48 | |
| 49 | return(0); |
| 50 | } |
| 51 | |
| 52 | int do_yrd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 53 | { |
| 54 | char *filename = argv[1]; |
| 55 | printf ("Reading file %s ", filename); |
| 56 | |
| 57 | cmd_yaffs_read_file(filename); |
| 58 | |
| 59 | printf ("done\n"); |
| 60 | return(0); |
| 61 | } |
| 62 | |
| 63 | int do_ywr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 64 | { |
| 65 | char *filename = argv[1]; |
| 66 | ulong value = simple_strtoul(argv[2], NULL, 16); |
| 67 | ulong numValues = simple_strtoul(argv[3], NULL, 16); |
| 68 | |
| 69 | printf ("Writing value (%x) %x times to %s... ", value, numValues, filename); |
| 70 | |
| 71 | cmd_yaffs_write_file(filename,value,numValues); |
| 72 | |
| 73 | printf ("done\n"); |
| 74 | return(0); |
| 75 | } |
| 76 | |
| 77 | int do_yrdm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 78 | { |
| 79 | char *filename = argv[1]; |
| 80 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 81 | |
| 82 | cmd_yaffs_mread_file(filename, (char *)addr); |
| 83 | |
| 84 | return(0); |
| 85 | } |
| 86 | |
| 87 | int do_ywrm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 88 | { |
| 89 | char *filename = argv[1]; |
| 90 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 91 | ulong size = simple_strtoul(argv[3], NULL, 16); |
| 92 | |
| 93 | cmd_yaffs_mwrite_file(filename, (char *)addr, size); |
| 94 | |
| 95 | return(0); |
| 96 | } |
| 97 | |
| 98 | int do_ymkdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 99 | { |
| 100 | char *dirname = argv[1]; |
| 101 | |
| 102 | cmd_yaffs_mkdir(dirname); |
| 103 | |
| 104 | return(0); |
| 105 | } |
| 106 | |
| 107 | int do_yrmdir (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 108 | { |
| 109 | char *dirname = argv[1]; |
| 110 | |
| 111 | cmd_yaffs_rmdir(dirname); |
| 112 | |
| 113 | return(0); |
| 114 | } |
| 115 | |
| 116 | int do_yrm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 117 | { |
| 118 | char *path = argv[1]; |
| 119 | |
| 120 | cmd_yaffs_rm(path); |
| 121 | |
| 122 | return(0); |
| 123 | } |
| 124 | |
| 125 | int do_ymv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 126 | { |
| 127 | char *oldPath = argv[1]; |
| 128 | char *newPath = argv[2]; |
| 129 | |
| 130 | cmd_yaffs_mv(newPath, oldPath); |
| 131 | |
| 132 | return(0); |
| 133 | } |
| 134 | |
| 135 | int do_ydump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 136 | { |
| 137 | char *dirname = argv[1]; |
| 138 | if (yaffs_DumpDevStruct(dirname) != 0) |
| 139 | printf("yaffs_DumpDevStruct returning error when dumping path: , %s\n", dirname); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
| 145 | U_BOOT_CMD( |
| 146 | ymount, 3, 0, do_ymount, |
| 147 | "ymount\t- mount yaffs\n", |
| 148 | "\n" |
| 149 | ); |
| 150 | |
| 151 | U_BOOT_CMD( |
| 152 | yumount, 3, 0, do_yumount, |
| 153 | "yumount\t- unmount yaffs\n", |
| 154 | "\n" |
| 155 | ); |
| 156 | |
| 157 | U_BOOT_CMD( |
| 158 | yls, 4, 0, do_yls, |
| 159 | "yls\t- yaffs ls\n", |
| 160 | "[-l] name\n" |
| 161 | ); |
| 162 | |
| 163 | U_BOOT_CMD( |
| 164 | yrd, 2, 0, do_yrd, |
| 165 | "yrd\t- read file from yaffs\n", |
| 166 | "filename\n" |
| 167 | ); |
| 168 | |
| 169 | U_BOOT_CMD( |
| 170 | ywr, 4, 0, do_ywr, |
| 171 | "ywr\t- write file to yaffs\n", |
| 172 | "filename value num_vlues\n" |
| 173 | ); |
| 174 | |
| 175 | U_BOOT_CMD( |
| 176 | yrdm, 3, 0, do_yrdm, |
| 177 | "yrdm\t- read file to memory from yaffs\n", |
| 178 | "filename offset\n" |
| 179 | ); |
| 180 | |
| 181 | U_BOOT_CMD( |
| 182 | ywrm, 4, 0, do_ywrm, |
| 183 | "ywrm\t- write file from memory to yaffs\n", |
| 184 | "filename offset size\n" |
| 185 | ); |
| 186 | |
| 187 | U_BOOT_CMD( |
| 188 | ymkdir, 2, 0, do_ymkdir, |
| 189 | "ymkdir\t- YAFFS mkdir\n", |
| 190 | "dirname\n" |
| 191 | ); |
| 192 | |
| 193 | U_BOOT_CMD( |
| 194 | yrmdir, 2, 0, do_yrmdir, |
| 195 | "yrmdir\t- YAFFS rmdir\n", |
| 196 | "dirname\n" |
| 197 | ); |
| 198 | |
| 199 | U_BOOT_CMD( |
| 200 | yrm, 2, 0, do_yrm, |
| 201 | "yrm\t- YAFFS rm\n", |
| 202 | "path\n" |
| 203 | ); |
| 204 | |
| 205 | U_BOOT_CMD( |
| 206 | ymv, 4, 0, do_ymv, |
| 207 | "ymv\t- YAFFS mv\n", |
| 208 | "oldPath newPath\n" |
| 209 | ); |
| 210 | |
| 211 | U_BOOT_CMD( |
| 212 | ydump, 2, 0, do_ydump, |
| 213 | "ydump\t- YAFFS device struct\n", |
| 214 | "dirname\n" |
| 215 | ); |