[cc65] CRC-32

Date view Thread view Subject view

From: MagerValp (MagerValp_at_cling.gu.se)
Date: 2003-09-19 17:28:39


To add protection against corrupted rom images and flash programming
failures, I'm implementing CRC-32 checks in the C1's boot rom. My ld65
config looks like this:

MEMORY {
	LOWZP:	start = $00, size = $80, type = rw;
	HIGHZP:	start = $c0, size = $40, type = rw;
	LORAM:	start = $0200, size = $1e00;
	FLASH:	start = $2000, size = $1e00;
	ROM:	start = $c000, size = $4000, file = %O, define = yes;
}
SEGMENTS {
	ZEROPAGE:	load = LOWZP, type = zp;
	DEVZP:		load = HIGHZP, type = zp, start = $e0;
	VOLZP:		load = HIGHZP, type = zp, start = $f0;
	BSS:		load = LORAM, type = bss, define = yes, align = $100;
	VOLBSS:		load = LORAM, type = bss, start = $1f00;
	DEVBSS:		load = LORAM, type = bss, start = $1f40;
	CHECKSUM:	load = ROM, type = wprot;
	CODE:		load = ROM, type = wprot;
	RODATA:		load = ROM, type = wprot, align = $100;
	DATA:		load = ROM, type = rw;
	RELOC:		load = ROM, run = FLASH, type = rw, define = yes;
	VOLVECTORS:	load = ROM, type = ro, start = $ff00;
	DEVVECTORS:	load = ROM, type = ro, start = $ff40;
	CTLVECTORS:	load = ROM, type = ro, start = $ff50;
	DBGVECTORS:	load = ROM, type = ro, start = $ff60;
	GFXVECTORS:	load = ROM, type = ro, start = $ff80;
	VERSION:	load = ROM, type = ro, start = $fff0;
	CPUVECTORS:	load = ROM, type = ro, start = $fffa;
}

I have reserved 4 bytes in the CHECKSUM segment, and I'm assuming that
there's no way of getting ld65 to automagically fill it with the CRC
of the rest of the ROM. So what I did was write a small perl script
that reads the last 16380 bytes of the generated file, computes the
CRC-32 checksum, and writes it all back. In the rom I have a corre-
sponding routine that I grabbed from 6502.org, and this is where the
trouble starts. Perl, 6502.org, zip, and cksum all give me different
values for the same data:

% perl -MString::CRC -e 'printf("%08x\n", crc("\x00" x 16380, 32));'
bfb3e861
% dd if=/dev/zero of=testrom bs=16380 count=1
% zip testrom.zip testrom
% unzip -v testrom.zip
  16380  Defl:N      33 100%  09-19-103  16:53  36aefd86   testrom
% cksum testrom | awk '{printf "%08x", $1}'
2fd654c8

...and the assembler routine from 6502.org gives me c9510279.

*sigh*

Has anyone here successfully used the crc-32 code from 6502.org?

-- 
                       Wildstar delenda est
    ___          .     .  .         .       . +  .         .      o   
  _|___|_   +   .  +     .     +         .  Per Olofsson, arkadspelare
    o-o    .      .     .   o         +          MagerValp_at_cling.gu.se
     -       +            +    .     http://www.cling.gu.se/~cl3polof/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-09-19 17:34:17 CEST