iPXE
efi_fdt.c File Reference

EFI Flattened Device Tree. More...

#include <string.h>
#include <byteswap.h>
#include <ipxe/fdt.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_table.h>
#include <ipxe/efi/efi_fdt.h>
#include <ipxe/efi/Guid/Fdt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
 EFI_USE_TABLE (FDT_TABLE, &efi_fdt, 0)
static void efi_fdt_init (void)
 Initialise EFI Flattened Device Tree.
struct init_fn efi_fdt_init_fn __init_fn (INIT_EARLY)
 EFI Flattened Device Tree initialisation function.
static size_t efi_fdt_len (const void *data)
 Determine length of EFI Flattened Device Tree.
int efi_fdt_install (const char *cmdline)
 Install EFI Flattened Device Tree table.
int efi_fdt_uninstall (void)
 Uninstall EFI Flattened Device Tree table.

Variables

static struct fdt_headerefi_fdt
 EFI Flattened Device Tree configuration table.
static struct efi_table efi_fdt_table
 EFI Flattened Device Tree table type.
static void * efi_fdt_backup
 EFI Flattened Device Tree table backup.
static struct fdt_headerefi_fdt_installed
 EFI Flattened Device Tree installed table.

Detailed Description

EFI Flattened Device Tree.

Definition in file efi_fdt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ EFI_USE_TABLE()

EFI_USE_TABLE ( FDT_TABLE ,
& efi_fdt,
0  )

References efi_fdt.

◆ efi_fdt_init()

void efi_fdt_init ( void )
static

Initialise EFI Flattened Device Tree.

Definition at line 50 of file efi_fdt.c.

50 {
51 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
52 EFI_STATUS efirc;
53 int rc;
54
55 /* Do nothing if no configuration table is present */
56 if ( ! efi_fdt ) {
57 DBGC ( &efi_fdt, "EFIFDT has no configuration table\n" );
58 return;
59 }
60 DBGC ( &efi_fdt, "EFIFDT configuration table at %p\n", efi_fdt );
61
62 /* Parse as system device tree */
63 if ( ( rc = fdt_parse ( &sysfdt, efi_fdt, -1UL ) ) != 0 ) {
64 DBGC ( &efi_fdt, "EFIFDT could not parse: %s\n",
65 strerror ( rc ) );
66 return;
67 }
68
69 /* Create copy, since table may be removed at any time */
70 if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, sysfdt.len,
71 &sysfdt.raw ) ) != 0 ) {
72 DBGC ( &efi_fdt, "EFIFDT could not create copy\n" );
73 sysfdt.len = 0;
74 return;
75 }
76 memcpy ( sysfdt.raw, efi_fdt, sysfdt.len );
77}
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
@ EfiBootServicesData
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static struct fdt_header * efi_fdt
EFI Flattened Device Tree configuration table.
Definition efi_fdt.c:43
int fdt_parse(struct fdt *fdt, struct fdt_header *hdr, size_t max_len)
Parse device tree.
Definition fdt.c:904
struct fdt sysfdt
The system flattened device tree (if present)
Definition fdt.c:45
#define DBGC(...)
Definition compiler.h:505
EFI_SYSTEM_TABLE * efi_systab
void * memcpy(void *dest, const void *src, size_t len) __nonnull
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_ALLOCATE_POOL AllocatePool
Definition UefiSpec.h:1949

References EFI_BOOT_SERVICES::AllocatePool, DBGC, efi_fdt, efi_systab, EfiBootServicesData, fdt_parse(), memcpy(), rc, strerror(), and sysfdt.

Referenced by __init_fn().

◆ __init_fn()

struct init_fn efi_fdt_init_fn __init_fn ( INIT_EARLY )

EFI Flattened Device Tree initialisation function.

References __init_fn, efi_fdt_init(), and INIT_EARLY.

◆ efi_fdt_len()

size_t efi_fdt_len ( const void * data)
static

Determine length of EFI Flattened Device Tree.

Parameters
dataConfiguration table data (presumed valid)
Return values
lenLength of table

Definition at line 91 of file efi_fdt.c.

91 {
92 const struct fdt_header *hdr = data;
93
94 return be32_to_cpu ( hdr->totalsize );
95}
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define be32_to_cpu(value)
Definition byteswap.h:117
Device tree header.
Definition fdt.h:19

References be32_to_cpu, data, and hdr.

