2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stream/read_bytes.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-09-14 17:12:36 +02:00
|
|
|
/* if they set the precompressed rom stream, they better have set a type */
|
2006-12-15 12:42:16 +01:00
|
|
|
#if CONFIG_PRECOMPRESSED_PAYLOAD && ((!CONFIG_COMPRESSED_PAYLOAD_NRV2B) && (!CONFIG_COMPRESSED_PAYLOAD_LZMA))
|
|
|
|
#error "You set CONFIG_PRECOMPRESSED_PAYLOAD but need to set CONFIG_COMPRESSED_PAYLOAD_NRV2B or CONFIG_COMPRESSED_PAYLOAD_LZMA"
|
2006-09-14 17:12:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If they set ANY of these, then we're compressed */
|
2006-12-15 12:42:16 +01:00
|
|
|
#if ((CONFIG_COMPRESSED_PAYLOAD_NRV2B) || (CONFIG_COMPRESSED_PAYLOAD_LZMA))
|
2006-09-14 17:12:36 +02:00
|
|
|
#define UNCOMPRESSER 1
|
|
|
|
extern unsigned char _heap, _eheap;
|
|
|
|
#endif
|
|
|
|
|
2006-12-15 12:42:16 +01:00
|
|
|
#if (CONFIG_COMPRESSED_PAYLOAD_NRV2B)
|
2006-09-14 17:12:36 +02:00
|
|
|
#define HAVE_UNCOMPRESSER 1
|
2006-05-04 02:47:15 +02:00
|
|
|
// include generic nrv2b
|
|
|
|
#include "../lib/nrv2b.c"
|
2006-09-14 17:12:36 +02:00
|
|
|
#endif
|
|
|
|
|
2006-12-15 12:42:16 +01:00
|
|
|
#if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
|
2006-09-14 17:12:36 +02:00
|
|
|
#if HAVE_UNCOMPRESSER
|
|
|
|
#error "You're defining more than one compression type, which is not allowed (of course)"
|
|
|
|
#endif
|
|
|
|
#define HAVE_UNCOMPRESSER 1
|
2008-08-27 23:53:11 +02:00
|
|
|
// include generic lzma
|
2006-09-14 17:12:36 +02:00
|
|
|
#include "../lib/lzma.c"
|
2006-05-04 02:47:15 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2006-12-15 13:56:28 +01:00
|
|
|
#ifndef CONFIG_ROM_PAYLOAD_START
|
|
|
|
#define CONFIG_ROM_PAYLOAD_START 0xffff0000UL
|
2003-04-22 21:02:15 +02:00
|
|
|
#endif
|
|
|
|
|
2006-05-04 02:47:15 +02:00
|
|
|
/* well, this is a mess, and it will get fixed, but not right away.
|
|
|
|
* until we stop using 'ld' for building the rom image, that is.
|
2006-12-15 13:56:28 +01:00
|
|
|
* problem is, that on the sc520, ROM_PAYLOAD_START has to be at 0x2000000.
|
|
|
|
* but if you set CONFIG_ROM_PAYLOAD_START to that, then ld will try to
|
2006-05-04 02:47:15 +02:00
|
|
|
* build a giant image: 0x0-0x2000000, i.e. almost 4 GB.
|
|
|
|
* so make this non-static, non-const for now.
|
2005-09-23 19:08:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*XXXXXXXXXXXXXX */
|
2006-12-15 13:56:28 +01:00
|
|
|
/*static const */unsigned char *rom_start = (unsigned char *)CONFIG_ROM_PAYLOAD_START;
|
|
|
|
/*static const */unsigned char *rom_end = (unsigned char *)(CONFIG_ROM_PAYLOAD_START + PAYLOAD_SIZE - 1);
|
2005-09-23 19:08:58 +02:00
|
|
|
/*XXXXXXXXXXXXXX */
|
2006-05-04 02:47:15 +02:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
static const unsigned char *rom;
|
|
|
|
|
2006-09-14 17:12:36 +02:00
|
|
|
#if UNCOMPRESSER
|
|
|
|
unsigned long
|
|
|
|
uncompress(uint8_t * rom_start, uint8_t *dest )
|
|
|
|
{
|
2006-12-15 12:42:16 +01:00
|
|
|
#if (CONFIG_COMPRESSED_PAYLOAD_NRV2B)
|
2006-10-04 22:46:15 +02:00
|
|
|
unsigned long ilen; // used compressed stream length
|
|
|
|
return unrv2b(rom_start, dest, &ilen);
|
2006-09-14 17:12:36 +02:00
|
|
|
#endif
|
2006-12-15 12:42:16 +01:00
|
|
|
#if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
|
2006-09-14 17:12:36 +02:00
|
|
|
return ulzma(rom_start, dest);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
int stream_init(void)
|
|
|
|
{
|
2006-09-14 17:12:36 +02:00
|
|
|
#if (UNCOMPRESSER)
|
2006-05-18 05:07:16 +02:00
|
|
|
unsigned char *dest;
|
2006-05-04 02:47:15 +02:00
|
|
|
unsigned long olen;
|
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2006-05-04 02:47:15 +02:00
|
|
|
printk_debug("rom_stream: 0x%08lx - 0x%08lx\n",
|
2003-04-22 21:02:15 +02:00
|
|
|
(unsigned long)rom_start,
|
|
|
|
(unsigned long)rom_end);
|
2006-05-04 02:47:15 +02:00
|
|
|
|
2006-09-14 17:12:36 +02:00
|
|
|
#if (UNCOMPRESSER)
|
2006-05-04 02:47:15 +02:00
|
|
|
|
|
|
|
dest = &_eheap; /* need a good address on RAM */
|
|
|
|
|
|
|
|
#if _RAMBASE<0x00100000
|
|
|
|
olen = *(unsigned int *)dest;
|
|
|
|
#if (CONFIG_CONSOLE_VGA==1) || (CONFIG_PCI_ROM_RUN == 1)
|
2008-08-01 13:48:00 +02:00
|
|
|
if((dest < (unsigned char *)0xa0000) && ((dest+olen)>(unsigned char *)0xa0000)) {
|
|
|
|
dest = (unsigned char *)(CONFIG_LB_MEM_TOPK<<10);
|
2006-05-04 02:47:15 +02:00
|
|
|
}
|
|
|
|
#endif
|
2008-01-18 16:08:58 +01:00
|
|
|
if((dest < (unsigned char *) 0xf0000) && ((dest+olen)> (unsigned char *)0xf0000)) { // coreboot tables etc
|
2006-05-18 05:07:16 +02:00
|
|
|
dest = (unsigned char *) (CONFIG_LB_MEM_TOPK<<10);
|
2006-05-04 02:47:15 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-14 17:12:36 +02:00
|
|
|
/* ALL of those settings are too smart and also unsafe. Set the dest to 16 MB:
|
|
|
|
* known to be safe for LB for now, and mostly safe for all elf images we have tried.
|
|
|
|
* long term, this has got to be fixed.
|
|
|
|
*/
|
|
|
|
dest = (unsigned char *) (16 * 1024 * 1024);
|
2009-04-03 17:02:08 +02:00
|
|
|
printk_debug("Uncompressing to RAM %p ", dest);
|
2006-09-14 17:12:36 +02:00
|
|
|
olen = uncompress((uint8_t *) rom_start, (uint8_t *)dest );
|
2006-05-18 05:07:16 +02:00
|
|
|
printk_debug(" olen = 0x%08lx done.\n", olen);
|
2008-08-27 23:53:11 +02:00
|
|
|
if (olen != 0) {
|
|
|
|
rom_end = dest + olen - 1;
|
|
|
|
rom = dest;
|
|
|
|
} else {
|
|
|
|
/* Decompression failed, assume payload is uncompressed */
|
|
|
|
printk_debug("Decompression failed. Assuming payload is uncompressed...\n");
|
|
|
|
rom = rom_start;
|
|
|
|
}
|
2006-05-04 02:47:15 +02:00
|
|
|
#else
|
|
|
|
rom = rom_start;
|
|
|
|
#endif
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void stream_fini(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_offset_t stream_skip(byte_offset_t count)
|
|
|
|
{
|
|
|
|
byte_offset_t bytes;
|
|
|
|
bytes = count;
|
2007-02-03 11:43:48 +01:00
|
|
|
if ((rom + bytes - 1) > rom_end) {
|
2003-04-22 21:02:15 +02:00
|
|
|
printk_warning("%6d:%s() - overflowed source buffer\n",
|
2009-02-12 22:30:06 +01:00
|
|
|
__LINE__, __func__);
|
2003-04-22 21:02:15 +02:00
|
|
|
bytes = 0;
|
|
|
|
if (rom <= rom_end) {
|
|
|
|
bytes = (rom_end - rom) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rom += bytes;
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_offset_t stream_read(void *vdest, byte_offset_t count)
|
|
|
|
{
|
|
|
|
unsigned char *dest = vdest;
|
|
|
|
const unsigned char *src = rom;
|
|
|
|
byte_offset_t bytes;
|
|
|
|
|
|
|
|
bytes = stream_skip(count);
|
|
|
|
memcpy(dest, src, bytes);
|
|
|
|
return bytes;
|
|
|
|
}
|