2002-11-03 08:24:07 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
2004-01-04 05:24:46 +08:00
|
|
|
* (C) Copyright 2002
|
|
|
|
* Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
|
2002-11-03 08:24:07 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boot support
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <s_record.h>
|
2003-06-28 05:31:46 +08:00
|
|
|
#include <jffs2/load_kernel.h>
|
2002-11-03 08:24:07 +08:00
|
|
|
#include <net.h>
|
|
|
|
|
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
|
2004-01-04 05:24:46 +08:00
|
|
|
|
|
|
|
#include <cramfs/cramfs_fs.h>
|
|
|
|
|
2004-01-05 00:28:35 +08:00
|
|
|
extern int cramfs_check (struct part_info *info);
|
|
|
|
extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
|
|
|
|
extern int cramfs_ls (struct part_info *info, char *filename);
|
|
|
|
extern int cramfs_info (struct part_info *info);
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
static int part_num=0;
|
|
|
|
|
|
|
|
#ifndef CFG_JFFS_CUSTOM_PART
|
|
|
|
|
2004-08-03 07:22:59 +08:00
|
|
|
#define CFG_JFFS_SINGLE_PART 1
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
static struct part_info part;
|
|
|
|
|
2004-04-19 03:43:36 +08:00
|
|
|
#ifndef CONFIG_JFFS2_NAND
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
struct part_info*
|
|
|
|
jffs2_part_info(int part_num)
|
|
|
|
{
|
|
|
|
extern flash_info_t flash_info[]; /* info for FLASH chips */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(part_num==0){
|
|
|
|
|
|
|
|
if(part.usr_priv==(void*)1)
|
|
|
|
return ∂
|
|
|
|
|
|
|
|
memset(&part, 0, sizeof(part));
|
|
|
|
|
|
|
|
#if defined(CFG_JFFS2_FIRST_SECTOR)
|
|
|
|
part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
|
|
|
|
#else
|
|
|
|
part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Figure out flash partition size */
|
|
|
|
for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
|
|
|
|
part.size += flash_info[i].size;
|
|
|
|
|
|
|
|
#if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
|
|
|
|
part.size -=
|
|
|
|
flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
|
|
|
|
flash_info[CFG_JFFS2_FIRST_BANK].start[0];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Mark the struct as ready */
|
|
|
|
part.usr_priv=(void*)1;
|
|
|
|
|
|
|
|
return ∂
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-19 03:43:36 +08:00
|
|
|
|
|
|
|
#else /* CONFIG_JFFS2_NAND */
|
|
|
|
|
|
|
|
struct part_info*
|
|
|
|
jffs2_part_info(int part_num)
|
|
|
|
{
|
|
|
|
if(part_num==0){
|
|
|
|
|
|
|
|
if(part.usr_priv==(void*)1)
|
|
|
|
return ∂
|
|
|
|
|
|
|
|
memset(&part, 0, sizeof(part));
|
|
|
|
|
2004-06-11 05:34:36 +08:00
|
|
|
part.offset = (char *)CONFIG_JFFS2_NAND_OFF;
|
2004-04-19 03:43:36 +08:00
|
|
|
part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */
|
|
|
|
|
|
|
|
#ifndef CONFIG_JFFS2_NAND_DEV
|
|
|
|
#define CONFIG_JFFS2_NAND_DEV 0
|
|
|
|
#endif
|
|
|
|
/* nand device with the JFFS2 parition plus 1 */
|
|
|
|
part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1);
|
|
|
|
return ∂
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_JFFS2_NAND */
|
2002-11-03 08:24:07 +08:00
|
|
|
#endif /* ifndef CFG_JFFS_CUSTOM_PART */
|
2004-01-04 05:24:46 +08:00
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
int
|
|
|
|
do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2004-07-02 00:30:44 +08:00
|
|
|
struct part_info* jffs2_part_info(int);
|
|
|
|
int jffs2_1pass_load(char *, struct part_info *,const char *);
|
|
|
|
char *fsname;
|
2004-06-09 21:37:52 +08:00
|
|
|
char *filename;
|
2004-07-02 00:30:44 +08:00
|
|
|
int size;
|
|
|
|
struct part_info *part;
|
|
|
|
ulong offset = load_addr;
|
2004-06-09 21:37:52 +08:00
|
|
|
|
|
|
|
/* pre-set Boot file name */
|
|
|
|
if ((filename = getenv("bootfile")) == NULL) {
|
|
|
|
filename = "uImage";
|
|
|
|
}
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
if (argc == 2) {
|
|
|
|
filename = argv[1];
|
|
|
|
}
|
|
|
|
if (argc == 3) {
|
|
|
|
offset = simple_strtoul(argv[1], NULL, 16);
|
2004-03-24 06:14:11 +08:00
|
|
|
load_addr = offset;
|
2002-11-03 08:24:07 +08:00
|
|
|
filename = argv[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != (part=jffs2_part_info(part_num))){
|
|
|
|
|
2004-01-04 05:24:46 +08:00
|
|
|
/* check partition type for cramfs */
|
|
|
|
fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
|
|
|
|
printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
|
|
|
|
|
|
|
|
if (cramfs_check(part)) {
|
|
|
|
size = cramfs_load ((char *) offset, part, filename);
|
|
|
|
} else {
|
|
|
|
/* if this is not cramfs assume jffs2 */
|
|
|
|
size = jffs2_1pass_load((char *)offset, part, filename);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
|
|
|
if (size > 0) {
|
|
|
|
char buf[10];
|
2004-01-04 05:24:46 +08:00
|
|
|
printf("### %s load complete: %d bytes loaded to 0x%lx\n",
|
|
|
|
fsname, size, offset);
|
2002-11-03 08:24:07 +08:00
|
|
|
sprintf(buf, "%x", size);
|
|
|
|
setenv("filesize", buf);
|
|
|
|
} else {
|
2004-01-04 05:24:46 +08:00
|
|
|
printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return !(size > 0);
|
|
|
|
}
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("Active partition not valid\n");
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2005-06-10 18:00:19 +08:00
|
|
|
struct part_info* jffs2_part_info(int);
|
|
|
|
int jffs2_1pass_ls(struct part_info *,char *);
|
|
|
|
char *filename = "/";
|
2002-11-03 08:24:07 +08:00
|
|
|
int ret;
|
|
|
|
struct part_info *part;
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
filename = argv[1];
|
|
|
|
|
|
|
|
if (0 != (part=jffs2_part_info(part_num))){
|
|
|
|
|
2004-01-04 05:24:46 +08:00
|
|
|
/* check partition type for cramfs */
|
|
|
|
if (cramfs_check(part)) {
|
|
|
|
ret = cramfs_ls (part, filename);
|
|
|
|
} else {
|
|
|
|
/* if this is not cramfs assume jffs2 */
|
|
|
|
ret = jffs2_1pass_ls(part, filename);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
|
|
|
return (ret == 1);
|
|
|
|
}
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("Active partition not valid\n");
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2004-01-04 05:24:46 +08:00
|
|
|
struct part_info* jffs2_part_info(int);
|
|
|
|
int jffs2_1pass_info(struct part_info *);
|
2002-11-03 08:24:07 +08:00
|
|
|
struct part_info *part;
|
2004-01-04 05:24:46 +08:00
|
|
|
char *fsname;
|
|
|
|
int ret;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2004-01-04 05:24:46 +08:00
|
|
|
if ((part=jffs2_part_info(part_num))){
|
|
|
|
|
|
|
|
/* check partition type for cramfs */
|
|
|
|
fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
|
|
|
|
printf("### filesystem type is %s\n", fsname);
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2004-01-04 05:24:46 +08:00
|
|
|
if (cramfs_check(part)) {
|
|
|
|
ret = cramfs_info (part);
|
|
|
|
} else {
|
|
|
|
/* if this is not cramfs assume jffs2 */
|
|
|
|
ret = jffs2_1pass_info(part);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
|
|
|
return (ret == 1);
|
|
|
|
}
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("Active partition not valid\n");
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-03 07:22:59 +08:00
|
|
|
#ifndef CFG_JFFS_SINGLE_PART
|
2002-11-03 08:24:07 +08:00
|
|
|
int
|
|
|
|
do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int tmp_part;
|
2004-01-04 05:24:46 +08:00
|
|
|
char str_part_num[3];
|
2005-06-10 18:00:19 +08:00
|
|
|
struct part_info* jffs2_part_info(int);
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-06-10 18:00:19 +08:00
|
|
|
if (argc >= 2) {
|
2002-11-03 08:24:07 +08:00
|
|
|
tmp_part = simple_strtoul(argv[1], NULL, 16);
|
2005-06-10 18:00:19 +08:00
|
|
|
} else {
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("Need partition number in argument list\n");
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jffs2_part_info(tmp_part)){
|
2003-09-11 06:30:53 +08:00
|
|
|
printf("Partition changed to %d\n",tmp_part);
|
2002-11-03 08:24:07 +08:00
|
|
|
part_num=tmp_part;
|
2004-01-04 05:24:46 +08:00
|
|
|
sprintf(str_part_num, "%d", part_num);
|
|
|
|
setenv("partition", str_part_num);
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Partition %d is not valid partiton\n",tmp_part);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2004-09-09 06:03:11 +08:00
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
chpart, 2, 0, do_jffs2_chpart,
|
|
|
|
"chpart\t- change active partition\n",
|
|
|
|
" - change active partition\n"
|
|
|
|
);
|
2004-08-03 07:22:59 +08:00
|
|
|
#endif /* CFG_JFFS_SINGLE_PART */
|
2003-06-28 05:31:46 +08:00
|
|
|
|
|
|
|
/***************************************************/
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
fsload, 3, 0, do_jffs2_fsload,
|
2004-06-09 20:42:26 +08:00
|
|
|
"fsload\t- load binary file from a filesystem image\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
"[ off ] [ filename ]\n"
|
|
|
|
" - load binary file from flash bank\n"
|
|
|
|
" with offset 'off'\n"
|
|
|
|
);
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
fsinfo, 1, 1, do_jffs2_fsinfo,
|
2004-06-09 20:42:26 +08:00
|
|
|
"fsinfo\t- print information about filesystems\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
" - print information about filesystems\n"
|
|
|
|
);
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
ls, 2, 1, do_jffs2_ls,
|
2004-06-09 20:42:26 +08:00
|
|
|
"ls\t- list files in a directory (default /)\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
"[ directory ]\n"
|
|
|
|
" - list files in a directory.\n"
|
|
|
|
);
|
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
#endif /* CFG_CMD_JFFS2 */
|