From 24d743968a20f5bfa6601cb2b6e31cdae3ff1c2f Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Mon, 18 Feb 2008 00:48:25 +0000 Subject: [PATCH] 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 Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/coreboot-v3@606 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- include/lar.h | 9 +++++++++ lib/lar.c | 34 ++++++++++++++++++++++++---------- util/lar/lar.c | 6 +++--- util/lar/lar.h | 13 +++++++++++-- util/lar/stream.c | 12 ++++++------ 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/include/lar.h b/include/lar.h index 9b0914023a..1c15d79577 100644 --- a/include/lar.h +++ b/include/lar.h @@ -74,6 +74,15 @@ struct lar_header { 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; diff --git a/lib/lar.c b/lib/lar.c index 7a497dc989..3f558c166a 100644 --- a/lib/lar.c +++ b/lib/lar.c @@ -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 find_file(const struct mem_file *archive, const char *filename, struct mem_f 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; } /** diff --git a/util/lar/lar.c b/util/lar/lar.c index 987e954183..1a03d9129f 100644 --- a/util/lar/lar.c +++ b/util/lar/lar.c @@ -40,7 +40,7 @@ static int isverbose = 0; 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 @@ int main(int argc, char *argv[]) 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': diff --git a/util/lar/lar.h b/util/lar/lar.h index 28e670fa33..411c74a722 100644 --- a/util/lar/lar.h +++ b/util/lar/lar.h @@ -92,7 +92,14 @@ struct lar { 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 uncompress_func uncompress_functions[] = { }; static const char *algo_name[] = { - "", + "none", "lzma", "nrv2b", "zeroes", + /* invalid should always be the last entry. */ + "invalid" }; diff --git a/util/lar/stream.c b/util/lar/stream.c index 0b9f766189..fc6cc452bf 100644 --- a/util/lar/stream.c +++ b/util/lar/stream.c @@ -147,7 +147,7 @@ int output_elf_segments(struct lar *lar, char *name, char *filebuf, 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 @@ void lar_list_files(struct lar *lar, struct file *files) 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 @@ int lar_extract_files(struct lar *lar, struct file *files) 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 @@ int lar_process_name(char *name, char **pfilename, char **ppathname, if (!strncmp(name, "nocompress:",11)) { filename += 11; - *thisalgo = none; + *thisalgo = ALGO_NONE; } /* this is dangerous */ @@ -846,8 +846,8 @@ int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo) 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;