From patchwork Thu Oct 29 00:25:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319309 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15329ilc; Wed, 28 Oct 2020 17:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQv5U0b/3Efty6DuHjfyOnJf2gxGjLLXRPekdY1YDTseHOv9v9isjybZI99sfaUG+rsxW+ X-Received: by 2002:a17:906:e83:: with SMTP id p3mr364021ejf.243.1603931222032; Wed, 28 Oct 2020 17:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931222; cv=none; d=google.com; s=arc-20160816; b=Tq0VHl7/XzmTw/kZwoW9iiup5qwCAZl3lHKzcyfIKiZ7YzX1lYwO3z6zXpmhowU6wd 4D0d9nrdBEu8eQtX0pyGgXLvxMyfhldWUlUL7asCw2D3S9WpdiE4HwTAlE9TC5lep+rE pfV8hKdT7lnbBcx3RCZWJpihvVMHDftYjdzKNe913jQd4AyRaa33vcsOOd24B8ATMbMk OMdtESqa7zKRbF0Xuvag0uoLnD/RJZyWSnIJKn/mxcxk6vkkTwINennr2dXDrFMISNyh X+WvDZYvOu8ym2/JRMSyHxVlMSVqO7gvqXOPpClU2gbHedlJOEjuU15kJPQsxyWbg2P+ SvtQ== 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=nxZK42LHMJ6WpkTiO187Xt6SEIs4iWGiI8ieah5a5VUv+wdgnWshtOQPDTrUFU1GmB 9m5L4l2P+jcOil1817kyUOxlNO7KERmv2fxTbzd7Txp6hpBSmeT6IC9BcDmpj5lAvphv hogRLo49AGgVsWxZLm+oy1MI1Cli/fJPlOWP9EvAbg5Ak/Qmg87IMQ7cYi00Vo4O50Vy NvbLZdQp9LcUyIpk23OSOZo+rIVdL66jGXqxqcs12nllf0mWya76TN3b5OPnBBGzENUi FBCi2baDvdHOc/3VvNEjeTgnApdk85CZDwNN68Bc1VzUNj/MZ1oZDxAC2yUh9MnPfwMt vtpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DjC5ZcuW; 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 e3si647618eja.411.2020.10.28.17.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27:02 -0700 (PDT) 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=DjC5ZcuW; 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 8A047824DA; Thu, 29 Oct 2020 01:26:25 +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="DjC5ZcuW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 164EA824E8; Thu, 29 Oct 2020 01:26:17 +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-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 CC458824A8 for ; Thu, 29 Oct 2020 01:26:11 +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-pl1-x641.google.com with SMTP id b19so473514pld.0 for ; Wed, 28 Oct 2020 17:26:11 -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=DjC5ZcuWDPgcToE3beTiCjN7c/l9awS1dMzo17qyWlwsyzdo2MRzsFziFHrlWlkbVH +FwE9Sz+h8cOADJD8Dd7d8thmyOa8MteZX4c9bL/0dmanv2707T8piAEouMqOkFJgvCb EJrFkI+Z/2FELqguMkhR5ATgSMLT+n/Tl6lHH8PXEozbZwJl6AGHA28rAN1IvB+6HihV 4QJChYgXe9kD5E6+gu8QrGaCLv2JAcOULGU5D1Zqgw0AMCAbyUEFm7XZBJQRfLEn/oPS cfhiV9h16ZOvjJiHQFhBFvMGjke1ryH4aoPW/AciXOlKllYy6P4mapSipsnuR3q5BKzR UGxA== 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=IhbYj7Uk43mrKJnv3kGkXoGWePjXCzG27sDE0g2EiqC7pBM7frNKweZTjQDxF2ROKO OH9CQn26QqZDvPHT4kJDVy0Y/H5ViM+hW8yRUbkaPyLXmdMAbnWmWSDsmBHxVrHf315P wMzt6Xb/SPGmq3GilMZL8arTaROXht5iEIoYkQ6iwGFtXWNia1iNnmUObxj3Kkw5Y3w8 k3gkh5xQ9wU0NGn9Ptw4gq93D2FDhSf+qXzc5f/cV8KpECSXWCsP5epKC9niSZEXNDtb 0U6Q9PlxVsdoGHcWeV9yXtmldRIgzW29LjQAXoU+IpfW/nGVFeVPrjmI2iqxT+dFOe8Y BiLg== X-Gm-Message-State: AOAM533qSMRj3gzZItDA09wu2dbkTy/4bsaOQUvJhpxa23M5Tg7208bs Fo/3RYWhhzeOk8XSDrecsIUSdexXSOmFdQ== X-Received: by 2002:a17:902:7004:b029:d6:489b:6657 with SMTP id y4-20020a1709027004b02900d6489b6657mr1438208plk.20.1603931170216; Wed, 28 Oct 2020 17:26:10 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:09 -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: [RESEND PATCH v6 06/17] efi_loader: add efi_create_indexed_name() Date: Thu, 29 Oct 2020 09:25:17 +0900 Message-Id: <20201029002528.34408-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-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; +}