bcm63xx-cfe: update to the latest master
[openwrt/openwrt.git] / scripts / gen_image_generic.sh
1 #!/bin/sh
2 # Copyright (C) 2006-2012 OpenWrt.org
3 set -e -x
4 if [ $# -ne 5 ] && [ $# -ne 6 ]; then
5 echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image> [<align>]"
6 exit 1
7 fi
8
9 OUTPUT="$1"
10 KERNELSIZE="$2"
11 KERNELDIR="$3"
12 ROOTFSSIZE="$4"
13 ROOTFSIMAGE="$5"
14 ALIGN="$6"
15
16 rm -f "$OUTPUT"
17
18 head=16
19 sect=63
20
21 # create partition table
22 set $(ptgen -o "$OUTPUT" -h $head -s $sect ${GUID:+-g} -p "${KERNELSIZE}m" -p "${ROOTFSSIZE}m" ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE} ${GUID:+-G $GUID})
23
24 KERNELOFFSET="$(($1 / 512))"
25 KERNELSIZE="$2"
26 ROOTFSOFFSET="$(($3 / 512))"
27 ROOTFSSIZE="$(($4 / 512))"
28
29 [ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
30 dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc
31
32 if [ -n "$GUID" ]; then
33 [ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$((ROOTFSOFFSET + ROOTFSSIZE))" conv=notrunc count="$sect"
34 mkfs.fat -n kernel -C "$OUTPUT.kernel" -S 512 "$((KERNELSIZE / 1024))"
35 mcopy -s -i "$OUTPUT.kernel" "$KERNELDIR"/* ::/
36 else
37 make_ext4fs -J -L kernel -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
38 fi
39 dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
40 rm -f "$OUTPUT.kernel"