Skip to contentSkip to conversation

tools: mksunxiboot: Fix problems on big endian systems

PATCH New Siarhei Siamashka 2 participants 2 messages Feb 8, 2015 – Feb 16, 2015 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: mksunxiboot: Fix problems on big endian systems

Now my PS3 can be also used to build u-boot for sunxi devices.

---
 tools/mksunxiboot.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/mksunxiboot.c +8 -6
index 1f0fbae..0035f6e 100644
@@ -43,19 +43,19 @@ int gen_check_sum(struct boot_file_head *head_p)
 	uint32_t i;
 	uint32_t sum;
 
-	length = head_p->length;
+	length = le32_to_cpu(head_p->length);
 	if ((length & 0x3) != 0)	/* must 4-byte-aligned */
 		return -1;
 	buf = (uint32_t *)head_p;
-	head_p->check_sum = STAMP_VALUE;	/* fill stamp */
+	head_p->check_sum = cpu_to_le32(STAMP_VALUE);	/* fill stamp */
 	loop = length >> 2;
 
 	/* calculate the sum */
 	for (i = 0, sum = 0; i < loop; i++)
-		sum += buf[i];
+		sum += le32_to_cpu(buf[i]);
 
 	/* write back check sum */
-	head_p->check_sum = sum;
+	head_p->check_sum = cpu_to_le32(sum);
 
 	return 0;
 }
@@ -125,10 +125,12 @@ int main(int argc, char *argv[])
 	memcpy(img.header.magic, BOOT0_MAGIC, 8);	/* no '0' termination */
 	img.header.length =
 		ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+	img.header.b_instruction = cpu_to_le32(img.header.b_instruction);
+	img.header.length = cpu_to_le32(img.header.length);
 	gen_check_sum(&img.header);
 
-	count = write(fd_out, &img, img.header.length);
-	if (count != img.header.length) {
+	count = write(fd_out, &img, le32_to_cpu(img.header.length));
+	if (count != le32_to_cpu(img.header.length)) {
 		perror("Writing output");
 		return EXIT_FAILURE;
 	}
Signature · 1 line
2.0.5
#1 lore raw

PATCH 1/1 tools: mksunxiboot: Fix problems on big endian systems

Hi,

Quoted 3 lines · Siarhei Siamashka

Now my PS3 can be also used to build u-boot for sunxi devices.

Thanks, applied to u-boot-sunxi/next and included in the pull-req which I've just send out.

Regards,

Hans

Quoted 48 lines
---
  tools/mksunxiboot.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
tools/mksunxiboot.c +8 -6
index 1f0fbae..0035f6e 100644
@@ -43,19 +43,19 @@ int gen_check_sum(struct boot_file_head *head_p)
  	uint32_t i;
  	uint32_t sum;
 
-	length = head_p->length;
+	length = le32_to_cpu(head_p->length);
  	if ((length & 0x3) != 0)	/* must 4-byte-aligned */
  		return -1;
  	buf = (uint32_t *)head_p;
-	head_p->check_sum = STAMP_VALUE;	/* fill stamp */
+	head_p->check_sum = cpu_to_le32(STAMP_VALUE);	/* fill stamp */
  	loop = length >> 2;
 
  	/* calculate the sum */
  	for (i = 0, sum = 0; i < loop; i++)
-		sum += buf[i];
+		sum += le32_to_cpu(buf[i]);
 
  	/* write back check sum */
-	head_p->check_sum = sum;
+	head_p->check_sum = cpu_to_le32(sum);
 
  	return 0;
  }
@@ -125,10 +125,12 @@ int main(int argc, char *argv[])
  	memcpy(img.header.magic, BOOT0_MAGIC, 8);	/* no '0' termination */
  	img.header.length =
  		ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+	img.header.b_instruction = cpu_to_le32(img.header.b_instruction);
+	img.header.length = cpu_to_le32(img.header.length);
  	gen_check_sum(&img.header);
 
-	count = write(fd_out, &img, img.header.length);
-	if (count != img.header.length) {
+	count = write(fd_out, &img, le32_to_cpu(img.header.length));
+	if (count != le32_to_cpu(img.header.length)) {
  		perror("Writing output");
  		return EXIT_FAILURE;
  	}