summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/rtkload/read_memory.c
blob: 2596911e9ed76b0ecf1291b8d8e12fd6b47664c4 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* read_memory.c
 * 
 * This file is subject to the terms and conditions of the GNU
 * General Public License.  See the file "COPYING" in the main
 * directory of this archive for more details.
 *
 * Copyright (C) 2000, Jay Carlson
 */

/*   read_memory is the memory-based back end for the image-reading
 * functions.
 * 
 * Support for non-compressed kernels has probably rotted.  
 */


#include <linux/types.h>
#include "hfload.h"

#ifndef EMBEDDED
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#endif

char *source_memory;

#ifdef EMBEDDED
#ifndef COMPRESSED_KERNEL
extern char source_memory_start;
#endif
#endif

// david -----------------------
//#include <linux/config.h>
#include <linux/autoconf.h>

//#ifdef BZ2_COMPRESS //sc_yang
void * memcpy(void * dest,const void *src,size_t count)
{
        char *tmp = (char *) dest, *s = (char *) src;

        while (count--)
                *tmp++ = *s++;

        return dest;
}
#if 0
void * memset(void * s, int c, size_t count)
{
        char *xs = (char *) s;

        while (count--)
                *xs++ = (char) c;

        return s;
}
#endif // CONFIG_NINO_8MB
//------------------------------


void
read_struct(void *s, ssize_t size)
{
	memcpy(s, source_memory+file_offset, size);
    file_offset += size;
}

void
seek_forward(int offset) {
        if (offset % 4 != 0) {
         #ifndef __DO_QUIET__       
				printf("Can't seek by a non-word aligned amount\n");
        #endif 
		       exit(1);
        }
        
        if (offset < file_offset) {
            #ifndef __DO_QUIET__    
			printf("can't seek backwards\n");
			#endif
                exit(1);
        }

        file_offset = offset;
}

void
copy_to_region(int *addr, ssize_t size) {
        int i, dummy;

        int *source, *dest;
#ifndef __DO_QUIET__
        printf("copying 0x%x bytes from file offset 0x%x to address 0x%08x\n",
               size, file_offset, addr);
#endif
#ifndef FAKE_COPYING
        memcpy(addr, source_memory+file_offset, size);
#endif
        
        file_offset += size;
}

void
init_read() {
#ifndef EMBEDDED
        struct stat buf;
        if (fstat(0, &buf)) {
                perror("stat");
                exit(1);
        }
        source_memory = mmap(0, buf.st_size & ~(4095), PROT_READ, MAP_PRIVATE, 0, 0);
        if (!source_memory) {
                perror("mmap");
                exit(1);
        }
#else
#ifdef COMPRESSED_KERNEL
        source_memory = (char *)UNCOMPRESS_OUT;
#else
        source_memory = &source_memory_start;
#endif
#endif
}