From 8b1e1cc575d5113b764e24f493a98e7dd34e4efd Mon Sep 17 00:00:00 2001 From: yafen Date: Sun, 19 Jul 2020 23:04:19 +0800 Subject: [PATCH] reset to old kernel after uninstall raspberrypi-kernel --- README.en.md | 19 ++------- README.md | 23 ++--------- raspberrypi-kernel.spec | 87 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 87 insertions(+), 42 deletions(-) diff --git a/README.en.md b/README.en.md index e06b0fc..34c32bf 100644 --- a/README.en.md +++ b/README.en.md @@ -16,23 +16,12 @@ AArch64 #### Instructions -1. The version of raspberrypi kernel ends with `.raspi`, e.g., `4.19.90-2005.2.0.0036.raspi.aarch64 `. -2. The module files will be installed into `/lib/modules`. The directory name of these module files is the same as the version of raspberrypi kernel, such as `4.19.90-2005.2.0.0036.raspi.aarch64`. -3. The image file will be installed into `/boot`, whose filename is like `vmlinuz-4.19.90-2005.2.0.0036.raspi.aarch64`. Note that the image file is in GZ compression format by default. You can decompress this file, and then rename it to `kernel8.img` as follows. +1. The version of raspberrypi kernel is in the front of `.raspi.aarch64` such as `4.19.90-2005.2.0.0001.raspi.aarch64`. +2. The module files will be installed into `/lib/modules/` such as `/lib/modules/4.19.90-2005.2.0.0001.raspi.aarch64`, where `4.19.90-2005.2.0.0039.raspi` is the version of raspberrypi kernel. +3. The image file will be installed into `/boot/` such as `/boot/vmlinuz-4.19.90-2005.2.0.0001.raspi.aarch64`. Meanwhile, the `/boot/kernel8.img` will be overrided by the image file. +4. The device tree files will be installed into `/boot/` such as `/boot/dtb-4.19.90-2005.2.0.0001.raspi.aarch64`. Meanwhile, the `.dtb` files and `overlays` folder in this `dtb-4.19.90-2005.2.0.0001.raspi.aarch64` directory will replace the corresponding files in `/boot/`. - ``` - cd /boot - cp vmlinuz-4.19.90-2005.2.0.0036.raspi.aarch64 Image.gz - gunzip Image.gz - mv Image kernel8.img - ``` -4. The device tree files will be installed into `/boot`. The directory name of these files looks like `dtb-4.19.90-2005.2.0.0036.raspi.aarch64`. You need to copy the device tree files to `/boot` as follows. - - ``` - cd /boot - cp dtb-4.19.90-2005.2.0.0036.raspi.aarch64/*.dtb ./ - ``` #### Contribution diff --git a/README.md b/README.md index 85e9a04..aad059e 100644 --- a/README.md +++ b/README.md @@ -18,25 +18,10 @@ AArch64 安装 raspberrypi-kernel 后, -1. 内核版本号后缀增加 `.raspi` 标识,形如 `4.19.90-2005.2.0.0036.raspi.aarch64`。 -2. 内核模块安装在 `/lib/modules` 目录下,对应文件夹名称同内核版本号,如 `4.19.90-2005.2.0.0036.raspi.aarch64`。 -3. 内核映像文件在 `/boot` 目录下,映像文件名形如 `vmlinuz-4.19.90-2005.2.0.0036.raspi.aarch64`。注意,该文件默认是采用 GZ 压缩格式的压缩文件,需要解压缩后重命名为 `kernel8.img`。 - - 具体过程: - ``` - cd /boot - cp vmlinuz-4.19.90-2005.2.0.0036.raspi.aarch64 Image.gz - gunzip Image.gz - mv Image kernel8.img - ``` - -4. 设备树文件在 `/boot` 目录下的文件夹下,该文件夹名称形如 `dtb-4.19.90-2005.2.0.0036.raspi.aarch64`,需要将其中的设备树文件拷贝到 `/boot` 目录下。 - - 具体过程: - ``` - cd /boot - cp dtb-4.19.90-2005.2.0.0036.raspi.aarch64/*.dtb ./ - ``` +1. 内核版本号后缀增加 `.raspi` 标识,形如 `4.19.90-2005.2.0.0001.raspi.aarch64`。 +2. 内核模块安装在 `/lib/modules/` 目录下,对应文件夹名称同内核版本号,如 `4.19.90-2005.2.0.0001.raspi.aarch64`。 +3. 内核映像文件在 `/boot/` 目录下,映像文件名形如 `vmlinuz-4.19.90-2005.2.0.0001.raspi.aarch64`。同时,该文件会替换原来的 `/boot/kernel8.img` 文件。 +4. 设备树文件在 `/boot/` 目录下的文件夹下,该文件夹名称形如 `dtb-4.19.90-2005.2.0.0001.raspi.aarch64`。同时,该文件夹下的 `.dtb` 文件和 `overlays` 文件夹会替换 `/boot/` 下对应的文件。 #### 参与贡献 diff --git a/raspberrypi-kernel.spec b/raspberrypi-kernel.spec index 3853f97..282a969 100644 --- a/raspberrypi-kernel.spec +++ b/raspberrypi-kernel.spec @@ -8,7 +8,7 @@ Name: raspberrypi-kernel Version: 4.19.90 -Release: %{hulkrelease}.0036 +Release: %{hulkrelease}.0001 Summary: Linux Kernel License: GPLv2 URL: http://www.kernel.org/ @@ -57,12 +57,8 @@ cd linux-%{KernelVer} perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}.raspi.%{_target_cpu}/" Makefile make ARCH=%{Arch} %{?_smp_mflags} openeuler-raspi_defconfig -make ARCH=%{Arch} dtbs -TargetImage=$(basename $(make -s image_name)) - -make ARCH=%{Arch} $TargetImage %{?_smp_mflags} -make ARCH=%{Arch} modules %{?_smp_mflags} +make ARCH=%{Arch} %{?_smp_mflags} %install cd linux-%{KernelVer} @@ -73,7 +69,9 @@ make ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE rm -rf $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/source $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build mkdir -p $RPM_BUILD_ROOT/boot -install -m 755 $(make -s image_name) $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} +TargetImage=$(make -s image_name) +TargetImage=${TargetImage%.*} +install -m 755 $TargetImage $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} install -m 644 .config $RPM_BUILD_ROOT/boot/config-%{KernelVer} install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-%{KernelVer} @@ -82,6 +80,79 @@ install -m 644 $(find arch/%{Arch}/boot/dts/broadcom/ -name "*.dtb") $RPM_BUILD_ install -m 644 $(find arch/%{Arch}/boot/dts/overlays/ -name "*.dtbo") $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/overlays/ install -m 644 arch/%{Arch}/boot/dts/overlays/README $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/overlays/ +%postun +version_old=0 +if [ "$1" == "0" ]; then + version_old=old +else + version_tmp=0 + name_len=`echo -n %{name}-|wc -c` + for item in `rpm -qa %{name} 2>/dev/null` + do + cur_version=${item:name_len} + cpu_version=${cur_version##*.} + if [ "$cpu_version" == "%{_target_cpu}" ]; then + cur_version=${cur_version%.*} + cur_version=$cur_version.raspi.$cpu_version + if [[ "$cur_version" != "%{KernelVer}" && "$cur_version" > "$version_tmp" ]]; then + version_tmp=$cur_version + fi + fi + done + if [[ "$version_tmp" < "%{KernelVer}" ]]; then + version_old=$version_tmp + fi +fi +if [ "$version_old" != "0" ]; then + if [ -f /boot/vmlinuz-$version_old ] && [ -d /boot/dtb-$version_old ] && ( [ "$version_old" == "old" ] || [ -d /lib/modules/$version_old ] ); then + ls /boot/dtb-$version_old/overlays/*.dtbo > /dev/null 2>&1 + if [ "$?" == "0" ]; then + ls /boot/dtb-$version_old/*.dtb > /dev/null 2>&1 + if [ "$?" == "0" ]; then + rm -rf /boot/*.dtb /boot/overlays /boot/kernel8.img + mkdir /boot/overlays + install -m 755 /boot/vmlinuz-$version_old /boot/kernel8.img + for file in `ls /boot/dtb-$version_old/*.dtb 2>/dev/null` + do + if [ -f $file ]; then + install -m 644 $file /boot/`basename $file` + fi + done + install -m 644 $(find /boot/dtb-$version_old/overlays/ -name "*.dtbo") /boot/overlays/ + install -m 644 /boot/dtb-$version_old/overlays/README /boot/overlays/ + else + echo "warning: files in /boot/dtb-$version_old/*.dtb missing when resetting kernel as $version_old, something may go wrong when starting this device next time." + fi + else + echo "warning: files in /boot/dtb-$version_old/overlays missing when resetting kernel as $version_old, something may go wrong when starting this device next time." + fi + else + echo "warning: files missing when resetting kernel as $version_old, something may go wrong when starting this device next time." + fi +fi + +%posttrans +if [ "$1" == "1" ]; then + if [ ! -f /boot/vmlinuz-old ] && [ -f /boot/kernel8.img ]; then + mkdir /boot/dtb-old + mv /boot/*.dtb /boot/dtb-old + mv /boot/overlays /boot/dtb-old/ + mv /boot/kernel8.img /boot/vmlinuz-old + fi +fi +rm -rf /boot/*.dtb /boot/overlays /boot/kernel8.img +mkdir -p /boot/overlays +install -m 755 /boot/vmlinuz-%{KernelVer} /boot/kernel8.img +for file in `ls /boot/dtb-%{KernelVer}/*.dtb 2>/dev/null` +do + if [ -f $file ]; then + install -m 644 $file /boot/`basename $file` + fi +done +install -m 644 $(find /boot/dtb-%{KernelVer}/overlays/ -name "*.dtbo") /boot/overlays/ +install -m 644 /boot/dtb-%{KernelVer}/overlays/README /boot/overlays/ + + %files %defattr (-, root, root) %doc @@ -89,7 +160,7 @@ install -m 644 arch/%{Arch}/boot/dts/overlays/README $RPM_BUILD_ROOT/boot/dtb-%{ /boot/System.map-* /boot/vmlinuz-* /boot/dtb-* -/lib/modules/%{KernelVer}/ +/lib/modules/%{KernelVer} %changelog * Thu Jun 11 2020 EulixOS Buildteam - 4.19.90-2003.4.0.0036-raspi