Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(init): support installing headers on generic linux distributions #67

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions init/fetch-linux-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ generate_headers()
zcat /proc/config.gz > .config
make ARCH=x86 oldconfig > /dev/null
make ARCH=x86 prepare > /dev/null

# Clean up abundant non-header files to speed-up copying
find ${BUILD_DIR} -regex '.*\.c\|.*\.txt\|.*Makefile\|.*Build\|.*Kconfig' -type f -delete
leodido marked this conversation as resolved.
Show resolved Hide resolved
}

fetch_cos_linux_sources()
Expand All @@ -23,6 +26,16 @@ fetch_cos_linux_sources()
curl -s "https://storage.googleapis.com/cos-tools/${BUILD_ID}/kernel-src.tar.gz" | tar -xzf - -C ${BUILD_DIR}
}

fetch_generic_linux_sources()
{
kernel_version=$(uname -r | tr -d '+')
major_version=$(echo ${kernel_version} | cut -d . -f 1)
echo "Fetching upstream kernel sources for ${kernel_version}."
mkdir -p ${BUILD_DIR}
curl -sL https://www.kernel.org/pub/linux/kernel/v${major_version}.x/linux-$kernel_version.tar.gz | tar --strip-components=1 -xzf - -C ${BUILD_DIR}

}

install_cos_linux_headers()
{
if grep -q CHROMEOS_RELEASE_VERSION ${LSB_FILE};then
Expand All @@ -31,15 +44,29 @@ install_cos_linux_headers()
SOURCES_DIR="${TARGET_DIR}/linux-lakitu-${BUILD_ID}"

if [ ! -e "${SOURCES_DIR}/.installed" ];then
echo "Installing kernel headers for for COS build ${BUILD_ID}"
fetch_cos_linux_sources
generate_headers
mv ${BUILD_DIR} ${TARGET_DIR}
echo "Installing kernel headers for COS build ${BUILD_ID}"
time fetch_cos_linux_sources
time generate_headers
time mv ${BUILD_DIR} ${TARGET_DIR}
touch "${SOURCES_DIR}/.installed"
fi
fi
}

install_generic_linux_headers()
{
BUILD_DIR="/linux-generic-$(uname -r)"
SOURCES_DIR="${TARGET_DIR}/linux-generic-$(uname -r)"

if [ ! -e "${SOURCES_DIR}/.installed" ];then
echo "Installing kernel headers for generic kernel"
time fetch_generic_linux_sources
time generate_headers
time mv ${BUILD_DIR} ${TARGET_DIR}
touch "${SOURCES_DIR}/.installed"
fi
}

install_headers()
{
distro=$(grep ^NAME ${OS_RELEASE_FILE} | cut -d = -f 2)
Expand All @@ -50,7 +77,10 @@ install_headers()
HEADERS_TARGET=${SOURCES_DIR}
;;
*)
echo "WARNING: ${distro} is not a supported distro, cannot install headers, ensure they are installed to /lib/modules"
echo "WARNING: Cannot find distro-specific headers for ${distro}. Fetching generic headers."
install_generic_linux_headers
HEADERS_TARGET=${SOURCES_DIR}
;;
esac
}

Expand Down