rockbox/utils/ypr0tools/extract_section.c
Thomas Martitz 249bba03f1 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
2011-12-24 11:56:46 +00:00

85 lines
2.3 KiB
C

/***************************************************************************
* __________ __ ___.
* 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);
}