Commit 700a0c64 authored by Wolfgang Denk's avatar Wolfgang Denk

Add common (with Linux) MTD partition scheme and "mtdparts" command

Old, obsolete and duplicated code was cleaned up and replace by the
new partitioning method. There are two possible approaches now:
* define a single, static partition
* use mtdparts command line option and dynamic partitioning
Default is static partitioning.
parent 452e8e72
......@@ -2,6 +2,30 @@
Changes for U-Boot 1.1.3:
======================================================================
* Add common (with Linux) MTD partition scheme and "mtdparts" command
Old, obsolete and duplicated code was cleaned up and replace by the
new partitioning method. There are two possible approaches now:
The first one is to define a single, static partition:
#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_DEV "nor0"
#define CONFIG_JFFS2_PART_SIZE 0xFFFFFFFF /* use whole device */
#define CONFIG_JFFS2_PART_SIZE 0x00100000 /* use 1MB */
#define CONFIG_JFFS2_PART_OFFSET 0x00000000
The second method uses the mtdparts command line option and dynamic
partitioning:
/* mtdparts command line support */
#define CONFIG_JFFS2_CMDLINE
#define MTDIDS_DEFAULT "nor1=zuma-1,nor2=zuma-2"
#define MTDPARTS_DEFAULT "mtdparts=zuma-1:-(jffs2),zuma-2:-(user)"
Command line of course produces bigger images, and may be inappropriate
for some targets, so by default it's off.
* Fix build problems for PM856 Board
* Fix sign extension bug in 'fpga loadb' command;
......
......@@ -21,4 +21,8 @@
# MA 02111-1307 USA
#
# Reserve 256 kB for Monitor
TEXT_BASE = 0xFFFC0000
# Reserve 320 kB for Monitor
#TEXT_BASE = 0xFFFB0000
......@@ -24,6 +24,7 @@
*/
#include <config.h>
#include <asm/processor.h>
#include <74xx_7xx.h>
#include <mpc106.h>
#include <version.h>
......
......@@ -27,6 +27,7 @@
#include <pci.h>
#include <mpc106.h>
#include <asm/processor.h>
/* defines L2CR register for MPC750 */
......
......@@ -24,6 +24,7 @@
*/
#include <config.h>
#include <asm/processor.h>
#include <version.h>
#include <mpc106.h>
......
......@@ -197,9 +197,25 @@
#define CFG_DIRECT_FLASH_TFTP
#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
#define CFG_JFFS2_FIRST_BANK 0
#define CFG_JFFS2_NUM_BANKS CFG_MAX_FLASH_BANKS
#define CFG_JFFS2_FIRST_SECTOR 4
/*
* JFFS2 partitions
*
*/
/* No command line, one static partition, whole device */
#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_DEV "nor0"
#define CONFIG_JFFS2_PART_SIZE 0xFFFFFFFF
#define CONFIG_JFFS2_PART_OFFSET 0x00000000
/* mtdparts command line support */
/* Note: fake mtd_id used, no linux mtd map file */
/*
#define CONFIG_JFFS2_CMDLINE
#define MTDIDS_DEFAULT "nor0=fads0,nor1=fads-1,nor2=fads-2,nor3=fads-3"
#define MTDPARTS_DEFAULT "mtdparts=fads-0:-@1m(user1),fads-1:-(user2),fads-2:-(user3),fads-3:-(user4)"
*/
#define CFG_JFFS2_SORT_FRAGMENTS
#endif /* CFG_CMD_JFFS2 */
......
......@@ -447,60 +447,3 @@ flash_real_protect(flash_info_t *info, long sector, int prot)
*addr = FLASH_CMD_RESET;
return (0);
}
/*-----------------------------------------------------------------------
* Support for flash file system (JFFS2)
*
* We use custom partition info function because we have to fit the
* file system image between first sector (containing hard reset
* configuration word) and the sector containing U-Boot image. Standard
* partition info function does not allow for last sector specification
* and assumes that the file system occupies flash bank up to and
* including bank's last sector.
*/
#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CFG_JFFS_CUSTOM_PART)
#error TODO
#ifndef CFG_JFFS2_FIRST_SECTOR
#define CFG_JFFS2_FIRST_SECTOR 0
#endif
#ifndef CFG_JFFS2_FIRST_BANK
#define CFG_JFFS2_FIRST_BANK 0
#endif
#ifndef CFG_JFFS2_NUM_BANKS
#define CFG_JFFS2_NUM_BANKS 1
#endif
#define CFG_JFFS2_LAST_BANK (CFG_JFFS2_FIRST_BANK + CFG_JFFS2_NUM_BANKS - 1)
#include <jffs2/jffs2.h>
static struct part_info partition;
struct part_info *jffs2_part_info(int part_num)
{
int i;
if (part_num == 0) {
if (partition.usr_priv == 0) {
partition.offset =
(unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
for (i = CFG_JFFS2_FIRST_BANK; i <= CFG_JFFS2_LAST_BANK; i++)
partition.size += flash_info[i].size;
partition.size -=
flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
flash_info[CFG_JFFS2_FIRST_BANK].start[0];
#ifdef CFG_JFFS2_LAST_SECTOR
i = flash_info[CFG_JFFS2_LAST_BANK].sector_count - 1;
partition.size -=
flash_info[CFG_JFFS2_LAST_BANK].start[i] -
flash_info[CFG_JFFS2_LAST_BANK].start[CFG_JFFS2_LAST_SECTOR];
#endif
partition.usr_priv = (void *)1;
}
return &partition;
}
return 0;
}
#endif /* JFFS2 */
......@@ -35,10 +35,6 @@
#include <common.h>
#include <asm/arch/pxa-regs.h>
#if defined CFG_JFFS_CUSTOM_PART
#include <jffs2/jffs2.h>
#endif
/* Debugging macros ------------------------------------------------------ */
#undef FLASH_DEBUG
......@@ -78,179 +74,6 @@
flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
#if defined CFG_JFFS_CUSTOM_PART
/**
* jffs2_part_info - get information about a JFFS2 partition
*
* @part_num: number of the partition you want to get info about
* @return: struct part_info* in case of success, 0 if failure
*/
static struct part_info part;
static int current_part = -1;
#ifdef CONFIG_MTD_INNOKOM_16MB
#ifdef CONFIG_MTD_INNOKOM_64MB
#error Please define only one CONFIG_MTD_INNOKOM_XXMB option.
#endif
struct part_info* jffs2_part_info(int part_num) {
void *jffs2_priv_saved = part.jffs2_priv;
PRINTK2("jffs2_part_info: part_num=%i\n",part_num);
if (current_part == part_num)
return &part;
/* u-boot partition */
if(part_num==0){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00000000;
part.size=256*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* primary OS+firmware partition */
if(part_num==1){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00040000;
part.size=768*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* secondary OS+firmware partition */
if(part_num==2){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00100000;
part.size=8*1024*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* data partition */
if(part_num==3){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00900000;
part.size=7*1024*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
if (current_part == part_num) {
part.usr_priv = &current_part;
part.jffs2_priv = jffs2_priv_saved;
return &part;
}
PRINTK("jffs2_part_info: end of partition table\n");
return 0;
}
#endif /* CONFIG_MTD_INNOKOM_16MB */
#ifdef CONFIG_MTD_INNOKOM_64MB
#ifdef CONFIG_MTD_INNOKOM_16MB
#error Please define only one CONFIG_MTD_INNOKOM_XXMB option.
#endif
struct part_info* jffs2_part_info(int part_num) {
void *jffs2_priv_saved = part.jffs2_priv;
PRINTK2("jffs2_part_info: part_num=%i\n",part_num);
if (current_part == part_num)
return &part;
/* u-boot partition */
if(part_num==0){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00000000;
part.size=256*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* primary OS+firmware partition */
if(part_num==1){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00040000;
part.size=16*1024*1024-128*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* secondary OS+firmware partition */
if(part_num==2){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x01020000;
part.size=16*1024*1024-128*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* data partition */
if(part_num==3){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x02000000;
part.size=32*1024*1024;
/* Mark the struct as ready */
current_part = part_num;
PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
PRINTK("part.size = 0x%08x\n",(unsigned int)part.size);
}
if (current_part == part_num) {
part.usr_priv = &current_part;
part.jffs2_priv = jffs2_priv_saved;
return &part;
}
PRINTK("jffs2_part_info: end of partition table\n");
return 0;
}
#endif /* CONFIG_MTD_INNOKOM_64MB */
#endif /* defined CFG_JFFS_CUSTOM_PART */
/**
* flash_init: - initialize data structures for flash chips
*
......
......@@ -490,59 +490,3 @@ int flash_real_protect(flash_info_t *info, long sector, int prot)
return rc;
}
/*-----------------------------------------------------------------------
* Support for flash file system (JFFS2)
*
* We use custom partition info function because we have to fit the
* file system image between first sector (containing hard reset
* configuration word) and the sector containing U-Boot image. Standard
* partition info function does not allow for last sector specification
* and assumes that the file system occupies flash bank up to and
* including bank's last sector.
*/
#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CFG_JFFS_CUSTOM_PART)
#ifndef CFG_JFFS2_FIRST_SECTOR
#define CFG_JFFS2_FIRST_SECTOR 0
#endif
#ifndef CFG_JFFS2_FIRST_BANK
#define CFG_JFFS2_FIRST_BANK 0
#endif
#ifndef CFG_JFFS2_NUM_BANKS
#define CFG_JFFS2_NUM_BANKS 1
#endif
#define CFG_JFFS2_LAST_BANK (CFG_JFFS2_FIRST_BANK + CFG_JFFS2_NUM_BANKS - 1)
#include <jffs2/jffs2.h>
static struct part_info partition;
struct part_info *jffs2_part_info(int part_num)
{
int i;
if (part_num == 0) {
if (partition.usr_priv == 0) {
partition.offset =
(unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
for (i = CFG_JFFS2_FIRST_BANK; i <= CFG_JFFS2_LAST_BANK; i++)
partition.size += flash_info[i].size;
partition.size -=
flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
flash_info[CFG_JFFS2_FIRST_BANK].start[0];
#ifdef CFG_JFFS2_LAST_SECTOR
i = flash_info[CFG_JFFS2_LAST_BANK].sector_count - 1;
partition.size -=
flash_info[CFG_JFFS2_LAST_BANK].start[i] -
flash_info[CFG_JFFS2_LAST_BANK].start[CFG_JFFS2_LAST_SECTOR];
#endif
partition.usr_priv = (void *)1;
}
return &partition;
}
return 0;
}
#endif /* JFFS2 */
......@@ -25,10 +25,6 @@
#include <common.h>
#if defined CFG_JFFS_CUSTOM_PART
#include <jffs2/jffs2.h>
#endif
#define FLASH_BANK_SIZE MX1FS2_FLASH_BANK_SIZE
#define MAIN_SECT_SIZE MX1FS2_FLASH_SECT_SIZE
......@@ -70,67 +66,6 @@ static int write_word_amd(flash_info_t * info, FPWV * dest, FPW data);
static void flash_sync_real_protect(flash_info_t * info);
#endif
#if defined CFG_JFFS_CUSTOM_PART
/**
* jffs2_part_info - get information about a JFFS2 partition
*
* @part_num: number of the partition you want to get info about
* @return: struct part_info* in case of success, 0 if failure
*/
static struct part_info part;
static int current_part = -1;
struct part_info *
jffs2_part_info(int part_num)
{
void *jffs2_priv_saved = part.jffs2_priv;
printf("jffs2_part_info: part_num=%i\n", part_num);
if (current_part == part_num)
return &part;
/* rootfs */
if (part_num == 0) {
memset(&part, 0, sizeof (part));
part.offset = (char *) MX1FS2_JFFS2_PART0_START;
part.size = MX1FS2_JFFS2_PART0_SIZE;
/* Mark the struct as ready */
current_part = part_num;
printf("part.offset = 0x%08x\n", (unsigned int) part.offset);
printf("part.size = 0x%08x\n", (unsigned int) part.size);
}
/* userfs */
if (part_num == 1) {
memset(&part, 0, sizeof (part));
part.offset = (char *) MX1FS2_JFFS2_PART1_START;
part.size = MX1FS2_JFFS2_PART1_SIZE;
/* Mark the struct as ready */
current_part = part_num;
printf("part.offset = 0x%08x\n", (unsigned int) part.offset);
printf("part.size = 0x%08x\n", (unsigned int) part.size);
}
if (current_part == part_num) {
part.usr_priv = &current_part;
part.jffs2_priv = jffs2_priv_saved;
return &part;
}
printf("jffs2_part_info: end of partition table\n");
return 0;
}
#endif /* CFG_JFFS_CUSTOM_PART */
/*-----------------------------------------------------------------------
* flash_init()
*
......
......@@ -601,70 +601,3 @@ long int initdram(int board_type)
return (size_sdram);
}
#ifdef CFG_JFFS_CUSTOM_PART
static struct part_info part;
#define jffs2_block(i) \
((struct jffs2_unknown_node*)(CFG_JFFS2_BASE + (i) * 65536))
struct part_info* jffs2_part_info(int part_num)
{
DECLARE_GLOBAL_DATA_PTR;
bd_t *bd = gd->bd;
char* s;
int i;
int bootnor = 0; /* assume booting from NAND flash */
if (part_num != 0)
return 0; /* only support one partition */
if (part.usr_priv == (void*)1)
return &part; /* already have part info */
memset(&part, 0, sizeof(part));
if (nand_dev_desc[0].ChipID == NAND_ChipID_UNKNOWN)
bootnor = 1;
else if (bd->bi_flashsize < 0x800000)
bootnor = 0;
else for (i = 0; !bootnor && i < 4; ++i) {
/* boot from NOR if JFFS2 info in any of
* first 4 erase blocks
*/
if (jffs2_block(i)->magic == JFFS2_MAGIC_BITMASK)
bootnor = 1;
}
if (bootnor) {
/* no NAND flash or boot in NOR, use NOR flash */
part.offset = (unsigned char *)CFG_JFFS2_BASE;
part.size = CFG_JFFS2_SIZE;
}
else {
char readcmd[60];
/* boot info in NAND flash, get and use copy in RAM */
/* override info from environment if present */
s = getenv("fsaddr");
part.offset = s ? (void *)simple_strtoul(s, NULL, 16)
: (void *)CFG_JFFS2_RAMBASE;
s = getenv("fssize");
part.size = s ? simple_strtoul(s, NULL, 16)
: CFG_JFFS2_RAMSIZE;
/* read from nand flash */
sprintf(readcmd, "nand read.jffs2 %x 0 %x",
(uint32_t)part.offset, part.size);
run_command(readcmd, 0);
}
part.erasesize = 0; /* unused */
part.usr_priv=(void*)1; /* ready */
return &part;
}
#endif /* ifdef CFG_JFFS_CUSTOM_PART */
......@@ -56,90 +56,10 @@ int dram_init(void)
return 0;
}
#ifndef VOICEBLUE_SMALL_FLASH
#include <jffs2/jffs2.h>
extern flash_info_t flash_info[];
static struct part_info partinfo;
static int current_part = -1;
/* Partition table (Linux MTD see it this way)
*
* 0 - U-Boot
* 1 - env
* 2 - redundant env
* 3 - data1 (jffs2)
* 4 - data2 (jffs2)
*/
static struct {
ulong offset;
ulong size;
} part[5];
static void partition_flash(flash_info_t *info)
{
char mtdparts[128];
int i, n, size, psize;
const ulong plen[3] = { CFG_MONITOR_LEN, CFG_ENV_SIZE, CFG_ENV_SIZE };
size = n = 0;
for (i = 0; i < 4; i++) {
part[i].offset = info->start[n];
psize = i < 3 ? plen[i] : (info->size - size) / 2;
while (part[i].size < psize) {
if (++n > info->sector_count) {
printf("Partitioning error. System halted.\n");
while (1) ;
}
part[i].size += info->start[n] - info->start[n - 1];
}
size += part[i].size;
}
part[4].offset = info->start[n];
part[4].size = info->start[info->sector_count - 1] - info->start[n];
sprintf(mtdparts, "omapflash.0:"
"%dk(U-Boot)ro,%dk(env),%dk(r_env),%dk(data1),-(data2)",
part[0].size >> 10, part[1].size >> 10,
part[2].size >> 10, part[3].size >> 10);
setenv ("mtdparts", mtdparts);
}
struct part_info* jffs2_part_info(int part_num)
{
void *jffs2_priv_saved = partinfo.jffs2_priv;
if (part_num != 3 && part_num != 4)
return NULL;
if (current_part != part_num) {
memset(&partinfo, 0, sizeof(partinfo));
current_part = part_num;
partinfo.offset = (char*) part[part_num].offset;
partinfo.size = part[part_num].size;
partinfo.usr_priv = &current_part;
partinfo.jffs2_priv = jffs2_priv_saved;
}
return &partinfo;
}
#endif
int misc_init_r(void)
{
*((volatile unsigned short *) VOICEBLUE_LED_REG) = 0x55;
#ifndef VOICEBLUE_SMALL_FLASH
if (flash_info[0].flash_id == FLASH_UNKNOWN) {
printf("Unknown flash. System halted.\n");
while (1) ;
}
partition_flash(&flash_info[0]);
#endif
return 0;
}
......
......@@ -27,10 +27,6 @@
#include <common.h>
#include <linux/byteorder/swab.h>
#if defined CFG_JFFS_CUSTOM_PART
#include <jffs2/jffs2.h>
#endif
#define SWAP(x) __swab32(x)
flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
......@@ -40,80 +36,6 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info);
static int write_word (flash_info_t *info, ulong dest, ulong data);
static void flash_get_offsets (ulong base, flash_info_t *info);
#if defined CFG_JFFS_CUSTOM_PART
/*
* jffs2_part_info - get information about a JFFS2 partition
*
* @part_num: number of the partition you want to get info about
* @return: struct part_info* in case of success, 0 if failure
*/
static struct part_info part;
static int current_part = -1;
struct part_info* jffs2_part_info(int part_num) {
void *jffs2_priv_saved = part.jffs2_priv;
printf("jffs2_part_info: part_num=%i\n",part_num);
if (current_part == part_num)
return &part;
/* u-boot partition */
if(part_num==0){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00000000;
part.size=256*1024;
/* Mark the struct as ready */
current_part = part_num;
printf("part.offset = 0x%08x\n",(unsigned int)part.offset);
printf("part.size = 0x%08x\n",(unsigned int)part.size);
}
/* primary OS+firmware partition */
if(part_num==1){
memset(&part, 0, sizeof(part));
part.offset=(char*)0x00040000;
part.size=1024*1024;