Create a gist now

Instantly share code, notes, and snippets.

@anatol /config.txt
Last active Aug 29, 2015

What would you like to do?
Building ChromeOS kernel without chroot
earlyprintk=ttyS0,115200n8
console=tty1
console=ttyS0,115200n8
loglevel=7
init=/sbin/init
cros_secure
oops=panic
panic=-1
root=PARTUUID=%U/PARTNROFF=1
rootwait
rw
dm_verity.error_behavior=3
dm_verity.max_bios=-1
dm_verity.dev_wait=0
dm="1 vroot none ro 1,0 2506752 verity payload=ROOT_DEV
hashtree=HASH_DEV hashstart=2506752 alg=sha1
root_hexdigest=ab4ff111dcebd3e623dc4c0f86e96926f809553c
salt=2ce301bbe1e7067e2e00cdf707e7ad4028d2e64695829e33499f3667513dff01"
noinitrd cros_debug
vt.global_cursor_default=0
kern_guid=%U
/dts-v1/;
/ {
description = "Chrome OS kernel image with one or more FDT blobs";
#address-cells = <1>;
images {
kernel@1 {
data = /incbin/("linux/arch/arm64/boot/Image");
type = "kernel_noload";
arch = "arm64";
os = "linux";
compression = "none";
load = <0>;
entry = <0>;
};
fdt@1 {
description = "tegra132-ryu-p1.dtb";
data = /incbin/("linux/arch/arm64/boot/dts/tegra132-ryu-p1.dtb");
type = "flat_dt";
arch = "arm64";
compression = "none";
hash@1 {
algo = "sha1";
};
};
};
configurations {
default = "conf@1";
conf@1 {
kernel = "kernel@1";
fdt = "fdt@1";
};
};
};
#!/bin/sh
set -e
ARCH_FLAGS='ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-'
REMOTE_ADDR=${1:-ryu}
ROOT=$(dirname $(readlink -f "$0"))
cd $ROOT
if [ ! -f work/lib/firmware/nvidia/tegra124/xusb.bin ]; then
pushd work
USB_FW_VER=2014.10.10.00.00
wget http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/xhci-firmware-$USB_FW_VER.tbz2 -O xusb.tbz2
tar -jxf xusb.tbz2
popd
fi
mkdir -p work/root/boot
pushd linux
if [ chromeos/config/arm64/chromiumos-arm64.flavour.config -nt .config ]; then
chromeos/scripts/prepareconfig chromiumos-arm64
echo "CONFIG_EXTRA_FIRMWARE=\"nvidia/tegra124/xusb.bin\"" >> .config
echo "CONFIG_EXTRA_FIRMWARE_DIR=\"$ROOT/work/lib/firmware\"" >> .config
yes '' | make $ARCH_FLAGS oldconfig
fi
make $ARCH_FLAGS -j$(nproc)
make $ARCH_FLAGS INSTALL_MOD_PATH=../work/root --silent -j$(nproc) modules_install firmware_install
popd
if [ ! -e work/bootloader.bin ]; then
# arm does not need a bootloader in kernel partition
# creating fake bootloader image
dd if=/dev/zero of=work/bootloader.bin bs=512 count=1 > /dev/null
fi
# Build kernel image (vmlinux + dtb)
# code comes from <chromeos>/chromeos/src/third_party/chromiumos-overlay/eclass/cros-kernel2.eclass
mkimage -D '-I dts -O dtb -p 1024 -i .' -f configs/kernel.its work/kernel.img > /dev/null
# TODO: generate *.its dynamically
# Is it possible to use dtb file from kernel compilation?
# kernel sign keys
# https://chromium.googlesource.com/chromiumos/platform/vboot_reference/+/master/tests/devkeys/kernel.keyblock
# https://chromium.googlesource.com/chromiumos/platform/vboot_reference/+/master/tests/devkeys/kernel_data_key.vbprivk
# sign the kernel. output is kernel.img -> kernel.bin
futility vbutil_kernel --pack work/kernel.bin \
--keyblock configs/kernel.keyblock \
--signprivate configs/kernel_data_key.vbprivk \
--version 1 \
--config configs/config.txt \
--bootloader work/bootloader.bin \
--vmlinuz work/kernel.img \
--arch aarch64
cp -u linux/System.map work/root/boot/
# KERN-B partition 4
# ROOT-B partition 5
device=/dev/mmcblk0
kern_part_idx=4
root_part_idx=5
new_kernel_part=${device}p${kern_part_idx}
new_root_part=${device}p${root_part_idx}
function remote_sh() {
REMOTE_OUT=$(ssh $REMOTE_ADDR "$@")
return ${PIPESTATUS[0]}
}
# args: from, to
function remote_copy {
REMOTE_OUT=$(scp $1 $REMOTE_ADDR:$2)
return ${PIPESTATUS[0]}
}
# args remote root
function remote_sync_root {
srcs=(boot lib/modules lib/firmware)
for src in "${srcs[@]}"; do
rsync -carq --safe-links --delete work/root/$src/ $REMOTE_ADDR:$1/$src/
done
}
# copy and flash kernel
remote_copy work/kernel.bin /tmp/kernel.bin
remote_sh dd of=$new_kernel_part if=/tmp/kernel.bin bs=4K
# check if ROOT-B already mounted
remote_sh rootdev
current_root=$REMOTE_OUT
if [ "$current_root" == "$new_root_part" ]; then
remote_sh mount -o remount,rw /
remote_sync_root '/'
else
remote_new_root='/tmp/new_root'
remote_sh mkdir -p $remote_new_root
remote_sh mount $new_root_part $remote_new_root
remote_sync_root $remote_new_root
remote_sh umount $new_root_part
fi
remote_sh cgpt add -i $kern_part_idx -S 0 -T 5 -P 15 $device
remote_sh uname -r -v
echo ' = Old kernel: ' $REMOTE_OUT
remote_sh sync
remote_sh reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment