aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Fainelli <florian@openwrt.org>2010-03-18 23:35:21 +0000
committerFlorian Fainelli <florian@openwrt.org>2010-03-18 23:35:21 +0000
commita1058204d0ad9e3cd5f46c6adcf6a0cf7b408176 (patch)
treebaa9919e6eaaa00c545b1b80100512b483267ab5 /scripts
parent66dc3ee0c9a8eae18cd7baf13add8fe73ea217d6 (diff)
downloadupstream-a1058204d0ad9e3cd5f46c6adcf6a0cf7b408176.tar.gz
upstream-a1058204d0ad9e3cd5f46c6adcf6a0cf7b408176.tar.bz2
upstream-a1058204d0ad9e3cd5f46c6adcf6a0cf7b408176.zip
rework board detection
Rework board detection, separate board specific code into its own file. As a result we also change the way rdc images are generated. Support for board which required binary tools, like AMIT are dropped. Patch by Bernhard Loos. SVN-Revision: 20294
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/pad_image100
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/pad_image b/scripts/pad_image
new file mode 100755
index 0000000000..14f1499076
--- /dev/null
+++ b/scripts/pad_image
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+function usage {
+ echo "Usage: prepare_image image_type kernel_image rootfs_image header_size"
+ echo "Padd root and kernel image to the correct size and append the jffs2 start marker as needed"
+ exit 1
+}
+
+function pad_file {
+ echo "Padding $1 to size $2"
+ dd if=$1 of=$1.paddingtempfile bs=$2 count=1 conv=sync &> /dev/null
+ mv $1.paddingtempfile $1
+}
+
+#filesize filestart padding
+function calc_pad {
+ [ $((($1 + $2) & ($3 - 1))) == 0 ] && {
+ echo $1
+ return 0
+ }
+ echo $(((($1 + $2) | ($3 - 1)) + 1 - $2))
+}
+
+function prep_squash {
+ echo "kernel_size: $kernel_size"
+ echo "header_size: $header_size"
+ kernel_pad_size=$(calc_pad $kernel_size $header_size 32)
+ kernel_end=$(($header_size + $kernel_pad_size))
+ pad_file $kernel_image $kernel_pad_size
+
+ #4k
+ rootfs_pad_size=$(calc_pad $rootfs_size $kernel_end 4096)
+ pad_file $rootfs_image $rootfs_pad_size
+ echo -ne '\xde\xad\xc0\xde' >> $rootfs_image
+
+ #8k
+ rootfs_pad_size=$(calc_pad $rootfs_size $kernel_end 8192)
+ [ $rootfs_pad_size == rootfs_old_padsize ] || {
+ pad_file $rootfs_image $rootfs_pad_size
+ rootfs_old_padsize=$rootfs_pad_size
+ echo -ne '\xde\xad\xc0\xde' >> $rootfs_image
+ }
+
+ #64k
+ rootfs_pad_size=$(calc_pad $rootfs_size $kernel_end 65536)
+ [ $rootfs_pad_size == rootfs_old_padsize ] || {
+ pad_file $rootfs_image $rootfs_pad_size
+ rootfs_old_padsize=$rootfs_pad_size
+ echo -ne '\xde\xad\xc0\xde' >> $rootfs_image
+ }
+
+ #128k
+ rootfs_pad_size=$(calc_pad $rootfs_size $kernel_end 131072)
+ [ $rootfs_pad_size == rootfs_old_padsize ] || {
+ pad_file $rootfs_image $rootfs_pad_size
+ rootfs_old_padsize=$rootfs_pad_size
+ echo -ne '\xde\xad\xc0\xde' >> $rootfs_image
+ }
+
+}
+
+function prep_jffs2 {
+ kernel_pad_size=$(calc_pad $kernel_size $header_size $1)
+ pad_file $kernel_image $kernel_pad_size
+}
+
+image_type=$1
+kernel_image=$2
+rootfs_image=$3
+header_size=$4
+
+if [ -z "$image_type" ] || [ -z "$rootfs_image" ] || [ -z "$kernel_image" ] || [ -z "$header_size" ]; then
+ usage
+fi
+
+if [ ! -e "$rootfs_image" ] || [ -z "$kernel_image" ]; then
+ echo "input file not found"
+ exit 1
+fi
+
+kernel_size=$(stat -c "%s" "$kernel_image")
+rootfs_size=$(stat -c "%s" "$rootfs_image")
+
+if [ $kernel_size == 0 ] || [ $rootfs_size == 0 ]; then
+ echo "kernel or rootfs empty"
+ exit 1
+fi
+
+case $image_type in
+ squashfs )
+ prep_squash ;;
+ jffs2-64k )
+ prep_jffs2 65536 ;;
+ jffs2-128k )
+ prep_jffs2 131072 ;;
+ * )
+ echo "Unknown image type"
+ exit 1 ;;
+esac
+