mxs: re-work SD card image generation
[openwrt/staging/chunkeey.git] / target / linux / mxs / image / gen_sdcard_ext4_ext4.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2015 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 set -x
10 [ $# -eq 4 ] || {
11 echo "SYNTAX: $0 <file> <u-boot.sb image> <rootfs image> <rootfs size>"
12 exit 1
13 }
14
15 OUTPUT="$1"
16 UBOOT="$2"
17 ROOTFS="$3"
18 ROOTFSSIZE="$4"
19
20 head=4
21 sect=63
22
23 # set the Boot stream partition size to 1M
24 set `ptgen -o $OUTPUT -h $head -s $sect -l 1024 -t 53 -p 1M -t 83 -p ${ROOTFSSIZE}M -t 83 -p ${ROOTFSSIZE}M`
25
26 ROOTFS1OFFSET="$(($3 / 512))"
27 ROOTFS1SIZE="$(($4 / 512))"
28 ROOTFS2OFFSET="$(($5 / 512))"
29 ROOTFS2SIZE="$(($6 / 512))"
30
31 dd bs=512 if="$ROOTFS" of="$OUTPUT" seek="$ROOTFS1OFFSET" conv=notrunc
32 dd bs=512 if="$ROOTFS" of="$OUTPUT" seek="$ROOTFS2OFFSET" conv=notrunc
33 sdimage -d "$OUTPUT" -f "$UBOOT"