From 2541ce2c1af87f74a9feb35a1cbfc20ff8d04e4b Mon Sep 17 00:00:00 2001 From: Nandor Han Date: Thu, 10 Jun 2021 16:56:43 +0300 Subject: reboot-mode: add support for reboot mode control A new driver uclass is created to handle the reboot mode control. The new uclass driver is updating an environment variable with the configured reboot mode. The mode is extracted from a map provided at initialization time. The map contains a list of modes and associated ids. Signed-off-by: Nandor Han Reviewed-by: Simon Glass --- include/dm/uclass-id.h | 1 + include/reboot-mode/reboot-mode.h | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 include/reboot-mode/reboot-mode.h (limited to 'include') diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index d800f679d56..9d474533ba8 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -92,6 +92,7 @@ enum uclass_id { UCLASS_PWRSEQ, /* Power sequence device */ UCLASS_QFW, /* QEMU firmware config device */ UCLASS_RAM, /* RAM controller */ + UCLASS_REBOOT_MODE, /* Reboot mode */ UCLASS_REGULATOR, /* Regulator device */ UCLASS_REMOTEPROC, /* Remote Processor device */ UCLASS_RESET, /* Reset controller device */ diff --git a/include/reboot-mode/reboot-mode.h b/include/reboot-mode/reboot-mode.h new file mode 100644 index 00000000000..86b51f881ca --- /dev/null +++ b/include/reboot-mode/reboot-mode.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c), Vaisala Oyj + */ + +#ifndef REBOOT_MODE_REBOOT_MODE_H__ +#define REBOOT_MODE_REBOOT_MODE_H__ + +#include +#include + +struct reboot_mode_mode { + const char *mode_name; + u32 mode_id; +}; + +struct reboot_mode_uclass_platdata { + struct reboot_mode_mode *modes; + u8 count; + const char *env_variable; +}; + +struct reboot_mode_ops { + /** + * get() - get the current reboot mode value + * + * Returns the current value from the reboot mode backing store. + * + * @dev: Device to read from + * @rebootmode: Address to save the current reboot mode value + */ + int (*get)(struct udevice *dev, u32 *rebootmode); + + /** + * set() - set a reboot mode value + * + * Sets the value in the reboot mode backing store. + * + * @dev: Device to read from + * @rebootmode: New reboot mode value to store + */ + int (*set)(struct udevice *dev, u32 rebootmode); +}; + +/* Access the operations for a reboot mode device */ +#define reboot_mode_get_ops(dev) ((struct reboot_mode_ops *)(dev)->driver->ops) + +/** + * dm_reboot_mode_update() - Update the reboot mode env variable. + * + * @dev: Device to read from + * @return 0 if OK, -ve on error + */ +int dm_reboot_mode_update(struct udevice *dev); + +#endif /* REBOOT_MODE_REBOOT_MODE_H__ */ -- cgit v1.2.3 From f9db2f16cb6fc7b6d05b0e70de65881bc97ba5c2 Mon Sep 17 00:00:00 2001 From: Nandor Han Date: Thu, 10 Jun 2021 16:56:44 +0300 Subject: reboot-mode: read the boot mode from GPIOs status A use case for controlling the boot mode is when the user wants to control the device boot by pushing a button without needing to go in user-space. Add a new backed for reboot mode where GPIOs are used to control the reboot-mode. The driver is able to scan a predefined list of GPIOs and return the magic value. Having the modes associated with the magic value generated based on the GPIO values, allows the reboot mode uclass to select the proper mode. Signed-off-by: Nandor Han Reviewed-by: Simon Glass --- include/reboot-mode/reboot-mode-gpio.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 include/reboot-mode/reboot-mode-gpio.h (limited to 'include') diff --git a/include/reboot-mode/reboot-mode-gpio.h b/include/reboot-mode/reboot-mode-gpio.h new file mode 100644 index 00000000000..16b1185c698 --- /dev/null +++ b/include/reboot-mode/reboot-mode-gpio.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) Vaisala Oyj. + */ + +#ifndef REBOOT_MODE_REBOOT_MODE_GPIO_H_ +#define REBOOT_MODE_REBOOT_MODE_GPIO_H_ + +#include + +/* + * In case of initializing the driver statically (using U_BOOT_DEVICE macro), + * we can use this struct to declare the pins used. + */ + +#if !CONFIG_IS_ENABLED(OF_CONTROL) +struct reboot_mode_gpio_config { + int gpio_dev_offset; + int gpio_offset; + int flags; +}; +#endif + +struct reboot_mode_gpio_platdata { + struct gpio_desc *gpio_desc; +#if !CONFIG_IS_ENABLED(OF_CONTROL) + struct reboot_mode_gpio_config *gpios_config; +#endif + int gpio_count; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_GPIO_H_ */ -- cgit v1.2.3 From c74675bd904b6ce9d5820a80f27793c0583fd54c Mon Sep 17 00:00:00 2001 From: Nandor Han Date: Thu, 10 Jun 2021 16:56:45 +0300 Subject: reboot-mode: read the boot mode from RTC memory RTC devices could provide battery-backed memory that can be used for storing the reboot mode magic value. Add a new reboot-mode back-end that uses RTC to store the reboot-mode magic value. The driver also supports both endianness modes. Signed-off-by: Nandor Han Reviewed-by: Simon Glass --- include/reboot-mode/reboot-mode-rtc.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 include/reboot-mode/reboot-mode-rtc.h (limited to 'include') diff --git a/include/reboot-mode/reboot-mode-rtc.h b/include/reboot-mode/reboot-mode-rtc.h new file mode 100644 index 00000000000..3613678f636 --- /dev/null +++ b/include/reboot-mode/reboot-mode-rtc.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c), Vaisala Oyj + */ + +#ifndef REBOOT_MODE_REBOOT_MODE_RTC_H_ +#define REBOOT_MODE_REBOOT_MODE_RTC_H_ + +struct reboot_mode_rtc_platdata { + struct udevice *rtc; + bool is_big_endian; + int addr; + size_t size; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_RTC_H_ */ -- cgit v1.2.3 From 26dd9936574864155b989b9f14319ca2779f0598 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 8 Jul 2021 15:57:33 +0200 Subject: lib: add crypt subsystem Add the basic functionality required to support the standard crypt format. The files crypt-sha256.c and crypt-sha512.c originate from libxcrypt and their formatting is therefor retained. The integration is done via a crypt_compare() function in crypt.c. ``` libxcrypt $ git describe --long --always --all tags/v4.4.17-0-g6b110bc ``` Signed-off-by: Steffen Jaeckel Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- include/crypt.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 include/crypt.h (limited to 'include') diff --git a/include/crypt.h b/include/crypt.h new file mode 100644 index 00000000000..e0be2832ff2 --- /dev/null +++ b/include/crypt.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (C) 2020 Steffen Jaeckel */ + +/** + * Compare should with the processed passphrase. + * + * @should The crypt-style string to compare against + * @passphrase The plaintext passphrase + * @equal Pointer to an int where the result is stored + * '0' = unequal + * '1' = equal + */ +void crypt_compare(const char *should, const char *passphrase, int *equal); -- cgit v1.2.3 From 29bbe71ccfef3440b4881259c6f8e39b6e7924c6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 8 Jul 2021 15:57:34 +0200 Subject: lib: wrap crypt API to hide errno usage In order to prevent using the global errno, replace it with a static version and create a wrapper function which returns the error value. Signed-off-by: Steffen Jaeckel Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- include/crypt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/crypt.h b/include/crypt.h index e0be2832ff2..f18a1705d4d 100644 --- a/include/crypt.h +++ b/include/crypt.h @@ -9,5 +9,6 @@ * @equal Pointer to an int where the result is stored * '0' = unequal * '1' = equal + * @return 0 on success, error code of errno else */ -void crypt_compare(const char *should, const char *passphrase, int *equal); +int crypt_compare(const char *should, const char *passphrase, int *equal); -- cgit v1.2.3 From 25c8b9f298e46ea6048b5308f7ee207c6461c36a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 8 Jul 2021 15:57:40 +0200 Subject: test: add first autoboot unit tests This adds tests for the crypt-based and plain SHA256-based password hashing algorithms in the autoboot flow. Signed-off-by: Steffen Jaeckel Reviewed-by: Simon Glass --- include/console.h | 17 +++++++++++++++++ include/test/common.h | 15 +++++++++++++++ include/test/suites.h | 1 + 3 files changed, 33 insertions(+) create mode 100644 include/test/common.h (limited to 'include') diff --git a/include/console.h b/include/console.h index f848bcbf037..b182440fcd6 100644 --- a/include/console.h +++ b/include/console.h @@ -83,6 +83,17 @@ int console_record_readline(char *str, int maxlen); * @return available bytes (0 if empty) */ int console_record_avail(void); + +/** + * console_in_puts() - Write a string to the console input buffer + * + * This writes the given string to the console_in buffer which will then be + * returned if a function calls e.g. `getc()` + * + * @str: the string to write + * @return the number of bytes added + */ +int console_in_puts(const char *str); #else static inline int console_record_init(void) { @@ -114,6 +125,12 @@ static inline int console_record_avail(void) return 0; } +static inline int console_in_puts(const char *str) +{ + /* There is never anything written */ + return 0; +} + #endif /* !CONFIG_CONSOLE_RECORD */ /** diff --git a/include/test/common.h b/include/test/common.h new file mode 100644 index 00000000000..81260d06ad6 --- /dev/null +++ b/include/test/common.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2019 Heinrich Schuchardt + * Copyright (c) 2021 Steffen Jaeckel + */ + +#ifndef __TEST_COMMON_H__ +#define __TEST_COMMON_H__ + +#include + +/* Declare a new common function test */ +#define COMMON_TEST(_name, _flags) UNIT_TEST(_name, _flags, common_test) + +#endif /* __TEST_COMMON_H__ */ diff --git a/include/test/suites.h b/include/test/suites.h index 80b41f188c7..d35cd83a4eb 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -31,6 +31,7 @@ int do_ut_addrmap(struct cmd_tbl *cmdtp, int flag, int argc, int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_common(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); -- cgit v1.2.3