Commit c924e2a8036f43f2f4a8e829ecfc8e9d6e8cce63

Authored by Siarhei Siamashka
Committed by Hans de Goede
1 parent b1b912ddf3

tools: mksunxiboot: Fix problems on big endian systems

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

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Showing 1 changed file with 8 additions and 6 deletions Side-by-side Diff

... ... @@ -43,19 +43,19 @@
43 43 uint32_t i;
44 44 uint32_t sum;
45 45  
46   - length = head_p->length;
  46 + length = le32_to_cpu(head_p->length);
47 47 if ((length & 0x3) != 0) /* must 4-byte-aligned */
48 48 return -1;
49 49 buf = (uint32_t *)head_p;
50   - head_p->check_sum = STAMP_VALUE; /* fill stamp */
  50 + head_p->check_sum = cpu_to_le32(STAMP_VALUE); /* fill stamp */
51 51 loop = length >> 2;
52 52  
53 53 /* calculate the sum */
54 54 for (i = 0, sum = 0; i < loop; i++)
55   - sum += buf[i];
  55 + sum += le32_to_cpu(buf[i]);
56 56  
57 57 /* write back check sum */
58   - head_p->check_sum = sum;
  58 + head_p->check_sum = cpu_to_le32(sum);
59 59  
60 60 return 0;
61 61 }
62 62  
... ... @@ -125,10 +125,12 @@
125 125 memcpy(img.header.magic, BOOT0_MAGIC, 8); /* no '0' termination */
126 126 img.header.length =
127 127 ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
  128 + img.header.b_instruction = cpu_to_le32(img.header.b_instruction);
  129 + img.header.length = cpu_to_le32(img.header.length);
128 130 gen_check_sum(&img.header);
129 131  
130   - count = write(fd_out, &img, img.header.length);
131   - if (count != img.header.length) {
  132 + count = write(fd_out, &img, le32_to_cpu(img.header.length));
  133 + if (count != le32_to_cpu(img.header.length)) {
132 134 perror("Writing output");
133 135 return EXIT_FAILURE;
134 136 }