2 Copyright © 1995-2010, 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 old 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
)
62 uint32_t size
= 512 * 1024;
65 fd
= open(argv
[1], O_RDWR
| O_CREAT
, 0666);
72 for (len
= lseek(fd
, 0, SEEK_END
); len
< size
; len
++) {
73 unsigned char ff
= 0xff;
77 rom
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
,
79 if (rom
== MAP_FAILED
) {
85 /* add interrupt vector offsets, needed by 68000 and 68010 */
86 p
= (uint8_t*)rom
+ size
- 16;
87 for (i
= 0; i
< 7; i
++) {
88 p
[i
* 2 + 1] = i
+ 0x18;
93 p
= (uint8_t*)rom
+ size
- 20;
99 err
= amiga_checksum(rom
, size
, size
- 24, 0);
100 err
= amiga_checksum(rom
, size
, size
- 24, 1);