From e8bced62b6be344dbc922d88b1b278e316e1585f Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Fri, 28 Feb 2020 09:05:04 +0900 Subject: cmd: efidebug: fix a failure of "boot rm" sub-command There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16"). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 21dfd44fcc9..056ebb10832 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -649,7 +649,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, int id, i; char *endp; char var_name[9]; - u16 var_name16[9]; + u16 var_name16[9], *p; efi_status_t ret; if (argc == 1) @@ -662,7 +662,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; sprintf(var_name, "Boot%04X", id); - utf8_utf16_strncpy((u16 **)&var_name16, var_name, 9); + p = var_name16; + utf8_utf16_strncpy(&p, var_name, 9); ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { -- cgit v1.3.1 From 30efb5dd43fdeb6173c61a55b537fcfba2c45f3f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 2 Mar 2020 20:13:10 +0100 Subject: cmd: efidebug: correct error message Add the missing line feed at the error message if the variable referred to by 'efidebug boot rm' does not exist. Shorten the format string by using the variable name instead of the number of the boot variable. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 056ebb10832..8c3681c37d9 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -667,7 +667,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { - printf("Cannot remove Boot%04X", id); + printf("Cannot remove %ls\n", var_name16); return CMD_RET_FAILURE; } } -- cgit v1.3.1 From 4af2a33ee5b91223f993af9bb0de1a081090634b Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Wed, 11 Mar 2020 08:46:29 +0000 Subject: cmd: gpio: Make `gpio input` return pin value again 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") correctly changed the behaviour of the gpio command to return CMD_RET_SUCCESS or CMD_RET_FAILURE, but any existing script which expects the return value to be the pin value is broken by this change. Reinstate the legacy behaviour for `gpio input` only. Fixes: 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") Signed-off-by: Alex Kiernan Signed-off-by: Alex Kiernan Reviewed-by: Simon Glass --- cmd/gpio.c | 7 ++++++- test/py/tests/test_gpio.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/py/tests/test_gpio.py (limited to 'cmd') diff --git a/cmd/gpio.c b/cmd/gpio.c index 16c2cebb3d4..408a942455b 100644 --- a/cmd/gpio.c +++ b/cmd/gpio.c @@ -248,7 +248,12 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (ret != -EBUSY) gpio_free(gpio); - return CMD_RET_SUCCESS; + /* + * Whilst wrong, the legacy gpio input command returns the pin + * value, or CMD_RET_FAILURE (which is indistinguishable from a + * valid pin value). + */ + return (sub_cmd == GPIOC_INPUT) ? value : CMD_RET_SUCCESS; err: if (ret != -EBUSY) diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py new file mode 100644 index 00000000000..8c64f686b0b --- /dev/null +++ b/test/py/tests/test_gpio.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpio') +def test_gpio_input(u_boot_console): + """Test that gpio input correctly returns the value of a gpio pin.""" + + response = u_boot_console.run_command('gpio input 0; echo rc:$?') + expected_response = 'rc:0' + assert(expected_response in response) + response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?') + expected_response = 'rc:1' + assert(expected_response in response) + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpio') +def test_gpio_exit_statuses(u_boot_console): + """Test that non-input gpio commands correctly return the command + success/failure status.""" + + expected_response = 'rc:0' + response = u_boot_console.run_command('gpio clear 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio set 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio toggle 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio status -a; echo rc:$?') + assert(expected_response in response) + + expected_response = 'rc:1' + response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio input 200; echo rc:$?') + assert(expected_response in response) -- cgit v1.3.1 From fef907b2e4406da8addebd7fefb6fd87ca7875ab Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 14 Mar 2020 10:59:34 +0100 Subject: efi_loader: create reservations after ft_board_setup Some memory reservations are made in ft_board_setup(). Ensure that we create reserved memory map entries after ft_board_setup(). The downside of this patch is that if bootefi is called multiple times with an devicetree argument superfluous reservations for the old copies of the device tree will exist. But that is still better than missing a reservation. Deleting the superfluous reservations is not possible because reservations in the memory map are rounded to page size and may be coallesced. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 24fc42ae898..522ed28d6ac 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -263,9 +263,6 @@ efi_status_t efi_install_fdt(void *fdt) return EFI_LOAD_ERROR; } - /* Create memory reservations as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - /* Prepare device tree for payload */ ret = copy_fdt(&fdt); if (ret) { @@ -278,6 +275,9 @@ efi_status_t efi_install_fdt(void *fdt) return EFI_LOAD_ERROR; } + /* Create memory reservations as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + /* Install device tree as UEFI table */ ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS) { -- cgit v1.3.1 From a415d61eac26a9108c26ef779f2009dc3062f5d8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 14 Mar 2020 08:44:07 +0100 Subject: cmd: map addresses to sysmem in efidebug memmap Addresses in the sandbox's device tree are in the sandbox's virtual address space. If we want to compare memory reservations in the device-tree with the output of 'efidebug memmap', we need to convert back to this address space. Adjust the output of the 'efidebug memmap' command. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 8c3681c37d9..bb7c13d6a1c 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -488,9 +489,10 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, printf("%-16s %.*llx-%.*llx", type, EFI_PHYS_ADDR_WIDTH, - map->physical_start, + (u64)map_to_sysmem((void *)map->physical_start), EFI_PHYS_ADDR_WIDTH, - map->physical_start + map->num_pages * EFI_PAGE_SIZE); + (u64)map_to_sysmem((void *)map->physical_start + + map->num_pages * EFI_PAGE_SIZE)); print_memory_attributes(map->attribute); putc('\n'); -- cgit v1.3.1 From 7be64b885a360d0b7e78a5f624698a67513be53f Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 13 Mar 2020 17:11:30 -0700 Subject: cmd: bootefi: Parse reserved-memory node from DT Currently, bootefi only parses memory reservation block to setup EFI reserved memory mappings. However, it doesn't parse the reserved-memory[1] device tree node that also can contain the reserved memory regions. Add capability to parse reserved-memory node and update the EFI memory mappings accordingly. 1. /doc/device-tree-bindings/reserved-memory/reserved-memory.txt] Signed-off-by: Atish Patra Fix an endless loop. The /reserved-memory node may have children without reg property. Remove a superfluous debug statement. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'cmd') diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 522ed28d6ac..3bbe2d6a1a4 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -149,6 +149,20 @@ done: return ret; } +static void efi_reserve_memory(u64 addr, u64 size) +{ + u64 pages; + + /* Convert from sandbox address space. */ + addr = (uintptr_t)map_sysmem(addr, 0); + pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); + addr &= ~EFI_PAGE_MASK; + if (efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, + false) != EFI_SUCCESS) + printf("Reserved memory mapping failed addr %llx size %llx\n", + addr, size); +} + /** * efi_carve_out_dt_rsv() - Carve out DT reserved memory ranges * @@ -161,7 +175,8 @@ done: static void efi_carve_out_dt_rsv(void *fdt) { int nr_rsv, i; - uint64_t addr, size, pages; + u64 addr, size; + int nodeoffset, subnode; nr_rsv = fdt_num_mem_rsv(fdt); @@ -169,15 +184,25 @@ static void efi_carve_out_dt_rsv(void *fdt) for (i = 0; i < nr_rsv; i++) { if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0) continue; + efi_reserve_memory(addr, size); + } - /* Convert from sandbox address space. */ - addr = (uintptr_t)map_sysmem(addr, 0); - - pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); - addr &= ~EFI_PAGE_MASK; - if (efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, - false) != EFI_SUCCESS) - printf("FDT memrsv map %d: Failed to add to map\n", i); + /* process reserved-memory */ + nodeoffset = fdt_subnode_offset(fdt, 0, "reserved-memory"); + if (nodeoffset >= 0) { + subnode = fdt_first_subnode(fdt, nodeoffset); + while (subnode >= 0) { + /* check if this subnode has a reg property */ + addr = fdtdec_get_addr_size(fdt, subnode, "reg", + (fdt_size_t *)&size); + /* + * The /reserved-memory node may have children with + * a size instead of a reg property. + */ + if (addr != FDT_ADDR_T_NONE) + efi_reserve_memory(addr, size); + subnode = fdt_next_subnode(fdt, subnode); + } } } -- cgit v1.3.1