2002-11-03 08:24:07 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
2005-08-08 07:03:24 +08:00
|
|
|
*
|
2004-01-04 05:24:46 +08:00
|
|
|
* (C) Copyright 2002
|
|
|
|
* Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
|
2005-08-08 07:03:24 +08:00
|
|
|
*
|
2004-01-04 05:24:46 +08:00
|
|
|
* (C) Copyright 2003
|
|
|
|
* Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
|
2002-11-03 08:24:07 +08:00
|
|
|
*
|
2005-08-08 07:03:24 +08:00
|
|
|
* (C) Copyright 2005
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* Added support for reading flash partition table from environment.
|
|
|
|
* Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
|
|
|
|
* kernel tree.
|
|
|
|
*
|
|
|
|
* $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
|
|
|
|
* Copyright 2002 SYSGO Real-Time Solutions GmbH
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2005-08-08 07:03:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Three environment variables are used by the parsing routines:
|
|
|
|
*
|
|
|
|
* 'partition' - keeps current partition identifier
|
|
|
|
*
|
|
|
|
* partition := <part-id>
|
|
|
|
* <part-id> := <dev-id>,part_num
|
|
|
|
*
|
2005-08-10 21:14:32 +08:00
|
|
|
*
|
2005-08-08 07:03:24 +08:00
|
|
|
* 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
|
|
|
|
*
|
|
|
|
* mtdids=<idmap>[,<idmap>,...]
|
|
|
|
*
|
|
|
|
* <idmap> := <dev-id>=<mtd-id>
|
2008-08-27 13:45:20 +08:00
|
|
|
* <dev-id> := 'nand'|'nor'|'onenand'<dev-num>
|
2005-08-08 07:03:24 +08:00
|
|
|
* <dev-num> := mtd device number, 0...
|
|
|
|
* <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 'mtdparts' - partition list
|
|
|
|
*
|
|
|
|
* mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
|
|
|
|
*
|
|
|
|
* <mtd-def> := <mtd-id>:<part-def>[,<part-def>...]
|
|
|
|
* <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)
|
|
|
|
* <part-def> := <size>[@<offset>][<name>][<ro-flag>]
|
|
|
|
* <size> := standard linux memsize OR '-' to denote all remaining space
|
|
|
|
* <offset> := partition start offset within the device
|
|
|
|
* <name> := '(' NAME ')'
|
|
|
|
* <ro-flag> := when set to 'ro' makes partition read-only (not used, passed to kernel)
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
|
|
|
|
* - if the above variables are not set defaults for a given target are used
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
*
|
|
|
|
* 1 NOR Flash, with 1 single writable partition:
|
|
|
|
* mtdids=nor0=edb7312-nor
|
|
|
|
* mtdparts=mtdparts=edb7312-nor:-
|
|
|
|
*
|
|
|
|
* 1 NOR Flash with 2 partitions, 1 NAND with one
|
|
|
|
* mtdids=nor0=edb7312-nor,nand0=edb7312-nand
|
|
|
|
* mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-09-15 06:03:35 +08:00
|
|
|
* JFFS2/CRAMFS support
|
2005-08-08 07:03:24 +08:00
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <jffs2/jffs2.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <cramfs/cramfs_fs.h>
|
|
|
|
|
2007-07-09 07:02:23 +08:00
|
|
|
#if defined(CONFIG_CMD_NAND)
|
2006-03-06 01:57:33 +08:00
|
|
|
#include <linux/mtd/nand.h>
|
2005-09-15 05:53:32 +08:00
|
|
|
#include <nand.h>
|
2007-07-09 07:02:23 +08:00
|
|
|
#endif
|
2008-08-27 13:45:20 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_ONENAND)
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/onenand.h>
|
|
|
|
#include <onenand_uboot.h>
|
|
|
|
#endif
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* enable/disable debugging messages */
|
2006-02-24 16:37:22 +08:00
|
|
|
#define DEBUG_JFFS
|
|
|
|
#undef DEBUG_JFFS
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2007-08-07 05:31:49 +08:00
|
|
|
#ifdef DEBUG_JFFS
|
2005-08-08 07:03:24 +08:00
|
|
|
# define DEBUGF(fmt, args...) printf(fmt ,##args)
|
|
|
|
#else
|
|
|
|
# define DEBUGF(fmt, args...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* special size referring to all the remaining space in a partition */
|
|
|
|
#define SIZE_REMAINING 0xFFFFFFFF
|
|
|
|
|
|
|
|
/* special offset value, it is used when not provided by user
|
|
|
|
*
|
|
|
|
* this value is used temporarily during parsing, later such offests
|
|
|
|
* are recalculated */
|
|
|
|
#define OFFSET_NOT_SPECIFIED 0xFFFFFFFF
|
|
|
|
|
|
|
|
/* minimum partition size */
|
|
|
|
#define MIN_PART_SIZE 4096
|
|
|
|
|
|
|
|
/* this flag needs to be set in part_info struct mask_flags
|
|
|
|
* field for read-only partitions */
|
2006-02-24 16:37:22 +08:00
|
|
|
#define MTD_WRITEABLE_CMD 1
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
/* current active device and partition number */
|
2009-05-16 18:04:22 +08:00
|
|
|
#ifdef CONFIG_CMD_MTDPARTS
|
|
|
|
/* Use the ones declared in cmd_mtdparts.c */
|
|
|
|
extern struct mtd_device *current_mtd_dev;
|
|
|
|
extern u8 current_mtd_partnum;
|
|
|
|
#else
|
|
|
|
/* Use local ones */
|
|
|
|
struct mtd_device *current_mtd_dev = NULL;
|
|
|
|
u8 current_mtd_partnum = 0;
|
|
|
|
#endif
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
#if defined(CONFIG_CMD_CRAMFS)
|
|
|
|
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);
|
|
|
|
#else
|
|
|
|
/* defining empty macros for function names is ugly but avoids ifdef clutter
|
|
|
|
* all over the code */
|
|
|
|
#define cramfs_check(x) (0)
|
|
|
|
#define cramfs_load(x,y,z) (-1)
|
|
|
|
#define cramfs_ls(x,y) (0)
|
|
|
|
#define cramfs_info(x) (0)
|
|
|
|
#endif
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
#ifndef CONFIG_CMD_MTDPARTS
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
2009-03-19 20:30:36 +08:00
|
|
|
* Check device number to be within valid range for given device type.
|
2005-08-08 07:03:24 +08:00
|
|
|
*
|
2009-03-19 20:30:36 +08:00
|
|
|
* @param dev device to validate
|
|
|
|
* @return 0 if device is valid, 1 otherwise
|
2002-11-03 08:24:07 +08:00
|
|
|
*/
|
2009-03-19 20:30:36 +08:00
|
|
|
static int mtd_device_validate(u8 type, u8 num, u32 *size)
|
2005-08-08 07:03:24 +08:00
|
|
|
{
|
2009-03-19 20:30:36 +08:00
|
|
|
if (type == MTD_DEV_TYPE_NOR) {
|
|
|
|
#if defined(CONFIG_CMD_FLASH)
|
|
|
|
if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
|
|
|
|
extern flash_info_t flash_info[];
|
|
|
|
*size = flash_info[num].size;
|
2004-01-05 00:28:35 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
return 0;
|
2005-08-08 07:03:24 +08:00
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
printf("no such FLASH device: %s%d (valid range 0 ... %d\n",
|
|
|
|
MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
|
|
|
|
#else
|
|
|
|
printf("support for FLASH devices not present\n");
|
|
|
|
#endif
|
|
|
|
} else if (type == MTD_DEV_TYPE_NAND) {
|
|
|
|
#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
|
2017-06-27 08:12:55 +08:00
|
|
|
struct mtd_info *mtd = get_nand_dev_by_index(num);
|
|
|
|
if (mtd) {
|
|
|
|
*size = mtd->size;
|
2009-03-19 20:30:36 +08:00
|
|
|
return 0;
|
2005-08-08 07:03:24 +08:00
|
|
|
}
|
2004-08-03 07:22:59 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
printf("no such NAND device: %s%d (valid range 0 ... %d)\n",
|
|
|
|
MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
|
|
|
|
#else
|
|
|
|
printf("support for NAND devices not present\n");
|
|
|
|
#endif
|
|
|
|
} else if (type == MTD_DEV_TYPE_ONENAND) {
|
|
|
|
#if defined(CONFIG_CMD_ONENAND)
|
|
|
|
*size = onenand_mtd.size;
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
printf("support for OneNAND devices not present\n");
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
printf("Unknown defice type %d\n", type);
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
return 1;
|
2005-08-08 07:03:24 +08:00
|
|
|
}
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
2009-03-19 20:30:36 +08:00
|
|
|
* Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
|
|
|
|
* return device type and number.
|
2005-08-08 07:03:24 +08:00
|
|
|
*
|
2009-03-19 20:30:36 +08:00
|
|
|
* @param id string describing device id
|
|
|
|
* @param ret_id output pointer to next char after parse completes (output)
|
|
|
|
* @param dev_type parsed device type (output)
|
|
|
|
* @param dev_num parsed device number (output)
|
2005-08-08 07:03:24 +08:00
|
|
|
* @return 0 on success, 1 otherwise
|
|
|
|
*/
|
2009-03-19 20:30:36 +08:00
|
|
|
static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
2009-03-19 20:30:36 +08:00
|
|
|
const char *p = id;
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
*dev_type = 0;
|
|
|
|
if (strncmp(p, "nand", 4) == 0) {
|
|
|
|
*dev_type = MTD_DEV_TYPE_NAND;
|
|
|
|
p += 4;
|
|
|
|
} else if (strncmp(p, "nor", 3) == 0) {
|
|
|
|
*dev_type = MTD_DEV_TYPE_NOR;
|
|
|
|
p += 3;
|
|
|
|
} else if (strncmp(p, "onenand", 7) == 0) {
|
|
|
|
*dev_type = MTD_DEV_TYPE_ONENAND;
|
|
|
|
p += 7;
|
|
|
|
} else {
|
|
|
|
printf("incorrect device type in %s\n", id);
|
2005-08-08 07:03:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
if (!isdigit(*p)) {
|
|
|
|
printf("incorrect device number in %s\n", id);
|
2005-08-08 07:03:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
*dev_num = simple_strtoul(p, (char **)&p, 0);
|
|
|
|
if (ret_id)
|
|
|
|
*ret_id = p;
|
2005-08-08 07:03:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-19 20:30:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/*
|
|
|
|
* 'Static' version of command line mtdparts_init() routine. Single partition on
|
|
|
|
* a single device configuration.
|
|
|
|
*/
|
|
|
|
|
2008-12-31 01:35:57 +08:00
|
|
|
/**
|
|
|
|
* Calculate sector size.
|
|
|
|
*
|
|
|
|
* @return sector size
|
|
|
|
*/
|
|
|
|
static inline u32 get_part_sector_size_nand(struct mtdids *id)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
|
2016-05-31 02:57:54 +08:00
|
|
|
struct mtd_info *mtd;
|
2008-12-31 01:35:57 +08:00
|
|
|
|
2017-06-27 08:12:55 +08:00
|
|
|
mtd = get_nand_dev_by_index(id->num);
|
2008-12-31 01:35:57 +08:00
|
|
|
|
2016-05-31 02:57:54 +08:00
|
|
|
return mtd->erasesize;
|
2008-12-31 01:35:57 +08:00
|
|
|
#else
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *part)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_CMD_FLASH)
|
|
|
|
extern flash_info_t flash_info[];
|
|
|
|
|
|
|
|
u32 end_phys, start_phys, sector_size = 0, size = 0;
|
|
|
|
int i;
|
|
|
|
flash_info_t *flash;
|
|
|
|
|
|
|
|
flash = &flash_info[id->num];
|
|
|
|
|
|
|
|
start_phys = flash->start[0] + part->offset;
|
2010-12-31 05:47:56 +08:00
|
|
|
end_phys = start_phys + part->size - 1;
|
2008-12-31 01:35:57 +08:00
|
|
|
|
|
|
|
for (i = 0; i < flash->sector_count; i++) {
|
|
|
|
if (flash->start[i] >= end_phys)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (flash->start[i] >= start_phys) {
|
|
|
|
if (i == flash->sector_count - 1) {
|
|
|
|
size = flash->start[0] + flash->size - flash->start[i];
|
|
|
|
} else {
|
|
|
|
size = flash->start[i+1] - flash->start[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sector_size < size)
|
|
|
|
sector_size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sector_size;
|
|
|
|
#else
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 get_part_sector_size_onenand(void)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_CMD_ONENAND)
|
|
|
|
struct mtd_info *mtd;
|
|
|
|
|
|
|
|
mtd = &onenand_mtd;
|
|
|
|
|
|
|
|
return mtd->erasesize;
|
|
|
|
#else
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part)
|
|
|
|
{
|
|
|
|
if (id->type == MTD_DEV_TYPE_NAND)
|
|
|
|
return get_part_sector_size_nand(id);
|
|
|
|
else if (id->type == MTD_DEV_TYPE_NOR)
|
|
|
|
return get_part_sector_size_nor(id, part);
|
|
|
|
else if (id->type == MTD_DEV_TYPE_ONENAND)
|
|
|
|
return get_part_sector_size_onenand();
|
|
|
|
else
|
|
|
|
DEBUGF("Error: Unknown device type.\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
|
|
|
* Parse and initialize global mtdids mapping and create global
|
2005-08-10 21:14:32 +08:00
|
|
|
* device/partition list.
|
2005-08-08 07:03:24 +08:00
|
|
|
*
|
2009-05-16 18:04:22 +08:00
|
|
|
* 'Static' version of command line mtdparts_init() routine. Single partition on
|
|
|
|
* a single device configuration.
|
|
|
|
*
|
2005-08-08 07:03:24 +08:00
|
|
|
* @return 0 on success, 1 otherwise
|
|
|
|
*/
|
|
|
|
int mtdparts_init(void)
|
|
|
|
{
|
|
|
|
static int initialized = 0;
|
|
|
|
u32 size;
|
|
|
|
char *dev_name;
|
|
|
|
|
|
|
|
DEBUGF("\n---mtdparts_init---\n");
|
|
|
|
if (!initialized) {
|
2005-08-10 03:41:20 +08:00
|
|
|
struct mtdids *id;
|
|
|
|
struct part_info *part;
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
initialized = 1;
|
2009-05-16 18:04:22 +08:00
|
|
|
current_mtd_dev = (struct mtd_device *)
|
2005-08-08 07:03:24 +08:00
|
|
|
malloc(sizeof(struct mtd_device) +
|
|
|
|
sizeof(struct part_info) +
|
|
|
|
sizeof(struct mtdids));
|
2009-05-16 18:04:22 +08:00
|
|
|
if (!current_mtd_dev) {
|
2005-08-08 07:03:24 +08:00
|
|
|
printf("out of memory\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2009-05-16 18:04:22 +08:00
|
|
|
memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
|
|
|
|
sizeof(struct part_info) + sizeof(struct mtdids));
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2009-05-16 18:04:22 +08:00
|
|
|
id = (struct mtdids *)(current_mtd_dev + 1);
|
2005-08-10 03:41:20 +08:00
|
|
|
part = (struct part_info *)(id + 1);
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* id */
|
|
|
|
id->mtd_id = "single part";
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
#if defined(CONFIG_JFFS2_DEV)
|
|
|
|
dev_name = CONFIG_JFFS2_DEV;
|
2002-11-03 08:24:07 +08:00
|
|
|
#else
|
2005-08-08 07:03:24 +08:00
|
|
|
dev_name = "nor0";
|
2002-11-03 08:24:07 +08:00
|
|
|
#endif
|
|
|
|
|
2009-03-19 20:30:36 +08:00
|
|
|
if ((mtd_id_parse(dev_name, NULL, &id->type, &id->num) != 0) ||
|
|
|
|
(mtd_device_validate(id->type, id->num, &size) != 0)) {
|
2005-08-08 07:03:24 +08:00
|
|
|
printf("incorrect device: %s%d\n", MTD_DEV_TYPE(id->type), id->num);
|
2009-05-16 18:04:22 +08:00
|
|
|
free(current_mtd_dev);
|
2005-08-08 07:03:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
id->size = size;
|
|
|
|
INIT_LIST_HEAD(&id->link);
|
|
|
|
|
|
|
|
DEBUGF("dev id: type = %d, num = %d, size = 0x%08lx, mtd_id = %s\n",
|
|
|
|
id->type, id->num, id->size, id->mtd_id);
|
|
|
|
|
|
|
|
/* partition */
|
|
|
|
part->name = "static";
|
|
|
|
part->auto_name = 0;
|
|
|
|
|
|
|
|
#if defined(CONFIG_JFFS2_PART_SIZE)
|
|
|
|
part->size = CONFIG_JFFS2_PART_SIZE;
|
|
|
|
#else
|
|
|
|
part->size = SIZE_REMAINING;
|
|
|
|
#endif
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
#if defined(CONFIG_JFFS2_PART_OFFSET)
|
|
|
|
part->offset = CONFIG_JFFS2_PART_OFFSET;
|
|
|
|
#else
|
|
|
|
part->offset = 0x00000000;
|
2002-11-03 08:24:07 +08:00
|
|
|
#endif
|
|
|
|
|
2009-05-16 18:04:22 +08:00
|
|
|
part->dev = current_mtd_dev;
|
2005-08-08 07:03:24 +08:00
|
|
|
INIT_LIST_HEAD(&part->link);
|
|
|
|
|
|
|
|
/* recalculate size if needed */
|
|
|
|
if (part->size == SIZE_REMAINING)
|
|
|
|
part->size = id->size - part->offset;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2010-01-08 21:03:06 +08:00
|
|
|
part->sector_size = get_part_sector_size(id, part);
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
DEBUGF("part : name = %s, size = 0x%08lx, offset = 0x%08lx\n",
|
|
|
|
part->name, part->size, part->offset);
|
|
|
|
|
|
|
|
/* device */
|
2009-05-16 18:04:22 +08:00
|
|
|
current_mtd_dev->id = id;
|
|
|
|
INIT_LIST_HEAD(¤t_mtd_dev->link);
|
|
|
|
current_mtd_dev->num_parts = 1;
|
|
|
|
INIT_LIST_HEAD(¤t_mtd_dev->parts);
|
|
|
|
list_add(&part->link, ¤t_mtd_dev->parts);
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2005-08-08 07:03:24 +08:00
|
|
|
|
2002-11-03 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-19 20:30:36 +08:00
|
|
|
#endif /* #ifndef CONFIG_CMD_MTDPARTS */
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
|
|
|
* Return pointer to the partition of a requested number from a requested
|
|
|
|
* device.
|
|
|
|
*
|
|
|
|
* @param dev device that is to be searched for a partition
|
|
|
|
* @param part_num requested partition number
|
|
|
|
* @return pointer to the part_info, NULL otherwise
|
|
|
|
*/
|
|
|
|
static struct part_info* jffs2_part_info(struct mtd_device *dev, unsigned int part_num)
|
2004-04-19 03:43:36 +08:00
|
|
|
{
|
2005-08-08 07:03:24 +08:00
|
|
|
struct list_head *entry;
|
|
|
|
struct part_info *part;
|
|
|
|
int num;
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
DEBUGF("\n--- jffs2_part_info: partition number %d for device %s%d (%s)\n",
|
|
|
|
part_num, MTD_DEV_TYPE(dev->id->type),
|
|
|
|
dev->id->num, dev->id->mtd_id);
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
if (part_num >= dev->num_parts) {
|
|
|
|
printf("invalid partition number %d for device %s%d (%s)\n",
|
|
|
|
part_num, MTD_DEV_TYPE(dev->id->type),
|
|
|
|
dev->id->num, dev->id->mtd_id);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-19 03:43:36 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* locate partition number, return it */
|
|
|
|
num = 0;
|
|
|
|
list_for_each(entry, &dev->parts) {
|
|
|
|
part = list_entry(entry, struct part_info, link);
|
|
|
|
|
|
|
|
if (part_num == num++) {
|
|
|
|
return part;
|
|
|
|
}
|
2004-04-19 03:43:36 +08:00
|
|
|
}
|
2005-08-08 07:03:24 +08:00
|
|
|
|
|
|
|
return NULL;
|
2004-04-19 03:43:36 +08:00
|
|
|
}
|
|
|
|
|
2007-08-07 05:31:49 +08:00
|
|
|
/***************************************************/
|
2016-02-06 11:30:11 +08:00
|
|
|
/* U-Boot commands */
|
2007-08-07 05:31:49 +08:00
|
|
|
/***************************************************/
|
2004-01-04 05:24:46 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
|
|
|
* Routine implementing fsload u-boot command. This routine tries to load
|
|
|
|
* a requested file from jffs2/cramfs filesystem on a current partition.
|
|
|
|
*
|
|
|
|
* @param cmdtp command internal data
|
|
|
|
* @param flag command flag
|
|
|
|
* @param argc number of arguments supplied to the command
|
|
|
|
* @param argv arguments list
|
|
|
|
* @return 0 on success, 1 otherwise
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
2004-07-02 00:30:44 +08:00
|
|
|
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 */
|
2017-08-04 02:22:12 +08:00
|
|
|
filename = env_get("bootfile");
|
|
|
|
if (!filename)
|
2004-06-09 21:37:52 +08:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* make sure we are in sync with env variables */
|
|
|
|
if (mtdparts_init() !=0)
|
|
|
|
return 1;
|
|
|
|
|
2009-05-16 18:04:22 +08:00
|
|
|
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2007-09-15 06:03:35 +08:00
|
|
|
/* check partition type for cramfs */
|
|
|
|
fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
|
2004-01-04 05:24:46 +08:00
|
|
|
printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
|
|
|
|
|
|
|
|
if (cramfs_check(part)) {
|
|
|
|
size = cramfs_load ((char *) offset, part, filename);
|
|
|
|
} else {
|
2007-09-15 06:03:35 +08:00
|
|
|
/* if this is not cramfs assume jffs2 */
|
2004-01-04 05:24:46 +08:00
|
|
|
size = jffs2_1pass_load((char *)offset, part, filename);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
|
|
|
if (size > 0) {
|
2004-01-04 05:24:46 +08:00
|
|
|
printf("### %s load complete: %d bytes loaded to 0x%lx\n",
|
|
|
|
fsname, size, offset);
|
2017-08-04 02:22:10 +08:00
|
|
|
env_set_hex("filesize", size);
|
2002-11-03 08:24:07 +08:00
|
|
|
} 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);
|
|
|
|
}
|
2005-08-16 15:32:45 +08:00
|
|
|
return 1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
|
|
|
* Routine implementing u-boot ls command which lists content of a given
|
|
|
|
* directory on a current partition.
|
|
|
|
*
|
|
|
|
* @param cmdtp command internal data
|
|
|
|
* @param flag command flag
|
|
|
|
* @param argc number of arguments supplied to the command
|
|
|
|
* @param argv arguments list
|
|
|
|
* @return 0 on success, 1 otherwise
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
2005-06-10 18:00:19 +08:00
|
|
|
char *filename = "/";
|
2002-11-03 08:24:07 +08:00
|
|
|
int ret;
|
|
|
|
struct part_info *part;
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
filename = argv[1];
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* make sure we are in sync with env variables */
|
|
|
|
if (mtdparts_init() !=0)
|
|
|
|
return 1;
|
|
|
|
|
2009-05-16 18:04:22 +08:00
|
|
|
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2004-01-04 05:24:46 +08:00
|
|
|
/* check partition type for cramfs */
|
|
|
|
if (cramfs_check(part)) {
|
|
|
|
ret = cramfs_ls (part, filename);
|
|
|
|
} else {
|
2007-09-15 06:03:35 +08:00
|
|
|
/* if this is not cramfs assume jffs2 */
|
2004-01-04 05:24:46 +08:00
|
|
|
ret = jffs2_1pass_ls(part, filename);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-16 15:32:45 +08:00
|
|
|
return ret ? 0 : 1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2005-08-16 15:32:45 +08:00
|
|
|
return 1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/**
|
|
|
|
* Routine implementing u-boot fsinfo command. This routine prints out
|
|
|
|
* miscellaneous filesystem informations/statistics.
|
|
|
|
*
|
|
|
|
* @param cmdtp command internal data
|
|
|
|
* @param flag command flag
|
|
|
|
* @param argc number of arguments supplied to the command
|
|
|
|
* @param argv arguments list
|
|
|
|
* @return 0 on success, 1 otherwise
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-11-03 08:24:07 +08:00
|
|
|
{
|
|
|
|
struct part_info *part;
|
2007-09-15 06:03:35 +08:00
|
|
|
char *fsname;
|
2004-01-04 05:24:46 +08:00
|
|
|
int ret;
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/* make sure we are in sync with env variables */
|
|
|
|
if (mtdparts_init() !=0)
|
|
|
|
return 1;
|
2005-08-10 21:14:32 +08:00
|
|
|
|
2009-05-16 18:04:22 +08:00
|
|
|
if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
|
2004-01-04 05:24:46 +08:00
|
|
|
|
|
|
|
/* check partition type for cramfs */
|
2007-09-15 06:03:35 +08:00
|
|
|
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 {
|
2007-09-15 06:03:35 +08:00
|
|
|
/* if this is not cramfs assume jffs2 */
|
2004-01-04 05:24:46 +08:00
|
|
|
ret = jffs2_1pass_info(part);
|
|
|
|
}
|
2002-11-03 08:24:07 +08:00
|
|
|
|
2005-08-16 15:32:45 +08:00
|
|
|
return ret ? 0 : 1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
2005-08-16 15:32:45 +08:00
|
|
|
return 1;
|
2002-11-03 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2005-08-08 07:03:24 +08:00
|
|
|
/***************************************************/
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
fsload, 3, 0, do_jffs2_fsload,
|
2009-01-28 08:03:12 +08:00
|
|
|
"load binary file from a filesystem image",
|
2003-06-28 05:31:46 +08:00
|
|
|
"[ off ] [ filename ]\n"
|
|
|
|
" - load binary file from flash bank\n"
|
2009-05-24 23:06:54 +08:00
|
|
|
" with offset 'off'"
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
2005-08-08 07:03:24 +08:00
|
|
|
U_BOOT_CMD(
|
2017-05-30 20:18:55 +08:00
|
|
|
fsls, 2, 1, do_jffs2_ls,
|
2009-01-28 08:03:12 +08:00
|
|
|
"list files in a directory (default /)",
|
2009-05-24 23:06:54 +08:00
|
|
|
"[ directory ]"
|
2005-08-08 07:03:24 +08:00
|
|
|
);
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
fsinfo, 1, 1, do_jffs2_fsinfo,
|
2009-01-28 08:03:12 +08:00
|
|
|
"print information about filesystems",
|
2009-05-24 23:06:54 +08:00
|
|
|
""
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
2005-08-08 07:03:24 +08:00
|
|
|
/***************************************************/
|