mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
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 <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://coreboot.org/repository/coreboot-v3@606 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
9f07a52934
commit
24d743968a
5 changed files with 53 additions and 21 deletions
|
@ -74,6 +74,15 @@ struct lar_header {
|
||||||
u64 loadaddress;
|
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 {
|
struct mem_file {
|
||||||
void *start;
|
void *start;
|
||||||
int len;
|
int len;
|
||||||
|
|
34
lib/lar.c
34
lib/lar.c
|
@ -31,6 +31,15 @@
|
||||||
#define ntohl(x) (x)
|
#define ntohl(x) (x)
|
||||||
#endif
|
#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
|
* run_address is passed the address of a function taking no parameters and
|
||||||
* jumps to it, returning the result.
|
* 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)
|
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 */
|
/* no compression */
|
||||||
if (archive->compression == 0) {
|
case ALGO_NONE:
|
||||||
memcpy(where, archive->start, archive->len);
|
memcpy(where, archive->start, archive->len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
#ifdef CONFIG_COMPRESSION_LZMA
|
#ifdef CONFIG_COMPRESSION_LZMA
|
||||||
/* lzma */
|
/* lzma */
|
||||||
unsigned long ulzma(unsigned char *src, unsigned char *dst);
|
case ALGO_LZMA: {
|
||||||
if (archive->compression == 1) {
|
unsigned long ulzma(unsigned char *src, unsigned char *dst);
|
||||||
ulzma(archive->start, where);
|
ulzma(archive->start, where);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_COMPRESSION_NRV2B
|
#ifdef CONFIG_COMPRESSION_NRV2B
|
||||||
/* nrv2b */
|
/* nrv2b */
|
||||||
unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
|
case ALGO_NRV2B: {
|
||||||
if (archive->compression == 2) {
|
unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
|
||||||
unsigned long tmp;
|
unsigned long tmp;
|
||||||
unrv2b(archive->start, where, &tmp);
|
unrv2b(archive->start, where, &tmp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* zeroes */
|
/* zeroes */
|
||||||
if (archive->compression == 3) {
|
case ALGO_ZEROES:
|
||||||
memset(where, 0, archive->reallen);
|
memset(where, 0, archive->reallen);
|
||||||
return 0;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ static int isverbose = 0;
|
||||||
static int iselfparse = 0;
|
static int iselfparse = 0;
|
||||||
static long larsize = 0;
|
static long larsize = 0;
|
||||||
static char *bootblock = NULL;
|
static char *bootblock = NULL;
|
||||||
enum compalgo algo = none;
|
enum compalgo algo = ALGO_NONE;
|
||||||
|
|
||||||
static void usage(char *name)
|
static void usage(char *name)
|
||||||
{
|
{
|
||||||
|
@ -272,10 +272,10 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if (strcasecmp("lzma", optarg) == 0) {
|
if (strcasecmp("lzma", optarg) == 0) {
|
||||||
algo = lzma;
|
algo = ALGO_LZMA;
|
||||||
}
|
}
|
||||||
if (strcasecmp("nrv2b", optarg) == 0) {
|
if (strcasecmp("nrv2b", optarg) == 0) {
|
||||||
algo = nrv2b;
|
algo = ALGO_NRV2B;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
|
|
|
@ -92,7 +92,14 @@ struct lar {
|
||||||
u32 size; /**< Size of the mmaped file */
|
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 (*compress_func) (char *, int, char *, int *);
|
||||||
typedef void (*uncompress_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[] = {
|
static const char *algo_name[] = {
|
||||||
"",
|
"none",
|
||||||
"lzma",
|
"lzma",
|
||||||
"nrv2b",
|
"nrv2b",
|
||||||
"zeroes",
|
"zeroes",
|
||||||
|
/* invalid should always be the last entry. */
|
||||||
|
"invalid"
|
||||||
};
|
};
|
||||||
|
|
|
@ -147,7 +147,7 @@ int output_elf_segments(struct lar *lar, char *name, char *filebuf,
|
||||||
fprintf(stderr, "Dropping empty section\n");
|
fprintf(stderr, "Dropping empty section\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
thisalgo = zeroes;
|
thisalgo = ALGO_ZEROES;
|
||||||
if (verbose())
|
if (verbose())
|
||||||
fprintf(stderr, "New section addr %#x size %#x\n",
|
fprintf(stderr, "New section addr %#x size %#x\n",
|
||||||
(u32)shdr[i].sh_addr, (u32)shdr[i].sh_size);
|
(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)) {
|
if (file_in_list(files, filename)) {
|
||||||
printf(" %s ", filename);
|
printf(" %s ", filename);
|
||||||
|
|
||||||
if (ntohl(header->compression) == none) {
|
if (ntohl(header->compression) == ALGO_NONE) {
|
||||||
printf("(%d bytes @0x%lx);",
|
printf("(%d bytes @0x%lx);",
|
||||||
ntohl(header->len),
|
ntohl(header->len),
|
||||||
(unsigned long)(ptr - lar->map) +
|
(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 (file_in_list(files, filename)) {
|
||||||
|
|
||||||
if (ntohl(header->compression) == none) {
|
if (ntohl(header->compression) == ALGO_NONE) {
|
||||||
ret = _write_file(filename,
|
ret = _write_file(filename,
|
||||||
(u8 *) (ptr + ntohl(header->offset)),
|
(u8 *) (ptr + ntohl(header->offset)),
|
||||||
(u32) ntohl(header->len));
|
(u32) ntohl(header->len));
|
||||||
|
@ -730,7 +730,7 @@ int lar_process_name(char *name, char **pfilename, char **ppathname,
|
||||||
|
|
||||||
if (!strncmp(name, "nocompress:",11)) {
|
if (!strncmp(name, "nocompress:",11)) {
|
||||||
filename += 11;
|
filename += 11;
|
||||||
*thisalgo = none;
|
*thisalgo = ALGO_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is dangerous */
|
/* this is dangerous */
|
||||||
|
@ -846,8 +846,8 @@ int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo)
|
||||||
int complen;
|
int complen;
|
||||||
compress_functions[*thisalgo](ptr, size, temp, &complen);
|
compress_functions[*thisalgo](ptr, size, temp, &complen);
|
||||||
|
|
||||||
if (complen >= size && (*thisalgo != none)) {
|
if (complen >= size && (*thisalgo != ALGO_NONE)) {
|
||||||
*thisalgo = none;
|
*thisalgo = ALGO_NONE;
|
||||||
compress_functions[*thisalgo](ptr, size, temp, &complen);
|
compress_functions[*thisalgo](ptr, size, temp, &complen);
|
||||||
}
|
}
|
||||||
return complen;
|
return complen;
|
||||||
|
|
Loading…
Add table
Reference in a new issue