rpms/bios_extract/devel bios_extract--ami_endian.diff, NONE, 1.1 bios_extract--phoenix_and_lh5_endian.diff, NONE, 1.1 bios_extract--recognition_of_more_bios_types.diff, NONE, 1.1 bios_extract.spec, 1.2, 1.3 import.log, 1.1, 1.2

Peter Lemenkov peter at fedoraproject.org
Sat Aug 1 19:07:51 UTC 2009


Author: peter

Update of /cvs/pkgs/rpms/bios_extract/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv8642/devel

Modified Files:
	bios_extract.spec import.log 
Added Files:
	bios_extract--ami_endian.diff 
	bios_extract--phoenix_and_lh5_endian.diff 
	bios_extract--recognition_of_more_bios_types.diff 
Log Message:
BigEndian fixes and more bios-types recognized now

bios_extract--ami_endian.diff:
 ami.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

--- NEW FILE bios_extract--ami_endian.diff ---
>From c07e897df4b1d64307550049d08ebcbbe258e593 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov at gmail.com>
Date: Sat, 1 Aug 2009 20:55:17 +0400
Subject: [PATCH] Fix for endianness in AMI extraction routines.

Subj. Since I finally found AMI bios images among other ~ 2.5 Gbytes
of proprietary bioses.

Signed-off-by: Peter Lemenkov <lemenkov at gmail.com>

diff --git a/ami.c b/ami.c
index 108ef1e..88a00d4 100644
--- a/ami.c
+++ b/ami.c
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <endian.h>
 
 #include "bios_extract.h"
 #include "lh5_extract.h"
@@ -177,7 +178,7 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
     }
 
     /* now dump the individual modules */
-    Offset = (abc->BeginHi << 4) + abc->BeginLo;
+    Offset = (le16toh(abc->BeginHi) << 4) + le16toh(abc->BeginLo);
 
     for (i = 0; i < 0x80; i++) {
 	char filename[64], *ModuleName;
@@ -198,15 +199,15 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
 	    sprintf(filename, "amibody_%02x.rom", part->PartID);
 
 	if (Compressed)
-	    printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x14, part->ROMSize);
+	    printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x14, le32toh(part->ROMSize));
 	else
-	    printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x0C, part->CSize);
+	    printf("0x%05X (%6d bytes)", Offset - BIOSOffset + 0x0C, le16toh(part->CSize));
 
 	printf(" -> %s", filename);
 	if (part->PartID != 0x20)
 	    printf("  ");
 	if (Compressed)
-	    printf(" (%5d bytes)", part->ExpSize);
+	    printf(" (%5d bytes)", le32toh(part->ExpSize));
 	else
 	    printf("\t\t");
 
@@ -217,25 +218,25 @@ AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
 	    printf("\n");
 
 	if (Compressed)
-	    BufferSize = part->ExpSize;
+	    BufferSize = le32toh(part->ExpSize);
 	else
-	    BufferSize = part->CSize;
+	    BufferSize = le16toh(part->CSize);
 
 	Buffer = MMapOutputFile(filename, BufferSize);
 	if (!Buffer)
 	    return FALSE;
 
 	if (Compressed)
-	    LH5Decode(BIOSImage + (Offset - BIOSOffset) + 0x14, part->ROMSize,
+	    LH5Decode(BIOSImage + (Offset - BIOSOffset) + 0x14, le32toh(part->ROMSize),
 		      Buffer, BufferSize);
 	else
 	    memcpy(Buffer, BIOSImage + (Offset - BIOSOffset) + 0x0C, BufferSize);
 
 	munmap(Buffer, BufferSize);
 
-	if ((part->PrePartHi == 0xFFFF) || (part->PrePartLo == 0xFFFF))
+	if ((le16toh(part->PrePartHi) == 0xFFFF) || (le16toh(part->PrePartLo) == 0xFFFF))
 	    break;
-	Offset = (part->PrePartHi << 4) + part->PrePartLo;
+	Offset = (le16toh(part->PrePartHi) << 4) + le16toh(part->PrePartLo);
     }
 
     return TRUE;

