From patchwork Thu Oct 29 04:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319345 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp141898ilc; Wed, 28 Oct 2020 21:50:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws5RdHn1P6azDuEdVpQVPPRrdtoJ0lbNn+oFfIzRMmp7eMVLIcpr36d38nyDifyqnTaI5q X-Received: by 2002:a17:906:3c03:: with SMTP id h3mr2291653ejg.78.1603947037919; Wed, 28 Oct 2020 21:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603947037; cv=none; d=google.com; s=arc-20160816; b=TYL9C7lQGkD+TEVKTRZ7LjnAkgnztwxrlG6LnH3llOobDDDf266ZUMXTR5FtRTXOgW nmKAbt2o0HJKtZgxEY/1kMwbQhpahcpVrI4vzfxnqQOKdjJVzPTZoSW0Ev1QQk32b0b4 3ArLwxzMUtf4rpJS5oVK/rPuXcyPmXg5L5u616UIjgIl5gcz7v7jitgye+RYr923VKrr 4BVCaf+TkrunyW+1o3DjsFRX09CZtlDlA9TP2Z8RC5h2DIU4SL1PwtomozxtRtIL5U7c WaXj9YmQTA7hDKiJq9jz+aYgHgrPcATrqJ/aiYPbpBs+86lnGnNvFJN8j57SMeml3CFx R7mw== 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=IIyz/G2V8RGNSWELRmVa4LMPEriqbU3t9cbP3otDPT4zDSk33/vGCgiRjSKURU2s7l 5mOGjEcNH3Z3FXmuUciyioROPt83nMVOHxPk4aMm2Yh/JmvqhuKIfyfRoDgtMqHXi+mS x7aRImDtGThH2bSnaz9RU0277fPY/xfu8Dx1XXv4kiis36z5D4rtXywbxhvSZpk/+cus EraoN5niR2ZCwjxPD+oiWJvmXVtRQxaiybJ3FjTbx8mvbjI3XA9LntTDAmjmRpcK7KYK BmW69RIVbOoanoQz3iYPsXJ/fCbN5lEB6d761L5Hwv9TNBrStUlK8Gn6N4bZ0Zln+6Zh vkUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OW0Pm1Gv; 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 h10si1091004eje.596.2020.10.28.21.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 21:50:37 -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=OW0Pm1Gv; 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 68C29824FB; Thu, 29 Oct 2020 05:50:01 +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="OW0Pm1Gv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4FD6E824F7; Thu, 29 Oct 2020 05:50:00 +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-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 8716D824FB for ; Thu, 29 Oct 2020 05:49:54 +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-pg1-x543.google.com with SMTP id h6so1351445pgk.4 for ; Wed, 28 Oct 2020 21:49:54 -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=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=OW0Pm1GvvUXOOoZ7niWsKSFB3lwjJEKkZ297yykYvAJ+LzFvnfU/b3bznJzcV5EF0W cYpXFFksraNZ162RVR7OjOSg2ffFrP/MUbFTT9SOSO0uTn8IOWrCNide+hdnzIksWF5u GGZTuDsf/cq+uRBWVOdkD7gnBml2yqQlS2p9aP3jpyQfYUOFR47HPFT9GFWrM8uHFCmH kpNlGtVyWBVcVYebTJMUPHhHKebvJR44YxAmfAgJMw3veh8cHLo2Xf8KQQKjJ6wRjKM0 VzX3lvntCbxwgdu0qMKFo6Rnu2zA5rfhnLpbPPDI0uhqiYL5UwyxIwPRsY0BDls3kqeE uhgg== 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=tm3PhtaSPgitclZKbOQAWyJGib5RYF4r1zL7OiDAjzWMa4IeIE76GV9KMbdn2cDcdQ zePqK9ijWkL4PoeCPPn+JKQnOzX3KeaUrIpt04+q8oj9RPhxd2hj1SkJnwqiRHz+IFJ9 2UfJuXdJTmbLvHWTAcxHzfwLRCfSakK7Cly0JJou5tL0QMPkYksz1FRsppMos9cfwllU MJuNxUr+4FNSJa8ZUMXWxw1jDEoOdiGtBU2pGt2JIAQP7ghrcPyKGsUqwECXlZrhz+Kh Wze/lGtoHYqZsQmQS2tEhZ38k4XQq4o4T1PPtqPWCvAg3Q9ZVYs69Hw5+Dl4K6ZwsRXo e+wg== X-Gm-Message-State: AOAM533IimOG/fttMO2ZrQmVWbJqWyHZPtGjaassltp7E0VGlluwsVJ6 hAAM9vSQNWAYGqgeNoKLUJSdlA== X-Received: by 2002:a62:c181:0:b029:152:6ba8:a011 with SMTP id i123-20020a62c1810000b02901526ba8a011mr2607652pfg.2.1603946993093; Wed, 28 Oct 2020 21:49:53 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id t14sm830689pjy.46.2020.10.28.21.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 21:49:52 -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 v7 06/17] efi_loader: add efi_create_indexed_name() Date: Thu, 29 Oct 2020 13:47:46 +0900 Message-Id: <20201029044757.183262-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029044757.183262-1-takahiro.akashi@linaro.org> References: <20201029044757.183262-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; +}