Skip to content

Commit

Permalink
modalai/voxl2: add voxl2-import-core.sh utility script
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <christian@paral.in>
  • Loading branch information
paralin committed Oct 26, 2022
1 parent f3e17d3 commit 9b05507
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 48 deletions.
59 changes: 12 additions & 47 deletions configs/modalai/voxl2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,61 +90,26 @@ drivers provided in the container will then provide all proprietary features:

```sh
# Copy the modalai files to the device.
# Replace "root@voxl2" with your voxl2 ip.
rsync --progress voxl2_platform_1.3.1-0.8.tar.gz root@voxl2:/mnt/persist/
# Replace "root@voxl2" with your voxl2 ip address.
rsync --progress voxl2_platform_1.3.1-0.8.tar.gz root@voxl2:/mnt/persist/voxl2_platform.tar.gz

# Extract the modalai files.
# Run the importer script to import the image.
ssh root@voxl2
cd /mnt/persist
gzip -c -d voxl2_platform_1.3.1-0.8.tar.gz | tar -xf-
cd ./voxl2_platform_1.3.1-0.8
cd ./system-image

# Decompress the sysfs image.
docker run --rm -v $(pwd):/data --workdir /data -it alpine:edge sh -c "apk add android-tools && simg2img qti-ubuntu-robotics-image-m0054-sysfs.ext4 sysfs.ext4"

# Mount the base system image.
mkdir -p mtpt
sudo mount -o loop -t ext4 ./sysfs.ext4 ./mtpt

# Import the base docker image.
cd ./mtpt
sudo tar -c . | docker import - skiffos/skiff-core-voxl2:base

# Unmount.
cd ..
sudo umount ./mtpt

# Use a dockerfile to adjust the image with some fixups.
cd /opt/skiff/coreenv/skiff-core-voxl2
docker build -f Dockerfile.minimize -t skiffos/skiff-core-voxl2:latest .
voxl2-import-core.sh /mnt/persist/voxl2_platform.tar.gz

# The Docker image is imported at skiffos/skiff-core-voxl2:latest
# Force skiff-core to load the new image.
# NOTE: this will delete your existing core container!
docker rm -f core
systemctl restart skiff-core

# The Docker image is called skiffos/skiff-core-voxl2:latest

# Installing the voxl sdk:
su - core
sudo bash
cd /mnt/persist/
cd ./voxl2_platform_1.3.1-0.8/voxl-sdk
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
echo "deb [trusted=yes] file:$(pwd) ./" > /etc/apt/sources.list.d/local.list
apt-get update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/local.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"

# install voxl-suite
apt-get install -y -o Dpkg::Options::="--force-overwrite" voxl-suite

# Done installing.
# You may also want to cleanup some disk space:
docker system prune
```

# License Acknowledgment
# Licenses

The ModelAI packages are provided under various licenses. Skiff does not
directly redistribute any parts of the toolkit, but will download them from the
upstream sources via Buildroot packages as part of the build process. Buildroot
produce a bundle of license files with "make br/legal-info". It is the
responsibility of the end user to follow all applicable licenses' terms.
The ModelAI packages are provided under various licenses. SkiffOS does not
redistribute these packages, but will download them from the upstream sources as
part of the apt install steps in the Dockerfile. It is the responsibility of the
end user to follow all applicable licenses' terms.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# https://github.com/skiffos/SkiffOS/tree/master/configs/modalai/voxl2#skiff-core-importing-vendor-provided-image
FROM skiffos/skiff-core-voxl2:base

# Update and install some packages.
RUN \
chmod 1777 /tmp; \
export DEBIAN_FRONTEND=noninteractive; \
Expand Down Expand Up @@ -44,7 +45,7 @@ RUN touch /etc/ssh/sshd_not_to_be_run && \
systemctl mask NetworkManager wpa_supplicant sshd haveged && \
systemctl mask dhcpd systemd-timesyncd firewalld snapd && \
systemctl mask ssh ab-updater dnsmasq wpa_supplicant && \
systemctl mask sscrpcd
systemctl mask sscrpcd systemd-networkd

