Skip to contentSkip to conversation

powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

PATCH Applied Chris Packham 4 participants 6 messages May 26, 2013 – Jun 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

From: Chris Packham <[email protected]>

Instead of assuming that SYS_TEXT_BASE is 0xFFF80000 calculate the initial pbl command offset by subtracting the image size from the top of the 24-bit address range. Also increase the size of the memory buffer to accommodate a larger output image.

---
Hi,

I was trying to get a SPIFLASH image working for my board based on a P2040 and found that the pblimage tool assumes that u-boot.bin is always 512K. In my case it's actually larger. This patch is my attempt to allow for an arbitrary u-boot.bin image size.

Thanks,
Chris

 tools/pblimage.c |   33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)
tools/pblimage.c +26 -7
index 508a747..3582ada 100644
@@ -26,18 +26,14 @@
 #include "pblimage.h"
 
 /*
- * The PBL can load up to 64 bytes at a time, so we split the U-Boot
- * image into 64 byte chunks. PBL needs a command for each piece, of
- * the form "81xxxxxx", where "xxxxxx" is the offset. SYS_TEXT_BASE
- * is 0xFFF80000 for PBL boot, and PBL only cares about low 24-bit,
- * so it starts from 0x81F80000.
+ * Initialize to an invalid value.
  */
-static uint32_t next_pbl_cmd = 0x81F80000;
+static uint32_t next_pbl_cmd = 0x82000000;
 /*
  * need to store all bytes in memory for calculating crc32, then write the
  * bytes to image file for PBL boot.
  */
-static unsigned char mem_buf[600000];
+static unsigned char mem_buf[1000000];
 static unsigned char *pmem_buf = mem_buf;
 static int pbl_size;
 static char *fname = "Unknown";
@@ -52,6 +48,28 @@ static union
 
 #define ENDIANNESS ((char)endian_test.l)
 
