summaryrefslogtreecommitdiff
path: root/src/stream/rom_stream.c
blob: 7a662d019e1982e052633d7dd6e8c5b851e73309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <console/console.h>
#include <stdlib.h>
#include <stddef.h>
#include <stream/read_bytes.h>
#include <string.h>


#ifndef CONFIG_ROM_STREAM_START
#define CONFIG_ROM_STREAM_START 0xffff0000UL
#endif

/* 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. 
 * problem is, that on the sc520, ROM_STREAM_START has to be at 0x2000000. 
 * but if you set CONFIG_ROM_STREAM_START to that, then ld will try to 
 * build a giant image: 0x0-0x2000000, i.e. almost 4 GB. 
 * so make this non-static, non-const for now. 
 */

/*XXXXXXXXXXXXXX */
/*static const */unsigned char *rom_start = (void *)CONFIG_ROM_STREAM_START;
/*static const */unsigned char *rom_end   = (void *)(CONFIG_ROM_STREAM_START + PAYLOAD_SIZE - 1);
/*XXXXXXXXXXXXXX */
static const unsigned char *rom;

int stream_init(void)
{
	rom = rom_start;

	printk_debug("%6d:%s() - rom_stream: 0x%08lx - 0x%08lx\n",
		__LINE__, __FUNCTION__,
		(unsigned long)rom_start,
		(unsigned long)rom_end);
	return 0;
}


void stream_fini(void)
{
	return;
}

byte_offset_t stream_skip(byte_offset_t count)
{
	byte_offset_t bytes;
	bytes = count;
	if ((rom + bytes) > rom_end) {
		printk_warning("%6d:%s() - overflowed source buffer\n",
			__LINE__, __FUNCTION__);
		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;
}