WORKDIR /
ENTRYPOINT ["/lib/systemd/systemd"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ define SKIFF_CORE_VOXL2_INSTALL_COREENV
cp -r $(SKIFF_CORE_VOXL2_PKGDIR)/coreenv/* $(TARGET_DIR)/opt/skiff/coreenv/skiff-core-voxl2/
$(INSTALL) -m 0644 $(SKIFF_CORE_VOXL2_PKGDIR)/coreenv-defconfig.yaml \
$(TARGET_DIR)/opt/skiff/coreenv/defconfig.yaml
$(INSTALL) -m 0755 $(SKIFF_CORE_VOXL2_PKGDIR)/voxl2-import-core.sh \
$(TARGET_DIR)/usr/bin/voxl2-import-core.sh
touch $(TARGET_DIR)/opt/skiff/coreenv/.overridden
endef

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/bin/bash
set -eo pipefail

VOXL_PLATFORM_PATH=$1
if [ -z "$VOXL_PLATFORM_PATH" ] && [ -f /mnt/persist/voxl2_platform.tar.gz ]; then
echo "Using voxl2_platform.tar.gz at /mnt/persist/voxl2_platform.tar.gz..."
# If they didn't specify any but this is present, assume they meant to use it.
VOXL_PLATFORM_PATH=/mnt/persist/voxl2_platform.tar.gz
fi

if [ -z "$VOXL_PLATFORM_PATH" ] || [ ! -f $VOXL_PLATFORM_PATH ]; then
echo "usage: voxl2-import-core.sh voxl2_platform.tar.gz"
echo "make sure voxl2_platform.tar.gz is in /mnt/persist"
exit 1
fi

COREENV_PATH=/opt/skiff/coreenv/skiff-core-voxl2/
if [ ! -d ${COREENV_PATH} ]; then
echo "Expected ${COREENV_PATH} but not found."
echo "Please make sure you're running on SkiffOS for Voxl2 with skiff-core-voxl2."
echo "You can try to force rebuild that package in SkiffOS: make br/skiff-core-voxl2-dirclean"
echo " make br/skiff-core-voxl2-dirclean"
echo " make compile"
echo "... then re-flash SkiffOS.\n"
echo "Otherwise open an issue: https://github.com/skiffos/skiffos/issues"
exit 1
fi

WORK_DIR=/mnt/persist/import-core
WORK_MTPT=${WORK_DIR}/mtpt
mkdir -p ${WORK_DIR}
if mountpoint -q ${WORK_MTPT}; then
echo "Unmounting old mtpt root..."
umount --recursive ${WORK_MTPT}
fi
if [ -d ${WORK_DIR}/platform ]; then
echo "Removing old extracted platform files..."
rm -rf ${WORK_DIR}/platform
fi

ALPINE_IMAGE=docker.io/library/alpine:latest
if ! docker inspect ${ALPINE_IMAGE} >/dev/null 2>/dev/null; then
echo "Pulling library/alpine:latest from Docker Hub..."
docker pull ${ALPINE_IMAGE}
else
echo "Docker image library/alpine:latest already exists..."
fi

WORK_CTR=tmp-android-tools
if docker inspect ${WORK_CTR} >/dev/null 2>/dev/null; then
echo "Work container ${WORK_CTR} already exists, using it."
else
echo "Running the container ${WORK_CTR}..."
docker run --rm -d \
--name="${WORK_CTR}" \
-v ${WORK_DIR}:/work \
docker.io/library/alpine:latest \
sleep infinity
fi

STAGE2_CTR=tmp-voxl2-stage2
if docker inspect ${STAGE2_CTR} >/dev/null 2>/dev/null; then
echo "Removing stage2 container..."
docker rm -f ${STAGE2_CTR} || true
fi

function cleanup {
if mountpoint -q ${WORK_MTPT}; then
echo "Unmounting work mountpoint..."
umount ${WORK_MTPT} || true
fi
if docker inspect ${WORK_CTR} >/dev/null 2>/dev/null; then
echo "Removing work container..."
docker rm -f ${WORK_CTR} || true
fi
if docker inspect ${STAGE2_CTR} >/dev/null 2>/dev/null; then
echo "Removing stage2 container..."
docker rm -f ${STAGE2_CTR} || true
fi
}
trap cleanup EXIT

echo "Installing android-tools in the container..."
docker exec -it ${WORK_CTR} apk add android-tools

mkdir -p ${WORK_DIR}/platform
echo "Extracting $(basename ${VOXL_PLATFORM_PATH}) (this will take a minute)..."
tar -C ${WORK_DIR}/platform --strip-components=1 -xf ${VOXL_PLATFORM_PATH}

echo "Extracting sparse rootfs image (this will take a minute)..."
mkdir -p ${WORK_DIR}/extracted
docker exec -it ${WORK_CTR} \
simg2img \
/work/platform/system-image/qti-ubuntu-robotics-image-m0054-sysfs.ext4 \
/work/extracted/sysfs.ext4

EXTRACTED_IMG=${WORK_DIR}/extracted/sysfs.ext4
echo "Extracted sysfs image to ${EXTRACTED_IMG}..."

echo "Mounting sysfs.ext4 to ${WORK_MTPT}"
mkdir -p ${WORK_MTPT}
mount -o loop ${EXTRACTED_IMG} ${WORK_MTPT}

DOCKER_IMG_BASE=skiffos/skiff-core-voxl2:base
echo "Importing the base docker image ${DOCKER_IMG_BASE} (this will take a while)..."
pushd ${WORK_MTPT}
tar -c . | docker import - ${DOCKER_IMG_BASE}
popd

echo "Unmounting work mountpoint..."
umount ${WORK_MTPT} || true

DOCKER_IMG_STAGE2=skiffos/skiff-core-voxl2:stage2
echo "Upgrading ${DOCKER_IMG_BASE} to ${DOCKER_IMG_STAGE2} (this will take a while)..."
pushd ${COREENV_PATH}
docker build -t ${DOCKER_IMG_STAGE2} -f Dockerfile.vendor .
popd

echo "Setting up temporary container to install voxl-sdk debs..."
docker run --rm -d \
--entrypoint "/bin/bash" \
--name="${STAGE2_CTR}" \
-v ${WORK_DIR}:/mnt/work \
${DOCKER_IMG_STAGE2} \
-c "sleep 1000000"

cat > ${WORK_DIR}/platform/voxl-sdk/install-debs.sh <<- EOM
#!/bin/bash
set -eo pipefail
echo "Disabling some audio modules..."
rm /etc/modules-load.d/audio_load.conf || true
echo "Scanning for dpkg packages..."
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
echo "Setting up apt source..."
echo "deb [trusted=yes] file:\$(pwd) ./" > /etc/apt/sources.list.d/local.list
apt-get update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/local.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
# Disable systemctl as we don't have systemd running.
mv /bin/systemctl /bin/systemctl.bak
printf "#!/bin/bash\nexit 0\n" > /bin/systemctl
chmod +x /bin/systemctl
echo "Installing voxl-suite..."
apt-get install -y -o Dpkg::Options::="--force-overwrite" voxl-suite || true
apt-get install -f -y -o Dpkg::Options::="--force-overwrite" || true
apt-get install -y -o Dpkg::Options::="--force-overwrite" voxl-suite
mv /bin/systemctl.bak /bin/systemctl
EOM

echo "Running script to install the voxl-sdk debs (this will take a while)..."
docker exec -w /mnt/work/platform/voxl-sdk -it ${STAGE2_CTR} bash ./install-debs.sh

DOCKER_IMG_FINAL=skiffos/skiff-core-voxl2:latest
echo "Committing work container to ${DOCKER_IMG_FINAL} (this will take a moment)..."
docker commit ${STAGE2_CTR} ${DOCKER_IMG_FINAL}
docker rm -f ${STAGE2_CTR} || true

echo
echo "You will need to restart the core container to apply the changes:"
echo " docker rm -f core"
echo " systemctl restart skiff-core"
echo
echo "Then enter the core container user:"
echo " su - core"
echo

# final cleanup, only if successful.
# otherwise we leave the files in place to review.
echo "Cleaning up temporary files (this will take a moment)..."
if [ -d ${WORK_DIR} ]; then
rm -rf ${WORK_DIR} || true
fi

0 comments on commit 9b05507

Please sign in to comment.