Skip to content

Commit

Permalink
Support armv5tel based pogoplug devices
Browse files Browse the repository at this point in the history
  • Loading branch information
the-maldridge committed Oct 4, 2017
1 parent b4218de commit b4804a8
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 44 deletions.
10 changes: 10 additions & 0 deletions lib.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ set_target_arch_from_platform() {
beaglebone*) XBPS_TARGET_ARCH="armv7l";;
cubieboard2*|cubietruck*) XBPS_TARGET_ARCH="armv7l";;
dockstar*) XBPS_TARGET_ARCH="armv5tel";;
pogoplugv4*) XBPS_TARGET_ARCH="armv5tel" ;;
odroid-u2*) XBPS_TARGET_ARCH="armv7l";;
odroid-c2*) XBPS_TARGET_ARCH="aarch64";;
rpi3*) XBPS_TARGET_ARCH="aarch64";;
Expand All @@ -252,6 +253,15 @@ set_target_arch_from_platform() {
fi
}

set_dracut_args_from_platform() {
# In rare cases it is necessary to set platform specific dracut
# args. This is mostly the case on ARM platforms.
case "$PLATFORM" in
pogoplugv4*) dracut_args="-o 'btrfs drm i18n resume terminfo'" ;;
*) ;;
esac
}

set_cachedir() {
# The package artifacts are cacheable, but they need to be isolated
# from the host cache.
Expand Down
124 changes: 81 additions & 43 deletions mknet.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Options:
-c <cachedir> Use this XBPS cache directory.
-i <lz4|gzip|bzip2|xz> Compression type for the initramfs image (xz if unset).
-o <file> Output file name for the netboot tarball (auto if unset).
-K <kernelpkg> Use <kernelpkg> instead of 'linux' to build the image.
-k <keymap> Console keymap to set (us if unset)
-l <locale> Locale to set (en_US.UTF-8 if unset)
Expand All @@ -76,11 +77,12 @@ _EOF
# SCRIPT EXECUTION STARTS HERE
# ########################################

while getopts "r:c:C:T:i:o:h" opt; do
while getopts "r:c:C:T:K:i:o:k:l:h" opt; do
case $opt in
r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY";;
c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
i) INITRAMFS_COMPRESSION="$OPTARG";;
K) KERNELPKG="$OPTARG";;
o) OUTPUT_FILE="$OPTARG";;
k) KEYMAP="$OPTARG";;
l) LOCALE="$OPTARG";;
Expand Down Expand Up @@ -153,10 +155,20 @@ info_msg "Install kernel and additional required netboot packages"
# The rootfs has no kernel in it, so it needs to have at the very
# least dracut, syslinux, and linux installed. binutils provides
# /usr/bin/strip which lets us shrink down the size of the initrd
# dracut-network provides the in-initrd network stack
# dialog is needed by the install environment
# ${INITRAMFS_COMPRESSION} is the name of the compressor we want to use (lz4 by default)
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy linux dracut syslinux binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz}"
# dracut-network provides the in-initrd network stack dialog is needed
# by the install environment. ${INITRAMFS_COMPRESSION} is the name of
# the compressor we want to use (lz4 by default).
if [ -z "${XBPS_TARGET_ARCH}" ] ; then
# This platform is x86 or compatible, we should use
# syslinux/pxelinux to boot the system.
bootloader_pkg=syslinux
else
# This is likely an arm platform of some kind. In general these
# either have u-boot or a u-boot compatible loader, so we'll use
# that to produce a uImage and a uInitrd
bootloader_pkg=uboot-mkimage
fi
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"

# Dracut needs to know the kernel version that will be using this
Expand All @@ -182,45 +194,71 @@ run_cmd_chroot "$ROOTFS" "env -i /usr/bin/dracut \
[ $? -ne 0 ] && die "Failed to generate the initramfs"