bios_extract--phoenix_and_lh5_endian.diff:
 lh5_extract.c |    9 +++++----
 phoenix.c     |   33 +++++++++++++++++----------------
 2 files changed, 22 insertions(+), 20 deletions(-)

--- NEW FILE bios_extract--phoenix_and_lh5_endian.diff ---
>From 989a6c675212d459619a3a1e1c53dd6040e65867 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov at gmail.com>
Date: Sat, 1 Aug 2009 20:37:56 +0400
Subject: [PATCH] New version of endian patch.

I removed #ifdefs completely, since they already exists in <endian.h>,
so we may simply (and safely) use htole[16,32]/le[16,32]toh. I also fixed
nasty typo in my prevoius patch - I should use le[16,32]to h rather than
htole[16,32]. However this renders to correct results,also, since both of
them are actually just #defines around bswap_[16,32].

Also, I found one phoenix BIOS image and therefore was able to fix extraction
from it on PowerPC. See patch.

Signed-off-by: Peter Lemenkov <lemenkov at gmail.com>

diff --git a/lh5_extract.c b/lh5_extract.c
index 60ecd48..b3e2d98 100644
--- a/lh5_extract.c
+++ b/lh5_extract.c
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <endian.h>
 
 #include "lh5_extract.h"
 
@@ -129,18 +130,18 @@ LH5HeaderParse(unsigned char *Buffer, int BufferSize,
         return 0;
     }
 
-    *packed_size = *(unsigned int *) (Buffer + 7);
-    *original_size = *(unsigned int *) (Buffer + 11);
+    *packed_size = le32toh(*(unsigned int *) (Buffer + 7));
+    *original_size = le32toh(*(unsigned int *) (Buffer + 11));
 
     name_length = Buffer[21];
     *name = strndup((char *) Buffer + 22, name_length);
 
-    *crc = *(unsigned short *) (Buffer + 22 + name_length);
+    *crc = le16toh(*(unsigned short *) (Buffer + 22 + name_length));
 
     offset = header_size + 2;
     /* Skip extended headers */
     while (1) {
-	unsigned short extend_size = *(unsigned short *) (Buffer + offset - 2);
+	unsigned short extend_size = le16toh(*(unsigned short *) (Buffer + offset - 2));
 
 	if (!extend_size)
 	    break;
diff --git a/phoenix.c b/phoenix.c
index 8ee241c..c2fe10a 100644
--- a/phoenix.c
+++ b/phoenix.c
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+#include <endian.h>
 
 #include "bios_extract.h"
 #include "lh5_extract.h"
@@ -108,10 +109,10 @@ PhoenixModule(unsigned char *BIOSImage, int BIOSLength, int Offset)
 	return 0;
     }
 
-    if ((Offset + Module->HeadLen + 4 + Module->Packed1) > BIOSLength) {
+    if ((Offset + Module->HeadLen + 4 + le32toh(Module->Packed1)) > BIOSLength) {
 	fprintf(stderr, "Error: Module overruns buffer at 0x%05X\n",
 		Offset);
-	return Module->Previous;
+	return le32toh(Module->Previous);
     }
 
     ModuleName = PhoenixModuleNameGet(Module->Type);
@@ -134,47 +135,47 @@ PhoenixModule(unsigned char *BIOSImage, int BIOSLength, int Offset)
     switch (Module->Compression) {
     case 5: /* LH5 */
 	printf("0x%05X (%6d bytes)   ->   %s\t(%d bytes)", Offset + Module->HeadLen + 4,
-	       Module->Packed1, filename, Module->ExpLen1);
+	       le32toh(Module->Packed1), filename, le32toh(Module->ExpLen1));
 
-	Buffer = MMapOutputFile(filename, Module->ExpLen1);
+	Buffer = MMapOutputFile(filename, le32toh(Module->ExpLen1));
 	if (!Buffer)
 	    break;
 
 	LH5Decode(BIOSImage + Offset + Module->HeadLen + 4,
-		  Module->Packed1, Buffer, Module->ExpLen1);
+		  le32toh(Module->Packed1), Buffer, le32toh(Module->ExpLen1));
 
