Add serial stream payload support from Ed Swierk <eswierk@arastra.com>
X-Signed-Off-By: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2447 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
197a4a8dbb
commit
ebafa4df42
5 changed files with 311 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ uses CONFIG_ROM_STREAM
|
|||
uses CONFIG_IDE_STREAM
|
||||
uses CONFIG_FS_STREAM
|
||||
uses CONFIG_IDE
|
||||
uses CONFIG_SERIAL_STREAM
|
||||
|
||||
if CONFIG_ROM_STREAM
|
||||
object rom_stream.o
|
||||
|
|
@ -16,3 +17,7 @@ if CONFIG_FS_STREAM
|
|||
object fs_stream.o
|
||||
dir fs
|
||||
end
|
||||
|
||||
if CONFIG_SERIAL_STREAM
|
||||
object serial_stream.o
|
||||
end
|
||||
|
|
|
|||
92
src/stream/serial_stream.c
Normal file
92
src/stream/serial_stream.c
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include <console/console.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stream/read_bytes.h>
|
||||
#include <string.h>
|
||||
|
||||
/* if they set the precompressed rom stream, they better have set a type */
|
||||
#if CONFIG_PRECOMPRESSED_ROM_STREAM && ((!CONFIG_COMPRESSED_ROM_STREAM) && (!CONFIG_COMPRESSED_ROM_STREAM_NRV2B) && (!CONFIG_COMPRESSED_ROM_STREAM_LZMA))
|
||||
#error "You set CONFIG_PRECOMPRESSED_ROM_STREAM but need to set CONFIG_COMPRESSED_ROM_STREAM (implies NRV2B, deprecated) or CONFIG_COMPRESSED_ROM_STREAM_NRV2B or CONFIG_COMPRESSED_ROM_STREAM_LZMA"
|
||||
#endif
|
||||
|
||||
#if (CONFIG_COMPRESSED_ROM_STREAM) || (CONFIG_COMPRESSED_ROM_STREAM_NRV2B)
|
||||
#define HAVE_UNCOMPRESSER 1
|
||||
#include "../lib/nrv2b.c"
|
||||
#endif
|
||||
|
||||
#if (CONFIG_COMPRESSED_ROM_STREAM_LZMA)
|
||||
#if HAVE_UNCOMPRESSER
|
||||
#error "You're defining more than one compression type, which is not allowed (of course)"
|
||||
#endif
|
||||
#define HAVE_UNCOMPRESSER 1
|
||||
#include "../lib/lzma.c"
|
||||
#endif
|
||||
|
||||
#include "../lib/xmodem.c"
|
||||
|
||||
/* Blocks of RAM for storing stream data */
|
||||
static unsigned char *stream_start = (unsigned char *) 0x02000000;
|
||||
static unsigned char *stream_end;
|
||||
static unsigned char *temp_start = (unsigned char *) 0x03000000;
|
||||
static int stream_max_bytes = 0x00800000;
|
||||
|
||||
#if HAVE_UNCOMPRESSER
|
||||
static unsigned long uncompress(uint8_t *src, uint8_t *dest)
|
||||
{
|
||||
#if (CONFIG_COMPRESSED_ROM_STREAM) || (CONFIG_COMPRESSED_ROM_STREAM_NRV2B)
|
||||
unsigned long ilen;
|
||||
return unrv2b(src, dest, &ilen);
|
||||
#endif
|
||||
#if (CONFIG_COMPRESSED_ROM_STREAM_LZMA)
|
||||
return ulzma(src, dest);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int stream_init(void)
|
||||
{
|
||||
int len;
|
||||
|
||||
printk_debug("serial_stream: downloading to 0x%08lx; start XMODEM transfer now!\n", temp_start);
|
||||
if ((len = xmodemReceive(temp_start, stream_max_bytes)) <= 0) {
|
||||
printk_debug("\nserial_stream: XMODEM transfer failed\n");
|
||||
return -1;
|
||||
}
|
||||
printk_debug("\nserial_stream: XMODEM transfer complete; %d bytes received\n", len);
|
||||
#if HAVE_UNCOMPRESSER
|
||||
printk_debug("serial_stream: uncompressing to 0x%08lx\n", stream_start);
|
||||
len = uncompress((uint8_t *) temp_start, (uint8_t *) stream_start);
|
||||
printk_debug("serial_stream: %d bytes uncompressed\n", len);
|
||||
#else
|
||||
printk_debug("serial_stream: copying to 0x%08lx\n", stream_start);
|
||||
memcpy(stream_start, temp_start, len);
|
||||
#endif
|
||||
stream_end = stream_start + len - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stream_fini(void)
|
||||
{
|
||||
}
|
||||
|
||||
byte_offset_t stream_skip(byte_offset_t count)
|
||||
{
|
||||
if ((stream_start + count) > stream_end) {
|
||||
printk_warning("%6d:%s() - overflowed source buffer\n",
|
||||
__LINE__, __FUNCTION__);
|
||||
count = 0;
|
||||
if (stream_start <= stream_end) {
|
||||
count = (stream_end - stream_start) + 1;
|
||||
}
|
||||
}
|
||||
stream_start += count;
|
||||
return count;
|
||||
}
|
||||
|
||||
byte_offset_t stream_read(void *vdest, byte_offset_t count)
|
||||
{
|
||||
unsigned char *old_start = stream_start;
|
||||
count = stream_skip(count);
|
||||
memcpy(vdest, old_start, count);
|
||||
return count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue