Skip to contentSkip to conversation

subject: efi_loader: add HII database protocol

PATCH Superseded AKASHI Takahiro 3 participants 13 messages Jan 21, 2019 – Feb 12, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

v3 cover subject: efi_loader: add HII database protocol

HII database protocol is the last missing (major?) piece of code so that we can run unmodified EDKII's shell and UEFI SCT on EFI-enabled u-boot.

The original code was initially written by Leif and Rob a year ago[1], and now I'm reworking it. The implementation has not been much enhanced from the original, but I tried to give it clearer implementation to be able to add more functionality easily later on.
I also addressed the comments by Alex[2] and added a self test on request of Heinrich.

HII configuration routing protocol and access protocol have only a skeleton and should be implemented when we need to have *drivers* that require configuration mechanism.

# Please note that a bunch of warnings are generated by checkpatch.pl,

# but there are also good reasons for not fixing them.

Changes in v3 (Jan 21, 2019)
* drope v2's patch#1("lib: add u16_strcpy/strdup functions") as it has been merged
* define a "key" value as u32 in efi_key_descriptor
* simplify "if" condition in export_package_lists()
* access "packed" structures of HII packages through get_unaligned_xx()
* implement GetSecondaryLanguages()
* compare a language in case-insensitive way in GetString() & GetLanguages()
* cosmetic changes (including variable/struct member names)

Changes in v2 (Nov 16, 2018)
* add some descriptions to newly added functions
* rename EFI_HII_PACKAGE_[TYPE|LEN]_* to __EFI_HII_PACKAGE_[TYPE|LEN]_* as they are of internal use only
* cast a return value (of efi_status_t) to "unsigned int" for printing

[1] https://lists.denx.de/pipermail/u-boot/2017-October/308999.html
[2] https://lists.denx.de/pipermail/u-boot/2017-October/309116.html

AKASHI Takahiro (4):
efi: hii: add guid package support
efi: hii: add keyboard layout package support
efi: hii: add HII config routing/access protocols
efi_selftest: add HII database protocols test

Leif Lindholm (1):
efi_loader: Initial HII database protocols

 include/efi_api.h                        |  421 ++++++++-
 include/efi_loader.h                     |    8 +
 lib/efi_loader/Makefile                  |    1 +
 lib/efi_loader/efi_boottime.c            |   18 +
 lib/efi_loader/efi_hii.c                 | 1095 ++++++++++++++++++++++
 lib/efi_loader/efi_hii_config.c          |  146 +++
 lib/efi_selftest/Makefile                |    1 +
 lib/efi_selftest/efi_selftest_hii.c      | 1046 +++++++++++++++++++++
 lib/efi_selftest/efi_selftest_hii_data.c |  453 +++++++++
 9 files changed, 3188 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_hii.c
 create mode 100644 lib/efi_loader/efi_hii_config.c
 create mode 100644 lib/efi_selftest/efi_selftest_hii.c
 create mode 100644 lib/efi_selftest/efi_selftest_hii_data.c
Signature · 1 line
2.19.1
#1 lore raw

PATCH v3 1/5 efi_loader: Initial HII database protocols

From: Leif Lindholm <[email protected]>

This patch provides enough implementation of the following protocols to run EDKII's Shell.efi and UEFI SCT:

* EfiHiiDatabaseProtocol
* EfiHiiStringProtocol

Not implemented are:
* ExportPackageLists()
* RegisterPackageNotify()/UnregisterPackageNotify()
* SetKeyboardLayout() (i.e. *current* keyboard layout)

HII database protocol in this patch series can handle only:
* GUID package
* string package
* keyboard layout package
(The other packages, except Device path package, will be necessary
for interactive and graphical UI.)

---
 include/efi_api.h             | 245 ++++++++-
 include/efi_loader.h          |   4 +
 lib/efi_loader/Makefile       |   1 +
 lib/efi_loader/efi_boottime.c |  12 +
 lib/efi_loader/efi_hii.c      | 922 ++++++++++++++++++++++++++++++++++
 5 files changed, 1183 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_hii.c
include/efi_api.h +244 -1
index aef77b6319de..67c3753de0b1 100644
@@ -17,6 +17,7 @@
 #define _EFI_API_H
 
 #include <efi.h>
+#include <charset.h>
 
 #ifdef CONFIG_EFI_LOADER
 #include <asm/setjmp.h>
@@ -34,7 +35,10 @@ enum efi_timer_delay {
 
 #define efi_intn_t ssize_t
 #define efi_uintn_t size_t
-typedef uint16_t *efi_string_t;
+typedef void *efi_hii_handle_t;
+typedef u16 *efi_string_t;
+typedef u16 efi_string_id_t;
+typedef u32 efi_hii_font_style_t;
 
 #define EVT_TIMER				0x80000000
 #define EVT_RUNTIME				0x40000000
@@ -697,6 +701,245 @@ struct efi_device_path_utilities_protocol {
 		uint16_t node_length);
 };
 
