From patchwork Mon Aug 3 05:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 247349 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp931730ilo; Sun, 2 Aug 2020 22:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxneBSdYO6U3ncCfe7vEYjKPyUhKfXG6fM67iRpNSgrAyzUKUkfCtMzCs53geQG2BN+idJh X-Received: by 2002:a05:6402:cb9:: with SMTP id cn25mr14497086edb.247.1596433536255; Sun, 02 Aug 2020 22:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596433536; cv=none; d=google.com; s=arc-20160816; b=ZeViOnONabIGrNbxN866KSPUxiQwaxeT8xoyuxk4bO8acFzY/4gBdOc6IxnkkE9iKD uwnlBx4MQ1A5WuThDHOc5FtnsMrjmOVOry6gTy5a2I3QC96wH9suNUPQ4bcuVdSXYuoQ irh82uVpD7704Bjl1Jpjf3WMeQYfn144ZCL1pr9mCRYMw6mc8jYiPE73kRBoxVag5r7E 9r5oK1edQNc6tfrP5T2k9CZ0RSH7Aw/lEivUj4xqwOQ3cilPukcJSRSIExe35tdurpff CKNnrh8HQjW9AfBjHgq5f4zl7zFgCVC7+I1f4KAALtC9maEvUpHNV0xGETWF5ljvVxZb r96A== 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=KM0tOWyokDJbCvjHrgG9ikKOH2UJZCA+Wjc6ehMw7Ac=; b=G8NiG0khoLE7xpkG9+SvRTETtCHEPbDaWbuCf/UHdUfu+tV4+vL71Ead2ESHkDc1tz 5adLp/WAruBqqIRU28quJhe2zW79FHgL48kiWOBuI47TzFRHDD6LA9ZwU1lbOZjyXMLM YVlu2OmH+TMbWyXzEALJkiOwL7/laMWr2Ogl7xAjC6TsfQxvuW7XngorEiW9Z+LD2xUh p7+HOKFi2Jv8goGl1Nv18jGDLUPBoUFvF9F27JfuQpB98DrmG2abL73P9UE/Q15bFMpN nF0cU+M9iRXjsxG0KV3m6IePmoT4RdCXykW/w3ynEsZe/MypnnZWeMIzkNBBoi7Da8Uw x41A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DnWYdvWb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a17si7340204ejt.20.2020.08.02.22.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 22:45:36 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DnWYdvWb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 1564F82174; Mon, 3 Aug 2020 07:44:48 +0200 (CEST) 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="DnWYdvWb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1F6C082165; Mon, 3 Aug 2020 07:44:45 +0200 (CEST) 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-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 DB0FE820E6 for ; Mon, 3 Aug 2020 07:44:40 +0200 (CEST) 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-pl1-x644.google.com with SMTP id k13so12346025plk.13 for ; Sun, 02 Aug 2020 22:44:40 -0700 (PDT) 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=KM0tOWyokDJbCvjHrgG9ikKOH2UJZCA+Wjc6ehMw7Ac=; b=DnWYdvWbFUTYS2VivL6GrF47Np2JMPM/lSs6kWC3WJ1RyDCQDU6U7c8ldXJYdoYehU t0nkBLPimiJkwq0TFjzoLKp/d5abTH+6QiLY+SIX6MNCwmBRTC29oi+vVkQ654dz3tBB jAZlzggY9lSszFxxjyXepCNFznBW+ICLXwvmFnxOjFi3HmbMOlfvd46MIp0MdA5mbUSV SnqsqDG8ovG1xGE2h4oUVyVkA6SZT6kA7wK+dPB2scPT94ARrOzQfMZYRKCqq7jmKDU7 G0rhp1SpMihj1skgtM7WCqnzkGQOJ1to99GoecUtoKQmGj6sZGG2MNvQ7vL39N75PPch P8LQ== 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=KM0tOWyokDJbCvjHrgG9ikKOH2UJZCA+Wjc6ehMw7Ac=; b=DlLXKFBtFPPiB50IPkjC00WhXs48yxux1l3TiBDKcRJgMfLLOXgwX64lMdKnif0VP/ TMue8rBDFbv+GrgMdb/olKKynwhIXOkPs+nhcpaJhdyRfwW6DAid1gsOHCjnzvU7uphC Aq2MBxsVA41AfC3X8CJFwDavfqn+PIeKuIrJG/KHQSJplQl42SYg/s3iu2g8+0Y/2ii8 qgS9AEU7jwjaGQmBuyjHh/09bL12LGdPwi8IJ+ZhYQXwXMUmqyZdrER8RRvO/C1Np60u Ydn+6heav2qdWE8Ra2H7CLbxpyI28P6S4/42oK6ctaL3Z60mHUm3MWn7dfvezUmjUWBL jKkQ== X-Gm-Message-State: AOAM530qw3up5FvwdcL1Kw8M4ij2GbJ7lOqM4noDypYhTYCUd35Q96RK MpKx2qR7HguFGy8V0lb3iuz3Kw== X-Received: by 2002:a17:902:9a81:: with SMTP id w1mr13392402plp.186.1596433479422; Sun, 02 Aug 2020 22:44:39 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id r25sm16952633pgv.88.2020.08.02.22.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 22:44:38 -0700 (PDT) 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 v5 06/17] efi_loader: add efi_create_indexed_name() Date: Mon, 3 Aug 2020 14:43:44 +0900 Message-Id: <20200803054355.17356-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200803054355.17356-1-takahiro.akashi@linaro.org> References: <20200803054355.17356-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.27.0 diff --git a/include/efi_loader.h b/include/efi_loader.h index 98944640bee7..d33efa9e9b13 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -795,6 +795,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 6196c0a06cd7..a09a7b607e11 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -230,3 +231,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; +}