+/*
+ * The PBL can load up to 64 bytes at a time, so we split the U-Boot
+ * image into 64 byte chunks. PBL needs a command for each piece, of
+ * the form "81xxxxxx", where "xxxxxx" is the offset. Calculate the
+ * start offset by subtracting the size of the u-boot image from the
+ * top of the allowable 24-bit range.
+ */
+static void init_next_pbl_cmd(FILE *fp_uboot)
+{
+	struct stat st;
+	int fd = fileno(fp_uboot);
+	size_t size;
+
+	if (fstat(fd, &st) == -1) {
+		printf("Error: Could not determine u-boot image size. %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
+	next_pbl_cmd = 0x82000000 - st.st_size;
+}
+
 static void generate_pbl_cmd(void)
 {
 	uint32_t val = next_pbl_cmd;
@@ -80,6 +98,7 @@ static void pbl_fget(size_t size, FILE *stream)
 /* load split u-boot with PBI command 81xxxxxx. */
 static void load_uboot(FILE *fp_uboot)
 {
+	init_next_pbl_cmd(fp_uboot);
 	while (next_pbl_cmd < 0x82000000) {
 		generate_pbl_cmd();
 		pbl_fget(64, fp_uboot);
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

Hi, Chris,

For the init value of "next_pbl_cmd", there was a patch at below link can be used:
http://lists.denx.de/pipermail/u-boot/2013-March/150260.html

this patch with your modification below should can meet your requirement:

tools/pblimage.c line 36

Quoted 2 lines
tools/pblimage.c +1 -1
-static unsigned char mem_buf[600000];
+static unsigned char mem_buf[1000000];

Best Regards,
Shaohui Xie

Quoted 104 lines

-----Original Message-----
From: Chris Packham [mailto:judge.packham at gmail.com]
Sent: Monday, May 27, 2013 6:52 AM
To: Fleming Andy-AFLEMING
Cc: Xie Shaohui-B21989; u-boot at lists.denx.de; Chris Packham
Subject: [PATCH] powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

From: Chris Packham <[email protected]>

Instead of assuming that SYS_TEXT_BASE is 0xFFF80000 calculate the initial pbl command offset by subtracting the image size from the top of the 24-bit address range. Also increase the size of the memory buffer to accommodate a larger output image.

---
Hi,

I was trying to get a SPIFLASH image working for my board based on a P2040 and found that the pblimage tool assumes that u-boot.bin is always 512K. In my case it's actually larger. This patch is my attempt to allow for an arbitrary u-boot.bin image size.

Thanks,
Chris

 tools/pblimage.c |   33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)
tools/pblimage.c index 508a747..3582ada renamed from tools/pblimage.c +0 -0

100644

tools/pblimage.c +2 -6
@@ -26,18 +26,14 @@
 #include "pblimage.h"
 
 /*
- * The PBL can load up to 64 bytes at a time, so we split the U-Boot
- * image into 64 byte chunks. PBL needs a command for each piece, of
- * the form "81xxxxxx", where "xxxxxx" is the offset. SYS_TEXT_BASE
- * is 0xFFF80000 for PBL boot, and PBL only cares about low 24-bit,
- * so it starts from 0x81F80000.
+ * Initialize to an invalid value.
  */
-static uint32_t next_pbl_cmd = 0x81F80000;
+static uint32_t next_pbl_cmd = 0x82000000;
 /*
  * need to store all bytes in memory for calculating crc32, then write

the
* bytes to image file for PBL boot.
*/

tools/pblimage.c +1 -1
-static unsigned char mem_buf[600000];
+static unsigned char mem_buf[1000000];
 static unsigned char *pmem_buf = mem_buf;  static int pbl_size;  static

char *fname = "Unknown"; @@ -52,6 +48,28 @@ static union

#define ENDIANNESS ((char)endian_test.l)

tools/pblimage.c +21 -1
+/*
+ * The PBL can load up to 64 bytes at a time, so we split the U-Boot
+ * image into 64 byte chunks. PBL needs a command for each piece, of
+ * the form "81xxxxxx", where "xxxxxx" is the offset. Calculate the
+ * start offset by subtracting the size of the u-boot image from the
+ * top of the allowable 24-bit range.
+ */
+static void init_next_pbl_cmd(FILE *fp_uboot) {
+	struct stat st;
+	int fd = fileno(fp_uboot);
+	size_t size;
+
+	if (fstat(fd, &st) == -1) {
+		printf("Error: Could not determine u-boot image size. %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
+	next_pbl_cmd = 0x82000000 - st.st_size; }
+
 static void generate_pbl_cmd(void)
 {
 	uint32_t val = next_pbl_cmd;
@@ -80,6 +98,7 @@ static void pbl_fget(size_t size, FILE *stream)
 /* load split u-boot with PBI command 81xxxxxx. */  static void
 load_uboot(FILE *fp_uboot)  {
+	init_next_pbl_cmd(fp_uboot);
 	while (next_pbl_cmd < 0x82000000) {
 		generate_pbl_cmd();
 		pbl_fget(64, fp_uboot);
--

1.7.9.5

NOTICE: This message contains privileged and confidential information intended only for the use of the addressee named above. If you are not the intended recipient of this message you are hereby notified that you must not disseminate, copy or take any action in reliance on it. If you have received this message in error please notify Allied Telesis Labs Ltd immediately.
Any views expressed in this message are those of the individual sender, except where the sender has the authority to issue and specifically states them to be the views of Allied Telesis Labs.

#2 lore raw

PATCH 1/1 powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

Quoted 5 lines · On 27/05/13 18:18, Xie Shaohui-B21989 wrote:

Hi, Chris,

For the init value of "next_pbl_cmd", there was a patch at below link can be used:
http://lists.denx.de/pipermail/u-boot/2013-March/150260.html

Thanks for the pointer. I did check the main u-boot.git tree but didn't search the list.

I don't know if it's a concern for u-boot but the patch linked above assumes something that isn't quite true for my usage. My board uses the SPI booting option for factory boot-strap. The "normal" method is booting from NOR. When I build a NOR image I prepend a standalone application image to the bootloader for convenience of only having to program one image to NOR. In my case CONFIG_SYS_TEXT_BASE is not the base address of the binary I'm trying to wrap in a pbl image.

Another advantage of my version is that you don't necessarily have to be using mkimage/pblimage on the current u-boot configuration. It could be an externally built image and we're just using mkimage/pblimage to wrap it into something that we can program into SPI.

Quoted 112 lines

this patch with your modification below should can meet your requirement:

tools/pblimage.c line 36

Quoted 2 lines
tools/pblimage.c +1 -1
-static unsigned char mem_buf[600000];
+static unsigned char mem_buf[1000000];

Best Regards,
Shaohui Xie

Quoted 104 lines

-----Original Message-----
From: Chris Packham [mailto:judge.packham at gmail.com]
Sent: Monday, May 27, 2013 6:52 AM
To: Fleming Andy-AFLEMING
Cc: Xie Shaohui-B21989; u-boot at lists.denx.de; Chris Packham
Subject: [PATCH] powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

From: Chris Packham <[email protected]>

Instead of assuming that SYS_TEXT_BASE is 0xFFF80000 calculate the initial pbl command offset by subtracting the image size from the top of the 24-bit address range. Also increase the size of the memory buffer to accommodate a larger output image.

---
Hi,

I was trying to get a SPIFLASH image working for my board based on a P2040 and found that the pblimage tool assumes that u-boot.bin is always 512K. In my case it's actually larger. This patch is my attempt to allow for an arbitrary u-boot.bin image size.

Thanks,
Chris

 tools/pblimage.c |   33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)
tools/pblimage.c index 508a747..3582ada renamed from tools/pblimage.c +0 -0

100644

tools/pblimage.c +2 -6
@@ -26,18 +26,14 @@
 #include "pblimage.h"
 
 /*
- * The PBL can load up to 64 bytes at a time, so we split the U-Boot
- * image into 64 byte chunks. PBL needs a command for each piece, of
- * the form "81xxxxxx", where "xxxxxx" is the offset. SYS_TEXT_BASE
- * is 0xFFF80000 for PBL boot, and PBL only cares about low 24-bit,
- * so it starts from 0x81F80000.
+ * Initialize to an invalid value.
  */
-static uint32_t next_pbl_cmd = 0x81F80000;
+static uint32_t next_pbl_cmd = 0x82000000;
 /*
  * need to store all bytes in memory for calculating crc32, then write

the
* bytes to image file for PBL boot.
*/

tools/pblimage.c +1 -1
-static unsigned char mem_buf[600000];
+static unsigned char mem_buf[1000000];
 static unsigned char *pmem_buf = mem_buf;  static int pbl_size;  static

char *fname = "Unknown"; @@ -52,6 +48,28 @@ static union

#define ENDIANNESS ((char)endian_test.l)

tools/pblimage.c +21 -1
+/*
+ * The PBL can load up to 64 bytes at a time, so we split the U-Boot
+ * image into 64 byte chunks. PBL needs a command for each piece, of
+ * the form "81xxxxxx", where "xxxxxx" is the offset. Calculate the
+ * start offset by subtracting the size of the u-boot image from the
+ * top of the allowable 24-bit range.
+ */
+static void init_next_pbl_cmd(FILE *fp_uboot) {
+	struct stat st;
+	int fd = fileno(fp_uboot);
+	size_t size;
+
+	if (fstat(fd, &st) == -1) {
+		printf("Error: Could not determine u-boot image size. %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
+	next_pbl_cmd = 0x82000000 - st.st_size; }
+
 static void generate_pbl_cmd(void)
 {
 	uint32_t val = next_pbl_cmd;
@@ -80,6 +98,7 @@ static void pbl_fget(size_t size, FILE *stream)
 /* load split u-boot with PBI command 81xxxxxx. */  static void
 load_uboot(FILE *fp_uboot)  {
+	init_next_pbl_cmd(fp_uboot);
 	while (next_pbl_cmd < 0x82000000) {
 		generate_pbl_cmd();
 		pbl_fget(64, fp_uboot);
--

1.7.9.5

NOTICE: This message contains privileged and confidential information intended only for the use of the addressee named above. If you are not the intended recipient of this message you are hereby notified that you must not disseminate, copy or take any action in reliance on it. If you have received this message in error please notify Allied Telesis Labs Ltd immediately.
Any views expressed in this message are those of the individual sender, except where the sender has the authority to issue and specifically states them to be the views of Allied Telesis Labs.

#3 lore raw

PATCH 1/1 powerpc/CoreNet: Allow pbl images to take u-boot images != 512K

Quoted 19 lines · On 27/05/13 18:18, Xie Shaohui-B21989 wrote:
Quoted 3 lines

Hi, Chris,

For the init value of "next_pbl_cmd", there was a patch at below link

can be used:

Quoted 2 lines

http://lists.denx.de/pipermail/u-boot/2013-March/150260.html

Thanks for the pointer. I did check the main u-boot.git tree but didn't search the list.

I don't know if it's a concern for u-boot but the patch linked above assumes something that isn't quite true for my usage. My board uses the SPI booting option for factory boot-strap. The "normal" method is booting from NOR. When I build a NOR image I prepend a standalone application image to the bootloader for convenience of only having to program one image to NOR. In my case CONFIG_SYS_TEXT_BASE is not the base address of the binary I'm trying to wrap in a pbl image.

Quoted 5 lines

Another advantage of my version is that you don't necessarily have to be using mkimage/pblimage on the current u-boot configuration. It could be an externally built image and we're just using mkimage/pblimage to wrap it into something that we can program into SPI.

[S.H] OK. I see what is your requirement.
ACK.

Best Regards,
Shaohui Xie

Applied
#4 lore raw
In reply to Chris Packham
Quoted 8 lines · Chris Packham

From: Chris Packham <[email protected]>

Instead of assuming that SYS_TEXT_BASE is 0xFFF80000 calculate the initial pbl command offset by subtracting the image size from the top of the 24-bit address range. Also increase the size of the memory buffer to accommodate a larger output image.

I've applied this (thanks), but I'll note it had a warning about unused variable "size". Because it was unused. Please build-test any patches, and ensure they are free of warnings.

tools/pblimage.c static union · line 62

Quoted 11 lines

+ * The PBL can load up to 64 bytes at a time, so we split the U-Boot
+ * image into 64 byte chunks. PBL needs a command for each piece, of
+ * the form "81xxxxxx", where "xxxxxx" is the offset. Calculate the
+ * start offset by subtracting the size of the u-boot image from the
+ * top of the allowable 24-bit range.
+ */

tools/pblimage.c +5 -0
+static void init_next_pbl_cmd(FILE *fp_uboot)
+{
+	struct stat st;
+	int fd = fileno(fp_uboot);
+	size_t size;

This was the variable, for future reference.

tools/pblimage.c static union · line 71

Quoted 9 lines
tools/pblimage.c +9 -0
+
+	if (fstat(fd, &st) == -1) {
+		printf("Error: Could not determine u-boot image size. %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
+	next_pbl_cmd = 0x82000000 - st.st_size;
+}

Andy

#5 lore raw

Hi Andy,

Quoted 14 lines
Quoted 1 line
Quoted 1 line · Andy Fleming
Quoted 8 lines · Chris Packham

From: Chris Packham <[email protected]>

Instead of assuming that SYS_TEXT_BASE is 0xFFF80000 calculate the initial pbl command offset by subtracting the image size from the top of the 24-bit address range. Also increase the size of the memory buffer to accommodate a larger output image.

I've applied this (thanks), but I'll note it had a warning about unused variable "size". Because it was unused. Please build-test any patches, and ensure they are free of warnings.

Quoted 13 lines

tools/pblimage.c static union · line 62

Quoted 11 lines

+ * The PBL can load up to 64 bytes at a time, so we split the U-Boot
+ * image into 64 byte chunks. PBL needs a command for each piece, of
+ * the form "81xxxxxx", where "xxxxxx" is the offset. Calculate the
+ * start offset by subtracting the size of the u-boot image from the
+ * top of the allowable 24-bit range.
+ */

tools/pblimage.c +5 -0
+static void init_next_pbl_cmd(FILE *fp_uboot)
+{
+	struct stat st;
+	int fd = fileno(fp_uboot);
+	size_t size;

This was the variable, for future reference.

OK I'll keep an eye out in the future. I usually run with CFLAGS+='-Wall -Werror' so I'm not sure how I missed this.

Quoted 11 lines

tools/pblimage.c static union · line 71

Quoted 9 lines
tools/pblimage.c +9 -0
+
+	if (fstat(fd, &st) == -1) {
+		printf("Error: Could not determine u-boot image size. %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
+	next_pbl_cmd = 0x82000000 - st.st_size;
+}

Andy