+/*
+ * Human Interface Infrastructure (HII)
+ */
+struct efi_hii_package_list_header {
+	efi_guid_t package_list_guid;
+	u32 package_length;
+} __packed;
+
+/**
+ * struct efi_hii_package_header - EFI HII package header
+ *
+ * @fields:	'fields' replaces the bit-fields defined in the EFI
+ *		specification to to avoid possible compiler incompatibilities::
+ *
+ *		u32 length:24;
+ *		u32 type:8;
+ */
+struct efi_hii_package_header {
+	u32 fields;
+} __packed;
+
+#define __EFI_HII_PACKAGE_LEN_SHIFT	0
+#define __EFI_HII_PACKAGE_TYPE_SHIFT	24
+#define __EFI_HII_PACKAGE_LEN_MASK	0xffffff
+#define __EFI_HII_PACKAGE_TYPE_MASK	0xff
+
+#define EFI_HII_PACKAGE_TYPE_ALL          0x00
+#define EFI_HII_PACKAGE_TYPE_GUID         0x01
+#define EFI_HII_PACKAGE_FORMS             0x02
+#define EFI_HII_PACKAGE_STRINGS           0x04
+#define EFI_HII_PACKAGE_FONTS             0x05
+#define EFI_HII_PACKAGE_IMAGES            0x06
+#define EFI_HII_PACKAGE_SIMPLE_FONTS      0x07
+#define EFI_HII_PACKAGE_DEVICE_PATH       0x08
+#define EFI_HII_PACKAGE_KEYBOARD_LAYOUT   0x09
+#define EFI_HII_PACKAGE_ANIMATIONS        0x0A
+#define EFI_HII_PACKAGE_END               0xDF
+#define EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN 0xE0
+#define EFI_HII_PACKAGE_TYPE_SYSTEM_END   0xFF
+
+/*
+ * HII string package
+ */
+struct efi_hii_strings_package {
+	struct efi_hii_package_header header;
+	u32 header_size;
+	u32 string_info_offset;
+	u16 language_window[16];
+	efi_string_id_t language_name;
+	u8  language[];
+} __packed;
+
+struct efi_hii_string_block {
+	u8 block_type;
+	/* u8 block_body[]; */
+} __packed;
+
+#define EFI_HII_SIBT_END               0x00
+#define EFI_HII_SIBT_STRING_SCSU       0x10
+#define EFI_HII_SIBT_STRING_SCSU_FONT  0x11
+#define EFI_HII_SIBT_STRINGS_SCSU      0x12
+#define EFI_HII_SIBT_STRINGS_SCSU_FONT 0x13
+#define EFI_HII_SIBT_STRING_UCS2       0x14
+#define EFI_HII_SIBT_STRING_UCS2_FONT  0x15
+#define EFI_HII_SIBT_STRINGS_UCS2      0x16
+#define EFI_HII_SIBT_STRINGS_UCS2_FONT 0x17
+#define EFI_HII_SIBT_DUPLICATE         0x20
+#define EFI_HII_SIBT_SKIP2             0x21
+#define EFI_HII_SIBT_SKIP1             0x22
+#define EFI_HII_SIBT_EXT1              0x30
+#define EFI_HII_SIBT_EXT2              0x31
+#define EFI_HII_SIBT_EXT4              0x32
+#define EFI_HII_SIBT_FONT              0x40
+
+struct efi_hii_sibt_string_ucs2_block {
+	struct efi_hii_string_block header;
+	u16 string_text[];
+} __packed;
+
+static inline struct efi_hii_string_block *
+efi_hii_sibt_string_ucs2_block_next(struct efi_hii_sibt_string_ucs2_block *blk)
+{
+	return ((void *)blk) + sizeof(*blk) +
+		(u16_strlen(blk->string_text) + 1) * 2;
+}
+
+/*
+ * HII keyboard package
+ */
+typedef enum {
+	EFI_KEY_LCTRL, EFI_KEY_A0, EFI_KEY_LALT, EFI_KEY_SPACE_BAR,
+	EFI_KEY_A2, EFI_KEY_A3, EFI_KEY_A4, EFI_KEY_RCTRL, EFI_KEY_LEFT_ARROW,
+	EFI_KEY_DOWN_ARROW, EFI_KEY_RIGHT_ARROW, EFI_KEY_ZERO,
+	EFI_KEY_PERIOD, EFI_KEY_ENTER, EFI_KEY_LSHIFT, EFI_KEY_B0,
+	EFI_KEY_B1, EFI_KEY_B2, EFI_KEY_B3, EFI_KEY_B4, EFI_KEY_B5, EFI_KEY_B6,
+	EFI_KEY_B7, EFI_KEY_B8, EFI_KEY_B9, EFI_KEY_B10, EFI_KEY_RSHIFT,
+	EFI_KEY_UP_ARROW, EFI_KEY_ONE, EFI_KEY_TWO, EFI_KEY_THREE,
+	EFI_KEY_CAPS_LOCK, EFI_KEY_C1, EFI_KEY_C2, EFI_KEY_C3, EFI_KEY_C4,
+	EFI_KEY_C5, EFI_KEY_C6, EFI_KEY_C7, EFI_KEY_C8, EFI_KEY_C9,
+	EFI_KEY_C10, EFI_KEY_C11, EFI_KEY_C12, EFI_KEY_FOUR, EFI_KEY_FIVE,
+	EFI_KEY_SIX, EFI_KEY_PLUS, EFI_KEY_TAB, EFI_KEY_D1, EFI_KEY_D2,
+	EFI_KEY_D3, EFI_KEY_D4, EFI_KEY_D5, EFI_KEY_D6, EFI_KEY_D7, EFI_KEY_D8,
+	EFI_KEY_D9, EFI_KEY_D10, EFI_KEY_D11, EFI_KEY_D12, EFI_KEY_D13,
+	EFI_KEY_DEL, EFI_KEY_END, EFI_KEY_PG_DN, EFI_KEY_SEVEN, EFI_KEY_EIGHT,
+	EFI_KEY_NINE, EFI_KEY_E0, EFI_KEY_E1, EFI_KEY_E2, EFI_KEY_E3,
+	EFI_KEY_E4, EFI_KEY_E5, EFI_KEY_E6, EFI_KEY_E7, EFI_KEY_E8, EFI_KEY_E9,
+	EFI_KEY_E10, EFI_KEY_E11, EFI_KEY_E12, EFI_KEY_BACK_SPACE,
+	EFI_KEY_INS, EFI_KEY_HOME, EFI_KEY_PG_UP, EFI_KEY_NLCK, EFI_KEY_SLASH,
+	EFI_KEY_ASTERISK, EFI_KEY_MINUS, EFI_KEY_ESC, EFI_KEY_F1, EFI_KEY_F2,
+	EFI_KEY_F3, EFI_KEY_F4, EFI_KEY_F5, EFI_KEY_F6, EFI_KEY_F7, EFI_KEY_F8,
+	EFI_KEY_F9, EFI_KEY_F10, EFI_KEY_F11, EFI_KEY_F12, EFI_KEY_PRINT,
+	EFI_KEY_SLCK, EFI_KEY_PAUSE,
+} efi_key;
+
+struct efi_key_descriptor {
+	u32 key;
+	u16 unicode;
+	u16 shifted_unicode;
+	u16 alt_gr_unicode;
+	u16 shifted_alt_gr_unicode;
+	u16 modifier;
+	u16 affected_attribute;
+} __packed;
+
+struct efi_hii_keyboard_layout {
+	u16 layout_length;
+	efi_guid_t guid;
+	u32 layout_descriptor_string_offset;
+	u8 descriptor_count;
+	struct efi_key_descriptor descriptors[];
+} __packed;
+
+/*
+ * HII protocols
+ */
+#define EFI_HII_STRING_PROTOCOL_GUID \
+	EFI_GUID(0x0fd96974, 0x23aa, 0x4cdc, \
+		 0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a)
+
+struct efi_font_info {
+	efi_hii_font_style_t font_style;
+	u16 font_size;
+	u16 font_name[1];
+};
+
+struct efi_hii_string_protocol {
+	efi_status_t(EFIAPI *new_string)(
+		const struct efi_hii_string_protocol *this,
+		efi_hii_handle_t package_list,
+		efi_string_id_t *string_id,
+		const u8 *language,
+		const u16 *language_name,
+		const efi_string_t string,
+		const struct efi_font_info *string_font_info);
+	efi_status_t(EFIAPI *get_string)(
+		const struct efi_hii_string_protocol *this,
+		const u8 *language,
+		efi_hii_handle_t package_list,
+		efi_string_id_t string_id,
+		efi_string_t string,
+		efi_uintn_t *string_size,
+		struct efi_font_info **string_font_info);
+	efi_status_t(EFIAPI *set_string)(
+		const struct efi_hii_string_protocol *this,
+		efi_hii_handle_t package_list,
+		efi_string_id_t string_id,
+		const u8 *language,
+		const efi_string_t string,
+		const struct efi_font_info *string_font_info);
+	efi_status_t(EFIAPI *get_languages)(
+		const struct efi_hii_string_protocol *this,
+		efi_hii_handle_t package_list,
+		u8 *languages,
+		efi_uintn_t *languages_size);
+	efi_status_t(EFIAPI *get_secondary_languages)(
+		const struct efi_hii_string_protocol *this,
+		efi_hii_handle_t package_list,
+		const u8 *primary_language,
+		u8 *secondary_languages,
+		efi_uintn_t *secondary_languages_size);
+};
+
+#define EFI_HII_DATABASE_PROTOCOL_GUID	     \
+	EFI_GUID(0xef9fc172, 0xa1b2, 0x4693, \
+		 0xb3, 0x27, 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42)
+
+struct efi_hii_database_protocol {
+	efi_status_t(EFIAPI *new_package_list)(
+		const struct efi_hii_database_protocol *this,
+		const struct efi_hii_package_list_header *package_list,
+		const efi_handle_t driver_handle,
+		efi_hii_handle_t *handle);
+	efi_status_t(EFIAPI *remove_package_list)(
+		const struct efi_hii_database_protocol *this,
+		efi_hii_handle_t handle);
+	efi_status_t(EFIAPI *update_package_list)(
+		const struct efi_hii_database_protocol *this,
+		efi_hii_handle_t handle,
+		const struct efi_hii_package_list_header *package_list);
+	efi_status_t(EFIAPI *list_package_lists)(
+		const struct efi_hii_database_protocol *this,
+		u8 package_type,
+		const efi_guid_t *package_guid,
+		efi_uintn_t *handle_buffer_length,
+		efi_hii_handle_t *handle);
+	efi_status_t(EFIAPI *export_package_lists)(
+		const struct efi_hii_database_protocol *this,
+		efi_hii_handle_t handle,
+		efi_uintn_t *buffer_size,
+		struct efi_hii_package_list_header *buffer);
+	efi_status_t(EFIAPI *register_package_notify)(
+		const struct efi_hii_database_protocol *this,
+		u8 package_type,
+		const efi_guid_t *package_guid,
+		const void *package_notify_fn,
+		efi_uintn_t notify_type,
+		efi_handle_t *notify_handle);
+	efi_status_t(EFIAPI *unregister_package_notify)(
+		const struct efi_hii_database_protocol *this,
+		efi_handle_t notification_handle
+		);
+	efi_status_t(EFIAPI *find_keyboard_layouts)(
+		const struct efi_hii_database_protocol *this,
+		u16 *key_guid_buffer_length,
+		efi_guid_t *key_guid_buffer);
+	efi_status_t(EFIAPI *get_keyboard_layout)(
+		const struct efi_hii_database_protocol *this,
+		efi_guid_t *key_guid,
+		u16 *keyboard_layout_length,
+		struct efi_hii_keyboard_layout *keyboard_layout);
+	efi_status_t(EFIAPI *set_keyboard_layout)(
+		const struct efi_hii_database_protocol *this,
+		efi_guid_t *key_guid);
+	efi_status_t(EFIAPI *get_package_list_handle)(
+		const struct efi_hii_database_protocol *this,
+		efi_hii_handle_t package_list_handle,
+		efi_handle_t *driver_handle);
+};
+
 #define EFI_GOP_GUID \
 	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
 		 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
