Initial kernel packaging
This commit is contained in:
parent
2461da6060
commit
d171f30198
|
@ -0,0 +1,19 @@
|
|||
#only include specific /debian files
|
||||
src/debian/*
|
||||
!src/debian/compat
|
||||
!src/debian/changelog
|
||||
!src/debian/control
|
||||
!src/debian/rules
|
||||
|
||||
#generic packaging artifacts
|
||||
debhelper-build-stamp
|
||||
.debhelper
|
||||
*.deb
|
||||
*.dsc
|
||||
*.build
|
||||
*.buildinfo
|
||||
*.changes
|
||||
*.log
|
||||
*.substvars
|
||||
*.diff.gz
|
||||
*.upload
|
|
@ -0,0 +1,19 @@
|
|||
#only include specific /debian files
|
||||
src/debian/*
|
||||
!src/debian/compat
|
||||
!src/debian/changelog
|
||||
!src/debian/control
|
||||
!src/debian/rules
|
||||
|
||||
#generic packaging artifacts
|
||||
debhelper-build-stamp
|
||||
.debhelper
|
||||
*.deb
|
||||
*.dsc
|
||||
*.build
|
||||
*.buildinfo
|
||||
*.changes
|
||||
*.log
|
||||
*.substvars
|
||||
*.diff.gz
|
||||
*.upload
|
|
@ -0,0 +1,35 @@
|
|||
.DEFAULT_GOAL := default
|
||||
#import all shared make vars
|
||||
PRAWNOS_ROOT := $(shell git rev-parse --show-toplevel)
|
||||
include $(PRAWNOS_ROOT)/scripts/BuildScripts/BuildCommon.mk
|
||||
|
||||
#package specific vars
|
||||
VERSION := $(shell cd src/; dpkg-parsechangelog --show-field Version)
|
||||
PACKAGE_NAME := prawnos-linux-$(VERSION)-image-armhf
|
||||
PACKAGE_NAME_DEB := $(PACKAGE_NAME).deb
|
||||
|
||||
default: $(PACKAGE_NAME_DEB)
|
||||
|
||||
$(PACKAGE_NAME_DEB):
|
||||
@echo Building $@
|
||||
#TODO: Have dependancy on kernel buil
|
||||
#copy the vmlinux here and zip it up with a makefile
|
||||
cd src/; debuild -us -uc
|
||||
mkdir -p $PRAWNOS_LOCAL_APT_REPO
|
||||
cp $PACKAGE_NAME $PRAWNOS_LOCAL_APT_REPO
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(PRAWNOS_LOCAL_APT_REPO)/$(PACKAGE_NAME_DEB)
|
||||
rm -rf *.upload
|
||||
rm -rf *.deb
|
||||
rm -rf *.changes
|
||||
rm -rf *.dsc
|
||||
rm -rf *.build
|
||||
rm -rf *.diff.gz
|
||||
rm -rf *.debian.tar.xz
|
||||
rm -rf *.buildinfo
|
||||
|
||||
.PHONY: upload
|
||||
upload:
|
||||
$(PRAWNOS_PACKAGE_SCRIPTS_UPLOAD)
|
|
@ -0,0 +1,143 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This file is part of PrawnOS (https://www.prawnos.com)
|
||||
# Copyright (c) 2020 Hal Emmerich <hal@halemmerich.com>
|
||||
# Copyright (c) 2020 Fil Bergamo <fil@filberg.eu>
|
||||
|
||||
# PrawnOS is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2
|
||||
# as published by the Free Software Foundation.
|
||||
|
||||
# PrawnOS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -----------------------------------------------
|
||||
# STATIC CONFIGURATION
|
||||
# -----------------------------------------------
|
||||
#
|
||||
# eMMC device name
|
||||
emmc_devname=mmcblk2
|
||||
#
|
||||
# Actual kernel image (.kpart)
|
||||
kimg=./vmlinux.kpart
|
||||
#
|
||||
# GPT partition type UUID for "ChromeOS kernel"
|
||||
ptype_kernel="FE3A2A5D-4F32-41A7-B725-ACCC3285A309"
|
||||
#
|
||||
# Kernel partition number
|
||||
pnum_kernel=1
|
||||
# -----------------------------------------------
|
||||
|
||||
# function die():
|
||||
# print an error message and exit with the provided code
|
||||
# $1 = error message
|
||||
# $2 = exit code
|
||||
die()
|
||||
{
|
||||
redtxt='\033[0;31m'
|
||||
printf "$redtxt$1\n"
|
||||
exit $2
|
||||
}
|
||||
|
||||
# function get_partition_type_uuid()
|
||||
# print the UUID of the gpt partition type
|
||||
# for the given partition number on the given device
|
||||
# $1 = device (e.g. /dev/mmcblk2)
|
||||
# $2 = partition number
|
||||
get_partition_type_uuid()
|
||||
{
|
||||
cgpt show -i "$2" -t -n -q "$1" 2>/dev/null
|
||||
}
|
||||
|
||||
# function get_root_partition()
|
||||
# print the actual physical device
|
||||
# currently mounted as "/"
|
||||
get_root_partition()
|
||||
{
|
||||
rootfs=$(findmnt / -n -o SOURCE)
|
||||
|
||||
if echo "$rootfs" | grep -q "/dev/mapper" ;then
|
||||
# root filesystem is on luks volume
|
||||
# let's find the physical device behind it
|
||||
rootfs=$(cryptsetup status "$rootfs" | grep "device: " | cut -d ' ' -f 5)
|
||||
fi
|
||||
echo "$rootfs"
|
||||
}
|
||||
|
||||
|
||||
# ------------- BEGIN SCRIPT EXECUTION --------------------
|
||||
|
||||
set -e
|
||||
|
||||
# Check root or sudo
|
||||
[ ! $(id -u) = 0 ] &&
|
||||
die "Please run this script with sudo, or as root" 1
|
||||
|
||||
rootfs=$(get_root_partition)
|
||||
devname=$(lsblk -no pkname $rootfs | head -n 1)
|
||||
devtype=
|
||||
kpart=
|
||||
|
||||
case "$devname" in
|
||||
$emmc_devname)
|
||||
devtype="Internal eMMC"
|
||||
kpart=/dev/${devname}p$pnum_kernel
|
||||
;;
|
||||
sd*)
|
||||
devtype="USB Stick"
|
||||
kpart=/dev/${devname}$pnum_kernel
|
||||
;;
|
||||
mmcblk[0-9])
|
||||
devtype="External SD card"
|
||||
kpart=/dev/${devname}p$pnum_kernel
|
||||
;;
|
||||
*)
|
||||
die "FAILED to recognize booted device type $devname" 127
|
||||
esac
|
||||
|
||||
# Check that the selected partition is effectively of type "kernel"
|
||||
ptype=$(get_partition_type_uuid /dev/$devname $pnum_kernel)
|
||||
[ ! "$ptype" = "$ptype_kernel" ] &&
|
||||
die "FATAL ERROR: unexpected partitioning scheme found. Partition # $pnum_kernel is NOT the kernel partition!" 255
|
||||
|
||||
# Check that the needed kernel images exist
|
||||
[ ! -e "$kimg" ] &&
|
||||
die "ERROR: cannot find kernel image at $kimg !" 127
|
||||
|
||||
[ ! -e "$blnk" ] &&
|
||||
die "ERROR: cannot find blank image at $blnk !" 127
|
||||
|
||||
|
||||
# Prompt for user's confirmation
|
||||
echo "
|
||||
----------------------------
|
||||
/!\\ !!! CAUTION !!! /!\\
|
||||
----------------------------
|
||||
This will flash a new kernel image onto the running device's kernel partition: $kpart
|
||||
The detected running device is: $devtype.
|
||||
DO NOT shutdown or reboot before completing the process!
|
||||
"
|
||||
|
||||
# put the kernel in the kernel partition
|
||||
#blank the kernel partition first, with 32MiB of zeros
|
||||
kernel_size=65536
|
||||
block_size=512
|
||||
dd if=/dev/zero of="$kpart" conv=notrunc bs=512 count=$kernel_size ||
|
||||
die "FAILED to flash blank kernel on $kpart!" 255
|
||||
|
||||
dd if="$kimg" of="$kpart" conv=notrunc ||
|
||||
die "FAILED to flash kernel image on $kpart!" 255
|
||||
|
||||
echo "
|
||||
The new kernel image has been successfully flashed onto $kpart.
|
||||
Reboot to run the new kernel"
|
||||
|
||||
# TODO: install modules. -----------------------------------
|
||||
# Right now, there's no easy way to do that on the running machine
|
||||
# -----------------------------------------------------------------
|
||||
# make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
|
Reference in New Issue