Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-08-23 Thread Rasmus Villemoes
On 23/08/2022 16.35, Simon Glass wrote:
> Hi Rasmus,
> 
> On Tue, 23 Aug 2022 at 07:06, Rasmus Villemoes
>  wrote:
>>
>> On 23/08/2022 15.38, Simon Glass wrote:
>>
 +/**
 + * board_rng_seed() - Provide a seed to be passed via /chosen/rng-seed
 + *
 + * This function is called if CONFIG_BOARD_RNG_SEED is set, and must
 + * be provided by the board. It should return, via @buf, some suitable
 + * seed value to pass to the kernel.
 + *
 + * @param buf A struct abuf for returning the seed and its size.
 + * @return0 if ok, negative on error.
 + */
 +int board_rng_seed(struct abuf *buf);
>>>
>>> Instead of yet another hook, can we use EVT_FT_FIXUP? An even better
>>> option might be to use EVT_FT_FIXUP and then call a UCLASS_BOARD
>>> method to obtain the information.
>>
>> I didn't know there was anything called EVT_FT_FIXUP, and from grepping,
>> it seems suffer the same problem as ft_board_setup() as I mention,
>> namely running after the command line (aka /chosen/bootargs) has been
>> set up.
> 
> If that is the only problem, then you could add another event for
> doing an earlier fixup.

Then I'd much rather just add a board_fdt_chosen() hook called early in
fdt_chosen(), rather than having to enable yet another overcomplicated
generic framework. But this was very much specifically targeted at
rng-seed, because that's a generic, defined binding in /chosen, and I
wanted to support that explicitly rather than having each board
implement the logic for populating that - even if, due to its nature,
the board must supply the actual value to put there.

>> Also, I can't see how it can actually affect the blob being passed to
>> the kernel, doesn't
>>
>> fixup.tree = oftree_default();
>> ret = event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup));
>>
>> mean that fixup.tree points at U-Boot's control fdt rather than the blob
>> that will be passed as the kernel's fdt? That seems wrong.
> 
> Yes that is wrong for many platforms. We should probably just change
> it, but there is a complication.
> 
> My recent series made a start at supporting writing to a DT using the
> ofnode interface. See vbe_simple_test_base() for some comments on the
> current state. You could require OF_LIVE to be enabled for your new
> feature.
> 
> Ideally I'd like to see ofnode used for all devicetree access, but it
> will need to be done in stages. In the meantime we should try to head
> in that direction.

Huh? You'd need to deserialize the blob we've loaded (from FIT or uImage
or given directly to a bootm command), then have _all_ the various fixup
functions (setting mac addresses, populating /chosen, all the various
arch and board fixups etc.) modify that deserialized tree, and then at
the end of the day, you need to serialize the tree again to pass to
linux. I don't see how that could happen incrementally, and I don't see
what advantage this would bring anyway.

All that has nothing at all to do with how U-Boot code accesses U-Boot's
control DT.

Rasmus


[PATCH v13 9/9] test: unit test for eficonfig

2022-08-23 Thread Masahisa Kojima
Provide a unit test for the eficonfig command.

Signed-off-by: Masahisa Kojima 
---
No update since v12

Changes in v12:
- update menu handling

Changes in v11:
- fix expected result when no BootOrder is defined

Newly added in v10

 configs/sandbox_defconfig |   1 +
 test/py/tests/test_eficonfig/conftest.py  |  40 +++
 .../py/tests/test_eficonfig/test_eficonfig.py | 332 ++
 3 files changed, 373 insertions(+)
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb48..48c60c606d 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -93,6 +93,7 @@ CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
diff --git a/test/py/tests/test_eficonfig/conftest.py 
b/test/py/tests/test_eficonfig/conftest.py
new file mode 100644
index 00..f289df0362
--- /dev/null
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier:  GPL-2.0+
+
+"""Fixture for UEFI eficonfig test
+"""
+
+import os
+import shutil
+from subprocess import check_call
+import pytest
+
+@pytest.fixture(scope='session')
+def efi_eficonfig_data(u_boot_config):
+"""Set up a file system to be used in UEFI "eficonfig" command
+   tests
+
+Args:
+u_boot_config -- U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
+image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
+
+shutil.rmtree(mnt_point, ignore_errors=True)
+os.mkdir(mnt_point, mode = 0o755)
+
+with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 1")
+
+with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 2")
+
+shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+mnt_point + '/initrddump.efi')
+
+check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat 
{mnt_point} {image_path}',
+   shell=True)
+
+return image_path
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py 
b/test/py/tests/test_eficonfig/test_eficonfig.py
new file mode 100644
index 00..0edb1ec627
--- /dev/null
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -0,0 +1,332 @@
+# SPDX-License-Identifier:  GPL-2.0+
+""" Unit test for UEFI menu-driven configuration
+"""
+
+import pytest
+import time
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_eficonfig')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
+
+def send_user_input_and_wait(user_str, expect_str):
+time.sleep(0.1) # TODO: does not work correctly without sleep
+u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
+   wait_for_echo=True, send_nl=False)
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
+# press UP key
+for i in range(up_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x41', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press DOWN key
+for i in range(down_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x42', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press ENTER if requested
+if enter:
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# wait expected output
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_escape_key(wait_prompt):
+u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, 
wait_for_echo=False, send_nl=False)
+
+def press_enter_key(wait_prompt):
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+   wait_for_echo=False, send_nl=False)
+
+def check_current_is_maintenance_menu():
+for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot 
Option',
+  'Change Boot Order', 'Delete Boot Option', 'Quit'):
+u_boot_console.p.expect([i])
+
+""" Unit test for "eficonfig" command
+Th

[PATCH v13 8/9] doc:eficonfig: add documentation for eficonfig command

2022-08-23 Thread Masahisa Kojima
Add documentation for eficonfig command.

Signed-off-by: Masahisa Kojima 
---
Changes in v13:
- describe how to auto boot according to the UEFI Boot option

Changes in v12:
- CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE condition is added
  to show newly added boot option

No update since v10

Changes in v10:
- describe how to boot system after editting by eficonfig

Changes in v8:
- command name is changed from "efimenu" to "eficonfig"

Newly created in v7

 doc/usage/cmd/eficonfig.rst | 71 +
 doc/usage/index.rst |  1 +
 2 files changed, 72 insertions(+)
 create mode 100644 doc/usage/cmd/eficonfig.rst

diff --git a/doc/usage/cmd/eficonfig.rst b/doc/usage/cmd/eficonfig.rst
new file mode 100644
index 00..48932fa16b
--- /dev/null
+++ b/doc/usage/cmd/eficonfig.rst
@@ -0,0 +1,71 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. (C) Copyright 2022, Masahisa Kojima 
+
+eficonfig command
+=
+
+Synopsis
+
+::
+
+eficonfig
+
+Description
+---
+
+The "eficonfig" command uses U-Boot menu interface and privides
+a menu-driven UEFI variable maintenance feature.
+The "eficonfig" has the following menu entries.
+
+Add Boot Option
+Add new UEFI Boot Option.
+User can edit description, file path, and optional_data.
+
+Edit Boot Option
+Edit the existing UEFI Boot Option
+User can edit description, file path, and optional_data.
+
+Change Boot Order
+Change the order of UEFI BootOrder variable.
+
+Delete Boot Option
+Delete the UEFI Boot Option
+
+Configuration
+-
+
+The "eficonfig" command is enabled by::
+
+CONFIG_CMD_EFICONFIG=y
+
+If CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not enter
+U-Boot console. In this case, bootmenu can be used to invoke "eficonfig"::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="setenv bootmenu_0 UEFI Maintenance Menu=eficonfig"
+
+How to boot the system with newly added UEFI Boot Option
+
+
+"eficonfig" command is responsible to configure the UEFI variables,
+not directly handle the system boot.
+The new Boot Option added by "eficonfig" is appended at the last entry
+of UEFI BootOrder variable, user may want to change the boot order
+through "Change Boot Order".
+If the bootmenu is enabled, CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled,
+and "eficonfig" is configured as preboot command, the newly added Boot Options
+are enumerated in the bootmenu when user exits from the eficonfig menu.
+User may select the entry in the bootmenu to boot the system, or follow
+the U-Boot configuration the system already has.
+
+Auto boot with the UEFI Boot Option
+'''
+
+To do auto boot according to the UEFI BootOrder variable,
+add "bootefi bootmgr" entry as a default or first bootmenu entry::
+
+CONFIG_PREBOOT="setenv bootmenu_0 UEFI Boot Manager=bootefi bootmgr; 
setenv bootmenu_1 UEFI Maintenance Menu=eficonfig"
+
+See also
+
+* :doc:`bootmenu` provides a simple mechanism for creating menus 
with different boot items
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 28f9683a3e..09f2928970 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -35,6 +35,7 @@ Shell commands
cmd/conitrace
cmd/dm
cmd/echo
+   cmd/eficonfig
cmd/env
cmd/event
cmd/exception
-- 
2.17.1



[PATCH v13 7/9] doc:bootmenu: add description for UEFI boot support

2022-08-23 Thread Masahisa Kojima
The bootmenu enumerates the UEFI boot options
for boot device selection.
This commit adds the description how the UEFI boot work
in bootmenu. This commit also adds "Synopsis", "Description"
and "Configuration" sections to follow the U-Boot command
documentation format.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Ilias Apalodimas 
---
No update since v10

Changes in v10:
- fix typos

Changes in v7:
- update the description what bootmenu do for uefi-related boot menu
- add default behavior when user exits from bootmenu

Changes in v6:
- remove distro boot related contents because the distro boot
support in bootmenu is dropped
- update uefi entry example
- add [delay] argument of bootmenu command
- add description to enable uefi boot entry

Changes in v5:
- follow the cmd documentation format same as other command, add "Synopsis",
  "Description" add "Configuration" sections

Newly created in v4

 doc/usage/cmd/bootmenu.rst | 74 ++
 1 file changed, 74 insertions(+)

diff --git a/doc/usage/cmd/bootmenu.rst b/doc/usage/cmd/bootmenu.rst
index 9430f8c9aa..cb3c8d2f93 100644
--- a/doc/usage/cmd/bootmenu.rst
+++ b/doc/usage/cmd/bootmenu.rst
@@ -4,6 +4,15 @@
 bootmenu command
 
 
+Synopsis
+
+::
+
+bootmenu [delay]
+
+Description
+---
+
 The "bootmenu" command uses U-Boot menu interfaces and provides
 a simple mechanism for creating menus with different boot items.
 The cursor keys "Up" and "Down" are used for navigation through
@@ -79,6 +88,55 @@ The above example will be rendered as below::
 The selected menu entry will be highlighted - it will have inverted
 background and text colors.
 
+UEFI boot variable enumeration
+''
+If enabled, the bootmenu command will automatically generate and add
+UEFI-related boot menu entries for the following items.
+
+ * possible bootable media with default file names
+ * user-defined UEFI boot options
+
+The bootmenu automatically enumerates the possible bootable
+media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.
+This auto generated entry is named as " :" format.
+(e.g. "usb 0:1")
+
+The bootmenu displays the UEFI-related menu entries in order of "BootOrder".
+When the user selects the UEFI boot menu entry, the bootmenu sets
+the selected boot variable index to "BootNext" without non-volatile attribute,
+then call the uefi boot manager with the command "bootefi bootmgr".
+
+Example bootmenu is as below::
+
+*** U-Boot Boot Menu ***
+
+   mmc 0:1
+   mmc 0:2
+   debian
+   nvme 0:1
+   ubuntu
+   nvme 0:2
+   usb 0:2
+   U-Boot console
+
+Default behavior when user exits from the bootmenu
+~~
+User can exit from bootmenu by selecting the last entry
+"U-Boot console"/"Quit" or ESC/CTRL+C key.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is disabled,
+user exits from the bootmenu and returns to the U-Boot console.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not
+enter the U-Boot console. When the user exits from the bootmenu,
+the bootmenu invokes the following default behavior.
+
+ * if CONFIG_CMD_BOOTEFI_BOOTMGR is enabled, execute "bootefi bootmgr" command
+ * "bootefi bootmgr" fails or is not enabled, then execute "run bootcmd" 
command.
+
+Configuration
+-
+
 The "bootmenu" command is enabled by::
 
 CONFIG_CMD_BOOTMENU=y
@@ -88,3 +146,19 @@ To run the bootmenu at startup add these additional 
settings::
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_BOOTDELAY=30
 CONFIG_AUTOBOOT_MENU_SHOW=y
+
+UEFI boot variable enumeration is enabled by::
+
+CONFIG_CMD_BOOTEFI_BOOTMGR=y
+
+To improve the product security, entering U-Boot console from bootmenu
+can be disabled by::
+
+CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
+
+To scan the discoverable devices connected to the buses such as
+USB and PCIe prior to bootmenu showing up, CONFIG_PREBOOT can be
+used to run the command before showing the bootmenu, i.e.::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="pci enum; usb start; scsi scan; nvme scan; virtio scan"
-- 
2.17.1



[PATCH v13 6/9] eficonfig: add "Change Boot Order" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to update UEFI BootOrder variable.
User moves the entry with UP/DOWN key, changes the order
with PLUS/MINUS key, press SPACE to activate or deactivate
the entry, then finalizes the order by ENTER key.
If the entry is activated, the boot index is added into the
BootOrder variable in the order of the list.

The U-Boot menu framework is well designed for static menu,
this commit implements the own menu display and key handling
for dynamically change the order of menu entry.

Signed-off-by: Masahisa Kojima 
---
No update since v12

Changes in v12:
- enumerate removable media device

Changes in v11:
- remove BootOrder variable dependency
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.
- add KEY_SPACE to toggle the boot option active status

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- add "Save" and "Quit" entries

Changes in v7:
- use UP/DOWN and PLUS/MINUS key to change to order

no update in v6:

 cmd/eficonfig.c | 351 +++-
 1 file changed, 350 insertions(+), 1 deletion(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 92171c4894..0922115138 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -91,6 +91,23 @@ struct eficonfig_boot_selection_data {
int *selected;
 };
 
+/**
+ * struct eficonfig_boot_order - structure to be used to update BootOrder 
variable
+ *
+ * @num:   index in the menu entry
+ * @description:   pointer to the description string
+ * @boot_index:boot option index
+ * @active:flag to include the boot option into BootOrder variable
+ * @list:  list structure
+ */
+struct eficonfig_boot_order {
+   u32 num;
+   u16 *description;
+   u32 boot_index;
+   bool active;
+   struct list_head list;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1716,6 +1733,338 @@ out:
return ret;
 }
 
+/**
+ * eficonfig_display_change_boot_order() - display the BootOrder list
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)
+{
+   bool reverse;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *entry;
+
+   printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION
+  "\n  ** Change Boot Order **\n"
+  ANSI_CURSOR_POSITION
+  "  Press UP/DOWN to move, +/- to change order"
+  ANSI_CURSOR_POSITION
+  "  Press SPACE to activate or deactivate the entry"
+  ANSI_CURSOR_POSITION
+  "  Select [Save] to complete, ESC/CTRL+C to quit"
+  ANSI_CURSOR_POSITION ANSI_CLEAR_LINE,
+  1, 1, efi_menu->count + 5, 1, efi_menu->count + 6, 1,
+  efi_menu->count + 7, 1,  efi_menu->count + 8, 1);
+
+   /* draw boot option list */
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct eficonfig_boot_order, list);
+   reverse = (entry->num == efi_menu->active);
+
+   printf(ANSI_CURSOR_POSITION, entry->num + 4, 7);
+
+   if (reverse)
+   puts(ANSI_COLOR_REVERSE);
+
+   if (entry->num < efi_menu->count - 2) {
+   if (entry->active)
+   printf("[*]  ");
+   else
+   printf("[ ]  ");
+   }
+
+   printf("%ls", entry->description);
+
+   if (reverse)
+   puts(ANSI_COLOR_RESET);
+   }
+}
+
+/**
+ * eficonfig_choice_change_boot_order() - handle the BootOrder update
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static efi_status_t eficonfig_choice_change_boot_order(struct efimenu 
*efi_menu)
+{
+   int esc = 0;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *tmp;
+   enum bootmenu_key key = KEY_NONE;
+   struct eficonfig_boot_order *entry;
+
+   while (1) {
+   bootmenu_loop(NULL, &key, &esc);
+
+   switch (key) {
+   case KEY_PLUS:
+   if (efi_menu->active > 0) {
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct 
eficonfig_boot_order, list);
+   if (entry->num == efi_menu->active)
+   break;
+   }
+   tmp = list_entry(pos->prev, struct 
eficonfig_boot_order, list);
+   entry->num--;
+   tmp->num++;
+ 

[PATCH v13 5/9] bootmenu: add removable media entries

2022-08-23 Thread Masahisa Kojima
UEFI specification requires booting from removal media using
a architecture-specific default image name such as BOOTAA64.EFI.
This commit adds the removable media entries into bootmenu,
so that user can select the removable media and boot with
default image.

The bootmenu automatically enumerates the possible bootable
media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
add it as new UEFI boot option(BOOT) and update BootOrder
variable. This automatically generated UEFI boot option
has the dedicated guid in the optional_data to distinguish it from
the UEFI boot option user adds manually. This optional_data is
removed when the efi bootmgr loads the selected UEFI boot option.

This commit also provides the BOOT variable maintenance feature.
Depending on the system hardware setup, some devices
may not exist at a later system boot, so bootmenu checks the
available device in each bootmenu invocation and automatically
removes the BOOT variable corrensponding to the non-existent
media device.

Signed-off-by: Masahisa Kojima 
---
Changes in v13:
- remove BootOrder variable dependency

Changes in v12:
- move generate_media_device_boot_option into cmd/eficonfig.c and expose it
- remove unnecessary include file

Changes in v11:
- update delete_boot_option() parameter

Changes in v10:
- add function comment
- devname dynamic allocation removes, allocate in stack
- delete BOOT when updating BootOrder fails

Changes in v9:
- update efi_disk_get_device_name() parameter to pass efi_handle_t
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- rename prepare_media_device_entry() to generate_media_device_boot_option()

Changes in v6:
- optional_data size is changed to 16bytes
- check the load option size before comparison
- remove guid included in optional_data of auto generated
  entry when loading

Changes in v5:
- Return EFI_SUCCESS if there is no BootOrder defined
- correctly handle the case if no removable device found
- use guid to identify the automatically generated entry by bootmenu

 cmd/bootmenu.c   |  22 +++-
 cmd/eficonfig.c  | 209 +++
 include/efi_config.h |   1 +
 include/efi_loader.h |  16 +++
 lib/efi_loader/efi_bootmgr.c |   4 +
 5 files changed, 246 insertions(+), 6 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 704d36debe..3340be1632 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -220,7 +220,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
return 1;
 }
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
 /**
  * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries
  *
@@ -340,11 +340,21 @@ static struct bootmenu_data *bootmenu_create(int delay)
if (ret < 0)
goto cleanup;
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
if (i < MAX_COUNT - 1) {
-   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
-   if (ret < 0 && ret != -ENOENT)
-   goto cleanup;
+   efi_status_t efi_ret;
+
+   /*
+* UEFI specification requires booting from removal media using
+* a architecture-specific default image name such as 
BOOTAA64.EFI.
+*/
+   efi_ret = eficonfig_generate_media_device_boot_option();
+   if (efi_ret != EFI_SUCCESS && efi_ret != EFI_NOT_FOUND)
+   goto cleanup;
+
+   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
+   if (ret < 0 && ret != -ENOENT)
+   goto cleanup;
}
 #endif
 
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 537f3f2bbc..92171c4894 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1786,6 +1786,215 @@ static efi_status_t 
eficonfig_process_delete_boot_option(void *data)
return ret;
 }
 
+/**
+ * eficonfig_enumerate_boot_option() - enumerate the possible bootable media
+ *
+ * @opt:   pointer to the media boot option structure
+ * @volume_handles:pointer to the efi handles
+ * @count: number of efi handle
+ * Return: status code
+ */
+efi_status_t eficonfig_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
+efi_handle_t *volume_handles, 
efi_status_t count)
+{
+   u32 i;
+   struct efi_handler *handler;
+   efi_status_t ret = EFI_SUCCESS;
+
+   for (i = 0; i < count; i++) {
+   u16 *p;
+   u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
+   char *optional_data;
+   struct efi_loa

[PATCH v13 4/9] eficonfig: add "Delete Boot Option" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to delete the UEFI boot option.
User moves the entry with UP/DOWN key, changes, then presses
ENTER key to delete the selected boot option.

Signed-off-by: Masahisa Kojima 
---
No update since v11

Changes in v11:
- update function interface to show boot selection menu
- support to delete the load option is not included in BootOrder

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- to stay the boot order list after user delete the entry

no update in v6:

changes in v5:

 cmd/eficonfig.c | 71 +
 1 file changed, 71 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 22389b537f..537f3f2bbc 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1716,6 +1716,76 @@ out:
return ret;
 }
 
+/**
+ * delete_boot_option() - delete selected boot option
+ *
+ * @boot_index:boot option index to delete
+ * Return: status code
+ */
+static efi_status_t delete_boot_option(u16 boot_index)
+{
+   u16 *bootorder;
+   u16 varname[9];
+   efi_status_t ret;
+   unsigned int index;
+   efi_uintn_t num, size;
+
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", boot_index);
+   ret = efi_set_variable_int(varname, &efi_global_variable_guid,
+  0, 0, NULL, false);
+   if (ret != EFI_SUCCESS) {
+   log_err("delete boot option(%ls) failed\n", varname);
+   return ret;
+   }
+
+   /* update BootOrder if necessary */
+   bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
+   if (!bootorder)
+   return EFI_SUCCESS;
+
+   num = size / sizeof(u16);
+   if (!search_bootorder(bootorder, num, boot_index, &index))
+   return EFI_SUCCESS;
+
+   memmove(&bootorder[index], &bootorder[index + 1],
+   (num - index - 1) * sizeof(u16));
+   size -= sizeof(u16);
+   ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  size, bootorder, false);
+
+   return ret;
+}
+
+/**
+ * eficonfig_process_delete_boot_option() - handler to delete boot option
+ *
+ * @data:  pointer to the data for each entry
+ * Return: status code
+ */
+static efi_status_t eficonfig_process_delete_boot_option(void *data)
+{
+   efi_status_t ret;
+   unsigned int selected;
+
+   while (1) {
+   ret = eficonfig_show_boot_selection(&selected);
+   if (ret == EFI_SUCCESS)
+   ret = delete_boot_option(selected);
+
+   if (ret != EFI_SUCCESS)
+   break;
+   }
+
+   /* to stay the parent menu */
+   ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
+
+   return ret;
+}
+
 /**
  * eficonfig_init() - do required initialization for eficonfig command
  *
@@ -1746,6 +1816,7 @@ static efi_status_t eficonfig_init(void)
 static const struct eficonfig_item maintenance_menu_items[] = {
{"Add Boot Option", eficonfig_process_add_boot_option},
{"Edit Boot Option", eficonfig_process_edit_boot_option},
+   {"Delete Boot Option", eficonfig_process_delete_boot_option},
{"Quit", eficonfig_process_quit},
 };
 
-- 
2.17.1



[PATCH v13 3/9] menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling

2022-08-23 Thread Masahisa Kojima
This is preparation to support menu-driven UEFI BootOrder
variable updated by KEY_PLUS, KEY_MINUS and KEY_SPACE.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Heinrich Schuchardt 
Reviewed-by: Ilias Apalodimas 
---
No update since v11

Changes in v11:
- add SPACE key handling

Newly created in v7

 common/menu.c  | 9 +
 include/menu.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/common/menu.c b/common/menu.c
index 3e876b55b3..0d19601cf5 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -548,4 +548,13 @@ void bootmenu_loop(struct bootmenu_data *menu,
/* ^C was pressed */
if (c == 0x3)
*key = KEY_QUIT;
+
+   if (c == '+')
+   *key = KEY_PLUS;
+
+   if (c == '-')
+   *key = KEY_MINUS;
+
+   if (c == ' ')
+   *key = KEY_SPACE;
 }
diff --git a/include/menu.h b/include/menu.h
index e74616cae8..702aacb170 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -48,6 +48,9 @@ enum bootmenu_key {
KEY_DOWN,
KEY_SELECT,
KEY_QUIT,
+   KEY_PLUS,
+   KEY_MINUS,
+   KEY_SPACE,
 };
 
 void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-- 
2.17.1



[PATCH v13 1/9] eficonfig: menu-driven addition of UEFI boot option

2022-08-23 Thread Masahisa Kojima
This commit add the "eficonfig" command.
The "eficonfig" command implements the menu-driven UEFI boot option
maintenance feature. This commit implements the addition of
new boot option. User can select the block device volume having
efi_simple_file_system_protocol and select the file corresponding
to the Boot variable. User can also enter the description and
optional_data of the BOOT variable in utf8.

This commit adds "include/efi_config.h", it contains the common
definition to be used from other menus such as UEFI Secure Boot
key management.

Signed-off-by: Masahisa Kojima 
---
No change since v12

Changes in v12:
- add select/clear menu before displaying volume selectio
- move function declaration from efi_loader.h to efi_config.h
- remove unused declaration
- support the boot option does not have file path
- correctly handle if optional_data is empty

Changes in v11:
- refactor menu entry construction, directly use eficonfig_entry structure
- remove reading directory info to calculate the number of entry
- fix invalid efi_free_pool() in ill_file_info()
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.

Changes in v10:
- add initrd file selection
- do refactoring
- eficonfig_process_common() use list structure
- remove u'/' before copying file_path into current_path
- fix typos
- check snprintf error

Changes in v9:
- move "efi_guid_bootmenu_auto_generated definition" into efi_bootmgr.c
  to address build error when CMD_EFICONFIG is disabled
- fix typos and comment
- remove file system information from error message
- remove unreachable code in eficonfig_choice_entry()
- single printf() call as much as possible
- call only getchar() in  eficonfig_print_msg()
- filter out '.' entry from file selection
- update the efi_disk_get_device_name() implementation
- add function comment

Changes in v8:
- command name is change from "efimenu" to "eficonfig"
- function and struct prefixes is changed to "eficonfig"
- fix menu header string

Changes in v7:
- add "efimenu" command and uefi variable maintenance code
  moved into cmd/efimenu.c
- create include/efimenu.h to define the common definition for
  the other menu such as UEFI Secure Boot key management
- update boot option edit UI, user can select description, file,
  and optional_data to edit in the same menu like following.

  ** Edit Boot Option **

 Description: debian
 File: virtio 0:1/EFI\debian\grubaa64.efi
 Optional Data: test
 Save
 Quit

- remove exit parameter from efimenu_process_common()
- menu title type is changed from u16 to char
- efimenu_process_common() add menu title string
- reduce printf/puts function call for displaying the menu
- efi_console_get_u16_string() accept 0 length to allow
  optional_data is empty
- efi_console_get_u16_string() the "size" parameter name is changes to "count"
- efimenu is now designed to maintain the UEFI variables, remove autoboot 
related code
- remove one empty line before "Quit" entry
- efimenu_init() processes only the first time

Changes in v6:
- fix typos
- modify volume name to match U-Boot syntax
- compile in CONFIG_EFI_LOADER=n and CONFIG_CMD_BOOTEFI_BOOTMGR=n
- simplify u16_strncmp() usage
- support "a\b.efi" file path, use link list to handle filepath
- modify length check condition
- UEFI related menu items only appears with CONFIG_AUTOBOOT_MENU_SHOW=y

Changes in v5:
- remove forward declarations
- add const qualifier for menu items
- fix the possible unaligned access for directory info access
- split into three commit 1)add boot option 2) delete boot option 3)change boot 
order
  This commit is 1)add boot option.
- fix file name buffer allocation size, it should be EFI_BOOTMENU_FILE_PATH_MAX 
* sizeof(u16)
- fix wrong size checking for file selection

Chanes in v4:
- UEFI boot option maintenance menu is integrated into bootmenu
- display the simplified volume name(e.g. usb0:1, nvme1:2) for the
  volume selection
- instead of extending lib/efi_loader/efi_bootmgr.c, newly create
  lib/efi_loader/efi_bootmenu_maintenance.c and implement boot
  variable maintenance into it.

Changes in RFC v3:
 not included in v3 series

Changes in RFC v2:
- enable utf8 user input for boot option name
- create lib/efi_loader/efi_console.c::efi_console_get_u16_string() for
  utf8 user input handling
- use u16_strlcat instead of u16_strcat
- remove the EFI_CALLs, and newly create or expose the following
  xxx_int() functions.
efi_locate_handle_buffer_int(), efi_open_volume_int(),
efi_file_open_int(), efi_file_close_int(), efi_file_read_int() and
efi_file_setpos_int().
  Note that EFI_CALLs still exist for EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
  and EFI_SIMPLE_TEXT_INPUT/OUTPUT_PROTOCOL
- use efi_search_protocol() instead of calling locate_protocol() to get
  the device_path_to_text_protocol interface.
- remove unn

[PATCH v13 2/9] eficonfig: add "Edit Boot Option" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to edit the existing
BOOT variable contents.
User selects the item from the boot option list, then
user can edit the description, file path and optional_data.

Note that automatically generated boot option entry by bootmenu
to support the removable media device is filtered out and user
can not edit the automatically generated entry.

Signed-off-by: Masahisa Kojima 
---
No update since v11

Changes in v11:
- remove BootOrder variable dependency
- change the list load option order
   1) in the order of BootOrder
   2) remaing load option that is not included in the BootOrder
- add check for the number of menu entry exceeds max
- truncate the long load option label when user edits
- add EFICONFIG_VOLUME_PATH_MAX to display text converted volume
  device path in case the volume does not exist

Changes in v10:
- update eficonfig_edit_boot_option() argument

Changes in v9:
- add function comment

Changes in v8:
- fix menu header string
- fix function and structure prefix to "eficonfig"

Newly created in v7

 cmd/eficonfig.c  | 277 +--
 include/efi_config.h |   1 +
 2 files changed, 269 insertions(+), 9 deletions(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 9709222378..22389b537f 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -40,7 +40,7 @@ struct eficonfig_filepath_info {
  *
  * @file_info: user selected file info
  * @initrd_info:   user selected initrd file info
- * @boot_index:index of the UEFI BootOrder variable
+ * @boot_index:index of the boot option
  * @description:   pointer to the description string
  * @optional_data: pointer to the optional_data
  * @edit_completed:flag indicates edit complete
@@ -80,6 +80,17 @@ struct eficonfig_file_entry_data {
u16 *file_name;
 };
 
+/**
+ * struct eficonfig_boot_selection_data - structure to be used to select the 
boot option entry
+ *
+ * @boot_index:index of the boot option
+ * @selected:  pointer to store the selected index in the BootOrder 
variable
+ */
+struct eficonfig_boot_selection_data {
+   u16 boot_index;
+   int *selected;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1143,34 +1154,58 @@ static efi_status_t prepare_file_selection_entry(struct 
efimenu *efi_menu, char
 {
u32 len;
efi_status_t ret;
-   u16 *file_name, *p;
+   u16 *file_name = NULL, *p;
efi_handle_t handle;
-   char devname[BOOTMENU_DEVICE_NAME_MAX] = {0};
+   char *devname;
+
+   devname = calloc(1, EFICONFIG_VOLUME_PATH_MAX + 1);
+   if (!devname)
+   return EFI_OUT_OF_RESOURCES;
 
/* get the device name only when the user already selected the file 
path */
handle = efi_dp_find_obj(file_info->dp_volume, NULL, NULL);
if (handle) {
-   ret = efi_disk_get_device_name(handle, devname, 
BOOTMENU_DEVICE_NAME_MAX);
+   ret = efi_disk_get_device_name(handle, devname, 
EFICONFIG_VOLUME_PATH_MAX);
if (ret != EFI_SUCCESS)
-   return ret;
+   goto out;
+   }
+
+   /*
+* If the preconfigured volume does not exist in the system, display 
the text
+* converted volume device path instead of U-Boot friendly name(e.g. 
"usb 0:1").
+*/
+   if (!handle && file_info->dp_volume) {
+   u16 *dp_str;
+   char *q = devname;
+
+   dp_str = efi_dp_str(file_info->dp_volume);
+   if (dp_str)
+   utf16_utf8_strncpy(&q, dp_str, 
EFICONFIG_VOLUME_PATH_MAX);
+
+   efi_free_pool(dp_str);
}
 
/* append u'/' to devname, it is just for display purpose. */
if (file_info->current_path[0] != u'\0' && file_info->current_path[0] 
!= u'/')
-   strlcat(devname, "/", BOOTMENU_DEVICE_NAME_MAX);
+   strlcat(devname, "/", EFICONFIG_VOLUME_PATH_MAX + 1);
 
len = strlen(devname);
len += utf16_utf8_strlen(file_info->current_path) + 1;
file_name = calloc(1, len * sizeof(u16));
-   if (!file_name)
-   return ret;
+   if (!file_name) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
 
p = file_name;
utf8_utf16_strcpy(&p, devname);
u16_strlcat(file_name, file_info->current_path, len);
ret = create_boot_option_entry(efi_menu, title, file_name,
   eficonfig_select_file_handler, 
file_info);
+out:
+   free(devname);
free(file_name);
+
return ret;
 }
 
@@ -1337,10 +1372,14 @@ static efi_status_t eficonfig_edit_boot_option(u16 
*varname, struct eficonfig_bo
if (ret != EFI_SUCCESS)
goto out;
 
-   if (!lo.label || (lo.label && u16_strlen(lo.label) >= 
EFICONFIG_DESCRIPTION_MAX)) {
+   if (!lo.label) {

[PATCH v13 0/9] enable menu-driven UEFI variable maintenance

2022-08-23 Thread Masahisa Kojima
This series adds the menu-driven UEFI boot variable maintenance
through the "eficonfig" new command.
This series also adds the removable media support in bootmenu.

Initrd file selection and python based unit test are added in v10.

Source code can be cloned with:
$ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git -b 
kojima/eficonfig_upstream_v13

[Major Changes]
- there is detailed changelog in each commit

Masahisa Kojima (9):
  eficonfig: menu-driven addition of UEFI boot option
  eficonfig: add "Edit Boot Option" menu entry
  menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling
  eficonfig: add "Delete Boot Option" menu entry
  bootmenu: add removable media entries
  eficonfig: add "Change Boot Order" menu entry
  doc:bootmenu: add description for UEFI boot support
  doc:eficonfig: add documentation for eficonfig command
  test: unit test for eficonfig

 cmd/Kconfig   |7 +
 cmd/Makefile  |1 +
 cmd/bootmenu.c|   22 +-
 cmd/eficonfig.c   | 2430 +
 common/menu.c |9 +
 configs/sandbox_defconfig |1 +
 doc/usage/cmd/bootmenu.rst|   74 +
 doc/usage/cmd/eficonfig.rst   |   71 +
 doc/usage/index.rst   |1 +
 include/efi_config.h  |   97 +
 include/efi_loader.h  |   53 +
 include/menu.h|3 +
 lib/efi_loader/efi_bootmgr.c  |7 +
 lib/efi_loader/efi_boottime.c |   52 +-
 lib/efi_loader/efi_console.c  |   70 +
 lib/efi_loader/efi_disk.c |   50 +
 lib/efi_loader/efi_file.c |   75 +-
 test/py/tests/test_eficonfig/conftest.py  |   40 +
 .../py/tests/test_eficonfig/test_eficonfig.py |  332 +++
 19 files changed, 3342 insertions(+), 53 deletions(-)
 create mode 100644 cmd/eficonfig.c
 create mode 100644 doc/usage/cmd/eficonfig.rst
 create mode 100644 include/efi_config.h
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

-- 
2.17.1



Re: [PATCH v12 8/9] doc:eficonfig: add documentation for eficonfig command

2022-08-23 Thread Masahisa Kojima
On Wed, 24 Aug 2022 at 13:27, Masahisa Kojima
 wrote:
>
> Add documentation for eficonfig command.
>
> Signed-off-by: Masahisa Kojima 
> ---
> Changes in v12:
> - CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE condition is added
>   to show newly added boot option
>
> No update since v10
>
> Changes in v10:
> - describe how to boot system after editting by eficonfig
>
> Changes in v8:
> - command name is changed from "efimenu" to "eficonfig"
>
> Newly created in v7
>
>  doc/usage/cmd/eficonfig.rst | 63 +
>  doc/usage/index.rst |  1 +
>  2 files changed, 64 insertions(+)
>  create mode 100644 doc/usage/cmd/eficonfig.rst
>
> diff --git a/doc/usage/cmd/eficonfig.rst b/doc/usage/cmd/eficonfig.rst
> new file mode 100644
> index 00..52cc7b900d
> --- /dev/null
> +++ b/doc/usage/cmd/eficonfig.rst
> @@ -0,0 +1,63 @@
> +.. SPDX-License-Identifier: GPL-2.0+
> +.. (C) Copyright 2022, Masahisa Kojima 
> +
> +eficonfig command
> +=
> +
> +Synopsis
> +
> +::
> +
> +eficonfig
> +
> +Description
> +---
> +
> +The "eficonfig" command uses U-Boot menu interface and privides
> +a menu-driven UEFI variable maintenance feature.
> +The "eficonfig" has the following menu entries.
> +
> +Add Boot Option
> +Add new UEFI Boot Option.
> +User can edit description, file path, and optional_data.
> +
> +Edit Boot Option
> +Edit the existing UEFI Boot Option
> +User can edit description, file path, and optional_data.
> +
> +Change Boot Order
> +Change the order of UEFI BootOrder variable.
> +
> +Delete Boot Option
> +Delete the UEFI Boot Option
> +
> +Configuration
> +-
> +
> +The "eficonfig" command is enabled by::
> +
> +CONFIG_CMD_EFICONFIG=y
> +
> +If CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not enter
> +U-Boot console. In this case, bootmenu can be used to invoke "eficonfig"::
> +
> +CONFIG_USE_PREBOOT=y
> +CONFIG_PREBOOT="setenv bootmenu_0 UEFI Maintenance Menu=eficonfig"

To do autoboot with efi bootmgr, we need an additional preboot configuration.
"setenv bootmenu_0 UEFI Boot Manager=bootefi bootmgr; setenv
bootmenu_1 UEFI Maintenance Menu=eficonfig"

I will update the document in the next version.

Bootmenu is displayed as follows.

  *** U-Boot Boot Menu ***

  UEFI Boot Manager
  UEFI Maintenance Menu
  virtio 0:1
  virtio 0:2
  U-Boot console


Thanks,
Masahisa Kojima

> +
> +How to boot the system with newly added UEFI Boot Option
> +
> +
> +"eficonfig" command is responsible to configure the UEFI variables,
> +not directly handle the system boot.
> +The new Boot Option added by "eficonfig" is appended at the last entry
> +of UEFI BootOrder variable, user may want to change the boot order
> +through "Change Boot Order".
> +If the bootmenu is enabled, CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled,
> +and "eficonfig" is configured as preboot command, the newly added Boot 
> Options
> +are enumerated in the bootmenu when user exits from the eficonfig menu.
> +User may select the entry in the bootmenu to boot the system, or follow
> +the U-Boot configuration the system already has.
> +
> +See also
> +
> +* :doc:`bootmenu` provides a simple mechanism for creating menus 
> with different boot items
> diff --git a/doc/usage/index.rst b/doc/usage/index.rst
> index 28f9683a3e..09f2928970 100644
> --- a/doc/usage/index.rst
> +++ b/doc/usage/index.rst
> @@ -35,6 +35,7 @@ Shell commands
> cmd/conitrace
> cmd/dm
> cmd/echo
> +   cmd/eficonfig
> cmd/env
> cmd/event
> cmd/exception
> --
> 2.17.1
>


Re: mvebu - switch to orion-timer

2022-08-23 Thread Stefan Roese

Hi Pali,

On 24.08.22 00:33, Pali Rohár wrote:

Hello Stefan! Now when U-Boot contains new orion-timer.c driver, which
Michael wrote, I think that it mvebu platform should switch to use it.
Because build process for armada boards prints deprecation warning that
new timer is not being used. Could you look at it, if it is possible to
do global switch for mach-mvebu and mach-kirkwood? I think it does not
make sense to do per-board switching as it is de-facto platform related
code.


Yes, I also though about this.

But...

In Linux we have 2 different timer clocksource drivers for Orion /
Kirkwood and Armada XP / 370 etc:

drivers/clocksource/timer-orion.c
drivers/clocksource/timer-armada-370-xp.c

I did not check, if and why this is necessary to handle those chips
via different drivers yet. Perhaps later this week. Or someone of
you beats me with this. ;)

Thanks,
Stefan


Re: [PATCH] board: ti: common: board_detect: Fix EEPROM read quirk

2022-08-23 Thread Nishanth Menon
On 19:05-20220823, Matwey V. Kornilov wrote:
> There are three different kinds of EEPROM possibly present on boards.
>   1. 1byte address. For those we should avoid 2byte address in order
>  not to rewrite the data. Second byte of the address can potentially
>  be interpreted as the data to write.
>   2. 2byte address with defined behaviour. When we try to use 1byte
>  address they just return "FF FF FF FF ... FF"
>   3. 2byte address with undefined behaviour (for instance, 24LC32AI).
>  When we try to use 1byte address, then their internal read
>  pointer is changed to some value. Subsequential reads may be
>  broken.
> 
> To gracefully handle both case #1 and case #3 we read all required
> data from EEPROM at once (about 80 bytes). So either all the data is
> valid or we fallback to 2byte address.

I would suggest to add a note that this was measured as adding extra
time in startup time.

With that:
Acked-by: Nishanth Menon 
> 
> Cc: Nishanth Menon 
> Fixes: a58147c2dbbf ("board: ti: common: board_detect: Do 1byte address 
> checks first.")
> Reference: 
> https://lore.kernel.org/all/CAJs94Ebdd4foOjhGFu9Bop0v=b1us9nedlxfhgcy23ukglz...@mail.gmail.com/
> Signed-off-by: Matwey V. Kornilov 
> ---
>  board/ti/common/board_detect.c | 26 --
>  1 file changed, 8 insertions(+), 18 deletions(-)
> 
> diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
> index ed34991377..fdf83fcfb0 100644
> --- a/board/ti/common/board_detect.c
> +++ b/board/ti/common/board_detect.c
> @@ -86,7 +86,6 @@ __weak void gpi2c_init(void)
>  static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
>   u32 header, u32 size, uint8_t *ep)
>  {
> - u32 hdr_read = 0xdeadbeef;
>   int rc;
>  
>  #if CONFIG_IS_ENABLED(DM_I2C)
> @@ -113,10 +112,10 @@ static int __maybe_unused ti_i2c_eeprom_get(int 
> bus_addr, int dev_addr,
>* We must allow for fall through to check the data if 2 byte
>* addressing works
>*/
> - (void)dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
> + (void)dm_i2c_read(dev, 0, ep, size);
>  
>   /* Corrupted data??? */
> - if (hdr_read != header) {
> + if (*((u32 *)ep) != header) {
>   /*
>* read the eeprom header using i2c again, but use only a
>* 2 byte address (some newer boards need this..)
> @@ -125,16 +124,12 @@ static int __maybe_unused ti_i2c_eeprom_get(int 
> bus_addr, int dev_addr,
>   if (rc)
>   return rc;
>  
> - rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
> + rc = dm_i2c_read(dev, 0, ep, size);
>   if (rc)
>   return rc;
>   }
> - if (hdr_read != header)
> + if (*((u32 *)ep) != header)
>   return -1;
> -
> - rc = dm_i2c_read(dev, 0, ep, size);
> - if (rc)
> - return rc;
>  #else
>   u32 byte;
>  
> @@ -154,26 +149,21 @@ static int __maybe_unused ti_i2c_eeprom_get(int 
> bus_addr, int dev_addr,
>* We must allow for fall through to check the data if 2 byte
>* addressing works
>*/
> - (void)i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4);
> + (void)i2c_read(dev_addr, 0x0, byte, ep, size);
>  
>   /* Corrupted data??? */
> - if (hdr_read != header) {
> + if (*((u32 *)ep) != header) {
>   /*
>* read the eeprom header using i2c again, but use only a
>* 2 byte address (some newer boards need this..)
>*/
>   byte = 2;
> - rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read,
> -   4);
> + rc = i2c_read(dev_addr, 0x0, byte, ep, size);
>   if (rc)
>   return rc;
>   }
> - if (hdr_read != header)
> + if (*((u32 *)ep) != header)
>   return -1;
> -
> - rc = i2c_read(dev_addr, 0x0, byte, ep, size);
> - if (rc)
> - return rc;
>  #endif
>   return 0;
>  }
> -- 
> 2.26.2
> 

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v11 6/9] bootmenu: add removable media entries

2022-08-23 Thread Masahisa Kojima
On Wed, 24 Aug 2022 at 13:29, Masahisa Kojima
 wrote:
>
> Hi Akashi-san,
>
> On Wed, 24 Aug 2022 at 10:57, Takahiro Akashi
>  wrote:
> >
> > On Fri, Aug 19, 2022 at 12:05:50PM +0900, Masahisa Kojima wrote:
> > > Hi Akashi-san,
> > >
> > > On Fri, 19 Aug 2022 at 10:31, Takahiro Akashi
> > >  wrote:
> > > >
> > > > On Wed, Aug 17, 2022 at 06:36:11PM +0900, Masahisa Kojima wrote:
> > > > > UEFI specification requires booting from removal media using
> > > > > a architecture-specific default image name such as BOOTAA64.EFI.
> > > > > This commit adds the removable media entries into bootmenu,
> > > > > so that user can select the removable media and boot with
> > > > > default image.
> > > > >
> > > > > The bootmenu automatically enumerates the possible bootable
> > > > > media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
> > > > > add it as new UEFI boot option(BOOT) and update BootOrder
> > > > > variable. This automatically generated UEFI boot option
> > > >
> > > > Should this feature belong to bootmenu command?
> > > > Under the current implementation, those boot options are
> > > > generated only by bootmenu, and so if eficonfig is invoked
> > > > prior to bootmenu, we won't see them (under "Change Boot Order").
> > > >
> > > > I expect that the functionality be also provided in eficonfig
> > > > (or even as part of system initialization?).
> > >
> > > OK, generating the (removable) media boot options will be added
> > > in "Change Boot Order".
> >
> > I found another wrong behavior. What I did was
> > - eficonfig
> >   it shows no boot options.
> > - scsi rescan
> >   One disk with two partitions was detected.
> > - eficonfig
> >   Now it shows two options for removal media.
> >   I disabled one of two partitions from BootOrder.
> > - bootmenu
> >   It still shows both boot options. -> Probably okay?

No, disabled option must not be displayed.

> > - eficonfig
> >   Then a duplicated option comes up:
> >   ** Change Boot Order **
> >
> > [*]  scsi 0:1
> > [*]  scsi 0:2
> > [ ]  scsi 0:2
> > Save
> > Quit
> >
> > Internally there exist three boot options now.
>
> I have not checked this email before sending the v12 series.
> I will confirm behavior.

I could reproduce the problem and fix it in the next version.

Thanks,
Masahisa Kojima

>
> Thanks,
> Masahisa Kojima
>
> >
> > -Takahiro Akashi
> >
> > > Thanks,
> > > Masahisa Kojima
> > >
> > > >
> > > > -Takahiro Akashi
> > > >
> > > >
> > > > > has the dedicated guid in the optional_data to distinguish it from
> > > > > the UEFI boot option user adds manually. This optional_data is
> > > > > removed when the efi bootmgr loads the selected UEFI boot option.
> > > > >
> > > > > This commit also provides the BOOT variable maintenance feature.
> > > > > Depending on the system hardware setup, some devices
> > > > > may not exist at a later system boot, so bootmenu checks the
> > > > > available device in each bootmenu invocation and automatically
> > > > > removes the BOOT variable corrensponding to the non-existent
> > > > > media device.
> > > > >
> > > > > Signed-off-by: Masahisa Kojima 
> > > > > ---
> > > > > Changes in v11:
> > > > > - update delete_boot_option() parameter
> > > > >
> > > > > Changes in v10:
> > > > > - add function comment
> > > > > - devname dynamic allocation removes, allocate in stack
> > > > > - delete BOOT when updating BootOrder fails
> > > > >
> > > > > Changes in v9:
> > > > > - update efi_disk_get_device_name() parameter to pass efi_handle_t
> > > > > - add function comment
> > > > >
> > > > > Changes in v8:
> > > > > - function and structure prefix is changed to "eficonfig"
> > > > >
> > > > > Changes in v7:
> > > > > - rename prepare_media_device_entry() to 
> > > > > generate_media_device_boot_option()
> > > > >
> > > > > Changes in v6:
> > > > > - optional_data size is changed to 16bytes
> > > > > - check the load option size before comparison
> > > > > - remove guid included in optional_data of auto generated
> > > > >   entry when loading
> > > > >
> > > > > Changes in v5:
> > > > > - Return EFI_SUCCESS if there is no BootOrder defined
> > > > > - correctly handle the case if no removable device found
> > > > > - use guid to identify the automatically generated entry by bootmenu
> > > > >
> > > > >  cmd/bootmenu.c   | 106 +--
> > > > >  cmd/eficonfig.c  | 135 
> > > > > +++
> > > > >  include/efi_loader.h |  20 ++
> > > > >  lib/efi_loader/efi_bootmgr.c |   4 ++
> > > > >  4 files changed, 260 insertions(+), 5 deletions(-)
> > > > >
> > > > > diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> > > > > index 704d36debe..04df41a0cb 100644
> > > > > --- a/cmd/bootmenu.c
> > > > > +++ b/cmd/bootmenu.c
> > > > > @@ -220,7 +220,93 @@ static int prepare_bootmenu_entry(struct 
> > > > > bootmenu_data *menu,
> > > > >   return 1;
> > > > >  }
> > > > >
> > > > > -#if (CONFIG_I

[PATCH v2 2/2] timer: bcmbca: use arm global timer for bcm63138 SoC

2022-08-23 Thread William Zhang
As STI timer is renamed to ARM A9 global timer, change BCM63138 to use
the new global timer config symbol name.

This patch applies on top of the my previous patch [1].

[1]: https://lists.denx.de/pipermail/u-boot/2022-August/491060.html

Signed-off-by: William Zhang 

---

Changes in v2:
- Fix typo in the subject line and patch link in the commit message

 arch/arm/mach-bcmbca/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-bcmbca/Kconfig b/arch/arm/mach-bcmbca/Kconfig
index 27b243cbc3d8..62b371612b6a 100644
--- a/arch/arm/mach-bcmbca/Kconfig
+++ b/arch/arm/mach-bcmbca/Kconfig
@@ -29,7 +29,7 @@ config BCM4912
 config BCM63138
bool "Support for Broadcom 63138 Family"
select TIMER
-   select STI_TIMER
+   select ARM_GLOBAL_TIMER
select CPU_V7A
select DM_SERIAL
select BCM6345_SERIAL
-- 
2.37.1



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH v2 1/2] timer: sti: convert sti-timer to arm a9 global timer

2022-08-23 Thread William Zhang
STI timer is actually ARM Cortex A9 global timer. Convert the driver to
use generic global timer name and make it consistent with Linux kernel
global timer driver. This also allows any A9 based device to use this
driver.

Signed-off-by: William Zhang 
---

(no changes since v1)

 MAINTAINERS   |  2 +-
 drivers/timer/Kconfig |  8 +++--
 drivers/timer/Makefile|  2 +-
 .../timer/{sti-timer.c => arm_global_timer.c} | 30 ++-
 4 files changed, 23 insertions(+), 19 deletions(-)
 rename drivers/timer/{sti-timer.c => arm_global_timer.c} (66%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1103bb068154..f7d77bb8cfa9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -503,7 +503,7 @@ F:  drivers/mmc/sti_sdhci.c
 F: drivers/reset/sti-reset.c
 F: drivers/serial/serial_sti_asc.c
 F: drivers/sysreset/sysreset_sti.c
-F: drivers/timer/sti-timer.c
+F: drivers/timer/arm_global_timer.c
 F: drivers/usb/host/dwc3-sti-glue.c
 F: include/dwc3-sti-glue.h
 F: include/dt-bindings/clock/stih407-clks.h
diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index 20b5af7e260f..3e1d70fbb930 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -215,12 +215,14 @@ config SANDBOX_TIMER
  Select this to enable an emulated timer for sandbox. It gets
  time from host os.
 
-config STI_TIMER
-   bool "STi timer support"
+config ARM_GLOBAL_TIMER
+   bool "ARM Cortex A9 global timer support"
depends on TIMER
+   depends on ARM
default y if ARCH_STI
help
- Select this to enable a timer for STi devices.
+ Select this to enable global timer found on ARM Cortex A9
+ based devices.
 
 config STM32_TIMER
bool "STM32 timer support"
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index d9822a537009..d23569365408 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -22,7 +22,7 @@ obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o
 obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o
 obj-$(CONFIG_SANDBOX_TIMER)+= sandbox_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
-obj-$(CONFIG_STI_TIMER)+= sti-timer.o
+obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)  += stm32_timer.o
 obj-$(CONFIG_X86_TSC_TIMER)+= tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)+= mtk_timer.o
diff --git a/drivers/timer/sti-timer.c b/drivers/timer/arm_global_timer.c
similarity index 66%
rename from drivers/timer/sti-timer.c
rename to drivers/timer/arm_global_timer.c
index 87444a0650f6..065f10bb742b 100644
--- a/drivers/timer/sti-timer.c
+++ b/drivers/timer/arm_global_timer.c
@@ -2,6 +2,8 @@
 /*
  * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
  * Author(s): Patrice Chotard,  for 
STMicroelectronics.
+ *
+ * ARM Cortext A9 global timer driver
  */
 
 #include 
@@ -13,13 +15,13 @@
 #include 
 #include 
 
-struct sti_timer_priv {
+struct arm_global_timer_priv {
struct globaltimer *global_timer;
 };
 
-static u64 sti_timer_get_count(struct udevice *dev)
+static u64 arm_global_timer_get_count(struct udevice *dev)
 {
-   struct sti_timer_priv *priv = dev_get_priv(dev);
+   struct arm_global_timer_priv *priv = dev_get_priv(dev);
struct globaltimer *global_timer = priv->global_timer;
u32 low, high;
u64 timer;
@@ -37,10 +39,10 @@ static u64 sti_timer_get_count(struct udevice *dev)
return (u64)((timer << 32) | low);
 }
 
-static int sti_timer_probe(struct udevice *dev)
+static int arm_global_timer_probe(struct udevice *dev)
 {
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-   struct sti_timer_priv *priv = dev_get_priv(dev);
+   struct arm_global_timer_priv *priv = dev_get_priv(dev);
struct clk clk;
int err;
ulong ret;
@@ -66,20 +68,20 @@ static int sti_timer_probe(struct udevice *dev)
return 0;
 }
 
-static const struct timer_ops sti_timer_ops = {
-   .get_count = sti_timer_get_count,
+static const struct timer_ops arm_global_timer_ops = {
+   .get_count = arm_global_timer_get_count,
 };
 
-static const struct udevice_id sti_timer_ids[] = {
+static const struct udevice_id arm_global_timer_ids[] = {
{ .compatible = "arm,cortex-a9-global-timer" },
{}
 };
 
-U_BOOT_DRIVER(sti_timer) = {
-   .name = "sti_timer",
+U_BOOT_DRIVER(arm_global_timer) = {
+   .name = "arm_global_timer",
.id = UCLASS_TIMER,
-   .of_match = sti_timer_ids,
-   .priv_auto  = sizeof(struct sti_timer_priv),
-   .probe = sti_timer_probe,
-   .ops = &sti_timer_ops,
+   .of_match = arm_global_timer_ids,
+   .priv_auto  = sizeof(struct arm_global_timer_priv),
+   .probe = arm_global_timer_probe,
+   .ops = &arm_global_timer_ops,
 };
-- 
2.37.1



smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH v11 6/9] bootmenu: add removable media entries

2022-08-23 Thread Masahisa Kojima
Hi Akashi-san,

On Wed, 24 Aug 2022 at 10:57, Takahiro Akashi
 wrote:
>
> On Fri, Aug 19, 2022 at 12:05:50PM +0900, Masahisa Kojima wrote:
> > Hi Akashi-san,
> >
> > On Fri, 19 Aug 2022 at 10:31, Takahiro Akashi
> >  wrote:
> > >
> > > On Wed, Aug 17, 2022 at 06:36:11PM +0900, Masahisa Kojima wrote:
> > > > UEFI specification requires booting from removal media using
> > > > a architecture-specific default image name such as BOOTAA64.EFI.
> > > > This commit adds the removable media entries into bootmenu,
> > > > so that user can select the removable media and boot with
> > > > default image.
> > > >
> > > > The bootmenu automatically enumerates the possible bootable
> > > > media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
> > > > add it as new UEFI boot option(BOOT) and update BootOrder
> > > > variable. This automatically generated UEFI boot option
> > >
> > > Should this feature belong to bootmenu command?
> > > Under the current implementation, those boot options are
> > > generated only by bootmenu, and so if eficonfig is invoked
> > > prior to bootmenu, we won't see them (under "Change Boot Order").
> > >
> > > I expect that the functionality be also provided in eficonfig
> > > (or even as part of system initialization?).
> >
> > OK, generating the (removable) media boot options will be added
> > in "Change Boot Order".
>
> I found another wrong behavior. What I did was
> - eficonfig
>   it shows no boot options.
> - scsi rescan
>   One disk with two partitions was detected.
> - eficonfig
>   Now it shows two options for removal media.
>   I disabled one of two partitions from BootOrder.
> - bootmenu
>   It still shows both boot options. -> Probably okay?
> - eficonfig
>   Then a duplicated option comes up:
>   ** Change Boot Order **
>
> [*]  scsi 0:1
> [*]  scsi 0:2
> [ ]  scsi 0:2
> Save
> Quit
>
> Internally there exist three boot options now.

I have not checked this email before sending the v12 series.
I will confirm behavior.

Thanks,
Masahisa Kojima

>
> -Takahiro Akashi
>
> > Thanks,
> > Masahisa Kojima
> >
> > >
> > > -Takahiro Akashi
> > >
> > >
> > > > has the dedicated guid in the optional_data to distinguish it from
> > > > the UEFI boot option user adds manually. This optional_data is
> > > > removed when the efi bootmgr loads the selected UEFI boot option.
> > > >
> > > > This commit also provides the BOOT variable maintenance feature.
> > > > Depending on the system hardware setup, some devices
> > > > may not exist at a later system boot, so bootmenu checks the
> > > > available device in each bootmenu invocation and automatically
> > > > removes the BOOT variable corrensponding to the non-existent
> > > > media device.
> > > >
> > > > Signed-off-by: Masahisa Kojima 
> > > > ---
> > > > Changes in v11:
> > > > - update delete_boot_option() parameter
> > > >
> > > > Changes in v10:
> > > > - add function comment
> > > > - devname dynamic allocation removes, allocate in stack
> > > > - delete BOOT when updating BootOrder fails
> > > >
> > > > Changes in v9:
> > > > - update efi_disk_get_device_name() parameter to pass efi_handle_t
> > > > - add function comment
> > > >
> > > > Changes in v8:
> > > > - function and structure prefix is changed to "eficonfig"
> > > >
> > > > Changes in v7:
> > > > - rename prepare_media_device_entry() to 
> > > > generate_media_device_boot_option()
> > > >
> > > > Changes in v6:
> > > > - optional_data size is changed to 16bytes
> > > > - check the load option size before comparison
> > > > - remove guid included in optional_data of auto generated
> > > >   entry when loading
> > > >
> > > > Changes in v5:
> > > > - Return EFI_SUCCESS if there is no BootOrder defined
> > > > - correctly handle the case if no removable device found
> > > > - use guid to identify the automatically generated entry by bootmenu
> > > >
> > > >  cmd/bootmenu.c   | 106 +--
> > > >  cmd/eficonfig.c  | 135 +++
> > > >  include/efi_loader.h |  20 ++
> > > >  lib/efi_loader/efi_bootmgr.c |   4 ++
> > > >  4 files changed, 260 insertions(+), 5 deletions(-)
> > > >
> > > > diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> > > > index 704d36debe..04df41a0cb 100644
> > > > --- a/cmd/bootmenu.c
> > > > +++ b/cmd/bootmenu.c
> > > > @@ -220,7 +220,93 @@ static int prepare_bootmenu_entry(struct 
> > > > bootmenu_data *menu,
> > > >   return 1;
> > > >  }
> > > >
> > > > -#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
> > > > +#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
> > > > (CONFIG_IS_ENABLED(CMD_EFICONFIG))
> > > > +/**
> > > > + * generate_media_device_boot_option() - generate the media device 
> > > > boot option
> > > > + *
> > > > + * This function enumerates all devices supporting 
> > > > EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
> > > > + * and generate the bootmenu entries.
> > > > + * This function also provide the BOOT vari

[PATCH v12 9/9] test: unit test for eficonfig

2022-08-23 Thread Masahisa Kojima
Provide a unit test for the eficonfig command.

Signed-off-by: Masahisa Kojima 
---
Changes in v12:
- update menu handling

Changes in v11:
- fix expected result when no BootOrder is defined

Newly added in v10

 configs/sandbox_defconfig |   1 +
 test/py/tests/test_eficonfig/conftest.py  |  40 +++
 .../py/tests/test_eficonfig/test_eficonfig.py | 332 ++
 3 files changed, 373 insertions(+)
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb48..48c60c606d 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -93,6 +93,7 @@ CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
diff --git a/test/py/tests/test_eficonfig/conftest.py 
b/test/py/tests/test_eficonfig/conftest.py
new file mode 100644
index 00..f289df0362
--- /dev/null
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier:  GPL-2.0+
+
+"""Fixture for UEFI eficonfig test
+"""
+
+import os
+import shutil
+from subprocess import check_call
+import pytest
+
+@pytest.fixture(scope='session')
+def efi_eficonfig_data(u_boot_config):
+"""Set up a file system to be used in UEFI "eficonfig" command
+   tests
+
+Args:
+u_boot_config -- U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
+image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
+
+shutil.rmtree(mnt_point, ignore_errors=True)
+os.mkdir(mnt_point, mode = 0o755)
+
+with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 1")
+
+with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 2")
+
+shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+mnt_point + '/initrddump.efi')
+
+check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat 
{mnt_point} {image_path}',
+   shell=True)
+
+return image_path
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py 
b/test/py/tests/test_eficonfig/test_eficonfig.py
new file mode 100644
index 00..0edb1ec627
--- /dev/null
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -0,0 +1,332 @@
+# SPDX-License-Identifier:  GPL-2.0+
+""" Unit test for UEFI menu-driven configuration
+"""
+
+import pytest
+import time
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_eficonfig')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
+
+def send_user_input_and_wait(user_str, expect_str):
+time.sleep(0.1) # TODO: does not work correctly without sleep
+u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
+   wait_for_echo=True, send_nl=False)
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
+# press UP key
+for i in range(up_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x41', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press DOWN key
+for i in range(down_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x42', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press ENTER if requested
+if enter:
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# wait expected output
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_escape_key(wait_prompt):
+u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, 
wait_for_echo=False, send_nl=False)
+
+def press_enter_key(wait_prompt):
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+   wait_for_echo=False, send_nl=False)
+
+def check_current_is_maintenance_menu():
+for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot 
Option',
+  'Change Boot Order', 'Delete Boot Option', 'Quit'):
+u_boot_console.p.expect([i])
+
+""" Unit test for "eficonfig" command
+The menu-driven interfa

[PATCH v12 8/9] doc:eficonfig: add documentation for eficonfig command

2022-08-23 Thread Masahisa Kojima
Add documentation for eficonfig command.

Signed-off-by: Masahisa Kojima 
---
Changes in v12:
- CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE condition is added
  to show newly added boot option

No update since v10

Changes in v10:
- describe how to boot system after editting by eficonfig

Changes in v8:
- command name is changed from "efimenu" to "eficonfig"

Newly created in v7

 doc/usage/cmd/eficonfig.rst | 63 +
 doc/usage/index.rst |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 doc/usage/cmd/eficonfig.rst

diff --git a/doc/usage/cmd/eficonfig.rst b/doc/usage/cmd/eficonfig.rst
new file mode 100644
index 00..52cc7b900d
--- /dev/null
+++ b/doc/usage/cmd/eficonfig.rst
@@ -0,0 +1,63 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. (C) Copyright 2022, Masahisa Kojima 
+
+eficonfig command
+=
+
+Synopsis
+
+::
+
+eficonfig
+
+Description
+---
+
+The "eficonfig" command uses U-Boot menu interface and privides
+a menu-driven UEFI variable maintenance feature.
+The "eficonfig" has the following menu entries.
+
+Add Boot Option
+Add new UEFI Boot Option.
+User can edit description, file path, and optional_data.
+
+Edit Boot Option
+Edit the existing UEFI Boot Option
+User can edit description, file path, and optional_data.
+
+Change Boot Order
+Change the order of UEFI BootOrder variable.
+
+Delete Boot Option
+Delete the UEFI Boot Option
+
+Configuration
+-
+
+The "eficonfig" command is enabled by::
+
+CONFIG_CMD_EFICONFIG=y
+
+If CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not enter
+U-Boot console. In this case, bootmenu can be used to invoke "eficonfig"::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="setenv bootmenu_0 UEFI Maintenance Menu=eficonfig"
+
+How to boot the system with newly added UEFI Boot Option
+
+
+"eficonfig" command is responsible to configure the UEFI variables,
+not directly handle the system boot.
+The new Boot Option added by "eficonfig" is appended at the last entry
+of UEFI BootOrder variable, user may want to change the boot order
+through "Change Boot Order".
+If the bootmenu is enabled, CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled,
+and "eficonfig" is configured as preboot command, the newly added Boot Options
+are enumerated in the bootmenu when user exits from the eficonfig menu.
+User may select the entry in the bootmenu to boot the system, or follow
+the U-Boot configuration the system already has.
+
+See also
+
+* :doc:`bootmenu` provides a simple mechanism for creating menus 
with different boot items
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 28f9683a3e..09f2928970 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -35,6 +35,7 @@ Shell commands
cmd/conitrace
cmd/dm
cmd/echo
+   cmd/eficonfig
cmd/env
cmd/event
cmd/exception
-- 
2.17.1



[PATCH v12 7/9] doc:bootmenu: add description for UEFI boot support

2022-08-23 Thread Masahisa Kojima
The bootmenu enumerates the UEFI boot options
for boot device selection.
This commit adds the description how the UEFI boot work
in bootmenu. This commit also adds "Synopsis", "Description"
and "Configuration" sections to follow the U-Boot command
documentation format.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Ilias Apalodimas 
---
No update since v10

Changes in v10:
- fix typos

Changes in v7:
- update the description what bootmenu do for uefi-related boot menu
- add default behavior when user exits from bootmenu

Changes in v6:
- remove distro boot related contents because the distro boot
support in bootmenu is dropped
- update uefi entry example
- add [delay] argument of bootmenu command
- add description to enable uefi boot entry

Changes in v5:
- follow the cmd documentation format same as other command, add "Synopsis",
  "Description" add "Configuration" sections

Newly created in v4

 doc/usage/cmd/bootmenu.rst | 74 ++
 1 file changed, 74 insertions(+)

diff --git a/doc/usage/cmd/bootmenu.rst b/doc/usage/cmd/bootmenu.rst
index 9430f8c9aa..cb3c8d2f93 100644
--- a/doc/usage/cmd/bootmenu.rst
+++ b/doc/usage/cmd/bootmenu.rst
@@ -4,6 +4,15 @@
 bootmenu command
 
 
+Synopsis
+
+::
+
+bootmenu [delay]
+
+Description
+---
+
 The "bootmenu" command uses U-Boot menu interfaces and provides
 a simple mechanism for creating menus with different boot items.
 The cursor keys "Up" and "Down" are used for navigation through
@@ -79,6 +88,55 @@ The above example will be rendered as below::
 The selected menu entry will be highlighted - it will have inverted
 background and text colors.
 
+UEFI boot variable enumeration
+''
+If enabled, the bootmenu command will automatically generate and add
+UEFI-related boot menu entries for the following items.
+
+ * possible bootable media with default file names
+ * user-defined UEFI boot options
+
+The bootmenu automatically enumerates the possible bootable
+media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.
+This auto generated entry is named as " :" format.
+(e.g. "usb 0:1")
+
+The bootmenu displays the UEFI-related menu entries in order of "BootOrder".
+When the user selects the UEFI boot menu entry, the bootmenu sets
+the selected boot variable index to "BootNext" without non-volatile attribute,
+then call the uefi boot manager with the command "bootefi bootmgr".
+
+Example bootmenu is as below::
+
+*** U-Boot Boot Menu ***
+
+   mmc 0:1
+   mmc 0:2
+   debian
+   nvme 0:1
+   ubuntu
+   nvme 0:2
+   usb 0:2
+   U-Boot console
+
+Default behavior when user exits from the bootmenu
+~~
+User can exit from bootmenu by selecting the last entry
+"U-Boot console"/"Quit" or ESC/CTRL+C key.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is disabled,
+user exits from the bootmenu and returns to the U-Boot console.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not
+enter the U-Boot console. When the user exits from the bootmenu,
+the bootmenu invokes the following default behavior.
+
+ * if CONFIG_CMD_BOOTEFI_BOOTMGR is enabled, execute "bootefi bootmgr" command
+ * "bootefi bootmgr" fails or is not enabled, then execute "run bootcmd" 
command.
+
+Configuration
+-
+
 The "bootmenu" command is enabled by::
 
 CONFIG_CMD_BOOTMENU=y
@@ -88,3 +146,19 @@ To run the bootmenu at startup add these additional 
settings::
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_BOOTDELAY=30
 CONFIG_AUTOBOOT_MENU_SHOW=y
+
+UEFI boot variable enumeration is enabled by::
+
+CONFIG_CMD_BOOTEFI_BOOTMGR=y
+
+To improve the product security, entering U-Boot console from bootmenu
+can be disabled by::
+
+CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
+
+To scan the discoverable devices connected to the buses such as
+USB and PCIe prior to bootmenu showing up, CONFIG_PREBOOT can be
+used to run the command before showing the bootmenu, i.e.::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="pci enum; usb start; scsi scan; nvme scan; virtio scan"
-- 
2.17.1



[PATCH v12 6/9] eficonfig: add "Change Boot Order" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to update UEFI BootOrder variable.
User moves the entry with UP/DOWN key, changes the order
with PLUS/MINUS key, press SPACE to activate or deactivate
the entry, then finalizes the order by ENTER key.
If the entry is activated, the boot index is added into the
BootOrder variable in the order of the list.

The U-Boot menu framework is well designed for static menu,
this commit implements the own menu display and key handling
for dynamically change the order of menu entry.

Signed-off-by: Masahisa Kojima 
---
Changes in v12:
- enumerate removable media device

Changes in v11:
- remove BootOrder variable dependency
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.
- add KEY_SPACE to toggle the boot option active status

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- add "Save" and "Quit" entries

Changes in v7:
- use UP/DOWN and PLUS/MINUS key to change to order

no update in v6:

 cmd/eficonfig.c | 351 +++-
 1 file changed, 350 insertions(+), 1 deletion(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 240f343421..2ddfd61638 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -91,6 +91,23 @@ struct eficonfig_boot_selection_data {
int *selected;
 };
 
+/**
+ * struct eficonfig_boot_order - structure to be used to update BootOrder 
variable
+ *
+ * @num:   index in the menu entry
+ * @description:   pointer to the description string
+ * @boot_index:boot option index
+ * @active:flag to include the boot option into BootOrder variable
+ * @list:  list structure
+ */
+struct eficonfig_boot_order {
+   u32 num;
+   u16 *description;
+   u32 boot_index;
+   bool active;
+   struct list_head list;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1716,6 +1733,338 @@ out:
return ret;
 }
 
+/**
+ * eficonfig_display_change_boot_order() - display the BootOrder list
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)
+{
+   bool reverse;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *entry;
+
+   printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION
+  "\n  ** Change Boot Order **\n"
+  ANSI_CURSOR_POSITION
+  "  Press UP/DOWN to move, +/- to change order"
+  ANSI_CURSOR_POSITION
+  "  Press SPACE to activate or deactivate the entry"
+  ANSI_CURSOR_POSITION
+  "  Select [Save] to complete, ESC/CTRL+C to quit"
+  ANSI_CURSOR_POSITION ANSI_CLEAR_LINE,
+  1, 1, efi_menu->count + 5, 1, efi_menu->count + 6, 1,
+  efi_menu->count + 7, 1,  efi_menu->count + 8, 1);
+
+   /* draw boot option list */
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct eficonfig_boot_order, list);
+   reverse = (entry->num == efi_menu->active);
+
+   printf(ANSI_CURSOR_POSITION, entry->num + 4, 7);
+
+   if (reverse)
+   puts(ANSI_COLOR_REVERSE);
+
+   if (entry->num < efi_menu->count - 2) {
+   if (entry->active)
+   printf("[*]  ");
+   else
+   printf("[ ]  ");
+   }
+
+   printf("%ls", entry->description);
+
+   if (reverse)
+   puts(ANSI_COLOR_RESET);
+   }
+}
+
+/**
+ * eficonfig_choice_change_boot_order() - handle the BootOrder update
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static efi_status_t eficonfig_choice_change_boot_order(struct efimenu 
*efi_menu)
+{
+   int esc = 0;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *tmp;
+   enum bootmenu_key key = KEY_NONE;
+   struct eficonfig_boot_order *entry;
+
+   while (1) {
+   bootmenu_loop(NULL, &key, &esc);
+
+   switch (key) {
+   case KEY_PLUS:
+   if (efi_menu->active > 0) {
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct 
eficonfig_boot_order, list);
+   if (entry->num == efi_menu->active)
+   break;
+   }
+   tmp = list_entry(pos->prev, struct 
eficonfig_boot_order, list);
+   entry->num--;
+   tmp->num++;
+   list_del(&tmp->

[PATCH v12 5/9] bootmenu: add removable media entries

2022-08-23 Thread Masahisa Kojima
UEFI specification requires booting from removal media using
a architecture-specific default image name such as BOOTAA64.EFI.
This commit adds the removable media entries into bootmenu,
so that user can select the removable media and boot with
default image.

The bootmenu automatically enumerates the possible bootable
media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
add it as new UEFI boot option(BOOT) and update BootOrder
variable. This automatically generated UEFI boot option
has the dedicated guid in the optional_data to distinguish it from
the UEFI boot option user adds manually. This optional_data is
removed when the efi bootmgr loads the selected UEFI boot option.

This commit also provides the BOOT variable maintenance feature.
Depending on the system hardware setup, some devices
may not exist at a later system boot, so bootmenu checks the
available device in each bootmenu invocation and automatically
removes the BOOT variable corrensponding to the non-existent
media device.

Signed-off-by: Masahisa Kojima 
---
Changes in v12:
- move generate_media_device_boot_option into cmd/eficonfig.c and expose it
- remove unnecessary include file

Changes in v11:
- update delete_boot_option() parameter

Changes in v10:
- add function comment
- devname dynamic allocation removes, allocate in stack
- delete BOOT when updating BootOrder fails

Changes in v9:
- update efi_disk_get_device_name() parameter to pass efi_handle_t
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- rename prepare_media_device_entry() to generate_media_device_boot_option()

Changes in v6:
- optional_data size is changed to 16bytes
- check the load option size before comparison
- remove guid included in optional_data of auto generated
  entry when loading

Changes in v5:
- Return EFI_SUCCESS if there is no BootOrder defined
- correctly handle the case if no removable device found
- use guid to identify the automatically generated entry by bootmenu

 cmd/bootmenu.c   |  22 +++-
 cmd/eficonfig.c  | 222 +++
 include/efi_config.h |   1 +
 include/efi_loader.h |  16 +++
 lib/efi_loader/efi_bootmgr.c |   4 +
 5 files changed, 259 insertions(+), 6 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 704d36debe..3340be1632 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -220,7 +220,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
return 1;
 }
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
 /**
  * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries
  *
@@ -340,11 +340,21 @@ static struct bootmenu_data *bootmenu_create(int delay)
if (ret < 0)
goto cleanup;
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
if (i < MAX_COUNT - 1) {
-   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
-   if (ret < 0 && ret != -ENOENT)
-   goto cleanup;
+   efi_status_t efi_ret;
+
+   /*
+* UEFI specification requires booting from removal media using
+* a architecture-specific default image name such as 
BOOTAA64.EFI.
+*/
+   efi_ret = eficonfig_generate_media_device_boot_option();
+   if (efi_ret != EFI_SUCCESS && efi_ret != EFI_NOT_FOUND)
+   goto cleanup;
+
+   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
+   if (ret < 0 && ret != -ENOENT)
+   goto cleanup;
}
 #endif
 
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 537f3f2bbc..240f343421 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1786,6 +1786,228 @@ static efi_status_t 
eficonfig_process_delete_boot_option(void *data)
return ret;
 }
 
+/**
+ * eficonfig_enumerate_boot_option() - enumerate the possible bootable media
+ *
+ * @opt:   pointer to the media boot option structure
+ * @volume_handles:pointer to the efi handles
+ * @count: number of efi handle
+ * Return: status code
+ */
+efi_status_t eficonfig_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
+efi_handle_t *volume_handles, 
efi_status_t count)
+{
+   u32 i;
+   struct efi_handler *handler;
+   efi_status_t ret = EFI_SUCCESS;
+
+   for (i = 0; i < count; i++) {
+   u16 *p;
+   u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
+   char *optional_data;
+   struct efi_load_option lo;
+   char buf[BOOTMENU_DEVICE_NA

[PATCH v12 4/9] eficonfig: add "Delete Boot Option" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to delete the UEFI boot option.
User moves the entry with UP/DOWN key, changes, then presses
ENTER key to delete the selected boot option.

Signed-off-by: Masahisa Kojima 
---
No update since v11

Changes in v11:
- update function interface to show boot selection menu
- support to delete the load option is not included in BootOrder

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- to stay the boot order list after user delete the entry

no update in v6:

changes in v5:

 cmd/eficonfig.c | 71 +
 1 file changed, 71 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 22389b537f..537f3f2bbc 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1716,6 +1716,76 @@ out:
return ret;
 }
 
+/**
+ * delete_boot_option() - delete selected boot option
+ *
+ * @boot_index:boot option index to delete
+ * Return: status code
+ */
+static efi_status_t delete_boot_option(u16 boot_index)
+{
+   u16 *bootorder;
+   u16 varname[9];
+   efi_status_t ret;
+   unsigned int index;
+   efi_uintn_t num, size;
+
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", boot_index);
+   ret = efi_set_variable_int(varname, &efi_global_variable_guid,
+  0, 0, NULL, false);
+   if (ret != EFI_SUCCESS) {
+   log_err("delete boot option(%ls) failed\n", varname);
+   return ret;
+   }
+
+   /* update BootOrder if necessary */
+   bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
+   if (!bootorder)
+   return EFI_SUCCESS;
+
+   num = size / sizeof(u16);
+   if (!search_bootorder(bootorder, num, boot_index, &index))
+   return EFI_SUCCESS;
+
+   memmove(&bootorder[index], &bootorder[index + 1],
+   (num - index - 1) * sizeof(u16));
+   size -= sizeof(u16);
+   ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  size, bootorder, false);
+
+   return ret;
+}
+
+/**
+ * eficonfig_process_delete_boot_option() - handler to delete boot option
+ *
+ * @data:  pointer to the data for each entry
+ * Return: status code
+ */
+static efi_status_t eficonfig_process_delete_boot_option(void *data)
+{
+   efi_status_t ret;
+   unsigned int selected;
+
+   while (1) {
+   ret = eficonfig_show_boot_selection(&selected);
+   if (ret == EFI_SUCCESS)
+   ret = delete_boot_option(selected);
+
+   if (ret != EFI_SUCCESS)
+   break;
+   }
+
+   /* to stay the parent menu */
+   ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
+
+   return ret;
+}
+
 /**
  * eficonfig_init() - do required initialization for eficonfig command
  *
@@ -1746,6 +1816,7 @@ static efi_status_t eficonfig_init(void)
 static const struct eficonfig_item maintenance_menu_items[] = {
{"Add Boot Option", eficonfig_process_add_boot_option},
{"Edit Boot Option", eficonfig_process_edit_boot_option},
+   {"Delete Boot Option", eficonfig_process_delete_boot_option},
{"Quit", eficonfig_process_quit},
 };
 
-- 
2.17.1



[PATCH v12 3/9] menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling

2022-08-23 Thread Masahisa Kojima
This is preparation to support menu-driven UEFI BootOrder
variable updated by KEY_PLUS, KEY_MINUS and KEY_SPACE.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Heinrich Schuchardt 
Reviewed-by: Ilias Apalodimas 
---
No update since v11

Changes in v11:
- add SPACE key handling

Newly created in v7

 common/menu.c  | 9 +
 include/menu.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/common/menu.c b/common/menu.c
index 3e876b55b3..0d19601cf5 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -548,4 +548,13 @@ void bootmenu_loop(struct bootmenu_data *menu,
/* ^C was pressed */
if (c == 0x3)
*key = KEY_QUIT;
+
+   if (c == '+')
+   *key = KEY_PLUS;
+
+   if (c == '-')
+   *key = KEY_MINUS;
+
+   if (c == ' ')
+   *key = KEY_SPACE;
 }
diff --git a/include/menu.h b/include/menu.h
index e74616cae8..702aacb170 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -48,6 +48,9 @@ enum bootmenu_key {
KEY_DOWN,
KEY_SELECT,
KEY_QUIT,
+   KEY_PLUS,
+   KEY_MINUS,
+   KEY_SPACE,
 };
 
 void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-- 
2.17.1



[PATCH v12 1/9] eficonfig: menu-driven addition of UEFI boot option

2022-08-23 Thread Masahisa Kojima
This commit add the "eficonfig" command.
The "eficonfig" command implements the menu-driven UEFI boot option
maintenance feature. This commit implements the addition of
new boot option. User can select the block device volume having
efi_simple_file_system_protocol and select the file corresponding
to the Boot variable. User can also enter the description and
optional_data of the BOOT variable in utf8.

This commit adds "include/efi_config.h", it contains the common
definition to be used from other menus such as UEFI Secure Boot
key management.

Signed-off-by: Masahisa Kojima 
---
Changes in v12:
- add select/clear menu before displaying volume selectio
- move function declaration from efi_loader.h to efi_config.h
- remove unused declaration
- support the boot option does not have file path
- correctly handle if optional_data is empty

Changes in v11:
- refactor menu entry construction, directly use eficonfig_entry structure
- remove reading directory info to calculate the number of entry
- fix invalid efi_free_pool() in ill_file_info()
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.

Changes in v10:
- add initrd file selection
- do refactoring
- eficonfig_process_common() use list structure
- remove u'/' before copying file_path into current_path
- fix typos
- check snprintf error

Changes in v9:
- move "efi_guid_bootmenu_auto_generated definition" into efi_bootmgr.c
  to address build error when CMD_EFICONFIG is disabled
- fix typos and comment
- remove file system information from error message
- remove unreachable code in eficonfig_choice_entry()
- single printf() call as much as possible
- call only getchar() in  eficonfig_print_msg()
- filter out '.' entry from file selection
- update the efi_disk_get_device_name() implementation
- add function comment

Changes in v8:
- command name is change from "efimenu" to "eficonfig"
- function and struct prefixes is changed to "eficonfig"
- fix menu header string

Changes in v7:
- add "efimenu" command and uefi variable maintenance code
  moved into cmd/efimenu.c
- create include/efimenu.h to define the common definition for
  the other menu such as UEFI Secure Boot key management
- update boot option edit UI, user can select description, file,
  and optional_data to edit in the same menu like following.

  ** Edit Boot Option **

 Description: debian
 File: virtio 0:1/EFI\debian\grubaa64.efi
 Optional Data: test
 Save
 Quit

- remove exit parameter from efimenu_process_common()
- menu title type is changed from u16 to char
- efimenu_process_common() add menu title string
- reduce printf/puts function call for displaying the menu
- efi_console_get_u16_string() accept 0 length to allow
  optional_data is empty
- efi_console_get_u16_string() the "size" parameter name is changes to "count"
- efimenu is now designed to maintain the UEFI variables, remove autoboot 
related code
- remove one empty line before "Quit" entry
- efimenu_init() processes only the first time

Changes in v6:
- fix typos
- modify volume name to match U-Boot syntax
- compile in CONFIG_EFI_LOADER=n and CONFIG_CMD_BOOTEFI_BOOTMGR=n
- simplify u16_strncmp() usage
- support "a\b.efi" file path, use link list to handle filepath
- modify length check condition
- UEFI related menu items only appears with CONFIG_AUTOBOOT_MENU_SHOW=y

Changes in v5:
- remove forward declarations
- add const qualifier for menu items
- fix the possible unaligned access for directory info access
- split into three commit 1)add boot option 2) delete boot option 3)change boot 
order
  This commit is 1)add boot option.
- fix file name buffer allocation size, it should be EFI_BOOTMENU_FILE_PATH_MAX 
* sizeof(u16)
- fix wrong size checking for file selection

Chanes in v4:
- UEFI boot option maintenance menu is integrated into bootmenu
- display the simplified volume name(e.g. usb0:1, nvme1:2) for the
  volume selection
- instead of extending lib/efi_loader/efi_bootmgr.c, newly create
  lib/efi_loader/efi_bootmenu_maintenance.c and implement boot
  variable maintenance into it.

Changes in RFC v3:
 not included in v3 series

Changes in RFC v2:
- enable utf8 user input for boot option name
- create lib/efi_loader/efi_console.c::efi_console_get_u16_string() for
  utf8 user input handling
- use u16_strlcat instead of u16_strcat
- remove the EFI_CALLs, and newly create or expose the following
  xxx_int() functions.
efi_locate_handle_buffer_int(), efi_open_volume_int(),
efi_file_open_int(), efi_file_close_int(), efi_file_read_int() and
efi_file_setpos_int().
  Note that EFI_CALLs still exist for EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
  and EFI_SIMPLE_TEXT_INPUT/OUTPUT_PROTOCOL
- use efi_search_protocol() instead of calling locate_protocol() to get
  the device_path_to_text_protocol interface.
- remove unnecessary puts(ANSI_CL

[PATCH v12 2/9] eficonfig: add "Edit Boot Option" menu entry

2022-08-23 Thread Masahisa Kojima
This commit adds the menu entry to edit the existing
BOOT variable contents.
User selects the item from the boot option list, then
user can edit the description, file path and optional_data.

Note that automatically generated boot option entry by bootmenu
to support the removable media device is filtered out and user
can not edit the automatically generated entry.

Signed-off-by: Masahisa Kojima 
---
No update since v11

Changes in v11:
- remove BootOrder variable dependency
- change the list load option order
   1) in the order of BootOrder
   2) remaing load option that is not included in the BootOrder
- add check for the number of menu entry exceeds max
- truncate the long load option label when user edits
- add EFICONFIG_VOLUME_PATH_MAX to display text converted volume
  device path in case the volume does not exist

Changes in v10:
- update eficonfig_edit_boot_option() argument

Changes in v9:
- add function comment

Changes in v8:
- fix menu header string
- fix function and structure prefix to "eficonfig"

Newly created in v7

 cmd/eficonfig.c  | 277 +--
 include/efi_config.h |   1 +
 2 files changed, 269 insertions(+), 9 deletions(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 9709222378..22389b537f 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -40,7 +40,7 @@ struct eficonfig_filepath_info {
  *
  * @file_info: user selected file info
  * @initrd_info:   user selected initrd file info
- * @boot_index:index of the UEFI BootOrder variable
+ * @boot_index:index of the boot option
  * @description:   pointer to the description string
  * @optional_data: pointer to the optional_data
  * @edit_completed:flag indicates edit complete
@@ -80,6 +80,17 @@ struct eficonfig_file_entry_data {
u16 *file_name;
 };
 
+/**
+ * struct eficonfig_boot_selection_data - structure to be used to select the 
boot option entry
+ *
+ * @boot_index:index of the boot option
+ * @selected:  pointer to store the selected index in the BootOrder 
variable
+ */
+struct eficonfig_boot_selection_data {
+   u16 boot_index;
+   int *selected;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1143,34 +1154,58 @@ static efi_status_t prepare_file_selection_entry(struct 
efimenu *efi_menu, char
 {
u32 len;
efi_status_t ret;
-   u16 *file_name, *p;
+   u16 *file_name = NULL, *p;
efi_handle_t handle;
-   char devname[BOOTMENU_DEVICE_NAME_MAX] = {0};
+   char *devname;
+
+   devname = calloc(1, EFICONFIG_VOLUME_PATH_MAX + 1);
+   if (!devname)
+   return EFI_OUT_OF_RESOURCES;
 
/* get the device name only when the user already selected the file 
path */
handle = efi_dp_find_obj(file_info->dp_volume, NULL, NULL);
if (handle) {
-   ret = efi_disk_get_device_name(handle, devname, 
BOOTMENU_DEVICE_NAME_MAX);
+   ret = efi_disk_get_device_name(handle, devname, 
EFICONFIG_VOLUME_PATH_MAX);
if (ret != EFI_SUCCESS)
-   return ret;
+   goto out;
+   }
+
+   /*
+* If the preconfigured volume does not exist in the system, display 
the text
+* converted volume device path instead of U-Boot friendly name(e.g. 
"usb 0:1").
+*/
+   if (!handle && file_info->dp_volume) {
+   u16 *dp_str;
+   char *q = devname;
+
+   dp_str = efi_dp_str(file_info->dp_volume);
+   if (dp_str)
+   utf16_utf8_strncpy(&q, dp_str, 
EFICONFIG_VOLUME_PATH_MAX);
+
+   efi_free_pool(dp_str);
}
 
/* append u'/' to devname, it is just for display purpose. */
if (file_info->current_path[0] != u'\0' && file_info->current_path[0] 
!= u'/')
-   strlcat(devname, "/", BOOTMENU_DEVICE_NAME_MAX);
+   strlcat(devname, "/", EFICONFIG_VOLUME_PATH_MAX + 1);
 
len = strlen(devname);
len += utf16_utf8_strlen(file_info->current_path) + 1;
file_name = calloc(1, len * sizeof(u16));
-   if (!file_name)
-   return ret;
+   if (!file_name) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
 
p = file_name;
utf8_utf16_strcpy(&p, devname);
u16_strlcat(file_name, file_info->current_path, len);
ret = create_boot_option_entry(efi_menu, title, file_name,
   eficonfig_select_file_handler, 
file_info);
+out:
+   free(devname);
free(file_name);
+
return ret;
 }
 
@@ -1337,10 +1372,14 @@ static efi_status_t eficonfig_edit_boot_option(u16 
*varname, struct eficonfig_bo
if (ret != EFI_SUCCESS)
goto out;
 
-   if (!lo.label || (lo.label && u16_strlen(lo.label) >= 
EFICONFIG_DESCRIPTION_MAX)) {
+   if (!lo.label) {

[PATCH v12 0/9] enable menu-driven UEFI variable maintenance

2022-08-23 Thread Masahisa Kojima
This series adds the menu-driven UEFI boot variable maintenance
through the "eficonfig" new command.
This series also adds the removable media support in bootmenu.

Initrd file selection and python based unit test are added in v10.

Source code can be cloned with:
$ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git -b 
kojima/eficonfig_upstream_v12

[Major Changes]
- there is detailed changelog in each commit

Masahisa Kojima (9):
  eficonfig: menu-driven addition of UEFI boot option
  eficonfig: add "Edit Boot Option" menu entry
  menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling
  eficonfig: add "Delete Boot Option" menu entry
  bootmenu: add removable media entries
  eficonfig: add "Change Boot Order" menu entry
  doc:bootmenu: add description for UEFI boot support
  doc:eficonfig: add documentation for eficonfig command
  test: unit test for eficonfig

 cmd/Kconfig   |7 +
 cmd/Makefile  |1 +
 cmd/bootmenu.c|   22 +-
 cmd/eficonfig.c   | 2443 +
 common/menu.c |9 +
 configs/sandbox_defconfig |1 +
 doc/usage/cmd/bootmenu.rst|   74 +
 doc/usage/cmd/eficonfig.rst   |   63 +
 doc/usage/index.rst   |1 +
 include/efi_config.h  |   97 +
 include/efi_loader.h  |   53 +
 include/menu.h|3 +
 lib/efi_loader/efi_bootmgr.c  |7 +
 lib/efi_loader/efi_boottime.c |   52 +-
 lib/efi_loader/efi_console.c  |   70 +
 lib/efi_loader/efi_disk.c |   50 +
 lib/efi_loader/efi_file.c |   75 +-
 test/py/tests/test_eficonfig/conftest.py  |   40 +
 .../py/tests/test_eficonfig/test_eficonfig.py |  332 +++
 19 files changed, 3347 insertions(+), 53 deletions(-)
 create mode 100644 cmd/eficonfig.c
 create mode 100644 doc/usage/cmd/eficonfig.rst
 create mode 100644 include/efi_config.h
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

-- 
2.17.1



Re: mvebu - switch to orion-timer

2022-08-23 Thread Tony Dinh
Hi Stefan,

I would like to see this too. I was thinking of doing it per board,
but it is more appropriate to enable it for Arch_Kirkwood and
Arch_MVEBU.

Thanks,
Tony

On Tue, Aug 23, 2022 at 3:33 PM Pali Rohár  wrote:
>
> Hello Stefan! Now when U-Boot contains new orion-timer.c driver, which
> Michael wrote, I think that it mvebu platform should switch to use it.
> Because build process for armada boards prints deprecation warning that
> new timer is not being used. Could you look at it, if it is possible to
> do global switch for mach-mvebu and mach-kirkwood? I think it does not
> make sense to do per-board switching as it is de-facto platform related
> code.


Re: [PATCH v11 6/9] bootmenu: add removable media entries

2022-08-23 Thread Takahiro Akashi
On Fri, Aug 19, 2022 at 12:05:50PM +0900, Masahisa Kojima wrote:
> Hi Akashi-san,
> 
> On Fri, 19 Aug 2022 at 10:31, Takahiro Akashi
>  wrote:
> >
> > On Wed, Aug 17, 2022 at 06:36:11PM +0900, Masahisa Kojima wrote:
> > > UEFI specification requires booting from removal media using
> > > a architecture-specific default image name such as BOOTAA64.EFI.
> > > This commit adds the removable media entries into bootmenu,
> > > so that user can select the removable media and boot with
> > > default image.
> > >
> > > The bootmenu automatically enumerates the possible bootable
> > > media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
> > > add it as new UEFI boot option(BOOT) and update BootOrder
> > > variable. This automatically generated UEFI boot option
> >
> > Should this feature belong to bootmenu command?
> > Under the current implementation, those boot options are
> > generated only by bootmenu, and so if eficonfig is invoked
> > prior to bootmenu, we won't see them (under "Change Boot Order").
> >
> > I expect that the functionality be also provided in eficonfig
> > (or even as part of system initialization?).
> 
> OK, generating the (removable) media boot options will be added
> in "Change Boot Order".

I found another wrong behavior. What I did was
- eficonfig
  it shows no boot options.
- scsi rescan
  One disk with two partitions was detected.
- eficonfig
  Now it shows two options for removal media.
  I disabled one of two partitions from BootOrder.
- bootmenu
  It still shows both boot options. -> Probably okay?
- eficonfig
  Then a duplicated option comes up:
  ** Change Boot Order **

[*]  scsi 0:1
[*]  scsi 0:2
[ ]  scsi 0:2
Save
Quit

Internally there exist three boot options now.

-Takahiro Akashi

> Thanks,
> Masahisa Kojima
> 
> >
> > -Takahiro Akashi
> >
> >
> > > has the dedicated guid in the optional_data to distinguish it from
> > > the UEFI boot option user adds manually. This optional_data is
> > > removed when the efi bootmgr loads the selected UEFI boot option.
> > >
> > > This commit also provides the BOOT variable maintenance feature.
> > > Depending on the system hardware setup, some devices
> > > may not exist at a later system boot, so bootmenu checks the
> > > available device in each bootmenu invocation and automatically
> > > removes the BOOT variable corrensponding to the non-existent
> > > media device.
> > >
> > > Signed-off-by: Masahisa Kojima 
> > > ---
> > > Changes in v11:
> > > - update delete_boot_option() parameter
> > >
> > > Changes in v10:
> > > - add function comment
> > > - devname dynamic allocation removes, allocate in stack
> > > - delete BOOT when updating BootOrder fails
> > >
> > > Changes in v9:
> > > - update efi_disk_get_device_name() parameter to pass efi_handle_t
> > > - add function comment
> > >
> > > Changes in v8:
> > > - function and structure prefix is changed to "eficonfig"
> > >
> > > Changes in v7:
> > > - rename prepare_media_device_entry() to 
> > > generate_media_device_boot_option()
> > >
> > > Changes in v6:
> > > - optional_data size is changed to 16bytes
> > > - check the load option size before comparison
> > > - remove guid included in optional_data of auto generated
> > >   entry when loading
> > >
> > > Changes in v5:
> > > - Return EFI_SUCCESS if there is no BootOrder defined
> > > - correctly handle the case if no removable device found
> > > - use guid to identify the automatically generated entry by bootmenu
> > >
> > >  cmd/bootmenu.c   | 106 +--
> > >  cmd/eficonfig.c  | 135 +++
> > >  include/efi_loader.h |  20 ++
> > >  lib/efi_loader/efi_bootmgr.c |   4 ++
> > >  4 files changed, 260 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> > > index 704d36debe..04df41a0cb 100644
> > > --- a/cmd/bootmenu.c
> > > +++ b/cmd/bootmenu.c
> > > @@ -220,7 +220,93 @@ static int prepare_bootmenu_entry(struct 
> > > bootmenu_data *menu,
> > >   return 1;
> > >  }
> > >
> > > -#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
> > > +#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
> > > (CONFIG_IS_ENABLED(CMD_EFICONFIG))
> > > +/**
> > > + * generate_media_device_boot_option() - generate the media device boot 
> > > option
> > > + *
> > > + * This function enumerates all devices supporting 
> > > EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
> > > + * and generate the bootmenu entries.
> > > + * This function also provide the BOOT variable maintenance for
> > > + * the media device entries.
> > > + *   - Automatically create the BOOT variable for the newly detected 
> > > device,
> > > + * this BOOT variable is distinguished by the special GUID
> > > + * stored in the EFI_LOAD_OPTION.optional_data
> > > + *   - If the device is not attached to the system, the associated 
> > > BOOT variable
> > > + * is automatically deleted.
> > > + *
> 

[PATCH] kontron-sl-mx8mm: Let CONFIG_SPL_FIT_IMAGE_TINY be selected

2022-08-23 Thread Fabio Estevam
When CONFIG_IMX_HAB is selected the 'hab_status' command reports several
error events, indicating that the BootROM failed to authenticate the SPL.

After inspecting the content of the memory location that corresponds to
the DTB load address, the content did not match with the DTB binary,
showing that some kind of memory corruption/overlap occurred.

Letting the CONFIG_SPL_FIT_IMAGE_TINY option to be selected causes the
DTB to be properly placed into RAM and no more overlap occurs.

With this change, the 'hab_status' command returns no more error events,
which indicates that the BootROM succeeded to authenticate the SPL.

Signed-off-by: Fabio Estevam 
---
 configs/kontron-sl-mx8mm_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/kontron-sl-mx8mm_defconfig 
b/configs/kontron-sl-mx8mm_defconfig
index 5387f65926f6..f8589b010cce 100644
--- a/configs/kontron-sl-mx8mm_defconfig
+++ b/configs/kontron-sl-mx8mm_defconfig
@@ -39,7 +39,6 @@ CONFIG_CUSTOM_SYS_SPL_MALLOC_ADDR=0x4220
 CONFIG_SYS_SPL_MALLOC_SIZE=0x8
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x300
-# CONFIG_SPL_FIT_IMAGE_TINY is not set
 CONFIG_SPL_I2C=y
 CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_POWER=y
-- 
2.25.1



[PATCH 2/2] timer: bcmbca: use arm global timer for bcm63138 SoS

2022-08-23 Thread William Zhang
As STI timer is renamed to ARM A9 global timer, change BCM63138 to use
the new global timer config symbol name.

This patch applies on top of the my previous patch [1].

[1]: https://lists.denx.de/pipermail/u-boot/2022-August//491060.html

Signed-off-by: William Zhang 

---

 arch/arm/mach-bcmbca/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-bcmbca/Kconfig b/arch/arm/mach-bcmbca/Kconfig
index 27b243cbc3d8..62b371612b6a 100644
--- a/arch/arm/mach-bcmbca/Kconfig
+++ b/arch/arm/mach-bcmbca/Kconfig
@@ -29,7 +29,7 @@ config BCM4912
 config BCM63138
bool "Support for Broadcom 63138 Family"
select TIMER
-   select STI_TIMER
+   select ARM_GLOBAL_TIMER
select CPU_V7A
select DM_SERIAL
select BCM6345_SERIAL
-- 
2.37.1



smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH 1/2] timer: sti: convert sti-timer to arm a9 global timer

2022-08-23 Thread William Zhang
STI timer is actually ARM Cortex A9 global timer. Convert the driver to
use generic global timer name and make it consistent with Linux kernel
global timer driver. This also allows any A9 based device to use this
driver.

Signed-off-by: William Zhang 
---

 MAINTAINERS   |  2 +-
 drivers/timer/Kconfig |  8 +++--
 drivers/timer/Makefile|  2 +-
 .../timer/{sti-timer.c => arm_global_timer.c} | 30 ++-
 4 files changed, 23 insertions(+), 19 deletions(-)
 rename drivers/timer/{sti-timer.c => arm_global_timer.c} (66%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1103bb068154..f7d77bb8cfa9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -503,7 +503,7 @@ F:  drivers/mmc/sti_sdhci.c
 F: drivers/reset/sti-reset.c
 F: drivers/serial/serial_sti_asc.c
 F: drivers/sysreset/sysreset_sti.c
-F: drivers/timer/sti-timer.c
+F: drivers/timer/arm_global_timer.c
 F: drivers/usb/host/dwc3-sti-glue.c
 F: include/dwc3-sti-glue.h
 F: include/dt-bindings/clock/stih407-clks.h
diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index 20b5af7e260f..3e1d70fbb930 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -215,12 +215,14 @@ config SANDBOX_TIMER
  Select this to enable an emulated timer for sandbox. It gets
  time from host os.
 
-config STI_TIMER
-   bool "STi timer support"
+config ARM_GLOBAL_TIMER
+   bool "ARM Cortex A9 global timer support"
depends on TIMER
+   depends on ARM
default y if ARCH_STI
help
- Select this to enable a timer for STi devices.
+ Select this to enable global timer found on ARM Cortex A9
+ based devices.
 
 config STM32_TIMER
bool "STM32 timer support"
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index d9822a537009..d23569365408 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -22,7 +22,7 @@ obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o
 obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o
 obj-$(CONFIG_SANDBOX_TIMER)+= sandbox_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
-obj-$(CONFIG_STI_TIMER)+= sti-timer.o
+obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)  += stm32_timer.o
 obj-$(CONFIG_X86_TSC_TIMER)+= tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)+= mtk_timer.o
diff --git a/drivers/timer/sti-timer.c b/drivers/timer/arm_global_timer.c
similarity index 66%
rename from drivers/timer/sti-timer.c
rename to drivers/timer/arm_global_timer.c
index 87444a0650f6..065f10bb742b 100644
--- a/drivers/timer/sti-timer.c
+++ b/drivers/timer/arm_global_timer.c
@@ -2,6 +2,8 @@
 /*
  * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
  * Author(s): Patrice Chotard,  for 
STMicroelectronics.
+ *
+ * ARM Cortext A9 global timer driver
  */
 
 #include 
@@ -13,13 +15,13 @@
 #include 
 #include 
 
-struct sti_timer_priv {
+struct arm_global_timer_priv {
struct globaltimer *global_timer;
 };
 
-static u64 sti_timer_get_count(struct udevice *dev)
+static u64 arm_global_timer_get_count(struct udevice *dev)
 {
-   struct sti_timer_priv *priv = dev_get_priv(dev);
+   struct arm_global_timer_priv *priv = dev_get_priv(dev);
struct globaltimer *global_timer = priv->global_timer;
u32 low, high;
u64 timer;
@@ -37,10 +39,10 @@ static u64 sti_timer_get_count(struct udevice *dev)
return (u64)((timer << 32) | low);
 }
 
-static int sti_timer_probe(struct udevice *dev)
+static int arm_global_timer_probe(struct udevice *dev)
 {
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-   struct sti_timer_priv *priv = dev_get_priv(dev);
+   struct arm_global_timer_priv *priv = dev_get_priv(dev);
struct clk clk;
int err;
ulong ret;
@@ -66,20 +68,20 @@ static int sti_timer_probe(struct udevice *dev)
return 0;
 }
 
-static const struct timer_ops sti_timer_ops = {
-   .get_count = sti_timer_get_count,
+static const struct timer_ops arm_global_timer_ops = {
+   .get_count = arm_global_timer_get_count,
 };
 
-static const struct udevice_id sti_timer_ids[] = {
+static const struct udevice_id arm_global_timer_ids[] = {
{ .compatible = "arm,cortex-a9-global-timer" },
{}
 };
 
-U_BOOT_DRIVER(sti_timer) = {
-   .name = "sti_timer",
+U_BOOT_DRIVER(arm_global_timer) = {
+   .name = "arm_global_timer",
.id = UCLASS_TIMER,
-   .of_match = sti_timer_ids,
-   .priv_auto  = sizeof(struct sti_timer_priv),
-   .probe = sti_timer_probe,
-   .ops = &sti_timer_ops,
+   .of_match = arm_global_timer_ids,
+   .priv_auto  = sizeof(struct arm_global_timer_priv),
+   .probe = arm_global_timer_probe,
+   .ops = &arm_global_timer_ops,
 };
-- 
2.37.1



smime.p7s
Description: S/MIME Cryptographic Signature


mvebu - switch to orion-timer

2022-08-23 Thread Pali Rohár
Hello Stefan! Now when U-Boot contains new orion-timer.c driver, which
Michael wrote, I think that it mvebu platform should switch to use it.
Because build process for armada boards prints deprecation warning that
new timer is not being used. Could you look at it, if it is possible to
do global switch for mach-mvebu and mach-kirkwood? I think it does not
make sense to do per-board switching as it is de-facto platform related
code.


[PATCH v3 5/7] doc: fru: add documentation for the fru command and APIs

2022-08-23 Thread Jae Hyun Yoo
Add a usage document for the 'fru' u-boot command.
Add kerneldocs for .

Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * Added kerneldocs to 'include/fru.h'. (Simon)

Changes from v1:
 * Newly added in v2. (Heinrich)

 doc/usage/cmd/fru.rst | 144 +
 doc/usage/index.rst   |   1 +
 include/fru.h | 182 ++
 3 files changed, 327 insertions(+)
 create mode 100644 doc/usage/cmd/fru.rst

diff --git a/doc/usage/cmd/fru.rst b/doc/usage/cmd/fru.rst
new file mode 100644
index ..d65bbc6dcbba
--- /dev/null
+++ b/doc/usage/cmd/fru.rst
@@ -0,0 +1,144 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+fru command
+===
+
+Synopsis
+
+
+::
+
+fru capture 
+fru display
+fru generate -b   [ ...]
+fru generate -p 
[ ...]
+
+Description
+---
+
+The *fru* commands is used to generate, capture and display FRU (Field
+Replaceable Unit) information data.
+
+Capture
+~~~
+
+The *fru capture* command parses and captures FRU configuration table at
+a specified address.
+
+addr
+memory address which FRU configuration table is stored.
+
+Display
+~~~
+
+The *fru display* command displays FRU information that is parsed using
+fru capture command.
+
+Generate
+
+
+The *fru generate* command generates a FRU configuration table which has Board
+or Product Info Area using the given field parameters.
+
+-b
+generate FRU which has board info area.
+
+addr
+memory address which FRU configuration table will be stored.
+
+manufacturer
+board manufacturer string.
+
+board name
+board product name string.
+
+serial number
+board serial number string.
+
+serial number
+board serial number string.
+
+part number
+board part number string.
+
+file id
+FRU File ID string. The FRU File version field is a pre-defined
+field provided as a manufacturing aid for verifying the file that
+was used during manufacture or field update to load the FRU
+information. The content is manufacturer-specific.
+
+custom
+additional custom board info area fields, if any.
+
+-p
+generate FRU which has product info area.
+
+addr
+memory address which FRU configuration table will be stored.
+
+manufacturer
+product manufacturer string.
+
+board name
+product name string.
+
+part number
+product part/model number string.
+
+version number
+product version number string.
+
+serial number
+product serial number string.
+
+asset number
+asset tag.
+
+file id
+FRU File ID string. The FRU File version field is a pre-defined
+field provided as a manufacturing aid for verifying the file that
+was used during manufacture or field update to load the FRU
+information. The content is manufacturer-specific.
+
+custom
+additional custom product info area fields, if any.
+
+Example
+---
+
+::
+
+=> fru generate -b 9000 abc def ghi jkl mno prs tuv wxy
+=> fru capture 9000
+=> fru display
+*COMMON HEADER*
+Version:1
+*** No Internal Area ***
+*** No Chassis Info Area ***
+Board Area Offset:8
+*** No Product Info Area ***
+*** No MultiRecord Area ***
+*BOARD INFO*
+Version:1
+Board Area Length:40
+Time in Minutes from 0:00hrs 1/1/96: 0
+ Manufacturer Name: abc
+ Product Name: def
+ Serial Number: ghi
+ Part Number: jkl
+ File ID: mno
+ Custom Type/Length: 0xc3
+  : 70 72 73 prs
+ Custom Type/Length: 0xc3
+  : 74 75 76 tuv
+ Custom Type/Length: 0xc3
+  : 77 78 79 wxy
+*PRODUCT INFO*
+Version:0
+Product Area Length:0
+*MULTIRECORDS*
+
+Configuration
+-
+
+The fru command is only available if CONFIG_CMD_FRU=y.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 28f9683a3e6f..e96a16356307 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -45,6 +45,7 @@ Shell commands
cmd/fatload
cmd/fdt
cmd/for
+   cmd/fru
cmd/gpio
cmd/load
cmd/loadm
diff --git a/include/fru.h b/include/fru.h
index 2b19033a3843..1d11fd1a5964 100644
--- a/include/fru.h
+++ b/include/fru.h
@@ -10,6 +10,21 @@
 
 #include 
 
+/**
+ * struct fru_common_hdr - FRU common header
+ *
+ * @version:   Common header format version
+ * @off_internal:  Internal use area starting offset
+ * @off_chassis:   Chassis info area starting offset
+ * @off_board: Board area startin

[PATCH v3 7/7] test: cmd: fru: add unit test for the fru command

2022-08-23 Thread Jae Hyun Yoo
Add test cases for the fru command.

Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * Newly added in v3. (Simon)

 include/test/suites.h |  1 +
 test/cmd/Makefile |  1 +
 test/cmd/fru.c| 84 +++
 test/cmd_ut.c |  6 
 4 files changed, 92 insertions(+)
 create mode 100644 test/cmd/fru.c

diff --git a/include/test/suites.h b/include/test/suites.h
index 44025ccecd6f..1d4a8c3e4a66 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -39,6 +39,7 @@ int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int 
argc,
 int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_ut_fru(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index c331757425ea..5995384dad91 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -8,6 +8,7 @@ endif
 obj-y += mem.o
 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
+obj-$(CONFIG_CMD_FRU) += fru.o
 obj-$(CONFIG_CMD_LOADM) += loadm.o
 obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
diff --git a/test/cmd/fru.c b/test/cmd/fru.c
new file mode 100644
index ..fa560622cf0b
--- /dev/null
+++ b/test/cmd/fru.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Executes tests for fru command
+ *
+ * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define FRU_TEST(_name, _flags)UNIT_TEST(_name, _flags, fru_test)
+
+#define CMD_FRU_TEST_SRC_BUF_SIZE 1024
+
+static const char cmd_gen_b[] =
+   "fru generate -b %08lx abcd efgh ijkl mnop qrst uvwx";
+static const char cmd_gen_p[] =
+   "fru generate -p %08lx abcd efgh ijkl mnop qrst uvwx yz01 2345";
+
+static const char cmd_capture[] = "fru capture %08lx";
+
+static int fru_test_board(struct unit_test_state *uts)
+{
+   u8 fru_src[CMD_FRU_TEST_SRC_BUF_SIZE];
+   int i;
+
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf(cmd_gen_b, (ulong)map_to_sysmem(fru_src)));
+   ut_assertok(run_commandf(cmd_capture, (ulong)map_to_sysmem(fru_src)));
+   ut_assertok(run_command("fru display", 0));
+   for (i = 0; i < 11; i++)
+   ut_assert_skipline();
+   ut_assert_nextline(" Manufacturer Name: abcd");
+   ut_assert_nextline(" Product Name: efgh");
+   ut_assert_nextline(" Serial Number: ijkl");
+   ut_assert_nextline(" Part Number: mnop");
+   ut_assert_nextline(" File ID: qrst");
+   ut_assert_nextline(" Custom Type/Length: 0xc4");
+   ut_assert_nextline("  : 75 76 77 78 
 uvwx");
+   for (i = 0; i < 4; i++)
+   ut_assert_skipline();
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FRU_TEST(fru_test_board, UT_TESTF_CONSOLE_REC);
+
+static int fru_test_product(struct unit_test_state *uts)
+{
+   u8 fru_src[CMD_FRU_TEST_SRC_BUF_SIZE];
+   int i;
+
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf(cmd_gen_p, (ulong)map_to_sysmem(fru_src)));
+   ut_assertok(run_commandf(cmd_capture, (ulong)map_to_sysmem(fru_src)));
+   ut_assertok(run_command("fru display", 0));
+   for (i = 0; i < 14; i++)
+   ut_assert_skipline();
+   ut_assert_nextline(" Manufacturer Name: abcd");
+   ut_assert_nextline(" Product Name: efgh");
+   ut_assert_nextline(" Part Number: ijkl");
+   ut_assert_nextline(" Version Number: mnop");
+   ut_assert_nextline(" Serial Number: qrst");
+   ut_assert_nextline(" Asset Number: uvwx");
+   ut_assert_nextline(" File ID: yz01");
+   ut_assert_nextline(" Custom Type/Length: 0xc4");
+   ut_assert_nextline("  : 32 33 34 35 
 2345");
+   ut_assert_skipline();
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FRU_TEST(fru_test_product, UT_TESTF_CONSOLE_REC);
+
+int do_ut_fru(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+   struct unit_test *tests = UNIT_TEST_SUITE_START(fru_test);
+   const int n_ents = UNIT_TEST_SUITE_COUNT(fru_test);
+
+   return cmd_ut_category("fru", "fru_test_", tests, n_ents, argc, argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 3789c6b784c0..4c163da8176c 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -80,6 +80,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
 #ifdef CONFIG_CMD_LOADM
U_BOOT_CMD_

[PATCH v3 4/7] cmd: fru: add product info area parsing support

2022-08-23 Thread Jae Hyun Yoo
Add product info area parsing support. Custom board fields can be
added dynamically using linked list so that each board support can
utilize them in their own custom way.

Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * Changed 'struct fru_board_info_member' to 'struct fru_common_info_member'.

Changes from v1:
 * Refactored using linked list instead of calling a custom parsing callback.

Changes from RFC:
 * Added manufacturer custom product info fields parsing flow.

 cmd/fru.c |  28 --
 include/fru.h |  34 ++-
 lib/fru_ops.c | 244 +++---
 3 files changed, 286 insertions(+), 20 deletions(-)

diff --git a/cmd/fru.c b/cmd/fru.c
index b2cadbec9780..42bdaae09449 100644
--- a/cmd/fru.c
+++ b/cmd/fru.c
@@ -43,11 +43,22 @@ static int do_fru_display(struct cmd_tbl *cmdtp, int flag, 
int argc,
 static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
+   int (*fru_generate)(const void *addr, int argc, char *const argv[]);
unsigned long addr;
const void *buf;
-   int ret;
+   int ret, maxargs;
+
+   if (!strncmp(argv[2], "-b", 3)) {
+   fru_generate = fru_board_generate;
+   maxargs = cmdtp->maxargs + FRU_BOARD_AREA_TOTAL_FIELDS;
+   } else if (!strncmp(argv[2], "-p", 3)) {
+   fru_generate = fru_product_generate;
+   maxargs = cmdtp->maxargs + FRU_PRODUCT_AREA_TOTAL_FIELDS;
+   } else {
+   return CMD_RET_USAGE;
+   }
 
-   if (argc < cmdtp->maxargs)
+   if (argc < maxargs)
return CMD_RET_USAGE;
 
addr = hextoul(argv[3], NULL);
@@ -62,7 +73,7 @@ static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, 
int argc,
 static struct cmd_tbl cmd_fru_sub[] = {
U_BOOT_CMD_MKENT(capture, 3, 0, do_fru_capture, "", ""),
U_BOOT_CMD_MKENT(display, 2, 0, do_fru_display, "", ""),
-   U_BOOT_CMD_MKENT(board_gen, 8, 0, do_fru_generate, "", ""),
+   U_BOOT_CMD_MKENT(generate, 4, 0, do_fru_generate, "", ""),
 };
 
 static int do_fru(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -90,11 +101,16 @@ static char fru_help_text[] =
"capture  - Parse and capture FRU table present at address.\n"
"fru display - Displays content of FRU table that was captured using\n"
"  fru capture command\n"
-   "fru board_gen\n"
-   "[custom ...] - Generate FRU\n"
-   "  format with board info area filled based on\n"
+   "fru generate -b\n"
+   "  [custom ...] - Generate FRU\n"
+   "format with board info area filled based on\n"
"parameters.  is pointing to place where FRU is\n"
"generated.\n"
+   "fru generate -p\n"
+   "  \n"
+   " [custom ...] - Generate FRU format with\n"
+   "product info area filled based on parameters. \n"
+   "is pointing to place where FRU is generated.\n"
;
 #endif
 
diff --git a/include/fru.h b/include/fru.h
index b158b80b5866..2b19033a3843 100644
--- a/include/fru.h
+++ b/include/fru.h
@@ -31,7 +31,13 @@ struct fru_board_info_header {
u8 time[3];
 } __packed;
 
-struct fru_board_info_member {
+struct fru_product_info_header {
+   u8 ver;
+   u8 len;
+   u8 lang_code;
+} __packed;
+
+struct fru_common_info_member {
u8 type_len;
u8 *name;
 } __packed;
@@ -64,6 +70,27 @@ struct fru_board_data {
struct list_head custom_fields;
 };
 
+struct fru_product_data {
+   u8 ver;
+   u8 len;
+   u8 lang_code;
+   u8 manufacturer_type_len;
+   u8 manufacturer_name[FRU_INFO_FIELD_LEN_MAX];
+   u8 product_name_type_len;
+   u8 product_name[FRU_INFO_FIELD_LEN_MAX];
+   u8 part_number_type_len;
+   u8 part_number[FRU_INFO_FIELD_LEN_MAX];
+   u8 version_number_type_len;
+   u8 version_number[FRU_INFO_FIELD_LEN_MAX];
+   u8 serial_number_type_len;
+   u8 serial_number[FRU_INFO_FIELD_LEN_MAX];
+   u8 asset_number_type_len;
+   u8 asset_number[FRU_INFO_FIELD_LEN_MAX];
+   u8 file_id_type_len;
+   u8 file_id[FRU_INFO_FIELD_LEN_MAX];
+   struct list_head custom_fields;
+};
+
 struct fru_multirec_hdr {
u8 rec_type;
u8 type;
@@ -85,6 +112,7 @@ struct fru_multirec_node {
 struct fru_table {
struct fru_common_hdr hdr;
struct fru_board_data brd;
+   struct fru_product_data prd;
struct list_head multi_recs;
bool captured;
 };
@@ -102,13 +130,15 @@ struct fru_table {
 
 /* This should be minimum of fields */
 #define FRU_BOARD_AREA_TOTAL_FIELDS5
+#define FRU_PRODUCT_AREA_TOTAL_FIELDS  7
 #define FRU_TYPELEN_TYPE_SHIFT 6
 #define FRU_TYPELEN_TYPE_BINARY0
 #define FRU_TYPELEN_TYPE_ASCII83
 
 int fru_displ

[PATCH v3 6/7] test: py: fru: add a test for the fru command

2022-08-23 Thread Jae Hyun Yoo
Add a simple test for the 'fru' command.

Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * Added CONFIG_CMD_FRU=y only into the sandbox_defconfig. (Simon)

Changes from v1:
 * Newly added in v2. (Heinrich)

 configs/sandbox_defconfig |  1 +
 test/py/tests/test_fru.py | 47 +++
 2 files changed, 48 insertions(+)
 create mode 100644 test/py/tests/test_fru.py

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb483b..293e39706cf2 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -115,6 +115,7 @@ CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_MTDPARTS=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
+CONFIG_CMD_FRU=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
 CONFIG_OF_CONTROL=y
diff --git a/test/py/tests/test_fru.py b/test/py/tests/test_fru.py
new file mode 100644
index ..e5e1d7d00639
--- /dev/null
+++ b/test/py/tests/test_fru.py
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+
+import pytest
+import u_boot_utils
+
+@pytest.mark.buildconfigspec('cmd_fru')
+def test_fru_board(u_boot_console):
+"""Test that fru command generates and captures board FRU information as
+expected."""
+
+ram_base = u_boot_utils.find_ram_base(u_boot_console)
+addr = '0x%x' % ram_base
+expected_response = 'rc:0'
+response = u_boot_console.run_command('fru generate -b ' + addr + ' abcd 
efgh ijkl mnop qrst uvwx; echo rc:$?')
+assert(expected_response in response)
+response = u_boot_console.run_command('fru capture ' + addr + '; echo 
rc:$?')
+assert(expected_response in response)
+response = u_boot_console.run_command('fru display')
+assert('Manufacturer Name: abcd' in response)
+assert('Product Name: efgh' in response)
+assert('Serial Number: ijkl' in response)
+assert('Part Number: mnop' in response)
+assert('File ID: qrst' in response)
+assert('Custom Type/Length: 0xc4' in response)
+
+@pytest.mark.buildconfigspec('cmd_fru')
+def test_fru_product(u_boot_console):
+"""Test that fru command generates and captures product FRU information as
+expected."""
+
+ram_base = u_boot_utils.find_ram_base(u_boot_console)
+addr = '0x%x' % ram_base
+expected_response = 'rc:0'
+response = u_boot_console.run_command('fru generate -p ' + addr + ' abcd 
efgh ijkl mnop qrst uvwx yz01 2345; echo rc:$?')
+assert(expected_response in response)
+response = u_boot_console.run_command('fru capture ' + addr + '; echo 
rc:$?')
+assert(expected_response in response)
+response = u_boot_console.run_command('fru display')
+assert('Manufacturer Name: abcd' in response)
+assert('Product Name: efgh' in response)
+assert('Part Number: ijkl' in response)
+assert('Version Number: mnop' in response)
+assert('Serial Number: qrst' in response)
+assert('Asset Number: uvwx' in response)
+assert('File ID: yz01' in response)
+assert('Custom Type/Length: 0xc4' in response)
-- 
2.25.1



[PATCH v3 3/7] cmd: fru: fix a sandbox segfault issue

2022-08-23 Thread Jae Hyun Yoo
This command doesn't work with sandbox because direct memory access
causes a segfault error. Fix it up using map_sysmem().

Signed-off-by: Jae Hyun Yoo 
Reviewed-by: Simon Glass 
---
Changes from v2:
 * Added a 'Reviewed-by' tag. (Simon)

Changes from v1:
 * Newly added in v2.

 board/xilinx/common/board.c |  2 +-
 cmd/fru.c   | 19 ---
 include/fru.h   |  4 ++--
 lib/fru_ops.c   | 17 -
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index e58b11d7f757..3292083c5250 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -241,7 +241,7 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char 
*name,
goto end;
}
 
-   fru_capture((unsigned long)fru_content);
+   fru_capture(fru_content);
if (gd->flags & GD_FLG_RELOC || (_DEBUG && 
CONFIG_IS_ENABLED(DTB_RESELECT))) {
printf("Xilinx I2C FRU format at %s:\n", name);
ret = fru_display(0);
diff --git a/cmd/fru.c b/cmd/fru.c
index 2ec5012af5ac..b2cadbec9780 100644
--- a/cmd/fru.c
+++ b/cmd/fru.c
@@ -9,12 +9,15 @@
 #include 
 #include 
 #include 
+#include 
 
 static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
unsigned long addr;
+   const void *buf;
char *endp;
+   int ret;
 
if (argc < cmdtp->maxargs)
return CMD_RET_USAGE;
@@ -23,7 +26,11 @@ static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, 
int argc,
if (*argv[1] == 0 || *endp != 0)
return -1;
 
-   return fru_capture(addr);
+   buf = map_sysmem(addr, 0);
+   ret = fru_capture(buf);
+   unmap_sysmem(buf);
+
+   return ret;
 }
 
 static int do_fru_display(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -37,13 +44,19 @@ static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, 
int argc,
   char *const argv[])
 {
unsigned long addr;
+   const void *buf;
+   int ret;
 
if (argc < cmdtp->maxargs)
return CMD_RET_USAGE;
 
-   addr = hextoul(argv[2], NULL);
+   addr = hextoul(argv[3], NULL);
+
+   buf = map_sysmem(addr, 0);
+   ret = fru_generate(buf, argc - 3, argv + 3);
+   unmap_sysmem(buf);
 
-   return fru_generate(addr, argc - 3, argv + 3);
+   return ret;
 }
 
 static struct cmd_tbl cmd_fru_sub[] = {
diff --git a/include/fru.h b/include/fru.h
index 41655864dbf5..b158b80b5866 100644
--- a/include/fru.h
+++ b/include/fru.h
@@ -107,8 +107,8 @@ struct fru_table {
 #define FRU_TYPELEN_TYPE_ASCII83
 
 int fru_display(int verbose);
-int fru_capture(unsigned long addr);
-int fru_generate(unsigned long addr, int argc, char *const argv[]);
+int fru_capture(const void *addr);
+int fru_generate(const void *addr, int argc, char *const argv[]);
 u8 fru_checksum(u8 *addr, u8 len);
 int fru_check_type_len(u8 type_len, u8 language, u8 *type);
 const struct fru_table *fru_get_fru_data(void);
diff --git a/lib/fru_ops.c b/lib/fru_ops.c
index c0360f219c37..6ed1388b2fc8 100644
--- a/lib/fru_ops.c
+++ b/lib/fru_ops.c
@@ -91,7 +91,7 @@ static u8 fru_gen_type_len(u8 *addr, char *name)
return 1 + len;
 }
 
-int fru_generate(unsigned long addr, int argc, char *const argv[])
+int fru_generate(const void *addr, int argc, char *const argv[])
 {
struct fru_common_hdr *header = (struct fru_common_hdr *)addr;
struct fru_board_info_header *board_info;
@@ -155,8 +155,8 @@ int fru_generate(unsigned long addr, int argc, char *const 
argv[])
 
debug("checksum %x(addr %x)\n", *member, len);
 
-   env_set_hex("fru_addr", addr);
-   env_set_hex("filesize", (unsigned long)member - addr + 1);
+   env_set_hex("fru_addr", (ulong)addr);
+   env_set_hex("filesize", (ulong)member - (ulong)addr + 1);
 
return 0;
 }
@@ -171,7 +171,7 @@ static void fru_delete_custom_fields(struct list_head 
*custom_fields)
}
 }
 
-static int fru_append_custom_info(unsigned long addr,
+static int fru_append_custom_info(const void *addr,
  struct list_head *custom_fields)
 {
struct fru_custom_info *info = (struct fru_custom_info *)addr;
@@ -190,7 +190,7 @@ static int fru_append_custom_info(unsigned long addr,
return 0;
 }
 
-static int fru_parse_board(unsigned long addr)
+static int fru_parse_board(const void *addr)
 {
u8 i, type;
int len;
@@ -268,8 +268,7 @@ static void fru_delete_multirecs(struct list_head 
*multi_recs)
}
 }
 
-static int fru_append_multirec(unsigned long addr,
-  struct list_head *multi_recs)
+static int fru_append_multirec(const void *addr, struct list_head *multi_recs)
 {
struct fru_multirec_info *mr_src = (struct fru_multirec_info *)addr;
struct fru_multirec_node *mr_n

[PATCH v3 1/7] xilinx: common: refactor FRU handling support

2022-08-23 Thread Jae Hyun Yoo
Refactor FRU handling support to remove Xilinx customization dependency.
With this change, single or multiple custom board fields and
multi-records can be added dynamically using linked list so that each
board support can utilize them in their own custom way.

It's a preparation change for moving the FRU command support to common
region.

Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * None.

Changes from v1:
 * Newly added in v2.

 board/xilinx/common/board.c   |  63 --
 board/xilinx/common/fru.c |  12 +-
 board/xilinx/common/fru.h |  76 +++-
 board/xilinx/common/fru_ops.c | 228 --
 4 files changed, 264 insertions(+), 115 deletions(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 9b4aded466ab..e979f0176273 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -88,6 +88,9 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
 #define EEPROM_HDR_NO_OF_MAC_ADDR  4
 #define EEPROM_HDR_ETH_ALENETH_ALEN
 #define EEPROM_HDR_UUID_LEN16
+#define EEPROM_MULTIREC_TYPE_XILINX_OEM0xD2
+#define EEPROM_MULTIREC_MAC_OFFSET 4
+#define EEPROM_MULTIREC_DUT_MACID  0x31
 
 struct xilinx_board_description {
u32 header;
@@ -116,6 +119,19 @@ struct xilinx_legacy_format {
char unused3[29]; /* 0xe3 */
 };
 
+struct xilinx_multirec_mac {
+   u8 xlnx_iana_id[3];
+   u8 ver;
+   u8 macid[EEPROM_HDR_NO_OF_MAC_ADDR][ETH_ALEN];
+};
+
+enum xilinx_board_custom_field {
+   brd_custom_field_rev = 0,
+   brd_custom_field_pcie,
+   brd_custom_field_uuid,
+   brd_custom_field_max
+};
+
 static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size)
 {
int i;
@@ -200,9 +216,14 @@ static bool xilinx_detect_legacy(u8 *buffer)
 static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
  struct xilinx_board_description *desc)
 {
+   u8 parsed_macid[EEPROM_HDR_NO_OF_MAC_ADDR][ETH_ALEN] = { 0 };
+   struct fru_custom_info custom_info[brd_custom_field_max] = { 0 };
+   struct fru_custom_field_node *ci_node;
+   struct fru_multirec_node *mr_node;
+   const struct fru_table *fru_data;
int i, ret, eeprom_size;
u8 *fru_content;
-   u8 id = 0;
+   u8 id = 0, field = 0;
 
/* FIXME this is shortcut - if eeprom type is wrong it will fail */
eeprom_size = i2c_eeprom_size(dev);
@@ -237,30 +258,56 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, 
char *name,
goto end;
}
 
+   fru_data = fru_get_fru_data();
+
+   list_for_each_entry(ci_node, &fru_data->brd.custom_fields, list) {
+   custom_info[field].type_len = ci_node->info.type_len;
+   memcpy(custom_info[field].data, ci_node->info.data,
+  ci_node->info.type_len & FRU_TYPELEN_LEN_MASK);
+   if (++field < brd_custom_field_max)
+   break;
+   }
+
+   list_for_each_entry(mr_node, &fru_data->multi_recs, list) {
+   struct fru_multirec_hdr *hdr = &mr_node->info.hdr;
+
+   if (hdr->rec_type == EEPROM_MULTIREC_TYPE_XILINX_OEM) {
+   struct xilinx_multirec_mac *mac;
+
+   mac = (struct xilinx_multirec_mac *)mr_node->info.data;
+   if (mac->ver == EEPROM_MULTIREC_DUT_MACID) {
+   int mac_len = hdr->len -
+ EEPROM_MULTIREC_MAC_OFFSET;
+
+   memcpy(parsed_macid, mac->macid, mac_len);
+   }
+   }
+   }
+
/* It is clear that FRU was captured and structures were filled */
-   strlcpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name,
+   strlcpy(desc->manufacturer, (char *)fru_data->brd.manufacturer_name,
sizeof(desc->manufacturer));
-   strlcpy(desc->uuid, (char *)fru_data.brd.uuid,
+   strlcpy(desc->uuid, (char *)custom_info[brd_custom_field_uuid].data,
sizeof(desc->uuid));
-   strlcpy(desc->name, (char *)fru_data.brd.product_name,
+   strlcpy(desc->name, (char *)fru_data->brd.product_name,
sizeof(desc->name));
for (i = 0; i < sizeof(desc->name); i++) {
if (desc->name[i] == ' ')
desc->name[i] = '\0';
}
-   strlcpy(desc->revision, (char *)fru_data.brd.rev,
+   strlcpy(desc->revision, (char *)custom_info[brd_custom_field_rev].data,
sizeof(desc->revision));
for (i = 0; i < sizeof(desc->revision); i++) {
if (desc->revision[i] == ' ')
desc->revision[i] = '\0';
}
-   strlcpy(desc->serial, (char *)fru_data.brd.serial_number,
+   strlcpy(desc->serial, (char *)fru_data->brd.serial_number,
sizeof(desc->serial));
 
while (id 

[PATCH v3 0/7] cmd/fru: move FRU handling support to common region

2022-08-23 Thread Jae Hyun Yoo
Hello,

The FRU handling was added as a Xilinx board dependent support but it
is also useful for other boards, so this commit moves the FRU handling
support to the common region so that it can be enabled by CONFIG_CMD_FRU.

To provide manufacturer specific custom info fields and multi-records
parsing, it refactors the FRU handling logic using linked list so that each
board support can utilize them in their own custom way. This series adds
'Product Info' parsing support, usage document and unit test script too.

Please review!

Thanks,
Jae

Graeme Gregory (1):
  cmd: fru: move FRU handling support to common region

Jae Hyun Yoo (6):
  xilinx: common: refactor FRU handling support
  cmd: fru: fix a sandbox segfault issue
  cmd: fru: add product info area parsing support
  doc: fru: add documentation for the fru command and APIs
  test: py: fru: add a test for the fru command
  test: cmd: fru: add unit test for the fru command

 board/xilinx/Kconfig   |   8 -
 board/xilinx/common/Makefile   |   3 -
 board/xilinx/common/board.c|  68 ++-
 board/xilinx/common/fru.h  | 108 -
 board/xilinx/common/fru_ops.c  | 415 -
 cmd/Kconfig|   8 +
 cmd/Makefile   |   1 +
 {board/xilinx/common => cmd}/fru.c |  54 ++-
 configs/sandbox_defconfig  |   1 +
 doc/usage/cmd/fru.rst  | 144 ++
 doc/usage/index.rst|   1 +
 include/fru.h  | 328 +
 include/test/suites.h  |   1 +
 lib/Makefile   |   1 +
 lib/fru_ops.c  | 725 +
 test/cmd/Makefile  |   1 +
 test/cmd/fru.c |  84 
 test/cmd_ut.c  |   6 +
 test/py/tests/test_fru.py  |  47 ++
 19 files changed, 1447 insertions(+), 557 deletions(-)
 delete mode 100644 board/xilinx/common/fru.h
 delete mode 100644 board/xilinx/common/fru_ops.c
 rename {board/xilinx/common => cmd}/fru.c (50%)
 create mode 100644 doc/usage/cmd/fru.rst
 create mode 100644 include/fru.h
 create mode 100644 lib/fru_ops.c
 create mode 100644 test/cmd/fru.c
 create mode 100644 test/py/tests/test_fru.py

-- 
2.25.1



[PATCH v3 2/7] cmd: fru: move FRU handling support to common region

2022-08-23 Thread Jae Hyun Yoo
From: Graeme Gregory 

The FRU handling was added as a Xilinx board dependent support but it
is also useful for other boards too, so this commit moves the FRU
handling support to the common region so that it can be enabled by
CONFIG_CMD_FRU.

Signed-off-by: Graeme Gregory 
Signed-off-by: Jae Hyun Yoo 
---
Changes from v2:
 * None.

Changes from v1:
 * Split out the custom field and multi-record handling part as a
   seperate patch. (Michal)
 * Moved fru_ops.c to lib. (Heinrich)
 * Added what does FRU stand for. (Heinrich)

Changes from RFC:
 * Made FRU typecode string table as a generic and sharable table. (Michal)
 * Made OEM multirecord parsing call happen only on customizable type IDs.
   (Michal)
 * Added manufacturer custom board info fields parsing flow. (Michal)

 board/xilinx/Kconfig   | 8 
 board/xilinx/common/Makefile   | 3 ---
 board/xilinx/common/board.c| 3 +--
 cmd/Kconfig| 8 
 cmd/Makefile   | 1 +
 {board/xilinx/common => cmd}/fru.c | 3 +--
 {board/xilinx/common => include}/fru.h | 0
 lib/Makefile   | 1 +
 {board/xilinx/common => lib}/fru_ops.c | 3 +--
 9 files changed, 13 insertions(+), 17 deletions(-)
 rename {board/xilinx/common => cmd}/fru.c (99%)
 rename {board/xilinx/common => include}/fru.h (100%)
 rename {board/xilinx/common => lib}/fru_ops.c (99%)

diff --git a/board/xilinx/Kconfig b/board/xilinx/Kconfig
index 17880661736d..110706b20fa3 100644
--- a/board/xilinx/Kconfig
+++ b/board/xilinx/Kconfig
@@ -74,11 +74,3 @@ config ZYNQ_GEM_I2C_MAC_OFFSET
  Set the MAC offset for i2C.
 
 endif
-
-config CMD_FRU
-   bool "FRU information for product"
-   help
- This option enables FRU commands to capture and display FRU
- information present in the device. The FRU Information is used
- to primarily to provide "inventory" information about the boards
- that the FRU Information Device is located on.
diff --git a/board/xilinx/common/Makefile b/board/xilinx/common/Makefile
index cdc3c9677432..e33baaae1159 100644
--- a/board/xilinx/common/Makefile
+++ b/board/xilinx/common/Makefile
@@ -8,6 +8,3 @@ obj-y   += board.o
 ifndef CONFIG_ARCH_ZYNQ
 obj-$(CONFIG_DISPLAY_CPUINFO) += cpu-info.o
 endif
-ifndef CONFIG_SPL_BUILD
-obj-$(CONFIG_CMD_FRU) += fru.o fru_ops.o
-endif
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index e979f0176273..e58b11d7f757 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -25,8 +26,6 @@
 #include 
 #include 
 
-#include "fru.h"
-
 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
 struct efi_fw_image fw_images[] = {
 #if defined(XILINX_BOOT_IMAGE_GUID)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 211ebe9c8783..29b2e11e1247 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1063,6 +1063,14 @@ config CMD_FPGAD
  fpga_get_reg() function. This functions similarly to the 'md'
  command.
 
+config CMD_FRU
+   bool "FRU information for product"
+   help
+ This option enables FRU (Field Replaceable Unit) commands to capture
+ and display FRU information present in the device. The FRU Information
+ is used to primarily to provide "inventory" information about the
+ boards that the FRU Information Device is located on.
+
 config CMD_FUSE
bool "fuse - support for the fuse subssystem"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index 6e87522b62e8..58e353611a5a 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
+obj-$(CONFIG_CMD_FRU) += fru.o
 obj-$(CONFIG_CMD_FS_GENERIC) += fs.o
 obj-$(CONFIG_CMD_FUSE) += fuse.o
 obj-$(CONFIG_CMD_GETTIME) += gettime.o
diff --git a/board/xilinx/common/fru.c b/cmd/fru.c
similarity index 99%
rename from board/xilinx/common/fru.c
rename to cmd/fru.c
index 0d72911df04d..2ec5012af5ac 100644
--- a/board/xilinx/common/fru.c
+++ b/cmd/fru.c
@@ -7,10 +7,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
-#include "fru.h"
-
 static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
diff --git a/board/xilinx/common/fru.h b/include/fru.h
similarity index 100%
rename from board/xilinx/common/fru.h
rename to include/fru.h
diff --git a/lib/Makefile b/lib/Makefile
index e3deb1528794..ef8933ae3aee 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -39,6 +39,7 @@ obj-y += crc16-ccitt.o
 obj-$(CONFIG_ERRNO_STR) += errno_str.o
 obj-$(CONFIG_FIT) += fdtdec_common.o
 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
+obj-$(CONFIG_CMD_FRU) += fru_ops.o
 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-$(CONFIG_SMBIOS_PARSER) += smbios-parse

Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

2022-08-23 Thread Antoine Mazeas

Thanks Simon,

Can I ask you to clarify what you meant by "drop the private firmware"?
For the record, this patch was tested using the vendored firmware from
Raspberry Pi, v1.20220331, and subsequently v1.20220811 when it came
out.

I'm happy to do the requested change now if you think it is preferable.

Regards

Le 22/08/2022 à 18:39, Simon Glass a écrit :

Hi Antoine,

On Fri, 19 Aug 2022 at 08:08, Antoine Mazeas  wrote:


The RPI firmware adjusts several property values in the dtb it passes
to u-boot depending on the board/SoC revision. Inherit some of these
when u-boot loads a dtb itself. Specificaly copy:

* /model: The firmware provides a more specific string
* /memreserve: The firmware defines a reserved range, better keep it
* emmc2bus and pcie0 dma-ranges: The C0T revision of the bcm2711 Soc (as
   present on rpi 400 and some rpi 4B boards) has different values for
   these then the B0T revision. So these need to be adjusted to boot on
   these boards
* blconfig: The firmware defines the memory area where the blconfig
   stored. Copy those over so it can be enabled.
* /chosen/kaslr-seed: The firmware generates a kaslr seed, take advantage
   of that.

Signed-off-by: Sjoerd Simons 
Signed-off-by: Antoine Mazeas 
---

  board/raspberrypi/rpi/rpi.c | 48 +
  1 file changed, 48 insertions(+)


Reviewed-by: Simon Glass 

I wonder if anyone has tried to drop the private firmware on the boards?

At some point copy_property() should move to fdt_support.c if others use it


Re: ethernet dt aliases implications in U-Boot and Linux

2022-08-23 Thread Rob Herring
On Tue, Aug 9, 2022 at 4:39 PM Tim Harvey  wrote:
>
> On Tue, Aug 9, 2022 at 2:31 PM Pali Rohár  wrote:
> >
> > On Tuesday 09 August 2022 16:48:23 Sean Anderson wrote:
> > > On 8/8/22 5:45 PM, Michal Suchánek wrote:
> > > > On Mon, Aug 08, 2022 at 02:38:35PM -0700, Stephen Hemminger wrote:
> > > >> On Mon, 8 Aug 2022 23:09:45 +0200
> > > >> Michal Suchánek  wrote:
> > > >>
> > > >> > On Mon, Aug 08, 2022 at 03:57:55PM -0400, Sean Anderson wrote:
> > > >> > > Hi Tim,
> > > >> > >
> > > >> > > On 8/8/22 3:18 PM, Tim Harvey wrote:
> > > >> > > > Greetings,
> > > >> > > >
> > > >> > > > I'm trying to understand if there is any implication of 
> > > >> > > > 'ethernet'
> > > >> > > > aliases in Linux such as:
> > > >> > > > aliases {
> > > >> > > > ethernet0 = &eqos;
> > > >> > > > ethernet1 = &fec;
> > > >> > > > ethernet2 = &lan1;
> > > >> > > > ethernet3 = &lan2;
> > > >> > > > ethernet4 = &lan3;
> > > >> > > > ethernet5 = &lan4;
> > > >> > > > ethernet6 = &lan5;
> > > >> > > > };
> > > >> > > >
> > > >> > > > I know U-Boot boards that use device-tree will use these aliases 
> > > >> > > > to
> > > >> > > > name the devices in U-Boot such that the device with alias 
> > > >> > > > 'ethernet0'
> > > >> > > > becomes eth0 and alias 'ethernet1' becomes eth1 but for Linux it
> > > >> > > > appears that the naming of network devices that are embedded (ie 
> > > >> > > > SoC)
> > > >> > > > vs enumerated (ie pci/usb) are always based on device 
> > > >> > > > registration
> > > >> > > > order which for static drivers depends on Makefile linking order 
> > > >> > > > and
> > > >> > > > has nothing to do with device-tree.
> > > >> > > >
> > > >> > > > Is there currently any way to control network device naming in 
> > > >> > > > Linux
> > > >> > > > other than udev?

Ah, the topic that will never die.

> > > >> > >
> > > >> > > You can also use systemd-networkd et al. (but that is the same 
> > > >> > > kind of mechanism)
> > > >> > >
> > > >> > > > Does Linux use the ethernet aliases for anything at all?
> > > >> > >
> > > >> > > No :l
> > > >> >
> > > >> > Maybe it's a great opportunity for porting biosdevname to DT based
> > > >> > platforms ;-)
> > > >>
> > > >> Sorry, biosdevname was wrong way to do things.
> > > >> Did you look at the internals, it was dumpster diving as root into 
> > > >> BIOS.
> > > >
> > > > When it's BIOS what defines the names then you have to read them from
> > > > the BIOS. Recently it was updated to use some sysfs file or whatver.
> > > > It's not like you would use any of that code with DT, anyway.
> > > >
> > > >> Systemd-networkd does things in much more supportable manner using 
> > > >> existing
> > > >> sysfs API's.
> > > >
> > > > Which is a dumpster of systemd code, no thanks.
> > > >
> > > > I want my device naming independent of the init system, especially if
> > > > it's systemd.
> > >
> > > Well, there's always nameif...
> > >
> > > That said, I have made [1] for people using systemd-networkd.
> > >
> > > --Sean
> > >
> > > [1] https://github.com/systemd/systemd/pull/24265
> >
> > Hello!
> >
> > In some cases "label" DT property can be used also as interface name.
> > For example this property is already used by DSA kernel driver.
> >
> > I created very simple script which renames all interfaces in system to
> > their "label" DT property (if there is any defined).
> >
> > #!/bin/sh
> > for iface in `ls /sys/class/net/`; do
> > for of_node in of_node device/of_node; do
> > if test -e /sys/class/net/$iface/$of_node/; then
> > label=`cat /sys/class/net/$iface/$of_node/label 
> > 2>/dev/null`
> > if test -n "$label" && test "$label" != "$iface"; 
> > then
> > echo "Renaming net interface $iface to 
> > $label..."
> > up=$((`cat /sys/class/net/$iface/flags 
> > 2>/dev/null || echo 1` & 0x1))
> > if test "$up" != "0"; then
> > ip link set dev $iface down
> > fi
> > ip link set dev $iface name "$label" && 
> > iface=$label
> > if test "$up" != "0"; then
> > ip link set dev $iface up
> > fi
> > fi
> > break
> > fi
> > done
> > done
> >
> > Maybe it would be better first to use "label" and then use ethernet alias?
>
> I've been wondering the same as well which made me wonder what the
> history of the 'aliases' node is and why its not used in most cases in
> Linux. I know for the SOC's I work with we've always defined aliases
> for ethernet, gpio, serial, spi, i2c, mmc etc. Where
> did this practice come from and why 

[PATCH] post: memory: Fix format strings

2022-08-23 Thread Sean Anderson
This fixes numerous cases of format strings not matching their
arguments. Also keep the format strings on one line for easier grepping.

Signed-off-by: Sean Anderson 
---

 post/drivers/memory.c | 30 --
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/post/drivers/memory.c b/post/drivers/memory.c
index 281989da6fa..4fb9355d603 100644
--- a/post/drivers/memory.c
+++ b/post/drivers/memory.c
@@ -228,9 +228,8 @@ static int memory_post_dataline(unsigned long long * pmem)
hi = (temp64>>32) & 0x;
lo = temp64 & 0x;
 
-   post_log("Memory (data line) error at %08x, "
- "wrote %08x%08x, read %08x%08x !\n",
- pmem, pathi, patlo, hi, lo);
+   post_log("Memory (data line) error at %p, wrote 
%08x%08x, read %08x%08x !\n",
+pmem, pathi, patlo, hi, lo);
ret = -1;
}
}
@@ -259,9 +258,8 @@ static int memory_post_addrline(ulong *testaddr, ulong 
*base, ulong size)
}
 #endif
if(readback == *testaddr) {
-   post_log("Memory (address line) error at 
%08x<->%08x, "
-   "XOR value %08x !\n",
-   testaddr, target, xor);
+   post_log("Memory (address line) error at 
%p<->%p, XOR value %08lx !\n",
+testaddr, target, xor);
ret = -1;
}
}
@@ -287,9 +285,8 @@ static int memory_post_test1(unsigned long start,
for (i = 0; i < size / sizeof (ulong) && !ret; i++) {
readback = mem[i];
if (readback != val) {
-   post_log("Memory error at %08x, "
- "wrote %08x, read %08x !\n",
- mem + i, val, readback);
+   post_log("Memory error at %p, wrote %08lx, read %08lx 
!\n",
+mem + i, val, readback);
 
ret = -1;
break;
@@ -317,9 +314,8 @@ static int memory_post_test2(unsigned long start, unsigned 
long size)
for (i = 0; i < size / sizeof (ulong) && !ret; i++) {
readback = mem[i];
if (readback != (1 << (i % 32))) {
-   post_log("Memory error at %08x, "
- "wrote %08x, read %08x !\n",
- mem + i, 1 << (i % 32), readback);
+   post_log("Memory error at %p, wrote %08lx, read %08lx 
!\n",
+mem + i, 1UL << (i % 32), readback);
 
ret = -1;
break;
@@ -347,9 +343,8 @@ static int memory_post_test3(unsigned long start, unsigned 
long size)
for (i = 0; i < size / sizeof (ulong) && !ret; i++) {
readback = mem[i];
if (readback != i) {
-   post_log("Memory error at %08x, "
- "wrote %08x, read %08x !\n",
- mem + i, i, readback);
+   post_log("Memory error at %p, wrote %08lx, read %08lx 
!\n",
+mem + i, i, readback);
 
ret = -1;
break;
@@ -377,9 +372,8 @@ static int memory_post_test4(unsigned long start, unsigned 
long size)
for (i = 0; i < size / sizeof (ulong) && !ret; i++) {
readback = mem[i];
if (readback != ~i) {
-   post_log("Memory error at %08x, "
- "wrote %08x, read %08x !\n",
- mem + i, ~i, readback);
+   post_log("Memory error at %p, wrote %08lx, read %08lx 
!\n",
+mem + i, ~i, readback);
 
ret = -1;
break;
-- 
2.35.1.1320.gc452695387.dirty



[PATCH v2 2/2] dts: imx8mp-rsb3720: modify configrations to load fip into memory

2022-08-23 Thread Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" 

The changes of commit 6a21c695213b ("arm: dts: imx8mp: add of-list
support to common imx8mp-u-boot.dtsi") breaks the loading of the fip.
This commit fixes the break by modify the configuration properly.

Signed-off-by: Ying-Chun Liu (PaulLiu) 
Cc: Stefano Babic 
Cc: Fabio Estevam 
Cc: NXP i.MX U-Boot Team 
---
 arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi 
b/arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi
index 4419967ee4..32d9fbc886 100644
--- a/arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi
@@ -158,12 +158,10 @@
};
};
};
-
-   configurations {
-   conf {
-   loadables = "atf", "fip";
-   };
-   };
};
};
 };
+
+&binman_configuration {
+   loadables = "atf", "fip";
+};
-- 
2.35.1



[PATCH v2 1/2] dts: imx8mp: assign binman_configuration node name to config-SEQ

2022-08-23 Thread Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" 

assign a node name for config-SEQ so that the board dts can modify
the configuration more easily.

Signed-off-by: Ying-Chun Liu (PaulLiu) 
Cc: Stefano Babic 
Cc: Fabio Estevam 
Cc: NXP i.MX U-Boot Team 
---
v2: just rebase to the latest master branch.
---
 arch/arm/dts/imx8mp-u-boot.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/dts/imx8mp-u-boot.dtsi b/arch/arm/dts/imx8mp-u-boot.dtsi
index adb243..6cb0bb2d4c 100644
--- a/arch/arm/dts/imx8mp-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-u-boot.dtsi
@@ -148,7 +148,7 @@
configurations {
default = "@config-DEFAULT-SEQ";
 
-   @config-SEQ {
+   binman_configuration: @config-SEQ {
description = "NAME";
fdt = "fdt-SEQ";
firmware = "uboot";
-- 
2.35.1



[PATCH v2 0/2] dts: imx8mp-rsb3720: modify configrations to load fip into memory

2022-08-23 Thread Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" 

The changes of commit 6a21c695213b ("arm: dts: imx8mp: add of-list
support to common imx8mp-u-boot.dtsi") breaks the loading of the fip.
This commit fixes the break by modify the configuration properly.

v2: just rebase to the latest master branch.

Ying-Chun Liu (PaulLiu) (2):
  dts: imx8mp: assign binman_configuration node name to config-SEQ
  dts: imx8mp-rsb3720: modify configrations to load fip into memory

 arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi | 10 --
 arch/arm/dts/imx8mp-u-boot.dtsi|  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)
-- 
2.35.1



[PATCH] ARM: stm32: Switch DHSOM to FMC2 EBI driver

2022-08-23 Thread Marek Vasut
Perform long overdue conversion of ad-hoc FMC2 EBI bus initialization
to upstream FMC2 EBI driver. No functional change.

Signed-off-by: Marek Vasut 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 .../dts/stm32mp15xx-dhcom-picoitx-u-boot.dtsi |  8 ---
 arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi| 14 -
 .../stm32mp15xx-dhcor-drc-compact-u-boot.dtsi | 16 --
 board/dhelectronics/dh_stm32mp1/board.c   | 52 ---
 configs/stm32mp15_dhcom_basic_defconfig   |  1 +
 configs/stm32mp15_dhcor_basic_defconfig   |  1 +
 6 files changed, 2 insertions(+), 90 deletions(-)

diff --git a/arch/arm/dts/stm32mp15xx-dhcom-picoitx-u-boot.dtsi 
b/arch/arm/dts/stm32mp15xx-dhcom-picoitx-u-boot.dtsi
index 5bc6698f87f..0bcaec50198 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom-picoitx-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcom-picoitx-u-boot.dtsi
@@ -5,14 +5,6 @@
 
 #include "stm32mp15xx-dhcom-u-boot.dtsi"
 
-/ {
-   aliases {
-   /delete-property/ ethernet1;
-   };
-};
-
-/delete-node/ &ks8851;
-
 &usbotg_hs {
dr_mode = "peripheral";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi 
b/arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi
index ee747a52bb7..8a7156c93bf 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi
@@ -9,8 +9,6 @@
 #include "stm32mp15-ddr3-dhsom-2x2Gb-1066-binG.dtsi"
 #include "stm32mp15-ddr3-dhsom-2x4Gb-1066-binG.dtsi"
 
-/delete-node/ &ksz8851;
-
 / {
aliases {
i2c1 = &i2c2;
@@ -21,7 +19,6 @@
spi0 = &qspi;
usb0 = &usbotg_hs;
eeprom0 = &eeprom0;
-   ethernet1 = &ks8851;
};
 
config {
@@ -30,12 +27,6 @@
dh,som-coding-gpios = <&gpiof 12 0>, <&gpiof 13 0>, <&gpiof 15 
0>;
dh,ddr3-coding-gpios = <&gpioz 6 0>, <&gpioz 7 0>;
};
-
-   /* This is actually on FMC2, but we do not have bus driver for that */
-   ks8851: ks8851mll@6400 {
-   compatible = "micrel,ks8851-mll";
-   reg = <0x6400 0x2>;
-   };
 };
 
 ðernet0 {
@@ -74,11 +65,6 @@
 };
 
 &pinctrl {
-   /* These should bound to FMC2 bus driver, but we do not have one */
-   pinctrl-0 = <&fmc_pins_b &mco2_pins_a>;
-   pinctrl-1 = <&fmc_sleep_pins_b &mco2_sleep_pins_a>;
-   pinctrl-names = "default", "sleep";
-
mco2_pins_a: mco2-0 {
pins {
pinmux = ; /* MCO2 */
diff --git a/arch/arm/dts/stm32mp15xx-dhcor-drc-compact-u-boot.dtsi 
b/arch/arm/dts/stm32mp15xx-dhcor-drc-compact-u-boot.dtsi
index 407fed56167..b6a6a78647a 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-drc-compact-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcor-drc-compact-u-boot.dtsi
@@ -5,25 +5,16 @@
 
 #include "stm32mp15xx-dhcor-u-boot.dtsi"
 
-/delete-node/ &ksz8851;
-
 / {
aliases {
mmc0 = &sdmmc1;
mmc1 = &sdmmc2;
usb0 = &usbotg_hs;
-   ethernet1 = &ks8851;
};
 
config {
dh,board-coding-gpios = <&gpioh 9 0>, <&gpioh 8 0>, <&gpioh 3 
0>;
};
-
-   /* This is actually on FMC2, but we do not have bus driver for that */
-   ks8851: ks8851mll@6400 {
-   compatible = "micrel,ks8851-mll";
-   reg = <0x6400 0x2>;
-   };
 };
 
 ðernet0 {
@@ -38,13 +29,6 @@
};
 };
 
-&pinctrl {
-   /* These should bound to FMC2 bus driver, but we do not have one */
-   pinctrl-0 = <&fmc_pins_b>;
-   pinctrl-1 = <&fmc_sleep_pins_b>;
-   pinctrl-names = "default", "sleep";
-};
-
 &sdmmc1 {
u-boot,dm-spl;
st,use-ckin;
diff --git a/board/dhelectronics/dh_stm32mp1/board.c 
b/board/dhelectronics/dh_stm32mp1/board.c
index e3c7ed10492..9188f5381eb 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -527,56 +527,6 @@ static void sysconf_init(void)
 #endif
 }
 
-static void board_init_fmc2(void)
-{
-#define STM32_FMC2_BCR10x0
-#define STM32_FMC2_BTR10x4
-#define STM32_FMC2_BWTR1   0x104
-#define STM32_FMC2_BCR(x)  ((x) * 0x8 + STM32_FMC2_BCR1)
-#define STM32_FMC2_BCRx_FMCEN  BIT(31)
-#define STM32_FMC2_BCRx_WREN   BIT(12)
-#define STM32_FMC2_BCRx_RSVD   BIT(7)
-#define STM32_FMC2_BCRx_FACCEN BIT(6)
-#define STM32_FMC2_BCRx_MWID(n)((n) << 4)
-#define STM32_FMC2_BCRx_MTYP(n)((n) << 2)
-#define STM32_FMC2_BCRx_MUXEN  BIT(1)
-#define STM32_FMC2_BCRx_MBKEN  BIT(0)
-#define STM32_FMC2_BTR(x)  ((x) * 0x8 + STM32_FMC2_BTR1)
-#define STM32_FMC2_BTRx_DATAHLD(n) ((n) << 30)
-#define STM32_FMC2_BTRx_BUSTURN(n) ((n) << 16)
-#define STM32_FMC2_BTRx_DATAST(n)  ((n) << 8)
-#define STM32_FMC2_BTRx_ADDHLD(n)  ((n) << 4)
-#define STM32_FMC2_BTRx_ADDSET(n)  ((n) << 0)
-
-

Re: [PATCH] ARM: imx: Deduplicate i.MX8M SNVS LPGPR unlock

2022-08-23 Thread Fabio Estevam

On 23/08/2022 14:05, Marek Vasut wrote:

Pull this LPGPR unlock into common code, since it is used in multiple
systems already.

Signed-off-by: Marek Vasut 
Cc: Fabio Estevam 
Cc: Peng Fan 
Cc: Stefano Babic 
Cc: Ye Li 
Cc: uboot-imx 


Reviewed-by: Fabio Estevam 


[PATCH] vbe: Enable command only with BOOTSTD_FULL

2022-08-23 Thread Simon Glass
Avoid enabling this command by default. This saves about 1KB of code
space.

Signed-off-by: Simon Glass 
---

 cmd/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 211ebe9c878..8ea064b8d2f 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -333,7 +333,7 @@ config BOOTM_RTEMS
 config CMD_VBE
bool "vbe - Verified Boot for Embedded"
depends on BOOTMETH_VBE
-   default y
+   default y if BOOTSTD_FULL
help
  Provides various subcommands related to VBE, such as listing the
  available methods, looking at the state and changing which method
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 7/7] tpm: Allow committing non-volatile data

2022-08-23 Thread Simon Glass
Add an option to tell the TPM to commit non-volatile data immediately it
is changed, rather than waiting until later. This is needed in some
situations, since if the device reboots it may not write the data.

Add definitions for the rest of the Cr50 commands while we are here.

Signed-off-by: Simon Glass 
---

Changes in v4:
- Rename function and add arguments for the command/subcmd

 include/tpm-v2.h | 17 +
 lib/tpm-v2.c | 21 +
 2 files changed, 38 insertions(+)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 36c6ac0be6e..737e57551d7 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -671,4 +671,21 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 
*sendbuf,
 u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd,
  u8 *recvbuf, size_t *recv_size);
 
+/**
+ * tpm2_enable_nvcommits() - Tell TPM to commit NV data immediately
+ *
+ * For Chromium OS verified boot, we may reboot or reset at different times,
+ * possibly leaving non-volatile data unwritten by the TPM.
+ *
+ * This vendor command is used to indicate that non-volatile data should be
+ * written to its store immediately.
+ *
+ * @devTPM device
+ * @vendor_cmd:Vendor command number to send
+ * @vendor_subcmd: Vendor sub-command number to send
+ * Return: result of the operation
+ */
+u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd,
+ uint vendor_subcmd);
+
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index edee9854a7c..697b982e079 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -704,3 +704,24 @@ u32 tpm2_report_state(struct udevice *dev, uint 
vendor_cmd, uint vendor_subcmd,
 
return 0;
 }
+
+u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd,
+ uint vendor_subcmd)
+{
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_NO_SESSIONS),   /* TAG */
+   tpm_u32(10 + 2),/* Length */
+   tpm_u32(vendor_cmd),/* Command code */
+
+   tpm_u16(vendor_subcmd),
+   };
+   int ret;
+
+   ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+   log_debug("ret=%s, %x\n", dev->name, ret);
+   if (ret)
+   return ret;
+
+   return 0;
+}
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 6/7] tpm: Implement state command for Cr50

2022-08-23 Thread Simon Glass
Add a vendor-specific TPM2 command for this and implement it for Cr50.
Note: This is not part of the TPM spec, but is a Cr50 extension.

Signed-off-by: Simon Glass 
---

Changes in v4:
- Rename function and add arguments for the command/subcmd

 drivers/tpm/cr50_i2c.c | 163 +
 include/tpm-v2.h   |  13 
 lib/tpm-v2.c   |  25 +++
 3 files changed, 201 insertions(+)

diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index f8c30878947..08d417a844c 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -13,11 +13,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -37,6 +39,50 @@ enum {
CR50_MAX_BUF_SIZE = 63,
 };
 
+/*
+ * Operations specific to the Cr50 TPM used on Chromium OS and Android devices
+ *
+ * FIXME: below is not enough to differentiate between vendors commands
+ * of numerous devices. However, the current tpm2 APIs aren't very amenable
+ * to extending generically because the marshaling code is assuming all
+ * knowledge of all commands.
+ */
+#define TPM2_CC_VENDOR_BIT_MASK0x2000
+
+#define TPM2_CR50_VENDOR_COMMAND   (TPM2_CC_VENDOR_BIT_MASK | 0)
+#define TPM2_CR50_SUB_CMD_IMMEDIATE_RESET  19
+#define TPM2_CR50_SUB_CMD_NVMEM_ENABLE_COMMITS 21
+#define TPM2_CR50_SUB_CMD_REPORT_TPM_STATE 23
+#define TPM2_CR50_SUB_CMD_TURN_UPDATE_ON   24
+#define TPM2_CR50_SUB_CMD_GET_REC_BTN  29
+#define TPM2_CR50_SUB_CMD_TPM_MODE 40
+#define TPM2_CR50_SUB_CMD_GET_BOOT_MODE52
+#define TPM2_CR50_SUB_CMD_RESET_EC 53
+
+/* Cr50 vendor-specific error codes. */
+#define VENDOR_RC_ERR  0x0500
+enum cr50_vendor_rc {
+   VENDOR_RC_INTERNAL_ERROR= (VENDOR_RC_ERR | 6),
+   VENDOR_RC_NO_SUCH_SUBCOMMAND= (VENDOR_RC_ERR | 8),
+   VENDOR_RC_NO_SUCH_COMMAND   = (VENDOR_RC_ERR | 127),
+};
+
+enum cr50_tpm_mode {
+   /*
+* Default state: TPM is enabled, and may be set to either
+* TPM_MODE_ENABLED or TPM_MODE_DISABLED.
+*/
+   TPM_MODE_ENABLED_TENTATIVE = 0,
+
+   /* TPM is enabled, and mode may not be changed. */
+   TPM_MODE_ENABLED = 1,
+
+   /* TPM is disabled, and mode may not be changed. */
+   TPM_MODE_DISABLED = 2,
+
+   TPM_MODE_INVALID,
+};
+
 /**
  * struct cr50_priv - Private driver data
  *
@@ -54,6 +100,41 @@ struct cr50_priv {
bool use_irq;
 };
 
+/*
+ * The below structure represents the body of the response to the 'report tpm
+ * state' vendor command.
+ *
+ * It is transferred over the wire, so it needs to be serialized/deserialized,
+ * and it is likely to change, so its contents must be versioned.
+ */
+#define TPM_STATE_VERSION  1
+struct tpm_vendor_state {
+   u32 version;
+   /*
+* The following three fields are set by the TPM in case of an assert.
+* There is no other processing than setting the source code line
+* number, error code and the first 4 characters of the function name.
+*
+* We don't expect this happening, but it is included in the report
+* just in case.
+*/
+   u32 fail_line;  /* s_failLIne */
+   u32 fail_code;  /* s_failCode */
+   char func_name[4];  /* s_failFunction, limited to 4 chars */
+
+   /*
+* The following two fields are the current time filtered value of the
+* 'failed tries' TPM counter, and the maximum allowed value of the
+* counter.
+*
+* failed_tries == max_tries is the definition of the TPM lockout
+* condition.
+*/
+   u32 failed_tries;   /* gp.failedTries */
+   u32 max_tries;  /* gp.maxTries */
+   /* The below fields are present in version 2 and above */
+};
+
 /* Wait for interrupt to indicate TPM is ready */
 static int cr50_i2c_wait_tpm_ready(struct udevice *dev)
 {
@@ -573,6 +654,87 @@ static int cr50_i2c_get_desc(struct udevice *dev, char 
*buf, int size)
return len;
 }
 
+static int stringify_state(char *buf, int len, char *str, size_t max_size)
+{
+   struct tpm_vendor_state state;
+   size_t text_size = 0;
+
+   state.version = get_unaligned_be32(buf +
+   offsetof(struct tpm_vendor_state, version));
+   state.fail_line = get_unaligned_be32(buf +
+   offsetof(struct tpm_vendor_state, fail_line));
+   state.fail_code = get_unaligned_be32(buf +
+   offsetof(struct tpm_vendor_state, fail_code));
+   memcpy(state.func_name,
+  buf + offsetof(struct tpm_vendor_state, func_name),
+  sizeof(state.func_name));
+   state.failed_tries = get_unaligned_be32(buf +
+   offsetof(struct tpm_vendor_state, failed_tries));
+   state.max_tries = get_unaligned_be32(buf +
+   offsetof(struct tpm_vendor_state, max_tries));
+
+

[PATCH v4 5/7] tpm: Allow reporting the internal state

2022-08-23 Thread Simon Glass
It is useful to read information about the current TPM state, where
supported, e.g. for debugging purposes when verified boot fails.

Add support for this to the TPM interface as well as Cr50. Add a simple
sandbox test.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/tpm-common.c   | 20 
 cmd/tpm-user-utils.h   |  2 ++
 cmd/tpm-v2.c   |  3 +++
 drivers/tpm/tpm-uclass.c   | 10 ++
 drivers/tpm/tpm2_tis_sandbox.c | 11 +++
 include/tpm-common.h   | 20 
 test/dm/Makefile   |  1 +
 test/dm/tpm.c  | 34 ++
 8 files changed, 101 insertions(+)
 create mode 100644 test/dm/tpm.c

diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
index 47adaffd184..d0c63cadf41 100644
--- a/cmd/tpm-common.c
+++ b/cmd/tpm-common.c
@@ -333,6 +333,26 @@ int do_tpm_info(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return 0;
 }
 
+int do_tpm_report_state(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   struct udevice *dev;
+   char buf[80];
+   int rc;
+
+   rc = get_tpm(&dev);
+   if (rc)
+   return rc;
+   rc = tpm_report_state(dev, buf, sizeof(buf));
+   if (rc < 0) {
+   printf("Couldn't get TPM state (%d)\n", rc);
+   return CMD_RET_FAILURE;
+   }
+   printf("%s\n", buf);
+
+   return 0;
+}
+
 int do_tpm_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct udevice *dev;
diff --git a/cmd/tpm-user-utils.h b/cmd/tpm-user-utils.h
index 358ddff5761..de4a934aab6 100644
--- a/cmd/tpm-user-utils.h
+++ b/cmd/tpm-user-utils.h
@@ -21,6 +21,8 @@ int do_tpm_device(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[]);
 int do_tpm_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_tpm_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_tpm_report_state(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[]);
 int do_tpm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
 #endif /* __TPM_USER_UTILS_H */
diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
index 4ea5f9f094f..d93b83ada93 100644
--- a/cmd/tpm-v2.c
+++ b/cmd/tpm-v2.c
@@ -359,6 +359,7 @@ static int do_tpm_pcr_setauthvalue(struct cmd_tbl *cmdtp, 
int flag,
 static struct cmd_tbl tpm2_commands[] = {
U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""),
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
+   U_BOOT_CMD_MKENT(state, 0, 1, do_tpm_report_state, "", ""),
U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
@@ -389,6 +390,8 @@ U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a 
TPMv2.x command",
 "Show all devices or set the specified device\n"
 "info\n"
 "Show information about the TPM.\n"
+"state\n"
+"Show internal state from the TPM (if available)\n"
 "init\n"
 "Initialize the software stack. Always the first command to issue.\n"
 "startup \n"
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 0eb35f50c4e..5ff0cd3958c 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -49,6 +49,16 @@ int tpm_get_desc(struct udevice *dev, char *buf, int size)
return ops->get_desc(dev, buf, size);
 }
 
+int tpm_report_state(struct udevice *dev, char *buf, int size)
+{
+   struct tpm_ops *ops = tpm_get_ops(dev);
+
+   if (!ops->report_state)
+   return -ENOSYS;
+
+   return ops->report_state(dev, buf, size);
+}
+
 /* Returns max number of milliseconds to wait */
 static ulong tpm_tis_i2c_calc_ordinal_duration(struct tpm_chip_priv *priv,
   u32 ordinal)
diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index c26f5d35abf..dd94bdc31fb 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -795,6 +795,16 @@ static int sandbox_tpm2_get_desc(struct udevice *dev, char 
*buf, int size)
return snprintf(buf, size, "Sandbox TPM2.x");
 }
 
+static int sandbox_tpm2_report_state(struct udevice *dev, char *buf, int size)
+{
+   struct sandbox_tpm2 *priv = dev_get_priv(dev);
+
+   if (size < 40)
+   return -ENOSPC;
+
+   return snprintf(buf, size, "init_done=%d", priv->init_done);
+}
+
 static int sandbox_tpm2_open(struct udevice *dev)
 {
struct sandbox_tpm2 *tpm = dev_get_priv(dev);
@@ -834,6 +844,7 @@ static const struct tpm_ops sandbox_tpm2_ops = {
.open   = sandbox_tpm2_open,
.close  = sandbox_tpm2_close,
.get_desc   = sandbox_tpm2_get_desc,
+   .report_state   = sandbox_tpm2_report_state,
.xfer 

[PATCH v4 4/7] tpm: sandbox: Allow init of TPM in a different phase

2022-08-23 Thread Simon Glass
At present the emulator assumes that the TPM is inited in the same phase
where it is used. But in fact SPL may init the TPM, so we don't want to
complain when U-Boot proper later uses it. Remove this check.

It might be best to save this information into the device state for the
TPM, so that we can make sure the TPM was inited at some point. For now,
this seems good enough.

Reviewed-by: Ilias Apalodimas 

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/tpm/tpm2_tis_sandbox.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index ac6eb143539..c26f5d35abf 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -366,8 +366,10 @@ static int sandbox_tpm2_check_readyness(struct udevice 
*dev, int command)
 
break;
default:
-   if (!tpm->tests_done)
-   return TPM2_RC_NEEDS_TEST;
+   /* Skip this, since the startup may have happened in SPL
+* if (!tpm->tests_done)
+*return TPM2_RC_NEEDS_TEST;
+*/
 
break;
}
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 3/7] tpm: Correct the define-space command in TPMv2

2022-08-23 Thread Simon Glass
The message format is incorrect. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Use constants instead of open-coded values

 lib/tpm-v2.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 6058f2e1e4f..3e240bb4c67 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -89,14 +89,18 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
 * Calculate the offset of the nv_policy piece by adding each of the
 * chunks below.
 */
-   uint offset = 10 + 8 + 13 + 14;
+   const int platform_len = sizeof(u32);
+   const int session_hdr_len = 13;
+   const int message_len = 14;
+   uint offset = TPM2_HDR_LEN + platform_len + session_hdr_len +
+   message_len;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
/* header 10 bytes */
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(offset + nv_policy_size),/* Length */
+   tpm_u32(offset + nv_policy_size + 2),/* Length */
tpm_u32(TPM2_CC_NV_DEFINE_SPACE),/* Command code */
 
-   /* handles 8 bytes */
+   /* handles 4 bytes */
tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
 
/* session header 13 bytes */
@@ -107,12 +111,15 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
tpm_u16(0), /* auth_size */
 
/* message 14 bytes + policy */
-   tpm_u16(12 + nv_policy_size),   /* size */
+   tpm_u16(message_len + nv_policy_size),  /* size */
tpm_u32(space_index),
tpm_u16(TPM2_ALG_SHA256),
tpm_u32(nv_attributes),
tpm_u16(nv_policy_size),
-   /* nv_policy */
+   /*
+* nv_policy
+* space_size
+*/
};
int ret;
 
@@ -120,8 +127,9 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
 * Fill the command structure starting from the first buffer:
 * - the password (if any)
 */
-   ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
-  offset, nv_policy, nv_policy_size);
+   ret = pack_byte_string(command_v2, sizeof(command_v2), "sw",
+  offset, nv_policy, nv_policy_size,
+  offset + nv_policy_size, space_size);
if (ret)
return TPM_LIB_ERROR;
 
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 2/7] tpm: Correct the permissions command in TPMv1

2022-08-23 Thread Simon Glass
The offset here is incorrect. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/tpm-v1.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c
index 22a769c5874..d0e3ab1b21d 100644
--- a/lib/tpm-v1.c
+++ b/lib/tpm-v1.c
@@ -456,12 +456,13 @@ u32 tpm1_get_permissions(struct udevice *dev, u32 index, 
u32 *perm)
0x0, 0x0, 0x0, 0x4,
};
const size_t index_offset = 18;
-   const size_t perm_offset = 60;
+   const size_t perm_offset = 74;
u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE];
size_t response_length = sizeof(response);
u32 err;
 
-   if (pack_byte_string(buf, sizeof(buf), "d", 0, command, sizeof(command),
+   if (pack_byte_string(buf, sizeof(buf), "sd",
+0, command, sizeof(command),
 index_offset, index))
return TPM_LIB_ERROR;
err = tpm_sendrecv_command(dev, buf, response, &response_length);
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 1/7] tpm: Require a digest source when extending the PCR

2022-08-23 Thread Simon Glass
This feature is used for measured boot, so we can add a log entry to the
TCPA with some information about where the digest comes from. It is not
currently supported in the TPM drivers, but add it to the API so that
code which expects it can signal its request.

Signed-off-by: Simon Glass 
---

(no changes since v3)

Changes in v3:
- Drop limits on the TPM hash size
- Update commit message

Changes in v2:
- Use "cmd" for the digest type in the tpm command
- Update comment for tpm_pcr_extend() 'name' parameter

 cmd/tpm-v1.c  |  3 ++-
 cmd/tpm_test.c|  5 +++--
 include/tpm_api.h |  8 +---
 lib/tpm-v2.c  |  2 ++
 lib/tpm_api.c | 10 ++
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
index bf238a9f2e3..0efb079b0a9 100644
--- a/cmd/tpm-v1.c
+++ b/cmd/tpm-v1.c
@@ -131,7 +131,8 @@ static int do_tpm_extend(struct cmd_tbl *cmdtp, int flag, 
int argc,
return CMD_RET_FAILURE;
}
 
-   rc = tpm_pcr_extend(dev, index, in_digest, out_digest);
+   rc = tpm_pcr_extend(dev, index, in_digest, sizeof(in_digest),
+   out_digest, "cmd");
if (!rc) {
puts("PCR value after execution of the command:\n");
print_byte_string(out_digest, sizeof(out_digest));
diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
index a3ccb12f53a..b35eae81dc3 100644
--- a/cmd/tpm_test.c
+++ b/cmd/tpm_test.c
@@ -91,7 +91,8 @@ static int test_early_extend(struct udevice *dev)
tpm_init(dev);
TPM_CHECK(tpm_startup(dev, TPM_ST_CLEAR));
TPM_CHECK(tpm_continue_self_test(dev));
-   TPM_CHECK(tpm_pcr_extend(dev, 1, value_in, value_out));
+   TPM_CHECK(tpm_pcr_extend(dev, 1, value_in, sizeof(value_in), value_out,
+"test"));
printf("done\n");
return 0;
 }
@@ -438,7 +439,7 @@ static int test_timing(struct udevice *dev)
   100);
TTPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)),
   100);
-   TTPM_CHECK(tpm_pcr_extend(dev, 0, in, out), 200);
+   TTPM_CHECK(tpm_pcr_extend(dev, 0, in, sizeof(in), out, "test"), 200);
TTPM_CHECK(tpm_set_global_lock(dev), 50);
TTPM_CHECK(tpm_tsc_physical_presence(dev, PHYS_PRESENCE), 100);
printf("done\n");
diff --git a/include/tpm_api.h b/include/tpm_api.h
index 11aa14eb793..8979d9d6df7 100644
--- a/include/tpm_api.h
+++ b/include/tpm_api.h
@@ -81,14 +81,16 @@ u32 tpm_nv_write_value(struct udevice *dev, u32 index, 
const void *data,
  *
  * @param dev  TPM device
  * @param indexindex of the PCR
- * @param in_digest160-bit value representing the event to be
+ * @param in_digest160/256-bit value representing the event to be
  * recorded
- * @param out_digest   160-bit PCR value after execution of the
+ * @param size size of digest in bytes
+ * @param out_digest   160/256-bit PCR value after execution of the
  * command
+ * @param name digest source, used for log output
  * Return: return code of the operation
  */
 u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
-  void *out_digest);
+  uint size, void *out_digest, const char *name);
 
 /**
  * Issue a TPM_PCRRead command.
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 1bf627853af..6058f2e1e4f 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -157,6 +157,8 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
};
int ret;
 
+   if (!digest)
+   return -EINVAL;
/*
 * Fill the command structure starting from the first buffer:
 * - the digest
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 032f383ca04..aa4a9fd406c 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -140,15 +140,17 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
 }
 
 u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
-  void *out_digest)
+  uint size, void *out_digest, const char *name)
 {
-   if (tpm_is_v1(dev))
+   if (tpm_is_v1(dev)) {
return tpm1_extend(dev, index, in_digest, out_digest);
-   else if (tpm_is_v2(dev))
+   } else if (tpm_is_v2(dev)) {
return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
   TPM2_DIGEST_LEN);
-   else
+   /* @name is ignored as we do not support measured boot */
+   } else {
return -ENOSYS;
+   }
 }
 
 u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH v4 0/7] tpm: Various minor fixes and enhancements

2022-08-23 Thread Simon Glass
This series contains some minor enhancements for the TPM code to make it
work with Chromium OS verified boot.

Changes in v4:
- Rename function and add arguments for the command/subcmd
- Rename function and add arguments for the command/subcmd

Changes in v3:
- Drop limits on the TPM hash size
- Update commit message

Changes in v2:
- Use "cmd" for the digest type in the tpm command
- Update comment for tpm_pcr_extend() 'name' parameter
- Use constants instead of open-coded values

Simon Glass (7):
  tpm: Require a digest source when extending the PCR
  tpm: Correct the permissions command in TPMv1
  tpm: Correct the define-space command in TPMv2
  tpm: sandbox: Allow init of TPM in a different phase
  tpm: Allow reporting the internal state
  tpm: Implement state command for Cr50
  tpm: Allow committing non-volatile data

 cmd/tpm-common.c   |  20 
 cmd/tpm-user-utils.h   |   2 +
 cmd/tpm-v1.c   |   3 +-
 cmd/tpm-v2.c   |   3 +
 cmd/tpm_test.c |   5 +-
 drivers/tpm/cr50_i2c.c | 163 +
 drivers/tpm/tpm-uclass.c   |  10 ++
 drivers/tpm/tpm2_tis_sandbox.c |  17 +++-
 include/tpm-common.h   |  20 
 include/tpm-v2.h   |  30 ++
 include/tpm_api.h  |   8 +-
 lib/tpm-v1.c   |   5 +-
 lib/tpm-v2.c   |  70 --
 lib/tpm_api.c  |  10 +-
 test/dm/Makefile   |   1 +
 test/dm/tpm.c  |  34 +++
 16 files changed, 380 insertions(+), 21 deletions(-)
 create mode 100644 test/dm/tpm.c

-- 
2.37.2.609.g9ff673ca1a-goog



[PATCH] spi: stm32_spi: Fix GPIO chipselect polarity handling

2022-08-23 Thread Marek Vasut
The GPIO chipselect signal polarity is handled by the GPIO core code,
the driver code is only responsible for asserting and deasserting the
GPIO. Do not invert the GPIO polarity in the driver code.

For example, In case CS GPIO is active low, then the DT must contain
GPIO_ACTIVE_LOW flag and the GPIO core code would set the GPIO accordingly.

Signed-off-by: Marek Vasut 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
---
 drivers/spi/stm32_spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c
index fe5419e8518..0cb24546ca9 100644
--- a/drivers/spi/stm32_spi.c
+++ b/drivers/spi/stm32_spi.c
@@ -434,7 +434,7 @@ static int stm32_spi_xfer(struct udevice *slave, unsigned 
int bitlen,
 
slave_plat = dev_get_parent_plat(slave);
if (flags & SPI_XFER_BEGIN)
-   stm32_spi_set_cs(bus, slave_plat->cs, false);
+   stm32_spi_set_cs(bus, slave_plat->cs, true);
 
/* Be sure to have data in fifo before starting data transfer */
if (priv->tx_buf)
@@ -485,7 +485,7 @@ static int stm32_spi_xfer(struct udevice *slave, unsigned 
int bitlen,
stm32_spi_stopxfer(bus);
 
if (flags & SPI_XFER_END)
-   stm32_spi_set_cs(bus, slave_plat->cs, true);
+   stm32_spi_set_cs(bus, slave_plat->cs, false);
 
return xfer_status;
 }
-- 
2.35.1



[PATCH 1/2] usb: gadget: designware-udc: Drop the driver

2022-08-23 Thread Marek Vasut
This driver is not used by any system and is long unmaintained, drop it.
There is a DWC2 OTG driver which is maintained, see CONFIG_USB_GADGET_DWC2_OTG .

Signed-off-by: Marek Vasut 
---
Cc: Heiko Schocher 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 drivers/serial/usbtty.h |2 -
 drivers/usb/gadget/Makefile |1 -
 drivers/usb/gadget/designware_udc.c | 1021 ---
 include/usb/designware_udc.h|  183 -
 4 files changed, 1207 deletions(-)
 delete mode 100644 drivers/usb/gadget/designware_udc.c
 delete mode 100644 include/usb/designware_udc.h

diff --git a/drivers/serial/usbtty.h b/drivers/serial/usbtty.h
index 0d89fc085fb..e27aa368c9a 100644
--- a/drivers/serial/usbtty.h
+++ b/drivers/serial/usbtty.h
@@ -13,8 +13,6 @@
 #include 
 #if defined(CONFIG_PPC)
 #include 
-#elif defined(CONFIG_DW_UDC)
-#include 
 #elif defined(CONFIG_CI_UDC)
 #include 
 #endif
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 306dd3127f4..dd09ee01959 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -42,6 +42,5 @@ else
 ifdef CONFIG_USB_DEVICE
 obj-y += core.o
 obj-y += ep0.o
-obj-$(CONFIG_DW_UDC) += designware_udc.o
 endif
 endif
diff --git a/drivers/usb/gadget/designware_udc.c 
b/drivers/usb/gadget/designware_udc.c
deleted file mode 100644
index 41a6e8cb7d3..000
--- a/drivers/usb/gadget/designware_udc.c
+++ /dev/null
@@ -1,1021 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Based on drivers/usb/gadget/omap1510_udc.c
- * TI OMAP1510 USB bus interface driver
- *
- * (C) Copyright 2009
- * Vipin Kumar, STMicroelectronics, vipin.ku...@st.com.
- */
-
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include "ep0.h"
-#include 
-#include 
-#include 
-
-#define UDC_INIT_MDELAY80  /* Device settle delay */
-
-/* Some kind of debugging output... */
-#ifndef DEBUG_DWUSBTTY
-#define UDCDBG(str)
-#define UDCDBGA(fmt, args...)
-#else
-#define UDCDBG(str) serial_printf(str "\n")
-#define UDCDBGA(fmt, args...) serial_printf(fmt "\n", ##args)
-#endif
-
-static struct urb *ep0_urb;
-static struct usb_device_instance *udc_device;
-
-static struct plug_regs *const plug_regs_p =
-(struct plug_regs * const)CONFIG_SYS_PLUG_BASE;
-static struct udc_regs *const udc_regs_p =
-(struct udc_regs * const)CONFIG_SYS_USBD_BASE;
-static struct udc_endp_regs *const outep_regs_p =
-&((struct udc_regs * const)CONFIG_SYS_USBD_BASE)->out_regs[0];
-static struct udc_endp_regs *const inep_regs_p =
-&((struct udc_regs * const)CONFIG_SYS_USBD_BASE)->in_regs[0];
-
-/*
- * udc_state_transition - Write the next packet to TxFIFO.
- * @initial:   Initial state.
- * @final: Final state.
- *
- * Helper function to implement device state changes. The device states and
- * the events that transition between them are:
- *
- * STATE_ATTACHED
- * ||  /\
- * \/  ||
- * DEVICE_HUB_CONFIGURED   DEVICE_HUB_RESET
- * ||  /\
- * \/  ||
- * STATE_POWERED
- * ||  /\
- * \/  ||
- * DEVICE_RESETDEVICE_POWER_INTERRUPTION
- * ||  /\
- * \/  ||
- * STATE_DEFAULT
- * ||  /\
- * \/  ||
- * DEVICE_ADDRESS_ASSIGNED DEVICE_RESET
- * ||  /\
- * \/  ||
- * STATE_ADDRESSED
- * ||  /\
- * \/  ||
- * DEVICE_CONFIGURED   DEVICE_DE_CONFIGURED
- * ||  /\
- * \/  ||
- * STATE_CONFIGURED
- *
- * udc_state_transition transitions up (in the direction from STATE_ATTACHED
- * to STATE_CONFIGURED) from the specified initial state to the specified final
- * state, passing through each intermediate state on the way. If the initial
- * state is at or above (i.e. nearer to STATE_CONFIGURED) the final state, then
- * no state transitions will take place.
- *
- * udc_state_transition also transitions down (in the direction from
- * STATE_CONFIGURED to STATE_ATTACHED) from the specified initial state to the
- * specified final state, passing through each intermediate state on the way.
- * If the initial state is at or below (i.e. nearer to STATE_ATTACHED) the 
final
- * state, then no state transitions will take place.
- *
- * This function must only be called with interrupts disabled.
- */
-static void udc_state_transition(usb_device_state_t initial,
-usb_device_state

[PATCH 2/2] usb: gadget: Clean up Makefile ifdeffery

2022-08-23 Thread Marek Vasut
Take the USB_ETHER ifdef block apart and make use of obj-$(VAR) instead
to include the source files in build. The duplicate CI_UDC entry is now
removed, the USB_DEVICE ifdef is now reduced to core.o ep.o addition,
the ether.o can be conditionally compiled in using USB_ETHER.

No functional change.

Signed-off-by: Marek Vasut 
---
Cc: Heiko Schocher 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 drivers/usb/gadget/Makefile | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index dd09ee01959..9c04403da30 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -21,7 +21,6 @@ obj-$(CONFIG_USB_GADGET_DWC2_OTG) += dwc2_udc_otg.o
 obj-$(CONFIG_USB_GADGET_DWC2_OTG_PHY) += dwc2_udc_otg_phy.o
 obj-$(CONFIG_USB_GADGET_FOTG210) += fotg210.o
 obj-$(CONFIG_USB_GADGET_MAX3420) += max3420_udc.o
-obj-$(CONFIG_CI_UDC)   += ci_udc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_USB_GADGET_DOWNLOAD) += g_dnl.o
 obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
@@ -33,14 +32,12 @@ obj-$(CONFIG_USB_FUNCTION_ROCKUSB) += f_rockusb.o
 obj-$(CONFIG_USB_FUNCTION_ACM) += f_acm.o
 endif
 endif
-ifdef CONFIG_USB_ETHER
-obj-y += ether.o
+
+obj-$(CONFIG_CI_UDC) += ci_udc.o
+
+obj-$(CONFIG_USB_ETHER) += ether.o
 obj-$(CONFIG_USB_ETH_RNDIS) += rndis.o
-obj-$(CONFIG_CI_UDC)   += ci_udc.o
-else
+
 # Devices not related to the new gadget layer depend on CONFIG_USB_DEVICE
-ifdef CONFIG_USB_DEVICE
-obj-y += core.o
-obj-y += ep0.o
-endif
-endif
+# This is really only N900 and USBTTY now.
+obj-$(CONFIG_USB_DEVICE) += core.o ep0.o
-- 
2.35.1



[PATCH] ARM: imx: Deduplicate i.MX8M SNVS LPGPR unlock

2022-08-23 Thread Marek Vasut
Pull this LPGPR unlock into common code, since it is used in multiple
systems already.

Signed-off-by: Marek Vasut 
Cc: Fabio Estevam 
Cc: Peng Fan 
Cc: Stefano Babic 
Cc: Ye Li 
Cc: uboot-imx 
---
 arch/arm/include/asm/arch-imx8m/imx-regs.h|  5 +
 arch/arm/mach-imx/imx8m/soc.c | 12 ++
 .../imx8mm_data_modul_edm_sbc.c   | 22 ---
 .../dh_imx8mp/imx8mp_dhcom_pdk2.c | 17 --
 board/menlo/mx8menlo/mx8menlo.c   | 17 --
 5 files changed, 17 insertions(+), 56 deletions(-)

diff --git a/arch/arm/include/asm/arch-imx8m/imx-regs.h 
b/arch/arm/include/asm/arch-imx8m/imx-regs.h
index ff3b9ddd9f7..29d5baaab8b 100644
--- a/arch/arm/include/asm/arch-imx8m/imx-regs.h
+++ b/arch/arm/include/asm/arch-imx8m/imx-regs.h
@@ -27,6 +27,7 @@
 #define IOMUXC_GPR_BASE_ADDR   0x3034
 #define OCOTP_BASE_ADDR0x3035
 #define ANATOP_BASE_ADDR   0x3036
+#define SNVS_BASE_ADDR 0x3037
 #define CCM_BASE_ADDR  0x3038
 #define SRC_BASE_ADDR  0x3039
 #define GPC_BASE_ADDR  0x303A
@@ -113,6 +114,10 @@
 #define SRC_DDR1_RCR_CORE_RESET_N_MASK BIT(1)
 #define SRC_DDR1_RCR_PRESET_N_MASK BIT(0)
 
+#define SNVS_LPSR  0x4c
+#define SNVS_LPLVDR0x64
+#define SNVS_LPPGDR_INIT   0x41736166
+
 struct iomuxc_gpr_base_regs {
u32 gpr[47];
 };
diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index d115b25a5b6..5739546c022 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -544,6 +544,16 @@ static int imx8m_check_clock(void *ctx, struct event 
*event)
 }
 EVENT_SPY(EVT_DM_POST_INIT, imx8m_check_clock);
 
+static void imx8m_setup_snvs(void)
+{
+   /* Enable SNVS clock */
+   clock_enable(CCGR_SNVS, 1);
+   /* Initialize glitch detect */
+   writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
+   /* Clear interrupt status */
+   writel(0x, SNVS_BASE_ADDR + SNVS_LPSR);
+}
+
 int arch_cpu_init(void)
 {
struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
@@ -594,6 +604,8 @@ int arch_cpu_init(void)
writel(0x200, &ocotp->ctrl_clr);
}
 
+   imx8m_setup_snvs();
+
return 0;
 }
 
diff --git a/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c 
b/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
index 6dc4e6a9a2b..a5905051dad 100644
--- a/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
+++ b/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
@@ -34,22 +34,6 @@ int board_phys_sdram_size(phys_size_t *size)
return 0;
 }
 
-/* IMX8M SNVS registers needed for the bootcount functionality */
-#define SNVS_BASE_ADDR 0x3037
-#define SNVS_LPSR  0x4c
-#define SNVS_LPLVDR0x64
-#define SNVS_LPPGDR_INIT   0x41736166
-
-static void setup_snvs(void)
-{
-   /* Enable SNVS clock */
-   clock_enable(CCGR_SNVS, 1);
-   /* Initialize glitch detect */
-   writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
-   /* Clear interrupt status */
-   writel(0x, SNVS_BASE_ADDR + SNVS_LPSR);
-}
-
 static void setup_mac_address(void)
 {
unsigned char enetaddr[6];
@@ -97,12 +81,6 @@ static void setup_boot_device(void)
env_set_ulong("devnum", 1);
 }
 
-int board_init(void)
-{
-   setup_snvs();
-   return 0;
-}
-
 int board_late_init(void)
 {
struct udevice *dev;
diff --git a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c 
b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
index 6f06daf86f7..9d8e19d994a 100644
--- a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
+++ b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
@@ -37,22 +37,6 @@ int board_phys_sdram_size(phys_size_t *size)
return 0;
 }
 
-/* IMX8M SNVS registers needed for the bootcount functionality */
-#define SNVS_BASE_ADDR 0x3037
-#define SNVS_LPSR  0x4c
-#define SNVS_LPLVDR0x64
-#define SNVS_LPPGDR_INIT   0x41736166
-
-static void setup_snvs(void)
-{
-   /* Enable SNVS clock */
-   clock_enable(CCGR_SNVS, 1);
-   /* Initialize glitch detect */
-   writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
-   /* Clear interrupt status */
-   writel(0x, SNVS_BASE_ADDR + SNVS_LPSR);
-}
-
 static void setup_eqos(void)
 {
struct iomuxc_gpr_base_regs *gpr =
@@ -145,7 +129,6 @@ int board_init(void)
 {
setup_eqos();
setup_fec();
-   setup_snvs();
return 0;
 }
 
diff --git a/board/menlo/mx8menlo/mx8menlo.c b/board/menlo/mx8menlo/mx8menlo.c
index 9d3708a3637..61fc4ec85f0 100644
--- a/board/menlo/mx8menlo/mx8menlo.c
+++ b/board/menlo/mx8menlo/mx8menlo.c
@@ -12,24 +12,7 @@
 #include 
 #include 
 
-#define SNVS_BASE_

[PATCH] board: ti: common: board_detect: Fix EEPROM read quirk

2022-08-23 Thread Matwey V. Kornilov
There are three different kinds of EEPROM possibly present on boards.
  1. 1byte address. For those we should avoid 2byte address in order
 not to rewrite the data. Second byte of the address can potentially
 be interpreted as the data to write.
  2. 2byte address with defined behaviour. When we try to use 1byte
 address they just return "FF FF FF FF ... FF"
  3. 2byte address with undefined behaviour (for instance, 24LC32AI).
 When we try to use 1byte address, then their internal read
 pointer is changed to some value. Subsequential reads may be
 broken.

To gracefully handle both case #1 and case #3 we read all required
data from EEPROM at once (about 80 bytes). So either all the data is
valid or we fallback to 2byte address.

Cc: Nishanth Menon 
Fixes: a58147c2dbbf ("board: ti: common: board_detect: Do 1byte address checks 
first.")
Reference: 
https://lore.kernel.org/all/CAJs94Ebdd4foOjhGFu9Bop0v=b1us9nedlxfhgcy23ukglz...@mail.gmail.com/
Signed-off-by: Matwey V. Kornilov 
---
 board/ti/common/board_detect.c | 26 --
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
index ed34991377..fdf83fcfb0 100644
--- a/board/ti/common/board_detect.c
+++ b/board/ti/common/board_detect.c
@@ -86,7 +86,6 @@ __weak void gpi2c_init(void)
 static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
u32 header, u32 size, uint8_t *ep)
 {
-   u32 hdr_read = 0xdeadbeef;
int rc;
 
 #if CONFIG_IS_ENABLED(DM_I2C)
@@ -113,10 +112,10 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, 
int dev_addr,
 * We must allow for fall through to check the data if 2 byte
 * addressing works
 */
-   (void)dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
+   (void)dm_i2c_read(dev, 0, ep, size);
 
/* Corrupted data??? */
-   if (hdr_read != header) {
+   if (*((u32 *)ep) != header) {
/*
 * read the eeprom header using i2c again, but use only a
 * 2 byte address (some newer boards need this..)
@@ -125,16 +124,12 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, 
int dev_addr,
if (rc)
return rc;
 
-   rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
+   rc = dm_i2c_read(dev, 0, ep, size);
if (rc)
return rc;
}
-   if (hdr_read != header)
+   if (*((u32 *)ep) != header)
return -1;
-
-   rc = dm_i2c_read(dev, 0, ep, size);
-   if (rc)
-   return rc;
 #else
u32 byte;
 
@@ -154,26 +149,21 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, 
int dev_addr,
 * We must allow for fall through to check the data if 2 byte
 * addressing works
 */
-   (void)i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4);
+   (void)i2c_read(dev_addr, 0x0, byte, ep, size);
 
/* Corrupted data??? */
-   if (hdr_read != header) {
+   if (*((u32 *)ep) != header) {
/*
 * read the eeprom header using i2c again, but use only a
 * 2 byte address (some newer boards need this..)
 */
byte = 2;
-   rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read,
- 4);
+   rc = i2c_read(dev_addr, 0x0, byte, ep, size);
if (rc)
return rc;
}
-   if (hdr_read != header)
+   if (*((u32 *)ep) != header)
return -1;
-
-   rc = i2c_read(dev_addr, 0x0, byte, ep, size);
-   if (rc)
-   return rc;
 #endif
return 0;
 }
-- 
2.26.2



Please pull u-boot-marvell/master

2022-08-23 Thread Stefan Roese

Hi Tom,

please pull this next batch of mostly Marvell related patches:


- kirkwood: pogo_v4 & nsa310s: Add distro boot (Tony)
- kirkwood: add DM timer support and use it on lsxl boards (Michael)
- kirkwood: convert the Buffalo Linkstation LS-CHLv2 and XHL boards
  to DM (Michael)
- mvebu: turris_mox/omnia: misc improments (Pali)
- mvebu: mbus: Fix mbus driver to work also after U-Boot relocation (Pali)


Here the Azure build, without any issues:

https://dev.azure.com/sr0718/u-boot/_build/results?buildId=241&view=results

Thanks,
Stefan

The following changes since commit 1d323d83061fae8f94a9118b8db3384daef26216:

  Prepare v2022.10-rc3 (2022-08-22 18:54:48 -0400)

are available in the Git repository at:

  g...@source.denx.de:u-boot/custodians/u-boot-marvell.git

for you to fetch changes up to 560a5c3bb3bedac7d1da93362401a1d926214660:

  board: lsxl: update the README (2022-08-23 12:40:34 +0200)


Michael Walle (21):
  time: move the CONFIG_SYS_TIMER_RATE handling to the compiler
  arm: kirkwood: make it CONFIG_TIMER aware
  timer: add orion-timer support
  button: gpio: add DM_GPIO dependency
  board: lsxl: limit size to 384kiB
  board: lsxl: remove unused features
  board: lsxl: remove eraseenv script
  board: lsxl: remove CONFIG_ENV_OVERWRITE
  board: lsxl: remove unused header files
  board: lsxl: automatically select CONFIG_MISC_INIT_R
  board: lsxl: use CONFIG_DEFAULT_FDT_FILE
  board: lsxl: reorder image loading and remove ramdisk_len
  board: lsxl: use proper *_r variables
  board: lsxl: enable ATAGS support
  board: lsxl: make last resort recovery more reliable
  board: lsxl: convert to DM_GPIO
  board: lsxl: convert to DM_ETH
  board: lsxl: convert to DM_SERIAL
  board: lsxl: convert to CONFIG_TIMER
  board: lsxl: disable eth0
  board: lsxl: update the README

Pali Rohár (5):
  arm: mvebu: Define env_sf_get_env_addr() for all Armada boards in SPL
  arm: mvebu: turris_omnia: Show MCU version
  arm: mvebu: turris_mox: Set "sfp" label in eth1 DT node when only 
Mox SFP is detected
  arm: mvebu: mbus: Fix mbus driver to work also after U-Boot 
relocation

  arm: kirkwood: 88f6281: Detect CONFIG_SYS_TCLK from SAR register

Tony Dinh (2):
  arm: kirkwood: pogo_v4: Add Distro boot capability
  arm: kirkwood: nsa310s: Add Distro boot capability

 arch/arm/dts/kirkwood-lschlv2-u-boot.dtsi   |  13 ++
 arch/arm/dts/kirkwood-lsxhl-u-boot.dtsi |  13 ++
 arch/arm/mach-kirkwood/Kconfig  |   2 +
 arch/arm/mach-kirkwood/include/mach/config.h|   2 +
 arch/arm/mach-kirkwood/include/mach/cpu.h   |   3 -
 arch/arm/mach-kirkwood/include/mach/kw88f6281.h |   3 +-
 arch/arm/mach-kirkwood/include/mach/soc.h   |   2 +
 arch/arm/mach-mvebu/Makefile|   3 +
 arch/arm/mach-mvebu/include/mach/cpu.h  |   3 -
 arch/arm/mach-mvebu/mbus.c  | 167 
++--

 arch/arm/mach-mvebu/spl.c   |  13 ++
 board/CZ.NIC/turris_mox/turris_mox.c|   5 +
 board/CZ.NIC/turris_omnia/turris_omnia.c|  46 +--
 board/Synology/ds109/ds109.c|   1 +
 board/alliedtelesis/x530/x530.c |   2 +-
 board/buffalo/lsxl/README   |  32 ++---
 board/buffalo/lsxl/lsxl.c   | 165 
+--

 board/maxbcm/maxbcm.c   |   8 +-
 board/theadorable/theadorable.c |   4 +-
 board/zyxel/nsa310s/MAINTAINERS |   1 -
 configs/lschlv2_defconfig   |  31 +++--
 configs/lsxhl_defconfig |  31 +++--
 configs/nsa310s_defconfig   |  17 +--
 configs/pogo_v4_defconfig   |  25 ++--
 drivers/button/Kconfig  |   1 +
 drivers/timer/Kconfig   |   6 +
 drivers/timer/Makefile  |   1 +
 drivers/timer/orion-timer.c |  63 +
 include/configs/lsxl.h  |  76 ---
 include/configs/nsa310s.h   |  31 -
 include/configs/pogo_v4.h   |  54 ++--
 include/linux/mbus.h|  13 +-
 lib/time.c  |  15 ++-
 33 files changed, 521 insertions(+), 331 deletions(-)
 create mode 100644 arch/arm/dts/kirkwood-lschlv2-u-boot.dtsi
 create mode 100644 arch/arm/dts/kirkwood-lsxhl-u-boot.dtsi
 create mode 100644 drivers/timer/orion-timer.c


Re: [PATCH 00/22] board: lsxl: major update and DM conversion

2022-08-23 Thread Michael Walle

Am 2022-08-23 17:01, schrieb Stefan Roese:

Applied to u-boot-marvell/master, with my small fix for the ds109
board


Great! Thanks, Stefan.

-michael


Re: [PATCH 00/22] board: lsxl: major update and DM conversion

2022-08-23 Thread Stefan Roese

On 17.08.22 21:37, Michael Walle wrote:

Convert the Buffalo Linkstation LS-CHLv2 and XHL boards to DM_GPIO,
DM_ETH, DM_SERIAL and CONFIG_TIMER.

Patches 01-02 fix TCLK handling on the kirkwood SoC if the clock is
166MHz.
Patches 03-04 add CONFIG_TIMER support for kirkwood/mvebu.
Patches 05-21 will then update the lsxl board

Michael Walle (21):
   time: move the CONFIG_SYS_TIMER_RATE handling to the compiler
   arm: kirkwood: make it CONFIG_TIMER aware
   timer: add orion-timer support
   button: gpio: add DM_GPIO dependency
   board: lsxl: limit size to 384kiB
   board: lsxl: remove unused features
   board: lsxl: remove eraseenv script
   board: lsxl: remove CONFIG_ENV_OVERWRITE
   board: lsxl: remove unused header files
   board: lsxl: automatically select CONFIG_MISC_INIT_R
   board: lsxl: use CONFIG_DEFAULT_FDT_FILE
   board: lsxl: reorder image loading and remove ramdisk_len
   board: lsxl: use proper *_r variables
   board: lsxl: enable ATAGS support
   board: lsxl: make last resort recovery more reliable
   board: lsxl: convert to DM_GPIO
   board: lsxl: convert to DM_ETH
   board: lsxl: convert to DM_SERIAL
   board: lsxl: convert to CONFIG_TIMER
   board: lsxl: disable eth0
   board: lsxl: update the README

Pali Rohár (1):
   arm: kirkwood: 88f6281: Detect CONFIG_SYS_TCLK from SAR register

  arch/arm/dts/kirkwood-lschlv2-u-boot.dtsi |  13 ++
  arch/arm/dts/kirkwood-lsxhl-u-boot.dtsi   |  13 ++
  arch/arm/mach-kirkwood/Kconfig|   2 +
  arch/arm/mach-kirkwood/include/mach/config.h  |   2 +
  .../mach-kirkwood/include/mach/kw88f6281.h|   3 +-
  arch/arm/mach-kirkwood/include/mach/soc.h |   2 +
  arch/arm/mach-mvebu/Makefile  |   3 +
  board/buffalo/lsxl/README |  32 ++--
  board/buffalo/lsxl/lsxl.c | 165 +++---
  configs/lschlv2_defconfig |  31 +++-
  configs/lsxhl_defconfig   |  31 +++-
  drivers/button/Kconfig|   1 +
  drivers/timer/Kconfig |   6 +
  drivers/timer/Makefile|   1 +
  drivers/timer/orion-timer.c   |  63 +++
  include/configs/lsxl.h|  76 +++-
  lib/time.c|  15 +-
  17 files changed, 300 insertions(+), 159 deletions(-)
  create mode 100644 arch/arm/dts/kirkwood-lschlv2-u-boot.dtsi
  create mode 100644 arch/arm/dts/kirkwood-lsxhl-u-boot.dtsi
  create mode 100644 drivers/timer/orion-timer.c



Applied to u-boot-marvell/master, with my small fix for the ds109
board

Thanks,
Stefan


Re: [RESEND PATCH] arm: kirkwood: nsa310s: Add Distro boot capability

2022-08-23 Thread Stefan Roese

On 12.08.22 01:40, Tony Dinh wrote:

- Add distro boot to board include file and deconfig file
- Miscellaneous changes:
- Remove Gerald from maintainer list (email bounced)
- Add CONFIG_SUPPORT_PASSING_ATAGS and friends to support legacy
kernel method of booting (e.g. OpenWrt) with appended DTB.
- Add CONFIG_UBIFS_SILENCE_MSG to reduce binary size.

Note that this patch is depended on the following patch:
https://patchwork.ozlabs.org/project/uboot/patch/20220807192709.21717-1-p...@kernel.org/

Signed-off-by: Tony Dinh 


Applied to u-boot-marvell/master

Thanks,
Stefan


---

  board/zyxel/nsa310s/MAINTAINERS |  1 -
  configs/nsa310s_defconfig   | 17 +
  include/configs/nsa310s.h   | 31 +--
  3 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/board/zyxel/nsa310s/MAINTAINERS b/board/zyxel/nsa310s/MAINTAINERS
index d153758c21..11106acf3e 100644
--- a/board/zyxel/nsa310s/MAINTAINERS
+++ b/board/zyxel/nsa310s/MAINTAINERS
@@ -1,5 +1,4 @@
  NSA310S BOARD
-M: Gerald Kerma 
  M:Tony Dinh 
  M:Luka Perkov 
  S:Maintained
diff --git a/configs/nsa310s_defconfig b/configs/nsa310s_defconfig
index 2b39ae74b3..a5f01ef88e 100644
--- a/configs/nsa310s_defconfig
+++ b/configs/nsa310s_defconfig
@@ -4,6 +4,9 @@ CONFIG_SYS_DCACHE_OFF=y
  CONFIG_ARCH_CPU_INIT=y
  CONFIG_SYS_THUMB_BUILD=y
  CONFIG_ARCH_KIRKWOOD=y
+CONFIG_SUPPORT_PASSING_ATAGS=y
+CONFIG_CMDLINE_TAG=y
+CONFIG_INITRD_TAG=y
  CONFIG_SYS_KWD_CONFIG="board/zyxel/nsa310s/kwbimage.cfg"
  CONFIG_SYS_TEXT_BASE=0x60
  CONFIG_SYS_MALLOC_F_LEN=0x400
@@ -14,35 +17,25 @@ CONFIG_ENV_OFFSET=0xE
  CONFIG_DEFAULT_DEVICE_TREE="kirkwood-nsa310s"
  CONFIG_IDENT_STRING="\nZyXEL NSA310S/320S 1/2-Bay Power Media Server"
  CONFIG_SYS_LOAD_ADDR=0x80
+CONFIG_DISTRO_DEFAULTS=y
  CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
  CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xc8012000
  CONFIG_BOOTDELAY=3
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="setenv bootargs ${console} ${mtdparts} ${bootargs_root}; ubi 
part root; ubifsmount ubi:rootfs; ubifsload 0x80 ${kernel}; ubifsload 0x70 
${fdt}; ubifsumount; fdt addr 0x70; fdt resize; fdt chosen; bootz 0x80 - 
0x70"
  CONFIG_USE_PREBOOT=y
  # CONFIG_DISPLAY_BOARDINFO is not set
-CONFIG_HUSH_PARSER=y
  CONFIG_SYS_PROMPT="NSA310s> "
  CONFIG_SYS_MAXARGS=32
  CONFIG_SYS_PBSIZE=1050
-CONFIG_CMD_BOOTZ=y
  # CONFIG_CMD_FLASH is not set
  CONFIG_CMD_NAND=y
  CONFIG_CMD_SATA=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MII=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_EXT2=y
-CONFIG_CMD_FAT=y
-CONFIG_CMD_FS_GENERIC=y
  CONFIG_CMD_JFFS2=y
  CONFIG_CMD_MTDPARTS=y
  CONFIG_MTDIDS_DEFAULT="nand0=orion_nand"
  
CONFIG_MTDPARTS_DEFAULT="mtdparts=orion_nand:0xe@0x0(uboot),0x2@0xe(uboot_env),0x10@0x10(second_stage_uboot),-@0x20(root)"
  CONFIG_CMD_UBI=y
-CONFIG_ISO_PARTITION=y
  CONFIG_OF_CONTROL=y
  CONFIG_ENV_OVERWRITE=y
  CONFIG_ENV_IS_IN_NAND=y
@@ -65,6 +58,6 @@ CONFIG_MII=y
  CONFIG_SYS_NS16550=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
-CONFIG_USB_STORAGE=y
+CONFIG_UBIFS_SILENCE_MSG=y
  CONFIG_LZMA=y
  CONFIG_BZIP2=y
diff --git a/include/configs/nsa310s.h b/include/configs/nsa310s.h
index 027a47b5a3..62f0701180 100644
--- a/include/configs/nsa310s.h
+++ b/include/configs/nsa310s.h
@@ -9,15 +9,42 @@
  #ifndef _CONFIG_NSA310S_H
  #define _CONFIG_NSA310S_H
  
+/*

+ * mv-common.h should be defined after CMD configs since it used them
+ * to enable certain macros
+ */
  #include "mv-common.h"
  
-/* default environment variables */

+/* Include the common distro boot environment */
+#ifndef CONFIG_SPL_BUILD
+
+#define BOOT_TARGET_DEVICES(func) \
+   func(USB, usb, 0) \
+   func(SATA, sata, 0) \
+   func(DHCP, dhcp, na)
+
+#define KERNEL_ADDR_R  __stringify(0x80)
+#define FDT_ADDR_R __stringify(0x2c0)
+#define RAMDISK_ADDR_R __stringify(0x0110)
+#define SCRIPT_ADDR_R  __stringify(0x20)
+
+#define LOAD_ADDRESS_ENV_SETTINGS \
+   "kernel_addr_r=" KERNEL_ADDR_R "\0" \
+   "fdt_addr_r=" FDT_ADDR_R "\0" \
+   "ramdisk_addr_r=" RAMDISK_ADDR_R "\0" \
+   "scriptaddr=" SCRIPT_ADDR_R "\0"
+
+#include 
  
  #define CONFIG_EXTRA_ENV_SETTINGS \

"console=console=ttyS0,115200\0" \
"kernel=/boot/zImage\0" \
"fdt=/boot/nsa310s.dtb\0" \
-   "bootargs_root=ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs rw\0"
+   "bootargs_root=ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs rw\0" \
+   LOAD_ADDRESS_ENV_SETTINGS \
+   BOOTENV
+
+#endif /* CONFIG_SPL_BUILD */
  
  /* Ethernet driver configuration */

  #define CONFIG_MVGBE_PORTS{1, 0}  /* enable port 0 only */


Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH] arm: mvebu: mbus: Fix mbus driver to work also after U-Boot relocation

2022-08-23 Thread Stefan Roese

On 10.08.22 14:46, Pali Rohár wrote:

mbus driver is initialized from arch_cpu_init() callback which is called
before relocation. This driver stores lot of functions and structure
pointers into global variables, so it is data position dependent.

Therefore after relocations all pointers are invalid and driver does not
work anymore as all pointers referes to the old memory, which overlaps with
CONFIG_SYS_LOAD_ADDR and ${loadaddr}.

For example U-Boot fuse command crashes if loadaddr memory is cleared or
rewritten by some image loaded by U-Boot load command.

   mw.w ${loadaddr} 0x0 1
   fuse read 0 1 2

Fix this issue by removing of all mbus global variables in which are stored
pointers to structures or functions which changes during relocation. And
replace it by direct function calls (not via pointers). With this change
fuse command finally works.

Signed-off-by: Pali Rohár 


Applied to u-boot-marvell/master

Thanks,
Stefan


---
  arch/arm/mach-kirkwood/include/mach/cpu.h |   3 -
  arch/arm/mach-mvebu/include/mach/cpu.h|   3 -
  arch/arm/mach-mvebu/mbus.c| 167 +-
  board/alliedtelesis/x530/x530.c   |   2 +-
  board/maxbcm/maxbcm.c |   8 +-
  board/theadorable/theadorable.c   |   4 +-
  include/linux/mbus.h  |  13 +-
  7 files changed, 75 insertions(+), 125 deletions(-)

diff --git a/arch/arm/mach-kirkwood/include/mach/cpu.h 
b/arch/arm/mach-kirkwood/include/mach/cpu.h
index 71c546f9acf6..d8639c60352b 100644
--- a/arch/arm/mach-kirkwood/include/mach/cpu.h
+++ b/arch/arm/mach-kirkwood/include/mach/cpu.h
@@ -144,9 +144,6 @@ struct kwgpio_registers {
u32 irq_level;
  };
  
-/* Needed for dynamic (board-specific) mbus configuration */

-extern struct mvebu_mbus_state mbus_state;
-
  /*
   * functions
   */
diff --git a/arch/arm/mach-mvebu/include/mach/cpu.h 
b/arch/arm/mach-mvebu/include/mach/cpu.h
index 689c96bd4eac..d9fa1f32aa52 100644
--- a/arch/arm/mach-mvebu/include/mach/cpu.h
+++ b/arch/arm/mach-mvebu/include/mach/cpu.h
@@ -122,9 +122,6 @@ struct sar_freq_modes {
u32 d_clk;
  };
  
-/* Needed for dynamic (board-specific) mbus configuration */

-extern struct mvebu_mbus_state mbus_state;
-
  /*
   * functions
   */
diff --git a/arch/arm/mach-mvebu/mbus.c b/arch/arm/mach-mvebu/mbus.c
index 3b1b9f73ebf6..7092f6cc10c2 100644
--- a/arch/arm/mach-mvebu/mbus.c
+++ b/arch/arm/mach-mvebu/mbus.c
@@ -88,31 +88,34 @@
  
  #define DOVE_DDR_BASE_CS_OFF(n) ((n) << 4)
  
-struct mvebu_mbus_state;

-
-struct mvebu_mbus_soc_data {
-   unsigned int num_wins;
-   unsigned int num_remappable_wins;
-   unsigned int (*win_cfg_offset)(const int win);
-   void (*setup_cpu_target)(struct mvebu_mbus_state *s);
-};
-
-struct mvebu_mbus_state mbus_state
-   __section(".data");
  static struct mbus_dram_target_info mbus_dram_info
__section(".data");
  
+#if defined(CONFIG_ARCH_MVEBU)

+   #define MVEBU_MBUS_NUM_WINS 20
+   #define MVEBU_MBUS_NUM_REMAPPABLE_WINS 8
+   #define MVEBU_MBUS_WIN_CFG_OFFSET(win) 
armada_370_xp_mbus_win_offset(win)
+#elif defined(CONFIG_ARCH_KIRKWOOD)
+   #define MVEBU_MBUS_NUM_WINS 8
+   #define MVEBU_MBUS_NUM_REMAPPABLE_WINS 4
+   #define MVEBU_MBUS_WIN_CFG_OFFSET(win) orion5x_mbus_win_offset(win)
+#else
+   #error "No supported architecture"
+#endif
+
+static unsigned int armada_370_xp_mbus_win_offset(int win);
+static unsigned int orion5x_mbus_win_offset(int win);
+
  /*
   * Functions to manipulate the address decoding windows
   */
  
-static void mvebu_mbus_read_window(struct mvebu_mbus_state *mbus,

-  int win, int *enabled, u64 *base,
+static void mvebu_mbus_read_window(int win, int *enabled, u64 *base,
   u32 *size, u8 *target, u8 *attr,
   u64 *remap)
  {
-   void __iomem *addr = mbus->mbuswins_base +
-   mbus->soc->win_cfg_offset(win);
+   void __iomem *addr = (void __iomem *)MVEBU_CPU_WIN_BASE +
+   MVEBU_MBUS_WIN_CFG_OFFSET(win);
u32 basereg = readl(addr + WIN_BASE_OFF);
u32 ctrlreg = readl(addr + WIN_CTRL_OFF);
  
@@ -133,7 +136,7 @@ static void mvebu_mbus_read_window(struct mvebu_mbus_state *mbus,

*attr = (ctrlreg & WIN_CTRL_ATTR_MASK) >> WIN_CTRL_ATTR_SHIFT;
  
  	if (remap) {

-   if (win < mbus->soc->num_remappable_wins) {
+   if (win < MVEBU_MBUS_NUM_REMAPPABLE_WINS) {
u32 remap_low = readl(addr + WIN_REMAP_LO_OFF);
u32 remap_hi  = readl(addr + WIN_REMAP_HI_OFF);
*remap = ((u64)remap_hi << 32) | remap_low;
@@ -143,27 +146,25 @@ static void mvebu_mbus_read_window(struct 
mvebu_mbus_state *mbus,
}
  }
  
-static void mvebu_mbus_disable_window(struct mvebu_mbus_state *mbus,

- int win)
+static void mvebu_mbus_disable_window(i

Re: [PATCH] arm: mvebu: turris_mox: Set "sfp" label in eth1 DT node when only Mox SFP is detected

2022-08-23 Thread Stefan Roese

On 10.08.22 12:54, Pali Rohár wrote:

When Mox SFP module is connected after Topaz or Peridot module then port DT
node already contains "sfp" label. But Mox SFP module can be connected also
without Topaz or Peridot module in which case it is connected directly into
he eth1 DT node, which is without any label. So add "sfp" label into eth1
DT node in this case.

Signed-off-by: Pali Rohár 


Applied to u-boot-marvell/master

Thanks,
Stefan


---
  board/CZ.NIC/turris_mox/turris_mox.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index 28259e71405f..3dbd68e52366 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -821,6 +821,11 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 "sgmii");
if (res < 0)
return res;
+
+   res = fdt_setprop_string(blob, node, "label",
+"sfp");
+   if (res < 0)
+   return res;
}
  
  		res = fdt_status_okay_by_compatible(blob, "cznic,moxtet-gpio");


Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH] arm: mvebu: turris_omnia: Show MCU version

2022-08-23 Thread Stefan Roese

On 10.08.22 11:00, Pali Rohár wrote:

There are already more MCU firmware versions for Turris Omnia in
production, so display git commit (version) of the MCU firmware during
U-Boot startup. It will help to identify what version of MCU firmware is
Turris Omnia using.

MCU firmware for Turris Omnia is open source and available at website:
https://gitlab.nic.cz/turris/hw/omnia_hw_ctrl

It can be updated from running system via i2c bus with this tool:
https://gitlab.nic.cz/turris/omnia-mcutool

Signed-off-by: Pali Rohár 


Applied to u-boot-marvell/master

Thanks,
Stefan


---
  board/CZ.NIC/turris_omnia/turris_omnia.c | 36 
  1 file changed, 36 insertions(+)

diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c 
b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 5ddd873d0250..caae8ce44695 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -21,6 +21,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -61,7 +62,9 @@ DECLARE_GLOBAL_DATA_PTR;
  enum mcu_commands {
CMD_GET_STATUS_WORD = 0x01,
CMD_GET_RESET   = 0x09,
+   CMD_GET_FW_VERSION_APP  = 0x0a,
CMD_WATCHDOG_STATE  = 0x0b,
+   CMD_GET_FW_VERSION_BOOT = 0x0e,
  
  	/* available if STS_FEATURES_SUPPORTED bit set in status word */

CMD_GET_FEATURES= 0x10,
@@ -428,6 +431,38 @@ static const char * const omnia_get_mcu_type(void)
return mcu_types[stsword & STS_MCU_TYPE_MASK];
  }
  
+static const char * const omnia_get_mcu_version(void)

+{
+   static char version[82];
+   u8 version_app[20];
+   u8 version_boot[20];
+   int ret;
+
+   ret = omnia_mcu_read(CMD_GET_FW_VERSION_APP, &version_app, 
sizeof(version_app));
+   if (ret)
+   return "unknown";
+
+   ret = omnia_mcu_read(CMD_GET_FW_VERSION_BOOT, &version_boot, 
sizeof(version_boot));
+   if (ret)
+   return "unknown";
+
+   /*
+* If git commits of MCU bootloader and MCU application are same then
+* show version only once. If they are different then show both commits.
+*/
+   if (!memcmp(version_app, version_boot, 20)) {
+   bin2hex(version, version_app, 20);
+   version[40] = '\0';
+   } else {
+   bin2hex(version, version_boot, 20);
+   version[40] = '/';
+   bin2hex(version + 41, version_app, 20);
+   version[81] = '\0';
+   }
+
+   return version;
+}
+
  /*
   * Define the DDR layout / topology here in the board file. This will
   * be used by the DDR3 init code in the SPL U-Boot version to configure
@@ -944,6 +979,7 @@ int show_board_info(void)
err = turris_atsha_otp_get_serial_number(&version_num, &serial_num);
printf("Model: Turris Omnia\n");
printf("  MCU type: %s\n", omnia_get_mcu_type());
+   printf("  MCU version: %s\n", omnia_get_mcu_version());
printf("  RAM size: %i MiB\n", omnia_get_ram_size_gb() * 1024);
if (err)
printf("  Serial Number: unknown\n");


Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH] arm: kirkwood: pogo_v4: Add Distro boot capability

2022-08-23 Thread Stefan Roese

On 09.08.22 05:01, Tony Dinh wrote:

- Add distro boot to board include file and deconfig file
- Miscellaneous changes:
- Add CONFIG_SUPPORT_PASSING_ATAGS and friends to support legacy
kernel method of booting (e.g. OpenWrt) with appended DTB.
- Add CONFIG_LTO and CONFIG_UBIFS_SILENCE_MSG, and disable some
unused configs  to reduce binary size.

Note that this patch is depended on the following patch:
https://patchwork.ozlabs.org/project/uboot/patch/20220807192709.21717-1-p...@kernel.org/

Signed-off-by: Tony Dinh 


Applied to u-boot-marvell/master

Thanks,
Stefan


---

  configs/pogo_v4_defconfig | 25 --
  include/configs/pogo_v4.h | 54 +--
  2 files changed, 57 insertions(+), 22 deletions(-)

diff --git a/configs/pogo_v4_defconfig b/configs/pogo_v4_defconfig
index c62c88f1b5..748842100e 100644
--- a/configs/pogo_v4_defconfig
+++ b/configs/pogo_v4_defconfig
@@ -4,6 +4,9 @@ CONFIG_SYS_DCACHE_OFF=y
  CONFIG_ARCH_CPU_INIT=y
  CONFIG_SYS_THUMB_BUILD=y
  CONFIG_ARCH_KIRKWOOD=y
+CONFIG_SUPPORT_PASSING_ATAGS=y
+CONFIG_CMDLINE_TAG=y
+CONFIG_INITRD_TAG=y
  CONFIG_SYS_KWD_CONFIG="board/cloudengines/pogo_v4/kwbimage.cfg"
  CONFIG_SYS_TEXT_BASE=0x60
  CONFIG_SYS_MALLOC_F_LEN=0x400
@@ -13,23 +16,24 @@ CONFIG_ENV_OFFSET=0xC
  CONFIG_DEFAULT_DEVICE_TREE="kirkwood-pogoplug-series-4"
  CONFIG_IDENT_STRING="\nPogoplug V4"
  CONFIG_SYS_LOAD_ADDR=0x80
+CONFIG_LTO=y
+CONFIG_DISTRO_DEFAULTS=y
  CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
  CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xc8012000
  CONFIG_BOOTSTAGE=y
  CONFIG_SHOW_BOOT_PROGRESS=y
  CONFIG_BOOTDELAY=10
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="setenv bootargs ${bootargs_console}; run bootcmd_usb; bootm 
0x0080 0x0110 0x2c0"
  CONFIG_USE_PREBOOT=y
  CONFIG_BOARD_LATE_INIT=y
-CONFIG_HUSH_PARSER=y
  CONFIG_SYS_PROMPT="Pogo_V4> "
  CONFIG_SYS_MAXARGS=32
  CONFIG_SYS_PBSIZE=1050
-CONFIG_CMD_BOOTZ=y
  # CONFIG_BOOTM_PLAN9 is not set
  # CONFIG_BOOTM_RTEMS is not set
  # CONFIG_BOOTM_VXWORKS is not set
+# CONFIG_CMD_ELF is not set
+# CONFIG_CMD_IMI is not set
+# CONFIG_CMD_XIMG is not set
  # CONFIG_CMD_FLASH is not set
  CONFIG_CMD_MMC=y
  CONFIG_CMD_MTD=y
@@ -37,22 +41,14 @@ CONFIG_CMD_NAND=y
  CONFIG_CMD_PCI=y
  CONFIG_CMD_SATA=y
  CONFIG_CMD_USB=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MII=y
-CONFIG_CMD_PING=y
  CONFIG_CMD_SNTP=y
  CONFIG_CMD_DNS=y
-CONFIG_CMD_EXT2=y
-CONFIG_CMD_EXT4=y
-CONFIG_CMD_FAT=y
-CONFIG_CMD_FS_GENERIC=y
+# CONFIG_CMD_BLOCK_CACHE is not set
  CONFIG_CMD_JFFS2=y
  CONFIG_CMD_MTDPARTS=y
  CONFIG_MTDIDS_DEFAULT="nand0=orion_nand"
  
CONFIG_MTDPARTS_DEFAULT="mtdparts=orion_nand:2M(u-boot),3M(uImage),3M(uImage2),8M(failsafe),112M(root)"
  CONFIG_CMD_UBI=y
-CONFIG_ISO_PARTITION=y
-CONFIG_EFI_PARTITION=y
  CONFIG_PARTITION_TYPE_GUID=y
  CONFIG_OF_CONTROL=y
  CONFIG_ENV_OVERWRITE=y
@@ -62,6 +58,7 @@ CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_NETCONSOLE=y
  CONFIG_SYS_FAULT_ECHO_LINK_DOWN=y
  CONFIG_DM=y
+# CONFIG_DM_WARN is not set
  CONFIG_SATA_MV=y
  CONFIG_SYS_SATA_MAX_DEVICE=1
  CONFIG_LBA48=y
@@ -84,6 +81,6 @@ CONFIG_USB=y
  CONFIG_USB_XHCI_HCD=y
  CONFIG_USB_XHCI_PCI=y
  CONFIG_USB_EHCI_HCD=y
-CONFIG_USB_STORAGE=y
  CONFIG_JFFS2_LZO=y
  CONFIG_JFFS2_NAND=y
+CONFIG_UBIFS_SILENCE_MSG=y
diff --git a/include/configs/pogo_v4.h b/include/configs/pogo_v4.h
index 7fff78b7b5..b5ce2dd13d 100644
--- a/include/configs/pogo_v4.h
+++ b/include/configs/pogo_v4.h
@@ -21,15 +21,53 @@
   */
  #include "mv-common.h"
  
-/*

- * Default environment variables
- */
+/* Include the common distro boot environment */
+#ifndef CONFIG_SPL_BUILD
+
+#ifdef CONFIG_MMC
+#define BOOT_TARGET_DEVICES_MMC(func) func(MMC, mmc, 0)
+#else
+#define BOOT_TARGET_DEVICES_MMC(func)
+#endif
+
+#ifdef CONFIG_SATA
+#define BOOT_TARGET_DEVICES_SATA(func) func(SATA, sata, 0)
+#else
+#define BOOT_TARGET_DEVICES_SATA(func)
+#endif
+
+#ifdef CONFIG_USB_STORAGE
+#define BOOT_TARGET_DEVICES_USB(func) func(USB, usb, 0)
+#else
+#define BOOT_TARGET_DEVICES_USB(func)
+#endif
+
+#define BOOT_TARGET_DEVICES(func) \
+   BOOT_TARGET_DEVICES_MMC(func) \
+   BOOT_TARGET_DEVICES_USB(func) \
+   BOOT_TARGET_DEVICES_SATA(func) \
+   func(DHCP, dhcp, na)
+
+#define KERNEL_ADDR_R  __stringify(0x80)
+#define FDT_ADDR_R __stringify(0x2c0)
+#define RAMDISK_ADDR_R __stringify(0x0110)
+#define SCRIPT_ADDR_R  __stringify(0x20)
+
+#define LOAD_ADDRESS_ENV_SETTINGS \
+   "kernel_addr_r=" KERNEL_ADDR_R "\0" \
+   "fdt_addr_r=" FDT_ADDR_R "\0" \
+   "ramdisk_addr_r=" RAMDISK_ADDR_R "\0" \
+   "scriptaddr=" SCRIPT_ADDR_R "\0"
+
+#include 
+
  #define CONFIG_EXTRA_ENV_SETTINGS \
-   "dtb_file=/boot/dts/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
-   "bootargs_console=console=ttyS0,115200\0" \
-   "bootcmd_usb=usb start; load usb 0:1 0x0080 /boot/uImage; " \
-   "load usb 0:1 0x0110 /boot/uInitrd; " \
-   "load usb 0:1 0x2c0 $dtb_file\0"
+   LOAD_ADDRESS_ENV_SET

Re: [PATCH] arm: mvebu: Define env_sf_get_env_addr() for all Armada boards in SPL

2022-08-23 Thread Stefan Roese

On 08.08.22 19:13, Pali Rohár wrote:

SPI0 CS0 Flash is mapped to address range 0xD400 - 0xD7FF by BootROM.
Proper U-Boot removes this direct mapping. So it is available only in SPL.
This applies for all 32-bit Armada BootROMs. SPL mvebu code is used only on
32-bit Armada SoCs. So move env_sf_get_env_addr() function from Turris
Omnia board to common SPL mvebu code and add proper checks for SPI0 CS0.

Signed-off-by: Pali Rohár 


Applied to u-boot-marvell/master

Thanks,
Stefan


---
  arch/arm/mach-mvebu/spl.c| 13 +
  board/CZ.NIC/turris_omnia/turris_omnia.c | 10 --
  2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 13c99913c380..866e0ac62345 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -292,6 +292,19 @@ int board_return_to_bootrom(struct spl_image_info 
*spl_image,
hang();
  }
  
+/*

+ * SPI0 CS0 Flash is mapped to address range 0xD400 - 0xD7FF by 
BootROM.
+ * Proper U-Boot removes this direct mapping. So it is available only in SPL.
+ */
+#if defined(CONFIG_SPL_ENV_IS_IN_SPI_FLASH) && \
+CONFIG_ENV_SPI_BUS == 0 && CONFIG_ENV_SPI_CS == 0 && \
+CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE <= 64*1024*1024
+void *env_sf_get_env_addr(void)
+{
+   return (void *)0xD400 + CONFIG_ENV_OFFSET;
+}
+#endif
+
  void board_init_f(ulong dummy)
  {
int ret;
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c 
b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 5921769f1e1d..3180305f8031 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -255,16 +255,6 @@ static bool omnia_detect_wwan_usb3(const char *wwan_slot)
return false;
  }
  
-void *env_sf_get_env_addr(void)

-{
-   /* SPI Flash is mapped to address 0xD400 only in SPL */
-#ifdef CONFIG_SPL_BUILD
-   return (void *)0xD400 + CONFIG_ENV_OFFSET;
-#else
-   return NULL;
-#endif
-}
-
  int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
  {
  #ifdef CONFIG_SPL_ENV_SUPPORT


Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH v2 2/2] cmd: mvebu/bubt: Check for A38x/A37xx OTP secure bits and secure boot

2022-08-23 Thread Stefan Roese

On 23.08.22 14:44, Pali Rohár wrote:

On Tuesday 23 August 2022 07:05:33 Stefan Roese wrote:

Hi Pali,

On 09.08.22 21:42, Pali Rohár wrote:

For obvious reasons BootROMS rejects unsigned images when secure boot is
enabled in OTP secure bits. So check for OPT secure bits and do not allow
flashing unsigned images when secure boot is enabled. Access to OTP via
U-Boot fuse API is currently implemented only for A38x and A37xx SoCs.

Additionally Armada 3700 BootROM rejects signed trusted image when secure
boot is not enabled in OTP. So add also check for this case. On the other
hand Armada 38x BootROM acceps images with secure boot header when secure
boot is not enabled in OTP.

OTP secure bits may have burned also boot device source. Check it also and
reject flashing images to target storage which does not match OTP.

Signed-off-by: Pali Rohár 

---
Changes in v2:
* Add missing dependency on MVEBU_EFUSE
* Use only for A38x and A37xx


Running a world CI build leads to these errors:

$ make clearfog_gt_8k_defconfig
...
$ make -sj
cmd/mvebu/bubt.c:809:12: warning: 'fuse_read_u64' defined but not used
[-Wunused-function]
   809 | static u64 fuse_read_u64(u32 bank)
   |^

Could you please please take a look and fix this issue?


There is missing guard to not compile that function for A7k/A8k. I will
fix it in v3.


Thanks for fixing this. I'll probably skip v3 in the next pull request,
as I've everything ready with the other patches now.

Thanks,
Stefan


Thanks,
Stefan


---
   cmd/mvebu/Kconfig |   1 +
   cmd/mvebu/bubt.c  | 127 +++---
   2 files changed, 120 insertions(+), 8 deletions(-)

diff --git a/cmd/mvebu/Kconfig b/cmd/mvebu/Kconfig
index 120397d6d4d0..9ec3aa983a51 100644
--- a/cmd/mvebu/Kconfig
+++ b/cmd/mvebu/Kconfig
@@ -5,6 +5,7 @@ config CMD_MVEBU_BUBT
bool "bubt"
select SHA256 if ARMADA_3700
select SHA512 if ARMADA_3700
+   select MVEBU_EFUSE if ARMADA_38X || ARMADA_3700
help
  bubt - Burn a u-boot image to flash
  For details about bubt command please see the documentation
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 3b6ffb7ffd1f..feb1e778a98c 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -13,6 +13,8 @@
   #include 
   #include 
   #include 
+#include 
+#include 
   #include 
   #include 
@@ -121,6 +123,17 @@ struct a38x_main_hdr_v1 {
u8  checksum;  /* 0x1F  */
   };
+/*
+ * Header for the optional headers, version 1 (Armada 370/XP/375/38x/39x)
+ */
+struct a38x_opt_hdr_v1 {
+   u8  headertype;
+   u8  headersz_msb;
+   u16 headersz_lsb;
+   u8  data[0];
+};
+#define A38X_OPT_HDR_V1_SECURE_TYPE0x1
+
   struct a38x_boot_mode {
unsigned int id;
const char *name;
@@ -706,6 +719,7 @@ static int check_image_header(void)
   {
u8 checksum;
u32 checksum32, exp_checksum32;
+   u32 offset, size;
const struct a38x_main_hdr_v1 *hdr =
(struct a38x_main_hdr_v1 *)get_load_addr();
const size_t image_size = a38x_header_size(hdr);
@@ -752,6 +766,38 @@ static int check_image_header(void)
printf("Image checksum...OK!\n");
return 0;
   }
+
+#if defined(CONFIG_ARMADA_38X)
+static int a38x_image_is_secure(const struct a38x_main_hdr_v1 *hdr)
+{
+   u32 image_size = a38x_header_size(hdr);
+   struct a38x_opt_hdr_v1 *ohdr;
+   u32 ohdr_size;
+
+   if (hdr->version != 1)
+   return 0;
+
+   if (!hdr->ext)
+   return 0;
+
+   ohdr = (struct a38x_opt_hdr_v1 *)(hdr + 1);
+   do {
+   if (ohdr->headertype == A38X_OPT_HDR_V1_SECURE_TYPE)
+   return 1;
+
+   ohdr_size = (ohdr->headersz_msb << 16) | 
le16_to_cpu(ohdr->headersz_lsb);
+
+   if (!*((u8 *)ohdr + ohdr_size - 4))
+   break;
+
+   ohdr = (struct a38x_opt_hdr_v1 *)((u8 *)ohdr + ohdr_size);
+   if ((u8 *)ohdr >= (u8 *)hdr + image_size)
+   break;
+   } while (1);
+
+   return 0;
+}
+#endif
   #else /* Not ARMADA? */
   static int check_image_header(void)
   {
@@ -760,20 +806,58 @@ static int check_image_header(void)
   }
   #endif
+static u64 fuse_read_u64(u32 bank)
+{
+   u32 val[2];
+   int ret;
+
+   ret = fuse_read(bank, 0, &val[0]);
+   if (ret < 0)
+   return -1;
+
+   ret = fuse_read(bank, 1, &val[1]);
+   if (ret < 0)
+   return -1;
+
+   return ((u64)val[1] << 32) | val[0];
+}
+
+#if defined(CONFIG_ARMADA_3700)
+static inline u8 maj3(u8 val)
+{
+   /* return majority vote of 3 bits */
+   return ((val & 0x7) == 3 || (val & 0x7) > 4) ? 1 : 0;
+}
+#endif
+
   static int bubt_check_boot_mode(const struct bubt_dev *dst)
   {
   #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT)
-   int mode;
+   int mode, secure_mode;
   #if defined(

Re: [PATCH v1 08/26] imx6ul/imx6ull: synchronise device trees with linux

2022-08-23 Thread Frieder Schrempf
Am 03.08.22 um 15:21 schrieb Frieder Schrempf:
> Hi Marcel, hi Stefano,
> 
> Am 03.08.22 um 15:02 schrieb Stefano Babic:
>> On 03.08.22 14:58, Marcel Ziswiler wrote:
>>> Hi Frieder
>>>
>>> On Mon, 2022-08-01 at 10:08 +0200, Frieder Schrempf wrote:
 Hi Marcel,

 Am 21.07.22 um 15:27 schrieb Marcel Ziswiler:
> From: Marcel Ziswiler 
>
> Synchronise device trees with linux v5.19-rc5.
>
> Signed-off-by: Marcel Ziswiler 

 Thanks for the sync patches!

 Unfortunately this will break the Kontron SL/BL i.MX6UL/ULL boards
 (N6x1x). The reason is that the U-Boot devicetrees received some
 simplification and renaming that haven't been upstreamed to the kernel,
 yet. I will add updating the kernel DTs to my to-do list and would
 recommend to drop the Kontron DT changes from this patch for now.
>>>
>>> Sorry about that. I did not expect Stefano to apply all of this that
>>> quickly. On the other hand we can be very
>>> grateful that he reacted that promptly this time around (;-p).
>>>
>>
>> :-D
>>
>>> Anyway, please let me know if I can be of service to correct any of
>>> this. Like I wrote in [1] I plan to re-sync
>>> again and fix a few review comments once 6.0-rc1 is out. I guess I
>>> could also include a fix (or revert) by that
>>> time.
>>
>> I think it is a good plan.
> 
> As for the Kontron SL/BL i.MX6UL/ULL boards the U-Boot DTs are more
> up-to-date than the kernel ones, it would be good if you, Marcel, could
> just revert the changes in the next round of patches and exclude the
> boards from your sync with 6.0-rc1 as any changes to the kernel DTs I
> will eventually come up with will land in 6.1 at the earliest.

I sent out a big devicetree rework for the board to the kernel list (see
[1]) and it got applied, so I assume it will be part of Linux 6.1.

Based on this I also created patches that among other things sync the
U-Boot devicetrees for the Kontron SL/BL i.MX6UL/ULL boards with the
upcoming changes in Linux (see [2]).

[1]
https://patchwork.kernel.org/project/linux-arm-kernel/cover/20220815082814.27651-1-frie...@fris.de/
[2]
https://patchwork.ozlabs.org/project/uboot/cover/20220823142917.306176-1-frie...@fris.de/


Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-08-23 Thread Simon Glass
Hi Rasmus,

On Tue, 23 Aug 2022 at 07:06, Rasmus Villemoes
 wrote:
>
> On 23/08/2022 15.38, Simon Glass wrote:
>
> >> +/**
> >> + * board_rng_seed() - Provide a seed to be passed via /chosen/rng-seed
> >> + *
> >> + * This function is called if CONFIG_BOARD_RNG_SEED is set, and must
> >> + * be provided by the board. It should return, via @buf, some suitable
> >> + * seed value to pass to the kernel.
> >> + *
> >> + * @param buf A struct abuf for returning the seed and its size.
> >> + * @return0 if ok, negative on error.
> >> + */
> >> +int board_rng_seed(struct abuf *buf);
> >
> > Instead of yet another hook, can we use EVT_FT_FIXUP? An even better
> > option might be to use EVT_FT_FIXUP and then call a UCLASS_BOARD
> > method to obtain the information.
>
> I didn't know there was anything called EVT_FT_FIXUP, and from grepping,
> it seems suffer the same problem as ft_board_setup() as I mention,
> namely running after the command line (aka /chosen/bootargs) has been
> set up.

If that is the only problem, then you could add another event for
doing an earlier fixup.

>
> Also, I can't see how it can actually affect the blob being passed to
> the kernel, doesn't
>
> fixup.tree = oftree_default();
> ret = event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup));
>
> mean that fixup.tree points at U-Boot's control fdt rather than the blob
> that will be passed as the kernel's fdt? That seems wrong.

Yes that is wrong for many platforms. We should probably just change
it, but there is a complication.

My recent series made a start at supporting writing to a DT using the
ofnode interface. See vbe_simple_test_base() for some comments on the
current state. You could require OF_LIVE to be enabled for your new
feature.

Ideally I'd like to see ofnode used for all devicetree access, but it
will need to be done in stages. In the meantime we should try to head
in that direction.

Regards,
Simon


[PATCH 6/6] imx: imx6ul: kontron-sl-mx6ul: Sync devicetrees

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

Sync the devicetrees with Linux and adjust the board names.

Signed-off-by: Frieder Schrempf 
---
Note:

* The devicetree changes this is based on are still pending in Linux
  (see 
https://patchwork.kernel.org/project/linux-arm-kernel/cover/20220815082814.27651-1-frie...@fris.de/).
---
 arch/arm/dts/Makefile |   4 +-
 arch/arm/dts/imx6ul-kontron-bl-43.dts | 103 +
 ...i => imx6ul-kontron-bl-common-u-boot.dtsi} |   0
 ...x-s.dtsi => imx6ul-kontron-bl-common.dtsi} |   0
 ...oot.dtsi => imx6ul-kontron-bl-u-boot.dtsi} |   2 +-
 ...tron-n631x-s.dts => imx6ul-kontron-bl.dts} |   9 +-
 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts   | 423 --
 ...mon.dtsi => imx6ul-kontron-sl-common.dtsi} |  15 +
 ...-n631x-som.dtsi => imx6ul-kontron-sl.dtsi} |   6 +-
 ...ot.dtsi => imx6ull-kontron-bl-u-boot.dtsi} |   2 +-
 arch/arm/dts/imx6ull-kontron-bl.dts   |  15 +
 arch/arm/dts/imx6ull-kontron-n641x-s.dts  |  16 -
 ...n641x-som.dtsi => imx6ull-kontron-sl.dtsi} |   6 +-
 board/kontron/sl-mx6ul/MAINTAINERS|   6 +-
 board/kontron/sl-mx6ul/spl.c  |  16 +-
 configs/kontron-sl-mx6ul_defconfig|   4 +-
 16 files changed, 161 insertions(+), 466 deletions(-)
 create mode 100644 arch/arm/dts/imx6ul-kontron-bl-43.dts
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-s-u-boot.dtsi => 
imx6ul-kontron-bl-common-u-boot.dtsi} (100%)
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-s.dtsi => 
imx6ul-kontron-bl-common.dtsi} (100%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-s-u-boot.dtsi => 
imx6ul-kontron-bl-u-boot.dtsi} (75%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-s.dts => imx6ul-kontron-bl.dts} (52%)
 delete mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-som-common.dtsi => 
imx6ul-kontron-sl-common.dtsi} (90%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-som.dtsi => imx6ul-kontron-sl.dtsi} 
(62%)
 rename arch/arm/dts/{imx6ull-kontron-n641x-s-u-boot.dtsi => 
imx6ull-kontron-bl-u-boot.dtsi} (75%)
 create mode 100644 arch/arm/dts/imx6ull-kontron-bl.dts
 delete mode 100644 arch/arm/dts/imx6ull-kontron-n641x-s.dts
 rename arch/arm/dts/{imx6ull-kontron-n641x-som.dtsi => 
imx6ull-kontron-sl.dtsi} (55%)

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 48cb1f52b7a..d075fcf953c 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -879,8 +879,8 @@ dtb-$(CONFIG_MX6UL) += \
imx6ul-phytec-segin-ff-rdk-nand.dtb \
imx6ul-pico-hobbit.dtb \
imx6ul-pico-pi.dtb \
-   imx6ul-kontron-n631x-s.dtb \
-   imx6ull-kontron-n641x-s.dtb
+   imx6ul-kontron-bl.dtb \
+   imx6ull-kontron-bl.dtb
 
 dtb-$(CONFIG_MX6ULL) += \
imx6ull-14x14-evk.dtb \
diff --git a/arch/arm/dts/imx6ul-kontron-bl-43.dts 
b/arch/arm/dts/imx6ul-kontron-bl-43.dts
new file mode 100644
index 000..0c643706a15
--- /dev/null
+++ b/arch/arm/dts/imx6ul-kontron-bl-43.dts
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 exceet electronics GmbH
+ * Copyright (C) 2018 Kontron Electronics GmbH
+ * Copyright (c) 2019 Krzysztof Kozlowski 
+ */
+
+#include "imx6ul-kontron-bl.dts"
+
+/ {
+   model = "Kontron BL i.MX6UL 43 (N631X S 43)";
+   compatible = "kontron,bl-imx6ul-43", "kontron,bl-imx6ul",
+"kontron,sl-imx6ul", "fsl,imx6ul";
+
+   backlight {
+   compatible = "pwm-backlight";
+   pwms = <&pwm7 0 500>;
+   brightness-levels = <0 4 8 16 32 64 128 255>;
+   default-brightness-level = <6>;
+   status = "okay";
+   };
+};
+
+&i2c4 {
+   touchscreen@5d {
+   compatible = "goodix,gt928";
+   reg = <0x5d>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_cap_touch>;
+   interrupt-parent = <&gpio5>;
+   interrupts = <6 IRQ_TYPE_LEVEL_LOW>;
+   reset-gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>;
+   irq-gpios = <&gpio5 6 GPIO_ACTIVE_HIGH>;
+   };
+};
+
+&lcdif {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_lcdif_dat &pinctrl_lcdif_ctrl>;
+   /* Leave status disabled because of missing display panel node */
+};
+
+&pwm7 {
+   #pwm-cells = <2>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_pwm7>;
+   status = "okay";
+};
+
+&iomuxc {
+   pinctrl_cap_touch: captouchgrp {
+   fsl,pins = <
+   MX6UL_PAD_SNVS_TAMPER6__GPIO5_IO06  0x1b0b0 /* 
Touch Interrupt */
+   MX6UL_PAD_SNVS_TAMPER7__GPIO5_IO07  0x1b0b0 /* 
Touch Reset */
+   MX6UL_PAD_SNVS_TAMPER8__GPIO5_IO08  0x1b0b0 /* 
Touch Wake */
+   >;
+   };
+
+   pinctrl_lcdif_ctrl: lcdifctrlgrp {
+   fsl,pins = <
+   MX6UL_PAD_LCD_CLK__LCDIF_CLK0x79
+   MX6UL_PAD_LCD_ENABLE__LCDIF_E

[PATCH 5/6] imx: imx6ul: kontron-sl-mx6ul: Migrate to use CONFIG_EXTRA_ENV_TEXT

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

Move the environment from the board header to a separate text file
and also drop those variables that are already set in env_default.h
from the Kconfig options or are not needed anymore.

Signed-off-by: Frieder Schrempf 
---
 board/kontron/sl-mx6ul/sl-mx6ul.env |  4 
 include/configs/kontron-sl-mx6ul.h  | 10 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul.env

diff --git a/board/kontron/sl-mx6ul/sl-mx6ul.env 
b/board/kontron/sl-mx6ul/sl-mx6ul.env
new file mode 100644
index 000..9484e739dd4
--- /dev/null
+++ b/board/kontron/sl-mx6ul/sl-mx6ul.env
@@ -0,0 +1,4 @@
+kernel_addr_r=0x8200
+ramdisk_addr_r=0x8808
+pxefile_addr_r=0x8010
+scriptaddr=0x8010
diff --git a/include/configs/kontron-sl-mx6ul.h 
b/include/configs/kontron-sl-mx6ul.h
index 7aac5d3f5a1..f0586f7f721 100644
--- a/include/configs/kontron-sl-mx6ul.h
+++ b/include/configs/kontron-sl-mx6ul.h
@@ -49,14 +49,6 @@
 #define CONFIG_SYS_FSL_USDHC_NUM   2
 #endif
 
-#define CONFIG_EXTRA_ENV_SETTINGS \
-   "kernel_addr_r=0x8200\0" \
-   "ramdisk_addr_r=0x8808\0" \
-   "pxefile_addr_r=0x8010\0" \
-   "scriptaddr=0x8010\0" \
-   "bootdelay=3\0" \
-   "ethact=" CONFIG_ETHPRIME "\0" \
-   "hostname=" CONFIG_HOSTNAME "\0" \
-   BOOTENV
+#define CONFIG_EXTRA_ENV_SETTINGS BOOTENV
 
 #endif /* __KONTRON_MX6UL_CONFIG_H */
-- 
2.37.2



[PATCH 4/6] imx: imx6ul: kontron-sl-mx6ul: Select correct boot and env device

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

Instead of checking both, SPI NOR and MMC for loading U-Boot proper
and the environment, implement a way to detect the actual boot
device even if the BootROM doesn't report it and we can't rely
solely on the fuse settings, as by default we use MMC as primary
boot device and boot from SPI NOR via the secondary fallback device
(EEPROM Recovery Mode).

Signed-off-by: Frieder Schrempf 
---
 board/kontron/sl-mx6ul/Makefile  |  2 ++
 board/kontron/sl-mx6ul/sl-mx6ul-common.c | 24 
 board/kontron/sl-mx6ul/sl-mx6ul-common.h | 11 +++
 board/kontron/sl-mx6ul/sl-mx6ul.c| 15 +++
 board/kontron/sl-mx6ul/spl.c | 23 ++-
 5 files changed, 66 insertions(+), 9 deletions(-)
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.c
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.h

diff --git a/board/kontron/sl-mx6ul/Makefile b/board/kontron/sl-mx6ul/Makefile
index cae273c9309..6af5f65450a 100644
--- a/board/kontron/sl-mx6ul/Makefile
+++ b/board/kontron/sl-mx6ul/Makefile
@@ -6,3 +6,5 @@ obj-y := spl.o
 else
 obj-y := sl-mx6ul.o
 endif
+
+obj-y += sl-mx6ul-common.o
diff --git a/board/kontron/sl-mx6ul/sl-mx6ul-common.c 
b/board/kontron/sl-mx6ul/sl-mx6ul-common.c
new file mode 100644
index 000..1f24acdfa3d
--- /dev/null
+++ b/board/kontron/sl-mx6ul/sl-mx6ul-common.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Kontron Electronics GmbH
+ */
+
+#include 
+#include 
+
+#include 
+
+bool sl_mx6ul_is_spi_nor_boot(void)
+{
+   u32 bmode = imx6_src_get_boot_mode();
+
+   /*
+* Check if "EEPROM Recovery" enabled and ECSPI2_CONREG not 0x0.
+* If this is the case and U-Boot didn't initialize the SPI bus
+* yet, we can safely assume that we are booting from SPI NOR.
+*/
+   if ((bmode & 0x4000) && readl(0x0200c008))
+   return true;
+
+   return false;
+}
diff --git a/board/kontron/sl-mx6ul/sl-mx6ul-common.h 
b/board/kontron/sl-mx6ul/sl-mx6ul-common.h
new file mode 100644
index 000..58a0e77a8b0
--- /dev/null
+++ b/board/kontron/sl-mx6ul/sl-mx6ul-common.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2022 Kontron Electronics GmbH
+ */
+
+#ifndef __SL_MX6UL_COMMON_H
+#define __SL_MX6UL_COMMON_H
+
+bool sl_mx6ul_is_spi_nor_boot(void);
+
+#endif // __SL_MX6UL_COMMON_H
diff --git a/board/kontron/sl-mx6ul/sl-mx6ul.c 
b/board/kontron/sl-mx6ul/sl-mx6ul.c
index 79d4d8753b0..0f45ea84fc7 100644
--- a/board/kontron/sl-mx6ul/sl-mx6ul.c
+++ b/board/kontron/sl-mx6ul/sl-mx6ul.c
@@ -6,8 +6,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -83,3 +85,16 @@ int board_init(void)
 
return 0;
 }
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+   if (prio)
+   return ENVL_UNKNOWN;
+
+   if (sl_mx6ul_is_spi_nor_boot() && 
CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+   return ENVL_SPI_FLASH;
+   else if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
+   return ENVL_MMC;
+
+   return ENVL_NOWHERE;
+}
diff --git a/board/kontron/sl-mx6ul/spl.c b/board/kontron/sl-mx6ul/spl.c
index 12b0352146f..ba6915c898c 100644
--- a/board/kontron/sl-mx6ul/spl.c
+++ b/board/kontron/sl-mx6ul/spl.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -339,26 +340,30 @@ void board_boot_order(u32 *spl_boot_list)
 
/*
 * The default boot fuse settings use the SD card (MMC1) as primary
-* boot device, but allow SPI NOR as a fallback boot device.
-* We can't detect the fallback case and spl_boot_device() will return
-* BOOT_DEVICE_MMC1 despite the actual boot device being SPI NOR.
-* Therefore we try to load U-Boot proper vom SPI NOR after loading
-* from MMC has failed.
+* boot device, but allow SPI NOR as a fallback boot device. There
+* is no proper way to detect if the fallback was used. Therefore
+* we read the ECSPI2_CONREG register and see if it differs from the
+* reset value 0x0. If that's the case we can assume that the BootROM
+* has successfully probed the SPI NOR.
 */
-   spl_boot_list[0] = bootdev;
-
switch (bootdev) {
case BOOT_DEVICE_MMC1:
case BOOT_DEVICE_MMC2:
-   spl_boot_list[1] = BOOT_DEVICE_SPI;
+   if (sl_mx6ul_is_spi_nor_boot()) {
+   spl_boot_list[0] = BOOT_DEVICE_SPI;
+   return;
+   }
break;
}
+
+   spl_boot_list[0] = bootdev;
 }
 
 int board_early_init_f(void)
 {
setup_iomux_uart();
-   setup_spi();
+   if (sl_mx6ul_is_spi_nor_boot())
+   setup_spi();
 
return 0;
 }
-- 
2.37.2



[PATCH 3/6] imx: imx6ul: kontron-sl-mx6ul: Fix CONFIG_ENV_SPI_BUS

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

The SPI NOR is on ECSPI1 so CONFIG_ENV_SPI_BUS should be 1
to detect the environment on the SPI NOR.

Signed-off-by: Frieder Schrempf 
---
 configs/kontron-sl-mx6ul_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/kontron-sl-mx6ul_defconfig 
b/configs/kontron-sl-mx6ul_defconfig
index 664c55e9eb0..4eb10bec0ee 100644
--- a/configs/kontron-sl-mx6ul_defconfig
+++ b/configs/kontron-sl-mx6ul_defconfig
@@ -64,7 +64,6 @@ CONFIG_OF_LIST="imx6ul-kontron-n631x-s 
imx6ull-kontron-n641x-s"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_SPI_BUS=2
 CONFIG_USE_ETHPRIME=y
 CONFIG_ETHPRIME="eth0"
 CONFIG_BOOTCOUNT_LIMIT=y
-- 
2.37.2



[PATCH 1/6] Makefile: Make flash.bin target available for all platforms

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

There is no reason for restricting the use of the flash.bin target
to the i.MX8 platform. Others can benefit from this as well.

Signed-off-by: Frieder Schrempf 
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index ff25f929748..cb8ccdea783 100644
--- a/Makefile
+++ b/Makefile
@@ -1546,7 +1546,7 @@ tpl/u-boot-with-tpl.bin: tpl/u-boot-tpl.bin u-boot.bin 
FORCE
 SPL: spl/u-boot-spl.bin FORCE
$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 
-ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y)
+#ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y)
 ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y)
 u-boot.cnt: u-boot.bin FORCE
$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
@@ -1562,7 +1562,7 @@ flash.bin: spl/u-boot-spl.bin u-boot.itb FORCE
$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 endif
 endif
-endif
+#endif
 
 u-boot.uim: u-boot.bin FORCE
$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
-- 
2.37.2



[PATCH 2/6] imx: imx6ul: kontron-sl-mx6ul: Enable migrated Kconfig options

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

The board support was merged at the same time as some Kconfig options
for SPL were migrated/renamed. As a result some essential features
like serial output, MMC support, etc. are currently missing. Fix this
by enabling the required options.

Signed-off-by: Frieder Schrempf 
---
 configs/kontron-sl-mx6ul_defconfig | 8 
 1 file changed, 8 insertions(+)

diff --git a/configs/kontron-sl-mx6ul_defconfig 
b/configs/kontron-sl-mx6ul_defconfig
index f9cebf9e9c9..664c55e9eb0 100644
--- a/configs/kontron-sl-mx6ul_defconfig
+++ b/configs/kontron-sl-mx6ul_defconfig
@@ -14,8 +14,12 @@ CONFIG_TARGET_KONTRON_MX6UL=y
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx6ul-kontron-n631x-s"
 CONFIG_SPL_TEXT_BASE=0x00908000
+CONFIG_SPL_MMC=y
+CONFIG_SPL_SERIAL=y
 CONFIG_BOOTCOUNT_BOOTLIMIT=3
 CONFIG_SPL=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
+CONFIG_SPL_SPI=y
 CONFIG_SYS_MEMTEST_START=0x8000
 CONFIG_SYS_MEMTEST_END=0x9000
 CONFIG_DISTRO_DEFAULTS=y
@@ -26,11 +30,15 @@ CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_BOARD_TYPES=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SPL_RAW_IMAGE_SUPPORT=y
 CONFIG_SPL_LEGACY_IMAGE_FORMAT=y
 CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK=y
 CONFIG_SYS_SPL_MALLOC=y
+CONFIG_SPL_SPI_LOAD=y
+CONFIG_SYS_SPI_U_BOOT_OFFS=0x11400
 CONFIG_SPL_USB_HOST=y
 CONFIG_SPL_USB_GADGET=y
+CONFIG_SPL_USB_SDP_SUPPORT=y
 CONFIG_SPL_WATCHDOG=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_SYS_PBSIZE=532
-- 
2.37.2



[PATCH 0/6] imx: imx6ul: kontron-sl-mx6ul: Fixes and improvements

2022-08-23 Thread Frieder Schrempf
From: Frieder Schrempf 

This series fixes some issues with the kontron-sl-mx6ul board
configuration. It also syncs devicetrees with changes in the
Linux kernel.

Notes:

* This series is based on imx/master and fixes the previously merged
  sync patch from Marcel [1].
* The devicetree changes this is based on are still pending in Linux
  (see [2]).

[1] 
https://patchwork.ozlabs.org/project/uboot/patch/20220721132748.1052244-9-mar...@ziswiler.com/
[2] 
https://patchwork.kernel.org/project/linux-arm-kernel/cover/20220815082814.27651-1-frie...@fris.de/

Frieder Schrempf (6):
  Makefile: Make flash.bin target available for all platforms
  imx: imx6ul: kontron-sl-mx6ul: Enable migrated Kconfig options
  imx: imx6ul: kontron-sl-mx6ul: Fix CONFIG_ENV_SPI_BUS
  imx: imx6ul: kontron-sl-mx6ul: Select correct boot and env device
  imx: imx6ul: kontron-sl-mx6ul: Migrate to use CONFIG_EXTRA_ENV_TEXT
  imx: imx6ul: kontron-sl-mx6ul: Sync devicetrees

 Makefile  |   4 +-
 arch/arm/dts/Makefile |   4 +-
 arch/arm/dts/imx6ul-kontron-bl-43.dts | 103 +
 ...i => imx6ul-kontron-bl-common-u-boot.dtsi} |   0
 ...x-s.dtsi => imx6ul-kontron-bl-common.dtsi} |   0
 ...oot.dtsi => imx6ul-kontron-bl-u-boot.dtsi} |   2 +-
 ...tron-n631x-s.dts => imx6ul-kontron-bl.dts} |   9 +-
 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts   | 423 --
 ...mon.dtsi => imx6ul-kontron-sl-common.dtsi} |  15 +
 ...-n631x-som.dtsi => imx6ul-kontron-sl.dtsi} |   6 +-
 ...ot.dtsi => imx6ull-kontron-bl-u-boot.dtsi} |   2 +-
 arch/arm/dts/imx6ull-kontron-bl.dts   |  15 +
 arch/arm/dts/imx6ull-kontron-n641x-s.dts  |  16 -
 ...n641x-som.dtsi => imx6ull-kontron-sl.dtsi} |   6 +-
 board/kontron/sl-mx6ul/MAINTAINERS|   6 +-
 board/kontron/sl-mx6ul/Makefile   |   2 +
 board/kontron/sl-mx6ul/sl-mx6ul-common.c  |  24 +
 board/kontron/sl-mx6ul/sl-mx6ul-common.h  |  11 +
 board/kontron/sl-mx6ul/sl-mx6ul.c |  15 +
 board/kontron/sl-mx6ul/sl-mx6ul.env   |   4 +
 board/kontron/sl-mx6ul/spl.c  |  39 +-
 configs/kontron-sl-mx6ul_defconfig|  13 +-
 include/configs/kontron-sl-mx6ul.h|  10 +-
 23 files changed, 242 insertions(+), 487 deletions(-)
 create mode 100644 arch/arm/dts/imx6ul-kontron-bl-43.dts
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-s-u-boot.dtsi => 
imx6ul-kontron-bl-common-u-boot.dtsi} (100%)
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-s.dtsi => 
imx6ul-kontron-bl-common.dtsi} (100%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-s-u-boot.dtsi => 
imx6ul-kontron-bl-u-boot.dtsi} (75%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-s.dts => imx6ul-kontron-bl.dts} (52%)
 delete mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts
 rename arch/arm/dts/{imx6ul-kontron-n6x1x-som-common.dtsi => 
imx6ul-kontron-sl-common.dtsi} (90%)
 rename arch/arm/dts/{imx6ul-kontron-n631x-som.dtsi => imx6ul-kontron-sl.dtsi} 
(62%)
 rename arch/arm/dts/{imx6ull-kontron-n641x-s-u-boot.dtsi => 
imx6ull-kontron-bl-u-boot.dtsi} (75%)
 create mode 100644 arch/arm/dts/imx6ull-kontron-bl.dts
 delete mode 100644 arch/arm/dts/imx6ull-kontron-n641x-s.dts
 rename arch/arm/dts/{imx6ull-kontron-n641x-som.dtsi => 
imx6ull-kontron-sl.dtsi} (55%)
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.c
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.h
 create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul.env

-- 
2.37.2



Re: [PATCH] image: Ensure image header name is null terminated

2022-08-23 Thread Rasmus Villemoes
On 23/08/2022 15.38, Simon Glass wrote:
> Hi John,
> 
> On Tue, 23 Aug 2022 at 03:46, John Keeping  wrote:
>>
>> On Tue, Aug 23, 2022 at 03:59:07PM +1000, Joel Stanley wrote:
>>> When building with GCC 12:
>>>
>>> ../include/image.h:779:9: warning: ‘strncpy’ specified bound 32 equals 
>>> destination size [-Wstringop-truncation]
>>>   779 | strncpy(image_get_name(hdr), name, IH_NMLEN);
>>>   | ^~~~
>>>
>>> Ensure the copied string is null terminated by always setting the final
>>> byte to 0. Shorten the strncpy to IH_NMLEN-1 as we will always overwrite
>>> the last byte.
>>>
>>> We can't use strlcpy as this is code is built on the host as well as the
>>> target.
>>
>> Since this is in the header, isn't the point that it doesn't need to be
>> null-terminated?
>>
>> When printing we're careful to use:
>>
>> "%.*s", IH_NMLEN, ...
>>
>> so I think the warning is wrong here - we want both of the strncpy()
>> behaviours that are normally considered strange:
>>
>> - it's okay not to null terminate as this is an explicitly sized field
>>
>> - we want to pad the whole field with zeroes if the string is short
> 
> That's my understanding too. We are careful to avoid expecting a
> terminator. I am not sure what to do with the warning though

Maybe this could be some inspiration:

info gcc

'nonstring'
 The 'nonstring' variable attribute specifies that an object or
 member declaration with type array of 'char', 'signed char', or
 'unsigned char', or pointer to such a type is intended to store
 character arrays that do not necessarily contain a terminating
 'NUL'.  This is useful in detecting uses of such arrays or pointers
 with functions that expect 'NUL'-terminated strings, and to avoid
 warnings when such an array or pointer is used as an argument to a
 bounded string manipulation function such as 'strncpy'.  For
 example, without the attribute, GCC will issue a warning for the
 'strncpy' call below because it may truncate the copy without
 appending the terminating 'NUL' character.  Using the attribute
 makes it possible to suppress the warning.  However, when the array
 is declared with the attribute the call to 'strlen' is diagnosed
 because when the array doesn't contain a 'NUL'-terminated string
 the call is undefined.  To copy, compare, of search non-string
 character arrays use the 'memcpy', 'memcmp', 'memchr', and other
 functions that operate on arrays of bytes.  In addition, calling
 'strnlen' and 'strndup' with such arrays is safe provided a
 suitable bound is specified, and not diagnosed.

  struct Data
  {
char name [32] __attribute__ ((nonstring));
  };

  int f (struct Data *pd, const char *s)
  {
strncpy (pd->name, s, sizeof pd->name);
...
return strlen (pd->name);   // unsafe, gets a warning
  }

[https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes]



Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-08-23 Thread Rasmus Villemoes
On 23/08/2022 15.38, Simon Glass wrote:

>> +/**
>> + * board_rng_seed() - Provide a seed to be passed via /chosen/rng-seed
>> + *
>> + * This function is called if CONFIG_BOARD_RNG_SEED is set, and must
>> + * be provided by the board. It should return, via @buf, some suitable
>> + * seed value to pass to the kernel.
>> + *
>> + * @param buf A struct abuf for returning the seed and its size.
>> + * @return0 if ok, negative on error.
>> + */
>> +int board_rng_seed(struct abuf *buf);
> 
> Instead of yet another hook, can we use EVT_FT_FIXUP? An even better
> option might be to use EVT_FT_FIXUP and then call a UCLASS_BOARD
> method to obtain the information.

I didn't know there was anything called EVT_FT_FIXUP, and from grepping,
it seems suffer the same problem as ft_board_setup() as I mention,
namely running after the command line (aka /chosen/bootargs) has been
set up.

Also, I can't see how it can actually affect the blob being passed to
the kernel, doesn't

fixup.tree = oftree_default();
ret = event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup));

mean that fixup.tree points at U-Boot's control fdt rather than the blob
that will be passed as the kernel's fdt? That seems wrong.

Rasmus


Re: [RFC PATCH] imx8mp: fix boot hang when booting NXP kernel 5.15.32

2022-08-23 Thread Marek Vasut

On 8/23/22 15:36, Rasmus Villemoes wrote:

We have observed a somewhat weird bug: When booting the downstream NXP
kernel lf-5.15.32-2.0.0 [fa6c3168595c], sometimes the board would hang
during imx_lcdifv3_probe(). Adding some printk debugging revealed that
the hang always happened at the

   writel(CTRL_SW_RESET, lcdifv3->base + LCDIFV3_CTRL_CLR);

However, only some of our imx8mp EVK boards and some of our custom
imx8mp-based boards showed this; others never seemed to show it,
making us initially suspect a hardware/board assembly error, though it
would be weird for that to apply to both our design and the EVKs.

Moreover, for the boards that did have this behaviour, applying a
generous amount of cooling spray to the SOC did make it boot, while
conversely heating it up before booting was a sure way to make it
hang. But even after that discovery, applying heat to the boards that
seemed to be immune from this bug didn't make them hang either.

It is also worth mentioning that whenever the boards did boot,
i.e. get past that critical line in probe(), whether those of the
"immune" kind or those which we cooled sufficiently, graphics appeared
to work just fine.

Eventually, we discovered that when using a downstream NXP U-Boot
[lf_v2022.04, 1c881f4da8], this bug never happened. So I started
bisecting between v2022.04 and lf_v2022.04, leading to

   commit 610e1b1246f7832bd96bfa9615e043565a19ac1b
   Author: Ye Li 
   Date:   Mon Mar 30 01:56:03 2020 -0700

 MLK-23574-22 imx8m: clock: Sync clock settings with imx_v2020.04

Now that commit does a lot of things, but it wasn't hard to figure out
that the part that was relevant to our case was the addition of the
enable_display_clk() function.

Since I only have imx8mp boards (some EVKs and a few custom designs),
this only adds the enable_display_clk() for that SOC. But this really
seems like something that the kernel itself should (be able to) take
care of, without relying on the bootloader having done such random
magic.

Signed-off-by: Rasmus Villemoes 
---

I don't know if upstream U-Boot cares about being able to boot a
downstream NXP linux kernel. Or if this really should be fixed on the
kernel side, making the lcdif driver properly configure the clock(s)
before lifting the reset bit. But if somebody else runs into this
issue, hopefully just this patch submission will at least save them
some time.

Can someone from NXP explain what's going on? In particular, how come
graphics works just fine even when, apparently, clocks have not been
properly configured? And why does this only happen for some boards,
but not others that should be physically identical? What's with the
temperature dependency?

  arch/arm/mach-imx/imx8m/clock_imx8mm.c | 27 +-
  1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx8m/clock_imx8mm.c 
b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
index 4db55f8608..96a9eb4dd3 100644
--- a/arch/arm/mach-imx/imx8m/clock_imx8mm.c
+++ b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
@@ -45,7 +45,6 @@ int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
return 0;
  }
  
-#ifdef CONFIG_SPL_BUILD

  static struct imx_int_pll_rate_table imx8mm_fracpll_tbl[] = {
PLL_1443X_RATE(10U, 250, 3, 1, 0),
PLL_1443X_RATE(93300U, 311, 4, 1, 0),
@@ -124,6 +123,8 @@ static int fracpll_configure(enum pll_clocks pll, u32 freq)
return 0;
  }
  
+#ifdef CONFIG_SPL_BUILD

+
  void dram_pll_init(ulong pll_val)
  {
fracpll_configure(ANATOP_DRAM_PLL, pll_val);
@@ -298,6 +299,28 @@ int intpll_configure(enum pll_clocks pll, ulong freq)
return 0;
  }
  
+#define VIDEO_PLL_RATE 59400U

+
+static void enable_display_clk(void)
+{
+   if (IS_ENABLED(CONFIG_IMX8MP)) {
+   clock_enable(CCGR_DISPMIX, false);
+
+   /* Set Video PLL to 594Mhz, p = 1, m = 99, k = 0, s = 2 */
+   fracpll_configure(ANATOP_VIDEO_PLL, VIDEO_PLL_RATE);
+
+   /* 500Mhz */
+   clock_set_target_val(MEDIA_AXI_CLK_ROOT, CLK_ROOT_ON | 
CLK_ROOT_SOURCE_SEL(1) | CLK_ROOT_PRE_DIV(CLK_ROOT_PRE_DIV2));
+
+   /* 200Mhz */
+   clock_set_target_val(MEDIA_APB_CLK_ROOT, CLK_ROOT_ON | 
CLK_ROOT_SOURCE_SEL(2) | CLK_ROOT_PRE_DIV(CLK_ROOT_PRE_DIV4));
+
+   /* 27Mhz MIPI DPHY PLL ref from video PLL */
+   clock_set_target_val(MEDIA_MIPI_PHY1_REF_CLK_ROOT, CLK_ROOT_ON 
| CLK_ROOT_SOURCE_SEL(7) | CLK_ROOT_POST_DIV(CLK_ROOT_POST_DIV22));
+   clock_enable(CCGR_DISPMIX, true);
+   }
+}
+


You might want to check Linux /sys/kernel/debug/clk/clk_summary 
before/after this change and see if there are any differences . If so, 
try using assigned-clock-rates in Linux DT and see if that can achieve 
the same "fix" effect.


Re: [PATCH] binman: Sort tests and rework test-file numbers

2022-08-23 Thread Simon Glass
On Tue, 23 Aug 2022 at 04:46, Stefan Herbrechtsmeier
 wrote:
>
> From: Stefan Herbrechtsmeier 
>
> Tests should be in order of the test-file numbers. Sort the tests
> according to the test-file numbers and rework the test-file numbers to
> eliminate duplicate numbers.
>
> Signed-off-by: Stefan Herbrechtsmeier 
>
> ---
>
>  tools/binman/ftest.py | 113 +-
>  .../binman/test/{225_dev.key => 230_dev.key}  |   0
>  .../{225_pre_load.dts => 230_pre_load.dts}|   2 +-
>  ...re_load_pkcs.dts => 231_pre_load_pkcs.dts} |   2 +-
>  ..._pre_load_pss.dts => 232_pre_load_pss.dts} |   2 +-
>  ...g.dts => 233_pre_load_invalid_padding.dts} |   2 +-
>  ...d_sha.dts => 234_pre_load_invalid_sha.dts} |   2 +-
>  ...algo.dts => 235_pre_load_invalid_algo.dts} |   2 +-
>  ...d_key.dts => 236_pre_load_invalid_key.dts} |   2 +-
>  ..._unique_names.dts => 237_unique_names.dts} |   0
>  ...s_multi.dts => 238_unique_names_multi.dts} |   0
>  ...ntool.dts => 239_replace_with_bintool.dts} |   0
>  ...eplace.dts => 240_fit_extract_replace.dts} |   0
>  ...ple.dts => 241_replace_section_simple.dts} |   0
>  ..._mkimage_name.dts => 242_mkimage_name.dts} |   0
>  ...kimage_image.dts => 243_mkimage_image.dts} |   0
>  ...t.dts => 244_mkimage_image_no_content.dts} |   0
>  ...mage_bad.dts => 245_mkimage_image_bad.dts} |   0
>  ...ion_other.dts => 246_collection_other.dts} |   0
>  ..._mkimage_coll.dts => 247_mkimage_coll.dts} |   0
>  ...s => 248_compress_dtb_prepend_invalid.dts} |   0
>  ...ts => 249_compress_dtb_prepend_length.dts} |   0
>  ...valid.dts => 250_compress_dtb_invalid.dts} |   0
>  ...dtb_zstd.dts => 251_compress_dtb_zstd.dts} |   0
>  24 files changed, 64 insertions(+), 63 deletions(-)
>  rename tools/binman/test/{225_dev.key => 230_dev.key} (100%)
>  rename tools/binman/test/{225_pre_load.dts => 230_pre_load.dts} (86%)
>  rename tools/binman/test/{226_pre_load_pkcs.dts => 231_pre_load_pkcs.dts} 
> (87%)
>  rename tools/binman/test/{227_pre_load_pss.dts => 232_pre_load_pss.dts} (87%)
>  rename tools/binman/test/{228_pre_load_invalid_padding.dts => 
> 233_pre_load_invalid_padding.dts} (86%)
>  rename tools/binman/test/{229_pre_load_invalid_sha.dts => 
> 234_pre_load_invalid_sha.dts} (86%)
>  rename tools/binman/test/{230_pre_load_invalid_algo.dts => 
> 235_pre_load_invalid_algo.dts} (86%)
>  rename tools/binman/test/{231_pre_load_invalid_key.dts => 
> 236_pre_load_invalid_key.dts} (86%)
>  rename tools/binman/test/{230_unique_names.dts => 237_unique_names.dts} 
> (100%)
>  rename tools/binman/test/{231_unique_names_multi.dts => 
> 238_unique_names_multi.dts} (100%)
>  rename tools/binman/test/{232_replace_with_bintool.dts => 
> 239_replace_with_bintool.dts} (100%)
>  rename tools/binman/test/{233_fit_extract_replace.dts => 
> 240_fit_extract_replace.dts} (100%)
>  rename tools/binman/test/{234_replace_section_simple.dts => 
> 241_replace_section_simple.dts} (100%)
>  rename tools/binman/test/{235_mkimage_name.dts => 242_mkimage_name.dts} 
> (100%)
>  rename tools/binman/test/{236_mkimage_image.dts => 243_mkimage_image.dts} 
> (100%)
>  rename tools/binman/test/{237_mkimage_image_no_content.dts => 
> 244_mkimage_image_no_content.dts} (100%)
>  rename tools/binman/test/{238_mkimage_image_bad.dts => 
> 245_mkimage_image_bad.dts} (100%)
>  rename tools/binman/test/{239_collection_other.dts => 
> 246_collection_other.dts} (100%)
>  rename tools/binman/test/{240_mkimage_coll.dts => 247_mkimage_coll.dts} 
> (100%)
>  rename tools/binman/test/{235_compress_dtb_prepend_invalid.dts => 
> 248_compress_dtb_prepend_invalid.dts} (100%)
>  rename tools/binman/test/{236_compress_dtb_prepend_length.dts => 
> 249_compress_dtb_prepend_length.dts} (100%)
>  rename tools/binman/test/{237_compress_dtb_invalid.dts => 
> 250_compress_dtb_invalid.dts} (100%)
>  rename tools/binman/test/{238_compress_dtb_zstd.dts => 
> 251_compress_dtb_zstd.dts} (100%)
>

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] boot: simplify bootmeth_vbe_simple_ft_fixup()

2022-08-23 Thread Simon Glass
On Tue, 23 Aug 2022 at 02:32, Heinrich Schuchardt
 wrote:
>
> Don't assign a value to a variable if it is not used afterwards.
> Move variables to the code fragment where they are used.
>
> Addresses-Coverity: CID 356243 ("Code maintainability issues (UNUSED_VALUE)")
> Signed-off-by: Heinrich Schuchardt 
> ---
>  boot/vbe_simple.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] boot: fix vbe_find_first_device()

2022-08-23 Thread Simon Glass
On Tue, 23 Aug 2022 at 02:25, Heinrich Schuchardt
 wrote:
>
> uclass_find_first_device() may return NULL if no device for the uclass
> exists. Handle this case gracefully.
>
> Addresses-Coverity: CID 356244 ("Null pointer dereferences (FORWARD_NULL)")
> Signed-off-by: Heinrich Schuchardt 
> ---
>  boot/vbe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-08-23 Thread Simon Glass
?Hi,

On Mon, 22 Aug 2022 at 01:34, Rasmus Villemoes
 wrote:
>
> A recurring theme on LKML is the boot process deadlocking due to some
> process blocking waiting for random numbers, while the kernel's
> Cryptographic Random Number Generator (crng) is not initalized yet,
> but that very blocking means no activity happens that would generate
> the entropy necessary to finalize seeding the crng.
>
> This is not a problem on boards that have a good hwrng (when the
> kernel is configured to trust it), whether in the CPU or in a TPM or
> elsewhere. However, that's far from all boards out there. Moreover,
> there are consumers in the kernel that try to obtain random numbers
> very early, before the kernel has had any chance to initialize any
> hwrng or other peripherals.
>
> Allow a board to provide a board_rng_seed() function, which is
> responsible for providing a value to be put into the rng-seed property
> under the /chosen node.
>
> The board code is responsible for how to actually obtain those
> bytes.
>
> - One possibility is for the board to load a seed "file" from
>   somewhere (it need not be a file in a filesystem of course), and
>   then ensure that that the same seed file does not get used on
>   subsequent boots.
>
>   * One way to do that is to delete the file, or otherwise mark it as
> invalid, then rely on userspace to create a new one, and living
> with the possibility of not finding a seed file during some boots.
>
>   * Another is to use the scheme used by systemd-boot and create a new
> seed file immediately, but in a way that the seed passed to the
> kernel and the new (i.e. next) seed cannot be deduced from each
> other, see the explanation at
> https://lore.kernel.org/lkml/20190929090512.GB13049@gardel-login/
> and the current code at
> https://github.com/systemd/systemd/blob/main/src/boot/efi/random-seed.c
>
> - The board may have an hwrng from which some bytes can be read; while
>   the kernel can also do that, doing it in U-Boot and providing a seed
>   ensures that even very early users in the kernel get good random
>   numbers.
>
> - If the board has a sensor of some sort (temperature, humidity, GPS,
>   RTC, whatever), mixing in a reading of that doesn't hurt.
>
> - etc. etc.
>
> These can of course be combined.
>
> The rng-seed property is mixed into the pool used by the linux
> kernel's CRNG very early during boot. Whether it then actually
> contributes towards the kernel considering the CRNG initialized
> depends on whether the kernel has been configured with
> CONFIG_RANDOM_TRUST_BOOTLOADER (nowadays overridable via the
> random.trust_bootloader command line option). But that's for the BSP
> developer to ultimately decide.
>
> So, if the board needs to have all that logic, why not also just have
> it do the actual population of /chosen/rng-seed in ft_board_setup(),
> which is not that many extra lines of code?
>
> I considered that, but decided handling this logically belongs in
> fdt_chosen(). Also, apart from saving the board code from the few
> lines of boilerplate, doing it in ft_board_setup() is too late for at
> least some use cases. For example, I want to allow the board logic to
> decide
>
>   ok, let's pass back this buffer and use that as seed, but also let's
>   set random.trust_bootloader=n so no entropy is credited.
>
> This requires the rng-seed handling to happen before bootargs
> handling. For example, during the very first boot, the board might not
> have a proper seed file, but the board could still return (a hash of)
> some CPU serial# or whatnot, so that at least no two boards ever get
> the same seed - the kernel always mixes in the value passed in
> rng-seed, but if it is not "trusted", the kernel would still go
> through the same motions as it would if no rng-seed was passed before
> considering its CRNG initialized. I.e., by returning that
> unique-to-this-board value and setting random.trust_bootloader=n, the
> board would be no worse off than if board_rng_seed() returned nothing
> at all.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  common/Kconfig| 14 ++
>  common/fdt_support.c  | 13 +
>  include/fdt_support.h | 13 +
>  3 files changed, 40 insertions(+)
>
> diff --git a/common/Kconfig b/common/Kconfig
> index e7914ca750..ebee856e56 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -768,6 +768,20 @@ config TPL_STACKPROTECTOR
> bool "Stack Protector buffer overflow detection for TPL"
> depends on STACKPROTECTOR && TPL
>
> +config BOARD_RNG_SEED
> +   bool "Provide /chosen/rng-seed property to the linux kernel"
> +   help
> + Selecting this option requires the board to define a
> + board_rng_seed() function, which should return a buffer
> + which will be used to populate the /chosen/rng-seed property
> + in the device tree for the OS being booted.
> +
> + It is up to the board code (and more generally the whole

Re: [PATCH] image: Ensure image header name is null terminated

2022-08-23 Thread Simon Glass
Hi John,

On Tue, 23 Aug 2022 at 03:46, John Keeping  wrote:
>
> On Tue, Aug 23, 2022 at 03:59:07PM +1000, Joel Stanley wrote:
> > When building with GCC 12:
> >
> > ../include/image.h:779:9: warning: ‘strncpy’ specified bound 32 equals 
> > destination size [-Wstringop-truncation]
> >   779 | strncpy(image_get_name(hdr), name, IH_NMLEN);
> >   | ^~~~
> >
> > Ensure the copied string is null terminated by always setting the final
> > byte to 0. Shorten the strncpy to IH_NMLEN-1 as we will always overwrite
> > the last byte.
> >
> > We can't use strlcpy as this is code is built on the host as well as the
> > target.
>
> Since this is in the header, isn't the point that it doesn't need to be
> null-terminated?
>
> When printing we're careful to use:
>
> "%.*s", IH_NMLEN, ...
>
> so I think the warning is wrong here - we want both of the strncpy()
> behaviours that are normally considered strange:
>
> - it's okay not to null terminate as this is an explicitly sized field
>
> - we want to pad the whole field with zeroes if the string is short

That's my understanding too. We are careful to avoid expecting a
terminator. I am not sure what to do with the warning though

Regards,
Simon


>
> > Fixes: b97a2a0a21f2 ("[new uImage] Define a API for image handling 
> > operations")
> > Signed-off-by: Joel Stanley 
> > ---
> >  include/image.h | 5 -
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/image.h b/include/image.h
> > index e4c6a50b885f..665b2278b7fb 100644
> > --- a/include/image.h
> > +++ b/include/image.h
> > @@ -776,7 +776,10 @@ image_set_hdr_b(comp)/* image_set_comp */
> >
> >  static inline void image_set_name(image_header_t *hdr, const char *name)
> >  {
> > - strncpy(image_get_name(hdr), name, IH_NMLEN);
> > + char *hdr_name = image_get_name(hdr);
> > +
> > + strncpy(hdr_name, name, IH_NMLEN - 1);
> > + hdr_name[IH_NMLEN - 1] = '\0';
> >  }
> >
> >  int image_check_hcrc(const image_header_t *hdr);
> > --
> > 2.35.1
> >


Re: [PATCH] common/console.c: prevent pre-console buffer contents from being added to itself

2022-08-23 Thread Simon Glass
Hi Rasmus,

On Tue, 23 Aug 2022 at 05:38, Rasmus Villemoes
 wrote:
>
> Ping.
>
> The previous patch has already been applied [cff29636933a,
> common/console.c: use CONFIG_VAL() with PRE_CON_BUF_* variables], and I
> realize this one might be more "controversial" in how it makes
> gd->precon_buf_idx serve as a "flag" when negative, but I'd really like
> to make progress towards making pre-console-buffering usable in SPL
> (since I'm debugging yet another issue where I need to know what
> happened very early).
>
> On 03/05/2022 15.13, Rasmus Villemoes wrote:
> > I do not have any non-serial output devices, so a
> > print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL)
> > does nothing for me.
> >
> > However, I was manually inspected the pre-console buffer using md.b,
> > and I noticed that the early part of it was repeated. The reason is
> > that the first call of print_pre_console_buffer(), from
> > console_init_f(), ends up invoking puts() with the contents of the
> > buffer at that point, and puts() at that point ends up in the else
> > branch of
> >
> >   if (gd->flags & GD_FLG_DEVINIT) {
> >   /* Send to the standard output */
> >   fputs(stdout, s);
> >   } else {
> >   /* Send directly to the handler */
> >   pre_console_puts(s);
> >   serial_puts(s);
> >   }
> >
> > so indeed the contents is added again.
> >
> > That can be somewhat confusing (both when reading the buffer manually,
> > but also if it did actually come out on some device). So disable all
> > use of the pre-console buffer while print_pre_console_buffer() is
> > emitting it.
> >
> > Signed-off-by: Rasmus Villemoes 
> > ---
> >  common/console.c  | 10 +-
> >  include/asm-generic/global_data.h | 12 
> >  2 files changed, 17 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass 

Looking at the logic here, I wonder if we should use membuf, but I
suspect it would increase code size, s probably note.


> >
> > diff --git a/common/console.c b/common/console.c
> > index dc071f1ed6..c5a72d9a2a 100644
> > --- a/common/console.c
> > +++ b/common/console.c
> > @@ -599,6 +599,9 @@ static void pre_console_putc(const char c)
> >  {
> >   char *buffer;
> >
> > + if (gd->precon_buf_idx < 0)
> > + return;
> > +
> >   buffer = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), 
> > CONFIG_VAL(PRE_CON_BUF_SZ));
> >
> >   buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
> > @@ -608,13 +611,16 @@ static void pre_console_putc(const char c)
> >
> >  static void pre_console_puts(const char *s)
> >  {
> > + if (gd->precon_buf_idx < 0)
> > + return;
> > +
> >   while (*s)
> >   pre_console_putc(*s++);
> >  }
> >
> >  static void print_pre_console_buffer(int flushpoint)
> >  {
> > - unsigned long in = 0, out = 0;
> > + long in = 0, out = 0;
> >   char buf_out[CONFIG_VAL(PRE_CON_BUF_SZ) + 1];
> >   char *buf_in;
> >
> > @@ -631,6 +637,7 @@ static void print_pre_console_buffer(int flushpoint)
> >
> >   buf_out[out] = 0;
> >
> > + gd->precon_buf_idx = -1;
> >   switch (flushpoint) {
> >   case PRE_CONSOLE_FLUSHPOINT1_SERIAL:
> >   puts(buf_out);
> > @@ -639,6 +646,7 @@ static void print_pre_console_buffer(int flushpoint)
> >   console_puts_select(stdout, false, buf_out);
> >   break;
> >   }
> > + gd->precon_buf_idx = in;
> >  }
> >  #else
> >  static inline void pre_console_putc(const char c) {}
> > diff --git a/include/asm-generic/global_data.h 
> > b/include/asm-generic/global_data.h
> > index 805a6fd679..2a747d91e1 100644
> > --- a/include/asm-generic/global_data.h
> > +++ b/include/asm-generic/global_data.h
> > @@ -115,10 +115,14 @@ struct global_data {
> >   /**
> >* @precon_buf_idx: pre-console buffer index
> >*
> > -  * @precon_buf_idx indicates the current position of the buffer used 
> > to
> > -  * collect output before the console becomes available
> > -  */
> > - unsigned long precon_buf_idx;
> > +  * @precon_buf_idx indicates the current position of the
> > +  * buffer used to collect output before the console becomes
> > +  * available. When negative, the pre-console buffer is
> > +  * temporarily disabled (used when the pre-console buffer is
> > +  * being written out, to prevent adding its contents to
> > +  * itself).
> > +  */
> > + long precon_buf_idx;
> >  #endif
> >   /**
> >* @env_addr: address of environment structure
>


Re: [RESEND PATCH 1/2] rpi: Copy properties from firmware dtb to the loaded dtb

2022-08-23 Thread Simon Glass
Hi Antoine,

On Mon, 22 Aug 2022 at 16:00, Antoine Mazeas  wrote:
>
> Thanks Simon,
>
> Can I ask you to clarify what you meant by "drop the private firmware"?

Replace the private binary with a full U-Boot implementation. I hope
that the vendor might do it one day.

> For the record, this patch was tested using the vendored firmware from
> Raspberry Pi, v1.20220331, and subsequently v1.20220811 when it came
> out.
>
> I'm happy to do the requested change now if you think it is preferable.

No need, it's fine. We'll keep an eye out for it if someone else uses
your function.

Regards,
Simon


>
> Regards
>
> Le 22/08/2022 à 18:39, Simon Glass a écrit :
> > Hi Antoine,
> >
> > On Fri, 19 Aug 2022 at 08:08, Antoine Mazeas  wrote:
> >>
> >> The RPI firmware adjusts several property values in the dtb it passes
> >> to u-boot depending on the board/SoC revision. Inherit some of these
> >> when u-boot loads a dtb itself. Specificaly copy:
> >>
> >> * /model: The firmware provides a more specific string
> >> * /memreserve: The firmware defines a reserved range, better keep it
> >> * emmc2bus and pcie0 dma-ranges: The C0T revision of the bcm2711 Soc (as
> >>present on rpi 400 and some rpi 4B boards) has different values for
> >>these then the B0T revision. So these need to be adjusted to boot on
> >>these boards
> >> * blconfig: The firmware defines the memory area where the blconfig
> >>stored. Copy those over so it can be enabled.
> >> * /chosen/kaslr-seed: The firmware generates a kaslr seed, take advantage
> >>of that.
> >>
> >> Signed-off-by: Sjoerd Simons 
> >> Signed-off-by: Antoine Mazeas 
> >> ---
> >>
> >>   board/raspberrypi/rpi/rpi.c | 48 +
> >>   1 file changed, 48 insertions(+)
> >
> > Reviewed-by: Simon Glass 
> >
> > I wonder if anyone has tried to drop the private firmware on the boards?
> >
> > At some point copy_property() should move to fdt_support.c if others use it


[RFC PATCH] imx8mp: fix boot hang when booting NXP kernel 5.15.32

2022-08-23 Thread Rasmus Villemoes
We have observed a somewhat weird bug: When booting the downstream NXP
kernel lf-5.15.32-2.0.0 [fa6c3168595c], sometimes the board would hang
during imx_lcdifv3_probe(). Adding some printk debugging revealed that
the hang always happened at the

  writel(CTRL_SW_RESET, lcdifv3->base + LCDIFV3_CTRL_CLR);

However, only some of our imx8mp EVK boards and some of our custom
imx8mp-based boards showed this; others never seemed to show it,
making us initially suspect a hardware/board assembly error, though it
would be weird for that to apply to both our design and the EVKs.

Moreover, for the boards that did have this behaviour, applying a
generous amount of cooling spray to the SOC did make it boot, while
conversely heating it up before booting was a sure way to make it
hang. But even after that discovery, applying heat to the boards that
seemed to be immune from this bug didn't make them hang either.

It is also worth mentioning that whenever the boards did boot,
i.e. get past that critical line in probe(), whether those of the
"immune" kind or those which we cooled sufficiently, graphics appeared
to work just fine.

Eventually, we discovered that when using a downstream NXP U-Boot
[lf_v2022.04, 1c881f4da8], this bug never happened. So I started
bisecting between v2022.04 and lf_v2022.04, leading to

  commit 610e1b1246f7832bd96bfa9615e043565a19ac1b
  Author: Ye Li 
  Date:   Mon Mar 30 01:56:03 2020 -0700

MLK-23574-22 imx8m: clock: Sync clock settings with imx_v2020.04

Now that commit does a lot of things, but it wasn't hard to figure out
that the part that was relevant to our case was the addition of the
enable_display_clk() function.

Since I only have imx8mp boards (some EVKs and a few custom designs),
this only adds the enable_display_clk() for that SOC. But this really
seems like something that the kernel itself should (be able to) take
care of, without relying on the bootloader having done such random
magic.

Signed-off-by: Rasmus Villemoes 
---

I don't know if upstream U-Boot cares about being able to boot a
downstream NXP linux kernel. Or if this really should be fixed on the
kernel side, making the lcdif driver properly configure the clock(s)
before lifting the reset bit. But if somebody else runs into this
issue, hopefully just this patch submission will at least save them
some time.

Can someone from NXP explain what's going on? In particular, how come
graphics works just fine even when, apparently, clocks have not been
properly configured? And why does this only happen for some boards,
but not others that should be physically identical? What's with the
temperature dependency?

 arch/arm/mach-imx/imx8m/clock_imx8mm.c | 27 +-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx8m/clock_imx8mm.c 
b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
index 4db55f8608..96a9eb4dd3 100644
--- a/arch/arm/mach-imx/imx8m/clock_imx8mm.c
+++ b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
@@ -45,7 +45,6 @@ int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
return 0;
 }
 
-#ifdef CONFIG_SPL_BUILD
 static struct imx_int_pll_rate_table imx8mm_fracpll_tbl[] = {
PLL_1443X_RATE(10U, 250, 3, 1, 0),
PLL_1443X_RATE(93300U, 311, 4, 1, 0),
@@ -124,6 +123,8 @@ static int fracpll_configure(enum pll_clocks pll, u32 freq)
return 0;
 }
 
+#ifdef CONFIG_SPL_BUILD
+
 void dram_pll_init(ulong pll_val)
 {
fracpll_configure(ANATOP_DRAM_PLL, pll_val);
@@ -298,6 +299,28 @@ int intpll_configure(enum pll_clocks pll, ulong freq)
return 0;
 }
 
+#define VIDEO_PLL_RATE 59400U
+
+static void enable_display_clk(void)
+{
+   if (IS_ENABLED(CONFIG_IMX8MP)) {
+   clock_enable(CCGR_DISPMIX, false);
+
+   /* Set Video PLL to 594Mhz, p = 1, m = 99, k = 0, s = 2 */
+   fracpll_configure(ANATOP_VIDEO_PLL, VIDEO_PLL_RATE);
+
+   /* 500Mhz */
+   clock_set_target_val(MEDIA_AXI_CLK_ROOT, CLK_ROOT_ON | 
CLK_ROOT_SOURCE_SEL(1) | CLK_ROOT_PRE_DIV(CLK_ROOT_PRE_DIV2));
+
+   /* 200Mhz */
+   clock_set_target_val(MEDIA_APB_CLK_ROOT, CLK_ROOT_ON | 
CLK_ROOT_SOURCE_SEL(2) | CLK_ROOT_PRE_DIV(CLK_ROOT_PRE_DIV4));
+
+   /* 27Mhz MIPI DPHY PLL ref from video PLL */
+   clock_set_target_val(MEDIA_MIPI_PHY1_REF_CLK_ROOT, CLK_ROOT_ON 
| CLK_ROOT_SOURCE_SEL(7) | CLK_ROOT_POST_DIV(CLK_ROOT_POST_DIV22));
+   clock_enable(CCGR_DISPMIX, true);
+   }
+}
+
 void init_uart_clk(u32 index)
 {
/*
@@ -485,6 +508,8 @@ int clock_init(void)
 
clock_enable(CCGR_SEC_DEBUG, 1);
 
+   enable_display_clk();
+
return 0;
 };
 
-- 
2.37.2



[PATCH] arm64: zynqmp: add ref_clk property for REFCLKPER calculation

2022-08-23 Thread Michal Simek
From: Piyush Mehta 

Added ref_clk 'ref' property for GUCTL_REFCLKPER and GFLADJ_REFCLK_FLADJ
calculation. This property configure correct value for SOF/ITP counter
and period of ref_clk.
This patch adds 'ref' property for both dwc3_0 and dwc3_1 cores.

Signed-off-by: Piyush Mehta 
Signed-off-by: Michal Simek 
---

 arch/arm/dts/zynqmp-clk-ccf.dtsi | 8 
 arch/arm/dts/zynqmp.dtsi | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/dts/zynqmp-clk-ccf.dtsi b/arch/arm/dts/zynqmp-clk-ccf.dtsi
index 7b09d7515186..b99eb07b00a0 100644
--- a/arch/arm/dts/zynqmp-clk-ccf.dtsi
+++ b/arch/arm/dts/zynqmp-clk-ccf.dtsi
@@ -260,11 +260,19 @@
assigned-clocks = <&zynqmp_clk USB0_BUS_REF>, <&zynqmp_clk 
USB3_DUAL_REF>;
 };
 
+&dwc3_0 {
+   clocks = <&zynqmp_clk USB3_DUAL_REF>;
+};
+
 &usb1 {
clocks = <&zynqmp_clk USB1_BUS_REF>, <&zynqmp_clk USB3_DUAL_REF>;
assigned-clocks = <&zynqmp_clk USB1_BUS_REF>, <&zynqmp_clk 
USB3_DUAL_REF>;
 };
 
+&dwc3_1 {
+   clocks = <&zynqmp_clk USB3_DUAL_REF>;
+};
+
 &watchdog0 {
clocks = <&zynqmp_clk WDT>;
 };
diff --git a/arch/arm/dts/zynqmp.dtsi b/arch/arm/dts/zynqmp.dtsi
index 2aaec6cf5a15..f4184f79a577 100644
--- a/arch/arm/dts/zynqmp.dtsi
+++ b/arch/arm/dts/zynqmp.dtsi
@@ -869,6 +869,7 @@
iommus = <&smmu 0x860>;
snps,quirk-frame-length-adjustment = <0x20>;
snps,refclk_fladj;
+   clock-names = "ref";
snps,enable_guctl1_resume_quirk;
snps,enable_guctl1_ipd_quirk;
snps,xhci-stream-quirk;
@@ -900,6 +901,7 @@
iommus = <&smmu 0x861>;
snps,quirk-frame-length-adjustment = <0x20>;
snps,refclk_fladj;
+   clock-names = "ref";
snps,enable_guctl1_resume_quirk;
snps,enable_guctl1_ipd_quirk;
snps,xhci-stream-quirk;
-- 
2.36.1



[PATCH] arm64: zynqmp: Add missing tca6416 to zynqmp SC

2022-08-23 Thread Michal Simek
Add missing tca6416 i2c gpio controller to SC dts file.

Signed-off-by: Michal Simek 
---

 arch/arm/dts/zynqmp-e-a2197-00-revA.dts | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts 
b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
index 37c56181c9cb..4940825b002f 100644
--- a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
+++ b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
@@ -203,6 +203,18 @@
 &i2c0 { /* MIO 34-35 - can't stay here */
status = "okay";
clock-frequency = <40>;
+
+   tca6416_u233: gpio@20 { /* u233 */
+   compatible = "ti,tca6416";
+   reg = <0x20>;
+   gpio-controller; /* interrupt not connected */
+   #gpio-cells = <2>;
+   gpio-line-names = "MAX6643_OT_B", "MAX6643_FANFAIL_B", "", "", 
/* 0 - 3 */
+   "PMBUS2_INA226_ALERT", "", "", 
"MAX6643_FULLSPD", /* 4 - 7 */
+   "FMCP1_FMC_PRSNT_M2C_B", 
"FMCP2_FMC_PRSNT_M2C_B", "FMCP1_FMCP_PRSNT_M2C_B", "FMCP2_FMCP_PRSNT_M2C_B", /* 
10 - 13 */
+   "VCCINT_VRHOT_B", "8A34001_EXP_RST_B", 
"PMBUS_ALERT", "PMBUS1_INA226_ALERT"; /* 14 - 17 */
+   };
+
i2c-mux@74 { /* u33 */
compatible = "nxp,pca9548";
#address-cells = <1>;
-- 
2.36.1



[PATCH] arm: dts: Add xlnx prefix to GEM compatible string

2022-08-23 Thread Michal Simek
From: Harini Katakam 

cdns,zynq/zynqmp were recentle deprecated in Linux in favour of xlnx
prefix. Add this new compatible string and retain the existing string for
compatibility with uboot drivers.

Signed-off-by: Harini Katakam 
Signed-off-by: Michal Simek 
---

 arch/arm/dts/zynq-7000.dtsi | 4 ++--
 arch/arm/dts/zynqmp.dtsi| 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/zynq-7000.dtsi b/arch/arm/dts/zynq-7000.dtsi
index a7ca00fb76c6..b4aa09d149b0 100644
--- a/arch/arm/dts/zynq-7000.dtsi
+++ b/arch/arm/dts/zynq-7000.dtsi
@@ -247,7 +247,7 @@
};
 
gem0: ethernet@e000b000 {
-   compatible = "cdns,zynq-gem", "cdns,gem";
+   compatible = "xlnx,zynq-gem", "cdns,zynq-gem", 
"cdns,gem";
reg = <0xe000b000 0x1000>;
status = "disabled";
interrupts = <0 22 4>;
@@ -258,7 +258,7 @@
};
 
gem1: ethernet@e000c000 {
-   compatible = "cdns,zynq-gem", "cdns,gem";
+   compatible = "xlnx,zynq-gem", "cdns,zynq-gem", 
"cdns,gem";
reg = <0xe000c000 0x1000>;
status = "disabled";
interrupts = <0 45 4>;
diff --git a/arch/arm/dts/zynqmp.dtsi b/arch/arm/dts/zynqmp.dtsi
index fbc6e752da93..2aaec6cf5a15 100644
--- a/arch/arm/dts/zynqmp.dtsi
+++ b/arch/arm/dts/zynqmp.dtsi
@@ -529,7 +529,7 @@
};
 
gem0: ethernet@ff0b {
-   compatible = "cdns,zynqmp-gem", "cdns,gem";
+   compatible = "xlnx,zynqmp-gem", "cdns,zynqmp-gem", 
"cdns,gem";
status = "disabled";
interrupt-parent = <&gic>;
interrupts = <0 57 4>, <0 57 4>;
@@ -543,7 +543,7 @@
};
 
gem1: ethernet@ff0c {
-   compatible = "cdns,zynqmp-gem", "cdns,gem";
+   compatible = "xlnx,zynqmp-gem", "cdns,zynqmp-gem", 
"cdns,gem";
status = "disabled";
interrupt-parent = <&gic>;
interrupts = <0 59 4>, <0 59 4>;
@@ -557,7 +557,7 @@
};
 
gem2: ethernet@ff0d {
-   compatible = "cdns,zynqmp-gem", "cdns,gem";
+   compatible = "xlnx,zynqmp-gem", "cdns,zynqmp-gem", 
"cdns,gem";
status = "disabled";
interrupt-parent = <&gic>;
interrupts = <0 61 4>, <0 61 4>;
@@ -571,7 +571,7 @@
};
 
gem3: ethernet@ff0e {
-   compatible = "cdns,zynqmp-gem", "cdns,gem";
+   compatible = "xlnx,zynqmp-gem", "cdns,zynqmp-gem", 
"cdns,gem";
status = "disabled";
interrupt-parent = <&gic>;
interrupts = <0 63 4>, <0 63 4>;
-- 
2.36.1



[PATCH v3 2/2] cmd: mvebu/bubt: Check for A38x/A37xx OTP secure bits and secure boot

2022-08-23 Thread Pali Rohár
For obvious reasons BootROMS rejects unsigned images when secure boot is
enabled in OTP secure bits. So check for OPT secure bits and do not allow
flashing unsigned images when secure boot is enabled. Access to OTP via
U-Boot fuse API is currently implemented only for A38x and A37xx SoCs.

Additionally Armada 3700 BootROM rejects signed trusted image when secure
boot is not enabled in OTP. So add also check for this case. On the other
hand Armada 38x BootROM acceps images with secure boot header when secure
boot is not enabled in OTP.

OTP secure bits may have burned also boot device source. Check it also and
reject flashing images to target storage which does not match OTP.

Signed-off-by: Pali Rohár 
Reviewed-by: Stefan Roese 

---
Changes in v3:
* Guard fuse_read_u64() function

Changes in v2:
* Add missing dependency on MVEBU_EFUSE
* Use only for A38x and A37xx
---
 cmd/mvebu/Kconfig |   1 +
 cmd/mvebu/bubt.c  | 128 +++---
 2 files changed, 121 insertions(+), 8 deletions(-)

diff --git a/cmd/mvebu/Kconfig b/cmd/mvebu/Kconfig
index 120397d6d4d0..9ec3aa983a51 100644
--- a/cmd/mvebu/Kconfig
+++ b/cmd/mvebu/Kconfig
@@ -5,6 +5,7 @@ config CMD_MVEBU_BUBT
bool "bubt"
select SHA256 if ARMADA_3700
select SHA512 if ARMADA_3700
+   select MVEBU_EFUSE if ARMADA_38X || ARMADA_3700
help
  bubt - Burn a u-boot image to flash
  For details about bubt command please see the documentation
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index a97e5ce38a5e..7e6e47f40d6e 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -13,6 +13,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -121,6 +123,17 @@ struct a38x_main_hdr_v1 {
u8  checksum;  /* 0x1F  */
 };
 
+/*
+ * Header for the optional headers, version 1 (Armada 370/XP/375/38x/39x)
+ */
+struct a38x_opt_hdr_v1 {
+   u8  headertype;
+   u8  headersz_msb;
+   u16 headersz_lsb;
+   u8  data[0];
+};
+#define A38X_OPT_HDR_V1_SECURE_TYPE0x1
+
 struct a38x_boot_mode {
unsigned int id;
const char *name;
@@ -753,6 +766,38 @@ static int check_image_header(void)
printf("Image checksum...OK!\n");
return 0;
 }
+
+#if defined(CONFIG_ARMADA_38X)
+static int a38x_image_is_secure(const struct a38x_main_hdr_v1 *hdr)
+{
+   u32 image_size = a38x_header_size(hdr);
+   struct a38x_opt_hdr_v1 *ohdr;
+   u32 ohdr_size;
+
+   if (hdr->version != 1)
+   return 0;
+
+   if (!hdr->ext)
+   return 0;
+
+   ohdr = (struct a38x_opt_hdr_v1 *)(hdr + 1);
+   do {
+   if (ohdr->headertype == A38X_OPT_HDR_V1_SECURE_TYPE)
+   return 1;
+
+   ohdr_size = (ohdr->headersz_msb << 16) | 
le16_to_cpu(ohdr->headersz_lsb);
+
+   if (!*((u8 *)ohdr + ohdr_size - 4))
+   break;
+
+   ohdr = (struct a38x_opt_hdr_v1 *)((u8 *)ohdr + ohdr_size);
+   if ((u8 *)ohdr >= (u8 *)hdr + image_size)
+   break;
+   } while (1);
+
+   return 0;
+}
+#endif
 #else /* Not ARMADA? */
 static int check_image_header(void)
 {
@@ -761,20 +806,60 @@ static int check_image_header(void)
 }
 #endif
 
+#if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT)
+static u64 fuse_read_u64(u32 bank)
+{
+   u32 val[2];
+   int ret;
+
+   ret = fuse_read(bank, 0, &val[0]);
+   if (ret < 0)
+   return -1;
+
+   ret = fuse_read(bank, 1, &val[1]);
+   if (ret < 0)
+   return -1;
+
+   return ((u64)val[1] << 32) | val[0];
+}
+#endif
+
+#if defined(CONFIG_ARMADA_3700)
+static inline u8 maj3(u8 val)
+{
+   /* return majority vote of 3 bits */
+   return ((val & 0x7) == 3 || (val & 0x7) > 4) ? 1 : 0;
+}
+#endif
+
 static int bubt_check_boot_mode(const struct bubt_dev *dst)
 {
 #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT)
-   int mode;
+   int mode, secure_mode;
 #if defined(CONFIG_ARMADA_3700)
const struct tim_boot_flash_sign *boot_modes = tim_boot_flash_signs;
const struct common_tim_data *hdr =
(struct common_tim_data *)get_load_addr();
u32 id = hdr->boot_flash_sign;
+   int is_secure = hdr->trusted != 0;
+   u64 otp_secure_bits = fuse_read_u64(1);
+   int otp_secure_boot = ((maj3(otp_secure_bits >> 0) << 0) |
+  (maj3(otp_secure_bits >> 4) << 1)) == 2;
+   unsigned int otp_boot_device = (maj3(otp_secure_bits >> 48) << 0) |
+  (maj3(otp_secure_bits >> 52) << 1) |
+  (maj3(otp_secure_bits >> 56) << 2) |
+  (maj3(otp_secure_bits >> 60) << 3);
 #elif defined(CONFIG_ARMADA_32BIT)
const struct a38x_boot_mode *boot_modes = a38x_boot_modes;
const struct a38x_main_hdr_v1

[PATCH v3 1/2] cmd: mvebu/bubt: Check for A38x image data checksum

2022-08-23 Thread Pali Rohár
Currently for A38x image is checked only header checksum.
So check also for image data checksum to prevent flashing broken image.

Signed-off-by: Pali Rohár 
Reviewed-by: Stefan Roese 

---
Changes in v3:
* Compile fix (move another code chunk from patch 2/2 to 1/2)

Changes in v2:
* Compile fix (move code chunk from patch 2/2 to 1/2)
---
 cmd/mvebu/bubt.c | 46 +-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 2136af64163c..a97e5ce38a5e 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -688,9 +688,25 @@ static uint8_t image_checksum8(const void *start, size_t 
len)
return csum;
 }
 
+static uint32_t image_checksum32(const void *start, size_t len)
+{
+   u32 csum = 0;
+   const u32 *p = start;
+
+   while (len) {
+   csum += *p;
+   ++p;
+   len -= sizeof(u32);
+   }
+
+   return csum;
+}
+
 static int check_image_header(void)
 {
u8 checksum;
+   u32 checksum32, exp_checksum32;
+   u32 offset, size;
const struct a38x_main_hdr_v1 *hdr =
(struct a38x_main_hdr_v1 *)get_load_addr();
const size_t image_size = a38x_header_size(hdr);
@@ -701,11 +717,39 @@ static int check_image_header(void)
checksum = image_checksum8(hdr, image_size);
checksum -= hdr->checksum;
if (checksum != hdr->checksum) {
-   printf("Error: Bad A38x image checksum. 0x%x != 0x%x\n",
+   printf("Error: Bad A38x image header checksum. 0x%x != 0x%x\n",
   checksum, hdr->checksum);
return -ENOEXEC;
}
 
+   offset = le32_to_cpu(hdr->srcaddr);
+   size = le32_to_cpu(hdr->blocksize);
+
+   if (hdr->blockid == 0x78) { /* SATA id */
+   if (offset < 1) {
+   printf("Error: Bad A38x image srcaddr.\n");
+   return -ENOEXEC;
+   }
+   offset -= 1;
+   offset *= 512;
+   }
+
+   if (hdr->blockid == 0xAE) /* SDIO id */
+   offset *= 512;
+
+   if (offset % 4 != 0 || size < 4 || size % 4 != 0) {
+   printf("Error: Bad A38x image blocksize.\n");
+   return -ENOEXEC;
+   }
+
+   checksum32 = image_checksum32((u8 *)hdr + offset, size - 4);
+   exp_checksum32 = *(u32 *)((u8 *)hdr + offset + size - 4);
+   if (checksum32 != exp_checksum32) {
+   printf("Error: Bad A38x image data checksum. 0x%08x != 
0x%08x\n",
+  checksum32, exp_checksum32);
+   return -ENOEXEC;
+   }
+
printf("Image checksum...OK!\n");
return 0;
 }
-- 
2.20.1



Re: [PATCH v2 2/2] cmd: mvebu/bubt: Check for A38x/A37xx OTP secure bits and secure boot

2022-08-23 Thread Pali Rohár
On Tuesday 23 August 2022 07:05:33 Stefan Roese wrote:
> Hi Pali,
> 
> On 09.08.22 21:42, Pali Rohár wrote:
> > For obvious reasons BootROMS rejects unsigned images when secure boot is
> > enabled in OTP secure bits. So check for OPT secure bits and do not allow
> > flashing unsigned images when secure boot is enabled. Access to OTP via
> > U-Boot fuse API is currently implemented only for A38x and A37xx SoCs.
> > 
> > Additionally Armada 3700 BootROM rejects signed trusted image when secure
> > boot is not enabled in OTP. So add also check for this case. On the other
> > hand Armada 38x BootROM acceps images with secure boot header when secure
> > boot is not enabled in OTP.
> > 
> > OTP secure bits may have burned also boot device source. Check it also and
> > reject flashing images to target storage which does not match OTP.
> > 
> > Signed-off-by: Pali Rohár 
> > 
> > ---
> > Changes in v2:
> > * Add missing dependency on MVEBU_EFUSE
> > * Use only for A38x and A37xx
> 
> Running a world CI build leads to these errors:
> 
> $ make clearfog_gt_8k_defconfig
> ...
> $ make -sj
> cmd/mvebu/bubt.c:809:12: warning: 'fuse_read_u64' defined but not used
> [-Wunused-function]
>   809 | static u64 fuse_read_u64(u32 bank)
>   |^
> 
> Could you please please take a look and fix this issue?

There is missing guard to not compile that function for A7k/A8k. I will
fix it in v3.

> Thanks,
> Stefan
> 
> > ---
> >   cmd/mvebu/Kconfig |   1 +
> >   cmd/mvebu/bubt.c  | 127 +++---
> >   2 files changed, 120 insertions(+), 8 deletions(-)
> > 
> > diff --git a/cmd/mvebu/Kconfig b/cmd/mvebu/Kconfig
> > index 120397d6d4d0..9ec3aa983a51 100644
> > --- a/cmd/mvebu/Kconfig
> > +++ b/cmd/mvebu/Kconfig
> > @@ -5,6 +5,7 @@ config CMD_MVEBU_BUBT
> > bool "bubt"
> > select SHA256 if ARMADA_3700
> > select SHA512 if ARMADA_3700
> > +   select MVEBU_EFUSE if ARMADA_38X || ARMADA_3700
> > help
> >   bubt - Burn a u-boot image to flash
> >   For details about bubt command please see the documentation
> > diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
> > index 3b6ffb7ffd1f..feb1e778a98c 100644
> > --- a/cmd/mvebu/bubt.c
> > +++ b/cmd/mvebu/bubt.c
> > @@ -13,6 +13,8 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> > +#include 
> >   #include 
> >   #include 
> > @@ -121,6 +123,17 @@ struct a38x_main_hdr_v1 {
> > u8  checksum;  /* 0x1F  */
> >   };
> > +/*
> > + * Header for the optional headers, version 1 (Armada 370/XP/375/38x/39x)
> > + */
> > +struct a38x_opt_hdr_v1 {
> > +   u8  headertype;
> > +   u8  headersz_msb;
> > +   u16 headersz_lsb;
> > +   u8  data[0];
> > +};
> > +#define A38X_OPT_HDR_V1_SECURE_TYPE0x1
> > +
> >   struct a38x_boot_mode {
> > unsigned int id;
> > const char *name;
> > @@ -706,6 +719,7 @@ static int check_image_header(void)
> >   {
> > u8 checksum;
> > u32 checksum32, exp_checksum32;
> > +   u32 offset, size;
> > const struct a38x_main_hdr_v1 *hdr =
> > (struct a38x_main_hdr_v1 *)get_load_addr();
> > const size_t image_size = a38x_header_size(hdr);
> > @@ -752,6 +766,38 @@ static int check_image_header(void)
> > printf("Image checksum...OK!\n");
> > return 0;
> >   }
> > +
> > +#if defined(CONFIG_ARMADA_38X)
> > +static int a38x_image_is_secure(const struct a38x_main_hdr_v1 *hdr)
> > +{
> > +   u32 image_size = a38x_header_size(hdr);
> > +   struct a38x_opt_hdr_v1 *ohdr;
> > +   u32 ohdr_size;
> > +
> > +   if (hdr->version != 1)
> > +   return 0;
> > +
> > +   if (!hdr->ext)
> > +   return 0;
> > +
> > +   ohdr = (struct a38x_opt_hdr_v1 *)(hdr + 1);
> > +   do {
> > +   if (ohdr->headertype == A38X_OPT_HDR_V1_SECURE_TYPE)
> > +   return 1;
> > +
> > +   ohdr_size = (ohdr->headersz_msb << 16) | 
> > le16_to_cpu(ohdr->headersz_lsb);
> > +
> > +   if (!*((u8 *)ohdr + ohdr_size - 4))
> > +   break;
> > +
> > +   ohdr = (struct a38x_opt_hdr_v1 *)((u8 *)ohdr + ohdr_size);
> > +   if ((u8 *)ohdr >= (u8 *)hdr + image_size)
> > +   break;
> > +   } while (1);
> > +
> > +   return 0;
> > +}
> > +#endif
> >   #else /* Not ARMADA? */
> >   static int check_image_header(void)
> >   {
> > @@ -760,20 +806,58 @@ static int check_image_header(void)
> >   }
> >   #endif
> > +static u64 fuse_read_u64(u32 bank)
> > +{
> > +   u32 val[2];
> > +   int ret;
> > +
> > +   ret = fuse_read(bank, 0, &val[0]);
> > +   if (ret < 0)
> > +   return -1;
> > +
> > +   ret = fuse_read(bank, 1, &val[1]);
> > +   if (ret < 0)
> > +   return -1;
> > +
> > +   return ((u64)val[1] << 32) | val[0];
> > +}
> > +
> > +#if defined(CONFIG_ARMADA_3700)
> > +static inline u8 maj3(u8 val)
> > +{
> > +   /* return majority vote of 3 bits */
> > +   return ((val & 0x7) == 3 || (val & 0x7) > 4) ? 1 : 0;
> > +}
> > +#endif
> > +
> >   static i

  1   2   >