Skip to content

Instantly share code, notes, and snippets.

@qnnnnez
Last active November 16, 2023 06:13
Show Gist options
  • Save qnnnnez/d31f2ac2bec891f3ca457f828446f925 to your computer and use it in GitHub Desktop.
Save qnnnnez/d31f2ac2bec891f3ca457f828446f925 to your computer and use it in GitHub Desktop.
Flash boot partition directly on your OpenStick device. (Tested on UZ801V3)
#!/bin/bash
set -e
set -x
if [ $# -eq 0 ]; then
echo "Usage: $0 kernel-version"
echo "kernel-version is the suffix of vmlinuz and initrd.img in /boot"
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
vmlinuz_path="/boot/vmlinuz-$1"
initrd_path="/boot/initrd.img-$1"
flash_target="/dev/disk/by-partlabel/boot"
work_dir="$(mktemp -d)"
uncompressed_image_path="$work_dir/vmlinuz-uncompressed"
image_gz_path="$work_dir/Image.gz"
kernel_dtb_path="$work_dir/kernel-dtb"
boot_img_path="$work_dir/boot.img"
echo "compressing kernel ..."
if gzip -d <"$vmlinuz_path" >"$uncompressed_image_path"; then
echo "vmlinuz already compressed"
else
readelf -h "$vmlinuz_path" >/dev/null && cp "$vmlinuz_path" "$uncompressed_image_path"
fi
gzip -9 <"$uncompressed_image_path" >"$image_gz_path"
echo
echo "concating kernel and dtb ..."
cat "$image_gz_path" "$dtb_path" >"$kernel_dtb_path"
echo
echo "creating boot.img ..."
mkbootimg \
--base 0x80000000 \
--kernel_offset 0x00080000 \
--ramdisk_offset 0x02000000 \
--tags_offset 0x01e00000 \
--pagesize 2048 \
--second_offset 0x00f00000 \
--ramdisk "$initrd_path" \
--cmdline "earlycon root=PARTUUID=a7ab80e8-e9d1-e8cd-f157-93f69b1d141e console=ttyMSM0,115200 no_framebuffer=true rw"\
--kernel "$kernel_dtb_path" -o "$boot_img_path"
echo
echo "flashing boot.img to boot partition ..."
dd if="$boot_img_path" of="$flash_target" bs=1M status=progress
echo "flashing boot.img to boot partition ..."
dd if="$boot_img_path" of="$flash_target" bs=1M status=progress
echo
echo "cleaning up ..."
rm -rf "$work_dir"
echo
echo "all done"
@qnnnnez
Copy link
Author

qnnnnez commented Nov 2, 2023

Get Kernel Sources

Clone the msm8916-mainline kernel sources:

git clone https://github.com/msm8916-mainline/linux

Compile Kernel

export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
make msm8916_defconfig 
make menuconfig

Compile kernel:

make -j16

Create Debian Package

Create kernel package:

make bindeb-pkg

You can find .deb packages in ..

Prepare the Device

Install kernel packages created previously.

Copy dtb, kernel image and flashing script to device.

Install mkbootimg: apt install mkbootimg

Modify flash-boot-img.sh and change kernel_dtb_path to point to you dtb file.

Generate and Flash boot.img

Choose the version you want to flash:

for x in /boot/vmlinuz-*; do echo "${x#/boot/vmlinuz-}"; done

Run flashing script as root:

sudo bash flash-boot-img.sh {version}

Reference

https://www.kancloud.cn/handsomehacker/openstick/2637565

https://wiki.debian.org/BuildADebianKernelPackage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment