From patchwork Mon Sep 7 05:34:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 249196 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp3415116ilg; Sun, 6 Sep 2020 22:38:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaBQONxyyYfyegs4xhpwLnzjTeDu5szwySuo4R5sWuszk6KHy/dwRSEs1i1mZ69BZnKxja X-Received: by 2002:a17:906:bb06:: with SMTP id jz6mr19039639ejb.275.1599457090872; Sun, 06 Sep 2020 22:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599457090; cv=none; d=google.com; s=arc-20160816; b=GUhKynQURHAUq2X4OR8+hfeAF9xoTdbrcAdxch60fn/wx9QU9FhstkC0E1LbTsrdoO c6sfQyT7yXUlGv+ULVOewTDhH/WfgwKaiAuK+enanXXEIpNGb4mPKsU8syX82+AuSpab m+vjMOeCkI7GJDniMgDZghj4OLw6ertI2POEda5GSFEB65txaQLY5PoIeDURa1sJXQTI CSHpyEhV2iKL5lN6rRccH6BjUDshaDYLhz6XYkRzg+Db4mLuYsc+XMaTXAaFMdg+g/Fq nRlshyi2uL/eYPmYnRk5z4STV590oqzZDiq+GG7Yi7wBuL3/fls2zBlZJqu6mnCIfaU0 QdVQ== 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=DCcGfqr5MYYQCRkQTNmZjCmHMsSXVjigLUWJwnUQhnc=; b=N0TC28b83IPQu/xRweILSeEJdax4KScwkijRmb4rA01BVU4We2jWFcLMVc53dBm6Kp RIJGYjYlfpqbUZXJCueAKrRUlIfZq08Dw06WJNqZ2JenLNMLTpu317WK3aoyuvZUVMUT hb0aAe5qG3mnV1Si3ywAu0haHtt4PyboETR+hO1t8U4qLsxc3uwGJcbH+7XFp2SdT+B0 jCM8hG7CU9VkvVnr1g4CJFhdbHKvySlRIkx3SKm4/Si5Zmlzkp9GpCFNgYBSGIJXzfL4 Hzqw3bTJyP0KwdszcCoz0wDyQrTzemslDkOujiIYbK/H3MJDT8NCqyjt0i3OD8vQYrzz 1Kyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LFzm5Qr+; 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 ay11si8994875edb.517.2020.09.06.22.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 22:38:10 -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=LFzm5Qr+; 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 0D556824F6; Mon, 7 Sep 2020 07:36:35 +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="LFzm5Qr+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 94A22824D7; Mon, 7 Sep 2020 07:36:15 +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-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (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 8C0FA824C9 for ; Mon, 7 Sep 2020 07:35:57 +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-pj1-x1041.google.com with SMTP id b16so6137875pjp.0 for ; Sun, 06 Sep 2020 22:35:57 -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=DCcGfqr5MYYQCRkQTNmZjCmHMsSXVjigLUWJwnUQhnc=; b=LFzm5Qr+CrPS/jtX33Z8PwpWfJa9UyYi4E2b8KseKKg9+YfyZ+PTyU4Mtmzw03mjQF vf6gFLmyxENOdEKAPtXK/qafUP5nggAT5zn0AkXgNeH2jabHveYfF+7A0ZpL4tKNLRzO YhcPmwB6+Qk0kygvsXqhWA9HOdz4Q5OPxERi30rz7d3PQR6MRHJFrAxWMs72IuVYkHuR ufyL8GJCTHZ1gTG9RBgakDutabzm9n/xKsV4gPZpTgo0Lp2Tsaa8+kQF794a+pH3ipHi rRCOqnpVfTf4UYloYIZEUC3e20/jLnTHWa7ZW4y9EhlTA0m8n2w/mNXSIRK6yECr1W+z dGfA== 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=DCcGfqr5MYYQCRkQTNmZjCmHMsSXVjigLUWJwnUQhnc=; b=YaNMidnHFfpwXeVcuFVfPbVqQbn892D6CBNjKRMO+738c5NMeWhPNrbqM6DNbHKUeo Iusfl3rZcgIISy9DBWjTrZ30igQq++EdHqQdGbI94iiv+cHy08na6YHovH0w6AeVE3jl HzBDkrhRP5cQj7aS4a80m1aU+UZXczQ5AcuQ9hsd7GyUOmEsABsgxGlotpit5d2mCaCY TreSlcHvuO+Ni6wvGFNj5Q4xxCpGIOk808eQgFGq3mUk1PRUwvDZNUNd60rJXu9S1l1e aRyNLXVVUrv0eWCf27ZwfdSdKCgJCB7DRaF6/U8Kufa3w7XZZwM/5JrI10n1N05a30om PYOQ== X-Gm-Message-State: AOAM531/Sx1+Eh0JvpMZW1xJBVVNP66r4ZN/LzyOO/To4UgbplBgeIdk wJJdzSOrKyVOqlQBNYXCojH09Q== X-Received: by 2002:a17:902:968d:: with SMTP id n13mr18365341plp.260.1599456955884; Sun, 06 Sep 2020 22:35:55 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id w6sm10783939pgr.82.2020.09.06.22.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 22:35:55 -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 v6 06/17] efi_loader: add efi_create_indexed_name() Date: Mon, 7 Sep 2020 14:34:15 +0900 Message-Id: <20200907053426.1675646-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907053426.1675646-1-takahiro.akashi@linaro.org> References: <20200907053426.1675646-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 0baa1d2324c8..a4a123c149fd 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -803,6 +803,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; +}