summaryrefslogtreecommitdiff
path: root/lib/efi_loader
diff options
context:
space:
mode:
Diffstat (limited to 'lib/efi_loader')
-rw-r--r--lib/efi_loader/Kconfig1
-rw-r--r--lib/efi_loader/efi_bootbin.c3
-rw-r--r--lib/efi_loader/efi_boottime.c32
-rw-r--r--lib/efi_loader/efi_device_path.c26
-rw-r--r--lib/efi_loader/efi_file.c58
-rw-r--r--lib/efi_loader/efi_http.c6
-rw-r--r--lib/efi_loader/efi_ipconfig.c4
-rw-r--r--lib/efi_loader/efi_net.c608
-rw-r--r--lib/efi_loader/efi_setup.c27
9 files changed, 571 insertions, 194 deletions
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index d4f6b56afaa..6130af14337 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -27,6 +27,7 @@ config EFI_LOADER
select REGEX
imply FAT
imply FAT_WRITE
+ imply FAT_RENAME
imply USB_KEYBOARD_FN_KEYS
imply VIDEO_ANSI
help
diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c
index 10ec5e9ada3..deafb2ce1c2 100644
--- a/lib/efi_loader/efi_bootbin.c
+++ b/lib/efi_loader/efi_bootbin.c
@@ -16,6 +16,7 @@
#include <log.h>
#include <malloc.h>
#include <mapmem.h>
+#include <net.h>
static struct efi_device_path *bootefi_image_path;
static struct efi_device_path *bootefi_device_path;
@@ -67,7 +68,7 @@ static efi_status_t calculate_paths(const char *dev, const char *devnr,
#if IS_ENABLED(CONFIG_NETDEVICES)
if (!strcmp(dev, "Net") || !strcmp(dev, "Http")) {
- ret = efi_net_set_dp(dev, devnr);
+ ret = efi_net_new_dp(dev, devnr, eth_get_dev());
if (ret != EFI_SUCCESS)
return ret;
}
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 5164cb15986..c8d9a6037f7 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -21,7 +21,6 @@
#include <usb.h>
#include <watchdog.h>
#include <asm/global_data.h>
-#include <asm/setjmp.h>
#include <linux/libfdt_env.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -60,9 +59,9 @@ static efi_handle_t current_image;
static volatile gd_t *efi_gd, *app_gd;
#endif
-static efi_status_t efi_uninstall_protocol
- (efi_handle_t handle, const efi_guid_t *protocol,
- void *protocol_interface, bool preserve);
+efi_status_t efi_uninstall_protocol
+ (efi_handle_t handle, const efi_guid_t *protocol,
+ void *protocol_interface, bool preserve);
/* 1 if inside U-Boot code, 0 if inside EFI payload code */
static int entry_count = 1;
@@ -100,12 +99,11 @@ const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID;
/* GUID of the SMBIOS table */
const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
-static efi_status_t EFIAPI efi_disconnect_controller(
+efi_status_t EFIAPI efi_disconnect_controller(
efi_handle_t controller_handle,
efi_handle_t driver_image_handle,
efi_handle_t child_handle);
-static
efi_status_t EFIAPI efi_connect_controller(efi_handle_t controller_handle,
efi_handle_t *driver_image_handle,
struct efi_device_path *remain_device_path,
@@ -1039,7 +1037,7 @@ static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
*
* Return: status code
*/
-static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
+efi_status_t EFIAPI efi_close_event(struct efi_event *event)
{
struct efi_register_notify_event *item, *next;
@@ -1380,9 +1378,9 @@ static efi_status_t efi_disconnect_all_drivers
*
* Return: status code
*/
-static efi_status_t efi_uninstall_protocol
- (efi_handle_t handle, const efi_guid_t *protocol,
- void *protocol_interface, bool preserve)
+efi_status_t efi_uninstall_protocol
+ (efi_handle_t handle, const efi_guid_t *protocol,
+ void *protocol_interface, bool preserve)
{
struct efi_handler *handler;
struct efi_open_protocol_info_item *item;
@@ -2233,8 +2231,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
if (!efi_st_keep_devices) {
bootm_disable_interrupts();
- if (IS_ENABLED(CONFIG_USB_DEVICE))
- udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}
@@ -3199,7 +3195,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
void *info;
efi_handle_t parent_image = current_image;
efi_status_t exit_status;
- struct jmp_buf_data exit_jmp;
+ jmp_buf exit_jmp;
EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
@@ -3238,7 +3234,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
}
/* call the image! */
- if (setjmp(&exit_jmp)) {
+ if (setjmp(exit_jmp)) {
/*
* We called the entry point of the child image with EFI_CALL
* in the lines below. The child image called the Exit() boot
@@ -3444,7 +3440,7 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
struct efi_loaded_image *loaded_image_protocol;
struct efi_loaded_image_obj *image_obj =
(struct efi_loaded_image_obj *)image_handle;
- struct jmp_buf_data *exit_jmp;
+ jmp_buf *exit_jmp;
EFI_ENTRY("%p, %ld, %zu, %p", image_handle, exit_status,
exit_data_size, exit_data);
@@ -3511,7 +3507,7 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
*/
efi_restore_gd();
- longjmp(exit_jmp, 1);
+ longjmp(*exit_jmp, 1);
panic("EFI application exited");
out:
@@ -3665,7 +3661,7 @@ static efi_status_t efi_connect_single_controller(
*
* Return: status code
*/
-static efi_status_t EFIAPI efi_connect_controller(
+efi_status_t EFIAPI efi_connect_controller(
efi_handle_t controller_handle,
efi_handle_t *driver_image_handle,
struct efi_device_path *remain_device_path,
@@ -3844,7 +3840,7 @@ static efi_status_t efi_get_child_controllers(
*
* Return: status code
*/
-static efi_status_t EFIAPI efi_disconnect_controller(
+efi_status_t EFIAPI efi_disconnect_controller(
efi_handle_t controller_handle,
efi_handle_t driver_image_handle,
efi_handle_t child_handle)
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c0633a736b6..c9bf2726fe2 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -954,20 +954,20 @@ struct efi_device_path *efi_dp_from_uart(void)
return buf;
}
-struct efi_device_path __maybe_unused *efi_dp_from_eth(void)
+struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev)
{
void *buf, *start;
unsigned dpsize = 0;
- assert(eth_get_dev());
+ assert(dev);
- dpsize += dp_size(eth_get_dev());
+ dpsize += dp_size(dev);
start = buf = efi_alloc(dpsize + sizeof(END));
if (!buf)
return NULL;
- buf = dp_fill(buf, eth_get_dev());
+ buf = dp_fill(buf, dev);
*((struct efi_device_path *)buf) = END;
@@ -984,11 +984,13 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(void)
* @ip: IPv4 local address
* @mask: network mask
* @srv: IPv4 remote/server address
+ * @dev: net udevice
* Return: pointer to device path, NULL on error
*/
static 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_ipv4_address *srv,
+ struct udevice *dev)
{
struct efi_device_path *dp1, *dp2, *pos;
struct {
@@ -1010,7 +1012,7 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,
pos = &dp.end;
memcpy(pos, &END, sizeof(END));
- dp1 = efi_dp_from_eth();
+ dp1 = efi_dp_from_eth(dev);
if (!dp1)
return NULL;
@@ -1029,9 +1031,10 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip,
* and an END node.
*
* @server: URI of remote server
+ * @dev: net udevice
* Return: pointer to HTTP device path, NULL on error
*/
-struct efi_device_path *efi_dp_from_http(const char *server)
+struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev)
{
struct efi_device_path *dp1, *dp2;
struct efi_device_path_uri *uridp;
@@ -1045,12 +1048,13 @@ struct efi_device_path *efi_dp_from_http(const char *server)
(!server && IS_ENABLED(CONFIG_NET_LWIP)))
return NULL;
- efi_net_get_addr(&ip, &mask, NULL);
+ efi_net_get_addr(&ip, &mask, NULL, dev);
- dp1 = efi_dp_from_ipv4(&ip, &mask, NULL);
+ dp1 = efi_dp_from_ipv4(&ip, &mask, NULL, dev);
if (!dp1)
return NULL;
+
strcpy(tmp, "http://");
if (server) {
@@ -1185,8 +1189,8 @@ 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") || !strcmp(dev, "Http"))) {
- efi_net_get_dp(&dp);
+ (!strcmp(dev, "Net") || !strcmp(dev, "Http"))) {
+ efi_net_dp_from_dev(&dp, eth_get_dev(), false);
} else if (!strcmp(dev, "Uart")) {
dp = efi_dp_from_uart();
} else {
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 201fa5f8f3c..7d81da8f2d8 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -40,7 +40,7 @@ struct file_handle {
struct fs_dir_stream *dirs;
struct fs_dirent *dent;
- char path[0];
+ char *path;
};
#define to_fh(x) container_of(x, struct file_handle, base)
@@ -178,6 +178,7 @@ static struct efi_file_handle *file_open(struct file_system *fs,
u64 attributes)
{
struct file_handle *fh;
+ char *path;
char f0[MAX_UTF8_PER_UTF16] = {0};
int plen = 0;
int flen = 0;
@@ -194,11 +195,13 @@ static struct efi_file_handle *file_open(struct file_system *fs,
plen = strlen(parent->path) + 1;
}
+ fh = calloc(1, sizeof(*fh));
/* +2 is for null and '/' */
- fh = calloc(1, sizeof(*fh) + plen + (flen * MAX_UTF8_PER_UTF16) + 2);
- if (!fh)
- return NULL;
+ path = calloc(1, plen + (flen * MAX_UTF8_PER_UTF16) + 2);
+ if (!fh || !path)
+ goto error;
+ fh->path = path;
fh->open_mode = open_mode;
fh->base = efi_file_handle_protocol;
fh->fs = fs;
@@ -245,6 +248,7 @@ static struct efi_file_handle *file_open(struct file_system *fs,
return &fh->base;
error:
+ free(fh->path);
free(fh);
return NULL;
}
@@ -368,6 +372,7 @@ out:
static efi_status_t file_close(struct file_handle *fh)
{
fs_closedir(fh->dirs);
+ free(fh->path);
free(fh);
return EFI_SUCCESS;
}
@@ -949,6 +954,7 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
{
struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_UNSUPPORTED;
+ char *new_file_name = NULL, *new_path = NULL;
EFI_ENTRY("%p, %pUs, %zu, %p", file, info_type, buffer_size, buffer);
@@ -978,13 +984,43 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
pos = new_file_name;
utf16_utf8_strcpy(&pos, info->file_name);
if (strcmp(new_file_name, filename)) {
- /* TODO: we do not support renaming */
- EFI_PRINT("Renaming not supported\n");
- free(new_file_name);
- ret = EFI_ACCESS_DENIED;
- goto out;
+ int dlen;
+ int rv;
+
+ if (set_blk_dev(fh)) {
+ ret = EFI_DEVICE_ERROR;
+ goto out;
+ }
+ dlen = filename - fh->path;
+ new_path = calloc(1, dlen + strlen(new_file_name) + 1);
+ if (!new_path) {
+ ret = EFI_OUT_OF_RESOURCES;
+ goto out;
+ }
+ memcpy(new_path, fh->path, dlen);
+ strcpy(new_path + dlen, new_file_name);
+ sanitize_path(new_path);
+ rv = fs_exists(new_path);
+ if (rv) {
+ ret = EFI_ACCESS_DENIED;
+ goto out;
+ }
+ /* fs_exists() calls fs_close(), so open file system again */
+ if (set_blk_dev(fh)) {
+ ret = EFI_DEVICE_ERROR;
+ goto out;
+ }
+ rv = fs_rename(fh->path, new_path);
+ if (rv) {
+ ret = EFI_ACCESS_DENIED;
+ goto out;
+ }
+ free(fh->path);
+ fh->path = new_path;
+ /* Prevent new_path from being freed on out */
+ new_path = NULL;
+ ret = EFI_SUCCESS;
}
- free(new_file_name);
/* Check for truncation */
if (!fh->isdir) {
ret = efi_get_file_size(fh, &file_size);
@@ -1007,6 +1043,8 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
ret = EFI_UNSUPPORTED;
}
out:
+ free(new_path);
+ free(new_file_name);
return EFI_EXIT(ret);
}
diff --git a/lib/efi_loader/efi_http.c b/lib/efi_loader/efi_http.c
index 88816256b03..189317fe2d2 100644
--- a/lib/efi_loader/efi_http.c
+++ b/lib/efi_loader/efi_http.c
@@ -36,6 +36,7 @@ static const efi_guid_t efi_http_guid = EFI_HTTP_PROTOCOL_GUID;
struct efi_http_instance {
struct efi_http_protocol http;
efi_handle_t handle;
+ struct efi_service_binding_protocol *parent;
bool configured;
void *http_load_addr;
ulong file_size;
@@ -188,7 +189,7 @@ static efi_status_t EFIAPI efi_http_configure(struct efi_http_protocol *this,
if (!ipv4_node->use_default_address) {
efi_net_set_addr((struct efi_ipv4_address *)&ipv4_node->local_address,
- (struct efi_ipv4_address *)&ipv4_node->local_subnet, NULL);
+ (struct efi_ipv4_address *)&ipv4_node->local_subnet, NULL, NULL);
}
http_instance->current_offset = 0;
@@ -243,7 +244,7 @@ static efi_status_t EFIAPI efi_http_request(struct efi_http_protocol *this,
ret = efi_net_do_request(url_8, current_method, &http_instance->http_load_addr,
&http_instance->status_code, &http_instance->file_size,
- http_instance->headers_buffer);
+ http_instance->headers_buffer, http_instance->parent);
if (ret != EFI_SUCCESS)
goto out;
@@ -408,6 +409,7 @@ static efi_status_t EFIAPI efi_http_service_binding_create_child(
goto failure_to_add_protocol;
}
+ new_instance->parent = this;
efi_add_handle(new_instance->handle);
*child_handle = new_instance->handle;
diff --git a/lib/efi_loader/efi_ipconfig.c b/lib/efi_loader/efi_ipconfig.c
index f1c092daafd..9f51f77fa9a 100644
--- a/lib/efi_loader/efi_ipconfig.c
+++ b/lib/efi_loader/efi_ipconfig.c
@@ -60,7 +60,7 @@ static efi_status_t EFIAPI efi_ip4_config2_set_data(struct efi_ip4_config2_proto
memcpy((void *)&current_http_ip, data,
sizeof(struct efi_ip4_config2_manual_address));
efi_net_set_addr(&current_http_ip.address,
- &current_http_ip.subnet_mask, NULL);
+ &current_http_ip.subnet_mask, NULL, NULL);
return EFI_EXIT(EFI_SUCCESS);
}
return EFI_EXIT(EFI_BAD_BUFFER_SIZE);
@@ -133,7 +133,7 @@ static efi_status_t EFIAPI efi_ip4_config2_get_data(struct efi_ip4_config2_proto
return EFI_EXIT(EFI_BUFFER_TOO_SMALL);
}
- efi_net_get_addr(&current_http_ip.address, &current_http_ip.subnet_mask, NULL);
+ efi_net_get_addr(&current_http_ip.address, &current_http_ip.subnet_mask, NULL, NULL);
memcpy(data, (void *)&current_http_ip,
sizeof(struct efi_ip4_config2_manual_address));
diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c
index 60aa076feaa..b3291b4f1d5 100644
--- a/lib/efi_loader/efi_net.c
+++ b/lib/efi_loader/efi_net.c
@@ -24,54 +24,70 @@
#include <vsprintf.h>
#include <net.h>
-static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
+#define MAX_EFI_NET_OBJS 10
+#define MAX_NUM_DHCP_ENTRIES 10
+#define MAX_NUM_DP_ENTRIES 10
+
+const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
static const efi_guid_t efi_pxe_base_code_protocol_guid =
EFI_PXE_BASE_CODE_PROTOCOL_GUID;
-static struct efi_pxe_packet *dhcp_ack;
-static void *new_tx_packet;
-static void *transmit_buffer;
-static uchar **receive_buffer;
-static size_t *receive_lengths;
-static int rx_packet_idx;
-static int rx_packet_num;
-static struct efi_net_obj *netobj;
+
+struct dp_entry {
+ struct efi_device_path *net_dp;
+ struct udevice *dev;
+ bool is_valid;
+};
/*
- * The current network device path. This device path is updated when a new
- * bootfile is downloaded from the network. If then the bootfile is loaded
- * as an efi image, net_dp is passed as the device path of the loaded image.
+ * The network device path cache. An entry is added when a new bootfile
+ * is downloaded from the network. If the bootfile is then loaded as an
+ * efi image, the most recent entry corresponding to the device is passed
+ * as the device path of the loaded image.
*/
-static struct efi_device_path *net_dp;
+static struct dp_entry dp_cache[MAX_NUM_DP_ENTRIES];
+static int next_dp_entry;
+#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL)
static struct wget_http_info efi_wget_info = {
.set_bootdev = false,
.check_buffer_size = true,
};
+#endif
-/*
- * The notification function of this event is called in every timer cycle
- * to check if a new network packet has been received.
- */
-static struct efi_event *network_timer_event;
-/*
- * This event is signaled when a packet has been received.
- */
-static struct efi_event *wait_for_packet;
+struct dhcp_entry {
+ struct efi_pxe_packet *dhcp_ack;
+ struct udevice *dev;
+ bool is_valid;
+};
+
+static struct dhcp_entry dhcp_cache[MAX_NUM_DHCP_ENTRIES];
+static int next_dhcp_entry;
/**
* struct efi_net_obj - EFI object representing a network interface
*
* @header: EFI object header
+ * @dev: net udevice
* @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
* @http_service_binding: Http service binding protocol interface
+ * @new_tx_packet: new transmit packet
+ * @transmit_buffer: transmit buffer
+ * @receive_buffer: array of receive buffers
+ * @receive_lengths: array of lengths for received packets
+ * @rx_packet_idx: index of the current receive packet
+ * @rx_packet_num: number of received packets
+ * @wait_for_packet: signaled when a packet has been received
+ * @network_timer_event: event to check for new network packets.
+ * @efi_seq_num: sequence number of the EFI net object.
*/
struct efi_net_obj {
struct efi_object header;
+ struct udevice *dev;
struct efi_simple_network net;
struct efi_simple_network_mode net_mode;
struct efi_pxe_base_code_protocol pxe;
@@ -82,8 +98,54 @@ struct efi_net_obj {
#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL)
struct efi_service_binding_protocol http_service_binding;
#endif
+ void *new_tx_packet;
+ void *transmit_buffer;
+ uchar **receive_buffer;
+ size_t *receive_lengths;
+ int rx_packet_idx;
+ int rx_packet_num;
+ struct efi_event *wait_for_packet;
+ struct efi_event *network_timer_event;
+ int efi_seq_num;
};
+static int curr_efi_net_obj;
+static struct efi_net_obj *net_objs[MAX_EFI_NET_OBJS];
+
+/**
+ * efi_netobj_is_active() - checks if a netobj is active in the efi subsystem
+ *
+ * @netobj: pointer to efi_net_obj
+ * Return: true if active
+ */
+static bool efi_netobj_is_active(struct efi_net_obj *netobj)
+{
+ if (!netobj || !efi_search_obj(&netobj->header))
+ return false;
+
+ return true;
+}
+
+/*
+ * efi_netobj_from_snp() - get efi_net_obj from simple network protocol
+ *
+ *
+ * @snp: pointer to the simple network protocol
+ * Return: pointer to efi_net_obj, NULL on error
+ */
+static struct efi_net_obj *efi_netobj_from_snp(struct efi_simple_network *snp)
+{
+ int i;
+
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && &net_objs[i]->net == snp) {
+ // Do not register duplicate devices
+ return net_objs[i];
+ }
+ }
+ return NULL;
+}
+
/*
* efi_net_start() - start the network interface
*
@@ -97,20 +159,22 @@ struct efi_net_obj {
static efi_status_t EFIAPI efi_net_start(struct efi_simple_network *this)
{
efi_status_t ret = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p", this);
-
/* Check parameters */
if (!this) {
ret = EFI_INVALID_PARAMETER;
goto out;
}
+ nt = efi_netobj_from_snp(this);
+
if (this->mode->state != EFI_NETWORK_STOPPED) {
ret = EFI_ALREADY_STARTED;
} else {
this->int_status = 0;
- wait_for_packet->is_signaled = false;
+ nt->wait_for_packet->is_signaled = false;
this->mode->state = EFI_NETWORK_STARTED;
}
out:
@@ -130,6 +194,7 @@ out:
static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this)
{
efi_status_t ret = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p", this);
@@ -139,13 +204,17 @@ static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this)
goto out;
}
+ nt = efi_netobj_from_snp(this);
+
if (this->mode->state == EFI_NETWORK_STOPPED) {
ret = EFI_NOT_STARTED;
} else {
/* Disable hardware and put it into the reset state */
+ eth_set_dev(nt->dev);
+ env_set("ethact", eth_get_name());
eth_halt();
/* Clear cache of packets */
- rx_packet_num = 0;
+ nt->rx_packet_num = 0;
this->mode->state = EFI_NETWORK_STOPPED;
}
out:
@@ -169,6 +238,7 @@ static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
{
int ret;
efi_status_t r = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p, %lx, %lx", this, extra_rx, extra_tx);
@@ -177,6 +247,7 @@ static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
r = EFI_INVALID_PARAMETER;
goto out;
}
+ nt = efi_netobj_from_snp(this);
switch (this->mode->state) {
case EFI_NETWORK_INITIALIZED:
@@ -189,14 +260,13 @@ static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
/* Setup packet buffers */
net_init();
- /* Disable hardware and put it into the reset state */
- eth_halt();
/* Clear cache of packets */
- rx_packet_num = 0;
- /* Set current device according to environment variables */
- eth_set_current();
+ nt->rx_packet_num = 0;
+ /* Set the net device corresponding to the efi net object */
+ eth_set_dev(nt->dev);
+ env_set("ethact", eth_get_name());
/* Get hardware ready for send and receive operations */
- ret = eth_init();
+ ret = eth_start_udev(nt->dev);
if (ret < 0) {
eth_halt();
this->mode->state = EFI_NETWORK_STOPPED;
@@ -204,7 +274,7 @@ static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
goto out;
} else {
this->int_status = 0;
- wait_for_packet->is_signaled = false;
+ nt->wait_for_packet->is_signaled = false;
this->mode->state = EFI_NETWORK_INITIALIZED;
}
out:
@@ -265,6 +335,7 @@ out:
static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this)
{
efi_status_t ret = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p", this);
@@ -273,6 +344,7 @@ static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this)
ret = EFI_INVALID_PARAMETER;
goto out;
}
+ nt = efi_netobj_from_snp(this);
switch (this->mode->state) {
case EFI_NETWORK_INITIALIZED:
@@ -285,9 +357,12 @@ static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this)
goto out;
}
+ eth_set_dev(nt->dev);
+ env_set("ethact", eth_get_name());
eth_halt();
+
this->int_status = 0;
- wait_for_packet->is_signaled = false;
+ nt->wait_for_packet->is_signaled = false;
this->mode->state = EFI_NETWORK_STARTED;
out:
@@ -463,6 +538,7 @@ static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
u32 *int_status, void **txbuf)
{
efi_status_t ret = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p, %p, %p", this, int_status, txbuf);
@@ -474,6 +550,8 @@ static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
goto out;
}
+ nt = efi_netobj_from_snp(this);
+
switch (this->mode->state) {
case EFI_NETWORK_STOPPED:
ret = EFI_NOT_STARTED;
@@ -490,9 +568,9 @@ static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
this->int_status = 0;
}
if (txbuf)
- *txbuf = new_tx_packet;
+ *txbuf = nt->new_tx_packet;
- new_tx_packet = NULL;
+ nt->new_tx_packet = NULL;
out:
return EFI_EXIT(ret);
}
@@ -519,6 +597,7 @@ static efi_status_t EFIAPI efi_net_transmit
struct efi_mac_address *dest_addr, u16 *protocol)
{
efi_status_t ret = EFI_SUCCESS;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p, %lu, %lu, %p, %p, %p, %p", this,
(unsigned long)header_size, (unsigned long)buffer_size,
@@ -532,6 +611,8 @@ static efi_status_t EFIAPI efi_net_transmit
goto out;
}
+ nt = efi_netobj_from_snp(this);
+
/* We do not support jumbo packets */
if (buffer_size > PKTSIZE_ALIGN) {
ret = EFI_INVALID_PARAMETER;
@@ -576,11 +657,14 @@ static efi_status_t EFIAPI efi_net_transmit
break;
}
+ eth_set_dev(nt->dev);
+ env_set("ethact", eth_get_name());
+
/* Ethernet packets always fit, just bounce */
- memcpy(transmit_buffer, buffer, buffer_size);
- net_send_packet(transmit_buffer, buffer_size);
+ memcpy(nt->transmit_buffer, buffer, buffer_size);
+ net_send_packet(nt->transmit_buffer, buffer_size);
- new_tx_packet = buffer;
+ nt->new_tx_packet = buffer;
this->int_status |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
out:
return EFI_EXIT(ret);
@@ -611,6 +695,7 @@ static efi_status_t EFIAPI efi_net_receive
struct ethernet_hdr *eth_hdr;
size_t hdr_size = sizeof(struct ethernet_hdr);
u16 protlen;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size,
buffer_size, buffer, src_addr, dest_addr, protocol);
@@ -624,6 +709,8 @@ static efi_status_t EFIAPI efi_net_receive
goto out;
}
+ nt = efi_netobj_from_snp(this);
+
switch (this->mode->state) {
case EFI_NETWORK_STOPPED:
ret = EFI_NOT_STARTED;
@@ -635,16 +722,16 @@ static efi_status_t EFIAPI efi_net_receive
break;
}
- if (!rx_packet_num) {
+ if (!nt->rx_packet_num) {
ret = EFI_NOT_READY;
goto out;
}
/* Fill export parameters */
- eth_hdr = (struct ethernet_hdr *)receive_buffer[rx_packet_idx];
+ eth_hdr = (struct ethernet_hdr *)nt->receive_buffer[nt->rx_packet_idx];
protlen = ntohs(eth_hdr->et_protlen);
if (protlen == 0x8100) {
hdr_size += 4;
- protlen = ntohs(*(u16 *)&receive_buffer[rx_packet_idx][hdr_size - 2]);
+ protlen = ntohs(*(u16 *)&nt->receive_buffer[nt->rx_packet_idx][hdr_size - 2]);
}
if (header_size)
*header_size = hdr_size;
@@ -654,20 +741,20 @@ static efi_status_t EFIAPI efi_net_receive
memcpy(src_addr, eth_hdr->et_src, ARP_HLEN);
if (protocol)
*protocol = protlen;
- if (*buffer_size < receive_lengths[rx_packet_idx]) {
+ if (*buffer_size < nt->receive_lengths[nt->rx_packet_idx]) {
/* Packet doesn't fit, try again with bigger buffer */
- *buffer_size = receive_lengths[rx_packet_idx];
+ *buffer_size = nt->receive_lengths[nt->rx_packet_idx];
ret = EFI_BUFFER_TOO_SMALL;
goto out;
}
/* Copy packet */
- memcpy(buffer, receive_buffer[rx_packet_idx],
- receive_lengths[rx_packet_idx]);
- *buffer_size = receive_lengths[rx_packet_idx];
- rx_packet_idx = (rx_packet_idx + 1) % ETH_PACKETS_BATCH_RECV;
- rx_packet_num--;
- if (rx_packet_num)
- wait_for_packet->is_signaled = true;
+ memcpy(buffer, nt->receive_buffer[nt->rx_packet_idx],
+ nt->receive_lengths[nt->rx_packet_idx]);
+ *buffer_size = nt->receive_lengths[nt->rx_packet_idx];
+ nt->rx_packet_idx = (nt->rx_packet_idx + 1) % ETH_PACKETS_BATCH_RECV;
+ nt->rx_packet_num--;
+ if (nt->rx_packet_num)
+ nt->wait_for_packet->is_signaled = true;
else
this->int_status &= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
out:
@@ -684,18 +771,35 @@ out:
*/
void efi_net_set_dhcp_ack(void *pkt, int len)
{
- int maxsize = sizeof(*dhcp_ack);
+ struct efi_pxe_packet **dhcp_ack;
+ struct udevice *dev;
+ int i;
- if (!dhcp_ack) {
- dhcp_ack = malloc(maxsize);
- if (!dhcp_ack)
+ dhcp_ack = &dhcp_cache[next_dhcp_entry].dhcp_ack;
+
+ /* For now this function gets called only by the current device */
+ dev = eth_get_dev();
+
+ int maxsize = sizeof(**dhcp_ack);
+
+ if (!*dhcp_ack) {
+ *dhcp_ack = malloc(maxsize);
+ if (!*dhcp_ack)
return;
}
- memset(dhcp_ack, 0, maxsize);
- memcpy(dhcp_ack, pkt, min(len, maxsize));
+ memset(*dhcp_ack, 0, maxsize);
+ memcpy(*dhcp_ack, pkt, min(len, maxsize));
+
+ dhcp_cache[next_dhcp_entry].is_valid = true;
+ dhcp_cache[next_dhcp_entry].dev = dev;
+ next_dhcp_entry++;
+ next_dhcp_entry %= MAX_NUM_DHCP_ENTRIES;
- if (netobj)
- netobj->pxe_mode.dhcp_ack = *dhcp_ack;
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && net_objs[i]->dev == dev) {
+ net_objs[i]->pxe_mode.dhcp_ack = **dhcp_ack;
+ }
+ }
}
/**
@@ -709,6 +813,11 @@ void efi_net_set_dhcp_ack(void *pkt, int len)
static void efi_net_push(void *pkt, int len)
{
int rx_packet_next;
+ struct efi_net_obj *nt;
+
+ nt = net_objs[curr_efi_net_obj];
+ if (!nt)
+ return;
/* Check that we at least received an Ethernet header */
if (len < sizeof(struct ethernet_hdr))
@@ -719,15 +828,15 @@ static void efi_net_push(void *pkt, int len)
return;
/* Can't store more than pre-alloced buffer */
- if (rx_packet_num >= ETH_PACKETS_BATCH_RECV)
+ if (nt->rx_packet_num >= ETH_PACKETS_BATCH_RECV)
return;
- rx_packet_next = (rx_packet_idx + rx_packet_num) %
+ rx_packet_next = (nt->rx_packet_idx + nt->rx_packet_num) %
ETH_PACKETS_BATCH_RECV;
- memcpy(receive_buffer[rx_packet_next], pkt, len);
- receive_lengths[rx_packet_next] = len;
+ memcpy(nt->receive_buffer[rx_packet_next], pkt, len);
+ nt->receive_lengths[rx_packet_next] = len;
- rx_packet_num++;
+ nt->rx_packet_num++;
}
/**
@@ -742,6 +851,7 @@ static void EFIAPI efi_network_timer_notify(struct efi_event *event,
void *context)
{
struct efi_simple_network *this = (struct efi_simple_network *)context;
+ struct efi_net_obj *nt;
EFI_ENTRY("%p, %p", event, context);
@@ -752,14 +862,19 @@ static void EFIAPI efi_network_timer_notify(struct efi_event *event,
if (!this || this->mode->state != EFI_NETWORK_INITIALIZED)
goto out;
- if (!rx_packet_num) {
+ nt = efi_netobj_from_snp(this);
+ curr_efi_net_obj = nt->efi_seq_num;
+
+ if (!nt->rx_packet_num) {
+ eth_set_dev(nt->dev);
+ env_set("ethact", eth_get_name());
push_packet = efi_net_push;
eth_rx();
push_packet = NULL;
- if (rx_packet_num) {
+ if (nt->rx_packet_num) {
this->int_status |=
EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
- wait_for_packet->is_signaled = true;
+ nt->wait_for_packet->is_signaled = true;
}
}
out:
@@ -879,30 +994,179 @@ static efi_status_t EFIAPI efi_pxe_base_code_set_packets(
}
/**
+ * efi_netobj_set_dp() - set device path of a netobj
+ *
+ * @netobj: pointer to efi_net_obj
+ * @dp: device path to set, allocated by caller
+ * Return: status code
+ */
+efi_status_t efi_netobj_set_dp(struct efi_net_obj *netobj, struct efi_device_path *dp)
+{
+ efi_status_t ret;
+ struct efi_handler *phandler;
+ struct efi_device_path *new_net_dp;
+
+ if (!efi_netobj_is_active(netobj))
+ return EFI_SUCCESS;
+
+ // Create a device path for the netobj
+ new_net_dp = dp;
+ if (!new_net_dp)
+ return EFI_OUT_OF_RESOURCES;
+
+ phandler = NULL;
+ efi_search_protocol(&netobj->header, &efi_guid_device_path, &phandler);
+
+ // If the device path protocol is not yet installed, install it
+ if (!phandler)
+ goto add;
+
+ // If it is already installed, try to update it
+ ret = efi_reinstall_protocol_interface(&netobj->header, &efi_guid_device_path,
+ phandler->protocol_interface, new_net_dp);
+ if (ret != EFI_SUCCESS)
+ return ret;
+
+ return EFI_SUCCESS;
+add:
+ ret = efi_add_protocol(&netobj->header, &efi_guid_device_path,
+ new_net_dp);
+ if (ret != EFI_SUCCESS)
+ return ret;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ * efi_netobj_get_dp() - get device path of a netobj
+ *
+ * @netobj: pointer to efi_net_obj
+ * Return: device path, NULL on error
+ */
+static struct efi_device_path *efi_netobj_get_dp(struct efi_net_obj *netobj)
+{
+ struct efi_handler *phandler;
+
+ if (!efi_netobj_is_active(netobj))
+ return NULL;
+
+ phandler = NULL;
+ efi_search_protocol(&netobj->header, &efi_guid_device_path, &phandler);
+
+ if (phandler && phandler->protocol_interface)
+ return efi_dp_dup(phandler->protocol_interface);
+
+ return NULL;
+}
+
+/**
+ * efi_net_do_start() - start the efi network stack
+ *
+ * This gets called from do_bootefi_exec() each time a payload gets executed.
+ *
+ * @dev: net udevice
+ * Return: status code
+ */
+efi_status_t efi_net_do_start(struct udevice *dev)
+{
+ efi_status_t r = EFI_SUCCESS;
+ struct efi_net_obj *netobj;
+ struct efi_device_path *net_dp;
+ int i;
+
+ netobj = NULL;
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && net_objs[i]->dev == dev) {
+ netobj = net_objs[i];
+ break;
+ }
+ }
+
+ if (!efi_netobj_is_active(netobj))
+ return r;
+
+ efi_net_dp_from_dev(&net_dp, netobj->dev, true);
+ // If no dp cache entry applies and there already
+ // is a device path installed, continue
+ if (!net_dp) {
+ if (efi_netobj_get_dp(netobj))
+ goto set_addr;
+ else
+ net_dp = efi_dp_from_eth(netobj->dev);
+
+ }
+
+ if (!net_dp)
+ return EFI_OUT_OF_RESOURCES;
+
+ r = efi_netobj_set_dp(netobj, net_dp);
+ if (r != EFI_SUCCESS)
+ return r;
+set_addr:
+#ifdef CONFIG_EFI_HTTP_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, dev);
+#endif
+
+ return r;
+}
+
+/**
* efi_net_register() - register the simple network protocol
*
* This gets called from do_bootefi_exec().
+ * @dev: net udevice
*/
-efi_status_t efi_net_register(void)
+efi_status_t efi_net_register(struct udevice *dev)
{
efi_status_t r;
- int i;
-
- if (!eth_get_dev()) {
+ int seq_num;
+ struct efi_net_obj *netobj;
+ void *transmit_buffer = NULL;
+ uchar **receive_buffer = NULL;
+ size_t *receive_lengths;
+ int i, j;
+
+ if (!dev) {
/* No network device active, don't expose any */
return EFI_SUCCESS;
}
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && net_objs[i]->dev == dev) {
+ // Do not register duplicate devices
+ return EFI_SUCCESS;
+ }
+ }
+
+ seq_num = -1;
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (!net_objs[i]) {
+ seq_num = i;
+ break;
+ }
+ }
+ if (seq_num < 0)
+ return EFI_OUT_OF_RESOURCES;
+
/* We only expose the "active" network device, so one is enough */
netobj = calloc(1, sizeof(*netobj));
if (!netobj)
goto out_of_resources;
+ netobj->dev = dev;
+
/* Allocate an aligned transmit buffer */
transmit_buffer = calloc(1, PKTSIZE_ALIGN + PKTALIGN);
if (!transmit_buffer)
goto out_of_resources;
transmit_buffer = (void *)ALIGN((uintptr_t)transmit_buffer, PKTALIGN);
+ netobj->transmit_buffer = transmit_buffer;
/* Allocate a number of receive buffers */
receive_buffer = calloc(ETH_PACKETS_BATCH_RECV,
@@ -914,10 +1178,13 @@ efi_status_t efi_net_register(void)
if (!receive_buffer[i])
goto out_of_resources;
}
+ netobj->receive_buffer = receive_buffer;
+
receive_lengths = calloc(ETH_PACKETS_BATCH_RECV,
sizeof(*receive_lengths));
if (!receive_lengths)
goto out_of_resources;
+ netobj->receive_lengths = receive_lengths;
/* Hook net up to the device list */
efi_add_handle(&netobj->header);
@@ -928,14 +1195,6 @@ efi_status_t efi_net_register(void)
if (r != EFI_SUCCESS)
goto failure_to_add_protocol;
- if (net_dp)
- r = efi_add_protocol(&netobj->header, &efi_guid_device_path,
- net_dp);
- else
- r = efi_net_set_dp("Net", NULL);
- if (r != EFI_SUCCESS)
- goto failure_to_add_protocol;
-
r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid,
&netobj->pxe);
if (r != EFI_SUCCESS)
@@ -956,7 +1215,9 @@ efi_status_t efi_net_register(void)
netobj->net.receive = efi_net_receive;
netobj->net.mode = &netobj->net_mode;
netobj->net_mode.state = EFI_NETWORK_STOPPED;
- memcpy(netobj->net_mode.current_address.mac_addr, eth_get_ethaddr(), 6);
+ if (dev_get_plat(dev))
+ memcpy(netobj->net_mode.current_address.mac_addr,
+ ((struct eth_pdata *)dev_get_plat(dev))->enetaddr, 6);
netobj->net_mode.hwaddr_size = ARP_HLEN;
netobj->net_mode.media_header_size = ETHER_HDR_SIZE;
netobj->net_mode.max_packet_size = PKTSIZE;
@@ -976,20 +1237,31 @@ efi_status_t efi_net_register(void)
netobj->pxe.set_station_ip = efi_pxe_base_code_set_station_ip;
netobj->pxe.set_packets = efi_pxe_base_code_set_packets;
netobj->pxe.mode = &netobj->pxe_mode;
- if (dhcp_ack)
- netobj->pxe_mode.dhcp_ack = *dhcp_ack;
+
+ /*
+ * Scan dhcp entries for one corresponding
+ * to this udevice, from newest to oldest
+ */
+ i = (next_dhcp_entry + MAX_NUM_DHCP_ENTRIES - 1) % MAX_NUM_DHCP_ENTRIES;
+ for (j = 0; dhcp_cache[i].is_valid && j < MAX_NUM_DHCP_ENTRIES;
+ i = (i + MAX_NUM_DHCP_ENTRIES - 1) % MAX_NUM_DHCP_ENTRIES, j++) {
+ if (dev == dhcp_cache[i].dev) {
+ netobj->pxe_mode.dhcp_ack = *dhcp_cache[i].dhcp_ack;
+ break;
+ }
+ }
/*
* Create WaitForPacket event.
*/
r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
efi_network_timer_notify, NULL, NULL,
- &wait_for_packet);
+ &netobj->wait_for_packet);
if (r != EFI_SUCCESS) {
printf("ERROR: Failed to register network event\n");
return r;
}
- netobj->net.wait_for_packet = wait_for_packet;
+ netobj->net.wait_for_packet = netobj->wait_for_packet;
/*
* Create a timer event.
*
@@ -1000,13 +1272,13 @@ efi_status_t efi_net_register(void)
*/
r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
efi_network_timer_notify, &netobj->net, NULL,
- &network_timer_event);
+ &netobj->network_timer_event);
if (r != EFI_SUCCESS) {
printf("ERROR: Failed to register network event\n");
return r;
}
/* Network is time critical, create event in every timer cycle */
- r = efi_set_timer(network_timer_event, EFI_TIMER_PERIODIC, 0);
+ r = efi_set_timer(netobj->network_timer_event, EFI_TIMER_PERIODIC, 0);
if (r != EFI_SUCCESS) {
printf("ERROR: Failed to set network timer\n");
return r;
@@ -1022,15 +1294,9 @@ efi_status_t efi_net_register(void)
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
-
+ netobj->efi_seq_num = seq_num;
+ net_objs[seq_num] = netobj;
return EFI_SUCCESS;
failure_to_add_protocol:
printf("ERROR: Failure to add protocol\n");
@@ -1049,86 +1315,103 @@ out_of_resources:
}
/**
- * efi_net_set_dp() - set device path of efi net device
+ * efi_net_new_dp() - update device path associated to a net udevice
*
* This gets called to update the device path when a new boot
* file is downloaded
*
* @dev: dev to set the device path from
* @server: remote server address
+ * @udev: net udevice
* Return: status code
*/
-efi_status_t efi_net_set_dp(const char *dev, const char *server)
+efi_status_t efi_net_new_dp(const char *dev, const char *server, struct udevice *udev)
{
- efi_status_t ret = EFI_SUCCESS;
- struct efi_handler *phandler;
+ efi_status_t ret;
+ struct efi_net_obj *netobj;
struct efi_device_path *old_net_dp, *new_net_dp;
+ struct efi_device_path **dp;
+ int i;
- old_net_dp = net_dp;
+ dp = &dp_cache[next_dp_entry].net_dp;
+
+ dp_cache[next_dp_entry].dev = udev;
+ dp_cache[next_dp_entry].is_valid = true;
+ next_dp_entry++;
+ next_dp_entry %= MAX_NUM_DP_ENTRIES;
+
+ old_net_dp = *dp;
new_net_dp = NULL;
if (!strcmp(dev, "Net"))
- new_net_dp = efi_dp_from_eth();
+ new_net_dp = efi_dp_from_eth(udev);
else if (!strcmp(dev, "Http"))
- new_net_dp = efi_dp_from_http(server);
-
- if (!new_net_dp) {
+ new_net_dp = efi_dp_from_http(server, udev);
+ if (!new_net_dp)
return EFI_OUT_OF_RESOURCES;
- }
-
- // If netobj is not started yet, end here.
- if (!netobj) {
- goto exit;
- }
-
- phandler = NULL;
- efi_search_protocol(&netobj->header, &efi_guid_device_path, &phandler);
- // If the device path protocol is not yet installed, install it
- if (!phandler)
- goto add;
-
- // If it is already installed, try to update it
- ret = efi_reinstall_protocol_interface(&netobj->header, &efi_guid_device_path,
- old_net_dp, new_net_dp);
- if (ret != EFI_SUCCESS)
- goto error;
-
- net_dp = new_net_dp;
+ *dp = new_net_dp;
+ // Free the old cache entry
efi_free_pool(old_net_dp);
- return EFI_SUCCESS;
-add:
- ret = efi_add_protocol(&netobj->header, &efi_guid_device_path,
- new_net_dp);
- if (ret != EFI_SUCCESS)
- goto error;
-exit:
- net_dp = new_net_dp;
- efi_free_pool(old_net_dp);
+ netobj = NULL;
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && net_objs[i]->dev == udev) {
+ netobj = net_objs[i];
+ break;
+ }
+ }
+ if (!netobj)
+ return EFI_SUCCESS;
- return ret;
-error:
- // Failed, restore
- efi_free_pool(new_net_dp);
+ new_net_dp = efi_dp_dup(*dp);
+ if (!new_net_dp)
+ return EFI_OUT_OF_RESOURCES;
+ ret = efi_netobj_set_dp(netobj, new_net_dp);
+ if (ret != EFI_SUCCESS)
+ efi_free_pool(new_net_dp);
return ret;
}
/**
- * efi_net_get_dp() - get device path of efi net device
+ * efi_net_dp_from_dev() - get device path associated to a net udevice
*
* Produce a copy of the current device path
*
- * @dp: copy of the current device path, or NULL on error
+ * @dp: copy of the current device path
+ * @udev: net udevice
+ * @cache_only: get device path from cache only
*/
-void efi_net_get_dp(struct efi_device_path **dp)
+void efi_net_dp_from_dev(struct efi_device_path **dp, struct udevice *udev, bool cache_only)
{
+ int i, j;
+
if (!dp)
return;
- if (!net_dp)
- efi_net_set_dp("Net", NULL);
- if (net_dp)
- *dp = efi_dp_dup(net_dp);
+
+ *dp = NULL;
+
+ if (cache_only)
+ goto cache;
+
+ // If a netobj matches:
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && net_objs[i]->dev == udev) {
+ *dp = efi_netobj_get_dp(net_objs[i]);
+ if (*dp)
+ return;
+ }
+ }
+cache:
+ // Search in the cache
+ i = (next_dp_entry + MAX_NUM_DP_ENTRIES - 1) % MAX_NUM_DP_ENTRIES;
+ for (j = 0; dp_cache[i].is_valid && j < MAX_NUM_DP_ENTRIES;
+ i = (i + MAX_NUM_DP_ENTRIES - 1) % MAX_NUM_DP_ENTRIES, j++) {
+ if (dp_cache[i].dev == udev) {
+ *dp = efi_dp_dup(dp_cache[i].net_dp);
+ return;
+ }
+ }
}
/**
@@ -1144,11 +1427,15 @@ void efi_net_get_dp(struct efi_device_path **dp)
* be filled with the current network mask
* @gw: pointer to an efi_ipv4_address struct to be
* filled with the current network gateway
+ * @dev: udevice
*/
void efi_net_get_addr(struct efi_ipv4_address *ip,
struct efi_ipv4_address *mask,
- struct efi_ipv4_address *gw)
+ struct efi_ipv4_address *gw,
+ struct udevice *dev)
{
+ if (!dev)
+ dev = eth_get_dev();
#ifdef CONFIG_NET_LWIP
char ipstr[] = "ipaddr\0\0";
char maskstr[] = "netmask\0\0";
@@ -1157,7 +1444,7 @@ void efi_net_get_addr(struct efi_ipv4_address *ip,
struct in_addr tmp;
char *env;
- idx = dev_seq(eth_get_dev());
+ idx = dev_seq(dev);
if (idx < 0 || idx > 99) {
log_err("unexpected idx %d\n", idx);
@@ -1204,11 +1491,15 @@ void efi_net_get_addr(struct efi_ipv4_address *ip,
* @ip: pointer to new IP address
* @mask: pointer to new network mask to set
* @gw: pointer to new network gateway
+ * @dev: udevice
*/
void efi_net_set_addr(struct efi_ipv4_address *ip,
struct efi_ipv4_address *mask,
- struct efi_ipv4_address *gw)
+ struct efi_ipv4_address *gw,
+ struct udevice *dev)
{
+ if (!dev)
+ dev = eth_get_dev();
#ifdef CONFIG_NET_LWIP
char ipstr[] = "ipaddr\0\0";
char maskstr[] = "netmask\0\0";
@@ -1217,7 +1508,7 @@ void efi_net_set_addr(struct efi_ipv4_address *ip,
struct in_addr *addr;
char tmp[46];
- idx = dev_seq(eth_get_dev());
+ idx = dev_seq(dev);
if (idx < 0 || idx > 99) {
log_err("unexpected idx %d\n", idx);
@@ -1255,6 +1546,7 @@ void efi_net_set_addr(struct efi_ipv4_address *ip,
#endif
}
+#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL)
/**
* efi_net_set_buffer() - allocate a buffer of min 64K
*
@@ -1342,26 +1634,41 @@ void efi_net_parse_headers(ulong *num_headers, struct http_header *headers)
* @status_code: HTTP status code
* @file_size: file size in bytes
* @headers_buffer: headers buffer
+ * @parent: service binding protocol
* Return: status code
*/
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)
+ u32 *status_code, ulong *file_size, char *headers_buffer,
+ struct efi_service_binding_protocol *parent)
{
efi_status_t ret = EFI_SUCCESS;
int wget_ret;
static bool last_head;
+ struct udevice *dev;
+ int i;
- if (!buffer || !file_size)
+ if (!buffer || !file_size || !parent)
return EFI_ABORTED;
efi_wget_info.method = (enum wget_http_method)method;
efi_wget_info.headers = headers_buffer;
+ // Set corresponding udevice
+ dev = NULL;
+ for (i = 0; i < MAX_EFI_NET_OBJS; i++) {
+ if (net_objs[i] && &net_objs[i]->http_service_binding == parent)
+ dev = net_objs[i]->dev;
+ }
+ if (!dev)
+ return EFI_ABORTED;
+
switch (method) {
case HTTP_METHOD_GET:
ret = efi_net_set_buffer(buffer, last_head ? (size_t)efi_wget_info.hdr_cont_len : 0);
if (ret != EFI_SUCCESS)
goto out;
+ eth_set_dev(dev);
+ env_set("ethact", eth_get_name());
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
@@ -1369,6 +1676,8 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf
ret = efi_net_set_buffer(buffer, (size_t)efi_wget_info.hdr_cont_len);
if (ret != EFI_SUCCESS)
goto out;
+ eth_set_dev(dev);
+ env_set("ethact", eth_get_name());
if (wget_request((ulong)*buffer, url, &efi_wget_info)) {
efi_free_pool(*buffer);
ret = EFI_DEVICE_ERROR;
@@ -1388,6 +1697,8 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf
ret = efi_net_set_buffer(buffer, 0);
if (ret != EFI_SUCCESS)
goto out;
+ eth_set_dev(dev);
+ env_set("ethact", eth_get_name());
wget_request((ulong)*buffer, url, &efi_wget_info);
*file_size = 0;
*status_code = efi_wget_info.status_code;
@@ -1401,3 +1712,4 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf
out:
return ret;
}
+#endif
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index aa59bc7779d..48f91da5df7 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -11,7 +11,9 @@
#include <efi_variable.h>
#include <log.h>
#include <asm-generic/unaligned.h>
+#include <net.h>
+#define OBJ_LIST_INITIALIZED 0
#define OBJ_LIST_NOT_INITIALIZED 1
efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
@@ -209,6 +211,21 @@ out:
}
/**
+ * efi_start_obj_list() - Start EFI object list
+ *
+ * Return: status code
+ */
+static efi_status_t efi_start_obj_list(void)
+{
+ efi_status_t ret = EFI_SUCCESS;
+
+ if (IS_ENABLED(CONFIG_NETDEVICES))
+ ret = efi_net_do_start(eth_get_dev());
+
+ return ret;
+}
+
+/**
* efi_init_obj_list() - Initialize and populate EFI object list
*
* Return: status code
@@ -217,7 +234,9 @@ efi_status_t efi_init_obj_list(void)
{
efi_status_t ret = EFI_SUCCESS;
- /* Initialize once only */
+ /* Initialize only once, but start every time if correctly initialized*/
+ if (efi_obj_list_initialized == OBJ_LIST_INITIALIZED)
+ return efi_start_obj_list();
if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
return efi_obj_list_initialized;
@@ -318,7 +337,7 @@ efi_status_t efi_init_obj_list(void)
goto out;
}
if (IS_ENABLED(CONFIG_NETDEVICES)) {
- ret = efi_net_register();
+ ret = efi_net_register(eth_get_dev());
if (ret != EFI_SUCCESS)
goto out;
}
@@ -349,6 +368,10 @@ efi_status_t efi_init_obj_list(void)
if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK) &&
!IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY))
ret = efi_launch_capsules();
+ if (ret != EFI_SUCCESS)
+ goto out;
+
+ ret = efi_start_obj_list();
out:
efi_obj_list_initialized = ret;
return ret;