Fix x86 build with GEM5. Boot still fails as before.

Use ./run -g instead of ./rungem5.

More convenient GEM5 kernel command line options with -e differentially.
This commit is contained in:
Ciro Santilli
2018-02-22 00:23:57 +00:00
parent f31046d26a
commit 2c4a9476be
5 changed files with 103 additions and 96 deletions

View File

@@ -1209,7 +1209,7 @@ Instead, we have only chip makers, who keep everything that really works closed,
.... ....
./configure && ./build -a arm -g ./configure && ./build -a arm -g
./rungem5 -a arm ./run -a arm -g
.... ....
On another shell: On another shell:
@@ -1218,32 +1218,32 @@ On another shell:
./rungem5-shell ./rungem5-shell
.... ....
===== GEM5 Kernel command line arguments ===== GEM5 kernel command line arguments
E.g., to add `printk.time=y`, run: E.g., to add `printk.time=y`, run:
.... ....
./rungem5 -a arm -- --command-line='earlyprintk=pl011,0x1c090000 console=ttyAMA0 lpj=19988480 norandmaps rw loglevel=8 mem=512MB root=/dev/sda printk.time=y' ./run -a arm -e 'init=/poweroff.out' -g
.... ....
When you use `--command-line=`, it overrides default command lines, which are required to boot properly. Internals: when we give `--command-line=` to GEM5, it overrides default command lines, which are required to boot properly.
So if you pass just `--command-line='printk.time=y'`, it removes the required options, and boot fails. So if you pass just `--command-line='printk.time=y'` for example, it removes the required options, and boot fails.
An easy way to find the other options is to to an initial boot: Our run script hardcodes the require options in the default `--command-line` and appends extra options given by `-e`.
The default options can be found found with:
.... ....
./rungem5 -a arm ./run -a arm -g
.... ....
and then look at the line of the linux kernel that starts with and then look at the line of the linux kernel that starts with:
.... ....
Kernel command line: Kernel command line:
.... ....
We might copy the default `--command-line` into our startup scripts to make things easier at some point, but it would be fun to debug when the defaults change upstream and we don't notice :-(
===== QEMU with GEM5 kernel configuration ===== QEMU with GEM5 kernel configuration
TODO: QEMU did not work with the GEM5 kernel configurations. TODO: QEMU did not work with the GEM5 kernel configurations.
@@ -1271,7 +1271,7 @@ Guest has not initialized the display (yet).
Test it out with: Test it out with:
.... ....
./rungem5 -a arm ./run -a arm -g
.... ....
TODO hangs at: TODO hangs at:
@@ -1302,7 +1302,7 @@ Analogous to QEMU's <<snapshot>>.
Documentation: http://gem5.org/Checkpoints Documentation: http://gem5.org/Checkpoints
.... ....
./rungem5 -a arm ./rung -a arm -g
.... ....
In guest, wait for the boot to end and run: In guest, wait for the boot to end and run:
@@ -1314,7 +1314,7 @@ In guest, wait for the boot to end and run:
To restore the checkpoint, kill the VM and run: To restore the checkpoint, kill the VM and run:
.... ....
./rungem5 -a arm -- -r 1 ./rung -a arm -g -- -r 1
.... ....
Let's create a second checkpoint to see how it works, in guest: Let's create a second checkpoint to see how it works, in guest:
@@ -1327,7 +1327,7 @@ date >f
Kill the VM, and try it out: Kill the VM, and try it out:
.... ....
./rungem5 -a arm -- -r 2 ./run -a arm -g -- -r 2
.... ....
and now in the guest: and now in the guest:
@@ -1343,6 +1343,10 @@ Internals:
- the checkpoints are stored under `m5out/cpt.*` - the checkpoints are stored under `m5out/cpt.*`
- `m5` is a guest utility present inside the GEM5 tree which we cross-compiled and installed into the guest - `m5` is a guest utility present inside the GEM5 tree which we cross-compiled and installed into the guest
===== GEM5 limitations
* networking not working
==== GEM5 x86 ==== GEM5 x86
TODO didn't get it working yet. TODO didn't get it working yet.
@@ -1357,7 +1361,7 @@ Related threads:
.... ....
./configure && ./build -a x86_64-gem5 ./configure && ./build -a x86_64-gem5
./rungem5 -a x86_64-gem5 ./run -a x86_64 -g
.... ....
telnet: telnet:

2
build
View File

@@ -91,7 +91,7 @@ else
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"../kernel_config_fragment\" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"../kernel_config_fragment\"
" >> "${outdir}/.config" " >> "${outdir}/.config"
fi fi
if $x11; then if "$x11"; then
cat ../buildroot_config_fragment_x11 >> "${outdir}/.config" cat ../buildroot_config_fragment_x11 >> "${outdir}/.config"
fi fi
if ! "$gem5"; then if ! "$gem5"; then

