Re: [PATCH v6 00/25] spl: Use common function for loading/parsing images
What you are doing is the worst thing in the world. You have been ignoring all my changes which I have been sending for one year, then you wrote me that I'm not competent to do any kind of programming, later you wrote that you would ignore all my requests and stop responding to any questions, then you have removed all my code from u-boot and showed me as the worst person in the world. But seems that this is not enough for you. You have to continue attacking on me, and making everything even worse. WHAT YOU WANT FROM ME NOW WHY YOU ARE CONTACTING ME??? IS NOT IT ENOUGH WHAT YOU HAVE TO ME?? Or you do think that I forgot what you have been doing with me last years? Speak up! On Sunday 05 November 2023 21:25:38 Sean Anderson wrote: > This series adds support for loading all image types (Legacy (with and without > LZMA), FIT (with and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR, > NET, FAT, EXT, NVMe, and semihosting load methods. It does this by > introducing a > helper function which handles the minutiae of invoking the proper parsing > function, and reading the rest of the image. > > Hopefully, this will make it easier for load methods to support all image > types > that U-Boot supports, without having undocumented unsupported image types. I > applied this to several loaders which were invoking spl_load_simple_fit and/or > spl_parse_image_header, but I did not use it with others (e.g. DFU/RAM) which > had complications in the mix. > > This series is organized roughly into two parts. Patches up to "spl: Add > generic > spl_load function" are all setup or size-reduction oriented. Later patches > generally convert various load functions to spl_load. > > bloat-o-meter results (for CONFIG_SPL only) at [1]. Size growth has been the > bigegst challenge to preparing this series. I have used every trick I can > think > of to reduce bloat. Some SAMA boards no longer fit, but I have a plan to fix > them [2]. > > This is bar far the largest and most-difficult revision of this series > to-date. > There are probably still things which can reduce the size, but I have been > working on this series for the better part of two months and I think it is a > good idea to get some feedback. Because of the SAMA bloat, this series will > not > pass CI, so I expect to do a v7 before this is ready to apply. Feel free, > however, to apply patches in the first half (especially the fixes). > > This version of the series is better-tested than ever before, thanks to some > new > unit tests. However, things like the i.MX ROMAPI are untested. NAND should > also > be tested more-widely, for reasons listed in the commit message. I encourage > you > try this series out on your favorite board. > > This series depends on [3]. (Almost passing) CI at [4]. > > [1] https://gist.github.com/Forty-Bot/5bfe88676dd3c2aec6ebc23abb08e06f > This includes some changes to am335x_evm_spiboot and am65x_evm_r5_usbdfu > which have since been undone. > [2] https://lore.kernel.org/u-boot/20231105022742.632175-1-sean...@gmail.com/ > [3] https://lore.kernel.org/u-boot/20231104203753.1579217-1-sean...@gmail.com/ > [4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18447 > > Changes in v6: > - Fix uninitialized return value when we can't get a blk_desc > - Don't close fd before spl_load_simple_fit > - Remove NULL assignments in spl_load_info > - Remove dev from spl_load_info > - Take advantage of bl_len's power-of-twoness > - Refactor spl_load_info->read to use units of bytes > - Remove filename from spl_load_info > - Only support bl_len when we have to > - Remove spl_nand_legacy_read > - Split off LZMA decompression into its own function > - Support testing LEGACY_LZMA filesystem images > - Use pseudo-LTO for spl_load > - Align reads to bl_len > - Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads > anything directly. > - Convert nand to spl_load > - Fix LZMA support > - Fix load address > - Fix invalid return from spl_blk_load_image > - Fix soft reset after loading from SPI > - Explicitly initialize load_info members to reduce text size > - Rebase on u-boot/next > - Add option to disable DMA alignment for FAT > > Changes in v5: > - Make SHOW_ERRORS depend on LIBCOMMON > - Load the header in spl_load as well > - Don't bother trying to DMA-align the buffer, since we can't really fix > it. > - Convert NVMe to spl_load > > Changes in v4: > - Fix format specifiers in debug prints > - Reword/fix some of the doc comments for spl_load > - Rebase on u-boot/master > > Changes in v3: > - Fix using ffs instead of fls > - Fix using not initializing bl_len when info->filename was NULL > - Fix failing on success > > Changes in v2: > - Use reverse-xmas-tree style for locals in spl_simple_read. This is not > complete, since overhead depends on bl_mask. > - Convert semihosting as well > - Consolidate spi_load_image_os into spl_spi_load_image > > Sean Anderson (25): > spl: blk_fs: Fix uninitialized
Re: [PATCH v3 7/7] clk/qcom: fix rcg divider value
On Fri, 3 Nov 2023 at 21:11, Caleb Connolly wrote: > > The RCG divider field takes a value of (2*h - 1) where h is the divisor. > This allows fractional dividers to be supported by calculating them at > compile time using a macro. > > However, the clk_rcg_set_rate_mnd() function was also performing the > calculation. Clean this all up and consistently use the F() macro to > calculate these at compile time and properly support fractional divisors. > > Additionally, improve clk_bcr_update() to timeout with a warning rather > than hanging the board, and make the freq_tbl struct and helpers common > so that they can be reused by future platforms. > > Signed-off-by: Caleb Connolly > --- > drivers/clk/qcom/clock-apq8016.c | 2 +- > drivers/clk/qcom/clock-apq8096.c | 2 +- > drivers/clk/qcom/clock-qcom.c| 64 > +--- > drivers/clk/qcom/clock-qcom.h| 11 +++ > drivers/clk/qcom/clock-qcs404.c | 16 +- > drivers/clk/qcom/clock-sdm845.c | 26 > 6 files changed, 67 insertions(+), 54 deletions(-) > Reviewed-by: Sumit Garg -Sumit > diff --git a/drivers/clk/qcom/clock-apq8016.c > b/drivers/clk/qcom/clock-apq8016.c > index 630619c83454..eb812934cbae 100644 > --- a/drivers/clk/qcom/clock-apq8016.c > +++ b/drivers/clk/qcom/clock-apq8016.c > @@ -78,7 +78,7 @@ static struct vote_clk gcc_blsp1_ahb_clk = { > /* SDHCI */ > static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate) > { > - int div = 8; /* 100MHz default */ > + int div = 15; /* 100MHz default */ > > if (rate == 2) > div = 4; > diff --git a/drivers/clk/qcom/clock-apq8096.c > b/drivers/clk/qcom/clock-apq8096.c > index 095c1b431245..55f16c14e046 100644 > --- a/drivers/clk/qcom/clock-apq8096.c > +++ b/drivers/clk/qcom/clock-apq8096.c > @@ -65,7 +65,7 @@ static struct vote_clk gcc_blsp2_ahb_clk = { > > static int clk_init_sdc(struct msm_clk_priv *priv, uint rate) > { > - int div = 3; > + int div = 5; > > clk_enable_cbc(priv->base + SDCC2_AHB_CBCR); > clk_rcg_set_rate_mnd(priv->base, _regs, div, 0, 0, > diff --git a/drivers/clk/qcom/clock-qcom.c b/drivers/clk/qcom/clock-qcom.c > index fc478554f982..7c683e519226 100644 > --- a/drivers/clk/qcom/clock-qcom.c > +++ b/drivers/clk/qcom/clock-qcom.c > @@ -19,6 +19,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > > @@ -68,30 +70,42 @@ void clk_enable_vote_clk(phys_addr_t base, const struct > vote_clk *vclk) > /* Update clock command via CMD_RCGR */ > void clk_bcr_update(phys_addr_t apps_cmd_rcgr) > { > + u32 count; > setbits_le32(apps_cmd_rcgr, APPS_CMD_RCGR_UPDATE); > > /* Wait for frequency to be updated. */ > - while (readl(apps_cmd_rcgr) & APPS_CMD_RCGR_UPDATE) > - ; > + for (count = 0; count < 5; count++) { > + if (!(readl(apps_cmd_rcgr) & APPS_CMD_RCGR_UPDATE)) > + break; > + udelay(1); > + } > + WARN(count == 5, "WARNING: RCG @ %#llx [%#010x] stuck at off\n", > +apps_cmd_rcgr, readl(apps_cmd_rcgr)); > } > > -#define CFG_MODE_DUAL_EDGE (0x2 << 12) /* Counter mode */ > +#define CFG_SRC_DIV_MASK 0b1 > +#define CFG_SRC_SEL_SHIFT 8 > +#define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT) > +#define CFG_MODE_SHIFT 12 > +#define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT) > +#define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT) > +#define CFG_HW_CLK_CTRL_MASK BIT(20) > > -#define CFG_MASK 0x3FFF > - > -#define CFG_DIVIDER_MASK 0x1F > - > -/* root set rate for clocks with half integer and MND divider */ > +/* > + * root set rate for clocks with half integer and MND divider > + * div should be pre-calculated ((div * 2) - 1) > + */ > void clk_rcg_set_rate_mnd(phys_addr_t base, const struct bcr_regs *regs, > int div, int m, int n, int source, u8 mnd_width) > { > u32 cfg; > /* M value for MND divider. */ > u32 m_val = m; > + u32 n_minus_m = n - m; > /* NOT(N-M) value for MND divider. */ > - u32 n_val = ~((n) - (m)) * !!(n); > + u32 n_val = ~n_minus_m * !!(n); > /* NOT 2D value for MND divider. */ > - u32 d_val = ~(n); > + u32 d_val = ~(clamp_t(u32, n, m, n_minus_m)); > u32 mask = BIT(mnd_width) - 1; > > debug("m %#x n %#x d %#x div %#x mask %#x\n", m_val, n_val, d_val, > div, mask); > @@ -103,15 +117,13 @@ void clk_rcg_set_rate_mnd(phys_addr_t base, const > struct bcr_regs *regs, > > /* setup src select and divider */ > cfg = readl(base + regs->cfg_rcgr); > - cfg &= ~CFG_MASK; > - cfg |= source & CFG_CLK_SRC_MASK; /* Select clock source */ > + cfg &= ~(CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK); > + cfg |= source & CFG_SRC_SEL_MASK; /* Select clock source */ > > - /* Set
Re: [PATCH v3 6/7] clk/qcom: add mnd_width to clk_rcg_set_rate_mnd()
On Fri, 3 Nov 2023 at 21:09, Caleb Connolly wrote: > > This property is needed on some platforms to ensure that only the > relevant bits are set in the M/N/D registers. This commit broke qcs404 platform which is fixed by following add-on change: diff --git a/drivers/clk/qcom/clock-qcs404.c b/drivers/clk/qcom/clock-qcs404.c index 429ff35e1d..f5b3528039 100644 --- a/drivers/clk/qcom/clock-qcs404.c +++ b/drivers/clk/qcom/clock-qcs404.c @@ -195,7 +195,7 @@ static ulong qcs404_clk_set_rate(struct clk *clk, ulong rate) case GCC_BLSP1_UART2_APPS_CLK: /* UART: 115200 */ clk_rcg_set_rate_mnd(priv->base, _regs, 0, 12, 125, -CFG_CLK_SRC_CXO, 8); +CFG_CLK_SRC_CXO, 16); clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR); break; case GCC_BLSP1_AHB_CLK: This is needed as per Linux qcs404 clock driver too. I would suggest you double check if you have imported correct values from corresponding Linux clock drivers for other platforms too. BTW, after this fix feel free to add: Tested-by: Sumit Garg (QCS404) -Sumit > > Signed-off-by: Caleb Connolly > Reviewed-by: Sumit Garg > --- > drivers/clk/qcom/clock-apq8016.c | 4 ++-- > drivers/clk/qcom/clock-apq8096.c | 4 ++-- > drivers/clk/qcom/clock-qcom.c| 11 +++ > drivers/clk/qcom/clock-qcom.h| 2 +- > drivers/clk/qcom/clock-qcs404.c | 18 +- > drivers/clk/qcom/clock-sdm845.c | 3 +-- > 6 files changed, 22 insertions(+), 20 deletions(-) > > diff --git a/drivers/clk/qcom/clock-apq8016.c > b/drivers/clk/qcom/clock-apq8016.c > index 3f44252c453e..630619c83454 100644 > --- a/drivers/clk/qcom/clock-apq8016.c > +++ b/drivers/clk/qcom/clock-apq8016.c > @@ -86,7 +86,7 @@ static int clk_init_sdc(struct msm_clk_priv *priv, int > slot, uint rate) > clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot)); > /* 800Mhz/div, gpll0 */ > clk_rcg_set_rate_mnd(priv->base, _regs[slot], div, 0, 0, > -CFG_CLK_SRC_GPLL0); > +CFG_CLK_SRC_GPLL0, 8); > clk_enable_gpll0(priv->base, _vote_clk); > clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot)); > > @@ -109,7 +109,7 @@ static int clk_init_uart(struct msm_clk_priv *priv) > > /* 7372800 uart block clock @ GPLL0 */ > clk_rcg_set_rate_mnd(priv->base, _regs, 1, 144, 15625, > -CFG_CLK_SRC_GPLL0); > +CFG_CLK_SRC_GPLL0, 8); > > /* Vote for gpll0 clock */ > clk_enable_gpll0(priv->base, _vote_clk); > diff --git a/drivers/clk/qcom/clock-apq8096.c > b/drivers/clk/qcom/clock-apq8096.c > index 75633a7c2af8..095c1b431245 100644 > --- a/drivers/clk/qcom/clock-apq8096.c > +++ b/drivers/clk/qcom/clock-apq8096.c > @@ -69,7 +69,7 @@ static int clk_init_sdc(struct msm_clk_priv *priv, uint > rate) > > clk_enable_cbc(priv->base + SDCC2_AHB_CBCR); > clk_rcg_set_rate_mnd(priv->base, _regs, div, 0, 0, > -CFG_CLK_SRC_GPLL0); > +CFG_CLK_SRC_GPLL0, 8); > clk_enable_gpll0(priv->base, _vote_clk); > clk_enable_cbc(priv->base + SDCC2_APPS_CBCR); > > @@ -91,7 +91,7 @@ static int clk_init_uart(struct msm_clk_priv *priv) > > /* 7372800 uart block clock @ GPLL0 */ > clk_rcg_set_rate_mnd(priv->base, _regs, 1, 192, 15625, > -CFG_CLK_SRC_GPLL0); > +CFG_CLK_SRC_GPLL0, 8); > > /* Vote for gpll0 clock */ > clk_enable_gpll0(priv->base, _vote_clk); > diff --git a/drivers/clk/qcom/clock-qcom.c b/drivers/clk/qcom/clock-qcom.c > index 77bcaacd1583..fc478554f982 100644 > --- a/drivers/clk/qcom/clock-qcom.c > +++ b/drivers/clk/qcom/clock-qcom.c > @@ -83,7 +83,7 @@ void clk_bcr_update(phys_addr_t apps_cmd_rcgr) > > /* root set rate for clocks with half integer and MND divider */ > void clk_rcg_set_rate_mnd(phys_addr_t base, const struct bcr_regs *regs, > - int div, int m, int n, int source) > + int div, int m, int n, int source, u8 mnd_width) > { > u32 cfg; > /* M value for MND divider. */ > @@ -92,11 +92,14 @@ void clk_rcg_set_rate_mnd(phys_addr_t base, const struct > bcr_regs *regs, > u32 n_val = ~((n) - (m)) * !!(n); > /* NOT 2D value for MND divider. */ > u32 d_val = ~(n); > + u32 mask = BIT(mnd_width) - 1; > + > + debug("m %#x n %#x d %#x div %#x mask %#x\n", m_val, n_val, d_val, > div, mask); > > /* Program MND values */ > - writel(m_val, base + regs->M); > - writel(n_val, base + regs->N); > - writel(d_val, base + regs->D); > + writel(m_val & mask, base + regs->M); > + writel(n_val & mask, base + regs->N); > + writel(d_val & mask, base + regs->D); > > /* setup src select and divider */ >
Re: [PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used
On 11/6/23 03:25, Sean Anderson wrote: Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be used (as there is no block device support enabled). Disable these configs. The list of boards was generated with the following command: $ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \ ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI LIBDISK was left enabled for the am* boards, since it seems to result in actual size reduction, indicating that partitions are being used for something. Signed-off-by: Sean Anderson --- (no changes since v1) configs/am335x_evm_spiboot_defconfig | 2 +- configs/am65x_evm_r5_usbdfu_defconfig | 1 - configs/xilinx_zynqmp_mini_qspi_defconfig | 3 +++ configs/zynq_cse_nand_defconfig | 3 +++ configs/zynq_cse_nor_defconfig| 3 +++ configs/zynq_cse_qspi_defconfig | 3 +++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/configs/am335x_evm_spiboot_defconfig b/configs/am335x_evm_spiboot_defconfig index b5b11fb62c8..fff5265e56a 100644 --- a/configs/am335x_evm_spiboot_defconfig +++ b/configs/am335x_evm_spiboot_defconfig @@ -13,6 +13,7 @@ CONFIG_CLOCK_SYNTHESIZER=y # CONFIG_OF_LIBFDT_OVERLAY is not set # CONFIG_SPL_MMC is not set CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set CONFIG_SPL_SPI_FLASH_SUPPORT=y CONFIG_SPL_SPI=y CONFIG_TIMESTAMP=y @@ -27,7 +28,6 @@ CONFIG_SPL_SYS_MALLOC=y CONFIG_SPL_SYS_MALLOC_SIZE=0x80 CONFIG_SPL_FIT_IMAGE_TINY=y # CONFIG_SPL_FS_EXT4 is not set -CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img" CONFIG_SPL_MTD=y # CONFIG_SPL_NAND_SUPPORT is not set CONFIG_SPL_DM_SPI_FLASH=y diff --git a/configs/am65x_evm_r5_usbdfu_defconfig b/configs/am65x_evm_r5_usbdfu_defconfig index f610b2dd94e..6b0bb120d10 100644 --- a/configs/am65x_evm_r5_usbdfu_defconfig +++ b/configs/am65x_evm_r5_usbdfu_defconfig @@ -21,7 +21,6 @@ CONFIG_SPL_DRIVERS_MISC=y CONFIG_SPL_STACK_R_ADDR=0x8200 CONFIG_SPL_SIZE_LIMIT=0x7ec00 CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x2000 -CONFIG_SPL_FS_FAT=y CONFIG_SPL_LIBDISK_SUPPORT=y # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set CONFIG_SPL_LOAD_FIT=y diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig b/configs/xilinx_zynqmp_mini_qspi_defconfig index a1adfb9e5d1..8b92e1c7358 100644 --- a/configs/xilinx_zynqmp_mini_qspi_defconfig +++ b/configs/xilinx_zynqmp_mini_qspi_defconfig @@ -11,6 +11,8 @@ CONFIG_ENV_SIZE=0x80 CONFIG_DEFAULT_DEVICE_TREE="zynqmp-mini-qspi" CONFIG_SPL_STACK=0xfffc CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set +# CONFIG_SPL_LIBDISK_SUPPORT is not set CONFIG_SYS_MEM_RSVD_FOR_MMU=y CONFIG_ZYNQMP_NO_DDR=y # CONFIG_PSCI_RESET is not set @@ -89,6 +91,7 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_ARM_DCC=y CONFIG_SPI=y CONFIG_ZYNQMP_GQSPI=y +CONFIG_FS_FAT=y This can be also removed and also for zynq_cse boards below. There is no need to have FAT support. Thanks, Michal
Re: [PATCH 1/2] board: ti: am62x: am62x.env: Fix boot_targets
Hi Simon, On 11:22-20231005, Simon Glass wrote: > Hi Nishanth, > > On Thu, 5 Oct 2023 at 11:16, Nishanth Menon wrote: > > > > On 12:10-20231005, Nishanth Menon wrote: > > > On 12:36-20231005, Tom Rini wrote: > > > > On Thu, Oct 05, 2023 at 09:19:48AM -0500, Andrew Davis wrote: > > > > > On 10/4/23 8:54 AM, Nishanth Menon wrote: > > > > > > On 08:48-20231004, Andrew Davis wrote: > > > > > > > On 10/4/23 8:23 AM, Roger Quadros wrote: > > > > > > > > ti_mmc is not a valid boot_target for standard boot flow so > > > > > > > > > > > > > > Is there some way to make it into a valid boot_target? Otherwise > > > > > > > how do we use uEnv.txt files, or boot from FIT images with > > > > > > > overlays? > > > > > > > > > > > > envboot takes care of uEnv.txt file (see > > > > > > https://lore.kernel.org/all/20231004132324.44198-3-rog...@kernel.org/) > > > > > > > > > > > > Early remote proc loading and FIT image is a question for stdboot > > > > > > itself. > > > > > > > > > > > > > > > > If stdboot is missing these features then we shouldn't switch until it > > > > > has them. I'm all for switching to this, but only if it is complete. > > > > > > > > Depends on what you mean? Did you mean an option to run scripts > > > > (exists) or an option to do what TI needs done, via > > > > boot/bootmeth_something.c ? If the latter, someone from TI needs to > > > > figure out what that should be and do (but plumbing-wise everything it > > > > needs should exist). > > > > > > Andrew is generalizing here (on the wrong patch though). > > > > > > On am62x platforms, there is nothing regressing with this series. The > > > challenge is early remote_proc loading which is done for J7* platforms. > > > > > > How that is initiated as part of bootmethods is something of a gap. > > > > > > The other gap has been support for uEnv.txt -> which we can workaround > > > at the moment by using CONFIG_BOOTCOMMAND="run envboot; bootflow scan > > > -lb" in defconfig (This series from Roger already does that - hence I am > > > saying that Andrew is complaining on the wrong series). > > > > > > Ideally, we should just have CONFIG_BOOTCOMMAND="bootflow scan -lb" and > > > uEnv.txt remoteproc loads and the various standard bootmethods should > > > "just work". > > > > > > I forgot to add: FIT image authenticated boot flow. That is really what > > ti_mmc distroboot method was trying to solve. > > > > Maybe Simon or someone know how the stdboot flow handles authenticated > > kernel image and dtb boot flow with FIT image? > > Yes you can use FIT configuration verification and things should work as > normal. > Could you give any reference documentation for this? Regards, Manorit > Regards, > Simon
Re: [PATCH 10/15] configs: j721e_evm_a72_defconfig: Switch to bootstd
Hi Nishanth, On 19:38-20231102, Nishanth Menon wrote: > Switch to using bootstd. Note with this change, we will stop using > distro_bootcmd and instead depend entirely on bootflow method of > starting the system up. > > Signed-off-by: Nishanth Menon > --- > configs/j721e_evm_a72_defconfig | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig > index 99e0e168ebf7..98ac7ca59789 100644 > --- a/configs/j721e_evm_a72_defconfig > +++ b/configs/j721e_evm_a72_defconfig > @@ -29,10 +29,11 @@ CONFIG_SPL_SPI=y > # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set > CONFIG_SPL_LOAD_FIT=y > CONFIG_SPL_LOAD_FIT_ADDRESS=0x8100 > -CONFIG_DISTRO_DEFAULTS=y > CONFIG_OF_BOARD_SETUP=y > CONFIG_OF_SYSTEM_SETUP=y > -CONFIG_BOOTCOMMAND="run envboot; run distro_bootcmd;" > +CONFIG_BOOTSTD_FULL=y > +CONFIG_BOOTSTD_DEFAULTS=y > +CONFIG_BOOTCOMMAND="run envboot; bootflow scan -lb" Coming back to [0], AM62x didn't have early remote procs but j721e does, do you have any alternatives in place before migrating J7 platforms to stdboot? Regards, Manorit [0]: https://lore.kernel.org/u-boot/20231005171010.zvza7uqyn4mcgp5g@handsaw/ > CONFIG_LOGLEVEL=7 > CONFIG_SPL_MAX_SIZE=0xc > CONFIG_SPL_HAS_BSS_LINKER_SECTION=y > -- > 2.40.0 >
[PATCH] mtd: spi-nor: Update block protection flags for ospi flash parts
Updating the block protection flags for Gigadevice gd25lx256e and ISSI is25wx256 OSPI flash parts. Signed-off-by: Venkatesh Yadav Abbarapu --- drivers/mtd/spi/spi-nor-ids.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c index 77eb9f352c..b939780889 100644 --- a/drivers/mtd/spi/spi-nor-ids.c +++ b/drivers/mtd/spi/spi-nor-ids.c @@ -191,7 +191,8 @@ const struct flash_info spi_nor_ids[] = { SPI_NOR_QUAD_READ | SPI_NOR_HAS_LOCK | SPI_NOR_4B_OPCODES)}, { INFO("gd25lx256e", 0xc86819, 0, 64 * 1024, 512, -SECT_4K | SPI_NOR_OCTAL_READ | SPI_NOR_4B_OPCODES) +SECT_4K | SPI_NOR_OCTAL_READ | SPI_NOR_4B_OPCODES | +SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, /* adding these 1.8V OSPI flash parts */ {INFO("gd25lx512", 0xc8681A, 0, 64 * 1024, 1024,SECT_4K | @@ -233,7 +234,8 @@ const struct flash_info spi_nor_ids[] = { { INFO("is25wp01g", 0x9d701b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { INFO("is25wx256", 0x9d5b19, 0, 128 * 1024, 256, - SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ | SPI_NOR_4B_OPCODES) }, + SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ | SPI_NOR_4B_OPCODES | + SPI_NOR_HAS_TB) }, #endif #ifdef CONFIG_SPI_FLASH_MACRONIX /* MACRONIX */ /* Macronix */ -- 2.17.1
[PATCH v2] timer: starfive: Add Starfive timer support
Add timer driver in Starfive SoC. It is an timer that outside of CPU core and inside Starfive SoC. Signed-off-by: Kuan Lim Lee Signed-off-by: Wei Liang Lim Reviewed-by: Simon Glass Changes for v2: - correct driver name, comment, variable --- drivers/timer/Kconfig | 7 +++ drivers/timer/Makefile | 1 + drivers/timer/starfive-timer.c | 96 ++ 3 files changed, 104 insertions(+) create mode 100644 drivers/timer/starfive-timer.c diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 915b2af160..a98be9dfae 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -326,4 +326,11 @@ config XILINX_TIMER Select this to enable support for the timer found on any Xilinx boards (axi timer). +config STARFIVE_TIMER + bool "Starfive timer support" + depends on TIMER + help + Select this to enable support for the timer found on + Starfive SoC. + endmenu diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index 1ca74805fd..1ef814970b 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -34,3 +34,4 @@ obj-$(CONFIG_MTK_TIMER) += mtk_timer.o obj-$(CONFIG_MCHP_PIT64B_TIMER)+= mchp-pit64b-timer.o obj-$(CONFIG_IMX_GPT_TIMER)+= imx-gpt-timer.o obj-$(CONFIG_XILINX_TIMER) += xilinx-timer.o +obj-$(CONFIG_STARFIVE_TIMER) += starfive-timer.o diff --git a/drivers/timer/starfive-timer.c b/drivers/timer/starfive-timer.c new file mode 100644 index 00..b9ba33277e --- /dev/null +++ b/drivers/timer/starfive-timer.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2022 StarFive, Inc. All rights reserved. + * Author: Lee Kuan Lim + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#defineSTF_TIMER_INT_STATUS0x00 +#define STF_TIMER_CTL 0x04 +#define STF_TIMER_LOAD 0x08 +#define STF_TIMER_ENABLE 0x10 +#define STF_TIMER_RELOAD 0x14 +#define STF_TIMER_VALUE0x18 +#define STF_TIMER_INT_CLR 0x20 +#define STF_TIMER_INT_MASK 0x24 + +struct starfive_timer_priv { + void __iomem *base; + u32 timer_size; +}; + +static u64 notrace starfive_get_count(struct udevice *dev) +{ + struct starfive_timer_priv *priv = dev_get_priv(dev); + + /* Read decrement timer value and convert to increment value */ + return priv->timer_size - readl(priv->base + STF_TIMER_VALUE); +} + +static const struct timer_ops starfive_ops = { + .get_count = starfive_get_count, +}; + +static int starfive_probe(struct udevice *dev) +{ + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + struct starfive_timer_priv *priv = dev_get_priv(dev); + int timer_channel; + struct clk clk; + int ret; + + priv->base = dev_read_addr_ptr(dev); + if (!priv->base) + return -EINVAL; + + timer_channel = dev_read_u32_default(dev, "channel", 0); + priv->base = priv->base + (0x40 * timer_channel); + + /* Get clock rate from channel selectecd*/ + ret = clk_get_by_index(dev, timer_channel, ); + if (ret) + return ret; + + ret = clk_enable(); + if (ret) + return ret; + uc_priv->clock_rate = clk_get_rate(); + + /* +* Initiate timer, channel 0 +* Unmask Interrupt Mask +*/ + writel(0, priv->base + STF_TIMER_INT_MASK); + /* Single run mode Setting */ + if (dev_read_bool(dev, "single-run")) + writel(1, priv->base + STF_TIMER_CTL); + /* Set Reload value */ + priv->timer_size = dev_read_u32_default(dev, "timer-size", -1U); + writel(priv->timer_size, priv->base + STF_TIMER_LOAD); + /* Enable to start timer */ + writel(1, priv->base + STF_TIMER_ENABLE); + + return 0; +} + +static const struct udevice_id starfive_ids[] = { + { .compatible = "starfive,jh8100-timers" }, + { } +}; + +U_BOOT_DRIVER(jh8100_starfive_timer) = { + .name = "starfive_timer", + .id = UCLASS_TIMER, + .of_match = starfive_ids, + .probe = starfive_probe, + .ops= _ops, + .priv_auto = sizeof(struct starfive_timer_priv), +}; -- 2.34.1
[PATCH v6 20/25] spl: Convert nor to spl_load
This converts the nor load method to use spl_load. As a result it also adds support for LOAD_FIT_FULL. Since this is the last caller of spl_load_legacy_img, it has been removed. We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the test in that case. No boards enable SPL_NOR_SUPPORT and SPL_LOAD_FIT_FULL, so this is not a regression. Signed-off-by: Sean Anderson --- Changes in v6: - Fix LZMA support - Fix load address - Explicitly initialize load_info members Changes in v5: - Rework to load header in spl_load common/spl/spl_legacy.c | 61 --- common/spl/spl_nor.c | 40 + include/spl_load.h| 1 + test/image/spl_load_nor.c | 2 ++ 4 files changed, 10 insertions(+), 94 deletions(-) diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index a561939b4f0..08687ca8f6c 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -118,64 +118,3 @@ int spl_load_legacy_lzma(struct spl_image_info *spl_image, spl_image->size = lzma_len; return 0; } - -/* - * This function is added explicitly to avoid code size increase, when - * no compression method is enabled. The compiler will optimize the - * following switch/case statement in spl_load_legacy_img() away due to - * Dead Code Elimination. - */ -static inline int spl_image_get_comp(const struct legacy_img_hdr *hdr) -{ - if (IS_ENABLED(CONFIG_SPL_LZMA)) - return image_get_comp(hdr); - - return IH_COMP_NONE; -} - -int spl_load_legacy_img(struct spl_image_info *spl_image, - struct spl_boot_device *bootdev, - struct spl_load_info *load, ulong offset, - struct legacy_img_hdr *hdr) -{ - ulong dataptr; - int ret; - - /* -* If the payload is compressed, the decompressed data should be -* directly write to its load address. -*/ - if (spl_image_get_comp(hdr) != IH_COMP_NONE) - spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; - - ret = spl_parse_image_header(spl_image, bootdev, hdr); - if (ret) - return ret; - - /* Read image */ - switch (spl_image_get_comp(hdr)) { - case IH_COMP_NONE: - dataptr = offset; - - /* -* Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY -* is set -*/ - if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) - dataptr += sizeof(*hdr); - - load->read(load, dataptr, spl_image->size, - map_sysmem(spl_image->load_addr, spl_image->size)); - break; - - case IH_COMP_LZMA: - return spl_load_legacy_lzma(spl_image, load, offset); - - default: - debug("Compression method %s is not supported\n", - genimg_get_comp_short_name(image_get_comp(hdr))); - return -EINVAL; - } - - return 0; -} diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index aad230db4d3..70745114efe 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) @@ -28,8 +28,7 @@ unsigned long __weak spl_nor_get_uboot_base(void) static int spl_nor_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { - struct legacy_img_hdr *header; - __maybe_unused struct spl_load_info load; + struct spl_load_info load; /* * Loading of the payload to SDRAM is done with skipping of @@ -43,7 +42,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, * Load Linux from its location in NOR flash to its defined * location in SDRAM */ - header = (void *)CONFIG_SYS_OS_BASE; + const struct legacy_img_hdr *header = + (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE; #ifdef CONFIG_SPL_LOAD_FIT if (image_get_magic(header) == FDT_MAGIC) { int ret; @@ -93,34 +93,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, * Load real U-Boot from its location in NOR flash to its * defined location in SDRAM */ - header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header)); -#ifdef CONFIG_SPL_LOAD_FIT - if (image_get_magic(header) == FDT_MAGIC) { - debug("Found FIT format U-Boot\n"); - spl_set_bl_len(, 1); - load.read = spl_nor_load_read; - return spl_load_simple_fit(spl_image, , - spl_nor_get_uboot_base(), -
[PATCH v6 15/25] spl: Convert ext to use spl_load
This converts the ext load method to use spl_load. As a consequence, it also adds support for FIT and IMX images. Signed-off-by: Sean Anderson --- Changes in v6: - Explicitly initialize load_info members Changes in v5: - Rework to load header in spl_load common/spl/spl_ext.c | 36 ++-- include/spl_load.h | 1 + test/image/spl_load_fs.c | 9 ++--- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index af836ca15b8..d280b69c387 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -2,25 +2,35 @@ #include #include -#include #include #include +#include #include #include #include #include +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, + ulong size, void *buf) +{ + int ret; + loff_t actlen; + + ret = ext4fs_read(buf, file_offset, size, ); + if (ret) + return ret; + return actlen; +} + int spl_load_image_ext(struct spl_image_info *spl_image, struct spl_boot_device *bootdev, struct blk_desc *block_dev, int partition, const char *filename) { s32 err; - struct legacy_img_hdr *header; - loff_t filelen, actlen; + loff_t filelen; struct disk_partition part_info = {}; - - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + struct spl_load_info load; if (part_get_info(block_dev, partition, _info)) { printf("spl: no partition table found\n"); @@ -42,20 +52,10 @@ int spl_load_image_ext(struct spl_image_info *spl_image, puts("spl: ext4fs_open failed\n"); goto end; } - err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), ); - if (err < 0) { - puts("spl: ext4fs_read failed\n"); - goto end; - } - err = spl_parse_image_header(spl_image, bootdev, header); - if (err < 0) { - puts("spl: ext: failed to parse image header\n"); - goto end; - } - - err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen, - ); + spl_set_bl_len(, 1); + load.read = spl_fit_read; + err = spl_load(spl_image, bootdev, , filelen, 0); end: #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT diff --git a/include/spl_load.h b/include/spl_load.h index 406f8b577b2..65aa6bb4493 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image, * inline if there is one caller, and extern otherwise. */ #define SPL_LOAD_USERS \ + IS_ENABLED(CONFIG_SPL_FS_EXT4) + \ 0 #if SPL_LOAD_USERS > 1 diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c index 59d0244d44b..01559e98c4f 100644 --- a/test/image/spl_load_fs.c +++ b/test/image/spl_load_fs.c @@ -422,20 +422,23 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name, spl_mmc_clear_cache(); spl_fat_force_reregister(); - if (type == LEGACY && - spl_test_mmc_fs(uts, test_name, type, create_ext2, false)) + if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false)) return CMD_RET_FAILURE; - if (type != IMX8 && + if (type != IMX8 && type != LEGACY_LZMA && spl_test_mmc_fs(uts, test_name, type, create_fat, false)) return CMD_RET_FAILURE; + if (type == LEGACY_LZMA) + return 0; + return do_spl_test_load(uts, test_name, type, SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1, spl_mmc_load_image), spl_test_mmc_write_image); } SPL_IMG_TEST(spl_test_mmc, LEGACY, DM_FLAGS); +SPL_IMG_TEST(spl_test_mmc, LEGACY_LZMA, DM_FLAGS); SPL_IMG_TEST(spl_test_mmc, IMX8, DM_FLAGS); SPL_IMG_TEST(spl_test_mmc, FIT_EXTERNAL, DM_FLAGS); SPL_IMG_TEST(spl_test_mmc, FIT_INTERNAL, DM_FLAGS); -- 2.37.1
[PATCH v6 22/25] spl: Convert semihosting to spl_load
This converts the semihosting load method to use spl_load. As a result, it also adds support for LOAD_FIT_FULL and IMX images. Signed-off-by: Sean Anderson --- Changes in v6: - Explicitly initialize load_info members Changes in v5: - Rework to load header in spl_load Changes in v2: - New common/spl/spl_semihosting.c | 52 +--- include/spl_load.h | 1 + 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c index 9b0610b8fc8..941fa911040 100644 --- a/common/spl/spl_semihosting.c +++ b/common/spl/spl_semihosting.c @@ -8,18 +8,7 @@ #include #include #include - -static int smh_read_full(long fd, void *memp, size_t len) -{ - long read; - - read = smh_read(fd, memp, len); - if (read < 0) - return read; - if (read != len) - return -EIO; - return 0; -} +#include static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset, ulong size, void *buf) @@ -40,8 +29,7 @@ static int spl_smh_load_image(struct spl_image_info *spl_image, const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME; int ret; long fd, len; - struct legacy_img_hdr *header = - spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + struct spl_load_info load; fd = smh_open(filename, MODE_READ | MODE_BINARY); if (fd < 0) { @@ -56,38 +44,10 @@ static int spl_smh_load_image(struct spl_image_info *spl_image, } len = ret; - ret = smh_read_full(fd, header, sizeof(struct legacy_img_hdr)); - if (ret) { - log_debug("could not read image header: %d\n", ret); - goto out; - } - - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - load.read = smh_fit_read; - spl_set_bl_len(, 1); - load.priv = - - ret = spl_load_simple_fit(spl_image, , 0, header); - goto out; - } - - ret = spl_parse_image_header(spl_image, bootdev, header); - if (ret) { - log_debug("failed to parse image header: %d\n", ret); - goto out; - } - - ret = smh_seek(fd, 0); - if (ret) { - log_debug("could not seek to start of image: %d\n", ret); - goto out; - } - - ret = smh_read_full(fd, (void *)spl_image->load_addr, len); + load.read = smh_fit_read; + spl_set_bl_len(, 1); + load.priv = + ret = spl_load(spl_image, bootdev, , len, 0); if (ret) log_debug("could not read %s: %d\n", filename, ret); out: diff --git a/include/spl_load.h b/include/spl_load.h index 2618109cee0..2a20e866cd8 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -102,6 +102,7 @@ static inline int _spl_load(struct spl_image_info *spl_image, (IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \ IS_ENABLED(CONFIG_SPL_NET) + \ IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \ + IS_ENABLED(CONFIG_SPL_SEMIHOSTING) + \ 0 #if SPL_LOAD_USERS > 1 -- 2.37.1
[PATCH v6 25/25] spl: fat: Add option to disable DMA alignment
If we don't DMA-align buffers we pass to FAT, it will align them itself. This behaviour likely should be deprecated in favor of CONFIG_BOUNCE_BUFFER, but that's a task for another series. For the meantime, don't bother aligning the buffer unless we had been doing so in the past. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/Kconfig | 18 -- common/spl/spl_blk_fs.c | 5 - common/spl/spl_fat.c| 5 - 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/spl/Kconfig b/common/spl/Kconfig index b93526904eb..fc284a5bffc 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -694,13 +694,28 @@ config SPL_FS_SQUASHFS config SPL_FS_FAT bool "Support FAT filesystems" select FS_FAT - select SPL_LOAD_BLOCK help Enable support for FAT and VFAT filesystems with SPL. This permits U-Boot (or Linux in Falcon mode) to be loaded from a FAT filesystem from within SPL. Support for the underlying block device (e.g. MMC or USB) must be enabled separately. +config SPL_FS_FAT_DMA_ALIGN + bool "Use DMA-aligned buffers with FAT" + depends on SPL_FS_FAT + select SPL_LOAD_BLOCK + default y if SPL_LOAD_FIT + help + The FAT filesystem driver tries to ensure that the reads it issues to + the block subsystem use DMA-aligned buffers. If the supplied buffer is + not DMA-aligned, the FAT driver will use a bounce-buffer and read + block-by-block. This is separate from the bounce-buffer used by the + block subsystem (CONFIG_BOUNCE_BUFFER). + + Enable this config to align buffers passed to the FAT filesystem + driver. This will speed up reads, but will increase the size of U-Boot + by around 60 bytes. + config SPL_FS_LOAD_PAYLOAD_NAME string "File to load for U-Boot from the filesystem" depends on SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS || SPL_SEMIHOSTING @@ -1282,7 +1297,6 @@ config SPL_NVME depends on BLK select FS_LOADER select SPL_BLK_FS - select SPL_LOAD_BLOCK help This option enables support for NVM Express devices. It supports basic functions of NVMe (read/write). diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c index ac267ab979b..04eac6f306b 100644 --- a/common/spl/spl_blk_fs.c +++ b/common/spl/spl_blk_fs.c @@ -82,7 +82,10 @@ int spl_blk_load_image(struct spl_image_info *spl_image, } load.read = spl_fit_read; - spl_set_bl_len(, ARCH_DMA_MINALIGN); + if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN)) + spl_set_bl_len(, ARCH_DMA_MINALIGN); + else + spl_set_bl_len(, 1); load.priv = return spl_load(spl_image, bootdev, , filesize, 0); } diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 569f2b32928..a52f9e178e6 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -86,7 +86,10 @@ int spl_load_image_fat(struct spl_image_info *spl_image, } load.read = spl_fit_read; - spl_set_bl_len(, ARCH_DMA_MINALIGN); + if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN)) + spl_set_bl_len(, ARCH_DMA_MINALIGN); + else + spl_set_bl_len(, 1); load.priv = (void *)filename; err = spl_load(spl_image, bootdev, , size, 0); -- 2.37.1
[PATCH v6 21/25] spl: Convert NVMe to spl_load
This converts the blk load method (used exclusively by NVMe) to use spl_load. As a consequence, it also adds support for LOAD_FIT_FULL and IMX images. Signed-off-by: Sean Anderson --- Changes in v6: - Fix invalid return from spl_blk_load_image - Explicitly initialize load_info members Changes in v5: - New common/spl/spl_blk_fs.c | 66 +++- include/spl_load.h | 1 + test/image/spl_load_fs.c | 2 ++ 3 files changed, 14 insertions(+), 55 deletions(-) diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c index 53b8e1b11b4..ac267ab979b 100644 --- a/common/spl/spl_blk_fs.c +++ b/common/spl/spl_blk_fs.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -48,11 +49,11 @@ int spl_blk_load_image(struct spl_image_info *spl_image, enum uclass_id uclass_id, int devnum, int partnum) { const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME; - struct legacy_img_hdr *header; struct blk_desc *blk_desc; - loff_t actlen, filesize; + loff_t filesize; struct blk_dev dev; - int ret = -ENODEV; + struct spl_load_info load; + int ret; blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum); if (!blk_desc) { @@ -61,8 +62,8 @@ int spl_blk_load_image(struct spl_image_info *spl_image, } blk_show_device(uclass_id, devnum); - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + dev.filename = filename; dev.ifname = blk_get_uclass_name(uclass_id); snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%x:%x", devnum, partnum); @@ -70,63 +71,18 @@ int spl_blk_load_image(struct spl_image_info *spl_image, if (ret) { printf("spl: unable to set blk_dev %s %s. Err - %d\n", dev.ifname, dev.dev_part_str, ret); - goto out; - } - - ret = fs_read(filename, virt_to_phys(header), 0, - sizeof(struct legacy_img_hdr), ); - if (ret) { - printf("spl: unable to read file %s. Err - %d\n", filename, - ret); - goto out; - } - - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - load.read = spl_fit_read; - spl_set_bl_len(, ARCH_DMA_MINALIGN); - load.priv = - dev.filename = filename; - - return spl_load_simple_fit(spl_image, , 0, header); - } - - ret = spl_parse_image_header(spl_image, bootdev, header); - if (ret) { - printf("spl: unable to parse image header. Err - %d\n", - ret); - goto out; - } - - ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); - if (ret) { - printf("spl: unable to set blk_dev %s %s. Err - %d\n", - dev.ifname, dev.dev_part_str, ret); - goto out; + return ret; } ret = fs_size(filename, ); if (ret) { printf("spl: unable to get file size: %s. Err - %d\n", filename, ret); - goto out; + return ret; } - ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); - if (ret) { - printf("spl: unable to set blk_dev %s %s. Err - %d\n", - dev.ifname, dev.dev_part_str, ret); - goto out; - } - - ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize, - ); - if (ret) - printf("spl: unable to read file %s. Err - %d\n", - filename, ret); -out: - return ret; + load.read = spl_fit_read; + spl_set_bl_len(, ARCH_DMA_MINALIGN); + load.priv = + return spl_load(spl_image, bootdev, , filesize, 0); } diff --git a/include/spl_load.h b/include/spl_load.h index b48f80324bb..2618109cee0 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image, * inline if there is one caller, and extern otherwise. */ #define SPL_LOAD_USERS \ + IS_ENABLED(CONFIG_SPL_BLK_FS) + \ IS_ENABLED(CONFIG_SPL_FS_EXT4) + \ IS_ENABLED(CONFIG_SPL_FS_FAT) + \ IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \ diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c index 67c19da95e7..5f1de5486f4 100644 --- a/test/image/spl_load_fs.c +++ b/test/image/spl_load_fs.c @@ -395,6 +395,8 @@ static int spl_test_blk(struct unit_test_state *uts, const char *test_name, return spl_test_mmc_fs(uts, test_name, type, create_ext2, true); } SPL_IMG_TEST(spl_test_blk, LEGACY, DM_FLAGS); +SPL_IMG_TEST(spl_test_blk, LEGACY_LZMA,
[PATCH v6 18/25] spl: Convert nand to spl_load
This converts the nand load method to use spl_load. nand_page_size may not be valid until after nand_spl_load_image is called (see e.g. fsl_ifc_spl), so we set bl_len in spl_nand_read. Since spl_load reads the header for us, we can remove that argument from spl_nand_load_element. There are two possible regressions which could result from this commit. First, we ask for a negative address from spl_get_load_buffer. That is, instead of header = spl_get_load_buffer(0, sizeof(*header)); we do header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); this could cause a problem if spl_get_load_buffer does not return valid memory for negative offsets. Second, we now set bl_len for legacy images. This can cause memory up to a bl_len - 1 before the image load address to be written, which might not have been the case before. If this turns out to be a problem, we can add an option for a bounce buffer. We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the test in that case. No boards enable SPL_NAND_SUPPORT and SPL_LOAD_FIT_FULL, so this is not a regression. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_nand.c | 70 +- include/spl_load.h | 1 + test/image/spl_load_nand.c | 2 ++ 3 files changed, 19 insertions(+), 54 deletions(-) diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 91fa7674f17..3b0a1524238 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size, sector = *(int *)load->priv; offs = sector + nand_spl_adjust_offset(sector, offs - sector); err = nand_spl_load_image(offs, size, dst); + spl_set_bl_len(load, nand_page_size()); if (err) return 0; @@ -66,60 +68,20 @@ static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size, } static int spl_nand_load_element(struct spl_image_info *spl_image, -struct spl_boot_device *bootdev, -int offset, struct legacy_img_hdr *header) +struct spl_boot_device *bootdev, int offset) { - int bl_len; - int err; + struct spl_load_info load; - err = nand_spl_load_image(offset, sizeof(*header), (void *)header); - if (err) - return err; - - bl_len = nand_page_size(); - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - load.priv = - spl_set_bl_len(, bl_len); - load.read = spl_nand_read; - return spl_load_simple_fit(spl_image, , offset, header); - } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && - valid_container_hdr((void *)header)) { - struct spl_load_info load; - - load.priv = - spl_set_bl_len(, bl_len); - load.read = spl_nand_read; - return spl_load_imx_container(spl_image, , offset); - } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) && - image_get_magic(header) == IH_MAGIC) { - struct spl_load_info load; - - debug("Found legacy image\n"); - load.priv = - spl_set_bl_len(, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1); - load.read = spl_nand_read; - return spl_load_legacy_img(spl_image, bootdev, , offset, header); - } else { - err = spl_parse_image_header(spl_image, bootdev, header); - if (err) - return err; - return nand_spl_load_image(offset, spl_image->size, - map_sysmem(spl_image->load_addr, - spl_image->size)); - } + load.priv = + spl_set_bl_len(, 1); + load.read = spl_nand_read; + return spl_load(spl_image, bootdev, , 0, offset); } static int spl_nand_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { int err; - struct legacy_img_hdr *header; - int *src __attribute__((unused)); - int *dst __attribute__((unused)); #ifdef CONFIG_SPL_NAND_SOFTECC debug("spl: nand - using sw ecc\n"); @@ -128,10 +90,12 @@ static int spl_nand_load_image(struct spl_image_info *spl_image, #endif nand_init(); - header = spl_get_load_buffer(0, sizeof(*header)); - #if CONFIG_IS_ENABLED(OS_BOOT) if (!spl_start_uboot()) { + int *src, *dst; + struct legacy_img_hdr *header = +
[PATCH v6 23/25] spl: Convert spi to spl_load
This converts the spi load method to use spl_load. The address used for LOAD_FIT_FULL may be different, but there are no in-tree users of that config. Since payload_offs is only used without OS_BOOT, we defer its initialization. Signed-off-by: Sean Anderson --- Changes in v6: - Fix soft reset after loading from SPI Changes in v5: - Rework to load header in spl_load common/spl/spl_spi.c | 80 +++ include/spl_load.h| 1 + test/image/spl_load_spi.c | 1 + 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index 3e08ac7c1a2..f49e534b749 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -12,11 +12,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -95,9 +95,9 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, int err = 0; unsigned int payload_offs; struct spi_flash *flash; - struct legacy_img_hdr *header; unsigned int sf_bus = spl_spi_boot_bus(); unsigned int sf_cs = spl_spi_boot_cs(); + struct spl_load_info load; /* * Load U-Boot image from SPI flash into RAM @@ -112,77 +112,23 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, return -ENODEV; } +#if CONFIG_IS_ENABLED(OS_BOOT) + if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, header)) + return 0; +#endif + payload_offs = spl_spi_get_uboot_offs(flash); - - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); - if (CONFIG_IS_ENABLED(OF_REAL)) { payload_offs = ofnode_conf_read_int("u-boot,spl-payload-offset", payload_offs); } -#if CONFIG_IS_ENABLED(OS_BOOT) - if (spl_start_uboot() || spi_load_image_os(spl_image, bootdev, flash, header)) -#endif - { - /* Load u-boot, mkimage header is 64 bytes. */ - err = spi_flash_read(flash, payload_offs, sizeof(*header), -(void *)header); - if (err) { - debug("%s: Failed to read from SPI flash (err=%d)\n", - __func__, err); - return err; - } - - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) && - image_get_magic(header) == FDT_MAGIC) { - u32 size = roundup(fdt_totalsize(header), 4); - - err = spi_flash_read(flash, payload_offs, -size, -map_sysmem(CONFIG_SYS_LOAD_ADDR, - size)); - if (err) - return err; - err = spl_parse_image_header(spl_image, bootdev, - phys_to_virt(CONFIG_SYS_LOAD_ADDR)); - } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - load.priv = flash; - spl_set_bl_len(, 1); - load.read = spl_spi_fit_read; - err = spl_load_simple_fit(spl_image, , - payload_offs, - header); - } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && - valid_container_hdr((void *)header)) { - struct spl_load_info load; - - load.priv = flash; - spl_set_bl_len(, 1); - load.read = spl_spi_fit_read; - - err = spl_load_imx_container(spl_image, , -payload_offs); - } else { - err = spl_parse_image_header(spl_image, bootdev, header); - if (err) - return err; - err = spi_flash_read(flash, payload_offs + spl_image->offset, -spl_image->size, -map_sysmem(spl_image->load_addr, - spl_image->size)); - } - if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) { - err = spi_nor_remove(flash); - if (err) - return err; - } - } - + load.priv = flash; + spl_set_bl_len(, 1); + load.read = spl_spi_fit_read; + err = spl_load(spl_image,
[PATCH v6 24/25] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
spi_load_image_os performs almost the same steps as the non-falcon-boot path of spl_spi_load_image. The load address is different, and it also loads a device tree, but that's it. Refactor the boot process so that they can both use the same load function. Signed-off-by: Sean Anderson --- (no changes since v5) Changes in v5: - Rework to load header in spl_load Changes in v2: - New common/spl/spl_spi.c | 54 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index f49e534b749..89de73c726c 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -21,41 +21,6 @@ #include #include -#if CONFIG_IS_ENABLED(OS_BOOT) -/* - * Load the kernel, check for a valid header we can parse, and if found load - * the kernel and then device tree. - */ -static int spi_load_image_os(struct spl_image_info *spl_image, -struct spl_boot_device *bootdev, -struct spi_flash *flash, -struct legacy_img_hdr *header) -{ - int err; - - /* Read for a header, parse or error out. */ - spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS, sizeof(*header), - (void *)header); - - if (image_get_magic(header) != IH_MAGIC) - return -1; - - err = spl_parse_image_header(spl_image, bootdev, header); - if (err) - return err; - - spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS, - spl_image->size, (void *)spl_image->load_addr); - - /* Read device tree. */ - spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS, - CFG_SYS_SPI_ARGS_SIZE, - (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR); - - return 0; -} -#endif - static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { @@ -112,9 +77,21 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, return -ENODEV; } + load.priv = flash; + spl_set_bl_len(, 1); + load.read = spl_spi_fit_read; + #if CONFIG_IS_ENABLED(OS_BOOT) - if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, header)) - return 0; + if (spl_start_uboot()) { + int err = spl_load(spl_image, bootdev, , 0, + CFG_SYS_SPI_KERNEL_OFFS); + + if (!err) + /* Read device tree. */ + return spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS, + CFG_SYS_SPI_ARGS_SIZE, + (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR); + } #endif payload_offs = spl_spi_get_uboot_offs(flash); @@ -123,9 +100,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, payload_offs); } - load.priv = flash; - spl_set_bl_len(, 1); - load.read = spl_spi_fit_read; err = spl_load(spl_image, bootdev, , 0, payload_offs); if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) err = spi_nor_remove(flash); -- 2.37.1
[PATCH v6 19/25] spl: Convert net to spl_load
This converts the net load method to use spl_load. As a result, it also adds support for LOAD_FIT_FULL and IMX images. Signed-off-by: Sean Anderson --- Changes in v6: - Explicitly initialize load_info members Changes in v5: - Rework to load header in spl_load common/spl/spl_net.c | 29 + include/spl_load.h| 1 + test/image/spl_load_net.c | 2 ++ 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 47994e28165..898f9df705a 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include @@ -29,8 +29,7 @@ static ulong spl_net_load_read(struct spl_load_info *load, ulong sector, static int spl_net_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { - struct legacy_img_hdr *header = map_sysmem(image_load_addr, - sizeof(*header)); + struct spl_load_info load; int rv; env_init(); @@ -49,27 +48,9 @@ static int spl_net_load_image(struct spl_image_info *spl_image, return rv; } - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - spl_set_bl_len(, 1); - load.read = spl_net_load_read; - rv = spl_load_simple_fit(spl_image, , 0, header); - } else { - debug("Legacy image\n"); - - rv = spl_parse_image_header(spl_image, bootdev, header); - if (rv) - return rv; - - memcpy(map_sysmem(spl_image->load_addr, spl_image->size), - map_sysmem(image_load_addr, spl_image->size), - spl_image->size); - } - - return rv; + spl_set_bl_len(, 1); + load.read = spl_net_load_read; + return spl_load(spl_image, bootdev, , 0, 0); } #endif diff --git a/include/spl_load.h b/include/spl_load.h index 38294a21ad0..4777f84ac6b 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -99,6 +99,7 @@ static inline int _spl_load(struct spl_image_info *spl_image, IS_ENABLED(CONFIG_SPL_FS_FAT) + \ IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \ (IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \ + IS_ENABLED(CONFIG_SPL_NET) + \ 0 #if SPL_LOAD_USERS > 1 diff --git a/test/image/spl_load_net.c b/test/image/spl_load_net.c index f570cef163f..9d067a7a592 100644 --- a/test/image/spl_load_net.c +++ b/test/image/spl_load_net.c @@ -248,5 +248,7 @@ static int spl_test_net(struct unit_test_state *uts, const char *test_name, return ret; } SPL_IMG_TEST(spl_test_net, LEGACY, DM_FLAGS); +SPL_IMG_TEST(spl_test_net, LEGACY_LZMA, DM_FLAGS); +SPL_IMG_TEST(spl_test_net, IMX8, DM_FLAGS); SPL_IMG_TEST(spl_test_net, FIT_INTERNAL, DM_FLAGS); SPL_IMG_TEST(spl_test_net, FIT_EXTERNAL, DM_FLAGS); -- 2.37.1
[PATCH v6 17/25] spl: Convert mmc to spl_load
This converts the mmc loader to spl_load. Legacy images are handled by spl_load (via spl_parse_image_header), so mmc_load_legacy can be omitted. To accurately determine whether mmc_load_image_raw_sector is used (which might not be the case if SYS_MMCSD_FS_BOOT is enabled), we introduce a helper config SYS_MMCSD_RAW_MODE. This ensures we can inline spl_load correctly when a board only boots from filesystems. We still need to check for SPL_MMC, since some boards enable configure raw mode even without MMC support. Signed-off-by: Sean Anderson --- Changes in v6: - Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads anything directly. - Explicitly initialize load_info members Changes in v5: - Rework to load header in spl_load common/spl/Kconfig | 8 common/spl/spl_mmc.c | 89 include/spl_load.h | 1 + test/image/spl_load_fs.c | 3 -- 4 files changed, 16 insertions(+), 85 deletions(-) diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 0bc57d5fedb..b93526904eb 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -481,6 +481,11 @@ config SPL_DISPLAY_PRINT banner ("U-Boot SPL ..."). This function should be provided by the board. +config SPL_SYS_MMCSD_RAW_MODE + bool + help + Support booting from an MMC without a filesystem. + config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR bool "MMC raw mode: by sector" default y if ARCH_SUNXI || ARCH_DAVINCI || ARCH_UNIPHIER || \ @@ -490,6 +495,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR OMAP44XX || OMAP54XX || AM33XX || AM43XX || \ TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED select SPL_LOAD_BLOCK if SPL_MMC + select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC help Use sector number for specifying U-Boot location on MMC/SD in raw mode. @@ -527,6 +533,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION bool "MMC Raw mode: by partition" select SPL_LOAD_BLOCK if SPL_MMC + select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC help Use a partition for loading U-Boot when using MMC/SD in raw mode. @@ -1114,6 +1121,7 @@ config SPL_FALCON_BOOT_MMCSD bool "Enable Falcon boot from MMC or SD media" depends on SPL_OS_BOOT && SPL_MMC select SPL_LOAD_BLOCK + select SPL_SYS_MMCSD_RAW_MODE help Select this if the Falcon mode OS image mode is on MMC or SD media. diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 91272c03d3f..3d032bb27ce 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -19,49 +19,6 @@ #include #include -static int mmc_load_legacy(struct spl_image_info *spl_image, - struct spl_boot_device *bootdev, - struct mmc *mmc, - ulong sector, struct legacy_img_hdr *header) -{ - u32 image_offset_sectors; - u32 image_size_sectors; - unsigned long count; - u32 image_offset; - int ret; - - ret = spl_parse_image_header(spl_image, bootdev, header); - if (ret) - return ret; - - /* convert offset to sectors - round down */ - image_offset_sectors = spl_image->offset / mmc->read_bl_len; - /* calculate remaining offset */ - image_offset = spl_image->offset % mmc->read_bl_len; - - /* convert size to sectors - round up */ - image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / -mmc->read_bl_len; - - /* Read the header too to avoid extra memcpy */ - count = blk_dread(mmc_get_blk_desc(mmc), - sector + image_offset_sectors, - image_size_sectors, - map_sysmem(spl_image->load_addr, -image_size_sectors * mmc->read_bl_len)); - debug("read %x sectors to %lx\n", image_size_sectors, - spl_image->load_addr); - if (count != image_size_sectors) - return -EIO; - - if (image_offset) - memmove((void *)(ulong)spl_image->load_addr, - (void *)(ulong)spl_image->load_addr + image_offset, - spl_image->size); - - return 0; -} - static ulong h_spl_load_read(struct spl_load_info *load, ulong off, ulong size, void *buf) { @@ -87,46 +44,14 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, struct spl_boot_device *bootdev, struct mmc *mmc, unsigned long sector) { - unsigned long count; - struct legacy_img_hdr *header; + int ret; struct blk_desc *bd =
[PATCH v6 16/25] spl: Convert fat to spl_load
This converts the fat loader to use spl_load. Some platforms are very tight on space, so we take care to only include the code we really need. Signed-off-by: Sean Anderson --- (no changes since v5) Changes in v5: - Rework to load header in spl_load Changes in v3: - Fix failing on success common/spl/spl_fat.c | 56 +--- include/spl_load.h | 1 + test/image/spl_load_fs.c | 3 +-- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index a0c34eba48f..569f2b32928 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image, const char *filename) { int err; - struct legacy_img_hdr *header; + loff_t size; + struct spl_load_info load; err = spl_register_fat_device(block_dev, partition); if (err) goto end; - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); - - err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr)); - if (err <= 0) - goto end; - - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) && - image_get_magic(header) == FDT_MAGIC) { - err = file_fat_read(filename, - map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0); - if (err <= 0) - goto end; - err = spl_parse_image_header(spl_image, bootdev, -map_sysmem(CONFIG_SYS_LOAD_ADDR, - err)); - if (err == -EAGAIN) - return err; - if (err == 0) - err = 1; - } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { - struct spl_load_info load; - - debug("Found FIT\n"); - load.read = spl_fit_read; - spl_set_bl_len(, ARCH_DMA_MINALIGN); - load.priv = (void *)filename; - - return spl_load_simple_fit(spl_image, , 0, header); - } else { - err = spl_parse_image_header(spl_image, bootdev, header); + /* +* Avoid pulling in this function for other image types since we are +* very short on space on some boards. +*/ + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) { + err = fat_size(filename, ); if (err) goto end; - - err = file_fat_read(filename, map_sysmem(spl_image->load_addr, -spl_image->size), 0); + } else { + size = 0; } + load.read = spl_fit_read; + spl_set_bl_len(, ARCH_DMA_MINALIGN); + load.priv = (void *)filename; + err = spl_load(spl_image, bootdev, , size, 0); + end: #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT - if (err <= 0) + if (err < 0) printf("%s: error reading image %s, err - %d\n", __func__, filename, err); #endif - return (err <= 0); + return err; } #if CONFIG_IS_ENABLED(OS_BOOT) diff --git a/include/spl_load.h b/include/spl_load.h index 65aa6bb4493..5e0460d956d 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image, */ #define SPL_LOAD_USERS \ IS_ENABLED(CONFIG_SPL_FS_EXT4) + \ + IS_ENABLED(CONFIG_SPL_FS_FAT) + \ 0 #if SPL_LOAD_USERS > 1 diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c index 01559e98c4f..333df2dfb53 100644 --- a/test/image/spl_load_fs.c +++ b/test/image/spl_load_fs.c @@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const char *test_name, if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false)) return CMD_RET_FAILURE; - if (type != IMX8 && type != LEGACY_LZMA && - spl_test_mmc_fs(uts, test_name, type, create_fat, false)) + if (spl_test_mmc_fs(uts, test_name, type, create_fat, false)) return CMD_RET_FAILURE; if (type == LEGACY_LZMA) -- 2.37.1
[PATCH v6 13/25] test: spl: Support testing LEGACY_LZMA filesystem images
These will soon be supported, so we need to be able to test it. Export the lzma data and generally use the same process in spl_test_mmc_fs as do_spl_test_load. If we end up needing this in third place in the future, it would probably be good to refactor things out. Signed-off-by: Sean Anderson --- Changes in v6: - New include/test/spl.h | 4 test/image/spl_load.c| 4 +++- test/image/spl_load_fs.c | 23 ++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/test/spl.h b/include/test/spl.h index c1f64658502..a2a5f33e328 100644 --- a/include/test/spl.h +++ b/include/test/spl.h @@ -81,6 +81,10 @@ size_t create_image(void *dst, enum spl_test_image type, int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1, struct spl_image_info *info2); +/* Some compressed data and it size */ +extern const char lzma_compressed[]; +extern const size_t lzma_compressed_size; + /** * typedef write_image_t - Callback for writing an image * @uts: Current unit test state diff --git a/test/image/spl_load.c b/test/image/spl_load.c index 35ceed67756..e1036eff28c 100644 --- a/test/image/spl_load.c +++ b/test/image/spl_load.c @@ -374,7 +374,7 @@ SPL_IMG_TEST(spl_test_image, FIT_EXTERNAL, 0); * LZMA is too complex to generate on the fly, so let's use some data I put in * the oven^H^H^H^H compressed earlier */ -static const char lzma_compressed[] = { +const char lzma_compressed[] = { 0x5d, 0x00, 0x00, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x02, 0x05, 0x55, 0x4e, 0x82, 0xbc, 0xc2, 0x42, 0xf6, 0x88, 0x6c, 0x99, 0xd6, 0x82, 0x48, 0xa6, 0x06, 0x67, 0xf8, 0x46, 0x7c, 0xe9, @@ -610,6 +610,8 @@ static const char lzma_compressed[] = { 0x1e, 0xff, 0xff, 0x80, 0x8e, 0x00, 0x00 }; +const size_t lzma_compressed_size = sizeof(lzma_compressed); + int do_spl_test_load(struct unit_test_state *uts, const char *test_name, enum spl_test_image type, struct spl_image_loader *loader, int (*write_image)(struct unit_test_state *, void *, size_t)) diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c index 297ab08a820..59d0244d44b 100644 --- a/test/image/spl_load_fs.c +++ b/test/image/spl_load_fs.c @@ -320,10 +320,11 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name, const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME; struct blk_desc *dev_desc; size_t fs_size, fs_data, img_size, img_data, - data_size = SPL_TEST_DATA_SIZE; + plain_size = SPL_TEST_DATA_SIZE; struct spl_image_info info_write = { .name = test_name, - .size = data_size, + .size = type == LEGACY_LZMA ? lzma_compressed_size : + plain_size, }, info_read = { }; struct disk_partition part = { .start = 1, @@ -335,7 +336,7 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name, .boot_device = loader->boot_device, }; void *fs; - char *data; + char *data, *plain; img_size = create_image(NULL, type, _write, _data); ut_assert(img_size); @@ -345,7 +346,15 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name, ut_assertnonnull(fs); data = fs + fs_data + img_data; - generate_data(data, data_size, test_name); + if (type == LEGACY_LZMA) { + plain = malloc(plain_size); + ut_assertnonnull(plain); + generate_data(plain, plain_size, "lzma"); + memcpy(data, lzma_compressed, lzma_compressed_size); + } else { + plain = data; + generate_data(plain, plain_size, test_name); + } ut_asserteq(img_size, create_image(fs + fs_data, type, _write, NULL)); ut_asserteq(fs_size, create_fs(fs, img_size, filename, NULL)); @@ -366,8 +375,12 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name, ut_assertok(loader->load_image(_read, )); if (check_image_info(uts, _write, _read)) return CMD_RET_FAILURE; - ut_asserteq_mem(data, phys_to_virt(info_write.load_addr), data_size); + if (type == LEGACY_LZMA) + ut_asserteq(plain_size, info_read.size); + ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size); + if (type == LEGACY_LZMA) + free(plain); free(fs); return 0; } -- 2.37.1
[PATCH v6 00/25] spl: Use common function for loading/parsing images
This series adds support for loading all image types (Legacy (with and without LZMA), FIT (with and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR, NET, FAT, EXT, NVMe, and semihosting load methods. It does this by introducing a helper function which handles the minutiae of invoking the proper parsing function, and reading the rest of the image. Hopefully, this will make it easier for load methods to support all image types that U-Boot supports, without having undocumented unsupported image types. I applied this to several loaders which were invoking spl_load_simple_fit and/or spl_parse_image_header, but I did not use it with others (e.g. DFU/RAM) which had complications in the mix. This series is organized roughly into two parts. Patches up to "spl: Add generic spl_load function" are all setup or size-reduction oriented. Later patches generally convert various load functions to spl_load. bloat-o-meter results (for CONFIG_SPL only) at [1]. Size growth has been the bigegst challenge to preparing this series. I have used every trick I can think of to reduce bloat. Some SAMA boards no longer fit, but I have a plan to fix them [2]. This is bar far the largest and most-difficult revision of this series to-date. There are probably still things which can reduce the size, but I have been working on this series for the better part of two months and I think it is a good idea to get some feedback. Because of the SAMA bloat, this series will not pass CI, so I expect to do a v7 before this is ready to apply. Feel free, however, to apply patches in the first half (especially the fixes). This version of the series is better-tested than ever before, thanks to some new unit tests. However, things like the i.MX ROMAPI are untested. NAND should also be tested more-widely, for reasons listed in the commit message. I encourage you try this series out on your favorite board. This series depends on [3]. (Almost passing) CI at [4]. [1] https://gist.github.com/Forty-Bot/5bfe88676dd3c2aec6ebc23abb08e06f This includes some changes to am335x_evm_spiboot and am65x_evm_r5_usbdfu which have since been undone. [2] https://lore.kernel.org/u-boot/20231105022742.632175-1-sean...@gmail.com/ [3] https://lore.kernel.org/u-boot/20231104203753.1579217-1-sean...@gmail.com/ [4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18447 Changes in v6: - Fix uninitialized return value when we can't get a blk_desc - Don't close fd before spl_load_simple_fit - Remove NULL assignments in spl_load_info - Remove dev from spl_load_info - Take advantage of bl_len's power-of-twoness - Refactor spl_load_info->read to use units of bytes - Remove filename from spl_load_info - Only support bl_len when we have to - Remove spl_nand_legacy_read - Split off LZMA decompression into its own function - Support testing LEGACY_LZMA filesystem images - Use pseudo-LTO for spl_load - Align reads to bl_len - Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads anything directly. - Convert nand to spl_load - Fix LZMA support - Fix load address - Fix invalid return from spl_blk_load_image - Fix soft reset after loading from SPI - Explicitly initialize load_info members to reduce text size - Rebase on u-boot/next - Add option to disable DMA alignment for FAT Changes in v5: - Make SHOW_ERRORS depend on LIBCOMMON - Load the header in spl_load as well - Don't bother trying to DMA-align the buffer, since we can't really fix it. - Convert NVMe to spl_load Changes in v4: - Fix format specifiers in debug prints - Reword/fix some of the doc comments for spl_load - Rebase on u-boot/master Changes in v3: - Fix using ffs instead of fls - Fix using not initializing bl_len when info->filename was NULL - Fix failing on success Changes in v2: - Use reverse-xmas-tree style for locals in spl_simple_read. This is not complete, since overhead depends on bl_mask. - Convert semihosting as well - Consolidate spi_load_image_os into spl_spi_load_image Sean Anderson (25): spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc arm: Disable SPL_FS_FAT when it isn't used spl: Make SHOW_ERRORS depend on LIBCOMMON spl: semihosting: Don't close fd before spl_load_simple_fit spl: Remove NULL assignments in spl_load_info spl: Remove dev from spl_load_info spl: Take advantage of bl_len's power-of-twoness spl: Refactor spl_load_info->read to use units of bytes spl: Remove filename from spl_load_info spl: Only support bl_len when we have to spl: nand: Remove spl_nand_legacy_read spl: legacy: Split off LZMA decompression into its own function test: spl: Support testing LEGACY_LZMA filesystem images spl: Add generic spl_load function spl: Convert ext to use spl_load spl: Convert fat to spl_load spl: Convert mmc to spl_load spl: Convert nand to spl_load spl: Convert net to spl_load spl: Convert nor to spl_load spl: Convert NVMe to spl_load spl: Convert semihosting to spl_load spl: Convert spi
[PATCH v6 14/25] spl: Add generic spl_load function
Implementers of SPL_LOAD_IMAGE_METHOD have to correctly determine what type of image is being loaded and then call the appropriate image load function correctly. This is tricky, because some image load functions expect the whole image to already be loaded (CONFIG_SPL_LOAD_FIT_FULL), some will load the image automatically using spl_load_info.read() (CONFIG_SPL_LOAD_FIT/CONFIG_SPL_LOAD_IMX_CONTAINER), and some just parse the header and expect the caller to do the actual loading afterwards (legacy/raw images). Load methods often only support a subset of the above methods, meaning that not all image types can be used with all load methods. Further, the code to invoke these functions is duplicated between different load functions. To address this problem, this commit introduces a "spl_load" function. It aims to handle image detection and correct invocation of each of the parse/load functions. Although this function generally results in a size reduction with several users, it tends to bloat boards with only a single user. This is generally because programmers open-coding the contents of this function can make optimizations based on the specific loader. For example, NOR flash is memory-mapped, so it never bothers calling load->read. The compiler can't really make these optimizations across translation units. LTO solves this, but it is only available on some arches. To address this, perform "pseudo-LTO" by inlining spl_load when there are one or fewer users. At the moment, there are no users, so define SPL_LOAD_USERS to be 0. Signed-off-by: Sean Anderson --- Changes in v6: - Use pseudo-LTO for spl_load - Align reads to bl_len Changes in v5: - Load the header in spl_load as well - Don't bother trying to DMA-align the buffer, since we can't really fix it. Changes in v4: - Fix format specifiers in debug prints - Reword/fix some of the doc comments for spl_load Changes in v3: - Fix using ffs instead of fls - Fix using not initializing bl_len when info->filename was NULL Changes in v2: - Use reverse-xmas-tree style for locals in spl_simple_read. This is not complete, since overhead depends on bl_mask. common/spl/spl.c | 10 include/spl_load.h | 135 + 2 files changed, 145 insertions(+) create mode 100644 include/spl_load.h diff --git a/common/spl/spl.c b/common/spl/spl.c index 7ce38ce46d4..3ce5bfeec8b 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -352,6 +353,15 @@ int spl_parse_image_header(struct spl_image_info *spl_image, return 0; } +#if SPL_LOAD_USERS > 1 +int spl_load(struct spl_image_info *spl_image, +const struct spl_boot_device *bootdev, struct spl_load_info *info, +size_t size, size_t offset) +{ + return _spl_load(spl_image, bootdev, info, size, offset); +} +#endif + __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) { typedef void __noreturn (*image_entry_noargs_t)(void); diff --git a/include/spl_load.h b/include/spl_load.h new file mode 100644 index 000..406f8b577b2 --- /dev/null +++ b/include/spl_load.h @@ -0,0 +1,135 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) Sean Anderson + */ +#ifndef_SPL_LOAD_H_ +#define_SPL_LOAD_H_ + +#include +#include +#include +#include + +static inline int _spl_load(struct spl_image_info *spl_image, + const struct spl_boot_device *bootdev, + struct spl_load_info *info, size_t size, + size_t offset) +{ + struct legacy_img_hdr *header = + spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + ulong base_offset, image_offset, overhead; + int read, ret; + + read = info->read(info, offset, ALIGN(sizeof(*header), + spl_get_bl_len(info)), header); + if (read < sizeof(*header)) + return -EIO; + + if (image_get_magic(header) == FDT_MAGIC) { + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) { + void *buf; + + /* +* In order to support verifying images in the FIT, we +* need to load the whole FIT into memory. Try and +* guess how much we need to load by using the total +* size. This will fail for FITs with external data, +* but there's not much we can do about that. +*/ + if (!size) + size = round_up(fdt_totalsize(header), 4); + buf = map_sysmem(CONFIG_SYS_LOAD_ADDR, size); + read = info->read(info, offset, + ALIGN(size, spl_get_bl_len(info)), +
[PATCH v6 12/25] spl: legacy: Split off LZMA decompression into its own function
To allow for easier reuse of this functionality, split it off into its own function. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_legacy.c | 73 ++--- include/spl.h | 13 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index 75d9d822337..a561939b4f0 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -82,6 +82,43 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image, return 0; } +int spl_load_legacy_lzma(struct spl_image_info *spl_image, +struct spl_load_info *load, ulong offset) +{ + SizeT lzma_len = LZMA_LEN; + void *src; + ulong dataptr, overhead, size; + int ret; + + /* dataptr points to compressed payload */ + dataptr = ALIGN_DOWN(sizeof(struct legacy_img_hdr), +spl_get_bl_len(load)); + overhead = sizeof(struct legacy_img_hdr) - dataptr; + size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load)); + dataptr += offset; + + debug("LZMA: Decompressing %08lx to %08lx\n", + dataptr, spl_image->load_addr); + src = malloc(size); + if (!src) { + printf("Unable to allocate %d bytes for LZMA\n", + spl_image->size); + return -ENOMEM; + } + + load->read(load, dataptr, size, src); + ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr, + spl_image->size), _len, + src + overhead, spl_image->size); + if (ret) { + printf("LZMA decompression error: %d\n", ret); + return ret; + } + + spl_image->size = lzma_len; + return 0; +} + /* * This function is added explicitly to avoid code size increase, when * no compression method is enabled. The compiler will optimize the @@ -101,8 +138,6 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, struct spl_load_info *load, ulong offset, struct legacy_img_hdr *hdr) { - __maybe_unused SizeT lzma_len; - __maybe_unused void *src; ulong dataptr; int ret; @@ -133,39 +168,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, map_sysmem(spl_image->load_addr, spl_image->size)); break; - case IH_COMP_LZMA: { - ulong overhead, size; + case IH_COMP_LZMA: + return spl_load_legacy_lzma(spl_image, load, offset); - lzma_len = LZMA_LEN; - - /* dataptr points to compressed payload */ - dataptr = ALIGN_DOWN(sizeof(*hdr), spl_get_bl_len(load)); - overhead = sizeof(*hdr) - dataptr; - size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load)); - dataptr += offset; - - debug("LZMA: Decompressing %08lx to %08lx\n", - dataptr, spl_image->load_addr); - src = malloc(size); - if (!src) { - printf("Unable to allocate %d bytes for LZMA\n", - spl_image->size); - return -ENOMEM; - } - - load->read(load, dataptr, size, src); - ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr, - spl_image->size), - _len, src + overhead, - spl_image->size); - if (ret) { - printf("LZMA decompression error: %d\n", ret); - return ret; - } - - spl_image->size = lzma_len; - break; - } default: debug("Compression method %s is not supported\n", genimg_get_comp_short_name(image_get_comp(hdr))); diff --git a/include/spl.h b/include/spl.h index 4c421664a9d..d8d2cf43eeb 100644 --- a/include/spl.h +++ b/include/spl.h @@ -405,6 +405,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, #define SPL_COPY_PAYLOAD_ONLY 1 #define SPL_FIT_FOUND 2 +/** + * spl_load_legacy_lzma() - Load an LZMA-compressed legacy image + * @spl_image: Image description (already set up) + * @load: Structure containing the information required to load data. + * @offset:Pointer to image + * + * Load/decompress an LZMA-compressed legacy image from the device. + * + * Return: 0 on success, or a negative error on failure + */ +int spl_load_legacy_lzma(struct spl_image_info *spl_image, +struct spl_load_info *load, ulong offset); + /** * spl_load_legacy_img() - Loads a legacy image from a device. * @spl_image: Image description
[PATCH v6 02/25] arm: Disable SPL_FS_FAT when it isn't used
Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be used (as there is no block device support enabled). Disable these configs. The list of boards was generated with the following command: $ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \ ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI LIBDISK was left enabled for the am* boards, since it seems to result in actual size reduction, indicating that partitions are being used for something. Signed-off-by: Sean Anderson --- (no changes since v1) configs/am335x_evm_spiboot_defconfig | 2 +- configs/am65x_evm_r5_usbdfu_defconfig | 1 - configs/xilinx_zynqmp_mini_qspi_defconfig | 3 +++ configs/zynq_cse_nand_defconfig | 3 +++ configs/zynq_cse_nor_defconfig| 3 +++ configs/zynq_cse_qspi_defconfig | 3 +++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/configs/am335x_evm_spiboot_defconfig b/configs/am335x_evm_spiboot_defconfig index b5b11fb62c8..fff5265e56a 100644 --- a/configs/am335x_evm_spiboot_defconfig +++ b/configs/am335x_evm_spiboot_defconfig @@ -13,6 +13,7 @@ CONFIG_CLOCK_SYNTHESIZER=y # CONFIG_OF_LIBFDT_OVERLAY is not set # CONFIG_SPL_MMC is not set CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set CONFIG_SPL_SPI_FLASH_SUPPORT=y CONFIG_SPL_SPI=y CONFIG_TIMESTAMP=y @@ -27,7 +28,6 @@ CONFIG_SPL_SYS_MALLOC=y CONFIG_SPL_SYS_MALLOC_SIZE=0x80 CONFIG_SPL_FIT_IMAGE_TINY=y # CONFIG_SPL_FS_EXT4 is not set -CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img" CONFIG_SPL_MTD=y # CONFIG_SPL_NAND_SUPPORT is not set CONFIG_SPL_DM_SPI_FLASH=y diff --git a/configs/am65x_evm_r5_usbdfu_defconfig b/configs/am65x_evm_r5_usbdfu_defconfig index f610b2dd94e..6b0bb120d10 100644 --- a/configs/am65x_evm_r5_usbdfu_defconfig +++ b/configs/am65x_evm_r5_usbdfu_defconfig @@ -21,7 +21,6 @@ CONFIG_SPL_DRIVERS_MISC=y CONFIG_SPL_STACK_R_ADDR=0x8200 CONFIG_SPL_SIZE_LIMIT=0x7ec00 CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x2000 -CONFIG_SPL_FS_FAT=y CONFIG_SPL_LIBDISK_SUPPORT=y # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set CONFIG_SPL_LOAD_FIT=y diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig b/configs/xilinx_zynqmp_mini_qspi_defconfig index a1adfb9e5d1..8b92e1c7358 100644 --- a/configs/xilinx_zynqmp_mini_qspi_defconfig +++ b/configs/xilinx_zynqmp_mini_qspi_defconfig @@ -11,6 +11,8 @@ CONFIG_ENV_SIZE=0x80 CONFIG_DEFAULT_DEVICE_TREE="zynqmp-mini-qspi" CONFIG_SPL_STACK=0xfffc CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set +# CONFIG_SPL_LIBDISK_SUPPORT is not set CONFIG_SYS_MEM_RSVD_FOR_MMU=y CONFIG_ZYNQMP_NO_DDR=y # CONFIG_PSCI_RESET is not set @@ -89,6 +91,7 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_ARM_DCC=y CONFIG_SPI=y CONFIG_ZYNQMP_GQSPI=y +CONFIG_FS_FAT=y # CONFIG_FAT_WRITE is not set CONFIG_PANIC_HANG=y # CONFIG_GZIP is not set diff --git a/configs/zynq_cse_nand_defconfig b/configs/zynq_cse_nand_defconfig index 19f653f40d0..01f5c090d5e 100644 --- a/configs/zynq_cse_nand_defconfig +++ b/configs/zynq_cse_nand_defconfig @@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nand" CONFIG_SPL_STACK_R_ADDR=0x20 CONFIG_SPL_STACK=0xfe00 CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set +# CONFIG_SPL_LIBDISK_SUPPORT is not set CONFIG_SYS_LOAD_ADDR=0x0 CONFIG_REMAKE_ELF=y CONFIG_SYS_CUSTOM_LDSCRIPT=y @@ -78,6 +80,7 @@ CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ZYNQ=y CONFIG_SYS_NAND_ONFI_DETECTION=y CONFIG_ARM_DCC=y +CONFIG_FS_FAT=y CONFIG_SYS_TIMER_COUNTS_DOWN=y # CONFIG_GZIP is not set # CONFIG_LMB is not set diff --git a/configs/zynq_cse_nor_defconfig b/configs/zynq_cse_nor_defconfig index 64df1f0b83e..7b32ffd3501 100644 --- a/configs/zynq_cse_nor_defconfig +++ b/configs/zynq_cse_nor_defconfig @@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nor" CONFIG_SPL_STACK_R_ADDR=0x20 CONFIG_SPL_STACK=0xfe00 CONFIG_SPL=y +# CONFIG_SPL_FS_FAT is not set +# CONFIG_SPL_LIBDISK_SUPPORT is not set CONFIG_SYS_LOAD_ADDR=0x0 CONFIG_REMAKE_ELF=y CONFIG_SYS_CUSTOM_LDSCRIPT=y @@ -81,6 +83,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_SYS_FLASH_QUIET_TEST=y CONFIG_ARM_DCC=y +CONFIG_FS_FAT=y CONFIG_SYS_TIMER_COUNTS_DOWN=y # CONFIG_GZIP is not set # CONFIG_LMB is not set diff --git a/configs/zynq_cse_qspi_defconfig b/configs/zynq_cse_qspi_defconfig index 9368fb4ffbc..b4561c50e9a 100644 --- a/configs/zynq_cse_qspi_defconfig +++ b/configs/zynq_cse_qspi_defconfig @@ -16,6 +16,8 @@ CONFIG_SPL_STACK=0xfe00 CONFIG_SPL=y CONFIG_DEBUG_UART_BASE=0x0 CONFIG_DEBUG_UART_CLOCK=0 +# CONFIG_SPL_FS_FAT is not set +# CONFIG_SPL_LIBDISK_SUPPORT is not set # CONFIG_ZYNQ_DDRC_INIT is not set # CONFIG_CMD_ZYNQ is not set CONFIG_SYS_LOAD_ADDR=0x0 @@ -90,6 +92,7 @@ CONFIG_SPI_FLASH_WINBOND=y # CONFIG_SPI_FLASH_USE_4K_SECTORS is not set CONFIG_ARM_DCC=y CONFIG_ZYNQ_QSPI=y +CONFIG_FS_FAT=y CONFIG_SYS_TIMER_COUNTS_DOWN=y # CONFIG_GZIP is not set # CONFIG_LMB is not set -- 2.37.1
[PATCH v6 06/25] spl: Remove dev from spl_load_info
dev and priv server the same purpose, and are never set at the same time. Remove dev and convert all users to priv. While we're at it, reorder bl_len to be last for better alignment. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_mmc.c | 6 +++--- common/spl/spl_spi.c | 6 +++--- drivers/usb/gadget/f_sdp.c | 6 +++--- include/spl.h | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 6d9137c32e0..3d7551a7dae 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image, static ulong h_spl_load_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { - struct mmc *mmc = load->dev; + struct mmc *mmc = load->priv; return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); } @@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT\n"); - load.dev = mmc; + load.priv = mmc; load.filename = NULL; load.bl_len = mmc->read_bl_len; load.read = h_spl_load_read; @@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, valid_container_hdr((void *)header)) { struct spl_load_info load; - load.dev = mmc; + load.priv = mmc; load.filename = NULL; load.bl_len = mmc->read_bl_len; load.read = h_spl_load_read; diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index d83d70f2f33..af7a28e7c25 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image, static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { - struct spi_flash *flash = load->dev; + struct spi_flash *flash = load->priv; ulong ret; ret = spi_flash_read(flash, sector, count, buf); @@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT\n"); - load.dev = flash; + load.priv = flash; load.filename = NULL; load.bl_len = 1; load.read = spl_spi_fit_read; @@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, valid_container_hdr((void *)header)) { struct spl_load_info load; - load.dev = flash; + load.priv = flash; load.filename = NULL; load.bl_len = 1; load.read = spl_spi_fit_read; diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index ee9384fb37e..1b16b7eb452 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -744,7 +744,7 @@ static ulong sdp_load_read(struct spl_load_info *load, ulong sector, { debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); - memcpy(buf, (void *)(load->dev + sector), count); + memcpy(buf, (void *)(load->priv + sector), count); return count; } @@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT\n"); - load.dev = header; + load.priv = header; load.bl_len = 1; load.read = sdp_load_read; spl_load_simple_fit(spl_image, , 0, @@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image, valid_container_hdr((void *)header)) { struct spl_load_info load; - load.dev = header; + load.priv = header; load.bl_len = 1; load.read = sdp_load_read; spl_load_imx_container(spl_image, , 0); diff --git a/include/spl.h b/include/spl.h index 8ff20adc28e..951e136b9ea 100644 --- a/include/spl.h +++ b/include/spl.h @@ -285,16 +285,13 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info) /** * Information required to load data from a device * - * @dev: Pointer to the device, e.g. struct mmc * * @priv: Private data for the device * @bl_len: Block length for reading in bytes * @filename: Name of the fit
[PATCH v6 07/25] spl: Take advantage of bl_len's power-of-twoness
bl_len must be a power of two, so we can use ALIGN instead of roundup and similar tricks to avoid divisions. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_fit.c | 2 +- common/spl/spl_imx_container.c | 8 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 70d8d5942d9..6084ead0919 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -194,7 +194,7 @@ static int get_aligned_image_overhead(struct spl_load_info *info, int offset) if (info->filename) return offset & (ARCH_DMA_MINALIGN - 1); - return offset % info->bl_len; + return offset & (info->bl_len - 1); } static int get_aligned_image_size(struct spl_load_info *info, int data_size, diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c index 127802f5cb7..1cc51782766 100644 --- a/common/spl/spl_imx_container.c +++ b/common/spl/spl_imx_container.c @@ -33,13 +33,13 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image, images = (struct boot_img_t *)((u8 *)container + sizeof(struct container_hdr)); - if (images[image_index].offset % info->bl_len) { + if (!IS_ALIGNED(images[image_index].offset, info->bl_len)) { printf("%s: image%d offset not aligned to %u\n", __func__, image_index, info->bl_len); return NULL; } - sectors = roundup(images[image_index].size, info->bl_len) / + sectors = ALIGN(images[image_index].size, info->bl_len) / info->bl_len; sector = images[image_index].offset / info->bl_len + container_sector; @@ -69,7 +69,7 @@ static int read_auth_container(struct spl_image_info *spl_image, u32 sectors; int i, size, ret = 0; - size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len); + size = ALIGN(CONTAINER_HDR_ALIGNMENT, info->bl_len); sectors = size / info->bl_len; /* @@ -103,7 +103,7 @@ static int read_auth_container(struct spl_image_info *spl_image, debug("Container length %u\n", length); if (length > CONTAINER_HDR_ALIGNMENT) { - size = roundup(length, info->bl_len); + size = ALIGN(length, info->bl_len); sectors = size / info->bl_len; free(container); -- 2.37.1
[PATCH v6 10/25] spl: Only support bl_len when we have to
Aligning addresses and sizes causes overhead which is unnecessary when we are not loading from block devices. Remove bl_len when it is not needed. For example, on iot2050 we save 144 bytes with this patch (once the rest of this series is applied): add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-144 (-144) Function old new delta spl_load_simple_fit 920 904 -16 load_simple_fit 496 444 -52 spl_spi_load_image 384 308 -76 Total: Before=87431, After=87287, chg -0.16% We use panic() instead of BUILD_BUG_ON in spl_set_bl_len because we still need to be able to compile it for things like mmc_load_image_raw_sector, even if that function will not be used. Signed-off-by: Sean Anderson --- Changes in v6: - New arch/arm/mach-imx/spl_imx_romapi.c | 8 arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 +- common/spl/Kconfig | 14 +- common/spl/spl_blk_fs.c | 2 +- common/spl/spl_fat.c| 2 +- common/spl/spl_fit.c| 6 +++--- common/spl/spl_imx_container.c | 10 +- common/spl/spl_legacy.c | 4 ++-- common/spl/spl_mmc.c| 4 ++-- common/spl/spl_nand.c | 6 +++--- common/spl/spl_net.c| 2 +- common/spl/spl_nor.c| 8 common/spl/spl_ram.c| 2 +- common/spl/spl_semihosting.c| 2 +- common/spl/spl_spi.c| 4 ++-- common/spl/spl_ymodem.c | 2 +- drivers/usb/gadget/f_sdp.c | 4 ++-- include/spl.h | 25 + test/image/Kconfig | 1 + test/image/spl_load.c | 9 - test/image/spl_load_os.c| 2 +- 21 files changed, 78 insertions(+), 41 deletions(-) diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c index d7f6cb4b5ba..9f0968cdf71 100644 --- a/arch/arm/mach-imx/spl_imx_romapi.c +++ b/arch/arm/mach-imx/spl_imx_romapi.c @@ -101,7 +101,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, struct spl_load_info load; memset(, 0, sizeof(load)); - load.bl_len = pagesize; + spl_set_bl_len(, pagesize); load.read = spl_romapi_read_seekable; return spl_load_simple_fit(spl_image, , offset, header); } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && @@ -109,7 +109,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, struct spl_load_info load; memset(, 0, sizeof(load)); - load.bl_len = pagesize; + spl_set_bl_len(, pagesize); load.read = spl_romapi_read_seekable; ret = spl_load_imx_container(spl_image, , offset); @@ -334,7 +334,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, ss.pagesize = pagesize; memset(, 0, sizeof(load)); - load.bl_len = 1; + spl_set_bl_len(, 1); load.read = spl_romapi_read_stream; load.priv = @@ -358,7 +358,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, printf("ROM download failure %d\n", imagesize); memset(, 0, sizeof(load)); - load.bl_len = 1; + spl_set_bl_len(, 1); load.read = spl_ram_load_read; if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c index 5e7fba0c8e4..267cb0b1aba 100644 --- a/arch/arm/mach-sunxi/spl_spi_sunxi.c +++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c @@ -354,7 +354,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT image\n"); - load.bl_len = 1; + spl_set_bl_len(, 1); load.read = spi_load_read; ret = spl_load_simple_fit(spl_image, , load_offset, header); diff --git a/common/spl/Kconfig b/common/spl/Kconfig index e929f1bbae1..0bc57d5fedb 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -280,8 +280,15 @@ config SPL_BOARD_INIT spl_board_init() from board_init_r(). This function should be provided by the board. +config SPL_LOAD_BLOCK + bool + help + Support loading images from block devices. This adds a bl_len member + to struct spl_load_info. + config SPL_BOOTROM_SUPPORT bool "Support returning to the BOOTROM" + select SPL_LOAD_BLOCK if MACH_IMX help Some platforms (e.g. the Rockchip RK3368) provide support in their ROM for loading the next boot-stage
[PATCH v6 09/25] spl: Remove filename from spl_load_info
For filesystems, filename serves the same purpose as priv. However, spl_load_fit_image also uses it to determine whether to use a DMA-aligned buffer. This is beneficial for FAT, which uses a bounce-buffer if the destination is not DMA-aligned. Remove this logic, and instead achieve it by setting bl_len to ARCH_DMA_MINALIGN. With this done, we can remove filename entirely. One wrinkle bears mentioning: because filesystems are not block-based, we may read less than the size passed to spl_load_info.read. This can happen if the file size is not DMA-aligned. This is fine as long as we read the amount we originally wanted to. Modify the conditions for callers of spl_load_info.read to check against the original, unaligned size to avoid failing spuriously. Signed-off-by: Sean Anderson --- Changes in v6: - New arch/arm/mach-sunxi/spl_spi_sunxi.c | 1 - common/spl/spl_blk_fs.c | 10 ++ common/spl/spl_fat.c| 6 +++--- common/spl/spl_fit.c| 23 +-- common/spl/spl_imx_container.c | 8 +--- common/spl/spl_mmc.c| 2 -- common/spl/spl_nand.c | 3 --- common/spl/spl_semihosting.c| 1 - common/spl/spl_spi.c| 2 -- common/spl/spl_ymodem.c | 1 - include/spl.h | 2 -- test/image/spl_load_os.c| 1 - 12 files changed, 15 insertions(+), 45 deletions(-) diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c index 896aba69c32..5e7fba0c8e4 100644 --- a/arch/arm/mach-sunxi/spl_spi_sunxi.c +++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c @@ -354,7 +354,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT image\n"); - load.filename = NULL; load.bl_len = 1; load.read = spi_load_read; ret = spl_load_simple_fit(spl_image, , diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c index 144c8a65b5d..4975ce4d6ec 100644 --- a/common/spl/spl_blk_fs.c +++ b/common/spl/spl_blk_fs.c @@ -9,10 +9,12 @@ #include #include #include +#include #include struct blk_dev { const char *ifname; + const char *filename; char dev_part_str[8]; }; @@ -30,11 +32,11 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, return ret; } - ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size, + ret = fs_read(dev->filename, virt_to_phys(buf), file_offset, size, ); if (ret < 0) { printf("spl: error reading image %s. Err - %d\n", - load->filename, ret); + dev->filename, ret); return ret; } @@ -85,9 +87,9 @@ int spl_blk_load_image(struct spl_image_info *spl_image, debug("Found FIT\n"); load.read = spl_fit_read; - load.bl_len = 1; - load.filename = (void *)filename; + load.bl_len = ARCH_DMA_MINALIGN; load.priv = + dev.filename = filename; return spl_load_simple_fit(spl_image, , 0, header); } diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 6172e7bcd48..8a2c4e3af49 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -51,7 +51,7 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, { loff_t actread; int ret; - char *filename = (char *)load->filename; + char *filename = load->priv; ret = fat_read_file(filename, buf, file_offset, size, ); if (ret) @@ -97,8 +97,8 @@ int spl_load_image_fat(struct spl_image_info *spl_image, debug("Found FIT\n"); load.read = spl_fit_read; - load.bl_len = 1; - load.filename = (void *)filename; + load.bl_len = ARCH_DMA_MINALIGN; + load.priv = (void *)filename; return spl_load_simple_fit(spl_image, , 0, header); } else { diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index ce7ef0efd0d..0df4e6d1484 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -172,28 +171,11 @@ static int spl_fit_get_image_node(const struct spl_fit_info *ctx, static int get_aligned_image_offset(struct spl_load_info *info, int offset) { - /* -* If it is a FS read, get the first address before offset which is -* aligned to ARCH_DMA_MINALIGN. If it is raw read return the -* block number to which offset belongs. -*/ - if (info->filename) - return offset & ~(ARCH_DMA_MINALIGN - 1); - return ALIGN_DOWN(offset, info->bl_len); } static int
[PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes
Simplify things a bit for callers of spl_load_info->read by refactoring it to use units of bytes instead of bl_len. This generally simplifies the logic, as MMC is the only loader which actually works in sectors. It will also allow further refactoring to remove the special-case handling of filename. spl_load_legacy_img already works in units of bytes (oops) so it doesn't need to be changed. Signed-off-by: Sean Anderson --- Changes in v6: - New arch/arm/mach-imx/spl_imx_romapi.c | 16 +++--- common/spl/spl_fit.c | 51 +++--- common/spl/spl_imx_container.c | 45 +++--- common/spl/spl_mmc.c | 24 -- common/spl/spl_nand.c | 8 ++--- include/spl.h | 16 ++ test/image/spl_load_os.c | 13 7 files changed, 80 insertions(+), 93 deletions(-) diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c index 93d48e56aca..d7f6cb4b5ba 100644 --- a/arch/arm/mach-imx/spl_imx_romapi.c +++ b/arch/arm/mach-imx/spl_imx_romapi.c @@ -53,16 +53,10 @@ static int is_boot_from_stream_device(u32 boot) } static ulong spl_romapi_read_seekable(struct spl_load_info *load, - ulong sector, ulong count, + ulong offset, ulong byte, void *buf) { - u32 pagesize = *(u32 *)load->priv; - ulong byte = count * pagesize; - u32 offset; - - offset = sector * pagesize; - - return spl_romapi_raw_seekable_read(offset, byte, buf) / pagesize; + return spl_romapi_raw_seekable_read(offset, byte, buf); } static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, @@ -109,8 +103,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, memset(, 0, sizeof(load)); load.bl_len = pagesize; load.read = spl_romapi_read_seekable; - load.priv = - return spl_load_simple_fit(spl_image, , offset / pagesize, header); + return spl_load_simple_fit(spl_image, , offset, header); } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && valid_container_hdr((void *)header)) { struct spl_load_info load; @@ -118,9 +111,8 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, memset(, 0, sizeof(load)); load.bl_len = pagesize; load.read = spl_romapi_read_seekable; - load.priv = - ret = spl_load_imx_container(spl_image, , offset / pagesize); + ret = spl_load_imx_container(spl_image, , offset); } else { /* TODO */ puts("Can't support legacy image\n"); diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 6084ead0919..ce7ef0efd0d 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -180,7 +180,7 @@ static int get_aligned_image_offset(struct spl_load_info *info, int offset) if (info->filename) return offset & ~(ARCH_DMA_MINALIGN - 1); - return offset / info->bl_len; + return ALIGN_DOWN(offset, info->bl_len); } static int get_aligned_image_overhead(struct spl_load_info *info, int offset) @@ -205,7 +205,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, if (info->filename) return data_size; - return (data_size + info->bl_len - 1) / info->bl_len; + return ALIGN(data_size, info->bl_len); } /** @@ -222,7 +222,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, * * Return: 0 on success or a negative error number. */ -static int load_simple_fit(struct spl_load_info *info, ulong sector, +static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, const struct spl_fit_info *ctx, int node, struct spl_image_info *image_info) { @@ -234,7 +234,6 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector, void *load_ptr; void *src; ulong overhead; - int nr_sectors; uint8_t image_comp = -1, type = -1; const void *data; const void *fit = ctx->fit; @@ -291,11 +290,12 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector, length = len; overhead = get_aligned_image_overhead(info, offset); - nr_sectors = get_aligned_image_size(info, length, offset); + size = get_aligned_image_size(info, length, offset); if (info->read(info, - sector + get_aligned_image_offset(info, offset), - nr_sectors, src_ptr) != nr_sectors) + fit_offset + +
[PATCH v6 04/25] spl: semihosting: Don't close fd before spl_load_simple_fit
On real hardware, semihosting calls tends to have a large constant overhead (on the order of tens of milliseconds). Reduce the number of calls by one by reusing the existing fd in smh_fit_read, and closing it at the end of spl_smh_load_image. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_semihosting.c | 20 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c index f7dd289286d..8f11c29913f 100644 --- a/common/spl/spl_semihosting.c +++ b/common/spl/spl_semihosting.c @@ -24,18 +24,14 @@ static int smh_read_full(long fd, void *memp, size_t len) static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset, ulong size, void *buf) { - long fd; + long fd = *(long *)load->priv; ulong ret; - fd = smh_open(load->filename, MODE_READ | MODE_BINARY); - if (fd < 0) { - log_debug("could not open %s: %ld\n", load->filename, fd); + if (smh_seek(fd, file_offset)) return 0; - } + ret = smh_read(fd, buf, size); - smh_close(fd); - - return ret; + return ret < 0 ? 0 : ret; } static int spl_smh_load_image(struct spl_image_info *spl_image, @@ -73,11 +69,11 @@ static int spl_smh_load_image(struct spl_image_info *spl_image, debug("Found FIT\n"); load.read = smh_fit_read; load.bl_len = 1; - load.filename = filename; - load.priv = NULL; - smh_close(fd); + load.filename = NULL; + load.priv = - return spl_load_simple_fit(spl_image, , 0, header); + ret = spl_load_simple_fit(spl_image, , 0, header); + goto out; } ret = spl_parse_image_header(spl_image, bootdev, header); -- 2.37.1
[PATCH v6 11/25] spl: nand: Remove spl_nand_legacy_read
Now that spl_nand_fit_read works in units of bytes, it can be combined with spl_nand_legacy_read. Rename the resulting function spl_nand_read, since it is no longer FIT-specific. Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_nand.c | 33 + 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 281211b7f24..91fa7674f17 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -42,29 +42,22 @@ static int spl_nand_load_image(struct spl_image_info *spl_image, } #else -static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs, - ulong size, void *dst) +__weak u32 nand_spl_adjust_offset(u32 sector, u32 offs) +{ + return offs; +} + +static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size, + void *dst) { int err; ulong sector; - sector = *(int *)load->priv; - offs = sector + nand_spl_adjust_offset(sector, offs - sector); - err = nand_spl_load_image(offs, size, dst); - if (err) - return 0; - - return size; -} - -static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs, - ulong size, void *dst) -{ - int err; - debug("%s: offs %lx, size %lx, dst %p\n", __func__, offs, size, dst); + sector = *(int *)load->priv; + offs = sector + nand_spl_adjust_offset(sector, offs - sector); err = nand_spl_load_image(offs, size, dst); if (err) return 0; @@ -91,7 +84,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, debug("Found FIT\n"); load.priv = spl_set_bl_len(, bl_len); - load.read = spl_nand_fit_read; + load.read = spl_nand_read; return spl_load_simple_fit(spl_image, , offset, header); } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && valid_container_hdr((void *)header)) { @@ -99,16 +92,16 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, load.priv = spl_set_bl_len(, bl_len); - load.read = spl_nand_fit_read; + load.read = spl_nand_read; return spl_load_imx_container(spl_image, , offset); } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) && image_get_magic(header) == IH_MAGIC) { struct spl_load_info load; debug("Found legacy image\n"); + load.priv = spl_set_bl_len(, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1); - load.read = spl_nand_legacy_read; - + load.read = spl_nand_read; return spl_load_legacy_img(spl_image, bootdev, , offset, header); } else { err = spl_parse_image_header(spl_image, bootdev, header); -- 2.37.1
[PATCH v6 05/25] spl: Remove NULL assignments in spl_load_info
Remove NULL assignments to fields in spl_load_info when .load doesn't reference these fields. This can result in more efficient code. filename must stay even if it is unused, since load_simple_fit uses it. Signed-off-by: Sean Anderson --- Changes in v6: - New arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 -- common/spl/spl_fat.c| 1 - common/spl/spl_mmc.c| 2 -- common/spl/spl_nand.c | 4 common/spl/spl_spi.c| 2 -- common/spl/spl_ymodem.c | 1 - 6 files changed, 12 deletions(-) diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c b/arch/arm/mach-sunxi/spl_spi_sunxi.c index c2410dd7bb1..896aba69c32 100644 --- a/arch/arm/mach-sunxi/spl_spi_sunxi.c +++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c @@ -354,8 +354,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT image\n"); - load.dev = NULL; - load.priv = NULL; load.filename = NULL; load.bl_len = 1; load.read = spi_load_read; diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 014074f85be..6172e7bcd48 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -99,7 +99,6 @@ int spl_load_image_fat(struct spl_image_info *spl_image, load.read = spl_fit_read; load.bl_len = 1; load.filename = (void *)filename; - load.priv = NULL; return spl_load_simple_fit(spl_image, , 0, header); } else { diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 82689da1401..6d9137c32e0 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -106,7 +106,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, debug("Found FIT\n"); load.dev = mmc; - load.priv = NULL; load.filename = NULL; load.bl_len = mmc->read_bl_len; load.read = h_spl_load_read; @@ -116,7 +115,6 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image, struct spl_load_info load; load.dev = mmc; - load.priv = NULL; load.filename = NULL; load.bl_len = mmc->read_bl_len; load.read = h_spl_load_read; diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index b8cd6403ba4..9a5a5ffa04a 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -91,7 +91,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found FIT\n"); - load.dev = NULL; load.priv = load.filename = NULL; load.bl_len = bl_len; @@ -101,7 +100,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, valid_container_hdr((void *)header)) { struct spl_load_info load; - load.dev = NULL; load.priv = load.filename = NULL; load.bl_len = bl_len; @@ -112,8 +110,6 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, struct spl_load_info load; debug("Found legacy image\n"); - load.dev = NULL; - load.priv = NULL; load.filename = NULL; load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1; load.read = spl_nand_legacy_read; diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index 3ac4b1b5091..d83d70f2f33 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -152,7 +152,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, debug("Found FIT\n"); load.dev = flash; - load.priv = NULL; load.filename = NULL; load.bl_len = 1; load.read = spl_spi_fit_read; @@ -164,7 +163,6 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_load_info load; load.dev = flash; - load.priv = NULL; load.filename = NULL; load.bl_len = 1; load.read = spl_spi_fit_read; diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 038b4438457..8616cb3e915 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -134,7 +134,6 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image, struct ymodem_fit_info info; debug("Found FIT\n"); - load.dev = NULL; load.priv = (void *) load.filename = NULL; load.bl_len = 1; -- 2.37.1
[PATCH v6 03/25] spl: Make SHOW_ERRORS depend on LIBCOMMON
The purpose of SHOW_ERRORS is to print extra information. Make it depend on LIBCOMMON to avoid having to check for two configs. Signed-off-by: Sean Anderson Reviewed-by: Tom Rini --- (no changes since v5) Changes in v5: - New common/spl/Kconfig | 1 + common/spl/spl.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 00332cf243a..e929f1bbae1 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -183,6 +183,7 @@ config SPL_SYS_REPORT_STACK_F_USAGE config SPL_SHOW_ERRORS bool "Show more information when something goes wrong" + depends on SPL_LIBCOMMON_SUPPORT help This enabled more verbose error messages and checking when something goes wrong in SPL. For example, it shows the error code when U-Boot diff --git a/common/spl/spl.c b/common/spl/spl.c index 732d90d39e6..7ce38ce46d4 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -718,8 +718,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) ret = boot_from_devices(_image, spl_boot_list, ARRAY_SIZE(spl_boot_list)); if (ret) { - if (CONFIG_IS_ENABLED(SHOW_ERRORS) && - CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)) + if (CONFIG_IS_ENABLED(SHOW_ERRORS)) printf(SPL_TPL_PROMPT "failed to boot from all boot devices (err=%d)\n", ret); else -- 2.37.1
[PATCH v6 01/25] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc
Initialize ret to avoid returning garbage if blk_get_devnum_by_uclass_id fails. Fixes: 8ce6a2e1757 ("spl: blk: Support loading images from fs") Signed-off-by: Sean Anderson --- Changes in v6: - New common/spl/spl_blk_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c index 63825d620d1..144c8a65b5d 100644 --- a/common/spl/spl_blk_fs.c +++ b/common/spl/spl_blk_fs.c @@ -50,7 +50,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image, struct blk_desc *blk_desc; loff_t actlen, filesize; struct blk_dev dev; - int ret; + int ret = -ENODEV; blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum); if (!blk_desc) { -- 2.37.1
[PATCH] sunxi: h616: (really) lower SPL stack address to avoid BROM data
When using the USB OTG FEL mode on the Allwinner H616, the BootROM stores some data at the end of SRAM C. This is also the location where we place the initial SPL stack, so it will overwrite this data. We still need the BROM code after running the SPL, so should leave that area alone. Interestingly this does not seem to have an adverse effect, I guess on the "way out" (when we return to FEL after the SPL has run), this data is not needed by the BROM, for just the trailing end of the USB operation. However this is still wrong, and we should not clobber BROM data. Lower the SPL stack address to be situated right below the swap buffers we use in sunxi-fel: that should be out of the way of everyone else. This obsoletes a previous commit (eb53e7743c8f) with the same name: that one was changing the address in an *unused* macro in sunxi_common.h, so the previous patch didn't have any effect at all. Fixes: eb53e7743c8f ("sunxi: h616: lower SPL stack address to avoid BROM data") Signed-off-by: Andre Przywara --- Hi, sorry for the blunder with that previous patch! This issue came up when cleaning up some SPL code: LOW_LEVEL_SRAM_STACK, as changed in the previous patch, is not used anywhere. I have a patch to remove that whole section from sunxi-common.h, and will send that as part of some bigger SPL clean-up series later. Cheers, Andre common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 25cd18afda7..c521b02f4a3 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -370,7 +370,7 @@ config SPL_STACK default 0x93ffb8 if ARCH_MX6 && MX6_OCRAM_256KB default 0x91ffb8 if ARCH_MX6 && !MX6_OCRAM_256KB default 0x118000 if MACH_SUN50I_H6 - default 0x58000 if MACH_SUN50I_H616 + default 0x52a00 if MACH_SUN50I_H616 default 0x4 if MACH_SUN8I_R528 default 0x54000 if MACH_SUN50I || MACH_SUN50I_H5 default 0x18000 if MACH_SUN9I -- 2.35.8
[PATCH 2/2] phy: phy-mtk-tphy: add properties for phy tuning
Add properties to improve eye diagram which sometimes need adjust some parameters of u2phy; Add a property to tune disconnect threshold; Signed-off-by: Chunfeng Yun --- drivers/phy/phy-mtk-tphy.c | 58 +- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c index 1883f9f83e..ea9edf212c 100644 --- a/drivers/phy/phy-mtk-tphy.c +++ b/drivers/phy/phy-mtk-tphy.c @@ -47,6 +47,11 @@ #define PA0_USB20_PLL_PREDIV GENMASK(7, 6) #define PA0_RG_USB20_INTR_EN BIT(5) +#define U3P_USBPHYACR1 0x004 +#define PA1_RG_INTR_CALGENMASK(23, 19) +#define PA1_RG_VRT_SEL GENMASK(14, 12) +#define PA1_RG_TERM_SELGENMASK(10, 8) + #define U3P_USBPHYACR2 0x008 #define PA2_RG_U2PLL_BWGENMASK(21, 19) @@ -56,8 +61,10 @@ #define PA5_RG_U2_HS_100U_U3_ENBIT(11) #define U3P_USBPHYACR6 0x018 +#define PA6_RG_U2_PRE_EMP GENMASK(31, 30) #define PA6_RG_U2_BC11_SW_EN BIT(23) #define PA6_RG_U2_OTG_VBUSCMP_EN BIT(20) +#define PA6_RG_U2_DISCTH GENMASK(7, 4) #define PA6_RG_U2_SQTH GENMASK(3, 0) #define U3P_U2PHYACR4 0x020 @@ -240,7 +247,7 @@ struct u3phy_banks { struct mtk_phy_instance { void __iomem *port_base; - const struct device_node *np; + struct device_node *np; union { struct u2phy_banks u2_banks; struct u3phy_banks u3_banks; @@ -250,6 +257,11 @@ struct mtk_phy_instance { struct clk da_ref_clk; /* reference clock of analog phy */ u32 index; u32 type; + + u32 eye_vrt; + u32 eye_term; + u32 discth; + u32 pre_emphasis; }; struct mtk_tphy { @@ -564,6 +576,47 @@ static void phy_v2_banks_init(struct mtk_tphy *tphy, } } +static void phy_parse_property(struct mtk_tphy *tphy, + struct mtk_phy_instance *instance) +{ + ofnode node = np_to_ofnode(instance->np); + + if (instance->type != PHY_TYPE_USB2) + return; + + ofnode_read_u32(node, "mediatek,eye-vrt", >eye_vrt); + ofnode_read_u32(node, "mediatek,eye-term", >eye_term); + ofnode_read_u32(node, "mediatek,discth", >discth); + ofnode_read_u32(node, "mediatek,pre-emphasis", >pre_emphasis); + + dev_dbg(tphy->dev, "vrt:%d, term:%d, disc:%d, emp:%d\n", + instance->eye_vrt, instance->eye_term, + instance->discth, instance->pre_emphasis); +} + +static void u2_phy_props_set(struct mtk_tphy *tphy, +struct mtk_phy_instance *instance) +{ + struct u2phy_banks *u2_banks = >u2_banks; + void __iomem *com = u2_banks->com; + + if (instance->eye_vrt) + clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_VRT_SEL, + FIELD_PREP(PA1_RG_VRT_SEL, instance->eye_vrt)); + + if (instance->eye_term) + clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_TERM_SEL, + FIELD_PREP(PA1_RG_TERM_SEL, instance->eye_term)); + + if (instance->discth) + clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_DISCTH, + FIELD_PREP(PA6_RG_U2_DISCTH, instance->discth)); + + if (instance->pre_emphasis) + clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_PRE_EMP, + FIELD_PREP(PA6_RG_U2_PRE_EMP, instance->pre_emphasis)); +} + static int mtk_phy_init(struct phy *phy) { struct mtk_tphy *tphy = dev_get_priv(phy->dev); @@ -586,6 +639,7 @@ static int mtk_phy_init(struct phy *phy) switch (instance->type) { case PHY_TYPE_USB2: u2_phy_instance_init(tphy, instance); + u2_phy_props_set(tphy, instance); break; case PHY_TYPE_USB3: u3_phy_instance_init(tphy, instance); @@ -692,6 +746,8 @@ static int mtk_phy_xlate(struct phy *phy, return -EINVAL; } + phy_parse_property(tphy, instance); + return 0; } -- 2.25.1
[PATCH 1/2] dt-bindings: phy-mtk-tphy: add properties for phy tuning
Add properties to improve eye diagram which sometimes need adjust some parameters of u2phy; Add a property to tune disconnect threshold; Signed-off-by: Chunfeng Yun --- doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 9 + 1 file changed, 9 insertions(+) diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt index 3042c39d09..300e236b5b 100644 --- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt +++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt @@ -52,6 +52,15 @@ Optional properties (port (child) node): "da_ref": the reference clock of analog phy, used if the clocks of analog and digital phys are separated, otherwise uses "ref" clock only if needed. +- mediatek,eye-vrt : The selection of VRT reference voltage (U2 phy), + the value is [1, 7] +- mediatek,eye-term: The selection of HS_TX TERM reference voltage (U2 phy), + the value is [1, 7] +- mediatek,discth : The selection of disconnect threshold (U2 phy), + the value is [1, 15] +- mediatek,pre-emphasis: The level of pre-emphasis which used to widen + the eye opening and boost eye swing, + the value is [1, 3] Example: -- 2.25.1
[PATCH 0/4] Support StarFive Watchdog driver
This patchset adds to support StarFive Watchdog driver which is based on Linux kernel's starfive-wdt driver. Actually, the original driver supports both JH7100 and JH7110 with variant coding but this removes the JH7100 part of codes because JH7100 isn't supported in u-boot yet. However, this patch tries to keep the variant coding style for future work of JH7100 and have a consistency with the Linux driver. Chanho Park (4): clk: starfive: jh7110: Add watchdog clocks watchdog: Add StarFive Watchdog driver riscv: dts: jh7110: Add watchdog device tree node configs: visionfive2: Enable watchdog driver arch/riscv/dts/jh7110.dtsi | 10 + configs/starfive_visionfive2_defconfig | 5 + drivers/clk/starfive/clk-jh7110.c | 9 + drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/starfive_wdt.c| 329 + 6 files changed, 361 insertions(+) create mode 100644 drivers/watchdog/starfive_wdt.c -- 2.39.2
[PATCH 3/4] riscv: dts: jh7110: Add watchdog device tree node
Adds jh7110 watchdog device tree node. Signed-off-by: Chanho Park --- arch/riscv/dts/jh7110.dtsi | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi index 13c47f7caa36..6d2675d6ceac 100644 --- a/arch/riscv/dts/jh7110.dtsi +++ b/arch/riscv/dts/jh7110.dtsi @@ -533,6 +533,16 @@ #gpio-cells = <2>; }; + watchdog@1307 { + compatible = "starfive,jh7110-wdt"; + reg = <0x0 0x1307 0x0 0x1>; + clocks = < JH7110_SYSCLK_WDT_APB>, +< JH7110_SYSCLK_WDT_CORE>; + clock-names = "apb", "core"; + resets = < JH7110_SYSRST_WDT_APB>, +< JH7110_SYSRST_WDT_CORE>; + }; + mmc0: mmc@1601 { compatible = "starfive,jh7110-mmc"; reg = <0x0 0x1601 0x0 0x1>; -- 2.39.2
[PATCH 2/4] watchdog: Add StarFive Watchdog driver
Add to support StarFive watchdog driver. The driver is imported from linux kernel's drivers/watchdog/starfive-wdt.c without jh7100 support because there is no support of jh7100 SoC in u-boot yet. Howver, this patch has been kept the variant coding style because JH7100 can be added later and have a consistency with the linux driver. Signed-off-by: Chanho Park --- drivers/watchdog/Kconfig| 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/starfive_wdt.c | 329 3 files changed, 337 insertions(+) create mode 100644 drivers/watchdog/starfive_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 07fc4940e918..569726119ca1 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -344,6 +344,13 @@ config WDT_STM32MP Enable the STM32 watchdog (IWDG) driver. Enable support to configure STM32's on-SoC watchdog. +config WDT_STARFIVE + bool "StarFive watchdog timer support" + depends on WDT + imply WATCHDOG + help + Enable support for the watchdog timer of StarFive JH7110 SoC. + config WDT_SUNXI bool "Allwinner sunxi watchdog timer support" depends on WDT && ARCH_SUNXI diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index eef786f5e74e..5520d3d9ae8a 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_WDT_SBSA) += sbsa_gwdt.o obj-$(CONFIG_WDT_K3_RTI) += rti_wdt.o obj-$(CONFIG_WDT_SL28CPLD) += sl28cpld-wdt.o obj-$(CONFIG_WDT_SP805) += sp805_wdt.o +obj-$(CONFIG_WDT_STARFIVE) += starfive_wdt.o obj-$(CONFIG_WDT_STM32MP) += stm32mp_wdt.o obj-$(CONFIG_WDT_SUNXI) += sunxi_wdt.o obj-$(CONFIG_WDT_TANGIER) += tangier_wdt.o diff --git a/drivers/watchdog/starfive_wdt.c b/drivers/watchdog/starfive_wdt.c new file mode 100644 index ..ee9ec4cdc3a4 --- /dev/null +++ b/drivers/watchdog/starfive_wdt.c @@ -0,0 +1,329 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Starfive Watchdog driver + * + * Copyright (C) 2022 StarFive Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include + +/* JH7110 Watchdog register define */ +#define STARFIVE_WDT_JH7110_LOAD 0x000 +#define STARFIVE_WDT_JH7110_VALUE 0x004 +#define STARFIVE_WDT_JH7110_CONTROL0x008 /* +* [0]: reset enable; +* [1]: interrupt enable && watchdog enable +* [31:2]: reserved. +*/ +#define STARFIVE_WDT_JH7110_INTCLR 0x00c /* clear intterupt and reload the counter */ +#define STARFIVE_WDT_JH7110_IMS0x014 +#define STARFIVE_WDT_JH7110_LOCK 0xc00 /* write 0x1ACCE551 to unlock */ + +/* WDOGCONTROL */ +#define STARFIVE_WDT_ENABLE0x1 +#define STARFIVE_WDT_EN_SHIFT 0 +#define STARFIVE_WDT_RESET_EN 0x1 +#define STARFIVE_WDT_JH7110_RST_EN_SHIFT 1 + +/* WDOGLOCK */ +#define STARFIVE_WDT_JH7110_UNLOCK_KEY 0x1acce551 + +/* WDOGINTCLR */ +#define STARFIVE_WDT_INTCLR0x1 +#define STARFIVE_WDT_JH7100_INTCLR_AVA_SHIFT 1 /* Watchdog can clear interrupt when 0 */ + +#define STARFIVE_WDT_MAXCNT0x +#define STARFIVE_WDT_DEFAULT_TIME (15) +#define STARFIVE_WDT_DELAY_US 0 +#define STARFIVE_WDT_TIMEOUT_US1 + +/* module parameter */ +#define STARFIVE_WDT_EARLY_ENA 0 + +struct starfive_wdt_variant { + unsigned int control; /* Watchdog Control Resgister for reset enable */ + unsigned int load; /* Watchdog Load register */ + unsigned int reload;/* Watchdog Reload Control register */ + unsigned int enable;/* Watchdog Enable Register */ + unsigned int value; /* Watchdog Counter Value Register */ + unsigned int int_clr; /* Watchdog Interrupt Clear Register */ + unsigned int unlock;/* Watchdog Lock Register */ + unsigned int int_status;/* Watchdog Interrupt Status Register */ + + u32 unlock_key; + char enrst_shift; + char en_shift; + bool intclr_check; /* whether need to check it before clearing interrupt */ + char intclr_ava_shift; + bool double_timeout;/* The watchdog need twice timeout to reboot */ +}; + +struct starfive_wdt_priv { + void __iomem *base; + struct clk *core_clk; + struct clk *apb_clk; + struct reset_ctl_bulk *rst; + const struct starfive_wdt_variant *variant; + unsigned long freq; + u32 count; /* count of timeout */ + u32 reload; /* restore the count */ +}; + +/* Register layout and configuration for the
[PATCH 4/4] configs: visionfive2: Enable watchdog driver
Enables StarFive Watchdog driver and WDT command. Signed-off-by: Chanho Park --- configs/starfive_visionfive2_defconfig | 5 + 1 file changed, 5 insertions(+) diff --git a/configs/starfive_visionfive2_defconfig b/configs/starfive_visionfive2_defconfig index b15e7d24db19..7b39a63359dc 100644 --- a/configs/starfive_visionfive2_defconfig +++ b/configs/starfive_visionfive2_defconfig @@ -72,6 +72,7 @@ CONFIG_CMD_MEMINFO=y CONFIG_CMD_I2C=y CONFIG_CMD_PCI=y CONFIG_CMD_USB=y +CONFIG_CMD_WDT=y CONFIG_CMD_TFTPPUT=y CONFIG_CMD_BOOTSTAGE=y CONFIG_OF_BOARD=y @@ -133,3 +134,7 @@ CONFIG_USB_EHCI_PCI=y CONFIG_USB_OHCI_HCD=y CONFIG_USB_OHCI_PCI=y CONFIG_USB_KEYBOARD=y +# CONFIG_WATCHDOG is not set +# CONFIG_WATCHDOG_AUTOSTART is not set +CONFIG_WDT=y +CONFIG_WDT_STARFIVE=y -- 2.39.2
[PATCH 1/4] clk: starfive: jh7110: Add watchdog clocks
Add JH7110_SYSCLK_WDT_APB and JH7110_SYSCLK_WDT_CORE clocks for JH7110 watchdog device. Signed-off-by: Chanho Park --- drivers/clk/starfive/clk-jh7110.c | 9 + 1 file changed, 9 insertions(+) diff --git a/drivers/clk/starfive/clk-jh7110.c b/drivers/clk/starfive/clk-jh7110.c index a835541e48e9..a38694809a00 100644 --- a/drivers/clk/starfive/clk-jh7110.c +++ b/drivers/clk/starfive/clk-jh7110.c @@ -434,6 +434,15 @@ static int jh7110_syscrg_init(struct udevice *dev) starfive_clk_gate(priv->reg, "i2c5_apb", "apb0", OFFSET(JH7110_SYSCLK_I2C5_APB))); + /* Watchdog clocks */ + clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_WDT_APB), + starfive_clk_gate(priv->reg, +"wdt_apb", "apb0", +OFFSET(JH7110_SYSCLK_WDT_APB))); + clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_WDT_CORE), + starfive_clk_gate(priv->reg, +"wdt_core", "oscillator", +OFFSET(JH7110_SYSCLK_WDT_CORE))); /* enable noc_bus_stg_axi clock */ if (!clk_get_by_id(JH7110_SYSCLK_NOC_BUS_STG_AXI, )) -- 2.39.2
[PATCH] mmc: renesas-sdhi: Disable clock after tuning reset when possible
Currently the renesas_sdhi_reset_tuning() unconditionally leaves SDHI clock enabled after the tuning reset. This is not always necessary. After the driver performed tuning reset at the end of probe function, or in the unlikely case that tuning failed during regular operation, the SDHI clock can be disabled after the tuning reset. The following set_ios call would reconfigure the clock as needed. In case of regular set_ios call which requires a tuning reset, keep the clock enabled or disabled according to the mmc->clk_disable state. With this in place, the controllers which have not been accessed via block subsystem after boot are left in quiescent state. However, if an MMC device is used e.g. for environment storage, that controller would be accessed during the environment load and left active, including its clock which would still be generated. This is due to the design of the MMC subsystem, which does not deinit a controller after it was started once, the controller is only deinited in case of mmc rescan, or before OS boot. Signed-off-by: Marek Vasut --- Note: To address the part where MMC device has been inited once and is never deinited until rescan or OS boot, it would likely be necessary to implement something like runtime PM, possibly based on the cyclic framework. Basically, keep track of when the MMC was accessed last, and if certain time elapsed, deinit the MMC. This could also be used to handle card detect polling at the same time. --- Cc: Jaehoon Chung Cc: Nobuhiro Iwamatsu Cc: Paul Barker Cc: Peng Fan --- drivers/mmc/renesas-sdhi.c | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c index 8cd501c5f7c..97aaf1e4ec3 100644 --- a/drivers/mmc/renesas-sdhi.c +++ b/drivers/mmc/renesas-sdhi.c @@ -318,7 +318,7 @@ static unsigned int renesas_sdhi_init_tuning(struct tmio_sd_priv *priv) RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK; } -static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv) +static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv, bool clk_disable) { u32 reg; @@ -350,6 +350,12 @@ static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv) reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL); reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN; tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL); + + if (clk_disable) { + reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL); + reg &= ~TMIO_SD_CLKCTL_SCLKEN; + tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL); + } } static int renesas_sdhi_hs400(struct udevice *dev) @@ -629,7 +635,7 @@ int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode) out: if (ret < 0) { dev_warn(dev, "Tuning procedure failed\n"); - renesas_sdhi_reset_tuning(priv); + renesas_sdhi_reset_tuning(priv, true); } return ret; @@ -668,7 +674,7 @@ static int renesas_sdhi_set_ios(struct udevice *dev) (mmc->selected_mode != UHS_SDR104) && (mmc->selected_mode != MMC_HS_200) && (mmc->selected_mode != MMC_HS_400)) { - renesas_sdhi_reset_tuning(priv); + renesas_sdhi_reset_tuning(priv, mmc->clk_disable); } #endif @@ -1095,7 +1101,7 @@ static int renesas_sdhi_probe(struct udevice *dev) CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) if (priv->caps & TMIO_SD_CAP_RCAR_UHS) - renesas_sdhi_reset_tuning(priv); + renesas_sdhi_reset_tuning(priv, true); #endif return 0; -- 2.42.0
Re: [PATCH 1/1] rng: detect RISC-V Zkr RNG device in bind method
On 11/5/23 18:25, Simon Glass wrote: Hi Heinrich, On Sun, 5 Nov 2023 at 03:47, Heinrich Schuchardt wrote: On 11/4/23 21:42, Simon Glass wrote: Hi Heinrich, On Sat, 4 Nov 2023 at 06:51, Heinrich Schuchardt wrote: The existence of devices should be checked in the bind method and not in the probe method. Adjust the RISC-V Zkr RNG driver accordingly. Use ENOENT (and not ENODEV) to signal that the device is not available. Fixes: ceec977ba1a9 ("rng: Provide a RNG based on the RISC-V Zkr ISA extension") Reported-by: Andre Przywara Signed-off-by: Heinrich Schuchardt --- drivers/rng/riscv_zkr_rng.c | 34 ++ 1 file changed, 26 insertions(+), 8 deletions(-) This device should be in the DT, so you have some control over which RNG is used. The device-tree provided by QEMU does not contain such a device as Zkr is an ISA extension and not a device. This device-tree is not under the control of the U-Boot project. Why do you bring up QEMU? I would expect that it follows the norma dt bindings, so it should not be any different from real hardware? Yes Simon, QEMU follows the normal bindings. If you want to change these, please, contribute to the RISC-V working groups or to the Linux kernel project. Anyway, you could add it. It is just a binding. I believe RISC-V has all sorts of isa options which result in different machine features. What are you going to do when you want to choose between the ISA RNG and a TPM one? First of all there are different configurations switches for both drivers. But of course you can enable both. They will be different U-Boot devices. The rng command has a parameter to choose a RNG device by device number. This is not different to having two USB drives. Best regards Heinrich
Re: [PATCH 2/4] bootm: Move arm64-image processing later
On Sun, Nov 05, 2023 at 01:03:52PM -0700, Simon Glass wrote: > If the image is compressed, then the existing check fails, since the > header is wrong. > > Move the check later in the boot process, after the kernel is > decompressed. This allows use of bootm with compressed kernels, while > still permitting an uncompressed kernel to be used. > > Signed-off-by: Simon Glass How are we getting in to this case exactly? -- Tom signature.asc Description: PGP signature
Re: [PATCH 1/4] bootm: Allow ignoring the load address with kernel_noload
On Sun, Nov 05, 2023 at 01:03:51PM -0700, Simon Glass wrote: > This image type is supposed to ignore the load address. But at present > it fails if the load address is missing. If it is zero, the image is > loaded at address 0, which may not work on all boards. > > Make use of the kernel_addr_r environment variable, instead, since this > seems to be a more reliable final address for the kernel. > > Another option would be to create a new Kconfig for this, or to use a > region of memory known to be free, e.g. calculated from the DRAM banks. > But in any case we should try to avoid conflicting with the > kernel_addr_r variable. So the approach in this patch seems reasonable > to me. > > Signed-off-by: Simon Glass How are you creating the image in question here? A noload FIT is supposed to just supposed to go from where it is. Where do things fall down later? -- Tom signature.asc Description: PGP signature
Re: [PATCH 0/4] bootm: Handle compressed arm64 images with bootm
Hi, On Sun, 5 Nov 2023 at 20:05, Simon Glass wrote: > > This little series corrects a problem I noticed with arm64 images, > where the kernel is not recognised: > >## Loading kernel from FIT Image at 1000 ... > Using 'conf-930' configuration > Verifying Hash Integrity ... OK > Trying 'kernel' kernel subimage > Description: Linux-6.6.0-rc7-next-20231024-3-g259c196f194c > Type: Kernel Image (no loading done) > Compression: gzip compressed > Data Start: 0x1138 > Data Size:13667956 Bytes = 13 MiB > Verifying Hash Integrity ... OK >Bad Linux ARM64 Image magic! > > The problem is that the arm64 magic is checked before the image is > decompressed. > > Another issue is that the load address is read from the 'load' property > even with a kernel_noload image. This means that the kernel is loaded > to address 0, which may not be valid on the board. We can use the > kernel_addr_r environment variable instead. > > A patch is included to show the kernel load-address, so it is easy to > see what is going on. > > > Simon Glass (4): > bootm: Allow ignoring the load address with kernel_noload > bootm: Move arm64-image processing later > image: Show the load address when decompressing > image: Correct load_bug typo > > boot/bootm.c| 61 ++--- > boot/image.c| 13 +++ > include/image.h | 2 +- > 3 files changed, 48 insertions(+), 28 deletions(-) > > -- > 2.42.0.869.gea05f2083d-goog > This series has a few problems still, but I am sending it now since I believe it fixes a real problem on arm64. I will tidy it up soon. Regards, Simon
[PATCH 4/4] image: Correct load_bug typo
Correct a typo in the function comment for image_decomp(). Signed-off-by: Simon Glass --- include/image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/image.h b/include/image.h index 2e3cf839ee36..0fe67852c563 100644 --- a/include/image.h +++ b/include/image.h @@ -936,7 +936,7 @@ int image_decomp_type(const unsigned char *buf, ulong len); * @load: Destination load address in U-Boot memory * @image_start Image start address (where we are decompressing from) * @type: OS type (IH_OS_...) - * @load_bug: Place to decompress to + * @load_buf: Place to decompress to * @image_buf: Address to decompress from * @image_len: Number of bytes in @image_buf to decompress * @unc_len: Available space for decompression -- 2.42.0.869.gea05f2083d-goog
[PATCH 2/4] bootm: Move arm64-image processing later
If the image is compressed, then the existing check fails, since the header is wrong. Move the check later in the boot process, after the kernel is decompressed. This allows use of bootm with compressed kernels, while still permitting an uncompressed kernel to be used. Signed-off-by: Simon Glass --- boot/bootm.c | 51 ++- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 7583be5a4515..8c35afb09937 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -245,27 +245,6 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, return 1; } - if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { - if (IS_ENABLED(CONFIG_CMD_BOOTI) && - images.os.arch == IH_ARCH_ARM64 && - images.os.os == IH_OS_LINUX) { - ulong image_addr; - ulong image_size; - - ret = booti_setup(images.os.image_start, _addr, - _size, true); - if (ret != 0) - return 1; - - images.os.type = IH_TYPE_KERNEL; - images.os.load = image_addr; - images.ep = image_addr; - } else { - images.os.load = images.os.image_start; - images.ep += images.os.image_start; - } - } - images.os.start = map_to_sysmem(os_hdr); return 0; @@ -472,6 +451,36 @@ static int bootm_load_os(struct bootm_headers *images, int boot_progress) } } + if (IS_ENABLED(CONFIG_CMD_BOOTI) && + images->os.type == IH_TYPE_KERNEL_NOLOAD && + images->os.arch == IH_ARCH_ARM64 && + images->os.os == IH_OS_LINUX) { + ulong relocated_addr; + ulong image_size; + int ret; + + ret = booti_setup(load, _addr, _size, + false); + if (ret) { + printf("Failed to prep arm64 kernel (err=%d)\n", + ret); + return BOOTM_ERR_RESET; + } + + /* Handle BOOTM_STATE_LOADOS */ + if (relocated_addr != load) { + printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n", + load, + relocated_addr, relocated_addr + image_size); + memmove((void *)relocated_addr, + load_buf, image_size); + } + + images->ep = relocated_addr; + images->os.start = relocated_addr; + images->os.end = relocated_addr + image_size; + } + lmb_reserve(>lmb, images->os.load, (load_end - images->os.load)); return 0; -- 2.42.0.869.gea05f2083d-goog
[PATCH 1/4] bootm: Allow ignoring the load address with kernel_noload
This image type is supposed to ignore the load address. But at present it fails if the load address is missing. If it is zero, the image is loaded at address 0, which may not work on all boards. Make use of the kernel_addr_r environment variable, instead, since this seems to be a more reliable final address for the kernel. Another option would be to create a new Kconfig for this, or to use a region of memory known to be free, e.g. calculated from the DRAM banks. But in any case we should try to avoid conflicting with the kernel_addr_r variable. So the approach in this patch seems reasonable to me. Signed-off-by: Simon Glass --- boot/bootm.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index cb61485c226c..7583be5a4515 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -176,7 +176,13 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, images.os.end = fit_get_end(images.fit_hdr_os); - if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, + if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { + ulong load; + + load = env_get_hex("kernel_addr_r", -1UL); + printf("Using kernel load address %lx\n", load); + images.os.load = load; + } else if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, )) { puts("Can't get image load address!\n"); bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); @@ -229,7 +235,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, ret = fit_image_get_entry(images.fit_hdr_os, images.fit_noffset_os, ); - if (ret) { + if (ret && images.os.type == IH_TYPE_KERNEL_NOLOAD) { puts("Can't get entry point property!\n"); return 1; } -- 2.42.0.869.gea05f2083d-goog
[PATCH 3/4] image: Show the load address when decompressing
The destination address for decompression (or copying) is useful information. Show this to the user while booting, e.g.: Uncompressing Kernel Image (no loading done) to 208 Signed-off-by: Simon Glass --- boot/image.c | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/boot/image.c b/boot/image.c index 88b67bc3a199..675b5dd77f94 100644 --- a/boot/image.c +++ b/boot/image.c @@ -415,15 +415,20 @@ void image_print_contents(const void *ptr) * @type: OS type (IH_OS_...) * @comp_type: Compression type being used (IH_COMP_...) * @is_xip:true if the load address matches the image start + * @load: Load address for printing */ -static void print_decomp_msg(int comp_type, int type, bool is_xip) +static void print_decomp_msg(int comp_type, int type, bool is_xip, +ulong load) { const char *name = genimg_get_type_name(type); + /* Shows "Loading Kernel Image" for example */ if (comp_type == IH_COMP_NONE) - printf(" %s %s\n", is_xip ? "XIP" : "Loading", name); + printf(" %s %s", is_xip ? "XIP" : "Loading", name); else - printf(" Uncompressing %s\n", name); + printf(" Uncompressing %s", name); + + printf(" to %lx\n", load); } int image_decomp_type(const unsigned char *buf, ulong len) @@ -448,7 +453,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, int ret = -ENOSYS; *load_end = load; - print_decomp_msg(comp, type, load == image_start); + print_decomp_msg(comp, type, load == image_start, load); /* * Load the image to the right place, decompressing if needed. After -- 2.42.0.869.gea05f2083d-goog
[PATCH 0/4] bootm: Handle compressed arm64 images with bootm
This little series corrects a problem I noticed with arm64 images, where the kernel is not recognised: ## Loading kernel from FIT Image at 1000 ... Using 'conf-930' configuration Verifying Hash Integrity ... OK Trying 'kernel' kernel subimage Description: Linux-6.6.0-rc7-next-20231024-3-g259c196f194c Type: Kernel Image (no loading done) Compression: gzip compressed Data Start: 0x1138 Data Size:13667956 Bytes = 13 MiB Verifying Hash Integrity ... OK Bad Linux ARM64 Image magic! The problem is that the arm64 magic is checked before the image is decompressed. Another issue is that the load address is read from the 'load' property even with a kernel_noload image. This means that the kernel is loaded to address 0, which may not be valid on the board. We can use the kernel_addr_r environment variable instead. A patch is included to show the kernel load-address, so it is easy to see what is going on. Simon Glass (4): bootm: Allow ignoring the load address with kernel_noload bootm: Move arm64-image processing later image: Show the load address when decompressing image: Correct load_bug typo boot/bootm.c| 61 ++--- boot/image.c| 13 +++ include/image.h | 2 +- 3 files changed, 48 insertions(+), 28 deletions(-) -- 2.42.0.869.gea05f2083d-goog
Re: [PATCH v3 09/12] x86: Enable SSE in 64-bit mode
Hi Bin, On Sun, 5 Nov 2023 at 14:05, Bin Meng wrote: > > Hi Simon, > > On Mon, Oct 2, 2023 at 9:15 AM Simon Glass wrote: > > > > This is needed to support Truetype fonts. In any case, the compiler > > expects SSE to be available in 64-bit mode. Enable it. > > > > Signed-off-by: Simon Glass > > Suggested-by: Bin Meng > > --- > > > > (no changes since v1) > > > > arch/x86/config.mk| 1 - > > arch/x86/cpu/x86_64/cpu.c | 11 +++ > > 2 files changed, 11 insertions(+), 1 deletion(-) > > > > I didn't suggest we enable SSE for x86. This is the wrong approach. > > We should rewrite the Truetype support codes to avoid using float/double > types. > > This way the Truetype codes can be used on any other architectures > without the need for the compiler to emit explicit floating > instructions. I am not aware of any such library. At present, enabling truetype on coreboot64 causes a hang. Regards, Simon
Re: Need advise with u-boot on SH-7785LCR
Hi John, On Sun, 5 Nov 2023 at 09:37, John Paul Adrian Glaubitz wrote: > > Hi Simon, > > On Sat, 2023-11-04 at 19:42 +, Simon Glass wrote: > > Is it possible to check if it reaches the kernel? E.g. with > > earlyprintk ? It would be good to know if U-Boot managers to jump to > > Linux, or not. > > Thanks, this is actually a very good idea. In fact, we recently restored > earlyprintk support on SuperH which got disabled by accident [1], so I > would have an opportunity to use it right away. > > Do you have maybe any clue as for how to update u-boot on this machine? > > Might be a good idea to start from the most recent version that is supported > on this target. I assume the "erase" command will erase the flash. But there > doesn't seem to be a "program" command. No, sorry I don't have any idea about that. You could check the MAINTAINERS files in U-Boot and Linux for other people, perhaps, or check commit / blame logs? Regards, Simon > > Adrian > > -- > .''`. John Paul Adrian Glaubitz > : :' : Debian Developer > `. `' Physicist > `-GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [PATCH 1/1] rng: detect RISC-V Zkr RNG device in bind method
Hi Heinrich, On Sun, 5 Nov 2023 at 03:47, Heinrich Schuchardt wrote: > > On 11/4/23 21:42, Simon Glass wrote: > > Hi Heinrich, > > > > On Sat, 4 Nov 2023 at 06:51, Heinrich Schuchardt > > wrote: > >> > >> The existence of devices should be checked in the bind method and not in > >> the probe method. Adjust the RISC-V Zkr RNG driver accordingly. > >> > >> Use ENOENT (and not ENODEV) to signal that the device is not available. > >> > >> Fixes: ceec977ba1a9 ("rng: Provide a RNG based on the RISC-V Zkr ISA > >> extension") > >> Reported-by: Andre Przywara > >> Signed-off-by: Heinrich Schuchardt > >> --- > >> drivers/rng/riscv_zkr_rng.c | 34 ++ > >> 1 file changed, 26 insertions(+), 8 deletions(-) > > > > This device should be in the DT, so you have some control over which > > RNG is used. > > The device-tree provided by QEMU does not contain such a device as Zkr > is an ISA extension and not a device. This device-tree is not under the > control of the U-Boot project. Why do you bring up QEMU? I would expect that it follows the norma dt bindings, so it should not be any different from real hardware? Anyway, you could add it. It is just a binding. I believe RISC-V has all sorts of isa options which result in different machine features. What are you going to do when you want to choose between the ISA RNG and a TPM one? Regards, Simon
Re: [PATCH v2] x86: serial: ns16550: Allow the UART to be silently disabled
Hi Simon, On Thu, Nov 2, 2023 at 2:04 AM Simon Glass wrote: > > U-Boot normally requires a UART. When booting from coreboot it is > sometimes just not available, e.g. when no sysinfo or DBG2 information > is provided. > > In this case we need to continue running, since the display can be used. > Add a flag to disable serial for this case. > > This allows U-Boot to start up and operation from the display, instead > of hanging on start-up. > > This could perhaps be hidden behind a Kconfig option to reduce code > size. I think using a generic Kconfig option and filtering this out in the generic serial probe code is better than what is proposed in this patch. > > Signed-off-by: Simon Glass > --- > > Changes in v2: > - Drop RFC tag since there were no comments > > drivers/serial/ns16550.c | 17 +++-- > drivers/serial/serial_coreboot.c | 1 + > include/ns16550.h| 1 + > 3 files changed, 17 insertions(+), 2 deletions(-) > Regards, Bin
Re: [PATCH v3 08/12] video: Drop unnecessary truetype operations from SPL
On Mon, Oct 2, 2023 at 11:32 AM Simon Glass wrote: > > Saving and restoring entries is used for expo and for the command line, > which we don't use in SPL. Drop these methods. > > Signed-off-by: Simon Glass > --- > > Changes in v3: > - Add new patch to drop unnecessary truetype operations from SPL > > drivers/video/console_truetype.c | 10 ++ > 1 file changed, 10 insertions(+) > Reviewed-by: Bin Meng
Re: [PATCH v3 06/12] expo: Correct background colour
On Mon, Oct 2, 2023 at 9:30 AM Simon Glass wrote: > > Use the correct background colour when using white-on-black. > > Signed-off-by: Simon Glass > --- > > (no changes since v1) > > boot/expo.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > Reviewed-by: Bin Meng
Re: [PATCH v3 01/12] efi: Correct handling of frame buffer
On Mon, Oct 2, 2023 at 10:23 AM Simon Glass wrote: > > The efi_gop driver uses private fields from the video uclass to obtain a > pointer to the frame buffer. Use the platform data instead. > > Check the VIDEO_COPY setting to determine which frame buffer to use. Once > the next stage is running (and making use of U-Boot's EFI boot services) > U-Boot does not handle copying from priv->fb to the hardware framebuffer, > so we must allow EFI to write directly to the hardware framebuffer. > > We could provide a function to read this, but it seems better to just > document how it works. The original change ignored an explicit comment > in the video.h file ("Things that are private to the uclass: don't use > these in the driver") which is why this was missed when the VIDEO_COPY > feature was added. > > Signed-off-by: Simon Glass > Fixes: 8f661a5b662 ("efi_loader: gop: Expose fb when 32bpp") > --- > > (no changes since v2) > > Changes in v2: > - Rebase to -next > - Add some more comments to the header file > - Add fixes tag > > include/video.h | 9 ++--- > lib/efi_loader/efi_gop.c | 12 +++- > 2 files changed, 13 insertions(+), 8 deletions(-) > Reviewed-by: Bin Meng
Re: [PATCH v3 04/12] x86: coreboot: Add a boot script
On Mon, Oct 2, 2023 at 9:14 AM Simon Glass wrote: > > Provide the user with a list of available boot options. Selecting one > causes it to be booted. Pressing causes U-Boot to return to the > command-line prompt. > > Signed-off-by: Simon Glass > --- > > Changes in v3: > - Clear the screen before booting > > Changes in v2: > - Add new patch to add a coreboot boot script > > configs/coreboot64_defconfig | 1 + > configs/coreboot_defconfig | 1 + > 2 files changed, 2 insertions(+) > Reviewed-by: Bin Meng
Re: [PATCH v3 09/12] x86: Enable SSE in 64-bit mode
Hi Simon, On Mon, Oct 2, 2023 at 9:15 AM Simon Glass wrote: > > This is needed to support Truetype fonts. In any case, the compiler > expects SSE to be available in 64-bit mode. Enable it. > > Signed-off-by: Simon Glass > Suggested-by: Bin Meng > --- > > (no changes since v1) > > arch/x86/config.mk| 1 - > arch/x86/cpu/x86_64/cpu.c | 11 +++ > 2 files changed, 11 insertions(+), 1 deletion(-) > I didn't suggest we enable SSE for x86. This is the wrong approach. We should rewrite the Truetype support codes to avoid using float/double types. This way the Truetype codes can be used on any other architectures without the need for the compiler to emit explicit floating instructions. Regards, Bin
[PATCH v6 8/8] cmd: clk: Make soc_clk_dump static
After introducing dump to clk_ops there is no need to override or expose this symbol anymore. Signed-off-by: Igor Prusov Reviewed-by: Patrice Chotard Tested-by: Patrice Chotard Reviewed-by: Sean Anderson --- cmd/clk.c | 4 ++-- include/clk.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/clk.c b/cmd/clk.c index 4b9709d3ff..7bbcbfeda3 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -59,7 +59,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag) } } -int __weak soc_clk_dump(void) +static int soc_clk_dump(void) { struct udevice *dev; const struct clk_ops *ops; @@ -81,7 +81,7 @@ int __weak soc_clk_dump(void) return 0; } #else -int __weak soc_clk_dump(void) +static int soc_clk_dump(void) { puts("Not implemented\n"); return 1; diff --git a/include/clk.h b/include/clk.h index 249c0e0ab4..3d6394477b 100644 --- a/include/clk.h +++ b/include/clk.h @@ -676,8 +676,6 @@ static inline bool clk_valid(struct clk *clk) return clk && !!clk->dev; } -int soc_clk_dump(void); - #endif #define clk_prepare_enable(clk) clk_enable(clk) -- 2.34.1
[PATCH v6 7/8] clk: treewide: switch to clock dump from clk_ops
Switch to using new dump operation in clock provider drivers instead of overriding soc_clk_dump. Signed-off-by: Igor Prusov Tested-by: Patrice Chotard Reviewed-by: Sean Anderson --- arch/mips/mach-pic32/cpu.c | 23 drivers/clk/aspeed/clk_ast2600.c | 13 + drivers/clk/clk_k210.c | 12 +++-- drivers/clk/clk_pic32.c| 37 ++ drivers/clk/clk_versal.c | 9 --- drivers/clk/clk_zynq.c | 28 --- drivers/clk/clk_zynqmp.c | 22 +++ drivers/clk/imx/clk-imx8.c | 13 +++-- drivers/clk/meson/a1.c | 28 ++- drivers/clk/mvebu/armada-37xx-periph.c | 20 +- drivers/clk/stm32/clk-stm32mp1.c | 31 ++--- 11 files changed, 108 insertions(+), 128 deletions(-) diff --git a/arch/mips/mach-pic32/cpu.c b/arch/mips/mach-pic32/cpu.c index dbf8c9cd22..3181a946a2 100644 --- a/arch/mips/mach-pic32/cpu.c +++ b/arch/mips/mach-pic32/cpu.c @@ -143,26 +143,3 @@ const char *get_core_name(void) return str; } #endif -#ifdef CONFIG_CMD_CLK - -int soc_clk_dump(void) -{ - int i; - - printf("PLL Speed: %lu MHz\n", - CLK_MHZ(rate(PLLCLK))); - - printf("CPU Speed: %lu MHz\n", CLK_MHZ(rate(PB7CLK))); - - printf("MPLL Speed: %lu MHz\n", CLK_MHZ(rate(MPLL))); - - for (i = PB1CLK; i <= PB7CLK; i++) - printf("PB%d Clock Speed: %lu MHz\n", i - PB1CLK + 1, - CLK_MHZ(rate(i))); - - for (i = REF1CLK; i <= REF5CLK; i++) - printf("REFO%d Clock Speed: %lu MHz\n", i - REF1CLK + 1, - CLK_MHZ(rate(i))); - return 0; -} -#endif diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c index b3cc8392fa..eecfacd7fc 100644 --- a/drivers/clk/aspeed/clk_ast2600.c +++ b/drivers/clk/aspeed/clk_ast2600.c @@ -1109,6 +1109,7 @@ struct aspeed_clks { const char *name; }; +#if IS_ENABLED(CONFIG_CMD_CLK) static struct aspeed_clks aspeed_clk_names[] = { { ASPEED_CLK_HPLL, "hpll" }, { ASPEED_CLK_MPLL, "mpll" }, @@ -1123,18 +1124,12 @@ static struct aspeed_clks aspeed_clk_names[] = { { ASPEED_CLK_HUARTX, "huxclk" }, }; -int soc_clk_dump(void) +static void ast2600_clk_dump(struct udevice *dev) { - struct udevice *dev; struct clk clk; unsigned long rate; int i, ret; - ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(aspeed_scu), - ); - if (ret) - return ret; - printf("Clk\t\tHz\n"); for (i = 0; i < ARRAY_SIZE(aspeed_clk_names); i++) { @@ -1167,11 +1162,15 @@ int soc_clk_dump(void) return 0; } +#endif struct clk_ops ast2600_clk_ops = { .get_rate = ast2600_clk_get_rate, .set_rate = ast2600_clk_set_rate, .enable = ast2600_clk_enable, +#if IS_ENABLED(CONFIG_CMD_CLK) + .dump = ast2600_clk_dump, +#endif }; static int ast2600_clk_probe(struct udevice *dev) diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c index 2f17152021..b8d666e805 100644 --- a/drivers/clk/clk_k210.c +++ b/drivers/clk/clk_k210.c @@ -1276,16 +1276,10 @@ static void show_clks(struct k210_clk_priv *priv, int id, int depth) } } -int soc_clk_dump(void) +static int k210_clk_dump(struct udevice *dev) { - int ret; - struct udevice *dev; struct k210_clk_priv *priv; - ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(k210_clk), - ); - if (ret) - return ret; priv = dev_get_priv(dev); puts(" Rate Enabled Name\n"); @@ -1293,7 +1287,6 @@ int soc_clk_dump(void) printf(" %-9lu %-7c %*s%s\n", clk_get_rate(>in0), 'y', 0, "", priv->in0.dev->name); show_clks(priv, K210_CLK_IN0, 1); - return 0; } #endif @@ -1304,6 +1297,9 @@ static const struct clk_ops k210_clk_ops = { .set_parent = k210_clk_set_parent, .enable = k210_clk_enable, .disable = k210_clk_disable, +#if IS_ENABLED(CONFIG_CMD_CLK) + .dump = k210_clk_dump, +#endif }; static int k210_clk_probe(struct udevice *dev) diff --git a/drivers/clk/clk_pic32.c b/drivers/clk/clk_pic32.c index ef06a7fb9f..a77d0e7419 100644 --- a/drivers/clk/clk_pic32.c +++ b/drivers/clk/clk_pic32.c @@ -20,6 +20,8 @@ DECLARE_GLOBAL_DATA_PTR; +#define CLK_MHZ(x) ((x) / 100) + /* Primary oscillator */ #define SYS_POSC_CLK_HZ2400 @@ -385,9 +387,44 @@ static ulong pic32_set_rate(struct clk *clk, ulong rate) return rate; } +#if IS_ENABLED(CONFIG_CMD_CLK) +static void pic32_dump(struct udevice *dev) +{ + int i; + struct clk clk; + + clk.dev = dev; + + clk.id = PLLCLK; + printf("PLL Speed: %lu MHz\n", +
[PATCH v6 1/8] clk: zynq: Move soc_clk_dump to Zynq clock driver
Move clock dump function in preparation for switching to dump function in clk_ops. Signed-off-by: Igor Prusov Acked-by: Michal Simek --- arch/arm/mach-zynq/clk.c | 57 --- drivers/clk/clk_zynq.c | 58 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/arch/arm/mach-zynq/clk.c b/arch/arm/mach-zynq/clk.c index 1945f60e08..e6a67326dd 100644 --- a/arch/arm/mach-zynq/clk.c +++ b/arch/arm/mach-zynq/clk.c @@ -13,20 +13,6 @@ DECLARE_GLOBAL_DATA_PTR; -static const char * const clk_names[clk_max] = { - "armpll", "ddrpll", "iopll", - "cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x", - "ddr2x", "ddr3x", "dci", - "lqspi", "smc", "pcap", "gem0", "gem1", - "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1", - "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma", - "usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper", - "sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper", - "can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper", - "uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper", - "smc_aper", "swdt", "dbg_trc", "dbg_apb" -}; - /** * set_cpu_clk_info() - Setup clock information * @@ -65,46 +51,3 @@ int set_cpu_clk_info(void) return 0; } - -/** - * soc_clk_dump() - Print clock frequencies - * Returns zero on success - * - * Implementation for the clk dump command. - */ -int soc_clk_dump(void) -{ - struct udevice *dev; - int i, ret; - - ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_DRIVER_GET(zynq_clk), ); - if (ret) - return ret; - - printf("clk\t\tfrequency\n"); - for (i = 0; i < clk_max; i++) { - const char *name = clk_names[i]; - if (name) { - struct clk clk; - unsigned long rate; - - clk.id = i; - ret = clk_request(dev, ); - if (ret < 0) - return ret; - - rate = clk_get_rate(); - - clk_free(); - - if ((rate == (unsigned long)-ENOSYS) || - (rate == (unsigned long)-ENXIO)) - printf("%10s%20s\n", name, "unknown"); - else - printf("%10s%20lu\n", name, rate); - } - } - - return 0; -} diff --git a/drivers/clk/clk_zynq.c b/drivers/clk/clk_zynq.c index e80500e382..be5226175f 100644 --- a/drivers/clk/clk_zynq.c +++ b/drivers/clk/clk_zynq.c @@ -454,6 +454,64 @@ static int dummy_enable(struct clk *clk) return 0; } +static const char * const clk_names[clk_max] = { + "armpll", "ddrpll", "iopll", + "cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x", + "ddr2x", "ddr3x", "dci", + "lqspi", "smc", "pcap", "gem0", "gem1", + "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1", + "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma", + "usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper", + "sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper", + "can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper", + "uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper", + "smc_aper", "swdt", "dbg_trc", "dbg_apb" +}; + +/** + * soc_clk_dump() - Print clock frequencies + * Returns zero on success + * + * Implementation for the clk dump command. + */ +int soc_clk_dump(void) +{ + struct udevice *dev; + int i, ret; + + ret = uclass_get_device_by_driver(UCLASS_CLK, + DM_DRIVER_GET(zynq_clk), ); + if (ret) + return ret; + + printf("clk\t\tfrequency\n"); + for (i = 0; i < clk_max; i++) { + const char *name = clk_names[i]; + + if (name) { + struct clk clk; + unsigned long rate; + + clk.id = i; + ret = clk_request(dev, ); + if (ret < 0) + return ret; + + rate = clk_get_rate(); + + clk_free(); + + if ((rate == (unsigned long)-ENOSYS) || + (rate == (unsigned long)-ENXIO)) + printf("%10s%20s\n", name, "unknown"); + else + printf("%10s%20lu\n", name, rate); + } + } + + return 0; +} + static struct clk_ops zynq_clk_ops = { .get_rate = zynq_clk_get_rate, #ifndef CONFIG_SPL_BUILD -- 2.34.1
[PATCH v6 3/8] clk: k210: Move soc_clk_dump function
Move clock dump function to avoid forward declaration after switching to dump in clk_ops. Signed-off-by: Igor Prusov Reviewed-by: Sean Anderson --- drivers/clk/clk_k210.c | 92 +- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c index c534cc07e0..2f17152021 100644 --- a/drivers/clk/clk_k210.c +++ b/drivers/clk/clk_k210.c @@ -1238,52 +1238,6 @@ static int k210_clk_request(struct clk *clk) return 0; } -static const struct clk_ops k210_clk_ops = { - .request = k210_clk_request, - .set_rate = k210_clk_set_rate, - .get_rate = k210_clk_get_rate, - .set_parent = k210_clk_set_parent, - .enable = k210_clk_enable, - .disable = k210_clk_disable, -}; - -static int k210_clk_probe(struct udevice *dev) -{ - int ret; - struct k210_clk_priv *priv = dev_get_priv(dev); - - priv->base = dev_read_addr_ptr(dev_get_parent(dev)); - if (!priv->base) - return -EINVAL; - - ret = clk_get_by_index(dev, 0, >in0); - if (ret) - return ret; - - /* -* Force setting defaults, even before relocation. This is so we can -* set the clock rate for PLL1 before we relocate into aisram. -*/ - if (!(gd->flags & GD_FLG_RELOC)) - clk_set_defaults(dev, CLK_DEFAULTS_POST_FORCE); - - return 0; -} - -static const struct udevice_id k210_clk_ids[] = { - { .compatible = "canaan,k210-clk" }, - { }, -}; - -U_BOOT_DRIVER(k210_clk) = { - .name = "k210_clk", - .id = UCLASS_CLK, - .of_match = k210_clk_ids, - .ops = _clk_ops, - .probe = k210_clk_probe, - .priv_auto = sizeof(struct k210_clk_priv), -}; - #if IS_ENABLED(CONFIG_CMD_CLK) static char show_enabled(struct k210_clk_priv *priv, int id) { @@ -1342,3 +1296,49 @@ int soc_clk_dump(void) return 0; } #endif + +static const struct clk_ops k210_clk_ops = { + .request = k210_clk_request, + .set_rate = k210_clk_set_rate, + .get_rate = k210_clk_get_rate, + .set_parent = k210_clk_set_parent, + .enable = k210_clk_enable, + .disable = k210_clk_disable, +}; + +static int k210_clk_probe(struct udevice *dev) +{ + int ret; + struct k210_clk_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr_ptr(dev_get_parent(dev)); + if (!priv->base) + return -EINVAL; + + ret = clk_get_by_index(dev, 0, >in0); + if (ret) + return ret; + + /* +* Force setting defaults, even before relocation. This is so we can +* set the clock rate for PLL1 before we relocate into aisram. +*/ + if (!(gd->flags & GD_FLG_RELOC)) + clk_set_defaults(dev, CLK_DEFAULTS_POST_FORCE); + + return 0; +} + +static const struct udevice_id k210_clk_ids[] = { + { .compatible = "canaan,k210-clk" }, + { }, +}; + +U_BOOT_DRIVER(k210_clk) = { + .name = "k210_clk", + .id = UCLASS_CLK, + .of_match = k210_clk_ids, + .ops = _clk_ops, + .probe = k210_clk_probe, + .priv_auto = sizeof(struct k210_clk_priv), +}; -- 2.34.1
[PATCH v6 2/8] clk: ast2600: Move soc_clk_dump function
Move clock dump function to avoid forward declaration after switching to dump in clk_ops. Signed-off-by: Igor Prusov --- drivers/clk/aspeed/clk_ast2600.c | 70 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c index e5ada5b6d4..b3cc8392fa 100644 --- a/drivers/clk/aspeed/clk_ast2600.c +++ b/drivers/clk/aspeed/clk_ast2600.c @@ -1104,41 +1104,6 @@ static int ast2600_clk_enable(struct clk *clk) return 0; } -struct clk_ops ast2600_clk_ops = { - .get_rate = ast2600_clk_get_rate, - .set_rate = ast2600_clk_set_rate, - .enable = ast2600_clk_enable, -}; - -static int ast2600_clk_probe(struct udevice *dev) -{ - struct ast2600_clk_priv *priv = dev_get_priv(dev); - - priv->scu = devfdt_get_addr_ptr(dev); - if (IS_ERR(priv->scu)) - return PTR_ERR(priv->scu); - - ast2600_init_rgmii_clk(priv->scu, _clk_defconfig); - ast2600_init_rmii_clk(priv->scu, _clk_defconfig); - ast2600_configure_mac12_clk(priv->scu); - ast2600_configure_mac34_clk(priv->scu); - ast2600_configure_rsa_ecc_clk(priv->scu); - - return 0; -} - -static int ast2600_clk_bind(struct udevice *dev) -{ - int ret; - - /* The reset driver does not have a device node, so bind it here */ - ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", ); - if (ret) - debug("Warning: No reset driver: ret=%d\n", ret); - - return 0; -} - struct aspeed_clks { ulong id; const char *name; @@ -1203,6 +1168,41 @@ int soc_clk_dump(void) return 0; } +struct clk_ops ast2600_clk_ops = { + .get_rate = ast2600_clk_get_rate, + .set_rate = ast2600_clk_set_rate, + .enable = ast2600_clk_enable, +}; + +static int ast2600_clk_probe(struct udevice *dev) +{ + struct ast2600_clk_priv *priv = dev_get_priv(dev); + + priv->scu = devfdt_get_addr_ptr(dev); + if (IS_ERR(priv->scu)) + return PTR_ERR(priv->scu); + + ast2600_init_rgmii_clk(priv->scu, _clk_defconfig); + ast2600_init_rmii_clk(priv->scu, _clk_defconfig); + ast2600_configure_mac12_clk(priv->scu); + ast2600_configure_mac34_clk(priv->scu); + ast2600_configure_rsa_ecc_clk(priv->scu); + + return 0; +} + +static int ast2600_clk_bind(struct udevice *dev) +{ + int ret; + + /* The reset driver does not have a device node, so bind it here */ + ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", ); + if (ret) + debug("Warning: No reset driver: ret=%d\n", ret); + + return 0; +} + static const struct udevice_id ast2600_clk_ids[] = { { .compatible = "aspeed,ast2600-scu", }, { }, -- 2.34.1
[PATCH v6 4/8] clk: amlogic: Move driver and ops structs
Move driver and ops structs to avoid forward declaration after switching to dump in clk_ops. Signed-off-by: Igor Prusov Reviewed-by: Neil Armstrong --- drivers/clk/meson/a1.c | 34 +- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/clk/meson/a1.c b/drivers/clk/meson/a1.c index 1075ba7333..e3fa9db7d0 100644 --- a/drivers/clk/meson/a1.c +++ b/drivers/clk/meson/a1.c @@ -601,14 +601,6 @@ static int meson_clk_set_parent(struct clk *clk, struct clk *parent_clk) return meson_mux_set_parent_by_id(clk, parent_clk->id); } -static struct clk_ops meson_clk_ops = { - .disable= meson_clk_disable, - .enable = meson_clk_enable, - .get_rate = meson_clk_get_rate, - .set_rate = meson_clk_set_rate, - .set_parent = meson_clk_set_parent, -}; - static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); @@ -638,15 +630,6 @@ static const struct udevice_id meson_clk_ids[] = { { } }; -U_BOOT_DRIVER(meson_clk) = { - .name = "meson-clk-a1", - .id = UCLASS_CLK, - .of_match = meson_clk_ids, - .priv_auto = sizeof(struct meson_clk), - .ops= _clk_ops, - .probe = meson_clk_probe, -}; - static const char *meson_clk_get_name(struct clk *clk, int id) { const struct meson_clk_info *info; @@ -727,3 +710,20 @@ int soc_clk_dump(void) return 0; } + +static struct clk_ops meson_clk_ops = { + .disable= meson_clk_disable, + .enable = meson_clk_enable, + .get_rate = meson_clk_get_rate, + .set_rate = meson_clk_set_rate, + .set_parent = meson_clk_set_parent, +}; + +U_BOOT_DRIVER(meson_clk) = { + .name = "meson-clk-a1", + .id = UCLASS_CLK, + .of_match = meson_clk_ids, + .priv_auto = sizeof(struct meson_clk), + .ops= _clk_ops, + .probe = meson_clk_probe, +}; -- 2.34.1
[PATCH v6 5/8] clk: Add dump operation to clk_ops
This adds dump function to struct clk_ops which should replace soc_clk_dump. It allows clock drivers to provide custom dump implementation without overriding generic CCF dump function. Signed-off-by: Igor Prusov Reviewed-by: Patrice Chotard Tested-by: Patrice Chotard --- include/clk-uclass.h | 15 +++ 1 file changed, 15 insertions(+) diff --git a/include/clk-uclass.h b/include/clk-uclass.h index a22f1a5d84..3419daab34 100644 --- a/include/clk-uclass.h +++ b/include/clk-uclass.h @@ -25,6 +25,7 @@ struct ofnode_phandle_args; * @set_parent: Set current clock parent * @enable: Enable a clock. * @disable: Disable a clock. + * @dump: Print clock information. * * The individual methods are described more fully below. */ @@ -39,6 +40,9 @@ struct clk_ops { int (*set_parent)(struct clk *clk, struct clk *parent); int (*enable)(struct clk *clk); int (*disable)(struct clk *clk); +#if IS_ENABLED(CONFIG_CMD_CLK) + void (*dump)(struct udevice *dev); +#endif }; #if 0 /* For documentation only */ @@ -135,6 +139,17 @@ int enable(struct clk *clk); * Return: zero on success, or -ve error code. */ int disable(struct clk *clk); + +/** + * dump() - Print clock information. + * @clk: The clock device to dump. + * + * If present, this function is called by "clk dump" command for each + * bound device. + * + * Return: zero on success, or -ve error code. + */ +void dump(struct udevice *dev); #endif #endif -- 2.34.1
[PATCH v6 6/8] cmd: clk: Use dump function from clk_ops
Add another loop to dump additional info from clock providers that implement dump operation. Signed-off-by: Igor Prusov Reviewed-by: Patrice Chotard Tested-by: Patrice Chotard --- cmd/clk.c | 9 + 1 file changed, 9 insertions(+) diff --git a/cmd/clk.c b/cmd/clk.c index c7c379d7a6..4b9709d3ff 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -62,6 +62,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag) int __weak soc_clk_dump(void) { struct udevice *dev; + const struct clk_ops *ops; printf(" Rate Usecnt Name\n"); printf("--\n"); @@ -69,6 +70,14 @@ int __weak soc_clk_dump(void) uclass_foreach_dev_probe(UCLASS_CLK, dev) show_clks(dev, -1, 0); + uclass_foreach_dev_probe(UCLASS_CLK, dev) { + ops = dev_get_driver_ops(dev); + if (ops && ops->dump) { + printf("\n%s %s:\n", dev->driver->name, dev->name); + ops->dump(dev); + } + } + return 0; } #else -- 2.34.1
[PATCH v6 0/8] clk: Switch from soc_clk_dump to clk_ops function
Currently clock providers may override default implementation of soc_clk_dump function to replace clk dump command output. This causes confusing behaviour when u-boot is built with one of such drivers enabled but still has clocks defined using CCF. For example, enabling CMD_CLK and using clk dump on sandbox target will not show CCF clocks because k210 driver overrides common soc_clk_dump. Changelog: v1 -> v2: - Add missing static to dump functions v2 -> v3: - Make soc_clk_dump in cmd/clk.c static instead of removing __weak v3 -> v4: - Rebase and refactor dump for new Amlogic A1 clock controller driver v4 -> v5: - Add docs for dump() function in clk_ops - Print driver and device names before calling corresponding dump() v5 -> v6: - dump() return type changed to void - meson_clk_dump() and helper functions moved under CONFIG_CMD_CLK to fix unused-function diagnostic Igor Prusov (8): clk: zynq: Move soc_clk_dump to Zynq clock driver clk: ast2600: Move soc_clk_dump function clk: k210: Move soc_clk_dump function clk: amlogic: Move driver and ops structs clk: Add dump operation to clk_ops cmd: clk: Use dump function from clk_ops clk: treewide: switch to clock dump from clk_ops cmd: clk: Make soc_clk_dump static arch/arm/mach-zynq/clk.c | 57 -- arch/mips/mach-pic32/cpu.c | 23 -- cmd/clk.c | 13 +++- drivers/clk/aspeed/clk_ast2600.c | 83 ++-- drivers/clk/clk_k210.c | 104 - drivers/clk/clk_pic32.c| 37 + drivers/clk/clk_versal.c | 9 ++- drivers/clk/clk_zynq.c | 52 + drivers/clk/clk_zynqmp.c | 22 +++--- drivers/clk/imx/clk-imx8.c | 13 +--- drivers/clk/meson/a1.c | 58 ++ drivers/clk/mvebu/armada-37xx-periph.c | 20 +++-- drivers/clk/stm32/clk-stm32mp1.c | 31 ++-- include/clk-uclass.h | 15 include/clk.h | 2 - 15 files changed, 271 insertions(+), 268 deletions(-) -- 2.34.1
Re: Need advise with u-boot on SH-7785LCR
Hi Simon, On Sat, 2023-11-04 at 19:42 +, Simon Glass wrote: > Is it possible to check if it reaches the kernel? E.g. with > earlyprintk ? It would be good to know if U-Boot managers to jump to > Linux, or not. Thanks, this is actually a very good idea. In fact, we recently restored earlyprintk support on SuperH which got disabled by accident [1], so I would have an opportunity to use it right away. Do you have maybe any clue as for how to update u-boot on this machine? Might be a good idea to start from the most recent version that is supported on this target. I assume the "erase" command will erase the flash. But there doesn't seem to be a "program" command. Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `-GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913