scripts: mkbootimg_rpi4.sh: Stop build on any kind of errors
[platform/kernel/linux-rpi.git] / scripts / mkbootimg_rpi4.sh
1 #!/bin/bash
2
3 TMP_UBOOT_PATH=tmp_uboot
4 BOOT_PATH="rpi4/boot"
5 USER_ID=`id -u`
6 GROUP_ID=`id -g`
7 IS_64BIT=`cat .config | grep "CONFIG_64BIT=y"`
8 BUILD_ROOT=$PWD
9
10 cleanup() {
11         cd $BUILD_ROOT
12         if [ -e $TMP_UBOOT_PATH ]; then
13                 rm -rf ${TMP_UBOOT_PATH}
14         fi
15
16         if [ -e tmp_modules ]; then
17                 rm -rf tmp_modules
18         fi
19
20         if [ -e tmp/lib/modules ]; then
21                 rm -rf tmp/lib/modules
22         fi
23
24         if [ -n "$(mount | grep ${BUILD_ROOT}/tmp)" ]; then
25                 sudo umount tmp
26         fi
27
28         if [ -e tmp ]; then
29                 rm -rf tmp
30         fi
31 }
32
33 trap cleanup EXIT
34
35 set -e
36
37 rm -f boot.img
38 rm -rf tmp
39 mkdir tmp
40
41 # Create boot.img
42 mkfs.vfat -F 16 -C -n BOOT boot.img 65536
43 sudo mount -o loop,uid=$USER_ID,gid=$GROUP_ID,showexec boot.img ./tmp
44
45 if [ -n "$IS_64BIT" ]; then
46         echo "Create 64bit boot image"
47         cp -a $BOOT_PATH/config_64bit.txt ./tmp/config.txt
48 else
49         echo "Create 32bit boot image"
50         cp -a $BOOT_PATH/config.txt ./tmp
51 fi
52 cp -a $BOOT_PATH/LICENCE.broadcom ./tmp
53 cp -a $BOOT_PATH/start*.elf ./tmp
54 cp -a $BOOT_PATH/fixup*.dat ./tmp
55 if [ -n "$IS_64BIT" ]; then
56         cp -a arch/arm64/boot/Image ./tmp
57         cp -a arch/arm64/boot/dts/broadcom/bcm*.dtb ./tmp
58 else
59         cp -a arch/arm/boot/zImage ./tmp
60         cp -a arch/arm/boot/dts/bcm*.dtb ./tmp
61 fi
62
63 # install u-boot files extracted from u-boot-rpi4 rpm package in download.tizen.org.
64
65 mkdir -p ${TMP_UBOOT_PATH}
66 pushd ${TMP_UBOOT_PATH}
67 if [ -n "$IS_64BIT" ]; then
68         REPO_URL=http://download.tizen.org/snapshots/tizen/unified/latest/repos/standard/packages/aarch64/
69 else
70         REPO_URL=http://download.tizen.org/snapshots/tizen/unified/latest/repos/standard/packages/armv7l/
71 fi
72 rm -f index.html*
73 wget ${REPO_URL}
74 UBOOT=`awk -F\" '{ print $2 }' index.html | grep u-boot-rpi4`
75 wget ${REPO_URL}${UBOOT}
76 unrpm ${UBOOT}
77 popd
78
79 cp -a ${TMP_UBOOT_PATH}/boot/* ./tmp
80 rm -rf ${TMP_UBOOT_PATH}
81
82 sync
83 sudo umount tmp
84
85 rm -f modules.img
86 mkdir -p tmp/lib/modules
87 mkdir -p tmp_modules
88
89 # Create modules.img
90 dd if=/dev/zero of=modules.img bs=1024 count=32768
91 mkfs.ext4 -q -F -t ext4 -b 1024 -L modules modules.img
92 sudo mount -o loop modules.img ./tmp/lib/modules
93 if [ -n "$IS_64BIT" ]; then
94         export ARCH=arm64
95         export CROSS_COMPILE=aarch64-linux-gnu-
96 else
97         export ARCH=arm
98         export CROSS_COMPILE=arm-linux-gnueabi-
99 fi
100 make modules_install INSTALL_MOD_PATH=./tmp_modules INSTALL_MOD_STRIP=1
101
102 sudo mv ./tmp_modules/lib/modules/* ./tmp/lib/modules
103 sudo -n chown root:root ./tmp/lib/modules -R
104
105 sync
106 sudo umount tmp/lib/modules
107
108 rm -rf tmp tmp_modules
109
110 # Create boot tarball for the lthor flashing
111 DATE=`date +%Y%m%d`
112 if [ -n "$IS_64BIT" ]; then
113         BOOT_TARBALL=tizen-local-${DATE}-boot-arm64-rpi4.tar.gz
114 else
115         BOOT_TARBALL=tizen-local-${DATE}-boot-armv7l-rpi4.tar.gz
116 fi
117
118 tar czf ${BOOT_TARBALL} boot.img modules.img
119 if [ "$?" != "0" ]; then
120         echo "Failed to create boot tarball"
121         exit 1
122 fi
123
124 echo ${BOOT_TARBALL}
125
126 set +e