View File

@@ -8,8 +8,14 @@ GEM5_VERSION = 1.0
GEM5_SITE = $(BR2_EXTERNAL_GEM5_PATH) GEM5_SITE = $(BR2_EXTERNAL_GEM5_PATH)
GEM5_SITE_METHOD = local GEM5_SITE_METHOD = local
ifeq ($(ARCH),x86_64)
ARCH_MAKE = x86
else
ARCH_MAKE = $(ARCH)
endif
define GEM5_BUILD_CMDS define GEM5_BUILD_CMDS
cd '$(@D)/gem5/util/m5' && $(MAKE) -f 'Makefile.$(ARCH)' CC='$(TARGET_CC)' LD='$(TARGET_LD)' cd '$(@D)/gem5/util/m5' && $(MAKE) -f 'Makefile.$(ARCH_MAKE)' CC='$(TARGET_CC)' LD='$(TARGET_LD)'
endef endef
define GEM5_INSTALL_TARGET_CMDS define GEM5_INSTALL_TARGET_CMDS

119
run
View File

@@ -13,9 +13,10 @@ nographic=false
# Turned on by default since v4.12 # Turned on by default since v4.12
extra_append='nokaslr norandmaps printk.devkmsg=on printk.time=y' extra_append='nokaslr norandmaps printk.devkmsg=on printk.time=y'
extra_flags='' extra_flags=''
gem5=false
initrd=false initrd=false
root='' root=''
while getopts a:de:iknqt:x OPT; do while getopts a:de:giknqt:x OPT; do
case "$OPT" in case "$OPT" in
a) a)
arch="$OPTARG" arch="$OPTARG"
@@ -33,6 +34,9 @@ while getopts a:de:iknqt:x OPT; do
extra_flags="$extra_flags -serial tcp::1234,server,nowait" extra_flags="$extra_flags -serial tcp::1234,server,nowait"
kgdb=true kgdb=true
;; ;;
g)
gem5=true
;;
i) i)
initrd=true initrd=true
;; ;;
@@ -49,9 +53,35 @@ done
shift "$(($OPTIND - 1))" shift "$(($OPTIND - 1))"
extra_flags="$extra_flags $@" extra_flags="$extra_flags $@"
buildroot_out_dir="./buildroot/output.${arch}~" if $gem5; then
images_dir="$buildroot_out_dir/images" outdir="$(pwd)/buildroot/output.${arch}-gem5~"
qemu_common="\ gem5_dir="$(pwd)/gem5/gem5"
if [ "$arch" = x86_64 ]; then
cmd="\
M5_PATH='$(pwd)/gem5/gem5-system' \
'${gem5_dir}/build/X86/gem5.opt' \
'${gem5_dir}/configs/example/fs.py' \
--disk-image='${outdir}/images/rootfs.ext2' \
--kernel='${outdir}/build/linux-custom/vmlinux' \
--root-device=/dev/sda \
"
elif [ "$arch" = arm ]; then
cmd="\
M5_PATH='$(pwd)/gem5/gem5-system' \
'${gem5_dir}/build/ARM/gem5.opt' \
'${gem5_dir}/configs/example/fs.py' \
--command-line='earlyprintk=pl011,0x1c090000 console=ttyAMA0 lpj=19988480 norandmaps rw loglevel=8 mem=512MB root=/dev/sda $extra_append' \
--disk-image='${outdir}/images/rootfs.ext2' \
--dtb-file='${gem5_dir}/system/arm/dt/armv7_gem5_v1_1cpu.dtb' \
--kernel='${outdir}/build/linux-custom/vmlinux' \
--machine-type=VExpress_GEM5_V1 \
"
fi
cmd="$cmd \"\$@\""
else
buildroot_out_dir="./buildroot/output.${arch}~"
images_dir="$buildroot_out_dir/images"
qemu_common="\
$debug_qemu \ $debug_qemu \
$buildroot_out_dir/host/usr/bin/qemu-system-${arch} \ $buildroot_out_dir/host/usr/bin/qemu-system-${arch} \
-m 128M \ -m 128M \
@@ -59,20 +89,20 @@ $buildroot_out_dir/host/usr/bin/qemu-system-${arch} \
-netdev user,hostfwd=tcp::45455-:45455,id=net0 \ -netdev user,hostfwd=tcp::45455-:45455,id=net0 \
-smp 1 \ -smp 1 \
" "
if $initrd; then if $initrd; then
extra_flags="$extra_flags -initrd '${images_dir}/rootfs.cpio'" extra_flags="$extra_flags -initrd '${images_dir}/rootfs.cpio'"
fi fi
# The base QEMU commands are found under board/qemu/*/readme.tx # The base QEMU commands are found under board/qemu/*/readme.tx
case "$arch" in case "$arch" in
x86_64) x86_64)
if $kgdb; then if $kgdb; then
extra_append="$extra_append kgdboc=ttyS0,115200" extra_append="$extra_append kgdboc=ttyS0,115200"
fi fi
if ! $initrd; then if ! $initrd; then
root='root=/dev/vda' root='root=/dev/vda'
extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=virtio,format=qcow2'" extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=virtio,format=qcow2'"
fi fi
cmd="$qemu_common \ cmd="$qemu_common \
-M pc \ -M pc \
-append '$root nopat $extra_append' \ -append '$root nopat $extra_append' \
-device edu \ -device edu \
@@ -81,16 +111,16 @@ case "$arch" in
-kernel ${images_dir}/bzImage \ -kernel ${images_dir}/bzImage \
$extra_flags \ $extra_flags \
" "
;; ;;
arm) arm)
if $kgdb; then if $kgdb; then
extra_append="$extra_append kgdboc=ttyAMA0,115200" extra_append="$extra_append kgdboc=ttyAMA0,115200"
fi fi
if ! $initrd; then if ! $initrd; then
root='root=/dev/sda' root='root=/dev/sda'
extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=scsi,format=qcow2'" extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=scsi,format=qcow2'"
fi fi
cmd="$qemu_common \ cmd="$qemu_common \
-M versatilepb \ -M versatilepb \
-append '$root $extra_append' \ -append '$root $extra_append' \
-device rtl8139,netdev=net0 \ -device rtl8139,netdev=net0 \
@@ -99,12 +129,12 @@ $extra_flags \
-serial stdio \ -serial stdio \
$extra_flags \ $extra_flags \
" "
;; ;;
aarch64) aarch64)
if $kgdb; then if $kgdb; then
extra_append="$extra_append kgdboc=ttyAMA0,115200" extra_append="$extra_append kgdboc=ttyAMA0,115200"
fi fi
cmd="$qemu_common \ cmd="$qemu_common \
-M virt \ -M virt \
-append 'root=/dev/sda $extra_append' \ -append 'root=/dev/sda $extra_append' \
-cpu cortex-a57 \ -cpu cortex-a57 \
@@ -114,13 +144,13 @@ $extra_flags \
-serial stdio \ -serial stdio \
$extra_flags \ $extra_flags \
" "
;; ;;
mips64) mips64)
if ! $initrd; then if ! $initrd; then
root='root=/dev/hda' root='root=/dev/hda'
extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,format=qcow2'" extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,format=qcow2'"
fi fi
cmd="$qemu_common \ cmd="$qemu_common \
-M malta \ -M malta \
-append 'root=/dev/hda $extra_append' \ -append 'root=/dev/hda $extra_append' \
-cpu I6400 \ -cpu I6400 \
@@ -129,7 +159,10 @@ $extra_flags \
-nographic \ -nographic \
$extra_flags \ $extra_flags \
" "
;; ;;
esac esac
fi
echo "$cmd" echo "$cmd"
eval "$cmd" eval "$cmd"