include/efi_loader.h +4 -0
index 6323686f9d37..18384a8caf5c 100644
@@ -106,6 +106,8 @@ extern const struct efi_device_path_utilities_protocol
 /* Implementation of the EFI_UNICODE_COLLATION_PROTOCOL */
 extern const struct efi_unicode_collation_protocol
 					efi_unicode_collation_protocol;
+extern const struct efi_hii_database_protocol efi_hii_database;
+extern const struct efi_hii_string_protocol efi_hii_string;
 
 uint16_t *efi_dp_str(struct efi_device_path *dp);
 
@@ -139,6 +141,8 @@ extern const efi_guid_t efi_file_system_info_guid;
 extern const efi_guid_t efi_guid_device_path_utilities_protocol;
 /* GUID of the Unicode collation protocol */
 extern const efi_guid_t efi_guid_unicode_collation_protocol;
+extern const efi_guid_t efi_guid_hii_database_protocol;
+extern const efi_guid_t efi_guid_hii_string_protocol;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
lib/efi_loader/Makefile +1 -0
index a7bba58d4126..dc8bc1461cb9 100644
@@ -24,6 +24,7 @@ obj-y += efi_device_path.o
 obj-y += efi_device_path_to_text.o
 obj-y += efi_device_path_utilities.o
 obj-y += efi_file.o
