[U-Boot-Users] "8.partition":(1 of 1) [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6

Author: Ulf Samuelsson ulf@atmel.com Date: 2007-03-27
Subject: "8.partition":(1 of 1) [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6
CHANGELOG: [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6 Make partition boundaries align with start of dataflash pages Add partition name to environment automatically Add printing info on protection status Enable by setting CONFIG_NEW_PARTITION in <board>.h
Patch generated from files: drivers_dataflash.c.patch include_dataflash.h.patch include_flash.h.patch
Signed-off-by: Ulf Samuelsson --------------------------------------------------------------------------------------------------------------------------------- diff -urN u-boot-1.2.0/drivers/dataflash.c u-boot-1.2.0-atmel/drivers/dataflash.c --- u-boot-1.2.0/drivers/dataflash.c 2007-01-07 00:13:11.000000000 +0100 +++ u-boot-1.2.0-atmel/drivers/dataflash.c 2007-03-27 10:30:30.000000000 +0200 @@ -26,18 +26,67 @@ AT91S_DATAFLASH_INFO dataflash_info[CFG_MAX_DATAFLASH_BANKS]; static AT91S_DataFlash DataFlashInst;
+#ifdef CONFIG_AT91SAM9260EK +int cs[][CFG_MAX_DATAFLASH_BANKS] = { + {CFG_DATAFLASH_LOGIC_ADDR_CS0, 0}, /* Logical adress, CS */ + {CFG_DATAFLASH_LOGIC_ADDR_CS1, 1} +}; +#elif defined(CONFIG_AT91SAM9263EK) +int cs[][CFG_MAX_DATAFLASH_BANKS] = { + {CFG_DATAFLASH_LOGIC_ADDR_CS0, 0} /* Logical adress, CS */ +}; +#else int cs[][CFG_MAX_DATAFLASH_BANKS] = { {CFG_DATAFLASH_LOGIC_ADDR_CS0, 0}, /* Logical adress, CS */ {CFG_DATAFLASH_LOGIC_ADDR_CS3, 3} }; +#endif
/*define the area offsets*/ +#if defined(CONFIG_AT91SAM9261EK) || defined(CONFIG_AT91SAM9260EK) || defined(CONFIG_AT91SAM9263EK) +#if defined(CONFIG_NEW_PARTITION) +dataflash_protect_t area_list[NB_DATAFLASH_AREA] = { + {0x00000000, 0x00003FFF, FLAG_PROTECT_SET, 0, "Bootstrap"}, /* ROM code */ + {0x00004200, 0x000083FF, FLAG_PROTECT_CLEAR, 0, "Environment"}, /* u-boot environment */ + {0x00008400, 0x0003DDFF, FLAG_PROTECT_SET, 0, "U-Boot"}, /* u-boot code */ + {0x0003DE00, 0x00041FFF, FLAG_PROTECT_CLEAR, FLAG_SETENV, "MON"}, /* Room for alternative boot monitor */ + {0x00042000, 0x0018BFFF, FLAG_PROTECT_CLEAR, FLAG_SETENV, "OS"}, /* data area size to tune */ + {0x0018C000, 0xFFFFFFFF, FLAG_PROTECT_CLEAR, FLAG_SETENV, "FS"}, /* data area size to tune */ +}; +#else +dataflash_protect_t area_list[NB_DATAFLASH_AREA] = { + {0, 0x3fff, FLAG_PROTECT_SET}, /* ROM code */ + {0x4000, 0x7fff, FLAG_PROTECT_CLEAR}, /* u-boot environment */ + {0x8000, 0x37fff, FLAG_PROTECT_SET}, /* u-boot code */ + {0x38000, 0x1fffff, FLAG_PROTECT_CLEAR}, /* data area size to tune */ +}; +#endif +#elif defined(CONFIG_NEW_PARTITION) +/*define the area offsets*/ +/* Invalid partitions should be defined with start > end */ +dataflash_protect_t area_list[NB_DATAFLASH_AREA*CFG_MAX_DATAFLASH_BANKS] = { + {0x00000000, 0x000083ff, FLAG_PROTECT_SET, 0, "Bootstrap"}, /* ROM code */ + {0x00008400, 0x00020fff, FLAG_PROTECT_SET, 0, "U-Boot"}, /* u-boot code */ + {0x00021000, 0x000293ff, FLAG_PROTECT_CLEAR, 0, "Environment"}, /* u-boot environment 8Kb */ + {0x00029400, 0x00041fff, FLAG_PROTECT_INVALID, 0, "<Unused>"}, /* Rest of Sector 1 */ + {0x00042000, 0x0018Bfff, FLAG_PROTECT_CLEAR, FLAG_SETENV, "OS"}, /* data area size to tune */ + {0x0018C000, 0xffffffff, FLAG_PROTECT_CLEAR, FLAG_SETENV, "FS"}, /* data area size to tune */ + + {0x00000000, 0xffffffff, FLAG_PROTECT_CLEAR, FLAG_SETENV, "Data"}, /* data area */ + {0xffffffff, 0x00000000, FLAG_PROTECT_INVALID, 0, "<Invalid>"}, /* Invalid */ + {0xffffffff, 0x00000000, FLAG_PROTECT_INVALID, 0, "<Invalid>"}, /* Invalid */ + {0xffffffff, 0x00000000, FLAG_PROTECT_INVALID, 0, "<Invalid>"}, /* Invalid */ + {0xffffffff, 0x00000000, FLAG_PROTECT_INVALID, 0, "<Invalid>"}, /* Invalid */ + {0xffffffff, 0x00000000, FLAG_PROTECT_INVALID, 0, "<Invalid>"}, /* Invalid */ +}; +#else dataflash_protect_t area_list[NB_DATAFLASH_AREA] = { {0, 0x7fff, FLAG_PROTECT_SET}, /* ROM code */ {0x8000, 0x1ffff, FLAG_PROTECT_SET}, /* u-boot code */ {0x20000, 0x27fff, FLAG_PROTECT_CLEAR}, /* u-boot environment */ {0x28000, 0x1fffff, FLAG_PROTECT_CLEAR}, /* data area size to tune */ }; +#endif
extern void AT91F_SpiInit (void); extern int AT91F_DataflashProbe (int i, AT91PS_DataflashDesc pDesc); @@ -53,10 +102,15 @@ { int i, j; int dfcode; + int part = 0; + int last_part; + int found[CFG_MAX_DATAFLASH_BANKS]; + unsigned char protected;
AT91F_SpiInit ();
for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) { + found[i] = 0; dataflash_info[i].Desc.state = IDLE; dataflash_info[i].id = 0; dataflash_info[i].Device.pages_number = 0; @@ -72,6 +126,7 @@ dataflash_info[i].Desc.DataFlash_state = IDLE; dataflash_info[i].logical_address = cs[i][0]; dataflash_info[i].id = dfcode; + found[i] += dfcode;; break;
case AT45DB321: @@ -83,6 +138,7 @@ dataflash_info[i].Desc.DataFlash_state = IDLE; dataflash_info[i].logical_address = cs[i][0]; dataflash_info[i].id = dfcode; + found[i] += dfcode;; break;
case AT45DB642: @@ -94,6 +150,7 @@ dataflash_info[i].Desc.DataFlash_state = IDLE; dataflash_info[i].logical_address = cs[i][0]; dataflash_info[i].id = dfcode; + found[i] += dfcode;; break; case AT45DB128: dataflash_info[i].Device.pages_number = 16384; @@ -104,26 +161,75 @@ dataflash_info[i].Desc.DataFlash_state = IDLE; dataflash_info[i].logical_address = cs[i][0]; dataflash_info[i].id = dfcode; + found[i] += dfcode;; break;
default: + dfcode = 0; break; } /* set the last area end to the dataflash size*/ area_list[NB_DATAFLASH_AREA -1].end = (dataflash_info[i].Device.pages_number * dataflash_info[i].Device.pages_size)-1; - + last_part=0; /* set the area addresses */ for(j = 0; j<NB_DATAFLASH_AREA; j++) { - dataflash_info[i].Device.area_list[j].start = area_list[j].start + dataflash_info[i].logical_address; - dataflash_info[i].Device.area_list[j].end = area_list[j].end + dataflash_info[i].logical_address; - dataflash_info[i].Device.area_list[j].protected = area_list[j].protected; + /* dataflash_info[i].Device.area_list[j].start = area_list[j].start + dataflash_info[i].logical_address;*/ + /* dataflash_info[i].Device.area_list[j].end = area_list[j].end + dataflash_info[i].logical_address;*/ + /* dataflash_info[i].Device.area_list[j].protected = area_list[j].protected;*/ + if(found[i]!=0) { + /* printf("Start=%X, ",area_list[part].start + dataflash_info[i].logical_address);*/ + dataflash_info[i].Device.area_list[j].start = area_list[part].start + dataflash_info[i].logical_address; + if(area_list[part].end == 0xffffffff) { + /* printf("End (computed)=%X, ",dataflash_info[i].end_address + dataflash_info[i].logical_address);*/ + dataflash_info[i].Device.area_list[j].end = dataflash_info[i].end_address + dataflash_info [i].logical_address; + last_part = 1; + } else { + /* printf("End=%X, ",area_list[part].end + dataflash_info[i].logical_address);*/ + dataflash_info[i].Device.area_list[j].end = area_list[part].end + dataflash_info[i].logical_address; + } + protected = area_list[part].protected; + /* Set the environment according to the label...*/ + if(protected == FLAG_PROTECT_INVALID) { + /* printf("Invalid\n");*/ + dataflash_info[i].Device.area_list[j].protected = FLAG_PROTECT_INVALID; + } else { + /* printf("%s\n", (area_list[part].protected==FLAG_PROTECT_SET)?"(RO)":""); */ + dataflash_info[i].Device.area_list[j].protected = protected; + } + /*printf("To: %s, From: %s\n",dataflash_info[i].Device.area_list[j].label,area_list[part].label);*/ + strcpy(dataflash_info[i].Device.area_list[j].label,area_list[part].label); + /*printf("To: %s, From: %s\n",dataflash_info[i].Device.area_list[j].label,area_list[part].label);*/ + } + part++; } } - return (1); + return found[0]; }
+#ifdef CONFIG_NEW_DF_PARTITION +int AT91F_DataflashSetEnv (void) +{ + int i, j; + int part; + unsigned char env; + unsigned char s[32]; /* Will fit a long int in hex */ + unsigned long start; + for (i = 0, part= 0; i < CFG_MAX_DATAFLASH_BANKS; i++) { + for(j = 0; j<NB_DATAFLASH_AREA; j++) { + env = area_list[part].setenv; + /* Set the environment according to the label...*/ + if((env & FLAG_SETENV) == FLAG_SETENV) { + start = dataflash_info[i].Device.area_list[j].start; + sprintf(s,"%X",start); + setenv(area_list[part].label,s); + } + part++; + } + } +} +#endif
void dataflash_print_info (void) { @@ -159,11 +265,26 @@ dataflash_info[i].Device.pages_size, (unsigned int) dataflash_info[i].logical_address); for (j=0; j< NB_DATAFLASH_AREA; j++) { - printf ("Area %i:\t%08lX to %08lX %s\n", j, - dataflash_info[i].Device.area_list[j].start, - dataflash_info[i].Device.area_list[j].end, - (dataflash_info[i].Device.area_list[j].protected == - FLAG_PROTECT_SET) ? "(RO)" : ""); + switch(dataflash_info[i].Device.area_list[j].protected) { + case FLAG_PROTECT_SET: + case FLAG_PROTECT_CLEAR: + printf ("Area %i:\t%08lX to %08lX %s", j, + dataflash_info[i].Device.area_list[j].start, + dataflash_info[i].Device.area_list[j].end, + (dataflash_info[i].Device.area_list[j].protected==FLAG_PROTECT_SET) ? "(RO)" : " "); +#ifdef CONFIG_NEW_DF_PARTITION + printf(" %s\n", dataflash_info[i].Device.area_list[j].label); +#else + printf("\n"); +#endif + break; +#ifdef CONFIG_NEW_DF_PARTITION + case FLAG_PROTECT_INVALID: + break; +#endif + } + + } } } @@ -204,8 +325,9 @@ int i;
for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) { - if ((((int) addr) & 0xFF000000) == - dataflash_info[i].logical_address) { + if ( dataflash_info[i].id + && ((((int) addr) & 0xFF000000) == + dataflash_info[i].logical_address)) { addr_valid = 1; break; } @@ -244,7 +366,7 @@ if (area == NB_DATAFLASH_AREA) return -1; /*test protection value*/ if (pdataFlash->pDevice->area_list[area].protected == FLAG_PROTECT_SET) return 0; - + if (pdataFlash->pDevice->area_list[area].protected == FLAG_PROTECT_INVALID) return 0; return 1; } /*-----------------------------------------------------------------------------*/ @@ -278,9 +400,13 @@
/*set protection value*/ for(j = area1; j < area2+1 ; j++) - if (flag == 0) dataflash_info[i].Device.area_list[j].protected = FLAG_PROTECT_CLEAR; - else dataflash_info[i].Device.area_list[j].protected = FLAG_PROTECT_SET; - + if(dataflash_info[i].Device.area_list[j].protected != FLAG_PROTECT_INVALID) { + if (flag == 0) { + dataflash_info[i].Device.area_list[j].protected = FLAG_PROTECT_CLEAR; + } else { + dataflash_info[i].Device.area_list[j].protected = FLAG_PROTECT_SET; + } + } return (area2-area1+1); }
@@ -342,7 +468,7 @@ printf ("Timeout writing to DataFlash\n"); break; case ERR_PROTECTED: - printf ("Can't write to protected DataFlash sectors\n"); + printf ("Can't write to protected/invalid DataFlash sectors\n"); break; case ERR_INVAL: printf ("Outside available DataFlash\n"); diff -urN u-boot-1.2.0/include/dataflash.h u-boot-1.2.0-atmel/include/dataflash.h --- u-boot-1.2.0/include/dataflash.h 2007-01-07 00:13:11.000000000 +0100 +++ u-boot-1.2.0-atmel/include/dataflash.h 2007-03-24 20:07:33.000000000 +0100 @@ -38,13 +38,47 @@ #include "config.h"
/*number of protected area*/ +#ifdef CONFIG_NEW_PARTITION +#define NB_DATAFLASH_AREA 6 +#else #define NB_DATAFLASH_AREA 4 +#endif + +#ifdef CFG_NO_FLASH + +/*----------------------------------------------------------------------- + * return codes from flash_write(): + */ +#define ERR_OK 0 +#define ERR_TIMOUT 1 +#define ERR_NOT_ERASED 2 +#define ERR_PROTECTED 4 +#define ERR_INVAL 8 +#define ERR_ALIGN 16 +#define ERR_UNKNOWN_FLASH_VENDOR 32 +#define ERR_UNKNOWN_FLASH_TYPE 64 +#define ERR_PROG_ERROR 128 + +/*----------------------------------------------------------------------- + * Protection Flags for flash_protect(): + */ +#define FLAG_PROTECT_SET 0x01 +#define FLAG_PROTECT_CLEAR 0x02 +#define FLAG_PROTECT_INVALID 0x03 + +/*----------------------------------------------------------------------- + * Set Environment according to label: + */ +#define FLAG_SETENV 0x80 +#endif /* CFG_NO_FLASH */
/*define the area structure*/ typedef struct { unsigned long start; unsigned long end; unsigned char protected; + unsigned char setenv; + unsigned char label[20]; } dataflash_protect_t;
typedef unsigned int AT91S_DataFlashStatus; @@ -96,6 +130,7 @@ AT91S_DataflashDesc Desc; AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */ unsigned long logical_address; + unsigned long end_address; unsigned int id; /* device id */ } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
@@ -106,7 +141,7 @@ #define AT45DB321 0x34 #define AT45DB642 0x3c #define AT45DB128 0x10 - +#define PAGES_PER_BLOCK 8 #define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */
/* DataFlash return value */ @@ -170,9 +205,12 @@ extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr); extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr); extern int addr_dataflash (unsigned long addr); +extern int addr2ram(ulong addr); extern int read_dataflash (unsigned long addr, unsigned long size, char *result); extern int write_dataflash (unsigned long addr, unsigned long dest, unsigned long size); extern void dataflash_print_info (void); extern void dataflash_perror (int err); - +#ifdef CONFIG_NEW_DF_PARTITION +extern int AT91F_DataflashSetEnv (void); +#endif #endif diff -urN u-boot-1.2.0/include/flash.h u-boot-1.2.0-atmel/include/flash.h --- u-boot-1.2.0/include/flash.h 2007-01-07 00:13:11.000000000 +0100 +++ u-boot-1.2.0-atmel/include/flash.h 2007-03-24 20:07:33.000000000 +0100 @@ -119,6 +119,12 @@ */ #define FLAG_PROTECT_SET 0x01 #define FLAG_PROTECT_CLEAR 0x02 +#define FLAG_PROTECT_INVALID 0x03 + +/*----------------------------------------------------------------------- + * Set Environment according to label: + */ +#define FLAG_SETENV 0x80
/*----------------------------------------------------------------------- * Device IDs

On Tue, Mar 27, 2007 at 06:17:59PM +0200, Ulf Samuelsson wrote:
CHANGELOG: [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6 Make partition boundaries align with start of dataflash pages Add partition name to environment automatically Add printing info on protection status Enable by setting CONFIG_NEW_PARTITION in <board>.h
I do not like this one... drivers/dataflash.c has too much knowledge of various board types, which will soon lead to #ifdef mess. Moreover it is imposible to use cmdline partitions without touching this file again.
Best regards, ladis

On Tue, Mar 27, 2007 at 06:17:59PM +0200, Ulf Samuelsson wrote:
CHANGELOG: [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6 Make partition boundaries align with start of dataflash pages Add partition name to environment automatically Add printing info on protection status Enable by setting CONFIG_NEW_PARTITION in <board>.h
I do not like this one... drivers/dataflash.c has too much knowledge of various board types, which will soon lead to #ifdef mess. Moreover it is imposible to use cmdline partitions without touching this file again.
Best regards, ladis
Please note that these partitions are NOT used by the kernel. It defines partitions for U-boot use only. The kernel will only see the rootsfs partition.
U-Boot uses the partition info to determine where to store the kernel and where to store the rootfs.
There is a natural step of 256 pages in the dataflashes, so you should always allocate 256 pages for Initial boot/U-boot/Environment.
Then you could use a configuration parameter where you define the size of the kernel, and then the rootfs is in the remainder. I am converging on this solution for the pathces on the ftp site.
If you have more than one dataflash, each extra dataflash has a single partition for u-boot purposes.
Best Regards Ulf Samuelsson

On Tue, Mar 27, 2007 at 06:17:59PM +0200, Ulf Samuelsson wrote:
CHANGELOG: [PATCH][ARM] Change dataflash partition boundaries to be compatible with Linux 2.6 Make partition boundaries align with start of dataflash pages Add partition name to environment automatically Add printing info on protection status Enable by setting CONFIG_NEW_PARTITION in <board>.h
I do not like this one... drivers/dataflash.c has too much knowledge of various board types, which will soon lead to #ifdef mess. Moreover it is imposible to use cmdline partitions without touching this file again.
Best regards, ladis
Please note that these partitions are NOT used by the kernel. It defines partitions for U-boot use only. The kernel will only see the rootsfs partition.
U-Boot uses the partition info to determine where to store the kernel and where to store the rootfs.
There is a natural step of 256 pages in the dataflashes, so you should always allocate 256 pages for Initial boot/U-boot/Environment.
Then you could use a configuration parameter where you define the size of the kernel, and then the rootfs is in the remainder. I am converging on this solution for the pathces on the ftp site.
If you have more than one dataflash, each extra dataflash has a single partition for u-boot purposes.
Best Regards Ulf Samuelsson
participants (2)
-
Ladislav Michl
-
Ulf Samuelsson