From 3080ddf970b15c606d396b80845ff74569575e67 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 22 Feb 2023 02:10:20 +0100 Subject: [PATCH 1/5] test: unit test for crc8 Add a unit test for the crc8() function. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/lib/Makefile | 1 + test/lib/test_crc8.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/lib/test_crc8.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 7e7922fe3b4..e0bd9e04e8f 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o obj-$(CONFIG_GETOPT) += getopt.o +obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o else obj-$(CONFIG_SANDBOX) += kconfig_spl.o diff --git a/test/lib/test_crc8.c b/test/lib/test_crc8.c new file mode 100644 index 00000000000..0dac97bc5bf --- /dev/null +++ b/test/lib/test_crc8.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2023, Heinrich Schuchardt + * + * Unit test for crc8 + */ + +#include +#include +#include + +static int lib_crc8(struct unit_test_state *uts) { + const char str[] = {0x20, 0xf4, 0xd8, 0x24, 0x6f, 0x41, 0x91, 0xae, + 0x46, 0x61, 0xf6, 0x55, 0xeb, 0x38, 0x47, 0x0f, + 0xec, 0xd8}; + int actual1, actual2, actual3; + int expected1 = 0x47, expected2 = 0xea, expected3 = expected1; + + actual1 = crc8(0, str, sizeof(str)); + ut_asserteq(expected1, actual1); + actual2 = crc8(0, str, 7); + ut_asserteq(expected2, actual2); + actual3 = crc8(actual2, str + 7, sizeof(str) - 7); + ut_asserteq(expected3, actual3); + + return 0; +} + +LIB_TEST(lib_crc8, 0); From ac2ac6908095a22bb48ae3ca5f7a2596f7fc13a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Stehl=C3=A9?= Date: Mon, 20 Feb 2023 15:37:29 +0100 Subject: [PATCH 2/5] doc: uefi: fix links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a couple of links so that they are rendered correctly with sphinx. Signed-off-by: Vincent Stehlé Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- doc/develop/uefi/fwu_updates.rst | 3 ++- doc/develop/uefi/uefi.rst | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/develop/uefi/fwu_updates.rst b/doc/develop/uefi/fwu_updates.rst index 72c850a7908..e4709d82b41 100644 --- a/doc/develop/uefi/fwu_updates.rst +++ b/doc/develop/uefi/fwu_updates.rst @@ -27,7 +27,8 @@ metadata. Individual drivers can be added based on the type of storage media, and its partitioning method. Details of the storage device containing the FWU metadata partitions are specified through a U-Boot specific device tree property `fwu-mdata-store`. Please refer to -U-Boot `doc `__ +U-Boot :download:`fwu-mdata-gpt.yaml +` for the device tree bindings. Enabling the FWU Multi Bank Update feature diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst index a944c0fb803..ffe25ca2318 100644 --- a/doc/develop/uefi/uefi.rst +++ b/doc/develop/uefi/uefi.rst @@ -386,8 +386,8 @@ is because the FWU feature supports multiple partitions(banks) of updatable images, and the actual dfu alt number to which the image is to be written to is determined at runtime, based on the value of the update bank to which the image is to be written. For more information -on the FWU Multi Bank Update feature, please refer `doc -`__. +on the FWU Multi Bank Update feature, please refer to +:doc:`/develop/uefi/fwu_updates`. When using the FMP for FIT images, the image index value needs to be set to 1. From 5ee8d90f5469572f3b07d42857012d110476cd2f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 3 Mar 2023 22:48:27 +0100 Subject: [PATCH 3/5] doc: man-page for panic command Provide a man-page for the panic command. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/usage/cmd/panic.rst | 33 +++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 34 insertions(+) create mode 100644 doc/usage/cmd/panic.rst diff --git a/doc/usage/cmd/panic.rst b/doc/usage/cmd/panic.rst new file mode 100644 index 00000000000..115eba5bde1 --- /dev/null +++ b/doc/usage/cmd/panic.rst @@ -0,0 +1,33 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +panic command +============= + +Synopis +------- + +:: + + panic [message] + +Description +----------- + +Display a message and reset the board. + +message + text to be displayed + +Examples +-------- + +:: + + => panic 'Unrecoverable error' + Unrecoverable error + resetting ... + +Configuration +------------- + +If CONFIG_PANIC_HANG=y, the user has to reset the board manually. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 840c20c934d..ebf5eea9f8a 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -65,6 +65,7 @@ Shell commands cmd/md cmd/mmc cmd/mtest + cmd/panic cmd/part cmd/pause cmd/pinmux From 26a35023c41dcceda057173ac6cdcc1de5fd4f31 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Tue, 21 Feb 2023 11:33:17 +0900 Subject: [PATCH 4/5] efi_loader: update SetVariable attribute check UEFI specification v2.10 says that EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated and EFI_UNSUPPORTED should be returned in SetVariable variable service. Current implementation returns EFI_INVALID_PARAMETER, let's fix the return value. Together with above change, this commit also updates the SetVariable attribute check to be aligned with the EDK2 reference implementation. Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 5804f69954a..be95ed44e6e 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -230,8 +230,30 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, u64 time = 0; enum efi_auth_var_type var_type; - if (!variable_name || !*variable_name || !vendor || - ((attributes & EFI_VARIABLE_RUNTIME_ACCESS) && + if (!variable_name || !*variable_name || !vendor) + return EFI_INVALID_PARAMETER; + + if (data_size && !data) + return EFI_INVALID_PARAMETER; + + /* EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated */ + if (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) + return EFI_UNSUPPORTED; + + /* Make sure if runtime bit is set, boot service bit is set also */ + if ((attributes & + (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == + EFI_VARIABLE_RUNTIME_ACCESS) + return EFI_INVALID_PARAMETER; + + /* only EFI_VARIABLE_NON_VOLATILE attribute is invalid */ + if ((attributes & EFI_VARIABLE_MASK) == EFI_VARIABLE_NON_VOLATILE) + return EFI_INVALID_PARAMETER; + + /* Make sure HR is set with NV, BS and RT */ + if (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD && + (!(attributes & EFI_VARIABLE_NON_VOLATILE) || + !(attributes & EFI_VARIABLE_RUNTIME_ACCESS) || !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS))) return EFI_INVALID_PARAMETER; @@ -281,8 +303,6 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, /* authenticate a variable */ if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT)) { - if (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) - return EFI_INVALID_PARAMETER; if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) { u32 env_attr; @@ -300,8 +320,7 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, } } else { if (attributes & - (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | - EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)) { + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) { EFI_PRINT("Secure boot is not configured\n"); return EFI_INVALID_PARAMETER; } From d3970e04e7125e37ea8c4f3f056b6f5ba868e5f7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 3 Mar 2023 22:04:26 +0100 Subject: [PATCH 5/5] efi_loader: describe term_get_char() Add a function description. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_console.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 43176309077..a2d137d7a9e 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -77,6 +77,14 @@ static struct simple_text_output_mode efi_con_mode = { .cursor_visible = 1, }; +/** + * term_get_char() - read a character from the console + * + * Wait for up to 100 ms to read a character from the console. + * + * @c: pointer to the buffer to receive the character + * Return: 0 on success, 1 otherwise + */ static int term_get_char(s32 *c) { u64 timeout;