diff --git a/Software/a4092flash/flash.c b/Software/a4092flash/flash.c index f2d6b55..85c2f5f 100644 --- a/Software/a4092flash/flash.c +++ b/Software/a4092flash/flash.c @@ -158,6 +158,21 @@ static UWORD flash_get_sectorSize(UBYTE manufacturer, UBYTE device) { return sectorSize; } +/** flash_readByte + * + * @brief Read a byte from Flash + * @param address Address to read from + * @return The data that was read + */ +UBYTE flash_readByte(ULONG address) { + // Mask address to ensure it is within the valid flash size. + address &= (FLASH_SIZE - 1); + + return flash_read_byte(address); +} + + + /** flash_writeByte * * @brief Write a byte to the Flash diff --git a/Software/a4092flash/flash.h b/Software/a4092flash/flash.h index 39a2670..450767d 100644 --- a/Software/a4092flash/flash.h +++ b/Software/a4092flash/flash.h @@ -24,6 +24,7 @@ void flash_unlock_sdp(); void flash_erase_chip(); +UBYTE flash_readByte(ULONG); void flash_writeByte(ULONG, UBYTE); bool flash_init(UBYTE *, UBYTE *, ULONG *, UWORD *); void flash_erase_sector(ULONG); diff --git a/Software/a4092flash/main.c b/Software/a4092flash/main.c index bd6145c..2b48fd3 100644 --- a/Software/a4092flash/main.c +++ b/Software/a4092flash/main.c @@ -446,7 +446,7 @@ BOOL readFileToBuf(char *filename, void *buffer) { */ BOOL writeBufToFlash(struct scsiBoard *board, UBYTE *source, UBYTE *dest, ULONG size) { UBYTE *sourcePtr = NULL; - UBYTE *destPtr = NULL; + UBYTE destVal = 0; int progress = 0; int lastProgress = 1; @@ -482,9 +482,9 @@ BOOL writeBufToFlash(struct scsiBoard *board, UBYTE *source, UBYTE *dest, ULONG lastProgress = progress; } sourcePtr = ((void *)source + i); - destPtr = ((void *)dest + (i << 2)); - if (*sourcePtr != *destPtr) { - printf("\nVerification failed at %06x - Expected %02X but read %02X\n",(int)destPtr,*sourcePtr,*destPtr); + destVal = flash_readByte(i); + if (*sourcePtr != destVal) { + printf("\nVerification failed at offset %06x - Expected %02X but read %02X\n",i,*sourcePtr,destVal); return false; } }