Message ID | 20190430014825.30553-15-marek.behun@nic.cz |
---|---|
State | Superseded |
Delegated to: | Stefan Roese |
Headers | show |
Series | Fixes for Turris Omnia | expand |
On 30.04.19 03:48, Marek Behún wrote: > There is a Factory RESET button on the back side of the Turris Omnia > router. When user presses this button before powering the device up and > keeps it pressed, the microcontroller prevents the main CPU from booting > and counts how long the RESET button is being pressed (and indicates > this by lighting up front LEDs). > > The idea behind this is that the user can boot the device into several > Factory RESET modes. > > This patch adds support for U-Boot to read into which Factory RESET mode > the user booted the device. The value is an integer stored into the > omnia_reset environment variable. It is 0 if the button was not pressed > at all during power up, otherwise it is the number identifying the > Factory RESET mode. > > This patch also adds support for configuring (via Kconfig) if the > bootcmd environment variable should be overwritten if this Factory RESET > button was pressed during device powerup, and if this configuration > option is enabled, the value by which bootcmd should be overwritten with > is also a configurable option. The default value sets the colors of all > the LEDs on the front panel to green, then loads the rescue system image > from the SPI flash memory and then boots it. > > Signed-off-by: Marek Behún <marek.behun@nic.cz> > --- > arch/arm/mach-mvebu/Kconfig | 43 ++++++++++++++++++++++++ > board/CZ.NIC/turris_omnia/turris_omnia.c | 23 +++++++++++++ > 2 files changed, 66 insertions(+) > > diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig > index fc29c3b084..4229a505d1 100644 > --- a/arch/arm/mach-mvebu/Kconfig > +++ b/arch/arm/mach-mvebu/Kconfig > @@ -116,6 +116,7 @@ config TARGET_DB_88F6820_AMC > config TARGET_TURRIS_OMNIA > bool "Support Turris Omnia" > select 88F6820 > + select BOARD_LATE_INIT > select DM_I2C > select I2C_MUX > select I2C_MUX_PCA954x > @@ -165,6 +166,48 @@ config TARGET_DB_XC3_24G4XG > > endchoice > > +if TARGET_TURRIS_OMNIA > + > +config TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD > + bool "Turris Omnia RESET button overwrites bootcmd" > + default y > + help > + There is a RESET button on the back side of the Turris Omnia router, > + which is read by the microcontroller before the main CPU is booted. > + If this button is pressed during device poweron, the CPU is only > + booted after the button is released. > + > + The CPU can then read how long the RESET button was pressed (in time > + intervals of cca 2 seconds, at most 12 different values), and U-Boot > + stores this value into omnia_reset environment variable. > + The microcontroller also lights up one front LED every time interval, > + so that users can see the value they are forcing. > + > + If this option is enabled, the board code will also overwrite the > + bootcmd variable with a constant configurable in this configuration > + (config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE) if the RESET button was > + pressed for at least one time interval. > + > + Otherwise only the omnia_reset environment variable is set. > + > +config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE > + string "Turris Omnia RESET button bootcmd value" > + default "i2c dev 2; i2c mw 0x2a.1 0x3 0x1c 1; i2c mw 0x2a.1 0x4 0x1c 1; mw.l 0x01000000 0x00ff000c; i2c write 0x01000000 0x2a.1 0x5 4 -s; setenv bootargs \\\"$bootargs omniarescue=$omnia_reset\\\"; sf probe; sf read 0x1000000 0x100000 0x700000; bootm 0x1000000; bootz 0x1000000" > + depends on TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD > + help > + If the RESET button is pressed during device poweron and released at > + least after cca 2 seconds, the bootcmd will be overwritten with this > + value. > + > + You can use the omnia_reset environment variable in this command to > + detect how long the reset button was pressed (or pass this value to > + Linux as a boot parameter). > + > + The default value of this command set the front LEDs to green color > + and then tries to boot rescue system from SPI memory. > + > +endif I fail to see a real reason to introduce these Kconfig options. Is TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD enabled for your board? If not it just adds dead code, as no other board will ever enable it. So do you plan to add 2 Omnia build targets, one with and one w/o this option enabled? Or what is your plan here? Thanks, Stefan > + > config SYS_BOARD > default "clearfog" if TARGET_CLEARFOG > default "helios4" if TARGET_HELIOS4 > diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c > index af43ee23d9..91fce6370c 100644 > --- a/board/CZ.NIC/turris_omnia/turris_omnia.c > +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c > @@ -328,6 +328,28 @@ static int set_regdomain(void) > printf("Regdomain set to %s\n", rd); > return env_set("regdomain", rd); > } > + > +static void handle_reset_button(void) > +{ > + int ret; > + u8 reset_status; > + > + ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1); > + if (ret) { > + printf("omnia_mcu_read failed: %i, reset status unknown!\n", > + ret); > + return; > + } > + > + env_set_ulong("omnia_reset", reset_status); > + > +#ifdef CONFIG_TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD > + if (reset_status) { > + printf("RESET button was pressed, overwriting bootcmd!\n"); > + env_set("bootcmd", CONFIG_TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE); > + } > +#endif > +} > #endif > > int board_early_init_f(void) > @@ -373,6 +395,7 @@ int board_late_init(void) > { > #ifndef CONFIG_SPL_BUILD > set_regdomain(); > + handle_reset_button(); > #endif > > return 0; > Viele Grüße, Stefan
On Thu, 2 May 2019 08:10:36 +0200 Stefan Roese <sr@denx.de> wrote: > I fail to see a real reason to introduce these Kconfig options. Is > TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD enabled for your board? If not > it just adds dead code, as no other board will ever enable it. So do > you plan to add 2 Omnia build targets, one with and one w/o this > option enabled? Or what is your plan here? > > Thanks, > Stefan My idea was that the users should be able to disable this functionality, if they are compiling u-boot themselves, but we are going to ship Omnias with this config enabled. I can of course remove the Kconfig options and enable this reset button handling all times. Marek
On 02.05.19 11:39, Marek Behun wrote: > On Thu, 2 May 2019 08:10:36 +0200 > Stefan Roese <sr@denx.de> wrote: > >> I fail to see a real reason to introduce these Kconfig options. Is >> TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD enabled for your board? If not >> it just adds dead code, as no other board will ever enable it. So do >> you plan to add 2 Omnia build targets, one with and one w/o this >> option enabled? Or what is your plan here? >> >> Thanks, >> Stefan > > My idea was that the users should be able to disable this functionality, > if they are compiling u-boot themselves, but we are going to ship > Omnias with this config enabled. Understood, thanks. > I can of course remove the Kconfig options and enable this reset button > handling all times. Please do so. If someone whats to disable this functionality or change the reset button bootcmd, then he/she/it must do some changes (defconfig or code). Thanks, Stefan
On Thu, 2 May 2019 11:43:12 +0200 Stefan Roese <sr@denx.de> wrote: > Please do so. If someone whats to disable this functionality or change > the reset button bootcmd, then he/she/it must do some changes > (defconfig or code). So should I remove the options from Kconfig or enable them by default? BTW: We are going to ship omnia with several other options enabled? Should I push them also to defconfig? They are: CONFIG_FIT=y CONFIG_FIT_ENABLE_SHA256_SUPPORT=y CONFIG_FIT_VERBOSE=y CONFIG_CMD_LZMADEC=y CONFIG_CMD_AES=y CONFIG_CMD_HASH=y CONFIG_CMD_SHA1SUM=y Marek
On 02.05.19 13:53, Marek Behún wrote: > On Thu, 2 May 2019 11:43:12 +0200 > Stefan Roese <sr@denx.de> wrote: > >> Please do so. If someone whats to disable this functionality or change >> the reset button bootcmd, then he/she/it must do some changes >> (defconfig or code). > > So should I remove the options from Kconfig or enable them by default? Yes. > BTW: We are going to ship omnia with several other options enabled? > Should I push them also to defconfig? Yes please. Or why would it make sense to have a stripped down version of this board port in mainline? > They are: > > CONFIG_FIT=y > CONFIG_FIT_ENABLE_SHA256_SUPPORT=y > CONFIG_FIT_VERBOSE=y > CONFIG_CMD_LZMADEC=y > CONFIG_CMD_AES=y > CONFIG_CMD_HASH=y > CONFIG_CMD_SHA1SUM=y > > Marek > Thanks, Stefan
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index fc29c3b084..4229a505d1 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -116,6 +116,7 @@ config TARGET_DB_88F6820_AMC config TARGET_TURRIS_OMNIA bool "Support Turris Omnia" select 88F6820 + select BOARD_LATE_INIT select DM_I2C select I2C_MUX select I2C_MUX_PCA954x @@ -165,6 +166,48 @@ config TARGET_DB_XC3_24G4XG endchoice +if TARGET_TURRIS_OMNIA + +config TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + bool "Turris Omnia RESET button overwrites bootcmd" + default y + help + There is a RESET button on the back side of the Turris Omnia router, + which is read by the microcontroller before the main CPU is booted. + If this button is pressed during device poweron, the CPU is only + booted after the button is released. + + The CPU can then read how long the RESET button was pressed (in time + intervals of cca 2 seconds, at most 12 different values), and U-Boot + stores this value into omnia_reset environment variable. + The microcontroller also lights up one front LED every time interval, + so that users can see the value they are forcing. + + If this option is enabled, the board code will also overwrite the + bootcmd variable with a constant configurable in this configuration + (config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE) if the RESET button was + pressed for at least one time interval. + + Otherwise only the omnia_reset environment variable is set. + +config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE + string "Turris Omnia RESET button bootcmd value" + default "i2c dev 2; i2c mw 0x2a.1 0x3 0x1c 1; i2c mw 0x2a.1 0x4 0x1c 1; mw.l 0x01000000 0x00ff000c; i2c write 0x01000000 0x2a.1 0x5 4 -s; setenv bootargs \\\"$bootargs omniarescue=$omnia_reset\\\"; sf probe; sf read 0x1000000 0x100000 0x700000; bootm 0x1000000; bootz 0x1000000" + depends on TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + help + If the RESET button is pressed during device poweron and released at + least after cca 2 seconds, the bootcmd will be overwritten with this + value. + + You can use the omnia_reset environment variable in this command to + detect how long the reset button was pressed (or pass this value to + Linux as a boot parameter). + + The default value of this command set the front LEDs to green color + and then tries to boot rescue system from SPI memory. + +endif + config SYS_BOARD default "clearfog" if TARGET_CLEARFOG default "helios4" if TARGET_HELIOS4 diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index af43ee23d9..91fce6370c 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -328,6 +328,28 @@ static int set_regdomain(void) printf("Regdomain set to %s\n", rd); return env_set("regdomain", rd); } + +static void handle_reset_button(void) +{ + int ret; + u8 reset_status; + + ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1); + if (ret) { + printf("omnia_mcu_read failed: %i, reset status unknown!\n", + ret); + return; + } + + env_set_ulong("omnia_reset", reset_status); + +#ifdef CONFIG_TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + if (reset_status) { + printf("RESET button was pressed, overwriting bootcmd!\n"); + env_set("bootcmd", CONFIG_TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE); + } +#endif +} #endif int board_early_init_f(void) @@ -373,6 +395,7 @@ int board_late_init(void) { #ifndef CONFIG_SPL_BUILD set_regdomain(); + handle_reset_button(); #endif return 0;
There is a Factory RESET button on the back side of the Turris Omnia router. When user presses this button before powering the device up and keeps it pressed, the microcontroller prevents the main CPU from booting and counts how long the RESET button is being pressed (and indicates this by lighting up front LEDs). The idea behind this is that the user can boot the device into several Factory RESET modes. This patch adds support for U-Boot to read into which Factory RESET mode the user booted the device. The value is an integer stored into the omnia_reset environment variable. It is 0 if the button was not pressed at all during power up, otherwise it is the number identifying the Factory RESET mode. This patch also adds support for configuring (via Kconfig) if the bootcmd environment variable should be overwritten if this Factory RESET button was pressed during device powerup, and if this configuration option is enabled, the value by which bootcmd should be overwritten with is also a configurable option. The default value sets the colors of all the LEDs on the front panel to green, then loads the rescue system image from the SPI flash memory and then boots it. Signed-off-by: Marek Behún <marek.behun@nic.cz> --- arch/arm/mach-mvebu/Kconfig | 43 ++++++++++++++++++++++++ board/CZ.NIC/turris_omnia/turris_omnia.c | 23 +++++++++++++ 2 files changed, 66 insertions(+)