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 generic nrv2b
21 #include "../lib/nrv2b.c"
24 #if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
26 #error "You're defining more than one compression type, which is not allowed (of course)"
28 #define HAVE_UNCOMPRESSER 1
29 // include generic nrv2b
30 #include "../lib/lzma.c"
33 #ifndef CONFIG_ROM_PAYLOAD_START
34 #define CONFIG_ROM_PAYLOAD_START 0xffff0000UL
37 /* well, this is a mess, and it will get fixed, but not right away.
38 * until we stop using 'ld' for building the rom image, that is.
39 * problem is, that on the sc520, ROM_PAYLOAD_START has to be at 0x2000000.
40 * but if you set CONFIG_ROM_PAYLOAD_START to that, then ld will try to
41 * build a giant image: 0x0-0x2000000, i.e. almost 4 GB.
42 * so make this non-static, non-const for now.
46 /*static const */unsigned char *rom_start = (unsigned char *)CONFIG_ROM_PAYLOAD_START;
47 /*static const */unsigned char *rom_end = (unsigned char *)(CONFIG_ROM_PAYLOAD_START + PAYLOAD_SIZE - 1);
50 static const unsigned char *rom;
54 uncompress(uint8_t * rom_start, uint8_t *dest )
56 #if (CONFIG_COMPRESSED_PAYLOAD_NRV2B)
57 unsigned long ilen; // used compressed stream length
58 return unrv2b(rom_start, dest, &ilen);
60 #if (CONFIG_COMPRESSED_PAYLOAD_LZMA)
61 return ulzma(rom_start, dest);
72 printk_debug("rom_stream: 0x%08lx - 0x%08lx\n",
73 (unsigned long)rom_start,
74 (unsigned long)rom_end);
78 dest = &_eheap; /* need a good address on RAM */
80 #if _RAMBASE<0x00100000
81 olen = *(unsigned int *)dest;
82 #if (CONFIG_CONSOLE_VGA==1) || (CONFIG_PCI_ROM_RUN == 1)
83 if((dest < 0xa0000) && ((dest+olen)>0xa0000)) {
84 dest = (CONFIG_LB_MEM_TOPK<<10);
87 if((dest < (unsigned char *) 0xf0000) && ((dest+olen)> (unsigned char *)0xf0000)) { // coreboot tables etc
88 dest = (unsigned char *) (CONFIG_LB_MEM_TOPK<<10);
92 /* ALL of those settings are too smart and also unsafe. Set the dest to 16 MB:
93 * known to be safe for LB for now, and mostly safe for all elf images we have tried.
94 * long term, this has got to be fixed.
96 dest = (unsigned char *) (16 * 1024 * 1024);
97 printk_debug("Uncompressing to RAM 0x%08lx ", dest);
98 olen = uncompress((uint8_t *) rom_start, (uint8_t *)dest );
99 printk_debug(" olen = 0x%08lx done.\n", olen);
100 rom_end = dest + olen - 1;
110 void stream_fini(void)
115 byte_offset_t stream_skip(byte_offset_t count)
119 if ((rom + bytes - 1) > rom_end) {
120 printk_warning("%6d:%s() - overflowed source buffer\n",
121 __LINE__, __FUNCTION__);
123 if (rom <= rom_end) {
124 bytes = (rom_end - rom) + 1;
131 byte_offset_t stream_read(void *vdest, byte_offset_t count)
133 unsigned char *dest = vdest;
134 const unsigned char *src = rom;
137 bytes = stream_skip(count);
138 memcpy(dest, src, bytes);