Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 2 | # Copyright (c) 2016 Google, Inc |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | # |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 5 | # To run a single test, change to this directory, and: |
| 6 | # |
| 7 | # python -m unittest func_test.TestFunctional.testHelp |
| 8 | |
Simon Glass | fdc3436 | 2020-07-09 18:39:45 -0600 | [diff] [blame] | 9 | import collections |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 10 | import gzip |
Simon Glass | e0e5df9 | 2018-09-14 04:57:31 -0600 | [diff] [blame] | 11 | import hashlib |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 12 | from optparse import OptionParser |
| 13 | import os |
Simon Glass | fdc3436 | 2020-07-09 18:39:45 -0600 | [diff] [blame] | 14 | import re |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 15 | import shutil |
| 16 | import struct |
| 17 | import sys |
| 18 | import tempfile |
| 19 | import unittest |
Simon Glass | 56ee85e | 2022-01-09 20:13:57 -0700 | [diff] [blame] | 20 | import unittest.mock |
| 21 | import urllib.error |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 22 | |
Simon Glass | 386c63c | 2022-01-09 20:13:50 -0700 | [diff] [blame] | 23 | from binman import bintool |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 24 | from binman import cbfs_util |
| 25 | from binman import cmdline |
| 26 | from binman import control |
| 27 | from binman import elf |
| 28 | from binman import elf_test |
Simon Glass | 7598972 | 2021-11-23 21:08:59 -0700 | [diff] [blame] | 29 | from binman import fip_util |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 30 | from binman import fmap_util |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 31 | from binman import state |
| 32 | from dtoc import fdt |
| 33 | from dtoc import fdt_util |
| 34 | from binman.etype import fdtmap |
| 35 | from binman.etype import image_header |
Simon Glass | 0723798 | 2020-08-05 13:27:47 -0600 | [diff] [blame] | 36 | from binman.image import Image |
Simon Glass | 4583c00 | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 37 | from u_boot_pylib import command |
| 38 | from u_boot_pylib import test_util |
| 39 | from u_boot_pylib import tools |
| 40 | from u_boot_pylib import tout |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 41 | |
| 42 | # Contents of test files, corresponding to different entry types |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 43 | U_BOOT_DATA = b'1234' |
| 44 | U_BOOT_IMG_DATA = b'img' |
Alper Nebi Yasak | 367ecbf | 2022-06-18 15:13:11 +0300 | [diff] [blame] | 45 | U_BOOT_SPL_DATA = b'56780123456789abcdefghijklm' |
| 46 | U_BOOT_TPL_DATA = b'tpl9876543210fedcbazywvuts' |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 47 | U_BOOT_VPL_DATA = b'vpl76543210fedcbazywxyz_' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 48 | BLOB_DATA = b'89' |
| 49 | ME_DATA = b'0abcd' |
| 50 | VGA_DATA = b'vga' |
Sughosh Ganu | b617611 | 2023-08-22 23:09:59 +0530 | [diff] [blame] | 51 | EFI_CAPSULE_DATA = b'efi' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 52 | U_BOOT_DTB_DATA = b'udtb' |
| 53 | U_BOOT_SPL_DTB_DATA = b'spldtb' |
| 54 | U_BOOT_TPL_DTB_DATA = b'tpldtb' |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 55 | U_BOOT_VPL_DTB_DATA = b'vpldtb' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 56 | X86_START16_DATA = b'start16' |
| 57 | X86_START16_SPL_DATA = b'start16spl' |
| 58 | X86_START16_TPL_DATA = b'start16tpl' |
Simon Glass | 2250ee6 | 2019-08-24 07:22:48 -0600 | [diff] [blame] | 59 | X86_RESET16_DATA = b'reset16' |
| 60 | X86_RESET16_SPL_DATA = b'reset16spl' |
| 61 | X86_RESET16_TPL_DATA = b'reset16tpl' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 62 | PPC_MPC85XX_BR_DATA = b'ppcmpc85xxbr' |
| 63 | U_BOOT_NODTB_DATA = b'nodtb with microcode pointer somewhere in here' |
| 64 | U_BOOT_SPL_NODTB_DATA = b'splnodtb with microcode pointer somewhere in here' |
| 65 | U_BOOT_TPL_NODTB_DATA = b'tplnodtb with microcode pointer somewhere in here' |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 66 | U_BOOT_VPL_NODTB_DATA = b'vplnodtb' |
Alper Nebi Yasak | 2135331 | 2022-02-08 01:08:04 +0300 | [diff] [blame] | 67 | U_BOOT_EXP_DATA = U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA |
| 68 | U_BOOT_SPL_EXP_DATA = U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA |
| 69 | U_BOOT_TPL_EXP_DATA = U_BOOT_TPL_NODTB_DATA + U_BOOT_TPL_DTB_DATA |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 70 | FSP_DATA = b'fsp' |
| 71 | CMC_DATA = b'cmc' |
| 72 | VBT_DATA = b'vbt' |
| 73 | MRC_DATA = b'mrc' |
Simon Glass | bb74837 | 2018-07-17 13:25:33 -0600 | [diff] [blame] | 74 | TEXT_DATA = 'text' |
| 75 | TEXT_DATA2 = 'text2' |
| 76 | TEXT_DATA3 = 'text3' |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 77 | CROS_EC_RW_DATA = b'ecrw' |
| 78 | GBB_DATA = b'gbbd' |
| 79 | BMPBLK_DATA = b'bmp' |
| 80 | VBLOCK_DATA = b'vblk' |
| 81 | FILES_DATA = (b"sorry I'm late\nOh, don't bother apologising, I'm " + |
| 82 | b"sorry you're alive\n") |
Simon Glass | ff5c7e3 | 2019-07-08 13:18:42 -0600 | [diff] [blame] | 83 | COMPRESS_DATA = b'compress xxxxxxxxxxxxxxxxxxxxxx data' |
Simon Glass | 8f5ef89 | 2020-10-26 17:40:25 -0600 | [diff] [blame] | 84 | COMPRESS_DATA_BIG = COMPRESS_DATA * 2 |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 85 | REFCODE_DATA = b'refcode' |
Simon Glass | ea0fff9 | 2019-08-24 07:23:07 -0600 | [diff] [blame] | 86 | FSP_M_DATA = b'fsp_m' |
Simon Glass | bc6a88f | 2019-10-20 21:31:35 -0600 | [diff] [blame] | 87 | FSP_S_DATA = b'fsp_s' |
Simon Glass | 998d148 | 2019-10-20 21:31:36 -0600 | [diff] [blame] | 88 | FSP_T_DATA = b'fsp_t' |
Simon Glass | dc2f81a | 2020-09-01 05:13:58 -0600 | [diff] [blame] | 89 | ATF_BL31_DATA = b'bl31' |
Roger Quadros | 47f420a | 2022-02-19 20:50:04 +0200 | [diff] [blame] | 90 | TEE_OS_DATA = b'this is some tee OS data' |
Simon Glass | 7598972 | 2021-11-23 21:08:59 -0700 | [diff] [blame] | 91 | ATF_BL2U_DATA = b'bl2u' |
Bin Meng | 4c4d607 | 2021-05-10 20:23:33 +0800 | [diff] [blame] | 92 | OPENSBI_DATA = b'opensbi' |
Samuel Holland | 18bd455 | 2020-10-21 21:12:15 -0500 | [diff] [blame] | 93 | SCP_DATA = b'scp' |
Jonas Karlman | 05b978b | 2023-02-25 19:01:33 +0000 | [diff] [blame] | 94 | ROCKCHIP_TPL_DATA = b'rockchip-tpl' |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 95 | TEST_FDT1_DATA = b'fdt1' |
| 96 | TEST_FDT2_DATA = b'test-fdt2' |
Simon Glass | fb91d56 | 2020-09-06 10:35:33 -0600 | [diff] [blame] | 97 | ENV_DATA = b'var1=1\nvar2="2"' |
Christian Taedcke | 289e600 | 2023-07-17 09:05:54 +0200 | [diff] [blame] | 98 | ENCRYPTED_IV_DATA = b'123456' |
| 99 | ENCRYPTED_KEY_DATA = b'abcde' |
Philippe Reynes | b1c5093 | 2022-03-28 22:57:04 +0200 | [diff] [blame] | 100 | PRE_LOAD_MAGIC = b'UBSH' |
| 101 | PRE_LOAD_VERSION = 0x11223344.to_bytes(4, 'big') |
| 102 | PRE_LOAD_HDR_SIZE = 0x00001000.to_bytes(4, 'big') |
Neha Malcom Francis | 6c66ccf | 2023-07-22 00:14:24 +0530 | [diff] [blame] | 103 | TI_BOARD_CONFIG_DATA = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
Neha Malcom Francis | 7814482 | 2023-07-22 00:14:25 +0530 | [diff] [blame] | 104 | TI_UNSECURE_DATA = b'unsecuredata' |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 105 | |
| 106 | # Subdirectory of the input dir to use to put test FDTs |
| 107 | TEST_FDT_SUBDIR = 'fdts' |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 108 | |
Simon Glass | 6ccbfcd | 2019-07-20 12:23:47 -0600 | [diff] [blame] | 109 | # The expected size for the device tree in some tests |
Simon Glass | f667e45 | 2019-07-08 14:25:50 -0600 | [diff] [blame] | 110 | EXTRACT_DTB_SIZE = 0x3c9 |
| 111 | |
Simon Glass | 6ccbfcd | 2019-07-20 12:23:47 -0600 | [diff] [blame] | 112 | # Properties expected to be in the device tree when update_dtb is used |
| 113 | BASE_DTB_PROPS = ['offset', 'size', 'image-pos'] |
| 114 | |
Simon Glass | 12bb1a9 | 2019-07-20 12:23:51 -0600 | [diff] [blame] | 115 | # Extra properties expected to be in the device tree when allow-repack is used |
| 116 | REPACK_DTB_PROPS = ['orig-offset', 'orig-size'] |
| 117 | |
Stefan Herbrechtsmeier | cbe2e75 | 2022-08-19 16:25:28 +0200 | [diff] [blame] | 118 | # Supported compression bintools |
Stefan Herbrechtsmeier | cd15b64 | 2022-08-19 16:25:38 +0200 | [diff] [blame] | 119 | COMP_BINTOOLS = ['bzip2', 'gzip', 'lz4', 'lzma_alone', 'lzop', 'xz', 'zstd'] |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 120 | |
Simon Glass | 2f80c5e | 2023-01-07 14:07:14 -0700 | [diff] [blame] | 121 | TEE_ADDR = 0x5678 |
| 122 | |
Sughosh Ganu | b617611 | 2023-08-22 23:09:59 +0530 | [diff] [blame] | 123 | # Firmware Management Protocol(FMP) GUID |
| 124 | FW_MGMT_GUID = 'edd5cb6d2de8444cbda17194199ad92a' |
| 125 | # Image GUID specified in the DTS |
| 126 | CAPSULE_IMAGE_GUID = '52cfd7092007104791d108469b7fe9c8' |
| 127 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 128 | class TestFunctional(unittest.TestCase): |
| 129 | """Functional tests for binman |
| 130 | |
| 131 | Most of these use a sample .dts file to build an image and then check |
| 132 | that it looks correct. The sample files are in the test/ subdirectory |
| 133 | and are numbered. |
| 134 | |
| 135 | For each entry type a very small test file is created using fixed |
| 136 | string contents. This makes it easy to test that things look right, and |
| 137 | debug problems. |
| 138 | |
| 139 | In some cases a 'real' file must be used - these are also supplied in |
| 140 | the test/ diurectory. |
| 141 | """ |
| 142 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 143 | def setUpClass(cls): |
Simon Glass | 4d5994f | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 144 | global entry |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 145 | from binman import entry |
Simon Glass | 4d5994f | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 146 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 147 | # Handle the case where argv[0] is 'python' |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 148 | cls._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) |
| 149 | cls._binman_pathname = os.path.join(cls._binman_dir, 'binman') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 150 | |
| 151 | # Create a temporary directory for input files |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 152 | cls._indir = tempfile.mkdtemp(prefix='binmant.') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 153 | |
| 154 | # Create some test files |
| 155 | TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA) |
| 156 | TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA) |
| 157 | TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA) |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 158 | TestFunctional._MakeInputFile('tpl/u-boot-tpl.bin', U_BOOT_TPL_DATA) |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 159 | TestFunctional._MakeInputFile('vpl/u-boot-vpl.bin', U_BOOT_VPL_DATA) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 160 | TestFunctional._MakeInputFile('blobfile', BLOB_DATA) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 161 | TestFunctional._MakeInputFile('me.bin', ME_DATA) |
| 162 | TestFunctional._MakeInputFile('vga.bin', VGA_DATA) |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 163 | cls._ResetDtbs() |
Simon Glass | 2250ee6 | 2019-08-24 07:22:48 -0600 | [diff] [blame] | 164 | |
Jagdish Gediya | 9d368f3 | 2018-09-03 21:35:08 +0530 | [diff] [blame] | 165 | TestFunctional._MakeInputFile('u-boot-br.bin', PPC_MPC85XX_BR_DATA) |
Simon Glass | 2250ee6 | 2019-08-24 07:22:48 -0600 | [diff] [blame] | 166 | |
Simon Glass | 5e23918 | 2019-08-24 07:22:49 -0600 | [diff] [blame] | 167 | TestFunctional._MakeInputFile('u-boot-x86-start16.bin', X86_START16_DATA) |
| 168 | TestFunctional._MakeInputFile('spl/u-boot-x86-start16-spl.bin', |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 169 | X86_START16_SPL_DATA) |
Simon Glass | 5e23918 | 2019-08-24 07:22:49 -0600 | [diff] [blame] | 170 | TestFunctional._MakeInputFile('tpl/u-boot-x86-start16-tpl.bin', |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 171 | X86_START16_TPL_DATA) |
Simon Glass | 2250ee6 | 2019-08-24 07:22:48 -0600 | [diff] [blame] | 172 | |
| 173 | TestFunctional._MakeInputFile('u-boot-x86-reset16.bin', |
| 174 | X86_RESET16_DATA) |
| 175 | TestFunctional._MakeInputFile('spl/u-boot-x86-reset16-spl.bin', |
| 176 | X86_RESET16_SPL_DATA) |
| 177 | TestFunctional._MakeInputFile('tpl/u-boot-x86-reset16-tpl.bin', |
| 178 | X86_RESET16_TPL_DATA) |
| 179 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 180 | TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 181 | TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin', |
| 182 | U_BOOT_SPL_NODTB_DATA) |
Simon Glass | f025363 | 2018-09-14 04:57:32 -0600 | [diff] [blame] | 183 | TestFunctional._MakeInputFile('tpl/u-boot-tpl-nodtb.bin', |
| 184 | U_BOOT_TPL_NODTB_DATA) |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 185 | TestFunctional._MakeInputFile('vpl/u-boot-vpl-nodtb.bin', |
| 186 | U_BOOT_VPL_NODTB_DATA) |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 187 | TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) |
| 188 | TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 189 | TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 190 | TestFunctional._MakeInputFile('mrc.bin', MRC_DATA) |
Simon Glass | ec127af | 2018-07-17 13:25:39 -0600 | [diff] [blame] | 191 | TestFunctional._MakeInputFile('ecrw.bin', CROS_EC_RW_DATA) |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 192 | TestFunctional._MakeInputDir('devkeys') |
| 193 | TestFunctional._MakeInputFile('bmpblk.bin', BMPBLK_DATA) |
Simon Glass | 3ae192c | 2018-10-01 12:22:31 -0600 | [diff] [blame] | 194 | TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA) |
Simon Glass | ea0fff9 | 2019-08-24 07:23:07 -0600 | [diff] [blame] | 195 | TestFunctional._MakeInputFile('fsp_m.bin', FSP_M_DATA) |
Simon Glass | bc6a88f | 2019-10-20 21:31:35 -0600 | [diff] [blame] | 196 | TestFunctional._MakeInputFile('fsp_s.bin', FSP_S_DATA) |
Simon Glass | 998d148 | 2019-10-20 21:31:36 -0600 | [diff] [blame] | 197 | TestFunctional._MakeInputFile('fsp_t.bin', FSP_T_DATA) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 198 | |
Simon Glass | 53e22bf | 2019-08-24 07:22:53 -0600 | [diff] [blame] | 199 | cls._elf_testdir = os.path.join(cls._indir, 'elftest') |
| 200 | elf_test.BuildElfTestFiles(cls._elf_testdir) |
| 201 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 202 | # ELF file with a '_dt_ucode_base_size' symbol |
Simon Glass | f514d8f | 2019-08-24 07:22:54 -0600 | [diff] [blame] | 203 | TestFunctional._MakeInputFile('u-boot', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 204 | tools.read_file(cls.ElfTestFile('u_boot_ucode_ptr'))) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 205 | |
| 206 | # Intel flash descriptor file |
Simon Glass | 0ba4b3d | 2020-07-09 18:39:41 -0600 | [diff] [blame] | 207 | cls._SetupDescriptor() |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 208 | |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 209 | shutil.copytree(cls.TestFile('files'), |
| 210 | os.path.join(cls._indir, 'files')) |
Simon Glass | 0a98b28 | 2018-09-14 04:57:28 -0600 | [diff] [blame] | 211 | |
Neha Malcom Francis | 6c66ccf | 2023-07-22 00:14:24 +0530 | [diff] [blame] | 212 | shutil.copytree(cls.TestFile('yaml'), |
| 213 | os.path.join(cls._indir, 'yaml')) |
| 214 | |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 215 | TestFunctional._MakeInputFile('compress', COMPRESS_DATA) |
Simon Glass | 8f5ef89 | 2020-10-26 17:40:25 -0600 | [diff] [blame] | 216 | TestFunctional._MakeInputFile('compress_big', COMPRESS_DATA_BIG) |
Simon Glass | dc2f81a | 2020-09-01 05:13:58 -0600 | [diff] [blame] | 217 | TestFunctional._MakeInputFile('bl31.bin', ATF_BL31_DATA) |
Roger Quadros | 47f420a | 2022-02-19 20:50:04 +0200 | [diff] [blame] | 218 | TestFunctional._MakeInputFile('tee-pager.bin', TEE_OS_DATA) |
Simon Glass | 7598972 | 2021-11-23 21:08:59 -0700 | [diff] [blame] | 219 | TestFunctional._MakeInputFile('bl2u.bin', ATF_BL2U_DATA) |
Bin Meng | 4c4d607 | 2021-05-10 20:23:33 +0800 | [diff] [blame] | 220 | TestFunctional._MakeInputFile('fw_dynamic.bin', OPENSBI_DATA) |
Samuel Holland | 18bd455 | 2020-10-21 21:12:15 -0500 | [diff] [blame] | 221 | TestFunctional._MakeInputFile('scp.bin', SCP_DATA) |
Jonas Karlman | 05b978b | 2023-02-25 19:01:33 +0000 | [diff] [blame] | 222 | TestFunctional._MakeInputFile('rockchip-tpl.bin', ROCKCHIP_TPL_DATA) |
Neha Malcom Francis | 7814482 | 2023-07-22 00:14:25 +0530 | [diff] [blame] | 223 | TestFunctional._MakeInputFile('ti_unsecure.bin', TI_UNSECURE_DATA) |
Sughosh Ganu | b617611 | 2023-08-22 23:09:59 +0530 | [diff] [blame] | 224 | TestFunctional._MakeInputFile('capsule_input.bin', EFI_CAPSULE_DATA) |
Simon Glass | 83d73c2 | 2018-09-14 04:57:26 -0600 | [diff] [blame] | 225 | |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 226 | # Add a few .dtb files for testing |
| 227 | TestFunctional._MakeInputFile('%s/test-fdt1.dtb' % TEST_FDT_SUBDIR, |
| 228 | TEST_FDT1_DATA) |
| 229 | TestFunctional._MakeInputFile('%s/test-fdt2.dtb' % TEST_FDT_SUBDIR, |
| 230 | TEST_FDT2_DATA) |
| 231 | |
Simon Glass | fb91d56 | 2020-09-06 10:35:33 -0600 | [diff] [blame] | 232 | TestFunctional._MakeInputFile('env.txt', ENV_DATA) |
| 233 | |
Simon Glass | 40c8bdd | 2022-03-05 20:19:12 -0700 | [diff] [blame] | 234 | # ELF file with two sections in different parts of memory, used for both |
| 235 | # ATF and OP_TEE |
| 236 | TestFunctional._MakeInputFile('bl31.elf', |
| 237 | tools.read_file(cls.ElfTestFile('elf_sections'))) |
| 238 | TestFunctional._MakeInputFile('tee.elf', |
| 239 | tools.read_file(cls.ElfTestFile('elf_sections'))) |
| 240 | |
Simon Glass | 2f80c5e | 2023-01-07 14:07:14 -0700 | [diff] [blame] | 241 | # Newer OP_TEE file in v1 binary format |
| 242 | cls.make_tee_bin('tee.bin') |
| 243 | |
Christian Taedcke | 289e600 | 2023-07-17 09:05:54 +0200 | [diff] [blame] | 244 | # test files for encrypted tests |
| 245 | TestFunctional._MakeInputFile('encrypted-file.iv', ENCRYPTED_IV_DATA) |
| 246 | TestFunctional._MakeInputFile('encrypted-file.key', ENCRYPTED_KEY_DATA) |
| 247 | |
Stefan Herbrechtsmeier | cbe2e75 | 2022-08-19 16:25:28 +0200 | [diff] [blame] | 248 | cls.comp_bintools = {} |
| 249 | for name in COMP_BINTOOLS: |
| 250 | cls.comp_bintools[name] = bintool.Bintool.create(name) |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 251 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 252 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 253 | def tearDownClass(cls): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 254 | """Remove the temporary input directory and its contents""" |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 255 | if cls.preserve_indir: |
| 256 | print('Preserving input dir: %s' % cls._indir) |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 257 | else: |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 258 | if cls._indir: |
| 259 | shutil.rmtree(cls._indir) |
| 260 | cls._indir = None |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 261 | |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 262 | @classmethod |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 263 | def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False, |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 264 | toolpath=None, verbosity=None): |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 265 | """Accept arguments controlling test execution |
| 266 | |
| 267 | Args: |
| 268 | preserve_indir: Preserve the shared input directory used by all |
| 269 | tests in this class. |
| 270 | preserve_outdir: Preserve the output directories used by tests. Each |
| 271 | test has its own, so this is normally only useful when running a |
| 272 | single test. |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 273 | toolpath: ist of paths to use for tools |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 274 | """ |
| 275 | cls.preserve_indir = preserve_indir |
| 276 | cls.preserve_outdirs = preserve_outdirs |
Simon Glass | 8acce60 | 2019-07-08 13:18:50 -0600 | [diff] [blame] | 277 | cls.toolpath = toolpath |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 278 | cls.verbosity = verbosity |
Simon Glass | d5164a7 | 2019-07-08 13:18:49 -0600 | [diff] [blame] | 279 | |
Stefan Herbrechtsmeier | cbe2e75 | 2022-08-19 16:25:28 +0200 | [diff] [blame] | 280 | def _CheckBintool(self, bintool): |
| 281 | if not bintool.is_present(): |
| 282 | self.skipTest('%s not available' % bintool.name) |
| 283 | |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 284 | def _CheckLz4(self): |
Stefan Herbrechtsmeier | cbe2e75 | 2022-08-19 16:25:28 +0200 | [diff] [blame] | 285 | bintool = self.comp_bintools['lz4'] |
| 286 | self._CheckBintool(bintool) |
Simon Glass | ac62fba | 2019-07-08 13:18:53 -0600 | [diff] [blame] | 287 | |
Simon Glass | bf574f1 | 2019-07-20 12:24:09 -0600 | [diff] [blame] | 288 | def _CleanupOutputDir(self): |
| 289 | """Remove the temporary output directory""" |
| 290 | if self.preserve_outdirs: |
| 291 | print('Preserving output dir: %s' % tools.outdir) |
| 292 | else: |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 293 | tools._finalise_for_test() |
Simon Glass | bf574f1 | 2019-07-20 12:24:09 -0600 | [diff] [blame] | 294 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 295 | def setUp(self): |
| 296 | # Enable this to turn on debugging output |
Simon Glass | f3385a5 | 2022-01-29 14:14:15 -0700 | [diff] [blame] | 297 | # tout.init(tout.DEBUG) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 298 | command.test_result = None |
| 299 | |
| 300 | def tearDown(self): |
| 301 | """Remove the temporary output directory""" |
Simon Glass | bf574f1 | 2019-07-20 12:24:09 -0600 | [diff] [blame] | 302 | self._CleanupOutputDir() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 303 | |
Simon Glass | f86a736 | 2019-07-20 12:24:10 -0600 | [diff] [blame] | 304 | def _SetupImageInTmpdir(self): |
| 305 | """Set up the output image in a new temporary directory |
| 306 | |
| 307 | This is used when an image has been generated in the output directory, |
| 308 | but we want to run binman again. This will create a new output |
| 309 | directory and fail to delete the original one. |
| 310 | |
| 311 | This creates a new temporary directory, copies the image to it (with a |
| 312 | new name) and removes the old output directory. |
| 313 | |
| 314 | Returns: |
| 315 | Tuple: |
| 316 | Temporary directory to use |
| 317 | New image filename |
| 318 | """ |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 319 | image_fname = tools.get_output_filename('image.bin') |
Simon Glass | f86a736 | 2019-07-20 12:24:10 -0600 | [diff] [blame] | 320 | tmpdir = tempfile.mkdtemp(prefix='binman.') |
| 321 | updated_fname = os.path.join(tmpdir, 'image-updated.bin') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 322 | tools.write_file(updated_fname, tools.read_file(image_fname)) |
Simon Glass | f86a736 | 2019-07-20 12:24:10 -0600 | [diff] [blame] | 323 | self._CleanupOutputDir() |
| 324 | return tmpdir, updated_fname |
| 325 | |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 326 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 327 | def _ResetDtbs(cls): |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 328 | TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) |
| 329 | TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA) |
| 330 | TestFunctional._MakeInputFile('tpl/u-boot-tpl.dtb', U_BOOT_TPL_DTB_DATA) |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 331 | TestFunctional._MakeInputFile('vpl/u-boot-vpl.dtb', U_BOOT_VPL_DTB_DATA) |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 332 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 333 | def _RunBinman(self, *args, **kwargs): |
| 334 | """Run binman using the command line |
| 335 | |
| 336 | Args: |
| 337 | Arguments to pass, as a list of strings |
| 338 | kwargs: Arguments to pass to Command.RunPipe() |
| 339 | """ |
Simon Glass | d980069 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 340 | result = command.run_pipe([[self._binman_pathname] + list(args)], |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 341 | capture=True, capture_stderr=True, raise_on_error=False) |
| 342 | if result.return_code and kwargs.get('raise_on_error', True): |
| 343 | raise Exception("Error running '%s': %s" % (' '.join(args), |
| 344 | result.stdout + result.stderr)) |
| 345 | return result |
| 346 | |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 347 | def _DoBinman(self, *argv): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 348 | """Run binman using directly (in the same process) |
| 349 | |
| 350 | Args: |
| 351 | Arguments to pass, as a list of strings |
| 352 | Returns: |
| 353 | Return value (0 for success) |
| 354 | """ |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 355 | argv = list(argv) |
| 356 | args = cmdline.ParseArgs(argv) |
| 357 | args.pager = 'binman-invalid-pager' |
| 358 | args.build_dir = self._indir |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 359 | |
| 360 | # For testing, you can force an increase in verbosity here |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 361 | # args.verbosity = tout.DEBUG |
| 362 | return control.Binman(args) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 363 | |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 364 | def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False, |
Simon Glass | eb833d8 | 2019-04-25 21:58:34 -0600 | [diff] [blame] | 365 | entry_args=None, images=None, use_real_dtb=False, |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 366 | use_expanded=False, verbosity=None, allow_missing=False, |
Heiko Thiery | a89c8f2 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 367 | allow_fake_blobs=False, extra_indirs=None, threads=None, |
Simon Glass | 4f9ee83 | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 368 | test_section_timeout=False, update_fdt_in_elf=None, |
Andrew Davis | 15432ea | 2023-07-22 00:14:44 +0530 | [diff] [blame] | 369 | force_missing_bintools='', ignore_missing=False, output_dir=None): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 370 | """Run binman with a given test file |
| 371 | |
| 372 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 373 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 374 | debug: True to enable debugging output |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 375 | map: True to output map files for the images |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 376 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 377 | tree before packing it into the image |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 378 | entry_args: Dict of entry args to supply to binman |
| 379 | key: arg name |
| 380 | value: value of that arg |
| 381 | images: List of image names to build |
Simon Glass | e9d336d | 2020-09-01 05:13:55 -0600 | [diff] [blame] | 382 | use_real_dtb: True to use the test file as the contents of |
| 383 | the u-boot-dtb entry. Normally this is not needed and the |
| 384 | test contents (the U_BOOT_DTB_DATA string) can be used. |
| 385 | But in some test we need the real contents. |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 386 | use_expanded: True to use expanded entries where available, e.g. |
| 387 | 'u-boot-expanded' instead of 'u-boot' |
Simon Glass | e9d336d | 2020-09-01 05:13:55 -0600 | [diff] [blame] | 388 | verbosity: Verbosity level to use (0-3, None=don't set it) |
| 389 | allow_missing: Set the '--allow-missing' flag so that missing |
| 390 | external binaries just produce a warning instead of an error |
Heiko Thiery | a89c8f2 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 391 | allow_fake_blobs: Set the '--fake-ext-blobs' flag |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 392 | extra_indirs: Extra input directories to add using -I |
Simon Glass | c69d19c | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 393 | threads: Number of threads to use (None for default, 0 for |
| 394 | single-threaded) |
Simon Glass | 7115f00 | 2021-11-03 21:09:17 -0600 | [diff] [blame] | 395 | test_section_timeout: True to force the first time to timeout, as |
| 396 | used in testThreadTimeout() |
Simon Glass | 0427bed | 2021-11-03 21:09:18 -0600 | [diff] [blame] | 397 | update_fdt_in_elf: Value to pass with --update-fdt-in-elf=xxx |
Simon Glass | 4f9ee83 | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 398 | force_missing_tools (str): comma-separated list of bintools to |
| 399 | regard as missing |
Andrew Davis | 15432ea | 2023-07-22 00:14:44 +0530 | [diff] [blame] | 400 | output_dir: Specific output directory to use for image using -O |
Simon Glass | 7115f00 | 2021-11-03 21:09:17 -0600 | [diff] [blame] | 401 | |
| 402 | Returns: |
| 403 | int return code, 0 on success |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 404 | """ |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 405 | args = [] |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 406 | if debug: |
| 407 | args.append('-D') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 408 | if verbosity is not None: |
| 409 | args.append('-v%d' % verbosity) |
| 410 | elif self.verbosity: |
| 411 | args.append('-v%d' % self.verbosity) |
| 412 | if self.toolpath: |
| 413 | for path in self.toolpath: |
| 414 | args += ['--toolpath', path] |
Simon Glass | c69d19c | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 415 | if threads is not None: |
| 416 | args.append('-T%d' % threads) |
| 417 | if test_section_timeout: |
| 418 | args.append('--test-section-timeout') |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 419 | args += ['build', '-p', '-I', self._indir, '-d', self.TestFile(fname)] |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 420 | if map: |
| 421 | args.append('-m') |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 422 | if update_dtb: |
Simon Glass | 2569e10 | 2019-07-08 13:18:47 -0600 | [diff] [blame] | 423 | args.append('-u') |
Simon Glass | 93d1741 | 2018-09-14 04:57:23 -0600 | [diff] [blame] | 424 | if not use_real_dtb: |
| 425 | args.append('--fake-dtb') |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 426 | if not use_expanded: |
| 427 | args.append('--no-expanded') |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 428 | if entry_args: |
Simon Glass | 5097915 | 2019-05-14 15:53:41 -0600 | [diff] [blame] | 429 | for arg, value in entry_args.items(): |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 430 | args.append('-a%s=%s' % (arg, value)) |
Simon Glass | 4f9f105 | 2020-07-09 18:39:38 -0600 | [diff] [blame] | 431 | if allow_missing: |
| 432 | args.append('-M') |
Simon Glass | b38da15 | 2022-11-09 19:14:42 -0700 | [diff] [blame] | 433 | if ignore_missing: |
| 434 | args.append('-W') |
Heiko Thiery | a89c8f2 | 2022-01-06 11:49:41 +0100 | [diff] [blame] | 435 | if allow_fake_blobs: |
| 436 | args.append('--fake-ext-blobs') |
Simon Glass | 4f9ee83 | 2022-01-09 20:14:09 -0700 | [diff] [blame] | 437 | if force_missing_bintools: |
| 438 | args += ['--force-missing-bintools', force_missing_bintools] |
Simon Glass | 0427bed | 2021-11-03 21:09:18 -0600 | [diff] [blame] | 439 | if update_fdt_in_elf: |
| 440 | args += ['--update-fdt-in-elf', update_fdt_in_elf] |
Simon Glass | 0bfa7b0 | 2018-09-14 04:57:12 -0600 | [diff] [blame] | 441 | if images: |
| 442 | for image in images: |
| 443 | args += ['-i', image] |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 444 | if extra_indirs: |
| 445 | for indir in extra_indirs: |
| 446 | args += ['-I', indir] |
Andrew Davis | 15432ea | 2023-07-22 00:14:44 +0530 | [diff] [blame] | 447 | if output_dir: |
| 448 | args += ['-O', output_dir] |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 449 | return self._DoBinman(*args) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 450 | |
| 451 | def _SetupDtb(self, fname, outfile='u-boot.dtb'): |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 452 | """Set up a new test device-tree file |
| 453 | |
| 454 | The given file is compiled and set up as the device tree to be used |
| 455 | for ths test. |
| 456 | |
| 457 | Args: |
| 458 | fname: Filename of .dts file to read |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 459 | outfile: Output filename for compiled device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 460 | |
| 461 | Returns: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 462 | Contents of device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 463 | """ |
Simon Glass | a004f29 | 2019-07-20 12:23:49 -0600 | [diff] [blame] | 464 | tmpdir = tempfile.mkdtemp(prefix='binmant.') |
| 465 | dtb = fdt_util.EnsureCompiled(self.TestFile(fname), tmpdir) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 466 | with open(dtb, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 467 | data = fd.read() |
| 468 | TestFunctional._MakeInputFile(outfile, data) |
Simon Glass | a004f29 | 2019-07-20 12:23:49 -0600 | [diff] [blame] | 469 | shutil.rmtree(tmpdir) |
Simon Glass | e0e6275 | 2018-10-01 21:12:41 -0600 | [diff] [blame] | 470 | return data |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 471 | |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 472 | def _GetDtbContentsForSpls(self, dtb_data, name): |
| 473 | """Create a version of the main DTB for SPL / TPL / VPL |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 474 | |
| 475 | For testing we don't actually have different versions of the DTB. With |
| 476 | U-Boot we normally run fdtgrep to remove unwanted nodes, but for tests |
| 477 | we don't normally have any unwanted nodes. |
| 478 | |
| 479 | We still want the DTBs for SPL and TPL to be different though, since |
| 480 | otherwise it is confusing to know which one we are looking at. So add |
| 481 | an 'spl' or 'tpl' property to the top-level node. |
Simon Glass | e9d336d | 2020-09-01 05:13:55 -0600 | [diff] [blame] | 482 | |
| 483 | Args: |
| 484 | dtb_data: dtb data to modify (this should be a value devicetree) |
| 485 | name: Name of a new property to add |
| 486 | |
| 487 | Returns: |
| 488 | New dtb data with the property added |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 489 | """ |
| 490 | dtb = fdt.Fdt.FromData(dtb_data) |
| 491 | dtb.Scan() |
| 492 | dtb.GetNode('/binman').AddZeroProp(name) |
| 493 | dtb.Sync(auto_resize=True) |
| 494 | dtb.Pack() |
| 495 | return dtb.GetContents() |
| 496 | |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 497 | def _DoReadFileDtb(self, fname, use_real_dtb=False, use_expanded=False, |
| 498 | map=False, update_dtb=False, entry_args=None, |
Simon Glass | c69d19c | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 499 | reset_dtbs=True, extra_indirs=None, threads=None): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 500 | """Run binman and return the resulting image |
| 501 | |
| 502 | This runs binman with a given test file and then reads the resulting |
| 503 | output file. It is a shortcut function since most tests need to do |
| 504 | these steps. |
| 505 | |
| 506 | Raises an assertion failure if binman returns a non-zero exit code. |
| 507 | |
| 508 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 509 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 510 | use_real_dtb: True to use the test file as the contents of |
| 511 | the u-boot-dtb entry. Normally this is not needed and the |
| 512 | test contents (the U_BOOT_DTB_DATA string) can be used. |
| 513 | But in some test we need the real contents. |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 514 | use_expanded: True to use expanded entries where available, e.g. |
| 515 | 'u-boot-expanded' instead of 'u-boot' |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 516 | map: True to output map files for the images |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 517 | update_dtb: Update the offset and size of each entry in the device |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 518 | tree before packing it into the image |
Simon Glass | e9d336d | 2020-09-01 05:13:55 -0600 | [diff] [blame] | 519 | entry_args: Dict of entry args to supply to binman |
| 520 | key: arg name |
| 521 | value: value of that arg |
| 522 | reset_dtbs: With use_real_dtb the test dtb is overwritten by this |
| 523 | function. If reset_dtbs is True, then the original test dtb |
| 524 | is written back before this function finishes |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 525 | extra_indirs: Extra input directories to add using -I |
Simon Glass | c69d19c | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 526 | threads: Number of threads to use (None for default, 0 for |
| 527 | single-threaded) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 528 | |
| 529 | Returns: |
| 530 | Tuple: |
| 531 | Resulting image contents |
| 532 | Device tree contents |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 533 | Map data showing contents of image (or None if none) |
Simon Glass | ea6922e | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 534 | Output device tree binary filename ('u-boot.dtb' path) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 535 | """ |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 536 | dtb_data = None |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 537 | # Use the compiled test file as the u-boot-dtb input |
| 538 | if use_real_dtb: |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 539 | dtb_data = self._SetupDtb(fname) |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 540 | |
| 541 | # For testing purposes, make a copy of the DT for SPL and TPL. Add |
| 542 | # a node indicating which it is, so aid verification. |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 543 | for name in ['spl', 'tpl', 'vpl']: |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 544 | dtb_fname = '%s/u-boot-%s.dtb' % (name, name) |
| 545 | outfile = os.path.join(self._indir, dtb_fname) |
| 546 | TestFunctional._MakeInputFile(dtb_fname, |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 547 | self._GetDtbContentsForSpls(dtb_data, name)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 548 | |
| 549 | try: |
Simon Glass | 53af22a | 2018-07-17 13:25:32 -0600 | [diff] [blame] | 550 | retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb, |
Simon Glass | 6cf9953 | 2020-09-01 05:13:59 -0600 | [diff] [blame] | 551 | entry_args=entry_args, use_real_dtb=use_real_dtb, |
Simon Glass | c69d19c | 2021-07-06 10:36:37 -0600 | [diff] [blame] | 552 | use_expanded=use_expanded, extra_indirs=extra_indirs, |
| 553 | threads=threads) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 554 | self.assertEqual(0, retcode) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 555 | out_dtb_fname = tools.get_output_filename('u-boot.dtb.out') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 556 | |
| 557 | # Find the (only) image, read it and return its contents |
| 558 | image = control.images['image'] |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 559 | image_fname = tools.get_output_filename('image.bin') |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 560 | self.assertTrue(os.path.exists(image_fname)) |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 561 | if map: |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 562 | map_fname = tools.get_output_filename('image.map') |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 563 | with open(map_fname) as fd: |
| 564 | map_data = fd.read() |
| 565 | else: |
| 566 | map_data = None |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 567 | with open(image_fname, 'rb') as fd: |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 568 | return fd.read(), dtb_data, map_data, out_dtb_fname |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 569 | finally: |
| 570 | # Put the test file back |
Simon Glass | 6ed45ba | 2018-09-14 04:57:24 -0600 | [diff] [blame] | 571 | if reset_dtbs and use_real_dtb: |
Simon Glass | b8ef5b6 | 2018-07-17 13:25:48 -0600 | [diff] [blame] | 572 | self._ResetDtbs() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 573 | |
Simon Glass | 3c08131 | 2019-07-08 14:25:26 -0600 | [diff] [blame] | 574 | def _DoReadFileRealDtb(self, fname): |
| 575 | """Run binman with a real .dtb file and return the resulting data |
| 576 | |
| 577 | Args: |
| 578 | fname: DT source filename to use (e.g. 082_fdt_update_all.dts) |
| 579 | |
| 580 | Returns: |
| 581 | Resulting image contents |
| 582 | """ |
| 583 | return self._DoReadFileDtb(fname, use_real_dtb=True, update_dtb=True)[0] |
| 584 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 585 | def _DoReadFile(self, fname, use_real_dtb=False): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 586 | """Helper function which discards the device-tree binary |
| 587 | |
| 588 | Args: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 589 | fname: Device-tree source filename to use (e.g. 005_simple.dts) |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 590 | use_real_dtb: True to use the test file as the contents of |
| 591 | the u-boot-dtb entry. Normally this is not needed and the |
| 592 | test contents (the U_BOOT_DTB_DATA string) can be used. |
| 593 | But in some test we need the real contents. |
Simon Glass | ea6922e | 2018-07-17 13:25:27 -0600 | [diff] [blame] | 594 | |
| 595 | Returns: |
| 596 | Resulting image contents |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 597 | """ |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 598 | return self._DoReadFileDtb(fname, use_real_dtb)[0] |
| 599 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 600 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 601 | def _MakeInputFile(cls, fname, contents): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 602 | """Create a new test input file, creating directories as needed |
| 603 | |
| 604 | Args: |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 605 | fname: Filename to create |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 606 | contents: File contents to write in to the file |
| 607 | Returns: |
| 608 | Full pathname of file created |
| 609 | """ |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 610 | pathname = os.path.join(cls._indir, fname) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 611 | dirname = os.path.dirname(pathname) |
| 612 | if dirname and not os.path.exists(dirname): |
| 613 | os.makedirs(dirname) |
| 614 | with open(pathname, 'wb') as fd: |
| 615 | fd.write(contents) |
| 616 | return pathname |
| 617 | |
| 618 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 619 | def _MakeInputDir(cls, dirname): |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 620 | """Create a new test input directory, creating directories as needed |
| 621 | |
| 622 | Args: |
| 623 | dirname: Directory name to create |
| 624 | |
| 625 | Returns: |
| 626 | Full pathname of directory created |
| 627 | """ |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 628 | pathname = os.path.join(cls._indir, dirname) |
Simon Glass | 0ef87aa | 2018-07-17 13:25:44 -0600 | [diff] [blame] | 629 | if not os.path.exists(pathname): |
| 630 | os.makedirs(pathname) |
| 631 | return pathname |
| 632 | |
| 633 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 634 | def _SetupSplElf(cls, src_fname='bss_data'): |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 635 | """Set up an ELF file with a '_dt_ucode_base_size' symbol |
| 636 | |
| 637 | Args: |
| 638 | Filename of ELF file to use as SPL |
| 639 | """ |
Simon Glass | c9a0b27 | 2019-08-24 07:22:59 -0600 | [diff] [blame] | 640 | TestFunctional._MakeInputFile('spl/u-boot-spl', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 641 | tools.read_file(cls.ElfTestFile(src_fname))) |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 642 | |
| 643 | @classmethod |
Simon Glass | 2090f1e | 2019-08-24 07:23:00 -0600 | [diff] [blame] | 644 | def _SetupTplElf(cls, src_fname='bss_data'): |
| 645 | """Set up an ELF file with a '_dt_ucode_base_size' symbol |
| 646 | |
| 647 | Args: |
| 648 | Filename of ELF file to use as TPL |
| 649 | """ |
| 650 | TestFunctional._MakeInputFile('tpl/u-boot-tpl', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 651 | tools.read_file(cls.ElfTestFile(src_fname))) |
Simon Glass | 2090f1e | 2019-08-24 07:23:00 -0600 | [diff] [blame] | 652 | |
| 653 | @classmethod |
Simon Glass | 6ad2452 | 2022-02-28 07:16:54 -0700 | [diff] [blame] | 654 | def _SetupVplElf(cls, src_fname='bss_data'): |
| 655 | """Set up an ELF file with a '_dt_ucode_base_size' symbol |
| 656 | |
| 657 | Args: |
| 658 | Filename of ELF file to use as VPL |
| 659 | """ |
| 660 | TestFunctional._MakeInputFile('vpl/u-boot-vpl', |
| 661 | tools.read_file(cls.ElfTestFile(src_fname))) |
| 662 | |
| 663 | @classmethod |
Lukas Funke | 8c1fbd1 | 2023-07-18 13:53:13 +0200 | [diff] [blame] | 664 | def _SetupPmuFwlElf(cls, src_fname='bss_data'): |
| 665 | """Set up an ELF file with a '_dt_ucode_base_size' symbol |
| 666 | |
| 667 | Args: |
| 668 | Filename of ELF file to use as VPL |
| 669 | """ |
| 670 | TestFunctional._MakeInputFile('pmu-firmware.elf', |
| 671 | tools.read_file(cls.ElfTestFile(src_fname))) |
| 672 | |
| 673 | @classmethod |
Simon Glass | 0ba4b3d | 2020-07-09 18:39:41 -0600 | [diff] [blame] | 674 | def _SetupDescriptor(cls): |
| 675 | with open(cls.TestFile('descriptor.bin'), 'rb') as fd: |
| 676 | TestFunctional._MakeInputFile('descriptor.bin', fd.read()) |
| 677 | |
| 678 | @classmethod |
Simon Glass | b986b3b | 2019-08-24 07:22:43 -0600 | [diff] [blame] | 679 | def TestFile(cls, fname): |
| 680 | return os.path.join(cls._binman_dir, 'test', fname) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 681 | |
Simon Glass | 53e22bf | 2019-08-24 07:22:53 -0600 | [diff] [blame] | 682 | @classmethod |
| 683 | def ElfTestFile(cls, fname): |
| 684 | return os.path.join(cls._elf_testdir, fname) |
| 685 | |
Simon Glass | 2f80c5e | 2023-01-07 14:07:14 -0700 | [diff] [blame] | 686 | @classmethod |
| 687 | def make_tee_bin(cls, fname, paged_sz=0, extra_data=b''): |
| 688 | init_sz, start_hi, start_lo, dummy = (len(U_BOOT_DATA), 0, TEE_ADDR, 0) |
| 689 | data = b'OPTE\x01xxx' + struct.pack('<5I', init_sz, start_hi, start_lo, |
| 690 | dummy, paged_sz) + U_BOOT_DATA |
| 691 | data += extra_data |
| 692 | TestFunctional._MakeInputFile(fname, data) |
| 693 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 694 | def AssertInList(self, grep_list, target): |
| 695 | """Assert that at least one of a list of things is in a target |
| 696 | |
| 697 | Args: |
| 698 | grep_list: List of strings to check |
| 699 | target: Target string |
| 700 | """ |
| 701 | for grep in grep_list: |
| 702 | if grep in target: |
| 703 | return |
Simon Glass | 1fc62de | 2019-05-17 22:00:50 -0600 | [diff] [blame] | 704 | self.fail("Error: '%s' not found in '%s'" % (grep_list, target)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 705 | |
| 706 | def CheckNoGaps(self, entries): |
| 707 | """Check that all entries fit together without gaps |
| 708 | |
| 709 | Args: |
| 710 | entries: List of entries to check |
| 711 | """ |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 712 | offset = 0 |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 713 | for entry in entries.values(): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 714 | self.assertEqual(offset, entry.offset) |
| 715 | offset += entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 716 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 717 | def GetFdtLen(self, dtb): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 718 | """Get the totalsize field from a device-tree binary |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 719 | |
| 720 | Args: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 721 | dtb: Device-tree binary contents |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 722 | |
| 723 | Returns: |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 724 | Total size of device-tree binary, from the header |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 725 | """ |
| 726 | return struct.unpack('>L', dtb[4:8])[0] |
| 727 | |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 728 | def _GetPropTree(self, dtb, prop_names, prefix='/binman/'): |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 729 | def AddNode(node, path): |
| 730 | if node.name != '/': |
| 731 | path += '/' + node.name |
Simon Glass | 086cec9 | 2019-07-08 14:25:27 -0600 | [diff] [blame] | 732 | for prop in node.props.values(): |
| 733 | if prop.name in prop_names: |
| 734 | prop_path = path + ':' + prop.name |
| 735 | tree[prop_path[len(prefix):]] = fdt_util.fdt32_to_cpu( |
| 736 | prop.value) |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 737 | for subnode in node.subnodes: |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 738 | AddNode(subnode, path) |
| 739 | |
| 740 | tree = {} |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 741 | AddNode(dtb.GetRoot(), '') |
| 742 | return tree |
| 743 | |
Ivan Mikhaylov | 5b34efe | 2023-03-08 01:13:40 +0000 | [diff] [blame] | 744 | def _CheckSign(self, fit, key): |
| 745 | try: |
| 746 | tools.run('fit_check_sign', '-k', key, '-f', fit) |
| 747 | except: |
| 748 | self.fail('Expected signed FIT container') |
| 749 | return False |
| 750 | return True |
| 751 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 752 | def testRun(self): |
| 753 | """Test a basic run with valid args""" |
| 754 | result = self._RunBinman('-h') |
| 755 | |
| 756 | def testFullHelp(self): |
| 757 | """Test that the full help is displayed with -H""" |
| 758 | result = self._RunBinman('-H') |
Simon Glass | 61adb2d | 2021-03-18 20:25:13 +1300 | [diff] [blame] | 759 | help_file = os.path.join(self._binman_dir, 'README.rst') |
Tom Rini | 3759df0 | 2018-01-16 15:29:50 -0500 | [diff] [blame] | 760 | # Remove possible extraneous strings |
| 761 | extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n' |
| 762 | gothelp = result.stdout.replace(extra, '') |
| 763 | self.assertEqual(len(gothelp), os.path.getsize(help_file)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 764 | self.assertEqual(0, len(result.stderr)) |
| 765 | self.assertEqual(0, result.return_code) |
| 766 | |
| 767 | def testFullHelpInternal(self): |
| 768 | """Test that the full help is displayed with -H""" |
| 769 | try: |
| 770 | command.test_result = command.CommandResult() |
| 771 | result = self._DoBinman('-H') |
Simon Glass | 61adb2d | 2021-03-18 20:25:13 +1300 | [diff] [blame] | 772 | help_file = os.path.join(self._binman_dir, 'README.rst') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 773 | finally: |
| 774 | command.test_result = None |
| 775 | |
| 776 | def testHelp(self): |
| 777 | """Test that the basic help is displayed with -h""" |
| 778 | result = self._RunBinman('-h') |
| 779 | self.assertTrue(len(result.stdout) > 200) |
| 780 | self.assertEqual(0, len(result.stderr)) |
| 781 | self.assertEqual(0, result.return_code) |
| 782 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 783 | def testBoard(self): |
| 784 | """Test that we can run it with a specific board""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 785 | self._SetupDtb('005_simple.dts', 'sandbox/u-boot.dtb') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 786 | TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA) |
Simon Glass | 63aeaeb | 2021-03-18 20:25:05 +1300 | [diff] [blame] | 787 | result = self._DoBinman('build', '-n', '-b', 'sandbox') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 788 | self.assertEqual(0, result) |
| 789 | |
| 790 | def testNeedBoard(self): |
| 791 | """Test that we get an error when no board ius supplied""" |
| 792 | with self.assertRaises(ValueError) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 793 | result = self._DoBinman('build') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 794 | self.assertIn("Must provide a board to process (use -b <board>)", |
| 795 | str(e.exception)) |
| 796 | |
| 797 | def testMissingDt(self): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 798 | """Test that an invalid device-tree file generates an error""" |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 799 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 800 | self._RunBinman('build', '-d', 'missing_file') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 801 | # We get one error from libfdt, and a different one from fdtget. |
| 802 | self.AssertInList(["Couldn't open blob from 'missing_file'", |
| 803 | 'No such file or directory'], str(e.exception)) |
| 804 | |
| 805 | def testBrokenDt(self): |
Simon Glass | 7ae5f31 | 2018-06-01 09:38:19 -0600 | [diff] [blame] | 806 | """Test that an invalid device-tree source file generates an error |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 807 | |
| 808 | Since this is a source file it should be compiled and the error |
| 809 | will come from the device-tree compiler (dtc). |
| 810 | """ |
| 811 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 812 | self._RunBinman('build', '-d', self.TestFile('001_invalid.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 813 | self.assertIn("FATAL ERROR: Unable to parse input tree", |
| 814 | str(e.exception)) |
| 815 | |
| 816 | def testMissingNode(self): |
| 817 | """Test that a device tree without a 'binman' node generates an error""" |
| 818 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 819 | self._DoBinman('build', '-d', self.TestFile('002_missing_node.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 820 | self.assertIn("does not have a 'binman' node", str(e.exception)) |
| 821 | |
| 822 | def testEmpty(self): |
| 823 | """Test that an empty binman node works OK (i.e. does nothing)""" |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 824 | result = self._RunBinman('build', '-d', self.TestFile('003_empty.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 825 | self.assertEqual(0, len(result.stderr)) |
| 826 | self.assertEqual(0, result.return_code) |
| 827 | |
| 828 | def testInvalidEntry(self): |
| 829 | """Test that an invalid entry is flagged""" |
| 830 | with self.assertRaises(Exception) as e: |
Simon Glass | 53cd5d9 | 2019-07-08 14:25:29 -0600 | [diff] [blame] | 831 | result = self._RunBinman('build', '-d', |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 832 | self.TestFile('004_invalid_entry.dts')) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 833 | self.assertIn("Unknown entry type 'not-a-valid-type' in node " |
| 834 | "'/binman/not-a-valid-type'", str(e.exception)) |
| 835 | |
| 836 | def testSimple(self): |
| 837 | """Test a simple binman with a single file""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 838 | data = self._DoReadFile('005_simple.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 839 | self.assertEqual(U_BOOT_DATA, data) |
| 840 | |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 841 | def testSimpleDebug(self): |
| 842 | """Test a simple binman run with debugging enabled""" |
Simon Glass | e2705fa | 2019-07-08 14:25:53 -0600 | [diff] [blame] | 843 | self._DoTestFile('005_simple.dts', debug=True) |
Simon Glass | 7fe9173 | 2017-11-13 18:55:00 -0700 | [diff] [blame] | 844 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 845 | def testDual(self): |
| 846 | """Test that we can handle creating two images |
| 847 | |
| 848 | This also tests image padding. |
| 849 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 850 | retcode = self._DoTestFile('006_dual_image.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 851 | self.assertEqual(0, retcode) |
| 852 | |
| 853 | image = control.images['image1'] |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 854 | self.assertEqual(len(U_BOOT_DATA), image.size) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 855 | fname = tools.get_output_filename('image1.bin') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 856 | self.assertTrue(os.path.exists(fname)) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 857 | with open(fname, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 858 | data = fd.read() |
| 859 | self.assertEqual(U_BOOT_DATA, data) |
| 860 | |
| 861 | image = control.images['image2'] |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 862 | self.assertEqual(3 + len(U_BOOT_DATA) + 5, image.size) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 863 | fname = tools.get_output_filename('image2.bin') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 864 | self.assertTrue(os.path.exists(fname)) |
Simon Glass | 1d0ebf7 | 2019-05-14 15:53:42 -0600 | [diff] [blame] | 865 | with open(fname, 'rb') as fd: |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 866 | data = fd.read() |
| 867 | self.assertEqual(U_BOOT_DATA, data[3:7]) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 868 | self.assertEqual(tools.get_bytes(0, 3), data[:3]) |
| 869 | self.assertEqual(tools.get_bytes(0, 5), data[7:]) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 870 | |
| 871 | def testBadAlign(self): |
| 872 | """Test that an invalid alignment value is detected""" |
| 873 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 874 | self._DoTestFile('007_bad_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 875 | self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power " |
| 876 | "of two", str(e.exception)) |
| 877 | |
| 878 | def testPackSimple(self): |
| 879 | """Test that packing works as expected""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 880 | retcode = self._DoTestFile('008_pack.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 881 | self.assertEqual(0, retcode) |
| 882 | self.assertIn('image', control.images) |
| 883 | image = control.images['image'] |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 884 | entries = image.GetEntries() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 885 | self.assertEqual(5, len(entries)) |
| 886 | |
| 887 | # First u-boot |
| 888 | self.assertIn('u-boot', entries) |
| 889 | entry = entries['u-boot'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 890 | self.assertEqual(0, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 891 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 892 | |
| 893 | # Second u-boot, aligned to 16-byte boundary |
| 894 | self.assertIn('u-boot-align', entries) |
| 895 | entry = entries['u-boot-align'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 896 | self.assertEqual(16, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 897 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 898 | |
| 899 | # Third u-boot, size 23 bytes |
| 900 | self.assertIn('u-boot-size', entries) |
| 901 | entry = entries['u-boot-size'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 902 | self.assertEqual(20, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 903 | self.assertEqual(len(U_BOOT_DATA), entry.contents_size) |
| 904 | self.assertEqual(23, entry.size) |
| 905 | |
| 906 | # Fourth u-boot, placed immediate after the above |
| 907 | self.assertIn('u-boot-next', entries) |
| 908 | entry = entries['u-boot-next'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 909 | self.assertEqual(43, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 910 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 911 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 912 | # Fifth u-boot, placed at a fixed offset |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 913 | self.assertIn('u-boot-fixed', entries) |
| 914 | entry = entries['u-boot-fixed'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 915 | self.assertEqual(61, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 916 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 917 | |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 918 | self.assertEqual(65, image.size) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 919 | |
| 920 | def testPackExtra(self): |
| 921 | """Test that extra packing feature works as expected""" |
Simon Glass | 4eec34c | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 922 | data, _, _, out_dtb_fname = self._DoReadFileDtb('009_pack_extra.dts', |
| 923 | update_dtb=True) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 924 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 925 | self.assertIn('image', control.images) |
| 926 | image = control.images['image'] |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 927 | entries = image.GetEntries() |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 928 | self.assertEqual(6, len(entries)) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 929 | |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 930 | # First u-boot with padding before and after (included in minimum size) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 931 | self.assertIn('u-boot', entries) |
| 932 | entry = entries['u-boot'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 933 | self.assertEqual(0, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 934 | self.assertEqual(3, entry.pad_before) |
| 935 | self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size) |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 936 | self.assertEqual(U_BOOT_DATA, entry.data) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 937 | self.assertEqual(tools.get_bytes(0, 3) + U_BOOT_DATA + |
| 938 | tools.get_bytes(0, 5), data[:entry.size]) |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 939 | pos = entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 940 | |
| 941 | # Second u-boot has an aligned size, but it has no effect |
| 942 | self.assertIn('u-boot-align-size-nop', entries) |
| 943 | entry = entries['u-boot-align-size-nop'] |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 944 | self.assertEqual(pos, entry.offset) |
| 945 | self.assertEqual(len(U_BOOT_DATA), entry.size) |
| 946 | self.assertEqual(U_BOOT_DATA, entry.data) |
| 947 | self.assertEqual(U_BOOT_DATA, data[pos:pos + entry.size]) |
| 948 | pos += entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 949 | |
| 950 | # Third u-boot has an aligned size too |
| 951 | self.assertIn('u-boot-align-size', entries) |
| 952 | entry = entries['u-boot-align-size'] |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 953 | self.assertEqual(pos, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 954 | self.assertEqual(32, entry.size) |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 955 | self.assertEqual(U_BOOT_DATA, entry.data) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 956 | self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 32 - len(U_BOOT_DATA)), |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 957 | data[pos:pos + entry.size]) |
| 958 | pos += entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 959 | |
| 960 | # Fourth u-boot has an aligned end |
| 961 | self.assertIn('u-boot-align-end', entries) |
| 962 | entry = entries['u-boot-align-end'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 963 | self.assertEqual(48, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 964 | self.assertEqual(16, entry.size) |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 965 | self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)]) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 966 | self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 16 - len(U_BOOT_DATA)), |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 967 | data[pos:pos + entry.size]) |
| 968 | pos += entry.size |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 969 | |
| 970 | # Fifth u-boot immediately afterwards |
| 971 | self.assertIn('u-boot-align-both', entries) |
| 972 | entry = entries['u-boot-align-both'] |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 973 | self.assertEqual(64, entry.offset) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 974 | self.assertEqual(64, entry.size) |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 975 | self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)]) |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 976 | self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 64 - len(U_BOOT_DATA)), |
Simon Glass | ef439ed | 2020-10-26 17:40:08 -0600 | [diff] [blame] | 977 | data[pos:pos + entry.size]) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 978 | |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 979 | # Sixth u-boot with both minimum size and aligned size |
| 980 | self.assertIn('u-boot-min-size', entries) |
| 981 | entry = entries['u-boot-min-size'] |
| 982 | self.assertEqual(128, entry.offset) |
| 983 | self.assertEqual(32, entry.size) |
| 984 | self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)]) |
| 985 | self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 32 - len(U_BOOT_DATA)), |
| 986 | data[pos:pos + entry.size]) |
| 987 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 988 | self.CheckNoGaps(entries) |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 989 | self.assertEqual(160, image.size) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 990 | |
Simon Glass | 4eec34c | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 991 | dtb = fdt.Fdt(out_dtb_fname) |
| 992 | dtb.Scan() |
| 993 | props = self._GetPropTree(dtb, ['size', 'offset', 'image-pos']) |
| 994 | expected = { |
| 995 | 'image-pos': 0, |
| 996 | 'offset': 0, |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 997 | 'size': 160, |
Simon Glass | 4eec34c | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 998 | |
| 999 | 'u-boot:image-pos': 0, |
| 1000 | 'u-boot:offset': 0, |
| 1001 | 'u-boot:size': 3 + 5 + len(U_BOOT_DATA), |
| 1002 | |
| 1003 | 'u-boot-align-size-nop:image-pos': 12, |
| 1004 | 'u-boot-align-size-nop:offset': 12, |
| 1005 | 'u-boot-align-size-nop:size': 4, |
| 1006 | |
| 1007 | 'u-boot-align-size:image-pos': 16, |
| 1008 | 'u-boot-align-size:offset': 16, |
| 1009 | 'u-boot-align-size:size': 32, |
| 1010 | |
| 1011 | 'u-boot-align-end:image-pos': 48, |
| 1012 | 'u-boot-align-end:offset': 48, |
| 1013 | 'u-boot-align-end:size': 16, |
| 1014 | |
| 1015 | 'u-boot-align-both:image-pos': 64, |
| 1016 | 'u-boot-align-both:offset': 64, |
| 1017 | 'u-boot-align-both:size': 64, |
Samuel Holland | b01ae03 | 2023-01-21 17:25:16 -0600 | [diff] [blame] | 1018 | |
| 1019 | 'u-boot-min-size:image-pos': 128, |
| 1020 | 'u-boot-min-size:offset': 128, |
| 1021 | 'u-boot-min-size:size': 32, |
Simon Glass | 4eec34c | 2020-10-26 17:40:10 -0600 | [diff] [blame] | 1022 | } |
| 1023 | self.assertEqual(expected, props) |
| 1024 | |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1025 | def testPackAlignPowerOf2(self): |
| 1026 | """Test that invalid entry alignment is detected""" |
| 1027 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1028 | self._DoTestFile('010_pack_align_power2.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1029 | self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power " |
| 1030 | "of two", str(e.exception)) |
| 1031 | |
| 1032 | def testPackAlignSizePowerOf2(self): |
| 1033 | """Test that invalid entry size alignment is detected""" |
| 1034 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1035 | self._DoTestFile('011_pack_align_size_power2.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1036 | self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a " |
| 1037 | "power of two", str(e.exception)) |
| 1038 | |
| 1039 | def testPackInvalidAlign(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1040 | """Test detection of an offset that does not match its alignment""" |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1041 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1042 | self._DoTestFile('012_pack_inv_align.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1043 | self.assertIn("Node '/binman/u-boot': Offset 0x5 (5) does not match " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1044 | "align 0x4 (4)", str(e.exception)) |
| 1045 | |
| 1046 | def testPackInvalidSizeAlign(self): |
| 1047 | """Test that invalid entry size alignment is detected""" |
| 1048 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1049 | self._DoTestFile('013_pack_inv_size_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1050 | self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match " |
| 1051 | "align-size 0x4 (4)", str(e.exception)) |
| 1052 | |
| 1053 | def testPackOverlap(self): |
| 1054 | """Test that overlapping regions are detected""" |
| 1055 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1056 | self._DoTestFile('014_pack_overlap.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1057 | self.assertIn("Node '/binman/u-boot-align': Offset 0x3 (3) overlaps " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1058 | "with previous entry '/binman/u-boot' ending at 0x4 (4)", |
| 1059 | str(e.exception)) |
| 1060 | |
| 1061 | def testPackEntryOverflow(self): |
| 1062 | """Test that entries that overflow their size are detected""" |
| 1063 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1064 | self._DoTestFile('015_pack_overflow.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1065 | self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) " |
| 1066 | "but entry size is 0x3 (3)", str(e.exception)) |
| 1067 | |
| 1068 | def testPackImageOverflow(self): |
| 1069 | """Test that entries which overflow the image size are detected""" |
| 1070 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1071 | self._DoTestFile('016_pack_image_overflow.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 1072 | self.assertIn("Section '/binman': contents size 0x4 (4) exceeds section " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1073 | "size 0x3 (3)", str(e.exception)) |
| 1074 | |
| 1075 | def testPackImageSize(self): |
| 1076 | """Test that the image size can be set""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1077 | retcode = self._DoTestFile('017_pack_image_size.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1078 | self.assertEqual(0, retcode) |
| 1079 | self.assertIn('image', control.images) |
| 1080 | image = control.images['image'] |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1081 | self.assertEqual(7, image.size) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1082 | |
| 1083 | def testPackImageSizeAlign(self): |
| 1084 | """Test that image size alignemnt works as expected""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1085 | retcode = self._DoTestFile('018_pack_image_align.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1086 | self.assertEqual(0, retcode) |
| 1087 | self.assertIn('image', control.images) |
| 1088 | image = control.images['image'] |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1089 | self.assertEqual(16, image.size) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1090 | |
| 1091 | def testPackInvalidImageAlign(self): |
| 1092 | """Test that invalid image alignment is detected""" |
| 1093 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1094 | self._DoTestFile('019_pack_inv_image_align.dts') |
Simon Glass | 8f1da50 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 1095 | self.assertIn("Section '/binman': Size 0x7 (7) does not match " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1096 | "align-size 0x8 (8)", str(e.exception)) |
| 1097 | |
Simon Glass | 8d2ef3e | 2022-02-11 13:23:21 -0700 | [diff] [blame] | 1098 | def testPackAlignPowerOf2Inv(self): |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1099 | """Test that invalid image alignment is detected""" |
| 1100 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1101 | self._DoTestFile('020_pack_inv_image_align_power2.dts') |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1102 | self.assertIn("Image '/binman': Alignment size 131 must be a power of " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1103 | "two", str(e.exception)) |
| 1104 | |
| 1105 | def testImagePadByte(self): |
| 1106 | """Test that the image pad byte can be specified""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1107 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1108 | data = self._DoReadFile('021_image_pad.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1109 | self.assertEqual(U_BOOT_SPL_DATA + tools.get_bytes(0xff, 1) + |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1110 | U_BOOT_DATA, data) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1111 | |
| 1112 | def testImageName(self): |
| 1113 | """Test that image files can be named""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1114 | retcode = self._DoTestFile('022_image_name.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1115 | self.assertEqual(0, retcode) |
| 1116 | image = control.images['image1'] |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1117 | fname = tools.get_output_filename('test-name') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1118 | self.assertTrue(os.path.exists(fname)) |
| 1119 | |
| 1120 | image = control.images['image2'] |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1121 | fname = tools.get_output_filename('test-name.xx') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1122 | self.assertTrue(os.path.exists(fname)) |
| 1123 | |
| 1124 | def testBlobFilename(self): |
| 1125 | """Test that generic blobs can be provided by filename""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1126 | data = self._DoReadFile('023_blob.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1127 | self.assertEqual(BLOB_DATA, data) |
| 1128 | |
| 1129 | def testPackSorted(self): |
| 1130 | """Test that entries can be sorted""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1131 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1132 | data = self._DoReadFile('024_sorted.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1133 | self.assertEqual(tools.get_bytes(0, 1) + U_BOOT_SPL_DATA + |
| 1134 | tools.get_bytes(0, 2) + U_BOOT_DATA, data) |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1135 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1136 | def testPackZeroOffset(self): |
| 1137 | """Test that an entry at offset 0 is not given a new offset""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1138 | self._SetupSplElf() |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1139 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1140 | self._DoTestFile('025_pack_zero_size.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1141 | self.assertIn("Node '/binman/u-boot-spl': Offset 0x0 (0) overlaps " |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1142 | "with previous entry '/binman/u-boot' ending at 0x4 (4)", |
| 1143 | str(e.exception)) |
| 1144 | |
| 1145 | def testPackUbootDtb(self): |
| 1146 | """Test that a device tree can be added to U-Boot""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1147 | data = self._DoReadFile('026_pack_u_boot_dtb.dts') |
Simon Glass | 4f44304 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1148 | self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1149 | |
| 1150 | def testPackX86RomNoSize(self): |
| 1151 | """Test that the end-at-4gb property requires a size property""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1152 | self._SetupSplElf() |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1153 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1154 | self._DoTestFile('027_pack_4gb_no_size.dts') |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1155 | self.assertIn("Image '/binman': Section size must be provided when " |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1156 | "using end-at-4gb", str(e.exception)) |
| 1157 | |
Jagdish Gediya | 94b57db | 2018-09-03 21:35:07 +0530 | [diff] [blame] | 1158 | def test4gbAndSkipAtStartTogether(self): |
| 1159 | """Test that the end-at-4gb and skip-at-size property can't be used |
| 1160 | together""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1161 | self._SetupSplElf() |
Jagdish Gediya | 94b57db | 2018-09-03 21:35:07 +0530 | [diff] [blame] | 1162 | with self.assertRaises(ValueError) as e: |
Simon Glass | dfdd2b6 | 2019-08-24 07:23:02 -0600 | [diff] [blame] | 1163 | self._DoTestFile('098_4gb_and_skip_at_start_together.dts') |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1164 | self.assertIn("Image '/binman': Provide either 'end-at-4gb' or " |
Jagdish Gediya | 94b57db | 2018-09-03 21:35:07 +0530 | [diff] [blame] | 1165 | "'skip-at-start'", str(e.exception)) |
| 1166 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1167 | def testPackX86RomOutside(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1168 | """Test that the end-at-4gb property checks for offset boundaries""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1169 | self._SetupSplElf() |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1170 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1171 | self._DoTestFile('028_pack_4gb_outside.dts') |
Simon Glass | e6bed4f | 2020-10-26 17:40:05 -0600 | [diff] [blame] | 1172 | self.assertIn("Node '/binman/u-boot': Offset 0x0 (0) size 0x4 (4) " |
| 1173 | "is outside the section '/binman' starting at " |
| 1174 | '0xffffffe0 (4294967264) of size 0x20 (32)', |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1175 | str(e.exception)) |
| 1176 | |
| 1177 | def testPackX86Rom(self): |
| 1178 | """Test that a basic x86 ROM can be created""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1179 | self._SetupSplElf() |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1180 | data = self._DoReadFile('029_x86_rom.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1181 | self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 3) + U_BOOT_SPL_DATA + |
| 1182 | tools.get_bytes(0, 2), data) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1183 | |
| 1184 | def testPackX86RomMeNoDesc(self): |
| 1185 | """Test that an invalid Intel descriptor entry is detected""" |
Simon Glass | 0ba4b3d | 2020-07-09 18:39:41 -0600 | [diff] [blame] | 1186 | try: |
Simon Glass | 52b10dd | 2020-07-25 15:11:19 -0600 | [diff] [blame] | 1187 | TestFunctional._MakeInputFile('descriptor-empty.bin', b'') |
Simon Glass | 0ba4b3d | 2020-07-09 18:39:41 -0600 | [diff] [blame] | 1188 | with self.assertRaises(ValueError) as e: |
Simon Glass | 52b10dd | 2020-07-25 15:11:19 -0600 | [diff] [blame] | 1189 | self._DoTestFile('163_x86_rom_me_empty.dts') |
Simon Glass | 0ba4b3d | 2020-07-09 18:39:41 -0600 | [diff] [blame] | 1190 | self.assertIn("Node '/binman/intel-descriptor': Cannot find Intel Flash Descriptor (FD) signature", |
| 1191 | str(e.exception)) |
| 1192 | finally: |
| 1193 | self._SetupDescriptor() |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1194 | |
| 1195 | def testPackX86RomBadDesc(self): |
| 1196 | """Test that the Intel requires a descriptor entry""" |
| 1197 | with self.assertRaises(ValueError) as e: |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1198 | self._DoTestFile('030_x86_rom_me_no_desc.dts') |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1199 | self.assertIn("Node '/binman/intel-me': No offset set with " |
| 1200 | "offset-unset: should another entry provide this correct " |
| 1201 | "offset?", str(e.exception)) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1202 | |
| 1203 | def testPackX86RomMe(self): |
| 1204 | """Test that an x86 ROM with an ME region can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1205 | data = self._DoReadFile('031_x86_rom_me.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1206 | expected_desc = tools.read_file(self.TestFile('descriptor.bin')) |
Simon Glass | c5ac138 | 2019-07-08 13:18:54 -0600 | [diff] [blame] | 1207 | if data[:0x1000] != expected_desc: |
| 1208 | self.fail('Expected descriptor binary at start of image') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1209 | self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)]) |
| 1210 | |
| 1211 | def testPackVga(self): |
| 1212 | """Test that an image with a VGA binary can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1213 | data = self._DoReadFile('032_intel_vga.dts') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1214 | self.assertEqual(VGA_DATA, data[:len(VGA_DATA)]) |
| 1215 | |
| 1216 | def testPackStart16(self): |
| 1217 | """Test that an image with an x86 start16 region can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1218 | data = self._DoReadFile('033_x86_start16.dts') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1219 | self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) |
| 1220 | |
Jagdish Gediya | 9d368f3 | 2018-09-03 21:35:08 +0530 | [diff] [blame] | 1221 | def testPackPowerpcMpc85xxBootpgResetvec(self): |
| 1222 | """Test that an image with powerpc-mpc85xx-bootpg-resetvec can be |
| 1223 | created""" |
Simon Glass | dfdd2b6 | 2019-08-24 07:23:02 -0600 | [diff] [blame] | 1224 | data = self._DoReadFile('150_powerpc_mpc85xx_bootpg_resetvec.dts') |
Jagdish Gediya | 9d368f3 | 2018-09-03 21:35:08 +0530 | [diff] [blame] | 1225 | self.assertEqual(PPC_MPC85XX_BR_DATA, data[:len(PPC_MPC85XX_BR_DATA)]) |
| 1226 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1227 | def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False): |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 1228 | """Handle running a test for insertion of microcode |
| 1229 | |
| 1230 | Args: |
| 1231 | dts_fname: Name of test .dts file |
| 1232 | nodtb_data: Data that we expect in the first section |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1233 | ucode_second: True if the microsecond entry is second instead of |
| 1234 | third |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 1235 | |
| 1236 | Returns: |
| 1237 | Tuple: |
| 1238 | Contents of first region (U-Boot or SPL) |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1239 | Offset and size components of microcode pointer, as inserted |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 1240 | in the above (two 4-byte words) |
| 1241 | """ |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1242 | data = self._DoReadFile(dts_fname, True) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1243 | |
| 1244 | # Now check the device tree has no microcode |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1245 | if ucode_second: |
| 1246 | ucode_content = data[len(nodtb_data):] |
| 1247 | ucode_pos = len(nodtb_data) |
| 1248 | dtb_with_ucode = ucode_content[16:] |
| 1249 | fdt_len = self.GetFdtLen(dtb_with_ucode) |
| 1250 | else: |
| 1251 | dtb_with_ucode = data[len(nodtb_data):] |
| 1252 | fdt_len = self.GetFdtLen(dtb_with_ucode) |
| 1253 | ucode_content = dtb_with_ucode[fdt_len:] |
| 1254 | ucode_pos = len(nodtb_data) + fdt_len |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1255 | fname = tools.get_output_filename('test.dtb') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1256 | with open(fname, 'wb') as fd: |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 1257 | fd.write(dtb_with_ucode) |
Simon Glass | ec3f378 | 2017-05-27 07:38:29 -0600 | [diff] [blame] | 1258 | dtb = fdt.FdtScan(fname) |
| 1259 | ucode = dtb.GetNode('/microcode') |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1260 | self.assertTrue(ucode) |
| 1261 | for node in ucode.subnodes: |
| 1262 | self.assertFalse(node.props.get('data')) |
| 1263 | |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1264 | # Check that the microcode appears immediately after the Fdt |
| 1265 | # This matches the concatenation of the data properties in |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 1266 | # the /microcode/update@xxx nodes in 34_x86_ucode.dts. |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1267 | ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, |
| 1268 | 0x78235609) |
Simon Glass | adc5701 | 2018-07-06 10:27:16 -0600 | [diff] [blame] | 1269 | self.assertEqual(ucode_data, ucode_content[:len(ucode_data)]) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1270 | |
| 1271 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1272 | # expected offset and size |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1273 | pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, |
| 1274 | len(ucode_data)) |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1275 | u_boot = data[:len(nodtb_data)] |
| 1276 | return u_boot, pos_and_size |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1277 | |
| 1278 | def testPackUbootMicrocode(self): |
| 1279 | """Test that x86 microcode can be handled correctly |
| 1280 | |
| 1281 | We expect to see the following in the image, in order: |
| 1282 | u-boot-nodtb.bin with a microcode pointer inserted at the correct |
| 1283 | place |
| 1284 | u-boot.dtb with the microcode removed |
| 1285 | the microcode |
| 1286 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1287 | first, pos_and_size = self._RunMicrocodeTest('034_x86_ucode.dts', |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1288 | U_BOOT_NODTB_DATA) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1289 | self.assertEqual(b'nodtb with microcode' + pos_and_size + |
| 1290 | b' somewhere in here', first) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1291 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1292 | def _RunPackUbootSingleMicrocode(self): |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1293 | """Test that x86 microcode can be handled correctly |
| 1294 | |
| 1295 | We expect to see the following in the image, in order: |
| 1296 | u-boot-nodtb.bin with a microcode pointer inserted at the correct |
| 1297 | place |
| 1298 | u-boot.dtb with the microcode |
| 1299 | an empty microcode region |
| 1300 | """ |
| 1301 | # We need the libfdt library to run this test since only that allows |
| 1302 | # finding the offset of a property. This is required by |
| 1303 | # Entry_u_boot_dtb_with_ucode.ObtainContents(). |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1304 | data = self._DoReadFile('035_x86_single_ucode.dts', True) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1305 | |
| 1306 | second = data[len(U_BOOT_NODTB_DATA):] |
| 1307 | |
| 1308 | fdt_len = self.GetFdtLen(second) |
| 1309 | third = second[fdt_len:] |
| 1310 | second = second[:fdt_len] |
| 1311 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1312 | ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) |
| 1313 | self.assertIn(ucode_data, second) |
| 1314 | ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) |
Simon Glass | e0ff855 | 2016-11-25 20:15:53 -0700 | [diff] [blame] | 1315 | |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1316 | # Check that the microcode pointer was inserted. It should match the |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1317 | # expected offset and size |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1318 | pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, |
| 1319 | len(ucode_data)) |
| 1320 | first = data[:len(U_BOOT_NODTB_DATA)] |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1321 | self.assertEqual(b'nodtb with microcode' + pos_and_size + |
| 1322 | b' somewhere in here', first) |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 1323 | |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1324 | def testPackUbootSingleMicrocode(self): |
| 1325 | """Test that x86 microcode can be handled correctly with fdt_normal. |
| 1326 | """ |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1327 | self._RunPackUbootSingleMicrocode() |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1328 | |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 1329 | def testUBootImg(self): |
| 1330 | """Test that u-boot.img can be put in a file""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1331 | data = self._DoReadFile('036_u_boot_img.dts') |
Simon Glass | c49deb8 | 2016-11-25 20:15:54 -0700 | [diff] [blame] | 1332 | self.assertEqual(U_BOOT_IMG_DATA, data) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1333 | |
| 1334 | def testNoMicrocode(self): |
| 1335 | """Test that a missing microcode region is detected""" |
| 1336 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1337 | self._DoReadFile('037_x86_no_ucode.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1338 | self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode " |
| 1339 | "node found in ", str(e.exception)) |
| 1340 | |
| 1341 | def testMicrocodeWithoutNode(self): |
| 1342 | """Test that a missing u-boot-dtb-with-ucode node is detected""" |
| 1343 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1344 | self._DoReadFile('038_x86_ucode_missing_node.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1345 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " |
| 1346 | "microcode region u-boot-dtb-with-ucode", str(e.exception)) |
| 1347 | |
| 1348 | def testMicrocodeWithoutNode2(self): |
| 1349 | """Test that a missing u-boot-ucode node is detected""" |
| 1350 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1351 | self._DoReadFile('039_x86_ucode_missing_node2.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1352 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " |
| 1353 | "microcode region u-boot-ucode", str(e.exception)) |
| 1354 | |
| 1355 | def testMicrocodeWithoutPtrInElf(self): |
| 1356 | """Test that a U-Boot binary without the microcode symbol is detected""" |
| 1357 | # ELF file without a '_dt_ucode_base_size' symbol |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1358 | try: |
Simon Glass | bccd91d | 2019-08-24 07:22:55 -0600 | [diff] [blame] | 1359 | TestFunctional._MakeInputFile('u-boot', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1360 | tools.read_file(self.ElfTestFile('u_boot_no_ucode_ptr'))) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1361 | |
| 1362 | with self.assertRaises(ValueError) as e: |
Simon Glass | 160a766 | 2017-05-27 07:38:26 -0600 | [diff] [blame] | 1363 | self._RunPackUbootSingleMicrocode() |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1364 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate " |
| 1365 | "_dt_ucode_base_size symbol in u-boot", str(e.exception)) |
| 1366 | |
| 1367 | finally: |
| 1368 | # Put the original file back |
Simon Glass | f514d8f | 2019-08-24 07:22:54 -0600 | [diff] [blame] | 1369 | TestFunctional._MakeInputFile('u-boot', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1370 | tools.read_file(self.ElfTestFile('u_boot_ucode_ptr'))) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1371 | |
| 1372 | def testMicrocodeNotInImage(self): |
| 1373 | """Test that microcode must be placed within the image""" |
| 1374 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1375 | self._DoReadFile('040_x86_ucode_not_in_image.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1376 | self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode " |
| 1377 | "pointer _dt_ucode_base_size at fffffe14 is outside the " |
Simon Glass | 25ac0e6 | 2018-06-01 09:38:14 -0600 | [diff] [blame] | 1378 | "section ranging from 00000000 to 0000002e", str(e.exception)) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1379 | |
| 1380 | def testWithoutMicrocode(self): |
| 1381 | """Test that we can cope with an image without microcode (e.g. qemu)""" |
Simon Glass | bccd91d | 2019-08-24 07:22:55 -0600 | [diff] [blame] | 1382 | TestFunctional._MakeInputFile('u-boot', |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1383 | tools.read_file(self.ElfTestFile('u_boot_no_ucode_ptr'))) |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1384 | data, dtb, _, _ = self._DoReadFileDtb('044_x86_optional_ucode.dts', True) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1385 | |
| 1386 | # Now check the device tree has no microcode |
| 1387 | self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)]) |
| 1388 | second = data[len(U_BOOT_NODTB_DATA):] |
| 1389 | |
| 1390 | fdt_len = self.GetFdtLen(second) |
| 1391 | self.assertEqual(dtb, second[:fdt_len]) |
| 1392 | |
| 1393 | used_len = len(U_BOOT_NODTB_DATA) + fdt_len |
| 1394 | third = data[used_len:] |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1395 | self.assertEqual(tools.get_bytes(0, 0x200 - used_len), third) |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1396 | |
| 1397 | def testUnknownPosSize(self): |
| 1398 | """Test that microcode must be placed within the image""" |
| 1399 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1400 | self._DoReadFile('041_unknown_pos_size.dts', True) |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1401 | self.assertIn("Section '/binman': Unable to set offset/size for unknown " |
Simon Glass | 75db086 | 2016-11-25 20:15:55 -0700 | [diff] [blame] | 1402 | "entry 'invalid-entry'", str(e.exception)) |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1403 | |
| 1404 | def testPackFsp(self): |
| 1405 | """Test that an image with a FSP binary can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1406 | data = self._DoReadFile('042_intel_fsp.dts') |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1407 | self.assertEqual(FSP_DATA, data[:len(FSP_DATA)]) |
| 1408 | |
| 1409 | def testPackCmc(self): |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1410 | """Test that an image with a CMC binary can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1411 | data = self._DoReadFile('043_intel_cmc.dts') |
Simon Glass | da22909 | 2016-11-25 20:15:56 -0700 | [diff] [blame] | 1412 | self.assertEqual(CMC_DATA, data[:len(CMC_DATA)]) |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1413 | |
| 1414 | def testPackVbt(self): |
| 1415 | """Test that an image with a VBT binary can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1416 | data = self._DoReadFile('046_intel_vbt.dts') |
Bin Meng | 59ea8c2 | 2017-08-15 22:41:54 -0700 | [diff] [blame] | 1417 | self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) |
Simon Glass | 9fc60b4 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1418 | |
Simon Glass | 5650984 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 1419 | def testSplBssPad(self): |
| 1420 | """Test that we can pad SPL's BSS with zeros""" |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1421 | # ELF file with a '__bss_size' symbol |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1422 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1423 | data = self._DoReadFile('047_spl_bss_pad.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1424 | self.assertEqual(U_BOOT_SPL_DATA + tools.get_bytes(0, 10) + U_BOOT_DATA, |
Simon Glass | e6d85ff | 2019-05-14 15:53:47 -0600 | [diff] [blame] | 1425 | data) |
Simon Glass | 5650984 | 2017-11-12 21:52:25 -0700 | [diff] [blame] | 1426 | |
Simon Glass | 86af511 | 2018-10-01 21:12:42 -0600 | [diff] [blame] | 1427 | def testSplBssPadMissing(self): |
| 1428 | """Test that a missing symbol is detected""" |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1429 | self._SetupSplElf('u_boot_ucode_ptr') |
Simon Glass | b50e561 | 2017-11-13 18:54:54 -0700 | [diff] [blame] | 1430 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1431 | self._DoReadFile('047_spl_bss_pad.dts') |
Simon Glass | b50e561 | 2017-11-13 18:54:54 -0700 | [diff] [blame] | 1432 | self.assertIn('Expected __bss_size symbol in spl/u-boot-spl', |
| 1433 | str(e.exception)) |
| 1434 | |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 1435 | def testPackStart16Spl(self): |
Simon Glass | 35b384c | 2018-09-14 04:57:10 -0600 | [diff] [blame] | 1436 | """Test that an image with an x86 start16 SPL region can be created""" |
Simon Glass | 9255f3c | 2019-08-24 07:23:01 -0600 | [diff] [blame] | 1437 | data = self._DoReadFile('048_x86_start16_spl.dts') |
Simon Glass | 8772213 | 2017-11-12 21:52:26 -0700 | [diff] [blame] | 1438 | self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)]) |
| 1439 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1440 | def _PackUbootSplMicrocode(self, dts, ucode_second=False): |
| 1441 | """Helper function for microcode tests |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1442 | |
| 1443 | We expect to see the following in the image, in order: |
| 1444 | u-boot-spl-nodtb.bin with a microcode pointer inserted at the |
| 1445 | correct place |
| 1446 | u-boot.dtb with the microcode removed |
| 1447 | the microcode |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1448 | |
| 1449 | Args: |
| 1450 | dts: Device tree file to use for test |
| 1451 | ucode_second: True if the microsecond entry is second instead of |
| 1452 | third |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1453 | """ |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1454 | self._SetupSplElf('u_boot_ucode_ptr') |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1455 | first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA, |
| 1456 | ucode_second=ucode_second) |
Simon Glass | c6c10e7 | 2019-05-17 22:00:46 -0600 | [diff] [blame] | 1457 | self.assertEqual(b'splnodtb with microc' + pos_and_size + |
| 1458 | b'ter somewhere in here', first) |
Simon Glass | 6b187df | 2017-11-12 21:52:27 -0700 | [diff] [blame] | 1459 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1460 | def testPackUbootSplMicrocode(self): |
| 1461 | """Test that x86 microcode can be handled correctly in SPL""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1462 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1463 | self._PackUbootSplMicrocode('049_x86_ucode_spl.dts') |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1464 | |
| 1465 | def testPackUbootSplMicrocodeReorder(self): |
| 1466 | """Test that order doesn't matter for microcode entries |
| 1467 | |
| 1468 | This is the same as testPackUbootSplMicrocode but when we process the |
| 1469 | u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode |
| 1470 | entry, so we reply on binman to try later. |
| 1471 | """ |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1472 | self._PackUbootSplMicrocode('058_x86_ucode_spl_needs_retry.dts', |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1473 | ucode_second=True) |
| 1474 | |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 1475 | def testPackMrc(self): |
| 1476 | """Test that an image with an MRC binary can be created""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1477 | data = self._DoReadFile('050_intel_mrc.dts') |
Simon Glass | ca4f4ff | 2017-11-12 21:52:28 -0700 | [diff] [blame] | 1478 | self.assertEqual(MRC_DATA, data[:len(MRC_DATA)]) |
| 1479 | |
Simon Glass | 47419ea | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 1480 | def testSplDtb(self): |
| 1481 | """Test that an image with spl/u-boot-spl.dtb can be created""" |
Marek Vasut | fadad3a | 2023-07-18 07:23:58 -0600 | [diff] [blame] | 1482 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1483 | data = self._DoReadFile('051_u_boot_spl_dtb.dts') |
Simon Glass | 47419ea | 2017-11-13 18:54:55 -0700 | [diff] [blame] | 1484 | self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)]) |
| 1485 | |
Simon Glass | 4e6fdbe | 2017-11-13 18:54:56 -0700 | [diff] [blame] | 1486 | def testSplNoDtb(self): |
| 1487 | """Test that an image with spl/u-boot-spl-nodtb.bin can be created""" |
Simon Glass | 0fe44dc | 2021-04-25 08:39:32 +1200 | [diff] [blame] | 1488 | self._SetupSplElf() |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1489 | data = self._DoReadFile('052_u_boot_spl_nodtb.dts') |
Simon Glass | 4e6fdbe | 2017-11-13 18:54:56 -0700 | [diff] [blame] | 1490 | self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)]) |
| 1491 | |
Simon Glass | 3d43338 | 2021-03-21 18:24:30 +1300 | [diff] [blame] | 1492 | def checkSymbols(self, dts, base_data, u_boot_offset, entry_args=None, |
Simon Glass | 4649bea | 2023-07-18 07:23:54 -0600 | [diff] [blame] | 1493 | use_expanded=False, no_write_symbols=False): |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1494 | """Check the image contains the expected symbol values |
| 1495 | |
| 1496 | Args: |
| 1497 | dts: Device tree file to use for test |
| 1498 | base_data: Data before and after 'u-boot' section |
| 1499 | u_boot_offset: Offset of 'u-boot' section in image |
Simon Glass | 3d43338 | 2021-03-21 18:24:30 +1300 | [diff] [blame] | 1500 | entry_args: Dict of entry args to supply to binman |
| 1501 | key: arg name |
| 1502 | value: value of that arg |
| 1503 | use_expanded: True to use expanded entries where available, e.g. |
| 1504 | 'u-boot-expanded' instead of 'u-boot' |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1505 | """ |
Simon Glass | 1542c8b | 2019-08-24 07:22:56 -0600 | [diff] [blame] | 1506 | elf_fname = self.ElfTestFile('u_boot_binman_syms') |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1507 | syms = elf.GetSymbols(elf_fname, ['binman', 'image']) |
| 1508 | addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start') |
Alper Nebi Yasak | 367ecbf | 2022-06-18 15:13:11 +0300 | [diff] [blame] | 1509 | self.assertEqual(syms['_binman_sym_magic'].address, addr) |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1510 | self.assertEqual(syms['_binman_u_boot_spl_any_prop_offset'].address, |
Alper Nebi Yasak | 367ecbf | 2022-06-18 15:13:11 +0300 | [diff] [blame] | 1511 | addr + 4) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1512 | |
Simon Glass | 11ae93e | 2018-10-01 21:12:47 -0600 | [diff] [blame] | 1513 | self._SetupSplElf('u_boot_binman_syms') |
Simon Glass | 3d43338 | 2021-03-21 18:24:30 +1300 | [diff] [blame] | 1514 | data = self._DoReadFileDtb(dts, entry_args=entry_args, |
| 1515 | use_expanded=use_expanded)[0] |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1516 | # The image should contain the symbols from u_boot_binman_syms.c |
| 1517 | # Note that image_pos is adjusted by the base address of the image, |
| 1518 | # which is 0x10 in our test image |
Alper Nebi Yasak | 367ecbf | 2022-06-18 15:13:11 +0300 | [diff] [blame] | 1519 | sym_values = struct.pack('<LLQLL', elf.BINMAN_SYM_MAGIC_VALUE, |
| 1520 | 0x00, u_boot_offset + len(U_BOOT_DATA), |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1521 | 0x10 + u_boot_offset, 0x04) |
Simon Glass | 4649bea | 2023-07-18 07:23:54 -0600 | [diff] [blame] | 1522 | if no_write_symbols: |
| 1523 | expected = (base_data + |
| 1524 | tools.get_bytes(0xff, 0x38 - len(base_data)) + |
| 1525 | U_BOOT_DATA + base_data) |
| 1526 | else: |
| 1527 | expected = (sym_values + base_data[24:] + |
| 1528 | tools.get_bytes(0xff, 1) + U_BOOT_DATA + sym_values + |
| 1529 | base_data[24:]) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 1530 | self.assertEqual(expected, data) |
| 1531 | |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1532 | def testSymbols(self): |
| 1533 | """Test binman can assign symbols embedded in U-Boot""" |
Alper Nebi Yasak | 367ecbf | 2022-06-18 15:13:11 +0300 | [diff] [blame] | 1534 | self.checkSymbols('053_symbols.dts', U_BOOT_SPL_DATA, 0x1c) |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1535 | |
| 1536 | def testSymbolsNoDtb(self): |
| 1537 | """Test binman can assign symbols embedded in U-Boot SPL""" |
Simon Glass | e9e0db8 | 2021-03-21 18:24:29 +1300 | [diff] [blame] | 1538 | self.checkSymbols('196_symbols_nodtb.dts', |
Simon Glass | f589882 | 2021-03-18 20:24:56 +1300 | [diff] [blame] | 1539 | U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA, |
| 1540 | 0x38) |
| 1541 | |
Simon Glass | dd57c13 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 1542 | def testPackUnitAddress(self): |
| 1543 | """Test that we support multiple binaries with the same name""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1544 | data = self._DoReadFile('054_unit_address.dts') |
Simon Glass | dd57c13 | 2018-06-01 09:38:11 -0600 | [diff] [blame] | 1545 | self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data) |
| 1546 | |
Simon Glass | 1854695 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1547 | def testSections(self): |
| 1548 | """Basic test of sections""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1549 | data = self._DoReadFile('055_sections.dts') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1550 | expected = (U_BOOT_DATA + tools.get_bytes(ord('!'), 12) + |
| 1551 | U_BOOT_DATA + tools.get_bytes(ord('a'), 12) + |
| 1552 | U_BOOT_DATA + tools.get_bytes(ord('&'), 4)) |
Simon Glass | 1854695 | 2018-06-01 09:38:16 -0600 | [diff] [blame] | 1553 | self.assertEqual(expected, data) |
Simon Glass | 9fc60b4 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 1554 | |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1555 | def testMap(self): |
| 1556 | """Tests outputting a map of the images""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1557 | _, _, map_data, _ = self._DoReadFileDtb('055_sections.dts', map=True) |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1558 | self.assertEqual('''ImagePos Offset Size Name |
Simon Glass | 193d3db | 2023-02-07 14:34:18 -0700 | [diff] [blame] | 1559 | 00000000 00000000 00000028 image |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1560 | 00000000 00000000 00000010 section@0 |
| 1561 | 00000000 00000000 00000004 u-boot |
| 1562 | 00000010 00000010 00000010 section@1 |
| 1563 | 00000010 00000000 00000004 u-boot |
| 1564 | 00000020 00000020 00000004 section@2 |
| 1565 | 00000020 00000000 00000004 u-boot |
Simon Glass | 3b0c382 | 2018-06-01 09:38:20 -0600 | [diff] [blame] | 1566 | ''', map_data) |
| 1567 | |
Simon Glass | c8d48ef | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1568 | def testNamePrefix(self): |
| 1569 | """Tests that name prefixes are used""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1570 | _, _, map_data, _ = self._DoReadFileDtb('056_name_prefix.dts', map=True) |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1571 | self.assertEqual('''ImagePos Offset Size Name |
Simon Glass | 193d3db | 2023-02-07 14:34:18 -0700 | [diff] [blame] | 1572 | 00000000 00000000 00000028 image |
Simon Glass | 1be70d2 | 2018-07-17 13:25:49 -0600 | [diff] [blame] | 1573 | 00000000 00000000 00000010 section@0 |
| 1574 | 00000000 00000000 00000004 ro-u-boot |
| 1575 | 00000010 00000010 00000010 section@1 |
| 1576 | 00000010 00000000 00000004 rw-u-boot |
Simon Glass | c8d48ef | 2018-06-01 09:38:21 -0600 | [diff] [blame] | 1577 | ''', map_data) |
| 1578 | |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1579 | def testUnknownContents(self): |
| 1580 | """Test that obtaining the contents works as expected""" |
| 1581 | with self.assertRaises(ValueError) as e: |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1582 | self._DoReadFile('057_unknown_contents.dts', True) |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 1583 | self.assertIn("Image '/binman': Internal error: Could not complete " |
Simon Glass | 1628793 | 2020-04-17 18:09:03 -0600 | [diff] [blame] | 1584 | "processing of contents: remaining [" |
| 1585 | "<binman.etype._testing.Entry__testing ", str(e.exception)) |
Simon Glass | 736bb0a | 2018-07-06 10:27:17 -0600 | [diff] [blame] | 1586 | |
Simon Glass | 5c89023 | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1587 | def testBadChangeSize(self): |
| 1588 | """Test that trying to change the size of an entry fails""" |
Simon Glass | c52c9e7 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 1589 | try: |
| 1590 | state.SetAllowEntryExpansion(False) |
| 1591 | with self.assertRaises(ValueError) as e: |
| 1592 | self._DoReadFile('059_change_size.dts', True) |
Simon Glass | 79d3c58 | 2019-07-20 12:23:57 -0600 | [diff] [blame] | 1593 | self.assertIn("Node '/binman/_testing': Cannot update entry size from 2 to 3", |
Simon Glass | c52c9e7 | 2019-07-08 14:25:37 -0600 | [diff] [blame] | 1594 | str(e.exception)) |
| 1595 | finally: |
| 1596 | state.SetAllowEntryExpansion(True) |
Simon Glass | 5c89023 | 2018-07-06 10:27:19 -0600 | [diff] [blame] | 1597 | |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1598 | def testUpdateFdt(self): |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1599 | """Test that we can update the device tree with offset/size info""" |
Simon Glass | 741f2d6 | 2018-10-01 12:22:30 -0600 | [diff] [blame] | 1600 | _, _, _, out_dtb_fname = self._DoReadFileDtb('060_fdt_update.dts', |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1601 | update_dtb=True) |
Simon Glass | cee02e6 | 2018-07-17 13:25:52 -0600 | [diff] [blame] | 1602 | dtb = fdt.Fdt(out_dtb_fname) |
| 1603 | dtb.Scan() |
Simon Glass | 12bb1a9 | 2019-07-20 12:23:51 -0600 | [diff] [blame] | 1604 | props = self._GetPropTree(dtb, BASE_DTB_PROPS + REPACK_DTB_PROPS) |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1605 | self.assertEqual({ |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1606 | 'image-pos': 0, |
Simon Glass | 8122f39 | 2018-07-17 13:25:28 -0600 | [diff] [blame] | 1607 | 'offset': 0, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1608 | '_testing:offset': 32, |
Simon Glass | 79d3c58 | 2019-07-20 12:23:57 -0600 | [diff] [blame] | 1609 | '_testing:size': 2, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1610 | '_testing:image-pos': 32, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1611 | 'section@0/u-boot:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1612 | 'section@0/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1613 | 'section@0/u-boot:image-pos': 0, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1614 | 'section@0:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1615 | 'section@0:size': 16, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1616 | 'section@0:image-pos': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1617 | |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1618 | 'section@1/u-boot:offset': 0, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1619 | 'section@1/u-boot:size': len(U_BOOT_DATA), |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1620 | 'section@1/u-boot:image-pos': 16, |
Simon Glass | 3ab9598 | 2018-08-01 15:22:37 -0600 | [diff] [blame] | 1621 | 'section@1:offset': 16, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1622 | 'section@1:size': 16, |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 1623 | 'section@1:image-pos': 16, |
Simon Glass | 16b8d6b | 2018-07-06 10:27:42 -0600 | [diff] [blame] | 1624 | 'size': <
|