Re: [EXTERNAL] Re: [PATCH] common: Kconfig: Fix CMD_BMP/BMP dependency

2023-07-14 Thread Samuel Dionne-Riel
Please do!

On 7/14/23, Nikhil M Jain  wrote:
>
>
> On 10/07/23 20:36, Tom Rini wrote:
>> On Sun, Jul 09, 2023 at 07:18:10PM -0400, Samuel Dionne-Riel wrote:
>>
>>> Using `default y` will not select BMP when CMD_BMP has been enabled, if
>>> it was already configured.
>>>
>>> By using `select`, if `CMD_BMP` is turned on, it will force the presence
>>> of `BMP`.
>>>
>>> Fixes: 072b0e16c482114d242580dd7a3197db5966705f
>>
>> The fixes tag should be the "git log -n1 --oneline" version of the
>> commit, btw.
>>
>>> Signed-off-by: Samuel Dionne-Riel 
>>> ---
>>>   cmd/Kconfig| 1 +
>>>   common/Kconfig | 2 +-
>>>   2 files changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/cmd/Kconfig b/cmd/Kconfig
>>> index 02e54f1e50..94c54b2359 100644
>>> --- a/cmd/Kconfig
>>> +++ b/cmd/Kconfig
>>> @@ -1988,6 +1988,7 @@ config CMD_2048
>>>   config CMD_BMP
>>> bool "Enable 'bmp' command"
>>> depends on VIDEO
>>> +   select BMP
>>> help
>>>   This provides a way to obtain information about a BMP-format image
>>>   and to display it. BMP (which presumably stands for BitMaP) is a
>>> diff --git a/common/Kconfig b/common/Kconfig
>>> index bbabadb35e..d0117e3dc8 100644
>>> --- a/common/Kconfig
>>> +++ b/common/Kconfig
>>> @@ -1157,7 +1157,7 @@ config IO_TRACE
>>>
>>>   config BMP
>>> bool "Enable bmp image display"
>>> -   default y if CMD_BMP
>>> +   default n
>>> help
>>>   Enable bmp functions to display bmp image and get bmp info.
>>
>> Since this is something that can be resolved by correcting the resulting
>> .config file (or storing a new defconfig in your build system, or what
>> have you) I'm not grabbing this for the release I'll be doing later
>> today.  Also in a v2, "default n" is the default. And I'm not entirely
>> sure if BMP (and SPL_BMP) end up being things that should be asked, or
>> should be select'd because they're library functions. Finally, this
>> should perhaps be part of
>> https://patchwork.ozlabs.org/project/uboot/list/?series=360683&state=*
>> but I'm not sure and will wait for Nikhil to chime in.
>>
> @Samuel, is it okay if I pick this patch and send it as a patch as part
> of my above mentioned series with the changes suggested by Tom?
>


-- 
— Samuel Dionne-Riel


[PATCH] common: Kconfig: Fix CMD_BMP/BMP dependency

2023-07-09 Thread Samuel Dionne-Riel
Using `default y` will not select BMP when CMD_BMP has been enabled, if
it was already configured.

By using `select`, if `CMD_BMP` is turned on, it will force the presence
of `BMP`.

Fixes: 072b0e16c482114d242580dd7a3197db5966705f
Signed-off-by: Samuel Dionne-Riel 
---
 cmd/Kconfig| 1 +
 common/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 02e54f1e50..94c54b2359 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1988,6 +1988,7 @@ config CMD_2048
 config CMD_BMP
bool "Enable 'bmp' command"
depends on VIDEO
+   select BMP
help
  This provides a way to obtain information about a BMP-format image
  and to display it. BMP (which presumably stands for BitMaP) is a
diff --git a/common/Kconfig b/common/Kconfig
index bbabadb35e..d0117e3dc8 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1157,7 +1157,7 @@ config IO_TRACE
 
 config BMP
bool "Enable bmp image display"
-   default y if CMD_BMP
+   default n
help
  Enable bmp functions to display bmp image and get bmp info.
 
-- 
2.41.0



[PATCH v4] cmd: Add pause command

2022-08-18 Thread Samuel Dionne-Riel
This command is being introduced with the goal of allowing user-friendly
"generic use case" U-Boot builds to pause until user input under some
situations.

The main use case would be when a boot failure happens, to pause until
the user has had time to acknowledge the current state.

Tested using:

make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'

Signed-off-by: Samuel Dionne-Riel 
Cc: Simon Glass 
---

Hi!

I believe everything is addressed. I took the comment about the sort
order being wonky as needing no changes.

Changes for v4
  - No functional change in command, mainly code style
  - Addressed nits
  - Added missing docs
  - Wrote test fully in code

Changes for v3
  - No functional change in patch
  - Sent with lines unwrapped
  - Added changelog

Changes for v2
  - Added test, as requested by Tom
  - Made CMD_PAUSE default n


---
 cmd/Kconfig |  6 +
 cmd/Makefile|  1 +
 cmd/pause.c | 32 ++
 configs/sandbox64_defconfig |  1 +
 configs/sandbox_defconfig   |  1 +
 doc/usage/cmd/pause.rst | 53 +
 doc/usage/index.rst |  1 +
 test/cmd/Makefile   |  3 +++
 test/cmd/test_pause.c   | 45 +++
 9 files changed, 143 insertions(+)
 create mode 100644 cmd/pause.c
 create mode 100644 doc/usage/cmd/pause.rst
 create mode 100644 test/cmd/test_pause.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 3625ff2a50b..e8d1f73cd0d 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1961,6 +1961,12 @@ config CMD_GETTIME
  milliseconds. See also the 'bootstage' command which provides more
  flexibility for boot timing.
 
+config CMD_PAUSE
+   bool "pause command"
+   help
+ Delay execution waiting for any user input.
+ Useful to allow the user to read a failure log.
+
 config CMD_RNG
bool "rng command"
depends on DM_RNG
diff --git a/cmd/Makefile b/cmd/Makefile
index 5e43a1e022e..98a6224bdc1 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_CMD_MFSL) += mfsl.o
 obj-$(CONFIG_CMD_MII) += mii.o
 obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MDIO) += mdio.o
+obj-$(CONFIG_CMD_PAUSE) += pause.o
 obj-$(CONFIG_CMD_SLEEP) += sleep.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
