Make only single kernel version, offer to update sources (#11)

Source updates may break building older releases (eg kernel#48 source breaks dtb includes for kernel#41)
* Only build latest
* offer to update sources
This commit is contained in:
Owen Carter 2024-11-07 14:17:47 +01:00 committed by GitHub
parent 140add012f
commit ba12d53a61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 124 additions and 84 deletions

View File

@ -46,7 +46,9 @@ Go for a coffee.. ignore the 'git clone' suggestion.
- This will use ~1.6Gb of space.. so be prepared. - This will use ~1.6Gb of space.. so be prepared.
#### Updating sources #### Updating sources
You can re-run the `apt source` command in this folder and it will only download and update as needed, but is still somewhat slow since it verifies the existing downloads when updating. The `make_dtbs.sh` command used below will offer to update the source tree when run, this shoule be done wnenever a new kernel vesion s being built, but does not need to be re-done after that version has been fetched at least once.
You can also manually re-run the `apt source` command in this folder and it will only download and update as needed, but is still somewhat slow since it verifies the existing downloads when updating.
------------------------------------------- -------------------------------------------
# Building the device tree(s) # Building the device tree(s)
@ -61,7 +63,7 @@ Run the build as a normal user (the same user used to fetch the sources above).
* `.dtb` is the binary compiled device tree, this is what we are building here, and is supplied to the kernel at boot time. * `.dtb` is the binary compiled device tree, this is what we are building here, and is supplied to the kernel at boot time.
## device tree sources ## device tree sources
For convenience, the default `sun20i-d1-mangopi-mq-pro.dts` file from the Ubuntu source is also linked here. For convenience, the default `sun20i-d1-mangopi-mq-pro.dts` file from the Ubuntu source is also linked here.
Rather than modifying the default tree you should copy it to a custom name, eg 'my-project.dts'. Or you can copy in examples from the [alt-trees](../alt-trees/) folder. Rather than modifying the default tree you should copy it to a custom name, eg 'my-project.dts'. Or you can copy in examples from the [alt-trees](../alt-trees/) folder.
@ -80,27 +82,35 @@ This will:
```console ```console
$ ./make_dtbs.sh $ ./make_dtbs.sh
Building for kernels: 6.8.0-41-generic Update source tree (may be slow)? [y/N]:
Cleaning existing 6.8.0-41-generic build directory Available kernels:
[1] 6.8.0-41-generic
[2] 6.8.0-44-generic
[3] 6.8.0-47-generic
[4] 6.8.0-48-generic - currently running kernel
Which kernel to build? [4]:
Compiling against headers for 6.8.0-41-generic Building for kernel: 6.8.0-48-generic
Precompiling all includes in build root into 6.8.0-41-generic build directory Cleaning existing 6.8.0-48-generic build directory
sun20i-common-regulators.dtsi -> 6.8.0-41-generic/sun20i-common-regulators.dtsi
sun20i-d1.dtsi -> 6.8.0-41-generic/sun20i-d1.dtsi Compiling against headers for 6.8.0-48-generic
sun20i-d1s.dtsi -> 6.8.0-41-generic/sun20i-d1s.dtsi Precompiling all includes in build root into 6.8.0-48-generic build directory
sunxi-d1-t113.dtsi -> 6.8.0-41-generic/sunxi-d1-t113.dtsi sun20i-common-regulators.dtsi -> 6.8.0-48-generic/sun20i-common-regulators.dtsi
sunxi-d1s-t113.dtsi -> 6.8.0-41-generic/sunxi-d1s-t113.dtsi sun20i-d1.dtsi -> 6.8.0-48-generic/sun20i-d1.dtsi
Precompiling all sources in build root into 6.8.0-41-generic build directory sun20i-d1s.dtsi -> 6.8.0-48-generic/sun20i-d1s.dtsi
my-project.dts -> 6.8.0-41-generic/my-project.dts sunxi-d1-t113.dtsi -> 6.8.0-48-generic/sunxi-d1-t113.dtsi
sun20i-d1-mangopi-mq-pro.dts -> 6.8.0-41-generic/sun20i-d1-mangopi-mq-pro.dts sunxi-d1s-t113.dtsi -> 6.8.0-48-generic/sunxi-d1s-t113.dtsi
Compiling all device tree sources in 6.8.0-41-generic build directory Precompiling all sources in build root into 6.8.0-48-generic build directory
6.8.0-41-generic/my-project.dts -> 6.8.0-41-generic/my-project.dtb my-project.dts -> 6.8.0-48-generic/my-project.dts
6.8.0-41-generic/sun20i-d1-mangopi-mq-pro.dts -> 6.8.0-41-generic/sun20i-d1-mangopi-mq-pro.dtb sun20i-d1-mangopi-mq-pro.dts -> 6.8.0-48-generic/sun20i-d1-mangopi-mq-pro.dts
Compiling all device tree sources in 6.8.0-48-generic build directory
6.8.0-48-generic/my-project.dts -> 6.8.0-48-generic/my-project.dtb
6.8.0-48-generic/sun20i-d1-mangopi-mq-pro.dts -> 6.8.0-48-generic/sun20i-d1-mangopi-mq-pro.dtb
Success. Consider running 'flash_latest.sh' to make permanent (see docs) Success. Consider running 'flash_latest.sh' to make permanent (see docs)
``` ```
The `6.8.0-41-generic` folder now has our device tree: `my-project.dtb` The `6.8.0-48-generic` folder now has our device tree: `my-project.dtb`
- We also generate the default device tree, this can be ignored. - We also generate the default device tree, this can be ignored.
The tool builds for *all* the kernels available on the system, not just the running kernel. The tool builds for *all* the kernels available on the system, not just the running kernel.
@ -169,21 +179,25 @@ Running *flash-kernel* immediately after this will fail since it cannot yet find
Run `flash_latest.sh`, this will ask you to confirm which kernel version you want to copy from. Run `flash_latest.sh`, this will ask you to confirm which kernel version you want to copy from.
- It defaults to the current running kernel. - It defaults to the current running kernel.
- When upgrading this allows you to precompile and install the correct DTB in advance before rebooting into the new kernel. - When upgrading this allows you to precompile and install the correct DTB in advance before rebooting into the new kernel.
- It needs root access via `sudo`, (you will be prompted to enter your password if using sudo with a password)
```console ```console
$ ./flash_latest.sh $ ./flash_latest.sh
Available kernels: Available kernels:
[1] 6.8.0-41-generic - currently running kernel [1] 6.8.0-41-generic
Which kernel to link? [1]: [2] 6.8.0-44-generic
[3] 6.8.0-47-generic
[4] 6.8.0-48-generic - currently running kernel
Which kernel to link? [4]:
Cleaning '/etc/flash-kernel/dtbs/' and copying in device tree binaries from '6.8.0-41-generic/' Cleaning '/etc/flash-kernel/dtbs/' and copying in device tree binaries from '6.8.0-48-generic/'
/home/owen/MQ-Pro-IO/build-trees/6.8.0-41-generic/my-project.dtb --> /etc/flash-kernel/dtbs/my-project.dtb /home/owen/MQ-Pro-IO/build-trees/6.8.0-48-generic/my-project.dtb --> /etc/flash-kernel/dtbs/my-project.dtb
/home/owen/MQ-Pro-IO/build-trees/6.8.0-41-generic/sun20i-d1-mangopi-mq-pro.dtb --> /etc/flash-kernel/dtbs/sun20i-d1-mangopi-mq-pro.dtb /home/owen/MQ-Pro-IO/build-trees/6.8.0-48-generic/sun20i-d1-mangopi-mq-pro.dtb --> /etc/flash-kernel/dtbs/sun20i-d1-mangopi-mq-pro.dtb
Run 'flash-kernel' to apply device tree? [Y]:
Run 'flash-kernel' to apply device tree? [Y]: y
Using DTB: custom/my-project.dtb Using DTB: custom/my-project.dtb
Installing /etc/flash-kernel/dtbs/my-project.dtb into /boot/dtbs/6.8.0-41-generic/custom/my-project.dtb Installing /etc/flash-kernel/dtbs/my-project.dtb into /boot/dtbs/6.8.0-48-generic/custom/my-project.dtb
Taking backup of my-project.dtb. Taking backup of my-project.dtb.
Installing new my-project.dtb. Installing new my-project.dtb.
System running in EFI mode, skipping. System running in EFI mode, skipping.

View File

@ -5,72 +5,98 @@
dtc=/usr/bin/dtc dtc=/usr/bin/dtc
cdir=`pwd` cdir=`pwd`
versions=`dpkg --list | grep linux-image-[0-9].* | cut -d" " -s -f 3 | sed s/^linux-image-// | sort -Vr` versions=`dpkg --list | grep linux-image-[0-9].* | cut -d" " -s -f 3 | sed s/^linux-image-// | sort -V`
current=`/usr/bin/uname -r`
echo -ne "\nBuilding for kernels: " read -p "Update source tree (may be slow)? [y/N]: " choice
echo `echo $versions | sed "s/ /, /g"` if [ ! -z "$choice" ] ; then
echo if [ "$choice" == 'y' ] ; then
cd ../source
apt source linux-riscv
fi
fi
# Disabled auto building of all alt trees, better to do individually echo -e "\nAvailable kernels:"
#alt=../alt-trees option=0
#echo "Linking alt dts sources to build root" declare -a klist
#for dts in `ls -d $alt/*/*.dts`; do for ver in $versions ; do
# echo "$dts" option=$((option+1))
# ln -s "$dts" . klist[$option]=$ver
#done echo -n " [$option] $ver"
if [ $ver == $current ] ; then
# Ensure sure build roots exist and are clean echo " - currently running kernel"
for revision in $versions ; do
if [ -d "$cdir/$revision" ]; then
echo "Cleaning existing $revision build directory"
rm -f $revision/*.dts $revision/*.dtsi $revision/*.dtb
else else
echo "Creating new build directory: $revision" echo
mkdir $revision
fi fi
done done
# Compile for each revision read -p "Which kernel to build? [$option]: " choice
for revision in $versions ; do if [ -z "$choice" ] ; then
cd $cdir choice=$option
echo -e "\nCompiling against headers for $revision" else
echo "Precompiling all includes in build root into $revision build directory" echo
for file in `ls *.dtsi`; do echo "WARNING: building older versions may fail if the source tree includes have changed with more recent kernels"
echo " $file -> $revision/${file##*/}" echo
cpp -I/usr/src/linux-headers-$revision/include/ -nostdinc -undef -x assembler-with-cpp $file > $revision/${file##*/} fi
if [ ! -s "$revision/${file##*/}" ] ; then
rm "$revision/${file##*/}"
echo "**** ERROR ****"
echo "Precompile failed for include: $revision/${file##*/}"
exit 1
fi
done
echo "Precompiling all sources in build root into $revision build directory" revision=${klist[$choice]}
for file in `ls *.dts`; do if [ -z "$revision" ] ; then
echo " $file -> $revision/${file##*/}" echo "No valid kernel selected, exiting."
cpp -I/usr/src/linux-headers-$revision/include/ -nostdinc -undef -x assembler-with-cpp $file > $revision/${file##*/} exit
if [ ! -s "$revision/${file##*/}" ] ; then fi
rm "$revision/${file##*/}"
echo "**** ERROR ****"
echo "Precompile failed for source: $revision/${file##*/}"
exit 1
fi
done
echo "Compiling all device tree sources in $revision build directory" echo -ne "\nBuilding for kernel: $revision"
cd $revision echo
for file in `ls *.dts`; do
out=${file/.dts/.dtb} # Ensure sure build root exists and is clean
echo " $revision/$file -> $revision/$out" if [ -d "$cdir/$revision" ]; then
$dtc $file > $out echo "Cleaning existing $revision build directory"
if [ ! -s "$out" ] ; then rm -f $revision/*.dts $revision/*.dtsi $revision/*.dtb
rm "$out" else
echo "**** ERROR ****" echo "Creating new build directory: $revision"
echo "Compile failed for: $out" mkdir $revision
exit 1 fi
fi
done # Compile
cd $cdir
echo -e "\nCompiling against headers for $revision"
echo "Precompiling all includes in build root into $revision build directory"
for file in `ls *.dtsi`; do
echo " $file -> $revision/${file##*/}"
cpp -I/usr/src/linux-headers-$revision/include/ -nostdinc -undef -x assembler-with-cpp $file > $revision/${file##*/}
if [ ! -s "$revision/${file##*/}" ] ; then
rm "$revision/${file##*/}"
echo "**** ERROR ****"
echo "Precompile failed for include: $revision/${file##*/}"
exit 1
fi
done
echo "Precompiling all sources in build root into $revision build directory"
for file in `ls *.dts`; do
echo " $file -> $revision/${file##*/}"
cpp -I/usr/src/linux-headers-$revision/include/ -nostdinc -undef -x assembler-with-cpp $file > $revision/${file##*/}
if [ ! -s "$revision/${file##*/}" ] ; then
rm "$revision/${file##*/}"
echo "**** ERROR ****"
echo "Precompile failed for source: $revision/${file##*/}"
exit 1
fi
done
echo "Compiling all device tree sources in $revision build directory"
cd $revision
for file in `ls *.dts`; do
out=${file/.dts/.dtb}
echo " $revision/$file -> $revision/$out"
$dtc $file > $out
if [ ! -s "$out" ] ; then
rm "$out"
echo "**** ERROR ****"
echo "Compile failed for: $out"
exit 1
fi
done done
echo -e "\nSuccess. Consider running 'flash_latest.sh' to make permanent (see docs)" echo -e "\nSuccess. Consider running 'flash_latest.sh' to make permanent (see docs)"