2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: m68k-amiga ROM checksum generator
18 static int amiga_checksum(uint8_t *mem
, int size
, uint32_t chkoff
, int update
)
20 uint32_t oldcksum
= 0, cksum
= 0, prevck
= 0;
23 for (i
= 0; i
< size
; i
+=4) {
24 uint32_t val
= (mem
[i
+0] << 24) +
29 /* Clear existing checksum */
30 if (update
&& i
== chkoff
) {
43 if (update
&& cksum
!= oldcksum
) {
44 printf("Updating checksum from 0x%08x to 0x%08x\n", oldcksum
, cksum
);
46 mem
[chkoff
+ 0] = (cksum
>> 24) & 0xff;
47 mem
[chkoff
+ 1] = (cksum
>> 16) & 0xff;
48 mem
[chkoff
+ 2] = (cksum
>> 8) & 0xff;
49 mem
[chkoff
+ 3] = (cksum
>> 0) & 0xff;
57 int main(int argc
, char **argv
)
59 int err
, fd
, i
, retval
= EXIT_FAILURE
;
65 fd
= open(argv
[1], O_RDWR
| O_CREAT
, 0666);
71 origlen
= lseek(fd
, 0, SEEK_END
);
73 /* Make sure we have a valid ROM ID */
74 rom
= mmap(NULL
, origlen
, PROT_READ
| PROT_WRITE
,
76 if (rom
== MAP_FAILED
)
83 if (p
[0] == 0x11 && (p
[1] >= 0x11 || p
[1] <= 0x14))
90 printf("Warning: ROM ID is for a 256K ROM, but the image is larger -> promoting to 512KB ROM.\n");
98 printf("Error: Invalid ROM ID (%02x%02x).\n", p
[0], p
[1]);
110 printf("Error: ROM Size > %uKB", size
/1024);
111 if ((len
- size
) >= 1024)
112 printf(" (+%luKB).\n", (len
- size
)/1024);
114 printf(" (+%luB).\n", (len
- size
));
119 for (; len
< size
; len
++) {
123 /* Earlier kickstarts used 0x00 as the pad byte.. */
131 rom
= mmap(NULL
, len
, PROT_READ
| PROT_WRITE
,
134 if (rom
!= MAP_FAILED
)
136 p
= (uint8_t*)rom
+ len
- 20;
137 if ((origlen
<= (size
- 24)) ||
138 ((p
[0] == (len
>> 24) & 0xFF) &&
139 (p
[1] == (len
>> 16) & 0xFF) &&
140 (p
[2] == (len
>> 8) & 0xFF) &&
141 (p
[3] == (len
>> 0) & 0xFF)))
143 /* Make sure the rom size is set*/
149 /* Add the interrupt vector offsets,
150 * needed by 68000 and 68010 */
151 p
= (uint8_t*)rom
+ len
- 16;
152 for (i
= 0; i
< 8; i
++) {
153 p
[i
* 2 + 1] = i
+ 0x18;
157 err
= amiga_checksum(rom
, len
, len
- 24, 0);
158 err
= amiga_checksum(rom
, len
, len
- 24, 1);
160 retval
= EXIT_SUCCESS
;
164 printf("Error: Rom Data Size exceeds available space (%lu bytes remaining).\n", size
- origlen
);