efi_loader: efi http and ipconfig drivers
Subsystems (3)
v4 cover efi_loader: efi http and ipconfig drivers
Add support for EFI_HTTP_PROTOCOL, EFI_HTTP_SERVICE_BINDING_PROTOCOL, and EFI_IP4_CONFIG2_PROTOCOL.
This series depends on the series 'wget: Expose wget to applications', also found at:
https://github.com/0n41rd4/u-boot/commits/http-driver-wget
The fist two patches of this series are not efi specific and have also been sent to the corresponding maintainers, but this series depends on them, so they are added here for redundancy. A branch with both series of patches, concatenated, is at:
https://github.com/0n41rd4/u-boot/commits/efi-http-driver
Adriano Cordova (12):
net: wget: let wget_with_dns work with dns disabled
efi_loader: device_path: add definition of
DEVICE_PATH_SUB_TYPE_MSG_IPV4
efi_loader: device_path: add efi_dp_from_ipv4
efi_api: add definitions for HTTP and IP4_CONFIG2 protocols
efi_loader: efi_net: add efi_net_set_addr, efi_net_get_addr
efi_loader: device_path: add support for HTTP device path
efi_loader: net: set EFI bootdevice device path to HTTP when loaded
from wget
efi_loader: net: add support to send http requests and parse http
headers
efi_loader: efi_net: add EFI_IP4_CONFIG2_PROTOCOL
efi_loader: efi_net: add EFI_HTTP_PROTOCOL
efi_selftest: add test for HTTP protocol
efi_selftest: add test for IPv4 Config2 protocol
Heinrich Schuchardt (2):
efi_loader: add IPv4() to device path to text protocol
lib: uuid: display HTTP and IPV4 Config II protocols
include/efi_api.h | 220 +++++++++ include/efi_loader.h | 42 ++ lib/efi_loader/Kconfig | 17 + lib/efi_loader/Makefile | 2 + lib/efi_loader/efi_device_path.c | 92 +++- lib/efi_loader/efi_device_path_to_text.c | 23 + lib/efi_loader/efi_http.c | 548 +++++++++++++++++++++++ lib/efi_loader/efi_ipconfig.c | 214 +++++++++ lib/efi_loader/efi_net.c | 354 ++++++++++++++- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_http.c | 315 +++++++++++++ lib/efi_selftest/efi_selftest_ipconfig.c | 170 +++++++ lib/uuid.c | 14 + net/lwip/wget.c | 1 + net/wget.c | 37 +- 15 files changed, 2029 insertions(+), 22 deletions(-) create mode 100644 lib/efi_loader/efi_http.c create mode 100644 lib/efi_loader/efi_ipconfig.c create mode 100644 lib/efi_selftest/efi_selftest_http.c create mode 100644 lib/efi_selftest/efi_selftest_ipconfig.c
Signature · 1 line
2.43.0
PATCH v4 1/14 net: wget: let wget_with_dns work with dns disabled
This was marked as TODO in the code:
-Enable use of wget_with_dns even if CMD_DNS is disabled if the given uri has the ip address for the http server. -Check for port in the uri when transforming to legacy wget syntax inside wget_with_dns.
-Move the check for CMD_DNS inside wget_with_dns.
---
v3:
Removed console output inside efi routine.
(no changes since v2)
net/wget.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
net/wget.c +21 -15
@@ -530,12 +530,10 @@ void wget_start(void)wget_send (TCP_SYN ,0 ,0 ,0 ); } -#if (IS_ENABLED (CONFIG_CMD_DNS ))int wget_with_dns (ulong dst_addr,char *uri) {int ret; -char *s, *host_name, *file_name, *str_copy; - +char *s, *host_name, *file_name, *str_copy, *port;/* * Download file using wget. *
@@ -550,24 +548,33 @@ int wget_with_dns(ulong dst_addr, char *uri) s = str_copy +strlen ("http://" ); host_name =strsep (&s,"/" );if (!s) { -log_err ("Error: invalied uri, no file path\n" ); ret = -EINVAL ; goto out; } file_name = s; -/* TODO: If the given uri has ip address for the http server, skip dns */ - net_dns_resolve = host_name; - net_dns_env_var ="httpserverip" ; -if (net_loop (DNS ) <0 ) { -log_err ("Error: dns lookup of %s failed, check setup\n" , net_dns_resolve); - ret = -EINVAL ; - goto out; - } - s =env_get ("httpserverip" ); -if (!s) { + port = host_name; + host_name =strsep (&port,":" ); + +if (string_to_ip (host_name).s_addr) { + s = host_name; + }else { +#if IS_ENABLED (CONFIG_CMD_DNS ) + net_dns_resolve = host_name; + net_dns_env_var ="httpserverip" ; +if (net_loop (DNS ) <0 ) { + ret = -EINVAL ; + goto out; + } + s =env_get ("httpserverip" ); +if (!s) { + ret = -EINVAL ; + goto out; + } +#else ret = -EINVAL ; goto out; +#endif }strlcpy (net_boot_file_name, s,sizeof (net_boot_file_name));
@@ -581,7 +588,6 @@ out:return ret <0 ? ret :0 ; } -#endif /** * wget_validate_uri() - validate the uri for wget
Signature · 1 line
2.43.0
Re: [PATCH v4 01/14] net: wget: let wget_with_dns work with dns disabled
Quoted 9 lines · Adriano Cordova
This was marked as TODO in the code:
-Enable use ofwget_with_dnseven ifCMD_DNSis disabled if the given uri has the ip address for the http server. -Check for port in the uri when transforming to legacy wget syntax insidewget_with_dns.
-Move the check forCMD_DNSinsidewget_with_dns.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4 are not described:
* drop console output
* avoid checking non-zero via '!= 0'.
Quoted 13 lines
v3:
Removed console output inside efi routine.(no changes since v2)
net/wget.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)net/wget.c +0
-0
net/wget.c void wget_start(void) · line 536
Quoted 10 lines
net/wget.c +1
-3@@ -530,12 +530,10 @@ void wget_start(void)wget_send (TCP_SYN ,0 ,0 ,0 ); } -#if (IS_ENABLED (CONFIG_CMD_DNS ))int wget_with_dns (ulong dst_addr,char *uri) {int ret; -char *s, *host_name, *file_name, *str_copy; - +char *s, *host_name, *file_name, *str_copy, *port;
nits:
Missing empty line.
Quoted 15 lines
net/wget.c +0
-3/* * Download file using wget. * @@ -550,24 +548,33 @@ int wget_with_dns(ulong dst_addr, char *uri) s = str_copy +strlen ("http://" ); host_name =strsep (&s,"/" );if (!s) { -log_err ("Error: invalied uri, no file path\n" ); ret = -EINVAL ; goto out; } file_name = s; -/* TODO: If the given uri has ip address for the http server, skip dns */ - net_dns_resolve = host_name;
net/wget.c int wget_with_dns(ulong dst_addr, char *uri) · line 557
Quoted 10 lines
net/wget.c +2
-8- net_dns_env_var ="httpserverip" ; -if (net_loop (DNS ) <0 ) { -log_err ("Error: dns lookup of %s failed, check setup\n" , net_dns_resolve); - ret = -EINVAL ; - goto out; - } - s =env_get ("httpserverip" ); -if (!s) { + port = host_name; + host_name =strsep (&port,":" );
RFC 1738 has:
login = [ user [ ":" password ] "@" ] hostport
hostport = host [ ":" port ]
So here variable port may point to the password. And host_name to the user name. We might check for '@' and bail out with an error code if it occurs.
You are determining the host port as a string, but I cannot see where you are ever using it.
In wget_send_stored() I see this line:
server_port = env_get_ulong("httpdstp", 10, SERVER_PORT) & 0xffff;
Maybe make server_port a static variable and set it here if variable port does not contain a number.
Best regards
Heinrich
Quoted 31 lines
net/wget.c +18
-1+ +if (string_to_ip (host_name).s_addr) { + s = host_name; + }else { +#if IS_ENABLED (CONFIG_CMD_DNS ) + net_dns_resolve = host_name; + net_dns_env_var ="httpserverip" ; +if (net_loop (DNS ) <0 ) { + ret = -EINVAL ; + goto out; + } + s =env_get ("httpserverip" ); +if (!s) { + ret = -EINVAL ; + goto out; + } +#else ret = -EINVAL ; goto out; +#endif }strlcpy (net_boot_file_name, s,sizeof (net_boot_file_name));@@ -581,7 +588,6 @@ out:return ret <0 ? ret :0 ; } -#endif /** * wget_validate_uri() - validate the uri for wget
Re: [PATCH v4 01/14] net: wget: let wget_with_dns work with dns disabled
Quoted 85 lines · Heinrich Schuchardt
Quoted 9 lines · Adriano Cordova
This was marked as TODO in the code:
-Enable use ofwget_with_dnseven ifCMD_DNSis disabled if the given uri has the ip address for the http server. -Check for port in the uri when transforming to legacy wget syntax insidewget_with_dns.
-Move the check forCMD_DNSinsidewget_with_dns.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4 are not described:
* drop console output
* avoid checking non-zero via '!= 0'.Quoted 13 lines
v3:
Removed console output inside efi routine.(no changes since v2)
net/wget.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)net/wget.c +0
-0net/wget.c void wget_start(void) · line 536
Quoted 10 lines
net/wget.c +1
-3@@ -530,12 +530,10 @@ void wget_start(void)wget_send (TCP_SYN ,0 ,0 ,0 ); } -#if (IS_ENABLED (CONFIG_CMD_DNS ))int wget_with_dns (ulong dst_addr,char *uri) {int ret; -char *s, *host_name, *file_name, *str_copy; - +char *s, *host_name, *file_name, *str_copy, *port;nits:
Missing empty line.Quoted 4 lines
net/wget.c +0
-0/* * Download file using wget. * net/wget.c int wget_with_dns(ulong dst_addr, char *uri) · line 559
Quoted 10 lines
net/wget.c +0
-2@@ -550,24 +548,33 @@ int wget_with_dns(ulong dst_addr, char *uri) s = str_copy +strlen ("http://" ); host_name =strsep (&s,"/" );if (!s) { -log_err ("Error: invalied uri, no file path\n" ); ret = -EINVAL ; goto out; } file_name = s; -/* TODO: If the given uri has ip address for the http server, skip dns */
net/wget.c int wget_with_dns(ulong dst_addr, char *uri)
Quoted 4 lines
net/wget.c +0
-4- net_dns_resolve = host_name; - net_dns_env_var ="httpserverip" ; -if (net_loop (DNS ) <0 ) { - log_err("Error: dns lookup of %s failed, check setup\n",
net_dns_resolve);net/wget.c int wget_with_dns(ulong dst_addr, char *uri) · line 557
Quoted 7 lines
net/wget.c +2
-5- ret = -EINVAL ; - goto out; - } - s =env_get ("httpserverip" ); -if (!s) { + port = host_name; + host_name =strsep (&port,":" );RFC 1738 has:
login = [ user [ ":" password ] "@" ] hostport
hostport = host [ ":" port ]So here variable port may point to the password. And
host_nameto the user name. We might check for '@' and bail out with an error code if it occurs.You are determining the host port as a string, but I cannot see where you are ever using it.
In
wget_send_stored()I see this line:
Quoted 9 lines
server_port=env_get_ulong("httpdstp", 10, SERVER_PORT)&0xffff;Maybe make
server_porta static variable and set it here if variable port does not contain a number.Best regards
Heinrich
The current documentation and implementation of wget is not compliant with RFC 1738 and only supports ip:path. I will erase the port and leave the wget parsing
as it is documented (ip:path). I think reworking the legacy wget parsing to be RFC 1738
compliant can be done in a separate patch.
Quoted 34 lines
Quoted 32 lines
net/wget.c +18
-1+ +if (string_to_ip (host_name).s_addr) { + s = host_name; + }else { +#if IS_ENABLED (CONFIG_CMD_DNS ) + net_dns_resolve = host_name; + net_dns_env_var ="httpserverip" ; +if (net_loop (DNS ) <0 ) { + ret = -EINVAL ; + goto out; + } + s =env_get ("httpserverip" ); +if (!s) { + ret = -EINVAL ; + goto out; + } +#else ret = -EINVAL ; goto out; +#endif }strlcpy (net_boot_file_name, s,sizeof (net_boot_file_name));@@ -581,7 +588,6 @@ out:return ret <0 ? ret :0 ; } -#endif /** * wget_validate_uri() - validate the uri for wget
Re: [PATCH v4 01/14] net: wget: let wget_with_dns work with dns disabled
In reply to Adriano CordovaQuoted 2 lines · Adriano Cordova
This was marked as TODO in the code:
-Enable use ofwget_with_dnseven ifCMD_DNSis disabled if
Then I believe the function should be renamed. _with_dns is misleading.
Quoted 45 lines
the given uri has the ip address for the http server. -Check for port in the uri when transforming to legacy wget syntax inside
wget_with_dns.
-Move the check forCMD_DNSinsidewget_with_dns.Signed-off-by Adriano Cordova <[email protected]>---
v3:
Removed console output inside efi routine.(no changes since v2)
net/wget.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)net/wget.c +1
-6@@ -530,12 +530,10 @@ void wget_start(void)wget_send (TCP_SYN ,0 ,0 ,0 ); } -#if (IS_ENABLED (CONFIG_CMD_DNS ))int wget_with_dns (ulong dst_addr,char *uri) {int ret; -char *s, *host_name, *file_name, *str_copy; - +char *s, *host_name, *file_name, *str_copy, *port;/* * Download file using wget. * @@ -550,24 +548,33 @@ int wget_with_dns(ulong dst_addr, char *uri) s = str_copy +strlen ("http://" ); host_name =strsep (&s,"/" );if (!s) { -log_err ("Error: invalied uri, no file path\n" ); ret = -EINVAL ; goto out; } file_name = s; -/* TODO: If the given uri has ip address for the http server, skip dns */ - net_dns_resolve = host_name;
net/wget.c int wget_with_dns(ulong dst_addr, char *uri) · line 557
Quoted 10 lines
net/wget.c +2
-8- net_dns_env_var ="httpserverip" ; -if (net_loop (DNS ) <0 ) { -log_err ("Error: dns lookup of %s failed, check setup\n" , net_dns_resolve); - ret = -EINVAL ; - goto out; - } - s =env_get ("httpserverip" ); -if (!s) { + port = host_name; + host_name =strsep (&port,":" );
You should do something with the port (or reject URLs with a non-default port).
Quoted 24 lines
net/wget.c +18
-0+ +if (string_to_ip (host_name).s_addr) { + s = host_name; + }else { +#if IS_ENABLED (CONFIG_CMD_DNS ) + net_dns_resolve = host_name; + net_dns_env_var ="httpserverip" ; +if (net_loop (DNS ) <0 ) { + ret = -EINVAL ; + goto out; + } + s =env_get ("httpserverip" ); +if (!s) { + ret = -EINVAL ; + goto out; + } +#else ret = -EINVAL ; goto out; +#endif }strlcpy (net_boot_file_name, s,sizeof (net_boot_file_name));
net/wget.c out: · line 593
Quoted 7 lines
net/wget.c +0
-1@@ -581,7 +588,6 @@ out:return ret <0 ? ret :0 ; } -#endif /** * wget_validate_uri() - validate the uri for wget
Thanks,
Signature · 1 line
Jerome
PATCH v4 2/14 efi_loader: device_path: add definition of DEVICE_PATH_SUB_TYPE_MSG_IPV4
In reply to Adriano CordovaAdd definition for DEVICE_PATH_SUB_TYPE_MSG_IPV4 device path subtype.
---
(no changes since v3)
Changes in v3:
- Removed alignment in struct efi_ipv4_address
include/efi_api.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/efi_api.h +17 -0
@@ -616,6 +616,7 @@ struct efi_device_path_acpi_path {# define DEVICE_PATH_SUB_TYPE_MSG_SCSI 0x02# define DEVICE_PATH_SUB_TYPE_MSG_USB 0x05# define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR 0x0b +# define DEVICE_PATH_SUB_TYPE_MSG_IPV4 0x0c# define DEVICE_PATH_SUB_TYPE_MSG_UART 0x0e# define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS 0x0f# define DEVICE_PATH_SUB_TYPE_MSG_USB_WWI 0x10
@@ -691,6 +692,22 @@ struct efi_device_path_uri {u8 uri[]; } __packed; +struct efi_ipv4_address { +u8 ip_addr[4 ]; +}; + +struct efi_device_path_ipv4 { +struct efi_device_path dp; +struct efi_ipv4_address local_ip_address; +struct efi_ipv4_address remote_ip_address; +u16 local_port; +u16 remote_port; +u16 protocol; +u8 static_ip_address; +struct efi_ipv4_address gateway_ip_address; +struct efi_ipv4_address subnet_mask; +} __packed; +#define DEVICE_PATH_TYPE_MEDIA_DEVICE 0x04# define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH 0x01# define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02
Signature · 1 line
2.43.0
PATCH v4 3/14 efi_loader: device_path: add efi_dp_from_ipv4
In reply to Adriano CordovaAdd efi_dp_from_ipv4 to form a device path from an ipv4 address.
---
Changes in v4:
- Fixed memcpy mistake
Changes in v3:
- Removed some unnecessary void* casts.
- Changed sizeof(struct efi_device_path_ipv4) to sizeof(*ipv4dp) in efi_dp_from_ipv4.
lib/efi_loader/efi_device_path.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
lib/efi_loader/efi_device_path.c +38 -0
@@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void)return start; } +struct efi_device_path *efi_dp_from_ipv4 (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *srv) +{ +struct efi_device_path *dp1, *dp2; +efi_uintn_t ipv4dp_len; +struct efi_device_path_ipv4 *ipv4dp; +char *pos; + + ipv4dp_len =sizeof (*ipv4dp); + ipv4dp =efi_alloc (ipv4dp_len +sizeof (END )); +if (!ipv4dp) { +log_err ("Out of memory\n" ); +return NULL ; + } + + ipv4dp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ; + ipv4dp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_IPV4 ; + ipv4dp->dp.length = ipv4dp_len; + ipv4dp->protocol =6 ; +if (ip) +memcpy (&ipv4dp->local_ip_address, ip,sizeof (*ip)); +if (mask) +memcpy (&ipv4dp->subnet_mask, mask,sizeof (*mask)); +if (srv) +memcpy (&ipv4dp->remote_ip_address, srv,sizeof (*srv)); + pos = (void *)(uintptr_t )ipv4dp + ipv4dp_len; +memcpy (pos, &END ,sizeof (END )); + + dp1 =efi_dp_from_eth (); + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)ipv4dp,0 ); + +efi_free_pool (ipv4dp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Signature · 1 line
2.43.0
Re: [PATCH v4 03/14] efi_loader: device_path: add efi_dp_from_ipv4
Quoted 21 lines · Adriano Cordova
Add
efi_dp_from_ipv4to form a device path from an ipv4 address.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Fixed memcpy mistakeChanges in v3:
- Removed some unnecessary void* casts.
- Changedsizeof(struct efi_device_path_ipv4)tosizeof(*ipv4dp)inefi_dp_from_ipv4.lib/efi_loader/efi_device_path.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/efi_loader/efi_device_path.c +0
-0
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 976
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0@@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void)return start; }
A function description is missing.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 987
Quoted 11 lines
lib/efi_loader/efi_device_path.c +11
-0+struct efi_device_path *efi_dp_from_ipv4 (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *srv) +{ +struct efi_device_path *dp1, *dp2; +efi_uintn_t ipv4dp_len; +struct efi_device_path_ipv4 *ipv4dp; +char *pos; + + ipv4dp_len =sizeof (*ipv4dp); + ipv4dp =efi_alloc (ipv4dp_len +sizeof (END ));
ipv4dp is a small structure and is freed below. Allocating it on the stack would reduce the code size.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 989
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+if (!ipv4dp) { +log_err ("Out of memory\n" );
Writing messages inside a protocol implementation should be avoided.
Quoted 4 lines
lib/efi_loader/efi_device_path.c +4
-0+return NULL ; + } + + ipv4dp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ;
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 1003
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+ ipv4dp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_IPV4 ; + ipv4dp->dp.length = ipv4dp_len; + ipv4dp->protocol =6 ; +if (ip) +memcpy (&ipv4dp->local_ip_address, ip,sizeof (*ip)); +if (mask) +memcpy (&ipv4dp->subnet_mask, mask,sizeof (*mask)); +if (srv) +memcpy (&ipv4dp->remote_ip_address, srv,sizeof (*srv)); + pos = (void *)(uintptr_t )ipv4dp + ipv4dp_len;
Here you
1 - convert ipv4dp to uintptr_t
2 - convert the uintptr_t value to void * 3 - add an offset to the void * value
In the C standard adding an offset to a void * value results in undefined behavior. Unfortunately U-Boot code uses it a lot.
pos = (char *)ipv4dp + ipv4dp_len;
is all it takes to have a defined behavior here.
Best regards
Heinrich
Quoted 14 lines
lib/efi_loader/efi_device_path.c +11
-0+memcpy (pos, &END ,sizeof (END )); + + dp1 =efi_dp_from_eth (); + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)ipv4dp,0 ); + +efi_free_pool (ipv4dp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Re: [PATCH v4 03/14] efi_loader: device_path: add efi_dp_from_ipv4
Quoted 64 lines · Heinrich Schuchardt
Quoted 21 lines · Adriano Cordova
Add
efi_dp_from_ipv4to form a device path from an ipv4 address.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Fixed memcpy mistakeChanges in v3:
- Removed some unnecessary void* casts.
- Changedsizeof(struct efi_device_path_ipv4)tosizeof(*ipv4dp)inefi_dp_from_ipv4.lib/efi_loader/efi_device_path.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/efi_loader/efi_device_path.c +0
-0lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 976
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0@@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void)return start; }A function description is missing.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 987
Quoted 11 lines
lib/efi_loader/efi_device_path.c +11
-0+struct efi_device_path *efi_dp_from_ipv4 (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *srv) +{ +struct efi_device_path *dp1, *dp2; +efi_uintn_t ipv4dp_len; +struct efi_device_path_ipv4 *ipv4dp; +char *pos; + + ipv4dp_len =sizeof (*ipv4dp); + ipv4dp =efi_alloc (ipv4dp_len +sizeof (END ));ipv4dp is a small structure and is freed below. Allocating it on the stack would reduce the code size.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 989
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+if (!ipv4dp) { +log_err ("Out of memory\n" );Writing messages inside a protocol implementation should be avoided.
Quoted 4 lines
lib/efi_loader/efi_device_path.c +4
-0+return NULL ; + } + + ipv4dp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ;lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 1003
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+ ipv4dp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_IPV4 ; + ipv4dp->dp.length = ipv4dp_len; + ipv4dp->protocol =6 ; +if (ip) +memcpy (&ipv4dp->local_ip_address, ip,sizeof (*ip)); +if (mask) +memcpy (&ipv4dp->subnet_mask, mask,sizeof (*mask)); +if (srv) +memcpy (&ipv4dp->remote_ip_address, srv,sizeof (*srv)); + pos = (void *)(uintptr_t )ipv4dp + ipv4dp_len;
Quoted 8 lines
Here you
1 - convert ipv4dp to
uintptr_t
2 - convert theuintptr_tvalue to void *
3 - add an offset to the void * valueIn the C standard adding an offset to a void * value results in undefined behavior. Unfortunately U-Boot code uses it a lot.
It's a known support gcc extension that treats void* similar to char*. Do you think it's worth changing all of the callsites we have?
Thanks
/Ilias
Quoted 24 lines
pos = (char *)ipv4dp +
ipv4dp_len;is all it takes to have a defined behavior here.
Best regards
Heinrich
Quoted 14 lines
lib/efi_loader/efi_device_path.c +11
-0+memcpy (pos, &END ,sizeof (END )); + + dp1 =efi_dp_from_eth (); + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)ipv4dp,0 ); + +efi_free_pool (ipv4dp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Re: [PATCH v4 03/14] efi_loader: device_path: add efi_dp_from_ipv4
Quoted 72 lines · Ilias Apalodimas
Quoted 70 lines · Heinrich Schuchardt
Quoted 21 lines · Adriano Cordova
Add
efi_dp_from_ipv4to form a device path from an ipv4 address.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Fixed memcpy mistakeChanges in v3:
- Removed some unnecessary void* casts.
- Changedsizeof(struct efi_device_path_ipv4)tosizeof(*ipv4dp)inefi_dp_from_ipv4.lib/efi_loader/efi_device_path.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/efi_loader/efi_device_path.c +0
-0lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 976
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0@@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void)return start; }A function description is missing.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 987
Quoted 11 lines
lib/efi_loader/efi_device_path.c +11
-0+struct efi_device_path *efi_dp_from_ipv4 (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *srv) +{ +struct efi_device_path *dp1, *dp2; +efi_uintn_t ipv4dp_len; +struct efi_device_path_ipv4 *ipv4dp; +char *pos; + + ipv4dp_len =sizeof (*ipv4dp); + ipv4dp =efi_alloc (ipv4dp_len +sizeof (END ));ipv4dp is a small structure and is freed below. Allocating it on the stack would reduce the code size.
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 989
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+if (!ipv4dp) { +log_err ("Out of memory\n" );Writing messages inside a protocol implementation should be avoided.
Quoted 4 lines
lib/efi_loader/efi_device_path.c +4
-0+return NULL ; + } + + ipv4dp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ;lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 1003
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+ ipv4dp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_IPV4 ; + ipv4dp->dp.length = ipv4dp_len; + ipv4dp->protocol =6 ; +if (ip) +memcpy (&ipv4dp->local_ip_address, ip,sizeof (*ip)); +if (mask) +memcpy (&ipv4dp->subnet_mask, mask,sizeof (*mask)); +if (srv) +memcpy (&ipv4dp->remote_ip_address, srv,sizeof (*srv)); + pos = (void *)(uintptr_t )ipv4dp + ipv4dp_len;Here you
1 - convert ipv4dp to
uintptr_t
2 - convert theuintptr_tvalue to void *
3 - add an offset to the void * value
Quoted 5 lines
Quoted 2 lines
In the C standard adding an offset to a void * value results in undefined behavior. Unfortunately U-Boot code uses it a lot.
It's a known support gcc extension that treats void* similar to char*. Do you think it's worth changing all of the call sites we have?
No, I don't request this. But as pos is already char*, we should not use void* here.
Best regards
Heinrich
Quoted 24 lines
Quoted 24 lines
pos = (char *)ipv4dp +
ipv4dp_len;is all it takes to have a defined behavior here.
Best regards
Heinrich
Quoted 14 lines
lib/efi_loader/efi_device_path.c +11
-0+memcpy (pos, &END ,sizeof (END )); + + dp1 =efi_dp_from_eth (); + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)ipv4dp,0 ); + +efi_free_pool (ipv4dp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Re: [PATCH v4 03/14] efi_loader: device_path: add efi_dp_from_ipv4
In reply to Heinrich SchuchardtQuoted 30 lines · Heinrich Schuchardt
Quoted 13 lines · Adriano Cordova
Add
efi_dp_from_ipv4to form a device path from an ipv4 address.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Fixed memcpy mistakeChanges in v3:
- Removed some unnecessary void* casts.
- Changedsizeof(struct efi_device_path_ipv4)tosizeof(*ipv4dp)inefi_dp_from_ipv4.Review
Quoted 4 lines
lib/efi_loader/efi_device_path.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)(quoted diff) +0
-0
b/lib/efi_loader/efi_device_path.clib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused
Quoted 4 lines
index
ee387e1dfd..cdeea4791f100644lib/efi_loader/efi_device_path.c +0
-0@@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused
*efi_dp_from_eth(void)lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 976
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0return start; }A function description is missing.
Quoted 14 lines
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 987
Quoted 11 lines
lib/efi_loader/efi_device_path.c +11
-0+struct efi_device_path *efi_dp_from_ipv4 (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *srv) +{ +struct efi_device_path *dp1, *dp2; +efi_uintn_t ipv4dp_len; +struct efi_device_path_ipv4 *ipv4dp; +char *pos; + + ipv4dp_len =sizeof (*ipv4dp); + ipv4dp =efi_alloc (ipv4dp_len +sizeof (END ));ipv4dp is a small structure and is freed below. Allocating it on the stack would reduce the code size.
But as it is a device path it has to be allocated contiguously to the END node, see the next lines. It is then passed to efi_dp_concat where this is important.
Quoted 34 lines
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 989
Quoted 7 lines
lib/efi_loader/efi_device_path.c +2
-0+if (!ipv4dp) { +log_err ("Out of memory\n" );Writing messages inside a protocol implementation should be avoided.
Quoted 4 lines
lib/efi_loader/efi_device_path.c +4
-0+return NULL ; + } + + ipv4dp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ;lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 1003
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+ ipv4dp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_IPV4 ; + ipv4dp->dp.length = ipv4dp_len; + ipv4dp->protocol =6 ; +if (ip) +memcpy (&ipv4dp->local_ip_address, ip,sizeof (*ip)); +if (mask) +memcpy (&ipv4dp->subnet_mask, mask,sizeof (*mask)); +if (srv) +memcpy (&ipv4dp->remote_ip_address, srv,sizeof (*srv)); + pos = (void *)(uintptr_t )ipv4dp + ipv4dp_len;Here you
1 - convert ipv4dp to
uintptr_t
2 - convert theuintptr_tvalue to void *
3 - add an offset to the void * valueIn the C standard adding an offset to a void * value results in undefined behavior. Unfortunately U-Boot code uses it a lot.
Quoted 8 lines
pos = (char *)ipv4dp +
ipv4dp_len;is all it takes to have a defined behavior here.
Best regards
Heinrich
It was originally a char *, I will change it back
Quoted 5 lines
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void)
Quoted 4 lines
lib/efi_loader/efi_device_path.c +4
-0+memcpy (pos, &END ,sizeof (END )); + + dp1 =efi_dp_from_eth (); + dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)ipv4dp,0);
Quoted 12 lines
lib/efi_loader/efi_device_path.c struct efi_device_path __maybe_unused *efi_dp_from_eth(void) · line 1017
Quoted 10 lines
lib/efi_loader/efi_device_path.c +7
-0+ +efi_free_pool (ipv4dp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Best,
Adriano
Re: [PATCH v4 03/14] efi_loader: device_path: add efi_dp_from_ipv4
Quoted 53 lines · Adriano Córdova
El mar, 19 nov 2024 a las 6:50, Heinrich Schuchardt (<[email protected] <mailto:[email protected]>>) escribió:
On 18.11.24 22:08, Adriano Cordova wrote: > Add efi_dp_from_ipv4 to form a device path from an ipv4 address. > > Signed-off-by: Adriano Cordova <[email protected] <mailto:[email protected]>> > --- > > Changes in v4: > - Fixed memcpy mistake > > Changes in v3: > - Removed some unnecessary void* casts. > - Changed sizeof(struct efi_device_path_ipv4) to sizeof(*ipv4dp) > in efi_dp_from_ipv4. > > lib/efi_loader/efi_device_path.c | 38 +++++++++++++++++++++++++ +++++++ > 1 file changed, 38 insertions(+) > > diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/ efi_device_path.c > index ee387e1dfd..cdeea4791f 100644 > --- a/lib/efi_loader/efi_device_path.c > +++ b/lib/efi_loader/efi_device_path.c > @@ -974,6 +974,44 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void) > return start; > } > A function description is missing. > +struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, > + struct efi_ipv4_address *mask, > + struct efi_ipv4_address *srv) > +{ > + struct efi_device_path *dp1, *dp2; > + efi_uintn_t ipv4dp_len; > + struct efi_device_path_ipv4 *ipv4dp; > + char *pos; > + > + ipv4dp_len = sizeof(*ipv4dp); > + ipv4dp = efi_alloc(ipv4dp_len + sizeof(END)); ipv4dp is a small structure and is freed below. Allocating it on the stack would reduce the code size.
Quoted 3 lines
But as it is a device path it has to be allocated contiguously to the END node, see the next lines. It is then passed to
efi_dp_concatwhere this is important.
struct {
struct efi_device_path_ipv4 ipv4dp;
struct efi_device_path end;
} dp;should give you a variable of adequate size.
Best regards
Heinrich
Quoted 61 lines
> + if (!ipv4dp) { > + log_err("Out of memory\n"); Writing messages inside a protocol implementation should be avoided. > + return NULL; > + } > + > + ipv4dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; > + ipv4dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_IPV4; > + ipv4dp->dp.length = ipv4dp_len; > + ipv4dp->protocol = 6; > + if (ip) > + memcpy(&ipv4dp->local_ip_address, ip, sizeof(*ip)); > + if (mask) > + memcpy(&ipv4dp->subnet_mask, mask, sizeof(*mask)); > + if (srv) > + memcpy(&ipv4dp->remote_ip_address, srv, sizeof(*srv)); > + pos = (void *)(uintptr_t)ipv4dp + ipv4dp_len; Here you 1 - convert ipv4dp to uintptr_t 2 - convert the uintptr_t value to void * 3 - add an offset to the void * value In the C standard adding an offset to a void * value results in undefined behavior. Unfortunately U-Boot code uses it a lot. pos = (char *)ipv4dp + ipv4dp_len; is all it takes to have a defined behavior here. Best regards HeinrichIt was originally a char *, I will change it back
> + memcpy(pos, &END, sizeof(END)); > + > + dp1 = efi_dp_from_eth(); > + dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)ipv4dp, 0); > + > + efi_free_pool(ipv4dp); > + efi_free_pool(dp1); > + > + return dp2; > +} > + > /* Construct a device-path for memory-mapped image */ > struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, > uint64_t start_address,Best,
Adriano
PATCH v4 4/14 efi_loader: add IPv4() to device path to text protocol
In reply to Adriano CordovaFrom: Heinrich Schuchardt <[email protected]>
Implement Ipv4() node support in the device path to text protocol.
---
(no changes since v2)
lib/efi_loader/efi_device_path_to_text.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
lib/efi_loader/efi_device_path_to_text.c +23 -0
@@ -8,6 +8,7 @@#include <blk.h> #include <efi_loader.h> #include <malloc.h> +#include <net.h> #define MAC_OUTPUT_LEN 22#define UNKNOWN_OUTPUT_LEN 23
@@ -170,6 +171,28 @@ static char *dp_msging(char *s, struct efi_device_path *dp)break ; } +case DEVICE_PATH_SUB_TYPE_MSG_IPV4 : { +struct efi_device_path_ipv4 *idp = + (struct efi_device_path_ipv4 *)dp; + + s +=sprintf (s,"IPv4(%pI4," , &idp->remote_ip_address); +switch (idp->protocol) { +case IPPROTO_TCP : + s +=sprintf (s,"TCP," ); +case IPPROTO_UDP : + s +=sprintf (s,"UDP," ); +default : + s +=sprintf (s,"0x%x," , idp->protocol); + } + s +=sprintf (s, idp->static_ip_address ?"Static" :"DHCP" ); + s +=sprintf (s,",%pI4" , &idp->local_ip_address); +if (idp->dp.length ==sizeof (struct efi_device_path_ipv4 )) + s +=sprintf (s,",%pI4,%pI4" , &idp->gateway_ip_address, + &idp->subnet_mask); + s +=sprintf (s,")" ); + +break ; + }case DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS : {struct efi_device_path_usb_class *ucdp = (struct efi_device_path_usb_class *)dp;
Signature · 1 line
2.43.0
Re: [PATCH v4 04/14] efi_loader: add IPv4() to device path to text protocol
Quoted 56 lines · Adriano Cordova
From: Heinrich Schuchardt <[email protected]>
Implement
Ipv4()node support in the device path to text protocol.Signed-off-by Heinrich Schuchardt <[email protected]>Signed-off-by Adriano Cordova <[email protected]>---
(no changes since v2)
lib/efi_loader/efi_device_path_to_text.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)lib/efi_loader/efi_device_path_to_text.c +23
-1@@ -8,6 +8,7 @@#include <blk.h> #include <efi_loader.h> #include <malloc.h> +#include <net.h> #define MAC_OUTPUT_LEN 22#define UNKNOWN_OUTPUT_LEN 23@@ -170,6 +171,28 @@ static char *dp_msging(char *s, struct efi_device_path *dp)break ; } +case DEVICE_PATH_SUB_TYPE_MSG_IPV4 : { +struct efi_device_path_ipv4 *idp = + (struct efi_device_path_ipv4 *)dp; + + s +=sprintf (s,"IPv4(%pI4," , &idp->remote_ip_address); +switch (idp->protocol) { +case IPPROTO_TCP : + s +=sprintf (s,"TCP," ); +case IPPROTO_UDP : + s +=sprintf (s,"UDP," ); +default : + s +=sprintf (s,"0x%x," , idp->protocol); + } + s +=sprintf (s, idp->static_ip_address ?"Static" :"DHCP" ); + s +=sprintf (s,",%pI4" , &idp->local_ip_address); +if (idp->dp.length ==sizeof (struct efi_device_path_ipv4 )) + s +=sprintf (s,",%pI4,%pI4" , &idp->gateway_ip_address, + &idp->subnet_mask); + s +=sprintf (s,")" ); + +break ; + }case DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS : {struct efi_device_path_usb_class *ucdp = (struct efi_device_path_usb_class *)dp; --
Quoted 2 lines
2.43.0
might overflow but that's w ider problem of all our device path functions
PATCH v4 5/14 efi_api: add definitions for HTTP and IP4_CONFIG2 protocols
In reply to Adriano CordovaAdd EFI definitions for EFI_IP4_CONFIG2_PROTOCOL, EFI_HTTP_SERVICE_BINDING_PROTOCOL, and EFI_HTTP_PROTOCOL. According to UEFI spec 2.10.
---
(no changes since v2)
include/efi_api.h | 203 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+)
include/efi_api.h +203 -0
@@ -1725,6 +1725,209 @@ struct efi_pxe_base_code_protocol {struct efi_pxe_mode *mode; }; +#define EFI_IP4_CONFIG2_PROTOCOL_GUID \ + EFI_GUID(0x5b446ed1, 0xe30b, 0x4faa, \ + 0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80) + +enum efi_ip4_config2_data_type { +EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO , +EFI_IP4_CONFIG2_DATA_TYPE_POLICY , +EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS , +EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY , +EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER , +EFI_IP4_CONFIG2_DATA_TYPE_MAXIMUM , +}; + +struct efi_ip4_config2_protocol { + efi_status_t (EFIAPI * set_data)(struct efi_ip4_config2_protocol *this, + enum efi_ip4_config2_data_type data_type, + efi_uintn_t data_size, + void *data); + efi_status_t (EFIAPI * get_data)(struct efi_ip4_config2_protocol *this, + enum efi_ip4_config2_data_type data_type, + efi_uintn_t *data_size, + void *data); + efi_status_t (EFIAPI * register_data_notify)(struct efi_ip4_config2_protocol *this, + enum efi_ip4_config2_data_type data_type, + struct efi_event *event); + efi_status_t (EFIAPI * unregister_data_notify)(struct efi_ip4_config2_protocol *this, + enum efi_ip4_config2_data_type data_type, + struct efi_event *event); +}; + +struct efi_ip4_route_table { +struct efi_ipv4_address subnet_address; +struct efi_ipv4_address subnet_mask; +struct efi_ipv4_address gateway_address; +}; + +#define EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE 32 + +struct efi_ip4_config2_interface_info { +u16 name[EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE ]; +u8 if_type; +u32 hw_address_size; +struct efi_mac_address hw_address; +struct efi_ipv4_address station_address; +struct efi_ipv4_address subnet_mask; +u32 route_table_size; +struct efi_ip4_route_table *route_table; +}; + +enum efi_ip4_config2_policy { +EFI_IP4_CONFIG2_POLICY_STATIC , +EFI_IP4_CONFIG2_POLICY_DHCP , +EFI_IP4_CONFIG2_POLICY_MAX +}; + +struct efi_ip4_config2_manual_address { +struct efi_ipv4_address address; +struct efi_ipv4_address subnet_mask; +}; + +#define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \ + EFI_GUID(0xbdc8e6af, 0xd9bc, 0x4379, \ + 0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c) + +struct efi_service_binding_protocol { + efi_status_t (EFIAPI * create_child)(struct efi_service_binding_protocol *this, + efi_handle_t *child_handle); + efi_status_t (EFIAPI * destroy_child)(struct efi_service_binding_protocol *this, + efi_handle_t child_handle); +}; + +#define EFI_HTTP_PROTOCOL_GUID \ + EFI_GUID(0x7A59B29B, 0x910B, 0x4171, \ + 0x82, 0x42, 0xA8, 0x5A, 0x0D, 0xF2, 0x5B, 0x5B) + +enum efi_http_version { +HTTPVERSION10 , +HTTPVERSION11 , +HTTPVERSIONUNSUPPORTED +}; + +struct efi_httpv4_access_point { +bool use_default_address; +struct efi_ipv4_address local_address; +struct efi_ipv4_address local_subnet; +u16 local_port; +}; + +union efi_http_access_point { +struct efi_httpv4_access_point *ipv4_node; +struct efi_httpv6_access_point *ipv6_node; +}; + +struct efi_http_config_data { +enum efi_http_version http_version; +u32 timeout; +bool is_ipv6; +union efi_http_access_point access_point; +}; + +enum efi_http_method { +HTTP_METHOD_GET , +HTTP_METHOD_POST , +HTTP_METHOD_PATCH , +HTTP_METHOD_OPTIONS , +HTTP_METHOD_CONNECT , +HTTP_METHOD_HEAD , +HTTP_METHOD_PUT , +HTTP_METHOD_DELETE , +HTTP_METHOD_TRACE , +HTTP_METHOD_MAX +}; + +enum efi_http_status_code { +HTTP_STATUS_UNSUPPORTED_STATUS =0 , +HTTP_STATUS_100_CONTINUE , +HTTP_STATUS_101_SWITCHING_PROTOCOLS , +HTTP_STATUS_200_OK , +HTTP_STATUS_201_CREATED , +HTTP_STATUS_202_ACCEPTED , +HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION , +HTTP_STATUS_204_NO_CONTENT , +HTTP_STATUS_205_RESET_CONTENT , +HTTP_STATUS_206_PARTIAL_CONTENT , +HTTP_STATUS_300_MULTIPLE_CHOICES , +HTTP_STATUS_301_MOVED_PERMANENTLY , +HTTP_STATUS_302_FOUND , +HTTP_STATUS_303_SEE_OTHER , +HTTP_STATUS_304_NOT_MODIFIED , +HTTP_STATUS_305_USE_PROXY , +HTTP_STATUS_307_TEMPORARY_REDIRECT , +HTTP_STATUS_400_BAD_REQUEST , +HTTP_STATUS_401_UNAUTHORIZED , +HTTP_STATUS_402_PAYMENT_REQUIRED , +HTTP_STATUS_403_FORBIDDEN , +HTTP_STATUS_404_NOT_FOUND , +HTTP_STATUS_405_METHOD_NOT_ALLOWED , +HTTP_STATUS_406_NOT_ACCEPTABLE , +HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED , +HTTP_STATUS_408_REQUEST_TIME_OUT , +HTTP_STATUS_409_CONFLICT , +HTTP_STATUS_410_GONE , +HTTP_STATUS_411_LENGTH_REQUIRED , +HTTP_STATUS_412_PRECONDITION_FAILED , +HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE , +HTTP_STATUS_414_REQUEST_URI_TOO_LARGE , +HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE , +HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED , +HTTP_STATUS_417_EXPECTATION_FAILED , +HTTP_STATUS_500_INTERNAL_SERVER_ERROR , +HTTP_STATUS_501_NOT_IMPLEMENTED , +HTTP_STATUS_502_BAD_GATEWAY , +HTTP_STATUS_503_SERVICE_UNAVAILABLE , +HTTP_STATUS_504_GATEWAY_TIME_OUT , +HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED , +HTTP_STATUS_308_PERMANENT_REDIRECT +}; + +struct efi_http_request_data { +enum efi_http_method method; +u16 *url; +}; + +struct efi_http_response_data { +enum efi_http_status_code status_code; +}; + +struct efi_http_header { +char *field_name; +char *field_value; +}; + +struct efi_http_message { +union { +struct efi_http_request_data *request; +struct efi_http_response_data *response; + } data; +efi_uintn_t header_count; +struct efi_http_header *headers; +efi_uintn_t body_length; +void *body; +}; + +struct efi_http_token { +struct efi_event *event; +efi_status_t status; +struct efi_http_message *message; +}; + +struct efi_http_protocol { + efi_status_t (EFIAPI * get_mode_data)(struct efi_http_protocol *this, + struct efi_http_config_data *data); + efi_status_t (EFIAPI * configure)(struct efi_http_protocol *this, + struct efi_http_config_data *data); + efi_status_t (EFIAPI * request)(struct efi_http_protocol *this, + struct efi_http_token *token); + efi_status_t (EFIAPI * cancel)(struct efi_http_protocol *this, + struct efi_http_token *token); + efi_status_t (EFIAPI * response)(struct efi_http_protocol *this, + struct efi_http_token *token); + efi_status_t (EFIAPI * poll)(struct efi_http_protocol *this); +}; +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \ 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
Signature · 1 line
2.43.0
PATCH v4 6/14 efi_loader: efi_net: add efi_net_set_addr, efi_net_get_addr
In reply to Adriano CordovaAdd the functions efi_net_set_addr and efi_net_get_addr to set and get the ip address from efi code in a network agnostic way. This could also go in net_common, or be compiled conditionally for each network stack.
---
Changes in v4:
- Removed unnecessary casts
- Changed char *ipstr by char ipstr[].
(no changes since v2)
include/efi_loader.h | 16 +++++ lib/efi_loader/efi_net.c | 125 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+)
include/efi_loader.h +16 -0
@@ -125,6 +125,22 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, size_t buffer_size) { }#endif +#if CONFIG_IS_ENABLED (NETDEVICES ) &&CONFIG_IS_ENABLED (EFI_LOADER ) +void efi_net_get_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw); +void efi_net_set_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw); +#else +static inline void efi_net_get_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) { } +static inline void efi_net_set_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) { } +#endif +/* Maximum number of configuration tables */ #define EFI_MAX_CONFIGURATION_TABLES 16
lib/efi_loader/efi_net.c +125 -0
134 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 06/14] efi_loader: efi_net: add efi_net_set_addr, efi_net_get_addr
Quoted 101 lines · Adriano Cordova
Add the functions
efi_net_set_addrandefi_net_get_addrto set and get the ip address from efi code in a network agnostic way. This could also go innet_common, or be compiled conditionally for each network stack.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Removed unnecessary casts
- Changed char *ipstr by char ipstr[].(no changes since v2)
include/efi_loader.h | 16 +++++ lib/efi_loader/efi_net.c | 125 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+)include/efi_loader.h +16
-0@@ -125,6 +125,22 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, size_t buffer_size) { }#endif +#if CONFIG_IS_ENABLED (NETDEVICES ) &&CONFIG_IS_ENABLED (EFI_LOADER ) +void efi_net_get_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw); +void efi_net_set_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw); +#else +static inline void efi_net_get_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) { } +static inline void efi_net_set_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) { } +#endif +/* Maximum number of configuration tables */ #define EFI_MAX_CONFIGURATION_TABLES 16lib/efi_loader/efi_net.c +41
-0@@ -17,6 +17,7 @@#include <efi_loader.h> #include <malloc.h> +#include <vsprintf.h> #include <net.h> static const efi_guid_t efi_net_guid =EFI_SIMPLE_NETWORK_PROTOCOL_GUID ;@@ -997,3 +998,127 @@ out_of_resources:printf ("ERROR: Out of memory\n" );return EFI_OUT_OF_RESOURCES ; } + +/** +* efi_net_get_addr() - get IP address information +* +* Copy the current IP address, mask, and gateway into the +* efi_ipv4_address structs pointed to by ip, mask and gw, +* respectively. +* +* @ip: pointer to an efi_ipv4_address struct to +* be filled with the current IP address +* @mask: pointer to an efi_ipv4_address struct to +* be filled with the current network mask +* @gw: pointer to an efi_ipv4_address struct to be +* filled with the current network gateway +*/ +void efi_net_get_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) +{ +#ifdef CONFIG_NET_LWIP +char ipstr[] ="ipaddr\0\0" ; +char maskstr[] ="netmask\0\0" ; +char gwstr[] ="gatewayip\0\0" ; +int idx; +struct in_addr tmp; +char *env; + + idx =dev_seq (eth_get_dev ()); + +if (idx <0 || idx >99 ) { +log_err ("unexpected idx %d\n" , idx); +return ; + } + +if (idx) { +sprintf (ipstr,"ipaddr%d" , idx); +sprintf (maskstr,"netmask%d" , idx); +sprintf (gwstr,"gatewayip%d" , idx); + } +
lib/efi_loader/efi_net.c out_of_resources: · line 1050
Quoted 10 lines
lib/efi_loader/efi_net.c +10
-0+ env =env_get (ipstr); +if (env && ip) { + tmp =string_to_ip (env); +memcpy (ip, &tmp,4 ); + } + + env =env_get (maskstr); +if (env && mask) { + tmp =string_to_ip (env); +memcpy (mask, &tmp,4 );
Using sizeof(*ip), sizeof(*mask) etc is better than just hardcoding 4 here
Cheers
/Ilias
Quoted 77 lines
lib/efi_loader/efi_net.c +74
-1+ } + env =env_get (gwstr); +if (env && gw) { + tmp =string_to_ip (env); +memcpy (gw, &tmp,4 ); + } +#else +if (ip) +memcpy (ip, &net_ip,4 ); +if (mask) +memcpy (mask, &net_netmask,4 ); +#endif +} + +/** +* efi_net_set_addr() - set IP address information +* +* Set the current IP address, mask, and gateway to the +* efi_ipv4_address structs pointed to by ip, mask and gw, +* respectively. +* +* @ip: pointer to new IP address +* @mask: pointer to new network mask to set +* @gw: pointer to new network gateway +*/ +void efi_net_set_addr (struct efi_ipv4_address *ip, +struct efi_ipv4_address *mask, +struct efi_ipv4_address *gw) +{ +#ifdef CONFIG_NET_LWIP +char ipstr[] ="ipaddr\0\0" ; +char maskstr[] ="netmask\0\0" ; +char gwstr[] ="gatewayip\0\0" ; +int idx; +struct in_addr *addr; +char tmp[46 ]; + + idx =dev_seq (eth_get_dev ()); + +if (idx <0 || idx >99 ) { +log_err ("unexpected idx %d\n" , idx); +return ; + } + +if (idx) { +sprintf (ipstr,"ipaddr%d" , idx); +sprintf (maskstr,"netmask%d" , idx); +sprintf (gwstr,"gatewayip%d" , idx); + } + +if (ip) { + addr = (struct in_addr *)ip; +ip_to_string (*addr, tmp); +env_set (ipstr, tmp); + } + +if (mask) { + addr = (struct in_addr *)mask; +ip_to_string (*addr, tmp); +env_set (maskstr, tmp); + } + +if (gw) { + addr = (struct in_addr *)gw; +ip_to_string (*addr, tmp); +env_set (gwstr, tmp); + } +#else +if (ip) +memcpy (&net_ip, ip,4 ); +if (mask) +memcpy (&net_netmask, mask,4 ); +#endif +} --2.43.0
PATCH v4 7/14 efi_loader: device_path: add support for HTTP device path
In reply to Adriano CordovaAdd efi_dp_from_http to form a device path from HTTP. The device path is the concatenation of the device path returned by efi_dp_from_ipv4 together with an URI node and an END node.
---
Changes in v4:
- Reworked an if-else
Changes in v3:
- Moved argument checks in efi_dp_from_http to the beginning of the function
include/efi_loader.h | 1 + lib/efi_loader/efi_device_path.c | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
include/efi_loader.h +1 -0
@@ -872,6 +872,7 @@ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);struct efi_device_path *efi_dp_from_file (const struct efi_device_path *dp,const char *path);struct efi_device_path *efi_dp_from_eth (void ); +struct efi_device_path *efi_dp_from_http (const char *server);struct efi_device_path *efi_dp_from_mem (uint32_t mem_type,uint64_t start_address,size_t size);
lib/efi_loader/efi_device_path.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 07/14] efi_loader: device_path: add support for HTTP device path
Quoted 32 lines · Adriano Cordova
Add
efi_dp_from_httpto form a device path from HTTP. The device path is the concatenation of the device path returned byefi_dp_from_ipv4together with an URI node and an END node.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Reworked an if-elseChanges in v3:
- Moved argument checks inefi_dp_from_httpto the beginning of the functioninclude/efi_loader.h | 1 + lib/efi_loader/efi_device_path.c | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)include/efi_loader.h +1
-0@@ -872,6 +872,7 @@ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);struct efi_device_path *efi_dp_from_file (const struct efi_device_path *dp,const char *path);struct efi_device_path *efi_dp_from_eth (void ); +struct efi_device_path *efi_dp_from_http (const char *server);struct efi_device_path *efi_dp_from_mem (uint32_t mem_type,uint64_t start_address,size_t size);lib/efi_loader/efi_device_path.c +0
-0
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1014
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0@@ -1012,6 +1012,58 @@ struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,return dp2; }
A function description is missing.
Please,
Quoted 7 lines
lib/efi_loader/efi_device_path.c +7
-0+struct efi_device_path *efi_dp_from_http (const char *server) +{ +struct efi_device_path *dp1, *dp2; +struct efi_device_path_uri *uridp; +efi_uintn_t uridp_len; +char *pos; +char tmp[128 ];
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1031
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+struct efi_ipv4_address ip; +struct efi_ipv4_address mask; + +if ((server &&strlen ("http://" ) +strlen (server) +1 >sizeof (tmp)) || + (!server &&IS_ENABLED (CONFIG_NET_LWIP ))) +return NULL ; + +efi_net_get_addr (&ip, &mask,NULL ); + + dp1 =efi_dp_from_ipv4 (&ip, &mask,NULL );
This seems to be the only usage of efi_dp_from_ipv4(). So we should make it static.
dp1 is expected to be NULL if we are out of memory. This error needs to be handled.
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1033
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ +strcpy (tmp,"http://" );
@Ilias:
Linaro sent a patch series for supporting https.
Will that go in after this series?
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1036
Quoted 3 lines
lib/efi_loader/efi_device_path.c +3
-0+ +if (server) { +memcpy (tmp +strlen ("http://" ), server,strlen (server) +1 );
Please, use strcat() to simplify this line.
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1038
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ } +#if !IS_ENABLED (CONFIG_NET_LWIP )
Please use 'else if' instead of '#if'.
Best regards
Heinrich
Quoted 31 lines
lib/efi_loader/efi_device_path.c +28
-0+ else { +ip_to_string (net_server_ip, tmp +strlen ("http://" )); + } +#endif + + uridp_len =sizeof (struct efi_device_path ) +strlen (tmp) +1 ; + uridp =efi_alloc (uridp_len +sizeof (END )); +if (!uridp) { +log_err ("Out of memory\n" ); +return NULL ; + } + uridp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ; + uridp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_URI ; + uridp->dp.length = uridp_len; +debug ("device path: setting uri device path to %s\n" , tmp); +memcpy (uridp->uri, tmp,strlen (tmp) +1 ); + + pos = (char *)uridp + uridp_len; +memcpy (pos, &END ,sizeof (END )); + + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)uridp,0 ); + +efi_free_pool (uridp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Re: [PATCH v4 07/14] efi_loader: device_path: add support for HTTP device path
Quoted 84 lines · Heinrich Schuchardt
Quoted 11 lines · Adriano Cordova
Add
efi_dp_from_httpto form a device path from HTTP. The device path is the concatenation of the device path returned byefi_dp_from_ipv4together with an URI node and an END node.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Reworked an if-elseChanges in v3:
- Moved argument checks inefi_dp_from_httpto the beginning of thefunction
include/efi_loader.h struct efi_device_path *efi_dp_part_node(struct
Quoted 9 lines
include/efi_loader.h | 1 + lib/efi_loader/efi_device_path.c | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)include/efi_loader.h +0
-0@@ -872,6 +872,7 @@ struct efi_device_path *efi_dp_part_node(struct
blk_desc*desc, int part);include/efi_loader.h struct efi_device_path *efi_dp_part_node(struct · line 872
Quoted 1 line
include/efi_loader.h +0
-0struct efi_device_path *efi_dp_from_file(const struct efi_device_path*dp,
Review
Quoted 7 lines
include/efi_loader.h +1
-0const char *path);struct efi_device_path *efi_dp_from_eth (void ); +struct efi_device_path *efi_dp_from_http (const char *server);struct efi_device_path *efi_dp_from_mem (uint32_t mem_type,uint64_t start_address,size_t size);(quoted diff) +0
-0
b/lib/efi_loader/efi_device_path.clib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct
Quoted 4 lines
index
cdeea4791f..9ee03062ac100644lib/efi_loader/efi_device_path.c +0
-0@@ -1012,6 +1012,58 @@ struct efi_device_path *efi_dp_from_ipv4(struct
efi_ipv4_address*ip,lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1014
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0return dp2; }A function description is missing.
Please,lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,
Quoted 11 lines
lib/efi_loader/efi_device_path.c +11
-0+struct efi_device_path *efi_dp_from_http(const char *server) +{ + struct efi_device_path *dp1, *dp2; + struct efi_device_path_uri *uridp; + efi_uintn_t uridp_len; + char *pos; + char tmp[128]; + struct efi_ipv4_address ip; + struct efi_ipv4_address mask; + + if ((server && strlen("http://") + strlen(server) + 1 >sizeof(tmp)) ||
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1031
Quoted 6 lines
lib/efi_loader/efi_device_path.c +6
-0+ (!server && IS_ENABLED(CONFIG_NET_LWIP))) +return NULL ; + +efi_net_get_addr (&ip, &mask,NULL ); + + dp1 =efi_dp_from_ipv4 (&ip, &mask,NULL );This seems to be the only usage of
efi_dp_from_ipv4(). So we should make it static.dp1 is expected to be NULL if we are out of memory. This error needs to be handled.
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct · line 1033
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ +strcpy (tmp,"http://" );@Ilias:
Linaro sent a patch series for supporting https.
Will that go in after this series?lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,
Quoted 3 lines
lib/efi_loader/efi_device_path.c +3
-0+ +if (server) { + memcpy(tmp + strlen("http://"), server, strlen(server) +1);
Please, use
strcat()to simplify this line.
Quoted 9 lines
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1038
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ } +#if !IS_ENABLED (CONFIG_NET_LWIP )Please use 'else if' instead of '#if'.
Best regards
Heinrich
Hi Heinrich,
I can't use 'else if' as the symbol net_server_ip is only defined in legacy net
Best,
Adriano
Quoted 34 lines
Quoted 32 lines
lib/efi_loader/efi_device_path.c +28
-0+ else { +ip_to_string (net_server_ip, tmp +strlen ("http://" )); + } +#endif + + uridp_len =sizeof (struct efi_device_path ) +strlen (tmp) +1 ; + uridp =efi_alloc (uridp_len +sizeof (END )); +if (!uridp) { +log_err ("Out of memory\n" ); +return NULL ; + } + uridp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ; + uridp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_URI ; + uridp->dp.length = uridp_len; +debug ("device path: setting uri device path to %s\n" , tmp); +memcpy (uridp->uri, tmp,strlen (tmp) +1 ); + + pos = (char *)uridp + uridp_len; +memcpy (pos, &END ,sizeof (END )); + + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)uridp,0 ); + +efi_free_pool (uridp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
Re: [PATCH v4 07/14] efi_loader: device_path: add support for HTTP device path
Quoted 101 lines · Adriano Córdova
El mar, 19 nov 2024 a las 7:14, Heinrich Schuchardt (<[email protected] <mailto:[email protected]>>) escribió:
On 18.11.24 22:09, Adriano Cordova wrote: > Add efi_dp_from_http to form a device path from HTTP. The > device path is the concatenation of the device path returned > by efi_dp_from_ipv4 together with an URI node and an END node. > > Signed-off-by: Adriano Cordova <[email protected] <mailto:[email protected]>> > --- > Changes in v4: > - Reworked an if-else > > Changes in v3: > - Moved argument checks in efi_dp_from_http to the beginning of the function > include/efi_loader.h | 1 + > lib/efi_loader/efi_device_path.c | 52 +++++++++++++++++++++++++ +++++++ > 2 files changed, 53 insertions(+) > > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 612bc42816..96b204dfc3 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -872,6 +872,7 @@ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part); > struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, > const char *path); > struct efi_device_path *efi_dp_from_eth(void); > +struct efi_device_path *efi_dp_from_http(const char *server); > struct efi_device_path *efi_dp_from_mem(uint32_t mem_type, > uint64_t start_address, > size_t size); > diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/ efi_device_path.c > index cdeea4791f..9ee03062ac 100644 > --- a/lib/efi_loader/efi_device_path.c > +++ b/lib/efi_loader/efi_device_path.c > @@ -1012,6 +1012,58 @@ struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, > return dp2; > } > A function description is missing. Please, > +struct efi_device_path *efi_dp_from_http(const char *server) > +{ > + struct efi_device_path *dp1, *dp2; > + struct efi_device_path_uri *uridp; > + efi_uintn_t uridp_len; > + char *pos; > + char tmp[128]; > + struct efi_ipv4_address ip; > + struct efi_ipv4_address mask; > + > + if ((server && strlen("http://") + strlen(server) + 1 > sizeof(tmp)) || > + (!server && IS_ENABLED(CONFIG_NET_LWIP))) > + return NULL; > + > + efi_net_get_addr(&ip, &mask, NULL); > + > + dp1 = efi_dp_from_ipv4(&ip, &mask, NULL); This seems to be the only usage of efi_dp_from_ipv4(). So we should make it static. dp1 is expected to be NULL if we are out of memory. This error needs to be handled. > + > + strcpy(tmp, "http://"); @Ilias: Linaro sent a patch series for supporting https. Will that go in after this series? > + > + if (server) { > + memcpy(tmp + strlen("http://"), server, strlen(server) + 1); Please, use strcat() to simplify this line. > + } > +#if !IS_ENABLED(CONFIG_NET_LWIP) Please use 'else if' instead of '#if'. Best regards Heinrich
Quoted 2 lines
Hi Heinrich,
I can't use 'else if' as the symbolnet_server_ipis only defined in legacy net
Understood.
@Jerome
Should the function ip_to_string be() moved to net/net-common.c in future to implement the missing commands in lwIP?
Best regards
Heinrich
Quoted 38 lines
Best,
Adriano> + else { > + ip_to_string(net_server_ip, tmp + strlen("http://")); > + } > +#endif > + > + uridp_len = sizeof(struct efi_device_path) + strlen(tmp) + 1; > + uridp = efi_alloc(uridp_len + sizeof(END)); > + if (!uridp) { > + log_err("Out of memory\n"); > + return NULL; > + } > + uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; > + uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; > + uridp->dp.length = uridp_len; > + debug("device path: setting uri device path to %s\n", tmp); > + memcpy(uridp->uri, tmp, strlen(tmp) + 1); > + > + pos = (char *)uridp + uridp_len; > + memcpy(pos, &END, sizeof(END)); > + > + dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)uridp, 0); > + > + efi_free_pool(uridp); > + efi_free_pool(dp1); > + > + return dp2; > +} > + > /* Construct a device-path for memory-mapped image */ > struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, > uint64_t start_address,
Re: [PATCH v4 07/14] efi_loader: device_path: add support for HTTP device path
Quoted 102 lines · Heinrich Schuchardt
Quoted 101 lines · Adriano Córdova
El mar, 19 nov 2024 a las 7:14, Heinrich Schuchardt (<[email protected] <mailto:[email protected]>>) escribió:
On 18.11.24 22:09, Adriano Cordova wrote:
> Addefi_dp_from_httpto form a device path from HTTP. The > device path is the concatenation of the device path returned > byefi_dp_from_ipv4together with an URI node and an END node. >
> Signed-off-by: Adriano Cordova <[email protected] <mailto:[email protected]>>
> ---
> Changes in v4:
> - Reworked an if-else
>
> Changes in v3:
> - Moved argument checks inefi_dp_from_httpto the beginning of the function
> include/efi_loader.h | 1 +
> lib/efi_loader/efi_device_path.c | 52 +++++++++++++++++++++++++
+++++++
> 2 files changed, 53 insertions(+)
>
> diff --gita/include/efi_loader.hb/include/efi_loader.h> index612bc42816..96b204dfc3100644
> ---a/include/efi_loader.h
> +++b/include/efi_loader.h
> @@ -872,6 +872,7 @@ structefi_device_path*efi_dp_part_node(structblk_desc*desc, int part);
> structefi_device_path*efi_dp_from_file(const structefi_device_path*dp,
> const char *path); > structefi_device_path*efi_dp_from_eth(void);
> +structefi_device_path*efi_dp_from_http(const char *server); > structefi_device_path*efi_dp_from_mem(uint32_tmem_type, > uint64_tstart_address, > size_t size);
> diff --gita/lib/efi_loader/efi_device_path.cb/lib/efi_loader/efi_device_path.c
> indexcdeea4791f..9ee03062ac100644
> ---a/lib/efi_loader/efi_device_path.c
> +++b/lib/efi_loader/efi_device_path.c
> @@ -1012,6 +1012,58 @@ structefi_device_path*efi_dp_from_ipv4(structefi_ipv4_address*ip,
> return dp2;
> }
>A function description is missing.
Please,> +struct
efi_device_path*efi_dp_from_http(const char *server) > +{
> + structefi_device_path*dp1, *dp2;
> + structefi_device_path_uri*uridp;
> + efi_uintn_turidp_len;
> + char *pos;
> + char tmp[128];
> + structefi_ipv4_addressip;
> + structefi_ipv4_addressmask;
> +
> + if ((server &&strlen("http://")+ strlen(server) + 1 > sizeof(tmp)) ||
> + (!server &&IS_ENABLED(CONFIG_NET_LWIP))) > + return NULL;
> +
> + efi_net_get_addr(&ip, &mask, NULL);
> +
> + dp1 =efi_dp_from_ipv4(&ip, &mask, NULL);This seems to be the only usage of
efi_dp_from_ipv4(). So we should make
it static.dp1 is expected to be NULL if we are out of memory. This error needs to be handled.
> +
> + strcpy(tmp, "http://");@Ilias:
Linaro sent a patch series for supporting https. Will that go in after this series?> +
> + if (server) {
> + memcpy(tmp +strlen("http://"), server, strlen(server) + 1);Please, use
strcat()to simplify this line.> + }
> +#if !IS_ENABLED(CONFIG_NET_LWIP)Please use 'else if' instead of '#if'.
Best regards
Heinrich
Quoted 7 lines
Quoted 2 lines
Hi Heinrich,
I can't use 'else if' as the symbolnet_server_ipis only defined in legacy netUnderstood.
@Jerome
Should the functionip_to_stringbe()moved tonet/net-common.cin future to implement the missing commands in lwIP?
That would certainly be a good place for it, yes.
Thanks,
Signature · 1 line
Jerome
Quoted 44 lines
Best regards
Heinrich
Quoted 38 lines
Best,
Adriano> + else {
> + ip_to_string(net_server_ip, tmp +strlen("http://")); > + }
> +#endif
> +
> + uridp_len =sizeof(struct efi_device_path)+ strlen(tmp) + 1; > + uridp =efi_alloc(uridp_len + sizeof(END));
> + if (!uridp) {
> + log_err("Out of memory\n");
> + return NULL;
> + }
> + uridp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE; > + uridp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_URI; > + uridp->dp.length =uridp_len;
> + debug("device path: setting uri device path to %s\n", tmp); > + memcpy(uridp->uri, tmp, strlen(tmp) + 1);
> +
> + pos = (char *)uridp +uridp_len;
> + memcpy(pos, &END, sizeof(END));
> +
> + dp2 =efi_dp_concat(dp1, (const struct efi_device_path *)uridp, 0);
> +
> + efi_free_pool(uridp);
> + efi_free_pool(dp1);
> +
> + return dp2;
> +}
> +
> /* Construct a device-path for memory-mapped image */ > structefi_device_path*efi_dp_from_mem(uint32_tmemory_type, > uint64_tstart_address,
Re: [PATCH v4 07/14] efi_loader: device_path: add support for HTTP device path
In reply to Heinrich SchuchardtHi Heinrich
Quoted 65 lines · Heinrich Schuchardt
Quoted 32 lines · Adriano Cordova
Add
efi_dp_from_httpto form a device path from HTTP. The device path is the concatenation of the device path returned byefi_dp_from_ipv4together with an URI node and an END node.Signed-off-by Adriano Cordova <[email protected]>---
Changes in v4:
- Reworked an if-elseChanges in v3:
- Moved argument checks inefi_dp_from_httpto the beginning of the functioninclude/efi_loader.h | 1 + lib/efi_loader/efi_device_path.c | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)include/efi_loader.h +1
-0@@ -872,6 +872,7 @@ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);struct efi_device_path *efi_dp_from_file (const struct efi_device_path *dp,const char *path);struct efi_device_path *efi_dp_from_eth (void ); +struct efi_device_path *efi_dp_from_http (const char *server);struct efi_device_path *efi_dp_from_mem (uint32_t mem_type,uint64_t start_address,size_t size);lib/efi_loader/efi_device_path.c +0
-0lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1014
Quoted 3 lines
lib/efi_loader/efi_device_path.c +0
-0@@ -1012,6 +1012,58 @@ struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,return dp2; }A function description is missing.
Please,Quoted 7 lines
lib/efi_loader/efi_device_path.c +7
-0+struct efi_device_path *efi_dp_from_http (const char *server) +{ +struct efi_device_path *dp1, *dp2; +struct efi_device_path_uri *uridp; +efi_uintn_t uridp_len; +char *pos; +char tmp[128 ];lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1031
Quoted 10 lines
lib/efi_loader/efi_device_path.c +10
-0+struct efi_ipv4_address ip; +struct efi_ipv4_address mask; + +if ((server &&strlen ("http://" ) +strlen (server) +1 >sizeof (tmp)) || + (!server &&IS_ENABLED (CONFIG_NET_LWIP ))) +return NULL ; + +efi_net_get_addr (&ip, &mask,NULL ); + + dp1 =efi_dp_from_ipv4 (&ip, &mask,NULL );This seems to be the only usage of
efi_dp_from_ipv4(). So we should make it static.dp1 is expected to be NULL if we are out of memory. This error needs to be handled.
Quoted 6 lines
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1033
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ +strcpy (tmp,"http://" );@Ilias:
Linaro sent a patch series for supporting https.
Will that go in after this series?
The https:// support in already in -master, but I can live without it for now on this series.
Cheers
/Ilias
Quoted 48 lines
lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1036
Quoted 4 lines
lib/efi_loader/efi_device_path.c +3
-0+ +if (server) { +memcpy (tmp +strlen ("http://" ), server,strlen (server) +1 );Please, use
strcat()to simplify this line.lib/efi_loader/efi_device_path.c struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, · line 1038
Quoted 2 lines
lib/efi_loader/efi_device_path.c +2
-0+ } +#if !IS_ENABLED (CONFIG_NET_LWIP )Please use 'else if' instead of '#if'.
Best regards
Heinrich
Quoted 31 lines
lib/efi_loader/efi_device_path.c +28
-0+ else { +ip_to_string (net_server_ip, tmp +strlen ("http://" )); + } +#endif + + uridp_len =sizeof (struct efi_device_path ) +strlen (tmp) +1 ; + uridp =efi_alloc (uridp_len +sizeof (END )); +if (!uridp) { +log_err ("Out of memory\n" ); +return NULL ; + } + uridp->dp.type =DEVICE_PATH_TYPE_MESSAGING_DEVICE ; + uridp->dp.sub_type =DEVICE_PATH_SUB_TYPE_MSG_URI ; + uridp->dp.length = uridp_len; +debug ("device path: setting uri device path to %s\n" , tmp); +memcpy (uridp->uri, tmp,strlen (tmp) +1 ); + + pos = (char *)uridp + uridp_len; +memcpy (pos, &END ,sizeof (END )); + + dp2 =efi_dp_concat (dp1, (const struct efi_device_path *)uridp,0 ); + +efi_free_pool (uridp); +efi_free_pool (dp1); + +return dp2; +} +/* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, uint64_t start_address,
PATCH v4 8/14 efi_loader: net: set EFI bootdevice device path to HTTP when loaded from wget
In reply to Adriano CordovaSet the device path of the efi boot device to an HTTP device path (as formed by efi_dp_from_http) when the next boot stage is loaded using wget (i.e., when wget is used with wget_info.set_bootdev=1).
When loaded from HTTP, the device path should account for it so that the next boot stage is aware (e.g. grub only loads its http stack if it itself was loaded from http, and it checks this from its device path).
---
(no changes since v2)
include/efi_loader.h | 6 +++++ lib/efi_loader/efi_device_path.c | 2 +- lib/efi_loader/efi_net.c | 38 +++++++++++++++++++++++++++++++- net/lwip/wget.c | 1 + net/wget.c | 1 + 5 files changed, 46 insertions(+), 2 deletions(-)
include/efi_loader.h +6 -0
@@ -126,6 +126,10 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr,#endif #if CONFIG_IS_ENABLED (NETDEVICES ) &&CONFIG_IS_ENABLED (EFI_LOADER ) +/* Call this to update the current device path of the efi net device */ +void efi_net_set_dp (const char *dev,const char *server); +/* Call this to get the current device path of the efi net device */ +void efi_net_get_dp (void **dp);void efi_net_get_addr (struct efi_ipv4_address *ip,struct efi_ipv4_address *mask,struct efi_ipv4_address *gw);
@@ -133,6 +137,8 @@ void efi_net_set_addr(struct efi_ipv4_address *ip,struct efi_ipv4_address *mask, struct efi_ipv4_address *gw);#else +static inline void efi_net_set_dp (const char *dev,const char *server) { } +static inline void efi_net_get_dp (void **dp) { }static inline void efi_net_get_addr (struct efi_ipv4_address *ip,struct efi_ipv4_address *mask,struct efi_ipv4_address *gw) { }
lib/efi_loader/efi_device_path.c +1 -1
@@ -1165,7 +1165,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, dp =efi_dp_from_mem (EFI_RESERVED_MEMORY_TYPE , (uintptr_t )image_addr, image_size); }else if (IS_ENABLED (CONFIG_NETDEVICES ) && !strcmp (dev,"Net" )) { - dp =efi_dp_from_eth (); +efi_net_get_dp ((void **)&dp); }else if (!strcmp (dev,"Uart" )) { dp =efi_dp_from_uart (); }else {
lib/efi_loader/efi_net.c +37 -1
@@ -16,6 +16,7 @@*/ #include <efi_loader.h> +#include <dm.h> #include <malloc.h> #include <vsprintf.h> #include <net.h>
@@ -31,6 +32,7 @@ static size_t *receive_lengths;static int rx_packet_idx;static int rx_packet_num;static struct efi_net_obj *netobj; +static struct efi_device_path *net_dp;/* * The notification function of this event is called in every timer cycle
@@ -902,8 +904,10 @@ efi_status_t efi_net_register(void) &netobj->net);if (r !=EFI_SUCCESS ) goto failure_to_add_protocol; +if (!net_dp) +efi_net_set_dp ("Net" ,NULL ); r =efi_add_protocol (&netobj->header, &efi_guid_device_path, -efi_dp_from_eth ()); + net_dp);if (r !=EFI_SUCCESS ) goto failure_to_add_protocol; r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid,
@@ -999,6 +1003,38 @@ out_of_resources:return EFI_OUT_OF_RESOURCES ; } +/** +* efi_net_set_dp() - set device path of efi net device +* +* This gets called to update the device path when a new boot +* file is dowloaded +* +* @dev: dev to set the device path from +* @server: remote server address +*/ +void efi_net_set_dp (const char *dev,const char *server) +{ +if (!strcmp (dev,"Net" )) + net_dp =efi_dp_from_eth (); +else if (!strcmp (dev,"Http" )) + net_dp =efi_dp_from_http (server); +} + +/** +* efi_net_get_dp() - get device path of efi net device +* +* Produce a copy of the current device path +* +* @dp: copy of the current device path +*/ +void efi_net_get_dp (void **dp) +{ +if (!net_dp) +efi_net_set_dp ("Net" ,NULL ); +if (dp && net_dp) + *dp =efi_dp_dup (net_dp); +} +/** * efi_net_get_addr() - get IP address information *
net/lwip/wget.c +1 -0
@@ -217,6 +217,7 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,print_size (rx_content_len / elapsed *1000 ,"/s)\n" );printf ("Bytes transferred = %lu (%lx hex)\n" , ctx->size, ctx->size);if (wget_info->set_bootdev) { +efi_net_set_dp ("Http" , ctx->server_name);efi_set_bootdev ("Net" ,"" , ctx->path,map_sysmem (ctx->saved_daddr,0 ), rx_content_len); }
net/wget.c +1 -0
@@ -442,6 +442,7 @@ static void wget_handler(uchar *pkt, u16 dport,net_set_state (wget_loop_state); wget_info->file_size = net_boot_file_size;if (wget_info->method ==WGET_HTTP_METHOD_GET && wget_info->set_bootdev) { +efi_net_set_dp ("Http" ,NULL );efi_set_bootdev ("Net" ,"" , image_url,map_sysmem (image_load_addr,0 ), net_boot_file_size);
Signature · 1 line
2.43.0
Re: [PATCH v4 08/14] efi_loader: net: set EFI bootdevice device path to HTTP when loaded from wget
Quoted 70 lines · Adriano Cordova
Set the device path of the efi boot device to an HTTP device path (as formed by
efi_dp_from_http) when the next boot stage is loaded using wget (i.e., when wget is used with wget_info.set_bootdev=1).When loaded from HTTP, the device path should account for it so that the next boot stage is aware (e.g. grub only loads its http stack if it itself was loaded from http, and it checks this from its device path).
Signed-off-by Adriano Cordova <[email protected]>---
(no changes since v2)
include/efi_loader.h | 6 +++++ lib/efi_loader/efi_device_path.c | 2 +- lib/efi_loader/efi_net.c | 38 +++++++++++++++++++++++++++++++- net/lwip/wget.c | 1 + net/wget.c | 1 + 5 files changed, 46 insertions(+), 2 deletions(-)include/efi_loader.h +6
-0@@ -126,6 +126,10 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr,#endif #if CONFIG_IS_ENABLED (NETDEVICES ) &&CONFIG_IS_ENABLED (EFI_LOADER ) +/* Call this to update the current device path of the efi net device */ +void efi_net_set_dp (const char *dev,const char *server); +/* Call this to get the current device path of the efi net device */ +void efi_net_get_dp (void **dp);void efi_net_get_addr (struct efi_ipv4_address *ip,struct efi_ipv4_address *mask,struct efi_ipv4_address *gw);@@ -133,6 +137,8 @@ void efi_net_set_addr(struct efi_ipv4_address *ip,struct efi_ipv4_address *mask, struct efi_ipv4_address *gw);#else +static inline void efi_net_set_dp (const char *dev,const char *server) { } +static inline void efi_net_get_dp (void **dp) { }static inline void efi_net_get_addr (struct efi_ipv4_address *ip,struct efi_ipv4_address *mask,struct efi_ipv4_address *gw) { }lib/efi_loader/efi_device_path.c +1
-1@@ -1165,7 +1165,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, dp =efi_dp_from_mem (EFI_RESERVED_MEMORY_TYPE , (uintptr_t )image_addr, image_size); }else if (IS_ENABLED (CONFIG_NETDEVICES ) && !strcmp (dev,"Net" )) { - dp =efi_dp_from_eth (); +efi_net_get_dp ((void **)&dp); }else if (!strcmp (dev,"Uart" )) { dp =efi_dp_from_uart (); }else {lib/efi_loader/efi_net.c +1
-0@@ -16,6 +16,7 @@*/ #include <efi_loader.h> +#include <dm.h> #include <malloc.h> #include <vsprintf.h> #include <net.h>
lib/efi_loader/efi_net.c static size_t *receive_lengths; · line 34
Quoted 3 lines
lib/efi_loader/efi_net.c +0
-0@@ -31,6 +32,7 @@ static size_t *receive_lengths;static int rx_packet_idx;static int rx_packet_num;static struct efi_net_obj *netobj;
The role of net_dp deserves a description.
Quoted 35 lines
lib/efi_loader/efi_net.c +19
-1+static struct efi_device_path *net_dp;/* * The notification function of this event is called in every timer cycle @@ -902,8 +904,10 @@ efi_status_t efi_net_register(void) &netobj->net);if (r !=EFI_SUCCESS ) goto failure_to_add_protocol; +if (!net_dp) +efi_net_set_dp ("Net" ,NULL ); r =efi_add_protocol (&netobj->header, &efi_guid_device_path, -efi_dp_from_eth ()); + net_dp);if (r !=EFI_SUCCESS ) goto failure_to_add_protocol; r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid,@@ -999,6 +1003,38 @@ out_of_resources:return EFI_OUT_OF_RESOURCES ; } +/** +* efi_net_set_dp() - set device path of efi net device +* +* This gets called to update the device path when a new boot +* file is dowloaded +* +* @dev: dev to set the device path from +* @server: remote server address +*/ +void efi_net_set_dp (const char *dev,const char *server) +{ +if (!strcmp (dev,"Net" )) + net_dp =efi_dp_from_eth (); +else if (!strcmp (dev,"Http" )) + net_dp =efi_dp_from_http (server);
lib/efi_loader/efi_net.c out_of_resources: · line 1030
Quoted 10 lines
lib/efi_loader/efi_net.c +10
-0+} + +/** +* efi_net_get_dp() - get device path of efi net device +* +* Produce a copy of the current device path +* +* @dp: copy of the current device path +*/ +void efi_net_get_dp (void **dp)
We know that dp must point to a device-path. Please, do not use void**.
efi_device_path** should be fine.
Best regards
Heinrich
Quoted 34 lines
lib/efi_loader/efi_net.c +7
-0+{ +if (!net_dp) +efi_net_set_dp ("Net" ,NULL ); +if (dp && net_dp) + *dp =efi_dp_dup (net_dp); +} +/** * efi_net_get_addr() - get IP address information * net/lwip/wget.c +1
-0@@ -217,6 +217,7 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,print_size (rx_content_len / elapsed *1000 ,"/s)\n" );printf ("Bytes transferred = %lu (%lx hex)\n" , ctx->size, ctx->size);if (wget_info->set_bootdev) { +efi_net_set_dp ("Http" , ctx->server_name);efi_set_bootdev ("Net" ,"" , ctx->path,map_sysmem (ctx->saved_daddr,0 ), rx_content_len); }net/wget.c +1
-0@@ -442,6 +442,7 @@ static void wget_handler(uchar *pkt, u16 dport,net_set_state (wget_loop_state); wget_info->file_size = net_boot_file_size;if (wget_info->method ==WGET_HTTP_METHOD_GET && wget_info->set_bootdev) { +efi_net_set_dp ("Http" ,NULL );efi_set_bootdev ("Net" ,"" , image_url,map_sysmem (image_load_addr,0 ), net_boot_file_size);
PATCH v4 9/14 efi_loader: net: add support to send http requests and parse http headers
In reply to Adriano CordovaAdd network-stack agnostic way to send an http request and parse http headers from efi drivers. This uses wget as a backend and communicates with it via efi_wget_info.
The function efi_net_do_request allocates a buffer on behalf of an efi application using efi_alloc and passes it to wget to receive the data. If the method is GET and the buffer is too small, it re-allocates the buffer based on the last received Content-Length header and tries again. If the method is HEAD it just issues one request. So issuing a HEAD request (to update Content-Length) and then a GET request is preferred but not required.
The function efi_net_parse_headers parses a raw buffer containing an http header into an array of EFI specific 'http_header' structs.
---
Changes in v4:
- Remove void* casts
- Add documentation
Changes in v3:
- Add a struct wget_http_info efi_wget_info for efi_net to pass to wget when issuing wget requests, instead of using the old wget_info (see v2 of the series 'wget: Expose wget to applications').
- Let a pointer to the http status code be passed to efi_net_do_request for it to fill it for the client after a request.
include/efi_loader.h | 13 ++++ lib/efi_loader/efi_net.c | 155 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+)
include/efi_loader.h +13 -0
@@ -16,6 +16,7 @@#include <image.h> #include <pe.h> #include <linux/list.h> +#include <linux/sizes.h> #include <linux/oid_registry.h> struct blk_desc ;
@@ -136,6 +137,18 @@ void efi_net_get_addr(struct efi_ipv4_address *ip,void efi_net_set_addr (struct efi_ipv4_address *ip,struct efi_ipv4_address *mask,struct efi_ipv4_address *gw); +efi_status_t efi_net_do_request (u8 *url,enum efi_http_method method,void **buffer, +u32 *status_code,ulong *file_size,char *headers_buffer); +#define MAX_HTTP_HEADERS_SIZE SZ_64K +#define MAX_HTTP_HEADERS 100 +#define MAX_HTTP_HEADER_NAME 128 +#define MAX_HTTP_HEADER_VALUE 512 +struct http_header { +uchar name[MAX_HTTP_HEADER_NAME ]; +uchar value[MAX_HTTP_HEADER_VALUE ]; +}; + +void efi_net_parse_headers (ulong *num_headers,struct http_header *headers);#else static inline void efi_net_set_dp (const char *dev,const char *server) { }static inline void efi_net_get_dp (void **dp) { }
lib/efi_loader/efi_net.c +155 -0
170 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 10/14 efi_loader: efi_net: add EFI_IP4_CONFIG2_PROTOCOL
In reply to Adriano CordovaAdd an implementation of the EFI_IP4_CONFIG2_PROTOCOL. The protocol is attached to the handle of the efi network device. This is the same handle where snp and pxe are attached to.
---
Changes in v4:
- efi_ipconfig.c is compiled if ARCH_QEMU || SANDBOX
- An #ifdef changed to IF_ENABLED
- Removed a log_err
- Reworked sanity checks in efi_ip4_config2_set_data
(no changes since v2)
include/efi_loader.h | 3 + lib/efi_loader/Kconfig | 9 ++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_ipconfig.c | 214 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_net.c | 20 +++- 5 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 lib/efi_loader/efi_ipconfig.c
include/efi_loader.h +3 -0
@@ -627,6 +627,9 @@ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,efi_status_t efi_gop_register (void );/* Called by bootefi to make the network interface available */ efi_status_t efi_net_register (void ); +/* Called by efi_net_register to make the ip4 config2 protocol available */ +efi_status_t efi_ipconfig_register (const efi_handle_t handle, +struct efi_ip4_config2_protocol *ip4config);/* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register (void );efi_status_t efi_initrd_register (void );
lib/efi_loader/Kconfig +9 -0
@@ -476,6 +476,15 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_IP4_CONFIG2_PROTOCOL + bool "EFI_IP4_CONFIG2_PROTOCOL support" + default y if ARCH_QEMU || SANDBOX + depends on NET || NET_LWIP + help + Provides an implementation of the EFI_IP4_CONFIG2_PROTOCOL, this + protocol can be used to set and get the current ip address and + other network information. + endmenu menu "Misc options"
lib/efi_loader/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_EFI_ESRT) += efi_esrt.o obj-$(CONFIG_VIDEO) += efi_gop.o obj-$(CONFIG_BLK) += efi_disk.o obj-$(CONFIG_NETDEVICES) += efi_net.o +obj-$(CONFIG_EFI_IP4_CONFIG2_PROTOCOL) += efi_ipconfig.o obj-$(CONFIG_ACPI) += efi_acpi.o obj-$(CONFIG_SMBIOS) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
lib/efi_loader/efi_ipconfig.c new file +214 -0
214 lines not on this page · raw message
lib/efi_loader/efi_net.c +15 -5
@@ -54,11 +54,12 @@ static struct efi_event *wait_for_packet;/** * struct efi_net_obj - EFI object representing a network interface * -* @header: EFI object header -* @net: simple network protocol interface -* @net_mode: status of the network interface -* @pxe: PXE base code protocol interface -* @pxe_mode: status of the PXE base code protocol +* @header: EFI object header +* @net: simple network protocol interface +* @net_mode: status of the network interface +* @pxe: PXE base code protocol interface +* @pxe_mode: status of the PXE base code protocol +* @ip4_config2: IP4 Config2 protocol interface */ struct efi_net_obj {struct efi_object header;
@@ -66,6 +67,9 @@ struct efi_net_obj {struct efi_simple_network_mode net_mode;struct efi_pxe_base_code_protocol pxe;struct efi_pxe_mode pxe_mode; +#if IS_ENABLED (CONFIG_EFI_IP4_CONFIG2_PROTOCOL ) +struct efi_ip4_config2_protocol ip4_config2; +#endif };/*
@@ -993,6 +997,12 @@ efi_status_t efi_net_register(void)return r; } +#ifdef CONFIG_EFI_IP4_CONFIG2_PROTOCOL + r =efi_ipconfig_register (&netobj->header, &netobj->ip4_config2); +if (r !=EFI_SUCCESS ) + goto failure_to_add_protocol; +#endif +return EFI_SUCCESS ; failure_to_add_protocol:printf ("ERROR: Failure to add protocol\n" );
Signature · 1 line
2.43.0
PATCH v4 11/14 efi_loader: efi_net: add EFI_HTTP_PROTOCOL
In reply to Adriano CordovaAdd an EFI HTTP driver. This commit implements the EFI_HTTP_PROTOCOL and the EFI_HTTP_SERVICE_BINDING_PROTOCOL. The latter is attached to the handle of th efi network device. This is the same handle where snp, pxe, and ipconfig are attached to.
---
Changes in v4:
- Reworked pointers to be void * instead of ulong.
- Removed some console output
- Check invalid parameters at the beginning, and do not signal an event in case parameters are invalid.
Changes in v3:
- Add documentation
- Clean up the way the buffer pointed to http_load_addr in the current http instance was being freed.
- Remove unnecessary initialization new_instance->handle = NULL in efi_http_service_binding_create_child.
include/efi_loader.h | 3 + lib/efi_loader/Kconfig | 8 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_http.c | 548 ++++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_net.c | 20 +- 5 files changed, 578 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_http.c
include/efi_loader.h +3 -0
@@ -630,6 +630,9 @@ efi_status_t efi_net_register(void);/* Called by efi_net_register to make the ip4 config2 protocol available */ efi_status_t efi_ipconfig_register (const efi_handle_t handle,struct efi_ip4_config2_protocol *ip4config); +/* Called by efi_net_register to make the http protocol available */ +efi_status_t efi_http_register (const efi_handle_t handle, +struct efi_service_binding_protocol *http_service_binding);/* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register (void );efi_status_t efi_initrd_register (void );
lib/efi_loader/Kconfig +8 -0
@@ -485,6 +485,14 @@ config EFI_IP4_CONFIG2_PROTOCOL protocol can be used to set and get the current ip address and other network information. +config EFI_HTTP_PROTOCOL + bool "EFI_HTTP_PROTOCOL support" + default y if ARCH_QEMU || SANDBOX + depends on WGET + help + Provides an EFI HTTP driver implementing the EFI_HTTP_PROTOCOL. and + EFI_HTTP_SERVICE_BINDING_PROTOCOL. + endmenu menu "Misc options"
lib/efi_loader/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_VIDEO) += efi_gop.o obj-$(CONFIG_BLK) += efi_disk.o obj-$(CONFIG_NETDEVICES) += efi_net.o obj-$(CONFIG_EFI_IP4_CONFIG2_PROTOCOL) += efi_ipconfig.o +obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_http.o obj-$(CONFIG_ACPI) += efi_acpi.o obj-$(CONFIG_SMBIOS) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
lib/efi_loader/efi_http.c new file +548 -0
548 lines not on this page · raw message
lib/efi_loader/efi_net.c +18 -2
@@ -60,6 +60,7 @@ static struct efi_event *wait_for_packet;* @pxe: PXE base code protocol interface * @pxe_mode: status of the PXE base code protocol * @ip4_config2: IP4 Config2 protocol interface +* @http_service_binding: Http service binding protocol interface */ struct efi_net_obj {struct efi_object header;
@@ -70,6 +71,9 @@ struct efi_net_obj {#if IS_ENABLED (CONFIG_EFI_IP4_CONFIG2_PROTOCOL )struct efi_ip4_config2_protocol ip4_config2;#endif +#if IS_ENABLED (CONFIG_EFI_HTTP_PROTOCOL ) +struct efi_service_binding_protocol http_service_binding; +#endif };/*
@@ -1003,6 +1007,19 @@ efi_status_t efi_net_register(void) goto failure_to_add_protocol;#endif +#ifdef CONFIG_EFI_HTTP_PROTOCOL + r =efi_http_register (&netobj->header, &netobj->http_service_binding); +if (r !=EFI_SUCCESS ) + goto failure_to_add_protocol; +/* +* No harm on doing the following. If the PXE handle is present, the client could +* find it and try to get its IP address from it. In here the PXE handle is present +* but the PXE protocol is not yet implmenented, so we add this in the meantime. +*/ +efi_net_get_addr ((struct efi_ipv4_address *)&netobj->pxe_mode.station_ip, + (struct efi_ipv4_address *)&netobj->pxe_mode.subnet_mask,NULL ); +#endif +return EFI_SUCCESS ; failure_to_add_protocol:printf ("ERROR: Failure to add protocol\n" );
@@ -1190,8 +1207,6 @@ static efi_status_t efi_net_set_buffer(void **buffer, size_t size)if (size <SZ_64K ) size =SZ_64K ; -efi_free_pool (*buffer); - *buffer =efi_alloc (size);if (!*buffer) ret =EFI_OUT_OF_RESOURCES ;
@@ -1288,6 +1303,7 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf wget_ret =wget_request ((ulong)*buffer, url, &efi_wget_info);if ((ulong )efi_wget_info.hdr_cont_len > efi_wget_info.buffer_size) {// Try again with updated buffer size +efi_free_pool (*buffer); ret =efi_net_set_buffer (buffer, (size_t )efi_wget_info.hdr_cont_len);if (ret !=EFI_SUCCESS ) goto out;
Signature · 1 line
2.43.0
PATCH v4 12/14 lib: uuid: display HTTP and IPV4 Config II protocols
In reply to Adriano CordovaFrom: Heinrich Schuchardt <[email protected]>
Add long texts for
* EFI HTTP Protocol
* EFI HTTP Service Binding Protocol
* EFI IPv4 Configuration II Protocol
to the uuid library.
---
(no changes since v2)
lib/uuid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
lib/uuid.c +14 -0
@@ -174,6 +174,20 @@ static const struct {"Firmware Management" ,EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID }, +#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL) + { +"HTTP" , +EFI_HTTP_PROTOCOL_GUID , + }, + { +"HTTP Service Binding" , +EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID , + }, + { +"IPv4 Config2" , +EFI_IP4_CONFIG2_PROTOCOL_GUID , + }, +#endif /* Configuration table GUIDs */ { "ACPI table",
Signature · 1 line
2.43.0
PATCH v4 13/14 efi_selftest: add test for HTTP protocol
In reply to Adriano CordovaAdd a test for the EFI_HTTP_PROTOCOL andEFI_SEVICE_BINDING_PROTOCOL.
---
(no changes since v2)
lib/efi_selftest/Makefile | 2 +- lib/efi_selftest/efi_selftest_http.c | 315 +++++++++++++++++++++++++++ 2 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 lib/efi_selftest/efi_selftest_http.c
lib/efi_selftest/Makefile +1 -1
@@ -52,7 +52,7 @@ efi_selftest_watchdog.o obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o obj-$(CONFIG_NETDEVICES) += efi_selftest_snp.o - +obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_http.o obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_selftest_devicepath.o obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += \ efi_selftest_unicode_collation.o
lib/efi_selftest/efi_selftest_http.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 14/14 efi_selftest: add test for IPv4 Config2 protocol
In reply to Adriano CordovaAdd a test for the EFI_IP4_CONFIG2_PROTOCOL. The test sets the ip policy to static, adds an ip address, and then reads the current ip address and checks for it to be the same as the one that was set.
---
Changes in v4:
- Removed unnecessary void* casts
(no changes since v2)
lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_ipconfig.c | 170 +++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_ipconfig.c
lib/efi_selftest/Makefile +2 -0
@@ -53,6 +53,8 @@ efi_selftest_watchdog.o obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o obj-$(CONFIG_NETDEVICES) += efi_selftest_snp.o obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_http.o +obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_ipconfig.o + obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_selftest_devicepath.o obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += \ efi_selftest_unicode_collation.o
lib/efi_selftest/efi_selftest_ipconfig.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
2.43.0