Skip to content

Instantly share code, notes, and snippets.

@plesiv
Created December 22, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plesiv/46ff26e1ac616400bfdc to your computer and use it in GitHub Desktop.
Save plesiv/46ff26e1ac616400bfdc to your computer and use it in GitHub Desktop.
Creates uramdisk.tar.gz from ramdisk.tar.gz - AND/OR - Installs Linux Kernel modules on ramdisk
#!/usr/bin/env bash
#
# Installs Kernel modules on ramdisk and/or creates uramdisk from ramdisk.
#
# Tested on Ubuntu.
# Invoking with arguments:
# -m > install kernel modules on ramdisk
# -u > create uramdisk from ramdisk
# -mu / no arguments > do both
# -----------------------------------------------------------------------------
# Configuration
CROSS_COMPILE=/opt/Xilinx/SDK/2014.1/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-
KERNEL_SRC_PATH=~/linux-xlnx-xilinx-v2013.4-trd
IMG_IN=ramdisk.image.gz
ARCH=arm
# -----------------------------------------------------------------------------
# Execution
MNT_DIR=$(mktemp -d /tmp/ramdisk-tmp.XXXXXXXXXX)
# Process command line arguments
ISM=
ISU=
if [ "$#" -eq 0 ]; then
ISM=y
ISU=y
else
while getopts ":mu" opt; do
case $opt in
m) ISM=y ;;
u) ISU=y ;;
\?) echo "Invalid option: -$OPTARG" >&2 ;;
esac
done
fi
# -m
if [ -n "$ISM" ]; then
echo "Installing modules..."
echo -e "\e[1m[root permisions required]\e[0m Mounting ramdisk image"
sudo true
cp "$IMG_IN" "${IMG_IN}_bak" # backup
gunzip "$IMG_IN"
[ ! -e "$MNT_DIR" ] && mkdir -p "$MNT_DIR" # create if doesn't exist
sudo mount -o loop "${IMG_IN%%.gz}" "$MNT_DIR" # mount image
# >> ENTER Kernel directory >>
pushd "${KERNEL_SRC_PATH}"
# install kernel modules on ramdisk image
sudo rm -r "${MNT_DIR}/lib/modules/"
sudo make modules ARCH="${ARCH}" INSTALL_MOD_PATH="${MNT_DIR}" CROSS_COMPILE="${CROSS_COMPILE}"
sudo make modules_install ARCH="${ARCH}" INSTALL_MOD_PATH="${MNT_DIR}" CROSS_COMPILE="${CROSS_COMPILE}"
# << EXIT Kernel directory <<
popd
# remove superfluous links
sudo rm -v "${MNT_DIR}"/lib/modules/*/build
sudo rm -v "${MNT_DIR}"/lib/modules/*/source
# unmount and compress image
sudo umount "$MNT_DIR"
[ -e "$MNT_DIR" ] && sudo rm -rf "$MNT_DIR"
gzip -9 "${IMG_IN%%.gz}"
fi
# -u
if [ -n "$ISU" ]; then
echo "creating uramdisk..."
mkimage -A "${ARCH}" -T ramdisk -C gzip -d "$IMG_IN" "u${IMG_IN}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment