Refactor to match linux-rpi

This commit is contained in:
build@apk-groulx 2023-04-22 18:14:59 +00:00
parent bea9886d19
commit 07085b7e29
7 changed files with 193 additions and 7423 deletions

View file

@ -2,205 +2,201 @@
[ "$CBUILD" != "$CHOST" ] && _cross="-$CARCH" || _cross=""
_flavor=rm
pkgname=linux-$_flavor
pkgname=linux-rm
pkgver=5.4.70
_rmver=1.3.3
pkgrel=0
pkgdesc="Linux $_flavor kernel"
url="https://www.kernel.org"
depends="initramfs-generator"
_depends_dev="perl gmp-dev mpc1-dev mpfr-dev elfutils-dev bash flex bison zstd"
makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware-any openssl-dev>3 mawk
diffutils findutils zstd pahole python3 lzop gcc$_cross"
options="!strip"
pkgdesc="Linux kernel with reMarkable patches"
url=https://github.com/reMarkable/linux
depends="initramfs-generator linux-firmware-brcm linux-firmware-cypress"
_depends_dev="perl gmp-dev elfutils-dev bash mpc1-dev mpfr-dev"
makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware mawk
bison flex openssl-dev>3 findutils xz lzop gcc$_cross
"
options="!strip !check"
builddir="$srcdir"/linux-RM1XX_${pkgver}_v$_rmver
source="
https://github.com/reMarkable/linux/archive/refs/tags/RM1XX_${pkgver}_v$_rmver.tar.gz
rm.armv7.config
rm2.armv7.config
enable-automatic-partial-refreshing.patch
enable-sdhc1.patch
config-changes-rm.armv7
config-changes-rm.armhf
config-changes-rm2.armv7
config-changes-rm2.armhf
"
subpackages="$pkgname-dev:_dev:$CBUILD_ARCH $pkgname-doc"
arch="armv7 armhf"
license="GPL-2.0"
_flavors=
for _i in $source; do
case $_i in
*.$CARCH.config)
_f=${_i%."$CARCH".config}
config-*.$CARCH)
_f=${_i%.$CARCH}
_f=${_f#config-changes-}
_flavors="$_flavors $_f"
if [ "linux-$_f" != "$pkgname" ]; then
subpackages="$subpackages linux-$_f::$CBUILD_ARCH linux-$_f-dev:_dev:$CBUILD_ARCH"
fi
[ "linux-$_f" != "$pkgname" ] && subpackages="$subpackages linux-$_f::$CBUILD_ARCH"
subpackages="$subpackages linux-$_f-dev:_dev:$CBUILD_ARCH"
;;
esac
done
builddir="$srcdir"/linux-RM1XX_${pkgver}_v$_rmver
arch="armv7"
license="GPL-2.0-only"
_kernelarch() {
local arch="$1"
case "$arch" in
aarch64*) arch="arm64" ;;
arm*) arch="arm" ;;
mips*) arch="mips" ;;
ppc*) arch="powerpc" ;;
s390*) arch="s390" ;;
case "$CARCH" in
aarch64) _carch="arm64" ;;
arm*) _carch="arm" ;;
esac
# generate config from defconfig and apply local changes.
# config-changes-$flavor.$CARCH holds a list of = delimited
# config command and values used by kernel scripts/config script.
_genconfig() {
local flavor=$1 defconfig=
local subbuilddir="$srcdir"/build-$flavor
local defconfig=
case $flavor in
rm) defconfig=zero-gravitas_defconfig ;;
rm2) defconfig=zero-sugar_defconfig ;;
*) die "Unknown flavor: $flavor" ;;
esac
echo "$arch"
}
_prepareconfig() {
local _flavor="$1"
local _arch="$2"
local _config=$_flavor.$_arch.config
local _builddir="$srcdir"/build-$_flavor.$_arch
mkdir -p "$_builddir"
echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine
cp "$builddir"/arch/$_carch/configs/$defconfig \
"$subbuilddir"/.config
cp "$srcdir"/$_config "$_builddir"/.config
msg "Configuring $_flavor kernel ($_arch)"
make -C "$builddir" \
O="$_builddir" \
ARCH="$(_kernelarch $_arch)" \
olddefconfig
}
listconfigs() {
for i in $source; do
case "$i" in
*.config) echo $i;;
while read line; do
# skip comments
case "$line" in
"#"*) continue;;
esac
done
local option=${line%%=*} str=
local cmd=$(echo $line | cut -d= -f2)
case "$cmd" in
y) cmd="enable";;
n) cmd="disable";;
m) cmd="module";;
'"'*) cmd="set-str"; str="${line#*=}";;
[0-9]*) cmd="set-val"; str="${line#*=}";;
*) die "Command $cmd not accepted" ;;
esac
msg "[$flavor] $cmd: $option $str"
"$builddir"/scripts/config \
--file "$subbuilddir"/.config \
--$cmd "$option" "${str//\"/}"
done < "$srcdir"/config-changes-$flavor.$CARCH
}
prepareconfigs() {
for _config in $(listconfigs); do
local _flavor=${_config%%.*}
local _arch=${_config%.config}
_arch=${_arch#*.}
local _builddir="$srcdir"/build-$_flavor.$_arch
_prepareconfig "$_flavor" "$_arch"
done
# verify if options are set to correct value
_verifyconfig() {
local flavor=$1
local subbuilddir="$srcdir"/build-$flavor
while read line; do
[ ${line:0:1} = "#" ] && continue
local option=${line%%=*} str= invert=
local cmd=$(echo $line | cut -d= -f2)
case "$cmd" in
enable) str="$option=y" ;;
disable) str="$option"; invert="-v" ;;
module) str="$option=m" ;;
set-val) str="$option=${line##*=}" ;;
set-str) str=${line##*=}
str="$option=\"${str//\"/}\"" ;;
esac
grep -q $invert "^$str" "$subbuilddir"/.config || \
die "Config: $option not properly set!"
done < "$srcdir"/config-changes-$flavor.$CARCH
}
# this is supposed to be run before version is bumped so we can compare
# what new kernel config knobs are introduced
prepareupdate() {
clean && fetch && unpack && prepare && deps
prepareconfigs
rm -r "$buildir"
}
updateconfigs() {
if ! [ -d "$builddir" ]; then
deps && fetch && unpack && prepare
fi
for _config in $(listconfigs); do
local _flavor=${_config%%.*}
local _arch=${_config%.config}
_arch=${_arch#*.}
local _builddir="$srcdir"/build-$_flavor.$_arch
prepare() {
default_prepare
local flavor=
for flavor in $_flavors; do
local _builddir="$srcdir"/build-$flavor
mkdir -p "$_builddir"
echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine
local actions="listnewconfig oldconfig"
if ! [ -f "$_builddir"/.config ]; then
cp "$srcdir"/$_config "$_builddir"/.config
actions="olddefconfig"
env | grep ^CONFIG_ >> "$_builddir"/.config || true
fi
make -j1 -C "$buildir" \
echo "-$pkgrel-$flavor" > "$_builddir"/localversion-alpine
_genconfig $flavor
make -C "$builddir" \
O="$_builddir" \
ARCH="$(_kernelarch $_arch)" \
$actions savedefconfig
cp "$_builddir"/defconfig "$startdir"/$_config
ARCH="$_carch" \
olddefconfig
_verifyconfig $flavor
done
}
build() {
unset LDFLAGS
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
for i in $_flavors; do
_prepareconfig "$i" "$CARCH"
done
for i in $_flavors; do
msg "Building $i kernel"
cd "$srcdir"/build-$i.$CARCH
make ARCH="$(_kernelarch $CARCH)" \
CC="${CC:-gcc}" \
AWK="${AWK:-mawk}" \
cd "$srcdir"/build-$i
local _kver=$(make kernelversion)
if [ "$_kver" != "$pkgver" ]; then
error "Version in Makefile ($_kver) does not correspond with pkgver ($pkgver)"
return 1
fi
make ARCH="$_carch" CC="${CC:-gcc}" \
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine"
done
}
_package() {
local _buildflavor="$1" _outdir="$2"
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
local _abi_release="$(make -C "$_builddir" -s kernelrelease)"
cd "$srcdir"/build-$_buildflavor.$CARCH
local _abi_release="$(make -s kernelrelease)"
# modules_install seems to regenerate a defect Modules.symvers on s390x. Work
# around it by backing it up and restore it after modules_install
cp Module.symvers Module.symvers.backup
cd "$srcdir"/build-$_buildflavor
mkdir -p "$_outdir"/boot "$_outdir"/lib/modules
local _install
case "$CARCH" in
arm*|aarch64) _install="zinstall dtbs_install";;
*) _install=install;;
arm*)
_install="zinstall dtbs_install"
;;
aarch64)
_install="install dtbs_install"
;;
*)
_install=install
;;
esac
make -j1 modules_install $_install \
ARCH="$(_kernelarch $CARCH)" \
INSTALL_MOD_PATH="$_outdir" \
INSTALL_MOD_STRIP=1 \
INSTALL_PATH="$_outdir"/boot \
INSTALL_DTBS_PATH="$_outdir/boot/dtbs-$_buildflavor"
cd "$srcdir"/build-$_buildflavor
# modules_install seems to regenerate a defect Modules.symvers. Work
# around it by backing it up and restore it after modules_install
cp Module.symvers Module.symvers.backup
local INSTALL_DTBS_PATH="$_outdir"/boot
make -j1 modules_install $_install \
ARCH="$_carch" \
INSTALL_MOD_PATH="$_outdir" \
INSTALL_PATH="$_outdir"/boot \
INSTALL_DTBS_PATH="$INSTALL_DTBS_PATH"
cp Module.symvers.backup Module.symvers
rm -f "$_outdir"/lib/modules/"$_abi_release"/build \
"$_outdir"/lib/modules/"$_abi_release"/source
rm -f "$_outdir"/lib/modules/$_abi_release/build \
"$_outdir"/lib/modules/$_abi_release/source
rm -rf "$_outdir"/lib/firmware
install -D -m644 include/config/kernel.release \
"$_outdir"/usr/share/kernel/$_buildflavor/kernel.release
if [ "$CARCH" = "aarch64" ]; then
mv -f "$INSTALL_DTBS_PATH"/broadcom/*.dtb \
"$INSTALL_DTBS_PATH"
rmdir "$INSTALL_DTBS_PATH"/broadcom
fi
}
# main flavor installs in $pkgdir
package() {
depends="$depends linux-firmware-any"
_package $_flavor "$pkgdir"
# copy files for linux-$_flavor-doc sub package
mkdir -p "$pkgdir"/usr/share/doc
cp -r "$builddir"/Documentation \
"$pkgdir"/usr/share/doc/linux-doc-"$pkgver"/
# remove files that aren't part of the documentation itself
for nondoc in \
.gitignore conf.py docutils.conf \
dontdiff Kconfig Makefile
do
rm "$pkgdir"/usr/share/doc/linux-doc-"$pkgver"/"$nondoc"
done
# create /usr/share/doc/linux-doc symlink
cd "$pkgdir"/usr/share/doc; ln -s linux-doc-"$pkgver" linux-doc
_package rm "$pkgdir"
}
# subflavors install in $subpkgdir
gravitas() {
_package zero-gravitas "$subpkgdir"
}
sugar() {
_package zero-sugar "$subpkgdir"
rm2() {
depends="initramfs-generator linux-firmware-brcm linux-firmware-cypress"
_package rm2 "$subpkgdir"
}
_dev() {
local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g')
local _builddir="$srcdir"/build-$_flavor.$CARCH
local _builddir="$srcdir"/build-$_flavor
local _abi_release="$(make -C "$_builddir" -s kernelrelease)"
# copy the only the parts that we really need for build 3rd party
# kernel modules and install those as /usr/src/linux-headers,
@ -211,23 +207,22 @@ _dev() {
#
pkgdesc="Headers and script for third party modules for $_flavor kernel"
depends="$_depends_dev"
local dir="$subpkgdir"/usr/src/linux-headers-"$_abi_release"
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
local dir="$subpkgdir"/usr/src/linux-headers-$_abi_release
# first we import config, run prepare to set up for building
# external modules, and create the scripts
mkdir -p "$dir"
cp -a "$_builddir"/.config "$_builddir"/localversion-alpine \
"$dir"/
cp "$_builddir"/.config "$dir"/.config
echo "-$pkgrel-$_flavor" > "$dir"/localversion-alpine
make -j1 -C "$builddir" \
O="$dir" \
ARCH="$(_kernelarch $CARCH)" \
ARCH="$_carch" \
AWK="${AWK:-mawk}" \
prepare modules_prepare scripts
syncconfig prepare modules_prepare scripts
# remove the stuff that points to real sources. we want 3rd party
# modules to believe this is the sources
# modules to believe this is the soruces
rm "$dir"/Makefile "$dir"/source
# copy the needed stuff from real sources
@ -238,27 +233,27 @@ _dev() {
find . -path './include/*' -prune \
-o -path './scripts/*' -prune -o -type f \
\( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
-name '*.sh' -o -name '*.pl' -o -name '*.lds' -o -name 'Platform' \) \
-name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
-print | cpio -pdm "$dir"
cp -a scripts include "$dir"
find $(find arch -name include -type d -print) -type f \
| cpio -pdm "$dir"
find arch -name include -type d -print | while IFS='' read -r folder; do
find "$folder" -type f | cpio -pdm "$dir"
done
install -Dm644 "$srcdir"/build-$_flavor.$CARCH/Module.symvers \
install -Dm644 "$_builddir"/Module.symvers \
"$dir"/Module.symvers
mkdir -p "$subpkgdir"/lib/modules/"$_abi_release"
ln -sf /usr/src/linux-headers-"$_abi_release" \
"$subpkgdir"/lib/modules/"$_abi_release"/build
mkdir -p "$subpkgdir"/lib/modules/$_abi_release
ln -sf /usr/src/linux-headers-$_abi_release \
"$subpkgdir"/lib/modules/$_abi_release/build
}
sha512sums="
80ab274ca3d30935d9913490662f17499c1ceedb438fe171554097d25ffc1cf85ee53f0c1642e94c0b833fdfb17636cd554bf685e4a6f5dac20cf122c1a25447 RM1XX_5.4.70_v1.3.3.tar.gz
35cff2602d57ea037c5441b204db32d66412d692c16179f7520428f802079bfaa871dcbc9aaf5ba4d07f7221b828da14538d8e1547d2391698489b4f562a45a8 rm.armv7.config
df7ba6c0878c714faa91d52c5f6f506e99b5004eea38a66d17a14a94c992cfb7f00df85d30391d97cca9e2a0314ba3f6b0983ae9a2e9aedc95ea14aba57c9578 rm2.armv7.config
0f47278c5bfafb939e46224fbf16f9491e3cc560ac128dcf430a1f6cf9064fb1c5bf5db1a3076c35d30c004aec525a7d6616a647564f197bb29c57701c1db982 enable-automatic-partial-refreshing.patch
6f2036a2f88b0d80ba5e37e3d119aebd2dc33453f5a5d84b319ec50c0c00d8cb93fc4b3f5e10f3d56c1496f3cb297551c405f36c5d864af112398f0792f1549a enable-sdhc1.patch
786e7db529023bfd74e2281436858691e833937650814d8dc31ef0f17af0b3d8fb71af16328685e8a3f52885b9840084f5d457d053cc9f8f597a422dca6eb470 config-changes-rm.armv7
786e7db529023bfd74e2281436858691e833937650814d8dc31ef0f17af0b3d8fb71af16328685e8a3f52885b9840084f5d457d053cc9f8f597a422dca6eb470 config-changes-rm.armhf
786e7db529023bfd74e2281436858691e833937650814d8dc31ef0f17af0b3d8fb71af16328685e8a3f52885b9840084f5d457d053cc9f8f597a422dca6eb470 config-changes-rm2.armv7
786e7db529023bfd74e2281436858691e833937650814d8dc31ef0f17af0b3d8fb71af16328685e8a3f52885b9840084f5d457d053cc9f8f597a422dca6eb470 config-changes-rm2.armhf
"

View file

@ -0,0 +1 @@
config-changes-rm.armv7

View file

@ -0,0 +1,42 @@
# format is config=command
# where command can be one of:
# y,n,m,"<str>,<value>
# from remarkable-microsd project
# see http://www.davisr.me/projects/remarkable-microsd/
CONFIG_RTL_CARDS=y
CONFIG_BATTERY_BQ27XXX=y
CONFIG_BATTERY_BQ27XXX_I2C=y
CONFIG_CRYPTO_AEAD=y
CONFIG_CRYPTO_GF128MUL=y
CONFIG_CRYPTO_NULL=y
CONFIG_CRYPTO_SEQIV=y
CONFIG_CRYPTO_CTR=y
CONFIG_CRYPTO_GHASH=y
CONFIG_FB_MXC_EINK_AUTO_UPDATE_MODE=y
# serial through USB
CONFIG_USB_ACM=y
CONFIG_USB_F_ACM=y
CONFIG_USB_U_SERIAL=y
CONFIG_USB_CDC_COMPOSITE=y
# wifi module doesn't load early enough for lack of initramfs
CONFIG_CFG80211=y
CONFIG_MAC80211=y
CONFIG_BRCMFMAC=y
CONFIG_BRCMUTIL=y
# iwd requires these modules
CONFIG_CRYPTO_AES=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
CONFIG_KEY_DH_OPERATIONS=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_MD5=y
CONFIG_CRYPTO_CBC=y
CONFIG_CRYPTO_SHA256=y
CONFIG_CRYPTO_DES=y
CONFIG_CRYPTO_CMAC=y
CONFIG_CRYPTO_HMAC=y
CONFIG_CRYPTO_SHA512=y
CONFIG_CRYPTO_SHA1=y
# other
LOCALVERSION=""
CONFIG_DEFAULT_HOSTNAME="remarkable"

View file

@ -0,0 +1 @@
config-changes-rm.armv7

View file

@ -0,0 +1 @@
config-changes-rm.armv7

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff