wireguard: bump to 0.0.20190227
[openwrt/openwrt.git] / scripts / gen_image_generic.sh
1 #!/usr/bin/env bash
2 # Copyright (C) 2006-2012 OpenWrt.org
3 set -x
4 [ $# == 5 -o $# == 6 ] || {
5 echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image> [<align>]"
6 exit 1
7 }
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 cyl=$(( ($KERNELSIZE + $ROOTFSSIZE) * 1024 * 1024 / ($head * $sect * 512)))
21
22 # create partition table
23 set `ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE}`
24
25 KERNELOFFSET="$(($1 / 512))"
26 KERNELSIZE="$2"
27 ROOTFSOFFSET="$(($3 / 512))"
28 ROOTFSSIZE="$(($4 / 512))"
29
30 [ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
31 dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc
32
33 make_ext4fs -J -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
34 dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
35 rm -f "$OUTPUT.kernel"