|
29 | 29 | # QEMU executable to use
|
30 | 30 | 'qemu_binary': 'qemu-system-x86_64',
|
31 | 31 | # Path to directory containing `OVMF_{CODE/VARS}.fd`.
|
32 |
| - # TODO: use installed OVMF, if available. |
33 |
| - 'ovmf_dir': WORKSPACE_DIR / 'uefi-test-runner', |
| 32 | + # `find_ovmf` function will try to find one if this isn't specified. |
| 33 | + 'ovmf_dir': None, |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | # Path to target directory. If None, it will be initialized with information
|
@@ -112,17 +112,50 @@ def doc():
|
112 | 112 | '--package', 'uefi-services',
|
113 | 113 | ])
|
114 | 114 |
|
| 115 | +def ovmf_files(ovmf_dir): |
| 116 | + 'Returns the tuple of paths to OVMF_CODE.fd and OVMF_VARS.fd given the directory' |
| 117 | + return ovmf_dir / 'OVMF_CODE.fd', ovmf_dir / 'OVMF_VARS.fd' |
| 118 | + |
| 119 | +def check_ovmf_dir(ovmf_dir): |
| 120 | + 'Check whether the given directory contains necessary OVMF files' |
| 121 | + ovmf_code, ovmf_vars = ovmf_files(ovmf_dir) |
| 122 | + return ovmf_code.is_file() and ovmf_vars.is_file() |
| 123 | + |
| 124 | +def find_ovmf(): |
| 125 | + 'Find path to OVMF files' |
| 126 | + |
| 127 | + # If the path is specified in the settings, use it. |
| 128 | + if SETTINGS['ovmf_dir'] is not None: |
| 129 | + ovmf_dir = SETTINGS['ovmf_dir'] |
| 130 | + if check_ovmf_dir(ovmf_dir): |
| 131 | + return ovmf_dir |
| 132 | + raise FileNotFoundError(f'OVMF files not found in `{ovmf_dir}`') |
| 133 | + |
| 134 | + # Check whether the test runner directory contains the files. |
| 135 | + ovmf_dir = WORKSPACE_DIR / 'uefi-test-runner' |
| 136 | + if check_ovmf_dir(ovmf_dir): |
| 137 | + return ovmf_dir |
| 138 | + |
| 139 | + if sys.platform.startswith('linux'): |
| 140 | + possible_paths = [ |
| 141 | + # Most distros, including CentOS, Fedora, Debian, and Ubuntu. |
| 142 | + Path('/usr/share/OVMF'), |
| 143 | + # Arch Linux |
| 144 | + Path('/usr/share/ovmf/x64'), |
| 145 | + ] |
| 146 | + for path in possible_paths: |
| 147 | + if check_ovmf_dir(path): |
| 148 | + return path |
| 149 | + |
| 150 | + raise FileNotFoundError(f'OVMF files not found anywhere') |
| 151 | + |
115 | 152 | def run_qemu():
|
116 | 153 | 'Runs the code in QEMU.'
|
117 | 154 |
|
118 | 155 | # Rebuild all the changes.
|
119 | 156 | build('--features', 'qemu')
|
120 | 157 |
|
121 |
| - ovmf_dir = SETTINGS['ovmf_dir'] |
122 |
| - ovmf_code, ovmf_vars = ovmf_dir / 'OVMF_CODE.fd', ovmf_dir / 'OVMF_VARS.fd' |
123 |
| - |
124 |
| - if not ovmf_code.is_file(): |
125 |
| - raise FileNotFoundError(f'OVMF_CODE.fd not found in the `{ovmf_dir}` directory') |
| 158 | + ovmf_code, ovmf_vars = ovmf_files(find_ovmf()) |
126 | 159 |
|
127 | 160 | examples_dir = build_dir() / 'examples'
|
128 | 161 |
|
|
0 commit comments