Author: hailfinger
Date: 2008-02-18 01:48:25 +0100 (Mon, 18 Feb 2008)
New Revision: 606

Modified:
   coreboot-v3/include/lar.h
   coreboot-v3/lib/lar.c
   coreboot-v3/util/lar/lar.c
   coreboot-v3/util/lar/lar.h
   coreboot-v3/util/lar/stream.c
Log:
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.

Uppercasing enum compalgo also found a name clash between NONE as 
compression algo and NONE as operation mode of util/lar.

Compile and boot tested on Qemu.

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


Modified: coreboot-v3/include/lar.h
===================================================================
--- coreboot-v3/include/lar.h   2008-02-16 19:18:32 UTC (rev 605)
+++ coreboot-v3/include/lar.h   2008-02-18 00:48:25 UTC (rev 606)
@@ -74,6 +74,15 @@
        u64 loadaddress;
 };
 
+enum compalgo {
+       ALGO_NONE = 0,
+       ALGO_LZMA = 1,
+       ALGO_NRV2B = 2,
+       ALGO_ZEROES = 3,
+       /* invalid should always be the last entry. */
+       ALGO_INVALID
+};
+
 struct mem_file {
        void *start;
        int len;

Modified: coreboot-v3/lib/lar.c
===================================================================
--- coreboot-v3/lib/lar.c       2008-02-16 19:18:32 UTC (rev 605)
+++ coreboot-v3/lib/lar.c       2008-02-18 00:48:25 UTC (rev 606)
@@ -31,6 +31,15 @@
 #define ntohl(x) (x)
 #endif
 
+static const char *algo_name[] = {
+       "none",
+       "lzma",
+       "nrv2b",
+       "zeroes",
+       /* invalid should always be the last entry. */
+       "invalid"
+};
+
 /**
  * run_address is passed the address of a function taking no parameters and
  * jumps to it, returning the result. 
@@ -147,36 +156,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 >= ALGO_INVALID)
+                                       ? ALGO_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 ALGO_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 ALGO_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 ALGO_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 ALGO_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;
 }
 
 /**

Modified: coreboot-v3/util/lar/lar.c
===================================================================
--- coreboot-v3/util/lar/lar.c  2008-02-16 19:18:32 UTC (rev 605)
+++ coreboot-v3/util/lar/lar.c  2008-02-18 00:48:25 UTC (rev 606)
@@ -40,7 +40,7 @@
 static int iselfparse = 0;
 static long larsize = 0;
 static char *bootblock = NULL;
-enum compalgo algo = none;
+enum compalgo algo = ALGO_NONE;
 
 static void usage(char *name)
 {
@@ -272,10 +272,10 @@
                        break;
                case 'C':
                        if (strcasecmp("lzma", optarg) == 0) {
-                               algo = lzma;
+                               algo = ALGO_LZMA;
                        }
                        if (strcasecmp("nrv2b", optarg) == 0) {
-                               algo = nrv2b;
+                               algo = ALGO_NRV2B;
                        }
                        break;
                case 'l':

Modified: coreboot-v3/util/lar/lar.h
===================================================================
--- coreboot-v3/util/lar/lar.h  2008-02-16 19:18:32 UTC (rev 605)
+++ coreboot-v3/util/lar/lar.h  2008-02-18 00:48:25 UTC (rev 606)
@@ -92,7 +92,14 @@
        u32 size; /**< Size of the mmaped file */
 };
 
-enum compalgo { none = 0, lzma = 1, nrv2b = 2, zeroes = 3 };
+enum compalgo {
+       ALGO_NONE = 0,
+       ALGO_LZMA = 1,
+       ALGO_NRV2B = 2,
+       ALGO_ZEROES = 3,
+       /* invalid should always be the last entry. */
+       ALGO_INVALID
+};
 
 typedef void (*compress_func) (char *, int, char *, int *);
 typedef void (*uncompress_func) (char *, int, char *, int);
@@ -124,8 +131,10 @@
 };
 
 static const char *algo_name[] = {
-       "",
+       "none",
        "lzma",
        "nrv2b",
        "zeroes",
+       /* invalid should always be the last entry. */
+       "invalid"
 };

Modified: coreboot-v3/util/lar/stream.c
===================================================================
--- coreboot-v3/util/lar/stream.c       2008-02-16 19:18:32 UTC (rev 605)
+++ coreboot-v3/util/lar/stream.c       2008-02-18 00:48:25 UTC (rev 606)
@@ -147,7 +147,7 @@
                                fprintf(stderr, "Dropping empty section\n");
                        continue;
                }
-               thisalgo = zeroes;
+               thisalgo = ALGO_ZEROES;
                if (verbose())
                        fprintf(stderr,  "New section addr %#x size %#x\n",
                        (u32)shdr[i].sh_addr, (u32)shdr[i].sh_size);
@@ -565,7 +565,7 @@
                if (file_in_list(files, filename)) {
                        printf("  %s ", filename);
 
-                       if (ntohl(header->compression) == none) {
+                       if (ntohl(header->compression) == ALGO_NONE) {
                                printf("(%d bytes @0x%lx);",
                                       ntohl(header->len),
                                       (unsigned long)(ptr - lar->map) +
@@ -669,7 +669,7 @@
 
                if (file_in_list(files, filename)) {
 
-                       if (ntohl(header->compression) == none) {
+                       if (ntohl(header->compression) == ALGO_NONE) {
                                ret = _write_file(filename,
                                                  (u8 *) (ptr + 
ntohl(header->offset)),
                                                  (u32) ntohl(header->len));
@@ -730,7 +730,7 @@
 
        if (!strncmp(name, "nocompress:",11)) {
                filename += 11;
-               *thisalgo = none;
+               *thisalgo = ALGO_NONE;
        }
 
        /* this is dangerous */
@@ -846,8 +846,8 @@
        int complen;
        compress_functions[*thisalgo](ptr, size, temp, &complen);
 
-       if (complen >= size && (*thisalgo != none)) {
-               *thisalgo = none;
+       if (complen >= size && (*thisalgo != ALGO_NONE)) {
+               *thisalgo = ALGO_NONE;
                compress_functions[*thisalgo](ptr, size, temp, &complen);
        }
        return complen;


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

Reply via email to