wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 4 | * (C) Copyright 2002 |
| 5 | * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de> |
| 6 | * (C) Copyright 2003 |
| 7 | * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Boot support |
| 30 | */ |
| 31 | #include <common.h> |
| 32 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | #include <s_record.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 34 | #include <jffs2/load_kernel.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | #include <net.h> |
| 36 | |
| 37 | #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 38 | |
| 39 | #include <cramfs/cramfs_fs.h> |
| 40 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 41 | extern int cramfs_check (struct part_info *info); |
| 42 | extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename); |
| 43 | extern int cramfs_ls (struct part_info *info, char *filename); |
| 44 | extern int cramfs_info (struct part_info *info); |
| 45 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 46 | static int part_num=0; |
| 47 | |
| 48 | #ifndef CFG_JFFS_CUSTOM_PART |
| 49 | |
| 50 | static struct part_info part; |
| 51 | |
wdenk | 8886a66 | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 52 | #ifndef CONFIG_JFFS2_NAND |
| 53 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | struct part_info* |
| 55 | jffs2_part_info(int part_num) |
| 56 | { |
| 57 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 58 | int i; |
| 59 | |
| 60 | if(part_num==0){ |
| 61 | |
| 62 | if(part.usr_priv==(void*)1) |
| 63 | return ∂ |
| 64 | |
| 65 | memset(&part, 0, sizeof(part)); |
| 66 | |
| 67 | #if defined(CFG_JFFS2_FIRST_SECTOR) |
| 68 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR]; |
| 69 | #else |
| 70 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0]; |
| 71 | #endif |
| 72 | |
| 73 | /* Figure out flash partition size */ |
| 74 | for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++) |
| 75 | part.size += flash_info[i].size; |
| 76 | |
| 77 | #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0) |
| 78 | part.size -= |
| 79 | flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] - |
| 80 | flash_info[CFG_JFFS2_FIRST_BANK].start[0]; |
| 81 | #endif |
| 82 | |
wdenk | 7ad5e4c | 2004-04-25 15:41:35 +0000 | [diff] [blame] | 83 | /* unused in current jffs2 loader */ |
| 84 | part.erasesize = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | |
| 86 | /* Mark the struct as ready */ |
| 87 | part.usr_priv=(void*)1; |
| 88 | |
wdenk | 8886a66 | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 89 | return ∂ |
| 90 | } |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | #else /* CONFIG_JFFS2_NAND */ |
| 95 | |
| 96 | struct part_info* |
| 97 | jffs2_part_info(int part_num) |
| 98 | { |
| 99 | if(part_num==0){ |
| 100 | |
| 101 | if(part.usr_priv==(void*)1) |
| 102 | return ∂ |
| 103 | |
| 104 | memset(&part, 0, sizeof(part)); |
| 105 | |
wdenk | efc6f36 | 2004-06-10 21:34:36 +0000 | [diff] [blame] | 106 | part.offset = (char *)CONFIG_JFFS2_NAND_OFF; |
wdenk | 8886a66 | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 107 | part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */ |
| 108 | |
| 109 | #ifndef CONFIG_JFFS2_NAND_DEV |
| 110 | #define CONFIG_JFFS2_NAND_DEV 0 |
| 111 | #endif |
| 112 | /* nand device with the JFFS2 parition plus 1 */ |
| 113 | part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 114 | return ∂ |
| 115 | } |
| 116 | return 0; |
| 117 | } |
wdenk | 8886a66 | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 118 | |
| 119 | #endif /* CONFIG_JFFS2_NAND */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 120 | #endif /* ifndef CFG_JFFS_CUSTOM_PART */ |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 121 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 122 | int |
| 123 | do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 124 | { |
wdenk | f2140d5 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 125 | struct part_info* jffs2_part_info(int); |
| 126 | int jffs2_1pass_load(char *, struct part_info *,const char *); |
| 127 | char *fsname; |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 128 | char *filename; |
wdenk | f2140d5 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 129 | int size; |
| 130 | struct part_info *part; |
| 131 | ulong offset = load_addr; |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 132 | |
| 133 | /* pre-set Boot file name */ |
| 134 | if ((filename = getenv("bootfile")) == NULL) { |
| 135 | filename = "uImage"; |
| 136 | } |
| 137 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 138 | if (argc == 2) { |
| 139 | filename = argv[1]; |
| 140 | } |
| 141 | if (argc == 3) { |
| 142 | offset = simple_strtoul(argv[1], NULL, 16); |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 143 | load_addr = offset; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 144 | filename = argv[2]; |
| 145 | } |
| 146 | |
| 147 | if (0 != (part=jffs2_part_info(part_num))){ |
| 148 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 149 | /* check partition type for cramfs */ |
| 150 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); |
| 151 | printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset); |
| 152 | |
| 153 | if (cramfs_check(part)) { |
| 154 | size = cramfs_load ((char *) offset, part, filename); |
| 155 | } else { |
| 156 | /* if this is not cramfs assume jffs2 */ |
| 157 | size = jffs2_1pass_load((char *)offset, part, filename); |
| 158 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 159 | |
| 160 | if (size > 0) { |
| 161 | char buf[10]; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 162 | printf("### %s load complete: %d bytes loaded to 0x%lx\n", |
| 163 | fsname, size, offset); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | sprintf(buf, "%x", size); |
| 165 | setenv("filesize", buf); |
| 166 | } else { |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 167 | printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return !(size > 0); |
| 171 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 172 | puts ("Active partition not valid\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int |
| 177 | do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 178 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 179 | struct part_info* jffs2_part_info(int); |
| 180 | int jffs2_1pass_ls(struct part_info *,char *); |
| 181 | |
| 182 | char *filename = "/"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | int ret; |
| 184 | struct part_info *part; |
| 185 | |
| 186 | if (argc == 2) |
| 187 | filename = argv[1]; |
| 188 | |
| 189 | if (0 != (part=jffs2_part_info(part_num))){ |
| 190 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 191 | /* check partition type for cramfs */ |
| 192 | if (cramfs_check(part)) { |
| 193 | ret = cramfs_ls (part, filename); |
| 194 | } else { |
| 195 | /* if this is not cramfs assume jffs2 */ |
| 196 | ret = jffs2_1pass_ls(part, filename); |
| 197 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 198 | |
| 199 | return (ret == 1); |
| 200 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 201 | puts ("Active partition not valid\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | int |
| 206 | do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 207 | { |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 208 | struct part_info* jffs2_part_info(int); |
| 209 | int jffs2_1pass_info(struct part_info *); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | struct part_info *part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 211 | char *fsname; |
| 212 | int ret; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 213 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 214 | if ((part=jffs2_part_info(part_num))){ |
| 215 | |
| 216 | /* check partition type for cramfs */ |
| 217 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); |
| 218 | printf("### filesystem type is %s\n", fsname); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 219 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 220 | if (cramfs_check(part)) { |
| 221 | ret = cramfs_info (part); |
| 222 | } else { |
| 223 | /* if this is not cramfs assume jffs2 */ |
| 224 | ret = jffs2_1pass_info(part); |
| 225 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 226 | |
| 227 | return (ret == 1); |
| 228 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 229 | puts ("Active partition not valid\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int |
| 234 | do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 235 | { |
| 236 | int tmp_part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 237 | char str_part_num[3]; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 238 | struct part_info* jffs2_part_info(int); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 239 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 240 | if (argc >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | tmp_part = simple_strtoul(argv[1], NULL, 16); |
| 242 | }else{ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 243 | puts ("Need partition number in argument list\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 244 | return 0; |
| 245 | |
| 246 | } |
| 247 | |
| 248 | if (jffs2_part_info(tmp_part)){ |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 249 | printf("Partition changed to %d\n",tmp_part); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 250 | part_num=tmp_part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 251 | sprintf(str_part_num, "%d", part_num); |
| 252 | setenv("partition", str_part_num); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | printf("Partition %d is not valid partiton\n",tmp_part); |
| 257 | return 0; |
| 258 | |
| 259 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 260 | |
| 261 | /***************************************************/ |
| 262 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 263 | U_BOOT_CMD( |
| 264 | fsload, 3, 0, do_jffs2_fsload, |
wdenk | 6568eaa | 2004-06-09 12:42:26 +0000 | [diff] [blame] | 265 | "fsload\t- load binary file from a filesystem image\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 266 | "[ off ] [ filename ]\n" |
| 267 | " - load binary file from flash bank\n" |
| 268 | " with offset 'off'\n" |
| 269 | ); |
| 270 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 271 | U_BOOT_CMD( |
| 272 | fsinfo, 1, 1, do_jffs2_fsinfo, |
wdenk | 6568eaa | 2004-06-09 12:42:26 +0000 | [diff] [blame] | 273 | "fsinfo\t- print information about filesystems\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 274 | " - print information about filesystems\n" |
| 275 | ); |
| 276 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 277 | U_BOOT_CMD( |
| 278 | ls, 2, 1, do_jffs2_ls, |
wdenk | 6568eaa | 2004-06-09 12:42:26 +0000 | [diff] [blame] | 279 | "ls\t- list files in a directory (default /)\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 280 | "[ directory ]\n" |
| 281 | " - list files in a directory.\n" |
| 282 | ); |
| 283 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 284 | U_BOOT_CMD( |
| 285 | chpart, 2, 0, do_jffs2_chpart, |
wdenk | 6568eaa | 2004-06-09 12:42:26 +0000 | [diff] [blame] | 286 | "chpart\t- change active partition\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 287 | " - change active partition\n" |
| 288 | ); |
| 289 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | #endif /* CFG_CMD_JFFS2 */ |