summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/rtkload/read_fd.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_fd.c
parent0239d37124f9184b478a42de8a7fa1bc85a6a6fe (diff)
Add realtek target files
Signed-off-by: Roman Yeryomin <roman@advem.lv>
Diffstat (limited to 'target/linux/realtek/files/rtkload/read_fd.c')
-rw-r--r--target/linux/realtek/files/rtkload/read_fd.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/target/linux/realtek/files/rtkload/read_fd.c b/target/linux/realtek/files/rtkload/read_fd.c
new file mode 100644
index 000000000..bf40fb30e
--- /dev/null
+++ b/target/linux/realtek/files/rtkload/read_fd.c
@@ -0,0 +1,69 @@
+/* This file has not been tested for ages. */
+
+#include "hfload.h"
+
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+void
+read_struct(void *s, ssize_t size)
+{
+ ssize_t real;
+
+ real = read(0, s, size);
+ if (size != real) {
+ printf("trying to read %d, got %d; dying.\n", size, real);
+ exit(1);
+ }
+ file_offset += real;
+}
+
+void
+seek_forward(int offset) {
+ int dummy, i;
+ ssize_t real;
+
+ if (offset % 4 != 0) {
+ printf("Can't seek by a non-word aligned amount\n");
+ exit(1);
+ }
+
+ if (offset < file_offset) {
+ printf("can't seek backwards\n");
+ exit(1);
+ }
+
+ for (; offset < file_offset; file_offset += 4) {
+ real = read(0, &dummy, 4);
+ if (real != 4) {
+ printf("error seeking forward at offset %d\n", file_offset);
+ exit(1);
+ }
+ }
+}
+
+void
+copy_to_region(int *addr, ssize_t size) {
+ int i, dummy, real;
+
+ printf("copying %x bytes from file offset %x to address %08x\n",
+ size, file_offset, addr);
+
+#ifdef FAKE_COPYING
+ for (i = 0; i < size; i += 4) {
+ read_struct(&dummy, sizeof(int));
+ }
+#else
+ real = read(0, addr, size);
+ if (real != size) {
+ printf("failed to read %d bytes, exiting\n");
+ exit(1);
+ }
+ file_offset += real;
+#endif
+}
+
+void
+init_read() {
+}