+obj-y += efi_hii.o
 obj-y += efi_image_loader.o
 obj-y += efi_memory.o
 obj-y += efi_root_node.o
lib/efi_loader/efi_boottime.c +12 -0
index cc9efbb0cbfd..ba2e1f652afe 100644
@@ -1558,6 +1558,18 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
 	if (ret != EFI_SUCCESS)
 		goto failure;
 
+	ret = efi_add_protocol(&obj->header,
+			       &efi_guid_hii_string_protocol,
+			       (void *)&efi_hii_string);
+	if (ret != EFI_SUCCESS)
+		goto failure;
+
+	ret = efi_add_protocol(&obj->header,
+			       &efi_guid_hii_database_protocol,
+			       (void *)&efi_hii_database);
+	if (ret != EFI_SUCCESS)
+		goto failure;
+
 	return ret;
 failure:
 	printf("ERROR: Failure to install protocols for loaded image\n");
lib/efi_loader/efi_hii.c new file +922 -0

922 lines not on this page · raw message

Signature · 1 line
2.19.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH v3 1/5 efi_loader: Initial HII database protocols

Quoted 20 lines · Alexander Graf
Quoted 20 lines

From: Leif Lindholm <[email protected]>

This patch provides enough implementation of the following protocols to run EDKII's Shell.efi and UEFI SCT:

* EfiHiiDatabaseProtocol
* EfiHiiStringProtocol

Not implemented are:
* ExportPackageLists()
* RegisterPackageNotify()/UnregisterPackageNotify()
* SetKeyboardLayout() (i.e. *current* keyboard layout)

HII database protocol in this patch series can handle only:
* GUID package
* string package
* keyboard layout package
(The other packages, except Device path package, will be necessary
for interactive and graphical UI.)

Quoted 9 lines
Quoted 3 lines

Thanks, applied to efi-next

Alex

I have rebased the efi-next tree upon U-Boot master. My Odroid C2 crashes when booting via U-Boot -> iPXE -> GRUB -> Linux. Bisection points to this patch. The HII protocols are referenced by iPXE if available.

An interesting comment in
https://www.spinics.net/lists/arm-kernel/msg704238.html for a similar U-Boot related error is:

"Looks like you're taking the SError as soon as we unmask them, so it could've been pending for ages. It would be interesting to see if it's actually caused by the kernel, or if the firmware triggers it beforehand."

Booting via iPXE is described in doc/README.iscsi

This patch and some follow up patches are included in the pull request for the EFI tree.

I would prefer if we could remove the HII protocols from the pull request until the patches are thoroughly tested.

