summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/rtkload/read_memory.c
diff options
context:
space:
mode:
authorRoman Yeryomin <roman@advem.lv>2012-09-13 00:40:35 +0300
committerRoman Yeryomin <roman@advem.lv>2012-12-03 00:13:21 +0200
commit5deb3317cb51ac52de922bb55f8492624018906d (patch)
treec2fbe6346699d9bb0f2100490c3029519bb8fde8 /target/linux/realtek/files/rtkload/read_memory.c
parent0239d37124f9184b478a42de8a7fa1bc85a6a6fe (diff)
Add realtek target files
Signed-off-by: Roman Yeryomin <roman@advem.lv>
Diffstat (limited to 'target/linux/realtek/files/rtkload/read_memory.c')
-rw-r--r--target/linux/realtek/files/rtkload/read_memory.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/target/linux/realtek/files/rtkload/read_memory.c b/target/linux/realtek/files/rtkload/read_memory.c
new file mode 100644
index 000000000..2596911e9
--- /dev/null
+++ b/target/linux/realtek/files/rtkload/read_memory.c
@@ -0,0 +1,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
+}