summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-06-26 10:00:29 +0200
committerLuc Verhaegen <libv@skynet.be>2009-06-26 10:00:29 +0200
commit1558735183683e474eab151af7bdb65afbee36de (patch)
tree532eabf32315c6ec17196e12ee45c9bad298a3d7
parent038e6a597ae6efd4a70d25ca3f663c723bee1e4a (diff)
Fix up ami to also dump enough info together with the files.
And get rid of the silly argument parsing. We just take the filename.
-rw-r--r--ami.c131
-rw-r--r--bios_extract.c78
-rw-r--r--bios_extract.h4
-rw-r--r--phoenix.c2
4 files changed, 76 insertions, 139 deletions
diff --git a/ami.c b/ami.c
index 9c2db34..108ef1e 100644
--- a/ami.c
+++ b/ami.c
@@ -94,7 +94,7 @@ AMI95ModuleNames[] = {
};
static char *
-AMI95ModuleNameGet(uint8_t ID, int V95)
+AMI95ModuleNameGet(uint8_t ID)
{
int i;
@@ -102,14 +102,14 @@ AMI95ModuleNameGet(uint8_t ID, int V95)
if (AMI95ModuleNames[i].Id == ID)
return AMI95ModuleNames[i].Name;
- return "";
+ return NULL;
}
/*
*
*/
Bool
-AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, Bool Extract,
+AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
uint32_t AMIBOffset, uint32_t ABCOffset)
{
Bool Compressed;
@@ -147,15 +147,23 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, Bool Extr
return FALSE;
}
+ /* now the individual modules */
+ abc = (struct abc *) (BIOSImage + ABCOffset);
+
+ /* Get Date */
+ memcpy(Date, BIOSImage + BIOSLength - 11, 8);
+ Date[8] = 0;
+
+ printf("AMI95 Version\t: %.4s (%s)\n", abc->Version, Date);
+
/* First, the boot rom */
- if (!Extract)
- printf("AMIBOOT ROM at 0x%05X (0x%05X)\n",
- AMIBOffset, BIOSLength - AMIBOffset);
- else {
- uint32_t RealOffset;
+ {
+ uint32_t BootOffset;
int fd;
- RealOffset = AMIBOffset & 0xFFFF0000;
+ BootOffset = AMIBOffset & 0xFFFF0000;
+
+ printf("0x%05X (%6d bytes) -> amiboot.rom\n", BootOffset, BIOSLength - BootOffset);
fd = open("amiboot.rom", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
@@ -164,30 +172,19 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, Bool Extr
return FALSE;
}
- printf("Dumping amiboot.rom.\n");
-
- write(fd, BIOSImage + RealOffset, BIOSLength - RealOffset);
+ write(fd, BIOSImage + BootOffset, BIOSLength - BootOffset);
close(fd);
}
- /* now the individual modules */
- printf("AMIBIOS 95 header at 0x%05X\n", ABCOffset);
- abc = (struct abc *) (BIOSImage + ABCOffset);
-
- /* Get Date */
- memcpy(Date, BIOSImage + BIOSLength - 11, 8);
- Date[8] = 0;
-
- printf("AMI95 Version\t: %.4s (%s)\n", abc->Version, Date);
- printf("Packed Data\t: %X (%u bytes)\n",
- (uint32_t) abc->CRCLen * 8, (uint32_t) abc->CRCLen * 8);
-
+ /* now dump the individual modules */
Offset = (abc->BeginHi << 4) + abc->BeginLo;
- printf("Modules offset\t: 0x%05X\n", Offset);
-
- printf("\nListing Modules:\n");
for (i = 0; i < 0x80; i++) {
+ char filename[64], *ModuleName;
+ static uint8_t Multiple = 0; /* For the case of multiple 0x20 modules */
+ unsigned char *Buffer;
+ int BufferSize;
+
part = (struct part *) (BIOSImage + (Offset - BIOSOffset));
if (part->IsComprs == 0x80)
@@ -195,46 +192,46 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, Bool Extr
else
Compressed = TRUE;
- if (!Extract) {
- if (Compressed)
- printf(" %02i: %02X (%17.17s) 0x%05X (0x%05X -> 0x%05X)\n",
- i, part->PartID, AMI95ModuleNameGet(part->PartID, TRUE),
- Offset - BIOSOffset + 0x14, part->ROMSize, part->ExpSize);
- else
- printf(" %02i: %02X (%17.17s) 0x%05X (0x%05X)\n",
- i, part->PartID, AMI95ModuleNameGet(part->PartID, TRUE),
- Offset - BIOSOffset + 0x0C, part->CSize);
- } else {
- char filename[64];
- static uint8_t Multiple = 0; /* For the case of multiple 0x20 modules */
- unsigned char *Buffer;
- int BufferSize;
-
- if (part->PartID == 0x20)
- sprintf(filename, "amipci_%.2X.%.2X", Multiple++, part->PartID);
- else
- sprintf(filename, "amibody.%.2x", part->PartID);
-
- printf("Dumping part %d to %s\n", i, filename);
-
- if (Compressed)
- BufferSize = part->ExpSize;
- else
- BufferSize = part->CSize;
-
- Buffer = MMapOutputFile(filename, BufferSize);
- if (!Buffer)
- return FALSE;
-
- if (Compressed)
- LH5Decode(BIOSImage + (Offset - BIOSOffset) + 0x14,
- part->ROMSize, Buffer, BufferSize);
- else
- memcpy(Buffer, BIOSImage + (Offset - BIOSOffset) + 0x0C,
- BufferSize);
-
- munmap(Buffer, BufferSize);
- }
+ if (part->PartID == 0x20)
+ sprintf(filename, "amipci_%02X_%02X.rom", Multiple++, part->PartID);
+ else
+ sprintf(filename, "amibody_%02x.rom", part->PartID);
+
+ if (Compressed)
+ printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x14, part->ROMSize);
+ else
+ printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x0C, part->CSize);
+
+ printf(" -> %s", filename);
+ if (part->PartID != 0x20)
+ printf(" ");
+ if (Compressed)
+ printf(" (%5d bytes)", part->ExpSize);
+ else
+ printf("\t\t");
+
+ ModuleName = AMI95ModuleNameGet(part->PartID);
+ if (ModuleName)
+ printf(" \"%s\"\n", ModuleName);
+ else
+ printf("\n");
+
+ if (Compressed)
+ BufferSize = part->ExpSize;
+ else
+ BufferSize = part->CSize;
+
+ Buffer = MMapOutputFile(filename, BufferSize);
+ if (!Buffer)
+ return FALSE;
+
+ if (Compressed)
+ LH5Decode(BIOSImage + (Offset - BIOSOffset) + 0x14, part->ROMSize,
+ Buffer, BufferSize);
+ else
+ memcpy(Buffer, BIOSImage + (Offset - BIOSOffset) + 0x0C, BufferSize);
+
+ munmap(Buffer, BufferSize);
if ((part->PrePartHi == 0xFFFF) || (part->PrePartLo == 0xFFFF))
break;
diff --git a/bios_extract.c b/bios_extract.c
index 2929dab..316dd76 100644
--- a/bios_extract.c
+++ b/bios_extract.c
@@ -33,63 +33,6 @@ HelpPrint(char *name)
{
printf("Program to extract AMI Bios images (AMIBIOS '94 and '95).\n\n");
printf("Usage: %s <action> <filename>\n", name);
- printf("Actions:\n");
- printf("\"l\"\tList Bios Structure.\n");
- printf("\"x\"\tExtract Bios Modules.\n");
- printf("\"h\"\tPrint usage information.\n");
-}
-
-static char *
-ArgumentsParse(int argc, char *argv[], Bool *Extract)
-{
- char *FileName = NULL;
- Bool FoundAction = FALSE;
- int i;
-
- *Extract = FALSE;
-
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "h"))
- return NULL;
- else if (!strcmp(argv[i], "x")) {
- if (!FoundAction) {
- *Extract = TRUE;
- FoundAction = TRUE;
- } else {
- fprintf(stderr, "Error: wrong argument (%s)."
- " Please provide only one action.\n", argv[i]);
- return NULL;
- }
- } else if (!strcmp(argv[i], "l")) {
- if (!FoundAction) {
- *Extract = FALSE;
- FoundAction = TRUE;
- } else {
- fprintf(stderr, "Error: wrong argument (%s)."
- " Please provide only one action.\n", argv[i]);
- return NULL;
- }
- } else {
- if (!FileName)
- FileName = argv[i];
- else {
- fprintf(stderr, "Error: wrong argument (%s)."
- " Please provide only one filename.\n", argv[i]);
- return NULL;
- }
- }
- }
-
- if (!FileName) {
- fprintf(stderr, "Error: Please provide a filename.\n");
- return NULL;
- }
-
- if (!FoundAction) {
- return NULL;
- }
-
- return FileName;
}
unsigned char *
@@ -137,10 +80,10 @@ static struct {
char *String1;
char *String2;
Bool (*Handler) (unsigned char *Image, int ImageLength, int ImageOffset,
- Bool Extract, uint32_t Offset1, uint32_t Offset2);
+ uint32_t Offset1, uint32_t Offset2);
} BIOSIdentification[] = {
{"AMIBOOT ROM", "AMIBIOSC", AMI95Extract},
- //{"Phoenix FirstBIOS", "BCPSEGMENT", PhoenixExtract},
+ {"Phoenix FirstBIOS", "BCPSEGMENT", PhoenixExtract},
{"PhoenixBIOS 4.0", "BCPSEGMENT", PhoenixExtract},
{NULL, NULL, NULL},
};
@@ -151,8 +94,6 @@ static struct {
int
main(int argc, char *argv[])
{
- Bool Extract = FALSE;
- char *FileName = NULL;
int FileLength = 0;
uint32_t BIOSOffset = 0;
unsigned char *BIOSImage = NULL;
@@ -161,23 +102,22 @@ main(int argc, char *argv[])
int i, len;
unsigned char *tmp;
- FileName = ArgumentsParse(argc, argv, &Extract);
- if (!FileName) {
+ if (argc != 2) {
HelpPrint(argv[0]);
return 1;
}
- fd = open(FileName, O_RDONLY);
+ fd = open(argv[1], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error: Failed to open %s: %s\n",
- FileName, strerror(errno));
+ argv[1], strerror(errno));
return 1;
}
FileLength = lseek(fd, 0, SEEK_END);
if (FileLength < 0) {
fprintf(stderr, "Error: Failed to lseek \"%s\": %s\n",
- FileName, strerror(errno));
+ argv[1], strerror(errno));
return 1;
}
BIOSOffset = 0x100000 - FileLength;
@@ -185,11 +125,11 @@ main(int argc, char *argv[])
BIOSImage = mmap(NULL, FileLength, PROT_READ, MAP_PRIVATE, fd, 0);
if (BIOSImage < 0) {
fprintf(stderr, "Error: Failed to mmap %s: %s\n",
- FileName, strerror(errno));
+ argv[1], strerror(errno));
return 1;
}
- printf("Using file \"%s\" (%ukB)\n", FileName, FileLength >> 10);
+ printf("Using file \"%s\" (%ukB)\n", argv[1], FileLength >> 10);
for (i = 0; BIOSIdentification[i].Handler; i++) {
len = strlen(BIOSIdentification[i].String1);
@@ -204,7 +144,7 @@ main(int argc, char *argv[])
continue;
Offset2 = tmp - BIOSImage;
- if (BIOSIdentification[i].Handler(BIOSImage, FileLength, BIOSOffset, Extract,
+ if (BIOSIdentification[i].Handler(BIOSImage, FileLength, BIOSOffset,
Offset1, Offset2))
return 0;
else
diff --git a/bios_extract.h b/bios_extract.h
index c0bec92..1c7df9a 100644
--- a/bios_extract.h
+++ b/bios_extract.h
@@ -28,10 +28,10 @@ unsigned char *MMapOutputFile(char *filename, int size);
/* ami.c */
Bool AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
- Bool Extract, uint32_t Offset1, uint32_t Offset2);
+ uint32_t Offset1, uint32_t Offset2);
/* phoenix.c */
Bool PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
- Bool Extract, uint32_t Offset1, uint32_t Offset2);
+ uint32_t Offset1, uint32_t Offset2);
#endif /* BIOS_EXTRACT_H */
diff --git a/phoenix.c b/phoenix.c
index 51ce5b3..8ee241c 100644
--- a/phoenix.c
+++ b/phoenix.c
@@ -182,7 +182,7 @@ PhoenixModule(unsigned char *BIOSImage, int BIOSLength, int Offset)
*/
Bool
PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
- Bool Extract, uint32_t Offset1, uint32_t BCPSegmentOffset)
+ uint32_t Offset1, uint32_t BCPSegmentOffset)
{
struct PhoenixID {
char Name[6];