info_msg "Collect netboot components"
# The whole point of this endeavor is to get the files needed for PXE.
# Now that they have been generated, we copy them out of the doomed
# ROOTFS and into the $BOOT_DIR where we're staging the rest of the
# tarball
mv -v "$ROOTFS/boot/initrd" "$BOOT_DIR"
cp -v "$ROOTFS/boot/vmlinuz-$KERNELVERSION" "$BOOT_DIR/vmlinuz"

# The initrd has *very* restrictive permissions by default. To
# prevent some SysAdmin down the road having a very frustrating time
# debugging this, we just fix this here and now.
chmod 0644 "$BOOT_DIR/initrd"

# Now we need to grab the rest of the files that go in the tarball.
# Some of these are always required, some of these are canonical, and
# some of this list is from trial and error. Either way, this is the
# minimum needed to get Void up and booting on metal from the network.
for prog in pxelinux.0 ldlinux.c32 libcom32.c32 vesamenu.c32 libutil.c32 chain.c32 ; do
cp -v "$ROOTFS/usr/share/syslinux/$prog" "$BOOT_DIR"
done
if [ ${bootloader_pkg} == "syslinux" ] ; then
# The whole point of this endeavor is to get the files needed for PXE.
# Now that they have been generated, we copy them out of the doomed
# ROOTFS and into the $BOOT_DIR where we're staging the rest of the
# tarball
mv -v "$ROOTFS/boot/initrd" "$BOOT_DIR"
cp -v "$ROOTFS/boot/vmlinuz-$KERNELVERSION" "$BOOT_DIR/vmlinuz"

# The initrd has *very* restrictive permissions by default. To
# prevent some SysAdmin down the road having a very frustrating time
# debugging this, we just fix this here and now.
chmod 0644 "$BOOT_DIR/initrd"

# Now we need to grab the rest of the files that go in the tarball.
# Some of these are always required, some of these are canonical, and
# some of this list is from trial and error. Either way, this is the
# minimum needed to get Void up and booting on metal from the network.
for prog in pxelinux.0 ldlinux.c32 libcom32.c32 vesamenu.c32 libutil.c32 chain.c32 ; do
cp -v "$ROOTFS/usr/share/syslinux/$prog" "$BOOT_DIR"
done

# Lastly we need the default pxelinux config and the splash image.
# This is user configurable, but if that isn't set then we'll use the
# one from data/splash.png instead
mkdir -p "$PXELINUX_DIR"
cp -f pxelinux.cfg/pxelinux.cfg.in "$PXELINUX_DIR/default"
cp -f "${SPLASH_IMAGE-data/splash.png}" "$BOOT_DIR"

# This sets all the variables in the default config file
info_msg "Configuring pxelinux.0 default boot menu"
sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE-splash.png}")|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP-us}|" \
-e "s|@@ARCH@@|$XBPS_TARGET_ARCH|" \
-e "s|@@LOCALE@@|${LOCALE-en_US.UTF-8}|" \
-e "s|@@BOOT_TITLE@@|${BOOT_TITLE-Void Linux}|" \
-e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
"$PXELINUX_DIR/default"
else
# u-boot has far far fewer components, but u-boot artifacts do
# require some pre-processing

if [ ! -f "$ROOTFS/boot/uImage" ] ; then

# Build the uImage, this is really just the kernel with a wrapper
# to make u-boot happy. It also sets the load and entry
# addresses, though in general these are overriden by the u-boot
# configuration.
run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T kernel -C none -a 0x00000000 -e 0x00000000 -n 'Void Kernel' -d /boot/zImage /boot/uImage"

# Build the uInitrd which is similarly just a copy of the real
# initrd in a format that u-boot is willing to ingest.
run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n 'Void Installer Initrd' -d /boot/initrd /boot/uInitrd"

# Copy out the artifacts that are worth keeping
cp "$ROOTFS/boot/uImage" "$BOOT_DIR"
cp "$ROOTFS/boot/uInitrd" "$BOOT_DIR"
cp -r "$ROOTFS/boot/dtbs" "$BOOT_DIR"
else
# Copy the existing uImage out
cp "$ROOTFS/boot/uImage" "$BOOT_DIR"
fi
fi