◆ efi_fdt_install()

int efi_fdt_install ( const char * cmdline)

Install EFI Flattened Device Tree table.

Parameters
cmdlineCommand line, or NULL
Return values
rcReturn status code

Definition at line 115 of file efi_fdt.c.

115 {
116 int rc;
117
118 /* Create device tree */
119 if ( ( rc = fdt_create ( &efi_fdt_installed, cmdline, 0, 0 ) ) != 0 ) {
120 DBGC ( &efi_fdt, "EFI_FDT could not install: %s\n",
121 strerror ( rc ) );
122 goto err_create;
123 }
124
125 /* Install table */
127 &efi_fdt_backup ) ) != 0 ) {
128 DBGC ( &efi_fdt, "EFIFDT could not install: %s\n",
129 strerror ( rc ) );
130 goto err_install;
131 }
132
133 return 0;
134
136 err_install:
138 err_create:
139 return rc;
140}
static struct efi_table efi_fdt_table
EFI Flattened Device Tree table type.
Definition efi_fdt.c:98
static void * efi_fdt_backup
EFI Flattened Device Tree table backup.
Definition efi_fdt.c:104
static struct fdt_header * efi_fdt_installed
EFI Flattened Device Tree installed table.
Definition efi_fdt.c:107
int efi_install_table(struct efi_table *table, const void *data, void **backup)
Install EFI configuration table.
Definition efi_table.c:71
int efi_uninstall_table(struct efi_table *table, void **backup)
Uninstall EFI configuration table.
Definition efi_table.c:162
void fdt_remove(struct fdt_header *hdr)
Remove device tree.
Definition fdt.c:1459
int fdt_create(struct fdt_header **hdr, const char *cmdline, physaddr_t initrd, size_t initrd_len)
Create device tree.
Definition fdt.c:1408
uint32_t cmdline
Definition multiboot.h:4

References cmdline, DBGC, efi_fdt, efi_fdt_backup, efi_fdt_installed, efi_fdt_table, efi_install_table(), efi_uninstall_table(), fdt_create(), fdt_remove(), rc, and strerror().

◆ efi_fdt_uninstall()

int efi_fdt_uninstall ( void )

Uninstall EFI Flattened Device Tree table.

Uninstall EFI Flattened Device Tree table (when no FDT support is present)

Return values
rcReturn status code

Definition at line 147 of file efi_fdt.c.

147 {
148 int rc;
149
150 /* Uninstall table */
152 &efi_fdt_backup ) ) != 0 ) {
153 DBGC ( &efi_fdt, "EFIFDT could not %sinstall: %s\n",
154 ( efi_fdt_backup ? "re" : "un" ), strerror ( rc ) );
155 /* Leak memory: there is nothing else we can do */
156 return rc;
157 }
158
159 /* Remove table */
161
162 return 0;
163}

References DBGC, efi_fdt, efi_fdt_backup, efi_fdt_installed, efi_fdt_table, efi_uninstall_table(), fdt_remove(), rc, and strerror().

Variable Documentation

◆ efi_fdt

struct fdt_header* efi_fdt
static

EFI Flattened Device Tree configuration table.

Definition at line 43 of file efi_fdt.c.

Referenced by efi_fdt_init(), efi_fdt_install(), efi_fdt_uninstall(), EFI_USE_TABLE(), and PROVIDE_REQUIRING_SYMBOL().

◆ efi_fdt_table

struct efi_table efi_fdt_table
static
Initial value:
= {
.len = efi_fdt_len,
}
static size_t efi_fdt_len(const void *data)
Determine length of EFI Flattened Device Tree.
Definition efi_fdt.c:91
EFI_GUID efi_fdt_table_guid
FDT table GUID.
Definition efi_guid.c:449

EFI Flattened Device Tree table type.

Definition at line 98 of file efi_fdt.c.

98 {
99 .guid = &efi_fdt_table_guid,
100 .len = efi_fdt_len,
101};

Referenced by efi_fdt_install(), and efi_fdt_uninstall().

◆ efi_fdt_backup

void* efi_fdt_backup
static

EFI Flattened Device Tree table backup.

Definition at line 104 of file efi_fdt.c.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().

◆ efi_fdt_installed

struct fdt_header* efi_fdt_installed
static

EFI Flattened Device Tree installed table.

Definition at line 107 of file efi_fdt.c.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().