sc520 support -- ethernet works
[coreboot.git] / src / stream / rom_stream.c
1 #include <console/console.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <stream/read_bytes.h>
5 #include <string.h>
6
7
8 #ifndef CONFIG_ROM_STREAM_START
9 #define CONFIG_ROM_STREAM_START 0xffff0000UL
10 #endif
11
12 /* well, this is a mess, and it will get fixed, but not right away. 
13  * until we stop using 'ld' for building the rom image, that is. 
14  * problem is, that on the sc520, ROM_STREAM_START has to be at 0x2000000. 
15  * but if you set CONFIG_ROM_STREAM_START to that, then ld will try to 
16  * build a giant image: 0x0-0x2000000, i.e. almost 4 GB. 
17  * so make this non-static, non-const for now. 
18  */
19
20 /*XXXXXXXXXXXXXX */
21 /*static const */unsigned char *rom_start = (void *)CONFIG_ROM_STREAM_START;
22 /*static const */unsigned char *rom_end   = (void *)(CONFIG_ROM_STREAM_START + PAYLOAD_SIZE - 1);
23 /*XXXXXXXXXXXXXX */
24 static const unsigned char *rom;
25
26 int stream_init(void)
27 {
28         rom = rom_start;
29
30         printk_debug("%6d:%s() - rom_stream: 0x%08lx - 0x%08lx\n",
31                 __LINE__, __FUNCTION__,
32                 (unsigned long)rom_start,
33                 (unsigned long)rom_end);
34         return 0;
35 }
36
37
38 void stream_fini(void)
39 {
40         return;
41 }
42
43 byte_offset_t stream_skip(byte_offset_t count)
44 {
45         byte_offset_t bytes;
46         bytes = count;
47         if ((rom + bytes) > rom_end) {
48                 printk_warning("%6d:%s() - overflowed source buffer\n",
49                         __LINE__, __FUNCTION__);
50                 bytes = 0;
51                 if (rom <= rom_end) {
52                         bytes = (rom_end - rom) + 1;
53                 }
54         }
55         rom += bytes;
56         return bytes;
57 }
58
59 byte_offset_t stream_read(void *vdest, byte_offset_t count)
60 {
61         unsigned char *dest = vdest;
62         const unsigned char *src = rom;
63         byte_offset_t bytes;
64
65         bytes = stream_skip(count);
66         memcpy(dest, src, bytes);
67         return bytes;
68 }