mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
Create a file-local process_file() function which has
the common parts of copy_file() and run_file(). Signed-off-by: Alex Beregszaszi <alex@rtfs.hu> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@497 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
872be1d31b
commit
b21bb44f50
1 changed files with 34 additions and 50 deletions
84
lib/lar.c
84
lib/lar.c
|
@ -123,6 +123,35 @@ int find_file(struct mem_file *archive, const char *filename, struct mem_file *r
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int process_file(struct mem_file *archive, void *where)
|
||||
{
|
||||
printk(BIOS_SPEW, "LAR: Compression algorithm #%i used\n", archive->compression);
|
||||
/* no compression */
|
||||
if (archive->compression == 0) {
|
||||
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) {
|
||||
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) {
|
||||
unsigned long tmp;
|
||||
unrv2b(archive->start, where, &tmp);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
printk(BIOS_INFO, "LAR: Compression algorithm #%i not supported!\n", archive->compression);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a file name in the LAR , search for it, and load it into memory, using
|
||||
* the loadaddress pointer in the mem_file struct.
|
||||
|
@ -146,34 +175,13 @@ void *load_file(struct mem_file *archive, const char *filename)
|
|||
}
|
||||
entry = result.entry;
|
||||
where = result.loadaddress;
|
||||
printk(BIOS_SPEW, "LAR: Compression algorithm #%i used\n", result.compression);
|
||||
/* no compression */
|
||||
if (result.compression == 0) {
|
||||
memcpy(where, result.start, result.len);
|
||||
return entry;
|
||||
}
|
||||
#ifdef CONFIG_COMPRESSION_LZMA
|
||||
/* lzma */
|
||||
unsigned long ulzma(unsigned char *src, unsigned char *dst);
|
||||
if (result.compression == 1) {
|
||||
ulzma(result.start, where);
|
||||
return entry;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_COMPRESSION_NRV2B
|
||||
/* nrv2b */
|
||||
unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
|
||||
if (result.compression == 2) {
|
||||
int tmp;
|
||||
unrv2b(result.start, where, &tmp);
|
||||
return entry;
|
||||
}
|
||||
#endif
|
||||
printk(BIOS_INFO, "LAR: Compression algorithm #%i not supported!\n", result.compression);
|
||||
|
||||
if (process_file(&result, where) == 0)
|
||||
return entry;
|
||||
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
/* FIXME -- most of copy_file should be replaced by load_file */
|
||||
/**
|
||||
* Given a file name in the LAR , search for it, and load it into memory,
|
||||
* using the passed-in pointer as the address
|
||||
|
@ -194,31 +202,7 @@ int copy_file(struct mem_file *archive, const char *filename, void *where)
|
|||
return 1;
|
||||
}
|
||||
|
||||
printk(BIOS_SPEW, "LAR: Compression algorithm #%i used\n", result.compression);
|
||||
/* no compression */
|
||||
if (result.compression == 0) {
|
||||
memcpy(where, result.start, result.len);
|
||||
return 0;
|
||||
}
|
||||
#ifdef CONFIG_COMPRESSION_LZMA
|
||||
/* lzma */
|
||||
unsigned long ulzma(unsigned char *src, unsigned char *dst);
|
||||
if (result.compression == 1) {
|
||||
ulzma(result.start, where);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_COMPRESSION_NRV2B
|
||||
/* nrv2b */
|
||||
unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p);
|
||||
if (result.compression == 2) {
|
||||
int tmp;
|
||||
unrv2b(result.start, where, &tmp);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
printk(BIOS_INFO, "LAR: Compression algorithm #%i not supported!\n", result.compression);
|
||||
return 1;
|
||||
return process_file(&result, where);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue