script: Improve the QEMU scripts to Python
cover script: Improve the QEMU scripts to Python
This series updates the two QEMU scripts available in U-Boot:
- Converts build-qemu to Python
- Converts build-efi to avoid sudo (unless SCT is used)
- Introduces a proper settings file shared between both scripts
It also includes a few documentation updates.
The next step is to get these scripts running in CI.
Simon Glass (6):
test: Update fs_helper to support passing in the image
scripts: Rename build-efi.py to drop the file extension
scripts: Convert the build-efi script to avoid sudo
scripts: Create a common settings file for QEMU scripts
u_boot_pylib: Support a fatal level in tout
scripts: Convert the build-qemu script to Python
MAINTAINERS | 5 +-
doc/board/emulation/script.rst | 78 +++++-
doc/develop/uefi/u-boot_on_efi.rst | 7 +-
scripts/{build-efi.py => build-efi} | 159 ++---------
scripts/build-qemu | 414 ++++++++++++++++++++++++++++
scripts/build-qemu.sh | 211 --------------
scripts/build_helper.py | 126 +++++++++
test/py/tests/fs_helper.py | 18 +-
tools/binman/control.py | 6 +-
tools/u_boot_pylib/tout.py | 22 +-
10 files changed, 660 insertions(+), 386 deletions(-)
rename scripts/{build-efi.py => build-efi} (52%)
create mode 100755 scripts/build-qemu
delete mode 100755 scripts/build-qemu.sh
create mode 100644 scripts/build_helper.pySignature · 4 lines
2.43.0 base-commit: c5a631df96de7421d10ee03dceed1b79db213026 branch: script
PATCH 1/6 test: Update fs_helper to support passing in the image
This function is useful for other scripts, so add a parameter to specify the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in many cases we only want to see warnings / errors.
---
test/py/tests/fs_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
test/py/tests/fs_helper.py +13 -5
@@ -8,8 +8,10 @@ import re import os from subprocess import call, check_call, check_output, CalledProcessError +from subprocess import DEVNULL -def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): +def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000, + fs_img=None, quiet=False): """Create a file system volume Args:
@@ -19,12 +21,15 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): prefix (str): Prefix string of volume's file name src_dir (str): Root directory to use, or None for none size_gran (int): Size granularity of file system image in bytes + fs_img (str or None): Filename for image, or None to invent one + quiet (bool): Suppress non-error output Raises: CalledProcessError: if any error occurs when creating the filesystem """ - fs_img = f'{prefix}.{fs_type}.img' - fs_img = os.path.join(config.persistent_data_dir, fs_img) + if not fs_img: + leaf = f'{prefix}.{fs_type}.img' + fs_img = os.path.join(config.persistent_data_dir, leaf) if fs_type == 'fat12': mkfs_opt = '-F 12'
@@ -58,14 +63,17 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): check_call(f'rm -f {fs_img}', shell=True) check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}', shell=True) - check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True) + check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True, + stdout=DEVNULL if quiet else None) if fs_type == 'ext4': sb_content = check_output(f'tune2fs -l {fs_img}', shell=True).decode() if 'metadata_csum' in sb_content: check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) elif fs_lnxtype == 'vfat' and src_dir: - check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True) + flags = f"-smpQ{'' if quiet else 'v'}" + check_call(f'mcopy -i {fs_img} {flags} {src_dir}/* ::/', + shell=True) elif fs_lnxtype == 'exfat' and src_dir: check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True) return fs_img
Signature · 1 line
2.43.0
Simon Glass
AppliedRe: [PATCH 1/6] test: Update fs_helper to support passing in the image
This function is useful for other scripts, so add a parameter to specify the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in many cases we only want to see warnings / errors.
---
test/py/tests/fs_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Applied to sjg/master, thanks!
Re: [PATCH 1/6] test: Update fs_helper to support passing in the image
Quoted 6 lines · Simon Glass
This function is useful for other scripts, so add a parameter to specify the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in many cases we only want to see warnings / errors.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
test/py/tests/fs_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)Applied to sjg/master, thanks!
You have been repeatedly asked to not send messages about your personal tree to the list. Please stop sending these messages (and I hope you didn't change the patchwork status too, again).
Signature · 1 line
Tom
Re: [PATCH 1/6] test: Update fs_helper to support passing in the image
Hi Tom,
Quoted 11 lines · Tom Rini
Quoted 9 lines · Simon Glass
This function is useful for other scripts, so add a parameter to specify the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in many cases we only want to see warnings / errors.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Quoted 4 lines
test/py/tests/fs_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)Applied to sjg/master, thanks!
You have been repeatedly asked to not send messages about your personal tree to the list. Please stop sending these messages (and I hope you didn't change the patchwork status too, again).
We are still not really on the same page here.
This series is showing as rejected in patchwork, so I've applied it to my tree and sent an appropriate message. While we are in this state of your rejecting my patches, I am not sure what else I can do. I have already renamed the tree, as you requested, so there should be no confusion that this is my tree. If there is still confusion, then perhaps the rename (which took quite a bit of effort) was not effective in resolving your concerns?
If you do take a pull request (e.g. for one of the 100+ patches assigned to me in patchwork right now), the patches will then be in your tree, so presumably need to be marked 'accepted' in patchwork. When would be the best time for me to change this status?
BTW, I'm really not sure why you have rejected this particular patch. Even if you don't want scripts maintained in your tree, this is really just a small tweak. It will help reduce the delta between our trees.
Regards,
Simon
Re: [PATCH 1/6] test: Update fs_helper to support passing in the image
Quoted 17 lines · Simon Glass
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 12 lines · Simon Glass
This function is useful for other scripts, so add a parameter to specify the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in many cases we only want to see warnings / errors.
Signed-off-by Simon Glass <[email protected]>---
test/py/tests/fs_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Applied to sjg/master, thanks!
You have been repeatedly asked to not send messages about your personal tree to the list. Please stop sending these messages (and I hope you didn't change the patchwork status too, again).
We are still not really on the same page here.
Yes, you keep not following seemingly clear directions. You posted something not against master, and that also continued adding things which do not belong in the tree, to the tree.
Quoted 2 lines
This series is showing as rejected in patchwork, so I've applied it to my tree and sent an appropriate message
There is no appropriate message to send to the public mailing list for your downstream tree, stop doing that. And patchwork reflects mainline, not your personal tree.
Quoted 6 lines
While we are in this state of
your rejecting my patches, I am not sure what else I can do. I have already renamed the tree, as you requested, so there should be no confusion that this is my tree. If there is still confusion, then perhaps the rename (which took quite a bit of effort) was not effective in resolving your concerns?
Your downstream tree is not a special tree. Others have explained how they maintain downstream trees and work on upstreaming changes.
Quoted 4 lines
If you do take a pull request (e.g. for one of the 100+ patches assigned to me in patchwork right now), the patches will then be in your tree, so presumably need to be marked 'accepted' in patchwork. When would be the best time for me to change this status?
The status of patches for mainline in patchwork is pretty easy. I even run some helper scripts every tag to update (most) patches that might have been missed.
Quoted 3 lines
BTW, I'm really not sure why you have rejected this particular patch. Even if you don't want scripts maintained in your tree, this is really just a small tweak. It will help reduce the delta between our trees.
It was rejected either because it wasn't against mainline, or because it contained changes that had already been rejected.
Signature · 1 line
Tom
PATCH 2/6 scripts: Rename build-efi.py to drop the file extension
In reply to Simon GlassThe .py extension isn't very useful. Drop it and update the shebang to specify Python 3
Update the docs for this and also drop the old reference to 2021 images.
---
MAINTAINERS | 2 +-
doc/develop/uefi/u-boot_on_efi.rst | 7 +++----
scripts/{build-efi.py => build-efi} | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
rename scripts/{build-efi.py => build-efi} (99%)MAINTAINERS +1 -1
@@ -1074,7 +1074,7 @@ F: doc/develop/uefi/u-boot_on_efi.rst F: drivers/block/efi-media-uclass.c F: drivers/block/sb_efi_media.c F: lib/efi/ -F: scripts/build-efi.py +F: scripts/build-efi F: test/dm/efi_media.c EFI LOGGING
doc/develop/uefi/u-boot_on_efi.rst +3 -4
@@ -97,9 +97,8 @@ that EFI does not support booting a 64-bit application from a 32-bit EFI (or vice versa). Also it will often fail to print an error message if you get this wrong. -You may find the script `scripts/build-efi.py` helpful for building and testing -U-Boot on UEFI on QEMU. It also includes links to UEFI binaries dating from -2021. +You may find the script `scripts/build-efi` helpful for building and testing +U-Boot on UEFI on QEMU. See `Example run`_ for an example run.
@@ -202,7 +201,7 @@ Example run This shows running with serial enabled (see `include/configs/efi-x86_app.h`):: - $ scripts/build-efi.py -wsPr + $ scripts/build-efi -wsPr Packaging efi-x86_app32 Running qemu-system-i386
scripts/build-efi renamed from scripts/build-efi.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0+ """ Script to build an EFI thing suitable for booting with QEMU, possibly running
Signature · 1 line
2.43.0
PATCH 3/6 scripts: Convert the build-efi script to avoid sudo
In reply to Simon GlassMake use of the mk_fs() function to avoid needing to use sudo to mount the loopback partition. This makes the script a little more friendly for those nervous about sudo in their tools.
---
MAINTAINERS | 1 + scripts/build-efi | 104 +++++----------------------------------- scripts/build_helper.py | 64 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 92 deletions(-) create mode 100644 scripts/build_helper.py
MAINTAINERS +1 -0
@@ -1127,6 +1127,7 @@ W: https://docs.u-boot.org/en/latest/board/emulation/script.html F: configs/qemu_x86* F: doc/board/emulation/script.rst F: scripts/build-qemu.sh +F: scripts/build_helper.py ENVIRONMENT M: Joe Hershberger <[email protected]>
scripts/build-efi +12 -92
148 lines not on this page · raw message
scripts/build_helper.py new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 4/6 scripts: Create a common settings file for QEMU scripts
In reply to Simon GlassMove the settings into a common file so they can be used by all tools.
---
scripts/build-efi | 53 ++++----------------------------- scripts/build_helper.py | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 47 deletions(-)
scripts/build-efi +6 -47
@@ -16,7 +16,6 @@ Use ~/.build-efi to configure the various paths used by this script. """ from argparse import ArgumentParser -import configparser import os import shutil
@@ -63,55 +62,15 @@ def parse_args(): return args -def get_settings(): - """Get settings from the settings file - - Return: - ConfigParser containing settings - """ - settings = configparser.ConfigParser() - fname = f'{os.getenv("HOME")}/.build-efi' - if not os.path.exists(fname): - print('No config file found ~/.build-efi\nCreating one...\n') - tools.write_file(fname, '''[build-efi] -# Mount path for the temporary image -mount_point = /mnt/test-efi - -# Image-output filename -image_file = try.img - -# Set ubdir to the build directory where you build U-Boot out-of-tree -# We avoid in-tree build because it gets confusing trying different builds -build_dir = /tmp/b - -# Build the kernel with: make O=/tmp/kernel -bzimage = /tmp/kernel/arch/x86/boot/bzImage - -# Place where OVMF-pure-efi.i386.fd etc. are kept -efi_dir = . -''', binary=False) - settings.read(fname) - return settings - - class BuildEfi: """Class to collect together the various bits of state while running""" - def __init__(self, settings, args): + def __init__(self, args): self.helper = Helper() - self.settings = settings - self.img = self.get_setting('image_file', 'try.img') - self.build_dir = self.get_setting("build_dir", '/tmp') + self.helper.read_settings() + self.img = self.helper.get_setting('efi_image_file', 'efi.img') + self.build_dir = self.helper.get_setting("build_dir", '/tmp') self.args = args - def get_setting(self, name, fallback=None): - """Get a setting by name - - Args: - name (str): Name of setting to retrieve - fallback (str or None): Value to return if the setting is missing - """ - return self.settings.get('build-efi', name, fallback=fallback) - def run_qemu(self, bitness, serial_only): """Run QEMU
@@ -120,7 +79,7 @@ class BuildEfi: serial_only (bool): True to run without a display """ extra = [] - efi_dir = self.get_setting("efi_dir") + efi_dir = self.helper.get_setting('efi_dir') if self.args.arm: qemu_arch = 'aarch64' extra += ['--machine', 'virt', '-cpu', 'max']
@@ -210,5 +169,5 @@ class BuildEfi: if __name__ == "__main__": - efi = BuildEfi(get_settings(), parse_args()) + efi = BuildEfi(parse_args()) efi.start()
scripts/build_helper.py +65 -0
77 lines not on this page · raw message
Signature · 1 line
2.43.0
Simon Glass
AppliedRe: [PATCH 4/6] scripts: Create a common settings file for QEMU scripts
Move the settings into a common file so they can be used by all tools.
---
scripts/build-efi | 53 ++++----------------------------- scripts/build_helper.py | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 47 deletions(-)
Applied to sjg/master, thanks!
PATCH 5/6 u_boot_pylib: Support a fatal level in tout
In reply to Simon GlassIt is convenient to be able to print a message and exit. Add a new 'fatal' level to support this.
Update some assumptions about the level, so that the tools continue to work as now.
---
tools/binman/control.py | 6 +++--- tools/u_boot_pylib/tout.py | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-)
tools/binman/control.py +3 -3
@@ -777,7 +777,7 @@ def Binman(args): if args.cmd in ['ls', 'extract', 'replace', 'tool', 'sign']: try: - tout.init(args.verbosity) + tout.init(args.verbosity + 1) if args.cmd == 'replace': tools.prepare_output_dir(args.outdir, args.preserve) else:
@@ -835,9 +835,9 @@ def Binman(args): args.indir.append(board_pathname) try: - tout.init(args.verbosity) + tout.init(args.verbosity + 1) elf.debug = args.debug - cbfs_util.VERBOSE = args.verbosity > 2 + cbfs_util.VERBOSE = args.verbosity > tout.NOTICE state.use_fake_dtb = args.fake_dtb # Normally we replace the 'u-boot' etype with 'u-boot-expanded', etc.
tools/u_boot_pylib/tout.py +16 -6
@@ -9,7 +9,7 @@ import sys from u_boot_pylib import terminal # Output verbosity levels that we support -ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6) +FATAL, ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(7) in_progress = False
@@ -42,12 +42,12 @@ def user_is_present(): Returns: True if it thinks the user is there, and False otherwise """ - return stdout_is_tty and verbose > 0 + return stdout_is_tty and verbose > ERROR def clear_progress(): """Clear any active progress message on the terminal.""" global in_progress - if verbose > 0 and stdout_is_tty and in_progress: + if verbose > ERROR and stdout_is_tty and in_progress: _stdout.write('\r%s\r' % (" " * len (_progress))) _stdout.flush() in_progress = False
@@ -60,7 +60,7 @@ def progress(msg, warning=False, trailer='...'): warning: True if this is a warning.""" global in_progress clear_progress() - if verbose > 0: + if verbose > ERROR: _progress = msg + trailer if stdout_is_tty: col = _color.YELLOW if warning else _color.GREEN
@@ -87,6 +87,8 @@ def _output(level, msg, color=None): print(msg, file=sys.stderr) else: print(msg) + if level == FATAL: + sys.exit(1) def do_output(level, msg): """Output a message to the terminal.
@@ -98,6 +100,14 @@ def do_output(level, msg): """ _output(level, msg) +def fatal(msg): + """Display an error message and exit + + Args: + msg; Message to display. + """ + _output(FATAL, msg, _color.RED) + def error(msg): """Display an error message
@@ -153,13 +163,13 @@ def user_output(msg): Args: msg; Message to display. """ - _output(0, msg) + _output(ERROR, msg) def init(_verbose=WARNING, stdout=sys.stdout, allow_colour=True): """Initialize a new output object. Args: - verbose: Verbosity level (0-4). + verbose: Verbosity level (0-6). stdout: File to use for stdout. """ global verbose, _progress, _color, _stdout, stdout_is_tty
Signature · 1 line
2.43.0
Simon Glass
AppliedRe: [PATCH 5/6] u_boot_pylib: Support a fatal level in tout
It is convenient to be able to print a message and exit. Add a new 'fatal' level to support this.
Update some assumptions about the level, so that the tools continue to work as now.
---
tools/binman/control.py | 6 +++--- tools/u_boot_pylib/tout.py | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-)
Applied to sjg/master, thanks!
PATCH 6/6 scripts: Convert the build-qemu script to Python
In reply to Simon GlassConvert this to Python and make use of the build_helpers module. Update that module to remove old options and improve the ordering of options.
The script doubles in size, part of which is being a lot more friendly with virtiofsd problems, as well as adding a verbose mode.
Update the documentation as well.
---
MAINTAINERS | 2 +- doc/board/emulation/script.rst | 78 +++++-- scripts/build-qemu | 414 +++++++++++++++++++++++++++++++++ scripts/build-qemu.sh | 211 ----------------- scripts/build_helper.py | 17 +- 5 files changed, 485 insertions(+), 237 deletions(-) create mode 100755 scripts/build-qemu delete mode 100755 scripts/build-qemu.sh
MAINTAINERS +1 -1
@@ -1126,7 +1126,7 @@ S: Maintained W: https://docs.u-boot.org/en/latest/board/emulation/script.html F: configs/qemu_x86* F: doc/board/emulation/script.rst -F: scripts/build-qemu.sh +F: scripts/build-qemu F: scripts/build_helper.py ENVIRONMENT
doc/board/emulation/script.rst +63 -15
104 lines not on this page · raw message
scripts/build-qemu new file +414 -0
414 lines not on this page · raw message
scripts/build-qemu.sh deleted +0 -211
211 lines not on this page · raw message
scripts/build_helper.py +7 -10
@@ -38,19 +38,20 @@ class Helper: tools.write_file(fname, '''# U-Boot QEMU-scripts config [DEFAULT] -# Image-output filename -image_file = try.img - -# Image directory (for prebuilt UEFI-images) -image_dir = ~/dev/uefi - # Set ubdir to the build directory where you build U-Boot out-of-tree # We avoid in-tree build because it gets confusing trying different builds +# Each board gets a build in a separate subdir build_dir = /tmp/b +# Image directory (for OS images) +image_dir = ~/dev/os + # Build the kernel with: make O=/tmp/kernel bzimage = /tmp/kernel/arch/x86/boot/bzImage +# EFI image-output filename +efi_image_file = try.img + # Directory where OVMF-pure-efi.i386.fd etc. are kept efi_dir = ~/dev/efi
@@ -59,10 +60,6 @@ sct_dir = ~/dev/efi/sct # Directory where the SCT image is temporarily mounted for modification sct_mnt = /mnt/sct - -# Directory containing Tianocore builds (e.g. OVMF-pure-efi.x64.fd) -tianocore_dir = ~/dev/efi/tianocore - ''', binary=False) self.settings.read(fname)
Signature · 1 line
2.43.0
Quoted 9 lines · Simon Glass
This series updates the two QEMU scripts available in U-Boot:
- Converts build-qemu to Python
- Converts build-efi to avoid sudo (unless SCT is used)
- Introduces a proper settings file shared between both scriptsIt also includes a few documentation updates.
The next step is to get these scripts running in CI.
This extends the anti-pattern of "one big repository for everything" while also expanding upon the scripting that I already said I don't want in mainline and I thought you were going to maintain in the u-boot-contrib repository instead.
Signature · 1 line
Tom
Hi Tom,
Quoted 9 lines · Tom Rini
Quoted 6 lines · Simon Glass
This series updates the two QEMU scripts available in U-Boot:
- Converts build-qemu to Python
- Converts build-efi to avoid sudo (unless SCT is used)
- Introduces a proper settings file shared between both scripts
Quoted 8 lines
Quoted 3 lines
It also includes a few documentation updates.
The next step is to get these scripts running in CI.
This extends the anti-pattern of "one big repository for everything" while also expanding upon the scripting that I already said I don't want in mainline and I thought you were going to maintain in the u-boot-contrib repository instead.
Apart from the philosophical side, your original complaint was about use of sudo which I have mostly resolved. If you are worried about the size of the repo, these files are small and the repo is already big; in fact it grew nearly 30% in the last year.
Another comment you had was about CVEs, but I'm not sure it is relevant in this case. I suspect we could find another way to make UEFI SCT work than mounting a loopback device. In fact I was hoping that Linaro might get SCT running in CI.
Anyway, yes, I did add a script in your contrib repo [1] . But then I decided to see what others would do. It has been three months now and I haven't seen any contributions to it. So it may actually be that no one sees any value in it. I would like people to use and extend these scripts, e.g. for RISC-V and for booting other OSes. I very much doubt anything like that will happen in contrib/ but we can keep an eye on it and perhaps I will be wrong.
I'd like to suggest that you consider another PoV on this. If contrib/ becomes a thriving marketplace, we can always delete the scripts from the tree.
Regards,
Simon
[1] https://source.denx.de/u-boot/u-boot-extras/-/tree/master/contrib?ref_type=heads
Quoted 14 lines · Simon Glass
Hi Tom,
Quoted 11 lines · Tom Rini
Quoted 8 lines · Simon Glass
This series updates the two QEMU scripts available in U-Boot:
- Converts build-qemu to Python
- Converts build-efi to avoid sudo (unless SCT is used)
- Introduces a proper settings file shared between both scriptsIt also includes a few documentation updates.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
The next step is to get these scripts running in CI.
This extends the anti-pattern of "one big repository for everything" while also expanding upon the scripting that I already said I don't want in mainline and I thought you were going to maintain in the u-boot-contrib repository instead.
Apart from the philosophical side,
OK, but it's not "philosophical". One giant repository is an anti-pattern and is to be avoided. Mentioning things we use as subtrees misses the point entirely. So no, this is the wrong direction for numerous reasons and I leave it as an exercise to you to read up on why this is bad.
Signature · 1 line
Tom