summaryrefslogtreecommitdiffstats
path: root/utils/ypr0tools/extract_section.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-12-24 11:56:46 +0000
committerThomas Martitz <kugel@rockbox.org>2011-12-24 11:56:46 +0000
commit249bba03f1051f4984538f66b9e7d36674c61e5c (patch)
treeb9a0d78e05269ed2043521ab0dfdad83aeaf2aff /utils/ypr0tools/extract_section.c
parent567e0ad93ef3048f2266932b10dcdb309b1a77c9 (diff)
downloadrockbox-249bba03f1051f4984538f66b9e7d36674c61e5c.tar.gz
rockbox-249bba03f1051f4984538f66b9e7d36674c61e5c.zip
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system, but is the only application. It therefore can implement lots of stuff that native targets also implement, while leveraging the underlying linux kernel. The port is quite advanced. User interface, audio playback, plugins work mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page). Included in utils/ypr0tools are scripts and programs required to generate a patched firmware. The patched firmware has the rootfs modified to load Rockbox. It includes a early/safe USB mode. This port needs a new toolchain, one that includes glibc headers and libraries. rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may also work. Most of the initial effort is done by Lorenzo Miori and others (on ABI), including reverse engineering and patching of the original firmware, initial drivers, and more. Big thanks to you. Flyspray: FS#12348 Author: Lorenzo Miori, myself Merry christmas to ypr0 owners! :) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/ypr0tools/extract_section.c')
-rw-r--r--utils/ypr0tools/extract_section.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/utils/ypr0tools/extract_section.c b/utils/ypr0tools/extract_section.c
new file mode 100644
index 0000000000..8ad12bc7df
--- /dev/null
+++ b/utils/ypr0tools/extract_section.c
@@ -0,0 +1,85 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2011 Thomas Martitz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+/* A simple replacement program for (
+ * dd if=$file1 of=$file2 bs=1 skip=$offset count=$size
+ *
+ * Written because byte-size operations with dd are unbearably slow.
+ */
+
+void usage(void)
+{
+ fprintf(stderr, "Usage: extract_section <romfile> <outfile> <offset> <byte count>\n");
+ exit(1);
+}
+
+void die(const char* fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ exit(1);
+}
+
+int main(int argc, const char* argv[])
+{
+ if (argc != 5)
+ usage();
+
+ int ifd, ofd;
+ ssize_t size = atol(argv[4]);
+ long skip = atol(argv[3]);
+
+ if (!size)
+ die("invalid byte count\n");
+
+ ifd = open(argv[1], O_RDONLY);
+ if (ifd < 0)
+ die("Could not open %s for reading!\n", argv[1]);
+
+ ofd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (ofd < 0)
+ die("Could not create %s\n", argv[2]);
+
+ void *buf = malloc(size);
+ if (!buf) die("OOM\n");
+
+ lseek(ifd, skip, SEEK_SET);
+ lseek(ofd, 0, SEEK_SET);
+ if (read(ifd, buf, size) != size)
+ die("Read failed\n");
+ if (write(ofd, buf, size) != size)
+ die("write failed\n");
+
+ close(ifd);
+ close(ofd);
+
+ exit(EXIT_SUCCESS);
+}