All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v7 06/17] efi_loader: add efi_create_indexed_name()
Date: Thu, 29 Oct 2020 13:47:46 +0900	[thread overview]
Message-ID: <20201029044757.183262-7-takahiro.akashi@linaro.org> (raw)
In-Reply-To: <20201029044757.183262-1-takahiro.akashi@linaro.org>

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 <takahiro.akashi@linaro.org>
---
 include/efi_loader.h       |  3 +++
 lib/efi_loader/efi_setup.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

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 <common.h>
+#include <charset.h>
 #include <bootm.h>
 #include <efi_loader.h>
 #include <efi_variable.h>
@@ -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;
+}
-- 
2.28.0

  parent reply	other threads:[~2020-10-29  4:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29  4:47 [PATCH v7 00/17] efi_loader: add capsule update support AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 01/17] dfu: rename dfu_tftp_write() to dfu_write_by_name() AKASHI Takahiro
2020-10-29 14:43   ` Tom Rini
2020-10-30  4:45     ` AKASHI Takahiro
2020-10-30  8:40     ` Lukasz Majewski
2020-10-29  4:47 ` [PATCH v7 02/17] dfu: modify an argument type for an address AKASHI Takahiro
2020-10-29 14:43   ` Tom Rini
2020-10-29  4:47 ` [PATCH v7 03/17] common: update: add a generic interface for FIT image AKASHI Takahiro
2020-10-29 14:43   ` Tom Rini
2020-10-29  4:47 ` [PATCH v7 04/17] dfu: export dfu_list AKASHI Takahiro
2020-10-29 14:43   ` Tom Rini
2020-10-29  4:47 ` [PATCH v7 05/17] efi_loader: add option to initialise EFI subsystem early AKASHI Takahiro
2020-10-29  4:47 ` AKASHI Takahiro [this message]
2020-10-29  4:47 ` [PATCH v7 07/17] efi_loader: define UpdateCapsule api AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 08/17] efi_loader: capsule: add capsule_on_disk support AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 09/17] efi_loader: capsule: add memory range capsule definitions AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 10/17] efi_loader: capsule: support firmware update AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 11/17] efi_loader: add firmware management protocol for FIT image AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 12/17] dfu: add dfu_write_by_alt() AKASHI Takahiro
2020-10-29 14:43   ` Tom Rini
2020-10-29  4:47 ` [PATCH v7 13/17] efi_loader: add firmware management protocol for raw image AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 14/17] cmd: add "efidebug capsule" command AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 15/17] tools: add mkeficapsule command for UEFI capsule update AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 16/17] test/py: efi_capsule: test for FIT image capsule AKASHI Takahiro
2020-10-29  4:47 ` [PATCH v7 17/17] test/py: efi_capsule: test for raw " AKASHI Takahiro
2020-10-29 14:43 ` [PATCH v7 00/17] efi_loader: add capsule update support Tom Rini
2020-11-04  9:36   ` AKASHI Takahiro
2020-11-04 12:57     ` Tom Rini
2020-10-30  7:54 ` Heinrich Schuchardt
2020-10-30  7:59   ` Heinrich Schuchardt
2020-10-30 17:46 ` [PATCH] test: unit test for efi_create_indexed_name() Heinrich Schuchardt
2020-10-30 17:46   ` Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201029044757.183262-7-takahiro.akashi@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.