forked from vtsingaras/firmware-mod-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
case
committed
Apr 16, 2013
0 parents
commit 127fab3
Showing
5,064 changed files
with
982,886 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
#!/bin/bash | ||
|
||
DIR="$1" | ||
NEXT_PARAM="" | ||
|
||
if [ "$1" == "-h" ] | ||
then | ||
echo "Usage: $0 [FMK directory] [-nopad | -min]" | ||
exit 1 | ||
fi | ||
|
||
if [ "$DIR" == "" ] || [ "$DIR" == "-nopad" ] || [ "$DIR" == "-min" ] | ||
then | ||
DIR="fmk" | ||
NEXT_PARAM="$1" | ||
else | ||
NEXT_PARAM="$2" | ||
fi | ||
|
||
# Need to extract file systems as ROOT | ||
if [ "$UID" != "0" ] | ||
then | ||
SUDO="sudo" | ||
else | ||
SUDO="" | ||
fi | ||
|
||
DIR=$(readlink -f $DIR) | ||
|
||
# Make sure we're operating out of the FMK directory | ||
cd $(dirname $(readlink -f $0)) | ||
|
||
# Order matters here! | ||
eval $(cat shared-ng.inc) | ||
eval $(cat $CONFLOG) | ||
FSOUT="$DIR/new-filesystem.$FS_TYPE" | ||
|
||
printf "Firmware Mod Kit (build-ng) ${VERSION}, (c)2011-2013 Craig Heffner, Jeremy Collake\n\n" | ||
|
||
if [ ! -d "$DIR" ] | ||
then | ||
echo -e "Usage: $0 [build directory] [-nopad]\n" | ||
exit 1 | ||
fi | ||
|
||
# Check if FMK has been built, and if not, build it | ||
if [ ! -e "./src/crcalc/crcalc" ] | ||
then | ||
echo "Firmware-Mod-Kit has not been built yet. Building..." | ||
cd src && ./configure && make | ||
|
||
if [ $? -eq 0 ] | ||
then | ||
cd - | ||
else | ||
echo "Build failed! Quitting..." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
echo "Building new $FS_TYPE file system..." | ||
|
||
# Clean up any previously created files | ||
rm -rf "$FWOUT" "$FSOUT" | ||
|
||
# Build the appropriate file system | ||
case $FS_TYPE in | ||
"squashfs") | ||
# Check for squashfs 4.0 realtek, which requires the -comp option to build lzma images. | ||
if [ "$(echo $MKFS | grep 'squashfs-4.0-realtek')" != "" ] && [ "$FS_COMPRESSION" == "lzma" ] | ||
then | ||
COMP="-comp lzma" | ||
else | ||
COMP="" | ||
fi | ||
|
||
# Mksquashfs 4.0 tools don't support the -le option; little endian is built by default | ||
if [ "$(echo $MKFS | grep 'squashfs-4.')" != "" ] && [ "$ENDIANESS" == "-le" ] | ||
then | ||
ENDIANESS="" | ||
fi | ||
|
||
# Increasing the block size minimizes the resulting image size (larger dictionary). Max block size of 1MB. | ||
if [ "$NEXT_PARAM" == "-min" ] | ||
then | ||
echo "Blocksize override (-min). Original used $((FS_BLOCKSIZE/1024))KB blocks. New firmware uses 1MB blocks." | ||
FS_BLOCKSIZE="$((1024*1024))" | ||
fi | ||
|
||
# if blocksize var exists, then add '-b' parameter | ||
if [ "$FS_BLOCKSIZE" != "" ] | ||
then | ||
BS="-b $FS_BLOCKSIZE" | ||
fi | ||
|
||
$SUDO $MKFS "$ROOTFS" "$FSOUT" $ENDIANESS $BS $COMP -all-root | ||
;; | ||
"cramfs") | ||
$SUDO $MKFS "$ROOTFS" "$FSOUT" | ||
if [ "$ENDIANESS" == "-be" ] | ||
then | ||
mv "$FSOUT" "$FSOUT.le" | ||
./src/cramfsswap/cramfsswap "$FSOUT.le" "$FSOUT" | ||
rm -f "$FSOUT.le" | ||
fi | ||
;; | ||
*) | ||
echo "Unsupported file system '$FS_TYPE'!" | ||
;; | ||
esac | ||
|
||
if [ ! -e $FSOUT ] | ||
then | ||
echo "Failed to create new file system! Quitting..." | ||
exit 1 | ||
fi | ||
|
||
# Append the new file system to the first part of the original firmware file | ||
cp $HEADER_IMAGE $FWOUT | ||
$SUDO cat $FSOUT >> $FWOUT | ||
|
||
# Calculate and create any filler bytes required between the end of the file system and the footer / EOF. | ||
CUR_SIZE=$(ls -l $FWOUT | awk '{print $5}') | ||
((FILLER_SIZE=$FW_SIZE-$CUR_SIZE-$FOOTER_SIZE)) | ||
|
||
if [ "$FILLER_SIZE" -lt 0 ] | ||
then | ||
echo "ERROR: New firmware image will be larger than original image!" | ||
echo " Building firmware images larger than the original can brick your device!" | ||
echo " Try re-running with the -min option, or remove any unnecessary files from the file system." | ||
echo " Refusing to create new firmware image." | ||
echo "" | ||
echo " Original file size: $FW_SIZE" | ||
echo " Current file size: $CUR_SIZE" | ||
echo "" | ||
echo " Quitting..." | ||
rm -f "$FWOUT" "$FSOUT" | ||
exit 1 | ||
else | ||
if [ "$NEXT_PARAM" != "-nopad" ]; then | ||
echo "Remaining free bytes in firmware image: $FILLER_SIZE" | ||
perl -e "print \"\xFF\"x$FILLER_SIZE" >> "$FWOUT" | ||
else | ||
echo "Padding of firmware image disabled via -nopad" | ||
fi | ||
fi | ||
|
||
# Append the footer to the new firmware image, if there is any footer | ||
if [ "$FOOTER_SIZE" -gt "0" ] | ||
then | ||
cat $FOOTER_IMAGE >> "$FWOUT" | ||
fi | ||
|
||
# Calculate new checksum values for the firmware header | ||
# trx, dlob, uimage | ||
./src/crcalc/crcalc "$FWOUT" "$BINLOG" | ||
|
||
if [ $? -eq 0 ] | ||
then | ||
echo -n "Finished! " | ||
else | ||
echo -n "Firmware header not supported; firmware checksums may be incorrect. " | ||
fi | ||
|
||
# if a Buffalo image, then run encrypter - base on image name | ||
if [ "$(echo $FWOUT | grep -i 'buffalo')" != "" ] | ||
then | ||
# product name, version, key, encryption type can be specified here | ||
$KEY="" # specify full param, e.g. -k mykey | ||
$MAGIC="" | ||
$PRODUCT="" | ||
$LONGSTATE="" | ||
./src/firmware-tools/buffalo-enc -i $FWOUT -o $FWOUT.buffalo.enc $KEY $MAGIC $PRODUCT $LONGSTATE | ||
#if [ $? -eq 0 ] | ||
#then | ||
# echo "Encrypted Buffalo image created." | ||
#else | ||
# echo "ERROR creating an encrypted Buffalo image" | ||
#fi | ||
fi | ||
|
||
echo "New firmware image has been saved to: $FWOUT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# 20110224-1507-MCT - Needed quotes around a string compare. | ||
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
echo " Checking for updates ..." | ||
mkdir update_check | ||
cd update_check | ||
SYSNAME=`uname` | ||
if [ `expr "$SYSNAME" : "Darwin"` = 6 ]; then | ||
curl -O -s --connect-timeout 4 --retry 1 http://firmware-mod-kit.googlecode.com/svn/trunk/firmware_mod_kit_version.txt | ||
else | ||
wget --quiet --timeout=4 --tries=1 http://firmware-mod-kit.googlecode.com/svn/trunk/firmware_mod_kit_version.txt | ||
fi | ||
cd .. | ||
if [ ! -f "update_check/firmware_mod_kit_version.txt" ]; then | ||
echo " ! WARNING: Could not check for update. No connectivity or server down?" | ||
rm -rf update_check | ||
exit 1 | ||
fi | ||
NEW_VERSION=`cat update_check/firmware_mod_kit_version.txt` | ||
CUR_VERSION=`cat firmware_mod_kit_version.txt` | ||
if [ "$NEW_VERSION" != "$CUR_VERSION" ]; then | ||
echo " !!! There is a newer version available: $NEW_VERSION" | ||
echo " You are currently using $CUR_VERSION" | ||
else | ||
echo " You have the latest version of this kit." | ||
fi | ||
rm -rf update_check | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
. ./shared.inc | ||
Cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<html> | ||
|
||
<head> | ||
<meta http-equiv="Content-Language" content="en-us"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | ||
<title>Creating IPKs</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<p><b><font size="5">IPK Creation Kit</font><br> | ||
</b>(c)2006 Jeremy Collake <<a href="mailto:jeremy.collake@gmail.com">jeremy.collake@gmail.com</a>><br> | ||
<br> | ||
<font color="#FF0000">!!! <b>ALPHA STAGE OF DEVELOPMENT. MAY NOT WORK AND HAVE | ||
MANY PROBLEMS</b> !!!</font></p> | ||
<p>This document attempts to outline the process of creation of IPKG format | ||
packages with the IPK Creation Kit, giving specific emphasis on usage for | ||
embedded linux platforms such as <a href="http://www.openwrt.org">OpenWrt</a> | ||
and <a href="http://www.dd-wrt.com">DD-WRT</a>. It is a quick draft intended to | ||
encourage people to develop IPKs specific to certain firmwares for use with the | ||
<a href="http://www.bitsum.com/firmware_mod_kit.htm">Firmware Modification Kit</a>, | ||
a kit that allows easy modification of firmware images without recompiling the | ||
sources.</p> | ||
<p><b><font size="4">The structure of an IPK</font></b></p> | ||
<p>IPK files are <b><i>archives</i></b> containing the following:</p> | ||
<ul> | ||
<li><u><b>data.tar.gz</b></u> : contains data.tar:<ul> | ||
<li><u><b>data.tar</b></u> : These are the files that will be installed | ||
to, or removed from, the file system. They are in their correct | ||
locations in the directory tree starting at the root of the firmware | ||
file system. For example:<ul> | ||
<li><font face="Courier"><b>./</b>usr/sbin/package<br> | ||
./tmp/package_config<br> | ||
./etc/package_config <i>-> symbolic link</i> -> ../tmp/config_folder<br> | ||
./tmp/package_config/package.conf<br> | ||
NOTE: </font><i>the "." directory must be included in the path names</i></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
<li><b><u>control.tar.gz</u> </b>: contains control.tar:<ul> | ||
<li><u><b>control.tar</b></u> : These are files which give information | ||
about the package. For examples, it's name, version, and dependencies.<ul> | ||
<li>./control : describes the package</li> | ||
<li>./conffiles : indicates which files in the package are used for | ||
config files once installed</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
<li><b><u>debian_binary</u> </b>: the reason this exists is unknown. It's | ||
perhaps some platform or format indicator. It is a text file that consists | ||
of "2.0". </li> | ||
</ul> | ||
<p> </p> | ||
<p><b><font size="4">Using the IPK template</font></b></p> | ||
<p>The IPK template directory contained in the Firmware Modification Kit makes | ||
it particularly easy to create IPK files without having to manually create them | ||
each time.</p> | ||
<p><b><font size="4">Creating your own IPK</font></b></p> | ||
<blockquote> | ||
<p><b><font size="4">Step 1</font></b></p> | ||
<p>Copy or extract the IPK template directory to a new directory named after | ||
the package you are creating an IPK for. If you are copying, use "cp -r" to | ||
copy the entire directory and all its contents.</p> | ||
<p><b><font size="4">Step 2</font></b></p> | ||
<p>In the new directory edit the "<i>control</i>" and "<i>conffiles</i>" | ||
text files appropriately. The fields in "control" are probably | ||
self-explanatory:</p> | ||
<p><i><b>control:</b></i></p> | ||
<table border="0" width="100%" bgcolor="#FFFFCC" id="table5"> | ||
<tr> | ||
<td><br> | ||
<font face="Courier">Package: somepackage<br> | ||
Priority: optional<br> | ||
Depends: libpcap libncurses<br> | ||
Section: net<br> | ||
Description: A minimal and secure package of great sorts.<br> | ||
Maintainer: Junior Jim-Bob <juniorjim.bob.com><br> | ||
Source: N/A<br> | ||
Version: 2.61-1<br> | ||
Architecture: mipsel<br> | ||
</font></td> | ||
</tr> | ||
</table> | ||
<p>If you want to get fancy, the<i> Source</i> field can indicate a URL to | ||
download the data.tar.gz portion of the package. If instead the package | ||
files are included inside the PKG, leave "N/A" in this field.</p> | ||
<p>"conffiles" contains a listing of files in the package that are used for | ||
configuration storage. This is helpful to preserve the configuration of the | ||
package if it is updated, or if the configuration otherwise needs | ||
preserving. It might look something like this after editing:</p> | ||
<p><i><b>conffiles:</b></i></p> | ||
<table border="0" width="100%" bgcolor="#FFFFCC" id="table6"> | ||
<tr> | ||
<td><br> | ||
<font face="Courier">/etc/package_config/package.conf<br> | ||
/etc/package_config/moreconfig.conf<br> | ||
</font></td> | ||
</tr> | ||
</table> | ||
<p><b><font size="4">Step 3</font></b></p> | ||
<p>Copy the package files into the folder in the same relative directories | ||
to which they will be installed to the file system. Symbolic links are | ||
allowed. For example:</p> | ||
<table border="0" width="100%" bgcolor="#FFFFCC" id="table7"> | ||
<tr> | ||
<td><br> | ||
<font face="Courier">./usr/sbin/mypackage<br> | ||
./tmp/etc/package_config/<br> | ||
./etc/package_config/ ---(symbolic link)---> | ||
../tmp/etc/package_config/<br> | ||
./tmp/etc/package_config/moreconfig.conf<br> | ||
</font></td> | ||
</tr> | ||
</table> | ||
<p>The above makes the /etc/package_config/ directory a symbolic link to | ||
/tmp/package_config/. This would be useful for firmwares that have a | ||
read-only /etc file system. On these systems, the configuration files could | ||
reside on a ram disk and be emitted at boot-time based on input from some | ||
other store of configuration variables, like NVRAM.</p> | ||
<p><b><font size="4">Step 4:</font></b></p> | ||
<p>Build the IPK. You're done, now simply build the IPK file with the script | ||
provided. It's parameters are:</p> | ||
<p>MAKE_IPK.SH OUTPUT_PACKAGE_IPK IPK_BASE_DIRECTORY</p> | ||
<p><i><b>OUTPUT_PACKAGE_IPK</b> </i>: The IPK file to output. If it already | ||
exists it will be over-written.<br> | ||
<i><b>IPK_BASE_DIRECTORY</b> </i>: The directory you created in step 1 and | ||
have been working with up until now.</p> | ||
<p>Example:</p> | ||
<table border="0" width="100%" bgcolor="#FFFFCC" id="table8"> | ||
<tr> | ||
<td><br> | ||
<font face="Courier">make_ipk.sh package.ipk ../package_ipk_dir<br> | ||
</font></td> | ||
</tr> | ||
</table> | ||
<p> </p> | ||
</blockquote> | ||
<p>To support this project:</p> | ||
<p> | ||
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> | ||
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p> | ||
<p> </p> | ||
<p><font size="2">This document (c)2006 Jeremy Collake. <br> | ||
All Rights reserved. This document may be freely republished in its unaltered | ||
and whole form only. Alterations or partial publishing requires approval of | ||
Jeremy Collake <<a href="mailto:jeremy@bitsum.com">jeremy@bitsum.com</a>>.</font></p> | ||
|
||
</body> | ||
|
||
</html> |
Oops, something went wrong.