diff options
-rw-r--r-- | README | 21 | ||||
-rw-r--r-- | cmd/bootmenu.c | 4 | ||||
-rw-r--r-- | cmd/eficonfig.c | 410 | ||||
-rw-r--r-- | doc/develop/uefi/uefi.rst | 7 | ||||
-rw-r--r-- | drivers/video/Kconfig | 8 | ||||
-rw-r--r-- | drivers/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/console_core.c | 6 | ||||
-rw-r--r-- | drivers/video/dw_mipi_dsi.c | 4 | ||||
-rw-r--r-- | drivers/video/himax-hx8394.c | 237 | ||||
-rw-r--r-- | drivers/video/pwm_backlight.c | 2 | ||||
-rw-r--r-- | drivers/video/rockchip/dw_mipi_dsi_rockchip.c | 38 | ||||
-rw-r--r-- | drivers/video/rockchip/rk_vop.c | 2 | ||||
-rw-r--r-- | include/efi_config.h | 5 | ||||
-rw-r--r-- | include/efi_loader.h | 11 | ||||
-rw-r--r-- | lib/efi_loader/efi_bootmgr.c | 385 | ||||
-rw-r--r-- | lib/efi_loader/efi_boottime.c | 43 | ||||
-rw-r--r-- | lib/efi_loader/efi_helper.c | 25 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_controllers.c | 44 |
18 files changed, 792 insertions, 461 deletions
@@ -2430,27 +2430,6 @@ Hit 'q': [q, b, e, ?] ## Application terminated, rc = 0x0 -Minicom warning: -================ - -Over time, many people have reported problems when trying to use the -"minicom" terminal emulation program for serial download. I (wd) -consider minicom to be broken, and recommend not to use it. Under -Unix, I recommend to use C-Kermit for general purpose use (and -especially for kermit binary protocol download ("loadb" command), and -use "cu" for S-Record download ("loads" command). See -https://www.denx.de/wiki/view/DULG/SystemSetup#Section_4.3. -for help with kermit. - - -Nevertheless, if you absolutely want to use it try adding this -configuration to your "File transfer protocols" section: - - Name Program Name U/D FullScr IO-Red. Multi - X kermit /usr/bin/kermit -i -l %l -s Y U Y N N - Y kermit /usr/bin/kermit -i -l %l -r N D Y N N - - Implementation Internals: ========================= diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 6baeedc69f..987b16889f 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -351,8 +351,8 @@ static struct bootmenu_data *bootmenu_create(int delay) * UEFI specification requires booting from removal media using * a architecture-specific default image name such as BOOTAA64.EFI. */ - efi_ret = eficonfig_generate_media_device_boot_option(); - if (efi_ret != EFI_SUCCESS && efi_ret != EFI_NOT_FOUND) + efi_ret = efi_bootmgr_update_media_device_boot_option(); + if (efi_ret != EFI_SUCCESS) goto cleanup; ret = prepare_uefi_bootorder_entry(menu, &iter, &i); diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 720f52b48b..e6e8a0a488 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1135,43 +1135,6 @@ out: } /** - * eficonfig_get_unused_bootoption() - get unused "Boot####" index - * - * @buf: pointer to the buffer to store boot option variable name - * @buf_size: buffer size - * @index: pointer to store the index in the BootOrder variable - * Return: status code - */ -efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size, - unsigned int *index) -{ - u32 i; - efi_status_t ret; - efi_uintn_t size; - - if (buf_size < u16_strsize(u"Boot####")) - return EFI_BUFFER_TOO_SMALL; - - for (i = 0; i <= 0xFFFF; i++) { - size = 0; - efi_create_indexed_name(buf, buf_size, "Boot", i); - ret = efi_get_variable_int(buf, &efi_global_variable_guid, - NULL, &size, NULL, NULL); - if (ret == EFI_BUFFER_TOO_SMALL) - continue; - else - break; - } - - if (i > 0xFFFF) - return EFI_OUT_OF_RESOURCES; - - *index = i; - - return EFI_SUCCESS; -} - -/** * eficonfig_set_boot_option() - set boot option * * @varname: pointer to variable name @@ -1209,46 +1172,6 @@ static efi_status_t eficonfig_set_boot_option(u16 *varname, struct efi_device_pa } /** - * eficonfig_append_bootorder() - append new boot option in BootOrder variable - * - * @index: "Boot####" index to append to BootOrder variable - * Return: status code - */ -efi_status_t eficonfig_append_bootorder(u16 index) -{ - u16 *bootorder; - efi_status_t ret; - u16 *new_bootorder = NULL; - efi_uintn_t last, size, new_size; - - /* append new boot option */ - bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); - last = size / sizeof(u16); - new_size = size + sizeof(u16); - new_bootorder = calloc(1, new_size); - if (!new_bootorder) { - ret = EFI_OUT_OF_RESOURCES; - goto out; - } - memcpy(new_bootorder, bootorder, size); - new_bootorder[last] = index; - - ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - new_size, new_bootorder, false); - if (ret != EFI_SUCCESS) - goto out; - -out: - free(bootorder); - free(new_bootorder); - - return ret; -} - -/** * create_boot_option_entry() - create boot option entry * * @efi_menu: pointer to the efimenu structure @@ -1619,7 +1542,7 @@ static efi_status_t eficonfig_process_add_boot_option(void *data) if (!bo) return EFI_OUT_OF_RESOURCES; - ret = eficonfig_get_unused_bootoption(varname, sizeof(varname), &bo->boot_index); + ret = efi_bootmgr_get_unused_bootoption(varname, sizeof(varname), &bo->boot_index); if (ret != EFI_SUCCESS) return ret; @@ -1627,7 +1550,7 @@ static efi_status_t eficonfig_process_add_boot_option(void *data) if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_append_bootorder((u16)bo->boot_index); + ret = efi_bootmgr_append_bootorder((u16)bo->boot_index); if (ret != EFI_SUCCESS) goto out; @@ -1657,31 +1580,6 @@ static efi_status_t eficonfig_process_boot_selected(void *data) } /** - * search_bootorder() - search the boot option index in BootOrder - * - * @bootorder: pointer to the BootOrder variable - * @num: number of BootOrder entry - * @target: target boot option index to search - * @index: pointer to store the index of BootOrder variable - * Return: true if exists, false otherwise - */ -static bool search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index) -{ - u32 i; - - for (i = 0; i < num; i++) { - if (target == bootorder[i]) { - if (index) - *index = i; - - return true; - } - } - - return false; -} - -/** * eficonfig_add_boot_selection_entry() - add boot option menu entry * * @efi_menu: pointer to store the efimenu structure @@ -1805,7 +1703,7 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) if (efi_varname_is_load_option(var_name16, &index)) { /* If the index is included in the BootOrder, skip it */ - if (search_bootorder(bootorder, num, index, NULL)) + if (efi_search_bootorder(bootorder, num, index, NULL)) continue; ret = eficonfig_add_boot_selection_entry(efi_menu, index, selected); @@ -2202,7 +2100,7 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi if (efi_varname_is_load_option(var_name16, &index)) { /* If the index is included in the BootOrder, skip it */ - if (search_bootorder(bootorder, num, index, NULL)) + if (efi_search_bootorder(bootorder, num, index, NULL)) continue; ret = eficonfig_add_change_boot_order_entry(efi_menu, index, false); @@ -2305,50 +2203,6 @@ out: } /** - * delete_boot_option() - delete selected boot option - * - * @boot_index: boot option index to delete - * Return: status code - */ -static efi_status_t delete_boot_option(u16 boot_index) -{ - u16 *bootorder; - u16 varname[9]; - efi_status_t ret; - unsigned int index; - efi_uintn_t num, size; - - efi_create_indexed_name(varname, sizeof(varname), - "Boot", boot_index); - ret = efi_set_variable_int(varname, &efi_global_variable_guid, - 0, 0, NULL, false); - if (ret != EFI_SUCCESS) { - log_err("delete boot option(%ls) failed\n", varname); - return ret; - } - - /* update BootOrder if necessary */ - bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); - if (!bootorder) - return EFI_SUCCESS; - - num = size / sizeof(u16); - if (!search_bootorder(bootorder, num, boot_index, &index)) - return EFI_SUCCESS; - - memmove(&bootorder[index], &bootorder[index + 1], - (num - index - 1) * sizeof(u16)); - size -= sizeof(u16); - ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - size, bootorder, false); - - return ret; -} - -/** * eficonfig_process_delete_boot_option() - handler to delete boot option * * @data: pointer to the data for each entry @@ -2362,7 +2216,7 @@ static efi_status_t eficonfig_process_delete_boot_option(void *data) while (1) { ret = eficonfig_show_boot_selection(&selected); if (ret == EFI_SUCCESS) - ret = delete_boot_option(selected); + ret = efi_bootmgr_delete_boot_option(selected); if (ret != EFI_SUCCESS) break; @@ -2375,256 +2229,6 @@ static efi_status_t eficonfig_process_delete_boot_option(void *data) } /** - * eficonfig_enumerate_boot_option() - enumerate the possible bootable media - * - * @opt: pointer to the media boot option structure - * @volume_handles: pointer to the efi handles - * @count: number of efi handle - * Return: status code - */ -efi_status_t eficonfig_enumerate_boot_option(struct eficonfig_media_boot_option *opt, - efi_handle_t *volume_handles, efi_status_t count) -{ - u32 i; - struct efi_handler *handler; - efi_status_t ret = EFI_SUCCESS; - - for (i = 0; i < count; i++) { - u16 *p; - u16 dev_name[BOOTMENU_DEVICE_NAME_MAX]; - char *optional_data; - struct efi_load_option lo; - char buf[BOOTMENU_DEVICE_NAME_MAX]; - struct efi_device_path *device_path; - - ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); - if (ret != EFI_SUCCESS) - continue; - ret = efi_protocol_open(handler, (void **)&device_path, - efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (ret != EFI_SUCCESS) - continue; - - ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); - if (ret != EFI_SUCCESS) - continue; - - p = dev_name; - utf8_utf16_strncpy(&p, buf, strlen(buf)); - - lo.label = dev_name; - lo.attributes = LOAD_OPTION_ACTIVE; - lo.file_path = device_path; - lo.file_path_length = efi_dp_size(device_path) + sizeof(END); - /* - * Set the dedicated guid to optional_data, it is used to identify - * the boot option that automatically generated by the bootmenu. - * efi_serialize_load_option() expects optional_data is null-terminated - * utf8 string, so set the "1234567" string to allocate enough space - * to store guid, instead of realloc the load_option. - */ - lo.optional_data = "1234567"; - opt[i].size = efi_serialize_load_option(&lo, (u8 **)&opt[i].lo); - if (!opt[i].size) { - ret = EFI_OUT_OF_RESOURCES; - goto out; - } - /* set the guid */ - optional_data = (char *)opt[i].lo + (opt[i].size - u16_strsize(u"1234567")); - memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); - } - -out: - return ret; -} - -/** - * eficonfig_delete_invalid_boot_option() - delete non-existing boot option - * - * @opt: pointer to the media boot option structure - * @count: number of media boot option structure - * Return: status code - */ -efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_option *opt, - efi_status_t count) -{ - efi_uintn_t size; - void *load_option; - u32 i, list_size = 0; - struct efi_load_option lo; - u16 *var_name16 = NULL; - u16 varname[] = u"Boot####"; - efi_status_t ret = EFI_SUCCESS; - u16 *delete_index_list = NULL, *p; - efi_uintn_t buf_size; - - buf_size = 128; - var_name16 = malloc(buf_size); - if (!var_name16) - return EFI_OUT_OF_RESOURCES; - - var_name16[0] = 0; - for (;;) { - int index; - efi_guid_t guid; - efi_uintn_t tmp; - - ret = efi_next_variable_name(&buf_size, &var_name16, &guid); - if (ret == EFI_NOT_FOUND) { - /* - * EFI_NOT_FOUND indicates we retrieved all EFI variables. - * This should be treated as success. - */ - ret = EFI_SUCCESS; - break; - } - if (ret != EFI_SUCCESS) - goto out; - - if (!efi_varname_is_load_option(var_name16, &index)) - continue; - - efi_create_indexed_name(varname, sizeof(varname), "Boot", index); - load_option = efi_get_var(varname, &efi_global_variable_guid, &size); - if (!load_option) - continue; - - tmp = size; - ret = efi_deserialize_load_option(&lo, load_option, &size); - if (ret != EFI_SUCCESS) - goto next; - - if (size >= sizeof(efi_guid_bootmenu_auto_generated) && - !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { - for (i = 0; i < count; i++) { - if (opt[i].size == tmp && - memcmp(opt[i].lo, load_option, tmp) == 0) { - opt[i].exist = true; - break; - } - } - - /* - * The entire list of variables must be retrieved by - * efi_get_next_variable_name_int() before deleting the invalid - * boot option, just save the index here. - */ - if (i == count) { - p = realloc(delete_index_list, sizeof(u32) * - (list_size + 1)); - if (!p) { - ret = EFI_OUT_OF_RESOURCES; - goto out; - } - delete_index_list = p; - delete_index_list[list_size++] = index; - } - } -next: - free(load_option); - } - - /* delete all invalid boot options */ - for (i = 0; i < list_size; i++) { - ret = delete_boot_option(delete_index_list[i]); - if (ret != EFI_SUCCESS) - goto out; - } - -out: - free(var_name16); - free(delete_index_list); - - return ret; -} - -/** - * eficonfig_generate_media_device_boot_option() - generate the media device boot option - * - * This function enumerates all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL - * and generate the bootmenu entries. - * This function also provide the BOOT#### variable maintenance for - * the media device entries. - * - Automatically create the BOOT#### variable for the newly detected device, - * this BOOT#### variable is distinguished by the special GUID - * stored in the EFI_LOAD_OPTION.optional_data - * - If the device is not attached to the system, the associated BOOT#### variable - * is automatically deleted. - * - * Return: status code - */ -efi_status_t eficonfig_generate_media_device_boot_option(void) -{ - u32 i; - efi_status_t ret; - efi_uintn_t count; - efi_handle_t *volume_handles = NULL; - struct eficonfig_media_boot_option *opt = NULL; - - ret = efi_locate_handle_buffer_int(BY_PROTOCOL, &efi_simple_file_system_protocol_guid, - NULL, &count, (efi_handle_t **)&volume_handles); - if (ret != EFI_SUCCESS) - return ret; - - opt = calloc(count, sizeof(struct eficonfig_media_boot_option)); - if (!opt) - goto out; - - /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */ - ret = eficonfig_enumerate_boot_option(opt, volume_handles, count); - if (ret != EFI_SUCCESS) - goto out; - - /* - * System hardware configuration may vary depending on the user setup. - * The boot option is automatically added by the bootmenu. - * If the device is not attached to the system, the boot option needs - * to be deleted. - */ - ret = eficonfig_delete_invalid_boot_option(opt, count); - if (ret != EFI_SUCCESS) - goto out; - - /* add non-existent boot option */ - for (i = 0; i < count; i++) { - u32 boot_index; - u16 var_name[9]; - - if (!opt[i].exist) { - ret = eficonfig_get_unused_bootoption(var_name, sizeof(var_name), - &boot_index); - if (ret != EFI_SUCCESS) - goto out; - - ret = efi_set_variable_int(var_name, &efi_global_variable_guid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - opt[i].size, opt[i].lo, false); - if (ret != EFI_SUCCESS) - goto out; - - ret = eficonfig_append_bootorder(boot_index); - if (ret != EFI_SUCCESS) { - efi_set_variable_int(var_name, &efi_global_variable_guid, - 0, 0, NULL, false); - goto out; - } - } - } - -out: - if (opt) { - for (i = 0; i < count; i++) - free(opt[i].lo); - } - free(opt); - efi_free_pool(volume_handles); - - return ret; -} - -/** * eficonfig_init() - do required initialization for eficonfig command * * Return: status code @@ -2709,8 +2313,8 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const a if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - ret = eficonfig_generate_media_device_boot_option(); - if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND) + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) return ret; while (1) { diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst index 6626ceec52..a7a41f2fac 100644 --- a/doc/develop/uefi/uefi.rst +++ b/doc/develop/uefi/uefi.rst @@ -552,6 +552,13 @@ update using a capsule file with --fw-version of 5, the update will fail. When the --fw-version in the capsule file is updated, lowest-supported-version in the dtb might be updated accordingly. +If user needs to enforce anti-rollback to any older version, +the lowest-supported-version property in dtb must be always updated manually. + +Note that the lowest-supported-version property specified in U-Boot's control +device tree can be changed by U-Boot fdt command. +Secure systems should not enable this command. + To insert the lowest supported version into a dtb .. code-block:: console diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 2ba4f5eac7..b8147f280c 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -507,6 +507,14 @@ config VIDEO_LCD_ENDEAVORU using the same DSI command sequence. The panel has a 720x1280 resolution and uses 24 bit RGB per pixel. +config VIDEO_LCD_HIMAX_HX8394 + bool "Himax HX8394 DSI LCD panel support" + depends on PANEL && BACKLIGHT + select VIDEO_MIPI_DSI + help + Say Y here if you want to enable support for Himax HX8394 + dsi 4dl panel. + config VIDEO_LCD_ORISETECH_OTM8009A bool "OTM8009A DSI LCD panel support" select VIDEO_MIPI_DSI diff --git a/drivers/video/Makefile b/drivers/video/Makefile index a926370908..d13af9f3b1 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_VIDEO_IPUV3) += imx/ obj-$(CONFIG_VIDEO_IVYBRIDGE_IGD) += ivybridge_igd.o obj-$(CONFIG_VIDEO_LCD_ANX9804) += anx9804.o obj-$(CONFIG_VIDEO_LCD_ENDEAVORU) += endeavoru-panel.o +obj-$(CONFIG_VIDEO_LCD_HIMAX_HX8394) += himax-hx8394.o obj-$(CONFIG_VIDEO_LCD_HITACHI_TX18D42VM) += hitachi_tx18d42vm_lcd.o obj-$(CONFIG_VIDEO_LCD_ORISETECH_OTM8009A) += orisetech_otm8009a.o obj-$(CONFIG_VIDEO_LCD_RAYDIUM_RM68200) += raydium-rm68200.o diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c index 1f93b1b85f..b5d0e3dcec 100644 --- a/drivers/video/console_core.c +++ b/drivers/video/console_core.c @@ -201,6 +201,12 @@ int console_simple_select_font(struct udevice *dev, const char *name, uint size) { struct video_fontdata *font; + if (!name) { + if (fonts->name) + console_set_font(dev, fonts); + return 0; + } + for (font = fonts; font->name; font++) { if (!strcmp(name, font->name)) { console_set_font(dev, font); diff --git a/drivers/video/dw_mipi_dsi.c b/drivers/video/dw_mipi_dsi.c index 92e388ac1e..22fef7e882 100644 --- a/drivers/video/dw_mipi_dsi.c +++ b/drivers/video/dw_mipi_dsi.c @@ -538,9 +538,9 @@ static void dw_mipi_dsi_dpi_config(struct dw_mipi_dsi *dsi, break; } - if (device->mode_flags & DISPLAY_FLAGS_VSYNC_HIGH) + if (timings->flags & DISPLAY_FLAGS_VSYNC_LOW) val |= VSYNC_ACTIVE_LOW; - if (device->mode_flags & DISPLAY_FLAGS_HSYNC_HIGH) + if (timings->flags & DISPLAY_FLAGS_HSYNC_LOW) val |= HSYNC_ACTIVE_LOW; dsi_write(dsi, DSI_DPI_VCID, DPI_VCID(dsi->channel)); diff --git a/drivers/video/himax-hx8394.c b/drivers/video/himax-hx8394.c new file mode 100644 index 0000000000..63637b4db0 --- /dev/null +++ b/drivers/video/himax-hx8394.c @@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Ondrej Jirman <megi@xff.cz> + */ +#include <common.h> +#include <backlight.h> +#include <dm.h> +#include <mipi_dsi.h> +#include <panel.h> +#include <asm/gpio.h> +#include <dm/device_compat.h> +#include <linux/delay.h> +#include <power/regulator.h> + +struct hx8394_panel_priv { + struct udevice *reg_vcc; + struct udevice *reg_iovcc; + struct gpio_desc reset; + struct udevice *backlight; +}; + +static const struct display_timing default_timing = { + .pixelclock.typ = 74250000, + .hactive.typ = 720, + .hfront_porch.typ = 40, + .hback_porch.typ = 40, + .hsync_len.typ = 46, + .vactive.typ = 1440, + .vfront_porch.typ = 7, + .vback_porch.typ = 9, + .vsync_len.typ = 7, + .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW, +}; + +#define dsi_dcs_write_seq(device, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_dcs_write_buffer(device, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +static int hx8394_init_sequence(struct udevice *dev) +{ + struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); + struct mipi_dsi_device *device = plat->device; + int ret; + + dsi_dcs_write_seq(device, 0xb9, 0xff, 0x83, 0x94); + dsi_dcs_write_seq(device, 0xb1, 0x48, 0x11, 0x71, 0x09, 0x32, 0x24, + 0x71, 0x31, 0x55, 0x30); + dsi_dcs_write_seq(device, 0xba, 0x63, 0x03, 0x68, 0x6b, 0xb2, 0xc0); + dsi_dcs_write_seq(device, 0xb2, 0x00, 0x80, 0x78, 0x0c, 0x07); + dsi_dcs_write_seq(device, 0xb4, 0x12, 0x63, 0x12, 0x63, 0x12, 0x63, + 0x01, 0x0c, 0x7c, 0x55, 0x00, 0x3f, 0x12, 0x6b, 0x12, + 0x6b, 0x12, 0x6b, 0x01, 0x0c, 0x7c); + dsi_dcs_write_seq(device, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x1c, + 0x00, 0x00, 0x32, 0x10, 0x09, 0x00, 0x09, 0x32, 0x15, + 0xad, 0x05, 0xad, 0x32, 0x00, 0x00, 0x00, 0x00, 0x37, + 0x03, 0x0b, 0x0b, 0x37, 0x00, 0x00, 0x00, 0x0c, 0x40); + dsi_dcs_write_seq(device, 0xd5, 0x19, 0x19, 0x18, 0x18, 0x1b, 0x1b, + 0x1a, 0x1a, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x20, 0x21, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x25, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18); + dsi_dcs_write_seq(device, 0xd6, 0x18, 0x18, 0x19, 0x19, 0x1b, 0x1b, + 0x1a, 0x1a, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x00, 0x25, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x21, 0x20, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18); + dsi_dcs_write_seq(device, 0xe0, 0x00, 0x04, 0x0c, 0x12, 0x14, 0x18, + 0x1a, 0x18, 0x31, 0x3f, 0x4d, 0x4c, 0x54, 0x65, 0x6b, + 0x70, 0x7f, 0x82, 0x7e, 0x8a, 0x99, 0x4a, 0x48, 0x49, + 0x4b, 0x4a, 0x4c, 0x4b, 0x7f, 0x00, 0x04, 0x0c, 0x11, + 0x13, 0x17, 0x1a, 0x18, 0x31, 0x3f, 0x4d, 0x4c, 0x54, + 0x65, 0x6b, 0x70, 0x7f, 0x82, 0x7e, 0x8a, 0x99, 0x4a, + 0x48, 0x49, 0x4b, 0x4a, 0x4c, 0x4b, 0x7f); + dsi_dcs_write_seq(device, 0xcc, 0x0b); + dsi_dcs_write_seq(device, 0xc0, 0x1f, 0x31); + dsi_dcs_write_seq(device, 0xb6, 0x7d, 0x7d); + dsi_dcs_write_seq(device, 0xd4, 0x02); + dsi_dcs_write_seq(device, 0xbd, 0x01); + dsi_dcs_write_seq(device, 0xb1, 0x00); + dsi_dcs_write_seq(device, 0xbd, 0x00); + dsi_dcs_write_seq(device, 0xc6, 0xed); + + ret = mipi_dsi_dcs_exit_sleep_mode(device); + if (ret) + return ret; + + /* Panel is operational 120 msec after reset */ + mdelay(120); + + ret = mipi_dsi_dcs_set_display_on(device); + if (ret) + return ret; + + return 0; +} + +static int hx8394_panel_enable_backlight(struct udevice *dev) +{ + struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); + struct mipi_dsi_device *device = plat->device; + struct hx8394_panel_priv *priv = dev_get_priv(dev); + int ret; + + ret = mipi_dsi_attach(device); + if (ret < 0) { + printf("mipi_dsi_attach failed %d\n", ret); + return ret; + } + + ret = hx8394_init_sequence(dev); + if (ret) { + printf("hx8394_init_sequence failed %d\n", ret); + return ret; + } + + if (priv->backlight) { + ret = backlight_enable(priv->backlight); + if (ret) { + printf("backlight enabled failed %d\n", ret); + return ret; + } + + backlight_set_brightness(priv->backlight, 60); + } + + mdelay(10); + + return 0; +} + +static int hx8394_panel_get_display_timing(struct udevice *dev, + struct display_timing *timings) +{ + memcpy(timings, &default_timing, sizeof(*timings)); + + return 0; +} + +static int hx8394_panel_of_to_plat(struct udevice *dev) +{ + struct hx8394_panel_priv *priv = dev_get_priv(dev); + int ret; + + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { + ret = device_get_supply_regulator(dev, "vcc-supply", + &priv->reg_vcc); + if (ret && ret != -ENOENT) { + dev_err(dev, "Warning: cannot get vcc supply\n"); + return ret; + } + + ret = device_get_supply_regulator(dev, "iovcc-supply", + &priv->reg_iovcc); + if (ret && ret != -ENOENT) { + dev_err(dev, "Warning: cannot get iovcc supply\n"); + return ret; + } + } + + ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, + "backlight", &priv->backlight); + if (ret) + dev_warn(dev, "failed to get backlight\n"); + + ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset, + GPIOD_IS_OUT); + if (ret) { + dev_err(dev, "warning: cannot get reset GPIO (%d)\n", ret); + if (ret != -ENOENT) + return ret; + } + + return 0; +} + +static int hx8394_panel_probe(struct udevice *dev) +{ + struct hx8394_panel_priv *priv = dev_get_priv(dev); + struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); + int ret; + + dm_gpio_set_value(&priv->reset, true); + + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { + dev_dbg(dev, "enable vcc '%s'\n", priv->reg_vcc->name); + ret = regulator_set_enable(priv->reg_vcc, true); + if (ret) + return ret; + + dev_dbg(dev, "enable iovcc '%s'\n", priv->reg_iovcc->name); + ret = regulator_set_enable(priv->reg_iovcc, true); + if (ret) { + regulator_set_enable(priv->reg_vcc, false); + return ret; + } + } + + mdelay(5); + dm_gpio_set_value(&priv->reset, false); + + mdelay(180); + + /* fill characteristics of DSI data link */ + plat->lanes = 4; + plat->format = MIPI_DSI_FMT_RGB888; + plat->mode_flags = MIPI_DSI_MODE_VIDEO | + MIPI_DSI_MODE_VIDEO_BURST; + + return 0; +} + +static const struct panel_ops hx8394_panel_ops = { + .enable_backlight = hx8394_panel_enable_backlight, + .get_display_timing = hx8394_panel_get_display_timing, +}; + +static const struct udevice_id hx8394_panel_ids[] = { + { .compatible = "hannstar,hsd060bhw4" }, + { } +}; + +U_BOOT_DRIVER(hx8394_panel) = { + .name = "hx8394_panel", + .id = UCLASS_PANEL, + .of_match = hx8394_panel_ids, + .ops = &hx8394_panel_ops, + .of_to_plat = hx8394_panel_of_to_plat, + .probe = hx8394_panel_probe, + .plat_auto = sizeof(struct mipi_dsi_panel_plat), + .priv_auto = sizeof(struct hx8394_panel_priv), +}; diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index d7c096923b..46c16a8f44 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -63,7 +63,7 @@ static int set_pwm(struct pwm_backlight_priv *priv) int ret; if (priv->period_ns) { - duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) / + duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) / (priv->max_level - priv->min_level); ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns, duty_cycle); diff --git a/drivers/video/rockchip/dw_mipi_dsi_rockchip.c b/drivers/video/rockchip/dw_mipi_dsi_rockchip.c index ca548a60b7..117c3db21a 100644 --- a/drivers/video/rockchip/dw_mipi_dsi_rockchip.c +++ b/drivers/video/rockchip/dw_mipi_dsi_rockchip.c @@ -18,6 +18,7 @@ #include <panel.h> #include <phy-mipi-dphy.h> #include <reset.h> +#include <syscon.h> #include <video_bridge.h> #include <dm/device_compat.h> #include <dm/lists.h> @@ -30,6 +31,9 @@ #include <dm/device-internal.h> #include <linux/bitops.h> +#include <asm/arch-rockchip/clock.h> +#include <asm/arch-rockchip/hardware.h> + #define USEC_PER_SEC 1000000L /* @@ -197,6 +201,7 @@ struct dw_rockchip_dsi_priv { struct mipi_dsi_device device; void __iomem *base; struct udevice *panel; + void __iomem *grf; /* Optional external dphy */ struct phy phy; @@ -344,7 +349,7 @@ static int dsi_phy_init(void *priv_data) struct dw_rockchip_dsi_priv *dsi = dev_get_priv(dev); int ret, i, vco; - if (&dsi->phy) { + if (dsi->phy.dev) { ret = generic_phy_configure(&dsi->phy, &dsi->phy_opts); if (ret) { dev_err(dsi->dsi_host, @@ -460,7 +465,7 @@ static int dsi_phy_init(void *priv_data) dw_mipi_dsi_phy_write(dsi, HS_TX_DATA_LANE_EXIT_STATE_TIME_CONTROL, BIT(5) | ns2bc(dsi, 100)); - return ret; + return 0; } static void dsi_phy_post_set_mode(void *priv_data, unsigned long mode_flags) @@ -505,7 +510,6 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, struct display_timing *timings, unsigned int _prediv, best_prediv; unsigned long _fbdiv, best_fbdiv; unsigned long min_delta = ULONG_MAX; - unsigned int pllref_clk; bpp = mipi_dsi_pixel_format_to_bpp(format); if (bpp < 0) { @@ -527,7 +531,7 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, struct display_timing *timings, } /* for external phy only the mipi_dphy_config is necessary */ - if (&dsi->phy) { + if (dsi->phy.dev) { phy_mipi_dphy_get_default_config(timings->pixelclock.typ * 10 / 8, bpp, lanes, &dsi->phy_opts); @@ -537,7 +541,7 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, struct display_timing *timings, return 0; } - pllref_clk = clk_get_rate(dsi->ref); + fin = clk_get_rate(dsi->ref); fout = target_mbps * USEC_PER_SEC; /* constraint: 5Mhz <= Fref / N <= 40MHz */ @@ -753,16 +757,13 @@ static int dw_mipi_dsi_rockchip_set_bl(struct udevice *dev, int percent) static void dw_mipi_dsi_rockchip_config(struct dw_rockchip_dsi_priv *dsi) { if (dsi->cdata->lanecfg1_grf_reg) - dsi_write(dsi, dsi->cdata->lanecfg1_grf_reg, - dsi->cdata->lanecfg1); + rk_setreg(dsi->grf + dsi->cdata->lanecfg1_grf_reg, dsi->cdata->lanecfg1); if (dsi->cdata->lanecfg2_grf_reg) - dsi_write(dsi, dsi->cdata->lanecfg2_grf_reg, - dsi->cdata->lanecfg2); + rk_setreg(dsi->grf + dsi->cdata->lanecfg2_grf_reg, dsi->cdata->lanecfg2); if (dsi->cdata->enable_grf_reg) - dsi_write(dsi, dsi->cdata->enable_grf_reg, - dsi->cdata->enable); + rk_setreg(dsi->grf + dsi->cdata->enable_grf_reg, dsi->cdata->enable); } static int dw_mipi_dsi_rockchip_bind(struct udevice *dev) @@ -795,6 +796,8 @@ static int dw_mipi_dsi_rockchip_probe(struct udevice *dev) return -EINVAL; } + priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + i = 0; while (cdata[i].reg) { if (cdata[i].reg == (fdt_addr_t)priv->base) { @@ -815,25 +818,27 @@ static int dw_mipi_dsi_rockchip_probe(struct udevice *dev) * NULL if it's not initialized. */ ret = generic_phy_get_by_name(dev, "dphy", &priv->phy); - if ((ret) && (ret != -ENODEV)) { + if (ret && ret != -ENODATA) { dev_err(dev, "failed to get mipi dphy: %d\n", ret); - return -EINVAL; + return ret; } priv->pclk = devm_clk_get(dev, "pclk"); if (IS_ERR(priv->pclk)) { + ret = PTR_ERR(priv->pclk); dev_err(dev, "peripheral clock get error %d\n", ret); return ret; } /* Get a ref clock only if not using an external phy. */ - if (&priv->phy) { + if (priv->phy.dev) { dev_dbg(dev, "setting priv->ref to NULL\n"); priv->ref = NULL; } else { priv->ref = devm_clk_get(dev, "ref"); - if (ret) { + if (IS_ERR(priv->ref)) { + ret = PTR_ERR(priv->ref); dev_err(dev, "pll reference clock get error %d\n", ret); return ret; } @@ -841,7 +846,8 @@ static int dw_mipi_dsi_rockchip_probe(struct udevice *dev) priv->rst = devm_reset_control_get_by_index(device->dev, 0); if (IS_ERR(priv->rst)) { - dev_err(dev, "missing dsi hardware reset\n"); + ret = PTR_ERR(priv->rst); + dev_err(dev, "missing dsi hardware reset %d\n", ret); return ret; } diff --git a/drivers/video/rockchip/rk_vop.c b/drivers/video/rockchip/rk_vop.c index dab9902fda..c514e2a0e4 100644 --- a/drivers/video/rockchip/rk_vop.c +++ b/drivers/video/rockchip/rk_vop.c @@ -432,7 +432,7 @@ int rk_vop_probe(struct udevice *dev) ret = reset_assert(&ahb_rst); if (ret) { dev_err(dev, "failed to assert ahb reset (ret=%d)\n", ret); - return ret; + return ret; } udelay(20); diff --git a/include/efi_config.h b/include/efi_config.h index 01ce9b2b06..d7c1601137 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -105,11 +105,6 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, void (*item_data_print)(void *), char *(*item_choice)(void *)); efi_status_t eficonfig_process_select_file(void *data); -efi_status_t eficonfig_get_unused_bootoption(u16 *buf, - efi_uintn_t buf_size, u32 *index); -efi_status_t eficonfig_append_bootorder(u16 index); -efi_status_t eficonfig_generate_media_device_boot_option(void); - efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, char *title, eficonfig_entry_func func, void *data); diff --git a/include/efi_loader.h b/include/efi_loader.h index 11e08a804f..604fd765f7 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -517,6 +517,17 @@ struct efi_register_notify_event { int efi_init_early(void); /* Initialize efi execution environment */ efi_status_t efi_init_obj_list(void); +/* Append new boot option in BootOrder variable */ +efi_status_t efi_bootmgr_append_bootorder(u16 index); +/* Get unused "Boot####" index */ +efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf, + efi_uintn_t buf_size, u32 *index); +/* Generate the media device boot option */ +efi_status_t efi_bootmgr_update_media_device_boot_option(void); +/* Delete selected boot option */ +efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index); +/* search the boot option index in BootOrder */ +bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index); /* Set up console modes */ void efi_setup_console_size(void); /* Install device tree */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 7ac5f89f76..a40762c74c 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -344,3 +344,388 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) error: return ret; } + +/** + * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media + * + * @opt: pointer to the media boot option structure + * @volume_handles: pointer to the efi handles + * @count: number of efi handle + * Return: status code + */ +static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boot_option *opt, + efi_handle_t *volume_handles, + efi_status_t count) +{ + u32 i; + struct efi_handler *handler; + efi_status_t ret = EFI_SUCCESS; + + for (i = 0; i < count; i++) { + u16 *p; + u16 dev_name[BOOTMENU_DEVICE_NAME_MAX]; + char *optional_data; + struct efi_load_option lo; + char buf[BOOTMENU_DEVICE_NAME_MAX]; + struct efi_device_path *device_path; + struct efi_device_path *short_dp; + + ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); + if (ret != EFI_SUCCESS) + continue; + ret = efi_protocol_open(handler, (void **)&device_path, + efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + continue; + + ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); + if (ret != EFI_SUCCESS) + continue; + + p = dev_name; + utf8_utf16_strncpy(&p, buf, strlen(buf)); + + /* prefer to short form device path */ + short_dp = efi_dp_shorten(device_path); + if (short_dp) + device_path = short_dp; + + lo.label = dev_name; + lo.attributes = LOAD_OPTION_ACTIVE; + lo.file_path = device_path; + lo.file_path_length = efi_dp_size(device_path) + sizeof(END); + /* + * Set the dedicated guid to optional_data, it is used to identify + * the boot option that automatically generated by the bootmenu. + * efi_serialize_load_option() expects optional_data is null-terminated + * utf8 string, so set the "1234567" string to allocate enough space + * to store guid, instead of realloc the load_option. + */ + lo.optional_data = "1234567"; + opt[i].size = efi_serialize_load_option(&lo, (u8 **)&opt[i].lo); + if (!opt[i].size) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + /* set the guid */ + optional_data = (char *)opt[i].lo + (opt[i].size - u16_strsize(u"1234567")); + memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); + } + +out: + return ret; +} + +/** + * efi_bootmgr_delete_invalid_boot_option() - delete non-existing boot option + * + * @opt: pointer to the media boot option structure + * @count: number of media boot option structure + * Return: status code + */ +static efi_status_t efi_bootmgr_delete_invalid_boot_option(struct eficonfig_media_boot_option *opt, + efi_status_t count) +{ + efi_uintn_t size; + void *load_option; + u32 i, list_size = 0; + struct efi_load_option lo; + u16 *var_name16 = NULL; + u16 varname[] = u"Boot####"; + efi_status_t ret = EFI_SUCCESS; + u16 *delete_index_list = NULL, *p; + efi_uintn_t buf_size; + + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return EFI_OUT_OF_RESOURCES; + + var_name16[0] = 0; + for (;;) { + int index; + efi_guid_t guid; + efi_uintn_t tmp; + + ret = efi_next_variable_name(&buf_size, &var_name16, &guid); + if (ret == EFI_NOT_FOUND) { + /* + * EFI_NOT_FOUND indicates we retrieved all EFI variables. + * This should be treated as success. + */ + ret = EFI_SUCCESS; + break; + } + + if (ret != EFI_SUCCESS) + goto out; + + if (!efi_varname_is_load_option(var_name16, &index)) + continue; + + efi_create_indexed_name(varname, sizeof(varname), "Boot", index); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + tmp = size; + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) + goto next; + + if (size >= sizeof(efi_guid_bootmenu_auto_generated) && + !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + for (i = 0; i < count; i++) { + if (opt[i].size == tmp && + memcmp(opt[i].lo, load_option, tmp) == 0) { + opt[i].exist = true; + break; + } + } + + /* + * The entire list of variables must be retrieved by + * efi_get_next_variable_name_int() before deleting the invalid + * boot option, just save the index here. + */ + if (i == count) { + p = realloc(delete_index_list, sizeof(u32) * + (list_size + 1)); + if (!p) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + delete_index_list = p; + delete_index_list[list_size++] = index; + } + } +next: + free(load_option); + } + + /* delete all invalid boot options */ + for (i = 0; i < list_size; i++) { + ret = efi_bootmgr_delete_boot_option(delete_index_list[i]); + if (ret != EFI_SUCCESS) + goto out; + } + +out: + free(var_name16); + free(delete_index_list); + + return ret; +} + +/** + * efi_bootmgr_get_unused_bootoption() - get unused "Boot####" index + * + * @buf: pointer to the buffer to store boot option variable name + * @buf_size: buffer size + * @index: pointer to store the index in the BootOrder variable + * Return: status code + */ +efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size, + unsigned int *index) +{ + u32 i; + efi_status_t ret; + efi_uintn_t size; + + if (buf_size < u16_strsize(u"Boot####")) + return EFI_BUFFER_TOO_SMALL; + + for (i = 0; i <= 0xFFFF; i++) { + size = 0; + efi_create_indexed_name(buf, buf_size, "Boot", i); + ret = efi_get_variable_int(buf, &efi_global_variable_guid, + NULL, &size, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) + continue; + else + break; + } + + if (i > 0xFFFF) + return EFI_OUT_OF_RESOURCES; + + *index = i; + + return EFI_SUCCESS; +} + +/** + * efi_bootmgr_append_bootorder() - append new boot option in BootOrder variable + * + * @index: "Boot####" index to append to BootOrder variable + * Return: status code + */ +efi_status_t efi_bootmgr_append_bootorder(u16 index) +{ + u16 *bootorder; + efi_status_t ret; + u16 *new_bootorder = NULL; + efi_uintn_t last, size, new_size; + + /* append new boot option */ + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + last = size / sizeof(u16); + new_size = size + sizeof(u16); + new_bootorder = calloc(1, new_size); + if (!new_bootorder) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + memcpy(new_bootorder, bootorder, size); + new_bootorder[last] = index; + + ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + new_size, new_bootorder, false); + if (ret != EFI_SUCCESS) + goto out; + +out: + free(bootorder); + free(new_bootorder); + + return ret; +} + +/** + * efi_bootmgr_delete_boot_option() - delete selected boot option + * + * @boot_index: boot option index to delete + * Return: status code + */ +efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index) +{ + u16 *bootorder; + u16 varname[9]; + efi_status_t ret; + unsigned int index; + efi_uintn_t num, size; + + efi_create_indexed_name(varname, sizeof(varname), + "Boot", boot_index); + ret = efi_set_variable_int(varname, &efi_global_variable_guid, + 0, 0, NULL, false); + if (ret != EFI_SUCCESS) { + log_err("delete boot option(%ls) failed\n", varname); + return ret; + } + + /* update BootOrder if necessary */ + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) + return EFI_SUCCESS; + + num = size / sizeof(u16); + if (!efi_search_bootorder(bootorder, num, boot_index, &index)) + return EFI_SUCCESS; + + memmove(&bootorder[index], &bootorder[index + 1], + (num - index - 1) * sizeof(u16)); + size -= sizeof(u16); + ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + size, bootorder, false); + + return ret; +} + +/** + * efi_bootmgr_update_media_device_boot_option() - generate the media device boot option + * + * This function enumerates all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL + * and generate the bootmenu entries. + * This function also provide the BOOT#### variable maintenance for + * the media device entries. + * - Automatically create the BOOT#### variable for the newly detected device, + * this BOOT#### variable is distinguished by the special GUID + * stored in the EFI_LOAD_OPTION.optional_data + * - If the device is not attached to the system, the associated BOOT#### variable + * is automatically deleted. + * + * Return: status code + */ +efi_status_t efi_bootmgr_update_media_device_boot_option(void) +{ + u32 i; + efi_status_t ret; + efi_uintn_t count; + efi_handle_t *volume_handles = NULL; + struct eficonfig_media_boot_option *opt = NULL; + + ret = efi_locate_handle_buffer_int(BY_PROTOCOL, + &efi_simple_file_system_protocol_guid, + NULL, &count, + (efi_handle_t **)&volume_handles); + if (ret != EFI_SUCCESS) + goto out; + + opt = calloc(count, sizeof(struct eficonfig_media_boot_option)); + if (!opt) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */ + ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, count); + if (ret != EFI_SUCCESS) + goto out; + + /* + * System hardware configuration may vary depending on the user setup. + * The boot option is automatically added by the bootmenu. + * If the device is not attached to the system, the boot option needs + * to be deleted. + */ + ret = efi_bootmgr_delete_invalid_boot_option(opt, count); + if (ret != EFI_SUCCESS) + goto out; + + /* add non-existent boot option */ + for (i = 0; i < count; i++) { + u32 boot_index; + u16 var_name[9]; + + if (!opt[i].exist) { + ret = efi_bootmgr_get_unused_bootoption(var_name, sizeof(var_name), + &boot_index); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_set_variable_int(var_name, &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + opt[i].size, opt[i].lo, false); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_bootmgr_append_bootorder(boot_index); + if (ret != EFI_SUCCESS) { + efi_set_variable_int(var_name, &efi_global_variable_guid, + 0, 0, NULL, false); + goto out; + } + } + } + +out: + if (opt) { + for (i = 0; i < count; i++) + free(opt[i].lo); + } + free(opt); + efi_free_pool(volume_handles); + + if (ret == EFI_NOT_FOUND) + return EFI_SUCCESS; + return ret; +} diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d5065f296a..2ca7359f3e 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -97,6 +97,12 @@ static efi_status_t EFIAPI efi_disconnect_controller( efi_handle_t driver_image_handle, efi_handle_t child_handle); +static +efi_status_t EFIAPI efi_connect_controller(efi_handle_t controller_handle, + efi_handle_t *driver_image_handle, + struct efi_device_path *remain_device_path, + bool recursive); + /* Called on every callback entry */ int __efi_entry_check(void) { @@ -1298,7 +1304,7 @@ static efi_status_t efi_disconnect_all_drivers const efi_guid_t *protocol, efi_handle_t child_handle) { - efi_uintn_t number_of_drivers; + efi_uintn_t number_of_drivers, tmp; efi_handle_t *driver_handle_buffer; efi_status_t r, ret; @@ -1308,15 +1314,30 @@ static efi_status_t efi_disconnect_all_drivers return ret; if (!number_of_drivers) return EFI_SUCCESS; - ret = EFI_NOT_FOUND; + + tmp = number_of_drivers; while (number_of_drivers) { - r = EFI_CALL(efi_disconnect_controller( + ret = EFI_CALL(efi_disconnect_controller( handle, driver_handle_buffer[--number_of_drivers], child_handle)); - if (r == EFI_SUCCESS) - ret = r; + if (ret != EFI_SUCCESS) + goto reconnect; } + + free(driver_handle_buffer); + return ret; + +reconnect: + /* Reconnect all disconnected drivers */ + for (; number_of_drivers < tmp; number_of_drivers++) { + r = EFI_CALL(efi_connect_controller(handle, + &driver_handle_buffer[number_of_drivers], + NULL, true)); + if (r != EFI_SUCCESS) + EFI_PRINT("Failed to reconnect controller\n"); + } + free(driver_handle_buffer); return ret; } @@ -1352,18 +1373,26 @@ static efi_status_t efi_uninstall_protocol r = efi_search_protocol(handle, protocol, &handler); if (r != EFI_SUCCESS) goto out; + if (handler->protocol_interface != protocol_interface) + return EFI_NOT_FOUND; /* Disconnect controllers */ - efi_disconnect_all_drivers(efiobj, protocol, NULL); + r = efi_disconnect_all_drivers(efiobj, protocol, NULL); + if (r != EFI_SUCCESS) { + r = EFI_ACCESS_DENIED; + goto out; + } /* Close protocol */ list_for_each_entry_safe(item, pos, &handler->open_infos, link) { if (item->info.attributes == EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_GET_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_TEST_PROTOCOL) - list_del(&item->link); + efi_delete_open_info(item); } + /* if agents didn't close the protocols properly */ if (!list_empty(&handler->open_infos)) { r = EFI_ACCESS_DENIED; + EFI_CALL(efi_connect_controller(handle, NULL, NULL, true)); goto out; } r = efi_remove_protocol(handle, protocol, protocol_interface); diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 1f4ab2b419..cdfd16ea77 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -257,3 +257,28 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, efi_guid_t *gu return ret; } + +/** + * efi_search_bootorder() - search the boot option index in BootOrder + * + * @bootorder: pointer to the BootOrder variable + * @num: number of BootOrder entry + * @target: target boot option index to search + * @index: pointer to store the index of BootOrder variable + * Return: true if exists, false otherwise + */ +bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index) +{ + u32 i; + + for (i = 0; i < num; i++) { + if (target == bootorder[i]) { + if (index) + *index = i; + + return true; + } + } + + return false; +} diff --git a/lib/efi_selftest/efi_selftest_controllers.c b/lib/efi_selftest/efi_selftest_controllers.c index 63e674bedc..02f19574f8 100644 --- a/lib/efi_selftest/efi_selftest_controllers.c +++ b/lib/efi_selftest/efi_selftest_controllers.c @@ -28,6 +28,7 @@ static efi_guid_t guid_child_controller = static efi_handle_t handle_controller; static efi_handle_t handle_child_controller[NUMBER_OF_CHILD_CONTROLLERS]; static efi_handle_t handle_driver; +static bool allow_removal; /* * Count child controllers @@ -85,8 +86,8 @@ static efi_status_t EFIAPI supported( controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER); switch (ret) { case EFI_ACCESS_DENIED: - case EFI_ALREADY_STARTED: return ret; + case EFI_ALREADY_STARTED: case EFI_SUCCESS: break; default: @@ -124,8 +125,8 @@ static efi_status_t EFIAPI start( controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER); switch (ret) { case EFI_ACCESS_DENIED: - case EFI_ALREADY_STARTED: return ret; + case EFI_ALREADY_STARTED: case EFI_SUCCESS: break; default: @@ -238,6 +239,9 @@ static efi_status_t EFIAPI stop( if (ret != EFI_SUCCESS) efi_st_error("Cannot free buffer\n"); + if (!allow_removal) + return EFI_DEVICE_ERROR; + /* Detach driver from controller */ ret = boottime->close_protocol( controller_handle, &guid_controller, @@ -342,6 +346,7 @@ static int execute(void) return EFI_ST_FAILURE; } /* Destroy remaining child controllers and disconnect controller */ + allow_removal = true; ret = boottime->disconnect_controller(handle_controller, NULL, NULL); if (ret != EFI_SUCCESS) { efi_st_error("Failed to disconnect controller\n"); @@ -393,7 +398,40 @@ static int execute(void) efi_st_error("Number of children %u != %u\n", (unsigned int)count, NUMBER_OF_CHILD_CONTROLLERS); } - /* Uninstall controller protocol */ + + allow_removal = false; + /* Try to uninstall controller protocol using the wrong interface */ + ret = boottime->uninstall_protocol_interface(handle_controller, + &guid_controller, + &interface1); + if (ret != EFI_NOT_FOUND) { + efi_st_error("Interface not checked when uninstalling protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * Uninstall a protocol while Disconnect controller won't + * allow it. + */ + ret = boottime->uninstall_protocol_interface(handle_controller, + &guid_controller, + &interface2); + if (ret != EFI_ACCESS_DENIED) { + efi_st_error("Uninstall protocol interface failed\n"); + return EFI_ST_FAILURE; + } + /* + * Check number of child controllers and make sure children have + * been reconnected + */ + ret = count_child_controllers(handle_controller, &guid_controller, + &count); + if (ret != EFI_SUCCESS || count != NUMBER_OF_CHILD_CONTROLLERS) { + efi_st_error("Number of children %u != %u\n", + (unsigned int)count, NUMBER_OF_CHILD_CONTROLLERS); + } + + allow_removal = true; ret = boottime->uninstall_protocol_interface(handle_controller, &guid_controller, &interface2); |