* [PATCH 0/9] ARM: boards: protonic-imx6: Updates
@ 2022-06-16 13:11 Robin van der Gracht
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
` (9 more replies)
0 siblings, 10 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Our USB FIT boot is now broken and we can no longer aquire the RFID I2C
eeprom chips we're using to store board serial and MAC address.
With this patchstack I'm proposing fusing the serial in the ocotp GP1
register as an alternative to the RFID eeprom and making the usb boot
sequence a boot entry to avoid the race condition we now have.
The patchstack also includes some minor fixes/changes I found during
implementation of the above.
- Robin
Robin van der Gracht (9):
ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
ARM: boards: protonic-imx6: Update comment to match a recent code
update
ARM: boards: protonic-imx6: Free allocated autoboot_timeout string
ARM: boards: protonic-imx6: Always free allocated alias string
ARM: boards: protonic-imx6: Remove unsused argument from
prt_imx6_usb_mount
ARM: boards: protonic-imx6: Register prt-usb boot entry
ARM: boards: protonic-imx6: Remove usb_delay from the priv struct
ARM: boards: protonic-imx6: Read serial and mac from fuses if
available
ARM: boards: protonic-imx6: Register serial_number parameter with
ocotp
arch/arm/boards/protonic-imx6/board.c | 215 +++++++++++++++++++-------
1 file changed, 159 insertions(+), 56 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 16:28 ` Oleksij Rempel
2022-06-16 13:11 ` [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update Robin van der Gracht
` (8 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
The usb check needs to be skipped unless both keys are pressed
simultaneously.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index cdbb8debe6..8f8a0c745e 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
gpio_direction_input(GPIO_KEY_F6);
gpio_direction_input(GPIO_KEY_CYCLE);
- if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
+ if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
priv->no_usb_check = 1;
return 0;
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-17 7:00 ` Sascha Hauer
2022-06-16 13:11 ` [PATCH 3/9] ARM: boards: protonic-imx6: Free allocated autoboot_timeout string Robin van der Gracht
` (7 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Fixes: 1e817b64bc45968320597344e6b05463edd9c5e5
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 8f8a0c745e..3116f3ac42 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -392,7 +392,7 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
else
priv->usb_delay = 1;
- /* the usb_delay value is used for poller_call_async() */
+ /* the usb_delay value is used for wq_queue_delayed_work() */
delay = basprintf("%d", priv->usb_delay);
ret = setenv("global.autoboot_timeout", delay);
if (ret)
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 3/9] ARM: boards: protonic-imx6: Free allocated autoboot_timeout string
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
2022-06-16 13:11 ` [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 4/9] ARM: boards: protonic-imx6: Always free allocated alias string Robin van der Gracht
` (6 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 3116f3ac42..76c26fe296 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -395,6 +395,7 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
/* the usb_delay value is used for wq_queue_delayed_work() */
delay = basprintf("%d", priv->usb_delay);
ret = setenv("global.autoboot_timeout", delay);
+ free(delay);
if (ret)
goto exit_env_init;
}
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 4/9] ARM: boards: protonic-imx6: Always free allocated alias string
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (2 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 3/9] ARM: boards: protonic-imx6: Free allocated autoboot_timeout string Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 5/9] ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount Robin van der Gracht
` (5 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
The memory required to store the string needs to be freed on success
as well since it's no longer used.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 76c26fe296..7978553cb8 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -681,24 +681,22 @@ static int prt_imx6_rfid_fixup(struct prt_imx6_priv *priv,
}
i2c_node = of_find_node_by_alias(root, alias);
+ kfree(alias);
if (!i2c_node) {
dev_err(priv->dev, "Unsupported i2c adapter\n");
- ret = -ENODEV;
- goto free_alias;
+ return -ENODEV;
}
eeprom_node_name = basprintf("/eeprom@%x", dcfg->i2c_addr);
if (!eeprom_node_name) {
- ret = -ENOMEM;
- goto free_alias;
+ return -ENOMEM;
}
node = of_create_node(i2c_node, eeprom_node_name);
if (!node) {
dev_err(priv->dev, "Failed to create node %s\n",
eeprom_node_name);
- ret = -ENOMEM;
- goto free_eeprom;
+ return -ENOMEM;
}
ret = of_property_write_string(node, "compatible", "atmel,24c256");
@@ -722,8 +720,6 @@ static int prt_imx6_rfid_fixup(struct prt_imx6_priv *priv,
return 0;
free_eeprom:
kfree(eeprom_node_name);
-free_alias:
- kfree(alias);
exit_error:
dev_err(priv->dev, "Failed to apply fixup: %pe\n", ERR_PTR(ret));
return ret;
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 5/9] ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (3 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 4/9] ARM: boards: protonic-imx6: Always free allocated alias string Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 6/9] ARM: boards: protonic-imx6: Register prt-usb boot entry Robin van der Gracht
` (4 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Removing this unused pointer pointer relieves the caller from freeing the
memory afterwards.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 7978553cb8..e67d8d2f3b 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -248,7 +248,7 @@ static int prt_imx6_read_i2c_mac_serial(struct prt_imx6_priv *priv)
return 0;
}
-static int prt_imx6_usb_mount(struct prt_imx6_priv *priv, char **usbdisk)
+static int prt_imx6_usb_mount(struct prt_imx6_priv *priv)
{
struct device_d *dev = priv->dev;
const char *path;
@@ -267,8 +267,6 @@ static int prt_imx6_usb_mount(struct prt_imx6_priv *priv, char **usbdisk)
ret = mount(path, NULL, "usb", NULL);
if (ret)
goto exit_usb_mount;
-
- *usbdisk = strdup("disk0.0");
return 0;
}
@@ -278,8 +276,6 @@ static int prt_imx6_usb_mount(struct prt_imx6_priv *priv, char **usbdisk)
ret = mount(path, NULL, "usb", NULL);
if (ret)
goto exit_usb_mount;
-
- *usbdisk = strdup("disk0");
return 0;
}
@@ -294,7 +290,7 @@ static void prt_imx6_check_usb_boot_do_work(struct work_struct *w)
{
struct prt_imx6_priv *priv = container_of(w, struct prt_imx6_priv, work);
struct device_d *dev = priv->dev;
- char *second_word, *bootsrc, *usbdisk;
+ char *second_word, *bootsrc;
char buf[sizeof("vicut1q recovery")] = {};
unsigned int v;
ssize_t size;
@@ -306,7 +302,7 @@ static void prt_imx6_check_usb_boot_do_work(struct work_struct *w)
usb_rescan();
- ret = prt_imx6_usb_mount(priv, &usbdisk);
+ ret = prt_imx6_usb_mount(priv);
if (ret)
return;
@@ -363,12 +359,10 @@ static void prt_imx6_check_usb_boot_do_work(struct work_struct *w)
if (ret)
goto exit_usb_boot;
- free(usbdisk);
return;
exit_usb_boot:
dev_err(dev, "Failed to run usb boot: %s\n", strerror(-ret));
- free(usbdisk);
return;
}
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 6/9] ARM: boards: protonic-imx6: Register prt-usb boot entry
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (4 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 5/9] ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 7/9] ARM: boards: protonic-imx6: Remove usb_delay from the priv struct Robin van der Gracht
` (3 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
The worker that polls for a bootable usb device and the first boot.default
target are executed at the same time (after usb_delay seconds). Since
inspecting the usb drive's contents takes some time it loses the race
breaking usb boot.
If we make the usb boot routine a boot entry and prepend it to boot.default
it will always run first when the autoboot timeout expires. If the usb boot
entry fails boot will just fallback to the next entry (i.e. bootchooser).
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 108 +++++++++++++++++++-------
1 file changed, 79 insertions(+), 29 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index e67d8d2f3b..2c4f323799 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -4,10 +4,13 @@
// SPDX-FileCopyrightText: 2020 Oleksij Rempel, Pengutronix
#include <bbu.h>
+#include <boot.h>
+#include <bootm.h>
#include <common.h>
#include <deep-probe.h>
#include <environment.h>
#include <fcntl.h>
+#include <globalvar.h>
#include <gpio.h>
#include <i2c/i2c.h>
#include <mach/bbu.h>
@@ -21,7 +24,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <usb/usb.h>
-#include <work.h>
#define GPIO_HW_REV_ID {\
{IMX_GPIO_NR(2, 8), GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "rev_id0"}, \
@@ -88,8 +90,6 @@ struct prt_imx6_priv {
const char *name;
unsigned int usb_delay;
unsigned int no_usb_check;
- struct work_queue wq;
- struct work_struct work;
};
struct prti6q_rfid_contents {
@@ -286,25 +286,21 @@ exit_usb_mount:
#define OTG_PORTSC1 (MX6_OTG_BASE_ADDR+0x184)
-static void prt_imx6_check_usb_boot_do_work(struct work_struct *w)
+static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
{
- struct prt_imx6_priv *priv = container_of(w, struct prt_imx6_priv, work);
+ struct prt_imx6_priv *priv = prt_priv;
struct device_d *dev = priv->dev;
- char *second_word, *bootsrc;
+ char *second_word;
char buf[sizeof("vicut1q recovery")] = {};
- unsigned int v;
+ struct bootm_data bootm_data = {};
ssize_t size;
int fd, ret;
- v = readl(OTG_PORTSC1);
- if ((v & 0x0c00) == 0) /* LS == SE0 ==> nothing connected */
- return;
-
usb_rescan();
ret = prt_imx6_usb_mount(priv);
if (ret)
- return;
+ return ret;
fd = open("/usb/boot_target", O_RDONLY);
if (fd < 0) {
@@ -343,35 +339,90 @@ static void prt_imx6_check_usb_boot_do_work(struct work_struct *w)
goto exit_usb_boot;
}
+ bootm_data_init_defaults(&bootm_data);
+
second_word++;
if (strncmp(second_word, "usb", 3) == 0) {
- bootsrc = "usb";
+ dev_info(dev, "Booting from USB drive\n");
+ bootm_data.os_file = "/usb/linuximage.fit";
} else if (strncmp(second_word, "recovery", 8) == 0) {
- bootsrc = "recovery";
+ dev_info(dev, "Booting internal recovery OS\n");
+ bootm_data.os_file = "/dev/mmc2.5";
} else {
dev_err(dev, "Unknown boot target!\n");
ret = -ENODEV;
goto exit_usb_boot;
}
- dev_info(dev, "detected valid usb boot target file, overwriting boot to: %s\n", bootsrc);
- ret = setenv("global.boot.default", bootsrc);
+ ret = globalvar_add_simple("linux.bootargs.root",
+ "root=/dev/ram rw rootwait ramdisk_size=196608");
+ if (ret)
+ goto exit_usb_boot;
+
+ if (verbose)
+ bootm_data.verbose = verbose;
+ if (dryrun)
+ bootm_data.dryrun = dryrun;
+
+ ret = bootm_boot(&bootm_data);
if (ret)
goto exit_usb_boot;
- return;
+ return 0;
exit_usb_boot:
dev_err(dev, "Failed to run usb boot: %s\n", strerror(-ret));
- return;
+ return ret;
+}
+
+static void prt_imx6_bootentry_release(struct bootentry *entry)
+{
+ free(entry);
+}
+
+static int prt_imx6_bootentry_create(struct bootentries *bootentries, const char *name)
+{
+ struct bootentry *entry;
+
+ entry = xzalloc(sizeof(*entry));
+ if (!entry)
+ return -ENOMEM;
+
+ entry->me.type = MENU_ENTRY_NORMAL;
+ entry->release = prt_imx6_bootentry_release;
+ entry->boot = prt_imx6_usb_boot;
+ entry->title = xstrdup(name);
+ entry->description = xstrdup("Boot FIT image of a USB drive");
+ bootentries_add_entry(bootentries, entry);
+
+ return 0;
+}
+
+static int prt_imx6_bootentry_provider(struct bootentries *bootentries,
+ const char *name)
+{
+ int found = 0;
+ unsigned int v;
+
+ if (strncmp(name, "prt-usb", 7))
+ return found;
+
+ v = readl(OTG_PORTSC1);
+ if ((v & 0x0c00) == 0) /* No usb device detected */
+ return found;
+
+ if (!prt_imx6_bootentry_create(bootentries, name))
+ found = 1;
+
+ return found;
}
static int prt_imx6_env_init(struct prt_imx6_priv *priv)
{
const struct prt_machine_data *dcfg = priv->dcfg;
struct device_d *dev = priv->dev;
- char *delay, *bootsrc;
+ char *delay, *bootsrc, *boot_targets;
int ret;
ret = setenv("global.linux.bootargs.base", "consoleblank=0 vt.color=0x00");
@@ -399,7 +450,13 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
else
bootsrc = "mmc2";
- ret = setenv("global.boot.default", bootsrc);
+ if (!priv->no_usb_check)
+ boot_targets = xasprintf("prt-usb %s", bootsrc);
+ else
+ boot_targets = xstrdup(bootsrc);
+
+ ret = setenv("global.boot.default", boot_targets);
+ free(boot_targets);
if (ret)
goto exit_env_init;
@@ -468,16 +525,9 @@ static int prt_imx6_devices_init(void)
prt_imx6_read_i2c_mac_serial(priv);
- prt_imx6_env_init(priv);
+ bootentry_register_provider(prt_imx6_bootentry_provider);
- if (!priv->no_usb_check) {
- priv->wq.fn = prt_imx6_check_usb_boot_do_work;
-
- wq_register(&priv->wq);
-
- wq_queue_delayed_work(&priv->wq, &priv->work,
- priv->usb_delay * SECOND);
- }
+ prt_imx6_env_init(priv);
return 0;
}
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 7/9] ARM: boards: protonic-imx6: Remove usb_delay from the priv struct
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (5 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 6/9] ARM: boards: protonic-imx6: Register prt-usb boot entry Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 8/9] ARM: boards: protonic-imx6: Read serial and mac from fuses if available Robin van der Gracht
` (2 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
It's only used in one function right now.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 2c4f323799..95ec7be793 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -88,7 +88,6 @@ struct prt_imx6_priv {
unsigned int hw_id;
unsigned int hw_rev;
const char *name;
- unsigned int usb_delay;
unsigned int no_usb_check;
};
@@ -423,6 +422,7 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
const struct prt_machine_data *dcfg = priv->dcfg;
struct device_d *dev = priv->dev;
char *delay, *bootsrc, *boot_targets;
+ unsigned int autoboot_timeout;
int ret;
ret = setenv("global.linux.bootargs.base", "consoleblank=0 vt.color=0x00");
@@ -433,12 +433,11 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
set_autoboot_state(AUTOBOOT_BOOT);
} else {
if (dcfg->flags & PRT_IMX6_USB_LONG_DELAY)
- priv->usb_delay = 4;
+ autoboot_timeout = 4;
else
- priv->usb_delay = 1;
+ autoboot_timeout = 1;
- /* the usb_delay value is used for wq_queue_delayed_work() */
- delay = basprintf("%d", priv->usb_delay);
+ delay = basprintf("%d", autoboot_timeout);
ret = setenv("global.autoboot_timeout", delay);
free(delay);
if (ret)
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 8/9] ARM: boards: protonic-imx6: Read serial and mac from fuses if available
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (6 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 7/9] ARM: boards: protonic-imx6: Remove usb_delay from the priv struct Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 9/9] ARM: boards: protonic-imx6: Register serial_number parameter with ocotp Robin van der Gracht
2022-06-17 7:10 ` (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates Sascha Hauer
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Read board serial number from GP1 fuses if available and fall-back to the
i2c RFID eeprom (current method) otherwise.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 44 ++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 95ec7be793..dd2c041e07 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -15,6 +15,7 @@
#include <i2c/i2c.h>
#include <mach/bbu.h>
#include <mach/imx6.h>
+#include <mach/ocotp-fusemap.h>
#include <mfd/imx6q-iomuxc-gpr.h>
#include <mfd/syscon.h>
#include <net.h>
@@ -211,12 +212,11 @@ static int prt_imx6_set_mac(struct prt_imx6_priv *priv,
return 0;
}
-static int prt_imx6_set_serial(struct prt_imx6_priv *priv,
- struct prti6q_rfid_contents *rfid)
+static int prt_imx6_set_serial(struct prt_imx6_priv *priv, char *serial)
{
- rfid->serial[9] = 0; /* Failsafe */
- dev_info(priv->dev, "Serial number: %s\n", rfid->serial);
- barebox_set_serial_number(rfid->serial);
+ serial[9] = 0; /* Failsafe */
+ dev_info(priv->dev, "Serial number: %s\n", serial);
+ barebox_set_serial_number(serial);
return 0;
}
@@ -240,13 +240,36 @@ static int prt_imx6_read_i2c_mac_serial(struct prt_imx6_priv *priv)
if (ret)
return ret;
- ret = prt_imx6_set_serial(priv, &rfid);
+ ret = prt_imx6_set_serial(priv, rfid.serial);
if (ret)
return ret;
return 0;
}
+#define PRT_IMX6_GP1_FMT_DEC BIT(31)
+
+static int prt_imx6_read_ocotp_serial(struct prt_imx6_priv *priv)
+{
+ int ret;
+ char serial[11];
+ unsigned val;
+
+ ret = imx_ocotp_read_field(OCOTP_GP1, &val);
+ if (ret) {
+ dev_err(priv->dev, "Failed to read ocotp serial (%i)\n", ret);
+ return ret;
+ }
+
+ if (!(val & PRT_IMX6_GP1_FMT_DEC))
+ return -EINVAL;
+ val &= PRT_IMX6_GP1_FMT_DEC - 1;
+
+ snprintf(serial, sizeof(serial), "%u", val);
+
+ return prt_imx6_set_serial(priv, serial);
+}
+
static int prt_imx6_usb_mount(struct prt_imx6_priv *priv)
{
struct device_d *dev = priv->dev;
@@ -522,7 +545,14 @@ static int prt_imx6_devices_init(void)
prt_imx6_bbu(priv);
- prt_imx6_read_i2c_mac_serial(priv);
+ /*
+ * Read serial number from fuses. On success we'll assume the imx_ocotp
+ * driver takes care of providing the mac address if needed. On
+ * failure we'll fallback to reading and setting serial and mac from an
+ * attached RFID eeprom.
+ */
+ if (prt_imx6_read_ocotp_serial(priv) != 0)
+ prt_imx6_read_i2c_mac_serial(priv);
bootentry_register_provider(prt_imx6_bootentry_provider);
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 9/9] ARM: boards: protonic-imx6: Register serial_number parameter with ocotp
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (7 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 8/9] ARM: boards: protonic-imx6: Read serial and mac from fuses if available Robin van der Gracht
@ 2022-06-16 13:11 ` Robin van der Gracht
2022-06-17 7:10 ` (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates Sascha Hauer
9 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-16 13:11 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel, Robin van der Gracht, david
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
arch/arm/boards/protonic-imx6/board.c | 39 ++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index dd2c041e07..8436903fd8 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -90,6 +90,7 @@ struct prt_imx6_priv {
unsigned int hw_rev;
const char *name;
unsigned int no_usb_check;
+ char *ocotp_serial;
};
struct prti6q_rfid_contents {
@@ -252,7 +253,6 @@ static int prt_imx6_read_i2c_mac_serial(struct prt_imx6_priv *priv)
static int prt_imx6_read_ocotp_serial(struct prt_imx6_priv *priv)
{
int ret;
- char serial[11];
unsigned val;
ret = imx_ocotp_read_field(OCOTP_GP1, &val);
@@ -265,9 +265,31 @@ static int prt_imx6_read_ocotp_serial(struct prt_imx6_priv *priv)
return -EINVAL;
val &= PRT_IMX6_GP1_FMT_DEC - 1;
- snprintf(serial, sizeof(serial), "%u", val);
+ priv->ocotp_serial = xasprintf("%u", val);
- return prt_imx6_set_serial(priv, serial);
+ return prt_imx6_set_serial(priv, priv->ocotp_serial);
+}
+
+static int prt_imx6_set_ocotp_serial(struct param_d *param, void *driver_priv)
+{
+ struct prt_imx6_priv *priv = driver_priv;
+ int ret;
+ unsigned val;
+
+ ret = kstrtouint(priv->ocotp_serial, 10, &val);
+ if (ret)
+ return ret;
+
+ if (val & PRT_IMX6_GP1_FMT_DEC)
+ return -ERANGE;
+ val |= PRT_IMX6_GP1_FMT_DEC;
+
+ ret = imx_ocotp_write_field(OCOTP_GP1, val);
+ if (ret)
+ return ret;
+
+ barebox_set_serial_number(priv->ocotp_serial);
+ return 0;
}
static int prt_imx6_usb_mount(struct prt_imx6_priv *priv)
@@ -536,6 +558,8 @@ exit_bbu:
static int prt_imx6_devices_init(void)
{
struct prt_imx6_priv *priv = prt_priv;
+ struct device_d *ocotp_dev;
+ struct param_d *p;
if (!priv)
return 0;
@@ -558,6 +582,15 @@ static int prt_imx6_devices_init(void)
prt_imx6_env_init(priv);
+ ocotp_dev = get_device_by_name("ocotp0");
+ if (ocotp_dev) {
+ p = dev_add_param_string(ocotp_dev, "serial_number",
+ prt_imx6_set_ocotp_serial, NULL,
+ &priv->ocotp_serial, priv);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+ }
+
return 0;
}
late_initcall(prt_imx6_devices_init);
--
2.34.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
@ 2022-06-16 16:28 ` Oleksij Rempel
2022-06-16 16:38 ` Oleksij Rempel
0 siblings, 1 reply; 22+ messages in thread
From: Oleksij Rempel @ 2022-06-16 16:28 UTC (permalink / raw)
To: Robin van der Gracht; +Cc: barebox, david
Hi Robin,
On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
> The usb check needs to be skipped unless both keys are pressed
> simultaneously.
>
> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> ---
> arch/arm/boards/protonic-imx6/board.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index cdbb8debe6..8f8a0c745e 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
> gpio_direction_input(GPIO_KEY_F6);
> gpio_direction_input(GPIO_KEY_CYCLE);
>
> - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
> + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
> priv->no_usb_check = 1;
Hm, you probably wont:
if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
otherwise usb check will be always skipped.
Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-16 16:28 ` Oleksij Rempel
@ 2022-06-16 16:38 ` Oleksij Rempel
2022-06-17 6:57 ` Sascha Hauer
2022-06-20 6:48 ` Robin van der Gracht
0 siblings, 2 replies; 22+ messages in thread
From: Oleksij Rempel @ 2022-06-16 16:38 UTC (permalink / raw)
To: Oleksij Rempel, Robin van der Gracht; +Cc: barebox, david
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
> Hi Robin,
>
> On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
>> The usb check needs to be skipped unless both keys are pressed
>> simultaneously.
>>
>> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
>> ---
>> arch/arm/boards/protonic-imx6/board.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
>> index cdbb8debe6..8f8a0c745e 100644
>> --- a/arch/arm/boards/protonic-imx6/board.c
>> +++ b/arch/arm/boards/protonic-imx6/board.c
>> @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
>> gpio_direction_input(GPIO_KEY_F6);
>> gpio_direction_input(GPIO_KEY_CYCLE);
>>
>> - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
>> + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
>> priv->no_usb_check = 1;
>
> Hm, you probably wont:
> if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
>
> otherwise usb check will be always skipped.
Or, it is active low and your patch is correct :D
--
Regards,
Oleksij
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-16 16:38 ` Oleksij Rempel
@ 2022-06-17 6:57 ` Sascha Hauer
2022-06-17 8:44 ` Marco Felsch
2022-06-20 6:48 ` Robin van der Gracht
1 sibling, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2022-06-17 6:57 UTC (permalink / raw)
To: Oleksij Rempel; +Cc: Oleksij Rempel, Robin van der Gracht, barebox, david
On Thu, Jun 16, 2022 at 06:38:45PM +0200, Oleksij Rempel wrote:
> Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
> > Hi Robin,
> >
> > On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
> > > The usb check needs to be skipped unless both keys are pressed
> > > simultaneously.
> > >
> > > Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> > > ---
> > > arch/arm/boards/protonic-imx6/board.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> > > index cdbb8debe6..8f8a0c745e 100644
> > > --- a/arch/arm/boards/protonic-imx6/board.c
> > > +++ b/arch/arm/boards/protonic-imx6/board.c
> > > @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
> > > gpio_direction_input(GPIO_KEY_F6);
> > > gpio_direction_input(GPIO_KEY_CYCLE);
> > >
> > > - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
> > > + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
> > > priv->no_usb_check = 1;
> >
> > Hm, you probably wont:
> > if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
> >
> > otherwise usb check will be always skipped.
>
> Or, it is active low and your patch is correct :D
If they are, can we add a comment or _N suffix to the names?
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update
2022-06-16 13:11 ` [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update Robin van der Gracht
@ 2022-06-17 7:00 ` Sascha Hauer
2022-06-20 6:40 ` Robin van der Gracht
0 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2022-06-17 7:00 UTC (permalink / raw)
To: Robin van der Gracht; +Cc: barebox, david, Oleksij Rempel
On Thu, Jun 16, 2022 at 03:11:07PM +0200, Robin van der Gracht wrote:
> Fixes: 1e817b64bc45968320597344e6b05463edd9c5e5
We don't have this commit in mainline, could you reference the
corresponding upstream commit instead? Please write as
aabbccddeeff ("subject")
Sascha
>
> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> ---
> arch/arm/boards/protonic-imx6/board.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index 8f8a0c745e..3116f3ac42 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -392,7 +392,7 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
> else
> priv->usb_delay = 1;
>
> - /* the usb_delay value is used for poller_call_async() */
> + /* the usb_delay value is used for wq_queue_delayed_work() */
> delay = basprintf("%d", priv->usb_delay);
> ret = setenv("global.autoboot_timeout", delay);
> if (ret)
> --
> 2.34.1
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
` (8 preceding siblings ...)
2022-06-16 13:11 ` [PATCH 9/9] ARM: boards: protonic-imx6: Register serial_number parameter with ocotp Robin van der Gracht
@ 2022-06-17 7:10 ` Sascha Hauer
9 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2022-06-17 7:10 UTC (permalink / raw)
To: Robin van der Gracht; +Cc: barebox, david, Oleksij Rempel
On Thu, Jun 16, 2022 at 03:11:05PM +0200, Robin van der Gracht wrote:
> Our USB FIT boot is now broken and we can no longer aquire the RFID I2C
> eeprom chips we're using to store board serial and MAC address.
>
> With this patchstack I'm proposing fusing the serial in the ocotp GP1
> register as an alternative to the RFID eeprom and making the usb boot
> sequence a boot entry to avoid the race condition we now have.
>
> The patchstack also includes some minor fixes/changes I found during
> implementation of the above.
>
> - Robin
>
> Robin van der Gracht (9):
> ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
> ARM: boards: protonic-imx6: Update comment to match a recent code
> update
> ARM: boards: protonic-imx6: Free allocated autoboot_timeout string
> ARM: boards: protonic-imx6: Always free allocated alias string
> ARM: boards: protonic-imx6: Remove unsused argument from
> prt_imx6_usb_mount
> ARM: boards: protonic-imx6: Register prt-usb boot entry
> ARM: boards: protonic-imx6: Remove usb_delay from the priv struct
> ARM: boards: protonic-imx6: Read serial and mac from fuses if
> available
> ARM: boards: protonic-imx6: Register serial_number parameter with
> ocotp
Applied 3-9, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-17 6:57 ` Sascha Hauer
@ 2022-06-17 8:44 ` Marco Felsch
2022-06-20 7:51 ` Ahmad Fatoum
0 siblings, 1 reply; 22+ messages in thread
From: Marco Felsch @ 2022-06-17 8:44 UTC (permalink / raw)
To: Sascha Hauer
Cc: Oleksij Rempel, Oleksij Rempel, Robin van der Gracht, barebox, david
On 22-06-17, Sascha Hauer wrote:
> On Thu, Jun 16, 2022 at 06:38:45PM +0200, Oleksij Rempel wrote:
> > Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
> > > Hi Robin,
> > >
> > > On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
> > > > The usb check needs to be skipped unless both keys are pressed
> > > > simultaneously.
> > > >
> > > > Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> > > > ---
> > > > arch/arm/boards/protonic-imx6/board.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> > > > index cdbb8debe6..8f8a0c745e 100644
> > > > --- a/arch/arm/boards/protonic-imx6/board.c
> > > > +++ b/arch/arm/boards/protonic-imx6/board.c
> > > > @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
> > > > gpio_direction_input(GPIO_KEY_F6);
> > > > gpio_direction_input(GPIO_KEY_CYCLE);
> > > >
> > > > - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
> > > > + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
> > > > priv->no_usb_check = 1;
> > >
> > > Hm, you probably wont:
> > > if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
> > >
> > > otherwise usb check will be always skipped.
> >
> > Or, it is active low and your patch is correct :D
>
> If they are, can we add a comment or _N suffix to the names?
Does barebox not have gpiod? The board code just should check if it is
active or not. Whatever active means in this case.
Regards,
Marco
>
> Sascha
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update
2022-06-17 7:00 ` Sascha Hauer
@ 2022-06-20 6:40 ` Robin van der Gracht
0 siblings, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-20 6:40 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox, david, Oleksij Rempel
On 2022-06-17 09:00, Sascha Hauer wrote:
> On Thu, Jun 16, 2022 at 03:11:07PM +0200, Robin van der Gracht wrote:
>> Fixes: 1e817b64bc45968320597344e6b05463edd9c5e5
>
> We don't have this commit in mainline, could you reference the
> corresponding upstream commit instead? Please write as
> aabbccddeeff ("subject")
I must have mixed those up. The commit that my commit amends:
commit 8d4698e793d823590f050b36b26f67f73d5f9e85
Author: Oleksij Rempel <o.rempel@pengutronix.de>
Date: Mon Mar 28 14:09:56 2022 +0200
ARM: boards: protonic-imx6: fix file system access warning
We should not access a file system from the poller. So, do it from the
worker. This patch will fix warning on FS access for Protonic board
code.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link:
https://lore.barebox.org/20220328120956.2402132-1-o.rempel@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-16 16:38 ` Oleksij Rempel
2022-06-17 6:57 ` Sascha Hauer
@ 2022-06-20 6:48 ` Robin van der Gracht
2022-06-20 7:23 ` Oleksij Rempel
1 sibling, 1 reply; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-20 6:48 UTC (permalink / raw)
To: Oleksij Rempel; +Cc: Oleksij Rempel, barebox, david
On 2022-06-16 18:38, Oleksij Rempel wrote:
> Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
>> Hi Robin,
>>
>> On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
>>> The usb check needs to be skipped unless both keys are pressed
>>> simultaneously.
>>>
>>> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
>>> ---
>>> arch/arm/boards/protonic-imx6/board.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/arm/boards/protonic-imx6/board.c
>>> b/arch/arm/boards/protonic-imx6/board.c
>>> index cdbb8debe6..8f8a0c745e 100644
>>> --- a/arch/arm/boards/protonic-imx6/board.c
>>> +++ b/arch/arm/boards/protonic-imx6/board.c
>>> @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv
>>> *priv)
>>> gpio_direction_input(GPIO_KEY_F6);
>>> gpio_direction_input(GPIO_KEY_CYCLE);
>>>
>>> - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
>>> + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
>>> priv->no_usb_check = 1;
>>
>> Hm, you probably wont:
>> if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
>>
>> otherwise usb check will be always skipped.
>
> Or, it is active low and your patch is correct :D
They are active low. I mentoned that in the patch subject ;)
I want both keys pressed simultaniously as a requirement for the usb check
because it adds a delay (autoboot_timeout) to the boot process.
- Robin
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-20 6:48 ` Robin van der Gracht
@ 2022-06-20 7:23 ` Oleksij Rempel
0 siblings, 0 replies; 22+ messages in thread
From: Oleksij Rempel @ 2022-06-20 7:23 UTC (permalink / raw)
To: Robin van der Gracht; +Cc: Oleksij Rempel, barebox, david
On Mon, Jun 20, 2022 at 08:48:32AM +0200, Robin van der Gracht wrote:
> On 2022-06-16 18:38, Oleksij Rempel wrote:
> > Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
> > > Hi Robin,
> > >
> > > On Thu, Jun 16, 2022 at 03:11:06PM +0200, Robin van der Gracht wrote:
> > > > The usb check needs to be skipped unless both keys are pressed
> > > > simultaneously.
> > > >
> > > > Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> > > > ---
> > > > arch/arm/boards/protonic-imx6/board.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/arch/arm/boards/protonic-imx6/board.c
> > > > b/arch/arm/boards/protonic-imx6/board.c
> > > > index cdbb8debe6..8f8a0c745e 100644
> > > > --- a/arch/arm/boards/protonic-imx6/board.c
> > > > +++ b/arch/arm/boards/protonic-imx6/board.c
> > > > @@ -645,7 +645,7 @@ static int prt_imx6_init_prtvt7(struct
> > > > prt_imx6_priv *priv)
> > > > gpio_direction_input(GPIO_KEY_F6);
> > > > gpio_direction_input(GPIO_KEY_CYCLE);
> > > >
> > > > - if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
> > > > + if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
> > > > priv->no_usb_check = 1;
> > >
> > > Hm, you probably wont:
> > > if (!(gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6)))
> > >
> > > otherwise usb check will be always skipped.
> >
> > Or, it is active low and your patch is correct :D
>
> They are active low. I mentoned that in the patch subject ;)
> I want both keys pressed simultaniously as a requirement for the usb check
> because it adds a delay (autoboot_timeout) to the boot process.
Now you can see how important it is to have all needed info in the code,
not in the patch subject :)
Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-17 8:44 ` Marco Felsch
@ 2022-06-20 7:51 ` Ahmad Fatoum
2022-06-20 8:16 ` Robin van der Gracht
2022-06-20 15:42 ` Robin van der Gracht
0 siblings, 2 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2022-06-20 7:51 UTC (permalink / raw)
To: Marco Felsch, Sascha Hauer
Cc: Oleksij Rempel, Oleksij Rempel, Robin van der Gracht, barebox, david
Hello,
On 17.06.22 10:44, Marco Felsch wrote:
> On 22-06-17, Sascha Hauer wrote:
>>> Or, it is active low and your patch is correct :D
>>
>> If they are, can we add a comment or _N suffix to the names?
>
> Does barebox not have gpiod? The board code just should check if it is
> active or not. Whatever active means in this case.
There is gpiod_get(), but there's also gpio-keys support. See
drivers/input/specialkeys.c for an example on how to register an input
notifier.
Robin, did you test this works with barebox v2022.05.0?
I'd have assumed this to be broken by f349b662674e ("gpio: allocate dynamic
gpio numbers top down"). Especially, with deep probe, you can't and shouldn't
depend on GPIO expanders numbering being fixed. If you use an input notifier,
you should sidestep this issue altogether.
Cheers,
Ahmad
>
> Regards,
> Marco
>
>>
>> Sascha
>>
>> --
>> Pengutronix e.K. | |
>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>
>>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-20 7:51 ` Ahmad Fatoum
@ 2022-06-20 8:16 ` Robin van der Gracht
2022-06-20 15:42 ` Robin van der Gracht
1 sibling, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-20 8:16 UTC (permalink / raw)
To: Ahmad Fatoum
Cc: Marco Felsch, Sascha Hauer, Oleksij Rempel, Oleksij Rempel,
barebox, david
Hi Ahmand,
On 2022-06-20 09:51, Ahmad Fatoum wrote:
> Hello,
>
> On 17.06.22 10:44, Marco Felsch wrote:
>> On 22-06-17, Sascha Hauer wrote:
>>>> Or, it is active low and your patch is correct :D
>>>
>>> If they are, can we add a comment or _N suffix to the names?
>>
>> Does barebox not have gpiod? The board code just should check if it is
>> active or not. Whatever active means in this case.
>
> There is gpiod_get(), but there's also gpio-keys support. See
> drivers/input/specialkeys.c for an example on how to register an input
> notifier.
I dont think I can use gpiod_get() due to the device tree format for
gpio-keys. I didn't know about the input_notifier framework. I'll check
if I can get it to work with that as-well.
> Robin, did you test this works with barebox v2022.05.0?
> I'd have assumed this to be broken by f349b662674e ("gpio: allocate dynamic
> gpio numbers top down"). Especially, with deep probe, you can't and
> shouldn't
> depend on GPIO expanders numbering being fixed. If you use an input
> notifier,
> you should sidestep this issue altogether.
I just notiched that as well. I was just making some changes including the
feadback from this thread:
diff --git a/arch/arm/boards/protonic-imx6/board.c
b/arch/arm/boards/protonic-imx6/board.c
index cdbb8debe6..374ec11364 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -635,17 +635,24 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv
*priv)
return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
}
-#define GPIO_KEY_F6 (0xe0 + 5)
-#define GPIO_KEY_CYCLE (0xe0 + 2)
-
static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
{
- /* This function relies heavely on the gpio-pca9539 driver */
+ int gpio_f6, gpio_cycle;
+ struct device_d *gpio_expander;
+
+ gpio_expander = get_device_by_name("pca95390");
+ if (!gpio_expander) {
+ dev_err(priv->dev, "Can't find pca9539 gpio expander\n");
+ return -ENODEV;
+ }
+
+ gpio_cycle = gpio_get_num(gpio_expander, 2);
+ gpio_request_one(gpio_cycle, GPIOF_ACTIVE_LOW | GPIOF_DIR_IN,
"Cycle");
- gpio_direction_input(GPIO_KEY_F6);
- gpio_direction_input(GPIO_KEY_CYCLE);
+ gpio_f6 = gpio_get_num(gpio_expander, 5);
+ gpio_request_one(gpio_f6, GPIOF_ACTIVE_LOW | GPIOF_DIR_IN, "F6");
- if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
+ if (!(gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6)))
priv->no_usb_check = 1;
return 0;
I'll make a proposal with the input_notifier aswell.
- Robin
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
2022-06-20 7:51 ` Ahmad Fatoum
2022-06-20 8:16 ` Robin van der Gracht
@ 2022-06-20 15:42 ` Robin van der Gracht
1 sibling, 0 replies; 22+ messages in thread
From: Robin van der Gracht @ 2022-06-20 15:42 UTC (permalink / raw)
To: Ahmad Fatoum
Cc: Marco Felsch, Sascha Hauer, Oleksij Rempel, Oleksij Rempel,
barebox, david
Hello Ahmad,
On 2022-06-20 09:51, Ahmad Fatoum wrote:
> Hello,
>
> On 17.06.22 10:44, Marco Felsch wrote:
>> On 22-06-17, Sascha Hauer wrote:
>>>> Or, it is active low and your patch is correct :D
>>>
>>> If they are, can we add a comment or _N suffix to the names?
>>
>> Does barebox not have gpiod? The board code just should check if it is
>> active or not. Whatever active means in this case.
>
> There is gpiod_get(), but there's also gpio-keys support. See
> drivers/input/specialkeys.c for an example on how to register an input
> notifier.
I'm interested in two keys pressed at the same time. When I implement a
notifyer like in specialkeys.c I'll have to check if the other key is pressed
at that time as well.
I noticed that the input subsystem is already maintaining a bitmask with keys
pressed. If I tap into that, I can implement it like so:
diff --git a/arch/arm/boards/protonic-imx6/board.c
b/arch/arm/boards/protonic-imx6/board.c
index 8436903fd8..1e1a22ae8e 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -8,11 +8,13 @@
#include <bootm.h>
#include <common.h>
#include <deep-probe.h>
+#include <dt-bindings/input/linux-event-codes.h>
#include <environment.h>
#include <fcntl.h>
#include <globalvar.h>
#include <gpio.h>
#include <i2c/i2c.h>
+#include <input/input.h>
#include <mach/bbu.h>
#include <mach/imx6.h>
#include <mach/ocotp-fusemap.h>
@@ -742,17 +744,13 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv
*priv)
return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
}
-#define GPIO_KEY_F6 (0xe0 + 5)
-#define GPIO_KEY_CYCLE (0xe0 + 2)
-
static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
{
- /* This function relies heavely on the gpio-pca9539 driver */
+ unsigned long keys[BITS_TO_LONGS(KEY_CYCLEWINDOWS)];
- gpio_direction_input(GPIO_KEY_F6);
- gpio_direction_input(GPIO_KEY_CYCLE);
+ input_key_get_status(keys, KEY_CYCLEWINDOWS);
- if (gpio_get_value(GPIO_KEY_CYCLE) || gpio_get_value(GPIO_KEY_F6))
+ if (!(test_bit(KEY_CYCLEWINDOWS, keys) && test_bit(KEY_F6, keys)))
priv->no_usb_check = 1;
return 0;
- Robin
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2022-06-20 15:44 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 13:11 [PATCH 0/9] ARM: boards: protonic-imx6: Updates Robin van der Gracht
2022-06-16 13:11 ` [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low Robin van der Gracht
2022-06-16 16:28 ` Oleksij Rempel
2022-06-16 16:38 ` Oleksij Rempel
2022-06-17 6:57 ` Sascha Hauer
2022-06-17 8:44 ` Marco Felsch
2022-06-20 7:51 ` Ahmad Fatoum
2022-06-20 8:16 ` Robin van der Gracht
2022-06-20 15:42 ` Robin van der Gracht
2022-06-20 6:48 ` Robin van der Gracht
2022-06-20 7:23 ` Oleksij Rempel
2022-06-16 13:11 ` [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update Robin van der Gracht
2022-06-17 7:00 ` Sascha Hauer
2022-06-20 6:40 ` Robin van der Gracht
2022-06-16 13:11 ` [PATCH 3/9] ARM: boards: protonic-imx6: Free allocated autoboot_timeout string Robin van der Gracht
2022-06-16 13:11 ` [PATCH 4/9] ARM: boards: protonic-imx6: Always free allocated alias string Robin van der Gracht
2022-06-16 13:11 ` [PATCH 5/9] ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount Robin van der Gracht
2022-06-16 13:11 ` [PATCH 6/9] ARM: boards: protonic-imx6: Register prt-usb boot entry Robin van der Gracht
2022-06-16 13:11 ` [PATCH 7/9] ARM: boards: protonic-imx6: Remove usb_delay from the priv struct Robin van der Gracht
2022-06-16 13:11 ` [PATCH 8/9] ARM: boards: protonic-imx6: Read serial and mac from fuses if available Robin van der Gracht
2022-06-16 13:11 ` [PATCH 9/9] ARM: boards: protonic-imx6: Register serial_number parameter with ocotp Robin van der Gracht
2022-06-17 7:10 ` (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox