More robust detection of file transfer/conversion errors in ROM/boot code
This commit is contained in:
parent
f09637186d
commit
cf49864327
3 changed files with 31 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
|||
#ifndef ROM_vax780_vmb_exe_H
|
||||
#define ROM_vax780_vmb_exe_H 0
|
||||
/*
|
||||
VAX/vax780_vmb_exe.h produced at Tue Sep 20 04:39:17 2011
|
||||
from VAX/vmb.exe which was last modified at Tue Sep 20 03:24:44 2011
|
||||
file size: 44544 (0xAE00)
|
||||
VAX/vax780_vmb_exe.h produced at Sun Feb 26 12:32:44 2012
|
||||
from VAX/vmb.exe which was last modified at Sat Feb 18 00:01:12 2012
|
||||
file size: 44544 (0xAE00) - checksum: 0xFFC014CC
|
||||
*/
|
||||
unsigned char vax780_vmb_exe[] = {
|
||||
0xD4,0xEF,0x34,0x61,0x00,0x00,0x17,0xEF,0xB8,0x5D,0x00,0x00,0xC1,0xAB,0x38,0xAB,
|
||||
|
@ -2788,3 +2790,4 @@ unsigned char vax780_vmb_exe[] = {
|
|||
0x4C,0x52,0x45,0x41,0x44,0x3A,0x58,0x2D,0x32,0x20,0x20,0x43,0x4F,0x4E,0x49,0x4F,
|
||||
0x3A,0x58,0x2D,0x33,0x20,0x20,0x2A,0x45,0x6E,0x64,0x20,0x6F,0x66,0x20,0x49,0x64,
|
||||
0x65,0x6E,0x74,0x20,0x6C,0x69,0x73,0x74,0x73,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,};
|
||||
#endif /* ROM_vax780_vmb_exe_H */
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef ROM_vax_ka655x_bin_H
|
||||
#define ROM_vax_ka655x_bin_H 0
|
||||
/*
|
||||
VAX/vax_ka655x_bin.h produced at Tue Sep 20 04:39:07 2011
|
||||
from VAX/ka655x.bin which was last modified at Tue Sep 20 03:24:43 2011
|
||||
file size: 131072 (0x20000)
|
||||
VAX/vax_ka655x_bin.h produced at Sun Feb 26 12:32:44 2012
|
||||
from VAX/ka655x.bin which was last modified at Sat Feb 18 00:01:12 2012
|
||||
file size: 131072 (0x20000) - checksum: 0xFF7673B6
|
||||
*/
|
||||
unsigned char vax_ka655x_bin[] = {
|
||||
0x11,0x22,0x11,0xFE,0x02,0x03,0x53,0x01,0x31,0x89,0x03,0x00,0x31,0x8B,0x03,0x00,
|
||||
|
@ -8196,3 +8198,4 @@ unsigned char vax_ka655x_bin[] = {
|
|||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
|
||||
#endif /* ROM_vax_ka655x_bin_H */
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
|
||||
int sim_make_ROM_include(const char *rom_filename,
|
||||
int expected_size,
|
||||
int expected_checksum,
|
||||
const char *include_filename,
|
||||
const char *rom_array_name)
|
||||
{
|
||||
|
@ -65,6 +66,7 @@ int bytes_written = 0;
|
|||
int c;
|
||||
struct stat statb;
|
||||
unsigned char *ROMData = NULL;
|
||||
unsigned int checksum = 0;
|
||||
|
||||
if (NULL == (rFile = fopen (rom_filename, "rb"))) {
|
||||
printf ("Error Opening '%s' for input: %s\n", rom_filename, strerror(errno));
|
||||
|
@ -76,7 +78,7 @@ if (stat (rom_filename, &statb)) {
|
|||
return -1;
|
||||
}
|
||||
if (statb.st_size != expected_size) {
|
||||
printf ("Error: ROM file '%s' has an unexpected size: %d vs %d\n", (int)statb.st_size, expected_size);
|
||||
printf ("Error: ROM file '%s' has an unexpected size: %d vs %d\n", rom_filename, (int)statb.st_size, expected_size);
|
||||
printf ("This can happen if the file was transferred or unpacked incorrectly\n");
|
||||
printf ("and in the process tried to convert line endings rather than passing\n");
|
||||
printf ("the file's contents unmodified\n");
|
||||
|
@ -91,6 +93,17 @@ if (statb.st_size != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) {
|
|||
return -1;
|
||||
}
|
||||
fclose (rFile);
|
||||
for (c=0; c<statb.st_size; ++c)
|
||||
checksum += ROMData[c];
|
||||
checksum = ~checksum;
|
||||
if ((expected_checksum != 0) && (checksum != expected_checksum)) {
|
||||
printf ("Error: ROM file '%s' has an unexpected checksum: 0x%08X vs 0x%08X\n", rom_filename, checksum, expected_checksum);
|
||||
printf ("This can happen if the file was transferred or unpacked incorrectly\n");
|
||||
printf ("and in the process tried to convert line endings rather than passing\n");
|
||||
printf ("the file's contents unmodified\n");
|
||||
fclose (rFile);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* If the target include file already exists, determine if it contains the exact
|
||||
* data in the base ROM image. If so, then we are already done
|
||||
|
@ -139,7 +152,7 @@ fprintf (iFile, "#define ROM_%s_H 0\n", rom_array_name);
|
|||
fprintf (iFile, "/*\n");
|
||||
fprintf (iFile, " %s produced at %s", include_filename, ctime(&now));
|
||||
fprintf (iFile, " from %s which was last modified at %s", rom_filename, ctime(&statb.st_mtime));
|
||||
fprintf (iFile, " file size: %d (0x%X)\n", (int)statb.st_size, (int)statb.st_size);
|
||||
fprintf (iFile, " file size: %d (0x%X) - checksum: 0x%08X\n", (int)statb.st_size, (int)statb.st_size, checksum);
|
||||
fprintf (iFile, "*/\n");
|
||||
fprintf (iFile, "unsigned char %s[] = {", rom_array_name);
|
||||
for (bytes_written=0;bytes_written<statb.st_size; ++bytes_written) {
|
||||
|
@ -165,7 +178,8 @@ return 0;
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sim_make_ROM_include ("VAX/ka655x.bin", 131072, "VAX/vax_ka655x_bin.h", "vax_ka655x_bin");
|
||||
sim_make_ROM_include ("VAX/vmb.exe", 44544, "VAX/vax780_vmb_exe.h", "vax780_vmb_exe");
|
||||
exit(0);
|
||||
int status = 0;
|
||||
status += sim_make_ROM_include ("VAX/ka655x.bin", 131072, 0xFF7673B6, "VAX/vax_ka655x_bin.h", "vax_ka655x_bin");
|
||||
status += sim_make_ROM_include ("VAX/vmb.exe", 44544, 0xFFC014CC, "VAX/vax780_vmb_exe.h", "vax780_vmb_exe");
|
||||
exit((status == 0) ? 0 : 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue