1# SPDX-License-Identifier:  GPL-2.0+
2# Copyright (c) 2020
3# Author: Kory Maincent <kory.maincent@bootlin.com>
4
5# Test U-Boot's "extension" commands.
6
7import os
8import pytest
9import utils
10
11overlay_addr = 0x1000
12
13SANDBOX_DTB='arch/sandbox/dts/sandbox.dtb'
14OVERLAY_DIR='arch/sandbox/dts/'
15
16def load_dtb(ubman):
17    ubman.log.action('Loading devicetree to RAM...')
18    ubman.run_command('host load hostfs - $fdt_addr_r %s' % (os.path.join(ubman.config.build_dir, SANDBOX_DTB)))
19    ubman.run_command('fdt addr $fdt_addr_r')
20
21@pytest.mark.buildconfigspec('cmd_fdt')
22@pytest.mark.boardspec('sandbox')
23def test_extension(ubman):
24    """Test the 'extension' command."""
25
26    load_dtb(ubman)
27
28    output = ubman.run_command('extension list')
29    # extension_bootdev_hunt may have already run.
30    # Without reboot we cannot make any assumption here.
31    # assert('No extension' in output)
32
33    output = ubman.run_command('extension scan')
34    assert output == 'Found 2 extension board(s).'
35
36    output = ubman.run_command('extension list')
37    assert('overlay0.dtbo' in output)
38    assert('overlay1.dtbo' in output)
39
40    ubman.run_command_list([
41        'setenv extension_overlay_addr %s' % (overlay_addr),
42        'setenv extension_overlay_cmd \'host load hostfs - ${extension_overlay_addr} %s${extension_overlay_name}\'' % (os.path.join(ubman.config.build_dir, OVERLAY_DIR))])
43
44    output = ubman.run_command('extension apply 0')
45    assert('bytes read' in output)
46
47    output = ubman.run_command('fdt print')
48    assert('button3' in output)
49
50    output = ubman.run_command('extension apply all')
51    assert('bytes read' in output)
52
53    output = ubman.run_command('fdt print')
54    assert('button4' in output)
55
56