From 102b0b11195ffe421f352d510c15fd6bb0e7c8f3 Mon Sep 17 00:00:00 2001 From: Weijie Gao Date: Mon, 22 Jul 2019 10:35:10 +0800 Subject: [PATCH 01/14] arm: dts: change MT7629 to use spi-mem rather than qspi The original mtk_qspi driver has been removed. We change MT7629 to use newly added mtk-spimem driver. Signed-off-by: Weijie Gao Acked-by: Jagan Teki --- arch/arm/dts/mt7629-rfb.dts | 18 +++++++++++++----- arch/arm/dts/mt7629.dtsi | 14 ++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/arch/arm/dts/mt7629-rfb.dts b/arch/arm/dts/mt7629-rfb.dts index 08c3b59222..0981f9b3b1 100644 --- a/arch/arm/dts/mt7629-rfb.dts +++ b/arch/arm/dts/mt7629-rfb.dts @@ -13,7 +13,7 @@ compatible = "mediatek,mt7629-rfb", "mediatek,mt7629"; aliases { - spi0 = &qspi; + spi0 = &snfi; }; chosen { @@ -33,7 +33,14 @@ }; &pinctrl { - qspi_pins: qspi-pins { + snfi_pins: snfi-pins { + mux { + function = "flash"; + groups = "snfi"; + }; + }; + + snor_pins: snor-pins { mux { function = "flash"; groups = "spi_nor"; @@ -55,9 +62,10 @@ }; }; -&qspi { - pinctrl-names = "default"; - pinctrl-0 = <&qspi_pins>; +&snfi { + pinctrl-names = "default", "snfi"; + pinctrl-0 = <&snor_pins>; + pinctrl-1 = <&snfi_pins>; status = "okay"; spi-flash@0{ diff --git a/arch/arm/dts/mt7629.dtsi b/arch/arm/dts/mt7629.dtsi index ecbd29d7ae..8ff19162f0 100644 --- a/arch/arm/dts/mt7629.dtsi +++ b/arch/arm/dts/mt7629.dtsi @@ -215,10 +215,16 @@ status = "disabled"; }; - qspi: qspi@11014000 { - compatible = "mediatek,mt7629-qspi"; - reg = <0x11014000 0xe0>, <0x30000000 0x10000000>; - reg-names = "reg_base", "mem_base"; + snfi: snfi@1100d000 { + compatible = "mediatek,mtk-snfi-spi"; + reg = <0x1100d000 0x2000>; + clocks = <&pericfg CLK_PERI_NFI_PD>, + <&pericfg CLK_PERI_SNFI_PD>; + clock-names = "nfi_clk", "pad_clk"; + assigned-clocks = <&topckgen CLK_TOP_AXI_SEL>, + <&topckgen CLK_TOP_NFI_INFRA_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_SYSPLL1_D2>, + <&topckgen CLK_TOP_UNIVPLL2_D8>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; From b236f8c086b38a3e43bd57ed3364ab691d47c73f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 27 Jul 2019 20:21:06 +0200 Subject: [PATCH 02/14] log: document the assign() macro Provide a concise description of the assert() macro. Point out that the tested expression is always executed, irrespective of the value of _DEBUG. Signed-off-by: Heinrich Schuchardt --- include/log.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/log.h b/include/log.h index 7566ba7f2d..6d15e955d7 100644 --- a/include/log.h +++ b/include/log.h @@ -183,6 +183,18 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, */ void __assert_fail(const char *assertion, const char *file, unsigned int line, const char *function); + +/** + * assert() - assert expression is true + * + * If the expression x evaluates to false and _DEBUG evaluates to true, a panic + * message is written and the system stalls. The value of _DEBUG is set to true + * if DEBUG is defined before including common.h. + * + * The expression x is always executed irrespective of the value of _DEBUG. + * + * @x: expression to test + */ #define assert(x) \ ({ if (!(x) && _DEBUG) \ __assert_fail(#x, __FILE__, __LINE__, __func__); }) From ecaae801d63bc0549ca681608ba787d96faeb322 Mon Sep 17 00:00:00 2001 From: Heiko Schocher Date: Mon, 29 Jul 2019 07:23:19 +0200 Subject: [PATCH 03/14] autoboot: fix bug using with CAAM and AUTOBOOT_ENCRYPTION if CONFIG_AUTOBOOT_KEYED, CONFIG_AUTOBOOT_ENCRYPTION and CONFIG_AUTOBOOT_STOP_STR_SHA256 are enabled in conjunction with CONFIG_SHA_HW_ACCEL and CONFIG_FSL_CAAM, we get the Error when pressing a key while waiting for bootdelay: Error: Address arguments are not aligned CAAM was not setup properly or it is faulty Reason is, that used variables are not cache aligned, so malloc this variables cache aligned. Probably this is also a bugfix for other hw accelerators than CAAM. Signed-off-by: Heiko Schocher --- common/autoboot.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/autoboot.c b/common/autoboot.c index 42fbd7614a..7a91736a00 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -71,8 +72,8 @@ static int passwd_abort_sha256(uint64_t etime) { const char *sha_env_str = env_get("bootstopkeysha256"); u8 sha_env[SHA256_SUM_LEN]; - u8 sha[SHA256_SUM_LEN]; - char presskey[MAX_DELAY_STOP_STR]; + u8 *sha; + char *presskey; const char *algo_name = "sha256"; u_int presskey_len = 0; int abort = 0; @@ -93,6 +94,9 @@ static int passwd_abort_sha256(uint64_t etime) return 0; } + presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); + sha = malloc_cache_aligned(SHA256_SUM_LEN); + size = SHA256_SUM_LEN; /* * We don't know how long the stop-string is, so we need to * generate the sha256 hash upon each input character and @@ -101,8 +105,11 @@ static int passwd_abort_sha256(uint64_t etime) do { if (tstc()) { /* Check for input string overflow */ - if (presskey_len >= MAX_DELAY_STOP_STR) + if (presskey_len >= MAX_DELAY_STOP_STR) { + free(presskey); + free(sha); return 0; + } presskey[presskey_len++] = getc(); @@ -116,6 +123,8 @@ static int passwd_abort_sha256(uint64_t etime) } } while (!abort && get_ticks() <= etime); + free(presskey); + free(sha); return abort; } From 8702e614d94adc9df8f58f97d47d39319727d190 Mon Sep 17 00:00:00 2001 From: Ryder Lee Date: Mon, 29 Jul 2019 22:17:46 +0800 Subject: [PATCH 04/14] MAINTAINERS: MediaTek: add MediaTek team in the entry Add MediaTek team as designated reviewer. Signed-off-by: Ryder Lee --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 182c9c7fc2..b443c5af75 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -196,6 +196,7 @@ F: arch/arm/include/asm/arch-pxa/ ARM MEDIATEK M: Ryder Lee M: Weijie Gao +R: GSS_MTK_Uboot_upstream S: Maintained F: arch/arm/mach-mediatek/ F: arch/arm/include/asm/arch-mediatek/ From 4f3ee271eb3e0fb76d7c5406e5f18549dc318a9f Mon Sep 17 00:00:00 2001 From: Ryder Lee Date: Mon, 29 Jul 2019 22:17:47 +0800 Subject: [PATCH 05/14] ARM: dts: add hifsys reset for MediaTek SoCs This adds missing hifsys reset parts in header files. Tested-by: Frank Wunderlich Signed-off-by: Ryder Lee --- arch/arm/dts/mt7623.dtsi | 7 +++++++ include/dt-bindings/reset/mtk-reset.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/dts/mt7623.dtsi b/arch/arm/dts/mt7623.dtsi index 448d1d7381..64079c61bf 100644 --- a/arch/arm/dts/mt7623.dtsi +++ b/arch/arm/dts/mt7623.dtsi @@ -248,6 +248,13 @@ status = "disabled"; }; + hifsys: syscon@1a000000 { + compatible = "mediatek,mt7623-hifsys", "syscon"; + reg = <0x1a000000 0x1000>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + ethsys: syscon@1b000000 { compatible = "mediatek,mt7623-ethsys", "syscon"; reg = <0x1b000000 0x1000>; diff --git a/include/dt-bindings/reset/mtk-reset.h b/include/dt-bindings/reset/mtk-reset.h index 5f0a74f280..78fcdab009 100644 --- a/include/dt-bindings/reset/mtk-reset.h +++ b/include/dt-bindings/reset/mtk-reset.h @@ -15,4 +15,13 @@ #define ETHSYS_MCM_RST 2 #define ETHSYS_SYS_RST 0 +/* HIFSYS resets */ +#define HIFSYS_PCIE2_RST 26 +#define HIFSYS_PCIE1_RST 25 +#define HIFSYS_PCIE0_RST 24 +#define HIFSYS_UPHY1_RST 22 +#define HIFSYS_UPHY0_RST 21 +#define HIFSYS_UHOST1_RST 4 +#define HIFSYS_UHOST0_RST 3 + #endif /* _DT_BINDINGS_MTK_RESET_H_ */ From 2d88b5a38eda720b028818c039e08b8d6dea6cc6 Mon Sep 17 00:00:00 2001 From: Ryder Lee Date: Mon, 29 Jul 2019 22:17:48 +0800 Subject: [PATCH 06/14] clk: MediaTek: add hifsys entry for MT7623 SoC. This adds high speed interface subsystem - hifsys (i.e. PCIe and USB) for MT7623 SoC and enables its reset controller. The control block is shared with ethsys and accordingly rename the related defines. Tested-by: Frank Wunderlich Signed-off-by: Ryder Lee --- drivers/clk/mediatek/clk-mt7623.c | 68 ++++++++++++++++++++++--------- drivers/clk/mediatek/clk-mt7629.c | 4 +- drivers/clk/mediatek/clk-mtk.h | 2 +- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/drivers/clk/mediatek/clk-mt7623.c b/drivers/clk/mediatek/clk-mt7623.c index 87ad4f79ce..dfce32e283 100644 --- a/drivers/clk/mediatek/clk-mt7623.c +++ b/drivers/clk/mediatek/clk-mt7623.c @@ -691,34 +691,42 @@ static const struct mtk_gate peri_cgs[] = { GATE_PERI1(CLK_PERI_FCI, CLK_TOP_MS_CARD_SEL, 11), }; -/* ethsys */ -static const struct mtk_gate_regs eth_cg_regs = { +/* ethsys and hifsys */ +static const struct mtk_gate_regs eth_hif_cg_regs = { .sta_ofs = 0x30, }; -#define GATE_ETH(_id, _parent, _shift, _flag) { \ +#define GATE_ETH_HIF(_id, _parent, _shift, _flag) { \ .id = _id, \ .parent = _parent, \ - .regs = ð_cg_regs, \ + .regs = ð_hif_cg_regs, \ .shift = _shift, \ .flags = CLK_GATE_NO_SETCLR_INV | (_flag), \ } -#define GATE_ETH0(_id, _parent, _shift) \ - GATE_ETH(_id, _parent, _shift, CLK_PARENT_APMIXED) +#define GATE_ETH_HIF0(_id, _parent, _shift) \ + GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_APMIXED) -#define GATE_ETH1(_id, _parent, _shift) \ - GATE_ETH(_id, _parent, _shift, CLK_PARENT_TOPCKGEN) +#define GATE_ETH_HIF1(_id, _parent, _shift) \ + GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_TOPCKGEN) static const struct mtk_gate eth_cgs[] = { - GATE_ETH1(CLK_ETHSYS_HSDMA, CLK_TOP_ETHIF_SEL, 5), - GATE_ETH1(CLK_ETHSYS_ESW, CLK_TOP_ETHPLL_500M, 6), - GATE_ETH0(CLK_ETHSYS_GP2, CLK_APMIXED_TRGPLL, 7), - GATE_ETH1(CLK_ETHSYS_GP1, CLK_TOP_ETHPLL_500M, 8), - GATE_ETH1(CLK_ETHSYS_PCM, CLK_TOP_ETHIF_SEL, 11), - GATE_ETH1(CLK_ETHSYS_GDMA, CLK_TOP_ETHIF_SEL, 14), - GATE_ETH1(CLK_ETHSYS_I2S, CLK_TOP_ETHIF_SEL, 17), - GATE_ETH1(CLK_ETHSYS_CRYPTO, CLK_TOP_ETHIF_SEL, 29), + GATE_ETH_HIF1(CLK_ETHSYS_HSDMA, CLK_TOP_ETHIF_SEL, 5), + GATE_ETH_HIF1(CLK_ETHSYS_ESW, CLK_TOP_ETHPLL_500M, 6), + GATE_ETH_HIF0(CLK_ETHSYS_GP2, CLK_APMIXED_TRGPLL, 7), + GATE_ETH_HIF1(CLK_ETHSYS_GP1, CLK_TOP_ETHPLL_500M, 8), + GATE_ETH_HIF1(CLK_ETHSYS_PCM, CLK_TOP_ETHIF_SEL, 11), + GATE_ETH_HIF1(CLK_ETHSYS_GDMA, CLK_TOP_ETHIF_SEL, 14), + GATE_ETH_HIF1(CLK_ETHSYS_I2S, CLK_TOP_ETHIF_SEL, 17), + GATE_ETH_HIF1(CLK_ETHSYS_CRYPTO, CLK_TOP_ETHIF_SEL, 29), +}; + +static const struct mtk_gate hif_cgs[] = { + GATE_ETH_HIF1(CLK_HIFSYS_USB0PHY, CLK_TOP_ETHPLL_500M, 21), + GATE_ETH_HIF1(CLK_HIFSYS_USB1PHY, CLK_TOP_ETHPLL_500M, 22), + GATE_ETH_HIF1(CLK_HIFSYS_PCIE0, CLK_TOP_ETHPLL_500M, 24), + GATE_ETH_HIF1(CLK_HIFSYS_PCIE1, CLK_TOP_ETHPLL_500M, 25), + GATE_ETH_HIF1(CLK_HIFSYS_PCIE2, CLK_TOP_ETHPLL_500M, 26), }; static const struct mtk_clk_tree mt7623_clk_tree = { @@ -778,19 +786,24 @@ static int mt7623_pericfg_probe(struct udevice *dev) return mtk_common_clk_gate_init(dev, &mt7623_clk_tree, peri_cgs); } +static int mt7623_hifsys_probe(struct udevice *dev) +{ + return mtk_common_clk_gate_init(dev, &mt7623_clk_tree, hif_cgs); +} + static int mt7623_ethsys_probe(struct udevice *dev) { return mtk_common_clk_gate_init(dev, &mt7623_clk_tree, eth_cgs); } -static int mt7623_ethsys_bind(struct udevice *dev) +static int mt7623_ethsys_hifsys_bind(struct udevice *dev) { int ret = 0; #if CONFIG_IS_ENABLED(RESET_MEDIATEK) - ret = mediatek_reset_bind(dev, ETHSYS_RST_CTRL_OFS, 1); + ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1); if (ret) - debug("Warning: failed to bind ethsys reset controller\n"); + debug("Warning: failed to bind reset controller\n"); #endif return ret; @@ -821,6 +834,11 @@ static const struct udevice_id mt7623_ethsys_compat[] = { { } }; +static const struct udevice_id mt7623_hifsys_compat[] = { + { .compatible = "mediatek,mt7623-hifsys" }, + { } +}; + static const struct udevice_id mt7623_mcucfg_compat[] = { { .compatible = "mediatek,mt7623-mcucfg" }, { } @@ -874,12 +892,22 @@ U_BOOT_DRIVER(mtk_clk_pericfg) = { .flags = DM_FLAG_PRE_RELOC, }; +U_BOOT_DRIVER(mtk_clk_hifsys) = { + .name = "mt7623-clock-hifsys", + .id = UCLASS_CLK, + .of_match = mt7623_hifsys_compat, + .probe = mt7623_hifsys_probe, + .bind = mt7623_ethsys_hifsys_bind, + .priv_auto_alloc_size = sizeof(struct mtk_cg_priv), + .ops = &mtk_clk_gate_ops, +}; + U_BOOT_DRIVER(mtk_clk_ethsys) = { .name = "mt7623-clock-ethsys", .id = UCLASS_CLK, .of_match = mt7623_ethsys_compat, .probe = mt7623_ethsys_probe, - .bind = mt7623_ethsys_bind, + .bind = mt7623_ethsys_hifsys_bind, .priv_auto_alloc_size = sizeof(struct mtk_cg_priv), .ops = &mtk_clk_gate_ops, }; diff --git a/drivers/clk/mediatek/clk-mt7629.c b/drivers/clk/mediatek/clk-mt7629.c index 6a9f60139c..30a919f224 100644 --- a/drivers/clk/mediatek/clk-mt7629.c +++ b/drivers/clk/mediatek/clk-mt7629.c @@ -608,9 +608,9 @@ static int mt7629_ethsys_bind(struct udevice *dev) int ret = 0; #if CONFIG_IS_ENABLED(RESET_MEDIATEK) - ret = mediatek_reset_bind(dev, ETHSYS_RST_CTRL_OFS, 1); + ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1); if (ret) - debug("Warning: failed to bind ethsys reset controller\n"); + debug("Warning: failed to bind reset controller\n"); #endif return ret; diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 7847388b2a..dce93253ad 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -23,7 +23,7 @@ #define CLK_PARENT_TOPCKGEN BIT(5) #define CLK_PARENT_MASK GENMASK(5, 4) -#define ETHSYS_RST_CTRL_OFS 0x34 +#define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34 /* struct mtk_pll_data - hardware-specific PLLs data */ struct mtk_pll_data { From 6948f1023f3aa382bb023f115929ab3106edb7ee Mon Sep 17 00:00:00 2001 From: Ramon Fried Date: Wed, 31 Jul 2019 11:04:26 +0300 Subject: [PATCH 07/14] pci_ep: Fix Coverity warning Fix the following Coverity warning: CID 244086: Incorrect expression (BAD_COMPARE) Comparing pointer "ep_bar" against NULL using anything besides == or is likely to be incorrect. Fixes: 914026d25848 ("drivers: pci_ep: Introduce UCLASS_PCI_EP uclass") Signed-off-by: Ramon Fried --- drivers/pci_endpoint/pci_ep-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci_endpoint/pci_ep-uclass.c b/drivers/pci_endpoint/pci_ep-uclass.c index 2f9c70398d..9f53a9a9b9 100644 --- a/drivers/pci_endpoint/pci_ep-uclass.c +++ b/drivers/pci_endpoint/pci_ep-uclass.c @@ -43,7 +43,7 @@ int pci_ep_set_bar(struct udevice *dev, uint func_no, struct pci_bar *ep_bar) int flags = ep_bar->flags; /* Some basic bar validity checks */ - if (ep_bar->barno > BAR_5 || ep_bar < BAR_0) + if (ep_bar->barno > BAR_5 || ep_bar->barno < BAR_0) return -EINVAL; if ((ep_bar->barno == BAR_5 && From f254bd02a0754402feaed2e5ec5aba4c5f1512e1 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Wed, 31 Jul 2019 19:59:08 +0300 Subject: [PATCH 08/14] avb: Fix build when CONFIG_OPTEE_TA_AVB is disabled When having only these AVB related configs enabled: CONFIG_AVB_VERIFY=y CONFIG_CMD_AVB=y CONFIG_LIBAVB=y build fails with next errors: common/avb_verify.c: In function 'read_persistent_value': common/avb_verify.c:867:6: warning: implicit declaration of function 'get_open_session' common/avb_verify.c:870:45: error: 'struct AvbOpsData' has no member named 'tee' common/avb_verify.c:894:7: warning: implicit declaration of function 'invoke_func' common/avb_verify.c: In function 'write_persistent_value': common/avb_verify.c:931:45: error: 'struct AvbOpsData' has no member named 'tee' Guard read_persistent_value() and write_persistent_value() functions by checking if CONFIG_OPTEE_TA_AVB is enabled (as those are only used in that case) to fix the build with mentioned configuration. Signed-off-by: Sam Protsenko Reviewed-by: Igor Opaniuk --- common/avb_verify.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/avb_verify.c b/common/avb_verify.c index 32034d927c..36898a610f 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -851,6 +851,7 @@ static AvbIOResult get_size_of_partition(AvbOps *ops, return AVB_IO_RESULT_OK; } +#ifdef CONFIG_OPTEE_TA_AVB static AvbIOResult read_persistent_value(AvbOps *ops, const char *name, size_t buffer_size, @@ -968,6 +969,8 @@ free_name: return rc; } +#endif + /** * ============================================================================ * AVB2.0 AvbOps alloc/initialisation/free From 97f3c09706543205f7a2f6fa91e110946c302fcb Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Wed, 31 Jul 2019 19:59:09 +0300 Subject: [PATCH 09/14] cmd: avb: Fix compiler warnings When building U-Boot with AVB enabled, compiler shows next warnings: cmd/avb.c: In function 'do_avb_read_pvalue': cmd/avb.c:371:18: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' {aka 'unsigned int'} [-Wformat=] printf("Read %ld bytes, value = %s\n", bytes_read, ~~^ ~~~~~~~~~~ %d cmd/avb.c: In function 'do_avb_write_pvalue': cmd/avb.c:404:19: warning: format '%ld' expects argument of type 'long int', but argument 2 has type '__kernel_size_t' {aka 'unsigned int'} [-Wformat=] printf("Wrote %ld bytes\n", strlen(value) + 1); ~~^ ~~~~~~~~~~~~~~~~~ %d Fix those by using "%zu" specified. Signed-off-by: Sam Protsenko Reviewed-by: Igor Opaniuk --- cmd/avb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index c5af4a2e46..3f6fd763a0 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -368,7 +368,7 @@ int do_avb_read_pvalue(cmd_tbl_t *cmdtp, int flag, int argc, if (avb_ops->read_persistent_value(avb_ops, name, bytes, buffer, &bytes_read) == AVB_IO_RESULT_OK) { - printf("Read %ld bytes, value = %s\n", bytes_read, + printf("Read %zu bytes, value = %s\n", bytes_read, (char *)buffer); free(buffer); return CMD_RET_SUCCESS; @@ -401,7 +401,7 @@ int do_avb_write_pvalue(cmd_tbl_t *cmdtp, int flag, int argc, if (avb_ops->write_persistent_value(avb_ops, name, strlen(value) + 1, (const uint8_t *)value) == AVB_IO_RESULT_OK) { - printf("Wrote %ld bytes\n", strlen(value) + 1); + printf("Wrote %zu bytes\n", strlen(value) + 1); return CMD_RET_SUCCESS; } From bf46be72163d90797d3ee5252395da69c6fc2e6b Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 2 Aug 2019 14:58:09 +0200 Subject: [PATCH 10/14] console: update silent tag after env load Update the "silent" property with the variable "silent" get from saved environment, it solves the issue when: - CONFIG_SILENT_CONSOLE and CONFIG_SYS_CONSOLE_IS_IN_ENV are activated - silent is not defined in default environment - silent is requested in saved environment with: > env set silent 1; env save On next reboot the console is not disabled as expected after relocation and the environment load from flash (the callback is not called when the INSERT is requested in the created hash table) Signed-off-by: Patrick Delaunay Signed-off-by: Patrice Chotard --- common/console.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/console.c b/common/console.c index 0b0dd76256..7b45403bb3 100644 --- a/common/console.c +++ b/common/console.c @@ -793,6 +793,9 @@ int console_init_r(void) int iomux_err = 0; #endif + /* update silent for env loaded from flash (initr_env) */ + console_update_silent(); + /* set default handlers at first */ gd->jt->getc = serial_getc; gd->jt->tstc = serial_tstc; @@ -884,6 +887,7 @@ int console_init_r(void) struct list_head *pos; struct stdio_dev *dev; + /* update silent for env loaded from flash (initr_env) */ console_update_silent(); #ifdef CONFIG_SPLASH_SCREEN From 13551b911416044dede2311935f34b29095c8dba Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 2 Aug 2019 14:58:10 +0200 Subject: [PATCH 11/14] console: execute flush on uart when silent is removed Avoid to flush buffer when silent console is activated as the console can be reactivate later, after relocation, when the env will be updated with the saved one. Solve issue (missing beginning of U-Boot trace) when: - CONFIG_SILENT_CONSOLE is activated - silent=1 is defined in default environment (CONFIG_EXTRA_ENV_SETTINGS) - silent is removed in saved environment with: > env delete silent; env save Only functional when PRE_CONSOLE_BUFFER is activated. Signed-off-by: Patrick Delaunay Signed-off-by: Patrice Chotard --- common/console.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/common/console.c b/common/console.c index 7b45403bb3..d086feabb1 100644 --- a/common/console.c +++ b/common/console.c @@ -463,6 +463,11 @@ static void print_pre_console_buffer(int flushpoint) char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; char *buf_in; +#ifdef CONFIG_SILENT_CONSOLE + if (gd->flags & GD_FLG_SILENT) + return; +#endif + buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; @@ -511,8 +516,11 @@ void putc(const char c) membuff_putbyte(&gd->console_out, c); #endif #ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) + if (gd->flags & GD_FLG_SILENT) { + if (!(gd->flags & GD_FLG_DEVINIT)) + pre_console_putc(c); return; + } #endif #ifdef CONFIG_DISABLE_CONSOLE @@ -559,8 +567,11 @@ void puts(const char *s) membuff_put(&gd->console_out, s, strlen(s)); #endif #ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) + if (gd->flags & GD_FLG_SILENT) { + if (!(gd->flags & GD_FLG_DEVINIT)) + pre_console_puts(s); return; + } #endif #ifdef CONFIG_DISABLE_CONSOLE @@ -720,14 +731,22 @@ int console_assign(int file, const char *devname) return -1; } -static void console_update_silent(void) +/* return true if the 'silent' flag is removed */ +static bool console_update_silent(void) { #ifdef CONFIG_SILENT_CONSOLE - if (env_get("silent") != NULL) + if (env_get("silent")) { gd->flags |= GD_FLG_SILENT; - else + } else { + unsigned long flags = gd->flags; + gd->flags &= ~GD_FLG_SILENT; + + return !!(flags & GD_FLG_SILENT); + } #endif + + return false; } int console_announce_r(void) @@ -792,9 +811,13 @@ int console_init_r(void) #if CONFIG_IS_ENABLED(CONSOLE_MUX) int iomux_err = 0; #endif + int flushpoint; /* update silent for env loaded from flash (initr_env) */ - console_update_silent(); + if (console_update_silent()) + flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL; + else + flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL; /* set default handlers at first */ gd->jt->getc = serial_getc; @@ -872,7 +895,7 @@ done: if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) return 0; #endif - print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); + print_pre_console_buffer(flushpoint); return 0; } @@ -886,9 +909,13 @@ int console_init_r(void) struct list_head *list = stdio_get_list(); struct list_head *pos; struct stdio_dev *dev; + int flushpoint; /* update silent for env loaded from flash (initr_env) */ - console_update_silent(); + if (console_update_silent()) + flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL; + else + flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL; #ifdef CONFIG_SPLASH_SCREEN /* @@ -951,7 +978,7 @@ int console_init_r(void) if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) return 0; #endif - print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); + print_pre_console_buffer(flushpoint); return 0; } From bddd985734653c366c8da073650930fb2e9b5003 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 2 Aug 2019 15:52:28 -0700 Subject: [PATCH 12/14] fit: Do not automatically decompress ramdisk images The Linux ramdisk should always be decompressed by the kernel itself, not by U-Boot. Therefore, the 'compression' node in the FIT image should always be set to "none" for ramdisk images, since the only point of using that node is if you want U-Boot to do the decompression itself. Yet some systems populate the node to the compression algorithm used by the kernel instead. This used to be ignored, but now that we support decompression of all image types it becomes a problem. Since ramdisks should never be decompressed by U-Boot anyway, this patch adds a special exception for them to avoid these issues. Still, setting the 'compression' node like that is wrong in the first place, so we still want to print out a warning so that third-party distributions doing this can notice and fix it. Signed-off-by: Julius Werner Reviewed-by: Heiko Schocher Tested-by: Heiko Schocher Reviewed-by: Simon Goldschmidt --- common/image-fit.c | 13 +++++++++---- test/py/tests/test_fit.py | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index e346fed550..5c63c769de 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1998,10 +1998,11 @@ int fit_image_load(bootm_headers_t *images, ulong addr, comp = IH_COMP_NONE; loadbuf = buf; /* Kernel images get decompressed later in bootm_load_os(). */ - if (!(image_type == IH_TYPE_KERNEL || - image_type == IH_TYPE_KERNEL_NOLOAD) && - !fit_image_get_comp(fit, noffset, &comp) && - comp != IH_COMP_NONE) { + if (!fit_image_get_comp(fit, noffset, &comp) && + comp != IH_COMP_NONE && + !(image_type == IH_TYPE_KERNEL || + image_type == IH_TYPE_KERNEL_NOLOAD || + image_type == IH_TYPE_RAMDISK)) { ulong max_decomp_len = len * 20; if (load == data) { loadbuf = malloc(max_decomp_len); @@ -2021,6 +2022,10 @@ int fit_image_load(bootm_headers_t *images, ulong addr, memcpy(loadbuf, buf, len); } + if (image_type == IH_TYPE_RAMDISK && comp != IH_COMP_NONE) + puts("WARNING: 'compression' nodes for ramdisks are deprecated," + " please fix your .its file!\n"); + /* verify that image data is a proper FDT blob */ if (image_type == IH_TYPE_FLATDT && fdt_check_header(loadbuf)) { puts("Subimage data is not a FDT"); diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 8009d2907b..e3210ed43f 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -269,6 +269,11 @@ def test_fit(u_boot_console): def check_equal(expected_fname, actual_fname, failure_msg): """Check that a file matches its expected contents + This is always used on out-buffers whose size is decided by the test + script anyway, which in some cases may be larger than what we're + actually looking for. So it's safe to truncate it to the size of the + expected data. + Args: expected_fname: Filename containing expected contents actual_fname: Filename containing actual contents @@ -276,6 +281,8 @@ def test_fit(u_boot_console): """ expected_data = read_file(expected_fname) actual_data = read_file(actual_fname) + if len(expected_data) < len(actual_data): + actual_data = actual_data[:len(expected_data)] assert expected_data == actual_data, failure_msg def check_not_equal(expected_fname, actual_fname, failure_msg): @@ -435,7 +442,8 @@ def test_fit(u_boot_console): output = cons.run_command_list(cmd.splitlines()) check_equal(kernel, kernel_out, 'Kernel not loaded') check_equal(control_dtb, fdt_out, 'FDT not loaded') - check_equal(ramdisk, ramdisk_out, 'Ramdisk not loaded') + check_not_equal(ramdisk, ramdisk_out, 'Ramdisk got decompressed?') + check_equal(ramdisk + '.gz', ramdisk_out, 'Ramdist not loaded') cons = u_boot_console From 24434adbd1c73b59bff3c42691e26cc52cdb262a Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Mon, 5 Aug 2019 20:11:03 +0300 Subject: [PATCH 13/14] common: image-android-dt: Fix logic in print fdt info routine Do not attempt to print fdt info if root node wasn't found. Signed-off-by: Sam Protsenko --- common/image-android-dt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/image-android-dt.c b/common/image-android-dt.c index 6916826179..a2d52df4a2 100644 --- a/common/image-android-dt.c +++ b/common/image-android-dt.c @@ -78,17 +78,18 @@ static void android_dt_print_fdt_info(const struct fdt_header *fdt) { u32 fdt_size; int root_node_off; - const char *compatible = NULL; + const char *compatible; - fdt_size = fdt_totalsize(fdt); root_node_off = fdt_path_offset(fdt, "/"); if (root_node_off < 0) { printf("Error: Root node not found\n"); - } else { - compatible = fdt_getprop(fdt, root_node_off, "compatible", - NULL); + return; } + fdt_size = fdt_totalsize(fdt); + compatible = fdt_getprop(fdt, root_node_off, "compatible", + NULL); + printf(" (FDT)size = %d\n", fdt_size); printf(" (FDT)compatible = %s\n", compatible ? compatible : "(unknown)"); From 0b6febfdb3cf9b4a51fa65fbd94f9ab2d7738f32 Mon Sep 17 00:00:00 2001 From: Alex Deymo Date: Mon, 5 Aug 2019 22:24:45 +0200 Subject: [PATCH 14/14] Update include/android_image.h from AOSP This takes the latest changes from AOSP from the file include/bootimg/bootimg.h from the repository: https://android.googlesource.com/platform/system/tools/mkbootimg and update the U-Boot version with the latest changes. This file keeps the changes from AOSP to a minimum: * Comments were converted from C++ to C style. * Code inside __cplusplus #ifdef blocks were removed. * C++11 struct extensions replaced with a single struct. Signed-off-by: Alex Deymo Reviewed-by: Sam Protsenko --- include/android_image.h | 120 ++++++++++++++++++++++++++++++---------- 1 file changed, 90 insertions(+), 30 deletions(-) diff --git a/include/android_image.h b/include/android_image.h index d78db9e2b7..0519ece368 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -1,59 +1,78 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * This is from the Android Project, - * Repository: https://android.googlesource.com/platform/system/core/ - * File: mkbootimg/bootimg.h - * Commit: d162828814b08ada310846a33205befb69ef5799 + * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg + * File: include/bootimg/bootimg.h + * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f * - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2007 The Android Open Source Project */ #ifndef _ANDROID_IMAGE_H_ #define _ANDROID_IMAGE_H_ -typedef struct andr_img_hdr andr_img_hdr; - #define ANDR_BOOT_MAGIC "ANDROID!" #define ANDR_BOOT_MAGIC_SIZE 8 #define ANDR_BOOT_NAME_SIZE 16 #define ANDR_BOOT_ARGS_SIZE 512 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 +/* + * It is expected that callers would explicitly specify which version of the + * boot image header they need to use. + */ +typedef struct andr_img_hdr andr_img_hdr; + +/* The bootloader expects the structure of andr_img_hdr with header + * version 0 to be as follows: */ struct andr_img_hdr { - char magic[ANDR_BOOT_MAGIC_SIZE]; + /* Must be ANDR_BOOT_MAGIC. */ + char magic[ANDR_BOOT_MAGIC_SIZE]; - u32 kernel_size; /* size in bytes */ - u32 kernel_addr; /* physical load addr */ + u32 kernel_size; /* size in bytes */ + u32 kernel_addr; /* physical load addr */ - u32 ramdisk_size; /* size in bytes */ - u32 ramdisk_addr; /* physical load addr */ + u32 ramdisk_size; /* size in bytes */ + u32 ramdisk_addr; /* physical load addr */ - u32 second_size; /* size in bytes */ - u32 second_addr; /* physical load addr */ + u32 second_size; /* size in bytes */ + u32 second_addr; /* physical load addr */ - u32 tags_addr; /* physical addr for kernel tags */ - u32 page_size; /* flash page size we assume */ - u32 unused; /* reserved for future expansion: MUST be 0 */ + u32 tags_addr; /* physical addr for kernel tags */ + u32 page_size; /* flash page size we assume */ - /* operating system version and security patch level; for - * version "A.B.C" and patch level "Y-M-D": - * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C) - * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M) - * os_version = ver << 11 | lvl */ - u32 os_version; + /* Version of the boot image header. */ + u32 header_version; - char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */ + /* Operating system version and security patch level. + * For version "A.B.C" and patch level "Y-M-D": + * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) + * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ + u32 os_version; - char cmdline[ANDR_BOOT_ARGS_SIZE]; + char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */ - u32 id[8]; /* timestamp / checksum / sha1 / etc */ + char cmdline[ANDR_BOOT_ARGS_SIZE]; - /* Supplemental command line data; kept here to maintain - * binary compatibility with older versions of mkbootimg */ - char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE]; + u32 id[8]; /* timestamp / checksum / sha1 / etc */ + + /* Supplemental command line data; kept here to maintain + * binary compatibility with older versions of mkbootimg. */ + char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE]; + + /* Fields in boot_img_hdr_v1 and newer. */ + u32 recovery_dtbo_size; /* size in bytes for recovery DTBO/ACPIO image */ + u64 recovery_dtbo_offset; /* offset to recovery dtbo/acpio in boot image */ + u32 header_size; + + /* Fields in boot_img_hdr_v2 and newer. */ + u32 dtb_size; /* size in bytes for DTB image */ + u64 dtb_addr; /* physical load address for DTB image */ } __attribute__((packed)); -/* +/* When a boot header is of version 0, the structure of boot image is as + * follows: + * * +-----------------+ * | boot header | 1 page * +-----------------+ @@ -79,4 +98,45 @@ struct andr_img_hdr { * 6. if second_size != 0: jump to second_addr * else: jump to kernel_addr */ + +/* When the boot image header has a version of 2, the structure of the boot + * image is as follows: + * + * +---------------------+ + * | boot header | 1 page + * +---------------------+ + * | kernel | n pages + * +---------------------+ + * | ramdisk | m pages + * +---------------------+ + * | second stage | o pages + * +---------------------+ + * | recovery dtbo/acpio | p pages + * +---------------------+ + * | dtb | q pages + * +---------------------+ + + * n = (kernel_size + page_size - 1) / page_size + * m = (ramdisk_size + page_size - 1) / page_size + * o = (second_size + page_size - 1) / page_size + * p = (recovery_dtbo_size + page_size - 1) / page_size + * q = (dtb_size + page_size - 1) / page_size + * + * 0. all entities are page_size aligned in flash + * 1. kernel, ramdisk and DTB are required (size != 0) + * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B + * devices(recovery_dtbo_size != 0) + * 3. second is optional (second_size == 0 -> no second) + * 4. load each element (kernel, ramdisk, second, dtb) at + * the specified physical address (kernel_addr, etc) + * 5. If booting to recovery mode in a non-A/B device, extract recovery + * dtbo/acpio and apply the correct set of overlays on the base device tree + * depending on the hardware/product revision. + * 6. prepare tags at tag_addr. kernel_args[] is + * appended to the kernel commandline in the tags. + * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr + * 8. if second_size != 0: jump to second_addr + * else: jump to kernel_addr + */ + #endif