-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmksdfuse.sh
executable file
·106 lines (76 loc) · 2.16 KB
/
mksdfuse.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -x
test -e $TARGET_DIR/boot.img || exit 0
test -e $TARGET_DIR/sd_boot.img || exit 0
test -e $TARGET_DIR/params.bin || exit 0
test -e $TARGET_DIR/rootfs.tar.gz || exit 0
test -e $TARGET_DIR/modules.img || exit 0
MICROSD_IMAGE=$1
repartition() {
fdisk $1 << __EOF__
n
p
1
+${BOOT_SIZE}M
n
p
2
+${MODULE_SIZE}M
n
p
3
w
__EOF__
}
if [ "$MICROSD_IMAGE" == "1" ]; then
IMG_NAME=${TARGET_BOARD}_sdcard.img
else
IMG_NAME=${TARGET_BOARD}_sdfuse.img
fi
if [ "$MICROSD_IMAGE" == "1" ]; then
ROOTFS_SIZE=`gzip -l $TARGET_DIR/rootfs.tar.gz | grep rootfs | awk '{ print $2 }'`
ROOTFS_GAIN=200
else
ROOTFS_SIZE=`stat -c%s $TARGET_DIR/rootfs.tar.gz`
ROOTFS_GAIN=100
fi
ROOTFS_SZ=$((ROOTFS_SIZE >> 20))
TOTAL_SZ=`expr $ROOTFS_SZ + $BOOT_SIZE + $MODULE_SIZE + 2 + $ROOTFS_GAIN`
pushd ${TMP_DIR}
dd if=/dev/zero of=$IMG_NAME bs=1M count=$TOTAL_SZ
cp $PREBUILT_DIR/$TARGET_BOARD/bl1.bin $TARGET_DIR/
cp $PREBUILT_DIR/$TARGET_BOARD/tzsw.bin $TARGET_DIR/
dd conv=notrunc if=$TARGET_DIR/sd_boot.img of=$IMG_NAME bs=512
repartition $IMG_NAME
sync;sync;sync
sudo kpartx -a -v ${IMG_NAME}
LOOP_DEV1=`sudo kpartx -l ${IMG_NAME} | awk '{ print $1 }' | awk 'NR == 1'`
LOOP_DEV2=`sudo kpartx -l ${IMG_NAME} | awk '{ print $1 }' | awk 'NR == 3'`
sudo dd conv=notrunc if=$TARGET_DIR/boot.img of=$IMG_NAME bs=1M seek=1 count=$BOOT_SIZE
let SEEK_MODULES=(${BOOT_SIZE} + 1)
sudo dd conv=notrunc if=$TARGET_DIR/modules.img of=$IMG_NAME bs=1M seek=$SEEK_MODULES count=$MODULE_SIZE
sudo mkfs.ext4 -F -b 4096 -L rootfs /dev/mapper/${LOOP_DEV2}
test -d mnt || mkdir mnt
sudo mount /dev/mapper/${LOOP_DEV2} mnt
sync
if [ "$MICROSD_IMAGE" == "1" ]; then
sudo tar xf $TARGET_DIR/rootfs.tar.gz -C mnt
sudo sed -i "s/mmcblk0p/mmcblk1p/g" mnt/etc/fstab
else
sudo cp $TARGET_DIR/bl1.bin mnt
sudo cp $TARGET_DIR/bl2.bin mnt
sudo cp $TARGET_DIR/u-boot.bin mnt
sudo cp $TARGET_DIR/tzsw.bin mnt
sudo cp $TARGET_DIR/params.bin mnt
sudo cp $TARGET_DIR/boot.img mnt
sudo cp $TARGET_DIR/modules.img mnt
sudo cp $TARGET_DIR/rootfs.tar.gz mnt
sudo cp $TARGET_DIR/artik_release mnt
fi
sync;sync
sudo umount mnt
sudo kpartx -d ${IMG_NAME}
mv ${IMG_NAME} $TARGET_DIR
popd
ls -al ${TARGET_DIR}/${IMG_NAME}
echo "Done"