This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
lsts_glued/rules/linux/default.bash

212 lines
5.4 KiB
Bash
Raw Permalink Normal View History

2013-07-13 17:19:22 +01:00
version=\
(
2016-03-07 10:12:03 +00:00
'3.14.63'
2013-07-13 17:19:22 +01:00
)
url=\
(
2014-01-21 00:28:51 +00:00
"https://www.kernel.org/pub/linux/kernel/v3.x/linux-$version.tar.xz"
2013-07-13 17:19:22 +01:00
)
md5=\
(
2016-03-07 10:12:03 +00:00
'6cf8a6b23849f47f511e0e46cfdb6392'
2013-07-13 17:19:22 +01:00
)
maintainer=\
(
'Ricardo Martins <rasm@fe.up.pt>'
)
requires=\
(
2014-06-11 19:33:27 +01:00
'bc/host'
2013-07-13 17:19:22 +01:00
'kmod/host'
2014-01-21 00:37:37 +00:00
'lz4/host'
2013-07-13 17:19:22 +01:00
)
2014-08-19 18:26:49 +01:00
# This variable is updated by find_patches().
patches=()
# Major/Minor version.
linux_mm_version()
{
echo "$version" | cut -f1-2 -d.
}
# Major/Minor/Patch version.
linux_mmp_version()
{
echo "$version" | cut -f1 -d-
}
find_patches()
{
patches=(\
$(ls -1 \
"$pkg_dir/patches/$version/"*.patch \
"$pkg_dir/patches/$(linux_mmp_version)/"*.patch \
"$pkg_dir/patches/$(linux_mm_version)/"*.patch \
"$cfg_dir_system/patches/linux/$version/"*.patch \
"$cfg_dir_system/patches/linux/$(linux_mmp_version)/"*.patch \
"$cfg_dir_system/patches/linux/$(linux_mm_version)/"*.patch \
2> /dev/null | awk '!a[$0]++')
)
}
find_patches
# Get configuration file.
linux_cfg_file()
{
for f in "$version" "$(linux_mmp_version)" "$(linux_mm_version)"; do
f="$cfg_dir_system/cfg/linux-$f.cfg"
if [ -f "$f" ]; then
echo "$f"
return 0
fi
echo "Candidate kernel configuration file '$f' doesn't exist." 1>&2
done
echo "ERROR: failed to find a valid kernel configuration file." 1>&2
return 1
}
2014-08-19 18:26:49 +01:00
post_unpack()
{
n=0; while [ -n "${patches[$n]}" ]; do
patch="${patches[$n]}"
echo "* Applying $patch..."
(ucat "$patch" | patch -p1) || return 1
let n++
done
2014-08-19 18:26:49 +01:00
if [ -d "$cfg_dir_toolchain/firmware" ]; then
tar -C "$cfg_dir_toolchain/firmware" -c -v -f - . | tar -C firmware -x -v -f -
fi
}
refresh()
{
for rule in configure build target_install; do
if [ "$(linux_cfg_file)" -nt "$cfg_dir_builds/linux/$pkg_var/.$rule" ]; then
2014-08-19 18:26:49 +01:00
rm "$cfg_dir_builds/linux/$pkg_var/.$rule"
fi
done
}
configure()
{
$cmd_make \
ARCH=${cfg_target_linux} \
mrproper || return 1
2014-08-19 18:26:49 +01:00
cfg="$(linux_cfg_file)"
[ -n "$cfg" ] || return 1
$cmd_cp "$cfg" .config || return 1
2014-08-19 18:26:49 +01:00
if [ -f "$cfg_dir_system/files/initramfs_init.sh" ]; then
$cmd_mkdir initramfs &&
$cmd_cp "$pkg_dir/files/initramfs.conf" . &&
$cmd_cp "$cfg_dir_system/files/initramfs_init.sh" initramfs/init.sh &&
$cmd_cp "$cfg_dir_rootfs/bin/busybox" initramfs/busybox
fi
2014-08-19 18:26:49 +01:00
yes '' | $cmd_make \
CROSS_COMPILE=${cfg_target_canonical}- \
ARCH=${cfg_target_linux} \
oldconfig
}
build()
{
$cmd_make \
CROSS_COMPILE=$cfg_target_canonical- \
2016-04-06 15:59:33 +01:00
ARCH=$cfg_target_linux || return 1
2014-08-19 18:26:49 +01:00
$cmd_make \
CROSS_COMPILE=$cfg_target_canonical- \
ARCH=$cfg_target_linux \
2016-06-14 19:30:56 +01:00
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2016-04-06 15:59:33 +01:00
modules || return 1
2014-08-19 18:26:49 +01:00
if [ "$(basename $cfg_target_linux_kernel)" = 'uImage' ]; then
$cmd_make \
CROSS_COMPILE=$cfg_target_canonical- \
ARCH=$cfg_target_linux \
2016-06-14 19:30:56 +01:00
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2016-04-06 15:59:33 +01:00
uImage || return 1
2014-08-19 18:26:49 +01:00
fi
# Compressed image.
if [ "$(basename $cfg_target_linux_kernel)" = 'zImage' ]; then
$cmd_make \
CROSS_COMPILE=$cfg_target_canonical- \
ARCH=$cfg_target_linux \
2016-06-14 19:30:56 +01:00
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2016-04-06 15:59:33 +01:00
zImage || return 1
2014-08-19 18:26:49 +01:00
fi
# Device tree blob.
if [ -n "$cfg_target_linux_dtb" ]; then
$cmd_make \
CROSS_COMPILE=$cfg_target_canonical- \
ARCH=$cfg_target_linux \
2016-06-14 19:30:56 +01:00
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2016-04-06 15:59:33 +01:00
dtbs || return 1
2014-08-19 18:26:49 +01:00
fi
if [ -n "${cfg_target_linux_size}" ]; then
dd if="$cfg_target_linux_kernel" of="${cfg_target_linux_kernel}.padded" \
ibs="${cfg_target_linux_size}" conv=sync &&
mv "${cfg_target_linux_kernel}.padded" "${cfg_target_linux_kernel}"
fi
}
target_install()
{
if [ -n "$(file "$cfg_target_linux_kernel" | grep ELF)" ]; then
strip="$(echo $cfg_dir_toolchain/bin/*-strip)"
$strip -s -R .comment "$cfg_target_linux_kernel"
fi
# Kernel image.
if [ -n "$cfg_target_linux_kernel" ]; then
cp -v "$cfg_target_linux_kernel" "$cfg_dir_rootfs/boot/kernel"
else
echo "ERROR: failed to find kernel image at '$cfg_target_linux_kernel'"
return 1
2014-08-19 18:26:49 +01:00
fi
# Device tree blobs.
dts="arch/$cfg_target_linux/boot/dts"
if [ -d "$dts" ]; then
$cmd_mkdir "$cfg_dir_rootfs/boot" &&
cp -v "$dts/"*.dtb "$cfg_dir_rootfs/boot"
fi
# Device tree overlays.
overlays_dir="arch/$cfg_target_linux/boot/dts/overlays"
if [ -d "$overlays_dir" ]; then
$cmd_mkdir "$cfg_dir_rootfs/boot/overlays" || return 1
$cmd_cp "$overlays_dir"/*.dtbo "$cfg_dir_rootfs/boot/overlays" || return 1
fi
2014-08-19 18:26:49 +01:00
$cmd_make \
CROSS_COMPILE="$cfg_target_canonical-" \
ARCH="$cfg_target_linux" \
INSTALL_MOD_PATH="$cfg_dir_rootfs/usr" \
2016-06-14 19:30:56 +01:00
KBUILD_VERBOSE=1 \
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2014-08-19 18:26:49 +01:00
modules_install
$cmd_make \
CROSS_COMPILE="$cfg_target_canonical-" \
ARCH="$cfg_target_linux" \
INSTALL_MOD_PATH="$cfg_dir_rootfs/usr" \
2016-06-14 19:30:56 +01:00
KBUILD_VERBOSE=1 \
DEPMOD="$cfg_dir_toolchain/sbin/depmod" \
2014-08-19 18:26:49 +01:00
firmware_install
}