ARM: boards: protonic-imx6: Updates
Subsystems (2)
cover ARM: boards: protonic-imx6: Updates
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(-)
Signature · 1 line
2.34.1
PATCH 1/9 ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
The usb check needs to be skipped unless both keys are pressed simultaneously.
--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boards/protonic-imx6/board.c +1 -1
@@ -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 ;
Signature · 1 line
2.34.1
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Hi Robin,
Quoted 13 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0
arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv) · line 649
Quoted 6 lines
arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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
Signature · 4 lines
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 |
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
Quoted 19 lines
Hi Robin,
Quoted 16 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0@@ -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 );
Quoted 8 lines
arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv) · line 649
Quoted 3 lines
arch/arm/boards/protonic-imx6/board.c +1
-1-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
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Quoted 27 lines · Oleksij Rempel
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
Quoted 26 lines
Hi Robin,
Quoted 13 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv) · line 649
Quoted 6 lines
arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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)))
Quoted 3 lines
Quoted 1 line
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
Signature · 4 lines
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 |
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Quoted 28 lines · Sascha Hauer
Quoted 27 lines · Oleksij Rempel
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
Quoted 26 lines
Hi Robin,
Quoted 13 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv) · line 649
Quoted 6 lines
arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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)))
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
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
Quoted 10 lines
Sascha
Signature · 4 lines
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 |
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Hello,
Quoted 7 lines · Marco Felsch
Quoted 3 lines · Sascha Hauer
Quoted 1 line
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
Quoted 16 lines
Regards,
MarcoQuoted 10 lines
Sascha
Signature · 4 lines
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 |
Signature · 4 lines
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 |
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Hi Ahmand,
Quoted 6 lines · Ahmad Fatoum
Hello,
Quoted 3 lines · Marco Felsch
Quoted 2 lines · Sascha Hauer
Quoted 1 line
Or, it is active low and your patch is correct :D
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
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. Seedrivers/input/specialkeys.cfor 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.
Quoted 5 lines
Robin, did you test this works with barebox v2022.05.0?
I'd have assumed this to be broken byf349b662674e("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:
arch/arm/boards/protonic-imx6/board.c +14 -7
@@ -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
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
In reply to Ahmad FatoumHello Ahmad,
Quoted 6 lines · Ahmad Fatoum
Hello,
Quoted 3 lines · Marco Felsch
Quoted 2 lines · Sascha Hauer
Quoted 1 line
Or, it is active low and your patch is correct :D
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
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. Seedrivers/input/specialkeys.cfor 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:
arch/arm/boards/protonic-imx6/board.c +5 -7
@@ -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
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
In reply to Oleksij RempelQuoted 28 lines · Oleksij Rempel
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
Quoted 27 lines
Hi Robin,
Quoted 13 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct prt_imx6_priv · line 650
Quoted 7 lines
arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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)))
Quoted 3 lines
Quoted 1 line
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
Re: [PATCH 1/9] ARM: boards: protonic-imx6: prtvt7 hardkey inputs are active low
Quoted 30 lines · Robin van der Gracht
Quoted 29 lines · Oleksij Rempel
Am 16.06.22 um 18:28 schrieb Oleksij Rempel:
Quoted 28 lines
Hi Robin,
Quoted 14 lines · Robin van der Gracht
The usb check needs to be skipped unless both keys are pressed simultaneously.
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +0
-0arch/arm/boards/protonic-imx6/board.c static int prt_imx6_init_prtvt7(struct · line 650
Quoted 7 lines
arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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)))
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
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
Signature · 4 lines
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 |
PATCH 2/9 ARM: boards: protonic-imx6: Update comment to match a recent code update
In reply to Robin van der Gracht--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boards/protonic-imx6/board.c +1 -1
@@ -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)
Signature · 1 line
2.34.1
Sascha Hauer
maintainerRe: [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update
Quoted 1 line · Robin van der Gracht
Fixes 1e817b64bc45968320597344e6b05463edd9c5e5
We don't have this commit in mainline, could you reference the corresponding upstream commit instead? Please write as aabbccddeeff ("subject")
Sascha
Quoted 23 lines
Signed-off-by Robin van der Gracht <[email protected]>--- arch/arm/boards/protonic-imx6/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/boards/protonic-imx6/board.c +1
-1@@ -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)Signature · 1 line
2.34.1
Signature · 4 lines
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 |
Re: [PATCH 2/9] ARM: boards: protonic-imx6: Update comment to match a recent code update
Quoted 6 lines · Sascha Hauer
Quoted 1 line · Robin van der Gracht
Fixes 1e817b64bc45968320597344e6b05463edd9c5e5We 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 <[email protected]> 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.
Link:
https://lore.barebox.org/[email protected]
PATCH 3/9 ARM: boards: protonic-imx6: Free allocated autoboot_timeout string
In reply to Robin van der Gracht--- arch/arm/boards/protonic-imx6/board.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/boards/protonic-imx6/board.c +1 -0
@@ -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; }
Signature · 1 line
2.34.1
PATCH 4/9 ARM: boards: protonic-imx6: Always free allocated alias string
In reply to Robin van der GrachtThe memory required to store the string needs to be freed on success as well since it's no longer used.
--- arch/arm/boards/protonic-imx6/board.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/arm/boards/protonic-imx6/board.c +4 -8
@@ -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;
Signature · 1 line
2.34.1
PATCH 5/9 ARM: boards: protonic-imx6: Remove unsused argument from prt_imx6_usb_mount
In reply to Robin van der GrachtRemoving this unused pointer pointer relieves the caller from freeing the memory afterwards.
--- arch/arm/boards/protonic-imx6/board.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
arch/arm/boards/protonic-imx6/board.c +3 -9
@@ -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 ; }
Signature · 1 line
2.34.1
PATCH 6/9 ARM: boards: protonic-imx6: Register prt-usb boot entry
In reply to Robin van der GrachtThe 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).
--- arch/arm/boards/protonic-imx6/board.c | 108 +++++++++++++++++++------- 1 file changed, 79 insertions(+), 29 deletions(-)
arch/arm/boards/protonic-imx6/board.c +79 -29
@@ -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 ; }
Signature · 1 line
2.34.1
PATCH 7/9 ARM: boards: protonic-imx6: Remove usb_delay from the priv struct
In reply to Robin van der GrachtIt's only used in one function right now.
--- arch/arm/boards/protonic-imx6/board.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/arm/boards/protonic-imx6/board.c +4 -5
@@ -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)
Signature · 1 line
2.34.1
PATCH 8/9 ARM: boards: protonic-imx6: Read serial and mac from fuses if available
In reply to Robin van der GrachtRead board serial number from GP1 fuses if available and fall-back to the i2c RFID eeprom (current method) otherwise.
--- arch/arm/boards/protonic-imx6/board.c | 44 ++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-)
arch/arm/boards/protonic-imx6/board.c +37 -7
@@ -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);
Signature · 1 line
2.34.1
PATCH 9/9 ARM: boards: protonic-imx6: Register serial_number parameter with ocotp
In reply to Robin van der Gracht--- arch/arm/boards/protonic-imx6/board.c | 39 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
arch/arm/boards/protonic-imx6/board.c +36 -3
@@ -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);
Signature · 1 line
2.34.1
Sascha Hauer
maintainerRe: (subset) [PATCH 0/9] ARM: boards: protonic-imx6: Updates
In reply to Robin van der GrachtQuoted 12 lines · Robin van der Gracht
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
Quoted 14 lines
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 allocatedautoboot_timeoutstring
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: Removeusb_delayfrom the priv struct
ARM: boards: protonic-imx6: Read serial and mac from fuses if
available
ARM: boards: protonic-imx6: Registerserial_numberparameter with
ocotp
Applied 3-9, thanks
Sascha
Signature · 4 lines
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 |