From patchwork Tue Oct 10 12:22:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 115401 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3690755qgn; Tue, 10 Oct 2017 05:24:51 -0700 (PDT) X-Received: by 10.80.149.169 with SMTP id w38mr5718728eda.191.1507638290931; Tue, 10 Oct 2017 05:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507638290; cv=none; d=google.com; s=arc-20160816; b=g1vqn0N/I7o6ZPCxq5FPGzwRq4LjPew2nPzNw3zhzcc6QpWZItXusnEjf9QhLO7NQM Km+j8EJryx4t+3vrhzE4CF8HBQkxG2ACLD21jhXqf+D5KodTFuFjSJUPGfSyUuUGJyuL mMhe9PIZREzqvwT2MjPZ551sOSG8luWVFyguyjAZI3OFJ/27iSkWm+T10nBNhURTvZcN GTiBwzWy6GW3kt1eMVKDmhWUKadED6PNXGcChTYZpufJi4uxSEIrzzqS5D56YoM9BOM4 mBYuTd/CCzDIgZabaLw+hWA2M0xu1sj8Pin0Zz9hl+aspELhzObVm7Ib3dHSOwI1EaT+ /bUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=Yns3fRu5Qm/Dr/pttzwd1pbsYe2/471Svwz9fWrdO1A=; b=EvP/TIdAhdp3Z5l1LbFARhCbJKxIEYO3xUW4NMulAPUTmU/d2IwRKpviuOzk8KaulU LvTwnMZCdNyaZGwQ022xR5iY3xym6e7uoXjoMKjCLP8nVs9FC2sEWqC5z9PZo3oFjkW2 O2PwfAAoM/RwjbS8L9UpdjKeeEnuy133uFGLnsKObloAv8cc4Ga2ewaiqHNr8rgmRDcT Y99KguHpoRiTIGt3rilizVCS9MdxQZMwe+0WObDQuI8BPLwNOJtgwfZsuMSbvDYCMh6e IGpJTfgjhmWjH5uHGPw7gU45JJPVZEhodJBv160sHrnKzu7UZYRlRkZKug3J8FrC4IX5 ybDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Ebp9VAsb; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id x5si2645775edj.433.2017.10.10.05.24.50; Tue, 10 Oct 2017 05:24:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Ebp9VAsb; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: by lists.denx.de (Postfix, from userid 105) id 7E657C21C93; Tue, 10 Oct 2017 12:24:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 78989C21DBA; Tue, 10 Oct 2017 12:23:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6CE9AC21D84; Tue, 10 Oct 2017 12:23:33 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by lists.denx.de (Postfix) with ESMTPS id 473ABC21DA3 for ; Tue, 10 Oct 2017 12:23:30 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id z50so45456252qtj.4 for ; Tue, 10 Oct 2017 05:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xTIxuatjBe6vhbNlTtMaBmoRDpN/KRWlVMVixz5FDN0=; b=Ebp9VAsbn92g46Cngx7valPogx4gqT7pUmZ8Fr+BckpsQOlvUDchrNzsb1qTJLP9eL SpEKOO/8+48Mjo5pb8MVy7mAZUsxwaIn2IeLuJomeqvJUIOurHjvXW9uCwUTstikGBdj dpQm0Ha6MoKzfCyOn13MDc0tX/yxRe85rxaHI3RPXgsuc8tA/CtoTm6Ss1lFXiMqZEde VHPug9Fs2p+3v/7FFk8ha5OzCtDoIOunNRD79T2Fog2PfY+6soUaNrBCZYNsW/7m5kRT o9oXu+qHba2PE66NGVwh4GJ+kFi1RbtE2MhDQV03NqO7jfA0UkzrWrMarZsV1VKWV8bl hwig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xTIxuatjBe6vhbNlTtMaBmoRDpN/KRWlVMVixz5FDN0=; b=UyKq6MGIUXFChogzG0fTpRKhF0AqffZXxpZAukqX4FvMn+fAQyKkHwXd1l4mVNsokj XU6S+mdC0VucZE/54i83DMEKlHQDJN24ju8iyO1cfgTsEbgOJs+ipjRlRE+QSwttsfNj ferY5h9K+rhTyLwTE7ZhKhacCvcpJMUODVwQ/NSBDuvClPJUGHKL28w4P4tMeXyNLjf7 u0IrejvpqNq6YqbgUHH8QkNERrcXmXNq3OONgRs0st/f4FgKJXOMC9qPvanlYeEngwgn fHlp3B2G/NJfMXsRATn3C5xVZs/7noqrv2rn6Xdts2OxE5oIozconf5umDONmvBokU5f 5yLQ== X-Gm-Message-State: AMCzsaVe6vh2d58VbPZY4xvx/DkUUAX4FdSNcg6rcEDkol5MTrvS0rYl a43V3zc+V6hnByBrfim7bZ8hk9zT X-Google-Smtp-Source: AOwi7QCu3VGqRbpapBcwCI1EfTBZgNREWptBtcISEorTyV3+aJZk6/LAc9QgfD2pbqJmEZOWnFOyWg== X-Received: by 10.237.37.76 with SMTP id w12mr13648889qtc.201.1507638208910; Tue, 10 Oct 2017 05:23:28 -0700 (PDT) Received: from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id v185sm6201878qkd.44.2017.10.10.05.23.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Oct 2017 05:23:27 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Tue, 10 Oct 2017 08:22:59 -0400 Message-Id: <20171010122309.25313-4-robdclark@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010122309.25313-1-robdclark@gmail.com> References: <20171010122309.25313-1-robdclark@gmail.com> Cc: Heinrich Schuchardt , Leif Lindholm Subject: [U-Boot] [PATCH 03/11] efi_loader: Initial EFI_UNICODE_COLLATION_PROTOCOL X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Leif Lindholm Not complete, but enough for Shell.efi and SCT.efi. Initial skeleton written by Leif, and then implementation by myself. Cc: Leif Lindholm Signed-off-by: Rob Clark --- include/efi_api.h | 41 ++++++++++ include/efi_loader.h | 3 + lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_boottime.c | 6 ++ lib/efi_loader/efi_unicode.c | 170 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 lib/efi_loader/efi_unicode.c diff --git a/include/efi_api.h b/include/efi_api.h index 164147dc87..38dd1240c1 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -797,6 +797,47 @@ struct efi_hii_string_protocol { efi_uintn_t *secondary_languages_size); }; +/* + * Both UNICODE_COLLATION protocols seem to be the same thing, but + * advertised with two different GUID's because, why not? + */ + +#define EFI_UNICODE_COLLATION_PROTOCOL_GUID \ + EFI_GUID(0x1d85cd7f, 0xf43d, 0x11d2, \ + 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) + +#define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \ + EFI_GUID(0xa4c751fc, 0x23ae, 0x4c3e, \ + 0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49) + +struct efi_unicode_collation_protocol { + efi_intn_t (EFIAPI *stri_coll)( + struct efi_unicode_collation_protocol *this, + efi_string_t s1, + efi_string_t s2); + bool (EFIAPI *metai_match)( + struct efi_unicode_collation_protocol *this, + efi_string_t string, + efi_string_t pattern); + void (EFIAPI *str_lwr)( + struct efi_unicode_collation_protocol *this, + efi_string_t string); + void (EFIAPI *str_upr)( + struct efi_unicode_collation_protocol *this, + efi_string_t string); + void (EFIAPI *fat_to_str)( + struct efi_unicode_collation_protocol *this, + efi_uintn_t fat_size, + uint8_t *fat, + efi_string_t string); + bool (EFIAPI *str_to_fat)( + struct efi_unicode_collation_protocol *this, + efi_string_t string, + efi_uintn_t fat_size, + uint8_t *fat); + uint8_t *supported_languages; +}; + #define EFI_GOP_GUID \ EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \ 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a) diff --git a/include/efi_loader.h b/include/efi_loader.h index 591bf07e7a..af6812b2b4 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -83,6 +83,7 @@ extern const struct efi_device_path_utilities_protocol efi_device_path_utilities extern const struct efi_hii_config_routing_protocol efi_hii_config_routing; extern const struct efi_hii_database_protocol efi_hii_database; extern const struct efi_hii_string_protocol efi_hii_string; +extern const struct efi_unicode_collation_protocol efi_unicode_collation; uint16_t *efi_dp_str(struct efi_device_path *dp); @@ -97,6 +98,8 @@ extern const efi_guid_t efi_guid_device_path_utilities_protocol; extern const efi_guid_t efi_guid_hii_config_routing_protocol; extern const efi_guid_t efi_guid_hii_database_protocol; extern const efi_guid_t efi_guid_hii_string_protocol; +extern const efi_guid_t efi_guid_unicode_collation_protocol; +extern const efi_guid_t efi_guid_unicode_collation_protocol2; extern unsigned int __efi_runtime_start, __efi_runtime_stop; extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop; diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 725e0cba85..7ea96a4f1c 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -17,7 +17,7 @@ endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o obj-y += efi_memory.o efi_device_path_to_text.o efi_device_path.o -obj-y += efi_device_path_utilities.o efi_hii.o +obj-y += efi_device_path_utilities.o efi_hii.o efi_unicode.o obj-y += efi_file.o efi_variable.o efi_bootmgr.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_DM_VIDEO) += efi_gop.o diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index c179afc25a..b568f3f162 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1166,6 +1166,12 @@ void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *ob obj->protocols[7].guid = &efi_guid_hii_config_routing_protocol; obj->protocols[7].protocol_interface = (void *)&efi_hii_config_routing; + obj->protocols[8].guid = &efi_guid_unicode_collation_protocol; + obj->protocols[8].protocol_interface = (void *)&efi_unicode_collation; + + obj->protocols[9].guid = &efi_guid_unicode_collation_protocol2; + obj->protocols[9].protocol_interface = (void *)&efi_unicode_collation; + info->file_path = file_path; info->device_handle = efi_dp_find_obj(device_path, NULL); diff --git a/lib/efi_loader/efi_unicode.c b/lib/efi_loader/efi_unicode.c new file mode 100644 index 0000000000..2c6302df25 --- /dev/null +++ b/lib/efi_loader/efi_unicode.c @@ -0,0 +1,170 @@ +/* +* EFI Unicode interface + * + * Copyright (c) 2017 Leif Lindholm + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +const efi_guid_t efi_guid_unicode_collation_protocol = + EFI_UNICODE_COLLATION_PROTOCOL_GUID; + +const efi_guid_t efi_guid_unicode_collation_protocol2 = + EFI_UNICODE_COLLATION_PROTOCOL2_GUID; + +static int matchn(efi_string_t s1, unsigned n1, efi_string_t s2, unsigned n2) +{ + char u1[MAX_UTF8_PER_UTF16 * n1 + 1]; + char u2[MAX_UTF8_PER_UTF16 * n2 + 1]; + + *utf16_to_utf8((u8 *)u1, s1, n1) = '\0'; + *utf16_to_utf8((u8 *)u2, s2, n2) = '\0'; + + return strcasecmp(u1, u2); +} + +static efi_intn_t EFIAPI stri_coll(struct efi_unicode_collation_protocol *this, + efi_string_t s1, + efi_string_t s2) +{ + EFI_ENTRY("%p, \"%ls\", \"%ls\"", this, s1, s2); + + unsigned n1 = utf16_strlen(s1); + unsigned n2 = utf16_strlen(s2); + + return EFI_EXIT(matchn(s1, n1, s2, n2)); +} + +static bool match(efi_string_t string, efi_string_t pattern) +{ + while (true) { + uint16_t p = *pattern++; + bool matches = false; + + if (p == '\0' || *string == '\0') { + /* + * End of pattern or string, succeed if + * end of both: + */ + return *string == p; + } + + switch (p) { + case '*': + /* Match zero or more chars: */ + while (*string != '\0') { + if (match(string, pattern)) + return true; + string++; + } + return match(string, pattern); + case '?': + /* Match any one char: */ + string++; + break; + case '[': + /* Match char set, either [abc] or [a-c]: */ + + if (pattern[0] == '\0' || pattern[0] == ']') { + /* invalid pattern */ + return false; + } + + if (pattern[1] == '-') { + uint16_t lo, hi, c; + + /* range: [a-c] */ + lo = pattern[0]; + hi = pattern[2]; + + if (hi == '\0' || hi == ']' || pattern[3] != ']') { + /* invalid pattern */ + return false; + } + + c = tolower(*string); + lo = tolower(lo); + hi = tolower(hi); + + if (lo <= c && c <= hi) + matches = true; + + pattern += 4; + } else { + /* set: [abc] */ + while ((p = *pattern++) && p != ']') + if (matchn(string, 1, &p, 1)) + matches = true; + } + + if (!matches) + return false; + + string++; + break; + default: + if (matchn(string, 1, &p, 1)) + return false; + string++; + break; + } + } +} + +static bool EFIAPI metai_match(struct efi_unicode_collation_protocol *this, + efi_string_t string, + efi_string_t pattern) +{ + EFI_ENTRY("%p, \"%ls\", \"%ls\"", this, string, pattern); + return EFI_EXIT(match(string, pattern)); +} + +static void EFIAPI str_lwr(struct efi_unicode_collation_protocol *this, + efi_string_t string) +{ + EFI_ENTRY("%p, \"%ls\"", this, string); + EFI_EXIT(EFI_SUCCESS); + return; +} + +static void EFIAPI str_upr(struct efi_unicode_collation_protocol *this, + efi_string_t string) +{ + EFI_ENTRY("%p, \"%ls\"", this, string); + EFI_EXIT(EFI_SUCCESS); + return; +} + +static void EFIAPI fat_to_str(struct efi_unicode_collation_protocol *this, + efi_uintn_t fat_size, + uint8_t *fat, + efi_string_t string) +{ + EFI_ENTRY("%p, %zu, \"%s\", %p", this, fat_size, fat, string); + EFI_EXIT(EFI_SUCCESS); + return; +} + +static bool EFIAPI str_to_fat(struct efi_unicode_collation_protocol *this, + efi_string_t string, + efi_uintn_t fat_size, + uint8_t *fat) +{ + EFI_ENTRY("%p, \"%ls\", %zu, %p", this, string, fat_size, fat); + return EFI_EXIT(false); +} + +const struct efi_unicode_collation_protocol efi_unicode_collation = { + .stri_coll = stri_coll, + .metai_match = metai_match, + .str_lwr = str_lwr, + .str_upr = str_upr, + .fat_to_str = fat_to_str, + .str_to_fat = str_to_fat, + .supported_languages = (uint8_t *)"eng", +};