36
rungem5
View File

@@ -1,36 +0,0 @@
#!/usr/bin/env bash
arch=arm
while getopts 'a:' OPT; do
case "$OPT" in
a)
arch="$OPTARG"
;;
esac
done
shift "$(($OPTIND - 1))"
outdir="$(pwd)/buildroot/output.${arch}-gem5~"
gem5_dir="$(pwd)/gem5/gem5"
if [ "$arch" = x86_64 ]; then
cmd="\
M5_PATH='$(pwd)/gem5/gem5-system' \
'${gem5_dir}/build/X86/gem5.opt' \
'${gem5_dir}/configs/example/fs.py' \
--disk-image='${outdir}/images/rootfs.ext2' \
--kernel='${outdir}/build/linux-custom/vmlinux' \
--root-device=/dev/sda \
"
elif [ "$arch" = arm ]; then
cmd="\
M5_PATH='$(pwd)/gem5/gem5-system' \
'${gem5_dir}/build/ARM/gem5.opt' \
'${gem5_dir}/configs/example/fs.py' \
--disk-image='${outdir}/images/rootfs.ext2' \
--dtb-file='${gem5_dir}/system/arm/dt/armv7_gem5_v1_1cpu.dtb' \
--kernel='${outdir}/build/linux-custom/vmlinux' \
--machine-type=VExpress_GEM5_V1 \
--root-device=/dev/sda \
"
fi
cmd="$cmd \"\$@\""
echo "$cmd"
eval "$cmd"