arm-sdk

os build toolkit for various embedded devices
git clone https://git.parazyd.org/arm-sdk
Log | Files | Refs | Submodules | README | LICENSE

commit 71142cfcbcb72fa34e8dbd224df8b98a2e9af576
parent 09473ce00947cc42e9310daa86bec903ad573100
Author: parazyd <parazyd@dyne.org>
Date:   Fri, 15 Apr 2016 18:03:33 +0200

refactor prepimg

Diffstat:
MREADME.md | 2+-
Marm/common | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
2 files changed, 62 insertions(+), 30 deletions(-)

diff --git a/README.md b/README.md @@ -16,7 +16,7 @@ from shell scripts. Using a Debian-based OS, install the following packages: ``` -gnupg2 debootstrap curl rsync gcc-arm-none-eabi parted kpartx qemu-user-static sudo git-core parted gcc-multilib lib32z1 u-boot-tools device-tree-compiler +gnupg2 debootstrap curl rsync gcc-arm-none-eabi parted kpartx qemu-user-static sudo git-core parted gcc-multilib lib32z1 u-boot-tools device-tree-compiler cgpt ``` ## Quick start diff --git a/arm/common b/arm/common @@ -218,8 +218,8 @@ ${device_name}-thirdstage() { export DEBIAN_FRONTEND=noninteractive sudo -E mount -t proc proc ${strapdir}/proc && notice "Mounted proc..." - sudo -E mount --rbind /dev/ ${strapdir}/dev/ && notice "Mounted dev..." - sudo -E mount --rbind /dev/pts ${strapdir}/dev/pts && notice "Mounted dev/pts..." + sudo -E mount -o bind /dev/ ${strapdir}/dev/ && notice "Mounted dev..." + sudo -E mount -o bind /dev/pts ${strapdir}/dev/pts && notice "Mounted dev/pts..." notice "Chrooting..." LANG=C sudo -E chroot $strapdir /third-stage @@ -238,9 +238,12 @@ ${device_name}-thirdstage() { copy-zram - sudo umount -nR ${strapdir}/dev/pts && notice "Unmounted dev/pts" - sudo umount -nR ${strapdir}/dev && notice "Unmounted dev" + sudo umount ${strapdir}/dev/pts && notice "Unmounted dev/pts" + sleep 5 + sudo umount ${strapdir}/dev && notice "Unmounted dev" + sleep 2 sudo umount ${strapdir}/proc && notice "Unmounted proc" + sleep 2 notice "Finalized third-stage" notice "Next step is: ${device_name}-prepimg" } @@ -254,31 +257,60 @@ ${device_name}-prepimg() { bs=1M count=$size notice "Partitioning..." - parted ${image_name}.img --script -- mklabel msdos - parted ${image_name}.img --script -- mkpart primary ${parted_boot} - parted ${image_name}.img --script -- mkpart primary ${parted_root} - - loopdevice=`sudo losetup -f --show ${workdir}/${image_name}.img` - mappdevice=`sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1` - notice "Loopdevice: $loopdevice" - notice "Mapper device: $mappdevice" - - sleep 2 - - mappdevice="/dev/mapper/${mappdevice}" - bootpart=${mappdevice}p1 - rootpart=${mappdevice}p2 - - notice "Formatting partitions..." - sudo mkfs.vfat $bootpart - sudo mkfs.ext4 $rootpart - - mkdir -p ${workdir}/bootp ${workdir}/root - sudo mount $bootpart ${workdir}/bootp && notice "Mounted boot part" - sudo mount $rootpart ${workdir}/root && notice "Mounted root part" - - print ${inittab} | sudo tee -a ${strapdir}/etc/inittab - for i in $custmodules; do print $i | sudo tee -a ${strapdir}/etc/modules ; done + if [[ $gpt == 1 ]]; then + parted ${image_name}.img --script -- mklabel gpt + cgpt create -z ${image_name}.img + cgpt create ${image_name}.img + cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 ${image_name}.img + cgpt add -i 2 -t data -b 40960 -s `expr $(cgpt show ${image_name}.img \ + | grep 'Sec GPT table' \ + | awk '{print \$1}') - 40960` -l Root ${image_name}.img + + loopdevice=`sudo losetup -f --show ${workdir}/${image_name}.img` + mappdevice=`sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1` + notice "Loopdevice: $loopdevice" + notice "Mapper device: $mappdevice" + + warn "Do not think of purple hippos" && sleep 5 + + mappdevice="/dev/mapper/${mappdevice}" + bootpart=${mappdevice}p1 + rootpart=${mappdevice}p2 + + notice "Formatting partitions..." + mkfs.ext4 -L rootfs $rootpart + + mkdir -p ${workdir}/root + sudo mount $rootpart ${workdir}/root && notice "Mounted root part" + + for i in $custmodules; do print $i | sudo tee -a ${strapdir}/etc/modules ; done + else + parted ${image_name}.img --script -- mklabel msdos + parted ${image_name}.img --script -- mkpart primary ${parted_boot} + parted ${image_name}.img --script -- mkpart primary ${parted_root} + + loopdevice=`sudo losetup -f --show ${workdir}/${image_name}.img` + mappdevice=`sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1` + notice "Loopdevice: $loopdevice" + notice "Mapper device: $mappdevice" + + warn "Do not think of purple hippos" && sleep 5 + + mappdevice="/dev/mapper/${mappdevice}" + bootpart=${mappdevice}p1 + rootpart=${mappdevice}p2 + + notice "Formatting partitions..." + sudo mkfs.vfat $bootpart + sudo mkfs.ext4 $rootpart + + mkdir -p ${workdir}/bootp ${workdir}/root + sudo mount $bootpart ${workdir}/bootp && notice "Mounted boot part" + sudo mount $rootpart ${workdir}/root && notice "Mounted root part" + + print ${inittab} | sudo tee -a ${strapdir}/etc/inittab + for i in $custmodules; do print $i | sudo tee -a ${strapdir}/etc/modules ; done + fi notice "Finalized preparing image" notice "Next step is ${device_name}-build-kernel"