Commit 914af8a1 authored by Rabeeh Khoury's avatar Rabeeh Khoury

Different method to install ubuntu rootfs

Previously multistrap was used to download and create an ubuntu rootfs;
but multistrap failed under docker build since it required binfmt
installed.

This technique of installing ubuntu rootfs is totally different method,
takes more time to build but works under the native runme.sh script and
under docker build.

The method idea is -
1. Build a simple rootfs with a kernel that can be booted via
qemu-system-aarch64.
2. Install an initi script called S99bootstrap-ubuntu.sh under
/etc/init.d.
3. Run a qemu-system-aarch64 virtual machine with 1GByte of system
memory and use cortex-a57 which is the closed to cortex-a72,
virtualization wise and has the buildroot rootf as initrd and the
destination ubuntu-core.ext4 partition as a drive.
4. The VM would boot the kernel, mount the rootfs and run the
S99bootstrap-ubuntu.sh script
5. The script would download an ubuntu base image and then 'apt install'
in a virtual chrooted environment the reset of the packages to make this
rootfs to be bootable.
6. Use 'reboot' in the VM which triggers the '-no-reboot' flag for qemu
that makes the vm exit; and thus installation is continued.
7. ubuntu-core.ext4 partition is now ready to be used further on for
imaging and installations.
Signed-off-by: default avatarRabeeh Khoury <rabeeh@solid-run.com>
parent 019e12fa
......@@ -11,7 +11,7 @@ The build script builds the u-boot, atf, rcw and linux components, integrate it
## Build with Docker
A docker image providing a consistent build environment can be used as below. Since some steps require mounting a loopback device, you need to grant permission for the container to do so when launching:
A docker image providing a consistent build environment can be used as below:
1. build container image (first time only)
```
......@@ -19,7 +19,7 @@ A docker image providing a consistent build environment can be used as below. Si
```
2. invoke build script in working directory
```
docker run --cap-add SYS_ADMIN --device /dev/loop0 --device /dev/loop-control -i -t -v "$PWD":/work lx2160a_build $(id -u) $(id -g)
docker run -i -t -v "$PWD":/work lx2160a_build $(id -u) $(id -g)
```
## Build with host tools
......@@ -41,7 +41,7 @@ Selecting boot loader - *BOOT_LOADER=u-boot,uefi*
### Examples:
- `./runme.sh` **or**
- `docker run --cap-add SYS_ADMIN --device /dev/loop0 --device /dev/loop-control -i -t -v "$PWD":/work lx2160a_build $(id -u) $(id -g)`
- `docker run -i -t -v "$PWD":/work lx2160a_build $(id -u) $(id -g)`
generates *images/lx2160acex7_2000_700_3200_8_5_2.img* which is an image ready to be deployed on micro SD card and *images/lx2160acex7_xspi_2000_700_3200_8_5_2.img* which is an image ready to be deployed on the COM SPI flash.
......
......@@ -2,10 +2,17 @@ BR2_aarch64=y
BR2_cortex_a72=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_TARGET_GENERIC_HOSTNAME="localhost"
BR2_ROOTFS_OVERLAY="overlay/"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_E2FSPROGS=y
# BR2_PACKAGE_E2FSPROGS_FSCK is not set
BR2_PACKAGE_I2C_TOOLS=y
BR2_PACKAGE_RNG_TOOLS=y
BR2_PACKAGE_BASH=y
BR2_PACKAGE_TAR=y
BR2_PACKAGE_UTIL_LINUX=y
BR2_PACKAGE_UTIL_LINUX_HWCLOCK=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
......@@ -36,3 +36,4 @@ CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_TMPFS_XATTR=y
CONFIG_BLK_DEV_RAM_SIZE=524288
CONFIG_POWER_RESET_GPIO=y
......@@ -11,7 +11,7 @@ RUN apt-get update ; apt-get -y install wget make tar p7zip-full squashfs-tools
e2fsprogs parted dosfstools acpica-tools mtools \
device-tree-compiler xz-utils sudo gcc libssl-dev python2 python3 \
bison flex u-boot-tools git bc fuseext2 e2tools multistrap \
qemu-user-static g++ cpio python unzip rsync
qemu-system-arm g++ cpio python unzip rsync
# build environment
WORKDIR /work
......
......@@ -10,7 +10,7 @@ set -e
###############################################################################
#RELEASE=lx2160a-early-access-bsp0.7 # Supports both rev1 and rev2
#RELEASE=LSDK-19.09 # LSDK-19.09 supports rev1 only
BUILDROOT_VERSION=2019.05.2
BUILDROOT_VERSION=2020.02.1
#UEFI_RELEASE=DEBUG
#BOOT_LOADER=uefi
#DDR_SPEED=3200
......@@ -30,7 +30,7 @@ mkdir -p build images
ROOTDIR=`pwd`
PARALLEL=$(getconf _NPROCESSORS_ONLN) # Amount of parallel jobs for the builds
SPEED=2000_700_${DDR_SPEED}
TOOLS="wget tar git make 7z unsquashfs dd vim mkfs.ext4 sudo parted mkdosfs mcopy dtc iasl mkimage e2cp truncate multistrap qemu-aarch64-static cpio rsync bc bison flex"
TOOLS="wget tar git make 7z unsquashfs dd vim mkfs.ext4 parted mkdosfs mcopy dtc iasl mkimage e2cp truncate qemu-system-aarch64 cpio rsync bc bison flex python unzip"
export PATH=$ROOTDIR/build/toolchain/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:$PATH
export CROSS_COMPILE=aarch64-linux-gnu-
......@@ -63,12 +63,19 @@ for i in $TOOLS; do
if [ "x$TOOL_PATH" == "x" ]; then
echo "Tool $i is not installed"
echo "If running under apt based package management you can run -"
echo "sudo apt install build-essential git dosfstools e2fsprogs parted sudo mtools p7zip device-tree-compiler acpica-tools u-boot-tools e2tools multistrap qemu-user-static libssl-dev cpio rsync bc bison flex"
echo "sudo apt install build-essential git dosfstools e2fsprogs parted sudo mtools p7zip p7zip-full device-tree-compiler acpica-tools u-boot-tools e2tools qemu-system-arm libssl-dev cpio rsync bc bison flex python unzip"
exit -1
fi
done
set -e
# Check if git is configured
GIT_CONF=`git config user.name`
if [ "x$GIT_CONF" == "x" ]; then
echo "git is not configured. please configure git username and email first"
exit -1
fi
if [[ ! -d $ROOTDIR/build/toolchain ]]; then
mkdir -p $ROOTDIR/build/toolchain
cd $ROOTDIR/build/toolchain
......@@ -84,7 +91,7 @@ cd $ROOTDIR
###############################################################################
# source code cloning
###############################################################################
QORIQ_COMPONENTS="u-boot atf rcw restool mc-utils linux"
QORIQ_COMPONENTS="u-boot atf rcw restool mc-utils linux dpdk"
for i in $QORIQ_COMPONENTS; do
if [[ ! -d $ROOTDIR/build/$i ]]; then
echo "Cloing https://source.codeaurora.org/external/qoriq/qoriq-components/$i release $RELEASE"
......@@ -97,7 +104,9 @@ for i in $QORIQ_COMPONENTS; do
git checkout -b LSDK-19.09-V4.19
elif [ "x$i" == "xlinux" ] && [ "x$RELEASE" == "xLSDK-20.04" ]; then
git checkout -b LSDK-20.04-V5.4 refs/tags/LSDK-20.04-V5.4
elif [ "x$i" == "xrestool" && [ "x$RELEASE" == "xLSDK-19.06" ]; then
elif [ "x$i" == "xdpdk" ] && [ "x$RELEASE" == "xLSDK-20.04" ]; then
git checkout -b LSDK-19.09
elif [ "x$i" == "xrestool" ] && [ "x$RELEASE" == "xLSDK-19.06" ]; then
git checkout -b LSDK-19.09-update-291119
else
git checkout -b $RELEASE refs/tags/$RELEASE
......@@ -125,54 +134,57 @@ for i in $QORIQ_COMPONENTS; do
fi
done
if [[ ! -f $ROOTDIR/build/ubuntu-core.ext4 ]]; then
cd $ROOTDIR/build
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
export PACKAGES="systemd-sysv apt locales less wget procps openssh-server ifupdown net-tools isc-dhcp-client"
PACKAGES=$PACKAGES" ntpdate lm-sensors i2c-tools psmisc less sudo htop iproute2 iputils-ping kmod network-manager iptables rng-tools"
# xterm
cat > ubuntu.conf << EOF
[General]
unpack=true
bootstrap=Ubuntu
aptsources=Ubuntu
cleanup=true
allowrecommends=false
addimportant=false
[Ubuntu]
packages=$PACKAGES
source=http://ports.ubuntu.com/
keyring=ubuntu-keyring
suite=focal
components=main universe multiverse
mkdir -p ubuntu
cd ubuntu
if [ ! -d buildroot ]; then
git clone https://github.com/buildroot/buildroot -b $BUILDROOT_VERSION
fi
cd buildroot
cp $ROOTDIR/configs/buildroot/lx2160acex7_defconfig configs/
make lx2160acex7_defconfig
mkdir -p overlay/etc/init.d/
cat > overlay/etc/init.d/S99bootstrap-ubuntu.sh << EOF
#!/bin/sh
case "\$1" in
start)
resize
mkfs.ext4 -F /dev/vda -b 4096
mount /dev/vda /mnt
cd /mnt/
udhcpc -i eth0
wget -c -P /tmp/ http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04-base-arm64.tar.gz
tar zxf /tmp/ubuntu-base-20.04-base-arm64.tar.gz -C /mnt
mount -o bind /proc /mnt/proc/
mount -o bind /sys/ /mnt/sys/
mount -o bind /dev/ /mnt/dev/
mount -o bind /dev/pts /mnt/dev/pts
mount -t tmpfs tmpfs /mnt/var/lib/apt/
mount -t tmpfs tmpfs /mnt/var/cache/apt/
echo "nameserver 8.8.8.8" > /mnt/etc/resolv.conf
echo "localhost" > /mnt/etc/hostname
echo "127.0.0.1 localhost" > /mnt/etc/hosts
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
chroot /mnt apt update
chroot /mnt apt install --no-install-recommends -y systemd-sysv apt locales less wget procps openssh-server ifupdown net-tools isc-dhcp-client ntpdate lm-sensors i2c-tools psmisc less sudo htop iproute2 iputils-ping kmod network-manager iptables rng-tools apt-utils
echo -e "root\nroot" | chroot /mnt passwd
umount /mnt/var/lib/apt/
umount /mnt/var/cache/apt
chroot /mnt apt clean
chroot /mnt apt autoclean
reboot
;;
esac
EOF
sudo multistrap -a arm64 -d ubuntu -f ubuntu.conf
sudo sh -c 'echo localhost > ubuntu/etc/hostname'
sudo sh -c 'sudo cat > ubuntu/etc/hosts << EOF
127.0.0.1 localhost
EOF'
sudo sh -c 'echo "nameserver 8.8.8.8" > ubuntu/etc/resolv.conf'
QEMU=`which qemu-aarch64-static`
sudo cp $QEMU ubuntu/usr/bin/
set +e
## first configure fails
sudo chroot ubuntu/ /usr/bin/qemu-aarch64-static /usr/bin/dpkg --configure -a
set -e
sudo chroot ubuntu/ /usr/bin/qemu-aarch64-static /usr/bin/dpkg --configure -a
echo -e "root\nroot" | sudo chroot ubuntu/ /usr/bin/qemu-aarch64-static /usr/bin/passwd
# Remove qemu after done
sudo rm ubuntu/usr/bin/qemu-aarch64-static
truncate -s 350M ubuntu-core.ext4.tmp
mkfs.ext4 -b 4096 -F ubuntu-core.ext4.tmp
mkdir -p mnt
sudo mount -o loop ubuntu-core.ext4.tmp mnt/
sudo cp -a ubuntu/* mnt/
sudo umount mnt/
rmdir mnt/
mv ubuntu-core.ext4.tmp ubuntu-core.ext4
chmod +x overlay/etc/init.d/S99bootstrap-ubuntu.sh
make
IMG=ubuntu-core.ext4.tmp
truncate -s 350M $IMG
qemu-system-aarch64 -m 1G -M virt -cpu cortex-a57 -nographic -smp 1 -kernel output/images/Image -append "console=ttyAMA0" -netdev user,id=eth0 -device virtio-net-device,netdev=eth0 -initrd output/images/rootfs.cpio.gz -drive file=$IMG,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -no-reboot
mv $IMG $ROOTDIR/build/ubuntu-core.ext4
fi
if [[ ! -d $ROOTDIR/build/qoriq-mc-binary ]]; then
......@@ -182,22 +194,9 @@ if [[ ! -d $ROOTDIR/build/qoriq-mc-binary ]]; then
git checkout -b $RELEASE refs/tags/$RELEASE
fi
if [[ ! -d $ROOTDIR/build/buildroot ]]; then
cd $ROOTDIR/build
git clone https://github.com/buildroot/buildroot -b $BUILDROOT_VERSION
fi
###############################################################################
# building sources
###############################################################################
echo "Building buildroot"
cd $ROOTDIR/build/buildroot
cp $ROOTDIR/configs/buildroot/lx2160acex7_defconfig configs/
make lx2160acex7_defconfig
make source -j${PARALLEL}
make -j${PARALLEL}
echo "Building restool"
cd $ROOTDIR/build/restool
CC=${CROSS_COMPILE}gcc DESTDIR=./install prefix=/usr make install
......@@ -327,6 +326,20 @@ make INSTALL_MOD_PATH=$ROOTDIR/images/tmp/ INSTALL_MOD_STRIP=1 modules_install
cp $ROOTDIR/build/linux/arch/arm64/boot/Image $ROOTDIR/images/tmp/boot
cp $ROOTDIR/build/linux/arch/arm64/boot/dts/freescale/fsl-lx2160a-cex7.dtb $ROOTDIR/images/tmp/boot
echo "Building DPDK"
cd $ROOTDIR/build/dpdk
export CROSS=$CROSS_COMPILE
export RTE_SDK=$ROOTDIR/build/dpdk
export DESTDIR=$ROOTDIR/build/dpdk/install
export RTE_TARGET=arm64-dpaa2-linuxapp-gcc
#make -j32 T=arm64-dpaa2-linuxapp-gcc CONFIG_RTE_KNI_KMOD=n CONFIG_RTE_LIBRTE_PMD_OPENSSL=n clean
make -j32 T=arm64-dpaa2-linuxapp-gcc CONFIG_RTE_KNI_KMOD=n CONFIG_RTE_LIBRTE_PMD_OPENSSL=n install
make -j32 T=arm64-dpaa2-linuxapp-gcc CONFIG_RTE_KNI_KMOD=n CONFIG_RTE_LIBRTE_PMD_OPENSSL=n -C examples/l2fwd install
make -j32 T=arm64-dpaa2-linuxapp-gcc CONFIG_RTE_KNI_KMOD=n CONFIG_RTE_LIBRTE_PMD_OPENSSL=n -C examples/l3fwd install
###############################################################################
# assembling images
###############################################################################
......@@ -357,11 +370,11 @@ echo "Copying kernel modules"
cd $ROOTDIR/images/tmp/
for i in `find lib`; do
if [ -d $i ]; then
e2mkdir -G 0 -O 0 $ROOTDIR/images/tmp/ubuntu-core.ext4:$i
e2mkdir -G 0 -O 0 $ROOTDIR/images/tmp/ubuntu-core.ext4:usr/$i
fi
if [ -f $i ]; then
DIR=`dirname $i`
e2cp -G 0 -O 0 -p $ROOTDIR/images/tmp/$i $ROOTDIR/images/tmp/ubuntu-core.ext4:$DIR
e2cp -G 0 -O 0 -p $ROOTDIR/images/tmp/$i $ROOTDIR/images/tmp/ubuntu-core.ext4:usr/$DIR
fi
done
cd -
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment