1 #include <console/console.h>
4 #include <stream/read_bytes.h>
7 /* if they set the precompressed rom stream, they better have set a type */
8 #if CONFIG_PRECOMPRESSED_PAYLOAD && ((!CONFIG_COMPRESSED_PAYLOAD_NRV2B) && (!CONFIG_COMPRESSED_PAYLOAD_LZMA))
9 #error "You set CONFIG_PRECOMPRESSED_PAYLOAD but need to set CONFIG_COMPRESSED_PAYLOAD_NRV2B or CONFIG_COMPRESSED_PAYLOAD_LZMA"
12 /* If they set ANY of these, then we're compressed */
13 #if ((CONFIG_COMPRESSED_PAYLOAD_NRV2B) || (CONFIG_COMPRESSED_PAYLOAD_LZMA))
14 #define UNCOMPRESSER 1
15 extern unsigned char _heap, _eheap;
18 #if (CONFIG_COMPRESSED_PAYLOAD_NRV2B)
19 #define HAVE_UNCOMPRESSER 1
20 #include "../lib/nrv2b.c"
23 #if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
24 #ifdef HAVE_UNCOMPRESSER
25 #error "You're defining more than one compression type, which is not allowed."
27 #define HAVE_UNCOMPRESSER 1
28 unsigned long ulzma(unsigned char *src, unsigned char *dst);
31 #ifndef CONFIG_ROM_PAYLOAD_START
32 #define CONFIG_ROM_PAYLOAD_START 0xffff0000UL
35 /* well, this is a mess, and it will get fixed, but not right away.
36 * until we stop using 'ld' for building the rom image, that is.
37 * problem is, that on the sc520, ROM_PAYLOAD_START has to be at 0x2000000.
38 * but if you set CONFIG_ROM_PAYLOAD_START to that, then ld will try to
39 * build a giant image: 0x0-0x2000000, i.e. almost 4 GB.
40 * so make this non-static, non-const for now.
44 unsigned char *rom_start = (unsigned char *)CONFIG_ROM_PAYLOAD_START;
45 unsigned char *rom_end = (unsigned char *)(CONFIG_ROM_PAYLOAD_START + CONFIG_PAYLOAD_SIZE - 1);
48 static const unsigned char *rom;
52 uncompress(uint8_t * start_addr, uint8_t *dest_addr)
54 #if (CONFIG_COMPRESSED_PAYLOAD_NRV2B)
55 unsigned long ilen; // used compressed stream length
56 return unrv2b(start_addr, dest_addr, &ilen);
58 #if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
59 return ulzma(start_addr, dest_addr);
71 printk_debug("rom_stream: 0x%08lx - 0x%08lx\n",
72 (unsigned long)rom_start,
73 (unsigned long)rom_end);
77 dest = &_eheap; /* need a good address on RAM */
79 #if CONFIG_RAMBASE<0x00100000
80 olen = *(unsigned int *)dest;
81 #if (CONFIG_CONSOLE_VGA==1) || (CONFIG_PCI_ROM_RUN == 1)
82 if((dest < (unsigned char *)0xa0000) && ((dest+olen)>(unsigned char *)0xa0000)) {
83 dest = (unsigned char *)(CONFIG_LB_MEM_TOPK<<10);
86 if((dest < (unsigned char *) 0xf0000) && ((dest+olen)> (unsigned char *)0xf0000)) { // coreboot tables etc
87 dest = (unsigned char *) (CONFIG_LB_MEM_TOPK<<10);
91 /* ALL of those settings are too smart and also unsafe. Set the dest to 16 MB:
92 * known to be safe for LB for now, and mostly safe for all elf images we have tried.
93 * long term, this has got to be fixed.
95 dest = (unsigned char *) (16 * 1024 * 1024);
96 printk_debug("Uncompressing to RAM %p ", dest);
97 olen = uncompress((uint8_t *) rom_start, (uint8_t *)dest );
98 printk_debug(" olen = 0x%08lx done.\n", olen);
100 rom_end = dest + olen - 1;
103 /* Decompression failed, assume payload is uncompressed */
104 printk_debug("Decompression failed. Assuming payload is uncompressed...\n");
115 void stream_fini(void)
120 byte_offset_t stream_skip(byte_offset_t count)
124 if ((rom + bytes - 1) > rom_end) {
125 printk_warning("%6d:%s() - overflowed source buffer\n",
128 if (rom <= rom_end) {
129 bytes = (rom_end - rom) + 1;
136 byte_offset_t stream_read(void *vdest, byte_offset_t count)
138 unsigned char *dest = vdest;
139 const unsigned char *src = rom;
142 bytes = stream_skip(count);
143 memcpy(dest, src, bytes);