From patchwork Fri Nov 13 04:14:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 324264 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp899216ils; Thu, 12 Nov 2020 20:17:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxxZzKlunxXUQtuZ2pG5ush5GCtWkdZF/GzSShgjf1MBnJ/wOxwqLSYlv4XiHf0ahfDCTW X-Received: by 2002:a17:906:c298:: with SMTP id r24mr223609ejz.76.1605241048191; Thu, 12 Nov 2020 20:17:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605241048; cv=none; d=google.com; s=arc-20160816; b=UDtNicy3XZXQQ1hhN765CR/LsTpYLMIp/BqICjiPz6kghIOZGLnCVVoh6bgB0wYg+c vZzr5+7QWjQRRaUlscajhXccGh/NLZgzopvRLFbf3Pf2zfKCukT8ElAXK/XC7hq7cy82 3Xpt+WGKohCJkYM6hVnlFm8m3NVQy0e1r22NHCSluoWAfm9N/+UglkXIF9BybUePKDna pMZAQ2pSIZ5c8aBLxinHnFUPZu5T4OosmcvULZFcJZ7nRqkS/FA6AGn+n60goQ2vBsil vA5DVTRdNerVRLXQ3Y1yeEUypil4dUhvHR5Ue1HQLv7LMNOxA1JfOapbSKyigC/ur28X 29kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=k1MOOh9fvKyMbUJZgil8xeKYBwBI/La3SSdm4UwBNz71euE0vXvJoGeaEv4X9KUtoU cqC64pL6icHQLT3QeIr3kydwoM2ZYN7JkuvMu/ARm0LopgJzQZcIUEXHa7elXbm7sf7G /BHTjrhMaE+x+RqMTnClMcpZW3NLJOIReeL/UUp656U69JGp2ndz/bLLaoLzQqqKa1gK GZ7SBlujh9XZJgzKSTkS0JoQystl86+HYkTAVSLF+p4L8qjodwdSe5O9NGSfJJKBx7Li +CTtwV+LyA2avU3ZdjlooAC/C+txDaO+O7shI5FszP5Sm1sXZnUunAtTRlVpG+/g9T4D glaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TO0aMuV5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id f19si5720869edr.593.2020.11.12.20.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:17:28 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TO0aMuV5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3FB282585; Fri, 13 Nov 2020 05:16:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TO0aMuV5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4EFF982569; Fri, 13 Nov 2020 05:16:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0BB1D8000F for ; Fri, 13 Nov 2020 05:15:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x444.google.com with SMTP id y7so6502534pfq.11 for ; Thu, 12 Nov 2020 20:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=TO0aMuV5V4Sb0GUvziaI2Ol7bEmUMJ4K5jzktd+C5qaieXa+kudccUZboYOUNm0dN3 2dAXBaNHOZZRw+oVG2FOJuC8+HO9OKhtncpgnq3Mt+sOtAibjhJLD4BFcFTd6M/1wNdb ejgGM/IEouDimVtQGhXyGT2h5QerJsZiU3N4b68OMGS+R7HoAuRzy3b1iNcX4P83HDyE Itq/ezCW9z6J6hbJvZINQwJsiFXpxigH9fZxYd8aRba+XkDYCYw3/nJuo58g1UEPIhLL fdWEs2gYI3FViSDBdzx2f0KwG2I4n0ktuEch+ey5GGtrRq5YsgX7mWMyX8lUDzu9OCn2 vFGg== 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:mime-version:content-transfer-encoding; bh=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=GZIw7McuBPPbdjsdNOI0SZvIMJJlZVOYTXEOZ4kiTvsCBQ/c/WNkkNoLEXLl0UpKgw 6sKkdnOY73Y+pdJUPOifGGUNLBxpthnmaHUkHQB5VI4cXSUOI8NoBaG6BHasmV9HmNMB DQgQBG/I9ls/2GoO6IydfC10CNcX0kpPCuraGlZAGZ0RV8htEfNHuCP79+P5fEofQ/LT tbI8T1O3QJYctFX+T95npg43WsI/4XEzpvV73YbyzsKy+W7VhM7Et2a+VS6k7z8eNdNk 5A5mmHfx5UC/OYGhZumUD8J6NFxQ3GFd+SGI50TYCM4LeaPcq8zNHp6QN3KiZpzs6Qcj dKZA== X-Gm-Message-State: AOAM531DsY1/0Y1Ide8JESTxZ8uYeHW5XoUmhzjdCX1rnlc/IsvNYboz I2xEaoe8K5grStGY31H5YXHspQ== X-Received: by 2002:a62:6304:0:b029:164:38fe:771e with SMTP id x4-20020a6263040000b029016438fe771emr379610pfb.1.1605240948323; Thu, 12 Nov 2020 20:15:48 -0800 (PST) Received: from localhost.localdomain (p784a5642.tkyea130.ap.so-net.ne.jp. [120.74.86.66]) by smtp.gmail.com with ESMTPSA id s10sm4588340pjn.35.2020.11.12.20.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:15:47 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v8 06/18] efi_loader: add efi_create_indexed_name() Date: Fri, 13 Nov 2020 13:14:59 +0900 Message-Id: <20201113041511.48207-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201113041511.48207-1-takahiro.akashi@linaro.org> References: <20201113041511.48207-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean This function will be used from several places in UEFI subsystem to generate some specific form of utf-16 variable name. For example, L"Capsule0001" Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_setup.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) -- 2.28.0 diff --git a/include/efi_loader.h b/include/efi_loader.h index 7eea5566fdc9..6865a4847d53 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -804,6 +804,9 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp, /* runtime implementation of memcpy() */ void efi_memcpy_runtime(void *dest, const void *src, size_t n); +/* commonly used helper function */ +u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index); + #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 45226c5c1a53..6346eda771d0 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -235,3 +236,32 @@ out: efi_obj_list_initialized = ret; return ret; } + +/** + * efi_create_indexed_name - create a string name with an index + * @buffer: Buffer + * @name: Name string + * @index: Index + * + * Create a utf-16 string with @name, appending @index. + * For example, L"Capsule0001" + * This function is expected to be called only from several places + * in EFI subsystem. A caller should ensure that the buffer have + * enough space for a resulting string, including L"\0". + * No strict check against the length will be done here. + * + * Return: A pointer to the next position after the created string + * in @buffer, or NULL otherwise + */ +u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index) +{ + u16 *p; + char index_buf[5]; + + u16_strcpy(buffer, name); + p = buffer + utf16_strnlen(name, SIZE_MAX); + sprintf(index_buf, "%04X", index); + utf8_utf16_strcpy(&p, index_buf); + + return p; +}