Loading Linux 4.19.0-1-arm64 ...
Loading initial ramdisk ...
EFI stub: Booting Linux Kernel...
EFI stub: EFI_RNG_PROTOCOL unavailable, no randomness supplied EFI stub: Using DTB from configuration table
EFI stub: Exiting boot services and installing virtual address map...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 4.19.0-1-arm64
(debian-kernel at lists.debian.org) (gcc version 8.2.0 (Debian 8)
[    0.000000] Machine model: Hardkernel ODROID-C2
[    0.000000] earlycon: meson0 at MMIO 0x00000000c81004c0 (options
'115200n8')
[    0.000000] bootconsole [meson0] enabled
[    0.000000] SError Interrupt on CPU0, code 0xbf000000 -- SError
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-1-arm64 #1
Debian 4.19.12-1
[    0.000000] Hardware name: Hardkernel ODROID-C2 (DT)
[    0.000000] pstate: 00000085 (nzcv daIf -PAN -UAO)
[    0.000000] pc : setup_arch+0x104/0x570
[    0.000000] lr : setup_arch+0xfc/0x570
[    0.000000] sp : ffff000009293f10
[    0.000000] x29: ffff000009293f10 x28: 00000000023d0018
[    0.000000] x27: 000000007c9b30c0 x26: 0000000000000000
[    0.000000] x25: 0000000000000000 x24: 000000007ca7e000
[    0.000000] x23: 0000000000000000 x22: ffff000009299708
[    0.000000] x21: ffff7dfffe8000d4 x20: ffff0000092e3330
[    0.000000] x19: ffff000008080000 x18: 0000000000000010
[    0.000000] x17: 0000000000000000 x16: 0000000000000000
[    0.000000] x15: ffffffffffffffff x14: ffff000009299708
[    0.000000] x13: ffff00008943937f x12: 0000000000000028
[    0.000000] x11: 0000000000000007 x10: 0101010101010101
[    0.000000] x9 : fffffffffffffffb x8 : 0000000000000008
[    0.000000] x7 : 0000000000000003 x6 : 0000000000800000
[    0.000000] x5 : 0000800000000000 x4 : 0000000000000065
[    0.000000] x3 : 0000000000000063 x2 : 0000000000000000
[    0.000000] x1 : 0000000000000000 x0 : 0000000000000080
[    0.000000] Kernel panic - not syncing: Asynchronous SError Interrupt
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-1-arm64 #1
Debian 4.19.12-1
[    0.000000] Hardware name: Hardkernel ODROID-C2 (DT)
[    0.000000] Call trace:
[    0.000000]  dump_backtrace+0x0/0x180
[    0.000000]  show_stack+0x24/0x30
[    0.000000]  dump_stack+0x90/0xb4
[    0.000000]  panic+0x128/0x290
[    0.000000]  nmi_panic+0x7c/0x80
[    0.000000]  arm64_serror_panic+0x80/0x8c
[    0.000000]  is_valid_bugaddr+0x0/0x1c
[    0.000000]  el1_error+0x7c/0xdc
[    0.000000]  setup_arch+0x104/0x570
[    0.000000]  start_kernel+0x78/0x4c0

Best regards

Heinrich

#4 lore raw

PATCH v3 1/5 efi_loader: Initial HII database protocols

Quoted 41 lines · Heinrich Schuchardt
Quoted 20 lines · Alexander Graf
Quoted 20 lines

From: Leif Lindholm <[email protected]>

This patch provides enough implementation of the following protocols to run EDKII's Shell.efi and UEFI SCT:

* EfiHiiDatabaseProtocol
* EfiHiiStringProtocol

Not implemented are:
* ExportPackageLists()
* RegisterPackageNotify()/UnregisterPackageNotify()
* SetKeyboardLayout() (i.e. *current* keyboard layout)

HII database protocol in this patch series can handle only:
* GUID package
* string package
* keyboard layout package
(The other packages, except Device path package, will be necessary
for interactive and graphical UI.)

Quoted 8 lines
Quoted 3 lines

Thanks, applied to efi-next

Alex

I have rebased the efi-next tree upon U-Boot master. My Odroid C2 crashes when booting via U-Boot -> iPXE -> GRUB -> Linux. Bisection points to this patch. The HII protocols are referenced by iPXE if available.

An interesting comment in
https://www.spinics.net/lists/arm-kernel/msg704238.html for a similar U-Boot related error is:

"Looks like you're taking the SError as soon as we unmask them, so it could've been pending for ages. It would be interesting to see if it's actually caused by the kernel, or if the firmware triggers it beforehand."

Quoted 7 lines

Booting via iPXE is described in doc/README.iscsi

This patch and some follow up patches are included in the pull request for the EFI tree.

I would prefer if we could remove the HII protocols from the pull request until the patches are thoroughly tested.

I've posted a patch to remove only the protocol exposure. That way we can leave most bits in.

The #SError sounds like something is trying to write to a memory location that is not backed by a device. That is usually an indicator for a NULL dereference. Maybe by looking at the respective iPXE code, you will be able to find the spot that does the invalid access?

Alex

#5 lore raw

PATCH v3 1/5 efi_loader: Initial HII database protocols

Alex, Heinrich,

Quoted 50 lines · Alexander Graf
Quoted 41 lines · Heinrich Schuchardt
Quoted 20 lines · Alexander Graf
Quoted 20 lines

From: Leif Lindholm <[email protected]>

This patch provides enough implementation of the following protocols to run EDKII's Shell.efi and UEFI SCT:

* EfiHiiDatabaseProtocol
* EfiHiiStringProtocol

Not implemented are:
* ExportPackageLists()
* RegisterPackageNotify()/UnregisterPackageNotify()
* SetKeyboardLayout() (i.e. *current* keyboard layout)

HII database protocol in this patch series can handle only:
* GUID package
* string package
* keyboard layout package
(The other packages, except Device path package, will be necessary
for interactive and graphical UI.)

Quoted 8 lines
Quoted 3 lines

Thanks, applied to efi-next

Alex

I have rebased the efi-next tree upon U-Boot master. My Odroid C2 crashes when booting via U-Boot -> iPXE -> GRUB -> Linux. Bisection points to this patch. The HII protocols are referenced by iPXE if available.

An interesting comment in
https://www.spinics.net/lists/arm-kernel/msg704238.html for a similar U-Boot related error is:

"Looks like you're taking the SError as soon as we unmask them, so it could've been pending for ages. It would be interesting to see if it's actually caused by the kernel, or if the firmware triggers it beforehand."

Quoted 7 lines

Booting via iPXE is described in doc/README.iscsi

This patch and some follow up patches are included in the pull request for the EFI tree.

I would prefer if we could remove the HII protocols from the pull request until the patches are thoroughly tested.

Quoted 7 lines

I've posted a patch to remove only the protocol exposure. That way we can leave most bits in.

The #SError sounds like something is trying to write to a memory location that is not backed by a device. That is usually an indicator for a NULL dereference. Maybe by looking at the respective iPXE code, you will be able to find the spot that does the invalid access?

Taking a quick look at iPXE code (src/interface/efi/*), it uses
* HII_PACKAGE_FORMS
* HII_PACKAGE_STRINGS
* HII_CONFIG_ROUTING_PROTOCOL
* HII_CONFIG_ACCESS_PROTOCOL
but my current patch doesn't support neither PACKAGE_FORMS nor CONFIG_*_PROTOCOL. One of those might be a root cause. (I don't know when and how SError was triggered though.)

-Takahiro Akashi

Quoted 3 lines

Alex

#6 lore raw

PATCH v3 2/5 efi: hii: add guid package support

In reply to AKASHI Takahiro

Allow for handling GUID package in HII database protocol.

---
 include/efi_api.h        |  9 ++++++++
 lib/efi_loader/efi_hii.c | 48 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 51 insertions(+), 6 deletions(-)
include/efi_api.h +9 -0
index 67c3753de0b1..b2e77832a756 100644
@@ -741,6 +741,15 @@ struct efi_hii_package_header {
 #define EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN 0xE0
 #define EFI_HII_PACKAGE_TYPE_SYSTEM_END   0xFF
 
+/*
+ * HII GUID package
+ */
+struct efi_hii_guid_package {
+	struct efi_hii_package_header header;
+	efi_guid_t guid;
+	char data[];
+} __packed;
+
 /*
  * HII string package
  */
lib/efi_loader/efi_hii.c +42 -6

96 lines not on this page · raw message

Signature · 1 line
2.19.1
#7 lore raw

PATCH v3 3/5 efi: hii: add keyboard layout package support

In reply to AKASHI Takahiro

Allow for handling keyboard layout package in HII database protocol.

A package can be added or deleted in HII database protocol, but we don't set 'current' keyboard layout as there is no driver that requests a keyboard layout.

---
 include/efi_api.h        |   6 ++
 lib/efi_loader/efi_hii.c | 147 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 148 insertions(+), 5 deletions(-)
include/efi_api.h +6 -0
index b2e77832a756..46a86535a83d 100644
@@ -842,6 +842,12 @@ struct efi_hii_keyboard_layout {
 	struct efi_key_descriptor descriptors[];
 } __packed;
 
+struct efi_hii_keyboard_package {
+	struct efi_hii_package_header header;
+	u16 layout_count;
+	struct efi_hii_keyboard_layout layout[];
+} __packed;
+
 /*
  * HII protocols
  */
lib/efi_loader/efi_hii.c +142 -5

219 lines not on this page · raw message

Signature · 1 line
2.19.1
#8 lore raw

PATCH v3 4/5 efi: hii: add HII config routing/access protocols

In reply to AKASHI Takahiro

This patch is a place holder for HII configuration routing protocol and HII configuration access protocol.

---
 include/efi_api.h               | 161 ++++++++++++++++++++++++++++++++
 include/efi_loader.h            |   4 +
 lib/efi_loader/Makefile         |   2 +-
 lib/efi_loader/efi_boottime.c   |   6 ++
 lib/efi_loader/efi_hii_config.c | 146 +++++++++++++++++++++++++++++
 5 files changed, 318 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_hii_config.c
include/efi_api.h +161 -0
index 46a86535a83d..09c4320f1ac8 100644
@@ -39,6 +39,9 @@ typedef void *efi_hii_handle_t;
 typedef u16 *efi_string_t;
 typedef u16 efi_string_id_t;
 typedef u32 efi_hii_font_style_t;
+typedef u16 efi_question_id_t;
+typedef u16 efi_image_id_t;
+typedef u16 efi_form_id_t;
 
 #define EVT_TIMER				0x80000000
 #define EVT_RUNTIME				0x40000000
@@ -796,6 +799,101 @@ efi_hii_sibt_string_ucs2_block_next(struct efi_hii_sibt_string_ucs2_block *blk)
 		(u16_strlen(blk->string_text) + 1) * 2;
 }
 
+/*
+ * HII forms package
+ * TODO: full scope of definitions
+ */
+struct efi_hii_time {
+	u8 hour;
+	u8 minute;
+	u8 second;
+};
+
+struct efi_hii_date {
+	u16 year;
+	u8 month;
+	u8 day;
+};
+
+struct efi_hii_ref {
+	efi_question_id_t question_id;
+	efi_form_id_t form_id;
+	efi_guid_t form_set_guid;
+	efi_string_id_t device_path;
+};
+
+union efi_ifr_type_value {
+	u8 u8;				// EFI_IFR_TYPE_NUM_SIZE_8
+	u16 u16;			// EFI_IFR_TYPE_NUM_SIZE_16
+	u32 u32;			// EFI_IFR_TYPE_NUM_SIZE_32
+	u64 u64;			// EFI_IFR_TYPE_NUM_SIZE_64
+	bool b;				// EFI_IFR_TYPE_BOOLEAN
+	struct efi_hii_time time;	// EFI_IFR_TYPE_TIME
+	struct efi_hii_date date;	// EFI_IFR_TYPE_DATE
+	efi_string_id_t string;	// EFI_IFR_TYPE_STRING, EFI_IFR_TYPE_ACTION
+	struct efi_hii_ref ref;		// EFI_IFR_TYPE_REF
+	// u8 buffer[];			// EFI_IFR_TYPE_BUFFER
+};
+
+#define EFI_IFR_TYPE_NUM_SIZE_8		0x00
+#define EFI_IFR_TYPE_NUM_SIZE_16	0x01
+#define EFI_IFR_TYPE_NUM_SIZE_32	0x02
+#define EFI_IFR_TYPE_NUM_SIZE_64	0x03
+#define EFI_IFR_TYPE_BOOLEAN		0x04
+#define EFI_IFR_TYPE_TIME		0x05
+#define EFI_IFR_TYPE_DATE		0x06
+#define EFI_IFR_TYPE_STRING		0x07
+#define EFI_IFR_TYPE_OTHER		0x08
+#define EFI_IFR_TYPE_UNDEFINED		0x09
+#define EFI_IFR_TYPE_ACTION		0x0A
+#define EFI_IFR_TYPE_BUFFER		0x0B
+#define EFI_IFR_TYPE_REF		0x0C
+#define EFI_IFR_OPTION_DEFAULT		0x10
+#define EFI_IFR_OPTION_DEFAULT_MFG	0x20
+
+#define EFI_IFR_ONE_OF_OPTION_OP	0x09
+
+struct efi_ifr_op_header {
+	u8 opCode;
+	u8 length:7;
+	u8 scope:1;
+};
+
+struct efi_ifr_one_of_option {
+	struct efi_ifr_op_header header;
+	efi_string_id_t option;
+	u8 flags;
+	u8 type;
+	union efi_ifr_type_value value;
+};
+
+typedef efi_uintn_t efi_browser_action_t;
+
+#define EFI_BROWSER_ACTION_REQUEST_NONE			0
+#define EFI_BROWSER_ACTION_REQUEST_RESET		1
+#define EFI_BROWSER_ACTION_REQUEST_SUBMIT		2
+#define EFI_BROWSER_ACTION_REQUEST_EXIT			3
+#define EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT	4
+#define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT	5
+#define EFI_BROWSER_ACTION_REQUEST_FORM_APPLY		6
+#define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD		7
+#define EFI_BROWSER_ACTION_REQUEST_RECONNECT		8
+
+typedef efi_uintn_t efi_browser_action_request_t;
+
+#define EFI_BROWSER_ACTION_CHANGING			0
+#define EFI_BROWSER_ACTION_CHANGED			1
+#define EFI_BROWSER_ACTION_RETRIEVE			2
+#define EFI_BROWSER_ACTION_FORM_OPEN			3
+#define EFI_BROWSER_ACTION_FORM_CLOSE			4
+#define EFI_BROWSER_ACTION_SUBMITTED			5
+#define EFI_BROWSER_ACTION_DEFAULT_STANDARD		0x1000
+#define EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING	0x1001
+#define EFI_BROWSER_ACTION_DEFAULT_SAFE			0x1002
+#define EFI_BROWSER_ACTION_DEFAULT_PLATFORM		0x2000
+#define EFI_BROWSER_ACTION_DEFAULT_HARDWARE		0x3000
+#define EFI_BROWSER_ACTION_DEFAULT_FIRMWARE		0x4000
+
 /*
  * HII keyboard package
  */
@@ -955,6 +1053,69 @@ struct efi_hii_database_protocol {
 		efi_handle_t *driver_handle);
 };
 
