-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boot-utils: Initial bring up #1
Changes from 8 commits
5247162
a1c229c
6d2104e
e6875f5
ff1d673
b4586cd
51bc49e
101ef4f
e3ff4b5
2780f39
936f954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootfs.cpio |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Usage: ./boot-qemu.sh <options> | ||
|
||
Script description: Boots a Linux kernel in QEMU. | ||
|
||
Required parameters: | ||
-a | --arch | --architecture: | ||
The architecture to boot. Possible values are: | ||
* arm32_v5 | ||
* arm32_v6 | ||
* arm32_v7 | ||
* arm64 | ||
* mips | ||
* mipsel | ||
* ppc32 | ||
* ppc64 | ||
* ppc64le | ||
* x86_64 | ||
|
||
-k | --kbuild-folder: | ||
The kernel build folder, as an absolute path or relative path | ||
from wherever the script is being run. This is wherever the | ||
compiled vmlinux image lives, not the architecture's boot folder. | ||
|
||
Optional parameters: | ||
-d | --debug: | ||
Invokes 'set -x' for debugging the script. | ||
|
||
-h | --help: | ||
Prints this message then exits. | ||
|
||
-i | --interactive | --shell: | ||
By default, the rootfs images in this repo just boots the kernel, | ||
print the version string, then exit. If you would like to actually | ||
interact with the machine, this option passes 'rdinit=/bin/sh' to | ||
the kernel command line so that you are thrown into an interactive | ||
shell. | ||
|
||
-t | --timeout: | ||
By default, the timeout command waits 3 minutes before killing the | ||
QEMU machine. Depending on the power of the host machine, this might | ||
not be long enough for a kernel to boot so this allows that timeout | ||
to be configured. Takes the value passed to timeout (e.g. 30s or 4m). | ||
nathanchance marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Root of the repo | ||
BASE=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd) | ||
|
||
|
||
# Prints an error message in bold red then exits | ||
function die() { | ||
printf "\n\033[01;31m%s\033[0m\n" "${1}" | ||
exit 1 | ||
} | ||
|
||
|
||
# Check that a binary is found | ||
function checkbin() { | ||
command -v "${1}" &>/dev/null || die "${1} could not be found, please install it!" | ||
} | ||
|
||
|
||
# Parse inputs to the script | ||
function parse_parameters() { | ||
while (( ${#} )); do | ||
case ${1} in | ||
-a|--arch|--architecture) | ||
shift | ||
case ${1} in | ||
arm32_v5|arm32_v6|arm32_v7|arm64|mips|mipsel|ppc32|ppc64|ppc64le|x86_64) ARCH=${1} ;; | ||
*) die "Invalid --arch value '${1}'" ;; | ||
tpimh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
esac ;; | ||
|
||
-d|--debug) | ||
set -x ;; | ||
|
||
-h|--help) | ||
echo | ||
cat "${BASE}"/boot-qemu-help.txt | ||
echo | ||
exit 0 ;; | ||
|
||
-i|--interactive|--shell) | ||
INTERACTIVE=true ;; | ||
|
||
-k|--kbuild-folder) | ||
shift && KBUILD_DIR=${1} ;; | ||
|
||
-t|--timeout) | ||
shift && TIMEOUT=${1} ;; | ||
|
||
*) | ||
die "Invalid parameter '${1}'" ;; | ||
esac | ||
shift | ||
done | ||
} | ||
|
||
|
||
# Sanity check parameters and required tools | ||
function sanity_check() { | ||
# Kernel build folder and architecture are required paramters | ||
# We are not interactive by default and the default timeout is 3m | ||
: "${ARCH:?}" "${KBUILD_DIR:?}" "${INTERACTIVE:=false}" "${TIMEOUT:=3m}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is basically a shell builtin that acts like
and such. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you only need it for When we start using sigils, I get nervous that the code starts to look like Perl, and there's good jokes about Perl being unreadable for a reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I prefer to be explicit about the variables that I expect to be defined rather than using Otherwise, I can do the more verbose thing I mentioned if it is more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specially if the symbols are not that common in other languages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, I pushed 936f954, which should be less cryptic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks way better for both user and dev, thanks! |
||
|
||
# KBUILD_DIR could be a relative path; turn it into an absolute one with readlink | ||
KBUILD_DIR=$(readlink -f "${KBUILD_DIR}") | ||
|
||
# Let the user know if the kernel build folder does not exist | ||
[[ -d ${KBUILD_DIR} ]] || die "${KBUILD_DIR} does not exist!" | ||
|
||
# Make sure zstd is install | ||
checkbin zstd | ||
} | ||
|
||
|
||
# Decompress rootfs images | ||
function decomp_rootfs() { | ||
[[ ${ARCH} =~ arm32 ]] && ARCH_RTFS_DIR=arm | ||
nathanchance marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
IMAGES_DIR=${BASE}/images/${ARCH_RTFS_DIR:-${ARCH}} | ||
ROOTFS=${IMAGES_DIR}/rootfs.cpio | ||
|
||
rm -rf "${ROOTFS}" | ||
zstd -d "${ROOTFS}".zst -o "${ROOTFS}" | ||
} | ||
|
||
|
||
# Boot QEMU | ||
function setup_qemu_args() { | ||
if ${INTERACTIVE}; then | ||
RDINIT=" rdinit=/bin/sh" | ||
APPEND_RDINIT=( -append "${RDINIT}" ) | ||
fi | ||
|
||
case ${ARCH} in | ||
tpimh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
arm32_v5) | ||
ARCH=arm | ||
QEMU_ARCH_ARGS=( "${APPEND_RDINIT[@]}" | ||
-dtb "${KBUILD_DIR}"/arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb | ||
-machine palmetto-bmc | ||
-no-reboot ) | ||
QEMU=( qemu-system-arm ) ;; | ||
|
||
arm32_v6) | ||
ARCH=arm | ||
QEMU_ARCH_ARGS=( "${APPEND_RDINIT[@]}" | ||
-dtb "${KBUILD_DIR}"/arch/arm/boot/dts/aspeed-bmc-opp-romulus.dtb | ||
-machine romulus-bmc | ||
-no-reboot ) | ||
QEMU=( qemu-system-arm ) ;; | ||
|
||
arm32_v7) | ||
ARCH=arm | ||
QEMU_ARCH_ARGS=( -append "console=ttyAMA0${RDINIT}" | ||
-machine virt | ||
-no-reboot ) | ||
QEMU=( qemu-system-arm ) ;; | ||
|
||
arm64) | ||
KIMAGE=Image.gz | ||
QEMU_ARCH_ARGS=( -append "console=ttyAMA0${RDINIT}" | ||
-cpu cortex-a57 | ||
-machine virt ) | ||
QEMU=( qemu-system-aarch64 ) ;; | ||
|
||
mips|mipsel) | ||
KIMAGE=vmlinux | ||
QEMU_ARCH_ARGS=( "${APPEND_RDINIT[@]}" | ||
-cpu 24Kf | ||
-machine malta ) | ||
QEMU=( qemu-system-"${ARCH}" ) | ||
ARCH=mips ;; | ||
|
||
ppc32) | ||
ARCH=powerpc | ||
QEMU_ARCH_ARGS=( -append "console=ttyS0${RDINIT}" | ||
-machine bamboo | ||
-no-reboot ) | ||
QEMU_RAM=128m | ||
QEMU=( qemu-system-ppc ) ;; | ||
|
||
ppc64) | ||
ARCH=powerpc | ||
KIMAGE=vmlinux | ||
QEMU_ARCH_ARGS=( "${APPEND_RDINIT[@]}" | ||
-machine pseries | ||
-vga none ) | ||
QEMU_RAM=1G | ||
QEMU=( qemu-system-ppc64 ) ;; | ||
|
||
ppc64le) | ||
ARCH=powerpc | ||
KIMAGE=zImage.epapr | ||
QEMU_ARCH_ARGS=( "${APPEND_RDINIT[@]}" | ||
-device "ipmi-bmc-sim,id=bmc0" | ||
-device "isa-ipmi-bt,bmc=bmc0,irq=10" | ||
-L "${IMAGES_DIR}/" -bios skiboot.lid | ||
-machine powernv ) | ||
QEMU_RAM=2G | ||
QEMU=( qemu-system-ppc64 ) ;; | ||
|
||
x86_64) | ||
KIMAGE=bzImage | ||
QEMU_ARCH_ARGS=( -append "console=ttyS0${RDINIT}" ) | ||
# Use KVM if the processor supports it (first part) and the KVM module is loaded (second part) | ||
[[ $(grep -c -E 'vmx|svm' /proc/cpuinfo) -gt 0 && $(lsmod 2>/dev/null | grep -c kvm) -gt 0 ]] && \ | ||
QEMU_ARCH_ARGS=( "${QEMU_ARCH_ARGS[@]}" -cpu host -d "unimp,guest_errors" -enable-kvm ) | ||
QEMU=( qemu-system-x86_64 ) ;; | ||
esac | ||
checkbin "${QEMU[*]}" | ||
|
||
[[ ${KIMAGE:=zImage} = "vmlinux" ]] || BOOT_DIR=arch/${ARCH}/boot/ | ||
KERNEL=${KBUILD_DIR}/${BOOT_DIR}${KIMAGE} | ||
[[ -f ${KERNEL} ]] || die "${KERNEL} does not exist!" | ||
} | ||
|
||
|
||
# Invoke QEMU | ||
function invoke_qemu() { | ||
${INTERACTIVE} || QEMU=( timeout "${TIMEOUT}" unbuffer "${QEMU[@]}" ) | ||
|
||
set -x | ||
"${QEMU[@]}" \ | ||
"${QEMU_ARCH_ARGS[@]}" \ | ||
-display none \ | ||
-initrd "${ROOTFS}" \ | ||
-kernel "${KERNEL}" \ | ||
-m "${QEMU_RAM:=512m}" \ | ||
-serial mon:stdio | ||
RET=${?} | ||
set +x | ||
|
||
return ${RET} | ||
} | ||
|
||
|
||
parse_parameters "${@}" | ||
sanity_check | ||
decomp_rootfs | ||
setup_qemu_args | ||
invoke_qemu |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d1fa8ee1a3a79d42266db41e470e8d31075de0ebd36bc9b424648c4d100c4105 buildroot-2020.02.tar.gz |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
BASE=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd) | ||
VER=${1} | ||
TMP=$(mktemp -d) | ||
|
||
trap 'rm -rf "${TMP}"' EXIT INT TERM | ||
|
||
# Build skiboot | ||
cd "${TMP}" | ||
curl -LSs https://github.com/open-power/skiboot/archive/v"${VER}".tar.gz | tar xzf - | ||
cd skiboot-"${VER}" | ||
CROSS=${CROSS:-powerpc64le-linux-gnu-} SKIBOOT_VERSION=v${VER} make -j"$(nproc)" | ||
cp -v skiboot.lid "${BASE}" | ||
rm -rf "${PWD}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the folder and not path to kernel image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a couple of the ARM devices, we need the dtb to boot:
https://github.com/nathanchance/boot-utils/blob/101ef4f4258719dd4879cf68ae28af8cc9351595/boot-qemu.sh#L97
https://github.com/nathanchance/boot-utils/blob/101ef4f4258719dd4879cf68ae28af8cc9351595/boot-qemu.sh#L105