Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2019 Google Inc. All rights reserved. |
| 4 | |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | source "${ANDROID_BUILD_TOP}/external/shflags/src/shflags" |
| 18 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 19 | DEFINE_boolean p1 \ |
| 20 | false "Only generate/write the 1st partition (loader1)" "1" |
| 21 | DEFINE_boolean p2 \ |
| 22 | false "Only generate/write the 2nd partition (env)" "2" |
| 23 | DEFINE_boolean p3 \ |
| 24 | false "Only generate/write the 3rd partition (loader2)" "3" |
| 25 | DEFINE_boolean p4 \ |
| 26 | false "Only generate/write the 4th partition (trust)" "4" |
| 27 | DEFINE_boolean p5 \ |
| 28 | false "Only generate/write the 5th partition (rootfs)" "5" |
| 29 | |
| 30 | FLAGS_HELP="USAGE: $0 <KERNEL_DIR> [IMAGE] [flags]" |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 31 | |
| 32 | FLAGS "$@" || exit $? |
| 33 | eval set -- "${FLAGS_ARGV}" |
| 34 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 35 | if [ ${FLAGS_p1} -eq ${FLAGS_FALSE} ] && |
| 36 | [ ${FLAGS_p2} -eq ${FLAGS_FALSE} ] && |
| 37 | [ ${FLAGS_p3} -eq ${FLAGS_FALSE} ] && |
| 38 | [ ${FLAGS_p4} -eq ${FLAGS_FALSE} ] && |
| 39 | [ ${FLAGS_p5} -eq ${FLAGS_FALSE} ]; then |
| 40 | FLAGS_p1=${FLAGS_TRUE} |
| 41 | FLAGS_p2=${FLAGS_TRUE} |
| 42 | FLAGS_p3=${FLAGS_TRUE} |
| 43 | FLAGS_p4=${FLAGS_TRUE} |
| 44 | FLAGS_p5=${FLAGS_TRUE} |
| 45 | fi |
| 46 | |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 47 | for arg in "$@" ; do |
| 48 | if [ -z $KERNEL_DIR ]; then |
| 49 | KERNEL_DIR=$arg |
| 50 | elif [ -z $IMAGE ]; then |
| 51 | IMAGE=$arg |
| 52 | else |
| 53 | flags_help |
| 54 | exit 1 |
| 55 | fi |
| 56 | done |
| 57 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 58 | USE_IMAGE=`[ -z "${IMAGE}" ] && echo "0" || echo "1"` |
Tristan Muntsinger | 1f28d1f | 2019-10-16 22:53:55 -0700 | [diff] [blame] | 59 | OVERWRITE=`[ -e "${IMAGE}" ] && echo "1" || echo "0"` |
| 60 | if [ -z $KERNEL_DIR ]; then |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 61 | flags_help |
| 62 | exit 1 |
| 63 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 64 | if [ ! -e "${KERNEL_DIR}" ]; then |
| 65 | echo "error: can't find '${KERNEL_DIR}'. aborting..." |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | # escalate to superuser |
| 70 | if [ $UID -ne 0 ]; then |
| 71 | cd ${ANDROID_BUILD_TOP} |
| 72 | . ./build/envsetup.sh |
| 73 | lunch ${TARGET_PRODUCT}-${TARGET_BUILD_VARIANT} |
| 74 | mmma external/u-boot |
| 75 | cd - |
| 76 | exec sudo -E "${0}" ${@} |
| 77 | fi |
| 78 | |
Tristan Muntsinger | 1f28d1f | 2019-10-16 22:53:55 -0700 | [diff] [blame] | 79 | if [ $OVERWRITE -eq 1 ]; then |
| 80 | OVERWRITE_IMAGE=${IMAGE} |
| 81 | IMAGE=`mktemp` |
| 82 | fi |
| 83 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 84 | if [ $USE_IMAGE -eq 0 ]; then |
| 85 | init_devs=`lsblk --nodeps -oNAME -n` |
| 86 | echo "Reinsert device (to write to) into PC" |
| 87 | while true; do |
| 88 | devs=`lsblk --nodeps -oNAME -n` |
| 89 | new_devs="$(echo -e "${init_devs}\n${devs}" | sort | uniq -u | awk 'NF')" |
| 90 | num_devs=`echo "${new_devs}" | wc -l` |
| 91 | if [[ "${new_devs}" == "" ]]; then |
| 92 | num_devs=0 |
| 93 | fi |
| 94 | if [[ ${num_devs} -gt 1 ]]; then |
| 95 | echo "error: too many new devices detected! aborting..." |
| 96 | exit 1 |
| 97 | fi |
| 98 | if [[ ${num_devs} -eq 1 ]]; then |
| 99 | if [[ "${new_devs}" != "${mmc_dev}" ]]; then |
| 100 | if [[ "${mmc_dev}" != "" ]]; then |
| 101 | echo "error: block device name mismatch ${new_devs} != ${mmc_dev}" |
| 102 | echo "Reinsert device (to write to) into PC" |
| 103 | fi |
| 104 | mmc_dev=${new_devs} |
| 105 | continue |
| 106 | fi |
| 107 | echo "${init_devs}" | grep "${mmc_dev}" >/dev/null |
| 108 | if [[ $? -eq 0 ]]; then |
| 109 | init_devs="${devs}" |
| 110 | continue |
| 111 | fi |
| 112 | break |
| 113 | fi |
| 114 | done |
| 115 | # now inform the user |
| 116 | echo "Detected device at /dev/${mmc_dev}" |
| 117 | fi |
| 118 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 119 | if [ ${FLAGS_p1} -eq ${FLAGS_TRUE} ]; then |
| 120 | cd ${ANDROID_BUILD_TOP}/external/arm-trusted-firmware |
| 121 | CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rk3399 DEBUG=0 ERROR_DEPRECATED=1 bl31 |
| 122 | export BL31="${ANDROID_BUILD_TOP}/external/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf" |
| 123 | cd - |
| 124 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 125 | |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 126 | cd ${ANDROID_BUILD_TOP}/external/u-boot |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 127 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 128 | if [ ${FLAGS_p2} -eq ${FLAGS_TRUE} ]; then |
| 129 | tmpfile=`mktemp` |
| 130 | bootenv=`mktemp` |
| 131 | cat > ${tmpfile} << "EOF" |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 132 | bootdelay=2 |
| 133 | baudrate=1500000 |
| 134 | scriptaddr=0x00500000 |
| 135 | boot_targets=mmc1 mmc0 |
| 136 | bootcmd=run distro_bootcmd |
| 137 | distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done |
| 138 | bootcmd_mmc0=devnum=0; run mmc_boot |
| 139 | bootcmd_mmc1=devnum=1; run mmc_boot |
| 140 | mmc_boot=if mmc dev ${devnum}; then ; run scan_for_boot_part; fi |
Tristan Muntsinger | f06455a | 2019-10-31 16:08:19 -0700 | [diff] [blame] | 141 | scan_for_boot_part=part list mmc ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; if test $devnum = 1; then script_type=init; else script_type=boot; fi; for distro_bootpart in ${devplist}; do if fstype mmc ${devnum}:${distro_bootpart} bootfstype; then run find_script; fi; done; setenv devplist; setenv script_type; |
| 142 | find_script=if test -e mmc ${devnum}:${distro_bootpart} /boot/$script_type.scr; then echo Found U-Boot script /boot/$script_type.scr; run run_scr; fi |
| 143 | run_scr=load mmc ${devnum}:${distro_bootpart} ${scriptaddr} /boot/$script_type.scr; source ${scriptaddr} |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 144 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 145 | ${ANDROID_HOST_OUT}/bin/mkenvimage -s 32768 -o ${bootenv} - < ${tmpfile} |
| 146 | fi |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 147 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 148 | if [ ${FLAGS_p1} -eq ${FLAGS_TRUE} ] || [ ${FLAGS_p3} -eq ${FLAGS_TRUE} ]; then |
| 149 | make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- rock-pi-4-rk3399_defconfig |
| 150 | if [ ${FLAGS_p1} -eq ${FLAGS_TRUE} ]; then |
| 151 | make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` |
| 152 | fi |
| 153 | if [ ${FLAGS_p3} -eq ${FLAGS_TRUE} ]; then |
| 154 | make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- u-boot.itb |
| 155 | fi |
| 156 | if [ ${FLAGS_p1} -eq ${FLAGS_TRUE} ]; then |
| 157 | idbloader=`mktemp` |
| 158 | ${ANDROID_HOST_OUT}/bin/mkimage -n rk3399 -T rksd -d tpl/u-boot-tpl.bin ${idbloader} |
| 159 | cat spl/u-boot-spl.bin >> ${idbloader} |
| 160 | fi |
| 161 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 162 | cd - |
| 163 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 164 | if [ ${FLAGS_p5} -eq ${FLAGS_TRUE} ]; then |
| 165 | ${ANDROID_BUILD_TOP}/kernel/tests/net/test/build_rootfs.sh -a arm64 -s buster -n ${IMAGE} |
| 166 | if [ $? -ne 0 ]; then |
| 167 | echo "error: failed to build rootfs. exiting..." |
| 168 | exit 1 |
| 169 | fi |
| 170 | truncate -s +3G ${IMAGE} |
| 171 | e2fsck -f ${IMAGE} |
| 172 | resize2fs ${IMAGE} |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 173 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 174 | mntdir=`mktemp -d` |
| 175 | mount ${IMAGE} ${mntdir} |
| 176 | if [ $? != 0 ]; then |
| 177 | echo "error: unable to mount ${IMAGE} ${mntdir}" |
| 178 | exit 1 |
| 179 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 180 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 181 | cat > ${mntdir}/boot/init.cmd << "EOF" |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 182 | mmc dev 1 0; mmc read 0x02080000 0x1fc0 0x40; |
| 183 | ethaddr=$ethaddr |
| 184 | env default -a |
| 185 | setenv ethaddr $ethaddr |
| 186 | setenv boot_targets 'mmc1 mmc0 usb0 pxe' |
| 187 | saveenv |
| 188 | mmc dev 1 0; mmc read 0x04000000 0x1fc0 0x40; |
| 189 | mmc dev 0 0; mmc write 0x04000000 0x1fc0 0x40; |
| 190 | mmc dev 1 0; mmc write 0x02080000 0x1fc0 0x40; |
| 191 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 192 | ${ANDROID_BUILD_TOP}/external/u-boot/tools/mkimage \ |
Tristan Muntsinger | 5f26395 | 2019-10-16 21:12:06 -0700 | [diff] [blame] | 193 | -C none -A arm -T script -d ${mntdir}/boot/init.cmd ${mntdir}/boot/init.scr |
| 194 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 195 | cat > ${mntdir}/boot/boot.cmd << "EOF" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 196 | setenv bootcmd_dhcp ' |
| 197 | mw.b ${scriptaddr} 0 0x8000 |
| 198 | mmc dev 0 0 |
| 199 | mmc read ${scriptaddr} 0x1fc0 0x40 |
| 200 | env import -b ${scriptaddr} 0x8000 |
| 201 | mw.b ${scriptaddr} 0 0x8000 |
| 202 | if dhcp ${scriptaddr} manifest.txt; then |
| 203 | setenv OldSha ${Sha} |
| 204 | setenv Sha |
| 205 | env import -t ${scriptaddr} 0x8000 ManifestVersion |
Tristan Muntsinger | 19c66ee | 2019-11-08 19:10:48 -0800 | [diff] [blame] | 206 | echo "Manifest version $ManifestVersion"; |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 207 | if test "$ManifestVersion" = "1"; then |
| 208 | run manifest1 |
Tristan Muntsinger | 19c66ee | 2019-11-08 19:10:48 -0800 | [diff] [blame] | 209 | elif test "$ManifestVersion" = "2"; then |
| 210 | run manifest2 |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 211 | else |
| 212 | run manifestX |
| 213 | fi |
| 214 | fi' |
| 215 | setenv manifestX 'echo "***** ERROR: Unknown manifest version! *****";' |
| 216 | setenv manifest1 ' |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 217 | env import -t ${scriptaddr} 0x8000 |
| 218 | if test "$Sha" != "$OldSha"; then |
| 219 | setenv serverip ${TftpServer} |
| 220 | setenv loadaddr 0x00200000 |
| 221 | mmc dev 0 0; |
| 222 | file=$TplSplImg; offset=0x40; size=0x1f80; run tftpget1; setenv TplSplImg |
| 223 | file=$UbootItb; offset=0x4000; size=0x2000; run tftpget1; setenv UbootItb |
| 224 | file=$TrustImg; offset=0x6000; size=0x2000; run tftpget1; setenv TrustImg |
| 225 | file=$RootfsImg; offset=0x8000; size=0; run tftpget1; setenv RootfsImg |
| 226 | file=$UbootEnv; offset=0x1fc0; size=0x40; run tftpget1; setenv UbootEnv |
| 227 | mw.b ${scriptaddr} 0 0x8000 |
| 228 | env export -b ${scriptaddr} 0x8000 |
| 229 | mmc write ${scriptaddr} 0x1fc0 0x40 |
| 230 | else |
| 231 | echo "Already have ${Sha}. Booting..." |
| 232 | fi' |
Tristan Muntsinger | 19c66ee | 2019-11-08 19:10:48 -0800 | [diff] [blame] | 233 | setenv manifest2 ' |
| 234 | env import -t ${scriptaddr} 0x8000 |
| 235 | if test "$DFUethaddr" = "$ethaddr" || test "$DFUethaddr" = ""; then |
| 236 | if test "$Sha" != "$OldSha"; then |
| 237 | setenv serverip ${TftpServer} |
| 238 | setenv loadaddr 0x00200000 |
| 239 | mmc dev 0 0; |
| 240 | file=$TplSplImg; offset=0x40; size=0x1f80; run tftpget1; setenv TplSplImg |
| 241 | file=$UbootItb; offset=0x4000; size=0x2000; run tftpget1; setenv UbootItb |
| 242 | file=$TrustImg; offset=0x6000; size=0x2000; run tftpget1; setenv TrustImg |
| 243 | file=$RootfsImg; offset=0x8000; size=0; run tftpget1; setenv RootfsImg |
| 244 | file=$UbootEnv; offset=0x1fc0; size=0x40; run tftpget1; setenv UbootEnv |
| 245 | mw.b ${scriptaddr} 0 0x8000 |
| 246 | env export -b ${scriptaddr} 0x8000 |
| 247 | mmc write ${scriptaddr} 0x1fc0 0x40 |
| 248 | else |
| 249 | echo "Already have ${Sha}. Booting..." |
| 250 | fi |
| 251 | else |
| 252 | echo "Update ${Sha} isn't for me. Booting..." |
| 253 | fi' |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 254 | setenv tftpget1 " |
| 255 | mw.b ${loadaddr} 0 0x400000 |
| 256 | && tftp ${file} |
| 257 | && isGz=0 && setexpr isGz sub .*\\.gz\$ 1 ${file} |
| 258 | && if test $isGz = 1; then |
| 259 | setexpr boffset ${offset} * 0x200 |
| 260 | && gzwrite mmc 0 ${loadaddr} 0x${filesize} 100000 ${boffset} |
| 261 | && echo Updated: ${bootfile} |
| 262 | elif test ${file} = boot.env; then |
| 263 | env import -b ${loadaddr} |
| 264 | && echo Updated: boot.env |
| 265 | else |
| 266 | && if test $size = 0; then |
| 267 | setexpr x $filesize - 1 |
| 268 | && setexpr x $x / 0x1000 |
| 269 | && setexpr x $x + 1 |
| 270 | && setexpr x $x * 0x1000 |
| 271 | && setexpr x $x / 0x200 |
| 272 | && size=0x${x} |
| 273 | fi |
| 274 | && mmc write ${loadaddr} ${offset} ${size} |
| 275 | && echo Updated: ${bootfile} |
| 276 | fi |
| 277 | || echo ** UPDATE FAILED: ${bootfile} **" |
| 278 | if mmc dev 1 0; then; else |
| 279 | run bootcmd_dhcp; |
| 280 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 281 | load mmc ${devnum}:${distro_bootpart} 0x02080000 /boot/Image |
| 282 | load mmc ${devnum}:${distro_bootpart} 0x04000000 /boot/uInitrd |
| 283 | load mmc ${devnum}:${distro_bootpart} 0x01f00000 /boot/dtb/rockchip/rk3399-rock-pi-4.dtb |
| 284 | setenv finduuid "part uuid mmc ${devnum}:${distro_bootpart} uuid" |
| 285 | run finduuid |
| 286 | setenv bootargs "earlycon=uart8250,mmio32,0xff1a0000 console=ttyS2,1500000n8 loglevel=7 root=PARTUUID=${uuid} rootwait rootfstype=ext4 sdhci.debug_quirks=0x20000000" |
| 287 | booti 0x02080000 0x04000000 0x01f00000 |
| 288 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 289 | ${ANDROID_HOST_OUT}/bin/mkimage \ |
| 290 | -C none -A arm -T script -d ${mntdir}/boot/boot.cmd ${mntdir}/boot/boot.scr |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 291 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 292 | cd ${KERNEL_DIR} |
| 293 | export PATH=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/clang-r353983c/bin:$PATH |
| 294 | export PATH=${ANDROID_BUILD_TOP}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin:$PATH |
| 295 | make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-androidkernel- \ |
| 296 | CLANG_TRIPLE=aarch64-linux-gnu- rockpi4_defconfig |
| 297 | make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-androidkernel- \ |
| 298 | CLANG_TRIPLE=aarch64-linux-gnu- -j`nproc` |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 299 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 300 | cp ${KERNEL_DIR}/arch/arm64/boot/Image ${mntdir}/boot/ |
| 301 | mkdir -p ${mntdir}/boot/dtb/rockchip/ |
| 302 | cp ${KERNEL_DIR}/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4.dtb ${mntdir}/boot/dtb/rockchip/ |
| 303 | cd - |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 304 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 305 | mount -o bind /proc ${mntdir}/proc |
| 306 | mount -o bind /sys ${mntdir}/sys |
| 307 | mount -o bind /dev ${mntdir}/dev |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 308 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 309 | echo "Installing required packages..." |
| 310 | chroot ${mntdir} /bin/bash <<EOF |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 311 | apt-get update |
Tristan Muntsinger | 5ea7c6a | 2019-10-15 16:53:08 -0700 | [diff] [blame] | 312 | apt-get install -y -f initramfs-tools u-boot-tools network-manager openssh-server sudo man-db vim git dpkg-dev cdbs debhelper config-package-dev gdisk eject lzop binfmt-support ntpdate |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 313 | EOF |
| 314 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 315 | echo "Turning on DHCP client..." |
| 316 | cat >${mntdir}/etc/systemd/network/dhcp.network <<EOF |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 317 | [Match] |
| 318 | Name=en* |
| 319 | |
| 320 | [Network] |
| 321 | DHCP=yes |
| 322 | EOF |
| 323 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 324 | chroot ${mntdir} /bin/bash << "EOT" |
Tristan Muntsinger | 5ea7c6a | 2019-10-15 16:53:08 -0700 | [diff] [blame] | 325 | echo "Adding user vsoc-01 and groups..." |
| 326 | useradd -m -G kvm,sudo -d /home/vsoc-01 --shell /bin/bash vsoc-01 |
| 327 | echo -e "cuttlefish\ncuttlefish" | passwd |
| 328 | echo -e "cuttlefish\ncuttlefish" | passwd vsoc-01 |
| 329 | EOT |
| 330 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 331 | echo "Cloning android-cuttlefish..." |
| 332 | cd ${mntdir}/home/vsoc-01 |
| 333 | git clone https://github.com/google/android-cuttlefish.git |
| 334 | cd - |
Tristan Muntsinger | 5ea7c6a | 2019-10-15 16:53:08 -0700 | [diff] [blame] | 335 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 336 | echo "Creating led script..." |
| 337 | cat > ${mntdir}/usr/local/bin/led << "EOF" |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 338 | #!/bin/bash |
| 339 | |
| 340 | if [ "$1" == "--start" ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 341 | echo 125 > /sys/class/gpio/export |
| 342 | echo out > /sys/class/gpio/gpio125/direction |
| 343 | chmod 666 /sys/class/gpio/gpio125/value |
| 344 | echo 0 > /sys/class/gpio/gpio125/value |
| 345 | exit 0 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 346 | fi |
| 347 | |
| 348 | if [ "$1" == "--stop" ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 349 | echo 0 > /sys/class/gpio/gpio125/value |
| 350 | echo 125 > /sys/class/gpio/unexport |
| 351 | exit 0 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 352 | fi |
| 353 | |
| 354 | if [ ! -e /sys/class/gpio/gpio125/value ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 355 | echo "error: led service not initialized" |
| 356 | exit 1 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 357 | fi |
| 358 | |
| 359 | if [ "$1" == "0" ] || [ "$1" == "off" ] || [ "$1" == "OFF" ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 360 | echo 0 > /sys/class/gpio/gpio125/value |
| 361 | exit 0 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 362 | fi |
| 363 | |
| 364 | if [ "$1" == "1" ] || [ "$1" == "on" ] || [ "$1" == "ON" ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 365 | echo 1 > /sys/class/gpio/gpio125/value |
| 366 | exit 0 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 367 | fi |
| 368 | |
| 369 | echo "usage: led <0|1>" |
| 370 | exit 1 |
| 371 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 372 | chown root:root ${mntdir}/usr/local/bin/led |
| 373 | chmod 755 ${mntdir}/usr/local/bin/led |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 374 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 375 | echo "Creating led service..." |
| 376 | cat > ${mntdir}/etc/systemd/system/led.service << EOF |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 377 | [Unit] |
| 378 | Description=led service |
| 379 | ConditionPathExists=/usr/local/bin/led |
| 380 | |
| 381 | [Service] |
| 382 | Type=oneshot |
| 383 | ExecStart=/usr/local/bin/led --start |
| 384 | ExecStop=/usr/local/bin/led --stop |
| 385 | RemainAfterExit=true |
| 386 | StandardOutput=journal |
| 387 | |
| 388 | [Install] |
| 389 | WantedBy=multi-user.target |
| 390 | EOF |
| 391 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 392 | echo "Creating SD duplicator script..." |
| 393 | cat > ${mntdir}/usr/local/bin/sd-dupe << "EOF" |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 394 | #!/bin/bash |
| 395 | led 0 |
| 396 | |
| 397 | src_dev=mmcblk0 |
| 398 | dest_dev=mmcblk1 |
| 399 | part_num=p5 |
| 400 | |
| 401 | if [ -e /dev/mmcblk0p5 ]; then |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 402 | led 1 |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 403 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 404 | sgdisk -Z -a1 /dev/${dest_dev} |
| 405 | sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 /dev/${dest_dev} |
| 406 | sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env /dev/${dest_dev} |
| 407 | sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 /dev/${dest_dev} |
| 408 | sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust /dev/${dest_dev} |
| 409 | sgdisk -a1 -n:5:32768:- -A:5:set:2 -t:5:8305 -c:5:rootfs /dev/${dest_dev} |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 410 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 411 | src_block_count=`tune2fs -l /dev/${src_dev}${part_num} | grep "Block count:" | sed 's/.*: *//'` |
| 412 | src_block_size=`tune2fs -l /dev/${src_dev}${part_num} | grep "Block size:" | sed 's/.*: *//'` |
| 413 | src_fs_size=$(( src_block_count*src_block_size )) |
| 414 | src_fs_size_m=$(( src_fs_size / 1024 / 1024 + 1 )) |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 415 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 416 | dd if=/dev/${src_dev}p1 of=/dev/${dest_dev}p1 conv=sync,noerror status=progress |
| 417 | dd if=/dev/${src_dev}p2 of=/dev/${dest_dev}p2 conv=sync,noerror status=progress |
| 418 | dd if=/dev/${src_dev}p3 of=/dev/${dest_dev}p3 conv=sync,noerror status=progress |
| 419 | dd if=/dev/${src_dev}p4 of=/dev/${dest_dev}p4 conv=sync,noerror status=progress |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 420 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 421 | echo "Writing ${src_fs_size_m} MB: /dev/${src_dev} -> /dev/${dest_dev}..." |
| 422 | dd if=/dev/${src_dev}${part_num} of=/dev/${dest_dev}${part_num} bs=1M conv=sync,noerror status=progress |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 423 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 424 | echo "Expanding /dev/${dest_dev}${part_num} filesystem..." |
| 425 | e2fsck -fy /dev/${dest_dev}${part_num} |
| 426 | resize2fs /dev/${dest_dev}${part_num} |
| 427 | tune2fs -O has_journal /dev/${dest_dev}${part_num} |
| 428 | e2fsck -fy /dev/${dest_dev}${part_num} |
| 429 | sync /dev/${dest_dev} |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 430 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 431 | echo "Cleaning up..." |
| 432 | mount /dev/${dest_dev}${part_num} /media |
| 433 | chroot /media /usr/local/bin/install-cleanup |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 434 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 435 | if [ $? == 0 ]; then |
| 436 | echo "Successfully copied Rock Pi image!" |
| 437 | while true; do |
| 438 | led 1; sleep 0.5 |
| 439 | led 0; sleep 0.5 |
| 440 | done |
| 441 | else |
| 442 | echo "Error while copying Rock Pi image" |
| 443 | while true; do |
| 444 | led 1; sleep 0.1 |
| 445 | led 0; sleep 0.1 |
| 446 | done |
| 447 | fi |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 448 | else |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 449 | echo "Expanding /dev/${dest_dev}${part_num} filesystem..." |
| 450 | e2fsck -fy /dev/${dest_dev}${part_num} |
| 451 | resize2fs /dev/${dest_dev}${part_num} |
| 452 | tune2fs -O has_journal /dev/${dest_dev}${part_num} |
| 453 | e2fsck -fy /dev/${dest_dev}${part_num} |
| 454 | sync /dev/${dest_dev} |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 455 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 456 | echo "Cleaning up..." |
| 457 | /usr/local/bin/install-cleanup |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 458 | fi |
| 459 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 460 | chmod +x ${mntdir}/usr/local/bin/sd-dupe |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 461 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 462 | echo "Creating SD duplicator service..." |
| 463 | cat > ${mntdir}/etc/systemd/system/sd-dupe.service << EOF |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 464 | [Unit] |
| 465 | Description=Duplicate SD card rootfs to eMMC on Rock Pi |
| 466 | ConditionPathExists=/usr/local/bin/sd-dupe |
| 467 | After=led.service |
| 468 | |
| 469 | [Service] |
| 470 | Type=simple |
| 471 | ExecStart=/usr/local/bin/sd-dupe |
| 472 | TimeoutSec=0 |
| 473 | StandardOutput=tty |
| 474 | |
| 475 | [Install] |
| 476 | WantedBy=multi-user.target |
| 477 | EOF |
| 478 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 479 | echo "Creating cleanup script..." |
| 480 | cat > ${mntdir}/usr/local/bin/install-cleanup << "EOF" |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 481 | #!/bin/bash |
Tristan Muntsinger | 5ea7c6a | 2019-10-15 16:53:08 -0700 | [diff] [blame] | 482 | echo "Installing cuttlefish-common package..." |
| 483 | echo "nameserver 8.8.8.8" > /etc/resolv.conf |
| 484 | MAC=`ip link | grep eth0 -A1 | grep ether | sed 's/.*\(..:..:..:..:..:..\) .*/\1/'` |
| 485 | sed -i " 1 s/.*/& rockpi-${MAC}/" /etc/hosts |
| 486 | sudo hostnamectl set-hostname "rockpi-${MAC}" |
| 487 | |
| 488 | dpkg --add-architecture amd64 |
| 489 | until ping -c1 ftp.debian.org; do sleep 1; done |
| 490 | ntpdate time.google.com |
| 491 | while true; do |
| 492 | apt-get -o Acquire::Check-Valid-Until=false update |
| 493 | if [ $? != 0 ]; then sleep 1; continue; fi |
| 494 | apt-get install -y -f libc6:amd64 qemu-user-static |
| 495 | if [ $? != 0 ]; then sleep 1; continue; fi |
| 496 | break |
| 497 | done |
| 498 | cd /home/vsoc-01/android-cuttlefish |
| 499 | dpkg-buildpackage -d -uc -us |
| 500 | apt-get install -y -f ../cuttlefish-common_*_arm64.deb |
| 501 | apt-get clean |
| 502 | usermod -aG cvdnetwork vsoc-01 |
Tristan Muntsinger | 5ea7c6a | 2019-10-15 16:53:08 -0700 | [diff] [blame] | 503 | chmod 660 /dev/vhost-vsock |
| 504 | chown root:cvdnetwork /dev/vhost-vsock |
| 505 | |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 506 | rm /etc/machine-id |
| 507 | rm /var/lib/dbus/machine-id |
| 508 | dbus-uuidgen --ensure |
| 509 | systemd-machine-id-setup |
| 510 | |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 511 | systemctl disable sd-dupe |
| 512 | rm /etc/systemd/system/sd-dupe.service |
| 513 | rm /usr/local/bin/sd-dupe |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 514 | rm /usr/local/bin/install-cleanup |
| 515 | EOF |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 516 | chmod +x ${mntdir}/usr/local/bin/install-cleanup |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 517 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 518 | chroot ${mntdir} /bin/bash << "EOT" |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 519 | echo "Enabling services..." |
Tristan Muntsinger | ab89e8f | 2019-10-15 20:30:20 -0700 | [diff] [blame] | 520 | systemctl enable led |
| 521 | systemctl enable sd-dupe |
Tristan Muntsinger | d32ee2b | 2019-10-15 15:07:00 -0700 | [diff] [blame] | 522 | |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 523 | echo "Creating Initial Ramdisk..." |
| 524 | update-initramfs -c -t -k "5.2.0" |
| 525 | mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d /boot/initrd.img-5.2.0 /boot/uInitrd-5.2.0 |
| 526 | ln -s /boot/uInitrd-5.2.0 /boot/uInitrd |
| 527 | EOT |
| 528 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 529 | umount ${mntdir}/sys |
| 530 | umount ${mntdir}/dev |
| 531 | umount ${mntdir}/proc |
| 532 | umount ${mntdir} |
| 533 | |
| 534 | # Turn on journaling |
| 535 | tune2fs -O ^has_journal ${IMAGE} |
| 536 | e2fsck -fy ${IMAGE} >/dev/null 2>&1 |
| 537 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 538 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 539 | if [ ${USE_IMAGE} -eq 0 ]; then |
| 540 | # 32GB eMMC size |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 541 | end_sector=61071326 |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 542 | device=/dev/${mmc_dev} |
| 543 | devicep=${device} |
| 544 | |
| 545 | sgdisk -Z -a1 ${device} |
| 546 | sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 ${device} |
| 547 | sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env ${device} |
| 548 | sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 ${device} |
| 549 | sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust ${device} |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 550 | sgdisk -a1 -n:5:32768:${end_sector} -A:5:set:2 -t:5:8305 -c:5:rootfs ${device} |
| 551 | if [ ${FLAGS_p5} -eq ${FLAGS_TRUE} ]; then |
| 552 | dd if=${IMAGE} of=${devicep}5 bs=1M |
| 553 | resize2fs ${devicep}5 >/dev/null 2>&1 |
| 554 | fi |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 555 | else |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 556 | device=$(losetup -f) |
| 557 | devicep=${device}p |
| 558 | if [ ${FLAGS_p5} -eq ${FLAGS_FALSE} ]; then |
| 559 | fs_end=3G |
| 560 | end_sector=- |
| 561 | fi |
| 562 | if [ ${FLAGS_p5} -eq ${FLAGS_TRUE} ]; then |
| 563 | # Minimize rootfs filesystem |
| 564 | while true; do |
| 565 | out=`sudo resize2fs -M ${IMAGE} 2>&1` |
| 566 | if [[ $out =~ "Nothing to do" ]]; then |
| 567 | break |
| 568 | fi |
| 569 | done |
| 570 | # Minimize rootfs file size |
| 571 | block_count=`sudo tune2fs -l ${IMAGE} | grep "Block count:" | sed 's/.*: *//'` |
| 572 | block_size=`sudo tune2fs -l ${IMAGE} | grep "Block size:" | sed 's/.*: *//'` |
| 573 | sector_size=512 |
| 574 | start_sector=32768 |
| 575 | fs_size=$(( block_count*block_size )) |
| 576 | fs_sectors=$(( fs_size/sector_size )) |
| 577 | part_sectors=$(( ((fs_sectors-1)/2048+1)*2048 )) # 1MB-aligned |
| 578 | end_sector=$(( start_sector+part_sectors-1 )) |
| 579 | secondary_gpt_sectors=33 |
| 580 | fs_end=$(( (end_sector+secondary_gpt_sectors+1)*sector_size )) |
| 581 | image_size=$(( part_sectors*sector_size )) |
| 582 | truncate -s ${image_size} ${IMAGE} |
| 583 | e2fsck -fy ${IMAGE} >/dev/null 2>&1 |
| 584 | fi |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 585 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 586 | # Create final image |
Tristan Muntsinger | 1f28d1f | 2019-10-16 22:53:55 -0700 | [diff] [blame] | 587 | if [ $OVERWRITE -eq 1 ]; then |
| 588 | tmpimg=${OVERWRITE_IMAGE} |
| 589 | else |
| 590 | tmpimg=`mktemp` |
| 591 | fi |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 592 | truncate -s ${fs_end} ${tmpimg} |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 593 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 594 | # Create GPT |
| 595 | sgdisk -Z -a1 ${tmpimg} |
| 596 | sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 ${tmpimg} |
| 597 | sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env ${tmpimg} |
| 598 | sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 ${tmpimg} |
| 599 | sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust ${tmpimg} |
| 600 | sgdisk -a1 -n:5:32768:${end_sector} -A:5:set:2 -t:5:8305 -c:5:rootfs ${tmpimg} |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 601 | |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 602 | losetup ${device} ${tmpimg} |
| 603 | partx -v --add ${device} |
Tristan Muntsinger | 82c1050 | 2019-10-15 14:49:19 -0700 | [diff] [blame] | 604 | |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 605 | if [ ${FLAGS_p5} -eq ${FLAGS_TRUE} ]; then |
| 606 | dd if=${IMAGE} of=${devicep}5 bs=1M |
| 607 | fi |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 608 | fi |
Tristan Muntsinger | 3456911 | 2019-10-16 22:10:54 -0700 | [diff] [blame] | 609 | if [ ${FLAGS_p1} -eq ${FLAGS_TRUE} ]; then |
| 610 | dd if=${idbloader} of=${devicep}1 |
| 611 | fi |
| 612 | if [ ${FLAGS_p2} -eq ${FLAGS_TRUE} ]; then |
| 613 | dd if=${bootenv} of=${devicep}2 |
| 614 | fi |
| 615 | if [ ${FLAGS_p3} -eq ${FLAGS_TRUE} ]; then |
| 616 | dd if=${ANDROID_BUILD_TOP}/external/u-boot/u-boot.itb of=${devicep}3 |
| 617 | fi |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 618 | if [ ${USE_IMAGE} -eq 1 ]; then |
| 619 | chown $SUDO_USER:`id -ng $SUDO_USER` ${tmpimg} |
Tristan Muntsinger | 1f28d1f | 2019-10-16 22:53:55 -0700 | [diff] [blame] | 620 | if [ $OVERWRITE -eq 0 ]; then |
| 621 | mv ${tmpimg} ${IMAGE} |
| 622 | fi |
Tristan Muntsinger | e4eeded | 2019-10-15 20:26:15 -0700 | [diff] [blame] | 623 | partx -v --delete ${device} |
| 624 | losetup -d ${device} |
| 625 | fi |