+#define EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID \
+	EFI_GUID(0x587e72d7, 0xcc50, 0x4f79, \
+		 0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f)
+
+struct efi_hii_config_routing_protocol {
+	efi_status_t(EFIAPI *extract_config)(
+		const struct efi_hii_config_routing_protocol *this,
+		const efi_string_t request,
+		efi_string_t *progress,
+		efi_string_t *results);
+	efi_status_t(EFIAPI *export_config)(
+		const struct efi_hii_config_routing_protocol *this,
+		efi_string_t *results);
+	efi_status_t(EFIAPI *route_config)(
+		const struct efi_hii_config_routing_protocol *this,
+		const efi_string_t configuration,
+		efi_string_t *progress);
+	efi_status_t(EFIAPI *block_to_config)(
+		const struct efi_hii_config_routing_protocol *this,
+		const efi_string_t config_request,
+		const uint8_t *block,
+		const efi_uintn_t block_size,
+		efi_string_t *config,
+		efi_string_t *progress);
+	efi_status_t(EFIAPI *config_to_block)(
+		const struct efi_hii_config_routing_protocol *this,
+		const efi_string_t config_resp,
+		const uint8_t *block,
+		const efi_uintn_t *block_size,
+		efi_string_t *progress);
+	efi_status_t(EFIAPI *get_alt_config)(
+		const struct efi_hii_config_routing_protocol *this,
+		const efi_string_t config_resp,
+		const efi_guid_t *guid,
+		const efi_string_t name,
+		const struct efi_device_path *device_path,
+		const efi_string_t alt_cfg_id,
+		efi_string_t *alt_cfg_resp);
+};
+
+#define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
+	EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, \
+		 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
+
+struct efi_hii_config_access_protocol {
+	efi_status_t(EFIAPI *extract_config_access)(
+		const struct efi_hii_config_access_protocol *this,
+		const efi_string_t request,
+		efi_string_t *progress,
+		efi_string_t *results);
+	efi_status_t(EFIAPI *route_config_access)(
+		const struct efi_hii_config_access_protocol *this,
+		const efi_string_t configuration,
+		efi_string_t *progress);
+	efi_status_t(EFIAPI *form_callback)(
+		const struct efi_hii_config_access_protocol *this,
+		efi_browser_action_t action,
+		efi_question_id_t question_id,
+		u8 type,
+		union efi_ifr_type_value *value,
+		efi_browser_action_request_t *action_request);
+};
+
 #define EFI_GOP_GUID \
 	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
 		 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
