From 8ce1f10cf2b139258c890774f263bec55c4df8ce Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 13 Feb 2020 19:29:50 +0100 Subject: [PATCH 01/25] ARM: bootm: take into account gd->ram_top If gd->ram_top has been tuned using board_get_usable_ram_top(), it must be taken into account when reserving arch lmb. Signed-off-by: Patrice Chotard Reviewed-by: Patrick DELAUNAY Signed-off-by: Patrick Delaunay --- arch/arm/lib/bootm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index a135bcfc7b..f4b5ca6de0 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -75,6 +75,9 @@ void arch_lmb_reserve(struct lmb *lmb) gd->bd->bi_dram[bank].size - 1; if (sp > bank_end) continue; + if (bank_end > gd->ram_top) + bank_end = gd->ram_top - 1; + lmb_reserve(lmb, sp, bank_end - sp + 1); break; } From 46d9d1c306967780d7afbfcbf942daf9ab33c466 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Tue, 18 Feb 2020 08:54:09 +0000 Subject: [PATCH 02/25] env: make file-scope env_ptr variables static The combination ENV_IS_IN_NVRAM=y, ENV_IS_IN_REMOTE=y fails to build: env/remote.o:/mnt/ext4/devel/u-boot/env/remote.c:17: multiple definition of `env_ptr' env/nvram.o:/mnt/ext4/devel/u-boot/env/nvram.c:41: first defined here It's not necessarily a meaningful combination, but for build-testing it's nice to be able to enable most ENV_IS_IN_* at the same time, and since these env_ptr are not declared anywhere, they really have no reason to have external linkage. nand.c and flash.c similarly already define file-scope static env_ptr variables. Signed-off-by: Rasmus Villemoes --- env/nvram.c | 2 +- env/remote.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/env/nvram.c b/env/nvram.c index a78db21623..1a9fcf1c06 100644 --- a/env/nvram.c +++ b/env/nvram.c @@ -38,7 +38,7 @@ DECLARE_GLOBAL_DATA_PTR; extern void *nvram_read(void *dest, const long src, size_t count); extern void nvram_write(long dest, const void *src, size_t count); #else -env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; +static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; #endif #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE diff --git a/env/remote.c b/env/remote.c index 50d77b8dfe..e3f0608b16 100644 --- a/env/remote.c +++ b/env/remote.c @@ -12,9 +12,9 @@ #include #ifdef ENV_IS_EMBEDDED -env_t *env_ptr = &environment; +static env_t *env_ptr = &environment; #else /* ! ENV_IS_EMBEDDED */ -env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; +static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; #endif /* ENV_IS_EMBEDDED */ DECLARE_GLOBAL_DATA_PTR; From a17322329b3b1526b23f8e1f6573a5d4f737c573 Mon Sep 17 00:00:00 2001 From: Yusuke Ashiduka Date: Thu, 20 Feb 2020 20:48:01 +0900 Subject: [PATCH 03/25] cmd: Add unlz4 command This command is a new command called "unlz4" that decompresses from memory into memory. Used with the CONFIG_CMD_UNLZ4 optionenabled. Signed-off-by: Yusuke Ashiduka [trini: Use %zd / %zX not %ld / %lX in printf] Signed-off-by: Tom Rini --- cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/unlz4.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 cmd/unlz4.c diff --git a/cmd/Kconfig b/cmd/Kconfig index faa133da65..0e2576262d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -770,6 +770,13 @@ config CMD_LZMADEC Support decompressing an LZMA (Lempel-Ziv-Markov chain algorithm) image from memory. +config CMD_UNLZ4 + bool "unlz4" + default y if CMD_BOOTI + select LZ4 + help + Support decompressing an LZ4 image from memory region. + config CMD_UNZIP bool "unzip" default y if CMD_BOOTI diff --git a/cmd/Makefile b/cmd/Makefile index f1dd513a4b..6692ed96c6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -144,6 +144,7 @@ obj-$(CONFIG_CMD_TSI148) += tsi148.o obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_UBIFS) += ubifs.o obj-$(CONFIG_CMD_UNIVERSE) += universe.o +obj-$(CONFIG_CMD_UNLZ4) += unlz4.o obj-$(CONFIG_CMD_UNZIP) += unzip.o obj-$(CONFIG_CMD_VIRTIO) += virtio.o obj-$(CONFIG_CMD_WDT) += wdt.o diff --git a/cmd/unlz4.c b/cmd/unlz4.c new file mode 100644 index 0000000000..5320b378d3 --- /dev/null +++ b/cmd/unlz4.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 + * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved. + */ + +#include +#include +#include +#include + +static int do_unlz4(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long src, dst; + size_t src_len = ~0UL, dst_len = ~0UL; + int ret; + + switch (argc) { + case 4: + src = simple_strtoul(argv[1], NULL, 16); + dst = simple_strtoul(argv[2], NULL, 16); + dst_len = simple_strtoul(argv[3], NULL, 16); + break; + default: + return CMD_RET_USAGE; + } + + ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len); + if (ret) { + printf("Uncompressed err :%d\n", ret); + return 1; + } + + printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len); + env_set_hex("filesize", dst_len); + + return 0; +} + +U_BOOT_CMD(unlz4, 4, 1, do_unlz4, + "lz4 uncompress a memory region", + "srcaddr dstaddr dstsize\n" + "NOTE: Specify the destination size that is sufficiently larger\n" + " than the source size.\n" +); From a537fa4da1599c303bc4a0deb2cafbcadf618e2f Mon Sep 17 00:00:00 2001 From: Sam Shih Date: Fri, 21 Feb 2020 21:01:46 +0800 Subject: [PATCH 04/25] mediatek: pwm: add pwm driver for MediaTek SoCs This driver support the standard PWM API for MediaTek MT7623, MT7622 and MT7629 SoCs Signed-off-by: Sam Shih --- drivers/pwm/Kconfig | 7 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-mtk.c | 188 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 drivers/pwm/pwm-mtk.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 1f36fc78fa..edb3f0f538 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -23,6 +23,13 @@ config PWM_IMX help This PWM is found i.MX27 and later i.MX SoCs. +config PWM_MTK + bool "Enable support for MediaTek PWM" + depends on DM_PWM + help + This PWM is found on MT7622, MT7623, and MT7629. It supports a + programmable period and duty cycle. + config PWM_ROCKCHIP bool "Enable support for the Rockchip PWM" depends on DM_PWM diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index a837c35ed2..2c3a069006 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_DM_PWM) += pwm-uclass.o obj-$(CONFIG_PWM_EXYNOS) += exynos_pwm.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o pwm-imx-util.o +obj-$(CONFIG_PWM_MTK) += pwm-mtk.o obj-$(CONFIG_PWM_ROCKCHIP) += rk_pwm.o obj-$(CONFIG_PWM_SANDBOX) += sandbox_pwm.o obj-$(CONFIG_PWM_TEGRA) += tegra_pwm.o diff --git a/drivers/pwm/pwm-mtk.c b/drivers/pwm/pwm-mtk.c new file mode 100644 index 0000000000..97ed477025 --- /dev/null +++ b/drivers/pwm/pwm-mtk.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 MediaTek Inc. All Rights Reserved. + * + * Author: Sam Shih + */ + +#include +#include +#include +#include +#include +#include +#include + +/* PWM registers and bits definitions */ +#define PWMCON 0x00 +#define PWMHDUR 0x04 +#define PWMLDUR 0x08 +#define PWMGDUR 0x0c +#define PWMWAVENUM 0x28 +#define PWMDWIDTH 0x2c +#define PWM45DWIDTH_FIXUP 0x30 +#define PWMTHRES 0x30 +#define PWM45THRES_FIXUP 0x34 + +#define PWM_CLK_DIV_MAX 7 +#define MAX_PWM_NUM 8 + +#define NSEC_PER_SEC 1000000000L + +static const unsigned int mtk_pwm_reg_offset[] = { + 0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220 +}; + +struct mtk_pwm_soc { + unsigned int num_pwms; + bool pwm45_fixup; +}; + +struct mtk_pwm_priv { + void __iomem *base; + struct clk top_clk; + struct clk main_clk; + struct clk pwm_clks[MAX_PWM_NUM]; + const struct mtk_pwm_soc *soc; +}; + +static void mtk_pwm_w32(struct udevice *dev, uint channel, uint reg, uint val) +{ + struct mtk_pwm_priv *priv = dev_get_priv(dev); + u32 offset = mtk_pwm_reg_offset[channel]; + + writel(val, priv->base + offset + reg); +} + +static int mtk_pwm_set_config(struct udevice *dev, uint channel, + uint period_ns, uint duty_ns) +{ + struct mtk_pwm_priv *priv = dev_get_priv(dev); + u32 clkdiv = 0, clksel = 0, cnt_period, cnt_duty, + reg_width = PWMDWIDTH, reg_thres = PWMTHRES; + u64 resolution; + int ret = 0; + + clk_enable(&priv->top_clk); + clk_enable(&priv->main_clk); + /* Using resolution in picosecond gets accuracy higher */ + resolution = (u64)NSEC_PER_SEC * 1000; + do_div(resolution, clk_get_rate(&priv->pwm_clks[channel])); + cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, resolution); + while (cnt_period > 8191) { + resolution *= 2; + clkdiv++; + cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, + resolution); + if (clkdiv > PWM_CLK_DIV_MAX && clksel == 0) { + clksel = 1; + clkdiv = 0; + resolution = (u64)NSEC_PER_SEC * 1000 * 1625; + do_div(resolution, + clk_get_rate(&priv->pwm_clks[channel])); + cnt_period = DIV_ROUND_CLOSEST_ULL( + (u64)period_ns * 1000, resolution); + clk_enable(&priv->pwm_clks[channel]); + } + } + if (clkdiv > PWM_CLK_DIV_MAX && clksel == 1) { + printf("pwm period %u not supported\n", period_ns); + return -EINVAL; + } + if (priv->soc->pwm45_fixup && channel > 2) { + /* + * PWM[4,5] has distinct offset for PWMDWIDTH and PWMTHRES + * from the other PWMs on MT7623. + */ + reg_width = PWM45DWIDTH_FIXUP; + reg_thres = PWM45THRES_FIXUP; + } + cnt_duty = DIV_ROUND_CLOSEST_ULL((u64)duty_ns * 1000, resolution); + if (clksel == 1) + mtk_pwm_w32(dev, channel, PWMCON, BIT(15) | BIT(3) | clkdiv); + else + mtk_pwm_w32(dev, channel, PWMCON, BIT(15) | clkdiv); + mtk_pwm_w32(dev, channel, reg_width, cnt_period); + mtk_pwm_w32(dev, channel, reg_thres, cnt_duty); + + return ret; +}; + +static int mtk_pwm_set_enable(struct udevice *dev, uint channel, bool enable) +{ + struct mtk_pwm_priv *priv = dev_get_priv(dev); + u32 val = 0; + + val = readl(priv->base); + if (enable) + val |= BIT(channel); + else + val &= ~BIT(channel); + writel(val, priv->base); + + return 0; +}; + +static int mtk_pwm_probe(struct udevice *dev) +{ + struct mtk_pwm_priv *priv = dev_get_priv(dev); + int ret = 0; + int i; + + priv->soc = (struct mtk_pwm_soc *)dev_get_driver_data(dev); + priv->base = (void __iomem *)devfdt_get_addr(dev); + if (!priv->base) + return -EINVAL; + ret = clk_get_by_name(dev, "top", &priv->top_clk); + if (ret < 0) + return ret; + ret = clk_get_by_name(dev, "main", &priv->main_clk); + if (ret < 0) + return ret; + for (i = 0; i < priv->soc->num_pwms; i++) { + char name[8]; + + snprintf(name, sizeof(name), "pwm%d", i + 1); + ret = clk_get_by_name(dev, name, &priv->pwm_clks[i]); + if (ret < 0) + return ret; + } + + return ret; +} + +static const struct pwm_ops mtk_pwm_ops = { + .set_config = mtk_pwm_set_config, + .set_enable = mtk_pwm_set_enable, +}; + +static const struct mtk_pwm_soc mt7622_data = { + .num_pwms = 6, + .pwm45_fixup = false, +}; + +static const struct mtk_pwm_soc mt7623_data = { + .num_pwms = 5, + .pwm45_fixup = true, +}; + +static const struct mtk_pwm_soc mt7629_data = { + .num_pwms = 1, + .pwm45_fixup = false, +}; + +static const struct udevice_id mtk_pwm_ids[] = { + { .compatible = "mediatek,mt7622-pwm", .data = (ulong)&mt7622_data }, + { .compatible = "mediatek,mt7623-pwm", .data = (ulong)&mt7623_data }, + { .compatible = "mediatek,mt7629-pwm", .data = (ulong)&mt7629_data }, + { } +}; + +U_BOOT_DRIVER(mtk_pwm) = { + .name = "mtk_pwm", + .id = UCLASS_PWM, + .of_match = mtk_pwm_ids, + .ops = &mtk_pwm_ops, + .probe = mtk_pwm_probe, + .priv_auto_alloc_size = sizeof(struct mtk_pwm_priv), +}; From 25a1b5efb36179d141996c568186148a8c30f12d Mon Sep 17 00:00:00 2001 From: Sam Shih Date: Fri, 21 Feb 2020 21:01:47 +0800 Subject: [PATCH 05/25] arm: dts: add pwm support for MediaTek SoCs This patch add pwm support for mt7622, mt7623 and mt7629 SoCs Signed-off-by: Sam Shih --- arch/arm/dts/mt7622.dtsi | 19 +++++++++++++++++++ arch/arm/dts/mt7623.dtsi | 17 +++++++++++++++++ arch/arm/dts/mt7629.dtsi | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/arch/arm/dts/mt7622.dtsi b/arch/arm/dts/mt7622.dtsi index 1e8ec9b48b..f9ce0c6c3e 100644 --- a/arch/arm/dts/mt7622.dtsi +++ b/arch/arm/dts/mt7622.dtsi @@ -227,4 +227,23 @@ #clock-cells = <1>; }; + pwm: pwm@11006000 { + compatible = "mediatek,mt7622-pwm"; + reg = <0x11006000 0x1000>; + #clock-cells = <1>; + #pwm-cells = <2>; + interrupts = ; + clocks = <&topckgen CLK_TOP_PWM_SEL>, + <&pericfg CLK_PERI_PWM_PD>, + <&pericfg CLK_PERI_PWM1_PD>, + <&pericfg CLK_PERI_PWM2_PD>, + <&pericfg CLK_PERI_PWM3_PD>, + <&pericfg CLK_PERI_PWM4_PD>, + <&pericfg CLK_PERI_PWM5_PD>, + <&pericfg CLK_PERI_PWM6_PD>; + clock-names = "top", "main", "pwm1", "pwm2", "pwm3", "pwm4", + "pwm5", "pwm6"; + status = "disabled"; + }; + }; diff --git a/arch/arm/dts/mt7623.dtsi b/arch/arm/dts/mt7623.dtsi index 1f45dea575..0452889ef8 100644 --- a/arch/arm/dts/mt7623.dtsi +++ b/arch/arm/dts/mt7623.dtsi @@ -400,4 +400,21 @@ mediatek,ethsys = <ðsys>; status = "disabled"; }; + + pwm: pwm@11006000 { + compatible = "mediatek,mt7623-pwm"; + reg = <0x11006000 0x1000>; + #clock-cells = <1>; + #pwm-cells = <2>; + clocks = <&topckgen CLK_TOP_PWM_SEL>, + <&pericfg CLK_PERI_PWM>, + <&pericfg CLK_PERI_PWM1>, + <&pericfg CLK_PERI_PWM2>, + <&pericfg CLK_PERI_PWM3>, + <&pericfg CLK_PERI_PWM4>, + <&pericfg CLK_PERI_PWM5>; + clock-names = "top", "main", "pwm1", "pwm2", "pwm3", "pwm4", + "pwm5"; + status = "disabled"; + }; }; diff --git a/arch/arm/dts/mt7629.dtsi b/arch/arm/dts/mt7629.dtsi index a33a74a556..644d2da4a8 100644 --- a/arch/arm/dts/mt7629.dtsi +++ b/arch/arm/dts/mt7629.dtsi @@ -281,4 +281,20 @@ reg = <0x1b130000 0x1000>; #clock-cells = <1>; }; + + pwm: pwm@11006000 { + compatible = "mediatek,mt7629-pwm"; + reg = <0x11006000 0x1000>; + #clock-cells = <1>; + #pwm-cells = <2>; + interrupts = ; + clocks = <&topckgen CLK_TOP_PWM_SEL>, + <&pericfg CLK_PERI_PWM_PD>, + <&pericfg CLK_PERI_PWM1_PD>; + clock-names = "top", "main", "pwm1"; + assigned-clocks = <&topckgen CLK_TOP_PWM_SEL>; + assigned-clock-parents = <&topckgen CLK_TOP_UNIVPLL2_D4>; + status = "disabled"; + }; + }; From fd0e30b43b6b2401e68dc32c357869c617d4fdd1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 26 Feb 2020 07:26:26 +0100 Subject: [PATCH 06/25] cmd: fat: remove unused includes Remove unused includes from cmd/fat.c. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- cmd/fat.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/fat.c b/cmd/fat.c index 50df127f6d..abce2f1e0c 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -8,13 +8,7 @@ * Boot support */ #include -#include -#include -#include -#include -#include #include -#include #include #include From e6e9a4f0a9e74a079c10f7650c0386ee49e04e44 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 27 Feb 2020 18:28:00 +0100 Subject: [PATCH 07/25] block: ide: use definitions from include/libata.h Currently ATA commands are defined both in include/libata.h and include/ata.h. Use the command definitions from include/libata.h where applicable. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/block/ide.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 4b8a4eac17..67cc4fbc02 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -231,7 +231,7 @@ unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen, (unsigned char) ((buflen >> 8) & 0xFF)); ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); - ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET); + ide_outb(device, ATA_COMMAND, ATA_CMD_PACKET); udelay(50); mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR; @@ -570,7 +570,7 @@ static void ide_ident(struct blk_desc *dev_desc) /* * Start Ident Command */ - ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT); + ide_outb(device, ATA_COMMAND, ATA_CMD_ID_ATAPI); /* * Wait for completion - ATAPI devices need more time * to become ready @@ -582,7 +582,7 @@ static void ide_ident(struct blk_desc *dev_desc) /* * Start Ident Command */ - ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT); + ide_outb(device, ATA_COMMAND, ATA_CMD_ID_ATA); /* * Wait for completion @@ -966,7 +966,7 @@ ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, /* first check if the drive is in Powersaving mode, if yes, * increase the timeout value */ - ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR); + ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_POWER); udelay(50); c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */ From 04571bec56a53c846f072fb3bc7543586f10ee93 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 27 Feb 2020 18:28:01 +0100 Subject: [PATCH 08/25] ide: remove duplicate defines form include/ata.h ATA commands are already defined in include/libata.h. There is no need to duplicate them in include/ata.h. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- include/ata.h | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/include/ata.h b/include/ata.h index 3f4e4a0234..e35d91941d 100644 --- a/include/ata.h +++ b/include/ata.h @@ -70,43 +70,9 @@ #endif /* ATA_DEVICE */ #define ATA_LBA 0xE0 -/* - * ATA Commands (only mandatory commands listed here) - */ -#define ATA_CMD_READ 0x20 /* Read Sectors (with retries) */ -#define ATA_CMD_READN 0x21 /* Read Sectors ( no retries) */ -#define ATA_CMD_WRITE 0x30 /* Write Sectores (with retries)*/ -#define ATA_CMD_WRITEN 0x31 /* Write Sectors ( no retries)*/ -#define ATA_CMD_VRFY 0x40 /* Read Verify (with retries) */ -#define ATA_CMD_VRFYN 0x41 /* Read verify ( no retries) */ -#define ATA_CMD_SEEK 0x70 /* Seek */ -#define ATA_CMD_DIAG 0x90 /* Execute Device Diagnostic */ -#define ATA_CMD_INIT 0x91 /* Initialize Device Parameters */ -#define ATA_CMD_RD_MULT 0xC4 /* Read Multiple */ -#define ATA_CMD_WR_MULT 0xC5 /* Write Multiple */ -#define ATA_CMD_SETMULT 0xC6 /* Set Multiple Mode */ -#define ATA_CMD_RD_DMA 0xC8 /* Read DMA (with retries) */ -#define ATA_CMD_RD_DMAN 0xC9 /* Read DMS ( no retries) */ -#define ATA_CMD_WR_DMA 0xCA /* Write DMA (with retries) */ -#define ATA_CMD_WR_DMAN 0xCB /* Write DMA ( no retires) */ -#define ATA_CMD_IDENT 0xEC /* Identify Device */ -#define ATA_CMD_SETF 0xEF /* Set Features */ -#define ATA_CMD_CHK_PWR 0xE5 /* Check Power Mode */ - -#define ATA_CMD_READ_EXT 0x24 /* Read Sectors (with retries) with 48bit addressing */ -#define ATA_CMD_WRITE_EXT 0x34 /* Write Sectores (with retries) with 48bit addressing */ -#define ATA_CMD_VRFY_EXT 0x42 /* Read Verify (with retries) with 48bit addressing */ - -#define ATA_CMD_FLUSH 0xE7 /* Flush drive cache */ -#define ATA_CMD_FLUSH_EXT 0xEA /* Flush drive cache, with 48bit addressing */ - /* * ATAPI Commands */ -#define ATAPI_CMD_IDENT 0xA1 /* Identify AT Atachment Packed Interface Device */ -#define ATAPI_CMD_PACKET 0xA0 /* Packed Command */ - - #define ATAPI_CMD_INQUIRY 0x12 #define ATAPI_CMD_REQ_SENSE 0x03 #define ATAPI_CMD_READ_CAP 0x25 From ab5a2b0f7927196143d762b2ad9cdc51b84249b3 Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Sun, 1 Mar 2020 10:47:53 -0800 Subject: [PATCH 09/25] mkimage: fit: don't create image with 0700 permissions commit 7298e422504e ("mkimage: fit: add support to encrypt image with aes") added a new copyfile() function as part of the FIT image creation flow. This function as currently written creates the final image with a mode of 0700 (before umask), differing from the old behavior of 0666. Since there doesn't seem to be any reason to make the image executable or non-group, non-other readable, change the mask to 0666 to preserve the old behavior. Fixes: 7298e422504e ("mkimage: fit: add support to encrypt image with aes") Signed-off-by: Thomas Hebb --- tools/fit_image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index dd61a816c9..4301b5decb 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -642,7 +642,7 @@ static int copyfile(const char *src, const char *dst) goto out; } - fd_dst = open(dst, O_WRONLY | O_CREAT, 0700); + fd_dst = open(dst, O_WRONLY | O_CREAT, 0666); if (fd_dst < 0) { printf("Can't open file %s (%s)\n", dst, strerror(errno)); goto out; From 5fa8811fc2d5bf033e4217806ea7f7ab6e6be05b Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 28 Feb 2020 18:33:36 +0100 Subject: [PATCH 10/25] scripts: add documentation-file-ref-check 'make refcheckdocs' requires scripts/documentation-file-ref-check. Adopt script from Linux v5.6-rc3. Signed-off-by: Heinrich Schuchardt --- scripts/documentation-file-ref-check | 226 +++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100755 scripts/documentation-file-ref-check diff --git a/scripts/documentation-file-ref-check b/scripts/documentation-file-ref-check new file mode 100755 index 0000000000..0bfc5feefb --- /dev/null +++ b/scripts/documentation-file-ref-check @@ -0,0 +1,226 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# Treewide grep for references to files under doc, and report +# non-existing files in stderr. + +use warnings; +use strict; +use Getopt::Long qw(:config no_auto_abbrev); + +# NOTE: only add things here when the file was gone, but the text wants +# to mention a past documentation file, for example, to give credits for +# the original work. +my %false_positives = ( +); + +my $scriptname = $0; +$scriptname =~ s,.*/([^/]+/),$1,; + +# Parse arguments +my $help = 0; +my $fix = 0; +my $warn = 0; + +if (! -d ".git") { + printf "Warning: can't check if file exists, as this is not a git tree"; + exit 0; +} + +GetOptions( + 'fix' => \$fix, + 'warn' => \$warn, + 'h|help|usage' => \$help, +); + +if ($help != 0) { + print "$scriptname [--help] [--fix]\n"; + exit -1; +} + +# Step 1: find broken references +print "Finding broken references. This may take a while... " if ($fix); + +my %broken_ref; + +my $doc_fix = 0; + +open IN, "git grep ':doc:\`' doc/|" + or die "Failed to run git grep"; +while () { + next if (!m,^([^:]+):.*\:doc\:\`([^\`]+)\`,); + + my $d = $1; + my $doc_ref = $2; + + my $f = $doc_ref; + + $d =~ s,(.*/).*,$1,; + $f =~ s,.*\<([^\>]+)\>,$1,; + + $f ="$d$f.rst"; + + next if (grep -e, glob("$f")); + + if ($fix && !$doc_fix) { + print STDERR "\nWARNING: Currently, can't fix broken :doc:`` fields\n"; + } + $doc_fix++; + + print STDERR "$f: :doc:`$doc_ref`\n"; +} +close IN; + +open IN, "git grep 'doc/'|" + or die "Failed to run git grep"; +while () { + next if (!m/^([^:]+):(.*)/); + + my $f = $1; + my $ln = $2; + + # On linux-next, discard the Next/ directory + next if ($f =~ m,^Next/,); + + # Makefiles and scripts contain nasty expressions to parse docs + next if ($f =~ m/Makefile/ || $f =~ m/\.sh$/); + + # Skip this script + next if ($f eq $scriptname); + + # Ignore the dir where documentation will be built + next if ($ln =~ m,\b(\S*)doc/output,); + + if ($ln =~ m,\b(\S*)(doc/[A-Za-z0-9\_\.\,\~/\*\[\]\?+-]*)(.*),) { + my $prefix = $1; + my $ref = $2; + my $base = $2; + my $extra = $3; + + # some file references are like: + # /usr/src/linux/doc/DMA-{API,mapping}.txt + # For now, ignore them + next if ($extra =~ m/^{/); + + # Remove footnotes at the end like: + # doc/devicetree/dt-object-internal.txt[1] + $ref =~ s/(txt|rst)\[\d+]$/$1/; + + # Remove ending ']' without any '[' + $ref =~ s/\].*// if (!($ref =~ m/\[/)); + + # Remove puntuation marks at the end + $ref =~ s/[\,\.]+$//; + + my $fulref = "$prefix$ref"; + + $fulref =~ s/^(\ 1) { + print STDERR "WARNING: Won't auto-replace, as found multiple files close to $ref:\n"; + foreach my $j (@find) { + $j =~ s,^./,,; + print STDERR " $j\n"; + } + } else { + $f = $find[0]; + $f =~ s,^./,,; + print "INFO: Replacing $ref to $f\n"; + foreach my $j (qx(git grep -l $ref)) { + qx(sed "s\@$ref\@$f\@g" -i $j); + } + } +} From 42551f49b35fe1067c778086292a9b8c6fc2be0c Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 2 Mar 2020 10:12:41 +0100 Subject: [PATCH 11/25] doc: spl: update reference to driver-model/README.txt Update the reference in doc/README.SPL to a no more existing file: "driver-model/README.txt", it is changed to "doc/driver-model/design.rst". Adding the directory path /doc/ allows to check this reference with 'make refcheckdocs'. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- doc/README.SPL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/README.SPL b/doc/README.SPL index 929b9672b0..2beb6d8f11 100644 --- a/doc/README.SPL +++ b/doc/README.SPL @@ -81,7 +81,7 @@ fdtgrep is also used to remove: ('u-boot,dm-pre-reloc', 'u-boot,dm-spl' and 'u-boot,dm-tpl') All the nodes remaining in the SPL devicetree are bound -(see driver-model/README.txt). +(see doc/driver-model/design.rst). Debugging --------- From 71126d53df7aea9abb42b99b69c8d8b9cb5aa043 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 2 Mar 2020 13:21:53 +0100 Subject: [PATCH 12/25] tee: optee: use dev_info in print_os_revision Display TEE version at information level; this patch replaces debug() call to dev_info() in print_os_revision() function. Signed-off-by: Patrick Delaunay Acked-by: Jens Wiklander --- drivers/tee/optee/core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 9fb5e658f9..5260dab3ac 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -512,7 +512,7 @@ static bool is_optee_api(optee_invoke_fn *invoke_fn) res.a2 == OPTEE_MSG_UID_2 && res.a3 == OPTEE_MSG_UID_3; } -static void print_os_revision(optee_invoke_fn *invoke_fn) +static void print_os_revision(struct udevice *dev, optee_invoke_fn *invoke_fn) { union { struct arm_smccc_res smccc; @@ -527,11 +527,12 @@ static void print_os_revision(optee_invoke_fn *invoke_fn) &res.smccc); if (res.result.build_id) - debug("OP-TEE revision %lu.%lu (%08lx)\n", res.result.major, - res.result.minor, res.result.build_id); + dev_info(dev, "OP-TEE: revision %lu.%lu (%08lx)\n", + res.result.major, res.result.minor, + res.result.build_id); else - debug("OP-TEE revision %lu.%lu\n", res.result.major, - res.result.minor); + dev_info(dev, "OP-TEE: revision %lu.%lu\n", + res.result.major, res.result.minor); } static bool api_revision_is_compatible(optee_invoke_fn *invoke_fn) @@ -626,7 +627,7 @@ static int optee_probe(struct udevice *dev) return -ENOENT; } - print_os_revision(pdata->invoke_fn); + print_os_revision(dev, pdata->invoke_fn); if (!api_revision_is_compatible(pdata->invoke_fn)) { debug("%s: OP-TEE api revision mismatch\n", __func__); From a8c708ea9f84cf637bb2bd5cfdcfd2dbbe71b86f Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:29 +0100 Subject: [PATCH 13/25] cmd: mem: Correctly count the errors in mtest This patch changes mtest to correctly count the overall errors and print them even in the abort (Ctrl-C) case. Signed-off-by: Stefan Roese --- cmd/mem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 6d54f19527..9367278aa8 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -871,7 +871,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong start, end; vu_long *buf, *dummy; ulong iteration_limit = 0; - int ret; + ulong count = 0; ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; @@ -929,6 +929,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, } if (errs == -1UL) break; + count += errs; } /* @@ -947,14 +948,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ putc('\n'); - ret = 1; - } else { - printf("Tested %d iteration(s) with %lu errors.\n", - iteration, errs); - ret = errs != 0; } + printf("Tested %d iteration(s) with %lu errors.\n", iteration, count); - return ret; + return errs != 0; } #endif /* CONFIG_CMD_MEMTEST */ From 54de244c4779b452cc9314f475798d984fd27d0a Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:30 +0100 Subject: [PATCH 14/25] cmd: mem: Drop eldk-4.2 workaround and use cast in unmap_sysmem() Use a cast instead of the "eldk-4.2" workaround for unmap_sysmem(). Signed-off-by: Stefan Roese --- cmd/mem.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 9367278aa8..f519adaee2 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -932,18 +932,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, count += errs; } - /* - * Work-around for eldk-4.2 which gives this warning if we try to - * case in the unmap_sysmem() call: - * warning: initialization discards qualifiers from pointer target type - */ - { - void *vbuf = (void *)buf; - void *vdummy = (void *)dummy; - - unmap_sysmem(vbuf); - unmap_sysmem(vdummy); - } + unmap_sysmem((void *)buf); + unmap_sysmem((void *)dummy); if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ From f14bfa7ec6a5ec79e1c8dd48571b740922439912 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:31 +0100 Subject: [PATCH 15/25] cmd: mem: Use IS_ENABLED instead of alt_test variable This patch uses the IS_ENABLED() macro to check, which mtest variant is enabled. Signed-off-by: Stefan Roese --- cmd/mem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index f519adaee2..2ccc7032ad 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -875,11 +875,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; -#if defined(CONFIG_SYS_ALT_MEMTEST) - const int alt_test = 1; -#else - const int alt_test = 0; -#endif start = CONFIG_SYS_MEMTEST_START; end = CONFIG_SYS_MEMTEST_END; @@ -921,7 +916,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, printf("Iteration: %6d\r", iteration + 1); debug("\n"); - if (alt_test) { + if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); } else { errs = mem_test_quick(buf, start, end, pattern, From 8e434cb705d463bc8cff935160e4fb4c77cb99ab Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 5 Mar 2020 07:21:32 +0100 Subject: [PATCH 16/25] cmd: mem: Add bitflip memory test to alternate mtest This additional bitflip memory test is inspired by the bitflip test in memtester v4.3.0. It show some errors on some problematic GARDENA MT7688 based boards. The other memory tests usually don't show any errors here. Signed-off-by: Stefan Roese --- cmd/mem.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cmd/mem.c b/cmd/mem.c index 2ccc7032ad..0bfb6081e7 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -801,6 +801,59 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, return errs; } +static int compare_regions(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + int errs = 0; + size_t i; + + for (i = 0; i < count; i++, p1++, p2++) { + if (*p1 != *p2) { + printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n", + (unsigned long)*p1, (unsigned long)*p2, + *p1 ^ *p2, __ffs(*p1 ^ *p2), + (unsigned long)(i * sizeof(unsigned long))); + errs++; + } + } + + return errs; +} + +static ulong test_bitflip_comparison(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + unsigned int j, k; + unsigned long q; + size_t i; + int max; + int errs = 0; + + max = sizeof(unsigned long) * 8; + for (k = 0; k < max; k++) { + q = 0x00000001L << k; + for (j = 0; j < 8; j++) { + WATCHDOG_RESET(); + q = ~q; + p1 = (volatile unsigned long *)bufa; + p2 = (volatile unsigned long *)bufb; + for (i = 0; i < count; i++) + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q; + + errs += compare_regions(bufa, bufb, count); + } + + if (ctrlc()) + return -1UL; + } + + return errs; +} + static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, vu_long pattern, int iteration) { @@ -918,6 +971,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, debug("\n"); if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); + if (errs == -1UL) + break; + count += errs; + errs = test_bitflip_comparison(buf, + buf + (end - start) / 2, + (end - start) / + sizeof(unsigned long)); } else { errs = mem_test_quick(buf, start, end, pattern, iteration); From 2a2119e10ca364d7c1539a9103b9fd3839dbe6ac Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Thu, 5 Mar 2020 16:24:21 -0800 Subject: [PATCH 17/25] lib: kconfig: Add option to set BZIP2 compression method There is no way to select BZIP2 compression method. Add it under library/compression config where all other compression related configs are present. Signed-off-by: Atish Patra Reviewed-by: Tom Rini --- lib/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index 452f390c80..144a54da28 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -409,6 +409,11 @@ config GZIP help This enables support for GZIP compression algorithm. +config BZIP2 + bool "Enable bzip2 decompression support" + help + This enables support for BZIP2 compression algorithm. + config ZLIB bool default y From 155d6a3575470c1a735b8cf368d9e987930910a8 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Thu, 5 Mar 2020 16:24:22 -0800 Subject: [PATCH 18/25] image: Add a common compression type detection function. Currently, there is no method that can detect compression types given a file. This is very useful where a compressed kernel image is loaded directly to the memory. Inspect initial few bytes to figure out compression type of the image. It will be used in booti method for now but can be reused any other function in future as well. Signed-off-by: Atish Patra Reviewed-by: Tom Rini --- common/image.c | 23 +++++++++++++++++++++++ include/image.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/common/image.c b/common/image.c index 94873cb6ed..d8d14e871c 100644 --- a/common/image.c +++ b/common/image.c @@ -202,6 +202,14 @@ struct table_info { const table_entry_t *table; }; +static const struct comp_magic_map image_comp[] = { + { IH_COMP_BZIP2, "bzip2", {0x42, 0x5a},}, + { IH_COMP_GZIP, "gzip", {0x1f, 0x8b},}, + { IH_COMP_LZMA, "lzma", {0x5d, 0x00},}, + { IH_COMP_LZO, "lzo", {0x89, 0x4c},}, + { IH_COMP_NONE, "none", {}, }, +}; + static const struct table_info table_info[IH_COUNT] = { { "architecture", IH_ARCH_COUNT, uimage_arch }, { "compression", IH_COMP_COUNT, uimage_comp }, @@ -407,6 +415,21 @@ static void print_decomp_msg(int comp_type, int type, bool is_xip) printf(" Uncompressing %s\n", name); } +int image_decomp_type(const unsigned char *buf, ulong len) +{ + const struct comp_magic_map *cmagic = image_comp; + + if (len < 2) + return -EINVAL; + + for (; cmagic->comp_id > 0; cmagic++) { + if (!memcmp(buf, cmagic->magic, 2)) + break; + } + + return cmagic->comp_id; +} + int image_decomp(int comp, ulong load, ulong image_start, int type, void *load_buf, void *image_buf, ulong image_len, uint unc_len, ulong *load_end) diff --git a/include/image.h b/include/image.h index 2388c1f204..de55b2fb57 100644 --- a/include/image.h +++ b/include/image.h @@ -452,6 +452,15 @@ typedef struct table_entry { char *lname; /* long (output) name to print for messages */ } table_entry_t; +/* + * Compression type and magic number mapping table. + */ +struct comp_magic_map { + int comp_id; + const char *name; + unsigned char magic[2]; +}; + /* * get_table_entry_id() scans the translation table trying to find an * entry that matches the given short name. If a matching entry is @@ -868,6 +877,18 @@ static inline int image_check_target_arch(const image_header_t *hdr) } #endif /* USE_HOSTCC */ +/** + * image_decomp_type() - Find out compression type of an image + * + * @buf: Address in U-Boot memory where image is loaded. + * @len: Length of the compressed image. + * @return compression type or IH_COMP_NONE if not compressed. + * + * Note: Only following compression types are supported now. + * lzo, lzma, gzip, bzip2 + */ +int image_decomp_type(const unsigned char *buf, ulong len); + /** * image_decomp() - decompress an image * From 414c34ed555b8ce5c260cf641261ecf45beca251 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Thu, 5 Mar 2020 16:24:23 -0800 Subject: [PATCH 19/25] image: Add compressed Image parsing support in booti. Add compressed Image parsing support so that booti can parse both flat and compressed Image to boot Linux. Currently, it is difficult to calculate a safe address for every board where the compressed image can be decompressed. It is also not possible to figure out the size of the compressed file as well. Thus, user need to set two additional environment variables kernel_comp_addr_r and filesize to make this work. Following compression methods are supported for now. lzma, lzo, bzip2, gzip. lz4 support is not added as ARM64 kernel generates a lz4 compressed image with legacy header which U-Boot doesn't know how to parse and decompress. Tested on HiFive Unleashed and Qemu for RISC-V. Tested on Qemu for ARM64. Signed-off-by: Atish Patra Reviewed-by: Tom Rini [trini: Fix minor rST formatting problems] Signed-off-by: Tom Rini --- cmd/booti.c | 40 +++++++++++++++++++++++++- doc/README.distro | 12 ++++++++ doc/board/sifive/fu540.rst | 58 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/cmd/booti.c b/cmd/booti.c index de5058236e..4fff8cfcf6 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -14,6 +14,7 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; /* * Image booting support */ @@ -24,6 +25,12 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, ulong ld; ulong relocated_addr; ulong image_size; + uint8_t *temp; + ulong dest; + ulong dest_end; + unsigned long comp_len; + unsigned long decomp_len; + int ctype; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); @@ -38,6 +45,33 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, debug("* kernel: cmdline image address = 0x%08lx\n", ld); } + temp = map_sysmem(ld, 0); + ctype = image_decomp_type(temp, 2); + if (ctype > 0) { + dest = env_get_ulong("kernel_comp_addr_r", 16, 0); + comp_len = env_get_ulong("kernel_comp_size", 16, 0); + if (!dest || !comp_len) { + puts("kernel_comp_addr_r or kernel_comp_size is not provided!\n"); + return -EINVAL; + } + if (dest < gd->ram_base || dest > gd->ram_top) { + puts("kernel_comp_addr_r is outside of DRAM range!\n"); + return -EINVAL; + } + + debug("kernel image compression type %d size = 0x%08lx address = 0x%08lx\n", + ctype, comp_len, (ulong)dest); + decomp_len = comp_len * 10; + ret = image_decomp(ctype, 0, ld, IH_TYPE_KERNEL, + (void *)dest, (void *)ld, comp_len, + decomp_len, &dest_end); + if (ret) + return ret; + /* dest_end contains the uncompressed Image size */ + memmove((void *) ld, (void *)dest, dest_end); + } + unmap_sysmem((void *)ld); + ret = booti_setup(ld, &relocated_addr, &image_size, false); if (ret != 0) return 1; @@ -100,10 +134,14 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] = "[addr [initrd[:size]] [fdt]]\n" - " - boot Linux 'Image' stored at 'addr'\n" + " - boot Linux flat or compressed 'Image' stored at 'addr'\n" "\tThe argument 'initrd' is optional and specifies the address\n" "\tof an initrd in memory. The optional parameter ':size' allows\n" "\tspecifying the size of a RAW initrd.\n" + "\tCurrently only booting from gz, bz2, lzma and lz4 compression\n" + "\ttypes are supported. In order to boot from any of these compressed\n" + "\timages, user have to set kernel_comp_addr_r and kernel_comp_size enviornment\n" + "\tvariables beforehand.\n" #if defined(CONFIG_OF_LIBFDT) "\tSince booting a Linux kernel requires a flat device-tree, a\n" "\tthird argument providing the address of the device-tree blob\n" diff --git a/doc/README.distro b/doc/README.distro index ab6e6f4e74..5076bebd18 100644 --- a/doc/README.distro +++ b/doc/README.distro @@ -246,6 +246,18 @@ kernel_addr_r: A size of 16MB for the kernel is likely adequate. +kernel_comp_addr_r: + Optional. This is only required if user wants to boot Linux from a compressed + Image(.gz, .bz2, .lzma, .lzo) using booti command. It represents the location + in RAM where the compressed Image will be decompressed temporarily. Once the + decompression is complete, decompressed data will be moved kernel_addr_r for + booting. + +kernel_comp_size: + Optional. This is only required if user wants to boot Linux from a compressed + Image using booti command. It represents the size of the compressed file. The + size has to at least the size of loaded image for decompression to succeed. + pxefile_addr_r: Mandatory. The location in RAM where extlinux.conf will be loaded to prior diff --git a/doc/board/sifive/fu540.rst b/doc/board/sifive/fu540.rst index 3937222c6c..610ba87074 100644 --- a/doc/board/sifive/fu540.rst +++ b/doc/board/sifive/fu540.rst @@ -135,6 +135,11 @@ load uImage. => setenv netmask 255.255.252.0 => setenv serverip 10.206.4.143 => setenv gateway 10.206.4.1 + +If you want to use a flat kernel image such as Image file + +.. code-block:: none + => tftpboot ${kernel_addr_r} /sifive/fu540/Image ethernet@10090000: PHY present at 0 ethernet@10090000: Starting autonegotiation... @@ -174,6 +179,59 @@ load uImage. 1.2 MiB/s done Bytes transferred = 8867100 (874d1c hex) + +Or if you want to use a compressed kernel image file such as Image.gz + +.. code-block:: none + + => tftpboot ${kernel_addr_r} /sifive/fu540/Image.gz + ethernet@10090000: PHY present at 0 + ethernet@10090000: Starting autonegotiation... + ethernet@10090000: Autonegotiation complete + ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3c00) + Using ethernet@10090000 device + TFTP from server 10.206.4.143; our IP address is 10.206.7.133 + Filename '/sifive/fu540/Image.gz'. + Load address: 0x84000000 + Loading: ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ########################################## + 1.2 MiB/s + done + Bytes transferred = 4809458 (4962f2 hex) + =>setenv kernel_comp_addr_r 0x90000000 + =>setenv kernel_comp_size 0x500000 + +By this time, correct kernel image is loaded and required enviornment variables +are set. You can proceed to load the ramdisk and device tree from the tftp server +as well. + +.. code-block:: none + => tftpboot ${ramdisk_addr_r} /sifive/fu540/uRamdisk ethernet@10090000: PHY present at 0 ethernet@10090000: Starting autonegotiation... From ecb3a0a154fa43e636012be691521910928d67bd Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 24 Feb 2020 18:36:30 +0100 Subject: [PATCH 20/25] README: replace reference to boards.cfg boards.cfg is not delivered with the U-Boot source. So it is preferable to look at configs/*_defconfig to identify available deconfigs. Fix a typo. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 19dae14ac0..7ebf9f577e 100644 --- a/README +++ b/README @@ -3203,9 +3203,9 @@ is done by typing: make NAME_defconfig where "NAME_defconfig" is the name of one of the existing configu- -rations; see boards.cfg for supported names. +rations; see configs/*_defconfig for supported names. -Note: for some board special configuration names may exist; check if +Note: for some boards special configuration names may exist; check if additional information is available from the board vendor; for instance, the TQM823L systems are available without (standard) or with LCD support. You can select such additional "features" From 2799a69ee88f8fe086846095f8fe8a8e79483605 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 25 Feb 2020 21:35:39 +0100 Subject: [PATCH 21/25] doc: fix references to driver-model Fix some errors pointed out by 'make refcheckdocs'. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/README.fdt-control | 2 +- drivers/i2c/davinci_i2c.c | 2 +- drivers/i2c/kona_i2c.c | 2 +- drivers/i2c/sh_i2c.c | 2 +- drivers/i2c/soft_i2c.c | 2 +- tools/dtoc/dtb_platdata.py | 4 ++-- tools/dtoc/dtoc.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/README.fdt-control b/doc/README.fdt-control index e53cf51875..424d13fc5b 100644 --- a/doc/README.fdt-control +++ b/doc/README.fdt-control @@ -182,7 +182,7 @@ U-Boot can be divided into three phases: TPL, SPL and U-Boot proper. The full device tree is available to U-Boot proper, but normally only a subset (or none at all) is available to TPL and SPL. See 'Pre-Relocation Support' and -'SPL Support' in doc/driver-model/README.txt for more details. +'SPL Support' in doc/driver-model/design.rst for more details. Using several DTBs in the SPL (CONFIG_SPL_MULTI_DTB) diff --git a/drivers/i2c/davinci_i2c.c b/drivers/i2c/davinci_i2c.c index 2c77234c60..edc40f706c 100644 --- a/drivers/i2c/davinci_i2c.c +++ b/drivers/i2c/davinci_i2c.c @@ -8,7 +8,7 @@ * -------------------------------------------------------- * * NOTE: This driver should be converted to driver model before June 2017. - * Please see doc/driver-model/i2c-howto.txt for instructions. + * Please see doc/driver-model/i2c-howto.rst for instructions. */ #include diff --git a/drivers/i2c/kona_i2c.c b/drivers/i2c/kona_i2c.c index 0726b4c956..8e31481c0f 100644 --- a/drivers/i2c/kona_i2c.c +++ b/drivers/i2c/kona_i2c.c @@ -3,7 +3,7 @@ * Copyright 2013 Broadcom Corporation. * * NOTE: This driver should be converted to driver model before June 2017. - * Please see doc/driver-model/i2c-howto.txt for instructions. + * Please see doc/driver-model/i2c-howto.rst for instructions. */ #include diff --git a/drivers/i2c/sh_i2c.c b/drivers/i2c/sh_i2c.c index b69d213593..834f1f2179 100644 --- a/drivers/i2c/sh_i2c.c +++ b/drivers/i2c/sh_i2c.c @@ -4,7 +4,7 @@ * Copyright (C) 2011, 2013 Nobuhiro Iwamatsu * * NOTE: This driver should be converted to driver model before June 2017. - * Please see doc/driver-model/i2c-howto.txt for instructions. + * Please see doc/driver-model/i2c-howto.rst for instructions. */ #include diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c index 7f0303cc05..9ad1c281ff 100644 --- a/drivers/i2c/soft_i2c.c +++ b/drivers/i2c/soft_i2c.c @@ -12,7 +12,7 @@ * Neil Russell. * * NOTE: This driver should be converted to driver model before June 2017. - * Please see doc/driver-model/i2c-howto.txt for instructions. + * Please see doc/driver-model/i2c-howto.rst for instructions. */ #include diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 037e82c8bb..90a9e1a626 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -423,7 +423,7 @@ class DtbPlatdata(object): This writes out the body of a header file consisting of structure definitions for node in self._valid_nodes. See the documentation in - README.of-plat for more information. + doc/driver-model/of-plat.rst for more information. """ self.out_header() self.out('#include \n') @@ -527,7 +527,7 @@ class DtbPlatdata(object): U_BOOT_DEVICE() declarations for each valid node. Where a node has multiple compatible strings, a #define is used to make them equivalent. - See the documentation in doc/driver-model/of-plat.txt for more + See the documentation in doc/driver-model/of-plat.rst for more information. """ self.out_header() diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py index b3596a5918..f31cba900e 100755 --- a/tools/dtoc/dtoc.py +++ b/tools/dtoc/dtoc.py @@ -22,7 +22,7 @@ Dtoc produces two output files: This tool is used in U-Boot to provide device tree data to SPL without increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA options. For more information about the use of this options and tool please -see doc/driver-model/of-plat.txt +see doc/driver-model/of-plat.rst """ from __future__ import print_function From 0563700672450c8d88d5f90840be499ee0c5a5eb Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 25 Feb 2020 21:44:05 +0100 Subject: [PATCH 22/25] Kconfig: fix typos in CMD_BEDBUG description Fix documentation bug reported by 'make refcheckdocs'. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass Reviewed-by: Patrick Delaunay --- cmd/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 0e2576262d..a46c77d69d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2103,7 +2103,7 @@ config CMD_BEDBUG help The bedbug (emBEDded deBUGger) command provides debugging features for some PowerPC processors. For details please see the - docuemntation in doc/README.beddbug + documentation in doc/README.bedbug. config CMD_DIAG bool "diag - Board diagnostics" From 22961dc4412254578c8e1ae457cf1197b9aab30c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 26 Feb 2020 05:29:47 +0100 Subject: [PATCH 23/25] include/ata.h: remove invalid links Remove invalid URLs for "Information Technology - AT Attachment-3 Interface (ATA-3)", point to ANSI X3.298-1997. Signed-off-by: Heinrich Schuchardt --- include/ata.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/ata.h b/include/ata.h index e35d91941d..3d870c973f 100644 --- a/include/ata.h +++ b/include/ata.h @@ -6,11 +6,8 @@ /* * Most of the following information was derived from the document - * "Information Technology - AT Attachment-3 Interface (ATA-3)" - * which can be found at: - * http://www.dt.wdc.com/ata/ata-3/ata3r5v.zip - * ftp://poctok.iae.nsk.su/pub/asm/Documents/IDE/ATA3R5V.ZIP - * ftp://ftp.fee.vutbr.cz/pub/doc/io/ata/ata-3/ata3r5v.zip + * "Information Technology - AT Attachment-3 Interface (ATA-3)", + * ANSI X3.298-1997. */ #ifndef _ATA_H From f4a1426fd6e473ff523147a67d079c7ccb2a4e27 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 26 Feb 2020 07:12:33 +0100 Subject: [PATCH 24/25] ata: sort ATA commands Sort the ATA commands in include/libata.h by number. Add a few more comments. Signed-off-by: Heinrich Schuchardt --- include/libata.h | 84 ++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/include/libata.h b/include/libata.h index 25296ac66d..b03b29960d 100644 --- a/include/libata.h +++ b/include/libata.h @@ -133,49 +133,49 @@ enum { ATA_REG_IRQ = ATA_REG_NSECT, /* ATA device commands */ - ATA_CMD_DEV_RESET = 0x08, /* ATAPI device reset */ - ATA_CMD_CHK_POWER = 0xE5, /* check power mode */ - ATA_CMD_STANDBY = 0xE2, /* place in standby power mode */ - ATA_CMD_IDLE = 0xE3, /* place in idle power mode */ - ATA_CMD_EDD = 0x90, /* execute device diagnostic */ - ATA_CMD_FLUSH = 0xE7, - ATA_CMD_FLUSH_EXT = 0xEA, - ATA_CMD_ID_ATA = 0xEC, - ATA_CMD_ID_ATAPI = 0xA1, - ATA_CMD_READ = 0xC8, - ATA_CMD_READ_EXT = 0x25, - ATA_CMD_WRITE = 0xCA, - ATA_CMD_WRITE_EXT = 0x35, - ATA_CMD_WRITE_FUA_EXT = 0x3D, - ATA_CMD_FPDMA_READ = 0x60, - ATA_CMD_FPDMA_WRITE = 0x61, - ATA_CMD_PIO_READ = 0x20, - ATA_CMD_PIO_READ_EXT = 0x24, - ATA_CMD_PIO_WRITE = 0x30, - ATA_CMD_PIO_WRITE_EXT = 0x34, - ATA_CMD_READ_MULTI = 0xC4, - ATA_CMD_READ_MULTI_EXT = 0x29, - ATA_CMD_WRITE_MULTI = 0xC5, - ATA_CMD_WRITE_MULTI_EXT = 0x39, - ATA_CMD_WRITE_MULTI_FUA_EXT = 0xCE, - ATA_CMD_SET_FEATURES = 0xEF, - ATA_CMD_SET_MULTI = 0xC6, - ATA_CMD_PACKET = 0xA0, - ATA_CMD_VERIFY = 0x40, - ATA_CMD_VERIFY_EXT = 0x42, - ATA_CMD_STANDBYNOW1 = 0xE0, - ATA_CMD_IDLEIMMEDIATE = 0xE1, - ATA_CMD_SLEEP = 0xE6, - ATA_CMD_INIT_DEV_PARAMS = 0x91, - ATA_CMD_READ_NATIVE_MAX = 0xF8, + ATA_CMD_DEV_RESET = 0x08, /* ATAPI device reset */ + ATA_CMD_PIO_READ = 0x20, /* Read sectors with retry */ + ATA_CMD_PIO_READ_EXT = 0x24, + ATA_CMD_READ_EXT = 0x25, ATA_CMD_READ_NATIVE_MAX_EXT = 0x27, - ATA_CMD_SET_MAX = 0xF9, - ATA_CMD_SET_MAX_EXT = 0x37, - ATA_CMD_READ_LOG_EXT = 0x2f, - ATA_CMD_PMP_READ = 0xE4, - ATA_CMD_PMP_WRITE = 0xE8, - ATA_CMD_CONF_OVERLAY = 0xB1, - ATA_CMD_SEC_FREEZE_LOCK = 0xF5, + ATA_CMD_READ_MULTI_EXT = 0x29, + ATA_CMD_READ_LOG_EXT = 0x2f, + ATA_CMD_PIO_WRITE = 0x30, /* write sectors with retry */ + ATA_CMD_PIO_WRITE_EXT = 0x34, + ATA_CMD_WRITE_EXT = 0x35, + ATA_CMD_SET_MAX_EXT = 0x37, + ATA_CMD_WRITE_MULTI_EXT = 0x39, + ATA_CMD_WRITE_FUA_EXT = 0x3D, + ATA_CMD_VERIFY = 0x40, /* read verify sectors with retry */ + ATA_CMD_VERIFY_EXT = 0x42, + ATA_CMD_FPDMA_READ = 0x60, + ATA_CMD_FPDMA_WRITE = 0x61, + ATA_CMD_EDD = 0x90, /* execute device diagnostic */ + ATA_CMD_INIT_DEV_PARAMS = 0x91, /* initialize device parameters */ + ATA_CMD_PACKET = 0xA0, /* ATAPI packet */ + ATA_CMD_ID_ATAPI = 0xA1, /* ATAPI identify device */ + ATA_CMD_CONF_OVERLAY = 0xB1, + ATA_CMD_READ_MULTI = 0xC4, /* read multiple */ + ATA_CMD_WRITE_MULTI = 0xC5, /* write multiple */ + ATA_CMD_SET_MULTI = 0xC6, /* set multiple mode */ + ATA_CMD_READ = 0xC8, /* read DMA with retry */ + ATA_CMD_WRITE = 0xCA, /* write DMA with retry */ + ATA_CMD_WRITE_MULTI_FUA_EXT = 0xCE, + ATA_CMD_STANDBYNOW1 = 0xE0, /* standby immediate */ + ATA_CMD_IDLEIMMEDIATE = 0xE1, /* idle immediate */ + ATA_CMD_STANDBY = 0xE2, /* place in standby power mode */ + ATA_CMD_IDLE = 0xE3, /* place in idle power mode */ + ATA_CMD_PMP_READ = 0xE4, /* read buffer */ + ATA_CMD_CHK_POWER = 0xE5, /* check power mode */ + ATA_CMD_SLEEP = 0xE6, /* sleep */ + ATA_CMD_FLUSH = 0xE7, + ATA_CMD_PMP_WRITE = 0xE8, /* write buffer */ + ATA_CMD_FLUSH_EXT = 0xEA, + ATA_CMD_ID_ATA = 0xEC, /* identify device */ + ATA_CMD_SET_FEATURES = 0xEF, /* set features */ + ATA_CMD_SEC_FREEZE_LOCK = 0xF5, /* security freeze */ + ATA_CMD_READ_NATIVE_MAX = 0xF8, + ATA_CMD_SET_MAX = 0xF9, /* READ_LOG_EXT pages */ ATA_LOG_SATA_NCQ = 0x10, From 48180e15d3eaff51b1da30a90bc64b7acba8fb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Mon, 30 Mar 2020 18:48:42 +0200 Subject: [PATCH 25/25] fs: btrfs: support sparse extents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When logical address of a regular extent is 0, the extent is sparse and consists of all zeros. Without this when sparse extents are used in a file reading fails with Cannot map logical address 0 to physical Signed-off-by: Marek BehĂșn --- fs/btrfs/extent-io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/extent-io.c b/fs/btrfs/extent-io.c index 66d0e1c7d6..2e4599cf64 100644 --- a/fs/btrfs/extent-io.c +++ b/fs/btrfs/extent-io.c @@ -78,6 +78,12 @@ u64 btrfs_read_extent_reg(struct btrfs_path *path, if (size > dlen - offset) size = dlen - offset; + /* sparse extent */ + if (extent->disk_bytenr == 0) { + memset(out, 0, size); + return size; + } + physical = btrfs_map_logical_to_physical(extent->disk_bytenr); if (physical == -1ULL) return -1ULL;