kunit: tool: Don't download risc-v opensbi firmware with wget

When running a RISC-V test kernel under QEMU, we need an OpenSBI BIOS
file. In the original QEMU support patchset, kunit_tool would optionally
download this file from GitHub if it didn't exist, using wget.

These days, it can usually be found in the distro's qemu-system-riscv
package, and is located in /usr/share/qemu on all the distros I tried
(Debian, Arch, OpenSUSE). Use this file, and thereby don't do any
downloading in kunit_tool.

In addition, we used to shell out to whatever 'wget' was in the path,
which could have potentially been used to trick the developer into
running another binary. By not using wget at all, we nicely sidestep
this issue.

Cc: Xu Panda <xu.panda@zte.com.cn>
Fixes: 87c9c1631788 ("kunit: tool: add support for QEMU")
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: David Gow <davidgow@google.com>
Tested-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
David Gow 2022-09-23 13:00:39 +08:00 committed by Shuah Khan
parent 185d57797c
commit 3c4fc7bf4c

View File

@ -3,17 +3,13 @@ import os
import os.path import os.path
import sys import sys
GITHUB_OPENSBI_URL = 'https://github.com/qemu/qemu/raw/master/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin' OPENSBI_FILE = 'opensbi-riscv64-generic-fw_dynamic.bin'
OPENSBI_FILE = os.path.basename(GITHUB_OPENSBI_URL) OPENSBI_PATH = '/usr/share/qemu/' + OPENSBI_FILE
if not os.path.isfile(OPENSBI_FILE): if not os.path.isfile(OPENSBI_PATH):
print('\n\nOpenSBI file is not in the current working directory.\n' print('\n\nOpenSBI bios was not found in "' + OPENSBI_PATH + '".\n'
'Would you like me to download it for you from:\n' + GITHUB_OPENSBI_URL + ' ?\n') 'Please ensure that qemu-system-riscv is installed, or edit the path in "qemu_configs/riscv.py"\n')
response = input('yes/[no]: ') sys.exit()
if response.strip() == 'yes':
os.system('wget ' + GITHUB_OPENSBI_URL)
else:
sys.exit()
QEMU_ARCH = QemuArchParams(linux_arch='riscv', QEMU_ARCH = QemuArchParams(linux_arch='riscv',
kconfig=''' kconfig='''
@ -29,4 +25,4 @@ CONFIG_SERIAL_EARLYCON_RISCV_SBI=y''',
extra_qemu_params=[ extra_qemu_params=[
'-machine', 'virt', '-machine', 'virt',
'-cpu', 'rv64', '-cpu', 'rv64',
'-bios', 'opensbi-riscv64-generic-fw_dynamic.bin']) '-bios', OPENSBI_PATH])