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 | |
| 52 | struct part_info* |
| 53 | jffs2_part_info(int part_num) |
| 54 | { |
| 55 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 56 | int i; |
| 57 | |
| 58 | if(part_num==0){ |
| 59 | |
| 60 | if(part.usr_priv==(void*)1) |
| 61 | return ∂ |
| 62 | |
| 63 | memset(&part, 0, sizeof(part)); |
| 64 | |
| 65 | #if defined(CFG_JFFS2_FIRST_SECTOR) |
| 66 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR]; |
| 67 | #else |
| 68 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0]; |
| 69 | #endif |
| 70 | |
| 71 | /* Figure out flash partition size */ |
| 72 | for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++) |
| 73 | part.size += flash_info[i].size; |
| 74 | |
| 75 | #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0) |
| 76 | part.size -= |
| 77 | flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] - |
| 78 | flash_info[CFG_JFFS2_FIRST_BANK].start[0]; |
| 79 | #endif |
| 80 | |
| 81 | /* unused in current jffs2 loader */ |
| 82 | part.erasesize = 0; |
| 83 | |
| 84 | /* Mark the struct as ready */ |
| 85 | part.usr_priv=(void*)1; |
| 86 | |
| 87 | return ∂ |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | #endif /* ifndef CFG_JFFS_CUSTOM_PART */ |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 92 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | int |
| 94 | do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 95 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 96 | struct part_info* jffs2_part_info(int); |
| 97 | int jffs2_1pass_load(char *, struct part_info *,const char *); |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 98 | char *fsname; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 100 | char *filename = "uImage"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | ulong offset = CFG_LOAD_ADDR; |
| 102 | int size; |
| 103 | struct part_info *part; |
| 104 | |
| 105 | if (argc == 2) { |
| 106 | filename = argv[1]; |
| 107 | } |
| 108 | if (argc == 3) { |
| 109 | offset = simple_strtoul(argv[1], NULL, 16); |
| 110 | filename = argv[2]; |
| 111 | } |
| 112 | |
| 113 | if (0 != (part=jffs2_part_info(part_num))){ |
| 114 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 115 | /* check partition type for cramfs */ |
| 116 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); |
| 117 | printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset); |
| 118 | |
| 119 | if (cramfs_check(part)) { |
| 120 | size = cramfs_load ((char *) offset, part, filename); |
| 121 | } else { |
| 122 | /* if this is not cramfs assume jffs2 */ |
| 123 | size = jffs2_1pass_load((char *)offset, part, filename); |
| 124 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 125 | |
| 126 | if (size > 0) { |
| 127 | char buf[10]; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 128 | printf("### %s load complete: %d bytes loaded to 0x%lx\n", |
| 129 | fsname, size, offset); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | sprintf(buf, "%x", size); |
| 131 | setenv("filesize", buf); |
| 132 | } else { |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 133 | printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return !(size > 0); |
| 137 | } |
| 138 | printf("Active partition not valid\n"); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int |
| 143 | do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 144 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 145 | struct part_info* jffs2_part_info(int); |
| 146 | int jffs2_1pass_ls(struct part_info *,char *); |
| 147 | |
| 148 | char *filename = "/"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 149 | int ret; |
| 150 | struct part_info *part; |
| 151 | |
| 152 | if (argc == 2) |
| 153 | filename = argv[1]; |
| 154 | |
| 155 | if (0 != (part=jffs2_part_info(part_num))){ |
| 156 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 157 | /* check partition type for cramfs */ |
| 158 | if (cramfs_check(part)) { |
| 159 | ret = cramfs_ls (part, filename); |
| 160 | } else { |
| 161 | /* if this is not cramfs assume jffs2 */ |
| 162 | ret = jffs2_1pass_ls(part, filename); |
| 163 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | |
| 165 | return (ret == 1); |
| 166 | } |
| 167 | printf("Active partition not valid\n"); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int |
| 172 | do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 173 | { |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 174 | struct part_info* jffs2_part_info(int); |
| 175 | int jffs2_1pass_info(struct part_info *); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 176 | struct part_info *part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 177 | char *fsname; |
| 178 | int ret; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 179 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 180 | if ((part=jffs2_part_info(part_num))){ |
| 181 | |
| 182 | /* check partition type for cramfs */ |
| 183 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); |
| 184 | printf("### filesystem type is %s\n", fsname); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 186 | if (cramfs_check(part)) { |
| 187 | ret = cramfs_info (part); |
| 188 | } else { |
| 189 | /* if this is not cramfs assume jffs2 */ |
| 190 | ret = jffs2_1pass_info(part); |
| 191 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 192 | |
| 193 | return (ret == 1); |
| 194 | } |
| 195 | printf("Active partition not valid\n"); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | int |
| 200 | do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 201 | { |
| 202 | int tmp_part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 203 | char str_part_num[3]; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 204 | struct part_info* jffs2_part_info(int); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 205 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | if (argc >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 207 | tmp_part = simple_strtoul(argv[1], NULL, 16); |
| 208 | }else{ |
| 209 | printf("Need partition number in argument list\n"); |
| 210 | return 0; |
| 211 | |
| 212 | } |
| 213 | |
| 214 | if (jffs2_part_info(tmp_part)){ |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 215 | printf("Partition changed to %d\n",tmp_part); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 216 | part_num=tmp_part; |
wdenk | ae65f50 | 2004-01-03 21:24:46 +0000 | [diff] [blame] | 217 | sprintf(str_part_num, "%d", part_num); |
| 218 | setenv("partition", str_part_num); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | printf("Partition %d is not valid partiton\n",tmp_part); |
| 223 | return 0; |
| 224 | |
| 225 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 226 | |
| 227 | /***************************************************/ |
| 228 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 229 | U_BOOT_CMD( |
| 230 | fsload, 3, 0, do_jffs2_fsload, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 231 | "fsload - load binary file from a filesystem image\n", |
| 232 | "[ off ] [ filename ]\n" |
| 233 | " - load binary file from flash bank\n" |
| 234 | " with offset 'off'\n" |
| 235 | ); |
| 236 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 237 | U_BOOT_CMD( |
| 238 | fsinfo, 1, 1, do_jffs2_fsinfo, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 239 | "fsinfo - print information about filesystems\n", |
| 240 | " - print information about filesystems\n" |
| 241 | ); |
| 242 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 243 | U_BOOT_CMD( |
| 244 | ls, 2, 1, do_jffs2_ls, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 245 | "ls - list files in a directory (default /)\n", |
| 246 | "[ directory ]\n" |
| 247 | " - list files in a directory.\n" |
| 248 | ); |
| 249 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 250 | U_BOOT_CMD( |
| 251 | chpart, 2, 0, do_jffs2_chpart, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 252 | "chpart - change active partition\n", |
| 253 | " - change active partition\n" |
| 254 | ); |
| 255 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | #endif /* CFG_CMD_JFFS2 */ |