Skip to contentSkip to conversation

efi_loader: Simple Network Protocol

PATCH Superseded Heinrich Schuchardt 3 participants 37 messages Oct 5, 2017 – Oct 9, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover efi_loader: Simple Network Protocol

This patch series focuses on
* correction of parameter types for boot services
* fixes for the SetMem and CopyMem boot services
* fixes for the simple network protocol implementation (SNP)
* a unit test for SetMem, CopyMem and the simple network protocol

The unit test broadcasts a DHCPDISCOVER messager over the network and receives the reply.

This patch series is based on
* efi-next tree
https://github.com/agraf/u-boot/tree/efi-next
* [PATCH 1/1] efi_selftest: enable CONFIG_CMD_BOOTEFI_SELFTEST
https://patchwork.ozlabs.org/patch/816412/
This patch enables the unit test on qemu-x86_defconfig
* [PATCH 1/1] efi_loader: provide function comments for boot services
https://patchwork.ozlabs.org/patch/817010/

---
v2
Move efi_st_memcmp to a new module. We can reuse it in future tests.
Use constants as return values.
Reflect renaming of signaled to is_signaled for events.
---
Heinrich Schuchardt (17):
efi_loader: call EFI_EXIT in efi_copy_mem, efi_set_mem
efi_loader: parameters of CopyMem and SetMem
efi_loader: pass GUIDs as const efi_guid_t *
efi_loader: wrong type in wait_for_event
efi_loader: incorrect definition of EFI_SIMPLE_NETWORK_PROTOCOL
efi_loader: correct bits of receive_filters bit mask
efi_loader: fill simple network protocol revision
efi_loader: efi_net: hwaddr_size = 6
efi_net: return EFI_UNSUPPORTED where appropriate
efi_loader: use events for efi_net_receive
efi_loader: implement WaitForPacket event
efi_loader: fix efi_net_get_status
efi_loader: size fields in SimpleNetworkProtocol
efi_loader: fill return values in SimpleNetworkProtocol
efi_selftest: correct definition of efi_st_error
efi_selftest: allow printing MAC addresses
efi_loader: supply EFI network test

 include/efi_api.h                       |  62 +++--
 include/efi_selftest.h                  |  15 +-
 lib/efi_loader/efi_boottime.c           |  54 ++--
 lib/efi_loader/efi_net.c                | 144 +++++++++--
 lib/efi_selftest/Makefile               |   8 +-
 lib/efi_selftest/efi_selftest_console.c |  41 ++-
 lib/efi_selftest/efi_selftest_events.c  |   2 +-
 lib/efi_selftest/efi_selftest_snp.c     | 424 ++++++++++++++++++++++++++++++++
 lib/efi_selftest/efi_selftest_tpl.c     |   2 +-
 lib/efi_selftest/efi_selftest_util.c    |  25 ++
 10 files changed, 702 insertions(+), 75 deletions(-)
 create mode 100644 lib/efi_selftest/efi_selftest_snp.c
 create mode 100644 lib/efi_selftest/efi_selftest_util.c
Signature · 1 line
2.14.1
#1 lore raw

PATCH v2 1/17 efi_loader: call EFI_EXIT in efi_copy_mem, efi_set_mem

EFI_ENTRY and EFI_EXIT calls must match.

---
v2
no change

---
 lib/efi_loader/efi_boottime.c | 2 ++
 1 file changed, 2 insertions(+)