include/efi_loader.h +4 -0
index 18384a8caf5c..dd68cfce5c65 100644
@@ -106,6 +106,8 @@ extern const struct efi_device_path_utilities_protocol
 /* Implementation of the EFI_UNICODE_COLLATION_PROTOCOL */
 extern const struct efi_unicode_collation_protocol
 					efi_unicode_collation_protocol;
+extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
+extern const struct efi_hii_config_access_protocol efi_hii_config_access;
 extern const struct efi_hii_database_protocol efi_hii_database;
 extern const struct efi_hii_string_protocol efi_hii_string;
 
@@ -141,6 +143,8 @@ extern const efi_guid_t efi_file_system_info_guid;
 extern const efi_guid_t efi_guid_device_path_utilities_protocol;
 /* GUID of the Unicode collation protocol */
 extern const efi_guid_t efi_guid_unicode_collation_protocol;
+extern const efi_guid_t efi_guid_hii_config_routing_protocol;
+extern const efi_guid_t efi_guid_hii_config_access_protocol;
 extern const efi_guid_t efi_guid_hii_database_protocol;
 extern const efi_guid_t efi_guid_hii_string_protocol;
 
lib/efi_loader/Makefile +1 -1
index dc8bc1461cb9..3ba539314aee 100644
@@ -24,7 +24,7 @@ obj-y += efi_device_path.o
 obj-y += efi_device_path_to_text.o
 obj-y += efi_device_path_utilities.o
 obj-y += efi_file.o
-obj-y += efi_hii.o
+obj-y += efi_hii.o efi_hii_config.o
 obj-y += efi_image_loader.o
 obj-y += efi_memory.o
 obj-y += efi_root_node.o
lib/efi_loader/efi_boottime.c +6 -0
index ba2e1f652afe..291bc1bd35f9 100644
@@ -1570,6 +1570,12 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
 	if (ret != EFI_SUCCESS)
 		goto failure;
 
+	ret = efi_add_protocol(&obj->header,
+			       &efi_guid_hii_config_routing_protocol,
+			       (void *)&efi_hii_config_routing);
+	if (ret != EFI_SUCCESS)
+		goto failure;
+
 	return ret;
 failure:
 	printf("ERROR: Failure to install protocols for loaded image\n");
