Merge branch 'master' of git://git.denx.de/u-boot-usb
authorTom Rini <trini@konsulko.com>
Tue, 28 Apr 2020 14:08:47 +0000 (10:08 -0400)
committerTom Rini <trini@konsulko.com>
Tue, 28 Apr 2020 14:08:47 +0000 (10:08 -0400)
- DWC2/DWC3 improvements
- Assorted bugfixes

226 files changed:
.azure-pipelines.yml
.gitlab-ci.yml
.readthedocs.yml [new file with mode: 0644]
.travis.yml
Makefile
arch/arc/Kconfig
arch/arc/dts/Makefile
arch/arc/dts/hsdk-4xd.dts [new file with mode: 0644]
arch/arc/dts/hsdk-common.dtsi [new file with mode: 0644]
arch/arc/dts/hsdk.dts
arch/arc/include/asm/arcregs.h
arch/arc/lib/start.S
arch/arm/mach-socfpga/include/mach/clock_manager_s10.h
arch/mips/Kconfig
arch/mips/cpu/start.S
arch/mips/cpu/u-boot-spl.lds
arch/mips/dts/Makefile
arch/mips/dts/mediatek,mt7628-rfb.dts [new file with mode: 0644]
arch/mips/dts/mt7628-u-boot.dtsi [new file with mode: 0644]
arch/mips/dts/mt7628a.dtsi
arch/mips/dts/vocore_vocore2.dts [new file with mode: 0644]
arch/mips/include/asm/global_data.h
arch/mips/include/asm/u-boot-mips.h
arch/mips/lib/Makefile
arch/mips/lib/bootm.c
arch/mips/lib/spl.c [new file with mode: 0644]
arch/mips/lib/traps.c
arch/mips/mach-mtmips/Kconfig
arch/mips/mach-mtmips/Makefile
arch/mips/mach-mtmips/cpu.c
arch/mips/mach-mtmips/ddr_cal.c [new file with mode: 0644]
arch/mips/mach-mtmips/ddr_calibrate.c [deleted file]
arch/mips/mach-mtmips/ddr_init.c [new file with mode: 0644]
arch/mips/mach-mtmips/include/mach/ddr.h [new file with mode: 0644]
arch/mips/mach-mtmips/include/mach/mc.h [new file with mode: 0644]
arch/mips/mach-mtmips/include/mach/serial.h [new file with mode: 0644]
arch/mips/mach-mtmips/lowlevel_init.S [deleted file]
arch/mips/mach-mtmips/mt7628/Makefile [new file with mode: 0644]
arch/mips/mach-mtmips/mt7628/ddr.c [new file with mode: 0644]
arch/mips/mach-mtmips/mt7628/init.c [new file with mode: 0644]
arch/mips/mach-mtmips/mt7628/lowlevel_init.S [new file with mode: 0644]
arch/mips/mach-mtmips/mt7628/mt7628.h [new file with mode: 0644]
arch/mips/mach-mtmips/mt7628/serial.c [new file with mode: 0644]
arch/mips/mach-mtmips/mt76xx.h [deleted file]
arch/mips/mach-mtmips/spl.c [new file with mode: 0644]
board/gardena/smart-gateway-mt7688/board.c
board/mediatek/mt7628/Kconfig [new file with mode: 0644]
board/mediatek/mt7628/MAINTAINERS [new file with mode: 0644]
board/mediatek/mt7628/Makefile [new file with mode: 0644]
board/mediatek/mt7628/board.c [new file with mode: 0644]
board/synopsys/hsdk/Kconfig
board/synopsys/hsdk/MAINTAINERS
board/synopsys/hsdk/config.mk
board/synopsys/hsdk/headerize-hsdk.py
board/synopsys/hsdk/hsdk.c
board/vocore/vocore2/Kconfig [new file with mode: 0644]
board/vocore/vocore2/MAINTAINERS [new file with mode: 0644]
board/vocore/vocore2/Makefile [new file with mode: 0644]
board/vocore/vocore2/board.c [new file with mode: 0644]
cmd/mem.c
common/Makefile
common/fdt_region.c [new file with mode: 0644]
common/image-fit-sig.c
common/log.c
common/spl/Makefile
common/spl/spl.c
common/spl/spl_legacy.c [new file with mode: 0644]
common/spl/spl_nor.c
configs/gardena-smart-gateway-mt7688-ram_defconfig [deleted file]
configs/gardena-smart-gateway-mt7688_defconfig
configs/hsdk_4xd_defconfig [new file with mode: 0644]
configs/linkit-smart-7688-ram_defconfig [deleted file]
configs/linkit-smart-7688_defconfig
configs/mt7628_rfb_defconfig [new file with mode: 0644]
configs/socfpga_arria10_defconfig
configs/vocore2_defconfig [new file with mode: 0644]
doc/conf.py
doc/sphinx/parse-headers.pl
drivers/clk/clk-hsdk-cgu.c
drivers/mtd/nand/raw/brcmnand/brcmnand.c
drivers/sysreset/Kconfig
drivers/sysreset/Makefile
drivers/sysreset/sysreset_resetctl.c [new file with mode: 0644]
fs/ext4/ext4_journal.c
include/configs/bmips_bcm6318.h
include/configs/bmips_bcm63268.h
include/configs/bmips_bcm6328.h
include/configs/bmips_bcm6348.h
include/configs/bmips_bcm6358.h
include/configs/bmips_bcm6362.h
include/configs/bmips_bcm6368.h
include/configs/gardena-smart-gateway-mt7688.h
include/configs/hsdk-4xd.h [new file with mode: 0644]
include/configs/linkit-smart-7688.h
include/configs/mt7628.h [new file with mode: 0644]
include/configs/vocore2.h [new file with mode: 0644]
include/dt-bindings/clock/snps,hsdk-cgu.h
include/fdt_region.h [new file with mode: 0644]
include/linux/libfdt.h
include/spl.h
lib/Kconfig
lib/Makefile
lib/libfdt/Makefile
lib/libfdt/fdt_region.c [deleted file]
lib/libfdt/fdt_ro.c
lib/zlib/trees.c
net/Kconfig
net/tftp.c
test/py/tests/test_fs/conftest.py
test/run
tools/Makefile
tools/binman/binman
tools/binman/binman.py [deleted file]
tools/binman/cbfs_util.py
tools/binman/cbfs_util_test.py
tools/binman/control.py
tools/binman/elf.py
tools/binman/elf_test.py
tools/binman/entry.py
tools/binman/entry_test.py
tools/binman/etype/__init__.py [deleted file]
tools/binman/etype/_testing.py
tools/binman/etype/blob.py
tools/binman/etype/blob_dtb.py
tools/binman/etype/blob_named_by_arg.py
tools/binman/etype/cbfs.py
tools/binman/etype/cros_ec_rw.py
tools/binman/etype/fdtmap.py
tools/binman/etype/files.py
tools/binman/etype/fill.py
tools/binman/etype/fmap.py
tools/binman/etype/gbb.py
tools/binman/etype/image_header.py
tools/binman/etype/intel_cmc.py
tools/binman/etype/intel_descriptor.py
tools/binman/etype/intel_fit.py
tools/binman/etype/intel_fit_ptr.py
tools/binman/etype/intel_fsp.py
tools/binman/etype/intel_fsp_m.py
tools/binman/etype/intel_fsp_s.py
tools/binman/etype/intel_fsp_t.py
tools/binman/etype/intel_ifwi.py
tools/binman/etype/intel_me.py
tools/binman/etype/intel_mrc.py
tools/binman/etype/intel_refcode.py
tools/binman/etype/intel_vbt.py
tools/binman/etype/intel_vga.py
tools/binman/etype/powerpc_mpc85xx_bootpg_resetvec.py
tools/binman/etype/section.py
tools/binman/etype/text.py
tools/binman/etype/u_boot.py
tools/binman/etype/u_boot_dtb.py
tools/binman/etype/u_boot_dtb_with_ucode.py
tools/binman/etype/u_boot_elf.py
tools/binman/etype/u_boot_img.py
tools/binman/etype/u_boot_nodtb.py
tools/binman/etype/u_boot_spl.py
tools/binman/etype/u_boot_spl_bss_pad.py
tools/binman/etype/u_boot_spl_dtb.py
tools/binman/etype/u_boot_spl_elf.py
tools/binman/etype/u_boot_spl_nodtb.py
tools/binman/etype/u_boot_spl_with_ucode_ptr.py
tools/binman/etype/u_boot_tpl.py
tools/binman/etype/u_boot_tpl_dtb.py
tools/binman/etype/u_boot_tpl_dtb_with_ucode.py
tools/binman/etype/u_boot_tpl_elf.py
tools/binman/etype/u_boot_tpl_with_ucode_ptr.py
tools/binman/etype/u_boot_ucode.py
tools/binman/etype/u_boot_with_ucode_ptr.py
tools/binman/etype/vblock.py
tools/binman/etype/x86_reset16.py
tools/binman/etype/x86_reset16_spl.py
tools/binman/etype/x86_reset16_tpl.py
tools/binman/etype/x86_start16.py
tools/binman/etype/x86_start16_spl.py
tools/binman/etype/x86_start16_tpl.py
tools/binman/fdt_test.py
tools/binman/fmap_util.py
tools/binman/ftest.py
tools/binman/image.py
tools/binman/image_test.py
tools/binman/main.py [new file with mode: 0755]
tools/binman/state.py
tools/buildman/README
tools/buildman/builder.py
tools/buildman/builderthread.py
tools/buildman/buildman
tools/buildman/buildman.py [deleted file]
tools/buildman/cmdline.py
tools/buildman/control.py
tools/buildman/func_test.py
tools/buildman/main.py [new file with mode: 0755]
tools/buildman/test.py
tools/buildman/toolchain.py
tools/dtoc/dtb_platdata.py
tools/dtoc/dtoc
tools/dtoc/dtoc.py [deleted file]
tools/dtoc/fdt.py
tools/dtoc/fdt_util.py
tools/dtoc/main.py [new file with mode: 0755]
tools/dtoc/test_dtoc.py
tools/dtoc/test_fdt.py
tools/env/fw_env.c
tools/fdtgrep.c
tools/genboardscfg.py
tools/image-host.c
tools/libfdt/fdt_ro.c [new file with mode: 0644]
tools/moveconfig.py
tools/patman/checkpatch.py
tools/patman/command.py
tools/patman/func_test.py
tools/patman/get_maintainer.py
tools/patman/gitutil.py
tools/patman/main.py [new file with mode: 0755]
tools/patman/patchstream.py
tools/patman/patman
tools/patman/patman.py [deleted file]
tools/patman/project.py
tools/patman/series.py
tools/patman/settings.py
tools/patman/terminal.py
tools/patman/test.py
tools/patman/test_util.py
tools/patman/tools.py
tools/patman/tout.py
tools/rmboard.py

index d3e7b4dd0209621d1f4719183fe4beed748e8889..5d9645451d47385beb7808bf52b9ee7a74fc3499 100644 (file)
@@ -1,7 +1,7 @@
 variables:
   windows_vm: vs2017-win2016
   ubuntu_vm: ubuntu-18.04
-  ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20200311-10Apr2020
+  ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20200403-27Apr2020
   # Add '-u 0' options for Azure pipelines, otherwise we get "permission
   # denied" error when it tries to "useradd -m -u 1001 vsts_azpcontainer",
   # since our $(ci_runner_image) user is not root.
@@ -161,7 +161,7 @@ jobs:
           TEST_PY_BD: "sandbox"
         sandbox_clang:
           TEST_PY_BD: "sandbox"
-          OVERRIDE: "-O clang-7"
+          OVERRIDE: "-O clang-10"
         sandbox_spl:
           TEST_PY_BD: "sandbox_spl"
           TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff"
index 08bdf81e74d3c1fe1a4222524969f40d9c943ded..beaf9b9042abaafbd3f07065ac376b229b3418fc 100644 (file)
@@ -2,7 +2,7 @@
 
 # Grab our configured image.  The source for this is found at:
 # https://gitlab.denx.de/u-boot/gitlab-ci-runner
-image: trini/u-boot-gitlab-ci-runner:bionic-20200311-10Apr2020
+image: trini/u-boot-gitlab-ci-runner:bionic-20200403-27Apr2020
 
 # We run some tests in different order, to catch some failures quicker.
 stages:
@@ -181,7 +181,7 @@ sandbox with clang test.py:
   tags: [ 'all' ]
   variables:
     TEST_PY_BD: "sandbox"
-    OVERRIDE: "-O clang-7"
+    OVERRIDE: "-O clang-10"
   <<: *buildman_and_testpy_dfn
 
 sandbox_spl test.py:
diff --git a/.readthedocs.yml b/.readthedocs.yml
new file mode 100644 (file)
index 0000000..f3fb5ed
--- /dev/null
@@ -0,0 +1,19 @@
+# .readthedocs.yml
+# Read the Docs configuration file
+# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
+
+# Required
+version: 2
+
+# Build documentation in the docs/ directory with Sphinx
+sphinx:
+  configuration: docs/conf.py
+
+# Optionally build your docs in additional formats such as PDF and ePub
+formats: []
+
+# Optionally set the version of Python and requirements required to build your docs
+# python:
+#   version: 3.7
+#   install:
+#     - requirements: docs/requirements.txt
index 82e3b9152375e6b77687d745f565db410c4fe04c..fbfaaaff25d84e0e6260e352a7d9fcf5f2fdb7f0 100644 (file)
@@ -10,9 +10,10 @@ language: c
 
 addons:
   apt:
+    update: true
     sources:
-    - ubuntu-toolchain-r-test
-    - llvm-toolchain-bionic-7
+    - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
+      key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
     packages:
     - autopoint
     - cppcheck
@@ -38,7 +39,7 @@ addons:
     - liblz4-tool
     - lzma-alone
     - libisl15
-    - clang-7
+    - clang-10
     - srecord
     - graphviz
     - coreutils
@@ -57,7 +58,7 @@ install:
  - ln -s travis-ci /tmp/uboot-test-hooks/py/`hostname`
  # prepare buildman environment
  - echo -e "[toolchain]\nroot = /usr" > ~/.buildman
- - echo -e "arc = /tmp/arc_gnu_2018.09_prebuilt_uclibc_le_archs_linux_install" >> ~/.buildman
+ - echo -e "arc = /tmp/arc_gnu_2019.09_prebuilt_uclibc_le_archs_linux_install" >> ~/.buildman
  - echo -e "\n[toolchain-alias]\nsh = sh2" >> ~/.buildman
  - echo -e "x86 = i386" >> ~/.buildman;
  - echo -e "riscv = riscv64" >> ~/.buildman;
@@ -86,8 +87,8 @@ before_script:
       ./tools/buildman/buildman --fetch-arch i386;
     fi
   - if [[ "${TOOLCHAIN}" == arc ]]; then
-       wget https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2018.09-release/arc_gnu_2018.09_prebuilt_uclibc_le_archs_linux_install.tar.gz &&
-       tar -C /tmp -xf arc_gnu_2018.09_prebuilt_uclibc_le_archs_linux_install.tar.gz;
+       wget https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2019.09-release/arc_gnu_2019.09_prebuilt_uclibc_le_archs_linux_install.tar.gz &&
+       tar -C /tmp -xf arc_gnu_2019.09_prebuilt_uclibc_le_archs_linux_install.tar.gz;
     fi
   - if [[ "${TOOLCHAIN}" == "nds32" ]]; then
        wget https://github.com/vincentzwc/prebuilt-nds32-toolchain/releases/download/20180521/nds32le-linux-glibc-v3-upstream.tar.gz &&
@@ -499,7 +500,7 @@ matrix:
     - name: "test/py sandbox with clang"
       env:
         - TEST_PY_BD="sandbox"
-          OVERRIDE="-O clang-7"
+          OVERRIDE="-O clang-10"
     - name: "test/py sandbox_spl"
       env:
         - TEST_PY_BD="sandbox_spl"
index b8a4b5058a00f92d061e9823f6842a40273dbb26..68fecb4bac119240642aca1443ff24cc4404dc05 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -512,7 +512,7 @@ dt_h := include/generated/dt.h
 
 no-dot-config-targets := clean clobber mrproper distclean \
                         help %docs check% coccicheck \
-                        ubootversion backup tests check qcheck
+                        ubootversion backup tests check qcheck tcheck
 
 config-targets := 0
 mixed-targets  := 0
@@ -1002,6 +1002,9 @@ append = cat $(filter-out $< $(PHONY), $^) >> $@
 quiet_cmd_pad_cat = CAT     $@
 cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
 
+quiet_cmd_lzma = LZMA    $@
+cmd_lzma = lzma -c -z -k -9 $< > $@
+
 cfg: u-boot.cfg
 
 quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1322,7 +1325,9 @@ endif
 # Boards with more complex image requirements can provide an .its source file
 # or a generator script
 ifneq ($(CONFIG_SPL_FIT_SOURCE),"")
-U_BOOT_ITS = $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
+U_BOOT_ITS := u-boot.its
+$(U_BOOT_ITS): $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
+       $(call if_changed,copy)
 else
 ifneq ($(CONFIG_SPL_FIT_GENERATOR),"")
 U_BOOT_ITS := u-boot.its
@@ -1384,6 +1389,16 @@ else
 UBOOT_BIN := u-boot.bin
 endif
 
+MKIMAGEFLAGS_u-boot-lzma.img = -A $(ARCH) -T standalone -C lzma -O u-boot \
+       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+       -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
+
+u-boot.bin.lzma: u-boot.bin FORCE
+       $(call if_changed,lzma)
+
+u-boot-lzma.img: u-boot.bin.lzma FORCE
+       $(call if_changed,mkimage)
+
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
                $(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
                        $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
@@ -2098,6 +2113,7 @@ help:
        @echo  ''
        @echo  '  check           - Run all automated tests that use sandbox'
        @echo  '  qcheck          - Run quick automated tests that use sandbox'
+       @echo  '  tcheck          - Run quick automated tests on tools'
        @echo  ''
        @echo  'Other generic targets:'
        @echo  '  all             - Build all necessary images depending on configuration'
@@ -2143,6 +2159,9 @@ tests check:
 qcheck:
        $(srctree)/test/run quick
 
+tcheck:
+       $(srctree)/test/run tools
+
 # Documentation targets
 # ---------------------------------------------------------------------------
 DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
index 545fc3e243cdf0b8c1d05237b84fde3432e2309a..6ff201fa81678fab7d0bd70eb4663073dc347520 100644 (file)
@@ -164,18 +164,16 @@ config TARGET_NSIM
 
 config TARGET_AXS101
        bool "Support Synopsys Designware SDP board AXS101"
-       select BOUNCE_BUFFER if CMD_NAND
 
 config TARGET_AXS103
        bool "Support Synopsys Designware SDP board AXS103"
-       select BOUNCE_BUFFER if CMD_NAND
 
 config TARGET_EMSDP
        bool "Synopsys EM Software Development Platform"
        select CPU_ARCEM6
 
 config TARGET_HSDK
-       bool "Support Synpsys HS DevelopmentKit board"
+       bool "Support Synopsys HSDK or HSDK-4xD board"
 
 config TARGET_IOT_DEVKIT
        bool "Synopsys Brite IoT Development kit"
index 4f1e4637ce956922db66b8bbb86c5046f23a96c3..515fe1fe53588b6e5cb269c670be75722103af6e 100644 (file)
@@ -5,7 +5,7 @@ dtb-$(CONFIG_TARGET_AXS103) +=  axs103.dtb
 dtb-$(CONFIG_TARGET_NSIM) +=  nsim.dtb
 dtb-$(CONFIG_TARGET_TB100) +=  abilis_tb100.dtb
 dtb-$(CONFIG_TARGET_EMSDP) +=  emsdp.dtb
-dtb-$(CONFIG_TARGET_HSDK) +=  hsdk.dtb
+dtb-$(CONFIG_TARGET_HSDK) +=  hsdk.dtb hsdk-4xd.dtb
 dtb-$(CONFIG_TARGET_IOT_DEVKIT) +=  iot_devkit.dtb
 
 targets += $(dtb-y)
diff --git a/arch/arc/dts/hsdk-4xd.dts b/arch/arc/dts/hsdk-4xd.dts
new file mode 100644 (file)
index 0000000..b245eea
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Synopsys, Inc. All rights reserved.
+ * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
+ */
+/dts-v1/;
+
+#include "hsdk-common.dtsi"
+
+/ {
+       model = "snps,hsdk-4xd";
+};
diff --git a/arch/arc/dts/hsdk-common.dtsi b/arch/arc/dts/hsdk-common.dtsi
new file mode 100644 (file)
index 0000000..fd4245e
--- /dev/null
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017-2020 Synopsys, Inc. All rights reserved.
+ * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
+ */
+/dts-v1/;
+
+#include "skeleton.dtsi"
+#include "dt-bindings/clock/snps,hsdk-cgu.h"
+#include "dt-bindings/reset/snps,hsdk-reset.h"
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       aliases {
+               console = &uart0;
+               spi0 = &spi0;
+       };
+
+       cpu_card {
+               core_clk: core_clk {
+                       #clock-cells = <0>;
+                       compatible = "fixed-clock";
+                       clock-frequency = <500000000>;
+                       u-boot,dm-pre-reloc;
+               };
+       };
+
+       clk-fmeas {
+               clocks = <&cgu_clk CLK_ARC_PLL>, <&cgu_clk CLK_SYS_PLL>,
+                        <&cgu_clk CLK_TUN_PLL>, <&cgu_clk CLK_DDR_PLL>,
+                        <&cgu_clk CLK_ARC>, <&cgu_clk CLK_HDMI_PLL>,
+                        <&cgu_clk CLK_TUN_TUN>, <&cgu_clk CLK_HDMI>,
+                        <&cgu_clk CLK_SYS_APB>, <&cgu_clk CLK_SYS_AXI>,
+                        <&cgu_clk CLK_SYS_ETH>, <&cgu_clk CLK_SYS_USB>,
+                        <&cgu_clk CLK_SYS_SDIO>, <&cgu_clk CLK_SYS_HDMI>,
+                        <&cgu_clk CLK_SYS_GFX_CORE>, <&cgu_clk CLK_SYS_GFX_DMA>,
+                        <&cgu_clk CLK_SYS_GFX_CFG>, <&cgu_clk CLK_SYS_DMAC_CORE>,
+                        <&cgu_clk CLK_SYS_DMAC_CFG>, <&cgu_clk CLK_SYS_SDIO_REF>,
+                        <&cgu_clk CLK_SYS_SPI_REF>, <&cgu_clk CLK_SYS_I2C_REF>,
+                        <&cgu_clk CLK_SYS_UART_REF>, <&cgu_clk CLK_SYS_EBI_REF>,
+                        <&cgu_clk CLK_TUN_ROM>, <&cgu_clk CLK_TUN_PWM>,
+                        <&cgu_clk CLK_TUN_TIMER>;
+               clock-names = "cpu-pll", "sys-pll",
+                             "tun-pll", "ddr-clk",
+                             "cpu-clk", "hdmi-pll",
+                             "tun-clk", "hdmi-clk",
+                             "apb-clk", "axi-clk",
+                             "eth-clk", "usb-clk",
+                             "sdio-clk", "hdmi-sys-clk",
+                             "gfx-core-clk", "gfx-dma-clk",
+                             "gfx-cfg-clk", "dmac-core-clk",
+                             "dmac-cfg-clk", "sdio-ref-clk",
+                             "spi-clk", "i2c-clk",
+                             "uart-clk", "ebi-clk",
+                             "rom-clk", "pwm-clk",
+                             "timer-clk";
+       };
+
+       cgu_clk: cgu-clk@f0000000 {
+               compatible = "snps,hsdk-cgu-clock";
+               reg = <0xf0000000 0x10>, <0xf00014B8 0x4>;
+               #clock-cells = <1>;
+       };
+
+       cgu_rst: reset-controller@f00008a0 {
+               compatible = "snps,hsdk-reset";
+               #reset-cells = <1>;
+               reg = <0xf00008a0 0x4>, <0xf0000ff0 0x4>;
+       };
+
+       uart0: serial0@f0005000 {
+               compatible = "snps,dw-apb-uart";
+               reg = <0xf0005000 0x1000>;
+               reg-shift = <2>;
+               reg-io-width = <4>;
+       };
+
+       ethernet@f0008000 {
+               #interrupt-cells = <1>;
+               compatible = "snps,arc-dwmac-3.70a";
+               reg = <0xf0008000 0x2000>;
+               phy-mode = "gmii";
+       };
+
+       ehci@0xf0040000 {
+               compatible = "generic-ehci";
+               reg = <0xf0040000 0x100>;
+       };
+
+       ohci@0xf0060000 {
+               compatible = "generic-ohci";
+               reg = <0xf0060000 0x100>;
+       };
+
+       mmcclk_ciu: mmcclk-ciu {
+               compatible = "fixed-clock";
+               /*
+                * DW sdio controller has external ciu clock divider
+                * controlled via register in SDIO IP. Due to its
+                * unexpected default value (it should divide by 1
+                * but it divides by 8) SDIO IP uses wrong clock and
+                * works unstable (see STAR 9001204800)
+                * We switched to the minimum possible value of the
+                * divisor (div-by-2) in HSDK platform code.
+                * So default mmcclk ciu clock is 50000000 Hz.
+                */
+               clock-frequency = <50000000>;
+               #clock-cells = <0>;
+       };
+
+       mmc: mmc0@f000a000 {
+               compatible = "snps,dw-mshc";
+               reg = <0xf000a000 0x400>;
+               bus-width = <4>;
+               fifo-depth = <256>;
+               clocks = <&cgu_clk CLK_SYS_SDIO>, <&mmcclk_ciu>;
+               clock-names = "biu", "ciu";
+               max-frequency = <25000000>;
+       };
+
+       spi0: spi@f0020000 {
+               compatible = "snps,dw-apb-ssi";
+               reg = <0xf0020000 0x1000>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               spi-max-frequency = <4000000>;
+               clocks = <&cgu_clk CLK_SYS_SPI_REF>;
+               clock-names = "spi_clk";
+               cs-gpio = <&cs_gpio 0>;
+               spi_flash@0 {
+                       compatible = "jedec,spi-nor";
+                       reg = <0>;
+                       spi-max-frequency = <4000000>;
+               };
+       };
+
+       cs_gpio: gpio@f00014b0 {
+               compatible = "snps,creg-gpio";
+               reg = <0xf00014b0 0x4>;
+               gpio-controller;
+               #gpio-cells = <1>;
+               gpio-bank-name = "hsdk-spi-cs";
+               gpio-count = <1>;
+               gpio-first-shift = <0>;
+               gpio-bit-per-line = <2>;
+               gpio-activate-val = <2>;
+               gpio-deactivate-val = <3>;
+               gpio-default-val = <1>;
+       };
+};
index cf2ce8a1f6c93506cb5ad00e4320a8d2002b33a7..1a2e3d4322817d051aff266bc8a3f4b675c387ca 100644 (file)
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2017 Synopsys, Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Synopsys, Inc. All rights reserved.
+ * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
  */
 /dts-v1/;
 
-#include "skeleton.dtsi"
-#include "dt-bindings/clock/snps,hsdk-cgu.h"
-#include "dt-bindings/reset/snps,hsdk-reset.h"
+#include "hsdk-common.dtsi"
 
 / {
        model = "snps,hsdk";
-
-       #address-cells = <1>;
-       #size-cells = <1>;
-
-       aliases {
-               console = &uart0;
-               spi0 = &spi0;
-       };
-
-       cpu_card {
-               core_clk: core_clk {
-                       #clock-cells = <0>;
-                       compatible = "fixed-clock";
-                       clock-frequency = <500000000>;
-                       u-boot,dm-pre-reloc;
-               };
-       };
-
-       clk-fmeas {
-               clocks = <&cgu_clk CLK_ARC_PLL>, <&cgu_clk CLK_SYS_PLL>,
-                        <&cgu_clk CLK_TUN_PLL>, <&cgu_clk CLK_DDR_PLL>,
-                        <&cgu_clk CLK_ARC>, <&cgu_clk CLK_HDMI_PLL>,
-                        <&cgu_clk CLK_TUN_TUN>, <&cgu_clk CLK_HDMI>,
-                        <&cgu_clk CLK_SYS_APB>, <&cgu_clk CLK_SYS_AXI>,
-                        <&cgu_clk CLK_SYS_ETH>, <&cgu_clk CLK_SYS_USB>,
-                        <&cgu_clk CLK_SYS_SDIO>, <&cgu_clk CLK_SYS_HDMI>,
-                        <&cgu_clk CLK_SYS_GFX_CORE>, <&cgu_clk CLK_SYS_GFX_DMA>,
-                        <&cgu_clk CLK_SYS_GFX_CFG>, <&cgu_clk CLK_SYS_DMAC_CORE>,
-                        <&cgu_clk CLK_SYS_DMAC_CFG>, <&cgu_clk CLK_SYS_SDIO_REF>,
-                        <&cgu_clk CLK_SYS_SPI_REF>, <&cgu_clk CLK_SYS_I2C_REF>,
-                        <&cgu_clk CLK_SYS_UART_REF>, <&cgu_clk CLK_SYS_EBI_REF>,
-                        <&cgu_clk CLK_TUN_ROM>, <&cgu_clk CLK_TUN_PWM>;
-               clock-names = "cpu-pll", "sys-pll",
-                             "tun-pll", "ddr-clk",
-                             "cpu-clk", "hdmi-pll",
-                             "tun-clk", "hdmi-clk",
-                             "apb-clk", "axi-clk",
-                             "eth-clk", "usb-clk",
-                             "sdio-clk", "hdmi-sys-clk",
-                             "gfx-core-clk", "gfx-dma-clk",
-                             "gfx-cfg-clk", "dmac-core-clk",
-                             "dmac-cfg-clk", "sdio-ref-clk",
-                             "spi-clk", "i2c-clk",
-                             "uart-clk", "ebi-clk",
-                             "rom-clk", "pwm-clk";
-       };
-
-       cgu_clk: cgu-clk@f0000000 {
-               compatible = "snps,hsdk-cgu-clock";
-               reg = <0xf0000000 0x10>, <0xf00014B8 0x4>;
-               #clock-cells = <1>;
-       };
-
-       cgu_rst: reset-controller@f00008a0 {
-               compatible = "snps,hsdk-reset";
-               #reset-cells = <1>;
-               reg = <0xf00008a0 0x4>, <0xf0000ff0 0x4>;
-       };
-
-       uart0: serial0@f0005000 {
-               compatible = "snps,dw-apb-uart";
-               reg = <0xf0005000 0x1000>;
-               reg-shift = <2>;
-               reg-io-width = <4>;
-       };
-
-       ethernet@f0008000 {
-               #interrupt-cells = <1>;
-               compatible = "snps,arc-dwmac-3.70a";
-               reg = <0xf0008000 0x2000>;
-               phy-mode = "gmii";
-       };
-
-       ehci@0xf0040000 {
-               compatible = "generic-ehci";
-               reg = <0xf0040000 0x100>;
-       };
-
-       ohci@0xf0060000 {
-               compatible = "generic-ohci";
-               reg = <0xf0060000 0x100>;
-       };
-
-       mmcclk_ciu: mmcclk-ciu {
-               compatible = "fixed-clock";
-               /*
-                * DW sdio controller has external ciu clock divider
-                * controlled via register in SDIO IP. Due to its
-                * unexpected default value (it should divide by 1
-                * but it divides by 8) SDIO IP uses wrong clock and
-                * works unstable (see STAR 9001204800)
-                * We switched to the minimum possible value of the
-                * divisor (div-by-2) in HSDK platform code.
-                * So default mmcclk ciu clock is 50000000 Hz.
-                */
-               clock-frequency = <50000000>;
-               #clock-cells = <0>;
-       };
-
-       mmc: mmc0@f000a000 {
-               compatible = "snps,dw-mshc";
-               reg = <0xf000a000 0x400>;
-               bus-width = <4>;
-               fifo-depth = <256>;
-               clocks = <&cgu_clk CLK_SYS_SDIO>, <&mmcclk_ciu>;
-               clock-names = "biu", "ciu";
-               max-frequency = <25000000>;
-       };
-
-       spi0: spi@f0020000 {
-               compatible = "snps,dw-apb-ssi";
-               reg = <0xf0020000 0x1000>;
-               #address-cells = <1>;
-               #size-cells = <0>;
-               spi-max-frequency = <4000000>;
-               clocks = <&cgu_clk CLK_SYS_SPI_REF>;
-               clock-names = "spi_clk";
-               cs-gpio = <&cs_gpio 0>;
-               spi_flash@0 {
-                       compatible = "jedec,spi-nor";
-                       reg = <0>;
-                       spi-max-frequency = <4000000>;
-               };
-       };
-
-       cs_gpio: gpio@f00014b0 {
-               compatible = "snps,creg-gpio";
-               reg = <0xf00014b0 0x4>;
-               gpio-controller;
-               #gpio-cells = <1>;
-               gpio-bank-name = "hsdk-spi-cs";
-               gpio-count = <1>;
-               gpio-first-shift = <0>;
-               gpio-bit-per-line = <2>;
-               gpio-activate-val = <2>;
-               gpio-deactivate-val = <3>;
-               gpio-default-val = <1>;
-       };
 };
index fff6591c681d9968df82b90b2977f9fc0eb8d52b..516c14e105b1d90c3702a9382e8185b7a2258316 100644 (file)
@@ -51,6 +51,9 @@
 #define ARC_AUX_DCCM_BASE      0x18    /* DCCM Base Addr ARCv2 */
 #define ARC_AUX_ICCM_BASE      0x208   /* ICCM Base Addr ARCv2 */
 
+/* CSM auxiliary registers */
+#define ARC_AUX_CSM_ENABLE     0x9A0
+
 /* Timer related auxiliary registers */
 #define ARC_AUX_TIMER0_CNT     0x21    /* Timer 0 count */
 #define ARC_AUX_TIMER0_CTRL    0x22    /* Timer 0 control */
 
 /* DSP-extensions related auxiliary registers */
 #define ARC_AUX_DSP_BUILD      0x7A
+#define ARC_AUX_DSP_CTRL       0x59F
 
 /* ARC Subsystems related auxiliary registers */
 #define ARC_AUX_SUBSYS_BUILD   0xF0
index 8c744f5be7f188879ad39751dc3d5c7b3380a3c5..016ae85be23b687ebf8d7ba130e84f950daa2e47 100644 (file)
@@ -61,6 +61,21 @@ ENTRY(_start)
 1:
 #endif
 
+#ifdef CONFIG_ISA_ARCV2
+       ; In case of DSP extension presence in HW some instructions
+       ; (related to integer multiply, multiply-accumulate, and divide
+       ; operation) executes on this DSP execution unit. So their
+       ; execution will depend on dsp configuration register (DSP_CTRL)
+       ; As we want these instructions to execute the same way regardless
+       ; of DSP presence we need to set DSP_CTRL properly.
+       lr      r5, [ARC_AUX_DSP_BUILD]
+       bmsk    r5, r5, 7
+       breq    r5, 0, 1f
+       mov     r5, 0
+       sr      r5, [ARC_AUX_DSP_CTRL]
+1:
+#endif
+
 #ifdef __ARC_UNALIGNED__
        /*
         * Enable handling of unaligned access in the CPU as by default
index e710aa2f94f0c78d31f43e1505db7cf0740127b0..9d2b3bababe232b867d3e34dbdcb2309150add11 100644 (file)
@@ -85,7 +85,7 @@ void cm_basic_init(const struct cm_config * const cfg);
 #define CLKMGR_S10_MAINPLL_VCOCALIB                    0x8c
 /* Periphpll group */
 #define CLKMGR_S10_PERPLL_EN                           0xa4
-#define CLKMGR_S10_PERPLL_BYPASS                       0xac
+#define CLKMGR_S10_PERPLL_BYPASS                       0xb0
 #define CLKMGR_S10_PERPLL_CNTR2CLK                     0xbc
 #define CLKMGR_S10_PERPLL_CNTR3CLK                     0xc0
 #define CLKMGR_S10_PERPLL_CNTR4CLK                     0xc4
index a3ae6030448523eb5dff8ecdaeffe1f7c6324b5c..48e754cc46cec922bd13aa7f1e3ab5714765b278 100644 (file)
@@ -98,6 +98,7 @@ config ARCH_MTMIPS
        select SUPPORTS_CPU_MIPS32_R2
        select SUPPORTS_LITTLE_ENDIAN
        select SYSRESET
+       select SUPPORT_SPL
 
 config ARCH_JZ47XX
        bool "Support Ingenic JZ47xx"
@@ -287,6 +288,60 @@ config MIPS_RELOCATION_TABLE_SIZE
 
          If unsure, leave at the default value.
 
+config RESTORE_EXCEPTION_VECTOR_BASE
+       bool "Restore exception vector base before booting linux kernel"
+       default n
+       help
+         In U-Boot the exception vector base will be moved to top of memory,
+         to be used to display register dump when exception occurs.
+         But some old linux kernel does not honor the base set in CP0_EBASE.
+         A modified exception vector base will cause kernel crash.
+
+         This option will restore the exception vector base to its previous
+         value.
+
+         If unsure, say N.
+
+config OVERRIDE_EXCEPTION_VECTOR_BASE
+       bool "Override the exception vector base to be restored"
+       depends on RESTORE_EXCEPTION_VECTOR_BASE
+       default n
+       help
+         Enable this option if you want to use a different exception vector
+         base rather than the previously saved one.
+
+config NEW_EXCEPTION_VECTOR_BASE
+       hex "New exception vector base"
+       depends on OVERRIDE_EXCEPTION_VECTOR_BASE
+       range 0x80000000 0xbffff000
+       default 0x80000000
+       help
+         The exception vector base to be restored before booting linux kernel
+
+config INIT_STACK_WITHOUT_MALLOC_F
+       bool "Do not reserve malloc space on initial stack"
+       default n
+       help
+         Enable this option if you don't want to reserve malloc space on
+         initial stack. This is useful if the initial stack can't hold large
+         malloc space. Platform should set the malloc_base later when DRAM is
+         ready to use.
+
+config SPL_INIT_STACK_WITHOUT_MALLOC_F
+       bool "Do not reserve malloc space on initial stack in SPL"
+       default n
+       help
+         Enable this option if you don't want to reserve malloc space on
+         initial stack. This is useful if the initial stack can't hold large
+         malloc space. Platform should set the malloc_base later when DRAM is
+         ready to use.
+
+config SPL_LOADER_SUPPORT
+       bool
+       default n
+       help
+         Enable this option if you want to use SPL loaders without DM enabled.
+
 endmenu
 
 menu "OS boot interface"
@@ -389,6 +444,15 @@ config MIPS_INIT_STACK_IN_SRAM
          lowlevel_init. Thus lowlevel_init does not need to be implemented
          in assembler.
 
+config MIPS_SRAM_INIT
+       bool
+       default n
+       depends on MIPS_INIT_STACK_IN_SRAM
+       help
+         Select this if the SRAM for initial stack needs to be initialized
+         before it can be used. If enabled, a function mips_sram_init() will
+         be called just before setup_stack_gd.
+
 config SYS_DCACHE_SIZE
        int
        default 0
index 1d21b2324a7658a209a0bc3d63a25004c8e74b60..6de9a2f36243e6e5a815a3de0a2724e039dfcf0b 100644 (file)
@@ -59,7 +59,8 @@
                sp, sp, GD_SIZE         # reserve space for gd
        and     sp, sp, t0              # force 16 byte alignment
        move    k0, sp                  # save gd pointer
-#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
+    !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
        li      t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
        PTR_SUBU \
                sp, sp, t2              # reserve space for early malloc
        move    t0, k0
 1:
        PTR_S   zero, 0(t0)
+       PTR_ADDIU t0, PTRSIZE
        blt     t0, t1, 1b
-        PTR_ADDIU t0, PTRSIZE
+        nop
 
-#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
+    !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
        PTR_S   sp, GD_MALLOC_BASE(k0)  # gd->malloc_base offset
 #endif
        .endm
@@ -216,6 +219,13 @@ wr_done:
 #endif
 
 #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
+#ifdef CONFIG_MIPS_SRAM_INIT
+       /* Initialize the SRAM first */
+       PTR_LA  t9, mips_sram_init
+       jalr    t9
+        nop
+#endif
+
        /* Set up initial stack and global data */
        setup_stack_gd
 
index d08d6222c4ab8d6859767104b3a1a03f9a998899..28ea4f2a481dea61e513ef5956d5724bb1413c90 100644 (file)
@@ -27,7 +27,7 @@ SECTIONS
                *(SORT_BY_ALIGNMENT(.sdata*))
        } > .spl_mem
 
-#ifdef CONFIG_SPL_DM
+#if defined(CONFIG_SPL_DM) || defined(CONFIG_SPL_LOADER_SUPPORT)
        . = ALIGN(4);
        .u_boot_list : {
                KEEP(*(SORT(.u_boot_list*)));
@@ -37,6 +37,8 @@ SECTIONS
        . = ALIGN(4);
        __image_copy_end = .;
 
+       _image_binary_end = .;
+
        .bss (NOLOAD) : {
                __bss_start = .;
                *(.bss*)
index c9d75596f250f83206bff1cafcb209ac59d36c20..f711e9fb59c14d57b8ee591126245e30b226369c 100644 (file)
@@ -17,11 +17,13 @@ dtb-$(CONFIG_BOARD_COMTREND_CT5361) += comtrend,ct-5361.dtb
 dtb-$(CONFIG_BOARD_COMTREND_VR3032U) += comtrend,vr-3032u.dtb
 dtb-$(CONFIG_BOARD_COMTREND_WAP5813N) += comtrend,wap-5813n.dtb
 dtb-$(CONFIG_BOARD_HUAWEI_HG556A) += huawei,hg556a.dtb
+dtb-$(CONFIG_BOARD_MT7628_RFB) += mediatek,mt7628-rfb.dtb
 dtb-$(CONFIG_BOARD_NETGEAR_CG3100D) += netgear,cg3100d.dtb
 dtb-$(CONFIG_BOARD_NETGEAR_DGND3700V2) += netgear,dgnd3700v2.dtb
 dtb-$(CONFIG_BOARD_SAGEM_FAST1704) += sagem,f@st1704.dtb
 dtb-$(CONFIG_BOARD_SFR_NB4_SER) += sfr,nb4-ser.dtb
 dtb-$(CONFIG_BOARD_TPLINK_WDR4300) += tplink_wdr4300.dtb
+dtb-$(CONFIG_BOARD_VOCORE2) += vocore_vocore2.dtb
 dtb-$(CONFIG_TARGET_JZ4780_CI20) += ci20.dtb
 dtb-$(CONFIG_SOC_LUTON) += luton_pcb090.dtb luton_pcb091.dtb
 dtb-$(CONFIG_SOC_OCELOT) += ocelot_pcb120.dtb ocelot_pcb123.dtb
diff --git a/arch/mips/dts/mediatek,mt7628-rfb.dts b/arch/mips/dts/mediatek,mt7628-rfb.dts
new file mode 100644 (file)
index 0000000..6ff36da
--- /dev/null
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+/dts-v1/;
+
+#include "mt7628a.dtsi"
+
+/ {
+       compatible = "mediatek,mt7628-rfb", "ralink,mt7628a-soc";
+       model = "MediaTek MT7628 RFB";
+
+       aliases {
+               serial0 = &uart0;
+               spi0 = &spi0;
+       };
+
+       chosen {
+               stdout-path = &uart0;
+       };
+};
+
+&pinctrl {
+       state_default: pin_state {
+               pleds {
+                       groups = "p0led", "p1led", "p2led", "p3led", "p4led";
+                       function = "led";
+               };
+       };
+};
+
+&uart0 {
+       status = "okay";
+};
+
+&spi0 {
+       status = "okay";
+       num-cs = <2>;
+
+       spi-flash@0 {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               compatible = "jedec,spi-nor";
+               spi-max-frequency = <25000000>;
+               reg = <0>;
+       };
+};
+
+&eth {
+       mediatek,wan-port = <0>;
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&ephy_router_mode>;
+};
+
+&mmc {
+       bus-width = <4>;
+       cap-sd-highspeed;
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&sd_router_mode>;
+
+       status = "okay";
+};
diff --git a/arch/mips/dts/mt7628-u-boot.dtsi b/arch/mips/dts/mt7628-u-boot.dtsi
new file mode 100644 (file)
index 0000000..eea5dc6
--- /dev/null
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+&palmbus {
+       u-boot,dm-pre-reloc;
+};
+
+&reboot {
+       u-boot,dm-pre-reloc;
+};
+
+&clkctrl {
+       u-boot,dm-pre-reloc;
+};
+
+&rstctrl {
+       u-boot,dm-pre-reloc;
+};
+
+&pinctrl {
+       u-boot,dm-pre-reloc;
+};
+
+&uart0 {
+       u-boot,dm-pre-reloc;
+};
+
+&uart1 {
+       u-boot,dm-pre-reloc;
+};
+
+&uart2 {
+       u-boot,dm-pre-reloc;
+};
index 76a80c8952dfa870face823ddbdf1d4c19b13f46..6baa63add330dca738750e4f1f0b39cc2888e891 100644 (file)
@@ -33,7 +33,7 @@
                #clock-cells = <0>;
        };
 
-       palmbus@10000000 {
+       palmbus: palmbus@10000000 {
                compatible = "palmbus", "simple-bus";
                reg = <0x10000000 0x200000>;
                ranges = <0x0 0x10000000 0x1FFFFF>;
                        reg = <0x0 0x100>;
                };
 
-               syscon-reboot {
-                       compatible = "syscon-reboot";
-                       regmap = <&sysc>;
-                       offset = <0x34>;
-                       mask = <0x1>;
+               reboot: resetctl-reboot {
+                       compatible = "resetctl-reboot";
+
+                       resets = <&rstctrl MT7628_SYS_RST>;
+                       reset-names = "sysreset";
                };
 
                clkctrl: clkctrl@0x2c {
                                function = "uart2";
                        };
 
+                       uart2_pwm_pins: uart2_pwm_pins {
+                               groups = "spis";
+                               function = "pwm_uart2";
+                       };
+
                        i2c_pins: i2c_pins {
                                groups = "i2c";
                                function = "i2c";
diff --git a/arch/mips/dts/vocore_vocore2.dts b/arch/mips/dts/vocore_vocore2.dts
new file mode 100644 (file)
index 0000000..3502e4b
--- /dev/null
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Mauro Condarelli <mc5686@mclink.it>
+ */
+
+/dts-v1/;
+
+#include "mt7628a.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+
+/ {
+       compatible = "vocore,vocore2", "ralink,mt7628a-soc";
+       model = "VoCore2";
+
+       aliases {
+               serial0 = &uart2;
+               spi0 = &spi0;
+       };
+
+       memory@0 {
+               device_type = "memory";
+               reg = <0x0 0x08000000>;
+       };
+       leds {
+               compatible = "gpio-leds";
+
+               power {
+                       label = "vocore:power";
+                       gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
+                       default-state = "off";
+               };
+       };
+
+       chosen {
+               bootargs = "console=ttyS2,115200";
+               stdout-path = &uart2;
+       };
+};
+
+&pinctrl {
+       state_default: pin_state {
+               p0led {
+                       groups = "p0led_a";
+                       function = "led";
+               };
+       };
+};
+
+&uart2 {
+       status = "okay";
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&uart2_pwm_pins>;
+};
+
+&spi0 {
+       status = "okay";
+       nor0: spi-flash@0 {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               compatible = "jedec,spi-nor";
+               spi-max-frequency = <25000000>;
+               reg = <0>;
+       };
+};
+
+&eth {
+       status = "okay";
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&ephy_iot_mode>;
+       mediatek,poll-link-phy = <0>;
+};
+
+&mmc {
+       status = "okay";
+
+       bus-width = <4>;
+       max-frequency = <48000000>;
+       cap-sd-highspeed;
+       cap-mmc-highspeed;
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&sd_iot_mode>;
+};
index 7b4ad083ba0fae843404777b581d517af87916d0..4c30fab8717be76e9018ac29d66668baab17099e 100644 (file)
@@ -27,6 +27,9 @@ struct arch_global_data {
 #ifdef CONFIG_MIPS_L2_CACHE
        unsigned short l2_line_size;
 #endif
+#ifdef CONFIG_ARCH_MTMIPS
+       unsigned long timer_freq;
+#endif
 };
 
 #include <asm-generic/global_data.h>
index 88438b9576bbcf8bb9a4520d34c091e62d5d0b6e..8b37cc4029c7c477f3c5d20a77f33bf2dc1b7b33 100644 (file)
@@ -9,4 +9,6 @@ void except_vec_ejtag_debug(void);
 
 int arch_misc_init(void);
 
+void trap_restore(void);
+
 #endif /* _U_BOOT_MIPS_H_ */
index 24a72d9c973966a522fa73aa0c0cad421caf0853..9ee1fcb5c7024046cbb20041f6796665fb821bda 100644 (file)
@@ -12,5 +12,6 @@ obj-y += traps.o
 
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_CMD_GO) += boot.o
+obj-$(CONFIG_SPL_BUILD) += spl.o
 
 lib-$(CONFIG_USE_PRIVATE_LIBGCC) += ashldi3.o ashrdi3.o lshrdi3.o
index 8c0d7672f24ceab122c70e54236748f366b4eb25..f1db6d23b84e091fa098baada15e5f12ac3228a6 100644 (file)
@@ -294,6 +294,9 @@ static void boot_jump_linux(bootm_headers_t *images)
        bootstage_report();
 #endif
 
+       if (CONFIG_IS_ENABLED(RESTORE_EXCEPTION_VECTOR_BASE))
+               trap_restore();
+
        if (images->ft_len)
                kernel(-2, (ulong)images->ft_addr, 0, 0);
        else
diff --git a/arch/mips/lib/spl.c b/arch/mips/lib/spl.c
new file mode 100644 (file)
index 0000000..7ba3e53
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Stefan Roese <sr@denx.de>
+ */
+
+#include <common.h>
+#include <cpu_func.h>
+#include <spl.h>
+
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{
+       typedef void __noreturn (*image_entry_noargs_t)(void);
+       image_entry_noargs_t image_entry =
+               (image_entry_noargs_t)spl_image->entry_point;
+
+       /* Flush cache before jumping to application */
+       flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+
+       debug("image entry point: 0x%lx\n", spl_image->entry_point);
+       image_entry();
+}
index b8568c00fed53034ce48c6a368c6ebfd28bc392b..8fff7541e3c1e59d8cc8f709db01a713149cc923 100644 (file)
@@ -20,6 +20,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static unsigned long saved_ebase;
+
 static void show_regs(const struct pt_regs *regs)
 {
        const int field = 2 * sizeof(unsigned long);
@@ -102,7 +104,24 @@ void trap_init(ulong reloc_addr)
        set_handler(0x180, &except_vec3_generic, 0x80);
        set_handler(0x280, &except_vec_ejtag_debug, 0x80);
 
+       saved_ebase = read_c0_ebase() & 0xfffff000;
+
        write_c0_ebase(ebase);
        clear_c0_status(ST0_BEV);
        execution_hazard_barrier();
 }
+
+void trap_restore(void)
+{
+       set_c0_status(ST0_BEV);
+       execution_hazard_barrier();
+
+#ifdef CONFIG_OVERRIDE_EXCEPTION_VECTOR_BASE
+       write_c0_ebase(CONFIG_NEW_EXCEPTION_VECTOR_BASE & 0xfffff000);
+#else
+       write_c0_ebase(saved_ebase);
+#endif
+
+       clear_c0_status(ST0_BEV);
+       execution_hazard_barrier();
+}
index c8dcf19c0de2381aa4ce77b4b393a615cbcb5088..737de2cb8e28b212e75f1ed2d53b43fcfa65b85b 100644 (file)
@@ -7,14 +7,52 @@ config SYS_MALLOC_F_LEN
 config SYS_SOC
        default "mt7628" if SOC_MT7628
 
+config SYS_DCACHE_SIZE
+       default 32768
+
+config SYS_DCACHE_LINE_SIZE
+       default 32
+
+config SYS_ICACHE_SIZE
+       default 65536
+
+config SYS_ICACHE_LINE_SIZE
+       default 32
+
+config SYS_TEXT_BASE
+       default 0x9c000000 if !SPL
+       default 0x80200000 if SPL
+
+config SPL_TEXT_BASE
+       default 0x9c000000
+
+config SPL_PAYLOAD
+       default "u-boot-lzma.img" if SPL_LZMA
+
+config BUILD_TARGET
+       default "u-boot-with-spl.bin" if SPL
+
 choice
        prompt "MediaTek MIPS SoC select"
 
 config SOC_MT7628
        bool "MT7628"
        select MIPS_L1_CACHE_SHIFT_5
+       select MIPS_INIT_STACK_IN_SRAM
+       select MIPS_SRAM_INIT
+       select SYS_MIPS_CACHE_INIT_RAM_LOAD
        select PINCTRL_MT7628
        select MTK_SERIAL
+       select SYSRESET_RESETCTL
+       select SPL_SEPARATE_BSS if SPL
+       select SPL_INIT_STACK_WITHOUT_MALLOC_F if SPL
+       select SPL_LOADER_SUPPORT if SPL
+       select SPL_OF_CONTROL if SPL_DM
+       select SPL_SIMPLE_BUS if SPL_DM
+       select SPL_DM_SERIAL if SPL_DM
+       select SPL_CLK if SPL_DM && SPL_SERIAL_SUPPORT
+       select SPL_SYSRESET if SPL_DM
+       select SPL_OF_LIBFDT if SPL_OF_CONTROL
        help
          This supports MediaTek MT7628/MT7688.
 
@@ -27,7 +65,6 @@ config BOARD_GARDENA_SMART_GATEWAY_MT7688
        bool "GARDENA smart Gateway"
        depends on SOC_MT7628
        select BOARD_LATE_INIT
-       select SUPPORTS_BOOT_RAM
        help
          GARDENA smart Gateway boards have a MT7688 SoC with 128 MiB of RAM
          and 8 MiB of flash (SPI NOR) and additional SPI NAND storage.
@@ -35,7 +72,6 @@ config BOARD_GARDENA_SMART_GATEWAY_MT7688
 config BOARD_LINKIT_SMART_7688
        bool "LinkIt Smart 7688"
        depends on SOC_MT7628
-       select SUPPORTS_BOOT_RAM
        help
          Seeed LinkIt Smart 7688 boards have a MT7688 SoC with 128 MiB of RAM
          and 32 MiB of flash (SPI).
@@ -43,96 +79,36 @@ config BOARD_LINKIT_SMART_7688
          ethernet ports, 1 USB port, 1 UART, GPIO buttons and LEDs, and
          a MT7688 (PCIe).
 
-endchoice
-
-choice
-       prompt "Boot mode"
-
-config BOOT_RAM
-       bool "RAM boot"
-       depends on SUPPORTS_BOOT_RAM
-       help
-         This builds an image that is linked to a RAM address. It can be used
-         for booting from CFE via TFTP using an ELF image, but it can also be
-         booted from RAM by other bootloaders using a BIN image.
-
-config BOOT_ROM
-       bool "ROM boot"
-       depends on SUPPORTS_BOOT_RAM
-       help
-         This builds an image that is linked to a ROM address. It can be
-         used as main bootloader image which is programmed onto the onboard
-         flash storage (SPI NOR).
-
-endchoice
-
-choice
-       prompt "DDR2 size"
-
-config ONBOARD_DDR2_SIZE_256MBIT
-       bool "256MBit (32MByte) total size"
-       depends on BOOT_ROM
-       help
-         Use 256MBit (32MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_512MBIT
-       bool "512MBit (64MByte) total size"
-       depends on BOOT_ROM
-       help
-         Use 512MBit (64MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_1024MBIT
-       bool "1024MBit (128MByte) total size"
-       depends on BOOT_ROM
-       help
-         Use 1024MBit (128MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_2048MBIT
-       bool "2048MBit (256MByte) total size"
-       depends on BOOT_ROM
-       help
-         Use 2048MBit (256MByte) of DDR total size
-
-endchoice
-
-choice
-       prompt "DDR2 chip width"
-
-config ONBOARD_DDR2_CHIP_WIDTH_8BIT
-       bool "8bit DDR chip width"
-       depends on BOOT_ROM
+config BOARD_MT7628_RFB
+       bool "MediaTek MT7628 RFB"
+       depends on SOC_MT7628
        help
-         Use DDR chips with 8bit width
+         The reference design of MT7628. The board has 128 MiB DDR2, 8 MiB
+         SPI-NOR flash, 1 built-in switch with 5 ports, 1 UART, 1 USB host,
+         1 SDXC, 1 PCIe socket and JTAG pins.
 
-config ONBOARD_DDR2_CHIP_WIDTH_16BIT
-       bool "16bit DDR chip width"
-       depends on BOOT_ROM
+config BOARD_VOCORE2
+       bool "VoCore2"
+       depends on SOC_MT7628
+       select SPL_SERIAL_SUPPORT
+       select SPL_UART2_SPIS_PINMUX
        help
-         Use DDR chips with 16bit width
+         VoCore VoCore2 board has a MT7628 SoC with 128 MiB of RAM
+         and 16 MiB of flash (SPI).
 
 endchoice
 
-choice
-       prompt "DDR2 bus width"
-
-config ONBOARD_DDR2_BUS_WIDTH_16BIT
-       bool "16bit DDR bus width"
-       depends on BOOT_ROM
+config SPL_UART2_SPIS_PINMUX
+       bool "Use alternative pinmux for UART2 in SPL stage"
+       depends on SPL_SERIAL_SUPPORT
+       default n
        help
-         Use 16bit DDR bus width
-
-config ONBOARD_DDR2_BUS_WIDTH_32BIT
-       bool "32bit DDR bus width"
-       depends on BOOT_ROM
-       help
-         Use 32bit DDR bus width
-
-endchoice
-
-config SUPPORTS_BOOT_RAM
-       bool
+         Select this if the UART2 of your board is connected to GPIO 16/17
+         (shared with SPIS) rather than the usual GPIO 20/21.
 
 source "board/gardena/smart-gateway-mt7688/Kconfig"
+source "board/mediatek/mt7628/Kconfig"
 source "board/seeed/linkit-smart-7688/Kconfig"
+source "board/vocore/vocore2/Kconfig"
 
 endmenu
index 1f3e65e8a5542e35219433e45338aefe69115454..a7e6a6630470d6f9d097a1068944d983aa70cde4 100644 (file)
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y += cpu.o
+obj-y += ddr_init.o
+obj-y += ddr_cal.o
+obj-$(CONFIG_SPL_BUILD) += spl.o
 
-ifndef CONFIG_SKIP_LOWLEVEL_INIT
-obj-y += ddr_calibrate.o
-obj-y += lowlevel_init.o
-endif
+obj-$(CONFIG_SOC_MT7628) += mt7628/
index 8976ef57c7031c0a4f9c07d171bbcc92a56c4628..459a9673ebe8054b419032f9948b6c8aec1cf3d6 100644 (file)
@@ -4,69 +4,17 @@
  */
 
 #include <common.h>
-#include <dm.h>
-#include <init.h>
 #include <malloc.h>
-#include <ram.h>
-#include <wdt.h>
-#include <asm/io.h>
 #include <linux/io.h>
 #include <linux/sizes.h>
-#include "mt76xx.h"
 
-#define STR_LEN                        6
-
-#ifdef CONFIG_BOOT_ROM
-int mach_cpu_init(void)
-{
-       ddr_calibrate();
-
-       return 0;
-}
-#endif
+DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
+#ifdef CONFIG_SKIP_LOWLEVEL_INIT
        gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, SZ_256M);
-
-       return 0;
-}
-
-int print_cpuinfo(void)
-{
-       static const char * const boot_str[] = { "PLL (3-Byte SPI Addr)",
-                                                "PLL (4-Byte SPI Addr)",
-                                                "XTAL (3-Byte SPI Addr)",
-                                                "XTAL (4-Byte SPI Addr)" };
-       const void *blob = gd->fdt_blob;
-       void __iomem *sysc_base;
-       char buf[STR_LEN + 1];
-       fdt_addr_t base;
-       fdt_size_t size;
-       char *str;
-       int node;
-       u32 val;
-
-       /* Get system controller base address */
-       node = fdt_node_offset_by_compatible(blob, -1, "ralink,mt7620a-sysc");
-       if (node < 0)
-               return -FDT_ERR_NOTFOUND;
-
-       base = fdtdec_get_addr_size_auto_noparent(blob, node, "reg",
-                                                 0, &size, true);
-       if (base == FDT_ADDR_T_NONE)
-               return -EINVAL;
-
-       sysc_base = ioremap_nocache(base, size);
-
-       str = (char *)sysc_base + MT76XX_CHIPID_OFFS;
-       snprintf(buf, STR_LEN + 1, "%s", str);
-       val = readl(sysc_base + MT76XX_CHIP_REV_ID_OFFS);
-       printf("CPU:   %-*s Rev %ld.%ld - ", STR_LEN, buf,
-              (val & GENMASK(11, 8)) >> 8, val & GENMASK(3, 0));
-
-       val = (readl(sysc_base + MT76XX_SYSCFG0_OFFS) & GENMASK(3, 1)) >> 1;
-       printf("Boot from %s\n", boot_str[val]);
+#endif
 
        return 0;
 }
diff --git a/arch/mips/mach-mtmips/ddr_cal.c b/arch/mips/mach-mtmips/ddr_cal.c
new file mode 100644 (file)
index 0000000..71a53c3
--- /dev/null
@@ -0,0 +1,205 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <asm/addrspace.h>
+#include <asm/cacheops.h>
+#include <linux/bitops.h>
+#include <linux/io.h>
+#include <mach/mc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define COARSE_MIN_START       6
+#define FINE_MIN_START         15
+#define COARSE_MAX_START       7
+#define FINE_MAX_START         0
+
+#define NUM_OF_CACHELINE       128
+#define TEST_PAT_SIZE          (NUM_OF_CACHELINE * CONFIG_SYS_CACHELINE_SIZE)
+
+#define INIT_DQS_VAL           ((7 << DQS1_DELAY_COARSE_TUNING_S) | \
+                               (4 << DQS1_DELAY_FINE_TUNING_S) | \
+                               (7 << DQS0_DELAY_COARSE_TUNING_S) | \
+                               (4 << DQS0_DELAY_FINE_TUNING_S))
+
+static inline void pref_op(int op, const volatile void *addr)
+{
+       __asm__ __volatile__("pref %0, 0(%1)" : : "i" (op), "r" (addr));
+}
+
+static inline bool dqs_test_error(void __iomem *memc, u32 memsize, u32 dqsval,
+                                 u32 bias)
+{
+       u32 *nca, *ca;
+       u32 off;
+       int i;
+
+       for (off = 0; off < memsize - TEST_PAT_SIZE; off += (memsize >> 6)) {
+               nca = (u32 *)KSEG1ADDR(off);
+               ca = (u32 *)KSEG0ADDR(off);
+
+               writel(INIT_DQS_VAL, memc + MEMCTL_DDR_DQS_DLY_REG);
+               wmb();
+
+               for (i = 0; i < TEST_PAT_SIZE / sizeof(u32); i++)
+                       ca[i] = 0x1f1f1f1f;
+
+               for (i = 0; i < TEST_PAT_SIZE / sizeof(u32); i++)
+                       nca[i] = (u32)nca + i + bias;
+
+               writel(dqsval, memc + MEMCTL_DDR_DQS_DLY_REG);
+               wmb();
+
+               for (i = 0; i < TEST_PAT_SIZE; i += CONFIG_SYS_CACHELINE_SIZE)
+                       mips_cache(HIT_INVALIDATE_D, (u8 *)ca + i);
+               wmb();
+
+               for (i = 0; i < TEST_PAT_SIZE; i += CONFIG_SYS_CACHELINE_SIZE)
+                       pref_op(0, (u8 *)ca + i);
+
+               for (i = 0; i < TEST_PAT_SIZE / sizeof(u32); i++) {
+                       if (ca[i] != (u32)nca + i + bias)
+                               return true;
+               }
+       }
+
+       return false;
+}
+
+static inline int dqs_find_max(void __iomem *memc, u32 memsize, int initval,
+                              int maxval, int shift, u32 regval)
+{
+       int fieldval;
+       u32 dqsval;
+
+       for (fieldval = initval; fieldval <= maxval; fieldval++) {
+               dqsval = regval | (fieldval << shift);
+               if (dqs_test_error(memc, memsize, dqsval, 3))
+                       return max(fieldval - 1, initval);
+       }
+
+       return maxval;
+}
+
+static inline int dqs_find_min(void __iomem *memc, u32 memsize, int initval,
+                              int minval, int shift, u32 regval)
+{
+       int fieldval;
+       u32 dqsval;
+
+       for (fieldval = initval; fieldval >= minval; fieldval--) {
+               dqsval = regval | (fieldval << shift);
+               if (dqs_test_error(memc, memsize, dqsval, 1))
+                       return min(fieldval + 1, initval);
+       }
+
+       return minval;
+}
+
+void ddr_calibrate(void __iomem *memc, u32 memsize, u32 bw)
+{
+       u32 dqs_coarse_min, dqs_coarse_max, dqs_coarse_val;
+       u32 dqs_fine_min, dqs_fine_max, dqs_fine_val;
+       u32 dqs_coarse_min_limit, dqs_fine_min_limit;
+       u32 dlls, dqs_dll, ddr_cfg2_reg;
+       u32 dqs_dly_tmp, dqs_dly, test_dqs, shift;
+       u32 rem, mask;
+       int i;
+
+       /* Disable Self-refresh */
+       clrbits_32(memc + MEMCTL_DDR_SELF_REFRESH_REG, SR_AUTO_EN);
+
+       /* Save DDR_CFG2 and modify its DQS gating window */
+       ddr_cfg2_reg = readl(memc + MEMCTL_DDR_CFG2_REG);
+       mask = DQS0_GATING_WINDOW_M;
+       if (bw == IND_SDRAM_WIDTH_16BIT)
+               mask |= DQS1_GATING_WINDOW_M;
+       clrbits_32(memc + MEMCTL_DDR_CFG2_REG, mask);
+
+       /* Get minimum available DQS value */
+       dlls = readl(memc + MEMCTL_DLL_DBG_REG);
+       dlls = (dlls & MST_DLY_SEL_M) >> MST_DLY_SEL_S;
+
+       dqs_dll = dlls >> 4;
+       if (dqs_dll <= 8)
+               dqs_coarse_min_limit = 8 - dqs_dll;
+       else
+               dqs_coarse_min_limit = 0;
+
+       dqs_dll = dlls & 0xf;
+       if (dqs_dll <= 8)
+               dqs_fine_min_limit = 8 - dqs_dll;
+       else
+               dqs_fine_min_limit = 0;
+
+       /* Initial DQS register value */
+       dqs_dly = INIT_DQS_VAL;
+
+       /* Calibrate DQS0 and/or DQS1 */
+       for (i = 0; i < bw; i++) {
+               shift = i * 8;
+               dqs_dly &= ~(0xff << shift);
+
+               /* Find maximum DQS coarse-grain */
+               dqs_dly_tmp = dqs_dly | (0xf << shift);
+               dqs_coarse_max = dqs_find_max(memc, memsize, COARSE_MAX_START,
+                                             0xf, 4 + shift, dqs_dly_tmp);
+
+               /* Find maximum DQS fine-grain */
+               dqs_dly_tmp = dqs_dly | (dqs_coarse_max << (4 + shift));
+               test_dqs = dqs_find_max(memc, memsize, FINE_MAX_START, 0xf,
+                                       shift, dqs_dly_tmp);
+
+               if (test_dqs == FINE_MAX_START) {
+                       dqs_coarse_max--;
+                       dqs_fine_max = 0xf;
+               } else {
+                       dqs_fine_max = test_dqs - 1;
+               }
+
+               /* Find minimum DQS coarse-grain */
+               dqs_dly_tmp = dqs_dly;
+               dqs_coarse_min = dqs_find_min(memc, memsize, COARSE_MIN_START,
+                                             dqs_coarse_min_limit, 4 + shift,
+                                             dqs_dly_tmp);
+
+               /* Find minimum DQS fine-grain */
+               dqs_dly_tmp = dqs_dly | (dqs_coarse_min << (4 + shift));
+               test_dqs = dqs_find_min(memc, memsize, FINE_MIN_START,
+                                       dqs_fine_min_limit, shift, dqs_dly_tmp);
+
+               if (test_dqs == FINE_MIN_START + 1) {
+                       dqs_coarse_min++;
+                       dqs_fine_min = 0;
+               } else {
+                       dqs_fine_min = test_dqs;
+               }
+
+               /* Calculate central DQS coarse/fine value */
+               dqs_coarse_val = (dqs_coarse_max + dqs_coarse_min) >> 1;
+               rem = (dqs_coarse_max + dqs_coarse_min) % 2;
+
+               dqs_fine_val = (rem * 4) + ((dqs_fine_max + dqs_fine_min) >> 1);
+               if (dqs_fine_val >= 0x10) {
+                       dqs_coarse_val++;
+                       dqs_fine_val -= 8;
+               }
+
+               /* Save current DQS value */
+               dqs_dly |= ((dqs_coarse_val << 4) | dqs_fine_val) << shift;
+       }
+
+       /* Set final DQS value */
+       writel(dqs_dly, memc + MEMCTL_DDR_DQS_DLY_REG);
+
+       /* Restore DDR_CFG2 */
+       writel(ddr_cfg2_reg, memc + MEMCTL_DDR_CFG2_REG);
+
+       /* Enable Self-refresh */
+       setbits_32(memc + MEMCTL_DDR_SELF_REFRESH_REG, SR_AUTO_EN);
+}
diff --git a/arch/mips/mach-mtmips/ddr_calibrate.c b/arch/mips/mach-mtmips/ddr_calibrate.c
deleted file mode 100644 (file)
index 3cd4408..0000000
+++ /dev/null
@@ -1,309 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2018 Stefan Roese <sr@denx.de>
- *
- * This code is mostly based on the code extracted from this MediaTek
- * github repository:
- *
- * https://github.com/MediaTek-Labs/linkit-smart-uboot.git
- *
- * I was not able to find a specific license or other developers
- * copyrights here, so I can't add them here.
- *
- * Most functions in this file are copied from the MediaTek U-Boot
- * repository. Without any documentation, it was impossible to really
- * implement this differently. So its mostly a cleaned-up version of
- * the original code, with only support for the MT7628 / MT7688 SoC.
- */
-
-#include <common.h>
-#include <cpu_func.h>
-#include <linux/io.h>
-#include <asm/cacheops.h>
-#include <asm/io.h>
-#include "mt76xx.h"
-
-#define NUM_OF_CACHELINE       128
-#define MIN_START              6
-#define MIN_FINE_START         0xf
-#define MAX_START              7
-#define MAX_FINE_START         0x0
-
-#define CPU_FRAC_DIV           1
-
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_256MBIT)
-#define DRAM_BUTTOM 0x02000000
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_512MBIT)
-#define DRAM_BUTTOM 0x04000000
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_1024MBIT)
-#define DRAM_BUTTOM 0x08000000
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_2048MBIT)
-#define DRAM_BUTTOM 0x10000000
-#endif
-
-static inline void cal_memcpy(void *src, void *dst, u32 size)
-{
-       u8 *psrc = (u8 *)src;
-       u8 *pdst = (u8 *)dst;
-       int i;
-
-       for (i = 0; i < size; i++, psrc++, pdst++)
-               *pdst = *psrc;
-}
-
-static inline void cal_memset(void *src, u8 pat, u32 size)
-{
-       u8 *psrc = (u8 *)src;
-       int i;
-
-       for (i = 0; i < size; i++, psrc++)
-               *psrc = pat;
-}
-
-#define pref_op(hint, addr)                                            \
-       __asm__ __volatile__(                                           \
-               ".set   push\n"                                         \
-               ".set   noreorder\n"                                    \
-               "pref   %0, %1\n"                                       \
-               ".set   pop\n"                                          \
-               :                                                       \
-               : "i" (hint), "R" (*(u8 *)(addr)))
-
-static inline void cal_patgen(u32 start_addr, u32 size, u32 bias)
-{
-       u32 *addr = (u32 *)start_addr;
-       int i;
-
-       for (i = 0; i < size; i++)
-               addr[i] = start_addr + i + bias;
-}
-
-static inline int test_loop(int k, int dqs, u32 test_dqs, u32 *coarse_dqs,
-                           u32 offs, u32 pat, u32 val)
-{
-       u32 nc_addr;
-       u32 *c_addr;
-       int i;
-
-       for (nc_addr = 0xa0000000;
-            nc_addr < (0xa0000000 + DRAM_BUTTOM - NUM_OF_CACHELINE * 32);
-            nc_addr += (DRAM_BUTTOM >> 6) + offs) {
-               writel(0x00007474, (void *)MT76XX_MEMCTRL_BASE + 0x64);
-               wmb();          /* Make sure store if finished */
-
-               c_addr = (u32 *)(nc_addr & 0xdfffffff);
-               cal_memset(((u8 *)c_addr), 0x1F, NUM_OF_CACHELINE * 32);
-               cal_patgen(nc_addr, NUM_OF_CACHELINE * 8, pat);
-
-               if (dqs > 0)
-                       writel(0x00000074 |
-                              (((k == 1) ? coarse_dqs[dqs] : test_dqs) << 12) |
-                              (((k == 0) ? val : test_dqs) << 8),
-                              (void *)MT76XX_MEMCTRL_BASE + 0x64);
-               else
-                       writel(0x00007400 |
-                              (((k == 1) ? coarse_dqs[dqs] : test_dqs) << 4) |
-                              (((k == 0) ? val : test_dqs) << 0),
-                              (void *)MT76XX_MEMCTRL_BASE + 0x64);
-               wmb();          /* Make sure store if finished */
-
-               invalidate_dcache_range((u32)c_addr,
-                                       (u32)c_addr +
-                                       NUM_OF_CACHELINE * 32);
-               wmb();          /* Make sure store if finished */
-
-               for (i = 0; i < NUM_OF_CACHELINE * 8; i++) {
-                       if (i % 8 == 0)
-                               pref_op(0, &c_addr[i]);
-               }
-
-               for (i = 0; i < NUM_OF_CACHELINE * 8; i++) {
-                       if (c_addr[i] != nc_addr + i + pat)
-                               return -1;
-               }
-       }
-
-       return 0;
-}
-
-void ddr_calibrate(void)
-{
-       u32 min_coarse_dqs[2];
-       u32 max_coarse_dqs[2];
-       u32 min_fine_dqs[2];
-       u32 max_fine_dqs[2];
-       u32 coarse_dqs[2];
-       u32 fine_dqs[2];
-       int reg = 0, ddr_cfg2_reg;
-       int flag;
-       int i, k;
-       int dqs = 0;
-       u32 min_coarse_dqs_bnd, min_fine_dqs_bnd, coarse_dqs_dll, fine_dqs_dll;
-       u32 val;
-       u32 fdiv = 0, frac = 0;
-
-       /* Setup clock to run at full speed */
-       val = readl((void *)MT76XX_DYN_CFG0_REG);
-       fdiv = (u32)((val >> 8) & 0x0F);
-       if (CPU_FRAC_DIV < 1 || CPU_FRAC_DIV > 10)
-               frac = val & 0x0f;
-       else
-               frac = CPU_FRAC_DIV;
-
-       while (frac < fdiv) {
-               val = readl((void *)MT76XX_DYN_CFG0_REG);
-               fdiv = (val >> 8) & 0x0f;
-               fdiv--;
-               val &= ~(0x0f << 8);
-               val |= (fdiv << 8);
-               writel(val, (void *)MT76XX_DYN_CFG0_REG);
-               udelay(500);
-               val = readl((void *)MT76XX_DYN_CFG0_REG);
-               fdiv = (val >> 8) & 0x0f;
-       }
-
-       clrbits_le32((void *)MT76XX_MEMCTRL_BASE + 0x10, BIT(4));
-       ddr_cfg2_reg = readl((void *)MT76XX_MEMCTRL_BASE + 0x48);
-       clrbits_le32((void *)MT76XX_MEMCTRL_BASE + 0x48,
-                    (0x3 << 28) | (0x3 << 26));
-
-       min_coarse_dqs[0] = MIN_START;
-       min_coarse_dqs[1] = MIN_START;
-       min_fine_dqs[0] = MIN_FINE_START;
-       min_fine_dqs[1] = MIN_FINE_START;
-       max_coarse_dqs[0] = MAX_START;
-       max_coarse_dqs[1] = MAX_START;
-       max_fine_dqs[0] = MAX_FINE_START;
-       max_fine_dqs[1] = MAX_FINE_START;
-       dqs = 0;
-
-       /* Add by KP, DQS MIN boundary */
-       reg = readl((void *)MT76XX_MEMCTRL_BASE + 0x20);
-       coarse_dqs_dll = (reg & 0xf00) >> 8;
-       fine_dqs_dll = (reg & 0xf0) >> 4;
-       if (coarse_dqs_dll <= 8)
-               min_coarse_dqs_bnd = 8 - coarse_dqs_dll;
-       else
-               min_coarse_dqs_bnd = 0;
-
-       if (fine_dqs_dll <= 8)
-               min_fine_dqs_bnd = 8 - fine_dqs_dll;
-       else
-               min_fine_dqs_bnd = 0;
-       /* DQS MIN boundary */
-
-DQS_CAL:
-
-       for (k = 0; k < 2; k++) {
-               u32 test_dqs;
-
-               if (k == 0)
-                       test_dqs = MAX_START;
-               else
-                       test_dqs = MAX_FINE_START;
-
-               do {
-                       flag = test_loop(k, dqs, test_dqs, max_coarse_dqs,
-                                        0x400, 0x3, 0xf);
-                       if (flag == -1)
-                               break;
-
-                       test_dqs++;
-               } while (test_dqs <= 0xf);
-
-               if (k == 0) {
-                       max_coarse_dqs[dqs] = test_dqs;
-               } else {
-                       test_dqs--;
-
-                       if (test_dqs == MAX_FINE_START - 1) {
-                               max_coarse_dqs[dqs]--;
-                               max_fine_dqs[dqs] = 0xf;
-                       } else {
-                               max_fine_dqs[dqs] = test_dqs;
-                       }
-               }
-       }
-
-       for (k = 0; k < 2; k++) {
-               u32 test_dqs;
-
-               if (k == 0)
-                       test_dqs = MIN_START;
-               else
-                       test_dqs = MIN_FINE_START;
-
-               do {
-                       flag = test_loop(k, dqs, test_dqs, min_coarse_dqs,
-                                        0x480, 0x1, 0x0);
-                       if (k == 0) {
-                               if (flag == -1 ||
-                                   test_dqs == min_coarse_dqs_bnd)
-                                       break;
-
-                               test_dqs--;
-
-                               if (test_dqs < min_coarse_dqs_bnd)
-                                       break;
-                       } else {
-                               if (flag == -1) {
-                                       test_dqs++;
-                                       break;
-                               } else if (test_dqs == min_fine_dqs_bnd) {
-                                       break;
-                               }
-
-                               test_dqs--;
-
-                               if (test_dqs < min_fine_dqs_bnd)
-                                       break;
-                       }
-               } while (test_dqs >= 0);
-
-               if (k == 0) {
-                       min_coarse_dqs[dqs] = test_dqs;
-               } else {
-                       if (test_dqs == MIN_FINE_START + 1) {
-                               min_coarse_dqs[dqs]++;
-                               min_fine_dqs[dqs] = 0x0;
-                       } else {
-                               min_fine_dqs[dqs] = test_dqs;
-                       }
-               }
-       }
-
-       if (dqs == 0) {
-               dqs = 1;
-               goto DQS_CAL;
-       }
-
-       for (i = 0; i < 2; i++) {
-               u32 temp;
-
-               coarse_dqs[i] = (max_coarse_dqs[i] + min_coarse_dqs[i]) >> 1;
-               temp =
-                   (((max_coarse_dqs[i] + min_coarse_dqs[i]) % 2) * 4) +
-                   ((max_fine_dqs[i] + min_fine_dqs[i]) >> 1);
-               if (temp >= 0x10) {
-                       coarse_dqs[i]++;
-                       fine_dqs[i] = (temp - 0x10) + 0x8;
-               } else {
-                       fine_dqs[i] = temp;
-               }
-       }
-       reg = (coarse_dqs[1] << 12) | (fine_dqs[1] << 8) |
-               (coarse_dqs[0] << 4) | fine_dqs[0];
-
-       clrbits_le32((void *)MT76XX_MEMCTRL_BASE + 0x10, BIT(4));
-       writel(reg, (void *)MT76XX_MEMCTRL_BASE + 0x64);
-       writel(ddr_cfg2_reg, (void *)MT76XX_MEMCTRL_BASE + 0x48);
-       setbits_le32((void *)MT76XX_MEMCTRL_BASE + 0x10, BIT(4));
-
-       for (i = 0; i < 2; i++)
-               debug("[%02X%02X%02X%02X]", min_coarse_dqs[i],
-                     min_fine_dqs[i], max_coarse_dqs[i], max_fine_dqs[i]);
-       debug("\nDDR Calibration DQS reg = %08X\n", reg);
-}
diff --git a/arch/mips/mach-mtmips/ddr_init.c b/arch/mips/mach-mtmips/ddr_init.c
new file mode 100644 (file)
index 0000000..cd355cc
--- /dev/null
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <linux/bitops.h>
+#include <linux/io.h>
+#include <linux/sizes.h>
+#include <mach/ddr.h>
+#include <mach/mc.h>
+
+#define DDR_BW_TEST_PAT                        0xaa5555aa
+
+static const u32 dram_size[] = {
+       [DRAM_8MB] = SZ_8M,
+       [DRAM_16MB] = SZ_16M,
+       [DRAM_32MB] = SZ_32M,
+       [DRAM_64MB] = SZ_64M,
+       [DRAM_128MB] = SZ_128M,
+       [DRAM_256MB] = SZ_256M,
+};
+
+static void dram_test_write(u32 addr, u32 val)
+{
+       volatile ulong *target = (volatile ulong *)(KSEG1 + addr);
+
+       sync();
+       *target = val;
+       sync();
+}
+
+static u32 dram_test_read(u32 addr)
+{
+       volatile ulong *target = (volatile ulong *)(KSEG1 + addr);
+       u32 val;
+
+       sync();
+       val = *target;
+       sync();
+
+       return val;
+}
+
+static int dram_addr_test_bit(u32 bit)
+{
+       u32 val;
+
+       dram_test_write(0, 0);
+       dram_test_write(BIT(bit), DDR_BW_TEST_PAT);
+       val = dram_test_read(0);
+
+       if (val == DDR_BW_TEST_PAT)
+               return 1;
+
+       return 0;
+}
+
+static void mc_ddr_init(void __iomem *memc, const struct mc_ddr_cfg *cfg,
+                       u32 dq_dly, u32 dqs_dly, mc_reset_t mc_reset, u32 bw)
+{
+       u32 val;
+
+       mc_reset(1);
+       __udelay(200);
+       mc_reset(0);
+
+       clrbits_32(memc + MEMCTL_SDRAM_CFG1_REG, RBC_MAPPING);
+
+       writel(cfg->cfg2, memc + MEMCTL_DDR_CFG2_REG);
+       writel(cfg->cfg3, memc + MEMCTL_DDR_CFG3_REG);
+       writel(cfg->cfg4, memc + MEMCTL_DDR_CFG4_REG);
+       writel(dq_dly, memc + MEMCTL_DDR_DQ_DLY_REG);
+       writel(dqs_dly, memc + MEMCTL_DDR_DQS_DLY_REG);
+
+       writel(cfg->cfg0, memc + MEMCTL_DDR_CFG0_REG);
+
+       val = cfg->cfg1;
+       if (bw) {
+               val &= ~IND_SDRAM_WIDTH_M;
+               val |= (bw << IND_SDRAM_WIDTH_S) & IND_SDRAM_WIDTH_M;
+       }
+
+       writel(val, memc + MEMCTL_DDR_CFG1_REG);
+
+       clrsetbits_32(memc + MEMCTL_PWR_SAVE_CNT_REG, SR_TAR_CNT_M,
+                     1 << SR_TAR_CNT_S);
+
+       setbits_32(memc + MEMCTL_DDR_SELF_REFRESH_REG, SR_AUTO_EN);
+}
+
+void ddr1_init(struct mc_ddr_init_param *param)
+{
+       enum mc_dram_size sz;
+       u32 bw = 0;
+
+       /* First initialization, determine bus width */
+       mc_ddr_init(param->memc, &param->cfgs[DRAM_8MB], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, IND_SDRAM_WIDTH_16BIT);
+
+       /* Test bus width */
+       dram_test_write(0, DDR_BW_TEST_PAT);
+       if (dram_test_read(0) == DDR_BW_TEST_PAT)
+               bw = IND_SDRAM_WIDTH_16BIT;
+       else
+               bw = IND_SDRAM_WIDTH_8BIT;
+
+       /* Second initialization, determine DDR capacity */
+       mc_ddr_init(param->memc, &param->cfgs[DRAM_128MB], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, bw);
+
+       if (dram_addr_test_bit(9)) {
+               sz = DRAM_8MB;
+       } else {
+               if (dram_addr_test_bit(10)) {
+                       if (dram_addr_test_bit(23))
+                               sz = DRAM_16MB;
+                       else
+                               sz = DRAM_32MB;
+               } else {
+                       if (dram_addr_test_bit(24))
+                               sz = DRAM_64MB;
+                       else
+                               sz = DRAM_128MB;
+               }
+       }
+
+       /* Final initialization, with DDR calibration */
+       mc_ddr_init(param->memc, &param->cfgs[sz], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, bw);
+
+       /* Return actual DDR configuration */
+       param->memsize = dram_size[sz];
+       param->bus_width = bw;
+}
+
+void ddr2_init(struct mc_ddr_init_param *param)
+{
+       enum mc_dram_size sz;
+       u32 bw = 0;
+
+       /* First initialization, determine bus width */
+       mc_ddr_init(param->memc, &param->cfgs[DRAM_32MB], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, IND_SDRAM_WIDTH_16BIT);
+
+       /* Test bus width */
+       dram_test_write(0, DDR_BW_TEST_PAT);
+       if (dram_test_read(0) == DDR_BW_TEST_PAT)
+               bw = IND_SDRAM_WIDTH_16BIT;
+       else
+               bw = IND_SDRAM_WIDTH_8BIT;
+
+       /* Second initialization, determine DDR capacity */
+       mc_ddr_init(param->memc, &param->cfgs[DRAM_256MB], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, bw);
+
+       if (bw == IND_SDRAM_WIDTH_16BIT) {
+               if (dram_addr_test_bit(10)) {
+                       sz = DRAM_32MB;
+               } else {
+                       if (dram_addr_test_bit(24)) {
+                               if (dram_addr_test_bit(27))
+                                       sz = DRAM_64MB;
+                               else
+                                       sz = DRAM_128MB;
+                       } else {
+                               sz = DRAM_256MB;
+                       }
+               }
+       } else {
+               if (dram_addr_test_bit(23)) {
+                       sz = DRAM_32MB;
+               } else {
+                       if (dram_addr_test_bit(24)) {
+                               if (dram_addr_test_bit(27))
+                                       sz = DRAM_64MB;
+                               else
+                                       sz = DRAM_128MB;
+                       } else {
+                               sz = DRAM_256MB;
+                       }
+               }
+       }
+
+       /* Final initialization, with DDR calibration */
+       mc_ddr_init(param->memc, &param->cfgs[sz], param->dq_dly,
+                   param->dqs_dly, param->mc_reset, bw);
+
+       /* Return actual DDR configuration */
+       param->memsize = dram_size[sz];
+       param->bus_width = bw;
+}
diff --git a/arch/mips/mach-mtmips/include/mach/ddr.h b/arch/mips/mach-mtmips/include/mach/ddr.h
new file mode 100644 (file)
index 0000000..f921981
--- /dev/null
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef _MTMIPS_DDR_H_
+#define _MTMIPS_DDR_H_
+
+#include <linux/io.h>
+#include <linux/types.h>
+
+enum mc_dram_size {
+       DRAM_8MB,
+       DRAM_16MB,
+       DRAM_32MB,
+       DRAM_64MB,
+       DRAM_128MB,
+       DRAM_256MB,
+
+       __DRAM_SZ_MAX
+};
+
+struct mc_ddr_cfg {
+       u32 cfg0;
+       u32 cfg1;
+       u32 cfg2;
+       u32 cfg3;
+       u32 cfg4;
+};
+
+typedef void (*mc_reset_t)(int assert);
+
+struct mc_ddr_init_param {
+       void __iomem *memc;
+
+       u32 dq_dly;
+       u32 dqs_dly;
+
+       const struct mc_ddr_cfg *cfgs;
+       mc_reset_t mc_reset;
+
+       u32 memsize;
+       u32 bus_width;
+};
+
+void ddr1_init(struct mc_ddr_init_param *param);
+void ddr2_init(struct mc_ddr_init_param *param);
+void ddr_calibrate(void __iomem *memc, u32 memsize, u32 bw);
+
+#endif /* _MTMIPS_DDR_H_ */
diff --git a/arch/mips/mach-mtmips/include/mach/mc.h b/arch/mips/mach-mtmips/include/mach/mc.h
new file mode 100644 (file)
index 0000000..d7d623a
--- /dev/null
@@ -0,0 +1,180 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef _MTMIPS_MC_H_
+#define _MTMIPS_MC_H_
+
+#define MEMCTL_SDRAM_CFG0_REG          0x00
+#define DIS_CLK_GT                     0x80000000
+#define CLK_SLEW_S                     29
+#define CLK_SLEW_M                     0x60000000
+#define TWR                            0x10000000
+#define TMRD_S                         24
+#define TMRD_M                         0xf000000
+#define TRFC_S                         20
+#define TRFC_M                         0xf00000
+#define TCAS_S                         16
+#define TCAS_M                         0x30000
+#define TRAS_S                         12
+#define TRAS_M                         0xf000
+#define TRCD_S                         8
+#define TRCD_M                         0x300
+#define TRC_S                          4
+#define TRC_M                          0xf0
+#define TRP_S                          0
+#define TRP_M                          0x03
+
+#define MEMCTL_SDRAM_CFG1_REG          0x04
+#define SDRAM_INIT_START               0x80000000
+#define SDRAM_INIT_DONE                        0x40000000
+#define RBC_MAPPING                    0x20000000
+#define PWR_DOWN_EN                    0x10000000
+#define PWR_DOWN_MODE                  0x8000000
+#define SDRAM_WIDTH                    0x1000000
+#define NUMCOLS_S                      20
+#define NUMCOLS_M                      0x300000
+#define NUMROWS_S                      16
+#define NUMROWS_M                      0x30000
+#define TREFR_S                                0
+#define TREFR_M                                0xffff
+
+#define MEMCTL_DDR_SELF_REFRESH_REG    0x10
+#define ODT_SRC_SEL_S                  24
+#define ODT_SRC_SEL_M                  0xf000000
+#define ODT_OFF_DLY_S                  20
+#define ODT_OFF_DLY_M                  0xf00000
+#define ODT_ON_DLY_S                   16
+#define ODT_ON_DLY_M                   0xf0000
+#define SR_AUTO_EN                     0x10
+#define SRACK_B                                0x02
+#define SRREQ_B                                0x01
+
+#define MEMCTL_PWR_SAVE_CNT_REG                0x14
+#define PD_CNT_S                       24
+#define PD_CNT_M                       0xff000000
+#define SR_TAR_CNT_S                   0
+#define SR_TAR_CNT_M                   0xffffff
+
+#define MEMCTL_DLL_DBG_REG             0x20
+#define TDC_STABLE_S                   12
+#define TDC_STABLE_M                   0x3f000
+#define MST_DLY_SEL_S                  4
+#define MST_DLY_SEL_M                  0xff0
+#define CURR_STATE_S                   1
+#define CURR_STATE_M                   0x06
+#define ADLL_LOCK_DONE                 0x01
+
+#define MEMCTL_DDR_CFG0_REG            0x40
+#define T_RRD_S                                28
+#define T_RRD_M                                0xf0000000
+#define T_RAS_S                                23
+#define T_RAS_M                                0xf800000
+#define T_RP_S                         19
+#define T_RP_M                         0x780000
+#define T_RFC_S                                13
+#define T_RFC_M                                0x7e000
+#define T_REFI_S                       0
+#define T_REFI_M                       0x1fff
+
+#define MEMCTL_DDR_CFG1_REG            0x44
+#define T_WTR_S                                28
+#define T_WTR_M                                0xf0000000
+#define T_RTP_S                                24
+#define T_RTP_M                                0xf000000
+#define USER_DATA_WIDTH                        0x200000
+#define IND_SDRAM_SIZE_S               18
+#define IND_SDRAM_SIZE_M               0x1c0000
+#define IND_SDRAM_SIZE_8MB             1
+#define IND_SDRAM_SIZE_16MB            2
+#define IND_SDRAM_SIZE_32MB            3
+#define IND_SDRAM_SIZE_64MB            4
+#define IND_SDRAM_SIZE_128MB           5
+#define IND_SDRAM_SIZE_256MB           6
+#define IND_SDRAM_WIDTH_S              16
+#define IND_SDRAM_WIDTH_M              0x30000
+#define IND_SDRAM_WIDTH_8BIT           1
+#define IND_SDRAM_WIDTH_16BIT          2
+#define EXT_BANK_S                     14
+#define EXT_BANK_M                     0xc000
+#define TOTAL_SDRAM_WIDTH_S            12
+#define TOTAL_SDRAM_WIDTH_M            0x3000
+#define T_WR_S                         8
+#define T_WR_M                         0xf00
+#define T_MRD_S                                4
+#define T_MRD_M                                0xf0
+#define T_RCD_S                                0
+#define T_RCD_M                                0x0f
+
+#define MEMCTL_DDR_CFG2_REG            0x48
+#define REGE                           0x80000000
+#define DDR2_MODE                      0x40000000
+#define DQS0_GATING_WINDOW_S           28
+#define DQS0_GATING_WINDOW_M           0x30000000
+#define DQS1_GATING_WINDOW_S           26
+#define DQS1_GATING_WINDOW_M           0xc000000
+#define PD                             0x1000
+#define WR_S                           9
+#define WR_M                           0xe00
+#define DLLRESET                       0x100
+#define TESTMODE                       0x80
+#define CAS_LATENCY_S                  4
+#define CAS_LATENCY_M                  0x70
+#define BURST_TYPE                     0x08
+#define BURST_LENGTH_S                 0
+#define BURST_LENGTH_M                 0x07
+
+#define MEMCTL_DDR_CFG3_REG            0x4c
+#define Q_OFF                          0x1000
+#define RDOS                           0x800
+#define DIS_DIFF_DQS                   0x400
+#define OCD_S                          7
+#define OCD_M                          0x380
+#define RTT1                           0x40
+#define ADDITIVE_LATENCY_S             3
+#define ADDITIVE_LATENCY_M             0x38
+#define RTT0                           0x04
+#define DS                             0x02
+#define DLL                            0x01
+
+#define MEMCTL_DDR_CFG4_REG            0x50
+#define FAW_S                          0
+#define FAW_M                          0x0f
+
+#define MEMCTL_DDR_DQ_DLY_REG          0x60
+#define DQ1_DELAY_SEL_S                        24
+#define DQ1_DELAY_SEL_M                        0xff000000
+#define DQ0_DELAY_SEL_S                        16
+#define DQ0_DELAY_SEL_M                        0xff0000
+#define DQ1_DELAY_COARSE_TUNING_S      12
+#define DQ1_DELAY_COARSE_TUNING_M      0xf000
+#define DQ1_DELAY_FINE_TUNING_S                8
+#define DQ1_DELAY_FINE_TUNING_M                0xf00
+#define DQ0_DELAY_COARSE_TUNING_S      4
+#define DQ0_DELAY_COARSE_TUNING_M      0xf0
+#define DQ0_DELAY_FINE_TUNING_S                0
+#define DQ0_DELAY_FINE_TUNING_M                0x0f
+
+#define MEMCTL_DDR_DQS_DLY_REG         0x64
+#define DQS1_DELAY_SEL_S               24
+#define DQS1_DELAY_SEL_M               0xff000000
+#define DQS0_DELAY_SEL_S               16
+#define DQS0_DELAY_SEL_M               0xff0000
+#define DQS1_DELAY_COARSE_TUNING_S     12
+#define DQS1_DELAY_COARSE_TUNING_M     0xf000
+#define DQS1_DELAY_FINE_TUNING_S       8
+#define DQS1_DELAY_FINE_TUNING_M       0xf00
+#define DQS0_DELAY_COARSE_TUNING_S     4
+#define DQS0_DELAY_COARSE_TUNING_M     0xf0
+#define DQS0_DELAY_FINE_TUNING_S       0
+#define DQS0_DELAY_FINE_TUNING_M       0x0f
+
+#define MEMCTL_DDR_DLL_SLV_REG         0x68
+#define DLL_SLV_UPDATE_MODE            0x100
+#define DQS_DLY_SEL_EN                 0x80
+#define DQ_DLY_SEL_EN                  0x01
+
+#endif /* _MTMIPS_MC_H_ */
diff --git a/arch/mips/mach-mtmips/include/mach/serial.h b/arch/mips/mach-mtmips/include/mach/serial.h
new file mode 100644 (file)
index 0000000..bfa246b
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef _MTMIPS_SERIAL_H_
+#define _MTMIPS_SERIAL_H_
+
+void mtmips_spl_serial_init(void);
+
+#endif /* _MTMIPS_SERIAL_H_ */
diff --git a/arch/mips/mach-mtmips/lowlevel_init.S b/arch/mips/mach-mtmips/lowlevel_init.S
deleted file mode 100644 (file)
index aa707e0..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (c) 2018 Stefan Roese <sr@denx.de>
- *
- * This code is mostly based on the code extracted from this MediaTek
- * github repository:
- *
- * https://github.com/MediaTek-Labs/linkit-smart-uboot.git
- *
- * I was not able to find a specific license or other developers
- * copyrights here, so I can't add them here.
- */
-
-#include <config.h>
-#include <asm/regdef.h>
-#include <asm/mipsregs.h>
-#include <asm/addrspace.h>
-#include <asm/asm.h>
-#include "mt76xx.h"
-
-#ifndef BIT
-#define BIT(nr)                        (1 << (nr))
-#endif
-
-#define DELAY_USEC(us)         ((us) / 100)
-
-#define DDR_CFG1_CHIP_WIDTH_MASK (0x3 << 16)
-#define DDR_CFG1_BUS_WIDTH_MASK        (0x3 << 12)
-
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_256MBIT)
-#define DDR_CFG1_SIZE_VAL      0x222e2323
-#define DDR_CFG4_SIZE_VAL      7
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_512MBIT)
-#define DDR_CFG1_SIZE_VAL      0x22322323
-#define DDR_CFG4_SIZE_VAL      9
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_1024MBIT)
-#define DDR_CFG1_SIZE_VAL      0x22362323
-#define DDR_CFG4_SIZE_VAL      9
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_SIZE_2048MBIT)
-#define DDR_CFG1_SIZE_VAL      0x223a2323
-#define DDR_CFG4_SIZE_VAL      9
-#endif
-
-#if defined(CONFIG_ONBOARD_DDR2_CHIP_WIDTH_8BIT)
-#define DDR_CFG1_CHIP_WIDTH_VAL        (0x1 << 16)
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT)
-#define DDR_CFG1_CHIP_WIDTH_VAL        (0x2 << 16)
-#endif
-
-#if defined(CONFIG_ONBOARD_DDR2_BUS_WIDTH_16BIT)
-#define DDR_CFG1_BUS_WIDTH_VAL (0x2 << 12)
-#endif
-#if defined(CONFIG_ONBOARD_DDR2_BUS_WIDTH_32BIT)
-#define DDR_CFG1_BUS_WIDTH_VAL (0x3 << 12)
-#endif
-
-       .set noreorder
-
-LEAF(lowlevel_init)
-
-       /* Load base addresses as physical addresses for later usage */
-       li      s0, CKSEG1ADDR(MT76XX_SYSCTL_BASE)
-       li      s1, CKSEG1ADDR(MT76XX_MEMCTRL_BASE)
-       li      s2, CKSEG1ADDR(MT76XX_RGCTRL_BASE)
-
-       /* polling CPLL is ready */
-       li      t1, DELAY_USEC(1000000)
-       la      t5, MT76XX_ROM_STATUS_REG
-1:
-       lw      t2, 0(t5)
-       andi    t2, t2, 0x1
-       bnez    t2, CPLL_READY
-       subu    t1, t1, 1
-       bgtz    t1, 1b
-       nop
-       la      t0, MT76XX_CLKCFG0_REG
-       lw      t3, 0(t0)
-       ori     t3, t3, 0x1
-       sw      t3, 0(t0)
-       b       CPLL_DONE
-       nop
-CPLL_READY:
-       la      t0, MT76XX_CLKCFG0_REG
-       lw      t1, 0(t0)
-       li      t2, ~0x0c
-       and     t1, t1, t2
-       ori     t1, t1, 0xc
-       sw      t1, 0(t0)
-       la      t0, MT76XX_DYN_CFG0_REG
-       lw      t3, 0(t0)
-       li      t5, ~((0x0f << 8) | (0x0f << 0))
-       and     t3, t3, t5
-       li      t5, (10 << 8) | (1 << 0)
-       or      t3, t3, t5
-       sw      t3, 0(t0)
-       la      t0, MT76XX_CLKCFG0_REG
-       lw      t3, 0(t0)
-       li      t4, ~0x0F
-       and     t3, t3, t4
-       ori     t3, t3, 0xc
-       sw      t3, 0(t0)
-       lw      t3, 0(t0)
-       ori     t3, t3, 0x08
-       sw      t3, 0(t0)
-
-CPLL_DONE:
-       /* Reset MC */
-       lw      t2, 0x34(s0)
-       ori     t2, BIT(10)
-       sw      t2, 0x34(s0)
-       nop
-
-       /*
-        * SDR and DDR initialization: delay 200us
-        */
-       li      t0, DELAY_USEC(200 + 40)
-       li      t1, 0x1
-1:
-       sub     t0, t0, t1
-       bnez    t0, 1b
-       nop
-
-       /* set DRAM IO PAD for MT7628IC */
-       /* DDR LDO Enable  */
-       lw      t4, 0x100(s2)
-       li      t2, BIT(31)
-       or      t4, t4, t2
-       sw      t4, 0x100(s2)
-       lw      t4, 0x10c(s2)
-       j       LDO_1P8V
-       nop
-LDO_1P8V:
-       li      t2, ~BIT(6)
-       and     t4, t4, t2
-       sw      t4, 0x10c(s2)
-       j       DDRLDO_SOFT_START
-LDO_2P5V:
-       /* suppose external DDR1 LDO 2.5V */
-       li      t2, BIT(6)
-       or      t4, t4, t2
-       sw      t4, 0x10c(s2)
-
-DDRLDO_SOFT_START:
-       lw      t2, 0x10c(s2)
-       li      t3, BIT(16)
-       or      t2, t2, t3
-       sw      t2, 0x10c(s2)
-       li      t3, DELAY_USEC(250*50)
-LDO_DELAY:
-       subu    t3, t3, 1
-       bnez    t3, LDO_DELAY
-       nop
-
-       lw      t2, 0x10c(s2)
-       li      t3, BIT(18)
-       or      t2, t2, t3
-       sw      t2, 0x10c(s2)
-
-SET_RG_BUCK_FPWM:
-       lw      t2, 0x104(s2)
-       ori     t2, t2, BIT(10)
-       sw      t2, 0x104(s2)
-
-DDR_PAD_CFG:
-       /* clean CLK PAD */
-       lw      t2, 0x704(s2)
-       li      t8, 0xfffff0f0
-       and     t2, t2, t8
-       /* clean CMD PAD */
-       lw      t3, 0x70c(s2)
-       li      t8, 0xfffff0f0
-       and     t3, t3, t8
-       /* clean DQ IPAD */
-       lw      t4, 0x710(s2)
-       li      t8, 0xfffff8ff
-       and     t4, t4, t8
-       /* clean DQ OPAD */
-       lw      t5, 0x714(s2)
-       li      t8, 0xfffff0f0
-       and     t5, t5, t8
-       /* clean DQS IPAD */
-       lw      t6, 0x718(s2)
-       li      t8, 0xfffff8ff
-       and     t6, t6, t8
-       /* clean DQS OPAD */
-       lw      t7, 0x71c(s2)
-       li      t8, 0xfffff0f0
-       and     t7, t7, t8
-
-       lw      t9, 0xc(s0)
-       srl     t9, t9, 16
-       andi    t9, t9, 0x1
-       bnez    t9, MT7628_AN_DDR1_PAD
-MT7628_KN_PAD:
-       li      t8, 0x00000303
-       or      t2, t2, t8
-       or      t3, t3, t8
-       or      t5, t5, t8
-       or      t7, t7, t8
-       li      t8, 0x00000000
-       or      t4, t4, t8
-       or      t6, t6, t8
-       j       SET_PAD_CFG
-MT7628_AN_DDR1_PAD:
-       lw      t1, 0x10(s0)
-       andi    t1, t1, 0x1
-       beqz    t1, MT7628_AN_DDR2_PAD
-       li      t8, 0x00000c0c
-       or      t2, t2, t8
-       li      t8, 0x00000202
-       or      t3, t3, t8
-       li      t8, 0x00000707
-       or      t5, t5, t8
-       li      t8, 0x00000c0c
-       or      t7, t7, t8
-       li      t8, 0x00000000
-       or      t4, t4, t8
-       or      t6, t6, t8
-       j       SET_PAD_CFG
-MT7628_AN_DDR2_PAD:
-       li      t8, 0x00000c0c
-       or      t2, t2, t8
-       li      t8, 0x00000202
-       or      t3, t3, t8
-       li      t8, 0x00000404
-       or      t5, t5, t8
-       li      t8, 0x00000c0c
-       or      t7, t7, t8
-       li      t8, 0x00000000          /* ODT off */
-       or      t4, t4, t8
-       or      t6, t6, t8
-
-SET_PAD_CFG:
-       sw      t2, 0x704(s2)
-       sw      t3, 0x70c(s2)
-       sw      t4, 0x710(s2)
-       sw      t5, 0x714(s2)
-       sw      t6, 0x718(s2)
-       sw      t7, 0x71c(s2)
-
-       /*
-        * DDR initialization: reset pin to 0
-        */
-       lw      t2, 0x34(s0)
-       and     t2, ~BIT(10)
-       sw      t2, 0x34(s0)
-       nop
-
-       /*
-        * DDR initialization: wait til reg DDR_CFG1 bit 21 equal to 1 (ready)
-        */
-DDR_READY:
-       li      t1, DDR_CFG1_REG
-       lw      t0, 0(t1)
-       nop
-       and     t2, t0, BIT(21)
-       beqz    t2, DDR_READY
-       nop
-
-       /*
-        * DDR initialization
-        *
-        * Only DDR2 supported right now. DDR2 support can be added, once
-        * boards using it will get added to mainline U-Boot.
-        */
-       li      t1, DDR_CFG2_REG
-       lw      t0, 0(t1)
-       nop
-       and     t0, ~BIT(30)
-       and     t0, ~(7 << 4)
-       or      t0, (4 << 4)
-       or      t0, BIT(30)
-       or      t0, BIT(11)
-       sw      t0, 0(t1)
-       nop
-
-       li      t1, DDR_CFG3_REG
-       lw      t2, 0(t1)
-       /* Disable ODT; reference board ok, ev board fail */
-       and     t2, ~BIT(6)
-       or      t2, BIT(2)
-       li      t0, DDR_CFG4_REG
-       lw      t1, 0(t0)
-       li      t2, ~(0x01f | 0x0f0)
-       and     t1, t1, t2
-       ori     t1, t1, DDR_CFG4_SIZE_VAL
-       sw      t1, 0(t0)
-       nop
-
-       /*
-        * DDR initialization: config size and width on reg DDR_CFG1
-        */
-       li      t6, DDR_CFG1_SIZE_VAL
-
-       and     t6, ~DDR_CFG1_CHIP_WIDTH_MASK
-       or      t6, DDR_CFG1_CHIP_WIDTH_VAL
-
-       /* CONFIG DDR_CFG1[13:12] about TOTAL WIDTH */
-       and     t6, ~DDR_CFG1_BUS_WIDTH_MASK
-       or      t6, DDR_CFG1_BUS_WIDTH_VAL
-
-       li      t5, DDR_CFG1_REG
-       sw      t6, 0(t5)
-       nop
-
-       /*
-        * DDR: enable self auto refresh for power saving
-        * enable it by default for both RAM and ROM version (for CoC)
-        */
-       lw      t1, 0x14(s1)
-       nop
-       and     t1, 0xff000000
-       or      t1, 0x01
-       sw      t1, 0x14(s1)
-       nop
-       lw      t1, 0x10(s1)
-       nop
-       or      t1, 0x10
-       sw      t1, 0x10(s1)
-       nop
-
-       jr      ra
-       nop
-       END(lowlevel_init)
diff --git a/arch/mips/mach-mtmips/mt7628/Makefile b/arch/mips/mach-mtmips/mt7628/Makefile
new file mode 100644 (file)
index 0000000..7e139d5
--- /dev/null
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += lowlevel_init.o
+obj-y += init.o
+obj-y += ddr.o
+obj-$(CONFIG_SPL_BUILD) += serial.o
diff --git a/arch/mips/mach-mtmips/mt7628/ddr.c b/arch/mips/mach-mtmips/mt7628/ddr.c
new file mode 100644 (file)
index 0000000..06c0ca6
--- /dev/null
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <asm/addrspace.h>
+#include <linux/bitops.h>
+#include <linux/sizes.h>
+#include <linux/io.h>
+#include <mach/ddr.h>
+#include <mach/mc.h>
+#include "mt7628.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* DDR2 DQ_DLY */
+#define DDR2_DQ_DLY \
+                               ((0x8 << DQ1_DELAY_COARSE_TUNING_S) | \
+                               (0x2 << DQ1_DELAY_FINE_TUNING_S) | \
+                               (0x8 << DQ0_DELAY_COARSE_TUNING_S) | \
+                               (0x2 << DQ0_DELAY_FINE_TUNING_S))
+
+/* DDR2 DQS_DLY */
+#define DDR2_DQS_DLY \
+                               ((0x8 << DQS1_DELAY_COARSE_TUNING_S) | \
+                               (0x3 << DQS1_DELAY_FINE_TUNING_S) | \
+                               (0x8 << DQS0_DELAY_COARSE_TUNING_S) | \
+                               (0x3 << DQS0_DELAY_FINE_TUNING_S))
+
+const struct mc_ddr_cfg ddr1_cfgs_200mhz[] = {
+       [DRAM_8MB]   = { 0x34A1EB94, 0x20262324, 0x28000033, 0x00000002, 0x00000000 },
+       [DRAM_16MB]  = { 0x34A1EB94, 0x202A2324, 0x28000033, 0x00000002, 0x00000000 },
+       [DRAM_32MB]  = { 0x34A1E5CA, 0x202E2324, 0x28000033, 0x00000002, 0x00000000 },
+       [DRAM_64MB]  = { 0x3421E5CA, 0x20322324, 0x28000033, 0x00000002, 0x00000000 },
+       [DRAM_128MB] = { 0x241B05CA, 0x20362334, 0x28000033, 0x00000002, 0x00000000 },
+};
+
+const struct mc_ddr_cfg ddr1_cfgs_160mhz[] = {
+       [DRAM_8MB]   = { 0x239964A1, 0x20262323, 0x00000033, 0x00000002, 0x00000000 },
+       [DRAM_16MB]  = { 0x239964A1, 0x202A2323, 0x00000033, 0x00000002, 0x00000000 },
+       [DRAM_32MB]  = { 0x239964A1, 0x202E2323, 0x00000033, 0x00000002, 0x00000000 },
+       [DRAM_64MB]  = { 0x239984A1, 0x20322323, 0x00000033, 0x00000002, 0x00000000 },
+       [DRAM_128MB] = { 0x239AB4A1, 0x20362333, 0x00000033, 0x00000002, 0x00000000 },
+};
+
+const struct mc_ddr_cfg ddr2_cfgs_200mhz[] = {
+       [DRAM_32MB]  = { 0x2519E2E5, 0x222E2323, 0x68000C43, 0x00000452, 0x0000000A },
+       [DRAM_64MB]  = { 0x249AA2E5, 0x22322323, 0x68000C43, 0x00000452, 0x0000000A },
+       [DRAM_128MB] = { 0x249B42E5, 0x22362323, 0x68000C43, 0x00000452, 0x0000000A },
+       [DRAM_256MB] = { 0x249CE2E5, 0x223A2323, 0x68000C43, 0x00000452, 0x0000000A },
+};
+
+const struct mc_ddr_cfg ddr2_cfgs_160mhz[] = {
+       [DRAM_32MB]  = { 0x23918250, 0x222E2322, 0x40000A43, 0x00000452, 0x00000006 },
+       [DRAM_64MB]  = { 0x239A2250, 0x22322322, 0x40000A43, 0x00000452, 0x00000008 },
+       [DRAM_128MB] = { 0x2392A250, 0x22362322, 0x40000A43, 0x00000452, 0x00000008 },
+       [DRAM_256MB] = { 0x24140250, 0x223A2322, 0x40000A43, 0x00000452, 0x00000008 },
+};
+
+static void mt7628_memc_reset(int assert)
+{
+       void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+       if (assert)
+               setbits_32(sysc + SYSCTL_RSTCTL_REG, MC_RST);
+       else
+               clrbits_32(sysc + SYSCTL_RSTCTL_REG, MC_RST);
+}
+
+static void mt7628_ddr_pad_ldo_config(int ddr_type, int pkg_type)
+{
+       void __iomem *rgc = ioremap_nocache(RGCTL_BASE, RGCTL_SIZE);
+       u32 ck_pad1, cmd_pad1, dq_pad0, dq_pad1, dqs_pad0, dqs_pad1;
+
+       setbits_32(rgc + RGCTL_PMU_G0_REG, PMU_CFG_EN);
+
+       if (ddr_type == DRAM_DDR1)
+               setbits_32(rgc + RGCTL_PMU_G3_REG, RG_DDRLDO_VOSEL);
+       else
+               clrbits_32(rgc + RGCTL_PMU_G3_REG, RG_DDRLDO_VOSEL);
+
+       setbits_32(rgc + RGCTL_PMU_G3_REG, NI_DDRLDO_EN);
+
+       __udelay(250 * 50);
+
+       setbits_32(rgc + RGCTL_PMU_G3_REG, NI_DDRLDO_STB);
+       setbits_32(rgc + RGCTL_PMU_G1_REG, RG_BUCK_FPWM);
+
+       ck_pad1 = readl(rgc + RGCTL_DDR_PAD_CK_G1_REG);
+       cmd_pad1 = readl(rgc + RGCTL_DDR_PAD_CMD_G1_REG);
+       dq_pad0 = readl(rgc + RGCTL_DDR_PAD_DQ_G0_REG);
+       dq_pad1 = readl(rgc + RGCTL_DDR_PAD_DQ_G1_REG);
+       dqs_pad0 = readl(rgc + RGCTL_DDR_PAD_DQS_G0_REG);
+       dqs_pad1 = readl(rgc + RGCTL_DDR_PAD_DQS_G1_REG);
+
+       ck_pad1 &= ~(DRVP_M | DRVN_M);
+       cmd_pad1 &= ~(DRVP_M | DRVN_M);
+       dq_pad0 &= ~RTT_M;
+       dq_pad1 &= ~(DRVP_M | DRVN_M);
+       dqs_pad0 &= ~RTT_M;
+       dqs_pad1 &= ~(DRVP_M | DRVN_M);
+
+       if (pkg_type == PKG_ID_KN) {
+               ck_pad1 |= (3 << DRVP_S) | (3 << DRVN_S);
+               cmd_pad1 |= (3 << DRVP_S) | (3 << DRVN_S);
+               dq_pad1 |= (3 << DRVP_S) | (3 << DRVN_S);
+               dqs_pad1 |= (3 << DRVP_S) | (3 << DRVN_S);
+       } else {
+               ck_pad1 |= (12 << DRVP_S) | (12 << DRVN_S);
+               cmd_pad1 |= (2 << DRVP_S) | (2 << DRVN_S);
+               dqs_pad1 |= (12 << DRVP_S) | (12 << DRVN_S);
+               if (ddr_type == DRAM_DDR1)
+                       dq_pad1 |= (7 << DRVP_S) | (7 << DRVN_S);
+               else
+                       dq_pad1 |= (4 << DRVP_S) | (4 << DRVN_S);
+       }
+
+       writel(ck_pad1, rgc + RGCTL_DDR_PAD_CK_G1_REG);
+       writel(cmd_pad1, rgc + RGCTL_DDR_PAD_CMD_G1_REG);
+       writel(dq_pad0, rgc + RGCTL_DDR_PAD_DQ_G0_REG);
+       writel(dq_pad1, rgc + RGCTL_DDR_PAD_DQ_G1_REG);
+       writel(dqs_pad0, rgc + RGCTL_DDR_PAD_DQS_G0_REG);
+       writel(dqs_pad1, rgc + RGCTL_DDR_PAD_DQS_G1_REG);
+}
+
+void mt7628_ddr_init(void)
+{
+       void __iomem *sysc;
+       int ddr_type, pkg_type, lspd;
+       struct mc_ddr_init_param param;
+
+       sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+       ddr_type = readl(sysc + SYSCTL_SYSCFG0_REG) & DRAM_TYPE;
+       pkg_type = !!(readl(sysc + SYSCTL_CHIP_REV_ID_REG) & PKG_ID);
+       lspd = readl(sysc + SYSCTL_CLKCFG0_REG) &
+              (CPU_PLL_FROM_BBP | CPU_PLL_FROM_XTAL);
+
+       mt7628_memc_reset(1);
+       __udelay(200);
+
+       mt7628_ddr_pad_ldo_config(ddr_type, pkg_type);
+
+       param.memc = ioremap_nocache(MEMCTL_BASE, MEMCTL_SIZE);
+       param.dq_dly = DDR2_DQ_DLY;
+       param.dqs_dly = DDR2_DQS_DLY;
+       param.mc_reset = mt7628_memc_reset;
+       param.memsize = 0;
+       param.bus_width = 0;
+
+       if (pkg_type == PKG_ID_KN)
+               ddr_type = DRAM_DDR1;
+
+       if (ddr_type == DRAM_DDR1) {
+               if (lspd)
+                       param.cfgs = ddr1_cfgs_160mhz;
+               else
+                       param.cfgs = ddr1_cfgs_200mhz;
+               ddr1_init(&param);
+       } else {
+               if (lspd)
+                       param.cfgs = ddr2_cfgs_160mhz;
+               else
+                       param.cfgs = ddr2_cfgs_200mhz;
+               ddr2_init(&param);
+       }
+
+       ddr_calibrate(param.memc, param.memsize, param.bus_width);
+
+       gd->ram_size = param.memsize;
+}
diff --git a/arch/mips/mach-mtmips/mt7628/init.c b/arch/mips/mach-mtmips/mt7628/init.c
new file mode 100644 (file)
index 0000000..77d1f2e
--- /dev/null
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <dm/uclass.h>
+#include <dt-bindings/clock/mt7628-clk.h>
+#include <linux/io.h>
+#include "mt7628.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static void set_init_timer_freq(void)
+{
+       void __iomem *sysc;
+       u32 bs, val, timer_freq_post;
+
+       sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+       /* We can't use the clk driver as the DM has not been initialized yet */
+       bs = readl(sysc + SYSCTL_SYSCFG0_REG);
+       if ((bs & XTAL_FREQ_SEL) == XTAL_25MHZ) {
+               gd->arch.timer_freq = 25000000;
+               timer_freq_post = 575000000;
+       } else {
+               gd->arch.timer_freq = 40000000;
+               timer_freq_post = 580000000;
+       }
+
+       val = readl(sysc + SYSCTL_CLKCFG0_REG);
+       if (!(val & (CPU_PLL_FROM_BBP | CPU_PLL_FROM_XTAL)))
+               gd->arch.timer_freq = timer_freq_post;
+}
+
+void mt7628_init(void)
+{
+       set_init_timer_freq();
+
+       mt7628_ddr_init();
+}
+
+int print_cpuinfo(void)
+{
+       void __iomem *sysc;
+       struct udevice *clkdev;
+       u32 val, ver, eco, pkg, ddr, chipmode, ee;
+       ulong cpu_clk, bus_clk, xtal_clk, timer_freq;
+       struct clk clk;
+       int ret;
+
+       sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+       val = readl(sysc + SYSCTL_CHIP_REV_ID_REG);
+       ver = (val & VER_M) >> VER_S;
+       eco = (val & ECO_M) >> ECO_S;
+       pkg = !!(val & PKG_ID);
+
+       val = readl(sysc + SYSCTL_SYSCFG0_REG);
+       ddr = val & DRAM_TYPE;
+       chipmode = (val & CHIP_MODE_M) >> CHIP_MODE_S;
+
+       val = readl(sysc + SYSCTL_EFUSE_CFG_REG);
+       ee = val & EFUSE_MT7688;
+
+       printf("CPU:   MediaTek MT%u%c ver:%u eco:%u\n",
+              ee ? 7688 : 7628, pkg ? 'A' : 'K', ver, eco);
+
+       printf("Boot:  DDR%s, SPI-NOR %u-Byte Addr, CPU clock from %s\n",
+              ddr ? "" : "2", chipmode & 0x01 ? 4 : 3,
+              chipmode & 0x02 ? "XTAL" : "CPLL");
+
+       ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(mt7628_clk),
+                                         &clkdev);
+       if (ret)
+               return ret;
+
+       clk.dev = clkdev;
+
+       clk.id = CLK_CPU;
+       cpu_clk = clk_get_rate(&clk);
+
+       clk.id = CLK_SYS;
+       bus_clk = clk_get_rate(&clk);
+
+       clk.id = CLK_XTAL;
+       xtal_clk = clk_get_rate(&clk);
+
+       clk.id = CLK_MIPS_CNT;
+       timer_freq = clk_get_rate(&clk);
+
+       /* Set final timer frequency */
+       if (timer_freq)
+               gd->arch.timer_freq = timer_freq;
+
+       printf("Clock: CPU: %luMHz, Bus: %luMHz, XTAL: %luMHz\n",
+              cpu_clk / 1000000, bus_clk / 1000000, xtal_clk / 1000000);
+
+       return 0;
+}
+
+ulong notrace get_tbclk(void)
+{
+       return gd->arch.timer_freq;
+}
diff --git a/arch/mips/mach-mtmips/mt7628/lowlevel_init.S b/arch/mips/mach-mtmips/mt7628/lowlevel_init.S
new file mode 100644 (file)
index 0000000..e4a6c03
--- /dev/null
@@ -0,0 +1,161 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <config.h>
+#include <asm-offsets.h>
+#include <asm/cacheops.h>
+#include <asm/regdef.h>
+#include <asm/mipsregs.h>
+#include <asm/addrspace.h>
+#include <asm/asm.h>
+#include "mt7628.h"
+
+/* Set temporary stack address range */
+#ifndef CONFIG_SYS_INIT_SP_ADDR
+#define CONFIG_SYS_INIT_SP_ADDR        (CONFIG_SYS_SDRAM_BASE + \
+                               CONFIG_SYS_INIT_SP_OFFSET)
+#endif
+
+#define CACHE_STACK_SIZE       0x4000
+#define CACHE_STACK_BASE       (CONFIG_SYS_INIT_SP_ADDR - CACHE_STACK_SIZE)
+
+#define DELAY_USEC(us)         ((58 * (us)) / 3)
+
+       .set noreorder
+
+LEAF(mips_sram_init)
+#ifndef CONFIG_SKIP_LOWLEVEL_INIT
+       /* Setup CPU PLL */
+       li      t0, DELAY_USEC(1000000)
+       li      t1, KSEG1ADDR(SYSCTL_BASE + SYSCTL_ROM_STATUS_REG)
+       li      t2, KSEG1ADDR(SYSCTL_BASE + SYSCTL_CLKCFG0_REG)
+
+_check_rom_status:
+       lw      t3, 0(t1)
+       andi    t3, t3, 1
+       bnez    t3, _rom_normal
+       subu    t0, t0, 1
+       bnez    t0, _check_rom_status
+        nop
+
+       lw      t3, 0(t2)
+       ori     t3, (CPU_PLL_FROM_BBP | CPU_PLL_FROM_XTAL)
+       xori    t3, CPU_PLL_FROM_BBP
+       b       _cpu_pll_done
+        nop
+
+_rom_normal:
+       lw      t3, 0(t2)
+       ori     t3, (CPU_PLL_FROM_BBP | CPU_PLL_FROM_XTAL | \
+                   DIS_BBP_SLEEP | EN_BBP_CLK)
+       xori    t3, (CPU_PLL_FROM_BBP | CPU_PLL_FROM_XTAL)
+
+_cpu_pll_done:
+       sw      t3, 0(t2)
+
+       li      t2, KSEG1ADDR(RBUSCTL_BASE + RBUSCTL_DYN_CFG0_REG)
+       lw      t3, 0(t2)
+       ori     t3, t3, (CPU_FDIV_M | CPU_FFRAC_M)
+       xori    t3, t3, (CPU_FDIV_M | CPU_FFRAC_M)
+       ori     t3, t3, ((1 << CPU_FDIV_S) | (1 << CPU_FFRAC_S))
+       sw      t3, 0(t2)
+
+       /* Clear WST & SPR bits in ErrCtl */
+       mfc0    t0, CP0_ECC
+       ins     t0, zero, 30, 2
+       mtc0    t0, CP0_ECC
+       ehb
+
+       /* Simply initialize I-Cache */
+       li      a0, 0
+       li      a1, CONFIG_SYS_ICACHE_SIZE
+
+       mtc0    zero, CP0_TAGLO         /* Zero to DDataLo */
+
+1:     cache   INDEX_STORE_TAG_I, 0(a0)
+       addiu   a0, CONFIG_SYS_ICACHE_LINE_SIZE
+       bne     a0, a1, 1b
+        nop
+
+       /* Simply initialize D-Cache */
+       li      a0, 0
+       li      a1, CONFIG_SYS_DCACHE_SIZE
+
+       mtc0    zero, CP0_TAGLO, 2
+
+2:     cache   INDEX_STORE_TAG_D, 0(a0)
+       addiu   a0, CONFIG_SYS_DCACHE_LINE_SIZE
+       bne     a0, a1, 2b
+        nop
+
+       /* Set KSEG0 Cachable */
+       mfc0    t0, CP0_CONFIG
+       and     t0, t0, MIPS_CONF_IMPL
+       or      t0, t0, CONF_CM_CACHABLE_NONCOHERENT
+       mtc0    t0, CP0_CONFIG
+       ehb
+
+       /* Lock D-Cache */
+       PTR_LI  a0, CACHE_STACK_BASE            /* D-Cache lock base */
+       li      a1, CACHE_STACK_SIZE            /* D-Cache lock size */
+       li      a2, 0x1ffff800                  /* Mask of DTagLo[PTagLo] */
+
+3:
+       /* Lock one cacheline */
+       and     t0, a0, a2
+       ori     t0, 0xe0                        /* Valid & Dirty & Lock bits */
+       mtc0    t0, CP0_TAGLO, 2                /* Write to DTagLo */
+       ehb
+       cache   INDEX_STORE_TAG_D, 0(a0)
+
+       addiu   a0, CONFIG_SYS_DCACHE_LINE_SIZE
+       sub     a1, CONFIG_SYS_DCACHE_LINE_SIZE
+       bnez    a1, 3b
+        nop
+#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
+
+       jr      ra
+        nop
+       END(mips_sram_init)
+
+NESTED(lowlevel_init, 0, ra)
+       /* Save ra and do real lowlevel initialization */
+       move    s0, ra
+
+       PTR_LA  t9, mt7628_init
+       jalr    t9
+        nop
+
+       move    ra, s0
+
+#if CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
+       /* Set malloc base */
+       li      t0, (CONFIG_SYS_INIT_SP_ADDR + 15) & (~15)
+       PTR_S   t0, GD_MALLOC_BASE(k0)  # gd->malloc_base offset
+#endif
+
+       /* Write back data in locked cache to DRAM */
+       PTR_LI  a0, CACHE_STACK_BASE            /* D-Cache unlock base */
+       li      a1, CACHE_STACK_SIZE            /* D-Cache unlock size */
+
+1:
+       cache   HIT_WRITEBACK_INV_D, 0(a0)
+       addiu   a0, CONFIG_SYS_DCACHE_LINE_SIZE
+       sub     a1, CONFIG_SYS_DCACHE_LINE_SIZE
+       bnez    a1, 1b
+        nop
+
+       /* Set KSEG0 Uncached */
+       mfc0    t0, CP0_CONFIG
+       and     t0, t0, MIPS_CONF_IMPL
+       or      t0, t0, CONF_CM_UNCACHED
+       mtc0    t0, CP0_CONFIG
+       ehb
+
+       jr      ra
+        nop
+       END(lowlevel_init)
diff --git a/arch/mips/mach-mtmips/mt7628/mt7628.h b/arch/mips/mach-mtmips/mt7628/mt7628.h
new file mode 100644 (file)
index 0000000..391880b
--- /dev/null
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef _MT7628_H_
+#define _MT7628_H_
+
+#define SYSCTL_BASE                    0x10000000
+#define SYSCTL_SIZE                    0x100
+#define MEMCTL_BASE                    0x10000300
+#define MEMCTL_SIZE                    0x100
+#define RBUSCTL_BASE                   0x10000400
+#define RBUSCTL_SIZE                   0x100
+#define RGCTL_BASE                     0x10001000
+#define RGCTL_SIZE                     0x800
+
+#define SYSCTL_EFUSE_CFG_REG           0x08
+#define EFUSE_MT7688                   0x100000
+
+#define SYSCTL_CHIP_REV_ID_REG         0x0c
+#define PKG_ID                         0x10000
+#define PKG_ID_AN                      1
+#define PKG_ID_KN                      0
+#define VER_S                          8
+#define VER_M                          0xf00
+#define ECO_S                          0
+#define ECO_M                          0x0f
+
+#define SYSCTL_SYSCFG0_REG             0x10
+#define XTAL_FREQ_SEL                  0x40
+#define XTAL_40MHZ                     1
+#define XTAL_25MHZ                     0
+#define CHIP_MODE_S                    1
+#define CHIP_MODE_M                    0x0e
+#define DRAM_TYPE                      0x01
+#define DRAM_DDR1                      1
+#define DRAM_DDR2                      0
+
+#define SYSCTL_ROM_STATUS_REG          0x28
+
+#define SYSCTL_CLKCFG0_REG             0x2c
+#define DIS_BBP_SLEEP                  0x08
+#define EN_BBP_CLK                     0x04
+#define CPU_PLL_FROM_BBP               0x02
+#define CPU_PLL_FROM_XTAL              0x01
+
+#define SYSCTL_RSTCTL_REG              0x34
+#define MC_RST                         0x400
+
+#define SYSCTL_AGPIO_CFG_REG           0x3c
+#define EPHY_GPIO_AIO_EN_S             17
+#define EPHY_GPIO_AIO_EN_M             0x1e0000
+
+#define SYSCTL_GPIO_MODE1_REG          0x60
+#define UART2_MODE_S                   26
+#define UART2_MODE_M                   0xc000000
+#define UART1_MODE_S                   24
+#define UART1_MODE_M                   0x3000000
+#define UART0_MODE_S                   8
+#define UART0_MODE_M                   0x300
+#define SPIS_MODE_S                    2
+#define SPIS_MODE_M                    0x0c
+
+#define RBUSCTL_DYN_CFG0_REG           0x40
+#define CPU_FDIV_S                     8
+#define CPU_FDIV_M                     0xf00
+#define CPU_FFRAC_S                    0
+#define CPU_FFRAC_M                    0x0f
+
+#define RGCTL_PMU_G0_REG               0x100
+#define PMU_CFG_EN                     0x80000000
+
+#define RGCTL_PMU_G1_REG               0x104
+#define RG_BUCK_FPWM                   0x02
+
+#define RGCTL_PMU_G3_REG               0x10c
+#define NI_DDRLDO_STB                  0x40000
+#define NI_DDRLDO_EN                   0x10000
+#define RG_DDRLDO_VOSEL                        0x40
+
+#define RGCTL_DDR_PAD_CK_G0_REG                0x700
+#define RGCTL_DDR_PAD_CMD_G0_REG       0x708
+#define RGCTL_DDR_PAD_DQ_G0_REG                0x710
+#define RGCTL_DDR_PAD_DQS_G0_REG       0x718
+#define RTT_S                          8
+#define RTT_M                          0x700
+
+#define RGCTL_DDR_PAD_CK_G1_REG                0x704
+#define RGCTL_DDR_PAD_CMD_G1_REG       0x70c
+#define RGCTL_DDR_PAD_DQ_G1_REG                0x714
+#define RGCTL_DDR_PAD_DQS_G1_REG       0x71c
+#define DRVP_S                         0
+#define DRVP_M                         0x0f
+#define DRVN_S                         8
+#define DRVN_M                         0xf00
+
+#ifndef __ASSEMBLY__
+void mt7628_ddr_init(void);
+#endif
+
+#endif /* _MT7628_H_ */
diff --git a/arch/mips/mach-mtmips/mt7628/serial.c b/arch/mips/mach-mtmips/mt7628/serial.c
new file mode 100644 (file)
index 0000000..a7d3247
--- /dev/null
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include "mt7628.h"
+
+void mtmips_spl_serial_init(void)
+{
+#ifdef CONFIG_SPL_SERIAL_SUPPORT
+       void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+#if CONFIG_CONS_INDEX == 1
+       clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART0_MODE_M);
+#elif CONFIG_CONS_INDEX == 2
+       clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART1_MODE_M);
+#elif CONFIG_CONS_INDEX == 3
+       setbits_32(base + SYSCTL_AGPIO_CFG_REG, EPHY_GPIO_AIO_EN_M);
+#ifdef CONFIG_SPL_UART2_SPIS_PINMUX
+       setbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M);
+       clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M,
+                     1 << UART2_MODE_S);
+#else
+       clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M);
+       clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M,
+                     1 << SPIS_MODE_S);
+#endif /* CONFIG_SPL_UART2_SPIS_PINMUX */
+#endif /* CONFIG_CONS_INDEX */
+#endif /* CONFIG_SPL_SERIAL_SUPPORT */
+}
diff --git a/arch/mips/mach-mtmips/mt76xx.h b/arch/mips/mach-mtmips/mt76xx.h
deleted file mode 100644 (file)
index 17473ea..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (C) 2018 Stefan Roese <sr@denx.de>
- */
-
-#ifndef __MT76XX_H
-#define __MT76XX_H
-
-#define MT76XX_SYSCTL_BASE     0x10000000
-
-#define MT76XX_CHIPID_OFFS     0x00
-#define MT76XX_CHIP_REV_ID_OFFS        0x0c
-#define MT76XX_SYSCFG0_OFFS    0x10
-
-#define MT76XX_MEMCTRL_BASE    (MT76XX_SYSCTL_BASE + 0x0300)
-#define MT76XX_RGCTRL_BASE     (MT76XX_SYSCTL_BASE + 0x1000)
-
-#define MT76XX_ROM_STATUS_REG  (MT76XX_SYSCTL_BASE + 0x0028)
-#define MT76XX_CLKCFG0_REG     (MT76XX_SYSCTL_BASE + 0x002c)
-#define MT76XX_DYN_CFG0_REG    (MT76XX_SYSCTL_BASE + 0x0440)
-
-#define DDR_CFG1_REG           (MT76XX_MEMCTRL_BASE + 0x44)
-#define DDR_CFG2_REG           (MT76XX_MEMCTRL_BASE + 0x48)
-#define DDR_CFG3_REG           (MT76XX_MEMCTRL_BASE + 0x4c)
-#define DDR_CFG4_REG           (MT76XX_MEMCTRL_BASE + 0x50)
-
-#ifndef __ASSEMBLY__
-/* Prototypes */
-void ddr_calibrate(void);
-#endif
-
-#endif
diff --git a/arch/mips/mach-mtmips/spl.c b/arch/mips/mach-mtmips/spl.c
new file mode 100644 (file)
index 0000000..2a24af7
--- /dev/null
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <fdt.h>
+#include <spl.h>
+#include <asm/sections.h>
+#include <linux/sizes.h>
+#include <mach/serial.h>
+
+void __noreturn board_init_f(ulong dummy)
+{
+       spl_init();
+
+#ifdef CONFIG_SPL_SERIAL_SUPPORT
+       /*
+        * mtmips_spl_serial_init() is useful if debug uart is enabled,
+        * or DM based serial is not enabled.
+        */
+       mtmips_spl_serial_init();
+       preloader_console_init();
+#endif
+
+       board_init_r(NULL, 0);
+}
+
+void board_boot_order(u32 *spl_boot_list)
+{
+       spl_boot_list[0] = BOOT_DEVICE_NOR;
+}
+
+unsigned long spl_nor_get_uboot_base(void)
+{
+       void *uboot_base = __image_copy_end;
+
+       if (fdt_magic(uboot_base) == FDT_MAGIC)
+               return (unsigned long)uboot_base + fdt_totalsize(uboot_base);
+
+       return (unsigned long)uboot_base;
+}
index 48cf3091e99792db5365f6743467b5da077dd970..776afa43a66046fdf589d8502652765b022bf045 100644 (file)
@@ -295,8 +295,10 @@ err_free:
        return ret;
 }
 
+#ifndef CONFIG_SPL_BUILD
 U_BOOT_CMD(
        fd_write,       1,      0,      do_fd_write,
        "Write test factory-data values to SPI NOR",
        "\n"
 );
+#endif
diff --git a/board/mediatek/mt7628/Kconfig b/board/mediatek/mt7628/Kconfig
new file mode 100644 (file)
index 0000000..d6b6f9d
--- /dev/null
@@ -0,0 +1,12 @@
+if BOARD_MT7628_RFB
+
+config SYS_BOARD
+       default "mt7628"
+
+config SYS_VENDOR
+       default "mediatek"
+
+config SYS_CONFIG_NAME
+       default "mt7628"
+
+endif
diff --git a/board/mediatek/mt7628/MAINTAINERS b/board/mediatek/mt7628/MAINTAINERS
new file mode 100644 (file)
index 0000000..032fd0e
--- /dev/null
@@ -0,0 +1,7 @@
+MT7628_RFB BOARD
+M:     Weijie Gao <weijie.gao@mediatek.com>
+S:     Maintained
+F:     board/mediatek/mt7628
+F:     include/configs/mt7628.h
+F:     configs/mt7628_rfb_defconfig
+F:     arch/mips/dts/mediatek,mt7628-rfb.dts
diff --git a/board/mediatek/mt7628/Makefile b/board/mediatek/mt7628/Makefile
new file mode 100644 (file)
index 0000000..db129c5
--- /dev/null
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += board.o
diff --git a/board/mediatek/mt7628/board.c b/board/mediatek/mt7628/board.c
new file mode 100644 (file)
index 0000000..f837a06
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
index e8c00a6e7d078a62e288b4981a85e467e4bdc87b..d9c0e27a41dc81db8b6b2dbfeec55c181e9513eb 100644 (file)
@@ -7,6 +7,24 @@ config SYS_VENDOR
        default "synopsys"
 
 config SYS_CONFIG_NAME
-       default "hsdk"
+       default "hsdk" if BOARD_HSDK
+       default "hsdk-4xd" if BOARD_HSDK_4XD
+
+choice
+       prompt "HSDK board type"
+       default BOARD_HSDK
+
+config BOARD_HSDK
+       bool "ARC HS Development Kit"
+       help
+         ARC HS Development Kit based on quard core ARC HS38 processor
+
+config BOARD_HSDK_4XD
+       bool "ARC HS4x/HS4xD Development Kit"
+       help
+         ARC HS4x/HS4xD Development Kit based on quard core ARC HS48/HS47D
+         processor
+
+endchoice
 
 endif
index e22bd1e40b26d5bd3e283e77c90b500c3c6dd14c..73f71fd06bc24902ba1e659eafe68c4f278bff82 100644 (file)
@@ -1,5 +1,8 @@
-HSDK BOARD
+HSDK BOARDs
 M:     Eugeniy Paltsev <paltsev@synopsys.com>
 S:     Maintained
 F:     board/synopsys/hsdk/
 F:     configs/hsdk_defconfig
+F:     configs/hsdk_4xd_defconfig
+F:     include/configs/hsdk-4xd.h
+F:     include/configs/hsdk.h
index 5ae22fa2b75e4233e1d47d97b90fd94cb30f351d..def944aad2b69cde5927d7ead22f2e19bcdf8bd9 100644 (file)
@@ -2,6 +2,7 @@
 #
 # Copyright (C) 2018 Synopsys, Inc. All rights reserved.
 
+ifdef CONFIG_BOARD_HSDK
 PLATFORM_CPPFLAGS += -mcpu=hs38_linux -mlittle-endian -matomic -mll64 \
                      -mdiv-rem -mswap -mnorm -mmpy-option=9 -mbarrel-shifter \
                      -mfpu=fpud_all
@@ -13,3 +14,18 @@ bsp-generate: u-boot u-boot.bin
        $(Q)tools/mkimage -T script -C none -n 'uboot update script' \
                -d $(srctree)/u-boot-update.txt \
                $(srctree)/u-boot-update.scr &> /dev/null
+endif
+
+ifdef CONFIG_BOARD_HSDK_4XD
+PLATFORM_CPPFLAGS += -mcpu=hs4x_rel31 -mlittle-endian -matomic -mll64 \
+                     -mdiv-rem -mswap -mnorm -mmpy-option=9 -mbarrel-shifter \
+                     -mfpu=fpud_all
+
+bsp-generate: u-boot u-boot.bin
+       $(Q)python3 $(srctree)/board/$(BOARDDIR)/headerize-hsdk.py \
+               --arc-id 0x54 --image $(srctree)/u-boot.bin \
+               --elf $(srctree)/u-boot
+       $(Q)tools/mkimage -T script -C none -n 'uboot update script' \
+               -d $(srctree)/u-boot-update.txt \
+               $(srctree)/u-boot-update.scr &> /dev/null
+endif
index fce749723ed5eb7ba71a6ac0a55f5e697df1d28a..7b047cf4a386c342651eb8d531830f30ecb48e82 100644 (file)
@@ -27,7 +27,7 @@ def calc_check_sum(filename):
 
 
 def arg_verify(uboot_bin_filename, uboot_elf_filename, arc_id):
-    if arc_id not in [0x52, 0x53]:
+    if arc_id not in [0x52, 0x53, 0x54]:
         print("unknown ARC ID: " + hex(arc_id))
         sys.exit(2)
 
index 67a29e334d7535ca41350d80c999d19efe086c0e..a3e0563ff45104ffa9b2c012591fc6353def3ee1 100644 (file)
@@ -40,6 +40,9 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CREG_BASE              (ARC_PERIPHERAL_BASE + 0x1000)
 #define CREG_CPU_START         (CREG_BASE + 0x400)
 #define CREG_CPU_START_MASK    0xF
+#define CREG_CPU_START_POL     BIT(4)
+
+#define CREG_CPU_0_ENTRY       (CREG_BASE + 0x404)
 
 #define SDIO_BASE              (ARC_PERIPHERAL_BASE + 0xA000)
 #define SDIO_UHS_REG_EXT       (SDIO_BASE + 0x108)
@@ -79,6 +82,9 @@ struct hsdk_env_common_ctl {
        u32_env nvlim;
        u32_env icache;
        u32_env dcache;
+       u32_env csm_location;
+       u32_env l2_cache;
+       u32_env haps_apb;
 };
 
 /*
@@ -128,6 +134,11 @@ static const struct env_map_common env_map_common[] = {
        { "non_volatile_limit", ENV_HEX, true, 0, 0xF,  &env_common.nvlim },
        { "icache_ena", ENV_HEX, true,  0, 1,           &env_common.icache },
        { "dcache_ena", ENV_HEX, true,  0, 1,           &env_common.dcache },
+#if defined(CONFIG_BOARD_HSDK_4XD)
+       { "l2_cache_ena",       ENV_HEX, true,  0, 1,           &env_common.l2_cache },
+       { "csm_location",       ENV_HEX, true,  0, NO_CCM,      &env_common.csm_location },
+       { "haps_apb_location",  ENV_HEX, true,  0, 1,           &env_common.haps_apb },
+#endif /* CONFIG_BOARD_HSDK_4XD */
        {}
 };
 
@@ -154,6 +165,61 @@ static const struct env_map_percpu env_map_go[] = {
        {}
 };
 
+enum board_type {
+       T_BOARD_NONE,
+       T_BOARD_HSDK,
+       T_BOARD_HSDK_4XD
+};
+
+static inline enum board_type get_board_type_runtime(void)
+{
+       u32 arc_id = read_aux_reg(ARC_AUX_IDENTITY) & 0xFF;
+
+       if (arc_id == 0x52)
+               return T_BOARD_HSDK;
+       else if (arc_id == 0x54)
+               return T_BOARD_HSDK_4XD;
+       else
+               return T_BOARD_NONE;
+}
+
+static inline enum board_type get_board_type_config(void)
+{
+       if (IS_ENABLED(CONFIG_BOARD_HSDK))
+               return T_BOARD_HSDK;
+       else if (IS_ENABLED(CONFIG_BOARD_HSDK_4XD))
+               return T_BOARD_HSDK_4XD;
+       else
+               return T_BOARD_NONE;
+}
+
+static bool is_board_match_runtime(enum board_type type_req)
+{
+       return get_board_type_runtime() == type_req;
+}
+
+static bool is_board_match_config(enum board_type type_req)
+{
+       return get_board_type_config() == type_req;
+}
+
+static const char * board_name(enum board_type type)
+{
+       switch (type) {
+               case T_BOARD_HSDK:
+                       return "ARC HS Development Kit";
+               case T_BOARD_HSDK_4XD:
+                       return "ARC HS4x/HS4xD Development Kit";
+               default:
+                       return "?";
+       }
+}
+
+static bool board_mismatch(void)
+{
+       return get_board_type_config() != get_board_type_runtime();
+}
+
 static void sync_cross_cpu_data(void)
 {
        u32 value;
@@ -221,10 +287,48 @@ static void init_cluster_nvlim(void)
 
        flush_dcache_all();
        write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT, val);
-       write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
+       /* AUX_AUX_CACHE_LIMIT reg is missing starting from HS48 */
+       if (is_board_match_runtime(T_BOARD_HSDK))
+               write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
        flush_n_invalidate_dcache_all();
 }
 
+static void init_cluster_slc(void)
+{
+       /* ARC HS38 doesn't support SLC disabling */
+       if (!is_board_match_config(T_BOARD_HSDK_4XD))
+               return;
+
+       if (env_common.l2_cache.val)
+               slc_enable();
+       else
+               slc_disable();
+}
+
+#define CREG_CSM_BASE          (CREG_BASE + 0x210)
+
+static void init_cluster_csm(void)
+{
+       /* ARC HS38 in HSDK SoC doesn't include CSM */
+       if (!is_board_match_config(T_BOARD_HSDK_4XD))
+               return;
+
+       if (env_common.csm_location.val == NO_CCM) {
+               write_aux_reg(ARC_AUX_CSM_ENABLE, 0);
+       } else {
+               /*
+                * CSM base address is 256kByte aligned but we allow to map
+                * CSM only to aperture start (256MByte aligned)
+                * The field in CREG_CSM_BASE is in 17:2 bits itself so we need
+                * to shift it.
+                */
+               u32 csm_base = (env_common.csm_location.val * SZ_1K) << 2;
+
+               write_aux_reg(ARC_AUX_CSM_ENABLE, 1);
+               writel(csm_base, (void __iomem *)CREG_CSM_BASE);
+       }
+}
+
 static void init_master_icache(void)
 {
        if (icache_status()) {
@@ -279,25 +383,36 @@ static inline void halt_this_cpu(void)
        __builtin_arc_flag(1);
 }
 
-static void smp_kick_cpu_x(u32 cpu_id)
+static u32 get_masked_cpu_ctart_reg(void)
 {
        int cmd = readl((void __iomem *)CREG_CPU_START);
 
+       /*
+        * Quirk for HSDK-4xD - due to HW issues HSDK can use any pulse polarity
+        * and HSDK-4xD require active low polarity of cpu_start pulse.
+        */
+       cmd &= ~CREG_CPU_START_POL;
+
+       cmd &= ~CREG_CPU_START_MASK;
+
+       return cmd;
+}
+
+static void smp_kick_cpu_x(u32 cpu_id)
+{
+       int cmd;
+
        if (cpu_id > NR_CPUS)
                return;
 
-       cmd &= ~CREG_CPU_START_MASK;
+       cmd = get_masked_cpu_ctart_reg();
        cmd |= (1 << cpu_id);
        writel(cmd, (void __iomem *)CREG_CPU_START);
 }
 
 static u32 prepare_cpu_ctart_reg(void)
 {
-       int cmd = readl((void __iomem *)CREG_CPU_START);
-
-       cmd &= ~CREG_CPU_START_MASK;
-
-       return cmd | env_common.core_mask.val;
+       return get_masked_cpu_ctart_reg() | env_common.core_mask.val;
 }
 
 /* slave CPU entry for configuration */
@@ -560,6 +675,61 @@ void init_memory_bridge(void)
        writel(UPDATE_VAL, CREG_PAE_UPDT);
 }
 
+/*
+ * For HSDK-4xD we do additional AXI bridge tweaking in hsdk_init command:
+ * - we shrink IOC region.
+ * - we configure HS CORE SLV1 aperture depending on haps_apb_location
+ *   environment variable.
+ *
+ * As we've already configured AXI bridge in init_memory_bridge we don't
+ * do full configuration here but reconfigure changed part.
+ *
+ * m   master          AXI_M_m_SLV0    AXI_M_m_SLV1    AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
+ * 0   HS (CBU)        0x11111111      0x63111111      0xFEDCBA98      0x0E543210      [haps_apb_location = 0]
+ * 0   HS (CBU)        0x11111111      0x61111111      0xFEDCBA98      0x06543210      [haps_apb_location = 1]
+ * 1   HS (RTT)        0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 2   AXI Tunnel      0x88888888      0x88888888      0xFEDCBA98      0x76543210
+ * 3   HDMI-VIDEO      0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 4   HDMI-ADUIO      0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 5   USB-HOST        0x77777777      0x77779999      0xFEDCBA98      0x7654BA98
+ * 6   ETHERNET        0x77777777      0x77779999      0xFEDCBA98      0x7654BA98
+ * 7   SDIO            0x77777777      0x77779999      0xFEDCBA98      0x7654BA98
+ * 8   GPU             0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 9   DMAC (port #1)  0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 10  DMAC (port #2)  0x77777777      0x77777777      0xFEDCBA98      0x76543210
+ * 11  DVFS            0x00000000      0x60000000      0x00000000      0x00000000
+ */
+void tweak_memory_bridge_cfg(void)
+{
+       /*
+        * Only HSDK-4xD requre additional AXI bridge tweaking depending on
+        * haps_apb_location environment variable
+        */
+       if (!is_board_match_config(T_BOARD_HSDK_4XD))
+               return;
+
+       if (env_common.haps_apb.val) {
+               writel(0x61111111, CREG_AXI_M_SLV1(M_HS_CORE));
+               writel(0x06543210, CREG_AXI_M_OFT1(M_HS_CORE));
+       } else {
+               writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
+               writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
+       }
+       writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
+
+       writel(0x77779999, CREG_AXI_M_SLV1(M_USB_HOST));
+       writel(0x7654BA98, CREG_AXI_M_OFT1(M_USB_HOST));
+       writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
+
+       writel(0x77779999, CREG_AXI_M_SLV1(M_ETHERNET));;
+       writel(0x7654BA98, CREG_AXI_M_OFT1(M_ETHERNET));
+       writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
+
+       writel(0x77779999, CREG_AXI_M_SLV1(M_SDIO));
+       writel(0x7654BA98, CREG_AXI_M_OFT1(M_SDIO));
+       writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
+}
+
 static void setup_clocks(void)
 {
        ulong rate;
@@ -593,6 +763,9 @@ static void do_init_cluster(void)
         * cores.
         */
        init_cluster_nvlim();
+       init_cluster_csm();
+       init_cluster_slc();
+       tweak_memory_bridge_cfg();
 }
 
 static int check_master_cpu_id(void)
@@ -758,6 +931,11 @@ static int do_hsdk_go(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
        int ret;
 
+       if (board_mismatch()) {
+               printf("ERR: U-boot is not configured for this board!\n");
+               return CMD_RET_FAILURE;
+       }
+
        /*
         * Check for 'halt' parameter. 'halt' = enter halt-mode just before
         * starting the application; can be used for debug.
@@ -793,20 +971,45 @@ U_BOOT_CMD(
        "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
 );
 
+/*
+ * We may simply use static variable here to store init status, but we also want
+ * to avoid the situation when we reload U-boot via MDB after previous
+ * init is done but HW reset (board reset) isn't done. So let's store the
+ * init status in any unused register (i.e CREG_CPU_0_ENTRY) so status will
+ * survive after U-boot is reloaded via MDB.
+ */
+#define INIT_MARKER_REGISTER           ((void __iomem *)CREG_CPU_0_ENTRY)
+/* must be equal to INIT_MARKER_REGISTER reset value */
+#define INIT_MARKER_PENDING            0
+
+static bool init_marker_get(void)
+{
+       return readl(INIT_MARKER_REGISTER) != INIT_MARKER_PENDING;
+}
+
+static void init_mark_done(void)
+{
+       writel(~INIT_MARKER_PENDING, INIT_MARKER_REGISTER);
+}
+
 static int do_hsdk_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
-       static bool done = false;
        int ret;
 
+       if (board_mismatch()) {
+               printf("ERR: U-boot is not configured for this board!\n");
+               return CMD_RET_FAILURE;
+       }
+
        /* hsdk_init can be run only once */
-       if (done) {
+       if (init_marker_get()) {
                printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
                return CMD_RET_FAILURE;
        }
 
        ret = prepare_cpus();
        if (!ret)
-               done = true;
+               init_mark_done();
 
        return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
 }
@@ -911,10 +1114,13 @@ static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
        soc_clk_ctl("eth-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("usb-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("sdio-clk", NULL, CLK_PRINT | CLK_MHZ);
-/*     soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ); */
+       if (is_board_match_runtime(T_BOARD_HSDK_4XD))
+               soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("gfx-core-clk", NULL, CLK_PRINT | CLK_MHZ);
-       soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
-       soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
+       if (is_board_match_runtime(T_BOARD_HSDK)) {
+               soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
+               soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
+       }
        soc_clk_ctl("dmac-core-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("dmac-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("sdio-ref-clk", NULL, CLK_PRINT | CLK_MHZ);
@@ -929,15 +1135,19 @@ static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
        printf("\n");
 
        /* HDMI clock domain */
-/*     soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ); */
-/*     soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ); */
-/*     printf("\n"); */
+       if (is_board_match_runtime(T_BOARD_HSDK_4XD)) {
+               soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ);
+               soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ);
+               printf("\n");
+       }
 
        /* TUN clock domain */
        soc_clk_ctl("tun-pll", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("rom-clk", NULL, CLK_PRINT | CLK_MHZ);
        soc_clk_ctl("pwm-clk", NULL, CLK_PRINT | CLK_MHZ);
+       if (is_board_match_runtime(T_BOARD_HSDK_4XD))
+               soc_clk_ctl("timer-clk", NULL, CLK_PRINT | CLK_MHZ);
        printf("\n");
 
        return CMD_RET_SUCCESS;
@@ -1031,6 +1241,11 @@ int board_late_init(void)
 
 int checkboard(void)
 {
-       puts("Board: Synopsys ARC HS Development Kit\n");
+       printf("Board: Synopsys %s\n", board_name(get_board_type_runtime()));
+
+       if (board_mismatch())
+               printf("WARN: U-boot is configured NOT for this board but for %s!\n",
+                      board_name(get_board_type_config()));
+
        return 0;
 };
diff --git a/board/vocore/vocore2/Kconfig b/board/vocore/vocore2/Kconfig
new file mode 100644 (file)
index 0000000..baeff31
--- /dev/null
@@ -0,0 +1,12 @@
+if BOARD_VOCORE2
+
+config SYS_BOARD
+       default "vocore2"
+
+config SYS_VENDOR
+       default "vocore"
+
+config SYS_CONFIG_NAME
+       default "vocore2"
+
+endif
diff --git a/board/vocore/vocore2/MAINTAINERS b/board/vocore/vocore2/MAINTAINERS
new file mode 100644 (file)
index 0000000..8472351
--- /dev/null
@@ -0,0 +1,7 @@
+VOCORE_VOCORE2 BOARD
+M:     Mauro Condarelli <mc5686@mclink.it>
+S:     Maintained
+F: board/vocore/vocore2
+F: include/configs/vocore2.h
+F: configs/vocore2_defconfig
+F: arch/mips/dts/vocore_vocore2.dts
diff --git a/board/vocore/vocore2/Makefile b/board/vocore/vocore2/Makefile
new file mode 100644 (file)
index 0000000..70cd7a8
--- /dev/null
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y += board.o
diff --git a/board/vocore/vocore2/board.c b/board/vocore/vocore2/board.c
new file mode 100644 (file)
index 0000000..27e42d1
--- /dev/null
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Mauro Condarelli <mc5686@mclink.it>
+ *
+ * Nothing actually needed here
+ */
index 0bfb6081e7e13e99fd1a1632928e1221c6dd1d1c..009b7b58f32887dea97c78fbecb6f239289cc0d4 100644 (file)
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -1144,10 +1144,8 @@ static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        unsigned char *buf8;
        unsigned int i;
 
-       if (argc < 3 || argc > 4) {
-               printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
-               return 0;
-       }
+       if (argc < 3 || argc > 4)
+               return CMD_RET_USAGE;
 
        len = simple_strtoul(argv[2], NULL, 16);
        addr = simple_strtoul(argv[1], NULL, 16);
@@ -1174,7 +1172,8 @@ static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        unmap_sysmem(start);
        printf("%lu bytes filled with random data\n", len);
-       return 1;
+
+       return CMD_RET_SUCCESS;
 }
 #endif
 
index 3471c47be5b9c57faab995abbfd0e273a8d595a6..2e7a090588d93543f46ba720c5913052b2536a73 100644 (file)
@@ -110,6 +110,7 @@ obj-y += image.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
+obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
 obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
 obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o
diff --git a/common/fdt_region.c b/common/fdt_region.c
new file mode 100644 (file)
index 0000000..bf0a9be
--- /dev/null
@@ -0,0 +1,657 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause
+/*
+ * libfdt - Flat Device Tree manipulation
+ * Copyright (C) 2013 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <linux/libfdt_env.h>
+#include <fdt_region.h>
+
+#ifndef USE_HOSTCC
+#include <fdt.h>
+#include <linux/libfdt.h>
+#else
+#include "fdt_host.h"
+#endif
+
+#define FDT_MAX_DEPTH  32
+
+static int str_in_list(const char *str, char * const list[], int count)
+{
+       int i;
+
+       for (i = 0; i < count; i++)
+               if (!strcmp(list[i], str))
+                       return 1;
+
+       return 0;
+}
+
+int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
+                    char * const exc_prop[], int exc_prop_count,
+                    struct fdt_region region[], int max_regions,
+                    char *path, int path_len, int add_string_tab)
+{
+       int stack[FDT_MAX_DEPTH] = { 0 };
+       char *end;
+       int nextoffset = 0;
+       uint32_t tag;
+       int count = 0;
+       int start = -1;
+       int depth = -1;
+       int want = 0;
+       int base = fdt_off_dt_struct(fdt);
+
+       end = path;
+       *end = '\0';
+       do {
+               const struct fdt_property *prop;
+               const char *name;
+               const char *str;
+               int include = 0;
+               int stop_at = 0;
+               int offset;
+               int len;
+
+               offset = nextoffset;
+               tag = fdt_next_tag(fdt, offset, &nextoffset);
+               stop_at = nextoffset;
+
+               switch (tag) {
+               case FDT_PROP:
+                       include = want >= 2;
+                       stop_at = offset;
+                       prop = fdt_get_property_by_offset(fdt, offset, NULL);
+                       str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+                       if (str_in_list(str, exc_prop, exc_prop_count))
+                               include = 0;
+                       break;
+
+               case FDT_NOP:
+                       include = want >= 2;
+                       stop_at = offset;
+                       break;
+
+               case FDT_BEGIN_NODE:
+                       depth++;
+                       if (depth == FDT_MAX_DEPTH)
+                               return -FDT_ERR_BADSTRUCTURE;
+                       name = fdt_get_name(fdt, offset, &len);
+                       if (end - path + 2 + len >= path_len)
+                               return -FDT_ERR_NOSPACE;
+                       if (end != path + 1)
+                               *end++ = '/';
+                       strcpy(end, name);
+                       end += len;
+                       stack[depth] = want;
+                       if (want == 1)
+                               stop_at = offset;
+                       if (str_in_list(path, inc, inc_count))
+                               want = 2;
+                       else if (want)
+                               want--;
+                       else
+                               stop_at = offset;
+                       include = want;
+                       break;
+
+               case FDT_END_NODE:
+                       /* Depth must never go below -1 */
+                       if (depth < 0)
+                               return -FDT_ERR_BADSTRUCTURE;
+                       include = want;
+                       want = stack[depth--];
+                       while (end > path && *--end != '/')
+                               ;
+                       *end = '\0';
+                       break;
+
+               case FDT_END:
+                       include = 1;
+                       break;
+               }
+
+               if (include && start == -1) {
+                       /* Should we merge with previous? */
+                       if (count && count <= max_regions &&
+                           offset == region[count - 1].offset +
+                                       region[count - 1].size - base)
+                               start = region[--count].offset - base;
+                       else
+                               start = offset;
+               }
+
+               if (!include && start != -1) {
+                       if (count < max_regions) {
+                               region[count].offset = base + start;
+                               region[count].size = stop_at - start;
+                       }
+                       count++;
+                       start = -1;
+               }
+       } while (tag != FDT_END);
+
+       if (nextoffset != fdt_size_dt_struct(fdt))
+               return -FDT_ERR_BADLAYOUT;
+
+       /* Add a region for the END tag and the string table */
+       if (count < max_regions) {
+               region[count].offset = base + start;
+               region[count].size = nextoffset - start;
+               if (add_string_tab)
+                       region[count].size += fdt_size_dt_strings(fdt);
+       }
+       count++;
+
+       return count;
+}
+
+/**
+ * fdt_add_region() - Add a new region to our list
+ * @info:      State information
+ * @offset:    Start offset of region
+ * @size:      Size of region
+ *
+ * The region is added if there is space, but in any case we increment the
+ * count. If permitted, and the new region overlaps the last one, we merge
+ * them.
+ */
+static int fdt_add_region(struct fdt_region_state *info, int offset, int size)
+{
+       struct fdt_region *reg;
+
+       reg = info->region ? &info->region[info->count - 1] : NULL;
+       if (info->can_merge && info->count &&
+           info->count <= info->max_regions &&
+           reg && offset <= reg->offset + reg->size) {
+               reg->size = offset + size - reg->offset;
+       } else if (info->count++ < info->max_regions) {
+               if (reg) {
+                       reg++;
+                       reg->offset = offset;
+                       reg->size = size;
+               }
+       } else {
+               return -1;
+       }
+
+       return 0;
+}
+
+static int region_list_contains_offset(struct fdt_region_state *info,
+                                      const void *fdt, int target)
+{
+       struct fdt_region *reg;
+       int num;
+
+       target += fdt_off_dt_struct(fdt);
+       for (reg = info->region, num = 0; num < info->count; reg++, num++) {
+               if (target >= reg->offset && target < reg->offset + reg->size)
+                       return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * fdt_add_alias_regions() - Add regions covering the aliases that we want
+ *
+ * The /aliases node is not automatically included by fdtgrep unless the
+ * command-line arguments cause to be included (or not excluded). However
+ * aliases are special in that we generally want to include those which
+ * reference a node that fdtgrep includes.
+ *
+ * In fact we want to include only aliases for those nodes still included in
+ * the fdt, and drop the other aliases since they point to nodes that will not
+ * be present.
+ *
+ * This function scans the aliases and adds regions for those which we want
+ * to keep.
+ *
+ * @fdt: Device tree to scan
+ * @region: List of regions
+ * @count: Number of regions in the list so far (i.e. starting point for this
+ *     function)
+ * @max_regions: Maximum number of regions in @region list
+ * @info: Place to put the region state
+ * @return number of regions after processing, or -FDT_ERR_NOSPACE if we did
+ * not have enough room in the regions table for the regions we wanted to add.
+ */
+int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
+                         int max_regions, struct fdt_region_state *info)
+{
+       int base = fdt_off_dt_struct(fdt);
+       int node, node_end, offset;
+       int did_alias_header;
+
+       node = fdt_subnode_offset(fdt, 0, "aliases");
+       if (node < 0)
+               return -FDT_ERR_NOTFOUND;
+
+       /*
+        * Find the next node so that we know where the /aliases node ends. We
+        * need special handling if /aliases is the last node.
+        */
+       node_end = fdt_next_subnode(fdt, node);
+       if (node_end == -FDT_ERR_NOTFOUND)
+               /* Move back to the FDT_END_NODE tag of '/' */
+               node_end = fdt_size_dt_struct(fdt) - sizeof(fdt32_t) * 2;
+       else if (node_end < 0) /* other error */
+               return node_end;
+       node_end -= sizeof(fdt32_t);  /* Move to FDT_END_NODE tag of /aliases */
+
+       did_alias_header = 0;
+       info->region = region;
+       info->count = count;
+       info->can_merge = 0;
+       info->max_regions = max_regions;
+
+       for (offset = fdt_first_property_offset(fdt, node);
+            offset >= 0;
+            offset = fdt_next_property_offset(fdt, offset)) {
+               const struct fdt_property *prop;
+               const char *name;
+               int target, next;
+
+               prop = fdt_get_property_by_offset(fdt, offset, NULL);
+               name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+               target = fdt_path_offset(fdt, name);
+               if (!region_list_contains_offset(info, fdt, target))
+                       continue;
+               next = fdt_next_property_offset(fdt, offset);
+               if (next < 0)
+                       next = node_end;
+
+               if (!did_alias_header) {
+                       fdt_add_region(info, base + node, 12);
+                       did_alias_header = 1;
+               }
+               fdt_add_region(info, base + offset, next - offset);
+       }
+
+       /* Add the FDT_END_NODE tag */
+       if (did_alias_header)
+               fdt_add_region(info, base + node_end, sizeof(fdt32_t));
+
+       return info->count < max_regions ? info->count : -FDT_ERR_NOSPACE;
+}
+
+/**
+ * fdt_include_supernodes() - Include supernodes required by this node
+ * @info:      State information
+ * @depth:     Current stack depth
+ *
+ * When we decided to include a node or property which is not at the top
+ * level, this function forces the inclusion of higher level nodes. For
+ * example, given this tree:
+ *
+ * / {
+ *     testing {
+ *     }
+ * }
+ *
+ * If we decide to include testing then we need the root node to have a valid
+ * tree. This function adds those regions.
+ */
+static int fdt_include_supernodes(struct fdt_region_state *info, int depth)
+{
+       int base = fdt_off_dt_struct(info->fdt);
+       int start, stop_at;
+       int i;
+
+       /*
+        * Work down the stack looking for supernodes that we didn't include.
+        * The algortihm here is actually pretty simple, since we know that
+        * no previous subnode had to include these nodes, or if it did, we
+        * marked them as included (on the stack) already.
+        */
+       for (i = 0; i <= depth; i++) {
+               if (!info->stack[i].included) {
+                       start = info->stack[i].offset;
+
+                       /* Add the FDT_BEGIN_NODE tag of this supernode */
+                       fdt_next_tag(info->fdt, start, &stop_at);
+                       if (fdt_add_region(info, base + start, stop_at - start))
+                               return -1;
+
+                       /* Remember that this supernode is now included */
+                       info->stack[i].included = 1;
+                       info->can_merge = 1;
+               }
+
+               /* Force (later) generation of the FDT_END_NODE tag */
+               if (!info->stack[i].want)
+                       info->stack[i].want = WANT_NODES_ONLY;
+       }
+
+       return 0;
+}
+
+enum {
+       FDT_DONE_NOTHING,
+       FDT_DONE_MEM_RSVMAP,
+       FDT_DONE_STRUCT,
+       FDT_DONE_END,
+       FDT_DONE_STRINGS,
+       FDT_DONE_ALL,
+};
+
+int fdt_first_region(const void *fdt,
+               int (*h_include)(void *priv, const void *fdt, int offset,
+                                int type, const char *data, int size),
+               void *priv, struct fdt_region *region,
+               char *path, int path_len, int flags,
+               struct fdt_region_state *info)
+{
+       struct fdt_region_ptrs *p = &info->ptrs;
+
+       /* Set up our state */
+       info->fdt = fdt;
+       info->can_merge = 1;
+       info->max_regions = 1;
+       info->start = -1;
+       p->want = WANT_NOTHING;
+       p->end = path;
+       *p->end = '\0';
+       p->nextoffset = 0;
+       p->depth = -1;
+       p->done = FDT_DONE_NOTHING;
+
+       return fdt_next_region(fdt, h_include, priv, region,
+                              path, path_len, flags, info);
+}
+
+/***********************************************************************
+ *
+ *     Theory of operation
+ *
+ * Note: in this description 'included' means that a node (or other part
+ * of the tree) should be included in the region list, i.e. it will have
+ * a region which covers its part of the tree.
+ *
+ * This function maintains some state from the last time it is called.
+ * It checks the next part of the tree that it is supposed to look at
+ * (p.nextoffset) to see if that should be included or not. When it
+ * finds something to include, it sets info->start to its offset. This
+ * marks the start of the region we want to include.
+ *
+ * Once info->start is set to the start (i.e. not -1), we continue
+ * scanning until we find something that we don't want included. This
+ * will be the end of a region. At this point we can close off the
+ * region and add it to the list. So we do so, and reset info->start
+ * to -1.
+ *
+ * One complication here is that we want to merge regions. So when we
+ * come to add another region later, we may in fact merge it with the
+ * previous one if one ends where the other starts.
+ *
+ * The function fdt_add_region() will return -1 if it fails to add the
+ * region, because we already have a region ready to be returned, and
+ * the new one cannot be merged in with it. In this case, we must return
+ * the region we found, and wait for another call to this function.
+ * When it comes, we will repeat the processing of the tag and again
+ * try to add a region. This time it will succeed.
+ *
+ * The current state of the pointers (stack, offset, etc.) is maintained
+ * in a ptrs member. At the start of every loop iteration we make a copy
+ * of it.  The copy is then updated as the tag is processed. Only if we
+ * get to the end of the loop iteration (and successfully call
+ * fdt_add_region() if we need to) can we commit the changes we have
+ * made to these pointers. For example, if we see an FDT_END_NODE tag,
+ * we will decrement the depth value. But if we need to add a region
+ * for this tag (let's say because the previous tag is included and this
+ * FDT_END_NODE tag is not included) then we will only commit the result
+ * if we were able to add the region. That allows us to retry again next
+ * time.
+ *
+ * We keep track of a variable called 'want' which tells us what we want
+ * to include when there is no specific information provided by the
+ * h_include function for a particular property. This basically handles
+ * the inclusion of properties which are pulled in by virtue of the node
+ * they are in. So if you include a node, its properties are also
+ * included.  In this case 'want' will be WANT_NODES_AND_PROPS. The
+ * FDT_REG_DIRECT_SUBNODES feature also makes use of 'want'. While we
+ * are inside the subnode, 'want' will be set to WANT_NODES_ONLY, so
+ * that only the subnode's FDT_BEGIN_NODE and FDT_END_NODE tags will be
+ * included, and properties will be skipped. If WANT_NOTHING is
+ * selected, then we will just rely on what the h_include() function
+ * tells us.
+ *
+ * Using 'want' we work out 'include', which tells us whether this
+ * current tag should be included or not. As you can imagine, if the
+ * value of 'include' changes, that means we are on a boundary between
+ * nodes to include and nodes to exclude. At this point we either close
+ * off a previous region and add it to the list, or mark the start of a
+ * new region.
+ *
+ * Apart from the nodes, we have mem_rsvmap, the FDT_END tag and the
+ * string list. Each of these dealt with as a whole (i.e. we create a
+ * region for each if it is to be included). For mem_rsvmap we don't
+ * allow it to merge with the first struct region. For the stringlist,
+ * we don't allow it to merge with the last struct region (which
+ * contains at minimum the FDT_END tag).
+ *
+ *********************************************************************/
+
+int fdt_next_region(const void *fdt,
+               int (*h_include)(void *priv, const void *fdt, int offset,
+                                int type, const char *data, int size),
+               void *priv, struct fdt_region *region,
+               char *path, int path_len, int flags,
+               struct fdt_region_state *info)
+{
+       int base = fdt_off_dt_struct(fdt);
+       int last_node = 0;
+       const char *str;
+
+       info->region = region;
+       info->count = 0;
+       if (info->ptrs.done < FDT_DONE_MEM_RSVMAP &&
+           (flags & FDT_REG_ADD_MEM_RSVMAP)) {
+               /* Add the memory reserve map into its own region */
+               if (fdt_add_region(info, fdt_off_mem_rsvmap(fdt),
+                                  fdt_off_dt_struct(fdt) -
+                                  fdt_off_mem_rsvmap(fdt)))
+                       return 0;
+               info->can_merge = 0;    /* Don't allow merging with this */
+               info->ptrs.done = FDT_DONE_MEM_RSVMAP;
+       }
+
+       /*
+        * Work through the tags one by one, deciding whether each needs to
+        * be included or not. We set the variable 'include' to indicate our
+        * decision. 'want' is used to track what we want to include - it
+        * allows us to pick up all the properties (and/or subnode tags) of
+        * a node.
+        */
+       while (info->ptrs.done < FDT_DONE_STRUCT) {
+               const struct fdt_property *prop;
+               struct fdt_region_ptrs p;
+               const char *name;
+               int include = 0;
+               int stop_at = 0;
+               uint32_t tag;
+               int offset;
+               int val;
+               int len;
+
+               /*
+                * Make a copy of our pointers. If we make it to the end of
+                * this block then we will commit them back to info->ptrs.
+                * Otherwise we can try again from the same starting state
+                * next time we are called.
+                */
+               p = info->ptrs;
+
+               /*
+                * Find the tag, and the offset of the next one. If we need to
+                * stop including tags, then by default we stop *after*
+                * including the current tag
+                */
+               offset = p.nextoffset;
+               tag = fdt_next_tag(fdt, offset, &p.nextoffset);
+               stop_at = p.nextoffset;
+
+               switch (tag) {
+               case FDT_PROP:
+                       stop_at = offset;
+                       prop = fdt_get_property_by_offset(fdt, offset, NULL);
+                       str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+                       val = h_include(priv, fdt, last_node, FDT_IS_PROP, str,
+                                           strlen(str) + 1);
+                       if (val == -1) {
+                               include = p.want >= WANT_NODES_AND_PROPS;
+                       } else {
+                               include = val;
+                               /*
+                                * Make sure we include the } for this block.
+                                * It might be more correct to have this done
+                                * by the call to fdt_include_supernodes() in
+                                * the case where it adds the node we are
+                                * currently in, but this is equivalent.
+                                */
+                               if ((flags & FDT_REG_SUPERNODES) && val &&
+                                   !p.want)
+                                       p.want = WANT_NODES_ONLY;
+                       }
+
+                       /* Value grepping is not yet supported */
+                       break;
+
+               case FDT_NOP:
+                       include = p.want >= WANT_NODES_AND_PROPS;
+                       stop_at = offset;
+                       break;
+
+               case FDT_BEGIN_NODE:
+                       last_node = offset;
+                       p.depth++;
+                       if (p.depth == FDT_MAX_DEPTH)
+                               return -FDT_ERR_BADSTRUCTURE;
+                       name = fdt_get_name(fdt, offset, &len);
+                       if (p.end - path + 2 + len >= path_len)
+                               return -FDT_ERR_NOSPACE;
+
+                       /* Build the full path of this node */
+                       if (p.end != path + 1)
+                               *p.end++ = '/';
+                       strcpy(p.end, name);
+                       p.end += len;
+                       info->stack[p.depth].want = p.want;
+                       info->stack[p.depth].offset = offset;
+
+                       /*
+                        * If we are not intending to include this node unless
+                        * it matches, make sure we stop *before* its tag.
+                        */
+                       if (p.want == WANT_NODES_ONLY ||
+                           !(flags & (FDT_REG_DIRECT_SUBNODES |
+                                      FDT_REG_ALL_SUBNODES))) {
+                               stop_at = offset;
+                               p.want = WANT_NOTHING;
+                       }
+                       val = h_include(priv, fdt, offset, FDT_IS_NODE, path,
+                                       p.end - path + 1);
+
+                       /* Include this if requested */
+                       if (val) {
+                               p.want = (flags & FDT_REG_ALL_SUBNODES) ?
+                                       WANT_ALL_NODES_AND_PROPS :
+                                       WANT_NODES_AND_PROPS;
+                       }
+
+                       /* If not requested, decay our 'p.want' value */
+                       else if (p.want) {
+                               if (p.want != WANT_ALL_NODES_AND_PROPS)
+                                       p.want--;
+
+                       /* Not including this tag, so stop now */
+                       } else {
+                               stop_at = offset;
+                       }
+
+                       /*
+                        * Decide whether to include this tag, and update our
+                        * stack with the state for this node
+                        */
+                       include = p.want;
+                       info->stack[p.depth].included = include;
+                       break;
+
+               case FDT_END_NODE:
+                       include = p.want;
+                       if (p.depth < 0)
+                               return -FDT_ERR_BADSTRUCTURE;
+
+                       /*
+                        * If we don't want this node, stop right away, unless
+                        * we are including subnodes
+                        */
+                       if (!p.want && !(flags & FDT_REG_DIRECT_SUBNODES))
+                               stop_at = offset;
+                       p.want = info->stack[p.depth].want;
+                       p.depth--;
+                       while (p.end > path && *--p.end != '/')
+                               ;
+                       *p.end = '\0';
+                       break;
+
+               case FDT_END:
+                       /* We always include the end tag */
+                       include = 1;
+                       p.done = FDT_DONE_STRUCT;
+                       break;
+               }
+
+               /* If this tag is to be included, mark it as region start */
+               if (include && info->start == -1) {
+                       /* Include any supernodes required by this one */
+                       if (flags & FDT_REG_SUPERNODES) {
+                               if (fdt_include_supernodes(info, p.depth))
+                                       return 0;
+                       }
+                       info->start = offset;
+               }
+
+               /*
+                * If this tag is not to be included, finish up the current
+                * region.
+                */
+               if (!include && info->start != -1) {
+                       if (fdt_add_region(info, base + info->start,
+                                          stop_at - info->start))
+                               return 0;
+                       info->start = -1;
+                       info->can_merge = 1;
+               }
+
+               /* If we have made it this far, we can commit our pointers */
+               info->ptrs = p;
+       }
+
+       /* Add a region for the END tag and a separate one for string table */
+       if (info->ptrs.done < FDT_DONE_END) {
+               if (info->ptrs.nextoffset != fdt_size_dt_struct(fdt))
+                       return -FDT_ERR_BADSTRUCTURE;
+
+               if (fdt_add_region(info, base + info->start,
+                                  info->ptrs.nextoffset - info->start))
+                       return 0;
+               info->ptrs.done++;
+       }
+       if (info->ptrs.done < FDT_DONE_STRINGS) {
+               if (flags & FDT_REG_ADD_STRING_TAB) {
+                       info->can_merge = 0;
+                       if (fdt_off_dt_strings(fdt) <
+                           base + info->ptrs.nextoffset)
+                               return -FDT_ERR_BADLAYOUT;
+                       if (fdt_add_region(info, fdt_off_dt_strings(fdt),
+                                          fdt_size_dt_strings(fdt)))
+                               return 0;
+               }
+               info->ptrs.done++;
+       }
+
+       return info->count > 0 ? 0 : -FDT_ERR_NOTFOUND;
+}
index 490566ca90089106e1914df95512e2c06d400cf2..3e735785949e9d642c00624164e8f03933ed6749 100644 (file)
@@ -11,6 +11,7 @@
 #include <malloc.h>
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
+#include <fdt_region.h>
 #include <image.h>
 #include <u-boot/rsa.h>
 #include <u-boot/rsa-checksum.h>
index ffb3cd6933223a1622e2cc7e2543f3f5a86586c8..c5b9b489ca3775f2376a72fa8747e60b5cee1aa3 100644 (file)
@@ -233,7 +233,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
        ldev = log_device_find_by_name(drv_name);
        if (!ldev)
                return -ENOENT;
-       filt = (struct log_filter *)calloc(1, sizeof(*filt));
+       filt = calloc(1, sizeof(*filt));
        if (!filt)
                return -ENOMEM;
 
index eaa57f5ce5e48646b77640ab5197281b3cbbabd9..c576a78126818e54269045995f9048831d1fa12b 100644 (file)
@@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o
 obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o
+obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_SUPPORT) += spl_legacy.o
 obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += spl_ymodem.o
index 932e6ab98ac4cd5d4c0fd5263bcc9c54183f1ff6..b0f0e1557b923f8be107e8bdee42f376295f3657 100644 (file)
@@ -254,6 +254,14 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
 }
 #endif
 
+__weak int spl_parse_legacy_header(struct spl_image_info *spl_image,
+                                  const struct image_header *header)
+{
+       /* LEGACY image not supported */
+       debug("Legacy boot image support not enabled, proceeding to other boot methods\n");
+       return -EINVAL;
+}
+
 int spl_parse_image_header(struct spl_image_info *spl_image,
                           const struct image_header *header)
 {
@@ -264,51 +272,11 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
                return ret;
 #endif
        if (image_get_magic(header) == IH_MAGIC) {
-#ifdef CONFIG_SPL_LEGACY_IMAGE_SUPPORT
-               u32 header_size = sizeof(struct image_header);
-
-#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
-               /* check uImage header CRC */
-               if (!image_check_hcrc(header)) {
-                       puts("SPL: Image header CRC check failed!\n");
-                       return -EINVAL;
-               }
-#endif
-
-               if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
-                       /*
-                        * On some system (e.g. powerpc), the load-address and
-                        * entry-point is located at address 0. We can't load
-                        * to 0-0x40. So skip header in this case.
-                        */
-                       spl_image->load_addr = image_get_load(header);
-                       spl_image->entry_point = image_get_ep(header);
-                       spl_image->size = image_get_data_size(header);
-               } else {
-                       spl_image->entry_point = image_get_ep(header);
-                       /* Load including the header */
-                       spl_image->load_addr = image_get_load(header) -
-                               header_size;
-                       spl_image->size = image_get_data_size(header) +
-                               header_size;
-               }
-#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
-               /* store uImage data length and CRC to check later */
-               spl_image->dcrc_data = image_get_load(header);
-               spl_image->dcrc_length = image_get_data_size(header);
-               spl_image->dcrc = image_get_dcrc(header);
-#endif
+               int ret;
 
-               spl_image->os = image_get_os(header);
-               spl_image->name = image_get_name(header);
-               debug(SPL_TPL_PROMPT
-                     "payload image: %32s load addr: 0x%lx size: %d\n",
-                     spl_image->name, spl_image->load_addr, spl_image->size);
-#else
-               /* LEGACY image not supported */
-               debug("Legacy boot image support not enabled, proceeding to other boot methods\n");
-               return -EINVAL;
-#endif
+               ret = spl_parse_legacy_header(spl_image, header);
+               if (ret)
+                       return ret;
        } else {
 #ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE
                /*
diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
new file mode 100644 (file)
index 0000000..29d3ec7
--- /dev/null
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Stefan Roese <sr@denx.de>
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <spl.h>
+
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
+#define LZMA_LEN       (1 << 20)
+
+int spl_parse_legacy_header(struct spl_image_info *spl_image,
+                           const struct image_header *header)
+{
+       u32 header_size = sizeof(struct image_header);
+
+       /* check uImage header CRC */
+       if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK) &&
+           !image_check_hcrc(header)) {
+               puts("SPL: Image header CRC check failed!\n");
+               return -EINVAL;
+       }
+
+       if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
+               /*
+                * On some system (e.g. powerpc), the load-address and
+                * entry-point is located at address 0. We can't load
+                * to 0-0x40. So skip header in this case.
+                */
+               spl_image->load_addr = image_get_load(header);
+               spl_image->entry_point = image_get_ep(header);
+               spl_image->size = image_get_data_size(header);
+       } else {
+               spl_image->entry_point = image_get_ep(header);
+               /* Load including the header */
+               spl_image->load_addr = image_get_load(header) -
+                       header_size;
+               spl_image->size = image_get_data_size(header) +
+                       header_size;
+       }
+
+#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
+       /* store uImage data length and CRC to check later */
+       spl_image->dcrc_data = image_get_load(header);
+       spl_image->dcrc_length = image_get_data_size(header);
+       spl_image->dcrc = image_get_dcrc(header);
+#endif
+
+       spl_image->os = image_get_os(header);
+       spl_image->name = image_get_name(header);
+       debug(SPL_TPL_PROMPT
+             "payload image: %32s load addr: 0x%lx size: %d\n",
+             spl_image->name, spl_image->load_addr, spl_image->size);
+
+       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 image_header *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_load_info *load, ulong header)
+{
+       __maybe_unused SizeT lzma_len;
+       __maybe_unused void *src;
+       struct image_header hdr;
+       ulong dataptr;
+       int ret;
+
+       /* Read header into local struct */
+       load->read(load, header, sizeof(hdr), &hdr);
+
+       ret = spl_parse_image_header(spl_image, &hdr);
+       if (ret)
+               return ret;
+
+       dataptr = header + sizeof(hdr);
+
+       /* Read image */
+       switch (spl_image_get_comp(&hdr)) {
+       case IH_COMP_NONE:
+               load->read(load, dataptr, spl_image->size,
+                          (void *)(unsigned long)spl_image->load_addr);
+               break;
+
+       case IH_COMP_LZMA:
+               lzma_len = LZMA_LEN;
+
+               debug("LZMA: Decompressing %08lx to %08lx\n",
+                     dataptr, spl_image->load_addr);
+               src = malloc(spl_image->size);
+               if (!src) {
+                       printf("Unable to allocate %d bytes for LZMA\n",
+                              spl_image->size);
+                       return -ENOMEM;
+               }
+
+               load->read(load, dataptr, spl_image->size, src);
+               ret = lzmaBuffToBuffDecompress((void *)spl_image->load_addr,
+                                              &lzma_len, src, 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)));
+               return -EINVAL;
+       }
+
+       return 0;
+}
index b1e79b9ded6258f44070e4e4d64bcddd8ba184a3..3f03ffe6a333f410fb7bd29dd50aa3a65ecad830 100644 (file)
@@ -24,7 +24,6 @@ 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)
 {
-       int ret;
        __maybe_unused const struct image_header *header;
        __maybe_unused struct spl_load_info load;
 
@@ -43,6 +42,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
                header = (const struct image_header *)CONFIG_SYS_OS_BASE;
 #ifdef CONFIG_SPL_LOAD_FIT
                if (image_get_magic(header) == FDT_MAGIC) {
+                       int ret;
+
                        debug("Found FIT\n");
                        load.bl_len = 1;
                        load.read = spl_nor_load_read;
@@ -61,6 +62,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 #endif
                if (image_get_os(header) == IH_OS_LINUX) {
                        /* happy - was a Linux */
+                       int ret;
 
                        ret = spl_parse_image_header(spl_image, header);
                        if (ret)
@@ -93,11 +95,9 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
                debug("Found FIT format U-Boot\n");
                load.bl_len = 1;
                load.read = spl_nor_load_read;
-               ret = spl_load_simple_fit(spl_image, &load,
-                                         spl_nor_get_uboot_base(),
-                                         (void *)header);
-
-               return ret;
+               return spl_load_simple_fit(spl_image, &load,
+                                          spl_nor_get_uboot_base(),
+                                          (void *)header);
        }
 #endif
        if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
@@ -107,14 +107,13 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
                                              spl_nor_get_uboot_base());
        }
 
-       ret = spl_parse_image_header(spl_image,
-                       (const struct image_header *)spl_nor_get_uboot_base());
-       if (ret)
-               return ret;
-
-       memcpy((void *)(unsigned long)spl_image->load_addr,
-              (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
-              spl_image->size);
+       /* Legacy image handling */
+       if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
+               load.bl_len = 1;
+               load.read = spl_nor_load_read;
+               return spl_load_legacy_img(spl_image, &load,
+                                          spl_nor_get_uboot_base());
+       }
 
        return 0;
 }
diff --git a/configs/gardena-smart-gateway-mt7688-ram_defconfig b/configs/gardena-smart-gateway-mt7688-ram_defconfig
deleted file mode 100644 (file)
index dbc94b4..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x80010000
-CONFIG_ENV_SIZE=0x10000
-CONFIG_ENV_SECT_SIZE=0x10000
-CONFIG_ENV_OFFSET=0xA0000
-CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
-CONFIG_NR_DRAM_BANKS=1
-CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
-CONFIG_ENV_OFFSET_REDUND=0xB0000
-CONFIG_ARCH_MTMIPS=y
-# CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-CONFIG_MIPS_BOOT_FDT=y
-CONFIG_ENV_VARS_UBOOT_CONFIG=y
-CONFIG_FIT=y
-CONFIG_FIT_SIGNATURE=y
-CONFIG_LEGACY_IMAGE_FORMAT=y
-CONFIG_OF_STDOUT_VIA_ALIAS=y
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="cp.b 83000000 84000000 10000 && dhcp uEnv.txt && env import -t ${fileaddr} ${filesize} && run do_u_boot_init; reset"
-CONFIG_USE_PREBOOT=y
-CONFIG_SYS_CONSOLE_INFO_QUIET=y
-CONFIG_VERSION_VARIABLE=y
-CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_HUSH_PARSER=y
-CONFIG_CMD_LICENSE=y
-# CONFIG_CMD_ELF is not set
-# CONFIG_CMD_XIMG is not set
-CONFIG_CMD_MEMINFO=y
-# CONFIG_CMD_FLASH is not set
-CONFIG_CMD_GPIO=y
-# CONFIG_CMD_LOADS is not set
-CONFIG_CMD_MTD=y
-CONFIG_CMD_SPI=y
-CONFIG_CMD_WDT=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MII=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_BOOTCOUNT=y
-CONFIG_CMD_TIME=y
-CONFIG_CMD_UUID=y
-CONFIG_CMD_MTDPARTS=y
-CONFIG_MTDIDS_DEFAULT="spi-nand0=spi0.1,nor0=spi0.0"
-CONFIG_MTDPARTS_DEFAULT="spi0.0:640k(uboot),64k(uboot_env0),64k(uboot_env1),64k(factory),-(unused);spi0.1:-(nand)"
-CONFIG_CMD_UBI=y
-CONFIG_DEFAULT_DEVICE_TREE="gardena-smart-gateway-mt7688"
-CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
-CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
-# CONFIG_DM_DEVICE_REMOVE is not set
-CONFIG_HAVE_BLOCK_DEVICE=y
-CONFIG_BOOTCOUNT_LIMIT=y
-CONFIG_LED=y
-CONFIG_LED_BLINK=y
-CONFIG_LED_GPIO=y
-CONFIG_MTD=y
-CONFIG_DM_MTD=y
-CONFIG_MTD_SPI_NAND=y
-CONFIG_SPI_FLASH_GIGADEVICE=y
-CONFIG_SPI_FLASH_MACRONIX=y
-CONFIG_SPI_FLASH_SPANSION=y
-CONFIG_SPI_FLASH_STMICRO=y
-CONFIG_SPI_FLASH_WINBOND=y
-CONFIG_SPI_FLASH_XMC=y
-CONFIG_SPI_FLASH_MTD=y
-CONFIG_MTD_UBI_BEB_LIMIT=22
-CONFIG_MT7628_ETH=y
-CONFIG_PHY=y
-CONFIG_SPI=y
-CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
-CONFIG_WDT=y
-CONFIG_WDT_MT7621=y
-CONFIG_LZMA=y
index 23d8ddb128b1f851345b6c566d1b0f2033210b5c..41496f739bdac2ecadca0bd6b7a6d40970b54db9 100644 (file)
@@ -1,16 +1,18 @@
 CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x9c000000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x10000
-CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0xA0000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
 CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
 CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
 CONFIG_ENV_OFFSET_REDUND=0xB0000
 CONFIG_ARCH_MTMIPS=y
-CONFIG_BOOT_ROM=y
-CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
-CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
@@ -24,6 +26,8 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_VERSION_VARIABLE=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_LICENSE=y
 # CONFIG_CMD_ELF is not set
@@ -50,6 +54,7 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_DM=y
 # CONFIG_DM_DEVICE_REMOVE is not set
 CONFIG_HAVE_BLOCK_DEVICE=y
 CONFIG_BOOTCOUNT_LIMIT=y
@@ -71,7 +76,7 @@ CONFIG_MT7628_ETH=y
 CONFIG_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_WDT=y
 CONFIG_WDT_MT7621=y
 CONFIG_LZMA=y
+CONFIG_SPL_LZMA=y
diff --git a/configs/hsdk_4xd_defconfig b/configs/hsdk_4xd_defconfig
new file mode 100644 (file)
index 0000000..64832ec
--- /dev/null
@@ -0,0 +1,67 @@
+CONFIG_ARC=y
+CONFIG_ISA_ARCV2=y
+CONFIG_TARGET_HSDK=y
+CONFIG_BOARD_HSDK_4XD=y
+CONFIG_SYS_TEXT_BASE=0x81000000
+CONFIG_DM_GPIO=y
+CONFIG_DEBUG_UART_BASE=0xf0005000
+CONFIG_DEBUG_UART_CLOCK=33333333
+CONFIG_SYS_CLK_FREQ=500000000
+CONFIG_DEBUG_UART=y
+CONFIG_USE_BOOTARGS=y
+CONFIG_BOOTARGS="console=ttyS0,115200n8"
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_BOARD_EARLY_INIT_R=y
+CONFIG_HUSH_PARSER=y
+CONFIG_SYS_PROMPT="hsdk-4xd# "
+CONFIG_CMD_ENV_FLAGS=y
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_MMC=y
+CONFIG_CMD_SPI=y
+CONFIG_CMD_USB=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_CACHE=y
+CONFIG_CMD_EXT2=y
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_EXT4_WRITE=y
+CONFIG_CMD_FAT=y
+CONFIG_OF_CONTROL=y
+CONFIG_OF_EMBED=y
+CONFIG_DEFAULT_DEVICE_TREE="hsdk-4xd"
+CONFIG_ENV_IS_IN_FAT=y
+CONFIG_ENV_FAT_INTERFACE="mmc"
+CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_DM=y
+CONFIG_CLK_HSDK=y
+CONFIG_HSDK_CREG_GPIO=y
+CONFIG_MMC=y
+CONFIG_DM_MMC=y
+CONFIG_MMC_DW=y
+CONFIG_MMC_DW_SNPS=y
+CONFIG_MTD=y
+CONFIG_DM_SPI_FLASH=y
+CONFIG_SPI_FLASH_SST=y
+CONFIG_DM_ETH=y
+CONFIG_ETH_DESIGNWARE=y
+CONFIG_MII=y
+CONFIG_DM_RESET=y
+CONFIG_DM_SERIAL=y
+CONFIG_DEBUG_UART_SHIFT=2
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_SYS_NS16550=y
+CONFIG_SPI=y
+CONFIG_DM_SPI=y
+CONFIG_DESIGNWARE_SPI=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_GENERIC=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB_OHCI_GENERIC=y
+CONFIG_USB_STORAGE=y
+CONFIG_USE_PRIVATE_LIBGCC=y
+CONFIG_PANIC_HANG=y
diff --git a/configs/linkit-smart-7688-ram_defconfig b/configs/linkit-smart-7688-ram_defconfig
deleted file mode 100644 (file)
index d1691ab..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x80010000
-CONFIG_ENV_SIZE=0x4000
-CONFIG_ENV_SECT_SIZE=0x10000
-CONFIG_ENV_OFFSET=0x80000
-CONFIG_NR_DRAM_BANKS=1
-CONFIG_ARCH_MTMIPS=y
-CONFIG_BOARD_LINKIT_SMART_7688=y
-# CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-CONFIG_MIPS_BOOT_FDT=y
-CONFIG_FIT=y
-CONFIG_FIT_SIGNATURE=y
-CONFIG_LEGACY_IMAGE_FORMAT=y
-CONFIG_OF_STDOUT_VIA_ALIAS=y
-CONFIG_SYS_CONSOLE_INFO_QUIET=y
-CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_HUSH_PARSER=y
-CONFIG_CMD_LICENSE=y
-# CONFIG_CMD_ELF is not set
-# CONFIG_CMD_XIMG is not set
-CONFIG_CMD_MEMINFO=y
-# CONFIG_CMD_FLASH is not set
-CONFIG_CMD_GPIO=y
-# CONFIG_CMD_LOADS is not set
-CONFIG_CMD_MTD=y
-CONFIG_CMD_PART=y
-CONFIG_CMD_SPI=y
-CONFIG_CMD_USB=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MII=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_TIME=y
-CONFIG_CMD_FS_GENERIC=y
-# CONFIG_DOS_PARTITION is not set
-CONFIG_DEFAULT_DEVICE_TREE="linkit-smart-7688"
-CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
-# CONFIG_DM_DEVICE_REMOVE is not set
-CONFIG_BLK=y
-CONFIG_LED=y
-CONFIG_LED_BLINK=y
-CONFIG_LED_GPIO=y
-CONFIG_MTD=y
-CONFIG_SPI_FLASH_GIGADEVICE=y
-CONFIG_SPI_FLASH_MACRONIX=y
-CONFIG_SPI_FLASH_SPANSION=y
-CONFIG_SPI_FLASH_STMICRO=y
-CONFIG_SPI_FLASH_WINBOND=y
-CONFIG_SPI_FLASH_MTD=y
-CONFIG_MT7628_ETH=y
-CONFIG_PHY=y
-CONFIG_MT76X8_USB_PHY=y
-CONFIG_SPI=y
-CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
-CONFIG_USB=y
-CONFIG_DM_USB=y
-CONFIG_USB_EHCI_HCD=y
-CONFIG_USB_EHCI_GENERIC=y
-CONFIG_USB_STORAGE=y
-CONFIG_FS_EXT4=y
-CONFIG_FS_FAT=y
-CONFIG_LZMA=y
-CONFIG_LZO=y
index a567c0c507e8394162848d3a964311a3e0048f39..8ec66938cdce8175990f3846522b00ee143673f8 100644 (file)
@@ -1,14 +1,16 @@
 CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x9c000000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x4000
-CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0x80000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
 CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
 CONFIG_ARCH_MTMIPS=y
 CONFIG_BOARD_LINKIT_SMART_7688=y
-CONFIG_BOOT_ROM=y
-CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
-CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_FIT=y
@@ -17,6 +19,8 @@ CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_OF_STDOUT_VIA_ALIAS=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_LICENSE=y
 # CONFIG_CMD_ELF is not set
@@ -40,6 +44,7 @@ CONFIG_DEFAULT_DEVICE_TREE="linkit-smart-7688"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_DM=y
 # CONFIG_DM_DEVICE_REMOVE is not set
 CONFIG_BLK=y
 CONFIG_LED=y
@@ -57,7 +62,6 @@ CONFIG_PHY=y
 CONFIG_MT76X8_USB_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EHCI_HCD=y
@@ -67,3 +71,4 @@ CONFIG_FS_EXT4=y
 CONFIG_FS_FAT=y
 CONFIG_LZMA=y
 CONFIG_LZO=y
+CONFIG_SPL_LZMA=y
diff --git a/configs/mt7628_rfb_defconfig b/configs/mt7628_rfb_defconfig
new file mode 100644 (file)
index 0000000..f444cf9
--- /dev/null
@@ -0,0 +1,47 @@
+CONFIG_MIPS=y
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_ENV_SIZE=0x1000
+CONFIG_ENV_OFFSET=0x30000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
+CONFIG_ARCH_MTMIPS=y
+CONFIG_BOARD_MT7628_RFB=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
+CONFIG_MIPS_BOOT_FDT=y
+CONFIG_FIT=y
+# CONFIG_ARCH_FIXUP_FDT_MEMORY is not set
+CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
+# CONFIG_CMD_ELF is not set
+# CONFIG_CMD_XIMG is not set
+# CONFIG_CMD_CRC32 is not set
+# CONFIG_CMD_DM is not set
+CONFIG_CMD_GPIO=y
+# CONFIG_CMD_LOADS is not set
+CONFIG_CMD_SPI=y
+# CONFIG_CMD_NFS is not set
+# CONFIG_PARTITIONS is not set
+CONFIG_DEFAULT_DEVICE_TREE="mediatek,mt7628-rfb"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_NET_RANDOM_ETHADDR=y
+# CONFIG_INPUT is not set
+CONFIG_SPI_FLASH_EON=y
+CONFIG_SPI_FLASH_GIGADEVICE=y
+CONFIG_SPI_FLASH_ISSI=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_SPI_FLASH_SPANSION=y
+CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_XMC=y
+CONFIG_MT7628_ETH=y
+# CONFIG_SPECIFY_CONSOLE_INDEX is not set
+CONFIG_SPI=y
+CONFIG_MT7621_SPI=y
+CONFIG_LZMA=y
+CONFIG_SPL_LZMA=y
index ca34457ddd1601e0bfbd9248362a45f38f1d03c7..35ae18fac0031e19bc2497106eba27f8c4b99f91 100644 (file)
@@ -27,6 +27,7 @@ CONFIG_CMD_GREPENV=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_MTDIDS_DEFAULT="nor0=ff705000.spi.0"
@@ -49,4 +50,7 @@ CONFIG_SPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_DESIGNWARE_APB_TIMER=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_USB_DWC2=y
 # CONFIG_SPL_WDT is not set
diff --git a/configs/vocore2_defconfig b/configs/vocore2_defconfig
new file mode 100644 (file)
index 0000000..6cacec0
--- /dev/null
@@ -0,0 +1,101 @@
+CONFIG_MIPS=y
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_ENV_SIZE=0x1000
+CONFIG_ENV_OFFSET=0x04e000
+CONFIG_ENV_SECT_SIZE=0x1000
+CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
+CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
+CONFIG_ARCH_MTMIPS=y
+CONFIG_BOARD_VOCORE2=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
+CONFIG_MIPS_BOOT_FDT=y
+CONFIG_ENV_VARS_UBOOT_CONFIG=y
+CONFIG_SYS_BOOT_GET_CMDLINE=y
+CONFIG_SYS_BOOT_GET_KBD=y
+CONFIG_FIT=y
+CONFIG_FIT_SIGNATURE=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_OF_STDOUT_VIA_ALIAS=y
+CONFIG_LOGLEVEL=8
+CONFIG_VERSION_VARIABLE=y
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
+CONFIG_HUSH_PARSER=y
+CONFIG_CMD_LICENSE=y
+# CONFIG_BOOTM_NETBSD is not set
+# CONFIG_BOOTM_PLAN9 is not set
+# CONFIG_BOOTM_RTEMS is not set
+# CONFIG_BOOTM_VXWORKS is not set
+# CONFIG_CMD_ELF is not set
+# CONFIG_CMD_XIMG is not set
+# CONFIG_CMD_CRC32 is not set
+CONFIG_CMD_MEMINFO=y
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_GPT=y
+CONFIG_CMD_GPT_RENAME=y
+# CONFIG_CMD_LOADS is not set
+CONFIG_CMD_MMC=y
+CONFIG_CMD_MTD=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_SPI=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_WDT=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_MII=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
+CONFIG_MTDPARTS_DEFAULT="spi0.0:312k(u-boot),4k(env),4k(factory),2368k(kernel),-(filesystem)"
+CONFIG_DEFAULT_DEVICE_TREE="vocore_vocore2"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_DM=y
+# CONFIG_DM_DEVICE_REMOVE is not set
+CONFIG_BOOTCOUNT_LIMIT=y
+CONFIG_LED=y
+CONFIG_LED_BLINK=y
+CONFIG_LED_GPIO=y
+CONFIG_MMC=y
+CONFIG_DM_MMC=y
+# CONFIG_MMC_HW_PARTITIONING is not set
+CONFIG_MMC_MTK=y
+CONFIG_MTD=y
+CONFIG_SPI_FLASH_SFDP_SUPPORT=y
+CONFIG_SPI_FLASH_GIGADEVICE=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_SPI_FLASH_SPANSION=y
+CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_MTD=y
+CONFIG_MT7628_ETH=y
+CONFIG_PHY=y
+CONFIG_MT76X8_USB_PHY=y
+CONFIG_SPECIFY_CONSOLE_INDEX=y
+CONFIG_CONS_INDEX=3
+CONFIG_SPI=y
+CONFIG_MT7621_SPI=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_GENERIC=y
+CONFIG_USB_STORAGE=y
+CONFIG_WDT=y
+CONFIG_WDT_MT7621=y
+CONFIG_FS_EXT4=y
+CONFIG_FAT_WRITE=y
+CONFIG_LZMA=y
+CONFIG_LZO=y
+CONFIG_SPL_LZMA=y
index 8bb27ad9e2567753ca1d404e9f8fff4bc8ee374b..93250a6aeed4a2997661f74d339b175d22f515d6 100644 (file)
@@ -31,6 +31,8 @@ from load_config import loadConfig
 # If your documentation needs a minimal Sphinx version, state it here.
 needs_sphinx = '1.3'
 
+latex_engine = 'xelatex'
+
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
index d4f38262eb5e9ff7f78a1f876095283c7e991d3f..c518050ffc3fb22b43a0d668028ea9b1d8444102 100755 (executable)
@@ -344,7 +344,7 @@ enums and defines and create cross-references to a Sphinx book.
 
 B<parse_headers.pl> [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>]
 
-Where <options> can be: --debug, --help or --man.
+Where <options> can be: --debug, --help or --usage.
 
 =head1 OPTIONS
 
@@ -382,7 +382,7 @@ ioctl.
 The EXCEPTIONS_FILE contain two rules to allow ignoring a symbol or
 to replace the default references by a custom one.
 
-Please read doc/doc-guide/parse-headers.rst at the Kernel's
+Please read Documentation/doc-guide/parse-headers.rst at the Kernel's
 tree for more details.
 
 =head1 BUGS
index 6eaafdeaf996fc082eac086b69967950fdf48e7d..3035c5fb38ea320971494a5da56badba4726d8de 100644 (file)
@@ -67,6 +67,7 @@
 #define CGU_TUN_IDIV_TUN       0x380
 #define CGU_TUN_IDIV_ROM       0x390
 #define CGU_TUN_IDIV_PWM       0x3A0
+#define CGU_TUN_IDIV_TIMER     0x3B0
 #define CGU_HDMI_IDIV_APB      0x480
 #define CGU_SYS_IDIV_APB       0x180
 #define CGU_SYS_IDIV_AXI       0x190
 #define MIN_PLL_RATE                   100000000 /* 100 MHz */
 #define PARENT_RATE_33                 33333333 /* fixed clock - xtal */
 #define PARENT_RATE_27                 27000000 /* fixed clock - xtal */
-#define CGU_MAX_CLOCKS                 26
+#define CGU_MAX_CLOCKS                 27
 
 #define CGU_SYS_CLOCKS                 16
 #define MAX_AXI_CLOCKS                 4
 
-#define CGU_TUN_CLOCKS                 3
+#define CGU_TUN_CLOCKS                 4
 #define MAX_TUN_CLOCKS                 6
 
 struct hsdk_tun_idiv_cfg {
@@ -147,7 +148,8 @@ static const struct hsdk_tun_clk_cfg tun_clk_cfg = {
        { 600000000, 600000000, 600000000, 600000000, 750000000, 600000000 }, {
        { CGU_TUN_IDIV_TUN,     { 24,   12,     8,      6,      6,      4 } },
        { CGU_TUN_IDIV_ROM,     { 4,    4,      4,      4,      5,      4 } },
-       { CGU_TUN_IDIV_PWM,     { 8,    8,      8,      8,      10,     8 } }
+       { CGU_TUN_IDIV_PWM,     { 8,    8,      8,      8,      10,     8 } },
+       { CGU_TUN_IDIV_TIMER,   { 12,   12,     12,     12,     15,     12 } }
        }
 };
 
@@ -316,6 +318,7 @@ static const struct hsdk_cgu_clock_map clock_map[] = {
        { CGU_TUN_PLL, 0, CGU_TUN_IDIV_TUN, &sdt_pll_dat, idiv_get, tun_clk_set, idiv_off },
        { CGU_TUN_PLL, 0, CGU_TUN_IDIV_ROM, &sdt_pll_dat, idiv_get, idiv_set, idiv_off },
        { CGU_TUN_PLL, 0, CGU_TUN_IDIV_PWM, &sdt_pll_dat, idiv_get, idiv_set, idiv_off },
+       { CGU_TUN_PLL, 0, CGU_TUN_IDIV_TIMER, &sdt_pll_dat, idiv_get, idiv_set, idiv_off },
        { CGU_HDMI_PLL, 0, 0, &hdmi_pll_dat, pll_get, pll_set, NULL },
        { CGU_HDMI_PLL, 0, CGU_HDMI_IDIV_APB, &hdmi_pll_dat, idiv_get, idiv_set, idiv_off }
 };
index 5232328e1e4a21308b8b8b29e14f2158d166cffb..7bdebf586994e50663d2fba07d94c07f1c021fbd 100644 (file)
@@ -2714,6 +2714,14 @@ int brcmnand_probe(struct udevice *dev, struct brcmnand_soc *soc)
        }
 #endif /* __UBOOT__ */
 
+       /* No chip-selects could initialize properly */
+       if (list_empty(&ctrl->host_list)) {
+               ret = -ENODEV;
+               goto err;
+       }
+
+       return 0;
+
 err:
 #ifndef __UBOOT__
        clk_disable_unprepare(ctrl->clk);
@@ -2722,7 +2730,6 @@ err:
                clk_disable(ctrl->clk);
 #endif /* __UBOOT__ */
        return ret;
-
 }
 EXPORT_SYMBOL_GPL(brcmnand_probe);
 
index f09e138bb8c57c0c078c9e2deee725e8b5c89883..4be7433404701d9943c50f202b43a593e330489d 100644 (file)
@@ -101,6 +101,12 @@ config SYSRESET_WATCHDOG
        help
          Reboot support for generic watchdog reset.
 
+config SYSRESET_RESETCTL
+       bool "Enable support for reset controller reboot driver"
+       select DM_RESET
+       help
+         Reboot support using generic reset controller.
+
 config SYSRESET_X86
        bool "Enable support for x86 processor reboot driver"
        depends on X86
index 51af68fad3b0a93deb9d87de1b0186f59d4f8bbc..3ed4bab9e376e2885dc03a5ac36e76dee29c8703 100644 (file)
@@ -16,5 +16,6 @@ obj-$(CONFIG_SYSRESET_SOCFPGA_S10) += sysreset_socfpga_s10.o
 obj-$(CONFIG_SYSRESET_TI_SCI) += sysreset-ti-sci.o
 obj-$(CONFIG_SYSRESET_SYSCON) += sysreset_syscon.o
 obj-$(CONFIG_SYSRESET_WATCHDOG) += sysreset_watchdog.o
+obj-$(CONFIG_SYSRESET_RESETCTL) += sysreset_resetctl.o
 obj-$(CONFIG_$(SPL_TPL_)SYSRESET_X86) += sysreset_x86.o
 obj-$(CONFIG_TARGET_XTFPGA) += sysreset_xtfpga.o
diff --git a/drivers/sysreset/sysreset_resetctl.c b/drivers/sysreset/sysreset_resetctl.c
new file mode 100644 (file)
index 0000000..b8203ba
--- /dev/null
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <sysreset.h>
+#include <reset.h>
+
+struct resetctl_reboot_priv {
+       struct reset_ctl_bulk resets;
+};
+
+static int resetctl_reboot_request(struct udevice *dev, enum sysreset_t type)
+{
+       struct resetctl_reboot_priv *priv = dev_get_priv(dev);
+
+       return reset_assert_bulk(&priv->resets);
+}
+
+static struct sysreset_ops resetctl_reboot_ops = {
+       .request = resetctl_reboot_request,
+};
+
+int resetctl_reboot_probe(struct udevice *dev)
+{
+       struct resetctl_reboot_priv *priv = dev_get_priv(dev);
+
+       return reset_get_bulk(dev, &priv->resets);
+}
+
+static const struct udevice_id resetctl_reboot_ids[] = {
+       { .compatible = "resetctl-reboot" },
+       { }
+};
+
+U_BOOT_DRIVER(resetctl_reboot) = {
+       .id = UCLASS_SYSRESET,
+       .name = "resetctl_reboot",
+       .of_match = resetctl_reboot_ids,
+       .ops = &resetctl_reboot_ops,
+       .priv_auto_alloc_size = sizeof(struct resetctl_reboot_priv),
+       .probe = resetctl_reboot_probe,
+};
index 3559daf11d2b2d87f3e28cfe5906951276f2773a..f8524e5a99abb51dcb5400c2c666c3ec2a656b91 100644 (file)
@@ -409,6 +409,9 @@ int ext4fs_check_journal_state(int recovery_flag)
        char *temp_buff1 = NULL;
        struct ext_filesystem *fs = get_fs();
 
+       if (le32_to_cpu(fs->sb->feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+               return 0;
+
        temp_buff = zalloc(fs->blksz);
        if (!temp_buff)
                return -ENOMEM;
index c7e7119aafd14b2438b76a4647a73120c8e1fa70..45eb931c257af38e729d3974cf49ea82eed7e4b7 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 45f26bb309757609db1c05021e96a22e9c5c99d5..eed321eb6fc8aca0d43cb46829f6d2760a322cd9 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 8d594387853f4d80a76d4174eaac32e0ffd4d64b..c78099a49dcd09e42f01ccbb8a6426236d6db650 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 061d6b25b714850ed1f8c5497aec27a9a57897e5..547cf857ceb0a135deb257f12c4e76846bd518ae 100644 (file)
@@ -17,7 +17,9 @@
 /* USB */
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 583217d26217b9de132cea173279e6aa769384a6..116e9705b6be7a8db1c405eef8f17795b0966d17 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 570bc3b33d3dc6aa73207f9267150059b18e5340..e5e8b15e18723a8dc57e8a8f30eb55f92c0bc396 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index ab5bdac7268aef0a168b270816e328ab5fb35f3f..4d4403f8d218d333aa2bac0e0b68ec8a6bf5af4d 100644 (file)
@@ -19,7 +19,9 @@
 #define CONFIG_EHCI_MMIO_BIG_ENDIAN
 #define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 2
+#if defined(CONFIG_USB_OHCI_HCD)
 #define CONFIG_USB_OHCI_NEW
+#endif /* CONFIG_USB_OHCI_HCD */
 
 /* U-Boot */
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_SYS_SDRAM_BASE + SZ_1M
index 59c60743d24cadd20e737a219272f21786d8e2e6..6412efcbf88e5a126e6d09b55e2f14f93e4a7053 100644 (file)
 
 #define CONFIG_SYS_INIT_SP_OFFSET      0x400000
 
-#ifdef CONFIG_BOOT_RAM
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #endif
 
+#define CONFIG_SYS_UBOOT_START         CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR      0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE                0x10000
+#define CONFIG_SPL_MAX_SIZE            0x10000
+#define CONFIG_SPL_PAD_TO              0
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE          0
+
+/* Serial SPL */
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK         40000000
+#define CONFIG_SYS_NS16550_REG_SIZE    -4
+#define CONFIG_SYS_NS16550_COM1                0xb0000c00
+#define CONFIG_CONS_INDEX              1
+#endif
+
 /* UART */
 #define CONFIG_SYS_BAUDRATE_TABLE      { 9600, 19200, 38400, 57600, 115200, \
                                          230400, 460800, 921600 }
diff --git a/include/configs/hsdk-4xd.h b/include/configs/hsdk-4xd.h
new file mode 100644 (file)
index 0000000..4628108
--- /dev/null
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Synopsys, Inc. All rights reserved.
+ * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
+ */
+
+#ifndef _CONFIG_HSDK_H_
+#define _CONFIG_HSDK_H_
+
+#include <linux/sizes.h>
+
+/*
+ *  CPU configuration
+ */
+#define NR_CPUS                                4
+#define ARC_PERIPHERAL_BASE            0xF0000000
+#define ARC_DWMMC_BASE                 (ARC_PERIPHERAL_BASE + 0xA000)
+#define ARC_DWGMAC_BASE                        (ARC_PERIPHERAL_BASE + 0x18000)
+
+/*
+ * Memory configuration
+ */
+#define CONFIG_SYS_MONITOR_BASE                CONFIG_SYS_TEXT_BASE
+
+#define CONFIG_SYS_DDR_SDRAM_BASE      0x80000000
+#define CONFIG_SYS_SDRAM_BASE          CONFIG_SYS_DDR_SDRAM_BASE
+#define CONFIG_SYS_SDRAM_SIZE          SZ_1G
+
+#define CONFIG_SYS_INIT_SP_ADDR                \
+       (CONFIG_SYS_SDRAM_BASE + 0x1000 - GENERATED_GBL_DATA_SIZE)
+
+#define CONFIG_SYS_MALLOC_LEN          SZ_2M
+#define CONFIG_SYS_BOOTM_LEN           SZ_128M
+#define CONFIG_SYS_LOAD_ADDR           0x82000000
+
+/*
+ * UART configuration
+ */
+#define CONFIG_SYS_NS16550_SERIAL
+#define CONFIG_SYS_NS16550_CLK         33330000
+#define CONFIG_SYS_NS16550_MEM32
+
+/*
+ * Ethernet PHY configuration
+ */
+
+/*
+ * USB 1.1 configuration
+ */
+#define CONFIG_USB_OHCI_NEW
+#define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 1
+
+/*
+ * Environment settings
+ */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+       "upgrade=if mmc rescan && " \
+               "fatload mmc 0:1 ${loadaddr} u-boot-update.scr && " \
+               "iminfo ${loadaddr} && source ${loadaddr}; then; else echo " \
+               "\"Fail to upgrade.\n" \
+               "Do you have u-boot-update.scr and u-boot.head on first (FAT) SD card partition?\"" \
+               "; fi\0" \
+       "core_mask=0xF\0" \
+       "hsdk_hs45d=setenv core_mask 0x2; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x0; setenv icache_ena 0x0; setenv csm_location 0x10; \
+setenv dcache_ena 0x0; setenv core_iccm_1 0x7; \
+setenv core_dccm_1 0x8; setenv non_volatile_limit 0xF;\0" \
+       "hsdk_hs47d=setenv core_mask 0x1; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x0; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_0 0x10; \
+setenv core_dccm_0 0x10; setenv non_volatile_limit 0xF;\0" \
+       "hsdk_hs47d_ccm=setenv core_mask 0x2; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x0; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_1 0x7; \
+setenv core_dccm_1 0x8; setenv non_volatile_limit 0xF;\0" \
+       "hsdk_hs48=setenv core_mask 0x1; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x1; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_0 0x10; \
+setenv core_dccm_0 0x10; setenv non_volatile_limit 0xF;\0" \
+       "hsdk_hs48_ccm=setenv core_mask 0x2; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x1; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_1 0x7; \
+setenv core_dccm_1 0x8; setenv non_volatile_limit 0xF;\0" \
+       "hsdk_hs48x2=run hsdk_hs47dx2;\0" \
+       "hsdk_hs47dx2=setenv core_mask 0x3; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x1; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_0 0x10; \
+setenv core_dccm_0 0x10; setenv non_volatile_limit 0xF; \
+setenv core_iccm_1 0x6; setenv core_dccm_1 0x6;\0" \
+       "hsdk_hs48x3=run hsdk_hs47dx3;\0" \
+       "hsdk_hs47dx3=setenv core_mask 0x7; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x1; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_0 0x10; \
+setenv core_dccm_0 0x10; setenv non_volatile_limit 0xF; \
+setenv core_iccm_1 0x6; setenv core_dccm_1 0x6; \
+setenv core_iccm_2 0x10; setenv core_dccm_2 0x10;\0" \
+       "hsdk_hs48x4=run hsdk_hs47dx4;\0" \
+       "hsdk_hs47dx4=setenv core_mask 0xF; setenv haps_apb_location 0x1; \
+setenv l2_cache_ena 0x1; setenv icache_ena 0x1; setenv csm_location 0x10; \
+setenv dcache_ena 0x1; setenv core_iccm_0 0x10; \
+setenv core_dccm_0 0x10; setenv non_volatile_limit 0xF; \
+setenv core_iccm_1 0x6; setenv core_dccm_1 0x6; \
+setenv core_iccm_2 0x10; setenv core_dccm_2 0x10; \
+setenv core_iccm_3 0x6; setenv core_dccm_3 0x6;\0"
+
+/*
+ * Environment configuration
+ */
+#define CONFIG_BOOTFILE                        "uImage"
+#define CONFIG_LOADADDR                        CONFIG_SYS_LOAD_ADDR
+
+/* Cli configuration */
+#define CONFIG_SYS_CBSIZE              SZ_2K
+
+/*
+ * Callback configuration
+ */
+#define CONFIG_BOARD_LATE_INIT
+
+#endif /* _CONFIG_HSDK_H_ */
index ca5b693e4ccb80e75a2f9ac179d7ab088e8282bf..4276e95dee2798aba6fdb8b6434d6db8d8b09f6b 100644 (file)
 
 #define CONFIG_SYS_INIT_SP_OFFSET      0x400000
 
-#ifdef CONFIG_BOOT_RAM
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #endif
 
+#define CONFIG_SYS_UBOOT_START         CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR      0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE                0x10000
+#define CONFIG_SPL_MAX_SIZE            0x10000
+#define CONFIG_SPL_PAD_TO              0
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE          0
+
+/* Serial SPL */
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK         40000000
+#define CONFIG_SYS_NS16550_REG_SIZE    -4
+#define CONFIG_SYS_NS16550_COM3                0xb0000e00
+#define CONFIG_CONS_INDEX              3
+
+#endif
+
 /* UART */
 #define CONFIG_SYS_BAUDRATE_TABLE      { 9600, 19200, 38400, 57600, 115200, \
                                          230400, 460800, 921600 }
diff --git a/include/configs/mt7628.h b/include/configs/mt7628.h
new file mode 100644 (file)
index 0000000..9b9218d
--- /dev/null
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef __CONFIG_MT7628_H
+#define __CONFIG_MT7628_H
+
+#define CONFIG_SYS_HZ                  1000
+#define CONFIG_SYS_MIPS_TIMER_FREQ     290000000
+
+#define CONFIG_SYS_MONITOR_BASE                CONFIG_SYS_TEXT_BASE
+
+#define CONFIG_SYS_MALLOC_LEN          0x100000
+#define CONFIG_SYS_BOOTPARAMS_LEN      0x20000
+
+#define CONFIG_SYS_SDRAM_BASE          0x80000000
+#define CONFIG_SYS_LOAD_ADDR           0x80010000
+
+#define CONFIG_SYS_INIT_SP_OFFSET      0x80000
+
+#define CONFIG_SYS_BOOTM_LEN           0x1000000
+
+#define CONFIG_SYS_MAXARGS             16
+#define CONFIG_SYS_CBSIZE              1024
+
+/* Serial SPL */
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK         40000000
+#define CONFIG_SYS_NS16550_REG_SIZE    -4
+#define CONFIG_SYS_NS16550_COM1                0xb0000c00
+#define CONFIG_CONS_INDEX              1
+#endif
+
+/* Serial common */
+#define CONFIG_SYS_BAUDRATE_TABLE      { 9600, 19200, 38400, 57600, 115200, \
+                                         230400, 460800, 921600 }
+
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
+#define CONFIG_SKIP_LOWLEVEL_INIT
+#endif
+
+#define CONFIG_SYS_UBOOT_START         CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR      0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE                0x10000
+#define CONFIG_SPL_MAX_SIZE            0x10000
+#define CONFIG_SPL_PAD_TO              0
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE          0
+
+#endif /* __CONFIG_MT7628_H */
diff --git a/include/configs/vocore2.h b/include/configs/vocore2.h
new file mode 100644 (file)
index 0000000..8100e4d
--- /dev/null
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Mauro Condarelli <mc5686@mclink.it>
+ */
+
+#ifndef __VOCORE2_CONFIG_H__
+#define __VOCORE2_CONFIG_H__
+
+/* CPU */
+#define CONFIG_SYS_MIPS_TIMER_FREQ     290000000
+
+/* RAM */
+#define CONFIG_SYS_SDRAM_BASE          0x80000000
+
+#define CONFIG_SYS_LOAD_ADDR   CONFIG_SYS_SDRAM_BASE + 0x100000
+
+#define CONFIG_SYS_INIT_SP_OFFSET      0x400000
+
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
+#define CONFIG_SKIP_LOWLEVEL_INIT
+#endif
+
+#define CONFIG_SYS_UBOOT_START         CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR      0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE                0x10000
+#define CONFIG_SPL_MAX_SIZE            0x10000
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE          0
+
+/* Serial SPL */
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK         40000000
+#define CONFIG_SYS_NS16550_REG_SIZE    -4
+#define CONFIG_SYS_NS16550_COM3                0xb0000e00
+#define CONFIG_CONS_INDEX              3
+
+/* RAM */
+#define CONFIG_SYS_MEMTEST_START       0x80100000
+#define CONFIG_SYS_MEMTEST_END         0x80400000
+
+/* Memory usage */
+#define CONFIG_SYS_MAXARGS             64
+#define CONFIG_SYS_MALLOC_LEN          (1024 * 1024)
+#define CONFIG_SYS_BOOTPARAMS_LEN      (128 * 1024)
+#define CONFIG_SYS_CBSIZE              512
+
+/* U-Boot */
+#define CONFIG_SYS_MONITOR_BASE                CONFIG_SYS_TEXT_BASE
+
+/* Environment settings */
+
+#endif //__VOCORE2_CONFIG_H__
index 2cfe34eb35f37114c1f84ce17c568fe4639853e4..1ce7661cd932a71ad4ae4ba7d0b136b8ba8e84d6 100644 (file)
@@ -36,7 +36,8 @@
 #define CLK_TUN_TUN            21
 #define CLK_TUN_ROM            22
 #define CLK_TUN_PWM            23
-#define CLK_HDMI_PLL           24
-#define CLK_HDMI               25
+#define CLK_TUN_TIMER          24
+#define CLK_HDMI_PLL           25
+#define CLK_HDMI               26
 
 #endif /* __DT_BINDINGS_CLK_HSDK_CGU_H_ */
diff --git a/include/fdt_region.h b/include/fdt_region.h
new file mode 100644 (file)
index 0000000..ff7a1cc
--- /dev/null
@@ -0,0 +1,304 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _FDT_REGION_H
+#define _FDT_REGION_H
+
+#ifndef SWIG /* Not available in Python */
+struct fdt_region {
+       int offset;
+       int size;
+};
+
+/*
+ * Flags for fdt_find_regions()
+ *
+ * Add a region for the string table (always the last region)
+ */
+#define FDT_REG_ADD_STRING_TAB         (1 << 0)
+
+/*
+ * Add all supernodes of a matching node/property, useful for creating a
+ * valid subset tree
+ */
+#define FDT_REG_SUPERNODES             (1 << 1)
+
+/* Add the FDT_BEGIN_NODE tags of subnodes, including their names */
+#define FDT_REG_DIRECT_SUBNODES        (1 << 2)
+
+/* Add all subnodes of a matching node */
+#define FDT_REG_ALL_SUBNODES           (1 << 3)
+
+/* Add a region for the mem_rsvmap table (always the first region) */
+#define FDT_REG_ADD_MEM_RSVMAP         (1 << 4)
+
+/* Indicates what an fdt part is (node, property, value) */
+#define FDT_IS_NODE                    (1 << 0)
+#define FDT_IS_PROP                    (1 << 1)
+#define FDT_IS_VALUE                   (1 << 2)        /* not supported */
+#define FDT_IS_COMPAT                  (1 << 3)        /* used internally */
+#define FDT_NODE_HAS_PROP              (1 << 4)        /* node contains prop */
+
+#define FDT_ANY_GLOBAL         (FDT_IS_NODE | FDT_IS_PROP | FDT_IS_VALUE | \
+                                       FDT_IS_COMPAT)
+#define FDT_IS_ANY                     0x1f            /* all the above */
+
+/* We set a reasonable limit on the number of nested nodes */
+#define FDT_MAX_DEPTH                  32
+
+/* Decribes what we want to include from the current tag */
+enum want_t {
+       WANT_NOTHING,
+       WANT_NODES_ONLY,                /* No properties */
+       WANT_NODES_AND_PROPS,           /* Everything for one level */
+       WANT_ALL_NODES_AND_PROPS        /* Everything for all levels */
+};
+
+/* Keeps track of the state at parent nodes */
+struct fdt_subnode_stack {
+       int offset;             /* Offset of node */
+       enum want_t want;       /* The 'want' value here */
+       int included;           /* 1 if we included this node, 0 if not */
+};
+
+struct fdt_region_ptrs {
+       int depth;                      /* Current tree depth */
+       int done;                       /* What we have completed scanning */
+       enum want_t want;               /* What we are currently including */
+       char *end;                      /* Pointer to end of full node path */
+       int nextoffset;                 /* Next node offset to check */
+};
+
+/* The state of our finding algortihm */
+struct fdt_region_state {
+       struct fdt_subnode_stack stack[FDT_MAX_DEPTH];  /* node stack */
+       struct fdt_region *region;      /* Contains list of regions found */
+       int count;                      /* Numnber of regions found */
+       const void *fdt;                /* FDT blob */
+       int max_regions;                /* Maximum regions to find */
+       int can_merge;          /* 1 if we can merge with previous region */
+       int start;                      /* Start position of current region */
+       struct fdt_region_ptrs ptrs;    /* Pointers for what we are up to */
+};
+
+/**
+ * fdt_find_regions() - find regions in device tree
+ *
+ * Given a list of nodes to include and properties to exclude, find
+ * the regions of the device tree which describe those included parts.
+ *
+ * The intent is to get a list of regions which will be invariant provided
+ * those parts are invariant. For example, if you request a list of regions
+ * for all nodes but exclude the property "data", then you will get the
+ * same region contents regardless of any change to "data" properties.
+ *
+ * This function can be used to produce a byte-stream to send to a hashing
+ * function to verify that critical parts of the FDT have not changed.
+ *
+ * Nodes which are given in 'inc' are included in the region list, as
+ * are the names of the immediate subnodes nodes (but not the properties
+ * or subnodes of those subnodes).
+ *
+ * For eaxample "/" means to include the root node, all root properties
+ * and the FDT_BEGIN_NODE and FDT_END_NODE of all subnodes of /. The latter
+ * ensures that we capture the names of the subnodes. In a hashing situation
+ * it prevents the root node from changing at all Any change to non-excluded
+ * properties, names of subnodes or number of subnodes would be detected.
+ *
+ * When used with FITs this provides the ability to hash and sign parts of
+ * the FIT based on different configurations in the FIT. Then it is
+ * impossible to change anything about that configuration (include images
+ * attached to the configuration), but it may be possible to add new
+ * configurations, new images or new signatures within the existing
+ * framework.
+ *
+ * Adding new properties to a device tree may result in the string table
+ * being extended (if the new property names are different from those
+ * already added). This function can optionally include a region for
+ * the string table so that this can be part of the hash too.
+ *
+ * The device tree header is not included in the list.
+ *
+ * @fdt:       Device tree to check
+ * @inc:       List of node paths to included
+ * @inc_count: Number of node paths in list
+ * @exc_prop:  List of properties names to exclude
+ * @exc_prop_count:    Number of properties in exclude list
+ * @region:    Returns list of regions
+ * @max_region:        Maximum length of region list
+ * @path:      Pointer to a temporary string for the function to use for
+ *             building path names
+ * @path_len:  Length of path, must be large enough to hold the longest
+ *             path in the tree
+ * @add_string_tab:    1 to add a region for the string table
+ * @return number of regions in list. If this is >max_regions then the
+ * region array was exhausted. You should increase max_regions and try
+ * the call again.
+ */
+int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
+                    char * const exc_prop[], int exc_prop_count,
+                    struct fdt_region region[], int max_regions,
+                    char *path, int path_len, int add_string_tab);
+
+/**
+ * fdt_first_region() - find regions in device tree
+ *
+ * Given a nodes and properties to include and properties to exclude, find
+ * the regions of the device tree which describe those included parts.
+ *
+ * The use for this function is twofold. Firstly it provides a convenient
+ * way of performing a structure-aware grep of the tree. For example it is
+ * possible to grep for a node and get all the properties associated with
+ * that node. Trees can be subsetted easily, by specifying the nodes that
+ * are required, and then writing out the regions returned by this function.
+ * This is useful for small resource-constrained systems, such as boot
+ * loaders, which want to use an FDT but do not need to know about all of
+ * it.
+ *
+ * Secondly it makes it easy to hash parts of the tree and detect changes.
+ * The intent is to get a list of regions which will be invariant provided
+ * those parts are invariant. For example, if you request a list of regions
+ * for all nodes but exclude the property "data", then you will get the
+ * same region contents regardless of any change to "data" properties.
+ *
+ * This function can be used to produce a byte-stream to send to a hashing
+ * function to verify that critical parts of the FDT have not changed.
+ * Note that semantically null changes in order could still cause false
+ * hash misses. Such reordering might happen if the tree is regenerated
+ * from source, and nodes are reordered (the bytes-stream will be emitted
+ * in a different order and many hash functions will detect this). However
+ * if an existing tree is modified using libfdt functions, such as
+ * fdt_add_subnode() and fdt_setprop(), then this problem is avoided.
+ *
+ * The nodes/properties to include/exclude are defined by a function
+ * provided by the caller. This function is called for each node and
+ * property, and must return:
+ *
+ *    0 - to exclude this part
+ *    1 - to include this part
+ *   -1 - for FDT_IS_PROP only: no information is available, so include
+ *             if its containing node is included
+ *
+ * The last case is only used to deal with properties. Often a property is
+ * included if its containing node is included - this is the case where
+ * -1 is returned.. However if the property is specifically required to be
+ * included/excluded, then 0 or 1 can be returned. Note that including a
+ * property when the FDT_REG_SUPERNODES flag is given will force its
+ * containing node to be included since it is not valid to have a property
+ * that is not in a node.
+ *
+ * Using the information provided, the inclusion of a node can be controlled
+ * either by a node name or its compatible string, or any other property
+ * that the function can determine.
+ *
+ * As an example, including node "/" means to include the root node and all
+ * root properties. A flag provides a way of also including supernodes (of
+ * which there is none for the root node), and another flag includes
+ * immediate subnodes, so in this case we would get the FDT_BEGIN_NODE and
+ * FDT_END_NODE of all subnodes of /.
+ *
+ * The subnode feature helps in a hashing situation since it prevents the
+ * root node from changing at all. Any change to non-excluded properties,
+ * names of subnodes or number of subnodes would be detected.
+ *
+ * When used with FITs this provides the ability to hash and sign parts of
+ * the FIT based on different configurations in the FIT. Then it is
+ * impossible to change anything about that configuration (include images
+ * attached to the configuration), but it may be possible to add new
+ * configurations, new images or new signatures within the existing
+ * framework.
+ *
+ * Adding new properties to a device tree may result in the string table
+ * being extended (if the new property names are different from those
+ * already added). This function can optionally include a region for
+ * the string table so that this can be part of the hash too. This is always
+ * the last region.
+ *
+ * The FDT also has a mem_rsvmap table which can also be included, and is
+ * always the first region if so.
+ *
+ * The device tree header is not included in the region list. Since the
+ * contents of the FDT are changing (shrinking, often), the caller will need
+ * to regenerate the header anyway.
+ *
+ * @fdt:       Device tree to check
+ * @h_include: Function to call to determine whether to include a part or
+ *             not:
+ *
+ *             @priv: Private pointer as passed to fdt_find_regions()
+ *             @fdt: Pointer to FDT blob
+ *             @offset: Offset of this node / property
+ *             @type: Type of this part, FDT_IS_...
+ *             @data: Pointer to data (node name, property name, compatible
+ *                     string, value (not yet supported)
+ *             @size: Size of data, or 0 if none
+ *             @return 0 to exclude, 1 to include, -1 if no information is
+ *             available
+ * @priv:      Private pointer passed to h_include
+ * @region:    Returns list of regions, sorted by offset
+ * @max_regions: Maximum length of region list
+ * @path:      Pointer to a temporary string for the function to use for
+ *             building path names
+ * @path_len:  Length of path, must be large enough to hold the longest
+ *             path in the tree
+ * @flags:     Various flags that control the region algortihm, see
+ *             FDT_REG_...
+ * @return number of regions in list. If this is >max_regions then the
+ * region array was exhausted. You should increase max_regions and try
+ * the call again. Only the first max_regions elements are available in the
+ * array.
+ *
+ * On error a -ve value is return, which can be:
+ *
+ *     -FDT_ERR_BADSTRUCTURE (too deep or more END tags than BEGIN tags
+ *     -FDT_ERR_BADLAYOUT
+ *     -FDT_ERR_NOSPACE (path area is too small)
+ */
+int fdt_first_region(const void *fdt,
+                    int (*h_include)(void *priv, const void *fdt, int offset,
+                                     int type, const char *data, int size),
+                    void *priv, struct fdt_region *region,
+                    char *path, int path_len, int flags,
+                    struct fdt_region_state *info);
+
+/** fdt_next_region() - find next region
+ *
+ * See fdt_first_region() for full description. This function finds the
+ * next region according to the provided parameters, which must be the same
+ * as passed to fdt_first_region().
+ *
+ * This function can additionally return -FDT_ERR_NOTFOUND when there are no
+ * more regions
+ */
+int fdt_next_region(const void *fdt,
+                   int (*h_include)(void *priv, const void *fdt, int offset,
+                                    int type, const char *data, int size),
+                   void *priv, struct fdt_region *region,
+                   char *path, int path_len, int flags,
+                   struct fdt_region_state *info);
+
+/**
+ * fdt_add_alias_regions() - find aliases that point to existing regions
+ *
+ * Once a device tree grep is complete some of the nodes will be present
+ * and some will have been dropped. This function checks all the alias nodes
+ * to figure out which points point to nodes which are still present. These
+ * aliases need to be kept, along with the nodes they reference.
+ *
+ * Given a list of regions function finds the aliases that still apply and
+ * adds more regions to the list for these. This function is called after
+ * fdt_next_region() has finished returning regions and requires the same
+ * state.
+ *
+ * @fdt:       Device tree file to reference
+ * @region:    List of regions that will be kept
+ * @count:     Number of regions
+ * @max_regions: Number of entries that can fit in @region
+ * @info:      Region state as returned from fdt_next_region()
+ * @return new number of regions in @region (i.e. count + the number added)
+ * or -FDT_ERR_NOSPACE if there was not enough space.
+ */
+int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
+                         int max_regions, struct fdt_region_state *info);
+#endif /* SWIG */
+
+#endif /* _FDT_REGION_H */
index eeb2344971f3ff9489ae454647bb4f951bf170df..39dbc88aa549b3a3849233dfcaaf9c26565a6a1d 100644 (file)
@@ -8,305 +8,6 @@
 #include "../../scripts/dtc/libfdt/libfdt.h"
 
 /* U-Boot local hacks */
-
-#ifndef SWIG /* Not available in Python */
-struct fdt_region {
-       int offset;
-       int size;
-};
-
-/*
- * Flags for fdt_find_regions()
- *
- * Add a region for the string table (always the last region)
- */
-#define FDT_REG_ADD_STRING_TAB         (1 << 0)
-
-/*
- * Add all supernodes of a matching node/property, useful for creating a
- * valid subset tree
- */
-#define FDT_REG_SUPERNODES             (1 << 1)
-
-/* Add the FDT_BEGIN_NODE tags of subnodes, including their names */
-#define FDT_REG_DIRECT_SUBNODES        (1 << 2)
-
-/* Add all subnodes of a matching node */
-#define FDT_REG_ALL_SUBNODES           (1 << 3)
-
-/* Add a region for the mem_rsvmap table (always the first region) */
-#define FDT_REG_ADD_MEM_RSVMAP         (1 << 4)
-
-/* Indicates what an fdt part is (node, property, value) */
-#define FDT_IS_NODE                    (1 << 0)
-#define FDT_IS_PROP                    (1 << 1)
-#define FDT_IS_VALUE                   (1 << 2)        /* not supported */
-#define FDT_IS_COMPAT                  (1 << 3)        /* used internally */
-#define FDT_NODE_HAS_PROP              (1 << 4)        /* node contains prop */
-
-#define FDT_ANY_GLOBAL         (FDT_IS_NODE | FDT_IS_PROP | FDT_IS_VALUE | \
-                                       FDT_IS_COMPAT)
-#define FDT_IS_ANY                     0x1f            /* all the above */
-
-/* We set a reasonable limit on the number of nested nodes */
-#define FDT_MAX_DEPTH                  32
-
-/* Decribes what we want to include from the current tag */
-enum want_t {
-       WANT_NOTHING,
-       WANT_NODES_ONLY,                /* No properties */
-       WANT_NODES_AND_PROPS,           /* Everything for one level */
-       WANT_ALL_NODES_AND_PROPS        /* Everything for all levels */
-};
-
-/* Keeps track of the state at parent nodes */
-struct fdt_subnode_stack {
-       int offset;             /* Offset of node */
-       enum want_t want;       /* The 'want' value here */
-       int included;           /* 1 if we included this node, 0 if not */
-};
-
-struct fdt_region_ptrs {
-       int depth;                      /* Current tree depth */
-       int done;                       /* What we have completed scanning */
-       enum want_t want;               /* What we are currently including */
-       char *end;                      /* Pointer to end of full node path */
-       int nextoffset;                 /* Next node offset to check */
-};
-
-/* The state of our finding algortihm */
-struct fdt_region_state {
-       struct fdt_subnode_stack stack[FDT_MAX_DEPTH];  /* node stack */
-       struct fdt_region *region;      /* Contains list of regions found */
-       int count;                      /* Numnber of regions found */
-       const void *fdt;                /* FDT blob */
-       int max_regions;                /* Maximum regions to find */
-       int can_merge;          /* 1 if we can merge with previous region */
-       int start;                      /* Start position of current region */
-       struct fdt_region_ptrs ptrs;    /* Pointers for what we are up to */
-};
-
-/**
- * fdt_find_regions() - find regions in device tree
- *
- * Given a list of nodes to include and properties to exclude, find
- * the regions of the device tree which describe those included parts.
- *
- * The intent is to get a list of regions which will be invariant provided
- * those parts are invariant. For example, if you request a list of regions
- * for all nodes but exclude the property "data", then you will get the
- * same region contents regardless of any change to "data" properties.
- *
- * This function can be used to produce a byte-stream to send to a hashing
- * function to verify that critical parts of the FDT have not changed.
- *
- * Nodes which are given in 'inc' are included in the region list, as
- * are the names of the immediate subnodes nodes (but not the properties
- * or subnodes of those subnodes).
- *
- * For eaxample "/" means to include the root node, all root properties
- * and the FDT_BEGIN_NODE and FDT_END_NODE of all subnodes of /. The latter
- * ensures that we capture the names of the subnodes. In a hashing situation
- * it prevents the root node from changing at all Any change to non-excluded
- * properties, names of subnodes or number of subnodes would be detected.
- *
- * When used with FITs this provides the ability to hash and sign parts of
- * the FIT based on different configurations in the FIT. Then it is
- * impossible to change anything about that configuration (include images
- * attached to the configuration), but it may be possible to add new
- * configurations, new images or new signatures within the existing
- * framework.
- *
- * Adding new properties to a device tree may result in the string table
- * being extended (if the new property names are different from those
- * already added). This function can optionally include a region for
- * the string table so that this can be part of the hash too.
- *
- * The device tree header is not included in the list.
- *
- * @fdt:       Device tree to check
- * @inc:       List of node paths to included
- * @inc_count: Number of node paths in list
- * @exc_prop:  List of properties names to exclude
- * @exc_prop_count:    Number of properties in exclude list
- * @region:    Returns list of regions
- * @max_region:        Maximum length of region list
- * @path:      Pointer to a temporary string for the function to use for
- *             building path names
- * @path_len:  Length of path, must be large enough to hold the longest
- *             path in the tree
- * @add_string_tab:    1 to add a region for the string table
- * @return number of regions in list. If this is >max_regions then the
- * region array was exhausted. You should increase max_regions and try
- * the call again.
- */
-int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
-                    char * const exc_prop[], int exc_prop_count,
-                    struct fdt_region region[], int max_regions,
-                    char *path, int path_len, int add_string_tab);
-
-/**
- * fdt_first_region() - find regions in device tree
- *
- * Given a nodes and properties to include and properties to exclude, find
- * the regions of the device tree which describe those included parts.
- *
- * The use for this function is twofold. Firstly it provides a convenient
- * way of performing a structure-aware grep of the tree. For example it is
- * possible to grep for a node and get all the properties associated with
- * that node. Trees can be subsetted easily, by specifying the nodes that
- * are required, and then writing out the regions returned by this function.
- * This is useful for small resource-constrained systems, such as boot
- * loaders, which want to use an FDT but do not need to know about all of
- * it.
- *
- * Secondly it makes it easy to hash parts of the tree and detect changes.
- * The intent is to get a list of regions which will be invariant provided
- * those parts are invariant. For example, if you request a list of regions
- * for all nodes but exclude the property "data", then you will get the
- * same region contents regardless of any change to "data" properties.
- *
- * This function can be used to produce a byte-stream to send to a hashing
- * function to verify that critical parts of the FDT have not changed.
- * Note that semantically null changes in order could still cause false
- * hash misses. Such reordering might happen if the tree is regenerated
- * from source, and nodes are reordered (the bytes-stream will be emitted
- * in a different order and many hash functions will detect this). However
- * if an existing tree is modified using libfdt functions, such as
- * fdt_add_subnode() and fdt_setprop(), then this problem is avoided.
- *
- * The nodes/properties to include/exclude are defined by a function
- * provided by the caller. This function is called for each node and
- * property, and must return:
- *
- *    0 - to exclude this part
- *    1 - to include this part
- *   -1 - for FDT_IS_PROP only: no information is available, so include
- *             if its containing node is included
- *
- * The last case is only used to deal with properties. Often a property is
- * included if its containing node is included - this is the case where
- * -1 is returned.. However if the property is specifically required to be
- * included/excluded, then 0 or 1 can be returned. Note that including a
- * property when the FDT_REG_SUPERNODES flag is given will force its
- * containing node to be included since it is not valid to have a property
- * that is not in a node.
- *
- * Using the information provided, the inclusion of a node can be controlled
- * either by a node name or its compatible string, or any other property
- * that the function can determine.
- *
- * As an example, including node "/" means to include the root node and all
- * root properties. A flag provides a way of also including supernodes (of
- * which there is none for the root node), and another flag includes
- * immediate subnodes, so in this case we would get the FDT_BEGIN_NODE and
- * FDT_END_NODE of all subnodes of /.
- *
- * The subnode feature helps in a hashing situation since it prevents the
- * root node from changing at all. Any change to non-excluded properties,
- * names of subnodes or number of subnodes would be detected.
- *
- * When used with FITs this provides the ability to hash and sign parts of
- * the FIT based on different configurations in the FIT. Then it is
- * impossible to change anything about that configuration (include images
- * attached to the configuration), but it may be possible to add new
- * configurations, new images or new signatures within the existing
- * framework.
- *
- * Adding new properties to a device tree may result in the string table
- * being extended (if the new property names are different from those
- * already added). This function can optionally include a region for
- * the string table so that this can be part of the hash too. This is always
- * the last region.
- *
- * The FDT also has a mem_rsvmap table which can also be included, and is
- * always the first region if so.
- *
- * The device tree header is not included in the region list. Since the
- * contents of the FDT are changing (shrinking, often), the caller will need
- * to regenerate the header anyway.
- *
- * @fdt:       Device tree to check
- * @h_include: Function to call to determine whether to include a part or
- *             not:
- *
- *             @priv: Private pointer as passed to fdt_find_regions()
- *             @fdt: Pointer to FDT blob
- *             @offset: Offset of this node / property
- *             @type: Type of this part, FDT_IS_...
- *             @data: Pointer to data (node name, property name, compatible
- *                     string, value (not yet supported)
- *             @size: Size of data, or 0 if none
- *             @return 0 to exclude, 1 to include, -1 if no information is
- *             available
- * @priv:      Private pointer passed to h_include
- * @region:    Returns list of regions, sorted by offset
- * @max_regions: Maximum length of region list
- * @path:      Pointer to a temporary string for the function to use for
- *             building path names
- * @path_len:  Length of path, must be large enough to hold the longest
- *             path in the tree
- * @flags:     Various flags that control the region algortihm, see
- *             FDT_REG_...
- * @return number of regions in list. If this is >max_regions then the
- * region array was exhausted. You should increase max_regions and try
- * the call again. Only the first max_regions elements are available in the
- * array.
- *
- * On error a -ve value is return, which can be:
- *
- *     -FDT_ERR_BADSTRUCTURE (too deep or more END tags than BEGIN tags
- *     -FDT_ERR_BADLAYOUT
- *     -FDT_ERR_NOSPACE (path area is too small)
- */
-int fdt_first_region(const void *fdt,
-                    int (*h_include)(void *priv, const void *fdt, int offset,
-                                     int type, const char *data, int size),
-                    void *priv, struct fdt_region *region,
-                    char *path, int path_len, int flags,
-                    struct fdt_region_state *info);
-
-/** fdt_next_region() - find next region
- *
- * See fdt_first_region() for full description. This function finds the
- * next region according to the provided parameters, which must be the same
- * as passed to fdt_first_region().
- *
- * This function can additionally return -FDT_ERR_NOTFOUND when there are no
- * more regions
- */
-int fdt_next_region(const void *fdt,
-                   int (*h_include)(void *priv, const void *fdt, int offset,
-                                    int type, const char *data, int size),
-                   void *priv, struct fdt_region *region,
-                   char *path, int path_len, int flags,
-                   struct fdt_region_state *info);
-
-/**
- * fdt_add_alias_regions() - find aliases that point to existing regions
- *
- * Once a device tree grep is complete some of the nodes will be present
- * and some will have been dropped. This function checks all the alias nodes
- * to figure out which points point to nodes which are still present. These
- * aliases need to be kept, along with the nodes they reference.
- *
- * Given a list of regions function finds the aliases that still apply and
- * adds more regions to the list for these. This function is called after
- * fdt_next_region() has finished returning regions and requires the same
- * state.
- *
- * @fdt:       Device tree file to reference
- * @region:    List of regions that will be kept
- * @count:     Number of regions
- * @max_regions: Number of entries that can fit in @region
- * @info:      Region state as returned from fdt_next_region()
- * @return new number of regions in @region (i.e. count + the number added)
- * or -FDT_ERR_NOSPACE if there was not enough space.
- */
-int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
-                         int max_regions, struct fdt_region_state *info);
-#endif /* SWIG */
-
 extern struct fdt_header *working_fdt;  /* Pointer to the working fdt */
 
 #endif /* _INCLUDE_LIBFDT_H_ */
index 8b15cd4914ce4a4c32299ebb9d6e6a61d72171cc..6bf9fd8bebb6de440909c785cf3ba4cc4865308b 100644 (file)
@@ -223,6 +223,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_img() - Loads a legacy image from a device.
+ * @spl_image: Image description to set up
+ * @load:      Structure containing the information required to load data.
+ * @header:    Pointer to image header (including appended image)
+ *
+ * Reads an legacy image from the device. Loads u-boot image to
+ * specified load address.
+ * Returns 0 on success.
+ */
+int spl_load_legacy_img(struct spl_image_info *spl_image,
+                       struct spl_load_info *load, ulong header);
+
 /**
  * spl_load_imx_container() - Loads a imx container image from a device.
  * @spl_image: Image description to set up
index 144a54da2804de60a42aaa25aea2df0211fba63c..868de3bf3b813aff6cf75d95c760986be05d23d1 100644 (file)
@@ -434,6 +434,11 @@ config SPL_LZ4
          fast compression and decompression speed. It belongs to the LZ77
          family of byte-oriented compression schemes.
 
+config SPL_LZMA
+       bool "Enable LZMA decompression support for SPL build"
+       help
+         This enables support for LZMA compression altorithm for SPL boot.
+
 config SPL_LZO
        bool "Enable LZO decompression support in SPL"
        help
index ded9a932aa0ba9d3990780ee703eb76980beb091..c6f862b0c22941e267f5ac8883c30930df31f2c1 100644 (file)
@@ -67,6 +67,7 @@ obj-$(CONFIG_$(SPL_)ZLIB) += zlib/
 obj-$(CONFIG_$(SPL_)ZSTD) += zstd/
 obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o
 obj-$(CONFIG_$(SPL_)LZO) += lzo/
+obj-$(CONFIG_$(SPL_)LZMA) += lzma/
 obj-$(CONFIG_$(SPL_)LZ4) += lz4_wrapper.o
 
 obj-$(CONFIG_LIBAVB) += libavb/
index 5d3ae4e2f138dd669ea19f765f6361ab5475e167..1fe50ecbe5208fe6835b88e62c7110758f346cdf 100644 (file)
@@ -3,9 +3,9 @@
 # (C) Copyright 2000-2007
 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 
-# Use upstream code.
 obj-y += \
        fdt.o \
+       fdt_ro.o \
        fdt_wip.o \
        fdt_strerror.o \
        fdt_sw.o \
@@ -15,12 +15,5 @@ obj-y += \
 
 obj-$(CONFIG_OF_LIBFDT_OVERLAY) += fdt_overlay.o
 
-# Locally modified for U-Boot.
-# TODO: split out the local modifiction.
-obj-y += fdt_ro.o
-
-# U-Boot own file
-obj-y += fdt_region.o
-
 ccflags-y := -I$(srctree)/scripts/dtc/libfdt \
        -DFDT_ASSUME_MASK=$(CONFIG_$(SPL_TPL_)OF_LIBFDT_ASSUME_MASK)
diff --git a/lib/libfdt/fdt_region.c b/lib/libfdt/fdt_region.c
deleted file mode 100644 (file)
index 7e9fa92..0000000
+++ /dev/null
@@ -1,656 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2013 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- */
-
-#include <linux/libfdt_env.h>
-
-#ifndef USE_HOSTCC
-#include <fdt.h>
-#include <linux/libfdt.h>
-#else
-#include "fdt_host.h"
-#endif
-
-#define FDT_MAX_DEPTH  32
-
-static int str_in_list(const char *str, char * const list[], int count)
-{
-       int i;
-
-       for (i = 0; i < count; i++)
-               if (!strcmp(list[i], str))
-                       return 1;
-
-       return 0;
-}
-
-int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
-                    char * const exc_prop[], int exc_prop_count,
-                    struct fdt_region region[], int max_regions,
-                    char *path, int path_len, int add_string_tab)
-{
-       int stack[FDT_MAX_DEPTH] = { 0 };
-       char *end;
-       int nextoffset = 0;
-       uint32_t tag;
-       int count = 0;
-       int start = -1;
-       int depth = -1;
-       int want = 0;
-       int base = fdt_off_dt_struct(fdt);
-
-       end = path;
-       *end = '\0';
-       do {
-               const struct fdt_property *prop;
-               const char *name;
-               const char *str;
-               int include = 0;
-               int stop_at = 0;
-               int offset;
-               int len;
-
-               offset = nextoffset;
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-               stop_at = nextoffset;
-
-               switch (tag) {
-               case FDT_PROP:
-                       include = want >= 2;
-                       stop_at = offset;
-                       prop = fdt_get_property_by_offset(fdt, offset, NULL);
-                       str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-                       if (str_in_list(str, exc_prop, exc_prop_count))
-                               include = 0;
-                       break;
-
-               case FDT_NOP:
-                       include = want >= 2;
-                       stop_at = offset;
-                       break;
-
-               case FDT_BEGIN_NODE:
-                       depth++;
-                       if (depth == FDT_MAX_DEPTH)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       name = fdt_get_name(fdt, offset, &len);
-                       if (end - path + 2 + len >= path_len)
-                               return -FDT_ERR_NOSPACE;
-                       if (end != path + 1)
-                               *end++ = '/';
-                       strcpy(end, name);
-                       end += len;
-                       stack[depth] = want;
-                       if (want == 1)
-                               stop_at = offset;
-                       if (str_in_list(path, inc, inc_count))
-                               want = 2;
-                       else if (want)
-                               want--;
-                       else
-                               stop_at = offset;
-                       include = want;
-                       break;
-
-               case FDT_END_NODE:
-                       /* Depth must never go below -1 */
-                       if (depth < 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       include = want;
-                       want = stack[depth--];
-                       while (end > path && *--end != '/')
-                               ;
-                       *end = '\0';
-                       break;
-
-               case FDT_END:
-                       include = 1;
-                       break;
-               }
-
-               if (include && start == -1) {
-                       /* Should we merge with previous? */
-                       if (count && count <= max_regions &&
-                           offset == region[count - 1].offset +
-                                       region[count - 1].size - base)
-                               start = region[--count].offset - base;
-                       else
-                               start = offset;
-               }
-
-               if (!include && start != -1) {
-                       if (count < max_regions) {
-                               region[count].offset = base + start;
-                               region[count].size = stop_at - start;
-                       }
-                       count++;
-                       start = -1;
-               }
-       } while (tag != FDT_END);
-
-       if (nextoffset != fdt_size_dt_struct(fdt))
-               return -FDT_ERR_BADLAYOUT;
-
-       /* Add a region for the END tag and the string table */
-       if (count < max_regions) {
-               region[count].offset = base + start;
-               region[count].size = nextoffset - start;
-               if (add_string_tab)
-                       region[count].size += fdt_size_dt_strings(fdt);
-       }
-       count++;
-
-       return count;
-}
-
-/**
- * fdt_add_region() - Add a new region to our list
- * @info:      State information
- * @offset:    Start offset of region
- * @size:      Size of region
- *
- * The region is added if there is space, but in any case we increment the
- * count. If permitted, and the new region overlaps the last one, we merge
- * them.
- */
-static int fdt_add_region(struct fdt_region_state *info, int offset, int size)
-{
-       struct fdt_region *reg;
-
-       reg = info->region ? &info->region[info->count - 1] : NULL;
-       if (info->can_merge && info->count &&
-           info->count <= info->max_regions &&
-           reg && offset <= reg->offset + reg->size) {
-               reg->size = offset + size - reg->offset;
-       } else if (info->count++ < info->max_regions) {
-               if (reg) {
-                       reg++;
-                       reg->offset = offset;
-                       reg->size = size;
-               }
-       } else {
-               return -1;
-       }
-
-       return 0;
-}
-
-static int region_list_contains_offset(struct fdt_region_state *info,
-                                      const void *fdt, int target)
-{
-       struct fdt_region *reg;
-       int num;
-
-       target += fdt_off_dt_struct(fdt);
-       for (reg = info->region, num = 0; num < info->count; reg++, num++) {
-               if (target >= reg->offset && target < reg->offset + reg->size)
-                       return 1;
-       }
-
-       return 0;
-}
-
-/**
- * fdt_add_alias_regions() - Add regions covering the aliases that we want
- *
- * The /aliases node is not automatically included by fdtgrep unless the
- * command-line arguments cause to be included (or not excluded). However
- * aliases are special in that we generally want to include those which
- * reference a node that fdtgrep includes.
- *
- * In fact we want to include only aliases for those nodes still included in
- * the fdt, and drop the other aliases since they point to nodes that will not
- * be present.
- *
- * This function scans the aliases and adds regions for those which we want
- * to keep.
- *
- * @fdt: Device tree to scan
- * @region: List of regions
- * @count: Number of regions in the list so far (i.e. starting point for this
- *     function)
- * @max_regions: Maximum number of regions in @region list
- * @info: Place to put the region state
- * @return number of regions after processing, or -FDT_ERR_NOSPACE if we did
- * not have enough room in the regions table for the regions we wanted to add.
- */
-int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
-                         int max_regions, struct fdt_region_state *info)
-{
-       int base = fdt_off_dt_struct(fdt);
-       int node, node_end, offset;
-       int did_alias_header;
-
-       node = fdt_subnode_offset(fdt, 0, "aliases");
-       if (node < 0)
-               return -FDT_ERR_NOTFOUND;
-
-       /*
-        * Find the next node so that we know where the /aliases node ends. We
-        * need special handling if /aliases is the last node.
-        */
-       node_end = fdt_next_subnode(fdt, node);
-       if (node_end == -FDT_ERR_NOTFOUND)
-               /* Move back to the FDT_END_NODE tag of '/' */
-               node_end = fdt_size_dt_struct(fdt) - sizeof(fdt32_t) * 2;
-       else if (node_end < 0) /* other error */
-               return node_end;
-       node_end -= sizeof(fdt32_t);  /* Move to FDT_END_NODE tag of /aliases */
-
-       did_alias_header = 0;
-       info->region = region;
-       info->count = count;
-       info->can_merge = 0;
-       info->max_regions = max_regions;
-
-       for (offset = fdt_first_property_offset(fdt, node);
-            offset >= 0;
-            offset = fdt_next_property_offset(fdt, offset)) {
-               const struct fdt_property *prop;
-               const char *name;
-               int target, next;
-
-               prop = fdt_get_property_by_offset(fdt, offset, NULL);
-               name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-               target = fdt_path_offset(fdt, name);
-               if (!region_list_contains_offset(info, fdt, target))
-                       continue;
-               next = fdt_next_property_offset(fdt, offset);
-               if (next < 0)
-                       next = node_end;
-
-               if (!did_alias_header) {
-                       fdt_add_region(info, base + node, 12);
-                       did_alias_header = 1;
-               }
-               fdt_add_region(info, base + offset, next - offset);
-       }
-
-       /* Add the FDT_END_NODE tag */
-       if (did_alias_header)
-               fdt_add_region(info, base + node_end, sizeof(fdt32_t));
-
-       return info->count < max_regions ? info->count : -FDT_ERR_NOSPACE;
-}
-
-/**
- * fdt_include_supernodes() - Include supernodes required by this node
- * @info:      State information
- * @depth:     Current stack depth
- *
- * When we decided to include a node or property which is not at the top
- * level, this function forces the inclusion of higher level nodes. For
- * example, given this tree:
- *
- * / {
- *     testing {
- *     }
- * }
- *
- * If we decide to include testing then we need the root node to have a valid
- * tree. This function adds those regions.
- */
-static int fdt_include_supernodes(struct fdt_region_state *info, int depth)
-{
-       int base = fdt_off_dt_struct(info->fdt);
-       int start, stop_at;
-       int i;
-
-       /*
-        * Work down the stack looking for supernodes that we didn't include.
-        * The algortihm here is actually pretty simple, since we know that
-        * no previous subnode had to include these nodes, or if it did, we
-        * marked them as included (on the stack) already.
-        */
-       for (i = 0; i <= depth; i++) {
-               if (!info->stack[i].included) {
-                       start = info->stack[i].offset;
-
-                       /* Add the FDT_BEGIN_NODE tag of this supernode */
-                       fdt_next_tag(info->fdt, start, &stop_at);
-                       if (fdt_add_region(info, base + start, stop_at - start))
-                               return -1;
-
-                       /* Remember that this supernode is now included */
-                       info->stack[i].included = 1;
-                       info->can_merge = 1;
-               }
-
-               /* Force (later) generation of the FDT_END_NODE tag */
-               if (!info->stack[i].want)
-                       info->stack[i].want = WANT_NODES_ONLY;
-       }
-
-       return 0;
-}
-
-enum {
-       FDT_DONE_NOTHING,
-       FDT_DONE_MEM_RSVMAP,
-       FDT_DONE_STRUCT,
-       FDT_DONE_END,
-       FDT_DONE_STRINGS,
-       FDT_DONE_ALL,
-};
-
-int fdt_first_region(const void *fdt,
-               int (*h_include)(void *priv, const void *fdt, int offset,
-                                int type, const char *data, int size),
-               void *priv, struct fdt_region *region,
-               char *path, int path_len, int flags,
-               struct fdt_region_state *info)
-{
-       struct fdt_region_ptrs *p = &info->ptrs;
-
-       /* Set up our state */
-       info->fdt = fdt;
-       info->can_merge = 1;
-       info->max_regions = 1;
-       info->start = -1;
-       p->want = WANT_NOTHING;
-       p->end = path;
-       *p->end = '\0';
-       p->nextoffset = 0;
-       p->depth = -1;
-       p->done = FDT_DONE_NOTHING;
-
-       return fdt_next_region(fdt, h_include, priv, region,
-                              path, path_len, flags, info);
-}
-
-/***********************************************************************
- *
- *     Theory of operation
- *
- * Note: in this description 'included' means that a node (or other part
- * of the tree) should be included in the region list, i.e. it will have
- * a region which covers its part of the tree.
- *
- * This function maintains some state from the last time it is called.
- * It checks the next part of the tree that it is supposed to look at
- * (p.nextoffset) to see if that should be included or not. When it
- * finds something to include, it sets info->start to its offset. This
- * marks the start of the region we want to include.
- *
- * Once info->start is set to the start (i.e. not -1), we continue
- * scanning until we find something that we don't want included. This
- * will be the end of a region. At this point we can close off the
- * region and add it to the list. So we do so, and reset info->start
- * to -1.
- *
- * One complication here is that we want to merge regions. So when we
- * come to add another region later, we may in fact merge it with the
- * previous one if one ends where the other starts.
- *
- * The function fdt_add_region() will return -1 if it fails to add the
- * region, because we already have a region ready to be returned, and
- * the new one cannot be merged in with it. In this case, we must return
- * the region we found, and wait for another call to this function.
- * When it comes, we will repeat the processing of the tag and again
- * try to add a region. This time it will succeed.
- *
- * The current state of the pointers (stack, offset, etc.) is maintained
- * in a ptrs member. At the start of every loop iteration we make a copy
- * of it.  The copy is then updated as the tag is processed. Only if we
- * get to the end of the loop iteration (and successfully call
- * fdt_add_region() if we need to) can we commit the changes we have
- * made to these pointers. For example, if we see an FDT_END_NODE tag,
- * we will decrement the depth value. But if we need to add a region
- * for this tag (let's say because the previous tag is included and this
- * FDT_END_NODE tag is not included) then we will only commit the result
- * if we were able to add the region. That allows us to retry again next
- * time.
- *
- * We keep track of a variable called 'want' which tells us what we want
- * to include when there is no specific information provided by the
- * h_include function for a particular property. This basically handles
- * the inclusion of properties which are pulled in by virtue of the node
- * they are in. So if you include a node, its properties are also
- * included.  In this case 'want' will be WANT_NODES_AND_PROPS. The
- * FDT_REG_DIRECT_SUBNODES feature also makes use of 'want'. While we
- * are inside the subnode, 'want' will be set to WANT_NODES_ONLY, so
- * that only the subnode's FDT_BEGIN_NODE and FDT_END_NODE tags will be
- * included, and properties will be skipped. If WANT_NOTHING is
- * selected, then we will just rely on what the h_include() function
- * tells us.
- *
- * Using 'want' we work out 'include', which tells us whether this
- * current tag should be included or not. As you can imagine, if the
- * value of 'include' changes, that means we are on a boundary between
- * nodes to include and nodes to exclude. At this point we either close
- * off a previous region and add it to the list, or mark the start of a
- * new region.
- *
- * Apart from the nodes, we have mem_rsvmap, the FDT_END tag and the
- * string list. Each of these dealt with as a whole (i.e. we create a
- * region for each if it is to be included). For mem_rsvmap we don't
- * allow it to merge with the first struct region. For the stringlist,
- * we don't allow it to merge with the last struct region (which
- * contains at minimum the FDT_END tag).
- *
- *********************************************************************/
-
-int fdt_next_region(const void *fdt,
-               int (*h_include)(void *priv, const void *fdt, int offset,
-                                int type, const char *data, int size),
-               void *priv, struct fdt_region *region,
-               char *path, int path_len, int flags,
-               struct fdt_region_state *info)
-{
-       int base = fdt_off_dt_struct(fdt);
-       int last_node = 0;
-       const char *str;
-
-       info->region = region;
-       info->count = 0;
-       if (info->ptrs.done < FDT_DONE_MEM_RSVMAP &&
-           (flags & FDT_REG_ADD_MEM_RSVMAP)) {
-               /* Add the memory reserve map into its own region */
-               if (fdt_add_region(info, fdt_off_mem_rsvmap(fdt),
-                                  fdt_off_dt_struct(fdt) -
-                                  fdt_off_mem_rsvmap(fdt)))
-                       return 0;
-               info->can_merge = 0;    /* Don't allow merging with this */
-               info->ptrs.done = FDT_DONE_MEM_RSVMAP;
-       }
-
-       /*
-        * Work through the tags one by one, deciding whether each needs to
-        * be included or not. We set the variable 'include' to indicate our
-        * decision. 'want' is used to track what we want to include - it
-        * allows us to pick up all the properties (and/or subnode tags) of
-        * a node.
-        */
-       while (info->ptrs.done < FDT_DONE_STRUCT) {
-               const struct fdt_property *prop;
-               struct fdt_region_ptrs p;
-               const char *name;
-               int include = 0;
-               int stop_at = 0;
-               uint32_t tag;
-               int offset;
-               int val;
-               int len;
-
-               /*
-                * Make a copy of our pointers. If we make it to the end of
-                * this block then we will commit them back to info->ptrs.
-                * Otherwise we can try again from the same starting state
-                * next time we are called.
-                */
-               p = info->ptrs;
-
-               /*
-                * Find the tag, and the offset of the next one. If we need to
-                * stop including tags, then by default we stop *after*
-                * including the current tag
-                */
-               offset = p.nextoffset;
-               tag = fdt_next_tag(fdt, offset, &p.nextoffset);
-               stop_at = p.nextoffset;
-
-               switch (tag) {
-               case FDT_PROP:
-                       stop_at = offset;
-                       prop = fdt_get_property_by_offset(fdt, offset, NULL);
-                       str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-                       val = h_include(priv, fdt, last_node, FDT_IS_PROP, str,
-                                           strlen(str) + 1);
-                       if (val == -1) {
-                               include = p.want >= WANT_NODES_AND_PROPS;
-                       } else {
-                               include = val;
-                               /*
-                                * Make sure we include the } for this block.
-                                * It might be more correct to have this done
-                                * by the call to fdt_include_supernodes() in
-                                * the case where it adds the node we are
-                                * currently in, but this is equivalent.
-                                */
-                               if ((flags & FDT_REG_SUPERNODES) && val &&
-                                   !p.want)
-                                       p.want = WANT_NODES_ONLY;
-                       }
-
-                       /* Value grepping is not yet supported */
-                       break;
-
-               case FDT_NOP:
-                       include = p.want >= WANT_NODES_AND_PROPS;
-                       stop_at = offset;
-                       break;
-
-               case FDT_BEGIN_NODE:
-                       last_node = offset;
-                       p.depth++;
-                       if (p.depth == FDT_MAX_DEPTH)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       name = fdt_get_name(fdt, offset, &len);
-                       if (p.end - path + 2 + len >= path_len)
-                               return -FDT_ERR_NOSPACE;
-
-                       /* Build the full path of this node */
-                       if (p.end != path + 1)
-                               *p.end++ = '/';
-                       strcpy(p.end, name);
-                       p.end += len;
-                       info->stack[p.depth].want = p.want;
-                       info->stack[p.depth].offset = offset;
-
-                       /*
-                        * If we are not intending to include this node unless
-                        * it matches, make sure we stop *before* its tag.
-                        */
-                       if (p.want == WANT_NODES_ONLY ||
-                           !(flags & (FDT_REG_DIRECT_SUBNODES |
-                                      FDT_REG_ALL_SUBNODES))) {
-                               stop_at = offset;
-                               p.want = WANT_NOTHING;
-                       }
-                       val = h_include(priv, fdt, offset, FDT_IS_NODE, path,
-                                       p.end - path + 1);
-
-                       /* Include this if requested */
-                       if (val) {
-                               p.want = (flags & FDT_REG_ALL_SUBNODES) ?
-                                       WANT_ALL_NODES_AND_PROPS :
-                                       WANT_NODES_AND_PROPS;
-                       }
-
-                       /* If not requested, decay our 'p.want' value */
-                       else if (p.want) {
-                               if (p.want != WANT_ALL_NODES_AND_PROPS)
-                                       p.want--;
-
-                       /* Not including this tag, so stop now */
-                       } else {
-                               stop_at = offset;
-                       }
-
-                       /*
-                        * Decide whether to include this tag, and update our
-                        * stack with the state for this node
-                        */
-                       include = p.want;
-                       info->stack[p.depth].included = include;
-                       break;
-
-               case FDT_END_NODE:
-                       include = p.want;
-                       if (p.depth < 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-
-                       /*
-                        * If we don't want this node, stop right away, unless
-                        * we are including subnodes
-                        */
-                       if (!p.want && !(flags & FDT_REG_DIRECT_SUBNODES))
-                               stop_at = offset;
-                       p.want = info->stack[p.depth].want;
-                       p.depth--;
-                       while (p.end > path && *--p.end != '/')
-                               ;
-                       *p.end = '\0';
-                       break;
-
-               case FDT_END:
-                       /* We always include the end tag */
-                       include = 1;
-                       p.done = FDT_DONE_STRUCT;
-                       break;
-               }
-
-               /* If this tag is to be included, mark it as region start */
-               if (include && info->start == -1) {
-                       /* Include any supernodes required by this one */
-                       if (flags & FDT_REG_SUPERNODES) {
-                               if (fdt_include_supernodes(info, p.depth))
-                                       return 0;
-                       }
-                       info->start = offset;
-               }
-
-               /*
-                * If this tag is not to be included, finish up the current
-                * region.
-                */
-               if (!include && info->start != -1) {
-                       if (fdt_add_region(info, base + info->start,
-                                          stop_at - info->start))
-                               return 0;
-                       info->start = -1;
-                       info->can_merge = 1;
-               }
-
-               /* If we have made it this far, we can commit our pointers */
-               info->ptrs = p;
-       }
-
-       /* Add a region for the END tag and a separate one for string table */
-       if (info->ptrs.done < FDT_DONE_END) {
-               if (info->ptrs.nextoffset != fdt_size_dt_struct(fdt))
-                       return -FDT_ERR_BADSTRUCTURE;
-
-               if (fdt_add_region(info, base + info->start,
-                                  info->ptrs.nextoffset - info->start))
-                       return 0;
-               info->ptrs.done++;
-       }
-       if (info->ptrs.done < FDT_DONE_STRINGS) {
-               if (flags & FDT_REG_ADD_STRING_TAB) {
-                       info->can_merge = 0;
-                       if (fdt_off_dt_strings(fdt) <
-                           base + info->ptrs.nextoffset)
-                               return -FDT_ERR_BADLAYOUT;
-                       if (fdt_add_region(info, fdt_off_dt_strings(fdt),
-                                          fdt_size_dt_strings(fdt)))
-                               return 0;
-               }
-               info->ptrs.done++;
-       }
-
-       return info->count > 0 ? 0 : -FDT_ERR_NOTFOUND;
-}
index be03aea9eb006f4bf9d3f908003bd30ef1ca9363..7ede074537e019c6d5f42a727bdc53eaae3848b0 100644 (file)
@@ -1,925 +1,2 @@
-// SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- */
 #include <linux/libfdt_env.h>
-
-#ifndef USE_HOSTCC
-#include <fdt.h>
-#include <linux/libfdt.h>
-#else
-#include "fdt_host.h"
-#endif
-
-#include "libfdt_internal.h"
-
-static int fdt_nodename_eq_(const void *fdt, int offset,
-                           const char *s, int len)
-{
-       int olen;
-       const char *p = fdt_get_name(fdt, offset, &olen);
-
-       if (!p || (fdt_chk_extra() && olen < len))
-               /* short match */
-               return 0;
-
-       if (memcmp(p, s, len) != 0)
-               return 0;
-
-       if (p[len] == '\0')
-               return 1;
-       else if (!memchr(s, '@', len) && (p[len] == '@'))
-               return 1;
-       else
-               return 0;
-}
-
-const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
-{
-       int32_t totalsize;
-       uint32_t absoffset;
-       size_t len;
-       int err;
-       const char *s, *n;
-
-       if (!fdt_chk_extra()) {
-               s = (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
-
-               if (lenp)
-                       *lenp = strlen(s);
-               return s;
-       }
-       totalsize = fdt_ro_probe_(fdt);
-       err = totalsize;
-       if (totalsize < 0)
-               goto fail;
-
-       err = -FDT_ERR_BADOFFSET;
-       absoffset = stroffset + fdt_off_dt_strings(fdt);
-       if (absoffset >= totalsize)
-               goto fail;
-       len = totalsize - absoffset;
-
-       if (fdt_magic(fdt) == FDT_MAGIC) {
-               if (stroffset < 0)
-                       goto fail;
-               if (!fdt_chk_version() || fdt_version(fdt) >= 17) {
-                       if (stroffset >= fdt_size_dt_strings(fdt))
-                               goto fail;
-                       if ((fdt_size_dt_strings(fdt) - stroffset) < len)
-                               len = fdt_size_dt_strings(fdt) - stroffset;
-               }
-       } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
-               if ((stroffset >= 0)
-                   || (stroffset < -fdt_size_dt_strings(fdt)))
-                       goto fail;
-               if ((-stroffset) < len)
-                       len = -stroffset;
-       } else {
-               err = -FDT_ERR_INTERNAL;
-               goto fail;
-       }
-
-       s = (const char *)fdt + absoffset;
-       n = memchr(s, '\0', len);
-       if (!n) {
-               /* missing terminating NULL */
-               err = -FDT_ERR_TRUNCATED;
-               goto fail;
-       }
-
-       if (lenp)
-               *lenp = n - s;
-       return s;
-
-fail:
-       if (lenp)
-               *lenp = err;
-       return NULL;
-}
-
-const char *fdt_string(const void *fdt, int stroffset)
-{
-       return fdt_get_string(fdt, stroffset, NULL);
-}
-
-static int fdt_string_eq_(const void *fdt, int stroffset,
-                         const char *s, int len)
-{
-       int slen;
-       const char *p = fdt_get_string(fdt, stroffset, &slen);
-
-       return p && (slen == len) && (memcmp(p, s, len) == 0);
-}
-
-int fdt_find_max_phandle(const void *fdt, uint32_t *phandle)
-{
-       uint32_t max = 0;
-       int offset = -1;
-
-       while (true) {
-               uint32_t value;
-
-               offset = fdt_next_node(fdt, offset, NULL);
-               if (offset < 0) {
-                       if (offset == -FDT_ERR_NOTFOUND)
-                               break;
-
-                       return offset;
-               }
-
-               value = fdt_get_phandle(fdt, offset);
-
-               if (value > max)
-                       max = value;
-       }
-
-       if (phandle)
-               *phandle = max;
-
-       return 0;
-}
-
-int fdt_generate_phandle(const void *fdt, uint32_t *phandle)
-{
-       uint32_t max;
-       int err;
-
-       err = fdt_find_max_phandle(fdt, &max);
-       if (err < 0)
-               return err;
-
-       if (max == FDT_MAX_PHANDLE)
-               return -FDT_ERR_NOPHANDLES;
-
-       if (phandle)
-               *phandle = max + 1;
-
-       return 0;
-}
-
-static const struct fdt_reserve_entry *fdt_mem_rsv(const void *fdt, int n)
-{
-       int offset = n * sizeof(struct fdt_reserve_entry);
-       int absoffset = fdt_off_mem_rsvmap(fdt) + offset;
-
-       if (fdt_chk_extra()) {
-               if (absoffset < fdt_off_mem_rsvmap(fdt))
-                       return NULL;
-               if (absoffset > fdt_totalsize(fdt) -
-                   sizeof(struct fdt_reserve_entry))
-                       return NULL;
-       }
-       return fdt_mem_rsv_(fdt, n);
-}
-
-int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
-{
-       const struct fdt_reserve_entry *re;
-
-       FDT_RO_PROBE(fdt);
-       re = fdt_mem_rsv(fdt, n);
-       if (fdt_chk_extra() && !re)
-               return -FDT_ERR_BADOFFSET;
-
-       *address = fdt64_to_cpu(re->address);
-       *size = fdt64_to_cpu(re->size);
-       return 0;
-}
-
-int fdt_num_mem_rsv(const void *fdt)
-{
-       int i;
-       const struct fdt_reserve_entry *re;
-
-       for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) {
-               if (fdt64_to_cpu(re->size) == 0)
-                       return i;
-       }
-       return -FDT_ERR_TRUNCATED;
-}
-
-static int nextprop_(const void *fdt, int offset)
-{
-       uint32_t tag;
-       int nextoffset;
-
-       do {
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-
-               switch (tag) {
-               case FDT_END:
-                       if (nextoffset >= 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       else
-                               return nextoffset;
-
-               case FDT_PROP:
-                       return offset;
-               }
-               offset = nextoffset;
-       } while (tag == FDT_NOP);
-
-       return -FDT_ERR_NOTFOUND;
-}
-
-int fdt_subnode_offset_namelen(const void *fdt, int offset,
-                              const char *name, int namelen)
-{
-       int depth;
-
-       FDT_RO_PROBE(fdt);
-
-       for (depth = 0;
-            (offset >= 0) && (depth >= 0);
-            offset = fdt_next_node(fdt, offset, &depth))
-               if ((depth == 1)
-                   && fdt_nodename_eq_(fdt, offset, name, namelen))
-                       return offset;
-
-       if (depth < 0)
-               return -FDT_ERR_NOTFOUND;
-       return offset; /* error */
-}
-
-int fdt_subnode_offset(const void *fdt, int parentoffset,
-                      const char *name)
-{
-       return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
-}
-
-int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
-{
-       const char *end = path + namelen;
-       const char *p = path;
-       int offset = 0;
-
-       FDT_RO_PROBE(fdt);
-
-       /* see if we have an alias */
-       if (*path != '/') {
-               const char *q = memchr(path, '/', end - p);
-
-               if (!q)
-                       q = end;
-
-               p = fdt_get_alias_namelen(fdt, p, q - p);
-               if (!p)
-                       return -FDT_ERR_BADPATH;
-               offset = fdt_path_offset(fdt, p);
-
-               p = q;
-       }
-
-       while (p < end) {
-               const char *q;
-
-               while (*p == '/') {
-                       p++;
-                       if (p == end)
-                               return offset;
-               }
-               q = memchr(p, '/', end - p);
-               if (! q)
-                       q = end;
-
-               offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
-               if (offset < 0)
-                       return offset;
-
-               p = q;
-       }
-
-       return offset;
-}
-
-int fdt_path_offset(const void *fdt, const char *path)
-{
-       return fdt_path_offset_namelen(fdt, path, strlen(path));
-}
-
-const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
-{
-       const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset);
-       const char *nameptr;
-       int err;
-
-       if (fdt_chk_extra() &&
-           (((err = fdt_ro_probe_(fdt)) < 0)
-            || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)))
-               goto fail;
-
-       nameptr = nh->name;
-
-       if (fdt_chk_version() && fdt_version(fdt) < 0x10) {
-               /*
-                * For old FDT versions, match the naming conventions of V16:
-                * give only the leaf name (after all /). The actual tree
-                * contents are loosely checked.
-                */
-               const char *leaf;
-               leaf = strrchr(nameptr, '/');
-               if (leaf == NULL) {
-                       err = -FDT_ERR_BADSTRUCTURE;
-                       goto fail;
-               }
-               nameptr = leaf+1;
-       }
-
-       if (len)
-               *len = strlen(nameptr);
-
-       return nameptr;
-
- fail:
-       if (len)
-               *len = err;
-       return NULL;
-}
-
-int fdt_first_property_offset(const void *fdt, int nodeoffset)
-{
-       int offset;
-
-       if ((offset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
-               return offset;
-
-       return nextprop_(fdt, offset);
-}
-
-int fdt_next_property_offset(const void *fdt, int offset)
-{
-       if ((offset = fdt_check_prop_offset_(fdt, offset)) < 0)
-               return offset;
-
-       return nextprop_(fdt, offset);
-}
-
-static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt,
-                                                             int offset,
-                                                             int *lenp)
-{
-       int err;
-       const struct fdt_property *prop;
-
-       if (fdt_chk_basic() && (err = fdt_check_prop_offset_(fdt, offset)) < 0) {
-               if (lenp)
-                       *lenp = err;
-               return NULL;
-       }
-
-       prop = fdt_offset_ptr_(fdt, offset);
-
-       if (lenp)
-               *lenp = fdt32_to_cpu(prop->len);
-
-       return prop;
-}
-
-const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
-                                                     int offset,
-                                                     int *lenp)
-{
-       /* Prior to version 16, properties may need realignment
-        * and this API does not work. fdt_getprop_*() will, however. */
-
-       if (fdt_chk_version() && fdt_version(fdt) < 0x10) {
-               if (lenp)
-                       *lenp = -FDT_ERR_BADVERSION;
-               return NULL;
-       }
-
-       return fdt_get_property_by_offset_(fdt, offset, lenp);
-}
-
-static const struct fdt_property *fdt_get_property_namelen_(const void *fdt,
-                                                           int offset,
-                                                           const char *name,
-                                                           int namelen,
-                                                           int *lenp,
-                                                           int *poffset)
-{
-       for (offset = fdt_first_property_offset(fdt, offset);
-            (offset >= 0);
-            (offset = fdt_next_property_offset(fdt, offset))) {
-               const struct fdt_property *prop;
-
-               prop = fdt_get_property_by_offset_(fdt, offset, lenp);
-               if (fdt_chk_extra() && !prop) {
-                       offset = -FDT_ERR_INTERNAL;
-                       break;
-               }
-               if (fdt_string_eq_(fdt, fdt32_to_cpu(prop->nameoff),
-                                  name, namelen)) {
-                       if (poffset)
-                               *poffset = offset;
-                       return prop;
-               }
-       }
-
-       if (lenp)
-               *lenp = offset;
-       return NULL;
-}
-
-
-const struct fdt_property *fdt_get_property_namelen(const void *fdt,
-                                                   int offset,
-                                                   const char *name,
-                                                   int namelen, int *lenp)
-{
-       /* Prior to version 16, properties may need realignment
-        * and this API does not work. fdt_getprop_*() will, however. */
-       if (fdt_chk_version() && fdt_version(fdt) < 0x10) {
-               if (lenp)
-                       *lenp = -FDT_ERR_BADVERSION;
-               return NULL;
-       }
-
-       return fdt_get_property_namelen_(fdt, offset, name, namelen, lenp,
-                                        NULL);
-}
-
-
-const struct fdt_property *fdt_get_property(const void *fdt,
-                                           int nodeoffset,
-                                           const char *name, int *lenp)
-{
-       return fdt_get_property_namelen(fdt, nodeoffset, name,
-                                       strlen(name), lenp);
-}
-
-const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
-                               const char *name, int namelen, int *lenp)
-{
-       int poffset;
-       const struct fdt_property *prop;
-
-       prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp,
-                                        &poffset);
-       if (!prop)
-               return NULL;
-
-       /* Handle realignment */
-       if (fdt_chk_version() && fdt_version(fdt) < 0x10 &&
-           (poffset + sizeof(*prop)) % 8 && fdt32_to_cpu(prop->len) >= 8)
-               return prop->data + 4;
-       return prop->data;
-}
-
-const void *fdt_getprop_by_offset(const void *fdt, int offset,
-                                 const char **namep, int *lenp)
-{
-       const struct fdt_property *prop;
-
-       prop = fdt_get_property_by_offset_(fdt, offset, lenp);
-       if (!prop)
-               return NULL;
-       if (namep) {
-               const char *name;
-               int namelen;
-
-               if (fdt_chk_extra()) {
-                       name = fdt_get_string(fdt, fdt32_to_cpu(prop->nameoff),
-                                             &namelen);
-                       if (!name) {
-                               if (lenp)
-                                       *lenp = namelen;
-                               return NULL;
-                       }
-                       *namep = name;
-               } else {
-                       *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-               }
-       }
-
-       /* Handle realignment */
-       if (fdt_chk_version() && fdt_version(fdt) < 0x10 &&
-           (offset + sizeof(*prop)) % 8 && fdt32_to_cpu(prop->len) >= 8)
-               return prop->data + 4;
-       return prop->data;
-}
-
-const void *fdt_getprop(const void *fdt, int nodeoffset,
-                       const char *name, int *lenp)
-{
-       return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);
-}
-
-uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
-{
-       const fdt32_t *php;
-       int len;
-
-       /* FIXME: This is a bit sub-optimal, since we potentially scan
-        * over all the properties twice. */
-       php = fdt_getprop(fdt, nodeoffset, "phandle", &len);
-       if (!php || (len != sizeof(*php))) {
-               php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);
-               if (!php || (len != sizeof(*php)))
-                       return 0;
-       }
-
-       return fdt32_to_cpu(*php);
-}
-
-const char *fdt_get_alias_namelen(const void *fdt,
-                                 const char *name, int namelen)
-{
-       int aliasoffset;
-
-       aliasoffset = fdt_path_offset(fdt, "/aliases");
-       if (aliasoffset < 0)
-               return NULL;
-
-       return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
-}
-
-const char *fdt_get_alias(const void *fdt, const char *name)
-{
-       return fdt_get_alias_namelen(fdt, name, strlen(name));
-}
-
-int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
-{
-       int pdepth = 0, p = 0;
-       int offset, depth, namelen;
-       const char *name;
-
-       FDT_RO_PROBE(fdt);
-
-       if (buflen < 2)
-               return -FDT_ERR_NOSPACE;
-
-       for (offset = 0, depth = 0;
-            (offset >= 0) && (offset <= nodeoffset);
-            offset = fdt_next_node(fdt, offset, &depth)) {
-               while (pdepth > depth) {
-                       do {
-                               p--;
-                       } while (buf[p-1] != '/');
-                       pdepth--;
-               }
-
-               if (pdepth >= depth) {
-                       name = fdt_get_name(fdt, offset, &namelen);
-                       if (!name)
-                               return namelen;
-                       if ((p + namelen + 1) <= buflen) {
-                               memcpy(buf + p, name, namelen);
-                               p += namelen;
-                               buf[p++] = '/';
-                               pdepth++;
-                       }
-               }
-
-               if (offset == nodeoffset) {
-                       if (pdepth < (depth + 1))
-                               return -FDT_ERR_NOSPACE;
-
-                       if (p > 1) /* special case so that root path is "/", not "" */
-                               p--;
-                       buf[p] = '\0';
-                       return 0;
-               }
-       }
-
-       if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
-               return -FDT_ERR_BADOFFSET;
-       else if (offset == -FDT_ERR_BADOFFSET)
-               return -FDT_ERR_BADSTRUCTURE;
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
-                                int supernodedepth, int *nodedepth)
-{
-       int offset, depth;
-       int supernodeoffset = -FDT_ERR_INTERNAL;
-
-       FDT_RO_PROBE(fdt);
-
-       if (supernodedepth < 0)
-               return -FDT_ERR_NOTFOUND;
-
-       for (offset = 0, depth = 0;
-            (offset >= 0) && (offset <= nodeoffset);
-            offset = fdt_next_node(fdt, offset, &depth)) {
-               if (depth == supernodedepth)
-                       supernodeoffset = offset;
-
-               if (offset == nodeoffset) {
-                       if (nodedepth)
-                               *nodedepth = depth;
-
-                       if (supernodedepth > depth)
-                               return -FDT_ERR_NOTFOUND;
-                       else
-                               return supernodeoffset;
-               }
-       }
-
-       if (fdt_chk_extra()) {
-               if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
-                       return -FDT_ERR_BADOFFSET;
-               else if (offset == -FDT_ERR_BADOFFSET)
-                       return -FDT_ERR_BADSTRUCTURE;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_depth(const void *fdt, int nodeoffset)
-{
-       int nodedepth;
-       int err;
-
-       err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);
-       if (err)
-               return (!fdt_chk_extra() || err < 0) ? err : -FDT_ERR_INTERNAL;
-       return nodedepth;
-}
-
-int fdt_parent_offset(const void *fdt, int nodeoffset)
-{
-       int nodedepth = fdt_node_depth(fdt, nodeoffset);
-
-       if (nodedepth < 0)
-               return nodedepth;
-       return fdt_supernode_atdepth_offset(fdt, nodeoffset,
-                                           nodedepth - 1, NULL);
-}
-
-int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
-                                 const char *propname,
-                                 const void *propval, int proplen)
-{
-       int offset;
-       const void *val;
-       int len;
-
-       FDT_RO_PROBE(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we scan each
-        * property of a node in fdt_getprop(), then if that didn't
-        * find what we want, we scan over them again making our way
-        * to the next node.  Still it's the easiest to implement
-        * approach; performance can come later. */
-       for (offset = fdt_next_node(fdt, startoffset, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               val = fdt_getprop(fdt, offset, propname, &len);
-               if (val && (len == proplen)
-                   && (memcmp(val, propval, len) == 0))
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
-{
-       int offset;
-
-       if ((phandle == 0) || (phandle == -1))
-               return -FDT_ERR_BADPHANDLE;
-
-       FDT_RO_PROBE(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we
-        * potentially scan each property of a node in
-        * fdt_get_phandle(), then if that didn't find what
-        * we want, we scan over them again making our way to the next
-        * node.  Still it's the easiest to implement approach;
-        * performance can come later. */
-       for (offset = fdt_next_node(fdt, -1, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               if (fdt_get_phandle(fdt, offset) == phandle)
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
-{
-       int len = strlen(str);
-       const char *p;
-
-       while (listlen >= len) {
-               if (memcmp(str, strlist, len+1) == 0)
-                       return 1;
-               p = memchr(strlist, '\0', listlen);
-               if (!p)
-                       return 0; /* malformed strlist.. */
-               listlen -= (p-strlist) + 1;
-               strlist = p + 1;
-       }
-       return 0;
-}
-
-int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
-{
-       const char *list, *end;
-       int length, count = 0;
-
-       list = fdt_getprop(fdt, nodeoffset, property, &length);
-       if (!list)
-               return length;
-
-       end = list + length;
-
-       while (list < end) {
-               length = strnlen(list, end - list) + 1;
-
-               /* Abort if the last string isn't properly NUL-terminated. */
-               if (list + length > end)
-                       return -FDT_ERR_BADVALUE;
-
-               list += length;
-               count++;
-       }
-
-       return count;
-}
-
-int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
-                         const char *string)
-{
-       int length, len, idx = 0;
-       const char *list, *end;
-
-       list = fdt_getprop(fdt, nodeoffset, property, &length);
-       if (!list)
-               return length;
-
-       len = strlen(string) + 1;
-       end = list + length;
-
-       while (list < end) {
-               length = strnlen(list, end - list) + 1;
-
-               /* Abort if the last string isn't properly NUL-terminated. */
-               if (list + length > end)
-                       return -FDT_ERR_BADVALUE;
-
-               if (length == len && memcmp(list, string, length) == 0)
-                       return idx;
-
-               list += length;
-               idx++;
-       }
-
-       return -FDT_ERR_NOTFOUND;
-}
-
-const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
-                              const char *property, int idx,
-                              int *lenp)
-{
-       const char *list, *end;
-       int length;
-
-       list = fdt_getprop(fdt, nodeoffset, property, &length);
-       if (!list) {
-               if (lenp)
-                       *lenp = length;
-
-               return NULL;
-       }
-
-       end = list + length;
-
-       while (list < end) {
-               length = strnlen(list, end - list) + 1;
-
-               /* Abort if the last string isn't properly NUL-terminated. */
-               if (list + length > end) {
-                       if (lenp)
-                               *lenp = -FDT_ERR_BADVALUE;
-
-                       return NULL;
-               }
-
-               if (idx == 0) {
-                       if (lenp)
-                               *lenp = length - 1;
-
-                       return list;
-               }
-
-               list += length;
-               idx--;
-       }
-
-       if (lenp)
-               *lenp = -FDT_ERR_NOTFOUND;
-
-       return NULL;
-}
-
-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
-                             const char *compatible)
-{
-       const void *prop;
-       int len;
-
-       prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
-       if (!prop)
-               return len;
-
-       return !fdt_stringlist_contains(prop, len, compatible);
-}
-
-int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
-                                 const char *compatible)
-{
-       int offset, err;
-
-       FDT_RO_PROBE(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we scan each
-        * property of a node in fdt_node_check_compatible(), then if
-        * that didn't find what we want, we scan over them again
-        * making our way to the next node.  Still it's the easiest to
-        * implement approach; performance can come later. */
-       for (offset = fdt_next_node(fdt, startoffset, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               err = fdt_node_check_compatible(fdt, offset, compatible);
-               if ((err < 0) && (err != -FDT_ERR_NOTFOUND))
-                       return err;
-               else if (err == 0)
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-#if !defined(CHECK_LEVEL) || CHECK_LEVEL > 0
-int fdt_check_full(const void *fdt, size_t bufsize)
-{
-       int err;
-       int num_memrsv;
-       int offset, nextoffset = 0;
-       uint32_t tag;
-       unsigned depth = 0;
-       const void *prop;
-       const char *propname;
-
-       if (bufsize < FDT_V1_SIZE)
-               return -FDT_ERR_TRUNCATED;
-       err = fdt_check_header(fdt);
-       if (err != 0)
-               return err;
-       if (bufsize < fdt_totalsize(fdt))
-               return -FDT_ERR_TRUNCATED;
-
-       num_memrsv = fdt_num_mem_rsv(fdt);
-       if (num_memrsv < 0)
-               return num_memrsv;
-
-       while (1) {
-               offset = nextoffset;
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-
-               if (nextoffset < 0)
-                       return nextoffset;
-
-               switch (tag) {
-               case FDT_NOP:
-                       break;
-
-               case FDT_END:
-                       if (depth != 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       return 0;
-
-               case FDT_BEGIN_NODE:
-                       depth++;
-                       if (depth > INT_MAX)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       break;
-
-               case FDT_END_NODE:
-                       if (depth == 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       depth--;
-                       break;
-
-               case FDT_PROP:
-                       prop = fdt_getprop_by_offset(fdt, offset, &propname,
-                                                    &err);
-                       if (!prop)
-                               return err;
-                       break;
-
-               default:
-                       return -FDT_ERR_INTERNAL;
-               }
-       }
-}
-#endif
+#include "../../scripts/dtc/libfdt/fdt_ro.c"
index a0078d08ee039a14575cb87257b099b925878ee9..3e09517ed0e55d6422c94f37e26295b87ca6e7b4 100644 (file)
@@ -7,27 +7,28 @@
 /*
  *  ALGORITHM
  *
- *      The "deflation" process uses several Huffman trees. The more
- *      common source values are represented by shorter bit sequences.
+ *     The "deflation" process uses several Huffman trees. The more
+ *     common source values are represented by shorter bit sequences.
  *
- *      Each code tree is stored in a compressed form which is itself
- * a Huffman encoding of the lengths of all the code strings (in
- * ascending order by source values).  The actual code strings are
- * reconstructed from the lengths in the inflate process, as described
- * in the deflate specification.
+ *     Each code tree is stored in a compressed form which is itself
+ *     a Huffman encoding of the lengths of all the code strings (in
+ *     ascending order by source values). The actual code strings are
+ *     reconstructed from the lengths in the inflate process, as
+ *     described in the deflate specification.
  *
  *  REFERENCES
  *
- *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
- *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
+ *     Deutsch, P.
+ *         RFC 1951, DEFLATE Compressed Data Format Specification version 1.3
+ *         https://tools.ietf.org/html/rfc1951, 1996
  *
- *      Storer, James A.
- *          Data Compression:  Methods and Theory, pp. 49-50.
- *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
+ *     Storer, James A.
+ *         Data Compression:  Methods and Theory, pp. 49-50.
+ *         Computer Science Press, 1988.  ISBN 0-7167-8156-5.
  *
- *      Sedgewick, R.
- *          Algorithms, p290.
- *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
+ *     Sedgewick, R.
+ *         Algorithms, p290.
+ *         Addison-Wesley, 1983. ISBN 0-201-06672-6.
  */
 
 /* @(#) $Id$ */
index 96bbce17785f5ced12be5b6ca7c3699bf1286ef6..ac6d0cf8a6fc51fd61386f46a854face43f31b71 100644 (file)
@@ -44,5 +44,9 @@ config TFTP_BLOCKSIZE
        default 1468
        help
          Default TFTP block size.
+         The MTU is typically 1500 for ethernet, so a TFTP block of
+         1468 (MTU minus eth.hdrs) provides a good throughput with
+         almost-MTU block sizes.
+         You can also activate CONFIG_IP_DEFRAG to set a larger block.
 
 endif   # if NET
index 585eb6ef0cb3a14469894d64b436f7c90c22e23c..be24e630754c2546ee6e77492a7e4cfa848c0dd5 100644 (file)
@@ -133,14 +133,9 @@ static char tftp_filename[MAX_LEN];
  * almost-MTU block sizes.  At least try... fall back to 512 if need be.
  * (but those using CONFIG_IP_DEFRAG may want to set a larger block in cfg file)
  */
-#ifdef CONFIG_TFTP_BLOCKSIZE
-#define TFTP_MTU_BLOCKSIZE CONFIG_TFTP_BLOCKSIZE
-#else
-#define TFTP_MTU_BLOCKSIZE 1468
-#endif
 
 static unsigned short tftp_block_size = TFTP_BLOCK_SIZE;
-static unsigned short tftp_block_size_option = TFTP_MTU_BLOCKSIZE;
+static unsigned short tftp_block_size_option = CONFIG_TFTP_BLOCKSIZE;
 
 static inline int store_block(int block, uchar *src, unsigned int len)
 {
index 1949f916197ab0a8eb0d05f0322b9a7bf48c5986..ee82169c2a37eae1d2b22e23fc9289869a8971c2 100644 (file)
@@ -335,8 +335,9 @@ def fs_obj_basic(request, u_boot_config):
         md5val.append(out.split()[0])
 
         umount_fs(mount_dir)
-    except CalledProcessError:
-        pytest.skip('Setup failed for filesystem: ' + fs_type)
+    except CalledProcessError as err:
+        pytest.skip('Setup failed for filesystem: ' + fs_type + \
+            '. {}'.format(err))
         return
     else:
         yield [fs_ubtype, fs_img, md5val]
index d635622c106c351e24466064e2b162f7b97b7079..27331a8e40d1dcc2b6d64a0907b97b60cc725f02 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -15,22 +15,29 @@ run_test() {
 
 # SKip slow tests if requested
 [ "$1" == "quick" ] && mark_expr="not slow"
+[ "$1" == "quick" ] && skip=--skip-net-tests
+[ "$1" == "tools" ] && tools_only=y
 
 failures=0
 
-# Run all tests that the standard sandbox build can support
-run_test "sandbox" ./test/py/test.py --bd sandbox --build -m "${mark_expr}"
+if [ -z "$tools_only" ]; then
+       # Run all tests that the standard sandbox build can support
+       run_test "sandbox" ./test/py/test.py --bd sandbox --build \
+               -m "${mark_expr}"
+fi
 
 # Run tests which require sandbox_spl
 run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \
-       -k 'test_ofplatdata or test_handoff'
+               -k 'test_ofplatdata or test_handoff'
 
-# Run tests for the flat-device-tree version of sandbox. This is a special
-# build which does not enable CONFIG_OF_LIVE for the live device tree, so we can
-# check that functionality is the same. The standard sandbox build (above) uses
-# CONFIG_OF_LIVE.
-run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build \
-       -k test_ut
+if [ -z "$tools_only" ]; then
+       # Run tests for the flat-device-tree version of sandbox. This is a special
+       # build which does not enable CONFIG_OF_LIVE for the live device tree, so we can
+       # check that functionality is the same. The standard sandbox build (above) uses
+       # CONFIG_OF_LIVE.
+       run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree \
+               --build -k test_ut
+fi
 
 # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it
 # provides and which is built by the sandbox_spl config. Also set up the path
@@ -43,7 +50,6 @@ TOOLS_DIR=build-sandbox_spl/tools
 run_test "binman" ./tools/binman/binman --toolpath ${TOOLS_DIR} test
 run_test "patman" ./tools/patman/patman --test
 
-[ "$1" == "quick" ] && skip=--skip-net-tests
 run_test "buildman" ./tools/buildman/buildman -t ${skip}
 run_test "fdt" ./tools/dtoc/test_fdt -t
 run_test "dtoc" ./tools/dtoc/dtoc -t
index c2b26340047ae31be56c339c10d77eada999f099..1f9144f0288004f0f82ddb3f5508a9b98996bea4 100644 (file)
@@ -63,14 +63,8 @@ FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := common/image-cipher.o
 
 # The following files are synced with upstream DTC.
 # Use synced versions from scripts/dtc/libfdt/.
-LIBFDT_SRCS_SYNCED := fdt.c fdt_wip.c fdt_sw.c fdt_rw.c \
-               fdt_strerror.c fdt_empty_tree.c fdt_addresses.c fdt_overlay.c
-# The following files are locally modified for U-Boot (unfotunately).
-# Use U-Boot own versions from lib/libfdt/.
-LIBFDT_SRCS_UNSYNCED := fdt_ro.c fdt_region.c
-
-LIBFDT_OBJS := $(addprefix libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_SYNCED))) \
-              $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_SRCS_UNSYNCED)))
+LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \
+               fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
 
 RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
                                        rsa-sign.o rsa-verify.o rsa-checksum.o \
@@ -87,6 +81,7 @@ dumpimage-mkimage-objs := aisimage.o \
                        $(FIT_OBJS-y) \
                        $(FIT_SIG_OBJS-y) \
                        $(FIT_CIPHER_OBJS-y) \
+                       common/fdt_region.o \
                        common/bootm.o \
                        lib/crc32.o \
                        default_image.o \
@@ -211,7 +206,7 @@ hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
 hostprogs-$(CONFIG_RISCV) += prelink-riscv
 
 hostprogs-y += fdtgrep
-fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o
+fdtgrep-objs += $(LIBFDT_OBJS) common/fdt_region.o fdtgrep.o
 
 ifneq ($(TOOLS_ONLY),y)
 hostprogs-y += spl_size_limit
index 979b7e4d4b8fdd0bfeda53b04edf141cbf22149c..11a5d8e18ab71465be9424cf930c5e792c75edb7 120000 (symlink)
@@ -1 +1 @@
-binman.py
\ No newline at end of file
+main.py
\ No newline at end of file
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
deleted file mode 100755 (executable)
index 9e6fd72..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0+
-
-# Copyright (c) 2016 Google, Inc
-# Written by Simon Glass <sjg@chromium.org>
-#
-# Creates binary images from input files controlled by a description
-#
-
-"""See README for more information"""
-
-from __future__ import print_function
-
-from distutils.sysconfig import get_python_lib
-import glob
-import multiprocessing
-import os
-import site
-import sys
-import traceback
-import unittest
-
-# Bring in the patman and dtoc libraries (but don't override the first path
-# in PYTHONPATH)
-our_path = os.path.dirname(os.path.realpath(__file__))
-for dirname in ['../patman', '../dtoc', '..', '../concurrencytest']:
-    sys.path.insert(2, os.path.join(our_path, dirname))
-
-# Bring in the libfdt module
-sys.path.insert(2, 'scripts/dtc/pylibfdt')
-sys.path.insert(2, os.path.join(our_path,
-                '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
-
-# When running under python-coverage on Ubuntu 16.04, the dist-packages
-# directories are dropped from the python path. Add them in so that we can find
-# the elffile module. We could use site.getsitepackages() here but unfortunately
-# that is not available in a virtualenv.
-sys.path.append(get_python_lib())
-
-import cmdline
-import command
-use_concurrent = True
-try:
-    from concurrencytest import ConcurrentTestSuite, fork_for_tests
-except:
-    use_concurrent = False
-import control
-import test_util
-
-def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
-    """Run the functional tests and any embedded doctests
-
-    Args:
-        debug: True to enable debugging, which shows a full stack trace on error
-        verbosity: Verbosity level to use
-        test_preserve_dirs: True to preserve the input directory used by tests
-            so that it can be examined afterwards (only useful for debugging
-            tests). If a single test is selected (in args[0]) it also preserves
-            the output directory for this test. Both directories are displayed
-            on the command line.
-        processes: Number of processes to use to run tests (None=same as #CPUs)
-        args: List of positional args provided to binman. This can hold a test
-            name to execute (as in 'binman test testSections', for example)
-        toolpath: List of paths to use for tools
-    """
-    import cbfs_util_test
-    import elf_test
-    import entry_test
-    import fdt_test
-    import ftest
-    import image_test
-    import test
-    import doctest
-
-    result = unittest.TestResult()
-    for module in []:
-        suite = doctest.DocTestSuite(module)
-        suite.run(result)
-
-    sys.argv = [sys.argv[0]]
-    if debug:
-        sys.argv.append('-D')
-    if verbosity:
-        sys.argv.append('-v%d' % verbosity)
-    if toolpath:
-        for path in toolpath:
-            sys.argv += ['--toolpath', path]
-
-    # Run the entry tests first ,since these need to be the first to import the
-    # 'entry' module.
-    test_name = args and args[0] or None
-    suite = unittest.TestSuite()
-    loader = unittest.TestLoader()
-    for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
-                   elf_test.TestElf, image_test.TestImage,
-                   cbfs_util_test.TestCbfs):
-        # Test the test module about our arguments, if it is interested
-        if hasattr(module, 'setup_test_args'):
-            setup_test_args = getattr(module, 'setup_test_args')
-            setup_test_args(preserve_indir=test_preserve_dirs,
-                preserve_outdirs=test_preserve_dirs and test_name is not None,
-                toolpath=toolpath, verbosity=verbosity)
-        if test_name:
-            try:
-                suite.addTests(loader.loadTestsFromName(test_name, module))
-            except AttributeError:
-                continue
-        else:
-            suite.addTests(loader.loadTestsFromTestCase(module))
-    if use_concurrent and processes != 1:
-        concurrent_suite = ConcurrentTestSuite(suite,
-                fork_for_tests(processes or multiprocessing.cpu_count()))
-        concurrent_suite.run(result)
-    else:
-        suite.run(result)
-
-    # Remove errors which just indicate a missing test. Since Python v3.5 If an
-    # ImportError or AttributeError occurs while traversing name then a
-    # synthetic test that raises that error when run will be returned. These
-    # errors are included in the errors accumulated by result.errors.
-    if test_name:
-        errors = []
-        for test, err in result.errors:
-            if ("has no attribute '%s'" % test_name) not in err:
-                errors.append((test, err))
-            result.testsRun -= 1
-        result.errors = errors
-
-    print(result)
-    for test, err in result.errors:
-        print(test.id(), err)
-    for test, err in result.failures:
-        print(err, result.failures)
-    if result.skipped:
-        print('%d binman test%s SKIPPED:' %
-              (len(result.skipped), 's' if len(result.skipped) > 1 else ''))
-        for skip_info in result.skipped:
-            print('%s: %s' % (skip_info[0], skip_info[1]))
-    if result.errors or result.failures:
-        print('binman tests FAILED')
-        return 1
-    return 0
-
-def GetEntryModules(include_testing=True):
-    """Get a set of entry class implementations
-
-    Returns:
-        Set of paths to entry class filenames
-    """
-    glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
-    return set([os.path.splitext(os.path.basename(item))[0]
-                for item in glob_list
-                if include_testing or '_testing' not in item])
-
-def RunTestCoverage():
-    """Run the tests and check that we get 100% coverage"""
-    glob_list = GetEntryModules(False)
-    all_set = set([os.path.splitext(os.path.basename(item))[0]
-                   for item in glob_list if '_testing' not in item])
-    test_util.RunTestCoverage('tools/binman/binman.py', None,
-            ['*test*', '*binman.py', 'tools/patman/*', 'tools/dtoc/*'],
-            args.build_dir, all_set)
-
-def RunBinman(args):
-    """Main entry point to binman once arguments are parsed
-
-    Args:
-        args: Command line arguments Namespace object
-    """
-    ret_code = 0
-
-    if not args.debug:
-        sys.tracebacklimit = 0
-
-    if args.cmd == 'test':
-        if args.test_coverage:
-            RunTestCoverage()
-        else:
-            ret_code = RunTests(args.debug, args.verbosity, args.processes,
-                                args.test_preserve_dirs, args.tests,
-                                args.toolpath)
-
-    elif args.cmd == 'entry-docs':
-        control.WriteEntryDocs(GetEntryModules())
-
-    else:
-        try:
-            ret_code = control.Binman(args)
-        except Exception as e:
-            print('binman: %s' % e)
-            if args.debug:
-                print()
-                traceback.print_exc()
-            ret_code = 1
-    return ret_code
-
-
-if __name__ == "__main__":
-    args = cmdline.ParseArgs(sys.argv[1:])
-
-    ret_code = RunBinman(args)
-    sys.exit(ret_code)
index 99d77878c9a648346c5db432634f82f2a4a2d301..39973371b937d911f2403280cce6df642b4e2125 100644 (file)
@@ -15,16 +15,14 @@ Currently supported: raw and stage types with compression, padding empty areas
     with empty files, fixed-offset files
 """
 
-from __future__ import print_function
-
 from collections import OrderedDict
 import io
 import struct
 import sys
 
-import command
-import elf
-import tools
+from binman import elf
+from patman import command
+from patman import tools
 
 # Set to True to enable printing output while working
 DEBUG = False
index ddc2e09e35870bf7948ac1515bdab8449821a427..2c62c8a0f8145487bd2cab6f2174fc293b905830 100755 (executable)
@@ -9,8 +9,6 @@ These create and read various CBFSs and compare the results with expected
 values and with cbfstool
 """
 
-from __future__ import print_function
-
 import io
 import os
 import shutil
@@ -18,11 +16,11 @@ import struct
 import tempfile
 import unittest
 
-import cbfs_util
-from cbfs_util import CbfsWriter
-import elf
-import test_util
-import tools
+from binman import cbfs_util
+from binman.cbfs_util import CbfsWriter
+from binman import elf
+from patman import test_util
+from patman import tools
 
 U_BOOT_DATA           = b'1234'
 U_BOOT_DTB_DATA       = b'udtb'
index 68ad5fc2c0c4d098ddcf430d77be8b21dbe23668..dc1dd2a7dcff85dd58187bd6409bf22074caf0c9 100644 (file)
@@ -5,17 +5,15 @@
 # Creates binary images from input files controlled by a description
 #
 
-from __future__ import print_function
-
 from collections import OrderedDict
 import os
 import sys
-import tools
+from patman import tools
 
-import cbfs_util
-import command
-import elf
-import tout
+from binman import cbfs_util
+from binman import elf
+from patman import command
+from patman import tout
 
 # List of images we plan to create
 # Make this global so that it can be referenced from tests
@@ -62,7 +60,7 @@ def WriteEntryDocs(modules, test_missing=None):
             to show as missing even if it is present. Should be set to None in
             normal use.
     """
-    from entry import Entry
+    from binman.entry import Entry
     Entry.WriteDocs(modules, test_missing)
 
 
@@ -336,8 +334,8 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt):
     """
     # Import these here in case libfdt.py is not available, in which case
     # the above help option still works.
-    import fdt
-    import fdt_util
+    from dtoc import fdt
+    from dtoc import fdt_util
     global images
 
     # Get the device tree ready by compiling it and copying the compiled
@@ -475,7 +473,7 @@ def Binman(args):
 
     # Put these here so that we can import this module without libfdt
     from image import Image
-    import state
+    from binman import state
 
     if args.cmd in ['ls', 'extract', 'replace']:
         try:
index de1ce73f2ae9bdd86856bbe10411a103196f186e..f88031c2bf97c19874eb2a7ae596c7ba3cfe04ba 100644 (file)
@@ -5,10 +5,7 @@
 # Handle various things related to ELF images
 #
 
-from __future__ import print_function
-
 from collections import namedtuple, OrderedDict
-import command
 import io
 import os
 import re
@@ -16,8 +13,9 @@ import shutil
 import struct
 import tempfile
 
-import tools
-import tout
+from patman import command
+from patman import tools
+from patman import tout
 
 ELF_TOOLS = True
 try:
index ac26fd51e41975c6ef1ddee488f00fbd022fb762..37e1b423cf61cd9743ee1f8474c842fdcaf651ff 100644 (file)
@@ -10,11 +10,11 @@ import sys
 import tempfile
 import unittest
 
-import command
-import elf
-import test_util
-import tools
-import tout
+from binman import elf
+from patman import command
+from patman import test_util
+from patman import tools
+from patman import tout
 
 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
 
index b6f1b2c93fb195381d4d9d6130ab7cb2c72fa4f1..90ffd276177d5921e1819843b1e8bda2fc36ec13 100644 (file)
@@ -4,17 +4,15 @@
 # Base class for all entries
 #
 
-from __future__ import print_function
-
 from collections import namedtuple
 import importlib
 import os
 import sys
 
-import fdt_util
-import tools
-from tools import ToHex, ToHexSize
-import tout
+from dtoc import fdt_util
+from patman import tools
+from patman.tools import ToHex, ToHexSize
+from patman import tout
 
 modules = {}
 
@@ -65,7 +63,7 @@ class Entry(object):
     def __init__(self, section, etype, node, name_prefix=''):
         # Put this here to allow entry-docs and help to work without libfdt
         global state
-        import state
+        from binman import state
 
         self.section = section
         self.etype = etype
@@ -110,15 +108,11 @@ class Entry(object):
 
         # Import the module if we have not already done so.
         if not module:
-            old_path = sys.path
-            sys.path.insert(0, os.path.join(our_path, 'etype'))
             try:
-                module = importlib.import_module(module_name)
+                module = importlib.import_module('binman.etype.' + module_name)
             except ImportError as e:
                 raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" %
                                  (etype, node_path, module_name, e))
-            finally:
-                sys.path = old_path
             modules[module_name] = module
 
         # Look up the expected class name
@@ -592,9 +586,7 @@ features to produce new behaviours.
             modules.remove('_testing')
         missing = []
         for name in modules:
-            if name.startswith('__'):
-                continue
-            module = Entry.Lookup(name, name)
+            module = Entry.Lookup('WriteDocs', name)
             docs = getattr(module, '__doc__')
             if test_missing == name:
                 docs = None
index 277e10b5859f493361f08961d45b9bccdaf8ce20..80802f33de62972e2ce13575f625912269c1a7cf 100644 (file)
@@ -9,10 +9,10 @@ import os
 import sys
 import unittest
 
-import entry
-import fdt
-import fdt_util
-import tools
+from binman import entry
+from dtoc import fdt
+from dtoc import fdt_util
+from patman import tools
 
 class TestEntry(unittest.TestCase):
     def setUp(self):
@@ -37,11 +37,11 @@ class TestEntry(unittest.TestCase):
             else:
                 reload(entry)
         else:
-            import entry
+            from binman import entry
 
     def testEntryContents(self):
         """Test the Entry bass class"""
-        import entry
+        from binman import entry
         base_entry = entry.Entry(None, None, None)
         self.assertEqual(True, base_entry.ObtainContents())
 
diff --git a/tools/binman/etype/__init__.py b/tools/binman/etype/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
index 25a6206bf331a1e7c1f0feb98b9963431869ef44..ed718eed14518268e4c921c4daf2f6f670c26df3 100644 (file)
@@ -7,9 +7,9 @@
 
 from collections import OrderedDict
 
-from entry import Entry, EntryArg
-import fdt_util
-import tools
+from binman.entry import Entry, EntryArg
+from dtoc import fdt_util
+from patman import tools
 
 
 class Entry__testing(Entry):
index d34c7b51bffb589b47931686a322ee740992ae13..ede7a7a68cf6c72aa134c82f9653ab8abf1bf3ff 100644 (file)
@@ -5,10 +5,10 @@
 # Entry-type module for blobs, which are binary objects read from files
 #
 
-from entry import Entry
-import fdt_util
-import tools
-import tout
+from binman.entry import Entry
+from dtoc import fdt_util
+from patman import tools
+from patman import tout
 
 class Entry_blob(Entry):
     """Entry containing an arbitrary binary blob
index b2afa064c1130a741ee4a2150e3cdd14ec1cac8e..6c069437633e09137d60c12c6d068d308ba4cd62 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot device tree files
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_blob_dtb(Entry_blob):
     """A blob that holds a device tree
@@ -18,7 +18,7 @@ class Entry_blob_dtb(Entry_blob):
     def __init__(self, section, etype, node):
         # Put this here to allow entry-docs and help to work without libfdt
         global state
-        import state
+        from binman import state
 
         Entry_blob.__init__(self, section, etype, node)
 
index 344112bc42088938a97f501dcd1706ed5dcf7d81..3b4593f071a74c19910e0b7ca153db6ebcae8f1f 100644 (file)
@@ -8,8 +8,8 @@
 
 from collections import OrderedDict
 
-from blob import Entry_blob
-from entry import EntryArg
+from binman.etype.blob import Entry_blob
+from binman.entry import EntryArg
 
 
 class Entry_blob_named_by_arg(Entry_blob):
index 35b78370b2efce29809dc3de05570b67bfe15f55..e9aed8310c7cba9a6a537fa37677d9dd14db00a0 100644 (file)
@@ -7,10 +7,10 @@
 
 from collections import OrderedDict
 
-import cbfs_util
-from cbfs_util import CbfsWriter
-from entry import Entry
-import fdt_util
+from binman import cbfs_util
+from binman.cbfs_util import CbfsWriter
+from binman.entry import Entry
+from dtoc import fdt_util
 
 class Entry_cbfs(Entry):
     """Entry containing a Coreboot Filesystem (CBFS)
@@ -165,7 +165,7 @@ class Entry_cbfs(Entry):
     def __init__(self, section, etype, node):
         # Put this here to allow entry-docs and help to work without libfdt
         global state
-        import state
+        from binman import state
 
         Entry.__init__(self, section, etype, node)
         self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
index 261f8657a6276fca119f7b3a9437e05cf9b9d934..0dbe14b342a97de22bc10c279b817aec64b919f2 100644 (file)
@@ -5,7 +5,7 @@
 # Entry-type module for a Chromium OS EC image (read-write section)
 #
 
-from blob_named_by_arg import Entry_blob_named_by_arg
+from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg
 
 
 class Entry_cros_ec_rw(Entry_blob_named_by_arg):
index 5dc08b8289a0c7f382b8c46e1c31051e235b1429..aa8807990b7237b16f39e6cb00dac67d7e38f7f9 100644 (file)
@@ -8,9 +8,9 @@ This handles putting an FDT into the image with just the information about the
 image.
 """
 
-from entry import Entry
-import tools
-import tout
+from binman.entry import Entry
+from patman import tools
+from patman import tout
 
 FDTMAP_MAGIC   = b'_FDTMAP_'
 FDTMAP_HDR_LEN = 16
@@ -82,8 +82,8 @@ class Entry_fdtmap(Entry):
         global Fdt
 
         import libfdt
-        import state
-        from fdt import Fdt
+        from binman import state
+        from dtoc.fdt import Fdt
 
         Entry.__init__(self, section, etype, node)
 
index 3473a2b1efdb1697ad25154bea91fce403cc5a96..10ab585f0ed391352413df57fe3b81e9c8c89b06 100644 (file)
@@ -9,9 +9,9 @@
 import glob
 import os
 
-from section import Entry_section
-import fdt_util
-import tools
+from binman.etype.section import Entry_section
+from dtoc import fdt_util
+from patman import tools
 
 
 class Entry_files(Entry_section):
@@ -30,7 +30,7 @@ class Entry_files(Entry_section):
     def __init__(self, section, etype, node):
         # Put this here to allow entry-docs and help to work without libfdt
         global state
-        import state
+        from binman import state
 
         Entry_section.__init__(self, section, etype, node)
         self._pattern = fdt_util.GetString(self._node, 'pattern')
index 623b7f4e95e9aa379a5c694f11d1dce67540f560..860410ed6e52af627934d4a16e5e95770a4b0e5d 100644 (file)
@@ -3,9 +3,9 @@
 # Written by Simon Glass <sjg@chromium.org>
 #
 
-from entry import Entry
-import fdt_util
-import tools
+from binman.entry import Entry
+from dtoc import fdt_util
+from patman import tools
 
 class Entry_fill(Entry):
     """An entry which is filled to a particular byte value
index 835ba5012e55b881383b6405487641d2b40093c3..a43fac38de2ff827404d0097c13a5ce7a8fed734 100644 (file)
@@ -5,11 +5,11 @@
 # Entry-type module for a Flash map, as used by the flashrom SPI flash tool
 #
 
-from entry import Entry
-import fmap_util
-import tools
-from tools import ToHexSize
-import tout
+from binman.entry import Entry
+from binman import fmap_util
+from patman import tools
+from patman.tools import ToHexSize
+from patman import tout
 
 
 class Entry_fmap(Entry):
index a94c0fca9d5368c2df69b14e94fc44da58abaa88..dd1059971791fe1a6873acdafda1b0b31f811b84 100644 (file)
@@ -8,11 +8,11 @@
 
 from collections import OrderedDict
 
-import command
-from entry import Entry, EntryArg
+from patman import command
+from binman.entry import Entry, EntryArg
 
-import fdt_util
-import tools
+from dtoc import fdt_util
+from patman import tools
 
 # Build GBB flags.
 # (src/platform/vboot_reference/firmware/include/gbb_header.h)
index b9327dd799b7513cd914e2d50b06127ab7b23aa2..176bdeb29b3341933010debb81dd4b565664d537 100644 (file)
@@ -11,8 +11,8 @@ image.
 
 import struct
 
-from entry import Entry
-import fdt_util
+from binman.entry import Entry
+from dtoc import fdt_util
 
 IMAGE_HEADER_MAGIC = b'BinM'
 IMAGE_HEADER_LEN   = 8
index fa6f7793c64ab22805ae365fe0b0ed4ec18b5da4..5e6edbe4dfd748d6e86a41316c36799b8b643798 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Chip Microcode binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_cmc(Entry_blob):
     """Entry containing an Intel Chipset Micro Code (CMC) file
index b6477931d6cc95a597dc2e7d9d762c6eb4c57a96..d4d7a26901d066acea825cda3241be36fb81508d 100644 (file)
@@ -7,8 +7,8 @@
 
 import struct
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 FD_SIGNATURE   = struct.pack('<L', 0x0ff0a55a)
 MAX_REGIONS    = 5
index 2a34a05f95554b2cf75b8b6ae71bb4c5d4f8efff..ea482a61254480f5b9d1f720a26c8415c42c0db5 100644 (file)
@@ -7,7 +7,7 @@
 
 import struct
 
-from blob import Entry_blob
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fit(Entry_blob):
     """Intel Firmware Image Table (FIT)
index 148b206c3c6ca638a80a7e50cc4cd86151aedeec..df118a68f2d5a31f5ad846f58119ae801cc9e955 100644 (file)
@@ -7,7 +7,7 @@
 
 import struct
 
-from blob import Entry_blob
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fit_ptr(Entry_blob):
     """Intel Firmware Image Table (FIT) pointer
index 00a78e7083221113ebf0ab7d48dffa63228d2993..7db3d96b432bb62e65edb942b158ee1b16ebd0dd 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Firmware Support Package binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fsp(Entry_blob):
     """Entry containing an Intel Firmware Support Package (FSP) file
index bb1de73e4145349806ba783715407ef541efe3ef..51b4e7e1ac31583d2f861af0d11e8469ddc5431e 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Firmware Support Package binary blob (M section)
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fsp_m(Entry_blob):
     """Entry containing Intel Firmware Support Package (FSP) memory init
index 3d6900d1fba2cb365484c4cafb11cb6c544f51bf..b3683e476a0e6aac490338b68108223654e35323 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Firmware Support Package binary blob (S section)
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fsp_s(Entry_blob):
     """Entry containing Intel Firmware Support Package (FSP) silicon init
index 813a81f2e66e70b021cec239344062c7c0d24f4a..0f196f0f1c12a26dfb4d2282c72eacdb1a0b8713 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Firmware Support Package binary blob (T section)
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_fsp_t(Entry_blob):
     """Entry containing Intel Firmware Support Package (FSP) temp ram init
index 36aadc210c46cc45bc87fb3fab74a3e61fae46a0..6a96f6be552cd6680f7b478559036dcf084cbf3f 100644 (file)
@@ -7,10 +7,10 @@
 
 from collections import OrderedDict
 
-from entry import Entry
-from blob import Entry_blob
-import fdt_util
-import tools
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
+from dtoc import fdt_util
+from patman import tools
 
 class Entry_intel_ifwi(Entry_blob):
     """Entry containing an Intel Integrated Firmware Image (IFWI) file
index c932ec5222563322e3ebc52bfadb189d01655830..41c9c6b9203be84b8f2fa52b9e0b2ad4f3977ca5 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Management Engine binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_me(Entry_blob):
     """Entry containing an Intel Management Engine (ME) file
index 4dbc99a04f2ac346b6e4c9e1c8b81eb2d0be5529..854a4dda61590b1f454f851061eec72c13d31bf9 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Memory Reference Code binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_mrc(Entry_blob):
     """Entry containing an Intel Memory Reference Code (MRC) file
index 045db589d175501abb52350a8936037caeacf356..a1059f787e6ed96818a881a06ec987ef9fde9332 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for Intel Memory Reference Code binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_refcode(Entry_blob):
     """Entry containing an Intel Reference Code file
index d93dd19634146e5d514260df0802599113d9054d..4d465ad01732547ebcf6f9b87107d9fa399aaa6c 100644 (file)
@@ -4,8 +4,8 @@
 # Entry-type module for Intel Video BIOS Table binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_vbt(Entry_blob):
     """Entry containing an Intel Video BIOS Table (VBT) file
index 40982c8665680990d7e7e7bf91352b6c6792c51f..04cd72f3dc19089059ee563bc36a2f5a2d289f44 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for x86 VGA ROM binary blob
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_intel_vga(Entry_blob):
     """Entry containing an Intel Video Graphics Adaptor (VGA) file
index 59fedd2b54b969d8460ff614bc4ff09c61397417..cefd425a5dc10d34153b70ce3a571da998f42ea5 100644 (file)
@@ -4,8 +4,8 @@
 # Entry-type module for the PowerPC mpc85xx bootpg and resetvec code for U-Boot
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_powerpc_mpc85xx_bootpg_resetvec(Entry_blob):
     """PowerPC mpc85xx bootpg + resetvec code for U-Boot
index 89b7bf67fa6fab589d55500c1dfcf32e3982403b..91b8e0c1100716f5a33476ca3202655279e3ab41 100644 (file)
@@ -8,16 +8,14 @@ Sections are entries which can contain other entries. This allows hierarchical
 images to be created.
 """
 
-from __future__ import print_function
-
 from collections import OrderedDict
 import re
 import sys
 
-from entry import Entry
-import fdt_util
-import tools
-import tout
+from binman.entry import Entry
+from dtoc import fdt_util
+from patman import tools
+from patman import tout
 
 
 class Entry_section(Entry):
index da1813a638e33de25a180aa9ea3f92f33644c276..3577135adbe39ab17fc50df0a2d5c9bed1cbcdde 100644 (file)
@@ -5,9 +5,9 @@
 
 from collections import OrderedDict
 
-from entry import Entry, EntryArg
-import fdt_util
-import tools
+from binman.entry import Entry, EntryArg
+from dtoc import fdt_util
+from patman import tools
 
 
 class Entry_text(Entry):
index 23dd12ce43594bf359532d86ce99f266178097a8..ab1019b00c7b082b486dd1a67321204f954a5261 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot binary
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot(Entry_blob):
     """U-Boot flat binary
index 6c805a666da492e738156e28e6d574fad00ff1bc..e98350088f5c1053f3c65bcbe10038692e83e6bb 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot device tree
 #
 
-from entry import Entry
-from blob_dtb import Entry_blob_dtb
+from binman.entry import Entry
+from binman.etype.blob_dtb import Entry_blob_dtb
 
 class Entry_u_boot_dtb(Entry_blob_dtb):
     """U-Boot device tree
index 6efd24a9b33a13d8f9a4ec71cd8e75095fdace98..aec145533eb5a0045d9091dacc1b229e04bc71be 100644 (file)
@@ -5,9 +5,9 @@
 # Entry-type module for U-Boot device tree with the microcode removed
 #
 
-from entry import Entry
-from blob_dtb import Entry_blob_dtb
-import tools
+from binman.entry import Entry
+from binman.etype.blob_dtb import Entry_blob_dtb
+from patman import tools
 
 class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
     """A U-Boot device tree file, with the microcode removed
@@ -26,7 +26,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
     def __init__(self, section, etype, node):
         # Put this here to allow entry-docs and help to work without libfdt
         global state
-        import state
+        from binman import state
 
         Entry_blob_dtb.__init__(self, section, etype, node)
         self.ucode_data = b''
@@ -44,7 +44,7 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
 
     def ProcessFdt(self, fdt):
         # So the module can be loaded without it
-        import fdt
+        from dtoc import fdt
 
         # If the section does not need microcode, there is nothing to do
         ucode_dest_entry = self.section.FindEntryType(
index f83860dc0a84262c8faa5ad743daa535d8a0ffa5..5f906e520cf076b18475775cc1fb22d699451833 100644 (file)
@@ -5,11 +5,11 @@
 # Entry-type module for U-Boot ELF image
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
-import fdt_util
-import tools
+from dtoc import fdt_util
+from patman import tools
 
 class Entry_u_boot_elf(Entry_blob):
     """U-Boot ELF image
index 1ec0757c7f8d10b19fc6de33a82b46b4491b14c7..50cc71d3ce2a33ae670cf53df7c90e1c6ac08832 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot binary
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_img(Entry_blob):
     """U-Boot legacy image
index a4b95a4390a7a698e5779fe385e4bf409e4fb652..e8c0e1a1d6c45c3fc8f04cab52b3488d1c01e961 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for 'u-boot-nodtb.bin'
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_nodtb(Entry_blob):
     """U-Boot flat binary without device tree appended
index 7fedd000212d9db47dcc200eb35d00aad64f8f0a..a6fddbe8f14b50d788c059951afb338f93b5a3a2 100644 (file)
@@ -5,10 +5,9 @@
 # Entry-type module for spl/u-boot-spl.bin
 #
 
-import elf
-
-from entry import Entry
-from blob import Entry_blob
+from binman import elf
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_spl(Entry_blob):
     """U-Boot SPL binary
index 66a296a6f85a2758893c34b9e19c2030c80a586c..a6a177a1287747b3344a696bf312d2bb21c78312 100644 (file)
@@ -7,11 +7,11 @@
 # to it will appear to SPL to be at the end of BSS rather than the start.
 #
 
-import command
-import elf
-from entry import Entry
-from blob import Entry_blob
-import tools
+from binman import elf
+from binman.entry import Entry
+from patman import command
+from binman.etype.blob import Entry_blob
+from patman import tools
 
 class Entry_u_boot_spl_bss_pad(Entry_blob):
     """U-Boot SPL binary padded with a BSS region
index 1bcd449bf3ad625cca28da105097585f3826f710..a0761eeacd6663f983778455c90af142b864e63c 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot device tree in SPL (Secondary Program Loader)
 #
 
-from entry import Entry
-from blob_dtb import Entry_blob_dtb
+from binman.entry import Entry
+from binman.etype.blob_dtb import Entry_blob_dtb
 
 class Entry_u_boot_spl_dtb(Entry_blob_dtb):
     """U-Boot SPL device tree
index 24ee77237ed611185dd8222d18de94d1e28f099b..f99f74abab230c6ccb18d803eb644c378a4e47cf 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot SPL ELF image
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_spl_elf(Entry_blob):
     """U-Boot SPL ELF image
index 41c17366b1d6df488cd3a369000eeda9c278fca6..072b915ff3a24395a6efe5a5012c0217334bdc21 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for 'u-boot-nodtb.bin'
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_spl_nodtb(Entry_blob):
     """SPL binary without device tree appended
index b650cf0146c8aac16d1e6ddb1d4a37ed81dcd69f..b1543a5ef323e09833c6dff0b91bb2cca5e5a3fe 100644 (file)
@@ -7,11 +7,7 @@
 
 import struct
 
-import command
-from entry import Entry
-from blob import Entry_blob
-from u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
-import tools
+from binman.etype.u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
 
 class Entry_u_boot_spl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr):
     """U-Boot SPL with embedded microcode pointer
index 1b69c4f4a746f4ad3d348fbe25faf1f15d6bd877..6562457c9a673c8ab5226d6bc354ad6532dcad46 100644 (file)
@@ -5,10 +5,9 @@
 # Entry-type module for tpl/u-boot-tpl.bin
 #
 
-import elf
-
-from entry import Entry
-from blob import Entry_blob
+from binman import elf
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_tpl(Entry_blob):
     """U-Boot TPL binary
index 81a39704598fcf979ce2fd7d08690638416b8735..890155f271f3d466430ab381b14da579e29e977b 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot device tree in TPL (Tertiary Program Loader)
 #
 
-from entry import Entry
-from blob_dtb import Entry_blob_dtb
+from binman.entry import Entry
+from binman.etype.blob_dtb import Entry_blob_dtb
 
 class Entry_u_boot_tpl_dtb(Entry_blob_dtb):
     """U-Boot TPL device tree
index ce19a49e2e6334820fc2fc3795dfe461139cb67e..ca1bf85ace7b33236c45faeeb51e76c4914f324c 100644 (file)
@@ -5,10 +5,7 @@
 # Entry-type module for U-Boot device tree with the microcode removed
 #
 
-import control
-from entry import Entry
-from u_boot_dtb_with_ucode import Entry_u_boot_dtb_with_ucode
-import tools
+from binman.etype.u_boot_dtb_with_ucode import Entry_u_boot_dtb_with_ucode
 
 class Entry_u_boot_tpl_dtb_with_ucode(Entry_u_boot_dtb_with_ucode):
     """U-Boot TPL with embedded microcode pointer
index 9cc1cc2c450a8804265ebd23a5552d2731c8fdbe..7fa8e963640fe38f481c821b472216a2d5405800 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for U-Boot TPL ELF image
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_u_boot_tpl_elf(Entry_blob):
     """U-Boot TPL ELF image
index 8d94dded694fb8eea147ddd1410aab7ef052d698..7f7fab71051c07741ceb127808fa0dd6a58959d7 100644 (file)
@@ -7,11 +7,11 @@
 
 import struct
 
-import command
-from entry import Entry
-from blob import Entry_blob
-from u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
-import tools
+from patman import command
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
+from binman.etype.u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
+from patman import tools
 
 class Entry_u_boot_tpl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr):
     """U-Boot TPL with embedded microcode pointer
index dee8848db7af56a7b70df9d5d6eec4c17d9374ba..d9e1a605efa48a081e6b44f9b7708efd78d90a05 100644 (file)
@@ -5,9 +5,9 @@
 # Entry-type module for a U-Boot binary with an embedded microcode pointer
 #
 
-from entry import Entry
-from blob import Entry_blob
-import tools
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
+from patman import tools
 
 class Entry_u_boot_ucode(Entry_blob):
     """U-Boot microcode block
index 960a5efeb4182127b6b02509b6f9926649270c53..06047b654df577e0a96259ca6e16679f7bd98425 100644 (file)
@@ -7,12 +7,12 @@
 
 import struct
 
-import command
-import elf
-from entry import Entry
-from blob import Entry_blob
-import fdt_util
-import tools
+from binman import elf
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
+from dtoc import fdt_util
+from patman import tools
+from patman import command
 
 class Entry_u_boot_with_ucode_ptr(Entry_blob):
     """U-Boot with embedded microcode pointer
index 91fa2f7808fc3bf6b379745f16d234f10ed496b1..5753de7ec7aa17070c6594b0bf3388a850ee7b48 100644 (file)
@@ -9,10 +9,10 @@
 from collections import OrderedDict
 import os
 
-from entry import Entry, EntryArg
+from binman.entry import Entry, EntryArg
 
-import fdt_util
-import tools
+from dtoc import fdt_util
+from patman import tools
 
 class Entry_vblock(Entry):
     """An entry which contains a Chromium OS verified boot block
index 54eb814ea3dbb2375796a0232be057886ac3efc5..ad864e54429b5411d572bb8413d12664b6cd2d19 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 reset code for U-Boot
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_reset16(Entry_blob):
     """x86 16-bit reset code for U-Boot
index 699a0c6bcbe9c081b1a093548aafda067a0d94ec..9a663f0ae231f302cb2dd084fdc39c5fa5dc24ac 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 reset code for U-Boot
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_reset16_spl(Entry_blob):
     """x86 16-bit reset code for U-Boot
index 4eedb8d601d90bb8a6021b5afd373969a0de5f0d..864508f367261ed6b36ff0d0719d216ec6cd3942 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 reset code for U-Boot
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_reset16_tpl(Entry_blob):
     """x86 16-bit reset code for U-Boot
index 6736b692d5102730b0e772e5ad02b1e7147ecb6b..d8345f67221f4b1e4f1eb9696cf39c047c174c1a 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 start-up code for U-Boot
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_start16(Entry_blob):
     """x86 16-bit start-up code for U-Boot
index c8c70639de01ec93d838b3abac5f47fd782357a8..ad520d3c6d905619c5ce7b99464127a8c0cba509 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 start-up code for U-Boot SPL
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_start16_spl(Entry_blob):
     """x86 16-bit start-up code for SPL
index 5261a8adf04972ff8722574ed5ca9128601421bc..ccc8727d1d45160a57c9990cd476cd1d92ad4224 100644 (file)
@@ -5,8 +5,8 @@
 # Entry-type module for the 16-bit x86 start-up code for U-Boot TPL
 #
 
-from entry import Entry
-from blob import Entry_blob
+from binman.entry import Entry
+from binman.etype.blob import Entry_blob
 
 class Entry_x86_start16_tpl(Entry_blob):
     """x86 16-bit start-up code for TPL
index ac6f910d3c00fb4a1accf94701a22fe19f8e3db9..c491d40e9eed0f57f389f7e18c83c2819f2152da 100644 (file)
@@ -9,10 +9,10 @@ import sys
 import tempfile
 import unittest
 
-import fdt
-from fdt import FdtScan
-import fdt_util
-import tools
+from dtoc import fdt
+from dtoc import fdt_util
+from dtoc.fdt import FdtScan
+from patman import tools
 
 class TestFdt(unittest.TestCase):
     @classmethod
index d0f956b6221612b53fc28418c6b0f79349a03a91..25fe60a9cc3b3d9557731c709452633741acfcc0 100644 (file)
@@ -10,7 +10,7 @@ import collections
 import struct
 import sys
 
-import tools
+from patman import tools
 
 # constants imported from lib/fmap.h
 FMAP_SIGNATURE = b'__FMAP__'
index 872b8554440d6a3799a4d0652b1a1e570109addb..5e24920088c5a91becb478d915ed45d777d17011 100644 (file)
@@ -6,8 +6,7 @@
 #
 #    python -m unittest func_test.TestFunctional.testHelp
 
-from __future__ import print_function
-
+import gzip
 import hashlib
 from optparse import OptionParser
 import os
@@ -17,24 +16,23 @@ import sys
 import tempfile
 import unittest
 
-import binman
-import cbfs_util
-import cmdline
-import command
-import control
-import elf
-import elf_test
-import fdt
-from etype import fdtmap
-from etype import image_header
-import fdt_util
-import fmap_util
-import test_util
-import gzip
+from binman import cbfs_util
+from binman import cmdline
+from binman import control
+from binman import elf
+from binman import elf_test
+from binman import fmap_util
+from binman import main
+from binman import state
+from dtoc import fdt
+from dtoc import fdt_util
+from binman.etype import fdtmap
+from binman.etype import image_header
 from image import Image
-import state
-import tools
-import tout
+from patman import command
+from patman import test_util
+from patman import tools
+from patman import tout
 
 # Contents of test files, corresponding to different entry types
 U_BOOT_DATA           = b'1234'
@@ -103,7 +101,7 @@ class TestFunctional(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
         global entry
-        import entry
+        from binman import entry
 
         # Handle the case where argv[0] is 'python'
         cls._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
@@ -1290,8 +1288,8 @@ class TestFunctional(unittest.TestCase):
         with self.assertRaises(ValueError) as e:
             self._DoReadFile('057_unknown_contents.dts', True)
         self.assertIn("Image '/binman': Internal error: Could not complete "
-                "processing of contents: remaining [<_testing.Entry__testing ",
-                str(e.exception))
+                "processing of contents: remaining ["
+                "<binman.etype._testing.Entry__testing ", str(e.exception))
 
     def testBadChangeSize(self):
         """Test that trying to change the size of an entry fails"""
@@ -1338,7 +1336,8 @@ class TestFunctional(unittest.TestCase):
         with self.assertRaises(ValueError) as e:
             self._DoReadFileDtb('061_fdt_update_bad.dts', update_dtb=True)
         self.assertIn('Could not complete processing of Fdt: remaining '
-                      '[<_testing.Entry__testing', str(e.exception))
+                      '[<binman.etype._testing.Entry__testing',
+                        str(e.exception))
 
     def testEntryArgs(self):
         """Test passing arguments to entries from the command line"""
@@ -1430,14 +1429,14 @@ class TestFunctional(unittest.TestCase):
     def testEntryDocs(self):
         """Test for creation of entry documentation"""
         with test_util.capture_sys_output() as (stdout, stderr):
-            control.WriteEntryDocs(binman.GetEntryModules())
+            control.WriteEntryDocs(main.GetEntryModules())
         self.assertTrue(len(stdout.getvalue()) > 0)
 
     def testEntryDocsMissing(self):
         """Test handling of missing entry documentation"""
         with self.assertRaises(ValueError) as e:
             with test_util.capture_sys_output() as (stdout, stderr):
-                control.WriteEntryDocs(binman.GetEntryModules(), 'u_boot')
+                control.WriteEntryDocs(main.GetEntryModules(), 'u_boot')
         self.assertIn('Documentation is missing for modules: u_boot',
                       str(e.exception))
 
index 2beab7fd4d2d50ebdf9b2627005a1944cea78631..523b274c3192c555e599da80b44e6c2b04e3b3c1 100644 (file)
@@ -5,8 +5,6 @@
 # Class for an image, the output of binman
 #
 
-from __future__ import print_function
-
 from collections import OrderedDict
 import fnmatch
 from operator import attrgetter
@@ -14,14 +12,14 @@ import os
 import re
 import sys
 
-from entry import Entry
-from etype import fdtmap
-from etype import image_header
-from etype import section
-import fdt
-import fdt_util
-import tools
-import tout
+from binman.entry import Entry
+from binman.etype import fdtmap
+from binman.etype import image_header
+from binman.etype import section
+from dtoc import fdt
+from dtoc import fdt_util
+from patman import tools
+from patman import tout
 
 class Image(section.Entry_section):
     """A Image, representing an output from binman
index 10f85d1081fec9c0fe3b1cde987d69b3cccacd2d..f85c3c51c0f56cd188ed73650bcdf88f0c2ecd6e 100644 (file)
@@ -7,7 +7,7 @@
 import unittest
 
 from image import Image
-from test_util import capture_sys_output
+from patman.test_util import capture_sys_output
 
 class TestImage(unittest.TestCase):
     def testInvalidFormat(self):
diff --git a/tools/binman/main.py b/tools/binman/main.py
new file mode 100755 (executable)
index 0000000..efa7fa8
--- /dev/null
@@ -0,0 +1,138 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
+
+# Copyright (c) 2016 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+# Creates binary images from input files controlled by a description
+#
+
+"""See README for more information"""
+
+from distutils.sysconfig import get_python_lib
+import glob
+import os
+import site
+import sys
+import traceback
+import unittest
+
+# Bring in the patman and dtoc libraries (but don't override the first path
+# in PYTHONPATH)
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.insert(2, os.path.join(our_path, '..'))
+
+from patman import test_util
+
+# Bring in the libfdt module
+sys.path.insert(2, 'scripts/dtc/pylibfdt')
+sys.path.insert(2, os.path.join(our_path,
+                '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
+
+# When running under python-coverage on Ubuntu 16.04, the dist-packages
+# directories are dropped from the python path. Add them in so that we can find
+# the elffile module. We could use site.getsitepackages() here but unfortunately
+# that is not available in a virtualenv.
+sys.path.append(get_python_lib())
+
+from binman import cmdline
+from binman import control
+from patman import test_util
+
+def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
+    """Run the functional tests and any embedded doctests
+
+    Args:
+        debug: True to enable debugging, which shows a full stack trace on error
+        verbosity: Verbosity level to use
+        test_preserve_dirs: True to preserve the input directory used by tests
+            so that it can be examined afterwards (only useful for debugging
+            tests). If a single test is selected (in args[0]) it also preserves
+            the output directory for this test. Both directories are displayed
+            on the command line.
+        processes: Number of processes to use to run tests (None=same as #CPUs)
+        args: List of positional args provided to binman. This can hold a test
+            name to execute (as in 'binman test testSections', for example)
+        toolpath: List of paths to use for tools
+    """
+    from binman import cbfs_util_test
+    from binman import elf_test
+    from binman import entry_test
+    from binman import fdt_test
+    from binman import ftest
+    from binman import image_test
+    from binman import test
+    import doctest
+
+    result = unittest.TestResult()
+    test_name = args and args[0] or None
+
+    # Run the entry tests first ,since these need to be the first to import the
+    # 'entry' module.
+    test_util.RunTestSuites(
+        result, debug, verbosity, test_preserve_dirs, processes, test_name,
+        toolpath,
+        [entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
+         elf_test.TestElf, image_test.TestImage, cbfs_util_test.TestCbfs])
+
+    return test_util.ReportResult('binman', test_name, result)
+
+def GetEntryModules(include_testing=True):
+    """Get a set of entry class implementations
+
+    Returns:
+        Set of paths to entry class filenames
+    """
+    glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
+    return set([os.path.splitext(os.path.basename(item))[0]
+                for item in glob_list
+                if include_testing or '_testing' not in item])
+
+def RunTestCoverage():
+    """Run the tests and check that we get 100% coverage"""
+    glob_list = GetEntryModules(False)
+    all_set = set([os.path.splitext(os.path.basename(item))[0]
+                   for item in glob_list if '_testing' not in item])
+    test_util.RunTestCoverage('tools/binman/binman', None,
+            ['*test*', '*main.py', 'tools/patman/*', 'tools/dtoc/*'],
+            args.build_dir, all_set)
+
+def RunBinman(args):
+    """Main entry point to binman once arguments are parsed
+
+    Args:
+        args: Command line arguments Namespace object
+    """
+    ret_code = 0
+
+    if not args.debug:
+        sys.tracebacklimit = 0
+
+    if args.cmd == 'test':
+        if args.test_coverage:
+            RunTestCoverage()
+        else:
+            ret_code = RunTests(args.debug, args.verbosity, args.processes,
+                                args.test_preserve_dirs, args.tests,
+                                args.toolpath)
+
+    elif args.cmd == 'entry-docs':
+        control.WriteEntryDocs(GetEntryModules())
+
+    else:
+        try:
+            ret_code = control.Binman(args)
+        except Exception as e:
+            print('binman: %s' % e)
+            if args.debug:
+                print()
+                traceback.print_exc()
+            ret_code = 1
+    return ret_code
+
+
+if __name__ == "__main__":
+    args = cmdline.ParseArgs(sys.argv[1:])
+
+    ret_code = RunBinman(args)
+    sys.exit(ret_code)
index d704ed2c7cd1a589f2cca0596e43aaaba1d5e4ab..36bc5135354f49799fa3d8cf337bf0fcd5fcd52a 100644 (file)
@@ -8,10 +8,10 @@
 import hashlib
 import re
 
-import fdt
+from dtoc import fdt
 import os
-import tools
-import tout
+from patman import tools
+from patman import tout
 
 # Records the device-tree files known to binman, keyed by entry type (e.g.
 # 'u-boot-spl-dtb'). These are the output FDT files, which can be updated by
@@ -167,8 +167,8 @@ def Prepare(images, dtb):
     global output_fdt_info, main_dtb, fdt_path_prefix
     # Import these here in case libfdt.py is not available, in which case
     # the above help option still works.
-    import fdt
-    import fdt_util
+    from dtoc import fdt
+    from dtoc import fdt_util
 
     # If we are updating the DTBs we need to put these updated versions
     # where Entry_blob_dtb can find them. We can ignore 'u-boot.dtb'
index f3a0dc7288dbdcbe17941d2e3bd8355929c6670f..b2f983c715d7428965b7b329f0413728889d24dd 100644 (file)
@@ -1091,7 +1091,8 @@ the -w option, for example:
 
    buildman -o /tmp/build --board sandbox -w
 
-This will write the full build into /tmp/build including object files.
+This will write the full build into /tmp/build including object files. You must
+specify the output directory with -o when using -w.
 
 
 Other options
index 30ebe1d820a7fba8b8358e490df33994fbb6ff43..f8e71de427213967ae5540990ca9235b270db3d1 100644 (file)
@@ -17,12 +17,12 @@ import sys
 import threading
 import time
 
-import builderthread
-import command
-import gitutil
-import terminal
-from terminal import Print
-import toolchain
+from buildman import builderthread
+from buildman import toolchain
+from patman import command
+from patman import gitutil
+from patman import terminal
+from patman.terminal import Print
 
 """
 Theory of Operation
@@ -479,6 +479,9 @@ class Builder:
         Args:
             commit_upto: Commit number to use (0..self.count-1)
         """
+        if self.work_in_output:
+            return self._working_dir
+
         commit_dir = None
         if self.commits:
             commit = self.commits[commit_upto]
@@ -502,6 +505,8 @@ class Builder:
             target: Target name
         """
         output_dir = self._GetOutputDir(commit_upto)
+        if self.work_in_output:
+            return output_dir
         return os.path.join(output_dir, target)
 
     def GetDoneFile(self, commit_upto, target):
index fc6e1ab25da3c5e5f17f1852f0b3bc84eb10a7ff..48fcd6cf7e2477fceba39086bb597bcfc36be60a 100644 (file)
@@ -9,8 +9,8 @@ import shutil
 import sys
 import threading
 
-import command
-import gitutil
+from patman import command
+from patman import gitutil
 
 RETURN_CODE_RETRY = -1
 
@@ -280,8 +280,6 @@ class BuilderThread(threading.Thread):
             work_in_output: Use the output directory as the work directory and
                 don't write to a separate output directory.
         """
-        if work_in_output:
-            return
         # Fatal error
         if result.return_code < 0:
             return
@@ -333,7 +331,7 @@ class BuilderThread(threading.Thread):
 
             # Write out the image and function size information and an objdump
             env = result.toolchain.MakeEnvironment(self.builder.full_path)
-            with open(os.path.join(build_dir, 'env'), 'w') as fd:
+            with open(os.path.join(build_dir, 'out-env'), 'w') as fd:
                 for var in sorted(env.keys()):
                     print('%s="%s"' % (var, env[var]), file=fd)
             lines = []
@@ -379,7 +377,8 @@ class BuilderThread(threading.Thread):
                             capture_stderr=True, cwd=result.out_dir,
                             raise_on_error=False, env=env)
             ubootenv = os.path.join(result.out_dir, 'uboot.env')
-            self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env'])
+            if not work_in_output:
+                self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env'])
 
             # Write out the image sizes file. This is similar to the output
             # of binutil's 'size' utility, but it omits the header line and
@@ -391,17 +390,21 @@ class BuilderThread(threading.Thread):
                 with open(sizes, 'w') as fd:
                     print('\n'.join(lines), file=fd)
 
-        # Write out the configuration files, with a special case for SPL
-        for dirname in ['', 'spl', 'tpl']:
-            self.CopyFiles(result.out_dir, build_dir, dirname, ['u-boot.cfg',
-                'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg', '.config',
-                'include/autoconf.mk', 'include/generated/autoconf.h'])
-
-        # Now write the actual build output
-        if keep_outputs:
-            self.CopyFiles(result.out_dir, build_dir, '', ['u-boot*', '*.bin',
-                '*.map', '*.img', 'MLO', 'SPL', 'include/autoconf.mk',
-                'spl/u-boot-spl*'])
+        if not work_in_output:
+            # Write out the configuration files, with a special case for SPL
+            for dirname in ['', 'spl', 'tpl']:
+                self.CopyFiles(
+                    result.out_dir, build_dir, dirname,
+                    ['u-boot.cfg', 'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg',
+                     '.config', 'include/autoconf.mk',
+                     'include/generated/autoconf.h'])
+
+            # Now write the actual build output
+            if keep_outputs:
+                self.CopyFiles(
+                    result.out_dir, build_dir, '',
+                    ['u-boot*', '*.bin', '*.map', '*.img', 'MLO', 'SPL',
+                     'include/autoconf.mk', 'spl/u-boot-spl*'])
 
     def CopyFiles(self, out_dir, build_dir, dirname, patterns):
         """Copy files from the build directory to the output.
index e4fba2d4b03b785f50033c817bba292f0c8ee960..11a5d8e18ab71465be9424cf930c5e792c75edb7 120000 (symlink)
@@ -1 +1 @@
-buildman.py
\ No newline at end of file
+main.py
\ No newline at end of file
diff --git a/tools/buildman/buildman.py b/tools/buildman/buildman.py
deleted file mode 100755 (executable)
index 30a8690..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0+
-#
-# Copyright (c) 2012 The Chromium OS Authors.
-#
-
-"""See README for more information"""
-
-from __future__ import print_function
-
-import multiprocessing
-import os
-import re
-import sys
-import unittest
-
-# Bring in the patman libraries
-our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.insert(1, os.path.join(our_path, '../patman'))
-
-# Our modules
-import board
-import bsettings
-import builder
-import checkpatch
-import cmdline
-import control
-import doctest
-import gitutil
-import patchstream
-import terminal
-import toolchain
-
-def RunTests(skip_net_tests):
-    import func_test
-    import test
-    import doctest
-
-    result = unittest.TestResult()
-    for module in ['toolchain', 'gitutil']:
-        suite = doctest.DocTestSuite(module)
-        suite.run(result)
-
-    sys.argv = [sys.argv[0]]
-    if skip_net_tests:
-        test.use_network = False
-    for module in (test.TestBuild, func_test.TestFunctional):
-        suite = unittest.TestLoader().loadTestsFromTestCase(module)
-        suite.run(result)
-
-    print(result)
-    for test, err in result.errors:
-        print(err)
-    for test, err in result.failures:
-        print(err)
-
-
-options, args = cmdline.ParseArgs()
-
-# Run our meagre tests
-if options.test:
-    RunTests(options.skip_net_tests)
-
-# Build selected commits for selected boards
-else:
-    bsettings.Setup(options.config_file)
-    ret_code = control.DoBuildman(options, args)
-    sys.exit(ret_code)
index 1377b9d2bec8a1db6ff7690e6d3a217dfae8bbdc..680c072d6628f6bedaccf1775b4889d89595ef40 100644 (file)
@@ -76,8 +76,7 @@ def ParseArgs():
           default=False, help="Do a dry run (describe actions, but do nothing)")
     parser.add_option('-N', '--no-subdirs', action='store_true', dest='no_subdirs',
           default=False, help="Don't create subdirectories when building current source for a single board")
-    parser.add_option('-o', '--output-dir', type='string',
-          dest='output_dir', default='..',
+    parser.add_option('-o', '--output-dir', type='string', dest='output_dir',
           help='Directory where all builds happen and buildman has its workspace (default is ../)')
     parser.add_option('-O', '--override-toolchain', type='string',
           help="Override host toochain to use for sandbox (e.g. 'clang-7')")
index 30c030fd16ee596a3c901837a103495663f6ab5a..071c2613ecf5785533ce002e427ca9aa6f96d3b9 100644 (file)
@@ -5,18 +5,18 @@
 import multiprocessing
 import os
 import shutil
+import subprocess
 import sys
 
-import board
-import bsettings
-from builder import Builder
-import gitutil
-import patchstream
-import terminal
-from terminal import Print
-import toolchain
-import command
-import subprocess
+from buildman import board
+from buildman import bsettings
+from buildman import toolchain
+from buildman.builder import Builder
+from patman import command
+from patman import gitutil
+from patman import patchstream
+from patman import terminal
+from patman.terminal import Print
 
 def GetPlural(count):
     """Returns a plural 's' if count is not 1"""
@@ -175,6 +175,10 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
     if options.incremental:
         print(col.Color(col.RED,
                         'Warning: -I has been removed. See documentation'))
+    if not options.output_dir:
+        if options.work_in_output:
+            sys.exit(col.Color(col.RED, '-w requires that you specify -o'))
+        options.output_dir = '..'
 
     # Work out what subset of the boards we are building
     if not boards:
@@ -207,7 +211,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
         sys.exit(col.Color(col.RED, 'No matching boards found'))
 
     if options.print_prefix:
-        err = ShowToolchainInfo(boards, toolchains)
+        err = ShowToolchainPrefix(boards, toolchains)
         if err:
             sys.exit(col.Color(col.RED, err))
         return 0
index 1fbc6f6b0034cfd3e69245b9ff812c299fb2ff4e..418677f9ccb34c9d8fd58c8a0e453eeb44e74cee 100644 (file)
@@ -8,15 +8,15 @@ import sys
 import tempfile
 import unittest
 
-import board
-import bsettings
-import cmdline
-import command
-import control
-import gitutil
-import terminal
-import toolchain
-import tools
+from buildman import board
+from buildman import bsettings
+from buildman import cmdline
+from buildman import control
+from buildman import toolchain
+from patman import command
+from patman import gitutil
+from patman import terminal
+from patman import tools
 
 settings_data = '''
 # Buildman settings file
@@ -546,6 +546,13 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(self._builder.count, self._total_builds)
         self.assertEqual(self._builder.fail, 0)
 
+    def testEnvironment(self):
+        """Test that the done and environment files are written to out-env"""
+        self._RunControl('-o', self._output_dir)
+        board0_dir = os.path.join(self._output_dir, 'current', 'board0')
+        self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
+        self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env')))
+
     def testWorkInOutput(self):
         """Test the -w option which should write directly to the output dir"""
         board_list = board.Boards()
@@ -554,6 +561,10 @@ class TestFunctional(unittest.TestCase):
                          boards=board_list)
         self.assertTrue(
             os.path.exists(os.path.join(self._output_dir, 'u-boot')))
+        self.assertTrue(
+            os.path.exists(os.path.join(self._output_dir, 'done')))
+        self.assertTrue(
+            os.path.exists(os.path.join(self._output_dir, 'out-env')))
 
     def testWorkInOutputFail(self):
         """Test the -w option failures"""
@@ -569,3 +580,9 @@ class TestFunctional(unittest.TestCase):
             self._RunControl('-b', self._test_branch, '-o', self._output_dir,
                              '-w', clean_dir=False, boards=board_list)
         self.assertIn("single commit", str(e.exception))
+
+        board_list = board.Boards()
+        board_list.AddBoard(board.Board(*boards[0]))
+        with self.assertRaises(SystemExit) as e:
+            self._RunControl('-w', clean_dir=False)
+        self.assertIn("specify -o", str(e.exception))
diff --git a/tools/buildman/main.py b/tools/buildman/main.py
new file mode 100755 (executable)
index 0000000..2b71473
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+
+"""See README for more information"""
+
+import doctest
+import multiprocessing
+import os
+import re
+import sys
+import unittest
+
+# Bring in the patman libraries
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.insert(1, os.path.join(our_path, '..'))
+
+# Our modules
+from buildman import board
+from buildman import bsettings
+from buildman import builder
+from buildman import cmdline
+from buildman import control
+from buildman import toolchain
+from patman import patchstream
+from patman import gitutil
+from patman import terminal
+
+def RunTests(skip_net_tests):
+    import func_test
+    import test
+    import doctest
+
+    result = unittest.TestResult()
+    for module in ['buildman.toolchain', 'patman.gitutil']:
+        suite = doctest.DocTestSuite(module)
+        suite.run(result)
+
+    sys.argv = [sys.argv[0]]
+    if skip_net_tests:
+        test.use_network = False
+    for module in (test.TestBuild, func_test.TestFunctional):
+        suite = unittest.TestLoader().loadTestsFromTestCase(module)
+        suite.run(result)
+
+    print(result)
+    for test, err in result.errors:
+        print(err)
+    for test, err in result.failures:
+        print(err)
+
+
+options, args = cmdline.ParseArgs()
+
+# Run our meagre tests
+if options.test:
+    RunTests(options.skip_net_tests)
+
+# Build selected commits for selected boards
+else:
+    bsettings.Setup(options.config_file)
+    ret_code = control.DoBuildman(options, args)
+    sys.exit(ret_code)
index d32b22653fba088c24cfd9fd7c3ba00efab59ff8..40811ba9f9e73c8bde310a8c41a88fb13db48254 100644 (file)
@@ -11,18 +11,17 @@ import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../patman'))
-
-import board
-import bsettings
-import builder
-import control
-import command
-import commit
-import terminal
-import test_util
-import toolchain
-import tools
+
+from buildman import board
+from buildman import bsettings
+from buildman import builder
+from buildman import control
+from buildman import toolchain
+from patman import commit
+from patman import command
+from patman import terminal
+from patman import test_util
+from patman import tools
 
 use_network = True
 
@@ -583,7 +582,7 @@ class TestBuild(unittest.TestCase):
                 url = self.toolchains.LocateArchUrl('arm')
             self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
                     'crosstool/files/bin/x86_64/.*/'
-                    'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
+                    'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
 
     def testGetEnvArgs(self):
         """Test the GetEnvArgs() function"""
index 4456a805c742d0505500f8c5ea27803f794d660a..acb5a29c8fb83af7e4e63b14737adb8d7ff95f81 100644 (file)
@@ -10,10 +10,10 @@ import sys
 import tempfile
 import urllib.request, urllib.error, urllib.parse
 
-import bsettings
-import command
-import terminal
-import tools
+from buildman import bsettings
+from patman import command
+from patman import terminal
+from patman import tools
 
 (PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH,
     PRIORITY_CALC) = list(range(4))
index 90a9e1a626912f6230d4e6c4016bcb1cadb10319..ecfe0624d1090659bbb0ee6ead9c8170d7c3c794 100644 (file)
@@ -15,9 +15,9 @@ import collections
 import copy
 import sys
 
-import fdt
-import fdt_util
-import tools
+from dtoc import fdt
+from dtoc import fdt_util
+from patman import tools
 
 # When we see these properties we ignore them - i.e. do not create a structure member
 PROP_IGNORE_LIST = [
index 896ca44e62f76ce1117198f7b20c30bcca8d3326..11a5d8e18ab71465be9424cf930c5e792c75edb7 120000 (symlink)
@@ -1 +1 @@
-dtoc.py
\ No newline at end of file
+main.py
\ No newline at end of file
diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py
deleted file mode 100755 (executable)
index f31cba9..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0+
-#
-# Copyright (C) 2016 Google, Inc
-# Written by Simon Glass <sjg@chromium.org>
-#
-
-"""Device tree to C tool
-
-This tool converts a device tree binary file (.dtb) into two C files. The
-indent is to allow a C program to access data from the device tree without
-having to link against libfdt. By putting the data from the device tree into
-C structures, normal C code can be used. This helps to reduce the size of the
-compiled program.
-
-Dtoc produces two output files:
-
-   dt-structs.h  - contains struct definitions
-   dt-platdata.c - contains data from the device tree using the struct
-                      definitions, as well as U-Boot driver definitions.
-
-This tool is used in U-Boot to provide device tree data to SPL without
-increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
-options. For more information about the use of this options and tool please
-see doc/driver-model/of-plat.rst
-"""
-
-from __future__ import print_function
-
-from optparse import OptionParser
-import os
-import sys
-import unittest
-
-# Bring in the patman libraries
-our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../patman'))
-
-# Bring in the libfdt module
-sys.path.insert(0, 'scripts/dtc/pylibfdt')
-sys.path.insert(0, os.path.join(our_path,
-                '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
-
-import dtb_platdata
-import test_util
-
-def run_tests(args):
-    """Run all the test we have for dtoc
-
-    Args:
-        args: List of positional args provided to dtoc. This can hold a test
-            name to execute (as in 'dtoc -t test_empty_file', for example)
-    """
-    import test_dtoc
-
-    result = unittest.TestResult()
-    sys.argv = [sys.argv[0]]
-    test_name = args and args[0] or None
-    for module in (test_dtoc.TestDtoc,):
-        if test_name:
-            try:
-                suite = unittest.TestLoader().loadTestsFromName(test_name, module)
-            except AttributeError:
-                continue
-        else:
-            suite = unittest.TestLoader().loadTestsFromTestCase(module)
-        suite.run(result)
-
-    print(result)
-    for _, err in result.errors:
-        print(err)
-    for _, err in result.failures:
-        print(err)
-    if result.errors or result.failures:
-        print('dtoc tests FAILED')
-        return 1
-    return 0
-
-def RunTestCoverage():
-    """Run the tests and check that we get 100% coverage"""
-    sys.argv = [sys.argv[0]]
-    test_util.RunTestCoverage('tools/dtoc/dtoc.py', '/dtoc.py',
-            ['tools/patman/*.py', '*/fdt*', '*test*'], options.build_dir)
-
-
-if __name__ != '__main__':
-    sys.exit(1)
-
-parser = OptionParser()
-parser.add_option('-B', '--build-dir', type='string', default='b',
-        help='Directory containing the build output')
-parser.add_option('-d', '--dtb-file', action='store',
-                  help='Specify the .dtb input file')
-parser.add_option('--include-disabled', action='store_true',
-                  help='Include disabled nodes')
-parser.add_option('-o', '--output', action='store', default='-',
-                  help='Select output filename')
-parser.add_option('-P', '--processes', type=int,
-                  help='set number of processes to use for running tests')
-parser.add_option('-t', '--test', action='store_true', dest='test',
-                  default=False, help='run tests')
-parser.add_option('-T', '--test-coverage', action='store_true',
-                default=False, help='run tests and check for 100% coverage')
-(options, args) = parser.parse_args()
-
-# Run our meagre tests
-if options.test:
-    ret_code = run_tests(args)
-    sys.exit(ret_code)
-
-elif options.test_coverage:
-    RunTestCoverage()
-
-else:
-    dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
-                           options.output)
index 1b7b730359ae80c84260b58b85a3284a0c4f88a4..188490b728f890d05ab8b793fcdc894df4390ebb 100644 (file)
@@ -8,10 +8,10 @@
 import struct
 import sys
 
-import fdt_util
+from dtoc import fdt_util
 import libfdt
 from libfdt import QUIET_NOTFOUND
-import tools
+from patman import tools
 
 # This deals with a device tree, presenting it as an assortment of Node and
 # Prop objects, representing nodes and properties, respectively. This file
index b105faec74908573a6c24b129875d0b0b3ede1f0..b0407937723e836b7a4f5fa04a8e32a9da77239e 100644 (file)
@@ -13,8 +13,8 @@ import struct
 import sys
 import tempfile
 
-import command
-import tools
+from patman import command
+from patman import tools
 
 def fdt32_to_cpu(val):
     """Convert a device tree cell to an integer
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
new file mode 100755 (executable)
index 0000000..b94d9c3
--- /dev/null
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2016 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+
+"""Device tree to C tool
+
+This tool converts a device tree binary file (.dtb) into two C files. The
+indent is to allow a C program to access data from the device tree without
+having to link against libfdt. By putting the data from the device tree into
+C structures, normal C code can be used. This helps to reduce the size of the
+compiled program.
+
+Dtoc produces two output files:
+
+   dt-structs.h  - contains struct definitions
+   dt-platdata.c - contains data from the device tree using the struct
+                      definitions, as well as U-Boot driver definitions.
+
+This tool is used in U-Boot to provide device tree data to SPL without
+increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
+options. For more information about the use of this options and tool please
+see doc/driver-model/of-plat.rst
+"""
+
+from optparse import OptionParser
+import os
+import sys
+import unittest
+
+# Bring in the patman libraries
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(our_path, '..'))
+
+# Bring in the libfdt module
+sys.path.insert(0, 'scripts/dtc/pylibfdt')
+sys.path.insert(0, os.path.join(our_path,
+                '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
+
+from dtoc import dtb_platdata
+from patman import test_util
+
+def run_tests(args):
+    """Run all the test we have for dtoc
+
+    Args:
+        args: List of positional args provided to dtoc. This can hold a test
+            name to execute (as in 'dtoc -t test_empty_file', for example)
+    """
+    import test_dtoc
+
+    result = unittest.TestResult()
+    sys.argv = [sys.argv[0]]
+    test_name = args and args[0] or None
+    for module in (test_dtoc.TestDtoc,):
+        if test_name:
+            try:
+                suite = unittest.TestLoader().loadTestsFromName(test_name, module)
+            except AttributeError:
+                continue
+        else:
+            suite = unittest.TestLoader().loadTestsFromTestCase(module)
+        suite.run(result)
+
+    print(result)
+    for _, err in result.errors:
+        print(err)
+    for _, err in result.failures:
+        print(err)
+    if result.errors or result.failures:
+        print('dtoc tests FAILED')
+        return 1
+    return 0
+
+def RunTestCoverage():
+    """Run the tests and check that we get 100% coverage"""
+    sys.argv = [sys.argv[0]]
+    test_util.RunTestCoverage('tools/dtoc/dtoc', '/main.py',
+            ['tools/patman/*.py', '*/fdt*', '*test*'], options.build_dir)
+
+
+if __name__ != '__main__':
+    sys.exit(1)
+
+parser = OptionParser()
+parser.add_option('-B', '--build-dir', type='string', default='b',
+        help='Directory containing the build output')
+parser.add_option('-d', '--dtb-file', action='store',
+                  help='Specify the .dtb input file')
+parser.add_option('--include-disabled', action='store_true',
+                  help='Include disabled nodes')
+parser.add_option('-o', '--output', action='store', default='-',
+                  help='Select output filename')
+parser.add_option('-P', '--processes', type=int,
+                  help='set number of processes to use for running tests')
+parser.add_option('-t', '--test', action='store_true', dest='test',
+                  default=False, help='run tests')
+parser.add_option('-T', '--test-coverage', action='store_true',
+                default=False, help='run tests and check for 100% coverage')
+(options, args) = parser.parse_args()
+
+# Run our meagre tests
+if options.test:
+    ret_code = run_tests(args)
+    sys.exit(ret_code)
+
+elif options.test_coverage:
+    RunTestCoverage()
+
+else:
+    dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
+                           options.output)
index d733b70655865584dad970b556dd88ecf484b40a..8498e8303c26131a0195b5f31921694725adec26 100755 (executable)
@@ -9,22 +9,20 @@ This includes unit tests for some functions and functional tests for the dtoc
 tool.
 """
 
-from __future__ import print_function
-
 import collections
 import os
 import struct
 import unittest
 
-import dtb_platdata
+from dtoc import dtb_platdata
 from dtb_platdata import conv_name_to_c
 from dtb_platdata import get_compat_name
 from dtb_platdata import get_value
 from dtb_platdata import tab_to
-import fdt
-import fdt_util
-import test_util
-import tools
+from dtoc import fdt
+from dtoc import fdt_util
+from patman import test_util
+from patman import tools
 
 our_path = os.path.dirname(os.path.realpath(__file__))
 
index 3316757e61e3ede85355587edc4dd9c290c10838..375e906424c5a29c92f12957780d169e3083419b 100755 (executable)
@@ -4,8 +4,6 @@
 # Written by Simon Glass <sjg@chromium.org>
 #
 
-from __future__ import print_function
-
 from optparse import OptionParser
 import glob
 import os
@@ -16,17 +14,16 @@ import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-for dirname in ['../patman', '..']:
-    sys.path.insert(0, os.path.join(our_path, dirname))
+sys.path.insert(1, os.path.join(our_path, '..'))
 
-import command
-import fdt
+from dtoc import fdt
+from dtoc import fdt_util
+from dtoc.fdt_util import fdt32_to_cpu
 from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, BytesToValue
-import fdt_util
-from fdt_util import fdt32_to_cpu
 import libfdt
-import test_util
-import tools
+from patman import command
+from patman import test_util
+from patman import tools
 
 def _GetPropertyValue(dtb, node, prop_name):
     """Low-level function to get the property value based on its offset
index 381739d28df20edf7422861bdc946cd2982d2e3f..8734663cd4c770f4a393b23601b78b78084f1e7d 100644 (file)
@@ -1647,6 +1647,9 @@ static int check_device_config(int dev)
                        goto err;
                }
                DEVTYPE(dev) = mtdinfo.type;
+               if (DEVESIZE(dev) == 0 && ENVSECTORS(dev) == 0 &&
+                   mtdinfo.type == MTD_NORFLASH)
+                       DEVESIZE(dev) = mtdinfo.erasesize;
                if (DEVESIZE(dev) == 0)
                        /* Assume the erase size is the same as the env-size */
                        DEVESIZE(dev) = ENVSIZE(dev);
index 2a8058f57fa4e13ebe99aa82b77e1b411ebffda4..7e168a1e6befd11bb981d09de7dfcef6d2147d50 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fdt_region.h>
 
 #include "fdt_host.h"
 #include "libfdt_internal.h"
index 4f6382bc7ca92c0b80f353537d34fe47f844c3ff..4ee7aa1f891ed9a4e9a08e2a13c8f9468c52abc7 100755 (executable)
@@ -22,8 +22,7 @@ import sys
 import tempfile
 import time
 
-sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'buildman'))
-import kconfiglib
+from buildman import kconfiglib
 
 ### constant variables ###
 OUTPUT_FILE = 'boards.cfg'
index 5bb68965e7632e78a79bfd894a91d92273444a13..9a83b7f6755f89c6b202897d7487fcdbe687a891 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "mkimage.h"
 #include <bootm.h>
+#include <fdt_region.h>
 #include <image.h>
 #include <version.h>
 
diff --git a/tools/libfdt/fdt_ro.c b/tools/libfdt/fdt_ro.c
new file mode 100644 (file)
index 0000000..8a9735a
--- /dev/null
@@ -0,0 +1,2 @@
+#include "fdt_host.h"
+#include "../scripts/dtc/libfdt/fdt_ro.c"
index d8bf7fd0717fe1c405317e9e5ea95698a50ecefc..36361f9ed1b6c70b05bed13443c750e1d2806e12 100755 (executable)
@@ -314,11 +314,9 @@ import tempfile
 import threading
 import time
 
-sys.path.append(os.path.join(os.path.dirname(__file__), 'buildman'))
-sys.path.append(os.path.join(os.path.dirname(__file__), 'patman'))
-import bsettings
-import kconfiglib
-import toolchain
+from buildman import bsettings
+from buildman import kconfiglib
+from buildman import toolchain
 
 SHOW_GNU_MAKE = 'scripts/show-gnu-make'
 SLEEP_TIME=0.03
index d47ea438b7da58cc1c6d569dbc8c55f0b6e3e6f6..795b5193145e2d58b5682f25adc775f03d0dab83 100644 (file)
@@ -3,12 +3,14 @@
 #
 
 import collections
-import command
-import gitutil
 import os
 import re
 import sys
-import terminal
+
+from patman import command
+from patman import gitutil
+from patman import terminal
+from patman import tools
 
 def FindCheckPatch():
     top_level = gitutil.GetTopLevel()
index 5fbd2c4a3e9c3fbd6dd7b8806ec67a54f7c791c6..e67ac159e5a0e9cfe401244f43c185c788766011 100644 (file)
@@ -3,8 +3,9 @@
 #
 
 import os
-import cros_subprocess
-import tools
+
+from patman import cros_subprocess
+from patman import tools
 
 """Shell command ease-ups for Python."""
 
index 76319fff37e3df6f0fc3bd515c92209470658ce1..b7e2825de88148c6b577519ded479e40987ac337 100644 (file)
@@ -12,15 +12,12 @@ import sys
 import tempfile
 import unittest
 
-try:
-    from StringIO import StringIO
-except ImportError:
-    from io import StringIO
-
-import gitutil
-import patchstream
-import settings
-import tools
+from io import StringIO
+
+from patman import gitutil
+from patman import patchstream
+from patman import settings
+from patman import tools
 
 
 @contextlib.contextmanager
index 0ffb55a8219ffbcc886b086ffdff0bcad61fd74a..473f0feebf40b4ebb6a73c2be117925de24259c1 100644 (file)
@@ -2,10 +2,11 @@
 # Copyright (c) 2012 The Chromium OS Authors.
 #
 
-import command
-import gitutil
 import os
 
+from patman import command
+from patman import gitutil
+
 def FindGetMaintainer():
     """Look for the get_maintainer.pl script.
 
index a2a225c6b903bbf940b0902852d76788a5a46c9d..770a0510142cf19ca271fa554d5170d6d5e8f321 100644 (file)
@@ -2,17 +2,17 @@
 # Copyright (c) 2011 The Chromium OS Authors.
 #
 
-import command
 import re
 import os
-import series
 import subprocess
 import sys
-import terminal
 
-import checkpatch
-import settings
-import tools
+from patman import checkpatch
+from patman import command
+from patman import series
+from patman import settings
+from patman import terminal
+from patman import tools
 
 # True to use --no-decorate - we check this in Setup()
 use_no_decorate = True
diff --git a/tools/patman/main.py b/tools/patman/main.py
new file mode 100755 (executable)
index 0000000..f3d9c0c
--- /dev/null
@@ -0,0 +1,184 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2011 The Chromium OS Authors.
+#
+
+"""See README for more information"""
+
+from optparse import OptionParser
+import os
+import re
+import sys
+import unittest
+
+if __name__ == "__main__":
+    # Allow 'from patman import xxx to work'
+    our_path = os.path.dirname(os.path.realpath(__file__))
+    sys.path.append(os.path.join(our_path, '..'))
+
+# Our modules
+from patman import checkpatch
+from patman import command
+from patman import gitutil
+from patman import patchstream
+from patman import project
+from patman import settings
+from patman import terminal
+from patman import test
+
+
+parser = OptionParser()
+parser.add_option('-H', '--full-help', action='store_true', dest='full_help',
+       default=False, help='Display the README file')
+parser.add_option('-c', '--count', dest='count', type='int',
+       default=-1, help='Automatically create patches from top n commits')
+parser.add_option('-i', '--ignore-errors', action='store_true',
+       dest='ignore_errors', default=False,
+       help='Send patches email even if patch errors are found')
+parser.add_option('-m', '--no-maintainers', action='store_false',
+       dest='add_maintainers', default=True,
+       help="Don't cc the file maintainers automatically")
+parser.add_option('-l', '--limit-cc', dest='limit', type='int',
+       default=None, help='Limit the cc list to LIMIT entries [default: %default]')
+parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
+       default=False, help="Do a dry run (create but don't email patches)")
+parser.add_option('-p', '--project', default=project.DetectProject(),
+                  help="Project name; affects default option values and "
+                  "aliases [default: %default]")
+parser.add_option('-r', '--in-reply-to', type='string', action='store',
+                  help="Message ID that this series is in reply to")
+parser.add_option('-s', '--start', dest='start', type='int',
+       default=0, help='Commit to start creating patches from (0 = HEAD)')
+parser.add_option('-t', '--ignore-bad-tags', action='store_true',
+                  default=False, help='Ignore bad tags / aliases')
+parser.add_option('--test', action='store_true', dest='test',
+                  default=False, help='run tests')
+parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
+       default=False, help='Verbose output of errors and warnings')
+parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store',
+       default=None, help='Output cc list for patch file (used by git)')
+parser.add_option('--no-check', action='store_false', dest='check_patch',
+                  default=True,
+                  help="Don't check for patch compliance")
+parser.add_option('--no-tags', action='store_false', dest='process_tags',
+                  default=True, help="Don't process subject tags as aliaes")
+parser.add_option('--smtp-server', type='str',
+                  help="Specify the SMTP server to 'git send-email'")
+parser.add_option('-T', '--thread', action='store_true', dest='thread',
+                  default=False, help='Create patches as a single thread')
+
+parser.usage += """
+
+Create patches from commits in a branch, check them and email them as
+specified by tags you place in the commits. Use -n to do a dry run first."""
+
+
+# Parse options twice: first to get the project and second to handle
+# defaults properly (which depends on project).
+(options, args) = parser.parse_args()
+settings.Setup(parser, options.project, '')
+(options, args) = parser.parse_args()
+
+if __name__ != "__main__":
+    pass
+
+# Run our meagre tests
+elif options.test:
+    import doctest
+    from patman import func_test
+
+    sys.argv = [sys.argv[0]]
+    result = unittest.TestResult()
+    for module in (test.TestPatch, func_test.TestFunctional):
+        suite = unittest.TestLoader().loadTestsFromTestCase(module)
+        suite.run(result)
+
+    for module in ['gitutil', 'settings', 'terminal']:
+        suite = doctest.DocTestSuite(module)
+        suite.run(result)
+
+    # TODO: Surely we can just 'print' result?
+    print(result)
+    for test, err in result.errors:
+        print(err)
+    for test, err in result.failures:
+        print(err)
+
+# Called from git with a patch filename as argument
+# Printout a list of additional CC recipients for this patch
+elif options.cc_cmd:
+    fd = open(options.cc_cmd, 'r')
+    re_line = re.compile('(\S*) (.*)')
+    for line in fd.readlines():
+        match = re_line.match(line)
+        if match and match.group(1) == args[0]:
+            for cc in match.group(2).split('\0'):
+                cc = cc.strip()
+                if cc:
+                    print(cc)
+    fd.close()
+
+elif options.full_help:
+    pager = os.getenv('PAGER')
+    if not pager:
+        pager = 'more'
+    fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
+                         'README')
+    command.Run(pager, fname)
+
+# Process commits, produce patches files, check them, email them
+else:
+    gitutil.Setup()
+
+    if options.count == -1:
+        # Work out how many patches to send if we can
+        options.count = gitutil.CountCommitsToBranch() - options.start
+
+    col = terminal.Color()
+    if not options.count:
+        str = 'No commits found to process - please use -c flag'
+        sys.exit(col.Color(col.RED, str))
+
+    # Read the metadata from the commits
+    if options.count:
+        series = patchstream.GetMetaData(options.start, options.count)
+        cover_fname, args = gitutil.CreatePatches(options.start, options.count,
+                series)
+
+    # Fix up the patch files to our liking, and insert the cover letter
+    patchstream.FixPatches(series, args)
+    if cover_fname and series.get('cover'):
+        patchstream.InsertCoverLetter(cover_fname, series, options.count)
+
+    # Do a few checks on the series
+    series.DoChecks()
+
+    # Check the patches, and run them through 'git am' just to be sure
+    if options.check_patch:
+        ok = checkpatch.CheckPatches(options.verbose, args)
+    else:
+        ok = True
+
+    cc_file = series.MakeCcFile(options.process_tags, cover_fname,
+                                not options.ignore_bad_tags,
+                                options.add_maintainers, options.limit)
+
+    # Email the patches out (giving the user time to check / cancel)
+    cmd = ''
+    its_a_go = ok or options.ignore_errors
+    if its_a_go:
+        cmd = gitutil.EmailPatches(series, cover_fname, args,
+                options.dry_run, not options.ignore_bad_tags, cc_file,
+                in_reply_to=options.in_reply_to, thread=options.thread,
+                smtp_server=options.smtp_server)
+    else:
+        print(col.Color(col.RED, "Not sending emails due to errors/warnings"))
+
+    # For a dry run, just show our actions as a sanity check
+    if options.dry_run:
+        series.ShowActions(args, cmd, options.process_tags)
+        if not its_a_go:
+            print(col.Color(col.RED, "Email would not be sent"))
+
+    os.remove(cc_file)
index df3eb7483bb2f5f95770bc7d2d1ae24fe059d21f..405297505c9ca1bc584ec76817b554d8281b3530 100644 (file)
@@ -9,10 +9,10 @@ import re
 import shutil
 import tempfile
 
-import command
-import commit
-import gitutil
-from series import Series
+from patman import command
+from patman import commit
+from patman import gitutil
+from patman.series import Series
 
 # Tags that we detect and remove
 re_remove = re.compile('^BUG=|^TEST=|^BRANCH=|^Review URL:'
index 6cc3d7a56a54b88c36534e232952b58d2c053e34..11a5d8e18ab71465be9424cf930c5e792c75edb7 120000 (symlink)
@@ -1 +1 @@
-patman.py
\ No newline at end of file
+main.py
\ No newline at end of file
diff --git a/tools/patman/patman.py b/tools/patman/patman.py
deleted file mode 100755 (executable)
index 7f4ac9a..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0+
-#
-# Copyright (c) 2011 The Chromium OS Authors.
-#
-
-"""See README for more information"""
-
-from optparse import OptionParser
-import os
-import re
-import sys
-import unittest
-
-# Our modules
-try:
-    from patman import checkpatch, command, gitutil, patchstream, \
-        project, settings, terminal, test
-except ImportError:
-    import checkpatch
-    import command
-    import gitutil
-    import patchstream
-    import project
-    import settings
-    import terminal
-    import test
-
-
-parser = OptionParser()
-parser.add_option('-H', '--full-help', action='store_true', dest='full_help',
-       default=False, help='Display the README file')
-parser.add_option('-c', '--count', dest='count', type='int',
-       default=-1, help='Automatically create patches from top n commits')
-parser.add_option('-i', '--ignore-errors', action='store_true',
-       dest='ignore_errors', default=False,
-       help='Send patches email even if patch errors are found')
-parser.add_option('-m', '--no-maintainers', action='store_false',
-       dest='add_maintainers', default=True,
-       help="Don't cc the file maintainers automatically")
-parser.add_option('-l', '--limit-cc', dest='limit', type='int',
-       default=None, help='Limit the cc list to LIMIT entries [default: %default]')
-parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
-       default=False, help="Do a dry run (create but don't email patches)")
-parser.add_option('-p', '--project', default=project.DetectProject(),
-                  help="Project name; affects default option values and "
-                  "aliases [default: %default]")
-parser.add_option('-r', '--in-reply-to', type='string', action='store',
-                  help="Message ID that this series is in reply to")
-parser.add_option('-s', '--start', dest='start', type='int',
-       default=0, help='Commit to start creating patches from (0 = HEAD)')
-parser.add_option('-t', '--ignore-bad-tags', action='store_true',
-                  default=False, help='Ignore bad tags / aliases')
-parser.add_option('--test', action='store_true', dest='test',
-                  default=False, help='run tests')
-parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
-       default=False, help='Verbose output of errors and warnings')
-parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store',
-       default=None, help='Output cc list for patch file (used by git)')
-parser.add_option('--no-check', action='store_false', dest='check_patch',
-                  default=True,
-                  help="Don't check for patch compliance")
-parser.add_option('--no-tags', action='store_false', dest='process_tags',
-                  default=True, help="Don't process subject tags as aliaes")
-parser.add_option('--smtp-server', type='str',
-                  help="Specify the SMTP server to 'git send-email'")
-parser.add_option('-T', '--thread', action='store_true', dest='thread',
-                  default=False, help='Create patches as a single thread')
-
-parser.usage += """
-
-Create patches from commits in a branch, check them and email them as
-specified by tags you place in the commits. Use -n to do a dry run first."""
-
-
-# Parse options twice: first to get the project and second to handle
-# defaults properly (which depends on project).
-(options, args) = parser.parse_args()
-settings.Setup(parser, options.project, '')
-(options, args) = parser.parse_args()
-
-if __name__ != "__main__":
-    pass
-
-# Run our meagre tests
-elif options.test:
-    import doctest
-    import func_test
-
-    sys.argv = [sys.argv[0]]
-    result = unittest.TestResult()
-    for module in (test.TestPatch, func_test.TestFunctional):
-        suite = unittest.TestLoader().loadTestsFromTestCase(module)
-        suite.run(result)
-
-    for module in ['gitutil', 'settings', 'terminal']:
-        suite = doctest.DocTestSuite(module)
-        suite.run(result)
-
-    # TODO: Surely we can just 'print' result?
-    print(result)
-    for test, err in result.errors:
-        print(err)
-    for test, err in result.failures:
-        print(err)
-
-# Called from git with a patch filename as argument
-# Printout a list of additional CC recipients for this patch
-elif options.cc_cmd:
-    fd = open(options.cc_cmd, 'r')
-    re_line = re.compile('(\S*) (.*)')
-    for line in fd.readlines():
-        match = re_line.match(line)
-        if match and match.group(1) == args[0]:
-            for cc in match.group(2).split('\0'):
-                cc = cc.strip()
-                if cc:
-                    print(cc)
-    fd.close()
-
-elif options.full_help:
-    pager = os.getenv('PAGER')
-    if not pager:
-        pager = 'more'
-    fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
-                         'README')
-    command.Run(pager, fname)
-
-# Process commits, produce patches files, check them, email them
-else:
-    gitutil.Setup()
-
-    if options.count == -1:
-        # Work out how many patches to send if we can
-        options.count = gitutil.CountCommitsToBranch() - options.start
-
-    col = terminal.Color()
-    if not options.count:
-        str = 'No commits found to process - please use -c flag'
-        sys.exit(col.Color(col.RED, str))
-
-    # Read the metadata from the commits
-    if options.count:
-        series = patchstream.GetMetaData(options.start, options.count)
-        cover_fname, args = gitutil.CreatePatches(options.start, options.count,
-                series)
-
-    # Fix up the patch files to our liking, and insert the cover letter
-    patchstream.FixPatches(series, args)
-    if cover_fname and series.get('cover'):
-        patchstream.InsertCoverLetter(cover_fname, series, options.count)
-
-    # Do a few checks on the series
-    series.DoChecks()
-
-    # Check the patches, and run them through 'git am' just to be sure
-    if options.check_patch:
-        ok = checkpatch.CheckPatches(options.verbose, args)
-    else:
-        ok = True
-
-    cc_file = series.MakeCcFile(options.process_tags, cover_fname,
-                                not options.ignore_bad_tags,
-                                options.add_maintainers, options.limit)
-
-    # Email the patches out (giving the user time to check / cancel)
-    cmd = ''
-    its_a_go = ok or options.ignore_errors
-    if its_a_go:
-        cmd = gitutil.EmailPatches(series, cover_fname, args,
-                options.dry_run, not options.ignore_bad_tags, cc_file,
-                in_reply_to=options.in_reply_to, thread=options.thread,
-                smtp_server=options.smtp_server)
-    else:
-        print(col.Color(col.RED, "Not sending emails due to errors/warnings"))
-
-    # For a dry run, just show our actions as a sanity check
-    if options.dry_run:
-        series.ShowActions(args, cmd, options.process_tags)
-        if not its_a_go:
-            print(col.Color(col.RED, "Email would not be sent"))
-
-    os.remove(cc_file)
index 1d9cfc06252b4c83ca6c08d03e4d523485567abc..2dfc303729bec8f764cac6a487bd0fd2a1e377c3 100644 (file)
@@ -4,7 +4,7 @@
 
 import os.path
 
-import gitutil
+from patman import gitutil
 
 def DetectProject():
     """Autodetect the name of the current project.
index 6d9d48b1233a467ef2b52339fedf49fc50c99fd2..e5e28cebdf5e0ed016c0c246f4a5f7da8a72bd9f 100644 (file)
@@ -2,16 +2,14 @@
 # Copyright (c) 2011 The Chromium OS Authors.
 #
 
-from __future__ import print_function
-
 import itertools
 import os
 
-import get_maintainer
-import gitutil
-import settings
-import terminal
-import tools
+from patman import get_maintainer
+from patman import gitutil
+from patman import settings
+from patman import terminal
+from patman import tools
 
 # Series-xxx tags that we understand
 valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name',
index 5dc83a850023c779d6ce76ce96aaea9df3056646..ca74fc611ff24fc92a179f3fd01d4800190c2424 100644 (file)
@@ -2,8 +2,6 @@
 # Copyright (c) 2011 The Chromium OS Authors.
 #
 
-from __future__ import print_function
-
 try:
     import configparser as ConfigParser
 except:
@@ -12,9 +10,9 @@ except:
 import os
 import re
 
-import command
-import gitutil
-import tools
+from patman import command
+from patman import gitutil
+from patman import tools
 
 """Default settings per-project.
 
@@ -36,10 +34,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
     - Merge general default settings/aliases with project-specific ones.
 
     # Sample config used for tests below...
-    >>> try:
-    ...     from StringIO import StringIO
-    ... except ImportError:
-    ...     from io import StringIO
+    >>> from io import StringIO
     >>> sample_config = '''
     ... [alias]
     ... me: Peter P. <likesspiders@example.com>
index 5c9e3eea20cf967a4f92477ac46789985b97ddbd..c709438bdc4f737b8509e6e69f6565381785994e 100644 (file)
@@ -7,8 +7,6 @@
 This module handles terminal interaction including ANSI color codes.
 """
 
-from __future__ import print_function
-
 import os
 import re
 import shutil
index 889e186606ea5e6bbe429dcaccc784bd04d8512b..e7f709e34c7fcefb62198e628c0a59a6de57c873 100644 (file)
@@ -8,11 +8,11 @@ import os
 import tempfile
 import unittest
 
-import checkpatch
-import gitutil
-import patchstream
-import series
-import commit
+from patman import checkpatch
+from patman import gitutil
+from patman import patchstream
+from patman import series
+from patman import commit
 
 
 class TestPatch(unittest.TestCase):
index 09f258c26b4736b5784b05583347257074b42024..4d28d9fc922f8c35e1836c59df69eeed52714d44 100644 (file)
@@ -3,21 +3,23 @@
 # Copyright (c) 2016 Google, Inc
 #
 
-from __future__ import print_function
-
 from contextlib import contextmanager
 import glob
+import multiprocessing
 import os
 import sys
+import unittest
 
-import command
+from patman import command
+from patman import test_util
 
-try:
-  from StringIO import StringIO
-except ImportError:
-  from io import StringIO
+from io import StringIO
 
-PYTHON = 'python%d' % sys.version_info[0]
+use_concurrent = True
+try:
+    from concurrencytest import ConcurrentTestSuite, fork_for_tests
+except:
+    use_concurrent = False
 
 
 def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None):
@@ -46,12 +48,15 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None):
         glob_list = []
     glob_list += exclude_list
     glob_list += ['*libfdt.py', '*site-packages*', '*dist-packages*']
-    test_cmd = 'test' if 'binman.py' in prog else '-t'
-    cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools %s-coverage run '
-           '--omit "%s" %s %s -P1' % (build_dir, PYTHON, ','.join(glob_list),
+    test_cmd = 'test' if 'binman' in prog else '-t'
+    prefix = ''
+    if build_dir:
+        prefix = 'PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools ' % build_dir
+    cmd = ('%spython3-coverage run '
+           '--omit "%s" %s %s -P1' % (prefix, ','.join(glob_list),
                                       prog, test_cmd))
     os.system(cmd)
-    stdout = command.Output('%s-coverage' % PYTHON, 'report')
+    stdout = command.Output('python3-coverage', 'report')
     lines = stdout.splitlines()
     if required:
         # Convert '/path/to/name.py' just the module name 'name'
@@ -70,8 +75,8 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None):
     print(coverage)
     if coverage != '100%':
         print(stdout)
-        print("Type '%s-coverage html' to get a report in "
-              'htmlcov/index.html' % PYTHON)
+        print("Type 'python3-coverage html' to get a report in "
+              'htmlcov/index.html')
         print('Coverage error: %s, but should be 100%%' % coverage)
         ok = False
     if not ok:
@@ -90,3 +95,95 @@ def capture_sys_output():
         yield capture_out, capture_err
     finally:
         sys.stdout, sys.stderr = old_out, old_err
+
+
+def ReportResult(toolname:str, test_name: str, result: unittest.TestResult):
+    """Report the results from a suite of tests
+
+    Args:
+        toolname: Name of the tool that ran the tests
+        test_name: Name of test that was run, or None for all
+        result: A unittest.TestResult object containing the results
+    """
+    # Remove errors which just indicate a missing test. Since Python v3.5 If an
+    # ImportError or AttributeError occurs while traversing name then a
+    # synthetic test that raises that error when run will be returned. These
+    # errors are included in the errors accumulated by result.errors.
+    if test_name:
+        errors = []
+
+        for test, err in result.errors:
+            if ("has no attribute '%s'" % test_name) not in err:
+                errors.append((test, err))
+            result.testsRun -= 1
+        result.errors = errors
+
+    print(result)
+    for test, err in result.errors:
+        print(test.id(), err)
+    for test, err in result.failures:
+        print(err, result.failures)
+    if result.skipped:
+        print('%d binman test%s SKIPPED:' %
+              (len(result.skipped), 's' if len(result.skipped) > 1 else ''))
+        for skip_info in result.skipped:
+            print('%s: %s' % (skip_info[0], skip_info[1]))
+    if result.errors or result.failures:
+        print('binman tests FAILED')
+        return 1
+    return 0
+
+
+def RunTestSuites(result, debug, verbosity, test_preserve_dirs, processes,
+                  test_name, toolpath, test_class_list):
+    """Run a series of test suites and collect the results
+
+    Args:
+        result: A unittest.TestResult object to add the results to
+        debug: True to enable debugging, which shows a full stack trace on error
+        verbosity: Verbosity level to use (0-4)
+        test_preserve_dirs: True to preserve the input directory used by tests
+            so that it can be examined afterwards (only useful for debugging
+            tests). If a single test is selected (in args[0]) it also preserves
+            the output directory for this test. Both directories are displayed
+            on the command line.
+        processes: Number of processes to use to run tests (None=same as #CPUs)
+        test_name: Name of test to run, or None for all
+        toolpath: List of paths to use for tools
+        test_class_list: List of test classes to run
+    """
+    for module in []:
+        suite = doctest.DocTestSuite(module)
+        suite.run(result)
+
+    sys.argv = [sys.argv[0]]
+    if debug:
+        sys.argv.append('-D')
+    if verbosity:
+        sys.argv.append('-v%d' % verbosity)
+    if toolpath:
+        for path in toolpath:
+            sys.argv += ['--toolpath', path]
+
+    suite = unittest.TestSuite()
+    loader = unittest.TestLoader()
+    for module in test_class_list:
+        # Test the test module about our arguments, if it is interested
+        if hasattr(module, 'setup_test_args'):
+            setup_test_args = getattr(module, 'setup_test_args')
+            setup_test_args(preserve_indir=test_preserve_dirs,
+                preserve_outdirs=test_preserve_dirs and test_name is not None,
+                toolpath=toolpath, verbosity=verbosity)
+        if test_name:
+            try:
+                suite.addTests(loader.loadTestsFromName(test_name, module))
+            except AttributeError:
+                continue
+        else:
+            suite.addTests(loader.loadTestsFromTestCase(module))
+    if use_concurrent and processes != 1:
+        concurrent_suite = ConcurrentTestSuite(suite,
+                fork_for_tests(processes or multiprocessing.cpu_count()))
+        concurrent_suite.run(result)
+    else:
+        suite.run(result)
index 3feddb292fc70a5a250ab3de30cb01eb17a77403..b50370dfe8dea414bbe6e9d75c88f4e5caabfa77 100644 (file)
@@ -3,9 +3,6 @@
 # Copyright (c) 2016 Google, Inc
 #
 
-from __future__ import print_function
-
-import command
 import glob
 import os
 import shutil
@@ -13,7 +10,8 @@ import struct
 import sys
 import tempfile
 
-import tout
+from patman import command
+from patman import tout
 
 # Output directly (generally this is temporary)
 outdir = None
index 2a384851b0d186fe1ecd7ddd273e201dd94495bf..c7e32720965769014d23ef264db7735e9c68ef18 100644 (file)
@@ -4,11 +4,9 @@
 # Terminal output logging.
 #
 
-from __future__ import print_function
-
 import sys
 
-import terminal
+from patman import terminal
 
 # Output verbosity levels that we support
 ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6)
index df4f04b01c561cc70a8a8025debdedff26389677..06c3562ad8110968f897ae6bf3c1bc5cba0200fa 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/python3
 # SPDX-License-Identifier: GPL-2.0+
 # Copyright 2019 Google LLC
 #
@@ -23,8 +23,6 @@ This script works by:
 Search for ## to update the commit message manually.
 """
 
-from __future__ import print_function
-
 import glob
 import os
 import re
@@ -32,9 +30,8 @@ import sys
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../tools/patman'))
 
-import command
+from patman import command
 
 def rm_kconfig_include(path):
     """Remove a path from Kconfig files