-	munmap(Buffer, Module->ExpLen1);
+	munmap(Buffer, le32toh(Module->ExpLen1));
 
 	break;
     /* case 3 */ /* LZSS */
     case 0: /* not compressed at all */
 	/* why do we not use the full header here? */
 	printf("0x%05X (%6d bytes)   ->   %s", Offset + Module->HeadLen,
-	       Module->Packed1, filename);
+	       le32toh(Module->Packed1), filename);
 
-	write(fd, BIOSImage + Offset + Module->HeadLen, Module->Packed1);
+	write(fd, BIOSImage + Offset + Module->HeadLen, le32toh(Module->Packed1));
 	break;
     default:
 	fprintf(stderr, "Unsupported compression type for %s: %d\n",
 		filename, Module->Compression);
 	printf("0x%05X (%6d bytes)   ->   %s\t(%d bytes)", Offset + Module->HeadLen + 4,
-	       Module->Packed1, filename, Module->ExpLen1);
+	       le32toh(Module->Packed1), filename, le32toh(Module->ExpLen1));
 
-	write(fd, BIOSImage + Offset + Module->HeadLen + 4, Module->Packed1);
+	write(fd, BIOSImage + Offset + Module->HeadLen + 4, le32toh(Module->Packed1));
 	break;
     }
 
     close(fd);
     free(filename);
 
-    if (Module->Offset || Module->Segment) {
+    if (le16toh(Module->Offset) || le16toh(Module->Segment)) {
 	if (!Module->Compression)
 	    printf("\t\t");
-	printf("\t [0x%04X:0x%04X]\n", Module->Segment << 12, Module->Offset);
+	printf("\t [0x%04X:0x%04X]\n", le16toh(Module->Segment) << 12, le16toh(Module->Offset));
     } else
 	printf("\n");
 
-    return Module->Previous;
+    return le32toh(Module->Previous);
 }
 
 /*
@@ -195,11 +196,11 @@ PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
 
     for (ID = (struct PhoenixID *) (BIOSImage + BCPSegmentOffset + 10);
 	 ((void *) ID < (void *) (BIOSImage + BIOSLength)) && ID->Name[0];
-	 ID = (struct PhoenixID *) (((unsigned char *) ID) + ID->Length)) {
+	 ID = (struct PhoenixID *) (((unsigned char *) ID) + le16toh(ID->Length))) {
 #if 0
 	printf("PhoenixID: Name %c%c%c%c%c%c, Flags 0x%04X, Length %d\n",
 	       ID->Name[0],  ID->Name[1], ID->Name[2],  ID->Name[3],
-	       ID->Name[4],  ID->Name[5], ID->Flags, ID->Length);
+	       ID->Name[4],  ID->Name[5], le16toh(ID->Flags), le16toh(ID->Length));
 #endif
 	if (!strncmp(ID->Name, "BCPSYS", 6))
 	    break;
@@ -224,7 +225,7 @@ PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
 	printf("Version \"%s\", created on %s at %s.\n", Version, Date, Time);
     }
 
-    Offset = *((uint32_t *) (((char *) ID) + 0x77));
+    Offset = le32toh(*((uint32_t *) (((char *) ID) + 0x77)));
     Offset &= (BIOSLength - 1);
     if (!Offset) {
 	fprintf(stderr, "Error: retrieved invalid Modules offset.\n");

bios_extract--recognition_of_more_bios_types.diff:
 bios_extract.c |    5 +++++
 1 file changed, 5 insertions(+)

--- NEW FILE bios_extract--recognition_of_more_bios_types.diff ---
>From 2fe1f3c5351ce7d757a0dd63607b67cdcbf235b3 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov at gmail.com>
Date: Sat, 1 Aug 2009 21:08:01 +0400
Subject: [PATCH] Identification of some more BIOS images.

Subj. Actually, I'm sure this is an ugly patch. The proper way will be
the addition of some special search procedures and some commandline
switches to force using of specific extraction routines ( -f ami, -f award).

Anyway, here is a working patch for decoding Asus bioses.

Signed-off-by: Peter Lemenkov <lemenkov at gmail.com>

diff --git a/bios_extract.c b/bios_extract.c
index 7b81c72..104232a 100644
--- a/bios_extract.c
+++ b/bios_extract.c
@@ -89,6 +89,11 @@ static struct {
     {"Award BootBlock", "= Award Decompression Bios =", AwardExtract},
     {"Phoenix FirstBIOS", "BCPSEGMENT", PhoenixExtract},
     {"PhoenixBIOS 4.0", "BCPSEGMENT", PhoenixExtract},
+    /* custom modified BIOS from Asus - they replace "AMIBOOT " with their own
+     * BIOS ID text */
+    {"ROM", "AMIBIOSC", AMI95Extract},
+    /* some award modules - not sure this is a good solution */
+    {"Award", "Award", AwardExtract},
     {NULL, NULL, NULL},
 };
 


Index: bios_extract.spec
===================================================================
RCS file: /cvs/pkgs/rpms/bios_extract/devel/bios_extract.spec,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -p -r1.2 -r1.3
--- bios_extract.spec	24 Jul 2009 18:04:42 -0000	1.2
+++ bios_extract.spec	1 Aug 2009 19:07:51 -0000	1.3
@@ -3,13 +3,19 @@
 
 Name:		bios_extract
 Version:	0
-Release:	0.3.%{git_commit_date}git%{?dist}
+Release:	0.4.%{git_commit_date}git%{?dist}
 Summary:	Tools to extract the different submodules of common legacy bioses
 
 Group:		Applications/System
 License:	GPLv2+
 URL:		http://cgit.freedesktop.org/~libv/bios_extract
 Source0:	http://cgit.freedesktop.org/~libv/bios_extract/snapshot/%{name}-%{git_commit}.tar.bz2
+# fix for extraction of Award and Phoenix bios-images on BigEndian platforms (patch sent upstream)
+Patch0:		bios_extract--ami_endian.diff
+# fix for extraction of AMI bios-images on BigEndian platforms (patch sent upstream)
+Patch1:		bios_extract--phoenix_and_lh5_endian.diff
+# recognized more bios images (ASUS for example) (patch sent upstream)
+Patch2:		bios_extract--recognition_of_more_bios_types.diff
 BuildRoot:	%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 
 %description
@@ -19,6 +25,9 @@ Tools to extract the different submodule
 %prep
 %setup -q -n %{name}-%{git_commit}
 sed -i s/^CFLAGS.*$// Makefile
+%patch0 -p1 -b .big_endian
+%patch1 -p1 -b .ami_big_endian
+%patch2 -p1 -b .more_images
 
 
 %build
@@ -42,6 +51,10 @@ rm -rf $RPM_BUILD_ROOT
 
 
 %changelog
+* Sat Aug  1 2009 Peter Lemenkov <lemenkov at gmail.com> 0-0.4.20090713git
+- Fixed work on BigEndian platforms
+- More bios-types recognized
+
 * Fri Jul 24 2009 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0-0.3.20090713git
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild
 


Index: import.log
===================================================================
RCS file: /cvs/pkgs/rpms/bios_extract/devel/import.log,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -r1.1 -r1.2
--- import.log	23 Jul 2009 16:51:04 -0000	1.1
+++ import.log	1 Aug 2009 19:07:51 -0000	1.2
@@ -1 +1,2 @@
 bios_extract-0-0_2_20090713git_fc11:HEAD:bios_extract-0-0.2.20090713git.fc11.src.rpm:1248367822
+bios_extract-0-0_4_20090713git_fc11:HEAD:bios_extract-0-0.4.20090713git.fc11.src.rpm:1249153598




More information about the scm-commits mailing list