efi_loader.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * EFI application loader
  4. *
  5. * Copyright (c) 2016 Alexander Graf
  6. */
  7. #ifndef _EFI_LOADER_H
  8. #define _EFI_LOADER_H 1
  9. #include <common.h>
  10. #include <blk.h>
  11. #include <event.h>
  12. #include <log.h>
  13. #include <part_efi.h>
  14. #include <efi_api.h>
  15. #include <image.h>
  16. #include <pe.h>
  17. #include <linux/list.h>
  18. #include <linux/oid_registry.h>
  19. struct blk_desc;
  20. struct jmp_buf_data;
  21. static inline int guidcmp(const void *g1, const void *g2)
  22. {
  23. return memcmp(g1, g2, sizeof(efi_guid_t));
  24. }
  25. static inline void *guidcpy(void *dst, const void *src)
  26. {
  27. return memcpy(dst, src, sizeof(efi_guid_t));
  28. }
  29. #if CONFIG_IS_ENABLED(EFI_LOADER)
  30. /**
  31. * __efi_runtime_data - declares a non-const variable for EFI runtime section
  32. *
  33. * This macro indicates that a variable is non-const and should go into the
  34. * EFI runtime section, and thus still be available when the OS is running.
  35. *
  36. * Only use on variables not declared const.
  37. *
  38. * Example:
  39. *
  40. * ::
  41. *
  42. * static __efi_runtime_data my_computed_table[256];
  43. */
  44. #define __efi_runtime_data __section(".data.efi_runtime")
  45. /**
  46. * __efi_runtime_rodata - declares a read-only variable for EFI runtime section
  47. *
  48. * This macro indicates that a variable is read-only (const) and should go into
  49. * the EFI runtime section, and thus still be available when the OS is running.
  50. *
  51. * Only use on variables also declared const.
  52. *
  53. * Example:
  54. *
  55. * ::
  56. *
  57. * static const __efi_runtime_rodata my_const_table[] = { 1, 2, 3 };
  58. */
  59. #define __efi_runtime_rodata __section(".rodata.efi_runtime")
  60. /**
  61. * __efi_runtime - declares a function for EFI runtime section
  62. *
  63. * This macro indicates that a function should go into the EFI runtime section,
  64. * and thus still be available when the OS is running.
  65. *
  66. * Example:
  67. *
  68. * ::
  69. *
  70. * static __efi_runtime compute_my_table(void);
  71. */
  72. #define __efi_runtime __section(".text.efi_runtime")
  73. /*
  74. * Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
  75. * to make it available at runtime
  76. */
  77. efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
  78. /*
  79. * Special case handler for error/abort that just tries to dtrt to get
  80. * back to u-boot world
  81. */
  82. void efi_restore_gd(void);
  83. /* Call this to set the current device name */
  84. void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
  85. void *buffer, size_t buffer_size);
  86. /* Called by networking code to memorize the dhcp ack package */
  87. void efi_net_set_dhcp_ack(void *pkt, int len);
  88. /* Print information about all loaded images */
  89. void efi_print_image_infos(void *pc);
  90. /* Hook at initialization */
  91. efi_status_t efi_launch_capsules(void);
  92. #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
  93. /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
  94. #define __efi_runtime_data
  95. #define __efi_runtime_rodata
  96. #define __efi_runtime
  97. static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
  98. {
  99. return EFI_SUCCESS;
  100. }
  101. /* No loader configured, stub out EFI_ENTRY */
  102. static inline void efi_restore_gd(void) { }
  103. static inline void efi_set_bootdev(const char *dev, const char *devnr,
  104. const char *path, void *buffer,
  105. size_t buffer_size) { }
  106. static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
  107. static inline void efi_print_image_infos(void *pc) { }
  108. static inline efi_status_t efi_launch_capsules(void)
  109. {
  110. return EFI_SUCCESS;
  111. }
  112. #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
  113. /* Maximum number of configuration tables */
  114. #define EFI_MAX_CONFIGURATION_TABLES 16
  115. /* GUID used by the root node */
  116. #define U_BOOT_GUID \
  117. EFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \
  118. 0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b)
  119. /* GUID used as root for blkmap devices */
  120. #define U_BOOT_BLKMAP_DEV_GUID \
  121. EFI_GUID(0x4cad859d, 0xd644, 0x42ff, \
  122. 0x87, 0x0b, 0xc0, 0x2e, 0xac, 0x05, 0x58, 0x63)
  123. /* GUID used as host device on sandbox */
  124. #define U_BOOT_HOST_DEV_GUID \
  125. EFI_GUID(0xbbe4e671, 0x5773, 0x4ea1, \
  126. 0x9a, 0xab, 0x3a, 0x7d, 0xbf, 0x40, 0xc4, 0x82)
  127. /* GUID used as root for virtio devices */
  128. #define U_BOOT_VIRTIO_DEV_GUID \
  129. EFI_GUID(0x63293792, 0xadf5, 0x9325, \
  130. 0xb9, 0x9f, 0x4e, 0x0e, 0x45, 0x5c, 0x1b, 0x1e)
  131. /* GUID for the auto generated boot menu entry */
  132. #define EFICONFIG_AUTO_GENERATED_ENTRY_GUID \
  133. EFI_GUID(0x38c1acc1, 0x9fc0, 0x41f0, \
  134. 0xb9, 0x01, 0xfa, 0x74, 0xd6, 0xd6, 0xe4, 0xde)
  135. /* Use internal device tree when starting UEFI application */
  136. #define EFI_FDT_USE_INTERNAL NULL
  137. /* Root node */
  138. extern efi_handle_t efi_root;
  139. /* Set to EFI_SUCCESS when initialized */
  140. extern efi_status_t efi_obj_list_initialized;
  141. /* Flag used by the selftest to avoid detaching devices in ExitBootServices() */
  142. extern bool efi_st_keep_devices;
  143. /* EFI system partition */
  144. extern struct efi_system_partition {
  145. enum uclass_id uclass_id;
  146. int devnum;
  147. u8 part;
  148. } efi_system_partition;
  149. int __efi_entry_check(void);
  150. int __efi_exit_check(void);
  151. const char *__efi_nesting(void);
  152. const char *__efi_nesting_inc(void);
  153. const char *__efi_nesting_dec(void);
  154. /*
  155. * Enter the u-boot world from UEFI:
  156. */
  157. #define EFI_ENTRY(format, ...) do { \
  158. assert(__efi_entry_check()); \
  159. debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
  160. __func__, ##__VA_ARGS__); \
  161. } while(0)
  162. /*
  163. * Exit the u-boot world back to UEFI:
  164. */
  165. #define EFI_EXIT(ret) ({ \
  166. typeof(ret) _r = ret; \
  167. debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
  168. __func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
  169. assert(__efi_exit_check()); \
  170. _r; \
  171. })
  172. /*
  173. * Call non-void UEFI function from u-boot and retrieve return value:
  174. */
  175. #define EFI_CALL(exp) ({ \
  176. debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
  177. assert(__efi_exit_check()); \
  178. typeof(exp) _r = exp; \
  179. assert(__efi_entry_check()); \
  180. debug("%sEFI: %lu returned by %s\n", __efi_nesting_dec(), \
  181. (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK), #exp); \
  182. _r; \
  183. })
  184. /*
  185. * Call void UEFI function from u-boot:
  186. */
  187. #define EFI_CALL_VOID(exp) do { \
  188. debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
  189. assert(__efi_exit_check()); \
  190. exp; \
  191. assert(__efi_entry_check()); \
  192. debug("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
  193. } while(0)
  194. /*
  195. * Write an indented message with EFI prefix
  196. */
  197. #define EFI_PRINT(format, ...) ({ \
  198. debug("%sEFI: " format, __efi_nesting(), \
  199. ##__VA_ARGS__); \
  200. })
  201. #ifdef CONFIG_SYS_CACHELINE_SIZE
  202. #define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
  203. #else
  204. /* Just use the greatest cache flush alignment requirement I'm aware of */
  205. #define EFI_CACHELINE_SIZE 128
  206. #endif
  207. /* max bootmenu title size for volume selection */
  208. #define BOOTMENU_DEVICE_NAME_MAX 16
  209. /* Key identifying current memory map */
  210. extern efi_uintn_t efi_memory_map_key;
  211. extern struct efi_runtime_services efi_runtime_services;
  212. extern struct efi_system_table systab;
  213. extern struct efi_simple_text_output_protocol efi_con_out;
  214. extern struct efi_simple_text_input_protocol efi_con_in;
  215. extern struct efi_console_control_protocol efi_console_control;
  216. extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
  217. /* implementation of the EFI_DEVICE_PATH_UTILITIES_PROTOCOL */
  218. extern const struct efi_device_path_utilities_protocol
  219. efi_device_path_utilities;
  220. /* current version of the EFI_UNICODE_COLLATION_PROTOCOL */
  221. extern const struct efi_unicode_collation_protocol
  222. efi_unicode_collation_protocol2;
  223. extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
  224. extern const struct efi_hii_config_access_protocol efi_hii_config_access;
  225. extern const struct efi_hii_database_protocol efi_hii_database;
  226. extern const struct efi_hii_string_protocol efi_hii_string;
  227. uint16_t *efi_dp_str(struct efi_device_path *dp);
  228. /* GUID for the auto generated boot menu entry */
  229. extern const efi_guid_t efi_guid_bootmenu_auto_generated;
  230. /* GUID of the U-Boot root node */
  231. extern const efi_guid_t efi_u_boot_guid;
  232. #ifdef CONFIG_SANDBOX
  233. /* GUID of U-Boot host device on sandbox */
  234. extern const efi_guid_t efi_guid_host_dev;
  235. #endif
  236. /* GUID of the EFI_BLOCK_IO_PROTOCOL */
  237. extern const efi_guid_t efi_block_io_guid;
  238. extern const efi_guid_t efi_global_variable_guid;
  239. extern const efi_guid_t efi_guid_console_control;
  240. extern const efi_guid_t efi_guid_device_path;
  241. /* GUID of the EFI system partition */
  242. extern const efi_guid_t efi_system_partition_guid;
  243. /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
  244. extern const efi_guid_t efi_guid_driver_binding_protocol;
  245. /* event group ExitBootServices() invoked */
  246. extern const efi_guid_t efi_guid_event_group_exit_boot_services;
  247. /* event group SetVirtualAddressMap() invoked */
  248. extern const efi_guid_t efi_guid_event_group_virtual_address_change;
  249. /* event group memory map changed */
  250. extern const efi_guid_t efi_guid_event_group_memory_map_change;
  251. /* event group boot manager about to boot */
  252. extern const efi_guid_t efi_guid_event_group_ready_to_boot;
  253. /* event group ResetSystem() invoked (before ExitBootServices) */
  254. extern const efi_guid_t efi_guid_event_group_reset_system;
  255. /* GUID of the device tree table */
  256. extern const efi_guid_t efi_guid_fdt;
  257. extern const efi_guid_t efi_guid_loaded_image;
  258. extern const efi_guid_t efi_guid_loaded_image_device_path;
  259. extern const efi_guid_t efi_guid_device_path_to_text_protocol;
  260. extern const efi_guid_t efi_simple_file_system_protocol_guid;
  261. extern const efi_guid_t efi_file_info_guid;
  262. /* GUID for file system information */
  263. extern const efi_guid_t efi_file_system_info_guid;
  264. extern const efi_guid_t efi_guid_device_path_utilities_protocol;
  265. /* GUID of the deprecated Unicode collation protocol */
  266. extern const efi_guid_t efi_guid_unicode_collation_protocol;
  267. /* GUIDs of the Load File and Load File2 protocol */
  268. extern const efi_guid_t efi_guid_load_file_protocol;
  269. extern const efi_guid_t efi_guid_load_file2_protocol;
  270. /* GUID of the Unicode collation protocol */
  271. extern const efi_guid_t efi_guid_unicode_collation_protocol2;
  272. extern const efi_guid_t efi_guid_hii_config_routing_protocol;
  273. extern const efi_guid_t efi_guid_hii_config_access_protocol;
  274. extern const efi_guid_t efi_guid_hii_database_protocol;
  275. extern const efi_guid_t efi_guid_hii_string_protocol;
  276. /* GUIDs for authentication */
  277. extern const efi_guid_t efi_guid_image_security_database;
  278. extern const efi_guid_t efi_guid_sha256;
  279. extern const efi_guid_t efi_guid_cert_x509;
  280. extern const efi_guid_t efi_guid_cert_x509_sha256;
  281. extern const efi_guid_t efi_guid_cert_x509_sha384;
  282. extern const efi_guid_t efi_guid_cert_x509_sha512;
  283. extern const efi_guid_t efi_guid_cert_type_pkcs7;
  284. /* GUID of RNG protocol */
  285. extern const efi_guid_t efi_guid_rng_protocol;
  286. /* GUID of capsule update result */
  287. extern const efi_guid_t efi_guid_capsule_report;
  288. /* GUID of firmware management protocol */
  289. extern const efi_guid_t efi_guid_firmware_management_protocol;
  290. /* GUID for the ESRT */
  291. extern const efi_guid_t efi_esrt_guid;
  292. /* GUID of the SMBIOS table */
  293. extern const efi_guid_t smbios_guid;
  294. /*GUID of console */
  295. extern const efi_guid_t efi_guid_text_input_protocol;
  296. extern const efi_guid_t efi_guid_text_output_protocol;
  297. extern char __efi_runtime_start[], __efi_runtime_stop[];
  298. extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[];
  299. /**
  300. * struct efi_open_protocol_info_item - open protocol info item
  301. *
  302. * When a protocol is opened a open protocol info entry is created.
  303. * These are maintained in a list.
  304. *
  305. * @link: link to the list of open protocol info entries of a protocol
  306. * @info: information about the opening of a protocol
  307. */
  308. struct efi_open_protocol_info_item {
  309. struct list_head link;
  310. struct efi_open_protocol_info_entry info;
  311. };
  312. /**
  313. * struct efi_handler - single protocol interface of a handle
  314. *
  315. * When the UEFI payload wants to open a protocol on an object to get its
  316. * interface (usually a struct with callback functions), this struct maps the
  317. * protocol GUID to the respective protocol interface
  318. *
  319. * @link: link to the list of protocols of a handle
  320. * @guid: GUID of the protocol
  321. * @protocol_interface: protocol interface
  322. * @open_infos: link to the list of open protocol info items
  323. */
  324. struct efi_handler {
  325. struct list_head link;
  326. const efi_guid_t guid;
  327. void *protocol_interface;
  328. struct list_head open_infos;
  329. };
  330. /**
  331. * enum efi_object_type - type of EFI object
  332. *
  333. * In UnloadImage we must be able to identify if the handle relates to a
  334. * started image.
  335. */
  336. enum efi_object_type {
  337. /** @EFI_OBJECT_TYPE_UNDEFINED: undefined image type */
  338. EFI_OBJECT_TYPE_UNDEFINED = 0,
  339. /** @EFI_OBJECT_TYPE_U_BOOT_FIRMWARE: U-Boot firmware */
  340. EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,
  341. /** @EFI_OBJECT_TYPE_LOADED_IMAGE: loaded image (not started) */
  342. EFI_OBJECT_TYPE_LOADED_IMAGE,
  343. /** @EFI_OBJECT_TYPE_STARTED_IMAGE: started image */
  344. EFI_OBJECT_TYPE_STARTED_IMAGE,
  345. };
  346. /**
  347. * struct efi_object - dereferenced EFI handle
  348. *
  349. * @link: pointers to put the handle into a linked list
  350. * @protocols: linked list with the protocol interfaces installed on this
  351. * handle
  352. * @type: image type if the handle relates to an image
  353. * @dev: pointer to the DM device which is associated with this EFI handle
  354. *
  355. * UEFI offers a flexible and expandable object model. The objects in the UEFI
  356. * API are devices, drivers, and loaded images. struct efi_object is our storage
  357. * structure for these objects.
  358. *
  359. * When including this structure into a larger structure always put it first so
  360. * that when deleting a handle the whole encompassing structure can be freed.
  361. *
  362. * A pointer to this structure is referred to as a handle. Typedef efi_handle_t
  363. * has been created for such pointers.
  364. */
  365. struct efi_object {
  366. /* Every UEFI object is part of a global object list */
  367. struct list_head link;
  368. /* The list of protocols */
  369. struct list_head protocols;
  370. enum efi_object_type type;
  371. struct udevice *dev;
  372. };
  373. enum efi_image_auth_status {
  374. EFI_IMAGE_AUTH_FAILED = 0,
  375. EFI_IMAGE_AUTH_PASSED,
  376. };
  377. /**
  378. * struct efi_loaded_image_obj - handle of a loaded image
  379. *
  380. * @header: EFI object header
  381. * @exit_status: exit status passed to Exit()
  382. * @exit_data_size: exit data size passed to Exit()
  383. * @exit_data: exit data passed to Exit()
  384. * @exit_jmp: long jump buffer for returning from started image
  385. * @entry: entry address of the relocated image
  386. * @image_type: indicates if the image is an applicition or a driver
  387. * @auth_status: indicates if the image is authenticated
  388. */
  389. struct efi_loaded_image_obj {
  390. struct efi_object header;
  391. efi_status_t *exit_status;
  392. efi_uintn_t *exit_data_size;
  393. u16 **exit_data;
  394. struct jmp_buf_data *exit_jmp;
  395. EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
  396. struct efi_system_table *st);
  397. u16 image_type;
  398. enum efi_image_auth_status auth_status;
  399. };
  400. /**
  401. * struct efi_event
  402. *
  403. * @link: Link to list of all events
  404. * @queue_link: Link to the list of queued events
  405. * @type: Type of event, see efi_create_event
  406. * @notify_tpl: Task priority level of notifications
  407. * @notify_function: Function to call when the event is triggered
  408. * @notify_context: Data to be passed to the notify function
  409. * @group: Event group
  410. * @trigger_time: Period of the timer
  411. * @trigger_next: Next time to trigger the timer
  412. * @trigger_type: Type of timer, see efi_set_timer
  413. * @is_signaled: The event occurred. The event is in the signaled state.
  414. */
  415. struct efi_event {
  416. struct list_head link;
  417. struct list_head queue_link;
  418. uint32_t type;
  419. efi_uintn_t notify_tpl;
  420. void (EFIAPI *notify_function)(struct efi_event *event, void *context);
  421. void *notify_context;
  422. const efi_guid_t *group;
  423. u64 trigger_next;
  424. u64 trigger_time;
  425. enum efi_timer_delay trigger_type;
  426. bool is_signaled;
  427. };
  428. /* This list contains all UEFI objects we know of */
  429. extern struct list_head efi_obj_list;
  430. /* List of all events */
  431. extern struct list_head efi_events;
  432. /**
  433. * struct efi_protocol_notification - handle for notified protocol
  434. *
  435. * When a protocol interface is installed for which an event was registered with
  436. * the RegisterProtocolNotify() service this structure is used to hold the
  437. * handle on which the protocol interface was installed.
  438. *
  439. * @link: link to list of all handles notified for this event
  440. * @handle: handle on which the notified protocol interface was installed
  441. */
  442. struct efi_protocol_notification {
  443. struct list_head link;
  444. efi_handle_t handle;
  445. };
  446. /**
  447. * struct efi_register_notify_event - event registered by
  448. * RegisterProtocolNotify()
  449. *
  450. * The address of this structure serves as registration value.
  451. *
  452. * @link: link to list of all registered events
  453. * @event: registered event. The same event may registered for multiple
  454. * GUIDs.
  455. * @protocol: protocol for which the event is registered
  456. * @handles: linked list of all handles on which the notified protocol was
  457. * installed
  458. */
  459. struct efi_register_notify_event {
  460. struct list_head link;
  461. struct efi_event *event;
  462. efi_guid_t protocol;
  463. struct list_head handles;
  464. };
  465. /* called at pre-initialization */
  466. int efi_init_early(void);
  467. /* Initialize efi execution environment */
  468. efi_status_t efi_init_obj_list(void);
  469. /* Append new boot option in BootOrder variable */
  470. efi_status_t efi_bootmgr_append_bootorder(u16 index);
  471. /* Get unused "Boot####" index */
  472. efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,
  473. efi_uintn_t buf_size, u32 *index);
  474. /* Generate the media device boot option */
  475. efi_status_t efi_bootmgr_update_media_device_boot_option(void);
  476. /* Delete selected boot option */
  477. efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
  478. /* search the boot option index in BootOrder */
  479. bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
  480. /* Set up console modes */
  481. void efi_setup_console_size(void);
  482. /* Install device tree */
  483. efi_status_t efi_install_fdt(void *fdt);
  484. /* Run loaded UEFI image */
  485. efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size);
  486. /* Initialize variable services */
  487. efi_status_t efi_init_variables(void);
  488. /* Notify ExitBootServices() is called */
  489. void efi_variables_boot_exit_notify(void);
  490. efi_status_t efi_tcg2_notify_exit_boot_services_failed(void);
  491. /* Measure efi application invocation */
  492. efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *handle);
  493. /* Measure efi application exit */
  494. efi_status_t efi_tcg2_measure_efi_app_exit(void);
  495. /* Measure DTB */
  496. efi_status_t efi_tcg2_measure_dtb(void *dtb);
  497. /* Called by bootefi to initialize root node */
  498. efi_status_t efi_root_node_register(void);
  499. /* Called by bootefi to initialize runtime */
  500. efi_status_t efi_initialize_system_table(void);
  501. /* efi_runtime_detach() - detach unimplemented runtime functions */
  502. void efi_runtime_detach(void);
  503. /* efi_convert_pointer() - convert pointer to virtual address */
  504. efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition,
  505. void **address);
  506. /* Carve out DT reserved memory ranges */
  507. void efi_carve_out_dt_rsv(void *fdt);
  508. /* Purge unused kaslr-seed */
  509. void efi_try_purge_kaslr_seed(void *fdt);
  510. /* Called by bootefi to make console interface available */
  511. efi_status_t efi_console_register(void);
  512. /* Called by efi_init_obj_list() to proble all block devices */
  513. efi_status_t efi_disks_register(void);
  514. /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */
  515. efi_status_t efi_rng_register(void);
  516. /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
  517. efi_status_t efi_tcg2_register(void);
  518. /* Called by efi_init_obj_list() to install RISCV_EFI_BOOT_PROTOCOL */
  519. efi_status_t efi_riscv_register(void);
  520. /* Called by efi_init_obj_list() to do initial measurement */
  521. efi_status_t efi_tcg2_do_initial_measurement(void);
  522. /* measure the pe-coff image, extend PCR and add Event Log */
  523. efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
  524. struct efi_loaded_image_obj *handle,
  525. struct efi_loaded_image *loaded_image_info);
  526. /* Create handles and protocols for the partitions of a block device */
  527. int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
  528. const char *uclass_idname, int diskid,
  529. const char *pdevname);
  530. /* Called by bootefi to make GOP (graphical) interface available */
  531. efi_status_t efi_gop_register(void);
  532. /* Called by bootefi to make the network interface available */
  533. efi_status_t efi_net_register(void);
  534. /* Called by bootefi to make the watchdog available */
  535. efi_status_t efi_watchdog_register(void);
  536. efi_status_t efi_initrd_register(void);
  537. efi_status_t efi_initrd_deregister(void);
  538. /* Called by bootefi to make SMBIOS tables available */
  539. /**
  540. * efi_acpi_register() - write out ACPI tables
  541. *
  542. * Called by bootefi to make ACPI tables available
  543. *
  544. * Return: 0 if OK, -ENOMEM if no memory is available for the tables
  545. */
  546. efi_status_t efi_acpi_register(void);
  547. /**
  548. * efi_smbios_register() - write out SMBIOS tables
  549. *
  550. * Called by bootefi to make SMBIOS tables available
  551. *
  552. * Return: 0 if OK, -ENOMEM if no memory is available for the tables
  553. */
  554. efi_status_t efi_smbios_register(void);
  555. struct efi_simple_file_system_protocol *
  556. efi_fs_from_path(struct efi_device_path *fp);
  557. /* Called by efi_set_watchdog_timer to reset the timer */
  558. efi_status_t efi_set_watchdog(unsigned long timeout);
  559. /* Called from places to check whether a timer expired */
  560. void efi_timer_check(void);
  561. /* Check if a buffer contains a PE-COFF image */
  562. efi_status_t efi_check_pe(void *buffer, size_t size, void **nt_header);
  563. /* PE loader implementation */
  564. efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
  565. void *efi, size_t efi_size,
  566. struct efi_loaded_image *loaded_image_info);
  567. /* Called once to store the pristine gd pointer */
  568. void efi_save_gd(void);
  569. /* Call this to relocate the runtime section to an address space */
  570. void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
  571. /* Call this to get image parameters */
  572. void efi_get_image_parameters(void **img_addr, size_t *img_size);
  573. /* Add a new object to the object list. */
  574. void efi_add_handle(efi_handle_t obj);
  575. /* Create handle */
  576. efi_status_t efi_create_handle(efi_handle_t *handle);
  577. /* Delete handle */
  578. efi_status_t efi_delete_handle(efi_handle_t obj);
  579. /* Call this to validate a handle and find the EFI object for it */
  580. struct efi_object *efi_search_obj(const efi_handle_t handle);
  581. /* Locate device_path handle */
  582. efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol,
  583. struct efi_device_path **device_path,
  584. efi_handle_t *device);
  585. /* Load image */
  586. efi_status_t EFIAPI efi_load_image(bool boot_policy,
  587. efi_handle_t parent_image,
  588. struct efi_device_path *file_path,
  589. void *source_buffer,
  590. efi_uintn_t source_size,
  591. efi_handle_t *image_handle);
  592. /* Start image */
  593. efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  594. efi_uintn_t *exit_data_size,
  595. u16 **exit_data);
  596. /* Unload image */
  597. efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle);
  598. /* Find a protocol on a handle */
  599. efi_status_t efi_search_protocol(const efi_handle_t handle,
  600. const efi_guid_t *protocol_guid,
  601. struct efi_handler **handler);
  602. /* Install new protocol on a handle */
  603. efi_status_t efi_add_protocol(const efi_handle_t handle,
  604. const efi_guid_t *protocol,
  605. void *protocol_interface);
  606. /* Open protocol */
  607. efi_status_t efi_protocol_open(struct efi_handler *handler,
  608. void **protocol_interface, void *agent_handle,
  609. void *controller_handle, uint32_t attributes);
  610. /* Install multiple protocol interfaces */
  611. efi_status_t EFIAPI
  612. efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...);
  613. efi_status_t EFIAPI
  614. efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...);
  615. /* Get handles that support a given protocol */
  616. efi_status_t EFIAPI efi_locate_handle_buffer(
  617. enum efi_locate_search_type search_type,
  618. const efi_guid_t *protocol, void *search_key,
  619. efi_uintn_t *no_handles, efi_handle_t **buffer);
  620. /* Close a previously opened protocol interface */
  621. efi_status_t efi_close_protocol(efi_handle_t handle, const efi_guid_t *protocol,
  622. efi_handle_t agent_handle,
  623. efi_handle_t controller_handle);
  624. /* Open a protocol interface */
  625. efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle,
  626. const efi_guid_t *protocol,
  627. void **protocol_interface);
  628. /* Call this to create an event */
  629. efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
  630. void (EFIAPI *notify_function) (
  631. struct efi_event *event,
  632. void *context),
  633. void *notify_context, efi_guid_t *group,
  634. struct efi_event **event);
  635. /* Call this to set a timer */
  636. efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
  637. uint64_t trigger_time);
  638. /* Call this to signal an event */
  639. void efi_signal_event(struct efi_event *event);
  640. /* return true if the device is removable */
  641. bool efi_disk_is_removable(efi_handle_t handle);
  642. /**
  643. * efi_create_simple_file_system() - create simple file system protocol
  644. *
  645. * Create a simple file system protocol for a partition.
  646. *
  647. * @desc: block device descriptor
  648. * @part: partition number
  649. * @dp: device path
  650. * @fsp: simple file system protocol
  651. * Return: status code
  652. */
  653. efi_status_t
  654. efi_create_simple_file_system(struct blk_desc *desc, int part,
  655. struct efi_device_path *dp,
  656. struct efi_simple_file_system_protocol **fsp);
  657. /* open file from device-path: */
  658. struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
  659. /* Registers a callback function for a notification event. */
  660. efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol,
  661. struct efi_event *event,
  662. void **registration);
  663. efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size);
  664. /* get a device path from a Boot#### option */
  665. struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid);
  666. /* get len, string (used in u-boot crypto from a guid */
  667. const char *guid_to_sha_str(const efi_guid_t *guid);
  668. int algo_to_len(const char *algo);
  669. int efi_link_dev(efi_handle_t handle, struct udevice *dev);
  670. int efi_unlink_dev(efi_handle_t handle);
  671. bool efi_varname_is_load_option(u16 *var_name16, int *index);
  672. efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
  673. efi_guid_t *guid);
  674. /**
  675. * efi_size_in_pages() - convert size in bytes to size in pages
  676. *
  677. * This macro returns the number of EFI memory pages required to hold 'size'
  678. * bytes.
  679. *
  680. * @size: size in bytes
  681. * Return: size in pages
  682. */
  683. #define efi_size_in_pages(size) (((size) + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
  684. /* Allocate boot service data pool memory */
  685. void *efi_alloc(size_t len);
  686. /* Allocate pages on the specified alignment */
  687. void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align);
  688. /* More specific EFI memory allocator, called by EFI payloads */
  689. efi_status_t efi_allocate_pages(enum efi_allocate_type type,
  690. enum efi_memory_type memory_type,
  691. efi_uintn_t pages, uint64_t *memory);
  692. /* EFI memory free function. */
  693. efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages);
  694. /* EFI memory allocator for small allocations */
  695. efi_status_t efi_allocate_pool(enum efi_memory_type pool_type,
  696. efi_uintn_t size, void **buffer);
  697. /* EFI pool memory free function. */
  698. efi_status_t efi_free_pool(void *buffer);
  699. /* Allocate and retrieve EFI memory map */
  700. efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size,
  701. struct efi_mem_desc **memory_map);
  702. /* Returns the EFI memory map */
  703. efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
  704. struct efi_mem_desc *memory_map,
  705. efi_uintn_t *map_key,
  706. efi_uintn_t *descriptor_size,
  707. uint32_t *descriptor_version);
  708. /* Adds a range into the EFI memory map */
  709. efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type);
  710. /* Adds a conventional range into the EFI memory map */
  711. efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
  712. u64 ram_top);
  713. /* Called by board init to initialize the EFI drivers */
  714. efi_status_t efi_driver_init(void);
  715. /* Called when a block device is added */
  716. int efi_disk_probe(void *ctx, struct event *event);
  717. /* Called when a block device is removed */
  718. int efi_disk_remove(void *ctx, struct event *event);
  719. /* Called by board init to initialize the EFI memory map */
  720. int efi_memory_init(void);
  721. /* Adds new or overrides configuration table entry to the system table */
  722. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table);
  723. /* Sets up a loaded image */
  724. efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
  725. struct efi_device_path *file_path,
  726. struct efi_loaded_image_obj **handle_ptr,
  727. struct efi_loaded_image **info_ptr);
  728. #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
  729. extern void *efi_bounce_buffer;
  730. #define EFI_LOADER_BOUNCE_BUFFER_SIZE (64 * 1024 * 1024)
  731. #endif
  732. /* shorten device path */
  733. struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp);
  734. struct efi_device_path *efi_dp_next(const struct efi_device_path *dp);
  735. int efi_dp_match(const struct efi_device_path *a,
  736. const struct efi_device_path *b);
  737. efi_handle_t efi_dp_find_obj(struct efi_device_path *dp,
  738. const efi_guid_t *guid,
  739. struct efi_device_path **rem);
  740. /* get size of the first device path instance excluding end node */
  741. efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp);
  742. /* size of multi-instance device path excluding end node */
  743. efi_uintn_t efi_dp_size(const struct efi_device_path *dp);
  744. struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp);
  745. struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
  746. const struct efi_device_path *dp2);
  747. struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
  748. const struct efi_device_path *node);
  749. /* Create a device path node of given type, sub-type, length */
  750. struct efi_device_path *efi_dp_create_device_node(const u8 type,
  751. const u8 sub_type,
  752. const u16 length);
  753. /* Append device path instance */
  754. struct efi_device_path *efi_dp_append_instance(
  755. const struct efi_device_path *dp,
  756. const struct efi_device_path *dpi);
  757. /* Get next device path instance */
  758. struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
  759. efi_uintn_t *size);
  760. /* Check if a device path contains muliple instances */
  761. bool efi_dp_is_multi_instance(const struct efi_device_path *dp);
  762. struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part);
  763. /* Create a device node for a block device partition. */
  764. struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);
  765. struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp,
  766. const char *path);
  767. struct efi_device_path *efi_dp_from_eth(void);
  768. struct efi_device_path *efi_dp_from_mem(uint32_t mem_type,
  769. uint64_t start_address,
  770. uint64_t end_address);
  771. /* Determine the last device path node that is not the end node. */
  772. const struct efi_device_path *efi_dp_last_node(
  773. const struct efi_device_path *dp);
  774. efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
  775. struct efi_device_path **device_path,
  776. struct efi_device_path **file_path);
  777. struct efi_device_path *efi_dp_from_uart(void);
  778. efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
  779. const char *path,
  780. struct efi_device_path **device,
  781. struct efi_device_path **file);
  782. ssize_t efi_dp_check_length(const struct efi_device_path *dp,
  783. const size_t maxlen);
  784. #define EFI_DP_TYPE(_dp, _type, _subtype) \
  785. (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
  786. ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
  787. /* template END node: */
  788. extern const struct efi_device_path END;
  789. /* Indicate supported runtime services */
  790. efi_status_t efi_init_runtime_supported(void);
  791. /* Update CRC32 in table header */
  792. void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table);
  793. /* Boards may provide the functions below to implement RTS functionality */
  794. void __efi_runtime EFIAPI efi_reset_system(
  795. enum efi_reset_type reset_type,
  796. efi_status_t reset_status,
  797. unsigned long data_size, void *reset_data);
  798. /* Architecture specific initialization of the EFI subsystem */
  799. efi_status_t efi_reset_system_init(void);
  800. efi_status_t __efi_runtime EFIAPI efi_get_time(
  801. struct efi_time *time,
  802. struct efi_time_cap *capabilities);
  803. efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time);
  804. #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
  805. /*
  806. * Entry point for the tests of the EFI API.
  807. * It is called by 'bootefi selftest'
  808. */
  809. efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
  810. struct efi_system_table *systab);
  811. #endif
  812. efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
  813. const efi_guid_t *vendor, u32 *attributes,
  814. efi_uintn_t *data_size, void *data);
  815. efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
  816. u16 *variable_name,
  817. efi_guid_t *vendor);
  818. efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
  819. const efi_guid_t *vendor, u32 attributes,
  820. efi_uintn_t data_size, const void *data);
  821. efi_status_t EFIAPI efi_query_variable_info(
  822. u32 attributes, u64 *maximum_variable_storage_size,
  823. u64 *remaining_variable_storage_size,
  824. u64 *maximum_variable_size);
  825. void *efi_get_var(const u16 *name, const efi_guid_t *vendor, efi_uintn_t *size);
  826. /*
  827. * See section 3.1.3 in the v2.7 UEFI spec for more details on
  828. * the layout of EFI_LOAD_OPTION. In short it is:
  829. *
  830. * typedef struct _EFI_LOAD_OPTION {
  831. * UINT32 Attributes;
  832. * UINT16 FilePathListLength;
  833. * // CHAR16 Description[]; <-- variable length, NULL terminated
  834. * // EFI_DEVICE_PATH_PROTOCOL FilePathList[];
  835. * <-- FilePathListLength bytes
  836. * // UINT8 OptionalData[];
  837. * } EFI_LOAD_OPTION;
  838. */
  839. struct efi_load_option {
  840. u32 attributes;
  841. u16 file_path_length;
  842. u16 *label;
  843. struct efi_device_path *file_path;
  844. const u8 *optional_data;
  845. };
  846. struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
  847. const efi_guid_t *guid);
  848. struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
  849. const struct efi_device_path *dp2);
  850. struct efi_device_path *search_gpt_dp_node(struct efi_device_path *device_path);
  851. efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data,
  852. efi_uintn_t *size);
  853. unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
  854. efi_status_t efi_set_load_options(efi_handle_t handle,
  855. efi_uintn_t load_options_size,
  856. void *load_options);
  857. efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options);
  858. /**
  859. * struct efi_image_regions - A list of memory regions
  860. *
  861. * @max: Maximum number of regions
  862. * @num: Number of regions
  863. * @reg: array of regions
  864. */
  865. struct efi_image_regions {
  866. int max;
  867. int num;
  868. struct image_region reg[];
  869. };
  870. /**
  871. * struct efi_sig_data - A decoded data of struct efi_signature_data
  872. *
  873. * This structure represents an internal form of signature in
  874. * signature database. A listed list may represent a signature list.
  875. *
  876. * @next: Pointer to next entry
  877. * @owner: Signature owner
  878. * @data: Pointer to signature data
  879. * @size: Size of signature data
  880. */
  881. struct efi_sig_data {
  882. struct efi_sig_data *next;
  883. efi_guid_t owner;
  884. void *data;
  885. size_t size;
  886. };
  887. /**
  888. * struct efi_signature_store - A decoded data of signature database
  889. *
  890. * This structure represents an internal form of signature database.
  891. *
  892. * @next: Pointer to next entry
  893. * @sig_type: Signature type
  894. * @sig_data_list: Pointer to signature list
  895. */
  896. struct efi_signature_store {
  897. struct efi_signature_store *next;
  898. efi_guid_t sig_type;
  899. struct efi_sig_data *sig_data_list;
  900. };
  901. struct x509_certificate;
  902. struct pkcs7_message;
  903. /**
  904. * struct eficonfig_media_boot_option - boot option for (removable) media device
  905. *
  906. * This structure is used to enumerate possible boot option
  907. *
  908. * @lo: Serialized load option data
  909. * @size: Size of serialized load option data
  910. * @exist: Flag to indicate the load option already exists
  911. * in Non-volatile load option
  912. */
  913. struct eficonfig_media_boot_option {
  914. void *lo;
  915. efi_uintn_t size;
  916. bool exist;
  917. };
  918. bool efi_hash_regions(struct image_region *regs, int count,
  919. void **hash, const char *hash_algo, int *len);
  920. bool efi_signature_lookup_digest(struct efi_image_regions *regs,
  921. struct efi_signature_store *db,
  922. bool dbx);
  923. bool efi_signature_verify(struct efi_image_regions *regs,
  924. struct pkcs7_message *msg,
  925. struct efi_signature_store *db,
  926. struct efi_signature_store *dbx);
  927. static inline bool efi_signature_verify_one(struct efi_image_regions *regs,
  928. struct pkcs7_message *msg,
  929. struct efi_signature_store *db)
  930. {
  931. return efi_signature_verify(regs, msg, db, NULL);
  932. }
  933. bool efi_signature_check_signers(struct pkcs7_message *msg,
  934. struct efi_signature_store *dbx);
  935. efi_status_t efi_image_region_add(struct efi_image_regions *regs,
  936. const void *start, const void *end,
  937. int nocheck);
  938. void efi_sigstore_free(struct efi_signature_store *sigstore);
  939. struct efi_signature_store *efi_build_signature_store(void *sig_list,
  940. efi_uintn_t size);
  941. struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
  942. bool efi_secure_boot_enabled(void);
  943. bool efi_capsule_auth_enabled(void);
  944. void *efi_prepare_aligned_image(void *efi, u64 *efi_size);
  945. bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
  946. WIN_CERTIFICATE **auth, size_t *auth_len);
  947. struct pkcs7_message *efi_parse_pkcs7_header(const void *buf,
  948. size_t buflen,
  949. u8 **tmpbuf);
  950. /* runtime implementation of memcpy() */
  951. void efi_memcpy_runtime(void *dest, const void *src, size_t n);
  952. /* commonly used helper functions */
  953. u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name,
  954. unsigned int index);
  955. efi_string_t efi_convert_string(const char *str);
  956. extern const struct efi_firmware_management_protocol efi_fmp_fit;
  957. extern const struct efi_firmware_management_protocol efi_fmp_raw;
  958. /* Capsule update */
  959. efi_status_t EFIAPI efi_update_capsule(
  960. struct efi_capsule_header **capsule_header_array,
  961. efi_uintn_t capsule_count,
  962. u64 scatter_gather_list);
  963. efi_status_t EFIAPI efi_query_capsule_caps(
  964. struct efi_capsule_header **capsule_header_array,
  965. efi_uintn_t capsule_count,
  966. u64 *maximum_capsule_size,
  967. u32 *reset_type);
  968. efi_status_t efi_capsule_authenticate(const void *capsule,
  969. efi_uintn_t capsule_size,
  970. void **image, efi_uintn_t *image_size);
  971. #define EFI_CAPSULE_DIR u"\\EFI\\UpdateCapsule\\"
  972. /**
  973. * struct efi_fw_image - Information on firmware images updatable through
  974. * capsule update
  975. *
  976. * This structure gives information about the firmware images on the platform
  977. * which can be updated through the capsule update mechanism
  978. *
  979. * @image_type_id: Image GUID. Same value is to be used in the capsule
  980. * @fw_name: Name of the firmware image
  981. * @image_index: Image Index, same as value passed to SetImage FMP
  982. * function
  983. */
  984. struct efi_fw_image {
  985. efi_guid_t image_type_id;
  986. u16 *fw_name;
  987. u8 image_index;
  988. };
  989. /**
  990. * struct efi_capsule_update_info - Information needed for capsule updates
  991. *
  992. * This structure provides information needed for performing firmware
  993. * updates. The structure needs to be initialised per platform, for all
  994. * platforms which enable capsule updates
  995. *
  996. * @dfu_string: String used to populate dfu_alt_info
  997. * @num_images: The number of images array entries
  998. * @images: Pointer to an array of updatable images
  999. */
  1000. struct efi_capsule_update_info {
  1001. const char *dfu_string;
  1002. int num_images;
  1003. struct efi_fw_image *images;
  1004. };
  1005. extern struct efi_capsule_update_info update_info;
  1006. /**
  1007. * Install the ESRT system table.
  1008. *
  1009. * Return: status code
  1010. */
  1011. efi_status_t efi_esrt_register(void);
  1012. /**
  1013. * efi_ecpt_register() - Install the ECPT system table.
  1014. *
  1015. * Return: status code
  1016. */
  1017. efi_status_t efi_ecpt_register(void);
  1018. /**
  1019. * efi_esrt_populate() - Populates the ESRT entries from the FMP instances
  1020. * present in the system.
  1021. * If an ESRT already exists, the old ESRT is replaced in the system table.
  1022. * The memory of the old ESRT is deallocated.
  1023. *
  1024. * Return:
  1025. * - EFI_SUCCESS if the ESRT is correctly created
  1026. * - error code otherwise.
  1027. */
  1028. efi_status_t efi_esrt_populate(void);
  1029. efi_status_t efi_load_capsule_drivers(void);
  1030. efi_status_t platform_get_eventlog(struct udevice *dev, u64 *addr, u32 *sz);
  1031. efi_status_t efi_locate_handle_buffer_int(enum efi_locate_search_type search_type,
  1032. const efi_guid_t *protocol, void *search_key,
  1033. efi_uintn_t *no_handles, efi_handle_t **buffer);
  1034. efi_status_t efi_open_volume_int(struct efi_simple_file_system_protocol *this,
  1035. struct efi_file_handle **root);
  1036. efi_status_t efi_file_open_int(struct efi_file_handle *this,
  1037. struct efi_file_handle **new_handle,
  1038. u16 *file_name, u64 open_mode,
  1039. u64 attributes);
  1040. efi_status_t efi_file_close_int(struct efi_file_handle *file);
  1041. efi_status_t efi_file_read_int(struct efi_file_handle *this,
  1042. efi_uintn_t *buffer_size, void *buffer);
  1043. efi_status_t efi_file_setpos_int(struct efi_file_handle *file, u64 pos);
  1044. typedef efi_status_t (*efi_console_filter_func)(struct efi_input_key *key);
  1045. efi_status_t efi_console_get_u16_string
  1046. (struct efi_simple_text_input_protocol *cin,
  1047. u16 *buf, efi_uintn_t count, efi_console_filter_func filer_func,
  1048. int row, int col);
  1049. efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size);
  1050. /**
  1051. * efi_add_known_memory() - add memory banks to EFI memory map
  1052. *
  1053. * This weak function may be overridden for specific architectures.
  1054. */
  1055. void efi_add_known_memory(void);
  1056. #endif /* _EFI_LOADER_H */