diff --git a/cmd/pause.c b/cmd/pause.c
new file mode 100644
index 000..c97833c0d70
--- /dev/null
+++ b/cmd/pause.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021
+ * Samuel Dionne-Riel 
+ */
+
+#include 
+#include 
+
+static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   char *message = "Press any key to continue...";
+
+   if (argc == 2)
+   message = argv[1];
+
+   /* No newline, so it sticks to the bottom of the screen */
+   printf("%s", message);
+
+   /* Wait on "any" key... */
+   (void) getchar();
+
+   /* Since there was no newline, we need it now */
+   printf("\n");
+
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(pause, 2, 1, do_pause,
+   "delay until user input",
+   "[prompt] - Wait until users presses any key. [prompt] can be used to 
customize the message.\n"
+);
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 6553568e768..0af582d642d 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -67,6 +67,7 @@ CONFIG_CMD_BMP=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb483..d856d9b0942 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -96,6 +96,7 @@ CONFIG_CMD_BOOTCOUNT=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/doc/usage/cmd/pause.rst b/doc/usage/cmd/pause.rst
new file mode 100644
index 000..c79e399c020
--- /dev/null
+++ b/doc/usage/cmd/pause.rst
@@ -0,0 +1,53 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later:
+
+pause command
+=
+
+Synopsis
+
+
+::
+
+pause [prompt]
+
+
+Description
+---
+
+The pause command delays execution waiting for any user input.
+
+It can accept a single parameter to change the prompt message.
+
+Examples
+
+
+Using with the default prompt:
+
+::
+
+=> pause
+Press any key to continue...
+
+
+Using with a custom prompt:
+
+::
+
+=> pause 'Prompt for pause...'
+Prompt for pause...
+
+Note that complex prompts require proper quoting:
+
+::
+
+=> pause Prompt for pause...
+pause - delay until user input
+
+Usage:
+pause [prompt] - Wait until users

[PATCH v3] cmd: Add pause command

2022-08-17 Thread Samuel Dionne-Riel
This command is being introduced with the goal of allowing user-friendly
"generic use case" U-Boot builds to pause until user input under some
situations.

The main use case would be when a boot failure happens, to pause until
the user has had time to acknowledge the current state.

Tested using:

make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'

Signed-off-by: Samuel Dionne-Riel 
---
Hi,

I hit a snag when sending v2, and lines ended-up wrapped. In addition
I also forgot to include the changelog.

It seems the patch on patchwork was also broken in a way it was not
on my end. I do not know why the lines ended-up mis-ordered.

Please tell if I should have used RESEND v2, since technically the
content of the patch are unchanged.

Changes for v3
  - No functional change in patch
  - Sent with lines unwrapped
  - Added changelog

Changes for v2
  - Added test, as requested by Tom
  - Made CMD_PAUSE default n

---
 cmd/Kconfig |  7 +
 cmd/Makefile|  1 +
 cmd/pause.c | 35 +
 configs/sandbox64_defconfig |  1 +
 configs/sandbox_defconfig   |  1 +
 test/cmd/Makefile   |  3 ++
 test/cmd/test_pause.c   | 62 +
 7 files changed, 110 insertions(+)
 create mode 100644 cmd/pause.c
 create mode 100644 test/cmd/test_pause.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 3625ff2a50b..e774670a35c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1961,6 +1961,13 @@ config CMD_GETTIME
  milliseconds. See also the 'bootstage' command which provides more
  flexibility for boot timing.
 
+config CMD_PAUSE
+   bool "pause command"
+   default n
+   help
+ Delay execution waiting for any user input.
+ Useful to allow the user to read a failure log.
+
 config CMD_RNG
bool "rng command"
depends on DM_RNG
diff --git a/cmd/Makefile b/cmd/Makefile
index 5e43a1e022e..98a6224bdc1 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_CMD_MFSL) += mfsl.o
 obj-$(CONFIG_CMD_MII) += mii.o
 obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MDIO) += mdio.o
+obj-$(CONFIG_CMD_PAUSE) += pause.o
 obj-$(CONFIG_CMD_SLEEP) += sleep.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
diff --git a/cmd/pause.c b/cmd/pause.c
new file mode 100644
index 000..07bf346f3d1
--- /dev/null
+++ b/cmd/pause.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021
+ * Samuel Dionne-Riel 
+ */
+
+#include 
+#include 
+
+static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   char *message = "Press any key to continue...";
+
+   if (argc > 2)
+   return CMD_RET_USAGE;
+
+   if (argc == 2)
+   message = argv[1];
+
+   /* No newline, so it sticks to the bottom of the screen */
+   printf("%s", message);
+
+   /* Wait on "any" key... */
+   (void) getchar();
+
+   /* Since there was no newline, we need it now. */
+   printf("\n");
+
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(pause, 2, 1, do_pause,
+   "delay until user input",
+   "pause [prompt] - Wait until users presses any key. [prompt] can be 
used to customize the message.\n"
+);
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 6553568e768..0af582d642d 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -67,6 +67,7 @@ CONFIG_CMD_BMP=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb483..d856d9b0942 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -96,6 +96,7 @@ CONFIG_CMD_BOOTCOUNT=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index c331757425e..1bb02d93a23 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -5,6 +5,9 @@
 ifdef CONFIG_HUSH_PARSER
 obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
 endif
+ifdef CONFIG_CONSOLE_RECORD
+obj-$(CONFIG_CMD_PAUSE) += test_pause.o
+endif
 obj-y += mem.o
 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c
new file mode 100644
index 000..9c55c6302bc
--- /dev/null
+++ b/test/cmd/test_pause.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for pause command
+ *
+ * Copyright 2022, Samuel Dionne-Riel 
+ *
+ * Based on tests for echo:
+ * Copyright 2020, Heinrich Schuchadt 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;

[PATCH v2] cmd: Add pause command

2022-08-17 Thread Samuel Dionne-Riel
This command is being introduced with the goal of allowing user-friendly
"generic use case" U-Boot builds to pause until user input under some
situations.

The main use case would be when a boot failure happens, to pause until
the user has had time to acknowledge the current state.

Tested with sandbox using:

make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'

Signed-off-by: Samuel Dionne-Riel 
---
 cmd/Kconfig |  7 +
 cmd/Makefile|  1 +
 cmd/pause.c | 35 +
 configs/sandbox64_defconfig |  1 +
 configs/sandbox_defconfig   |  1 +
 test/cmd/Makefile   |  3 ++
 test/cmd/test_pause.c   | 62 +
 7 files changed, 110 insertions(+)
 create mode 100644 cmd/pause.c
 create mode 100644 test/cmd/test_pause.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 3625ff2a50b..e774670a35c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1961,6 +1961,13 @@ config CMD_GETTIME
  milliseconds. See also the 'bootstage' command which
provides more flexibility for boot timing.
 
+config CMD_PAUSE
+   bool "pause command"
+   default n
+   help
+ Delay execution waiting for any user input.
+ Useful to allow the user to read a failure log.
+
 config CMD_RNG
