* [U-Boot] [PATCH 0/3] support enter download mode on rockchip platform
@ 2017-09-12 13:55 Andy Yan
2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Andy Yan @ 2017-09-12 13:55 UTC (permalink / raw)
To: u-boot
Most rockchip platform based boards use a key to instruct
the board enter download firmware mode, some boards use a
adc to detect the key status, and some use a gpio.
This series try to implement all the download mode releated
functions.
Andy Yan (3):
rockchip: make boot_mode releated codes reused across all platforms
rockchip: add support for backing to bootrom download mode
rockchip: check download key before bootup
arch/arm/include/asm/arch-rockchip/boot_mode.h | 6 +++
arch/arm/include/asm/arch-rockchip/bootrom.h | 2 +-
arch/arm/mach-rockchip/Kconfig | 15 +++++++
arch/arm/mach-rockchip/Makefile | 5 ++-
arch/arm/mach-rockchip/boot_mode.c | 58 ++++++++++++++++++++++++++
arch/arm/mach-rockchip/bootrom.c | 2 +-
arch/arm/mach-rockchip/rk3036-board.c | 24 -----------
arch/arm/mach-rockchip/rk322x-board.c | 24 -----------
arch/arm/mach-rockchip/rk3288-board.c | 25 -----------
arch/arm/mach-rockchip/rk3399-board.c | 14 +++++++
arch/arm/mach-rockchip/save_boot_param.S | 56 +++++++++++++++++++++----
board/rockchip/evb_rk3399/evb-rk3399.c | 28 +++++++++++++
12 files changed, 174 insertions(+), 85 deletions(-)
create mode 100644 arch/arm/mach-rockchip/boot_mode.c
create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
--
2.7.4
^ permalink raw reply [flat|nested] 11+ messages in thread* [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms 2017-09-12 13:55 [U-Boot] [PATCH 0/3] support enter download mode on rockchip platform Andy Yan @ 2017-09-12 13:57 ` Andy Yan 2017-09-13 4:26 ` Simon Glass 2017-09-21 9:02 ` Heiko Stuebner 2017-09-12 13:57 ` [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode Andy Yan 2017-09-12 13:58 ` [U-Boot] [PATCH 3/3] rockchip: check download key before bootup Andy Yan 2 siblings, 2 replies; 11+ messages in thread From: Andy Yan @ 2017-09-12 13:57 UTC (permalink / raw) To: u-boot setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file. Signed-off-by: Andy Yan <andy.yan@rock-chips.com> --- arch/arm/include/asm/arch-rockchip/boot_mode.h | 2 ++ arch/arm/mach-rockchip/Kconfig | 14 +++++++++++ arch/arm/mach-rockchip/Makefile | 5 +++- arch/arm/mach-rockchip/boot_mode.c | 33 ++++++++++++++++++++++++++ arch/arm/mach-rockchip/rk3036-board.c | 24 ------------------- arch/arm/mach-rockchip/rk322x-board.c | 24 ------------------- arch/arm/mach-rockchip/rk3288-board.c | 25 ------------------- arch/arm/mach-rockchip/rk3399-board.c | 14 +++++++++++ 8 files changed, 67 insertions(+), 74 deletions(-) create mode 100644 arch/arm/mach-rockchip/boot_mode.c create mode 100644 arch/arm/mach-rockchip/rk3399-board.c diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h index bd65f60..163b2e7 100644 --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h @@ -16,4 +16,6 @@ /* enter usb mass storage mode */ #define BOOT_UMS (REBOOT_FLAG + 12) +int setup_boot_mode(void); + #endif diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index d9b25d5..527ca60 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -114,6 +114,7 @@ config ROCKCHIP_RK3399 select SPL_DRIVERS_MISC_SUPPORT select ENABLE_ARM_SOC_BOOT0_HOOK select DEBUG_UART_BOARD_INIT + select BOARD_LATE_INIT help The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72 and quad-core Cortex-A53. @@ -149,6 +150,19 @@ config TPL_ROCKCHIP_BACK_TO_BROM SPL will return to the boot rom, which will then load the U-Boot binary to keep going on. +config ROCKCHIP_BOOT_MODE_REG + hex "Rockchip boot mode flag register address" + default 0x200081c8 if ROCKCHIP_RK3036 + default 0x110005d8 if ROCKCHIP_RK322X + default 0xff730094 if ROCKCHIP_RK3288 + default 0xff738200 if ROCKCHIP_RK3368 + default 0xff320300 if ROCKCHIP_RK3399 + default 0x10300580 if ROCKCHIP_RV1108 + default 0 + help + The Soc will enter to different boot mode according to different + value of this register. + config ROCKCHIP_SPL_RESERVE_IRAM hex "Size of IRAM reserved in SPL" default 0x4000 diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 79e9704..b7624cb 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -10,7 +10,6 @@ # the stack-pointer is valid before switching to the U-Boot stack). obj-spl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o obj-tpl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o obj-tpl-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board-tpl.o obj-tpl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-tpl.o @@ -22,10 +21,14 @@ obj-spl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-spl.o spl-boot-order.o obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) +ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0) +obj-y += boot_mode.o +endif obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o +obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o endif obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c new file mode 100644 index 0000000..7b3cbc5 --- /dev/null +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -0,0 +1,33 @@ +/* + * (C) Copyright 2016 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <asm/io.h> +#include <asm/arch/boot_mode.h> + +int setup_boot_mode(void) +{ + void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; + int boot_mode = readl(reg); + + debug("boot mode %x.\n", boot_mode); + + /* Clear boot mode */ + writel(BOOT_NORMAL, reg); + + switch (boot_mode) { + case BOOT_FASTBOOT: + printf("enter fastboot!\n"); + env_set("preboot", "setenv preboot; fastboot usb0"); + break; + case BOOT_UMS: + printf("enter UMS!\n"); + env_set("preboot", "setenv preboot; ums mmc 0"); + break; + } + + return 0; +} diff --git a/arch/arm/mach-rockchip/rk3036-board.c b/arch/arm/mach-rockchip/rk3036-board.c index a3457f3..a5d2571 100644 --- a/arch/arm/mach-rockchip/rk3036-board.c +++ b/arch/arm/mach-rockchip/rk3036-board.c @@ -19,30 +19,6 @@ DECLARE_GLOBAL_DATA_PTR; -#define GRF_BASE 0x20008000 - -static void setup_boot_mode(void) -{ - struct rk3036_grf *const grf = (void *)GRF_BASE; - int boot_mode = readl(&grf->os_reg[4]); - - debug("boot mode %x.\n", boot_mode); - - /* Clear boot mode */ - writel(BOOT_NORMAL, &grf->os_reg[4]); - - switch (boot_mode) { - case BOOT_FASTBOOT: - printf("enter fastboot!\n"); - env_set("preboot", "setenv preboot; fastboot usb0"); - break; - case BOOT_UMS: - printf("enter UMS!\n"); - env_set("preboot", "setenv preboot; ums mmc 0"); - break; - } -} - __weak int rk_board_late_init(void) { return 0; diff --git a/arch/arm/mach-rockchip/rk322x-board.c b/arch/arm/mach-rockchip/rk322x-board.c index c0ac2e9..3af137e 100644 --- a/arch/arm/mach-rockchip/rk322x-board.c +++ b/arch/arm/mach-rockchip/rk322x-board.c @@ -15,30 +15,6 @@ DECLARE_GLOBAL_DATA_PTR; -#define GRF_BASE 0x11000000 - -static void setup_boot_mode(void) -{ - struct rk322x_grf *const grf = (void *)GRF_BASE; - int boot_mode = readl(&grf->os_reg[4]); - - debug("boot mode %x.\n", boot_mode); - - /* Clear boot mode */ - writel(BOOT_NORMAL, &grf->os_reg[4]); - - switch (boot_mode) { - case BOOT_FASTBOOT: - printf("enter fastboot!\n"); - env_set("preboot", "setenv preboot; fastboot usb0"); - break; - case BOOT_UMS: - printf("enter UMS!\n"); - env_set("preboot", "setenv preboot; ums mmc 0"); - break; - } -} - __weak int rk_board_late_init(void) { return 0; diff --git a/arch/arm/mach-rockchip/rk3288-board.c b/arch/arm/mach-rockchip/rk3288-board.c index 278bb40..1c53cca 100644 --- a/arch/arm/mach-rockchip/rk3288-board.c +++ b/arch/arm/mach-rockchip/rk3288-board.c @@ -23,31 +23,6 @@ DECLARE_GLOBAL_DATA_PTR; -#define PMU_BASE 0xff730000 - -static void setup_boot_mode(void) -{ - struct rk3288_pmu *const pmu = (void *)PMU_BASE; - int boot_mode = readl(&pmu->sys_reg[0]); - - debug("boot mode %x.\n", boot_mode); - - /* Clear boot mode */ - writel(BOOT_NORMAL, &pmu->sys_reg[0]); - - switch (boot_mode) { - case BOOT_FASTBOOT: - printf("enter fastboot!\n"); - env_set("preboot", "setenv preboot; fastboot usb0"); - break; - case BOOT_UMS: - printf("enter UMS!\n"); - env_set("preboot", "setenv preboot; if mmc dev 0;" - "then ums mmc 0; else ums mmc 1;fi"); - break; - } -} - __weak int rk_board_late_init(void) { return 0; diff --git a/arch/arm/mach-rockchip/rk3399-board.c b/arch/arm/mach-rockchip/rk3399-board.c new file mode 100644 index 0000000..9293843 --- /dev/null +++ b/arch/arm/mach-rockchip/rk3399-board.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2017 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <asm/arch/boot_mode.h> + +int board_late_init(void) +{ + setup_boot_mode(); + return 0; +} -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms 2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan @ 2017-09-13 4:26 ` Simon Glass 2017-09-21 9:02 ` Heiko Stuebner 1 sibling, 0 replies; 11+ messages in thread From: Simon Glass @ 2017-09-13 4:26 UTC (permalink / raw) To: u-boot On 12 September 2017 at 07:57, Andy Yan <andy.yan@rock-chips.com> wrote: > setup_boot_mode function use the same logic but different > mode register address across all the rockchip platforms, > so it's better to make this function reused across all the > platforms, and let the mode register address setting from > the config file. > > Signed-off-by: Andy Yan <andy.yan@rock-chips.com> > > --- > > arch/arm/include/asm/arch-rockchip/boot_mode.h | 2 ++ > arch/arm/mach-rockchip/Kconfig | 14 +++++++++++ > arch/arm/mach-rockchip/Makefile | 5 +++- > arch/arm/mach-rockchip/boot_mode.c | 33 ++++++++++++++++++++++++++ > arch/arm/mach-rockchip/rk3036-board.c | 24 ------------------- > arch/arm/mach-rockchip/rk322x-board.c | 24 ------------------- > arch/arm/mach-rockchip/rk3288-board.c | 25 ------------------- > arch/arm/mach-rockchip/rk3399-board.c | 14 +++++++++++ > 8 files changed, 67 insertions(+), 74 deletions(-) > create mode 100644 arch/arm/mach-rockchip/boot_mode.c > create mode 100644 arch/arm/mach-rockchip/rk3399-board.c Reviewed-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms 2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan 2017-09-13 4:26 ` Simon Glass @ 2017-09-21 9:02 ` Heiko Stuebner 2017-09-21 9:04 ` Andy Yan 1 sibling, 1 reply; 11+ messages in thread From: Heiko Stuebner @ 2017-09-21 9:02 UTC (permalink / raw) To: u-boot Hi Andy, Am Dienstag, 12. September 2017, 21:57:32 CEST schrieb Andy Yan: > setup_boot_mode function use the same logic but different > mode register address across all the rockchip platforms, > so it's better to make this function reused across all the > platforms, and let the mode register address setting from > the config file. > > Signed-off-by: Andy Yan <andy.yan@rock-chips.com> > > --- > > arch/arm/include/asm/arch-rockchip/boot_mode.h | 2 ++ > arch/arm/mach-rockchip/Kconfig | 14 +++++++++++ > arch/arm/mach-rockchip/Makefile | 5 +++- > arch/arm/mach-rockchip/boot_mode.c | 33 ++++++++++++++++++++++++++ > arch/arm/mach-rockchip/rk3036-board.c | 24 ------------------- > arch/arm/mach-rockchip/rk322x-board.c | 24 ------------------- > arch/arm/mach-rockchip/rk3288-board.c | 25 ------------------- > arch/arm/mach-rockchip/rk3399-board.c | 14 +++++++++++ > 8 files changed, 67 insertions(+), 74 deletions(-) > create mode 100644 arch/arm/mach-rockchip/boot_mode.c > create mode 100644 arch/arm/mach-rockchip/rk3399-board.c > > diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h > index bd65f60..163b2e7 100644 > --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h > +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h > @@ -16,4 +16,6 @@ > /* enter usb mass storage mode */ > #define BOOT_UMS (REBOOT_FLAG + 12) > > +int setup_boot_mode(void); > + > #endif > diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig > index d9b25d5..527ca60 100644 > --- a/arch/arm/mach-rockchip/Kconfig > +++ b/arch/arm/mach-rockchip/Kconfig > @@ -114,6 +114,7 @@ config ROCKCHIP_RK3399 > select SPL_DRIVERS_MISC_SUPPORT > select ENABLE_ARM_SOC_BOOT0_HOOK > select DEBUG_UART_BOARD_INIT > + select BOARD_LATE_INIT > help > The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72 > and quad-core Cortex-A53. > @@ -149,6 +150,19 @@ config TPL_ROCKCHIP_BACK_TO_BROM > SPL will return to the boot rom, which will then load the U-Boot > binary to keep going on. > > +config ROCKCHIP_BOOT_MODE_REG > + hex "Rockchip boot mode flag register address" > + default 0x200081c8 if ROCKCHIP_RK3036 > + default 0x110005d8 if ROCKCHIP_RK322X > + default 0xff730094 if ROCKCHIP_RK3288 > + default 0xff738200 if ROCKCHIP_RK3368 > + default 0xff320300 if ROCKCHIP_RK3399 > + default 0x10300580 if ROCKCHIP_RV1108 could you possibly look up if the rk3188 and rk3066 also support the subsequent boot to maskrom download mode from the later patches and include the register if possible? Thanks Heiko ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms 2017-09-21 9:02 ` Heiko Stuebner @ 2017-09-21 9:04 ` Andy Yan 0 siblings, 0 replies; 11+ messages in thread From: Andy Yan @ 2017-09-21 9:04 UTC (permalink / raw) To: u-boot Hi Heiko: On 2017年09月21日 17:02, Heiko Stuebner wrote: > Hi Andy, > > Am Dienstag, 12. September 2017, 21:57:32 CEST schrieb Andy Yan: >> setup_boot_mode function use the same logic but different >> mode register address across all the rockchip platforms, >> so it's better to make this function reused across all the >> platforms, and let the mode register address setting from >> the config file. >> >> Signed-off-by: Andy Yan <andy.yan@rock-chips.com> >> >> --- >> >> arch/arm/include/asm/arch-rockchip/boot_mode.h | 2 ++ >> arch/arm/mach-rockchip/Kconfig | 14 +++++++++++ >> arch/arm/mach-rockchip/Makefile | 5 +++- >> arch/arm/mach-rockchip/boot_mode.c | 33 ++++++++++++++++++++++++++ >> arch/arm/mach-rockchip/rk3036-board.c | 24 ------------------- >> arch/arm/mach-rockchip/rk322x-board.c | 24 ------------------- >> arch/arm/mach-rockchip/rk3288-board.c | 25 ------------------- >> arch/arm/mach-rockchip/rk3399-board.c | 14 +++++++++++ >> 8 files changed, 67 insertions(+), 74 deletions(-) >> create mode 100644 arch/arm/mach-rockchip/boot_mode.c >> create mode 100644 arch/arm/mach-rockchip/rk3399-board.c >> >> diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h >> index bd65f60..163b2e7 100644 >> --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h >> +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h >> @@ -16,4 +16,6 @@ >> /* enter usb mass storage mode */ >> #define BOOT_UMS (REBOOT_FLAG + 12) >> >> +int setup_boot_mode(void); >> + >> #endif >> diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig >> index d9b25d5..527ca60 100644 >> --- a/arch/arm/mach-rockchip/Kconfig >> +++ b/arch/arm/mach-rockchip/Kconfig >> @@ -114,6 +114,7 @@ config ROCKCHIP_RK3399 >> select SPL_DRIVERS_MISC_SUPPORT >> select ENABLE_ARM_SOC_BOOT0_HOOK >> select DEBUG_UART_BOARD_INIT >> + select BOARD_LATE_INIT >> help >> The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72 >> and quad-core Cortex-A53. >> @@ -149,6 +150,19 @@ config TPL_ROCKCHIP_BACK_TO_BROM >> SPL will return to the boot rom, which will then load the U-Boot >> binary to keep going on. >> >> +config ROCKCHIP_BOOT_MODE_REG >> + hex "Rockchip boot mode flag register address" >> + default 0x200081c8 if ROCKCHIP_RK3036 >> + default 0x110005d8 if ROCKCHIP_RK322X >> + default 0xff730094 if ROCKCHIP_RK3288 >> + default 0xff738200 if ROCKCHIP_RK3368 >> + default 0xff320300 if ROCKCHIP_RK3399 >> + default 0x10300580 if ROCKCHIP_RV1108 > could you possibly look up if the rk3188 and rk3066 also support > the subsequent boot to maskrom download mode from the later > patches and include the register if possible? Okay, I will add support for them in next version. > > > Thanks > Heiko > > > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode 2017-09-12 13:55 [U-Boot] [PATCH 0/3] support enter download mode on rockchip platform Andy Yan 2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan @ 2017-09-12 13:57 ` Andy Yan 2017-09-13 4:26 ` Simon Glass 2017-09-12 13:58 ` [U-Boot] [PATCH 3/3] rockchip: check download key before bootup Andy Yan 2 siblings, 1 reply; 11+ messages in thread From: Andy Yan @ 2017-09-12 13:57 UTC (permalink / raw) To: u-boot Rockchip bootrom will enter download mode if it returns from spl/tpl with a none-zero value and couldn't find a valid image in the backup partition. This patch provide a method to instruct the system to back to bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. As the bootrom download function relys on some modules such as interrupts, so we need to back to bootrom as early as possbile before the tpl/tps code override the interrupt settings. Signed-off-by: Andy Yan <andy.yan@rock-chips.com> Reviewed-by: Kever Yang <kever.yang@rock-chips.com> --- arch/arm/include/asm/arch-rockchip/boot_mode.h | 4 ++ arch/arm/include/asm/arch-rockchip/bootrom.h | 2 +- arch/arm/mach-rockchip/Kconfig | 1 + arch/arm/mach-rockchip/bootrom.c | 2 +- arch/arm/mach-rockchip/save_boot_param.S | 56 +++++++++++++++++++++----- 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h index 163b2e7..6b2a610 100644 --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h @@ -15,7 +15,11 @@ #define BOOT_CHARGING (REBOOT_FLAG + 11) /* enter usb mass storage mode */ #define BOOT_UMS (REBOOT_FLAG + 12) +/* enter bootrom download mode */ +#define BOOT_BROM_DOWNLOAD 0xEF08A53C +#ifndef __ASSEMBLY__ int setup_boot_mode(void); +#endif #endif diff --git a/arch/arm/include/asm/arch-rockchip/bootrom.h b/arch/arm/include/asm/arch-rockchip/bootrom.h index 92eb878..6ae3e94 100644 --- a/arch/arm/include/asm/arch-rockchip/bootrom.h +++ b/arch/arm/include/asm/arch-rockchip/bootrom.h @@ -22,6 +22,6 @@ void back_to_bootrom(void); /** * Assembler component for the above (do not call this directly) */ -void _back_to_bootrom_s(void); +void _back_to_bootrom_s(int mode); #endif diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index 527ca60..a2b7a7e 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -113,6 +113,7 @@ config ROCKCHIP_RK3399 select SPL_SERIAL_SUPPORT select SPL_DRIVERS_MISC_SUPPORT select ENABLE_ARM_SOC_BOOT0_HOOK + select ROCKCHIP_BROM_HELPER select DEBUG_UART_BOARD_INIT select BOARD_LATE_INIT help diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c index 8380e4e..6f0d583 100644 --- a/arch/arm/mach-rockchip/bootrom.c +++ b/arch/arm/mach-rockchip/bootrom.c @@ -12,5 +12,5 @@ void back_to_bootrom(void) #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT) puts("Returning to boot ROM...\n"); #endif - _back_to_bootrom_s(); + _back_to_bootrom_s(0); } diff --git a/arch/arm/mach-rockchip/save_boot_param.S b/arch/arm/mach-rockchip/save_boot_param.S index 50fce20..325e81e 100644 --- a/arch/arm/mach-rockchip/save_boot_param.S +++ b/arch/arm/mach-rockchip/save_boot_param.S @@ -6,12 +6,25 @@ */ #include <linux/linkage.h> +#include <asm/arch/boot_mode.h> #if defined(CONFIG_ARM64) .globl SAVE_SP_ADDR SAVE_SP_ADDR: .quad 0 +ENTRY(check_back_to_brom_dnl_flag) + ldr x8, =CONFIG_ROCKCHIP_BOOT_MODE_REG + ldr x9, [x8] + ldr x0, =BOOT_BROM_DOWNLOAD + cmp x9, x0 + b.ne save_boot_params_ret + mov x9, xzr + str x9, [x8] /* clear flag */ + mov x0, #1 /* indicate the bootrom to enter download mode */ + b _back_to_bootrom_s +ENDPROC(check_back_to_brom_dnl_flag) + ENTRY(save_boot_params) sub sp, sp, #0x60 stp x29, x30, [sp, #0x50] @@ -23,14 +36,22 @@ ENTRY(save_boot_params) ldr x8, =SAVE_SP_ADDR mov x9, sp str x9, [x8] +#if CONFIG_ROCKCHIP_BOOT_MODE_REG + b check_back_to_brom_dnl_flag +#else b save_boot_params_ret /* back to my caller */ +#endif ENDPROC(save_boot_params) +/* + * x0: return value for bootrom, none-zero for bootrom download + * mode and zero for normal boot mode + */ .globl _back_to_bootrom_s ENTRY(_back_to_bootrom_s) - ldr x0, =SAVE_SP_ADDR - ldr x0, [x0] - mov sp, x0 + ldr x1, =SAVE_SP_ADDR + ldr x1, [x1] + mov sp, x1 ldp x29, x30, [sp, #0x50] ldp x27, x28, [sp, #0x40] ldp x25, x26, [sp, #0x30] @@ -38,7 +59,6 @@ ENTRY(_back_to_bootrom_s) ldp x21, x22, [sp, #0x10] ldp x19, x20, [sp] add sp, sp, #0x60 - mov x0, xzr ret ENDPROC(_back_to_bootrom_s) #else @@ -46,6 +66,18 @@ ENDPROC(_back_to_bootrom_s) SAVE_SP_ADDR: .word 0 +ENTRY(check_back_to_brom_dnl_flag) + ldr r0, =CONFIG_ROCKCHIP_BOOT_MODE_REG + ldr r1, [r0] + ldr r2, =BOOT_BROM_DOWNLOAD + cmp r1, r2 + bne save_boot_params_ret + mov r3, #0 + str r3, [r0] @clear flag + mov r0, #1 @indicate the bootrom to enter download mode + b _back_to_bootrom_s +ENDPROC(check_back_to_brom_dnl_flag) + /* * void save_boot_params * @@ -55,15 +87,21 @@ ENTRY(save_boot_params) push {r1-r12, lr} ldr r0, =SAVE_SP_ADDR str sp, [r0] - b save_boot_params_ret @ back to my caller +#if CONFIG_ROCKCHIP_BOOT_MODE_REG + b check_back_to_brom_dnl_flag +#else + b save_boot_params_ret +#endif ENDPROC(save_boot_params) - +/* + * r0: return value for bootrom, none-zero for bootrom download + * mode and zero for normal boot mode + */ .globl _back_to_bootrom_s ENTRY(_back_to_bootrom_s) - ldr r0, =SAVE_SP_ADDR - ldr sp, [r0] - mov r0, #0 + ldr r1, =SAVE_SP_ADDR + ldr sp, [r1] pop {r1-r12, pc} ENDPROC(_back_to_bootrom_s) #endif -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode 2017-09-12 13:57 ` [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode Andy Yan @ 2017-09-13 4:26 ` Simon Glass 0 siblings, 0 replies; 11+ messages in thread From: Simon Glass @ 2017-09-13 4:26 UTC (permalink / raw) To: u-boot Hi Andy, On 12 September 2017 at 07:57, Andy Yan <andy.yan@rock-chips.com> wrote: > Rockchip bootrom will enter download mode if it returns from > spl/tpl with a none-zero value and couldn't find a valid image > in the backup partition. > This patch provide a method to instruct the system to back to > bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. > As the bootrom download function relys on some modules such as > interrupts, so we need to back to bootrom as early as possbile > before the tpl/tps code override the interrupt settings. > > Signed-off-by: Andy Yan <andy.yan@rock-chips.com> > Reviewed-by: Kever Yang <kever.yang@rock-chips.com> > --- > > arch/arm/include/asm/arch-rockchip/boot_mode.h | 4 ++ > arch/arm/include/asm/arch-rockchip/bootrom.h | 2 +- > arch/arm/mach-rockchip/Kconfig | 1 + > arch/arm/mach-rockchip/bootrom.c | 2 +- > arch/arm/mach-rockchip/save_boot_param.S | 56 +++++++++++++++++++++----- > 5 files changed, 54 insertions(+), 11 deletions(-) > > diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h > index 163b2e7..6b2a610 100644 > --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h > +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h > @@ -15,7 +15,11 @@ > #define BOOT_CHARGING (REBOOT_FLAG + 11) > /* enter usb mass storage mode */ > #define BOOT_UMS (REBOOT_FLAG + 12) > +/* enter bootrom download mode */ > +#define BOOT_BROM_DOWNLOAD 0xEF08A53C > > +#ifndef __ASSEMBLY__ > int setup_boot_mode(void); > +#endif > > #endif > diff --git a/arch/arm/include/asm/arch-rockchip/bootrom.h b/arch/arm/include/asm/arch-rockchip/bootrom.h > index 92eb878..6ae3e94 100644 > --- a/arch/arm/include/asm/arch-rockchip/bootrom.h > +++ b/arch/arm/include/asm/arch-rockchip/bootrom.h > @@ -22,6 +22,6 @@ void back_to_bootrom(void); > /** > * Assembler component for the above (do not call this directly) > */ > -void _back_to_bootrom_s(void); > +void _back_to_bootrom_s(int mode); Please document the arg > > #endif > diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig > index 527ca60..a2b7a7e 100644 > --- a/arch/arm/mach-rockchip/Kconfig > +++ b/arch/arm/mach-rockchip/Kconfig > @@ -113,6 +113,7 @@ config ROCKCHIP_RK3399 > select SPL_SERIAL_SUPPORT > select SPL_DRIVERS_MISC_SUPPORT > select ENABLE_ARM_SOC_BOOT0_HOOK > + select ROCKCHIP_BROM_HELPER > select DEBUG_UART_BOARD_INIT > select BOARD_LATE_INIT > help > diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c > index 8380e4e..6f0d583 100644 > --- a/arch/arm/mach-rockchip/bootrom.c > +++ b/arch/arm/mach-rockchip/bootrom.c > @@ -12,5 +12,5 @@ void back_to_bootrom(void) > #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT) > puts("Returning to boot ROM...\n"); > #endif > - _back_to_bootrom_s(); > + _back_to_bootrom_s(0); What does 0 mean? Should this be an enum / #define ? > } > diff --git a/arch/arm/mach-rockchip/save_boot_param.S b/arch/arm/mach-rockchip/save_boot_param.S > index 50fce20..325e81e 100644 > --- a/arch/arm/mach-rockchip/save_boot_param.S > +++ b/arch/arm/mach-rockchip/save_boot_param.S > @@ -6,12 +6,25 @@ > */ > > #include <linux/linkage.h> > +#include <asm/arch/boot_mode.h> > > #if defined(CONFIG_ARM64) > .globl SAVE_SP_ADDR > SAVE_SP_ADDR: > .quad 0 > > +ENTRY(check_back_to_brom_dnl_flag) > + ldr x8, =CONFIG_ROCKCHIP_BOOT_MODE_REG > + ldr x9, [x8] > + ldr x0, =BOOT_BROM_DOWNLOAD > + cmp x9, x0 > + b.ne save_boot_params_ret > + mov x9, xzr > + str x9, [x8] /* clear flag */ > + mov x0, #1 /* indicate the bootrom to enter download mode */ > + b _back_to_bootrom_s > +ENDPROC(check_back_to_brom_dnl_flag) > + > ENTRY(save_boot_params) > sub sp, sp, #0x60 > stp x29, x30, [sp, #0x50] > @@ -23,14 +36,22 @@ ENTRY(save_boot_params) > ldr x8, =SAVE_SP_ADDR > mov x9, sp > str x9, [x8] > +#if CONFIG_ROCKCHIP_BOOT_MODE_REG > + b check_back_to_brom_dnl_flag > +#else > b save_boot_params_ret /* back to my caller */ > +#endif > ENDPROC(save_boot_params) > > +/* > + * x0: return value for bootrom, none-zero for bootrom download > + * mode and zero for normal boot mode > + */ > .globl _back_to_bootrom_s > ENTRY(_back_to_bootrom_s) > - ldr x0, =SAVE_SP_ADDR > - ldr x0, [x0] > - mov sp, x0 > + ldr x1, =SAVE_SP_ADDR > + ldr x1, [x1] > + mov sp, x1 > ldp x29, x30, [sp, #0x50] > ldp x27, x28, [sp, #0x40] > ldp x25, x26, [sp, #0x30] > @@ -38,7 +59,6 @@ ENTRY(_back_to_bootrom_s) > ldp x21, x22, [sp, #0x10] > ldp x19, x20, [sp] > add sp, sp, #0x60 > - mov x0, xzr > ret > ENDPROC(_back_to_bootrom_s) > #else > @@ -46,6 +66,18 @@ ENDPROC(_back_to_bootrom_s) > SAVE_SP_ADDR: > .word 0 > > +ENTRY(check_back_to_brom_dnl_flag) Please document what this function does > + ldr r0, =CONFIG_ROCKCHIP_BOOT_MODE_REG > + ldr r1, [r0] > + ldr r2, =BOOT_BROM_DOWNLOAD > + cmp r1, r2 > + bne save_boot_params_ret > + mov r3, #0 > + str r3, [r0] @clear flag > + mov r0, #1 @indicate the bootrom to enter download mode > + b _back_to_bootrom_s > +ENDPROC(check_back_to_brom_dnl_flag) > + > /* > * void save_boot_params > * > @@ -55,15 +87,21 @@ ENTRY(save_boot_params) > push {r1-r12, lr} > ldr r0, =SAVE_SP_ADDR > str sp, [r0] > - b save_boot_params_ret @ back to my caller > +#if CONFIG_ROCKCHIP_BOOT_MODE_REG > + b check_back_to_brom_dnl_flag > +#else > + b save_boot_params_ret > +#endif > ENDPROC(save_boot_params) > > - > +/* > + * r0: return value for bootrom, none-zero for bootrom download > + * mode and zero for normal boot mode > + */ > .globl _back_to_bootrom_s > ENTRY(_back_to_bootrom_s) > - ldr r0, =SAVE_SP_ADDR > - ldr sp, [r0] > - mov r0, #0 > + ldr r1, =SAVE_SP_ADDR > + ldr sp, [r1] > pop {r1-r12, pc} > ENDPROC(_back_to_bootrom_s) > #endif > -- > 2.7.4 > > Regards, Simon ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 3/3] rockchip: check download key before bootup 2017-09-12 13:55 [U-Boot] [PATCH 0/3] support enter download mode on rockchip platform Andy Yan 2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan 2017-09-12 13:57 ` [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode Andy Yan @ 2017-09-12 13:58 ` Andy Yan 2017-09-13 4:26 ` Simon Glass 2 siblings, 1 reply; 11+ messages in thread From: Andy Yan @ 2017-09-12 13:58 UTC (permalink / raw) To: u-boot Enter download mode if the download key pressed. Signed-off-by: Andy Yan <andy.yan@rock-chips.com> --- arch/arm/mach-rockchip/boot_mode.c | 27 ++++++++++++++++++++++++++- board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index 7b3cbc5..bff1cbc 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -8,11 +8,36 @@ #include <asm/io.h> #include <asm/arch/boot_mode.h> +void set_back_to_bootrom_dnl_flag(void) +{ + writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); +} + +/* + * some boards use a adc key, but some use gpio + */ +__weak int rockchip_dnl_key_pressed(void) +{ + return false; +} + +void rockchip_dnl_mode_check(void) +{ + if (rockchip_dnl_key_pressed()) { + printf("download key pressed, enter download mode..."); + set_back_to_bootrom_dnl_flag(); + do_reset(NULL, 0, 0, NULL); + } +} + int setup_boot_mode(void) { void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; - int boot_mode = readl(reg); + int boot_mode; + + rockchip_dnl_mode_check(); + boot_mode = readl(reg); debug("boot mode %x.\n", boot_mode); /* Clear boot mode */ diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c index d50c59d..738d942 100644 --- a/board/rockchip/evb_rk3399/evb-rk3399.c +++ b/board/rockchip/evb_rk3399/evb-rk3399.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> +#include <adc.h> #include <dm.h> #include <ram.h> #include <dm/pinctrl.h> @@ -13,6 +14,33 @@ DECLARE_GLOBAL_DATA_PTR; +#define KEY_DOWN_MIN_VAL 1 +#define KEY_DOWN_MAX_VAL 20 + +int rockchip_dnl_key_pressed(void) +{ + unsigned int ret; + unsigned int i; + unsigned int val; + int cnt = 0; + + for (i = 0; i < 10; i++) { + ret = adc_channel_single_shot("saradc", 1, &val); + if (ret) { + printf("%s adc_channel_single_shot fail!\n", __func__); + break; + } + + if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL)) + cnt++; + } + + if (cnt >= 8) + return true; + else + return false; +} + int board_init(void) { struct udevice *pinctrl, *regulator; -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 3/3] rockchip: check download key before bootup 2017-09-12 13:58 ` [U-Boot] [PATCH 3/3] rockchip: check download key before bootup Andy Yan @ 2017-09-13 4:26 ` Simon Glass 2017-09-13 6:14 ` Andy Yan 0 siblings, 1 reply; 11+ messages in thread From: Simon Glass @ 2017-09-13 4:26 UTC (permalink / raw) To: u-boot Hi Andy, On 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote: > Enter download mode if the download key pressed. > > Signed-off-by: Andy Yan <andy.yan@rock-chips.com> > --- > > arch/arm/mach-rockchip/boot_mode.c | 27 ++++++++++++++++++++++++++- > board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c > index 7b3cbc5..bff1cbc 100644 > --- a/arch/arm/mach-rockchip/boot_mode.c > +++ b/arch/arm/mach-rockchip/boot_mode.c > @@ -8,11 +8,36 @@ > #include <asm/io.h> > #include <asm/arch/boot_mode.h> > > +void set_back_to_bootrom_dnl_flag(void) > +{ > + writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); > +} > + > +/* > + * some boards use a adc key, but some use gpio > + */ > +__weak int rockchip_dnl_key_pressed(void) Can you please declare this in a header file and add a full comment as to what this does? > +{ > + return false; > +} > + > +void rockchip_dnl_mode_check(void) > +{ > + if (rockchip_dnl_key_pressed()) { > + printf("download key pressed, enter download mode..."); should that be 'entering'? > + set_back_to_bootrom_dnl_flag(); > + do_reset(NULL, 0, 0, NULL); > + } > +} > + > int setup_boot_mode(void) > { > void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; > - int boot_mode = readl(reg); > + int boot_mode; > + > + rockchip_dnl_mode_check(); > > + boot_mode = readl(reg); > debug("boot mode %x.\n", boot_mode); > > /* Clear boot mode */ > diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c > index d50c59d..738d942 100644 > --- a/board/rockchip/evb_rk3399/evb-rk3399.c > +++ b/board/rockchip/evb_rk3399/evb-rk3399.c > @@ -4,6 +4,7 @@ > * SPDX-License-Identifier: GPL-2.0+ > */ > #include <common.h> > +#include <adc.h> > #include <dm.h> > #include <ram.h> > #include <dm/pinctrl.h> > @@ -13,6 +14,33 @@ > > DECLARE_GLOBAL_DATA_PTR; > > +#define KEY_DOWN_MIN_VAL 1 > +#define KEY_DOWN_MAX_VAL 20 > + > +int rockchip_dnl_key_pressed(void) > +{ > + unsigned int ret; > + unsigned int i; > + unsigned int val; > + int cnt = 0; > + Please document what is going on here - why the loop? What is the check against min/max value? > + for (i = 0; i < 10; i++) { > + ret = adc_channel_single_shot("saradc", 1, &val); > + if (ret) { > + printf("%s adc_channel_single_shot fail!\n", __func__); > + break; > + } > + > + if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL)) > + cnt++; > + } > + > + if (cnt >= 8) > + return true; > + else > + return false; > +} > + > int board_init(void) > { > struct udevice *pinctrl, *regulator; > -- > 2.7.4 > > Regards, Simon ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 3/3] rockchip: check download key before bootup 2017-09-13 4:26 ` Simon Glass @ 2017-09-13 6:14 ` Andy Yan 2017-09-17 17:52 ` Simon Glass 0 siblings, 1 reply; 11+ messages in thread From: Andy Yan @ 2017-09-13 6:14 UTC (permalink / raw) To: u-boot Hi Simon: On 2017年09月13日 12:26, Simon Glass wrote: > Hi Andy, > > On 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote: >> Enter download mode if the download key pressed. >> >> Signed-off-by: Andy Yan <andy.yan@rock-chips.com> >> --- >> >> arch/arm/mach-rockchip/boot_mode.c | 27 ++++++++++++++++++++++++++- >> board/rockchip/evb_rk3399/evb-rk3399.c | 28 ++++++++++++++++++++++++++++ >> 2 files changed, 54 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c >> index 7b3cbc5..bff1cbc 100644 >> --- a/arch/arm/mach-rockchip/boot_mode.c >> +++ b/arch/arm/mach-rockchip/boot_mode.c >> @@ -8,11 +8,36 @@ >> #include <asm/io.h> >> #include <asm/arch/boot_mode.h> >> >> +void set_back_to_bootrom_dnl_flag(void) >> +{ >> + writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); >> +} >> + >> +/* >> + * some boards use a adc key, but some use gpio >> + */ >> +__weak int rockchip_dnl_key_pressed(void) > Can you please declare this in a header file and add a full comment as > to what this does? This function is only used in this file and can be override by other boards. So I don't think this is a necessary to declare this in a header file. Of course, I will add a full comment for it. >> +{ >> + return false; >> +} >> + >> +void rockchip_dnl_mode_check(void) >> +{ >> + if (rockchip_dnl_key_pressed()) { >> + printf("download key pressed, enter download mode..."); > should that be 'entering'? Okay, should be 'entering' >> + set_back_to_bootrom_dnl_flag(); >> + do_reset(NULL, 0, 0, NULL); >> + } >> +} >> + >> int setup_boot_mode(void) >> { >> void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; >> - int boot_mode = readl(reg); >> + int boot_mode; >> + >> + rockchip_dnl_mode_check(); >> >> + boot_mode = readl(reg); >> debug("boot mode %x.\n", boot_mode); >> >> /* Clear boot mode */ >> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c b/board/rockchip/evb_rk3399/evb-rk3399.c >> index d50c59d..738d942 100644 >> --- a/board/rockchip/evb_rk3399/evb-rk3399.c >> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c >> @@ -4,6 +4,7 @@ >> * SPDX-License-Identifier: GPL-2.0+ >> */ >> #include <common.h> >> +#include <adc.h> >> #include <dm.h> >> #include <ram.h> >> #include <dm/pinctrl.h> >> @@ -13,6 +14,33 @@ >> >> DECLARE_GLOBAL_DATA_PTR; >> >> +#define KEY_DOWN_MIN_VAL 1 >> +#define KEY_DOWN_MAX_VAL 20 >> + >> +int rockchip_dnl_key_pressed(void) >> +{ >> + unsigned int ret; >> + unsigned int i; >> + unsigned int val; >> + int cnt = 0; >> + > Please document what is going on here - why the loop? What is the > check against min/max value? This if for voltage debounce, according to my experience on the rk3399 evb board, in the 10 adc sample results, we will met 2 ~ 4 result vals are out of the MIN~MAX range. > >> + for (i = 0; i < 10; i++) { >> + ret = adc_channel_single_shot("saradc", 1, &val); >> + if (ret) { >> + printf("%s adc_channel_single_shot fail!\n", __func__); >> + break; >> + } >> + >> + if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL)) >> + cnt++; >> + } >> + >> + if (cnt >= 8) >> + return true; >> + else >> + return false; >> +} >> + >> int board_init(void) >> { >> struct udevice *pinctrl, *regulator; >> -- >> 2.7.4 >> >> > Regards, > Simon > > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH 3/3] rockchip: check download key before bootup 2017-09-13 6:14 ` Andy Yan @ 2017-09-17 17:52 ` Simon Glass 0 siblings, 0 replies; 11+ messages in thread From: Simon Glass @ 2017-09-17 17:52 UTC (permalink / raw) To: u-boot Hi Andy, On 13 September 2017 at 00:14, Andy Yan <andy.yan@rock-chips.com> wrote: > Hi Simon: > > > > On 2017年09月13日 12:26, Simon Glass wrote: >> >> Hi Andy, >> >> On 12 September 2017 at 07:58, Andy Yan <andy.yan@rock-chips.com> wrote: >>> >>> Enter download mode if the download key pressed. >>> >>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com> >>> --- >>> >>> arch/arm/mach-rockchip/boot_mode.c | 27 ++++++++++++++++++++++++++- >>> board/rockchip/evb_rk3399/evb-rk3399.c | 28 >>> ++++++++++++++++++++++++++++ >>> 2 files changed, 54 insertions(+), 1 deletion(-) >>> >>> diff --git a/arch/arm/mach-rockchip/boot_mode.c >>> b/arch/arm/mach-rockchip/boot_mode.c >>> index 7b3cbc5..bff1cbc 100644 >>> --- a/arch/arm/mach-rockchip/boot_mode.c >>> +++ b/arch/arm/mach-rockchip/boot_mode.c >>> @@ -8,11 +8,36 @@ >>> #include <asm/io.h> >>> #include <asm/arch/boot_mode.h> >>> >>> +void set_back_to_bootrom_dnl_flag(void) >>> +{ >>> + writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); >>> +} >>> + >>> +/* >>> + * some boards use a adc key, but some use gpio >>> + */ >>> +__weak int rockchip_dnl_key_pressed(void) >> >> Can you please declare this in a header file and add a full comment as >> to what this does? > > > This function is only used in this file and can be override by other > boards. So I don't > think this is a necessary to declare this in a header file. The reason is that all exported functions should be declared somewhere. Otherwise the function can be used / overridden somewhere else without any argument checking. > Of course, I will add a full comment for it. >>> >>> +{ >>> + return false; >>> +} >>> + >>> +void rockchip_dnl_mode_check(void) >>> +{ >>> + if (rockchip_dnl_key_pressed()) { >>> + printf("download key pressed, enter download mode..."); >> >> should that be 'entering'? > > > Okay, should be 'entering' > >>> + set_back_to_bootrom_dnl_flag(); >>> + do_reset(NULL, 0, 0, NULL); >>> + } >>> +} >>> + >>> int setup_boot_mode(void) >>> { >>> void* reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; >>> - int boot_mode = readl(reg); >>> + int boot_mode; >>> + >>> + rockchip_dnl_mode_check(); >>> >>> + boot_mode = readl(reg); >>> debug("boot mode %x.\n", boot_mode); >>> >>> /* Clear boot mode */ >>> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c >>> b/board/rockchip/evb_rk3399/evb-rk3399.c >>> index d50c59d..738d942 100644 >>> --- a/board/rockchip/evb_rk3399/evb-rk3399.c >>> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c >>> @@ -4,6 +4,7 @@ >>> * SPDX-License-Identifier: GPL-2.0+ >>> */ >>> #include <common.h> >>> +#include <adc.h> >>> #include <dm.h> >>> #include <ram.h> >>> #include <dm/pinctrl.h> >>> @@ -13,6 +14,33 @@ >>> >>> DECLARE_GLOBAL_DATA_PTR; >>> >>> +#define KEY_DOWN_MIN_VAL 1 >>> +#define KEY_DOWN_MAX_VAL 20 >>> + >>> +int rockchip_dnl_key_pressed(void) >>> +{ >>> + unsigned int ret; >>> + unsigned int i; >>> + unsigned int val; >>> + int cnt = 0; >>> + >> >> Please document what is going on here - why the loop? What is the >> check against min/max value? > > > This if for voltage debounce, according to my experience on the rk3399 > evb board, in the 10 adc sample results, > we will met 2 ~ 4 result vals are out of the MIN~MAX range. OK great, please add a comment here about this. > >> >>> + for (i = 0; i < 10; i++) { >>> + ret = adc_channel_single_shot("saradc", 1, &val); >>> + if (ret) { >>> + printf("%s adc_channel_single_shot fail!\n", >>> __func__); >>> + break; >>> + } >>> + >>> + if ((val >= KEY_DOWN_MIN_VAL) && (val <= >>> KEY_DOWN_MAX_VAL)) >>> + cnt++; >>> + } >>> + >>> + if (cnt >= 8) >>> + return true; >>> + else >>> + return false; >>> +} >>> + >>> int board_init(void) >>> { >>> struct udevice *pinctrl, *regulator; >>> -- >>> 2.7.4Regards, Simon ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-09-21 9:04 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-09-12 13:55 [U-Boot] [PATCH 0/3] support enter download mode on rockchip platform Andy Yan 2017-09-12 13:57 ` [U-Boot] [PATCH 1/3] rockchip: make boot_mode releated codes reused across all platforms Andy Yan 2017-09-13 4:26 ` Simon Glass 2017-09-21 9:02 ` Heiko Stuebner 2017-09-21 9:04 ` Andy Yan 2017-09-12 13:57 ` [U-Boot] [PATCH 2/3] rockchip: add support for backing to bootrom download mode Andy Yan 2017-09-13 4:26 ` Simon Glass 2017-09-12 13:58 ` [U-Boot] [PATCH 3/3] rockchip: check download key before bootup Andy Yan 2017-09-13 4:26 ` Simon Glass 2017-09-13 6:14 ` Andy Yan 2017-09-17 17:52 ` Simon Glass
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.