summaryrefslogtreecommitdiffstats
path: root/utils/ypr0tools
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ypr0tools')
-rw-r--r--utils/ypr0tools/Makefile13
-rwxr-xr-xutils/ypr0tools/MuonEncryptbin0 -> 11006 bytes
-rw-r--r--utils/ypr0tools/README12
-rw-r--r--utils/ypr0tools/cramfs-1.1/COPYING340
-rw-r--r--utils/ypr0tools/cramfs-1.1/GNUmakefile12
-rw-r--r--utils/ypr0tools/cramfs-1.1/NOTES168
-rw-r--r--utils/ypr0tools/cramfs-1.1/README76
-rw-r--r--utils/ypr0tools/cramfs-1.1/cramfsck.c716
-rw-r--r--utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h98
-rw-r--r--utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h15
-rw-r--r--utils/ypr0tools/cramfs-1.1/mkcramfs.c889
-rw-r--r--utils/ypr0tools/extract_section.c85
-rw-r--r--utils/ypr0tools/files/.rockbox/README1
-rw-r--r--utils/ypr0tools/files/Playlists/README1
-rw-r--r--utils/ypr0tools/files/etc/mods/safe_mode.rawbin0 -> 230400 bytes
-rwxr-xr-xutils/ypr0tools/files/etc/mods/safe_mode.sh111
-rwxr-xr-xutils/ypr0tools/files/etc/profile66
-rwxr-xr-xutils/ypr0tools/pack-firmware.sh132
-rwxr-xr-xutils/ypr0tools/patch-firmware.sh67
-rwxr-xr-xutils/ypr0tools/rockbox.sh47
-rwxr-xr-xutils/ypr0tools/unpack-firmware.sh90
21 files changed, 2939 insertions, 0 deletions
diff --git a/utils/ypr0tools/Makefile b/utils/ypr0tools/Makefile
new file mode 100644
index 0000000000..efc1de63f2
--- /dev/null
+++ b/utils/ypr0tools/Makefile
@@ -0,0 +1,13 @@
+
+.PHONY: all clean
+PROGS = extract_section
+CC = gcc
+CFLAGS = -O1 -g -W -Wall
+
+
+all: $(PROGS)
+ $(MAKE) -C cramfs-1.1
+
+clean:
+ $(MAKE) -C cramfs-1.1 clean
+ rm -f extract_section
diff --git a/utils/ypr0tools/MuonEncrypt b/utils/ypr0tools/MuonEncrypt
new file mode 100755
index 0000000000..b1bc124523
--- /dev/null
+++ b/utils/ypr0tools/MuonEncrypt
Binary files differ
diff --git a/utils/ypr0tools/README b/utils/ypr0tools/README
new file mode 100644
index 0000000000..45777dd8c5
--- /dev/null
+++ b/utils/ypr0tools/README
@@ -0,0 +1,12 @@
+
+To generate a firmware, run (paths may differ):
+
+$ make
+$ ./unpack-firmware.sh R0.ROM /tmp/romfiles
+$ sudo ./patch-firmware.sh files /tmp/romfiles # needs sudo
+$ ./pack-firmware.sh R0.ROM /tmp/romfiles
+
+After that, R0.ROM is patched and can load Rockbox.
+
+rockbox.sh is a script to put into rockbox.zip. It's a small loader script
+that sets stuff up.
diff --git a/utils/ypr0tools/cramfs-1.1/COPYING b/utils/ypr0tools/cramfs-1.1/COPYING
new file mode 100644
index 0000000000..5b6e7c66c2
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/utils/ypr0tools/cramfs-1.1/GNUmakefile b/utils/ypr0tools/cramfs-1.1/GNUmakefile
new file mode 100644
index 0000000000..e15fb22f01
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/GNUmakefile
@@ -0,0 +1,12 @@
+CC = gcc
+CFLAGS = -W -Wall -O2 -g -Wno-pointer-sign
+CPPFLAGS = -I.
+LDLIBS = -lz
+PROGS = mkcramfs cramfsck
+
+all: $(PROGS)
+
+distclean clean:
+ rm -f $(PROGS)
+
+.PHONY: all clean
diff --git a/utils/ypr0tools/cramfs-1.1/NOTES b/utils/ypr0tools/cramfs-1.1/NOTES
new file mode 100644
index 0000000000..445d1c2d76
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/NOTES
@@ -0,0 +1,168 @@
+Notes on Filesystem Layout
+--------------------------
+
+These notes describe what mkcramfs generates. Kernel requirements are
+a bit looser, e.g. it doesn't care if the <file_data> items are
+swapped around (though it does care that directory entries (inodes) in
+a given directory are contiguous, as this is used by readdir).
+
+All data is currently in host-endian format; neither mkcramfs nor the
+kernel ever do swabbing. (See section `Block Size' below.)
+
+<filesystem>:
+ <superblock>
+ <directory_structure>
+ <data>
+
+<superblock>: struct cramfs_super (see cramfs_fs.h).
+
+<directory_structure>:
+ For each file:
+ struct cramfs_inode (see cramfs_fs.h).
+ Filename. Not generally null-terminated, but it is
+ null-padded to a multiple of 4 bytes.
+
+The order of inode traversal is described as "width-first" (not to be
+confused with breadth-first); i.e. like depth-first but listing all of
+a directory's entries before recursing down its subdirectories: the
+same order as `ls -AUR' (but without the /^\..*:$/ directory header
+lines); put another way, the same order as `find -type d -exec
+ls -AU1 {} \;'.
+
+Beginning in 2.4.7, directory entries are sorted. This optimization
+allows cramfs_lookup to return more quickly when a filename does not
+exist, speeds up user-space directory sorts, etc.
+
+<data>:
+ One <file_data> for each file that's either a symlink or a
+ regular file of non-zero st_size.
+
+<file_data>:
+ nblocks * <block_pointer>
+ (where nblocks = (st_size - 1) / blksize + 1)
+ nblocks * <block>
+ padding to multiple of 4 bytes
+
+The i'th <block_pointer> for a file stores the byte offset of the
+*end* of the i'th <block> (i.e. one past the last byte, which is the
+same as the start of the (i+1)'th <block> if there is one). The first
+<block> immediately follows the last <block_pointer> for the file.
+<block_pointer>s are each 32 bits long.
+
+The order of <file_data>'s is a depth-first descent of the directory
+tree, i.e. the same order as `find -size +0 \( -type f -o -type l \)
+-print'.
+
+
+<block>: The i'th <block> is the output of zlib's compress function
+applied to the i'th blksize-sized chunk of the input data.
+(For the last <block> of the file, the input may of course be smaller.)
+Each <block> may be a different size. (See <block_pointer> above.)
+<block>s are merely byte-aligned, not generally u32-aligned.
+
+
+Holes
+-----
+
+This kernel supports cramfs holes (i.e. [efficient representation of]
+blocks in uncompressed data consisting entirely of NUL bytes), but by
+default mkcramfs doesn't test for & create holes, since cramfs in
+kernels up to at least 2.3.39 didn't support holes. Run mkcramfs
+with -z if you want it to create files that can have holes in them.
+
+
+Tools
+-----
+
+The cramfs user-space tools, including mkcramfs and cramfsck, are
+located at <http://sourceforge.net/projects/cramfs/>.
+
+
+Future Development
+==================
+
+Block Size
+----------
+
+(Block size in cramfs refers to the size of input data that is
+compressed at a time. It's intended to be somewhere around
+PAGE_CACHE_SIZE for cramfs_readpage's convenience.)
+
+The superblock ought to indicate the block size that the fs was
+written for, since comments in <linux/pagemap.h> indicate that
+PAGE_CACHE_SIZE may grow in future (if I interpret the comment
+correctly).
+
+Currently, mkcramfs #define's PAGE_CACHE_SIZE as 4096 and uses that
+for blksize, whereas Linux-2.3.39 uses its PAGE_CACHE_SIZE, which in
+turn is defined as PAGE_SIZE (which can be as large as 32KB on arm).
+This discrepancy is a bug, though it's not clear which should be
+changed.
+
+One option is to change mkcramfs to take its PAGE_CACHE_SIZE from
+<asm/page.h>. Personally I don't like this option, but it does
+require the least amount of change: just change `#define
+PAGE_CACHE_SIZE (4096)' to `#include <asm/page.h>'. The disadvantage
+is that the generated cramfs cannot always be shared between different
+kernels, not even necessarily kernels of the same architecture if
+PAGE_CACHE_SIZE is subject to change between kernel versions
+(currently possible with arm and ia64).
+
+The remaining options try to make cramfs more sharable.
+
+One part of that is addressing endianness. The two options here are
+`always use little-endian' (like ext2fs) or `writer chooses
+endianness; kernel adapts at runtime'. Little-endian wins because of
+code simplicity and little CPU overhead even on big-endian machines.
+
+The cost of swabbing is changing the code to use the le32_to_cpu
+etc. macros as used by ext2fs. We don't need to swab the compressed
+data, only the superblock, inodes and block pointers.
+
+
+The other part of making cramfs more sharable is choosing a block
+size. The options are:
+
+ 1. Always 4096 bytes.
+
+ 2. Writer chooses blocksize; kernel adapts but rejects blocksize >
+ PAGE_CACHE_SIZE.
+
+ 3. Writer chooses blocksize; kernel adapts even to blocksize >
+ PAGE_CACHE_SIZE.
+
+It's easy enough to change the kernel to use a smaller value than
+PAGE_CACHE_SIZE: just make cramfs_readpage read multiple blocks.
+
+The cost of option 1 is that kernels with a larger PAGE_CACHE_SIZE
+value don't get as good compression as they can.
+
+The cost of option 2 relative to option 1 is that the code uses
+variables instead of #define'd constants. The gain is that people
+with kernels having larger PAGE_CACHE_SIZE can make use of that if
+they don't mind their cramfs being inaccessible to kernels with
+smaller PAGE_CACHE_SIZE values.
+
+Option 3 is easy to implement if we don't mind being CPU-inefficient:
+e.g. get readpage to decompress to a buffer of size MAX_BLKSIZE (which
+must be no larger than 32KB) and discard what it doesn't need.
+Getting readpage to read into all the covered pages is harder.
+
+The main advantage of option 3 over 1, 2, is better compression. The
+cost is greater complexity. Probably not worth it, but I hope someone
+will disagree. (If it is implemented, then I'll re-use that code in
+e2compr.)
+
+
+Another cost of 2 and 3 over 1 is making mkcramfs use a different
+block size, but that just means adding and parsing a -b option.
+
+
+Inode Size
+----------
+
+Given that cramfs will probably be used for CDs etc. as well as just
+silicon ROMs, it might make sense to expand the inode a little from
+its current 12 bytes. Inodes other than the root inode are followed
+by filename, so the expansion doesn't even have to be a multiple of 4
+bytes.
diff --git a/utils/ypr0tools/cramfs-1.1/README b/utils/ypr0tools/cramfs-1.1/README
new file mode 100644
index 0000000000..31f53f0ab9
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/README
@@ -0,0 +1,76 @@
+
+ Cramfs - cram a filesystem onto a small ROM
+
+cramfs is designed to be simple and small, and to compress things well.
+
+It uses the zlib routines to compress a file one page at a time, and
+allows random page access. The meta-data is not compressed, but is
+expressed in a very terse representation to make it use much less
+diskspace than traditional filesystems.
+
+You can't write to a cramfs filesystem (making it compressible and
+compact also makes it _very_ hard to update on-the-fly), so you have to
+create the disk image with the "mkcramfs" utility.
+
+
+Usage Notes
+-----------
+
+File sizes are limited to less than 16MB.
+
+Maximum filesystem size is a little over 256MB. (The last file on the
+filesystem is allowed to extend past 256MB.)
+
+Only the low 8 bits of gid are stored. The current version of
+mkcramfs simply truncates to 8 bits, which is a potential security
+issue.
+
+Hard links are supported, but hard linked files
+will still have a link count of 1 in the cramfs image.
+
+Cramfs directories have no `.' or `..' entries. Directories (like
+every other file on cramfs) always have a link count of 1. (There's
+no need to use -noleaf in `find', btw.)
+
+No timestamps are stored in a cramfs, so these default to the epoch
+(1970 GMT). Recently-accessed files may have updated timestamps, but
+the update lasts only as long as the inode is cached in memory, after
+which the timestamp reverts to 1970, i.e. moves backwards in time.
+
+Currently, cramfs must be written and read with architectures of the
+same endianness, and can be read only by kernels with PAGE_CACHE_SIZE
+== 4096. At least the latter of these is a bug, but it hasn't been
+decided what the best fix is. For the moment if you have larger pages
+you can just change the #define in mkcramfs.c, so long as you don't
+mind the filesystem becoming unreadable to future kernels.
+
+
+For /usr/share/magic
+--------------------
+
+0 ulelong 0x28cd3d45 Linux cramfs offset 0
+>4 ulelong x size %d
+>8 ulelong x flags 0x%x
+>12 ulelong x future 0x%x
+>16 string >\0 signature "%.16s"
+>32 ulelong x fsid.crc 0x%x
+>36 ulelong x fsid.edition %d
+>40 ulelong x fsid.blocks %d
+>44 ulelong x fsid.files %d
+>48 string >\0 name "%.16s"
+512 ulelong 0x28cd3d45 Linux cramfs offset 512
+>516 ulelong x size %d
+>520 ulelong x flags 0x%x
+>524 ulelong x future 0x%x
+>528 string >\0 signature "%.16s"
+>544 ulelong x fsid.crc 0x%x
+>548 ulelong x fsid.edition %d
+>552 ulelong x fsid.blocks %d
+>556 ulelong x fsid.files %d
+>560 string >\0 name "%.16s"
+
+
+Hacker Notes
+------------
+
+See fs/cramfs/README for filesystem layout and implementation notes.
diff --git a/utils/ypr0tools/cramfs-1.1/cramfsck.c b/utils/ypr0tools/cramfs-1.1/cramfsck.c
new file mode 100644
index 0000000000..aef017a4b4
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/cramfsck.c
@@ -0,0 +1,716 @@
+/*
+ * cramfsck - check a cramfs file system
+ *
+ * Copyright (C) 2000-2002 Transmeta Corporation
+ *
+ * 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * 1999/12/03: Linus Torvalds (cramfs tester and unarchive program)
+ * 2000/06/03: Daniel Quinlan (CRC and length checking program)
+ * 2000/06/04: Daniel Quinlan (merged programs, added options, support
+ * for special files, preserve permissions and
+ * ownership, cramfs superblock v2, bogus mode
+ * test, pathname length test, etc.)
+ * 2000/06/06: Daniel Quinlan (support for holes, pretty-printing,
+ * symlink size test)
+ * 2000/07/11: Daniel Quinlan (file length tests, start at offset 0 or 512,
+ * fsck-compatible exit codes)
+ * 2000/07/15: Daniel Quinlan (initial support for block devices)
+ * 2002/01/10: Daniel Quinlan (additional checks, test more return codes,
+ * use read if mmap fails, standardize messages)
+ */
+
+/* compile-time options */
+#define INCLUDE_FS_TESTS /* include cramfs checking and extraction */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/sysmacros.h>
+#include <utime.h>
+#include <sys/ioctl.h>
+#define _LINUX_STRING_H_
+#include <linux/fs.h>
+#include <linux/cramfs_fs.h>
+#include <zlib.h>
+
+/* Exit codes used by fsck-type programs */
+#define FSCK_OK 0 /* No errors */
+#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
+#define FSCK_REBOOT 2 /* System should be rebooted */
+#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
+#define FSCK_ERROR 8 /* Operational error */
+#define FSCK_USAGE 16 /* Usage or syntax error */
+#define FSCK_LIBRARY 128 /* Shared library error */
+
+#define PAD_SIZE 512
+
+#define PAGE_CACHE_SIZE page_size
+
+static const char *progname = "cramfsck";
+
+static int fd; /* ROM image file descriptor */
+static char *filename; /* ROM image filename */
+struct cramfs_super super; /* just find the cramfs superblock once */
+static int opt_verbose = 0; /* 1 = verbose (-v), 2+ = very verbose (-vv) */
+#ifdef INCLUDE_FS_TESTS
+static int opt_extract = 0; /* extract cramfs (-x) */
+static char *extract_dir = "root"; /* extraction directory (-x) */
+static uid_t euid; /* effective UID */
+
+/* (cramfs_super + start) <= start_dir < end_dir <= start_data <= end_data */
+static unsigned long start_dir = ~0UL; /* start of first non-root inode */
+static unsigned long end_dir = 0; /* end of the directory structure */
+static unsigned long start_data = ~0UL; /* start of the data (256 MB = max) */
+static unsigned long end_data = 0; /* end of the data */
+
+/* Guarantee access to at least 8kB at a time */
+#define ROMBUFFER_BITS 13
+#define ROMBUFFERSIZE (1 << ROMBUFFER_BITS)
+#define ROMBUFFERMASK (ROMBUFFERSIZE-1)
+static char read_buffer[ROMBUFFERSIZE * 2];
+static unsigned long read_buffer_block = ~0UL;
+
+/* Uncompressing data structures... */
+static char *outbuffer;
+static z_stream stream;
+
+static size_t page_size;
+
+/* Prototypes */
+static void expand_fs(char *, struct cramfs_inode *);
+#endif /* INCLUDE_FS_TESTS */
+
+/* Input status of 0 to print help and exit without an error. */
+static void usage(int status)
+{
+ FILE *stream = status ? stderr : stdout;
+
+ fprintf(stream, "usage: %s [-hv] [-x dir] file\n"
+ " -h print this help\n"
+ " -x dir extract into dir\n"
+ " -v be more verbose\n"
+ " file file to test\n", progname);
+
+ exit(status);
+}
+
+static void die(int status, int syserr, const char *fmt, ...)
+{
+ va_list arg_ptr;
+ int save = errno;
+
+ fflush(0);
+ va_start(arg_ptr, fmt);
+ fprintf(stderr, "%s: ", progname);
+ vfprintf(stderr, fmt, arg_ptr);
+ if (syserr) {
+ fprintf(stderr, ": %s", strerror(save));
+ }
+ fprintf(stderr, "\n");
+ va_end(arg_ptr);
+ exit(status);
+}
+
+static void test_super(int *start, size_t *length) {
+ struct stat st;
+
+ /* find the physical size of the file or block device */
+ if (stat(filename, &st) < 0) {
+ die(FSCK_ERROR, 1, "stat failed: %s", filename);
+ }
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ die(FSCK_ERROR, 1, "open failed: %s", filename);
+ }
+ if (S_ISBLK(st.st_mode)) {
+ if (ioctl(fd, BLKGETSIZE, length) < 0) {
+ die(FSCK_ERROR, 1, "ioctl failed: unable to determine device size: %s", filename);
+ }
+ *length = *length * 512;
+ }
+ else if (S_ISREG(st.st_mode)) {
+ *length = st.st_size;
+ }
+ else {
+ die(FSCK_ERROR, 0, "not a block device or file: %s", filename);
+ }
+
+ if (*length < sizeof(struct cramfs_super)) {
+ die(FSCK_UNCORRECTED, 0, "file length too short");
+ }
+
+ /* find superblock */
+ if (read(fd, &super, sizeof(super)) != sizeof(super)) {
+ die(FSCK_ERROR, 1, "read failed: %s", filename);
+ }
+ if (super.magic == CRAMFS_MAGIC) {
+ *start = 0;
+ }
+ else if (*length >= (PAD_SIZE + sizeof(super))) {
+ lseek(fd, PAD_SIZE, SEEK_SET);
+ if (read(fd, &super, sizeof(super)) != sizeof(super)) {
+ die(FSCK_ERROR, 1, "read failed: %s", filename);
+ }
+ if (super.magic == CRAMFS_MAGIC) {
+ *start = PAD_SIZE;
+ }
+ }
+
+ /* superblock tests */
+ if (super.magic != CRAMFS_MAGIC) {
+ die(FSCK_UNCORRECTED, 0, "superblock magic not found");
+ }
+ if (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {
+ die(FSCK_ERROR, 0, "unsupported filesystem features");
+ }
+ if (super.size < PAGE_CACHE_SIZE) {
+ die(FSCK_UNCORRECTED, 0, "superblock size (%d) too small", super.size);
+ }
+ if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
+ if (super.fsid.files == 0) {
+ die(FSCK_UNCORRECTED, 0, "zero file count");
+ }
+ if (*length < super.size) {
+ die(FSCK_UNCORRECTED, 0, "file length too short");
+ }
+ else if (*length > super.size) {
+ fprintf(stderr, "warning: file extends past end of filesystem\n");
+ }
+ }
+ else {
+ fprintf(stderr, "warning: old cramfs format\n");
+ }
+}
+
+static void test_crc(int start)
+{
+ void *buf;
+ u32 crc;
+
+ if (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) {
+#ifdef INCLUDE_FS_TESTS
+ return;
+#else /* not INCLUDE_FS_TESTS */
+ die(FSCK_USAGE, 0, "unable to test CRC: old cramfs format");
+#endif /* not INCLUDE_FS_TESTS */
+ }
+
+ crc = crc32(0L, Z_NULL, 0);
+
+ buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ if (buf == MAP_FAILED) {
+ buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (buf != MAP_FAILED) {
+ lseek(fd, 0, SEEK_SET);
+ read(fd, buf, super.size);
+ }
+ }
+ if (buf != MAP_FAILED) {
+ ((struct cramfs_super *) (buf+start))->fsid.crc = crc32(0L, Z_NULL, 0);
+ crc = crc32(crc, buf+start, super.size-start);
+ munmap(buf, super.size);
+ }
+ else {
+ int retval;
+ size_t length = 0;
+
+ buf = malloc(4096);
+ if (!buf) {
+ die(FSCK_ERROR, 1, "malloc failed");
+ }
+ lseek(fd, start, SEEK_SET);
+ for (;;) {
+ retval = read(fd, buf, 4096);
+ if (retval < 0) {
+ die(FSCK_ERROR, 1, "read failed: %s", filename);
+ }
+ else if (retval == 0) {
+ break;
+ }
+ if (length == 0) {
+ ((struct cramfs_super *) buf)->fsid.crc = crc32(0L, Z_NULL, 0);
+ }
+ length += retval;
+ if (length > (super.size-start)) {
+ crc = crc32(crc, buf, retval - (length - (super.size-start)));
+ break;
+ }
+ crc = crc32(crc, buf, retval);
+ }
+ free(buf);
+ }
+
+ if (crc != super.fsid.crc) {
+ die(FSCK_UNCORRECTED, 0, "crc error");
+ }
+}
+
+#ifdef INCLUDE_FS_TESTS
+static void print_node(char type, struct cramfs_inode *i, char *name)
+{
+ char info[10];
+
+ if (S_ISCHR(i->mode) || (S_ISBLK(i->mode))) {
+ /* major/minor numbers can be as high as 2^12 or 4096 */
+ snprintf(info, 10, "%4d,%4d", major(i->size), minor(i->size));
+ }
+ else {
+ /* size be as high as 2^24 or 16777216 */
+ snprintf(info, 10, "%9d", i->size);
+ }
+
+ printf("%c %04o %s %5d:%-3d %s\n",
+ type, i->mode & ~S_IFMT, info, i->uid, i->gid, name);
+}
+
+/*
+ * Create a fake "blocked" access
+ */
+static void *romfs_read(unsigned long offset)
+{
+ unsigned int block = offset >> ROMBUFFER_BITS;
+ if (block != read_buffer_block) {
+ read_buffer_block = block;
+ lseek(fd, block << ROMBUFFER_BITS, SEEK_SET);
+ read(fd, read_buffer, ROMBUFFERSIZE * 2);
+ }
+ return read_buffer + (offset & ROMBUFFERMASK);
+}
+
+static struct cramfs_inode *cramfs_iget(struct cramfs_inode * i)
+{
+ struct cramfs_inode *inode = malloc(sizeof(struct cramfs_inode));
+
+ if (!inode) {
+ die(FSCK_ERROR, 1, "malloc failed");
+ }
+ *inode = *i;
+ return inode;
+}
+
+static struct cramfs_inode *iget(unsigned int ino)
+{
+ return cramfs_iget(romfs_read(ino));
+}
+
+static void iput(struct cramfs_inode *inode)
+{
+ free(inode);
+}
+
+/*
+ * Return the offset of the root directory
+ */
+static struct cramfs_inode *read_super(void)
+{
+ unsigned long offset = super.root.offset << 2;
+
+ if (!S_ISDIR(super.root.mode))
+ die(FSCK_UNCORRECTED, 0, "root inode is not directory");
+ if (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
+ ((offset != sizeof(struct cramfs_super)) &&
+ (offset != PAD_SIZE + sizeof(struct cramfs_super))))
+ {
+ die(FSCK_UNCORRECTED, 0, "bad root offset (%lu)", offset);
+ }
+ return cramfs_iget(&super.root);
+}
+
+static int uncompress_block(void *src, int len)
+{
+ int err;
+
+ stream.next_in = src;
+ stream.avail_in = len;
+
+ stream.next_out = (unsigned char *) outbuffer;
+ stream.avail_out = PAGE_CACHE_SIZE*2;
+
+ inflateReset(&stream);
+
+ if (len > PAGE_CACHE_SIZE*2) {
+ die(FSCK_UNCORRECTED, 0, "data block too large");
+ }
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ die(FSCK_UNCORRECTED, 0, "decompression error %p(%d): %s",
+ zError(err), src, len);
+ }
+ return stream.total_out;
+}
+
+static void do_uncompress(char *path, int fd, unsigned long offset, unsigned long size)
+{
+ unsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);
+
+ do {
+ unsigned long out = PAGE_CACHE_SIZE;
+ unsigned long next = *(u32 *) romfs_read(offset);
+
+ if (next > end_data) {
+ end_data = next;
+ }
+
+ offset += 4;
+ if (curr == next) {
+ if (opt_verbose > 1) {
+ printf(" hole at %ld (%d)\n", curr, PAGE_CACHE_SIZE);
+ }
+ if (size < PAGE_CACHE_SIZE)
+ out = size;
+ memset(outbuffer, 0x00, out);
+ }
+ else {
+ if (opt_verbose > 1) {
+ printf(" uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
+ }
+ out = uncompress_block(romfs_read(curr), next - curr);
+ }
+ if (size >= PAGE_CACHE_SIZE) {
+ if (out != PAGE_CACHE_SIZE) {
+ die(FSCK_UNCORRECTED, 0, "non-block (%ld) bytes", out);
+ }
+ } else {
+ if (out != size) {
+ die(FSCK_UNCORRECTED, 0, "non-size (%ld vs %ld) bytes", out, size);
+ }
+ }
+ size -= out;
+ if (opt_extract) {
+ if (write(fd, outbuffer, out) < 0) {
+ die(FSCK_ERROR, 1, "write failed: %s", path);
+ }
+ }
+ curr = next;
+ } while (size);
+}
+
+static void change_file_status(char *path, struct cramfs_inode *i)
+{
+ struct utimbuf epoch = { 0, 0 };
+
+ if (euid == 0) {
+ if (lchown(path, i->uid, i->gid) < 0) {
+ die(FSCK_ERROR, 1, "lchown failed: %s", path);
+ }
+ if (S_ISLNK(i->mode))
+ return;
+ if ((S_ISUID | S_ISGID) & i->mode) {
+ if (chmod(path, i->mode) < 0) {
+ die(FSCK_ERROR, 1, "chown failed: %s", path);
+ }
+ }
+ }
+ if (S_ISLNK(i->mode))
+ return;
+ if (utime(path, &epoch) < 0) {
+ die(FSCK_ERROR, 1, "utime failed: %s", path);
+ }
+}
+
+static void do_directory(char *path, struct cramfs_inode *i)
+{
+ int pathlen = strlen(path);
+ int count = i->size;
+ unsigned long offset = i->offset << 2;
+ char *newpath = malloc(pathlen + 256);
+
+ if (!newpath) {
+ die(FSCK_ERROR, 1, "malloc failed");
+ }
+ if (offset == 0 && count != 0) {
+ die(FSCK_UNCORRECTED, 0, "directory inode has zero offset and non-zero size: %s", path);
+ }
+ if (offset != 0 && offset < start_dir) {
+ start_dir = offset;
+ }
+ /* TODO: Do we need to check end_dir for empty case? */
+ memcpy(newpath, path, pathlen);
+ newpath[pathlen] = '/';
+ pathlen++;
+ if (opt_verbose) {
+ print_node('d', i, path);
+ }
+ if (opt_extract) {
+ if (mkdir(path, i->mode) < 0) {
+ die(FSCK_ERROR, 1, "mkdir failed: %s", path);
+ }
+ change_file_status(path, i);
+ }
+ while (count > 0) {
+ struct cramfs_inode *child = iget(offset);
+ int size;
+ int newlen = child->namelen << 2;
+
+ size = sizeof(struct cramfs_inode) + newlen;
+ count -= size;
+
+ offset += sizeof(struct cramfs_inode);
+
+ memcpy(newpath + pathlen, romfs_read(offset), newlen);
+ newpath[pathlen + newlen] = 0;
+ if (newlen == 0) {
+ die(FSCK_UNCORRECTED, 0, "filename length is zero");
+ }
+ if ((pathlen + newlen) - strlen(newpath) > 3) {
+ die(FSCK_UNCORRECTED, 0, "bad filename length");
+ }
+ expand_fs(newpath, child);
+
+ offset += newlen;
+
+ if (offset <= start_dir) {
+ die(FSCK_UNCORRECTED, 0, "bad inode offset");
+ }
+ if (offset > end_dir) {
+ end_dir = offset;
+ }
+ iput(child); /* free(child) */
+ }
+ free(newpath);
+}
+
+static void do_file(char *path, struct cramfs_inode *i)
+{
+ unsigned long offset = i->offset << 2;
+ int fd = 0;
+
+ if (offset == 0 && i->size != 0) {
+ die(FSCK_UNCORRECTED, 0, "file inode has zero offset and non-zero size");
+ }
+ if (i->size == 0 && offset != 0) {
+ die(FSCK_UNCORRECTED, 0, "file inode has zero size and non-zero offset");
+ }
+ if (offset != 0 && offset < start_data) {
+ start_data = offset;
+ }
+ if (opt_verbose) {
+ print_node('f', i, path);
+ }
+ if (opt_extract) {
+ fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, i->mode);
+ if (fd < 0) {
+ die(FSCK_ERROR, 1, "open failed: %s", path);
+ }
+ }
+ if (i->size) {
+ do_uncompress(path, fd, offset, i->size);
+ }
+ if (opt_extract) {
+ close(fd);
+ change_file_status(path, i);
+ }
+}
+
+static void do_symlink(char *path, struct cramfs_inode *i)
+{
+ unsigned long offset = i->offset << 2;
+ unsigned long curr = offset + 4;
+ unsigned long next = *(u32 *) romfs_read(offset);
+ unsigned long size;
+
+ if (offset == 0) {
+ die(FSCK_UNCORRECTED, 0, "symbolic link has zero offset");
+ }
+ if (i->size == 0) {
+ die(FSCK_UNCORRECTED, 0, "symbolic link has zero size");
+ }
+
+ if (offset < start_data) {
+ start_data = offset;
+ }
+ if (next > end_data) {
+ end_data = next;
+ }
+
+ size = uncompress_block(romfs_read(curr), next - curr);
+ if (size != i->size) {
+ die(FSCK_UNCORRECTED, 0, "size error in symlink: %s", path);
+ }
+ outbuffer[size] = 0;
+ if (opt_verbose) {
+ char *str;
+
+ asprintf(&str, "%s -> %s", path, outbuffer);
+ print_node('l', i, str);
+ if (opt_verbose > 1) {
+ printf(" uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
+ }
+ free(str);
+ }
+ if (opt_extract) {
+ if (symlink(outbuffer, path) < 0) {
+ die(FSCK_ERROR, 1, "symlink failed: %s", path);
+ }
+ change_file_status(path, i);
+ }
+}
+
+static void do_special_inode(char *path, struct cramfs_inode *i)
+{
+ dev_t devtype = 0;
+ char type;
+
+ if (i->offset) { /* no need to shift offset */
+ die(FSCK_UNCORRECTED, 0, "special file has non-zero offset: %s", path);
+ }
+ if (S_ISCHR(i->mode)) {
+ devtype = i->size;
+ type = 'c';
+ }
+ else if (S_ISBLK(i->mode)) {
+ devtype = i->size;
+ type = 'b';
+ }
+ else if (S_ISFIFO(i->mode)) {
+ if (i->size != 0) {
+ die(FSCK_UNCORRECTED, 0, "fifo has non-zero size: %s", path);
+ }
+ type = 'p';
+ }
+ else if (S_ISSOCK(i->mode)) {
+ if (i->size != 0) {
+ die(FSCK_UNCORRECTED, 0, "socket has non-zero size: %s", path);
+ }
+ type = 's';
+ }
+ else {
+ die(FSCK_UNCORRECTED, 0, "bogus mode: %s (%o)", path, i->mode);
+ return; /* not reached */
+ }
+
+ if (opt_verbose) {
+ print_node(type, i, path);
+ }
+
+ if (opt_extract) {
+ if (mknod(path, i->mode, devtype) < 0) {
+ die(FSCK_ERROR, 1, "mknod failed: %s", path);
+ }
+ change_file_status(path, i);
+ }
+}
+
+static void expand_fs(char *path, struct cramfs_inode *inode)
+{
+ if (S_ISDIR(inode->mode)) {
+ do_directory(path, inode);
+ }
+ else if (S_ISREG(inode->mode)) {
+ do_file(path, inode);
+ }
+ else if (S_ISLNK(inode->mode)) {
+ do_symlink(path, inode);
+ }
+ else {
+ do_special_inode(path, inode);
+ }
+}
+
+static void test_fs(int start)
+{
+ struct cramfs_inode *root;
+
+ root = read_super();
+ umask(0);
+ euid = geteuid();
+ stream.next_in = NULL;
+ stream.avail_in = 0;
+ inflateInit(&stream);
+ expand_fs(extract_dir, root);
+ inflateEnd(&stream);
+ if (start_data != ~0UL) {
+ if (start_data < (sizeof(struct cramfs_super) + start)) {
+ die(FSCK_UNCORRECTED, 0, "directory data start (%ld) < sizeof(struct cramfs_super) + start (%ld)", start_data, sizeof(struct cramfs_super) + start);
+ }
+ if (end_dir != start_data) {
+ die(FSCK_UNCORRECTED, 0, "directory data end (%ld) != file data start (%ld)", end_dir, start_data);
+ }
+ }
+ if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
+ if (end_data > super.size) {
+ die(FSCK_UNCORRECTED, 0, "invalid file data offset");
+ }
+ }
+ iput(root); /* free(root) */
+}
+#endif /* INCLUDE_FS_TESTS */
+
+int main(int argc, char **argv)
+{
+ int c; /* for getopt */
+ int start = 0;
+ size_t length;
+
+ page_size = sysconf(_SC_PAGESIZE);
+
+ if (argc)
+ progname = argv[0];
+
+ outbuffer = malloc(page_size * 2);
+ if (!outbuffer)
+ die(FSCK_ERROR, 1, "failed to allocate outbuffer");
+
+ /* command line options */
+ while ((c = getopt(argc, argv, "hx:v")) != EOF) {
+ switch (c) {
+ case 'h':
+ usage(FSCK_OK);
+ case 'x':
+#ifdef INCLUDE_FS_TESTS
+ opt_extract = 1;
+ extract_dir = optarg;
+ break;
+#else /* not INCLUDE_FS_TESTS */
+ die(FSCK_USAGE, 0, "compiled without -x support");
+#endif /* not INCLUDE_FS_TESTS */
+ case 'v':
+ opt_verbose++;
+ break;
+ }
+ }
+
+ if ((argc - optind) != 1)
+ usage(FSCK_USAGE);
+ filename = argv[optind];
+
+ test_super(&start, &length);
+ test_crc(start);
+#ifdef INCLUDE_FS_TESTS
+ test_fs(start);
+#endif /* INCLUDE_FS_TESTS */
+
+ if (opt_verbose) {
+ printf("%s: OK\n", filename);
+ }
+
+ exit(FSCK_OK);
+}
+
+/*
+ * Local variables:
+ * c-file-style: "linux"
+ * End:
+ */
diff --git a/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h
new file mode 100644
index 0000000000..a8948f34b7
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs.h
@@ -0,0 +1,98 @@
+#ifndef __CRAMFS_H
+#define __CRAMFS_H
+
+#ifndef __KERNEL__
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
+
+#endif
+
+#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
+#define CRAMFS_SIGNATURE "Compressed ROMFS"
+
+/*
+ * Width of various bitfields in struct cramfs_inode.
+ * Primarily used to generate warnings in mkcramfs.
+ */
+#define CRAMFS_MODE_WIDTH 16
+#define CRAMFS_UID_WIDTH 16
+#define CRAMFS_SIZE_WIDTH 24
+#define CRAMFS_GID_WIDTH 8
+#define CRAMFS_NAMELEN_WIDTH 6
+#define CRAMFS_OFFSET_WIDTH 26
+
+/*
+ * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
+ * path length is 63 << 2 = 252.
+ */
+#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
+
+/*
+ * Reasonably terse representation of the inode data.
+ */
+struct cramfs_inode {
+ u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
+ /* SIZE for device files is i_rdev */
+ u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
+ /* NAMELEN is the length of the file name, divided by 4 and
+ rounded up. (cramfs doesn't support hard links.) */
+ /* OFFSET: For symlinks and non-empty regular files, this
+ contains the offset (divided by 4) of the file data in
+ compressed form (starting with an array of block pointers;
+ see README). For non-empty directories it is the offset
+ (divided by 4) of the inode of the first file in that
+ directory. For anything else, offset is zero. */
+ u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
+};
+
+struct cramfs_info {
+ u32 crc;
+ u32 edition;
+ u32 blocks;
+ u32 files;
+};
+
+/*
+ * Superblock information at the beginning of the FS.
+ */
+struct cramfs_super {
+ u32 magic; /* 0x28cd3d45 - random number */
+ u32 size; /* length in bytes */
+ u32 flags; /* feature flags */
+ u32 future; /* reserved for future use */
+ u8 signature[16]; /* "Compressed ROMFS" */
+ struct cramfs_info fsid; /* unique filesystem info */
+ u8 name[16]; /* user-defined name */
+ struct cramfs_inode root; /* root inode data */
+};
+
+/*
+ * Feature flags
+ *
+ * 0x00000000 - 0x000000ff: features that work for all past kernels
+ * 0x00000100 - 0xffffffff: features that don't work for past kernels
+ */
+#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
+#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
+#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
+#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
+#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
+
+/*
+ * Valid values in super.flags. Currently we refuse to mount
+ * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
+ * changed to test super.future instead.
+ */
+#define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \
+ | CRAMFS_FLAG_HOLES \
+ | CRAMFS_FLAG_WRONG_SIGNATURE \
+ | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
+
+/* Uncompression interfaces to the underlying zlib */
+int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
+int cramfs_uncompress_init(void);
+int cramfs_uncompress_exit(void);
+
+#endif
diff --git a/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h
new file mode 100644
index 0000000000..afea368796
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/linux/cramfs_fs_sb.h
@@ -0,0 +1,15 @@
+#ifndef _CRAMFS_FS_SB
+#define _CRAMFS_FS_SB
+
+/*
+ * cramfs super-block data in memory
+ */
+struct cramfs_sb_info {
+ unsigned long magic;
+ unsigned long size;
+ unsigned long blocks;
+ unsigned long files;
+ unsigned long flags;
+};
+
+#endif
diff --git a/utils/ypr0tools/cramfs-1.1/mkcramfs.c b/utils/ypr0tools/cramfs-1.1/mkcramfs.c
new file mode 100644
index 0000000000..2eccb733be
--- /dev/null
+++ b/utils/ypr0tools/cramfs-1.1/mkcramfs.c
@@ -0,0 +1,889 @@
+/*
+ * mkcramfs - make a cramfs file system
+ *
+ * Copyright (C) 1999-2002 Transmeta Corporation
+ *
+ * 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * If you change the disk format of cramfs, please update fs/cramfs/README.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <stdarg.h>
+#include <linux/cramfs_fs.h>
+#include <zlib.h>
+#include <stdint.h>
+
+/* Exit codes used by mkfs-type programs */
+#define MKFS_OK 0 /* No errors */
+#define MKFS_ERROR 8 /* Operational error */
+#define MKFS_USAGE 16 /* Usage or syntax error */
+
+/* The kernel only supports PAD_SIZE of 0 and 512. */
+#define PAD_SIZE 512
+
+/*
+ * The longest filename component to allow for in the input directory tree.
+ * ext2fs (and many others) allow up to 255 bytes. A couple of filesystems
+ * allow longer (e.g. smbfs 1024), but there isn't much use in supporting
+ * >255-byte names in the input directory tree given that such names get
+ * truncated to CRAMFS_MAXPATHLEN (252 bytes) when written to cramfs.
+ *
+ * Old versions of mkcramfs generated corrupted filesystems if any input
+ * filenames exceeded CRAMFS_MAXPATHLEN (252 bytes), however old
+ * versions of cramfsck seem to have been able to detect the corruption.
+ */
+#define MAX_INPUT_NAMELEN 255
+
+/*
+ * Maximum size fs you can create is roughly 256MB. (The last file's
+ * data must begin within 256MB boundary but can extend beyond that.)
+ *
+ * Note that if you want it to fit in a ROM then you're limited to what the
+ * hardware and kernel can support.
+ */
+#define MAXFSLEN ((((1 << CRAMFS_OFFSET_WIDTH) - 1) << 2) /* offset */ \
+ + (1 << CRAMFS_SIZE_WIDTH) - 1 /* filesize */ \
+ + (1 << CRAMFS_SIZE_WIDTH) * 4 / blksize /* block pointers */ )
+
+static const char *progname = "mkcramfs";
+static unsigned int blksize;
+static long total_blocks = 0, total_nodes = 1; /* pre-count the root node */
+static int image_length = 0;
+
+/*
+ * If opt_holes is set, then mkcramfs can create explicit holes in the
+ * data, which saves 26 bytes per hole (which is a lot smaller a
+ * saving than most most filesystems).
+ *
+ * Note that kernels up to at least 2.3.39 don't support cramfs holes,
+ * which is why this is turned off by default.
+ *
+ * If opt_verbose is 1, be verbose. If it is higher, be even more verbose.
+ */
+static u32 opt_edition = 0;
+static int opt_errors = 0;
+static int opt_holes = 0;
+static int opt_pad = 0;
+static int opt_verbose = 0;
+static char *opt_image = NULL;
+static char *opt_name = NULL;
+
+static int warn_dev, warn_gid, warn_namelen, warn_skip, warn_size, warn_uid;
+
+/* In-core version of inode / directory entry. */
+struct entry {
+ /* stats */
+ unsigned char *name;
+ unsigned int mode, size, uid, gid;
+
+ /* these are only used for non-empty files */
+ char *path; /* always null except non-empty files */
+ int fd; /* temporarily open files while mmapped */
+
+ /* FS data */
+ void *uncompressed;
+ /* points to other identical file */
+ struct entry *same;
+ unsigned int offset; /* pointer to compressed data in archive */
+ unsigned int dir_offset; /* Where in the archive is the directory entry? */
+
+ /* organization */
+ struct entry *child; /* null for non-directories and empty directories */
+ struct entry *next;
+};
+
+/* Input status of 0 to print help and exit without an error. */
+static void usage(int status)
+{
+ FILE *stream = status ? stderr : stdout;
+
+ fprintf(stream, "usage: %s [-h] [-b blksize] [-e edition] [-i file] [-n name] dirname outfile\n"
+ " -h print this help\n"
+ " -E make all warnings errors (non-zero exit status)\n"
+ " -b blksize blocksize to use\n"
+ " -e edition set edition number (part of fsid)\n"
+ " -i file insert a file image into the filesystem (requires >= 2.4.0)\n"
+ " -n name set name of cramfs filesystem\n"
+ " -p pad by %d bytes for boot code\n"
+ " -s sort directory entries (old option, ignored)\n"
+ " -v be more verbose\n"
+ " -z make explicit holes (requires >= 2.3.39)\n"
+ " dirname root of the directory tree to be compressed\n"
+ " outfile output file\n", progname, PAD_SIZE);
+
+ exit(status);
+}
+
+static void die(int status, int syserr, const char *fmt, ...)
+{
+ va_list arg_ptr;
+ int save = errno;
+
+ fflush(0);
+ va_start(arg_ptr, fmt);
+ fprintf(stderr, "%s: ", progname);
+ vfprintf(stderr, fmt, arg_ptr);
+ if (syserr) {
+ fprintf(stderr, ": %s", strerror(save));
+ }
+ fprintf(stderr, "\n");
+ va_end(arg_ptr);
+ exit(status);
+}
+
+static void map_entry(struct entry *entry)
+{
+ if (entry->path) {
+ entry->fd = open(entry->path, O_RDONLY);
+ if (entry->fd < 0) {
+ die(MKFS_ERROR, 1, "open failed: %s", entry->path);
+ }
+ entry->uncompressed = mmap(NULL, entry->size, PROT_READ, MAP_PRIVATE, entry->fd, 0);
+ if (entry->uncompressed == MAP_FAILED) {
+ die(MKFS_ERROR, 1, "mmap failed: %s", entry->path);
+ }
+ }
+}
+
+static void unmap_entry(struct entry *entry)
+{
+ if (entry->path) {
+ if (munmap(entry->uncompressed, entry->size) < 0) {
+ die(MKFS_ERROR, 1, "munmap failed: %s", entry->path);
+ }
+ close(entry->fd);
+ }
+}
+
+static int find_identical_file(struct entry *orig, struct entry *newfile)
+{
+ if (orig == newfile)
+ return 1;
+ if (!orig)
+ return 0;
+ if (orig->size == newfile->size && (orig->path || orig->uncompressed))
+ {
+ map_entry(orig);
+ map_entry(newfile);
+ if (!memcmp(orig->uncompressed, newfile->uncompressed, orig->size))
+ {
+ newfile->same = orig;
+ unmap_entry(newfile);
+ unmap_entry(orig);
+ return 1;
+ }
+ unmap_entry(newfile);
+ unmap_entry(orig);
+ }
+ return (find_identical_file(orig->child, newfile) ||
+ find_identical_file(orig->next, newfile));
+}
+
+static void eliminate_doubles(struct entry *root, struct entry *orig) {
+ if (orig) {
+ if (orig->size && (orig->path || orig->uncompressed))
+ find_identical_file(root, orig);
+ eliminate_doubles(root, orig->child);
+ eliminate_doubles(root, orig->next);
+ }
+}
+
+/*
+ * We define our own sorting function instead of using alphasort which
+ * uses strcoll and changes ordering based on locale information.
+ */
+static int cramsort (const void *a, const void *b)
+{
+ return strcmp ((*(const struct dirent **) a)->d_name,
+ (*(const struct dirent **) b)->d_name);
+}
+
+static unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, loff_t *fslen_ub)
+{
+ struct dirent **dirlist;
+ int totalsize = 0, dircount, dirindex;
+ char *path, *endpath;
+ size_t len = strlen(name);
+
+ /* Set up the path. */
+ /* TODO: Reuse the parent's buffer to save memcpy'ing and duplication. */
+ path = malloc(len + 1 + MAX_INPUT_NAMELEN + 1);
+ if (!path) {
+ die(MKFS_ERROR, 1, "malloc failed");
+ }
+ memcpy(path, name, len);
+ endpath = path + len;
+ *endpath = '/';
+ endpath++;
+
+ /* read in the directory and sort */
+ dircount = scandir(name, &dirlist, 0, cramsort);
+
+ if (dircount < 0) {
+ die(MKFS_ERROR, 1, "scandir failed: %s", name);
+ }
+
+ /* process directory */
+ for (dirindex = 0; dirindex < dircount; dirindex++) {
+ struct dirent *dirent;
+ struct entry *entry;
+ struct stat st;
+ int size;
+ size_t namelen;
+
+ dirent = dirlist[dirindex];
+
+ /* Ignore "." and ".." - we won't be adding them to the archive */
+ if (dirent->d_name[0] == '.') {
+ if (dirent->d_name[1] == '\0')
+ continue;
+ if (dirent->d_name[1] == '.') {
+ if (dirent->d_name[2] == '\0')
+ continue;
+ }
+ }
+ namelen = strlen(dirent->d_name);
+ if (namelen > MAX_INPUT_NAMELEN) {
+ die(MKFS_ERROR, 0,
+ "very long (%u bytes) filename found: %s\n"
+ "please increase MAX_INPUT_NAMELEN in mkcramfs.c and recompile",
+ namelen, dirent->d_name);
+ }
+ memcpy(endpath, dirent->d_name, namelen + 1);
+
+ if (lstat(path, &st) < 0) {
+ warn_skip = 1;
+ continue;
+ }
+ entry = calloc(1, sizeof(struct entry));
+ if (!entry) {
+ die(MKFS_ERROR, 1, "calloc failed");
+ }
+ entry->name = strdup(dirent->d_name);
+ if (!entry->name) {
+ die(MKFS_ERROR, 1, "strdup failed");
+ }
+ /* truncate multi-byte UTF-8 filenames on character boundary */
+ if (namelen > CRAMFS_MAXPATHLEN) {
+ namelen = CRAMFS_MAXPATHLEN;
+ warn_namelen = 1;
+ /* the first lost byte must not be a trail byte */
+ while ((entry->name[namelen] & 0xc0) == 0x80) {
+ namelen--;
+ /* are we reasonably certain it was UTF-8 ? */
+ if (entry->name[namelen] < 0x80 || !namelen) {
+ die(MKFS_ERROR, 0, "cannot truncate filenames not encoded in UTF-8");
+ }
+ }
+ entry->name[namelen] = '\0';
+ }
+ entry->mode = st.st_mode;
+ entry->size = st.st_size;
+ entry->uid = st.st_uid;
+ if (entry->uid >= 1 << CRAMFS_UID_WIDTH)
+ warn_uid = 1;
+ entry->gid = st.st_gid;
+ if (entry->gid >= 1 << CRAMFS_GID_WIDTH)
+ /* TODO: We ought to replace with a default
+ gid instead of truncating; otherwise there
+ are security problems. Maybe mode should
+ be &= ~070. Same goes for uid once Linux
+ supports >16-bit uids. */
+ warn_gid = 1;
+ size = sizeof(struct cramfs_inode) + ((namelen + 3) & ~3);
+ *fslen_ub += size;
+ if (S_ISDIR(st.st_mode)) {
+ entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);
+ } else if (S_ISREG(st.st_mode)) {
+ if (entry->size) {
+ if (access(path, R_OK) < 0) {
+ warn_skip = 1;
+ continue;
+ }
+ entry->path = strdup(path);
+ if (!entry->path) {
+ die(MKFS_ERROR, 1, "strdup failed");
+ }
+ if ((entry->size >= 1 << CRAMFS_SIZE_WIDTH)) {
+ warn_size = 1;
+ entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
+ }
+ }
+ } else if (S_ISLNK(st.st_mode)) {
+ int len;
+ entry->uncompressed = malloc(entry->size);
+ if (!entry->uncompressed) {
+ die(MKFS_ERROR, 1, "malloc failed");
+ }
+ len = readlink(path, entry->uncompressed, entry->size);
+ if (len < 0) {
+ warn_skip = 1;
+ continue;
+ }
+ entry->size = len;
+ } else if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
+ /* maybe we should skip sockets */
+ entry->size = 0;
+ } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
+ entry->size = st.st_rdev;
+ if (entry->size & -(1<<CRAMFS_SIZE_WIDTH))
+ warn_dev = 1;
+ } else {
+ die(MKFS_ERROR, 0, "bogus file type: %s", entry->name);
+ }
+
+ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
+ int blocks = ((entry->size - 1) / blksize + 1);
+
+ /* block pointers & data expansion allowance + data */
+ if (entry->size)
+ *fslen_ub += (4+26)*blocks + entry->size + 3;
+ }
+
+ /* Link it into the list */
+ *prev = entry;
+ prev = &entry->next;
+ totalsize += size;
+ }
+ free(path);
+ free(dirlist); /* allocated by scandir() with malloc() */
+ return totalsize;
+}
+
+/* Returns sizeof(struct cramfs_super), which includes the root inode. */
+static unsigned int write_superblock(struct entry *root, char *base, int size)
+{
+ struct cramfs_super *super = (struct cramfs_super *) base;
+ unsigned int offset = sizeof(struct cramfs_super) + image_length;
+
+ offset += opt_pad; /* 0 if no padding */
+
+ super->magic = CRAMFS_MAGIC;
+ super->flags = CRAMFS_FLAG_FSID_VERSION_2 | CRAMFS_FLAG_SORTED_DIRS;
+ if (opt_holes)
+ super->flags |= CRAMFS_FLAG_HOLES;
+ if (image_length > 0)
+ super->flags |= CRAMFS_FLAG_SHIFTED_ROOT_OFFSET;
+ super->size = size;
+ memcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));
+
+ super->fsid.crc = crc32(0L, Z_NULL, 0);
+ super->fsid.edition = opt_edition;
+ super->fsid.blocks = total_blocks;
+ super->fsid.files = total_nodes;
+
+ memset(super->name, 0x00, sizeof(super->name));
+ if (opt_name)
+ strncpy(super->name, opt_name, sizeof(super->name));
+ else
+ strncpy(super->name, "Compressed", sizeof(super->name));
+
+ super->root.mode = root->mode;
+ super->root.uid = root->uid;
+ super->root.gid = root->gid;
+ super->root.size = root->size;
+ super->root.offset = offset >> 2;
+
+ return offset;
+}
+
+static void set_data_offset(struct entry *entry, char *base, unsigned long offset)
+{
+ struct cramfs_inode *inode = (struct cramfs_inode *) (base + entry->dir_offset);
+
+ if ((offset & 3) != 0) {
+ die(MKFS_ERROR, 0, "illegal offset of %lu bytes", offset);
+ }
+ if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {
+ die(MKFS_ERROR, 0, "filesystem too big");
+ }
+ inode->offset = (offset >> 2);
+}
+
+/*
+ * TODO: Does this work for chars >= 0x80? Most filesystems use UTF-8
+ * encoding for filenames, whereas the console is a single-byte
+ * character set like iso-latin-1.
+ */
+static void print_node(struct entry *e)
+{
+ char info[10];
+ char type = '?';
+
+ if (S_ISREG(e->mode)) type = 'f';
+ else if (S_ISDIR(e->mode)) type = 'd';
+ else if (S_ISLNK(e->mode)) type = 'l';
+ else if (S_ISCHR(e->mode)) type = 'c';
+ else if (S_ISBLK(e->mode)) type = 'b';
+ else if (S_ISFIFO(e->mode)) type = 'p';
+ else if (S_ISSOCK(e->mode)) type = 's';
+
+ if (S_ISCHR(e->mode) || (S_ISBLK(e->mode))) {
+ /* major/minor numbers can be as high as 2^12 or 4096 */
+ snprintf(info, 10, "%4d,%4d", major(e->size), minor(e->size));
+ }
+ else {
+ /* size be as high as 2^24 or 16777216 */
+ snprintf(info, 10, "%9d", e->size);
+ }
+
+ printf("%c %04o %s %5d:%-3d %s\n",
+ type, e->mode & ~S_IFMT, info, e->uid, e->gid, e->name);
+}
+
+/*
+ * We do a width-first printout of the directory
+ * entries, using a stack to remember the directories
+ * we've seen.
+ */
+static unsigned int write_directory_structure(struct entry *entry, char *base, unsigned int offset)
+{
+ int stack_entries = 0;
+ int stack_size = 64;
+ struct entry **entry_stack;
+
+ entry_stack = malloc(stack_size * sizeof(struct entry *));
+ if (!entry_stack) {
+ die(MKFS_ERROR, 1, "malloc failed");
+ }
+
+ if (opt_verbose) {
+ printf("root:\n");
+ }
+
+ for (;;) {
+ int dir_start = stack_entries;
+ while (entry) {
+ struct cramfs_inode *inode = (struct cramfs_inode *) (base + offset);
+ size_t len = strlen(entry->name);
+
+ entry->dir_offset = offset;
+
+ inode->mode = entry->mode;
+ inode->uid = entry->uid;
+ inode->gid = entry->gid;
+ inode->size = entry->size;
+ inode->offset = 0;
+ /* Non-empty directories, regfiles and symlinks will
+ write over inode->offset later. */
+
+ offset += sizeof(struct cramfs_inode);
+ total_nodes++; /* another node */
+ memcpy(base + offset, entry->name, len);
+ /* Pad up the name to a 4-byte boundary */
+ while (len & 3) {
+ *(base + offset + len) = '\0';
+ len++;
+ }
+ inode->namelen = len >> 2;
+ offset += len;
+
+ if (opt_verbose)
+ print_node(entry);
+
+ if (entry->child) {
+ if (stack_entries >= stack_size) {
+ stack_size *= 2;
+ entry_stack = realloc(entry_stack, stack_size * sizeof(struct entry *));
+ if (!entry_stack) {
+ die(MKFS_ERROR, 1, "realloc failed");
+ }
+ }
+ entry_stack[stack_entries] = entry;
+ stack_entries++;
+ }
+ entry = entry->next;
+ }
+
+ /*
+ * Reverse the order the stack entries pushed during
+ * this directory, for a small optimization of disk
+ * access in the created fs. This change makes things
+ * `ls -UR' order.
+ */
+ {
+ struct entry **lo = entry_stack + dir_start;
+ struct entry **hi = entry_stack + stack_entries;
+ struct entry *tmp;
+
+ while (lo < --hi) {
+ tmp = *lo;
+ *lo++ = *hi;
+ *hi = tmp;
+ }
+ }
+
+ /* Pop a subdirectory entry from the stack, and recurse. */
+ if (!stack_entries)
+ break;
+ stack_entries--;
+ entry = entry_stack[stack_entries];
+
+ set_data_offset(entry, base, offset);
+ if (opt_verbose) {
+ printf("%s:\n", entry->name);
+ }
+ entry = entry->child;
+ }
+ free(entry_stack);
+ return offset;
+}
+
+static int is_zero(char const *begin, unsigned len)
+{
+ /* Returns non-zero iff the first LEN bytes from BEGIN are all NULs. */
+ return (len-- == 0 ||
+ (begin[0] == '\0' &&
+ (len-- == 0 ||
+ (begin[1] == '\0' &&
+ (len-- == 0 ||
+ (begin[2] == '\0' &&
+ (len-- == 0 ||
+ (begin[3] == '\0' &&
+ memcmp(begin, begin + 4, len) == 0))))))));
+}
+
+/*
+ * One 4-byte pointer per block and then the actual blocked
+ * output. The first block does not need an offset pointer,
+ * as it will start immediately after the pointer block;
+ * so the i'th pointer points to the end of the i'th block
+ * (i.e. the start of the (i+1)'th block or past EOF).
+ *
+ * Note that size > 0, as a zero-sized file wouldn't ever
+ * have gotten here in the first place.
+ */
+static unsigned int do_compress(char *base, unsigned int offset, char const *name, char *uncompressed, unsigned int size)
+{
+ unsigned long original_size = size;
+ unsigned long original_offset = offset;
+ unsigned long new_size;
+ unsigned long blocks = (size - 1) / blksize + 1;
+ unsigned long curr = offset + 4 * blocks;
+ int change;
+
+ total_blocks += blocks;
+
+ do {
+ unsigned long len = 2 * blksize;
+ unsigned int input = size;
+ int err;
+
+ if (input > blksize)
+ input = blksize;
+ size -= input;
+ if (!(opt_holes && is_zero (uncompressed, input))) {
+ err = compress2(base + curr, &len, uncompressed, input, Z_BEST_COMPRESSION);
+ if (err != Z_OK) {
+ die(MKFS_ERROR, 0, "compression error: %s", zError(err));
+ }
+ curr += len;
+ }
+ uncompressed += input;
+
+ if (len > blksize*2) {
+ /* (I don't think this can happen with zlib.) */
+ die(MKFS_ERROR, 0, "AIEEE: block \"compressed\" to > 2*blocklength (%ld)", len);
+ }
+
+ *(u32 *) (base + offset) = curr;
+ offset += 4;
+ } while (size);
+
+ curr = (curr + 3) & ~3;
+ new_size = curr - original_offset;
+ /* TODO: Arguably, original_size in these 2 lines should be
+ st_blocks * 512. But if you say that then perhaps
+ administrative data should also be included in both. */
+ change = new_size - original_size;
+ if (opt_verbose > 1) {
+ printf("%6.2f%% (%+d bytes)\t%s\n",
+ (change * 100) / (double) original_size, change, name);
+ }
+
+ return curr;
+}
+
+
+/*
+ * Traverse the entry tree, writing data for every item that has
+ * non-null entry->path (i.e. every non-empty regfile) and non-null
+ * entry->uncompressed (i.e. every symlink).
+ */
+static unsigned int write_data(struct entry *entry, char *base, unsigned int offset)
+{
+ do {
+ if (entry->path || entry->uncompressed) {
+ if (entry->same) {
+ set_data_offset(entry, base, entry->same->offset);
+ entry->offset = entry->same->offset;
+ }
+ else {
+ set_data_offset(entry, base, offset);
+ entry->offset = offset;
+ map_entry(entry);
+ offset = do_compress(base, offset, entry->name, entry->uncompressed, entry->size);
+ unmap_entry(entry);
+ }
+ }
+ else if (entry->child)
+ offset = write_data(entry->child, base, offset);
+ entry=entry->next;
+ } while (entry);
+ return offset;
+}
+
+static unsigned int write_file(char *file, char *base, unsigned int offset)
+{
+ int fd;
+ char *buf;
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ die(MKFS_ERROR, 1, "open failed: %s", file);
+ }
+ buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (buf == MAP_FAILED) {
+ die(MKFS_ERROR, 1, "mmap failed");
+ }
+ memcpy(base + offset, buf, image_length);
+ munmap(buf, image_length);
+ close (fd);
+ /* Pad up the image_length to a 4-byte boundary */
+ while (image_length & 3) {
+ *(base + offset + image_length) = '\0';
+ image_length++;
+ }
+ return (offset + image_length);
+}
+
+int main(int argc, char **argv)
+{
+ struct stat st; /* used twice... */
+ struct entry *root_entry;
+ char *rom_image;
+ ssize_t offset, written;
+ int fd;
+ /* initial guess (upper-bound) of required filesystem size */
+ loff_t fslen_ub = sizeof(struct cramfs_super);
+ char const *dirname, *outfile;
+ u32 crc;
+ int c; /* for getopt */
+ char *ep; /* for strtoul */
+
+ blksize = sysconf(_SC_PAGESIZE);
+ total_blocks = 0;
+
+ if (argc)
+ progname = argv[0];
+
+ /* command line options */
+ while ((c = getopt(argc, argv, "hEb:e:i:n:psvz")) != EOF) {
+ switch (c) {
+ case 'h':
+ usage(MKFS_OK);
+ case 'E':
+ opt_errors = 1;
+ break;
+ case 'b':
+ errno = 0;
+ blksize = strtoul(optarg, &ep, 10);
+ if (errno || optarg[0] == '\0' || *ep != '\0')
+ usage(MKFS_USAGE);
+ if (blksize < 512 || (blksize & (blksize - 1)))
+ die(MKFS_ERROR, 0, "invalid blocksize: %u", blksize);
+ break;
+ case 'e':
+ errno = 0;
+ opt_edition = strtoul(optarg, &ep, 10);
+ if (errno || optarg[0] == '\0' || *ep != '\0')
+ usage(MKFS_USAGE);
+ break;
+ case 'i':
+ opt_image = optarg;
+ if (lstat(opt_image, &st) < 0) {
+ die(MKFS_ERROR, 1, "lstat failed: %s", opt_image);
+ }
+ image_length = st.st_size; /* may be padded later */
+ fslen_ub += (image_length + 3); /* 3 is for padding */
+ break;
+ case 'n':
+ opt_name = optarg;
+ break;
+ case 'p':
+ opt_pad = PAD_SIZE;
+ fslen_ub += PAD_SIZE;
+ break;
+ case 's':
+ /* old option, ignored */
+ break;
+ case 'v':
+ opt_verbose++;
+ break;
+ case 'z':
+ opt_holes = 1;
+ break;
+ }
+ }
+
+ if ((argc - optind) != 2)
+ usage(MKFS_USAGE);
+ dirname = argv[optind];
+ outfile = argv[optind + 1];
+
+ if (stat(dirname, &st) < 0) {
+ die(MKFS_USAGE, 1, "stat failed: %s", dirname);
+ }
+ fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0) {
+ die(MKFS_USAGE, 1, "open failed: %s", outfile);
+ }
+
+ root_entry = calloc(1, sizeof(struct entry));
+ if (!root_entry) {
+ die(MKFS_ERROR, 1, "calloc failed");
+ }
+ root_entry->mode = st.st_mode;
+ root_entry->uid = st.st_uid;
+ root_entry->gid = st.st_gid;
+
+ root_entry->size = parse_directory(root_entry, dirname, &root_entry->child, &fslen_ub);
+
+ /* always allocate a multiple of blksize bytes because that's
+ what we're going to write later on */
+ fslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1;
+
+ if (fslen_ub > MAXFSLEN) {
+ fprintf(stderr,
+ "warning: estimate of required size (upper bound) is %jdMB, but maximum image size is %uMB, we might die prematurely\n",
+ (intmax_t) (fslen_ub >> 20),
+ MAXFSLEN >> 20);
+ fslen_ub = MAXFSLEN;
+ }
+
+ /* find duplicate files. TODO: uses the most inefficient algorithm
+ possible. */
+ eliminate_doubles(root_entry, root_entry);
+
+ /* TODO: Why do we use a private/anonymous mapping here
+ followed by a write below, instead of just a shared mapping
+ and a couple of ftruncate calls? Is it just to save us
+ having to deal with removing the file afterwards? If we
+ really need this huge anonymous mapping, we ought to mmap
+ in smaller chunks, so that the user doesn't need nn MB of
+ RAM free. If the reason is to be able to write to
+ un-mmappable block devices, then we could try shared mmap
+ and revert to anonymous mmap if the shared mmap fails. */
+ rom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+ if (rom_image == MAP_FAILED) {
+ die(MKFS_ERROR, 1, "mmap failed");
+ }
+
+ /* Skip the first opt_pad bytes for boot loader code */
+ offset = opt_pad;
+ memset(rom_image, 0x00, opt_pad);
+
+ /* Skip the superblock and come back to write it later. */
+ offset += sizeof(struct cramfs_super);
+
+ /* Insert a file image. */
+ if (opt_image) {
+ printf("Including: %s\n", opt_image);
+ offset = write_file(opt_image, rom_image, offset);
+ }
+
+ offset = write_directory_structure(root_entry->child, rom_image, offset);
+ printf("Directory data: %zd bytes\n", offset);
+
+ offset = write_data(root_entry, rom_image, offset);
+
+ /* We always write a multiple of blksize bytes, so that
+ losetup works. */
+ offset = ((offset - 1) | (blksize - 1)) + 1;
+ printf("Everything: %zd kilobytes\n", offset >> 10);
+
+ /* Write the superblock now that we can fill in all of the fields. */
+ write_superblock(root_entry, rom_image+opt_pad, offset);
+ printf("Super block: %zd bytes\n", sizeof(struct cramfs_super));
+
+ /* Put the checksum in. */
+ crc = crc32(0L, Z_NULL, 0);
+ crc = crc32(crc, (rom_image+opt_pad), (offset-opt_pad));
+ ((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = crc;
+ printf("CRC: %x\n", crc);
+
+ /* Check to make sure we allocated enough space. */
+ if (fslen_ub < offset) {
+ die(MKFS_ERROR, 0, "not enough space allocated for ROM image (%Ld allocated, %d used)", fslen_ub, offset);
+ }
+
+ written = write(fd, rom_image, offset);
+ if (written < 0) {
+ die(MKFS_ERROR, 1, "write failed");
+ }
+ if (offset != written) {
+ die(MKFS_ERROR, 0, "ROM image write failed (wrote %d of %d bytes): No space left on device?", written, offset);
+ }
+
+ /* (These warnings used to come at the start, but they scroll off the
+ screen too quickly.) */
+ if (warn_namelen)
+ fprintf(stderr, /* bytes, not chars: think UTF-8. */
+ "warning: filenames truncated to %d bytes (possibly less if multi-byte UTF-8)\n",
+ CRAMFS_MAXPATHLEN);
+ if (warn_skip)
+ fprintf(stderr, "warning: files were skipped due to errors\n");
+ if (warn_size)
+ fprintf(stderr,
+ "warning: file sizes truncated to %luMB (minus 1 byte)\n",
+ 1L << (CRAMFS_SIZE_WIDTH - 20));
+ if (warn_uid) /* (not possible with current Linux versions) */
+ fprintf(stderr,
+ "warning: uids truncated to %u bits (this may be a security concern)\n",
+ CRAMFS_UID_WIDTH);
+ if (warn_gid)
+ fprintf(stderr,
+ "warning: gids truncated to %u bits (this may be a security concern)\n",
+ CRAMFS_GID_WIDTH);
+ if (warn_dev)
+ fprintf(stderr,
+ "WARNING: device numbers truncated to %u bits (this almost certainly means\n"
+ "that some device files will be wrong)\n",
+ CRAMFS_OFFSET_WIDTH);
+ if (opt_errors &&
+ (warn_namelen||warn_skip||warn_size||warn_uid||warn_gid||warn_dev))
+ exit(MKFS_ERROR);
+
+ exit(MKFS_OK);
+}
+
+/*
+ * Local variables:
+ * c-file-style: "linux"
+ * End:
+ */
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);
+}
diff --git a/utils/ypr0tools/files/.rockbox/README b/utils/ypr0tools/files/.rockbox/README
new file mode 100644
index 0000000000..f0e306e196
--- /dev/null
+++ b/utils/ypr0tools/files/.rockbox/README
@@ -0,0 +1 @@
+This directory is empty and acts as mount point.
diff --git a/utils/ypr0tools/files/Playlists/README b/utils/ypr0tools/files/Playlists/README
new file mode 100644
index 0000000000..f0e306e196
--- /dev/null
+++ b/utils/ypr0tools/files/Playlists/README
@@ -0,0 +1 @@
+This directory is empty and acts as mount point.
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.raw b/utils/ypr0tools/files/etc/mods/safe_mode.raw
new file mode 100644
index 0000000000..1c1aa61dd1
--- /dev/null
+++ b/utils/ypr0tools/files/etc/mods/safe_mode.raw
Binary files differ
diff --git a/utils/ypr0tools/files/etc/mods/safe_mode.sh b/utils/ypr0tools/files/etc/mods/safe_mode.sh
new file mode 100755
index 0000000000..122b2eabfe
--- /dev/null
+++ b/utils/ypr0tools/files/etc/mods/safe_mode.sh
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+# YP-R0 Safe Mode!!
+# - Part of the "Device Rescue Kit", modded ROM v2.20 and onwards
+# Version: v0.3
+# v0.2 - initial version
+# v0.3 - USB cable check implemented
+# by lorenzo92 aka Memory
+# memoryS60@gmail.com
+
+CustomIMG="/mnt/media1/safe_mode.raw"
+DefIMG="/etc/mods/safe_mode.raw"
+
+timer=0
+# Seconds before turning the device OFF
+timeout=2
+
+shutdown () {
+ sync
+ reboot
+}
+
+cableDaemon () {
+ cd /usr/local/bin
+ while [ 1 ]
+ do
+ if [ $timer -gt $timeout ]
+ then
+ shutdown
+ fi
+
+ if ./minird 0x0a | grep -q 0x00
+ then
+ timer=$(($timer+1))
+ else
+ timer=0
+ fi
+ sleep 1
+ done
+}
+
+# Back button is a \x08\x00\x00\x00 string...
+# ...since bash removes null bytes for us, we must only care the single byte
+var=$(dd if=/dev/r0Btn bs=4 count=1)
+# Here a workaround to detect \x08 byte :S
+var2=$(echo -e -n "\x08")
+if [[ "$var" = "$var2" ]]
+then
+ echo "Safe mode (USB) activated..."
+ # Put the backlight at the minimum level: no energy waste, please ;)
+ # Using low level interface
+
+ cd /usr/local/bin
+ ./afewr 0x1b 0x3 0x8
+
+ # Long press reset time 5 secs
+ [ -e /etc/mods/reset_time_mod.sh ] && /bin/sh /etc/mods/reset_time_mod.sh
+
+ # Clear the screen and show a nice picture :D
+
+ echo -n "1" > /sys/class/graphics/fb0/blank
+ echo -n "0" >> /sys/class/graphics/fb0/blank
+# echo -n "1" > /sys/class/graphics/fb2/blank
+# echo -n "0" >> /sys/class/graphics/fb2/blank
+ if [ -e $CustomIMG ]
+ then
+ cat $CustomIMG > "/dev/fb0"
+ else
+ cat $DefIMG > "/dev/fb0"
+ fi
+
+ # Here the real USB connection stuff
+ # This is slightly modified by me; it was contained in the cramfs shipped with
+ # YP-R0 opensource package...
+
+ lsmod | grep g_file_storage
+ if [ $? == 0 ]
+ then
+ umount /mnt/media1/dev/gadget
+ fi
+ #if [ -d /mnt/media0 ]
+ #then
+ umount /mnt/media1
+ umount /mnt/media0
+ #umount /mnt/mmc
+ #fi
+ lsmod | grep rfs
+ if [ $? == 0 ]
+ then
+ rmmod rfs
+ fi
+ lsmod | grep g_file_storage
+ if [ $? == 0 ]
+ then
+ rmmod gadgetfs
+ rmmod g_file_storage
+ rmmod arcotg_udc
+ fi
+ lsmod | grep g_file_storage
+ if [ $? != 0 ]
+ then
+ modprobe g-file-storage file=/dev/stl3,/dev/stl2,/dev/mmcblk0 removable=1
+ fi
+
+ # Let's implement the check if usb cable is still inserted or not...
+ cableDaemon
+
+ return 1
+else
+ return 0
+fi
diff --git a/utils/ypr0tools/files/etc/profile b/utils/ypr0tools/files/etc/profile
new file mode 100755
index 0000000000..4ba61d7535
--- /dev/null
+++ b/utils/ypr0tools/files/etc/profile
@@ -0,0 +1,66 @@
+export PS1='\u@\h \w$ '
+export PS2='> '
+export PS3='? '
+export PS4='[$LINENO]+'
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
+export LD_LIBRARY_PATH=/mnt/media1/Lib:/mnt/media1/Lib/ExtraLib:/usr/lib
+export FSL_OMX_COMPONENT_REGISTRY="/Sysdata/OpenMaxIL/ComponentRegistry.txt"
+export FSL_OMX_MAX_INDEX_SIZE=1048576
+export MALLOC_CHECK_=0
+
+ulimit -s unlimited
+hwclock -s
+
+alias ls='ls --color=auto'
+alias ll='ls -l --color=auto'
+
+# Start with lorenzo92's safe mode
+SCRIPT="/etc/mods/safe_mode.sh"
+if [ -f $SCRIPT ]
+then
+ /bin/sh $SCRIPT
+ # it returns 1 if usb was connected
+ if [ "$?" = "1" ]
+ then
+ sync
+ sleep 1
+ reboot
+ fi
+fi
+
+if [ -e "/mnt/media1/r0" ]
+then
+ MAINFILE="/mnt/media1/r0"
+elif [ -f "/mnt/media0/r0" ]
+then
+ # copy to media1 since USB wouldn't work
+ cp /mnt/media0/r0 /mnt/media1/r0_media0
+ if [ "$?" = "0" ]
+ then # perhaps cp failed due to insufficient storage or so
+ MAINFILE="/mnt/media1/r0_media0"
+ else
+ MAINFILE="/usr/local/bin/r0"
+ fi
+else
+ MAINFILE="/usr/local/bin/r0"
+fi
+
+# source the rockbox loader script
+SOURCE="/mnt/media0/.rockbox/rockbox.sh"
+[ -f $SOURCE ] && . $SOURCE
+
+# source user script if available
+SOURCE="/mnt/media0/rc.user"
+[ -f $SOURCE ] && . $SOURCE
+
+# finally call the entry point
+if [ -e $MAINFILE ]
+then
+ chmod 777 $MAINFILE
+ $MAINFILE Application AppMain
+ rm -f /mnt/media1/r0_media0
+ sync
+# sleep 5
+ reboot
+fi
diff --git a/utils/ypr0tools/pack-firmware.sh b/utils/ypr0tools/pack-firmware.sh
new file mode 100755
index 0000000000..f3b55548d9
--- /dev/null
+++ b/utils/ypr0tools/pack-firmware.sh
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+######################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+#
+# * Script to generate a Samsung YP-R0 firmware file (R0.ROM) */
+######################################################################
+#
+# This file was oringally called NewPack.sh, its origin is the R0 open source
+# package from Samsung.
+#
+# Muon Platform
+# Copyright (c) 2004-2009 Samsung Electronics, Inc.
+# All rights reserved.
+#
+# Rom Packaging Script
+# It needs sudoer privilege of rm, mkdir, cp, mkcramfs.
+# You can configure it in the /etc/sudoer file.
+# This script is very dangerous. Be careful to use.
+#
+# SangMan Sim<sangman.sim@samsung.com>
+
+# bail out early
+set -e
+
+DIR=${2:-"."}
+DIR=${DIR%/}
+REVISION="$DIR/RevisionInfo.txt"
+CRAMFS="$DIR/cramfs-fsl.rom"
+SYSDATA="$DIR/SYSDATA.bin"
+MBOOT="$DIR/MBoot.bin"
+MBOOT_TMP="${TMP_DIR:-$DIR}/MBoot.tmp"
+LINUX="$DIR/zImage"
+R0ROM=$1
+
+# some sanity checks
+if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+ echo "Usage $0 <rom file> [path to image files]"
+ exit 1
+fi
+
+if [ ! -f ./MuonEncrypt ]; then
+ echo "Couldn't find MuonEncrypt binary (try 'make')"
+ exit 1
+fi
+
+if [ ! -e $REVISION ]; then
+ cat >$REVISION <<EOF
+Version : V2.30
+Target : KR
+EOF
+fi
+
+
+function WriteImage {
+ echo "Adding $1 to $R0ROM"
+ #HEAD_STR=[`stat -c%s $1`/`md5sum $1 | cut -d " " -f 1`]
+ #HEAD_SIZE=`echo $HEAD_STR | wc -c`
+ #PACK_SIZE=`expr 44 - $HEAD_SIZE`
+
+ #while [ $PACK_SIZE -gt 0 ]
+ #do
+ #PACK_SIZE=`expr $PACK_SIZE - 1`
+ #echo -n 0
+ #done
+
+ ./MuonEncrypt $1 >> $R0ROM
+ #cat $MBOOT >> $R0ROM
+}
+
+function Pack4Byte {
+ FILE_SIZE=`stat -c%s $R0ROM`
+ PACK_SIZE=`expr 4 - $FILE_SIZE % 4`
+
+ if [ $PACK_SIZE != 4 ]
+ then
+ while [ $PACK_SIZE -gt 0 ]
+ do
+ PACK_SIZE=`expr $PACK_SIZE - 1` || true
+ echo -en $1 >> $R0ROM
+ done
+ fi
+
+}
+
+echo Make $R0ROM
+
+cat $REVISION > $R0ROM
+echo User : $USER >> $R0ROM
+echo Dir : $PWD >> $R0ROM
+echo BuildTime : `date "+%y/%m/%d %H:%M:%S"` >> $R0ROM
+echo MBoot : size\(`stat -c%s $MBOOT`\),checksum\(`md5sum $MBOOT | cut -d " " -f 1`\) >> $R0ROM
+echo Linux : size\(`stat -c%s $LINUX`\),checksum\(`md5sum $LINUX | cut -d " " -f 1`\) >> $R0ROM
+echo RootFS : size\(`stat -c%s $CRAMFS`\),checksum\(`md5sum $CRAMFS | cut -d " " -f 1`\) >> $R0ROM
+echo Sysdata : size\(`stat -c%s $SYSDATA`\),checksum\(`md5sum $SYSDATA | cut -d " " -f 1`\) >> $R0ROM
+
+Pack4Byte "\\n"
+
+
+dd if=$MBOOT of=$MBOOT_TMP bs=96 count=1 2> /dev/null
+
+echo `stat -c%s $MBOOT`:`md5sum $MBOOT | cut -d " " -f 1` >> $MBOOT_TMP
+echo `stat -c%s $LINUX`:`md5sum $LINUX | cut -d " " -f 1` >> $MBOOT_TMP
+echo `stat -c%s $CRAMFS`:`md5sum $CRAMFS | cut -d " " -f 1` >> $MBOOT_TMP
+echo `stat -c%s $SYSDATA`:`md5sum $SYSDATA | cut -d " " -f 1` >> $MBOOT_TMP
+
+dd if=$MBOOT of=$MBOOT_TMP bs=1088 skip=1 seek=1 2> /dev/null
+WriteImage $MBOOT_TMP
+
+#rm $MBOOT_TMP
+
+Pack4Byte "0"
+
+WriteImage $LINUX
+
+Pack4Byte "0"
+
+WriteImage $CRAMFS
+
+Pack4Byte "0"
+
+WriteImage $SYSDATA
+
+echo $R0ROM : `stat -c%s $R0ROM`, `md5sum $R0ROM | cut -d " " -f 1`
+#head -9 $R0ROM
+
+echo "Done"
diff --git a/utils/ypr0tools/patch-firmware.sh b/utils/ypr0tools/patch-firmware.sh
new file mode 100755
index 0000000000..879b3f879d
--- /dev/null
+++ b/utils/ypr0tools/patch-firmware.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+
+######################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+#
+# * Script to patch an unpacked Samsung YP-R0 firmware file */
+# Copyright (C) 2011 Thomas Martitz
+######################################################################
+# bail out early
+set -e
+
+if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+ echo "Usage: $0 <files path> [path to unpacked rom]"
+ echo "\t<files path> is expected to have a rootfs layout and to contain"
+ echo "\tonly the files to overwrite (plain cp -r is used)"
+ exit 1
+fi
+
+FILES=${1%/}
+FILES=${FILES:-"/"}
+DIR=${2:-"."}
+DIR=${DIR%/}
+ROOTFS=$DIR/rootfs
+CRAMFS=$DIR/cramfs-fsl.rom
+
+# sanity checks
+
+# this needs to be run as root!
+if [ $(whoami) != "root" ]
+then
+ echo "This needs to be run as root"
+ exit 1
+fi
+
+if [ ! -e $1 ] || [ ! -e $2 ]; then
+ echo "$1 or $2 does not exist"
+ exit 1
+fi
+
+if [ -z $ROOTFS ] || [ -z $FILES ]; then
+ echo "Invalid input directories"
+ exit 1
+fi
+
+if [ ! -e $CRAMFS ]; then
+ echo "Cramfs image not found (did you extract the firmware?)"
+ exit 1
+fi
+
+echo "Extracting cramfs image"
+
+[ ! -e $ROOTFS ] || rmdir -p $ROOTFS
+cramfs-1.1/cramfsck -x $ROOTFS $CRAMFS
+
+echo "Patching rootfs"
+echo "cp -r $FILES/* $ROOTFS/"
+cp -r $FILES/.rockbox $ROOTFS/
+cp -r $FILES/* $ROOTFS/
+
+echo "Packing new cramfs image"
+cramfs-1.1/mkcramfs $ROOTFS $CRAMFS
diff --git a/utils/ypr0tools/rockbox.sh b/utils/ypr0tools/rockbox.sh
new file mode 100755
index 0000000000..cbe54fd223
--- /dev/null
+++ b/utils/ypr0tools/rockbox.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+######################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+#
+# * Samsung YP-R0 Rockbox as an application loader *
+# Lorenzo Miori (C) 2011
+######################################################################
+
+# This is expected to be sourced by the shell, which is then
+# expected to run $MAINFILE
+
+# Check for menu button being pressed. Return immediately to launch the OF
+var=$(dd if=/dev/r0Btn bs=4 count=1)
+# Here a workaround to detect the byte
+var2=$(echo -e -n "\x07")
+
+if [[ "$var" = "$var2" ]]
+then
+ return
+fi
+
+
+# Blank-Unblank video to get rid of Samsung BootLogo, but turn off backlight before to hide these things :)
+echo -n "0" > /sys/devices/platform/afe.0/bli
+echo -n "1" > /sys/class/graphics/fb0/blank
+echo -n "0" >> /sys/class/graphics/fb0/blank
+
+amixer sset 'Soft Mute' 0
+amixer sset 'Master' 85%
+
+# We set-up various settings for the cpu governor: default are
+# Every 1,5 s the kernel evaluates if it's the case to down/up clocking the cpu
+echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+echo "1" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/ignore_nice_load
+echo "150000" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
+echo "95" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
+
+# bind these two to the root so that they're writable
+mount --bind /mnt/media0/.rockbox /.rockbox
+mount --bind /mnt/media0/Playlists /Playlists
+
+MAINFILE="/mnt/media0/.rockbox/rockbox"
diff --git a/utils/ypr0tools/unpack-firmware.sh b/utils/ypr0tools/unpack-firmware.sh
new file mode 100755
index 0000000000..ab80670c79
--- /dev/null
+++ b/utils/ypr0tools/unpack-firmware.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+######################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+#
+# * Script to unpack a Samsung YP-R0 firmware file (R0.ROM) */
+######################################################################
+
+# The file was originally called MuonDecrypt.sh
+#
+# I'm not sure about the original author of this file, as it wasn't included in Samsung package.
+# But I guess it was done by JeanLouis, an Italian user of the Hardware Upgrade Forum. If needed, we should search throug old posts for that...
+#
+
+
+# bail out early
+set -e
+
+# some sanity checks
+if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+ echo "Usage $0 <rom file> [out dir]"
+ exit 1
+fi
+
+
+ROM=$1
+DIR=${2:-"."}
+DIR=${DIR%/}
+MBOOT="$DIR/MBoot.bin"
+MBOOT_TMP="${TMP_DIR:-$DIR}/MBoot.tmp"
+LINUX="$DIR/zImage"
+CRAMFS="$DIR/cramfs-fsl.rom"
+SYSDATA="$DIR/SYSDATA.bin"
+MD5SUMS="$DIR/MD5SUMS"
+TMP="${TMP_DIR:-$DIR}/_$$.tmp"
+
+
+if [ ! -f ./extract_section ]; then
+ echo "Couldn't find extract_section binary (try 'make')"
+ exit 1
+fi
+
+if [ ! -f ./MuonEncrypt ]; then
+ echo "Couldn't find MuonEncrypt binary (try 'make')"
+ exit 1
+fi
+
+mkdir -p $DIR
+
+if [ ! -w $DIR ]; then
+ echo "Target dir not writable"
+ exit 1
+fi
+
+ExtractAndDecrypt() {
+ START=$(expr $START - $2)
+ echo "Extracting $1..."
+ ./extract_section $ROM $TMP $START $2
+ echo "Decrypt $1..."
+ ./MuonEncrypt $TMP > $1
+}
+
+size=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 2 | cut -d\) -f 1; done`)
+checksum=( `head -n 9 $ROM | tail -n 4 | while read LINE; do echo $LINE | cut -d\( -f 3 | cut -d\) -f 1; done`)
+
+echo "${checksum[0]} $MBOOT" > $MD5SUMS
+echo "${checksum[1]} $LINUX" >> $MD5SUMS
+echo "${checksum[2]} $CRAMFS" >> $MD5SUMS
+echo "${checksum[3]} $SYSDATA" >> $MD5SUMS
+
+START=`stat -c%s $ROM`
+
+ExtractAndDecrypt $SYSDATA ${size[3]}
+ExtractAndDecrypt $CRAMFS ${size[2]}
+ExtractAndDecrypt $LINUX ${size[1]}
+ExtractAndDecrypt $MBOOT_TMP ${size[0]}
+
+rm $TMP
+echo "Create $MBOOT..."
+dd if=$MBOOT_TMP of=$MBOOT bs=96 count=1 2>/dev/null
+dd if=$MBOOT_TMP of=$MBOOT bs=1088 skip=1 seek=1 2>/dev/null
+rm $MBOOT_TMP
+
+echo "Check integrity:"
+md5sum -c $MD5SUMS