bool "rng command"
depends on DM_RNG
diff --git a/cmd/Makefile b/cmd/Makefile
index 5e43a1e022e..98a6224bdc1 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_CMD_MFSL) += mfsl.o
 obj-$(CONFIG_CMD_MII) += mii.o
 obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MDIO) += mdio.o
+obj-$(CONFIG_CMD_PAUSE) += pause.o
 obj-$(CONFIG_CMD_SLEEP) += sleep.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
diff --git a/cmd/pause.c b/cmd/pause.c
new file mode 100644
index 000..07bf346f3d1
--- /dev/null
+++ b/cmd/pause.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021
+ * Samuel Dionne-Riel 
+ */
+
+#include 
+#include 
+
+static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char
*const argv[]) +{
+   char *message = "Press any key to continue...";
+
+   if (argc > 2)
+   return CMD_RET_USAGE;
+
+   if (argc == 2)
+   message = argv[1];
+
+   /* No newline, so it sticks to the bottom of the screen */
+   printf("%s", message);
+
+   /* Wait on "any" key... */
+   (void) getchar();
+
+   /* Since there was no newline, we need it now. */
+   printf("\n");
+
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(pause, 2, 1, do_pause,
+   "delay until user input",
+   "pause [prompt] - Wait until users presses any key. [prompt]
can be used to customize the message.\n" +);
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 6553568e768..0af582d642d 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -67,6 +67,7 @@ CONFIG_CMD_BMP=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb483..d856d9b0942 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -96,6 +96,7 @@ CONFIG_CMD_BOOTCOUNT=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PAUSE=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_QFW=y
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index c331757425e..1bb02d93a23 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -5,6 +5,9 @@
 ifdef CONFIG_HUSH_PARSER
 obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
 endif
+ifdef CONFIG_CONSOLE_RECORD
+obj-$(CONFIG_CMD_PAUSE) += test_pause.o
+endif
 obj-y += mem.o
 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c
new file mode 100644
index 000..9c55c6302bc
--- /dev/null
+++ b/test/cmd/test_pause.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for pause command
+ *
+ * Copyright 2022, Samuel Dionne-Riel 
+ *
+ * Based on tests for echo:
+ * Copyright 2020, Heinrich Schuchadt 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct test_data {
+   char *cmd;
+   char *expected;
+   int expected_ret;
+};
+
+static struct test_data pause_data[] = {
+   /* Test default message */
+   {"pause",
+"Press any key to continue...",
+0},
+   /* Test provided message */
+   {"pause 'Prompt for pause...'",
+"Prompt for pause...",
+0},
+   /* Test providing more than one params */
+   {"pause a b",
+"pause - delay until user i

[PATCH 3/4] cmd: Add vibrator command

2021-12-22 Thread Samuel Dionne-Riel
Signed-off-by: Samuel Dionne-Riel 
---
 cmd/Kconfig|  10 
 cmd/Makefile   |   1 +
 cmd/vibrator.c | 148 +
 3 files changed, 159 insertions(+)
 create mode 100644 cmd/vibrator.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index e538e69a11..51e79ad806 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1391,6 +1391,16 @@ config CMD_PVBLOCK
help
  Xen para-virtualized block device support
 
+config CMD_VIBRATOR
+   bool "vibrator"
+   depends on VIBRATOR
+   default y if VIBRATOR
+   help
+ Enable the 'vibrator' command which allows for control of vibrator
+ motors available on the board. The vibrator motors can be listed with
+ 'vibrator list' and controlled with vibrator on/off/time. Any
+ vibrator driver can be controlled with this command.
+
 config CMD_VIRTIO
bool "virtio"
depends on VIRTIO
diff --git a/cmd/Makefile b/cmd/Makefile
index 6c4db4ed2e..49bf184bd9 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -164,6 +164,7 @@ obj-$(CONFIG_CMD_UBIFS) += ubifs.o
 obj-$(CONFIG_CMD_UNIVERSE) += universe.o
 obj-$(CONFIG_CMD_UNLZ4) += unlz4.o
 obj-$(CONFIG_CMD_UNZIP) += unzip.o
+obj-$(CONFIG_CMD_VIBRATOR) += vibrator.o
 obj-$(CONFIG_CMD_VIRTIO) += virtio.o
 obj-$(CONFIG_CMD_WDT) += wdt.o
 obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
diff --git a/cmd/vibrator.c b/cmd/vibrator.c
new file mode 100644
index 00..b77cb4867a
--- /dev/null
+++ b/cmd/vibrator.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Samuel Dionne-Riel 
+ * Copyright (c) 2017 Google, Inc
+ * Largely derived from `cmd/led.c`
+ * Original written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char *const state_label[] = {
+   [VIBRATOR_STATE_OFF]= "off",
+   [VIBRATOR_STATE_ON] = "on",
+   [VIBRATOR_STATE_TOGGLE] = "toggle",
+};
+
+enum vibrator_state_t get_vibrator_cmd(char *var)
+{
+   int i;
+
+   for (i = 0; i < VIBRATOR_STATE_COUNT; i++) {
+   if (!strncmp(var, state_label[i], strlen(var)))
+   return i;
+   }
+
+   return -1;
+}
+
+static int show_vibrator_state(struct udevice *dev)
+{
+   int ret;
+
+   ret = vibrator_get_state(dev);
+   if (ret >= VIBRATOR_STATE_COUNT)
+   ret = -EINVAL;
+   if (ret >= 0)
+   printf("%s\n", state_label[ret]);
+
+   return ret;
+}
+
+static int list_vibrators(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   for (uclass_find_first_device(UCLASS_VIBRATOR, &dev);
+dev;
+uclass_find_next_device(&dev)) {
+   struct vibrator_uc_plat *plat = dev_get_uclass_plat(dev);
+
+   if (!plat->label)
+   continue;
+   printf("%-15s ", plat->label);
+   if (device_active(dev)) {
+   ret = show_vibrator_state(dev);
+   if (ret < 0)
+   printf("Error %d\n", ret);
+   } else {
+   printf("\n");
+   }
+   }
+
+   return 0;
+}
+
+int timed_vibration(struct udevice *dev, int duration_ms)
+{
+   int ret;
+
+   ret = vibrator_set_state(dev, VIBRATOR_STATE_ON);
+   if (ret < 0) {
+   printf("Vibrator operation failed (err=%d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   udelay(duration_ms * 1000);
+
+   ret = vibrator_set_state(dev, VIBRATOR_STATE_OFF);
+   if (ret < 0) {
+   printf("Vibrator operation failed (err=%d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+int do_vibrator(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+   enum vibrator_state_t cmd;
+   const char *vibrator_label;
+   struct udevice *dev;
+   int ret;
+   int duration_ms = 0;
+
+   /* Validate arguments */
+   if (argc < 2)
+   return CMD_RET_USAGE;
+   vibrator_label = argv[1];
+   if (strncmp(vibrator_label, "list", 4) == 0)
+   return list_vibrators();
+
+   cmd = argc > 2 ? get_vibrator_cmd(argv[2]) : VIBRATOR_STATE_COUNT;
+   ret = vibrator_get_by_label(vibrator_label, &dev);
+   if (ret) {
+   printf("Vibrator '%s' not found (err=%d)\n", vibrator_label, 
ret);
+   return CMD_RET_FAILURE;
+   }
+
+   if (strncmp(argv[2], "timed", 5) == 0) {
+   if (argc < 4)
+   return CMD_RET_USAGE;
+   duration_ms = dectoul(argv[3], NULL);
+
+   return timed_vibration(dev, duration_ms);
+   

[PATCH 4/4] pinephone_defconfig: Add gpio vibrator support

2021-12-22 Thread Samuel Dionne-Riel
Signed-off-by: Samuel Dionne-Riel 
Cc: Samuel Holland 
---
 configs/pinephone_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/pinephone_defconfig b/configs/pinephone_defconfig
index 9d39204a43..72aaa4ea94 100644
--- a/configs/pinephone_defconfig
+++ b/configs/pinephone_defconfig
@@ -16,3 +16,5 @@ CONFIG_LED_STATUS_GPIO=y
 CONFIG_LED_STATUS0=y
 CONFIG_LED_STATUS_BIT=114
 CONFIG_LED_STATUS_STATE=2
+CONFIG_VIBRATOR=y
+CONFIG_VIBRATOR_GPIO=y
-- 
2.34.0



[PATCH 1/4] drivers: Introduce vibrator uclass

2021-12-22 Thread Samuel Dionne-Riel
Signed-off-by: Samuel Dionne-Riel 
---
 arch/sandbox/dts/test.dts  | 10 +++
 configs/sandbox_defconfig  |  2 +
 drivers/Kconfig|  2 +
 drivers/Makefile   |  1 +
 drivers/vibrator/Kconfig   | 21 +++
 drivers/vibrator/Makefile  |  5 ++
 drivers/vibrator/vibrator-uclass.c | 62 +++
 include/dm/uclass-id.h |  1 +
 include/vibrator.h | 87 +++
 test/dm/Makefile   |  1 +
 test/dm/vibrator.c | 97 ++
 11 files changed, 289 insertions(+)
 create mode 100644 drivers/vibrator/Kconfig
 create mode 100644 drivers/vibrator/Makefile
 create mode 100644 drivers/vibrator/vibrator-uclass.c
 create mode 100644 include/vibrator.h
 create mode 100644 test/dm/vibrator.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 2cea4a43c8..3633b8fb9f 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1608,6 +1608,16 @@
compatible = "sandbox,regmap_test";
};
};
+
+   vibrator_left {
+   compatible = "gpio-vibrator";
+   enable-gpios = <&gpio_a 1 0 GPIO_ACTIVE_HIGH>;
+   };
+
+   vibrator_right {
+   compatible = "gpio-vibrator";
+   enable-gpios = <&gpio_a 2 0 GPIO_ACTIVE_HIGH>;
+   };
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index c390afe9de..43f9972178 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -273,6 +273,8 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_USB_ETHER=y
 CONFIG_USB_ETH_CDC=y
+CONFIG_VIBRATOR=y
+CONFIG_VIBRATOR_GPIO=y
 CONFIG_DM_VIDEO=y
 CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_ROTATION=y
diff --git a/drivers/Kconfig b/drivers/Kconfig
index b26ca8cf70..a15674f22c 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -134,6 +134,8 @@ source "drivers/usb/Kconfig"
 
 source "drivers/ufs/Kconfig"
 
+source "drivers/vibrator/Kconfig"
+
 source "drivers/video/Kconfig"
 
 source "drivers/virtio/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 4e7cf28440..2290d4a5d8 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_$(SPL_TPL_)RTC) += rtc/
 obj-$(CONFIG_$(SPL_TPL_)SERIAL) += serial/
 obj-$(CONFIG_$(SPL_TPL_)SPI) += spi/
 obj-$(CONFIG_$(SPL_TPL_)TIMER) += timer/
+obj-$(CONFIG_$(SPL_TPL_)VIBRATOR) += vibrator/
 obj-$(CONFIG_$(SPL_TPL_)VIRTIO) += virtio/
 obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/
 obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/
diff --git a/drivers/vibrator/Kconfig b/drivers/vibrator/Kconfig
new file mode 100644
index 00..f988aa63b9
--- /dev/null
+++ b/drivers/vibrator/Kconfig
@@ -0,0 +1,21 @@
+menu "Vibrator Feedback Support"
+
+config VIBRATOR
+   bool "Enable vibration motor support"
+   depends on DM
+   help
+ Many boards have vibration motorss which can be used to signal status 
or
+ alerts. U-Boot provides a uclass API to implement this feature. 
Vibration
+ motor drivers can provide access to board-specific vibration motors. 
Use
+ of the device tree for configuration is encouraged.
+
+config SPL_VIBRATOR
+   bool "Enable vibration motor support in SPL"
+   depends on SPL && SPL_DM
+   help
+ The vibration motor subsystem adds a small amount of overhead to the 
image.
+ If this is acceptable and you have a need to use vibration motors in 
SPL,
+ enable this option. You will need to enable device tree in SPL
+ for this to work.
+
+endmenu
diff --git a/drivers/vibrator/Makefile b/drivers/vibrator/Makefile
new file mode 100644
index 00..326838ff7a
--- /dev/null
+++ b/drivers/vibrator/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2021 Samuel Dionne-Riel 
+
+obj-y += vibrator-uclass.o
diff --git a/drivers/vibrator/vibrator-uclass.c 
b/drivers/vibrator/vibrator-uclass.c
new file mode 100644
index 00..ffb6522a19
--- /dev/null
+++ b/drivers/vibrator/vibrator-uclass.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Samuel Dionne-Riel 
+ * Copyright (c) 2015 Google, Inc
+ * Largely derived from `drivers/led/led-uclass.c`
+ * Original written by Simon Glass 
+ */
+
+#define LOG_CATEGORY UCLASS_VIBRATOR
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int vibrator_get_by_label(const char *label, struct udevice **devp)
+{
+   struct udevice *dev;
+   struct uclass *uc;
+   int ret;
+
+   ret = uclass_get(UCLASS_VIBRATOR, &uc);
+   if (ret)
+   return ret;
+   uclass_foreach_dev(dev, uc) {
+   struct vibrator

[PATCH 2/4] vibrator: Add vibrator_gpio driver

2021-12-22 Thread Samuel Dionne-Riel
Signed-off-by: Samuel Dionne-Riel 
---
 drivers/vibrator/Kconfig |  16 
 drivers/vibrator/Makefile|   1 +
 drivers/vibrator/vibrator_gpio.c | 122 +++
 3 files changed, 139 insertions(+)
 create mode 100644 drivers/vibrator/vibrator_gpio.c

diff --git a/drivers/vibrator/Kconfig b/drivers/vibrator/Kconfig
index f988aa63b9..88e84ffb6c 100644
--- a/drivers/vibrator/Kconfig
+++ b/drivers/vibrator/Kconfig
@@ -18,4 +18,20 @@ config SPL_VIBRATOR
  enable this option. You will need to enable device tree in SPL
  for this to work.
 
+config VIBRATOR_GPIO
+   bool "VIBRATOR support for GPIO-connected VIBRATORs"
+   depends on VIBRATOR && DM_GPIO
+   help
+ Enable support for vibration motors which are connected to GPIO lines.
+ These GPIOs may be on the SoC or some other device which provides 
GPIOs.
+ The GPIO driver must used driver model. vibration motors are 
configured
+ using the device tree.
+
+config SPL_VIBRATOR_GPIO
+   bool "Vibration motor support for GPIO-connected vibration motors in 
SPL"
+depends on SPL_VIBRATOR && DM_GPIO
+   help
+ This option is an SPL-variant of the VIBRATOR_GPIO option.
+ See the help of VIBRATOR_GPIO for details.
+
 endmenu
diff --git a/drivers/vibrator/Makefile b/drivers/vibrator/Makefile
index 326838ff7a..cc5fc14fbf 100644
--- a/drivers/vibrator/Makefile
+++ b/drivers/vibrator/Makefile
@@ -3,3 +3,4 @@
 # Copyright (c) 2021 Samuel Dionne-Riel 
 
 obj-y += vibrator-uclass.o
+obj-$(CONFIG_$(SPL_)VIBRATOR_GPIO) += vibrator_gpio.o
diff --git a/drivers/vibrator/vibrator_gpio.c b/drivers/vibrator/vibrator_gpio.c
new file mode 100644
index 00..95648a7231
--- /dev/null
+++ b/drivers/vibrator/vibrator_gpio.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Samuel Dionne-Riel 
+ * Copyright (c) 2015 Google, Inc
+ * Largely derived from `drivers/led/led_gpio.c`
+ * Original written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct vibrator_gpio_priv {
+   struct gpio_desc gpio;
+};
+
+static int gpio_vibrator_set_state(struct udevice *dev, enum vibrator_state_t 
state)
+{
+   struct vibrator_gpio_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if (!dm_gpio_is_valid(&priv->gpio))
+   return -EREMOTEIO;
+   switch (state) {
+   case VIBRATOR_STATE_OFF:
+   case VIBRATOR_STATE_ON:
+   break;
+   case VIBRATOR_STATE_TOGGLE:
+   ret = dm_gpio_get_value(&priv->gpio);
+   if (ret < 0)
+   return ret;
+   state = !ret;
+   break;
+   default:
+   return -ENOSYS;
+   }
+
+   return dm_gpio_set_value(&priv->gpio, state);
+}
+
+static enum vibrator_state_t gpio_vibrator_get_state(struct udevice *dev)
+{
+   struct vibrator_gpio_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if (!dm_gpio_is_valid(&priv->gpio))
+   return -EREMOTEIO;
+   ret = dm_gpio_get_value(&priv->gpio);
+   if (ret < 0)
+   return ret;
+
+   return ret ? VIBRATOR_STATE_ON : VIBRATOR_STATE_OFF;
+}
+
+static int vibrator_gpio_probe(struct udevice *dev)
+{
+   struct vibrator_gpio_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->gpio, 
GPIOD_IS_OUT);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static int vibrator_gpio_remove(struct udevice *dev)
+{
+   /*
+* The GPIO driver may have already been removed. We will need to
+* address this more generally.
+*/
+   if (!IS_ENABLED(CONFIG_SANDBOX)) {
+   struct vibrator_gpio_priv *priv = dev_get_priv(dev);
+
+   if (dm_gpio_is_valid(&priv->gpio))
+   dm_gpio_free(dev, &priv->gpio);
+   }
+
+   return 0;
+}
+
+static int vibrator_gpio_bind(struct udevice *dev)
+{
+   ofnode node;
+   struct vibrator_uc_plat *uc_plat;
+   const char *label;
+
+   node = dev_ofnode(dev);
+   label = ofnode_get_name(node);
+
+   uc_plat = dev_get_uclass_plat(dev);
+   uc_plat->label = label;
+
+   return 0;
+}
+
+static const struct vibrator_ops gpio_vibrator_ops = {
+   .set_state  = gpio_vibrator_set_state,
+   .get_state  = gpio_vibrator_get_state,
+};
+
+static const struct udevice_id vibrator_gpio_ids[] = {
+   { .compatible = "gpio-vibrator" },
+   { }
+};
+
+U_BOOT_DRIVER(vibrator_gpio) = {
+   .name   = "gpio_vibrator",
+   .id = UCLASS_VIBRATOR,
+   .of_match = vibrator_gpio_ids,
+   .ops= &gpio_vibrator_ops,
+   .priv_auto  = sizeof(struct v

[PATCH 0/4] Add vibration motor support to U-Boot

2021-12-22 Thread Samuel Dionne-Riel
This series of patch adds support for vibration motors (often called
vibrators) to U-Boot.

The support adds the necessary plumbing to support SPL usage of
vibration motors. This can be used to vibrate the device, like a phone,
as early as possible during the boot process.

A `vibrator` command allows scripts, or customised boot commands, to
vibrate the device. This can be used to provide feedback to the end-user
about failure state, or boot stage.

An example use case of the command is, in a customized boot command, to
signify that an error happend, by synchronizing red LED flashes with a
few short vibrations.

Samuel Dionne-Riel (4):
  drivers: Introduce vibrator uclass
  vibrator: Add vibrator_gpio driver
  cmd: Add vibrator command
  pinephone_defconfig: Add gpio vibrator support

 arch/sandbox/dts/test.dts  |  10 ++
 cmd/Kconfig|  10 ++
 cmd/Makefile   |   1 +
 cmd/vibrator.c | 148 +
 configs/pinephone_defconfig|   2 +
 configs/sandbox_defconfig  |   2 +
 drivers/Kconfig|   2 +
 drivers/Makefile   |   1 +
 drivers/vibrator/Kconfig   |  37 
 drivers/vibrator/Makefile  |   6 ++
 drivers/vibrator/vibrator-uclass.c |  62 
 drivers/vibrator/vibrator_gpio.c   | 122 
 include/dm/uclass-id.h |   1 +
 include/vibrator.h |  87 +
 test/dm/Makefile   |   1 +
 test/dm/vibrator.c |  97 +++
 16 files changed, 589 insertions(+)
 create mode 100644 cmd/vibrator.c
 create mode 100644 drivers/vibrator/Kconfig
 create mode 100644 drivers/vibrator/Makefile
 create mode 100644 drivers/vibrator/vibrator-uclass.c
 create mode 100644 drivers/vibrator/vibrator_gpio.c
 create mode 100644 include/vibrator.h
 create mode 100644 test/dm/vibrator.c

-- 
2.34.0



[PATCH] cmd: Add pause command

2021-12-20 Thread Samuel Dionne-Riel
This command is being introduced with the goal of allowing user-friendly
"generic use case" U-Boot builds to pause until user input under some
situations.

The main use case would be when a boot failure happens, to pause until
the user has had time to acknowledge the current state.

Signed-off-by: Samuel Dionne-Riel 
---
 cmd/Kconfig  |  7 +++
 cmd/Makefile |  1 +
 cmd/pause.c  | 35 +++
 3 files changed, 43 insertions(+)
 create mode 100644 cmd/pause.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5b30b13e43..26d5707f75 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1807,6 +1807,13 @@ config CMD_GETTIME
  milliseconds. See also the 'bootstage' command which provides more
  flexibility for boot timing.
 
+config CMD_PAUSE
+   bool "pause command"
+   default y
+   help
+ Delay execution waiting for any user input.
+ Useful to allow the user to read a failure log.
+
 config CMD_RNG
bool "rng command"
depends on DM_RNG
diff --git a/cmd/Makefile b/cmd/Makefile
index 891819ae0f..6c4db4ed2e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -98,6 +98,7 @@ obj-$(CONFIG_CMD_MFSL) += mfsl.o
 obj-$(CONFIG_CMD_MII) += mii.o
 obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MDIO) += mdio.o
+obj-$(CONFIG_CMD_PAUSE) += pause.o
 obj-$(CONFIG_CMD_SLEEP) += sleep.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
diff --git a/cmd/pause.c b/cmd/pause.c
new file mode 100644
index 00..0a7ea35ebe
--- /dev/null
+++ b/cmd/pause.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021
+ * Samuel Dionne-Riel 
+ */
+
+#include 
+#include 
+
+static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   char *message = "Press any key to continue...";
+
+   if (argc > 2)
+   return CMD_RET_USAGE;
+
+   if (argc == 2)
+   message = argv[1];
+
+   /* No newline, so it sticks to the bottom of the screen */
+   printf("%s", message);
+
+   /* Wait on "any" key... */
+   (void) getchar();
+
+   /* Since there was no newline, we need it now. */
+   printf("\n");
+
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(pause, 2, 1, do_pause,
+   "delay until user input",
+   "pause [prompt] - Wait until users presses any key. [prompt] can be 
used to customize the message.\n"
+);
-- 
2.34.0



-- 
Samuel Dionne-Riel


[PATCH] cmd: env: Add `indirect` to indirectly set values

2021-12-20 Thread Samuel Dionne-Riel
This allows an ergonomic-enough approximation of ${!variable} expansion.
This could be used the following way:

```
for target in ${boot_targets}; do
   env indirect target_name target_name_${target}
   # ...
done
```

Assuming `target_name_mmc0` and similar are set appropriately.

A default value can be optionally provided.

Note: this acts on environment variables, not hush variables.

Signed-off-by: Samuel Dionne-Riel 
Cc: Simon Glass 
Cc: "Marek Behún" 
---
 cmd/Kconfig  |  4 
 cmd/nvedit.c | 45 +
 2 files changed, 49 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 26d5707f75..e538e69a11 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -508,6 +508,10 @@ config CMD_NVEDIT_EFI
  If enabled, we are allowed to set/print UEFI variables using
  "env" command with "-e" option without knowing details.
 
+config CMD_NVEDIT_INDIRECT
+   bool "env indirect - Sets environment value from another"
+   default y
+
 config CMD_NVEDIT_INFO
bool "env info - print or evaluate environment information"
help
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 3bb6e764c0..53e6b57b60 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1018,6 +1018,45 @@ sep_err:
 }
 #endif
 
+#if defined(CONFIG_CMD_NVEDIT_INDIRECT)
+static int do_env_indirect(struct cmd_tbl *cmdtp, int flag,
+  int argc, char *const argv[])
+{
+   char *to = argv[1];
+   char *from = argv[2];
+   char *default_value = NULL;
+   int ret = 0;
+
+   if (argc < 3 || argc > 4) {
+   return CMD_RET_USAGE;
+   }
+
+   if (argc == 4) {
+   default_value = argv[3];
+   }
+
+   if (env_get(from) == NULL && default_value == NULL) {
+   printf("## env indirect: Environment variable for  (%s) 
does not exist.\n", from);
+
+   return CMD_RET_FAILURE;
+   }
+
+   if (env_get(from) == NULL) {
+   ret = env_set(to, default_value);
+   }
+   else {
+   ret = env_set(to, env_get(from));
+   }
+
+   if (ret == 0) {
+   return CMD_RET_SUCCESS;
+   }
+   else {
+   return CMD_RET_FAILURE;
+   }
+}
+#endif
+
 #if defined(CONFIG_CMD_NVEDIT_INFO)
 /*
  * print_env_info - print environment information
@@ -1181,6 +1220,9 @@ static struct cmd_tbl cmd_env_sub[] = {
 #if defined(CONFIG_CMD_IMPORTENV)
U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
 #endif
+#if defined(CONFIG_CMD_NVEDIT_INDIRECT)
+   U_BOOT_CMD_MKENT(indirect, 3, 0, do_env_indirect, "", ""),
+#endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""),
 #endif
@@ -1265,6 +1307,9 @@ static char env_help_text[] =
 #if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import 
environment\n"
 #endif
+#if defined(CONFIG_CMD_NVEDIT_INDIRECT)
+   "env indirect   [default] - sets  to the value of , 
using [default] when unset\n"
+#endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
    "env info - display environment information\n"
"env info [-d] [-p] [-q] - evaluate environment information\n"
-- 
2.34.0



-- 
Samuel Dionne-Riel


[PATCH] cmd: adc: Report return value on error

2021-12-20 Thread Samuel Dionne-Riel
Reporting the return value should always be done on error conditions,
this way the developer can start debugging issues with more knowledge
in-hand.

Signed-off-by: Samuel Dionne-Riel 
---
 cmd/adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/adc.c b/cmd/adc.c
index 16f914a030..75739bc8ee 100644
--- a/cmd/adc.c
+++ b/cmd/adc.c
@@ -81,8 +81,8 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int 
argc,
ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0),
  &data);
if (ret) {
-   printf("Error getting single shot for device %s channel %s\n",
-  argv[1], argv[2]);
+   printf("Error getting single shot for device %s channel %s 
(ret=%d)\n",
+  argv[1], argv[2], ret);
return CMD_RET_FAILURE;
    }
 
-- 
2.34.0



-- 
Samuel Dionne-Riel


[PATCH] lib: export vsscanf

2021-12-20 Thread Samuel Dionne-Riel
The function was missing from exports, even though it loooks like the
intent of the implementation in sscanf.c was to have it exported.

Signed-off-by: Samuel Dionne-Riel 
Cc: Simon Glass 
---

This is needed for porting an external library to U-Boot, in WIP
changes. It builds with a warning, and does link since the symbol is
present. Though when treating warnings as errors during development, it
becomes an issue.

 include/vsprintf.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index b474630146..8bfafa0d33 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -307,6 +307,14 @@ char *strmhz(char *buf, unsigned long hz);
  */
 void str_to_upper(const char *in, char *out, size_t len);
 
+/**
+ * vsscanf - Unformat a buffer into a list of arguments
+ * @buf:   input buffer
+ * @fmt:   format of buffer
+ * @args:  arguments
+ */
+int vsscanf(const char *inp, char const *fmt0, va_list ap);
+
 /**
  * sscanf - Unformat a buffer into a list of arguments
  * @buf:   input buffer
-- 
2.34.0



-- 
Samuel Dionne-Riel


[PATCH] tools: fdtgrep: Use unsigned chars for arrays

2021-02-10 Thread Samuel Dionne-Riel
Otherwise, values over 127 end up prefixed with ff.

Signed-off-by: Samuel Dionne-Riel 
Cc: Simon Glass 
---

Minimal reproduction:

```
// repro.dts
/dts-v1/;

/ {
ra = [ 7f ];
rb = [ 80 ];
};
```

Steps used to compile:

 $ dtc repro.dts > repro.dtb

Without the fix:

 $ fdtgrep --include-node / repro.dtb
/ {
ra = [7f];
rb = [ff80];
};

With the fix:

 $ fdtgrep --include-node / repro.dtb
/ {
ra = [7f];
rb = [80];
};

---

 tools/fdtgrep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
index e4112b8f69..db512465db 100644
--- a/tools/fdtgrep.c
+++ b/tools/fdtgrep.c
@@ -213,7 +213,7 @@ static void utilfdt_print_data(const char *data, int len)
} else {
printf(" = [");
for (i = 0; i < len; i++)
-   printf("%02x%s", *p++, i < len - 1 ? " " : "");
+   printf("%02x%s", (unsigned char)*p++, i < len - 1 ? " " 
: "");
printf("]");
}
 }
-- 
2.29.2


[U-Boot] [PATCH v2] usb: Make USB_MUSB_PIO_ONLY selected by USB_MUSB_SUNXI

2019-11-28 Thread Samuel Dionne-Riel
This ensures the USB_MUSB_PIO_ONLY config is set to an apppropriate
value from the changes enabling USB_MUSB_GADGET does.

Namely, USB_MUSB_PIO_ONLY default to =y on USB_MUSB_SUNXI being y.

Signed-off-by: Samuel Dionne-Riel 

---

Changes in v2:
  - Use select as a reverse-dependency

As discussed on IRC with Marex,

Some additional context about the bug.

Using `make ..._defconfig` for a sunxi board, then using `make
menuconfig` to change the option `CONFIG_USB_MUSB_GADGET=y` causes
builds to fail. When the same option is set to `=y` via the defconfig
file, the option work. Follows the failure:

```
  CC  drivers/usb/musb-new/musb_gadget.o
drivers/usb/musb-new/musb_gadget.c: In function 'map_dma_buffer':
drivers/usb/musb-new/musb_gadget.c:103:26: warning: implicit declaration of 
function 'dma_map_single'; did you mean 'malloc_simple'? 
[-Wimplicit-function-declaration]
   request->request.dma = dma_map_single(
  ^~
  malloc_simple
drivers/usb/musb-new/musb_gadget.c:108:8: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'USB_DT_DEVICE'?
  ? DMA_TO_DEVICE
^
USB_DT_DEVICE
drivers/usb/musb-new/musb_gadget.c:108:8: note: each undeclared identifier is 
reported only once for each function it appears in
drivers/usb/musb-new/musb_gadget.c:109:8: error: 'DMA_FROM_DEVICE' undeclared 
(first use in this function); did you mean 'U_BOOT_DEVICE'?
  : DMA_FROM_DEVICE);
^~~
U_BOOT_DEVICE
drivers/usb/musb-new/musb_gadget.c:112:3: warning: implicit declaration of 
function 'dma_sync_single_for_device' [-Wimplicit-function-declaration]
   dma_sync_single_for_device(musb->controller,
   ^~
drivers/usb/musb-new/musb_gadget.c: In function 'unmap_dma_buffer':
drivers/usb/musb-new/musb_gadget.c:135:3: warning: implicit declaration of 
function 'dma_unmap_single' [-Wimplicit-function-declaration]
   dma_unmap_single(musb->controller,
   ^~~~
drivers/usb/musb-new/musb_gadget.c:139:7: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'USB_DT_DEVICE'?
 ? DMA_TO_DEVICE
   ^
   USB_DT_DEVICE
drivers/usb/musb-new/musb_gadget.c:140:7: error: 'DMA_FROM_DEVICE' undeclared 
(first use in this function); did you mean 'U_BOOT_DEVICE'?
 : DMA_FROM_DEVICE);
   ^~~
   U_BOOT_DEVICE
drivers/usb/musb-new/musb_gadget.c:143:3: warning: implicit declaration of 
function 'dma_sync_single_for_cpu' [-Wimplicit-function-declaration]
   dma_sync_single_for_cpu(musb->controller,
   ^~~
make[1]: *** [scripts/Makefile.build:279: drivers/usb/musb-new/musb_gadget.o] 
Error 1
```

By diffing the resulting configuration, Othe main difference found is
`CONFIG_USB_MUSB_PIO_ONLY` is not set when failing, and set to `=y`
when working. This was verified to be the missing option.

As far as I understand it in Kconfig, "is not set" basically marks the
option as using a negative "unset" value, and does not mean that it
will use the default value. This difference in meaning makes it so
that when toggling the option with `make menuconfig`, the option has
already been set to "is not set", and it does not change to its
default value.

The actual bug may be that there is a regression and the code should
work when this value is unset, in this case I do not know how to
provide the proper fix.

This fix corrects the issue by gating the option behind
`if USB_MUSB_HOST || USB_MUSB_GADGET`. To me, it looks like this was
the intention, in the initial patch, but might have been overlooked.
I assume so since the option was defined after the `if`, rather than
before, like the other options not gated behind the option.


 drivers/usb/musb-new/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig
index 79ad14ef66..d7754014e3 100644
--- a/drivers/usb/musb-new/Kconfig
+++ b/drivers/usb/musb-new/Kconfig
@@ -58,6 +58,7 @@ config USB_MUSB_PIC32
 config USB_MUSB_SUNXI
bool "Enable sunxi OTG / DRC USB controller"
depends on ARCH_SUNXI
+   select USB_MUSB_PIO_ONLY
default y
---help---
Say y here to enable support for the sunxi OTG / DRC USB controller
-- 
2.23.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] usb: Make USB_MUSB_PIO_ONLY conditional on USB_MUSB_{HOST, GADGET}

2019-11-22 Thread Samuel Dionne-Riel
This ensures the USB_MUSB_PIO_ONLY config is set to an apppropriate
default values from the changes enabling USB_MUSB_GADGET does.

Namely, USB_MUSB_PIO_ONLY default to =y on USB_MUSB_SUNXI being y.
Since USB_MUSB_SUNXI is behind the conditional, the option does not
exist when using make ..._defconfig, thus the default of
USB_MUSB_PIO_ONLY is kept "# ... is not set". This, _is_
counter-intuitively a set value, meaning that the default will not be
applied once USB_MUSB_SUNXI is set to y by toggling USB_MUSB_GADGET
via menuconfig.

Signed-off-by: Samuel Dionne-Riel 

---
Some additional context about the bug.

Using `make ..._defconfig` for a sunxi board, then using `make
menuconfig` to change the option `CONFIG_USB_MUSB_GADGET=y` causes
builds to fail. When the same option is set to `=y` via the defconfig
file, the option work. Follows the failure:

```
  CC  drivers/usb/musb-new/musb_gadget.o
drivers/usb/musb-new/musb_gadget.c: In function 'map_dma_buffer':
drivers/usb/musb-new/musb_gadget.c:103:26: warning: implicit declaration of 
function 'dma_map_single'; did you mean 'malloc_simple'? 
[-Wimplicit-function-declaration]
   request->request.dma = dma_map_single(
  ^~
  malloc_simple
drivers/usb/musb-new/musb_gadget.c:108:8: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'USB_DT_DEVICE'?
  ? DMA_TO_DEVICE
^
USB_DT_DEVICE
drivers/usb/musb-new/musb_gadget.c:108:8: note: each undeclared identifier is 
reported only once for each function it appears in
drivers/usb/musb-new/musb_gadget.c:109:8: error: 'DMA_FROM_DEVICE' undeclared 
(first use in this function); did you mean 'U_BOOT_DEVICE'?
  : DMA_FROM_DEVICE);
^~~
U_BOOT_DEVICE
drivers/usb/musb-new/musb_gadget.c:112:3: warning: implicit declaration of 
function 'dma_sync_single_for_device' [-Wimplicit-function-declaration]
   dma_sync_single_for_device(musb->controller,
   ^~
drivers/usb/musb-new/musb_gadget.c: In function 'unmap_dma_buffer':
drivers/usb/musb-new/musb_gadget.c:135:3: warning: implicit declaration of 
function 'dma_unmap_single' [-Wimplicit-function-declaration]
   dma_unmap_single(musb->controller,
   ^~~~
drivers/usb/musb-new/musb_gadget.c:139:7: error: 'DMA_TO_DEVICE' undeclared 
(first use in this function); did you mean 'USB_DT_DEVICE'?
 ? DMA_TO_DEVICE
   ^
   USB_DT_DEVICE
drivers/usb/musb-new/musb_gadget.c:140:7: error: 'DMA_FROM_DEVICE' undeclared 
(first use in this function); did you mean 'U_BOOT_DEVICE'?
 : DMA_FROM_DEVICE);
   ^~~
   U_BOOT_DEVICE
drivers/usb/musb-new/musb_gadget.c:143:3: warning: implicit declaration of 
function 'dma_sync_single_for_cpu' [-Wimplicit-function-declaration]
   dma_sync_single_for_cpu(musb->controller,
   ^~~
make[1]: *** [scripts/Makefile.build:279: drivers/usb/musb-new/musb_gadget.o] 
Error 1
```

By diffing the resulting configuration, Othe main difference found is
`CONFIG_USB_MUSB_PIO_ONLY` is not set when failing, and set to `=y`
when working. This was verified to be the missing option.

As far as I understand it in Kconfig, "is not set" basically marks the
option as using a negative "unset" value, and does not mean that it
will use the default value. This difference in meaning makes it so
that when toggling the option with `make menuconfig`, the option has
already been set to "is not set", and it does not change to its
default value.

The actual bug may be that there is a regression and the code should
work when this value is unset, in this case I do not know how to
provide the proper fix.

This fix corrects the issue by gating the option behind
`if USB_MUSB_HOST || USB_MUSB_GADGET`. To me, it looks like this was
the intention, in the initial patch, but might have been overlooked.
I assume so since the option was defined after the `if`, rather than
before, like the other options not gated behind the option.


 drivers/usb/musb-new/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig
index 79ad14ef66..95499f1b17 100644
--- a/drivers/usb/musb-new/Kconfig
+++ b/drivers/usb/musb-new/Kconfig
@@ -72,11 +72,11 @@ config USB_MUSB_DISABLE_BULK_COMBINE_SPLIT
  support it yet. Select this option to disable the feature until the
  driver adds the support.
 
-endif
-
 config USB_MUSB_PIO_ONLY
bool "Disable DMA (always use PIO)"
default y if USB_MUSB_AM35X || USB_MUSB_PIC32 || USB_MUSB_OMAP2PLUS || 
USB_MUSB_DSPS || USB_MUSB_SUNXI
help
  All data is copied between memory and FIFO by the CPU.
  DMA controllers are ignored.
+
+endif
-- 
2.23.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot