Print name of compression algorithm in addition to the corresponding 
number during boot.
Convert process_file() to use enum compalgo instead of hardcoded 
"1","2","3" and change the control structure from a series of if() 
statements to a switch() statement.

Compile and boot tested on Qemu.

Signed-off-by: Carl-Daniel Hailfinger <[EMAIL PROTECTED]>

Index: LinuxBIOSv3-algonaming/include/lar.h
===================================================================
--- LinuxBIOSv3-algonaming/include/lar.h        (Revision 605)
+++ LinuxBIOSv3-algonaming/include/lar.h        (Arbeitskopie)
@@ -74,6 +74,24 @@
        u64 loadaddress;
 };
 
+enum compalgo {
+       none = 0,
+       lzma = 1,
+       nrv2b = 2,
+       zeroes = 3,
+       /* invalid should always be the last entry. */
+       invalid
+};
+
+static const char *algo_name[] = {
+       "",
+       "lzma",
+       "nrv2b",
+       "zeroes",
+       /* invalid should always be the last entry. */
+       "invalid"
+};
+
 struct mem_file {
        void *start;
        int len;
Index: LinuxBIOSv3-algonaming/lib/lar.c
===================================================================
--- LinuxBIOSv3-algonaming/lib/lar.c    (Revision 605)
+++ LinuxBIOSv3-algonaming/lib/lar.c    (Arbeitskopie)
@@ -147,36 +147,41 @@
 
 int process_file(const struct mem_file *archive, void *where)
 {
-       printk(BIOS_SPEW, "LAR: Compression algorithm #%i used\n", 
archive->compression);
+       const char *algoname = algo_name[(archive->compression >= invalid)
+                                       ? invalid : archive->compression];
+       printk(BIOS_SPEW, "LAR: Compression algorithm #%i (%s) used\n",
+               archive->compression, algoname);
+       switch (archive->compression) {
        /* no compression */
-       if (archive->compression == 0) {
+       case none:
                memcpy(where, archive->start, archive->len);
                return 0;
-       }
 #ifdef CONFIG_COMPRESSION_LZMA
        /* lzma */
-       unsigned long ulzma(unsigned char *src, unsigned char *dst);
-       if (archive->compression == 1) {
+       case lzma: {
+               unsigned long ulzma(unsigned char *src, unsigned char *dst);
                ulzma(archive->start, where);
                return 0;
        }
 #endif
 #ifdef CONFIG_COMPRESSION_NRV2B
        /* nrv2b */
-       unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
-       if (archive->compression == 2) {
+       case nrv2b: {
+               unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
                unsigned long tmp;
                unrv2b(archive->start, where, &tmp);
                return 0;
        }
 #endif
        /* zeroes */
-       if (archive->compression == 3) {
+       case zeroes:
                memset(where, 0, archive->reallen);
                return 0;
+       default:
+               printk(BIOS_INFO, "LAR: Compression algorithm #%i (%s) not"
+                       " supported!\n", archive->compression, algoname);
+               return -1;
        }
-       printk(BIOS_INFO, "LAR: Compression algorithm #%i not supported!\n", 
archive->compression);
-       return -1;
 }
 
 /**
Index: LinuxBIOSv3-algonaming/util/lar/lar.h
===================================================================
--- LinuxBIOSv3-algonaming/util/lar/lar.h       (Revision 605)
+++ LinuxBIOSv3-algonaming/util/lar/lar.h       (Arbeitskopie)
@@ -92,7 +92,14 @@
        u32 size; /**< Size of the mmaped file */
 };
 
-enum compalgo { none = 0, lzma = 1, nrv2b = 2, zeroes = 3 };
+enum compalgo {
+       none = 0,
+       lzma = 1,
+       nrv2b = 2,
+       zeroes = 3,
+       /* invalid should always be the last entry. */
+       invalid
+};
 
 typedef void (*compress_func) (char *, int, char *, int *);
 typedef void (*uncompress_func) (char *, int, char *, int);
@@ -128,4 +135,6 @@
        "lzma",
        "nrv2b",
        "zeroes",
+       /* invalid should always be the last entry. */
+       "invalid"
 };




-- 
http://www.hailfinger.org/


-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to