# Lastly we need the default pxelinux config and the splash image.
# This is user configurable, but if that isn't set then we'll use the
# one from data/splash.png instead
mkdir -p "$PXELINUX_DIR"
cp -f pxelinux.cfg/pxelinux.cfg.in "$PXELINUX_DIR/default"
cp -f "${SPLASH_IMAGE-data/splash.png}" "$BOOT_DIR"

# This sets all the variables in the default config file
info_msg "Configuring pxelinux.0 default boot menu"
sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE-splash.png}")|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP-us}|" \
-e "s|@@ARCH@@|$XBPS_TARGET_ARCH|" \
-e "s|@@LOCALE@@|${LOCALE-en_US.UTF-8}|" \
-e "s|@@BOOT_TITLE@@|${BOOT_TITLE-Void Linux}|" \
-e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
"$PXELINUX_DIR/default"

# Default output file format
# Compress the artifacts for distribution
OUTPUT_FILE="void-${XBPS_TARGET_ARCH}-NETBOOT-$(date +%Y%m%d).tar.gz"
info_msg "Compressing results to $OUTPUT_FILE"
cd "$BOOT_DIR" || die "Could not enter image dir"
Expand Down
37 changes: 36 additions & 1 deletion mkplatformfs.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Usage: $PROGNAME [options] <platform> <base-tarball>
Supported platforms: i686, x86_64, GCP,
dockstar, bananapi, beaglebone, cubieboard2, cubietruck,
odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64),
usbarmory, ci20
usbarmory, ci20, pogoplugv4
Options
-b <syspkg> Set an alternative base-system package (defaults to base-system)
Expand Down Expand Up @@ -116,6 +116,7 @@ case "$PLATFORM" in
rpi3*) PKGS="$BASEPKG rpi3-base" ;;
rpi2*) PKGS="$BASEPKG rpi-base" ;;
rpi*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
pogo*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
usbarmory*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
ci20*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
i686*) PKGS="$BASEPKG" ;;
Expand Down Expand Up @@ -156,6 +157,40 @@ run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -
# Since this is the only thing we're doing in the chroot, we clean up
# right after.
run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"

# Before final cleanup the ROOTFS needs to be checked to make sure it
# contains an initrd and if its a platform with arch 'arm*' it needs
# to also have a uInitrd. For this to work the system needs to have
# the uboot-mkimage package installed. Base system packages that do
# not provide this must provide the uInitrd pre-prepared if they are
# arm based. x86 images will have this built using native dracut
# using post unpacking steps for platforms that consume the x86
# tarballs.
if [ ! -f "$ROOTFS/boot/uInitrd" ] && [ -z "${XBPS_TARGET_ARCH##*arm*}" ] ; then

# Dracut needs to know the kernel version that will be using this
# initrd so that it can install the kernel drivers in it. Normally
# this check is quite complex, but since this is a clean rootfs and we
# just installed exactly one kernel, this check can get by with a
# really niave command to figure out the kernel version
KERNELVERSION=$(ls "$ROOTFS/usr/lib/modules/")

# Some platforms also have special arguments that need to be set
# for dracut. This allows us to kludge around issues that may
# exist on certain specific platforms we build for.
set_dracut_args_from_platform

# Now that things are setup, we can call dracut and build the initrd.
# This will pretty much step through the normal process to build
# initrd with the exception that the autoinstaller and netmenu are
# force added since no module depends on them.
info_msg "Building initrd for kernel version $KERNELVERSION"
run_cmd_chroot "$ROOTFS" "env -i /usr/bin/dracut $dracut_args /boot/initrd $KERNELVERSION"
[ $? -ne 0 ] && die "Failed to generate the initramfs"

run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n 'Void Linux' -d /boot/initrd /boot/uInitrd"
fi

cleanup_chroot

# The cache isn't that useful since by the time the ROOTFS will be
Expand Down

0 comments on commit b4804a8

Please sign in to comment.