blob: 76afda0cd89f308f56441e547acf99bc15a6d647 [file] [log] [blame]
Tristan Muntsinger82c10502019-10-15 14:49:19 -07001#!/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
17source "${ANDROID_BUILD_TOP}/external/shflags/src/shflags"
18
19FLAGS_HELP="USAGE: $0 <KERNEL_DIR> [IMAGE]"
20
21FLAGS "$@" || exit $?
22eval set -- "${FLAGS_ARGV}"
23
24for arg in "$@" ; do
25 if [ -z $KERNEL_DIR ]; then
26 KERNEL_DIR=$arg
27 elif [ -z $IMAGE ]; then
28 IMAGE=$arg
29 else
30 flags_help
31 exit 1
32 fi
33done
34
Tristan Muntsingere4eeded2019-10-15 20:26:15 -070035USE_IMAGE=`[ -z "${IMAGE}" ] && echo "0" || echo "1"`
Tristan Muntsinger82c10502019-10-15 14:49:19 -070036if [ -z $KERNEL_DIR ] || [ -z $IMAGE ]; then
37 flags_help
38 exit 1
39fi
40if [ -e "${IMAGE}" ]; then
41 echo "error: ${IMAGE} already exists"
42 exit 1
43fi
44if [ ! -e "${KERNEL_DIR}" ]; then
45 echo "error: can't find '${KERNEL_DIR}'. aborting..."
46 exit 1
47fi
48
49# escalate to superuser
50if [ $UID -ne 0 ]; then
51 cd ${ANDROID_BUILD_TOP}
52 . ./build/envsetup.sh
53 lunch ${TARGET_PRODUCT}-${TARGET_BUILD_VARIANT}
54 mmma external/u-boot
55 cd -
56 exec sudo -E "${0}" ${@}
57fi
58
Tristan Muntsingere4eeded2019-10-15 20:26:15 -070059if [ $USE_IMAGE -eq 0 ]; then
60 init_devs=`lsblk --nodeps -oNAME -n`
61 echo "Reinsert device (to write to) into PC"
62 while true; do
63 devs=`lsblk --nodeps -oNAME -n`
64 new_devs="$(echo -e "${init_devs}\n${devs}" | sort | uniq -u | awk 'NF')"
65 num_devs=`echo "${new_devs}" | wc -l`
66 if [[ "${new_devs}" == "" ]]; then
67 num_devs=0
68 fi
69 if [[ ${num_devs} -gt 1 ]]; then
70 echo "error: too many new devices detected! aborting..."
71 exit 1
72 fi
73 if [[ ${num_devs} -eq 1 ]]; then
74 if [[ "${new_devs}" != "${mmc_dev}" ]]; then
75 if [[ "${mmc_dev}" != "" ]]; then
76 echo "error: block device name mismatch ${new_devs} != ${mmc_dev}"
77 echo "Reinsert device (to write to) into PC"
78 fi
79 mmc_dev=${new_devs}
80 continue
81 fi
82 echo "${init_devs}" | grep "${mmc_dev}" >/dev/null
83 if [[ $? -eq 0 ]]; then
84 init_devs="${devs}"
85 continue
86 fi
87 break
88 fi
89 done
90 # now inform the user
91 echo "Detected device at /dev/${mmc_dev}"
92fi
93
Tristan Muntsinger82c10502019-10-15 14:49:19 -070094cd ${ANDROID_BUILD_TOP}/external/arm-trusted-firmware
95CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rk3399 DEBUG=0 ERROR_DEPRECATED=1 bl31
96export BL31="${ANDROID_BUILD_TOP}/external/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf"
97cd -
98
Tristan Muntsinger82c10502019-10-15 14:49:19 -070099cd ${ANDROID_BUILD_TOP}/external/u-boot
Tristan Muntsinger5f263952019-10-16 21:12:06 -0700100
101tmpfile=`mktemp`
102bootenv=`mktemp`
103cat > ${tmpfile} << "EOF"
104bootdelay=2
105baudrate=1500000
106scriptaddr=0x00500000
107boot_targets=mmc1 mmc0
108bootcmd=run distro_bootcmd
109distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
110bootcmd_mmc0=devnum=0; run mmc_boot
111bootcmd_mmc1=devnum=1; run mmc_boot
112mmc_boot=if mmc dev ${devnum}; then ; run scan_for_boot_part; fi
113scan_for_boot_part=part list mmc ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for part in ${devplist}; do if fstype mmc ${devnum}:${part} bootfstype; then run find_init_script; fi; done; setenv devplist
114find_init_script=if test -e mmc ${devnum}:${part} /boot/init.scr; then echo Found U-Boot script /boot/init.scr; run init_scr; fi
115init_scr=load mmc ${devnum}:${part} ${scriptaddr} /boot/init.scr; source ${scriptaddr}
116EOF
117${ANDROID_HOST_OUT}/bin/mkenvimage -s 32768 -o ${bootenv} - < ${tmpfile}
118
119idbloader=`mktemp`
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700120make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- rock-pi-4-rk3399_defconfig
121make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- -j`nproc`
122${ANDROID_HOST_OUT}/bin/mkimage -n rk3399 -T rksd -d tpl/u-boot-tpl.bin ${idbloader}
123cat spl/u-boot-spl.bin >> ${idbloader}
124cd -
125
126${ANDROID_BUILD_TOP}/kernel/tests/net/test/build_rootfs.sh -a arm64 -s buster -n ${IMAGE}
127if [ $? -ne 0 ]; then
128 echo "error: failed to build rootfs. exiting..."
129 exit 1
130fi
131truncate -s +3G ${IMAGE}
132e2fsck -f ${IMAGE}
133resize2fs ${IMAGE}
134
135mntdir=`mktemp -d`
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700136mount ${IMAGE} ${mntdir}
137if [ $? != 0 ]; then
138 echo "error: unable to mount ${IMAGE} ${mntdir}"
139 exit 1
140fi
141
Tristan Muntsinger5f263952019-10-16 21:12:06 -0700142cat > ${mntdir}/boot/init.cmd << "EOF"
143mmc dev 1 0; mmc read 0x02080000 0x1fc0 0x40;
144ethaddr=$ethaddr
145env default -a
146setenv ethaddr $ethaddr
147setenv boot_targets 'mmc1 mmc0 usb0 pxe'
148saveenv
149mmc dev 1 0; mmc read 0x04000000 0x1fc0 0x40;
150mmc dev 0 0; mmc write 0x04000000 0x1fc0 0x40;
151mmc dev 1 0; mmc write 0x02080000 0x1fc0 0x40;
152EOF
153${ANDROID_BUILD_TOP}/external/u-boot/tools/mkimage \
154 -C none -A arm -T script -d ${mntdir}/boot/init.cmd ${mntdir}/boot/init.scr
155
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700156cat > ${mntdir}/boot/boot.cmd << "EOF"
157load mmc ${devnum}:${distro_bootpart} 0x02080000 /boot/Image
158load mmc ${devnum}:${distro_bootpart} 0x04000000 /boot/uInitrd
159load mmc ${devnum}:${distro_bootpart} 0x01f00000 /boot/dtb/rockchip/rk3399-rock-pi-4.dtb
160setenv finduuid "part uuid mmc ${devnum}:${distro_bootpart} uuid"
161run finduuid
162setenv bootargs "earlycon=uart8250,mmio32,0xff1a0000 console=ttyS2,1500000n8 loglevel=7 root=PARTUUID=${uuid} rootwait rootfstype=ext4 sdhci.debug_quirks=0x20000000"
163booti 0x02080000 0x04000000 0x01f00000
164EOF
165${ANDROID_HOST_OUT}/bin/mkimage \
166 -C none -A arm -T script -d ${mntdir}/boot/boot.cmd ${mntdir}/boot/boot.scr
167
168cd ${KERNEL_DIR}
169export PATH=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/clang-r353983c/bin:$PATH
170export PATH=${ANDROID_BUILD_TOP}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin:$PATH
171make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-androidkernel- \
172 CLANG_TRIPLE=aarch64-linux-gnu- rockpi4_defconfig
173make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-androidkernel- \
174 CLANG_TRIPLE=aarch64-linux-gnu- -j`nproc`
175
176cp ${KERNEL_DIR}/arch/arm64/boot/Image ${mntdir}/boot/
177mkdir -p ${mntdir}/boot/dtb/rockchip/
178cp ${KERNEL_DIR}/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4.dtb ${mntdir}/boot/dtb/rockchip/
179cd -
180
Tristan Muntsinger5ea7c6a2019-10-15 16:53:08 -0700181mount -o bind /proc ${mntdir}/proc
182mount -o bind /sys ${mntdir}/sys
183mount -o bind /dev ${mntdir}/dev
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700184
185echo "Installing required packages..."
186chroot ${mntdir} /bin/bash <<EOF
187apt-get update
Tristan Muntsinger5ea7c6a2019-10-15 16:53:08 -0700188apt-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 Muntsinger82c10502019-10-15 14:49:19 -0700189EOF
190
191echo "Turning on DHCP client..."
192cat >${mntdir}/etc/systemd/network/dhcp.network <<EOF
193[Match]
194Name=en*
195
196[Network]
197DHCP=yes
198EOF
199
Tristan Muntsinger5ea7c6a2019-10-15 16:53:08 -0700200chroot ${mntdir} /bin/bash << "EOT"
201echo "Adding user vsoc-01 and groups..."
202useradd -m -G kvm,sudo -d /home/vsoc-01 --shell /bin/bash vsoc-01
203echo -e "cuttlefish\ncuttlefish" | passwd
204echo -e "cuttlefish\ncuttlefish" | passwd vsoc-01
205EOT
206
207echo "Cloning android-cuttlefish..."
208cd ${mntdir}/home/vsoc-01
209git clone https://github.com/google/android-cuttlefish.git
210cd -
211
Tristan Muntsingerab89e8f2019-10-15 20:30:20 -0700212echo "Creating led script..."
213cat > ${mntdir}/usr/local/bin/led << "EOF"
214#!/bin/bash
215
216if [ "$1" == "--start" ]; then
217 echo 125 > /sys/class/gpio/export
218 echo out > /sys/class/gpio/gpio125/direction
219 chmod 666 /sys/class/gpio/gpio125/value
220 echo 0 > /sys/class/gpio/gpio125/value
221 exit 0
222fi
223
224if [ "$1" == "--stop" ]; then
225 echo 0 > /sys/class/gpio/gpio125/value
226 echo 125 > /sys/class/gpio/unexport
227 exit 0
228fi
229
230if [ ! -e /sys/class/gpio/gpio125/value ]; then
231 echo "error: led service not initialized"
232 exit 1
233fi
234
235if [ "$1" == "0" ] || [ "$1" == "off" ] || [ "$1" == "OFF" ]; then
236 echo 0 > /sys/class/gpio/gpio125/value
237 exit 0
238fi
239
240if [ "$1" == "1" ] || [ "$1" == "on" ] || [ "$1" == "ON" ]; then
241 echo 1 > /sys/class/gpio/gpio125/value
242 exit 0
243fi
244
245echo "usage: led <0|1>"
246exit 1
247EOF
248chown root:root ${mntdir}/usr/local/bin/led
249chmod 755 ${mntdir}/usr/local/bin/led
250
251echo "Creating led service..."
252cat > ${mntdir}/etc/systemd/system/led.service << EOF
253[Unit]
254 Description=led service
255 ConditionPathExists=/usr/local/bin/led
256
257[Service]
258 Type=oneshot
259 ExecStart=/usr/local/bin/led --start
260 ExecStop=/usr/local/bin/led --stop
261 RemainAfterExit=true
262 StandardOutput=journal
263
264[Install]
265 WantedBy=multi-user.target
266EOF
267
268echo "Creating SD duplicator script..."
269cat > ${mntdir}/usr/local/bin/sd-dupe << "EOF"
270#!/bin/bash
271led 0
272
273src_dev=mmcblk0
274dest_dev=mmcblk1
275part_num=p5
276
277if [ -e /dev/mmcblk0p5 ]; then
278 led 1
279
280 sgdisk -Z -a1 /dev/${dest_dev}
281 sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 /dev/${dest_dev}
282 sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env /dev/${dest_dev}
283 sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 /dev/${dest_dev}
284 sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust /dev/${dest_dev}
285 sgdisk -a1 -n:5:32768:- -A:5:set:2 -t:5:8305 -c:5:rootfs /dev/${dest_dev}
286
287 src_block_count=`tune2fs -l /dev/${src_dev}${part_num} | grep "Block count:" | sed 's/.*: *//'`
288 src_block_size=`tune2fs -l /dev/${src_dev}${part_num} | grep "Block size:" | sed 's/.*: *//'`
289 src_fs_size=$(( src_block_count*src_block_size ))
290 src_fs_size_m=$(( src_fs_size / 1024 / 1024 + 1 ))
291
292 dd if=/dev/${src_dev}p1 of=/dev/${dest_dev}p1 conv=sync,noerror status=progress
293 dd if=/dev/${src_dev}p2 of=/dev/${dest_dev}p2 conv=sync,noerror status=progress
294 dd if=/dev/${src_dev}p3 of=/dev/${dest_dev}p3 conv=sync,noerror status=progress
295 dd if=/dev/${src_dev}p4 of=/dev/${dest_dev}p4 conv=sync,noerror status=progress
296
297 echo "Writing ${src_fs_size_m} MB: /dev/${src_dev} -> /dev/${dest_dev}..."
298 dd if=/dev/${src_dev}${part_num} of=/dev/${dest_dev}${part_num} bs=1M conv=sync,noerror status=progress
299
300 echo "Expanding /dev/${dest_dev}${part_num} filesystem..."
301 e2fsck -fy /dev/${dest_dev}${part_num}
302 resize2fs /dev/${dest_dev}${part_num}
303 tune2fs -O has_journal /dev/${dest_dev}${part_num}
304 e2fsck -fy /dev/${dest_dev}${part_num}
305 sync /dev/${dest_dev}
306
307 echo "Cleaning up..."
308 mount /dev/${dest_dev}${part_num} /media
309 chroot /media /usr/local/bin/install-cleanup
310
311 if [ $? == 0 ]; then
312 echo "Successfully copied Rock Pi image!"
313 while true; do
314 led 1; sleep 0.5
315 led 0; sleep 0.5
316 done
317 else
318 echo "Error while copying Rock Pi image"
319 while true; do
320 led 1; sleep 0.1
321 led 0; sleep 0.1
322 done
323 fi
324else
325 echo "Expanding /dev/${dest_dev}${part_num} filesystem..."
326 e2fsck -fy /dev/${dest_dev}${part_num}
327 resize2fs /dev/${dest_dev}${part_num}
328 tune2fs -O has_journal /dev/${dest_dev}${part_num}
329 e2fsck -fy /dev/${dest_dev}${part_num}
330 sync /dev/${dest_dev}
331
332 echo "Cleaning up..."
333 /usr/local/bin/install-cleanup
334fi
335EOF
336chmod +x ${mntdir}/usr/local/bin/sd-dupe
337
338echo "Creating SD duplicator service..."
339cat > ${mntdir}/etc/systemd/system/sd-dupe.service << EOF
340[Unit]
341 Description=Duplicate SD card rootfs to eMMC on Rock Pi
342 ConditionPathExists=/usr/local/bin/sd-dupe
343 After=led.service
344
345[Service]
346 Type=simple
347 ExecStart=/usr/local/bin/sd-dupe
348 TimeoutSec=0
349 StandardOutput=tty
350
351[Install]
352 WantedBy=multi-user.target
353EOF
354
Tristan Muntsingerd32ee2b2019-10-15 15:07:00 -0700355echo "Creating cleanup script..."
356cat > ${mntdir}/usr/local/bin/install-cleanup << "EOF"
357#!/bin/bash
Tristan Muntsinger5ea7c6a2019-10-15 16:53:08 -0700358echo "Installing cuttlefish-common package..."
359echo "nameserver 8.8.8.8" > /etc/resolv.conf
360MAC=`ip link | grep eth0 -A1 | grep ether | sed 's/.*\(..:..:..:..:..:..\) .*/\1/'`
361sed -i " 1 s/.*/& rockpi-${MAC}/" /etc/hosts
362sudo hostnamectl set-hostname "rockpi-${MAC}"
363
364dpkg --add-architecture amd64
365until ping -c1 ftp.debian.org; do sleep 1; done
366ntpdate time.google.com
367while true; do
368 apt-get -o Acquire::Check-Valid-Until=false update
369 if [ $? != 0 ]; then sleep 1; continue; fi
370 apt-get install -y -f libc6:amd64 qemu-user-static
371 if [ $? != 0 ]; then sleep 1; continue; fi
372 break
373done
374cd /home/vsoc-01/android-cuttlefish
375dpkg-buildpackage -d -uc -us
376apt-get install -y -f ../cuttlefish-common_*_arm64.deb
377apt-get clean
378usermod -aG cvdnetwork vsoc-01
Tristan Muntsinger5ea7c6a2019-10-15 16:53:08 -0700379chmod 660 /dev/vhost-vsock
380chown root:cvdnetwork /dev/vhost-vsock
381
Tristan Muntsingerd32ee2b2019-10-15 15:07:00 -0700382rm /etc/machine-id
383rm /var/lib/dbus/machine-id
384dbus-uuidgen --ensure
385systemd-machine-id-setup
386
Tristan Muntsingerab89e8f2019-10-15 20:30:20 -0700387systemctl disable sd-dupe
388rm /etc/systemd/system/sd-dupe.service
389rm /usr/local/bin/sd-dupe
Tristan Muntsingerd32ee2b2019-10-15 15:07:00 -0700390rm /usr/local/bin/install-cleanup
391EOF
392chmod +x ${mntdir}/usr/local/bin/install-cleanup
393
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700394chroot ${mntdir} /bin/bash << "EOT"
Tristan Muntsingerd32ee2b2019-10-15 15:07:00 -0700395echo "Enabling services..."
Tristan Muntsingerab89e8f2019-10-15 20:30:20 -0700396systemctl enable led
397systemctl enable sd-dupe
Tristan Muntsingerd32ee2b2019-10-15 15:07:00 -0700398
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700399echo "Creating Initial Ramdisk..."
400update-initramfs -c -t -k "5.2.0"
401mkimage -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
402ln -s /boot/uInitrd-5.2.0 /boot/uInitrd
403EOT
404
405umount ${mntdir}/sys
406umount ${mntdir}/dev
407umount ${mntdir}/proc
408umount ${mntdir}
409
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700410if [ ${USE_IMAGE} -eq 0 ]; then
411 # 32GB eMMC size
412 last_sector=61071326
413
414 device=/dev/${mmc_dev}
415 devicep=${device}
416
417 sgdisk -Z -a1 ${device}
418 sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 ${device}
419 sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env ${device}
420 sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 ${device}
421 sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust ${device}
422 sgdisk -a1 -n:5:32768:${last_sector} -A:5:set:2 -t:5:8305 -c:5:rootfs ${device}
423fi
424
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700425# Turn on journaling
426tune2fs -O ^has_journal ${IMAGE}
427e2fsck -fy ${IMAGE} >/dev/null 2>&1
428
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700429if [ ${USE_IMAGE} -eq 0 ]; then
430 dd if=${IMAGE} of=${devicep}5 bs=1M
431 resize2fs ${devicep}5 >/dev/null 2>&1
432else
433 # Minimize rootfs filesystem
434 while true; do
435 out=`sudo resize2fs -M ${IMAGE} 2>&1`
436 if [[ $out =~ "Nothing to do" ]]; then
437 break
438 fi
439 done
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700440
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700441 # Minimize rootfs file size
442 block_count=`sudo tune2fs -l ${IMAGE} | grep "Block count:" | sed 's/.*: *//'`
443 block_size=`sudo tune2fs -l ${IMAGE} | grep "Block size:" | sed 's/.*: *//'`
444 sector_size=512
445 start_sector=32768
446 fs_size=$(( block_count*block_size ))
447 fs_sectors=$(( fs_size/sector_size ))
448 part_sectors=$(( ((fs_sectors-1)/2048+1)*2048 )) # 1MB-aligned
449 end_sector=$(( start_sector+part_sectors-1 ))
450 secondary_gpt_sectors=33
451 fs_end=$(( (end_sector+secondary_gpt_sectors+1)*sector_size ))
452 image_size=$(( part_sectors*sector_size ))
453 truncate -s ${image_size} ${IMAGE}
454 e2fsck -fy ${IMAGE} >/dev/null 2>&1
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700455
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700456 # Create final image
457 tmpimg=`mktemp`
458 truncate -s ${fs_end} ${tmpimg}
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700459
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700460 # Create GPT
461 sgdisk -Z -a1 ${tmpimg}
462 sgdisk -a1 -n:1:64:8127 -t:1:8301 -c:1:loader1 ${tmpimg}
463 sgdisk -a1 -n:2:8128:8191 -t:2:8301 -c:2:env ${tmpimg}
464 sgdisk -a1 -n:3:16384:24575 -t:3:8301 -c:3:loader2 ${tmpimg}
465 sgdisk -a1 -n:4:24576:32767 -t:4:8301 -c:4:trust ${tmpimg}
466 sgdisk -a1 -n:5:32768:${end_sector} -A:5:set:2 -t:5:8305 -c:5:rootfs ${tmpimg}
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700467
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700468 device=$(losetup -f)
469 devicep=${device}p
470 losetup ${device} ${tmpimg}
471 partx -v --add ${device}
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700472
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700473 # copy over data
474 dd if=${IMAGE} of=${devicep}5 bs=1M
475fi
Tristan Muntsinger82c10502019-10-15 14:49:19 -0700476
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700477dd if=${idbloader} of=${devicep}1
Tristan Muntsinger5f263952019-10-16 21:12:06 -0700478dd if=${bootenv} of=${devicep}2
Tristan Muntsingere4eeded2019-10-15 20:26:15 -0700479dd if=${ANDROID_BUILD_TOP}/external/u-boot/u-boot.itb of=${devicep}3
480
481if [ ${USE_IMAGE} -eq 1 ]; then
482 chown $SUDO_USER:`id -ng $SUDO_USER` ${tmpimg}
483 mv ${tmpimg} ${IMAGE}
484 partx -v --delete ${device}
485 losetup -d ${device}
486fi