Skip to contentSkip to conversation

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

U-Boot-Users Ulf Samuelsson 2 participants 4 messages Mar 27, 2007 – May 23, 2007

lore
Share & tools
lore
#0 lore raw

Author: Ulf Samuelsson <[email protected]>
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
---------------------------------------------------------------------------------------------------------------------------------

drivers/dataflash.c +143 -17
diff -urN u-boot-1.2.0/drivers/dataflash.c u-boot-1.2.0-atmel/drivers/dataflash.c
@@ -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");
include/dataflash.h +40 -2

75 lines not on this page · raw message

include/flash.h +6 -0
diff -urN u-boot-1.2.0/include/flash.h u-boot-1.2.0-atmel/include/flash.h
@@ -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
Signature · 9 lines
Best Regards,
Ulf Samuelsson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ulf.vcf
Type: text/x-vcard
Size: 301 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20070327/696b743f/attachment.vcf 
#1 lore raw
Quoted 6 lines · Ulf Samuelsson

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

#2 lore raw

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

Quoted 8 lines · Ulf Samuelsson
Quoted 6 lines

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

Quoted 6 lines

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

#3 lore raw

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

In reply to Ladislav Michl
Quoted 8 lines · Ulf Samuelsson
Quoted 6 lines

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

Quoted 6 lines

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