lib/efi_loader/efi_hii_config.c new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.19.1
#9 lore raw

PATCH v3 5/5 efi_selftest: add HII database protocols test

In reply to AKASHI Takahiro

This efi_selftest tests HII database protocol and HII string protocol.

---
 lib/efi_selftest/Makefile                |    1 +
 lib/efi_selftest/efi_selftest_hii.c      | 1046 ++++++++++++++++++++++
 lib/efi_selftest/efi_selftest_hii_data.c |  453 ++++++++++
 3 files changed, 1500 insertions(+)
 create mode 100644 lib/efi_selftest/efi_selftest_hii.c
 create mode 100644 lib/efi_selftest/efi_selftest_hii_data.c
lib/efi_selftest/Makefile +1 -0
index 743b48204493..5cd8a757a3eb 100644
@@ -25,6 +25,7 @@ efi_selftest_exception.o \
 efi_selftest_exitbootservices.o \
 efi_selftest_fdt.o \
 efi_selftest_gop.o \
+efi_selftest_hii.o \
 efi_selftest_loaded_image.o \
 efi_selftest_manageprotocols.o \
 efi_selftest_memory.o \
lib/efi_selftest/efi_selftest_hii.c new file +1046 -0

1,046 lines not on this page · raw message

lib/efi_selftest/efi_selftest_hii_data.c new file +453 -0

453 lines not on this page · raw message

Signature · 1 line
2.19.1
#10 lore raw

v3 cover subject: efi_loader: add HII database protocol

In reply to AKASHI Takahiro
Quoted 10 lines · AKASHI Takahiro

HII database protocol is the last missing (major?) piece of code so that we can run unmodified EDKII's shell and UEFI SCT on EFI-enabled u-boot.

The original code was initially written by Leif and Rob a year ago[1], and now I'm reworking it. The implementation has not been much enhanced from the original, but I tried to give it clearer implementation to be able to add more functionality easily later on.
I also addressed the comments by Alex[2] and added a self test on request of Heinrich.

Quoted 3 lines

HII configuration routing protocol and access protocol have only a skeleton and should be implemented when we need to have *drivers* that require configuration mechanism.

But I'll wait for Heinrich's ok as well :)

Alex

#11 lore raw

v3 cover subject: efi_loader: add HII database protocol

Quoted 17 lines · Alexander Graf
Quoted 10 lines · AKASHI Takahiro

HII database protocol is the last missing (major?) piece of code so that we can run unmodified EDKII's shell and UEFI SCT on EFI-enabled u-boot.

The original code was initially written by Leif and Rob a year ago[1], and now I'm reworking it. The implementation has not been much enhanced from the original, but I tried to give it clearer implementation to be able to add more functionality easily later on.
I also addressed the comments by Alex[2] and added a self test on request of Heinrich.

Quoted 3 lines

HII configuration routing protocol and access protocol have only a skeleton and should be implemented when we need to have *drivers* that require configuration mechanism.

Quoted 7 lines

But I'll wait for Heinrich's ok as well :)

Alex

I have seen that Takahiro has integrated my recent suggestions.

Currently I am still trying to understand what is wrong with GetNextVariableName().

So let's go with your review.

Best regards

Heinrich

#12 lore raw

v3 cover subject: efi_loader: add HII database protocol

Heinrich,

Quoted 23 lines · Heinrich Schuchardt
Quoted 22 lines · Alexander Graf
Quoted 10 lines · AKASHI Takahiro

HII database protocol is the last missing (major?) piece of code so that we can run unmodified EDKII's shell and UEFI SCT on EFI-enabled u-boot.

The original code was initially written by Leif and Rob a year ago[1], and now I'm reworking it. The implementation has not been much enhanced from the original, but I tried to give it clearer implementation to be able to add more functionality easily later on.
I also addressed the comments by Alex[2] and added a self test on request of Heinrich.

Quoted 3 lines

HII configuration routing protocol and access protocol have only a skeleton and should be implemented when we need to have *drivers* that require configuration mechanism.

But I'll wait for Heinrich's ok as well :)

Quoted 6 lines
Quoted 2 lines

Alex

I have seen that Takahiro has integrated my recent suggestions.

Currently I am still trying to understand what is wrong with GetNextVariableName().

Thank you for finding and investigating this issue. I almost all of my time test my patches on arm64 primarily :)

-Takahiro Akashi

Quoted 5 lines

So let's go with your review.

Best regards

Heinrich

#13 lore raw

v3 cover subject: efi_loader: add HII database protocol

Quoted 32 lines

Am 23.01.2019 um 06:11 schrieb AKASHI Takahiro <[email protected]>:

Heinrich,

Quoted 26 lines · Heinrich Schuchardt
Quoted 25 lines · Alexander Graf
Quoted 13 lines · AKASHI Takahiro

HII database protocol is the last missing (major?) piece of code so that we can run unmodified EDKII's shell and UEFI SCT on EFI-enabled u-boot.

The original code was initially written by Leif and Rob a year ago[1], and now I'm reworking it. The implementation has not been much enhanced from the original, but I tried to give it clearer implementation to be able to add more functionality easily later on.
I also addressed the comments by Alex[2] and added a self test on request of Heinrich.

Quoted 3 lines

HII configuration routing protocol and access protocol have only a skeleton and should be implemented when we need to have *drivers* that require configuration mechanism.

But I'll wait for Heinrich's ok as well :)

Alex

Quoted 7 lines
Quoted 4 lines

I have seen that Takahiro has integrated my recent suggestions.

Currently I am still trying to understand what is wrong with GetNextVariableName().

Thank you for finding and investigating this issue. I almost all of my time test my patches on arm64 primarily :)

Please always push your patch queues as braches to github and enable travis there. It will tell you quite conclusive test results, so that you don't break others targets by accident :).

Alex

Quoted 8 lines

-Takahiro Akashi

Quoted 5 lines

So let's go with your review.

Best regards

Heinrich