From 4b5750aaeeb007bd822c77fee77dc3c51597e5d2 Mon Sep 17 00:00:00 2001 From: Chintan Vankar Date: Thu, 26 Sep 2024 10:31:38 +0530 Subject: [PATCH 1/8] doc: board: ti: am62x_sk: Add document for Ethernet boot on AM62x SoC. Document the procedure to enable Ethernet Boot on AM62x SoC. Signed-off-by: Chintan Vankar --- doc/board/ti/am62x_sk.rst | 196 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/doc/board/ti/am62x_sk.rst b/doc/board/ti/am62x_sk.rst index 51dab839ddd..dab2970a85c 100644 --- a/doc/board/ti/am62x_sk.rst +++ b/doc/board/ti/am62x_sk.rst @@ -305,6 +305,10 @@ https://www.ti.com/lit/pdf/spruiv7 under the `Boot Mode Pins` section. - 00000000 - 11001010 + * - Ethernet + - 00110000 + - 11000100 + For SW2 and SW1, the switch state in the "ON" position = 1. DFU based boot @@ -330,6 +334,198 @@ When using dfu-util the following commands can be used to boot to a U-Boot shell .. am62x_evm_rst_include_end_dfu_boot +Ethernet based boot +------------------- + +To boot the board via Ethernet, configure the BOOT MODE pins for Ethernet boot. + +On powering on the device, ROM uses the Ethernet Port corresponding to CPSW3G's MAC +Port 1 to transmit "TI K3 Bootp Boot". + +The TFTP server and DHCP server on the receiver device need to be configured such +that VCI string "TI K3 Bootp Boot" maps to the file `tiboot3.bin` and the TFTP +server should be capable of transferring it to the device. + +**Configuring DHCP server includes following steps:** + +* Install DHCP server: + +.. prompt:: bash $ + + sudo apt install isc-dhcp-server + +* Disable services before configuring: + +.. prompt:: bash $ + + sudo systemctl disable --now isc-dhcp-server.service isc-dhcp-server6.service + +* DHCP server setup + +Run the ip link or ifconfig command to find the name of your network interface: + +Example + +.. code-block:: + + eno1: flags=4163 mtu 1500 + inet 172.24.145.229 netmask 255.255.254.0 broadcast 172.24.145.255 + inet6 fe80::bbd5:34c8:3d4c:5de4 prefixlen 64 scopeid 0x20 + ether c0:18:03:bd:b1:a6 txqueuelen 1000 (Ethernet) + RX packets 2733979 bytes 1904440459 (1.9 GB) + RX errors 0 dropped 3850 overruns 0 frame 0 + TX packets 796807 bytes 84534764 (84.5 MB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe2200000-e2220000 + + enxf8e43b8cffe8: flags=4163 mtu 1500 + ether f8:e4:3b:8c:ff:e8 txqueuelen 1000 (Ethernet) + RX packets 95 bytes 31160 (31.1 KB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 89 bytes 17445 (17.4 KB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + + lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 85238 bytes 7244462 (7.2 MB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 85238 bytes 7244462 (7.2 MB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +Suppose we are using enxf8e43b8cffe8 interface, one end of it is connected to host PC +and other to board. + +* Do the following changes in /etc/dhcp/dhcpd.conf in host PC. + +.. code-block:: + + subnet 192.168.0.0 netmask 255.255.254.0 + { + range dynamic-bootp 192.168.0.2 192.168.0.5; + if substring (option vendor-class-identifier, 0, 16) = "TI K3 Bootp Boot" + { + filename "tiboot3.bin"; + } elsif substring (option vendor-class-identifier, 0, 20) = "AM62X U-Boot R5 SPL" + { + filename "tispl.bin"; + } elsif substring (option vendor-class-identifier, 0, 21) = "AM62X U-Boot A53 SPL" + { + filename "u-boot.img"; + } + default-lease-time 60000; + max-lease-time 720000; + next-server 192.168.0.1; + } + +* Do following changes in /etc/default/isc-dhcp-server + +.. code-block:: + + DHCPDv4_CONF=/etc/dhcp/dhcpd.conf + INTERFACESv4="enxf8e43b8cffe8" + INTERFACESv6="" + +* For your interface change ip address and netmask to next-server and your netmask + +.. prompt:: bash $ + + sudo ifconfig enxf8e43b8cffe8 192.168.0.1 netmask 255.255.254.0 + +* Enable DHCP + +.. prompt:: bash $ + + sudo systemctl enable --now isc-dhcp-server + +* To see if there is any configuration error or if dhcp is running run + +.. prompt:: bash $ + + sudo service isc-dhcp-server status + # If it shows error then something is wrong with configuration + +**For TFTP setup follow below steps:** + +* Install TFTP server: + +.. prompt:: bash $ + + sudo apt install tftpd-hpa + +tftpd-hpa package should be installed. + +Now, check whether the tftpd-hpa service is running with the following command: + +.. prompt:: bash $ + + sudo systemctl status tftpd-hpa + +* Configuring TFTP server: + +The default configuration file of tftpd-hpa server is /etc/default/tftpd-hpa. +If you want to configure the TFTP server, then you have to modify this configuration +file and restart the tftpd-hpa service afterword. + +To modify the /etc/default/tftpd-hpa configuration file, run the following command + +.. prompt:: bash $ + + sudo vim /etc/default/tftpd-hpa + +Configuration file may contain following configuration options by default: + +.. code-block:: + + # /etc/default/tftpd-hpa + + TFTP_USERNAME="tftp" + TFTP_DIRECTORY="/var/lib/tftpboot" + TFTP_ADDRESS=":69" + TFTP_OPTIONS="--secure" + +Now change the **TFTP_DIRECTORY** to **/tftp** and add the **--create** option to the +**TFTP_OPTIONS**. Without the **--create** option, you won't be able to create or upload +new files to the TFTP server. You will only be able to update existing files. + +After above changes /etc/default/tftpd-hpa file would look like this: + +.. code-block:: + + # /etc/default/tftpd-hpa + + TFTP_USERNAME="tftp" + TFTP_DIRECTORY="/tftp" + TFTP_ADDRESS=":69" + TFTP_OPTIONS="--secure --create" + +Since we have configured tftp directory as /tftp, put tiboot3.bin, tispl.bin +and u-boot.img after building it using sdk or manually cloning all the repos. + +To build binaries use following defconfig files: + +.. code-block:: + + am62x_evm_r5_ethboot_defconfig + am62x_evm_a53_ethboot_defconfig + +`tiboot3.bin` is expected to be built from `am62x_evm_r5_ethboot_defconfig` and +`tispl.bin` and `u-boot.img` are expected to be built from +`am62x_evm_a53_ethboot_defconfig`. + +Images should get fetched in following sequence as a part of boot procedure: + +.. code-block:: + + tiboot3.bin => tispl.bin => u-boot.img + +ROM loads and executes `tiboot3.bin` provided by the TFTP server. + +Next, based on NET_VCI_STRING string mentioned in respective defconfig file `tiboot3.bin` +fetches `tispl.bin` and then `tispl.bin` fetches `u-boot.img` from TFTP server which +completes Ethernet boot on the device. + Debugging U-Boot ---------------- From 8ac96c25e4a0df85f5069100ce1697d431bd0e12 Mon Sep 17 00:00:00 2001 From: Ken Kurematsu Date: Thu, 26 Sep 2024 09:26:05 +0000 Subject: [PATCH 2/8] doc: blkmap: Fix typo in command example Fixed a variable that was incorrect during the calculation of fileblks. Signed-off-by: Ken Kurematsu Reviewed-by: Quentin Schulz --- doc/usage/blkmap.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage/blkmap.rst b/doc/usage/blkmap.rst index 7337ea507a1..75f736c259f 100644 --- a/doc/usage/blkmap.rst +++ b/doc/usage/blkmap.rst @@ -54,7 +54,7 @@ downloaded file, in blocks: :: setexpr fileblks ${filesize} + 0x1ff - setexpr fileblks ${filesize} / 0x200 + setexpr fileblks ${fileblks} / 0x200 Then we can add a mapping to the start of our device, backed by the memory at `${loadaddr}`: From 82c98b9464d1c4473f9c695a0bbe1579c2de9682 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 16 Oct 2024 11:50:39 +0200 Subject: [PATCH 3/8] cmd: wget: CONFIG_CMD_WGET must depend on CONFIG_CMD_NET do_wget is defined in cmd/net.c. cmd/net.c is not compiled if CONFIG_CMD_NET=n. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- cmd/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index bff22b94de2..2f63959e91c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2117,6 +2117,7 @@ config CMD_TFTPBOOT config CMD_WGET bool "wget" + depends on CMD_NET default y if SANDBOX select PROT_TCP if NET select PROT_TCP_LWIP if NET_LWIP From 3d23dedd929cedb36499469ceec0247578fed046 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 16 Oct 2024 12:17:39 +0200 Subject: [PATCH 4/8] efi_loader: avoid #ifdef in efi_setup.c We prefer `if` over `#ifdef` in our code. Eliminate #ifdef statements in efi_setup.c. Reviewed-by: Ilias Apalodimas Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_setup.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index a610e032d2f..aa59bc7779d 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -86,7 +86,6 @@ out: return ret; } -#ifdef CONFIG_EFI_SECURE_BOOT /** * efi_init_secure_boot - initialize secure boot state * @@ -112,12 +111,6 @@ static efi_status_t efi_init_secure_boot(void) return ret; } -#else -static efi_status_t efi_init_secure_boot(void) -{ - return EFI_SUCCESS; -} -#endif /* CONFIG_EFI_SECURE_BOOT */ /** * efi_init_capsule - initialize capsule update state @@ -302,9 +295,11 @@ efi_status_t efi_init_obj_list(void) } /* Secure boot */ - ret = efi_init_secure_boot(); - if (ret != EFI_SUCCESS) - goto out; + if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT)) { + ret = efi_init_secure_boot(); + if (ret != EFI_SUCCESS) + goto out; + } /* Indicate supported runtime services */ ret = efi_init_runtime_supported(); @@ -322,11 +317,11 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; } -#ifdef CONFIG_NETDEVICES - ret = efi_net_register(); - if (ret != EFI_SUCCESS) - goto out; -#endif + if (IS_ENABLED(CONFIG_NETDEVICES)) { + ret = efi_net_register(); + if (ret != EFI_SUCCESS) + goto out; + } if (IS_ENABLED(CONFIG_ACPI)) { ret = efi_acpi_register(); if (ret != EFI_SUCCESS) From bc4fe5666dae6ab01a433970c3f5e6eb4833ebe7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 18 Oct 2024 03:18:36 +0200 Subject: [PATCH 5/8] efi_loader: reduce noisiness if ESP is missing EFI variables can be stored in a file on the EFI system partition. If that partition is missing we are writing two error messages per variable. This is too noisy. Just warn once about the missing ESP. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_var_file.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c index 413e1794e88..ba0bf33ffbd 100644 --- a/lib/efi_loader/efi_var_file.c +++ b/lib/efi_loader/efi_var_file.c @@ -37,18 +37,16 @@ static efi_status_t __maybe_unused efi_set_blk_dev_to_system_partition(void) char part_str[PART_STR_LEN]; int r; - if (efi_system_partition.uclass_id == UCLASS_INVALID) { - log_err("No EFI system partition\n"); + if (efi_system_partition.uclass_id == UCLASS_INVALID) return EFI_DEVICE_ERROR; - } + snprintf(part_str, PART_STR_LEN, "%x:%x", efi_system_partition.devnum, efi_system_partition.part); r = fs_set_blk_dev(blk_get_uclass_name(efi_system_partition.uclass_id), part_str, FS_TYPE_ANY); - if (r) { - log_err("Cannot read EFI system partition\n"); + if (r) return EFI_DEVICE_ERROR; - } + return EFI_SUCCESS; } @@ -67,14 +65,21 @@ efi_status_t efi_var_to_file(void) loff_t len; loff_t actlen; int r; + static bool once; ret = efi_var_collect(&buf, &len, EFI_VARIABLE_NON_VOLATILE); if (ret != EFI_SUCCESS) goto error; ret = efi_set_blk_dev_to_system_partition(); - if (ret != EFI_SUCCESS) - goto error; + if (ret != EFI_SUCCESS) { + if (!once) { + log_warning("Cannot persist EFI variables without system partition\n"); + once = true; + } + goto out; + } + once = false; r = fs_write(EFI_VAR_FILE_NAME, map_to_sysmem(buf), 0, len, &actlen); if (r || len != actlen) @@ -83,6 +88,7 @@ efi_status_t efi_var_to_file(void) error: if (ret != EFI_SUCCESS) log_err("Failed to persist EFI variables\n"); +out: free(buf); return ret; #else From 640427c6ae68ac3e85e06ea057b752398d4e060d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 17 Oct 2024 20:05:07 +0200 Subject: [PATCH 6/8] efi_loader: add missing lf in error message Messages written with log_err() should terminate with a linefeed. Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index b63b5cca71e..3d742fa1915 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -652,7 +652,7 @@ void *efi_alloc(size_t size) if (efi_allocate_pool(EFI_BOOT_SERVICES_DATA, size, &buf) != EFI_SUCCESS) { - log_err("out of memory"); + log_err("out of memory\n"); return NULL; } memset(buf, 0, size); From 76a692a2ca6acb1f644872289efd84997df429fb Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 17 Oct 2024 20:13:05 +0200 Subject: [PATCH 7/8] efi_loader: remove ERROR:, WARNING: prefixes in messages We should not write "ERROR:" or "WARNING:" when using log_err() or log_warning(). These prefixed don't provide additional information. Reviewed-by: Ilias Apalodimas Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_helper.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index a481eb4b7e3..00167bd2a10 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -412,7 +412,7 @@ static efi_status_t copy_fdt(void **fdtp) EFI_ACPI_RECLAIM_MEMORY, fdt_pages, &new_fdt_addr); if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to reserve space for FDT\n"); + log_err("Failed to reserve space for FDT\n"); goto done; } new_fdt = (void *)(uintptr_t)new_fdt_addr; @@ -468,7 +468,7 @@ efi_status_t efi_install_fdt(void *fdt) * but not both. */ if (CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) && fdt) - log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n"); + log_warning("Can't have ACPI table and device tree - ignoring DT.\n"); if (fdt == EFI_FDT_USE_INTERNAL) { const char *fdt_opt; @@ -483,13 +483,13 @@ efi_status_t efi_install_fdt(void *fdt) if (!fdt_opt) { fdt_opt = env_get("fdtcontroladdr"); if (!fdt_opt) { - log_err("ERROR: need device tree\n"); + log_err("need device tree\n"); return EFI_NOT_FOUND; } } fdt_addr = hextoul(fdt_opt, NULL); if (!fdt_addr) { - log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); + log_err("invalid $fdt_addr or $fdtcontroladdr\n"); return EFI_LOAD_ERROR; } fdt = map_sysmem(fdt_addr, 0); @@ -497,7 +497,7 @@ efi_status_t efi_install_fdt(void *fdt) /* Install device tree */ if (fdt_check_header(fdt)) { - log_err("ERROR: invalid device tree\n"); + log_err("invalid device tree\n"); return EFI_LOAD_ERROR; } @@ -510,12 +510,12 @@ efi_status_t efi_install_fdt(void *fdt) /* Prepare device tree for payload */ ret = copy_fdt(&fdt); if (ret) { - log_err("ERROR: out of memory\n"); + log_err("out of memory\n"); return EFI_OUT_OF_RESOURCES; } if (image_setup_libfdt(&img, fdt, false)) { - log_err("ERROR: failed to process device tree\n"); + log_err("failed to process device tree\n"); return EFI_LOAD_ERROR; } @@ -527,7 +527,7 @@ efi_status_t efi_install_fdt(void *fdt) if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) { ret = efi_tcg2_measure_dtb(fdt); if (ret == EFI_SECURITY_VIOLATION) { - log_err("ERROR: failed to measure DTB\n"); + log_err("failed to measure DTB\n"); return ret; } } @@ -535,7 +535,7 @@ efi_status_t efi_install_fdt(void *fdt) /* Install device tree as UEFI table */ ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS) { - log_err("ERROR: failed to install device tree\n"); + log_err("failed to install device tree\n"); return ret; } @@ -574,7 +574,7 @@ efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) */ ret = efi_set_watchdog(300); if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to set watchdog timer\n"); + log_err("failed to set watchdog timer\n"); goto out; } From 640c6c6cbaafa1b049118d431cf218d9dce3cdd8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 18 Oct 2024 03:30:14 +0200 Subject: [PATCH 8/8] efi_driver: use blk_create_devicef() The EFI block device driver is the only user of blk_create_device() outside the block device uclass. Use blk_create_devicef() instead like other block device drivers. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- lib/efi_driver/efi_block_device.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c index 34a0365739d..19a5ee24794 100644 --- a/lib/efi_driver/efi_block_device.c +++ b/lib/efi_driver/efi_block_device.c @@ -133,15 +133,13 @@ efi_bl_create_block_device(efi_handle_t handle, void *interface) sprintf(name, "efiblk#%d", devnum); /* Create driver model udevice for the EFI block io device */ - if (blk_create_device(parent, "efi_blk", name, UCLASS_EFI_LOADER, - devnum, io->media->block_size, - (lbaint_t)io->media->last_block, &bdev)) { + if (blk_create_devicef(parent, "efi_blk", name, UCLASS_EFI_LOADER, + devnum, io->media->block_size, + (lbaint_t)io->media->last_block, &bdev)) { ret = EFI_OUT_OF_RESOURCES; free(name); goto err; } - /* Set the DM_FLAG_NAME_ALLOCED flag to avoid a memory leak */ - device_set_name_alloced(bdev); plat = dev_get_plat(bdev); plat->handle = handle;