lib/efi_loader/efi_boottime.c +2 -0
index 66ce92f654..b8b98f2c4a 100644
@@ -1868,6 +1868,7 @@ static void EFIAPI efi_copy_mem(void *destination, void *source,
 {
 	EFI_ENTRY("%p, %p, %ld", destination, source, length);
 	memcpy(destination, source, length);
+	EFI_EXIT(EFI_SUCCESS);
 }
 
 /*
@@ -1885,6 +1886,7 @@ static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
 {
 	EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
 	memset(buffer, value, size);
+	EFI_EXIT(EFI_SUCCESS);
 }
 
 /*
Signature · 1 line
2.14.1
#3 lore raw

PATCH v2 2/17 efi_loader: parameters of CopyMem and SetMem

In reply to Heinrich Schuchardt

The UEFI spec defines the length parameters of CopyMem and SetMem as UINTN. We should size_t here.

The source buffer of CopyMem should be marked as const.

---
v2
no change

---
 include/efi_api.h             |  7 +++----
 lib/efi_loader/efi_boottime.c | 10 +++++-----
 2 files changed, 8 insertions(+), 9 deletions(-)
include/efi_api.h +3 -4
index c3b9032a48..0b1a383e61 100644
@@ -156,10 +156,9 @@ struct efi_boot_services {
 			void *handle, ...);
 	efi_status_t (EFIAPI *calculate_crc32)(void *data,
 			unsigned long data_size, uint32_t *crc32);
-	void (EFIAPI *copy_mem)(void *destination, void *source,
-			unsigned long length);
-	void (EFIAPI *set_mem)(void *buffer, unsigned long size,
-			uint8_t value);
+	void (EFIAPI *copy_mem)(void *destination, const void *source,
+			size_t length);
+	void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
 	void *create_event_ex;
 };
 
lib/efi_loader/efi_boottime.c +5 -5
index b8b98f2c4a..c48ff2cd2a 100644
@@ -1863,10 +1863,10 @@ static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  * @source		source of the copy operation
  * @length		number of bytes to copy
  */
-static void EFIAPI efi_copy_mem(void *destination, void *source,
-				unsigned long length)
+static void EFIAPI efi_copy_mem(void *destination, const void *source,
+				size_t length)
 {
-	EFI_ENTRY("%p, %p, %ld", destination, source, length);
+	EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
 	memcpy(destination, source, length);
 	EFI_EXIT(EFI_SUCCESS);
 }
@@ -1882,9 +1882,9 @@ static void EFIAPI efi_copy_mem(void *destination, void *source,
  * @size		size of buffer in bytes
  * @value		byte to copy to the buffer
  */
-static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
+static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
 {
-	EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
+	EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
 	memset(buffer, value, size);
 	EFI_EXIT(EFI_SUCCESS);
 }
Signature · 1 line
2.14.1
#4 lore raw

PATCH v2 2/17 efi_loader: parameters of CopyMem and SetMem

Quoted 5 lines · Heinrich Schuchardt

The UEFI spec defines the length parameters of CopyMem and SetMem as UINTN. We should size_t here.

The source buffer of CopyMem should be marked as const.

Quoted 8 lines

---
v2
no change

---
 include/efi_api.h             |  7 +++----
 lib/efi_loader/efi_boottime.c | 10 +++++-----
 2 files changed, 8 insertions(+), 9 deletions(-)
#5 lore raw

PATCH v2 3/17 efi_loader: pass GUIDs as const efi_guid_t *

In reply to Heinrich Schuchardt

We need to call some boottime services internally. Our GUIDs are stored as const efi_guid_t *.

The boottime services never change GUIDs.
So we can define the parameters as const efi_guid_t *.

---
v2
no change

---
 include/efi_api.h             | 27 ++++++++++++++-------------
 lib/efi_loader/efi_boottime.c | 40 +++++++++++++++++++++-------------------
 2 files changed, 35 insertions(+), 32 deletions(-)
include/efi_api.h +14 -13
index 0b1a383e61..aa4306aac9 100644
@@ -77,24 +77,25 @@ struct efi_boot_services {
 	efi_status_t (EFIAPI *check_event)(struct efi_event *event);
 #define EFI_NATIVE_INTERFACE	0x00000000
 	efi_status_t (EFIAPI *install_protocol_interface)(
-			void **handle, efi_guid_t *protocol,
+			void **handle, const efi_guid_t *protocol,
 			int protocol_interface_type, void *protocol_interface);
 	efi_status_t (EFIAPI *reinstall_protocol_interface)(
-			void *handle, efi_guid_t *protocol,
+			void *handle, const efi_guid_t *protocol,
 			void *old_interface, void *new_interface);
 	efi_status_t (EFIAPI *uninstall_protocol_interface)(void *handle,
-			efi_guid_t *protocol, void *protocol_interface);
-	efi_status_t (EFIAPI *handle_protocol)(efi_handle_t, efi_guid_t *,
-					       void **);
+			const efi_guid_t *protocol, void *protocol_interface);
+	efi_status_t (EFIAPI *handle_protocol)(efi_handle_t,
+					       const efi_guid_t *protocol,
+					       void **protocol_interface);
 	void *reserved;
 	efi_status_t (EFIAPI *register_protocol_notify)(
-			efi_guid_t *protocol, struct efi_event *event,
+			const efi_guid_t *protocol, struct efi_event *event,
 			void **registration);
 	efi_status_t (EFIAPI *locate_handle)(
 			enum efi_locate_search_type search_type,
-			efi_guid_t *protocol, void *search_key,
+			const efi_guid_t *protocol, void *search_key,
 			unsigned long *buffer_size, efi_handle_t *buffer);
-	efi_status_t (EFIAPI *locate_device_path)(efi_guid_t *protocol,
+	efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
 			struct efi_device_path **device_path,
 			efi_handle_t *device);
 	efi_status_t (EFIAPI *install_configuration_table)(
@@ -131,14 +132,14 @@ struct efi_boot_services {
 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
 	efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle,
-			efi_guid_t *protocol, void **interface,
+			const efi_guid_t *protocol, void **interface,
 			efi_handle_t agent_handle,
 			efi_handle_t controller_handle, u32 attributes);
 	efi_status_t (EFIAPI *close_protocol)(void *handle,
-			efi_guid_t *protocol, void *agent_handle,
+			const efi_guid_t *protocol, void *agent_handle,
 			void *controller_handle);
 	efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle,
-			efi_guid_t *protocol,
+			const efi_guid_t *protocol,
 			struct efi_open_protocol_info_entry **entry_buffer,
 			unsigned long *entry_count);
 	efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
@@ -146,9 +147,9 @@ struct efi_boot_services {
 			unsigned long *protocols_buffer_count);
 	efi_status_t (EFIAPI *locate_handle_buffer) (
 			enum efi_locate_search_type search_type,
-			efi_guid_t *protocol, void *search_key,
+			const efi_guid_t *protocol, void *search_key,
 			unsigned long *no_handles, efi_handle_t **buffer);
-	efi_status_t (EFIAPI *locate_protocol)(efi_guid_t *protocol,
+	efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
 			void *registration, void **protocol_interface);
 	efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
 			void **handle, ...);
lib/efi_loader/efi_boottime.c +21 -19
index c48ff2cd2a..e5adc17fab 100644
@@ -704,7 +704,7 @@ static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
  * @return			status code
  */
 static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
-			efi_guid_t *protocol, int protocol_interface_type,
+			const efi_guid_t *protocol, int protocol_interface_type,
 			void *protocol_interface)
 {
 	struct list_head *lhandle;
@@ -776,7 +776,7 @@ out:
  * @return			status code
  */
 static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
-			efi_guid_t *protocol, int protocol_interface_type,
+			const efi_guid_t *protocol, int protocol_interface_type,
 			void *protocol_interface)
 {
 	EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
@@ -802,7 +802,7 @@ static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
  * @return			status code
  */
 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
-			efi_guid_t *protocol, void *old_interface,
+			const efi_guid_t *protocol, void *old_interface,
 			void *new_interface)
 {
 	EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
@@ -823,7 +823,7 @@ static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  * @return			status code
  */
 static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
-			efi_guid_t *protocol, void *protocol_interface)
+			const efi_guid_t *protocol, void *protocol_interface)
 {
 	struct list_head *lhandle;
 	int i;
@@ -876,7 +876,7 @@ out:
  * @return			status code
  */
 static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
-			efi_guid_t *protocol, void *protocol_interface)
+			const efi_guid_t *protocol, void *protocol_interface)
 {
 	EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
 
@@ -897,9 +897,10 @@ static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
  * @registration	key for retrieving the registration information
  * @return		status code
  */
-static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
-							struct efi_event *event,
-							void **registration)
+static efi_status_t EFIAPI efi_register_protocol_notify(
+						const efi_guid_t *protocol,
+						struct efi_event *event,
+						void **registration)
 {
 	EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
 	return EFI_EXIT(EFI_OUT_OF_RESOURCES);
@@ -917,7 +918,7 @@ static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
  * @return		0 if the handle implements the protocol
  */
 static int efi_search(enum efi_locate_search_type search_type,
-		      efi_guid_t *protocol, void *search_key,
+		      const efi_guid_t *protocol, void *search_key,
 		      struct efi_object *efiobj)
 {
 	int i;
@@ -954,7 +955,7 @@ static int efi_search(enum efi_locate_search_type search_type,
  */
 static efi_status_t efi_locate_handle(
 			enum efi_locate_search_type search_type,
-			efi_guid_t *protocol, void *search_key,
+			const efi_guid_t *protocol, void *search_key,
 			unsigned long *buffer_size, efi_handle_t *buffer)
 {
 	struct list_head *lhandle;
@@ -1006,7 +1007,7 @@ static efi_status_t efi_locate_handle(
  */
 static efi_status_t EFIAPI efi_locate_handle_ext(
 			enum efi_locate_search_type search_type,
-			efi_guid_t *protocol, void *search_key,
+			const efi_guid_t *protocol, void *search_key,
 			unsigned long *buffer_size, efi_handle_t *buffer)
 {
 	EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
@@ -1028,7 +1029,8 @@ static efi_status_t EFIAPI efi_locate_handle_ext(
  * @device		handle of the device
  * @return		status code
  */
-static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
+static efi_status_t EFIAPI efi_locate_device_path(
+			const efi_guid_t *protocol,
 			struct efi_device_path **device_path,
 			efi_handle_t *device)
 {
@@ -1567,7 +1569,7 @@ static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
  * @return		status code
  */
 static efi_status_t EFIAPI efi_close_protocol(void *handle,
-					      efi_guid_t *protocol,
+					      const efi_guid_t *protocol,
 					      void *agent_handle,
 					      void *controller_handle)
 {
@@ -1590,7 +1592,7 @@ static efi_status_t EFIAPI efi_close_protocol(void *handle,
  * @return		status code
  */
 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
-			efi_guid_t *protocol,
+			const efi_guid_t *protocol,
 			struct efi_open_protocol_info_entry **entry_buffer,
 			unsigned long *entry_count)
 {
@@ -1679,7 +1681,7 @@ static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  */
 static efi_status_t EFIAPI efi_locate_handle_buffer(
 			enum efi_locate_search_type search_type,
-			efi_guid_t *protocol, void *search_key,
+			const efi_guid_t *protocol, void *search_key,
 			unsigned long *no_handles, efi_handle_t **buffer)
 {
 	efi_status_t r;
@@ -1721,7 +1723,7 @@ out:
  * @registration	registration key passed to the notification function
  * @protocol_interface	interface implementing the protocol
  */
-static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
+static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
 					       void *registration,
 					       void **protocol_interface)
 {
@@ -1774,7 +1776,7 @@ static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
 	EFI_ENTRY("%p", handle);
 
 	va_list argptr;
-	efi_guid_t *protocol;
+	const efi_guid_t *protocol;
 	void *protocol_interface;
 	efi_status_t r = EFI_SUCCESS;
 	int i = 0;
@@ -1905,7 +1907,7 @@ static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
  * @return		status code
  */
 static efi_status_t EFIAPI efi_open_protocol(
-			void *handle, efi_guid_t *protocol,
+			void *handle, const efi_guid_t *protocol,
 			void **protocol_interface, void *agent_handle,
 			void *controller_handle, uint32_t attributes)
 {
@@ -1989,7 +1991,7 @@ out:
  * @return		status code
  */
 static efi_status_t EFIAPI efi_handle_protocol(void *handle,
-					       efi_guid_t *protocol,
+					       const efi_guid_t *protocol,
 					       void **protocol_interface)
 {
 	return efi_open_protocol(handle, protocol, protocol_interface, NULL,
Signature · 1 line
2.14.1
#6 lore raw

PATCH v2 3/17 efi_loader: pass GUIDs as const efi_guid_t *

Quoted 6 lines · Heinrich Schuchardt

We need to call some boottime services internally. Our GUIDs are stored as const efi_guid_t *.

The boottime services never change GUIDs.
So we can define the parameters as const efi_guid_t *.

Quoted 8 lines

---
v2
no change

---
 include/efi_api.h             | 27 ++++++++++++++-------------
 lib/efi_loader/efi_boottime.c | 40 +++++++++++++++++++++-------------------
 2 files changed, 35 insertions(+), 32 deletions(-)
#7 lore raw

PATCH v2 4/17 efi_loader: wrong type in wait_for_event

In reply to Heinrich Schuchardt

The UEFI spec defines parameter index of WaitForEvent as UINTN*. So we should use size_t here.

I deliberately do not use UINTN because I hold a following patch that will eliminate UINTN because uppercase types to not match the U-Boot coding style.

---
v2
no change

---
 include/efi_api.h                      | 2 +-
 lib/efi_loader/efi_boottime.c          | 2 +-
 lib/efi_selftest/efi_selftest_events.c | 2 +-
 lib/efi_selftest/efi_selftest_tpl.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
include/efi_api.h +1 -1
index aa4306aac9..c44dc9d0cb 100644
@@ -71,7 +71,7 @@ struct efi_boot_services {
 					 enum efi_timer_delay type,
 					 uint64_t trigger_time);
 	efi_status_t (EFIAPI *wait_for_event)(unsigned long number_of_events,
-			struct efi_event **event, unsigned long *index);
+			struct efi_event **event, size_t *index);
 	efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
 	efi_status_t (EFIAPI *close_event)(struct efi_event *event);
 	efi_status_t (EFIAPI *check_event)(struct efi_event *event);
lib/efi_loader/efi_boottime.c +1 -1
index e5adc17fab..976d5822f7 100644
@@ -553,7 +553,7 @@ static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
  */
 static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
 					      struct efi_event **event,
-					      unsigned long *index)
+					      size_t *index)
 {
 	int i, j;
 
lib/efi_selftest/efi_selftest_events.c +1 -1
index 532f165d43..b2cdc150da 100644
@@ -108,7 +108,7 @@ static int teardown(void)
  */
 static int execute(void)
 {
-	unsigned long index;
+	size_t index;
 	efi_status_t ret;
 
 	/* Set 10 ms timer */
lib/efi_selftest/efi_selftest_tpl.c +1 -1
index 5d13f3b52d..0b78ee7595 100644
@@ -110,7 +110,7 @@ static int teardown(void)
  */
 static int execute(void)
 {
-	unsigned long index;
+	size_t index;
 	efi_status_t ret;
 	UINTN old_tpl;
 
Signature · 1 line
2.14.1
#8 lore raw

PATCH v2 4/17 efi_loader: wrong type in wait_for_event

Quoted 11 lines · Heinrich Schuchardt

The UEFI spec defines parameter index of WaitForEvent as UINTN*. So we should use size_t here.

I deliberately do not use UINTN because I hold a following patch that will eliminate UINTN because uppercase types to not match the U-Boot coding style.

---
v2
no change

Quoted 6 lines
---
 include/efi_api.h                      | 2 +-
 lib/efi_loader/efi_boottime.c          | 2 +-
 lib/efi_selftest/efi_selftest_events.c | 2 +-
 lib/efi_selftest/efi_selftest_tpl.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
#9 lore raw

PATCH v2 5/17 efi_loader: incorrect definition of EFI_SIMPLE_NETWORK_PROTOCOL

In reply to Heinrich Schuchardt

WaitForPacket is an event and not a function pointer.

---
v2
no change

---
 include/efi_api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/efi_api.h +1 -1
index c44dc9d0cb..308baeec49 100644
@@ -633,7 +633,7 @@ struct efi_simple_network
 			ulong *header_size, ulong *buffer_size, void *buffer,
 			struct efi_mac_address *src_addr,
 			struct efi_mac_address *dest_addr, u16 *protocol);
-	void (EFIAPI *waitforpacket)(void);
+	struct efi_event *wait_for_packet;
 	struct efi_simple_network_mode *mode;
 };
 
Signature · 1 line
2.14.1
#11 lore raw

PATCH v2 6/17 efi_loader: correct bits of receive_filters bit mask

In reply to Heinrich Schuchardt

Remove extraneous commas.
Add comment.

---
v2
no change

---
 include/efi_api.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
include/efi_api.h +6 -5
index 308baeec49..8c227ce703 100644
@@ -593,11 +593,12 @@ struct efi_simple_network_mode {
 	u8 media_present;
 };
 
-#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01,
-#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02,
-#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04,
-#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08,
-#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10,
+/* receive_filters bit mask */
+#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
+#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
+#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
 
 struct efi_simple_network
 {
Signature · 1 line
2.14.1
#13 lore raw

PATCH v2 7/17 efi_loader: fill simple network protocol revision

In reply to Heinrich Schuchardt

Provide the simple network protocol revision.
This revision number could be used to identify backwards compatible enhancements of the protocol.

---
v2
no change

---
 include/efi_api.h        | 3 +++
 lib/efi_loader/efi_net.c | 1 +
 2 files changed, 4 insertions(+)
include/efi_api.h +3 -0
index 8c227ce703..2f31464cb3 100644
@@ -600,6 +600,9 @@ struct efi_simple_network_mode {
 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
 
+/* revision of the simple network protocol */
+#define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION	0x00010000
+
 struct efi_simple_network
 {
 	u64 revision;
lib/efi_loader/efi_net.c +1 -0
index 91f1e4a69e..fb23bcf633 100644
@@ -228,6 +228,7 @@ int efi_net_register(void)
 	netobj->parent.protocols[2].guid = &efi_pxe_guid;
 	netobj->parent.protocols[2].protocol_interface = &netobj->pxe;
 	netobj->parent.handle = &netobj->net;
+	netobj->net.revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
 	netobj->net.start = efi_net_start;
 	netobj->net.stop = efi_net_stop;
 	netobj->net.initialize = efi_net_initialize;
Signature · 1 line
2.14.1
#14 lore raw

PATCH v2 7/17 efi_loader: fill simple network protocol revision

Quoted 4 lines · Heinrich Schuchardt

Provide the simple network protocol revision.
This revision number could be used to identify backwards compatible enhancements of the protocol.

Quoted 8 lines

---
v2
no change

---
 include/efi_api.h        | 3 +++
 lib/efi_loader/efi_net.c | 1 +
 2 files changed, 4 insertions(+)
#15 lore raw

PATCH v2 8/17 efi_loader: efi_net: hwaddr_size = 6

In reply to Heinrich Schuchardt

The length of a MAC address is 6.
We have to set this length in the EFI_SIMPLE_NETWORK_MODE structure of the EFI_SIMPLE_NETWORK_PROTOCOL.

Without this patch iPXE fails to initialize the network with error message
SNP MAC(001e0633bcbf,0x0) has invalid hardware address length 0

---
v2
no change

---
 lib/efi_loader/efi_net.c | 1 +
 1 file changed, 1 insertion(+)
lib/efi_loader/efi_net.c +1 -0
index fb23bcf633..9def34cf93 100644
@@ -245,6 +245,7 @@ int efi_net_register(void)
 	netobj->net.mode = &netobj->net_mode;
 	netobj->net_mode.state = EFI_NETWORK_STARTED;
 	memcpy(netobj->net_mode.current_address.mac_addr, eth_get_ethaddr(), 6);
+	netobj->net_mode.hwaddr_size = ARP_HLEN;
 	netobj->net_mode.max_packet_size = PKTSIZE;
 
 	netobj->pxe.mode = &netobj->pxe_mode;
Signature · 1 line
2.14.1
#16 lore raw

PATCH v2 8/17 efi_loader: efi_net: hwaddr_size = 6

Quoted 8 lines · Heinrich Schuchardt

The length of a MAC address is 6.
We have to set this length in the EFI_SIMPLE_NETWORK_MODE structure of the EFI_SIMPLE_NETWORK_PROTOCOL.

Without this patch iPXE fails to initialize the network with error message
SNP MAC(001e0633bcbf,0x0) has invalid hardware address length 0

Quoted 7 lines

---
v2
no change

---
 lib/efi_loader/efi_net.c | 1 +
 1 file changed, 1 insertion(+)
#17 lore raw

PATCH v2 9/17 efi_net: return EFI_UNSUPPORTED where appropriate

In reply to Heinrich Schuchardt

U-Boot does not implement all functions of the simple network protocol. The unimplemented functions return either of EFI_SUCCESS and EFI_INVALID_PARAMETER.

The UEFI spec foresees to return EFI_UNSUPPORTED in these cases.

---
v2
no change

---
 lib/efi_loader/efi_net.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
lib/efi_loader/efi_net.c +4 -6
index 9def34cf93..569bf367a8 100644
@@ -78,9 +78,7 @@ static efi_status_t EFIAPI efi_net_receive_filters(
 	EFI_ENTRY("%p, %x, %x, %x, %lx, %p", this, enable, disable,
 		  reset_mcast_filter, mcast_filter_count, mcast_filter);
 
-	/* XXX Do we care? */
-
-	return EFI_EXIT(EFI_SUCCESS);
+	return EFI_EXIT(EFI_UNSUPPORTED);
 }
 
 static efi_status_t EFIAPI efi_net_station_address(
@@ -89,7 +87,7 @@ static efi_status_t EFIAPI efi_net_station_address(
 {
 	EFI_ENTRY("%p, %x, %p", this, reset, new_mac);
 
-	return EFI_EXIT(EFI_INVALID_PARAMETER);
+	return EFI_EXIT(EFI_UNSUPPORTED);
 }
 
 static efi_status_t EFIAPI efi_net_statistics(struct efi_simple_network *this,
@@ -98,7 +96,7 @@ static efi_status_t EFIAPI efi_net_statistics(struct efi_simple_network *this,
 {
 	EFI_ENTRY("%p, %x, %p, %p", this, reset, stat_size, stat_table);
 
-	return EFI_EXIT(EFI_INVALID_PARAMETER);
+	return EFI_EXIT(EFI_UNSUPPORTED);
 }
 
 static efi_status_t EFIAPI efi_net_mcastiptomac(struct efi_simple_network *this,
@@ -118,7 +116,7 @@ static efi_status_t EFIAPI efi_net_nvdata(struct efi_simple_network *this,
 	EFI_ENTRY("%p, %x, %lx, %lx, %p", this, read_write, offset, buffer_size,
 		  buffer);
 
-	return EFI_EXIT(EFI_INVALID_PARAMETER);
+	return EFI_EXIT(EFI_UNSUPPORTED);
 }
 
 static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
Signature · 1 line
2.14.1
#18 lore raw

PATCH v2 9/17 efi_net: return EFI_UNSUPPORTED where appropriate

Quoted 6 lines · Heinrich Schuchardt

U-Boot does not implement all functions of the simple network protocol. The unimplemented functions return either of EFI_SUCCESS and EFI_INVALID_PARAMETER.

The UEFI spec foresees to return EFI_UNSUPPORTED in these cases.

Quoted 7 lines

---
v2
no change

---
 lib/efi_loader/efi_net.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
#19 lore raw

PATCH v2 10/17 efi_loader: use events for efi_net_receive

In reply to Heinrich Schuchardt

A timer event is defined. The timer handler cares for receiving new packets.

efi_timer_check is called both in efi_net_transmit and efi_net_receive to enable events during network communication.

Calling efi_timer_check in efi_net_get_status is implemented in a separate patch.

---
v2
no change

---
 lib/efi_loader/efi_net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)
lib/efi_loader/efi_net.c +50 -3
index 569bf367a8..3498b96f7a 100644
@@ -19,6 +19,11 @@ static const efi_guid_t efi_pxe_guid = EFI_PXE_GUID;
 static struct efi_pxe_packet *dhcp_ack;
 static bool new_rx_packet;
 static void *new_tx_packet;
+/*
+ * The notification function of this event is called in every timer cycle
+ * to check if a new network packet has been received.
+ */
+static struct efi_event *network_timer_event;
 
 struct efi_net_obj {
 	/* Generic EFI object parent class data */
@@ -143,6 +148,8 @@ static efi_status_t EFIAPI efi_net_transmit(struct efi_simple_network *this,
 	EFI_ENTRY("%p, %lx, %lx, %p, %p, %p, %p", this, header_size,
 		  buffer_size, buffer, src_addr, dest_addr, protocol);
 
+	efi_timer_check();
+
 	if (header_size) {
 		/* We would need to create the header if header_size != 0 */
 		return EFI_EXIT(EFI_INVALID_PARAMETER);
@@ -174,9 +181,7 @@ static efi_status_t EFIAPI efi_net_receive(struct efi_simple_network *this,
 	EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size,
 		  buffer_size, buffer, src_addr, dest_addr, protocol);
 
-	push_packet = efi_net_push;
-	eth_rx();
-	push_packet = NULL;
+	efi_timer_check();
 
 	if (!new_rx_packet)
 		return EFI_EXIT(EFI_NOT_READY);
@@ -204,10 +209,32 @@ void efi_net_set_dhcp_ack(void *pkt, int len)
 	memcpy(dhcp_ack, pkt, min(len, maxsize));
 }
 
+/*
+ * Check if a new network packet has been received.
+ *
+ * This notification function is called in every timer cycle.
+ *
+ * @event	the event for which this notification function is registered
+ * @context	event context - not used in this function
+ */
+static void EFIAPI efi_network_timer_notify(struct efi_event *event,
+					    void *context)
+{
+	EFI_ENTRY("%p, %p", event, context);
+
+	if (!new_rx_packet) {
+		push_packet = efi_net_push;
+		eth_rx();
+		push_packet = NULL;
+	}
+	EFI_EXIT(EFI_SUCCESS);
+}
+
 /* This gets called from do_bootefi_exec(). */
 int efi_net_register(void)
 {
 	struct efi_net_obj *netobj;
+	efi_status_t r;
 
 	if (!eth_get_dev()) {
 		/* No eth device active, don't expose any */
@@ -253,5 +280,25 @@ int efi_net_register(void)
 	/* Hook net up to the device list */
 	list_add_tail(&netobj->parent.link, &efi_obj_list);
 
+	/*
+	 * Create a timer event.
+	 *
+	 * The notification function is used to check if an new networkd packet
+	 * has been received.
+	 */
+	r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
+			     efi_network_timer_notify, NULL,
+			     &network_timer_event);
+	if (r != EFI_SUCCESS) {
+		printf("ERROR: Failed to register network event\n");
+		return r;
+	}
+	/* Network is time critical, create event in every timer cyle */
+	r = efi_set_timer(network_timer_event, EFI_TIMER_PERIODIC, 0);
+	if (r != EFI_SUCCESS) {
+		printf("ERROR: Failed to set network timer\n");
+		return r;
+	}
+
 	return 0;
 }
Signature · 1 line
2.14.1
#20 lore raw

PATCH v2 10/17 efi_loader: use events for efi_net_receive

Quoted 8 lines · Heinrich Schuchardt

A timer event is defined. The timer handler cares for receiving new packets.

efi_timer_check is called both in efi_net_transmit and efi_net_receive to enable events during network communication.

Calling efi_timer_check in efi_net_get_status is implemented in a separate patch.

Can you explain in the commit message why this patch is needed?

Quoted 8 lines

---
v2
no change

---
 lib/efi_loader/efi_net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)
#21 lore raw

PATCH v2 11/17 efi_loader: implement WaitForPacket event

In reply to Heinrich Schuchardt

The WaitForPacket event informs that a network package has been received by the SimpleNetworkProtocol.

---
v2
signaled has been renamed to is_signaled and is bool

---
 lib/efi_loader/efi_net.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
lib/efi_loader/efi_net.c +17 -0
index 3498b96f7a..f63db686af 100644
@@ -24,6 +24,10 @@ static void *new_tx_packet;
  * to check if a new network packet has been received.
  */
 static struct efi_event *network_timer_event;
+/*
+ * This event is signaled when a packet has been received.
+ */
+static struct efi_event *wait_for_packet;
 
 struct efi_net_obj {
 	/* Generic EFI object parent class data */
@@ -227,6 +231,8 @@ static void EFIAPI efi_network_timer_notify(struct efi_event *event,
 		eth_rx();
 		push_packet = NULL;
 	}
+	if (!new_rx_packet)
+		wait_for_packet->is_signaled = true;
 	EFI_EXIT(EFI_SUCCESS);
 }
 
@@ -280,6 +286,17 @@ int efi_net_register(void)
 	/* Hook net up to the device list */
 	list_add_tail(&netobj->parent.link, &efi_obj_list);
 
+	/*
+	 * Create WaitForPacket event.
+	 */
+	r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
+			     efi_network_timer_notify, NULL,
+			     &wait_for_packet);
+	if (r != EFI_SUCCESS) {
+		printf("ERROR: Failed to register network event\n");
+		return r;
+	}
+	netobj->net.wait_for_packet = wait_for_packet;
 	/*
 	 * Create a timer event.
 	 *
Signature · 1 line
2.14.1
#22 lore raw

PATCH v2 11/17 efi_loader: implement WaitForPacket event

Quoted 27 lines · Heinrich Schuchardt

The WaitForPacket event informs that a network package has been received by the SimpleNetworkProtocol.

---
v2
signaled has been renamed to is_signaled and is bool

---
 lib/efi_loader/efi_net.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
lib/efi_loader/efi_net.c +4 -0
index 3498b96f7a..f63db686af 100644
@@ -24,6 +24,10 @@ static void *new_tx_packet;
  * to check if a new network packet has been received.
  */
 static struct efi_event *network_timer_event;
+/*
+ * This event is signaled when a packet has been received.
+ */
+static struct efi_event *wait_for_packet;
 
 struct efi_net_obj {
 	/* Generic EFI object parent class data */

lib/efi_loader/efi_net.c static void EFIAPI efi_network_timer_notify(struct efi_event *event, · line 235

Quoted 5 lines
lib/efi_loader/efi_net.c +2 -0
@@ -227,6 +231,8 @@ static void EFIAPI efi_network_timer_notify(struct efi_event *event,
 		eth_rx();
 		push_packet = NULL;
 	}
+	if (!new_rx_packet)
+		wait_for_packet->is_signaled = true;

Shouldn't that be if (new_rx_packet)? You want to know whether eth_rx() received something, no?

In fact, why don't you just move this whole line into efi_net_push()?

Alex

Quoted 22 lines
lib/efi_loader/efi_net.c +11 -0
 	EFI_EXIT(EFI_SUCCESS);
 }
 
@@ -280,6 +286,17 @@ int efi_net_register(void)
 	/* Hook net up to the device list */
 	list_add_tail(&netobj->parent.link, &efi_obj_list);
 
+	/*
+	 * Create WaitForPacket event.
+	 */
+	r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
+			     efi_network_timer_notify, NULL,
+			     &wait_for_packet);
+	if (r != EFI_SUCCESS) {
+		printf("ERROR: Failed to register network event\n");
+		return r;
+	}
+	netobj->net.wait_for_packet = wait_for_packet;
 	/*
 	 * Create a timer event.
 	 *
#23 lore raw

PATCH v2 12/17 efi_loader: fix efi_net_get_status

In reply to Heinrich Schuchardt

The returned interrupt status was wrong.

As out transmit buffer is empty we need to always set EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT.

When we have received a packet we need to set
EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT.

Furthermore we should call efi_timer_check() to handle events.

---
v2
no change

---
 include/efi_api.h        |  6 ++++++
 lib/efi_loader/efi_net.c | 11 ++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
include/efi_api.h +6 -0
index 2f31464cb3..1f349db246 100644
@@ -600,6 +600,12 @@ struct efi_simple_network_mode {
 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
 
+/* interrupt status bit mask */
+#define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT	0x01
+#define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT	0x02
+#define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT	0x04
+#define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT	0x08
+
 /* revision of the simple network protocol */
 #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION	0x00010000
 
lib/efi_loader/efi_net.c +8 -3
index f63db686af..5866119817 100644
@@ -133,9 +133,14 @@ static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
 {
 	EFI_ENTRY("%p, %p, %p", this, int_status, txbuf);
 
-	/* We send packets synchronously, so nothing is outstanding */
-	if (int_status)
-		*int_status = 0;
+	efi_timer_check();
+
+	if (int_status) {
+		/* We send packets synchronously, so nothing is outstanding */
+		*int_status = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
+		if (new_rx_packet)
+			*int_status |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
+	}
 	if (txbuf)
 		*txbuf = new_tx_packet;
 
Signature · 1 line
2.14.1
#24 lore raw

PATCH v2 12/17 efi_loader: fix efi_net_get_status

Quoted 10 lines · Heinrich Schuchardt

The returned interrupt status was wrong.

As out transmit buffer is empty we need to always set EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT.

When we have received a packet we need to set
EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT.

Furthermore we should call efi_timer_check() to handle events.

Quoted 8 lines

---
v2
no change

---
 include/efi_api.h        |  6 ++++++
 lib/efi_loader/efi_net.c | 11 ++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
#25 lore raw

PATCH v2 13/17 efi_loader: size fields in SimpleNetworkProtocol

In reply to Heinrich Schuchardt

The size fields in the Simple Network Protocol are all UINTN in the UEFI spec. So use size_t.

Provide a function description of the receive function.

---
v2
no change

---
 include/efi_api.h        |  4 ++--
 lib/efi_loader/efi_net.c | 24 ++++++++++++++++++++----
 2 files changed, 22 insertions(+), 6 deletions(-)
include/efi_api.h +2 -2
index 1f349db246..a9a6494afe 100644
@@ -636,11 +636,11 @@ struct efi_simple_network
 	efi_status_t (EFIAPI *get_status)(struct efi_simple_network *this,
 			u32 *int_status, void **txbuf);
 	efi_status_t (EFIAPI *transmit)(struct efi_simple_network *this,
-			ulong header_size, ulong buffer_size, void *buffer,
+			size_t header_size, size_t buffer_size, void *buffer,
 			struct efi_mac_address *src_addr,
 			struct efi_mac_address *dest_addr, u16 *protocol);
 	efi_status_t (EFIAPI *receive)(struct efi_simple_network *this,
-			ulong *header_size, ulong *buffer_size, void *buffer,
+			size_t *header_size, size_t *buffer_size, void *buffer,
 			struct efi_mac_address *src_addr,
 			struct efi_mac_address *dest_addr, u16 *protocol);
 	struct efi_event *wait_for_packet;
lib/efi_loader/efi_net.c +20 -4
index 5866119817..f8ae5578ba 100644
@@ -150,12 +150,13 @@ static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
 }
 
 static efi_status_t EFIAPI efi_net_transmit(struct efi_simple_network *this,
-		ulong header_size, ulong buffer_size, void *buffer,
+		size_t header_size, size_t buffer_size, void *buffer,
 		struct efi_mac_address *src_addr,
 		struct efi_mac_address *dest_addr, u16 *protocol)
 {
-	EFI_ENTRY("%p, %lx, %lx, %p, %p, %p, %p", this, header_size,
-		  buffer_size, buffer, src_addr, dest_addr, protocol);
+	EFI_ENTRY("%p, %lu, %lu, %p, %p, %p, %p", this,
+		  (unsigned long)header_size, (unsigned long)buffer_size,
+		  buffer, src_addr, dest_addr, protocol);
 
 	efi_timer_check();
 
@@ -182,8 +183,23 @@ static void efi_net_push(void *pkt, int len)
 	new_rx_packet = true;
 }
 
+/*
+ * Receive a packet from a network interface.
+ *
+ * This function implements the Receive service of the Simple Network Protocol.
+ * See the UEFI spec for details.
+ *
+ * @this	the instance of the Simple Network Protocol
+ * @header_size	size of the media header
+ * @buffer_size	size of the buffer to receive the packet
+ * @buffer	buffer to receive the packet
+ * @src_addr	source MAC address
+ * @dest_addr	destination MAC address
+ * @protocol	protocol
+ * @return	status code
+ */
 static efi_status_t EFIAPI efi_net_receive(struct efi_simple_network *this,
-		ulong *header_size, ulong *buffer_size, void *buffer,
+		size_t *header_size, size_t *buffer_size, void *buffer,
 		struct efi_mac_address *src_addr,
 		struct efi_mac_address *dest_addr, u16 *protocol)
 {
Signature · 1 line
2.14.1
#26 lore raw

PATCH v2 13/17 efi_loader: size fields in SimpleNetworkProtocol

Quoted 5 lines · Heinrich Schuchardt

The size fields in the Simple Network Protocol are all UINTN in the UEFI spec. So use size_t.

Provide a function description of the receive function.

Quoted 8 lines

---
v2
no change

---
 include/efi_api.h        |  4 ++--
 lib/efi_loader/efi_net.c | 24 ++++++++++++++++++++----
 2 files changed, 22 insertions(+), 6 deletions(-)
#27 lore raw

PATCH v2 14/17 efi_loader: fill return values in SimpleNetworkProtocol

In reply to Heinrich Schuchardt

In the receive function all return values should be filled.

---
v2
no change

---
 lib/efi_loader/efi_net.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
lib/efi_loader/efi_net.c +25 -2
index f8ae5578ba..9c85e1b72f 100644
@@ -203,6 +203,10 @@ static efi_status_t EFIAPI efi_net_receive(struct efi_simple_network *this,
 		struct efi_mac_address *src_addr,
 		struct efi_mac_address *dest_addr, u16 *protocol)
 {
+	struct ethernet_hdr *eth_hdr;
+	size_t hdr_size = sizeof(struct ethernet_hdr);
+	u16 protlen;
+
 	EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size,
 		  buffer_size, buffer, src_addr, dest_addr, protocol);
 
@@ -210,13 +214,32 @@ static efi_status_t EFIAPI efi_net_receive(struct efi_simple_network *this,
 
 	if (!new_rx_packet)
 		return EFI_EXIT(EFI_NOT_READY);
-
+	/* Check that we at least received an Ethernet header */
+	if (net_rx_packet_len < sizeof(struct ethernet_hdr)) {
+		new_rx_packet = false;
+		return EFI_EXIT(EFI_NOT_READY);
+	}
+	/* Fill export parameters */
+	eth_hdr = (struct ethernet_hdr *)net_rx_packet;
+	protlen = ntohs(eth_hdr->et_protlen);
+	if (protlen == 0x8100) {
+		hdr_size += 4;
+		protlen = ntohs(*(u16 *)&net_rx_packet[hdr_size - 2]);
+	}
+	if (header_size)
+		*header_size = hdr_size;
+	if (dest_addr)
+		memcpy(dest_addr, eth_hdr->et_dest, ARP_HLEN);
+	if (src_addr)
+		memcpy(src_addr, eth_hdr->et_src, ARP_HLEN);
+	if (protocol)
+		*protocol = protlen;
 	if (*buffer_size < net_rx_packet_len) {
 		/* Packet doesn't fit, try again with bigger buf */
 		*buffer_size = net_rx_packet_len;
 		return EFI_EXIT(EFI_BUFFER_TOO_SMALL);
 	}
-
+	/* Copy packet */
 	memcpy(buffer, net_rx_packet, net_rx_packet_len);
 	*buffer_size = net_rx_packet_len;
 	new_rx_packet = false;
Signature · 1 line
2.14.1
#28 lore raw

PATCH v2 14/17 efi_loader: fill return values in SimpleNetworkProtocol

Quoted 9 lines · Heinrich Schuchardt

In the receive function all return values should be filled.

---
v2
no change

---
 lib/efi_loader/efi_net.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

(in so far as I understand it)

#29 lore raw

PATCH v2 15/17 efi_selftest: correct definition of efi_st_error

In reply to Heinrich Schuchardt

Enclose definition in parantheses to allow using efi_st_error like a void function.

---
v2
no change

---
 include/efi_selftest.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/efi_selftest.h +2 -2
index beb662d4e1..2f0992f06e 100644
@@ -23,8 +23,8 @@
  * @...	format string followed by fields to print
  */
 #define efi_st_error(...) \
-	efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__); \
-	efi_st_printf(__VA_ARGS__) \
+	(efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
+	efi_st_printf(__VA_ARGS__)) \
 
 /*
  * A test may be setup and executed at boottime,
Signature · 1 line
2.14.1
#31 lore raw

PATCH v2 16/17 efi_selftest: allow printing MAC addresses

In reply to Heinrich Schuchardt

Add %pm as format string to print a MAC address.
This is helpful when analyzing network problems.

---
v2
no change

---
 lib/efi_selftest/efi_selftest_console.c | 41 ++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
lib/efi_selftest/efi_selftest_console.c +40 -1
index 7b5b724a61..840e2290c6 100644
@@ -12,6 +12,37 @@
 struct efi_simple_text_output_protocol *con_out;
 struct efi_simple_input_interface *con_in;
 
+/*
+ * Print a MAC address to an u16 string
+ *
+ * @pointer: mac address
+ * @buf: pointer to buffer address
+ * on return position of terminating zero word
+ */
+static void mac(void *pointer, u16 **buf)
+{
+	int i, j;
+	u16 c;
+	u8 *p = (u8 *)pointer;
+	u8 byte;
+	u16 *pos = *buf;
+
+	for (i = 0; i < ARP_HLEN; ++i) {
+		if (i)
+			*pos++ = ':';
+		byte = p[i];
+		for (j = 4; j >= 0; j -= 4) {
+			c = (byte >> j) & 0x0f;
+			c += '0';
+			if (c > '9')
+				c += 'a' - '9' - 1;
+			*pos++ = c;
+		}
+	}
+	*pos = 0;
+	*buf = pos;
+}
+
 /*
  * Print a pointer to an u16 string
  *
@@ -146,7 +177,15 @@ void efi_st_printf(const char *fmt, ...)
 				int2dec(va_arg(args, s32), &pos);
 				break;
 			case 'p':
-				pointer(va_arg(args, void*), &pos);
+				++c;
+				switch (*c) {
+				case 'm':
+					mac(va_arg(args, void*), &pos);
+					break;
+				default:
+					--c;
+					pointer(va_arg(args, void*), &pos);
+				}
 				break;
 			case 's':
 				s = va_arg(args, const char *);
Signature · 1 line
2.14.1
#32 lore raw

PATCH v2 16/17 efi_selftest: allow printing MAC addresses

Quoted 10 lines · Heinrich Schuchardt

Add %pm as format string to print a MAC address.
This is helpful when analyzing network problems.

---
v2
no change

---
 lib/efi_selftest/efi_selftest_console.c | 41 ++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

I wonder if we could use U-Boot's existing printf() code?

#33 lore raw

PATCH v2 17/17 efi_loader: supply EFI network test

In reply to Heinrich Schuchardt

This patch provices an EFI application to check the correct function of the Simple Network Protocol implementation.

It sends a DHCP request and analyzes the DHCP offer.

Different error conditions including a 10s timeout are checked.

A successful execution will look like this:

=> bootefi nettest
Scanning disk ide.blk#0...
Found 1 disks
WARNING: Invalid device tree, expect boot to fail Network test
DHCP Discover
DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02) as broadcast message.
OK. The test was completed successfully.

---
v2
move efi_st_memcmp to efi_selftest_util.c The function can be reused for other tests.

Use constants for return values.

---
 include/efi_selftest.h               |  11 +
 lib/efi_selftest/Makefile            |   8 +-
 lib/efi_selftest/efi_selftest_snp.c  | 424 +++++++++++++++++++++++++++++++++++
 lib/efi_selftest/efi_selftest_util.c |  25 +++
 4 files changed, 467 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_selftest/efi_selftest_snp.c
 create mode 100644 lib/efi_selftest/efi_selftest_util.c
include/efi_selftest.h +11 -0
index 2f0992f06e..7ec42a0406 100644
@@ -60,6 +60,17 @@ void efi_st_exit_boot_services(void);
 void efi_st_printf(const char *fmt, ...)
 		 __attribute__ ((format (__printf__, 1, 2)));
 
+/*
+ * Compare memory.
+ * We cannot use lib/string.c due to different CFLAGS values.
+ *
+ * @buf1:	first buffer
+ * @buf2:	second buffer
+ * @length:	number of bytes to compare
+ * @return:	0 if both buffers contain the same bytes
+ */
+int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
+
 /*
  * Reads an Unicode character from the input device.
  *
lib/efi_selftest/Makefile +7 -1
index 30f1960933..e446046e02 100644
@@ -15,12 +15,18 @@ CFLAGS_efi_selftest_events.o := $(CFLAGS_EFI)
 CFLAGS_REMOVE_efi_selftest_events.o := $(CFLAGS_NON_EFI)
 CFLAGS_efi_selftest_exitbootservices.o := $(CFLAGS_EFI)
 CFLAGS_REMOVE_efi_selftest_exitbootservices.o := $(CFLAGS_NON_EFI)
+CFLAGS_efi_selftest_snp.o := $(CFLAGS_EFI)
+CFLAGS_REMOVE_efi_selftest_snp.o := $(CFLAGS_NON_EFI)
 CFLAGS_efi_selftest_tpl.o := $(CFLAGS_EFI)
 CFLAGS_REMOVE_efi_selftest_tpl.o := $(CFLAGS_NON_EFI)
+CFLAGS_efi_selftest_util.o := $(CFLAGS_EFI)
+CFLAGS_REMOVE_efi_selftest_util.o := $(CFLAGS_NON_EFI)
 
 obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += \
 efi_selftest.o \
 efi_selftest_console.o \
 efi_selftest_events.o \
 efi_selftest_exitbootservices.o \
-efi_selftest_tpl.o
+efi_selftest_snp.o \
+efi_selftest_tpl.o \
+efi_selftest_util.o
lib/efi_selftest/efi_selftest_snp.c new file +424 -0

424 lines not on this page · raw message

lib/efi_selftest/efi_selftest_util.c new file +25 -0
new file mode 100644
index 0000000000..c9c295e2fb
@@ -0,0 +1,25 @@
+/*
+ * efi_selftest_util
+ *
+ * Copyright (c) 2017 Heinrich Schuchardt <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * Utility functions
+ */
+
+#include <efi_selftest.h>
+
+int efi_st_memcmp(const void *buf1, const void *buf2, size_t length)
+{
+	const u8 *pos1 = buf1;
+	const u8 *pos2 = buf2;
+
+	for (; length; --length) {
+		if (*pos1 != *pos2)
+			return pos1 - pos2;
+		++pos1;
+		++pos2;
+	}
+	return EFI_ST_SUCCESS;
+}
Signature · 1 line
2.14.1
#34 lore raw

PATCH v2 17/17 efi_loader: supply EFI network test

Quoted 26 lines · Heinrich Schuchardt

This patch provices an EFI application to check the correct function of the Simple Network Protocol implementation.

It sends a DHCP request and analyzes the DHCP offer.

Different error conditions including a 10s timeout are checked.

A successful execution will look like this:

=> bootefi nettest
Scanning disk ide.blk#0...
Found 1 disks
WARNING: Invalid device tree, expect boot to fail Network test
DHCP Discover
DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02) as broadcast message.
OK. The test was completed successfully.

---
v2
move efi_st_memcmp to efi_selftest_util.c The function can be reused for other tests.

Use constants for return values.

Quoted 8 lines
---
 include/efi_selftest.h               |  11 +
 lib/efi_selftest/Makefile            |   8 +-
 lib/efi_selftest/efi_selftest_snp.c  | 424 +++++++++++++++++++++++++++++++++++
 lib/efi_selftest/efi_selftest_util.c |  25 +++
 4 files changed, 467 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_selftest/efi_selftest_snp.c
 create mode 100644 lib/efi_selftest/efi_selftest_util.c
#35 lore raw

v2 cover efi_loader: Simple Network Protocol

In reply to Heinrich Schuchardt
Quoted 9 lines · Heinrich Schuchardt

This patch series focuses on
* correction of parameter types for boot services
* fixes for the SetMem and CopyMem boot services
* fixes for the simple network protocol implementation (SNP)
* a unit test for SetMem, CopyMem and the simple network protocol

The unit test broadcasts a DHCPDISCOVER messager over the network and receives the reply.

Quoted 8 lines

This patch series is based on
* efi-next tree
https://github.com/agraf/u-boot/tree/efi-next
* [PATCH 1/1] efi_selftest: enable CONFIG_CMD_BOOTEFI_SELFTEST
https://patchwork.ozlabs.org/patch/816412/
This patch enables the unit test on qemu-x86_defconfig
* [PATCH 1/1] efi_loader: provide function comments for boot services
https://patchwork.ozlabs.org/patch/817010/

Looks quite good to me. I've applied them (with the modification I suggested), running through tests and will push them to master if nobody (human or machine) objects within the next 1-2 days.

Alex

#36 lore raw

v2 cover efi_loader: Simple Network Protocol

Quoted 21 lines · Alexander Graf
Quoted 9 lines · Heinrich Schuchardt

This patch series focuses on
* correction of parameter types for boot services
* fixes for the SetMem and CopyMem boot services
* fixes for the simple network protocol implementation (SNP)
* a unit test for SetMem, CopyMem and the simple network protocol

The unit test broadcasts a DHCPDISCOVER messager over the network and receives the reply.

Quoted 8 lines

This patch series is based on
* efi-next tree
https://github.com/agraf/u-boot/tree/efi-next
* [PATCH 1/1] efi_selftest: enable CONFIG_CMD_BOOTEFI_SELFTEST
https://patchwork.ozlabs.org/patch/816412/
This patch enables the unit test on qemu-x86_defconfig
* [PATCH 1/1] efi_loader: provide function comments for boot services
https://patchwork.ozlabs.org/patch/817010/

Quoted 7 lines

Looks quite good to me. I've applied them (with the modification I suggested), running through tests and will push them to master if nobody (human or machine) objects within the next 1-2 days.

Alex

You moved setting is_signaled to efi_net_push.

181 static void efi_net_push(void *pkt, int len)
182 {
183 new_rx_packet = true;
184 wait_for_packet->is_signaled = true;
185 }

The code looks fine to me.

The selftest for the Simple Network Protocol correctly receives a DHCP packet.

Thank you.

I just sent you a fix for efi_st_memcmp:
[PATCH 1/1] efi_selftest: efi_st_memcmp return difference of bytes

Best regards

Heinrich