Last active
May 14, 2023 23:13
-
-
Save minlexx/c15330839133522047e36ce1f0d32059 to your computer and use it in GitHub Desktop.
Linux build scripts for postmarketOS (read HOWTO-use.txt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Just copy initramfs from the one generated by pmbootstrap/mkinitfs. | |
# It can be later used in repack-initfs.sh script to update kernel modules | |
# contained inside. | |
cp -v -i ~/.local/var/pmbootstrap/chroot_rootfs_samsung-klte/boot/initramfs \ | |
./initramfs.cpio.gz | |
######################################## | |
# OR for lavender | |
cp -v -i ~/.local/var/pmbootstrap/chroot_rootfs_xiaomi-lavender/boot/initramfs \ | |
./initramfs.cpio.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# verbose output of all commands | |
set -x | |
INITFS_FILE=initramfs-postmarketos-qcom-msm8974 | |
DTB=./arch/arm/boot/dts/qcom-msm8974-samsung-klte.dtb | |
KERNEL=./arch/arm/boot/zImage | |
KERNEL_DTB=${KERNEL}-dtb | |
OUT_BOOTIMG=boot-klte-mainline.img | |
# DEVICEINFO=~/dev/pmaports/device/testing/device-samsung-klte/deviceinfo | |
# source ${DEVICEINFO} | |
# Do not depend on currently selected device in pmbootstrap init, | |
# instead specify values manually: | |
deviceinfo_flash_offset_base="0x00000000" | |
deviceinfo_flash_offset_second="0x00f00000" | |
deviceinfo_flash_offset_kernel="0x00008000" | |
deviceinfo_flash_offset_ramdisk="0x02000000" | |
deviceinfo_flash_offset_tags="0x01e00000" | |
deviceinfo_flash_pagesize="2048" | |
deviceinfo_kernel_cmdline="console=ttyMSM0,115200,n8 msm.vram=192m msm.allow_vram_carveout=1 earlyprintk ignore_loglevel PMOS_NO_OUTPUT_REDIRECT" | |
echo "Appending dtb: cat ${KERNEL} ${DTB} > ${KERNEL_DTB}" | |
cat ${KERNEL} ${DTB} > ${KERNEL_DTB} | |
echo "Creating ${OUT_BOOTIMG}" | |
mkbootimg \ | |
--kernel ${KERNEL_DTB} \ | |
--ramdisk ${INITFS_FILE} \ | |
--base "${deviceinfo_flash_offset_base}" \ | |
--second_offset "${deviceinfo_flash_offset_second}" \ | |
--cmdline "${deviceinfo_kernel_cmdline}" \ | |
--kernel_offset "${deviceinfo_flash_offset_kernel}" \ | |
--ramdisk_offset "${deviceinfo_flash_offset_ramdisk}" \ | |
--tags_offset "${deviceinfo_flash_offset_tags}" \ | |
--pagesize "${deviceinfo_flash_pagesize}" \ | |
-o ${OUT_BOOTIMG} | |
############################################################################### | |
# for arm64 sdm660/lavender | |
#!/bin/bash | |
# verbose output of all commands | |
#set -x | |
INITFS_FILE=initramfs-new.cpio.gz | |
DTB=./arch/arm64/boot/dts/qcom/sdm660-xiaomi-lavender.dtb | |
KERNEL=./arch/arm64/boot/Image.gz | |
KERNEL_DTB=${KERNEL}-dtb | |
OUT_BOOTIMG=boot-lavender-mainline.img | |
echo "Appending dtb: cat ${KERNEL} ${DTB} > ${KERNEL_DTB}" | |
cat ${KERNEL} ${DTB} > ${KERNEL_DTB} | |
deviceinfo_kernel_cmdline_mainline="PMOS_NO_OUTPUT_REDIRECT" | |
deviceinfo_flash_offset_base="0x00000000" | |
deviceinfo_flash_offset_kernel="0x00008000" | |
deviceinfo_flash_offset_ramdisk="0x01000000" | |
deviceinfo_flash_offset_second="0x00f00000" | |
deviceinfo_flash_offset_tags="0x00000100" | |
deviceinfo_flash_pagesize="4096" | |
echo "Creating ${OUT_BOOTIMG} using DTB ${DTB} and initramfs ${INITFS_FILE}" | |
mkbootimg \ | |
--kernel ${KERNEL_DTB} \ | |
--ramdisk ${INITFS_FILE} \ | |
--base "${deviceinfo_flash_offset_base}" \ | |
--second_offset "${deviceinfo_flash_offset_second}" \ | |
--cmdline "${deviceinfo_kernel_cmdline_mainline}" \ | |
--kernel_offset "${deviceinfo_flash_offset_kernel}" \ | |
--ramdisk_offset "${deviceinfo_flash_offset_ramdisk}" \ | |
--tags_offset "${deviceinfo_flash_offset_tags}" \ | |
--pagesize "${deviceinfo_flash_pagesize}" \ | |
-o ${OUT_BOOTIMG} | |
ls --color -l ${OUT_BOOTIMG} | |
file ${OUT_BOOTIMG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First step, perform "pmbootstrap install" locally once for your device, | |
# to get the initramfs file generated by pmbootstrap. | |
# Then copy it into build dir (this is done only once!): | |
$ ./cp-initfs.sh | |
# Then regular build process: | |
$ ./menuconfig.sh or ./make.sh oldconfig | |
$ ./make.sh && ./modules-install.sh && ./create-bootimg.sh && ./upload-modules-root.sh | |
# If you need to update modules included in initramfs, run | |
# ./repack-initfs.sh right before ./create-bootimg.sh, like: | |
$ ./make.sh && ./modules-install.sh && ./repack-initfs.sh && ./create-bootimg.sh && ./upload-modules-root.sh | |
# reboot into download mode (hold buttons combo, or run on device: reboot-mode bootloader) | |
fastboot flash boot ./boot-klte-mainline.img / fastboot flash boot ./boot-lavender-mainline.img | |
fastboot reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add LOCALVERSION= to suppress "+" at the end of kernel version string | |
make -C ../ ARCH=arm CROSS_COMPILE=armv7a-unknown-linux-gnueabihf- O=build-klte -j8 "$@" | |
# for arm64 sdm660/lavender | |
#!/bin/bash | |
make -C ../ \ | |
ARCH=arm64 \ | |
CROSS_COMPILE=aarch64-unknown-linux-gnu- \ | |
O=build-lavender \ | |
LOCALVERSION="-sdm660" \ | |
-j8 \ | |
$* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set -x | |
PREFIX=./INSTALL_PREFIX | |
rm -rf ./${PREFIX} | |
mkdir -p ${PREFIX} | |
./make.sh INSTALL_MOD_PATH=${PREFIX} \ | |
INSTALL_MOD_STRIP=1 \ | |
modules_install | |
echo "Contents of ${PREFIX}/lib/modules:" | |
ls --color -l ${PREFIX}/lib/modules | |
# remove symlinks that are... bad | |
rm -f ${PREFIX}/lib/modules/*/build | |
rm -f ${PREFIX}/lib/modules/*/source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INITFS_FILE=initramfs | |
WORKDIR=INITFS | |
MODULES_DIR=./INSTALL_PREFIX/lib/modules/5.16.0-rc2-sdm660+/ | |
sudo rm -rf ./${WORKDIR} | |
mkdir ./${WORKDIR} | |
cp ${INITFS_FILE}.cpio.gz ./${WORKDIR} | |
# unpack | |
cd ${WORKDIR} | |
gzip -d ${INITFS_FILE}.cpio.gz | |
sudo cpio -i --file=${INITFS_FILE}.cpio | |
# remove source initfs cpio archive | |
rm ${INITFS_FILE}.cpio | |
# remove old modules | |
sudo rm -r ./lib/modules/* | |
# copy new modules | |
cd .. | |
sudo cp -aR ${MODULES_DIR} ./${WORKDIR}/lib/modules/ | |
# pack initramfs back | |
cd ./${WORKDIR} | |
find . | cpio -ov --format=newc | gzip -c -1 > ../${INITFS_FILE}-new.gz | |
cd .. | |
ls -la ./${INITFS_FILE}* | |
echo "Done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PREFIX=INSTALL_PREFIX | |
KERNELVERSION=$(ls ./${PREFIX}/lib/modules) | |
echo "Detected kernel version: $KERNELVERSION" | |
sudo rm -rf _initfs | |
mkdir _initfs | |
cp initramfs.cpio.gz _initfs | |
cd _initfs | |
gzip -d initramfs.cpio.gz | |
sudo cpio -i --file=initramfs.cpio | |
rm -f initramfs | |
cd .. | |
# debug | |
# tree _initfs | |
sudo rm -r _initfs/lib/modules/* | |
sudo mkdir -p _initfs/lib/modules/${KERNELVERSION} | |
# copy the whole modules dir instead, why not | |
sudo cp -R ./$PREFIX/lib/modules/${KERNELVERSION} _initfs/lib/modules | |
# debug | |
# tree _initfs | |
echo "Creating initramfs-new.cpio.gz ..." | |
cd _initfs | |
find . | cpio -o --format=newc | gzip -c -5 > ../initramfs-new.cpio.gz | |
cd .. | |
sudo rm -r _initfs | |
echo "Done:" | |
# ls -la initramfs*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
KERNELVERSION=5.16.0-postmarketos-qcom-msm8974 | |
# To avoid copying the entire set of modules, | |
# copy files only in specified lib/modules subdirectories. | |
# Otherwise iniramfs file can become too large! | |
DL=" | |
kernel/arch/arm/crypto | |
kernel/crypto | |
kernel/crypto/asymmetric_keys | |
kernel/drivers/gpu/drm/panel | |
kernel/drivers/input/misc | |
kernel/drivers/input/rmi4 | |
kernel/fs/f2fs | |
kernel/fs/overlayfs | |
" | |
# unpack initramfs to temp dir "_initfs" | |
sudo rm -rf _initfs | |
mkdir _initfs | |
cp initramfs.gz _initfs | |
cd _initfs | |
gzip -d initramfs.gz | |
sudo cpio -i --file=initramfs | |
rm initramfs | |
cd .. | |
# debug | |
# tree _initfs | |
# Remove existing lib/modules/.. | |
sudo rm -r _initfs/lib/modules/* | |
# Create new lib/modules/... | |
sudo mkdir -p _initfs/lib/modules/${KERNELVERSION} | |
# To avoid copying the entire set of modules, | |
# copy files only in specified subdirectories | |
for D in ${DL}; do | |
echo "Processing: $D ..." | |
sudo mkdir -p _initfs/lib/modules/${KERNELVERSION}/${D} | |
sudo cp INSTALL_PREFIX/lib/modules/${KERNELVERSION}/${D}/* \ | |
_initfs/lib/modules/${KERNELVERSION}/${D}/ | |
done | |
sudo cp INSTALL_PREFIX/lib/modules/${KERNELVERSION}/modules.* \ | |
_initfs/lib/modules/${KERNELVERSION}/ | |
# debug | |
# tree _initfs | |
# Repack initfs again | |
echo "Creating initramfs.gz ..." | |
cd _initfs | |
find . | cpio -ov --format=newc | gzip -c -1 > ../initramfs.gz | |
cd .. | |
ls -la initramfs*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
HOST=pmos | |
if [ -n "$1" ]; then | |
HOST=$1 | |
fi | |
KERNVER=$( ls INSTALL_PREFIX/lib/modules ) | |
echo "Uploading modules for ${KERNVER}..." | |
ssh root@${HOST} "rm -r /lib/modules/${KERNVER}" | |
scp -r INSTALL_PREFIX/lib/modules/* root@${HOST}:/lib/modules/ | |
#echo "Uploading boot.img..." | |
#scp ./boot-lavender-mainline.img root@${HOST}:/boot/boot.img | |
echo "Done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
scp -r INSTALL_PREFIX/lib/modules/* root@172.16.42.1:/lib/modules/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment