blob: ab89332331e2d6d946bb334a7aeb0672576542ff [file] [log] [blame]
Simon Glassa2d24e62023-02-13 08:56:41 -07001# SPDX-License-Identifier: GPL-2.0
2# Copyright 2023 Google LLC
3# Written by Simon Glass <sjg@chromium.org>
4
5"""Test handling of unmigrated u-boot,dm- tags"""
6
7import os
8import pytest
9
Simon Glassdb0e4532025-02-09 09:07:16 -070010import utils
Simon Glassa2d24e62023-02-13 08:56:41 -070011
12# This is needed for Azure, since the default '..' directory is not writeable
13TMPDIR1 = '/tmp/test_no_migrate'
14TMPDIR2 = '/tmp/test_no_migrate_spl'
15TMPDIR3 = '/tmp/test_migrate'
16
Simon Glass32701112025-02-09 09:07:17 -070017def build_for_migrate(ubman, replace_pair, board, tmpdir, disable_migrate=True):
Simon Glassa2d24e62023-02-13 08:56:41 -070018 """Build an updated U-Boot with a slightly modified device tree
19
20 Args:
Simon Glass32701112025-02-09 09:07:17 -070021 ubman (ConsoleBase): U-Boot console
Simon Glassa2d24e62023-02-13 08:56:41 -070022 replace_pair (tuple):
23 String to find
24 String to replace it with
25 board (str): Board to build
26 tmpdir (str): Temporary directory to use
27 disable_migrate (bool): True to disable CONFIG_OF_TAG_MIGRATE in build
28 """
Simon Glass32701112025-02-09 09:07:17 -070029 srcdir = ubman.config.source_dir
30 build_dir = ubman.config.build_dir
Simon Glassa2d24e62023-02-13 08:56:41 -070031
32 # Get the source for the existing dts
33 dt_dir = os.path.join(build_dir, 'arch', 'sandbox', 'dts')
34 orig_fname = os.path.join(dt_dir, 'sandbox.dtb')
35 out_dts = os.path.join(dt_dir, 'sandbox_out.dts')
Simon Glass32701112025-02-09 09:07:17 -070036 utils.run_and_log(ubman, ['dtc', orig_fname, '-I', 'dtb', '-O', 'dts',
Simon Glassdb0e4532025-02-09 09:07:16 -070037 '-o', out_dts])
Simon Glassa2d24e62023-02-13 08:56:41 -070038
39 # Update it to use an old tag
40 with open(out_dts) as inf:
41 data = inf.read()
42 data = data.replace(*replace_pair)
43
44 dts_fname = os.path.join(dt_dir, 'sandbox_oldtag.dts')
45 with open(dts_fname, 'w') as outf:
46 print(data, file=outf)
47 dtb_fname = os.path.join(dt_dir, 'sandbox_oldtag.dtb')
Simon Glass32701112025-02-09 09:07:17 -070048 utils.run_and_log(ubman, ['dtc', dts_fname, '-o', dtb_fname])
Simon Glassa2d24e62023-02-13 08:56:41 -070049
50 migrate = ['-a', '~CONFIG_OF_TAG_MIGRATE'] if disable_migrate else []
51
52 # Build sandbox with this new dtb, turning off OF_TAG_MIGRATE
53 env = dict(os.environ)
54 env['EXT_DTB'] = dtb_fname
55 env['DEVICE_TREE'] = 'sandbox_new'
56 env['NO_LTO'] = '1' # Speed up build
Simon Glassdb0e4532025-02-09 09:07:16 -070057 out = utils.run_and_log(
Simon Glass32701112025-02-09 09:07:17 -070058 ubman, ['./tools/buildman/buildman', '-m', '--board', board,
Simon Glassa2d24e62023-02-13 08:56:41 -070059 *migrate, '-w', '-o', tmpdir], ignore_errors=True, env=env)
60 return out
61
62@pytest.mark.slow
63@pytest.mark.boardspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -070064def test_of_no_migrate(ubman):
Simon Glassa2d24e62023-02-13 08:56:41 -070065 """Test sandbox with old boot phase tags like u-boot,dm-pre-proper"""
Simon Glassa2d24e62023-02-13 08:56:41 -070066
Simon Glass32701112025-02-09 09:07:17 -070067 build_for_migrate(ubman, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
Simon Glassa2d24e62023-02-13 08:56:41 -070068 'sandbox', TMPDIR1)
69
70 # It should fail to run, since the lcd device will not be bound before
71 # relocation. so won't get its frame-buffer memory
Simon Glassdb0e4532025-02-09 09:07:16 -070072 out = utils.run_and_log(
Simon Glass32701112025-02-09 09:07:17 -070073 ubman, [os.path.join(TMPDIR1, 'u-boot'), '-D', '-c', 'help'],
Simon Glassa2d24e62023-02-13 08:56:41 -070074 ignore_errors=True)
75 assert "Video device 'lcd' cannot allocate frame buffer memory" in out
76
77
78@pytest.mark.slow
79@pytest.mark.boardspec('sandbox_spl')
80@pytest.mark.boardspec('spl_of_platdata_inst')
81@pytest.mark.boardspec('!sandbox_tpl')
Simon Glassddba5202025-02-09 09:07:14 -070082def test_of_no_migrate_spl(ubman):
Simon Glassa2d24e62023-02-13 08:56:41 -070083 """Test sandbox with old boot phase tags like u-boot,dm-spl"""
Simon Glassa2d24e62023-02-13 08:56:41 -070084
Simon Glass32701112025-02-09 09:07:17 -070085 out = build_for_migrate(ubman, ['bootph-pre-ram', 'u-boot,dm-spl'],
Simon Glassa2d24e62023-02-13 08:56:41 -070086 'sandbox_spl', TMPDIR2)
87
88 # It should fail to build, since the SPL DT will not include 'spl-test'
89 # node, among others
90 assert "undefined type ‘struct dtd_sandbox_spl_test’" in out
91
92
93@pytest.mark.slow
94@pytest.mark.boardspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -070095def test_of_migrate(ubman):
Simon Glassa2d24e62023-02-13 08:56:41 -070096 """Test sandbox shows a message when tags were migrated"""
Simon Glassa2d24e62023-02-13 08:56:41 -070097
Simon Glass32701112025-02-09 09:07:17 -070098 build_for_migrate(ubman, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
Simon Glassa2d24e62023-02-13 08:56:41 -070099 'sandbox', TMPDIR3, disable_migrate=False)
100
101 # It should show a migration message
Simon Glassdb0e4532025-02-09 09:07:16 -0700102 out = utils.run_and_log(
Simon Glass32701112025-02-09 09:07:17 -0700103 ubman, [os.path.join(TMPDIR3, 'u-boot'), '-D', '-c', 'help'],
Simon Glassa2d24e62023-02-13 08:56:41 -0700104 ignore_errors=True)
105 assert "Warning: Device tree includes old 'u-boot,dm-' tags" in out