]> git.sur5r.net Git - u-boot/commitdiff
Merge branch 'master' of git://git.denx.de/u-boot-video
authorTom Rini <trini@konsulko.com>
Tue, 26 Jan 2016 14:48:07 +0000 (09:48 -0500)
committerTom Rini <trini@konsulko.com>
Tue, 26 Jan 2016 14:48:07 +0000 (09:48 -0500)
429 files changed:
.checkpatch.conf
Kconfig
Makefile
README
arch/arm/config.mk
arch/arm/cpu/armv7/mx6/clock.c
arch/arm/cpu/armv7/mx7/soc.c
arch/arm/include/asm/arch-mx6/crm_regs.h
arch/arm/include/asm/arch-mx7/imx-regs.h
arch/arm/include/asm/imx-common/dma.h
arch/arm/include/asm/imx-common/regs-apbh.h
arch/arm/include/asm/imx-common/regs-bch.h
arch/arm/mach-tegra/ap.c
arch/mips/include/asm/io.h
arch/openrisc/lib/board.c
arch/powerpc/config.mk
arch/powerpc/cpu/mpc512x/serial.c
arch/powerpc/cpu/mpc5xxx/serial.c
arch/powerpc/cpu/mpc83xx/law.c
arch/powerpc/cpu/mpc85xx/cpu_init.c
arch/powerpc/cpu/mpc8xxx/law.c
arch/x86/cpu/baytrail/valleyview.c
arch/x86/cpu/coreboot/pci.c
arch/x86/cpu/cpu.c
arch/x86/cpu/interrupts.c
arch/x86/cpu/irq.c
arch/x86/cpu/ivybridge/Makefile
arch/x86/cpu/ivybridge/bd82x6x.c
arch/x86/cpu/ivybridge/cpu.c
arch/x86/cpu/ivybridge/early_init.c [deleted file]
arch/x86/cpu/ivybridge/early_me.c
arch/x86/cpu/ivybridge/gma.c
arch/x86/cpu/ivybridge/lpc.c
arch/x86/cpu/ivybridge/model_206ax.c
arch/x86/cpu/ivybridge/northbridge.c
arch/x86/cpu/ivybridge/pch.c [deleted file]
arch/x86/cpu/ivybridge/pci.c [deleted file]
arch/x86/cpu/ivybridge/report_platform.c
arch/x86/cpu/ivybridge/sata.c
arch/x86/cpu/ivybridge/sdram.c
arch/x86/cpu/ivybridge/usb_ehci.c [deleted file]
arch/x86/cpu/ivybridge/usb_xhci.c [deleted file]
arch/x86/cpu/qemu/qemu.c
arch/x86/cpu/quark/Makefile
arch/x86/cpu/quark/irq.c [new file with mode: 0644]
arch/x86/cpu/quark/quark.c
arch/x86/cpu/queensbay/Makefile
arch/x86/cpu/queensbay/irq.c [new file with mode: 0644]
arch/x86/cpu/queensbay/tnc.c
arch/x86/dts/bayleybay.dts
arch/x86/dts/broadwell_som-6896.dts
arch/x86/dts/chromebook_link.dts
arch/x86/dts/chromebox_panther.dts
arch/x86/dts/crownbay.dts
arch/x86/dts/galileo.dts
arch/x86/dts/minnowmax.dts
arch/x86/dts/qemu-x86_i440fx.dts
arch/x86/dts/qemu-x86_q35.dts
arch/x86/include/asm/arch-ivybridge/bd82x6x.h
arch/x86/include/asm/arch-ivybridge/me.h
arch/x86/include/asm/arch-ivybridge/pch.h
arch/x86/include/asm/arch-ivybridge/sandybridge.h
arch/x86/include/asm/cpu.h
arch/x86/include/asm/irq.h
arch/x86/include/asm/u-boot-x86.h
arch/x86/lib/Makefile
arch/x86/lib/mpspec.c
arch/x86/lib/mrccache.c
arch/x86/lib/northbridge-uclass.c [new file with mode: 0644]
arch/x86/lib/pch-uclass.c [deleted file]
board/freescale/b4860qds/b4860qds.c
board/freescale/common/vid.c
board/freescale/common/vid.h
board/freescale/corenet_ds/corenet_ds.c
board/freescale/mx25pdk/Makefile
board/freescale/mx25pdk/lowlevel_init.S [deleted file]
board/freescale/mx25pdk/mx25pdk.c
board/freescale/mx7dsabresd/mx7dsabresd.c
board/freescale/p2041rdb/p2041rdb.c
board/freescale/t102xqds/t102xqds.c
board/freescale/t102xrdb/t102xrdb.c
board/freescale/t1040qds/t1040qds.c
board/freescale/t104xrdb/t104xrdb.c
board/freescale/t208xqds/t208xqds.c
board/freescale/t208xrdb/t208xrdb.c
board/freescale/t4qds/t4240emu.c
board/freescale/t4qds/t4240qds.c
board/freescale/t4rdb/t4240rdb.c
board/google/chromebook_link/link.c
board/renesas/sh7753evb/sh7753evb.c
board/tqc/tqm834x/tqm834x.c
cmd/Kconfig [new file with mode: 0644]
cmd/Makefile [new file with mode: 0644]
cmd/aes.c [new file with mode: 0644]
cmd/ambapp.c [new file with mode: 0644]
cmd/armflash.c [new file with mode: 0644]
cmd/bdinfo.c [new file with mode: 0644]
cmd/bedbug.c [new file with mode: 0644]
cmd/blob.c [new file with mode: 0644]
cmd/bmp.c [new file with mode: 0644]
cmd/boot.c [new file with mode: 0644]
cmd/bootldr.c [new file with mode: 0644]
cmd/bootm.c [new file with mode: 0644]
cmd/bootmenu.c [new file with mode: 0644]
cmd/bootstage.c [new file with mode: 0644]
cmd/cache.c [new file with mode: 0644]
cmd/cbfs.c [new file with mode: 0644]
cmd/clk.c [new file with mode: 0644]
cmd/console.c [new file with mode: 0644]
cmd/cplbinfo.c [new file with mode: 0644]
cmd/cpu.c [new file with mode: 0644]
cmd/cramfs.c [new file with mode: 0644]
cmd/dataflash_mmc_mux.c [new file with mode: 0644]
cmd/date.c [new file with mode: 0644]
cmd/dcr.c [new file with mode: 0644]
cmd/demo.c [new file with mode: 0644]
cmd/dfu.c [new file with mode: 0644]
cmd/diag.c [new file with mode: 0644]
cmd/disk.c [new file with mode: 0644]
cmd/display.c [new file with mode: 0644]
cmd/dtt.c [new file with mode: 0644]
cmd/echo.c [new file with mode: 0644]
cmd/eeprom.c [new file with mode: 0644]
cmd/efi.c [new file with mode: 0644]
cmd/elf.c [new file with mode: 0644]
cmd/ethsw.c [new file with mode: 0644]
cmd/exit.c [new file with mode: 0644]
cmd/ext2.c [new file with mode: 0644]
cmd/ext4.c [new file with mode: 0644]
cmd/fastboot.c [new file with mode: 0644]
cmd/fat.c [new file with mode: 0644]
cmd/fdc.c [new file with mode: 0644]
cmd/fdt.c [new file with mode: 0644]
cmd/fitupd.c [new file with mode: 0644]
cmd/flash.c [new file with mode: 0644]
cmd/fpga.c [new file with mode: 0644]
cmd/fpgad.c [new file with mode: 0644]
cmd/fs.c [new file with mode: 0644]
cmd/fs_uuid.c [new file with mode: 0644]
cmd/fuse.c [new file with mode: 0644]
cmd/gettime.c [new file with mode: 0644]
cmd/gpio.c [new file with mode: 0644]
cmd/gpt.c [new file with mode: 0644]
cmd/hash.c [new file with mode: 0644]
cmd/help.c [new file with mode: 0644]
cmd/host.c [new file with mode: 0644]
cmd/i2c.c [new file with mode: 0644]
cmd/ide.c [new file with mode: 0644]
cmd/immap.c [new file with mode: 0644]
cmd/ini.c [new file with mode: 0644]
cmd/io.c [new file with mode: 0644]
cmd/iotrace.c [new file with mode: 0644]
cmd/irq.c [new file with mode: 0644]
cmd/itest.c [new file with mode: 0644]
cmd/jffs2.c [new file with mode: 0644]
cmd/ldrinfo.c [new file with mode: 0644]
cmd/led.c [new file with mode: 0644]
cmd/license.c [new file with mode: 0644]
cmd/load.c [new file with mode: 0644]
cmd/log.c [new file with mode: 0644]
cmd/lzmadec.c [new file with mode: 0644]
cmd/mac.c [new file with mode: 0644]
cmd/md5sum.c [new file with mode: 0644]
cmd/mdio.c [new file with mode: 0644]
cmd/mem.c [new file with mode: 0644]
cmd/mfsl.c [new file with mode: 0644]
cmd/mii.c [new file with mode: 0644]
cmd/misc.c [new file with mode: 0644]
cmd/mmc.c [new file with mode: 0644]
cmd/mmc_spi.c [new file with mode: 0644]
cmd/mp.c [new file with mode: 0644]
cmd/mtdparts.c [new file with mode: 0644]
cmd/nand.c [new file with mode: 0644]
cmd/net.c [new file with mode: 0644]
cmd/nvedit.c [new file with mode: 0644]
cmd/onenand.c [new file with mode: 0644]
cmd/otp.c [new file with mode: 0644]
cmd/part.c [new file with mode: 0644]
cmd/pci.c [new file with mode: 0644]
cmd/pcmcia.c [new file with mode: 0644]
cmd/pmic.c [new file with mode: 0644]
cmd/portio.c [new file with mode: 0644]
cmd/pxe.c [new file with mode: 0644]
cmd/read.c [new file with mode: 0644]
cmd/reginfo.c [new file with mode: 0644]
cmd/regulator.c [new file with mode: 0644]
cmd/reiser.c [new file with mode: 0644]
cmd/remoteproc.c [new file with mode: 0644]
cmd/sata.c [new file with mode: 0644]
cmd/scsi.c [new file with mode: 0644]
cmd/setexpr.c [new file with mode: 0644]
cmd/sf.c [new file with mode: 0644]
cmd/sha1sum.c [new file with mode: 0644]
cmd/softswitch.c [new file with mode: 0644]
cmd/sound.c [new file with mode: 0644]
cmd/source.c [new file with mode: 0644]
cmd/spi.c [new file with mode: 0644]
cmd/spibootldr.c [new file with mode: 0644]
cmd/spl.c [new file with mode: 0644]
cmd/strings.c [new file with mode: 0644]
cmd/terminal.c [new file with mode: 0644]
cmd/test.c [new file with mode: 0644]
cmd/thordown.c [new file with mode: 0644]
cmd/time.c [new file with mode: 0644]
cmd/tpm.c [new file with mode: 0644]
cmd/tpm_test.c [new file with mode: 0644]
cmd/trace.c [new file with mode: 0644]
cmd/tsi148.c [new file with mode: 0644]
cmd/ubi.c [new file with mode: 0644]
cmd/ubifs.c [new file with mode: 0644]
cmd/universe.c [new file with mode: 0644]
cmd/unzip.c [new file with mode: 0644]
cmd/usb.c [new file with mode: 0644]
cmd/usb_mass_storage.c [new file with mode: 0644]
cmd/version.c [new file with mode: 0644]
cmd/ximg.c [new file with mode: 0644]
cmd/yaffs2.c [new file with mode: 0644]
cmd/zfs.c [new file with mode: 0644]
cmd/zip.c [new file with mode: 0644]
common/Kconfig
common/Makefile
common/bootm.c
common/cmd_aes.c [deleted file]
common/cmd_ambapp.c [deleted file]
common/cmd_armflash.c [deleted file]
common/cmd_bdinfo.c [deleted file]
common/cmd_bedbug.c [deleted file]
common/cmd_blob.c [deleted file]
common/cmd_bmp.c [deleted file]
common/cmd_boot.c [deleted file]
common/cmd_bootldr.c [deleted file]
common/cmd_bootm.c [deleted file]
common/cmd_bootmenu.c [deleted file]
common/cmd_bootstage.c [deleted file]
common/cmd_cache.c [deleted file]
common/cmd_cbfs.c [deleted file]
common/cmd_clk.c [deleted file]
common/cmd_console.c [deleted file]
common/cmd_cplbinfo.c [deleted file]
common/cmd_cpu.c [deleted file]
common/cmd_cramfs.c [deleted file]
common/cmd_dataflash_mmc_mux.c [deleted file]
common/cmd_date.c [deleted file]
common/cmd_dcr.c [deleted file]
common/cmd_demo.c [deleted file]
common/cmd_dfu.c [deleted file]
common/cmd_diag.c [deleted file]
common/cmd_disk.c [deleted file]
common/cmd_display.c [deleted file]
common/cmd_dtt.c [deleted file]
common/cmd_echo.c [deleted file]
common/cmd_eeprom.c [deleted file]
common/cmd_efi.c [deleted file]
common/cmd_elf.c [deleted file]
common/cmd_ethsw.c [deleted file]
common/cmd_exit.c [deleted file]
common/cmd_ext2.c [deleted file]
common/cmd_ext4.c [deleted file]
common/cmd_fastboot.c [deleted file]
common/cmd_fat.c [deleted file]
common/cmd_fdc.c [deleted file]
common/cmd_fdt.c [deleted file]
common/cmd_fitupd.c [deleted file]
common/cmd_flash.c [deleted file]
common/cmd_fpga.c [deleted file]
common/cmd_fpgad.c [deleted file]
common/cmd_fs.c [deleted file]
common/cmd_fs_uuid.c [deleted file]
common/cmd_fuse.c [deleted file]
common/cmd_gettime.c [deleted file]
common/cmd_gpio.c [deleted file]
common/cmd_gpt.c [deleted file]
common/cmd_hash.c [deleted file]
common/cmd_help.c [deleted file]
common/cmd_host.c [deleted file]
common/cmd_i2c.c [deleted file]
common/cmd_ide.c [deleted file]
common/cmd_immap.c [deleted file]
common/cmd_ini.c [deleted file]
common/cmd_io.c [deleted file]
common/cmd_iotrace.c [deleted file]
common/cmd_irq.c [deleted file]
common/cmd_itest.c [deleted file]
common/cmd_jffs2.c [deleted file]
common/cmd_ldrinfo.c [deleted file]
common/cmd_led.c [deleted file]
common/cmd_license.c [deleted file]
common/cmd_load.c [deleted file]
common/cmd_log.c [deleted file]
common/cmd_lzmadec.c [deleted file]
common/cmd_mac.c [deleted file]
common/cmd_md5sum.c [deleted file]
common/cmd_mdio.c [deleted file]
common/cmd_mem.c [deleted file]
common/cmd_mfsl.c [deleted file]
common/cmd_mii.c [deleted file]
common/cmd_misc.c [deleted file]
common/cmd_mmc.c [deleted file]
common/cmd_mmc_spi.c [deleted file]
common/cmd_mp.c [deleted file]
common/cmd_mtdparts.c [deleted file]
common/cmd_nand.c [deleted file]
common/cmd_net.c [deleted file]
common/cmd_nvedit.c [deleted file]
common/cmd_onenand.c [deleted file]
common/cmd_otp.c [deleted file]
common/cmd_part.c [deleted file]
common/cmd_pci.c [deleted file]
common/cmd_pcmcia.c [deleted file]
common/cmd_pmic.c [deleted file]
common/cmd_portio.c [deleted file]
common/cmd_pxe.c [deleted file]
common/cmd_read.c [deleted file]
common/cmd_reginfo.c [deleted file]
common/cmd_regulator.c [deleted file]
common/cmd_reiser.c [deleted file]
common/cmd_remoteproc.c [deleted file]
common/cmd_sata.c [deleted file]
common/cmd_scsi.c [deleted file]
common/cmd_setexpr.c [deleted file]
common/cmd_sf.c [deleted file]
common/cmd_sha1sum.c [deleted file]
common/cmd_softswitch.c [deleted file]
common/cmd_sound.c [deleted file]
common/cmd_source.c [deleted file]
common/cmd_spi.c [deleted file]
common/cmd_spibootldr.c [deleted file]
common/cmd_spl.c [deleted file]
common/cmd_strings.c [deleted file]
common/cmd_terminal.c [deleted file]
common/cmd_test.c [deleted file]
common/cmd_thordown.c [deleted file]
common/cmd_time.c [deleted file]
common/cmd_tpm.c [deleted file]
common/cmd_tpm_test.c [deleted file]
common/cmd_trace.c [deleted file]
common/cmd_tsi148.c [deleted file]
common/cmd_ubi.c [deleted file]
common/cmd_ubifs.c [deleted file]
common/cmd_universe.c [deleted file]
common/cmd_unzip.c [deleted file]
common/cmd_usb.c [deleted file]
common/cmd_usb_mass_storage.c [deleted file]
common/cmd_version.c [deleted file]
common/cmd_ximg.c [deleted file]
common/cmd_yaffs2.c [deleted file]
common/cmd_zfs.c [deleted file]
common/cmd_zip.c [deleted file]
common/console.c
common/env_mmc.c
common/usb_kbd.c
configs/chromebook_link_defconfig
configs/chromebox_panther_defconfig
doc/device-tree-bindings/serial/8250.txt [new file with mode: 0644]
doc/device-tree-bindings/serial/ns16550.txt [deleted file]
doc/device-tree-bindings/serial/omap_serial.txt [new file with mode: 0644]
doc/device-tree-bindings/serial/snps-dw-apb-uart.txt [new file with mode: 0644]
drivers/Makefile
drivers/bios_emulator/atibios.c
drivers/bios_emulator/bios.c
drivers/block/Kconfig
drivers/block/Makefile
drivers/block/disk-uclass.c [new file with mode: 0644]
drivers/core/lists.c
drivers/core/syscon-uclass.c
drivers/dma/apbh_dma.c
drivers/gpio/gpio-uclass.c
drivers/i2c/Kconfig
drivers/i2c/Makefile
drivers/i2c/intel_i2c.c [new file with mode: 0644]
drivers/mtd/nand/mxs_nand.c
drivers/mtd/ubi/build.c
drivers/net/eepro100.c
drivers/net/fsl-mc/mc.c
drivers/net/zynq_gem.c
drivers/pch/Makefile [new file with mode: 0644]
drivers/pch/pch-uclass.c [new file with mode: 0644]
drivers/pch/pch7.c [new file with mode: 0644]
drivers/pch/pch9.c [new file with mode: 0644]
drivers/pci/pci-uclass.c
drivers/pci/pci_auto.c
drivers/pci/pci_compat.c
drivers/pci/pci_internal.h
drivers/pci/pci_rom.c
drivers/pinctrl/uniphier/pinctrl-uniphier.h
drivers/serial/ns16550.c
drivers/serial/serial_ns16550.c
drivers/spi/ich.c
drivers/usb/dwc3/gadget.c
drivers/usb/dwc3/linux-compat.h
drivers/usb/eth/Makefile
drivers/usb/eth/r8152.c [new file with mode: 0644]
drivers/usb/eth/r8152.h [new file with mode: 0644]
drivers/usb/eth/r8152_fw.c [new file with mode: 0644]
drivers/usb/eth/usb_ether.c
drivers/usb/host/dwc2.c
drivers/usb/host/dwc2.h
drivers/usb/host/ehci-generic.c
drivers/usb/host/ehci-mx6.c
drivers/usb/host/ehci-pci.c
drivers/usb/host/ohci-lpc32xx.c
dts/Makefile
fs/ubifs/replay.c
fs/ubifs/super.c
include/bios_emul.h
include/common.h
include/configs/T4240RDB.h
include/configs/imx6_spl.h
include/configs/mx6_common.h
include/configs/mx6ul_14x14_evk.h
include/configs/mx7_common.h
include/configs/mx7dsabresd.h
include/configs/omap3_igep00x0.h
include/configs/omap3_logic.h
include/configs/qemu-x86.h
include/configs/rpi-common.h
include/dm/uclass-id.h
include/fdtdec.h
include/linux/bug.h [new file with mode: 0644]
include/part.h
include/pch.h [new file with mode: 0644]
include/pci.h
include/syscon.h
include/usb_ether.h
include/wait_bit.h [new file with mode: 0644]
lib/fdtdec.c
scripts/Kbuild.include
scripts/Makefile.spl
test/dm/syscon.c

index 35167e12015b202a910be77ed075af4dd8425b12..d1d32fac9db5314562db5ecd60ae907a5386ba79 100644 (file)
@@ -21,3 +21,7 @@
 
 # Ignore networking block comment style
 --ignore NETWORKING_BLOCK_COMMENT_STYLE
+
+# Ignore "WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet
+# addresses are __aligned(2)".
+--ignore PREFER_ETHER_ADDR_COPY
diff --git a/Kconfig b/Kconfig
index ee4e060c286fab19bb1d82f5cf56cde0b1116050..3ce5ba1b522effe11d4dfdacf877cba0472ac006 100644 (file)
--- a/Kconfig
+++ b/Kconfig
@@ -225,6 +225,8 @@ endmenu             # Boot images
 
 source "common/Kconfig"
 
+source "cmd/Kconfig"
+
 source "dts/Kconfig"
 
 source "net/Kconfig"
index c9c2cbedc641853c7886ffb023e5798362152899..06996d49a2fdffced542782658a8e6c01ec86899 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -661,6 +661,7 @@ libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
 libs-y += drivers/usb/phy/
 libs-y += drivers/usb/ulpi/
+libs-y += cmd/
 libs-y += common/
 libs-$(CONFIG_API) += api/
 libs-$(CONFIG_HAS_POST) += post/
diff --git a/README b/README
index ece479315f4cb8152fa86a5e1cd0fca6d21e4603..864c7cccc3b7a7182612680eba3316889460008b 100644 (file)
--- a/README
+++ b/README
@@ -3712,12 +3712,6 @@ Modem Support:
 - RTS/CTS Flow control enable:
                CONFIG_HWFLOW
 
-- Modem debug support:
-               CONFIG_MODEM_SUPPORT_DEBUG
-
-               Enables debugging stuff (char screen[1024], dbg())
-               for modem support. Useful only with BDI2000.
-
 - Interrupt support (PPC):
 
                There are common interrupt_init() and timer_interrupt()
index 0550225581f40f858cca4e88e7a6ad7cdcbc842e..a3e14a862b15af8267283d3ffa817172042db296 100644 (file)
@@ -40,7 +40,8 @@ ifeq ($(CONFIG_SYS_THUMB_BUILD),y)
 archprepare: checkthumb
 
 checkthumb:
-       @if test "$(call cc-version)" -lt "0404"; then \
+       @if test "$(call cc-name)" = "gcc" -a \
+                       "$(call cc-version)" -lt "0404"; then \
                echo -n '*** Your GCC does not produce working '; \
                echo 'binaries in THUMB mode.'; \
                echo '*** Your board is configured for THUMB mode.'; \
index 64514b16341088a93b6d71f636b55d96ec7d4ffc..27a3f2f4e68fc9af0b9838d91b0579a847bd5643 100644 (file)
@@ -18,6 +18,8 @@ enum pll_clocks {
        PLL_BUS,        /* System Bus PLL*/
        PLL_USBOTG,     /* OTG USB PLL */
        PLL_ENET,       /* ENET PLL */
+       PLL_AUDIO,      /* AUDIO PLL */
+       PLL_VIDEO,      /* AUDIO PLL */
 };
 
 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
@@ -204,7 +206,7 @@ int enable_spi_clk(unsigned char enable, unsigned spi_num)
 }
 static u32 decode_pll(enum pll_clocks pll, u32 infreq)
 {
-       u32 div;
+       u32 div, test_div, pll_num, pll_denom;
 
        switch (pll) {
        case PLL_SYS:
@@ -227,6 +229,44 @@ static u32 decode_pll(enum pll_clocks pll, u32 infreq)
                div &= BM_ANADIG_PLL_ENET_DIV_SELECT;
 
                return 25000000 * (div + (div >> 1) + 1);
+       case PLL_AUDIO:
+               div = __raw_readl(&imx_ccm->analog_pll_audio);
+               if (!(div & BM_ANADIG_PLL_AUDIO_ENABLE))
+                       return 0;
+               /* BM_ANADIG_PLL_AUDIO_BYPASS_CLK_SRC is ignored */
+               if (div & BM_ANADIG_PLL_AUDIO_BYPASS)
+                       return MXC_HCLK;
+               pll_num = __raw_readl(&imx_ccm->analog_pll_audio_num);
+               pll_denom = __raw_readl(&imx_ccm->analog_pll_audio_denom);
+               test_div = (div & BM_ANADIG_PLL_AUDIO_TEST_DIV_SELECT) >>
+                       BP_ANADIG_PLL_AUDIO_TEST_DIV_SELECT;
+               div &= BM_ANADIG_PLL_AUDIO_DIV_SELECT;
+               if (test_div == 3) {
+                       debug("Error test_div\n");
+                       return 0;
+               }
+               test_div = 1 << (2 - test_div);
+
+               return infreq * (div + pll_num / pll_denom) / test_div;
+       case PLL_VIDEO:
+               div = __raw_readl(&imx_ccm->analog_pll_video);
+               if (!(div & BM_ANADIG_PLL_VIDEO_ENABLE))
+                       return 0;
+               /* BM_ANADIG_PLL_AUDIO_BYPASS_CLK_SRC is ignored */
+               if (div & BM_ANADIG_PLL_VIDEO_BYPASS)
+                       return MXC_HCLK;
+               pll_num = __raw_readl(&imx_ccm->analog_pll_video_num);
+               pll_denom = __raw_readl(&imx_ccm->analog_pll_video_denom);
+               test_div = (div & BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT) >>
+                       BP_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
+               div &= BM_ANADIG_PLL_VIDEO_DIV_SELECT;
+               if (test_div == 3) {
+                       debug("Error test_div\n");
+                       return 0;
+               }
+               test_div = 1 << (2 - test_div);
+
+               return infreq * (div + pll_num / pll_denom) / test_div;
        default:
                return 0;
        }
@@ -437,7 +477,7 @@ static u32 get_mmdc_ch0_clk(void)
        u32 cbcmr = __raw_readl(&imx_ccm->cbcmr);
        u32 cbcdr = __raw_readl(&imx_ccm->cbcdr);
 
-       u32 freq, podf, per2_clk2_podf;
+       u32 freq, podf, per2_clk2_podf, pmu_misc2_audio_div;
 
        if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL) ||
            is_cpu_type(MXC_CPU_MX6SL)) {
@@ -472,8 +512,21 @@ static u32 get_mmdc_ch0_clk(void)
                                freq = mxc_get_pll_pfd(PLL_BUS, 0);
                                break;
                        case 3:
-                               /* static / 2 divider */
-                               freq =  mxc_get_pll_pfd(PLL_BUS, 2) / 2;
+                               pmu_misc2_audio_div = PMU_MISC2_AUDIO_DIV(__raw_readl(&imx_ccm->pmu_misc2));
+                               switch (pmu_misc2_audio_div) {
+                               case 0:
+                               case 2:
+                                       pmu_misc2_audio_div = 1;
+                                       break;
+                               case 1:
+                                       pmu_misc2_audio_div = 2;
+                                       break;
+                               case 3:
+                                       pmu_misc2_audio_div = 4;
+                                       break;
+                               }
+                               freq = decode_pll(PLL_AUDIO, MXC_HCLK) /
+                                       pmu_misc2_audio_div;
                                break;
                        }
                }
index c777922e9d5258f799d35586ac2e25ea3195a05f..1d8e4709713ef9a7ae7ec9e9a137f97d07314fd8 100644 (file)
@@ -130,6 +130,24 @@ static void init_csu(void)
                writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
 }
 
+static void imx_enet_mdio_fixup(void)
+{
+       struct iomuxc_gpr_base_regs *gpr_regs =
+               (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
+
+       /*
+        * The management data input/output (MDIO) requires open-drain,
+        * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
+        * this feature. So to TO1.1, need to enable open drain by setting
+        * bits GPR0[8:7].
+        */
+
+       if (soc_rev() >= CHIP_REV_1_1) {
+               setbits_le32(&gpr_regs->gpr[0],
+                            IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
+       }
+}
+
 int arch_cpu_init(void)
 {
        init_aips();
@@ -138,6 +156,8 @@ int arch_cpu_init(void)
        /* Disable PDE bit of WMCR register */
        imx_set_wdog_powerdown(false);
 
+       imx_enet_mdio_fixup();
+
 #ifdef CONFIG_APBH_DMA
        /* Start APBH DMA */
        mxs_dma_init();
index 13e0a3d9074022481e30d1f2665bbbeb4a08f948..22212c2202ea399edbdffdc12e7c3b409ba5403c 100644 (file)
@@ -103,6 +103,97 @@ struct mxc_ccm_reg {
        u32 analog_pfd_528_set;
        u32 analog_pfd_528_clr;
        u32 analog_pfd_528_tog;
+       /* PMU Memory Map/Register Definition */
+       u32 pmu_reg_1p1;
+       u32 pmu_reg_1p1_set;
+       u32 pmu_reg_1p1_clr;
+       u32 pmu_reg_1p1_tog;
+       u32 pmu_reg_3p0;
+       u32 pmu_reg_3p0_set;
+       u32 pmu_reg_3p0_clr;
+       u32 pmu_reg_3p0_tog;
+       u32 pmu_reg_2p5;
+       u32 pmu_reg_2p5_set;
+       u32 pmu_reg_2p5_clr;
+       u32 pmu_reg_2p5_tog;
+       u32 pmu_reg_core;
+       u32 pmu_reg_core_set;
+       u32 pmu_reg_core_clr;
+       u32 pmu_reg_core_tog;
+       u32 pmu_misc0;
+       u32 pmu_misc0_set;
+       u32 pmu_misc0_clr;
+       u32 pmu_misc0_tog;
+       u32 pmu_misc1;
+       u32 pmu_misc1_set;
+       u32 pmu_misc1_clr;
+       u32 pmu_misc1_tog;
+       u32 pmu_misc2;
+       u32 pmu_misc2_set;
+       u32 pmu_misc2_clr;
+       u32 pmu_misc2_tog;
+       /* TEMPMON Memory Map/Register Definition */
+       u32 tempsense0;
+       u32 tempsense0_set;
+       u32 tempsense0_clr;
+       u32 tempsense0_tog;
+       u32 tempsense1;
+       u32 tempsense1_set;
+       u32 tempsense1_clr;
+       u32 tempsense1_tog;
+       /* USB Analog Memory Map/Register Definition */
+       u32 usb1_vbus_detect;
+       u32 usb1_vbus_detect_set;
+       u32 usb1_vbus_detect_clr;
+       u32 usb1_vbus_detect_tog;
+       u32 usb1_chrg_detect;
+       u32 usb1_chrg_detect_set;
+       u32 usb1_chrg_detect_clr;
+       u32 usb1_chrg_detect_tog;
+       u32 usb1_vbus_det_stat;
+       u32 usb1_vbus_det_stat_set;
+       u32 usb1_vbus_det_stat_clr;
+       u32 usb1_vbus_det_stat_tog;
+       u32 usb1_chrg_det_stat;
+       u32 usb1_chrg_det_stat_set;
+       u32 usb1_chrg_det_stat_clr;
+       u32 usb1_chrg_det_stat_tog;
+       u32 usb1_loopback;
+       u32 usb1_loopback_set;
+       u32 usb1_loopback_clr;
+       u32 usb1_loopback_tog;
+       u32 usb1_misc;
+       u32 usb1_misc_set;
+       u32 usb1_misc_clr;
+       u32 usb1_misc_tog;
+       u32 usb2_vbus_detect;
+       u32 usb2_vbus_detect_set;
+       u32 usb2_vbus_detect_clr;
+       u32 usb2_vbus_detect_tog;
+       u32 usb2_chrg_detect;
+       u32 usb2_chrg_detect_set;
+       u32 usb2_chrg_detect_clr;
+       u32 usb2_chrg_detect_tog;
+       u32 usb2_vbus_det_stat;
+       u32 usb2_vbus_det_stat_set;
+       u32 usb2_vbus_det_stat_clr;
+       u32 usb2_vbus_det_stat_tog;
+       u32 usb2_chrg_det_stat;
+       u32 usb2_chrg_det_stat_set;
+       u32 usb2_chrg_det_stat_clr;
+       u32 usb2_chrg_det_stat_tog;
+       u32 usb2_loopback;
+       u32 usb2_loopback_set;
+       u32 usb2_loopback_clr;
+       u32 usb2_loopback_tog;
+       u32 usb2_misc;
+       u32 usb2_misc_set;
+       u32 usb2_misc_clr;
+       u32 usb2_misc_tog;
+       u32 digprog;
+       u32 reserved1[7];
+       /* For i.MX 6SoloLite */
+       u32 digprog_sololite;
 };
 #endif
 
@@ -1136,4 +1227,16 @@ struct mxc_ccm_reg {
 
 #define BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF 0x00000008
 
+#define BM_PMU_MISC2_AUDIO_DIV_MSB (1 << 23)
+#define BP_PMU_MISC2_AUDIO_DIV_MSB 23
+
+#define BM_PMU_MISC2_AUDIO_DIV_LSB (1 << 15)
+#define BP_PMU_MISC2_AUDIO_DIV_LSB 15
+
+#define PMU_MISC2_AUDIO_DIV(v) \
+       (((v & BM_PMU_MISC2_AUDIO_DIV_MSB) >> \
+       (BP_PMU_MISC2_AUDIO_DIV_MSB - 1)) | \
+       ((v & BM_PMU_MISC2_AUDIO_DIV_LSB) >> \
+        BP_PMU_MISC2_AUDIO_DIV_LSB))
+
 #endif /*__ARCH_ARM_MACH_MX6_CCM_REGS_H__ */
index e28a807ec2f7a3ca78cca5d066d8d1c84061eafb..58a25c7b16263dc9975b01f47901290a4d22594c 100644 (file)
@@ -272,6 +272,8 @@ struct src {
 #define IOMUXC_GPR_GPR0_DMAREQ_MUX_SEL5_SHIFT    5
 #define IOMUXC_GPR_GPR0_DMAREQ_MUX_SEL6_MASK     0x40u
 #define IOMUXC_GPR_GPR0_DMAREQ_MUX_SEL6_SHIFT    6
+#define IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK (3 << 7)
+#define IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_SHIFT 7
 /* GPR1 Bit Fields */
 #define IOMUXC_GPR_GPR1_GPR_WEIM_ACT_CS0_MASK    0x1u
 #define IOMUXC_GPR_GPR1_GPR_WEIM_ACT_CS0_SHIFT   0
index 7d421b3967cfb8295abfa4cb84d8f0d048879a5f..1aec4f9d5a2a8db0ffc9a25a61957dd7e733c720 100644 (file)
@@ -59,7 +59,7 @@ enum {
        MXS_DMA_CHANNEL_AHB_APBH_RESERVED1,
        MXS_MAX_DMA_CHANNELS,
 };
-#elif defined(CONFIG_MX6)
+#elif defined(CONFIG_MX6) || defined(CONFIG_MX7)
 enum {
        MXS_DMA_CHANNEL_AHB_APBH_GPMI0 = 0,
        MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
index ca7743600420048b5f404130dd35fcafe52f1fbe..391452cc1241ac96e90a907fa5fd867c8ae59a8d 100644 (file)
@@ -96,7 +96,7 @@ struct mxs_apbh_regs {
        mxs_reg_32(hw_apbh_version)
 };
 
-#elif (defined(CONFIG_MX28) || defined(CONFIG_MX6))
+#elif (defined(CONFIG_MX28) || defined(CONFIG_MX6) || defined(CONFIG_MX7))
 struct mxs_apbh_regs {
        mxs_reg_32(hw_apbh_ctrl0)
        mxs_reg_32(hw_apbh_ctrl1)
@@ -275,7 +275,7 @@ struct mxs_apbh_regs {
 #define        APBH_CTRL0_CLKGATE_CHANNEL_NAND7                0x0800
 #define        APBH_CTRL0_CLKGATE_CHANNEL_HSADC                0x1000
 #define        APBH_CTRL0_CLKGATE_CHANNEL_LCDIF                0x2000
-#elif defined(CONFIG_MX6)
+#elif (defined(CONFIG_MX6) || defined(CONFIG_MX7))
 #define        APBH_CTRL0_CLKGATE_CHANNEL_OFFSET               0
 #define        APBH_CTRL0_CLKGATE_CHANNEL_NAND0                0x0001
 #define        APBH_CTRL0_CLKGATE_CHANNEL_NAND1                0x0002
@@ -391,7 +391,7 @@ struct mxs_apbh_regs {
 #define        APBH_CHANNEL_CTRL_FREEZE_CHANNEL_LCDIF          0x2000
 #endif
 
-#if defined(CONFIG_MX6)
+#if (defined(CONFIG_MX6) || defined(CONFIG_MX7))
 #define        APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET          16
 #endif
 
index 5c477835fc5a4de7432a0cecb0033a5bcdd58fae..adfbace05deb496ef91df145973c8bd8b961ec4f 100644 (file)
@@ -123,7 +123,7 @@ struct mxs_bch_regs {
 #define        BCH_FLASHLAYOUT0_NBLOCKS_OFFSET                 24
 #define        BCH_FLASHLAYOUT0_META_SIZE_MASK                 (0xff << 16)
 #define        BCH_FLASHLAYOUT0_META_SIZE_OFFSET               16
-#if defined(CONFIG_MX6)
+#if (defined(CONFIG_MX6) || defined(CONFIG_MX7))
 #define        BCH_FLASHLAYOUT0_ECC0_MASK                      (0x1f << 11)
 #define        BCH_FLASHLAYOUT0_ECC0_OFFSET                    11
 #else
@@ -154,7 +154,7 @@ struct mxs_bch_regs {
 
 #define        BCH_FLASHLAYOUT1_PAGE_SIZE_MASK                 (0xffff << 16)
 #define        BCH_FLASHLAYOUT1_PAGE_SIZE_OFFSET               16
-#if defined(CONFIG_MX6)
+#if (defined(CONFIG_MX6) || defined(CONFIG_MX7))
 #define        BCH_FLASHLAYOUT1_ECCN_MASK                      (0x1f << 11)
 #define        BCH_FLASHLAYOUT1_ECCN_OFFSET                    11
 #else
index b4229f4575e83b373385e465c09a08892a13ab9f..a4fa00c9adaefeea838dec87a5d3325cf6fea7cd 100644 (file)
@@ -8,6 +8,7 @@
 /* Tegra AP (Application Processor) code */
 
 #include <common.h>
+#include <linux/bug.h>
 #include <asm/io.h>
 #include <asm/arch/gp_padctrl.h>
 #include <asm/arch/mc.h>
index b8ac5a5ac5417b68c481c5019438587e907ca6f2..f71e34231bc79c642471a556ae86e5af42234b10 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef _ASM_IO_H
 #define _ASM_IO_H
 
+#include <linux/bug.h>
 #include <linux/compiler.h>
 #include <linux/types.h>
 
index c26cc8f5031e4edad4b365d4a45505ff78d885cc..b7fbd2f125305f21802a68f8a32be312fb33a7fe 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <common.h>
+#include <console.h>
 #include <stdio_dev.h>
 #include <watchdog.h>
 #include <malloc.h>
index 6b44a3709a4afd58c7d765784a46eb816a9f718d..b0ed374563adb66f107fb127b0af328102b12109 100644 (file)
@@ -41,7 +41,8 @@ archprepare: checkgcc4
 # that U-Boot wants.
 # See http://lists.denx.de/pipermail/u-boot/2012-September/135156.html
 checkgcc4:
-       @if test $(call cc-version) -lt 0400; then \
+       @if test "$(call cc-name)" = "gcc" -a \
+                       $(call cc-version) -lt 0400; then \
                echo -n '*** Your GCC is too old, please upgrade to GCC 4.x or newer'; \
                false; \
        fi
index 4105a28509143d48f402ee7c2b43eb089b473c50..ac77ddcf4da0a939ac1ee306e14dad52552ec871 100644 (file)
@@ -203,18 +203,6 @@ void serial_putc_dev(unsigned int idx, const char c)
        out_8(&psc->tfdata_8, c);
 }
 
-void serial_putc_raw_dev(unsigned int idx, const char c)
-{
-       volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
-       volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx];
-
-       /* Wait for last character to go. */
-       while (!(in_be16(&psc->psc_status) & PSC_SR_TXEMP))
-               ;
-
-       out_8(&psc->tfdata_8, c);
-}
-
 void serial_puts_dev(unsigned int idx, const char *s)
 {
        while (*s)
index cb5b0bfe9b0d3eeb18e69ad3ae7627b145ddfe12..bccdcf7973af7b601c8c0c00a7f643dbd2f0f8d6 100644 (file)
@@ -112,17 +112,6 @@ void serial_putc_dev (unsigned long dev_base, const char c)
        psc->psc_buffer_8 = c;
 }
 
-void serial_putc_raw_dev(unsigned long dev_base, const char c)
-{
-       volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
-       /* Wait for last character to go. */
-       while (!(psc->psc_status & PSC_SR_TXEMP))
-               ;
-
-       psc->psc_buffer_8 = c;
-}
-
-
 void serial_puts_dev (unsigned long dev_base, const char *s)
 {
        while (*s) {
index 997aea488ff5836077e5f5245ec7a92b942432db..5659ab8d9201832bcc6c168dd6d27a3a9972d439 100644 (file)
@@ -19,7 +19,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (start == 0)
                start_align = 1ull << (LAW_SIZE_2G + 1);
        else
-               start_align = 1ull << (__ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
        law_sz = min(start_align, sz);
        law_sz_enc = __ilog2_u64(law_sz) - 1;
 
@@ -39,7 +39,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (sz) {
                start += law_sz;
 
-               start_align = 1ull << (__ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
                law_sz = min(start_align, sz);
                law_sz_enc = __ilog2_u64(law_sz) - 1;
                ecm = &immap->sysconf.ddrlaw[1];
index 13a7d0f664d2a19899c89c57f4fd44df3d24a341..8c6b678c899e97c8bbc898ece004f4619e599baa 100644 (file)
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
 #include <asm/fsl_srio.h>
+#ifdef CONFIG_FSL_CORENET
+#include <asm/fsl_portals.h>
+#include <asm/fsl_liodn.h>
+#endif
 #include <fsl_usb.h>
 #include <hwconfig.h>
 #include <linux/compiler.h>
@@ -788,6 +792,13 @@ int cpu_init_r(void)
                spin_table_compat = 1;
 #endif
 
+#ifdef CONFIG_FSL_CORENET
+       set_liodns();
+#ifdef CONFIG_SYS_DPAA_QBMAN
+       setup_portals();
+#endif
+#endif
+
        l2cache_init();
 #if defined(CONFIG_RAMBOOT_PBL)
        disable_cpc_sram();
index 24baad442e4967d2b97cb690b96616f035c49c22..bd79297f0f7a562c28a83b7aeb8036f1f130c29a 100644 (file)
@@ -188,7 +188,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (start == 0)
                start_align = 1ull << (LAW_SIZE_32G + 1);
        else
-               start_align = 1ull << (__ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
        law_sz = min(start_align, sz);
        law_sz_enc = __ilog2_u64(law_sz) - 1;
 
@@ -203,7 +203,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (sz) {
                start += law_sz;
 
-               start_align = 1ull << (__ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
                law_sz = min(start_align, sz);
                law_sz_enc = __ilog2_u64(law_sz) - 1;
 
index 7299f2cddc944de8edb25b3f7a40e62a4453a646..25382f9aab1efdb8e944b2094786fc64c8f0b570 100644 (file)
@@ -50,7 +50,7 @@ int arch_misc_init(void)
        mrccache_save();
 #endif
 
-       return pirq_init();
+       return 0;
 }
 
 int reserve_arch(void)
index 41e29a6086fdfb661ea521002c24f68426b119a2..7f5087a918386ab847cc2c25902bf78635116c9d 100644 (file)
@@ -14,7 +14,8 @@
 #include <pci.h>
 
 static const struct udevice_id generic_pch_ids[] = {
-       { .compatible = "intel,pch" },
+       { .compatible = "intel,pch7" },
+       { .compatible = "intel,pch9" },
        { }
 };
 
index 381d83526fbf63612f0fa8d27197a8e8af2fed6a..6c3a748f75388538fb61ca548718ddde25ae0c9e 100644 (file)
@@ -688,7 +688,7 @@ static int x86_mp_init(void)
 }
 #endif
 
-__weak int x86_init_cpus(void)
+static int x86_init_cpus(void)
 {
 #ifdef CONFIG_SMP
        debug("Init additional CPUs\n");
@@ -709,8 +709,24 @@ __weak int x86_init_cpus(void)
 
 int cpu_init_r(void)
 {
-       if (ll_boot_init())
-               return x86_init_cpus();
+       struct udevice *dev;
+       int ret;
+
+       if (!ll_boot_init())
+               return 0;
+
+       ret = x86_init_cpus();
+       if (ret)
+               return ret;
+
+       /*
+        * Set up the northbridge, PCH and LPC if available. Note that these
+        * may have had some limited pre-relocation init if they were probed
+        * before relocation, but this is post relocation.
+        */
+       uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
+       uclass_first_device(UCLASS_PCH, &dev);
+       uclass_first_device(UCLASS_LPC, &dev);
 
        return 0;
 }
index b00ddc0cb488163e5e14c1a6127ddbbb1dc8a04f..c40200bf8587e86113888c98b40a23e23b17bb33 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <asm/cache.h>
 #include <asm/control_regs.h>
 #include <asm/interrupt.h>
@@ -244,6 +245,14 @@ int disable_interrupts(void)
 
 int interrupt_init(void)
 {
+       struct udevice *dev;
+       int ret;
+
+       /* Try to set up the interrupt router, but don't require one */
+       ret = uclass_first_device(UCLASS_IRQ, &dev);
+       if (ret && ret != -ENODEV)
+               return ret;
+
        /*
         * When running as an EFI application we are not in control of
         * interrupts and should leave them alone.
index 35b29f69d8459cceb0fbbc5c0f3dd4e12b992564..0b36ace0915565ab5795655408bca91c88d7ff2a 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <malloc.h>
@@ -82,12 +83,7 @@ static inline void fill_irq_info(struct irq_info *slot, int bus, int device,
        slot->irq[pin - 1].bitmap = irq_router.irq_mask;
 }
 
-__weak void cpu_irq_init(void)
-{
-       return;
-}
-
-static int create_pirq_routing_table(void)
+static int create_pirq_routing_table(struct udevice *dev)
 {
        const void *blob = gd->fdt_blob;
        struct fdt_pci_addr addr;
@@ -97,16 +93,13 @@ static int create_pirq_routing_table(void)
        struct irq_routing_table *rt;
        struct irq_info *slot, *slot_base;
        int irq_entries = 0;
+       int parent;
        int i;
        int ret;
 
-       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_IRQ_ROUTER);
-       if (node < 0) {
-               debug("%s: Cannot find irq router node\n", __func__);
-               return -EINVAL;
-       }
-
-       ret = fdtdec_get_pci_addr(blob, node, FDT_PCI_SPACE_CONFIG,
+       node = dev->of_offset;
+       parent = dev->parent->of_offset;
+       ret = fdtdec_get_pci_addr(blob, parent, FDT_PCI_SPACE_CONFIG,
                                  "reg", &addr);
        if (ret)
                return ret;
@@ -225,13 +218,11 @@ static int create_pirq_routing_table(void)
        return 0;
 }
 
-int pirq_init(void)
+int irq_router_common_init(struct udevice *dev)
 {
        int ret;
 
-       cpu_irq_init();
-
-       ret = create_pirq_routing_table();
+       ret = create_pirq_routing_table(dev);
        if (ret) {
                debug("Failed to create pirq routing table\n");
                return ret;
@@ -243,6 +234,11 @@ int pirq_init(void)
        return 0;
 }
 
+int irq_router_probe(struct udevice *dev)
+{
+       return irq_router_common_init(dev);
+}
+
 u32 write_pirq_routing_table(u32 addr)
 {
        if (!pirq_routing_table)
@@ -250,3 +246,20 @@ u32 write_pirq_routing_table(u32 addr)
 
        return copy_pirq_routing_table(addr, pirq_routing_table);
 }
+
+static const struct udevice_id irq_router_ids[] = {
+       { .compatible = "intel,irq-router" },
+       { }
+};
+
+U_BOOT_DRIVER(irq_router_drv) = {
+       .name           = "intel_irq",
+       .id             = UCLASS_IRQ,
+       .of_match       = irq_router_ids,
+       .probe          = irq_router_probe,
+};
+
+UCLASS_DRIVER(irq) = {
+       .id             = UCLASS_IRQ,
+       .name           = "irq",
+};
index 0c7efaec7ceed9c9d43aeb40b4cb5c2470d5d646..45ef14187ea73cd30bfd6f856ca8fa565ec7c2b0 100644 (file)
@@ -7,7 +7,6 @@
 obj-y += bd82x6x.o
 obj-y += car.o
 obj-y += cpu.o
-obj-y += early_init.o
 obj-y += early_me.o
 obj-y += gma.o
 obj-y += lpc.o
@@ -15,10 +14,6 @@ obj-y += me_status.o
 obj-y += model_206ax.o
 obj-y += microcode_intel.o
 obj-y += northbridge.o
-obj-y += pch.o
-obj-y += pci.o
 obj-y += report_platform.o
 obj-y += sata.o
 obj-y += sdram.o
-obj-y += usb_ehci.o
-obj-y += usb_xhci.o
index 434dfd649f65853b3977e10f7c400a2346d6b150..2b172d49bade73704529abfbadd64beb28a932a7 100644 (file)
@@ -3,12 +3,15 @@
  *
  * SPDX-License-Identifier:    GPL-2.0+
  */
-
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <malloc.h>
+#include <pch.h>
+#include <syscon.h>
+#include <asm/cpu.h>
+#include <asm/io.h>
 #include <asm/lapic.h>
 #include <asm/pci.h>
 #include <asm/arch/bd82x6x.h>
 #include <asm/arch/pch.h>
 #include <asm/arch/sandybridge.h>
 
-void bd82x6x_pci_init(pci_dev_t dev)
+#define BIOS_CTRL      0xdc
+
+static int pch_revision_id = -1;
+static int pch_type = -1;
+
+/**
+ * pch_silicon_revision() - Read silicon revision ID from the PCH
+ *
+ * @dev:       PCH device
+ * @return silicon revision ID
+ */
+static int pch_silicon_revision(struct udevice *dev)
 {
-       u16 reg16;
-       u8 reg8;
-
-       debug("bd82x6x PCI init.\n");
-       /* Enable Bus Master */
-       reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
-       reg16 |= PCI_COMMAND_MASTER;
-       x86_pci_write_config16(dev, PCI_COMMAND, reg16);
-
-       /* This device has no interrupt */
-       x86_pci_write_config8(dev, INTR, 0xff);
-
-       /* disable parity error response and SERR */
-       reg16 = x86_pci_read_config16(dev, BCTRL);
-       reg16 &= ~(1 << 0);
-       reg16 &= ~(1 << 1);
-       x86_pci_write_config16(dev, BCTRL, reg16);
-
-       /* Master Latency Count must be set to 0x04! */
-       reg8 = x86_pci_read_config8(dev, SMLT);
-       reg8 &= 0x07;
-       reg8 |= (0x04 << 3);
-       x86_pci_write_config8(dev, SMLT, reg8);
-
-       /* Will this improve throughput of bus masters? */
-       x86_pci_write_config8(dev, PCI_MIN_GNT, 0x06);
-
-       /* Clear errors in status registers */
-       reg16 = x86_pci_read_config16(dev, PSTS);
-       /* reg16 |= 0xf900; */
-       x86_pci_write_config16(dev, PSTS, reg16);
-
-       reg16 = x86_pci_read_config16(dev, SECSTS);
-       /* reg16 |= 0xf900; */
-       x86_pci_write_config16(dev, SECSTS, reg16);
+       u8 val;
+
+       if (pch_revision_id < 0) {
+               dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
+               pch_revision_id = val;
+       }
+
+       return pch_revision_id;
 }
 
-static int bd82x6x_probe(struct udevice *dev)
+int pch_silicon_type(struct udevice *dev)
 {
-       const void *blob = gd->fdt_blob;
-       struct pci_controller *hose;
-       struct x86_cpu_priv *cpu;
-       int sata_node, gma_node;
-       int ret;
+       u8 val;
 
-       hose = pci_bus_to_hose(0);
-       lpc_enable(PCH_LPC_DEV);
-       lpc_init(hose, PCH_LPC_DEV);
-       sata_node = fdtdec_next_compatible(blob, 0,
-                                          COMPAT_INTEL_PANTHERPOINT_AHCI);
-       if (sata_node < 0) {
-               debug("%s: Cannot find SATA node\n", __func__);
-               return -EINVAL;
+       if (pch_type < 0) {
+               dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
+               pch_type = val;
        }
-       bd82x6x_sata_init(PCH_SATA_DEV, blob, sata_node);
-       bd82x6x_usb_ehci_init(PCH_EHCI1_DEV);
-       bd82x6x_usb_ehci_init(PCH_EHCI2_DEV);
-
-       cpu = calloc(1, sizeof(*cpu));
-       if (!cpu)
-               return -ENOMEM;
-       model_206ax_init(cpu);
-
-       gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA);
-       if (gma_node < 0) {
-               debug("%s: Cannot find GMA node\n", __func__);
-               return -EINVAL;
+
+       return pch_type;
+}
+
+/**
+ * pch_silicon_supported() - Check if a certain revision is supported
+ *
+ * @dev:       PCH device
+ * @type:      PCH type
+ * @rev:       Minimum required resion
+ * @return 0 if not supported, 1 if supported
+ */
+static int pch_silicon_supported(struct udevice *dev, int type, int rev)
+{
+       int cur_type = pch_silicon_type(dev);
+       int cur_rev = pch_silicon_revision(dev);
+
+       switch (type) {
+       case PCH_TYPE_CPT:
+               /* CougarPoint minimum revision */
+               if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
+                       return 1;
+               /* PantherPoint any revision */
+               if (cur_type == PCH_TYPE_PPT)
+                       return 1;
+               break;
+
+       case PCH_TYPE_PPT:
+               /* PantherPoint minimum revision */
+               if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
+                       return 1;
+               break;
+       }
+
+       return 0;
+}
+
+#define IOBP_RETRY 1000
+static inline int iobp_poll(void)
+{
+       unsigned try = IOBP_RETRY;
+       u32 data;
+
+       while (try--) {
+               data = readl(RCB_REG(IOBPS));
+               if ((data & 1) == 0)
+                       return 1;
+               udelay(10);
        }
-       ret = dm_pci_bus_find_bdf(PCH_VIDEO_DEV, &dev);
+
+       printf("IOBP timeout\n");
+       return 0;
+}
+
+void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
+                    u32 orvalue)
+{
+       u32 data;
+
+       /* Set the address */
+       writel(address, RCB_REG(IOBPIRI));
+
+       /* READ OPCODE */
+       if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
+               writel(IOBPS_RW_BX, RCB_REG(IOBPS));
+       else
+               writel(IOBPS_READ_AX, RCB_REG(IOBPS));
+       if (!iobp_poll())
+               return;
+
+       /* Read IOBP data */
+       data = readl(RCB_REG(IOBPD));
+       if (!iobp_poll())
+               return;
+
+       /* Check for successful transaction */
+       if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
+               printf("IOBP read 0x%08x failed\n", address);
+               return;
+       }
+
+       /* Update the data */
+       data &= andvalue;
+       data |= orvalue;
+
+       /* WRITE OPCODE */
+       if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
+               writel(IOBPS_RW_BX, RCB_REG(IOBPS));
+       else
+               writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
+       if (!iobp_poll())
+               return;
+
+       /* Write IOBP data */
+       writel(data, RCB_REG(IOBPD));
+       if (!iobp_poll())
+               return;
+}
+
+static int bd82x6x_probe(struct udevice *dev)
+{
+       struct udevice *gma_dev;
+       int ret;
+
+       if (!(gd->flags & GD_FLG_RELOC))
+               return 0;
+
+       /* Cause the SATA device to do its init */
+       uclass_first_device(UCLASS_DISK, &dev);
+
+       ret = syscon_get_by_driver_data(X86_SYSCON_GMA, &gma_dev);
        if (ret)
                return ret;
-       ret = gma_func0_init(dev, blob, gma_node);
+       ret = gma_func0_init(gma_dev);
        if (ret)
                return ret;
 
        return 0;
 }
 
-int bd82x6x_init(void)
+static int bd82x6x_pch_get_sbase(struct udevice *dev, ulong *sbasep)
 {
-       const void *blob = gd->fdt_blob;
-       int sata_node;
-
-       sata_node = fdtdec_next_compatible(blob, 0,
-                                          COMPAT_INTEL_PANTHERPOINT_AHCI);
-       if (sata_node < 0) {
-               debug("%s: Cannot find SATA node\n", __func__);
-               return -EINVAL;
-       }
+       u32 rcba;
+
+       dm_pci_read_config32(dev, PCH_RCBA, &rcba);
+       /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
+       rcba = rcba & 0xffffc000;
+       *sbasep = rcba + 0x3800;
+
+       return 0;
+}
+
+static enum pch_version bd82x6x_pch_get_version(struct udevice *dev)
+{
+       return PCHV_9;
+}
 
-       bd82x6x_pci_init(PCH_DEV);
-       bd82x6x_sata_enable(PCH_SATA_DEV, blob, sata_node);
-       northbridge_enable(PCH_DEV);
-       northbridge_init(PCH_DEV);
+static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
+{
+       uint8_t bios_cntl;
+
+       /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */
+       dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl);
+       if (protect) {
+               bios_cntl &= ~BIOS_CTRL_BIOSWE;
+               bios_cntl |= BIT(5);
+       } else {
+               bios_cntl |= BIOS_CTRL_BIOSWE;
+               bios_cntl &= ~BIT(5);
+       }
+       dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl);
 
        return 0;
 }
 
+static const struct pch_ops bd82x6x_pch_ops = {
+       .get_sbase      = bd82x6x_pch_get_sbase,
+       .get_version    = bd82x6x_pch_get_version,
+       .set_spi_protect = bd82x6x_set_spi_protect,
+};
+
 static const struct udevice_id bd82x6x_ids[] = {
        { .compatible = "intel,bd82x6x" },
        { }
@@ -126,4 +221,5 @@ U_BOOT_DRIVER(bd82x6x_drv) = {
        .id             = UCLASS_PCH,
        .of_match       = bd82x6x_ids,
        .probe          = bd82x6x_probe,
+       .ops            = &bd82x6x_pch_ops,
 };
index 343bfb4e98e264a7e5fa91f7e9f58c89427f73f3..948833c02857e6d98de58e57232b3be156aed9b2 100644 (file)
@@ -15,6 +15,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
+#include <pch.h>
 #include <asm/cpu.h>
 #include <asm/io.h>
 #include <asm/lapic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static void enable_port80_on_lpc(struct pci_controller *hose, pci_dev_t dev)
-{
-       /* Enable port 80 POST on LPC */
-       pci_hose_write_config_dword(hose, dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
-       clrbits_le32(RCB_REG(GCS), 4);
-}
-
-/*
- * Enable Prefetching and Caching.
- */
-static void enable_spi_prefetch(struct pci_controller *hose, pci_dev_t dev)
-{
-       u8 reg8;
-
-       pci_hose_read_config_byte(hose, dev, 0xdc, &reg8);
-       reg8 &= ~(3 << 2);
-       reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
-       pci_hose_write_config_byte(hose, dev, 0xdc, reg8);
-}
-
 static int set_flex_ratio_to_tdp_nominal(void)
 {
        msr_t flex_ratio, msr;
@@ -99,22 +80,6 @@ static int set_flex_ratio_to_tdp_nominal(void)
        return -EINVAL;
 }
 
-static void set_spi_speed(void)
-{
-       u32 fdod;
-
-       /* Observe SPI Descriptor Component Section 0 */
-       writel(0x1000, RCB_REG(SPI_DESC_COMP0));
-
-       /* Extract the1 Write/Erase SPI Frequency from descriptor */
-       fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
-       fdod >>= 24;
-       fdod &= 7;
-
-       /* Set Software Sequence frequency to match */
-       clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
-}
-
 int arch_cpu_init(void)
 {
        post_code(POST_CPU_INIT);
@@ -124,10 +89,8 @@ int arch_cpu_init(void)
 
 int arch_cpu_init_dm(void)
 {
-       const void *blob = gd->fdt_blob;
        struct pci_controller *hose;
-       struct udevice *bus;
-       int node;
+       struct udevice *bus, *dev;
        int ret;
 
        post_code(0x70);
@@ -141,19 +104,9 @@ int arch_cpu_init_dm(void)
        /* TODO(sjg@chromium.org): Get rid of gd->hose */
        gd->hose = hose;
 
-       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
-       if (node < 0)
-               return -ENOENT;
-       ret = lpc_early_init(gd->fdt_blob, node, PCH_LPC_DEV);
-       if (ret)
-               return ret;
-
-       enable_spi_prefetch(hose, PCH_LPC_DEV);
-
-       /* This is already done in start.S, but let's do it in C */
-       enable_port80_on_lpc(hose, PCH_LPC_DEV);
-
-       set_spi_speed();
+       ret = uclass_first_device(UCLASS_LPC, &dev);
+       if (!dev)
+               return -ENODEV;
 
        /*
         * We should do as little as possible before the serial console is
@@ -167,41 +120,6 @@ int arch_cpu_init_dm(void)
        return 0;
 }
 
-static int enable_smbus(void)
-{
-       pci_dev_t dev;
-       uint16_t value;
-
-       /* Set the SMBus device statically. */
-       dev = PCI_BDF(0x0, 0x1f, 0x3);
-
-       /* Check to make sure we've got the right device. */
-       value = x86_pci_read_config16(dev, 0x0);
-       if (value != 0x8086) {
-               printf("SMBus controller not found\n");
-               return -ENOSYS;
-       }
-
-       /* Set SMBus I/O base. */
-       x86_pci_write_config32(dev, SMB_BASE,
-                              SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
-
-       /* Set SMBus enable. */
-       x86_pci_write_config8(dev, HOSTC, HST_EN);
-
-       /* Set SMBus I/O space enable. */
-       x86_pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
-
-       /* Disable interrupt generation. */
-       outb(0, SMBUS_IO_BASE + SMBHSTCTL);
-
-       /* Clear any lingering errors, so transactions can run. */
-       outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
-       debug("SMBus controller enabled\n");
-
-       return 0;
-}
-
 #define PCH_EHCI0_TEMP_BAR0 0xe8000000
 #define PCH_EHCI1_TEMP_BAR0 0xe8000400
 #define PCH_XHCI_TEMP_BAR0  0xe8001000
@@ -215,33 +133,33 @@ static int enable_smbus(void)
  *
  * This is used to speed up the resume path.
  */
-static void enable_usb_bar(void)
+static void enable_usb_bar(struct udevice *bus)
 {
        pci_dev_t usb0 = PCH_EHCI1_DEV;
        pci_dev_t usb1 = PCH_EHCI2_DEV;
        pci_dev_t usb3 = PCH_XHCI_DEV;
-       u32 cmd;
+       ulong cmd;
 
        /* USB Controller 1 */
-       x86_pci_write_config32(usb0, PCI_BASE_ADDRESS_0,
-                              PCH_EHCI0_TEMP_BAR0);
-       cmd = x86_pci_read_config32(usb0, PCI_COMMAND);
+       pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
+                            PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
+       pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
        cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
-       x86_pci_write_config32(usb0, PCI_COMMAND, cmd);
+       pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
 
-       /* USB Controller 1 */
-       x86_pci_write_config32(usb1, PCI_BASE_ADDRESS_0,
-                              PCH_EHCI1_TEMP_BAR0);
-       cmd = x86_pci_read_config32(usb1, PCI_COMMAND);
+       /* USB Controller 2 */
+       pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
+                            PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
+       pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
        cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
-       x86_pci_write_config32(usb1, PCI_COMMAND, cmd);
+       pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
 
-       /* USB3 Controller */
-       x86_pci_write_config32(usb3, PCI_BASE_ADDRESS_0,
-                              PCH_XHCI_TEMP_BAR0);
-       cmd = x86_pci_read_config32(usb3, PCI_COMMAND);
+       /* USB3 Controller */
+       pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
+                            PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
+       pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
        cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
-       x86_pci_write_config32(usb3, PCI_COMMAND, cmd);
+       pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
 }
 
 static int report_bist_failure(void)
@@ -259,6 +177,7 @@ int print_cpuinfo(void)
 {
        enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
        char processor_name[CPU_MAX_NAME_LEN];
+       struct udevice *dev, *lpc;
        const char *name;
        uint32_t pm1_cnt;
        uint16_t pm1_sts;
@@ -289,7 +208,16 @@ int print_cpuinfo(void)
        }
 
        /* Early chipset init required before RAM init can work */
-       sandybridge_early_init(SANDYBRIDGE_MOBILE);
+       uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
+
+       ret = uclass_first_device(UCLASS_LPC, &lpc);
+       if (ret)
+               return ret;
+       if (!dev)
+               return -ENODEV;
+
+       /* Cause the SATA device to do its early init */
+       uclass_first_device(UCLASS_DISK, &dev);
 
        /* Check PM1_STS[15] to see if we are waking from Sx */
        pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
@@ -308,20 +236,18 @@ int print_cpuinfo(void)
        post_code(POST_EARLY_INIT);
 
        /* Enable SPD ROMs and DDR-III DRAM */
-       ret = enable_smbus();
+       ret = uclass_first_device(UCLASS_I2C, &dev);
        if (ret)
                return ret;
+       if (!dev)
+               return -ENODEV;
 
        /* Prepare USB controller early in S3 resume */
        if (boot_mode == PEI_BOOT_RESUME)
-               enable_usb_bar();
+               enable_usb_bar(pci_get_controller(lpc->parent));
 
        gd->arch.pei_boot_mode = boot_mode;
 
-       /* TODO: Move this to the board or driver */
-       x86_pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE | 1);
-       x86_pci_write_config32(PCH_LPC_DEV, GPIO_CNTL, 0x10);
-
        /* Print processor name */
        name = cpu_get_name(processor_name);
        printf("CPU:   %s\n", name);
diff --git a/arch/x86/cpu/ivybridge/early_init.c b/arch/x86/cpu/ivybridge/early_init.c
deleted file mode 100644 (file)
index 9ca008e..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * From Coreboot
- *
- * Copyright (C) 2007-2010 coresystems GmbH
- * Copyright (C) 2011 Google Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <asm/io.h>
-#include <asm/pci.h>
-#include <asm/arch/pch.h>
-#include <asm/arch/sandybridge.h>
-
-static void sandybridge_setup_bars(pci_dev_t pch_dev, pci_dev_t lpc_dev)
-{
-       /* Setting up Southbridge. In the northbridge code. */
-       debug("Setting up static southbridge registers\n");
-       x86_pci_write_config32(lpc_dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
-
-       x86_pci_write_config32(lpc_dev, PMBASE, DEFAULT_PMBASE | 1);
-       x86_pci_write_config8(lpc_dev, ACPI_CNTL, 0x80); /* Enable ACPI BAR */
-
-       debug("Disabling watchdog reboot\n");
-       setbits_le32(RCB_REG(GCS), 1 >> 5);     /* No reset */
-       outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08);    /* halt timer */
-
-       /* Set up all hardcoded northbridge BARs */
-       debug("Setting up static registers\n");
-       x86_pci_write_config32(pch_dev, EPBAR, DEFAULT_EPBAR | 1);
-       x86_pci_write_config32(pch_dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
-       x86_pci_write_config32(pch_dev, MCHBAR, DEFAULT_MCHBAR | 1);
-       x86_pci_write_config32(pch_dev, MCHBAR + 4,
-                              (0LL + DEFAULT_MCHBAR) >> 32);
-       /* 64MB - busses 0-63 */
-       x86_pci_write_config32(pch_dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
-       x86_pci_write_config32(pch_dev, PCIEXBAR + 4,
-                              (0LL + DEFAULT_PCIEXBAR) >> 32);
-       x86_pci_write_config32(pch_dev, DMIBAR, DEFAULT_DMIBAR | 1);
-       x86_pci_write_config32(pch_dev, DMIBAR + 4,
-                              (0LL + DEFAULT_DMIBAR) >> 32);
-
-       /* Set C0000-FFFFF to access RAM on both reads and writes */
-       x86_pci_write_config8(pch_dev, PAM0, 0x30);
-       x86_pci_write_config8(pch_dev, PAM1, 0x33);
-       x86_pci_write_config8(pch_dev, PAM2, 0x33);
-       x86_pci_write_config8(pch_dev, PAM3, 0x33);
-       x86_pci_write_config8(pch_dev, PAM4, 0x33);
-       x86_pci_write_config8(pch_dev, PAM5, 0x33);
-       x86_pci_write_config8(pch_dev, PAM6, 0x33);
-}
-
-static void sandybridge_setup_graphics(pci_dev_t pch_dev, pci_dev_t video_dev)
-{
-       u32 reg32;
-       u16 reg16;
-       u8 reg8;
-
-       reg16 = x86_pci_read_config16(video_dev, PCI_DEVICE_ID);
-       switch (reg16) {
-       case 0x0102: /* GT1 Desktop */
-       case 0x0106: /* GT1 Mobile */
-       case 0x010a: /* GT1 Server */
-       case 0x0112: /* GT2 Desktop */
-       case 0x0116: /* GT2 Mobile */
-       case 0x0122: /* GT2 Desktop >=1.3GHz */
-       case 0x0126: /* GT2 Mobile >=1.3GHz */
-       case 0x0156: /* IvyBridge */
-       case 0x0166: /* IvyBridge */
-               break;
-       default:
-               debug("Graphics not supported by this CPU/chipset\n");
-               return;
-       }
-
-       debug("Initialising Graphics\n");
-
-       /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
-       reg16 = x86_pci_read_config16(pch_dev, GGC);
-       reg16 &= ~0x00f8;
-       reg16 |= 1 << 3;
-       /* Program GTT memory by setting GGC[9:8] = 2MB */
-       reg16 &= ~0x0300;
-       reg16 |= 2 << 8;
-       /* Enable VGA decode */
-       reg16 &= ~0x0002;
-       x86_pci_write_config16(pch_dev, GGC, reg16);
-
-       /* Enable 256MB aperture */
-       reg8 = x86_pci_read_config8(video_dev, MSAC);
-       reg8 &= ~0x06;
-       reg8 |= 0x02;
-       x86_pci_write_config8(video_dev, MSAC, reg8);
-
-       /* Erratum workarounds */
-       reg32 = readl(MCHBAR_REG(0x5f00));
-       reg32 |= (1 << 9) | (1 << 10);
-       writel(reg32, MCHBAR_REG(0x5f00));
-
-       /* Enable SA Clock Gating */
-       reg32 = readl(MCHBAR_REG(0x5f00));
-       writel(reg32 | 1, MCHBAR_REG(0x5f00));
-
-       /* GPU RC6 workaround for sighting 366252 */
-       reg32 = readl(MCHBAR_REG(0x5d14));
-       reg32 |= (1 << 31);
-       writel(reg32, MCHBAR_REG(0x5d14));
-
-       /* VLW */
-       reg32 = readl(MCHBAR_REG(0x6120));
-       reg32 &= ~(1 << 0);
-       writel(reg32, MCHBAR_REG(0x6120));
-
-       reg32 = readl(MCHBAR_REG(0x5418));
-       reg32 |= (1 << 4) | (1 << 5);
-       writel(reg32, MCHBAR_REG(0x5418));
-}
-
-void sandybridge_early_init(int chipset_type)
-{
-       pci_dev_t pch_dev = PCH_DEV;
-       pci_dev_t video_dev = PCH_VIDEO_DEV;
-       pci_dev_t lpc_dev = PCH_LPC_DEV;
-       u32 capid0_a;
-       u8 reg8;
-
-       /* Device ID Override Enable should be done very early */
-       capid0_a = x86_pci_read_config32(pch_dev, 0xe4);
-       if (capid0_a & (1 << 10)) {
-               reg8 = x86_pci_read_config8(pch_dev, 0xf3);
-               reg8 &= ~7; /* Clear 2:0 */
-
-               if (chipset_type == SANDYBRIDGE_MOBILE)
-                       reg8 |= 1; /* Set bit 0 */
-
-               x86_pci_write_config8(pch_dev, 0xf3, reg8);
-       }
-
-       /* Setup all BARs required for early PCIe and raminit */
-       sandybridge_setup_bars(pch_dev, lpc_dev);
-
-       /* Device Enable */
-       x86_pci_write_config32(pch_dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
-
-       sandybridge_setup_graphics(pch_dev, video_dev);
-}
index 711470f36477d905e45cef93a69aa64343bbb001..b1df77d571b30ae08d7c91dcf779eefedfea7f11 100644 (file)
@@ -7,8 +7,10 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <asm/pci.h>
+#include <asm/cpu.h>
 #include <asm/processor.h>
 #include <asm/arch/me.h>
 #include <asm/arch/pch.h>
@@ -25,33 +27,36 @@ static const char *const me_ack_values[] = {
        [ME_HFS_ACK_CONTINUE]   = "Continue to boot"
 };
 
-static inline void pci_read_dword_ptr(void *ptr, int offset)
+static inline void pci_read_dword_ptr(struct udevice *me_dev, void *ptr,
+                                     int offset)
 {
        u32 dword;
 
-       dword = x86_pci_read_config32(PCH_ME_DEV, offset);
+       dm_pci_read_config32(me_dev, offset, &dword);
        memcpy(ptr, &dword, sizeof(dword));
 }
 
-static inline void pci_write_dword_ptr(void *ptr, int offset)
+static inline void pci_write_dword_ptr(struct udevice *me_dev, void *ptr,
+                                      int offset)
 {
        u32 dword = 0;
+
        memcpy(&dword, ptr, sizeof(dword));
-       x86_pci_write_config32(PCH_ME_DEV, offset, dword);
+       dm_pci_write_config32(me_dev, offset, dword);
 }
 
-void intel_early_me_status(void)
+void intel_early_me_status(struct udevice *me_dev)
 {
        struct me_hfs hfs;
        struct me_gmes gmes;
 
-       pci_read_dword_ptr(&hfs, PCI_ME_HFS);
-       pci_read_dword_ptr(&gmes, PCI_ME_GMES);
+       pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
+       pci_read_dword_ptr(me_dev, &gmes, PCI_ME_GMES);
 
        intel_me_status(&hfs, &gmes);
 }
 
-int intel_early_me_init(void)
+int intel_early_me_init(struct udevice *me_dev)
 {
        int count;
        struct me_uma uma;
@@ -61,7 +66,7 @@ int intel_early_me_init(void)
 
        /* Wait for ME UMA SIZE VALID bit to be set */
        for (count = ME_RETRY; count > 0; --count) {
-               pci_read_dword_ptr(&uma, PCI_ME_UMA);
+               pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
                if (uma.valid)
                        break;
                udelay(ME_DELAY);
@@ -72,7 +77,7 @@ int intel_early_me_init(void)
        }
 
        /* Check for valid firmware */
-       pci_read_dword_ptr(&hfs, PCI_ME_HFS);
+       pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
        if (hfs.fpt_bad) {
                printf("WARNING: ME has bad firmware\n");
                return -EBADF;
@@ -83,11 +88,11 @@ int intel_early_me_init(void)
        return 0;
 }
 
-int intel_early_me_uma_size(void)
+int intel_early_me_uma_size(struct udevice *me_dev)
 {
        struct me_uma uma;
 
-       pci_read_dword_ptr(&uma, PCI_ME_UMA);
+       pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
        if (uma.valid) {
                debug("ME: Requested %uMB UMA\n", uma.size);
                return uma.size;
@@ -97,11 +102,11 @@ int intel_early_me_uma_size(void)
        return -EINVAL;
 }
 
-static inline void set_global_reset(int enable)
+static inline void set_global_reset(struct udevice *dev, int enable)
 {
        u32 etr3;
 
-       etr3 = x86_pci_read_config32(PCH_LPC_DEV, ETR3);
+       dm_pci_read_config32(dev, ETR3, &etr3);
 
        /* Clear CF9 Without Resume Well Reset Enable */
        etr3 &= ~ETR3_CWORWRE;
@@ -112,10 +117,11 @@ static inline void set_global_reset(int enable)
        else
                etr3 &= ~ETR3_CF9GR;
 
-       x86_pci_write_config32(PCH_LPC_DEV, ETR3, etr3);
+       dm_pci_write_config32(dev, ETR3, etr3);
 }
 
-int intel_early_me_init_done(u8 status)
+int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
+                            uint status)
 {
        int count;
        u32 mebase_l, mebase_h;
@@ -126,8 +132,8 @@ int intel_early_me_init_done(u8 status)
        };
 
        /* MEBASE from MESEG_BASE[35:20] */
-       mebase_l = x86_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L);
-       mebase_h = x86_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H);
+       dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l);
+       dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h);
        mebase_h &= 0xf;
        did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
 
@@ -135,25 +141,25 @@ int intel_early_me_init_done(u8 status)
        debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n",
              status, did.uma_base);
 
-       pci_write_dword_ptr(&did, PCI_ME_H_GS);
+       pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS);
 
        /* Must wait for ME acknowledgement */
        for (count = ME_RETRY; count > 0; --count) {
-               pci_read_dword_ptr(&hfs, PCI_ME_HFS);
+               pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
                if (hfs.bios_msg_ack)
                        break;
                udelay(ME_DELAY);
        }
        if (!count) {
                printf("ERROR: ME failed to respond\n");
-               return -1;
+               return -ETIMEDOUT;
        }
 
        /* Return the requested BIOS action */
        debug("ME: Requested BIOS Action: %s\n", me_ack_values[hfs.ack_data]);
 
        /* Check status after acknowledgement */
-       intel_early_me_status();
+       intel_early_me_status(me_dev);
 
        switch (hfs.ack_data) {
        case ME_HFS_ACK_CONTINUE:
@@ -161,17 +167,17 @@ int intel_early_me_init_done(u8 status)
                return 0;
        case ME_HFS_ACK_RESET:
                /* Non-power cycle reset */
-               set_global_reset(0);
+               set_global_reset(dev, 0);
                reset_cpu(0);
                break;
        case ME_HFS_ACK_PWR_CYCLE:
                /* Power cycle reset */
-               set_global_reset(0);
+               set_global_reset(dev, 0);
                x86_full_reset();
                break;
        case ME_HFS_ACK_GBL_RESET:
                /* Global reset */
-               set_global_reset(1);
+               set_global_reset(dev, 1);
                x86_full_reset();
                break;
        case ME_HFS_ACK_S3:
@@ -180,5 +186,17 @@ int intel_early_me_init_done(u8 status)
                break;
        }
 
-       return -1;
+       return -EINVAL;
 }
+
+static const struct udevice_id ivybridge_syscon_ids[] = {
+       { .compatible = "intel,me", .data = X86_SYSCON_ME },
+       { .compatible = "intel,gma", .data = X86_SYSCON_GMA },
+       { }
+};
+
+U_BOOT_DRIVER(syscon_intel_me) = {
+       .name = "intel_me_syscon",
+       .id = UCLASS_SYSCON,
+       .of_match = ivybridge_syscon_ids,
+};
index 85a09c64b6725024b35d294f94f0420ab88dcb1f..3b6291e9054d607c1c563e8541ebf143e7d1672e 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <bios_emul.h>
+#include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <pci_rom.h>
@@ -352,14 +353,13 @@ static int gtt_poll(void *bar, u32 reg, u32 mask, u32 value)
        return 0;
 }
 
-static int gma_pm_init_pre_vbios(void *gtt_bar)
+static int gma_pm_init_pre_vbios(void *gtt_bar, int rev)
 {
        u32 reg32;
 
-       debug("GT Power Management Init, silicon = %#x\n",
-             bridge_silicon_revision());
+       debug("GT Power Management Init, silicon = %#x\n", rev);
 
-       if (bridge_silicon_revision() < IVB_STEP_C0) {
+       if (rev < IVB_STEP_C0) {
                /* 1: Enable force wake */
                gtt_write(gtt_bar, 0xa18c, 0x00000001);
                gtt_poll(gtt_bar, 0x130090, (1 << 0), (1 << 0));
@@ -369,14 +369,14 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
                gtt_poll(gtt_bar, 0x130040, (1 << 0), (1 << 0));
        }
 
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
                /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
                reg32 = gtt_read(gtt_bar, 0x42004);
                reg32 |= (1 << 14) | (1 << 15);
                gtt_write(gtt_bar, 0x42004, reg32);
        }
 
-       if (bridge_silicon_revision() >= IVB_STEP_A0) {
+       if (rev >= IVB_STEP_A0) {
                /* Display Reset Acknowledge Settings */
                reg32 = gtt_read(gtt_bar, 0x45010);
                reg32 |= (1 << 1) | (1 << 0);
@@ -385,7 +385,7 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
 
        /* 2: Get GT SKU from GTT+0x911c[13] */
        reg32 = gtt_read(gtt_bar, 0x911c);
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
                if (reg32 & (1 << 13)) {
                        debug("SNB GT1 Power Meter Weights\n");
                        gtt_write_powermeter(gtt_bar, snb_pm_gt1);
@@ -434,13 +434,13 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
        reg32 = gtt_read(gtt_bar, 0xa180);
        reg32 |= (1 << 26) | (1 << 31);
        /* (bit 20=1 for SNB step D1+ / IVB A0+) */
-       if (bridge_silicon_revision() >= SNB_STEP_D1)
+       if (rev >= SNB_STEP_D1)
                reg32 |= (1 << 20);
        gtt_write(gtt_bar, 0xa180, reg32);
 
        /* 6a: for SnB step D2+ only */
-       if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
-           (bridge_silicon_revision() >= SNB_STEP_D2)) {
+       if (((rev & BASE_REV_MASK) == BASE_REV_SNB) &&
+           (rev >= SNB_STEP_D2)) {
                reg32 = gtt_read(gtt_bar, 0x9400);
                reg32 |= (1 << 7);
                gtt_write(gtt_bar, 0x9400, reg32);
@@ -452,7 +452,7 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
                gtt_poll(gtt_bar, 0x941c, (1 << 1), (0 << 1));
        }
 
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
                reg32 = gtt_read(gtt_bar, 0x907c);
                reg32 |= (1 << 16);
                gtt_write(gtt_bar, 0x907c, reg32);
@@ -504,7 +504,7 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
        gtt_write(gtt_bar, 0xa070, 0x0000000a); /* RP Idle Hysteresis */
 
        /* 11a: Enable Render Standby (RC6) */
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
                /*
                 * IvyBridge should also support DeepRenderStandby.
                 *
@@ -538,14 +538,16 @@ static int gma_pm_init_pre_vbios(void *gtt_bar)
        return 0;
 }
 
-int gma_pm_init_post_vbios(void *gtt_bar, const void *blob, int node)
+int gma_pm_init_post_vbios(struct udevice *dev, int rev, void *gtt_bar)
 {
+       const void *blob = gd->fdt_blob;
+       int node = dev->of_offset;
        u32 reg32, cycle_delay;
 
        debug("GT Power Management Init (post VBIOS)\n");
 
        /* 15: Deassert Force Wake */
-       if (bridge_silicon_revision() < IVB_STEP_C0) {
+       if (rev < IVB_STEP_C0) {
                gtt_write(gtt_bar, 0xa18c, gtt_read(gtt_bar, 0xa18c) & ~1);
                gtt_poll(gtt_bar, 0x130090, (1 << 0), (0 << 0));
        } else {
@@ -728,15 +730,93 @@ static int int15_handler(void)
        return res;
 }
 
-int gma_func0_init(struct udevice *dev, const void *blob, int node)
+void sandybridge_setup_graphics(struct udevice *dev, struct udevice *video_dev)
+{
+       u32 reg32;
+       u16 reg16;
+       u8 reg8;
+
+       dm_pci_read_config16(video_dev, PCI_DEVICE_ID, &reg16);
+       switch (reg16) {
+       case 0x0102: /* GT1 Desktop */
+       case 0x0106: /* GT1 Mobile */
+       case 0x010a: /* GT1 Server */
+       case 0x0112: /* GT2 Desktop */
+       case 0x0116: /* GT2 Mobile */
+       case 0x0122: /* GT2 Desktop >=1.3GHz */
+       case 0x0126: /* GT2 Mobile >=1.3GHz */
+       case 0x0156: /* IvyBridge */
+       case 0x0166: /* IvyBridge */
+               break;
+       default:
+               debug("Graphics not supported by this CPU/chipset\n");
+               return;
+       }
+
+       debug("Initialising Graphics\n");
+
+       /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
+       dm_pci_read_config16(dev, GGC, &reg16);
+       reg16 &= ~0x00f8;
+       reg16 |= 1 << 3;
+       /* Program GTT memory by setting GGC[9:8] = 2MB */
+       reg16 &= ~0x0300;
+       reg16 |= 2 << 8;
+       /* Enable VGA decode */
+       reg16 &= ~0x0002;
+       dm_pci_write_config16(dev, GGC, reg16);
+
+       /* Enable 256MB aperture */
+       dm_pci_read_config8(video_dev, MSAC, &reg8);
+       reg8 &= ~0x06;
+       reg8 |= 0x02;
+       dm_pci_write_config8(video_dev, MSAC, reg8);
+
+       /* Erratum workarounds */
+       reg32 = readl(MCHBAR_REG(0x5f00));
+       reg32 |= (1 << 9) | (1 << 10);
+       writel(reg32, MCHBAR_REG(0x5f00));
+
+       /* Enable SA Clock Gating */
+       reg32 = readl(MCHBAR_REG(0x5f00));
+       writel(reg32 | 1, MCHBAR_REG(0x5f00));
+
+       /* GPU RC6 workaround for sighting 366252 */
+       reg32 = readl(MCHBAR_REG(0x5d14));
+       reg32 |= (1 << 31);
+       writel(reg32, MCHBAR_REG(0x5d14));
+
+       /* VLW */
+       reg32 = readl(MCHBAR_REG(0x6120));
+       reg32 &= ~(1 << 0);
+       writel(reg32, MCHBAR_REG(0x6120));
+
+       reg32 = readl(MCHBAR_REG(0x5418));
+       reg32 |= (1 << 4) | (1 << 5);
+       writel(reg32, MCHBAR_REG(0x5418));
+}
+
+int gma_func0_init(struct udevice *dev)
 {
 #ifdef CONFIG_VIDEO
        ulong start;
 #endif
+       struct udevice *nbridge;
        void *gtt_bar;
        ulong base;
        u32 reg32;
        int ret;
+       int rev;
+
+       /* Enable PCH Display Port */
+       writew(0x0010, RCB_REG(DISPBDF));
+       setbits_le32(RCB_REG(FD2), PCH_ENABLE_DBDF);
+
+       ret = uclass_first_device(UCLASS_NORTHBRIDGE, &nbridge);
+       if (!nbridge)
+               return -ENODEV;
+       rev = bridge_silicon_revision(nbridge);
+       sandybridge_setup_graphics(nbridge, dev);
 
        /* IGD needs to be Bus Master */
        dm_pci_read_config32(dev, PCI_COMMAND, &reg32);
@@ -750,7 +830,7 @@ int gma_func0_init(struct udevice *dev, const void *blob, int node)
 
        gtt_bar = (void *)dm_pci_read_bar32(dev, 0);
        debug("GT bar %p\n", gtt_bar);
-       ret = gma_pm_init_pre_vbios(gtt_bar);
+       ret = gma_pm_init_pre_vbios(gtt_bar, rev);
        if (ret)
                return ret;
 
@@ -761,7 +841,7 @@ int gma_func0_init(struct udevice *dev, const void *blob, int node)
        debug("BIOS ran in %lums\n", get_timer(start));
 #endif
        /* Post VBIOS init */
-       ret = gma_pm_init_post_vbios(gtt_bar, blob, node);
+       ret = gma_pm_init_post_vbios(dev, rev, gtt_bar);
        if (ret)
                return ret;
 
index af5d4a89089bad99778d5aef6799af6781143e86..9ab5ed3ff97bb998e16bda391e7cfdff599e2d48 100644 (file)
 #define ENABLE_ACPI_MODE_IN_COREBOOT   0
 #define TEST_SMM_FLASH_LOCKDOWN                0
 
-static int pch_enable_apic(pci_dev_t dev)
+static int pch_enable_apic(struct udevice *pch)
 {
        u32 reg32;
        int i;
 
        /* Enable ACPI I/O and power management. Set SCI IRQ to IRQ9 */
-       x86_pci_write_config8(dev, ACPI_CNTL, 0x80);
+       dm_pci_write_config8(pch, ACPI_CNTL, 0x80);
 
        writel(0, IO_APIC_INDEX);
        writel(1 << 25, IO_APIC_DATA);
@@ -66,36 +66,36 @@ static int pch_enable_apic(pci_dev_t dev)
        return 0;
 }
 
-static void pch_enable_serial_irqs(pci_dev_t dev)
+static void pch_enable_serial_irqs(struct udevice *pch)
 {
        u32 value;
 
        /* Set packet length and toggle silent mode bit for one frame. */
        value = (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0);
 #ifdef CONFIG_SERIRQ_CONTINUOUS_MODE
-       x86_pci_write_config8(dev, SERIRQ_CNTL, value);
+       dm_pci_write_config8(pch, SERIRQ_CNTL, value);
 #else
-       x86_pci_write_config8(dev, SERIRQ_CNTL, value | (1 << 6));
+       dm_pci_write_config8(pch, SERIRQ_CNTL, value | (1 << 6));
 #endif
 }
 
-static int pch_pirq_init(const void *blob, int node, pci_dev_t dev)
+static int pch_pirq_init(struct udevice *pch)
 {
        uint8_t route[8], *ptr;
 
-       if (fdtdec_get_byte_array(blob, node, "intel,pirq-routing", route,
-                                 sizeof(route)))
+       if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
+                                 "intel,pirq-routing", route, sizeof(route)))
                return -EINVAL;
        ptr = route;
-       x86_pci_write_config8(dev, PIRQA_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQB_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQC_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQD_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQA_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQB_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQC_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQD_ROUT, *ptr++);
 
-       x86_pci_write_config8(dev, PIRQE_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQF_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQG_ROUT, *ptr++);
-       x86_pci_write_config8(dev, PIRQH_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQE_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQF_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQG_ROUT, *ptr++);
+       dm_pci_write_config8(pch, PIRQH_ROUT, *ptr++);
 
        /*
         * TODO(sjg@chromium.org): U-Boot does not set up the interrupts
@@ -104,26 +104,28 @@ static int pch_pirq_init(const void *blob, int node, pci_dev_t dev)
        return 0;
 }
 
-static int pch_gpi_routing(const void *blob, int node, pci_dev_t dev)
+static int pch_gpi_routing(struct udevice *pch)
 {
        u8 route[16];
        u32 reg;
        int gpi;
 
-       if (fdtdec_get_byte_array(blob, node, "intel,gpi-routing", route,
-                                 sizeof(route)))
+       if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
+                                 "intel,gpi-routing", route, sizeof(route)))
                return -EINVAL;
 
        for (reg = 0, gpi = 0; gpi < ARRAY_SIZE(route); gpi++)
                reg |= route[gpi] << (gpi * 2);
 
-       x86_pci_write_config32(dev, 0xb8, reg);
+       dm_pci_write_config32(pch, 0xb8, reg);
 
        return 0;
 }
 
-static int pch_power_options(const void *blob, int node, pci_dev_t dev)
+static int pch_power_options(struct udevice *pch)
 {
+       const void *blob = gd->fdt_blob;
+       int node = pch->of_offset;
        u8 reg8;
        u16 reg16, pmbase;
        u32 reg32;
@@ -142,7 +144,7 @@ static int pch_power_options(const void *blob, int node, pci_dev_t dev)
         */
        pwr_on = MAINBOARD_POWER_ON;
 
-       reg16 = x86_pci_read_config16(dev, GEN_PMCON_3);
+       dm_pci_read_config16(pch, GEN_PMCON_3, &reg16);
        reg16 &= 0xfffe;
        switch (pwr_on) {
        case MAINBOARD_POWER_OFF:
@@ -169,7 +171,7 @@ static int pch_power_options(const void *blob, int node, pci_dev_t dev)
 
        reg16 |= (1 << 12);     /* Disable SLP stretch after SUS well */
 
-       x86_pci_write_config16(dev, GEN_PMCON_3, reg16);
+       dm_pci_write_config16(pch, GEN_PMCON_3, reg16);
        debug("Set power %s after power failure.\n", state);
 
        /* Set up NMI on errors. */
@@ -193,21 +195,22 @@ static int pch_power_options(const void *blob, int node, pci_dev_t dev)
        outb(reg8, 0x70);
 
        /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
-       reg16 = x86_pci_read_config16(dev, GEN_PMCON_1);
+       dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
        reg16 &= ~(3 << 0);     /* SMI# rate 1 minute */
        reg16 &= ~(1 << 10);    /* Disable BIOS_PCI_EXP_EN for native PME */
 #if DEBUG_PERIODIC_SMIS
        /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using periodic SMIs */
        reg16 |= (3 << 0);      /* Periodic SMI every 8s */
 #endif
-       x86_pci_write_config16(dev, GEN_PMCON_1, reg16);
+       dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
 
        /* Set the board's GPI routing. */
-       ret = pch_gpi_routing(blob, node, dev);
+       ret = pch_gpi_routing(pch);
        if (ret)
                return ret;
 
-       pmbase = x86_pci_read_config16(dev, 0x40) & 0xfffe;
+       dm_pci_read_config16(pch, 0x40, &pmbase);
+       pmbase &= 0xfffe;
 
        writel(pmbase + GPE0_EN, fdtdec_get_int(blob, node,
                                                "intel,gpe0-enable", 0));
@@ -227,16 +230,16 @@ static int pch_power_options(const void *blob, int node, pci_dev_t dev)
        return 0;
 }
 
-static void pch_rtc_init(pci_dev_t dev)
+static void pch_rtc_init(struct udevice *pch)
 {
        int rtc_failed;
        u8 reg8;
 
-       reg8 = x86_pci_read_config8(dev, GEN_PMCON_3);
+       dm_pci_read_config8(pch, GEN_PMCON_3, &reg8);
        rtc_failed = reg8 & RTC_BATTERY_DEAD;
        if (rtc_failed) {
                reg8 &= ~RTC_BATTERY_DEAD;
-               x86_pci_write_config8(dev, GEN_PMCON_3, reg8);
+               dm_pci_write_config8(pch, GEN_PMCON_3, reg8);
        }
        debug("rtc_failed = 0x%x\n", rtc_failed);
 
@@ -246,10 +249,10 @@ static void pch_rtc_init(pci_dev_t dev)
 }
 
 /* CougarPoint PCH Power Management init */
-static void cpt_pm_init(pci_dev_t dev)
+static void cpt_pm_init(struct udevice *pch)
 {
        debug("CougarPoint PM init\n");
-       x86_pci_write_config8(dev, 0xa9, 0x47);
+       dm_pci_write_config8(pch, 0xa9, 0x47);
        setbits_le32(RCB_REG(0x2238), (1 << 6) | (1 << 0));
 
        setbits_le32(RCB_REG(0x228c), 1 << 0);
@@ -290,10 +293,10 @@ static void cpt_pm_init(pci_dev_t dev)
 }
 
 /* PantherPoint PCH Power Management init */
-static void ppt_pm_init(pci_dev_t dev)
+static void ppt_pm_init(struct udevice *pch)
 {
        debug("PantherPoint PM init\n");
-       x86_pci_write_config8(dev, 0xa9, 0x47);
+       dm_pci_write_config8(pch, 0xa9, 0x47);
        setbits_le32(RCB_REG(0x2238), 1 << 0);
        setbits_le32(RCB_REG(0x228c), 1 << 0);
        setbits_le16(RCB_REG(0x1100), (1 << 13) | (1 << 14));
@@ -340,21 +343,21 @@ static void enable_hpet(void)
        clrsetbits_le32(RCB_REG(HPTC), 3 << 0, 1 << 7);
 }
 
-static void enable_clock_gating(pci_dev_t dev)
+static void enable_clock_gating(struct udevice *pch)
 {
        u32 reg32;
        u16 reg16;
 
        setbits_le32(RCB_REG(0x2234), 0xf);
 
-       reg16 = x86_pci_read_config16(dev, GEN_PMCON_1);
+       dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
        reg16 |= (1 << 2) | (1 << 11);
-       x86_pci_write_config16(dev, GEN_PMCON_1, reg16);
+       dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
 
-       pch_iobp_update(0xEB007F07, ~0UL, (1 << 31));
-       pch_iobp_update(0xEB004000, ~0UL, (1 << 7));
-       pch_iobp_update(0xEC007F07, ~0UL, (1 << 31));
-       pch_iobp_update(0xEC004000, ~0UL, (1 << 7));
+       pch_iobp_update(pch, 0xEB007F07, ~0UL, (1 << 31));
+       pch_iobp_update(pch, 0xEB004000, ~0UL, (1 << 7));
+       pch_iobp_update(pch, 0xEC007F07, ~0UL, (1 << 31));
+       pch_iobp_update(pch, 0xEC004000, ~0UL, (1 << 7));
 
        reg32 = readl(RCB_REG(CG));
        reg32 |= (1 << 31);
@@ -376,77 +379,24 @@ static void enable_clock_gating(pci_dev_t dev)
        setbits_le32(RCB_REG(0x3564), 0x3);
 }
 
-#if CONFIG_HAVE_SMI_HANDLER
-static void pch_lock_smm(pci_dev_t dev)
-{
-#if TEST_SMM_FLASH_LOCKDOWN
-       u8 reg8;
-#endif
-
-       if (acpi_slp_type != 3) {
-#if ENABLE_ACPI_MODE_IN_COREBOOT
-               debug("Enabling ACPI via APMC:\n");
-               outb(0xe1, 0xb2); /* Enable ACPI mode */
-               debug("done.\n");
-#else
-               debug("Disabling ACPI via APMC:\n");
-               outb(0x1e, 0xb2); /* Disable ACPI mode */
-               debug("done.\n");
-#endif
-       }
-
-       /* Don't allow evil boot loaders, kernels, or
-        * userspace applications to deceive us:
-        */
-       smm_lock();
-
-#if TEST_SMM_FLASH_LOCKDOWN
-       /* Now try this: */
-       debug("Locking BIOS to RO... ");
-       reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
-       debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
-             (reg8 & 1) ? "rw" : "ro");
-       reg8 &= ~(1 << 0);                      /* clear BIOSWE */
-       x86_pci_write_config8(dev, 0xdc, reg8);
-       reg8 |= (1 << 1);                       /* set BLE */
-       x86_pci_write_config8(dev, 0xdc, reg8);
-       debug("ok.\n");
-       reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
-       debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
-             (reg8 & 1) ? "rw" : "ro");
-
-       debug("Writing:\n");
-       writeb(0, 0xfff00000);
-       debug("Testing:\n");
-       reg8 |= (1 << 0);                       /* set BIOSWE */
-       x86_pci_write_config8(dev, 0xdc, reg8);
-
-       reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
-       debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
-             (reg8 & 1) ? "rw" : "ro");
-       debug("Done.\n");
-#endif
-}
-#endif
-
-static void pch_disable_smm_only_flashing(pci_dev_t dev)
+static void pch_disable_smm_only_flashing(struct udevice *pch)
 {
        u8 reg8;
 
        debug("Enabling BIOS updates outside of SMM... ");
-       reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
+       dm_pci_read_config8(pch, 0xdc, &reg8);  /* BIOS_CNTL */
        reg8 &= ~(1 << 5);
-       x86_pci_write_config8(dev, 0xdc, reg8);
+       dm_pci_write_config8(pch, 0xdc, reg8);
 }
 
-static void pch_fixups(pci_dev_t dev)
+static void pch_fixups(struct udevice *pch)
 {
        u8 gen_pmcon_2;
 
        /* Indicate DRAM init done for MRC S3 to know it can resume */
-       gen_pmcon_2 = x86_pci_read_config8(dev, GEN_PMCON_2);
+       dm_pci_read_config8(pch, GEN_PMCON_2, &gen_pmcon_2);
        gen_pmcon_2 |= (1 << 7);
-       x86_pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2);
+       dm_pci_write_config8(pch, GEN_PMCON_2, gen_pmcon_2);
 
        /* Enable DMI ASPM in the PCH */
        clrbits_le32(RCB_REG(0x2304), 1 << 10);
@@ -454,7 +404,49 @@ static void pch_fixups(pci_dev_t dev)
        setbits_le32(RCB_REG(0x21a8), 0x3);
 }
 
-int lpc_early_init(const void *blob, int node, pci_dev_t dev)
+/*
+ * Enable Prefetching and Caching.
+ */
+static void enable_spi_prefetch(struct udevice *pch)
+{
+       u8 reg8;
+
+       dm_pci_read_config8(pch, 0xdc, &reg8);
+       reg8 &= ~(3 << 2);
+       reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
+       dm_pci_write_config8(pch, 0xdc, reg8);
+}
+
+static void enable_port80_on_lpc(struct udevice *pch)
+{
+       /* Enable port 80 POST on LPC */
+       dm_pci_write_config32(pch, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
+       clrbits_le32(RCB_REG(GCS), 4);
+}
+
+static void set_spi_speed(void)
+{
+       u32 fdod;
+
+       /* Observe SPI Descriptor Component Section 0 */
+       writel(0x1000, RCB_REG(SPI_DESC_COMP0));
+
+       /* Extract the1 Write/Erase SPI Frequency from descriptor */
+       fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
+       fdod >>= 24;
+       fdod &= 7;
+
+       /* Set Software Sequence frequency to match */
+       clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
+}
+
+/**
+ * lpc_early_init() - set up LPC serial ports and other early things
+ *
+ * @dev:       LPC device
+ * @return 0 if OK, -ve on error
+ */
+static int lpc_early_init(struct udevice *dev)
 {
        struct reg_info {
                u32 base;
@@ -463,17 +455,18 @@ int lpc_early_init(const void *blob, int node, pci_dev_t dev)
        int count;
        int i;
 
-       count = fdtdec_get_int_array_count(blob, node, "intel,gen-dec",
-                       (u32 *)values, sizeof(values) / sizeof(u32));
+       count = fdtdec_get_int_array_count(gd->fdt_blob, dev->of_offset,
+                       "intel,gen-dec", (u32 *)values,
+                       sizeof(values) / sizeof(u32));
        if (count < 0)
                return -EINVAL;
 
        /* Set COM1/COM2 decode range */
-       x86_pci_write_config16(dev, LPC_IO_DEC, 0x0010);
+       dm_pci_write_config16(dev->parent, LPC_IO_DEC, 0x0010);
 
        /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
-       x86_pci_write_config16(dev, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
-                          GAMEL_LPC_EN | COMA_LPC_EN);
+       dm_pci_write_config16(dev->parent, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
+                             GAMEL_LPC_EN | COMA_LPC_EN);
 
        /* Write all registers but use 0 if we run out of data */
        count = count * sizeof(u32) / sizeof(values[0]);
@@ -482,81 +475,114 @@ int lpc_early_init(const void *blob, int node, pci_dev_t dev)
 
                if (i < count)
                        reg = ptr->base | PCI_COMMAND_IO | (ptr->size << 16);
-               x86_pci_write_config32(dev, LPC_GENX_DEC(i), reg);
+               dm_pci_write_config32(dev->parent, LPC_GENX_DEC(i), reg);
        }
 
+       enable_spi_prefetch(dev->parent);
+
+       /* This is already done in start.S, but let's do it in C */
+       enable_port80_on_lpc(dev->parent);
+
+       set_spi_speed();
+
        return 0;
 }
 
-int lpc_init(struct pci_controller *hose, pci_dev_t dev)
+static int lpc_init_extra(struct udevice *dev)
 {
+       struct udevice *pch = dev->parent;
        const void *blob = gd->fdt_blob;
        int node;
 
        debug("pch: lpc_init\n");
-       pci_write_bar32(hose, dev, 0, 0);
-       pci_write_bar32(hose, dev, 1, 0xff800000);
-       pci_write_bar32(hose, dev, 2, 0xfec00000);
-       pci_write_bar32(hose, dev, 3, 0x800);
-       pci_write_bar32(hose, dev, 4, 0x900);
+       dm_pci_write_bar32(pch, 0, 0);
+       dm_pci_write_bar32(pch, 1, 0xff800000);
+       dm_pci_write_bar32(pch, 2, 0xfec00000);
+       dm_pci_write_bar32(pch, 3, 0x800);
+       dm_pci_write_bar32(pch, 4, 0x900);
 
        node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
        if (node < 0)
                return -ENOENT;
 
        /* Set the value for PCI command register. */
-       x86_pci_write_config16(dev, PCI_COMMAND, 0x000f);
+       dm_pci_write_config16(pch, PCI_COMMAND, 0x000f);
 
        /* IO APIC initialization. */
-       pch_enable_apic(dev);
+       pch_enable_apic(pch);
 
-       pch_enable_serial_irqs(dev);
+       pch_enable_serial_irqs(pch);
 
        /* Setup the PIRQ. */
-       pch_pirq_init(blob, node, dev);
+       pch_pirq_init(pch);
 
        /* Setup power options. */
-       pch_power_options(blob, node, dev);
+       pch_power_options(pch);
 
        /* Initialize power management */
-       switch (pch_silicon_type()) {
+       switch (pch_silicon_type(pch)) {
        case PCH_TYPE_CPT: /* CougarPoint */
-               cpt_pm_init(dev);
+               cpt_pm_init(pch);
                break;
        case PCH_TYPE_PPT: /* PantherPoint */
-               ppt_pm_init(dev);
+               ppt_pm_init(pch);
                break;
        default:
-               printf("Unknown Chipset: %#02x.%dx\n", PCI_DEV(dev),
-                      PCI_FUNC(dev));
+               printf("Unknown Chipset: %s\n", pch->name);
                return -ENOSYS;
        }
 
        /* Initialize the real time clock. */
-       pch_rtc_init(dev);
+       pch_rtc_init(pch);
 
        /* Initialize the High Precision Event Timers, if present. */
        enable_hpet();
 
        /* Initialize Clock Gating */
-       enable_clock_gating(dev);
+       enable_clock_gating(pch);
 
-       pch_disable_smm_only_flashing(dev);
+       pch_disable_smm_only_flashing(pch);
 
-#if CONFIG_HAVE_SMI_HANDLER
-       pch_lock_smm(dev);
-#endif
+       pch_fixups(pch);
 
-       pch_fixups(dev);
+       return 0;
+}
+
+static int bd82x6x_lpc_early_init(struct udevice *dev)
+{
+       /* Setting up Southbridge. In the northbridge code. */
+       debug("Setting up static southbridge registers\n");
+       dm_pci_write_config32(dev->parent, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
+       dm_pci_write_config32(dev->parent, PMBASE, DEFAULT_PMBASE | 1);
+
+       /* Enable ACPI BAR */
+       dm_pci_write_config8(dev->parent, ACPI_CNTL, 0x80);
+
+       debug("Disabling watchdog reboot\n");
+       setbits_le32(RCB_REG(GCS), 1 >> 5);     /* No reset */
+       outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08);    /* halt timer */
+
+       dm_pci_write_config32(dev->parent, GPIO_BASE, DEFAULT_GPIOBASE | 1);
+       dm_pci_write_config32(dev->parent, GPIO_CNTL, 0x10);
 
        return 0;
 }
 
-void lpc_enable(pci_dev_t dev)
+static int bd82x6x_lpc_probe(struct udevice *dev)
 {
-       /* Enable PCH Display Port */
-       writew(0x0010, RCB_REG(DISPBDF));
-       setbits_le32(RCB_REG(FD2), PCH_ENABLE_DBDF);
+       int ret;
+
+       if (!(gd->flags & GD_FLG_RELOC)) {
+               ret = lpc_early_init(dev);
+               if (ret) {
+                       debug("%s: lpc_early_init() failed\n", __func__);
+                       return ret;
+               }
+
+               return bd82x6x_lpc_early_init(dev);
+       }
+
+       return lpc_init_extra(dev);
 }
 
 static const struct udevice_id bd82x6x_lpc_ids[] = {
@@ -568,4 +594,5 @@ U_BOOT_DRIVER(bd82x6x_lpc_drv) = {
        .name           = "lpc",
        .id             = UCLASS_LPC,
        .of_match       = bd82x6x_lpc_ids,
+       .probe          = bd82x6x_lpc_probe,
 };
index fd7db97cbdf1fff172f47cb22e03f42e95fc8555..9654600cf17866708698a3347a9fa6f7720ebec3 100644 (file)
@@ -8,10 +8,13 @@
  */
 
 #include <common.h>
+#include <cpu.h>
+#include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/acpi.h>
 #include <asm/cpu.h>
+#include <asm/cpu_x86.h>
 #include <asm/lapic.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
@@ -280,18 +283,13 @@ static void configure_c_states(void)
        msr_write(MSR_PP1_CURRENT_CONFIG, msr);
 }
 
-static int configure_thermal_target(void)
+static int configure_thermal_target(struct udevice *dev)
 {
        int tcc_offset;
        msr_t msr;
-       int node;
 
-       /* Find pointer to CPU configuration */
-       node = fdtdec_next_compatible(gd->fdt_blob, 0,
-                                     COMPAT_INTEL_MODEL_206AX);
-       if (node < 0)
-               return -ENOENT;
-       tcc_offset = fdtdec_get_int(gd->fdt_blob, node, "tcc-offset", 0);
+       tcc_offset = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "tcc-offset",
+                                   0);
 
        /* Set TCC activaiton offset if supported */
        msr = msr_read(MSR_PLATFORM_INFO);
@@ -400,56 +398,7 @@ static void configure_mca(void)
 static unsigned ehci_debug_addr;
 #endif
 
-/*
- * Initialize any extra cores/threads in this package.
- */
-static int intel_cores_init(struct x86_cpu_priv *cpu)
-{
-       struct cpuid_result result;
-       unsigned threads_per_package, threads_per_core, i;
-
-       /* Logical processors (threads) per core */
-       result = cpuid_ext(0xb, 0);
-       threads_per_core = result.ebx & 0xffff;
-
-       /* Logical processors (threads) per package */
-       result = cpuid_ext(0xb, 1);
-       threads_per_package = result.ebx & 0xffff;
-
-       debug("CPU: %u has %u cores, %u threads per core\n",
-             cpu->apic_id, threads_per_package / threads_per_core,
-             threads_per_core);
-
-       for (i = 1; i < threads_per_package; ++i) {
-               struct x86_cpu_priv *new_cpu;
-
-               new_cpu = calloc(1, sizeof(*new_cpu));
-               if (!new_cpu)
-                       return -ENOMEM;
-
-               new_cpu->apic_id = cpu->apic_id + i;
-
-               /* Update APIC ID if no hyperthreading */
-               if (threads_per_core == 1)
-                       new_cpu->apic_id <<= 1;
-
-               debug("CPU: %u has core %u\n", cpu->apic_id, new_cpu->apic_id);
-
-#if 0 && CONFIG_SMP && CONFIG_MAX_CPUS > 1
-               /* TODO(sjg@chromium.org): Start the new cpu */
-               if (!start_cpu(new_cpu)) {
-                       /* Record the error in cpu? */
-                       printk(BIOS_ERR, "CPU %u would not start!\n",
-                              new_cpu->apic_id);
-                       new_cpu->start_err = 1;
-               }
-#endif
-       }
-
-       return 0;
-}
-
-int model_206ax_init(struct x86_cpu_priv *cpu)
+static int model_206ax_init(struct udevice *dev)
 {
        int ret;
 
@@ -463,16 +412,6 @@ int model_206ax_init(struct x86_cpu_priv *cpu)
        set_ehci_debug(0);
 #endif
 
-       /* Setup MTRRs based on physical address size */
-#if 0 /* TODO: Implement this */
-       struct cpuid_result cpuid_regs;
-
-       cpuid_regs = cpuid(0x80000008);
-       x86_setup_fixed_mtrrs();
-       x86_setup_var_mtrrs(cpuid_regs.eax & 0xff, 2);
-       x86_mtrr_check();
-#endif
-
 #if CONFIG_USBDEBUG
        set_ehci_debug(ehci_debug_addr);
 #endif
@@ -491,9 +430,11 @@ int model_206ax_init(struct x86_cpu_priv *cpu)
        configure_misc();
 
        /* Thermal throttle activation offset */
-       ret = configure_thermal_target();
-       if (ret)
+       ret = configure_thermal_target(dev);
+       if (ret) {
+               debug("Cannot set thermal target\n");
                return ret;
+       }
 
        /* Enable Direct Cache Access */
        configure_dca_cap();
@@ -507,8 +448,49 @@ int model_206ax_init(struct x86_cpu_priv *cpu)
        /* Enable Turbo */
        turbo_enable();
 
-       /* Start up extra cores */
-       intel_cores_init(cpu);
+       return 0;
+}
+
+static int model_206ax_get_info(struct udevice *dev, struct cpu_info *info)
+{
+       msr_t msr;
+
+       msr = msr_read(IA32_PERF_CTL);
+       info->cpu_freq = ((msr.lo >> 8) & 0xff) * SANDYBRIDGE_BCLK * 1000000;
+       info->features = 1 << CPU_FEAT_L1_CACHE | 1 << CPU_FEAT_MMU;
+
+       return 0;
+}
+
+static int model_206ax_get_count(struct udevice *dev)
+{
+       return 4;
+}
+
+static int cpu_x86_model_206ax_probe(struct udevice *dev)
+{
+       if (dev->seq == 0)
+               model_206ax_init(dev);
 
        return 0;
 }
+
+static const struct cpu_ops cpu_x86_model_206ax_ops = {
+       .get_desc       = cpu_x86_get_desc,
+       .get_info       = model_206ax_get_info,
+       .get_count      = model_206ax_get_count,
+};
+
+static const struct udevice_id cpu_x86_model_206ax_ids[] = {
+       { .compatible = "intel,core-gen3" },
+       { }
+};
+
+U_BOOT_DRIVER(cpu_x86_model_206ax_drv) = {
+       .name           = "cpu_x86_model_206ax",
+       .id             = UCLASS_CPU,
+       .of_match       = cpu_x86_model_206ax_ids,
+       .bind           = cpu_x86_bind,
+       .probe          = cpu_x86_model_206ax_probe,
+       .ops            = &cpu_x86_model_206ax_ops,
+};
index e3d8c139dfda3a3d6472a00f69b2f990b076537c..a066607a18d3d11a75f50c0848bf7de3738e1d78 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <asm/msr.h>
 #include <asm/acpi.h>
 #include <asm/cpu.h>
 #include <asm/arch/model_206ax.h>
 #include <asm/arch/sandybridge.h>
 
-static int bridge_revision_id = -1;
-
-int bridge_silicon_revision(void)
+int bridge_silicon_revision(struct udevice *dev)
 {
-       if (bridge_revision_id < 0) {
-               struct cpuid_result result;
-               uint8_t stepping, bridge_id;
-               pci_dev_t dev;
-
-               result = cpuid(1);
-               stepping = result.eax & 0xf;
-               dev = PCI_BDF(0, 0, 0);
-               bridge_id = x86_pci_read_config16(dev, PCI_DEVICE_ID) & 0xf0;
-               bridge_revision_id = bridge_id | stepping;
-       }
-
-       return bridge_revision_id;
+       struct cpuid_result result;
+       u16 bridge_id;
+       u8 stepping;
+
+       result = cpuid(1);
+       stepping = result.eax & 0xf;
+       dm_pci_read_config16(dev, PCI_DEVICE_ID, &bridge_id);
+       bridge_id &= 0xf0;
+       return bridge_id | stepping;
 }
 
 /*
@@ -47,15 +42,14 @@ int bridge_silicon_revision(void)
 static const int legacy_hole_base_k = 0xa0000 / 1024;
 static const int legacy_hole_size_k = 384;
 
-static int get_pcie_bar(u32 *base, u32 *len)
+static int get_pcie_bar(struct udevice *dev, u32 *base, u32 *len)
 {
-       pci_dev_t dev = PCI_BDF(0, 0, 0);
        u32 pciexbar_reg;
 
        *base = 0;
        *len = 0;
 
-       pciexbar_reg = x86_pci_read_config32(dev, PCIEXBAR);
+       dm_pci_read_config32(dev, PCIEXBAR, &pciexbar_reg);
 
        if (!(pciexbar_reg & (1 << 0)))
                return 0;
@@ -81,55 +75,55 @@ static int get_pcie_bar(u32 *base, u32 *len)
        return 0;
 }
 
-static void add_fixed_resources(pci_dev_t dev, int index)
+static void add_fixed_resources(struct udevice *dev, int index)
 {
        u32 pcie_config_base, pcie_config_size;
 
-       if (get_pcie_bar(&pcie_config_base, &pcie_config_size)) {
+       if (get_pcie_bar(dev, &pcie_config_base, &pcie_config_size)) {
                debug("Adding PCIe config bar base=0x%08x size=0x%x\n",
                      pcie_config_base, pcie_config_size);
        }
 }
 
-static void northbridge_dmi_init(pci_dev_t dev)
+static void northbridge_dmi_init(struct udevice *dev, int rev)
 {
        /* Clear error status bits */
        writel(0xffffffff, DMIBAR_REG(0x1c4));
        writel(0xffffffff, DMIBAR_REG(0x1d0));
 
        /* Steps prior to DMI ASPM */
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
                clrsetbits_le32(DMIBAR_REG(0x250), (1 << 22) | (1 << 20),
                                1 << 21);
        }
 
        setbits_le32(DMIBAR_REG(0x238), 1 << 29);
 
-       if (bridge_silicon_revision() >= SNB_STEP_D0) {
+       if (rev >= SNB_STEP_D0) {
                setbits_le32(DMIBAR_REG(0x1f8), 1 << 16);
-       } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
+       } else if (rev >= SNB_STEP_D1) {
                clrsetbits_le32(DMIBAR_REG(0x1f8), 1 << 26, 1 << 16);
                setbits_le32(DMIBAR_REG(0x1fc), (1 << 12) | (1 << 23));
        }
 
        /* Enable ASPM on SNB link, should happen before PCH link */
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB)
+       if ((rev & BASE_REV_MASK) == BASE_REV_SNB)
                setbits_le32(DMIBAR_REG(0xd04), 1 << 4);
 
        setbits_le32(DMIBAR_REG(0x88), (1 << 1) | (1 << 0));
 }
 
-void northbridge_init(pci_dev_t dev)
+static void northbridge_init(struct udevice *dev, int rev)
 {
        u32 bridge_type;
 
        add_fixed_resources(dev, 6);
-       northbridge_dmi_init(dev);
+       northbridge_dmi_init(dev, rev);
 
        bridge_type = readl(MCHBAR_REG(0x5f10));
        bridge_type &= ~0xff;
 
-       if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
+       if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
                /* Enable Power Aware Interrupt Routing - fixed priority */
                clrsetbits_8(MCHBAR_REG(0x5418), 0xf, 0x4);
 
@@ -167,6 +161,78 @@ void northbridge_init(pci_dev_t dev)
        writel(0x00100001, MCHBAR_REG(0x5500));
 }
 
-void northbridge_enable(pci_dev_t dev)
+static void sandybridge_setup_northbridge_bars(struct udevice *dev)
+{
+       /* Set up all hardcoded northbridge BARs */
+       debug("Setting up static registers\n");
+       dm_pci_write_config32(dev, EPBAR, DEFAULT_EPBAR | 1);
+       dm_pci_write_config32(dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
+       dm_pci_write_config32(dev, MCHBAR, DEFAULT_MCHBAR | 1);
+       dm_pci_write_config32(dev, MCHBAR + 4, (0LL + DEFAULT_MCHBAR) >> 32);
+       /* 64MB - busses 0-63 */
+       dm_pci_write_config32(dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
+       dm_pci_write_config32(dev, PCIEXBAR + 4,
+                             (0LL + DEFAULT_PCIEXBAR) >> 32);
+       dm_pci_write_config32(dev, DMIBAR, DEFAULT_DMIBAR | 1);
+       dm_pci_write_config32(dev, DMIBAR + 4, (0LL + DEFAULT_DMIBAR) >> 32);
+
+       /* Set C0000-FFFFF to access RAM on both reads and writes */
+       dm_pci_write_config8(dev, PAM0, 0x30);
+       dm_pci_write_config8(dev, PAM1, 0x33);
+       dm_pci_write_config8(dev, PAM2, 0x33);
+       dm_pci_write_config8(dev, PAM3, 0x33);
+       dm_pci_write_config8(dev, PAM4, 0x33);
+       dm_pci_write_config8(dev, PAM5, 0x33);
+       dm_pci_write_config8(dev, PAM6, 0x33);
+}
+
+static int bd82x6x_northbridge_early_init(struct udevice *dev)
+{
+       const int chipset_type = SANDYBRIDGE_MOBILE;
+       u32 capid0_a;
+       u8 reg8;
+
+       /* Device ID Override Enable should be done very early */
+       dm_pci_read_config32(dev, 0xe4, &capid0_a);
+       if (capid0_a & (1 << 10)) {
+               dm_pci_read_config8(dev, 0xf3, &reg8);
+               reg8 &= ~7; /* Clear 2:0 */
+
+               if (chipset_type == SANDYBRIDGE_MOBILE)
+                       reg8 |= 1; /* Set bit 0 */
+
+               dm_pci_write_config8(dev, 0xf3, reg8);
+       }
+
+       sandybridge_setup_northbridge_bars(dev);
+
+       /* Device Enable */
+       dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
+
+       return 0;
+}
+
+static int bd82x6x_northbridge_probe(struct udevice *dev)
 {
+       int rev;
+
+       if (!(gd->flags & GD_FLG_RELOC))
+               return bd82x6x_northbridge_early_init(dev);
+
+       rev = bridge_silicon_revision(dev);
+       northbridge_init(dev, rev);
+
+       return 0;
 }
+
+static const struct udevice_id bd82x6x_northbridge_ids[] = {
+       { .compatible = "intel,bd82x6x-northbridge" },
+       { }
+};
+
+U_BOOT_DRIVER(bd82x6x_northbridge_drv) = {
+       .name           = "bd82x6x_northbridge",
+       .id             = UCLASS_NORTHBRIDGE,
+       .of_match       = bd82x6x_northbridge_ids,
+       .probe          = bd82x6x_northbridge_probe,
+};
diff --git a/arch/x86/cpu/ivybridge/pch.c b/arch/x86/cpu/ivybridge/pch.c
deleted file mode 100644 (file)
index bbab646..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * From Coreboot
- * Copyright (C) 2008-2009 coresystems GmbH
- * Copyright (C) 2012 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:    GPL-2.0
- */
-
-#include <common.h>
-#include <asm/io.h>
-#include <asm/pci.h>
-#include <asm/arch/pch.h>
-
-static int pch_revision_id = -1;
-static int pch_type = -1;
-
-int pch_silicon_revision(void)
-{
-       pci_dev_t dev;
-
-       dev = PCH_LPC_DEV;
-
-       if (pch_revision_id < 0)
-               pch_revision_id = x86_pci_read_config8(dev, PCI_REVISION_ID);
-       return pch_revision_id;
-}
-
-int pch_silicon_type(void)
-{
-       pci_dev_t dev;
-
-       dev = PCH_LPC_DEV;
-
-       if (pch_type < 0)
-               pch_type = x86_pci_read_config8(dev, PCI_DEVICE_ID + 1);
-       return pch_type;
-}
-
-int pch_silicon_supported(int type, int rev)
-{
-       int cur_type = pch_silicon_type();
-       int cur_rev = pch_silicon_revision();
-
-       switch (type) {
-       case PCH_TYPE_CPT:
-               /* CougarPoint minimum revision */
-               if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
-                       return 1;
-               /* PantherPoint any revision */
-               if (cur_type == PCH_TYPE_PPT)
-                       return 1;
-               break;
-
-       case PCH_TYPE_PPT:
-               /* PantherPoint minimum revision */
-               if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
-                       return 1;
-               break;
-       }
-
-       return 0;
-}
-
-#define IOBP_RETRY 1000
-static inline int iobp_poll(void)
-{
-       unsigned try = IOBP_RETRY;
-       u32 data;
-
-       while (try--) {
-               data = readl(RCB_REG(IOBPS));
-               if ((data & 1) == 0)
-                       return 1;
-               udelay(10);
-       }
-
-       printf("IOBP timeout\n");
-       return 0;
-}
-
-void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue)
-{
-       u32 data;
-
-       /* Set the address */
-       writel(address, RCB_REG(IOBPIRI));
-
-       /* READ OPCODE */
-       if (pch_silicon_supported(PCH_TYPE_CPT, PCH_STEP_B0))
-               writel(IOBPS_RW_BX, RCB_REG(IOBPS));
-       else
-               writel(IOBPS_READ_AX, RCB_REG(IOBPS));
-       if (!iobp_poll())
-               return;
-
-       /* Read IOBP data */
-       data = readl(RCB_REG(IOBPD));
-       if (!iobp_poll())
-               return;
-
-       /* Check for successful transaction */
-       if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
-               printf("IOBP read 0x%08x failed\n", address);
-               return;
-       }
-
-       /* Update the data */
-       data &= andvalue;
-       data |= orvalue;
-
-       /* WRITE OPCODE */
-       if (pch_silicon_supported(PCH_TYPE_CPT, PCH_STEP_B0))
-               writel(IOBPS_RW_BX, RCB_REG(IOBPS));
-       else
-               writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
-       if (!iobp_poll())
-               return;
-
-       /* Write IOBP data */
-       writel(data, RCB_REG(IOBPD));
-       if (!iobp_poll())
-               return;
-}
diff --git a/arch/x86/cpu/ivybridge/pci.c b/arch/x86/cpu/ivybridge/pci.c
deleted file mode 100644 (file)
index 5e90f30..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- * (C) Copyright 2008,2009
- * Graeme Russ, <graeme.russ@gmail.com>
- *
- * (C) Copyright 2002
- * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <dm.h>
-#include <pci.h>
-#include <asm/pci.h>
-#include <asm/post.h>
-#include <asm/arch/bd82x6x.h>
-#include <asm/arch/pch.h>
-
-static int pci_ivybridge_probe(struct udevice *bus)
-{
-       struct pci_controller *hose = dev_get_uclass_priv(bus);
-       pci_dev_t dev;
-       u16 reg16;
-
-       if (!(gd->flags & GD_FLG_RELOC))
-               return 0;
-       post_code(0x50);
-       bd82x6x_init();
-       post_code(0x51);
-
-       reg16 = 0xff;
-       dev = PCH_DEV;
-       reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
-       reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
-       x86_pci_write_config16(dev, PCI_COMMAND, reg16);
-
-       /*
-       * Clear non-reserved bits in status register.
-       */
-       pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
-       pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
-       pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
-
-       pci_write_bar32(hose, dev, 0, 0xf0000000);
-       post_code(0x52);
-
-       return 0;
-}
-
-static const struct dm_pci_ops pci_ivybridge_ops = {
-       .read_config    = pci_x86_read_config,
-       .write_config   = pci_x86_write_config,
-};
-
-static const struct udevice_id pci_ivybridge_ids[] = {
-       { .compatible = "intel,pci-ivybridge" },
-       { }
-};
-
-U_BOOT_DRIVER(pci_ivybridge_drv) = {
-       .name           = "pci_ivybridge",
-       .id             = UCLASS_PCI,
-       .of_match       = pci_ivybridge_ids,
-       .ops            = &pci_ivybridge_ops,
-       .probe          = pci_ivybridge_probe,
-};
index 44938709c9bccc086a05ce376ad44d9a6c1d725a..c78322aef99b9a5a5bdf4fa5fd7c7a3fbd99911e 100644 (file)
@@ -10,6 +10,7 @@
 #include <asm/cpu.h>
 #include <asm/pci.h>
 #include <asm/arch/pch.h>
+#include <asm/arch/sandybridge.h>
 
 static void report_cpu_info(void)
 {
@@ -63,27 +64,27 @@ static struct {
        {0x1E5F, "NM70"},
 };
 
-static void report_pch_info(void)
+static void report_pch_info(struct udevice *dev)
 {
        const char *pch_type = "Unknown";
        int i;
        u16 dev_id;
        uint8_t rev_id;
 
-       dev_id = x86_pci_read_config16(PCH_LPC_DEV, 2);
+       dm_pci_read_config16(dev, 2, &dev_id);
        for (i = 0; i < ARRAY_SIZE(pch_table); i++) {
                if (pch_table[i].dev_id == dev_id) {
                        pch_type = pch_table[i].dev_name;
                        break;
                }
        }
-       rev_id = x86_pci_read_config8(PCH_LPC_DEV, 8);
+       dm_pci_read_config8(dev, 8, &rev_id);
        debug("PCH type: %s, device id: %x, rev id %x\n", pch_type, dev_id,
              rev_id);
 }
 
-void report_platform_info(void)
+void report_platform_info(struct udevice *dev)
 {
        report_cpu_info();
-       report_pch_info();
+       report_pch_info(dev);
 }
index e7bf03c1dc7913971b160b6d5f5d14700caf4ded..a59d9edce5f57edd2c4167404cc27247c68b1304 100644 (file)
@@ -6,48 +6,56 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <fdtdec.h>
 #include <asm/io.h>
 #include <asm/pci.h>
 #include <asm/arch/pch.h>
 #include <asm/arch/bd82x6x.h>
 
-static inline u32 sir_read(pci_dev_t dev, int idx)
+DECLARE_GLOBAL_DATA_PTR;
+
+static inline u32 sir_read(struct udevice *dev, int idx)
 {
-       x86_pci_write_config32(dev, SATA_SIRI, idx);
-       return x86_pci_read_config32(dev, SATA_SIRD);
+       u32 data;
+
+       dm_pci_write_config32(dev, SATA_SIRI, idx);
+       dm_pci_read_config32(dev, SATA_SIRD, &data);
+
+       return data;
 }
 
-static inline void sir_write(pci_dev_t dev, int idx, u32 value)
+static inline void sir_write(struct udevice *dev, int idx, u32 value)
 {
-       x86_pci_write_config32(dev, SATA_SIRI, idx);
-       x86_pci_write_config32(dev, SATA_SIRD, value);
+       dm_pci_write_config32(dev, SATA_SIRI, idx);
+       dm_pci_write_config32(dev, SATA_SIRD, value);
 }
 
-static void common_sata_init(pci_dev_t dev, unsigned int port_map)
+static void common_sata_init(struct udevice *dev, unsigned int port_map)
 {
        u32 reg32;
        u16 reg16;
 
        /* Set IDE I/O Configuration */
        reg32 = SIG_MODE_PRI_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
-       x86_pci_write_config32(dev, IDE_CONFIG, reg32);
+       dm_pci_write_config32(dev, IDE_CONFIG, reg32);
 
        /* Port enable */
-       reg16 = x86_pci_read_config16(dev, 0x92);
+       dm_pci_read_config16(dev, 0x92, &reg16);
        reg16 &= ~0x3f;
        reg16 |= port_map;
-       x86_pci_write_config16(dev, 0x92, reg16);
+       dm_pci_write_config16(dev, 0x92, reg16);
 
        /* SATA Initialization register */
        port_map &= 0xff;
-       x86_pci_write_config32(dev, 0x94, ((port_map ^ 0x3f) << 24) | 0x183);
+       dm_pci_write_config32(dev, 0x94, ((port_map ^ 0x3f) << 24) | 0x183);
 }
 
-void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node)
+static void bd82x6x_sata_init(struct udevice *dev, struct udevice *pch)
 {
        unsigned int port_map, speed_support, port_tx;
-       struct pci_controller *hose = pci_bus_to_hose(0);
+       const void *blob = gd->fdt_blob;
+       int node = dev->of_offset;
        const char *mode;
        u32 reg32;
        u16 reg16;
@@ -59,33 +67,27 @@ void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node)
        speed_support = fdtdec_get_int(blob, node,
                                       "sata_interface_speed_support", 0);
 
-       /* Enable BARs */
-       x86_pci_write_config16(dev, PCI_COMMAND, 0x0007);
-
        mode = fdt_getprop(blob, node, "intel,sata-mode", NULL);
        if (!mode || !strcmp(mode, "ahci")) {
                u32 abar;
 
                debug("SATA: Controller in AHCI mode\n");
 
-               /* Set Interrupt Line, Interrupt Pin is set by D31IP.PIP */
-               x86_pci_write_config8(dev, INTR_LN, 0x0a);
-
                /* Set timings */
-               x86_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
                                IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
                                IDE_PPE0 | IDE_IE0 | IDE_TIME0);
-               x86_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
                                IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
 
                /* Sync DMA */
-               x86_pci_write_config16(dev, IDE_SDMA_CNT, IDE_PSDE0);
-               x86_pci_write_config16(dev, IDE_SDMA_TIM, 0x0001);
+               dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_PSDE0);
+               dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0001);
 
                common_sata_init(dev, 0x8000 | port_map);
 
                /* Initialize AHCI memory-mapped space */
-               abar = pci_read_bar32(hose, dev, 5);
+               abar = dm_pci_read_bar32(dev, 5);
                debug("ABAR: %08X\n", abar);
                /* CAP (HBA Capabilities) : enable power management */
                reg32 = readl(abar + 0x00);
@@ -113,59 +115,54 @@ void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node)
                debug("SATA: Controller in combined mode\n");
 
                /* No AHCI: clear AHCI base */
-               pci_write_bar32(hose, dev, 5, 0x00000000);
+               dm_pci_write_bar32(dev, 5, 0x00000000);
                /* And without AHCI BAR no memory decoding */
-               reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
+               dm_pci_read_config16(dev, PCI_COMMAND, &reg16);
                reg16 &= ~PCI_COMMAND_MEMORY;
-               x86_pci_write_config16(dev, PCI_COMMAND, reg16);
+               dm_pci_write_config16(dev, PCI_COMMAND, reg16);
 
-               x86_pci_write_config8(dev, 0x09, 0x80);
+               dm_pci_write_config8(dev, 0x09, 0x80);
 
                /* Set timings */
-               x86_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
                                IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
-               x86_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
                                IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
                                IDE_PPE0 | IDE_IE0 | IDE_TIME0);
 
                /* Sync DMA */
-               x86_pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0);
-               x86_pci_write_config16(dev, IDE_SDMA_TIM, 0x0200);
+               dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0);
+               dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0200);
 
                common_sata_init(dev, port_map);
        } else {
                debug("SATA: Controller in plain-ide mode\n");
 
                /* No AHCI: clear AHCI base */
-               pci_write_bar32(hose, dev, 5, 0x00000000);
+               dm_pci_write_bar32(dev, 5, 0x00000000);
 
                /* And without AHCI BAR no memory decoding */
-               reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
+               dm_pci_read_config16(dev, PCI_COMMAND, &reg16);
                reg16 &= ~PCI_COMMAND_MEMORY;
-               x86_pci_write_config16(dev, PCI_COMMAND, reg16);
+               dm_pci_write_config16(dev, PCI_COMMAND, reg16);
 
                /*
                 * Native mode capable on both primary and secondary (0xa)
                 * OR'ed with enabled (0x50) = 0xf
                 */
-               x86_pci_write_config8(dev, 0x09, 0x8f);
-
-               /* Set Interrupt Line */
-               /* Interrupt Pin is set by D31IP.PIP */
-               x86_pci_write_config8(dev, INTR_LN, 0xff);
+               dm_pci_write_config8(dev, 0x09, 0x8f);
 
                /* Set timings */
-               x86_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
                                IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
                                IDE_PPE0 | IDE_IE0 | IDE_TIME0);
-               x86_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
+               dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
                                IDE_SITRE | IDE_ISP_3_CLOCKS |
                                IDE_RCT_1_CLOCKS | IDE_IE0 | IDE_TIME0);
 
                /* Sync DMA */
-               x86_pci_write_config16(dev, IDE_SDMA_CNT,
-                                      IDE_SSDE0 | IDE_PSDE0);
-               x86_pci_write_config16(dev, IDE_SDMA_TIM, 0x0201);
+               dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0 | IDE_PSDE0);
+               dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0201);
 
                common_sata_init(dev, port_map);
        }
@@ -173,11 +170,11 @@ void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node)
        /* Set Gen3 Transmitter settings if needed */
        port_tx = fdtdec_get_int(blob, node, "intel,sata-port0-gen3-tx", 0);
        if (port_tx)
-               pch_iobp_update(SATA_IOBP_SP0G3IR, 0, port_tx);
+               pch_iobp_update(pch, SATA_IOBP_SP0G3IR, 0, port_tx);
 
        port_tx = fdtdec_get_int(blob, node, "intel,sata-port1-gen3-tx", 0);
        if (port_tx)
-               pch_iobp_update(SATA_IOBP_SP1G3IR, 0, port_tx);
+               pch_iobp_update(pch, SATA_IOBP_SP1G3IR, 0, port_tx);
 
        /* Additional Programming Requirements */
        sir_write(dev, 0x04, 0x00001600);
@@ -202,12 +199,14 @@ void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node)
        sir_write(dev, 0xc8, 0x0c0c0c0c);
        sir_write(dev, 0xd4, 0x10000000);
 
-       pch_iobp_update(0xea004001, 0x3fffffff, 0xc0000000);
-       pch_iobp_update(0xea00408a, 0xfffffcff, 0x00000100);
+       pch_iobp_update(pch, 0xea004001, 0x3fffffff, 0xc0000000);
+       pch_iobp_update(pch, 0xea00408a, 0xfffffcff, 0x00000100);
 }
 
-void bd82x6x_sata_enable(pci_dev_t dev, const void *blob, int node)
+static void bd82x6x_sata_enable(struct udevice *dev)
 {
+       const void *blob = gd->fdt_blob;
+       int node = dev->of_offset;
        unsigned port_map;
        const char *mode;
        u16 map = 0;
@@ -222,5 +221,36 @@ void bd82x6x_sata_enable(pci_dev_t dev, const void *blob, int node)
        port_map = fdtdec_get_int(blob, node, "intel,sata-port-map", 0);
 
        map |= (port_map ^ 0x3f) << 8;
-       x86_pci_write_config16(dev, 0x90, map);
+       dm_pci_write_config16(dev, 0x90, map);
 }
+
+static int bd82x6x_sata_probe(struct udevice *dev)
+{
+       struct udevice *pch;
+       int ret;
+
+       ret = uclass_first_device(UCLASS_PCH, &pch);
+       if (ret)
+               return ret;
+       if (!pch)
+               return -ENODEV;
+
+       if (!(gd->flags & GD_FLG_RELOC))
+               bd82x6x_sata_enable(dev);
+       else
+               bd82x6x_sata_init(dev, pch);
+
+       return 0;
+}
+
+static const struct udevice_id bd82x6x_ahci_ids[] = {
+       { .compatible = "intel,pantherpoint-ahci" },
+       { }
+};
+
+U_BOOT_DRIVER(ahci_ivybridge_drv) = {
+       .name           = "ahci_ivybridge",
+       .id             = UCLASS_DISK,
+       .of_match       = bd82x6x_ahci_ids,
+       .probe          = bd82x6x_sata_probe,
+};
index 4372a5caf2d23e8942a078e580cef4014d37e530..e23c422cd0ada61ff55189c6bc6390f0afa32226 100644 (file)
@@ -18,6 +18,8 @@
 #include <rtc.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <syscon.h>
+#include <asm/cpu.h>
 #include <asm/processor.h>
 #include <asm/gpio.h>
 #include <asm/global_data.h>
@@ -283,22 +285,24 @@ static int recovery_mode_enabled(void)
 /**
  * Find the PEI executable in the ROM and execute it.
  *
- * @param pei_data: configuration data for UEFI PEI reference code
+ * @dev: Northbridge device
+ * @pei_data: configuration data for UEFI PEI reference code
  */
-int sdram_initialise(struct pei_data *pei_data)
+int sdram_initialise(struct udevice *dev, struct udevice *me_dev,
+                    struct pei_data *pei_data)
 {
        unsigned version;
        const char *data;
        uint16_t done;
        int ret;
 
-       report_platform_info();
+       report_platform_info(dev);
 
        /* Wait for ME to be ready */
-       ret = intel_early_me_init();
+       ret = intel_early_me_init(me_dev);
        if (ret)
                return ret;
-       ret = intel_early_me_uma_size();
+       ret = intel_early_me_uma_size(me_dev);
        if (ret < 0)
                return ret;
 
@@ -374,12 +378,12 @@ int sdram_initialise(struct pei_data *pei_data)
         * Send ME init done for SandyBridge here.  This is done inside the
         * SystemAgent binary on IvyBridge
         */
-       done = x86_pci_read_config32(PCH_DEV, PCI_DEVICE_ID);
+       dm_pci_read_config16(dev, PCI_DEVICE_ID, &done);
        done &= BASE_REV_MASK;
        if (BASE_REV_SNB == done)
-               intel_early_me_init_done(ME_INIT_STATUS_SUCCESS);
+               intel_early_me_init_done(dev, me_dev, ME_INIT_STATUS_SUCCESS);
        else
-               intel_early_me_status();
+               intel_early_me_status(me_dev);
 
        post_system_agent_init(pei_data);
        report_memory_config();
@@ -495,8 +499,10 @@ static int add_memory_area(struct memory_info *info,
  *
  * This is a bit complicated since on x86 there are system memory holes all
  * over the place. We create a list of available memory blocks
+ *
+ * @dev:       Northbridge device
  */
-static int sdram_find(pci_dev_t dev)
+static int sdram_find(struct udevice *dev)
 {
        struct memory_info *info = &gd->arch.meminfo;
        uint32_t tseg_base, uma_size, tolud;
@@ -505,6 +511,7 @@ static int sdram_find(pci_dev_t dev)
        uint64_t uma_memory_size;
        unsigned long long tomk;
        uint16_t ggc;
+       u32 val;
 
        /* Total Memory 2GB example:
         *
@@ -533,24 +540,27 @@ static int sdram_find(pci_dev_t dev)
         */
 
        /* Top of Upper Usable DRAM, including remap */
-       touud = x86_pci_read_config32(dev, TOUUD+4);
-       touud <<= 32;
-       touud |= x86_pci_read_config32(dev, TOUUD);
+       dm_pci_read_config32(dev, TOUUD + 4, &val);
+       touud = (uint64_t)val << 32;
+       dm_pci_read_config32(dev, TOUUD, &val);
+       touud |= val;
 
        /* Top of Lower Usable DRAM */
-       tolud = x86_pci_read_config32(dev, TOLUD);
+       dm_pci_read_config32(dev, TOLUD, &tolud);
 
        /* Top of Memory - does not account for any UMA */
-       tom = x86_pci_read_config32(dev, 0xa4);
-       tom <<= 32;
-       tom |= x86_pci_read_config32(dev, 0xa0);
+       dm_pci_read_config32(dev, 0xa4, &val);
+       tom = (uint64_t)val << 32;
+       dm_pci_read_config32(dev, 0xa0, &val);
+       tom |= val;
 
        debug("TOUUD %llx TOLUD %08x TOM %llx\n", touud, tolud, tom);
 
        /* ME UMA needs excluding if total memory <4GB */
-       me_base = x86_pci_read_config32(dev, 0x74);
-       me_base <<= 32;
-       me_base |= x86_pci_read_config32(dev, 0x70);
+       dm_pci_read_config32(dev, 0x74, &val);
+       me_base = (uint64_t)val << 32;
+       dm_pci_read_config32(dev, 0x70, &val);
+       me_base |= val;
 
        debug("MEBASE %llx\n", me_base);
 
@@ -568,7 +578,7 @@ static int sdram_find(pci_dev_t dev)
        }
 
        /* Graphics memory comes next */
-       ggc = x86_pci_read_config16(dev, GGC);
+       dm_pci_read_config16(dev, GGC, &ggc);
        if (!(ggc & 2)) {
                debug("IGD decoded, subtracting ");
 
@@ -588,7 +598,7 @@ static int sdram_find(pci_dev_t dev)
        }
 
        /* Calculate TSEG size from its base which must be below GTT */
-       tseg_base = x86_pci_read_config32(dev, 0xb8);
+       dm_pci_read_config32(dev, 0xb8, &tseg_base);
        uma_size = (uma_memory_base - tseg_base) >> 10;
        tomk -= uma_size;
        uma_memory_base = tomk * 1024ULL;
@@ -723,15 +733,23 @@ int dram_init(void)
                        { 0, 4, 0x0000 }, /* P13= Empty */
                },
        };
-       pci_dev_t dev = PCI_BDF(0, 0, 0);
+       struct udevice *dev, *me_dev;
        int ret;
 
+       ret = uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
+       if (ret)
+               return ret;
+       if (!dev)
+               return -ENODEV;
+       ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev);
+       if (ret)
+               return ret;
        debug("Boot mode %d\n", gd->arch.pei_boot_mode);
        debug("mrc_input %p\n", pei_data.mrc_input);
        pei_data.boot_mode = gd->arch.pei_boot_mode;
        ret = copy_spd(&pei_data);
        if (!ret)
-               ret = sdram_initialise(&pei_data);
+               ret = sdram_initialise(dev, me_dev, &pei_data);
        if (ret)
                return ret;
 
diff --git a/arch/x86/cpu/ivybridge/usb_ehci.c b/arch/x86/cpu/ivybridge/usb_ehci.c
deleted file mode 100644 (file)
index da11aee..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * From Coreboot
- * Copyright (C) 2008-2009 coresystems GmbH
- *
- * SPDX-License-Identifier:    GPL-2.0
- */
-
-#include <common.h>
-#include <asm/io.h>
-#include <asm/pci.h>
-#include <asm/arch/pch.h>
-
-void bd82x6x_usb_ehci_init(pci_dev_t dev)
-{
-       u32 reg32;
-
-       /* Disable Wake on Disconnect in RMH */
-       reg32 = readl(RCB_REG(0x35b0));
-       reg32 |= 0x22;
-       writel(reg32, RCB_REG(0x35b0));
-
-       debug("EHCI: Setting up controller.. ");
-       reg32 = x86_pci_read_config32(dev, PCI_COMMAND);
-       reg32 |= PCI_COMMAND_MASTER;
-       /* reg32 |= PCI_COMMAND_SERR; */
-       x86_pci_write_config32(dev, PCI_COMMAND, reg32);
-
-       debug("done.\n");
-}
diff --git a/arch/x86/cpu/ivybridge/usb_xhci.c b/arch/x86/cpu/ivybridge/usb_xhci.c
deleted file mode 100644 (file)
index f77b804..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * From Coreboot
- * Copyright (C) 2008-2009 coresystems GmbH
- *
- * SPDX-License-Identifier:    GPL-2.0
- */
-
-#include <common.h>
-#include <asm/pci.h>
-#include <asm/arch/pch.h>
-
-void bd82x6x_usb_xhci_init(pci_dev_t dev)
-{
-       u32 reg32;
-
-       debug("XHCI: Setting up controller.. ");
-
-       /* lock overcurrent map */
-       reg32 = x86_pci_read_config32(dev, 0x44);
-       reg32 |= 1;
-       x86_pci_write_config32(dev, 0x44, reg32);
-
-       /* Enable clock gating */
-       reg32 = x86_pci_read_config32(dev, 0x40);
-       reg32 &= ~((1 << 20) | (1 << 21));
-       reg32 |= (1 << 19) | (1 << 18) | (1 << 17);
-       reg32 |= (1 << 10) | (1 << 9) | (1 << 8);
-       reg32 |= (1 << 31); /* lock */
-       x86_pci_write_config32(dev, 0x40, reg32);
-
-       debug("done.\n");
-}
index 46111c9cf058d82d35bf231c26d832f8d101bd15..5a7b92944a21501edd10b99824cb2eab337e0da1 100644 (file)
@@ -96,11 +96,6 @@ int arch_early_init_r(void)
        return 0;
 }
 
-int arch_misc_init(void)
-{
-       return pirq_init();
-}
-
 #ifdef CONFIG_GENERATE_MP_TABLE
 int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
 {
index 8f1d018fb60841d700939a42d5f46298be443fa9..6d670d75c102443d1062dd01609bc667d1587f82 100644 (file)
@@ -4,5 +4,5 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
-obj-y += car.o dram.o msg_port.o quark.o
+obj-y += car.o dram.o irq.o msg_port.o quark.o
 obj-y += mrc.o mrc_util.o hte.o smc.o
diff --git a/arch/x86/cpu/quark/irq.c b/arch/x86/cpu/quark/irq.c
new file mode 100644 (file)
index 0000000..1f8f909
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
+ * Copyright (C) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/irq.h>
+#include <asm/arch/device.h>
+#include <asm/arch/quark.h>
+
+int quark_irq_router_probe(struct udevice *dev)
+{
+       struct quark_rcba *rcba;
+       u32 base;
+
+       qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
+       base &= ~MEM_BAR_EN;
+       rcba = (struct quark_rcba *)base;
+
+       /*
+        * Route Quark PCI device interrupt pin to PIRQ
+        *
+        * Route device#23's INTA/B/C/D to PIRQA/B/C/D
+        * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
+        */
+       writew(PIRQC, &rcba->rmu_ir);
+       writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
+              &rcba->d23_ir);
+       writew(PIRQD, &rcba->core_ir);
+       writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
+              &rcba->d20d21_ir);
+
+       return irq_router_common_init(dev);
+}
+
+static const struct udevice_id quark_irq_router_ids[] = {
+       { .compatible = "intel,quark-irq-router" },
+       { }
+};
+
+U_BOOT_DRIVER(quark_irq_router_drv) = {
+       .name           = "quark_intel_irq",
+       .id             = UCLASS_IRQ,
+       .of_match       = quark_irq_router_ids,
+       .probe          = quark_irq_router_probe,
+};
index 72c681dceabaece9c81d1983199d31cdcf9fca1d..6e20930a4d21940c1311d32d12a68c1cf3a236a1 100644 (file)
@@ -7,12 +7,10 @@
 #include <common.h>
 #include <mmc.h>
 #include <asm/io.h>
-#include <asm/irq.h>
 #include <asm/mrccache.h>
 #include <asm/mtrr.h>
 #include <asm/pci.h>
 #include <asm/post.h>
-#include <asm/processor.h>
 #include <asm/arch/device.h>
 #include <asm/arch/msg_port.h>
 #include <asm/arch/quark.h>
@@ -346,29 +344,6 @@ int cpu_mmc_init(bd_t *bis)
        return pci_mmc_init("Quark SDHCI", mmc_supported);
 }
 
-void cpu_irq_init(void)
-{
-       struct quark_rcba *rcba;
-       u32 base;
-
-       qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
-       base &= ~MEM_BAR_EN;
-       rcba = (struct quark_rcba *)base;
-
-       /*
-        * Route Quark PCI device interrupt pin to PIRQ
-        *
-        * Route device#23's INTA/B/C/D to PIRQA/B/C/D
-        * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
-        */
-       writew(PIRQC, &rcba->rmu_ir);
-       writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
-              &rcba->d23_ir);
-       writew(PIRQD, &rcba->core_ir);
-       writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
-              &rcba->d20d21_ir);
-}
-
 int arch_misc_init(void)
 {
 #ifdef CONFIG_ENABLE_MRC_CACHE
@@ -380,7 +355,7 @@ int arch_misc_init(void)
        mrccache_save();
 #endif
 
-       return pirq_init();
+       return 0;
 }
 
 void board_final_cleanup(void)
index 660f9678bd303573ef506986f913382c4377e002..af3ffad385222ffb8ecafaca28d71d3b13eaba0e 100644 (file)
@@ -4,5 +4,5 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
-obj-y += fsp_configs.o
+obj-y += fsp_configs.o irq.o
 obj-y += tnc.o topcliff.o
diff --git a/arch/x86/cpu/queensbay/irq.c b/arch/x86/cpu/queensbay/irq.c
new file mode 100644 (file)
index 0000000..44369f7
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
+ * Copyright (C) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/pci.h>
+#include <asm/arch/device.h>
+#include <asm/arch/tnc.h>
+
+int queensbay_irq_router_probe(struct udevice *dev)
+{
+       struct tnc_rcba *rcba;
+       u32 base;
+
+       base = x86_pci_read_config32(TNC_LPC, LPC_RCBA);
+       base &= ~MEM_BAR_EN;
+       rcba = (struct tnc_rcba *)base;
+
+       /* Make sure all internal PCI devices are using INTA */
+       writel(INTA, &rcba->d02ip);
+       writel(INTA, &rcba->d03ip);
+       writel(INTA, &rcba->d27ip);
+       writel(INTA, &rcba->d31ip);
+       writel(INTA, &rcba->d23ip);
+       writel(INTA, &rcba->d24ip);
+       writel(INTA, &rcba->d25ip);
+       writel(INTA, &rcba->d26ip);
+
+       /*
+        * Route TunnelCreek PCI device interrupt pin to PIRQ
+        *
+        * Since PCIe downstream ports received INTx are routed to PIRQ
+        * A/B/C/D directly and not configurable, we have to route PCIe
+        * root ports' INTx to PIRQ A/B/C/D as well. For other devices
+        * on TunneCreek, route them to PIRQ E/F/G/H.
+        */
+       writew(PIRQE, &rcba->d02ir);
+       writew(PIRQF, &rcba->d03ir);
+       writew(PIRQG, &rcba->d27ir);
+       writew(PIRQH, &rcba->d31ir);
+       writew(PIRQA, &rcba->d23ir);
+       writew(PIRQB, &rcba->d24ir);
+       writew(PIRQC, &rcba->d25ir);
+       writew(PIRQD, &rcba->d26ir);
+
+       return irq_router_common_init(dev);
+}
+
+static const struct udevice_id queensbay_irq_router_ids[] = {
+       { .compatible = "intel,queensbay-irq-router" },
+       { }
+};
+
+U_BOOT_DRIVER(queensbay_irq_router_drv) = {
+       .name           = "queensbay_intel_irq",
+       .id             = UCLASS_IRQ,
+       .of_match       = queensbay_irq_router_ids,
+       .probe          = queensbay_irq_router_probe,
+};
index fb81919c212fa2d678d2b17a4d3a6f94ce7264b8..75f7adb74cd622603c595cd228930a09a45e01f8 100644 (file)
@@ -69,46 +69,9 @@ int arch_early_init_r(void)
        return 0;
 }
 
-void cpu_irq_init(void)
-{
-       struct tnc_rcba *rcba;
-       u32 base;
-
-       base = x86_pci_read_config32(TNC_LPC, LPC_RCBA);
-       base &= ~MEM_BAR_EN;
-       rcba = (struct tnc_rcba *)base;
-
-       /* Make sure all internal PCI devices are using INTA */
-       writel(INTA, &rcba->d02ip);
-       writel(INTA, &rcba->d03ip);
-       writel(INTA, &rcba->d27ip);
-       writel(INTA, &rcba->d31ip);
-       writel(INTA, &rcba->d23ip);
-       writel(INTA, &rcba->d24ip);
-       writel(INTA, &rcba->d25ip);
-       writel(INTA, &rcba->d26ip);
-
-       /*
-        * Route TunnelCreek PCI device interrupt pin to PIRQ
-        *
-        * Since PCIe downstream ports received INTx are routed to PIRQ
-        * A/B/C/D directly and not configurable, we have to route PCIe
-        * root ports' INTx to PIRQ A/B/C/D as well. For other devices
-        * on TunneCreek, route them to PIRQ E/F/G/H.
-        */
-       writew(PIRQE, &rcba->d02ir);
-       writew(PIRQF, &rcba->d03ir);
-       writew(PIRQG, &rcba->d27ir);
-       writew(PIRQH, &rcba->d31ir);
-       writew(PIRQA, &rcba->d23ir);
-       writew(PIRQB, &rcba->d24ir);
-       writew(PIRQC, &rcba->d25ir);
-       writew(PIRQD, &rcba->d26ir);
-}
-
 int arch_misc_init(void)
 {
        unprotect_spi_flash();
 
-       return pirq_init();
+       return 0;
 }
index d3380dee6ccc4cd9244bd216a1c9b70baf4cb42a..9bf707bf0e84bdd43c05d7f97d8fbafddcd2b5d7 100644 (file)
                };
        };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       #address-cells = <1>;
-                       #size-cells = <1>;
-                       reg = <0>;
-                       compatible = "winbond,w25q64dw", "spi-flash";
-                       memory-map = <0xff800000 0x00800000>;
-                       rw-mrc-cache {
-                               label = "rw-mrc-cache";
-                               reg = <0x006e0000 0x00010000>;
-                       };
-               };
-       };
-
        gpioa {
                compatible = "intel,ich6-gpio";
                u-boot,dm-pre-reloc;
                          0x42000000 0x0 0xc0000000 0xc0000000 0 0x20000000
                          0x01000000 0x0 0x2000 0x2000 0 0xe000>;
 
-               irq-router@1f,0 {
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "ibase";
-                       intel,ibase-offset = <0x50>;
-                       intel,pirq-link = <8 8>;
-                       intel,pirq-mask = <0xdee0>;
-                       intel,pirq-routing = <
-                               /* BayTrail PCI devices */
-                               PCI_BDF(0, 2, 0) INTA PIRQA
-                               PCI_BDF(0, 3, 0) INTA PIRQA
-                               PCI_BDF(0, 16, 0) INTA PIRQA
-                               PCI_BDF(0, 17, 0) INTA PIRQA
-                               PCI_BDF(0, 18, 0) INTA PIRQA
-                               PCI_BDF(0, 19, 0) INTA PIRQA
-                               PCI_BDF(0, 20, 0) INTA PIRQA
-                               PCI_BDF(0, 21, 0) INTA PIRQA
-                               PCI_BDF(0, 22, 0) INTA PIRQA
-                               PCI_BDF(0, 23, 0) INTA PIRQA
-                               PCI_BDF(0, 24, 0) INTA PIRQA
-                               PCI_BDF(0, 24, 1) INTC PIRQC
-                               PCI_BDF(0, 24, 2) INTD PIRQD
-                               PCI_BDF(0, 24, 3) INTB PIRQB
-                               PCI_BDF(0, 24, 4) INTA PIRQA
-                               PCI_BDF(0, 24, 5) INTC PIRQC
-                               PCI_BDF(0, 24, 6) INTD PIRQD
-                               PCI_BDF(0, 24, 7) INTB PIRQB
-                               PCI_BDF(0, 26, 0) INTA PIRQA
-                               PCI_BDF(0, 27, 0) INTA PIRQA
-                               PCI_BDF(0, 28, 0) INTA PIRQA
-                               PCI_BDF(0, 28, 1) INTB PIRQB
-                               PCI_BDF(0, 28, 2) INTC PIRQC
-                               PCI_BDF(0, 28, 3) INTD PIRQD
-                               PCI_BDF(0, 29, 0) INTA PIRQA
-                               PCI_BDF(0, 30, 0) INTA PIRQA
-                               PCI_BDF(0, 30, 1) INTD PIRQD
-                               PCI_BDF(0, 30, 2) INTB PIRQB
-                               PCI_BDF(0, 30, 3) INTC PIRQC
-                               PCI_BDF(0, 30, 4) INTD PIRQD
-                               PCI_BDF(0, 30, 5) INTB PIRQB
-                               PCI_BDF(0, 31, 3) INTB PIRQB
-
-                               /* PCIe root ports downstream interrupts */
-                               PCI_BDF(1, 0, 0) INTA PIRQA
-                               PCI_BDF(1, 0, 0) INTB PIRQB
-                               PCI_BDF(1, 0, 0) INTC PIRQC
-                               PCI_BDF(1, 0, 0) INTD PIRQD
-                               PCI_BDF(2, 0, 0) INTA PIRQB
-                               PCI_BDF(2, 0, 0) INTB PIRQC
-                               PCI_BDF(2, 0, 0) INTC PIRQD
-                               PCI_BDF(2, 0, 0) INTD PIRQA
-                               PCI_BDF(3, 0, 0) INTA PIRQC
-                               PCI_BDF(3, 0, 0) INTB PIRQD
-                               PCI_BDF(3, 0, 0) INTC PIRQA
-                               PCI_BDF(3, 0, 0) INTD PIRQB
-                               PCI_BDF(4, 0, 0) INTA PIRQD
-                               PCI_BDF(4, 0, 0) INTB PIRQA
-                               PCI_BDF(4, 0, 0) INTC PIRQB
-                               PCI_BDF(4, 0, 0) INTD PIRQC
-                       >;
+                       compatible = "intel,pch9";
+
+                       irq-router {
+                               compatible = "intel,irq-router";
+                               intel,pirq-config = "ibase";
+                               intel,ibase-offset = <0x50>;
+                               intel,pirq-link = <8 8>;
+                               intel,pirq-mask = <0xdee0>;
+                               intel,pirq-routing = <
+                                       /* BayTrail PCI devices */
+                                       PCI_BDF(0, 2, 0) INTA PIRQA
+                                       PCI_BDF(0, 3, 0) INTA PIRQA
+                                       PCI_BDF(0, 16, 0) INTA PIRQA
+                                       PCI_BDF(0, 17, 0) INTA PIRQA
+                                       PCI_BDF(0, 18, 0) INTA PIRQA
+                                       PCI_BDF(0, 19, 0) INTA PIRQA
+                                       PCI_BDF(0, 20, 0) INTA PIRQA
+                                       PCI_BDF(0, 21, 0) INTA PIRQA
+                                       PCI_BDF(0, 22, 0) INTA PIRQA
+                                       PCI_BDF(0, 23, 0) INTA PIRQA
+                                       PCI_BDF(0, 24, 0) INTA PIRQA
+                                       PCI_BDF(0, 24, 1) INTC PIRQC
+                                       PCI_BDF(0, 24, 2) INTD PIRQD
+                                       PCI_BDF(0, 24, 3) INTB PIRQB
+                                       PCI_BDF(0, 24, 4) INTA PIRQA
+                                       PCI_BDF(0, 24, 5) INTC PIRQC
+                                       PCI_BDF(0, 24, 6) INTD PIRQD
+                                       PCI_BDF(0, 24, 7) INTB PIRQB
+                                       PCI_BDF(0, 26, 0) INTA PIRQA
+                                       PCI_BDF(0, 27, 0) INTA PIRQA
+                                       PCI_BDF(0, 28, 0) INTA PIRQA
+                                       PCI_BDF(0, 28, 1) INTB PIRQB
+                                       PCI_BDF(0, 28, 2) INTC PIRQC
+                                       PCI_BDF(0, 28, 3) INTD PIRQD
+                                       PCI_BDF(0, 29, 0) INTA PIRQA
+                                       PCI_BDF(0, 30, 0) INTA PIRQA
+                                       PCI_BDF(0, 30, 1) INTD PIRQD
+                                       PCI_BDF(0, 30, 2) INTB PIRQB
+                                       PCI_BDF(0, 30, 3) INTC PIRQC
+                                       PCI_BDF(0, 30, 4) INTD PIRQD
+                                       PCI_BDF(0, 30, 5) INTB PIRQB
+                                       PCI_BDF(0, 31, 3) INTB PIRQB
+
+                                       /*
+                                        * PCIe root ports downstream
+                                        * interrupts
+                                        */
+                                       PCI_BDF(1, 0, 0) INTA PIRQA
+                                       PCI_BDF(1, 0, 0) INTB PIRQB
+                                       PCI_BDF(1, 0, 0) INTC PIRQC
+                                       PCI_BDF(1, 0, 0) INTD PIRQD
+                                       PCI_BDF(2, 0, 0) INTA PIRQB
+                                       PCI_BDF(2, 0, 0) INTB PIRQC
+                                       PCI_BDF(2, 0, 0) INTC PIRQD
+                                       PCI_BDF(2, 0, 0) INTD PIRQA
+                                       PCI_BDF(3, 0, 0) INTA PIRQC
+                                       PCI_BDF(3, 0, 0) INTB PIRQD
+                                       PCI_BDF(3, 0, 0) INTC PIRQA
+                                       PCI_BDF(3, 0, 0) INTD PIRQB
+                                       PCI_BDF(4, 0, 0) INTA PIRQD
+                                       PCI_BDF(4, 0, 0) INTB PIRQA
+                                       PCI_BDF(4, 0, 0) INTC PIRQB
+                                       PCI_BDF(4, 0, 0) INTD PIRQC
+                               >;
+                       };
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       #address-cells = <1>;
+                                       #size-cells = <1>;
+                                       reg = <0>;
+                                       compatible = "winbond,w25q64dw",
+                                               "spi-flash";
+                                       memory-map = <0xff800000 0x00800000>;
+                                       rw-mrc-cache {
+                                               label = "rw-mrc-cache";
+                                               reg = <0x006e0000 0x00010000>;
+                                       };
+                               };
+                       };
                };
        };
 
index 194f0ebcda4b9995d43bb697641eb3c31c7a6413..4e9e410b706aac85ea31ad99e4f28904bc6a64f7 100644 (file)
                ranges = <0x02000000 0x0 0xe0000000 0xe0000000 0 0x10000000
                        0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000
                        0x01000000 0x0 0x2000 0x2000 0 0xe000>;
-       };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       reg = <0>;
-                       compatible = "winbond,w25q128", "spi-flash";
-                       memory-map = <0xff000000 0x01000000>;
+               pch@1f,0 {
+                       reg = <0x0000f800 0 0 0 0>;
+                       compatible = "intel,pch9";
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       reg = <0>;
+                                       compatible = "winbond,w25q128", "spi-flash";
+                                       memory-map = <0xff000000 0x01000000>;
+                               };
+                       };
                };
        };
+
 };
index c4469a97683d705fd303893144e4b7fa02ffc3f1..d148d6e349cd87f0d8c06395834aca3f52909e5e 100644 (file)
 
        aliases {
                spi0 = "/pci/pch/spi";
+               usb0 = &usb_0;
+               usb1 = &usb_1;
        };
 
        config {
               silent_console = <0>;
        };
 
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               cpu@0 {
+                       device_type = "cpu";
+                       compatible = "intel,core-gen3";
+                       reg = <0>;
+                       intel,apic-id = <0>;
+               };
+
+               cpu@1 {
+                       device_type = "cpu";
+                       compatible = "intel,core-gen3";
+                       reg = <1>;
+                       intel,apic-id = <1>;
+               };
+
+               cpu@2 {
+                       device_type = "cpu";
+                       compatible = "intel,core-gen3";
+                       reg = <2>;
+                       intel,apic-id = <2>;
+               };
+
+               cpu@3 {
+                       device_type = "cpu";
+                       compatible = "intel,core-gen3";
+                       reg = <3>;
+                       intel,apic-id = <3>;
+               };
+
+       };
+
        gpioa {
                compatible = "intel,ich6-gpio";
                u-boot,dm-pre-reloc;
        };
 
        pci {
-               compatible = "intel,pci-ivybridge", "pci-x86";
+               compatible = "pci-x86";
                #address-cells = <3>;
                #size-cells = <2>;
                u-boot,dm-pre-reloc;
                ranges = <0x02000000 0x0 0xe0000000 0xe0000000 0 0x10000000
                        0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000
                        0x01000000 0x0 0x1000 0x1000 0 0xefff>;
-               sata {
-                       compatible = "intel,pantherpoint-ahci";
-                       intel,sata-mode = "ahci";
-                       intel,sata-port-map = <1>;
-                       intel,sata-port0-gen3-tx = <0x00880a7f>;
+
+               northbridge@0,0 {
+                       reg = <0x00000000 0 0 0 0>;
+                       compatible = "intel,bd82x6x-northbridge";
+                       u-boot,dm-pre-reloc;
                };
 
-               gma {
+               gma@2,0 {
+                       reg = <0x00001000 0 0 0 0>;
                        compatible = "intel,gma";
                        intel,dp_hotplug = <0 0 0x06>;
                        intel,panel-port-select = <1>;
                        intel,pch-backlight = <0x04000000>;
                };
 
-               pch {
+               me@16,0 {
+                       reg = <0x0000b000 0 0 0 0>;
+                       compatible = "intel,me";
+                       u-boot,dm-pre-reloc;
+               };
+
+               usb_1: usb@1a,0 {
+                       reg = <0x0000d000 0 0 0 0>;
+                       compatible = "ehci-pci";
+               };
+
+               usb_0: usb@1d,0 {
+                       reg = <0x0000e800 0 0 0 0>;
+                       compatible = "ehci-pci";
+               };
+
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,bd82x6x", "intel,pch";
+                       compatible = "intel,bd82x6x", "intel,pch9";
                        u-boot,dm-pre-reloc;
                        #address-cells = <1>;
                        #size-cells = <1>;
-                       gen-dec = <0x800 0xfc 0x900 0xfc>;
-                       intel,gen-dec = <0x800 0xfc 0x900 0xfc>;
                        intel,pirq-routing = <0x8b 0x8a 0x8b 0x8b
                                                0x80 0x80 0x80 0x80>;
                        intel,gpi-routing = <0 0 0 0 0 0 0 2
                                                1 0 0 0 0 0 0 0>;
                        /* Enable EC SMI source */
                        intel,alt-gp-smi-enable = <0x0100>;
+
                        spi {
                                #address-cells = <1>;
                                #size-cells = <0>;
                                compatible = "intel,bd82x6x-lpc";
                                #address-cells = <1>;
                                #size-cells = <0>;
+                               u-boot,dm-pre-reloc;
+                               intel,gen-dec = <0x800 0xfc 0x900 0xfc>;
                                cros-ec@200 {
                                        compatible = "google,cros-ec";
                                        reg = <0x204 1 0x200 1 0x880 0x80>;
                                };
                        };
                };
+
+               sata@1f,2 {
+                       compatible = "intel,pantherpoint-ahci";
+                       reg = <0x0000fa00 0 0 0 0>;
+                       u-boot,dm-pre-reloc;
+                       intel,sata-mode = "ahci";
+                       intel,sata-port-map = <1>;
+                       intel,sata-port0-gen3-tx = <0x00880a7f>;
+               };
+
+               smbus: smbus@1f,3 {
+                       compatible = "intel,ich-i2c";
+                       reg = <0x0000fb00 0 0 0 0>;
+                       u-boot,dm-pre-reloc;
+               };
        };
 
        tpm {
index 4e2b51708b1915cc0f1a2bfe90ce8c5869bc2301..23027016e5746a51768974a2629f06ea906ceecc 100644 (file)
                ranges = <0x02000000 0x0 0xe0000000 0xe0000000 0 0x10000000
                        0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000
                        0x01000000 0x0 0x1000 0x1000 0 0xf000>;
-       };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       #size-cells = <1>;
-                       #address-cells = <1>;
-                       reg = <0>;
-                       compatible = "winbond,w25q64", "spi-flash";
-                       memory-map = <0xff800000 0x00800000>;
-                       rw-mrc-cache {
-                               label = "rw-mrc-cache";
-                               reg = <0x003e0000 0x00010000>;
+               pch@1f,0 {
+                       reg = <0x0000f800 0 0 0 0>;
+                       compatible = "intel,pch9";
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       #size-cells = <1>;
+                                       #address-cells = <1>;
+                                       reg = <0>;
+                                       compatible = "winbond,w25q64",
+                                               "spi-flash";
+                                       memory-map = <0xff800000 0x00800000>;
+                                       rw-mrc-cache {
+                                               label = "rw-mrc-cache";
+                                               reg = <0x003e0000 0x00010000>;
+                                       };
+                               };
                        };
                };
        };
index 84231b37783ea673c43b752e2bd285cd7e22ac0c..d6dd0b49f0fac3a64f9ec4192c3a2ed431d2610f 100644 (file)
                stdout-path = "/serial";
        };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       reg = <0>;
-                       compatible = "sst,25vf016b", "spi-flash";
-                       memory-map = <0xffe00000 0x00200000>;
-               };
-       };
-
        microcode {
                update@0 {
 #include "microcode/m0220661105_cv.dtsi"
                        };
                };
 
-               irq-router@1f,0 {
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "pci";
-                       intel,pirq-link = <0x60 8>;
-                       intel,pirq-mask = <0xcee0>;
-                       intel,pirq-routing = <
-                               /* TunnelCreek PCI devices */
-                               PCI_BDF(0, 2, 0) INTA PIRQE
-                               PCI_BDF(0, 3, 0) INTA PIRQF
-                               PCI_BDF(0, 23, 0) INTA PIRQA
-                               PCI_BDF(0, 23, 0) INTB PIRQB
-                               PCI_BDF(0, 23, 0) INTC PIRQC
-                               PCI_BDF(0, 23, 0) INTD PIRQD
-                               PCI_BDF(0, 24, 0) INTA PIRQB
-                               PCI_BDF(0, 24, 0) INTB PIRQC
-                               PCI_BDF(0, 24, 0) INTC PIRQD
-                               PCI_BDF(0, 24, 0) INTD PIRQA
-                               PCI_BDF(0, 25, 0) INTA PIRQC
-                               PCI_BDF(0, 25, 0) INTB PIRQD
-                               PCI_BDF(0, 25, 0) INTC PIRQA
-                               PCI_BDF(0, 25, 0) INTD PIRQB
-                               PCI_BDF(0, 26, 0) INTA PIRQD
-                               PCI_BDF(0, 26, 0) INTB PIRQA
-                               PCI_BDF(0, 26, 0) INTC PIRQB
-                               PCI_BDF(0, 26, 0) INTD PIRQC
-                               PCI_BDF(0, 27, 0) INTA PIRQG
-                               /*
-                                * Topcliff PCI devices
-                                *
-                                * Note on the Crown Bay board, Topcliff chipset
-                                * is connected to TunnelCreek PCIe port 0, so
-                                * its bus number is 1 for its PCIe port and 2
-                                * for its PCI devices per U-Boot current PCI
-                                * bus enumeration algorithm.
-                                */
-                               PCI_BDF(1, 0, 0) INTA PIRQA
-                               PCI_BDF(2, 0, 1) INTA PIRQA
-                               PCI_BDF(2, 0, 2) INTA PIRQA
-                               PCI_BDF(2, 2, 0) INTB PIRQD
-                               PCI_BDF(2, 2, 1) INTB PIRQD
-                               PCI_BDF(2, 2, 2) INTB PIRQD
-                               PCI_BDF(2, 2, 3) INTB PIRQD
-                               PCI_BDF(2, 2, 4) INTB PIRQD
-                               PCI_BDF(2, 4, 0) INTC PIRQC
-                               PCI_BDF(2, 4, 1) INTC PIRQC
-                               PCI_BDF(2, 6, 0) INTD PIRQB
-                               PCI_BDF(2, 8, 0) INTA PIRQA
-                               PCI_BDF(2, 8, 1) INTA PIRQA
-                               PCI_BDF(2, 8, 2) INTA PIRQA
-                               PCI_BDF(2, 8, 3) INTA PIRQA
-                               PCI_BDF(2, 10, 0) INTB PIRQD
-                               PCI_BDF(2, 10, 1) INTB PIRQD
-                               PCI_BDF(2, 10, 2) INTB PIRQD
-                               PCI_BDF(2, 10, 3) INTB PIRQD
-                               PCI_BDF(2, 10, 4) INTB PIRQD
-                               PCI_BDF(2, 12, 0) INTC PIRQC
-                               PCI_BDF(2, 12, 1) INTC PIRQC
-                               PCI_BDF(2, 12, 2) INTC PIRQC
-                               PCI_BDF(2, 12, 3) INTC PIRQC
-                               PCI_BDF(2, 12, 4) INTC PIRQC
-                       >;
+                       compatible = "intel,pch7";
+
+                       irq-router {
+                               compatible = "intel,queensbay-irq-router";
+                               intel,pirq-config = "pci";
+                               intel,pirq-link = <0x60 8>;
+                               intel,pirq-mask = <0xcee0>;
+                               intel,pirq-routing = <
+                                       /* TunnelCreek PCI devices */
+                                       PCI_BDF(0, 2, 0) INTA PIRQE
+                                       PCI_BDF(0, 3, 0) INTA PIRQF
+                                       PCI_BDF(0, 23, 0) INTA PIRQA
+                                       PCI_BDF(0, 23, 0) INTB PIRQB
+                                       PCI_BDF(0, 23, 0) INTC PIRQC
+                                       PCI_BDF(0, 23, 0) INTD PIRQD
+                                       PCI_BDF(0, 24, 0) INTA PIRQB
+                                       PCI_BDF(0, 24, 0) INTB PIRQC
+                                       PCI_BDF(0, 24, 0) INTC PIRQD
+                                       PCI_BDF(0, 24, 0) INTD PIRQA
+                                       PCI_BDF(0, 25, 0) INTA PIRQC
+                                       PCI_BDF(0, 25, 0) INTB PIRQD
+                                       PCI_BDF(0, 25, 0) INTC PIRQA
+                                       PCI_BDF(0, 25, 0) INTD PIRQB
+                                       PCI_BDF(0, 26, 0) INTA PIRQD
+                                       PCI_BDF(0, 26, 0) INTB PIRQA
+                                       PCI_BDF(0, 26, 0) INTC PIRQB
+                                       PCI_BDF(0, 26, 0) INTD PIRQC
+                                       PCI_BDF(0, 27, 0) INTA PIRQG
+                                       /*
+                                       * Topcliff PCI devices
+                                       *
+                                       * Note on the Crown Bay board, Topcliff
+                                       * chipset is connected to TunnelCreek
+                                       * PCIe port 0, so its bus number is 1
+                                       * for its PCIe port and 2 for its PCI
+                                       * devices per U-Boot current PCI bus
+                                       * enumeration algorithm.
+                                       */
+                                       PCI_BDF(1, 0, 0) INTA PIRQA
+                                       PCI_BDF(2, 0, 1) INTA PIRQA
+                                       PCI_BDF(2, 0, 2) INTA PIRQA
+                                       PCI_BDF(2, 2, 0) INTB PIRQD
+                                       PCI_BDF(2, 2, 1) INTB PIRQD
+                                       PCI_BDF(2, 2, 2) INTB PIRQD
+                                       PCI_BDF(2, 2, 3) INTB PIRQD
+                                       PCI_BDF(2, 2, 4) INTB PIRQD
+                                       PCI_BDF(2, 4, 0) INTC PIRQC
+                                       PCI_BDF(2, 4, 1) INTC PIRQC
+                                       PCI_BDF(2, 6, 0) INTD PIRQB
+                                       PCI_BDF(2, 8, 0) INTA PIRQA
+                                       PCI_BDF(2, 8, 1) INTA PIRQA
+                                       PCI_BDF(2, 8, 2) INTA PIRQA
+                                       PCI_BDF(2, 8, 3) INTA PIRQA
+                                       PCI_BDF(2, 10, 0) INTB PIRQD
+                                       PCI_BDF(2, 10, 1) INTB PIRQD
+                                       PCI_BDF(2, 10, 2) INTB PIRQD
+                                       PCI_BDF(2, 10, 3) INTB PIRQD
+                                       PCI_BDF(2, 10, 4) INTB PIRQD
+                                       PCI_BDF(2, 12, 0) INTC PIRQC
+                                       PCI_BDF(2, 12, 1) INTC PIRQC
+                                       PCI_BDF(2, 12, 2) INTC PIRQC
+                                       PCI_BDF(2, 12, 3) INTC PIRQC
+                                       PCI_BDF(2, 12, 4) INTC PIRQC
+                               >;
+                       };
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       reg = <0>;
+                                       compatible = "sst,25vf016b",
+                                               "spi-flash";
+                                       memory-map = <0xffe00000 0x00200000>;
+                               };
+                       };
                };
        };
 
index 55165e14646aa1c3720bc18f223b6b065acc1be8..a2f5a1f223427508c447225df87bdce965b91b4a 100644 (file)
                        current-speed = <115200>;
                };
 
-               irq-router@1f,0 {
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "pci";
-                       intel,pirq-link = <0x60 8>;
-                       intel,pirq-mask = <0xdef8>;
-                       intel,pirq-routing = <
-                               PCI_BDF(0, 20, 0) INTA PIRQE
-                               PCI_BDF(0, 20, 1) INTB PIRQF
-                               PCI_BDF(0, 20, 2) INTC PIRQG
-                               PCI_BDF(0, 20, 3) INTD PIRQH
-                               PCI_BDF(0, 20, 4) INTA PIRQE
-                               PCI_BDF(0, 20, 5) INTB PIRQF
-                               PCI_BDF(0, 20, 6) INTC PIRQG
-                               PCI_BDF(0, 20, 7) INTD PIRQH
-                               PCI_BDF(0, 21, 0) INTA PIRQE
-                               PCI_BDF(0, 21, 1) INTB PIRQF
-                               PCI_BDF(0, 21, 2) INTC PIRQG
-                               PCI_BDF(0, 23, 0) INTA PIRQA
-                               PCI_BDF(0, 23, 1) INTB PIRQB
-
-                               /* PCIe root ports downstream interrupts */
-                               PCI_BDF(1, 0, 0) INTA PIRQA
-                               PCI_BDF(1, 0, 0) INTB PIRQB
-                               PCI_BDF(1, 0, 0) INTC PIRQC
-                               PCI_BDF(1, 0, 0) INTD PIRQD
-                               PCI_BDF(2, 0, 0) INTA PIRQB
-                               PCI_BDF(2, 0, 0) INTB PIRQC
-                               PCI_BDF(2, 0, 0) INTC PIRQD
-                               PCI_BDF(2, 0, 0) INTD PIRQA
-                       >;
+                       compatible = "intel,pch7";
+
+                       irq-router {
+                               compatible = "intel,quark-irq-router";
+                               intel,pirq-config = "pci";
+                               intel,pirq-link = <0x60 8>;
+                               intel,pirq-mask = <0xdef8>;
+                               intel,pirq-routing = <
+                                       PCI_BDF(0, 20, 0) INTA PIRQE
+                                       PCI_BDF(0, 20, 1) INTB PIRQF
+                                       PCI_BDF(0, 20, 2) INTC PIRQG
+                                       PCI_BDF(0, 20, 3) INTD PIRQH
+                                       PCI_BDF(0, 20, 4) INTA PIRQE
+                                       PCI_BDF(0, 20, 5) INTB PIRQF
+                                       PCI_BDF(0, 20, 6) INTC PIRQG
+                                       PCI_BDF(0, 20, 7) INTD PIRQH
+                                       PCI_BDF(0, 21, 0) INTA PIRQE
+                                       PCI_BDF(0, 21, 1) INTB PIRQF
+                                       PCI_BDF(0, 21, 2) INTC PIRQG
+                                       PCI_BDF(0, 23, 0) INTA PIRQA
+                                       PCI_BDF(0, 23, 1) INTB PIRQB
+
+                                       /* PCIe root ports downstream interrupts */
+                                       PCI_BDF(1, 0, 0) INTA PIRQA
+                                       PCI_BDF(1, 0, 0) INTB PIRQB
+                                       PCI_BDF(1, 0, 0) INTC PIRQC
+                                       PCI_BDF(1, 0, 0) INTD PIRQD
+                                       PCI_BDF(2, 0, 0) INTA PIRQB
+                                       PCI_BDF(2, 0, 0) INTB PIRQC
+                                       PCI_BDF(2, 0, 0) INTC PIRQD
+                                       PCI_BDF(2, 0, 0) INTD PIRQA
+                               >;
+                       };
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       #size-cells = <1>;
+                                       #address-cells = <1>;
+                                       reg = <0>;
+                                       compatible = "winbond,w25q64",
+                                               "spi-flash";
+                                       memory-map = <0xff800000 0x00800000>;
+                                       rw-mrc-cache {
+                                               label = "rw-mrc-cache";
+                                               reg = <0x00010000 0x00010000>;
+                                       };
+                               };
+                       };
                };
        };
 
                bank-name = "B";
        };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       #size-cells = <1>;
-                       #address-cells = <1>;
-                       reg = <0>;
-                       compatible = "winbond,w25q64", "spi-flash";
-                       memory-map = <0xff800000 0x00800000>;
-                       rw-mrc-cache {
-                               label = "rw-mrc-cache";
-                               reg = <0x00010000 0x00010000>;
-                       };
-               };
-       };
-
 };
index bbfd6d4028086afe5077591cf93026c6b5975815..e7ef7c987b6226b525a1d40be3299ec5787a0d6e 100644 (file)
                          0x42000000 0x0 0xc0000000 0xc0000000 0 0x20000000
                          0x01000000 0x0 0x2000 0x2000 0 0xe000>;
 
-               irq-router@1f,0 {
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "ibase";
-                       intel,ibase-offset = <0x50>;
-                       intel,pirq-link = <8 8>;
-                       intel,pirq-mask = <0xdee0>;
-                       intel,pirq-routing = <
-                               /* BayTrail PCI devices */
-                               PCI_BDF(0, 2, 0) INTA PIRQA
-                               PCI_BDF(0, 3, 0) INTA PIRQA
-                               PCI_BDF(0, 16, 0) INTA PIRQA
-                               PCI_BDF(0, 17, 0) INTA PIRQA
-                               PCI_BDF(0, 18, 0) INTA PIRQA
-                               PCI_BDF(0, 19, 0) INTA PIRQA
-                               PCI_BDF(0, 20, 0) INTA PIRQA
-                               PCI_BDF(0, 21, 0) INTA PIRQA
-                               PCI_BDF(0, 22, 0) INTA PIRQA
-                               PCI_BDF(0, 23, 0) INTA PIRQA
-                               PCI_BDF(0, 24, 0) INTA PIRQA
-                               PCI_BDF(0, 24, 1) INTC PIRQC
-                               PCI_BDF(0, 24, 2) INTD PIRQD
-                               PCI_BDF(0, 24, 3) INTB PIRQB
-                               PCI_BDF(0, 24, 4) INTA PIRQA
-                               PCI_BDF(0, 24, 5) INTC PIRQC
-                               PCI_BDF(0, 24, 6) INTD PIRQD
-                               PCI_BDF(0, 24, 7) INTB PIRQB
-                               PCI_BDF(0, 26, 0) INTA PIRQA
-                               PCI_BDF(0, 27, 0) INTA PIRQA
-                               PCI_BDF(0, 28, 0) INTA PIRQA
-                               PCI_BDF(0, 28, 1) INTB PIRQB
-                               PCI_BDF(0, 28, 2) INTC PIRQC
-                               PCI_BDF(0, 28, 3) INTD PIRQD
-                               PCI_BDF(0, 29, 0) INTA PIRQA
-                               PCI_BDF(0, 30, 0) INTA PIRQA
-                               PCI_BDF(0, 30, 1) INTD PIRQD
-                               PCI_BDF(0, 30, 2) INTB PIRQB
-                               PCI_BDF(0, 30, 3) INTC PIRQC
-                               PCI_BDF(0, 30, 4) INTD PIRQD
-                               PCI_BDF(0, 30, 5) INTB PIRQB
-                               PCI_BDF(0, 31, 3) INTB PIRQB
+                       compatible = "pci8086,0f1c", "intel,pch9";
 
-                               /* PCIe root ports downstream interrupts */
-                               PCI_BDF(1, 0, 0) INTA PIRQA
-                               PCI_BDF(1, 0, 0) INTB PIRQB
-                               PCI_BDF(1, 0, 0) INTC PIRQC
-                               PCI_BDF(1, 0, 0) INTD PIRQD
-                               PCI_BDF(2, 0, 0) INTA PIRQB
-                               PCI_BDF(2, 0, 0) INTB PIRQC
-                               PCI_BDF(2, 0, 0) INTC PIRQD
-                               PCI_BDF(2, 0, 0) INTD PIRQA
-                               PCI_BDF(3, 0, 0) INTA PIRQC
-                               PCI_BDF(3, 0, 0) INTB PIRQD
-                               PCI_BDF(3, 0, 0) INTC PIRQA
-                               PCI_BDF(3, 0, 0) INTD PIRQB
-                               PCI_BDF(4, 0, 0) INTA PIRQD
-                               PCI_BDF(4, 0, 0) INTB PIRQA
-                               PCI_BDF(4, 0, 0) INTC PIRQB
-                               PCI_BDF(4, 0, 0) INTD PIRQC
-                       >;
+                       irq-router {
+                               compatible = "intel,irq-router";
+                               intel,pirq-config = "ibase";
+                               intel,ibase-offset = <0x50>;
+                               intel,pirq-link = <8 8>;
+                               intel,pirq-mask = <0xdee0>;
+                               intel,pirq-routing = <
+                                       /* BayTrail PCI devices */
+                                       PCI_BDF(0, 2, 0) INTA PIRQA
+                                       PCI_BDF(0, 3, 0) INTA PIRQA
+                                       PCI_BDF(0, 16, 0) INTA PIRQA
+                                       PCI_BDF(0, 17, 0) INTA PIRQA
+                                       PCI_BDF(0, 18, 0) INTA PIRQA
+                                       PCI_BDF(0, 19, 0) INTA PIRQA
+                                       PCI_BDF(0, 20, 0) INTA PIRQA
+                                       PCI_BDF(0, 21, 0) INTA PIRQA
+                                       PCI_BDF(0, 22, 0) INTA PIRQA
+                                       PCI_BDF(0, 23, 0) INTA PIRQA
+                                       PCI_BDF(0, 24, 0) INTA PIRQA
+                                       PCI_BDF(0, 24, 1) INTC PIRQC
+                                       PCI_BDF(0, 24, 2) INTD PIRQD
+                                       PCI_BDF(0, 24, 3) INTB PIRQB
+                                       PCI_BDF(0, 24, 4) INTA PIRQA
+                                       PCI_BDF(0, 24, 5) INTC PIRQC
+                                       PCI_BDF(0, 24, 6) INTD PIRQD
+                                       PCI_BDF(0, 24, 7) INTB PIRQB
+                                       PCI_BDF(0, 26, 0) INTA PIRQA
+                                       PCI_BDF(0, 27, 0) INTA PIRQA
+                                       PCI_BDF(0, 28, 0) INTA PIRQA
+                                       PCI_BDF(0, 28, 1) INTB PIRQB
+                                       PCI_BDF(0, 28, 2) INTC PIRQC
+                                       PCI_BDF(0, 28, 3) INTD PIRQD
+                                       PCI_BDF(0, 29, 0) INTA PIRQA
+                                       PCI_BDF(0, 30, 0) INTA PIRQA
+                                       PCI_BDF(0, 30, 1) INTD PIRQD
+                                       PCI_BDF(0, 30, 2) INTB PIRQB
+                                       PCI_BDF(0, 30, 3) INTC PIRQC
+                                       PCI_BDF(0, 30, 4) INTD PIRQD
+                                       PCI_BDF(0, 30, 5) INTB PIRQB
+                                       PCI_BDF(0, 31, 3) INTB PIRQB
+
+                                       /*
+                                        * PCIe root ports downstream
+                                        * interrupts
+                                        */
+                                       PCI_BDF(1, 0, 0) INTA PIRQA
+                                       PCI_BDF(1, 0, 0) INTB PIRQB
+                                       PCI_BDF(1, 0, 0) INTC PIRQC
+                                       PCI_BDF(1, 0, 0) INTD PIRQD
+                                       PCI_BDF(2, 0, 0) INTA PIRQB
+                                       PCI_BDF(2, 0, 0) INTB PIRQC
+                                       PCI_BDF(2, 0, 0) INTC PIRQD
+                                       PCI_BDF(2, 0, 0) INTD PIRQA
+                                       PCI_BDF(3, 0, 0) INTA PIRQC
+                                       PCI_BDF(3, 0, 0) INTB PIRQD
+                                       PCI_BDF(3, 0, 0) INTC PIRQA
+                                       PCI_BDF(3, 0, 0) INTD PIRQB
+                                       PCI_BDF(4, 0, 0) INTA PIRQD
+                                       PCI_BDF(4, 0, 0) INTB PIRQA
+                                       PCI_BDF(4, 0, 0) INTC PIRQB
+                                       PCI_BDF(4, 0, 0) INTD PIRQC
+                               >;
+                       };
+
+                       spi {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               compatible = "intel,ich-spi";
+                               spi-flash@0 {
+                                       #address-cells = <1>;
+                                       #size-cells = <1>;
+                                       reg = <0>;
+                                       compatible = "stmicro,n25q064a",
+                                               "spi-flash";
+                                       memory-map = <0xff800000 0x00800000>;
+                                       rw-mrc-cache {
+                                               label = "rw-mrc-cache";
+                                               reg = <0x006f0000 0x00010000>;
+                                       };
+                               };
+                       };
                };
        };
 
                };
        };
 
-       spi {
-               #address-cells = <1>;
-               #size-cells = <0>;
-               compatible = "intel,ich-spi";
-               spi-flash@0 {
-                       #address-cells = <1>;
-                       #size-cells = <1>;
-                       reg = <0>;
-                       compatible = "stmicro,n25q064a", "spi-flash";
-                       memory-map = <0xff800000 0x00800000>;
-                       rw-mrc-cache {
-                               label = "rw-mrc-cache";
-                               reg = <0x006f0000 0x00010000>;
-                       };
-               };
-       };
-
        microcode {
                update@0 {
 #include "microcode/m0130673322.dtsi"
index 9086b461b9d1362745318d41f02cdf379a1a09e9..9c3f2a08e63721814c30065622f6d53e57eb7838 100644 (file)
                        0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000
                        0x01000000 0x0 0x2000 0x2000 0 0xe000>;
 
-               irq-router@1,0 {
+               pch@1,0 {
                        reg = <0x00000800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "pci";
-                       intel,pirq-link = <0x60 4>;
-                       intel,pirq-mask = <0x0e40>;
-                       intel,pirq-routing = <
-                               /* PIIX UHCI */
-                               PCI_BDF(0, 1, 2) INTD PIRQD
-                               /* e1000 NIC */
-                               PCI_BDF(0, 3, 0) INTA PIRQC
-                       >;
+                       compatible = "intel,pch7";
+
+                       irq-router {
+                               compatible = "intel,irq-router";
+                               intel,pirq-config = "pci";
+                               intel,pirq-link = <0x60 4>;
+                               intel,pirq-mask = <0x0e40>;
+                               intel,pirq-routing = <
+                                       /* PIIX UHCI */
+                                       PCI_BDF(0, 1, 2) INTD PIRQD
+                                       /* e1000 NIC */
+                                       PCI_BDF(0, 3, 0) INTA PIRQC
+                               >;
+                       };
                };
        };
 
index 145e8115cec96ef1e1845981464e56db20b3e1b7..5d601b344477ad4e1864951748a5f6cc9f49f951 100644 (file)
                        0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000
                        0x01000000 0x0 0x2000 0x2000 0 0xe000>;
 
-               irq-router@1f,0 {
+               pch@1f,0 {
                        reg = <0x0000f800 0 0 0 0>;
-                       compatible = "intel,irq-router";
-                       intel,pirq-config = "pci";
-                       intel,pirq-link = <0x60 8>;
-                       intel,pirq-mask = <0x0e40>;
-                       intel,pirq-routing = <
-                               /* e1000 NIC */
-                               PCI_BDF(0, 2, 0) INTA PIRQG
-                               /* ICH9 UHCI */
-                               PCI_BDF(0, 29, 0) INTA PIRQA
-                               PCI_BDF(0, 29, 1) INTB PIRQB
-                               PCI_BDF(0, 29, 2) INTC PIRQC
-                               /* ICH9 EHCI */
-                               PCI_BDF(0, 29, 7) INTD PIRQD
-                               /* ICH9 SATA */
-                               PCI_BDF(0, 31, 2) INTA PIRQA
-                       >;
+                       compatible = "intel,pch9";
+
+                       irq-router {
+                               compatible = "intel,irq-router";
+                               intel,pirq-config = "pci";
+                               intel,pirq-link = <0x60 8>;
+                               intel,pirq-mask = <0x0e40>;
+                               intel,pirq-routing = <
+                                       /* e1000 NIC */
+                                       PCI_BDF(0, 2, 0) INTA PIRQG
+                                       /* ICH9 UHCI */
+                                       PCI_BDF(0, 29, 0) INTA PIRQA
+                                       PCI_BDF(0, 29, 1) INTB PIRQB
+                                       PCI_BDF(0, 29, 2) INTC PIRQC
+                                       /* ICH9 EHCI */
+                                       PCI_BDF(0, 29, 7) INTD PIRQD
+                                       /* ICH9 SATA */
+                                       PCI_BDF(0, 31, 2) INTA PIRQA
+                               >;
+                       };
                };
        };
 
index fcdf6e26cbb2ef6b66cfe710c920388bc6242c30..e866580046619bfab3675b8455ba4cd1f0aea65a 100644 (file)
@@ -7,27 +7,6 @@
 #ifndef _ASM_ARCH_BD82X6X_H
 #define _ASM_ARCH_BD82X6X_H
 
-void bd82x6x_sata_init(pci_dev_t dev, const void *blob, int node);
-void bd82x6x_sata_enable(pci_dev_t dev, const void *blob, int node);
-void bd82x6x_pci_init(pci_dev_t dev);
-void bd82x6x_usb_ehci_init(pci_dev_t dev);
-void bd82x6x_usb_xhci_init(pci_dev_t dev);
-int gma_func0_init(struct udevice *dev, const void *blob, int node);
-int bd82x6x_init(void);
-
-/**
- * struct x86_cpu_priv - Information about a single CPU
- *
- * @apic_id: Advanced Programmable Interrupt Controller Identifier, which is
- * just a number representing the CPU core
- *
- * TODO: Move this to driver model once lifecycle is understood
- */
-struct x86_cpu_priv {
-       int apic_id;
-       int start_err;
-};
-
-int model_206ax_init(struct x86_cpu_priv *cpu);
+int gma_func0_init(struct udevice *dev);
 
 #endif
index 3a0809d6ece7c6438a5929f71e1f66de00883828..eb1b73f92e7469afc91894bd792304e8ebdd15bb 100644 (file)
@@ -345,12 +345,47 @@ struct __packed me_fwcaps {
        u8 reserved[3];
 };
 
-/* Defined in me_status.c for both romstage and ramstage */
+/**
+ * intel_me_status() - Check Intel Management Engine status
+ *
+ * struct hfs: Firmware status
+ * struct gmes:        Management engine status
+ */
 void intel_me_status(struct me_hfs *hfs, struct me_gmes *gmes);
 
-void intel_early_me_status(void);
-int intel_early_me_init(void);
-int intel_early_me_uma_size(void);
-int intel_early_me_init_done(u8 status);
+/**
+ * intel_early_me_status() - Check early Management Engine Status
+ *
+ * @me_dev:    Management engine PCI device
+ */
+void intel_early_me_status(struct udevice *me_dev);
+
+/**
+ * intel_early_me_init() - Early Intel Management Engine init
+ *
+ * @me_dev:    Management engine PCI device
+ * @return 0 if OK, -ve on error
+ */
+int intel_early_me_init(struct udevice *me_dev);
+
+/**
+ * intel_early_me_uma_size() - Get UMA size from the Intel Management Engine
+ *
+ * @me_dev:    Management engine PCI device
+ * @return UMA size if OK, -EINVAL on error
+ */
+int intel_early_me_uma_size(struct udevice *me_dev);
+
+/**
+ * intel_early_me_init_done() - Complete Intel Management Engine init
+ *
+ * @dev:       Northbridge device
+ * @me_dev:    Management engine PCI device
+ * @status:    Status result (ME_INIT_...)
+ * @return 0 to continue to boot, -EINVAL on unknown result data, -ETIMEDOUT
+ * if ME did not respond
+ */
+int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
+                            uint status);
 
 #endif
index 31437c8618d13f6c40a772a06447dfe436ce223e..af3e8e747c1563108ee065709a41e2d287795590 100644 (file)
 
 #define SMBUS_IO_BASE          0x0400
 
-int pch_silicon_revision(void);
-int pch_silicon_type(void);
-int pch_silicon_supported(int type, int rev);
-void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue);
-
 #define MAINBOARD_POWER_OFF    0
 #define MAINBOARD_POWER_ON     1
 #define MAINBOARD_POWER_KEEP   2
@@ -470,17 +465,23 @@ void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue);
 #define   DMISCI_STS   (1 << 9)
 #define TCO2_STS       0x66
 
-int lpc_init(struct pci_controller *hose, pci_dev_t dev);
-void lpc_enable(pci_dev_t dev);
+/**
+ * pch_silicon_revision() - Read silicon device ID from the PCH
+ *
+ * @dev:       PCH device
+ * @return silicon device ID
+ */
+int pch_silicon_type(struct udevice *dev);
 
 /**
- * lpc_early_init() - set up LPC serial ports and other early things
+ * pch_pch_iobp_update() - Update a pch register
  *
- * @blob:      Device tree blob
- * @node:      Offset of LPC node
- * @dev:       PCH PCI device containing the LPC
- * @return 0 if OK, -ve on error
+ * @dev:       PCH device
+ * @address:   Address to update
+ * @andvalue:  Value to AND with existing value
+ * @orvalue:   Value to OR with existing value
  */
-int lpc_early_init(const void *blob, int node, pci_dev_t dev);
+void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
+                            u32 orvalue);
 
 #endif
index c9605258b59160853566518c0de5fea96d8e6586..d137d6786a938c23a2d3d604a43633c07bcdc06a 100644 (file)
 
 #define DMIBAR_REG(x)  (DEFAULT_DMIBAR + x)
 
-int bridge_silicon_revision(void);
-
-void northbridge_enable(pci_dev_t dev);
-void northbridge_init(pci_dev_t dev);
+/**
+ * bridge_silicon_revision() - Get the Northbridge revision
+ *
+ * @dev:       Northbridge device
+ * @return revision ID (bits 3:0) and bridge ID (bits 7:4)
+ */
+int bridge_silicon_revision(struct udevice *dev);
 
-void report_platform_info(void);
+void report_platform_info(struct udevice *dev);
 
 void sandybridge_early_init(int chipset_type);
 
index c70183ccefffba8effd9fdb080210328285b03a3..18b034598639059048ed1922b5ee961a465675b7 100644 (file)
@@ -45,6 +45,17 @@ enum {
        GDT_BASE_HIGH_MASK      = 0xf,
 };
 
+/*
+ * System controllers in an x86 system. We mostly need to just find these and
+ * use them on PCI. At some point these might have their own uclass (e.g.
+ * UCLASS_VIDEO for the GMA device).
+ */
+enum {
+       X86_NONE,
+       X86_SYSCON_ME,          /* Intel Management Engine */
+       X86_SYSCON_GMA,         /* Intel Graphics Media Accelerator */
+};
+
 struct cpuid_result {
        uint32_t eax;
        uint32_t ebx;
index 6697da3b859124d0bf69e00471e006b12180ba47..5b9e6737634e69ed3044fb037306b331eabf297c 100644 (file)
@@ -56,23 +56,10 @@ struct pirq_routing {
 #define PIRQ_BITMAP            0xdef8
 
 /**
- * cpu_irq_init() - Initialize CPU IRQ routing
+ * irq_router_common_init() - Perform common x86 interrupt init
  *
- * This initializes some platform-specific registers related to IRQ routing,
- * like configuring internal PCI devices to use which PCI interrupt pin,
- * and which PCI interrupt pin is mapped to which PIRQ line. Note on some
- * platforms, such IRQ routing might be hard-coded thus cannot configure.
+ * This creates the PIRQ routing table and routes the IRQs
  */
-void cpu_irq_init(void);
-
-/**
- * pirq_init() - Initialize platform PIRQ routing
- *
- * This initializes the PIRQ routing on the platform and configures all PCI
- * devices' interrupt line register to a working IRQ number on the 8259 PIC.
- *
- * @return 0 if OK, -ve on error
- */
-int pirq_init(void);
+int irq_router_common_init(struct udevice *dev);
 
 #endif /* _ARCH_IRQ_H_ */
index dbf8e95c1b3457fe8feb04d6915d05b04119fdd7..9c143caf670b84653d14eda57bf70b936b965c35 100644 (file)
@@ -77,8 +77,6 @@ uint64_t timer_get_tsc(void);
 
 void quick_ram_check(void);
 
-int x86_init_cpus(void);
-
 #define PCI_VGA_RAM_IMAGE_START                0xc0000
 
 #endif /* _U_BOOT_I386_H_ */
index cd5ecb60ea44da4b1a8f8d948b7b679dcc756804..d9fc296b6e4877a1a3b3a8766fe7d54f6ac54d67 100644 (file)
@@ -19,12 +19,12 @@ obj-y       += lpc-uclass.o
 obj-y  += mpspec.o
 obj-$(CONFIG_ENABLE_MRC_CACHE) += mrccache.o
 obj-y += cmd_mtrr.o
+obj-y  += northbridge-uclass.o
 obj-$(CONFIG_I8259_PIC) += i8259.o
 obj-$(CONFIG_I8254_TIMER) += i8254.o
 ifndef CONFIG_DM_PCI
 obj-$(CONFIG_PCI) += pci_type1.o
 endif
-obj-y  += pch-uclass.o
 obj-y  += pirq_routing.o
 obj-y  += relocate.o
 obj-y += physmem.o
index f3ad116316a9541953c39c0f13709d96a3e44777..0faa582d772d4608dea2b178e4330376e29ea629 100644 (file)
@@ -292,19 +292,19 @@ static int mptable_add_intsrc(struct mp_config_table *mc,
        struct mpc_config_intsrc *intsrc_base;
        int intsrc_entries = 0;
        const void *blob = gd->fdt_blob;
-       int node;
+       struct udevice *dev;
        int len, count;
        const u32 *cell;
-       int i;
+       int i, ret;
 
-       /* Get I/O interrupt information from device tree */
-       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_IRQ_ROUTER);
-       if (node < 0) {
+       ret = uclass_first_device(UCLASS_IRQ, &dev);
+       if (ret && ret != -ENODEV) {
                debug("%s: Cannot find irq router node\n", __func__);
-               return -ENOENT;
+               return ret;
        }
 
-       cell = fdt_getprop(blob, node, "intel,pirq-routing", &len);
+       /* Get I/O interrupt information from device tree */
+       cell = fdt_getprop(blob, dev->of_offset, "intel,pirq-routing", &len);
        if (!cell)
                return -ENOENT;
 
index 53a1259d095369aad533eef8ec63435b1bff6d95..67bace4f40df6bb06e1fc3ec8022c9b9fd6ec079 100644 (file)
@@ -243,8 +243,12 @@ int mrccache_save(void)
                goto err_entry;
        data  = (struct mrc_data_container *)gd->arch.mrc_output;
        ret = mrccache_update(sf, &entry, data);
-       if (!ret)
+       if (!ret) {
                debug("Saved MRC data with checksum %04x\n", data->checksum);
+       } else if (ret == -EEXIST) {
+               debug("MRC data is the same as last time, skipping save\n");
+               ret = 0;
+       }
 
 err_entry:
        if (ret)
diff --git a/arch/x86/lib/northbridge-uclass.c b/arch/x86/lib/northbridge-uclass.c
new file mode 100644 (file)
index 0000000..64b6257
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/root.h>
+
+UCLASS_DRIVER(northbridge) = {
+       .id             = UCLASS_NORTHBRIDGE,
+       .name           = "northbridge",
+};
diff --git a/arch/x86/lib/pch-uclass.c b/arch/x86/lib/pch-uclass.c
deleted file mode 100644 (file)
index 20dfa81..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2015 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <dm.h>
-#include <dm/root.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static int pch_uclass_post_bind(struct udevice *bus)
-{
-       /*
-        * Scan the device tree for devices
-        *
-        * Before relocation, only bind devices marked for pre-relocation
-        * use.
-        */
-       return dm_scan_fdt_node(bus, gd->fdt_blob, bus->of_offset,
-                               gd->flags & GD_FLG_RELOC ? false : true);
-}
-
-UCLASS_DRIVER(pch) = {
-       .id             = UCLASS_PCH,
-       .name           = "pch",
-       .post_bind      = pch_uclass_post_bind,
-};
index 6a8fca61a0d451b6c407c87a3397bde2f1557eaa..e582abbaef364c96aaace212f614a4df77974302 100644 (file)
@@ -16,7 +16,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include <hwconfig.h>
@@ -1023,10 +1022,6 @@ int board_early_init_r(void)
                        MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                        0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
        /*
         * Adjust core voltage according to voltage ID
         * This function changes I2C mux to channel 2.
index f1bed51d30480d1c6e35bb2e4ca54e00ede0db8b..1bd65a8e5578feb0905587892b62fe3bc482576e 100644 (file)
@@ -42,7 +42,7 @@ int __weak board_vdd_drop_compensation(void)
  * The IR chip can show up under the following addresses:
  * 0x08 (Verified on T1040RDB-PA,T4240RDB-PB,X-T4240RDB-16GPA)
  * 0x09 (Verified on T1040RDB-PA)
- * 0x38 (Verified on T2080QDS, T2081QDS)
+ * 0x38 (Verified on T2080QDS, T2081QDS, T4240RDB)
  */
 static int find_ir_chip_on_i2c(void)
 {
@@ -292,7 +292,7 @@ int adjust_vdd(ulong vdd_override)
                (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
 #endif
        u32 fusesr;
-       u8 vid;
+       u8 vid, buf;
        int vdd_target, vdd_current, vdd_last;
        int ret, i2caddress;
        unsigned long vdd_string_override;
@@ -346,6 +346,21 @@ int adjust_vdd(ulong vdd_override)
                debug("VID: IR Chip found on I2C address 0x%02x\n", i2caddress);
        }
 
+       /* check IR chip work on Intel mode*/
+       ret = i2c_read(i2caddress,
+                      IR36021_INTEL_MODE_OOFSET,
+                      1, (void *)&buf, 1);
+       if (ret) {
+               printf("VID: failed to read IR chip mode.\n");
+               ret = -1;
+               goto exit;
+       }
+       if ((buf & IR36021_MODE_MASK) != IR36021_INTEL_MODE) {
+               printf("VID: IR Chip is not used in Intel mode.\n");
+               ret = -1;
+               goto exit;
+       }
+
        /* get the voltage ID from fuse status register */
        fusesr = in_be32(&gur->dcfg_fusesr);
        /*
index a9c7bb4790e4997b9a02e0a008d93942d888907e..9182c20bc9cc678299f3e53b594c5a86c88720c3 100644 (file)
 #define IR36021_LOOP1_VOUT_OFFSET      0x9A
 #define IR36021_MFR_ID_OFFSET          0x92
 #define IR36021_MFR_ID                 0x43
+#define IR36021_INTEL_MODE_OOFSET      0x14
+#define IR36021_MODE_MASK              0x20
+#define IR36021_INTEL_MODE             0x00
+#define IR36021_AMD_MODE               0x20
 
 /* step the IR regulator in 5mV increments */
 #define IR_VDD_STEP_DOWN               5
index 6f0fea1a3566a57c4efb4fec5078149bc767168e..f41985d2f66de5b887c3f0a561ca11695e99d7c2 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 
@@ -125,11 +124,6 @@ int board_early_init_r(void)
                        MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
                        0, flash_esel, BOOKE_PAGESZ_256M, 1);   /* ts, esel, tsize, iprot */
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        return 0;
 }
 
index 0b288f2588fa2b86444dcbcd535ae3659f6b5b24..02085b6b7e4c3edc5e064da1460bfc48f447e2f0 100644 (file)
@@ -7,4 +7,3 @@
 #
 
 obj-y  := mx25pdk.o
-obj-y  += lowlevel_init.o
diff --git a/board/freescale/mx25pdk/lowlevel_init.S b/board/freescale/mx25pdk/lowlevel_init.S
deleted file mode 100644 (file)
index 8c581b5..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright (c) 2011  Freescale Semiconductor
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-.globl lowlevel_init
-lowlevel_init:
-
-       mov     pc, lr
index 01dac72e85effc385364fa3173e133b3aff5ea32..788d3c3e35972b83260daa11498f057214826eae 100644 (file)
@@ -186,3 +186,6 @@ int checkboard(void)
 
        return 0;
 }
+
+/* Lowlevel init isn't used on mx25pdk, so just provide a dummy one here */
+void lowlevel_init(void) {}
index f8ae9733fc0ba5521bae4a461f31ca488feb673c..bbcc5bb0c6fcbee107349c1269d9e2a66d0682ed 100644 (file)
@@ -47,6 +47,9 @@ DECLARE_GLOBAL_DATA_PTR;
 #define QSPI_PAD_CTRL  \
        (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUE | PAD_CTL_PUS_PU47KOHM)
 
+#define NAND_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
+
+#define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU5KOHM)
 #ifdef CONFIG_SYS_I2C_MXC
 #define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
 /* I2C1 for PMIC */
@@ -196,6 +199,38 @@ static void iox74lv_init(void)
        gpio_direction_output(IOX_STCP, 1);
 };
 
+#ifdef CONFIG_NAND_MXS
+static iomux_v3_cfg_t const gpmi_pads[] = {
+       MX7D_PAD_SD3_DATA0__NAND_DATA00 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA1__NAND_DATA01 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA2__NAND_DATA02 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA3__NAND_DATA03 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA4__NAND_DATA04 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA5__NAND_DATA05 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA6__NAND_DATA06 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_DATA7__NAND_DATA07 | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_CLK__NAND_CLE      | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_CMD__NAND_ALE      | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_STROBE__NAND_RE_B  | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SD3_RESET_B__NAND_WE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_MCLK__NAND_WP_B   | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_RX_BCLK__NAND_CE3_B       | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_RX_SYNC__NAND_CE2_B       | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_RX_DATA__NAND_CE1_B       | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_TX_BCLK__NAND_CE0_B       | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_TX_SYNC__NAND_DQS | MUX_PAD_CTRL(NAND_PAD_CTRL),
+       MX7D_PAD_SAI1_TX_DATA__NAND_READY_B     | MUX_PAD_CTRL(NAND_PAD_READY0_CTRL),
+};
+
+static void setup_gpmi_nand(void)
+{
+       imx_iomux_v3_setup_multiple_pads(gpmi_pads, ARRAY_SIZE(gpmi_pads));
+
+       /* NAND_USDHC_BUS_CLK is set in rom */
+       set_clk_nand();
+}
+#endif
+
 #ifdef CONFIG_VIDEO_MXS
 static iomux_v3_cfg_t const lcd_pads[] = {
        MX7D_PAD_LCD_CLK__LCD_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
@@ -503,6 +538,10 @@ int board_init(void)
        setup_fec();
 #endif
 
+#ifdef CONFIG_NAND_MXS
+       setup_gpmi_nand();
+#endif
+
 #ifdef CONFIG_VIDEO_MXS
        setup_lcd();
 #endif
index e600bdbc2a87a38ab014d268aac95cbcfd733ed3..c6a724217fdb8195e71190bf6ad1153f0bb78b25 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 
@@ -140,8 +139,6 @@ int board_early_init_r(void)
                        MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                        0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-       setup_portals();
        board_config_lanes_mux();
 
        return 0;
index 708afcaebfacb4cb22ae214027e264fcb4b4c15d..76793a1186ec3aba7db3d9a3d83e491fb90e67fc 100644 (file)
@@ -15,7 +15,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include <hwconfig.h>
@@ -279,10 +278,6 @@ int board_early_init_r(void)
        set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
-#endif
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
 #endif
        select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
        board_mux_lane_to_slot();
index fddd240f98a4c25ec55bd777535ecc1f044a7861..01dbf381bdc96441e4e801a0809fce88e77e3032 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include "t102xrdb.h"
@@ -151,10 +150,6 @@ int board_early_init_r(void)
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 #endif
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
 #ifdef CONFIG_T1024RDB
        board_mux_lane();
 #endif
index eaca57fc5dfe05efd65b49de70d6e51edf0cfff6..d7d56b47c816115b2a21c9ac859dc2ed2776816c 100644 (file)
@@ -15,7 +15,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include <hwconfig.h>
@@ -152,10 +151,6 @@ int board_early_init_r(void)
        set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
-#endif
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
 #endif
        select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
 
index 322765288b0881303c84d9df7c590f525c74748f..ec97677df84a541de575aeb4c621156bdd0a5be4 100644 (file)
@@ -16,7 +16,6 @@
 #include <asm/fsl_fdt.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include "../common/sleep.h"
@@ -84,11 +83,6 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 #endif
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        return 0;
 }
 
index 7c89cd5ee9a0735e3b505b9d0fddbbdb9530a902..bfea3a15562b47a8140f3d874f2f45cae3eb00ae 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 
@@ -356,11 +355,6 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        /* Disable remote I2C connection to qixis fpga */
        QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
 
index 0c2c1c565bdd115ad1332cfd43598bf710c19330..0cb05aa03f0788cac40011c16ed761bac18fd8da 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 #include "t208xrdb.h"
@@ -81,11 +80,6 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        /*
         * Adjust core voltage according to voltage ID
         * This function changes I2C mux to channel 2.
index 54410943f28123b693480bd32ff6873181de6942..f1393f25f92506b16d853f79b99dfa9657db19b9 100644 (file)
@@ -15,7 +15,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -56,11 +55,6 @@ int board_early_init_r(void)
                MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        return 0;
 }
 
index 4f2cccd709d6554dbda9fd30e432265fb9b3e0b2..d6df144730ba27120cb2b693b7f0910d0ba9823d 100644 (file)
@@ -15,7 +15,6 @@
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 
@@ -552,11 +551,6 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
-
        /* Disable remote I2C connection to qixis fpga */
        QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
 
index fac442bfc8c8e9ab68eda0a9be8ad5fb74914a28..406fb132aea131188b6ed919340e35ad14b9271a 100644 (file)
 #include <asm/immap_85xx.h>
 #include <asm/fsl_law.h>
 #include <asm/fsl_serdes.h>
-#include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 #include <fm_eth.h>
 
 #include "t4rdb.h"
 #include "cpld.h"
+#include "../common/vid.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -75,10 +75,12 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 
-       set_liodns();
-#ifdef CONFIG_SYS_DPAA_QBMAN
-       setup_portals();
-#endif
+       /*
+        * Adjust core voltage according to voltage ID
+        * This function changes I2C mux to channel 2.
+       */
+       if (adjust_vdd(0))
+               printf("Warning: Adjusting core voltage failed.\n");
 
        return 0;
 }
index 1b97a8fea85537307764cbb6731f9d4afffb966d..d12d74202c51a6ed1f6dc2d0eade9be6e4c865b7 100644 (file)
 
 int arch_early_init_r(void)
 {
-       struct udevice *dev;
-       int ret;
-
-       /* Make sure the platform controller hub is up and running */
-       ret = uclass_get_device(UCLASS_PCH, 0, &dev);
-       if (ret)
-               return ret;
-
        return 0;
 }
 
index 9f6494561c6a43378f899fda6d4702344b6cf63a..52a1906c7f0703f6d8dec93cd6f1486aa5aa6aa2 100644 (file)
@@ -113,6 +113,7 @@ static void set_mac_to_sh_giga_eth_register(int channel, char *mac_string)
        writel(val, &ether->malr);
 }
 
+#if defined(CONFIG_SH_32BIT)
 /*****************************************************************
  * This PMB must be set on this timing. The lowlevel_init is run on
  * Area 0(phys 0x00000000), so we have to map it.
@@ -154,13 +155,16 @@ static void set_pmb_on_board_init(void)
        writel(mk_pmb_addr_val(0x98), PMB_ADDR_BASE(7));
        writel(mk_pmb_data_val(0x58, 0, 1, 1, 0, 1, 1), PMB_DATA_BASE(7));
 }
+#endif
 
 int board_init(void)
 {
        struct gether_control_regs *gether = GETHER_CONTROL_BASE;
 
        init_gpio();
+#if defined(CONFIG_SH_32BIT)
        set_pmb_on_board_init();
+#endif
 
        /* Sets TXnDLY to B'010 */
        writel(0x00000202, &gether->gbecont);
index d891a3844ca3836284a907faa7e5514840bcdd84..eca218c9cf003d8bb95f31678e303dba6c1ae11a 100644 (file)
@@ -43,7 +43,7 @@ ulong flash_get_size (ulong base, int banknum);
 /* Local functions */
 static int detect_num_flash_banks(void);
 static long int get_ddr_bank_size(short cs, long *base);
-static void set_cs_bounds(short cs, long base, long size);
+static void set_cs_bounds(short cs, ulong base, ulong size);
 static void set_cs_config(short cs, long config);
 static void set_ddr_config(void);
 
@@ -314,7 +314,7 @@ static long int get_ddr_bank_size(short cs, long *base)
 /**************************************************************************
  * Sets DDR bank CS bounds.
  */
-static void set_cs_bounds(short cs, long base, long size)
+static void set_cs_bounds(short cs, ulong base, ulong size)
 {
        debug("Setting bounds %08lx, %08lx for cs %d\n", base, size, cs);
        if(size == 0){
diff --git a/cmd/Kconfig b/cmd/Kconfig
new file mode 100644 (file)
index 0000000..2ed0263
--- /dev/null
@@ -0,0 +1,585 @@
+menu "Command line interface"
+
+config HUSH_PARSER
+       bool "Use hush shell"
+       select SYS_HUSH_PARSER
+       help
+         This option enables the "hush" shell (from Busybox) as command line
+         interpreter, thus enabling powerful command line syntax like
+         if...then...else...fi conditionals or `&&' and '||'
+         constructs ("shell scripts").
+
+         If disabled, you get the old, much simpler behaviour with a somewhat
+         smaller memory footprint.
+
+config SYS_HUSH_PARSER
+       bool
+       help
+         Backward compatibility.
+
+config SYS_PROMPT
+       string "Shell prompt"
+       default "=> "
+       help
+         This string is displayed in the command line to the left of the
+         cursor.
+
+menu "Autoboot options"
+
+config AUTOBOOT_KEYED
+       bool "Stop autobooting via specific input key / string"
+       default n
+       help
+         This option enables stopping (aborting) of the automatic
+         boot feature only by issuing a specific input key or
+         string. If not enabled, any input key will abort the
+         U-Boot automatic booting process and bring the device
+         to the U-Boot prompt for user input.
+
+config AUTOBOOT_PROMPT
+       string "Autoboot stop prompt"
+       depends on AUTOBOOT_KEYED
+       default "Autoboot in %d seconds\\n"
+       help
+         This string is displayed before the boot delay selected by
+         CONFIG_BOOTDELAY starts. If it is not defined there is no
+         output indicating that autoboot is in progress.
+
+         Note that this define is used as the (only) argument to a
+         printf() call, so it may contain '%' format specifications,
+         provided that it also includes, sepearated by commas exactly
+         like in a printf statement, the required arguments. It is
+         the responsibility of the user to select only such arguments
+         that are valid in the given context.
+
+config AUTOBOOT_ENCRYPTION
+       bool "Enable encryption in autoboot stopping"
+       depends on AUTOBOOT_KEYED
+       default n
+
+config AUTOBOOT_DELAY_STR
+       string "Delay autobooting via specific input key / string"
+       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+       help
+         This option delays the automatic boot feature by issuing
+         a specific input key or string. If CONFIG_AUTOBOOT_DELAY_STR
+         or the environment variable "bootdelaykey" is specified
+         and this string is received from console input before
+         autoboot starts booting, U-Boot gives a command prompt. The
+         U-Boot prompt will time out if CONFIG_BOOT_RETRY_TIME is
+         used, otherwise it never times out.
+
+config AUTOBOOT_STOP_STR
+       string "Stop autobooting via specific input key / string"
+       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+       help
+         This option enables stopping (aborting) of the automatic
+         boot feature only by issuing a specific input key or
+         string. If CONFIG_AUTOBOOT_STOP_STR or the environment
+         variable "bootstopkey" is specified and this string is
+         received from console input before autoboot starts booting,
+         U-Boot gives a command prompt. The U-Boot prompt never
+         times out, even if CONFIG_BOOT_RETRY_TIME is used.
+
+config AUTOBOOT_KEYED_CTRLC
+       bool "Enable Ctrl-C autoboot interruption"
+       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+       default n
+       help
+         This option allows for the boot sequence to be interrupted
+         by ctrl-c, in addition to the "bootdelaykey" and "bootstopkey".
+         Setting this variable provides an escape sequence from the
+         limited "password" strings.
+
+config AUTOBOOT_STOP_STR_SHA256
+       string "Stop autobooting via SHA256 encrypted password"
+       depends on AUTOBOOT_KEYED && AUTOBOOT_ENCRYPTION
+       help
+         This option adds the feature to only stop the autobooting,
+         and therefore boot into the U-Boot prompt, when the input
+         string / password matches a values that is encypted via
+         a SHA256 hash and saved in the environment.
+
+endmenu
+
+comment "Commands"
+
+menu "Info commands"
+
+config CMD_BDI
+       bool "bdinfo"
+       default y
+       help
+         Print board info
+
+config CMD_CONSOLE
+       bool "coninfo"
+       default y
+       help
+         Print console devices and information.
+
+config CMD_CPU
+       bool "cpu"
+       help
+         Print information about available CPUs. This normally shows the
+         number of CPUs, type (e.g. manufacturer, architecture, product or
+         internal name) and clock frequency. Other information may be
+         available depending on the CPU driver.
+
+config CMD_LICENSE
+       bool "license"
+       help
+         Print GPL license text
+
+endmenu
+
+menu "Boot commands"
+
+config CMD_BOOTD
+       bool "bootd"
+       default y
+       help
+         Run the command stored in the environment "bootcmd", i.e.
+         "bootd" does the same thing as "run bootcmd".
+
+config CMD_BOOTM
+       bool "bootm"
+       default y
+       help
+         Boot an application image from the memory.
+
+config CMD_ELF
+       bool "bootelf, bootvx"
+       default y
+       help
+         Boot an ELF/vxWorks image from the memory.
+
+config CMD_GO
+       bool "go"
+       default y
+       help
+         Start an application at a given address.
+
+config CMD_RUN
+       bool "run"
+       default y
+       help
+         Run the command in the given environment variable.
+
+config CMD_IMI
+       bool "iminfo"
+       default y
+       help
+         Print header information for application image.
+
+config CMD_IMLS
+       bool "imls"
+       default y
+       help
+         List all images found in flash
+
+config CMD_XIMG
+       bool "imxtract"
+       default y
+       help
+         Extract a part of a multi-image.
+
+config CMD_POWEROFF
+       bool
+
+endmenu
+
+menu "Environment commands"
+
+config CMD_EXPORTENV
+       bool "env export"
+       default y
+       help
+         Export environments.
+
+config CMD_IMPORTENV
+       bool "env import"
+       default y
+       help
+         Import environments.
+
+config CMD_EDITENV
+       bool "editenv"
+       default y
+       help
+         Edit environment variable.
+
+config CMD_SAVEENV
+       bool "saveenv"
+       default y
+       help
+         Save all environment variables into the compiled-in persistent
+         storage.
+
+config CMD_ENV_EXISTS
+       bool "env exists"
+       default y
+       help
+         Check if a variable is defined in the environment for use in
+         shell scripting.
+
+endmenu
+
+menu "Memory commands"
+
+config CMD_MEMORY
+       bool "md, mm, nm, mw, cp, cmp, base, loop"
+       default y
+       help
+         Memeory commands.
+           md - memory display
+           mm - memory modify (auto-incrementing address)
+           nm - memory modify (constant address)
+           mw - memory write (fill)
+           cp - memory copy
+           cmp - memory compare
+           base - print or set address offset
+           loop - initinite loop on address range
+
+config CMD_CRC32
+       bool "crc32"
+       default y
+       help
+         Compute CRC32.
+
+config LOOPW
+       bool "loopw"
+       help
+         Infinite write loop on address range
+
+config CMD_MEMTEST
+       bool "memtest"
+       help
+         Simple RAM read/write test.
+
+config CMD_MX_CYCLIC
+       bool "mdc, mwc"
+       help
+         mdc - memory display cyclic
+         mwc - memory write cyclic
+
+config CMD_MEMINFO
+       bool "meminfo"
+       help
+         Display memory information.
+
+endmenu
+
+menu "Device access commands"
+
+config CMD_DM
+       bool "dm - Access to driver model information"
+       depends on DM
+       default y
+       help
+         Provides access to driver model data structures and information,
+         such as a list of devices, list of uclasses and the state of each
+         device (e.g. activated). This is not required for operation, but
+         can be useful to see the state of driver model for debugging or
+         interest.
+
+config CMD_DEMO
+       bool "demo - Demonstration commands for driver model"
+       depends on DM
+       help
+         Provides a 'demo' command which can be used to play around with
+         driver model. To use this properly you will need to enable one or
+         both of the demo devices (DM_DEMO_SHAPE and DM_DEMO_SIMPLE).
+         Otherwise you will always get an empty list of devices. The demo
+         devices are defined in the sandbox device tree, so the easiest
+         option is to use sandbox and pass the -d point to sandbox's
+         u-boot.dtb file.
+
+config CMD_LOADB
+       bool "loadb"
+       default y
+       help
+         Load a binary file over serial line.
+
+config CMD_LOADS
+       bool "loads"
+       default y
+       help
+         Load an S-Record file over serial line
+
+config CMD_FLASH
+       bool "flinfo, erase, protect"
+       default y
+       help
+         NOR flash support.
+           flinfo - print FLASH memory information
+           erase - FLASH memory
+           protect - enable or disable FLASH write protection
+
+config CMD_ARMFLASH
+       depends on FLASH_CFI_DRIVER
+       bool "armflash"
+       help
+         ARM Ltd reference designs flash partition access
+
+config CMD_NAND
+       bool "nand"
+       help
+         NAND support.
+
+config CMD_SF
+       bool "sf"
+       help
+         SPI Flash support
+
+config CMD_SPI
+       bool "sspi"
+       help
+         SPI utility command.
+
+config CMD_I2C
+       bool "i2c"
+       help
+         I2C support.
+
+config CMD_USB
+       bool "usb"
+       help
+         USB support.
+
+config CMD_FPGA
+       bool "fpga"
+       default y
+       help
+         FPGA support.
+
+config CMD_REMOTEPROC
+       bool "remoteproc"
+       depends on REMOTEPROC
+       help
+         Support for Remote Processor control
+
+config CMD_GPIO
+       bool "gpio"
+       help
+         GPIO support.
+
+endmenu
+
+
+menu "Shell scripting commands"
+
+config CMD_ECHO
+       bool "echo"
+       default y
+       help
+         Echo args to console
+
+config CMD_ITEST
+       bool "itest"
+       default y
+       help
+         Return true/false on integer compare.
+
+config CMD_SOURCE
+       bool "source"
+       default y
+       help
+         Run script from memory
+
+config CMD_SETEXPR
+       bool "setexpr"
+       default y
+       help
+         Evaluate boolean and math expressions and store the result in an env
+           variable.
+         Also supports loading the value at a memory location into a variable.
+         If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
+
+endmenu
+
+menu "Network commands"
+
+config CMD_NET
+       bool "bootp, tftpboot"
+        select NET
+       default y
+       help
+         Network commands.
+         bootp - boot image via network using BOOTP/TFTP protocol
+         tftpboot - boot image via network using TFTP protocol
+
+config CMD_TFTPPUT
+       bool "tftp put"
+       help
+         TFTP put command, for uploading files to a server
+
+config CMD_TFTPSRV
+       bool "tftpsrv"
+       help
+         Act as a TFTP server and boot the first received file
+
+config CMD_RARP
+       bool "rarpboot"
+       help
+         Boot image via network using RARP/TFTP protocol
+
+config CMD_DHCP
+       bool "dhcp"
+       help
+         Boot image via network using DHCP/TFTP protocol
+
+config CMD_NFS
+       bool "nfs"
+       default y
+       help
+         Boot image via network using NFS protocol.
+
+config CMD_PING
+       bool "ping"
+       help
+         Send ICMP ECHO_REQUEST to network host
+
+config CMD_CDP
+       bool "cdp"
+       help
+         Perform CDP network configuration
+
+config CMD_SNTP
+       bool "sntp"
+       help
+         Synchronize RTC via network
+
+config CMD_DNS
+       bool "dns"
+       help
+         Lookup the IP of a hostname
+
+config CMD_LINK_LOCAL
+       bool "linklocal"
+       help
+         Acquire a network IP address using the link-local protocol
+
+endmenu
+
+menu "Misc commands"
+
+config CMD_AMBAPP
+       bool "ambapp"
+       depends on LEON3
+       default y
+       help
+         Lists AMBA Plug-n-Play information.
+
+config SYS_AMBAPP_PRINT_ON_STARTUP
+       bool "Show AMBA PnP info on startup"
+       depends on CMD_AMBAPP
+       default n
+       help
+         Show AMBA Plug-n-Play information on startup.
+
+config CMD_TIME
+       bool "time"
+       help
+         Run commands and summarize execution time.
+
+# TODO: rename to CMD_SLEEP
+config CMD_MISC
+       bool "sleep"
+       default y
+       help
+         Delay execution for some time
+
+config CMD_TIMER
+       bool "timer"
+       help
+         Access the system timer.
+
+config CMD_SETGETDCR
+       bool "getdcr, setdcr, getidcr, setidcr"
+       depends on 4xx
+       default y
+       help
+         getdcr - Get an AMCC PPC 4xx DCR's value
+         setdcr - Set an AMCC PPC 4xx DCR's value
+         getidcr - Get a register value via indirect DCR addressing
+         setidcr - Set a register value via indirect DCR addressing
+
+config CMD_SOUND
+       bool "sound"
+       depends on SOUND
+       help
+         This provides basic access to the U-Boot's sound support. The main
+         feature is to play a beep.
+
+            sound init   - set up sound system
+            sound play   - play a sound
+
+endmenu
+
+config CMD_BOOTSTAGE
+       bool "Enable the 'bootstage' command"
+       depends on BOOTSTAGE
+       help
+         Add a 'bootstage' command which supports printing a report
+         and un/stashing of bootstage data.
+
+menu "Power commands"
+config CMD_PMIC
+       bool "Enable Driver Model PMIC command"
+       depends on DM_PMIC
+       help
+         This is the pmic command, based on a driver model pmic's API.
+         Command features are unchanged:
+         - list               - list pmic devices
+         - pmic dev <id>      - show or [set] operating pmic device (NEW)
+         - pmic dump          - dump registers
+         - pmic read address  - read byte of register at address
+         - pmic write address - write byte to register at address
+         The only one change for this command is 'dev' subcommand.
+
+config CMD_REGULATOR
+       bool "Enable Driver Model REGULATOR command"
+       depends on DM_REGULATOR
+       help
+         This command is based on driver model regulator's API.
+         User interface features:
+         - list               - list regulator devices
+         - regulator dev <id> - show or [set] operating regulator device
+         - regulator info     - print constraints info
+         - regulator status   - print operating status
+         - regulator value <val] <-f> - print/[set] voltage value [uV]
+         - regulator current <val>    - print/[set] current value [uA]
+         - regulator mode <id>        - print/[set] operating mode id
+         - regulator enable           - enable the regulator output
+         - regulator disable          - disable the regulator output
+
+         The '-f' (force) option can be used for set the value which exceeds
+         the limits, which are found in device-tree and are kept in regulator's
+         uclass platdata structure.
+
+endmenu
+
+menu "Security commands"
+config CMD_TPM
+       bool "Enable the 'tpm' command"
+       depends on TPM
+       help
+         This provides a means to talk to a TPM from the command line. A wide
+         range of commands if provided - see 'tpm help' for details. The
+         command requires a suitable TPM on your board and the correct driver
+         must be enabled.
+
+config CMD_TPM_TEST
+       bool "Enable the 'tpm test' command"
+       depends on CMD_TPM
+       help
+         This provides a a series of tests to confirm that the TPM is working
+         correctly. The tests cover initialisation, non-volatile RAM, extend,
+         global lock and checking that timing is within expectations. The
+         tests pass correctly on Infineon TPMs but may need to be adjusted
+         for other devices.
+
+endmenu
+
+endmenu
diff --git a/cmd/Makefile b/cmd/Makefile
new file mode 100644 (file)
index 0000000..03f7e0a
--- /dev/null
@@ -0,0 +1,166 @@
+#
+# (C) Copyright 2004-2006
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+ifndef CONFIG_SPL_BUILD
+# core command
+obj-y += boot.o
+obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-y += help.o
+obj-y += version.o
+
+# command
+obj-$(CONFIG_CMD_AES) += aes.o
+obj-$(CONFIG_CMD_AMBAPP) += ambapp.o
+obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
+obj-$(CONFIG_SOURCE) += source.o
+obj-$(CONFIG_CMD_SOURCE) += source.o
+obj-$(CONFIG_CMD_BDI) += bdinfo.o
+obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
+obj-$(CONFIG_CMD_BMP) += bmp.o
+obj-$(CONFIG_CMD_BOOTMENU) += bootmenu.o
+obj-$(CONFIG_CMD_BOOTLDR) += bootldr.o
+obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o
+obj-$(CONFIG_CMD_CACHE) += cache.o
+obj-$(CONFIG_CMD_CBFS) += cbfs.o
+obj-$(CONFIG_CMD_CLK) += clk.o
+obj-$(CONFIG_CMD_CONSOLE) += console.o
+obj-$(CONFIG_CMD_CPLBINFO) += cplbinfo.o
+obj-$(CONFIG_CMD_CPU) += cpu.o
+obj-$(CONFIG_DATAFLASH_MMC_SELECT) += dataflash_mmc_mux.o
+obj-$(CONFIG_CMD_DATE) += date.o
+obj-$(CONFIG_CMD_DEMO) += demo.o
+obj-$(CONFIG_CMD_SOUND) += sound.o
+ifdef CONFIG_4xx
+obj-$(CONFIG_CMD_SETGETDCR) += dcr.o
+endif
+ifdef CONFIG_POST
+obj-$(CONFIG_CMD_DIAG) += diag.o
+endif
+obj-$(CONFIG_CMD_DISPLAY) += display.o
+obj-$(CONFIG_CMD_DTT) += dtt.o
+obj-$(CONFIG_CMD_ECHO) += echo.o
+obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
+obj-$(CONFIG_CMD_EEPROM) += eeprom.o
+obj-$(CONFIG_EFI_STUB) += efi.o
+obj-$(CONFIG_CMD_ELF) += elf.o
+obj-$(CONFIG_SYS_HUSH_PARSER) += exit.o
+obj-$(CONFIG_CMD_EXT4) += ext4.o
+obj-$(CONFIG_CMD_EXT2) += ext2.o
+obj-$(CONFIG_CMD_FAT) += fat.o
+obj-$(CONFIG_CMD_FDC) += fdc.o
+obj-$(CONFIG_OF_LIBFDT) += fdt.o
+obj-$(CONFIG_CMD_FITUPD) += fitupd.o
+obj-$(CONFIG_CMD_FLASH) += flash.o
+ifdef CONFIG_FPGA
+obj-$(CONFIG_CMD_FPGA) += fpga.o
+endif
+obj-$(CONFIG_CMD_FPGAD) += fpgad.o
+obj-$(CONFIG_CMD_FS_GENERIC) += fs.o
+obj-$(CONFIG_CMD_FUSE) += fuse.o
+obj-$(CONFIG_CMD_GETTIME) += gettime.o
+obj-$(CONFIG_CMD_GPIO) += gpio.o
+obj-$(CONFIG_CMD_I2C) += i2c.o
+obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
+obj-$(CONFIG_CMD_HASH) += hash.o
+obj-$(CONFIG_CMD_IDE) += ide.o
+obj-$(CONFIG_CMD_IMMAP) += immap.o
+obj-$(CONFIG_CMD_INI) += ini.o
+obj-$(CONFIG_CMD_IRQ) += irq.o
+obj-$(CONFIG_CMD_ITEST) += itest.o
+obj-$(CONFIG_CMD_JFFS2) += jffs2.o
+obj-$(CONFIG_CMD_CRAMFS) += cramfs.o
+obj-$(CONFIG_CMD_LDRINFO) += ldrinfo.o
+obj-$(CONFIG_CMD_LED) += led.o
+obj-$(CONFIG_CMD_LICENSE) += license.o
+obj-y += load.o
+obj-$(CONFIG_LOGBUFFER) += log.o
+obj-$(CONFIG_ID_EEPROM) += mac.o
+obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
+obj-$(CONFIG_CMD_MEMORY) += mem.o
+obj-$(CONFIG_CMD_IO) += io.o
+obj-$(CONFIG_CMD_MFSL) += mfsl.o
+obj-$(CONFIG_CMD_MII) += mii.o
+ifdef CONFIG_PHYLIB
+obj-$(CONFIG_CMD_MII) += mdio.o
+endif
+obj-$(CONFIG_CMD_MISC) += misc.o
+obj-$(CONFIG_CMD_MMC) += mmc.o
+obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
+obj-$(CONFIG_MP) += mp.o
+obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
+obj-$(CONFIG_CMD_NAND) += nand.o
+obj-$(CONFIG_CMD_NET) += net.o
+obj-$(CONFIG_CMD_ONENAND) += onenand.o
+obj-$(CONFIG_CMD_OTP) += otp.o
+obj-$(CONFIG_CMD_PART) += part.o
+ifdef CONFIG_PCI
+obj-$(CONFIG_CMD_PCI) += pci.o
+endif
+obj-y += pcmcia.o
+obj-$(CONFIG_CMD_PORTIO) += portio.o
+obj-$(CONFIG_CMD_PXE) += pxe.o
+obj-$(CONFIG_CMD_READ) += read.o
+obj-$(CONFIG_CMD_REGINFO) += reginfo.o
+obj-$(CONFIG_CMD_REISER) += reiser.o
+obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o
+obj-$(CONFIG_SANDBOX) += host.o
+obj-$(CONFIG_CMD_SATA) += sata.o
+obj-$(CONFIG_CMD_SF) += sf.o
+obj-$(CONFIG_CMD_SCSI) += scsi.o
+obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
+obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
+obj-$(CONFIG_CMD_SOFTSWITCH) += softswitch.o
+obj-$(CONFIG_CMD_SPI) += spi.o
+obj-$(CONFIG_CMD_SPIBOOTLDR) += spibootldr.o
+obj-$(CONFIG_CMD_STRINGS) += strings.o
+obj-$(CONFIG_CMD_TERMINAL) += terminal.o
+obj-$(CONFIG_CMD_TIME) += time.o
+obj-$(CONFIG_CMD_TRACE) += trace.o
+obj-$(CONFIG_SYS_HUSH_PARSER) += test.o
+obj-$(CONFIG_CMD_TPM) += tpm.o
+obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
+obj-$(CONFIG_CMD_TSI148) += tsi148.o
+obj-$(CONFIG_CMD_UBI) += ubi.o
+obj-$(CONFIG_CMD_UBIFS) += ubifs.o
+obj-$(CONFIG_CMD_UNIVERSE) += universe.o
+obj-$(CONFIG_CMD_UNZIP) += unzip.o
+ifdef CONFIG_LZMA
+obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
+endif
+
+obj-$(CONFIG_CMD_USB) += usb.o
+obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o
+obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o
+
+obj-$(CONFIG_CMD_USB_MASS_STORAGE) += usb_mass_storage.o
+obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o
+obj-$(CONFIG_CMD_XIMG) += ximg.o
+obj-$(CONFIG_YAFFS2) += yaffs2.o
+obj-$(CONFIG_CMD_SPL) += spl.o
+obj-$(CONFIG_CMD_ZIP) += zip.o
+obj-$(CONFIG_CMD_ZFS) += zfs.o
+
+obj-$(CONFIG_CMD_DFU) += dfu.o
+obj-$(CONFIG_CMD_GPT) += gpt.o
+obj-$(CONFIG_CMD_ETHSW) += ethsw.o
+
+# Power
+obj-$(CONFIG_CMD_PMIC) += pmic.o
+obj-$(CONFIG_CMD_REGULATOR) += regulator.o
+endif # !CONFIG_SPL_BUILD
+
+ifdef CONFIG_SPL_BUILD
+ifdef CONFIG_SPL_SATA_SUPPORT
+obj-$(CONFIG_CMD_SCSI) += scsi.o
+endif
+endif # CONFIG_SPL_BUILD
+
+obj-$(CONFIG_CMD_BLOB) += blob.o
+
+# core command
+obj-y += nvedit.o
+obj-y += disk.o
diff --git a/cmd/aes.c b/cmd/aes.c
new file mode 100644 (file)
index 0000000..76da3ef
--- /dev/null
+++ b/cmd/aes.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2014 Marek Vasut <marex@denx.de>
+ *
+ * Command for en/de-crypting block of memory with AES-128-CBC cipher.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <aes.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * do_aes() - Handle the "aes" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       uint32_t key_addr, src_addr, dst_addr, len;
+       uint8_t *key_ptr, *src_ptr, *dst_ptr;
+       uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
+       uint32_t aes_blocks;
+       int enc;
+
+       if (argc != 6)
+               return CMD_RET_USAGE;
+
+       if (!strncmp(argv[1], "enc", 3))
+               enc = 1;
+       else if (!strncmp(argv[1], "dec", 3))
+               enc = 0;
+       else
+               return CMD_RET_USAGE;
+
+       key_addr = simple_strtoul(argv[2], NULL, 16);
+       src_addr = simple_strtoul(argv[3], NULL, 16);
+       dst_addr = simple_strtoul(argv[4], NULL, 16);
+       len = simple_strtoul(argv[5], NULL, 16);
+
+       key_ptr = (uint8_t *)key_addr;
+       src_ptr = (uint8_t *)src_addr;
+       dst_ptr = (uint8_t *)dst_addr;
+
+       /* First we expand the key. */
+       aes_expand_key(key_ptr, key_exp);
+
+       /* Calculate the number of AES blocks to encrypt. */
+       aes_blocks = DIV_ROUND_UP(len, AES_KEY_LENGTH);
+
+       if (enc)
+               aes_cbc_encrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks);
+       else
+               aes_cbc_decrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks);
+
+       return 0;
+}
+
+/***************************************************/
+#ifdef CONFIG_SYS_LONGHELP
+static char aes_help_text[] =
+       "enc key src dst len - Encrypt block of data $len bytes long\n"
+       "                          at address $src using a key at address\n"
+       "                          $key and store the result at address\n"
+       "                          $dst. The $len size must be multiple of\n"
+       "                          16 bytes and $key must be 16 bytes long.\n"
+       "aes dec key src dst len - Decrypt block of data $len bytes long\n"
+       "                          at address $src using a key at address\n"
+       "                          $key and store the result at address\n"
+       "                          $dst. The $len size must be multiple of\n"
+       "                          16 bytes and $key must be 16 bytes long.";
+#endif
+
+U_BOOT_CMD(
+       aes, 6, 1, do_aes,
+       "AES 128 CBC encryption",
+       aes_help_text
+);
diff --git a/cmd/ambapp.c b/cmd/ambapp.c
new file mode 100644 (file)
index 0000000..4b6d174
--- /dev/null
@@ -0,0 +1,575 @@
+/*
+ * (C) Copyright 2007
+ * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * AMBA Plug&Play information list command
+ *
+ */
+#include <common.h>
+#include <command.h>
+#include <ambapp.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+typedef struct {
+       int device_id;
+       char *name;
+       char *desc;
+} ambapp_device_name;
+
+typedef struct {
+       unsigned int vendor_id;
+       char *name;
+       char *desc;
+       ambapp_device_name *devices;
+} ambapp_vendor_devnames;
+
+/** Vendor GAISLER devices */
+static ambapp_device_name GAISLER_devices[] = {
+       {GAISLER_LEON2DSU, "LEON2DSU", "Leon2 Debug Support Unit"},
+       {GAISLER_LEON3, "LEON3", "Leon3 SPARC V8 Processor"},
+       {GAISLER_LEON3DSU, "LEON3DSU", "Leon3 Debug Support Unit"},
+       {GAISLER_ETHAHB, "ETHAHB", "OC ethernet AHB interface"},
+       {GAISLER_APBMST, "APBMST", "AHB/APB Bridge"},
+       {GAISLER_AHBUART, "AHBUART", "AHB Debug UART"},
+       {GAISLER_SRCTRL, "SRCTRL", "Simple SRAM Controller"},
+       {GAISLER_SDCTRL, "SDCTRL", "PC133 SDRAM Controller"},
+       {GAISLER_SSRCTRL, "SSRCTRL", "Synchronous SRAM Controller"},
+       {GAISLER_APBUART, "APBUART", "Generic UART"},
+       {GAISLER_IRQMP, "IRQMP", "Multi-processor Interrupt Ctrl."},
+       {GAISLER_AHBRAM, "AHBRAM", "Single-port AHB SRAM module"},
+       {GAISLER_AHBDPRAM, "AHBDPRAM", "Dual-port AHB SRAM module"},
+       {GAISLER_GPTIMER, "GPTIMER", "Modular Timer Unit"},
+       {GAISLER_PCITRG, "PCITRG", "Simple 32-bit PCI Target"},
+       {GAISLER_PCISBRG, "PCISBRG", "Simple 32-bit PCI Bridge"},
+       {GAISLER_PCIFBRG, "PCIFBRG", "Fast 32-bit PCI Bridge"},
+       {GAISLER_PCITRACE, "PCITRACE", "32-bit PCI Trace Buffer"},
+       {GAISLER_DMACTRL, "DMACTRL", "AMBA DMA controller"},
+       {GAISLER_AHBTRACE, "AHBTRACE", "AMBA Trace Buffer"},
+       {GAISLER_DSUCTRL, "DSUCTRL", "DSU/ETH controller"},
+       {GAISLER_CANAHB, "CANAHB", "OC CAN AHB interface"},
+       {GAISLER_GPIO, "GPIO", "General Purpose I/O port"},
+       {GAISLER_AHBROM, "AHBROM", "Generic AHB ROM"},
+       {GAISLER_AHBJTAG, "AHBJTAG", "JTAG Debug Link"},
+       {GAISLER_ETHMAC, "ETHMAC", "GR Ethernet MAC"},
+       {GAISLER_SWNODE, "SWNODE", "SpaceWire Node Interface"},
+       {GAISLER_SPW, "SPW", "SpaceWire Serial Link"},
+       {GAISLER_AHB2AHB, "AHB2AHB", "AHB-to-AHB Bridge"},
+       {GAISLER_USBDC, "USBDC", "GR USB 2.0 Device Controller"},
+       {GAISLER_USB_DCL, "USB_DCL", "USB Debug Communication Link"},
+       {GAISLER_DDRMP, "DDRMP", "Multi-port DDR controller"},
+       {GAISLER_ATACTRL, "ATACTRL", "ATA controller"},
+       {GAISLER_DDRSP, "DDRSP", "Single-port DDR266 controller"},
+       {GAISLER_EHCI, "EHCI", "USB Enhanced Host Controller"},
+       {GAISLER_UHCI, "UHCI", "USB Universal Host Controller"},
+       {GAISLER_I2CMST, "I2CMST", "AMBA Wrapper for OC I2C-master"},
+       {GAISLER_SPW2, "SPW2", "GRSPW2 SpaceWire Serial Link"},
+       {GAISLER_AHBDMA, "AHBDMA", ""},
+       {GAISLER_NUHOSP3, "NUHOSP3", "Nuhorizons Spartan3 IO I/F"},
+       {GAISLER_CLKGATE, "CLKGATE", "Clock gating unit"},
+       {GAISLER_SPICTRL, "SPICTRL", "SPI Controller"},
+       {GAISLER_DDR2SP, "DDR2SP", "Single-port DDR2 controller"},
+       {GAISLER_SLINK, "SLINK", "SLINK Master"},
+       {GAISLER_GRTM, "GRTM", "CCSDS Telemetry Encoder"},
+       {GAISLER_GRTC, "GRTC", "CCSDS Telecommand Decoder"},
+       {GAISLER_GRPW, "GRPW", "PacketWire to AMBA AHB I/F"},
+       {GAISLER_GRCTM, "GRCTM", "CCSDS Time Manager"},
+       {GAISLER_GRHCAN, "GRHCAN", "ESA HurriCANe CAN with DMA"},
+       {GAISLER_GRFIFO, "GRFIFO", "FIFO Controller"},
+       {GAISLER_GRADCDAC, "GRADCDAC", "ADC / DAC Interface"},
+       {GAISLER_GRPULSE, "GRPULSE", "General Purpose I/O with Pulses"},
+       {GAISLER_GRTIMER, "GRTIMER", "Timer Unit with Latches"},
+       {GAISLER_AHB2PP, "AHB2PP", "AMBA AHB to Packet Parallel I/F"},
+       {GAISLER_GRVERSION, "GRVERSION", "Version and Revision Register"},
+       {GAISLER_APB2PW, "APB2PW", "PacketWire Transmit Interface"},
+       {GAISLER_PW2APB, "PW2APB", "PacketWire Receive Interface"},
+       {GAISLER_GRCAN, "GRCAN", "CAN Controller with DMA"},
+       {GAISLER_I2CSLV, "I2CSLV", "I2C Slave"},
+       {GAISLER_U16550, "U16550", "Simple 16550 UART"},
+       {GAISLER_AHBMST_EM, "AHBMST_EM", "AMBA Master Emulator"},
+       {GAISLER_AHBSLV_EM, "AHBSLV_EM", "AMBA Slave Emulator"},
+       {GAISLER_GRTESTMOD, "GRTESTMOD", "Test report module"},
+       {GAISLER_ASCS, "ASCS", "ASCS Master"},
+       {GAISLER_IPMVBCTRL, "IPMVBCTRL", "IPM-bus/MVBC memory controller"},
+       {GAISLER_SPIMCTRL, "SPIMCTRL", "SPI Memory Controller"},
+       {GAISLER_L4STAT, "L4STAT", "Leon4 Statistics Module"},
+       {GAISLER_LEON4, "LEON4", "Leon4 SPARC V8 Processor"},
+       {GAISLER_LEON4DSU, "LEON4DSU", "Leon4 Debug Support Unit"},
+       {GAISLER_PWM, "PWM", "PWM generator"},
+       {GAISLER_L2CACHE, "L2CACHE", "L2-Cache Controller"},
+       {GAISLER_SDCTRL64, "SDCTRL64", "64-bit PC133 SDRAM Controller"},
+       {GAISLER_GR1553B, "GR1553B", "MIL-STD-1553B Interface"},
+       {GAISLER_1553TST, "1553TST", "MIL-STD-1553B Test Device"},
+       {GAISLER_GRIOMMU, "GRIOMMU", "I/O Memory Management Unit"},
+       {GAISLER_FTAHBRAM, "FTAHBRAM", "Generic FT AHB SRAM module"},
+       {GAISLER_FTSRCTRL, "FTSRCTRL", "Simple FT SRAM Controller"},
+       {GAISLER_AHBSTAT, "AHBSTAT", "AHB Status Register"},
+       {GAISLER_LEON3FT, "LEON3FT", "Leon3-FT SPARC V8 Processor"},
+       {GAISLER_FTMCTRL, "FTMCTRL", "Memory controller with EDAC"},
+       {GAISLER_FTSDCTRL, "FTSDCTRL", "FT PC133 SDRAM Controller"},
+       {GAISLER_FTSRCTRL8, "FTSRCTRL8", "FT 8-bit SRAM/16-bit IO Ctrl"},
+       {GAISLER_MEMSCRUB, "MEMSCRUB", "AHB Memory Scrubber"},
+       {GAISLER_FTSDCTRL64, "FTSDCTRL64", "64-bit FT SDRAM Controller"},
+       {GAISLER_APBPS2, "APBPS2", "PS2 interface"},
+       {GAISLER_VGACTRL, "VGACTRL", "VGA controller"},
+       {GAISLER_LOGAN, "LOGAN", "On chip Logic Analyzer"},
+       {GAISLER_SVGACTRL, "SVGACTRL", "SVGA frame buffer"},
+       {GAISLER_T1AHB, "T1AHB", "Niagara T1 PCX/AHB bridge"},
+       {GAISLER_MP7WRAP, "MP7WRAP", "CoreMP7 wrapper"},
+       {GAISLER_GRSYSMON, "GRSYSMON", "AMBA wrapper for System Monitor"},
+       {GAISLER_GRACECTRL, "GRACECTRL", "System ACE I/F Controller"},
+       {GAISLER_ATAHBSLV, "ATAHBSLV", "AMBA Test Framework AHB Slave"},
+       {GAISLER_ATAHBMST, "ATAHBMST", "AMBA Test Framework AHB Master"},
+       {GAISLER_ATAPBSLV, "ATAPBSLV", "AMBA Test Framework APB Slave"},
+       {GAISLER_B1553BC, "B1553BC", "AMBA Wrapper for Core1553BBC"},
+       {GAISLER_B1553RT, "B1553RT", "AMBA Wrapper for Core1553BRT"},
+       {GAISLER_B1553BRM, "B1553BRM", "AMBA Wrapper for Core1553BRM"},
+       {GAISLER_AES, "AES", "Advanced Encryption Standard"},
+       {GAISLER_ECC, "ECC", "Elliptic Curve Cryptography"},
+       {GAISLER_PCIF, "PCIF", "AMBA Wrapper for CorePCIF"},
+       {GAISLER_CLKMOD, "CLKMOD", "CPU Clock Switching Ctrl module"},
+       {GAISLER_HAPSTRAK, "HAPSTRAK", "HAPS HapsTrak I/O Port"},
+       {GAISLER_TEST_1X2, "TEST_1X2", "HAPS TEST_1x2 interface"},
+       {GAISLER_WILD2AHB, "WILD2AHB", "WildCard CardBus interface"},
+       {GAISLER_BIO1, "BIO1", "Basic I/O board BIO1"},
+       {GAISLER_AESDMA, "AESDMA", "AES 256 DMA"},
+       {GAISLER_SATCAN, "SATCAN", "SatCAN controller"},
+       {GAISLER_CANMUX, "CANMUX", "CAN Bus multiplexer"},
+       {GAISLER_GRTMRX, "GRTMRX", "CCSDS Telemetry Receiver"},
+       {GAISLER_GRTCTX, "GRTCTX", "CCSDS Telecommand Transmitter"},
+       {GAISLER_GRTMDESC, "GRTMDESC", "CCSDS Telemetry Descriptor"},
+       {GAISLER_GRTMVC, "GRTMVC", "CCSDS Telemetry VC Generator"},
+       {GAISLER_GEFFE, "GEFFE", "Geffe Generator"},
+       {GAISLER_GPREG, "GPREG", "General Purpose Register"},
+       {GAISLER_GRTMPAHB, "GRTMPAHB", "CCSDS Telemetry VC AHB Input"},
+       {GAISLER_SPWCUC, "SPWCUC", "CCSDS CUC / SpaceWire I/F"},
+       {GAISLER_SPW2_DMA, "SPW2_DMA", "GRSPW Router DMA interface"},
+       {GAISLER_SPWROUTER, "SPWROUTER", "GRSPW Router"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor PENDER devices */
+static ambapp_device_name PENDER_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor ESA devices */
+static ambapp_device_name ESA_devices[] = {
+       {ESA_LEON2, "LEON2", "Leon2 SPARC V8 Processor"},
+       {ESA_LEON2APB, "LEON2APB", "Leon2 Peripheral Bus"},
+       {ESA_IRQ, "IRQ", "Leon2 Interrupt Controller"},
+       {ESA_TIMER, "TIMER", "Leon2 Timer"},
+       {ESA_UART, "UART", "Leon2 UART"},
+       {ESA_CFG, "CFG", "Leon2 Configuration Register"},
+       {ESA_IO, "IO", "Leon2 Input/Output"},
+       {ESA_MCTRL, "MCTRL", "Leon2 Memory Controller"},
+       {ESA_PCIARB, "PCIARB", "PCI Arbiter"},
+       {ESA_HURRICANE, "HURRICANE", "HurriCANe/HurryAMBA CAN Ctrl"},
+       {ESA_SPW_RMAP, "SPW_RMAP", "UoD/Saab SpaceWire/RMAP link"},
+       {ESA_AHBUART, "AHBUART", "Leon2 AHB Debug UART"},
+       {ESA_SPWA, "SPWA", "ESA/ASTRIUM SpaceWire link"},
+       {ESA_BOSCHCAN, "BOSCHCAN", "SSC/BOSCH CAN Ctrl"},
+       {ESA_IRQ2, "IRQ2", "Leon2 Secondary Irq Controller"},
+       {ESA_AHBSTAT, "AHBSTAT", "Leon2 AHB Status Register"},
+       {ESA_WPROT, "WPROT", "Leon2 Write Protection"},
+       {ESA_WPROT2, "WPROT2", "Leon2 Extended Write Protection"},
+       {ESA_PDEC3AMBA, "PDEC3AMBA", "ESA CCSDS PDEC3AMBA TC Decoder"},
+       {ESA_PTME3AMBA, "PTME3AMBA", "ESA CCSDS PTME3AMBA TM Encoder"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor ASTRIUM devices */
+static ambapp_device_name ASTRIUM_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor OPENCHIP devices */
+static ambapp_device_name OPENCHIP_devices[] = {
+       {OPENCHIP_APBGPIO, "APBGPIO", "APB General Purpose IO"},
+       {OPENCHIP_APBI2C, "APBI2C", "APB I2C Interface"},
+       {OPENCHIP_APBSPI, "APBSPI", "APB SPI Interface"},
+       {OPENCHIP_APBCHARLCD, "APBCHARLCD", "APB Character LCD"},
+       {OPENCHIP_APBPWM, "APBPWM", "APB PWM"},
+       {OPENCHIP_APBPS2, "APBPS2", "APB PS/2 Interface"},
+       {OPENCHIP_APBMMCSD, "APBMMCSD", "APB MMC/SD Card Interface"},
+       {OPENCHIP_APBNAND, "APBNAND", "APB NAND(SmartMedia) Interface"},
+       {OPENCHIP_APBLPC, "APBLPC", "APB LPC Interface"},
+       {OPENCHIP_APBCF, "APBCF", "APB CompactFlash (IDE)"},
+       {OPENCHIP_APBSYSACE, "APBSYSACE", "APB SystemACE Interface"},
+       {OPENCHIP_APB1WIRE, "APB1WIRE", "APB 1-Wire Interface"},
+       {OPENCHIP_APBJTAG, "APBJTAG", "APB JTAG TAP Master"},
+       {OPENCHIP_APBSUI, "APBSUI", "APB Simple User Interface"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor OPENCORES devices */
+static ambapp_device_name OPENCORES_devices[] = {
+       {OPENCORES_PCIBR, "PCIBR", "PCI Bridge"},
+       {OPENCORES_ETHMAC, "ETHMAC", "Ethernet MAC"},
+       {0, NULL}
+};
+
+
+/** Vendor CONTRIB devices */
+static ambapp_device_name CONTRIB_devices[] = {
+       {CONTRIB_CORE1, "CORE1", "Contributed core 1"},
+       {CONTRIB_CORE2, "CORE2", "Contributed core 2"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor EONIC devices */
+static ambapp_device_name EONIC_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor RADIONOR devices */
+static ambapp_device_name RADIONOR_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor GLEICHMANN devices */
+static ambapp_device_name GLEICHMANN_devices[] = {
+       {GLEICHMANN_CUSTOM, "CUSTOM", "Custom device"},
+       {GLEICHMANN_GEOLCD01, "GEOLCD01", "GEOLCD01 graphics system"},
+       {GLEICHMANN_DAC, "DAC", "Sigma delta DAC"},
+       {GLEICHMANN_HPI, "HPI", "AHB-to-HPI bridge"},
+       {GLEICHMANN_SPI, "SPI", "SPI master"},
+       {GLEICHMANN_HIFC, "HIFC", "Human interface controller"},
+       {GLEICHMANN_ADCDAC, "ADCDAC", "Sigma delta ADC/DAC"},
+       {GLEICHMANN_SPIOC, "SPIOC", ""},
+       {GLEICHMANN_AC97, "AC97", ""},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor MENTA devices */
+static ambapp_device_name MENTA_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor SUN devices */
+static ambapp_device_name SUN_devices[] = {
+       {SUN_T1, "T1", "Niagara T1 SPARC V9 Processor"},
+       {SUN_S1, "S1", "Niagara S1 SPARC V9 Processor"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor MOVIDIA devices */
+static ambapp_device_name MOVIDIA_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor ORBITA devices */
+static ambapp_device_name ORBITA_devices[] = {
+       {ORBITA_1553B, "1553B", "MIL-STD-1553B Controller"},
+       {ORBITA_429, "429", "429 Interface"},
+       {ORBITA_SPI, "SPI", "SPI Interface"},
+       {ORBITA_I2C, "I2C", "I2C Interface"},
+       {ORBITA_SMARTCARD, "SMARTCARD", "Smart Card Reader"},
+       {ORBITA_SDCARD, "SDCARD", "SD Card Reader"},
+       {ORBITA_UART16550, "UART16550", "16550 UART"},
+       {ORBITA_CRYPTO, "CRYPTO", "Crypto Engine"},
+       {ORBITA_SYSIF, "SYSIF", "System Interface"},
+       {ORBITA_PIO, "PIO", "Programmable IO module"},
+       {ORBITA_RTC, "RTC", "Real-Time Clock"},
+       {ORBITA_COLORLCD, "COLORLCD", "Color LCD Controller"},
+       {ORBITA_PCI, "PCI", "PCI Module"},
+       {ORBITA_DSP, "DSP", "DPS Co-Processor"},
+       {ORBITA_USBHOST, "USBHOST", "USB Host"},
+       {ORBITA_USBDEV, "USBDEV", "USB Device"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor SYNOPSYS devices */
+static ambapp_device_name SYNOPSYS_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor NASA devices */
+static ambapp_device_name NASA_devices[] = {
+       {NASA_EP32, "EP32", "EP32 Forth processor"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor CAL devices */
+static ambapp_device_name CAL_devices[] = {
+       {CAL_DDRCTRL, "DDRCTRL", ""},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor EMBEDDIT devices */
+static ambapp_device_name EMBEDDIT_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor CETON devices */
+static ambapp_device_name CETON_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor S3 devices */
+static ambapp_device_name S3_devices[] = {
+       {0, NULL, NULL}
+};
+
+
+/** Vendor ACTEL devices */
+static ambapp_device_name ACTEL_devices[] = {
+       {ACTEL_COREMP7, "COREMP7", "CoreMP7 Processor"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendor APPLECORE devices */
+static ambapp_device_name APPLECORE_devices[] = {
+       {APPLECORE_UTLEON3, "UTLEON3", "AppleCore uT-LEON3 Processor"},
+       {APPLECORE_UTLEON3DSU, "UTLEON3DSU", "AppleCore uT-LEON3 DSU"},
+       {0, NULL, NULL}
+};
+
+
+/** Vendors and their devices */
+static ambapp_vendor_devnames vendors[] = {
+       {VENDOR_GAISLER, "GAISLER", "Gaisler Research", GAISLER_devices},
+       {VENDOR_PENDER, "PENDER", "", PENDER_devices},
+       {VENDOR_ESA, "ESA", "European Space Agency", ESA_devices},
+       {VENDOR_ASTRIUM, "ASTRIUM", "", ASTRIUM_devices},
+       {VENDOR_OPENCHIP, "OPENCHIP", "OpenChip", OPENCHIP_devices},
+       {VENDOR_OPENCORES, "OPENCORES", "OpenCores", OPENCORES_devices},
+       {VENDOR_CONTRIB, "CONTRIB", "Various contributions", CONTRIB_devices},
+       {VENDOR_EONIC, "EONIC", "Eonic BV", EONIC_devices},
+       {VENDOR_RADIONOR, "RADIONOR", "Radionor Communications", RADIONOR_devices},
+       {VENDOR_GLEICHMANN, "GLEICHMANN", "Gleichmann Electronics", GLEICHMANN_devices},
+       {VENDOR_MENTA, "MENTA", "Menta", MENTA_devices},
+       {VENDOR_SUN, "SUN", "Sun Microsystems", SUN_devices},
+       {VENDOR_MOVIDIA, "MOVIDIA", "", MOVIDIA_devices},
+       {VENDOR_ORBITA, "ORBITA", "Orbita", ORBITA_devices},
+       {VENDOR_SYNOPSYS, "SYNOPSYS", "Synopsys Inc.", SYNOPSYS_devices},
+       {VENDOR_NASA, "NASA", "NASA", NASA_devices},
+       {VENDOR_S3, "S3", "S3 Group", S3_devices},
+       {VENDOR_CAL, "CAL", "", CAL_devices},
+       {VENDOR_EMBEDDIT, "EMBEDDIT", "Embedd.it", EMBEDDIT_devices},
+       {VENDOR_CETON, "CETON", "Ceton Corporation", CETON_devices},
+       {VENDOR_ACTEL, "ACTEL", "Actel Corporation", ACTEL_devices},
+       {VENDOR_APPLECORE, "APPLECORE", "AppleCore", APPLECORE_devices},
+       {0, NULL, NULL, NULL}
+};
+
+static ambapp_device_name *ambapp_get_dev(ambapp_device_name *devs, int id)
+{
+       if (!devs)
+               return NULL;
+
+       while (devs->device_id > 0) {
+               if (devs->device_id == id)
+                       return devs;
+               devs++;
+       }
+       return NULL;
+}
+
+char *ambapp_device_id2str(int vendor, int id)
+{
+       ambapp_vendor_devnames *ven = &vendors[0];
+       ambapp_device_name *dev;
+
+       while (ven->vendor_id > 0) {
+               if (ven->vendor_id == vendor) {
+                       dev = ambapp_get_dev(ven->devices, id);
+                       if (!dev)
+                               return NULL;
+                       return dev->name;
+               }
+               ven++;
+       }
+       return NULL;
+}
+
+char *ambapp_device_id2desc(int vendor, int id)
+{
+       ambapp_vendor_devnames *ven = &vendors[0];
+       ambapp_device_name *dev;
+
+       while (ven->vendor_id > 0) {
+               if (ven->vendor_id == vendor) {
+                       dev = ambapp_get_dev(ven->devices, id);
+                       if (!dev)
+                               return NULL;
+                       return dev->desc;
+               }
+               ven++;
+       }
+       return NULL;
+}
+
+char *ambapp_vendor_id2str(int vendor)
+{
+       ambapp_vendor_devnames *ven = &vendors[0];
+
+       while (ven->vendor_id > 0) {
+               if (ven->vendor_id == vendor) {
+                       return ven->name;
+               }
+               ven++;
+       }
+       return NULL;
+}
+
+static char *unknown = "unknown";
+
+char *ambapp_type_names[4] = {
+       /* 0 */ "UNUSED",
+       /* 1 */ "apb",
+       /* 2 */ "ahbmem",
+       /* 3 */ "ahbio"
+};
+
+/* Print one APB device */
+void ambapp_print_apb(ambapp_apbdev *dev, int index)
+{
+       char *dev_str, *ven_str;
+       unsigned int freq;
+
+       ven_str = ambapp_vendor_id2str(dev->vendor);
+       if (!ven_str) {
+               ven_str = unknown;
+               dev_str = unknown;
+       } else {
+               dev_str = ambapp_device_id2str(dev->vendor, dev->device);
+               if (!dev_str)
+                       dev_str = unknown;
+       }
+
+       /* Get Frequency of Core */
+       freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
+
+       printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n"
+              "   apb: 0x%08x - 0x%08x\n"
+              "   irq: %-2d (ver: %-2d)\n",
+              index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000,
+              dev->address, dev->address + (dev->mask-1),
+              dev->irq, dev->ver);
+}
+
+void ambapp_print_ahb(ambapp_ahbdev *dev, int index)
+{
+       char *dev_str, *ven_str, *type_str;
+       int i;
+       unsigned int freq;
+
+       ven_str = ambapp_vendor_id2str(dev->vendor);
+       if (!ven_str) {
+               ven_str = unknown;
+               dev_str = unknown;
+       } else {
+               dev_str = ambapp_device_id2str(dev->vendor, dev->device);
+               if (!dev_str)
+                       dev_str = unknown;
+       }
+
+       /* Get Frequency of Core */
+       freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
+
+       printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n",
+              index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000);
+
+       for (i = 0; i < 4; i++) {
+               if (dev->type[i] == 0)
+                       continue;
+               type_str = ambapp_type_names[dev->type[i]];
+               printf("   %-7s: 0x%08x - 0x%08x\n", type_str, dev->address[i],
+                       dev->address[i] + (dev->mask[i]-1));
+       }
+
+       printf("   irq: %-2d (ver: %d)\n", dev->irq, dev->ver);
+}
+
+int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       int index;
+       ambapp_apbdev apbdev;
+       ambapp_ahbdev ahbdev;
+
+       /* Print AHB Masters */
+       puts("\n--------- AHB Masters ---------\n");
+       index = 0;
+       while (ambapp_ahbmst_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
+               /* Found a AHB Master Device */
+               ambapp_print_ahb(&ahbdev, index);
+               index++;
+       }
+
+       /* Print AHB Slaves */
+       puts("\n--------- AHB Slaves  ---------\n");
+       index = 0;
+       while (ambapp_ahbslv_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
+               /* Found a AHB Slave Device */
+               ambapp_print_ahb(&ahbdev, index);
+               index++;
+       }
+
+       /* Print APB Slaves */
+       puts("\n--------- APB Slaves  ---------\n");
+       index = 0;
+       while (ambapp_apb_find(&ambapp_plb, 0, 0, index, &apbdev) == 1) {
+               /* Found a APB Slave Device */
+               ambapp_print_apb(&apbdev, index);
+               index++;
+       }
+
+       puts("\n");
+       return 0;
+}
+
+int ambapp_init_reloc(void)
+{
+       ambapp_vendor_devnames *vend = vendors;
+       ambapp_device_name *dev;
+
+       while (vend->vendor_id && vend->name) {
+               vend->name = (char *)((unsigned int)vend->name + gd->reloc_off);
+               vend->desc = (char *)((unsigned int)vend->desc + gd->reloc_off);
+               vend->devices = (ambapp_device_name *)
+                       ((unsigned int)vend->devices + gd->reloc_off);
+               dev = vend->devices;
+               vend++;
+               if (!dev)
+                       continue;
+               while (dev->device_id && dev->name) {
+                       dev->name =
+                           (char *)((unsigned int)dev->name + gd->reloc_off);
+                       dev->desc =
+                           (char *)((unsigned int)dev->desc + gd->reloc_off);
+                       dev++;
+               }
+       }
+       return 0;
+}
+
+U_BOOT_CMD(
+       ambapp, 1, 1, do_ambapp_print,
+       "list AMBA Plug&Play information",
+       "ambapp\n"
+       "    - lists AMBA (AHB & APB) Plug&Play devices present on the system"
+);
diff --git a/cmd/armflash.c b/cmd/armflash.c
new file mode 100644 (file)
index 0000000..b94d128
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+ * (C) Copyright 2015
+ * Linus Walleij, Linaro
+ *
+ * Support for ARM Flash Partitions
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <asm/io.h>
+
+#define MAX_REGIONS 4
+#define MAX_IMAGES 32
+
+struct afs_region {
+       u32 load_address;
+       u32 size;
+       u32 offset;
+};
+
+struct afs_image {
+       flash_info_t *flinfo;
+       const char *name;
+       u32 version;
+       u32 entrypoint;
+       u32 attributes;
+       u32 region_count;
+       struct afs_region regions[MAX_REGIONS];
+       ulong flash_mem_start;
+       ulong flash_mem_end;
+};
+
+static struct afs_image afs_images[MAX_IMAGES];
+static int num_afs_images;
+
+static u32 compute_crc(ulong start, u32 len)
+{
+       u32 sum = 0;
+       int i;
+
+       if (len % 4 != 0) {
+               printf("bad checksumming\n");
+               return 0;
+       }
+
+       for (i = 0; i < len; i += 4) {
+               u32 val;
+
+               val = readl((void *)start + i);
+               if (val > ~sum)
+                       sum++;
+               sum += val;
+       }
+       return ~sum;
+}
+
+static void parse_bank(ulong bank)
+{
+       int i;
+       ulong flstart, flend;
+       flash_info_t *info;
+
+       info = &flash_info[bank];
+       if (info->flash_id != FLASH_MAN_CFI) {
+               printf("Bank %lu: missing or unknown FLASH type\n", bank);
+               return;
+       }
+       if (!info->sector_count) {
+               printf("Bank %lu: no FLASH sectors\n", bank);
+               return;
+       }
+
+       flstart = info->start[0];
+       flend = flstart + info->size;
+
+       for (i = 0; i < info->sector_count; ++i) {
+               ulong secend;
+               u32 foot1, foot2;
+
+               if (ctrlc())
+                       break;
+
+               if (i == info->sector_count-1)
+                       secend = flend;
+               else
+                       secend = info->start[i+1];
+
+               /* Check for v1 header */
+               foot1 = readl((void *)secend - 0x0c);
+               if (foot1 == 0xA0FFFF9FU) {
+                       struct afs_image *afi = &afs_images[num_afs_images];
+                       ulong imginfo;
+
+                       afi->flinfo = info;
+                       afi->version = 1;
+                       afi->flash_mem_start = readl((void *)secend - 0x10);
+                       afi->flash_mem_end = readl((void *)secend - 0x14);
+                       afi->attributes = readl((void *)secend - 0x08);
+                       /* Adjust to even address */
+                       imginfo = afi->flash_mem_end + afi->flash_mem_end % 4;
+                       /* Record as a single region */
+                       afi->region_count = 1;
+                       afi->regions[0].offset = readl((void *)imginfo + 0x04);
+                       afi->regions[0].load_address =
+                               readl((void *)imginfo + 0x08);
+                       afi->regions[0].size = readl((void *)imginfo + 0x0C);
+                       afi->entrypoint = readl((void *)imginfo + 0x10);
+                       afi->name = (const char *)imginfo + 0x14;
+                       num_afs_images++;
+               }
+
+               /* Check for v2 header */
+               foot1 = readl((void *)secend - 0x04);
+               foot2 = readl((void *)secend - 0x08);
+               /* This makes up the string "HSLFTOOF" flash footer */
+               if (foot1 == 0x464F4F54U && foot2 == 0x464C5348U) {
+                       struct afs_image *afi = &afs_images[num_afs_images];
+                       ulong imginfo;
+                       u32 block_start, block_end;
+                       int j;
+
+                       afi->flinfo = info;
+                       afi->version = readl((void *)secend - 0x0c);
+                       imginfo = secend - 0x30 - readl((void *)secend - 0x10);
+                       afi->name = (const char *)secend - 0x30;
+
+                       afi->entrypoint = readl((void *)imginfo+0x08);
+                       afi->attributes = readl((void *)imginfo+0x0c);
+                       afi->region_count = readl((void *)imginfo+0x10);
+                       block_start = readl((void *)imginfo+0x54);
+                       block_end = readl((void *)imginfo+0x58);
+                       afi->flash_mem_start = afi->flinfo->start[block_start];
+                       afi->flash_mem_end = afi->flinfo->start[block_end];
+
+                       /*
+                        * Check footer CRC, the algorithm saves the inverse
+                        * checksum as part of the summed words, and thus
+                        * the result should be zero.
+                        */
+                       if (compute_crc(imginfo + 8, 0x88) != 0) {
+                               printf("BAD CRC on ARM image info\n");
+                               printf("(continuing anyway)\n");
+                       }
+
+                       /* Parse regions */
+                       for (j = 0; j < afi->region_count; j++) {
+                               afi->regions[j].load_address =
+                                       readl((void *)imginfo+0x14 + j*0x10);
+                               afi->regions[j].size =
+                                       readl((void *)imginfo+0x18 + j*0x10);
+                               afi->regions[j].offset =
+                                       readl((void *)imginfo+0x1c + j*0x10);
+                               /*
+                                * At offset 0x20 + j*0x10 there is a region
+                                * checksum which seems to be the running
+                                * sum + 3, however since we anyway checksum
+                                * the entire footer this is skipped over for
+                                * checking here.
+                                */
+                       }
+                       num_afs_images++;
+               }
+       }
+}
+
+static void parse_flash(void)
+{
+       ulong bank;
+
+       /* We have already parsed the images in flash */
+       if (num_afs_images > 0)
+               return;
+       for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank)
+               parse_bank(bank);
+}
+
+static int load_image(const char * const name, const ulong address)
+{
+       struct afs_image *afi = NULL;
+       int i;
+
+       parse_flash();
+       for (i = 0; i < num_afs_images; i++) {
+               struct afs_image *tmp = &afs_images[i];
+
+               if (!strcmp(tmp->name, name)) {
+                       afi = tmp;
+                       break;
+               }
+       }
+       if (!afi) {
+               printf("image \"%s\" not found in flash\n", name);
+               return CMD_RET_FAILURE;
+       }
+
+       for (i = 0; i < afi->region_count; i++) {
+               ulong from, to;
+
+               from = afi->flash_mem_start + afi->regions[i].offset;
+               if (address) {
+                       to = address;
+               } else if (afi->regions[i].load_address) {
+                       to = afi->regions[i].load_address;
+               } else {
+                       printf("no valid load address\n");
+                       return CMD_RET_FAILURE;
+               }
+
+               memcpy((void *)to, (void *)from, afi->regions[i].size);
+
+               printf("loaded region %d from %08lX to %08lX, %08X bytes\n",
+                      i,
+                      from,
+                      to,
+                      afi->regions[i].size);
+       }
+       return CMD_RET_SUCCESS;
+}
+
+static void print_images(void)
+{
+       int i;
+
+       parse_flash();
+       for (i = 0; i < num_afs_images; i++) {
+               struct afs_image *afi = &afs_images[i];
+               int j;
+
+               printf("Image: \"%s\" (v%d):\n", afi->name, afi->version);
+               printf("    Entry point: 0x%08X\n", afi->entrypoint);
+               printf("    Attributes: 0x%08X: ", afi->attributes);
+               if (afi->attributes == 0x01)
+                       printf("ARM executable");
+               if (afi->attributes == 0x08)
+                       printf("ARM backup");
+               printf("\n");
+               printf("    Flash mem start: 0x%08lX\n",
+                      afi->flash_mem_start);
+               printf("    Flash mem end: 0x%08lX\n",
+                      afi->flash_mem_end);
+               for (j = 0; j < afi->region_count; j++) {
+                       printf("    region %d\n"
+                              "        load address: %08X\n"
+                              "        size: %08X\n"
+                              "        offset: %08X\n",
+                              j,
+                              afi->regions[j].load_address,
+                              afi->regions[j].size,
+                              afi->regions[j].offset);
+               }
+       }
+}
+
+static int exists(const char * const name)
+{
+       int i;
+
+       parse_flash();
+       for (i = 0; i < num_afs_images; i++) {
+               struct afs_image *afi = &afs_images[i];
+
+               if (strcmp(afi->name, name) == 0)
+                       return CMD_RET_SUCCESS;
+       }
+       return CMD_RET_FAILURE;
+}
+
+static int do_afs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret = CMD_RET_SUCCESS;
+
+       if (argc == 1) {
+               print_images();
+       } else if (argc == 3 && !strcmp(argv[1], "exists")) {
+               ret = exists(argv[2]);
+       } else if (argc == 3 && !strcmp(argv[1], "load")) {
+               ret = load_image(argv[2], 0x0);
+       } else if (argc == 4 && !strcmp(argv[1], "load")) {
+               ulong load_addr;
+
+               load_addr = simple_strtoul(argv[3], NULL, 16);
+               ret = load_image(argv[2], load_addr);
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       return ret;
+}
+
+U_BOOT_CMD(afs, 4, 0, do_afs, "show AFS partitions",
+          "no arguments\n"
+          "    - list images in flash\n"
+          "exists <image>\n"
+          "    - returns 1 if an image exists, else 0\n"
+          "load <image>\n"
+          "    - load an image to the location indicated in the header\n"
+          "load <image> 0x<address>\n"
+          "    - load an image to the location specified\n");
diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
new file mode 100644 (file)
index 0000000..deed6d8
--- /dev/null
@@ -0,0 +1,574 @@
+/*
+ * (C) Copyright 2003
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+__maybe_unused
+static void print_num(const char *name, ulong value)
+{
+       printf("%-12s= 0x%08lX\n", name, value);
+}
+
+__maybe_unused
+static void print_eth(int idx)
+{
+       char name[10], *val;
+       if (idx)
+               sprintf(name, "eth%iaddr", idx);
+       else
+               strcpy(name, "ethaddr");
+       val = getenv(name);
+       if (!val)
+               val = "(not set)";
+       printf("%-12s= %s\n", name, val);
+}
+
+#ifndef CONFIG_DM_ETH
+__maybe_unused
+static void print_eths(void)
+{
+       struct eth_device *dev;
+       int i = 0;
+
+       do {
+               dev = eth_get_dev_by_index(i);
+               if (dev) {
+                       printf("eth%dname    = %s\n", i, dev->name);
+                       print_eth(i);
+                       i++;
+               }
+       } while (dev);
+
+       printf("current eth = %s\n", eth_get_name());
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+}
+#endif
+
+__maybe_unused
+static void print_lnum(const char *name, unsigned long long value)
+{
+       printf("%-12s= 0x%.8llX\n", name, value);
+}
+
+__maybe_unused
+static void print_mhz(const char *name, unsigned long hz)
+{
+       char buf[32];
+
+       printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
+}
+
+#if defined(CONFIG_PPC)
+void __weak board_detail(void)
+{
+       /* Please define boot_detail() for your platform */
+}
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+#ifdef DEBUG
+       print_num("bd address",         (ulong)bd);
+#endif
+       print_num("memstart",           bd->bi_memstart);
+       print_lnum("memsize",           bd->bi_memsize);
+       print_num("flashstart",         bd->bi_flashstart);
+       print_num("flashsize",          bd->bi_flashsize);
+       print_num("flashoffset",        bd->bi_flashoffset);
+       print_num("sramstart",          bd->bi_sramstart);
+       print_num("sramsize",           bd->bi_sramsize);
+#if    defined(CONFIG_5xx)  || defined(CONFIG_8xx) || \
+       defined(CONFIG_MPC8260) || defined(CONFIG_E500)
+       print_num("immr_base",          bd->bi_immr_base);
+#endif
+       print_num("bootflags",          bd->bi_bootflags);
+#if    defined(CONFIG_405EP) || \
+       defined(CONFIG_405GP) || \
+       defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
+       defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
+       defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
+       defined(CONFIG_XILINX_405)
+       print_mhz("procfreq",           bd->bi_procfreq);
+       print_mhz("plb_busfreq",        bd->bi_plb_busfreq);
+#if    defined(CONFIG_405EP) || defined(CONFIG_405GP) || \
+       defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
+       defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
+       defined(CONFIG_440SPE) || defined(CONFIG_XILINX_405)
+       print_mhz("pci_busfreq",        bd->bi_pci_busfreq);
+#endif
+#else  /* ! CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
+#if defined(CONFIG_CPM2)
+       print_mhz("vco",                bd->bi_vco);
+       print_mhz("sccfreq",            bd->bi_sccfreq);
+       print_mhz("brgfreq",            bd->bi_brgfreq);
+#endif
+       print_mhz("intfreq",            bd->bi_intfreq);
+#if defined(CONFIG_CPM2)
+       print_mhz("cpmfreq",            bd->bi_cpmfreq);
+#endif
+       print_mhz("busfreq",            bd->bi_busfreq);
+#endif /* CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
+
+#ifdef CONFIG_ENABLE_36BIT_PHYS
+#ifdef CONFIG_PHYS_64BIT
+       puts("addressing  = 36-bit\n");
+#else
+       puts("addressing  = 32-bit\n");
+#endif
+#endif
+
+       print_eth(0);
+#if defined(CONFIG_HAS_ETH1)
+       print_eth(1);
+#endif
+#if defined(CONFIG_HAS_ETH2)
+       print_eth(2);
+#endif
+#if defined(CONFIG_HAS_ETH3)
+       print_eth(3);
+#endif
+#if defined(CONFIG_HAS_ETH4)
+       print_eth(4);
+#endif
+#if defined(CONFIG_HAS_ETH5)
+       print_eth(5);
+#endif
+
+       printf("IP addr     = %s\n", getenv("ipaddr"));
+       printf("baudrate    = %6u bps\n", gd->baudrate);
+       print_num("relocaddr", gd->relocaddr);
+       board_detail();
+       return 0;
+}
+
+#elif defined(CONFIG_NIOS2)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       bd_t *bd = gd->bd;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank",  i);
+               print_num("-> start",   bd->bi_dram[i].start);
+               print_num("-> size",    bd->bi_dram[i].size);
+       }
+
+       print_num("flash start",        (ulong)bd->bi_flashstart);
+       print_num("flash size",         (ulong)bd->bi_flashsize);
+       print_num("flash offset",       (ulong)bd->bi_flashoffset);
+
+#if defined(CONFIG_SYS_SRAM_BASE)
+       print_num ("sram start",        (ulong)bd->bi_sramstart);
+       print_num ("sram size",         (ulong)bd->bi_sramsize);
+#endif
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_MICROBLAZE)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+       int i;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank",  i);
+               print_num("-> start",   bd->bi_dram[i].start);
+               print_num("-> size",    bd->bi_dram[i].size);
+       }
+
+       print_num("flash start    ",    (ulong)bd->bi_flashstart);
+       print_num("flash size     ",    (ulong)bd->bi_flashsize);
+       print_num("flash offset   ",    (ulong)bd->bi_flashoffset);
+#if defined(CONFIG_SYS_SRAM_BASE)
+       print_num("sram start     ",    (ulong)bd->bi_sramstart);
+       print_num("sram size      ",    (ulong)bd->bi_sramsize);
+#endif
+#if defined(CONFIG_CMD_NET)
+       print_eths();
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+       print_num("relocaddr", gd->relocaddr);
+       print_num("reloc off", gd->reloc_off);
+       print_num("fdt_blob", (ulong)gd->fdt_blob);
+       print_num("new_fdt", (ulong)gd->new_fdt);
+       print_num("fdt_size", (ulong)gd->fdt_size);
+
+       return 0;
+}
+
+#elif defined(CONFIG_SPARC)
+
+int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+#ifdef DEBUG
+       print_num("bd address             ", (ulong) bd);
+#endif
+       print_num("memstart               ", bd->bi_memstart);
+       print_lnum("memsize                ", bd->bi_memsize);
+       print_num("flashstart             ", bd->bi_flashstart);
+       print_num("CONFIG_SYS_MONITOR_BASE       ", CONFIG_SYS_MONITOR_BASE);
+       print_num("CONFIG_ENV_ADDR           ", CONFIG_ENV_ADDR);
+       printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%x (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
+              CONFIG_SYS_MONITOR_LEN);
+       printf("CONFIG_SYS_MALLOC_BASE        = 0x%x (%d)\n", CONFIG_SYS_MALLOC_BASE,
+              CONFIG_SYS_MALLOC_LEN);
+       printf("CONFIG_SYS_INIT_SP_OFFSET     = 0x%x (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
+              CONFIG_SYS_STACK_SIZE);
+       printf("CONFIG_SYS_PROM_OFFSET        = 0x%x (%d)\n", CONFIG_SYS_PROM_OFFSET,
+              CONFIG_SYS_PROM_SIZE);
+       printf("CONFIG_SYS_GBL_DATA_OFFSET    = 0x%x (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
+              GENERATED_GBL_DATA_SIZE);
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+       printf("baudrate               = %6u bps\n", gd->baudrate);
+       return 0;
+}
+
+#elif defined(CONFIG_M68K)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       print_num("memstart",           (ulong)bd->bi_memstart);
+       print_lnum("memsize",           (u64)bd->bi_memsize);
+       print_num("flashstart",         (ulong)bd->bi_flashstart);
+       print_num("flashsize",          (ulong)bd->bi_flashsize);
+       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
+#if defined(CONFIG_SYS_INIT_RAM_ADDR)
+       print_num("sramstart",          (ulong)bd->bi_sramstart);
+       print_num("sramsize",           (ulong)bd->bi_sramsize);
+#endif
+#if defined(CONFIG_SYS_MBAR)
+       print_num("mbar",               bd->bi_mbar_base);
+#endif
+       print_mhz("cpufreq",            bd->bi_intfreq);
+       print_mhz("busfreq",            bd->bi_busfreq);
+#ifdef CONFIG_PCI
+       print_mhz("pcifreq",            bd->bi_pcifreq);
+#endif
+#ifdef CONFIG_EXTRA_CLOCK
+       print_mhz("flbfreq",            bd->bi_flbfreq);
+       print_mhz("inpfreq",            bd->bi_inpfreq);
+       print_mhz("vcofreq",            bd->bi_vcofreq);
+#endif
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+#if defined(CONFIG_HAS_ETH1)
+       print_eth(1);
+#endif
+#if defined(CONFIG_HAS_ETH2)
+       print_eth(2);
+#endif
+#if defined(CONFIG_HAS_ETH3)
+       print_eth(3);
+#endif
+
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_BLACKFIN)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       printf("U-Boot      = %s\n", bd->bi_r_version);
+       printf("CPU         = %s\n", bd->bi_cpu);
+       printf("Board       = %s\n", bd->bi_board_name);
+       print_mhz("VCO",        bd->bi_vco);
+       print_mhz("CCLK",       bd->bi_cclk);
+       print_mhz("SCLK",       bd->bi_sclk);
+
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+       print_num("memstart",           (ulong)bd->bi_memstart);
+       print_lnum("memsize",           (u64)bd->bi_memsize);
+       print_num("flashstart",         (ulong)bd->bi_flashstart);
+       print_num("flashsize",          (ulong)bd->bi_flashsize);
+       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
+
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_MIPS)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+       print_num("memstart",           (ulong)bd->bi_memstart);
+       print_lnum("memsize",           (u64)bd->bi_memsize);
+       print_num("flashstart",         (ulong)bd->bi_flashstart);
+       print_num("flashsize",          (ulong)bd->bi_flashsize);
+       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
+
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_AVR32)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+       print_num("memstart",           (ulong)bd->bi_dram[0].start);
+       print_lnum("memsize",           (u64)bd->bi_dram[0].size);
+       print_num("flashstart",         (ulong)bd->bi_flashstart);
+       print_num("flashsize",          (ulong)bd->bi_flashsize);
+       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
+
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_ARM)
+
+static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       int i;
+       bd_t *bd = gd->bd;
+
+       print_num("arch_number",        bd->bi_arch_number);
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank",  i);
+               print_num("-> start",   bd->bi_dram[i].start);
+               print_num("-> size",    bd->bi_dram[i].size);
+       }
+
+#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
+       if (gd->secure_ram & MEM_RESERVE_SECURE_SECURED) {
+               print_num("Secure ram",
+                         gd->secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
+       }
+#endif
+#if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
+       print_eths();
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
+       print_num("TLB addr", gd->arch.tlb_addr);
+#endif
+       print_num("relocaddr", gd->relocaddr);
+       print_num("reloc off", gd->reloc_off);
+       print_num("irq_sp", gd->irq_sp);        /* irq stack pointer */
+       print_num("sp start ", gd->start_addr_sp);
+#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
+       print_num("FB base  ", gd->fb_base);
+#endif
+       /*
+        * TODO: Currently only support for davinci SOC's is added.
+        * Remove this check once all the board implement this.
+        */
+#ifdef CONFIG_CLOCKS
+       printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
+       printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
+       printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
+#endif
+#ifdef CONFIG_BOARD_TYPES
+       printf("Board Type  = %ld\n", gd->board_type);
+#endif
+       return 0;
+}
+
+#elif defined(CONFIG_SH)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+       print_num("mem start      ",    (ulong)bd->bi_memstart);
+       print_lnum("mem size       ",   (u64)bd->bi_memsize);
+       print_num("flash start    ",    (ulong)bd->bi_flashstart);
+       print_num("flash size     ",    (ulong)bd->bi_flashsize);
+       print_num("flash offset   ",    (ulong)bd->bi_flashoffset);
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+       return 0;
+}
+
+#elif defined(CONFIG_X86)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       bd_t *bd = gd->bd;
+
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+       print_num("bi_memstart",        bd->bi_memstart);
+       print_num("bi_memsize",         bd->bi_memsize);
+       print_num("bi_flashstart",      bd->bi_flashstart);
+       print_num("bi_flashsize",       bd->bi_flashsize);
+       print_num("bi_flashoffset",     bd->bi_flashoffset);
+       print_num("bi_sramstart",       bd->bi_sramstart);
+       print_num("bi_sramsize",        bd->bi_sramsize);
+       print_num("bi_bootflags",       bd->bi_bootflags);
+       print_mhz("cpufreq",            bd->bi_intfreq);
+       print_mhz("busfreq",            bd->bi_busfreq);
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank",  i);
+               print_num("-> start",   bd->bi_dram[i].start);
+               print_num("-> size",    bd->bi_dram[i].size);
+       }
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+       print_mhz("ethspeed",       bd->bi_ethspeed);
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_SANDBOX)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       bd_t *bd = gd->bd;
+
+       print_num("boot_params", (ulong)bd->bi_boot_params);
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank", i);
+               print_num("-> start", bd->bi_dram[i].start);
+               print_num("-> size", bd->bi_dram[i].size);
+       }
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
+       print_num("FB base  ", gd->fb_base);
+#endif
+       return 0;
+}
+
+#elif defined(CONFIG_NDS32)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       bd_t *bd = gd->bd;
+
+       print_num("arch_number",        bd->bi_arch_number);
+       print_num("boot_params",        (ulong)bd->bi_boot_params);
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               print_num("DRAM bank",  i);
+               print_num("-> start",   bd->bi_dram[i].start);
+               print_num("-> size",    bd->bi_dram[i].size);
+       }
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_OPENRISC)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       print_num("mem start",          (ulong)bd->bi_memstart);
+       print_lnum("mem size",          (u64)bd->bi_memsize);
+       print_num("flash start",        (ulong)bd->bi_flashstart);
+       print_num("flash size",         (ulong)bd->bi_flashsize);
+       print_num("flash offset",       (ulong)bd->bi_flashoffset);
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+
+       printf("baudrate    = %u bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#elif defined(CONFIG_ARC)
+
+int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bd_t *bd = gd->bd;
+
+       print_num("mem start",          bd->bi_memstart);
+       print_lnum("mem size",          bd->bi_memsize);
+
+#if defined(CONFIG_CMD_NET)
+       print_eth(0);
+       printf("ip_addr     = %s\n", getenv("ipaddr"));
+#endif
+       printf("baudrate    = %d bps\n", gd->baudrate);
+
+       return 0;
+}
+
+#else
+ #error "a case for this architecture does not exist!"
+#endif
+
+/* -------------------------------------------------------------------- */
+
+U_BOOT_CMD(
+       bdinfo, 1,      1,      do_bdinfo,
+       "print Board Info structure",
+       ""
+);
diff --git a/cmd/bedbug.c b/cmd/bedbug.c
new file mode 100644 (file)
index 0000000..69afeaf
--- /dev/null
@@ -0,0 +1,422 @@
+/*
+ * BedBug Functions
+ */
+
+#include <common.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <linux/ctype.h>
+#include <net.h>
+#include <bedbug/type.h>
+#include <bedbug/bedbug.h>
+#include <bedbug/regs.h>
+#include <bedbug/ppc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+extern void show_regs __P ((struct pt_regs *));
+extern int run_command __P ((const char *, int));
+
+ulong dis_last_addr = 0;       /* Last address disassembled   */
+ulong dis_last_len = 20;       /* Default disassembler length */
+CPU_DEBUG_CTX bug_ctx;         /* Bedbug context structure    */
+
+
+/* ======================================================================
+ * U-Boot's puts function does not append a newline, so the bedbug stuff
+ * will use this for the output of the dis/assembler.
+ * ====================================================================== */
+
+int bedbug_puts (const char *str)
+{
+       /* -------------------------------------------------- */
+
+       printf ("%s\r\n", str);
+       return 0;
+}                              /* bedbug_puts */
+
+
+
+/* ======================================================================
+ * Initialize the bug_ctx structure used by the bedbug debugger.  This is
+ * specific to the CPU since each has different debug registers and
+ * settings.
+ * ====================================================================== */
+
+void bedbug_init (void)
+{
+       /* -------------------------------------------------- */
+
+#if defined(CONFIG_4xx)
+       void bedbug405_init (void);
+
+       bedbug405_init ();
+#elif defined(CONFIG_8xx)
+       void bedbug860_init (void);
+
+       bedbug860_init ();
+#endif
+
+#if defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260)
+       /* Processors that are 603e core based */
+       void bedbug603e_init (void);
+
+       bedbug603e_init ();
+#endif
+
+       return;
+}                              /* bedbug_init */
+
+
+
+/* ======================================================================
+ * Entry point from the interpreter to the disassembler.  Repeated calls
+ * will resume from the last disassembled address.
+ * ====================================================================== */
+int do_bedbug_dis (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr;             /* Address to start disassembly from    */
+       ulong len;              /* # of instructions to disassemble     */
+
+       /* -------------------------------------------------- */
+
+       /* Setup to go from the last address if none is given */
+       addr = dis_last_addr;
+       len = dis_last_len;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /* New command */
+               addr = simple_strtoul (argv[1], NULL, 16);
+
+               /* If an extra param is given then it is the length */
+               if (argc > 2)
+                       len = simple_strtoul (argv[2], NULL, 16);
+       }
+
+       /* Run the disassembler */
+       disppc ((unsigned char *) addr, 0, len, bedbug_puts, F_RADHEX);
+
+       dis_last_addr = addr + (len * 4);
+       dis_last_len = len;
+       return 0;
+}                              /* do_bedbug_dis */
+
+U_BOOT_CMD (ds, 3, 1, do_bedbug_dis,
+           "disassemble memory",
+           "ds <address> [# instructions]");
+
+/* ======================================================================
+ * Entry point from the interpreter to the assembler.  Assembles
+ * instructions in consecutive memory locations until a '.' (period) is
+ * entered on a line by itself.
+ * ====================================================================== */
+int do_bedbug_asm (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       long mem_addr;          /* Address to assemble into     */
+       unsigned long instr;    /* Machine code for text        */
+       char prompt[15];        /* Prompt string for user input */
+       int asm_err;            /* Error code from the assembler */
+
+       /* -------------------------------------------------- */
+       int rcode = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       printf ("\nEnter '.' when done\n");
+       mem_addr = simple_strtoul (argv[1], NULL, 16);
+
+       while (1) {
+               putc ('\n');
+               disppc ((unsigned char *) mem_addr, 0, 1, bedbug_puts,
+                       F_RADHEX);
+
+               sprintf (prompt, "%08lx:    ", mem_addr);
+               cli_readline(prompt);
+
+               if (console_buffer[0] && strcmp (console_buffer, ".")) {
+                       if ((instr =
+                            asmppc (mem_addr, console_buffer,
+                                    &asm_err)) != 0) {
+                               *(unsigned long *) mem_addr = instr;
+                               mem_addr += 4;
+                       } else {
+                               printf ("*** Error: %s ***\n",
+                                       asm_error_str (asm_err));
+                               rcode = 1;
+                       }
+               } else {
+                       break;
+               }
+       }
+       return rcode;
+}                              /* do_bedbug_asm */
+
+U_BOOT_CMD (as, 2, 0, do_bedbug_asm,
+           "assemble memory", "as <address>");
+
+/* ======================================================================
+ * Used to set a break point from the interpreter.  Simply calls into the
+ * CPU-specific break point set routine.
+ * ====================================================================== */
+
+int do_bedbug_break (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       /* -------------------------------------------------- */
+       if (bug_ctx.do_break)
+               (*bug_ctx.do_break) (cmdtp, flag, argc, argv);
+       return 0;
+
+}                              /* do_bedbug_break */
+
+U_BOOT_CMD (break, 3, 0, do_bedbug_break,
+           "set or clear a breakpoint",
+           " - Set or clear a breakpoint\n"
+           "break <address> - Break at an address\n"
+           "break off <bp#> - Disable breakpoint.\n"
+           "break show      - List breakpoints.");
+
+/* ======================================================================
+ * Called from the debug interrupt routine.  Simply calls the CPU-specific
+ * breakpoint handling routine.
+ * ====================================================================== */
+
+void do_bedbug_breakpoint (struct pt_regs *regs)
+{
+       /* -------------------------------------------------- */
+
+       if (bug_ctx.break_isr)
+               (*bug_ctx.break_isr) (regs);
+
+       return;
+}                              /* do_bedbug_breakpoint */
+
+
+
+/* ======================================================================
+ * Called from the CPU-specific breakpoint handling routine.  Enter a
+ * mini main loop until the stopped flag is cleared from the breakpoint
+ * context.
+ *
+ * This handles the parts of the debugger that are common to all CPU's.
+ * ====================================================================== */
+
+void bedbug_main_loop (unsigned long addr, struct pt_regs *regs)
+{
+       int len;                /* Length of command line */
+       int flag;               /* Command flags          */
+       int rc = 0;             /* Result from run_command */
+       char prompt_str[20];    /* Prompt string          */
+       static char lastcommand[CONFIG_SYS_CBSIZE] = { 0 };     /* previous command */
+       /* -------------------------------------------------- */
+
+       if (bug_ctx.clear)
+               (*bug_ctx.clear) (bug_ctx.current_bp);
+
+       printf ("Breakpoint %d: ", bug_ctx.current_bp);
+       disppc ((unsigned char *) addr, 0, 1, bedbug_puts, F_RADHEX);
+
+       bug_ctx.stopped = 1;
+       bug_ctx.regs = regs;
+
+       sprintf (prompt_str, "BEDBUG.%d =>", bug_ctx.current_bp);
+
+       /* A miniature main loop */
+       while (bug_ctx.stopped) {
+               len = cli_readline(prompt_str);
+
+               flag = 0;       /* assume no special flags for now */
+
+               if (len > 0)
+                       strcpy (lastcommand, console_buffer);
+               else if (len == 0)
+                       flag |= CMD_FLAG_REPEAT;
+
+               if (len == -1)
+                       printf ("<INTERRUPT>\n");
+               else
+                       rc = run_command_repeatable(lastcommand, flag);
+
+               if (rc <= 0) {
+                       /* invalid command or not repeatable, forget it */
+                       lastcommand[0] = 0;
+               }
+       }
+
+       bug_ctx.regs = NULL;
+       bug_ctx.current_bp = 0;
+
+       return;
+}                              /* bedbug_main_loop */
+
+
+
+/* ======================================================================
+ * Interpreter command to continue from a breakpoint.  Just clears the
+ * stopped flag in the context so that the breakpoint routine will
+ * return.
+ * ====================================================================== */
+int do_bedbug_continue (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       /* -------------------------------------------------- */
+
+       if (!bug_ctx.stopped) {
+               printf ("Not at a breakpoint\n");
+               return 1;
+       }
+
+       bug_ctx.stopped = 0;
+       return 0;
+}                              /* do_bedbug_continue */
+
+U_BOOT_CMD (continue, 1, 0, do_bedbug_continue,
+           "continue from a breakpoint",
+           "");
+
+/* ======================================================================
+ * Interpreter command to continue to the next instruction, stepping into
+ * subroutines.  Works by calling the find_next_addr() routine to compute
+ * the address passes control to the CPU-specific set breakpoint routine
+ * for the current breakpoint number.
+ * ====================================================================== */
+int do_bedbug_step (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr;     /* Address to stop at */
+
+       /* -------------------------------------------------- */
+
+       if (!bug_ctx.stopped) {
+               printf ("Not at a breakpoint\n");
+               return 1;
+       }
+
+       if (!find_next_address((unsigned char *) &addr, false, bug_ctx.regs))
+               return 1;
+
+       if (bug_ctx.set)
+               (*bug_ctx.set) (bug_ctx.current_bp, addr);
+
+       bug_ctx.stopped = 0;
+       return 0;
+}                              /* do_bedbug_step */
+
+U_BOOT_CMD (step, 1, 1, do_bedbug_step,
+           "single step execution.",
+           "");
+
+/* ======================================================================
+ * Interpreter command to continue to the next instruction, stepping over
+ * subroutines.  Works by calling the find_next_addr() routine to compute
+ * the address passes control to the CPU-specific set breakpoint routine
+ * for the current breakpoint number.
+ * ====================================================================== */
+int do_bedbug_next (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr;     /* Address to stop at */
+
+       /* -------------------------------------------------- */
+
+       if (!bug_ctx.stopped) {
+               printf ("Not at a breakpoint\n");
+               return 1;
+       }
+
+       if (!find_next_address((unsigned char *) &addr, true, bug_ctx.regs))
+               return 1;
+
+       if (bug_ctx.set)
+               (*bug_ctx.set) (bug_ctx.current_bp, addr);
+
+       bug_ctx.stopped = 0;
+       return 0;
+}                              /* do_bedbug_next */
+
+U_BOOT_CMD (next, 1, 1, do_bedbug_next,
+           "single step execution, stepping over subroutines.",
+           "");
+
+/* ======================================================================
+ * Interpreter command to print the current stack.  This assumes an EABI
+ * architecture, so it starts with GPR R1 and works back up the stack.
+ * ====================================================================== */
+int do_bedbug_stack (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long sp;       /* Stack pointer                */
+       unsigned long func;     /* LR from stack                */
+       int depth;              /* Stack iteration level        */
+       int skip = 1;           /* Flag to skip the first entry */
+       unsigned long top;      /* Top of memory address        */
+
+       /* -------------------------------------------------- */
+
+       if (!bug_ctx.stopped) {
+               printf ("Not at a breakpoint\n");
+               return 1;
+       }
+
+       top = gd->bd->bi_memstart + gd->bd->bi_memsize;
+       depth = 0;
+
+       printf ("Depth     PC\n");
+       printf ("-----  --------\n");
+       printf ("%5d  %08lx\n", depth++, bug_ctx.regs->nip);
+
+       sp = bug_ctx.regs->gpr[1];
+       func = *(unsigned long *) (sp + 4);
+
+       while ((func < top) && (sp < top)) {
+               if (!skip)
+                       printf ("%5d  %08lx\n", depth++, func);
+               else
+                       --skip;
+
+               sp = *(unsigned long *) sp;
+               func = *(unsigned long *) (sp + 4);
+       }
+       return 0;
+}                              /* do_bedbug_stack */
+
+U_BOOT_CMD (where, 1, 1, do_bedbug_stack,
+           "Print the running stack.",
+           "");
+
+/* ======================================================================
+ * Interpreter command to dump the registers.  Calls the CPU-specific
+ * show registers routine.
+ * ====================================================================== */
+int do_bedbug_rdump (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       /* -------------------------------------------------- */
+
+       if (!bug_ctx.stopped) {
+               printf ("Not at a breakpoint\n");
+               return 1;
+       }
+
+       show_regs (bug_ctx.regs);
+       return 0;
+}                              /* do_bedbug_rdump */
+
+U_BOOT_CMD (rdump, 1, 1, do_bedbug_rdump,
+           "Show registers.", "");
+/* ====================================================================== */
+
+
+/*
+ * Copyright (c) 2001 William L. Pitts
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
diff --git a/cmd/blob.c b/cmd/blob.c
new file mode 100644 (file)
index 0000000..ac8b268
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ *
+ * Command for encapsulating/decapsulating blob of memory.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * blob_decap() - Decapsulate the data as a blob
+ * @key_mod:   - Pointer to key modifier/key
+ * @src:       - Address of data to be decapsulated
+ * @dst:       - Address of data to be decapsulated
+ * @len:       - Size of data to be decapsulated
+ *
+ * Returns zero on success,and negative on error.
+ */
+__weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
+{
+       return 0;
+}
+
+/**
+ * blob_encap() - Encapsulate the data as a blob
+ * @key_mod:   - Pointer to key modifier/key
+ * @src:       - Address of data to be encapsulated
+ * @dst:       - Address of data to be encapsulated
+ * @len:       - Size of data to be encapsulated
+ *
+ * Returns zero on success,and negative on error.
+ */
+__weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
+{
+       return 0;
+}
+
+/**
+ * do_blob() - Handle the "blob" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       uint32_t key_addr, src_addr, dst_addr, len;
+       uint8_t *km_ptr, *src_ptr, *dst_ptr;
+       int enc, ret = 0;
+
+       if (argc != 6)
+               return CMD_RET_USAGE;
+
+       if (!strncmp(argv[1], "enc", 3))
+               enc = 1;
+       else if (!strncmp(argv[1], "dec", 3))
+               enc = 0;
+       else
+               return CMD_RET_USAGE;
+
+       src_addr = simple_strtoul(argv[2], NULL, 16);
+       dst_addr = simple_strtoul(argv[3], NULL, 16);
+       len = simple_strtoul(argv[4], NULL, 16);
+       key_addr = simple_strtoul(argv[5], NULL, 16);
+
+       km_ptr = (uint8_t *)(uintptr_t)key_addr;
+       src_ptr = (uint8_t *)(uintptr_t)src_addr;
+       dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
+
+       if (enc)
+               ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
+       else
+               ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
+
+       return ret;
+}
+
+/***************************************************/
+static char blob_help_text[] =
+       "enc src dst len km - Encapsulate and create blob of data\n"
+       "                          $len bytes long at address $src and\n"
+       "                          store the result at address $dst.\n"
+       "                          $km is the address where the key\n"
+       "                          modifier is stored.\n"
+       "                          The modifier is required for generation\n"
+       "                          /use as key for cryptographic operation.\n"
+       "                          Key modifier should be 16 byte long.\n"
+       "blob dec src dst len km - Decapsulate the  blob of data at address\n"
+       "                          $src and store result of $len byte at\n"
+       "                          addr $dst.\n"
+       "                          $km is the address where the key\n"
+       "                          modifier is stored.\n"
+       "                          The modifier is required for generation\n"
+       "                          /use as key for cryptographic operation.\n"
+       "                          Key modifier should be 16 byte long.\n";
+
+U_BOOT_CMD(
+       blob, 6, 1, do_blob,
+       "Blob encapsulation/decryption",
+       blob_help_text
+);
diff --git a/cmd/bmp.c b/cmd/bmp.c
new file mode 100644 (file)
index 0000000..fd5b7db
--- /dev/null
+++ b/cmd/bmp.c
@@ -0,0 +1,275 @@
+/*
+ * (C) Copyright 2002
+ * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * BMP handling routines
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <lcd.h>
+#include <mapmem.h>
+#include <bmp_layout.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <splash.h>
+#include <video.h>
+
+static int bmp_info (ulong addr);
+
+/*
+ * Allocate and decompress a BMP image using gunzip().
+ *
+ * Returns a pointer to the decompressed image data. This pointer is
+ * aligned to 32-bit-aligned-address + 2.
+ * See doc/README.displaying-bmps for explanation.
+ *
+ * The allocation address is passed to 'alloc_addr' and must be freed
+ * by the caller after use.
+ *
+ * Returns NULL if decompression failed, or if the decompressed data
+ * didn't contain a valid BMP signature.
+ */
+#ifdef CONFIG_VIDEO_BMP_GZIP
+struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
+                            void **alloc_addr)
+{
+       void *dst;
+       unsigned long len;
+       struct bmp_image *bmp;
+
+       /*
+        * Decompress bmp image
+        */
+       len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
+       /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
+       dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3);
+       if (dst == NULL) {
+               puts("Error: malloc in gunzip failed!\n");
+               return NULL;
+       }
+
+       bmp = dst;
+
+       /* align to 32-bit-aligned-address + 2 */
+       bmp = (struct bmp_image *)((((unsigned int)dst + 1) & ~3) + 2);
+
+       if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
+                  &len) != 0) {
+               free(dst);
+               return NULL;
+       }
+       if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
+               puts("Image could be truncated"
+                               " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
+
+       /*
+        * Check for bmp mark 'BM'
+        */
+       if (!((bmp->header.signature[0] == 'B') &&
+             (bmp->header.signature[1] == 'M'))) {
+               free(dst);
+               return NULL;
+       }
+
+       debug("Gzipped BMP image detected!\n");
+
+       *alloc_addr = dst;
+       return bmp;
+}
+#else
+struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
+                            void **alloc_addr)
+{
+       return NULL;
+}
+#endif
+
+static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr;
+
+       switch (argc) {
+       case 1:         /* use load_addr as default address */
+               addr = load_addr;
+               break;
+       case 2:         /* use argument */
+               addr = simple_strtoul(argv[1], NULL, 16);
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       return (bmp_info(addr));
+}
+
+static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr;
+       int x = 0, y = 0;
+
+       splash_get_pos(&x, &y);
+
+       switch (argc) {
+       case 1:         /* use load_addr as default address */
+               addr = load_addr;
+               break;
+       case 2:         /* use argument */
+               addr = simple_strtoul(argv[1], NULL, 16);
+               break;
+       case 4:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               x = simple_strtoul(argv[2], NULL, 10);
+               y = simple_strtoul(argv[3], NULL, 10);
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+        return (bmp_display(addr, x, y));
+}
+
+static cmd_tbl_t cmd_bmp_sub[] = {
+       U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""),
+       U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
+};
+
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+void bmp_reloc(void) {
+       fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
+}
+#endif
+
+/*
+ * Subroutine:  do_bmp
+ *
+ * Description: Handler for 'bmp' command..
+ *
+ * Inputs:     argv[1] contains the subcommand
+ *
+ * Return:      None
+ *
+ */
+static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *c;
+
+       /* Strip off leading 'bmp' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub));
+
+       if (c)
+               return  c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       bmp,    5,      1,      do_bmp,
+       "manipulate BMP image data",
+       "info <imageAddr>          - display image info\n"
+       "bmp display <imageAddr> [x y] - display image at x,y"
+);
+
+/*
+ * Subroutine:  bmp_info
+ *
+ * Description: Show information about bmp file in memory
+ *
+ * Inputs:     addr            address of the bmp file
+ *
+ * Return:      None
+ *
+ */
+static int bmp_info(ulong addr)
+{
+       struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
+       void *bmp_alloc_addr = NULL;
+       unsigned long len;
+
+       if (!((bmp->header.signature[0]=='B') &&
+             (bmp->header.signature[1]=='M')))
+               bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
+
+       if (bmp == NULL) {
+               printf("There is no valid bmp file at the given address\n");
+               return 1;
+       }
+
+       printf("Image size    : %d x %d\n", le32_to_cpu(bmp->header.width),
+              le32_to_cpu(bmp->header.height));
+       printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
+       printf("Compression   : %d\n", le32_to_cpu(bmp->header.compression));
+
+       if (bmp_alloc_addr)
+               free(bmp_alloc_addr);
+
+       return(0);
+}
+
+/*
+ * Subroutine:  bmp_display
+ *
+ * Description: Display bmp file located in memory
+ *
+ * Inputs:     addr            address of the bmp file
+ *
+ * Return:      None
+ *
+ */
+int bmp_display(ulong addr, int x, int y)
+{
+#ifdef CONFIG_DM_VIDEO
+       struct udevice *dev;
+#endif
+       int ret;
+       struct bmp_image *bmp = map_sysmem(addr, 0);
+       void *bmp_alloc_addr = NULL;
+       unsigned long len;
+
+       if (!((bmp->header.signature[0]=='B') &&
+             (bmp->header.signature[1]=='M')))
+               bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
+
+       if (!bmp) {
+               printf("There is no valid bmp file at the given address\n");
+               return 1;
+       }
+       addr = map_to_sysmem(bmp);
+
+#ifdef CONFIG_DM_VIDEO
+       ret = uclass_first_device(UCLASS_VIDEO, &dev);
+       if (!ret) {
+               if (!dev)
+                       ret = -ENODEV;
+               if (!ret) {
+                       bool align = false;
+
+# ifdef CONFIG_SPLASH_SCREEN_ALIGN
+                       align = true;
+# endif /* CONFIG_SPLASH_SCREEN_ALIGN */
+                       ret = video_bmp_display(dev, addr, x, y, align);
+               }
+       }
+       return ret ? CMD_RET_FAILURE : 0;
+#elif defined(CONFIG_LCD)
+       ret = lcd_display_bitmap(addr, x, y);
+#elif defined(CONFIG_VIDEO)
+       ret = video_display_bitmap(addr, x, y);
+#else
+# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
+#endif
+
+       if (bmp_alloc_addr)
+               free(bmp_alloc_addr);
+
+       return ret;
+}
diff --git a/cmd/boot.c b/cmd/boot.c
new file mode 100644 (file)
index 0000000..72f2cf3
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * (C) Copyright 2000-2003
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Misc boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <net.h>
+
+#ifdef CONFIG_CMD_GO
+
+/* Allow ports to override the default behavior */
+__attribute__((weak))
+unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
+                                char * const argv[])
+{
+       return entry (argc, argv);
+}
+
+static int do_go(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong   addr, rc;
+       int     rcode = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+
+       printf ("## Starting application at 0x%08lX ...\n", addr);
+
+       /*
+        * pass address parameter as argv[0] (aka command name),
+        * and all remaining args
+        */
+       rc = do_go_exec ((void *)addr, argc - 1, argv + 1);
+       if (rc != 0) rcode = 1;
+
+       printf ("## Application terminated, rc = 0x%lX\n", rc);
+       return rcode;
+}
+
+/* -------------------------------------------------------------------- */
+
+U_BOOT_CMD(
+       go, CONFIG_SYS_MAXARGS, 1,      do_go,
+       "start application at address 'addr'",
+       "addr [arg ...]\n    - start application at address 'addr'\n"
+       "      passing 'arg' as arguments"
+);
+
+#endif
+
+U_BOOT_CMD(
+       reset, 1, 0,    do_reset,
+       "Perform RESET of the CPU",
+       ""
+);
+
+#ifdef CONFIG_CMD_POWEROFF
+U_BOOT_CMD(
+       poweroff, 1, 0, do_poweroff,
+       "Perform POWEROFF of the device",
+       ""
+);
+#endif
diff --git a/cmd/bootldr.c b/cmd/bootldr.c
new file mode 100644 (file)
index 0000000..bc5c1f9
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * U-boot - bootldr.c
+ *
+ * Copyright (c) 2005-2008 Analog Devices Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <config.h>
+#include <common.h>
+#include <command.h>
+
+#include <asm/blackfin.h>
+#include <asm/mach-common/bits/bootrom.h>
+
+/* Simple sanity check on the specified address to make sure it contains
+ * an LDR image of some sort.
+ */
+static bool ldr_valid_signature(uint8_t *data)
+{
+#if defined(__ADSPBF561__)
+
+       /* BF56x has a 4 byte global header */
+       if (data[3] == (GFLAG_56X_SIGN_MAGIC << (GFLAG_56X_SIGN_SHIFT - 24)))
+               return true;
+
+#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
+      defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
+      defined(__ADSPBF538__) || defined(__ADSPBF539__)
+
+       /* all the BF53x should start at this address mask */
+       uint32_t addr;
+       memmove(&addr, data, sizeof(addr));
+       if ((addr & 0xFF0FFF0F) == 0xFF000000)
+               return true;
+#else
+
+       /* everything newer has a magic byte */
+       uint32_t count;
+       memmove(&count, data + 8, sizeof(count));
+       if (data[3] == 0xAD && count == 0)
+               return true;
+
+#endif
+
+       return false;
+}
+
+/* If the Blackfin is new enough, the Blackfin on-chip ROM supports loading
+ * LDRs from random memory addresses.  So whenever possible, use that.  In
+ * the older cases (BF53x/BF561), parse the LDR format ourselves.
+ */
+static void ldr_load(uint8_t *base_addr)
+{
+#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
+  /*defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) ||*/\
+    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
+
+       uint32_t addr;
+       uint32_t count;
+       uint16_t flags;
+
+       /* the bf56x has a 4 byte global header ... but it is useless to
+        * us when booting an LDR from a memory address, so skip it
+        */
+# ifdef __ADSPBF561__
+       base_addr += 4;
+# endif
+
+       memmove(&flags, base_addr + 8, sizeof(flags));
+       bfin_write_EVT1(flags & BFLAG_53X_RESVECT ? 0xFFA00000 : 0xFFA08000);
+
+       do {
+               /* block header may not be aligned */
+               memmove(&addr, base_addr, sizeof(addr));
+               memmove(&count, base_addr+4, sizeof(count));
+               memmove(&flags, base_addr+8, sizeof(flags));
+               base_addr += sizeof(addr) + sizeof(count) + sizeof(flags);
+
+               printf("loading to 0x%08x (%#x bytes) flags: 0x%04x\n",
+                       addr, count, flags);
+
+               if (!(flags & BFLAG_53X_IGNORE)) {
+                       if (flags & BFLAG_53X_ZEROFILL)
+                               memset((void *)addr, 0x00, count);
+                       else
+                               memcpy((void *)addr, base_addr, count);
+
+                       if (flags & BFLAG_53X_INIT) {
+                               void (*init)(void) = (void *)addr;
+                               init();
+                       }
+               }
+
+               if (!(flags & BFLAG_53X_ZEROFILL))
+                       base_addr += count;
+       } while (!(flags & BFLAG_53X_FINAL));
+
+#endif
+}
+
+/* For BF537, we use the _BOOTROM_BOOT_DXE_FLASH funky ROM function.
+ * For all other BF53x/BF56x, we just call the entry point.
+ * For everything else (newer), we use _BOOTROM_MEMBOOT ROM function.
+ */
+static void ldr_exec(void *addr)
+{
+#if defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
+
+       /* restore EVT1 to reset value as this is what the bootrom uses as
+        * the default entry point when booting the final block of LDRs
+        */
+       bfin_write_EVT1(L1_INST_SRAM);
+       __asm__("call (%0);" : : "a"(_BOOTROM_MEMBOOT), "q7"(addr) : "RETS", "memory");
+
+#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
+      defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
+
+       void (*ldr_entry)(void) = (void *)bfin_read_EVT1();
+       ldr_entry();
+
+#else
+
+       int32_t (*BOOTROM_MEM)(void *, int32_t, int32_t, void *) = (void *)_BOOTROM_MEMBOOT;
+       BOOTROM_MEM(addr, 0, 0, NULL);
+
+#endif
+}
+
+/*
+ * the bootldr command loads an address, checks to see if there
+ *   is a Boot stream that the on-chip BOOTROM can understand,
+ *   and loads it via the BOOTROM Callback. It is possible
+ *   to also add booting from SPI, or TWI, but this function does
+ *   not currently support that.
+ */
+int do_bootldr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       void *addr;
+
+       /* Get the address */
+       if (argc < 2)
+               addr = (void *)load_addr;
+       else
+               addr = (void *)simple_strtoul(argv[1], NULL, 16);
+
+       /* Check if it is a LDR file */
+       if (ldr_valid_signature(addr)) {
+               printf("## Booting ldr image at 0x%p ...\n", addr);
+               ldr_load(addr);
+
+               icache_disable();
+               dcache_disable();
+
+               ldr_exec(addr);
+       } else
+               printf("## No ldr image at address 0x%p\n", addr);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       bootldr, 2, 0, do_bootldr,
+       "boot ldr image from memory",
+       "[addr]\n"
+       ""
+);
diff --git a/cmd/bootm.c b/cmd/bootm.c
new file mode 100644 (file)
index 0000000..48738ac
--- /dev/null
@@ -0,0 +1,775 @@
+/*
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <bootm.h>
+#include <command.h>
+#include <environment.h>
+#include <errno.h>
+#include <image.h>
+#include <lmb.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <nand.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <linux/ctype.h>
+#include <linux/err.h>
+#include <u-boot/zlib.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if defined(CONFIG_CMD_IMI)
+static int image_info(unsigned long addr);
+#endif
+
+#if defined(CONFIG_CMD_IMLS)
+#include <flash.h>
+#include <mtd/cfi_flash.h>
+extern flash_info_t flash_info[]; /* info for FLASH chips */
+#endif
+
+#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
+static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+#endif
+
+bootm_headers_t images;                /* pointers to os/initrd/fdt images */
+
+/* we overload the cmd field with our state machine info instead of a
+ * function pointer */
+static cmd_tbl_t cmd_bootm_sub[] = {
+       U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
+       U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
+#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
+       U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
+#endif
+#ifdef CONFIG_OF_LIBFDT
+       U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
+       U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
+       U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
+       U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
+       U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
+};
+
+static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       int ret = 0;
+       long state;
+       cmd_tbl_t *c;
+
+       c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
+       argc--; argv++;
+
+       if (c) {
+               state = (long)c->cmd;
+               if (state == BOOTM_STATE_START)
+                       state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
+       } else {
+               /* Unrecognized command */
+               return CMD_RET_USAGE;
+       }
+
+       if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) &&
+           images.state >= state) {
+               printf("Trying to execute a command out of order\n");
+               return CMD_RET_USAGE;
+       }
+
+       ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
+
+       return ret;
+}
+
+/*******************************************************************/
+/* bootm - boot application image from image in memory */
+/*******************************************************************/
+
+int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+       static int relocated = 0;
+
+       if (!relocated) {
+               int i;
+
+               /* relocate names of sub-command table */
+               for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
+                       cmd_bootm_sub[i].name += gd->reloc_off;
+
+               relocated = 1;
+       }
+#endif
+
+       /* determine if we have a sub command */
+       argc--; argv++;
+       if (argc > 0) {
+               char *endp;
+
+               simple_strtoul(argv[0], &endp, 16);
+               /* endp pointing to NULL means that argv[0] was just a
+                * valid number, pass it along to the normal bootm processing
+                *
+                * If endp is ':' or '#' assume a FIT identifier so pass
+                * along for normal processing.
+                *
+                * Right now we assume the first arg should never be '-'
+                */
+               if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
+                       return do_bootm_subcommand(cmdtp, flag, argc, argv);
+       }
+
+       return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
+               BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
+               BOOTM_STATE_LOADOS |
+#if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
+               BOOTM_STATE_OS_CMDLINE |
+#endif
+               BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
+               BOOTM_STATE_OS_GO, &images, 1);
+}
+
+int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
+{
+       const char *ep = getenv("autostart");
+
+       if (ep && !strcmp(ep, "yes")) {
+               char *local_args[2];
+               local_args[0] = (char *)cmd;
+               local_args[1] = NULL;
+               printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
+               return do_bootm(cmdtp, 0, 1, local_args);
+       }
+
+       return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char bootm_help_text[] =
+       "[addr [arg ...]]\n    - boot application image stored in memory\n"
+       "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
+       "\t'arg' can be the address of an initrd image\n"
+#if defined(CONFIG_OF_LIBFDT)
+       "\tWhen booting a Linux kernel which requires a flat device-tree\n"
+       "\ta third argument is required which is the address of the\n"
+       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+       "\tuse a '-' for the second argument. If you do not pass a third\n"
+       "\ta bd_info struct will be passed instead\n"
+#endif
+#if defined(CONFIG_FIT)
+       "\t\nFor the new multi component uImage format (FIT) addresses\n"
+       "\tmust be extened to include component or configuration unit name:\n"
+       "\taddr:<subimg_uname> - direct component image specification\n"
+       "\taddr#<conf_uname>   - configuration specification\n"
+       "\tUse iminfo command to get the list of existing component\n"
+       "\timages and configurations.\n"
+#endif
+       "\nSub-commands to do part of the bootm sequence.  The sub-commands "
+       "must be\n"
+       "issued in the order below (it's ok to not issue all sub-commands):\n"
+       "\tstart [addr [arg ...]]\n"
+       "\tloados  - load OS image\n"
+#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
+       "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
+#endif
+#if defined(CONFIG_OF_LIBFDT)
+       "\tfdt     - relocate flat device tree\n"
+#endif
+       "\tcmdline - OS specific command line processing/setup\n"
+       "\tbdt     - OS specific bd_t processing\n"
+       "\tprep    - OS specific prep before relocation or go\n"
+#if defined(CONFIG_TRACE)
+       "\tfake    - OS specific fake start without go\n"
+#endif
+       "\tgo      - start OS";
+#endif
+
+U_BOOT_CMD(
+       bootm,  CONFIG_SYS_MAXARGS,     1,      do_bootm,
+       "boot application image from memory", bootm_help_text
+);
+
+/*******************************************************************/
+/* bootd - boot default image */
+/*******************************************************************/
+#if defined(CONFIG_CMD_BOOTD)
+int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return run_command(getenv("bootcmd"), flag);
+}
+
+U_BOOT_CMD(
+       boot,   1,      1,      do_bootd,
+       "boot default, i.e., run 'bootcmd'",
+       ""
+);
+
+/* keep old command name "bootd" for backward compatibility */
+U_BOOT_CMD(
+       bootd, 1,       1,      do_bootd,
+       "boot default, i.e., run 'bootcmd'",
+       ""
+);
+
+#endif
+
+
+/*******************************************************************/
+/* iminfo - print header info for a requested image */
+/*******************************************************************/
+#if defined(CONFIG_CMD_IMI)
+static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int     arg;
+       ulong   addr;
+       int     rcode = 0;
+
+       if (argc < 2) {
+               return image_info(load_addr);
+       }
+
+       for (arg = 1; arg < argc; ++arg) {
+               addr = simple_strtoul(argv[arg], NULL, 16);
+               if (image_info(addr) != 0)
+                       rcode = 1;
+       }
+       return rcode;
+}
+
+static int image_info(ulong addr)
+{
+       void *hdr = (void *)addr;
+
+       printf("\n## Checking Image at %08lx ...\n", addr);
+
+       switch (genimg_get_format(hdr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+               puts("   Legacy image found\n");
+               if (!image_check_magic(hdr)) {
+                       puts("   Bad Magic Number\n");
+                       return 1;
+               }
+
+               if (!image_check_hcrc(hdr)) {
+                       puts("   Bad Header Checksum\n");
+                       return 1;
+               }
+
+               image_print_contents(hdr);
+
+               puts("   Verifying Checksum ... ");
+               if (!image_check_dcrc(hdr)) {
+                       puts("   Bad Data CRC\n");
+                       return 1;
+               }
+               puts("OK\n");
+               return 0;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               puts("   FIT image found\n");
+
+               if (!fit_check_format(hdr)) {
+                       puts("Bad FIT image format!\n");
+                       return 1;
+               }
+
+               fit_print_contents(hdr);
+
+               if (!fit_all_image_verify(hdr)) {
+                       puts("Bad hash in FIT image!\n");
+                       return 1;
+               }
+
+               return 0;
+#endif
+       default:
+               puts("Unknown image format!\n");
+               break;
+       }
+
+       return 1;
+}
+
+U_BOOT_CMD(
+       iminfo, CONFIG_SYS_MAXARGS,     1,      do_iminfo,
+       "print header information for application image",
+       "addr [addr ...]\n"
+       "    - print header information for application image starting at\n"
+       "      address 'addr' in memory; this includes verification of the\n"
+       "      image contents (magic number, header and payload checksums)"
+);
+#endif
+
+
+/*******************************************************************/
+/* imls - list all images found in flash */
+/*******************************************************************/
+#if defined(CONFIG_CMD_IMLS)
+static int do_imls_nor(void)
+{
+       flash_info_t *info;
+       int i, j;
+       void *hdr;
+
+       for (i = 0, info = &flash_info[0];
+               i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
+
+               if (info->flash_id == FLASH_UNKNOWN)
+                       goto next_bank;
+               for (j = 0; j < info->sector_count; ++j) {
+
+                       hdr = (void *)info->start[j];
+                       if (!hdr)
+                               goto next_sector;
+
+                       switch (genimg_get_format(hdr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+                       case IMAGE_FORMAT_LEGACY:
+                               if (!image_check_hcrc(hdr))
+                                       goto next_sector;
+
+                               printf("Legacy Image at %08lX:\n", (ulong)hdr);
+                               image_print_contents(hdr);
+
+                               puts("   Verifying Checksum ... ");
+                               if (!image_check_dcrc(hdr)) {
+                                       puts("Bad Data CRC\n");
+                               } else {
+                                       puts("OK\n");
+                               }
+                               break;
+#endif
+#if defined(CONFIG_FIT)
+                       case IMAGE_FORMAT_FIT:
+                               if (!fit_check_format(hdr))
+                                       goto next_sector;
+
+                               printf("FIT Image at %08lX:\n", (ulong)hdr);
+                               fit_print_contents(hdr);
+                               break;
+#endif
+                       default:
+                               goto next_sector;
+                       }
+
+next_sector:           ;
+               }
+next_bank:     ;
+       }
+       return 0;
+}
+#endif
+
+#if defined(CONFIG_CMD_IMLS_NAND)
+static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
+               size_t len)
+{
+       void *imgdata;
+       int ret;
+
+       imgdata = malloc(len);
+       if (!imgdata) {
+               printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
+                               nand_dev, off);
+               printf("   Low memory(cannot allocate memory for image)\n");
+               return -ENOMEM;
+       }
+
+       ret = nand_read_skip_bad(nand, off, &len,
+                       imgdata);
+       if (ret < 0 && ret != -EUCLEAN) {
+               free(imgdata);
+               return ret;
+       }
+
+       if (!image_check_hcrc(imgdata)) {
+               free(imgdata);
+               return 0;
+       }
+
+       printf("Legacy Image at NAND device %d offset %08llX:\n",
+                       nand_dev, off);
+       image_print_contents(imgdata);
+
+       puts("   Verifying Checksum ... ");
+       if (!image_check_dcrc(imgdata))
+               puts("Bad Data CRC\n");
+       else
+               puts("OK\n");
+
+       free(imgdata);
+
+       return 0;
+}
+
+static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
+               size_t len)
+{
+       void *imgdata;
+       int ret;
+
+       imgdata = malloc(len);
+       if (!imgdata) {
+               printf("May be a FIT Image at NAND device %d offset %08llX:\n",
+                               nand_dev, off);
+               printf("   Low memory(cannot allocate memory for image)\n");
+               return -ENOMEM;
+       }
+
+       ret = nand_read_skip_bad(nand, off, &len,
+                       imgdata);
+       if (ret < 0 && ret != -EUCLEAN) {
+               free(imgdata);
+               return ret;
+       }
+
+       if (!fit_check_format(imgdata)) {
+               free(imgdata);
+               return 0;
+       }
+
+       printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
+
+       fit_print_contents(imgdata);
+       free(imgdata);
+
+       return 0;
+}
+
+static int do_imls_nand(void)
+{
+       nand_info_t *nand;
+       int nand_dev = nand_curr_device;
+       size_t len;
+       loff_t off;
+       u32 buffer[16];
+
+       if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
+               puts("\nNo NAND devices available\n");
+               return -ENODEV;
+       }
+
+       printf("\n");
+
+       for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
+               nand = &nand_info[nand_dev];
+               if (!nand->name || !nand->size)
+                       continue;
+
+               for (off = 0; off < nand->size; off += nand->erasesize) {
+                       const image_header_t *header;
+                       int ret;
+
+                       if (nand_block_isbad(nand, off))
+                               continue;
+
+                       len = sizeof(buffer);
+
+                       ret = nand_read(nand, off, &len, (u8 *)buffer);
+                       if (ret < 0 && ret != -EUCLEAN) {
+                               printf("NAND read error %d at offset %08llX\n",
+                                               ret, off);
+                               continue;
+                       }
+
+                       switch (genimg_get_format(buffer)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+                       case IMAGE_FORMAT_LEGACY:
+                               header = (const image_header_t *)buffer;
+
+                               len = image_get_image_size(header);
+                               nand_imls_legacyimage(nand, nand_dev, off, len);
+                               break;
+#endif
+#if defined(CONFIG_FIT)
+                       case IMAGE_FORMAT_FIT:
+                               len = fit_get_size(buffer);
+                               nand_imls_fitimage(nand, nand_dev, off, len);
+                               break;
+#endif
+                       }
+               }
+       }
+
+       return 0;
+}
+#endif
+
+#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
+static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret_nor = 0, ret_nand = 0;
+
+#if defined(CONFIG_CMD_IMLS)
+       ret_nor = do_imls_nor();
+#endif
+
+#if defined(CONFIG_CMD_IMLS_NAND)
+       ret_nand = do_imls_nand();
+#endif
+
+       if (ret_nor)
+               return ret_nor;
+
+       if (ret_nand)
+               return ret_nand;
+
+       return (0);
+}
+
+U_BOOT_CMD(
+       imls,   1,              1,      do_imls,
+       "list all images found in flash",
+       "\n"
+       "    - Prints information about all images found at sector/block\n"
+       "      boundaries in nor/nand flash."
+);
+#endif
+
+#ifdef CONFIG_CMD_BOOTZ
+
+int __weak bootz_setup(ulong image, ulong *start, ulong *end)
+{
+       /* Please define bootz_setup() for your platform */
+
+       puts("Your platform's zImage format isn't supported yet!\n");
+       return -1;
+}
+
+/*
+ * zImage booting support
+ */
+static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[], bootm_headers_t *images)
+{
+       int ret;
+       ulong zi_start, zi_end;
+
+       ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
+                             images, 1);
+
+       /* Setup Linux kernel zImage entry point */
+       if (!argc) {
+               images->ep = load_addr;
+               debug("*  kernel: default image load address = 0x%08lx\n",
+                               load_addr);
+       } else {
+               images->ep = simple_strtoul(argv[0], NULL, 16);
+               debug("*  kernel: cmdline image address = 0x%08lx\n",
+                       images->ep);
+       }
+
+       ret = bootz_setup(images->ep, &zi_start, &zi_end);
+       if (ret != 0)
+               return 1;
+
+       lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
+
+       /*
+        * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
+        * have a header that provide this informaiton.
+        */
+       if (bootm_find_images(flag, argc, argv))
+               return 1;
+
+       return 0;
+}
+
+int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret;
+
+       /* Consume 'bootz' */
+       argc--; argv++;
+
+       if (bootz_start(cmdtp, flag, argc, argv, &images))
+               return 1;
+
+       /*
+        * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
+        * disable interrupts ourselves
+        */
+       bootm_disable_interrupts();
+
+       images.os.os = IH_OS_LINUX;
+       ret = do_bootm_states(cmdtp, flag, argc, argv,
+                             BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
+                             BOOTM_STATE_OS_GO,
+                             &images, 1);
+
+       return ret;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char bootz_help_text[] =
+       "[addr [initrd[:size]] [fdt]]\n"
+       "    - boot Linux zImage stored in memory\n"
+       "\tThe argument 'initrd' is optional and specifies the address\n"
+       "\tof the initrd in memory. The optional argument ':size' allows\n"
+       "\tspecifying the size of RAW initrd.\n"
+#if defined(CONFIG_OF_LIBFDT)
+       "\tWhen booting a Linux kernel which requires a flat device-tree\n"
+       "\ta third argument is required which is the address of the\n"
+       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+       "\tuse a '-' for the second argument. If you do not pass a third\n"
+       "\ta bd_info struct will be passed instead\n"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       bootz,  CONFIG_SYS_MAXARGS,     1,      do_bootz,
+       "boot Linux zImage image from memory", bootz_help_text
+);
+#endif /* CONFIG_CMD_BOOTZ */
+
+#ifdef CONFIG_CMD_BOOTI
+/* See Documentation/arm64/booting.txt in the Linux kernel */
+struct Image_header {
+       uint32_t        code0;          /* Executable code */
+       uint32_t        code1;          /* Executable code */
+       uint64_t        text_offset;    /* Image load offset, LE */
+       uint64_t        image_size;     /* Effective Image size, LE */
+       uint64_t        res1;           /* reserved */
+       uint64_t        res2;           /* reserved */
+       uint64_t        res3;           /* reserved */
+       uint64_t        res4;           /* reserved */
+       uint32_t        magic;          /* Magic number */
+       uint32_t        res5;
+};
+
+#define LINUX_ARM64_IMAGE_MAGIC        0x644d5241
+
+static int booti_setup(bootm_headers_t *images)
+{
+       struct Image_header *ih;
+       uint64_t dst;
+
+       ih = (struct Image_header *)map_sysmem(images->ep, 0);
+
+       if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
+               puts("Bad Linux ARM64 Image magic!\n");
+               return 1;
+       }
+       
+       if (ih->image_size == 0) {
+               puts("Image lacks image_size field, assuming 16MiB\n");
+               ih->image_size = (16 << 20);
+       }
+
+       /*
+        * If we are not at the correct run-time location, set the new
+        * correct location and then move the image there.
+        */
+       dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset);
+       if (images->ep != dst) {
+               void *src;
+
+               debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst);
+
+               src = (void *)images->ep;
+               images->ep = dst;
+               memmove((void *)dst, src, le32_to_cpu(ih->image_size));
+       }
+
+       return 0;
+}
+
+/*
+ * Image booting support
+ */
+static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[], bootm_headers_t *images)
+{
+       int ret;
+       struct Image_header *ih;
+
+       ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
+                             images, 1);
+
+       /* Setup Linux kernel Image entry point */
+       if (!argc) {
+               images->ep = load_addr;
+               debug("*  kernel: default image load address = 0x%08lx\n",
+                               load_addr);
+       } else {
+               images->ep = simple_strtoul(argv[0], NULL, 16);
+               debug("*  kernel: cmdline image address = 0x%08lx\n",
+                       images->ep);
+       }
+
+       ret = booti_setup(images);
+       if (ret != 0)
+               return 1;
+
+       ih = (struct Image_header *)map_sysmem(images->ep, 0);
+
+       lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size));
+
+       /*
+        * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
+        * have a header that provide this informaiton.
+        */
+       if (bootm_find_images(flag, argc, argv))
+               return 1;
+
+       return 0;
+}
+
+int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret;
+
+       /* Consume 'booti' */
+       argc--; argv++;
+
+       if (booti_start(cmdtp, flag, argc, argv, &images))
+               return 1;
+
+       /*
+        * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
+        * disable interrupts ourselves
+        */
+       bootm_disable_interrupts();
+
+       images.os.os = IH_OS_LINUX;
+       ret = do_bootm_states(cmdtp, flag, argc, argv,
+                             BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
+                             BOOTM_STATE_OS_GO,
+                             &images, 1);
+
+       return ret;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char booti_help_text[] =
+       "[addr [initrd[:size]] [fdt]]\n"
+       "    - boot Linux Image stored in memory\n"
+       "\tThe argument 'initrd' is optional and specifies the address\n"
+       "\tof the initrd in memory. The optional argument ':size' allows\n"
+       "\tspecifying the size of RAW initrd.\n"
+#if defined(CONFIG_OF_LIBFDT)
+       "\tSince booting a Linux kernelrequires a flat device-tree\n"
+       "\ta third argument is required which is the address of the\n"
+       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+       "\tuse a '-' for the second argument.\n"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       booti,  CONFIG_SYS_MAXARGS,     1,      do_booti,
+       "boot arm64 Linux Image image from memory", booti_help_text
+);
+#endif /* CONFIG_CMD_BOOTI */
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
new file mode 100644 (file)
index 0000000..5879065
--- /dev/null
@@ -0,0 +1,500 @@
+/*
+ * (C) Copyright 2011-2013 Pali Rohár <pali.rohar@gmail.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <ansi.h>
+#include <menu.h>
+#include <watchdog.h>
+#include <malloc.h>
+#include <linux/string.h>
+
+/* maximum bootmenu entries */
+#define MAX_COUNT      99
+
+/* maximal size of bootmenu env
+ *  9 = strlen("bootmenu_")
+ *  2 = strlen(MAX_COUNT)
+ *  1 = NULL term
+ */
+#define MAX_ENV_SIZE   (9 + 2 + 1)
+
+struct bootmenu_entry {
+       unsigned short int num;         /* unique number 0 .. MAX_COUNT */
+       char key[3];                    /* key identifier of number */
+       char *title;                    /* title of entry */
+       char *command;                  /* hush command of entry */
+       struct bootmenu_data *menu;     /* this bootmenu */
+       struct bootmenu_entry *next;    /* next menu entry (num+1) */
+};
+
+struct bootmenu_data {
+       int delay;                      /* delay for autoboot */
+       int active;                     /* active menu entry */
+       int count;                      /* total count of menu entries */
+       struct bootmenu_entry *first;   /* first menu entry */
+};
+
+enum bootmenu_key {
+       KEY_NONE = 0,
+       KEY_UP,
+       KEY_DOWN,
+       KEY_SELECT,
+};
+
+static char *bootmenu_getoption(unsigned short int n)
+{
+       char name[MAX_ENV_SIZE];
+
+       if (n > MAX_COUNT)
+               return NULL;
+
+       sprintf(name, "bootmenu_%d", n);
+       return getenv(name);
+}
+
+static void bootmenu_print_entry(void *data)
+{
+       struct bootmenu_entry *entry = data;
+       int reverse = (entry->menu->active == entry->num);
+
+       /*
+        * Move cursor to line where the entry will be drown (entry->num)
+        * First 3 lines contain bootmenu header + 1 empty line
+        */
+       printf(ANSI_CURSOR_POSITION, entry->num + 4, 1);
+
+       puts("     ");
+
+       if (reverse)
+               puts(ANSI_COLOR_REVERSE);
+
+       puts(entry->title);
+
+       if (reverse)
+               puts(ANSI_COLOR_RESET);
+}
+
+static void bootmenu_autoboot_loop(struct bootmenu_data *menu,
+                               enum bootmenu_key *key, int *esc)
+{
+       int i, c;
+
+       if (menu->delay > 0) {
+               printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
+               printf("  Hit any key to stop autoboot: %2d ", menu->delay);
+       }
+
+       while (menu->delay > 0) {
+               for (i = 0; i < 100; ++i) {
+                       if (!tstc()) {
+                               WATCHDOG_RESET();
+                               mdelay(10);
+                               continue;
+                       }
+
+                       menu->delay = -1;
+                       c = getc();
+
+                       switch (c) {
+                       case '\e':
+                               *esc = 1;
+                               *key = KEY_NONE;
+                               break;
+                       case '\r':
+                               *key = KEY_SELECT;
+                               break;
+                       default:
+                               *key = KEY_NONE;
+                               break;
+                       }
+
+                       break;
+               }
+
+               if (menu->delay < 0)
+                       break;
+
+               --menu->delay;
+               printf("\b\b\b%2d ", menu->delay);
+       }
+
+       printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
+       puts(ANSI_CLEAR_LINE);
+
+       if (menu->delay == 0)
+               *key = KEY_SELECT;
+}
+
+static void bootmenu_loop(struct bootmenu_data *menu,
+               enum bootmenu_key *key, int *esc)
+{
+       int c;
+
+       while (!tstc()) {
+               WATCHDOG_RESET();
+               mdelay(10);
+       }
+
+       c = getc();
+
+       switch (*esc) {
+       case 0:
+               /* First char of ANSI escape sequence '\e' */
+               if (c == '\e') {
+                       *esc = 1;
+                       *key = KEY_NONE;
+               }
+               break;
+       case 1:
+               /* Second char of ANSI '[' */
+               if (c == '[') {
+                       *esc = 2;
+                       *key = KEY_NONE;
+               } else {
+                       *esc = 0;
+               }
+               break;
+       case 2:
+       case 3:
+               /* Third char of ANSI (number '1') - optional */
+               if (*esc == 2 && c == '1') {
+                       *esc = 3;
+                       *key = KEY_NONE;
+                       break;
+               }
+
+               *esc = 0;
+
+               /* ANSI 'A' - key up was pressed */
+               if (c == 'A')
+                       *key = KEY_UP;
+               /* ANSI 'B' - key down was pressed */
+               else if (c == 'B')
+                       *key = KEY_DOWN;
+               /* other key was pressed */
+               else
+                       *key = KEY_NONE;
+
+               break;
+       }
+
+       /* enter key was pressed */
+       if (c == '\r')
+               *key = KEY_SELECT;
+}
+
+static char *bootmenu_choice_entry(void *data)
+{
+       struct bootmenu_data *menu = data;
+       struct bootmenu_entry *iter;
+       enum bootmenu_key key = KEY_NONE;
+       int esc = 0;
+       int i;
+
+       while (1) {
+               if (menu->delay >= 0) {
+                       /* Autoboot was not stopped */
+                       bootmenu_autoboot_loop(menu, &key, &esc);
+               } else {
+                       /* Some key was pressed, so autoboot was stopped */
+                       bootmenu_loop(menu, &key, &esc);
+               }
+
+               switch (key) {
+               case KEY_UP:
+                       if (menu->active > 0)
+                               --menu->active;
+                       /* no menu key selected, regenerate menu */
+                       return NULL;
+               case KEY_DOWN:
+                       if (menu->active < menu->count - 1)
+                               ++menu->active;
+                       /* no menu key selected, regenerate menu */
+                       return NULL;
+               case KEY_SELECT:
+                       iter = menu->first;
+                       for (i = 0; i < menu->active; ++i)
+                               iter = iter->next;
+                       return iter->key;
+               default:
+                       break;
+               }
+       }
+
+       /* never happens */
+       debug("bootmenu: this should not happen");
+       return NULL;
+}
+
+static void bootmenu_destroy(struct bootmenu_data *menu)
+{
+       struct bootmenu_entry *iter = menu->first;
+       struct bootmenu_entry *next;
+
+       while (iter) {
+               next = iter->next;
+               free(iter->title);
+               free(iter->command);
+               free(iter);
+               iter = next;
+       }
+       free(menu);
+}
+
+static struct bootmenu_data *bootmenu_create(int delay)
+{
+       unsigned short int i = 0;
+       const char *option;
+       struct bootmenu_data *menu;
+       struct bootmenu_entry *iter = NULL;
+
+       int len;
+       char *sep;
+       struct bootmenu_entry *entry;
+
+       menu = malloc(sizeof(struct bootmenu_data));
+       if (!menu)
+               return NULL;
+
+       menu->delay = delay;
+       menu->active = 0;
+       menu->first = NULL;
+
+       while ((option = bootmenu_getoption(i))) {
+               sep = strchr(option, '=');
+               if (!sep) {
+                       printf("Invalid bootmenu entry: %s\n", option);
+                       break;
+               }
+
+               entry = malloc(sizeof(struct bootmenu_entry));
+               if (!entry)
+                       goto cleanup;
+
+               len = sep-option;
+               entry->title = malloc(len + 1);
+               if (!entry->title) {
+                       free(entry);
+                       goto cleanup;
+               }
+               memcpy(entry->title, option, len);
+               entry->title[len] = 0;
+
+               len = strlen(sep + 1);
+               entry->command = malloc(len + 1);
+               if (!entry->command) {
+                       free(entry->title);
+                       free(entry);
+                       goto cleanup;
+               }
+               memcpy(entry->command, sep + 1, len);
+               entry->command[len] = 0;
+
+               sprintf(entry->key, "%d", i);
+
+               entry->num = i;
+               entry->menu = menu;
+               entry->next = NULL;
+
+               if (!iter)
+                       menu->first = entry;
+               else
+                       iter->next = entry;
+
+               iter = entry;
+               ++i;
+
+               if (i == MAX_COUNT - 1)
+                       break;
+       }
+
+       /* Add U-Boot console entry at the end */
+       if (i <= MAX_COUNT - 1) {
+               entry = malloc(sizeof(struct bootmenu_entry));
+               if (!entry)
+                       goto cleanup;
+
+               entry->title = strdup("U-Boot console");
+               if (!entry->title) {
+                       free(entry);
+                       goto cleanup;
+               }
+
+               entry->command = strdup("");
+               if (!entry->command) {
+                       free(entry->title);
+                       free(entry);
+                       goto cleanup;
+               }
+
+               sprintf(entry->key, "%d", i);
+
+               entry->num = i;
+               entry->menu = menu;
+               entry->next = NULL;
+
+               if (!iter)
+                       menu->first = entry;
+               else
+                       iter->next = entry;
+
+               iter = entry;
+               ++i;
+       }
+
+       menu->count = i;
+       return menu;
+
+cleanup:
+       bootmenu_destroy(menu);
+       return NULL;
+}
+
+static void bootmenu_show(int delay)
+{
+       int init = 0;
+       void *choice = NULL;
+       char *title = NULL;
+       char *command = NULL;
+       struct menu *menu;
+       struct bootmenu_data *bootmenu;
+       struct bootmenu_entry *iter;
+       char *option, *sep;
+
+       /* If delay is 0 do not create menu, just run first entry */
+       if (delay == 0) {
+               option = bootmenu_getoption(0);
+               if (!option) {
+                       puts("bootmenu option 0 was not found\n");
+                       return;
+               }
+               sep = strchr(option, '=');
+               if (!sep) {
+                       puts("bootmenu option 0 is invalid\n");
+                       return;
+               }
+               run_command(sep+1, 0);
+               return;
+       }
+
+       bootmenu = bootmenu_create(delay);
+       if (!bootmenu)
+               return;
+
+       menu = menu_create(NULL, bootmenu->delay, 1, bootmenu_print_entry,
+                          bootmenu_choice_entry, bootmenu);
+       if (!menu) {
+               bootmenu_destroy(bootmenu);
+               return;
+       }
+
+       for (iter = bootmenu->first; iter; iter = iter->next) {
+               if (!menu_item_add(menu, iter->key, iter))
+                       goto cleanup;
+       }
+
+       /* Default menu entry is always first */
+       menu_default_set(menu, "0");
+
+       puts(ANSI_CURSOR_HIDE);
+       puts(ANSI_CLEAR_CONSOLE);
+       printf(ANSI_CURSOR_POSITION, 1, 1);
+
+       init = 1;
+
+       if (menu_get_choice(menu, &choice)) {
+               iter = choice;
+               title = strdup(iter->title);
+               command = strdup(iter->command);
+       }
+
+cleanup:
+       menu_destroy(menu);
+       bootmenu_destroy(bootmenu);
+
+       if (init) {
+               puts(ANSI_CURSOR_SHOW);
+               puts(ANSI_CLEAR_CONSOLE);
+               printf(ANSI_CURSOR_POSITION, 1, 1);
+       }
+
+       if (title && command) {
+               debug("Starting entry '%s'\n", title);
+               free(title);
+               run_command(command, 0);
+               free(command);
+       }
+
+#ifdef CONFIG_POSTBOOTMENU
+       run_command(CONFIG_POSTBOOTMENU, 0);
+#endif
+}
+
+void menu_display_statusline(struct menu *m)
+{
+       struct bootmenu_entry *entry;
+       struct bootmenu_data *menu;
+
+       if (menu_default_choice(m, (void *)&entry) < 0)
+               return;
+
+       menu = entry->menu;
+
+       printf(ANSI_CURSOR_POSITION, 1, 1);
+       puts(ANSI_CLEAR_LINE);
+       printf(ANSI_CURSOR_POSITION, 2, 1);
+       puts("  *** U-Boot Boot Menu ***");
+       puts(ANSI_CLEAR_LINE_TO_END);
+       printf(ANSI_CURSOR_POSITION, 3, 1);
+       puts(ANSI_CLEAR_LINE);
+
+       /* First 3 lines are bootmenu header + 2 empty lines between entries */
+       printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
+       puts(ANSI_CLEAR_LINE);
+       printf(ANSI_CURSOR_POSITION, menu->count + 6, 1);
+       puts("  Press UP/DOWN to move, ENTER to select");
+       puts(ANSI_CLEAR_LINE_TO_END);
+       printf(ANSI_CURSOR_POSITION, menu->count + 7, 1);
+       puts(ANSI_CLEAR_LINE);
+}
+
+#ifdef CONFIG_MENU_SHOW
+int menu_show(int bootdelay)
+{
+       bootmenu_show(bootdelay);
+       return -1; /* -1 - abort boot and run monitor code */
+}
+#endif
+
+int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *delay_str = NULL;
+       int delay = 10;
+
+#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
+       delay = CONFIG_BOOTDELAY;
+#endif
+
+       if (argc >= 2)
+               delay_str = argv[1];
+
+       if (!delay_str)
+               delay_str = getenv("bootmenu_delay");
+
+       if (delay_str)
+               delay = (int)simple_strtol(delay_str, NULL, 10);
+
+       bootmenu_show(delay);
+       return 0;
+}
+
+U_BOOT_CMD(
+       bootmenu, 2, 1, do_bootmenu,
+       "ANSI terminal bootmenu",
+       "[delay]\n"
+       "    - show ANSI terminal bootmenu with autoboot delay"
+);
diff --git a/cmd/bootstage.c b/cmd/bootstage.c
new file mode 100644 (file)
index 0000000..788ab16
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2012, Google Inc. All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+
+static int do_bootstage_report(cmd_tbl_t *cmdtp, int flag, int argc,
+                              char * const argv[])
+{
+       bootstage_report();
+
+       return 0;
+}
+
+static int get_base_size(int argc, char * const argv[], ulong *basep,
+                        ulong *sizep)
+{
+       char *endp;
+
+       *basep = CONFIG_BOOTSTAGE_STASH_ADDR;
+       *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
+       if (argc < 2)
+               return 0;
+       *basep = simple_strtoul(argv[1], &endp, 16);
+       if (*argv[1] == 0 || *endp != 0)
+               return -1;
+       if (argc == 2)
+               return 0;
+       *sizep = simple_strtoul(argv[2], &endp, 16);
+       if (*argv[2] == 0 || *endp != 0)
+               return -1;
+
+       return 0;
+}
+
+static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc,
+                             char * const argv[])
+{
+       ulong base, size;
+       int ret;
+
+       if (get_base_size(argc, argv, &base, &size))
+               return CMD_RET_USAGE;
+       if (base == -1UL) {
+               printf("No bootstage stash area defined\n");
+               return 1;
+       }
+
+       if (0 == strcmp(argv[0], "stash"))
+               ret = bootstage_stash((void *)base, size);
+       else
+               ret = bootstage_unstash((void *)base, size);
+       if (ret)
+               return 1;
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_bootstage_sub[] = {
+       U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
+       U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
+       U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
+};
+
+/*
+ * Process a bootstage sub-command
+ */
+static int do_boostage(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       cmd_tbl_t *c;
+
+       /* Strip off leading 'bootstage' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
+                        ARRAY_SIZE(cmd_bootstage_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+
+U_BOOT_CMD(bootstage, 4, 1, do_boostage,
+       "Boot stage command",
+       " - check boot progress and timing\n"
+       "report                      - Print a report\n"
+       "stash [<start> [<size>]]    - Stash data into memory\n"
+       "unstash [<start> [<size>]]  - Unstash data from memory"
+);
diff --git a/cmd/cache.c b/cmd/cache.c
new file mode 100644 (file)
index 0000000..37ab345
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Cache support: switch on or off, get status
+ */
+#include <common.h>
+#include <command.h>
+#include <linux/compiler.h>
+
+static int parse_argv(const char *);
+
+void __weak invalidate_icache_all(void)
+{
+       /* please define arch specific invalidate_icache_all */
+       puts("No arch specific invalidate_icache_all available!\n");
+}
+
+static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       switch (argc) {
+       case 2:                 /* on / off     */
+               switch (parse_argv(argv[1])) {
+               case 0:
+                       icache_disable();
+                       break;
+               case 1:
+                       icache_enable();
+                       break;
+               case 2:
+                       invalidate_icache_all();
+                       break;
+               }
+               break;
+       case 1:                 /* get status */
+               printf("Instruction Cache is %s\n",
+                       icache_status() ? "ON" : "OFF");
+               return 0;
+       default:
+               return CMD_RET_USAGE;
+       }
+       return 0;
+}
+
+void __weak flush_dcache_all(void)
+{
+       puts("No arch specific flush_dcache_all available!\n");
+       /* please define arch specific flush_dcache_all */
+}
+
+static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       switch (argc) {
+       case 2:                 /* on / off */
+               switch (parse_argv(argv[1])) {
+               case 0:
+                       dcache_disable();
+                       break;
+               case 1:
+                       dcache_enable();
+                       break;
+               case 2:
+                       flush_dcache_all();
+                       break;
+               }
+               break;
+       case 1:                 /* get status */
+               printf("Data (writethrough) Cache is %s\n",
+                       dcache_status() ? "ON" : "OFF");
+               return 0;
+       default:
+               return CMD_RET_USAGE;
+       }
+       return 0;
+}
+
+static int parse_argv(const char *s)
+{
+       if (strcmp(s, "flush") == 0)
+               return 2;
+       else if (strcmp(s, "on") == 0)
+               return 1;
+       else if (strcmp(s, "off") == 0)
+               return 0;
+
+       return -1;
+}
+
+
+U_BOOT_CMD(
+       icache,   2,   1,     do_icache,
+       "enable or disable instruction cache",
+       "[on, off, flush]\n"
+       "    - enable, disable, or flush instruction cache"
+);
+
+U_BOOT_CMD(
+       dcache,   2,   1,     do_dcache,
+       "enable or disable data cache",
+       "[on, off, flush]\n"
+       "    - enable, disable, or flush data (writethrough) cache"
+);
diff --git a/cmd/cbfs.c b/cmd/cbfs.c
new file mode 100644 (file)
index 0000000..35d8a7a
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * CBFS commands
+ */
+#include <common.h>
+#include <command.h>
+#include <cbfs.h>
+
+int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       uintptr_t end_of_rom = 0xffffffff;
+       char *ep;
+
+       if (argc > 2) {
+               printf("usage: cbfsls [end of rom]>\n");
+               return 0;
+       }
+       if (argc == 2) {
+               end_of_rom = (int)simple_strtoul(argv[1], &ep, 16);
+               if (*ep) {
+                       puts("\n** Invalid end of ROM **\n");
+                       return 1;
+               }
+       }
+       file_cbfs_init(end_of_rom);
+       if (file_cbfs_result != CBFS_SUCCESS) {
+               printf("%s.\n", file_cbfs_error());
+               return 1;
+       }
+       return 0;
+}
+
+U_BOOT_CMD(
+       cbfsinit,       2,      0,      do_cbfs_init,
+       "initialize the cbfs driver",
+       "[end of rom]\n"
+       "    - Initialize the cbfs driver. The optional 'end of rom'\n"
+       "      parameter specifies where the end of the ROM is that the\n"
+       "      CBFS is in. It defaults to 0xFFFFFFFF\n"
+);
+
+int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       const struct cbfs_cachenode *file;
+       unsigned long offset;
+       unsigned long count;
+       long size;
+
+       if (argc < 3) {
+               printf("usage: cbfsload <addr> <filename> [bytes]\n");
+               return 1;
+       }
+
+       /* parse offset and count */
+       offset = simple_strtoul(argv[1], NULL, 16);
+       if (argc == 4)
+               count = simple_strtoul(argv[3], NULL, 16);
+       else
+               count = 0;
+
+       file = file_cbfs_find(argv[2]);
+       if (!file) {
+               if (file_cbfs_result == CBFS_FILE_NOT_FOUND)
+                       printf("%s: %s\n", file_cbfs_error(), argv[2]);
+               else
+                       printf("%s.\n", file_cbfs_error());
+               return 1;
+       }
+
+       printf("reading %s\n", file_cbfs_name(file));
+
+       size = file_cbfs_read(file, (void *)offset, count);
+
+       printf("\n%ld bytes read\n", size);
+
+       setenv_hex("filesize", size);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       cbfsload,       4,      0,      do_cbfs_fsload,
+       "load binary file from a cbfs filesystem",
+       "<addr> <filename> [bytes]\n"
+       "    - load binary file 'filename' from the cbfs to address 'addr'\n"
+);
+
+int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       const struct cbfs_cachenode *file = file_cbfs_get_first();
+       int files = 0;
+
+       if (!file) {
+               printf("%s.\n", file_cbfs_error());
+               return 1;
+       }
+
+       printf("     size              type  name\n");
+       printf("------------------------------------------\n");
+       while (file) {
+               u32 type = file_cbfs_type(file);
+               char *type_name = NULL;
+               const char *filename = file_cbfs_name(file);
+
+               printf(" %8d", file_cbfs_size(file));
+
+               switch (type) {
+               case CBFS_TYPE_STAGE:
+                       type_name = "stage";
+                       break;
+               case CBFS_TYPE_PAYLOAD:
+                       type_name = "payload";
+                       break;
+               case CBFS_TYPE_OPTIONROM:
+                       type_name = "option rom";
+                       break;
+               case CBFS_TYPE_BOOTSPLASH:
+                       type_name = "boot splash";
+                       break;
+               case CBFS_TYPE_RAW:
+                       type_name = "raw";
+                       break;
+               case CBFS_TYPE_VSA:
+                       type_name = "vsa";
+                       break;
+               case CBFS_TYPE_MBI:
+                       type_name = "mbi";
+                       break;
+               case CBFS_TYPE_MICROCODE:
+                       type_name = "microcode";
+                       break;
+               case CBFS_COMPONENT_CMOS_DEFAULT:
+                       type_name = "cmos default";
+                       break;
+               case CBFS_COMPONENT_CMOS_LAYOUT:
+                       type_name = "cmos layout";
+                       break;
+               case -1UL:
+                       type_name = "null";
+                       break;
+               }
+               if (type_name)
+                       printf("  %16s", type_name);
+               else
+                       printf("  %16d", type);
+
+               if (filename[0])
+                       printf("  %s\n", filename);
+               else
+                       printf("  %s\n", "(empty)");
+               file_cbfs_get_next(&file);
+               files++;
+       }
+
+       printf("\n%d file(s)\n\n", files);
+       return 0;
+}
+
+U_BOOT_CMD(
+       cbfsls, 1,      1,      do_cbfs_ls,
+       "list files",
+       "    - list the files in the cbfs\n"
+);
+
+int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       const struct cbfs_header *header = file_cbfs_get_header();
+
+       if (!header) {
+               printf("%s.\n", file_cbfs_error());
+               return 1;
+       }
+
+       printf("\n");
+       printf("CBFS version: %#x\n", header->version);
+       printf("ROM size: %#x\n", header->rom_size);
+       printf("Boot block size: %#x\n", header->boot_block_size);
+       printf("CBFS size: %#x\n",
+               header->rom_size - header->boot_block_size - header->offset);
+       printf("Alignment: %d\n", header->align);
+       printf("Offset: %#x\n", header->offset);
+       printf("\n");
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       cbfsinfo,       1,      1,      do_cbfs_fsinfo,
+       "print information about filesystem",
+       "    - print information about the cbfs filesystem\n"
+);
diff --git a/cmd/clk.c b/cmd/clk.c
new file mode 100644 (file)
index 0000000..6d3d46a
--- /dev/null
+++ b/cmd/clk.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 Xilinx, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <command.h>
+#include <clk.h>
+
+int __weak soc_clk_dump(void)
+{
+       puts("Not implemented\n");
+       return 1;
+}
+
+static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       return soc_clk_dump();
+}
+
+static cmd_tbl_t cmd_clk_sub[] = {
+       U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
+};
+
+static int do_clk(cmd_tbl_t *cmdtp, int flag, int argc,
+                 char *const argv[])
+{
+       cmd_tbl_t *c;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* Strip off leading 'clk' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char clk_help_text[] =
+       "dump - Print clock frequencies";
+#endif
+
+U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);
diff --git a/cmd/console.c b/cmd/console.c
new file mode 100644 (file)
index 0000000..9a356ec
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <stdio_dev.h>
+
+extern void _do_coninfo (void);
+static int do_coninfo(cmd_tbl_t *cmd, int flag, int argc, char * const argv[])
+{
+       int l;
+       struct list_head *list = stdio_get_list();
+       struct list_head *pos;
+       struct stdio_dev *dev;
+
+       /* Scan for valid output and input devices */
+
+       puts ("List of available devices:\n");
+
+       list_for_each(pos, list) {
+               dev = list_entry(pos, struct stdio_dev, list);
+
+               printf ("%-8s %08x %c%c ",
+                       dev->name,
+                       dev->flags,
+                       (dev->flags & DEV_FLAGS_INPUT) ? 'I' : '.',
+                       (dev->flags & DEV_FLAGS_OUTPUT) ? 'O' : '.');
+
+               for (l = 0; l < MAX_FILES; l++) {
+                       if (stdio_devices[l] == dev) {
+                               printf ("%s ", stdio_names[l]);
+                       }
+               }
+               putc ('\n');
+       }
+       return 0;
+}
+
+
+/***************************************************/
+
+U_BOOT_CMD(
+       coninfo,        3,      1,      do_coninfo,
+       "print console devices and information",
+       ""
+);
diff --git a/cmd/cplbinfo.c b/cmd/cplbinfo.c
new file mode 100644 (file)
index 0000000..ab5b3b5
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * cmd_cplbinfo.c - dump the instruction/data cplb tables
+ *
+ * Copyright (c) 2007-2008 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/blackfin.h>
+#include <asm/cplb.h>
+#include <asm/mach-common/bits/mpu.h>
+
+/*
+ * Translate the PAGE_SIZE bits into a human string
+ */
+static const char *cplb_page_size(uint32_t data)
+{
+       static const char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
+       return page_size_string_table[(data & PAGE_SIZE_MASK) >> PAGE_SIZE_SHIFT];
+}
+
+/*
+ * show a hardware cplb table
+ */
+static void show_cplb_table(uint32_t *addr, uint32_t *data)
+{
+       int i;
+       printf("      Address     Data   Size  Valid  Locked\n");
+       for (i = 1; i <= 16; ++i) {
+               printf(" %2i 0x%p  0x%05X   %s     %c      %c\n",
+                       i, (void *)*addr, *data,
+                       cplb_page_size(*data),
+                       (*data & CPLB_VALID ? 'Y' : 'N'),
+                       (*data & CPLB_LOCK ? 'Y' : 'N'));
+               ++addr;
+               ++data;
+       }
+}
+
+/*
+ * display current instruction and data cplb tables
+ */
+int do_cplbinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       printf("%s CPLB table [%08x]:\n", "Instruction", *(uint32_t *)DMEM_CONTROL);
+       show_cplb_table((uint32_t *)ICPLB_ADDR0, (uint32_t *)ICPLB_DATA0);
+
+       printf("%s CPLB table [%08x]:\n", "Data", *(uint32_t *)IMEM_CONTROL);
+       show_cplb_table((uint32_t *)DCPLB_ADDR0, (uint32_t *)DCPLB_DATA0);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       cplbinfo, 1, 0, do_cplbinfo,
+       "display current CPLB tables",
+       ""
+);
diff --git a/cmd/cpu.c b/cmd/cpu.c
new file mode 100644 (file)
index 0000000..b4af64f
--- /dev/null
+++ b/cmd/cpu.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <cpu.h>
+#include <dm.h>
+#include <errno.h>
+
+static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
+       "L1 cache",
+       "MMU",
+};
+
+static int print_cpu_list(bool detail)
+{
+       struct udevice *dev;
+       struct uclass *uc;
+       char buf[100];
+       int ret;
+
+       ret = uclass_get(UCLASS_CPU, &uc);
+       if (ret) {
+               printf("Cannot find CPU uclass\n");
+               return ret;
+       }
+       uclass_foreach_dev(dev, uc) {
+               struct cpu_platdata *plat = dev_get_parent_platdata(dev);
+               struct cpu_info info;
+               bool first;
+               int i;
+
+               ret = cpu_get_desc(dev, buf, sizeof(buf));
+               printf("%3d: %-10s %s\n", dev->seq, dev->name,
+                      ret ? "<no description>" : buf);
+               if (!detail)
+                       continue;
+               ret = cpu_get_info(dev, &info);
+               if (ret) {
+                       printf("\t(no detail available");
+                       if (ret != -ENOSYS)
+                               printf(": err=%d\n", ret);
+                       printf(")\n");
+                       continue;
+               }
+               printf("\tID = %d, freq = ", plat->cpu_id);
+               print_freq(info.cpu_freq, "");
+               first = true;
+               for (i = 0; i < CPU_FEAT_COUNT; i++) {
+                       if (info.features & (1 << i)) {
+                               printf("%s%s", first ? ": " : ", ",
+                                      cpu_feature_name[i]);
+                               first = false;
+                       }
+               }
+               printf("\n");
+       }
+
+       return 0;
+}
+
+static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       if (print_cpu_list(false))
+               return CMD_RET_FAILURE;
+
+       return 0;
+}
+
+static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char *const argv[])
+{
+       if (print_cpu_list(true))
+               return CMD_RET_FAILURE;
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_cpu_sub[] = {
+       U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
+       U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
+};
+
+/*
+ * Process a cpu sub-command
+ */
+static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       cmd_tbl_t *c = NULL;
+
+       /* Strip off leading 'cpu' command argument */
+       argc--;
+       argv++;
+
+       if (argc)
+               c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       cpu, 2, 1, do_cpu,
+       "display information about CPUs",
+       "list   - list available CPUs\n"
+       "cpu detail     - show CPU detail"
+);
diff --git a/cmd/cramfs.c b/cmd/cramfs.c
new file mode 100644 (file)
index 0000000..1d31326
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * SPDX-License-Identifier:    GPL-2.0+
+ *
+ * based on: cmd_jffs2.c
+ *
+ *     Add support for a CRAMFS located in RAM
+ */
+
+
+/*
+ * CRAMFS support
+ */
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+#include <jffs2/jffs2.h>
+#include <jffs2/load_kernel.h>
+#include <cramfs/cramfs_fs.h>
+
+/* enable/disable debugging messages */
+#define        DEBUG_CRAMFS
+#undef DEBUG_CRAMFS
+
+#ifdef  DEBUG_CRAMFS
+# define DEBUGF(fmt, args...)  printf(fmt ,##args)
+#else
+# define DEBUGF(fmt, args...)
+#endif
+
+#ifdef CONFIG_CRAMFS_CMDLINE
+#include <flash.h>
+
+#ifdef CONFIG_SYS_NO_FLASH
+# define OFFSET_ADJUSTMENT     0
+#else
+# define OFFSET_ADJUSTMENT     (flash_info[id.num].start[0])
+#endif
+
+#ifndef CONFIG_CMD_JFFS2
+#include <linux/stat.h>
+char *mkmodestr(unsigned long mode, char *str)
+{
+       static const char *l = "xwr";
+       int mask = 1, i;
+       char c;
+
+       switch (mode & S_IFMT) {
+               case S_IFDIR:    str[0] = 'd'; break;
+               case S_IFBLK:    str[0] = 'b'; break;
+               case S_IFCHR:    str[0] = 'c'; break;
+               case S_IFIFO:    str[0] = 'f'; break;
+               case S_IFLNK:    str[0] = 'l'; break;
+               case S_IFSOCK:   str[0] = 's'; break;
+               case S_IFREG:    str[0] = '-'; break;
+               default:         str[0] = '?';
+       }
+
+       for(i = 0; i < 9; i++) {
+               c = l[i%3];
+               str[9-i] = (mode & mask)?c:'-';
+               mask = mask<<1;
+       }
+
+       if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
+       if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
+       if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
+       str[10] = '\0';
+       return str;
+}
+#endif /* CONFIG_CMD_JFFS2 */
+
+extern int cramfs_check (struct part_info *info);
+extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
+extern int cramfs_ls (struct part_info *info, char *filename);
+extern int cramfs_info (struct part_info *info);
+
+/***************************************************/
+/* U-boot commands                                */
+/***************************************************/
+
+/**
+ * Routine implementing fsload u-boot command. This routine tries to load
+ * a requested file from cramfs filesystem at location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename;
+       int size;
+       ulong offset = load_addr;
+
+       struct part_info part;
+       struct mtd_device dev;
+       struct mtdids id;
+
+       ulong addr;
+       addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+       /* hack! */
+       /* cramfs_* only supports NOR flash chips */
+       /* fake the device type */
+       id.type = MTD_DEV_TYPE_NOR;
+       id.num = 0;
+       dev.id = &id;
+       part.dev = &dev;
+       /* fake the address offset */
+       part.offset = addr - OFFSET_ADJUSTMENT;
+
+       /* pre-set Boot file name */
+       if ((filename = getenv("bootfile")) == NULL) {
+               filename = "uImage";
+       }
+
+       if (argc == 2) {
+               filename = argv[1];
+       }
+       if (argc == 3) {
+               offset = simple_strtoul(argv[1], NULL, 0);
+               load_addr = offset;
+               filename = argv[2];
+       }
+
+       size = 0;
+       if (cramfs_check(&part))
+               size = cramfs_load ((char *) offset, &part, filename);
+
+       if (size > 0) {
+               printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
+                       size, offset);
+               setenv_hex("filesize", size);
+       } else {
+               printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
+       }
+
+       return !(size > 0);
+}
+
+/**
+ * Routine implementing u-boot ls command which lists content of a given
+ * directory at location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename = "/";
+       int ret;
+       struct part_info part;
+       struct mtd_device dev;
+       struct mtdids id;
+
+       ulong addr;
+       addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+       /* hack! */
+       /* cramfs_* only supports NOR flash chips */
+       /* fake the device type */
+       id.type = MTD_DEV_TYPE_NOR;
+       id.num = 0;
+       dev.id = &id;
+       part.dev = &dev;
+       /* fake the address offset */
+       part.offset = addr - OFFSET_ADJUSTMENT;
+
+       if (argc == 2)
+               filename = argv[1];
+
+       ret = 0;
+       if (cramfs_check(&part))
+               ret = cramfs_ls (&part, filename);
+
+       return ret ? 0 : 1;
+}
+
+/* command line only */
+
+/***************************************************/
+U_BOOT_CMD(
+       cramfsload,     3,      0,      do_cramfs_load,
+       "load binary file from a filesystem image",
+       "[ off ] [ filename ]\n"
+       "    - load binary file from address 'cramfsaddr'\n"
+       "      with offset 'off'\n"
+);
+U_BOOT_CMD(
+       cramfsls,       2,      1,      do_cramfs_ls,
+       "list files in a directory (default /)",
+       "[ directory ]\n"
+       "    - list files in a directory.\n"
+);
+
+#endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
+
+/***************************************************/
diff --git a/cmd/dataflash_mmc_mux.c b/cmd/dataflash_mmc_mux.c
new file mode 100644 (file)
index 0000000..3832248
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int mmc_nspi (const char *);
+
+int do_dataflash_mmc_mux (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       switch (argc) {
+       case 2:                 /* on / off     */
+               switch (mmc_nspi (argv[1])) {
+               case 0: AT91F_SelectSPI ();
+                       break;
+               case 1: AT91F_SelectMMC ();
+                       break;
+               }
+       case 1:                 /* get status */
+               printf ("Mux is configured to be %s\n",
+                       AT91F_GetMuxStatus () ? "MMC" : "SPI");
+               return 0;
+       default:
+               return CMD_RET_USAGE;
+       }
+       return 0;
+}
+
+static int mmc_nspi (const char *s)
+{
+       if (strcmp (s, "mmc") == 0) {
+               return 1;
+       } else if (strcmp (s, "spi") == 0) {
+               return 0;
+       }
+       return -1;
+}
+
+U_BOOT_CMD(
+       dataflash_mmc_mux, 2, 1, do_dataflash_mmc_mux,
+       "enable or disable MMC or SPI\n",
+       "[mmc, spi]\n"
+       "    - enable or disable MMC or SPI"
+);
diff --git a/cmd/date.c b/cmd/date.c
new file mode 100644 (file)
index 0000000..8714699
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * (C) Copyright 2001
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * RTC, Date & Time support: get and set date & time
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <rtc.h>
+#include <i2c.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const char * const weekdays[] = {
+       "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
+};
+
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+#define RELOC(a)       ((typeof(a))((unsigned long)(a) + gd->reloc_off))
+#else
+#define RELOC(a)       a
+#endif
+
+int mk_date (const char *, struct rtc_time *);
+
+static struct rtc_time default_tm = { 0, 0, 0, 1, 1, 2000, 6, 0, 0 };
+
+static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct rtc_time tm;
+       int rcode = 0;
+       int old_bus __maybe_unused;
+
+       /* switch to correct I2C bus */
+#ifdef CONFIG_DM_RTC
+       struct udevice *dev;
+
+       rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
+       if (rcode) {
+               printf("Cannot find RTC: err=%d\n", rcode);
+               return CMD_RET_FAILURE;
+       }
+#elif defined(CONFIG_SYS_I2C)
+       old_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
+#else
+       old_bus = I2C_GET_BUS();
+       I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM);
+#endif
+
+       switch (argc) {
+       case 2:                 /* set date & time */
+               if (strcmp(argv[1],"reset") == 0) {
+                       puts ("Reset RTC...\n");
+#ifdef CONFIG_DM_RTC
+                       rcode = dm_rtc_reset(dev);
+                       if (!rcode)
+                               rcode = dm_rtc_set(dev, &default_tm);
+#else
+                       rtc_reset();
+                       rcode = rtc_set(&default_tm);
+#endif
+                       if (rcode)
+                               puts("## Failed to set date after RTC reset\n");
+               } else {
+                       /* initialize tm with current time */
+#ifdef CONFIG_DM_RTC
+                       rcode = dm_rtc_get(dev, &tm);
+#else
+                       rcode = rtc_get(&tm);
+#endif
+                       if (!rcode) {
+                               /* insert new date & time */
+                               if (mk_date(argv[1], &tm) != 0) {
+                                       puts ("## Bad date format\n");
+                                       break;
+                               }
+                               /* and write to RTC */
+#ifdef CONFIG_DM_RTC
+                               rcode = dm_rtc_set(dev, &tm);
+#else
+                               rcode = rtc_set(&tm);
+#endif
+                               if (rcode) {
+                                       printf("## Set date failed: err=%d\n",
+                                              rcode);
+                               }
+                       } else {
+                               puts("## Get date failed\n");
+                       }
+               }
+               /* FALL TROUGH */
+       case 1:                 /* get date & time */
+#ifdef CONFIG_DM_RTC
+               rcode = dm_rtc_get(dev, &tm);
+#else
+               rcode = rtc_get(&tm);
+#endif
+               if (rcode) {
+                       puts("## Get date failed\n");
+                       break;
+               }
+
+               printf ("Date: %4d-%02d-%02d (%sday)    Time: %2d:%02d:%02d\n",
+                       tm.tm_year, tm.tm_mon, tm.tm_mday,
+                       (tm.tm_wday<0 || tm.tm_wday>6) ?
+                               "unknown " : RELOC(weekdays[tm.tm_wday]),
+                       tm.tm_hour, tm.tm_min, tm.tm_sec);
+
+               break;
+       default:
+               rcode = CMD_RET_USAGE;
+       }
+
+       /* switch back to original I2C bus */
+#ifdef CONFIG_SYS_I2C
+       i2c_set_bus_num(old_bus);
+#elif !defined(CONFIG_DM_RTC)
+       I2C_SET_BUS(old_bus);
+#endif
+
+       return rcode ? CMD_RET_FAILURE : 0;
+}
+
+/*
+ * simple conversion of two-digit string with error checking
+ */
+static int cnvrt2 (const char *str, int *valp)
+{
+       int val;
+
+       if ((*str < '0') || (*str > '9'))
+               return (-1);
+
+       val = *str - '0';
+
+       ++str;
+
+       if ((*str < '0') || (*str > '9'))
+               return (-1);
+
+       *valp = 10 * val + (*str - '0');
+
+       return (0);
+}
+
+/*
+ * Convert date string: MMDDhhmm[[CC]YY][.ss]
+ *
+ * Some basic checking for valid values is done, but this will not catch
+ * all possible error conditions.
+ */
+int mk_date (const char *datestr, struct rtc_time *tmp)
+{
+       int len, val;
+       char *ptr;
+
+       ptr = strchr (datestr,'.');
+       len = strlen (datestr);
+
+       /* Set seconds */
+       if (ptr) {
+               int sec;
+
+               *ptr++ = '\0';
+               if ((len - (ptr - datestr)) != 2)
+                       return (-1);
+
+               len = strlen (datestr);
+
+               if (cnvrt2 (ptr, &sec))
+                       return (-1);
+
+               tmp->tm_sec = sec;
+       } else {
+               tmp->tm_sec = 0;
+       }
+
+       if (len == 12) {                /* MMDDhhmmCCYY */
+               int year, century;
+
+               if (cnvrt2 (datestr+ 8, &century) ||
+                   cnvrt2 (datestr+10, &year) ) {
+                       return (-1);
+               }
+               tmp->tm_year = 100 * century + year;
+       } else if (len == 10) {         /* MMDDhhmmYY   */
+               int year, century;
+
+               century = tmp->tm_year / 100;
+               if (cnvrt2 (datestr+ 8, &year))
+                       return (-1);
+               tmp->tm_year = 100 * century + year;
+       }
+
+       switch (len) {
+       case 8:                 /* MMDDhhmm     */
+               /* fall thru */
+       case 10:                /* MMDDhhmmYY   */
+               /* fall thru */
+       case 12:                /* MMDDhhmmCCYY */
+               if (cnvrt2 (datestr+0, &val) ||
+                   val > 12) {
+                       break;
+               }
+               tmp->tm_mon  = val;
+               if (cnvrt2 (datestr+2, &val) ||
+                   val > ((tmp->tm_mon==2) ? 29 : 31)) {
+                       break;
+               }
+               tmp->tm_mday = val;
+
+               if (cnvrt2 (datestr+4, &val) ||
+                   val > 23) {
+                       break;
+               }
+               tmp->tm_hour = val;
+
+               if (cnvrt2 (datestr+6, &val) ||
+                   val > 59) {
+                       break;
+               }
+               tmp->tm_min  = val;
+
+               /* calculate day of week */
+               rtc_calc_weekday(tmp);
+
+               return (0);
+       default:
+               break;
+       }
+
+       return (-1);
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       date,   2,      1,      do_date,
+       "get/set/reset date & time",
+       "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n"
+       "  - without arguments: print date & time\n"
+       "  - with numeric argument: set the system date & time\n"
+       "  - with 'reset' argument: reset the RTC"
+);
diff --git a/cmd/dcr.c b/cmd/dcr.c
new file mode 100644 (file)
index 0000000..cc77250
--- /dev/null
+++ b/cmd/dcr.c
@@ -0,0 +1,222 @@
+/*
+ * (C) Copyright 2001
+ * Erik Theisen,  Wave 7 Optics, etheisen@mindspring.com.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * AMCC 4XX DCR Functions
+ */
+
+#include <common.h>
+#include <cli.h>
+#include <config.h>
+#include <command.h>
+#include <console.h>
+
+unsigned long get_dcr (unsigned short);
+unsigned long set_dcr (unsigned short, unsigned long);
+
+/* =======================================================================
+ * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
+ * =======================================================================
+ */
+int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
+{
+       unsigned short dcrn;    /* Device Control Register Num */
+       unsigned long value;    /* DCR's value */
+
+       unsigned long get_dcr (unsigned short);
+
+       /* Validate arguments */
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* Get a DCR */
+       dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
+       value = get_dcr (dcrn);
+
+       printf ("%04x: %08lx\n", dcrn, value);
+
+       return 0;
+}
+
+
+/* ======================================================================
+ * Interpreter command to set an AMCC PPC 4xx Device Control Register
+ * ======================================================================
+*/
+int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned short dcrn;    /* Device Control Register Num */
+       unsigned long value;
+
+       /* DCR's value */
+       int nbytes;
+
+       /* Validate arguments */
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* Set a DCR */
+       dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
+       do {
+               value = get_dcr (dcrn);
+               printf ("%04x: %08lx", dcrn, value);
+               nbytes = cli_readline(" ? ");
+               if (nbytes == 0) {
+                       /*
+                        * <CR> pressed as only input, don't modify current
+                        * location and exit command.
+                        */
+                       nbytes = 1;
+                       return 0;
+               } else {
+                       unsigned long i;
+                       char *endp;
+
+                       i = simple_strtoul (console_buffer, &endp, 16);
+                       nbytes = endp - console_buffer;
+                       if (nbytes)
+                               set_dcr (dcrn, i);
+               }
+       } while (nbytes);
+
+       return 0;
+}
+
+/* =======================================================================
+ * Interpreter command to retrieve an register value through AMCC PPC 4xx
+ * Device Control Register inderect addressing.
+ * =======================================================================
+ */
+int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned short adr_dcrn;        /* Device Control Register Num for Address */
+       unsigned short dat_dcrn;        /* Device Control Register Num for Data */
+       unsigned short offset;          /* Register's offset */
+       unsigned long value;            /* Register's value */
+       char *ptr = NULL;
+       char buf[80];
+
+       /* Validate arguments */
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       /* Find out whether ther is '.' (dot) symbol in the first parameter. */
+       strncpy (buf, argv[1], sizeof(buf)-1);
+       buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
+       ptr = strchr (buf, '.');
+
+       if (ptr != NULL) {
+               /* First parameter has format adr_dcrn.dat_dcrn */
+               *ptr++ = 0; /* erase '.', create zero-end string */
+               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+               dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
+       } else {
+               /*
+                * First parameter has format adr_dcrn; dat_dcrn will be
+                * calculated as adr_dcrn+1.
+                */
+               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+               dat_dcrn = adr_dcrn+1;
+       }
+
+       /* Register's offset */
+       offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
+
+       /* Disable interrupts */
+       disable_interrupts ();
+       /* Set offset */
+       set_dcr (adr_dcrn, offset);
+       /* get data */
+       value = get_dcr (dat_dcrn);
+       /* Enable interrupts */
+       enable_interrupts ();
+
+       printf ("%04x.%04x-%04x Read  %08lx\n", adr_dcrn, dat_dcrn, offset, value);
+
+       return 0;
+}
+
+/* =======================================================================
+ * Interpreter command to update an register value through AMCC PPC 4xx
+ * Device Control Register inderect addressing.
+ * =======================================================================
+ */
+int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned short adr_dcrn;        /* Device Control Register Num for Address */
+       unsigned short dat_dcrn;        /* Device Control Register Num for Data */
+       unsigned short offset;          /* Register's offset */
+       unsigned long value;            /* Register's value */
+       char *ptr = NULL;
+       char buf[80];
+
+       /* Validate arguments */
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       /* Find out whether ther is '.' (dot) symbol in the first parameter. */
+       strncpy (buf, argv[1], sizeof(buf)-1);
+       buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
+       ptr = strchr (buf, '.');
+
+       if (ptr != NULL) {
+               /* First parameter has format adr_dcrn.dat_dcrn */
+               *ptr++ = 0;     /* erase '.', create zero-end string */
+               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+               dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
+       } else {
+               /*
+                * First parameter has format adr_dcrn; dat_dcrn will be
+                * calculated as adr_dcrn+1.
+                */
+               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+               dat_dcrn = adr_dcrn+1;
+       }
+
+       /* Register's offset */
+       offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
+       /* New value */
+       value  = (unsigned  long) simple_strtoul (argv[3], NULL, 16);
+
+       /* Disable interrupts */
+       disable_interrupts ();
+       /* Set offset */
+       set_dcr (adr_dcrn, offset);
+       /* set data */
+       set_dcr (dat_dcrn, value);
+       /* Enable interrupts */
+       enable_interrupts ();
+
+       printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
+
+       return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       getdcr, 2,      1,      do_getdcr,
+       "Get an AMCC PPC 4xx DCR's value",
+       "dcrn - return a DCR's value."
+);
+U_BOOT_CMD(
+       setdcr, 2,      1,      do_setdcr,
+       "Set an AMCC PPC 4xx DCR's value",
+       "dcrn - set a DCR's value."
+);
+
+U_BOOT_CMD(
+       getidcr,        3,      1,      do_getidcr,
+       "Get a register value via indirect DCR addressing",
+       "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
+);
+
+U_BOOT_CMD(
+       setidcr,        4,      1,      do_setidcr,
+       "Set a register value via indirect DCR addressing",
+       "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
+);
diff --git a/cmd/demo.c b/cmd/demo.c
new file mode 100644 (file)
index 0000000..209dc4a
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm-demo.h>
+#include <mapmem.h>
+#include <asm/io.h>
+
+struct udevice *demo_dev;
+
+static int do_demo_hello(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char * const argv[])
+{
+       int ch = 0;
+
+       if (argc)
+               ch = *argv[0];
+
+       return demo_hello(demo_dev, ch);
+}
+
+static int do_demo_status(cmd_tbl_t *cmdtp, int flag, int argc,
+                         char * const argv[])
+{
+       int status;
+       int ret;
+
+       ret = demo_status(demo_dev, &status);
+       if (ret)
+               return ret;
+
+       printf("Status: %d\n", status);
+
+       return 0;
+}
+
+static int do_demo_light(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char * const argv[])
+{
+       int light;
+       int ret;
+
+       if (argc) {
+               light = simple_strtoul(argv[0], NULL, 16);
+               ret = demo_set_light(demo_dev, light);
+       } else {
+               ret = demo_get_light(demo_dev);
+               if (ret >= 0) {
+                       printf("Light: %x\n", ret);
+                       ret = 0;
+               }
+       }
+
+       return ret;
+}
+
+int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       int i, ret;
+
+       puts("Demo uclass entries:\n");
+
+       for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
+            dev;
+            ret = uclass_next_device(&dev)) {
+               printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
+                      i++, map_to_sysmem(dev),
+                      map_to_sysmem(dev->driver->ops),
+                      map_to_sysmem(dev_get_platdata(dev)));
+       }
+
+       return cmd_process_error(cmdtp, ret);
+}
+
+static cmd_tbl_t demo_commands[] = {
+       U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
+       U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
+       U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
+       U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
+};
+
+static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *demo_cmd;
+       int devnum = 0;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+       demo_cmd = find_cmd_tbl(argv[1], demo_commands,
+                               ARRAY_SIZE(demo_commands));
+       argc -= 2;
+       argv += 2;
+
+       if ((!demo_cmd || argc > demo_cmd->maxargs) ||
+           ((demo_cmd->name[0] != 'l') && (argc < 1)))
+               return CMD_RET_USAGE;
+
+       if (argc) {
+               devnum = simple_strtoul(argv[0], NULL, 10);
+               ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
+               if (ret)
+                       return cmd_process_error(cmdtp, ret);
+               argc--;
+               argv++;
+       } else {
+               demo_dev = NULL;
+               if (demo_cmd->cmd != do_demo_list)
+                       return CMD_RET_USAGE;
+       }
+
+       ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
+
+       return cmd_process_error(demo_cmd, ret);
+}
+
+U_BOOT_CMD(
+       demo,   4,      1,      do_demo,
+       "Driver model (dm) demo operations",
+       "list                     List available demo devices\n"
+       "demo hello <num> [<char>]     Say hello\n"
+       "demo light [<num>]            Set or get the lights\n"
+       "demo status <num>             Get demo device status\n"
+       "demo list                     List available demo devices"
+);
diff --git a/cmd/dfu.c b/cmd/dfu.c
new file mode 100644 (file)
index 0000000..6d95ce9
--- /dev/null
+++ b/cmd/dfu.c
@@ -0,0 +1,113 @@
+/*
+ * cmd_dfu.c -- dfu command
+ *
+ * Copyright (C) 2015
+ * Lukasz Majewski <l.majewski@majess.pl>
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
+ *         Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <dfu.h>
+#include <console.h>
+#include <g_dnl.h>
+#include <usb.h>
+#include <net.h>
+
+static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       bool dfu_reset = false;
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       char *usb_controller = argv[1];
+       char *interface = argv[2];
+       char *devstring = argv[3];
+
+       int ret, i = 0;
+#ifdef CONFIG_DFU_TFTP
+       unsigned long addr = 0;
+       if (!strcmp(argv[1], "tftp")) {
+               if (argc == 5)
+                       addr = simple_strtoul(argv[4], NULL, 0);
+
+               return update_tftp(addr, interface, devstring);
+       }
+#endif
+
+       ret = dfu_init_env_entities(interface, devstring);
+       if (ret)
+               goto done;
+
+       ret = CMD_RET_SUCCESS;
+       if (argc > 4 && strcmp(argv[4], "list") == 0) {
+               dfu_show_entities();
+               goto done;
+       }
+
+       int controller_index = simple_strtoul(usb_controller, NULL, 0);
+       board_usb_init(controller_index, USB_INIT_DEVICE);
+       g_dnl_clear_detach();
+       g_dnl_register("usb_dnl_dfu");
+       while (1) {
+               if (g_dnl_detach()) {
+                       /*
+                        * Check if USB bus reset is performed after detach,
+                        * which indicates that -R switch has been passed to
+                        * dfu-util. In this case reboot the device
+                        */
+                       if (dfu_usb_get_reset()) {
+                               dfu_reset = true;
+                               goto exit;
+                       }
+
+                       /*
+                        * This extra number of usb_gadget_handle_interrupts()
+                        * calls is necessary to assure correct transmission
+                        * completion with dfu-util
+                        */
+                       if (++i == 10000)
+                               goto exit;
+               }
+
+               if (ctrlc())
+                       goto exit;
+
+               WATCHDOG_RESET();
+               usb_gadget_handle_interrupts(controller_index);
+       }
+exit:
+       g_dnl_unregister();
+       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+done:
+       dfu_free_entities();
+
+       if (dfu_reset)
+               run_command("reset", 0);
+
+       g_dnl_clear_detach();
+
+       return ret;
+}
+
+U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
+       "Device Firmware Upgrade",
+       "<USB_controller> <interface> <dev> [list]\n"
+       "  - device firmware upgrade via <USB_controller>\n"
+       "    on device <dev>, attached to interface\n"
+       "    <interface>\n"
+       "    [list] - list available alt settings\n"
+#ifdef CONFIG_DFU_TFTP
+       "dfu tftp <interface> <dev> [<addr>]\n"
+       "  - device firmware upgrade via TFTP\n"
+       "    on device <dev>, attached to interface\n"
+       "    <interface>\n"
+       "    [<addr>] - address where FIT image has been stored\n"
+#endif
+);
diff --git a/cmd/diag.c b/cmd/diag.c
new file mode 100644 (file)
index 0000000..14ae04f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Diagnostics support
+ */
+#include <common.h>
+#include <command.h>
+#include <post.h>
+
+int do_diag (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int i;
+
+       if (argc == 1 || strcmp (argv[1], "run") != 0) {
+               /* List test info */
+               if (argc == 1) {
+                       puts ("Available hardware tests:\n");
+                       post_info (NULL);
+                       puts ("Use 'diag [<test1> [<test2> ...]]'"
+                                       " to get more info.\n");
+                       puts ("Use 'diag run [<test1> [<test2> ...]]'"
+                                       " to run tests.\n");
+               } else {
+                       for (i = 1; i < argc; i++) {
+                           if (post_info (argv[i]) != 0)
+                               printf ("%s - no such test\n", argv[i]);
+                       }
+               }
+       } else {
+               /* Run tests */
+               if (argc == 2) {
+                       post_run (NULL, POST_RAM | POST_MANUAL);
+               } else {
+                       for (i = 2; i < argc; i++) {
+                           if (post_run (argv[i], POST_RAM | POST_MANUAL) != 0)
+                               printf ("%s - unable to execute the test\n",
+                                       argv[i]);
+                       }
+               }
+       }
+
+       return 0;
+}
+/***************************************************/
+
+U_BOOT_CMD(
+       diag,   CONFIG_SYS_MAXARGS,     0,      do_diag,
+       "perform board diagnostics",
+            "    - print list of available tests\n"
+       "diag [test1 [test2]]\n"
+       "         - print information about specified tests\n"
+       "diag run - run all available tests\n"
+       "diag run [test1 [test2]]\n"
+       "         - run specified tests"
+);
diff --git a/cmd/disk.c b/cmd/disk.c
new file mode 100644 (file)
index 0000000..3025225
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * (C) Copyright 2000-2011
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <command.h>
+#include <part.h>
+
+#if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
+       defined(CONFIG_USB_STORAGE)
+int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
+                   char *const argv[])
+{
+       int dev, part;
+       ulong addr = CONFIG_SYS_LOAD_ADDR;
+       ulong cnt;
+       disk_partition_t info;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       image_header_t *hdr;
+#endif
+       block_dev_desc_t *dev_desc;
+
+#if defined(CONFIG_FIT)
+       const void *fit_hdr = NULL;
+#endif
+
+       bootstage_mark(BOOTSTAGE_ID_IDE_START);
+       if (argc > 3) {
+               bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
+               return CMD_RET_USAGE;
+       }
+       bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
+
+       if (argc > 1)
+               addr = simple_strtoul(argv[1], NULL, 16);
+
+       bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
+
+       part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
+                                       &dev_desc, &info, 1);
+       if (part < 0) {
+               bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
+               return 1;
+       }
+
+       dev = dev_desc->dev;
+       bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
+
+       printf("\nLoading from %s device %d, partition %d: "
+              "Name: %.32s  Type: %.32s\n", intf, dev, part, info.name,
+              info.type);
+
+       debug("First Block: " LBAFU ",  # of blocks: " LBAFU
+             ", Block Size: %ld\n",
+             info.start, info.size, info.blksz);
+
+       if (dev_desc->block_read(dev_desc, info.start, 1, (ulong *)addr) != 1) {
+               printf("** Read error on %d:%d\n", dev, part);
+               bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
+
+       switch (genimg_get_format((void *) addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+               hdr = (image_header_t *) addr;
+
+               bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
+
+               if (!image_check_hcrc(hdr)) {
+                       puts("\n** Bad Header Checksum **\n");
+                       bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
+                       return 1;
+               }
+               bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
+
+               image_print_contents(hdr);
+
+               cnt = image_get_image_size(hdr);
+               break;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               fit_hdr = (const void *) addr;
+               puts("Fit image detected...\n");
+
+               cnt = fit_get_size(fit_hdr);
+               break;
+#endif
+       default:
+               bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
+               puts("** Unknown image type\n");
+               return 1;
+       }
+
+       cnt += info.blksz - 1;
+       cnt /= info.blksz;
+       cnt -= 1;
+
+       if (dev_desc->block_read(dev_desc, info.start + 1, cnt,
+                                (ulong *)(addr + info.blksz)) != cnt) {
+               printf("** Read error on %d:%d\n", dev, part);
+               bootstage_error(BOOTSTAGE_ID_IDE_READ);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_IDE_READ);
+
+#if defined(CONFIG_FIT)
+       /* This cannot be done earlier,
+        * we need complete FIT image in RAM first */
+       if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
+               if (!fit_check_format(fit_hdr)) {
+                       bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
+                       puts("** Bad FIT image format\n");
+                       return 1;
+               }
+               bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
+               fit_print_contents(fit_hdr);
+       }
+#endif
+
+       flush_cache(addr, (cnt+1)*info.blksz);
+
+       /* Loading ok, update default load address */
+       load_addr = addr;
+
+       return bootm_maybe_autostart(cmdtp, argv[0]);
+}
+#endif
diff --git a/cmd/display.c b/cmd/display.c
new file mode 100644 (file)
index 0000000..bc1b1eb
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * (C) Copyright 2005
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <led-display.h>
+
+#undef DEBUG_DISP
+
+int do_display (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+
+       /* Clear display */
+       display_set(DISPLAY_CLEAR | DISPLAY_HOME);
+
+       if (argc < 2)
+               return (0);
+
+       for (i = 1; i < argc; i++) {
+               char *p = argv[i];
+
+               if (i > 1) { /* Insert a space between strings */
+                       display_putc(' ');
+               }
+
+               while ((*p)) {
+#ifdef DEBUG_DISP
+                       putc(*p);
+#endif
+                       display_putc(*p++);
+               }
+       }
+
+#ifdef DEBUG_DISP
+       putc('\n');
+#endif
+
+       return (0);
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       display,        CONFIG_SYS_MAXARGS,     1,      do_display,
+       "display string on dot matrix display",
+       "[<string>]\n"
+       "    - with <string> argument: display <string> on dot matrix display\n"
+       "    - without arguments: clear dot matrix display"
+);
diff --git a/cmd/dtt.c b/cmd/dtt.c
new file mode 100644 (file)
index 0000000..dd427a3
--- /dev/null
+++ b/cmd/dtt.c
@@ -0,0 +1,120 @@
+/*
+ * (C) Copyright 2001
+ * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+
+#include <dtt.h>
+#include <i2c.h>
+#include <tmu.h>
+#include <linux/bug.h>
+
+#if defined CONFIG_DTT_SENSORS
+static unsigned long sensor_initialized;
+
+static void _initialize_dtt(void)
+{
+       int i;
+       unsigned char sensors[] = CONFIG_DTT_SENSORS;
+
+       for (i = 0; i < sizeof(sensors); i++) {
+               if ((sensor_initialized & (1 << i)) == 0) {
+                       if (dtt_init_one(sensors[i]) != 0) {
+                               printf("DTT%d: Failed init!\n", i);
+                               continue;
+                       }
+                       sensor_initialized |= (1 << i);
+               }
+       }
+}
+
+void dtt_init(void)
+{
+       int old_bus;
+
+       /* switch to correct I2C bus */
+       old_bus = I2C_GET_BUS();
+       I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
+
+       _initialize_dtt();
+
+       /* switch back to original I2C bus */
+       I2C_SET_BUS(old_bus);
+}
+#endif
+
+int dtt_i2c(void)
+{
+#if defined CONFIG_DTT_SENSORS
+       int i;
+       unsigned char sensors[] = CONFIG_DTT_SENSORS;
+       int old_bus;
+
+       /* Force a compilation error, if there are more then 32 sensors */
+       BUILD_BUG_ON(sizeof(sensors) > 32);
+       /* switch to correct I2C bus */
+#ifdef CONFIG_SYS_I2C
+       old_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
+#else
+       old_bus = I2C_GET_BUS();
+       I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
+#endif
+
+       _initialize_dtt();
+
+       /*
+        * Loop through sensors, read
+        * temperature, and output it.
+        */
+       for (i = 0; i < sizeof(sensors); i++)
+               printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
+
+       /* switch back to original I2C bus */
+#ifdef CONFIG_SYS_I2C
+       i2c_set_bus_num(old_bus);
+#else
+       I2C_SET_BUS(old_bus);
+#endif
+#endif
+
+       return 0;
+}
+
+int dtt_tmu(void)
+{
+#if defined CONFIG_TMU_CMD_DTT
+       int cur_temp;
+
+       /* Sense and return latest thermal info */
+       if (tmu_monitor(&cur_temp) == TMU_STATUS_INIT) {
+               puts("TMU is in unknown state, temperature is invalid\n");
+               return -1;
+       }
+       printf("Current temperature: %u degrees Celsius\n", cur_temp);
+#endif
+       return 0;
+}
+
+int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int err = 0;
+
+       err |= dtt_i2c();
+       err |= dtt_tmu();
+
+       return err;
+}      /* do_dtt() */
+
+/***************************************************/
+
+U_BOOT_CMD(
+         dtt,  1,      1,      do_dtt,
+         "Read temperature from Digital Thermometer and Thermostat",
+         ""
+);
diff --git a/cmd/echo.c b/cmd/echo.c
new file mode 100644 (file)
index 0000000..3dc3a63
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       int putnl = 1;
+
+       for (i = 1; i < argc; i++) {
+               char *p = argv[i];
+               char *nls; /* new-line suppression */
+
+               if (i > 1)
+                       putc(' ');
+
+               nls = strstr(p, "\\c");
+               if (nls) {
+                       char *prenls = p;
+
+                       putnl = 0;
+                       /*
+                        * be paranoid and guess that someone might
+                        * say \c more than once
+                        */
+                       while (nls) {
+                               *nls = '\0';
+                               puts(prenls);
+                               *nls = '\\';
+                               prenls = nls + 2;
+                               nls = strstr(prenls, "\\c");
+                       }
+                       puts(prenls);
+               } else {
+                       puts(p);
+               }
+       }
+
+       if (putnl)
+               putc('\n');
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
+       "echo args to console",
+       "[args..]\n"
+       "    - echo args to console; \\c suppresses newline"
+);
diff --git a/cmd/eeprom.c b/cmd/eeprom.c
new file mode 100644 (file)
index 0000000..571240a
--- /dev/null
@@ -0,0 +1,265 @@
+/*
+ * (C) Copyright 2000, 2001
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Support for read and write access to EEPROM like memory devices. This
+ * includes regular EEPROM as well as  FRAM (ferroelectic nonvolaile RAM).
+ * FRAM devices read and write data at bus speed. In particular, there is no
+ * write delay. Also, there is no limit imposed on the number of bytes that can
+ * be transferred with a single read or write.
+ *
+ * Use the following configuration options to ensure no unneeded performance
+ * degradation (typical for EEPROM) is incured for FRAM memory:
+ *
+ * #define CONFIG_SYS_I2C_FRAM
+ * #undef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+ *
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <i2c.h>
+
+#ifndef        CONFIG_SYS_I2C_SPEED
+#define        CONFIG_SYS_I2C_SPEED    50000
+#endif
+
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS  0
+#endif
+
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS      8
+#endif
+
+#define        EEPROM_PAGE_SIZE        (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
+#define        EEPROM_PAGE_OFFSET(x)   ((x) & (EEPROM_PAGE_SIZE - 1))
+
+/*
+ * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
+ *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
+ *
+ * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
+ *   0x00000nxx for EEPROM address selectors and page number at n.
+ */
+#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
+       (CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
+       (CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
+#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
+#endif
+#endif
+
+__weak int eeprom_write_enable(unsigned dev_addr, int state)
+{
+       return 0;
+}
+
+void eeprom_init(int bus)
+{
+       /* SPI EEPROM */
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+       spi_init_f();
+#endif
+
+       /* I2C EEPROM */
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+#if defined(CONFIG_SYS_I2C)
+       if (bus >= 0)
+               i2c_set_bus_num(bus);
+#endif
+       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
+}
+
+static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
+{
+       unsigned blk_off;
+       int alen;
+
+       blk_off = offset & 0xff;        /* block offset */
+#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
+       addr[0] = offset >> 8;          /* block number */
+       addr[1] = blk_off;              /* block offset */
+       alen = 2;
+#else
+       addr[0] = offset >> 16;         /* block number */
+       addr[1] = offset >>  8;         /* upper address octet */
+       addr[2] = blk_off;              /* lower address octet */
+       alen = 3;
+#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
+
+       addr[0] |= dev_addr;            /* insert device address */
+
+       return alen;
+}
+
+static int eeprom_len(unsigned offset, unsigned end)
+{
+       unsigned len = end - offset;
+
+       /*
+        * For a FRAM device there is no limit on the number of the
+        * bytes that can be ccessed with the single read or write
+        * operation.
+        */
+#if !defined(CONFIG_SYS_I2C_FRAM)
+       unsigned blk_off = offset & 0xff;
+       unsigned maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
+
+       if (maxlen > I2C_RXTX_LEN)
+               maxlen = I2C_RXTX_LEN;
+
+       if (len > maxlen)
+               len = maxlen;
+#endif
+
+       return len;
+}
+
+static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
+                          uchar *buffer, unsigned len, bool read)
+{
+       int ret = 0;
+
+       /* SPI */
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+       if (read)
+               spi_read(addr, alen, buffer, len);
+       else
+               spi_write(addr, alen, buffer, len);
+#else  /* I2C */
+
+#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
+       i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
+#endif
+
+       if (read)
+               ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
+       else
+               ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
+
+       if (ret)
+               ret = 1;
+#endif
+       return ret;
+}
+
+static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
+                    unsigned cnt, bool read)
+{
+       unsigned end = offset + cnt;
+       unsigned alen, len;
+       int rcode = 0;
+       uchar addr[3];
+
+       while (offset < end) {
+               alen = eeprom_addr(dev_addr, offset, addr);
+
+               len = eeprom_len(offset, end);
+
+               rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
+
+               buffer += len;
+               offset += len;
+
+               if (!read)
+                       udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
+       }
+
+       return rcode;
+}
+
+int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+{
+       /*
+        * Read data until done or would cross a page boundary.
+        * We must write the address again when changing pages
+        * because the next page may be in a different device.
+        */
+       return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
+}
+
+int eeprom_write(unsigned dev_addr, unsigned offset,
+                uchar *buffer, unsigned cnt)
+{
+       int ret;
+
+       eeprom_write_enable(dev_addr, 1);
+
+       /*
+        * Write data until done or would cross a write page boundary.
+        * We must write the address again when changing pages
+        * because the address counter only increments within a page.
+        */
+       ret = eeprom_rw(dev_addr, offset, buffer, cnt, 0);
+
+       eeprom_write_enable(dev_addr, 0);
+       return ret;
+}
+
+static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *const fmt =
+               "\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
+       char * const *args = &argv[2];
+       int rcode;
+       ulong dev_addr, addr, off, cnt;
+       int bus_addr;
+
+       switch (argc) {
+#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
+       case 5:
+               bus_addr = -1;
+               dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
+               break;
+#endif
+       case 6:
+               bus_addr = -1;
+               dev_addr = simple_strtoul(*args++, NULL, 16);
+               break;
+       case 7:
+               bus_addr = simple_strtoul(*args++, NULL, 16);
+               dev_addr = simple_strtoul(*args++, NULL, 16);
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       addr = simple_strtoul(*args++, NULL, 16);
+       off = simple_strtoul(*args++, NULL, 16);
+       cnt = simple_strtoul(*args++, NULL, 16);
+
+       eeprom_init(bus_addr);
+
+       if (strcmp(argv[1], "read") == 0) {
+               printf(fmt, dev_addr, argv[1], addr, off, cnt);
+
+               rcode = eeprom_read(dev_addr, off, (uchar *)addr, cnt);
+
+               puts("done\n");
+               return rcode;
+       } else if (strcmp(argv[1], "write") == 0) {
+               printf(fmt, dev_addr, argv[1], addr, off, cnt);
+
+               rcode = eeprom_write(dev_addr, off, (uchar *)addr, cnt);
+
+               puts("done\n");
+               return rcode;
+       }
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       eeprom, 7,      1,      do_eeprom,
+       "EEPROM sub-system",
+       "read  <bus> <devaddr> addr off cnt\n"
+       "eeprom write <bus> <devaddr> addr off cnt\n"
+       "       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
+)
diff --git a/cmd/efi.c b/cmd/efi.c
new file mode 100644 (file)
index 0000000..c76296e
--- /dev/null
+++ b/cmd/efi.c
@@ -0,0 +1,257 @@
+/*
+ * (C) Copyright 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <efi.h>
+#include <errno.h>
+#include <malloc.h>
+
+static const char *const type_name[] = {
+       "reserved",
+       "loader_code",
+       "loader_data",
+       "bs_code",
+       "bs_data",
+       "rt_code",
+       "rt_data",
+       "conv",
+       "unusable",
+       "acpi_reclaim",
+       "acpi_nvs",
+       "io",
+       "io_port",
+       "pal_code",
+};
+
+static struct attr_info {
+       int shift;
+       const char *name;
+} mem_attr[] = {
+       { EFI_MEMORY_UC_SHIFT, "uncached" },
+       { EFI_MEMORY_WC_SHIFT, "write-coalescing" },
+       { EFI_MEMORY_WT_SHIFT, "write-through" },
+       { EFI_MEMORY_WB_SHIFT, "write-back" },
+       { EFI_MEMORY_UCE_SHIFT, "uncached & exported" },
+       { EFI_MEMORY_WP_SHIFT, "write-protect" },
+       { EFI_MEMORY_RP_SHIFT, "read-protect" },
+       { EFI_MEMORY_XP_SHIFT, "execute-protect" },
+       { EFI_MEMORY_RUNTIME_SHIFT, "needs runtime mapping" }
+};
+
+/* Maximum different attribute values we can track */
+#define ATTR_SEEN_MAX  30
+
+static inline bool is_boot_services(int type)
+{
+       return type == EFI_LOADER_CODE || type == EFI_LOADER_DATA ||
+               type == EFI_BOOT_SERVICES_CODE ||
+               type == EFI_BOOT_SERVICES_DATA;
+}
+
+static int h_cmp_entry(const void *v1, const void *v2)
+{
+       const struct efi_mem_desc *desc1 = v1;
+       const struct efi_mem_desc *desc2 = v2;
+       int64_t diff = desc1->physical_start - desc2->physical_start;
+
+       /*
+        * Manually calculate the difference to avoid sign loss in the 64-bit
+        * to 32-bit conversion
+        */
+       return diff < 0 ? -1 : diff > 0 ? 1 : 0;
+}
+
+void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs)
+{
+       struct efi_mem_desc *desc, *end, *base, *dest, *prev;
+       int count;
+       u64 addr;
+
+       base = malloc(size + sizeof(*desc));
+       if (!base) {
+               debug("%s: Cannot allocate %#x bytes\n", __func__, size);
+               return NULL;
+       }
+       end = (struct efi_mem_desc *)((ulong)map + size);
+       count = ((ulong)end - (ulong)map->desc) / map->desc_size;
+       memcpy(base, map->desc, (ulong)end - (ulong)map->desc);
+       qsort(base, count, map->desc_size, h_cmp_entry);
+       prev = NULL;
+       addr = 0;
+       dest = base;
+       end = base + count;
+       for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+               bool merge = true;
+               int type = desc->type;
+
+               if (skip_bs && is_boot_services(desc->type))
+                       type = EFI_CONVENTIONAL_MEMORY;
+
+               memcpy(dest, desc, map->desc_size);
+               dest->type = type;
+               if (!skip_bs || !prev)
+                       merge = false;
+               else if (desc->physical_start != addr)
+                       merge = false;
+               else if (type != EFI_CONVENTIONAL_MEMORY)
+                       merge = false;
+               else if (prev->type != EFI_CONVENTIONAL_MEMORY)
+                       merge = false;
+
+               if (merge) {
+                       prev->num_pages += desc->num_pages;
+               } else {
+                       prev = dest;
+                       dest = efi_get_next_mem_desc(map, dest);
+               }
+               addr = desc->physical_start + (desc->num_pages <<
+                               EFI_PAGE_SHIFT);
+       }
+
+       /* Mark the end */
+       dest->type = EFI_TABLE_END;
+
+       return base;
+}
+
+static void efi_print_mem_table(struct efi_entry_memmap *map,
+                               struct efi_mem_desc *desc, bool skip_bs)
+{
+       u64 attr_seen[ATTR_SEEN_MAX];
+       int attr_seen_count;
+       int upto, i;
+       u64 addr;
+
+       printf(" #  %-14s  %10s  %10s  %10s  %s\n", "Type", "Physical",
+              "Virtual", "Size", "Attributes");
+
+       /* Keep track of all the different attributes we have seen */
+       attr_seen_count = 0;
+       addr = 0;
+       for (upto = 0; desc->type != EFI_TABLE_END;
+            upto++, desc = efi_get_next_mem_desc(map, desc)) {
+               const char *name;
+               u64 size;
+
+               if (skip_bs && is_boot_services(desc->type))
+                       continue;
+               if (desc->physical_start != addr) {
+                       printf("    %-14s  %010llx  %10s  %010llx\n", "<gap>",
+                              addr, "", desc->physical_start - addr);
+               }
+               size = desc->num_pages << EFI_PAGE_SHIFT;
+
+               name = desc->type < ARRAY_SIZE(type_name) ?
+                               type_name[desc->type] : "<invalid>";
+               printf("%2d  %x:%-12s  %010llx  %010llx  %010llx  ", upto,
+                      desc->type, name, desc->physical_start,
+                      desc->virtual_start, size);
+               if (desc->attribute & EFI_MEMORY_RUNTIME)
+                       putc('r');
+               printf("%llx", desc->attribute & ~EFI_MEMORY_RUNTIME);
+               putc('\n');
+
+               for (i = 0; i < attr_seen_count; i++) {
+                       if (attr_seen[i] == desc->attribute)
+                               break;
+               }
+               if (i == attr_seen_count && i < ATTR_SEEN_MAX)
+                       attr_seen[attr_seen_count++] = desc->attribute;
+               addr = desc->physical_start + size;
+       }
+
+       printf("\nAttributes key:\n");
+       for (i = 0; i < attr_seen_count; i++) {
+               u64 attr = attr_seen[i];
+               bool first;
+               int j;
+
+               printf("%c%llx: ", attr & EFI_MEMORY_RUNTIME ? 'r' : ' ',
+                      attr & ~EFI_MEMORY_RUNTIME);
+               for (j = 0, first = true; j < ARRAY_SIZE(mem_attr); j++) {
+                       if (attr & (1ULL << mem_attr[j].shift)) {
+                               if (first)
+                                       first = false;
+                               else
+                                       printf(", ");
+                               printf("%s", mem_attr[j].name);
+                       }
+               }
+               putc('\n');
+       }
+       if (skip_bs)
+               printf("*Some areas are merged (use 'all' to see)\n");
+}
+
+static int do_efi_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct efi_mem_desc *desc;
+       struct efi_entry_memmap *map;
+       int size, ret;
+       bool skip_bs;
+
+       skip_bs = !argc || *argv[0] != 'a';
+       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+       switch (ret) {
+       case -ENOENT:
+               printf("No EFI table available\n");
+               goto done;
+       case -EPROTONOSUPPORT:
+               printf("Incorrect EFI table version\n");
+               goto done;
+       }
+       printf("EFI table at %lx, memory map %p, size %x, version %x, descr. size %#x\n",
+              gd->arch.table, map, size, map->version, map->desc_size);
+       if (map->version != EFI_MEM_DESC_VERSION) {
+               printf("Incorrect memory map version\n");
+               ret = -EPROTONOSUPPORT;
+               goto done;
+       }
+
+       desc = efi_build_mem_table(map, size, skip_bs);
+       if (!desc) {
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       efi_print_mem_table(map, desc, skip_bs);
+       free(desc);
+done:
+       if (ret)
+               printf("Error: %d\n", ret);
+
+       return ret ? CMD_RET_FAILURE : 0;
+}
+
+static cmd_tbl_t efi_commands[] = {
+       U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
+};
+
+static int do_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *efi_cmd;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+       efi_cmd = find_cmd_tbl(argv[1], efi_commands, ARRAY_SIZE(efi_commands));
+       argc -= 2;
+       argv += 2;
+       if (!efi_cmd || argc > efi_cmd->maxargs)
+               return CMD_RET_USAGE;
+
+       ret = efi_cmd->cmd(efi_cmd, flag, argc, argv);
+
+       return cmd_process_error(efi_cmd, ret);
+}
+
+U_BOOT_CMD(
+       efi,     3,      1,      do_efi,
+       "EFI access",
+       "mem [all]        Dump memory information [include boot services]"
+);
diff --git a/cmd/elf.c b/cmd/elf.c
new file mode 100644 (file)
index 0000000..5190cc6
--- /dev/null
+++ b/cmd/elf.c
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2001 William L. Pitts
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <elf.h>
+#include <net.h>
+#include <vxworks.h>
+#ifdef CONFIG_X86
+#include <asm/e820.h>
+#include <linux/linkage.h>
+#endif
+
+/*
+ * A very simple elf loader, assumes the image is valid, returns the
+ * entry point address.
+ */
+static unsigned long load_elf_image_phdr(unsigned long addr)
+{
+       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+       Elf32_Phdr *phdr; /* Program header structure pointer */
+       int i;
+
+       ehdr = (Elf32_Ehdr *)addr;
+       phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
+
+       /* Load each program header */
+       for (i = 0; i < ehdr->e_phnum; ++i) {
+               void *dst = (void *)(uintptr_t)phdr->p_paddr;
+               void *src = (void *)addr + phdr->p_offset;
+               debug("Loading phdr %i to 0x%p (%i bytes)\n",
+                     i, dst, phdr->p_filesz);
+               if (phdr->p_filesz)
+                       memcpy(dst, src, phdr->p_filesz);
+               if (phdr->p_filesz != phdr->p_memsz)
+                       memset(dst + phdr->p_filesz, 0x00,
+                              phdr->p_memsz - phdr->p_filesz);
+               flush_cache((unsigned long)dst, phdr->p_filesz);
+               ++phdr;
+       }
+
+       return ehdr->e_entry;
+}
+
+static unsigned long load_elf_image_shdr(unsigned long addr)
+{
+       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+       Elf32_Shdr *shdr; /* Section header structure pointer */
+       unsigned char *strtab = 0; /* String table pointer */
+       unsigned char *image; /* Binary image pointer */
+       int i; /* Loop counter */
+
+       ehdr = (Elf32_Ehdr *)addr;
+
+       /* Find the section header string table for output info */
+       shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
+                            (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
+
+       if (shdr->sh_type == SHT_STRTAB)
+               strtab = (unsigned char *)(addr + shdr->sh_offset);
+
+       /* Load each appropriate section */
+       for (i = 0; i < ehdr->e_shnum; ++i) {
+               shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
+                                    (i * sizeof(Elf32_Shdr)));
+
+               if (!(shdr->sh_flags & SHF_ALLOC) ||
+                   shdr->sh_addr == 0 || shdr->sh_size == 0) {
+                       continue;
+               }
+
+               if (strtab) {
+                       debug("%sing %s @ 0x%08lx (%ld bytes)\n",
+                             (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
+                              &strtab[shdr->sh_name],
+                              (unsigned long)shdr->sh_addr,
+                              (long)shdr->sh_size);
+               }
+
+               if (shdr->sh_type == SHT_NOBITS) {
+                       memset((void *)(uintptr_t)shdr->sh_addr, 0,
+                              shdr->sh_size);
+               } else {
+                       image = (unsigned char *)addr + shdr->sh_offset;
+                       memcpy((void *)(uintptr_t)shdr->sh_addr,
+                              (const void *)image, shdr->sh_size);
+               }
+               flush_cache(shdr->sh_addr, shdr->sh_size);
+       }
+
+       return ehdr->e_entry;
+}
+
+/* Allow ports to override the default behavior */
+static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
+                                    int argc, char * const argv[])
+{
+       unsigned long ret;
+
+       /*
+        * QNX images require the data cache is disabled.
+        * Data cache is already flushed, so just turn it off.
+        */
+       int dcache = dcache_status();
+       if (dcache)
+               dcache_disable();
+
+       /*
+        * pass address parameter as argv[0] (aka command name),
+        * and all remaining args
+        */
+       ret = entry(argc, argv);
+
+       if (dcache)
+               dcache_enable();
+
+       return ret;
+}
+
+/*
+ * Determine if a valid ELF image exists at the given memory location.
+ * First look at the ELF header magic field, then make sure that it is
+ * executable.
+ */
+int valid_elf_image(unsigned long addr)
+{
+       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+
+       ehdr = (Elf32_Ehdr *)addr;
+
+       if (!IS_ELF(*ehdr)) {
+               printf("## No elf image at address 0x%08lx\n", addr);
+               return 0;
+       }
+
+       if (ehdr->e_type != ET_EXEC) {
+               printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
+               return 0;
+       }
+
+       return 1;
+}
+
+/* Interpreter command to boot an arbitrary ELF image from memory */
+int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr; /* Address of the ELF image */
+       unsigned long rc; /* Return value from user code */
+       char *sload, *saddr;
+       const char *ep = getenv("autostart");
+
+       int rcode = 0;
+
+       sload = saddr = NULL;
+       if (argc == 3) {
+               sload = argv[1];
+               saddr = argv[2];
+       } else if (argc == 2) {
+               if (argv[1][0] == '-')
+                       sload = argv[1];
+               else
+                       saddr = argv[1];
+       }
+
+       if (saddr)
+               addr = simple_strtoul(saddr, NULL, 16);
+       else
+               addr = load_addr;
+
+       if (!valid_elf_image(addr))
+               return 1;
+
+       if (sload && sload[1] == 'p')
+               addr = load_elf_image_phdr(addr);
+       else
+               addr = load_elf_image_shdr(addr);
+
+       if (ep && !strcmp(ep, "no"))
+               return rcode;
+
+       printf("## Starting application at 0x%08lx ...\n", addr);
+
+       /*
+        * pass address parameter as argv[0] (aka command name),
+        * and all remaining args
+        */
+       rc = do_bootelf_exec((void *)addr, argc - 1, argv + 1);
+       if (rc != 0)
+               rcode = 1;
+
+       printf("## Application terminated, rc = 0x%lx\n", rc);
+
+       return rcode;
+}
+
+/*
+ * Interpreter command to boot VxWorks from a memory image.  The image can
+ * be either an ELF image or a raw binary.  Will attempt to setup the
+ * bootline and other parameters correctly.
+ */
+int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr; /* Address of image */
+       unsigned long bootaddr; /* Address to put the bootline */
+       char *bootline; /* Text of the bootline */
+       char *tmp; /* Temporary char pointer */
+       char build_buf[128]; /* Buffer for building the bootline */
+       int ptr = 0;
+#ifdef CONFIG_X86
+       struct e820info *info;
+       struct e820entry *data;
+#endif
+
+       /*
+        * Check the loadaddr variable.
+        * If we don't know where the image is then we're done.
+        */
+       if (argc < 2)
+               addr = load_addr;
+       else
+               addr = simple_strtoul(argv[1], NULL, 16);
+
+#if defined(CONFIG_CMD_NET)
+       /*
+        * Check to see if we need to tftp the image ourselves
+        * before starting
+        */
+       if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
+               if (net_loop(TFTPGET) <= 0)
+                       return 1;
+               printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
+                       addr);
+       }
+#endif
+
+       /*
+        * This should equate to
+        * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
+        * from the VxWorks BSP header files.
+        * This will vary from board to board
+        */
+#if defined(CONFIG_WALNUT)
+       tmp = (char *)CONFIG_SYS_NVRAM_BASE_ADDR + 0x500;
+       eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
+       memcpy(tmp, &build_buf[3], 3);
+#elif defined(CONFIG_SYS_VXWORKS_MAC_PTR)
+       tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
+       eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
+       memcpy(tmp, build_buf, 6);
+#else
+       puts("## Ethernet MAC address not copied to NV RAM\n");
+#endif
+
+       /*
+        * Use bootaddr to find the location in memory that VxWorks
+        * will look for the bootline string. The default value is
+        * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
+        * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
+        */
+       tmp = getenv("bootaddr");
+       if (!tmp) {
+               printf("## VxWorks bootline address not specified\n");
+       } else {
+               bootaddr = simple_strtoul(tmp, NULL, 16);
+
+               /*
+                * Check to see if the bootline is defined in the 'bootargs'
+                * parameter. If it is not defined, we may be able to
+                * construct the info.
+                */
+               bootline = getenv("bootargs");
+               if (bootline) {
+                       memcpy((void *)bootaddr, bootline,
+                              max(strlen(bootline), (size_t)255));
+                       flush_cache(bootaddr, max(strlen(bootline),
+                                                 (size_t)255));
+               } else {
+                       tmp = getenv("bootdev");
+                       if (tmp) {
+                               strcpy(build_buf, tmp);
+                               ptr = strlen(tmp);
+                       } else
+                               printf("## VxWorks boot device not specified\n");
+
+                       tmp = getenv("bootfile");
+                       if (tmp)
+                               ptr += sprintf(build_buf + ptr,
+                                              "host:%s ", tmp);
+                       else
+                               ptr += sprintf(build_buf + ptr,
+                                              "host:vxWorks ");
+
+                       /*
+                        * The following parameters are only needed if 'bootdev'
+                        * is an ethernet device, otherwise they are optional.
+                        */
+                       tmp = getenv("ipaddr");
+                       if (tmp) {
+                               ptr += sprintf(build_buf + ptr, "e=%s", tmp);
+                               tmp = getenv("netmask");
+                               if (tmp) {
+                                       u32 mask = getenv_ip("netmask").s_addr;
+                                       ptr += sprintf(build_buf + ptr,
+                                                      ":%08x ", ntohl(mask));
+                               } else {
+                                       ptr += sprintf(build_buf + ptr, " ");
+                               }
+                       }
+
+                       tmp = getenv("serverip");
+                       if (tmp)
+                               ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
+
+                       tmp = getenv("gatewayip");
+                       if (tmp)
+                               ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
+
+                       tmp = getenv("hostname");
+                       if (tmp)
+                               ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
+
+                       tmp = getenv("othbootargs");
+                       if (tmp) {
+                               strcpy(build_buf + ptr, tmp);
+                               ptr += strlen(tmp);
+                       }
+
+                       memcpy((void *)bootaddr, build_buf,
+                              max(strlen(build_buf), (size_t)255));
+                       flush_cache(bootaddr, max(strlen(build_buf),
+                                                 (size_t)255));
+               }
+
+               printf("## Using bootline (@ 0x%lx): %s\n", bootaddr,
+                      (char *)bootaddr);
+       }
+
+#ifdef CONFIG_X86
+       /*
+        * Since E820 information is critical to the kernel, if we don't
+        * specify these in the environments, use a default one.
+        */
+       tmp = getenv("e820data");
+       if (tmp)
+               data = (struct e820entry *)simple_strtoul(tmp, NULL, 16);
+       else
+               data = (struct e820entry *)VXWORKS_E820_DATA_ADDR;
+       tmp = getenv("e820info");
+       if (tmp)
+               info = (struct e820info *)simple_strtoul(tmp, NULL, 16);
+       else
+               info = (struct e820info *)VXWORKS_E820_INFO_ADDR;
+
+       memset(info, 0, sizeof(struct e820info));
+       info->sign = E820_SIGNATURE;
+       info->entries = install_e820_map(E820MAX, data);
+       info->addr = (info->entries - 1) * sizeof(struct e820entry) +
+                    VXWORKS_E820_DATA_ADDR;
+#endif
+
+       /*
+        * If the data at the load address is an elf image, then
+        * treat it like an elf image. Otherwise, assume that it is a
+        * binary image.
+        */
+       if (valid_elf_image(addr))
+               addr = load_elf_image_shdr(addr);
+       else
+               puts("## Not an ELF image, assuming binary\n");
+
+       printf("## Starting vxWorks at 0x%08lx ...\n", addr);
+
+       dcache_disable();
+#ifdef CONFIG_X86
+       /* VxWorks on x86 uses stack to pass parameters */
+       ((asmlinkage void (*)(int))addr)(0);
+#else
+       ((void (*)(int))addr)(0);
+#endif
+
+       puts("## vxWorks terminated\n");
+
+       return 1;
+}
+
+U_BOOT_CMD(
+       bootelf, 3, 0, do_bootelf,
+       "Boot from an ELF image in memory",
+       "[-p|-s] [address]\n"
+       "\t- load ELF image at [address] via program headers (-p)\n"
+       "\t  or via section headers (-s)"
+);
+
+U_BOOT_CMD(
+       bootvx, 2, 0, do_bootvx,
+       "Boot vxWorks from an ELF image",
+       " [address] - load address of vxWorks ELF image."
+);
diff --git a/cmd/ethsw.c b/cmd/ethsw.c
new file mode 100644 (file)
index 0000000..8e452e9
--- /dev/null
@@ -0,0 +1,1027 @@
+/*
+ * Copyright 2015 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:      GPL-2.0+
+ *
+ * Ethernet Switch commands
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <env_flags.h>
+#include <ethsw.h>
+
+static const char *ethsw_name;
+
+#define ETHSW_PORT_STATS_HELP "ethsw [port <port_no>] statistics " \
+"{ [help] | [clear] } - show an l2 switch port's statistics"
+
+static int ethsw_port_stats_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_PORT_STATS_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_LEARN_HELP "ethsw [port <port_no>] learning " \
+"{ [help] | show | auto | disable } " \
+"- enable/disable/show learning configuration on a port"
+
+static int ethsw_learn_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_LEARN_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
+"{ [help] | show | flush | { add | del } <mac> } " \
+"- Add/delete a mac entry in FDB; use show to see FDB entries; " \
+"if vlan <vid> is missing, VID 1 will be used"
+
+static int ethsw_fdb_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_FDB_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_PVID_HELP "ethsw [port <port_no>] " \
+"pvid { [help] | show | <pvid> } " \
+"- set/show PVID (ingress and egress VLAN tagging) for a port"
+
+static int ethsw_pvid_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_PVID_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_VLAN_HELP "ethsw [port <port_no>] vlan " \
+"{ [help] | show | add <vid> | del <vid> } " \
+"- add a VLAN to a port (VLAN members)"
+
+static int ethsw_vlan_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_VLAN_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
+"{ [help] | show | all | none | pvid } " \
+" - set egress tagging mod for a port"
+
+static int ethsw_port_untag_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_PORT_UNTAG_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
+"{ [help] | show | pvid | classified } " \
+"- Configure VID source for egress tag. " \
+"Tag's VID could be the frame's classified VID or the PVID of the port"
+
+static int ethsw_egr_tag_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_EGR_VLAN_TAG_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_VLAN_FDB_HELP "ethsw vlan fdb " \
+"{ [help] | show | shared | private } " \
+"- make VLAN learning shared or private"
+
+static int ethsw_vlan_learn_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_VLAN_FDB_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+#define ETHSW_PORT_INGR_FLTR_HELP "ethsw [port <port_no>] ingress filtering" \
+" { [help] | show | enable | disable } " \
+"- enable/disable VLAN ingress filtering on port"
+
+static int ethsw_ingr_fltr_help_key_func(struct ethsw_command_def *parsed_cmd)
+{
+       printf(ETHSW_PORT_INGR_FLTR_HELP"\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+static struct keywords_to_function {
+       enum ethsw_keyword_id cmd_keyword[ETHSW_MAX_CMD_PARAMS];
+       int cmd_func_offset;
+       int (*keyword_function)(struct ethsw_command_def *parsed_cmd);
+} ethsw_cmd_def[] = {
+               {
+                       .cmd_keyword = {
+                                       ethsw_id_enable,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_enable),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_disable,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_disable),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_statistics,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_port_stats_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_statistics,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_stats),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_statistics,
+                                       ethsw_id_clear,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_stats_clear),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_learning,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_learning,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_learning,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_learn_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_learning,
+                                       ethsw_id_auto,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_learn),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_learning,
+                                       ethsw_id_disable,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_learn),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_fdb_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_fdb_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   fdb_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_flush,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   fdb_flush),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_add,
+                                       ethsw_id_add_del_mac,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   fdb_entry_add),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_fdb,
+                                       ethsw_id_del,
+                                       ethsw_id_add_del_mac,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   fdb_entry_del),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_pvid,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_pvid_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_pvid,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_pvid_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_pvid,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   pvid_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_pvid,
+                                       ethsw_id_pvid_no,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   pvid_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_vlan_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_vlan_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_add,
+                                       ethsw_id_add_del_no,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_del,
+                                       ethsw_id_add_del_no,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_port_untag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_port_untag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_untag_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_all,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_untag_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_none,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_untag_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_untagged,
+                                       ethsw_id_pvid,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_untag_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_egress,
+                                       ethsw_id_tag,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_egr_tag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_egress,
+                                       ethsw_id_tag,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_egr_tag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_egress,
+                                       ethsw_id_tag,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_egr_vlan_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_egress,
+                                       ethsw_id_tag,
+                                       ethsw_id_pvid,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_egr_vlan_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_egress,
+                                       ethsw_id_tag,
+                                       ethsw_id_classified,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_egr_vlan_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_fdb,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_vlan_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_fdb,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_vlan_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_fdb,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_learn_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_fdb,
+                                       ethsw_id_shared,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_learn_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_vlan,
+                                       ethsw_id_fdb,
+                                       ethsw_id_private,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   vlan_learn_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_ingress,
+                                       ethsw_id_filtering,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_ingr_fltr_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_ingress,
+                                       ethsw_id_filtering,
+                                       ethsw_id_help,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = -1,
+                       .keyword_function = &ethsw_ingr_fltr_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_ingress,
+                                       ethsw_id_filtering,
+                                       ethsw_id_show,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_ingr_filt_show),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_ingress,
+                                       ethsw_id_filtering,
+                                       ethsw_id_enable,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_ingr_filt_set),
+                       .keyword_function = NULL,
+               }, {
+                       .cmd_keyword = {
+                                       ethsw_id_ingress,
+                                       ethsw_id_filtering,
+                                       ethsw_id_disable,
+                                       ethsw_id_key_end,
+                       },
+                       .cmd_func_offset = offsetof(struct ethsw_command_func,
+                                                   port_ingr_filt_set),
+                       .keyword_function = NULL,
+               },
+};
+
+struct keywords_optional {
+       int cmd_keyword[ETHSW_MAX_CMD_PARAMS];
+} cmd_opt_def[] = {
+               {
+                               .cmd_keyword = {
+                                               ethsw_id_port,
+                                               ethsw_id_port_no,
+                                               ethsw_id_key_end,
+                               },
+               }, {
+                               .cmd_keyword = {
+                                               ethsw_id_vlan,
+                                               ethsw_id_vlan_no,
+                                               ethsw_id_key_end,
+                               },
+               }, {
+                               .cmd_keyword = {
+                                               ethsw_id_port,
+                                               ethsw_id_port_no,
+                                               ethsw_id_vlan,
+                                               ethsw_id_vlan_no,
+                                               ethsw_id_key_end,
+                               },
+               },
+};
+
+static int keyword_match_gen(enum ethsw_keyword_id key_id, int argc, char
+                            *const argv[], int *argc_nr,
+                            struct ethsw_command_def *parsed_cmd);
+static int keyword_match_port(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd);
+static int keyword_match_vlan(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd);
+static int keyword_match_pvid(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd);
+static int keyword_match_mac_addr(enum ethsw_keyword_id key_id, int argc,
+                                 char *const argv[], int *argc_nr,
+                                 struct ethsw_command_def *parsed_cmd);
+
+/*
+ * Define properties for each keyword;
+ * keep the order synced with enum ethsw_keyword_id
+ */
+struct keyword_def {
+       const char *keyword_name;
+       int (*match)(enum ethsw_keyword_id key_id, int argc, char *const argv[],
+                    int *argc_nr, struct ethsw_command_def *parsed_cmd);
+} keyword[] = {
+               {
+                               .keyword_name = "help",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "show",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "port",
+                               .match = &keyword_match_port
+               },  {
+                               .keyword_name = "enable",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "disable",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "statistics",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "clear",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "learning",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "auto",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "vlan",
+                               .match = &keyword_match_vlan,
+               }, {
+                               .keyword_name = "fdb",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "add",
+                               .match = &keyword_match_mac_addr,
+               }, {
+                               .keyword_name = "del",
+                               .match = &keyword_match_mac_addr,
+               }, {
+                               .keyword_name = "flush",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "pvid",
+                               .match = &keyword_match_pvid,
+               }, {
+                               .keyword_name = "untagged",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "all",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "none",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "egress",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "tag",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "classified",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "shared",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "private",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "ingress",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "filtering",
+                               .match = &keyword_match_gen,
+               },
+};
+
+/*
+ * Function used by an Ethernet Switch driver to set the functions
+ * that must be called by the parser when an ethsw command is given
+ */
+int ethsw_define_functions(const struct ethsw_command_func *cmd_func)
+{
+       int i;
+       void **aux_p;
+       int (*cmd_func_aux)(struct ethsw_command_def *);
+
+       if (!cmd_func->ethsw_name)
+               return -EINVAL;
+
+       ethsw_name = cmd_func->ethsw_name;
+
+       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
+               /*
+                * get the pointer to the function send by the Ethernet Switch
+                * driver that corresponds to the proper ethsw command
+                */
+               if (ethsw_cmd_def[i].keyword_function)
+                       continue;
+
+               aux_p = (void *)cmd_func + ethsw_cmd_def[i].cmd_func_offset;
+
+               cmd_func_aux = (int (*)(struct ethsw_command_def *)) *aux_p;
+               ethsw_cmd_def[i].keyword_function = cmd_func_aux;
+       }
+
+       return 0;
+}
+
+/* Generic function used to match a keyword only by a string */
+static int keyword_match_gen(enum ethsw_keyword_id key_id, int argc,
+                            char *const argv[], int *argc_nr,
+                            struct ethsw_command_def *parsed_cmd)
+{
+       if (strcmp(argv[*argc_nr], keyword[key_id].keyword_name) == 0) {
+               parsed_cmd->cmd_to_keywords[*argc_nr] = key_id;
+
+               return 1;
+       }
+       return 0;
+}
+
+/* Function used to match the command's port */
+static int keyword_match_port(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd)
+{
+       unsigned long val;
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if (*argc_nr + 1 >= argc)
+               return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               parsed_cmd->port = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_port_no;
+               return 1;
+       }
+
+       return 0;
+}
+
+/* Function used to match the command's vlan */
+static int keyword_match_vlan(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd)
+{
+       unsigned long val;
+       int aux;
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if (*argc_nr + 1 >= argc)
+               return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               parsed_cmd->vid = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_vlan_no;
+               return 1;
+       }
+
+       aux = *argc_nr + 1;
+
+       if (keyword_match_gen(ethsw_id_add, argc, argv, &aux, parsed_cmd))
+               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_add;
+       else if (keyword_match_gen(ethsw_id_del, argc, argv, &aux, parsed_cmd))
+               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_del;
+       else
+               return 0;
+
+       if (*argc_nr + 2 >= argc)
+               return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 2], 10, &val) != -EINVAL) {
+               parsed_cmd->vid = val;
+               (*argc_nr) += 2;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_add_del_no;
+               return 1;
+       }
+
+       return 0;
+}
+
+/* Function used to match the command's pvid */
+static int keyword_match_pvid(enum ethsw_keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct ethsw_command_def *parsed_cmd)
+{
+       unsigned long val;
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if (*argc_nr + 1 >= argc)
+               return 1;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               parsed_cmd->vid = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_pvid_no;
+       }
+
+       return 1;
+}
+
+/* Function used to match the command's MAC address */
+static int keyword_match_mac_addr(enum ethsw_keyword_id key_id, int argc,
+                                    char *const argv[], int *argc_nr,
+                                    struct ethsw_command_def *parsed_cmd)
+{
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if ((*argc_nr + 1 >= argc) ||
+           !is_broadcast_ethaddr(parsed_cmd->ethaddr))
+               return 1;
+
+       if (eth_validate_ethaddr_str(argv[*argc_nr + 1])) {
+               printf("Invalid MAC address: %s\n", argv[*argc_nr + 1]);
+               return 0;
+       }
+
+       eth_parse_enetaddr(argv[*argc_nr + 1], parsed_cmd->ethaddr);
+
+       if (is_broadcast_ethaddr(parsed_cmd->ethaddr)) {
+               memset(parsed_cmd->ethaddr, 0xFF, sizeof(parsed_cmd->ethaddr));
+               return 0;
+       }
+
+       parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_add_del_mac;
+
+       return 1;
+}
+
+/* Finds optional keywords and modifies *argc_va to skip them */
+static void cmd_keywords_opt_check(const struct ethsw_command_def *parsed_cmd,
+                                  int *argc_val)
+{
+       int i;
+       int keyw_opt_matched;
+       int argc_val_max;
+       int const *cmd_keyw_p;
+       int const *cmd_keyw_opt_p;
+
+       /* remember the best match */
+       argc_val_max = *argc_val;
+
+       /*
+        * check if our command's optional keywords match the optional
+        * keywords of an available command
+        */
+       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
+               keyw_opt_matched = 0;
+               cmd_keyw_p = &parsed_cmd->cmd_to_keywords[keyw_opt_matched];
+               cmd_keyw_opt_p = &cmd_opt_def[i].cmd_keyword[keyw_opt_matched];
+
+               /*
+                * increase the number of keywords that
+                * matched with a command
+                */
+               while (keyw_opt_matched + *argc_val <
+                      parsed_cmd->cmd_keywords_nr &&
+                      *cmd_keyw_opt_p != ethsw_id_key_end &&
+                      *(cmd_keyw_p + *argc_val) == *cmd_keyw_opt_p) {
+                       keyw_opt_matched++;
+                       cmd_keyw_p++;
+                       cmd_keyw_opt_p++;
+               }
+
+               /*
+                * if all our optional command's keywords perfectly match an
+                * optional pattern, then we can move to the next defined
+                * keywords in our command; remember the one that matched the
+                * greatest number of keywords
+                */
+               if (keyw_opt_matched + *argc_val <=
+                   parsed_cmd->cmd_keywords_nr &&
+                   *cmd_keyw_opt_p == ethsw_id_key_end &&
+                   *argc_val + keyw_opt_matched > argc_val_max)
+                       argc_val_max = *argc_val + keyw_opt_matched;
+       }
+
+       *argc_val = argc_val_max;
+}
+
+/*
+ * Finds the function to call based on keywords and
+ * modifies *argc_va to skip them
+ */
+static void cmd_keywords_check(struct ethsw_command_def *parsed_cmd,
+                              int *argc_val)
+{
+       int i;
+       int keyw_matched;
+       int *cmd_keyw_p;
+       int *cmd_keyw_def_p;
+
+       /*
+        * check if our command's keywords match the
+        * keywords of an available command
+        */
+       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
+               keyw_matched = 0;
+               cmd_keyw_p = &parsed_cmd->cmd_to_keywords[keyw_matched];
+               cmd_keyw_def_p = &ethsw_cmd_def[i].cmd_keyword[keyw_matched];
+
+               /*
+                * increase the number of keywords that
+                * matched with a command
+                */
+               while (keyw_matched + *argc_val < parsed_cmd->cmd_keywords_nr &&
+                      *cmd_keyw_def_p != ethsw_id_key_end &&
+                      *(cmd_keyw_p + *argc_val) == *cmd_keyw_def_p) {
+                       keyw_matched++;
+                       cmd_keyw_p++;
+                       cmd_keyw_def_p++;
+               }
+
+               /*
+                * if all our command's keywords perfectly match an
+                * available command, then we get the function we need to call
+                * to configure the Ethernet Switch
+                */
+               if (keyw_matched && keyw_matched + *argc_val ==
+                   parsed_cmd->cmd_keywords_nr &&
+                   *cmd_keyw_def_p == ethsw_id_key_end) {
+                       *argc_val += keyw_matched;
+                       parsed_cmd->cmd_function =
+                                       ethsw_cmd_def[i].keyword_function;
+                       return;
+               }
+       }
+}
+
+/* find all the keywords in the command */
+static int keywords_find(int argc, char * const argv[],
+                        struct ethsw_command_def *parsed_cmd)
+{
+       int i;
+       int j;
+       int argc_val;
+       int rc = CMD_RET_SUCCESS;
+
+       for (i = 1; i < argc; i++) {
+               for (j = 0; j < ethsw_id_count; j++) {
+                       if (keyword[j].match(j, argc, argv, &i, parsed_cmd))
+                               break;
+               }
+       }
+
+       /* if there is no keyword match for a word, the command is invalid */
+       for (i = 1; i < argc; i++)
+               if (parsed_cmd->cmd_to_keywords[i] == ethsw_id_key_end)
+                       rc = CMD_RET_USAGE;
+
+       parsed_cmd->cmd_keywords_nr = argc;
+       argc_val = 1;
+
+       /* get optional parameters first */
+       cmd_keywords_opt_check(parsed_cmd, &argc_val);
+
+       if (argc_val == parsed_cmd->cmd_keywords_nr)
+               return CMD_RET_USAGE;
+
+       /*
+        * check the keywords and if a match is found,
+        * get the function to call
+        */
+       cmd_keywords_check(parsed_cmd, &argc_val);
+
+       /* error if not all commands' parameters were matched */
+       if (argc_val == parsed_cmd->cmd_keywords_nr) {
+               if (!parsed_cmd->cmd_function) {
+                       printf("Command not available for: %s\n", ethsw_name);
+                       rc = CMD_RET_FAILURE;
+               }
+       } else {
+               rc = CMD_RET_USAGE;
+       }
+
+       return rc;
+}
+
+static void command_def_init(struct ethsw_command_def *parsed_cmd)
+{
+       int i;
+
+       for (i = 0; i < ETHSW_MAX_CMD_PARAMS; i++)
+               parsed_cmd->cmd_to_keywords[i] = ethsw_id_key_end;
+
+       parsed_cmd->port = ETHSW_CMD_PORT_ALL;
+       parsed_cmd->vid = ETHSW_CMD_VLAN_ALL;
+       parsed_cmd->cmd_function = NULL;
+
+       /* We initialize the MAC address with the Broadcast address */
+       memset(parsed_cmd->ethaddr, 0xff, sizeof(parsed_cmd->ethaddr));
+}
+
+/* function to interpret commands starting with "ethsw " */
+static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct ethsw_command_def parsed_cmd;
+       int rc = CMD_RET_SUCCESS;
+
+       if (argc == 1 || argc >= ETHSW_MAX_CMD_PARAMS)
+               return CMD_RET_USAGE;
+
+       command_def_init(&parsed_cmd);
+
+       rc = keywords_find(argc, argv, &parsed_cmd);
+
+       if (rc == CMD_RET_SUCCESS)
+               rc = parsed_cmd.cmd_function(&parsed_cmd);
+
+       return rc;
+}
+
+#define ETHSW_PORT_CONF_HELP "[port <port_no>] { enable | disable | show } " \
+"- enable/disable a port; show shows a port's configuration"
+
+U_BOOT_CMD(ethsw, ETHSW_MAX_CMD_PARAMS, 0, do_ethsw,
+          "Ethernet l2 switch commands",
+          ETHSW_PORT_CONF_HELP"\n"
+          ETHSW_PORT_STATS_HELP"\n"
+          ETHSW_LEARN_HELP"\n"
+          ETHSW_FDB_HELP"\n"
+          ETHSW_PVID_HELP"\n"
+          ETHSW_VLAN_HELP"\n"
+          ETHSW_PORT_UNTAG_HELP"\n"
+          ETHSW_EGR_VLAN_TAG_HELP"\n"
+          ETHSW_VLAN_FDB_HELP"\n"
+          ETHSW_PORT_INGR_FLTR_HELP"\n"
+);
diff --git a/cmd/exit.c b/cmd/exit.c
new file mode 100644 (file)
index 0000000..c789233
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int do_exit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int r;
+
+       r = 0;
+       if (argc > 1)
+               r = simple_strtoul(argv[1], NULL, 10);
+
+       return -r - 2;
+}
+
+U_BOOT_CMD(
+       exit,   2,      1,      do_exit,
+       "exit script",
+       ""
+);
diff --git a/cmd/ext2.c b/cmd/ext2.c
new file mode 100644 (file)
index 0000000..6657ef5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2011 - 2012 Samsung Electronics
+ * EXT4 filesystem implementation in Uboot by
+ * Uma Shankar <uma.shankar@samsung.com>
+ * Manjunatha C Achar <a.manjunatha@samsung.com>
+
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Ext2fs support
+ */
+#include <fs.h>
+
+static int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+/******************************************************************************
+ * Ext2fs boot command intepreter. Derived from diskboot
+ */
+int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+U_BOOT_CMD(
+       ext2ls, 4,      1,      do_ext2ls,
+       "list files in a directory (default /)",
+       "<interface> <dev[:part]> [directory]\n"
+       "    - list files from 'dev' on 'interface' in a 'directory'"
+)
+
+U_BOOT_CMD(
+       ext2load,       6,      0,      do_ext2load,
+       "load binary file from a Ext2 filesystem",
+       "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
+       "    - load binary file 'filename' from 'dev' on 'interface'\n"
+       "      to address 'addr' from ext2 filesystem."
+)
diff --git a/cmd/ext4.c b/cmd/ext4.c
new file mode 100644 (file)
index 0000000..19423d1
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * (C) Copyright 2011 - 2012 Samsung Electronics
+ * EXT4 filesystem implementation in Uboot by
+ * Uma Shankar <uma.shankar@samsung.com>
+ * Manjunatha C Achar <a.manjunatha@samsung.com>
+ *
+ * Ext4fs support
+ * made from existing cmd_ext2.c file of Uboot
+ *
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Changelog:
+ *     0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
+ *             file in uboot. Added ext4fs ls load and write support.
+ */
+
+#include <common.h>
+#include <part.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <ext4fs.h>
+#include <linux/stat.h>
+#include <malloc.h>
+#include <fs.h>
+
+#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
+#include <usb.h>
+#endif
+
+int do_ext4_size(cmd_tbl_t *cmdtp, int flag, int argc,
+                                               char *const argv[])
+{
+       return do_size(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
+                                               char *const argv[])
+{
+       return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+#if defined(CONFIG_CMD_EXT4_WRITE)
+int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
+                 char *const argv[])
+{
+       return do_save(cmdtp, flag, argc, argv, FS_TYPE_EXT);
+}
+
+U_BOOT_CMD(ext4write, 7, 1, do_ext4_write,
+          "create a file in the root directory",
+          "<interface> <dev[:part]> <addr> <absolute filename path>\n"
+          "    [sizebytes] [file offset]\n"
+          "    - create a file in / directory");
+
+#endif
+
+U_BOOT_CMD(
+       ext4size,       4,      0,      do_ext4_size,
+       "determine a file's size",
+       "<interface> <dev[:part]> <filename>\n"
+       "    - Find file 'filename' from 'dev' on 'interface'\n"
+       "      and determine its size."
+);
+
+U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
+          "list files in a directory (default /)",
+          "<interface> <dev[:part]> [directory]\n"
+          "    - list files from 'dev' on 'interface' in a 'directory'");
+
+U_BOOT_CMD(ext4load, 7, 0, do_ext4_load,
+          "load binary file from a Ext4 filesystem",
+          "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
+          "    - load binary file 'filename' from 'dev' on 'interface'\n"
+          "      to address 'addr' from ext4 filesystem");
diff --git a/cmd/fastboot.c b/cmd/fastboot.c
new file mode 100644 (file)
index 0000000..488822a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 - 2009 Windriver, <www.windriver.com>
+ * Author: Tom Rix <Tom.Rix@windriver.com>
+ *
+ * (C) Copyright 2014 Linaro, Ltd.
+ * Rob Herring <robh@kernel.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <g_dnl.h>
+#include <usb.h>
+
+static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int controller_index;
+       char *usb_controller;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       usb_controller = argv[1];
+       controller_index = simple_strtoul(usb_controller, NULL, 0);
+
+       ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+       if (ret) {
+               error("USB init failed: %d", ret);
+               return CMD_RET_FAILURE;
+       }
+
+       g_dnl_clear_detach();
+       ret = g_dnl_register("usb_dnl_fastboot");
+       if (ret)
+               return ret;
+
+       if (!g_dnl_board_usb_cable_connected()) {
+               puts("\rUSB cable not detected.\n" \
+                    "Command exit.\n");
+               ret = CMD_RET_FAILURE;
+               goto exit;
+       }
+
+       while (1) {
+               if (g_dnl_detach())
+                       break;
+               if (ctrlc())
+                       break;
+               usb_gadget_handle_interrupts(controller_index);
+       }
+
+       ret = CMD_RET_SUCCESS;
+
+exit:
+       g_dnl_unregister();
+       g_dnl_clear_detach();
+       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+
+       return ret;
+}
+
+U_BOOT_CMD(
+       fastboot, 2, 1, do_fastboot,
+       "use USB Fastboot protocol",
+       "<USB_controller>\n"
+       "    - run as a fastboot usb device"
+);
diff --git a/cmd/fat.c b/cmd/fat.c
new file mode 100644 (file)
index 0000000..aae993d
--- /dev/null
+++ b/cmd/fat.c
@@ -0,0 +1,152 @@
+/*
+ * (C) Copyright 2002
+ * Richard Jones, rjones@nexus-tech.net
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <s_record.h>
+#include <net.h>
+#include <ata.h>
+#include <asm/io.h>
+#include <mapmem.h>
+#include <part.h>
+#include <fat.h>
+#include <fs.h>
+
+int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
+}
+
+U_BOOT_CMD(
+       fatsize,        4,      0,      do_fat_size,
+       "determine a file's size",
+       "<interface> <dev[:part]> <filename>\n"
+       "    - Find file 'filename' from 'dev' on 'interface'\n"
+       "      and determine its size."
+);
+
+int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
+}
+
+
+U_BOOT_CMD(
+       fatload,        7,      0,      do_fat_fsload,
+       "load binary file from a dos filesystem",
+       "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
+       "    - Load binary file 'filename' from 'dev' on 'interface'\n"
+       "      to address 'addr' from dos filesystem.\n"
+       "      'pos' gives the file position to start loading from.\n"
+       "      If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
+       "      'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
+       "      the load stops on end of file.\n"
+       "      If either 'pos' or 'bytes' are not aligned to\n"
+       "      ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
+       "      be printed and performance will suffer for the load."
+);
+
+static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
+}
+
+U_BOOT_CMD(
+       fatls,  4,      1,      do_fat_ls,
+       "list files in a directory (default /)",
+       "<interface> [<dev[:part]>] [directory]\n"
+       "    - list files from 'dev' on 'interface' in a 'directory'"
+);
+
+static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char * const argv[])
+{
+       int dev, part;
+       block_dev_desc_t *dev_desc;
+       disk_partition_t info;
+
+       if (argc < 2) {
+               printf("usage: fatinfo <interface> [<dev[:part]>]\n");
+               return 0;
+       }
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       dev = dev_desc->dev;
+       if (fat_set_blk_dev(dev_desc, &info) != 0) {
+               printf("\n** Unable to use %s %d:%d for fatinfo **\n",
+                       argv[1], dev, part);
+               return 1;
+       }
+       return file_fat_detectfs();
+}
+
+U_BOOT_CMD(
+       fatinfo,        3,      1,      do_fat_fsinfo,
+       "print information about filesystem",
+       "<interface> [<dev[:part]>]\n"
+       "    - print information about filesystem from 'dev' on 'interface'"
+);
+
+#ifdef CONFIG_FAT_WRITE
+static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       loff_t size;
+       int ret;
+       unsigned long addr;
+       unsigned long count;
+       block_dev_desc_t *dev_desc = NULL;
+       disk_partition_t info;
+       int dev = 0;
+       int part = 1;
+       void *buf;
+
+       if (argc < 5)
+               return cmd_usage(cmdtp);
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       dev = dev_desc->dev;
+
+       if (fat_set_blk_dev(dev_desc, &info) != 0) {
+               printf("\n** Unable to use %s %d:%d for fatwrite **\n",
+                       argv[1], dev, part);
+               return 1;
+       }
+       addr = simple_strtoul(argv[3], NULL, 16);
+       count = simple_strtoul(argv[5], NULL, 16);
+
+       buf = map_sysmem(addr, count);
+       ret = file_fat_write(argv[4], buf, 0, count, &size);
+       unmap_sysmem(buf);
+       if (ret < 0) {
+               printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
+                       argv[4], argv[1], dev, part);
+               return 1;
+       }
+
+       printf("%llu bytes written\n", size);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       fatwrite,       6,      0,      do_fat_fswrite,
+       "write file into a dos filesystem",
+       "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
+       "    - write file 'filename' from the address 'addr' in RAM\n"
+       "      to 'dev' on 'interface'"
+);
+#endif
diff --git a/cmd/fdc.c b/cmd/fdc.c
new file mode 100644 (file)
index 0000000..5766b56
--- /dev/null
+++ b/cmd/fdc.c
@@ -0,0 +1,752 @@
+/*
+ * (C) Copyright 2001
+ * Denis Peter, MPL AG, d.peter@mpl.ch.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+/*
+ * Floppy Disk support
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+
+
+#undef FDC_DEBUG
+
+#ifdef FDC_DEBUG
+#define        PRINTF(fmt,args...)     printf (fmt ,##args)
+#else
+#define PRINTF(fmt,args...)
+#endif
+
+/*#if defined(CONFIG_CMD_DATE) */
+/*#include <rtc.h> */
+/*#endif */
+
+typedef struct {
+       int             flags;          /* connected drives ect */
+       unsigned long   blnr;           /* Logical block nr */
+       uchar           drive;          /* drive no */
+       uchar           cmdlen;         /* cmd length */
+       uchar           cmd[16];        /* cmd desc */
+       uchar           dma;            /* if > 0 dma enabled */
+       uchar           result[11];     /* status information */
+       uchar           resultlen;      /* lenght of result */
+} FDC_COMMAND_STRUCT;
+
+/* flags: only the lower 8bit used:
+ * bit 0 if set drive 0 is present
+ * bit 1 if set drive 1 is present
+ * bit 2 if set drive 2 is present
+ * bit 3 if set drive 3 is present
+ * bit 4 if set disk in drive 0 is inserted
+ * bit 5 if set disk in drive 1 is inserted
+ * bit 6 if set disk in drive 2 is inserted
+ * bit 7 if set disk in drive 4 is inserted
+ */
+
+/* cmd indexes */
+#define COMMAND                        0
+#define DRIVE                  1
+#define CONFIG0                        1
+#define SPEC_HUTSRT            1
+#define TRACK                  2
+#define CONFIG1                        2
+#define SPEC_HLT               2
+#define HEAD                   3
+#define CONFIG2                        3
+#define SECTOR                 4
+#define SECTOR_SIZE            5
+#define LAST_TRACK             6
+#define GAP                    7
+#define DTL                    8
+/* result indexes */
+#define STATUS_0               0
+#define STATUS_PCN             1
+#define STATUS_1               1
+#define STATUS_2               2
+#define STATUS_TRACK           3
+#define STATUS_HEAD            4
+#define STATUS_SECT            5
+#define STATUS_SECT_SIZE       6
+
+
+/* Register addresses */
+#define FDC_BASE       0x3F0
+#define FDC_SRA                FDC_BASE + 0    /* Status Register A */
+#define FDC_SRB                FDC_BASE + 1    /* Status Register B */
+#define FDC_DOR                FDC_BASE + 2    /* Digital Output Register */
+#define FDC_TDR                FDC_BASE + 3    /* Tape Drive Register */
+#define FDC_DSR                FDC_BASE + 4    /* Data rate Register */
+#define FDC_MSR                FDC_BASE + 4    /* Main Status Register */
+#define FDC_FIFO       FDC_BASE + 5    /* FIFO */
+#define FDC_DIR                FDC_BASE + 6    /* Digital Input Register */
+#define FDC_CCR                FDC_BASE + 7    /* Configuration Control */
+/* Commands */
+#define FDC_CMD_SENSE_INT      0x08
+#define FDC_CMD_CONFIGURE      0x13
+#define FDC_CMD_SPECIFY                0x03
+#define FDC_CMD_RECALIBRATE    0x07
+#define FDC_CMD_READ           0x06
+#define FDC_CMD_READ_TRACK     0x02
+#define FDC_CMD_READ_ID                0x0A
+#define FDC_CMD_DUMP_REG       0x0E
+#define FDC_CMD_SEEK           0x0F
+
+#define FDC_CMD_SENSE_INT_LEN  0x01
+#define FDC_CMD_CONFIGURE_LEN  0x04
+#define FDC_CMD_SPECIFY_LEN    0x03
+#define FDC_CMD_RECALIBRATE_LEN        0x02
+#define FDC_CMD_READ_LEN       0x09
+#define FDC_CMD_READ_TRACK_LEN 0x09
+#define FDC_CMD_READ_ID_LEN    0x02
+#define FDC_CMD_DUMP_REG_LEN   0x01
+#define FDC_CMD_SEEK_LEN       0x03
+
+#define FDC_FIFO_THR           0x0C
+#define FDC_FIFO_DIS           0x00
+#define FDC_IMPLIED_SEEK       0x01
+#define FDC_POLL_DIS           0x00
+#define FDC_PRE_TRK            0x00
+#define FDC_CONFIGURE          FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
+#define FDC_MFM_MODE           0x01 /* MFM enable */
+#define FDC_SKIP_MODE          0x00 /* skip enable */
+
+#define FDC_TIME_OUT 100000 /* time out */
+#define        FDC_RW_RETRIES          3 /* read write retries */
+#define FDC_CAL_RETRIES                3 /* calibration and seek retries */
+
+
+/* Disk structure */
+typedef struct  {
+       unsigned int size;      /* nr of sectors total */
+       unsigned int sect;      /* sectors per track */
+       unsigned int head;      /* nr of heads */
+       unsigned int track;     /* nr of tracks */
+       unsigned int stretch;   /* !=0 means double track steps */
+       unsigned char   gap;    /* gap1 size */
+       unsigned char   rate;   /* data rate. |= 0x40 for perpendicular */
+       unsigned char   spec1;  /* stepping rate, head unload time */
+       unsigned char   fmt_gap;/* gap2 size */
+       unsigned char hlt;      /* head load time */
+       unsigned char sect_code;/* Sector Size code */
+       const char      * name; /* used only for predefined formats */
+} FD_GEO_STRUCT;
+
+
+/* supported Floppy types (currently only one) */
+const static FD_GEO_STRUCT floppy_type[2] = {
+       { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" },    /*  7 1.44MB 3.5"   */
+       {    0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL    },    /*  end of table    */
+};
+
+static FDC_COMMAND_STRUCT cmd; /* global command struct */
+
+/* If the boot drive number is undefined, we assume it's drive 0             */
+#ifndef CONFIG_SYS_FDC_DRIVE_NUMBER
+#define CONFIG_SYS_FDC_DRIVE_NUMBER 0
+#endif
+
+/* Hardware access */
+#ifndef CONFIG_SYS_ISA_IO_STRIDE
+#define CONFIG_SYS_ISA_IO_STRIDE 1
+#endif
+
+#ifndef CONFIG_SYS_ISA_IO_OFFSET
+#define CONFIG_SYS_ISA_IO_OFFSET 0
+#endif
+
+/* Supporting Functions */
+/* reads a Register of the FDC */
+unsigned char read_fdc_reg(unsigned int addr)
+{
+       volatile unsigned char *val =
+               (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
+                                          (addr * CONFIG_SYS_ISA_IO_STRIDE) +
+                                          CONFIG_SYS_ISA_IO_OFFSET);
+
+       return val [0];
+}
+
+/* writes a Register of the FDC */
+void write_fdc_reg(unsigned int addr, unsigned char val)
+{
+       volatile unsigned char *tmp =
+               (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
+                                          (addr * CONFIG_SYS_ISA_IO_STRIDE) +
+                                          CONFIG_SYS_ISA_IO_OFFSET);
+       tmp[0]=val;
+}
+
+/* waits for an interrupt (polling) */
+int wait_for_fdc_int(void)
+{
+       unsigned long timeout;
+       timeout = FDC_TIME_OUT;
+       while((read_fdc_reg(FDC_SRA)&0x80)==0) {
+               timeout--;
+               udelay(10);
+               if(timeout==0) /* timeout occured */
+                       return false;
+       }
+       return true;
+}
+
+/* reads a byte from the FIFO of the FDC and checks direction and RQM bit
+   of the MSR. returns -1 if timeout, or byte if ok */
+int read_fdc_byte(void)
+{
+       unsigned long timeout;
+       timeout = FDC_TIME_OUT;
+       while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
+               /* direction out and ready */
+               udelay(10);
+               timeout--;
+               if(timeout==0) /* timeout occured */
+                       return -1;
+       }
+       return read_fdc_reg(FDC_FIFO);
+}
+
+/* if the direction of the FIFO is wrong, this routine is used to
+   empty the FIFO. Should _not_ be used */
+int fdc_need_more_output(void)
+{
+       unsigned char c;
+       while((read_fdc_reg(FDC_MSR)&0xC0)==0xC0)       {
+                       c=(unsigned char)read_fdc_byte();
+                       printf("Error: more output: %x\n",c);
+       }
+       return true;
+}
+
+
+/* writes a byte to the FIFO of the FDC and checks direction and RQM bit
+   of the MSR */
+int write_fdc_byte(unsigned char val)
+{
+       unsigned long timeout;
+       timeout = FDC_TIME_OUT;
+       while((read_fdc_reg(FDC_MSR)&0xC0)!=0x80) {
+               /* direction in and ready for byte */
+               timeout--;
+               udelay(10);
+               fdc_need_more_output();
+               if(timeout==0) /* timeout occured */
+                       return false;
+       }
+       write_fdc_reg(FDC_FIFO,val);
+       return true;
+}
+
+/* sets up all FDC commands and issues it to the FDC. If
+   the command causes direct results (no Execution Phase)
+   the result is be read as well. */
+
+int fdc_issue_cmd(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
+{
+       int i;
+       unsigned long head,track,sect,timeout;
+       track = pCMD->blnr / (pFG->sect * pFG->head); /* track nr */
+       sect =  pCMD->blnr % (pFG->sect * pFG->head); /* remaining blocks */
+       head = sect / pFG->sect; /* head nr */
+       sect =  sect % pFG->sect; /* remaining blocks */
+       sect++; /* sectors are 1 based */
+       PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
+               pCMD->cmd[0],track,head,sect,pCMD->drive,pCMD->blnr);
+
+       if(head|=0) { /* max heads = 2 */
+               pCMD->cmd[DRIVE]=pCMD->drive | 0x04; /* head 1 */
+               pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
+       }
+       else {
+               pCMD->cmd[DRIVE]=pCMD->drive; /* head 0 */
+               pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
+       }
+       pCMD->cmd[TRACK]=(unsigned char) track; /* track */
+       switch (pCMD->cmd[COMMAND]) {
+               case FDC_CMD_READ:
+                       pCMD->cmd[SECTOR]=(unsigned char) sect; /* sector */
+                       pCMD->cmd[SECTOR_SIZE]=pFG->sect_code; /* sector size code */
+                       pCMD->cmd[LAST_TRACK]=pFG->sect; /* End of track */
+                       pCMD->cmd[GAP]=pFG->gap; /* gap */
+                       pCMD->cmd[DTL]=0xFF; /* DTL */
+                       pCMD->cmdlen=FDC_CMD_READ_LEN;
+                       pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
+                       pCMD->cmd[COMMAND]|=(FDC_SKIP_MODE<<5); /* set Skip bit */
+                       pCMD->resultlen=0;  /* result only after execution */
+                       break;
+               case FDC_CMD_SEEK:
+                       pCMD->cmdlen=FDC_CMD_SEEK_LEN;
+                       pCMD->resultlen=0;  /* no result */
+                       break;
+               case FDC_CMD_CONFIGURE:
+                       pCMD->cmd[CONFIG0]=0;
+                       pCMD->cmd[CONFIG1]=FDC_CONFIGURE; /* FIFO Threshold, Poll, Enable FIFO */
+                       pCMD->cmd[CONFIG2]=FDC_PRE_TRK; /* Precompensation Track */
+                       pCMD->cmdlen=FDC_CMD_CONFIGURE_LEN;
+                       pCMD->resultlen=0;  /* no result */
+                       break;
+               case FDC_CMD_SPECIFY:
+                       pCMD->cmd[SPEC_HUTSRT]=pFG->spec1;
+                       pCMD->cmd[SPEC_HLT]=(pFG->hlt)<<1; /* head load time */
+                       if(pCMD->dma==0)
+                               pCMD->cmd[SPEC_HLT]|=0x1; /* no dma */
+                       pCMD->cmdlen=FDC_CMD_SPECIFY_LEN;
+                       pCMD->resultlen=0;  /* no result */
+                       break;
+               case FDC_CMD_DUMP_REG:
+                       pCMD->cmdlen=FDC_CMD_DUMP_REG_LEN;
+                       pCMD->resultlen=10;  /* 10 byte result */
+                       break;
+               case FDC_CMD_READ_ID:
+                       pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
+                       pCMD->cmdlen=FDC_CMD_READ_ID_LEN;
+                       pCMD->resultlen=7;  /* 7 byte result */
+                       break;
+               case FDC_CMD_RECALIBRATE:
+                       pCMD->cmd[DRIVE]&=0x03; /* don't set the head bit */
+                       pCMD->cmdlen=FDC_CMD_RECALIBRATE_LEN;
+                       pCMD->resultlen=0;  /* no result */
+                       break;
+                       break;
+               case FDC_CMD_SENSE_INT:
+                       pCMD->cmdlen=FDC_CMD_SENSE_INT_LEN;
+                       pCMD->resultlen=2;
+                       break;
+       }
+       for(i=0;i<pCMD->cmdlen;i++) {
+               /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
+               if (write_fdc_byte(pCMD->cmd[i]) == false) {
+                       PRINTF("Error: timeout while issue cmd%d\n",i);
+                       return false;
+               }
+       }
+       timeout=FDC_TIME_OUT;
+       for(i=0;i<pCMD->resultlen;i++) {
+               while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
+                       timeout--;
+                       if(timeout==0) {
+                               PRINTF(" timeout while reading result%d MSR=0x%02X\n",i,read_fdc_reg(FDC_MSR));
+                               return false;
+                       }
+               }
+               pCMD->result[i]=(unsigned char)read_fdc_byte();
+       }
+       return true;
+}
+
+/* selects the drive assigned in the cmd structur and
+   switches on the Motor */
+void select_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
+{
+       unsigned char val;
+
+       val=(1<<(4+pCMD->drive))|pCMD->drive|0xC; /* set reset, dma gate and motor bits */
+       if((read_fdc_reg(FDC_DOR)&val)!=val) {
+               write_fdc_reg(FDC_DOR,val);
+               for(val=0;val<255;val++)
+                       udelay(500); /* wait some time to start motor */
+       }
+}
+
+/* switches off the Motor of the specified drive */
+void stop_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
+{
+       unsigned char val;
+
+       val=(1<<(4+pCMD->drive))|pCMD->drive; /* sets motor bits */
+       write_fdc_reg(FDC_DOR,(read_fdc_reg(FDC_DOR)&~val));
+}
+
+/* issues a recalibrate command, waits for interrupt and
+ * issues a sense_interrupt */
+int fdc_recalibrate(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
+{
+       pCMD->cmd[COMMAND]=FDC_CMD_RECALIBRATE;
+       if (fdc_issue_cmd(pCMD, pFG) == false)
+               return false;
+       while (wait_for_fdc_int() != true);
+
+       pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
+       return(fdc_issue_cmd(pCMD,pFG));
+}
+
+/* issues a recalibrate command, waits for interrupt and
+ * issues a sense_interrupt */
+int fdc_seek(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
+{
+       pCMD->cmd[COMMAND]=FDC_CMD_SEEK;
+       if (fdc_issue_cmd(pCMD, pFG) == false)
+               return false;
+       while (wait_for_fdc_int() != true);
+
+       pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
+       return(fdc_issue_cmd(pCMD,pFG));
+}
+
+/* terminates current command, by not servicing the FIFO
+ * waits for interrupt and fills in the result bytes */
+int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
+{
+       int i;
+       for(i=0;i<100;i++)
+               udelay(500); /* wait 500usec for fifo overrun */
+       while((read_fdc_reg(FDC_SRA)&0x80)==0x00); /* wait as long as no int has occured */
+       for(i=0;i<7;i++) {
+               pCMD->result[i]=(unsigned char)read_fdc_byte();
+       }
+       return true;
+}
+
+/* reads data from FDC, seek commands are issued automatic */
+int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
+{
+  /* first seek to start address */
+       unsigned long len,readblk,i,timeout,ii,offset;
+       unsigned char c,retriesrw,retriescal;
+       unsigned char *bufferw; /* working buffer */
+       int sect_size;
+       int flags;
+
+       flags=disable_interrupts(); /* switch off all Interrupts */
+       select_fdc_drive(pCMD); /* switch on drive */
+       sect_size=0x080<<pFG->sect_code;
+       retriesrw=0;
+       retriescal=0;
+       offset=0;
+       if (fdc_seek(pCMD, pFG) == false) {
+               stop_fdc_drive(pCMD);
+               if (flags)
+                       enable_interrupts();
+               return false;
+       }
+       if((pCMD->result[STATUS_0]&0x20)!=0x20) {
+               printf("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
+               stop_fdc_drive(pCMD);
+               if (flags)
+                       enable_interrupts();
+               return false;
+       }
+       /* now determine the next seek point */
+       /*      lastblk=pCMD->blnr + blocks; */
+       /*      readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
+       readblk=pFG->sect-(pCMD->blnr%pFG->sect);
+       PRINTF("1st nr of block possible read %ld start %ld\n",readblk,pCMD->blnr);
+       if(readblk>blocks) /* is end within 1st track */
+               readblk=blocks; /* yes, correct it */
+       PRINTF("we read %ld blocks start %ld\n",readblk,pCMD->blnr);
+       bufferw = &buffer[0]; /* setup working buffer */
+       do {
+retryrw:
+               len=sect_size * readblk;
+               pCMD->cmd[COMMAND]=FDC_CMD_READ;
+               if (fdc_issue_cmd(pCMD, pFG) == false) {
+                       stop_fdc_drive(pCMD);
+                       if (flags)
+                               enable_interrupts();
+                       return false;
+               }
+               for (i=0;i<len;i++) {
+                       timeout=FDC_TIME_OUT;
+                       do {
+                               c=read_fdc_reg(FDC_MSR);
+                               if((c&0xC0)==0xC0) {
+                                       bufferw[i]=read_fdc_reg(FDC_FIFO);
+                                       break;
+                               }
+                               if((c&0xC0)==0x80) { /* output */
+                                       PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i,c);
+                                       if(i>6) {
+                                               for(ii=0;ii<7;ii++) {
+                                                       pCMD->result[ii]=bufferw[(i-7+ii)];
+                                               } /* for */
+                                       }
+                                       if(retriesrw++>FDC_RW_RETRIES) {
+                                               if (retriescal++>FDC_CAL_RETRIES) {
+                                                       stop_fdc_drive(pCMD);
+                                                       if (flags)
+                                                               enable_interrupts();
+                                                       return false;
+                                               }
+                                               else {
+                                                       PRINTF(" trying to recalibrate Try %d\n",retriescal);
+                                                       if (fdc_recalibrate(pCMD, pFG) == false) {
+                                                               stop_fdc_drive(pCMD);
+                                                               if (flags)
+                                                                       enable_interrupts();
+                                                               return false;
+                                                       }
+                                                       retriesrw=0;
+                                                       goto retrycal;
+                                               } /* else >FDC_CAL_RETRIES */
+                                       }
+                                       else {
+                                               PRINTF("Read retry %d\n",retriesrw);
+                                               goto retryrw;
+                                       } /* else >FDC_RW_RETRIES */
+                               }/* if output */
+                               timeout--;
+                       } while (true);
+               } /* for len */
+               /* the last sector of a track or all data has been read,
+                * we need to get the results */
+               fdc_terminate(pCMD);
+               offset+=(sect_size*readblk); /* set up buffer pointer */
+               bufferw = &buffer[offset];
+               pCMD->blnr+=readblk; /* update current block nr */
+               blocks-=readblk; /* update blocks */
+               if(blocks==0)
+                       break; /* we are finish */
+               /* setup new read blocks */
+               /*      readblk=pFG->head*pFG->sect; */
+               readblk=pFG->sect;
+               if(readblk>blocks)
+                       readblk=blocks;
+retrycal:
+               /* a seek is necessary */
+               if (fdc_seek(pCMD, pFG) == false) {
+                       stop_fdc_drive(pCMD);
+                       if (flags)
+                               enable_interrupts();
+                       return false;
+               }
+               if((pCMD->result[STATUS_0]&0x20)!=0x20) {
+                       PRINTF("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
+                       stop_fdc_drive(pCMD);
+                       return false;
+               }
+       } while (true); /* start over */
+       stop_fdc_drive(pCMD); /* switch off drive */
+       if (flags)
+               enable_interrupts();
+       return true;
+}
+
+/* Scan all drives and check if drive is present and disk is inserted */
+int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
+{
+       int i,drives,state;
+  /* OK procedure of data book is satisfied.
+        * trying to get some information over the drives */
+       state=0; /* no drives, no disks */
+       for(drives=0;drives<4;drives++) {
+               pCMD->drive=drives;
+               select_fdc_drive(pCMD);
+               pCMD->blnr=0; /* set to the 1st block */
+               if (fdc_recalibrate(pCMD, pFG) == false)
+                       continue;
+               if((pCMD->result[STATUS_0]&0x10)==0x10)
+                       continue;
+               /* ok drive connected check for disk */
+               state|=(1<<drives);
+               pCMD->blnr=pFG->size; /* set to the last block */
+               if (fdc_seek(pCMD, pFG) == false)
+                       continue;
+               pCMD->blnr=0; /* set to the 1st block */
+               if (fdc_recalibrate(pCMD, pFG) == false)
+                       continue;
+               pCMD->cmd[COMMAND]=FDC_CMD_READ_ID;
+               if (fdc_issue_cmd(pCMD, pFG) == false)
+                       continue;
+               state|=(0x10<<drives);
+       }
+       stop_fdc_drive(pCMD);
+       for(i=0;i<4;i++) {
+               PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i,
+                       ((state&(1<<i))==(1<<i)) ? "":"not ",
+                       ((state&(0x10<<i))==(0x10<<i)) ? "":"no ",
+                       ((state&(0x10<<i))==(0x10<<i)) ? pFG->name : "");
+       }
+       pCMD->flags=state;
+       return true;
+}
+
+
+/**************************************************************************
+* int fdc_setup
+* setup the fdc according the datasheet
+* assuming in PS2 Mode
+*/
+int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
+{
+       int i;
+
+#ifdef CONFIG_SYS_FDC_HW_INIT
+       fdc_hw_init ();
+#endif
+       /* first, we reset the FDC via the DOR */
+       write_fdc_reg(FDC_DOR,0x00);
+       for(i=0; i<255; i++) /* then we wait some time */
+               udelay(500);
+       /* then, we clear the reset in the DOR */
+       pCMD->drive=drive;
+       select_fdc_drive(pCMD);
+       /* initialize the CCR */
+       write_fdc_reg(FDC_CCR,pFG->rate);
+       /* then initialize the DSR */
+       write_fdc_reg(FDC_DSR,pFG->rate);
+       if (wait_for_fdc_int() == false) {
+                       PRINTF("Time Out after writing CCR\n");
+                       return false;
+       }
+       /* now issue sense Interrupt and status command
+        * assuming only one drive present (drive 0) */
+       pCMD->dma=0; /* we don't use any dma at all */
+       for(i=0;i<4;i++) {
+               /* issue sense interrupt for all 4 possible drives */
+               pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
+               if (fdc_issue_cmd(pCMD, pFG) == false) {
+                       PRINTF("Sense Interrupt for drive %d failed\n",i);
+               }
+       }
+       /* issue the configure command */
+       pCMD->drive=drive;
+       select_fdc_drive(pCMD);
+       pCMD->cmd[COMMAND]=FDC_CMD_CONFIGURE;
+       if (fdc_issue_cmd(pCMD, pFG) == false) {
+               PRINTF(" configure timeout\n");
+               stop_fdc_drive(pCMD);
+               return false;
+       }
+       /* issue specify command */
+       pCMD->cmd[COMMAND]=FDC_CMD_SPECIFY;
+       if (fdc_issue_cmd(pCMD, pFG) == false) {
+               PRINTF(" specify timeout\n");
+               stop_fdc_drive(pCMD);
+               return false;
+
+       }
+       /* then, we clear the reset in the DOR */
+       /* fdc_check_drive(pCMD,pFG);   */
+       /*      write_fdc_reg(FDC_DOR,0x04); */
+
+       return true;
+}
+
+/****************************************************************************
+ * main routine do_fdcboot
+ */
+int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
+       FDC_COMMAND_STRUCT *pCMD = &cmd;
+       unsigned long addr,imsize;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       image_header_t *hdr;  /* used for fdc boot */
+#endif
+       unsigned char boot_drive;
+       int i,nrofblk;
+#if defined(CONFIG_FIT)
+       const void *fit_hdr = NULL;
+#endif
+
+       switch (argc) {
+       case 1:
+               addr = CONFIG_SYS_LOAD_ADDR;
+               boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
+               break;
+       case 2:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
+               break;
+       case 3:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               boot_drive=simple_strtoul(argv[2], NULL, 10);
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+       /* setup FDC and scan for drives  */
+       if (fdc_setup(boot_drive, pCMD, pFG) == false) {
+               printf("\n** Error in setup FDC **\n");
+               return 1;
+       }
+       if (fdc_check_drive(pCMD, pFG) == false) {
+               printf("\n** Error in check_drives **\n");
+               return 1;
+       }
+       if((pCMD->flags&(1<<boot_drive))==0) {
+               /* drive not available */
+               printf("\n** Drive %d not availabe **\n",boot_drive);
+               return 1;
+       }
+       if((pCMD->flags&(0x10<<boot_drive))==0) {
+               /* no disk inserted */
+               printf("\n** No disk inserted in drive %d **\n",boot_drive);
+               return 1;
+       }
+       /* ok, we have a valid source */
+       pCMD->drive=boot_drive;
+       /* read first block */
+       pCMD->blnr=0;
+       if (fdc_read_data((unsigned char *)addr, 1, pCMD, pFG) == false) {
+               printf("\nRead error:");
+               for(i=0;i<7;i++)
+                       printf("result%d: 0x%02X\n",i,pCMD->result[i]);
+               return 1;
+       }
+
+       switch (genimg_get_format ((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+               hdr = (image_header_t *)addr;
+               image_print_contents (hdr);
+
+               imsize = image_get_image_size (hdr);
+               break;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               fit_hdr = (const void *)addr;
+               puts ("Fit image detected...\n");
+
+               imsize = fit_get_size (fit_hdr);
+               break;
+#endif
+       default:
+               puts ("** Unknown image type\n");
+               return 1;
+       }
+
+       nrofblk=imsize/512;
+       if((imsize%512)>0)
+               nrofblk++;
+       printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr);
+       pCMD->blnr=0;
+       if (fdc_read_data((unsigned char *)addr, nrofblk, pCMD, pFG) == false) {
+               /* read image block */
+               printf("\nRead error:");
+               for(i=0;i<7;i++)
+                       printf("result%d: 0x%02X\n",i,pCMD->result[i]);
+               return 1;
+       }
+       printf("OK %ld Bytes loaded.\n",imsize);
+
+       flush_cache (addr, imsize);
+
+#if defined(CONFIG_FIT)
+       /* This cannot be done earlier, we need complete FIT image in RAM first */
+       if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
+               if (!fit_check_format (fit_hdr)) {
+                       puts ("** Bad FIT image format\n");
+                       return 1;
+               }
+               fit_print_contents (fit_hdr);
+       }
+#endif
+
+       /* Loading ok, update default load address */
+       load_addr = addr;
+
+       return bootm_maybe_autostart(cmdtp, argv[0]);
+}
+
+U_BOOT_CMD(
+       fdcboot,        3,      1,      do_fdcboot,
+       "boot from floppy device",
+       "loadAddr drive"
+);
diff --git a/cmd/fdt.c b/cmd/fdt.c
new file mode 100644 (file)
index 0000000..4c18962
--- /dev/null
+++ b/cmd/fdt.c
@@ -0,0 +1,1065 @@
+/*
+ * (C) Copyright 2007
+ * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
+ * Based on code written by:
+ *   Pantelis Antoniou <pantelis.antoniou@gmail.com> and
+ *   Matthew McClintock <msm@freescale.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <linux/ctype.h>
+#include <linux/types.h>
+#include <asm/global_data.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+#include <mapmem.h>
+#include <asm/io.h>
+
+#define MAX_LEVEL      32              /* how deeply nested we will go */
+#define SCRATCHPAD     1024            /* bytes of scratchpad memory */
+#ifndef CONFIG_CMD_FDT_MAX_DUMP
+#define CONFIG_CMD_FDT_MAX_DUMP 64
+#endif
+
+/*
+ * Global data (for the gd->bd)
+ */
+DECLARE_GLOBAL_DATA_PTR;
+
+static int fdt_valid(struct fdt_header **blobp);
+static int fdt_parse_prop(char *const*newval, int count, char *data, int *len);
+static int fdt_print(const char *pathp, char *prop, int depth);
+static int is_printable_string(const void *data, int len);
+
+/*
+ * The working_fdt points to our working flattened device tree.
+ */
+struct fdt_header *working_fdt;
+
+void set_working_fdt_addr(ulong addr)
+{
+       void *buf;
+
+       buf = map_sysmem(addr, 0);
+       working_fdt = buf;
+       setenv_hex("fdtaddr", addr);
+}
+
+/*
+ * Get a value from the fdt and format it to be set in the environment
+ */
+static int fdt_value_setenv(const void *nodep, int len, const char *var)
+{
+       if (is_printable_string(nodep, len))
+               setenv(var, (void *)nodep);
+       else if (len == 4) {
+               char buf[11];
+
+               sprintf(buf, "0x%08X", *(uint32_t *)nodep);
+               setenv(var, buf);
+       } else if (len%4 == 0 && len <= 20) {
+               /* Needed to print things like sha1 hashes. */
+               char buf[41];
+               int i;
+
+               for (i = 0; i < len; i += sizeof(unsigned int))
+                       sprintf(buf + (i * 2), "%08x",
+                               *(unsigned int *)(nodep + i));
+               setenv(var, buf);
+       } else {
+               printf("error: unprintable value\n");
+               return 1;
+       }
+       return 0;
+}
+
+/*
+ * Flattened Device Tree command, see the help for parameter definitions.
+ */
+static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /*
+        * Set the address of the fdt
+        */
+       if (argv[1][0] == 'a') {
+               unsigned long addr;
+               int control = 0;
+               struct fdt_header *blob;
+               /*
+                * Set the address [and length] of the fdt.
+                */
+               argc -= 2;
+               argv += 2;
+/* Temporary #ifdef - some archs don't have fdt_blob yet */
+#ifdef CONFIG_OF_CONTROL
+               if (argc && !strcmp(*argv, "-c")) {
+                       control = 1;
+                       argc--;
+                       argv++;
+               }
+#endif
+               if (argc == 0) {
+                       if (control)
+                               blob = (struct fdt_header *)gd->fdt_blob;
+                       else
+                               blob = working_fdt;
+                       if (!blob || !fdt_valid(&blob))
+                               return 1;
+                       printf("The address of the fdt is %#08lx\n",
+                              control ? (ulong)map_to_sysmem(blob) :
+                                       getenv_hex("fdtaddr", 0));
+                       return 0;
+               }
+
+               addr = simple_strtoul(argv[0], NULL, 16);
+               blob = map_sysmem(addr, 0);
+               if (!fdt_valid(&blob))
+                       return 1;
+               if (control)
+                       gd->fdt_blob = blob;
+               else
+                       set_working_fdt_addr(addr);
+
+               if (argc >= 2) {
+                       int  len;
+                       int  err;
+                       /*
+                        * Optional new length
+                        */
+                       len = simple_strtoul(argv[1], NULL, 16);
+                       if (len < fdt_totalsize(blob)) {
+                               printf ("New length %d < existing length %d, "
+                                       "ignoring.\n",
+                                       len, fdt_totalsize(blob));
+                       } else {
+                               /*
+                                * Open in place with a new length.
+                                */
+                               err = fdt_open_into(blob, blob, len);
+                               if (err != 0) {
+                                       printf ("libfdt fdt_open_into(): %s\n",
+                                               fdt_strerror(err));
+                               }
+                       }
+               }
+
+               return CMD_RET_SUCCESS;
+       }
+
+       if (!working_fdt) {
+               puts(
+                       "No FDT memory address configured. Please configure\n"
+                       "the FDT address via \"fdt addr <address>\" command.\n"
+                       "Aborting!\n");
+               return CMD_RET_FAILURE;
+       }
+
+       /*
+        * Move the working_fdt
+        */
+       if (strncmp(argv[1], "mo", 2) == 0) {
+               struct fdt_header *newaddr;
+               int  len;
+               int  err;
+
+               if (argc < 4)
+                       return CMD_RET_USAGE;
+
+               /*
+                * Set the address and length of the fdt.
+                */
+               working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16);
+               if (!fdt_valid(&working_fdt))
+                       return 1;
+
+               newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16);
+
+               /*
+                * If the user specifies a length, use that.  Otherwise use the
+                * current length.
+                */
+               if (argc <= 4) {
+                       len = fdt_totalsize(working_fdt);
+               } else {
+                       len = simple_strtoul(argv[4], NULL, 16);
+                       if (len < fdt_totalsize(working_fdt)) {
+                               printf ("New length 0x%X < existing length "
+                                       "0x%X, aborting.\n",
+                                       len, fdt_totalsize(working_fdt));
+                               return 1;
+                       }
+               }
+
+               /*
+                * Copy to the new location.
+                */
+               err = fdt_open_into(working_fdt, newaddr, len);
+               if (err != 0) {
+                       printf ("libfdt fdt_open_into(): %s\n",
+                               fdt_strerror(err));
+                       return 1;
+               }
+               working_fdt = newaddr;
+
+       /*
+        * Make a new node
+        */
+       } else if (strncmp(argv[1], "mk", 2) == 0) {
+               char *pathp;            /* path */
+               char *nodep;            /* new node to add */
+               int  nodeoffset;        /* node offset from libfdt */
+               int  err;
+
+               /*
+                * Parameters: Node path, new node to be appended to the path.
+                */
+               if (argc < 4)
+                       return CMD_RET_USAGE;
+
+               pathp = argv[2];
+               nodep = argv[3];
+
+               nodeoffset = fdt_path_offset (working_fdt, pathp);
+               if (nodeoffset < 0) {
+                       /*
+                        * Not found or something else bad happened.
+                        */
+                       printf ("libfdt fdt_path_offset() returned %s\n",
+                               fdt_strerror(nodeoffset));
+                       return 1;
+               }
+               err = fdt_add_subnode(working_fdt, nodeoffset, nodep);
+               if (err < 0) {
+                       printf ("libfdt fdt_add_subnode(): %s\n",
+                               fdt_strerror(err));
+                       return 1;
+               }
+
+       /*
+        * Set the value of a property in the working_fdt.
+        */
+       } else if (argv[1][0] == 's') {
+               char *pathp;            /* path */
+               char *prop;             /* property */
+               int  nodeoffset;        /* node offset from libfdt */
+               static char data[SCRATCHPAD];   /* storage for the property */
+               int  len;               /* new length of the property */
+               int  ret;               /* return value */
+
+               /*
+                * Parameters: Node path, property, optional value.
+                */
+               if (argc < 4)
+                       return CMD_RET_USAGE;
+
+               pathp  = argv[2];
+               prop   = argv[3];
+               if (argc == 4) {
+                       len = 0;
+               } else {
+                       ret = fdt_parse_prop(&argv[4], argc - 4, data, &len);
+                       if (ret != 0)
+                               return ret;
+               }
+
+               nodeoffset = fdt_path_offset (working_fdt, pathp);
+               if (nodeoffset < 0) {
+                       /*
+                        * Not found or something else bad happened.
+                        */
+                       printf ("libfdt fdt_path_offset() returned %s\n",
+                               fdt_strerror(nodeoffset));
+                       return 1;
+               }
+
+               ret = fdt_setprop(working_fdt, nodeoffset, prop, data, len);
+               if (ret < 0) {
+                       printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret));
+                       return 1;
+               }
+
+       /********************************************************************
+        * Get the value of a property in the working_fdt.
+        ********************************************************************/
+       } else if (argv[1][0] == 'g') {
+               char *subcmd;           /* sub-command */
+               char *pathp;            /* path */
+               char *prop;             /* property */
+               char *var;              /* variable to store result */
+               int  nodeoffset;        /* node offset from libfdt */
+               const void *nodep;      /* property node pointer */
+               int  len = 0;           /* new length of the property */
+
+               /*
+                * Parameters: Node path, property, optional value.
+                */
+               if (argc < 5)
+                       return CMD_RET_USAGE;
+
+               subcmd = argv[2];
+
+               if (argc < 6 && subcmd[0] != 's')
+                       return CMD_RET_USAGE;
+
+               var    = argv[3];
+               pathp  = argv[4];
+               prop   = argv[5];
+
+               nodeoffset = fdt_path_offset(working_fdt, pathp);
+               if (nodeoffset < 0) {
+                       /*
+                        * Not found or something else bad happened.
+                        */
+                       printf("libfdt fdt_path_offset() returned %s\n",
+                               fdt_strerror(nodeoffset));
+                       return 1;
+               }
+
+               if (subcmd[0] == 'n' || (subcmd[0] == 's' && argc == 5)) {
+                       int reqIndex = -1;
+                       int startDepth = fdt_node_depth(
+                               working_fdt, nodeoffset);
+                       int curDepth = startDepth;
+                       int curIndex = -1;
+                       int nextNodeOffset = fdt_next_node(
+                               working_fdt, nodeoffset, &curDepth);
+
+                       if (subcmd[0] == 'n')
+                               reqIndex = simple_strtoul(argv[5], NULL, 16);
+
+                       while (curDepth > startDepth) {
+                               if (curDepth == startDepth + 1)
+                                       curIndex++;
+                               if (subcmd[0] == 'n' && curIndex == reqIndex) {
+                                       const char *nodeName = fdt_get_name(
+                                           working_fdt, nextNodeOffset, NULL);
+
+                                       setenv(var, (char *)nodeName);
+                                       return 0;
+                               }
+                               nextNodeOffset = fdt_next_node(
+                                       working_fdt, nextNodeOffset, &curDepth);
+                               if (nextNodeOffset < 0)
+                                       break;
+                       }
+                       if (subcmd[0] == 's') {
+                               /* get the num nodes at this level */
+                               setenv_ulong(var, curIndex + 1);
+                       } else {
+                               /* node index not found */
+                               printf("libfdt node not found\n");
+                               return 1;
+                       }
+               } else {
+                       nodep = fdt_getprop(
+                               working_fdt, nodeoffset, prop, &len);
+                       if (len == 0) {
+                               /* no property value */
+                               setenv(var, "");
+                               return 0;
+                       } else if (len > 0) {
+                               if (subcmd[0] == 'v') {
+                                       int ret;
+
+                                       ret = fdt_value_setenv(nodep, len, var);
+                                       if (ret != 0)
+                                               return ret;
+                               } else if (subcmd[0] == 'a') {
+                                       /* Get address */
+                                       char buf[11];
+
+                                       sprintf(buf, "0x%p", nodep);
+                                       setenv(var, buf);
+                               } else if (subcmd[0] == 's') {
+                                       /* Get size */
+                                       char buf[11];
+
+                                       sprintf(buf, "0x%08X", len);
+                                       setenv(var, buf);
+                               } else
+                                       return CMD_RET_USAGE;
+                               return 0;
+                       } else {
+                               printf("libfdt fdt_getprop(): %s\n",
+                                       fdt_strerror(len));
+                               return 1;
+                       }
+               }
+
+       /*
+        * Print (recursive) / List (single level)
+        */
+       } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) {
+               int depth = MAX_LEVEL;  /* how deep to print */
+               char *pathp;            /* path */
+               char *prop;             /* property */
+               int  ret;               /* return value */
+               static char root[2] = "/";
+
+               /*
+                * list is an alias for print, but limited to 1 level
+                */
+               if (argv[1][0] == 'l') {
+                       depth = 1;
+               }
+
+               /*
+                * Get the starting path.  The root node is an oddball,
+                * the offset is zero and has no name.
+                */
+               if (argc == 2)
+                       pathp = root;
+               else
+                       pathp = argv[2];
+               if (argc > 3)
+                       prop = argv[3];
+               else
+                       prop = NULL;
+
+               ret = fdt_print(pathp, prop, depth);
+               if (ret != 0)
+                       return ret;
+
+       /*
+        * Remove a property/node
+        */
+       } else if (strncmp(argv[1], "rm", 2) == 0) {
+               int  nodeoffset;        /* node offset from libfdt */
+               int  err;
+
+               /*
+                * Get the path.  The root node is an oddball, the offset
+                * is zero and has no name.
+                */
+               nodeoffset = fdt_path_offset (working_fdt, argv[2]);
+               if (nodeoffset < 0) {
+                       /*
+                        * Not found or something else bad happened.
+                        */
+                       printf ("libfdt fdt_path_offset() returned %s\n",
+                               fdt_strerror(nodeoffset));
+                       return 1;
+               }
+               /*
+                * Do the delete.  A fourth parameter means delete a property,
+                * otherwise delete the node.
+                */
+               if (argc > 3) {
+                       err = fdt_delprop(working_fdt, nodeoffset, argv[3]);
+                       if (err < 0) {
+                               printf("libfdt fdt_delprop():  %s\n",
+                                       fdt_strerror(err));
+                               return err;
+                       }
+               } else {
+                       err = fdt_del_node(working_fdt, nodeoffset);
+                       if (err < 0) {
+                               printf("libfdt fdt_del_node():  %s\n",
+                                       fdt_strerror(err));
+                               return err;
+                       }
+               }
+
+       /*
+        * Display header info
+        */
+       } else if (argv[1][0] == 'h') {
+               u32 version = fdt_version(working_fdt);
+               printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt));
+               printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt),
+                      fdt_totalsize(working_fdt));
+               printf("off_dt_struct:\t\t0x%x\n",
+                      fdt_off_dt_struct(working_fdt));
+               printf("off_dt_strings:\t\t0x%x\n",
+                      fdt_off_dt_strings(working_fdt));
+               printf("off_mem_rsvmap:\t\t0x%x\n",
+                      fdt_off_mem_rsvmap(working_fdt));
+               printf("version:\t\t%d\n", version);
+               printf("last_comp_version:\t%d\n",
+                      fdt_last_comp_version(working_fdt));
+               if (version >= 2)
+                       printf("boot_cpuid_phys:\t0x%x\n",
+                               fdt_boot_cpuid_phys(working_fdt));
+               if (version >= 3)
+                       printf("size_dt_strings:\t0x%x\n",
+                               fdt_size_dt_strings(working_fdt));
+               if (version >= 17)
+                       printf("size_dt_struct:\t\t0x%x\n",
+                               fdt_size_dt_struct(working_fdt));
+               printf("number mem_rsv:\t\t0x%x\n",
+                      fdt_num_mem_rsv(working_fdt));
+               printf("\n");
+
+       /*
+        * Set boot cpu id
+        */
+       } else if (strncmp(argv[1], "boo", 3) == 0) {
+               unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
+               fdt_set_boot_cpuid_phys(working_fdt, tmp);
+
+       /*
+        * memory command
+        */
+       } else if (strncmp(argv[1], "me", 2) == 0) {
+               uint64_t addr, size;
+               int err;
+               addr = simple_strtoull(argv[2], NULL, 16);
+               size = simple_strtoull(argv[3], NULL, 16);
+               err = fdt_fixup_memory(working_fdt, addr, size);
+               if (err < 0)
+                       return err;
+
+       /*
+        * mem reserve commands
+        */
+       } else if (strncmp(argv[1], "rs", 2) == 0) {
+               if (argv[2][0] == 'p') {
+                       uint64_t addr, size;
+                       int total = fdt_num_mem_rsv(working_fdt);
+                       int j, err;
+                       printf("index\t\t   start\t\t    size\n");
+                       printf("-------------------------------"
+                               "-----------------\n");
+                       for (j = 0; j < total; j++) {
+                               err = fdt_get_mem_rsv(working_fdt, j, &addr, &size);
+                               if (err < 0) {
+                                       printf("libfdt fdt_get_mem_rsv():  %s\n",
+                                                       fdt_strerror(err));
+                                       return err;
+                               }
+                               printf("    %x\t%08x%08x\t%08x%08x\n", j,
+                                       (u32)(addr >> 32),
+                                       (u32)(addr & 0xffffffff),
+                                       (u32)(size >> 32),
+                                       (u32)(size & 0xffffffff));
+                       }
+               } else if (argv[2][0] == 'a') {
+                       uint64_t addr, size;
+                       int err;
+                       addr = simple_strtoull(argv[3], NULL, 16);
+                       size = simple_strtoull(argv[4], NULL, 16);
+                       err = fdt_add_mem_rsv(working_fdt, addr, size);
+
+                       if (err < 0) {
+                               printf("libfdt fdt_add_mem_rsv():  %s\n",
+                                       fdt_strerror(err));
+                               return err;
+                       }
+               } else if (argv[2][0] == 'd') {
+                       unsigned long idx = simple_strtoul(argv[3], NULL, 16);
+                       int err = fdt_del_mem_rsv(working_fdt, idx);
+
+                       if (err < 0) {
+                               printf("libfdt fdt_del_mem_rsv():  %s\n",
+                                       fdt_strerror(err));
+                               return err;
+                       }
+               } else {
+                       /* Unrecognized command */
+                       return CMD_RET_USAGE;
+               }
+       }
+#ifdef CONFIG_OF_BOARD_SETUP
+       /* Call the board-specific fixup routine */
+       else if (strncmp(argv[1], "boa", 3) == 0) {
+               int err = ft_board_setup(working_fdt, gd->bd);
+
+               if (err) {
+                       printf("Failed to update board information in FDT: %s\n",
+                              fdt_strerror(err));
+                       return CMD_RET_FAILURE;
+               }
+       }
+#endif
+#ifdef CONFIG_OF_SYSTEM_SETUP
+       /* Call the board-specific fixup routine */
+       else if (strncmp(argv[1], "sys", 3) == 0) {
+               int err = ft_system_setup(working_fdt, gd->bd);
+
+               if (err) {
+                       printf("Failed to add system information to FDT: %s\n",
+                              fdt_strerror(err));
+                       return CMD_RET_FAILURE;
+               }
+       }
+#endif
+       /* Create a chosen node */
+       else if (strncmp(argv[1], "cho", 3) == 0) {
+               unsigned long initrd_start = 0, initrd_end = 0;
+
+               if ((argc != 2) && (argc != 4))
+                       return CMD_RET_USAGE;
+
+               if (argc == 4) {
+                       initrd_start = simple_strtoul(argv[2], NULL, 16);
+                       initrd_end = simple_strtoul(argv[3], NULL, 16);
+               }
+
+               fdt_chosen(working_fdt);
+               fdt_initrd(working_fdt, initrd_start, initrd_end);
+
+#if defined(CONFIG_FIT_SIGNATURE)
+       } else if (strncmp(argv[1], "che", 3) == 0) {
+               int cfg_noffset;
+               int ret;
+               unsigned long addr;
+               struct fdt_header *blob;
+
+               if (!working_fdt)
+                       return CMD_RET_FAILURE;
+
+               if (argc > 2) {
+                       addr = simple_strtoul(argv[2], NULL, 16);
+                       blob = map_sysmem(addr, 0);
+               } else {
+                       blob = (struct fdt_header *)gd->fdt_blob;
+               }
+               if (!fdt_valid(&blob))
+                       return 1;
+
+               gd->fdt_blob = blob;
+               cfg_noffset = fit_conf_get_node(working_fdt, NULL);
+               if (!cfg_noffset) {
+                       printf("Could not find configuration node: %s\n",
+                              fdt_strerror(cfg_noffset));
+                       return CMD_RET_FAILURE;
+               }
+
+               ret = fit_config_verify(working_fdt, cfg_noffset);
+               if (ret == 0)
+                       return CMD_RET_SUCCESS;
+               else
+                       return CMD_RET_FAILURE;
+#endif
+
+       }
+       /* resize the fdt */
+       else if (strncmp(argv[1], "re", 2) == 0) {
+               fdt_shrink_to_minimum(working_fdt);
+       }
+       else {
+               /* Unrecognized command */
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+/****************************************************************************/
+
+/**
+ * fdt_valid() - Check if an FDT is valid. If not, change it to NULL
+ *
+ * @blobp: Pointer to FDT pointer
+ * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL)
+ */
+static int fdt_valid(struct fdt_header **blobp)
+{
+       const void *blob = *blobp;
+       int err;
+
+       if (blob == NULL) {
+               printf ("The address of the fdt is invalid (NULL).\n");
+               return 0;
+       }
+
+       err = fdt_check_header(blob);
+       if (err == 0)
+               return 1;       /* valid */
+
+       if (err < 0) {
+               printf("libfdt fdt_check_header(): %s", fdt_strerror(err));
+               /*
+                * Be more informative on bad version.
+                */
+               if (err == -FDT_ERR_BADVERSION) {
+                       if (fdt_version(blob) <
+                           FDT_FIRST_SUPPORTED_VERSION) {
+                               printf (" - too old, fdt %d < %d",
+                                       fdt_version(blob),
+                                       FDT_FIRST_SUPPORTED_VERSION);
+                       }
+                       if (fdt_last_comp_version(blob) >
+                           FDT_LAST_SUPPORTED_VERSION) {
+                               printf (" - too new, fdt %d > %d",
+                                       fdt_version(blob),
+                                       FDT_LAST_SUPPORTED_VERSION);
+                       }
+               }
+               printf("\n");
+               *blobp = NULL;
+               return 0;
+       }
+       return 1;
+}
+
+/****************************************************************************/
+
+/*
+ * Parse the user's input, partially heuristic.  Valid formats:
+ * <0x00112233 4 05>   - an array of cells.  Numbers follow standard
+ *                     C conventions.
+ * [00 11 22 .. nn] - byte stream
+ * "string"    - If the the value doesn't start with "<" or "[", it is
+ *                     treated as a string.  Note that the quotes are
+ *                     stripped by the parser before we get the string.
+ * newval: An array of strings containing the new property as specified
+ *     on the command line
+ * count: The number of strings in the array
+ * data: A bytestream to be placed in the property
+ * len: The length of the resulting bytestream
+ */
+static int fdt_parse_prop(char * const *newval, int count, char *data, int *len)
+{
+       char *cp;               /* temporary char pointer */
+       char *newp;             /* temporary newval char pointer */
+       unsigned long tmp;      /* holds converted values */
+       int stridx = 0;
+
+       *len = 0;
+       newp = newval[0];
+
+       /* An array of cells */
+       if (*newp == '<') {
+               newp++;
+               while ((*newp != '>') && (stridx < count)) {
+                       /*
+                        * Keep searching until we find that last ">"
+                        * That way users don't have to escape the spaces
+                        */
+                       if (*newp == '\0') {
+                               newp = newval[++stridx];
+                               continue;
+                       }
+
+                       cp = newp;
+                       tmp = simple_strtoul(cp, &newp, 0);
+                       *(__be32 *)data = __cpu_to_be32(tmp);
+                       data  += 4;
+                       *len += 4;
+
+                       /* If the ptr didn't advance, something went wrong */
+                       if ((newp - cp) <= 0) {
+                               printf("Sorry, I could not convert \"%s\"\n",
+                                       cp);
+                               return 1;
+                       }
+
+                       while (*newp == ' ')
+                               newp++;
+               }
+
+               if (*newp != '>') {
+                       printf("Unexpected character '%c'\n", *newp);
+                       return 1;
+               }
+       } else if (*newp == '[') {
+               /*
+                * Byte stream.  Convert the values.
+                */
+               newp++;
+               while ((stridx < count) && (*newp != ']')) {
+                       while (*newp == ' ')
+                               newp++;
+                       if (*newp == '\0') {
+                               newp = newval[++stridx];
+                               continue;
+                       }
+                       if (!isxdigit(*newp))
+                               break;
+                       tmp = simple_strtoul(newp, &newp, 16);
+                       *data++ = tmp & 0xFF;
+                       *len    = *len + 1;
+               }
+               if (*newp != ']') {
+                       printf("Unexpected character '%c'\n", *newp);
+                       return 1;
+               }
+       } else {
+               /*
+                * Assume it is one or more strings.  Copy it into our
+                * data area for convenience (including the
+                * terminating '\0's).
+                */
+               while (stridx < count) {
+                       size_t length = strlen(newp) + 1;
+                       strcpy(data, newp);
+                       data += length;
+                       *len += length;
+                       newp = newval[++stridx];
+               }
+       }
+       return 0;
+}
+
+/****************************************************************************/
+
+/*
+ * Heuristic to guess if this is a string or concatenated strings.
+ */
+
+static int is_printable_string(const void *data, int len)
+{
+       const char *s = data;
+
+       /* zero length is not */
+       if (len == 0)
+               return 0;
+
+       /* must terminate with zero or '\n' */
+       if (s[len - 1] != '\0' && s[len - 1] != '\n')
+               return 0;
+
+       /* printable or a null byte (concatenated strings) */
+       while (((*s == '\0') || isprint(*s) || isspace(*s)) && (len > 0)) {
+               /*
+                * If we see a null, there are three possibilities:
+                * 1) If len == 1, it is the end of the string, printable
+                * 2) Next character also a null, not printable.
+                * 3) Next character not a null, continue to check.
+                */
+               if (s[0] == '\0') {
+                       if (len == 1)
+                               return 1;
+                       if (s[1] == '\0')
+                               return 0;
+               }
+               s++;
+               len--;
+       }
+
+       /* Not the null termination, or not done yet: not printable */
+       if (*s != '\0' || (len != 0))
+               return 0;
+
+       return 1;
+}
+
+
+/*
+ * Print the property in the best format, a heuristic guess.  Print as
+ * a string, concatenated strings, a byte, word, double word, or (if all
+ * else fails) it is printed as a stream of bytes.
+ */
+static void print_data(const void *data, int len)
+{
+       int j;
+
+       /* no data, don't print */
+       if (len == 0)
+               return;
+
+       /*
+        * It is a string, but it may have multiple strings (embedded '\0's).
+        */
+       if (is_printable_string(data, len)) {
+               puts("\"");
+               j = 0;
+               while (j < len) {
+                       if (j > 0)
+                               puts("\", \"");
+                       puts(data);
+                       j    += strlen(data) + 1;
+                       data += strlen(data) + 1;
+               }
+               puts("\"");
+               return;
+       }
+
+       if ((len %4) == 0) {
+               if (len > CONFIG_CMD_FDT_MAX_DUMP)
+                       printf("* 0x%p [0x%08x]", data, len);
+               else {
+                       const __be32 *p;
+
+                       printf("<");
+                       for (j = 0, p = data; j < len/4; j++)
+                               printf("0x%08x%s", fdt32_to_cpu(p[j]),
+                                       j < (len/4 - 1) ? " " : "");
+                       printf(">");
+               }
+       } else { /* anything else... hexdump */
+               if (len > CONFIG_CMD_FDT_MAX_DUMP)
+                       printf("* 0x%p [0x%08x]", data, len);
+               else {
+                       const u8 *s;
+
+                       printf("[");
+                       for (j = 0, s = data; j < len; j++)
+                               printf("%02x%s", s[j], j < len - 1 ? " " : "");
+                       printf("]");
+               }
+       }
+}
+
+/****************************************************************************/
+
+/*
+ * Recursively print (a portion of) the working_fdt.  The depth parameter
+ * determines how deeply nested the fdt is printed.
+ */
+static int fdt_print(const char *pathp, char *prop, int depth)
+{
+       static char tabs[MAX_LEVEL+1] =
+               "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
+               "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
+       const void *nodep;      /* property node pointer */
+       int  nodeoffset;        /* node offset from libfdt */
+       int  nextoffset;        /* next node offset from libfdt */
+       uint32_t tag;           /* tag */
+       int  len;               /* length of the property */
+       int  level = 0;         /* keep track of nesting level */
+       const struct fdt_property *fdt_prop;
+
+       nodeoffset = fdt_path_offset (working_fdt, pathp);
+       if (nodeoffset < 0) {
+               /*
+                * Not found or something else bad happened.
+                */
+               printf ("libfdt fdt_path_offset() returned %s\n",
+                       fdt_strerror(nodeoffset));
+               return 1;
+       }
+       /*
+        * The user passed in a property as well as node path.
+        * Print only the given property and then return.
+        */
+       if (prop) {
+               nodep = fdt_getprop (working_fdt, nodeoffset, prop, &len);
+               if (len == 0) {
+                       /* no property value */
+                       printf("%s %s\n", pathp, prop);
+                       return 0;
+               } else if (len > 0) {
+                       printf("%s = ", prop);
+                       print_data (nodep, len);
+                       printf("\n");
+                       return 0;
+               } else {
+                       printf ("libfdt fdt_getprop(): %s\n",
+                               fdt_strerror(len));
+                       return 1;
+               }
+       }
+
+       /*
+        * The user passed in a node path and no property,
+        * print the node and all subnodes.
+        */
+       while(level >= 0) {
+               tag = fdt_next_tag(working_fdt, nodeoffset, &nextoffset);
+               switch(tag) {
+               case FDT_BEGIN_NODE:
+                       pathp = fdt_get_name(working_fdt, nodeoffset, NULL);
+                       if (level <= depth) {
+                               if (pathp == NULL)
+                                       pathp = "/* NULL pointer error */";
+                               if (*pathp == '\0')
+                                       pathp = "/";    /* root is nameless */
+                               printf("%s%s {\n",
+                                       &tabs[MAX_LEVEL - level], pathp);
+                       }
+                       level++;
+                       if (level >= MAX_LEVEL) {
+                               printf("Nested too deep, aborting.\n");
+                               return 1;
+                       }
+                       break;
+               case FDT_END_NODE:
+                       level--;
+                       if (level <= depth)
+                               printf("%s};\n", &tabs[MAX_LEVEL - level]);
+                       if (level == 0) {
+                               level = -1;             /* exit the loop */
+                       }
+                       break;
+               case FDT_PROP:
+                       fdt_prop = fdt_offset_ptr(working_fdt, nodeoffset,
+                                       sizeof(*fdt_prop));
+                       pathp    = fdt_string(working_fdt,
+                                       fdt32_to_cpu(fdt_prop->nameoff));
+                       len      = fdt32_to_cpu(fdt_prop->len);
+                       nodep    = fdt_prop->data;
+                       if (len < 0) {
+                               printf ("libfdt fdt_getprop(): %s\n",
+                                       fdt_strerror(len));
+                               return 1;
+                       } else if (len == 0) {
+                               /* the property has no value */
+                               if (level <= depth)
+                                       printf("%s%s;\n",
+                                               &tabs[MAX_LEVEL - level],
+                                               pathp);
+                       } else {
+                               if (level <= depth) {
+                                       printf("%s%s = ",
+                                               &tabs[MAX_LEVEL - level],
+                                               pathp);
+                                       print_data (nodep, len);
+                                       printf(";\n");
+                               }
+                       }
+                       break;
+               case FDT_NOP:
+                       printf("%s/* NOP */\n", &tabs[MAX_LEVEL - level]);
+                       break;
+               case FDT_END:
+                       return 1;
+               default:
+                       if (level <= depth)
+                               printf("Unknown tag 0x%08X\n", tag);
+                       return 1;
+               }
+               nodeoffset = nextoffset;
+       }
+       return 0;
+}
+
+/********************************************************************/
+#ifdef CONFIG_SYS_LONGHELP
+static char fdt_help_text[] =
+       "addr [-c]  <addr> [<length>]   - Set the [control] fdt location to <addr>\n"
+#ifdef CONFIG_OF_BOARD_SETUP
+       "fdt boardsetup                      - Do board-specific set up\n"
+#endif
+#ifdef CONFIG_OF_SYSTEM_SETUP
+       "fdt systemsetup                     - Do system-specific set up\n"
+#endif
+       "fdt move   <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n"
+       "fdt resize                          - Resize fdt to size + padding to 4k addr\n"
+       "fdt print  <path> [<prop>]          - Recursive print starting at <path>\n"
+       "fdt list   <path> [<prop>]          - Print one level starting at <path>\n"
+       "fdt get value <var> <path> <prop>   - Get <property> and store in <var>\n"
+       "fdt get name <var> <path> <index>   - Get name of node <index> and store in <var>\n"
+       "fdt get addr <var> <path> <prop>    - Get start address of <property> and store in <var>\n"
+       "fdt get size <var> <path> [<prop>]  - Get size of [<property>] or num nodes and store in <var>\n"
+       "fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
+       "fdt mknode <path> <node>            - Create a new node after <path>\n"
+       "fdt rm     <path> [<prop>]          - Delete the node or <property>\n"
+       "fdt header                          - Display header info\n"
+       "fdt bootcpu <id>                    - Set boot cpuid\n"
+       "fdt memory <addr> <size>            - Add/Update memory node\n"
+       "fdt rsvmem print                    - Show current mem reserves\n"
+       "fdt rsvmem add <addr> <size>        - Add a mem reserve\n"
+       "fdt rsvmem delete <index>           - Delete a mem reserves\n"
+       "fdt chosen [<start> <end>]          - Add/update the /chosen branch in the tree\n"
+       "                                        <start>/<end> - initrd start/end addr\n"
+#if defined(CONFIG_FIT_SIGNATURE)
+       "fdt checksign [<addr>]              - check FIT signature\n"
+       "                                        <start> - addr of key blob\n"
+       "                                                  default gd->fdt_blob\n"
+#endif
+       "NOTE: Dereference aliases by omiting the leading '/', "
+               "e.g. fdt print ethernet0.";
+#endif
+
+U_BOOT_CMD(
+       fdt,    255,    0,      do_fdt,
+       "flattened device tree utility commands", fdt_help_text
+);
diff --git a/cmd/fitupd.c b/cmd/fitupd.c
new file mode 100644 (file)
index 0000000..78b8747
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * (C) Copyright 2011
+ * Andreas Pretzsch, carpe noctem engineering, apr@cn-eng.de
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <net.h>
+
+#if !defined(CONFIG_UPDATE_TFTP)
+#error "CONFIG_UPDATE_TFTP required"
+#endif
+
+static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr = 0UL;
+
+       if (argc > 2)
+               return CMD_RET_USAGE;
+
+       if (argc == 2)
+               addr = simple_strtoul(argv[1], NULL, 16);
+
+       return update_tftp(addr, NULL, NULL);
+}
+
+U_BOOT_CMD(fitupd, 2, 0, do_fitupd,
+       "update from FIT image",
+       "[addr]\n"
+       "\t- run update from FIT image at addr\n"
+       "\t  or from tftp 'updatefile'"
+);
diff --git a/cmd/flash.c b/cmd/flash.c
new file mode 100644 (file)
index 0000000..85d18bb
--- /dev/null
@@ -0,0 +1,729 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * FLASH support
+ */
+#include <common.h>
+#include <command.h>
+
+#ifdef CONFIG_HAS_DATAFLASH
+#include <dataflash.h>
+#endif
+
+#if defined(CONFIG_CMD_MTDPARTS)
+#include <jffs2/jffs2.h>
+
+/* partition handling routines */
+int mtdparts_init(void);
+int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
+int find_dev_and_part(const char *id, struct mtd_device **dev,
+               u8 *part_num, struct part_info **part);
+#endif
+
+#ifndef CONFIG_SYS_NO_FLASH
+#include <flash.h>
+#include <mtd/cfi_flash.h>
+extern flash_info_t flash_info[];      /* info for FLASH chips */
+
+/*
+ * The user interface starts numbering for Flash banks with 1
+ * for historical reasons.
+ */
+
+/*
+ * this routine looks for an abbreviated flash range specification.
+ * the syntax is B:SF[-SL], where B is the bank number, SF is the first
+ * sector to erase, and SL is the last sector to erase (defaults to SF).
+ * bank numbers start at 1 to be consistent with other specs, sector numbers
+ * start at zero.
+ *
+ * returns:    1       - correct spec; *pinfo, *psf and *psl are
+ *                       set appropriately
+ *             0       - doesn't look like an abbreviated spec
+ *             -1      - looks like an abbreviated spec, but got
+ *                       a parsing error, a number out of range,
+ *                       or an invalid flash bank.
+ */
+static int
+abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
+{
+       flash_info_t *fp;
+       int bank, first, last;
+       char *p, *ep;
+
+       if ((p = strchr (str, ':')) == NULL)
+               return 0;
+       *p++ = '\0';
+
+       bank = simple_strtoul (str, &ep, 10);
+       if (ep == str || *ep != '\0' ||
+               bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS ||
+               (fp = &flash_info[bank - 1])->flash_id == FLASH_UNKNOWN)
+               return -1;
+
+       str = p;
+       if ((p = strchr (str, '-')) != NULL)
+               *p++ = '\0';
+
+       first = simple_strtoul (str, &ep, 10);
+       if (ep == str || *ep != '\0' || first >= fp->sector_count)
+               return -1;
+
+       if (p != NULL) {
+               last = simple_strtoul (p, &ep, 10);
+               if (ep == p || *ep != '\0' ||
+                       last < first || last >= fp->sector_count)
+                       return -1;
+       } else {
+               last = first;
+       }
+
+       *pinfo = fp;
+       *psf = first;
+       *psl = last;
+
+       return 1;
+}
+
+/*
+ * Take *addr in Flash and adjust it to fall on the end of its sector
+ */
+int flash_sect_roundb (ulong *addr)
+{
+       flash_info_t *info;
+       ulong bank, sector_end_addr;
+       char found;
+       int i;
+
+       /* find the end addr of the sector where the *addr is */
+       found = 0;
+       for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS && !found; ++bank) {
+               info = &flash_info[bank];
+               for (i = 0; i < info->sector_count && !found; ++i) {
+                       /* get the end address of the sector */
+                       if (i == info->sector_count - 1) {
+                               sector_end_addr = info->start[0] +
+                                                               info->size - 1;
+                       } else {
+                               sector_end_addr = info->start[i+1] - 1;
+                       }
+
+                       if (*addr <= sector_end_addr &&
+                                               *addr >= info->start[i]) {
+                               found = 1;
+                               /* adjust *addr if necessary */
+                               if (*addr < sector_end_addr)
+                                       *addr = sector_end_addr;
+                       } /* sector */
+               } /* bank */
+       }
+       if (!found) {
+               /* error, address not in flash */
+               printf("Error: end address (0x%08lx) not in flash!\n", *addr);
+               return 1;
+       }
+
+       return 0;
+}
+
+/*
+ * This function computes the start and end addresses for both
+ * erase and protect commands. The range of the addresses on which
+ * either of the commands is to operate can be given in two forms:
+ * 1. <cmd> start end - operate on <'start',  'end')
+ * 2. <cmd> start +length - operate on <'start', start + length)
+ * If the second form is used and the end address doesn't fall on the
+ * sector boundary, than it will be adjusted to the next sector boundary.
+ * If it isn't in the flash, the function will fail (return -1).
+ * Input:
+ *    arg1, arg2: address specification (i.e. both command arguments)
+ * Output:
+ *    addr_first, addr_last: computed address range
+ * Return:
+ *    1: success
+ *   -1: failure (bad format, bad address).
+*/
+static int
+addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
+{
+       char *ep;
+       char len_used; /* indicates if the "start +length" form used */
+
+       *addr_first = simple_strtoul(arg1, &ep, 16);
+       if (ep == arg1 || *ep != '\0')
+               return -1;
+
+       len_used = 0;
+       if (arg2 && *arg2 == '+'){
+               len_used = 1;
+               ++arg2;
+       }
+
+       *addr_last = simple_strtoul(arg2, &ep, 16);
+       if (ep == arg2 || *ep != '\0')
+               return -1;
+
+       if (len_used){
+               /*
+                * *addr_last has the length, compute correct *addr_last
+                * XXX watch out for the integer overflow! Right now it is
+                * checked for in both the callers.
+                */
+               *addr_last = *addr_first + *addr_last - 1;
+
+               /*
+                * It may happen that *addr_last doesn't fall on the sector
+                * boundary. We want to round such an address to the next
+                * sector boundary, so that the commands don't fail later on.
+                */
+
+               if (flash_sect_roundb(addr_last) > 0)
+                       return -1;
+       } /* "start +length" from used */
+
+       return 1;
+}
+
+static int
+flash_fill_sect_ranges (ulong addr_first, ulong addr_last,
+                       int *s_first, int *s_last,
+                       int *s_count )
+{
+       flash_info_t *info;
+       ulong bank;
+       int rcode = 0;
+
+       *s_count = 0;
+
+       for (bank=0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+               s_first[bank] = -1;     /* first sector to erase        */
+               s_last [bank] = -1;     /* last  sector to erase        */
+       }
+
+       for (bank=0,info = &flash_info[0];
+            (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (addr_first <= addr_last);
+            ++bank, ++info) {
+               ulong b_end;
+               int sect;
+               short s_end;
+
+               if (info->flash_id == FLASH_UNKNOWN) {
+                       continue;
+               }
+
+               b_end = info->start[0] + info->size - 1;        /* bank end addr */
+               s_end = info->sector_count - 1;                 /* last sector   */
+
+
+               for (sect=0; sect < info->sector_count; ++sect) {
+                       ulong end;      /* last address in current sect */
+
+                       end = (sect == s_end) ? b_end : info->start[sect + 1] - 1;
+
+                       if (addr_first > end)
+                               continue;
+                       if (addr_last < info->start[sect])
+                               continue;
+
+                       if (addr_first == info->start[sect]) {
+                               s_first[bank] = sect;
+                       }
+                       if (addr_last  == end) {
+                               s_last[bank]  = sect;
+                       }
+               }
+               if (s_first[bank] >= 0) {
+                       if (s_last[bank] < 0) {
+                               if (addr_last > b_end) {
+                                       s_last[bank] = s_end;
+                               } else {
+                                       puts ("Error: end address"
+                                               " not on sector boundary\n");
+                                       rcode = 1;
+                                       break;
+                               }
+                       }
+                       if (s_last[bank] < s_first[bank]) {
+                               puts ("Error: end sector"
+                                       " precedes start sector\n");
+                               rcode = 1;
+                               break;
+                       }
+                       sect = s_last[bank];
+                       addr_first = (sect == s_end) ? b_end + 1: info->start[sect + 1];
+                       (*s_count) += s_last[bank] - s_first[bank] + 1;
+               } else if (addr_first >= info->start[0] && addr_first < b_end) {
+                       puts ("Error: start address not on sector boundary\n");
+                       rcode = 1;
+                       break;
+               } else if (s_last[bank] >= 0) {
+                       puts ("Error: cannot span across banks when they are"
+                              " mapped in reverse order\n");
+                       rcode = 1;
+                       break;
+               }
+       }
+
+       return rcode;
+}
+#endif /* CONFIG_SYS_NO_FLASH */
+
+static int do_flinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+#ifndef CONFIG_SYS_NO_FLASH
+       ulong bank;
+#endif
+
+#ifdef CONFIG_HAS_DATAFLASH
+       dataflash_print_info();
+#endif
+
+#ifndef CONFIG_SYS_NO_FLASH
+       if (argc == 1) {        /* print info for all FLASH banks */
+               for (bank=0; bank <CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+                       printf ("\nBank # %ld: ", bank+1);
+
+                       flash_print_info (&flash_info[bank]);
+               }
+               return 0;
+       }
+
+       bank = simple_strtoul(argv[1], NULL, 16);
+       if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
+               printf ("Only FLASH Banks # 1 ... # %d supported\n",
+                       CONFIG_SYS_MAX_FLASH_BANKS);
+               return 1;
+       }
+       printf ("\nBank # %ld: ", bank);
+       flash_print_info (&flash_info[bank-1]);
+#endif /* CONFIG_SYS_NO_FLASH */
+       return 0;
+}
+
+static int do_flerase(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+#ifndef CONFIG_SYS_NO_FLASH
+       flash_info_t *info = NULL;
+       ulong bank, addr_first, addr_last;
+       int n, sect_first = 0, sect_last = 0;
+#if defined(CONFIG_CMD_MTDPARTS)
+       struct mtd_device *dev;
+       struct part_info *part;
+       u8 dev_type, dev_num, pnum;
+#endif
+       int rcode = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[1], "all") == 0) {
+               for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+                       printf ("Erase Flash Bank # %ld ", bank);
+                       info = &flash_info[bank-1];
+                       rcode = flash_erase (info, 0, info->sector_count-1);
+               }
+               return rcode;
+       }
+
+       if ((n = abbrev_spec(argv[1], &info, &sect_first, &sect_last)) != 0) {
+               if (n < 0) {
+                       puts ("Bad sector specification\n");
+                       return 1;
+               }
+               printf ("Erase Flash Sectors %d-%d in Bank # %zu ",
+                       sect_first, sect_last, (info-flash_info)+1);
+               rcode = flash_erase(info, sect_first, sect_last);
+               return rcode;
+       }
+
+#if defined(CONFIG_CMD_MTDPARTS)
+       /* erase <part-id> - erase partition */
+       if ((argc == 2) && (mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) {
+               mtdparts_init();
+               if (find_dev_and_part(argv[1], &dev, &pnum, &part) == 0) {
+                       if (dev->id->type == MTD_DEV_TYPE_NOR) {
+                               bank = dev->id->num;
+                               info = &flash_info[bank];
+                               addr_first = part->offset + info->start[0];
+                               addr_last = addr_first + part->size - 1;
+
+                               printf ("Erase Flash Partition %s, "
+                                               "bank %ld, 0x%08lx - 0x%08lx ",
+                                               argv[1], bank, addr_first,
+                                               addr_last);
+
+                               rcode = flash_sect_erase(addr_first, addr_last);
+                               return rcode;
+                       }
+
+                       printf("cannot erase, not a NOR device\n");
+                       return 1;
+               }
+       }
+#endif
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[1], "bank") == 0) {
+               bank = simple_strtoul(argv[2], NULL, 16);
+               if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
+                       printf ("Only FLASH Banks # 1 ... # %d supported\n",
+                               CONFIG_SYS_MAX_FLASH_BANKS);
+                       return 1;
+               }
+               printf ("Erase Flash Bank # %ld ", bank);
+               info = &flash_info[bank-1];
+               rcode = flash_erase (info, 0, info->sector_count-1);
+               return rcode;
+       }
+
+       if (addr_spec(argv[1], argv[2], &addr_first, &addr_last) < 0){
+               printf ("Bad address format\n");
+               return 1;
+       }
+
+       if (addr_first >= addr_last)
+               return CMD_RET_USAGE;
+
+       rcode = flash_sect_erase(addr_first, addr_last);
+       return rcode;
+#else
+       return 0;
+#endif /* CONFIG_SYS_NO_FLASH */
+}
+
+#ifndef CONFIG_SYS_NO_FLASH
+int flash_sect_erase (ulong addr_first, ulong addr_last)
+{
+       flash_info_t *info;
+       ulong bank;
+       int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS];
+       int erased = 0;
+       int planned;
+       int rcode = 0;
+
+       rcode = flash_fill_sect_ranges (addr_first, addr_last,
+                                       s_first, s_last, &planned );
+
+       if (planned && (rcode == 0)) {
+               for (bank=0,info = &flash_info[0];
+                    (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (rcode == 0);
+                    ++bank, ++info) {
+                       if (s_first[bank]>=0) {
+                               erased += s_last[bank] - s_first[bank] + 1;
+                               debug ("Erase Flash from 0x%08lx to 0x%08lx "
+                                       "in Bank # %ld ",
+                                       info->start[s_first[bank]],
+                                       (s_last[bank] == info->sector_count) ?
+                                               info->start[0] + info->size - 1:
+                                               info->start[s_last[bank]+1] - 1,
+                                       bank+1);
+                               rcode = flash_erase (info, s_first[bank], s_last[bank]);
+                       }
+               }
+               if (rcode == 0)
+                       printf("Erased %d sectors\n", erased);
+       } else if (rcode == 0) {
+               puts ("Error: start and/or end address"
+                       " not on sector boundary\n");
+               rcode = 1;
+       }
+       return rcode;
+}
+#endif /* CONFIG_SYS_NO_FLASH */
+
+static int do_protect(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int rcode = 0;
+#ifndef CONFIG_SYS_NO_FLASH
+       flash_info_t *info = NULL;
+       ulong bank;
+       int i, n, sect_first = 0, sect_last = 0;
+#if defined(CONFIG_CMD_MTDPARTS)
+       struct mtd_device *dev;
+       struct part_info *part;
+       u8 dev_type, dev_num, pnum;
+#endif
+#endif /* CONFIG_SYS_NO_FLASH */
+#ifdef CONFIG_HAS_DATAFLASH
+       int status;
+#endif
+#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
+       int p;
+       ulong addr_first, addr_last;
+#endif
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
+       if (strcmp(argv[1], "off") == 0)
+               p = 0;
+       else if (strcmp(argv[1], "on") == 0)
+               p = 1;
+       else
+               return CMD_RET_USAGE;
+#endif
+
+#ifdef CONFIG_HAS_DATAFLASH
+       if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) {
+               addr_first = simple_strtoul(argv[2], NULL, 16);
+               addr_last  = simple_strtoul(argv[3], NULL, 16);
+
+               if (addr_dataflash(addr_first) && addr_dataflash(addr_last)) {
+                       status = dataflash_real_protect(p,addr_first,addr_last);
+                       if (status < 0){
+                               puts ("Bad DataFlash sector specification\n");
+                               return 1;
+                       }
+                       printf("%sProtect %d DataFlash Sectors\n",
+                               p ? "" : "Un-", status);
+                       return 0;
+               }
+       }
+#endif
+
+#ifndef CONFIG_SYS_NO_FLASH
+       if (strcmp(argv[2], "all") == 0) {
+               for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+                       info = &flash_info[bank-1];
+                       if (info->flash_id == FLASH_UNKNOWN) {
+                               continue;
+                       }
+                       printf ("%sProtect Flash Bank # %ld\n",
+                               p ? "" : "Un-", bank);
+
+                       for (i=0; i<info->sector_count; ++i) {
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+                               if (flash_real_protect(info, i, p))
+                                       rcode = 1;
+                               putc ('.');
+#else
+                               info->protect[i] = p;
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+                       }
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+                       if (!rcode) puts (" done\n");
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+               }
+               return rcode;
+       }
+
+       if ((n = abbrev_spec(argv[2], &info, &sect_first, &sect_last)) != 0) {
+               if (n < 0) {
+                       puts ("Bad sector specification\n");
+                       return 1;
+               }
+               printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n",
+                       p ? "" : "Un-", sect_first, sect_last,
+                       (info-flash_info)+1);
+               for (i = sect_first; i <= sect_last; i++) {
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+                       if (flash_real_protect(info, i, p))
+                               rcode =  1;
+                       putc ('.');
+#else
+                       info->protect[i] = p;
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+               }
+
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+               if (!rcode) puts (" done\n");
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+
+               return rcode;
+       }
+
+#if defined(CONFIG_CMD_MTDPARTS)
+       /* protect on/off <part-id> */
+       if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
+               mtdparts_init();
+               if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) {
+                       if (dev->id->type == MTD_DEV_TYPE_NOR) {
+                               bank = dev->id->num;
+                               info = &flash_info[bank];
+                               addr_first = part->offset + info->start[0];
+                               addr_last = addr_first + part->size - 1;
+
+                               printf ("%sProtect Flash Partition %s, "
+                                               "bank %ld, 0x%08lx - 0x%08lx\n",
+                                               p ? "" : "Un", argv[1],
+                                               bank, addr_first, addr_last);
+
+                               rcode = flash_sect_protect (p, addr_first, addr_last);
+                               return rcode;
+                       }
+
+                       printf("cannot %sprotect, not a NOR device\n",
+                                       p ? "" : "un");
+                       return 1;
+               }
+       }
+#endif
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[2], "bank") == 0) {
+               bank = simple_strtoul(argv[3], NULL, 16);
+               if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
+                       printf ("Only FLASH Banks # 1 ... # %d supported\n",
+                               CONFIG_SYS_MAX_FLASH_BANKS);
+                       return 1;
+               }
+               printf ("%sProtect Flash Bank # %ld\n",
+                       p ? "" : "Un-", bank);
+               info = &flash_info[bank-1];
+
+               if (info->flash_id == FLASH_UNKNOWN) {
+                       puts ("missing or unknown FLASH type\n");
+                       return 1;
+               }
+               for (i=0; i<info->sector_count; ++i) {
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+                       if (flash_real_protect(info, i, p))
+                               rcode =  1;
+                       putc ('.');
+#else
+                       info->protect[i] = p;
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+               }
+
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+               if (!rcode) puts (" done\n");
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+
+               return rcode;
+       }
+
+       if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){
+               printf("Bad address format\n");
+               return 1;
+       }
+
+       if (addr_first >= addr_last)
+               return CMD_RET_USAGE;
+
+       rcode = flash_sect_protect (p, addr_first, addr_last);
+#endif /* CONFIG_SYS_NO_FLASH */
+       return rcode;
+}
+
+#ifndef CONFIG_SYS_NO_FLASH
+int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
+{
+       flash_info_t *info;
+       ulong bank;
+       int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS];
+       int protected, i;
+       int planned;
+       int rcode;
+
+       rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned );
+
+       protected = 0;
+
+       if (planned && (rcode == 0)) {
+               for (bank=0,info = &flash_info[0]; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) {
+                       if (info->flash_id == FLASH_UNKNOWN) {
+                               continue;
+                       }
+
+                       if (s_first[bank]>=0 && s_first[bank]<=s_last[bank]) {
+                               debug ("%sProtecting sectors %d..%d in bank %ld\n",
+                                       p ? "" : "Un-",
+                                       s_first[bank], s_last[bank], bank+1);
+                               protected += s_last[bank] - s_first[bank] + 1;
+                               for (i=s_first[bank]; i<=s_last[bank]; ++i) {
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+                                       if (flash_real_protect(info, i, p))
+                                               rcode = 1;
+                                       putc ('.');
+#else
+                                       info->protect[i] = p;
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+                               }
+                       }
+               }
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
+               puts (" done\n");
+#endif /* CONFIG_SYS_FLASH_PROTECTION */
+
+               printf ("%sProtected %d sectors\n",
+                       p ? "" : "Un-", protected);
+       } else if (rcode == 0) {
+               puts ("Error: start and/or end address"
+                       " not on sector boundary\n");
+               rcode = 1;
+       }
+       return rcode;
+}
+#endif /* CONFIG_SYS_NO_FLASH */
+
+
+/**************************************************/
+#if defined(CONFIG_CMD_MTDPARTS)
+# define TMP_ERASE     "erase <part-id>\n    - erase partition\n"
+# define TMP_PROT_ON   "protect on <part-id>\n    - protect partition\n"
+# define TMP_PROT_OFF  "protect off <part-id>\n    - make partition writable\n"
+#else
+# define TMP_ERASE     /* empty */
+# define TMP_PROT_ON   /* empty */
+# define TMP_PROT_OFF  /* empty */
+#endif
+
+U_BOOT_CMD(
+       flinfo,    2,    1,    do_flinfo,
+       "print FLASH memory information",
+       "\n    - print information for all FLASH memory banks\n"
+       "flinfo N\n    - print information for FLASH memory bank # N"
+);
+
+U_BOOT_CMD(
+       erase,   3,   0,  do_flerase,
+       "erase FLASH memory",
+       "start end\n"
+       "    - erase FLASH from addr 'start' to addr 'end'\n"
+       "erase start +len\n"
+       "    - erase FLASH from addr 'start' to the end of sect "
+       "w/addr 'start'+'len'-1\n"
+       "erase N:SF[-SL]\n    - erase sectors SF-SL in FLASH bank # N\n"
+       "erase bank N\n    - erase FLASH bank # N\n"
+       TMP_ERASE
+       "erase all\n    - erase all FLASH banks"
+);
+
+U_BOOT_CMD(
+       protect,  4,  0,   do_protect,
+       "enable or disable FLASH write protection",
+       "on  start end\n"
+       "    - protect FLASH from addr 'start' to addr 'end'\n"
+       "protect on start +len\n"
+       "    - protect FLASH from addr 'start' to end of sect "
+       "w/addr 'start'+'len'-1\n"
+       "protect on  N:SF[-SL]\n"
+       "    - protect sectors SF-SL in FLASH bank # N\n"
+       "protect on  bank N\n    - protect FLASH bank # N\n"
+       TMP_PROT_ON
+       "protect on  all\n    - protect all FLASH banks\n"
+       "protect off start end\n"
+       "    - make FLASH from addr 'start' to addr 'end' writable\n"
+       "protect off start +len\n"
+       "    - make FLASH from addr 'start' to end of sect "
+       "w/addr 'start'+'len'-1 wrtable\n"
+       "protect off N:SF[-SL]\n"
+       "    - make sectors SF-SL writable in FLASH bank # N\n"
+       "protect off bank N\n    - make FLASH bank # N writable\n"
+       TMP_PROT_OFF
+       "protect off all\n    - make all FLASH banks writable"
+);
+
+#undef TMP_ERASE
+#undef TMP_PROT_ON
+#undef TMP_PROT_OFF
diff --git a/cmd/fpga.c b/cmd/fpga.c
new file mode 100644 (file)
index 0000000..7f99aab
--- /dev/null
@@ -0,0 +1,376 @@
+/*
+ * (C) Copyright 2000, 2001
+ * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ *  FPGA support
+ */
+#include <common.h>
+#include <command.h>
+#include <fpga.h>
+#include <fs.h>
+#include <malloc.h>
+
+/* Local functions */
+static int fpga_get_op(char *opstr);
+
+/* Local defines */
+#define FPGA_NONE   -1
+#define FPGA_INFO   0
+#define FPGA_LOAD   1
+#define FPGA_LOADB  2
+#define FPGA_DUMP   3
+#define FPGA_LOADMK 4
+#define FPGA_LOADP  5
+#define FPGA_LOADBP 6
+#define FPGA_LOADFS 7
+
+/* ------------------------------------------------------------------------- */
+/* command form:
+ *   fpga <op> <device number> <data addr> <datasize>
+ * where op is 'load', 'dump', or 'info'
+ * If there is no device number field, the fpga environment variable is used.
+ * If there is no data addr field, the fpgadata environment variable is used.
+ * The info command requires no data address field.
+ */
+int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int op, dev = FPGA_INVALID_DEVICE;
+       size_t data_size = 0;
+       void *fpga_data = NULL;
+       char *devstr = getenv("fpga");
+       char *datastr = getenv("fpgadata");
+       int rc = FPGA_FAIL;
+       int wrong_parms = 0;
+#if defined(CONFIG_FIT)
+       const char *fit_uname = NULL;
+       ulong fit_addr;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+       fpga_fs_info fpga_fsinfo;
+       fpga_fsinfo.fstype = FS_TYPE_ANY;
+#endif
+
+       if (devstr)
+               dev = (int) simple_strtoul(devstr, NULL, 16);
+       if (datastr)
+               fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
+
+       switch (argc) {
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+       case 9:
+               fpga_fsinfo.blocksize = (unsigned int)
+                                            simple_strtoul(argv[5], NULL, 16);
+               fpga_fsinfo.interface = argv[6];
+               fpga_fsinfo.dev_part = argv[7];
+               fpga_fsinfo.filename = argv[8];
+#endif
+       case 5:         /* fpga <op> <dev> <data> <datasize> */
+               data_size = simple_strtoul(argv[4], NULL, 16);
+
+       case 4:         /* fpga <op> <dev> <data> */
+#if defined(CONFIG_FIT)
+               if (fit_parse_subimage(argv[3], (ulong)fpga_data,
+                                      &fit_addr, &fit_uname)) {
+                       fpga_data = (void *)fit_addr;
+                       debug("*  fpga: subimage '%s' from FIT image ",
+                             fit_uname);
+                       debug("at 0x%08lx\n", fit_addr);
+               } else
+#endif
+               {
+                       fpga_data = (void *)simple_strtoul(argv[3], NULL, 16);
+                       debug("*  fpga: cmdline image address = 0x%08lx\n",
+                             (ulong)fpga_data);
+               }
+               debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data);
+
+       case 3:         /* fpga <op> <dev | data addr> */
+               dev = (int)simple_strtoul(argv[2], NULL, 16);
+               debug("%s: device = %d\n", __func__, dev);
+               /* FIXME - this is a really weak test */
+               if ((argc == 3) && (dev > fpga_count())) {
+                       /* must be buffer ptr */
+                       debug("%s: Assuming buffer pointer in arg 3\n",
+                             __func__);
+
+#if defined(CONFIG_FIT)
+                       if (fit_parse_subimage(argv[2], (ulong)fpga_data,
+                                              &fit_addr, &fit_uname)) {
+                               fpga_data = (void *)fit_addr;
+                               debug("*  fpga: subimage '%s' from FIT image ",
+                                     fit_uname);
+                               debug("at 0x%08lx\n", fit_addr);
+                       } else
+#endif
+                       {
+                               fpga_data = (void *)dev;
+                               debug("*  fpga: cmdline image addr = 0x%08lx\n",
+                                     (ulong)fpga_data);
+                       }
+
+                       debug("%s: fpga_data = 0x%x\n",
+                             __func__, (uint)fpga_data);
+                       dev = FPGA_INVALID_DEVICE;      /* reset device num */
+               }
+
+       case 2:         /* fpga <op> */
+               op = (int)fpga_get_op(argv[1]);
+               break;
+
+       default:
+               debug("%s: Too many or too few args (%d)\n", __func__, argc);
+               op = FPGA_NONE; /* force usage display */
+               break;
+       }
+
+       if (dev == FPGA_INVALID_DEVICE) {
+               puts("FPGA device not specified\n");
+               op = FPGA_NONE;
+       }
+
+       switch (op) {
+       case FPGA_NONE:
+       case FPGA_INFO:
+               break;
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+       case FPGA_LOADFS:
+               /* Blocksize can be zero */
+               if (!fpga_fsinfo.interface || !fpga_fsinfo.dev_part ||
+                   !fpga_fsinfo.filename)
+                       wrong_parms = 1;
+#endif
+       case FPGA_LOAD:
+       case FPGA_LOADP:
+       case FPGA_LOADB:
+       case FPGA_LOADBP:
+       case FPGA_DUMP:
+               if (!fpga_data || !data_size)
+                       wrong_parms = 1;
+               break;
+#if defined(CONFIG_CMD_FPGA_LOADMK)
+       case FPGA_LOADMK:
+               if (!fpga_data)
+                       wrong_parms = 1;
+               break;
+#endif
+       }
+
+       if (wrong_parms) {
+               puts("Wrong parameters for FPGA request\n");
+               op = FPGA_NONE;
+       }
+
+       switch (op) {
+       case FPGA_NONE:
+               return CMD_RET_USAGE;
+
+       case FPGA_INFO:
+               rc = fpga_info(dev);
+               break;
+
+       case FPGA_LOAD:
+               rc = fpga_load(dev, fpga_data, data_size, BIT_FULL);
+               break;
+
+#if defined(CONFIG_CMD_FPGA_LOADP)
+       case FPGA_LOADP:
+               rc = fpga_load(dev, fpga_data, data_size, BIT_PARTIAL);
+               break;
+#endif
+
+       case FPGA_LOADB:
+               rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_FULL);
+               break;
+
+#if defined(CONFIG_CMD_FPGA_LOADBP)
+       case FPGA_LOADBP:
+               rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_PARTIAL);
+               break;
+#endif
+
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+       case FPGA_LOADFS:
+               rc = fpga_fsload(dev, fpga_data, data_size, &fpga_fsinfo);
+               break;
+#endif
+
+#if defined(CONFIG_CMD_FPGA_LOADMK)
+       case FPGA_LOADMK:
+               switch (genimg_get_format(fpga_data)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+               case IMAGE_FORMAT_LEGACY:
+                       {
+                               image_header_t *hdr =
+                                               (image_header_t *)fpga_data;
+                               ulong data;
+                               uint8_t comp;
+
+                               comp = image_get_comp(hdr);
+                               if (comp == IH_COMP_GZIP) {
+#if defined(CONFIG_GZIP)
+                                       ulong image_buf = image_get_data(hdr);
+                                       data = image_get_load(hdr);
+                                       ulong image_size = ~0UL;
+
+                                       if (gunzip((void *)data, ~0UL,
+                                                  (void *)image_buf,
+                                                  &image_size) != 0) {
+                                               puts("GUNZIP: error\n");
+                                               return 1;
+                                       }
+                                       data_size = image_size;
+#else
+                                       puts("Gunzip image is not supported\n");
+                                       return 1;
+#endif
+                               } else {
+                                       data = (ulong)image_get_data(hdr);
+                                       data_size = image_get_data_size(hdr);
+                               }
+                               rc = fpga_load(dev, (void *)data, data_size,
+                                              BIT_FULL);
+                       }
+                       break;
+#endif
+#if defined(CONFIG_FIT)
+               case IMAGE_FORMAT_FIT:
+                       {
+                               const void *fit_hdr = (const void *)fpga_data;
+                               int noffset;
+                               const void *fit_data;
+
+                               if (fit_uname == NULL) {
+                                       puts("No FIT subimage unit name\n");
+                                       return 1;
+                               }
+
+                               if (!fit_check_format(fit_hdr)) {
+                                       puts("Bad FIT image format\n");
+                                       return 1;
+                               }
+
+                               /* get fpga component image node offset */
+                               noffset = fit_image_get_node(fit_hdr,
+                                                            fit_uname);
+                               if (noffset < 0) {
+                                       printf("Can't find '%s' FIT subimage\n",
+                                              fit_uname);
+                                       return 1;
+                               }
+
+                               /* verify integrity */
+                               if (!fit_image_verify(fit_hdr, noffset)) {
+                                       puts ("Bad Data Hash\n");
+                                       return 1;
+                               }
+
+                               /* get fpga subimage data address and length */
+                               if (fit_image_get_data(fit_hdr, noffset,
+                                                      &fit_data, &data_size)) {
+                                       puts("Fpga subimage data not found\n");
+                                       return 1;
+                               }
+
+                               rc = fpga_load(dev, fit_data, data_size,
+                                              BIT_FULL);
+                       }
+                       break;
+#endif
+               default:
+                       puts("** Unknown image type\n");
+                       rc = FPGA_FAIL;
+                       break;
+               }
+               break;
+#endif
+
+       case FPGA_DUMP:
+               rc = fpga_dump(dev, fpga_data, data_size);
+               break;
+
+       default:
+               printf("Unknown operation\n");
+               return CMD_RET_USAGE;
+       }
+       return rc;
+}
+
+/*
+ * Map op to supported operations.  We don't use a table since we
+ * would just have to relocate it from flash anyway.
+ */
+static int fpga_get_op(char *opstr)
+{
+       int op = FPGA_NONE;
+
+       if (!strcmp("info", opstr))
+               op = FPGA_INFO;
+       else if (!strcmp("loadb", opstr))
+               op = FPGA_LOADB;
+       else if (!strcmp("load", opstr))
+               op = FPGA_LOAD;
+#if defined(CONFIG_CMD_FPGA_LOADP)
+       else if (!strcmp("loadp", opstr))
+               op = FPGA_LOADP;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADBP)
+       else if (!strcmp("loadbp", opstr))
+               op = FPGA_LOADBP;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+       else if (!strcmp("loadfs", opstr))
+               op = FPGA_LOADFS;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADMK)
+       else if (!strcmp("loadmk", opstr))
+               op = FPGA_LOADMK;
+#endif
+       else if (!strcmp("dump", opstr))
+               op = FPGA_DUMP;
+
+       if (op == FPGA_NONE)
+               printf("Unknown fpga operation \"%s\"\n", opstr);
+
+       return op;
+}
+
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+U_BOOT_CMD(fpga, 9, 1, do_fpga,
+#else
+U_BOOT_CMD(fpga, 6, 1, do_fpga,
+#endif
+          "loadable FPGA image support",
+          "[operation type] [device number] [image address] [image size]\n"
+          "fpga operations:\n"
+          "  dump\t[dev] [address] [size]\tLoad device to memory buffer\n"
+          "  info\t[dev]\t\t\tlist known device information\n"
+          "  load\t[dev] [address] [size]\tLoad device from memory buffer\n"
+#if defined(CONFIG_CMD_FPGA_LOADP)
+          "  loadp\t[dev] [address] [size]\t"
+          "Load device from memory buffer with partial bitstream\n"
+#endif
+          "  loadb\t[dev] [address] [size]\t"
+          "Load device from bitstream buffer (Xilinx only)\n"
+#if defined(CONFIG_CMD_FPGA_LOADBP)
+          "  loadbp\t[dev] [address] [size]\t"
+          "Load device from bitstream buffer with partial bitstream"
+          "(Xilinx only)\n"
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADFS)
+          "Load device from filesystem (FAT by default) (Xilinx only)\n"
+          "  loadfs [dev] [address] [image size] [blocksize] <interface>\n"
+          "        [<dev[:part]>] <filename>\n"
+#endif
+#if defined(CONFIG_CMD_FPGA_LOADMK)
+          "  loadmk [dev] [address]\tLoad device generated with mkimage"
+#if defined(CONFIG_FIT)
+          "\n"
+          "\tFor loadmk operating on FIT format uImage address must include\n"
+          "\tsubimage unit name in the form of addr:<subimg_uname>"
+#endif
+#endif
+);
diff --git a/cmd/fpgad.c b/cmd/fpgad.c
new file mode 100644 (file)
index 0000000..5370c3e
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * (C) Copyright 2013
+ * Dirk Eibach,  Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
+ *
+ * based on cmd_mem.c
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+
+#include <gdsys_fpga.h>
+
+static uint    dp_last_fpga;
+static uint    dp_last_addr;
+static uint    dp_last_length = 0x40;
+
+/*
+ * FPGA Memory Display
+ *
+ * Syntax:
+ *     fpgad {fpga} {addr} {len}
+ */
+#define DISP_LINE_LEN  16
+int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int k;
+       unsigned int fpga;
+       ulong   addr, length;
+       int rc = 0;
+       u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
+       ulong nbytes;
+
+       /*
+        * We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       fpga = dp_last_fpga;
+       addr = dp_last_addr;
+       length = dp_last_length;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /*
+                * FPGA is specified since argc > 2
+                */
+               fpga = simple_strtoul(argv[1], NULL, 16);
+
+               /*
+                * Address is specified since argc > 2
+                */
+               addr = simple_strtoul(argv[2], NULL, 16);
+
+               /*
+                * If another parameter, it is the length to display.
+                * Length is the number of objects, not number of bytes.
+                */
+               if (argc > 3)
+                       length = simple_strtoul(argv[3], NULL, 16);
+       }
+
+       nbytes = length * sizeof(u16);
+       do {
+               ulong linebytes = (nbytes > DISP_LINE_LEN) ?
+                                 DISP_LINE_LEN : nbytes;
+
+               for (k = 0; k < linebytes / sizeof(u16); ++k)
+                       fpga_get_reg(fpga,
+                                    (u16 *)fpga_ptr[fpga] + addr
+                                    / sizeof(u16) + k,
+                                    addr + k * sizeof(u16),
+                                    &linebuf[k]);
+               print_buffer(addr, (void *)linebuf, sizeof(u16),
+                            linebytes / sizeof(u16),
+                            DISP_LINE_LEN / sizeof(u16));
+
+               nbytes -= linebytes;
+               addr += linebytes;
+               if (ctrlc()) {
+                       rc = 1;
+                       break;
+               }
+       } while (nbytes > 0);
+
+       dp_last_fpga = fpga;
+       dp_last_addr = addr;
+       dp_last_length = length;
+       return rc;
+}
+
+U_BOOT_CMD(
+       fpgad,  4,      1,      do_fpga_md,
+       "fpga register display",
+       "fpga address [# of objects]"
+);
diff --git a/cmd/fs.c b/cmd/fs.c
new file mode 100644 (file)
index 0000000..8f8f1b2
--- /dev/null
+++ b/cmd/fs.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * Inspired by cmd_ext_common.c, cmd_fat.c.
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+
+static int do_size_wrapper(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return do_size(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+       size,   4,      0,      do_size_wrapper,
+       "determine a file's size",
+       "<interface> <dev[:part]> <filename>\n"
+       "    - Find file 'filename' from 'dev' on 'interface'\n"
+       "      and determine its size."
+);
+
+static int do_load_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       return do_load(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+       load,   7,      0,      do_load_wrapper,
+       "load binary file from a filesystem",
+       "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
+       "    - Load binary file 'filename' from partition 'part' on device\n"
+       "       type 'interface' instance 'dev' to address 'addr' in memory.\n"
+       "      'bytes' gives the size to load in bytes.\n"
+       "      If 'bytes' is 0 or omitted, the file is read until the end.\n"
+       "      'pos' gives the file byte position to start reading from.\n"
+       "      If 'pos' is 0 or omitted, the file is read from the start."
+)
+
+static int do_save_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       return do_save(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+       save,   7,      0,      do_save_wrapper,
+       "save file to a filesystem",
+       "<interface> <dev[:part]> <addr> <filename> bytes [pos]\n"
+       "    - Save binary file 'filename' to partition 'part' on device\n"
+       "      type 'interface' instance 'dev' from addr 'addr' in memory.\n"
+       "      'bytes' gives the size to save in bytes and is mandatory.\n"
+       "      'pos' gives the file byte position to start writing to.\n"
+       "      If 'pos' is 0 or omitted, the file is written from the start."
+)
+
+static int do_ls_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+       ls,     4,      1,      do_ls_wrapper,
+       "list files in a directory (default /)",
+       "<interface> [<dev[:part]> [directory]]\n"
+       "    - List files in directory 'directory' of partition 'part' on\n"
+       "      device type 'interface' instance 'dev'."
+)
+
+static int do_fstype_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       return do_fs_type(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+       fstype, 4, 1, do_fstype_wrapper,
+       "Look up a filesystem type",
+       "<interface> <dev>:<part>\n"
+       "- print filesystem type\n"
+       "fstype <interface> <dev>:<part> <varname>\n"
+       "- set environment variable to filesystem type\n"
+);
diff --git a/cmd/fs_uuid.c b/cmd/fs_uuid.c
new file mode 100644 (file)
index 0000000..613f3a4
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * cmd_fs_uuid.c -- fsuuid command
+ *
+ * Copyright (C) 2014, Bachmann electronic GmbH
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+
+static int do_fs_uuid_wrapper(cmd_tbl_t *cmdtp, int flag,
+       int argc, char * const argv[])
+{
+       return do_fs_uuid(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+       fsuuid, 4, 1, do_fs_uuid_wrapper,
+       "Look up a filesystem UUID",
+       "<interface> <dev>:<part>\n"
+       "    - print filesystem UUID\n"
+       "fsuuid <interface> <dev>:<part> <varname>\n"
+       "    - set environment variable to filesystem UUID\n"
+);
diff --git a/cmd/fuse.c b/cmd/fuse.c
new file mode 100644 (file)
index 0000000..5998f9b
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * (C) Copyright 2009-2013 ADVANSEE
+ * Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
+ *
+ * Based on the mpc512x iim code:
+ * Copyright 2008 Silicon Turnkey Express, Inc.
+ * Martha Marx <mmarx@silicontkx.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <fuse.h>
+#include <asm/errno.h>
+
+static int strtou32(const char *str, unsigned int base, u32 *result)
+{
+       char *ep;
+
+       *result = simple_strtoul(str, &ep, base);
+       if (ep == str || *ep != '\0')
+               return -EINVAL;
+
+       return 0;
+}
+
+static int confirm_prog(void)
+{
+       puts("Warning: Programming fuses is an irreversible operation!\n"
+                       "         This may brick your system.\n"
+                       "         Use this command only if you are sure of "
+                                       "what you are doing!\n"
+                       "\nReally perform this fuse programming? <y/N>\n");
+
+       if (confirm_yesno())
+               return 1;
+
+       puts("Fuse programming aborted\n");
+       return 0;
+}
+
+static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       const char *op = argc >= 2 ? argv[1] : NULL;
+       int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
+       u32 bank, word, cnt, val;
+       int ret, i;
+
+       argc -= 2 + confirmed;
+       argv += 2 + confirmed;
+
+       if (argc < 2 || strtou32(argv[0], 0, &bank) ||
+                       strtou32(argv[1], 0, &word))
+               return CMD_RET_USAGE;
+
+       if (!strcmp(op, "read")) {
+               if (argc == 2)
+                       cnt = 1;
+               else if (argc != 3 || strtou32(argv[2], 0, &cnt))
+                       return CMD_RET_USAGE;
+
+               printf("Reading bank %u:\n", bank);
+               for (i = 0; i < cnt; i++, word++) {
+                       if (!(i % 4))
+                               printf("\nWord 0x%.8x:", word);
+
+                       ret = fuse_read(bank, word, &val);
+                       if (ret)
+                               goto err;
+
+                       printf(" %.8x", val);
+               }
+               putc('\n');
+       } else if (!strcmp(op, "sense")) {
+               if (argc == 2)
+                       cnt = 1;
+               else if (argc != 3 || strtou32(argv[2], 0, &cnt))
+                       return CMD_RET_USAGE;
+
+               printf("Sensing bank %u:\n", bank);
+               for (i = 0; i < cnt; i++, word++) {
+                       if (!(i % 4))
+                               printf("\nWord 0x%.8x:", word);
+
+                       ret = fuse_sense(bank, word, &val);
+                       if (ret)
+                               goto err;
+
+                       printf(" %.8x", val);
+               }
+               putc('\n');
+       } else if (!strcmp(op, "prog")) {
+               if (argc < 3)
+                       return CMD_RET_USAGE;
+
+               for (i = 2; i < argc; i++, word++) {
+                       if (strtou32(argv[i], 16, &val))
+                               return CMD_RET_USAGE;
+
+                       printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
+                                       bank, word, val);
+                       if (!confirmed && !confirm_prog())
+                               return CMD_RET_FAILURE;
+                       ret = fuse_prog(bank, word, val);
+                       if (ret)
+                               goto err;
+               }
+       } else if (!strcmp(op, "override")) {
+               if (argc < 3)
+                       return CMD_RET_USAGE;
+
+               for (i = 2; i < argc; i++, word++) {
+                       if (strtou32(argv[i], 16, &val))
+                               return CMD_RET_USAGE;
+
+                       printf("Overriding bank %u word 0x%.8x with "
+                                       "0x%.8x...\n", bank, word, val);
+                       ret = fuse_override(bank, word, val);
+                       if (ret)
+                               goto err;
+               }
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+
+err:
+       puts("ERROR\n");
+       return CMD_RET_FAILURE;
+}
+
+U_BOOT_CMD(
+       fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
+       "Fuse sub-system",
+            "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
+       "    starting at 'word'\n"
+       "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
+       "    starting at 'word'\n"
+       "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
+       "    several fuse words, starting at 'word' (PERMANENT)\n"
+       "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
+       "    several fuse words, starting at 'word'"
+);
diff --git a/cmd/gettime.c b/cmd/gettime.c
new file mode 100644 (file)
index 0000000..c48baad
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ *
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * (C) Copyright 2001
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Get Timer overflows after 2^32 / CONFIG_SYS_HZ (32Khz) = 131072 sec
+ */
+#include <common.h>
+#include <command.h>
+
+static int do_gettime(cmd_tbl_t *cmdtp, int flag, int argc,
+                     char * const argv[])
+{
+       unsigned long int val = get_timer(0);
+
+#ifdef CONFIG_SYS_HZ
+       printf("Timer val: %lu\n", val);
+       printf("Seconds : %lu\n", val / CONFIG_SYS_HZ);
+       printf("Remainder : %lu\n", val % CONFIG_SYS_HZ);
+       printf("sys_hz = %lu\n", (unsigned long int)CONFIG_SYS_HZ);
+#else
+       printf("CONFIG_SYS_HZ not defined");
+       printf("Timer Val %lu", val);
+#endif
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       gettime,        1,      1,      do_gettime,
+       "get timer val elapsed",
+       "get time elapsed from uboot start"
+);
diff --git a/cmd/gpio.c b/cmd/gpio.c
new file mode 100644 (file)
index 0000000..2b78b16
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Control GPIO pins on the fly
+ *
+ * Copyright (c) 2008-2011 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <dm.h>
+#include <asm/gpio.h>
+
+__weak int name_to_gpio(const char *name)
+{
+       return simple_strtoul(name, NULL, 10);
+}
+
+enum gpio_cmd {
+       GPIO_INPUT,
+       GPIO_SET,
+       GPIO_CLEAR,
+       GPIO_TOGGLE,
+};
+
+#if defined(CONFIG_DM_GPIO) && !defined(gpio_status)
+
+/* A few flags used by show_gpio() */
+enum {
+       FLAG_SHOW_ALL           = 1 << 0,
+       FLAG_SHOW_BANK          = 1 << 1,
+       FLAG_SHOW_NEWLINE       = 1 << 2,
+};
+
+static void gpio_get_description(struct udevice *dev, const char *bank_name,
+                                int offset, int *flagsp)
+{
+       char buf[80];
+       int ret;
+
+       ret = gpio_get_function(dev, offset, NULL);
+       if (ret < 0)
+               goto err;
+       if (!(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
+               return;
+       if ((*flagsp & FLAG_SHOW_BANK) && bank_name) {
+               if (*flagsp & FLAG_SHOW_NEWLINE) {
+                       putc('\n');
+                       *flagsp &= ~FLAG_SHOW_NEWLINE;
+               }
+               printf("Bank %s:\n", bank_name);
+               *flagsp &= ~FLAG_SHOW_BANK;
+       }
+
+       ret = gpio_get_status(dev, offset, buf, sizeof(buf));
+       if (ret)
+               goto err;
+
+       printf("%s\n", buf);
+       return;
+err:
+       printf("Error %d\n", ret);
+}
+
+static int do_gpio_status(bool all, const char *gpio_name)
+{
+       struct udevice *dev;
+       int banklen;
+       int flags;
+       int ret;
+
+       flags = 0;
+       if (gpio_name && !*gpio_name)
+               gpio_name = NULL;
+       for (ret = uclass_first_device(UCLASS_GPIO, &dev);
+            dev;
+            ret = uclass_next_device(&dev)) {
+               const char *bank_name;
+               int num_bits;
+
+               flags |= FLAG_SHOW_BANK;
+               if (all)
+                       flags |= FLAG_SHOW_ALL;
+               bank_name = gpio_get_bank_info(dev, &num_bits);
+               if (!num_bits) {
+                       debug("GPIO device %s has no bits\n", dev->name);
+                       continue;
+               }
+               banklen = bank_name ? strlen(bank_name) : 0;
+
+               if (!gpio_name || !bank_name ||
+                   !strncmp(gpio_name, bank_name, banklen)) {
+                       const char *p = NULL;
+                       int offset;
+
+                       p = gpio_name + banklen;
+                       if (gpio_name && *p) {
+                               offset = simple_strtoul(p, NULL, 10);
+                               gpio_get_description(dev, bank_name, offset,
+                                                    &flags);
+                       } else {
+                               for (offset = 0; offset < num_bits; offset++) {
+                                       gpio_get_description(dev, bank_name,
+                                                            offset, &flags);
+                               }
+                       }
+               }
+               /* Add a newline between bank names */
+               if (!(flags & FLAG_SHOW_BANK))
+                       flags |= FLAG_SHOW_NEWLINE;
+       }
+
+       return ret;
+}
+#endif
+
+static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int gpio;
+       enum gpio_cmd sub_cmd;
+       ulong value;
+       const char *str_cmd, *str_gpio = NULL;
+       int ret;
+#ifdef CONFIG_DM_GPIO
+       bool all = false;
+#endif
+
+       if (argc < 2)
+ show_usage:
+               return CMD_RET_USAGE;
+       str_cmd = argv[1];
+       argc -= 2;
+       argv += 2;
+#ifdef CONFIG_DM_GPIO
+       if (argc > 0 && !strcmp(*argv, "-a")) {
+               all = true;
+               argc--;
+               argv++;
+       }
+#endif
+       if (argc > 0)
+               str_gpio = *argv;
+       if (!strncmp(str_cmd, "status", 1)) {
+               /* Support deprecated gpio_status() */
+#ifdef gpio_status
+               gpio_status();
+               return 0;
+#elif defined(CONFIG_DM_GPIO)
+               return cmd_process_error(cmdtp, do_gpio_status(all, str_gpio));
+#else
+               goto show_usage;
+#endif
+       }
+
+       if (!str_gpio)
+               goto show_usage;
+
+       /* parse the behavior */
+       switch (*str_cmd) {
+               case 'i': sub_cmd = GPIO_INPUT;  break;
+               case 's': sub_cmd = GPIO_SET;    break;
+               case 'c': sub_cmd = GPIO_CLEAR;  break;
+               case 't': sub_cmd = GPIO_TOGGLE; break;
+               default:  goto show_usage;
+       }
+
+#if defined(CONFIG_DM_GPIO)
+       /*
+        * TODO(sjg@chromium.org): For now we must fit into the existing GPIO
+        * framework, so we look up the name here and convert it to a GPIO number.
+        * Once all GPIO drivers are converted to driver model, we can change the
+        * code here to use the GPIO uclass interface instead of the numbered
+        * GPIO compatibility layer.
+        */
+       ret = gpio_lookup_name(str_gpio, NULL, NULL, &gpio);
+       if (ret) {
+               printf("GPIO: '%s' not found\n", str_gpio);
+               return cmd_process_error(cmdtp, ret);
+       }
+#else
+       /* turn the gpio name into a gpio number */
+       gpio = name_to_gpio(str_gpio);
+       if (gpio < 0)
+               goto show_usage;
+#endif
+       /* grab the pin before we tweak it */
+       ret = gpio_request(gpio, "cmd_gpio");
+       if (ret && ret != -EBUSY) {
+               printf("gpio: requesting pin %u failed\n", gpio);
+               return -1;
+       }
+
+       /* finally, let's do it: set direction and exec command */
+       if (sub_cmd == GPIO_INPUT) {
+               gpio_direction_input(gpio);
+               value = gpio_get_value(gpio);
+       } else {
+               switch (sub_cmd) {
+                       case GPIO_SET:    value = 1; break;
+                       case GPIO_CLEAR:  value = 0; break;
+                       case GPIO_TOGGLE: value = !gpio_get_value(gpio); break;
+                       default:          goto show_usage;
+               }
+               gpio_direction_output(gpio, value);
+       }
+       printf("gpio: pin %s (gpio %i) value is %lu\n",
+               str_gpio, gpio, value);
+
+       if (ret != -EBUSY)
+               gpio_free(gpio);
+
+       return value;
+}
+
+U_BOOT_CMD(gpio, 4, 0, do_gpio,
+          "query and control gpio pins",
+          "<input|set|clear|toggle> <pin>\n"
+          "    - input/set/clear/toggle the specified pin\n"
+          "gpio status [-a] [<bank> | <pin>]  - show [all/claimed] GPIOs");
diff --git a/cmd/gpt.c b/cmd/gpt.c
new file mode 100644 (file)
index 0000000..d94d553
--- /dev/null
+++ b/cmd/gpt.c
@@ -0,0 +1,456 @@
+/*
+ * cmd_gpt.c -- GPT (GUID Partition Table) handling command
+ *
+ * Copyright (C) 2015
+ * Lukasz Majewski <l.majewski@majess.pl>
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * author: Lukasz Majewski <l.majewski@samsung.com>
+ * author: Piotr Wilczek <p.wilczek@samsung.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <command.h>
+#include <part_efi.h>
+#include <exports.h>
+#include <linux/ctype.h>
+#include <div64.h>
+#include <memalign.h>
+
+#ifndef CONFIG_PARTITION_UUIDS
+#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_GPT to be enabled
+#endif
+
+/**
+ * extract_env(): Expand env name from string format '&{env_name}'
+ *                and return pointer to the env (if the env is set)
+ *
+ * @param str - pointer to string
+ * @param env - pointer to pointer to extracted env
+ *
+ * @return - zero on successful expand and env is set
+ */
+static int extract_env(const char *str, char **env)
+{
+       int ret = -1;
+       char *e, *s;
+#ifdef CONFIG_RANDOM_UUID
+       char uuid_str[UUID_STR_LEN + 1];
+#endif
+
+       if (!str || strlen(str) < 4)
+               return -1;
+
+       if (!((strncmp(str, "${", 2) == 0) && (str[strlen(str) - 1] == '}')))
+               return -1;
+
+       s = strdup(str);
+       if (s == NULL)
+               return -1;
+
+       memset(s + strlen(s) - 1, '\0', 1);
+       memmove(s, s + 2, strlen(s) - 1);
+
+       e = getenv(s);
+       if (e == NULL) {
+#ifdef CONFIG_RANDOM_UUID
+               debug("%s unset. ", str);
+               gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_STD);
+               setenv(s, uuid_str);
+
+               e = getenv(s);
+               if (e) {
+                       debug("Set to random.\n");
+                       ret = 0;
+               } else {
+                       debug("Can't get random UUID.\n");
+               }
+#else
+               debug("%s unset.\n", str);
+#endif
+       } else {
+               debug("%s get from environment.\n", str);
+               ret = 0;
+       }
+
+       *env = e;
+       free(s);
+
+       return ret;
+}
+
+/**
+ * extract_val(): Extract value from a key=value pair list (comma separated).
+ *                Only value for the given key is returend.
+ *                Function allocates memory for the value, remember to free!
+ *
+ * @param str - pointer to string with key=values pairs
+ * @param key - pointer to the key to search for
+ *
+ * @return - pointer to allocated string with the value
+ */
+static char *extract_val(const char *str, const char *key)
+{
+       char *v, *k;
+       char *s, *strcopy;
+       char *new = NULL;
+
+       strcopy = strdup(str);
+       if (strcopy == NULL)
+               return NULL;
+
+       s = strcopy;
+       while (s) {
+               v = strsep(&s, ",");
+               if (!v)
+                       break;
+               k = strsep(&v, "=");
+               if (!k)
+                       break;
+               if  (strcmp(k, key) == 0) {
+                       new = strdup(v);
+                       break;
+               }
+       }
+
+       free(strcopy);
+
+       return new;
+}
+
+/**
+ * found_key(): Found key without value in parameter list (comma separated).
+ *
+ * @param str - pointer to string with key
+ * @param key - pointer to the key to search for
+ *
+ * @return - true on found key
+ */
+static bool found_key(const char *str, const char *key)
+{
+       char *k;
+       char *s, *strcopy;
+       bool result = false;
+
+       strcopy = strdup(str);
+       if (!strcopy)
+               return NULL;
+
+       s = strcopy;
+       while (s) {
+               k = strsep(&s, ",");
+               if (!k)
+                       break;
+               if  (strcmp(k, key) == 0) {
+                       result = true;
+                       break;
+               }
+       }
+
+       free(strcopy);
+
+       return result;
+}
+
+/**
+ * set_gpt_info(): Fill partition information from string
+ *             function allocates memory, remember to free!
+ *
+ * @param dev_desc - pointer block device descriptor
+ * @param str_part - pointer to string with partition information
+ * @param str_disk_guid - pointer to pointer to allocated string with disk guid
+ * @param partitions - pointer to pointer to allocated partitions array
+ * @param parts_count - number of partitions
+ *
+ * @return - zero on success, otherwise error
+ *
+ */
+static int set_gpt_info(block_dev_desc_t *dev_desc,
+                       const char *str_part,
+                       char **str_disk_guid,
+                       disk_partition_t **partitions,
+                       u8 *parts_count)
+{
+       char *tok, *str, *s;
+       int i;
+       char *val, *p;
+       int p_count;
+       disk_partition_t *parts;
+       int errno = 0;
+       uint64_t size_ll, start_ll;
+
+       debug("%s:  lba num: 0x%x %d\n", __func__,
+             (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba);
+
+       if (str_part == NULL)
+               return -1;
+
+       str = strdup(str_part);
+
+       /* extract disk guid */
+       s = str;
+       val = extract_val(str, "uuid_disk");
+       if (!val) {
+#ifdef CONFIG_RANDOM_UUID
+               *str_disk_guid = malloc(UUID_STR_LEN + 1);
+               gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
+#else
+               free(str);
+               return -2;
+#endif
+       } else {
+               val = strsep(&val, ";");
+               if (extract_env(val, &p))
+                       p = val;
+               *str_disk_guid = strdup(p);
+               free(val);
+               /* Move s to first partition */
+               strsep(&s, ";");
+       }
+       if (strlen(s) == 0)
+               return -3;
+
+       i = strlen(s) - 1;
+       if (s[i] == ';')
+               s[i] = '\0';
+
+       /* calculate expected number of partitions */
+       p_count = 1;
+       p = s;
+       while (*p) {
+               if (*p++ == ';')
+                       p_count++;
+       }
+
+       /* allocate memory for partitions */
+       parts = calloc(sizeof(disk_partition_t), p_count);
+
+       /* retrieve partitions data from string */
+       for (i = 0; i < p_count; i++) {
+               tok = strsep(&s, ";");
+
+               if (tok == NULL)
+                       break;
+
+               /* uuid */
+               val = extract_val(tok, "uuid");
+               if (!val) {
+                       /* 'uuid' is optional if random uuid's are enabled */
+#ifdef CONFIG_RANDOM_UUID
+                       gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD);
+#else
+                       errno = -4;
+                       goto err;
+#endif
+               } else {
+                       if (extract_env(val, &p))
+                               p = val;
+                       if (strlen(p) >= sizeof(parts[i].uuid)) {
+                               printf("Wrong uuid format for partition %d\n", i);
+                               errno = -4;
+                               goto err;
+                       }
+                       strcpy((char *)parts[i].uuid, p);
+                       free(val);
+               }
+#ifdef CONFIG_PARTITION_TYPE_GUID
+               /* guid */
+               val = extract_val(tok, "type");
+               if (val) {
+                       /* 'type' is optional */
+                       if (extract_env(val, &p))
+                               p = val;
+                       if (strlen(p) >= sizeof(parts[i].type_guid)) {
+                               printf("Wrong type guid format for partition %d\n",
+                                      i);
+                               errno = -4;
+                               goto err;
+                       }
+                       strcpy((char *)parts[i].type_guid, p);
+                       free(val);
+               }
+#endif
+               /* name */
+               val = extract_val(tok, "name");
+               if (!val) { /* name is mandatory */
+                       errno = -4;
+                       goto err;
+               }
+               if (extract_env(val, &p))
+                       p = val;
+               if (strlen(p) >= sizeof(parts[i].name)) {
+                       errno = -4;
+                       goto err;
+               }
+               strcpy((char *)parts[i].name, p);
+               free(val);
+
+               /* size */
+               val = extract_val(tok, "size");
+               if (!val) { /* 'size' is mandatory */
+                       errno = -4;
+                       goto err;
+               }
+               if (extract_env(val, &p))
+                       p = val;
+               size_ll = ustrtoull(p, &p, 0);
+               parts[i].size = lldiv(size_ll, dev_desc->blksz);
+               free(val);
+
+               /* start address */
+               val = extract_val(tok, "start");
+               if (val) { /* start address is optional */
+                       if (extract_env(val, &p))
+                               p = val;
+                       start_ll = ustrtoull(p, &p, 0);
+                       parts[i].start = lldiv(start_ll, dev_desc->blksz);
+                       free(val);
+               }
+
+               /* bootable */
+               if (found_key(tok, "bootable"))
+                       parts[i].bootable = 1;
+       }
+
+       *parts_count = p_count;
+       *partitions = parts;
+       free(str);
+
+       return 0;
+err:
+       free(str);
+       free(*str_disk_guid);
+       free(parts);
+
+       return errno;
+}
+
+static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
+{
+       int ret;
+       char *str_disk_guid;
+       u8 part_count = 0;
+       disk_partition_t *partitions = NULL;
+
+       /* fill partitions */
+       ret = set_gpt_info(blk_dev_desc, str_part,
+                       &str_disk_guid, &partitions, &part_count);
+       if (ret) {
+               if (ret == -1)
+                       printf("No partition list provided\n");
+               if (ret == -2)
+                       printf("Missing disk guid\n");
+               if ((ret == -3) || (ret == -4))
+                       printf("Partition list incomplete\n");
+               return -1;
+       }
+
+       /* save partitions layout to disk */
+       ret = gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
+       free(str_disk_guid);
+       free(partitions);
+
+       return ret;
+}
+
+static int gpt_verify(block_dev_desc_t *blk_dev_desc, const char *str_part)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
+                                    blk_dev_desc->blksz);
+       disk_partition_t *partitions = NULL;
+       gpt_entry *gpt_pte = NULL;
+       char *str_disk_guid;
+       u8 part_count = 0;
+       int ret = 0;
+
+       /* fill partitions */
+       ret = set_gpt_info(blk_dev_desc, str_part,
+                       &str_disk_guid, &partitions, &part_count);
+       if (ret) {
+               if (ret == -1) {
+                       printf("No partition list provided - only basic check\n");
+                       ret = gpt_verify_headers(blk_dev_desc, gpt_head,
+                                                &gpt_pte);
+                       goto out;
+               }
+               if (ret == -2)
+                       printf("Missing disk guid\n");
+               if ((ret == -3) || (ret == -4))
+                       printf("Partition list incomplete\n");
+               return -1;
+       }
+
+       /* Check partition layout with provided pattern */
+       ret = gpt_verify_partitions(blk_dev_desc, partitions, part_count,
+                                   gpt_head, &gpt_pte);
+       free(str_disk_guid);
+       free(partitions);
+ out:
+       free(gpt_pte);
+       return ret;
+}
+
+/**
+ * do_gpt(): Perform GPT operations
+ *
+ * @param cmdtp - command name
+ * @param flag
+ * @param argc
+ * @param argv
+ *
+ * @return zero on success; otherwise error
+ */
+static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret = CMD_RET_SUCCESS;
+       int dev = 0;
+       char *ep;
+       block_dev_desc_t *blk_dev_desc = NULL;
+
+       if (argc < 4 || argc > 5)
+               return CMD_RET_USAGE;
+
+       dev = (int)simple_strtoul(argv[3], &ep, 10);
+       if (!ep || ep[0] != '\0') {
+               printf("'%s' is not a number\n", argv[3]);
+               return CMD_RET_USAGE;
+       }
+       blk_dev_desc = get_dev(argv[2], dev);
+       if (!blk_dev_desc) {
+               printf("%s: %s dev %d NOT available\n",
+                      __func__, argv[2], dev);
+               return CMD_RET_FAILURE;
+       }
+
+       if ((strcmp(argv[1], "write") == 0) && (argc == 5)) {
+               printf("Writing GPT: ");
+               ret = gpt_default(blk_dev_desc, argv[4]);
+       } else if ((strcmp(argv[1], "verify") == 0)) {
+               ret = gpt_verify(blk_dev_desc, argv[4]);
+               printf("Verify GPT: ");
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       if (ret) {
+               printf("error!\n");
+               return CMD_RET_FAILURE;
+       }
+
+       printf("success!\n");
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
+       "GUID Partition Table",
+       "<command> <interface> <dev> <partitions_list>\n"
+       " - GUID partition table restoration and validity check\n"
+       " Restore or verify GPT information on a device connected\n"
+       " to interface\n"
+       " Example usage:\n"
+       " gpt write mmc 0 $partitions\n"
+       " gpt verify mmc 0 $partitions\n"
+);
diff --git a/cmd/hash.c b/cmd/hash.c
new file mode 100644 (file)
index 0000000..704d21e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012 The Chromium OS Authors.
+ *
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <hash.h>
+#include <linux/ctype.h>
+
+static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *s;
+       int flags = HASH_FLAG_ENV;
+
+#ifdef CONFIG_HASH_VERIFY
+       if (argc < 4)
+               return CMD_RET_USAGE;
+       if (!strcmp(argv[1], "-v")) {
+               flags |= HASH_FLAG_VERIFY;
+               argc--;
+               argv++;
+       }
+#endif
+       /* Move forward to 'algorithm' parameter */
+       argc--;
+       argv++;
+       for (s = *argv; *s; s++)
+               *s = tolower(*s);
+       return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
+}
+
+#ifdef CONFIG_HASH_VERIFY
+#define HARGS 6
+#else
+#define HARGS 5
+#endif
+
+U_BOOT_CMD(
+       hash,   HARGS,  1,      do_hash,
+       "compute hash message digest",
+       "algorithm address count [[*]hash_dest]\n"
+               "    - compute message digest [save to env var / *address]"
+#ifdef CONFIG_HASH_VERIFY
+       "\nhash -v algorithm address count [*]hash\n"
+               "    - verify message digest of memory area to immediate value, \n"
+               "      env var or *address"
+#endif
+);
diff --git a/cmd/help.c b/cmd/help.c
new file mode 100644 (file)
index 0000000..6ff494d
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
+       const int len = ll_entry_count(cmd_tbl_t, cmd);
+       return _do_help(start, len, cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+       help,   CONFIG_SYS_MAXARGS,     1,      do_help,
+       "print command description/usage",
+       "\n"
+       "       - print brief description of all commands\n"
+       "help command ...\n"
+       "       - print detailed usage of 'command'"
+);
+
+/* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */
+ll_entry_declare(cmd_tbl_t, question_mark, cmd) = {
+       "?",    CONFIG_SYS_MAXARGS,     1,      do_help,
+       "alias for 'help'",
+#ifdef  CONFIG_SYS_LONGHELP
+       ""
+#endif /* CONFIG_SYS_LONGHELP */
+};
diff --git a/cmd/host.c b/cmd/host.c
new file mode 100644 (file)
index 0000000..ba1460e
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2012, Google Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <fs.h>
+#include <part.h>
+#include <sandboxblockdev.h>
+#include <asm/errno.h>
+
+static int host_curr_device = -1;
+
+static int do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
+}
+
+static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
+}
+
+static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
+}
+
+static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       if (argc < 2 || argc > 3)
+               return CMD_RET_USAGE;
+       char *ep;
+       char *dev_str = argv[1];
+       char *file = argc >= 3 ? argv[2] : NULL;
+       int dev = simple_strtoul(dev_str, &ep, 16);
+       if (*ep) {
+               printf("** Bad device specification %s **\n", dev_str);
+               return CMD_RET_USAGE;
+       }
+       return host_dev_bind(dev, file);
+}
+
+static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
+                          char * const argv[])
+{
+       if (argc < 1 || argc > 2)
+               return CMD_RET_USAGE;
+       int min_dev = 0;
+       int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
+       if (argc >= 2) {
+               char *ep;
+               char *dev_str = argv[1];
+               int dev = simple_strtoul(dev_str, &ep, 16);
+               if (*ep) {
+                       printf("** Bad device specification %s **\n", dev_str);
+                       return CMD_RET_USAGE;
+               }
+               min_dev = dev;
+               max_dev = dev;
+       }
+       int dev;
+       printf("%3s %12s %s\n", "dev", "blocks", "path");
+       for (dev = min_dev; dev <= max_dev; dev++) {
+               block_dev_desc_t *blk_dev;
+               int ret;
+
+               printf("%3d ", dev);
+               ret = host_get_dev_err(dev, &blk_dev);
+               if (ret) {
+                       if (ret == -ENOENT)
+                               puts("Not bound to a backing file\n");
+                       else if (ret == -ENODEV)
+                               puts("Invalid host device number\n");
+
+                       continue;
+               }
+               struct host_block_dev *host_dev = blk_dev->priv;
+               printf("%12lu %s\n", (unsigned long)blk_dev->lba,
+                      host_dev->filename);
+       }
+       return 0;
+}
+
+static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       int dev;
+       char *ep;
+       block_dev_desc_t *blk_dev;
+       int ret;
+
+       if (argc < 1 || argc > 3)
+               return CMD_RET_USAGE;
+
+       if (argc == 1) {
+               if (host_curr_device < 0) {
+                       printf("No current host device\n");
+                       return 1;
+               }
+               printf("Current host device %d\n", host_curr_device);
+               return 0;
+       }
+
+       dev = simple_strtoul(argv[1], &ep, 16);
+       if (*ep) {
+               printf("** Bad device specification %s **\n", argv[2]);
+               return CMD_RET_USAGE;
+       }
+
+       ret = host_get_dev_err(dev, &blk_dev);
+       if (ret) {
+               if (ret == -ENOENT)
+                       puts("Not bound to a backing file\n");
+               else if (ret == -ENODEV)
+                       puts("Invalid host device number\n");
+
+               return 1;
+       }
+
+       host_curr_device = dev;
+       return 0;
+}
+
+static cmd_tbl_t cmd_host_sub[] = {
+       U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
+       U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
+       U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
+       U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
+       U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
+       U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
+};
+
+static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
+                     char * const argv[])
+{
+       cmd_tbl_t *c;
+
+       /* Skip past 'host' */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], cmd_host_sub,
+                        ARRAY_SIZE(cmd_host_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       sb,     8,      1,      do_host,
+       "Deprecated: use 'host' command instead.", ""
+);
+
+U_BOOT_CMD(
+       host, 8, 1, do_host,
+       "Miscellaneous host commands",
+       "load hostfs - <addr> <filename> [<bytes> <offset>]  - "
+               "load a file from host\n"
+       "host ls hostfs - <filename>                    - list files on host\n"
+       "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
+               "save a file to host\n"
+       "host bind <dev> [<filename>] - bind \"host\" device to file\n"
+       "host info [<dev>]            - show device binding & info\n"
+       "host dev [<dev>] - Set or retrieve the current host device\n"
+       "host commands use the \"hostfs\" device. The \"host\" device is used\n"
+       "with standard IO commands such as fatls or ext2load"
+);
diff --git a/cmd/i2c.c b/cmd/i2c.c
new file mode 100644 (file)
index 0000000..b3bb644
--- /dev/null
+++ b/cmd/i2c.c
@@ -0,0 +1,2030 @@
+/*
+ * (C) Copyright 2009
+ * Sergey Kubushyn, himself, ksi@koi8.net
+ *
+ * Changes for unified multibus/multiadapter I2C support.
+ *
+ * (C) Copyright 2001
+ * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * I2C Functions similar to the standard memory functions.
+ *
+ * There are several parameters in many of the commands that bear further
+ * explanations:
+ *
+ * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
+ *   Each I2C chip on the bus has a unique address.  On the I2C data bus,
+ *   the address is the upper seven bits and the LSB is the "read/write"
+ *   bit.  Note that the {i2c_chip} address specified on the command
+ *   line is not shifted up: e.g. a typical EEPROM memory chip may have
+ *   an I2C address of 0x50, but the data put on the bus will be 0xA0
+ *   for write and 0xA1 for read.  This "non shifted" address notation
+ *   matches at least half of the data sheets :-/.
+ *
+ * {addr} is the address (or offset) within the chip.  Small memory
+ *   chips have 8 bit addresses.  Large memory chips have 16 bit
+ *   addresses.  Other memory chips have 9, 10, or 11 bit addresses.
+ *   Many non-memory chips have multiple registers and {addr} is used
+ *   as the register index.  Some non-memory chips have only one register
+ *   and therefore don't need any {addr} parameter.
+ *
+ *   The default {addr} parameter is one byte (.1) which works well for
+ *   memories and registers with 8 bits of address space.
+ *
+ *   You can specify the length of the {addr} field with the optional .0,
+ *   .1, or .2 modifier (similar to the .b, .w, .l modifier).  If you are
+ *   manipulating a single register device which doesn't use an address
+ *   field, use "0.0" for the address and the ".0" length field will
+ *   suppress the address in the I2C data stream.  This also works for
+ *   successive reads using the I2C auto-incrementing memory pointer.
+ *
+ *   If you are manipulating a large memory with 2-byte addresses, use
+ *   the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
+ *
+ *   Then there are the unfortunate memory chips that spill the most
+ *   significant 1, 2, or 3 bits of address into the chip address byte.
+ *   This effectively makes one chip (logically) look like 2, 4, or
+ *   8 chips.  This is handled (awkwardly) by #defining
+ *   CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
+ *   {addr} field (since .1 is the default, it doesn't actually have to
+ *   be specified).  Examples: given a memory chip at I2C chip address
+ *   0x50, the following would happen...
+ *     i2c md 50 0 10   display 16 bytes starting at 0x000
+ *                      On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
+ *     i2c md 50 100 10 display 16 bytes starting at 0x100
+ *                      On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
+ *     i2c md 50 210 10 display 16 bytes starting at 0x210
+ *                      On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
+ *   This is awfully ugly.  It would be nice if someone would think up
+ *   a better way of handling this.
+ *
+ * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
+ */
+
+#include <common.h>
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <dm.h>
+#include <edid.h>
+#include <environment.h>
+#include <errno.h>
+#include <i2c.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Display values from last command.
+ * Memory modify remembered values are different from display memory.
+ */
+static uint    i2c_dp_last_chip;
+static uint    i2c_dp_last_addr;
+static uint    i2c_dp_last_alen;
+static uint    i2c_dp_last_length = 0x10;
+
+static uint    i2c_mm_last_chip;
+static uint    i2c_mm_last_addr;
+static uint    i2c_mm_last_alen;
+
+/* If only one I2C bus is present, the list of devices to ignore when
+ * the probe command is issued is represented by a 1D array of addresses.
+ * When multiple buses are present, the list is an array of bus-address
+ * pairs.  The following macros take care of this */
+
+#if defined(CONFIG_SYS_I2C_NOPROBES)
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
+static struct
+{
+       uchar   bus;
+       uchar   addr;
+} i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
+#define GET_BUS_NUM    i2c_get_bus_num()
+#define COMPARE_BUS(b,i)       (i2c_no_probes[(i)].bus == (b))
+#define COMPARE_ADDR(a,i)      (i2c_no_probes[(i)].addr == (a))
+#define NO_PROBE_ADDR(i)       i2c_no_probes[(i)].addr
+#else          /* single bus */
+static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
+#define GET_BUS_NUM    0
+#define COMPARE_BUS(b,i)       ((b) == 0)      /* Make compiler happy */
+#define COMPARE_ADDR(a,i)      (i2c_no_probes[(i)] == (a))
+#define NO_PROBE_ADDR(i)       i2c_no_probes[(i)]
+#endif /* defined(CONFIG_SYS_I2C) */
+#endif
+
+#define DISP_LINE_LEN  16
+
+/*
+ * Default for driver model is to use the chip's existing address length.
+ * For legacy code, this is not stored, so we need to use a suitable
+ * default.
+ */
+#ifdef CONFIG_DM_I2C
+#define DEFAULT_ADDR_LEN       (-1)
+#else
+#define DEFAULT_ADDR_LEN       1
+#endif
+
+#ifdef CONFIG_DM_I2C
+static struct udevice *i2c_cur_bus;
+
+static int cmd_i2c_set_bus_num(unsigned int busnum)
+{
+       struct udevice *bus;
+       int ret;
+
+       ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
+       if (ret) {
+               debug("%s: No bus %d\n", __func__, busnum);
+               return ret;
+       }
+       i2c_cur_bus = bus;
+
+       return 0;
+}
+
+static int i2c_get_cur_bus(struct udevice **busp)
+{
+       if (!i2c_cur_bus) {
+               puts("No I2C bus selected\n");
+               return -ENODEV;
+       }
+       *busp = i2c_cur_bus;
+
+       return 0;
+}
+
+static int i2c_get_cur_bus_chip(uint chip_addr, struct udevice **devp)
+{
+       struct udevice *bus;
+       int ret;
+
+       ret = i2c_get_cur_bus(&bus);
+       if (ret)
+               return ret;
+
+       return i2c_get_chip(bus, chip_addr, 1, devp);
+}
+
+#endif
+
+/**
+ * i2c_init_board() - Board-specific I2C bus init
+ *
+ * This function is the default no-op implementation of I2C bus
+ * initialization. This function can be overriden by board-specific
+ * implementation if needed.
+ */
+__weak
+void i2c_init_board(void)
+{
+}
+
+/* TODO: Implement architecture-specific get/set functions */
+
+/**
+ * i2c_get_bus_speed() - Return I2C bus speed
+ *
+ * This function is the default implementation of function for retrieveing
+ * the current I2C bus speed in Hz.
+ *
+ * A driver implementing runtime switching of I2C bus speed must override
+ * this function to report the speed correctly. Simple or legacy drivers
+ * can use this fallback.
+ *
+ * Returns I2C bus speed in Hz.
+ */
+#if !defined(CONFIG_SYS_I2C) && !defined(CONFIG_DM_I2C)
+/*
+ * TODO: Implement architecture-specific get/set functions
+ * Should go away, if we switched completely to new multibus support
+ */
+__weak
+unsigned int i2c_get_bus_speed(void)
+{
+       return CONFIG_SYS_I2C_SPEED;
+}
+
+/**
+ * i2c_set_bus_speed() - Configure I2C bus speed
+ * @speed:     Newly set speed of the I2C bus in Hz
+ *
+ * This function is the default implementation of function for setting
+ * the I2C bus speed in Hz.
+ *
+ * A driver implementing runtime switching of I2C bus speed must override
+ * this function to report the speed correctly. Simple or legacy drivers
+ * can use this fallback.
+ *
+ * Returns zero on success, negative value on error.
+ */
+__weak
+int i2c_set_bus_speed(unsigned int speed)
+{
+       if (speed != CONFIG_SYS_I2C_SPEED)
+               return -1;
+
+       return 0;
+}
+#endif
+
+/**
+ * get_alen() - Small parser helper function to get address length
+ *
+ * Returns the address length.
+ */
+static uint get_alen(char *arg, int default_len)
+{
+       int     j;
+       int     alen;
+
+       alen = default_len;
+       for (j = 0; j < 8; j++) {
+               if (arg[j] == '.') {
+                       alen = arg[j+1] - '0';
+                       break;
+               } else if (arg[j] == '\0')
+                       break;
+       }
+       return alen;
+}
+
+enum i2c_err_op {
+       I2C_ERR_READ,
+       I2C_ERR_WRITE,
+};
+
+static int i2c_report_err(int ret, enum i2c_err_op op)
+{
+       printf("Error %s the chip: %d\n",
+              op == I2C_ERR_READ ? "reading" : "writing", ret);
+
+       return CMD_RET_FAILURE;
+}
+
+/**
+ * do_i2c_read() - Handle the "i2c read" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
+ */
+static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       uint    devaddr, length;
+       int alen;
+       u_char  *memaddr;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       /*
+        * I2C chip address
+        */
+       chip = simple_strtoul(argv[1], NULL, 16);
+
+       /*
+        * I2C data address within the chip.  This can be 1 or
+        * 2 bytes long.  Some day it might be 3 bytes long :-).
+        */
+       devaddr = simple_strtoul(argv[2], NULL, 16);
+       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+       if (alen > 3)
+               return CMD_RET_USAGE;
+
+       /*
+        * Length is the number of objects, not number of bytes.
+        */
+       length = simple_strtoul(argv[3], NULL, 16);
+
+       /*
+        * memaddr is the address where to store things in memory
+        */
+       memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (!ret)
+               ret = dm_i2c_read(dev, devaddr, memaddr, length);
+#else
+       ret = i2c_read(chip, devaddr, alen, memaddr, length);
+#endif
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       return 0;
+}
+
+static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       uint    devaddr, length;
+       int alen;
+       u_char  *memaddr;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+       struct dm_i2c_chip *i2c_chip;
+#endif
+
+       if ((argc < 5) || (argc > 6))
+               return cmd_usage(cmdtp);
+
+       /*
+        * memaddr is the address where to store things in memory
+        */
+       memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
+
+       /*
+        * I2C chip address
+        */
+       chip = simple_strtoul(argv[2], NULL, 16);
+
+       /*
+        * I2C data address within the chip.  This can be 1 or
+        * 2 bytes long.  Some day it might be 3 bytes long :-).
+        */
+       devaddr = simple_strtoul(argv[3], NULL, 16);
+       alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
+       if (alen > 3)
+               return cmd_usage(cmdtp);
+
+       /*
+        * Length is the number of bytes.
+        */
+       length = simple_strtoul(argv[4], NULL, 16);
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_WRITE);
+       i2c_chip = dev_get_parent_platdata(dev);
+       if (!i2c_chip)
+               return i2c_report_err(ret, I2C_ERR_WRITE);
+#endif
+
+       if (argc == 6 && !strcmp(argv[5], "-s")) {
+               /*
+                * Write all bytes in a single I2C transaction. If the target
+                * device is an EEPROM, it is your responsibility to not cross
+                * a page boundary. No write delay upon completion, take this
+                * into account if linking commands.
+                */
+#ifdef CONFIG_DM_I2C
+               i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS;
+               ret = dm_i2c_write(dev, devaddr, memaddr, length);
+#else
+               ret = i2c_write(chip, devaddr, alen, memaddr, length);
+#endif
+               if (ret)
+                       return i2c_report_err(ret, I2C_ERR_WRITE);
+       } else {
+               /*
+                * Repeated addressing - perform <length> separate
+                * write transactions of one byte each
+                */
+               while (length-- > 0) {
+#ifdef CONFIG_DM_I2C
+                       i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS;
+                       ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
+#else
+                       ret = i2c_write(chip, devaddr++, alen, memaddr++, 1);
+#endif
+                       if (ret)
+                               return i2c_report_err(ret, I2C_ERR_WRITE);
+/*
+ * No write delay with FRAM devices.
+ */
+#if !defined(CONFIG_SYS_I2C_FRAM)
+                       udelay(11000);
+#endif
+               }
+       }
+       return 0;
+}
+
+#ifdef CONFIG_DM_I2C
+static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char *const argv[])
+{
+       struct udevice *dev;
+       uint flags;
+       int chip;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       chip = simple_strtoul(argv[1], NULL, 16);
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       if (argc > 2) {
+               flags = simple_strtoul(argv[2], NULL, 16);
+               ret = i2c_set_chip_flags(dev, flags);
+       } else  {
+               ret = i2c_get_chip_flags(dev, &flags);
+               if (!ret)
+                       printf("%x\n", flags);
+       }
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       return 0;
+}
+
+static int do_i2c_olen(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       struct udevice *dev;
+       uint olen;
+       int chip;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       chip = simple_strtoul(argv[1], NULL, 16);
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       if (argc > 2) {
+               olen = simple_strtoul(argv[2], NULL, 16);
+               ret = i2c_set_chip_offset_len(dev, olen);
+       } else  {
+               ret = i2c_get_chip_offset_len(dev);
+               if (ret >= 0) {
+                       printf("%x\n", ret);
+                       ret = 0;
+               }
+       }
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       return 0;
+}
+#endif
+
+/**
+ * do_i2c_md() - Handle the "i2c md" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
+ */
+static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       uint    addr, length;
+       int alen;
+       int     j, nbytes, linebytes;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       /* We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       chip   = i2c_dp_last_chip;
+       addr   = i2c_dp_last_addr;
+       alen   = i2c_dp_last_alen;
+       length = i2c_dp_last_length;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /*
+                * New command specified.
+                */
+
+               /*
+                * I2C chip address
+                */
+               chip = simple_strtoul(argv[1], NULL, 16);
+
+               /*
+                * I2C data address within the chip.  This can be 1 or
+                * 2 bytes long.  Some day it might be 3 bytes long :-).
+                */
+               addr = simple_strtoul(argv[2], NULL, 16);
+               alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+               if (alen > 3)
+                       return CMD_RET_USAGE;
+
+               /*
+                * If another parameter, it is the length to display.
+                * Length is the number of objects, not number of bytes.
+                */
+               if (argc > 3)
+                       length = simple_strtoul(argv[3], NULL, 16);
+       }
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+#endif
+
+       /*
+        * Print the lines.
+        *
+        * We buffer all read data, so we can make sure data is read only
+        * once.
+        */
+       nbytes = length;
+       do {
+               unsigned char   linebuf[DISP_LINE_LEN];
+               unsigned char   *cp;
+
+               linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
+
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_read(dev, addr, linebuf, linebytes);
+#else
+               ret = i2c_read(chip, addr, alen, linebuf, linebytes);
+#endif
+               if (ret)
+                       return i2c_report_err(ret, I2C_ERR_READ);
+               else {
+                       printf("%04x:", addr);
+                       cp = linebuf;
+                       for (j=0; j<linebytes; j++) {
+                               printf(" %02x", *cp++);
+                               addr++;
+                       }
+                       puts ("    ");
+                       cp = linebuf;
+                       for (j=0; j<linebytes; j++) {
+                               if ((*cp < 0x20) || (*cp > 0x7e))
+                                       puts (".");
+                               else
+                                       printf("%c", *cp);
+                               cp++;
+                       }
+                       putc ('\n');
+               }
+               nbytes -= linebytes;
+       } while (nbytes > 0);
+
+       i2c_dp_last_chip   = chip;
+       i2c_dp_last_addr   = addr;
+       i2c_dp_last_alen   = alen;
+       i2c_dp_last_length = length;
+
+       return 0;
+}
+
+/**
+ * do_i2c_mw() - Handle the "i2c mw" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
+ */
+static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       ulong   addr;
+       int     alen;
+       uchar   byte;
+       int     count;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if ((argc < 4) || (argc > 5))
+               return CMD_RET_USAGE;
+
+       /*
+        * Chip is always specified.
+        */
+       chip = simple_strtoul(argv[1], NULL, 16);
+
+       /*
+        * Address is always specified.
+        */
+       addr = simple_strtoul(argv[2], NULL, 16);
+       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+       if (alen > 3)
+               return CMD_RET_USAGE;
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_WRITE);
+#endif
+       /*
+        * Value to write is always specified.
+        */
+       byte = simple_strtoul(argv[3], NULL, 16);
+
+       /*
+        * Optional count
+        */
+       if (argc == 5)
+               count = simple_strtoul(argv[4], NULL, 16);
+       else
+               count = 1;
+
+       while (count-- > 0) {
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_write(dev, addr++, &byte, 1);
+#else
+               ret = i2c_write(chip, addr++, alen, &byte, 1);
+#endif
+               if (ret)
+                       return i2c_report_err(ret, I2C_ERR_WRITE);
+               /*
+                * Wait for the write to complete.  The write can take
+                * up to 10mSec (we allow a little more time).
+                */
+/*
+ * No write delay with FRAM devices.
+ */
+#if !defined(CONFIG_SYS_I2C_FRAM)
+               udelay(11000);
+#endif
+       }
+
+       return 0;
+}
+
+/**
+ * do_i2c_crc() - Handle the "i2c crc32" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Calculate a CRC on memory
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
+ */
+static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       ulong   addr;
+       int     alen;
+       int     count;
+       uchar   byte;
+       ulong   crc;
+       ulong   err;
+       int ret = 0;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       /*
+        * Chip is always specified.
+        */
+       chip = simple_strtoul(argv[1], NULL, 16);
+
+       /*
+        * Address is always specified.
+        */
+       addr = simple_strtoul(argv[2], NULL, 16);
+       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+       if (alen > 3)
+               return CMD_RET_USAGE;
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+#endif
+       /*
+        * Count is always specified
+        */
+       count = simple_strtoul(argv[3], NULL, 16);
+
+       printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
+       /*
+        * CRC a byte at a time.  This is going to be slooow, but hey, the
+        * memories are small and slow too so hopefully nobody notices.
+        */
+       crc = 0;
+       err = 0;
+       while (count-- > 0) {
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_read(dev, addr, &byte, 1);
+#else
+               ret = i2c_read(chip, addr, alen, &byte, 1);
+#endif
+               if (ret)
+                       err++;
+               crc = crc32 (crc, &byte, 1);
+               addr++;
+       }
+       if (err > 0)
+               i2c_report_err(ret, I2C_ERR_READ);
+       else
+               printf ("%08lx\n", crc);
+
+       return 0;
+}
+
+/**
+ * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Modify memory.
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
+ *     i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
+ */
+static int
+mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       ulong   addr;
+       int     alen;
+       ulong   data;
+       int     size = 1;
+       int     nbytes;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       bootretry_reset_cmd_timeout();  /* got a good command to get here */
+       /*
+        * We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       chip = i2c_mm_last_chip;
+       addr = i2c_mm_last_addr;
+       alen = i2c_mm_last_alen;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /*
+                * New command specified.  Check for a size specification.
+                * Defaults to byte if no or incorrect specification.
+                */
+               size = cmd_get_data_size(argv[0], 1);
+
+               /*
+                * Chip is always specified.
+                */
+               chip = simple_strtoul(argv[1], NULL, 16);
+
+               /*
+                * Address is always specified.
+                */
+               addr = simple_strtoul(argv[2], NULL, 16);
+               alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+               if (alen > 3)
+                       return CMD_RET_USAGE;
+       }
+
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_WRITE);
+#endif
+
+       /*
+        * Print the address, followed by value.  Then accept input for
+        * the next value.  A non-converted value exits.
+        */
+       do {
+               printf("%08lx:", addr);
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
+#else
+               ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
+#endif
+               if (ret)
+                       return i2c_report_err(ret, I2C_ERR_READ);
+
+               data = cpu_to_be32(data);
+               if (size == 1)
+                       printf(" %02lx", (data >> 24) & 0x000000FF);
+               else if (size == 2)
+                       printf(" %04lx", (data >> 16) & 0x0000FFFF);
+               else
+                       printf(" %08lx", data);
+
+               nbytes = cli_readline(" ? ");
+               if (nbytes == 0) {
+                       /*
+                        * <CR> pressed as only input, don't modify current
+                        * location and move to next.
+                        */
+                       if (incrflag)
+                               addr += size;
+                       nbytes = size;
+                       /* good enough to not time out */
+                       bootretry_reset_cmd_timeout();
+               }
+#ifdef CONFIG_BOOT_RETRY_TIME
+               else if (nbytes == -2)
+                       break;  /* timed out, exit the command  */
+#endif
+               else {
+                       char *endp;
+
+                       data = simple_strtoul(console_buffer, &endp, 16);
+                       if (size == 1)
+                               data = data << 24;
+                       else if (size == 2)
+                               data = data << 16;
+                       data = be32_to_cpu(data);
+                       nbytes = endp - console_buffer;
+                       if (nbytes) {
+                               /*
+                                * good enough to not time out
+                                */
+                               bootretry_reset_cmd_timeout();
+#ifdef CONFIG_DM_I2C
+                               ret = dm_i2c_write(dev, addr, (uchar *)&data,
+                                                  size);
+#else
+                               ret = i2c_write(chip, addr, alen,
+                                               (uchar *)&data, size);
+#endif
+                               if (ret)
+                                       return i2c_report_err(ret,
+                                                             I2C_ERR_WRITE);
+#ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+                               udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
+#endif
+                               if (incrflag)
+                                       addr += size;
+                       }
+               }
+       } while (nbytes);
+
+       i2c_mm_last_chip = chip;
+       i2c_mm_last_addr = addr;
+       i2c_mm_last_alen = alen;
+
+       return 0;
+}
+
+/**
+ * do_i2c_probe() - Handle the "i2c probe" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c probe {addr}
+ *
+ * Returns zero (success) if one or more I2C devices was found
+ */
+static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int j;
+       int addr = -1;
+       int found = 0;
+#if defined(CONFIG_SYS_I2C_NOPROBES)
+       int k, skip;
+       unsigned int bus = GET_BUS_NUM;
+#endif /* NOPROBES */
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *bus, *dev;
+
+       if (i2c_get_cur_bus(&bus))
+               return CMD_RET_FAILURE;
+#endif
+
+       if (argc == 2)
+               addr = simple_strtol(argv[1], 0, 16);
+
+       puts ("Valid chip addresses:");
+       for (j = 0; j < 128; j++) {
+               if ((0 <= addr) && (j != addr))
+                       continue;
+
+#if defined(CONFIG_SYS_I2C_NOPROBES)
+               skip = 0;
+               for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
+                       if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
+                               skip = 1;
+                               break;
+                       }
+               }
+               if (skip)
+                       continue;
+#endif
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_probe(bus, j, 0, &dev);
+#else
+               ret = i2c_probe(j);
+#endif
+               if (ret == 0) {
+                       printf(" %02X", j);
+                       found++;
+               }
+       }
+       putc ('\n');
+
+#if defined(CONFIG_SYS_I2C_NOPROBES)
+       puts ("Excluded chip addresses:");
+       for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
+               if (COMPARE_BUS(bus,k))
+                       printf(" %02X", NO_PROBE_ADDR(k));
+       }
+       putc ('\n');
+#endif
+
+       return (0 == found);
+}
+
+/**
+ * do_i2c_loop() - Handle the "i2c loop" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ *
+ * Syntax:
+ *     i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
+ *     {length} - Number of bytes to read
+ *     {delay}  - A DECIMAL number and defaults to 1000 uSec
+ */
+static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint    chip;
+       int alen;
+       uint    addr;
+       uint    length;
+       u_char  bytes[16];
+       int     delay;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       /*
+        * Chip is always specified.
+        */
+       chip = simple_strtoul(argv[1], NULL, 16);
+
+       /*
+        * Address is always specified.
+        */
+       addr = simple_strtoul(argv[2], NULL, 16);
+       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
+       if (alen > 3)
+               return CMD_RET_USAGE;
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret && alen != -1)
+               ret = i2c_set_chip_offset_len(dev, alen);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_WRITE);
+#endif
+
+       /*
+        * Length is the number of objects, not number of bytes.
+        */
+       length = 1;
+       length = simple_strtoul(argv[3], NULL, 16);
+       if (length > sizeof(bytes))
+               length = sizeof(bytes);
+
+       /*
+        * The delay time (uSec) is optional.
+        */
+       delay = 1000;
+       if (argc > 3)
+               delay = simple_strtoul(argv[4], NULL, 10);
+       /*
+        * Run the loop...
+        */
+       while (1) {
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_read(dev, addr, bytes, length);
+#else
+               ret = i2c_read(chip, addr, alen, bytes, length);
+#endif
+               if (ret)
+                       i2c_report_err(ret, I2C_ERR_READ);
+               udelay(delay);
+       }
+
+       /* NOTREACHED */
+       return 0;
+}
+
+/*
+ * The SDRAM command is separately configured because many
+ * (most?) embedded boards don't use SDRAM DIMMs.
+ *
+ * FIXME: Document and probably move elsewhere!
+ */
+#if defined(CONFIG_CMD_SDRAM)
+static void print_ddr2_tcyc (u_char const b)
+{
+       printf ("%d.", (b >> 4) & 0x0F);
+       switch (b & 0x0F) {
+       case 0x0:
+       case 0x1:
+       case 0x2:
+       case 0x3:
+       case 0x4:
+       case 0x5:
+       case 0x6:
+       case 0x7:
+       case 0x8:
+       case 0x9:
+               printf ("%d ns\n", b & 0x0F);
+               break;
+       case 0xA:
+               puts ("25 ns\n");
+               break;
+       case 0xB:
+               puts ("33 ns\n");
+               break;
+       case 0xC:
+               puts ("66 ns\n");
+               break;
+       case 0xD:
+               puts ("75 ns\n");
+               break;
+       default:
+               puts ("?? ns\n");
+               break;
+       }
+}
+
+static void decode_bits (u_char const b, char const *str[], int const do_once)
+{
+       u_char mask;
+
+       for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
+               if (b & mask) {
+                       puts (*str);
+                       if (do_once)
+                               return;
+               }
+       }
+}
+
+/*
+ * Syntax:
+ *     i2c sdram {i2c_chip}
+ */
+static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       enum { unknown, EDO, SDRAM, DDR2 } type;
+
+       uint    chip;
+       u_char  data[128];
+       u_char  cksum;
+       int     j;
+
+       static const char *decode_CAS_DDR2[] = {
+               " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
+       };
+
+       static const char *decode_CAS_default[] = {
+               " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
+       };
+
+       static const char *decode_CS_WE_default[] = {
+               " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
+       };
+
+       static const char *decode_byte21_default[] = {
+               "  TBD (bit 7)\n",
+               "  Redundant row address\n",
+               "  Differential clock input\n",
+               "  Registerd DQMB inputs\n",
+               "  Buffered DQMB inputs\n",
+               "  On-card PLL\n",
+               "  Registered address/control lines\n",
+               "  Buffered address/control lines\n"
+       };
+
+       static const char *decode_byte22_DDR2[] = {
+               "  TBD (bit 7)\n",
+               "  TBD (bit 6)\n",
+               "  TBD (bit 5)\n",
+               "  TBD (bit 4)\n",
+               "  TBD (bit 3)\n",
+               "  Supports partial array self refresh\n",
+               "  Supports 50 ohm ODT\n",
+               "  Supports weak driver\n"
+       };
+
+       static const char *decode_row_density_DDR2[] = {
+               "512 MiB", "256 MiB", "128 MiB", "16 GiB",
+               "8 GiB", "4 GiB", "2 GiB", "1 GiB"
+       };
+
+       static const char *decode_row_density_default[] = {
+               "512 MiB", "256 MiB", "128 MiB", "64 MiB",
+               "32 MiB", "16 MiB", "8 MiB", "4 MiB"
+       };
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /*
+        * Chip is always specified.
+        */
+       chip = simple_strtoul (argv[1], NULL, 16);
+
+       if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) {
+               puts ("No SDRAM Serial Presence Detect found.\n");
+               return 1;
+       }
+
+       cksum = 0;
+       for (j = 0; j < 63; j++) {
+               cksum += data[j];
+       }
+       if (cksum != data[63]) {
+               printf ("WARNING: Configuration data checksum failure:\n"
+                       "  is 0x%02x, calculated 0x%02x\n", data[63], cksum);
+       }
+       printf ("SPD data revision            %d.%d\n",
+               (data[62] >> 4) & 0x0F, data[62] & 0x0F);
+       printf ("Bytes used                   0x%02X\n", data[0]);
+       printf ("Serial memory size           0x%02X\n", 1 << data[1]);
+
+       puts ("Memory type                  ");
+       switch (data[2]) {
+       case 2:
+               type = EDO;
+               puts ("EDO\n");
+               break;
+       case 4:
+               type = SDRAM;
+               puts ("SDRAM\n");
+               break;
+       case 8:
+               type = DDR2;
+               puts ("DDR2\n");
+               break;
+       default:
+               type = unknown;
+               puts ("unknown\n");
+               break;
+       }
+
+       puts ("Row address bits             ");
+       if ((data[3] & 0x00F0) == 0)
+               printf ("%d\n", data[3] & 0x0F);
+       else
+               printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
+
+       puts ("Column address bits          ");
+       if ((data[4] & 0x00F0) == 0)
+               printf ("%d\n", data[4] & 0x0F);
+       else
+               printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
+
+       switch (type) {
+       case DDR2:
+               printf ("Number of ranks              %d\n",
+                       (data[5] & 0x07) + 1);
+               break;
+       default:
+               printf ("Module rows                  %d\n", data[5]);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("Module data width            %d bits\n", data[6]);
+               break;
+       default:
+               printf ("Module data width            %d bits\n",
+                       (data[7] << 8) | data[6]);
+               break;
+       }
+
+       puts ("Interface signal levels      ");
+       switch(data[8]) {
+               case 0:  puts ("TTL 5.0 V\n");  break;
+               case 1:  puts ("LVTTL\n");      break;
+               case 2:  puts ("HSTL 1.5 V\n"); break;
+               case 3:  puts ("SSTL 3.3 V\n"); break;
+               case 4:  puts ("SSTL 2.5 V\n"); break;
+               case 5:  puts ("SSTL 1.8 V\n"); break;
+               default: puts ("unknown\n");    break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM cycle time             ");
+               print_ddr2_tcyc (data[9]);
+               break;
+       default:
+               printf ("SDRAM cycle time             %d.%d ns\n",
+                       (data[9] >> 4) & 0x0F, data[9] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM access time            0.%d%d ns\n",
+                       (data[10] >> 4) & 0x0F, data[10] & 0x0F);
+               break;
+       default:
+               printf ("SDRAM access time            %d.%d ns\n",
+                       (data[10] >> 4) & 0x0F, data[10] & 0x0F);
+               break;
+       }
+
+       puts ("EDC configuration            ");
+       switch (data[11]) {
+               case 0:  puts ("None\n");       break;
+               case 1:  puts ("Parity\n");     break;
+               case 2:  puts ("ECC\n");        break;
+               default: puts ("unknown\n");    break;
+       }
+
+       if ((data[12] & 0x80) == 0)
+               puts ("No self refresh, rate        ");
+       else
+               puts ("Self refresh, rate           ");
+
+       switch(data[12] & 0x7F) {
+               case 0:  puts ("15.625 us\n");  break;
+               case 1:  puts ("3.9 us\n");     break;
+               case 2:  puts ("7.8 us\n");     break;
+               case 3:  puts ("31.3 us\n");    break;
+               case 4:  puts ("62.5 us\n");    break;
+               case 5:  puts ("125 us\n");     break;
+               default: puts ("unknown\n");    break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM width (primary)        %d\n", data[13]);
+               break;
+       default:
+               printf ("SDRAM width (primary)        %d\n", data[13] & 0x7F);
+               if ((data[13] & 0x80) != 0) {
+                       printf ("  (second bank)              %d\n",
+                               2 * (data[13] & 0x7F));
+               }
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               if (data[14] != 0)
+                       printf ("EDC width                    %d\n", data[14]);
+               break;
+       default:
+               if (data[14] != 0) {
+                       printf ("EDC width                    %d\n",
+                               data[14] & 0x7F);
+
+                       if ((data[14] & 0x80) != 0) {
+                               printf ("  (second bank)              %d\n",
+                                       2 * (data[14] & 0x7F));
+                       }
+               }
+               break;
+       }
+
+       if (DDR2 != type) {
+               printf ("Min clock delay, back-to-back random column addresses "
+                       "%d\n", data[15]);
+       }
+
+       puts ("Burst length(s)             ");
+       if (data[16] & 0x80) puts (" Page");
+       if (data[16] & 0x08) puts (" 8");
+       if (data[16] & 0x04) puts (" 4");
+       if (data[16] & 0x02) puts (" 2");
+       if (data[16] & 0x01) puts (" 1");
+       putc ('\n');
+       printf ("Number of banks              %d\n", data[17]);
+
+       switch (type) {
+       case DDR2:
+               puts ("CAS latency(s)              ");
+               decode_bits (data[18], decode_CAS_DDR2, 0);
+               putc ('\n');
+               break;
+       default:
+               puts ("CAS latency(s)              ");
+               decode_bits (data[18], decode_CAS_default, 0);
+               putc ('\n');
+               break;
+       }
+
+       if (DDR2 != type) {
+               puts ("CS latency(s)               ");
+               decode_bits (data[19], decode_CS_WE_default, 0);
+               putc ('\n');
+       }
+
+       if (DDR2 != type) {
+               puts ("WE latency(s)               ");
+               decode_bits (data[20], decode_CS_WE_default, 0);
+               putc ('\n');
+       }
+
+       switch (type) {
+       case DDR2:
+               puts ("Module attributes:\n");
+               if (data[21] & 0x80)
+                       puts ("  TBD (bit 7)\n");
+               if (data[21] & 0x40)
+                       puts ("  Analysis probe installed\n");
+               if (data[21] & 0x20)
+                       puts ("  TBD (bit 5)\n");
+               if (data[21] & 0x10)
+                       puts ("  FET switch external enable\n");
+               printf ("  %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
+               if (data[20] & 0x11) {
+                       printf ("  %d active registers on DIMM\n",
+                               (data[21] & 0x03) + 1);
+               }
+               break;
+       default:
+               puts ("Module attributes:\n");
+               if (!data[21])
+                       puts ("  (none)\n");
+               else
+                       decode_bits (data[21], decode_byte21_default, 0);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               decode_bits (data[22], decode_byte22_DDR2, 0);
+               break;
+       default:
+               puts ("Device attributes:\n");
+               if (data[22] & 0x80) puts ("  TBD (bit 7)\n");
+               if (data[22] & 0x40) puts ("  TBD (bit 6)\n");
+               if (data[22] & 0x20) puts ("  Upper Vcc tolerance 5%\n");
+               else                 puts ("  Upper Vcc tolerance 10%\n");
+               if (data[22] & 0x10) puts ("  Lower Vcc tolerance 5%\n");
+               else                 puts ("  Lower Vcc tolerance 10%\n");
+               if (data[22] & 0x08) puts ("  Supports write1/read burst\n");
+               if (data[22] & 0x04) puts ("  Supports precharge all\n");
+               if (data[22] & 0x02) puts ("  Supports auto precharge\n");
+               if (data[22] & 0x01) puts ("  Supports early RAS# precharge\n");
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM cycle time (2nd highest CAS latency)        ");
+               print_ddr2_tcyc (data[23]);
+               break;
+       default:
+               printf ("SDRAM cycle time (2nd highest CAS latency)        %d."
+                       "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM access from clock (2nd highest CAS latency) 0."
+                       "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
+               break;
+       default:
+               printf ("SDRAM access from clock (2nd highest CAS latency) %d."
+                       "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM cycle time (3rd highest CAS latency)        ");
+               print_ddr2_tcyc (data[25]);
+               break;
+       default:
+               printf ("SDRAM cycle time (3rd highest CAS latency)        %d."
+                       "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("SDRAM access from clock (3rd highest CAS latency) 0."
+                       "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
+               break;
+       default:
+               printf ("SDRAM access from clock (3rd highest CAS latency) %d."
+                       "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("Minimum row precharge        %d.%02d ns\n",
+                       (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
+               break;
+       default:
+               printf ("Minimum row precharge        %d ns\n", data[27]);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("Row active to row active min %d.%02d ns\n",
+                       (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
+               break;
+       default:
+               printf ("Row active to row active min %d ns\n", data[28]);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("RAS to CAS delay min         %d.%02d ns\n",
+                       (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
+               break;
+       default:
+               printf ("RAS to CAS delay min         %d ns\n", data[29]);
+               break;
+       }
+
+       printf ("Minimum RAS pulse width      %d ns\n", data[30]);
+
+       switch (type) {
+       case DDR2:
+               puts ("Density of each row          ");
+               decode_bits (data[31], decode_row_density_DDR2, 1);
+               putc ('\n');
+               break;
+       default:
+               puts ("Density of each row          ");
+               decode_bits (data[31], decode_row_density_default, 1);
+               putc ('\n');
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               puts ("Command and Address setup    ");
+               if (data[32] >= 0xA0) {
+                       printf ("1.%d%d ns\n",
+                               ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
+               } else {
+                       printf ("0.%d%d ns\n",
+                               ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
+               }
+               break;
+       default:
+               printf ("Command and Address setup    %c%d.%d ns\n",
+                       (data[32] & 0x80) ? '-' : '+',
+                       (data[32] >> 4) & 0x07, data[32] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               puts ("Command and Address hold     ");
+               if (data[33] >= 0xA0) {
+                       printf ("1.%d%d ns\n",
+                               ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
+               } else {
+                       printf ("0.%d%d ns\n",
+                               ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
+               }
+               break;
+       default:
+               printf ("Command and Address hold     %c%d.%d ns\n",
+                       (data[33] & 0x80) ? '-' : '+',
+                       (data[33] >> 4) & 0x07, data[33] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("Data signal input setup      0.%d%d ns\n",
+                       (data[34] >> 4) & 0x0F, data[34] & 0x0F);
+               break;
+       default:
+               printf ("Data signal input setup      %c%d.%d ns\n",
+                       (data[34] & 0x80) ? '-' : '+',
+                       (data[34] >> 4) & 0x07, data[34] & 0x0F);
+               break;
+       }
+
+       switch (type) {
+       case DDR2:
+               printf ("Data signal input hold       0.%d%d ns\n",
+                       (data[35] >> 4) & 0x0F, data[35] & 0x0F);
+               break;
+       default:
+               printf ("Data signal input hold       %c%d.%d ns\n",
+                       (data[35] & 0x80) ? '-' : '+',
+                       (data[35] >> 4) & 0x07, data[35] & 0x0F);
+               break;
+       }
+
+       puts ("Manufacturer's JEDEC ID      ");
+       for (j = 64; j <= 71; j++)
+               printf ("%02X ", data[j]);
+       putc ('\n');
+       printf ("Manufacturing Location       %02X\n", data[72]);
+       puts ("Manufacturer's Part Number   ");
+       for (j = 73; j <= 90; j++)
+               printf ("%02X ", data[j]);
+       putc ('\n');
+       printf ("Revision Code                %02X %02X\n", data[91], data[92]);
+       printf ("Manufacturing Date           %02X %02X\n", data[93], data[94]);
+       puts ("Assembly Serial Number       ");
+       for (j = 95; j <= 98; j++)
+               printf ("%02X ", data[j]);
+       putc ('\n');
+
+       if (DDR2 != type) {
+               printf ("Speed rating                 PC%d\n",
+                       data[126] == 0x66 ? 66 : data[126]);
+       }
+       return 0;
+}
+#endif
+
+/*
+ * Syntax:
+ *     i2c edid {i2c_chip}
+ */
+#if defined(CONFIG_I2C_EDID)
+int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       uint chip;
+       struct edid1_info edid;
+       int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+#endif
+
+       if (argc < 2) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       chip = simple_strtoul(argv[1], NULL, 16);
+#ifdef CONFIG_DM_I2C
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (!ret)
+               ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
+#else
+       ret = i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid));
+#endif
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       if (edid_check_info(&edid)) {
+               puts("Content isn't valid EDID.\n");
+               return 1;
+       }
+
+       edid_print_info(&edid);
+       return 0;
+
+}
+#endif /* CONFIG_I2C_EDID */
+
+#ifdef CONFIG_DM_I2C
+static void show_bus(struct udevice *bus)
+{
+       struct udevice *dev;
+
+       printf("Bus %d:\t%s", bus->req_seq, bus->name);
+       if (device_active(bus))
+               printf("  (active %d)", bus->seq);
+       printf("\n");
+       for (device_find_first_child(bus, &dev);
+            dev;
+            device_find_next_child(&dev)) {
+               struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
+
+               printf("   %02x: %s, offset len %x, flags %x\n",
+                      chip->chip_addr, dev->name, chip->offset_len,
+                      chip->flags);
+       }
+}
+#endif
+
+/**
+ * do_i2c_show_bus() - Handle the "i2c bus" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero always.
+ */
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       if (argc == 1) {
+               /* show all busses */
+#ifdef CONFIG_DM_I2C
+               struct udevice *bus;
+               struct uclass *uc;
+               int ret;
+
+               ret = uclass_get(UCLASS_I2C, &uc);
+               if (ret)
+                       return CMD_RET_FAILURE;
+               uclass_foreach_dev(bus, uc)
+                       show_bus(bus);
+#else
+               int i;
+
+               for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
+                       printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
+#ifndef CONFIG_SYS_I2C_DIRECT_BUS
+                       int j;
+
+                       for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
+                               if (i2c_bus[i].next_hop[j].chip == 0)
+                                       break;
+                               printf("->%s@0x%2x:%d",
+                                      i2c_bus[i].next_hop[j].mux.name,
+                                      i2c_bus[i].next_hop[j].chip,
+                                      i2c_bus[i].next_hop[j].channel);
+                       }
+#endif
+                       printf("\n");
+               }
+#endif
+       } else {
+               int i;
+
+               /* show specific bus */
+               i = simple_strtoul(argv[1], NULL, 10);
+#ifdef CONFIG_DM_I2C
+               struct udevice *bus;
+               int ret;
+
+               ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
+               if (ret) {
+                       printf("Invalid bus %d: err=%d\n", i, ret);
+                       return CMD_RET_FAILURE;
+               }
+               show_bus(bus);
+#else
+               if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
+                       printf("Invalid bus %d\n", i);
+                       return -1;
+               }
+               printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
+#ifndef CONFIG_SYS_I2C_DIRECT_BUS
+                       int j;
+                       for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
+                               if (i2c_bus[i].next_hop[j].chip == 0)
+                                       break;
+                               printf("->%s@0x%2x:%d",
+                                      i2c_bus[i].next_hop[j].mux.name,
+                                      i2c_bus[i].next_hop[j].chip,
+                                      i2c_bus[i].next_hop[j].channel);
+                       }
+#endif
+               printf("\n");
+#endif
+       }
+
+       return 0;
+}
+#endif
+
+/**
+ * do_i2c_bus_num() - Handle the "i2c dev" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
+               defined(CONFIG_DM_I2C)
+static int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       int             ret = 0;
+       int     bus_no;
+
+       if (argc == 1) {
+               /* querying current setting */
+#ifdef CONFIG_DM_I2C
+               struct udevice *bus;
+
+               if (!i2c_get_cur_bus(&bus))
+                       bus_no = bus->seq;
+               else
+                       bus_no = -1;
+#else
+               bus_no = i2c_get_bus_num();
+#endif
+               printf("Current bus is %d\n", bus_no);
+       } else {
+               bus_no = simple_strtoul(argv[1], NULL, 10);
+#if defined(CONFIG_SYS_I2C)
+               if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
+                       printf("Invalid bus %d\n", bus_no);
+                       return -1;
+               }
+#endif
+               printf("Setting bus to %d\n", bus_no);
+#ifdef CONFIG_DM_I2C
+               ret = cmd_i2c_set_bus_num(bus_no);
+#else
+               ret = i2c_set_bus_num(bus_no);
+#endif
+               if (ret)
+                       printf("Failure changing bus number (%d)\n", ret);
+       }
+
+       return ret ? CMD_RET_FAILURE : 0;
+}
+#endif  /* defined(CONFIG_SYS_I2C) */
+
+/**
+ * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       int speed, ret=0;
+
+#ifdef CONFIG_DM_I2C
+       struct udevice *bus;
+
+       if (i2c_get_cur_bus(&bus))
+               return 1;
+#endif
+       if (argc == 1) {
+#ifdef CONFIG_DM_I2C
+               speed = dm_i2c_get_bus_speed(bus);
+#else
+               speed = i2c_get_bus_speed();
+#endif
+               /* querying current speed */
+               printf("Current bus speed=%d\n", speed);
+       } else {
+               speed = simple_strtoul(argv[1], NULL, 10);
+               printf("Setting bus speed to %d Hz\n", speed);
+#ifdef CONFIG_DM_I2C
+               ret = dm_i2c_set_bus_speed(bus, speed);
+#else
+               ret = i2c_set_bus_speed(speed);
+#endif
+               if (ret)
+                       printf("Failure changing bus speed (%d)\n", ret);
+       }
+
+       return ret ? CMD_RET_FAILURE : 0;
+}
+
+/**
+ * do_i2c_mm() - Handle the "i2c mm" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
+}
+
+/**
+ * do_i2c_nm() - Handle the "i2c nm" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
+}
+
+/**
+ * do_i2c_reset() - Handle the "i2c reset" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero always.
+ */
+static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+#if defined(CONFIG_DM_I2C)
+       struct udevice *bus;
+
+       if (i2c_get_cur_bus(&bus))
+               return CMD_RET_FAILURE;
+       if (i2c_deblock(bus)) {
+               printf("Error: Not supported by the driver\n");
+               return CMD_RET_FAILURE;
+       }
+#elif defined(CONFIG_SYS_I2C)
+       i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
+#else
+       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
+       return 0;
+}
+
+static cmd_tbl_t cmd_i2c_sub[] = {
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+       U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
+#if defined(CONFIG_SYS_I2C) || \
+       defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
+       U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
+#endif  /* CONFIG_I2C_MULTI_BUS */
+#if defined(CONFIG_I2C_EDID)
+       U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
+#endif  /* CONFIG_I2C_EDID */
+       U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
+       U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
+       U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
+       U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
+       U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
+       U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
+       U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
+#ifdef CONFIG_DM_I2C
+       U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
+       U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
+#if defined(CONFIG_CMD_SDRAM)
+       U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
+};
+
+static __maybe_unused void i2c_reloc(void)
+{
+       static int relocated;
+
+       if (!relocated) {
+               fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
+               relocated = 1;
+       };
+}
+
+/**
+ * do_i2c() - Handle the "i2c" command-line command
+ * @cmdtp:     Command data struct pointer
+ * @flag:      Command flag
+ * @argc:      Command-line argument count
+ * @argv:      Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *c;
+
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+       i2c_reloc();
+#endif
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* Strip off leading 'i2c' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+/***************************************************/
+#ifdef CONFIG_SYS_LONGHELP
+static char i2c_help_text[] =
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
+       "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
+#endif
+       "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
+#if defined(CONFIG_SYS_I2C) || \
+       defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
+       "i2c dev [dev] - show or set current I2C bus\n"
+#endif  /* CONFIG_I2C_MULTI_BUS */
+#if defined(CONFIG_I2C_EDID)
+       "i2c edid chip - print EDID configuration information\n"
+#endif  /* CONFIG_I2C_EDID */
+       "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
+       "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
+       "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
+       "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
+       "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
+       "i2c probe [address] - test for and show device(s) on the I2C bus\n"
+       "i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
+       "i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory\n"
+       "          to I2C; the -s option selects bulk write in a single transaction\n"
+#ifdef CONFIG_DM_I2C
+       "i2c flags chip [flags] - set or get chip flags\n"
+       "i2c olen chip [offset_length] - set or get chip offset length\n"
+#endif
+       "i2c reset - re-init the I2C Controller\n"
+#if defined(CONFIG_CMD_SDRAM)
+       "i2c sdram chip - print SDRAM configuration information\n"
+#endif
+       "i2c speed [speed] - show or set I2C bus speed";
+#endif
+
+U_BOOT_CMD(
+       i2c, 7, 1, do_i2c,
+       "I2C sub-system",
+       i2c_help_text
+);
diff --git a/cmd/ide.c b/cmd/ide.c
new file mode 100644 (file)
index 0000000..f19a7ce
--- /dev/null
+++ b/cmd/ide.c
@@ -0,0 +1,1457 @@
+/*
+ * (C) Copyright 2000-2011
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * IDE support
+ */
+
+#include <common.h>
+#include <config.h>
+#include <watchdog.h>
+#include <command.h>
+#include <image.h>
+#include <asm/byteorder.h>
+#include <asm/io.h>
+
+#if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
+# include <pcmcia.h>
+#endif
+
+#include <ide.h>
+#include <ata.h>
+
+#ifdef CONFIG_STATUS_LED
+# include <status_led.h>
+#endif
+
+#ifdef __PPC__
+# define EIEIO         __asm__ volatile ("eieio")
+# define SYNC          __asm__ volatile ("sync")
+#else
+# define EIEIO         /* nothing */
+# define SYNC          /* nothing */
+#endif
+
+/* ------------------------------------------------------------------------- */
+
+/* Current I/O Device  */
+static int curr_device = -1;
+
+/* Current offset for IDE0 / IDE1 bus access   */
+ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
+#if defined(CONFIG_SYS_ATA_IDE0_OFFSET)
+       CONFIG_SYS_ATA_IDE0_OFFSET,
+#endif
+#if defined(CONFIG_SYS_ATA_IDE1_OFFSET) && (CONFIG_SYS_IDE_MAXBUS > 1)
+       CONFIG_SYS_ATA_IDE1_OFFSET,
+#endif
+};
+
+static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
+
+block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
+/* ------------------------------------------------------------------------- */
+
+#ifdef CONFIG_IDE_RESET
+static void  ide_reset (void);
+#else
+#define ide_reset()    /* dummy */
+#endif
+
+static void  ide_ident (block_dev_desc_t *dev_desc);
+static uchar ide_wait  (int dev, ulong t);
+
+#define IDE_TIME_OUT   2000    /* 2 sec timeout */
+
+#define ATAPI_TIME_OUT 7000    /* 7 sec timeout (5 sec seems to work...) */
+
+#define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
+
+static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
+
+#ifndef CONFIG_SYS_ATA_PORT_ADDR
+#define CONFIG_SYS_ATA_PORT_ADDR(port) (port)
+#endif
+
+#ifdef CONFIG_ATAPI
+static void    atapi_inquiry(block_dev_desc_t *dev_desc);
+static ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                       lbaint_t blkcnt, void *buffer);
+#endif
+
+
+/* ------------------------------------------------------------------------- */
+
+int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int rcode = 0;
+
+       switch (argc) {
+       case 0:
+       case 1:
+               return CMD_RET_USAGE;
+       case 2:
+               if (strncmp(argv[1], "res", 3) == 0) {
+                       puts("\nReset IDE"
+#ifdef CONFIG_IDE_8xx_DIRECT
+                            " on PCMCIA " PCMCIA_SLOT_MSG
+#endif
+                            ": ");
+
+                       ide_init();
+                       return 0;
+               } else if (strncmp(argv[1], "inf", 3) == 0) {
+                       int i;
+
+                       putc('\n');
+
+                       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
+                               if (ide_dev_desc[i].type == DEV_TYPE_UNKNOWN)
+                                       continue;  /* list only known devices */
+                               printf("IDE device %d: ", i);
+                               dev_print(&ide_dev_desc[i]);
+                       }
+                       return 0;
+
+               } else if (strncmp(argv[1], "dev", 3) == 0) {
+                       if ((curr_device < 0)
+                           || (curr_device >= CONFIG_SYS_IDE_MAXDEVICE)) {
+                               puts("\nno IDE devices available\n");
+                               return 1;
+                       }
+                       printf("\nIDE device %d: ", curr_device);
+                       dev_print(&ide_dev_desc[curr_device]);
+                       return 0;
+               } else if (strncmp(argv[1], "part", 4) == 0) {
+                       int dev, ok;
+
+                       for (ok = 0, dev = 0;
+                            dev < CONFIG_SYS_IDE_MAXDEVICE;
+                            ++dev) {
+                               if (ide_dev_desc[dev].part_type !=
+                                   PART_TYPE_UNKNOWN) {
+                                       ++ok;
+                                       if (dev)
+                                               putc('\n');
+                                       print_part(&ide_dev_desc[dev]);
+                               }
+                       }
+                       if (!ok) {
+                               puts("\nno IDE devices available\n");
+                               rcode++;
+                       }
+                       return rcode;
+               }
+               return CMD_RET_USAGE;
+       case 3:
+               if (strncmp(argv[1], "dev", 3) == 0) {
+                       int dev = (int) simple_strtoul(argv[2], NULL, 10);
+
+                       printf("\nIDE device %d: ", dev);
+                       if (dev >= CONFIG_SYS_IDE_MAXDEVICE) {
+                               puts("unknown device\n");
+                               return 1;
+                       }
+                       dev_print(&ide_dev_desc[dev]);
+                       /*ide_print (dev); */
+
+                       if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
+                               return 1;
+
+                       curr_device = dev;
+
+                       puts("... is now current device\n");
+
+                       return 0;
+               } else if (strncmp(argv[1], "part", 4) == 0) {
+                       int dev = (int) simple_strtoul(argv[2], NULL, 10);
+
+                       if (ide_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
+                               print_part(&ide_dev_desc[dev]);
+                       } else {
+                               printf("\nIDE device %d not available\n",
+                                      dev);
+                               rcode = 1;
+                       }
+                       return rcode;
+               }
+
+               return CMD_RET_USAGE;
+       default:
+               /* at least 4 args */
+
+               if (strcmp(argv[1], "read") == 0) {
+                       ulong addr = simple_strtoul(argv[2], NULL, 16);
+                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       block_dev_desc_t *dev_desc;
+                       ulong n;
+
+#ifdef CONFIG_SYS_64BIT_LBA
+                       lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
+
+                       printf("\nIDE read: device %d block # %lld, count %ld ... ",
+                               curr_device, blk, cnt);
+#else
+                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
+
+                       printf("\nIDE read: device %d block # %ld, count %ld ... ",
+                               curr_device, blk, cnt);
+#endif
+
+                       dev_desc = &ide_dev_desc[curr_device];
+                       n = dev_desc->block_read(dev_desc, blk, cnt,
+                                                (ulong *)addr);
+                       /* flush cache after read */
+                       flush_cache(addr,
+                                   cnt * ide_dev_desc[curr_device].blksz);
+
+                       printf("%ld blocks read: %s\n",
+                              n, (n == cnt) ? "OK" : "ERROR");
+                       if (n == cnt)
+                               return 0;
+                       else
+                               return 1;
+               } else if (strcmp(argv[1], "write") == 0) {
+                       ulong addr = simple_strtoul(argv[2], NULL, 16);
+                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       ulong n;
+
+#ifdef CONFIG_SYS_64BIT_LBA
+                       lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
+
+                       printf("\nIDE write: device %d block # %lld, count %ld ... ",
+                               curr_device, blk, cnt);
+#else
+                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
+
+                       printf("\nIDE write: device %d block # %ld, count %ld ... ",
+                               curr_device, blk, cnt);
+#endif
+                       n = ide_write(&ide_dev_desc[curr_device], blk, cnt,
+                                     (ulong *)addr);
+
+                       printf("%ld blocks written: %s\n",
+                               n, (n == cnt) ? "OK" : "ERROR");
+                       if (n == cnt)
+                               return 0;
+                       else
+                               return 1;
+               } else {
+                       return CMD_RET_USAGE;
+               }
+
+               return rcode;
+       }
+}
+
+int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       return common_diskboot(cmdtp, "ide", argc, argv);
+}
+
+/* ------------------------------------------------------------------------- */
+
+__weak void ide_led(uchar led, uchar status)
+{
+#if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */
+       static uchar led_buffer;        /* Buffer for current LED status */
+
+       uchar *led_port = LED_PORT;
+
+       if (status)             /* switch LED on        */
+               led_buffer |= led;
+       else                    /* switch LED off       */
+               led_buffer &= ~led;
+
+       *led_port = led_buffer;
+#endif
+}
+
+#ifndef CONFIG_IDE_LED /* define LED macros, they are not used anyways */
+# define DEVICE_LED(x) 0
+# define LED_IDE1 1
+# define LED_IDE2 2
+#endif
+
+/* ------------------------------------------------------------------------- */
+
+__weak void ide_outb(int dev, int port, unsigned char val)
+{
+       debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
+             dev, port, val,
+             (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
+
+#if defined(CONFIG_IDE_AHB)
+       if (port) {
+               /* write command */
+               ide_write_register(dev, port, val);
+       } else {
+               /* write data */
+               outb(val, (ATA_CURR_BASE(dev)));
+       }
+#else
+       outb(val, (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
+#endif
+}
+
+__weak unsigned char ide_inb(int dev, int port)
+{
+       uchar val;
+
+#if defined(CONFIG_IDE_AHB)
+       val = ide_read_register(dev, port);
+#else
+       val = inb((ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
+#endif
+
+       debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
+             dev, port,
+             (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)), val);
+       return val;
+}
+
+void ide_init(void)
+{
+       unsigned char c;
+       int i, bus;
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+       extern int ide_devices_found;   /* Initialized in check_ide_device() */
+#endif /* CONFIG_IDE_8xx_PCCARD */
+
+#ifdef CONFIG_IDE_PREINIT
+       WATCHDOG_RESET();
+
+       if (ide_preinit()) {
+               puts("ide_preinit failed\n");
+               return;
+       }
+#endif /* CONFIG_IDE_PREINIT */
+
+       WATCHDOG_RESET();
+
+       /*
+        * Reset the IDE just to be sure.
+        * Light LED's to show
+        */
+       ide_led((LED_IDE1 | LED_IDE2), 1);      /* LED's on     */
+
+       /* ATAPI Drives seems to need a proper IDE Reset */
+       ide_reset();
+
+#ifdef CONFIG_IDE_INIT_POSTRESET
+       WATCHDOG_RESET();
+
+       if (ide_init_postreset()) {
+               puts("ide_preinit_postreset failed\n");
+               return;
+       }
+#endif /* CONFIG_IDE_INIT_POSTRESET */
+
+       /*
+        * Wait for IDE to get ready.
+        * According to spec, this can take up to 31 seconds!
+        */
+       for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
+               int dev =
+                       bus * (CONFIG_SYS_IDE_MAXDEVICE /
+                              CONFIG_SYS_IDE_MAXBUS);
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+               /* Skip non-ide devices from probing */
+               if ((ide_devices_found & (1 << bus)) == 0) {
+                       ide_led((LED_IDE1 | LED_IDE2), 0);      /* LED's off */
+                       continue;
+               }
+#endif
+               printf("Bus %d: ", bus);
+
+               ide_bus_ok[bus] = 0;
+
+               /* Select device
+                */
+               udelay(100000); /* 100 ms */
+               ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
+               udelay(100000); /* 100 ms */
+               i = 0;
+               do {
+                       udelay(10000);  /* 10 ms */
+
+                       c = ide_inb(dev, ATA_STATUS);
+                       i++;
+                       if (i > (ATA_RESET_TIME * 100)) {
+                               puts("** Timeout **\n");
+                               /* LED's off */
+                               ide_led((LED_IDE1 | LED_IDE2), 0);
+                               return;
+                       }
+                       if ((i >= 100) && ((i % 100) == 0))
+                               putc('.');
+
+               } while (c & ATA_STAT_BUSY);
+
+               if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
+                       puts("not available  ");
+                       debug("Status = 0x%02X ", c);
+#ifndef CONFIG_ATAPI           /* ATAPI Devices do not set DRDY */
+               } else if ((c & ATA_STAT_READY) == 0) {
+                       puts("not available  ");
+                       debug("Status = 0x%02X ", c);
+#endif
+               } else {
+                       puts("OK ");
+                       ide_bus_ok[bus] = 1;
+               }
+               WATCHDOG_RESET();
+       }
+
+       putc('\n');
+
+       ide_led((LED_IDE1 | LED_IDE2), 0);      /* LED's off    */
+
+       curr_device = -1;
+       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
+               int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;
+               ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
+               ide_dev_desc[i].if_type = IF_TYPE_IDE;
+               ide_dev_desc[i].dev = i;
+               ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
+               ide_dev_desc[i].blksz = 0;
+               ide_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
+               ide_dev_desc[i].lba = 0;
+               ide_dev_desc[i].block_read = ide_read;
+               ide_dev_desc[i].block_write = ide_write;
+               if (!ide_bus_ok[IDE_BUS(i)])
+                       continue;
+               ide_led(led, 1);        /* LED on       */
+               ide_ident(&ide_dev_desc[i]);
+               ide_led(led, 0);        /* LED off      */
+               dev_print(&ide_dev_desc[i]);
+
+               if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
+                       /* initialize partition type */
+                       init_part(&ide_dev_desc[i]);
+                       if (curr_device < 0)
+                               curr_device = i;
+               }
+       }
+       WATCHDOG_RESET();
+}
+
+/* ------------------------------------------------------------------------- */
+
+#ifdef CONFIG_PARTITIONS
+block_dev_desc_t *ide_get_dev(int dev)
+{
+       return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
+}
+#endif
+
+/* ------------------------------------------------------------------------- */
+
+/* We only need to swap data if we are running on a big endian cpu. */
+#if defined(__LITTLE_ENDIAN)
+__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+       ide_input_data(dev, sect_buf, words);
+}
+#else
+__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+       volatile ushort *pbuf =
+               (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+       ushort *dbuf = (ushort *) sect_buf;
+
+       debug("in input swap data base for read is %lx\n",
+             (unsigned long) pbuf);
+
+       while (words--) {
+#ifdef __MIPS__
+               *dbuf++ = swab16p((u16 *) pbuf);
+               *dbuf++ = swab16p((u16 *) pbuf);
+#else
+               *dbuf++ = ld_le16(pbuf);
+               *dbuf++ = ld_le16(pbuf);
+#endif /* !MIPS */
+       }
+}
+#endif /* __LITTLE_ENDIAN */
+
+
+#if defined(CONFIG_IDE_SWAP_IO)
+__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
+{
+       ushort *dbuf;
+       volatile ushort *pbuf;
+
+       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+       dbuf = (ushort *) sect_buf;
+       while (words--) {
+               EIEIO;
+               *pbuf = *dbuf++;
+               EIEIO;
+               *pbuf = *dbuf++;
+       }
+}
+#else  /* ! CONFIG_IDE_SWAP_IO */
+__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
+{
+#if defined(CONFIG_IDE_AHB)
+       ide_write_data(dev, sect_buf, words);
+#else
+       outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
+#endif
+}
+#endif /* CONFIG_IDE_SWAP_IO */
+
+#if defined(CONFIG_IDE_SWAP_IO)
+__weak void ide_input_data(int dev, ulong *sect_buf, int words)
+{
+       ushort *dbuf;
+       volatile ushort *pbuf;
+
+       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+       dbuf = (ushort *) sect_buf;
+
+       debug("in input data base for read is %lx\n", (unsigned long) pbuf);
+
+       while (words--) {
+               EIEIO;
+               *dbuf++ = *pbuf;
+               EIEIO;
+               *dbuf++ = *pbuf;
+       }
+}
+#else  /* ! CONFIG_IDE_SWAP_IO */
+__weak void ide_input_data(int dev, ulong *sect_buf, int words)
+{
+#if defined(CONFIG_IDE_AHB)
+       ide_read_data(dev, sect_buf, words);
+#else
+       insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
+#endif
+}
+
+#endif /* CONFIG_IDE_SWAP_IO */
+
+/* -------------------------------------------------------------------------
+ */
+static void ide_ident(block_dev_desc_t *dev_desc)
+{
+       unsigned char c;
+       hd_driveid_t iop;
+
+#ifdef CONFIG_ATAPI
+       int retries = 0;
+#endif
+       int device;
+
+       device = dev_desc->dev;
+       printf("  Device %d: ", device);
+
+       ide_led(DEVICE_LED(device), 1); /* LED on       */
+       /* Select device
+        */
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+       dev_desc->if_type = IF_TYPE_IDE;
+#ifdef CONFIG_ATAPI
+
+       retries = 0;
+
+       /* Warning: This will be tricky to read */
+       while (retries <= 1) {
+               /* check signature */
+               if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
+                   (ide_inb(device, ATA_SECT_NUM) == 0x01) &&
+                   (ide_inb(device, ATA_CYL_LOW) == 0x14) &&
+                   (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) {
+                       /* ATAPI Signature found */
+                       dev_desc->if_type = IF_TYPE_ATAPI;
+                       /*
+                        * Start Ident Command
+                        */
+                       ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT);
+                       /*
+                        * Wait for completion - ATAPI devices need more time
+                        * to become ready
+                        */
+                       c = ide_wait(device, ATAPI_TIME_OUT);
+               } else
+#endif
+               {
+                       /*
+                        * Start Ident Command
+                        */
+                       ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT);
+
+                       /*
+                        * Wait for completion
+                        */
+                       c = ide_wait(device, IDE_TIME_OUT);
+               }
+               ide_led(DEVICE_LED(device), 0); /* LED off      */
+
+               if (((c & ATA_STAT_DRQ) == 0) ||
+                   ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
+#ifdef CONFIG_ATAPI
+                       {
+                               /*
+                                * Need to soft reset the device
+                                * in case it's an ATAPI...
+                                */
+                               debug("Retrying...\n");
+                               ide_outb(device, ATA_DEV_HD,
+                                        ATA_LBA | ATA_DEVICE(device));
+                               udelay(100000);
+                               ide_outb(device, ATA_COMMAND, 0x08);
+                               udelay(500000); /* 500 ms */
+                       }
+                       /*
+                        * Select device
+                        */
+                       ide_outb(device, ATA_DEV_HD,
+                                ATA_LBA | ATA_DEVICE(device));
+                       retries++;
+#else
+                       return;
+#endif
+               }
+#ifdef CONFIG_ATAPI
+               else
+                       break;
+       }                       /* see above - ugly to read */
+
+       if (retries == 2)       /* Not found */
+               return;
+#endif
+
+       ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
+
+       ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev,
+                 sizeof(dev_desc->revision));
+       ident_cpy((unsigned char *) dev_desc->vendor, iop.model,
+                 sizeof(dev_desc->vendor));
+       ident_cpy((unsigned char *) dev_desc->product, iop.serial_no,
+                 sizeof(dev_desc->product));
+#ifdef __LITTLE_ENDIAN
+       /*
+        * firmware revision, model, and serial number have Big Endian Byte
+        * order in Word. Convert all three to little endian.
+        *
+        * See CF+ and CompactFlash Specification Revision 2.0:
+        * 6.2.1.6: Identify Drive, Table 39 for more details
+        */
+
+       strswab(dev_desc->revision);
+       strswab(dev_desc->vendor);
+       strswab(dev_desc->product);
+#endif /* __LITTLE_ENDIAN */
+
+       if ((iop.config & 0x0080) == 0x0080)
+               dev_desc->removable = 1;
+       else
+               dev_desc->removable = 0;
+
+#ifdef CONFIG_ATAPI
+       if (dev_desc->if_type == IF_TYPE_ATAPI) {
+               atapi_inquiry(dev_desc);
+               return;
+       }
+#endif /* CONFIG_ATAPI */
+
+#ifdef __BIG_ENDIAN
+       /* swap shorts */
+       dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16);
+#else  /* ! __BIG_ENDIAN */
+       /*
+        * do not swap shorts on little endian
+        *
+        * See CF+ and CompactFlash Specification Revision 2.0:
+        * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details.
+        */
+       dev_desc->lba = iop.lba_capacity;
+#endif /* __BIG_ENDIAN */
+
+#ifdef CONFIG_LBA48
+       if (iop.command_set_2 & 0x0400) {       /* LBA 48 support */
+               dev_desc->lba48 = 1;
+               dev_desc->lba = (unsigned long long) iop.lba48_capacity[0] |
+                       ((unsigned long long) iop.lba48_capacity[1] << 16) |
+                       ((unsigned long long) iop.lba48_capacity[2] << 32) |
+                       ((unsigned long long) iop.lba48_capacity[3] << 48);
+       } else {
+               dev_desc->lba48 = 0;
+       }
+#endif /* CONFIG_LBA48 */
+       /* assuming HD */
+       dev_desc->type = DEV_TYPE_HARDDISK;
+       dev_desc->blksz = ATA_BLOCKSIZE;
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
+       dev_desc->lun = 0;      /* just to fill something in... */
+
+#if 0                          /* only used to test the powersaving mode,
+                                * if enabled, the drive goes after 5 sec
+                                * in standby mode */
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+       c = ide_wait(device, IDE_TIME_OUT);
+       ide_outb(device, ATA_SECT_CNT, 1);
+       ide_outb(device, ATA_LBA_LOW, 0);
+       ide_outb(device, ATA_LBA_MID, 0);
+       ide_outb(device, ATA_LBA_HIGH, 0);
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+       ide_outb(device, ATA_COMMAND, 0xe3);
+       udelay(50);
+       c = ide_wait(device, IDE_TIME_OUT);     /* can't take over 500 ms */
+#endif
+}
+
+
+/* ------------------------------------------------------------------------- */
+
+ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+              void *buffer)
+{
+       int device = block_dev->dev;
+       ulong n = 0;
+       unsigned char c;
+       unsigned char pwrsave = 0;      /* power save */
+
+#ifdef CONFIG_LBA48
+       unsigned char lba48 = 0;
+
+       if (blknr & 0x0000fffff0000000ULL) {
+               /* more than 28 bits used, use 48bit mode */
+               lba48 = 1;
+       }
+#endif
+       debug("ide_read dev %d start " LBAF ", blocks " LBAF " buffer at %lX\n",
+             device, blknr, blkcnt, (ulong) buffer);
+
+       ide_led(DEVICE_LED(device), 1); /* LED on       */
+
+       /* Select device
+        */
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+       c = ide_wait(device, IDE_TIME_OUT);
+
+       if (c & ATA_STAT_BUSY) {
+               printf("IDE read: device %d not ready\n", device);
+               goto IDE_READ_E;
+       }
+
+       /* first check if the drive is in Powersaving mode, if yes,
+        * increase the timeout value */
+       ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR);
+       udelay(50);
+
+       c = ide_wait(device, IDE_TIME_OUT);     /* can't take over 500 ms */
+
+       if (c & ATA_STAT_BUSY) {
+               printf("IDE read: device %d not ready\n", device);
+               goto IDE_READ_E;
+       }
+       if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
+               printf("No Powersaving mode %X\n", c);
+       } else {
+               c = ide_inb(device, ATA_SECT_CNT);
+               debug("Powersaving %02X\n", c);
+               if (c == 0)
+                       pwrsave = 1;
+       }
+
+
+       while (blkcnt-- > 0) {
+
+               c = ide_wait(device, IDE_TIME_OUT);
+
+               if (c & ATA_STAT_BUSY) {
+                       printf("IDE read: device %d not ready\n", device);
+                       break;
+               }
+#ifdef CONFIG_LBA48
+               if (lba48) {
+                       /* write high bits */
+                       ide_outb(device, ATA_SECT_CNT, 0);
+                       ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
+#ifdef CONFIG_SYS_64BIT_LBA
+                       ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
+                       ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
+#else
+                       ide_outb(device, ATA_LBA_MID, 0);
+                       ide_outb(device, ATA_LBA_HIGH, 0);
+#endif
+               }
+#endif
+               ide_outb(device, ATA_SECT_CNT, 1);
+               ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
+               ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
+               ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
+
+#ifdef CONFIG_LBA48
+               if (lba48) {
+                       ide_outb(device, ATA_DEV_HD,
+                                ATA_LBA | ATA_DEVICE(device));
+                       ide_outb(device, ATA_COMMAND, ATA_CMD_READ_EXT);
+
+               } else
+#endif
+               {
+                       ide_outb(device, ATA_DEV_HD, ATA_LBA |
+                                ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
+                       ide_outb(device, ATA_COMMAND, ATA_CMD_READ);
+               }
+
+               udelay(50);
+
+               if (pwrsave) {
+                       /* may take up to 4 sec */
+                       c = ide_wait(device, IDE_SPIN_UP_TIME_OUT);
+                       pwrsave = 0;
+               } else {
+                       /* can't take over 500 ms */
+                       c = ide_wait(device, IDE_TIME_OUT);
+               }
+
+               if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
+                   ATA_STAT_DRQ) {
+                       printf("Error (no IRQ) dev %d blk " LBAF ": status "
+                              "%#02x\n", device, blknr, c);
+                       break;
+               }
+
+               ide_input_data(device, buffer, ATA_SECTORWORDS);
+               (void) ide_inb(device, ATA_STATUS);     /* clear IRQ */
+
+               ++n;
+               ++blknr;
+               buffer += ATA_BLOCKSIZE;
+       }
+IDE_READ_E:
+       ide_led(DEVICE_LED(device), 0); /* LED off      */
+       return (n);
+}
+
+/* ------------------------------------------------------------------------- */
+
+
+ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+               const void *buffer)
+{
+       int device = block_dev->dev;
+       ulong n = 0;
+       unsigned char c;
+
+#ifdef CONFIG_LBA48
+       unsigned char lba48 = 0;
+
+       if (blknr & 0x0000fffff0000000ULL) {
+               /* more than 28 bits used, use 48bit mode */
+               lba48 = 1;
+       }
+#endif
+
+       ide_led(DEVICE_LED(device), 1); /* LED on       */
+
+       /* Select device
+        */
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+
+       while (blkcnt-- > 0) {
+
+               c = ide_wait(device, IDE_TIME_OUT);
+
+               if (c & ATA_STAT_BUSY) {
+                       printf("IDE read: device %d not ready\n", device);
+                       goto WR_OUT;
+               }
+#ifdef CONFIG_LBA48
+               if (lba48) {
+                       /* write high bits */
+                       ide_outb(device, ATA_SECT_CNT, 0);
+                       ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
+#ifdef CONFIG_SYS_64BIT_LBA
+                       ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
+                       ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
+#else
+                       ide_outb(device, ATA_LBA_MID, 0);
+                       ide_outb(device, ATA_LBA_HIGH, 0);
+#endif
+               }
+#endif
+               ide_outb(device, ATA_SECT_CNT, 1);
+               ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
+               ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
+               ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
+
+#ifdef CONFIG_LBA48
+               if (lba48) {
+                       ide_outb(device, ATA_DEV_HD,
+                                ATA_LBA | ATA_DEVICE(device));
+                       ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE_EXT);
+
+               } else
+#endif
+               {
+                       ide_outb(device, ATA_DEV_HD, ATA_LBA |
+                                ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
+                       ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE);
+               }
+
+               udelay(50);
+
+               /* can't take over 500 ms */
+               c = ide_wait(device, IDE_TIME_OUT);
+
+               if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
+                   ATA_STAT_DRQ) {
+                       printf("Error (no IRQ) dev %d blk " LBAF ": status "
+                               "%#02x\n", device, blknr, c);
+                       goto WR_OUT;
+               }
+
+               ide_output_data(device, buffer, ATA_SECTORWORDS);
+               c = ide_inb(device, ATA_STATUS);        /* clear IRQ */
+               ++n;
+               ++blknr;
+               buffer += ATA_BLOCKSIZE;
+       }
+WR_OUT:
+       ide_led(DEVICE_LED(device), 0); /* LED off      */
+       return (n);
+}
+
+/* ------------------------------------------------------------------------- */
+
+/*
+ * copy src to dest, skipping leading and trailing blanks and null
+ * terminate the string
+ * "len" is the size of available memory including the terminating '\0'
+ */
+static void ident_cpy(unsigned char *dst, unsigned char *src,
+                     unsigned int len)
+{
+       unsigned char *end, *last;
+
+       last = dst;
+       end = src + len - 1;
+
+       /* reserve space for '\0' */
+       if (len < 2)
+               goto OUT;
+
+       /* skip leading white space */
+       while ((*src) && (src < end) && (*src == ' '))
+               ++src;
+
+       /* copy string, omitting trailing white space */
+       while ((*src) && (src < end)) {
+               *dst++ = *src;
+               if (*src++ != ' ')
+                       last = dst;
+       }
+OUT:
+       *last = '\0';
+}
+
+/* ------------------------------------------------------------------------- */
+
+/*
+ * Wait until Busy bit is off, or timeout (in ms)
+ * Return last status
+ */
+static uchar ide_wait(int dev, ulong t)
+{
+       ulong delay = 10 * t;   /* poll every 100 us */
+       uchar c;
+
+       while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) {
+               udelay(100);
+               if (delay-- == 0)
+                       break;
+       }
+       return (c);
+}
+
+/* ------------------------------------------------------------------------- */
+
+#ifdef CONFIG_IDE_RESET
+extern void ide_set_reset(int idereset);
+
+static void ide_reset(void)
+{
+       int i;
+
+       curr_device = -1;
+       for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i)
+               ide_bus_ok[i] = 0;
+       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i)
+               ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
+
+       ide_set_reset(1);       /* assert reset */
+
+       /* the reset signal shall be asserted for et least 25 us */
+       udelay(25);
+
+       WATCHDOG_RESET();
+
+       /* de-assert RESET signal */
+       ide_set_reset(0);
+
+       /* wait 250 ms */
+       for (i = 0; i < 250; ++i)
+               udelay(1000);
+}
+
+#endif /* CONFIG_IDE_RESET */
+
+/* ------------------------------------------------------------------------- */
+
+#if defined(CONFIG_OF_IDE_FIXUP)
+int ide_device_present(int dev)
+{
+       if (dev >= CONFIG_SYS_IDE_MAXBUS)
+               return 0;
+       return (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1);
+}
+#endif
+/* ------------------------------------------------------------------------- */
+
+#ifdef CONFIG_ATAPI
+/****************************************************************************
+ * ATAPI Support
+ */
+
+#if defined(CONFIG_IDE_SWAP_IO)
+/* since ATAPI may use commands with not 4 bytes alligned length
+ * we have our own transfer functions, 2 bytes alligned */
+__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+       ushort *dbuf;
+       volatile ushort *pbuf;
+
+       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+       dbuf = (ushort *) sect_buf;
+
+       debug("in output data shorts base for read is %lx\n",
+             (unsigned long) pbuf);
+
+       while (shorts--) {
+               EIEIO;
+               *pbuf = *dbuf++;
+       }
+}
+
+__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+       ushort *dbuf;
+       volatile ushort *pbuf;
+
+       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+       dbuf = (ushort *) sect_buf;
+
+       debug("in input data shorts base for read is %lx\n",
+             (unsigned long) pbuf);
+
+       while (shorts--) {
+               EIEIO;
+               *dbuf++ = *pbuf;
+       }
+}
+
+#else  /* ! CONFIG_IDE_SWAP_IO */
+__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+       outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
+}
+
+__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+       insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
+}
+
+#endif /* CONFIG_IDE_SWAP_IO */
+
+/*
+ * Wait until (Status & mask) == res, or timeout (in ms)
+ * Return last status
+ * This is used since some ATAPI CD ROMs clears their Busy Bit first
+ * and then they set their DRQ Bit
+ */
+static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res)
+{
+       ulong delay = 10 * t;   /* poll every 100 us */
+       uchar c;
+
+       /* prevents to read the status before valid */
+       c = ide_inb(dev, ATA_DEV_CTL);
+
+       while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) {
+               /* break if error occurs (doesn't make sense to wait more) */
+               if ((c & ATA_STAT_ERR) == ATA_STAT_ERR)
+                       break;
+               udelay(100);
+               if (delay-- == 0)
+                       break;
+       }
+       return (c);
+}
+
+/*
+ * issue an atapi command
+ */
+unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
+                         unsigned char *buffer, int buflen)
+{
+       unsigned char c, err, mask, res;
+       int n;
+
+       ide_led(DEVICE_LED(device), 1); /* LED on       */
+
+       /* Select device
+        */
+       mask = ATA_STAT_BUSY | ATA_STAT_DRQ;
+       res = 0;
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
+       if ((c & mask) != res) {
+               printf("ATAPI_ISSUE: device %d not ready status %X\n", device,
+                      c);
+               err = 0xFF;
+               goto AI_OUT;
+       }
+       /* write taskfile */
+       ide_outb(device, ATA_ERROR_REG, 0);     /* no DMA, no overlaped */
+       ide_outb(device, ATA_SECT_CNT, 0);
+       ide_outb(device, ATA_SECT_NUM, 0);
+       ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF));
+       ide_outb(device, ATA_CYL_HIGH,
+                (unsigned char) ((buflen >> 8) & 0xFF));
+       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
+
+       ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET);
+       udelay(50);
+
+       mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
+       res = ATA_STAT_DRQ;
+       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
+
+       if ((c & mask) != res) {        /* DRQ must be 1, BSY 0 */
+               printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d status 0x%02x\n",
+                       device, c);
+               err = 0xFF;
+               goto AI_OUT;
+       }
+
+       /* write command block */
+       ide_output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
+
+       /* ATAPI Command written wait for completition */
+       udelay(5000);           /* device must set bsy */
+
+       mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
+       /*
+        * if no data wait for DRQ = 0 BSY = 0
+        * if data wait for DRQ = 1 BSY = 0
+        */
+       res = 0;
+       if (buflen)
+               res = ATA_STAT_DRQ;
+       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
+       if ((c & mask) != res) {
+               if (c & ATA_STAT_ERR) {
+                       err = (ide_inb(device, ATA_ERROR_REG)) >> 4;
+                       debug("atapi_issue 1 returned sense key %X status %02X\n",
+                               err, c);
+               } else {
+                       printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x)  status 0x%02x\n",
+                               ccb[0], c);
+                       err = 0xFF;
+               }
+               goto AI_OUT;
+       }
+       n = ide_inb(device, ATA_CYL_HIGH);
+       n <<= 8;
+       n += ide_inb(device, ATA_CYL_LOW);
+       if (n > buflen) {
+               printf("ERROR, transfer bytes %d requested only %d\n", n,
+                      buflen);
+               err = 0xff;
+               goto AI_OUT;
+       }
+       if ((n == 0) && (buflen < 0)) {
+               printf("ERROR, transfer bytes %d requested %d\n", n, buflen);
+               err = 0xff;
+               goto AI_OUT;
+       }
+       if (n != buflen) {
+               debug("WARNING, transfer bytes %d not equal with requested %d\n",
+                       n, buflen);
+       }
+       if (n != 0) {           /* data transfer */
+               debug("ATAPI_ISSUE: %d Bytes to transfer\n", n);
+               /* we transfer shorts */
+               n >>= 1;
+               /* ok now decide if it is an in or output */
+               if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
+                       debug("Write to device\n");
+                       ide_output_data_shorts(device,
+                               (unsigned short *) buffer, n);
+               } else {
+                       debug("Read from device @ %p shorts %d\n", buffer, n);
+                       ide_input_data_shorts(device,
+                               (unsigned short *) buffer, n);
+               }
+       }
+       udelay(5000);           /* seems that some CD ROMs need this... */
+       mask = ATA_STAT_BUSY | ATA_STAT_ERR;
+       res = 0;
+       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
+       if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
+               err = (ide_inb(device, ATA_ERROR_REG) >> 4);
+               debug("atapi_issue 2 returned sense key %X status %X\n", err,
+                     c);
+       } else {
+               err = 0;
+       }
+AI_OUT:
+       ide_led(DEVICE_LED(device), 0); /* LED off      */
+       return (err);
+}
+
+/*
+ * sending the command to atapi_issue. If an status other than good
+ * returns, an request_sense will be issued
+ */
+
+#define ATAPI_DRIVE_NOT_READY  100
+#define ATAPI_UNIT_ATTN                10
+
+unsigned char atapi_issue_autoreq(int device,
+                                 unsigned char *ccb,
+                                 int ccblen,
+                                 unsigned char *buffer, int buflen)
+{
+       unsigned char sense_data[18], sense_ccb[12];
+       unsigned char res, key, asc, ascq;
+       int notready, unitattn;
+
+       unitattn = ATAPI_UNIT_ATTN;
+       notready = ATAPI_DRIVE_NOT_READY;
+
+retry:
+       res = atapi_issue(device, ccb, ccblen, buffer, buflen);
+       if (res == 0)
+               return 0;       /* Ok */
+
+       if (res == 0xFF)
+               return 0xFF;    /* error */
+
+       debug("(auto_req)atapi_issue returned sense key %X\n", res);
+
+       memset(sense_ccb, 0, sizeof(sense_ccb));
+       memset(sense_data, 0, sizeof(sense_data));
+       sense_ccb[0] = ATAPI_CMD_REQ_SENSE;
+       sense_ccb[4] = 18;      /* allocation Length */
+
+       res = atapi_issue(device, sense_ccb, 12, sense_data, 18);
+       key = (sense_data[2] & 0xF);
+       asc = (sense_data[12]);
+       ascq = (sense_data[13]);
+
+       debug("ATAPI_CMD_REQ_SENSE returned %x\n", res);
+       debug(" Sense page: %02X key %02X ASC %02X ASCQ %02X\n",
+             sense_data[0], key, asc, ascq);
+
+       if ((key == 0))
+               return 0;       /* ok device ready */
+
+       if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */
+               if (unitattn-- > 0) {
+                       udelay(200 * 1000);
+                       goto retry;
+               }
+               printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN);
+               goto error;
+       }
+       if ((asc == 0x4) && (ascq == 0x1)) {
+               /* not ready, but will be ready soon */
+               if (notready-- > 0) {
+                       udelay(200 * 1000);
+                       goto retry;
+               }
+               printf("Drive not ready, tried %d times\n",
+                      ATAPI_DRIVE_NOT_READY);
+               goto error;
+       }
+       if (asc == 0x3a) {
+               debug("Media not present\n");
+               goto error;
+       }
+
+       printf("ERROR: Unknown Sense key %02X ASC %02X ASCQ %02X\n", key, asc,
+              ascq);
+error:
+       debug("ERROR Sense key %02X ASC %02X ASCQ %02X\n", key, asc, ascq);
+       return (0xFF);
+}
+
+
+static void atapi_inquiry(block_dev_desc_t *dev_desc)
+{
+       unsigned char ccb[12];  /* Command descriptor block */
+       unsigned char iobuf[64];        /* temp buf */
+       unsigned char c;
+       int device;
+
+       device = dev_desc->dev;
+       dev_desc->type = DEV_TYPE_UNKNOWN;      /* not yet valid */
+       dev_desc->block_read = atapi_read;
+
+       memset(ccb, 0, sizeof(ccb));
+       memset(iobuf, 0, sizeof(iobuf));
+
+       ccb[0] = ATAPI_CMD_INQUIRY;
+       ccb[4] = 40;            /* allocation Legnth */
+       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 40);
+
+       debug("ATAPI_CMD_INQUIRY returned %x\n", c);
+       if (c != 0)
+               return;
+
+       /* copy device ident strings */
+       ident_cpy((unsigned char *) dev_desc->vendor, &iobuf[8], 8);
+       ident_cpy((unsigned char *) dev_desc->product, &iobuf[16], 16);
+       ident_cpy((unsigned char *) dev_desc->revision, &iobuf[32], 5);
+
+       dev_desc->lun = 0;
+       dev_desc->lba = 0;
+       dev_desc->blksz = 0;
+       dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
+       dev_desc->type = iobuf[0] & 0x1f;
+
+       if ((iobuf[1] & 0x80) == 0x80)
+               dev_desc->removable = 1;
+       else
+               dev_desc->removable = 0;
+
+       memset(ccb, 0, sizeof(ccb));
+       memset(iobuf, 0, sizeof(iobuf));
+       ccb[0] = ATAPI_CMD_START_STOP;
+       ccb[4] = 0x03;          /* start */
+
+       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0);
+
+       debug("ATAPI_CMD_START_STOP returned %x\n", c);
+       if (c != 0)
+               return;
+
+       memset(ccb, 0, sizeof(ccb));
+       memset(iobuf, 0, sizeof(iobuf));
+       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0);
+
+       debug("ATAPI_CMD_UNIT_TEST_READY returned %x\n", c);
+       if (c != 0)
+               return;
+
+       memset(ccb, 0, sizeof(ccb));
+       memset(iobuf, 0, sizeof(iobuf));
+       ccb[0] = ATAPI_CMD_READ_CAP;
+       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 8);
+       debug("ATAPI_CMD_READ_CAP returned %x\n", c);
+       if (c != 0)
+               return;
+
+       debug("Read Cap: LBA %02X%02X%02X%02X blksize %02X%02X%02X%02X\n",
+             iobuf[0], iobuf[1], iobuf[2], iobuf[3],
+             iobuf[4], iobuf[5], iobuf[6], iobuf[7]);
+
+       dev_desc->lba = ((unsigned long) iobuf[0] << 24) +
+               ((unsigned long) iobuf[1] << 16) +
+               ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]);
+       dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
+               ((unsigned long) iobuf[5] << 16) +
+               ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
+#ifdef CONFIG_LBA48
+       /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
+       dev_desc->lba48 = 0;
+#endif
+       return;
+}
+
+
+/*
+ * atapi_read:
+ * we transfer only one block per command, since the multiple DRQ per
+ * command is not yet implemented
+ */
+#define ATAPI_READ_MAX_BYTES   2048    /* we read max 2kbytes */
+#define ATAPI_READ_BLOCK_SIZE  2048    /* assuming CD part */
+#define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
+
+ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+                void *buffer)
+{
+       int device = block_dev->dev;
+       ulong n = 0;
+       unsigned char ccb[12];  /* Command descriptor block */
+       ulong cnt;
+
+       debug("atapi_read dev %d start " LBAF " blocks " LBAF " buffer at %lX\n",
+             device, blknr, blkcnt, (ulong) buffer);
+
+       do {
+               if (blkcnt > ATAPI_READ_MAX_BLOCK)
+                       cnt = ATAPI_READ_MAX_BLOCK;
+               else
+                       cnt = blkcnt;
+
+               ccb[0] = ATAPI_CMD_READ_12;
+               ccb[1] = 0;     /* reserved */
+               ccb[2] = (unsigned char) (blknr >> 24) & 0xFF;  /* MSB Block */
+               ccb[3] = (unsigned char) (blknr >> 16) & 0xFF;  /*  */
+               ccb[4] = (unsigned char) (blknr >> 8) & 0xFF;
+               ccb[5] = (unsigned char) blknr & 0xFF;  /* LSB Block */
+               ccb[6] = (unsigned char) (cnt >> 24) & 0xFF; /* MSB Block cnt */
+               ccb[7] = (unsigned char) (cnt >> 16) & 0xFF;
+               ccb[8] = (unsigned char) (cnt >> 8) & 0xFF;
+               ccb[9] = (unsigned char) cnt & 0xFF;    /* LSB Block */
+               ccb[10] = 0;    /* reserved */
+               ccb[11] = 0;    /* reserved */
+
+               if (atapi_issue_autoreq(device, ccb, 12,
+                                       (unsigned char *) buffer,
+                                       cnt * ATAPI_READ_BLOCK_SIZE)
+                   == 0xFF) {
+                       return (n);
+               }
+               n += cnt;
+               blkcnt -= cnt;
+               blknr += cnt;
+               buffer += (cnt * ATAPI_READ_BLOCK_SIZE);
+       } while (blkcnt > 0);
+       return (n);
+}
+
+/* ------------------------------------------------------------------------- */
+
+#endif /* CONFIG_ATAPI */
+
+U_BOOT_CMD(ide, 5, 1, do_ide,
+          "IDE sub-system",
+          "reset - reset IDE controller\n"
+          "ide info  - show available IDE devices\n"
+          "ide device [dev] - show or set current device\n"
+          "ide part [dev] - print partition table of one or all IDE devices\n"
+          "ide read  addr blk# cnt\n"
+          "ide write addr blk# cnt - read/write `cnt'"
+          " blocks starting at block `blk#'\n"
+          "    to/from memory address `addr'");
+
+U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
+          "boot from IDE device", "loadAddr dev:part");
diff --git a/cmd/immap.c b/cmd/immap.c
new file mode 100644 (file)
index 0000000..1414f9a
--- /dev/null
@@ -0,0 +1,703 @@
+/*
+ * (C) Copyright 2000-2003
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * MPC8xx/MPC8260 Internal Memory Map Functions
+ */
+
+#include <common.h>
+#include <command.h>
+
+#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260)
+
+#if defined(CONFIG_8xx)
+#include <asm/8xx_immap.h>
+#include <commproc.h>
+#include <asm/iopin_8xx.h>
+#elif defined(CONFIG_MPC8260)
+#include <asm/immap_8260.h>
+#include <asm/cpm_8260.h>
+#include <asm/iopin_8260.h>
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static void
+unimplemented ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       printf ("Sorry, but the '%s' command has not been implemented\n",
+               cmdtp->name);
+}
+
+int
+do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile sysconf8xx_t *sc = &immap->im_siu_conf;
+#elif defined(CONFIG_MPC8260)
+       volatile sysconf8260_t *sc = &immap->im_siu_conf;
+#endif
+
+       printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr);
+#if defined(CONFIG_8xx)
+       printf ("SWT   = %08x\n", sc->sc_swt);
+       printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask);
+       printf ("SIEL  = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec);
+       printf ("TESR  = %08x SDCR  = %08x\n", sc->sc_tesr, sc->sc_sdcr);
+#elif defined(CONFIG_MPC8260)
+       printf ("BCR   = %08x\n", sc->sc_bcr);
+       printf ("P_ACR =       %02x P_ALRH= %08x P_ALRL= %08x\n",
+               sc->sc_ppc_acr, sc->sc_ppc_alrh, sc->sc_ppc_alrl);
+       printf ("L_ACR =       %02x L_ALRH= %08x L_ALRL= %08x\n",
+               sc->sc_lcl_acr, sc->sc_lcl_alrh, sc->sc_lcl_alrl);
+       printf ("PTESR1= %08x PTESR2= %08x\n", sc->sc_tescr1, sc->sc_tescr2);
+       printf ("LTESR1= %08x LTESR2= %08x\n", sc->sc_ltescr1, sc->sc_ltescr2);
+       printf ("PDTEA = %08x PDTEM =       %02x\n", sc->sc_pdtea, sc->sc_pdtem);
+       printf ("LDTEA = %08x LDTEM =       %02x\n", sc->sc_ldtea, sc->sc_ldtem);
+#endif
+       return 0;
+}
+
+int
+do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile memctl8xx_t *memctl = &immap->im_memctl;
+       int nbanks = 8;
+#elif defined(CONFIG_MPC8260)
+       volatile memctl8260_t *memctl = &immap->im_memctl;
+       int nbanks = 12;
+#endif
+       volatile uint *p = &memctl->memc_br0;
+       int i;
+
+       for (i = 0; i < nbanks; i++, p += 2) {
+               if (i < 10) {
+                       printf ("BR%d   = %08x OR%d   = %08x\n",
+                               i, p[0], i, p[1]);
+               } else {
+                       printf ("BR%d  = %08x OR%d  = %08x\n",
+                               i, p[0], i, p[1]);
+               }
+       }
+
+       printf ("MAR   = %08x", memctl->memc_mar);
+#if defined(CONFIG_8xx)
+       printf (" MCR   = %08x\n", memctl->memc_mcr);
+#elif defined(CONFIG_MPC8260)
+       putc ('\n');
+#endif
+       printf ("MAMR  = %08x MBMR  = %08x",
+               memctl->memc_mamr, memctl->memc_mbmr);
+#if defined(CONFIG_8xx)
+       printf ("\nMSTAT =     %04x\n", memctl->memc_mstat);
+#elif defined(CONFIG_MPC8260)
+       printf (" MCMR  = %08x\n", memctl->memc_mcmr);
+#endif
+       printf ("MPTPR =     %04x MDR   = %08x\n",
+               memctl->memc_mptpr, memctl->memc_mdr);
+#if defined(CONFIG_MPC8260)
+       printf ("PSDMR = %08x LSDMR = %08x\n",
+               memctl->memc_psdmr, memctl->memc_lsdmr);
+       printf ("PURT  =       %02x PSRT  =       %02x\n",
+               memctl->memc_purt, memctl->memc_psrt);
+       printf ("LURT  =       %02x LSRT  =       %02x\n",
+               memctl->memc_lurt, memctl->memc_lsrt);
+       printf ("IMMR  = %08x\n", memctl->memc_immr);
+#endif
+       return 0;
+}
+
+int
+do_sitinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+#ifdef CONFIG_MPC8260
+int
+do_icinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+#endif
+
+int
+do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile car8xx_t *car = &immap->im_clkrst;
+#elif defined(CONFIG_MPC8260)
+       volatile car8260_t *car = &immap->im_clkrst;
+#endif
+
+#if defined(CONFIG_8xx)
+       printf ("SCCR  = %08x\n", car->car_sccr);
+       printf ("PLPRCR= %08x\n", car->car_plprcr);
+       printf ("RSR   = %08x\n", car->car_rsr);
+#elif defined(CONFIG_MPC8260)
+       printf ("SCCR  = %08x\n", car->car_sccr);
+       printf ("SCMR  = %08x\n", car->car_scmr);
+       printf ("RSR   = %08x\n", car->car_rsr);
+       printf ("RMR   = %08x\n", car->car_rmr);
+#endif
+       return 0;
+}
+
+static int counter;
+
+static void
+header(void)
+{
+       char *data = "\
+       --------------------------------        --------------------------------\
+       00000000001111111111222222222233        00000000001111111111222222222233\
+       01234567890123456789012345678901        01234567890123456789012345678901\
+       --------------------------------        --------------------------------\
+    ";
+       int i;
+
+       if (counter % 2)
+               putc('\n');
+       counter = 0;
+
+       for (i = 0; i < 4; i++, data += 79)
+               printf("%.79s\n", data);
+}
+
+static void binary (char *label, uint value, int nbits)
+{
+       uint mask = 1 << (nbits - 1);
+       int i, second = (counter++ % 2);
+
+       if (second)
+               putc (' ');
+       puts (label);
+       for (i = 32 + 1; i != nbits; i--)
+               putc (' ');
+
+       while (mask != 0) {
+               if (value & mask)
+                       putc ('1');
+               else
+                       putc ('0');
+               mask >>= 1;
+       }
+
+       if (second)
+               putc ('\n');
+}
+
+#if defined(CONFIG_8xx)
+#define PA_NBITS       16
+#define PA_NB_ODR       8
+#define PB_NBITS       18
+#define PB_NB_ODR      16
+#define PC_NBITS       12
+#define PD_NBITS       13
+#elif defined(CONFIG_MPC8260)
+#define PA_NBITS       32
+#define PA_NB_ODR      32
+#define PB_NBITS       28
+#define PB_NB_ODR      28
+#define PC_NBITS       32
+#define PD_NBITS       28
+#endif
+
+int
+do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile iop8xx_t *iop = &immap->im_ioport;
+       volatile ushort *l, *r;
+#elif defined(CONFIG_MPC8260)
+       volatile iop8260_t *iop = &immap->im_ioport;
+       volatile uint *l, *r;
+#endif
+       volatile uint *R;
+
+       counter = 0;
+       header ();
+
+       /*
+        * Ports A & B
+        */
+
+#if defined(CONFIG_8xx)
+       l = &iop->iop_padir;
+       R = &immap->im_cpm.cp_pbdir;
+#elif defined(CONFIG_MPC8260)
+       l = &iop->iop_pdira;
+       R = &iop->iop_pdirb;
+#endif
+       binary ("PA_DIR", *l++, PA_NBITS);
+       binary ("PB_DIR", *R++, PB_NBITS);
+       binary ("PA_PAR", *l++, PA_NBITS);
+       binary ("PB_PAR", *R++, PB_NBITS);
+#if defined(CONFIG_MPC8260)
+       binary ("PA_SOR", *l++, PA_NBITS);
+       binary ("PB_SOR", *R++, PB_NBITS);
+#endif
+       binary ("PA_ODR", *l++, PA_NB_ODR);
+       binary ("PB_ODR", *R++, PB_NB_ODR);
+       binary ("PA_DAT", *l++, PA_NBITS);
+       binary ("PB_DAT", *R++, PB_NBITS);
+
+       header ();
+
+       /*
+        * Ports C & D
+        */
+
+#if defined(CONFIG_8xx)
+       l = &iop->iop_pcdir;
+       r = &iop->iop_pddir;
+#elif defined(CONFIG_MPC8260)
+       l = &iop->iop_pdirc;
+       r = &iop->iop_pdird;
+#endif
+       binary ("PC_DIR", *l++, PC_NBITS);
+       binary ("PD_DIR", *r++, PD_NBITS);
+       binary ("PC_PAR", *l++, PC_NBITS);
+       binary ("PD_PAR", *r++, PD_NBITS);
+#if defined(CONFIG_8xx)
+       binary ("PC_SO ", *l++, PC_NBITS);
+       binary ("      ", 0, 0);
+       r++;
+#elif defined(CONFIG_MPC8260)
+       binary ("PC_SOR", *l++, PC_NBITS);
+       binary ("PD_SOR", *r++, PD_NBITS);
+       binary ("PC_ODR", *l++, PC_NBITS);
+       binary ("PD_ODR", *r++, PD_NBITS);
+#endif
+       binary ("PC_DAT", *l++, PC_NBITS);
+       binary ("PD_DAT", *r++, PD_NBITS);
+#if defined(CONFIG_8xx)
+       binary ("PC_INT", *l++, PC_NBITS);
+#endif
+
+       header ();
+       return 0;
+}
+
+/*
+ * set the io pins
+ * this needs a clean up for smaller tighter code
+ * use *uint and set the address based on cmd + port
+ */
+int
+do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint rcode = 0;
+       iopin_t iopin;
+       static uint port = 0;
+       static uint pin = 0;
+       static uint value = 0;
+       static enum {
+               DIR,
+               PAR,
+               SOR,
+               ODR,
+               DAT,
+#if defined(CONFIG_8xx)
+               INT
+#endif
+       } cmd = DAT;
+
+       if (argc != 5) {
+               puts ("iopset PORT PIN CMD VALUE\n");
+               return 1;
+       }
+       port = argv[1][0] - 'A';
+       if (port > 3)
+               port -= 0x20;
+       if (port > 3)
+               rcode = 1;
+       pin = simple_strtol (argv[2], NULL, 10);
+       if (pin > 31)
+               rcode = 1;
+
+
+       switch (argv[3][0]) {
+       case 'd':
+               if (argv[3][1] == 'a')
+                       cmd = DAT;
+               else if (argv[3][1] == 'i')
+                       cmd = DIR;
+               else
+                       rcode = 1;
+               break;
+       case 'p':
+               cmd = PAR;
+               break;
+       case 'o':
+               cmd = ODR;
+               break;
+       case 's':
+               cmd = SOR;
+               break;
+#if defined(CONFIG_8xx)
+       case 'i':
+               cmd = INT;
+               break;
+#endif
+       default:
+               printf ("iopset: unknown command %s\n", argv[3]);
+               rcode = 1;
+       }
+       if (argv[4][0] == '1')
+               value = 1;
+       else if (argv[4][0] == '0')
+               value = 0;
+       else
+               rcode = 1;
+       if (rcode == 0) {
+               iopin.port = port;
+               iopin.pin = pin;
+               iopin.flag = 0;
+               switch (cmd) {
+               case DIR:
+                       if (value)
+                               iopin_set_out (&iopin);
+                       else
+                               iopin_set_in (&iopin);
+                       break;
+               case PAR:
+                       if (value)
+                               iopin_set_ded (&iopin);
+                       else
+                               iopin_set_gen (&iopin);
+                       break;
+               case SOR:
+                       if (value)
+                               iopin_set_opt2 (&iopin);
+                       else
+                               iopin_set_opt1 (&iopin);
+                       break;
+               case ODR:
+                       if (value)
+                               iopin_set_odr (&iopin);
+                       else
+                               iopin_set_act (&iopin);
+                       break;
+               case DAT:
+                       if (value)
+                               iopin_set_high (&iopin);
+                       else
+                               iopin_set_low (&iopin);
+                       break;
+#if defined(CONFIG_8xx)
+               case INT:
+                       if (value)
+                               iopin_set_falledge (&iopin);
+                       else
+                               iopin_set_anyedge (&iopin);
+                       break;
+#endif
+               }
+
+       }
+       return rcode;
+}
+
+int
+do_dmainfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_fccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+static void prbrg (int n, uint val)
+{
+       uint extc = (val >> 14) & 3;
+       uint cd = (val & CPM_BRG_CD_MASK) >> 1;
+       uint div16 = (val & CPM_BRG_DIV16) != 0;
+
+#if defined(CONFIG_8xx)
+       ulong clock = gd->cpu_clk;
+#elif defined(CONFIG_MPC8260)
+       ulong clock = gd->arch.brg_clk;
+#endif
+
+       printf ("BRG%d:", n);
+
+       if (val & CPM_BRG_RST)
+               puts (" RESET");
+       else
+               puts ("      ");
+
+       if (val & CPM_BRG_EN)
+               puts ("  ENABLED");
+       else
+               puts (" DISABLED");
+
+       printf (" EXTC=%d", extc);
+
+       if (val & CPM_BRG_ATB)
+               puts (" ATB");
+       else
+               puts ("    ");
+
+       printf (" DIVIDER=%4d", cd);
+       if (extc == 0 && cd != 0) {
+               uint baudrate;
+
+               if (div16)
+                       baudrate = (clock / 16) / (cd + 1);
+               else
+                       baudrate = clock / (cd + 1);
+
+               printf ("=%6d bps", baudrate);
+       } else {
+               puts ("           ");
+       }
+
+       if (val & CPM_BRG_DIV16)
+               puts (" DIV16");
+       else
+               puts ("      ");
+
+       putc ('\n');
+}
+
+int
+do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile cpm8xx_t *cp = &immap->im_cpm;
+       volatile uint *p = &cp->cp_brgc1;
+#elif defined(CONFIG_MPC8260)
+       volatile uint *p = &immap->im_brgc1;
+#endif
+       int i = 1;
+
+       while (i <= 4)
+               prbrg (i++, *p++);
+
+#if defined(CONFIG_MPC8260)
+       p = &immap->im_brgc5;
+       while (i <= 8)
+               prbrg (i++, *p++);
+#endif
+       return 0;
+}
+
+int
+do_i2cinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+
+#if defined(CONFIG_8xx)
+       volatile i2c8xx_t *i2c = &immap->im_i2c;
+       volatile cpm8xx_t *cp = &immap->im_cpm;
+       volatile iic_t *iip = (iic_t *) & cp->cp_dparam[PROFF_IIC];
+#elif defined(CONFIG_MPC8260)
+       volatile i2c8260_t *i2c = &immap->im_i2c;
+       volatile iic_t *iip;
+       uint dpaddr;
+
+       dpaddr = immap->im_dprambase16[PROFF_I2C_BASE / sizeof(u16)];
+       if (dpaddr == 0)
+               iip = NULL;
+       else
+               iip = (iic_t *) & immap->im_dprambase[dpaddr];
+#endif
+
+       printf ("I2MOD = %02x I2ADD = %02x\n", i2c->i2c_i2mod, i2c->i2c_i2add);
+       printf ("I2BRG = %02x I2COM = %02x\n", i2c->i2c_i2brg, i2c->i2c_i2com);
+       printf ("I2CER = %02x I2CMR = %02x\n", i2c->i2c_i2cer, i2c->i2c_i2cmr);
+
+       if (iip == NULL)
+               puts ("i2c parameter ram not allocated\n");
+       else {
+               printf ("RBASE = %08x TBASE = %08x\n",
+                       iip->iic_rbase, iip->iic_tbase);
+               printf ("RFCR  =       %02x TFCR  =       %02x\n",
+                       iip->iic_rfcr, iip->iic_tfcr);
+               printf ("MRBLR =     %04x\n", iip->iic_mrblr);
+               printf ("RSTATE= %08x RDP   = %08x\n",
+                       iip->iic_rstate, iip->iic_rdp);
+               printf ("RBPTR =     %04x RBC   =     %04x\n",
+                       iip->iic_rbptr, iip->iic_rbc);
+               printf ("RXTMP = %08x\n", iip->iic_rxtmp);
+               printf ("TSTATE= %08x TDP   = %08x\n",
+                       iip->iic_tstate, iip->iic_tdp);
+               printf ("TBPTR =     %04x TBC   =     %04x\n",
+                       iip->iic_tbptr, iip->iic_tbc);
+               printf ("TXTMP = %08x\n", iip->iic_txtmp);
+       }
+       return 0;
+}
+
+int
+do_sccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_smcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_spiinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_muxinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_siinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+int
+do_mccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unimplemented (cmdtp, flag, argc, argv);
+       return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       siuinfo,        1,      1,      do_siuinfo,
+       "print System Interface Unit (SIU) registers",
+       ""
+);
+
+U_BOOT_CMD(
+       memcinfo,       1,      1,      do_memcinfo,
+       "print Memory Controller registers",
+       ""
+);
+
+U_BOOT_CMD(
+       sitinfo,        1,      1,      do_sitinfo,
+       "print System Integration Timers (SIT) registers",
+       ""
+);
+
+#ifdef CONFIG_MPC8260
+U_BOOT_CMD(
+       icinfo, 1,      1,      do_icinfo,
+       "print Interrupt Controller registers",
+       ""
+);
+#endif
+
+U_BOOT_CMD(
+       carinfo,        1,      1,      do_carinfo,
+       "print Clocks and Reset registers",
+       ""
+);
+
+U_BOOT_CMD(
+       iopinfo,        1,      1,      do_iopinfo,
+       "print I/O Port registers",
+       ""
+);
+
+U_BOOT_CMD(
+       iopset, 5,      0,      do_iopset,
+       "set I/O Port registers",
+       "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
+);
+
+U_BOOT_CMD(
+       dmainfo,        1,      1,      do_dmainfo,
+       "print SDMA/IDMA registers",
+       ""
+);
+
+U_BOOT_CMD(
+       fccinfo,        1,      1,      do_fccinfo,
+       "print FCC registers",
+       ""
+);
+
+U_BOOT_CMD(
+       brginfo,        1,      1,      do_brginfo,
+       "print Baud Rate Generator (BRG) registers",
+       ""
+);
+
+U_BOOT_CMD(
+       i2cinfo,        1,      1,      do_i2cinfo,
+       "print I2C registers",
+       ""
+);
+
+U_BOOT_CMD(
+       sccinfo,        1,      1,      do_sccinfo,
+       "print SCC registers",
+       ""
+);
+
+U_BOOT_CMD(
+       smcinfo,        1,      1,      do_smcinfo,
+       "print SMC registers",
+       ""
+);
+
+U_BOOT_CMD(
+       spiinfo,        1,      1,      do_spiinfo,
+       "print Serial Peripheral Interface (SPI) registers",
+       ""
+);
+
+U_BOOT_CMD(
+       muxinfo,        1,      1,      do_muxinfo,
+       "print CPM Multiplexing registers",
+       ""
+);
+
+U_BOOT_CMD(
+       siinfo, 1,      1,      do_siinfo,
+       "print Serial Interface (SI) registers",
+       ""
+);
+
+U_BOOT_CMD(
+       mccinfo,        1,      1,      do_mccinfo,
+       "print MCC registers",
+       ""
+);
+
+#endif
diff --git a/cmd/ini.c b/cmd/ini.c
new file mode 100644 (file)
index 0000000..727fd1c
--- /dev/null
+++ b/cmd/ini.c
@@ -0,0 +1,252 @@
+/*
+ * inih -- simple .INI file parser
+ *
+ * Copyright (c) 2009, Brush Technology
+ * Copyright (c) 2012:
+ *              Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:    BSD-3-Clause
+ *
+ * Go to the project home page for more info:
+ * http://code.google.com/p/inih/
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+
+#ifdef CONFIG_INI_MAX_LINE
+#define MAX_LINE CONFIG_INI_MAX_LINE
+#else
+#define MAX_LINE 200
+#endif
+
+#ifdef CONFIG_INI_MAX_SECTION
+#define MAX_SECTION CONFIG_INI_MAX_SECTION
+#else
+#define MAX_SECTION 50
+#endif
+
+#ifdef CONFIG_INI_MAX_NAME
+#define MAX_NAME CONFIG_INI_MAX_NAME
+#else
+#define MAX_NAME 50
+#endif
+
+/* Strip whitespace chars off end of given string, in place. Return s. */
+static char *rstrip(char *s)
+{
+       char *p = s + strlen(s);
+
+       while (p > s && isspace(*--p))
+               *p = '\0';
+       return s;
+}
+
+/* Return pointer to first non-whitespace char in given string. */
+static char *lskip(const char *s)
+{
+       while (*s && isspace(*s))
+               s++;
+       return (char *)s;
+}
+
+/* Return pointer to first char c or ';' comment in given string, or pointer to
+   null at end of string if neither found. ';' must be prefixed by a whitespace
+   character to register as a comment. */
+static char *find_char_or_comment(const char *s, char c)
+{
+       int was_whitespace = 0;
+
+       while (*s && *s != c && !(was_whitespace && *s == ';')) {
+               was_whitespace = isspace(*s);
+               s++;
+       }
+       return (char *)s;
+}
+
+/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
+static char *strncpy0(char *dest, const char *src, size_t size)
+{
+       strncpy(dest, src, size);
+       dest[size - 1] = '\0';
+       return dest;
+}
+
+/* Emulate the behavior of fgets but on memory */
+static char *memgets(char *str, int num, char **mem, size_t *memsize)
+{
+       char *end;
+       int len;
+       int newline = 1;
+
+       end = memchr(*mem, '\n', *memsize);
+       if (end == NULL) {
+               if (*memsize == 0)
+                       return NULL;
+               end = *mem + *memsize;
+               newline = 0;
+       }
+       len = min((end - *mem) + newline, num);
+       memcpy(str, *mem, len);
+       if (len < num)
+               str[len] = '\0';
+
+       /* prepare the mem vars for the next call */
+       *memsize -= (end - *mem) + newline;
+       *mem += (end - *mem) + newline;
+
+       return str;
+}
+
+/* Parse given INI-style file. May have [section]s, name=value pairs
+   (whitespace stripped), and comments starting with ';' (semicolon). Section
+   is "" if name=value pair parsed before any section heading. name:value
+   pairs are also supported as a concession to Python's ConfigParser.
+
+   For each name=value pair parsed, call handler function with given user
+   pointer as well as section, name, and value (data only valid for duration
+   of handler call). Handler should return nonzero on success, zero on error.
+
+   Returns 0 on success, line number of first error on parse error (doesn't
+   stop on first error).
+*/
+static int ini_parse(char *filestart, size_t filelen,
+       int (*handler)(void *, char *, char *, char *), void *user)
+{
+       /* Uses a fair bit of stack (use heap instead if you need to) */
+       char line[MAX_LINE];
+       char section[MAX_SECTION] = "";
+       char prev_name[MAX_NAME] = "";
+
+       char *curmem = filestart;
+       char *start;
+       char *end;
+       char *name;
+       char *value;
+       size_t memleft = filelen;
+       int lineno = 0;
+       int error = 0;
+
+       /* Scan through file line by line */
+       while (memgets(line, sizeof(line), &curmem, &memleft) != NULL) {
+               lineno++;
+               start = lskip(rstrip(line));
+
+               if (*start == ';' || *start == '#') {
+                       /*
+                        * Per Python ConfigParser, allow '#' comments at start
+                        * of line
+                        */
+               }
+#if CONFIG_INI_ALLOW_MULTILINE
+               else if (*prev_name && *start && start > line) {
+                       /*
+                        * Non-blank line with leading whitespace, treat as
+                        * continuation of previous name's value (as per Python
+                        * ConfigParser).
+                        */
+                       if (!handler(user, section, prev_name, start) && !error)
+                               error = lineno;
+               }
+#endif
+               else if (*start == '[') {
+                       /* A "[section]" line */
+                       end = find_char_or_comment(start + 1, ']');
+                       if (*end == ']') {
+                               *end = '\0';
+                               strncpy0(section, start + 1, sizeof(section));
+                               *prev_name = '\0';
+                       } else if (!error) {
+                               /* No ']' found on section line */
+                               error = lineno;
+                       }
+               } else if (*start && *start != ';') {
+                       /* Not a comment, must be a name[=:]value pair */
+                       end = find_char_or_comment(start, '=');
+                       if (*end != '=')
+                               end = find_char_or_comment(start, ':');
+                       if (*end == '=' || *end == ':') {
+                               *end = '\0';
+                               name = rstrip(start);
+                               value = lskip(end + 1);
+                               end = find_char_or_comment(value, '\0');
+                               if (*end == ';')
+                                       *end = '\0';
+                               rstrip(value);
+                               /* Strip double-quotes */
+                               if (value[0] == '"' &&
+                                   value[strlen(value)-1] == '"') {
+                                       value[strlen(value)-1] = '\0';
+                                       value += 1;
+                               }
+
+                               /*
+                                * Valid name[=:]value pair found, call handler
+                                */
+                               strncpy0(prev_name, name, sizeof(prev_name));
+                               if (!handler(user, section, name, value) &&
+                                    !error)
+                                       error = lineno;
+                       } else if (!error)
+                               /* No '=' or ':' found on name[=:]value line */
+                               error = lineno;
+               }
+       }
+
+       return error;
+}
+
+static int ini_handler(void *user, char *section, char *name, char *value)
+{
+       char *requested_section = (char *)user;
+#ifdef CONFIG_INI_CASE_INSENSITIVE
+       int i;
+
+       for (i = 0; i < strlen(requested_section); i++)
+               requested_section[i] = tolower(requested_section[i]);
+       for (i = 0; i < strlen(section); i++)
+               section[i] = tolower(section[i]);
+#endif
+
+       if (!strcmp(section, requested_section)) {
+#ifdef CONFIG_INI_CASE_INSENSITIVE
+               for (i = 0; i < strlen(name); i++)
+                       name[i] = tolower(name[i]);
+               for (i = 0; i < strlen(value); i++)
+                       value[i] = tolower(value[i]);
+#endif
+               setenv(name, value);
+               printf("ini: Imported %s as %s\n", name, value);
+       }
+
+       /* success */
+       return 1;
+}
+
+static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *section;
+       char *file_address;
+       size_t file_size;
+
+       if (argc == 1)
+               return CMD_RET_USAGE;
+
+       section = argv[1];
+       file_address = (char *)simple_strtoul(
+               argc < 3 ? getenv("loadaddr") : argv[2], NULL, 16);
+       file_size = (size_t)simple_strtoul(
+               argc < 4 ? getenv("filesize") : argv[3], NULL, 16);
+
+       return ini_parse(file_address, file_size, ini_handler, (void *)section);
+}
+
+U_BOOT_CMD(
+       ini, 4, 0, do_ini,
+       "parse an ini file in memory and merge the specified section into the env",
+       "section [[file-address] file-size]"
+);
diff --git a/cmd/io.c b/cmd/io.c
new file mode 100644 (file)
index 0000000..c59148f
--- /dev/null
+++ b/cmd/io.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2012 The Chromium OS Authors.
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+/*
+ * IO space access commands.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/io.h>
+
+/*
+ * IO Display
+ *
+ * Syntax:
+ *     iod{.b, .w, .l} {addr}
+ */
+int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       ulong addr;
+       int size;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       size = cmd_get_data_size(argv[0], 4);
+       if (size < 0)
+               return 1;
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+
+       printf("%04x: ", (u16) addr);
+
+       if (size == 4)
+               printf("%08x\n", inl(addr));
+       else if (size == 2)
+               printf("%04x\n", inw(addr));
+       else
+               printf("%02x\n", inb(addr));
+
+       return 0;
+}
+
+int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       ulong addr, size, val;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       size = cmd_get_data_size(argv[0], 4);
+       if (size < 0)
+               return 1;
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+       val = simple_strtoul(argv[2], NULL, 16);
+
+       if (size == 4)
+               outl((u32) val, addr);
+       else if (size == 2)
+               outw((u16) val, addr);
+       else
+               outb((u8) val, addr);
+
+       return 0;
+}
+
+/**************************************************/
+U_BOOT_CMD(iod, 2, 0, do_io_iod,
+          "IO space display", "[.b, .w, .l] address");
+
+U_BOOT_CMD(iow, 3, 0, do_io_iow,
+          "IO space modify",
+          "[.b, .w, .l] address value");
diff --git a/cmd/iotrace.c b/cmd/iotrace.c
new file mode 100644 (file)
index 0000000..f54276d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <iotrace.h>
+
+static void do_print_stats(void)
+{
+       ulong start, size, offset, count;
+
+       printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
+       iotrace_get_buffer(&start, &size, &offset, &count);
+       printf("Start:  %08lx\n", start);
+       printf("Size:   %08lx\n", size);
+       printf("Offset: %08lx\n", offset);
+       printf("Output: %08lx\n", start + offset);
+       printf("Count:  %08lx\n", count);
+       printf("CRC32:  %08lx\n", (ulong)iotrace_get_checksum());
+}
+
+static int do_set_buffer(int argc, char * const argv[])
+{
+       ulong addr = 0, size = 0;
+
+       if (argc == 2) {
+               addr = simple_strtoul(*argv++, NULL, 16);
+               size = simple_strtoul(*argv++, NULL, 16);
+       } else if (argc != 0) {
+               return CMD_RET_USAGE;
+       }
+
+       iotrace_set_buffer(addr, size);
+
+       return 0;
+}
+
+int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *cmd = argc < 2 ? NULL : argv[1];
+
+       if (!cmd)
+               return cmd_usage(cmdtp);
+       switch (*cmd) {
+       case 'b':
+               return do_set_buffer(argc - 2, argv + 2);
+       case 'p':
+               iotrace_set_enabled(0);
+               break;
+       case 'r':
+               iotrace_set_enabled(1);
+               break;
+       case 's':
+               do_print_stats();
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       iotrace,        4,      1,      do_iotrace,
+       "iotrace utility commands",
+       "stats                        - display iotrace stats\n"
+       "iotrace buffer <address> <size>      - set iotrace buffer\n"
+       "iotrace pause                        - pause tracing\n"
+       "iotrace resume                       - resume tracing"
+);
diff --git a/cmd/irq.c b/cmd/irq.c
new file mode 100644 (file)
index 0000000..02da450
--- /dev/null
+++ b/cmd/irq.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+
+static int do_interrupts(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char * const argv[])
+{
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       /* on */
+       if (strncmp(argv[1], "on", 2) == 0)
+               enable_interrupts();
+       else
+               disable_interrupts();
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       interrupts, 5, 0, do_interrupts,
+       "enable or disable interrupts",
+       "[on, off]"
+);
+
+/* Implemented in $(CPU)/interrupts.c */
+int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
+U_BOOT_CMD(
+       irqinfo,    1,    1,     do_irqinfo,
+       "print information about IRQs",
+       ""
+);
diff --git a/cmd/itest.c b/cmd/itest.c
new file mode 100644 (file)
index 0000000..91ae5c2
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * (C) Copyright 2003
+ * Tait Electronics Limited, Christchurch, New Zealand
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * This file provides a shell like 'test' function to return
+ * true/false from an integer or string compare of two memory
+ * locations or a location and a scalar/literal.
+ * A few parts were lifted from bash 'test' command
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <mapmem.h>
+
+#include <asm/io.h>
+
+#define EQ     0
+#define NE     1
+#define LT     2
+#define GT     3
+#define LE     4
+#define GE     5
+
+struct op_tbl_s {
+       char    *op;            /* operator string */
+       int     opcode;         /* internal representation of opcode */
+};
+
+typedef struct op_tbl_s op_tbl_t;
+
+static const op_tbl_t op_table [] = {
+       { "-lt", LT },
+       { "<"  , LT },
+       { "-gt", GT },
+       { ">"  , GT },
+       { "-eq", EQ },
+       { "==" , EQ },
+       { "-ne", NE },
+       { "!=" , NE },
+       { "<>" , NE },
+       { "-ge", GE },
+       { ">=" , GE },
+       { "-le", LE },
+       { "<=" , LE },
+};
+
+static long evalexp(char *s, int w)
+{
+       long l = 0;
+       unsigned long addr;
+       void *buf;
+
+       /* if the parameter starts with a * then assume is a pointer to the value we want */
+       if (s[0] == '*') {
+               addr = simple_strtoul(&s[1], NULL, 16);
+               buf = map_physmem(addr, w, MAP_WRBACK);
+               if (!buf) {
+                       puts("Failed to map physical memory\n");
+                       return 0;
+               }
+               switch (w) {
+               case 1:
+                       l = (long)(*(unsigned char *)buf);
+                       break;
+               case 2:
+                       l = (long)(*(unsigned short *)buf);
+                       break;
+               case 4:
+                       l = (long)(*(unsigned long *)buf);
+                       break;
+               }
+               unmap_physmem(buf, w);
+               return l;
+       } else {
+               l = simple_strtoul(s, NULL, 16);
+       }
+
+       return l & ((1UL << (w * 8)) - 1);
+}
+
+static char * evalstr(char *s)
+{
+       /* if the parameter starts with a * then assume a string pointer else its a literal */
+       if (s[0] == '*') {
+               return (char *)simple_strtoul(&s[1], NULL, 16);
+       } else if (s[0] == '$') {
+               int i = 2;
+
+               if (s[1] != '{')
+                       return NULL;
+
+               while (s[i] != '}') {
+                       if (s[i] == 0)
+                               return NULL;
+                       i++;
+               }
+               s[i] = 0;
+               return  getenv((const char *)&s[2]);
+       } else {
+               return s;
+       }
+}
+
+static int stringcomp(char *s, char *t, int op)
+{
+       int p;
+       char *l, *r;
+
+       l = evalstr(s);
+       r = evalstr(t);
+
+       p = strcmp(l, r);
+       switch (op) {
+       case EQ: return (p == 0);
+       case NE: return (p != 0);
+       case LT: return (p < 0);
+       case GT: return (p > 0);
+       case LE: return (p <= 0);
+       case GE: return (p >= 0);
+       }
+       return (0);
+}
+
+static int arithcomp (char *s, char *t, int op, int w)
+{
+       long l, r;
+
+       l = evalexp (s, w);
+       r = evalexp (t, w);
+
+       switch (op) {
+       case EQ: return (l == r);
+       case NE: return (l != r);
+       case LT: return (l < r);
+       case GT: return (l > r);
+       case LE: return (l <= r);
+       case GE: return (l >= r);
+       }
+       return (0);
+}
+
+static int binary_test(char *op, char *arg1, char *arg2, int w)
+{
+       int len, i;
+       const op_tbl_t *optp;
+
+       len = strlen(op);
+
+       for (optp = (op_tbl_t *)&op_table, i = 0;
+            i < ARRAY_SIZE(op_table);
+            optp++, i++) {
+
+               if ((strncmp (op, optp->op, len) == 0) && (len == strlen (optp->op))) {
+                       if (w == 0) {
+                               return (stringcomp(arg1, arg2, optp->opcode));
+                       } else {
+                               return (arithcomp (arg1, arg2, optp->opcode, w));
+                       }
+               }
+       }
+
+       printf("Unknown operator '%s'\n", op);
+       return 0;       /* op code not found */
+}
+
+/* command line interface to the shell test */
+static int do_itest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int     value, w;
+
+       /* Validate arguments */
+       if ((argc != 4))
+               return CMD_RET_USAGE;
+
+       /* Check for a data width specification.
+        * Defaults to long (4) if no specification.
+        * Uses -2 as 'width' for .s (string) so as not to upset existing code
+        */
+       switch (w = cmd_get_data_size(argv[0], 4)) {
+       case 1:
+       case 2:
+       case 4:
+               value = binary_test (argv[2], argv[1], argv[3], w);
+               break;
+       case -2:
+               value = binary_test (argv[2], argv[1], argv[3], 0);
+               break;
+       case -1:
+       default:
+               puts("Invalid data width specifier\n");
+               value = 0;
+               break;
+       }
+
+       return !value;
+}
+
+U_BOOT_CMD(
+       itest, 4, 0, do_itest,
+       "return true/false on integer compare",
+       "[.b, .w, .l, .s] [*]value1 <op> [*]value2"
+);
diff --git a/cmd/jffs2.c b/cmd/jffs2.c
new file mode 100644 (file)
index 0000000..bce0983
--- /dev/null
@@ -0,0 +1,619 @@
+/*
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2002
+ * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
+ *
+ * (C) Copyright 2003
+ * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
+ *
+ * (C) Copyright 2005
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ *   Added support for reading flash partition table from environment.
+ *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
+ *   kernel tree.
+ *
+ *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
+ *   Copyright 2002 SYSGO Real-Time Solutions GmbH
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Three environment variables are used by the parsing routines:
+ *
+ * 'partition' - keeps current partition identifier
+ *
+ * partition  := <part-id>
+ * <part-id>  := <dev-id>,part_num
+ *
+ *
+ * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
+ *
+ * mtdids=<idmap>[,<idmap>,...]
+ *
+ * <idmap>    := <dev-id>=<mtd-id>
+ * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
+ * <dev-num>  := mtd device number, 0...
+ * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
+ *
+ *
+ * 'mtdparts' - partition list
+ *
+ * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
+ *
+ * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
+ * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
+ * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
+ * <size>     := standard linux memsize OR '-' to denote all remaining space
+ * <offset>   := partition start offset within the device
+ * <name>     := '(' NAME ')'
+ * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
+ *
+ * Notes:
+ * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
+ * - if the above variables are not set defaults for a given target are used
+ *
+ * Examples:
+ *
+ * 1 NOR Flash, with 1 single writable partition:
+ * mtdids=nor0=edb7312-nor
+ * mtdparts=mtdparts=edb7312-nor:-
+ *
+ * 1 NOR Flash with 2 partitions, 1 NAND with one
+ * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
+ * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
+ *
+ */
+
+/*
+ * JFFS2/CRAMFS support
+ */
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <jffs2/jffs2.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+#include <cramfs/cramfs_fs.h>
+
+#if defined(CONFIG_CMD_NAND)
+#include <linux/mtd/nand.h>
+#include <nand.h>
+#endif
+
+#if defined(CONFIG_CMD_ONENAND)
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/onenand.h>
+#include <onenand_uboot.h>
+#endif
+
+/* enable/disable debugging messages */
+#define        DEBUG_JFFS
+#undef DEBUG_JFFS
+
+#ifdef  DEBUG_JFFS
+# define DEBUGF(fmt, args...)  printf(fmt ,##args)
+#else
+# define DEBUGF(fmt, args...)
+#endif
+
+/* special size referring to all the remaining space in a partition */
+#define SIZE_REMAINING         0xFFFFFFFF
+
+/* special offset value, it is used when not provided by user
+ *
+ * this value is used temporarily during parsing, later such offests
+ * are recalculated */
+#define OFFSET_NOT_SPECIFIED   0xFFFFFFFF
+
+/* minimum partition size */
+#define MIN_PART_SIZE          4096
+
+/* this flag needs to be set in part_info struct mask_flags
+ * field for read-only partitions */
+#define MTD_WRITEABLE_CMD              1
+
+/* current active device and partition number */
+#ifdef CONFIG_CMD_MTDPARTS
+/* Use the ones declared in cmd_mtdparts.c */
+extern struct mtd_device *current_mtd_dev;
+extern u8 current_mtd_partnum;
+#else
+/* Use local ones */
+struct mtd_device *current_mtd_dev = NULL;
+u8 current_mtd_partnum = 0;
+#endif
+
+#if defined(CONFIG_CMD_CRAMFS)
+extern int cramfs_check (struct part_info *info);
+extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
+extern int cramfs_ls (struct part_info *info, char *filename);
+extern int cramfs_info (struct part_info *info);
+#else
+/* defining empty macros for function names is ugly but avoids ifdef clutter
+ * all over the code */
+#define cramfs_check(x)                (0)
+#define cramfs_load(x,y,z)     (-1)
+#define cramfs_ls(x,y)         (0)
+#define cramfs_info(x)         (0)
+#endif
+
+#ifndef CONFIG_CMD_MTDPARTS
+/**
+ * Check device number to be within valid range for given device type.
+ *
+ * @param dev device to validate
+ * @return 0 if device is valid, 1 otherwise
+ */
+static int mtd_device_validate(u8 type, u8 num, u32 *size)
+{
+       if (type == MTD_DEV_TYPE_NOR) {
+#if defined(CONFIG_CMD_FLASH)
+               if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
+                       extern flash_info_t flash_info[];
+                       *size = flash_info[num].size;
+
+                       return 0;
+               }
+
+               printf("no such FLASH device: %s%d (valid range 0 ... %d\n",
+                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
+#else
+               printf("support for FLASH devices not present\n");
+#endif
+       } else if (type == MTD_DEV_TYPE_NAND) {
+#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
+               if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
+                       *size = nand_info[num].size;
+                       return 0;
+               }
+
+               printf("no such NAND device: %s%d (valid range 0 ... %d)\n",
+                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
+#else
+               printf("support for NAND devices not present\n");
+#endif
+       } else if (type == MTD_DEV_TYPE_ONENAND) {
+#if defined(CONFIG_CMD_ONENAND)
+               *size = onenand_mtd.size;
+               return 0;
+#else
+               printf("support for OneNAND devices not present\n");
+#endif
+       } else
+               printf("Unknown defice type %d\n", type);
+
+       return 1;
+}
+
+/**
+ * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
+ * return device type and number.
+ *
+ * @param id string describing device id
+ * @param ret_id output pointer to next char after parse completes (output)
+ * @param dev_type parsed device type (output)
+ * @param dev_num parsed device number (output)
+ * @return 0 on success, 1 otherwise
+ */
+static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
+{
+       const char *p = id;
+
+       *dev_type = 0;
+       if (strncmp(p, "nand", 4) == 0) {
+               *dev_type = MTD_DEV_TYPE_NAND;
+               p += 4;
+       } else if (strncmp(p, "nor", 3) == 0) {
+               *dev_type = MTD_DEV_TYPE_NOR;
+               p += 3;
+       } else if (strncmp(p, "onenand", 7) == 0) {
+               *dev_type = MTD_DEV_TYPE_ONENAND;
+               p += 7;
+       } else {
+               printf("incorrect device type in %s\n", id);
+               return 1;
+       }
+
+       if (!isdigit(*p)) {
+               printf("incorrect device number in %s\n", id);
+               return 1;
+       }
+
+       *dev_num = simple_strtoul(p, (char **)&p, 0);
+       if (ret_id)
+               *ret_id = p;
+       return 0;
+}
+
+/*
+ * 'Static' version of command line mtdparts_init() routine. Single partition on
+ * a single device configuration.
+ */
+
+/**
+ * Calculate sector size.
+ *
+ * @return sector size
+ */
+static inline u32 get_part_sector_size_nand(struct mtdids *id)
+{
+#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
+       nand_info_t *nand;
+
+       nand = &nand_info[id->num];
+
+       return nand->erasesize;
+#else
+       BUG();
+       return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *part)
+{
+#if defined(CONFIG_CMD_FLASH)
+       extern flash_info_t flash_info[];
+
+       u32 end_phys, start_phys, sector_size = 0, size = 0;
+       int i;
+       flash_info_t *flash;
+
+       flash = &flash_info[id->num];
+
+       start_phys = flash->start[0] + part->offset;
+       end_phys = start_phys + part->size - 1;
+
+       for (i = 0; i < flash->sector_count; i++) {
+               if (flash->start[i] >= end_phys)
+                       break;
+
+               if (flash->start[i] >= start_phys) {
+                       if (i == flash->sector_count - 1) {
+                               size = flash->start[0] + flash->size - flash->start[i];
+                       } else {
+                               size = flash->start[i+1] - flash->start[i];
+                       }
+
+                       if (sector_size < size)
+                               sector_size = size;
+               }
+       }
+
+       return sector_size;
+#else
+       BUG();
+       return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size_onenand(void)
+{
+#if defined(CONFIG_CMD_ONENAND)
+       struct mtd_info *mtd;
+
+       mtd = &onenand_mtd;
+
+       return mtd->erasesize;
+#else
+       BUG();
+       return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part)
+{
+       if (id->type == MTD_DEV_TYPE_NAND)
+               return get_part_sector_size_nand(id);
+       else if (id->type == MTD_DEV_TYPE_NOR)
+               return get_part_sector_size_nor(id, part);
+       else if (id->type == MTD_DEV_TYPE_ONENAND)
+               return get_part_sector_size_onenand();
+       else
+               DEBUGF("Error: Unknown device type.\n");
+
+       return 0;
+}
+
+/**
+ * Parse and initialize global mtdids mapping and create global
+ * device/partition list.
+ *
+ * 'Static' version of command line mtdparts_init() routine. Single partition on
+ * a single device configuration.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+int mtdparts_init(void)
+{
+       static int initialized = 0;
+       u32 size;
+       char *dev_name;
+
+       DEBUGF("\n---mtdparts_init---\n");
+       if (!initialized) {
+               struct mtdids *id;
+               struct part_info *part;
+
+               initialized = 1;
+               current_mtd_dev = (struct mtd_device *)
+                       malloc(sizeof(struct mtd_device) +
+                                       sizeof(struct part_info) +
+                                       sizeof(struct mtdids));
+               if (!current_mtd_dev) {
+                       printf("out of memory\n");
+                       return 1;
+               }
+               memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
+                      sizeof(struct part_info) + sizeof(struct mtdids));
+
+               id = (struct mtdids *)(current_mtd_dev + 1);
+               part = (struct part_info *)(id + 1);
+
+               /* id */
+               id->mtd_id = "single part";
+
+#if defined(CONFIG_JFFS2_DEV)
+               dev_name = CONFIG_JFFS2_DEV;
+#else
+               dev_name = "nor0";
+#endif
+
+               if ((mtd_id_parse(dev_name, NULL, &id->type, &id->num) != 0) ||
+                               (mtd_device_validate(id->type, id->num, &size) != 0)) {
+                       printf("incorrect device: %s%d\n", MTD_DEV_TYPE(id->type), id->num);
+                       free(current_mtd_dev);
+                       return 1;
+               }
+               id->size = size;
+               INIT_LIST_HEAD(&id->link);
+
+               DEBUGF("dev id: type = %d, num = %d, size = 0x%08lx, mtd_id = %s\n",
+                               id->type, id->num, id->size, id->mtd_id);
+
+               /* partition */
+               part->name = "static";
+               part->auto_name = 0;
+
+#if defined(CONFIG_JFFS2_PART_SIZE)
+               part->size = CONFIG_JFFS2_PART_SIZE;
+#else
+               part->size = SIZE_REMAINING;
+#endif
+
+#if defined(CONFIG_JFFS2_PART_OFFSET)
+               part->offset = CONFIG_JFFS2_PART_OFFSET;
+#else
+               part->offset = 0x00000000;
+#endif
+
+               part->dev = current_mtd_dev;
+               INIT_LIST_HEAD(&part->link);
+
+               /* recalculate size if needed */
+               if (part->size == SIZE_REMAINING)
+                       part->size = id->size - part->offset;
+
+               part->sector_size = get_part_sector_size(id, part);
+
+               DEBUGF("part  : name = %s, size = 0x%08lx, offset = 0x%08lx\n",
+                               part->name, part->size, part->offset);
+
+               /* device */
+               current_mtd_dev->id = id;
+               INIT_LIST_HEAD(&current_mtd_dev->link);
+               current_mtd_dev->num_parts = 1;
+               INIT_LIST_HEAD(&current_mtd_dev->parts);
+               list_add(&part->link, &current_mtd_dev->parts);
+       }
+
+       return 0;
+}
+#endif /* #ifndef CONFIG_CMD_MTDPARTS */
+
+/**
+ * Return pointer to the partition of a requested number from a requested
+ * device.
+ *
+ * @param dev device that is to be searched for a partition
+ * @param part_num requested partition number
+ * @return pointer to the part_info, NULL otherwise
+ */
+static struct part_info* jffs2_part_info(struct mtd_device *dev, unsigned int part_num)
+{
+       struct list_head *entry;
+       struct part_info *part;
+       int num;
+
+       if (!dev)
+               return NULL;
+
+       DEBUGF("\n--- jffs2_part_info: partition number %d for device %s%d (%s)\n",
+                       part_num, MTD_DEV_TYPE(dev->id->type),
+                       dev->id->num, dev->id->mtd_id);
+
+       if (part_num >= dev->num_parts) {
+               printf("invalid partition number %d for device %s%d (%s)\n",
+                               part_num, MTD_DEV_TYPE(dev->id->type),
+                               dev->id->num, dev->id->mtd_id);
+               return NULL;
+       }
+
+       /* locate partition number, return it */
+       num = 0;
+       list_for_each(entry, &dev->parts) {
+               part = list_entry(entry, struct part_info, link);
+
+               if (part_num == num++) {
+                       return part;
+               }
+       }
+
+       return NULL;
+}
+
+/***************************************************/
+/* U-boot commands                                */
+/***************************************************/
+
+/**
+ * Routine implementing fsload u-boot command. This routine tries to load
+ * a requested file from jffs2/cramfs filesystem on a current partition.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *fsname;
+       char *filename;
+       int size;
+       struct part_info *part;
+       ulong offset = load_addr;
+
+       /* pre-set Boot file name */
+       if ((filename = getenv("bootfile")) == NULL) {
+               filename = "uImage";
+       }
+
+       if (argc == 2) {
+               filename = argv[1];
+       }
+       if (argc == 3) {
+               offset = simple_strtoul(argv[1], NULL, 16);
+               load_addr = offset;
+               filename = argv[2];
+       }
+
+       /* make sure we are in sync with env variables */
+       if (mtdparts_init() !=0)
+               return 1;
+
+       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
+
+               /* check partition type for cramfs */
+               fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
+               printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
+
+               if (cramfs_check(part)) {
+                       size = cramfs_load ((char *) offset, part, filename);
+               } else {
+                       /* if this is not cramfs assume jffs2 */
+                       size = jffs2_1pass_load((char *)offset, part, filename);
+               }
+
+               if (size > 0) {
+                       printf("### %s load complete: %d bytes loaded to 0x%lx\n",
+                               fsname, size, offset);
+                       setenv_hex("filesize", size);
+               } else {
+                       printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
+               }
+
+               return !(size > 0);
+       }
+       return 1;
+}
+
+/**
+ * Routine implementing u-boot ls command which lists content of a given
+ * directory on a current partition.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename = "/";
+       int ret;
+       struct part_info *part;
+
+       if (argc == 2)
+               filename = argv[1];
+
+       /* make sure we are in sync with env variables */
+       if (mtdparts_init() !=0)
+               return 1;
+
+       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
+
+               /* check partition type for cramfs */
+               if (cramfs_check(part)) {
+                       ret = cramfs_ls (part, filename);
+               } else {
+                       /* if this is not cramfs assume jffs2 */
+                       ret = jffs2_1pass_ls(part, filename);
+               }
+
+               return ret ? 0 : 1;
+       }
+       return 1;
+}
+
+/**
+ * Routine implementing u-boot fsinfo command. This routine prints out
+ * miscellaneous filesystem informations/statistics.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct part_info *part;
+       char *fsname;
+       int ret;
+
+       /* make sure we are in sync with env variables */
+       if (mtdparts_init() !=0)
+               return 1;
+
+       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
+
+               /* check partition type for cramfs */
+               fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
+               printf("### filesystem type is %s\n", fsname);
+
+               if (cramfs_check(part)) {
+                       ret = cramfs_info (part);
+               } else {
+                       /* if this is not cramfs assume jffs2 */
+                       ret = jffs2_1pass_info(part);
+               }
+
+               return ret ? 0 : 1;
+       }
+       return 1;
+}
+
+/***************************************************/
+U_BOOT_CMD(
+       fsload, 3,      0,      do_jffs2_fsload,
+       "load binary file from a filesystem image",
+       "[ off ] [ filename ]\n"
+       "    - load binary file from flash bank\n"
+       "      with offset 'off'"
+);
+U_BOOT_CMD(
+       ls,     2,      1,      do_jffs2_ls,
+       "list files in a directory (default /)",
+       "[ directory ]"
+);
+
+U_BOOT_CMD(
+       fsinfo, 1,      1,      do_jffs2_fsinfo,
+       "print information about filesystems",
+       ""
+);
+/***************************************************/
diff --git a/cmd/ldrinfo.c b/cmd/ldrinfo.c
new file mode 100644 (file)
index 0000000..2aa56bd
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * U-boot - ldrinfo
+ *
+ * Copyright (c) 2010 Analog Devices Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <config.h>
+#include <common.h>
+#include <command.h>
+
+#include <asm/blackfin.h>
+#include <asm/mach-common/bits/bootrom.h>
+
+static uint32_t ldrinfo_header(const void *addr)
+{
+       uint32_t skip = 0;
+
+#if defined(__ADSPBF561__)
+       /* BF56x has a 4 byte global header */
+       uint32_t header, sign;
+       static const char * const spi_speed[] = {
+               "500K", "1M", "2M", "??",
+       };
+
+       memcpy(&header, addr, sizeof(header));
+
+       sign = (header & GFLAG_56X_SIGN_MASK) >> GFLAG_56X_SIGN_SHIFT;
+       printf("Header: %08X ( %s-bit-flash wait:%i hold:%i spi:%s %s)\n",
+               header,
+               (header & GFLAG_56X_16BIT_FLASH) ? "16" : "8",
+               (header & GFLAG_56X_WAIT_MASK) >> GFLAG_56X_WAIT_SHIFT,
+               (header & GFLAG_56X_HOLD_MASK) >> GFLAG_56X_HOLD_SHIFT,
+               spi_speed[(header & GFLAG_56X_SPI_MASK) >> GFLAG_56X_SPI_SHIFT],
+               sign == GFLAG_56X_SIGN_MAGIC ? "" : "!!hdrsign!! ");
+
+       skip = 4;
+#endif
+
+           /* |Block @ 12345678: 12345678 12345678 12345678 12345678 | */
+#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
+    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
+    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
+       printf("                  Address  Count    Flags\n");
+#else
+       printf("                  BCode    Address  Count    Argument\n");
+#endif
+
+       return skip;
+}
+
+struct ldr_flag {
+       uint16_t flag;
+       const char *desc;
+};
+
+static uint32_t ldrinfo_block(const void *base_addr)
+{
+       uint32_t count;
+
+       printf("Block @ %08X: ", (uint32_t)base_addr);
+
+#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
+    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
+    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
+
+       uint32_t addr, pval;
+       uint16_t flags;
+       int i;
+       static const struct ldr_flag ldr_flags[] = {
+               { BFLAG_53X_ZEROFILL,    "zerofill"  },
+               { BFLAG_53X_RESVECT,     "resvect"   },
+               { BFLAG_53X_INIT,        "init"      },
+               { BFLAG_53X_IGNORE,      "ignore"    },
+               { BFLAG_53X_COMPRESSED,  "compressed"},
+               { BFLAG_53X_FINAL,       "final"     },
+       };
+
+       memcpy(&addr, base_addr, sizeof(addr));
+       memcpy(&count, base_addr+4, sizeof(count));
+       memcpy(&flags, base_addr+8, sizeof(flags));
+
+       printf("%08X %08X %04X ( ", addr, count, flags);
+
+       for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
+               if (flags & ldr_flags[i].flag)
+                       printf("%s ", ldr_flags[i].desc);
+
+       pval = (flags & BFLAG_53X_PFLAG_MASK) >> BFLAG_53X_PFLAG_SHIFT;
+       if (pval)
+               printf("gpio%i ", pval);
+       pval = (flags & BFLAG_53X_PPORT_MASK) >> BFLAG_53X_PPORT_SHIFT;
+       if (pval)
+               printf("port%c ", 'e' + pval);
+
+       if (flags & BFLAG_53X_ZEROFILL)
+               count = 0;
+       if (flags & BFLAG_53X_FINAL)
+               count = 0;
+       else
+               count += sizeof(addr) + sizeof(count) + sizeof(flags);
+
+#else
+
+       const uint8_t *raw8 = base_addr;
+       uint32_t bcode, addr, arg, sign, chk;
+       int i;
+       static const struct ldr_flag ldr_flags[] = {
+               { BFLAG_SAFE,        "safe"      },
+               { BFLAG_AUX,         "aux"       },
+               { BFLAG_FILL,        "fill"      },
+               { BFLAG_QUICKBOOT,   "quickboot" },
+               { BFLAG_CALLBACK,    "callback"  },
+               { BFLAG_INIT,        "init"      },
+               { BFLAG_IGNORE,      "ignore"    },
+               { BFLAG_INDIRECT,    "indirect"  },
+               { BFLAG_FIRST,       "first"     },
+               { BFLAG_FINAL,       "final"     },
+       };
+
+       memcpy(&bcode, base_addr, sizeof(bcode));
+       memcpy(&addr, base_addr+4, sizeof(addr));
+       memcpy(&count, base_addr+8, sizeof(count));
+       memcpy(&arg, base_addr+12, sizeof(arg));
+
+       printf("%08X %08X %08X %08X ( ", bcode, addr, count, arg);
+
+       if (addr % 4)
+               printf("!!addralgn!! ");
+       if (count % 4)
+               printf("!!cntalgn!! ");
+
+       sign = (bcode & BFLAG_HDRSIGN_MASK) >> BFLAG_HDRSIGN_SHIFT;
+       if (sign != BFLAG_HDRSIGN_MAGIC)
+               printf("!!hdrsign!! ");
+
+       chk = 0;
+       for (i = 0; i < 16; ++i)
+               chk ^= raw8[i];
+       if (chk)
+               printf("!!hdrchk!! ");
+
+       printf("dma:%i ", bcode & BFLAG_DMACODE_MASK);
+
+       for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
+               if (bcode & ldr_flags[i].flag)
+                       printf("%s ", ldr_flags[i].desc);
+
+       if (bcode & BFLAG_FILL)
+               count = 0;
+       if (bcode & BFLAG_FINAL)
+               count = 0;
+       else
+               count += sizeof(bcode) + sizeof(addr) + sizeof(count) + sizeof(arg);
+
+#endif
+
+       printf(")\n");
+
+       return count;
+}
+
+static int do_ldrinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const void *addr;
+       uint32_t skip;
+
+       /* Get the address */
+       if (argc < 2)
+               addr = (void *)load_addr;
+       else
+               addr = (void *)simple_strtoul(argv[1], NULL, 16);
+
+       /* Walk the LDR */
+       addr += ldrinfo_header(addr);
+       do {
+               skip = ldrinfo_block(addr);
+               addr += skip;
+       } while (skip);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       ldrinfo, 2, 0, do_ldrinfo,
+       "validate ldr image in memory",
+       "[addr]\n"
+);
diff --git a/cmd/led.c b/cmd/led.c
new file mode 100644 (file)
index 0000000..b0f1a61
--- /dev/null
+++ b/cmd/led.c
@@ -0,0 +1,186 @@
+/*
+ * (C) Copyright 2010
+ * Jason Kridner <jkridner@beagleboard.org>
+ *
+ * Based on cmd_led.c patch from:
+ * http://www.mail-archive.com/u-boot@lists.denx.de/msg06873.html
+ * (C) Copyright 2008
+ * Ulf Samuelsson <ulf.samuelsson@atmel.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <status_led.h>
+
+struct led_tbl_s {
+       char            *string;        /* String for use in the command */
+       led_id_t        mask;           /* Mask used for calling __led_set() */
+       void            (*off)(void);   /* Optional function for turning LED off */
+       void            (*on)(void);    /* Optional function for turning LED on */
+       void            (*toggle)(void);/* Optional function for toggling LED */
+};
+
+typedef struct led_tbl_s led_tbl_t;
+
+static const led_tbl_t led_commands[] = {
+#ifdef CONFIG_BOARD_SPECIFIC_LED
+#ifdef STATUS_LED_BIT
+       { "0", STATUS_LED_BIT, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT1
+       { "1", STATUS_LED_BIT1, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT2
+       { "2", STATUS_LED_BIT2, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT3
+       { "3", STATUS_LED_BIT3, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT4
+       { "4", STATUS_LED_BIT4, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT5
+       { "5", STATUS_LED_BIT5, NULL, NULL, NULL },
+#endif
+#endif
+#ifdef STATUS_LED_GREEN
+       { "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
+#endif
+#ifdef STATUS_LED_YELLOW
+       { "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
+#endif
+#ifdef STATUS_LED_RED
+       { "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
+#endif
+#ifdef STATUS_LED_BLUE
+       { "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
+#endif
+       { NULL, 0, NULL, NULL, NULL }
+};
+
+enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
+
+enum led_cmd get_led_cmd(char *var)
+{
+       if (strcmp(var, "off") == 0)
+               return LED_OFF;
+       if (strcmp(var, "on") == 0)
+               return LED_ON;
+       if (strcmp(var, "toggle") == 0)
+               return LED_TOGGLE;
+       if (strcmp(var, "blink") == 0)
+               return LED_BLINK;
+
+       return -1;
+}
+
+/*
+ * LED drivers providing a blinking LED functionality, like the
+ * PCA9551, can override this empty weak function
+ */
+void __weak __led_blink(led_id_t mask, int freq)
+{
+}
+
+int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i, match = 0;
+       enum led_cmd cmd;
+       int freq;
+
+       /* Validate arguments */
+       if ((argc < 3) || (argc > 4))
+               return CMD_RET_USAGE;
+
+       cmd = get_led_cmd(argv[2]);
+       if (cmd < 0) {
+               return CMD_RET_USAGE;
+       }
+
+       for (i = 0; led_commands[i].string; i++) {
+               if ((strcmp("all", argv[1]) == 0) ||
+                   (strcmp(led_commands[i].string, argv[1]) == 0)) {
+                       match = 1;
+                       switch (cmd) {
+                       case LED_ON:
+                               if (led_commands[i].on)
+                                       led_commands[i].on();
+                               else
+                                       __led_set(led_commands[i].mask,
+                                                         STATUS_LED_ON);
+                               break;
+                       case LED_OFF:
+                               if (led_commands[i].off)
+                                       led_commands[i].off();
+                               else
+                                       __led_set(led_commands[i].mask,
+                                                         STATUS_LED_OFF);
+                               break;
+                       case LED_TOGGLE:
+                               if (led_commands[i].toggle)
+                                       led_commands[i].toggle();
+                               else
+                                       __led_toggle(led_commands[i].mask);
+                               break;
+                       case LED_BLINK:
+                               if (argc != 4)
+                                       return CMD_RET_USAGE;
+
+                               freq = simple_strtoul(argv[3], NULL, 10);
+                               __led_blink(led_commands[i].mask, freq);
+                       }
+                       /* Need to set only 1 led if led_name wasn't 'all' */
+                       if (strcmp("all", argv[1]) != 0)
+                               break;
+               }
+       }
+
+       /* If we ran out of matches, print Usage */
+       if (!match) {
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       led, 4, 1, do_led,
+       "["
+#ifdef CONFIG_BOARD_SPECIFIC_LED
+#ifdef STATUS_LED_BIT
+       "0|"
+#endif
+#ifdef STATUS_LED_BIT1
+       "1|"
+#endif
+#ifdef STATUS_LED_BIT2
+       "2|"
+#endif
+#ifdef STATUS_LED_BIT3
+       "3|"
+#endif
+#ifdef STATUS_LED_BIT4
+       "4|"
+#endif
+#ifdef STATUS_LED_BIT5
+       "5|"
+#endif
+#endif
+#ifdef STATUS_LED_GREEN
+       "green|"
+#endif
+#ifdef STATUS_LED_YELLOW
+       "yellow|"
+#endif
+#ifdef STATUS_LED_RED
+       "red|"
+#endif
+#ifdef STATUS_LED_BLUE
+       "blue|"
+#endif
+       "all] [on|off|toggle|blink] [blink-freq in ms]",
+       "[led_name] [on|off|toggle|blink] sets or clears led(s)"
+);
diff --git a/cmd/license.c b/cmd/license.c
new file mode 100644 (file)
index 0000000..b07de72
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * (C) Copyright 2007 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+
+/* COPYING is currently 15951 bytes in size */
+#define LICENSE_MAX    20480
+
+#include <command.h>
+#include <malloc.h>
+#include <license.h>
+
+int do_license(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *tok, *dst = malloc(LICENSE_MAX);
+       unsigned long len = LICENSE_MAX;
+
+       if (!dst)
+               return -1;
+
+       if (gunzip(dst, LICENSE_MAX, license_gz, &len) != 0) {
+               printf("Error uncompressing license text\n");
+               free(dst);
+               return -1;
+       }
+       puts(dst);
+       free(dst);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       license, 1, 1, do_license,
+       "print GPL license text",
+       ""
+);
diff --git a/cmd/load.c b/cmd/load.c
new file mode 100644 (file)
index 0000000..0aa7937
--- /dev/null
@@ -0,0 +1,1113 @@
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Serial up- and download support
+ */
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <s_record.h>
+#include <net.h>
+#include <exports.h>
+#include <xyzModem.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if defined(CONFIG_CMD_LOADB)
+static ulong load_serial_ymodem(ulong offset, int mode);
+#endif
+
+#if defined(CONFIG_CMD_LOADS)
+static ulong load_serial(long offset);
+static int read_record(char *buf, ulong len);
+# if defined(CONFIG_CMD_SAVES)
+static int save_serial(ulong offset, ulong size);
+static int write_record(char *buf);
+#endif
+
+static int do_echo = 1;
+#endif
+
+/* -------------------------------------------------------------------- */
+
+#if defined(CONFIG_CMD_LOADS)
+static int do_load_serial(cmd_tbl_t *cmdtp, int flag, int argc,
+                         char * const argv[])
+{
+       long offset = 0;
+       ulong addr;
+       int i;
+       char *env_echo;
+       int rcode = 0;
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       int load_baudrate, current_baudrate;
+
+       load_baudrate = current_baudrate = gd->baudrate;
+#endif
+
+       if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
+               do_echo = 1;
+       } else {
+               do_echo = 0;
+       }
+
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       if (argc >= 2) {
+               offset = simple_strtol(argv[1], NULL, 16);
+       }
+       if (argc == 3) {
+               load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
+
+               /* default to current baudrate */
+               if (load_baudrate == 0)
+                       load_baudrate = current_baudrate;
+       }
+       if (load_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ENTER ...\n",
+                       load_baudrate);
+               udelay(50000);
+               gd->baudrate = load_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == '\r')
+                               break;
+               }
+       }
+#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
+       if (argc == 2) {
+               offset = simple_strtol(argv[1], NULL, 16);
+       }
+#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
+
+       printf("## Ready for S-Record download ...\n");
+
+       addr = load_serial(offset);
+
+       /*
+        * Gather any trailing characters (for instance, the ^D which
+        * is sent by 'cu' after sending a file), and give the
+        * box some time (100 * 1 ms)
+        */
+       for (i=0; i<100; ++i) {
+               if (tstc()) {
+                       (void) getc();
+               }
+               udelay(1000);
+       }
+
+       if (addr == ~0) {
+               printf("## S-Record download aborted\n");
+               rcode = 1;
+       } else {
+               printf("## Start Addr      = 0x%08lX\n", addr);
+               load_addr = addr;
+       }
+
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       if (load_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ESC ...\n",
+                       current_baudrate);
+               udelay(50000);
+               gd->baudrate = current_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == 0x1B) /* ESC */
+                               break;
+               }
+       }
+#endif
+       return rcode;
+}
+
+static ulong load_serial(long offset)
+{
+       char    record[SREC_MAXRECLEN + 1];     /* buffer for one S-Record      */
+       char    binbuf[SREC_MAXBINLEN];         /* buffer for binary data       */
+       int     binlen;                         /* no. of data bytes in S-Rec.  */
+       int     type;                           /* return code for record type  */
+       ulong   addr;                           /* load address from S-Record   */
+       ulong   size;                           /* number of bytes transferred  */
+       ulong   store_addr;
+       ulong   start_addr = ~0;
+       ulong   end_addr   =  0;
+       int     line_count =  0;
+
+       while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
+               type = srec_decode(record, &binlen, &addr, binbuf);
+
+               if (type < 0) {
+                       return (~0);            /* Invalid S-Record             */
+               }
+
+               switch (type) {
+               case SREC_DATA2:
+               case SREC_DATA3:
+               case SREC_DATA4:
+                   store_addr = addr + offset;
+#ifndef CONFIG_SYS_NO_FLASH
+                   if (addr2info(store_addr)) {
+                       int rc;
+
+                       rc = flash_write((char *)binbuf,store_addr,binlen);
+                       if (rc != 0) {
+                               flash_perror(rc);
+                               return (~0);
+                       }
+                   } else
+#endif
+                   {
+                       memcpy((char *)(store_addr), binbuf, binlen);
+                   }
+                   if ((store_addr) < start_addr)
+                       start_addr = store_addr;
+                   if ((store_addr + binlen - 1) > end_addr)
+                       end_addr = store_addr + binlen - 1;
+                   break;
+               case SREC_END2:
+               case SREC_END3:
+               case SREC_END4:
+                   udelay(10000);
+                   size = end_addr - start_addr + 1;
+                   printf("\n"
+                           "## First Load Addr = 0x%08lX\n"
+                           "## Last  Load Addr = 0x%08lX\n"
+                           "## Total Size      = 0x%08lX = %ld Bytes\n",
+                           start_addr, end_addr, size, size
+                   );
+                   flush_cache(start_addr, size);
+                   setenv_hex("filesize", size);
+                   return (addr);
+               case SREC_START:
+                   break;
+               default:
+                   break;
+               }
+               if (!do_echo) { /* print a '.' every 100 lines */
+                       if ((++line_count % 100) == 0)
+                               putc('.');
+               }
+       }
+
+       return (~0);                    /* Download aborted             */
+}
+
+static int read_record(char *buf, ulong len)
+{
+       char *p;
+       char c;
+
+       --len;  /* always leave room for terminating '\0' byte */
+
+       for (p=buf; p < buf+len; ++p) {
+               c = getc();             /* read character               */
+               if (do_echo)
+                       putc(c);        /* ... and echo it              */
+
+               switch (c) {
+               case '\r':
+               case '\n':
+                       *p = '\0';
+                       return (p - buf);
+               case '\0':
+               case 0x03:                      /* ^C - Control C               */
+                       return (-1);
+               default:
+                       *p = c;
+               }
+
+           /* Check for the console hangup (if any different from serial) */
+           if (gd->jt->getc != getc) {
+               if (ctrlc()) {
+                   return (-1);
+               }
+           }
+       }
+
+       /* line too long - truncate */
+       *p = '\0';
+       return (p - buf);
+}
+
+#if defined(CONFIG_CMD_SAVES)
+
+int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong offset = 0;
+       ulong size   = 0;
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       int save_baudrate, current_baudrate;
+
+       save_baudrate = current_baudrate = gd->baudrate;
+#endif
+
+       if (argc >= 2) {
+               offset = simple_strtoul(argv[1], NULL, 16);
+       }
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       if (argc >= 3) {
+               size = simple_strtoul(argv[2], NULL, 16);
+       }
+       if (argc == 4) {
+               save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
+
+               /* default to current baudrate */
+               if (save_baudrate == 0)
+                       save_baudrate = current_baudrate;
+       }
+       if (save_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ENTER ...\n",
+                       save_baudrate);
+               udelay(50000);
+               gd->baudrate = save_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == '\r')
+                               break;
+               }
+       }
+#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
+       if (argc == 3) {
+               size = simple_strtoul(argv[2], NULL, 16);
+       }
+#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
+
+       printf("## Ready for S-Record upload, press ENTER to proceed ...\n");
+       for (;;) {
+               if (getc() == '\r')
+                       break;
+       }
+       if (save_serial(offset, size)) {
+               printf("## S-Record upload aborted\n");
+       } else {
+               printf("## S-Record upload complete\n");
+       }
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+       if (save_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ESC ...\n",
+                       (int)current_baudrate);
+               udelay(50000);
+               gd->baudrate = current_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == 0x1B) /* ESC */
+                               break;
+               }
+       }
+#endif
+       return 0;
+}
+
+#define SREC3_START                            "S0030000FC\n"
+#define SREC3_FORMAT                   "S3%02X%08lX%s%02X\n"
+#define SREC3_END                              "S70500000000FA\n"
+#define SREC_BYTES_PER_RECORD  16
+
+static int save_serial(ulong address, ulong count)
+{
+       int i, c, reclen, checksum, length;
+       char *hex = "0123456789ABCDEF";
+       char    record[2*SREC_BYTES_PER_RECORD+16];     /* buffer for one S-Record      */
+       char    data[2*SREC_BYTES_PER_RECORD+1];        /* buffer for hex data  */
+
+       reclen = 0;
+       checksum  = 0;
+
+       if(write_record(SREC3_START))                   /* write the header */
+               return (-1);
+       do {
+               if(count) {                                             /* collect hex data in the buffer  */
+                       c = *(volatile uchar*)(address + reclen);       /* get one byte    */
+                       checksum += c;                                                  /* accumulate checksum */
+                       data[2*reclen]   = hex[(c>>4)&0x0f];
+                       data[2*reclen+1] = hex[c & 0x0f];
+                       data[2*reclen+2] = '\0';
+                       ++reclen;
+                       --count;
+               }
+               if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
+                       /* enough data collected for one record: dump it */
+                       if(reclen) {    /* build & write a data record: */
+                               /* address + data + checksum */
+                               length = 4 + reclen + 1;
+
+                               /* accumulate length bytes into checksum */
+                               for(i = 0; i < 2; i++)
+                                       checksum += (length >> (8*i)) & 0xff;
+
+                               /* accumulate address bytes into checksum: */
+                               for(i = 0; i < 4; i++)
+                                       checksum += (address >> (8*i)) & 0xff;
+
+                               /* make proper checksum byte: */
+                               checksum = ~checksum & 0xff;
+
+                               /* output one record: */
+                               sprintf(record, SREC3_FORMAT, length, address, data, checksum);
+                               if(write_record(record))
+                                       return (-1);
+                       }
+                       address  += reclen;  /* increment address */
+                       checksum  = 0;
+                       reclen    = 0;
+               }
+       }
+       while(count);
+       if(write_record(SREC3_END))     /* write the final record */
+               return (-1);
+       return(0);
+}
+
+static int write_record(char *buf)
+{
+       char c;
+
+       while((c = *buf++))
+               putc(c);
+
+       /* Check for the console hangup (if any different from serial) */
+
+       if (ctrlc()) {
+           return (-1);
+       }
+       return (0);
+}
+# endif
+
+#endif
+
+
+#if defined(CONFIG_CMD_LOADB)
+/*
+ * loadb command (load binary) included
+ */
+#define XON_CHAR        17
+#define XOFF_CHAR       19
+#define START_CHAR      0x01
+#define ETX_CHAR       0x03
+#define END_CHAR        0x0D
+#define SPACE           0x20
+#define K_ESCAPE        0x23
+#define SEND_TYPE       'S'
+#define DATA_TYPE       'D'
+#define ACK_TYPE        'Y'
+#define NACK_TYPE       'N'
+#define BREAK_TYPE      'B'
+#define tochar(x) ((char) (((x) + SPACE) & 0xff))
+#define untochar(x) ((int) (((x) - SPACE) & 0xff))
+
+static void set_kerm_bin_mode(unsigned long *);
+static int k_recv(void);
+static ulong load_serial_bin(ulong offset);
+
+
+static char his_eol;        /* character he needs at end of packet */
+static int  his_pad_count;  /* number of pad chars he needs */
+static char his_pad_char;   /* pad chars he needs */
+static char his_quote;      /* quote chars he'll use */
+
+static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc,
+                             char * const argv[])
+{
+       ulong offset = 0;
+       ulong addr;
+       int load_baudrate, current_baudrate;
+       int rcode = 0;
+       char *s;
+
+       /* pre-set offset from CONFIG_SYS_LOAD_ADDR */
+       offset = CONFIG_SYS_LOAD_ADDR;
+
+       /* pre-set offset from $loadaddr */
+       if ((s = getenv("loadaddr")) != NULL) {
+               offset = simple_strtoul(s, NULL, 16);
+       }
+
+       load_baudrate = current_baudrate = gd->baudrate;
+
+       if (argc >= 2) {
+               offset = simple_strtoul(argv[1], NULL, 16);
+       }
+       if (argc == 3) {
+               load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
+
+               /* default to current baudrate */
+               if (load_baudrate == 0)
+                       load_baudrate = current_baudrate;
+       }
+
+       if (load_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ENTER ...\n",
+                       load_baudrate);
+               udelay(50000);
+               gd->baudrate = load_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == '\r')
+                               break;
+               }
+       }
+
+       if (strcmp(argv[0],"loady")==0) {
+               printf("## Ready for binary (ymodem) download "
+                       "to 0x%08lX at %d bps...\n",
+                       offset,
+                       load_baudrate);
+
+               addr = load_serial_ymodem(offset, xyzModem_ymodem);
+
+       } else if (strcmp(argv[0],"loadx")==0) {
+               printf("## Ready for binary (xmodem) download "
+                       "to 0x%08lX at %d bps...\n",
+                       offset,
+                       load_baudrate);
+
+               addr = load_serial_ymodem(offset, xyzModem_xmodem);
+
+       } else {
+
+               printf("## Ready for binary (kermit) download "
+                       "to 0x%08lX at %d bps...\n",
+                       offset,
+                       load_baudrate);
+               addr = load_serial_bin(offset);
+
+               if (addr == ~0) {
+                       load_addr = 0;
+                       printf("## Binary (kermit) download aborted\n");
+                       rcode = 1;
+               } else {
+                       printf("## Start Addr      = 0x%08lX\n", addr);
+                       load_addr = addr;
+               }
+       }
+       if (load_baudrate != current_baudrate) {
+               printf("## Switch baudrate to %d bps and press ESC ...\n",
+                       current_baudrate);
+               udelay(50000);
+               gd->baudrate = current_baudrate;
+               serial_setbrg();
+               udelay(50000);
+               for (;;) {
+                       if (getc() == 0x1B) /* ESC */
+                               break;
+               }
+       }
+
+       return rcode;
+}
+
+
+static ulong load_serial_bin(ulong offset)
+{
+       int size, i;
+
+       set_kerm_bin_mode((ulong *) offset);
+       size = k_recv();
+
+       /*
+        * Gather any trailing characters (for instance, the ^D which
+        * is sent by 'cu' after sending a file), and give the
+        * box some time (100 * 1 ms)
+        */
+       for (i=0; i<100; ++i) {
+               if (tstc()) {
+                       (void) getc();
+               }
+               udelay(1000);
+       }
+
+       flush_cache(offset, size);
+
+       printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
+       setenv_hex("filesize", size);
+
+       return offset;
+}
+
+static void send_pad(void)
+{
+       int count = his_pad_count;
+
+       while (count-- > 0)
+               putc(his_pad_char);
+}
+
+/* converts escaped kermit char to binary char */
+static char ktrans(char in)
+{
+       if ((in & 0x60) == 0x40) {
+               return (char) (in & ~0x40);
+       } else if ((in & 0x7f) == 0x3f) {
+               return (char) (in | 0x40);
+       } else
+               return in;
+}
+
+static int chk1(char *buffer)
+{
+       int total = 0;
+
+       while (*buffer) {
+               total += *buffer++;
+       }
+       return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
+}
+
+static void s1_sendpacket(char *packet)
+{
+       send_pad();
+       while (*packet) {
+               putc(*packet++);
+       }
+}
+
+static char a_b[24];
+static void send_ack(int n)
+{
+       a_b[0] = START_CHAR;
+       a_b[1] = tochar(3);
+       a_b[2] = tochar(n);
+       a_b[3] = ACK_TYPE;
+       a_b[4] = '\0';
+       a_b[4] = tochar(chk1(&a_b[1]));
+       a_b[5] = his_eol;
+       a_b[6] = '\0';
+       s1_sendpacket(a_b);
+}
+
+static void send_nack(int n)
+{
+       a_b[0] = START_CHAR;
+       a_b[1] = tochar(3);
+       a_b[2] = tochar(n);
+       a_b[3] = NACK_TYPE;
+       a_b[4] = '\0';
+       a_b[4] = tochar(chk1(&a_b[1]));
+       a_b[5] = his_eol;
+       a_b[6] = '\0';
+       s1_sendpacket(a_b);
+}
+
+
+static void (*os_data_init)(void);
+static void (*os_data_char)(char new_char);
+static int os_data_state, os_data_state_saved;
+static char *os_data_addr, *os_data_addr_saved;
+static char *bin_start_address;
+
+static void bin_data_init(void)
+{
+       os_data_state = 0;
+       os_data_addr = bin_start_address;
+}
+
+static void os_data_save(void)
+{
+       os_data_state_saved = os_data_state;
+       os_data_addr_saved = os_data_addr;
+}
+
+static void os_data_restore(void)
+{
+       os_data_state = os_data_state_saved;
+       os_data_addr = os_data_addr_saved;
+}
+
+static void bin_data_char(char new_char)
+{
+       switch (os_data_state) {
+       case 0:                                 /* data */
+               *os_data_addr++ = new_char;
+               break;
+       }
+}
+
+static void set_kerm_bin_mode(unsigned long *addr)
+{
+       bin_start_address = (char *) addr;
+       os_data_init = bin_data_init;
+       os_data_char = bin_data_char;
+}
+
+
+/* k_data_* simply handles the kermit escape translations */
+static int k_data_escape, k_data_escape_saved;
+static void k_data_init(void)
+{
+       k_data_escape = 0;
+       os_data_init();
+}
+
+static void k_data_save(void)
+{
+       k_data_escape_saved = k_data_escape;
+       os_data_save();
+}
+
+static void k_data_restore(void)
+{
+       k_data_escape = k_data_escape_saved;
+       os_data_restore();
+}
+
+static void k_data_char(char new_char)
+{
+       if (k_data_escape) {
+               /* last char was escape - translate this character */
+               os_data_char(ktrans(new_char));
+               k_data_escape = 0;
+       } else {
+               if (new_char == his_quote) {
+                       /* this char is escape - remember */
+                       k_data_escape = 1;
+               } else {
+                       /* otherwise send this char as-is */
+                       os_data_char(new_char);
+               }
+       }
+}
+
+#define SEND_DATA_SIZE  20
+static char send_parms[SEND_DATA_SIZE];
+static char *send_ptr;
+
+/* handle_send_packet interprits the protocol info and builds and
+   sends an appropriate ack for what we can do */
+static void handle_send_packet(int n)
+{
+       int length = 3;
+       int bytes;
+
+       /* initialize some protocol parameters */
+       his_eol = END_CHAR;             /* default end of line character */
+       his_pad_count = 0;
+       his_pad_char = '\0';
+       his_quote = K_ESCAPE;
+
+       /* ignore last character if it filled the buffer */
+       if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
+               --send_ptr;
+       bytes = send_ptr - send_parms;  /* how many bytes we'll process */
+       do {
+               if (bytes-- <= 0)
+                       break;
+               /* handle MAXL - max length */
+               /* ignore what he says - most I'll take (here) is 94 */
+               a_b[++length] = tochar(94);
+               if (bytes-- <= 0)
+                       break;
+               /* handle TIME - time you should wait for my packets */
+               /* ignore what he says - don't wait for my ack longer than 1 second */
+               a_b[++length] = tochar(1);
+               if (bytes-- <= 0)
+                       break;
+               /* handle NPAD - number of pad chars I need */
+               /* remember what he says - I need none */
+               his_pad_count = untochar(send_parms[2]);
+               a_b[++length] = tochar(0);
+               if (bytes-- <= 0)
+                       break;
+               /* handle PADC - pad chars I need */
+               /* remember what he says - I need none */
+               his_pad_char = ktrans(send_parms[3]);
+               a_b[++length] = 0x40;   /* He should ignore this */
+               if (bytes-- <= 0)
+                       break;
+               /* handle EOL - end of line he needs */
+               /* remember what he says - I need CR */
+               his_eol = untochar(send_parms[4]);
+               a_b[++length] = tochar(END_CHAR);
+               if (bytes-- <= 0)
+                       break;
+               /* handle QCTL - quote control char he'll use */
+               /* remember what he says - I'll use '#' */
+               his_quote = send_parms[5];
+               a_b[++length] = '#';
+               if (bytes-- <= 0)
+                       break;
+               /* handle QBIN - 8-th bit prefixing */
+               /* ignore what he says - I refuse */
+               a_b[++length] = 'N';
+               if (bytes-- <= 0)
+                       break;
+               /* handle CHKT - the clock check type */
+               /* ignore what he says - I do type 1 (for now) */
+               a_b[++length] = '1';
+               if (bytes-- <= 0)
+                       break;
+               /* handle REPT - the repeat prefix */
+               /* ignore what he says - I refuse (for now) */
+               a_b[++length] = 'N';
+               if (bytes-- <= 0)
+                       break;
+               /* handle CAPAS - the capabilities mask */
+               /* ignore what he says - I only do long packets - I don't do windows */
+               a_b[++length] = tochar(2);      /* only long packets */
+               a_b[++length] = tochar(0);      /* no windows */
+               a_b[++length] = tochar(94);     /* large packet msb */
+               a_b[++length] = tochar(94);     /* large packet lsb */
+       } while (0);
+
+       a_b[0] = START_CHAR;
+       a_b[1] = tochar(length);
+       a_b[2] = tochar(n);
+       a_b[3] = ACK_TYPE;
+       a_b[++length] = '\0';
+       a_b[length] = tochar(chk1(&a_b[1]));
+       a_b[++length] = his_eol;
+       a_b[++length] = '\0';
+       s1_sendpacket(a_b);
+}
+
+/* k_recv receives a OS Open image file over kermit line */
+static int k_recv(void)
+{
+       char new_char;
+       char k_state, k_state_saved;
+       int sum;
+       int done;
+       int length;
+       int n, last_n;
+       int len_lo, len_hi;
+
+       /* initialize some protocol parameters */
+       his_eol = END_CHAR;             /* default end of line character */
+       his_pad_count = 0;
+       his_pad_char = '\0';
+       his_quote = K_ESCAPE;
+
+       /* initialize the k_recv and k_data state machine */
+       done = 0;
+       k_state = 0;
+       k_data_init();
+       k_state_saved = k_state;
+       k_data_save();
+       n = 0;                          /* just to get rid of a warning */
+       last_n = -1;
+
+       /* expect this "type" sequence (but don't check):
+          S: send initiate
+          F: file header
+          D: data (multiple)
+          Z: end of file
+          B: break transmission
+        */
+
+       /* enter main loop */
+       while (!done) {
+               /* set the send packet pointer to begining of send packet parms */
+               send_ptr = send_parms;
+
+               /* With each packet, start summing the bytes starting with the length.
+                  Save the current sequence number.
+                  Note the type of the packet.
+                  If a character less than SPACE (0x20) is received - error.
+                */
+
+#if 0
+               /* OLD CODE, Prior to checking sequence numbers */
+               /* first have all state machines save current states */
+               k_state_saved = k_state;
+               k_data_save ();
+#endif
+
+               /* get a packet */
+               /* wait for the starting character or ^C */
+               for (;;) {
+                       switch (getc ()) {
+                       case START_CHAR:        /* start packet */
+                               goto START;
+                       case ETX_CHAR:          /* ^C waiting for packet */
+                               return (0);
+                       default:
+                               ;
+                       }
+               }
+START:
+               /* get length of packet */
+               sum = 0;
+               new_char = getc();
+               if ((new_char & 0xE0) == 0)
+                       goto packet_error;
+               sum += new_char & 0xff;
+               length = untochar(new_char);
+               /* get sequence number */
+               new_char = getc();
+               if ((new_char & 0xE0) == 0)
+                       goto packet_error;
+               sum += new_char & 0xff;
+               n = untochar(new_char);
+               --length;
+
+               /* NEW CODE - check sequence numbers for retried packets */
+               /* Note - this new code assumes that the sequence number is correctly
+                * received.  Handling an invalid sequence number adds another layer
+                * of complexity that may not be needed - yet!  At this time, I'm hoping
+                * that I don't need to buffer the incoming data packets and can write
+                * the data into memory in real time.
+                */
+               if (n == last_n) {
+                       /* same sequence number, restore the previous state */
+                       k_state = k_state_saved;
+                       k_data_restore();
+               } else {
+                       /* new sequence number, checkpoint the download */
+                       last_n = n;
+                       k_state_saved = k_state;
+                       k_data_save();
+               }
+               /* END NEW CODE */
+
+               /* get packet type */
+               new_char = getc();
+               if ((new_char & 0xE0) == 0)
+                       goto packet_error;
+               sum += new_char & 0xff;
+               k_state = new_char;
+               --length;
+               /* check for extended length */
+               if (length == -2) {
+                       /* (length byte was 0, decremented twice) */
+                       /* get the two length bytes */
+                       new_char = getc();
+                       if ((new_char & 0xE0) == 0)
+                               goto packet_error;
+                       sum += new_char & 0xff;
+                       len_hi = untochar(new_char);
+                       new_char = getc();
+                       if ((new_char & 0xE0) == 0)
+                               goto packet_error;
+                       sum += new_char & 0xff;
+                       len_lo = untochar(new_char);
+                       length = len_hi * 95 + len_lo;
+                       /* check header checksum */
+                       new_char = getc();
+                       if ((new_char & 0xE0) == 0)
+                               goto packet_error;
+                       if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
+                               goto packet_error;
+                       sum += new_char & 0xff;
+/* --length; */ /* new length includes only data and block check to come */
+               }
+               /* bring in rest of packet */
+               while (length > 1) {
+                       new_char = getc();
+                       if ((new_char & 0xE0) == 0)
+                               goto packet_error;
+                       sum += new_char & 0xff;
+                       --length;
+                       if (k_state == DATA_TYPE) {
+                               /* pass on the data if this is a data packet */
+                               k_data_char (new_char);
+                       } else if (k_state == SEND_TYPE) {
+                               /* save send pack in buffer as is */
+                               *send_ptr++ = new_char;
+                               /* if too much data, back off the pointer */
+                               if (send_ptr >= &send_parms[SEND_DATA_SIZE])
+                                       --send_ptr;
+                       }
+               }
+               /* get and validate checksum character */
+               new_char = getc();
+               if ((new_char & 0xE0) == 0)
+                       goto packet_error;
+               if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
+                       goto packet_error;
+               /* get END_CHAR */
+               new_char = getc();
+               if (new_char != END_CHAR) {
+                 packet_error:
+                       /* restore state machines */
+                       k_state = k_state_saved;
+                       k_data_restore();
+                       /* send a negative acknowledge packet in */
+                       send_nack(n);
+               } else if (k_state == SEND_TYPE) {
+                       /* crack the protocol parms, build an appropriate ack packet */
+                       handle_send_packet(n);
+               } else {
+                       /* send simple acknowledge packet in */
+                       send_ack(n);
+                       /* quit if end of transmission */
+                       if (k_state == BREAK_TYPE)
+                               done = 1;
+               }
+       }
+       return ((ulong) os_data_addr - (ulong) bin_start_address);
+}
+
+static int getcxmodem(void) {
+       if (tstc())
+               return (getc());
+       return -1;
+}
+static ulong load_serial_ymodem(ulong offset, int mode)
+{
+       int size;
+       int err;
+       int res;
+       connection_info_t info;
+       char ymodemBuf[1024];
+       ulong store_addr = ~0;
+       ulong addr = 0;
+
+       size = 0;
+       info.mode = mode;
+       res = xyzModem_stream_open(&info, &err);
+       if (!res) {
+
+               while ((res =
+                       xyzModem_stream_read(ymodemBuf, 1024, &err)) > 0) {
+                       store_addr = addr + offset;
+                       size += res;
+                       addr += res;
+#ifndef CONFIG_SYS_NO_FLASH
+                       if (addr2info(store_addr)) {
+                               int rc;
+
+                               rc = flash_write((char *) ymodemBuf,
+                                                 store_addr, res);
+                               if (rc != 0) {
+                                       flash_perror (rc);
+                                       return (~0);
+                               }
+                       } else
+#endif
+                       {
+                               memcpy((char *)(store_addr), ymodemBuf,
+                                       res);
+                       }
+
+               }
+       } else {
+               printf("%s\n", xyzModem_error(err));
+       }
+
+       xyzModem_stream_close(&err);
+       xyzModem_stream_terminate(false, &getcxmodem);
+
+
+       flush_cache(offset, size);
+
+       printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
+       setenv_hex("filesize", size);
+
+       return offset;
+}
+
+#endif
+
+/* -------------------------------------------------------------------- */
+
+#if defined(CONFIG_CMD_LOADS)
+
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+U_BOOT_CMD(
+       loads, 3, 0,    do_load_serial,
+       "load S-Record file over serial line",
+       "[ off ] [ baud ]\n"
+       "    - load S-Record file over serial line"
+       " with offset 'off' and baudrate 'baud'"
+);
+
+#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
+U_BOOT_CMD(
+       loads, 2, 0,    do_load_serial,
+       "load S-Record file over serial line",
+       "[ off ]\n"
+       "    - load S-Record file over serial line with offset 'off'"
+);
+#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
+
+/*
+ * SAVES always requires LOADS support, but not vice versa
+ */
+
+
+#if defined(CONFIG_CMD_SAVES)
+#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
+U_BOOT_CMD(
+       saves, 4, 0,    do_save_serial,
+       "save S-Record file over serial line",
+       "[ off ] [size] [ baud ]\n"
+       "    - save S-Record file over serial line"
+       " with offset 'off', size 'size' and baudrate 'baud'"
+);
+#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
+U_BOOT_CMD(
+       saves, 3, 0,    do_save_serial,
+       "save S-Record file over serial line",
+       "[ off ] [size]\n"
+       "    - save S-Record file over serial line with offset 'off' and size 'size'"
+);
+#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
+#endif /* CONFIG_CMD_SAVES */
+#endif /* CONFIG_CMD_LOADS */
+
+
+#if defined(CONFIG_CMD_LOADB)
+U_BOOT_CMD(
+       loadb, 3, 0,    do_load_serial_bin,
+       "load binary file over serial line (kermit mode)",
+       "[ off ] [ baud ]\n"
+       "    - load binary file over serial line"
+       " with offset 'off' and baudrate 'baud'"
+);
+
+U_BOOT_CMD(
+       loadx, 3, 0,    do_load_serial_bin,
+       "load binary file over serial line (xmodem mode)",
+       "[ off ] [ baud ]\n"
+       "    - load binary file over serial line"
+       " with offset 'off' and baudrate 'baud'"
+);
+
+U_BOOT_CMD(
+       loady, 3, 0,    do_load_serial_bin,
+       "load binary file over serial line (ymodem mode)",
+       "[ off ] [ baud ]\n"
+       "    - load binary file over serial line"
+       " with offset 'off' and baudrate 'baud'"
+);
+
+#endif /* CONFIG_CMD_LOADB */
+
+/* -------------------------------------------------------------------- */
+
+#if defined(CONFIG_CMD_HWFLOW)
+int do_hwflow(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       extern int hwflow_onoff(int);
+
+       if (argc == 2) {
+               if (strcmp(argv[1], "off") == 0)
+                       hwflow_onoff(-1);
+               else
+                       if (strcmp(argv[1], "on") == 0)
+                               hwflow_onoff(1);
+                       else
+                               return CMD_RET_USAGE;
+       }
+       printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
+       return 0;
+}
+
+/* -------------------------------------------------------------------- */
+
+U_BOOT_CMD(
+       hwflow, 2, 0,   do_hwflow,
+       "turn RTS/CTS hardware flow control in serial line on/off",
+       "[on|off]"
+);
+
+#endif /* CONFIG_CMD_HWFLOW */
diff --git a/cmd/log.c b/cmd/log.c
new file mode 100644 (file)
index 0000000..873ee40
--- /dev/null
+++ b/cmd/log.c
@@ -0,0 +1,311 @@
+/*
+ * (C) Copyright 2002-2007
+ * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
+ *
+ * Code used from linux/kernel/printk.c
+ * Copyright (C) 1991, 1992  Linus Torvalds
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ *
+ * Comments:
+ *
+ * After relocating the code, the environment variable "loglevel" is
+ * copied to console_loglevel.  The functionality is similar to the
+ * handling in the Linux kernel, i.e. messages logged with a priority
+ * less than console_loglevel are also output to stdout.
+ *
+ * If you want messages with the default level (e.g. POST messages) to
+ * appear on stdout also, make sure the environment variable
+ * "loglevel" is set at boot time to a number higher than
+ * default_message_loglevel below.
+ */
+
+/*
+ * Logbuffer handling routines
+ */
+
+#include <common.h>
+#include <command.h>
+#include <stdio_dev.h>
+#include <post.h>
+#include <logbuff.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Local prototypes */
+static void logbuff_putc(struct stdio_dev *dev, const char c);
+static void logbuff_puts(struct stdio_dev *dev, const char *s);
+static int logbuff_printk(const char *line);
+
+static char buf[1024];
+
+/* This combination will not print messages with the default loglevel */
+static unsigned console_loglevel = 3;
+static unsigned default_message_loglevel = 4;
+static unsigned log_version = 1;
+#ifdef CONFIG_ALT_LB_ADDR
+static volatile logbuff_t *log;
+#else
+static logbuff_t *log;
+#endif
+static char *lbuf;
+
+unsigned long __logbuffer_base(void)
+{
+       return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
+}
+unsigned long logbuffer_base(void)
+__attribute__((weak, alias("__logbuffer_base")));
+
+void logbuff_init_ptrs(void)
+{
+       unsigned long tag, post_word;
+       char *s;
+
+#ifdef CONFIG_ALT_LB_ADDR
+       log = (logbuff_t *)CONFIG_ALT_LH_ADDR;
+       lbuf = (char *)CONFIG_ALT_LB_ADDR;
+#else
+       log = (logbuff_t *)(logbuffer_base()) - 1;
+       lbuf = (char *)log->buf;
+#endif
+
+       /* Set up log version */
+       if ((s = getenv ("logversion")) != NULL)
+               log_version = (int)simple_strtoul(s, NULL, 10);
+
+       if (log_version == 2)
+               tag = log->v2.tag;
+       else
+               tag = log->v1.tag;
+       post_word = post_word_load();
+#ifdef CONFIG_POST
+       /* The post routines have setup the word so we can simply test it */
+       if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT))
+               logbuff_reset();
+#else
+       /* No post routines, so we do our own checking                    */
+       if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) {
+               logbuff_reset ();
+               post_word_store (LOGBUFF_MAGIC);
+       }
+#endif
+       if (log_version == 2 && (long)log->v2.start > (long)log->v2.con)
+               log->v2.start = log->v2.con;
+
+       /* Initialize default loglevel if present */
+       if ((s = getenv ("loglevel")) != NULL)
+               console_loglevel = (int)simple_strtoul(s, NULL, 10);
+
+       gd->flags |= GD_FLG_LOGINIT;
+}
+
+void logbuff_reset(void)
+{
+#ifndef CONFIG_ALT_LB_ADDR
+       memset(log, 0, sizeof(logbuff_t));
+#endif
+       if (log_version == 2) {
+               log->v2.tag = LOGBUFF_MAGIC;
+#ifdef CONFIG_ALT_LB_ADDR
+               log->v2.start = 0;
+               log->v2.con = 0;
+               log->v2.end = 0;
+               log->v2.chars = 0;
+#endif
+       } else {
+               log->v1.tag = LOGBUFF_MAGIC;
+#ifdef CONFIG_ALT_LB_ADDR
+               log->v1.dummy = 0;
+               log->v1.start = 0;
+               log->v1.size = 0;
+               log->v1.chars = 0;
+#endif
+       }
+}
+
+int drv_logbuff_init(void)
+{
+       struct stdio_dev logdev;
+       int rc;
+
+       /* Device initialization */
+       memset (&logdev, 0, sizeof (logdev));
+
+       strcpy (logdev.name, "logbuff");
+       logdev.ext   = 0;                       /* No extensions */
+       logdev.flags = DEV_FLAGS_OUTPUT;        /* Output only */
+       logdev.putc  = logbuff_putc;            /* 'putc' function */
+       logdev.puts  = logbuff_puts;            /* 'puts' function */
+
+       rc = stdio_register(&logdev);
+
+       return (rc == 0) ? 1 : rc;
+}
+
+static void logbuff_putc(struct stdio_dev *dev, const char c)
+{
+       char buf[2];
+       buf[0] = c;
+       buf[1] = '\0';
+       logbuff_printk(buf);
+}
+
+static void logbuff_puts(struct stdio_dev *dev, const char *s)
+{
+       logbuff_printk (s);
+}
+
+void logbuff_log(char *msg)
+{
+       if ((gd->flags & GD_FLG_LOGINIT)) {
+               logbuff_printk(msg);
+       } else {
+               /*
+                * Can happen only for pre-relocated errors as logging
+                * at that stage should be disabled
+                */
+               puts (msg);
+       }
+}
+
+/*
+ * Subroutine:  do_log
+ *
+ * Description: Handler for 'log' command..
+ *
+ * Inputs:     argv[1] contains the subcommand
+ *
+ * Return:      None
+ *
+ */
+int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct stdio_dev *sdev = NULL;
+       char *s;
+       unsigned long i, start, size;
+
+       if (strcmp(argv[1], "append") == 0) {
+               /* Log concatenation of all arguments separated by spaces */
+               for (i = 2; i < argc; i++) {
+                       logbuff_printk(argv[i]);
+                       logbuff_putc(sdev, (i < argc - 1) ? ' ' : '\n');
+               }
+               return 0;
+       }
+
+       switch (argc) {
+
+       case 2:
+               if (strcmp(argv[1], "show") == 0) {
+                       if (log_version == 2) {
+                               start = log->v2.start;
+                               size = log->v2.end - log->v2.start;
+                       } else {
+                               start = log->v1.start;
+                               size = log->v1.size;
+                       }
+                       if (size > LOGBUFF_LEN)
+                               size = LOGBUFF_LEN;
+                       for (i = 0; i < size; i++) {
+                               s = lbuf + ((start + i) & LOGBUFF_MASK);
+                               putc(*s);
+                       }
+                       return 0;
+               } else if (strcmp(argv[1], "reset") == 0) {
+                       logbuff_reset();
+                       return 0;
+               } else if (strcmp(argv[1], "info") == 0) {
+                       printf("Logbuffer   at  %08lx\n", (unsigned long)lbuf);
+                       if (log_version == 2) {
+                               printf("log_start    =  %08lx\n",
+                                       log->v2.start);
+                               printf("log_end      =  %08lx\n", log->v2.end);
+                               printf("log_con      =  %08lx\n", log->v2.con);
+                               printf("logged_chars =  %08lx\n",
+                                       log->v2.chars);
+                       }
+                       else {
+                               printf("log_start    =  %08lx\n",
+                                       log->v1.start);
+                               printf("log_size     =  %08lx\n",
+                                       log->v1.size);
+                               printf("logged_chars =  %08lx\n",
+                                       log->v1.chars);
+                       }
+                       return 0;
+               }
+               return CMD_RET_USAGE;
+
+       default:
+               return CMD_RET_USAGE;
+       }
+}
+
+U_BOOT_CMD(
+       log,     255,   1,      do_log,
+       "manipulate logbuffer",
+       "info   - show pointer details\n"
+       "log reset  - clear contents\n"
+       "log show   - show contents\n"
+       "log append <msg> - append <msg> to the logbuffer"
+);
+
+static int logbuff_printk(const char *line)
+{
+       int i;
+       char *msg, *p, *buf_end;
+       int line_feed;
+       static signed char msg_level = -1;
+
+       strcpy(buf + 3, line);
+       i = strlen(line);
+       buf_end = buf + 3 + i;
+       for (p = buf + 3; p < buf_end; p++) {
+               msg = p;
+               if (msg_level < 0) {
+                       if (
+                               p[0] != '<' ||
+                               p[1] < '0' ||
+                               p[1] > '7' ||
+                               p[2] != '>'
+                       ) {
+                               p -= 3;
+                               p[0] = '<';
+                               p[1] = default_message_loglevel + '0';
+                               p[2] = '>';
+                       } else {
+                               msg += 3;
+                       }
+                       msg_level = p[1] - '0';
+               }
+               line_feed = 0;
+               for (; p < buf_end; p++) {
+                       if (log_version == 2) {
+                               lbuf[log->v2.end & LOGBUFF_MASK] = *p;
+                               log->v2.end++;
+                               if (log->v2.end - log->v2.start > LOGBUFF_LEN)
+                                       log->v2.start++;
+                               log->v2.chars++;
+                       } else {
+                               lbuf[(log->v1.start + log->v1.size) &
+                                        LOGBUFF_MASK] = *p;
+                               if (log->v1.size < LOGBUFF_LEN)
+                                       log->v1.size++;
+                               else
+                                       log->v1.start++;
+                               log->v1.chars++;
+                       }
+                       if (*p == '\n') {
+                               line_feed = 1;
+                               break;
+                       }
+               }
+               if (msg_level < console_loglevel) {
+                       printf("%s", msg);
+               }
+               if (line_feed)
+                       msg_level = -1;
+       }
+       return i;
+}
diff --git a/cmd/lzmadec.c b/cmd/lzmadec.c
new file mode 100644 (file)
index 0000000..1ad9ed6
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
+ * lzma uncompress command in Uboot
+ *
+ * made from existing cmd_unzip.c file of Uboot
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <mapmem.h>
+#include <asm/io.h>
+
+#include <lzma/LzmaTools.h>
+
+static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       unsigned long src, dst;
+       unsigned long src_len = ~0UL, dst_len = ~0UL;
+       int ret;
+
+       switch (argc) {
+       case 4:
+               dst_len = simple_strtoul(argv[3], NULL, 16);
+               /* fall through */
+       case 3:
+               src = simple_strtoul(argv[1], NULL, 16);
+               dst = simple_strtoul(argv[2], NULL, 16);
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
+                                      map_sysmem(src, 0), dst_len);
+
+       if (ret != SZ_OK)
+               return 1;
+       printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
+       setenv_hex("filesize", src_len);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       lzmadec,    4,    1,    do_lzmadec,
+       "lzma uncompress a memory region",
+       "srcaddr dstaddr [dstsize]"
+);
diff --git a/cmd/mac.c b/cmd/mac.c
new file mode 100644 (file)
index 0000000..52d3ba0
--- /dev/null
+++ b/cmd/mac.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 Freescale Semiconductor
+ * York Sun (yorksun@freescale.com)
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+extern int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
+U_BOOT_CMD(
+       mac, 3, 1,  do_mac,
+       "display and program the system ID and MAC addresses in EEPROM",
+       "[read|save|id|num|errata|date|ports|0|1|2|3|4|5|6|7]\n"
+       "mac read\n"
+       "    - read EEPROM content into memory\n"
+       "mac save\n"
+       "    - save to the EEPROM\n"
+       "mac id\n"
+       "    - program system id\n"
+       "mac num\n"
+       "    - program system serial number\n"
+       "mac errata\n"
+       "    - program errata data\n"
+       "mac date\n"
+       "    - program date\n"
+       "mac ports\n"
+       "    - program the number of ports\n"
+       "mac X\n"
+       "    - program the MAC address for port X [X=0...7]"
+);
diff --git a/cmd/md5sum.c b/cmd/md5sum.c
new file mode 100644 (file)
index 0000000..23bb81e
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <mapmem.h>
+#include <u-boot/md5.h>
+#include <asm/io.h>
+
+/*
+ * Store the resulting sum to an address or variable
+ */
+static void store_result(const u8 *sum, const char *dest)
+{
+       unsigned int i;
+
+       if (*dest == '*') {
+               u8 *ptr;
+
+               ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
+               for (i = 0; i < 16; i++)
+                       *ptr++ = sum[i];
+       } else {
+               char str_output[33];
+               char *str_ptr = str_output;
+
+               for (i = 0; i < 16; i++) {
+                       sprintf(str_ptr, "%02x", sum[i]);
+                       str_ptr += 2;
+               }
+               setenv(dest, str_output);
+       }
+}
+
+#ifdef CONFIG_MD5SUM_VERIFY
+static int parse_verify_sum(char *verify_str, u8 *vsum)
+{
+       if (*verify_str == '*') {
+               u8 *ptr;
+
+               ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
+               memcpy(vsum, ptr, 16);
+       } else {
+               unsigned int i;
+               char *vsum_str;
+
+               if (strlen(verify_str) == 32)
+                       vsum_str = verify_str;
+               else {
+                       vsum_str = getenv(verify_str);
+                       if (vsum_str == NULL || strlen(vsum_str) != 32)
+                               return 1;
+               }
+
+               for (i = 0; i < 16; i++) {
+                       char *nullp = vsum_str + (i + 1) * 2;
+                       char end = *nullp;
+
+                       *nullp = '\0';
+                       *(u8 *)(vsum + i) =
+                               simple_strtoul(vsum_str + (i * 2), NULL, 16);
+                       *nullp = end;
+               }
+       }
+       return 0;
+}
+
+int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr, len;
+       unsigned int i;
+       u8 output[16];
+       u8 vsum[16];
+       int verify = 0;
+       int ac;
+       char * const *av;
+       void *buf;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       av = argv + 1;
+       ac = argc - 1;
+       if (strcmp(*av, "-v") == 0) {
+               verify = 1;
+               av++;
+               ac--;
+               if (ac < 3)
+                       return CMD_RET_USAGE;
+       }
+
+       addr = simple_strtoul(*av++, NULL, 16);
+       len = simple_strtoul(*av++, NULL, 16);
+
+       buf = map_sysmem(addr, len);
+       md5_wd(buf, len, output, CHUNKSZ_MD5);
+       unmap_sysmem(buf);
+
+       if (!verify) {
+               printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+               for (i = 0; i < 16; i++)
+                       printf("%02x", output[i]);
+               printf("\n");
+
+               if (ac > 2)
+                       store_result(output, *av);
+       } else {
+               char *verify_str = *av++;
+
+               if (parse_verify_sum(verify_str, vsum)) {
+                       printf("ERROR: %s does not contain a valid md5 sum\n",
+                               verify_str);
+                       return 1;
+               }
+               if (memcmp(output, vsum, 16) != 0) {
+                       printf("md5 for %08lx ... %08lx ==> ", addr,
+                               addr + len - 1);
+                       for (i = 0; i < 16; i++)
+                               printf("%02x", output[i]);
+                       printf(" != ");
+                       for (i = 0; i < 16; i++)
+                               printf("%02x", vsum[i]);
+                       printf(" ** ERROR **\n");
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+#else
+static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr, len;
+       unsigned int i;
+       u8 output[16];
+       void *buf;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+       len = simple_strtoul(argv[2], NULL, 16);
+
+       buf = map_sysmem(addr, len);
+       md5_wd(buf, len, output, CHUNKSZ_MD5);
+       unmap_sysmem(buf);
+
+       printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+       for (i = 0; i < 16; i++)
+               printf("%02x", output[i]);
+       printf("\n");
+
+       if (argc > 3)
+               store_result(output, argv[3]);
+
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_MD5SUM_VERIFY
+U_BOOT_CMD(
+       md5sum, 5,      1,      do_md5sum,
+       "compute MD5 message digest",
+       "address count [[*]sum]\n"
+               "    - compute MD5 message digest [save to sum]\n"
+       "md5sum -v address count [*]sum\n"
+               "    - verify md5sum of memory area"
+);
+#else
+U_BOOT_CMD(
+       md5sum, 4,      1,      do_md5sum,
+       "compute MD5 message digest",
+       "address count [[*]sum]\n"
+               "    - compute MD5 message digest [save to sum]"
+);
+#endif
diff --git a/cmd/mdio.c b/cmd/mdio.c
new file mode 100644 (file)
index 0000000..fb13d05
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * (C) Copyright 2011 Freescale Semiconductor, Inc
+ * Andy Fleming
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * MDIO Commands
+ */
+
+#include <common.h>
+#include <command.h>
+#include <miiphy.h>
+#include <phy.h>
+
+
+static char last_op[2];
+static uint last_data;
+static uint last_addr_lo;
+static uint last_addr_hi;
+static uint last_devad_lo;
+static uint last_devad_hi;
+static uint last_reg_lo;
+static uint last_reg_hi;
+
+static int extract_range(char *input, int *plo, int *phi)
+{
+       char *end;
+       *plo = simple_strtol(input, &end, 0);
+       if (end == input)
+               return -1;
+
+       if ((*end == '-') && *(++end))
+               *phi = simple_strtol(end, NULL, 0);
+       else if (*end == '\0')
+               *phi = *plo;
+       else
+               return -1;
+
+       return 0;
+}
+
+static int mdio_write_ranges(struct phy_device *phydev, struct mii_dev *bus,
+                            int addrlo,
+                            int addrhi, int devadlo, int devadhi,
+                            int reglo, int reghi, unsigned short data,
+                            int extended)
+{
+       int addr, devad, reg;
+       int err = 0;
+
+       for (addr = addrlo; addr <= addrhi; addr++) {
+               for (devad = devadlo; devad <= devadhi; devad++) {
+                       for (reg = reglo; reg <= reghi; reg++) {
+                               if (!extended)
+                                       err = bus->write(bus, addr, devad,
+                                                        reg, data);
+                               else
+                                       err = phydev->drv->writeext(phydev,
+                                                       addr, devad, reg, data);
+
+                               if (err)
+                                       goto err_out;
+                       }
+               }
+       }
+
+err_out:
+       return err;
+}
+
+static int mdio_read_ranges(struct phy_device *phydev, struct mii_dev *bus,
+                           int addrlo,
+                           int addrhi, int devadlo, int devadhi,
+                           int reglo, int reghi, int extended)
+{
+       int addr, devad, reg;
+
+       printf("Reading from bus %s\n", bus->name);
+       for (addr = addrlo; addr <= addrhi; addr++) {
+               printf("PHY at address %d:\n", addr);
+
+               for (devad = devadlo; devad <= devadhi; devad++) {
+                       for (reg = reglo; reg <= reghi; reg++) {
+                               int val;
+
+                               if (!extended)
+                                       val = bus->read(bus, addr, devad, reg);
+                               else
+                                       val = phydev->drv->readext(phydev, addr,
+                                               devad, reg);
+
+                               if (val < 0) {
+                                       printf("Error\n");
+
+                                       return val;
+                               }
+
+                               if (devad >= 0)
+                                       printf("%d.", devad);
+
+                               printf("%d - 0x%x\n", reg, val & 0xffff);
+                       }
+               }
+       }
+
+       return 0;
+}
+
+/* The register will be in the form [a[-b].]x[-y] */
+static int extract_reg_range(char *input, int *devadlo, int *devadhi,
+                            int *reglo, int *reghi)
+{
+       char *regstr;
+
+       /* use strrchr to find the last string after a '.' */
+       regstr = strrchr(input, '.');
+
+       /* If it exists, extract the devad(s) */
+       if (regstr) {
+               char devadstr[32];
+
+               strncpy(devadstr, input, regstr - input);
+               devadstr[regstr - input] = '\0';
+
+               if (extract_range(devadstr, devadlo, devadhi))
+                       return -1;
+
+               regstr++;
+       } else {
+               /* Otherwise, we have no devad, and we just got regs */
+               *devadlo = *devadhi = MDIO_DEVAD_NONE;
+
+               regstr = input;
+       }
+
+       return extract_range(regstr, reglo, reghi);
+}
+
+static int extract_phy_range(char *const argv[], int argc, struct mii_dev **bus,
+                            struct phy_device **phydev,
+                            int *addrlo, int *addrhi)
+{
+       struct phy_device *dev = *phydev;
+
+       if ((argc < 1) || (argc > 2))
+               return -1;
+
+       /* If there are two arguments, it's busname addr */
+       if (argc == 2) {
+               *bus = miiphy_get_dev_by_name(argv[0]);
+
+               if (!*bus)
+                       return -1;
+
+               return extract_range(argv[1], addrlo, addrhi);
+       }
+
+       /* It must be one argument, here */
+
+       /*
+        * This argument can be one of two things:
+        * 1) Ethernet device name
+        * 2) Just an address (use the previously-used bus)
+        *
+        * We check all buses for a PHY which is connected to an ethernet
+        * device by the given name.  If none are found, we call
+        * extract_range() on the string, and see if it's an address range.
+        */
+       dev = mdio_phydev_for_ethname(argv[0]);
+
+       if (dev) {
+               *addrlo = *addrhi = dev->addr;
+               *bus = dev->bus;
+
+               return 0;
+       }
+
+       /* It's an address or nothing useful */
+       return extract_range(argv[0], addrlo, addrhi);
+}
+
+/* ---------------------------------------------------------------- */
+static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char op[2];
+       int addrlo, addrhi, reglo, reghi, devadlo, devadhi;
+       unsigned short  data;
+       int pos = argc - 1;
+       struct mii_dev *bus;
+       struct phy_device *phydev = NULL;
+       int extended = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /*
+        * We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       op[0] = argv[1][0];
+       addrlo = last_addr_lo;
+       addrhi = last_addr_hi;
+       devadlo = last_devad_lo;
+       devadhi = last_devad_hi;
+       reglo  = last_reg_lo;
+       reghi  = last_reg_hi;
+       data   = last_data;
+
+       bus = mdio_get_current_dev();
+
+       if (flag & CMD_FLAG_REPEAT)
+               op[0] = last_op[0];
+
+       if (strlen(argv[1]) > 1) {
+               op[1] = argv[1][1];
+               if (op[1] == 'x') {
+                       phydev = mdio_phydev_for_ethname(argv[2]);
+
+                       if (phydev) {
+                               addrlo = phydev->addr;
+                               addrhi = addrlo;
+                               bus = phydev->bus;
+                               extended = 1;
+                       } else {
+                               return -1;
+                       }
+
+                       if (!phydev->drv ||
+                           (!phydev->drv->writeext && (op[0] == 'w')) ||
+                           (!phydev->drv->readext && (op[0] == 'r'))) {
+                               puts("PHY does not have extended functions\n");
+                               return -1;
+                       }
+               }
+       }
+
+       switch (op[0]) {
+       case 'w':
+               if (pos > 1)
+                       data = simple_strtoul(argv[pos--], NULL, 16);
+       case 'r':
+               if (pos > 1)
+                       if (extract_reg_range(argv[pos--], &devadlo, &devadhi,
+                                       &reglo, &reghi))
+                               return -1;
+
+       default:
+               if (pos > 1)
+                       if (extract_phy_range(&(argv[2]), pos - 1, &bus,
+                                       &phydev, &addrlo, &addrhi))
+                               return -1;
+
+               break;
+       }
+
+       if (op[0] == 'l') {
+               mdio_list_devices();
+
+               return 0;
+       }
+
+       /* Save the chosen bus */
+       miiphy_set_current_dev(bus->name);
+
+       switch (op[0]) {
+       case 'w':
+               mdio_write_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
+                                 reglo, reghi, data, extended);
+               break;
+
+       case 'r':
+               mdio_read_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
+                                reglo, reghi, extended);
+               break;
+       }
+
+       /*
+        * Save the parameters for repeats.
+        */
+       last_op[0] = op[0];
+       last_addr_lo = addrlo;
+       last_addr_hi = addrhi;
+       last_devad_lo = devadlo;
+       last_devad_hi = devadhi;
+       last_reg_lo  = reglo;
+       last_reg_hi  = reghi;
+       last_data    = data;
+
+       return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       mdio,   6,      1,      do_mdio,
+       "MDIO utility commands",
+       "list                   - List MDIO buses\n"
+       "mdio read <phydev> [<devad>.]<reg> - "
+               "read PHY's register at <devad>.<reg>\n"
+       "mdio write <phydev> [<devad>.]<reg> <data> - "
+               "write PHY's register at <devad>.<reg>\n"
+       "mdio rx <phydev> [<devad>.]<reg> - "
+               "read PHY's extended register at <devad>.<reg>\n"
+       "mdio wx <phydev> [<devad>.]<reg> <data> - "
+               "write PHY's extended register at <devad>.<reg>\n"
+       "<phydev> may be:\n"
+       "   <busname>  <addr>\n"
+       "   <addr>\n"
+       "   <eth name>\n"
+       "<addr> <devad>, and <reg> may be ranges, e.g. 1-5.4-0x1f.\n"
+);
diff --git a/cmd/mem.c b/cmd/mem.c
new file mode 100644 (file)
index 0000000..efa3929
--- /dev/null
+++ b/cmd/mem.c
@@ -0,0 +1,1410 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Memory Functions
+ *
+ * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
+ */
+
+#include <common.h>
+#include <console.h>
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#ifdef CONFIG_HAS_DATAFLASH
+#include <dataflash.h>
+#endif
+#include <hash.h>
+#include <inttypes.h>
+#include <mapmem.h>
+#include <watchdog.h>
+#include <asm/io.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifndef CONFIG_SYS_MEMTEST_SCRATCH
+#define CONFIG_SYS_MEMTEST_SCRATCH 0
+#endif
+
+static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
+
+/* Display values from last command.
+ * Memory modify remembered values are different from display memory.
+ */
+static ulong   dp_last_addr, dp_last_size;
+static ulong   dp_last_length = 0x40;
+static ulong   mm_last_addr, mm_last_size;
+
+static ulong   base_address = 0;
+
+/* Memory Display
+ *
+ * Syntax:
+ *     md{.b, .w, .l, .q} {addr} {len}
+ */
+#define DISP_LINE_LEN  16
+static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong   addr, length;
+#if defined(CONFIG_HAS_DATAFLASH)
+       ulong   nbytes, linebytes;
+#endif
+       int     size;
+       int rc = 0;
+
+       /* We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       addr = dp_last_addr;
+       size = dp_last_size;
+       length = dp_last_length;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /* New command specified.  Check for a size specification.
+                * Defaults to long if no or incorrect specification.
+                */
+               if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+                       return 1;
+
+               /* Address is specified since argc > 1
+               */
+               addr = simple_strtoul(argv[1], NULL, 16);
+               addr += base_address;
+
+               /* If another parameter, it is the length to display.
+                * Length is the number of objects, not number of bytes.
+                */
+               if (argc > 2)
+                       length = simple_strtoul(argv[2], NULL, 16);
+       }
+
+#if defined(CONFIG_HAS_DATAFLASH)
+       /* Print the lines.
+        *
+        * We buffer all read data, so we can make sure data is read only
+        * once, and all accesses are with the specified bus width.
+        */
+       nbytes = length * size;
+       do {
+               char    linebuf[DISP_LINE_LEN];
+               void* p;
+               linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
+
+               rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
+               p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
+               print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
+
+               nbytes -= linebytes;
+               addr += linebytes;
+               if (ctrlc()) {
+                       rc = 1;
+                       break;
+               }
+       } while (nbytes > 0);
+#else
+
+# if defined(CONFIG_BLACKFIN)
+       /* See if we're trying to display L1 inst */
+       if (addr_bfin_on_chip_mem(addr)) {
+               char linebuf[DISP_LINE_LEN];
+               ulong linebytes, nbytes = length * size;
+               do {
+                       linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
+                       memcpy(linebuf, (void *)addr, linebytes);
+                       print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
+
+                       nbytes -= linebytes;
+                       addr += linebytes;
+                       if (ctrlc()) {
+                               rc = 1;
+                               break;
+                       }
+               } while (nbytes > 0);
+       } else
+# endif
+
+       {
+               ulong bytes = size * length;
+               const void *buf = map_sysmem(addr, bytes);
+
+               /* Print the lines. */
+               print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
+               addr += bytes;
+               unmap_sysmem(buf);
+       }
+#endif
+
+       dp_last_addr = addr;
+       dp_last_length = length;
+       dp_last_size = size;
+       return (rc);
+}
+
+static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return mod_mem (cmdtp, 1, flag, argc, argv);
+}
+static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return mod_mem (cmdtp, 0, flag, argc, argv);
+}
+
+static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       u64 writeval;
+#else
+       ulong writeval;
+#endif
+       ulong   addr, count;
+       int     size;
+       void *buf, *start;
+       ulong bytes;
+
+       if ((argc < 3) || (argc > 4))
+               return CMD_RET_USAGE;
+
+       /* Check for size specification.
+       */
+       if ((size = cmd_get_data_size(argv[0], 4)) < 1)
+               return 1;
+
+       /* Address is specified since argc > 1
+       */
+       addr = simple_strtoul(argv[1], NULL, 16);
+       addr += base_address;
+
+       /* Get the value to write.
+       */
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       writeval = simple_strtoull(argv[2], NULL, 16);
+#else
+       writeval = simple_strtoul(argv[2], NULL, 16);
+#endif
+
+       /* Count ? */
+       if (argc == 4) {
+               count = simple_strtoul(argv[3], NULL, 16);
+       } else {
+               count = 1;
+       }
+
+       bytes = size * count;
+       start = map_sysmem(addr, bytes);
+       buf = start;
+       while (count-- > 0) {
+               if (size == 4)
+                       *((u32 *)buf) = (u32)writeval;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               else if (size == 8)
+                       *((u64 *)buf) = (u64)writeval;
+#endif
+               else if (size == 2)
+                       *((u16 *)buf) = (u16)writeval;
+               else
+                       *((u8 *)buf) = (u8)writeval;
+               buf += size;
+       }
+       unmap_sysmem(start);
+       return 0;
+}
+
+#ifdef CONFIG_MX_CYCLIC
+static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       ulong count;
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       count = simple_strtoul(argv[3], NULL, 10);
+
+       for (;;) {
+               do_mem_md (NULL, 0, 3, argv);
+
+               /* delay for <count> ms... */
+               for (i=0; i<count; i++)
+                       udelay (1000);
+
+               /* check for ctrl-c to abort... */
+               if (ctrlc()) {
+                       puts("Abort\n");
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
+static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i;
+       ulong count;
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       count = simple_strtoul(argv[3], NULL, 10);
+
+       for (;;) {
+               do_mem_mw (NULL, 0, 3, argv);
+
+               /* delay for <count> ms... */
+               for (i=0; i<count; i++)
+                       udelay (1000);
+
+               /* check for ctrl-c to abort... */
+               if (ctrlc()) {
+                       puts("Abort\n");
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+#endif /* CONFIG_MX_CYCLIC */
+
+static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong   addr1, addr2, count, ngood, bytes;
+       int     size;
+       int     rcode = 0;
+       const char *type;
+       const void *buf1, *buf2, *base;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       u64 word1, word2;
+#else
+       ulong word1, word2;
+#endif
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       /* Check for size specification.
+       */
+       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+               return 1;
+       type = size == 8 ? "double word" :
+              size == 4 ? "word" :
+              size == 2 ? "halfword" : "byte";
+
+       addr1 = simple_strtoul(argv[1], NULL, 16);
+       addr1 += base_address;
+
+       addr2 = simple_strtoul(argv[2], NULL, 16);
+       addr2 += base_address;
+
+       count = simple_strtoul(argv[3], NULL, 16);
+
+#ifdef CONFIG_HAS_DATAFLASH
+       if (addr_dataflash(addr1) | addr_dataflash(addr2)){
+               puts ("Comparison with DataFlash space not supported.\n\r");
+               return 0;
+       }
+#endif
+
+#ifdef CONFIG_BLACKFIN
+       if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
+               puts ("Comparison with L1 instruction memory not supported.\n\r");
+               return 0;
+       }
+#endif
+
+       bytes = size * count;
+       base = buf1 = map_sysmem(addr1, bytes);
+       buf2 = map_sysmem(addr2, bytes);
+       for (ngood = 0; ngood < count; ++ngood) {
+               if (size == 4) {
+                       word1 = *(u32 *)buf1;
+                       word2 = *(u32 *)buf2;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               } else if (size == 8) {
+                       word1 = *(u64 *)buf1;
+                       word2 = *(u64 *)buf2;
+#endif
+               } else if (size == 2) {
+                       word1 = *(u16 *)buf1;
+                       word2 = *(u16 *)buf2;
+               } else {
+                       word1 = *(u8 *)buf1;
+                       word2 = *(u8 *)buf2;
+               }
+               if (word1 != word2) {
+                       ulong offset = buf1 - base;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+                       printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
+                              PRIx64 ")\n",
+                              type, (void *)(addr1 + offset), size, word1,
+                              type, (void *)(addr2 + offset), size, word2);
+#else
+                       printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
+                               type, (ulong)(addr1 + offset), size, word1,
+                               type, (ulong)(addr2 + offset), size, word2);
+#endif
+                       rcode = 1;
+                       break;
+               }
+
+               buf1 += size;
+               buf2 += size;
+
+               /* reset watchdog from time to time */
+               if ((ngood % (64 << 10)) == 0)
+                       WATCHDOG_RESET();
+       }
+       unmap_sysmem(buf1);
+       unmap_sysmem(buf2);
+
+       printf("Total of %ld %s(s) were the same\n", ngood, type);
+       return rcode;
+}
+
+static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong   addr, dest, count, bytes;
+       int     size;
+       const void *src;
+       void *buf;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       /* Check for size specification.
+       */
+       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+               return 1;
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+       addr += base_address;
+
+       dest = simple_strtoul(argv[2], NULL, 16);
+       dest += base_address;
+
+       count = simple_strtoul(argv[3], NULL, 16);
+
+       if (count == 0) {
+               puts ("Zero length ???\n");
+               return 1;
+       }
+
+#ifndef CONFIG_SYS_NO_FLASH
+       /* check if we are copying to Flash */
+       if ( (addr2info(dest) != NULL)
+#ifdef CONFIG_HAS_DATAFLASH
+          && (!addr_dataflash(dest))
+#endif
+          ) {
+               int rc;
+
+               puts ("Copy to Flash... ");
+
+               rc = flash_write ((char *)addr, dest, count*size);
+               if (rc != 0) {
+                       flash_perror (rc);
+                       return (1);
+               }
+               puts ("done\n");
+               return 0;
+       }
+#endif
+
+#ifdef CONFIG_HAS_DATAFLASH
+       /* Check if we are copying from RAM or Flash to DataFlash */
+       if (addr_dataflash(dest) && !addr_dataflash(addr)){
+               int rc;
+
+               puts ("Copy to DataFlash... ");
+
+               rc = write_dataflash (dest, addr, count*size);
+
+               if (rc != 1) {
+                       dataflash_perror (rc);
+                       return (1);
+               }
+               puts ("done\n");
+               return 0;
+       }
+
+       /* Check if we are copying from DataFlash to RAM */
+       if (addr_dataflash(addr) && !addr_dataflash(dest)
+#ifndef CONFIG_SYS_NO_FLASH
+                                && (addr2info(dest) == NULL)
+#endif
+          ){
+               int rc;
+               rc = read_dataflash(addr, count * size, (char *) dest);
+               if (rc != 1) {
+                       dataflash_perror (rc);
+                       return (1);
+               }
+               return 0;
+       }
+
+       if (addr_dataflash(addr) && addr_dataflash(dest)){
+               puts ("Unsupported combination of source/destination.\n\r");
+               return 1;
+       }
+#endif
+
+#ifdef CONFIG_BLACKFIN
+       /* See if we're copying to/from L1 inst */
+       if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
+               memcpy((void *)dest, (void *)addr, count * size);
+               return 0;
+       }
+#endif
+
+       bytes = size * count;
+       buf = map_sysmem(dest, bytes);
+       src = map_sysmem(addr, bytes);
+       while (count-- > 0) {
+               if (size == 4)
+                       *((u32 *)buf) = *((u32  *)src);
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               else if (size == 8)
+                       *((u64 *)buf) = *((u64 *)src);
+#endif
+               else if (size == 2)
+                       *((u16 *)buf) = *((u16 *)src);
+               else
+                       *((u8 *)buf) = *((u8 *)src);
+               src += size;
+               buf += size;
+
+               /* reset watchdog from time to time */
+               if ((count % (64 << 10)) == 0)
+                       WATCHDOG_RESET();
+       }
+       unmap_sysmem(buf);
+       unmap_sysmem(src);
+
+       return 0;
+}
+
+static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       if (argc > 1) {
+               /* Set new base address.
+               */
+               base_address = simple_strtoul(argv[1], NULL, 16);
+       }
+       /* Print the current base address.
+       */
+       printf("Base Address: 0x%08lx\n", base_address);
+       return 0;
+}
+
+static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       ulong   addr, length, i, bytes;
+       int     size;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       volatile u64 *llp;
+#endif
+       volatile u32 *longp;
+       volatile u16 *shortp;
+       volatile u8 *cp;
+       const void *buf;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       /*
+        * Check for a size specification.
+        * Defaults to long if no or incorrect specification.
+        */
+       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+               return 1;
+
+       /* Address is always specified.
+       */
+       addr = simple_strtoul(argv[1], NULL, 16);
+
+       /* Length is the number of objects, not number of bytes.
+       */
+       length = simple_strtoul(argv[2], NULL, 16);
+
+       bytes = size * length;
+       buf = map_sysmem(addr, bytes);
+
+       /* We want to optimize the loops to run as fast as possible.
+        * If we have only one object, just run infinite loops.
+        */
+       if (length == 1) {
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               if (size == 8) {
+                       llp = (u64 *)buf;
+                       for (;;)
+                               i = *llp;
+               }
+#endif
+               if (size == 4) {
+                       longp = (u32 *)buf;
+                       for (;;)
+                               i = *longp;
+               }
+               if (size == 2) {
+                       shortp = (u16 *)buf;
+                       for (;;)
+                               i = *shortp;
+               }
+               cp = (u8 *)buf;
+               for (;;)
+                       i = *cp;
+       }
+
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       if (size == 8) {
+               for (;;) {
+                       llp = (u64 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *llp++;
+               }
+       }
+#endif
+       if (size == 4) {
+               for (;;) {
+                       longp = (u32 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *longp++;
+               }
+       }
+       if (size == 2) {
+               for (;;) {
+                       shortp = (u16 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *shortp++;
+               }
+       }
+       for (;;) {
+               cp = (u8 *)buf;
+               i = length;
+               while (i-- > 0)
+                       *cp++;
+       }
+       unmap_sysmem(buf);
+
+       return 0;
+}
+
+#ifdef CONFIG_LOOPW
+static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       ulong   addr, length, i, bytes;
+       int     size;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       volatile u64 *llp;
+       u64 data;
+#else
+       ulong   data;
+#endif
+       volatile u32 *longp;
+       volatile u16 *shortp;
+       volatile u8 *cp;
+       void *buf;
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       /*
+        * Check for a size specification.
+        * Defaults to long if no or incorrect specification.
+        */
+       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+               return 1;
+
+       /* Address is always specified.
+       */
+       addr = simple_strtoul(argv[1], NULL, 16);
+
+       /* Length is the number of objects, not number of bytes.
+       */
+       length = simple_strtoul(argv[2], NULL, 16);
+
+       /* data to write */
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       data = simple_strtoull(argv[3], NULL, 16);
+#else
+       data = simple_strtoul(argv[3], NULL, 16);
+#endif
+
+       bytes = size * length;
+       buf = map_sysmem(addr, bytes);
+
+       /* We want to optimize the loops to run as fast as possible.
+        * If we have only one object, just run infinite loops.
+        */
+       if (length == 1) {
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               if (size == 8) {
+                       llp = (u64 *)buf;
+                       for (;;)
+                               *llp = data;
+               }
+#endif
+               if (size == 4) {
+                       longp = (u32 *)buf;
+                       for (;;)
+                               *longp = data;
+               }
+               if (size == 2) {
+                       shortp = (u16 *)buf;
+                       for (;;)
+                               *shortp = data;
+               }
+               cp = (u8 *)buf;
+               for (;;)
+                       *cp = data;
+       }
+
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       if (size == 8) {
+               for (;;) {
+                       llp = (u64 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *llp++ = data;
+               }
+       }
+#endif
+       if (size == 4) {
+               for (;;) {
+                       longp = (u32 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *longp++ = data;
+               }
+       }
+       if (size == 2) {
+               for (;;) {
+                       shortp = (u16 *)buf;
+                       i = length;
+                       while (i-- > 0)
+                               *shortp++ = data;
+               }
+       }
+       for (;;) {
+               cp = (u8 *)buf;
+               i = length;
+               while (i-- > 0)
+                       *cp++ = data;
+       }
+}
+#endif /* CONFIG_LOOPW */
+
+#ifdef CONFIG_CMD_MEMTEST
+static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
+                         vu_long *dummy)
+{
+       vu_long *addr;
+       ulong errs = 0;
+       ulong val, readback;
+       int j;
+       vu_long offset;
+       vu_long test_offset;
+       vu_long pattern;
+       vu_long temp;
+       vu_long anti_pattern;
+       vu_long num_words;
+       static const ulong bitpattern[] = {
+               0x00000001,     /* single bit */
+               0x00000003,     /* two adjacent bits */
+               0x00000007,     /* three adjacent bits */
+               0x0000000F,     /* four adjacent bits */
+               0x00000005,     /* two non-adjacent bits */
+               0x00000015,     /* three non-adjacent bits */
+               0x00000055,     /* four non-adjacent bits */
+               0xaaaaaaaa,     /* alternating 1/0 */
+       };
+
+       num_words = (end_addr - start_addr) / sizeof(vu_long);
+
+       /*
+        * Data line test: write a pattern to the first
+        * location, write the 1's complement to a 'parking'
+        * address (changes the state of the data bus so a
+        * floating bus doesn't give a false OK), and then
+        * read the value back. Note that we read it back
+        * into a variable because the next time we read it,
+        * it might be right (been there, tough to explain to
+        * the quality guys why it prints a failure when the
+        * "is" and "should be" are obviously the same in the
+        * error message).
+        *
+        * Rather than exhaustively testing, we test some
+        * patterns by shifting '1' bits through a field of
+        * '0's and '0' bits through a field of '1's (i.e.
+        * pattern and ~pattern).
+        */
+       addr = buf;
+       for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
+               val = bitpattern[j];
+               for (; val != 0; val <<= 1) {
+                       *addr = val;
+                       *dummy  = ~val; /* clear the test data off the bus */
+                       readback = *addr;
+                       if (readback != val) {
+                               printf("FAILURE (data line): "
+                                       "expected %08lx, actual %08lx\n",
+                                               val, readback);
+                               errs++;
+                               if (ctrlc())
+                                       return -1;
+                       }
+                       *addr  = ~val;
+                       *dummy  = val;
+                       readback = *addr;
+                       if (readback != ~val) {
+                               printf("FAILURE (data line): "
+                                       "Is %08lx, should be %08lx\n",
+                                               readback, ~val);
+                               errs++;
+                               if (ctrlc())
+                                       return -1;
+                       }
+               }
+       }
+
+       /*
+        * Based on code whose Original Author and Copyright
+        * information follows: Copyright (c) 1998 by Michael
+        * Barr. This software is placed into the public
+        * domain and may be used for any purpose. However,
+        * this notice must not be changed or removed and no
+        * warranty is either expressed or implied by its
+        * publication or distribution.
+        */
+
+       /*
+       * Address line test
+
+        * Description: Test the address bus wiring in a
+        *              memory region by performing a walking
+        *              1's test on the relevant bits of the
+        *              address and checking for aliasing.
+        *              This test will find single-bit
+        *              address failures such as stuck-high,
+        *              stuck-low, and shorted pins. The base
+        *              address and size of the region are
+        *              selected by the caller.
+
+        * Notes:       For best results, the selected base
+        *              address should have enough LSB 0's to
+        *              guarantee single address bit changes.
+        *              For example, to test a 64-Kbyte
+        *              region, select a base address on a
+        *              64-Kbyte boundary. Also, select the
+        *              region size as a power-of-two if at
+        *              all possible.
+        *
+        * Returns:     0 if the test succeeds, 1 if the test fails.
+        */
+       pattern = (vu_long) 0xaaaaaaaa;
+       anti_pattern = (vu_long) 0x55555555;
+
+       debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
+       /*
+        * Write the default pattern at each of the
+        * power-of-two offsets.
+        */
+       for (offset = 1; offset < num_words; offset <<= 1)
+               addr[offset] = pattern;
+
+       /*
+        * Check for address bits stuck high.
+        */
+       test_offset = 0;
+       addr[test_offset] = anti_pattern;
+
+       for (offset = 1; offset < num_words; offset <<= 1) {
+               temp = addr[offset];
+               if (temp != pattern) {
+                       printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
+                               " expected 0x%.8lx, actual 0x%.8lx\n",
+                               start_addr + offset*sizeof(vu_long),
+                               pattern, temp);
+                       errs++;
+                       if (ctrlc())
+                               return -1;
+               }
+       }
+       addr[test_offset] = pattern;
+       WATCHDOG_RESET();
+
+       /*
+        * Check for addr bits stuck low or shorted.
+        */
+       for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
+               addr[test_offset] = anti_pattern;
+
+               for (offset = 1; offset < num_words; offset <<= 1) {
+                       temp = addr[offset];
+                       if ((temp != pattern) && (offset != test_offset)) {
+                               printf("\nFAILURE: Address bit stuck low or"
+                                       " shorted @ 0x%.8lx: expected 0x%.8lx,"
+                                       " actual 0x%.8lx\n",
+                                       start_addr + offset*sizeof(vu_long),
+                                       pattern, temp);
+                               errs++;
+                               if (ctrlc())
+                                       return -1;
+                       }
+               }
+               addr[test_offset] = pattern;
+       }
+
+       /*
+        * Description: Test the integrity of a physical
+        *              memory device by performing an
+        *              increment/decrement test over the
+        *              entire region. In the process every
+        *              storage bit in the device is tested
+        *              as a zero and a one. The base address
+        *              and the size of the region are
+        *              selected by the caller.
+        *
+        * Returns:     0 if the test succeeds, 1 if the test fails.
+        */
+       num_words++;
+
+       /*
+        * Fill memory with a known pattern.
+        */
+       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
+               WATCHDOG_RESET();
+               addr[offset] = pattern;
+       }
+
+       /*
+        * Check each location and invert it for the second pass.
+        */
+       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
+               WATCHDOG_RESET();
+               temp = addr[offset];
+               if (temp != pattern) {
+                       printf("\nFAILURE (read/write) @ 0x%.8lx:"
+                               " expected 0x%.8lx, actual 0x%.8lx)\n",
+                               start_addr + offset*sizeof(vu_long),
+                               pattern, temp);
+                       errs++;
+                       if (ctrlc())
+                               return -1;
+               }
+
+               anti_pattern = ~pattern;
+               addr[offset] = anti_pattern;
+       }
+
+       /*
+        * Check each location for the inverted pattern and zero it.
+        */
+       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
+               WATCHDOG_RESET();
+               anti_pattern = ~pattern;
+               temp = addr[offset];
+               if (temp != anti_pattern) {
+                       printf("\nFAILURE (read/write): @ 0x%.8lx:"
+                               " expected 0x%.8lx, actual 0x%.8lx)\n",
+                               start_addr + offset*sizeof(vu_long),
+                               anti_pattern, temp);
+                       errs++;
+                       if (ctrlc())
+                               return -1;
+               }
+               addr[offset] = 0;
+       }
+
+       return errs;
+}
+
+static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
+                           vu_long pattern, int iteration)
+{
+       vu_long *end;
+       vu_long *addr;
+       ulong errs = 0;
+       ulong incr, length;
+       ulong val, readback;
+
+       /* Alternate the pattern */
+       incr = 1;
+       if (iteration & 1) {
+               incr = -incr;
+               /*
+                * Flip the pattern each time to make lots of zeros and
+                * then, the next time, lots of ones.  We decrement
+                * the "negative" patterns and increment the "positive"
+                * patterns to preserve this feature.
+                */
+               if (pattern & 0x80000000)
+                       pattern = -pattern;     /* complement & increment */
+               else
+                       pattern = ~pattern;
+       }
+       length = (end_addr - start_addr) / sizeof(ulong);
+       end = buf + length;
+       printf("\rPattern %08lX  Writing..."
+               "%12s"
+               "\b\b\b\b\b\b\b\b\b\b",
+               pattern, "");
+
+       for (addr = buf, val = pattern; addr < end; addr++) {
+               WATCHDOG_RESET();
+               *addr = val;
+               val += incr;
+       }
+
+       puts("Reading...");
+
+       for (addr = buf, val = pattern; addr < end; addr++) {
+               WATCHDOG_RESET();
+               readback = *addr;
+               if (readback != val) {
+                       ulong offset = addr - buf;
+
+                       printf("\nMem error @ 0x%08X: "
+                               "found %08lX, expected %08lX\n",
+                               (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
+                               readback, val);
+                       errs++;
+                       if (ctrlc())
+                               return -1;
+               }
+               val += incr;
+       }
+
+       return errs;
+}
+
+/*
+ * Perform a memory test. A more complete alternative test can be
+ * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
+ * interrupted by ctrl-c or by a failure of one of the sub-tests.
+ */
+static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       ulong start, end;
+       vu_long *buf, *dummy;
+       ulong iteration_limit = 0;
+       int ret;
+       ulong errs = 0; /* number of errors, or -1 if interrupted */
+       ulong pattern = 0;
+       int iteration;
+#if defined(CONFIG_SYS_ALT_MEMTEST)
+       const int alt_test = 1;
+#else
+       const int alt_test = 0;
+#endif
+
+       start = CONFIG_SYS_MEMTEST_START;
+       end = CONFIG_SYS_MEMTEST_END;
+
+       if (argc > 1)
+               if (strict_strtoul(argv[1], 16, &start) < 0)
+                       return CMD_RET_USAGE;
+
+       if (argc > 2)
+               if (strict_strtoul(argv[2], 16, &end) < 0)
+                       return CMD_RET_USAGE;
+
+       if (argc > 3)
+               if (strict_strtoul(argv[3], 16, &pattern) < 0)
+                       return CMD_RET_USAGE;
+
+       if (argc > 4)
+               if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
+                       return CMD_RET_USAGE;
+
+       if (end < start) {
+               printf("Refusing to do empty test\n");
+               return -1;
+       }
+
+       printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
+       debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
+             start, end);
+
+       buf = map_sysmem(start, end - start);
+       dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
+       for (iteration = 0;
+                       !iteration_limit || iteration < iteration_limit;
+                       iteration++) {
+               if (ctrlc()) {
+                       errs = -1UL;
+                       break;
+               }
+
+               printf("Iteration: %6d\r", iteration + 1);
+               debug("\n");
+               if (alt_test) {
+                       errs = mem_test_alt(buf, start, end, dummy);
+               } else {
+                       errs = mem_test_quick(buf, start, end, pattern,
+                                             iteration);
+               }
+               if (errs == -1UL)
+                       break;
+       }
+
+       /*
+        * Work-around for eldk-4.2 which gives this warning if we try to
+        * case in the unmap_sysmem() call:
+        * warning: initialization discards qualifiers from pointer target type
+        */
+       {
+               void *vbuf = (void *)buf;
+               void *vdummy = (void *)dummy;
+
+               unmap_sysmem(vbuf);
+               unmap_sysmem(vdummy);
+       }
+
+       if (errs == -1UL) {
+               /* Memory test was aborted - write a newline to finish off */
+               putc('\n');
+               ret = 1;
+       } else {
+               printf("Tested %d iteration(s) with %lu errors.\n",
+                       iteration, errs);
+               ret = errs != 0;
+       }
+
+       return ret;
+}
+#endif /* CONFIG_CMD_MEMTEST */
+
+/* Modify memory.
+ *
+ * Syntax:
+ *     mm{.b, .w, .l, .q} {addr}
+ *     nm{.b, .w, .l, .q} {addr}
+ */
+static int
+mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
+{
+       ulong   addr;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       u64 i;
+#else
+       ulong i;
+#endif
+       int     nbytes, size;
+       void *ptr = NULL;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       bootretry_reset_cmd_timeout();  /* got a good command to get here */
+       /* We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       addr = mm_last_addr;
+       size = mm_last_size;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /* New command specified.  Check for a size specification.
+                * Defaults to long if no or incorrect specification.
+                */
+               if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+                       return 1;
+
+               /* Address is specified since argc > 1
+               */
+               addr = simple_strtoul(argv[1], NULL, 16);
+               addr += base_address;
+       }
+
+#ifdef CONFIG_HAS_DATAFLASH
+       if (addr_dataflash(addr)){
+               puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
+               return 0;
+       }
+#endif
+
+#ifdef CONFIG_BLACKFIN
+       if (addr_bfin_on_chip_mem(addr)) {
+               puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
+               return 0;
+       }
+#endif
+
+       /* Print the address, followed by value.  Then accept input for
+        * the next value.  A non-converted value exits.
+        */
+       do {
+               ptr = map_sysmem(addr, size);
+               printf("%08lx:", addr);
+               if (size == 4)
+                       printf(" %08x", *((u32 *)ptr));
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+               else if (size == 8)
+                       printf(" %016" PRIx64, *((u64 *)ptr));
+#endif
+               else if (size == 2)
+                       printf(" %04x", *((u16 *)ptr));
+               else
+                       printf(" %02x", *((u8 *)ptr));
+
+               nbytes = cli_readline(" ? ");
+               if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
+                       /* <CR> pressed as only input, don't modify current
+                        * location and move to next. "-" pressed will go back.
+                        */
+                       if (incrflag)
+                               addr += nbytes ? -size : size;
+                       nbytes = 1;
+                       /* good enough to not time out */
+                       bootretry_reset_cmd_timeout();
+               }
+#ifdef CONFIG_BOOT_RETRY_TIME
+               else if (nbytes == -2) {
+                       break;  /* timed out, exit the command  */
+               }
+#endif
+               else {
+                       char *endp;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+                       i = simple_strtoull(console_buffer, &endp, 16);
+#else
+                       i = simple_strtoul(console_buffer, &endp, 16);
+#endif
+                       nbytes = endp - console_buffer;
+                       if (nbytes) {
+                               /* good enough to not time out
+                                */
+                               bootretry_reset_cmd_timeout();
+                               if (size == 4)
+                                       *((u32 *)ptr) = i;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+                               else if (size == 8)
+                                       *((u64 *)ptr) = i;
+#endif
+                               else if (size == 2)
+                                       *((u16 *)ptr) = i;
+                               else
+                                       *((u8 *)ptr) = i;
+                               if (incrflag)
+                                       addr += size;
+                       }
+               }
+       } while (nbytes);
+       if (ptr)
+               unmap_sysmem(ptr);
+
+       mm_last_addr = addr;
+       mm_last_size = size;
+       return 0;
+}
+
+#ifdef CONFIG_CMD_CRC32
+
+static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int flags = 0;
+       int ac;
+       char * const *av;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       av = argv + 1;
+       ac = argc - 1;
+#ifdef CONFIG_HASH_VERIFY
+       if (strcmp(*av, "-v") == 0) {
+               flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
+               av++;
+               ac--;
+       }
+#endif
+
+       return hash_command("crc32", flags, cmdtp, flag, ac, av);
+}
+
+#endif
+
+/**************************************************/
+U_BOOT_CMD(
+       md,     3,      1,      do_mem_md,
+       "memory display",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address [# of objects]"
+#else
+       "[.b, .w, .l] address [# of objects]"
+#endif
+);
+
+
+U_BOOT_CMD(
+       mm,     2,      1,      do_mem_mm,
+       "memory modify (auto-incrementing address)",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address"
+#else
+       "[.b, .w, .l] address"
+#endif
+);
+
+
+U_BOOT_CMD(
+       nm,     2,      1,      do_mem_nm,
+       "memory modify (constant address)",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address"
+#else
+       "[.b, .w, .l] address"
+#endif
+);
+
+U_BOOT_CMD(
+       mw,     4,      1,      do_mem_mw,
+       "memory write (fill)",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address value [count]"
+#else
+       "[.b, .w, .l] address value [count]"
+#endif
+);
+
+U_BOOT_CMD(
+       cp,     4,      1,      do_mem_cp,
+       "memory copy",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] source target count"
+#else
+       "[.b, .w, .l] source target count"
+#endif
+);
+
+U_BOOT_CMD(
+       cmp,    4,      1,      do_mem_cmp,
+       "memory compare",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] addr1 addr2 count"
+#else
+       "[.b, .w, .l] addr1 addr2 count"
+#endif
+);
+
+#ifdef CONFIG_CMD_CRC32
+
+#ifndef CONFIG_HASH_VERIFY
+
+U_BOOT_CMD(
+       crc32,  4,      1,      do_mem_crc,
+       "checksum calculation",
+       "address count [addr]\n    - compute CRC32 checksum [save at addr]"
+);
+
+#else  /* CONFIG_HASH_VERIFY */
+
+U_BOOT_CMD(
+       crc32,  5,      1,      do_mem_crc,
+       "checksum calculation",
+       "address count [addr]\n    - compute CRC32 checksum [save at addr]\n"
+       "-v address count crc\n    - verify crc of memory area"
+);
+
+#endif /* CONFIG_HASH_VERIFY */
+
+#endif
+
+#ifdef CONFIG_CMD_MEMINFO
+__weak void board_show_dram(phys_size_t size)
+{
+       puts("DRAM:  ");
+       print_size(size, "\n");
+}
+
+static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       board_show_dram(gd->ram_size);
+
+       return 0;
+}
+#endif
+
+U_BOOT_CMD(
+       base,   2,      1,      do_mem_base,
+       "print or set address offset",
+       "\n    - print address offset for memory commands\n"
+       "base off\n    - set address offset for memory commands to 'off'"
+);
+
+U_BOOT_CMD(
+       loop,   3,      1,      do_mem_loop,
+       "infinite loop on address range",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address number_of_objects"
+#else
+       "[.b, .w, .l] address number_of_objects"
+#endif
+);
+
+#ifdef CONFIG_LOOPW
+U_BOOT_CMD(
+       loopw,  4,      1,      do_mem_loopw,
+       "infinite write loop on address range",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address number_of_objects data_to_write"
+#else
+       "[.b, .w, .l] address number_of_objects data_to_write"
+#endif
+);
+#endif /* CONFIG_LOOPW */
+
+#ifdef CONFIG_CMD_MEMTEST
+U_BOOT_CMD(
+       mtest,  5,      1,      do_mem_mtest,
+       "simple RAM read/write test",
+       "[start [end [pattern [iterations]]]]"
+);
+#endif /* CONFIG_CMD_MEMTEST */
+
+#ifdef CONFIG_MX_CYCLIC
+U_BOOT_CMD(
+       mdc,    4,      1,      do_mem_mdc,
+       "memory display cyclic",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address count delay(ms)"
+#else
+       "[.b, .w, .l] address count delay(ms)"
+#endif
+);
+
+U_BOOT_CMD(
+       mwc,    4,      1,      do_mem_mwc,
+       "memory write cyclic",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+       "[.b, .w, .l, .q] address value delay(ms)"
+#else
+       "[.b, .w, .l] address value delay(ms)"
+#endif
+);
+#endif /* CONFIG_MX_CYCLIC */
+
+#ifdef CONFIG_CMD_MEMINFO
+U_BOOT_CMD(
+       meminfo,        3,      1,      do_mem_info,
+       "display memory information",
+       ""
+);
+#endif
diff --git a/cmd/mfsl.c b/cmd/mfsl.c
new file mode 100644 (file)
index 0000000..e8e8e3c
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * (C) Copyright 2007 Michal Simek
+ *
+ * Michal  SIMEK <monstr@monstr.eu>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Microblaze FSL support
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <asm/asm.h>
+
+int do_frd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int fslnum;
+       unsigned int num;
+       unsigned int blocking;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
+       blocking = (unsigned int)simple_strtoul (argv[2], NULL, 16);
+       if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER) {
+               puts ("Bad number of FSL\n");
+               return CMD_RET_USAGE;
+       }
+
+       switch (fslnum) {
+#if (XILINX_FSL_NUMBER > 0)
+       case 0:
+               switch (blocking) {
+               case 0: NGET (num, 0);
+                       break;
+               case 1: NCGET (num, 0);
+                       break;
+               case 2: GET (num, 0);
+                       break;
+               case 3: CGET (num, 0);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 1)
+       case 1:
+               switch (blocking) {
+               case 0: NGET (num, 1);
+                       break;
+               case 1: NCGET (num, 1);
+                       break;
+               case 2: GET (num, 1);
+                       break;
+               case 3: CGET (num, 1);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 2)
+       case 2:
+               switch (blocking) {
+               case 0: NGET (num, 2);
+                       break;
+               case 1: NCGET (num, 2);
+                       break;
+               case 2: GET (num, 2);
+                       break;
+               case 3: CGET (num, 2);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 3)
+       case 3:
+               switch (blocking) {
+               case 0: NGET (num, 3);
+                       break;
+               case 1: NCGET (num, 3);
+                       break;
+               case 2: GET (num, 3);
+                       break;
+               case 3: CGET (num, 3);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 4)
+       case 4:
+               switch (blocking) {
+               case 0: NGET (num, 4);
+                       break;
+               case 1: NCGET (num, 4);
+                       break;
+               case 2: GET (num, 4);
+                       break;
+               case 3: CGET (num, 4);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 5)
+       case 5:
+               switch (blocking) {
+               case 0: NGET (num, 5);
+                       break;
+               case 1: NCGET (num, 5);
+                       break;
+               case 2: GET (num, 5);
+                       break;
+               case 3: CGET (num, 5);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 6)
+       case 6:
+               switch (blocking) {
+               case 0: NGET (num, 6);
+                       break;
+               case 1: NCGET (num, 6);
+                       break;
+               case 2: GET (num, 6);
+                       break;
+               case 3: CGET (num, 6);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 7)
+       case 7:
+               switch (blocking) {
+               case 0: NGET (num, 7);
+                       break;
+               case 1: NCGET (num, 7);
+                       break;
+               case 2: GET (num, 7);
+                       break;
+               case 3: CGET (num, 7);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+       default:
+               return 1;
+       }
+
+       printf ("%01x: 0x%08x - %s %s read\n", fslnum, num,
+               blocking < 2  ? "non blocking" : "blocking",
+               ((blocking == 1) || (blocking == 3)) ? "control" : "data" );
+       return 0;
+}
+
+int do_fwr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int fslnum;
+       unsigned int num;
+       unsigned int blocking;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
+       num = (unsigned int)simple_strtoul (argv[2], NULL, 16);
+       blocking = (unsigned int)simple_strtoul (argv[3], NULL, 16);
+       if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER)
+               return CMD_RET_USAGE;
+
+       switch (fslnum) {
+#if (XILINX_FSL_NUMBER > 0)
+       case 0:
+               switch (blocking) {
+               case 0: NPUT (num, 0);
+                       break;
+               case 1: NCPUT (num, 0);
+                       break;
+               case 2: PUT (num, 0);
+                       break;
+               case 3: CPUT (num, 0);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 1)
+       case 1:
+               switch (blocking) {
+               case 0: NPUT (num, 1);
+                       break;
+               case 1: NCPUT (num, 1);
+                       break;
+               case 2: PUT (num, 1);
+                       break;
+               case 3: CPUT (num, 1);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 2)
+       case 2:
+               switch (blocking) {
+               case 0: NPUT (num, 2);
+                       break;
+               case 1: NCPUT (num, 2);
+                       break;
+               case 2: PUT (num, 2);
+                       break;
+               case 3: CPUT (num, 2);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 3)
+       case 3:
+               switch (blocking) {
+               case 0: NPUT (num, 3);
+                       break;
+               case 1: NCPUT (num, 3);
+                       break;
+               case 2: PUT (num, 3);
+                       break;
+               case 3: CPUT (num, 3);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 4)
+       case 4:
+               switch (blocking) {
+               case 0: NPUT (num, 4);
+                       break;
+               case 1: NCPUT (num, 4);
+                       break;
+               case 2: PUT (num, 4);
+                       break;
+               case 3: CPUT (num, 4);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 5)
+       case 5:
+               switch (blocking) {
+               case 0: NPUT (num, 5);
+                       break;
+               case 1: NCPUT (num, 5);
+                       break;
+               case 2: PUT (num, 5);
+                       break;
+               case 3: CPUT (num, 5);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 6)
+       case 6:
+               switch (blocking) {
+               case 0: NPUT (num, 6);
+                       break;
+               case 1: NCPUT (num, 6);
+                       break;
+               case 2: PUT (num, 6);
+                       break;
+               case 3: CPUT (num, 6);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+#if (XILINX_FSL_NUMBER > 7)
+       case 7:
+               switch (blocking) {
+               case 0: NPUT (num, 7);
+                       break;
+               case 1: NCPUT (num, 7);
+                       break;
+               case 2: PUT (num, 7);
+                       break;
+               case 3: CPUT (num, 7);
+                       break;
+               default:
+                       return 2;
+               }
+               break;
+#endif
+       default:
+               return 1;
+       }
+
+       printf ("%01x: 0x%08x - %s %s write\n", fslnum, num,
+               blocking < 2  ? "non blocking" : "blocking",
+               ((blocking == 1) || (blocking == 3)) ? "control" : "data" );
+       return 0;
+
+}
+
+int do_rspr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned int reg = 0;
+       unsigned int val = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       reg = (unsigned int)simple_strtoul (argv[1], NULL, 16);
+       val = (unsigned int)simple_strtoul (argv[2], NULL, 16);
+       switch (reg) {
+       case 0x1:
+               if (argc > 2) {
+                       MTS (val, rmsr);
+                       NOP;
+                       MFS (val, rmsr);
+               } else {
+                       MFS (val, rmsr);
+               }
+               puts ("MSR");
+               break;
+       case 0x3:
+               MFS (val, rear);
+               puts ("EAR");
+               break;
+       case 0x5:
+               MFS (val, resr);
+               puts ("ESR");
+               break;
+       default:
+               puts ("Unsupported register\n");
+               return 1;
+       }
+       printf (": 0x%08x\n", val);
+       return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD (frd, 3, 1, do_frd,
+               "read data from FSL",
+               "- [fslnum [0|1|2|3]]\n"
+               " 0 - non blocking data read\n"
+               " 1 - non blocking control read\n"
+               " 2 - blocking data read\n"
+               " 3 - blocking control read");
+
+U_BOOT_CMD (fwr, 4, 1, do_fwr,
+               "write data to FSL",
+               "- [fslnum [0|1|2|3]]\n"
+               " 0 - non blocking data write\n"
+               " 1 - non blocking control write\n"
+               " 2 - blocking data write\n"
+               " 3 - blocking control write");
+
+U_BOOT_CMD (rspr, 3, 1, do_rspr,
+               "read/write special purpose register",
+               "- reg_num [write value] read/write special purpose register\n"
+               " 1 - MSR - Machine status register\n"
+               " 3 - EAR - Exception address register\n"
+               " 5 - ESR - Exception status register");
diff --git a/cmd/mii.c b/cmd/mii.c
new file mode 100644 (file)
index 0000000..7ef7532
--- /dev/null
+++ b/cmd/mii.c
@@ -0,0 +1,470 @@
+/*
+ * (C) Copyright 2001
+ * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * MII Utilities
+ */
+
+#include <common.h>
+#include <command.h>
+#include <miiphy.h>
+
+typedef struct _MII_reg_desc_t {
+       ushort regno;
+       char * name;
+} MII_reg_desc_t;
+
+static const MII_reg_desc_t reg_0_5_desc_tbl[] = {
+       { MII_BMCR,      "PHY control register" },
+       { MII_BMSR,      "PHY status register" },
+       { MII_PHYSID1,   "PHY ID 1 register" },
+       { MII_PHYSID2,   "PHY ID 2 register" },
+       { MII_ADVERTISE, "Autonegotiation advertisement register" },
+       { MII_LPA,       "Autonegotiation partner abilities register" },
+};
+
+typedef struct _MII_field_desc_t {
+       ushort hi;
+       ushort lo;
+       ushort mask;
+       char * name;
+} MII_field_desc_t;
+
+static const MII_field_desc_t reg_0_desc_tbl[] = {
+       { 15, 15, 0x01, "reset"                        },
+       { 14, 14, 0x01, "loopback"                     },
+       { 13,  6, 0x81, "speed selection"              }, /* special */
+       { 12, 12, 0x01, "A/N enable"                   },
+       { 11, 11, 0x01, "power-down"                   },
+       { 10, 10, 0x01, "isolate"                      },
+       {  9,  9, 0x01, "restart A/N"                  },
+       {  8,  8, 0x01, "duplex"                       }, /* special */
+       {  7,  7, 0x01, "collision test enable"        },
+       {  5,  0, 0x3f, "(reserved)"                   }
+};
+
+static const MII_field_desc_t reg_1_desc_tbl[] = {
+       { 15, 15, 0x01, "100BASE-T4 able"              },
+       { 14, 14, 0x01, "100BASE-X  full duplex able"  },
+       { 13, 13, 0x01, "100BASE-X  half duplex able"  },
+       { 12, 12, 0x01, "10 Mbps    full duplex able"  },
+       { 11, 11, 0x01, "10 Mbps    half duplex able"  },
+       { 10, 10, 0x01, "100BASE-T2 full duplex able"  },
+       {  9,  9, 0x01, "100BASE-T2 half duplex able"  },
+       {  8,  8, 0x01, "extended status"              },
+       {  7,  7, 0x01, "(reserved)"                   },
+       {  6,  6, 0x01, "MF preamble suppression"      },
+       {  5,  5, 0x01, "A/N complete"                 },
+       {  4,  4, 0x01, "remote fault"                 },
+       {  3,  3, 0x01, "A/N able"                     },
+       {  2,  2, 0x01, "link status"                  },
+       {  1,  1, 0x01, "jabber detect"                },
+       {  0,  0, 0x01, "extended capabilities"        },
+};
+
+static const MII_field_desc_t reg_2_desc_tbl[] = {
+       { 15,  0, 0xffff, "OUI portion"                },
+};
+
+static const MII_field_desc_t reg_3_desc_tbl[] = {
+       { 15, 10, 0x3f, "OUI portion"                },
+       {  9,  4, 0x3f, "manufacturer part number"   },
+       {  3,  0, 0x0f, "manufacturer rev. number"   },
+};
+
+static const MII_field_desc_t reg_4_desc_tbl[] = {
+       { 15, 15, 0x01, "next page able"               },
+       { 14, 14, 0x01, "(reserved)"                   },
+       { 13, 13, 0x01, "remote fault"                 },
+       { 12, 12, 0x01, "(reserved)"                   },
+       { 11, 11, 0x01, "asymmetric pause"             },
+       { 10, 10, 0x01, "pause enable"                 },
+       {  9,  9, 0x01, "100BASE-T4 able"              },
+       {  8,  8, 0x01, "100BASE-TX full duplex able"  },
+       {  7,  7, 0x01, "100BASE-TX able"              },
+       {  6,  6, 0x01, "10BASE-T   full duplex able"  },
+       {  5,  5, 0x01, "10BASE-T   able"              },
+       {  4,  0, 0x1f, "xxx to do"                    },
+};
+
+static const MII_field_desc_t reg_5_desc_tbl[] = {
+       { 15, 15, 0x01, "next page able"               },
+       { 14, 14, 0x01, "acknowledge"                  },
+       { 13, 13, 0x01, "remote fault"                 },
+       { 12, 12, 0x01, "(reserved)"                   },
+       { 11, 11, 0x01, "asymmetric pause able"        },
+       { 10, 10, 0x01, "pause able"                   },
+       {  9,  9, 0x01, "100BASE-T4 able"              },
+       {  8,  8, 0x01, "100BASE-X full duplex able"   },
+       {  7,  7, 0x01, "100BASE-TX able"              },
+       {  6,  6, 0x01, "10BASE-T full duplex able"    },
+       {  5,  5, 0x01, "10BASE-T able"                },
+       {  4,  0, 0x1f, "xxx to do"                    },
+};
+typedef struct _MII_field_desc_and_len_t {
+       const MII_field_desc_t *pdesc;
+       ushort len;
+} MII_field_desc_and_len_t;
+
+static const MII_field_desc_and_len_t desc_and_len_tbl[] = {
+       { reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl)   },
+       { reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl)   },
+       { reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl)   },
+       { reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl)   },
+       { reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl)   },
+       { reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl)   },
+};
+
+static void dump_reg(
+       ushort             regval,
+       const MII_reg_desc_t *prd,
+       const MII_field_desc_and_len_t *pdl);
+
+static int special_field(
+       ushort regno,
+       const MII_field_desc_t *pdesc,
+       ushort regval);
+
+static void MII_dump_0_to_5(
+       ushort regvals[6],
+       uchar reglo,
+       uchar reghi)
+{
+       ulong i;
+
+       for (i = 0; i < 6; i++) {
+               if ((reglo <= i) && (i <= reghi))
+                       dump_reg(regvals[i], &reg_0_5_desc_tbl[i],
+                               &desc_and_len_tbl[i]);
+       }
+}
+
+static void dump_reg(
+       ushort             regval,
+       const MII_reg_desc_t *prd,
+       const MII_field_desc_and_len_t *pdl)
+{
+       ulong i;
+       ushort mask_in_place;
+       const MII_field_desc_t *pdesc;
+
+       printf("%u.     (%04hx)                 -- %s --\n",
+               prd->regno, regval, prd->name);
+
+       for (i = 0; i < pdl->len; i++) {
+               pdesc = &pdl->pdesc[i];
+
+               mask_in_place = pdesc->mask << pdesc->lo;
+
+               printf("  (%04hx:%04x) %u.",
+                      mask_in_place,
+                      regval & mask_in_place,
+                      prd->regno);
+
+               if (special_field(prd->regno, pdesc, regval)) {
+               }
+               else {
+                       if (pdesc->hi == pdesc->lo)
+                               printf("%2u   ", pdesc->lo);
+                       else
+                               printf("%2u-%2u", pdesc->hi, pdesc->lo);
+                       printf(" = %5u    %s",
+                               (regval & mask_in_place) >> pdesc->lo,
+                               pdesc->name);
+               }
+               printf("\n");
+
+       }
+       printf("\n");
+}
+
+/* Special fields:
+** 0.6,13
+** 0.8
+** 2.15-0
+** 3.15-0
+** 4.4-0
+** 5.4-0
+*/
+
+static int special_field(
+       ushort regno,
+       const MII_field_desc_t *pdesc,
+       ushort regval)
+{
+       if ((regno == MII_BMCR) && (pdesc->lo == 6)) {
+               ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100);
+               printf("%2u,%2u =   b%u%u    speed selection = %s Mbps",
+                       6, 13,
+                       (regval >>  6) & 1,
+                       (regval >> 13) & 1,
+                       speed_bits == BMCR_SPEED1000 ? "1000" :
+                       speed_bits == BMCR_SPEED100  ? "100" :
+                       "10");
+               return 1;
+       }
+
+       else if ((regno == MII_BMCR) && (pdesc->lo == 8)) {
+               printf("%2u    = %5u    duplex = %s",
+                       pdesc->lo,
+                       (regval >>  pdesc->lo) & 1,
+                       ((regval >> pdesc->lo) & 1) ? "full" : "half");
+               return 1;
+       }
+
+       else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) {
+               ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
+               printf("%2u-%2u = %5u    selector = %s",
+                       pdesc->hi, pdesc->lo, sel_bits,
+                       sel_bits == PHY_ANLPAR_PSB_802_3 ?
+                               "IEEE 802.3" :
+                       sel_bits == PHY_ANLPAR_PSB_802_9 ?
+                               "IEEE 802.9 ISLAN-16T" :
+                       "???");
+               return 1;
+       }
+
+       else if ((regno == MII_LPA) && (pdesc->lo == 0)) {
+               ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
+               printf("%2u-%2u =     %u    selector = %s",
+                       pdesc->hi, pdesc->lo, sel_bits,
+                       sel_bits == PHY_ANLPAR_PSB_802_3 ?
+                               "IEEE 802.3" :
+                       sel_bits == PHY_ANLPAR_PSB_802_9 ?
+                               "IEEE 802.9 ISLAN-16T" :
+                       "???");
+               return 1;
+       }
+
+       return 0;
+}
+
+static char last_op[2];
+static uint last_data;
+static uint last_addr_lo;
+static uint last_addr_hi;
+static uint last_reg_lo;
+static uint last_reg_hi;
+static uint last_mask;
+
+static void extract_range(
+       char * input,
+       unsigned char * plo,
+       unsigned char * phi)
+{
+       char * end;
+       *plo = simple_strtoul(input, &end, 16);
+       if (*end == '-') {
+               end++;
+               *phi = simple_strtoul(end, NULL, 16);
+       }
+       else {
+               *phi = *plo;
+       }
+}
+
+/* ---------------------------------------------------------------- */
+static int do_mii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char            op[2];
+       unsigned char   addrlo, addrhi, reglo, reghi;
+       unsigned char   addr, reg;
+       unsigned short  data, mask;
+       int             rcode = 0;
+       const char      *devname;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+#if defined(CONFIG_MII_INIT)
+       mii_init ();
+#endif
+
+       /*
+        * We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       op[0] = last_op[0];
+       op[1] = last_op[1];
+       addrlo = last_addr_lo;
+       addrhi = last_addr_hi;
+       reglo  = last_reg_lo;
+       reghi  = last_reg_hi;
+       data   = last_data;
+       mask   = last_mask;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               op[0] = argv[1][0];
+               if (strlen(argv[1]) > 1)
+                       op[1] = argv[1][1];
+               else
+                       op[1] = '\0';
+
+               if (argc >= 3)
+                       extract_range(argv[2], &addrlo, &addrhi);
+               if (argc >= 4)
+                       extract_range(argv[3], &reglo, &reghi);
+               if (argc >= 5)
+                       data = simple_strtoul(argv[4], NULL, 16);
+               if (argc >= 6)
+                       mask = simple_strtoul(argv[5], NULL, 16);
+       }
+
+       if (addrhi > 31) {
+               printf("Incorrect PHY address. Range should be 0-31\n");
+               return CMD_RET_USAGE;
+       }
+
+       /* use current device */
+       devname = miiphy_get_current_dev();
+
+       /*
+        * check info/read/write.
+        */
+       if (op[0] == 'i') {
+               unsigned char j, start, end;
+               unsigned int oui;
+               unsigned char model;
+               unsigned char rev;
+
+               /*
+                * Look for any and all PHYs.  Valid addresses are 0..31.
+                */
+               if (argc >= 3) {
+                       start = addrlo; end = addrhi;
+               } else {
+                       start = 0; end = 31;
+               }
+
+               for (j = start; j <= end; j++) {
+                       if (miiphy_info (devname, j, &oui, &model, &rev) == 0) {
+                               printf("PHY 0x%02X: "
+                                       "OUI = 0x%04X, "
+                                       "Model = 0x%02X, "
+                                       "Rev = 0x%02X, "
+                                       "%3dbase%s, %s\n",
+                                       j, oui, model, rev,
+                                       miiphy_speed (devname, j),
+                                       miiphy_is_1000base_x (devname, j)
+                                               ? "X" : "T",
+                                       (miiphy_duplex (devname, j) == FULL)
+                                               ? "FDX" : "HDX");
+                       }
+               }
+       } else if (op[0] == 'r') {
+               for (addr = addrlo; addr <= addrhi; addr++) {
+                       for (reg = reglo; reg <= reghi; reg++) {
+                               data = 0xffff;
+                               if (miiphy_read (devname, addr, reg, &data) != 0) {
+                                       printf(
+                                       "Error reading from the PHY addr=%02x reg=%02x\n",
+                                               addr, reg);
+                                       rcode = 1;
+                               } else {
+                                       if ((addrlo != addrhi) || (reglo != reghi))
+                                               printf("addr=%02x reg=%02x data=",
+                                                       (uint)addr, (uint)reg);
+                                       printf("%04X\n", data & 0x0000FFFF);
+                               }
+                       }
+                       if ((addrlo != addrhi) && (reglo != reghi))
+                               printf("\n");
+               }
+       } else if (op[0] == 'w') {
+               for (addr = addrlo; addr <= addrhi; addr++) {
+                       for (reg = reglo; reg <= reghi; reg++) {
+                               if (miiphy_write (devname, addr, reg, data) != 0) {
+                                       printf("Error writing to the PHY addr=%02x reg=%02x\n",
+                                               addr, reg);
+                                       rcode = 1;
+                               }
+                       }
+               }
+       } else if (op[0] == 'm') {
+               for (addr = addrlo; addr <= addrhi; addr++) {
+                       for (reg = reglo; reg <= reghi; reg++) {
+                               unsigned short val = 0;
+                               if (miiphy_read(devname, addr,
+                                               reg, &val)) {
+                                       printf("Error reading from the PHY");
+                                       printf(" addr=%02x", addr);
+                                       printf(" reg=%02x\n", reg);
+                                       rcode = 1;
+                               } else {
+                                       val = (val & ~mask) | (data & mask);
+                                       if (miiphy_write(devname, addr,
+                                                        reg, val)) {
+                                               printf("Error writing to the PHY");
+                                               printf(" addr=%02x", addr);
+                                               printf(" reg=%02x\n", reg);
+                                               rcode = 1;
+                                       }
+                               }
+                       }
+               }
+       } else if (strncmp(op, "du", 2) == 0) {
+               ushort regs[6];
+               int ok = 1;
+               if ((reglo > 5) || (reghi > 5)) {
+                       printf(
+                               "The MII dump command only formats the "
+                               "standard MII registers, 0-5.\n");
+                       return 1;
+               }
+               for (addr = addrlo; addr <= addrhi; addr++) {
+                       for (reg = reglo; reg < reghi + 1; reg++) {
+                               if (miiphy_read(devname, addr, reg, &regs[reg]) != 0) {
+                                       ok = 0;
+                                       printf(
+                                       "Error reading from the PHY addr=%02x reg=%02x\n",
+                                               addr, reg);
+                                       rcode = 1;
+                               }
+                       }
+                       if (ok)
+                               MII_dump_0_to_5(regs, reglo, reghi);
+                       printf("\n");
+               }
+       } else if (strncmp(op, "de", 2) == 0) {
+               if (argc == 2)
+                       miiphy_listdev ();
+               else
+                       miiphy_set_current_dev (argv[2]);
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       /*
+        * Save the parameters for repeats.
+        */
+       last_op[0] = op[0];
+       last_op[1] = op[1];
+       last_addr_lo = addrlo;
+       last_addr_hi = addrhi;
+       last_reg_lo  = reglo;
+       last_reg_hi  = reghi;
+       last_data    = data;
+       last_mask    = mask;
+
+       return rcode;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       mii, 6, 1, do_mii,
+       "MII utility commands",
+       "device                            - list available devices\n"
+       "mii device <devname>                  - set current device\n"
+       "mii info   <addr>                     - display MII PHY info\n"
+       "mii read   <addr> <reg>               - read  MII PHY <addr> register <reg>\n"
+       "mii write  <addr> <reg> <data>        - write MII PHY <addr> register <reg>\n"
+       "mii modify <addr> <reg> <data> <mask> - modify MII PHY <addr> register <reg>\n"
+       "                                        updating bits identified in <mask>\n"
+       "mii dump   <addr> <reg>               - pretty-print <addr> <reg> (0-5 only)\n"
+       "Addr and/or reg may be ranges, e.g. 2-7."
+);
diff --git a/cmd/misc.c b/cmd/misc.c
new file mode 100644 (file)
index 0000000..39d8683
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * (C) Copyright 2001
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Misc functions
+ */
+#include <common.h>
+#include <command.h>
+#include <console.h>
+
+static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong start = get_timer(0);
+       ulong delay;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
+
+       while (get_timer(start) < delay) {
+               if (ctrlc())
+                       return (-1);
+
+               udelay(100);
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       sleep ,    2,    1,     do_sleep,
+       "delay execution for some time",
+       "N\n"
+       "    - delay execution for N seconds (N is _decimal_ !!!)"
+);
+
+#ifdef CONFIG_CMD_TIMER
+static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       static ulong start;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       if (!strcmp(argv[1], "start"))
+               start = get_timer(0);
+
+       if (!strcmp(argv[1], "get")) {
+               ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
+               printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       timer,    2,    1,     do_timer,
+       "access the system timer",
+       "start - Reset the timer reference.\n"
+       "timer get   - Print the time since 'start'."
+);
+#endif
diff --git a/cmd/mmc.c b/cmd/mmc.c
new file mode 100644 (file)
index 0000000..1c7156f
--- /dev/null
+++ b/cmd/mmc.c
@@ -0,0 +1,882 @@
+/*
+ * (C) Copyright 2003
+ * Kyle Harris, kharris@nexus-tech.net
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <mmc.h>
+
+static int curr_device = -1;
+#ifndef CONFIG_GENERIC_MMC
+int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int dev;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[1], "init") == 0) {
+               if (argc == 2) {
+                       if (curr_device < 0)
+                               dev = 1;
+                       else
+                               dev = curr_device;
+               } else if (argc == 3) {
+                       dev = (int)simple_strtoul(argv[2], NULL, 10);
+               } else {
+                       return CMD_RET_USAGE;
+               }
+
+               if (mmc_legacy_init(dev) != 0) {
+                       puts("No MMC card found\n");
+                       return 1;
+               }
+
+               curr_device = dev;
+               printf("mmc%d is available\n", curr_device);
+       } else if (strcmp(argv[1], "device") == 0) {
+               if (argc == 2) {
+                       if (curr_device < 0) {
+                               puts("No MMC device available\n");
+                               return 1;
+                       }
+               } else if (argc == 3) {
+                       dev = (int)simple_strtoul(argv[2], NULL, 10);
+
+#ifdef CONFIG_SYS_MMC_SET_DEV
+                       if (mmc_set_dev(dev) != 0)
+                               return 1;
+#endif
+                       curr_device = dev;
+               } else {
+                       return CMD_RET_USAGE;
+               }
+
+               printf("mmc%d is current device\n", curr_device);
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       mmc, 3, 1, do_mmc,
+       "MMC sub-system",
+       "init [dev] - init MMC sub system\n"
+       "mmc device [dev] - show or set current device"
+);
+#else /* !CONFIG_GENERIC_MMC */
+
+static void print_mmcinfo(struct mmc *mmc)
+{
+       int i;
+
+       printf("Device: %s\n", mmc->cfg->name);
+       printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
+       printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
+       printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
+                       (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
+                       (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
+
+       printf("Tran Speed: %d\n", mmc->tran_speed);
+       printf("Rd Block Len: %d\n", mmc->read_bl_len);
+
+       printf("%s version %d.%d", IS_SD(mmc) ? "SD" : "MMC",
+                       EXTRACT_SDMMC_MAJOR_VERSION(mmc->version),
+                       EXTRACT_SDMMC_MINOR_VERSION(mmc->version));
+       if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0)
+               printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version));
+       printf("\n");
+
+       printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
+       puts("Capacity: ");
+       print_size(mmc->capacity, "\n");
+
+       printf("Bus Width: %d-bit%s\n", mmc->bus_width,
+                       mmc->ddr_mode ? " DDR" : "");
+
+       puts("Erase Group Size: ");
+       print_size(((u64)mmc->erase_grp_size) << 9, "\n");
+
+       if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
+               bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
+               bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
+
+               puts("HC WP Group Size: ");
+               print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
+
+               puts("User Capacity: ");
+               print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
+               if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
+                       puts(" WRREL\n");
+               else
+                       putc('\n');
+               if (usr_enh) {
+                       puts("User Enhanced Start: ");
+                       print_size(mmc->enh_user_start, "\n");
+                       puts("User Enhanced Size: ");
+                       print_size(mmc->enh_user_size, "\n");
+               }
+               puts("Boot Capacity: ");
+               print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
+               puts("RPMB Capacity: ");
+               print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
+
+               for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
+                       bool is_enh = has_enh &&
+                               (mmc->part_attr & EXT_CSD_ENH_GP(i));
+                       if (mmc->capacity_gp[i]) {
+                               printf("GP%i Capacity: ", i+1);
+                               print_size(mmc->capacity_gp[i],
+                                          is_enh ? " ENH" : "");
+                               if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
+                                       puts(" WRREL\n");
+                               else
+                                       putc('\n');
+                       }
+               }
+       }
+}
+static struct mmc *init_mmc_device(int dev, bool force_init)
+{
+       struct mmc *mmc;
+       mmc = find_mmc_device(dev);
+       if (!mmc) {
+               printf("no mmc device at slot %x\n", dev);
+               return NULL;
+       }
+       if (force_init)
+               mmc->has_init = 0;
+       if (mmc_init(mmc))
+               return NULL;
+       return mmc;
+}
+static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct mmc *mmc;
+
+       if (curr_device < 0) {
+               if (get_mmc_num() > 0)
+                       curr_device = 0;
+               else {
+                       puts("No MMC device available\n");
+                       return 1;
+               }
+       }
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       print_mmcinfo(mmc);
+       return CMD_RET_SUCCESS;
+}
+
+#ifdef CONFIG_SUPPORT_EMMC_RPMB
+static int confirm_key_prog(void)
+{
+       puts("Warning: Programming authentication key can be done only once !\n"
+            "         Use this command only if you are sure of what you are doing,\n"
+            "Really perform the key programming? <y/N> ");
+       if (confirm_yesno())
+               return 1;
+
+       puts("Authentication key programming aborted\n");
+       return 0;
+}
+static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
+                         int argc, char * const argv[])
+{
+       void *key_addr;
+       struct mmc *mmc = find_mmc_device(curr_device);
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
+       if (!confirm_key_prog())
+               return CMD_RET_FAILURE;
+       if (mmc_rpmb_set_key(mmc, key_addr)) {
+               printf("ERROR - Key already programmed ?\n");
+               return CMD_RET_FAILURE;
+       }
+       return CMD_RET_SUCCESS;
+}
+static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
+                          int argc, char * const argv[])
+{
+       u16 blk, cnt;
+       void *addr;
+       int n;
+       void *key_addr = NULL;
+       struct mmc *mmc = find_mmc_device(curr_device);
+
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       addr = (void *)simple_strtoul(argv[1], NULL, 16);
+       blk = simple_strtoul(argv[2], NULL, 16);
+       cnt = simple_strtoul(argv[3], NULL, 16);
+
+       if (argc == 5)
+               key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
+
+       printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
+              curr_device, blk, cnt);
+       n =  mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
+
+       printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+       if (n != cnt)
+               return CMD_RET_FAILURE;
+       return CMD_RET_SUCCESS;
+}
+static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
+                           int argc, char * const argv[])
+{
+       u16 blk, cnt;
+       void *addr;
+       int n;
+       void *key_addr;
+       struct mmc *mmc = find_mmc_device(curr_device);
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       addr = (void *)simple_strtoul(argv[1], NULL, 16);
+       blk = simple_strtoul(argv[2], NULL, 16);
+       cnt = simple_strtoul(argv[3], NULL, 16);
+       key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
+
+       printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
+              curr_device, blk, cnt);
+       n =  mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
+
+       printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+       if (n != cnt)
+               return CMD_RET_FAILURE;
+       return CMD_RET_SUCCESS;
+}
+static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
+                             int argc, char * const argv[])
+{
+       unsigned long counter;
+       struct mmc *mmc = find_mmc_device(curr_device);
+
+       if (mmc_rpmb_get_counter(mmc, &counter))
+               return CMD_RET_FAILURE;
+       printf("RPMB Write counter= %lx\n", counter);
+       return CMD_RET_SUCCESS;
+}
+
+static cmd_tbl_t cmd_rpmb[] = {
+       U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
+       U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
+       U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
+};
+
+static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
+                     int argc, char * const argv[])
+{
+       cmd_tbl_t *cp;
+       struct mmc *mmc;
+       char original_part;
+       int ret;
+
+       cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
+
+       /* Drop the rpmb subcommand */
+       argc--;
+       argv++;
+
+       if (cp == NULL || argc > cp->maxargs)
+               return CMD_RET_USAGE;
+       if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
+               return CMD_RET_SUCCESS;
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (!(mmc->version & MMC_VERSION_MMC)) {
+               printf("It is not a EMMC device\n");
+               return CMD_RET_FAILURE;
+       }
+       if (mmc->version < MMC_VERSION_4_41) {
+               printf("RPMB not supported before version 4.41\n");
+               return CMD_RET_FAILURE;
+       }
+       /* Switch to the RPMB partition */
+       original_part = mmc->block_dev.part_num;
+       if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0)
+               return CMD_RET_FAILURE;
+       ret = cp->cmd(cmdtp, flag, argc, argv);
+
+       /* Return to original partition */
+       if (mmc_select_hwpart(curr_device, original_part) != 0)
+               return CMD_RET_FAILURE;
+       return ret;
+}
+#endif
+
+static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
+                      int argc, char * const argv[])
+{
+       struct mmc *mmc;
+       u32 blk, cnt, n;
+       void *addr;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       addr = (void *)simple_strtoul(argv[1], NULL, 16);
+       blk = simple_strtoul(argv[2], NULL, 16);
+       cnt = simple_strtoul(argv[3], NULL, 16);
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       printf("\nMMC read: dev # %d, block # %d, count %d ... ",
+              curr_device, blk, cnt);
+
+       n = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, addr);
+       /* flush cache after read */
+       flush_cache((ulong)addr, cnt * 512); /* FIXME */
+       printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+
+       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+}
+static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
+                       int argc, char * const argv[])
+{
+       struct mmc *mmc;
+       u32 blk, cnt, n;
+       void *addr;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       addr = (void *)simple_strtoul(argv[1], NULL, 16);
+       blk = simple_strtoul(argv[2], NULL, 16);
+       cnt = simple_strtoul(argv[3], NULL, 16);
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       printf("\nMMC write: dev # %d, block # %d, count %d ... ",
+              curr_device, blk, cnt);
+
+       if (mmc_getwp(mmc) == 1) {
+               printf("Error: card is write protected!\n");
+               return CMD_RET_FAILURE;
+       }
+       n = mmc->block_dev.block_write(&mmc->block_dev, blk, cnt, addr);
+       printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+
+       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+}
+static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
+                       int argc, char * const argv[])
+{
+       struct mmc *mmc;
+       u32 blk, cnt, n;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       blk = simple_strtoul(argv[1], NULL, 16);
+       cnt = simple_strtoul(argv[2], NULL, 16);
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
+              curr_device, blk, cnt);
+
+       if (mmc_getwp(mmc) == 1) {
+               printf("Error: card is write protected!\n");
+               return CMD_RET_FAILURE;
+       }
+       n = mmc->block_dev.block_erase(&mmc->block_dev, blk, cnt);
+       printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
+
+       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+}
+static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
+                        int argc, char * const argv[])
+{
+       struct mmc *mmc;
+
+       mmc = init_mmc_device(curr_device, true);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
+static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
+                      int argc, char * const argv[])
+{
+       block_dev_desc_t *mmc_dev;
+       struct mmc *mmc;
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       mmc_dev = mmc_get_dev(curr_device);
+       if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
+               print_part(mmc_dev);
+               return CMD_RET_SUCCESS;
+       }
+
+       puts("get mmc type error!\n");
+       return CMD_RET_FAILURE;
+}
+static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
+                     int argc, char * const argv[])
+{
+       int dev, part = 0, ret;
+       struct mmc *mmc;
+
+       if (argc == 1) {
+               dev = curr_device;
+       } else if (argc == 2) {
+               dev = simple_strtoul(argv[1], NULL, 10);
+       } else if (argc == 3) {
+               dev = (int)simple_strtoul(argv[1], NULL, 10);
+               part = (int)simple_strtoul(argv[2], NULL, 10);
+               if (part > PART_ACCESS_MASK) {
+                       printf("#part_num shouldn't be larger than %d\n",
+                              PART_ACCESS_MASK);
+                       return CMD_RET_FAILURE;
+               }
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       mmc = init_mmc_device(dev, true);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       ret = mmc_select_hwpart(dev, part);
+       printf("switch to partitions #%d, %s\n",
+              part, (!ret) ? "OK" : "ERROR");
+       if (ret)
+               return 1;
+
+       curr_device = dev;
+       if (mmc->part_config == MMCPART_NOAVAILABLE)
+               printf("mmc%d is current device\n", curr_device);
+       else
+               printf("mmc%d(part %d) is current device\n",
+                      curr_device, mmc->block_dev.hwpart);
+
+       return CMD_RET_SUCCESS;
+}
+static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
+                      int argc, char * const argv[])
+{
+       print_mmc_devices('\n');
+       return CMD_RET_SUCCESS;
+}
+
+static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
+                            int argc, char * const argv[])
+{
+       int i = 0;
+
+       memset(&pconf->user, 0, sizeof(pconf->user));
+
+       while (i < argc) {
+               if (!strcmp(argv[i], "enh")) {
+                       if (i + 2 >= argc)
+                               return -1;
+                       pconf->user.enh_start =
+                               simple_strtoul(argv[i+1], NULL, 10);
+                       pconf->user.enh_size =
+                               simple_strtoul(argv[i+2], NULL, 10);
+                       i += 3;
+               } else if (!strcmp(argv[i], "wrrel")) {
+                       if (i + 1 >= argc)
+                               return -1;
+                       pconf->user.wr_rel_change = 1;
+                       if (!strcmp(argv[i+1], "on"))
+                               pconf->user.wr_rel_set = 1;
+                       else if (!strcmp(argv[i+1], "off"))
+                               pconf->user.wr_rel_set = 0;
+                       else
+                               return -1;
+                       i += 2;
+               } else {
+                       break;
+               }
+       }
+       return i;
+}
+
+static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
+                          int argc, char * const argv[])
+{
+       int i;
+
+       memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
+
+       if (1 >= argc)
+               return -1;
+       pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
+
+       i = 1;
+       while (i < argc) {
+               if (!strcmp(argv[i], "enh")) {
+                       pconf->gp_part[pidx].enhanced = 1;
+                       i += 1;
+               } else if (!strcmp(argv[i], "wrrel")) {
+                       if (i + 1 >= argc)
+                               return -1;
+                       pconf->gp_part[pidx].wr_rel_change = 1;
+                       if (!strcmp(argv[i+1], "on"))
+                               pconf->gp_part[pidx].wr_rel_set = 1;
+                       else if (!strcmp(argv[i+1], "off"))
+                               pconf->gp_part[pidx].wr_rel_set = 0;
+                       else
+                               return -1;
+                       i += 2;
+               } else {
+                       break;
+               }
+       }
+       return i;
+}
+
+static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
+                             int argc, char * const argv[])
+{
+       struct mmc *mmc;
+       struct mmc_hwpart_conf pconf = { };
+       enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
+       int i, r, pidx;
+
+       mmc = init_mmc_device(curr_device, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (argc < 1)
+               return CMD_RET_USAGE;
+       i = 1;
+       while (i < argc) {
+               if (!strcmp(argv[i], "user")) {
+                       i++;
+                       r = parse_hwpart_user(&pconf, argc-i, &argv[i]);
+                       if (r < 0)
+                               return CMD_RET_USAGE;
+                       i += r;
+               } else if (!strncmp(argv[i], "gp", 2) &&
+                          strlen(argv[i]) == 3 &&
+                          argv[i][2] >= '1' && argv[i][2] <= '4') {
+                       pidx = argv[i][2] - '1';
+                       i++;
+                       r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
+                       if (r < 0)
+                               return CMD_RET_USAGE;
+                       i += r;
+               } else if (!strcmp(argv[i], "check")) {
+                       mode = MMC_HWPART_CONF_CHECK;
+                       i++;
+               } else if (!strcmp(argv[i], "set")) {
+                       mode = MMC_HWPART_CONF_SET;
+                       i++;
+               } else if (!strcmp(argv[i], "complete")) {
+                       mode = MMC_HWPART_CONF_COMPLETE;
+                       i++;
+               } else {
+                       return CMD_RET_USAGE;
+               }
+       }
+
+       puts("Partition configuration:\n");
+       if (pconf.user.enh_size) {
+               puts("\tUser Enhanced Start: ");
+               print_size(((u64)pconf.user.enh_start) << 9, "\n");
+               puts("\tUser Enhanced Size: ");
+               print_size(((u64)pconf.user.enh_size) << 9, "\n");
+       } else {
+               puts("\tNo enhanced user data area\n");
+       }
+       if (pconf.user.wr_rel_change)
+               printf("\tUser partition write reliability: %s\n",
+                      pconf.user.wr_rel_set ? "on" : "off");
+       for (pidx = 0; pidx < 4; pidx++) {
+               if (pconf.gp_part[pidx].size) {
+                       printf("\tGP%i Capacity: ", pidx+1);
+                       print_size(((u64)pconf.gp_part[pidx].size) << 9,
+                                  pconf.gp_part[pidx].enhanced ?
+                                  " ENH\n" : "\n");
+               } else {
+                       printf("\tNo GP%i partition\n", pidx+1);
+               }
+               if (pconf.gp_part[pidx].wr_rel_change)
+                       printf("\tGP%i write reliability: %s\n", pidx+1,
+                              pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
+       }
+
+       if (!mmc_hwpart_config(mmc, &pconf, mode)) {
+               if (mode == MMC_HWPART_CONF_COMPLETE)
+                       puts("Partitioning successful, "
+                            "power-cycle to make effective\n");
+               return CMD_RET_SUCCESS;
+       } else {
+               puts("Failed!\n");
+               return CMD_RET_FAILURE;
+       }
+}
+
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
+                         int argc, char * const argv[])
+{
+       int dev;
+       struct mmc *mmc;
+       u8 width, reset, mode;
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+       dev = simple_strtoul(argv[1], NULL, 10);
+       width = simple_strtoul(argv[2], NULL, 10);
+       reset = simple_strtoul(argv[3], NULL, 10);
+       mode = simple_strtoul(argv[4], NULL, 10);
+
+       mmc = init_mmc_device(dev, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (IS_SD(mmc)) {
+               puts("BOOT_BUS_WIDTH only exists on eMMC\n");
+               return CMD_RET_FAILURE;
+       }
+
+       /* acknowledge to be sent during boot operation */
+       return mmc_set_boot_bus_width(mmc, width, reset, mode);
+}
+static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
+                             int argc, char * const argv[])
+{
+       int dev;
+       struct mmc *mmc;
+       u32 bootsize, rpmbsize;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+       dev = simple_strtoul(argv[1], NULL, 10);
+       bootsize = simple_strtoul(argv[2], NULL, 10);
+       rpmbsize = simple_strtoul(argv[3], NULL, 10);
+
+       mmc = init_mmc_device(dev, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (IS_SD(mmc)) {
+               printf("It is not a EMMC device\n");
+               return CMD_RET_FAILURE;
+       }
+
+       if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
+               printf("EMMC boot partition Size change Failed.\n");
+               return CMD_RET_FAILURE;
+       }
+
+       printf("EMMC boot partition Size %d MB\n", bootsize);
+       printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
+       return CMD_RET_SUCCESS;
+}
+static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
+                          int argc, char * const argv[])
+{
+       int dev;
+       struct mmc *mmc;
+       u8 ack, part_num, access;
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       dev = simple_strtoul(argv[1], NULL, 10);
+       ack = simple_strtoul(argv[2], NULL, 10);
+       part_num = simple_strtoul(argv[3], NULL, 10);
+       access = simple_strtoul(argv[4], NULL, 10);
+
+       mmc = init_mmc_device(dev, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (IS_SD(mmc)) {
+               puts("PARTITION_CONFIG only exists on eMMC\n");
+               return CMD_RET_FAILURE;
+       }
+
+       /* acknowledge to be sent during boot operation */
+       return mmc_set_part_conf(mmc, ack, part_num, access);
+}
+static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
+                          int argc, char * const argv[])
+{
+       int dev;
+       struct mmc *mmc;
+       u8 enable;
+
+       /*
+        * Set the RST_n_ENABLE bit of RST_n_FUNCTION
+        * The only valid values are 0x0, 0x1 and 0x2 and writing
+        * a value of 0x1 or 0x2 sets the value permanently.
+        */
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       dev = simple_strtoul(argv[1], NULL, 10);
+       enable = simple_strtoul(argv[2], NULL, 10);
+
+       if (enable > 2) {
+               puts("Invalid RST_n_ENABLE value\n");
+               return CMD_RET_USAGE;
+       }
+
+       mmc = init_mmc_device(dev, false);
+       if (!mmc)
+               return CMD_RET_FAILURE;
+
+       if (IS_SD(mmc)) {
+               puts("RST_n_FUNCTION only exists on eMMC\n");
+               return CMD_RET_FAILURE;
+       }
+
+       return mmc_set_rst_n_function(mmc, enable);
+}
+#endif
+static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
+                        int argc, char * const argv[])
+{
+       struct mmc *mmc;
+       u32 val;
+       int ret;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+       val = simple_strtoul(argv[2], NULL, 16);
+
+       mmc = find_mmc_device(curr_device);
+       if (!mmc) {
+               printf("no mmc device at slot %x\n", curr_device);
+               return CMD_RET_FAILURE;
+       }
+       ret = mmc_set_dsr(mmc, val);
+       printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
+       if (!ret) {
+               mmc->has_init = 0;
+               if (mmc_init(mmc))
+                       return CMD_RET_FAILURE;
+               else
+                       return CMD_RET_SUCCESS;
+       }
+       return ret;
+}
+
+static cmd_tbl_t cmd_mmc[] = {
+       U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
+       U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
+       U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
+       U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
+       U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
+       U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
+       U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
+       U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+       U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
+       U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
+       U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
+       U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
+#endif
+#ifdef CONFIG_SUPPORT_EMMC_RPMB
+       U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
+};
+
+static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *cp;
+
+       cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
+
+       /* Drop the mmc command */
+       argc--;
+       argv++;
+
+       if (cp == NULL || argc > cp->maxargs)
+               return CMD_RET_USAGE;
+       if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
+               return CMD_RET_SUCCESS;
+
+       if (curr_device < 0) {
+               if (get_mmc_num() > 0) {
+                       curr_device = 0;
+               } else {
+                       puts("No MMC device available\n");
+                       return CMD_RET_FAILURE;
+               }
+       }
+       return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+       mmc, 29, 1, do_mmcops,
+       "MMC sub system",
+       "info - display info of the current MMC device\n"
+       "mmc read addr blk# cnt\n"
+       "mmc write addr blk# cnt\n"
+       "mmc erase blk# cnt\n"
+       "mmc rescan\n"
+       "mmc part - lists available partition on current mmc device\n"
+       "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
+       "mmc list - lists available devices\n"
+       "mmc hwpartition [args...] - does hardware partitioning\n"
+       "  arguments (sizes in 512-byte blocks):\n"
+       "    [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
+       "    [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
+       "    [check|set|complete] - mode, complete set partitioning completed\n"
+       "  WARNING: Partitioning is a write-once setting once it is set to complete.\n"
+       "  Power cycling is required to initialize partitions after set to complete.\n"
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+       "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
+       " - Set the BOOT_BUS_WIDTH field of the specified device\n"
+       "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
+       " - Change sizes of boot and RPMB partitions of specified device\n"
+       "mmc partconf dev boot_ack boot_partition partition_access\n"
+       " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
+       "mmc rst-function dev value\n"
+       " - Change the RST_n_FUNCTION field of the specified device\n"
+       "   WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
+#endif
+#ifdef CONFIG_SUPPORT_EMMC_RPMB
+       "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
+       "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
+       "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
+       "mmc rpmb counter - read the value of the write counter\n"
+#endif
+       "mmc setdsr <value> - set DSR register value\n"
+       );
+
+/* Old command kept for compatibility. Same as 'mmc info' */
+U_BOOT_CMD(
+       mmcinfo, 1, 0, do_mmcinfo,
+       "display MMC info",
+       "- display info of the current MMC device"
+);
+
+#endif /* !CONFIG_GENERIC_MMC */
diff --git a/cmd/mmc_spi.c b/cmd/mmc_spi.c
new file mode 100644 (file)
index 0000000..a2138b8
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Command for mmc_spi setup.
+ *
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <mmc.h>
+#include <spi.h>
+
+#ifndef CONFIG_MMC_SPI_BUS
+# define CONFIG_MMC_SPI_BUS 0
+#endif
+#ifndef CONFIG_MMC_SPI_CS
+# define CONFIG_MMC_SPI_CS 1
+#endif
+/* in SPI mode, MMC speed limit is 20MHz, while SD speed limit is 25MHz */
+#ifndef CONFIG_MMC_SPI_SPEED
+# define CONFIG_MMC_SPI_SPEED 25000000
+#endif
+/* MMC and SD specs only seem to care that sampling is on the
+ * rising edge ... meaning SPI modes 0 or 3.  So either SPI mode
+ * should be legit.  We'll use mode 0 since the steady state is 0,
+ * which is appropriate for hotplugging, unless the platform data
+ * specify mode 3 (if hardware is not compatible to mode 0).
+ */
+#ifndef CONFIG_MMC_SPI_MODE
+# define CONFIG_MMC_SPI_MODE SPI_MODE_0
+#endif
+
+static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint bus = CONFIG_MMC_SPI_BUS;
+       uint cs = CONFIG_MMC_SPI_CS;
+       uint speed = CONFIG_MMC_SPI_SPEED;
+       uint mode = CONFIG_MMC_SPI_MODE;
+       char *endp;
+       struct mmc *mmc;
+
+       if (argc < 2)
+               goto usage;
+
+       cs = simple_strtoul(argv[1], &endp, 0);
+       if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
+               goto usage;
+       if (*endp == ':') {
+               if (endp[1] == 0)
+                       goto usage;
+               bus = cs;
+               cs = simple_strtoul(endp + 1, &endp, 0);
+               if (*endp != 0)
+                       goto usage;
+       }
+       if (argc >= 3) {
+               speed = simple_strtoul(argv[2], &endp, 0);
+               if (*argv[2] == 0 || *endp != 0)
+                       goto usage;
+       }
+       if (argc >= 4) {
+               mode = simple_strtoul(argv[3], &endp, 16);
+               if (*argv[3] == 0 || *endp != 0)
+                       goto usage;
+       }
+       if (!spi_cs_is_valid(bus, cs)) {
+               printf("Invalid SPI bus %u cs %u\n", bus, cs);
+               return 1;
+       }
+
+       mmc = mmc_spi_init(bus, cs, speed, mode);
+       if (!mmc) {
+               printf("Failed to create MMC Device\n");
+               return 1;
+       }
+       printf("%s: %d at %u:%u hz %u mode %u\n", mmc->cfg->name, mmc->block_dev.dev,
+              bus, cs, speed, mode);
+       mmc_init(mmc);
+       return 0;
+
+usage:
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       mmc_spi,        4,      0,      do_mmc_spi,
+       "mmc_spi setup",
+       "[bus:]cs [hz] [mode]   - setup mmc_spi device"
+);
diff --git a/cmd/mp.c b/cmd/mp.c
new file mode 100644 (file)
index 0000000..a80c642
--- /dev/null
+++ b/cmd/mp.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int cpu_status_all(void)
+{
+       unsigned long cpuid;
+
+       for (cpuid = 0; ; cpuid++) {
+               if (!is_core_valid(cpuid)) {
+                       if (cpuid == 0) {
+                               printf("Core num: %lu is not valid\n", cpuid);
+                               return 1;
+                       }
+                       break;
+               }
+               cpu_status(cpuid);
+       }
+
+       return 0;
+}
+
+static int
+cpu_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long cpuid;
+
+       if (argc == 2 && strncmp(argv[1], "status", 6) == 0)
+                 return cpu_status_all();
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       cpuid = simple_strtoul(argv[1], NULL, 10);
+       if (!is_core_valid(cpuid)) {
+               printf ("Core num: %lu is not valid\n", cpuid);
+               return 1;
+       }
+
+
+       if (argc == 3) {
+               if (strncmp(argv[2], "reset", 5) == 0)
+                       cpu_reset(cpuid);
+               else if (strncmp(argv[2], "status", 6) == 0)
+                       cpu_status(cpuid);
+               else if (strncmp(argv[2], "disable", 7) == 0)
+                       return cpu_disable(cpuid);
+               else
+                       return CMD_RET_USAGE;
+
+               return 0;
+       }
+
+       /* 4 or greater, make sure its release */
+       if (strncmp(argv[2], "release", 7) != 0)
+               return CMD_RET_USAGE;
+
+       if (cpu_release(cpuid, argc - 3, argv + 3))
+               return CMD_RET_USAGE;
+
+       return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char cpu_help_text[] =
+           "<num> reset                 - Reset cpu <num>\n"
+       "cpu status                      - Status of all cpus\n"
+       "cpu <num> status                - Status of cpu <num>\n"
+       "cpu <num> disable               - Disable cpu <num>\n"
+       "cpu <num> release <addr> [args] - Release cpu <num> at <addr> with [args]"
+#ifdef CONFIG_PPC
+       "\n"
+       "                         [args] : <pir> <r3> <r6>\n" \
+       "                                   pir - processor id (if writeable)\n" \
+       "                                    r3 - value for gpr 3\n" \
+       "                                    r6 - value for gpr 6\n" \
+       "\n" \
+       "     Use '-' for any arg if you want the default value.\n" \
+       "     Default for r3 is <num> and r6 is 0\n" \
+       "\n" \
+       "     When cpu <num> is released r4 and r5 = 0.\n" \
+       "     r7 will contain the size of the initial mapped area"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       cpu, CONFIG_SYS_MAXARGS, 1, cpu_cmd,
+       "Multiprocessor CPU boot manipulation and release", cpu_help_text
+);
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
new file mode 100644 (file)
index 0000000..dab1958
--- /dev/null
@@ -0,0 +1,2106 @@
+/*
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2002
+ * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
+ *
+ * (C) Copyright 2003
+ * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
+ *
+ * (C) Copyright 2005
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ *   Added support for reading flash partition table from environment.
+ *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
+ *   kernel tree.
+ *
+ * (C) Copyright 2008
+ * Harald Welte, OpenMoko, Inc., Harald Welte <laforge@openmoko.org>
+ *
+ *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
+ *   Copyright 2002 SYSGO Real-Time Solutions GmbH
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Three environment variables are used by the parsing routines:
+ *
+ * 'partition' - keeps current partition identifier
+ *
+ * partition  := <part-id>
+ * <part-id>  := <dev-id>,part_num
+ *
+ *
+ * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
+ *
+ * mtdids=<idmap>[,<idmap>,...]
+ *
+ * <idmap>    := <dev-id>=<mtd-id>
+ * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
+ * <dev-num>  := mtd device number, 0...
+ * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
+ *
+ *
+ * 'mtdparts' - partition list
+ *
+ * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
+ *
+ * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
+ * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
+ * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
+ * <size>     := standard linux memsize OR '-' to denote all remaining space
+ * <offset>   := partition start offset within the device
+ * <name>     := '(' NAME ')'
+ * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
+ *
+ * Notes:
+ * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
+ * - if the above variables are not set defaults for a given target are used
+ *
+ * Examples:
+ *
+ * 1 NOR Flash, with 1 single writable partition:
+ * mtdids=nor0=edb7312-nor
+ * mtdparts=mtdparts=edb7312-nor:-
+ *
+ * 1 NOR Flash with 2 partitions, 1 NAND with one
+ * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
+ * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <jffs2/load_kernel.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+#include <linux/err.h>
+#include <linux/mtd/mtd.h>
+
+#if defined(CONFIG_CMD_NAND)
+#include <linux/mtd/nand.h>
+#include <nand.h>
+#endif
+
+#if defined(CONFIG_CMD_ONENAND)
+#include <linux/mtd/onenand.h>
+#include <onenand_uboot.h>
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* special size referring to all the remaining space in a partition */
+#define SIZE_REMAINING         (~0llu)
+
+/* special offset value, it is used when not provided by user
+ *
+ * this value is used temporarily during parsing, later such offests
+ * are recalculated */
+#define OFFSET_NOT_SPECIFIED   (~0llu)
+
+/* minimum partition size */
+#define MIN_PART_SIZE          4096
+
+/* this flag needs to be set in part_info struct mask_flags
+ * field for read-only partitions */
+#define MTD_WRITEABLE_CMD              1
+
+/* default values for mtdids and mtdparts variables */
+#if defined(MTDIDS_DEFAULT)
+static const char *const mtdids_default = MTDIDS_DEFAULT;
+#else
+static const char *const mtdids_default = NULL;
+#endif
+
+#if defined(MTDPARTS_DEFAULT)
+static const char *const mtdparts_default = MTDPARTS_DEFAULT;
+#else
+static const char *const mtdparts_default = NULL;
+#endif
+
+/* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
+#define MTDIDS_MAXLEN          128
+#define MTDPARTS_MAXLEN                512
+#define PARTITION_MAXLEN       16
+static char last_ids[MTDIDS_MAXLEN];
+static char last_parts[MTDPARTS_MAXLEN];
+static char last_partition[PARTITION_MAXLEN];
+
+/* low level jffs2 cache cleaning routine */
+extern void jffs2_free_cache(struct part_info *part);
+
+/* mtdids mapping list, filled by parse_ids() */
+static struct list_head mtdids;
+
+/* device/partition list, parse_cmdline() parses into here */
+static struct list_head devices;
+
+/* current active device and partition number */
+struct mtd_device *current_mtd_dev = NULL;
+u8 current_mtd_partnum = 0;
+
+static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
+
+/* command line only routines */
+static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
+static int device_del(struct mtd_device *dev);
+
+/**
+ * Parses a string into a number.  The number stored at ptr is
+ * potentially suffixed with K (for kilobytes, or 1024 bytes),
+ * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
+ * 1073741824).  If the number is suffixed with K, M, or G, then
+ * the return value is the number multiplied by one kilobyte, one
+ * megabyte, or one gigabyte, respectively.
+ *
+ * @param ptr where parse begins
+ * @param retptr output pointer to next char after parse completes (output)
+ * @return resulting unsigned int
+ */
+static u64 memsize_parse (const char *const ptr, const char **retptr)
+{
+       u64 ret = simple_strtoull(ptr, (char **)retptr, 0);
+
+       switch (**retptr) {
+               case 'G':
+               case 'g':
+                       ret <<= 10;
+               case 'M':
+               case 'm':
+                       ret <<= 10;
+               case 'K':
+               case 'k':
+                       ret <<= 10;
+                       (*retptr)++;
+               default:
+                       break;
+       }
+
+       return ret;
+}
+
+/**
+ * Format string describing supplied size. This routine does the opposite job
+ * to memsize_parse(). Size in bytes is converted to string and if possible
+ * shortened by using k (kilobytes), m (megabytes) or g (gigabytes) suffix.
+ *
+ * Note, that this routine does not check for buffer overflow, it's the caller
+ * who must assure enough space.
+ *
+ * @param buf output buffer
+ * @param size size to be converted to string
+ */
+static void memsize_format(char *buf, u64 size)
+{
+#define SIZE_GB ((u32)1024*1024*1024)
+#define SIZE_MB ((u32)1024*1024)
+#define SIZE_KB ((u32)1024)
+
+       if ((size % SIZE_GB) == 0)
+               sprintf(buf, "%llug", size/SIZE_GB);
+       else if ((size % SIZE_MB) == 0)
+               sprintf(buf, "%llum", size/SIZE_MB);
+       else if (size % SIZE_KB == 0)
+               sprintf(buf, "%lluk", size/SIZE_KB);
+       else
+               sprintf(buf, "%llu", size);
+}
+
+/**
+ * This routine does global indexing of all partitions. Resulting index for
+ * current partition is saved in 'mtddevnum'. Current partition name in
+ * 'mtddevname'.
+ */
+static void index_partitions(void)
+{
+       u16 mtddevnum;
+       struct part_info *part;
+       struct list_head *dentry;
+       struct mtd_device *dev;
+
+       debug("--- index partitions ---\n");
+
+       if (current_mtd_dev) {
+               mtddevnum = 0;
+               list_for_each(dentry, &devices) {
+                       dev = list_entry(dentry, struct mtd_device, link);
+                       if (dev == current_mtd_dev) {
+                               mtddevnum += current_mtd_partnum;
+                               setenv_ulong("mtddevnum", mtddevnum);
+                               break;
+                       }
+                       mtddevnum += dev->num_parts;
+               }
+
+               part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
+               setenv("mtddevname", part->name);
+
+               debug("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
+       } else {
+               setenv("mtddevnum", NULL);
+               setenv("mtddevname", NULL);
+
+               debug("=> mtddevnum NULL\n=> mtddevname NULL\n");
+       }
+}
+
+/**
+ * Save current device and partition in environment variable 'partition'.
+ */
+static void current_save(void)
+{
+       char buf[16];
+
+       debug("--- current_save ---\n");
+
+       if (current_mtd_dev) {
+               sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type),
+                                       current_mtd_dev->id->num, current_mtd_partnum);
+
+               setenv("partition", buf);
+               strncpy(last_partition, buf, 16);
+
+               debug("=> partition %s\n", buf);
+       } else {
+               setenv("partition", NULL);
+               last_partition[0] = '\0';
+
+               debug("=> partition NULL\n");
+       }
+       index_partitions();
+}
+
+
+/**
+ * Produce a mtd_info given a type and num.
+ *
+ * @param type mtd type
+ * @param num mtd number
+ * @param mtd a pointer to an mtd_info instance (output)
+ * @return 0 if device is valid, 1 otherwise
+ */
+static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
+{
+       char mtd_dev[16];
+
+       sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
+       *mtd = get_mtd_device_nm(mtd_dev);
+       if (IS_ERR(*mtd)) {
+               printf("Device %s not found!\n", mtd_dev);
+               return 1;
+       }
+       put_mtd_device(*mtd);
+
+       return 0;
+}
+
+/**
+ * Performs sanity check for supplied flash partition.
+ * Table of existing MTD flash devices is searched and partition device
+ * is located. Alignment with the granularity of nand erasesize is verified.
+ *
+ * @param id of the parent device
+ * @param part partition to validate
+ * @return 0 if partition is valid, 1 otherwise
+ */
+static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
+{
+       struct mtd_info *mtd = NULL;
+       int i, j;
+       ulong start;
+       u64 offset, size;
+
+       if (get_mtd_info(id->type, id->num, &mtd))
+               return 1;
+
+       part->sector_size = mtd->erasesize;
+
+       if (!mtd->numeraseregions) {
+               /*
+                * Only one eraseregion (NAND, OneNAND or uniform NOR),
+                * checking for alignment is easy here
+                */
+               offset = part->offset;
+               if (do_div(offset, mtd->erasesize)) {
+                       printf("%s%d: partition (%s) start offset"
+                              "alignment incorrect\n",
+                              MTD_DEV_TYPE(id->type), id->num, part->name);
+                       return 1;
+               }
+
+               size = part->size;
+               if (do_div(size, mtd->erasesize)) {
+                       printf("%s%d: partition (%s) size alignment incorrect\n",
+                              MTD_DEV_TYPE(id->type), id->num, part->name);
+                       return 1;
+               }
+       } else {
+               /*
+                * Multiple eraseregions (non-uniform NOR),
+                * checking for alignment is more complex here
+                */
+
+               /* Check start alignment */
+               for (i = 0; i < mtd->numeraseregions; i++) {
+                       start = mtd->eraseregions[i].offset;
+                       for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
+                               if (part->offset == start)
+                                       goto start_ok;
+                               start += mtd->eraseregions[i].erasesize;
+                       }
+               }
+
+               printf("%s%d: partition (%s) start offset alignment incorrect\n",
+                      MTD_DEV_TYPE(id->type), id->num, part->name);
+               return 1;
+
+       start_ok:
+
+               /* Check end/size alignment */
+               for (i = 0; i < mtd->numeraseregions; i++) {
+                       start = mtd->eraseregions[i].offset;
+                       for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
+                               if ((part->offset + part->size) == start)
+                                       goto end_ok;
+                               start += mtd->eraseregions[i].erasesize;
+                       }
+               }
+               /* Check last sector alignment */
+               if ((part->offset + part->size) == start)
+                       goto end_ok;
+
+               printf("%s%d: partition (%s) size alignment incorrect\n",
+                      MTD_DEV_TYPE(id->type), id->num, part->name);
+               return 1;
+
+       end_ok:
+               return 0;
+       }
+
+       return 0;
+}
+
+
+/**
+ * Performs sanity check for supplied partition. Offset and size are
+ * verified to be within valid range. Partition type is checked and
+ * part_validate_eraseblock() is called with the argument of part.
+ *
+ * @param id of the parent device
+ * @param part partition to validate
+ * @return 0 if partition is valid, 1 otherwise
+ */
+static int part_validate(struct mtdids *id, struct part_info *part)
+{
+       if (part->size == SIZE_REMAINING)
+               part->size = id->size - part->offset;
+
+       if (part->offset > id->size) {
+               printf("%s: offset %08llx beyond flash size %08llx\n",
+                               id->mtd_id, part->offset, id->size);
+               return 1;
+       }
+
+       if ((part->offset + part->size) <= part->offset) {
+               printf("%s%d: partition (%s) size too big\n",
+                               MTD_DEV_TYPE(id->type), id->num, part->name);
+               return 1;
+       }
+
+       if (part->offset + part->size > id->size) {
+               printf("%s: partitioning exceeds flash size\n", id->mtd_id);
+               return 1;
+       }
+
+       /*
+        * Now we need to check if the partition starts and ends on
+        * sector (eraseblock) regions
+        */
+       return part_validate_eraseblock(id, part);
+}
+
+/**
+ * Delete selected partition from the partition list of the specified device.
+ *
+ * @param dev device to delete partition from
+ * @param part partition to delete
+ * @return 0 on success, 1 otherwise
+ */
+static int part_del(struct mtd_device *dev, struct part_info *part)
+{
+       u8 current_save_needed = 0;
+
+       /* if there is only one partition, remove whole device */
+       if (dev->num_parts == 1)
+               return device_del(dev);
+
+       /* otherwise just delete this partition */
+
+       if (dev == current_mtd_dev) {
+               /* we are modyfing partitions for the current device,
+                * update current */
+               struct part_info *curr_pi;
+               curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
+
+               if (curr_pi) {
+                       if (curr_pi == part) {
+                               printf("current partition deleted, resetting current to 0\n");
+                               current_mtd_partnum = 0;
+                       } else if (part->offset <= curr_pi->offset) {
+                               current_mtd_partnum--;
+                       }
+                       current_save_needed = 1;
+               }
+       }
+
+       list_del(&part->link);
+       free(part);
+       dev->num_parts--;
+
+       if (current_save_needed > 0)
+               current_save();
+       else
+               index_partitions();
+
+       return 0;
+}
+
+/**
+ * Delete all partitions from parts head list, free memory.
+ *
+ * @param head list of partitions to delete
+ */
+static void part_delall(struct list_head *head)
+{
+       struct list_head *entry, *n;
+       struct part_info *part_tmp;
+
+       /* clean tmp_list and free allocated memory */
+       list_for_each_safe(entry, n, head) {
+               part_tmp = list_entry(entry, struct part_info, link);
+
+               list_del(entry);
+               free(part_tmp);
+       }
+}
+
+/**
+ * Add new partition to the supplied partition list. Make sure partitions are
+ * sorted by offset in ascending order.
+ *
+ * @param head list this partition is to be added to
+ * @param new partition to be added
+ */
+static int part_sort_add(struct mtd_device *dev, struct part_info *part)
+{
+       struct list_head *entry;
+       struct part_info *new_pi, *curr_pi;
+
+       /* link partition to parrent dev */
+       part->dev = dev;
+
+       if (list_empty(&dev->parts)) {
+               debug("part_sort_add: list empty\n");
+               list_add(&part->link, &dev->parts);
+               dev->num_parts++;
+               index_partitions();
+               return 0;
+       }
+
+       new_pi = list_entry(&part->link, struct part_info, link);
+
+       /* get current partition info if we are updating current device */
+       curr_pi = NULL;
+       if (dev == current_mtd_dev)
+               curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
+
+       list_for_each(entry, &dev->parts) {
+               struct part_info *pi;
+
+               pi = list_entry(entry, struct part_info, link);
+
+               /* be compliant with kernel cmdline, allow only one partition at offset zero */
+               if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
+                       printf("cannot add second partition at offset 0\n");
+                       return 1;
+               }
+
+               if (new_pi->offset <= pi->offset) {
+                       list_add_tail(&part->link, entry);
+                       dev->num_parts++;
+
+                       if (curr_pi && (pi->offset <= curr_pi->offset)) {
+                               /* we are modyfing partitions for the current
+                                * device, update current */
+                               current_mtd_partnum++;
+                               current_save();
+                       } else {
+                               index_partitions();
+                       }
+                       return 0;
+               }
+       }
+
+       list_add_tail(&part->link, &dev->parts);
+       dev->num_parts++;
+       index_partitions();
+       return 0;
+}
+
+/**
+ * Add provided partition to the partition list of a given device.
+ *
+ * @param dev device to which partition is added
+ * @param part partition to be added
+ * @return 0 on success, 1 otherwise
+ */
+static int part_add(struct mtd_device *dev, struct part_info *part)
+{
+       /* verify alignment and size */
+       if (part_validate(dev->id, part) != 0)
+               return 1;
+
+       /* partition is ok, add it to the list */
+       if (part_sort_add(dev, part) != 0)
+               return 1;
+
+       return 0;
+}
+
+/**
+ * Parse one partition definition, allocate memory and return pointer to this
+ * location in retpart.
+ *
+ * @param partdef pointer to the partition definition string i.e. <part-def>
+ * @param ret output pointer to next char after parse completes (output)
+ * @param retpart pointer to the allocated partition (output)
+ * @return 0 on success, 1 otherwise
+ */
+static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
+{
+       struct part_info *part;
+       u64 size;
+       u64 offset;
+       const char *name;
+       int name_len;
+       unsigned int mask_flags;
+       const char *p;
+
+       p = partdef;
+       *retpart = NULL;
+       *ret = NULL;
+
+       /* fetch the partition size */
+       if (*p == '-') {
+               /* assign all remaining space to this partition */
+               debug("'-': remaining size assigned\n");
+               size = SIZE_REMAINING;
+               p++;
+       } else {
+               size = memsize_parse(p, &p);
+               if (size < MIN_PART_SIZE) {
+                       printf("partition size too small (%llx)\n", size);
+                       return 1;
+               }
+       }
+
+       /* check for offset */
+       offset = OFFSET_NOT_SPECIFIED;
+       if (*p == '@') {
+               p++;
+               offset = memsize_parse(p, &p);
+       }
+
+       /* now look for the name */
+       if (*p == '(') {
+               name = ++p;
+               if ((p = strchr(name, ')')) == NULL) {
+                       printf("no closing ) found in partition name\n");
+                       return 1;
+               }
+               name_len = p - name + 1;
+               if ((name_len - 1) == 0) {
+                       printf("empty partition name\n");
+                       return 1;
+               }
+               p++;
+       } else {
+               /* 0x00000000@0x00000000 */
+               name_len = 22;
+               name = NULL;
+       }
+
+       /* test for options */
+       mask_flags = 0;
+       if (strncmp(p, "ro", 2) == 0) {
+               mask_flags |= MTD_WRITEABLE_CMD;
+               p += 2;
+       }
+
+       /* check for next partition definition */
+       if (*p == ',') {
+               if (size == SIZE_REMAINING) {
+                       *ret = NULL;
+                       printf("no partitions allowed after a fill-up partition\n");
+                       return 1;
+               }
+               *ret = ++p;
+       } else if ((*p == ';') || (*p == '\0')) {
+               *ret = p;
+       } else {
+               printf("unexpected character '%c' at the end of partition\n", *p);
+               *ret = NULL;
+               return 1;
+       }
+
+       /*  allocate memory */
+       part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
+       if (!part) {
+               printf("out of memory\n");
+               return 1;
+       }
+       memset(part, 0, sizeof(struct part_info) + name_len);
+       part->size = size;
+       part->offset = offset;
+       part->mask_flags = mask_flags;
+       part->name = (char *)(part + 1);
+
+       if (name) {
+               /* copy user provided name */
+               strncpy(part->name, name, name_len - 1);
+               part->auto_name = 0;
+       } else {
+               /* auto generated name in form of size@offset */
+               sprintf(part->name, "0x%08llx@0x%08llx", size, offset);
+               part->auto_name = 1;
+       }
+
+       part->name[name_len - 1] = '\0';
+       INIT_LIST_HEAD(&part->link);
+
+       debug("+ partition: name %-22s size 0x%08llx offset 0x%08llx mask flags %d\n",
+                       part->name, part->size,
+                       part->offset, part->mask_flags);
+
+       *retpart = part;
+       return 0;
+}
+
+/**
+ * Check device number to be within valid range for given device type.
+ *
+ * @param type mtd type
+ * @param num mtd number
+ * @param size a pointer to the size of the mtd device (output)
+ * @return 0 if device is valid, 1 otherwise
+ */
+static int mtd_device_validate(u8 type, u8 num, u64 *size)
+{
+       struct mtd_info *mtd = NULL;
+
+       if (get_mtd_info(type, num, &mtd))
+               return 1;
+
+       *size = mtd->size;
+
+       return 0;
+}
+
+/**
+ * Delete all mtd devices from a supplied devices list, free memory allocated for
+ * each device and delete all device partitions.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+static int device_delall(struct list_head *head)
+{
+       struct list_head *entry, *n;
+       struct mtd_device *dev_tmp;
+
+       /* clean devices list */
+       list_for_each_safe(entry, n, head) {
+               dev_tmp = list_entry(entry, struct mtd_device, link);
+               list_del(entry);
+               part_delall(&dev_tmp->parts);
+               free(dev_tmp);
+       }
+       INIT_LIST_HEAD(&devices);
+
+       return 0;
+}
+
+/**
+ * If provided device exists it's partitions are deleted, device is removed
+ * from device list and device memory is freed.
+ *
+ * @param dev device to be deleted
+ * @return 0 on success, 1 otherwise
+ */
+static int device_del(struct mtd_device *dev)
+{
+       part_delall(&dev->parts);
+       list_del(&dev->link);
+       free(dev);
+
+       if (dev == current_mtd_dev) {
+               /* we just deleted current device */
+               if (list_empty(&devices)) {
+                       current_mtd_dev = NULL;
+               } else {
+                       /* reset first partition from first dev from the
+                        * devices list as current */
+                       current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
+                       current_mtd_partnum = 0;
+               }
+               current_save();
+               return 0;
+       }
+
+       index_partitions();
+       return 0;
+}
+
+/**
+ * Search global device list and return pointer to the device of type and num
+ * specified.
+ *
+ * @param type device type
+ * @param num device number
+ * @return NULL if requested device does not exist
+ */
+struct mtd_device *device_find(u8 type, u8 num)
+{
+       struct list_head *entry;
+       struct mtd_device *dev_tmp;
+
+       list_for_each(entry, &devices) {
+               dev_tmp = list_entry(entry, struct mtd_device, link);
+
+               if ((dev_tmp->id->type == type) && (dev_tmp->id->num == num))
+                       return dev_tmp;
+       }
+
+       return NULL;
+}
+
+/**
+ * Add specified device to the global device list.
+ *
+ * @param dev device to be added
+ */
+static void device_add(struct mtd_device *dev)
+{
+       u8 current_save_needed = 0;
+
+       if (list_empty(&devices)) {
+               current_mtd_dev = dev;
+               current_mtd_partnum = 0;
+               current_save_needed = 1;
+       }
+
+       list_add_tail(&dev->link, &devices);
+
+       if (current_save_needed > 0)
+               current_save();
+       else
+               index_partitions();
+}
+
+/**
+ * Parse device type, name and mtd-id. If syntax is ok allocate memory and
+ * return pointer to the device structure.
+ *
+ * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
+ * @param ret output pointer to next char after parse completes (output)
+ * @param retdev pointer to the allocated device (output)
+ * @return 0 on success, 1 otherwise
+ */
+static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
+{
+       struct mtd_device *dev;
+       struct part_info *part;
+       struct mtdids *id;
+       const char *mtd_id;
+       unsigned int mtd_id_len;
+       const char *p;
+       const char *pend;
+       LIST_HEAD(tmp_list);
+       struct list_head *entry, *n;
+       u16 num_parts;
+       u64 offset;
+       int err = 1;
+
+       debug("===device_parse===\n");
+
+       assert(retdev);
+       *retdev = NULL;
+
+       if (ret)
+               *ret = NULL;
+
+       /* fetch <mtd-id> */
+       mtd_id = p = mtd_dev;
+       if (!(p = strchr(mtd_id, ':'))) {
+               printf("no <mtd-id> identifier\n");
+               return 1;
+       }
+       mtd_id_len = p - mtd_id + 1;
+       p++;
+
+       /* verify if we have a valid device specified */
+       if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
+               printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
+               return 1;
+       }
+
+#ifdef DEBUG
+       pend = strchr(p, ';');
+#endif
+       debug("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
+                       id->type, MTD_DEV_TYPE(id->type),
+                       id->num, id->mtd_id);
+       debug("parsing partitions %.*s\n", (int)(pend ? pend - p : strlen(p)), p);
+
+
+       /* parse partitions */
+       num_parts = 0;
+
+       offset = 0;
+       if ((dev = device_find(id->type, id->num)) != NULL) {
+               /* if device already exists start at the end of the last partition */
+               part = list_entry(dev->parts.prev, struct part_info, link);
+               offset = part->offset + part->size;
+       }
+
+       while (p && (*p != '\0') && (*p != ';')) {
+               err = 1;
+               if ((part_parse(p, &p, &part) != 0) || (!part))
+                       break;
+
+               /* calculate offset when not specified */
+               if (part->offset == OFFSET_NOT_SPECIFIED)
+                       part->offset = offset;
+               else
+                       offset = part->offset;
+
+               /* verify alignment and size */
+               if (part_validate(id, part) != 0)
+                       break;
+
+               offset += part->size;
+
+               /* partition is ok, add it to the list */
+               list_add_tail(&part->link, &tmp_list);
+               num_parts++;
+               err = 0;
+       }
+       if (err == 1) {
+               part_delall(&tmp_list);
+               return 1;
+       }
+
+       if (num_parts == 0) {
+               printf("no partitions for device %s%d (%s)\n",
+                               MTD_DEV_TYPE(id->type), id->num, id->mtd_id);
+               return 1;
+       }
+
+       debug("\ntotal partitions: %d\n", num_parts);
+
+       /* check for next device presence */
+       if (p) {
+               if (*p == ';') {
+                       if (ret)
+                               *ret = ++p;
+               } else if (*p == '\0') {
+                       if (ret)
+                               *ret = p;
+               } else {
+                       printf("unexpected character '%c' at the end of device\n", *p);
+                       if (ret)
+                               *ret = NULL;
+                       return 1;
+               }
+       }
+
+       /* allocate memory for mtd_device structure */
+       if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
+               printf("out of memory\n");
+               return 1;
+       }
+       memset(dev, 0, sizeof(struct mtd_device));
+       dev->id = id;
+       dev->num_parts = 0; /* part_sort_add increments num_parts */
+       INIT_LIST_HEAD(&dev->parts);
+       INIT_LIST_HEAD(&dev->link);
+
+       /* move partitions from tmp_list to dev->parts */
+       list_for_each_safe(entry, n, &tmp_list) {
+               part = list_entry(entry, struct part_info, link);
+               list_del(entry);
+               if (part_sort_add(dev, part) != 0) {
+                       device_del(dev);
+                       return 1;
+               }
+       }
+
+       *retdev = dev;
+
+       debug("===\n\n");
+       return 0;
+}
+
+/**
+ * Initialize global device list.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+static int mtd_devices_init(void)
+{
+       last_parts[0] = '\0';
+       current_mtd_dev = NULL;
+       current_save();
+
+       return device_delall(&devices);
+}
+
+/*
+ * Search global mtdids list and find id of requested type and number.
+ *
+ * @return pointer to the id if it exists, NULL otherwise
+ */
+static struct mtdids* id_find(u8 type, u8 num)
+{
+       struct list_head *entry;
+       struct mtdids *id;
+
+       list_for_each(entry, &mtdids) {
+               id = list_entry(entry, struct mtdids, link);
+
+               if ((id->type == type) && (id->num == num))
+                       return id;
+       }
+
+       return NULL;
+}
+
+/**
+ * Search global mtdids list and find id of a requested mtd_id.
+ *
+ * Note: first argument is not null terminated.
+ *
+ * @param mtd_id string containing requested mtd_id
+ * @param mtd_id_len length of supplied mtd_id
+ * @return pointer to the id if it exists, NULL otherwise
+ */
+static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len)
+{
+       struct list_head *entry;
+       struct mtdids *id;
+
+       debug("--- id_find_by_mtd_id: '%.*s' (len = %d)\n",
+                       mtd_id_len, mtd_id, mtd_id_len);
+
+       list_for_each(entry, &mtdids) {
+               id = list_entry(entry, struct mtdids, link);
+
+               debug("entry: '%s' (len = %zu)\n",
+                               id->mtd_id, strlen(id->mtd_id));
+
+               if (mtd_id_len != strlen(id->mtd_id))
+                       continue;
+               if (strncmp(id->mtd_id, mtd_id, mtd_id_len) == 0)
+                       return id;
+       }
+
+       return NULL;
+}
+
+/**
+ * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
+ * return device type and number.
+ *
+ * @param id string describing device id
+ * @param ret_id output pointer to next char after parse completes (output)
+ * @param dev_type parsed device type (output)
+ * @param dev_num parsed device number (output)
+ * @return 0 on success, 1 otherwise
+ */
+int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
+                u8 *dev_num)
+{
+       const char *p = id;
+
+       *dev_type = 0;
+       if (strncmp(p, "nand", 4) == 0) {
+               *dev_type = MTD_DEV_TYPE_NAND;
+               p += 4;
+       } else if (strncmp(p, "nor", 3) == 0) {
+               *dev_type = MTD_DEV_TYPE_NOR;
+               p += 3;
+       } else if (strncmp(p, "onenand", 7) == 0) {
+               *dev_type = MTD_DEV_TYPE_ONENAND;
+               p += 7;
+       } else {
+               printf("incorrect device type in %s\n", id);
+               return 1;
+       }
+
+       if (!isdigit(*p)) {
+               printf("incorrect device number in %s\n", id);
+               return 1;
+       }
+
+       *dev_num = simple_strtoul(p, (char **)&p, 0);
+       if (ret_id)
+               *ret_id = p;
+       return 0;
+}
+
+/**
+ * Process all devices and generate corresponding mtdparts string describing
+ * all partitions on all devices.
+ *
+ * @param buf output buffer holding generated mtdparts string (output)
+ * @param buflen buffer size
+ * @return 0 on success, 1 otherwise
+ */
+static int generate_mtdparts(char *buf, u32 buflen)
+{
+       struct list_head *pentry, *dentry;
+       struct mtd_device *dev;
+       struct part_info *part, *prev_part;
+       char *p = buf;
+       char tmpbuf[32];
+       u64 size, offset;
+       u32 len, part_cnt;
+       u32 maxlen = buflen - 1;
+
+       debug("--- generate_mtdparts ---\n");
+
+       if (list_empty(&devices)) {
+               buf[0] = '\0';
+               return 0;
+       }
+
+       strcpy(p, "mtdparts=");
+       p += 9;
+
+       list_for_each(dentry, &devices) {
+               dev = list_entry(dentry, struct mtd_device, link);
+
+               /* copy mtd_id */
+               len = strlen(dev->id->mtd_id) + 1;
+               if (len > maxlen)
+                       goto cleanup;
+               memcpy(p, dev->id->mtd_id, len - 1);
+               p += len - 1;
+               *(p++) = ':';
+               maxlen -= len;
+
+               /* format partitions */
+               prev_part = NULL;
+               part_cnt = 0;
+               list_for_each(pentry, &dev->parts) {
+                       part = list_entry(pentry, struct part_info, link);
+                       size = part->size;
+                       offset = part->offset;
+                       part_cnt++;
+
+                       /* partition size */
+                       memsize_format(tmpbuf, size);
+                       len = strlen(tmpbuf);
+                       if (len > maxlen)
+                               goto cleanup;
+                       memcpy(p, tmpbuf, len);
+                       p += len;
+                       maxlen -= len;
+
+
+                       /* add offset only when there is a gap between
+                        * partitions */
+                       if ((!prev_part && (offset != 0)) ||
+                                       (prev_part && ((prev_part->offset + prev_part->size) != part->offset))) {
+
+                               memsize_format(tmpbuf, offset);
+                               len = strlen(tmpbuf) + 1;
+                               if (len > maxlen)
+                                       goto cleanup;
+                               *(p++) = '@';
+                               memcpy(p, tmpbuf, len - 1);
+                               p += len - 1;
+                               maxlen -= len;
+                       }
+
+                       /* copy name only if user supplied */
+                       if(!part->auto_name) {
+                               len = strlen(part->name) + 2;
+                               if (len > maxlen)
+                                       goto cleanup;
+
+                               *(p++) = '(';
+                               memcpy(p, part->name, len - 2);
+                               p += len - 2;
+                               *(p++) = ')';
+                               maxlen -= len;
+                       }
+
+                       /* ro mask flag */
+                       if (part->mask_flags && MTD_WRITEABLE_CMD) {
+                               len = 2;
+                               if (len > maxlen)
+                                       goto cleanup;
+                               *(p++) = 'r';
+                               *(p++) = 'o';
+                               maxlen -= 2;
+                       }
+
+                       /* print ',' separator if there are other partitions
+                        * following */
+                       if (dev->num_parts > part_cnt) {
+                               if (1 > maxlen)
+                                       goto cleanup;
+                               *(p++) = ',';
+                               maxlen--;
+                       }
+                       prev_part = part;
+               }
+               /* print ';' separator if there are other devices following */
+               if (dentry->next != &devices) {
+                       if (1 > maxlen)
+                               goto cleanup;
+                       *(p++) = ';';
+                       maxlen--;
+               }
+       }
+
+       /* we still have at least one char left, as we decremented maxlen at
+        * the begining */
+       *p = '\0';
+
+       return 0;
+
+cleanup:
+       last_parts[0] = '\0';
+       return 1;
+}
+
+/**
+ * Call generate_mtdparts to process all devices and generate corresponding
+ * mtdparts string, save it in mtdparts environment variable.
+ *
+ * @param buf output buffer holding generated mtdparts string (output)
+ * @param buflen buffer size
+ * @return 0 on success, 1 otherwise
+ */
+static int generate_mtdparts_save(char *buf, u32 buflen)
+{
+       int ret;
+
+       ret = generate_mtdparts(buf, buflen);
+
+       if ((buf[0] != '\0') && (ret == 0))
+               setenv("mtdparts", buf);
+       else
+               setenv("mtdparts", NULL);
+
+       return ret;
+}
+
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+/**
+ * Get the net size (w/o bad blocks) of the given partition.
+ *
+ * @param mtd the mtd info
+ * @param part the partition
+ * @return the calculated net size of this partition
+ */
+static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
+{
+       uint64_t i, net_size = 0;
+
+       if (!mtd->block_isbad)
+               return part->size;
+
+       for (i = 0; i < part->size; i += mtd->erasesize) {
+               if (!mtd->block_isbad(mtd, part->offset + i))
+                       net_size += mtd->erasesize;
+       }
+
+       return net_size;
+}
+#endif
+
+static void print_partition_table(void)
+{
+       struct list_head *dentry, *pentry;
+       struct part_info *part;
+       struct mtd_device *dev;
+       int part_num;
+
+       list_for_each(dentry, &devices) {
+               dev = list_entry(dentry, struct mtd_device, link);
+               /* list partitions for given device */
+               part_num = 0;
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+               struct mtd_info *mtd;
+
+               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+                       return;
+
+               printf("\ndevice %s%d <%s>, # parts = %d\n",
+                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
+                               dev->id->mtd_id, dev->num_parts);
+               printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
+
+               list_for_each(pentry, &dev->parts) {
+                       u32 net_size;
+                       char *size_note;
+
+                       part = list_entry(pentry, struct part_info, link);
+                       net_size = net_part_size(mtd, part);
+                       size_note = part->size == net_size ? " " : " (!)";
+                       printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
+                                       part_num, part->name, part->size,
+                                       net_size, size_note, part->offset,
+                                       part->mask_flags);
+#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
+               printf("\ndevice %s%d <%s>, # parts = %d\n",
+                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
+                               dev->id->mtd_id, dev->num_parts);
+               printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
+
+               list_for_each(pentry, &dev->parts) {
+                       part = list_entry(pentry, struct part_info, link);
+                       printf("%2d: %-20s0x%08llx\t0x%08llx\t%d\n",
+                                       part_num, part->name, part->size,
+                                       part->offset, part->mask_flags);
+#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
+                       part_num++;
+               }
+       }
+
+       if (list_empty(&devices))
+               printf("no partitions defined\n");
+}
+
+/**
+ * Format and print out a partition list for each device from global device
+ * list.
+ */
+static void list_partitions(void)
+{
+       struct part_info *part;
+
+       debug("\n---list_partitions---\n");
+       print_partition_table();
+
+       /* current_mtd_dev is not NULL only when we have non empty device list */
+       if (current_mtd_dev) {
+               part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
+               if (part) {
+                       printf("\nactive partition: %s%d,%d - (%s) 0x%08llx @ 0x%08llx\n",
+                                       MTD_DEV_TYPE(current_mtd_dev->id->type),
+                                       current_mtd_dev->id->num, current_mtd_partnum,
+                                       part->name, part->size, part->offset);
+               } else {
+                       printf("could not get current partition info\n\n");
+               }
+       }
+
+       printf("\ndefaults:\n");
+       printf("mtdids  : %s\n",
+               mtdids_default ? mtdids_default : "none");
+       /*
+        * Using printf() here results in printbuffer overflow
+        * if default mtdparts string is greater than console
+        * printbuffer. Use puts() to prevent system crashes.
+        */
+       puts("mtdparts: ");
+       puts(mtdparts_default ? mtdparts_default : "none");
+       puts("\n");
+}
+
+/**
+ * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
+ * corresponding device and verify partition number.
+ *
+ * @param id string describing device and partition or partition name
+ * @param dev pointer to the requested device (output)
+ * @param part_num verified partition number (output)
+ * @param part pointer to requested partition (output)
+ * @return 0 on success, 1 otherwise
+ */
+int find_dev_and_part(const char *id, struct mtd_device **dev,
+               u8 *part_num, struct part_info **part)
+{
+       struct list_head *dentry, *pentry;
+       u8 type, dnum, pnum;
+       const char *p;
+
+       debug("--- find_dev_and_part ---\nid = %s\n", id);
+
+       list_for_each(dentry, &devices) {
+               *part_num = 0;
+               *dev = list_entry(dentry, struct mtd_device, link);
+               list_for_each(pentry, &(*dev)->parts) {
+                       *part = list_entry(pentry, struct part_info, link);
+                       if (strcmp((*part)->name, id) == 0)
+                               return 0;
+                       (*part_num)++;
+               }
+       }
+
+       p = id;
+       *dev = NULL;
+       *part = NULL;
+       *part_num = 0;
+
+       if (mtd_id_parse(p, &p, &type, &dnum) != 0)
+               return 1;
+
+       if ((*p++ != ',') || (*p == '\0')) {
+               printf("no partition number specified\n");
+               return 1;
+       }
+       pnum = simple_strtoul(p, (char **)&p, 0);
+       if (*p != '\0') {
+               printf("unexpected trailing character '%c'\n", *p);
+               return 1;
+       }
+
+       if ((*dev = device_find(type, dnum)) == NULL) {
+               printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
+               return 1;
+       }
+
+       if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
+               printf("no such partition\n");
+               *dev = NULL;
+               return 1;
+       }
+
+       *part_num = pnum;
+
+       return 0;
+}
+
+/**
+ * Find and delete partition. For partition id format see find_dev_and_part().
+ *
+ * @param id string describing device and partition
+ * @return 0 on success, 1 otherwise
+ */
+static int delete_partition(const char *id)
+{
+       u8 pnum;
+       struct mtd_device *dev;
+       struct part_info *part;
+
+       if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
+
+               debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08llx@0x%08llx\n",
+                               MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
+                               part->name, part->size, part->offset);
+
+               if (part_del(dev, part) != 0)
+                       return 1;
+
+               if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
+                       printf("generated mtdparts too long, resetting to null\n");
+                       return 1;
+               }
+               return 0;
+       }
+
+       printf("partition %s not found\n", id);
+       return 1;
+}
+
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+/**
+ * Increase the size of the given partition so that it's net size is at least
+ * as large as the size member and such that the next partition would start on a
+ * good block if it were adjacent to this partition.
+ *
+ * @param mtd the mtd device
+ * @param part the partition
+ * @param next_offset pointer to the offset of the next partition after this
+ *                    partition's size has been modified (output)
+ */
+static void spread_partition(struct mtd_info *mtd, struct part_info *part,
+                            uint64_t *next_offset)
+{
+       uint64_t net_size, padding_size = 0;
+       int truncated;
+
+       mtd_get_len_incl_bad(mtd, part->offset, part->size, &net_size,
+                            &truncated);
+
+       /*
+        * Absorb bad blocks immediately following this
+        * partition also into the partition, such that
+        * the next partition starts with a good block.
+        */
+       if (!truncated) {
+               mtd_get_len_incl_bad(mtd, part->offset + net_size,
+                                    mtd->erasesize, &padding_size, &truncated);
+               if (truncated)
+                       padding_size = 0;
+               else
+                       padding_size -= mtd->erasesize;
+       }
+
+       if (truncated) {
+               printf("truncated partition %s to %lld bytes\n", part->name,
+                      (uint64_t) net_size + padding_size);
+       }
+
+       part->size = net_size + padding_size;
+       *next_offset = part->offset + part->size;
+}
+
+/**
+ * Adjust all of the partition sizes, such that all partitions are at least
+ * as big as their mtdparts environment variable sizes and they each start
+ * on a good block.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+static int spread_partitions(void)
+{
+       struct list_head *dentry, *pentry;
+       struct mtd_device *dev;
+       struct part_info *part;
+       struct mtd_info *mtd;
+       int part_num;
+       uint64_t cur_offs;
+
+       list_for_each(dentry, &devices) {
+               dev = list_entry(dentry, struct mtd_device, link);
+
+               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+                       return 1;
+
+               part_num = 0;
+               cur_offs = 0;
+               list_for_each(pentry, &dev->parts) {
+                       part = list_entry(pentry, struct part_info, link);
+
+                       debug("spread_partitions: device = %s%d, partition %d ="
+                               " (%s) 0x%08x@0x%08x\n",
+                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
+                               part_num, part->name, part->size,
+                               part->offset);
+
+                       if (cur_offs > part->offset)
+                               part->offset = cur_offs;
+
+                       spread_partition(mtd, part, &cur_offs);
+
+                       part_num++;
+               }
+       }
+
+       index_partitions();
+
+       if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
+               printf("generated mtdparts too long, resetting to null\n");
+               return 1;
+       }
+       return 0;
+}
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
+/**
+ * Accept character string describing mtd partitions and call device_parse()
+ * for each entry. Add created devices to the global devices list.
+ *
+ * @param mtdparts string specifing mtd partitions
+ * @return 0 on success, 1 otherwise
+ */
+static int parse_mtdparts(const char *const mtdparts)
+{
+       const char *p = mtdparts;
+       struct mtd_device *dev;
+       int err = 1;
+       char tmp_parts[MTDPARTS_MAXLEN];
+
+       debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
+
+       /* delete all devices and partitions */
+       if (mtd_devices_init() != 0) {
+               printf("could not initialise device list\n");
+               return err;
+       }
+
+       /* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
+       if (gd->flags & GD_FLG_ENV_READY) {
+               p = getenv("mtdparts");
+       } else {
+               p = tmp_parts;
+               getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+       }
+
+       if (strncmp(p, "mtdparts=", 9) != 0) {
+               printf("mtdparts variable doesn't start with 'mtdparts='\n");
+               return err;
+       }
+       p += 9;
+
+       while (p && (*p != '\0')) {
+               err = 1;
+               if ((device_parse(p, &p, &dev) != 0) || (!dev))
+                       break;
+
+               debug("+ device: %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
+                               dev->id->num, dev->id->mtd_id);
+
+               /* check if parsed device is already on the list */
+               if (device_find(dev->id->type, dev->id->num) != NULL) {
+                       printf("device %s%d redefined, please correct mtdparts variable\n",
+                                       MTD_DEV_TYPE(dev->id->type), dev->id->num);
+                       break;
+               }
+
+               list_add_tail(&dev->link, &devices);
+               err = 0;
+       }
+       if (err == 1) {
+               device_delall(&devices);
+               return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * Parse provided string describing mtdids mapping (see file header for mtdids
+ * variable format). Allocate memory for each entry and add all found entries
+ * to the global mtdids list.
+ *
+ * @param ids mapping string
+ * @return 0 on success, 1 otherwise
+ */
+static int parse_mtdids(const char *const ids)
+{
+       const char *p = ids;
+       const char *mtd_id;
+       int mtd_id_len;
+       struct mtdids *id;
+       struct list_head *entry, *n;
+       struct mtdids *id_tmp;
+       u8 type, num;
+       u64 size;
+       int ret = 1;
+
+       debug("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
+
+       /* clean global mtdids list */
+       list_for_each_safe(entry, n, &mtdids) {
+               id_tmp = list_entry(entry, struct mtdids, link);
+               debug("mtdids del: %d %d\n", id_tmp->type, id_tmp->num);
+               list_del(entry);
+               free(id_tmp);
+       }
+       last_ids[0] = '\0';
+       INIT_LIST_HEAD(&mtdids);
+
+       while(p && (*p != '\0')) {
+
+               ret = 1;
+               /* parse 'nor'|'nand'|'onenand'<dev-num> */
+               if (mtd_id_parse(p, &p, &type, &num) != 0)
+                       break;
+
+               if (*p != '=') {
+                       printf("mtdids: incorrect <dev-num>\n");
+                       break;
+               }
+               p++;
+
+               /* check if requested device exists */
+               if (mtd_device_validate(type, num, &size) != 0)
+                       return 1;
+
+               /* locate <mtd-id> */
+               mtd_id = p;
+               if ((p = strchr(mtd_id, ',')) != NULL) {
+                       mtd_id_len = p - mtd_id + 1;
+                       p++;
+               } else {
+                       mtd_id_len = strlen(mtd_id) + 1;
+               }
+               if (mtd_id_len == 0) {
+                       printf("mtdids: no <mtd-id> identifier\n");
+                       break;
+               }
+
+               /* check if this id is already on the list */
+               int double_entry = 0;
+               list_for_each(entry, &mtdids) {
+                       id_tmp = list_entry(entry, struct mtdids, link);
+                       if ((id_tmp->type == type) && (id_tmp->num == num)) {
+                               double_entry = 1;
+                               break;
+                       }
+               }
+               if (double_entry) {
+                       printf("device id %s%d redefined, please correct mtdids variable\n",
+                                       MTD_DEV_TYPE(type), num);
+                       break;
+               }
+
+               /* allocate mtdids structure */
+               if (!(id = (struct mtdids *)malloc(sizeof(struct mtdids) + mtd_id_len))) {
+                       printf("out of memory\n");
+                       break;
+               }
+               memset(id, 0, sizeof(struct mtdids) + mtd_id_len);
+               id->num = num;
+               id->type = type;
+               id->size = size;
+               id->mtd_id = (char *)(id + 1);
+               strncpy(id->mtd_id, mtd_id, mtd_id_len - 1);
+               id->mtd_id[mtd_id_len - 1] = '\0';
+               INIT_LIST_HEAD(&id->link);
+
+               debug("+ id %s%d\t%16lld bytes\t%s\n",
+                               MTD_DEV_TYPE(id->type), id->num,
+                               id->size, id->mtd_id);
+
+               list_add_tail(&id->link, &mtdids);
+               ret = 0;
+       }
+       if (ret == 1) {
+               /* clean mtdids list and free allocated memory */
+               list_for_each_safe(entry, n, &mtdids) {
+                       id_tmp = list_entry(entry, struct mtdids, link);
+                       list_del(entry);
+                       free(id_tmp);
+               }
+               return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * Parse and initialize global mtdids mapping and create global
+ * device/partition list.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+int mtdparts_init(void)
+{
+       static int initialized = 0;
+       const char *ids, *parts;
+       const char *current_partition;
+       int ids_changed;
+       char tmp_ep[PARTITION_MAXLEN];
+       char tmp_parts[MTDPARTS_MAXLEN];
+
+       debug("\n---mtdparts_init---\n");
+       if (!initialized) {
+               INIT_LIST_HEAD(&mtdids);
+               INIT_LIST_HEAD(&devices);
+               memset(last_ids, 0, MTDIDS_MAXLEN);
+               memset(last_parts, 0, MTDPARTS_MAXLEN);
+               memset(last_partition, 0, PARTITION_MAXLEN);
+               initialized = 1;
+       }
+
+       /* get variables */
+       ids = getenv("mtdids");
+       /*
+        * The mtdparts variable tends to be long. If we need to access it
+        * before the env is relocated, then we need to use our own stack
+        * buffer.  gd->env_buf will be too small.
+        */
+       if (gd->flags & GD_FLG_ENV_READY) {
+               parts = getenv("mtdparts");
+       } else {
+               parts = tmp_parts;
+               getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+       }
+       current_partition = getenv("partition");
+
+       /* save it for later parsing, cannot rely on current partition pointer
+        * as 'partition' variable may be updated during init */
+       tmp_ep[0] = '\0';
+       if (current_partition)
+               strncpy(tmp_ep, current_partition, PARTITION_MAXLEN);
+
+       debug("last_ids  : %s\n", last_ids);
+       debug("env_ids   : %s\n", ids);
+       debug("last_parts: %s\n", last_parts);
+       debug("env_parts : %s\n\n", parts);
+
+       debug("last_partition : %s\n", last_partition);
+       debug("env_partition  : %s\n", current_partition);
+
+       /* if mtdids varible is empty try to use defaults */
+       if (!ids) {
+               if (mtdids_default) {
+                       debug("mtdids variable not defined, using default\n");
+                       ids = mtdids_default;
+                       setenv("mtdids", (char *)ids);
+               } else {
+                       printf("mtdids not defined, no default present\n");
+                       return 1;
+               }
+       }
+       if (strlen(ids) > MTDIDS_MAXLEN - 1) {
+               printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
+               return 1;
+       }
+
+       /* do no try to use defaults when mtdparts variable is not defined,
+        * just check the length */
+       if (!parts)
+               printf("mtdparts variable not set, see 'help mtdparts'\n");
+
+       if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
+               printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
+               return 1;
+       }
+
+       /* check if we have already parsed those mtdids */
+       if ((last_ids[0] != '\0') && (strcmp(last_ids, ids) == 0)) {
+               ids_changed = 0;
+       } else {
+               ids_changed = 1;
+
+               if (parse_mtdids(ids) != 0) {
+                       mtd_devices_init();
+                       return 1;
+               }
+
+               /* ok it's good, save new ids */
+               strncpy(last_ids, ids, MTDIDS_MAXLEN);
+       }
+
+       /* parse partitions if either mtdparts or mtdids were updated */
+       if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
+               if (parse_mtdparts(parts) != 0)
+                       return 1;
+
+               if (list_empty(&devices)) {
+                       printf("mtdparts_init: no valid partitions\n");
+                       return 1;
+               }
+
+               /* ok it's good, save new parts */
+               strncpy(last_parts, parts, MTDPARTS_MAXLEN);
+
+               /* reset first partition from first dev from the list as current */
+               current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
+               current_mtd_partnum = 0;
+               current_save();
+
+               debug("mtdparts_init: current_mtd_dev  = %s%d, current_mtd_partnum = %d\n",
+                               MTD_DEV_TYPE(current_mtd_dev->id->type),
+                               current_mtd_dev->id->num, current_mtd_partnum);
+       }
+
+       /* mtdparts variable was reset to NULL, delete all devices/partitions */
+       if (!parts && (last_parts[0] != '\0'))
+               return mtd_devices_init();
+
+       /* do not process current partition if mtdparts variable is null */
+       if (!parts)
+               return 0;
+
+       /* is current partition set in environment? if so, use it */
+       if ((tmp_ep[0] != '\0') && (strcmp(tmp_ep, last_partition) != 0)) {
+               struct part_info *p;
+               struct mtd_device *cdev;
+               u8 pnum;
+
+               debug("--- getting current partition: %s\n", tmp_ep);
+
+               if (find_dev_and_part(tmp_ep, &cdev, &pnum, &p) == 0) {
+                       current_mtd_dev = cdev;
+                       current_mtd_partnum = pnum;
+                       current_save();
+               }
+       } else if (getenv("partition") == NULL) {
+               debug("no partition variable set, setting...\n");
+               current_save();
+       }
+
+       return 0;
+}
+
+/**
+ * Return pointer to the partition of a requested number from a requested
+ * device.
+ *
+ * @param dev device that is to be searched for a partition
+ * @param part_num requested partition number
+ * @return pointer to the part_info, NULL otherwise
+ */
+static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num)
+{
+       struct list_head *entry;
+       struct part_info *part;
+       int num;
+
+       if (!dev)
+               return NULL;
+
+       debug("\n--- mtd_part_info: partition number %d for device %s%d (%s)\n",
+                       part_num, MTD_DEV_TYPE(dev->id->type),
+                       dev->id->num, dev->id->mtd_id);
+
+       if (part_num >= dev->num_parts) {
+               printf("invalid partition number %d for device %s%d (%s)\n",
+                               part_num, MTD_DEV_TYPE(dev->id->type),
+                               dev->id->num, dev->id->mtd_id);
+               return NULL;
+       }
+
+       /* locate partition number, return it */
+       num = 0;
+       list_for_each(entry, &dev->parts) {
+               part = list_entry(entry, struct part_info, link);
+
+               if (part_num == num++) {
+                       return part;
+               }
+       }
+
+       return NULL;
+}
+
+/***************************************************/
+/* U-boot commands                                */
+/***************************************************/
+/* command line only */
+/**
+ * Routine implementing u-boot chpart command. Sets new current partition based
+ * on the user supplied partition id. For partition id format see find_dev_and_part().
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+static int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+/* command line only */
+       struct mtd_device *dev;
+       struct part_info *part;
+       u8 pnum;
+
+       if (mtdparts_init() !=0)
+               return 1;
+
+       if (argc < 2) {
+               printf("no partition id specified\n");
+               return 1;
+       }
+
+       if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
+               return 1;
+
+       current_mtd_dev = dev;
+       current_mtd_partnum = pnum;
+       current_save();
+
+       printf("partition changed to %s%d,%d\n",
+                       MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum);
+
+       return 0;
+}
+
+/**
+ * Routine implementing u-boot mtdparts command. Initialize/update default global
+ * partition list and process user partition request (list, add, del).
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       if (argc == 2) {
+               if (strcmp(argv[1], "default") == 0) {
+                       setenv("mtdids", (char *)mtdids_default);
+                       setenv("mtdparts", (char *)mtdparts_default);
+                       setenv("partition", NULL);
+
+                       mtdparts_init();
+                       return 0;
+               } else if (strcmp(argv[1], "delall") == 0) {
+                       /* this may be the first run, initialize lists if needed */
+                       mtdparts_init();
+
+                       setenv("mtdparts", NULL);
+
+                       /* mtd_devices_init() calls current_save() */
+                       return mtd_devices_init();
+               }
+       }
+
+       /* make sure we are in sync with env variables */
+       if (mtdparts_init() != 0)
+               return 1;
+
+       if (argc == 1) {
+               list_partitions();
+               return 0;
+       }
+
+       /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
+       if (((argc == 5) || (argc == 6)) && (strncmp(argv[1], "add", 3) == 0)) {
+#define PART_ADD_DESC_MAXLEN 64
+               char tmpbuf[PART_ADD_DESC_MAXLEN];
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+               struct mtd_info *mtd;
+               uint64_t next_offset;
+#endif
+               u8 type, num, len;
+               struct mtd_device *dev;
+               struct mtd_device *dev_tmp;
+               struct mtdids *id;
+               struct part_info *p;
+
+               if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
+                       return 1;
+
+               if ((id = id_find(type, num)) == NULL) {
+                       printf("no such device %s defined in mtdids variable\n", argv[2]);
+                       return 1;
+               }
+
+               len = strlen(id->mtd_id) + 1;   /* 'mtd_id:' */
+               len += strlen(argv[3]);         /* size@offset */
+               len += strlen(argv[4]) + 2;     /* '(' name ')' */
+               if (argv[5] && (strlen(argv[5]) == 2))
+                       len += 2;               /* 'ro' */
+
+               if (len >= PART_ADD_DESC_MAXLEN) {
+                       printf("too long partition description\n");
+                       return 1;
+               }
+               sprintf(tmpbuf, "%s:%s(%s)%s",
+                               id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
+               debug("add tmpbuf: %s\n", tmpbuf);
+
+               if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
+                       return 1;
+
+               debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
+                               dev->id->num, dev->id->mtd_id);
+
+               p = list_entry(dev->parts.next, struct part_info, link);
+
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+                       return 1;
+
+               if (!strcmp(&argv[1][3], ".spread")) {
+                       spread_partition(mtd, p, &next_offset);
+                       debug("increased %s to %d bytes\n", p->name, p->size);
+               }
+#endif
+
+               dev_tmp = device_find(dev->id->type, dev->id->num);
+               if (dev_tmp == NULL) {
+                       device_add(dev);
+               } else if (part_add(dev_tmp, p) != 0) {
+                       /* merge new partition with existing ones*/
+                       device_del(dev);
+                       return 1;
+               }
+
+               if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
+                       printf("generated mtdparts too long, resetting to null\n");
+                       return 1;
+               }
+
+               return 0;
+       }
+
+       /* mtdparts del part-id */
+       if ((argc == 3) && (strcmp(argv[1], "del") == 0)) {
+               debug("del: part-id = %s\n", argv[2]);
+
+               return delete_partition(argv[2]);
+       }
+
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+       if ((argc == 2) && (strcmp(argv[1], "spread") == 0))
+               return spread_partitions();
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
+       return CMD_RET_USAGE;
+}
+
+/***************************************************/
+U_BOOT_CMD(
+       chpart, 2,      0,      do_chpart,
+       "change active partition",
+       "part-id\n"
+       "    - change active partition (e.g. part-id = nand0,1)"
+);
+
+#ifdef CONFIG_SYS_LONGHELP
+static char mtdparts_help_text[] =
+       "\n"
+       "    - list partition table\n"
+       "mtdparts delall\n"
+       "    - delete all partitions\n"
+       "mtdparts del part-id\n"
+       "    - delete partition (e.g. part-id = nand0,1)\n"
+       "mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
+       "    - add partition\n"
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+       "mtdparts add.spread <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
+       "    - add partition, padding size by skipping bad blocks\n"
+#endif
+       "mtdparts default\n"
+       "    - reset partition table to defaults\n"
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+       "mtdparts spread\n"
+       "    - adjust the sizes of the partitions so they are\n"
+       "      at least as big as the mtdparts variable specifies\n"
+       "      and they each start on a good block\n\n"
+#else
+       "\n"
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+       "-----\n\n"
+       "this command uses three environment variables:\n\n"
+       "'partition' - keeps current partition identifier\n\n"
+       "partition  := <part-id>\n"
+       "<part-id>  := <dev-id>,part_num\n\n"
+       "'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
+       "mtdids=<idmap>[,<idmap>,...]\n\n"
+       "<idmap>    := <dev-id>=<mtd-id>\n"
+       "<dev-id>   := 'nand'|'nor'|'onenand'<dev-num>\n"
+       "<dev-num>  := mtd device number, 0...\n"
+       "<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n"
+       "'mtdparts' - partition list\n\n"
+       "mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]\n\n"
+       "<mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]\n"
+       "<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)\n"
+       "<part-def> := <size>[@<offset>][<name>][<ro-flag>]\n"
+       "<size>     := standard linux memsize OR '-' to denote all remaining space\n"
+       "<offset>   := partition start offset within the device\n"
+       "<name>     := '(' NAME ')'\n"
+       "<ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)";
+#endif
+
+U_BOOT_CMD(
+       mtdparts,       6,      0,      do_mtdparts,
+       "define flash/nand partitions", mtdparts_help_text
+);
+/***************************************************/
diff --git a/cmd/nand.c b/cmd/nand.c
new file mode 100644 (file)
index 0000000..a6b67e2
--- /dev/null
@@ -0,0 +1,973 @@
+/*
+ * Driver for NAND support, Rick Bronson
+ * borrowed heavily from:
+ * (c) 1999 Machine Vision Holdings, Inc.
+ * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
+ *
+ * Ported 'dynenv' to 'nand env.oob' command
+ * (C) 2010 Nanometrics, Inc.
+ * 'dynenv' -- Dynamic environment offset in NAND OOB
+ * (C) Copyright 2006-2007 OpenMoko, Inc.
+ * Added 16-bit nand support
+ * (C) 2004 Texas Instruments
+ *
+ * Copyright 2010, 2012 Freescale Semiconductor
+ * The portions of this file whose copyright is held by Freescale and which
+ * are not considered a derived work of GPL v2-only code may be distributed
+ * and/or modified under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ */
+
+#include <common.h>
+#include <linux/mtd/mtd.h>
+#include <command.h>
+#include <console.h>
+#include <watchdog.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <jffs2/jffs2.h>
+#include <nand.h>
+
+#if defined(CONFIG_CMD_MTDPARTS)
+
+/* partition handling routines */
+int mtdparts_init(void);
+int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
+int find_dev_and_part(const char *id, struct mtd_device **dev,
+                     u8 *part_num, struct part_info **part);
+#endif
+
+static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
+{
+       int i;
+       u_char *datbuf, *oobbuf, *p;
+       static loff_t last;
+       int ret = 0;
+
+       if (repeat)
+               off = last + nand->writesize;
+
+       last = off;
+
+       datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize);
+       if (!datbuf) {
+               puts("No memory for page buffer\n");
+               return 1;
+       }
+
+       oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize);
+       if (!oobbuf) {
+               puts("No memory for page buffer\n");
+               ret = 1;
+               goto free_dat;
+       }
+       off &= ~(nand->writesize - 1);
+       loff_t addr = (loff_t) off;
+       struct mtd_oob_ops ops;
+       memset(&ops, 0, sizeof(ops));
+       ops.datbuf = datbuf;
+       ops.oobbuf = oobbuf;
+       ops.len = nand->writesize;
+       ops.ooblen = nand->oobsize;
+       ops.mode = MTD_OPS_RAW;
+       i = mtd_read_oob(nand, addr, &ops);
+       if (i < 0) {
+               printf("Error (%d) reading page %08lx\n", i, off);
+               ret = 1;
+               goto free_all;
+       }
+       printf("Page %08lx dump:\n", off);
+
+       if (!only_oob) {
+               i = nand->writesize >> 4;
+               p = datbuf;
+
+               while (i--) {
+                       printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
+                              "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                              p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
+                              p[8], p[9], p[10], p[11], p[12], p[13], p[14],
+                              p[15]);
+                       p += 16;
+               }
+       }
+
+       puts("OOB:\n");
+       i = nand->oobsize >> 3;
+       p = oobbuf;
+       while (i--) {
+               printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
+                      p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+               p += 8;
+       }
+
+free_all:
+       free(oobbuf);
+free_dat:
+       free(datbuf);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------- */
+
+static int set_dev(int dev)
+{
+       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+           !nand_info[dev].name) {
+               puts("No such device\n");
+               return -1;
+       }
+
+       if (nand_curr_device == dev)
+               return 0;
+
+       printf("Device %d: %s", dev, nand_info[dev].name);
+       puts("... is now current device\n");
+       nand_curr_device = dev;
+
+#ifdef CONFIG_SYS_NAND_SELECT_DEVICE
+       board_nand_select_device(nand_info[dev].priv, dev);
+#endif
+
+       return 0;
+}
+
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
+static void print_status(ulong start, ulong end, ulong erasesize, int status)
+{
+       /*
+        * Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is
+        * not the same as others.  Instead of bit 1 being lock, it is
+        * #lock_tight. To make the driver support either format, ignore bit 1
+        * and use only bit 0 and bit 2.
+        */
+       printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
+               start,
+               end - 1,
+               (end - start) / erasesize,
+               ((status & NAND_LOCK_STATUS_TIGHT) ?  "TIGHT " : ""),
+               (!(status & NAND_LOCK_STATUS_UNLOCK) ?  "LOCK " : ""),
+               ((status & NAND_LOCK_STATUS_UNLOCK) ?  "UNLOCK " : ""));
+}
+
+static void do_nand_status(nand_info_t *nand)
+{
+       ulong block_start = 0;
+       ulong off;
+       int last_status = -1;
+
+       struct nand_chip *nand_chip = nand->priv;
+       /* check the WP bit */
+       nand_chip->cmdfunc(nand, NAND_CMD_STATUS, -1, -1);
+       printf("device is %swrite protected\n",
+               (nand_chip->read_byte(nand) & 0x80 ?
+               "NOT " : ""));
+
+       for (off = 0; off < nand->size; off += nand->erasesize) {
+               int s = nand_get_lock_status(nand, off);
+
+               /* print message only if status has changed */
+               if (s != last_status && off != 0) {
+                       print_status(block_start, off, nand->erasesize,
+                                       last_status);
+                       block_start = off;
+               }
+               last_status = s;
+       }
+       /* Print the last block info */
+       print_status(block_start, off, nand->erasesize, last_status);
+}
+#endif
+
+#ifdef CONFIG_ENV_OFFSET_OOB
+unsigned long nand_env_oob_offset;
+
+int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
+{
+       int ret;
+       uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
+       nand_info_t *nand = &nand_info[0];
+       char *cmd = argv[1];
+
+       if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) {
+               puts("no devices available\n");
+               return 1;
+       }
+
+       set_dev(0);
+
+       if (!strcmp(cmd, "get")) {
+               ret = get_nand_env_oob(nand, &nand_env_oob_offset);
+               if (ret)
+                       return 1;
+
+               printf("0x%08lx\n", nand_env_oob_offset);
+       } else if (!strcmp(cmd, "set")) {
+               loff_t addr;
+               loff_t maxsize;
+               struct mtd_oob_ops ops;
+               int idx = 0;
+
+               if (argc < 3)
+                       goto usage;
+
+               /* We don't care about size, or maxsize. */
+               if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
+                               MTD_DEV_TYPE_NAND, nand_info[idx].size)) {
+                       puts("Offset or partition name expected\n");
+                       return 1;
+               }
+               if (set_dev(idx)) {
+                       puts("Offset or partition name expected\n");
+                       return 1;
+               }
+
+               if (idx != 0) {
+                       puts("Partition not on first NAND device\n");
+                       return 1;
+               }
+
+               if (nand->oobavail < ENV_OFFSET_SIZE) {
+                       printf("Insufficient available OOB bytes:\n"
+                              "%d OOB bytes available but %d required for "
+                              "env.oob support\n",
+                              nand->oobavail, ENV_OFFSET_SIZE);
+                       return 1;
+               }
+
+               if ((addr & (nand->erasesize - 1)) != 0) {
+                       printf("Environment offset must be block-aligned\n");
+                       return 1;
+               }
+
+               ops.datbuf = NULL;
+               ops.mode = MTD_OOB_AUTO;
+               ops.ooboffs = 0;
+               ops.ooblen = ENV_OFFSET_SIZE;
+               ops.oobbuf = (void *) oob_buf;
+
+               oob_buf[0] = ENV_OOB_MARKER;
+               oob_buf[1] = addr / nand->erasesize;
+
+               ret = nand->write_oob(nand, ENV_OFFSET_SIZE, &ops);
+               if (ret) {
+                       printf("Error writing OOB block 0\n");
+                       return ret;
+               }
+
+               ret = get_nand_env_oob(nand, &nand_env_oob_offset);
+               if (ret) {
+                       printf("Error reading env offset in OOB\n");
+                       return ret;
+               }
+
+               if (addr != nand_env_oob_offset) {
+                       printf("Verification of env offset in OOB failed: "
+                              "0x%08llx expected but got 0x%08lx\n",
+                              (unsigned long long)addr, nand_env_oob_offset);
+                       return 1;
+               }
+       } else {
+               goto usage;
+       }
+
+       return ret;
+
+usage:
+       return CMD_RET_USAGE;
+}
+
+#endif
+
+static void nand_print_and_set_info(int idx)
+{
+       nand_info_t *nand = &nand_info[idx];
+       struct nand_chip *chip = nand->priv;
+
+       printf("Device %d: ", idx);
+       if (chip->numchips > 1)
+               printf("%dx ", chip->numchips);
+       printf("%s, sector size %u KiB\n",
+              nand->name, nand->erasesize >> 10);
+       printf("  Page size   %8d b\n", nand->writesize);
+       printf("  OOB size    %8d b\n", nand->oobsize);
+       printf("  Erase size  %8d b\n", nand->erasesize);
+       printf("  subpagesize %8d b\n", chip->subpagesize);
+       printf("  options     0x%8x\n", chip->options);
+       printf("  bbt options 0x%8x\n", chip->bbt_options);
+
+       /* Set geometry info */
+       setenv_hex("nand_writesize", nand->writesize);
+       setenv_hex("nand_oobsize", nand->oobsize);
+       setenv_hex("nand_erasesize", nand->erasesize);
+}
+
+static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
+                       int read)
+{
+       int ret = 0;
+
+       while (count--) {
+               /* Raw access */
+               mtd_oob_ops_t ops = {
+                       .datbuf = (u8 *)addr,
+                       .oobbuf = ((u8 *)addr) + nand->writesize,
+                       .len = nand->writesize,
+                       .ooblen = nand->oobsize,
+                       .mode = MTD_OPS_RAW
+               };
+
+               if (read) {
+                       ret = mtd_read_oob(nand, off, &ops);
+               } else {
+                       ret = mtd_write_oob(nand, off, &ops);
+                       if (!ret)
+                               ret = nand_verify_page_oob(nand, &ops, off);
+               }
+
+               if (ret) {
+                       printf("%s: error at offset %llx, ret %d\n",
+                               __func__, (long long)off, ret);
+                       break;
+               }
+
+               addr += nand->writesize + nand->oobsize;
+               off += nand->writesize;
+       }
+
+       return ret;
+}
+
+/* Adjust a chip/partition size down for bad blocks so we don't
+ * read/write past the end of a chip/partition by accident.
+ */
+static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
+{
+       /* We grab the nand info object here fresh because this is usually
+        * called after arg_off_size() which can change the value of dev.
+        */
+       nand_info_t *nand = &nand_info[dev];
+       loff_t maxoffset = offset + *size;
+       int badblocks = 0;
+
+       /* count badblocks in NAND from offset to offset + size */
+       for (; offset < maxoffset; offset += nand->erasesize) {
+               if (nand_block_isbad(nand, offset))
+                       badblocks++;
+       }
+       /* adjust size if any bad blocks found */
+       if (badblocks) {
+               *size -= badblocks * nand->erasesize;
+               printf("size adjusted to 0x%llx (%d bad blocks)\n",
+                      (unsigned long long)*size, badblocks);
+       }
+}
+
+static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int i, ret = 0;
+       ulong addr;
+       loff_t off, size, maxsize;
+       char *cmd, *s;
+       nand_info_t *nand;
+#ifdef CONFIG_SYS_NAND_QUIET
+       int quiet = CONFIG_SYS_NAND_QUIET;
+#else
+       int quiet = 0;
+#endif
+       const char *quiet_str = getenv("quiet");
+       int dev = nand_curr_device;
+       int repeat = flag & CMD_FLAG_REPEAT;
+
+       /* at least two arguments please */
+       if (argc < 2)
+               goto usage;
+
+       if (quiet_str)
+               quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
+
+       cmd = argv[1];
+
+       /* Only "dump" is repeatable. */
+       if (repeat && strcmp(cmd, "dump"))
+               return 0;
+
+       if (strcmp(cmd, "info") == 0) {
+
+               putc('\n');
+               for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
+                       if (nand_info[i].name)
+                               nand_print_and_set_info(i);
+               }
+               return 0;
+       }
+
+       if (strcmp(cmd, "device") == 0) {
+               if (argc < 3) {
+                       putc('\n');
+                       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE)
+                               puts("no devices available\n");
+                       else
+                               nand_print_and_set_info(dev);
+                       return 0;
+               }
+
+               dev = (int)simple_strtoul(argv[2], NULL, 10);
+               set_dev(dev);
+
+               return 0;
+       }
+
+#ifdef CONFIG_ENV_OFFSET_OOB
+       /* this command operates only on the first nand device */
+       if (strcmp(cmd, "env.oob") == 0)
+               return do_nand_env_oob(cmdtp, argc - 1, argv + 1);
+#endif
+
+       /* The following commands operate on the current device, unless
+        * overridden by a partition specifier.  Note that if somehow the
+        * current device is invalid, it will have to be changed to a valid
+        * one before these commands can run, even if a partition specifier
+        * for another device is to be used.
+        */
+       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+           !nand_info[dev].name) {
+               puts("\nno devices available\n");
+               return 1;
+       }
+       nand = &nand_info[dev];
+
+       if (strcmp(cmd, "bad") == 0) {
+               printf("\nDevice %d bad blocks:\n", dev);
+               for (off = 0; off < nand->size; off += nand->erasesize)
+                       if (nand_block_isbad(nand, off))
+                               printf("  %08llx\n", (unsigned long long)off);
+               return 0;
+       }
+
+       /*
+        * Syntax is:
+        *   0    1     2       3    4
+        *   nand erase [clean] [off size]
+        */
+       if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) {
+               nand_erase_options_t opts;
+               /* "clean" at index 2 means request to write cleanmarker */
+               int clean = argc > 2 && !strcmp("clean", argv[2]);
+               int scrub_yes = argc > 2 && !strcmp("-y", argv[2]);
+               int o = (clean || scrub_yes) ? 3 : 2;
+               int scrub = !strncmp(cmd, "scrub", 5);
+               int spread = 0;
+               int args = 2;
+               const char *scrub_warn =
+                       "Warning: "
+                       "scrub option will erase all factory set bad blocks!\n"
+                       "         "
+                       "There is no reliable way to recover them.\n"
+                       "         "
+                       "Use this command only for testing purposes if you\n"
+                       "         "
+                       "are sure of what you are doing!\n"
+                       "\nReally scrub this NAND flash? <y/N>\n";
+
+               if (cmd[5] != 0) {
+                       if (!strcmp(&cmd[5], ".spread")) {
+                               spread = 1;
+                       } else if (!strcmp(&cmd[5], ".part")) {
+                               args = 1;
+                       } else if (!strcmp(&cmd[5], ".chip")) {
+                               args = 0;
+                       } else {
+                               goto usage;
+                       }
+               }
+
+               /*
+                * Don't allow missing arguments to cause full chip/partition
+                * erases -- easy to do accidentally, e.g. with a misspelled
+                * variable name.
+                */
+               if (argc != o + args)
+                       goto usage;
+
+               printf("\nNAND %s: ", cmd);
+               /* skip first two or three arguments, look for offset and size */
+               if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
+                                    &maxsize, MTD_DEV_TYPE_NAND,
+                                    nand_info[dev].size) != 0)
+                       return 1;
+
+               if (set_dev(dev))
+                       return 1;
+
+               nand = &nand_info[dev];
+
+               memset(&opts, 0, sizeof(opts));
+               opts.offset = off;
+               opts.length = size;
+               opts.jffs2  = clean;
+               opts.quiet  = quiet;
+               opts.spread = spread;
+
+               if (scrub) {
+                       if (scrub_yes) {
+                               opts.scrub = 1;
+                       } else {
+                               puts(scrub_warn);
+                               if (confirm_yesno()) {
+                                       opts.scrub = 1;
+                               } else {
+                                       puts("scrub aborted\n");
+                                       return 1;
+                               }
+                       }
+               }
+               ret = nand_erase_opts(nand, &opts);
+               printf("%s\n", ret ? "ERROR" : "OK");
+
+               return ret == 0 ? 0 : 1;
+       }
+
+       if (strncmp(cmd, "dump", 4) == 0) {
+               if (argc < 3)
+                       goto usage;
+
+               off = (int)simple_strtoul(argv[2], NULL, 16);
+               ret = nand_dump(nand, off, !strcmp(&cmd[4], ".oob"), repeat);
+
+               return ret == 0 ? 1 : 0;
+       }
+
+       if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
+               size_t rwsize;
+               ulong pagecount = 1;
+               int read;
+               int raw = 0;
+
+               if (argc < 4)
+                       goto usage;
+
+               addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+
+               read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
+               printf("\nNAND %s: ", read ? "read" : "write");
+
+               s = strchr(cmd, '.');
+
+               if (s && !strcmp(s, ".raw")) {
+                       raw = 1;
+
+                       if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
+                                       MTD_DEV_TYPE_NAND,
+                                       nand_info[dev].size))
+                               return 1;
+
+                       if (set_dev(dev))
+                               return 1;
+
+                       nand = &nand_info[dev];
+
+                       if (argc > 4 && !str2long(argv[4], &pagecount)) {
+                               printf("'%s' is not a number\n", argv[4]);
+                               return 1;
+                       }
+
+                       if (pagecount * nand->writesize > size) {
+                               puts("Size exceeds partition or device limit\n");
+                               return -1;
+                       }
+
+                       rwsize = pagecount * (nand->writesize + nand->oobsize);
+               } else {
+                       if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
+                                            &size, &maxsize,
+                                            MTD_DEV_TYPE_NAND,
+                                            nand_info[dev].size) != 0)
+                               return 1;
+
+                       if (set_dev(dev))
+                               return 1;
+
+                       /* size is unspecified */
+                       if (argc < 5)
+                               adjust_size_for_badblocks(&size, off, dev);
+                       rwsize = size;
+               }
+
+               nand = &nand_info[dev];
+
+               if (!s || !strcmp(s, ".jffs2") ||
+                   !strcmp(s, ".e") || !strcmp(s, ".i")) {
+                       if (read)
+                               ret = nand_read_skip_bad(nand, off, &rwsize,
+                                                        NULL, maxsize,
+                                                        (u_char *)addr);
+                       else
+                               ret = nand_write_skip_bad(nand, off, &rwsize,
+                                                         NULL, maxsize,
+                                                         (u_char *)addr,
+                                                         WITH_WR_VERIFY);
+#ifdef CONFIG_CMD_NAND_TRIMFFS
+               } else if (!strcmp(s, ".trimffs")) {
+                       if (read) {
+                               printf("Unknown nand command suffix '%s'\n", s);
+                               return 1;
+                       }
+                       ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
+                                               maxsize, (u_char *)addr,
+                                               WITH_DROP_FFS | WITH_WR_VERIFY);
+#endif
+               } else if (!strcmp(s, ".oob")) {
+                       /* out-of-band data */
+                       mtd_oob_ops_t ops = {
+                               .oobbuf = (u8 *)addr,
+                               .ooblen = rwsize,
+                               .mode = MTD_OPS_RAW
+                       };
+
+                       if (read)
+                               ret = mtd_read_oob(nand, off, &ops);
+                       else
+                               ret = mtd_write_oob(nand, off, &ops);
+               } else if (raw) {
+                       ret = raw_access(nand, addr, off, pagecount, read);
+               } else {
+                       printf("Unknown nand command suffix '%s'.\n", s);
+                       return 1;
+               }
+
+               printf(" %zu bytes %s: %s\n", rwsize,
+                      read ? "read" : "written", ret ? "ERROR" : "OK");
+
+               return ret == 0 ? 0 : 1;
+       }
+
+#ifdef CONFIG_CMD_NAND_TORTURE
+       if (strcmp(cmd, "torture") == 0) {
+               if (argc < 3)
+                       goto usage;
+
+               if (!str2off(argv[2], &off)) {
+                       puts("Offset is not a valid number\n");
+                       return 1;
+               }
+
+               printf("\nNAND torture: device %d offset 0x%llx size 0x%x\n",
+                       dev, off, nand->erasesize);
+               ret = nand_torture(nand, off);
+               printf(" %s\n", ret ? "Failed" : "Passed");
+
+               return ret == 0 ? 0 : 1;
+       }
+#endif
+
+       if (strcmp(cmd, "markbad") == 0) {
+               argc -= 2;
+               argv += 2;
+
+               if (argc <= 0)
+                       goto usage;
+
+               while (argc > 0) {
+                       addr = simple_strtoul(*argv, NULL, 16);
+
+                       if (mtd_block_markbad(nand, addr)) {
+                               printf("block 0x%08lx NOT marked "
+                                       "as bad! ERROR %d\n",
+                                       addr, ret);
+                               ret = 1;
+                       } else {
+                               printf("block 0x%08lx successfully "
+                                       "marked as bad\n",
+                                       addr);
+                       }
+                       --argc;
+                       ++argv;
+               }
+               return ret;
+       }
+
+       if (strcmp(cmd, "biterr") == 0) {
+               /* todo */
+               return 1;
+       }
+
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
+       if (strcmp(cmd, "lock") == 0) {
+               int tight = 0;
+               int status = 0;
+               if (argc == 3) {
+                       if (!strcmp("tight", argv[2]))
+                               tight = 1;
+                       if (!strcmp("status", argv[2]))
+                               status = 1;
+               }
+               if (status) {
+                       do_nand_status(nand);
+               } else {
+                       if (!nand_lock(nand, tight)) {
+                               puts("NAND flash successfully locked\n");
+                       } else {
+                               puts("Error locking NAND flash\n");
+                               return 1;
+                       }
+               }
+               return 0;
+       }
+
+       if (strncmp(cmd, "unlock", 5) == 0) {
+               int allexcept = 0;
+
+               s = strchr(cmd, '.');
+
+               if (s && !strcmp(s, ".allexcept"))
+                       allexcept = 1;
+
+               if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
+                                    &maxsize, MTD_DEV_TYPE_NAND,
+                                    nand_info[dev].size) < 0)
+                       return 1;
+
+               if (set_dev(dev))
+                       return 1;
+
+               if (!nand_unlock(&nand_info[dev], off, size, allexcept)) {
+                       puts("NAND flash successfully unlocked\n");
+               } else {
+                       puts("Error unlocking NAND flash, "
+                            "write and erase will probably fail\n");
+                       return 1;
+               }
+               return 0;
+       }
+#endif
+
+usage:
+       return CMD_RET_USAGE;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char nand_help_text[] =
+       "info - show available NAND devices\n"
+       "nand device [dev] - show or set current device\n"
+       "nand read - addr off|partition size\n"
+       "nand write - addr off|partition size\n"
+       "    read/write 'size' bytes starting at offset 'off'\n"
+       "    to/from memory address 'addr', skipping bad blocks.\n"
+       "nand read.raw - addr off|partition [count]\n"
+       "nand write.raw - addr off|partition [count]\n"
+       "    Use read.raw/write.raw to avoid ECC and access the flash as-is.\n"
+#ifdef CONFIG_CMD_NAND_TRIMFFS
+       "nand write.trimffs - addr off|partition size\n"
+       "    write 'size' bytes starting at offset 'off' from memory address\n"
+       "    'addr', skipping bad blocks and dropping any pages at the end\n"
+       "    of eraseblocks that contain only 0xFF\n"
+#endif
+       "nand erase[.spread] [clean] off size - erase 'size' bytes "
+       "from offset 'off'\n"
+       "    With '.spread', erase enough for given file size, otherwise,\n"
+       "    'size' includes skipped bad blocks.\n"
+       "nand erase.part [clean] partition - erase entire mtd partition'\n"
+       "nand erase.chip [clean] - erase entire chip'\n"
+       "nand bad - show bad blocks\n"
+       "nand dump[.oob] off - dump page\n"
+#ifdef CONFIG_CMD_NAND_TORTURE
+       "nand torture off - torture block at offset\n"
+#endif
+       "nand scrub [-y] off size | scrub.part partition | scrub.chip\n"
+       "    really clean NAND erasing bad blocks (UNSAFE)\n"
+       "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
+       "nand biterr off - make a bit error at offset (UNSAFE)"
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
+       "\n"
+       "nand lock [tight] [status]\n"
+       "    bring nand to lock state or display locked pages\n"
+       "nand unlock[.allexcept] [offset] [size] - unlock section"
+#endif
+#ifdef CONFIG_ENV_OFFSET_OOB
+       "\n"
+       "nand env.oob - environment offset in OOB of block 0 of"
+       "    first device.\n"
+       "nand env.oob set off|partition - set enviromnent offset\n"
+       "nand env.oob get - get environment offset"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       nand, CONFIG_SYS_MAXARGS, 1, do_nand,
+       "NAND sub-system", nand_help_text
+);
+
+static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
+                          ulong offset, ulong addr, char *cmd)
+{
+       int r;
+       char *s;
+       size_t cnt;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       image_header_t *hdr;
+#endif
+#if defined(CONFIG_FIT)
+       const void *fit_hdr = NULL;
+#endif
+
+       s = strchr(cmd, '.');
+       if (s != NULL &&
+           (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) {
+               printf("Unknown nand load suffix '%s'\n", s);
+               bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
+               return 1;
+       }
+
+       printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
+
+       cnt = nand->writesize;
+       r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
+                       (u_char *)addr);
+       if (r) {
+               puts("** Read error\n");
+               bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ);
+
+       switch (genimg_get_format ((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+               hdr = (image_header_t *)addr;
+
+               bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
+               image_print_contents (hdr);
+
+               cnt = image_get_image_size (hdr);
+               break;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               fit_hdr = (const void *)addr;
+               puts ("Fit image detected...\n");
+
+               cnt = fit_get_size (fit_hdr);
+               break;
+#endif
+       default:
+               bootstage_error(BOOTSTAGE_ID_NAND_TYPE);
+               puts ("** Unknown image type\n");
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
+
+       r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
+                       (u_char *)addr);
+       if (r) {
+               puts("** Read error\n");
+               bootstage_error(BOOTSTAGE_ID_NAND_READ);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_READ);
+
+#if defined(CONFIG_FIT)
+       /* This cannot be done earlier, we need complete FIT image in RAM first */
+       if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
+               if (!fit_check_format (fit_hdr)) {
+                       bootstage_error(BOOTSTAGE_ID_NAND_FIT_READ);
+                       puts ("** Bad FIT image format\n");
+                       return 1;
+               }
+               bootstage_mark(BOOTSTAGE_ID_NAND_FIT_READ_OK);
+               fit_print_contents (fit_hdr);
+       }
+#endif
+
+       /* Loading ok, update default load address */
+
+       load_addr = addr;
+
+       return bootm_maybe_autostart(cmdtp, cmd);
+}
+
+static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       char *boot_device = NULL;
+       int idx;
+       ulong addr, offset = 0;
+#if defined(CONFIG_CMD_MTDPARTS)
+       struct mtd_device *dev;
+       struct part_info *part;
+       u8 pnum;
+
+       if (argc >= 2) {
+               char *p = (argc == 2) ? argv[1] : argv[2];
+               if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
+                   (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
+                       if (dev->id->type != MTD_DEV_TYPE_NAND) {
+                               puts("Not a NAND device\n");
+                               return 1;
+                       }
+                       if (argc > 3)
+                               goto usage;
+                       if (argc == 3)
+                               addr = simple_strtoul(argv[1], NULL, 16);
+                       else
+                               addr = CONFIG_SYS_LOAD_ADDR;
+                       return nand_load_image(cmdtp, &nand_info[dev->id->num],
+                                              part->offset, addr, argv[0]);
+               }
+       }
+#endif
+
+       bootstage_mark(BOOTSTAGE_ID_NAND_PART);
+       switch (argc) {
+       case 1:
+               addr = CONFIG_SYS_LOAD_ADDR;
+               boot_device = getenv("bootdevice");
+               break;
+       case 2:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               boot_device = getenv("bootdevice");
+               break;
+       case 3:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               boot_device = argv[2];
+               break;
+       case 4:
+               addr = simple_strtoul(argv[1], NULL, 16);
+               boot_device = argv[2];
+               offset = simple_strtoul(argv[3], NULL, 16);
+               break;
+       default:
+#if defined(CONFIG_CMD_MTDPARTS)
+usage:
+#endif
+               bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
+               return CMD_RET_USAGE;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_SUFFIX);
+
+       if (!boot_device) {
+               puts("\n** No boot device **\n");
+               bootstage_error(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
+
+       idx = simple_strtoul(boot_device, NULL, 16);
+
+       if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx].name) {
+               printf("\n** Device %d not available\n", idx);
+               bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
+               return 1;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
+
+       return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
+}
+
+U_BOOT_CMD(nboot, 4, 1, do_nandboot,
+       "boot from NAND device",
+       "[partition] | [[[loadAddr] dev] offset]"
+);
diff --git a/cmd/net.c b/cmd/net.c
new file mode 100644 (file)
index 0000000..b2f3c7b
--- /dev/null
+++ b/cmd/net.c
@@ -0,0 +1,447 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <net.h>
+
+static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
+
+static int do_bootp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(BOOTP, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       bootp,  3,      1,      do_bootp,
+       "boot image via network using BOOTP/TFTP protocol",
+       "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+
+int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret;
+
+       bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
+       ret = netboot_common(TFTPGET, cmdtp, argc, argv);
+       bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
+       return ret;
+}
+
+U_BOOT_CMD(
+       tftpboot,       3,      1,      do_tftpb,
+       "boot image via network using TFTP protocol",
+       "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+
+#ifdef CONFIG_CMD_TFTPPUT
+int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(TFTPPUT, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       tftpput,        4,      1,      do_tftpput,
+       "TFTP put command, for uploading files to a server",
+       "Address Size [[hostIPaddr:]filename]"
+);
+#endif
+
+#ifdef CONFIG_CMD_TFTPSRV
+static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       return netboot_common(TFTPSRV, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       tftpsrv,        2,      1,      do_tftpsrv,
+       "act as a TFTP server and boot the first received file",
+       "[loadAddress]\n"
+       "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
+       "The transfer is aborted if a transfer has not been started after\n"
+       "about 50 seconds or if Ctrl-C is pressed."
+);
+#endif
+
+
+#ifdef CONFIG_CMD_RARP
+int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(RARP, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       rarpboot,       3,      1,      do_rarpb,
+       "boot image via network using RARP/TFTP protocol",
+       "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
+
+#if defined(CONFIG_CMD_DHCP)
+static int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(DHCP, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       dhcp,   3,      1,      do_dhcp,
+       "boot image via network using DHCP/TFTP protocol",
+       "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
+
+#if defined(CONFIG_CMD_NFS)
+static int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(NFS, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       nfs,    3,      1,      do_nfs,
+       "boot image via network using NFS protocol",
+       "[loadAddress] [[hostIPaddr:]bootfilename]"
+);
+#endif
+
+static void netboot_update_env(void)
+{
+       char tmp[22];
+
+       if (net_gateway.s_addr) {
+               ip_to_string(net_gateway, tmp);
+               setenv("gatewayip", tmp);
+       }
+
+       if (net_netmask.s_addr) {
+               ip_to_string(net_netmask, tmp);
+               setenv("netmask", tmp);
+       }
+
+       if (net_hostname[0])
+               setenv("hostname", net_hostname);
+
+       if (net_root_path[0])
+               setenv("rootpath", net_root_path);
+
+       if (net_ip.s_addr) {
+               ip_to_string(net_ip, tmp);
+               setenv("ipaddr", tmp);
+       }
+#if !defined(CONFIG_BOOTP_SERVERIP)
+       /*
+        * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams()
+        * could have set it
+        */
+       if (net_server_ip.s_addr) {
+               ip_to_string(net_server_ip, tmp);
+               setenv("serverip", tmp);
+       }
+#endif
+       if (net_dns_server.s_addr) {
+               ip_to_string(net_dns_server, tmp);
+               setenv("dnsip", tmp);
+       }
+#if defined(CONFIG_BOOTP_DNS2)
+       if (net_dns_server2.s_addr) {
+               ip_to_string(net_dns_server2, tmp);
+               setenv("dnsip2", tmp);
+       }
+#endif
+       if (net_nis_domain[0])
+               setenv("domain", net_nis_domain);
+
+#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
+       if (net_ntp_time_offset) {
+               sprintf(tmp, "%d", net_ntp_time_offset);
+               setenv("timeoffset", tmp);
+       }
+#endif
+#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
+       if (net_ntp_server.s_addr) {
+               ip_to_string(net_ntp_server, tmp);
+               setenv("ntpserverip", tmp);
+       }
+#endif
+}
+
+static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
+               char * const argv[])
+{
+       char *s;
+       char *end;
+       int   rcode = 0;
+       int   size;
+       ulong addr;
+
+       /* pre-set load_addr */
+       s = getenv("loadaddr");
+       if (s != NULL)
+               load_addr = simple_strtoul(s, NULL, 16);
+
+       switch (argc) {
+       case 1:
+               break;
+
+       case 2: /*
+                * Only one arg - accept two forms:
+                * Just load address, or just boot file name. The latter
+                * form must be written in a format which can not be
+                * mis-interpreted as a valid number.
+                */
+               addr = simple_strtoul(argv[1], &end, 16);
+               if (end == (argv[1] + strlen(argv[1])))
+                       load_addr = addr;
+               else
+                       copy_filename(net_boot_file_name, argv[1],
+                                     sizeof(net_boot_file_name));
+               break;
+
+       case 3:
+               load_addr = simple_strtoul(argv[1], NULL, 16);
+               copy_filename(net_boot_file_name, argv[2],
+                             sizeof(net_boot_file_name));
+
+               break;
+
+#ifdef CONFIG_CMD_TFTPPUT
+       case 4:
+               if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
+                   strict_strtoul(argv[2], 16, &save_size) < 0) {
+                       printf("Invalid address/size\n");
+                       return CMD_RET_USAGE;
+               }
+               copy_filename(net_boot_file_name, argv[3],
+                             sizeof(net_boot_file_name));
+               break;
+#endif
+       default:
+               bootstage_error(BOOTSTAGE_ID_NET_START);
+               return CMD_RET_USAGE;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NET_START);
+
+       size = net_loop(proto);
+       if (size < 0) {
+               bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
+               return CMD_RET_FAILURE;
+       }
+       bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
+
+       /* net_loop ok, update environment */
+       netboot_update_env();
+
+       /* done if no file was loaded (no errors though) */
+       if (size == 0) {
+               bootstage_error(BOOTSTAGE_ID_NET_LOADED);
+               return CMD_RET_SUCCESS;
+       }
+
+       /* flush cache */
+       flush_cache(load_addr, size);
+
+       bootstage_mark(BOOTSTAGE_ID_NET_LOADED);
+
+       rcode = bootm_maybe_autostart(cmdtp, argv[0]);
+
+       if (rcode == CMD_RET_SUCCESS)
+               bootstage_mark(BOOTSTAGE_ID_NET_DONE);
+       else
+               bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
+       return rcode;
+}
+
+#if defined(CONFIG_CMD_PING)
+static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       net_ping_ip = string_to_ip(argv[1]);
+       if (net_ping_ip.s_addr == 0)
+               return CMD_RET_USAGE;
+
+       if (net_loop(PING) < 0) {
+               printf("ping failed; host %s is not alive\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       printf("host %s is alive\n", argv[1]);
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       ping,   2,      1,      do_ping,
+       "send ICMP ECHO_REQUEST to network host",
+       "pingAddress"
+);
+#endif
+
+#if defined(CONFIG_CMD_CDP)
+
+static void cdp_update_env(void)
+{
+       char tmp[16];
+
+       if (cdp_appliance_vlan != htons(-1)) {
+               printf("CDP offered appliance VLAN %d\n",
+                      ntohs(cdp_appliance_vlan));
+               vlan_to_string(cdp_appliance_vlan, tmp);
+               setenv("vlan", tmp);
+               net_our_vlan = cdp_appliance_vlan;
+       }
+
+       if (cdp_native_vlan != htons(-1)) {
+               printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
+               vlan_to_string(cdp_native_vlan, tmp);
+               setenv("nvlan", tmp);
+               net_native_vlan = cdp_native_vlan;
+       }
+}
+
+int do_cdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int r;
+
+       r = net_loop(CDP);
+       if (r < 0) {
+               printf("cdp failed; perhaps not a CISCO switch?\n");
+               return CMD_RET_FAILURE;
+       }
+
+       cdp_update_env();
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       cdp,    1,      1,      do_cdp,
+       "Perform CDP network configuration",
+       "\n"
+);
+#endif
+
+#if defined(CONFIG_CMD_SNTP)
+int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *toff;
+
+       if (argc < 2) {
+               net_ntp_server = getenv_ip("ntpserverip");
+               if (net_ntp_server.s_addr == 0) {
+                       printf("ntpserverip not set\n");
+                       return CMD_RET_FAILURE;
+               }
+       } else {
+               net_ntp_server = string_to_ip(argv[1]);
+               if (net_ntp_server.s_addr == 0) {
+                       printf("Bad NTP server IP address\n");
+                       return CMD_RET_FAILURE;
+               }
+       }
+
+       toff = getenv("timeoffset");
+       if (toff == NULL)
+               net_ntp_time_offset = 0;
+       else
+               net_ntp_time_offset = simple_strtol(toff, NULL, 10);
+
+       if (net_loop(SNTP) < 0) {
+               printf("SNTP failed: host %pI4 not responding\n",
+                      &net_ntp_server);
+               return CMD_RET_FAILURE;
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       sntp,   2,      1,      do_sntp,
+       "synchronize RTC via network",
+       "[NTP server IP]\n"
+);
+#endif
+
+#if defined(CONFIG_CMD_DNS)
+int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc == 1)
+               return CMD_RET_USAGE;
+
+       /*
+        * We should check for a valid hostname:
+        * - Each label must be between 1 and 63 characters long
+        * - the entire hostname has a maximum of 255 characters
+        * - only the ASCII letters 'a' through 'z' (case-insensitive),
+        *   the digits '0' through '9', and the hyphen
+        * - cannot begin or end with a hyphen
+        * - no other symbols, punctuation characters, or blank spaces are
+        *   permitted
+        * but hey - this is a minimalist implmentation, so only check length
+        * and let the name server deal with things.
+        */
+       if (strlen(argv[1]) >= 255) {
+               printf("dns error: hostname too long\n");
+               return CMD_RET_FAILURE;
+       }
+
+       net_dns_resolve = argv[1];
+
+       if (argc == 3)
+               net_dns_env_var = argv[2];
+       else
+               net_dns_env_var = NULL;
+
+       if (net_loop(DNS) < 0) {
+               printf("dns lookup of %s failed, check setup\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       dns,    3,      1,      do_dns,
+       "lookup the IP of a hostname",
+       "hostname [envvar]"
+);
+
+#endif /* CONFIG_CMD_DNS */
+
+#if defined(CONFIG_CMD_LINK_LOCAL)
+static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       char tmp[22];
+
+       if (net_loop(LINKLOCAL) < 0)
+               return CMD_RET_FAILURE;
+
+       net_gateway.s_addr = 0;
+       ip_to_string(net_gateway, tmp);
+       setenv("gatewayip", tmp);
+
+       ip_to_string(net_netmask, tmp);
+       setenv("netmask", tmp);
+
+       ip_to_string(net_ip, tmp);
+       setenv("ipaddr", tmp);
+       setenv("llipaddr", tmp); /* store this for next time */
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       linklocal,      1,      1,      do_link_local,
+       "acquire a network IP address using the link-local protocol",
+       ""
+);
+
+#endif  /* CONFIG_CMD_LINK_LOCAL */
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
new file mode 100644 (file)
index 0000000..5ae9d9d
--- /dev/null
@@ -0,0 +1,1298 @@
+/*
+ * (C) Copyright 2000-2013
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Andreas Heppel <aheppel@sysgo.de>
+ *
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Support for persistent environment data
+ *
+ * The "environment" is stored on external storage as a list of '\0'
+ * terminated "name=value" strings. The end of the list is marked by
+ * a double '\0'. The environment is preceeded by a 32 bit CRC over
+ * the data part and, in case of redundant environment, a byte of
+ * flags.
+ *
+ * This linearized representation will also be used before
+ * relocation, i. e. as long as we don't have a full C runtime
+ * environment. After that, we use a hash table.
+ */
+
+#include <common.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <environment.h>
+#include <search.h>
+#include <errno.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <watchdog.h>
+#include <linux/stddef.h>
+#include <asm/byteorder.h>
+#include <asm/io.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if    !defined(CONFIG_ENV_IS_IN_EEPROM)       && \
+       !defined(CONFIG_ENV_IS_IN_FLASH)        && \
+       !defined(CONFIG_ENV_IS_IN_DATAFLASH)    && \
+       !defined(CONFIG_ENV_IS_IN_MMC)          && \
+       !defined(CONFIG_ENV_IS_IN_FAT)          && \
+       !defined(CONFIG_ENV_IS_IN_NAND)         && \
+       !defined(CONFIG_ENV_IS_IN_NVRAM)        && \
+       !defined(CONFIG_ENV_IS_IN_ONENAND)      && \
+       !defined(CONFIG_ENV_IS_IN_SPI_FLASH)    && \
+       !defined(CONFIG_ENV_IS_IN_REMOTE)       && \
+       !defined(CONFIG_ENV_IS_IN_UBI)          && \
+       !defined(CONFIG_ENV_IS_NOWHERE)
+# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
+SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
+#endif
+
+/*
+ * Maximum expected input data size for import command
+ */
+#define        MAX_ENV_SIZE    (1 << 20)       /* 1 MiB */
+
+/*
+ * This variable is incremented on each do_env_set(), so it can
+ * be used via get_env_id() as an indication, if the environment
+ * has changed or not. So it is possible to reread an environment
+ * variable only if the environment was changed ... done so for
+ * example in NetInitLoop()
+ */
+static int env_id = 1;
+
+int get_env_id(void)
+{
+       return env_id;
+}
+
+#ifndef CONFIG_SPL_BUILD
+/*
+ * Command interface: print one or all environment variables
+ *
+ * Returns 0 in case of error, or length of printed string
+ */
+static int env_print(char *name, int flag)
+{
+       char *res = NULL;
+       ssize_t len;
+
+       if (name) {             /* print a single name */
+               ENTRY e, *ep;
+
+               e.key = name;
+               e.data = NULL;
+               hsearch_r(e, FIND, &ep, &env_htab, flag);
+               if (ep == NULL)
+                       return 0;
+               len = printf("%s=%s\n", ep->key, ep->data);
+               return len;
+       }
+
+       /* print whole list */
+       len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
+
+       if (len > 0) {
+               puts(res);
+               free(res);
+               return len;
+       }
+
+       /* should never happen */
+       printf("## Error: cannot export environment\n");
+       return 0;
+}
+
+static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       int i;
+       int rcode = 0;
+       int env_flag = H_HIDE_DOT;
+
+       if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
+               argc--;
+               argv++;
+               env_flag &= ~H_HIDE_DOT;
+       }
+
+       if (argc == 1) {
+               /* print all env vars */
+               rcode = env_print(NULL, env_flag);
+               if (!rcode)
+                       return 1;
+               printf("\nEnvironment size: %d/%ld bytes\n",
+                       rcode, (ulong)ENV_SIZE);
+               return 0;
+       }
+
+       /* print selected env vars */
+       env_flag &= ~H_HIDE_DOT;
+       for (i = 1; i < argc; ++i) {
+               int rc = env_print(argv[i], env_flag);
+               if (!rc) {
+                       printf("## Error: \"%s\" not defined\n", argv[i]);
+                       ++rcode;
+               }
+       }
+
+       return rcode;
+}
+
+#ifdef CONFIG_CMD_GREPENV
+static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
+                      int argc, char * const argv[])
+{
+       char *res = NULL;
+       int len, grep_how, grep_what;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       grep_how  = H_MATCH_SUBSTR;     /* default: substring search    */
+       grep_what = H_MATCH_BOTH;       /* default: grep names and values */
+
+       while (--argc > 0 && **++argv == '-') {
+               char *arg = *argv;
+               while (*++arg) {
+                       switch (*arg) {
+#ifdef CONFIG_REGEX
+                       case 'e':               /* use regex matching */
+                               grep_how  = H_MATCH_REGEX;
+                               break;
+#endif
+                       case 'n':               /* grep for name */
+                               grep_what = H_MATCH_KEY;
+                               break;
+                       case 'v':               /* grep for value */
+                               grep_what = H_MATCH_DATA;
+                               break;
+                       case 'b':               /* grep for both */
+                               grep_what = H_MATCH_BOTH;
+                               break;
+                       case '-':
+                               goto DONE;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+
+DONE:
+       len = hexport_r(&env_htab, '\n',
+                       flag | grep_what | grep_how,
+                       &res, 0, argc, argv);
+
+       if (len > 0) {
+               puts(res);
+               free(res);
+       }
+
+       if (len < 2)
+               return 1;
+
+       return 0;
+}
+#endif
+#endif /* CONFIG_SPL_BUILD */
+
+/*
+ * Set a new environment variable,
+ * or replace or delete an existing one.
+ */
+static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
+{
+       int   i, len;
+       char  *name, *value, *s;
+       ENTRY e, *ep;
+
+       debug("Initial value for argc=%d\n", argc);
+       while (argc > 1 && **(argv + 1) == '-') {
+               char *arg = *++argv;
+
+               --argc;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'f':               /* force */
+                               env_flag |= H_FORCE;
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+       debug("Final value for argc=%d\n", argc);
+       name = argv[1];
+       value = argv[2];
+
+       if (strchr(name, '=')) {
+               printf("## Error: illegal character '='"
+                      "in variable name \"%s\"\n", name);
+               return 1;
+       }
+
+       env_id++;
+
+       /* Delete only ? */
+       if (argc < 3 || argv[2] == NULL) {
+               int rc = hdelete_r(name, &env_htab, env_flag);
+               return !rc;
+       }
+
+       /*
+        * Insert / replace new value
+        */
+       for (i = 2, len = 0; i < argc; ++i)
+               len += strlen(argv[i]) + 1;
+
+       value = malloc(len);
+       if (value == NULL) {
+               printf("## Can't malloc %d bytes\n", len);
+               return 1;
+       }
+       for (i = 2, s = value; i < argc; ++i) {
+               char *v = argv[i];
+
+               while ((*s++ = *v++) != '\0')
+                       ;
+               *(s - 1) = ' ';
+       }
+       if (s != value)
+               *--s = '\0';
+
+       e.key   = name;
+       e.data  = value;
+       hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
+       free(value);
+       if (!ep) {
+               printf("## Error inserting \"%s\" variable, errno=%d\n",
+                       name, errno);
+               return 1;
+       }
+
+       return 0;
+}
+
+int setenv(const char *varname, const char *varvalue)
+{
+       const char * const argv[4] = { "setenv", varname, varvalue, NULL };
+
+       /* before import into hashtable */
+       if (!(gd->flags & GD_FLG_ENV_READY))
+               return 1;
+
+       if (varvalue == NULL || varvalue[0] == '\0')
+               return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
+       else
+               return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
+}
+
+/**
+ * Set an environment variable to an integer value
+ *
+ * @param varname      Environment variable to set
+ * @param value                Value to set it to
+ * @return 0 if ok, 1 on error
+ */
+int setenv_ulong(const char *varname, ulong value)
+{
+       /* TODO: this should be unsigned */
+       char *str = simple_itoa(value);
+
+       return setenv(varname, str);
+}
+
+/**
+ * Set an environment variable to an value in hex
+ *
+ * @param varname      Environment variable to set
+ * @param value                Value to set it to
+ * @return 0 if ok, 1 on error
+ */
+int setenv_hex(const char *varname, ulong value)
+{
+       char str[17];
+
+       sprintf(str, "%lx", value);
+       return setenv(varname, str);
+}
+
+ulong getenv_hex(const char *varname, ulong default_val)
+{
+       const char *s;
+       ulong value;
+       char *endp;
+
+       s = getenv(varname);
+       if (s)
+               value = simple_strtoul(s, &endp, 16);
+       if (!s || endp == s)
+               return default_val;
+
+       return value;
+}
+
+#ifndef CONFIG_SPL_BUILD
+static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       return _do_env_set(flag, argc, argv, H_INTERACTIVE);
+}
+
+/*
+ * Prompt for environment variable
+ */
+#if defined(CONFIG_CMD_ASKENV)
+int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char message[CONFIG_SYS_CBSIZE];
+       int i, len, pos, size;
+       char *local_args[4];
+       char *endptr;
+
+       local_args[0] = argv[0];
+       local_args[1] = argv[1];
+       local_args[2] = NULL;
+       local_args[3] = NULL;
+
+       /*
+        * Check the syntax:
+        *
+        * env_ask envname [message1 ...] [size]
+        */
+       if (argc == 1)
+               return CMD_RET_USAGE;
+
+       /*
+        * We test the last argument if it can be converted
+        * into a decimal number.  If yes, we assume it's
+        * the size.  Otherwise we echo it as part of the
+        * message.
+        */
+       i = simple_strtoul(argv[argc - 1], &endptr, 10);
+       if (*endptr != '\0') {                  /* no size */
+               size = CONFIG_SYS_CBSIZE - 1;
+       } else {                                /* size given */
+               size = i;
+               --argc;
+       }
+
+       if (argc <= 2) {
+               sprintf(message, "Please enter '%s': ", argv[1]);
+       } else {
+               /* env_ask envname message1 ... messagen [size] */
+               for (i = 2, pos = 0; i < argc; i++) {
+                       if (pos)
+                               message[pos++] = ' ';
+
+                       strcpy(message + pos, argv[i]);
+                       pos += strlen(argv[i]);
+               }
+               message[pos++] = ' ';
+               message[pos] = '\0';
+       }
+
+       if (size >= CONFIG_SYS_CBSIZE)
+               size = CONFIG_SYS_CBSIZE - 1;
+
+       if (size <= 0)
+               return 1;
+
+       /* prompt for input */
+       len = cli_readline(message);
+
+       if (size < len)
+               console_buffer[size] = '\0';
+
+       len = 2;
+       if (console_buffer[0] != '\0') {
+               local_args[2] = console_buffer;
+               len = 3;
+       }
+
+       /* Continue calling setenv code */
+       return _do_env_set(flag, len, local_args, H_INTERACTIVE);
+}
+#endif
+
+#if defined(CONFIG_CMD_ENV_CALLBACK)
+static int print_static_binding(const char *var_name, const char *callback_name,
+                               void *priv)
+{
+       printf("\t%-20s %-20s\n", var_name, callback_name);
+
+       return 0;
+}
+
+static int print_active_callback(ENTRY *entry)
+{
+       struct env_clbk_tbl *clbkp;
+       int i;
+       int num_callbacks;
+
+       if (entry->callback == NULL)
+               return 0;
+
+       /* look up the callback in the linker-list */
+       num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
+       for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
+            i < num_callbacks;
+            i++, clbkp++) {
+#if defined(CONFIG_NEEDS_MANUAL_RELOC)
+               if (entry->callback == clbkp->callback + gd->reloc_off)
+#else
+               if (entry->callback == clbkp->callback)
+#endif
+                       break;
+       }
+
+       if (i == num_callbacks)
+               /* this should probably never happen, but just in case... */
+               printf("\t%-20s %p\n", entry->key, entry->callback);
+       else
+               printf("\t%-20s %-20s\n", entry->key, clbkp->name);
+
+       return 0;
+}
+
+/*
+ * Print the callbacks available and what they are bound to
+ */
+int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct env_clbk_tbl *clbkp;
+       int i;
+       int num_callbacks;
+
+       /* Print the available callbacks */
+       puts("Available callbacks:\n");
+       puts("\tCallback Name\n");
+       puts("\t-------------\n");
+       num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
+       for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
+            i < num_callbacks;
+            i++, clbkp++)
+               printf("\t%s\n", clbkp->name);
+       puts("\n");
+
+       /* Print the static bindings that may exist */
+       puts("Static callback bindings:\n");
+       printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
+       printf("\t%-20s %-20s\n", "-------------", "-------------");
+       env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL);
+       puts("\n");
+
+       /* walk through each variable and print the callback if it has one */
+       puts("Active callback bindings:\n");
+       printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
+       printf("\t%-20s %-20s\n", "-------------", "-------------");
+       hwalk_r(&env_htab, print_active_callback);
+       return 0;
+}
+#endif
+
+#if defined(CONFIG_CMD_ENV_FLAGS)
+static int print_static_flags(const char *var_name, const char *flags,
+                             void *priv)
+{
+       enum env_flags_vartype type = env_flags_parse_vartype(flags);
+       enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
+
+       printf("\t%-20s %-20s %-20s\n", var_name,
+               env_flags_get_vartype_name(type),
+               env_flags_get_varaccess_name(access));
+
+       return 0;
+}
+
+static int print_active_flags(ENTRY *entry)
+{
+       enum env_flags_vartype type;
+       enum env_flags_varaccess access;
+
+       if (entry->flags == 0)
+               return 0;
+
+       type = (enum env_flags_vartype)
+               (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
+       access = env_flags_parse_varaccess_from_binflags(entry->flags);
+       printf("\t%-20s %-20s %-20s\n", entry->key,
+               env_flags_get_vartype_name(type),
+               env_flags_get_varaccess_name(access));
+
+       return 0;
+}
+
+/*
+ * Print the flags available and what variables have flags
+ */
+int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       /* Print the available variable types */
+       printf("Available variable type flags (position %d):\n",
+               ENV_FLAGS_VARTYPE_LOC);
+       puts("\tFlag\tVariable Type Name\n");
+       puts("\t----\t------------------\n");
+       env_flags_print_vartypes();
+       puts("\n");
+
+       /* Print the available variable access types */
+       printf("Available variable access flags (position %d):\n",
+               ENV_FLAGS_VARACCESS_LOC);
+       puts("\tFlag\tVariable Access Name\n");
+       puts("\t----\t--------------------\n");
+       env_flags_print_varaccess();
+       puts("\n");
+
+       /* Print the static flags that may exist */
+       puts("Static flags:\n");
+       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
+               "Variable Access");
+       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
+               "---------------");
+       env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL);
+       puts("\n");
+
+       /* walk through each variable and print the flags if non-default */
+       puts("Active flags:\n");
+       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
+               "Variable Access");
+       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
+               "---------------");
+       hwalk_r(&env_htab, print_active_flags);
+       return 0;
+}
+#endif
+
+/*
+ * Interactively edit an environment variable
+ */
+#if defined(CONFIG_CMD_EDITENV)
+static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       char buffer[CONFIG_SYS_CBSIZE];
+       char *init_val;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* before import into hashtable */
+       if (!(gd->flags & GD_FLG_ENV_READY))
+               return 1;
+
+       /* Set read buffer to initial value or empty sting */
+       init_val = getenv(argv[1]);
+       if (init_val)
+               snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val);
+       else
+               buffer[0] = '\0';
+
+       if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
+               return 1;
+
+       if (buffer[0] == '\0') {
+               const char * const _argv[3] = { "setenv", argv[1], NULL };
+
+               return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE);
+       } else {
+               const char * const _argv[4] = { "setenv", argv[1], buffer,
+                       NULL };
+
+               return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE);
+       }
+}
+#endif /* CONFIG_CMD_EDITENV */
+#endif /* CONFIG_SPL_BUILD */
+
+/*
+ * Look up variable from environment,
+ * return address of storage for that variable,
+ * or NULL if not found
+ */
+char *getenv(const char *name)
+{
+       if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
+               ENTRY e, *ep;
+
+               WATCHDOG_RESET();
+
+               e.key   = name;
+               e.data  = NULL;
+               hsearch_r(e, FIND, &ep, &env_htab, 0);
+
+               return ep ? ep->data : NULL;
+       }
+
+       /* restricted capabilities before import */
+       if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
+               return (char *)(gd->env_buf);
+
+       return NULL;
+}
+
+/*
+ * Look up variable from environment for restricted C runtime env.
+ */
+int getenv_f(const char *name, char *buf, unsigned len)
+{
+       int i, nxt;
+
+       for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
+               int val, n;
+
+               for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
+                       if (nxt >= CONFIG_ENV_SIZE)
+                               return -1;
+               }
+
+               val = envmatch((uchar *)name, i);
+               if (val < 0)
+                       continue;
+
+               /* found; copy out */
+               for (n = 0; n < len; ++n, ++buf) {
+                       *buf = env_get_char(val++);
+                       if (*buf == '\0')
+                               return n;
+               }
+
+               if (n)
+                       *--buf = '\0';
+
+               printf("env_buf [%d bytes] too small for value of \"%s\"\n",
+                       len, name);
+
+               return n;
+       }
+
+       return -1;
+}
+
+/**
+ * Decode the integer value of an environment variable and return it.
+ *
+ * @param name         Name of environemnt variable
+ * @param base         Number base to use (normally 10, or 16 for hex)
+ * @param default_val  Default value to return if the variable is not
+ *                     found
+ * @return the decoded value, or default_val if not found
+ */
+ulong getenv_ulong(const char *name, int base, ulong default_val)
+{
+       /*
+        * We can use getenv() here, even before relocation, since the
+        * environment variable value is an integer and thus short.
+        */
+       const char *str = getenv(name);
+
+       return str ? simple_strtoul(str, NULL, base) : default_val;
+}
+
+#ifndef CONFIG_SPL_BUILD
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
+static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       printf("Saving Environment to %s...\n", env_name_spec);
+
+       return saveenv() ? 1 : 0;
+}
+
+U_BOOT_CMD(
+       saveenv, 1, 0,  do_env_save,
+       "save environment variables to persistent storage",
+       ""
+);
+#endif
+#endif /* CONFIG_SPL_BUILD */
+
+
+/*
+ * Match a name / name=value pair
+ *
+ * s1 is either a simple 'name', or a 'name=value' pair.
+ * i2 is the environment index for a 'name2=value2' pair.
+ * If the names match, return the index for the value2, else -1.
+ */
+int envmatch(uchar *s1, int i2)
+{
+       if (s1 == NULL)
+               return -1;
+
+       while (*s1 == env_get_char(i2++))
+               if (*s1++ == '=')
+                       return i2;
+
+       if (*s1 == '\0' && env_get_char(i2-1) == '=')
+               return i2;
+
+       return -1;
+}
+
+#ifndef CONFIG_SPL_BUILD
+static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
+                         int argc, char * const argv[])
+{
+       int all = 0, flag = 0;
+
+       debug("Initial value for argc=%d\n", argc);
+       while (--argc > 0 && **++argv == '-') {
+               char *arg = *argv;
+
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'a':               /* default all */
+                               all = 1;
+                               break;
+                       case 'f':               /* force */
+                               flag |= H_FORCE;
+                               break;
+                       default:
+                               return cmd_usage(cmdtp);
+                       }
+               }
+       }
+       debug("Final value for argc=%d\n", argc);
+       if (all && (argc == 0)) {
+               /* Reset the whole environment */
+               set_default_env("## Resetting to default environment\n");
+               return 0;
+       }
+       if (!all && (argc > 0)) {
+               /* Reset individual variables */
+               set_default_vars(argc, argv);
+               return 0;
+       }
+
+       return cmd_usage(cmdtp);
+}
+
+static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
+                        int argc, char * const argv[])
+{
+       int env_flag = H_INTERACTIVE;
+       int ret = 0;
+
+       debug("Initial value for argc=%d\n", argc);
+       while (argc > 1 && **(argv + 1) == '-') {
+               char *arg = *++argv;
+
+               --argc;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'f':               /* force */
+                               env_flag |= H_FORCE;
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+       debug("Final value for argc=%d\n", argc);
+
+       env_id++;
+
+       while (--argc > 0) {
+               char *name = *++argv;
+
+               if (!hdelete_r(name, &env_htab, env_flag))
+                       ret = 1;
+       }
+
+       return ret;
+}
+
+#ifdef CONFIG_CMD_EXPORTENV
+/*
+ * env export [-t | -b | -c] [-s size] addr [var ...]
+ *     -t:     export as text format; if size is given, data will be
+ *             padded with '\0' bytes; if not, one terminating '\0'
+ *             will be added (which is included in the "filesize"
+ *             setting so you can for exmple copy this to flash and
+ *             keep the termination).
+ *     -b:     export as binary format (name=value pairs separated by
+ *             '\0', list end marked by double "\0\0")
+ *     -c:     export as checksum protected environment format as
+ *             used for example by "saveenv" command
+ *     -s size:
+ *             size of output buffer
+ *     addr:   memory address where environment gets stored
+ *     var...  List of variable names that get included into the
+ *             export. Without arguments, the whole environment gets
+ *             exported.
+ *
+ * With "-c" and size is NOT given, then the export command will
+ * format the data as currently used for the persistent storage,
+ * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
+ * prepend a valid CRC32 checksum and, in case of resundant
+ * environment, a "current" redundancy flag. If size is given, this
+ * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
+ * checksum and redundancy flag will be inserted.
+ *
+ * With "-b" and "-t", always only the real data (including a
+ * terminating '\0' byte) will be written; here the optional size
+ * argument will be used to make sure not to overflow the user
+ * provided buffer; the command will abort if the size is not
+ * sufficient. Any remainign space will be '\0' padded.
+ *
+ * On successful return, the variable "filesize" will be set.
+ * Note that filesize includes the trailing/terminating '\0' byte(s).
+ *
+ * Usage szenario:  create a text snapshot/backup of the current settings:
+ *
+ *     => env export -t 100000
+ *     => era ${backup_addr} +${filesize}
+ *     => cp.b 100000 ${backup_addr} ${filesize}
+ *
+ * Re-import this snapshot, deleting all other settings:
+ *
+ *     => env import -d -t ${backup_addr}
+ */
+static int do_env_export(cmd_tbl_t *cmdtp, int flag,
+                        int argc, char * const argv[])
+{
+       char    buf[32];
+       ulong   addr;
+       char    *ptr, *cmd, *res;
+       size_t  size = 0;
+       ssize_t len;
+       env_t   *envp;
+       char    sep = '\n';
+       int     chk = 0;
+       int     fmt = 0;
+
+       cmd = *argv;
+
+       while (--argc > 0 && **++argv == '-') {
+               char *arg = *argv;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'b':               /* raw binary format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\0';
+                               break;
+                       case 'c':               /* external checksum format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\0';
+                               chk = 1;
+                               break;
+                       case 's':               /* size given */
+                               if (--argc <= 0)
+                                       return cmd_usage(cmdtp);
+                               size = simple_strtoul(*++argv, NULL, 16);
+                               goto NXTARG;
+                       case 't':               /* text format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\n';
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+NXTARG:                ;
+       }
+
+       if (argc < 1)
+               return CMD_RET_USAGE;
+
+       addr = simple_strtoul(argv[0], NULL, 16);
+       ptr = map_sysmem(addr, size);
+
+       if (size)
+               memset(ptr, '\0', size);
+
+       argc--;
+       argv++;
+
+       if (sep) {              /* export as text file */
+               len = hexport_r(&env_htab, sep,
+                               H_MATCH_KEY | H_MATCH_IDENT,
+                               &ptr, size, argc, argv);
+               if (len < 0) {
+                       error("Cannot export environment: errno = %d\n", errno);
+                       return 1;
+               }
+               sprintf(buf, "%zX", (size_t)len);
+               setenv("filesize", buf);
+
+               return 0;
+       }
+
+       envp = (env_t *)ptr;
+
+       if (chk)                /* export as checksum protected block */
+               res = (char *)envp->data;
+       else                    /* export as raw binary data */
+               res = ptr;
+
+       len = hexport_r(&env_htab, '\0',
+                       H_MATCH_KEY | H_MATCH_IDENT,
+                       &res, ENV_SIZE, argc, argv);
+       if (len < 0) {
+               error("Cannot export environment: errno = %d\n", errno);
+               return 1;
+       }
+
+       if (chk) {
+               envp->crc = crc32(0, envp->data, ENV_SIZE);
+#ifdef CONFIG_ENV_ADDR_REDUND
+               envp->flags = ACTIVE_FLAG;
+#endif
+       }
+       setenv_hex("filesize", len + offsetof(env_t, data));
+
+       return 0;
+
+sep_err:
+       printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
+       return 1;
+}
+#endif
+
+#ifdef CONFIG_CMD_IMPORTENV
+/*
+ * env import [-d] [-t [-r] | -b | -c] addr [size]
+ *     -d:     delete existing environment before importing;
+ *             otherwise overwrite / append to existion definitions
+ *     -t:     assume text format; either "size" must be given or the
+ *             text data must be '\0' terminated
+ *     -r:     handle CRLF like LF, that means exported variables with
+ *             a content which ends with \r won't get imported. Used
+ *             to import text files created with editors which are using CRLF
+ *             for line endings. Only effective in addition to -t.
+ *     -b:     assume binary format ('\0' separated, "\0\0" terminated)
+ *     -c:     assume checksum protected environment format
+ *     addr:   memory address to read from
+ *     size:   length of input data; if missing, proper '\0'
+ *             termination is mandatory
+ */
+static int do_env_import(cmd_tbl_t *cmdtp, int flag,
+                        int argc, char * const argv[])
+{
+       ulong   addr;
+       char    *cmd, *ptr;
+       char    sep = '\n';
+       int     chk = 0;
+       int     fmt = 0;
+       int     del = 0;
+       int     crlf_is_lf = 0;
+       size_t  size;
+
+       cmd = *argv;
+
+       while (--argc > 0 && **++argv == '-') {
+               char *arg = *argv;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'b':               /* raw binary format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\0';
+                               break;
+                       case 'c':               /* external checksum format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\0';
+                               chk = 1;
+                               break;
+                       case 't':               /* text format */
+                               if (fmt++)
+                                       goto sep_err;
+                               sep = '\n';
+                               break;
+                       case 'r':               /* handle CRLF like LF */
+                               crlf_is_lf = 1;
+                               break;
+                       case 'd':
+                               del = 1;
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+
+       if (argc < 1)
+               return CMD_RET_USAGE;
+
+       if (!fmt)
+               printf("## Warning: defaulting to text format\n");
+
+       if (sep != '\n' && crlf_is_lf )
+               crlf_is_lf = 0;
+
+       addr = simple_strtoul(argv[0], NULL, 16);
+       ptr = map_sysmem(addr, 0);
+
+       if (argc == 2) {
+               size = simple_strtoul(argv[1], NULL, 16);
+       } else if (argc == 1 && chk) {
+               puts("## Error: external checksum format must pass size\n");
+               return CMD_RET_FAILURE;
+       } else {
+               char *s = ptr;
+
+               size = 0;
+
+               while (size < MAX_ENV_SIZE) {
+                       if ((*s == sep) && (*(s+1) == '\0'))
+                               break;
+                       ++s;
+                       ++size;
+               }
+               if (size == MAX_ENV_SIZE) {
+                       printf("## Warning: Input data exceeds %d bytes"
+                               " - truncated\n", MAX_ENV_SIZE);
+               }
+               size += 2;
+               printf("## Info: input data size = %zu = 0x%zX\n", size, size);
+       }
+
+       if (chk) {
+               uint32_t crc;
+               env_t *ep = (env_t *)ptr;
+
+               size -= offsetof(env_t, data);
+               memcpy(&crc, &ep->crc, sizeof(crc));
+
+               if (crc32(0, ep->data, size) != crc) {
+                       puts("## Error: bad CRC, import failed\n");
+                       return 1;
+               }
+               ptr = (char *)ep->data;
+       }
+
+       if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
+                       crlf_is_lf, 0, NULL) == 0) {
+               error("Environment import failed: errno = %d\n", errno);
+               return 1;
+       }
+       gd->flags |= GD_FLG_ENV_READY;
+
+       return 0;
+
+sep_err:
+       printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
+               cmd);
+       return 1;
+}
+#endif
+
+#if defined(CONFIG_CMD_ENV_EXISTS)
+static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+       ENTRY e, *ep;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       e.key = argv[1];
+       e.data = NULL;
+       hsearch_r(e, FIND, &ep, &env_htab, 0);
+
+       return (ep == NULL) ? 1 : 0;
+}
+#endif
+
+/*
+ * New command line interface: "env" command with subcommands
+ */
+static cmd_tbl_t cmd_env_sub[] = {
+#if defined(CONFIG_CMD_ASKENV)
+       U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
+       U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
+#if defined(CONFIG_CMD_EDITENV)
+       U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
+#endif
+#if defined(CONFIG_CMD_ENV_CALLBACK)
+       U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
+#endif
+#if defined(CONFIG_CMD_ENV_FLAGS)
+       U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
+#endif
+#if defined(CONFIG_CMD_EXPORTENV)
+       U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
+#endif
+#if defined(CONFIG_CMD_GREPENV)
+       U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
+#endif
+#if defined(CONFIG_CMD_IMPORTENV)
+       U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
+#if defined(CONFIG_CMD_RUN)
+       U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
+#endif
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
+       U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
+#endif
+       U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
+#if defined(CONFIG_CMD_ENV_EXISTS)
+       U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
+#endif
+};
+
+#if defined(CONFIG_NEEDS_MANUAL_RELOC)
+void env_reloc(void)
+{
+       fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
+}
+#endif
+
+static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *cp;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       /* drop initial "env" arg */
+       argc--;
+       argv++;
+
+       cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
+
+       if (cp)
+               return cp->cmd(cmdtp, flag, argc, argv);
+
+       return CMD_RET_USAGE;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char env_help_text[] =
+#if defined(CONFIG_CMD_ASKENV)
+       "ask name [message] [size] - ask for environment variable\nenv "
+#endif
+#if defined(CONFIG_CMD_ENV_CALLBACK)
+       "callbacks - print callbacks and their associated variables\nenv "
+#endif
+       "default [-f] -a - [forcibly] reset default environment\n"
+       "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
+       "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
+#if defined(CONFIG_CMD_EDITENV)
+       "env edit name - edit environment variable\n"
+#endif
+#if defined(CONFIG_CMD_ENV_EXISTS)
+       "env exists name - tests for existence of variable\n"
+#endif
+#if defined(CONFIG_CMD_EXPORTENV)
+       "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
+#endif
+#if defined(CONFIG_CMD_ENV_FLAGS)
+       "env flags - print variables that have non-default flags\n"
+#endif
+#if defined(CONFIG_CMD_GREPENV)
+#ifdef CONFIG_REGEX
+       "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
+#else
+       "env grep [-n | -v | -b] string [...] - search environment\n"
+#endif
+#endif
+#if defined(CONFIG_CMD_IMPORTENV)
+       "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
+#endif
+       "env print [-a | name ...] - print environment\n"
+#if defined(CONFIG_CMD_RUN)
+       "env run var [...] - run commands in an environment variable\n"
+#endif
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
+       "env save - save environment\n"
+#endif
+       "env set [-f] name [arg ...]\n";
+#endif
+
+U_BOOT_CMD(
+       env, CONFIG_SYS_MAXARGS, 1, do_env,
+       "environment handling commands", env_help_text
+);
+
+/*
+ * Old command line interface, kept for compatibility
+ */
+
+#if defined(CONFIG_CMD_EDITENV)
+U_BOOT_CMD_COMPLETE(
+       editenv, 2, 0,  do_env_edit,
+       "edit environment variable",
+       "name\n"
+       "    - edit environment variable 'name'",
+       var_complete
+);
+#endif
+
+U_BOOT_CMD_COMPLETE(
+       printenv, CONFIG_SYS_MAXARGS, 1,        do_env_print,
+       "print environment variables",
+       "[-a]\n    - print [all] values of all environment variables\n"
+       "printenv name ...\n"
+       "    - print value of environment variable 'name'",
+       var_complete
+);
+
+#ifdef CONFIG_CMD_GREPENV
+U_BOOT_CMD_COMPLETE(
+       grepenv, CONFIG_SYS_MAXARGS, 0,  do_env_grep,
+       "search environment variables",
+#ifdef CONFIG_REGEX
+       "[-e] [-n | -v | -b] string ...\n"
+#else
+       "[-n | -v | -b] string ...\n"
+#endif
+       "    - list environment name=value pairs matching 'string'\n"
+#ifdef CONFIG_REGEX
+       "      \"-e\": enable regular expressions;\n"
+#endif
+       "      \"-n\": search variable names; \"-v\": search values;\n"
+       "      \"-b\": search both names and values (default)",
+       var_complete
+);
+#endif
+
+U_BOOT_CMD_COMPLETE(
+       setenv, CONFIG_SYS_MAXARGS, 0,  do_env_set,
+       "set environment variables",
+       "[-f] name value ...\n"
+       "    - [forcibly] set environment variable 'name' to 'value ...'\n"
+       "setenv [-f] name\n"
+       "    - [forcibly] delete environment variable 'name'",
+       var_complete
+);
+
+#if defined(CONFIG_CMD_ASKENV)
+
+U_BOOT_CMD(
+       askenv, CONFIG_SYS_MAXARGS,     1,      do_env_ask,
+       "get environment variables from stdin",
+       "name [message] [size]\n"
+       "    - get environment variable 'name' from stdin (max 'size' chars)"
+);
+#endif
+
+#if defined(CONFIG_CMD_RUN)
+U_BOOT_CMD_COMPLETE(
+       run,    CONFIG_SYS_MAXARGS,     1,      do_run,
+       "run commands in an environment variable",
+       "var [...]\n"
+       "    - run the commands in the environment variable(s) 'var'",
+       var_complete
+);
+#endif
+#endif /* CONFIG_SPL_BUILD */
diff --git a/cmd/onenand.c b/cmd/onenand.c
new file mode 100644 (file)
index 0000000..feab01a
--- /dev/null
@@ -0,0 +1,595 @@
+/*
+ *  U-Boot command for OneNAND support
+ *
+ *  Copyright (C) 2005-2008 Samsung Electronics
+ *  Kyungmin Park <kyungmin.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+
+#include <linux/compat.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/onenand.h>
+
+#include <asm/io.h>
+
+static struct mtd_info *mtd;
+
+static loff_t next_ofs;
+static loff_t skip_ofs;
+
+static int arg_off_size_onenand(int argc, char * const argv[], ulong *off,
+                               size_t *size)
+{
+       if (argc >= 1) {
+               if (!(str2long(argv[0], off))) {
+                       printf("'%s' is not a number\n", argv[0]);
+                       return -1;
+               }
+       } else {
+               *off = 0;
+       }
+
+       if (argc >= 2) {
+               if (!(str2long(argv[1], (ulong *)size))) {
+                       printf("'%s' is not a number\n", argv[1]);
+                       return -1;
+               }
+       } else {
+               *size = mtd->size - *off;
+       }
+
+       if ((*off + *size) > mtd->size) {
+               printf("total chip size (0x%llx) exceeded!\n", mtd->size);
+               return -1;
+       }
+
+       if (*size == mtd->size)
+               puts("whole chip\n");
+       else
+               printf("offset 0x%lx, size 0x%x\n", *off, *size);
+
+       return 0;
+}
+
+static int onenand_block_read(loff_t from, size_t len,
+                             size_t *retlen, u_char *buf, int oob)
+{
+       struct onenand_chip *this = mtd->priv;
+       int blocks = (int) len >> this->erase_shift;
+       int blocksize = (1 << this->erase_shift);
+       loff_t ofs = from;
+       struct mtd_oob_ops ops = {
+               .retlen         = 0,
+       };
+       int ret;
+
+       if (oob)
+               ops.ooblen = blocksize;
+       else
+               ops.len = blocksize;
+
+       while (blocks) {
+               ret = mtd_block_isbad(mtd, ofs);
+               if (ret) {
+                       printk("Bad blocks %d at 0x%x\n",
+                              (u32)(ofs >> this->erase_shift), (u32)ofs);
+                       ofs += blocksize;
+                       continue;
+               }
+
+               if (oob)
+                       ops.oobbuf = buf;
+               else
+                       ops.datbuf = buf;
+
+               ops.retlen = 0;
+               ret = mtd_read_oob(mtd, ofs, &ops);
+               if (ret) {
+                       printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
+                       ofs += blocksize;
+                       continue;
+               }
+               ofs += blocksize;
+               buf += blocksize;
+               blocks--;
+               *retlen += ops.retlen;
+       }
+
+       return 0;
+}
+
+static int onenand_write_oneblock_withoob(loff_t to, const u_char * buf,
+                                         size_t *retlen)
+{
+       struct mtd_oob_ops ops = {
+               .len = mtd->writesize,
+               .ooblen = mtd->oobsize,
+               .mode = MTD_OPS_AUTO_OOB,
+       };
+       int page, ret = 0;
+       for (page = 0; page < (mtd->erasesize / mtd->writesize); page ++) {
+               ops.datbuf = (u_char *)buf;
+               buf += mtd->writesize;
+               ops.oobbuf = (u_char *)buf;
+               buf += mtd->oobsize;
+               ret = mtd_write_oob(mtd, to, &ops);
+               if (ret)
+                       break;
+               to += mtd->writesize;
+       }
+
+       *retlen = (ret) ? 0 : mtd->erasesize;
+       return ret;
+}
+
+static int onenand_block_write(loff_t to, size_t len,
+                              size_t *retlen, const u_char * buf, int withoob)
+{
+       struct onenand_chip *this = mtd->priv;
+       int blocks = len >> this->erase_shift;
+       int blocksize = (1 << this->erase_shift);
+       loff_t ofs;
+       size_t _retlen = 0;
+       int ret;
+
+       if (to == next_ofs) {
+               next_ofs = to + len;
+               to += skip_ofs;
+       } else {
+               next_ofs = to + len;
+               skip_ofs = 0;
+       }
+       ofs = to;
+
+       while (blocks) {
+               ret = mtd_block_isbad(mtd, ofs);
+               if (ret) {
+                       printk("Bad blocks %d at 0x%x\n",
+                              (u32)(ofs >> this->erase_shift), (u32)ofs);
+                       skip_ofs += blocksize;
+                       goto next;
+               }
+
+               if (!withoob)
+                       ret = mtd_write(mtd, ofs, blocksize, &_retlen, buf);
+               else
+                       ret = onenand_write_oneblock_withoob(ofs, buf, &_retlen);
+               if (ret) {
+                       printk("Write failed 0x%x, %d", (u32)ofs, ret);
+                       skip_ofs += blocksize;
+                       goto next;
+               }
+
+               buf += blocksize;
+               blocks--;
+               *retlen += _retlen;
+next:
+               ofs += blocksize;
+       }
+
+       return 0;
+}
+
+static int onenand_block_erase(u32 start, u32 size, int force)
+{
+       struct onenand_chip *this = mtd->priv;
+       struct erase_info instr = {
+               .callback       = NULL,
+       };
+       loff_t ofs;
+       int ret;
+       int blocksize = 1 << this->erase_shift;
+
+       for (ofs = start; ofs < (start + size); ofs += blocksize) {
+               ret = mtd_block_isbad(mtd, ofs);
+               if (ret && !force) {
+                       printf("Skip erase bad block %d at 0x%x\n",
+                              (u32)(ofs >> this->erase_shift), (u32)ofs);
+                       continue;
+               }
+
+               instr.addr = ofs;
+               instr.len = blocksize;
+               instr.priv = force;
+               instr.mtd = mtd;
+               ret = mtd_erase(mtd, &instr);
+               if (ret) {
+                       printf("erase failed block %d at 0x%x\n",
+                              (u32)(ofs >> this->erase_shift), (u32)ofs);
+                       continue;
+               }
+       }
+
+       return 0;
+}
+
+static int onenand_block_test(u32 start, u32 size)
+{
+       struct onenand_chip *this = mtd->priv;
+       struct erase_info instr = {
+               .callback       = NULL,
+               .priv           = 0,
+       };
+
+       int blocks;
+       loff_t ofs;
+       int blocksize = 1 << this->erase_shift;
+       int start_block, end_block;
+       size_t retlen;
+       u_char *buf;
+       u_char *verify_buf;
+       int ret;
+
+       buf = malloc(blocksize);
+       if (!buf) {
+               printf("Not enough malloc space available!\n");
+               return -1;
+       }
+
+       verify_buf = malloc(blocksize);
+       if (!verify_buf) {
+               printf("Not enough malloc space available!\n");
+               return -1;
+       }
+
+       start_block = start >> this->erase_shift;
+       end_block = (start + size) >> this->erase_shift;
+
+       /* Protect boot-loader from badblock testing */
+       if (start_block < 2)
+               start_block = 2;
+
+       if (end_block > (mtd->size >> this->erase_shift))
+               end_block = mtd->size >> this->erase_shift;
+
+       blocks = start_block;
+       ofs = start;
+       while (blocks < end_block) {
+               printf("\rTesting block %d at 0x%x", (u32)(ofs >> this->erase_shift), (u32)ofs);
+
+               ret = mtd_block_isbad(mtd, ofs);
+               if (ret) {
+                       printf("Skip erase bad block %d at 0x%x\n",
+                              (u32)(ofs >> this->erase_shift), (u32)ofs);
+                       goto next;
+               }
+
+               instr.addr = ofs;
+               instr.len = blocksize;
+               ret = mtd_erase(mtd, &instr);
+               if (ret) {
+                       printk("Erase failed 0x%x, %d\n", (u32)ofs, ret);
+                       goto next;
+               }
+
+               ret = mtd_write(mtd, ofs, blocksize, &retlen, buf);
+               if (ret) {
+                       printk("Write failed 0x%x, %d\n", (u32)ofs, ret);
+                       goto next;
+               }
+
+               ret = mtd_read(mtd, ofs, blocksize, &retlen, verify_buf);
+               if (ret) {
+                       printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
+                       goto next;
+               }
+
+               if (memcmp(buf, verify_buf, blocksize))
+                       printk("\nRead/Write test failed at 0x%x\n", (u32)ofs);
+
+next:
+               ofs += blocksize;
+               blocks++;
+       }
+       printf("...Done\n");
+
+       free(buf);
+       free(verify_buf);
+
+       return 0;
+}
+
+static int onenand_dump(struct mtd_info *mtd, ulong off, int only_oob)
+{
+       int i;
+       u_char *datbuf, *oobbuf, *p;
+       struct mtd_oob_ops ops;
+       loff_t addr;
+
+       datbuf = malloc(mtd->writesize + mtd->oobsize);
+       oobbuf = malloc(mtd->oobsize);
+       if (!datbuf || !oobbuf) {
+               puts("No memory for page buffer\n");
+               return 1;
+       }
+       off &= ~(mtd->writesize - 1);
+       addr = (loff_t) off;
+       memset(&ops, 0, sizeof(ops));
+       ops.datbuf = datbuf;
+       ops.oobbuf = oobbuf;
+       ops.len = mtd->writesize;
+       ops.ooblen = mtd->oobsize;
+       ops.retlen = 0;
+       i = mtd_read_oob(mtd, addr, &ops);
+       if (i < 0) {
+               printf("Error (%d) reading page %08lx\n", i, off);
+               free(datbuf);
+               free(oobbuf);
+               return 1;
+       }
+       printf("Page %08lx dump:\n", off);
+       i = mtd->writesize >> 4;
+       p = datbuf;
+
+       while (i--) {
+               if (!only_oob)
+                       printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
+                              "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                              p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
+                              p[8], p[9], p[10], p[11], p[12], p[13], p[14],
+                              p[15]);
+               p += 16;
+       }
+       puts("OOB:\n");
+       i = mtd->oobsize >> 3;
+       p = oobbuf;
+
+       while (i--) {
+               printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
+                      p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+               p += 8;
+       }
+       free(datbuf);
+       free(oobbuf);
+
+       return 0;
+}
+
+static int do_onenand_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       printf("%s\n", mtd->name);
+       return 0;
+}
+
+static int do_onenand_bad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong ofs;
+
+       mtd = &onenand_mtd;
+       /* Currently only one OneNAND device is supported */
+       printf("\nDevice %d bad blocks:\n", 0);
+       for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) {
+               if (mtd_block_isbad(mtd, ofs))
+                       printf("  %08x\n", (u32)ofs);
+       }
+
+       return 0;
+}
+
+static int do_onenand_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       char *s;
+       int oob = 0;
+       ulong addr, ofs;
+       size_t len;
+       int ret = 0;
+       size_t retlen = 0;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       s = strchr(argv[0], '.');
+       if ((s != NULL) && (!strcmp(s, ".oob")))
+               oob = 1;
+
+       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
+
+       printf("\nOneNAND read: ");
+       if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0)
+               return 1;
+
+       ret = onenand_block_read(ofs, len, &retlen, (u8 *)addr, oob);
+
+       printf(" %d bytes read: %s\n", retlen, ret ? "ERROR" : "OK");
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_onenand_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr, ofs;
+       size_t len;
+       int ret = 0, withoob = 0;
+       size_t retlen = 0;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       if (strncmp(argv[0] + 6, "yaffs", 5) == 0)
+               withoob = 1;
+
+       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
+
+       printf("\nOneNAND write: ");
+       if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0)
+               return 1;
+
+       ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr, withoob);
+
+       printf(" %d bytes written: %s\n", retlen, ret ? "ERROR" : "OK");
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_onenand_erase(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong ofs;
+       int ret = 0;
+       size_t len;
+       int force;
+
+       /*
+        * Syntax is:
+        *   0       1     2       3    4
+        *   onenand erase [force] [off size]
+        */
+       argc--;
+       argv++;
+       if (argc)
+       {
+               if (!strcmp("force", argv[0]))
+               {
+                       force = 1;
+                       argc--;
+                       argv++;
+               }
+       }
+       printf("\nOneNAND erase: ");
+
+       /* skip first two or three arguments, look for offset and size */
+       if (arg_off_size_onenand(argc, argv, &ofs, &len) != 0)
+               return 1;
+
+       ret = onenand_block_erase(ofs, len, force);
+
+       printf("%s\n", ret ? "ERROR" : "OK");
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_onenand_test(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong ofs;
+       int ret = 0;
+       size_t len;
+
+       /*
+        * Syntax is:
+        *   0       1     2       3    4
+        *   onenand test [force] [off size]
+        */
+
+       printf("\nOneNAND test: ");
+
+       /* skip first two or three arguments, look for offset and size */
+       if (arg_off_size_onenand(argc - 1, argv + 1, &ofs, &len) != 0)
+               return 1;
+
+       ret = onenand_block_test(ofs, len);
+
+       printf("%s\n", ret ? "ERROR" : "OK");
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_onenand_dump(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong ofs;
+       int ret = 0;
+       char *s;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       s = strchr(argv[0], '.');
+       ofs = (int)simple_strtoul(argv[1], NULL, 16);
+
+       if (s != NULL && strcmp(s, ".oob") == 0)
+               ret = onenand_dump(mtd, ofs, 1);
+       else
+               ret = onenand_dump(mtd, ofs, 0);
+
+       return ret == 0 ? 1 : 0;
+}
+
+static int do_onenand_markbad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret = 0;
+       ulong addr;
+
+       argc -= 2;
+       argv += 2;
+
+       if (argc <= 0)
+               return CMD_RET_USAGE;
+
+       while (argc > 0) {
+               addr = simple_strtoul(*argv, NULL, 16);
+
+               if (mtd_block_markbad(mtd, addr)) {
+                       printf("block 0x%08lx NOT marked "
+                               "as bad! ERROR %d\n",
+                               addr, ret);
+                       ret = 1;
+               } else {
+                       printf("block 0x%08lx successfully "
+                               "marked as bad\n",
+                               addr);
+               }
+               --argc;
+               ++argv;
+       }
+       return ret;
+}
+
+static cmd_tbl_t cmd_onenand_sub[] = {
+       U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", ""),
+       U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""),
+       U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""),
+       U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", ""),
+       U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""),
+       U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""),
+       U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""),
+       U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad, "", ""),
+};
+
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+void onenand_reloc(void) {
+       fixup_cmdtable(cmd_onenand_sub, ARRAY_SIZE(cmd_onenand_sub));
+}
+#endif
+
+static int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *c;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       mtd = &onenand_mtd;
+
+       /* Strip off leading 'onenand' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_onenand_sub[0], ARRAY_SIZE(cmd_onenand_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       onenand,        CONFIG_SYS_MAXARGS,     1,      do_onenand,
+       "OneNAND sub-system",
+       "info - show available OneNAND devices\n"
+       "onenand bad - show bad blocks\n"
+       "onenand read[.oob] addr off size\n"
+       "onenand write[.yaffs] addr off size\n"
+       "    read/write 'size' bytes starting at offset 'off'\n"
+       "    to/from memory address 'addr', skipping bad blocks.\n"
+       "onenand erase [force] [off size] - erase 'size' bytes from\n"
+       "onenand test [off size] - test 'size' bytes from\n"
+       "    offset 'off' (entire device if not specified)\n"
+       "onenand dump[.oob] off - dump page\n"
+       "onenand markbad off [...] - mark bad block(s) at offset (UNSAFE)"
+);
diff --git a/cmd/otp.c b/cmd/otp.c
new file mode 100644 (file)
index 0000000..10c1475
--- /dev/null
+++ b/cmd/otp.c
@@ -0,0 +1,228 @@
+/*
+ * cmd_otp.c - interface to Blackfin on-chip One-Time-Programmable memory
+ *
+ * Copyright (c) 2007-2008 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+/* There are 512 128-bit "pages" (0x000 through 0x1FF).
+ * The pages are accessable as 64-bit "halfpages" (an upper and lower half).
+ * The pages are not part of the memory map.  There is an OTP controller which
+ * handles scanning in/out of bits.  While access is done through OTP MMRs,
+ * the bootrom provides C-callable helper functions to handle the interaction.
+ */
+
+#include <config.h>
+#include <common.h>
+#include <command.h>
+#include <console.h>
+
+#include <asm/blackfin.h>
+#include <asm/clock.h>
+#include <asm/mach-common/bits/otp.h>
+
+static const char *otp_strerror(uint32_t err)
+{
+       switch (err) {
+       case 0:                   return "no error";
+       case OTP_WRITE_ERROR:     return "OTP fuse write error";
+       case OTP_READ_ERROR:      return "OTP fuse read error";
+       case OTP_ACC_VIO_ERROR:   return "invalid OTP address";
+       case OTP_DATA_MULT_ERROR: return "multiple bad bits detected";
+       case OTP_ECC_MULT_ERROR:  return "error in ECC bits";
+       case OTP_PREV_WR_ERROR:   return "space already written";
+       case OTP_DATA_SB_WARN:    return "single bad bit in half page";
+       case OTP_ECC_SB_WARN:     return "single bad bit in ECC";
+       default:                  return "unknown error";
+       }
+}
+
+#define lowup(x) ((x) % 2 ? "upper" : "lower")
+
+static int check_voltage(void)
+{
+       /* Make sure voltage limits are within datasheet spec */
+       uint16_t vr_ctl = bfin_read_VR_CTL();
+
+#ifdef __ADSPBF54x__
+       /* 0.9V <= VDDINT <= 1.1V */
+       if ((vr_ctl & 0xc) && (vr_ctl & 0xc0) == 0xc0)
+               return 1;
+#else
+       /* for the parts w/out qualification yet */
+       (void)vr_ctl;
+#endif
+
+       return 0;
+}
+
+static void set_otp_timing(bool write)
+{
+       static uint32_t timing;
+       if (!timing) {
+               uint32_t tp1, tp2, tp3;
+               /* OTP_TP1 = 1000 / sclk_period (in nanoseconds)
+                * OTP_TP1 = 1000 / (1 / get_sclk() * 10^9)
+                * OTP_TP1 = (1000 * get_sclk()) / 10^9
+                * OTP_TP1 = get_sclk() / 10^6
+                */
+               tp1 = get_sclk() / 1000000;
+               /* OTP_TP2 = 400 / (2 * sclk_period)
+                * OTP_TP2 = 400 / (2 * 1 / get_sclk() * 10^9)
+                * OTP_TP2 = (400 * get_sclk()) / (2 * 10^9)
+                * OTP_TP2 = (2 * get_sclk()) / 10^7
+                */
+               tp2 = (2 * get_sclk() / 10000000) << 8;
+               /* OTP_TP3 = magic constant */
+               tp3 = (0x1401) << 15;
+               timing = tp1 | tp2 | tp3;
+       }
+
+       bfrom_OtpCommand(OTP_INIT, write ? timing : timing & ~(-1 << 15));
+}
+
+int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *cmd;
+       uint32_t ret, base_flags;
+       bool prompt_user, force_read;
+       uint32_t (*otp_func)(uint32_t page, uint32_t flags, uint64_t *page_content);
+
+       if (argc < 4) {
+ usage:
+               return CMD_RET_USAGE;
+       }
+
+       prompt_user = false;
+       base_flags = 0;
+       cmd = argv[1];
+       if (!strcmp(cmd, "read"))
+               otp_func = bfrom_OtpRead;
+       else if (!strcmp(cmd, "dump")) {
+               otp_func = bfrom_OtpRead;
+               force_read = true;
+       } else if (!strcmp(cmd, "write")) {
+               otp_func = bfrom_OtpWrite;
+               base_flags = OTP_CHECK_FOR_PREV_WRITE;
+               if (!strcmp(argv[2], "--force")) {
+                       argv++;
+                       --argc;
+               } else
+                       prompt_user = false;
+       } else if (!strcmp(cmd, "lock")) {
+               if (argc != 4)
+                       goto usage;
+               otp_func = bfrom_OtpWrite;
+               base_flags = OTP_LOCK;
+       } else
+               goto usage;
+
+       uint64_t *addr = (uint64_t *)simple_strtoul(argv[2], NULL, 16);
+       uint32_t page = simple_strtoul(argv[3], NULL, 16);
+       uint32_t flags;
+       size_t i, count;
+       ulong half;
+
+       if (argc > 4)
+               count = simple_strtoul(argv[4], NULL, 16);
+       else
+               count = 2;
+
+       if (argc > 5) {
+               half = simple_strtoul(argv[5], NULL, 16);
+               if (half != 0 && half != 1) {
+                       puts("Error: 'half' can only be '0' or '1'\n");
+                       goto usage;
+               }
+       } else
+               half = 0;
+
+       /* "otp lock" has slightly different semantics */
+       if (base_flags & OTP_LOCK) {
+               count = page;
+               page = (uint32_t)addr;
+               addr = NULL;
+       }
+
+       /* do to the nature of OTP, make sure users are sure */
+       if (prompt_user) {
+               printf(
+                       "Writing one time programmable memory\n"
+                       "Make sure your operating voltages and temperature are within spec\n"
+                       "   source address:  0x%p\n"
+                       "   OTP destination: %s page 0x%03X - %s page 0x%03lX\n"
+                       "   number to write: %lu halfpages\n"
+                       " type \"YES\" (no quotes) to confirm: ",
+                       addr,
+                       lowup(half), page,
+                       lowup(half + count - 1), page + (half + count - 1) / 2,
+                       half + count
+               );
+               if (!confirm_yesno()) {
+                       printf(" Aborting\n");
+                       return 1;
+               }
+       }
+
+       printf("OTP memory %s: addr 0x%p  page 0x%03X  count %zu ... ",
+               cmd, addr, page, count);
+
+       set_otp_timing(otp_func == bfrom_OtpWrite);
+       if (otp_func == bfrom_OtpWrite && check_voltage()) {
+               puts("ERROR: VDDINT voltage is out of spec for writing\n");
+               return -1;
+       }
+
+       /* Do the actual reading/writing stuff */
+       ret = 0;
+       for (i = half; i < count + half; ++i) {
+               flags = base_flags | (i % 2 ? OTP_UPPER_HALF : OTP_LOWER_HALF);
+ try_again:
+               ret = otp_func(page, flags, addr);
+               if (ret & OTP_MASTER_ERROR) {
+                       if (force_read) {
+                               if (flags & OTP_NO_ECC)
+                                       break;
+                               else
+                                       flags |= OTP_NO_ECC;
+                               puts("E");
+                               goto try_again;
+                       } else
+                               break;
+               } else if (ret)
+                       puts("W");
+               else
+                       puts(".");
+               if (!(base_flags & OTP_LOCK)) {
+                       ++addr;
+                       if (i % 2)
+                               ++page;
+               } else
+                       ++page;
+       }
+       if (ret & 0x1)
+               printf("\nERROR at page 0x%03X (%s-halfpage): 0x%03X: %s\n",
+                       page, lowup(i), ret, otp_strerror(ret));
+       else
+               puts(" done\n");
+
+       /* Make sure we disable writing */
+       set_otp_timing(false);
+       bfrom_OtpCommand(OTP_CLOSE, 0);
+
+       return ret;
+}
+
+U_BOOT_CMD(
+       otp, 7, 0, do_otp,
+       "One-Time-Programmable sub-system",
+       "read <addr> <page> [count] [half]\n"
+       " - read 'count' half-pages starting at 'page' (offset 'half') to 'addr'\n"
+       "otp dump <addr> <page> [count] [half]\n"
+       " - like 'otp read', but skip read errors\n"
+       "otp write [--force] <addr> <page> [count] [half]\n"
+       " - write 'count' half-pages starting at 'page' (offset 'half') from 'addr'\n"
+       "otp lock <page> <count>\n"
+       " - lock 'count' pages starting at 'page'"
+);
diff --git a/cmd/part.c b/cmd/part.c
new file mode 100644 (file)
index 0000000..5599509
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * made from cmd_ext2, which was:
+ *
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <part.h>
+#include <vsprintf.h>
+
+#ifndef CONFIG_PARTITION_UUIDS
+#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
+#endif
+
+static int do_part_uuid(int argc, char * const argv[])
+{
+       int part;
+       block_dev_desc_t *dev_desc;
+       disk_partition_t info;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+       if (argc > 3)
+               return CMD_RET_USAGE;
+
+       part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
+       if (part < 0)
+               return 1;
+
+       if (argc > 2)
+               setenv(argv[2], info.uuid);
+       else
+               printf("%s\n", info.uuid);
+
+       return 0;
+}
+
+static int do_part_list(int argc, char * const argv[])
+{
+       int ret;
+       block_dev_desc_t *desc;
+       char *var = NULL;
+       bool bootable = false;
+       int i;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (argc > 2) {
+               for (i = 2; i < argc ; i++) {
+                       if (argv[i][0] == '-') {
+                               if (!strcmp(argv[i], "-bootable")) {
+                                       bootable = true;
+                               } else {
+                                       printf("Unknown option %s\n", argv[i]);
+                                       return CMD_RET_USAGE;
+                               }
+                       } else {
+                               var = argv[i];
+                               break;
+                       }
+               }
+
+               /* Loops should have been exited at the last argument, which
+                * as it contained the variable */
+               if (argc != i + 1)
+                       return CMD_RET_USAGE;
+       }
+
+       ret = get_device(argv[0], argv[1], &desc);
+       if (ret < 0)
+               return 1;
+
+       if (var != NULL) {
+               int p;
+               char str[512] = { '\0', };
+               disk_partition_t info;
+
+               for (p = 1; p < 128; p++) {
+                       char t[5];
+                       int r = get_partition_info(desc, p, &info);
+
+                       if (r != 0)
+                               continue;
+
+                       if (bootable && !info.bootable)
+                               continue;
+
+                       sprintf(t, "%s%x", str[0] ? " " : "", p);
+                       strcat(str, t);
+               }
+               setenv(var, str);
+               return 0;
+       }
+
+       print_part(desc);
+
+       return 0;
+}
+
+static int do_part_start(int argc, char * const argv[])
+{
+       block_dev_desc_t *desc;
+       disk_partition_t info;
+       char buf[512] = { 0 };
+       int part;
+       int err;
+       int ret;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+       if (argc > 4)
+               return CMD_RET_USAGE;
+
+       part = simple_strtoul(argv[2], NULL, 0);
+
+       ret = get_device(argv[0], argv[1], &desc);
+       if (ret < 0)
+               return 1;
+
+       err = get_partition_info(desc, part, &info);
+       if (err)
+               return 1;
+
+       snprintf(buf, sizeof(buf), LBAF, info.start);
+
+       if (argc > 3)
+               setenv(argv[3], buf);
+       else
+               printf("%s\n", buf);
+
+       return 0;
+}
+
+static int do_part_size(int argc, char * const argv[])
+{
+       block_dev_desc_t *desc;
+       disk_partition_t info;
+       char buf[512] = { 0 };
+       int part;
+       int err;
+       int ret;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+       if (argc > 4)
+               return CMD_RET_USAGE;
+
+       part = simple_strtoul(argv[2], NULL, 0);
+
+       ret = get_device(argv[0], argv[1], &desc);
+       if (ret < 0)
+               return 1;
+
+       err = get_partition_info(desc, part, &info);
+       if (err)
+               return 1;
+
+       snprintf(buf, sizeof(buf), LBAF, info.size);
+
+       if (argc > 3)
+               setenv(argv[3], buf);
+       else
+               printf("%s\n", buf);
+
+       return 0;
+}
+
+static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (!strcmp(argv[1], "uuid"))
+               return do_part_uuid(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "list"))
+               return do_part_list(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "start"))
+               return do_part_start(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "size"))
+               return do_part_size(argc - 2, argv + 2);
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       part,   CONFIG_SYS_MAXARGS,     1,      do_part,
+       "disk partition related commands",
+       "uuid <interface> <dev>:<part>\n"
+       "    - print partition UUID\n"
+       "part uuid <interface> <dev>:<part> <varname>\n"
+       "    - set environment variable to partition UUID\n"
+       "part list <interface> <dev>\n"
+       "    - print a device's partition table\n"
+       "part list <interface> <dev> [flags] <varname>\n"
+       "    - set environment variable to the list of partitions\n"
+       "      flags can be -bootable (list only bootable partitions)\n"
+       "part start <interface> <dev> <part> <varname>\n"
+       "    - set environment variable to the start of the partition (in blocks)\n"
+       "part size <interface> <dev> <part> <varname>\n"
+       "    - set environment variable to the size of the partition (in blocks)"
+);
diff --git a/cmd/pci.c b/cmd/pci.c
new file mode 100644 (file)
index 0000000..8094d33
--- /dev/null
+++ b/cmd/pci.c
@@ -0,0 +1,687 @@
+/*
+ * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Andreas Heppel <aheppel@sysgo.de>
+ *
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * PCI routines
+ */
+
+#include <common.h>
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <dm.h>
+#include <asm/processor.h>
+#include <asm/io.h>
+#include <pci.h>
+
+struct pci_reg_info {
+       const char *name;
+       enum pci_size_t size;
+       u8 offset;
+};
+
+static int pci_byte_size(enum pci_size_t size)
+{
+       switch (size) {
+       case PCI_SIZE_8:
+               return 1;
+       case PCI_SIZE_16:
+               return 2;
+       case PCI_SIZE_32:
+       default:
+               return 4;
+       }
+}
+
+static int pci_field_width(enum pci_size_t size)
+{
+       return pci_byte_size(size) * 2;
+}
+
+#ifdef CONFIG_DM_PCI
+static void pci_show_regs(struct udevice *dev, struct pci_reg_info *regs)
+{
+       for (; regs->name; regs++) {
+               unsigned long val;
+
+               dm_pci_read_config(dev, regs->offset, &val, regs->size);
+               printf("  %s =%*s%#.*lx\n", regs->name,
+                      (int)(28 - strlen(regs->name)), "",
+                      pci_field_width(regs->size), val);
+       }
+}
+#else
+static unsigned long pci_read_config(pci_dev_t dev, int offset,
+                                    enum pci_size_t size)
+{
+       u32 val32;
+       u16 val16;
+       u8 val8;
+
+       switch (size) {
+       case PCI_SIZE_8:
+               pci_read_config_byte(dev, offset, &val8);
+               return val8;
+       case PCI_SIZE_16:
+               pci_read_config_word(dev, offset, &val16);
+               return val16;
+       case PCI_SIZE_32:
+       default:
+               pci_read_config_dword(dev, offset, &val32);
+               return val32;
+       }
+}
+
+static void pci_show_regs(pci_dev_t dev, struct pci_reg_info *regs)
+{
+       for (; regs->name; regs++) {
+               printf("  %s =%*s%#.*lx\n", regs->name,
+                      (int)(28 - strlen(regs->name)), "",
+                      pci_field_width(regs->size),
+                      pci_read_config(dev, regs->offset, regs->size));
+       }
+}
+#endif
+
+static struct pci_reg_info regs_start[] = {
+       { "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID },
+       { "device ID", PCI_SIZE_16, PCI_DEVICE_ID },
+       { "command register ID", PCI_SIZE_16, PCI_COMMAND },
+       { "status register", PCI_SIZE_16, PCI_STATUS },
+       { "revision ID", PCI_SIZE_8, PCI_REVISION_ID },
+       {},
+};
+
+static struct pci_reg_info regs_rest[] = {
+       { "sub class code", PCI_SIZE_8, PCI_CLASS_SUB_CODE },
+       { "programming interface", PCI_SIZE_8, PCI_CLASS_PROG },
+       { "cache line", PCI_SIZE_8, PCI_CACHE_LINE_SIZE },
+       { "latency time", PCI_SIZE_8, PCI_LATENCY_TIMER },
+       { "header type", PCI_SIZE_8, PCI_HEADER_TYPE },
+       { "BIST", PCI_SIZE_8, PCI_BIST },
+       { "base address 0", PCI_SIZE_32, PCI_BASE_ADDRESS_0 },
+       {},
+};
+
+static struct pci_reg_info regs_normal[] = {
+       { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
+       { "base address 2", PCI_SIZE_32, PCI_BASE_ADDRESS_2 },
+       { "base address 3", PCI_SIZE_32, PCI_BASE_ADDRESS_3 },
+       { "base address 4", PCI_SIZE_32, PCI_BASE_ADDRESS_4 },
+       { "base address 5", PCI_SIZE_32, PCI_BASE_ADDRESS_5 },
+       { "cardBus CIS pointer", PCI_SIZE_32, PCI_CARDBUS_CIS },
+       { "sub system vendor ID", PCI_SIZE_16, PCI_SUBSYSTEM_VENDOR_ID },
+       { "sub system ID", PCI_SIZE_16, PCI_SUBSYSTEM_ID },
+       { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS },
+       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
+       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
+       { "min Grant", PCI_SIZE_8, PCI_MIN_GNT },
+       { "max Latency", PCI_SIZE_8, PCI_MAX_LAT },
+       {},
+};
+
+static struct pci_reg_info regs_bridge[] = {
+       { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
+       { "primary bus number", PCI_SIZE_8, PCI_PRIMARY_BUS },
+       { "secondary bus number", PCI_SIZE_8, PCI_SECONDARY_BUS },
+       { "subordinate bus number", PCI_SIZE_8, PCI_SUBORDINATE_BUS },
+       { "secondary latency timer", PCI_SIZE_8, PCI_SEC_LATENCY_TIMER },
+       { "IO base", PCI_SIZE_8, PCI_IO_BASE },
+       { "IO limit", PCI_SIZE_8, PCI_IO_LIMIT },
+       { "secondary status", PCI_SIZE_16, PCI_SEC_STATUS },
+       { "memory base", PCI_SIZE_16, PCI_MEMORY_BASE },
+       { "memory limit", PCI_SIZE_16, PCI_MEMORY_LIMIT },
+       { "prefetch memory base", PCI_SIZE_16, PCI_PREF_MEMORY_BASE },
+       { "prefetch memory limit", PCI_SIZE_16, PCI_PREF_MEMORY_LIMIT },
+       { "prefetch memory base upper", PCI_SIZE_32, PCI_PREF_BASE_UPPER32 },
+       { "prefetch memory limit upper", PCI_SIZE_32, PCI_PREF_LIMIT_UPPER32 },
+       { "IO base upper 16 bits", PCI_SIZE_16, PCI_IO_BASE_UPPER16 },
+       { "IO limit upper 16 bits", PCI_SIZE_16, PCI_IO_LIMIT_UPPER16 },
+       { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS1 },
+       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
+       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
+       { "bridge control", PCI_SIZE_16, PCI_BRIDGE_CONTROL },
+       {},
+};
+
+static struct pci_reg_info regs_cardbus[] = {
+       { "capabilities", PCI_SIZE_8, PCI_CB_CAPABILITY_LIST },
+       { "secondary status", PCI_SIZE_16, PCI_CB_SEC_STATUS },
+       { "primary bus number", PCI_SIZE_8, PCI_CB_PRIMARY_BUS },
+       { "CardBus number", PCI_SIZE_8, PCI_CB_CARD_BUS },
+       { "subordinate bus number", PCI_SIZE_8, PCI_CB_SUBORDINATE_BUS },
+       { "CardBus latency timer", PCI_SIZE_8, PCI_CB_LATENCY_TIMER },
+       { "CardBus memory base 0", PCI_SIZE_32, PCI_CB_MEMORY_BASE_0 },
+       { "CardBus memory limit 0", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_0 },
+       { "CardBus memory base 1", PCI_SIZE_32, PCI_CB_MEMORY_BASE_1 },
+       { "CardBus memory limit 1", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_1 },
+       { "CardBus IO base 0", PCI_SIZE_16, PCI_CB_IO_BASE_0 },
+       { "CardBus IO base high 0", PCI_SIZE_16, PCI_CB_IO_BASE_0_HI },
+       { "CardBus IO limit 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0 },
+       { "CardBus IO limit high 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0_HI },
+       { "CardBus IO base 1", PCI_SIZE_16, PCI_CB_IO_BASE_1 },
+       { "CardBus IO base high 1", PCI_SIZE_16, PCI_CB_IO_BASE_1_HI },
+       { "CardBus IO limit 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1 },
+       { "CardBus IO limit high 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1_HI },
+       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
+       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
+       { "bridge control", PCI_SIZE_16, PCI_CB_BRIDGE_CONTROL },
+       { "subvendor ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_VENDOR_ID },
+       { "subdevice ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_ID },
+       { "PC Card 16bit base address", PCI_SIZE_32, PCI_CB_LEGACY_MODE_BASE },
+       {},
+};
+
+/**
+ * pci_header_show() - Show the header of the specified PCI device.
+ *
+ * @dev: Bus+Device+Function number
+ */
+#ifdef CONFIG_DM_PCI
+void pci_header_show(struct udevice *dev)
+#else
+void pci_header_show(pci_dev_t dev)
+#endif
+{
+#ifdef CONFIG_DM_PCI
+       unsigned long class, header_type;
+
+       dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
+       dm_pci_read_config(dev, PCI_HEADER_TYPE, &header_type, PCI_SIZE_8);
+#else
+       u8 class, header_type;
+
+       pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
+       pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
+#endif
+       pci_show_regs(dev, regs_start);
+       printf("  class code =                  0x%.2x (%s)\n", (int)class,
+              pci_class_str(class));
+       pci_show_regs(dev, regs_rest);
+
+       switch (header_type & 0x03) {
+       case PCI_HEADER_TYPE_NORMAL:    /* "normal" PCI device */
+               pci_show_regs(dev, regs_normal);
+               break;
+       case PCI_HEADER_TYPE_BRIDGE:    /* PCI-to-PCI bridge */
+               pci_show_regs(dev, regs_bridge);
+               break;
+       case PCI_HEADER_TYPE_CARDBUS:   /* PCI-to-CardBus bridge */
+               pci_show_regs(dev, regs_cardbus);
+               break;
+
+       default:
+               printf("unknown header\n");
+               break;
+    }
+}
+
+void pciinfo_header(int busnum, bool short_listing)
+{
+       printf("Scanning PCI devices on bus %d\n", busnum);
+
+       if (short_listing) {
+               printf("BusDevFun  VendorId   DeviceId   Device Class       Sub-Class\n");
+               printf("_____________________________________________________________\n");
+       }
+}
+
+#ifdef CONFIG_DM_PCI
+/**
+ * pci_header_show_brief() - Show the short-form PCI device header
+ *
+ * Reads and prints the header of the specified PCI device in short form.
+ *
+ * @dev: PCI device to show
+ */
+static void pci_header_show_brief(struct udevice *dev)
+{
+       ulong vendor, device;
+       ulong class, subclass;
+
+       dm_pci_read_config(dev, PCI_VENDOR_ID, &vendor, PCI_SIZE_16);
+       dm_pci_read_config(dev, PCI_DEVICE_ID, &device, PCI_SIZE_16);
+       dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
+       dm_pci_read_config(dev, PCI_CLASS_SUB_CODE, &subclass, PCI_SIZE_8);
+
+       printf("0x%.4lx     0x%.4lx     %-23s 0x%.2lx\n",
+              vendor, device,
+              pci_class_str(class), subclass);
+}
+
+static void pciinfo(struct udevice *bus, bool short_listing)
+{
+       struct udevice *dev;
+
+       pciinfo_header(bus->seq, short_listing);
+
+       for (device_find_first_child(bus, &dev);
+            dev;
+            device_find_next_child(&dev)) {
+               struct pci_child_platdata *pplat;
+
+               pplat = dev_get_parent_platdata(dev);
+               if (short_listing) {
+                       printf("%02x.%02x.%02x   ", bus->seq,
+                              PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
+                       pci_header_show_brief(dev);
+               } else {
+                       printf("\nFound PCI device %02x.%02x.%02x:\n", bus->seq,
+                              PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
+                       pci_header_show(dev);
+               }
+       }
+}
+
+#else
+
+/**
+ * pci_header_show_brief() - Show the short-form PCI device header
+ *
+ * Reads and prints the header of the specified PCI device in short form.
+ *
+ * @dev: Bus+Device+Function number
+ */
+void pci_header_show_brief(pci_dev_t dev)
+{
+       u16 vendor, device;
+       u8 class, subclass;
+
+       pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
+       pci_read_config_word(dev, PCI_DEVICE_ID, &device);
+       pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
+       pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass);
+
+       printf("0x%.4x     0x%.4x     %-23s 0x%.2x\n",
+              vendor, device,
+              pci_class_str(class), subclass);
+}
+
+/**
+ * pciinfo() - Show a list of devices on the PCI bus
+ *
+ * Show information about devices on PCI bus. Depending on @short_pci_listing
+ * the output will be more or less exhaustive.
+ *
+ * @bus_num: The number of the bus to be scanned
+ * @short_pci_listing: true to use short form, showing only a brief header
+ * for each device
+ */
+void pciinfo(int bus_num, int short_pci_listing)
+{
+       struct pci_controller *hose = pci_bus_to_hose(bus_num);
+       int device;
+       int function;
+       unsigned char header_type;
+       unsigned short vendor_id;
+       pci_dev_t dev;
+       int ret;
+
+       if (!hose)
+               return;
+
+       pciinfo_header(bus_num, short_pci_listing);
+
+       for (device = 0; device < PCI_MAX_PCI_DEVICES; device++) {
+               header_type = 0;
+               vendor_id = 0;
+               for (function = 0; function < PCI_MAX_PCI_FUNCTIONS;
+                    function++) {
+                       /*
+                        * If this is not a multi-function device, we skip
+                        * the rest.
+                        */
+                       if (function && !(header_type & 0x80))
+                               break;
+
+                       dev = PCI_BDF(bus_num, device, function);
+
+                       if (pci_skip_dev(hose, dev))
+                               continue;
+
+                       ret = pci_read_config_word(dev, PCI_VENDOR_ID,
+                                                  &vendor_id);
+                       if (ret)
+                               goto error;
+                       if ((vendor_id == 0xFFFF) || (vendor_id == 0x0000))
+                               continue;
+
+                       if (!function) {
+                               pci_read_config_byte(dev, PCI_HEADER_TYPE,
+                                                    &header_type);
+                       }
+
+                       if (short_pci_listing) {
+                               printf("%02x.%02x.%02x   ", bus_num, device,
+                                      function);
+                               pci_header_show_brief(dev);
+                       } else {
+                               printf("\nFound PCI device %02x.%02x.%02x:\n",
+                                      bus_num, device, function);
+                               pci_header_show(dev);
+                       }
+               }
+       }
+
+       return;
+error:
+       printf("Cannot read bus configuration: %d\n", ret);
+}
+#endif
+
+/**
+ * get_pci_dev() - Convert the "bus.device.function" identifier into a number
+ *
+ * @name: Device string in the form "bus.device.function" where each is in hex
+ * @return encoded pci_dev_t or -1 if the string was invalid
+ */
+static pci_dev_t get_pci_dev(char *name)
+{
+       char cnum[12];
+       int len, i, iold, n;
+       int bdfs[3] = {0,0,0};
+
+       len = strlen(name);
+       if (len > 8)
+               return -1;
+       for (i = 0, iold = 0, n = 0; i < len; i++) {
+               if (name[i] == '.') {
+                       memcpy(cnum, &name[iold], i - iold);
+                       cnum[i - iold] = '\0';
+                       bdfs[n++] = simple_strtoul(cnum, NULL, 16);
+                       iold = i + 1;
+               }
+       }
+       strcpy(cnum, &name[iold]);
+       if (n == 0)
+               n = 1;
+       bdfs[n] = simple_strtoul(cnum, NULL, 16);
+
+       return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
+}
+
+#ifdef CONFIG_DM_PCI
+static int pci_cfg_display(struct udevice *dev, ulong addr,
+                          enum pci_size_t size, ulong length)
+#else
+static int pci_cfg_display(pci_dev_t bdf, ulong addr, enum pci_size_t size,
+                          ulong length)
+#endif
+{
+#define DISP_LINE_LEN  16
+       ulong i, nbytes, linebytes;
+       int byte_size;
+       int rc = 0;
+
+       byte_size = pci_byte_size(size);
+       if (length == 0)
+               length = 0x40 / byte_size; /* Standard PCI config space */
+
+       /* Print the lines.
+        * once, and all accesses are with the specified bus width.
+        */
+       nbytes = length * byte_size;
+       do {
+               printf("%08lx:", addr);
+               linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
+               for (i = 0; i < linebytes; i += byte_size) {
+                       unsigned long val;
+
+#ifdef CONFIG_DM_PCI
+                       dm_pci_read_config(dev, addr, &val, size);
+#else
+                       val = pci_read_config(bdf, addr, size);
+#endif
+                       printf(" %0*lx", pci_field_width(size), val);
+                       addr += byte_size;
+               }
+               printf("\n");
+               nbytes -= linebytes;
+               if (ctrlc()) {
+                       rc = 1;
+                       break;
+               }
+       } while (nbytes > 0);
+
+       return (rc);
+}
+
+#ifndef CONFIG_DM_PCI
+static int pci_cfg_write (pci_dev_t bdf, ulong addr, ulong size, ulong value)
+{
+       if (size == 4) {
+               pci_write_config_dword(bdf, addr, value);
+       }
+       else if (size == 2) {
+               ushort val = value & 0xffff;
+               pci_write_config_word(bdf, addr, val);
+       }
+       else {
+               u_char val = value & 0xff;
+               pci_write_config_byte(bdf, addr, val);
+       }
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_DM_PCI
+static int pci_cfg_modify(struct udevice *dev, ulong addr, ulong size,
+                         ulong value, int incrflag)
+#else
+static int pci_cfg_modify(pci_dev_t bdf, ulong addr, ulong size, ulong value,
+                         int incrflag)
+#endif
+{
+       ulong   i;
+       int     nbytes;
+       ulong val;
+
+       /* Print the address, followed by value.  Then accept input for
+        * the next value.  A non-converted value exits.
+        */
+       do {
+               printf("%08lx:", addr);
+#ifdef CONFIG_DM_PCI
+               dm_pci_read_config(dev, addr, &val, size);
+#else
+               val = pci_read_config(bdf, addr, size);
+#endif
+               printf(" %0*lx", pci_field_width(size), val);
+
+               nbytes = cli_readline(" ? ");
+               if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
+                       /* <CR> pressed as only input, don't modify current
+                        * location and move to next. "-" pressed will go back.
+                        */
+                       if (incrflag)
+                               addr += nbytes ? -size : size;
+                       nbytes = 1;
+                       /* good enough to not time out */
+                       bootretry_reset_cmd_timeout();
+               }
+#ifdef CONFIG_BOOT_RETRY_TIME
+               else if (nbytes == -2) {
+                       break;  /* timed out, exit the command  */
+               }
+#endif
+               else {
+                       char *endp;
+                       i = simple_strtoul(console_buffer, &endp, 16);
+                       nbytes = endp - console_buffer;
+                       if (nbytes) {
+                               /* good enough to not time out
+                                */
+                               bootretry_reset_cmd_timeout();
+#ifdef CONFIG_DM_PCI
+                               dm_pci_write_config(dev, addr, i, size);
+#else
+                               pci_cfg_write(bdf, addr, size, i);
+#endif
+                               if (incrflag)
+                                       addr += size;
+                       }
+               }
+       } while (nbytes);
+
+       return 0;
+}
+
+/* PCI Configuration Space access commands
+ *
+ * Syntax:
+ *     pci display[.b, .w, .l] bus.device.function} [addr] [len]
+ *     pci next[.b, .w, .l] bus.device.function [addr]
+ *      pci modify[.b, .w, .l] bus.device.function [addr]
+ *      pci write[.b, .w, .l] bus.device.function addr value
+ */
+static int do_pci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr = 0, value = 0, cmd_size = 0;
+       enum pci_size_t size = PCI_SIZE_32;
+#ifdef CONFIG_DM_PCI
+       struct udevice *dev, *bus;
+#else
+       pci_dev_t dev;
+#endif
+       int busnum = 0;
+       pci_dev_t bdf = 0;
+       char cmd = 's';
+       int ret = 0;
+
+       if (argc > 1)
+               cmd = argv[1][0];
+
+       switch (cmd) {
+       case 'd':               /* display */
+       case 'n':               /* next */
+       case 'm':               /* modify */
+       case 'w':               /* write */
+               /* Check for a size specification. */
+               cmd_size = cmd_get_data_size(argv[1], 4);
+               size = (cmd_size == 4) ? PCI_SIZE_32 : cmd_size - 1;
+               if (argc > 3)
+                       addr = simple_strtoul(argv[3], NULL, 16);
+               if (argc > 4)
+                       value = simple_strtoul(argv[4], NULL, 16);
+       case 'h':               /* header */
+               if (argc < 3)
+                       goto usage;
+               if ((bdf = get_pci_dev(argv[2])) == -1)
+                       return 1;
+               break;
+#ifdef CONFIG_CMD_PCI_ENUM
+       case 'e':
+               break;
+#endif
+       default:                /* scan bus */
+               value = 1; /* short listing */
+               if (argc > 1) {
+                       if (argv[argc-1][0] == 'l') {
+                               value = 0;
+                               argc--;
+                       }
+                       if (argc > 1)
+                               busnum = simple_strtoul(argv[1], NULL, 16);
+               }
+#ifdef CONFIG_DM_PCI
+               ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus);
+               if (ret) {
+                       printf("No such bus\n");
+                       return CMD_RET_FAILURE;
+               }
+               pciinfo(bus, value);
+#else
+               pciinfo(busnum, value);
+#endif
+               return 0;
+       }
+
+#ifdef CONFIG_DM_PCI
+       ret = dm_pci_bus_find_bdf(bdf, &dev);
+       if (ret) {
+               printf("No such device\n");
+               return CMD_RET_FAILURE;
+       }
+#else
+       dev = bdf;
+#endif
+
+       switch (argv[1][0]) {
+       case 'h':               /* header */
+               pci_header_show(dev);
+               break;
+       case 'd':               /* display */
+               return pci_cfg_display(dev, addr, size, value);
+#ifdef CONFIG_CMD_PCI_ENUM
+       case 'e':
+# ifdef CONFIG_DM_PCI
+               printf("This command is not yet supported with driver model\n");
+# else
+               pci_init();
+# endif
+               break;
+#endif
+       case 'n':               /* next */
+               if (argc < 4)
+                       goto usage;
+               ret = pci_cfg_modify(dev, addr, size, value, 0);
+               break;
+       case 'm':               /* modify */
+               if (argc < 4)
+                       goto usage;
+               ret = pci_cfg_modify(dev, addr, size, value, 1);
+               break;
+       case 'w':               /* write */
+               if (argc < 5)
+                       goto usage;
+#ifdef CONFIG_DM_PCI
+               ret = dm_pci_write_config(dev, addr, value, size);
+#else
+               ret = pci_cfg_write(dev, addr, size, value);
+#endif
+               break;
+       default:
+               ret = CMD_RET_USAGE;
+               break;
+       }
+
+       return ret;
+ usage:
+       return CMD_RET_USAGE;
+}
+
+/***************************************************/
+
+#ifdef CONFIG_SYS_LONGHELP
+static char pci_help_text[] =
+       "[bus] [long]\n"
+       "    - short or long list of PCI devices on bus 'bus'\n"
+#ifdef CONFIG_CMD_PCI_ENUM
+       "pci enum\n"
+       "    - re-enumerate PCI buses\n"
+#endif
+       "pci header b.d.f\n"
+       "    - show header of PCI device 'bus.device.function'\n"
+       "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
+       "    - display PCI configuration space (CFG)\n"
+       "pci next[.b, .w, .l] b.d.f address\n"
+       "    - modify, read and keep CFG address\n"
+       "pci modify[.b, .w, .l] b.d.f address\n"
+       "    -  modify, auto increment CFG address\n"
+       "pci write[.b, .w, .l] b.d.f address value\n"
+       "    - write to CFG address";
+#endif
+
+U_BOOT_CMD(
+       pci,    5,      1,      do_pci,
+       "list and access PCI Configuration Space", pci_help_text
+);
diff --git a/cmd/pcmcia.c b/cmd/pcmcia.c
new file mode 100644 (file)
index 0000000..682d18f
--- /dev/null
@@ -0,0 +1,346 @@
+/*
+ * (C) Copyright 2000-2006
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ *
+ ********************************************************************
+ *
+ * Lots of code copied from:
+ *
+ * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
+ * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
+ *
+ * "The ExCA standard specifies that socket controllers should provide
+ * two IO and five memory windows per socket, which can be independently
+ * configured and positioned in the host address space and mapped to
+ * arbitrary segments of card address space. " - David A Hinds. 1999
+ *
+ * This controller does _not_ meet the ExCA standard.
+ *
+ * m8xx pcmcia controller brief info:
+ * + 8 windows (attrib, mem, i/o)
+ * + up to two slots (SLOT_A and SLOT_B)
+ * + inputpins, outputpins, event and mask registers.
+ * - no offset register. sigh.
+ *
+ * Because of the lacking offset register we must map the whole card.
+ * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
+ * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
+ * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
+ * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
+ * They are maximum 64KByte each...
+ */
+
+/* #define DEBUG       1       */
+
+/*
+ * PCMCIA support
+ */
+#include <common.h>
+#include <command.h>
+#include <config.h>
+#include <pcmcia.h>
+#include <asm/io.h>
+
+/* -------------------------------------------------------------------- */
+
+#if defined(CONFIG_CMD_PCMCIA)
+
+extern int pcmcia_on (void);
+extern int pcmcia_off (void);
+
+int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int rcode = 0;
+
+       if (argc != 2) {
+               printf ("Usage: pinit {on | off}\n");
+               return 1;
+       }
+       if (strcmp(argv[1],"on") == 0) {
+               rcode = pcmcia_on ();
+       } else if (strcmp(argv[1],"off") == 0) {
+               rcode = pcmcia_off ();
+       } else {
+               printf ("Usage: pinit {on | off}\n");
+               return 1;
+       }
+
+       return rcode;
+}
+
+U_BOOT_CMD(
+       pinit,  2,      0,      do_pinit,
+       "PCMCIA sub-system",
+       "on  - power on PCMCIA socket\n"
+       "pinit off - power off PCMCIA socket"
+);
+
+#endif
+
+/* -------------------------------------------------------------------- */
+
+#undef CHECK_IDE_DEVICE
+
+#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
+#define        CHECK_IDE_DEVICE
+#endif
+
+#if    defined(CONFIG_PXA_PCMCIA)
+#define        CHECK_IDE_DEVICE
+#endif
+
+#ifdef CHECK_IDE_DEVICE
+
+int            ide_devices_found;
+static uchar   *known_cards[] = {
+       (uchar *)"ARGOSY PnPIDE D5",
+       NULL
+};
+
+#define        MAX_TUPEL_SZ    512
+#define MAX_FEATURES   4
+
+#define MAX_IDENT_CHARS                64
+#define        MAX_IDENT_FIELDS        4
+
+#define        indent  "\t   "
+
+static void print_funcid (int func)
+{
+       puts (indent);
+       switch (func) {
+               case CISTPL_FUNCID_MULTI:
+                       puts (" Multi-Function");
+                       break;
+               case CISTPL_FUNCID_MEMORY:
+                       puts (" Memory");
+                       break;
+               case CISTPL_FUNCID_SERIAL:
+                       puts (" Serial Port");
+                       break;
+               case CISTPL_FUNCID_PARALLEL:
+                       puts (" Parallel Port");
+                       break;
+               case CISTPL_FUNCID_FIXED:
+                       puts (" Fixed Disk");
+                       break;
+               case CISTPL_FUNCID_VIDEO:
+                       puts (" Video Adapter");
+                       break;
+               case CISTPL_FUNCID_NETWORK:
+                       puts (" Network Adapter");
+                       break;
+               case CISTPL_FUNCID_AIMS:
+                       puts (" AIMS Card");
+                       break;
+               case CISTPL_FUNCID_SCSI:
+                       puts (" SCSI Adapter");
+                       break;
+               default:
+                       puts (" Unknown");
+                       break;
+       }
+       puts (" Card\n");
+}
+
+static void print_fixed (volatile uchar *p)
+{
+       if (p == NULL)
+               return;
+
+       puts(indent);
+
+       switch (*p) {
+               case CISTPL_FUNCE_IDE_IFACE:
+               {   uchar iface = *(p+2);
+
+               puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
+               puts (" interface ");
+               break;
+               }
+               case CISTPL_FUNCE_IDE_MASTER:
+               case CISTPL_FUNCE_IDE_SLAVE:
+               {   uchar f1 = *(p+2);
+               uchar f2 = *(p+4);
+
+               puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
+
+               if (f1 & CISTPL_IDE_UNIQUE)
+                       puts (" [unique]");
+
+               puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
+
+               if (f2 & CISTPL_IDE_HAS_SLEEP)
+                       puts (" [sleep]");
+
+               if (f2 & CISTPL_IDE_HAS_STANDBY)
+                       puts (" [standby]");
+
+               if (f2 & CISTPL_IDE_HAS_IDLE)
+                       puts (" [idle]");
+
+               if (f2 & CISTPL_IDE_LOW_POWER)
+                       puts (" [low power]");
+
+               if (f2 & CISTPL_IDE_REG_INHIBIT)
+                       puts (" [reg inhibit]");
+
+               if (f2 & CISTPL_IDE_HAS_INDEX)
+                       puts (" [index]");
+
+               if (f2 & CISTPL_IDE_IOIS16)
+                       puts (" [IOis16]");
+
+               break;
+               }
+       }
+       putc ('\n');
+}
+
+static int identify  (volatile uchar *p)
+{
+       uchar id_str[MAX_IDENT_CHARS];
+       uchar data;
+       uchar *t;
+       uchar **card;
+       int i, done;
+
+       if (p == NULL)
+               return (0);     /* Don't know */
+
+       t = id_str;
+       done =0;
+
+       for (i=0; i<=4 && !done; ++i, p+=2) {
+               while ((data = *p) != '\0') {
+                       if (data == 0xFF) {
+                               done = 1;
+                               break;
+                       }
+                       *t++ = data;
+                       if (t == &id_str[MAX_IDENT_CHARS-1]) {
+                               done = 1;
+                               break;
+                       }
+                       p += 2;
+               }
+               if (!done)
+                       *t++ = ' ';
+       }
+       *t = '\0';
+       while (--t > id_str) {
+               if (*t == ' ')
+                       *t = '\0';
+               else
+                       break;
+       }
+       puts ((char *)id_str);
+       putc ('\n');
+
+       for (card=known_cards; *card; ++card) {
+               debug ("## Compare against \"%s\"\n", *card);
+               if (strcmp((char *)*card, (char *)id_str) == 0) {       /* found! */
+                       debug ("## CARD FOUND ##\n");
+                       return (1);
+               }
+       }
+
+       return (0);     /* don't know */
+}
+
+int check_ide_device (int slot)
+{
+       volatile uchar *ident = NULL;
+       volatile uchar *feature_p[MAX_FEATURES];
+       volatile uchar *p, *start, *addr;
+       int n_features = 0;
+       uchar func_id = ~0;
+       uchar code, len;
+       ushort config_base = 0;
+       int found = 0;
+       int i;
+
+       addr = (volatile uchar *)(CONFIG_SYS_PCMCIA_MEM_ADDR +
+                                 CONFIG_SYS_PCMCIA_MEM_SIZE * (slot * 4));
+       debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
+
+       start = p = (volatile uchar *) addr;
+
+       while ((p - start) < MAX_TUPEL_SZ) {
+
+               code = *p; p += 2;
+
+               if (code == 0xFF) { /* End of chain */
+                       break;
+               }
+
+               len = *p; p += 2;
+#if defined(DEBUG) && (DEBUG > 1)
+               { volatile uchar *q = p;
+                       printf ("\nTuple code %02x  length %d\n\tData:",
+                               code, len);
+
+                       for (i = 0; i < len; ++i) {
+                               printf (" %02x", *q);
+                               q+= 2;
+                       }
+               }
+#endif /* DEBUG */
+               switch (code) {
+               case CISTPL_VERS_1:
+                       ident = p + 4;
+                       break;
+               case CISTPL_FUNCID:
+                       /* Fix for broken SanDisk which may have 0x80 bit set */
+                       func_id = *p & 0x7F;
+                       break;
+               case CISTPL_FUNCE:
+                       if (n_features < MAX_FEATURES)
+                               feature_p[n_features++] = p;
+                       break;
+               case CISTPL_CONFIG:
+                       config_base = (*(p+6) << 8) + (*(p+4));
+                       debug ("\n## Config_base = %04x ###\n", config_base);
+               default:
+                       break;
+               }
+               p += 2 * len;
+       }
+
+       found = identify (ident);
+
+       if (func_id != ((uchar)~0)) {
+               print_funcid (func_id);
+
+               if (func_id == CISTPL_FUNCID_FIXED)
+                       found = 1;
+               else
+                       return (1);     /* no disk drive */
+       }
+
+       for (i=0; i<n_features; ++i) {
+               print_fixed (feature_p[i]);
+       }
+
+       if (!found) {
+               printf ("unknown card type\n");
+               return (1);
+       }
+
+       ide_devices_found |= (1 << slot);
+
+       /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
+       *((uchar *)(addr + config_base)) = 1;
+#if 0
+       printf("\n## Config_base = %04x ###\n", config_base);
+       printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
+       printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
+       printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
+       printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
+#endif
+       return (0);
+}
+
+#endif /* CHECK_IDE_DEVICE */
diff --git a/cmd/pmic.c b/cmd/pmic.c
new file mode 100644 (file)
index 0000000..970767c
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+
+#define LIMIT_DEV      32
+#define LIMIT_PARENT   20
+
+static struct udevice *currdev;
+
+static int failure(int ret)
+{
+       printf("Error: %d (%s)\n", ret, errno_str(ret));
+
+       return CMD_RET_FAILURE;
+}
+
+static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *name;
+       int ret = -ENODEV;
+
+       switch (argc) {
+       case 2:
+               name = argv[1];
+               ret = pmic_get(name, &currdev);
+               if (ret) {
+                       printf("Can't get PMIC: %s!\n", name);
+                       return failure(ret);
+               }
+       case 1:
+               if (!currdev) {
+                       printf("PMIC device is not set!\n\n");
+                       return CMD_RET_USAGE;
+               }
+
+               printf("dev: %d @ %s\n", currdev->seq, currdev->name);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       int ret;
+
+       printf("| %-*.*s| %-*.*s| %s @ %s\n",
+              LIMIT_DEV, LIMIT_DEV, "Name",
+              LIMIT_PARENT, LIMIT_PARENT, "Parent name",
+              "Parent uclass", "seq");
+
+       for (ret = uclass_first_device(UCLASS_PMIC, &dev); dev;
+            ret = uclass_next_device(&dev)) {
+               if (ret)
+                       continue;
+
+               printf("| %-*.*s| %-*.*s| %s @ %d\n",
+                      LIMIT_DEV, LIMIT_DEV, dev->name,
+                      LIMIT_PARENT, LIMIT_PARENT, dev->parent->name,
+                      dev_get_uclass_name(dev->parent), dev->parent->seq);
+       }
+
+       if (ret)
+               return CMD_RET_FAILURE;
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       uint8_t value;
+       uint reg;
+       int ret;
+
+       if (!currdev) {
+               printf("First, set the PMIC device!\n");
+               return CMD_RET_USAGE;
+       }
+
+       dev = currdev;
+
+       printf("Dump pmic: %s registers\n", dev->name);
+
+       for (reg = 0; reg < pmic_reg_count(dev); reg++) {
+               ret = pmic_read(dev, reg, &value, 1);
+               if (ret) {
+                       printf("Can't read register: %d\n", reg);
+                       return failure(ret);
+               }
+
+               if (!(reg % 16))
+                       printf("\n0x%02x: ", reg);
+
+               printf("%2.2x ", value);
+       }
+       printf("\n");
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       int regs, ret;
+       uint8_t value;
+       uint reg;
+
+       if (!currdev) {
+               printf("First, set the PMIC device!\n");
+               return CMD_RET_USAGE;
+       }
+
+       dev = currdev;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       reg = simple_strtoul(argv[1], NULL, 0);
+       regs = pmic_reg_count(dev);
+       if (reg > regs) {
+               printf("PMIC max reg: %d\n", regs);
+               return failure(-EFAULT);
+       }
+
+       ret = pmic_read(dev, reg, &value, 1);
+       if (ret) {
+               printf("Can't read PMIC register: %d!\n", reg);
+               return failure(ret);
+       }
+
+       printf("0x%02x: 0x%2.2x\n", reg, value);
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       int regs, ret;
+       uint8_t value;
+       uint reg;
+
+       if (!currdev) {
+               printf("First, set the PMIC device!\n");
+               return CMD_RET_USAGE;
+       }
+
+       dev = currdev;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       reg = simple_strtoul(argv[1], NULL, 0);
+       regs = pmic_reg_count(dev);
+       if (reg > regs) {
+               printf("PMIC max reg: %d\n", regs);
+               return failure(-EFAULT);
+       }
+
+       value = simple_strtoul(argv[2], NULL, 0);
+
+       ret = pmic_write(dev, reg, &value, 1);
+       if (ret) {
+               printf("Can't write PMIC register: %d!\n", reg);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static cmd_tbl_t subcmd[] = {
+       U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""),
+       U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
+       U_BOOT_CMD_MKENT(dump, 1, 1, do_dump, "", ""),
+       U_BOOT_CMD_MKENT(read, 2, 1, do_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 3, 1, do_write, "", ""),
+};
+
+static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       cmd_tbl_t *cmd;
+
+       argc--;
+       argv++;
+
+       cmd = find_cmd_tbl(argv[0], subcmd, ARRAY_SIZE(subcmd));
+       if (cmd == NULL || argc > cmd->maxargs)
+               return CMD_RET_USAGE;
+
+       return cmd->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
+       " operations",
+       "list          - list pmic devices\n"
+       "pmic dev [name]    - show or [set] operating PMIC device\n"
+       "pmic dump          - dump registers\n"
+       "pmic read address  - read byte of register at address\n"
+       "pmic write address - write byte to register at address\n"
+);
diff --git a/cmd/portio.c b/cmd/portio.c
new file mode 100644 (file)
index 0000000..bf3a997
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * (C) Copyright 2003
+ * Marc Singer, elf@buici.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Port I/O Functions
+ *
+ * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
+ */
+
+#include <common.h>
+#include <command.h>
+
+/* Display values from last command.
+ * Memory modify remembered values are different from display memory.
+ */
+static uint in_last_addr, in_last_size;
+static uint out_last_addr, out_last_size, out_last_value;
+
+
+int do_portio_out (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       uint addr = out_last_addr;
+       uint size = out_last_size;
+       uint value = out_last_value;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /*
+                * New command specified.  Check for a size specification.
+                * Defaults to long if no or incorrect specification.
+                */
+               size = cmd_get_data_size (argv[0], 1);
+               addr = simple_strtoul (argv[1], NULL, 16);
+               value = simple_strtoul (argv[2], NULL, 16);
+       }
+#if defined (CONFIG_X86)
+
+       {
+               unsigned short port = addr;
+
+               switch (size) {
+               default:
+               case 1:
+                   {
+                       unsigned char ch = value;
+                       __asm__ volatile ("out %0, %%dx"::"a" (ch), "d" (port));
+                   }
+                       break;
+               case 2:
+                   {
+                       unsigned short w = value;
+                       __asm__ volatile ("out %0, %%dx"::"a" (w), "d" (port));
+                   }
+                       break;
+               case 4:
+                       __asm__ volatile ("out %0, %%dx"::"a" (value), "d" (port));
+
+                       break;
+               }
+       }
+
+#endif                                                 /* CONFIG_X86 */
+
+       out_last_addr = addr;
+       out_last_size = size;
+       out_last_value = value;
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       out,    3,      1,      do_portio_out,
+       "write datum to IO port",
+       "[.b, .w, .l] port value\n    - output to IO port"
+);
+
+int do_portio_in (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       uint addr = in_last_addr;
+       uint size = in_last_size;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /*
+                * New command specified.  Check for a size specification.
+                * Defaults to long if no or incorrect specification.
+                */
+               size = cmd_get_data_size (argv[0], 1);
+               addr = simple_strtoul (argv[1], NULL, 16);
+       }
+#if defined (CONFIG_X86)
+
+       {
+               unsigned short port = addr;
+
+               switch (size) {
+               default:
+               case 1:
+                   {
+                       unsigned char ch;
+                       __asm__ volatile ("in %%dx, %0":"=a" (ch):"d" (port));
+
+                       printf (" %02x\n", ch);
+                   }
+                       break;
+               case 2:
+                   {
+                       unsigned short w;
+                       __asm__ volatile ("in %%dx, %0":"=a" (w):"d" (port));
+
+                       printf (" %04x\n", w);
+                   }
+                       break;
+               case 4:
+                   {
+                       unsigned long l;
+                       __asm__ volatile ("in %%dx, %0":"=a" (l):"d" (port));
+
+                       printf (" %08lx\n", l);
+                   }
+                       break;
+               }
+       }
+#endif /* CONFIG_X86 */
+
+       in_last_addr = addr;
+       in_last_size = size;
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       in,     2,      1,      do_portio_in,
+       "read data from an IO port",
+       "[.b, .w, .l] port\n"
+       "    - read datum from IO port"
+);
diff --git a/cmd/pxe.c b/cmd/pxe.c
new file mode 100644 (file)
index 0000000..080b376
--- /dev/null
+++ b/cmd/pxe.c
@@ -0,0 +1,1725 @@
+/*
+ * Copyright 2010-2011 Calxeda, Inc.
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <errno.h>
+#include <linux/list.h>
+#include <fs.h>
+#include <asm/io.h>
+
+#include "menu.h"
+#include "cli.h"
+
+#define MAX_TFTP_PATH_LEN 127
+
+const char *pxe_default_paths[] = {
+#ifdef CONFIG_SYS_SOC
+       "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC,
+#endif
+       "default-" CONFIG_SYS_ARCH,
+       "default",
+       NULL
+};
+
+static bool is_pxe;
+
+/*
+ * Like getenv, but prints an error if envvar isn't defined in the
+ * environment.  It always returns what getenv does, so it can be used in
+ * place of getenv without changing error handling otherwise.
+ */
+static char *from_env(const char *envvar)
+{
+       char *ret;
+
+       ret = getenv(envvar);
+
+       if (!ret)
+               printf("missing environment variable: %s\n", envvar);
+
+       return ret;
+}
+
+#ifdef CONFIG_CMD_NET
+/*
+ * Convert an ethaddr from the environment to the format used by pxelinux
+ * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
+ * the beginning of the ethernet address to indicate a hardware type of
+ * Ethernet. Also converts uppercase hex characters into lowercase, to match
+ * pxelinux's behavior.
+ *
+ * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
+ * environment, or some other value < 0 on error.
+ */
+static int format_mac_pxe(char *outbuf, size_t outbuf_len)
+{
+       uchar ethaddr[6];
+
+       if (outbuf_len < 21) {
+               printf("outbuf is too small (%zd < 21)\n", outbuf_len);
+
+               return -EINVAL;
+       }
+
+       if (!eth_getenv_enetaddr_by_index("eth", eth_get_dev_index(),
+                                         ethaddr))
+               return -ENOENT;
+
+       sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
+               ethaddr[0], ethaddr[1], ethaddr[2],
+               ethaddr[3], ethaddr[4], ethaddr[5]);
+
+       return 1;
+}
+#endif
+
+/*
+ * Returns the directory the file specified in the bootfile env variable is
+ * in. If bootfile isn't defined in the environment, return NULL, which should
+ * be interpreted as "don't prepend anything to paths".
+ */
+static int get_bootfile_path(const char *file_path, char *bootfile_path,
+                            size_t bootfile_path_size)
+{
+       char *bootfile, *last_slash;
+       size_t path_len = 0;
+
+       /* Only syslinux allows absolute paths */
+       if (file_path[0] == '/' && !is_pxe)
+               goto ret;
+
+       bootfile = from_env("bootfile");
+
+       if (!bootfile)
+               goto ret;
+
+       last_slash = strrchr(bootfile, '/');
+
+       if (last_slash == NULL)
+               goto ret;
+
+       path_len = (last_slash - bootfile) + 1;
+
+       if (bootfile_path_size < path_len) {
+               printf("bootfile_path too small. (%zd < %zd)\n",
+                               bootfile_path_size, path_len);
+
+               return -1;
+       }
+
+       strncpy(bootfile_path, bootfile, path_len);
+
+ ret:
+       bootfile_path[path_len] = '\0';
+
+       return 1;
+}
+
+static int (*do_getfile)(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr);
+
+#ifdef CONFIG_CMD_NET
+static int do_get_tftp(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
+{
+       char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
+
+       tftp_argv[1] = file_addr;
+       tftp_argv[2] = (void *)file_path;
+
+       if (do_tftpb(cmdtp, 0, 3, tftp_argv))
+               return -ENOENT;
+
+       return 1;
+}
+#endif
+
+static char *fs_argv[5];
+
+static int do_get_ext2(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
+{
+#ifdef CONFIG_CMD_EXT2
+       fs_argv[0] = "ext2load";
+       fs_argv[3] = file_addr;
+       fs_argv[4] = (void *)file_path;
+
+       if (!do_ext2load(cmdtp, 0, 5, fs_argv))
+               return 1;
+#endif
+       return -ENOENT;
+}
+
+static int do_get_fat(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
+{
+#ifdef CONFIG_CMD_FAT
+       fs_argv[0] = "fatload";
+       fs_argv[3] = file_addr;
+       fs_argv[4] = (void *)file_path;
+
+       if (!do_fat_fsload(cmdtp, 0, 5, fs_argv))
+               return 1;
+#endif
+       return -ENOENT;
+}
+
+static int do_get_any(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
+{
+#ifdef CONFIG_CMD_FS_GENERIC
+       fs_argv[0] = "load";
+       fs_argv[3] = file_addr;
+       fs_argv[4] = (void *)file_path;
+
+       if (!do_load(cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
+               return 1;
+#endif
+       return -ENOENT;
+}
+
+/*
+ * As in pxelinux, paths to files referenced from files we retrieve are
+ * relative to the location of bootfile. get_relfile takes such a path and
+ * joins it with the bootfile path to get the full path to the target file. If
+ * the bootfile path is NULL, we use file_path as is.
+ *
+ * Returns 1 for success, or < 0 on error.
+ */
+static int get_relfile(cmd_tbl_t *cmdtp, const char *file_path,
+       unsigned long file_addr)
+{
+       size_t path_len;
+       char relfile[MAX_TFTP_PATH_LEN+1];
+       char addr_buf[18];
+       int err;
+
+       err = get_bootfile_path(file_path, relfile, sizeof(relfile));
+
+       if (err < 0)
+               return err;
+
+       path_len = strlen(file_path);
+       path_len += strlen(relfile);
+
+       if (path_len > MAX_TFTP_PATH_LEN) {
+               printf("Base path too long (%s%s)\n",
+                                       relfile,
+                                       file_path);
+
+               return -ENAMETOOLONG;
+       }
+
+       strcat(relfile, file_path);
+
+       printf("Retrieving file: %s\n", relfile);
+
+       sprintf(addr_buf, "%lx", file_addr);
+
+       return do_getfile(cmdtp, relfile, addr_buf);
+}
+
+/*
+ * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
+ * 'bootfile' was specified in the environment, the path to bootfile will be
+ * prepended to 'file_path' and the resulting path will be used.
+ *
+ * Returns 1 on success, or < 0 for error.
+ */
+static int get_pxe_file(cmd_tbl_t *cmdtp, const char *file_path,
+       unsigned long file_addr)
+{
+       unsigned long config_file_size;
+       char *tftp_filesize;
+       int err;
+       char *buf;
+
+       err = get_relfile(cmdtp, file_path, file_addr);
+
+       if (err < 0)
+               return err;
+
+       /*
+        * the file comes without a NUL byte at the end, so find out its size
+        * and add the NUL byte.
+        */
+       tftp_filesize = from_env("filesize");
+
+       if (!tftp_filesize)
+               return -ENOENT;
+
+       if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
+               return -EINVAL;
+
+       buf = map_sysmem(file_addr + config_file_size, 1);
+       *buf = '\0';
+       unmap_sysmem(buf);
+
+       return 1;
+}
+
+#ifdef CONFIG_CMD_NET
+
+#define PXELINUX_DIR "pxelinux.cfg/"
+
+/*
+ * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
+ * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
+ * from the bootfile path, as described above.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int get_pxelinux_path(cmd_tbl_t *cmdtp, const char *file,
+       unsigned long pxefile_addr_r)
+{
+       size_t base_len = strlen(PXELINUX_DIR);
+       char path[MAX_TFTP_PATH_LEN+1];
+
+       if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
+               printf("path (%s%s) too long, skipping\n",
+                               PXELINUX_DIR, file);
+               return -ENAMETOOLONG;
+       }
+
+       sprintf(path, PXELINUX_DIR "%s", file);
+
+       return get_pxe_file(cmdtp, path, pxefile_addr_r);
+}
+
+/*
+ * Looks for a pxe file with a name based on the pxeuuid environment variable.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int pxe_uuid_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
+{
+       char *uuid_str;
+
+       uuid_str = from_env("pxeuuid");
+
+       if (!uuid_str)
+               return -ENOENT;
+
+       return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
+}
+
+/*
+ * Looks for a pxe file with a name based on the 'ethaddr' environment
+ * variable.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int pxe_mac_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
+{
+       char mac_str[21];
+       int err;
+
+       err = format_mac_pxe(mac_str, sizeof(mac_str));
+
+       if (err < 0)
+               return err;
+
+       return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
+}
+
+/*
+ * Looks for pxe files with names based on our IP address. See pxelinux
+ * documentation for details on what these file names look like.  We match
+ * that exactly.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int pxe_ipaddr_paths(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
+{
+       char ip_addr[9];
+       int mask_pos, err;
+
+       sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
+
+       for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
+               err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
+
+               if (err > 0)
+                       return err;
+
+               ip_addr[mask_pos] = '\0';
+       }
+
+       return -ENOENT;
+}
+
+/*
+ * Entry point for the 'pxe get' command.
+ * This Follows pxelinux's rules to download a config file from a tftp server.
+ * The file is stored at the location given by the pxefile_addr_r environment
+ * variable, which must be set.
+ *
+ * UUID comes from pxeuuid env variable, if defined
+ * MAC addr comes from ethaddr env variable, if defined
+ * IP
+ *
+ * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
+ *
+ * Returns 0 on success or 1 on error.
+ */
+static int
+do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *pxefile_addr_str;
+       unsigned long pxefile_addr_r;
+       int err, i = 0;
+
+       do_getfile = do_get_tftp;
+
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       pxefile_addr_str = from_env("pxefile_addr_r");
+
+       if (!pxefile_addr_str)
+               return 1;
+
+       err = strict_strtoul(pxefile_addr_str, 16,
+                               (unsigned long *)&pxefile_addr_r);
+       if (err < 0)
+               return 1;
+
+       /*
+        * Keep trying paths until we successfully get a file we're looking
+        * for.
+        */
+       if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
+           pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
+           pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
+               printf("Config file found\n");
+
+               return 0;
+       }
+
+       while (pxe_default_paths[i]) {
+               if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
+                                     pxefile_addr_r) > 0) {
+                       printf("Config file found\n");
+                       return 0;
+               }
+               i++;
+       }
+
+       printf("Config file not found\n");
+
+       return 1;
+}
+#endif
+
+/*
+ * Wrapper to make it easier to store the file at file_path in the location
+ * specified by envaddr_name. file_path will be joined to the bootfile path,
+ * if any is specified.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path, const char *envaddr_name)
+{
+       unsigned long file_addr;
+       char *envaddr;
+
+       envaddr = from_env(envaddr_name);
+
+       if (!envaddr)
+               return -ENOENT;
+
+       if (strict_strtoul(envaddr, 16, &file_addr) < 0)
+               return -EINVAL;
+
+       return get_relfile(cmdtp, file_path, file_addr);
+}
+
+/*
+ * A note on the pxe file parser.
+ *
+ * We're parsing files that use syslinux grammar, which has a few quirks.
+ * String literals must be recognized based on context - there is no
+ * quoting or escaping support. There's also nothing to explicitly indicate
+ * when a label section completes. We deal with that by ending a label
+ * section whenever we see a line that doesn't include.
+ *
+ * As with the syslinux family, this same file format could be reused in the
+ * future for non pxe purposes. The only action it takes during parsing that
+ * would throw this off is handling of include files. It assumes we're using
+ * pxe, and does a tftp download of a file listed as an include file in the
+ * middle of the parsing operation. That could be handled by refactoring it to
+ * take a 'include file getter' function.
+ */
+
+/*
+ * Describes a single label given in a pxe file.
+ *
+ * Create these with the 'label_create' function given below.
+ *
+ * name - the name of the menu as given on the 'menu label' line.
+ * kernel - the path to the kernel file to use for this label.
+ * append - kernel command line to use when booting this label
+ * initrd - path to the initrd to use for this label.
+ * attempted - 0 if we haven't tried to boot this label, 1 if we have.
+ * localboot - 1 if this label specified 'localboot', 0 otherwise.
+ * list - lets these form a list, which a pxe_menu struct will hold.
+ */
+struct pxe_label {
+       char num[4];
+       char *name;
+       char *menu;
+       char *kernel;
+       char *append;
+       char *initrd;
+       char *fdt;
+       char *fdtdir;
+       int ipappend;
+       int attempted;
+       int localboot;
+       int localboot_val;
+       struct list_head list;
+};
+
+/*
+ * Describes a pxe menu as given via pxe files.
+ *
+ * title - the name of the menu as given by a 'menu title' line.
+ * default_label - the name of the default label, if any.
+ * timeout - time in tenths of a second to wait for a user key-press before
+ *           booting the default label.
+ * prompt - if 0, don't prompt for a choice unless the timeout period is
+ *          interrupted.  If 1, always prompt for a choice regardless of
+ *          timeout.
+ * labels - a list of labels defined for the menu.
+ */
+struct pxe_menu {
+       char *title;
+       char *default_label;
+       int timeout;
+       int prompt;
+       struct list_head labels;
+};
+
+/*
+ * Allocates memory for and initializes a pxe_label. This uses malloc, so the
+ * result must be free()'d to reclaim the memory.
+ *
+ * Returns NULL if malloc fails.
+ */
+static struct pxe_label *label_create(void)
+{
+       struct pxe_label *label;
+
+       label = malloc(sizeof(struct pxe_label));
+
+       if (!label)
+               return NULL;
+
+       memset(label, 0, sizeof(struct pxe_label));
+
+       return label;
+}
+
+/*
+ * Free the memory used by a pxe_label, including that used by its name,
+ * kernel, append and initrd members, if they're non NULL.
+ *
+ * So - be sure to only use dynamically allocated memory for the members of
+ * the pxe_label struct, unless you want to clean it up first. These are
+ * currently only created by the pxe file parsing code.
+ */
+static void label_destroy(struct pxe_label *label)
+{
+       if (label->name)
+               free(label->name);
+
+       if (label->kernel)
+               free(label->kernel);
+
+       if (label->append)
+               free(label->append);
+
+       if (label->initrd)
+               free(label->initrd);
+
+       if (label->fdt)
+               free(label->fdt);
+
+       if (label->fdtdir)
+               free(label->fdtdir);
+
+       free(label);
+}
+
+/*
+ * Print a label and its string members if they're defined.
+ *
+ * This is passed as a callback to the menu code for displaying each
+ * menu entry.
+ */
+static void label_print(void *data)
+{
+       struct pxe_label *label = data;
+       const char *c = label->menu ? label->menu : label->name;
+
+       printf("%s:\t%s\n", label->num, c);
+}
+
+/*
+ * Boot a label that specified 'localboot'. This requires that the 'localcmd'
+ * environment variable is defined. Its contents will be executed as U-boot
+ * command.  If the label specified an 'append' line, its contents will be
+ * used to overwrite the contents of the 'bootargs' environment variable prior
+ * to running 'localcmd'.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int label_localboot(struct pxe_label *label)
+{
+       char *localcmd;
+
+       localcmd = from_env("localcmd");
+
+       if (!localcmd)
+               return -ENOENT;
+
+       if (label->append) {
+               char bootargs[CONFIG_SYS_CBSIZE];
+
+               cli_simple_process_macros(label->append, bootargs);
+               setenv("bootargs", bootargs);
+       }
+
+       debug("running: %s\n", localcmd);
+
+       return run_command_list(localcmd, strlen(localcmd), 0);
+}
+
+/*
+ * Boot according to the contents of a pxe_label.
+ *
+ * If we can't boot for any reason, we return.  A successful boot never
+ * returns.
+ *
+ * The kernel will be stored in the location given by the 'kernel_addr_r'
+ * environment variable.
+ *
+ * If the label specifies an initrd file, it will be stored in the location
+ * given by the 'ramdisk_addr_r' environment variable.
+ *
+ * If the label specifies an 'append' line, its contents will overwrite that
+ * of the 'bootargs' environment variable.
+ */
+static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
+{
+       char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
+       char initrd_str[22];
+       char mac_str[29] = "";
+       char ip_str[68] = "";
+       int bootm_argc = 3;
+       int len = 0;
+       ulong kernel_addr;
+       void *buf;
+
+       label_print(label);
+
+       label->attempted = 1;
+
+       if (label->localboot) {
+               if (label->localboot_val >= 0)
+                       label_localboot(label);
+               return 0;
+       }
+
+       if (label->kernel == NULL) {
+               printf("No kernel given, skipping %s\n",
+                               label->name);
+               return 1;
+       }
+
+       if (label->initrd) {
+               if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
+                       printf("Skipping %s for failure retrieving initrd\n",
+                                       label->name);
+                       return 1;
+               }
+
+               bootm_argv[2] = initrd_str;
+               strcpy(bootm_argv[2], getenv("ramdisk_addr_r"));
+               strcat(bootm_argv[2], ":");
+               strcat(bootm_argv[2], getenv("filesize"));
+       } else {
+               bootm_argv[2] = "-";
+       }
+
+       if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
+               printf("Skipping %s for failure retrieving kernel\n",
+                               label->name);
+               return 1;
+       }
+
+       if (label->ipappend & 0x1) {
+               sprintf(ip_str, " ip=%s:%s:%s:%s",
+                       getenv("ipaddr"), getenv("serverip"),
+                       getenv("gatewayip"), getenv("netmask"));
+       }
+
+#ifdef CONFIG_CMD_NET
+       if (label->ipappend & 0x2) {
+               int err;
+               strcpy(mac_str, " BOOTIF=");
+               err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
+               if (err < 0)
+                       mac_str[0] = '\0';
+       }
+#endif
+
+       if ((label->ipappend & 0x3) || label->append) {
+               char bootargs[CONFIG_SYS_CBSIZE] = "";
+               char finalbootargs[CONFIG_SYS_CBSIZE];
+
+               if (strlen(label->append ?: "") +
+                   strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
+                       printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
+                              strlen(label->append ?: ""),
+                              strlen(ip_str), strlen(mac_str),
+                              sizeof(bootargs));
+                       return 1;
+               }
+
+               if (label->append)
+                       strcpy(bootargs, label->append);
+               strcat(bootargs, ip_str);
+               strcat(bootargs, mac_str);
+
+               cli_simple_process_macros(bootargs, finalbootargs);
+               setenv("bootargs", finalbootargs);
+               printf("append: %s\n", finalbootargs);
+       }
+
+       bootm_argv[1] = getenv("kernel_addr_r");
+
+       /*
+        * fdt usage is optional:
+        * It handles the following scenarios. All scenarios are exclusive
+        *
+        * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
+        * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
+        * and adjust argc appropriately.
+        *
+        * Scenario 2: If there is an fdt_addr specified, pass it along to
+        * bootm, and adjust argc appropriately.
+        *
+        * Scenario 3: fdt blob is not available.
+        */
+       bootm_argv[3] = getenv("fdt_addr_r");
+
+       /* if fdt label is defined then get fdt from server */
+       if (bootm_argv[3]) {
+               char *fdtfile = NULL;
+               char *fdtfilefree = NULL;
+
+               if (label->fdt) {
+                       fdtfile = label->fdt;
+               } else if (label->fdtdir) {
+                       char *f1, *f2, *f3, *f4, *slash;
+
+                       f1 = getenv("fdtfile");
+                       if (f1) {
+                               f2 = "";
+                               f3 = "";
+                               f4 = "";
+                       } else {
+                               /*
+                                * For complex cases where this code doesn't
+                                * generate the correct filename, the board
+                                * code should set $fdtfile during early boot,
+                                * or the boot scripts should set $fdtfile
+                                * before invoking "pxe" or "sysboot".
+                                */
+                               f1 = getenv("soc");
+                               f2 = "-";
+                               f3 = getenv("board");
+                               f4 = ".dtb";
+                       }
+
+                       len = strlen(label->fdtdir);
+                       if (!len)
+                               slash = "./";
+                       else if (label->fdtdir[len - 1] != '/')
+                               slash = "/";
+                       else
+                               slash = "";
+
+                       len = strlen(label->fdtdir) + strlen(slash) +
+                               strlen(f1) + strlen(f2) + strlen(f3) +
+                               strlen(f4) + 1;
+                       fdtfilefree = malloc(len);
+                       if (!fdtfilefree) {
+                               printf("malloc fail (FDT filename)\n");
+                               return 1;
+                       }
+
+                       snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
+                                label->fdtdir, slash, f1, f2, f3, f4);
+                       fdtfile = fdtfilefree;
+               }
+
+               if (fdtfile) {
+                       int err = get_relfile_envaddr(cmdtp, fdtfile, "fdt_addr_r");
+                       free(fdtfilefree);
+                       if (err < 0) {
+                               printf("Skipping %s for failure retrieving fdt\n",
+                                               label->name);
+                               return 1;
+                       }
+               } else {
+                       bootm_argv[3] = NULL;
+               }
+       }
+
+       if (!bootm_argv[3])
+               bootm_argv[3] = getenv("fdt_addr");
+
+       if (bootm_argv[3])
+               bootm_argc = 4;
+
+       kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
+       buf = map_sysmem(kernel_addr, 0);
+       /* Try bootm for legacy and FIT format image */
+       if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
+               do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
+#ifdef CONFIG_CMD_BOOTI
+       /* Try booting an AArch64 Linux kernel image */
+       else
+               do_booti(cmdtp, 0, bootm_argc, bootm_argv);
+#elif defined(CONFIG_CMD_BOOTZ)
+       /* Try booting a Image */
+       else
+               do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
+#endif
+       unmap_sysmem(buf);
+       return 1;
+}
+
+/*
+ * Tokens for the pxe file parser.
+ */
+enum token_type {
+       T_EOL,
+       T_STRING,
+       T_EOF,
+       T_MENU,
+       T_TITLE,
+       T_TIMEOUT,
+       T_LABEL,
+       T_KERNEL,
+       T_LINUX,
+       T_APPEND,
+       T_INITRD,
+       T_LOCALBOOT,
+       T_DEFAULT,
+       T_PROMPT,
+       T_INCLUDE,
+       T_FDT,
+       T_FDTDIR,
+       T_ONTIMEOUT,
+       T_IPAPPEND,
+       T_INVALID
+};
+
+/*
+ * A token - given by a value and a type.
+ */
+struct token {
+       char *val;
+       enum token_type type;
+};
+
+/*
+ * Keywords recognized.
+ */
+static const struct token keywords[] = {
+       {"menu", T_MENU},
+       {"title", T_TITLE},
+       {"timeout", T_TIMEOUT},
+       {"default", T_DEFAULT},
+       {"prompt", T_PROMPT},
+       {"label", T_LABEL},
+       {"kernel", T_KERNEL},
+       {"linux", T_LINUX},
+       {"localboot", T_LOCALBOOT},
+       {"append", T_APPEND},
+       {"initrd", T_INITRD},
+       {"include", T_INCLUDE},
+       {"devicetree", T_FDT},
+       {"fdt", T_FDT},
+       {"devicetreedir", T_FDTDIR},
+       {"fdtdir", T_FDTDIR},
+       {"ontimeout", T_ONTIMEOUT,},
+       {"ipappend", T_IPAPPEND,},
+       {NULL, T_INVALID}
+};
+
+/*
+ * Since pxe(linux) files don't have a token to identify the start of a
+ * literal, we have to keep track of when we're in a state where a literal is
+ * expected vs when we're in a state a keyword is expected.
+ */
+enum lex_state {
+       L_NORMAL = 0,
+       L_KEYWORD,
+       L_SLITERAL
+};
+
+/*
+ * get_string retrieves a string from *p and stores it as a token in
+ * *t.
+ *
+ * get_string used for scanning both string literals and keywords.
+ *
+ * Characters from *p are copied into t-val until a character equal to
+ * delim is found, or a NUL byte is reached. If delim has the special value of
+ * ' ', any whitespace character will be used as a delimiter.
+ *
+ * If lower is unequal to 0, uppercase characters will be converted to
+ * lowercase in the result. This is useful to make keywords case
+ * insensitive.
+ *
+ * The location of *p is updated to point to the first character after the end
+ * of the token - the ending delimiter.
+ *
+ * On success, the new value of t->val is returned. Memory for t->val is
+ * allocated using malloc and must be free()'d to reclaim it.  If insufficient
+ * memory is available, NULL is returned.
+ */
+static char *get_string(char **p, struct token *t, char delim, int lower)
+{
+       char *b, *e;
+       size_t len, i;
+
+       /*
+        * b and e both start at the beginning of the input stream.
+        *
+        * e is incremented until we find the ending delimiter, or a NUL byte
+        * is reached. Then, we take e - b to find the length of the token.
+        */
+       b = e = *p;
+
+       while (*e) {
+               if ((delim == ' ' && isspace(*e)) || delim == *e)
+                       break;
+               e++;
+       }
+
+       len = e - b;
+
+       /*
+        * Allocate memory to hold the string, and copy it in, converting
+        * characters to lowercase if lower is != 0.
+        */
+       t->val = malloc(len + 1);
+       if (!t->val)
+               return NULL;
+
+       for (i = 0; i < len; i++, b++) {
+               if (lower)
+                       t->val[i] = tolower(*b);
+               else
+                       t->val[i] = *b;
+       }
+
+       t->val[len] = '\0';
+
+       /*
+        * Update *p so the caller knows where to continue scanning.
+        */
+       *p = e;
+
+       t->type = T_STRING;
+
+       return t->val;
+}
+
+/*
+ * Populate a keyword token with a type and value.
+ */
+static void get_keyword(struct token *t)
+{
+       int i;
+
+       for (i = 0; keywords[i].val; i++) {
+               if (!strcmp(t->val, keywords[i].val)) {
+                       t->type = keywords[i].type;
+                       break;
+               }
+       }
+}
+
+/*
+ * Get the next token.  We have to keep track of which state we're in to know
+ * if we're looking to get a string literal or a keyword.
+ *
+ * *p is updated to point at the first character after the current token.
+ */
+static void get_token(char **p, struct token *t, enum lex_state state)
+{
+       char *c = *p;
+
+       t->type = T_INVALID;
+
+       /* eat non EOL whitespace */
+       while (isblank(*c))
+               c++;
+
+       /*
+        * eat comments. note that string literals can't begin with #, but
+        * can contain a # after their first character.
+        */
+       if (*c == '#') {
+               while (*c && *c != '\n')
+                       c++;
+       }
+
+       if (*c == '\n') {
+               t->type = T_EOL;
+               c++;
+       } else if (*c == '\0') {
+               t->type = T_EOF;
+               c++;
+       } else if (state == L_SLITERAL) {
+               get_string(&c, t, '\n', 0);
+       } else if (state == L_KEYWORD) {
+               /*
+                * when we expect a keyword, we first get the next string
+                * token delimited by whitespace, and then check if it
+                * matches a keyword in our keyword list. if it does, it's
+                * converted to a keyword token of the appropriate type, and
+                * if not, it remains a string token.
+                */
+               get_string(&c, t, ' ', 1);
+               get_keyword(t);
+       }
+
+       *p = c;
+}
+
+/*
+ * Increment *c until we get to the end of the current line, or EOF.
+ */
+static void eol_or_eof(char **c)
+{
+       while (**c && **c != '\n')
+               (*c)++;
+}
+
+/*
+ * All of these parse_* functions share some common behavior.
+ *
+ * They finish with *c pointing after the token they parse, and return 1 on
+ * success, or < 0 on error.
+ */
+
+/*
+ * Parse a string literal and store a pointer it at *dst. String literals
+ * terminate at the end of the line.
+ */
+static int parse_sliteral(char **c, char **dst)
+{
+       struct token t;
+       char *s = *c;
+
+       get_token(c, &t, L_SLITERAL);
+
+       if (t.type != T_STRING) {
+               printf("Expected string literal: %.*s\n", (int)(*c - s), s);
+               return -EINVAL;
+       }
+
+       *dst = t.val;
+
+       return 1;
+}
+
+/*
+ * Parse a base 10 (unsigned) integer and store it at *dst.
+ */
+static int parse_integer(char **c, int *dst)
+{
+       struct token t;
+       char *s = *c;
+
+       get_token(c, &t, L_SLITERAL);
+
+       if (t.type != T_STRING) {
+               printf("Expected string: %.*s\n", (int)(*c - s), s);
+               return -EINVAL;
+       }
+
+       *dst = simple_strtol(t.val, NULL, 10);
+
+       free(t.val);
+
+       return 1;
+}
+
+static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
+       struct pxe_menu *cfg, int nest_level);
+
+/*
+ * Parse an include statement, and retrieve and parse the file it mentions.
+ *
+ * base should point to a location where it's safe to store the file, and
+ * nest_level should indicate how many nested includes have occurred. For this
+ * include, nest_level has already been incremented and doesn't need to be
+ * incremented here.
+ */
+static int handle_include(cmd_tbl_t *cmdtp, char **c, unsigned long base,
+                               struct pxe_menu *cfg, int nest_level)
+{
+       char *include_path;
+       char *s = *c;
+       int err;
+       char *buf;
+       int ret;
+
+       err = parse_sliteral(c, &include_path);
+
+       if (err < 0) {
+               printf("Expected include path: %.*s\n",
+                                (int)(*c - s), s);
+               return err;
+       }
+
+       err = get_pxe_file(cmdtp, include_path, base);
+
+       if (err < 0) {
+               printf("Couldn't retrieve %s\n", include_path);
+               return err;
+       }
+
+       buf = map_sysmem(base, 0);
+       ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
+       unmap_sysmem(buf);
+
+       return ret;
+}
+
+/*
+ * Parse lines that begin with 'menu'.
+ *
+ * base and nest are provided to handle the 'menu include' case.
+ *
+ * base should point to a location where it's safe to store the included file.
+ *
+ * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
+ * a file it includes, 3 when parsing a file included by that file, and so on.
+ */
+static int parse_menu(cmd_tbl_t *cmdtp, char **c, struct pxe_menu *cfg,
+                               unsigned long base, int nest_level)
+{
+       struct token t;
+       char *s = *c;
+       int err = 0;
+
+       get_token(c, &t, L_KEYWORD);
+
+       switch (t.type) {
+       case T_TITLE:
+               err = parse_sliteral(c, &cfg->title);
+
+               break;
+
+       case T_INCLUDE:
+               err = handle_include(cmdtp, c, base, cfg,
+                                               nest_level + 1);
+               break;
+
+       default:
+               printf("Ignoring malformed menu command: %.*s\n",
+                               (int)(*c - s), s);
+       }
+
+       if (err < 0)
+               return err;
+
+       eol_or_eof(c);
+
+       return 1;
+}
+
+/*
+ * Handles parsing a 'menu line' when we're parsing a label.
+ */
+static int parse_label_menu(char **c, struct pxe_menu *cfg,
+                               struct pxe_label *label)
+{
+       struct token t;
+       char *s;
+
+       s = *c;
+
+       get_token(c, &t, L_KEYWORD);
+
+       switch (t.type) {
+       case T_DEFAULT:
+               if (!cfg->default_label)
+                       cfg->default_label = strdup(label->name);
+
+               if (!cfg->default_label)
+                       return -ENOMEM;
+
+               break;
+       case T_LABEL:
+               parse_sliteral(c, &label->menu);
+               break;
+       default:
+               printf("Ignoring malformed menu command: %.*s\n",
+                               (int)(*c - s), s);
+       }
+
+       eol_or_eof(c);
+
+       return 0;
+}
+
+/*
+ * Parses a label and adds it to the list of labels for a menu.
+ *
+ * A label ends when we either get to the end of a file, or
+ * get some input we otherwise don't have a handler defined
+ * for.
+ *
+ */
+static int parse_label(char **c, struct pxe_menu *cfg)
+{
+       struct token t;
+       int len;
+       char *s = *c;
+       struct pxe_label *label;
+       int err;
+
+       label = label_create();
+       if (!label)
+               return -ENOMEM;
+
+       err = parse_sliteral(c, &label->name);
+       if (err < 0) {
+               printf("Expected label name: %.*s\n", (int)(*c - s), s);
+               label_destroy(label);
+               return -EINVAL;
+       }
+
+       list_add_tail(&label->list, &cfg->labels);
+
+       while (1) {
+               s = *c;
+               get_token(c, &t, L_KEYWORD);
+
+               err = 0;
+               switch (t.type) {
+               case T_MENU:
+                       err = parse_label_menu(c, cfg, label);
+                       break;
+
+               case T_KERNEL:
+               case T_LINUX:
+                       err = parse_sliteral(c, &label->kernel);
+                       break;
+
+               case T_APPEND:
+                       err = parse_sliteral(c, &label->append);
+                       if (label->initrd)
+                               break;
+                       s = strstr(label->append, "initrd=");
+                       if (!s)
+                               break;
+                       s += 7;
+                       len = (int)(strchr(s, ' ') - s);
+                       label->initrd = malloc(len + 1);
+                       strncpy(label->initrd, s, len);
+                       label->initrd[len] = '\0';
+
+                       break;
+
+               case T_INITRD:
+                       if (!label->initrd)
+                               err = parse_sliteral(c, &label->initrd);
+                       break;
+
+               case T_FDT:
+                       if (!label->fdt)
+                               err = parse_sliteral(c, &label->fdt);
+                       break;
+
+               case T_FDTDIR:
+                       if (!label->fdtdir)
+                               err = parse_sliteral(c, &label->fdtdir);
+                       break;
+
+               case T_LOCALBOOT:
+                       label->localboot = 1;
+                       err = parse_integer(c, &label->localboot_val);
+                       break;
+
+               case T_IPAPPEND:
+                       err = parse_integer(c, &label->ipappend);
+                       break;
+
+               case T_EOL:
+                       break;
+
+               default:
+                       /*
+                        * put the token back! we don't want it - it's the end
+                        * of a label and whatever token this is, it's
+                        * something for the menu level context to handle.
+                        */
+                       *c = s;
+                       return 1;
+               }
+
+               if (err < 0)
+                       return err;
+       }
+}
+
+/*
+ * This 16 comes from the limit pxelinux imposes on nested includes.
+ *
+ * There is no reason at all we couldn't do more, but some limit helps prevent
+ * infinite (until crash occurs) recursion if a file tries to include itself.
+ */
+#define MAX_NEST_LEVEL 16
+
+/*
+ * Entry point for parsing a menu file. nest_level indicates how many times
+ * we've nested in includes.  It will be 1 for the top level menu file.
+ *
+ * Returns 1 on success, < 0 on error.
+ */
+static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
+                               struct pxe_menu *cfg, int nest_level)
+{
+       struct token t;
+       char *s, *b, *label_name;
+       int err;
+
+       b = p;
+
+       if (nest_level > MAX_NEST_LEVEL) {
+               printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
+               return -EMLINK;
+       }
+
+       while (1) {
+               s = p;
+
+               get_token(&p, &t, L_KEYWORD);
+
+               err = 0;
+               switch (t.type) {
+               case T_MENU:
+                       cfg->prompt = 1;
+                       err = parse_menu(cmdtp, &p, cfg,
+                               base + ALIGN(strlen(b) + 1, 4),
+                               nest_level);
+                       break;
+
+               case T_TIMEOUT:
+                       err = parse_integer(&p, &cfg->timeout);
+                       break;
+
+               case T_LABEL:
+                       err = parse_label(&p, cfg);
+                       break;
+
+               case T_DEFAULT:
+               case T_ONTIMEOUT:
+                       err = parse_sliteral(&p, &label_name);
+
+                       if (label_name) {
+                               if (cfg->default_label)
+                                       free(cfg->default_label);
+
+                               cfg->default_label = label_name;
+                       }
+
+                       break;
+
+               case T_INCLUDE:
+                       err = handle_include(cmdtp, &p,
+                               base + ALIGN(strlen(b), 4), cfg,
+                               nest_level + 1);
+                       break;
+
+               case T_PROMPT:
+                       eol_or_eof(&p);
+                       break;
+
+               case T_EOL:
+                       break;
+
+               case T_EOF:
+                       return 1;
+
+               default:
+                       printf("Ignoring unknown command: %.*s\n",
+                                                       (int)(p - s), s);
+                       eol_or_eof(&p);
+               }
+
+               if (err < 0)
+                       return err;
+       }
+}
+
+/*
+ * Free the memory used by a pxe_menu and its labels.
+ */
+static void destroy_pxe_menu(struct pxe_menu *cfg)
+{
+       struct list_head *pos, *n;
+       struct pxe_label *label;
+
+       if (cfg->title)
+               free(cfg->title);
+
+       if (cfg->default_label)
+               free(cfg->default_label);
+
+       list_for_each_safe(pos, n, &cfg->labels) {
+               label = list_entry(pos, struct pxe_label, list);
+
+               label_destroy(label);
+       }
+
+       free(cfg);
+}
+
+/*
+ * Entry point for parsing a pxe file. This is only used for the top level
+ * file.
+ *
+ * Returns NULL if there is an error, otherwise, returns a pointer to a
+ * pxe_menu struct populated with the results of parsing the pxe file (and any
+ * files it includes). The resulting pxe_menu struct can be free()'d by using
+ * the destroy_pxe_menu() function.
+ */
+static struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg)
+{
+       struct pxe_menu *cfg;
+       char *buf;
+       int r;
+
+       cfg = malloc(sizeof(struct pxe_menu));
+
+       if (!cfg)
+               return NULL;
+
+       memset(cfg, 0, sizeof(struct pxe_menu));
+
+       INIT_LIST_HEAD(&cfg->labels);
+
+       buf = map_sysmem(menucfg, 0);
+       r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
+       unmap_sysmem(buf);
+
+       if (r < 0) {
+               destroy_pxe_menu(cfg);
+               return NULL;
+       }
+
+       return cfg;
+}
+
+/*
+ * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
+ * menu code.
+ */
+static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
+{
+       struct pxe_label *label;
+       struct list_head *pos;
+       struct menu *m;
+       int err;
+       int i = 1;
+       char *default_num = NULL;
+
+       /*
+        * Create a menu and add items for all the labels.
+        */
+       m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print,
+                       NULL, NULL);
+
+       if (!m)
+               return NULL;
+
+       list_for_each(pos, &cfg->labels) {
+               label = list_entry(pos, struct pxe_label, list);
+
+               sprintf(label->num, "%d", i++);
+               if (menu_item_add(m, label->num, label) != 1) {
+                       menu_destroy(m);
+                       return NULL;
+               }
+               if (cfg->default_label &&
+                   (strcmp(label->name, cfg->default_label) == 0))
+                       default_num = label->num;
+
+       }
+
+       /*
+        * After we've created items for each label in the menu, set the
+        * menu's default label if one was specified.
+        */
+       if (default_num) {
+               err = menu_default_set(m, default_num);
+               if (err != 1) {
+                       if (err != -ENOENT) {
+                               menu_destroy(m);
+                               return NULL;
+                       }
+
+                       printf("Missing default: %s\n", cfg->default_label);
+               }
+       }
+
+       return m;
+}
+
+/*
+ * Try to boot any labels we have yet to attempt to boot.
+ */
+static void boot_unattempted_labels(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
+{
+       struct list_head *pos;
+       struct pxe_label *label;
+
+       list_for_each(pos, &cfg->labels) {
+               label = list_entry(pos, struct pxe_label, list);
+
+               if (!label->attempted)
+                       label_boot(cmdtp, label);
+       }
+}
+
+/*
+ * Boot the system as prescribed by a pxe_menu.
+ *
+ * Use the menu system to either get the user's choice or the default, based
+ * on config or user input.  If there is no default or user's choice,
+ * attempted to boot labels in the order they were given in pxe files.
+ * If the default or user's choice fails to boot, attempt to boot other
+ * labels in the order they were given in pxe files.
+ *
+ * If this function returns, there weren't any labels that successfully
+ * booted, or the user interrupted the menu selection via ctrl+c.
+ */
+static void handle_pxe_menu(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
+{
+       void *choice;
+       struct menu *m;
+       int err;
+
+       m = pxe_menu_to_menu(cfg);
+       if (!m)
+               return;
+
+       err = menu_get_choice(m, &choice);
+
+       menu_destroy(m);
+
+       /*
+        * err == 1 means we got a choice back from menu_get_choice.
+        *
+        * err == -ENOENT if the menu was setup to select the default but no
+        * default was set. in that case, we should continue trying to boot
+        * labels that haven't been attempted yet.
+        *
+        * otherwise, the user interrupted or there was some other error and
+        * we give up.
+        */
+
+       if (err == 1) {
+               err = label_boot(cmdtp, choice);
+               if (!err)
+                       return;
+       } else if (err != -ENOENT) {
+               return;
+       }
+
+       boot_unattempted_labels(cmdtp, cfg);
+}
+
+#ifdef CONFIG_CMD_NET
+/*
+ * Boots a system using a pxe file
+ *
+ * Returns 0 on success, 1 on error.
+ */
+static int
+do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long pxefile_addr_r;
+       struct pxe_menu *cfg;
+       char *pxefile_addr_str;
+
+       do_getfile = do_get_tftp;
+
+       if (argc == 1) {
+               pxefile_addr_str = from_env("pxefile_addr_r");
+               if (!pxefile_addr_str)
+                       return 1;
+
+       } else if (argc == 2) {
+               pxefile_addr_str = argv[1];
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
+               printf("Invalid pxefile address: %s\n", pxefile_addr_str);
+               return 1;
+       }
+
+       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+
+       if (cfg == NULL) {
+               printf("Error parsing config file\n");
+               return 1;
+       }
+
+       handle_pxe_menu(cmdtp, cfg);
+
+       destroy_pxe_menu(cfg);
+
+       copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name));
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_pxe_sub[] = {
+       U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
+       U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
+};
+
+static int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *cp;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       is_pxe = true;
+
+       /* drop initial "pxe" arg */
+       argc--;
+       argv++;
+
+       cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
+
+       if (cp)
+               return cp->cmd(cmdtp, flag, argc, argv);
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       pxe, 3, 1, do_pxe,
+       "commands to get and boot from pxe files",
+       "get - try to retrieve a pxe file using tftp\npxe "
+       "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
+);
+#endif
+
+/*
+ * Boots a system using a local disk syslinux/extlinux file
+ *
+ * Returns 0 on success, 1 on error.
+ */
+static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long pxefile_addr_r;
+       struct pxe_menu *cfg;
+       char *pxefile_addr_str;
+       char *filename;
+       int prompt = 0;
+
+       is_pxe = false;
+
+       if (argc > 1 && strstr(argv[1], "-p")) {
+               prompt = 1;
+               argc--;
+               argv++;
+       }
+
+       if (argc < 4)
+               return cmd_usage(cmdtp);
+
+       if (argc < 5) {
+               pxefile_addr_str = from_env("pxefile_addr_r");
+               if (!pxefile_addr_str)
+                       return 1;
+       } else {
+               pxefile_addr_str = argv[4];
+       }
+
+       if (argc < 6)
+               filename = getenv("bootfile");
+       else {
+               filename = argv[5];
+               setenv("bootfile", filename);
+       }
+
+       if (strstr(argv[3], "ext2"))
+               do_getfile = do_get_ext2;
+       else if (strstr(argv[3], "fat"))
+               do_getfile = do_get_fat;
+       else if (strstr(argv[3], "any"))
+               do_getfile = do_get_any;
+       else {
+               printf("Invalid filesystem: %s\n", argv[3]);
+               return 1;
+       }
+       fs_argv[1] = argv[1];
+       fs_argv[2] = argv[2];
+
+       if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
+               printf("Invalid pxefile address: %s\n", pxefile_addr_str);
+               return 1;
+       }
+
+       if (get_pxe_file(cmdtp, filename, pxefile_addr_r) < 0) {
+               printf("Error reading config file\n");
+               return 1;
+       }
+
+       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+
+       if (cfg == NULL) {
+               printf("Error parsing config file\n");
+               return 1;
+       }
+
+       if (prompt)
+               cfg->prompt = 1;
+
+       handle_pxe_menu(cmdtp, cfg);
+
+       destroy_pxe_menu(cfg);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       sysboot, 7, 1, do_sysboot,
+       "command to get and boot from syslinux files",
+       "[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n"
+       "    - load and parse syslinux menu file 'filename' from ext2, fat\n"
+       "      or any filesystem on 'dev' on 'interface' to address 'addr'"
+);
diff --git a/cmd/read.c b/cmd/read.c
new file mode 100644 (file)
index 0000000..8710288
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <part.h>
+
+int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *ep;
+       block_dev_desc_t *dev_desc = NULL;
+       int dev;
+       int part = 0;
+       disk_partition_t part_info;
+       ulong offset = 0u;
+       ulong limit = 0u;
+       void *addr;
+       uint blk;
+       uint cnt;
+
+       if (argc != 6) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       dev = (int)simple_strtoul(argv[2], &ep, 16);
+       if (*ep) {
+               if (*ep != ':') {
+                       printf("Invalid block device %s\n", argv[2]);
+                       return 1;
+               }
+               part = (int)simple_strtoul(++ep, NULL, 16);
+       }
+
+       dev_desc = get_dev(argv[1], dev);
+       if (dev_desc == NULL) {
+               printf("Block device %s %d not supported\n", argv[1], dev);
+               return 1;
+       }
+
+       addr = (void *)simple_strtoul(argv[3], NULL, 16);
+       blk = simple_strtoul(argv[4], NULL, 16);
+       cnt = simple_strtoul(argv[5], NULL, 16);
+
+       if (part != 0) {
+               if (get_partition_info(dev_desc, part, &part_info)) {
+                       printf("Cannot find partition %d\n", part);
+                       return 1;
+               }
+               offset = part_info.start;
+               limit = part_info.size;
+       } else {
+               /* Largest address not available in block_dev_desc_t. */
+               limit = ~0;
+       }
+
+       if (cnt + blk > limit) {
+               printf("Read out of range\n");
+               return 1;
+       }
+
+       if (dev_desc->block_read(dev_desc, offset + blk, cnt, addr) < 0) {
+               printf("Error reading blocks\n");
+               return 1;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       read,   6,      0,      do_read,
+       "Load binary data from a partition",
+       "<interface> <dev[:part]> addr blk# cnt"
+);
diff --git a/cmd/reginfo.c b/cmd/reginfo.c
new file mode 100644 (file)
index 0000000..5f19e79
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * (C) Copyright 2000
+ * Subodh Nijsure, SkyStream Networks, snijsure@skystream.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#if defined(CONFIG_8xx)
+#include <mpc8xx.h>
+#elif defined (CONFIG_4xx)
+extern void ppc4xx_reginfo(void);
+#elif defined (CONFIG_5xx)
+#include <mpc5xx.h>
+#elif defined (CONFIG_MPC5200)
+#include <mpc5xxx.h>
+#elif defined (CONFIG_MPC86xx)
+extern void mpc86xx_reginfo(void);
+#elif defined(CONFIG_MPC85xx)
+extern void mpc85xx_reginfo(void);
+#endif
+
+static int do_reginfo(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char * const argv[])
+{
+#if defined(CONFIG_8xx)
+       volatile immap_t     *immap  = (immap_t *)CONFIG_SYS_IMMR;
+       volatile memctl8xx_t *memctl = &immap->im_memctl;
+       volatile sysconf8xx_t *sysconf = &immap->im_siu_conf;
+       volatile sit8xx_t *timers = &immap->im_sit;
+
+       /* Hopefully more PowerPC  knowledgable people will add code to display
+        * other useful registers
+        */
+
+       printf ("\nSystem Configuration registers\n"
+
+               "\tIMMR\t0x%08X\n", get_immr(0));
+
+       printf("\tSIUMCR\t0x%08X", sysconf->sc_siumcr);
+       printf("\tSYPCR\t0x%08X\n",sysconf->sc_sypcr);
+
+       printf("\tSWT\t0x%08X",    sysconf->sc_swt);
+       printf("\tSWSR\t0x%04X\n", sysconf->sc_swsr);
+
+       printf("\tSIPEND\t0x%08X\tSIMASK\t0x%08X\n",
+               sysconf->sc_sipend, sysconf->sc_simask);
+       printf("\tSIEL\t0x%08X\tSIVEC\t0x%08X\n",
+               sysconf->sc_siel, sysconf->sc_sivec);
+       printf("\tTESR\t0x%08X\tSDCR\t0x%08X\n",
+               sysconf->sc_tesr, sysconf->sc_sdcr);
+
+       printf ("Memory Controller Registers\n"
+
+               "\tBR0\t0x%08X\tOR0\t0x%08X \n", memctl->memc_br0, memctl->memc_or0);
+       printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", memctl->memc_br1, memctl->memc_or1);
+       printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", memctl->memc_br2, memctl->memc_or2);
+       printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", memctl->memc_br3, memctl->memc_or3);
+       printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", memctl->memc_br4, memctl->memc_or4);
+       printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", memctl->memc_br5, memctl->memc_or5);
+       printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", memctl->memc_br6, memctl->memc_or6);
+       printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", memctl->memc_br7, memctl->memc_or7);
+       printf ("\n"
+               "\tmamr\t0x%08X\tmbmr\t0x%08X \n",
+               memctl->memc_mamr, memctl->memc_mbmr );
+       printf("\tmstat\t0x%08X\tmptpr\t0x%08X \n",
+               memctl->memc_mstat, memctl->memc_mptpr );
+       printf("\tmdr\t0x%08X \n", memctl->memc_mdr);
+
+       printf ("\nSystem Integration Timers\n"
+               "\tTBSCR\t0x%08X\tRTCSC\t0x%08X \n",
+               timers->sit_tbscr, timers->sit_rtcsc);
+       printf("\tPISCR\t0x%08X \n", timers->sit_piscr);
+
+       /*
+        * May be some CPM info here?
+        */
+
+#elif defined (CONFIG_4xx)
+       ppc4xx_reginfo();
+#elif defined(CONFIG_5xx)
+
+       volatile immap_t        *immap  = (immap_t *)CONFIG_SYS_IMMR;
+       volatile memctl5xx_t    *memctl = &immap->im_memctl;
+       volatile sysconf5xx_t   *sysconf = &immap->im_siu_conf;
+       volatile sit5xx_t       *timers = &immap->im_sit;
+       volatile car5xx_t       *car = &immap->im_clkrst;
+       volatile uimb5xx_t      *uimb = &immap->im_uimb;
+
+       puts ("\nSystem Configuration registers\n");
+       printf("\tIMMR\t0x%08X\tSIUMCR\t0x%08X \n", get_immr(0), sysconf->sc_siumcr);
+       printf("\tSYPCR\t0x%08X\tSWSR\t0x%04X \n" ,sysconf->sc_sypcr, sysconf->sc_swsr);
+       printf("\tSIPEND\t0x%08X\tSIMASK\t0x%08X \n", sysconf->sc_sipend, sysconf->sc_simask);
+       printf("\tSIEL\t0x%08X\tSIVEC\t0x%08X \n", sysconf->sc_siel, sysconf->sc_sivec);
+       printf("\tTESR\t0x%08X\n", sysconf->sc_tesr);
+
+       puts ("\nMemory Controller Registers\n");
+       printf("\tBR0\t0x%08X\tOR0\t0x%08X \n", memctl->memc_br0, memctl->memc_or0);
+       printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", memctl->memc_br1, memctl->memc_or1);
+       printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", memctl->memc_br2, memctl->memc_or2);
+       printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", memctl->memc_br3, memctl->memc_or3);
+       printf("\tDMBR\t0x%08X\tDMOR\t0x%08X \n", memctl->memc_dmbr, memctl->memc_dmor );
+       printf("\tMSTAT\t0x%08X\n", memctl->memc_mstat);
+
+       puts ("\nSystem Integration Timers\n");
+       printf("\tTBSCR\t0x%08X\tRTCSC\t0x%08X \n", timers->sit_tbscr, timers->sit_rtcsc);
+       printf("\tPISCR\t0x%08X \n", timers->sit_piscr);
+
+       puts ("\nClocks and Reset\n");
+       printf("\tSCCR\t0x%08X\tPLPRCR\t0x%08X \n", car->car_sccr, car->car_plprcr);
+
+       puts ("\nU-Bus to IMB3 Bus Interface\n");
+       printf("\tUMCR\t0x%08X\tUIPEND\t0x%08X \n", uimb->uimb_umcr, uimb->uimb_uipend);
+       puts ("\n\n");
+
+#elif defined(CONFIG_MPC5200)
+       puts ("\nMPC5200 registers\n");
+       printf ("MBAR=%08x\n", CONFIG_SYS_MBAR);
+       puts ("Memory map registers\n");
+       printf ("\tCS0: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS0_START,
+               *(volatile ulong*)MPC5XXX_CS0_STOP,
+               *(volatile ulong*)MPC5XXX_CS0_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00010000) ? 1 : 0);
+       printf ("\tCS1: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS1_START,
+               *(volatile ulong*)MPC5XXX_CS1_STOP,
+               *(volatile ulong*)MPC5XXX_CS1_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00020000) ? 1 : 0);
+       printf ("\tCS2: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS2_START,
+               *(volatile ulong*)MPC5XXX_CS2_STOP,
+               *(volatile ulong*)MPC5XXX_CS2_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00040000) ? 1 : 0);
+       printf ("\tCS3: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS3_START,
+               *(volatile ulong*)MPC5XXX_CS3_STOP,
+               *(volatile ulong*)MPC5XXX_CS3_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00080000) ? 1 : 0);
+       printf ("\tCS4: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS4_START,
+               *(volatile ulong*)MPC5XXX_CS4_STOP,
+               *(volatile ulong*)MPC5XXX_CS4_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00100000) ? 1 : 0);
+       printf ("\tCS5: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS5_START,
+               *(volatile ulong*)MPC5XXX_CS5_STOP,
+               *(volatile ulong*)MPC5XXX_CS5_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00200000) ? 1 : 0);
+       printf ("\tCS6: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS6_START,
+               *(volatile ulong*)MPC5XXX_CS6_STOP,
+               *(volatile ulong*)MPC5XXX_CS6_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x04000000) ? 1 : 0);
+       printf ("\tCS7: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_CS7_START,
+               *(volatile ulong*)MPC5XXX_CS7_STOP,
+               *(volatile ulong*)MPC5XXX_CS7_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x08000000) ? 1 : 0);
+       printf ("\tBOOTCS: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
+               *(volatile ulong*)MPC5XXX_BOOTCS_START,
+               *(volatile ulong*)MPC5XXX_BOOTCS_STOP,
+               *(volatile ulong*)MPC5XXX_BOOTCS_CFG,
+               (*(volatile ulong*)MPC5XXX_ADDECR & 0x02000000) ? 1 : 0);
+       printf ("\tSDRAMCS0: %08lX\n",
+               *(volatile ulong*)MPC5XXX_SDRAM_CS0CFG);
+       printf ("\tSDRAMCS1: %08lX\n",
+               *(volatile ulong*)MPC5XXX_SDRAM_CS1CFG);
+#elif defined(CONFIG_MPC86xx)
+       mpc86xx_reginfo();
+
+#elif defined(CONFIG_MPC85xx)
+       mpc85xx_reginfo();
+
+#elif defined(CONFIG_BLACKFIN)
+       puts("\nSystem Configuration registers\n");
+#ifndef __ADSPBF60x__
+       puts("\nPLL Registers\n");
+       printf("\tPLL_DIV:   0x%04x   PLL_CTL:      0x%04x\n",
+               bfin_read_PLL_DIV(), bfin_read_PLL_CTL());
+       printf("\tPLL_STAT:  0x%04x   PLL_LOCKCNT:  0x%04x\n",
+               bfin_read_PLL_STAT(), bfin_read_PLL_LOCKCNT());
+       printf("\tVR_CTL:    0x%04x\n", bfin_read_VR_CTL());
+
+       puts("\nEBIU AMC Registers\n");
+       printf("\tEBIU_AMGCTL:   0x%04x\n", bfin_read_EBIU_AMGCTL());
+       printf("\tEBIU_AMBCTL0:  0x%08x   EBIU_AMBCTL1:  0x%08x\n",
+               bfin_read_EBIU_AMBCTL0(), bfin_read_EBIU_AMBCTL1());
+# ifdef EBIU_MODE
+       printf("\tEBIU_MBSCTL:   0x%08x   EBIU_ARBSTAT:  0x%08x\n",
+               bfin_read_EBIU_MBSCTL(), bfin_read_EBIU_ARBSTAT());
+       printf("\tEBIU_MODE:     0x%08x   EBIU_FCTL:     0x%08x\n",
+               bfin_read_EBIU_MODE(), bfin_read_EBIU_FCTL());
+# endif
+
+# ifdef EBIU_RSTCTL
+       puts("\nEBIU DDR Registers\n");
+       printf("\tEBIU_DDRCTL0:  0x%08x   EBIU_DDRCTL1:  0x%08x\n",
+               bfin_read_EBIU_DDRCTL0(), bfin_read_EBIU_DDRCTL1());
+       printf("\tEBIU_DDRCTL2:  0x%08x   EBIU_DDRCTL3:  0x%08x\n",
+               bfin_read_EBIU_DDRCTL2(), bfin_read_EBIU_DDRCTL3());
+       printf("\tEBIU_DDRQUE:   0x%08x   EBIU_RSTCTL    0x%04x\n",
+               bfin_read_EBIU_DDRQUE(), bfin_read_EBIU_RSTCTL());
+       printf("\tEBIU_ERRADD:   0x%08x   EBIU_ERRMST:   0x%04x\n",
+               bfin_read_EBIU_ERRADD(), bfin_read_EBIU_ERRMST());
+# else
+       puts("\nEBIU SDC Registers\n");
+       printf("\tEBIU_SDRRC:   0x%04x   EBIU_SDBCTL:  0x%04x\n",
+               bfin_read_EBIU_SDRRC(), bfin_read_EBIU_SDBCTL());
+       printf("\tEBIU_SDSTAT:  0x%04x   EBIU_SDGCTL:  0x%08x\n",
+               bfin_read_EBIU_SDSTAT(), bfin_read_EBIU_SDGCTL());
+# endif
+#else
+       puts("\nCGU Registers\n");
+       printf("\tCGU_DIV:   0x%08x   CGU_CTL:      0x%08x\n",
+               bfin_read_CGU_DIV(), bfin_read_CGU_CTL());
+       printf("\tCGU_STAT:  0x%08x   CGU_LOCKCNT:  0x%08x\n",
+               bfin_read_CGU_STAT(), bfin_read_CGU_CLKOUTSEL());
+
+       puts("\nSMC DDR Registers\n");
+       printf("\tDDR_CFG:   0x%08x   DDR_TR0:      0x%08x\n",
+               bfin_read_DMC0_CFG(), bfin_read_DMC0_TR0());
+       printf("\tDDR_TR1:   0x%08x   DDR_TR2:      0x%08x\n",
+               bfin_read_DMC0_TR1(), bfin_read_DMC0_TR2());
+       printf("\tDDR_MR:    0x%08x   DDR_EMR1:     0x%08x\n",
+               bfin_read_DMC0_MR(), bfin_read_DMC0_EMR1());
+       printf("\tDDR_CTL:   0x%08x   DDR_STAT:     0x%08x\n",
+               bfin_read_DMC0_CTL(), bfin_read_DMC0_STAT());
+       printf("\tDDR_DLLCTL:0x%08x\n", bfin_read_DMC0_DLLCTL());
+#endif
+#endif /* CONFIG_BLACKFIN */
+
+       return 0;
+}
+
+ /**************************************************/
+
+#if defined(CONFIG_CMD_REGINFO)
+U_BOOT_CMD(
+       reginfo,        2,      1,      do_reginfo,
+       "print register information",
+       ""
+);
+#endif
diff --git a/cmd/regulator.c b/cmd/regulator.c
new file mode 100644 (file)
index 0000000..bfea6e0
--- /dev/null
@@ -0,0 +1,455 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+#include <power/regulator.h>
+
+#define LIMIT_DEVNAME  20
+#define LIMIT_OFNAME   32
+#define LIMIT_INFO     18
+
+static struct udevice *currdev;
+
+static int failure(int ret)
+{
+       printf("Error: %d (%s)\n", ret, errno_str(ret));
+
+       return CMD_RET_FAILURE;
+}
+
+static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       const char *name;
+       int ret = -ENXIO;
+
+       switch (argc) {
+       case 2:
+               name = argv[1];
+               ret = regulator_get_by_platname(name, &currdev);
+               if (ret) {
+                       printf("Can't get the regulator: %s!\n", name);
+                       return failure(ret);
+               }
+       case 1:
+               if (!currdev) {
+                       printf("Regulator device is not set!\n\n");
+                       return CMD_RET_USAGE;
+               }
+
+               uc_pdata = dev_get_uclass_platdata(currdev);
+               if (!uc_pdata) {
+                       printf("%s: no regulator platform data!\n", currdev->name);
+                       return failure(ret);
+               }
+
+               printf("dev: %s @ %s\n", uc_pdata->name, currdev->name);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int curr_dev_and_platdata(struct udevice **devp,
+                                struct dm_regulator_uclass_platdata **uc_pdata,
+                                bool allow_type_fixed)
+{
+       *devp = NULL;
+       *uc_pdata = NULL;
+
+       if (!currdev) {
+               printf("First, set the regulator device!\n");
+               return CMD_RET_FAILURE;
+       }
+
+       *devp = currdev;
+
+       *uc_pdata = dev_get_uclass_platdata(*devp);
+       if (!*uc_pdata) {
+               error("Regulator: %s - missing platform data!", currdev->name);
+               return CMD_RET_FAILURE;
+       }
+
+       if (!allow_type_fixed && (*uc_pdata)->type == REGULATOR_TYPE_FIXED) {
+               printf("Operation not allowed for fixed regulator!\n");
+               return CMD_RET_FAILURE;
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       struct udevice *dev;
+       int ret;
+
+       printf("| %-*.*s| %-*.*s| %s\n",
+              LIMIT_DEVNAME, LIMIT_DEVNAME, "Device",
+              LIMIT_OFNAME, LIMIT_OFNAME, "regulator-name",
+              "Parent");
+
+       for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
+            ret = uclass_find_next_device(&dev)) {
+               if (ret)
+                       continue;
+
+               uc_pdata = dev_get_uclass_platdata(dev);
+               printf("| %-*.*s| %-*.*s| %s\n",
+                      LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name,
+                      LIMIT_OFNAME, LIMIT_OFNAME, uc_pdata->name,
+                      dev->parent->name);
+       }
+
+       return ret;
+}
+
+static int constraint(const char *name, int val, const char *val_name)
+{
+       printf("%-*s", LIMIT_INFO, name);
+       if (val < 0) {
+               printf(" %s (err: %d)\n", errno_str(val), val);
+               return val;
+       }
+
+       if (val_name)
+               printf(" %d (%s)\n", val, val_name);
+       else
+               printf(" %d\n", val);
+
+       return 0;
+}
+
+static const char *get_mode_name(struct dm_regulator_mode *mode,
+                                int mode_count,
+                                int mode_id)
+{
+       while (mode_count--) {
+               if (mode->id == mode_id)
+                       return mode->name;
+               mode++;
+       }
+
+       return NULL;
+}
+
+static int do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       struct dm_regulator_mode *modes;
+       const char *parent_uc;
+       int mode_count;
+       int ret;
+       int i;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
+       if (ret)
+               return ret;
+
+       parent_uc = dev_get_uclass_name(dev->parent);
+
+       printf("%s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s\n",
+              "Regulator info:",
+              LIMIT_INFO, "* regulator-name:", uc_pdata->name,
+              LIMIT_INFO, "* device name:", dev->name,
+              LIMIT_INFO, "* parent name:", dev->parent->name,
+              LIMIT_INFO, "* parent uclass:", parent_uc,
+              LIMIT_INFO, "* constraints:");
+
+       constraint("  - min uV:", uc_pdata->min_uV, NULL);
+       constraint("  - max uV:", uc_pdata->max_uV, NULL);
+       constraint("  - min uA:", uc_pdata->min_uA, NULL);
+       constraint("  - max uA:", uc_pdata->max_uA, NULL);
+       constraint("  - always on:", uc_pdata->always_on,
+                  uc_pdata->always_on ? "true" : "false");
+       constraint("  - boot on:", uc_pdata->boot_on,
+                  uc_pdata->boot_on ? "true" : "false");
+
+       mode_count = regulator_mode(dev, &modes);
+       constraint("* op modes:", mode_count, NULL);
+
+       for (i = 0; i < mode_count; i++, modes++)
+               constraint("  - mode id:", modes->id, modes->name);
+
+       return CMD_RET_SUCCESS;
+}
+
+static void do_status_detail(struct udevice *dev,
+                            struct dm_regulator_uclass_platdata *uc_pdata)
+{
+       int current, value, mode;
+       const char *mode_name;
+       bool enabled;
+
+       printf("Regulator %s status:\n", uc_pdata->name);
+
+       enabled = regulator_get_enable(dev);
+       constraint(" * enable:", enabled, enabled ? "true" : "false");
+
+       value = regulator_get_value(dev);
+       constraint(" * value uV:", value, NULL);
+
+       current = regulator_get_current(dev);
+       constraint(" * current uA:", current, NULL);
+
+       mode = regulator_get_mode(dev);
+       mode_name = get_mode_name(uc_pdata->mode, uc_pdata->mode_count, mode);
+       constraint(" * mode id:", mode, mode_name);
+}
+
+static void do_status_line(struct udevice *dev)
+{
+       struct dm_regulator_uclass_platdata *pdata;
+       int current, value, mode;
+       const char *mode_name;
+       bool enabled;
+
+       pdata = dev_get_uclass_platdata(dev);
+       enabled = regulator_get_enable(dev);
+       value = regulator_get_value(dev);
+       current = regulator_get_current(dev);
+       mode = regulator_get_mode(dev);
+       mode_name = get_mode_name(pdata->mode, pdata->mode_count, mode);
+       printf("%-20s %-10s ", pdata->name, enabled ? "enabled" : "disabled");
+       if (value >= 0)
+               printf("%10d ", value);
+       else
+               printf("%10s ", "-");
+       if (current >= 0)
+               printf("%10d ", current);
+       else
+               printf("%10s ", "-");
+       if (mode >= 0)
+               printf("%-10s", mode_name);
+       else
+               printf("%-10s", "-");
+       printf("\n");
+}
+
+static int do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       struct udevice *dev;
+       int ret;
+
+       if (currdev && (argc < 2 || strcmp(argv[1], "-a"))) {
+               ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
+               if (ret)
+                       return CMD_RET_FAILURE;
+               do_status_detail(dev, uc_pdata);
+               return 0;
+       }
+
+       /* Show all of them in a list, probing them as needed */
+       printf("%-20s %-10s %10s %10s %-10s\n", "Name", "Enabled", "uV", "mA",
+              "Mode");
+       for (ret = uclass_first_device(UCLASS_REGULATOR, &dev); dev;
+            ret = uclass_next_device(&dev))
+               do_status_line(dev);
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       int value;
+       int force;
+       int ret;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1);
+       if (ret)
+               return ret;
+
+       if (argc == 1) {
+               ret = regulator_get_value(dev);
+               if (ret < 0) {
+                       printf("Regulator: %s - can't get the Voltage!\n",
+                              uc_pdata->name);
+                       return failure(ret);
+               }
+
+               printf("%d uV\n", ret);
+               return CMD_RET_SUCCESS;
+       }
+
+       if (argc == 3)
+               force = !strcmp("-f", argv[2]);
+       else
+               force = 0;
+
+       value = simple_strtoul(argv[1], NULL, 0);
+       if ((value < uc_pdata->min_uV || value > uc_pdata->max_uV) && !force) {
+               printf("Value exceeds regulator constraint limits %d..%d uV\n",
+                      uc_pdata->min_uV, uc_pdata->max_uV);
+               return CMD_RET_FAILURE;
+       }
+
+       ret = regulator_set_value(dev, value);
+       if (ret) {
+               printf("Regulator: %s - can't set the Voltage!\n",
+                      uc_pdata->name);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_current(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       int current;
+       int ret;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1);
+       if (ret)
+               return ret;
+
+       if (argc == 1) {
+               ret = regulator_get_current(dev);
+               if (ret < 0) {
+                       printf("Regulator: %s - can't get the Current!\n",
+                              uc_pdata->name);
+                       return failure(ret);
+               }
+
+               printf("%d uA\n", ret);
+               return CMD_RET_SUCCESS;
+       }
+
+       current = simple_strtoul(argv[1], NULL, 0);
+       if (current < uc_pdata->min_uA || current > uc_pdata->max_uA) {
+               printf("Current exceeds regulator constraint limits\n");
+               return CMD_RET_FAILURE;
+       }
+
+       ret = regulator_set_current(dev, current);
+       if (ret) {
+               printf("Regulator: %s - can't set the Current!\n",
+                      uc_pdata->name);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_mode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       int mode;
+       int ret;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, false);
+       if (ret)
+               return ret;
+
+       if (argc == 1) {
+               ret = regulator_get_mode(dev);
+               if (ret < 0) {
+                       printf("Regulator: %s - can't get the operation mode!\n",
+                              uc_pdata->name);
+                       return failure(ret);
+               }
+
+               printf("mode id: %d\n", ret);
+               return CMD_RET_SUCCESS;
+       }
+
+       mode = simple_strtoul(argv[1], NULL, 0);
+
+       ret = regulator_set_mode(dev, mode);
+       if (ret) {
+               printf("Regulator: %s - can't set the operation mode!\n",
+                      uc_pdata->name);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_enable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       int ret;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
+       if (ret)
+               return ret;
+
+       ret = regulator_set_enable(dev, true);
+       if (ret) {
+               printf("Regulator: %s - can't enable!\n", uc_pdata->name);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_disable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct udevice *dev;
+       struct dm_regulator_uclass_platdata *uc_pdata;
+       int ret;
+
+       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
+       if (ret)
+               return ret;
+
+       ret = regulator_set_enable(dev, false);
+       if (ret) {
+               printf("Regulator: %s - can't disable!\n", uc_pdata->name);
+               return failure(ret);
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+static cmd_tbl_t subcmd[] = {
+       U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""),
+       U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
+       U_BOOT_CMD_MKENT(info, 2, 1, do_info, "", ""),
+       U_BOOT_CMD_MKENT(status, 2, 1, do_status, "", ""),
+       U_BOOT_CMD_MKENT(value, 3, 1, do_value, "", ""),
+       U_BOOT_CMD_MKENT(current, 3, 1, do_current, "", ""),
+       U_BOOT_CMD_MKENT(mode, 2, 1, do_mode, "", ""),
+       U_BOOT_CMD_MKENT(enable, 1, 1, do_enable, "", ""),
+       U_BOOT_CMD_MKENT(disable, 1, 1, do_disable, "", ""),
+};
+
+static int do_regulator(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       cmd_tbl_t *cmd;
+
+       argc--;
+       argv++;
+
+       cmd = find_cmd_tbl(argv[0], subcmd, ARRAY_SIZE(subcmd));
+       if (cmd == NULL || argc > cmd->maxargs)
+               return CMD_RET_USAGE;
+
+       return cmd->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(regulator, CONFIG_SYS_MAXARGS, 1, do_regulator,
+       "uclass operations",
+       "list             - list UCLASS regulator devices\n"
+       "regulator dev [regulator-name] - show/[set] operating regulator device\n"
+       "regulator info                 - print constraints info\n"
+       "regulator status [-a]          - print operating status [for all]\n"
+       "regulator value [val] [-f]     - print/[set] voltage value [uV] (force)\n"
+       "regulator current [val]        - print/[set] current value [uA]\n"
+       "regulator mode [id]            - print/[set] operating mode id\n"
+       "regulator enable               - enable the regulator output\n"
+       "regulator disable              - disable the regulator output\n"
+);
diff --git a/cmd/reiser.c b/cmd/reiser.c
new file mode 100644 (file)
index 0000000..8871564
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Reiserfs support
+ */
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <reiserfs.h>
+#include <part.h>
+
+#ifndef CONFIG_DOS_PARTITION
+#error DOS partition support must be selected
+#endif
+
+/* #define     REISER_DEBUG */
+
+#ifdef REISER_DEBUG
+#define        PRINTF(fmt,args...)     printf (fmt ,##args)
+#else
+#define PRINTF(fmt,args...)
+#endif
+
+int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename = "/";
+       int dev, part;
+       block_dev_desc_t *dev_desc=NULL;
+       disk_partition_t info;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       if (argc == 4) {
+           filename = argv[3];
+       }
+
+       dev = dev_desc->dev;
+       PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
+
+       reiserfs_set_blk_dev(dev_desc, &info);
+
+       if (!reiserfs_mount(info.size)) {
+               printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
+               return 1;
+       }
+
+       if (reiserfs_ls (filename)) {
+               printf ("** Error reiserfs_ls() **\n");
+               return 1;
+       };
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       reiserls,       4,      1,      do_reiserls,
+       "list files in a directory (default /)",
+       "<interface> <dev[:part]> [directory]\n"
+       "    - list files from 'dev' on 'interface' in a 'directory'"
+);
+
+/******************************************************************************
+ * Reiserfs boot command intepreter. Derived from diskboot
+ */
+int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename = NULL;
+       int dev, part;
+       ulong addr = 0, filelen;
+       disk_partition_t info;
+       block_dev_desc_t *dev_desc = NULL;
+       unsigned long count;
+       char *addr_str;
+
+       switch (argc) {
+       case 3:
+               addr_str = getenv("loadaddr");
+               if (addr_str != NULL) {
+                       addr = simple_strtoul (addr_str, NULL, 16);
+               } else {
+                       addr = CONFIG_SYS_LOAD_ADDR;
+               }
+               filename = getenv ("bootfile");
+               count = 0;
+               break;
+       case 4:
+               addr = simple_strtoul (argv[3], NULL, 16);
+               filename = getenv ("bootfile");
+               count = 0;
+               break;
+       case 5:
+               addr = simple_strtoul (argv[3], NULL, 16);
+               filename = argv[4];
+               count = 0;
+               break;
+       case 6:
+               addr = simple_strtoul (argv[3], NULL, 16);
+               filename = argv[4];
+               count = simple_strtoul (argv[5], NULL, 16);
+               break;
+
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       if (!filename) {
+               puts ("\n** No boot file defined **\n");
+               return 1;
+       }
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       dev = dev_desc->dev;
+
+       printf("Loading file \"%s\" from %s device %d%c%c\n",
+               filename, argv[1], dev,
+               part ? ':' : ' ', part ? part + '0' : ' ');
+
+       reiserfs_set_blk_dev(dev_desc, &info);
+
+       if (!reiserfs_mount(info.size)) {
+               printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
+               return 1;
+       }
+
+       filelen = reiserfs_open(filename);
+       if (filelen < 0) {
+               printf("** File not found %s **\n", filename);
+               return 1;
+       }
+       if ((count < filelen) && (count != 0)) {
+           filelen = count;
+       }
+
+       if (reiserfs_read((char *)addr, filelen) != filelen) {
+               printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
+               return 1;
+       }
+
+       /* Loading ok, update default load address */
+       load_addr = addr;
+
+       printf ("\n%ld bytes read\n", filelen);
+       setenv_hex("filesize", filelen);
+
+       return filelen;
+}
+
+U_BOOT_CMD(
+       reiserload,     6,      0,      do_reiserload,
+       "load binary file from a Reiser filesystem",
+       "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
+       "    - load binary file 'filename' from 'dev' on 'interface'\n"
+       "      to address 'addr' from dos filesystem"
+);
diff --git a/cmd/remoteproc.c b/cmd/remoteproc.c
new file mode 100644 (file)
index 0000000..794a406
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated - http://www.ti.com/
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <remoteproc.h>
+
+/**
+ * print_remoteproc_list() - print all the remote processor devices
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int print_remoteproc_list(void)
+{
+       struct udevice *dev;
+       struct uclass *uc;
+       int ret;
+       char *type;
+
+       ret = uclass_get(UCLASS_REMOTEPROC, &uc);
+       if (ret) {
+               printf("Cannot find Remote processor class\n");
+               return ret;
+       }
+
+       uclass_foreach_dev(dev, uc) {
+               struct dm_rproc_uclass_pdata *uc_pdata;
+               const struct dm_rproc_ops *ops = rproc_get_ops(dev);
+
+               uc_pdata = dev_get_uclass_platdata(dev);
+
+               switch (uc_pdata->mem_type) {
+               case RPROC_INTERNAL_MEMORY_MAPPED:
+                       type = "internal memory mapped";
+                       break;
+               default:
+                       type = "unknown";
+                       break;
+               }
+               printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
+                      dev->seq,
+                      uc_pdata->name,
+                      type,
+                      ops->load ? "load " : "",
+                      ops->start ? "start " : "",
+                      ops->stop ? "stop " : "",
+                      ops->reset ? "reset " : "",
+                      ops->is_running ? "is_running " : "",
+                      ops->ping ? "ping " : "");
+       }
+       return 0;
+}
+
+/**
+ * do_rproc_init() - do basic initialization
+ * @cmdtp:     unused
+ * @flag:      unused
+ * @argc:      unused
+ * @argv:      unused
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int do_rproc_init(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char *const argv[])
+{
+       if (rproc_is_initialized()) {
+               printf("\tRemote Processors are already initialized\n");
+       } else {
+               if (!rproc_init())
+                       return 0;
+               printf("Few Remote Processors failed to be initalized\n");
+       }
+
+       return CMD_RET_FAILURE;
+}
+
+/**
+ * do_remoteproc_list() - print list of remote proc devices.
+ * @cmdtp:     unused
+ * @flag:      unused
+ * @argc:      unused
+ * @argv:      unused
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int do_remoteproc_list(cmd_tbl_t *cmdtp, int flag, int argc,
+                             char *const argv[])
+{
+       if (!rproc_is_initialized()) {
+               printf("\t Remote Processors is not initialized\n");
+               return CMD_RET_USAGE;
+       }
+
+       if (print_remoteproc_list())
+               return CMD_RET_FAILURE;
+
+       return 0;
+}
+
+/**
+ * do_remoteproc_load() - Load a remote processor with binary image
+ * @cmdtp:     unused
+ * @flag:      unused
+ * @argc:      argument count for the load function
+ * @argv:      arguments for the load function
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int do_remoteproc_load(cmd_tbl_t *cmdtp, int flag, int argc,
+                             char *const argv[])
+{
+       ulong addr, size;
+       int id, ret;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       id = (int)simple_strtoul(argv[1], NULL, 3);
+       addr = simple_strtoul(argv[2], NULL, 16);
+
+       size = simple_strtoul(argv[3], NULL, 16);
+
+       if (!size) {
+               printf("\t Expect some size??\n");
+               return CMD_RET_USAGE;
+       }
+
+       if (!rproc_is_initialized()) {
+               printf("\tRemote Processors are not initialized\n");
+               return CMD_RET_USAGE;
+       }
+
+       ret = rproc_load(id, addr, size);
+       printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
+              id, addr, size, ret ? " Failed!" : " Success!");
+
+       return ret ? CMD_RET_FAILURE : 0;
+}
+
+/**
+ * do_remoteproc_wrapper() - wrapper for various  rproc commands
+ * @cmdtp:     unused
+ * @flag:      unused
+ * @argc:      argument count for the rproc command
+ * @argv:      arguments for the rproc command
+ *
+ * Most of the commands just take id as a parameter andinvoke various
+ * helper routines in remote processor core. by using a set of
+ * common checks, we can reduce the amount of code used for this.
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int do_remoteproc_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+                                char *const argv[])
+{
+       int id, ret = CMD_RET_USAGE;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       id = (int)simple_strtoul(argv[1], NULL, 3);
+
+       if (!rproc_is_initialized()) {
+               printf("\tRemote Processors are not initialized\n");
+               return CMD_RET_USAGE;
+       }
+
+       if (!strcmp(argv[0], "start")) {
+               ret = rproc_start(id);
+       } else if (!strcmp(argv[0], "stop")) {
+               ret = rproc_stop(id);
+       } else if (!strcmp(argv[0], "reset")) {
+               ret = rproc_reset(id);
+       } else if (!strcmp(argv[0], "is_running")) {
+               ret = rproc_is_running(id);
+               if (!ret) {
+                       printf("Remote processor is Running\n");
+               } else if (ret == 1) {
+                       printf("Remote processor is NOT Running\n");
+                       ret = 0;
+               }
+               /* Else error.. */
+       } else if (!strcmp(argv[0], "ping")) {
+               ret = rproc_ping(id);
+               if (!ret) {
+                       printf("Remote processor responds 'Pong'\n");
+               } else if (ret == 1) {
+                       printf("No response from Remote processor\n");
+                       ret = 0;
+               }
+               /* Else error.. */
+       }
+
+       if (ret < 0)
+               printf("Operation Failed with error (%d)\n", ret);
+
+       return ret ? CMD_RET_FAILURE : 0;
+}
+
+static cmd_tbl_t cmd_remoteproc_sub[] = {
+       U_BOOT_CMD_MKENT(init, 0, 1, do_rproc_init,
+                        "Enumerate and initialize all processors", ""),
+       U_BOOT_CMD_MKENT(list, 0, 1, do_remoteproc_list,
+                        "list remote processors", ""),
+       U_BOOT_CMD_MKENT(load, 5, 1, do_remoteproc_load,
+                        "Load remote processor with provided image",
+                        "<id> [addr] [size]\n"
+                        "- id: ID of the remote processor(see 'list' cmd)\n"
+                        "- addr: Address in memory of the image to loadup\n"
+                        "- size: Size of the image to loadup\n"),
+       U_BOOT_CMD_MKENT(start, 1, 1, do_remoteproc_wrapper,
+                        "Start remote processor",
+                        "id - ID of the remote processor (see 'list' cmd)\n"),
+       U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper,
+                        "Stop remote processor",
+                        "id - ID of the remote processor (see 'list' cmd)\n"),
+       U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper,
+                        "Reset remote processor",
+                        "id - ID of the remote processor (see 'list' cmd)\n"),
+       U_BOOT_CMD_MKENT(is_running, 1, 1, do_remoteproc_wrapper,
+                        "Check to see if remote processor is running\n",
+                        "id - ID of the remote processor (see 'list' cmd)\n"),
+       U_BOOT_CMD_MKENT(ping, 1, 1, do_remoteproc_wrapper,
+                        "Ping to communicate with remote processor\n",
+                        "id - ID of the remote processor (see 'list' cmd)\n"),
+};
+
+/**
+ * do_remoteproc() - (replace: short desc)
+ * @cmdtp:     unused
+ * @flag:      unused
+ * @argc:      argument count
+ * @argv:      argument list
+ *
+ * parses up the command table to invoke the correct command.
+ *
+ * Return: 0 if no error, else returns appropriate error value.
+ */
+static int do_remoteproc(cmd_tbl_t *cmdtp, int flag, int argc,
+                        char *const argv[])
+{
+       cmd_tbl_t *c = NULL;
+
+       /* Strip off leading 'rproc' command argument */
+       argc--;
+       argv++;
+
+       if (argc)
+               c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
+                                ARRAY_SIZE(cmd_remoteproc_sub));
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(rproc, 5, 1, do_remoteproc,
+          "Control operation of remote processors in an SoC",
+          " [init|list|load|start|stop|reset|is_running|ping]\n"
+          "\t\t Where:\n"
+          "\t\t[addr] is a memory address\n"
+          "\t\t<id> is a numerical identifier for the remote processor\n"
+          "\t\t     provided by 'list' command.\n"
+          "\t\tNote: Remote processors must be initalized prior to usage\n"
+          "\t\tNote: Services are dependent on the driver capability\n"
+          "\t\t      'list' command shows the capability of each device\n"
+          "\n\tSubcommands:\n"
+          "\tinit   - Enumerate and initalize the remote processors\n"
+          "\tlist   - list available remote processors\n"
+          "\tload <id> [addr] [size]- Load the remote processor with binary\n"
+          "\t            image stored at address [addr] in memory\n"
+          "\tstart <id>        - Start the remote processor(must be loaded)\n"
+          "\tstop <id> - Stop the remote processor\n"
+          "\treset <id>        - Reset the remote processor\n"
+          "\tis_running <id> - Reports if the remote processor is running\n"
+          "\tping <id> - Ping the remote processor for communication\n");
diff --git a/cmd/sata.c b/cmd/sata.c
new file mode 100644 (file)
index 0000000..76bacea
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2000-2005, DENX Software Engineering
+ *             Wolfgang Denk <wd@denx.de>
+ * Copyright (C) Procsys. All rights reserved.
+ *             Mushtaq Khan <mushtaq_k@procsys.com>
+ *                     <mushtaqk_921@yahoo.co.in>
+ * Copyright (C) 2008 Freescale Semiconductor, Inc.
+ *             Dave Liu <daveliu@freescale.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <part.h>
+#include <sata.h>
+
+static int sata_curr_device = -1;
+block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
+
+static unsigned long sata_bread(block_dev_desc_t *block_dev, lbaint_t start,
+                               lbaint_t blkcnt, void *dst)
+{
+       return sata_read(block_dev->dev, start, blkcnt, dst);
+}
+
+static unsigned long sata_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
+                                lbaint_t blkcnt, const void *buffer)
+{
+       return sata_write(block_dev->dev, start, blkcnt, buffer);
+}
+
+int __sata_initialize(void)
+{
+       int rc;
+       int i;
+
+       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
+               memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc));
+               sata_dev_desc[i].if_type = IF_TYPE_SATA;
+               sata_dev_desc[i].dev = i;
+               sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
+               sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
+               sata_dev_desc[i].lba = 0;
+               sata_dev_desc[i].blksz = 512;
+               sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
+               sata_dev_desc[i].block_read = sata_bread;
+               sata_dev_desc[i].block_write = sata_bwrite;
+
+               rc = init_sata(i);
+               if (!rc) {
+                       rc = scan_sata(i);
+                       if (!rc && (sata_dev_desc[i].lba > 0) &&
+                               (sata_dev_desc[i].blksz > 0))
+                               init_part(&sata_dev_desc[i]);
+               }
+       }
+       sata_curr_device = 0;
+       return rc;
+}
+int sata_initialize(void) __attribute__((weak,alias("__sata_initialize")));
+
+__weak int __sata_stop(void)
+{
+       int i, err = 0;
+
+       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++)
+               err |= reset_sata(i);
+
+       if (err)
+               printf("Could not reset some SATA devices\n");
+
+       return err;
+}
+int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
+
+#ifdef CONFIG_PARTITIONS
+block_dev_desc_t *sata_get_dev(int dev)
+{
+       return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL;
+}
+#endif
+
+static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int rc = 0;
+
+       if (argc == 2 && strcmp(argv[1], "stop") == 0)
+               return sata_stop();
+
+       if (argc == 2 && strcmp(argv[1], "init") == 0) {
+               if (sata_curr_device != -1)
+                       sata_stop();
+
+               return sata_initialize();
+       }
+
+       /* If the user has not yet run `sata init`, do it now */
+       if (sata_curr_device == -1)
+               if (sata_initialize())
+                       return 1;
+
+       switch (argc) {
+       case 0:
+       case 1:
+               return CMD_RET_USAGE;
+       case 2:
+               if (strncmp(argv[1],"inf", 3) == 0) {
+                       int i;
+                       putc('\n');
+                       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; ++i) {
+                               if (sata_dev_desc[i].type == DEV_TYPE_UNKNOWN)
+                                       continue;
+                               printf ("SATA device %d: ", i);
+                               dev_print(&sata_dev_desc[i]);
+                       }
+                       return 0;
+               } else if (strncmp(argv[1],"dev", 3) == 0) {
+                       if ((sata_curr_device < 0) || (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE)) {
+                               puts("\nno SATA devices available\n");
+                               return 1;
+                       }
+                       printf("\nSATA device %d: ", sata_curr_device);
+                       dev_print(&sata_dev_desc[sata_curr_device]);
+                       return 0;
+               } else if (strncmp(argv[1],"part",4) == 0) {
+                       int dev, ok;
+
+                       for (ok = 0, dev = 0; dev < CONFIG_SYS_SATA_MAX_DEVICE; ++dev) {
+                               if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
+                                       ++ok;
+                                       if (dev)
+                                               putc ('\n');
+                                       print_part(&sata_dev_desc[dev]);
+                               }
+                       }
+                       if (!ok) {
+                               puts("\nno SATA devices available\n");
+                               rc ++;
+                       }
+                       return rc;
+               }
+               return CMD_RET_USAGE;
+       case 3:
+               if (strncmp(argv[1], "dev", 3) == 0) {
+                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
+
+                       printf("\nSATA device %d: ", dev);
+                       if (dev >= CONFIG_SYS_SATA_MAX_DEVICE) {
+                               puts ("unknown device\n");
+                               return 1;
+                       }
+                       dev_print(&sata_dev_desc[dev]);
+
+                       if (sata_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
+                               return 1;
+
+                       sata_curr_device = dev;
+
+                       puts("... is now current device\n");
+
+                       return 0;
+               } else if (strncmp(argv[1], "part", 4) == 0) {
+                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
+
+                       if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
+                               print_part(&sata_dev_desc[dev]);
+                       } else {
+                               printf("\nSATA device %d not available\n", dev);
+                               rc = 1;
+                       }
+                       return rc;
+               }
+               return CMD_RET_USAGE;
+
+       default: /* at least 4 args */
+               if (strcmp(argv[1], "read") == 0) {
+                       ulong addr = simple_strtoul(argv[2], NULL, 16);
+                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       ulong n;
+                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
+
+                       printf("\nSATA read: device %d block # %ld, count %ld ... ",
+                               sata_curr_device, blk, cnt);
+
+                       n = sata_read(sata_curr_device, blk, cnt, (u32 *)addr);
+
+                       /* flush cache after read */
+                       flush_cache(addr, cnt * sata_dev_desc[sata_curr_device].blksz);
+
+                       printf("%ld blocks read: %s\n",
+                               n, (n==cnt) ? "OK" : "ERROR");
+                       return (n == cnt) ? 0 : 1;
+               } else if (strcmp(argv[1], "write") == 0) {
+                       ulong addr = simple_strtoul(argv[2], NULL, 16);
+                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       ulong n;
+
+                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
+
+                       printf("\nSATA write: device %d block # %ld, count %ld ... ",
+                               sata_curr_device, blk, cnt);
+
+                       n = sata_write(sata_curr_device, blk, cnt, (u32 *)addr);
+
+                       printf("%ld blocks written: %s\n",
+                               n, (n == cnt) ? "OK" : "ERROR");
+                       return (n == cnt) ? 0 : 1;
+               } else {
+                       return CMD_RET_USAGE;
+               }
+
+               return rc;
+       }
+}
+
+U_BOOT_CMD(
+       sata, 5, 1, do_sata,
+       "SATA sub system",
+       "init - init SATA sub system\n"
+       "sata stop - disable SATA sub system\n"
+       "sata info - show available SATA devices\n"
+       "sata device [dev] - show or set current device\n"
+       "sata part [dev] - print partition table\n"
+       "sata read addr blk# cnt\n"
+       "sata write addr blk# cnt"
+);
diff --git a/cmd/scsi.c b/cmd/scsi.c
new file mode 100644 (file)
index 0000000..bc7d1b6
--- /dev/null
@@ -0,0 +1,733 @@
+/*
+ * (C) Copyright 2001
+ * Denis Peter, MPL AG Switzerland
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * SCSI support.
+ */
+#include <common.h>
+#include <command.h>
+#include <inttypes.h>
+#include <asm/processor.h>
+#include <scsi.h>
+#include <image.h>
+#include <pci.h>
+
+#ifdef CONFIG_SCSI_DEV_LIST
+#define SCSI_DEV_LIST CONFIG_SCSI_DEV_LIST
+#else
+#ifdef CONFIG_SCSI_SYM53C8XX
+#define SCSI_VEND_ID   0x1000
+#ifndef CONFIG_SCSI_DEV_ID
+#define SCSI_DEV_ID            0x0001
+#else
+#define SCSI_DEV_ID            CONFIG_SCSI_DEV_ID
+#endif
+#elif defined CONFIG_SATA_ULI5288
+
+#define SCSI_VEND_ID 0x10b9
+#define SCSI_DEV_ID  0x5288
+
+#elif !defined(CONFIG_SCSI_AHCI_PLAT)
+#error no scsi device defined
+#endif
+#define SCSI_DEV_LIST {SCSI_VEND_ID, SCSI_DEV_ID}
+#endif
+
+#if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT)
+const struct pci_device_id scsi_device_list[] = { SCSI_DEV_LIST };
+#endif
+static ccb tempccb;    /* temporary scsi command buffer */
+
+static unsigned char tempbuff[512]; /* temporary data buffer */
+
+static int scsi_max_devs; /* number of highest available scsi device */
+
+static int scsi_curr_dev; /* current device */
+
+static block_dev_desc_t scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];
+
+/********************************************************************************
+ *  forward declerations of some Setup Routines
+ */
+void scsi_setup_test_unit_ready(ccb * pccb);
+void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks);
+void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks);
+void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks);
+
+static void scsi_setup_write_ext(ccb *pccb, lbaint_t start,
+                               unsigned short blocks);
+void scsi_setup_inquiry(ccb * pccb);
+void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
+
+
+static int scsi_read_capacity(ccb *pccb, lbaint_t *capacity,
+                             unsigned long *blksz);
+static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                      lbaint_t blkcnt, void *buffer);
+static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+                       lbaint_t blkcnt, const void *buffer);
+
+
+/*********************************************************************************
+ * (re)-scan the scsi bus and reports scsi device info
+ * to the user if mode = 1
+ */
+void scsi_scan(int mode)
+{
+       unsigned char i,perq,modi,lun;
+       lbaint_t capacity;
+       unsigned long blksz;
+       ccb* pccb=(ccb *)&tempccb;
+
+       if(mode==1) {
+               printf("scanning bus for devices...\n");
+       }
+       for(i=0;i<CONFIG_SYS_SCSI_MAX_DEVICE;i++) {
+               scsi_dev_desc[i].target=0xff;
+               scsi_dev_desc[i].lun=0xff;
+               scsi_dev_desc[i].lba=0;
+               scsi_dev_desc[i].blksz=0;
+               scsi_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz));
+               scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
+               scsi_dev_desc[i].vendor[0]=0;
+               scsi_dev_desc[i].product[0]=0;
+               scsi_dev_desc[i].revision[0]=0;
+               scsi_dev_desc[i].removable = false;
+               scsi_dev_desc[i].if_type=IF_TYPE_SCSI;
+               scsi_dev_desc[i].dev=i;
+               scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN;
+               scsi_dev_desc[i].block_read=scsi_read;
+               scsi_dev_desc[i].block_write = scsi_write;
+       }
+       scsi_max_devs=0;
+       for(i=0;i<CONFIG_SYS_SCSI_MAX_SCSI_ID;i++) {
+               pccb->target=i;
+               for(lun=0;lun<CONFIG_SYS_SCSI_MAX_LUN;lun++) {
+                       pccb->lun=lun;
+                       pccb->pdata=(unsigned char *)&tempbuff;
+                       pccb->datalen=512;
+                       scsi_setup_inquiry(pccb);
+                       if (scsi_exec(pccb) != true) {
+                               if(pccb->contr_stat==SCSI_SEL_TIME_OUT) {
+                                       debug ("Selection timeout ID %d\n",pccb->target);
+                                       continue; /* selection timeout => assuming no device present */
+                               }
+                               scsi_print_error(pccb);
+                               continue;
+                       }
+                       perq=tempbuff[0];
+                       modi=tempbuff[1];
+                       if((perq & 0x1f)==0x1f) {
+                               continue; /* skip unknown devices */
+                       }
+                       if((modi&0x80)==0x80) /* drive is removable */
+                               scsi_dev_desc[scsi_max_devs].removable=true;
+                       /* get info for this device */
+                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].vendor[0],
+                                      &tempbuff[8], 8);
+                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].product[0],
+                                      &tempbuff[16], 16);
+                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].revision[0],
+                                      &tempbuff[32], 4);
+                       scsi_dev_desc[scsi_max_devs].target=pccb->target;
+                       scsi_dev_desc[scsi_max_devs].lun=pccb->lun;
+
+                       pccb->datalen=0;
+                       scsi_setup_test_unit_ready(pccb);
+                       if (scsi_exec(pccb) != true) {
+                               if (scsi_dev_desc[scsi_max_devs].removable == true) {
+                                       scsi_dev_desc[scsi_max_devs].type=perq;
+                                       goto removable;
+                               }
+                               scsi_print_error(pccb);
+                               continue;
+                       }
+                       if (scsi_read_capacity(pccb, &capacity, &blksz)) {
+                               scsi_print_error(pccb);
+                               continue;
+                       }
+                       scsi_dev_desc[scsi_max_devs].lba=capacity;
+                       scsi_dev_desc[scsi_max_devs].blksz=blksz;
+                       scsi_dev_desc[scsi_max_devs].log2blksz =
+                               LOG2(scsi_dev_desc[scsi_max_devs].blksz);
+                       scsi_dev_desc[scsi_max_devs].type=perq;
+                       init_part(&scsi_dev_desc[scsi_max_devs]);
+removable:
+                       if(mode==1) {
+                               printf ("  Device %d: ", scsi_max_devs);
+                               dev_print(&scsi_dev_desc[scsi_max_devs]);
+                       } /* if mode */
+                       scsi_max_devs++;
+               } /* next LUN */
+       }
+       if(scsi_max_devs>0)
+               scsi_curr_dev=0;
+       else
+               scsi_curr_dev = -1;
+
+       printf("Found %d device(s).\n", scsi_max_devs);
+#ifndef CONFIG_SPL_BUILD
+       setenv_ulong("scsidevs", scsi_max_devs);
+#endif
+}
+
+int scsi_get_disk_count(void)
+{
+       return scsi_max_devs;
+}
+
+#if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT)
+void scsi_init(void)
+{
+       int busdevfunc = -1;
+       int i;
+       /*
+        * Find a device from the list, this driver will support a single
+        * controller.
+        */
+       for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
+               /* get PCI Device ID */
+#ifdef CONFIG_DM_PCI
+               struct udevice *dev;
+               int ret;
+
+               ret = dm_pci_find_device(scsi_device_list[i].vendor,
+                                        scsi_device_list[i].device, 0, &dev);
+               if (!ret) {
+                       busdevfunc = dm_pci_get_bdf(dev);
+                       break;
+               }
+#else
+               busdevfunc = pci_find_device(scsi_device_list[i].vendor,
+                                            scsi_device_list[i].device,
+                                            0);
+#endif
+               if (busdevfunc != -1)
+                       break;
+       }
+
+       if (busdevfunc == -1) {
+               printf("Error: SCSI Controller(s) ");
+               for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
+                       printf("%04X:%04X ",
+                              scsi_device_list[i].vendor,
+                              scsi_device_list[i].device);
+               }
+               printf("not found\n");
+               return;
+       }
+#ifdef DEBUG
+       else {
+               printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n",
+                      scsi_device_list[i].vendor,
+                      scsi_device_list[i].device,
+                      (busdevfunc >> 16) & 0xFF,
+                      (busdevfunc >> 11) & 0x1F,
+                      (busdevfunc >> 8) & 0x7);
+       }
+#endif
+       bootstage_start(BOOTSTAGE_ID_ACCUM_SCSI, "ahci");
+       scsi_low_level_init(busdevfunc);
+       scsi_scan(1);
+       bootstage_accum(BOOTSTAGE_ID_ACCUM_SCSI);
+}
+#endif
+
+#ifdef CONFIG_PARTITIONS
+block_dev_desc_t * scsi_get_dev(int dev)
+{
+       return (dev < CONFIG_SYS_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL;
+}
+#endif
+
+/******************************************************************************
+ * scsi boot command intepreter. Derived from diskboot
+ */
+int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return common_diskboot(cmdtp, "scsi", argc, argv);
+}
+
+/*********************************************************************************
+ * scsi command intepreter
+ */
+int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       switch (argc) {
+       case 0:
+       case 1:
+               return CMD_RET_USAGE;
+
+       case 2:
+                       if (strncmp(argv[1],"res",3) == 0) {
+                               printf("\nReset SCSI\n");
+                               scsi_bus_reset();
+                               scsi_scan(1);
+                               return 0;
+                       }
+                       if (strncmp(argv[1],"inf",3) == 0) {
+                               int i;
+                               for (i=0; i<CONFIG_SYS_SCSI_MAX_DEVICE; ++i) {
+                                       if(scsi_dev_desc[i].type==DEV_TYPE_UNKNOWN)
+                                               continue; /* list only known devices */
+                                       printf ("SCSI dev. %d:  ", i);
+                                       dev_print(&scsi_dev_desc[i]);
+                               }
+                               return 0;
+                       }
+                       if (strncmp(argv[1],"dev",3) == 0) {
+                               if ((scsi_curr_dev < 0) || (scsi_curr_dev >= CONFIG_SYS_SCSI_MAX_DEVICE)) {
+                                       printf("\nno SCSI devices available\n");
+                                       return 1;
+                               }
+                               printf ("\n    Device %d: ", scsi_curr_dev);
+                               dev_print(&scsi_dev_desc[scsi_curr_dev]);
+                               return 0;
+                       }
+                       if (strncmp(argv[1],"scan",4) == 0) {
+                               scsi_scan(1);
+                               return 0;
+                       }
+                       if (strncmp(argv[1],"part",4) == 0) {
+                               int dev, ok;
+                               for (ok=0, dev=0; dev<CONFIG_SYS_SCSI_MAX_DEVICE; ++dev) {
+                                       if (scsi_dev_desc[dev].type!=DEV_TYPE_UNKNOWN) {
+                                               ok++;
+                                               if (dev)
+                                                       printf("\n");
+                                               debug ("print_part of %x\n",dev);
+                                                       print_part(&scsi_dev_desc[dev]);
+                                       }
+                               }
+                               if (!ok)
+                                       printf("\nno SCSI devices available\n");
+                               return 1;
+                       }
+                       return CMD_RET_USAGE;
+       case 3:
+                       if (strncmp(argv[1],"dev",3) == 0) {
+                               int dev = (int)simple_strtoul(argv[2], NULL, 10);
+                               printf ("\nSCSI device %d: ", dev);
+                               if (dev >= CONFIG_SYS_SCSI_MAX_DEVICE) {
+                                       printf("unknown device\n");
+                                       return 1;
+                               }
+                               printf ("\n    Device %d: ", dev);
+                               dev_print(&scsi_dev_desc[dev]);
+                               if(scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
+                                       return 1;
+                               }
+                               scsi_curr_dev = dev;
+                               printf("... is now current device\n");
+                               return 0;
+                       }
+                       if (strncmp(argv[1],"part",4) == 0) {
+                               int dev = (int)simple_strtoul(argv[2], NULL, 10);
+                               if(scsi_dev_desc[dev].type != DEV_TYPE_UNKNOWN) {
+                                       print_part(&scsi_dev_desc[dev]);
+                               }
+                               else {
+                                       printf ("\nSCSI device %d not available\n", dev);
+                               }
+                               return 1;
+                       }
+                       return CMD_RET_USAGE;
+    default:
+                       /* at least 4 args */
+                       if (strcmp(argv[1],"read") == 0) {
+                               ulong addr = simple_strtoul(argv[2], NULL, 16);
+                               ulong blk  = simple_strtoul(argv[3], NULL, 16);
+                               ulong cnt  = simple_strtoul(argv[4], NULL, 16);
+                               ulong n;
+                               printf ("\nSCSI read: device %d block # %ld, count %ld ... ",
+                                               scsi_curr_dev, blk, cnt);
+                               n = scsi_read(&scsi_dev_desc[scsi_curr_dev],
+                                             blk, cnt, (ulong *)addr);
+                               printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR");
+                               return 0;
+                       } else if (strcmp(argv[1], "write") == 0) {
+                               ulong addr = simple_strtoul(argv[2], NULL, 16);
+                               ulong blk = simple_strtoul(argv[3], NULL, 16);
+                               ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                               ulong n;
+                               printf("\nSCSI write: device %d block # %ld, "
+                                      "count %ld ... ",
+                                      scsi_curr_dev, blk, cnt);
+                               n = scsi_write(&scsi_dev_desc[scsi_curr_dev],
+                                              blk, cnt, (ulong *)addr);
+                               printf("%ld blocks written: %s\n", n,
+                                      (n == cnt) ? "OK" : "ERROR");
+                               return 0;
+                       }
+       } /* switch */
+       return CMD_RET_USAGE;
+}
+
+/****************************************************************************************
+ * scsi_read
+ */
+
+/* almost the maximum amount of the scsi_ext command.. */
+#define SCSI_MAX_READ_BLK 0xFFFF
+#define SCSI_LBA48_READ        0xFFFFFFF
+
+static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                      lbaint_t blkcnt, void *buffer)
+{
+       int device = block_dev->dev;
+       lbaint_t start, blks;
+       uintptr_t buf_addr;
+       unsigned short smallblks = 0;
+       ccb* pccb=(ccb *)&tempccb;
+       device&=0xff;
+       /* Setup  device
+        */
+       pccb->target=scsi_dev_desc[device].target;
+       pccb->lun=scsi_dev_desc[device].lun;
+       buf_addr=(unsigned long)buffer;
+       start=blknr;
+       blks=blkcnt;
+       debug("\nscsi_read: dev %d startblk " LBAF
+             ", blccnt " LBAF " buffer %lx\n",
+             device, start, blks, (unsigned long)buffer);
+       do {
+               pccb->pdata=(unsigned char *)buf_addr;
+#ifdef CONFIG_SYS_64BIT_LBA
+               if (start > SCSI_LBA48_READ) {
+                       unsigned long blocks;
+                       blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK);
+                       pccb->datalen = scsi_dev_desc[device].blksz * blocks;
+                       scsi_setup_read16(pccb, start, blocks);
+                       start += blocks;
+                       blks -= blocks;
+               } else
+#endif
+               if (blks > SCSI_MAX_READ_BLK) {
+                       pccb->datalen=scsi_dev_desc[device].blksz * SCSI_MAX_READ_BLK;
+                       smallblks=SCSI_MAX_READ_BLK;
+                       scsi_setup_read_ext(pccb,start,smallblks);
+                       start+=SCSI_MAX_READ_BLK;
+                       blks-=SCSI_MAX_READ_BLK;
+               }
+               else {
+                       pccb->datalen=scsi_dev_desc[device].blksz * blks;
+                       smallblks=(unsigned short) blks;
+                       scsi_setup_read_ext(pccb,start,smallblks);
+                       start+=blks;
+                       blks=0;
+               }
+               debug("scsi_read_ext: startblk " LBAF
+                     ", blccnt %x buffer %" PRIXPTR "\n",
+                     start, smallblks, buf_addr);
+               if (scsi_exec(pccb) != true) {
+                       scsi_print_error(pccb);
+                       blkcnt-=blks;
+                       break;
+               }
+               buf_addr+=pccb->datalen;
+       } while(blks!=0);
+       debug("scsi_read_ext: end startblk " LBAF
+             ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr);
+       return(blkcnt);
+}
+
+/*******************************************************************************
+ * scsi_write
+ */
+
+/* Almost the maximum amount of the scsi_ext command.. */
+#define SCSI_MAX_WRITE_BLK 0xFFFF
+
+static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
+                       lbaint_t blkcnt, const void *buffer)
+{
+       int device = block_dev->dev;
+       lbaint_t start, blks;
+       uintptr_t buf_addr;
+       unsigned short smallblks;
+       ccb* pccb = (ccb *)&tempccb;
+       device &= 0xff;
+       /* Setup  device
+        */
+       pccb->target = scsi_dev_desc[device].target;
+       pccb->lun = scsi_dev_desc[device].lun;
+       buf_addr = (unsigned long)buffer;
+       start = blknr;
+       blks = blkcnt;
+       debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
+             __func__, device, start, blks, (unsigned long)buffer);
+       do {
+               pccb->pdata = (unsigned char *)buf_addr;
+               if (blks > SCSI_MAX_WRITE_BLK) {
+                       pccb->datalen = (scsi_dev_desc[device].blksz *
+                                        SCSI_MAX_WRITE_BLK);
+                       smallblks = SCSI_MAX_WRITE_BLK;
+                       scsi_setup_write_ext(pccb, start, smallblks);
+                       start += SCSI_MAX_WRITE_BLK;
+                       blks -= SCSI_MAX_WRITE_BLK;
+               } else {
+                       pccb->datalen = scsi_dev_desc[device].blksz * blks;
+                       smallblks = (unsigned short)blks;
+                       scsi_setup_write_ext(pccb, start, smallblks);
+                       start += blks;
+                       blks = 0;
+               }
+               debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
+                     __func__, start, smallblks, buf_addr);
+               if (scsi_exec(pccb) != true) {
+                       scsi_print_error(pccb);
+                       blkcnt -= blks;
+                       break;
+               }
+               buf_addr += pccb->datalen;
+       } while (blks != 0);
+       debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
+             __func__, start, smallblks, buf_addr);
+       return blkcnt;
+}
+
+/* copy src to dest, skipping leading and trailing blanks
+ * and null terminate the string
+ */
+void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len)
+{
+       int start,end;
+
+       start=0;
+       while(start<len) {
+               if(src[start]!=' ')
+                       break;
+               start++;
+       }
+       end=len-1;
+       while(end>start) {
+               if(src[end]!=' ')
+                       break;
+               end--;
+       }
+       for( ; start<=end; start++) {
+               *dest++=src[start];
+       }
+       *dest='\0';
+}
+
+
+/* Trim trailing blanks, and NUL-terminate string
+ */
+void scsi_trim_trail (unsigned char *str, unsigned int len)
+{
+       unsigned char *p = str + len - 1;
+
+       while (len-- > 0) {
+               *p-- = '\0';
+               if (*p != ' ') {
+                       return;
+               }
+       }
+}
+
+int scsi_read_capacity(ccb *pccb, lbaint_t *capacity, unsigned long *blksz)
+{
+       *capacity = 0;
+
+       memset(pccb->cmd, 0, sizeof(pccb->cmd));
+       pccb->cmd[0] = SCSI_RD_CAPAC10;
+       pccb->cmd[1] = pccb->lun << 5;
+       pccb->cmdlen = 10;
+       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
+
+       pccb->datalen = 8;
+       if (scsi_exec(pccb) != true)
+               return 1;
+
+       *capacity = ((lbaint_t)pccb->pdata[0] << 24) |
+                   ((lbaint_t)pccb->pdata[1] << 16) |
+                   ((lbaint_t)pccb->pdata[2] << 8)  |
+                   ((lbaint_t)pccb->pdata[3]);
+
+       if (*capacity != 0xffffffff) {
+               /* Read capacity (10) was sufficient for this drive. */
+               *blksz = ((unsigned long)pccb->pdata[4] << 24) |
+                        ((unsigned long)pccb->pdata[5] << 16) |
+                        ((unsigned long)pccb->pdata[6] << 8)  |
+                        ((unsigned long)pccb->pdata[7]);
+               return 0;
+       }
+
+       /* Read capacity (10) was insufficient. Use read capacity (16). */
+
+       memset(pccb->cmd, 0, sizeof(pccb->cmd));
+       pccb->cmd[0] = SCSI_RD_CAPAC16;
+       pccb->cmd[1] = 0x10;
+       pccb->cmdlen = 16;
+       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
+
+       pccb->datalen = 16;
+       if (scsi_exec(pccb) != true)
+               return 1;
+
+       *capacity = ((uint64_t)pccb->pdata[0] << 56) |
+                   ((uint64_t)pccb->pdata[1] << 48) |
+                   ((uint64_t)pccb->pdata[2] << 40) |
+                   ((uint64_t)pccb->pdata[3] << 32) |
+                   ((uint64_t)pccb->pdata[4] << 24) |
+                   ((uint64_t)pccb->pdata[5] << 16) |
+                   ((uint64_t)pccb->pdata[6] << 8)  |
+                   ((uint64_t)pccb->pdata[7]);
+
+       *blksz = ((uint64_t)pccb->pdata[8]  << 56) |
+                ((uint64_t)pccb->pdata[9]  << 48) |
+                ((uint64_t)pccb->pdata[10] << 40) |
+                ((uint64_t)pccb->pdata[11] << 32) |
+                ((uint64_t)pccb->pdata[12] << 24) |
+                ((uint64_t)pccb->pdata[13] << 16) |
+                ((uint64_t)pccb->pdata[14] << 8)  |
+                ((uint64_t)pccb->pdata[15]);
+
+       return 0;
+}
+
+
+/************************************************************************************
+ * Some setup (fill-in) routines
+ */
+void scsi_setup_test_unit_ready(ccb * pccb)
+{
+       pccb->cmd[0]=SCSI_TST_U_RDY;
+       pccb->cmd[1]=pccb->lun<<5;
+       pccb->cmd[2]=0;
+       pccb->cmd[3]=0;
+       pccb->cmd[4]=0;
+       pccb->cmd[5]=0;
+       pccb->cmdlen=6;
+       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
+}
+
+#ifdef CONFIG_SYS_64BIT_LBA
+void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks)
+{
+       pccb->cmd[0] = SCSI_READ16;
+       pccb->cmd[1] = pccb->lun<<5;
+       pccb->cmd[2] = ((unsigned char) (start >> 56)) & 0xff;
+       pccb->cmd[3] = ((unsigned char) (start >> 48)) & 0xff;
+       pccb->cmd[4] = ((unsigned char) (start >> 40)) & 0xff;
+       pccb->cmd[5] = ((unsigned char) (start >> 32)) & 0xff;
+       pccb->cmd[6] = ((unsigned char) (start >> 24)) & 0xff;
+       pccb->cmd[7] = ((unsigned char) (start >> 16)) & 0xff;
+       pccb->cmd[8] = ((unsigned char) (start >> 8)) & 0xff;
+       pccb->cmd[9] = ((unsigned char) (start)) & 0xff;
+       pccb->cmd[10] = 0;
+       pccb->cmd[11] = ((unsigned char) (blocks >> 24)) & 0xff;
+       pccb->cmd[12] = ((unsigned char) (blocks >> 16)) & 0xff;
+       pccb->cmd[13] = ((unsigned char) (blocks >> 8)) & 0xff;
+       pccb->cmd[14] = (unsigned char) blocks & 0xff;
+       pccb->cmd[15] = 0;
+       pccb->cmdlen = 16;
+       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
+       debug ("scsi_setup_read16: cmd: %02X %02X "
+              "startblk %02X%02X%02X%02X%02X%02X%02X%02X "
+              "blccnt %02X%02X%02X%02X\n",
+               pccb->cmd[0], pccb->cmd[1],
+               pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5],
+               pccb->cmd[6], pccb->cmd[7], pccb->cmd[8], pccb->cmd[9],
+               pccb->cmd[11], pccb->cmd[12], pccb->cmd[13], pccb->cmd[14]);
+}
+#endif
+
+void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks)
+{
+       pccb->cmd[0]=SCSI_READ10;
+       pccb->cmd[1]=pccb->lun<<5;
+       pccb->cmd[2]=((unsigned char) (start>>24))&0xff;
+       pccb->cmd[3]=((unsigned char) (start>>16))&0xff;
+       pccb->cmd[4]=((unsigned char) (start>>8))&0xff;
+       pccb->cmd[5]=((unsigned char) (start))&0xff;
+       pccb->cmd[6]=0;
+       pccb->cmd[7]=((unsigned char) (blocks>>8))&0xff;
+       pccb->cmd[8]=(unsigned char) blocks & 0xff;
+       pccb->cmd[6]=0;
+       pccb->cmdlen=10;
+       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
+       debug ("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
+               pccb->cmd[0],pccb->cmd[1],
+               pccb->cmd[2],pccb->cmd[3],pccb->cmd[4],pccb->cmd[5],
+               pccb->cmd[7],pccb->cmd[8]);
+}
+
+void scsi_setup_write_ext(ccb *pccb, lbaint_t start, unsigned short blocks)
+{
+       pccb->cmd[0] = SCSI_WRITE10;
+       pccb->cmd[1] = pccb->lun << 5;
+       pccb->cmd[2] = ((unsigned char) (start>>24)) & 0xff;
+       pccb->cmd[3] = ((unsigned char) (start>>16)) & 0xff;
+       pccb->cmd[4] = ((unsigned char) (start>>8)) & 0xff;
+       pccb->cmd[5] = ((unsigned char) (start)) & 0xff;
+       pccb->cmd[6] = 0;
+       pccb->cmd[7] = ((unsigned char) (blocks>>8)) & 0xff;
+       pccb->cmd[8] = (unsigned char)blocks & 0xff;
+       pccb->cmd[9] = 0;
+       pccb->cmdlen = 10;
+       pccb->msgout[0] = SCSI_IDENTIFY;  /* NOT USED */
+       debug("%s: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
+             __func__,
+             pccb->cmd[0], pccb->cmd[1],
+             pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5],
+             pccb->cmd[7], pccb->cmd[8]);
+}
+
+void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks)
+{
+       pccb->cmd[0]=SCSI_READ6;
+       pccb->cmd[1]=pccb->lun<<5 | (((unsigned char)(start>>16))&0x1f);
+       pccb->cmd[2]=((unsigned char) (start>>8))&0xff;
+       pccb->cmd[3]=((unsigned char) (start))&0xff;
+       pccb->cmd[4]=(unsigned char) blocks & 0xff;
+       pccb->cmd[5]=0;
+       pccb->cmdlen=6;
+       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
+       debug ("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n",
+               pccb->cmd[0],pccb->cmd[1],
+               pccb->cmd[2],pccb->cmd[3],pccb->cmd[4]);
+}
+
+
+void scsi_setup_inquiry(ccb * pccb)
+{
+       pccb->cmd[0]=SCSI_INQUIRY;
+       pccb->cmd[1]=pccb->lun<<5;
+       pccb->cmd[2]=0;
+       pccb->cmd[3]=0;
+       if(pccb->datalen>255)
+               pccb->cmd[4]=255;
+       else
+               pccb->cmd[4]=(unsigned char)pccb->datalen;
+       pccb->cmd[5]=0;
+       pccb->cmdlen=6;
+       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
+}
+
+
+U_BOOT_CMD(
+       scsi, 5, 1, do_scsi,
+       "SCSI sub-system",
+       "reset - reset SCSI controller\n"
+       "scsi info  - show available SCSI devices\n"
+       "scsi scan  - (re-)scan SCSI bus\n"
+       "scsi device [dev] - show or set current device\n"
+       "scsi part [dev] - print partition table of one or all SCSI devices\n"
+       "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
+       "     to memory address `addr'\n"
+       "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
+       "     `blk#' from memory address `addr'"
+);
+
+U_BOOT_CMD(
+       scsiboot, 3, 1, do_scsiboot,
+       "boot from SCSI device",
+       "loadAddr dev:part"
+);
diff --git a/cmd/setexpr.c b/cmd/setexpr.c
new file mode 100644 (file)
index 0000000..e7194fc
--- /dev/null
@@ -0,0 +1,398 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ * Copyright 2013 Wolfgang Denk <wd@denx.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * This file provides a shell like 'expr' function to return.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <mapmem.h>
+
+static ulong get_arg(char *s, int w)
+{
+       /*
+        * If the parameter starts with a '*' then assume it is a pointer to
+        * the value we want.
+        */
+       if (s[0] == '*') {
+               ulong *p;
+               ulong addr;
+               ulong val;
+
+               addr = simple_strtoul(&s[1], NULL, 16);
+               switch (w) {
+               case 1:
+                       p = map_sysmem(addr, sizeof(uchar));
+                       val = (ulong)*(uchar *)p;
+                       unmap_sysmem(p);
+                       return val;
+               case 2:
+                       p = map_sysmem(addr, sizeof(ushort));
+                       val = (ulong)*(ushort *)p;
+                       unmap_sysmem(p);
+                       return val;
+               case 4:
+               default:
+                       p = map_sysmem(addr, sizeof(ulong));
+                       val = *p;
+                       unmap_sysmem(p);
+                       return val;
+               }
+       } else {
+               return simple_strtoul(s, NULL, 16);
+       }
+}
+
+#ifdef CONFIG_REGEX
+
+#include <slre.h>
+
+#define SLRE_BUFSZ     16384
+#define SLRE_PATSZ     4096
+
+/*
+ * memstr - Find the first substring in memory
+ * @s1: The string to be searched
+ * @s2: The string to search for
+ *
+ * Similar to and based on strstr(),
+ * but strings do not need to be NUL terminated.
+ */
+static char *memstr(const char *s1, int l1, const char *s2, int l2)
+{
+       if (!l2)
+               return (char *)s1;
+
+       while (l1 >= l2) {
+               l1--;
+               if (!memcmp(s1, s2, l2))
+                       return (char *)s1;
+               s1++;
+       }
+       return NULL;
+}
+
+static char *substitute(char *string,  /* string buffer */
+                       int *slen,      /* current string length */
+                       int ssize,      /* string bufer size */
+                       const char *old,/* old (replaced) string */
+                       int olen,       /* length of old string */
+                       const char *new,/* new (replacement) string */
+                       int nlen)       /* length of new string */
+{
+       char *p = memstr(string, *slen, old, olen);
+
+       if (p == NULL)
+               return NULL;
+
+       debug("## Match at pos %ld: match len %d, subst len %d\n",
+               (long)(p - string), olen, nlen);
+
+       /* make sure replacement matches */
+       if (*slen + nlen - olen > ssize) {
+               printf("## error: substitution buffer overflow\n");
+               return NULL;
+       }
+
+       /* move tail if needed */
+       if (olen != nlen) {
+               int tail, len;
+
+               len = (olen > nlen) ? olen : nlen;
+
+               tail = ssize - (p + len - string);
+
+               debug("## tail len %d\n", tail);
+
+               memmove(p + nlen, p + olen, tail);
+       }
+
+       /* insert substitue */
+       memcpy(p, new, nlen);
+
+       *slen += nlen - olen;
+
+       return p + nlen;
+}
+
+/*
+ * Perform regex operations on a environment variable
+ *
+ * Returns 0 if OK, 1 in case of errors.
+ */
+static int regex_sub(const char *name,
+       const char *r, const char *s, const char *t,
+       int global)
+{
+       struct slre slre;
+       char data[SLRE_BUFSZ];
+       char *datap = data;
+       const char *value;
+       int res, len, nlen, loop;
+
+       if (name == NULL)
+               return 1;
+
+       if (slre_compile(&slre, r) == 0) {
+               printf("Error compiling regex: %s\n", slre.err_str);
+               return 1;
+       }
+
+       if (t == NULL) {
+               value = getenv(name);
+
+               if (value == NULL) {
+                       printf("## Error: variable \"%s\" not defined\n", name);
+                       return 1;
+               }
+               t = value;
+       }
+
+       debug("REGEX on %s=%s\n", name, t);
+       debug("REGEX=\"%s\", SUBST=\"%s\", GLOBAL=%d\n",
+               r, s ? s : "<NULL>", global);
+
+       len = strlen(t);
+       if (len + 1 > SLRE_BUFSZ) {
+               printf("## error: subst buffer overflow: have %d, need %d\n",
+                       SLRE_BUFSZ, len + 1);
+               return 1;
+       }
+
+       strcpy(data, t);
+
+       if (s == NULL)
+               nlen = 0;
+       else
+               nlen = strlen(s);
+
+       for (loop = 0;; loop++) {
+               struct cap caps[slre.num_caps + 2];
+               char nbuf[SLRE_PATSZ];
+               const char *old;
+               char *np;
+               int i, olen;
+
+               (void) memset(caps, 0, sizeof(caps));
+
+               res = slre_match(&slre, datap, len, caps);
+
+               debug("Result: %d\n", res);
+
+               for (i = 0; i < slre.num_caps; i++) {
+                       if (caps[i].len > 0) {
+                               debug("Substring %d: [%.*s]\n", i,
+                                       caps[i].len, caps[i].ptr);
+                       }
+               }
+
+               if (res == 0) {
+                       if (loop == 0) {
+                               printf("%s: No match\n", t);
+                               return 1;
+                       } else {
+                               break;
+                       }
+               }
+
+               debug("## MATCH ## %s\n", data);
+
+               if (s == NULL) {
+                       printf("%s=%s\n", name, t);
+                       return 1;
+               }
+
+               old = caps[0].ptr;
+               olen = caps[0].len;
+
+               if (nlen + 1 >= SLRE_PATSZ) {
+                       printf("## error: pattern buffer overflow: have %d, need %d\n",
+                               SLRE_BUFSZ, nlen + 1);
+                       return 1;
+               }
+               strcpy(nbuf, s);
+
+               debug("## SUBST(1) ## %s\n", nbuf);
+
+               /*
+                * Handle back references
+                *
+                * Support for \0 ... \9, where \0 is the
+                * whole matched pattern (similar to &).
+                *
+                * Implementation is a bit simpleminded as
+                * backrefs are substituted sequentially, one
+                * by one.  This will lead to somewhat
+                * unexpected results if the replacement
+                * strings contain any \N strings then then
+                * may get substitued, too.  We accept this
+                * restriction for the sake of simplicity.
+                */
+               for (i = 0; i < 10; ++i) {
+                       char backref[2] = {
+                               '\\',
+                               '0',
+                       };
+
+                       if (caps[i].len == 0)
+                               break;
+
+                       backref[1] += i;
+
+                       debug("## BACKREF %d: replace \"%.*s\" by \"%.*s\" in \"%s\"\n",
+                               i,
+                               2, backref,
+                               caps[i].len, caps[i].ptr,
+                               nbuf);
+
+                       for (np = nbuf;;) {
+                               char *p = memstr(np, nlen, backref, 2);
+
+                               if (p == NULL)
+                                       break;
+
+                               np = substitute(np, &nlen,
+                                       SLRE_PATSZ,
+                                       backref, 2,
+                                       caps[i].ptr, caps[i].len);
+
+                               if (np == NULL)
+                                       return 1;
+                       }
+               }
+               debug("## SUBST(2) ## %s\n", nbuf);
+
+               datap = substitute(datap, &len, SLRE_BUFSZ,
+                               old, olen,
+                               nbuf, nlen);
+
+               if (datap == NULL)
+                       return 1;
+
+               debug("## REMAINDER: %s\n", datap);
+
+               debug("## RESULT: %s\n", data);
+
+               if (!global)
+                       break;
+       }
+       debug("## FINAL (now setenv()) :  %s\n", data);
+
+       printf("%s=%s\n", name, data);
+
+       return setenv(name, data);
+}
+#endif
+
+static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong a, b;
+       ulong value;
+       int w;
+
+       /*
+        * We take 3, 5, or 6 arguments:
+        * 3 : setexpr name value
+        * 5 : setexpr name val1 op val2
+        *     setexpr name [g]sub r s
+        * 6 : setexpr name [g]sub r s t
+        */
+
+       /* > 6 already tested by max command args */
+       if ((argc < 3) || (argc == 4))
+               return CMD_RET_USAGE;
+
+       w = cmd_get_data_size(argv[0], 4);
+
+       a = get_arg(argv[2], w);
+
+       /* plain assignment: "setexpr name value" */
+       if (argc == 3) {
+               setenv_hex(argv[1], a);
+               return 0;
+       }
+
+       /* 5 or 6 args (6 args only with [g]sub) */
+#ifdef CONFIG_REGEX
+       /*
+        * rexep handling: "setexpr name [g]sub r s [t]"
+        * with 5 args, "t" will be NULL
+        */
+       if (strcmp(argv[2], "gsub") == 0)
+               return regex_sub(argv[1], argv[3], argv[4], argv[5], 1);
+
+       if (strcmp(argv[2], "sub") == 0)
+               return regex_sub(argv[1], argv[3], argv[4], argv[5], 0);
+#endif
+
+       /* standard operators: "setexpr name val1 op val2" */
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       if (strlen(argv[3]) != 1)
+               return CMD_RET_USAGE;
+
+       b = get_arg(argv[4], w);
+
+       switch (argv[3][0]) {
+       case '|':
+               value = a | b;
+               break;
+       case '&':
+               value = a & b;
+               break;
+       case '+':
+               value = a + b;
+               break;
+       case '^':
+               value = a ^ b;
+               break;
+       case '-':
+               value = a - b;
+               break;
+       case '*':
+               value = a * b;
+               break;
+       case '/':
+               value = a / b;
+               break;
+       case '%':
+               value = a % b;
+               break;
+       default:
+               printf("invalid op\n");
+               return 1;
+       }
+
+       setenv_hex(argv[1], value);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       setexpr, 6, 0, do_setexpr,
+       "set environment variable as the result of eval expression",
+       "[.b, .w, .l] name [*]value1 <op> [*]value2\n"
+       "    - set environment variable 'name' to the result of the evaluated\n"
+       "      expression specified by <op>.  <op> can be &, |, ^, +, -, *, /, %\n"
+       "      size argument is only meaningful if value1 and/or value2 are\n"
+       "      memory addresses (*)\n"
+       "setexpr[.b, .w, .l] name [*]value\n"
+       "    - load a value into a variable"
+#ifdef CONFIG_REGEX
+       "\n"
+       "setexpr name gsub r s [t]\n"
+       "    - For each substring matching the regular expression <r> in the\n"
+       "      string <t>, substitute the string <s>.  The result is\n"
+       "      assigned to <name>.  If <t> is not supplied, use the old\n"
+       "      value of <name>\n"
+       "setexpr name sub r s [t]\n"
+       "    - Just like gsub(), but replace only the first matching substring"
+#endif
+);
diff --git a/cmd/sf.c b/cmd/sf.c
new file mode 100644 (file)
index 0000000..42862d9
--- /dev/null
+++ b/cmd/sf.c
@@ -0,0 +1,618 @@
+/*
+ * Command for accessing SPI flash.
+ *
+ * Copyright (C) 2008 Atmel Corporation
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <div64.h>
+#include <dm.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <spi.h>
+#include <spi_flash.h>
+#include <jffs2/jffs2.h>
+#include <linux/mtd/mtd.h>
+
+#include <asm/io.h>
+#include <dm/device-internal.h>
+
+static struct spi_flash *flash;
+
+/*
+ * This function computes the length argument for the erase command.
+ * The length on which the command is to operate can be given in two forms:
+ * 1. <cmd> offset len  - operate on <'offset',  'len')
+ * 2. <cmd> offset +len - operate on <'offset',  'round_up(len)')
+ * If the second form is used and the length doesn't fall on the
+ * sector boundary, than it will be adjusted to the next sector boundary.
+ * If it isn't in the flash, the function will fail (return -1).
+ * Input:
+ *    arg: length specification (i.e. both command arguments)
+ * Output:
+ *    len: computed length for operation
+ * Return:
+ *    1: success
+ *   -1: failure (bad format, bad address).
+ */
+static int sf_parse_len_arg(char *arg, ulong *len)
+{
+       char *ep;
+       char round_up_len; /* indicates if the "+length" form used */
+       ulong len_arg;
+
+       round_up_len = 0;
+       if (*arg == '+') {
+               round_up_len = 1;
+               ++arg;
+       }
+
+       len_arg = simple_strtoul(arg, &ep, 16);
+       if (ep == arg || *ep != '\0')
+               return -1;
+
+       if (round_up_len && flash->sector_size > 0)
+               *len = ROUND(len_arg, flash->sector_size);
+       else
+               *len = len_arg;
+
+       return 1;
+}
+
+/**
+ * This function takes a byte length and a delta unit of time to compute the
+ * approximate bytes per second
+ *
+ * @param len          amount of bytes currently processed
+ * @param start_ms     start time of processing in ms
+ * @return bytes per second if OK, 0 on error
+ */
+static ulong bytes_per_second(unsigned int len, ulong start_ms)
+{
+       /* less accurate but avoids overflow */
+       if (len >= ((unsigned int) -1) / 1024)
+               return len / (max(get_timer(start_ms) / 1024, 1UL));
+       else
+               return 1024 * len / max(get_timer(start_ms), 1UL);
+}
+
+static int do_spi_flash_probe(int argc, char * const argv[])
+{
+       unsigned int bus = CONFIG_SF_DEFAULT_BUS;
+       unsigned int cs = CONFIG_SF_DEFAULT_CS;
+       unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
+       unsigned int mode = CONFIG_SF_DEFAULT_MODE;
+       char *endp;
+#ifdef CONFIG_DM_SPI_FLASH
+       struct udevice *new, *bus_dev;
+       int ret;
+#else
+       struct spi_flash *new;
+#endif
+
+       if (argc >= 2) {
+               cs = simple_strtoul(argv[1], &endp, 0);
+               if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
+                       return -1;
+               if (*endp == ':') {
+                       if (endp[1] == 0)
+                               return -1;
+
+                       bus = cs;
+                       cs = simple_strtoul(endp + 1, &endp, 0);
+                       if (*endp != 0)
+                               return -1;
+               }
+       }
+
+       if (argc >= 3) {
+               speed = simple_strtoul(argv[2], &endp, 0);
+               if (*argv[2] == 0 || *endp != 0)
+                       return -1;
+       }
+       if (argc >= 4) {
+               mode = simple_strtoul(argv[3], &endp, 16);
+               if (*argv[3] == 0 || *endp != 0)
+                       return -1;
+       }
+
+#ifdef CONFIG_DM_SPI_FLASH
+       /* Remove the old device, otherwise probe will just be a nop */
+       ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
+       if (!ret) {
+               device_remove(new);
+               device_unbind(new);
+       }
+       flash = NULL;
+       ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
+       if (ret) {
+               printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
+                      bus, cs, ret);
+               return 1;
+       }
+
+       flash = dev_get_uclass_priv(new);
+#else
+       if (flash)
+               spi_flash_free(flash);
+
+       new = spi_flash_probe(bus, cs, speed, mode);
+       flash = new;
+
+       if (!new) {
+               printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
+               return 1;
+       }
+
+       flash = new;
+#endif
+
+       return 0;
+}
+
+/**
+ * Write a block of data to SPI flash, first checking if it is different from
+ * what is already there.
+ *
+ * If the data being written is the same, then *skipped is incremented by len.
+ *
+ * @param flash                flash context pointer
+ * @param offset       flash offset to write
+ * @param len          number of bytes to write
+ * @param buf          buffer to write from
+ * @param cmp_buf      read buffer to use to compare data
+ * @param skipped      Count of skipped data (incremented by this function)
+ * @return NULL if OK, else a string containing the stage which failed
+ */
+static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
+               size_t len, const char *buf, char *cmp_buf, size_t *skipped)
+{
+       char *ptr = (char *)buf;
+
+       debug("offset=%#x, sector_size=%#x, len=%#zx\n",
+             offset, flash->sector_size, len);
+       /* Read the entire sector so to allow for rewriting */
+       if (spi_flash_read(flash, offset, flash->sector_size, cmp_buf))
+               return "read";
+       /* Compare only what is meaningful (len) */
+       if (memcmp(cmp_buf, buf, len) == 0) {
+               debug("Skip region %x size %zx: no change\n",
+                     offset, len);
+               *skipped += len;
+               return NULL;
+       }
+       /* Erase the entire sector */
+       if (spi_flash_erase(flash, offset, flash->sector_size))
+               return "erase";
+       /* If it's a partial sector, copy the data into the temp-buffer */
+       if (len != flash->sector_size) {
+               memcpy(cmp_buf, buf, len);
+               ptr = cmp_buf;
+       }
+       /* Write one complete sector */
+       if (spi_flash_write(flash, offset, flash->sector_size, ptr))
+               return "write";
+
+       return NULL;
+}
+
+/**
+ * Update an area of SPI flash by erasing and writing any blocks which need
+ * to change. Existing blocks with the correct data are left unchanged.
+ *
+ * @param flash                flash context pointer
+ * @param offset       flash offset to write
+ * @param len          number of bytes to write
+ * @param buf          buffer to write from
+ * @return 0 if ok, 1 on error
+ */
+static int spi_flash_update(struct spi_flash *flash, u32 offset,
+               size_t len, const char *buf)
+{
+       const char *err_oper = NULL;
+       char *cmp_buf;
+       const char *end = buf + len;
+       size_t todo;            /* number of bytes to do in this pass */
+       size_t skipped = 0;     /* statistics */
+       const ulong start_time = get_timer(0);
+       size_t scale = 1;
+       const char *start_buf = buf;
+       ulong delta;
+
+       if (end - buf >= 200)
+               scale = (end - buf) / 100;
+       cmp_buf = memalign(ARCH_DMA_MINALIGN, flash->sector_size);
+       if (cmp_buf) {
+               ulong last_update = get_timer(0);
+
+               for (; buf < end && !err_oper; buf += todo, offset += todo) {
+                       todo = min_t(size_t, end - buf, flash->sector_size);
+                       if (get_timer(last_update) > 100) {
+                               printf("   \rUpdating, %zu%% %lu B/s",
+                                      100 - (end - buf) / scale,
+                                       bytes_per_second(buf - start_buf,
+                                                        start_time));
+                               last_update = get_timer(0);
+                       }
+                       err_oper = spi_flash_update_block(flash, offset, todo,
+                                       buf, cmp_buf, &skipped);
+               }
+       } else {
+               err_oper = "malloc";
+       }
+       free(cmp_buf);
+       putc('\r');
+       if (err_oper) {
+               printf("SPI flash failed in %s step\n", err_oper);
+               return 1;
+       }
+
+       delta = get_timer(start_time);
+       printf("%zu bytes written, %zu bytes skipped", len - skipped,
+              skipped);
+       printf(" in %ld.%lds, speed %ld B/s\n",
+              delta / 1000, delta % 1000, bytes_per_second(len, start_time));
+
+       return 0;
+}
+
+static int do_spi_flash_read_write(int argc, char * const argv[])
+{
+       unsigned long addr;
+       void *buf;
+       char *endp;
+       int ret = 1;
+       int dev = 0;
+       loff_t offset, len, maxsize;
+
+       if (argc < 3)
+               return -1;
+
+       addr = simple_strtoul(argv[1], &endp, 16);
+       if (*argv[1] == 0 || *endp != 0)
+               return -1;
+
+       if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
+                            &maxsize, MTD_DEV_TYPE_NOR, flash->size))
+               return -1;
+
+       /* Consistency checking */
+       if (offset + len > flash->size) {
+               printf("ERROR: attempting %s past flash size (%#x)\n",
+                      argv[0], flash->size);
+               return 1;
+       }
+
+       buf = map_physmem(addr, len, MAP_WRBACK);
+       if (!buf) {
+               puts("Failed to map physical memory\n");
+               return 1;
+       }
+
+       if (strcmp(argv[0], "update") == 0) {
+               ret = spi_flash_update(flash, offset, len, buf);
+       } else if (strncmp(argv[0], "read", 4) == 0 ||
+                       strncmp(argv[0], "write", 5) == 0) {
+               int read;
+
+               read = strncmp(argv[0], "read", 4) == 0;
+               if (read)
+                       ret = spi_flash_read(flash, offset, len, buf);
+               else
+                       ret = spi_flash_write(flash, offset, len, buf);
+
+               printf("SF: %zu bytes @ %#x %s: ", (size_t)len, (u32)offset,
+                      read ? "Read" : "Written");
+               if (ret)
+                       printf("ERROR %d\n", ret);
+               else
+                       printf("OK\n");
+       }
+
+       unmap_physmem(buf, len);
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_spi_flash_erase(int argc, char * const argv[])
+{
+       int ret;
+       int dev = 0;
+       loff_t offset, len, maxsize;
+       ulong size;
+
+       if (argc < 3)
+               return -1;
+
+       if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
+                       MTD_DEV_TYPE_NOR, flash->size))
+               return -1;
+
+       ret = sf_parse_len_arg(argv[2], &size);
+       if (ret != 1)
+               return -1;
+
+       /* Consistency checking */
+       if (offset + size > flash->size) {
+               printf("ERROR: attempting %s past flash size (%#x)\n",
+                      argv[0], flash->size);
+               return 1;
+       }
+
+       ret = spi_flash_erase(flash, offset, size);
+       printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)size, (u32)offset,
+              ret ? "ERROR" : "OK");
+
+       return ret == 0 ? 0 : 1;
+}
+
+static int do_spi_protect(int argc, char * const argv[])
+{
+       int ret = 0;
+       loff_t start, len;
+       bool prot = false;
+
+       if (argc != 4)
+               return -1;
+
+       if (!str2off(argv[2], &start)) {
+               puts("start sector is not a valid number\n");
+               return 1;
+       }
+
+       if (!str2off(argv[3], &len)) {
+               puts("len is not a valid number\n");
+               return 1;
+       }
+
+       if (strcmp(argv[1], "lock") == 0)
+               prot = true;
+       else if (strcmp(argv[1], "unlock") == 0)
+               prot = false;
+       else
+               return -1;  /* Unknown parameter */
+
+       ret = spi_flash_protect(flash, start, len, prot);
+
+       return ret == 0 ? 0 : 1;
+}
+
+#ifdef CONFIG_CMD_SF_TEST
+enum {
+       STAGE_ERASE,
+       STAGE_CHECK,
+       STAGE_WRITE,
+       STAGE_READ,
+
+       STAGE_COUNT,
+};
+
+static char *stage_name[STAGE_COUNT] = {
+       "erase",
+       "check",
+       "write",
+       "read",
+};
+
+struct test_info {
+       int stage;
+       int bytes;
+       unsigned base_ms;
+       unsigned time_ms[STAGE_COUNT];
+};
+
+static void show_time(struct test_info *test, int stage)
+{
+       uint64_t speed; /* KiB/s */
+       int bps;        /* Bits per second */
+
+       speed = (long long)test->bytes * 1000;
+       if (test->time_ms[stage])
+               do_div(speed, test->time_ms[stage] * 1024);
+       bps = speed * 8;
+
+       printf("%d %s: %d ticks, %d KiB/s %d.%03d Mbps\n", stage,
+              stage_name[stage], test->time_ms[stage],
+              (int)speed, bps / 1000, bps % 1000);
+}
+
+static void spi_test_next_stage(struct test_info *test)
+{
+       test->time_ms[test->stage] = get_timer(test->base_ms);
+       show_time(test, test->stage);
+       test->base_ms = get_timer(0);
+       test->stage++;
+}
+
+/**
+ * Run a test on the SPI flash
+ *
+ * @param flash                SPI flash to use
+ * @param buf          Source buffer for data to write
+ * @param len          Size of data to read/write
+ * @param offset       Offset within flash to check
+ * @param vbuf         Verification buffer
+ * @return 0 if ok, -1 on error
+ */
+static int spi_flash_test(struct spi_flash *flash, uint8_t *buf, ulong len,
+                          ulong offset, uint8_t *vbuf)
+{
+       struct test_info test;
+       int i;
+
+       printf("SPI flash test:\n");
+       memset(&test, '\0', sizeof(test));
+       test.base_ms = get_timer(0);
+       test.bytes = len;
+       if (spi_flash_erase(flash, offset, len)) {
+               printf("Erase failed\n");
+               return -1;
+       }
+       spi_test_next_stage(&test);
+
+       if (spi_flash_read(flash, offset, len, vbuf)) {
+               printf("Check read failed\n");
+               return -1;
+       }
+       for (i = 0; i < len; i++) {
+               if (vbuf[i] != 0xff) {
+                       printf("Check failed at %d\n", i);
+                       print_buffer(i, vbuf + i, 1,
+                                    min_t(uint, len - i, 0x40), 0);
+                       return -1;
+               }
+       }
+       spi_test_next_stage(&test);
+
+       if (spi_flash_write(flash, offset, len, buf)) {
+               printf("Write failed\n");
+               return -1;
+       }
+       memset(vbuf, '\0', len);
+       spi_test_next_stage(&test);
+
+       if (spi_flash_read(flash, offset, len, vbuf)) {
+               printf("Read failed\n");
+               return -1;
+       }
+       spi_test_next_stage(&test);
+
+       for (i = 0; i < len; i++) {
+               if (buf[i] != vbuf[i]) {
+                       printf("Verify failed at %d, good data:\n", i);
+                       print_buffer(i, buf + i, 1,
+                                    min_t(uint, len - i, 0x40), 0);
+                       printf("Bad data:\n");
+                       print_buffer(i, vbuf + i, 1,
+                                    min_t(uint, len - i, 0x40), 0);
+                       return -1;
+               }
+       }
+       printf("Test passed\n");
+       for (i = 0; i < STAGE_COUNT; i++)
+               show_time(&test, i);
+
+       return 0;
+}
+
+static int do_spi_flash_test(int argc, char * const argv[])
+{
+       unsigned long offset;
+       unsigned long len;
+       uint8_t *buf, *from;
+       char *endp;
+       uint8_t *vbuf;
+       int ret;
+
+       if (argc < 3)
+               return -1;
+       offset = simple_strtoul(argv[1], &endp, 16);
+       if (*argv[1] == 0 || *endp != 0)
+               return -1;
+       len = simple_strtoul(argv[2], &endp, 16);
+       if (*argv[2] == 0 || *endp != 0)
+               return -1;
+
+       vbuf = memalign(ARCH_DMA_MINALIGN, len);
+       if (!vbuf) {
+               printf("Cannot allocate memory (%lu bytes)\n", len);
+               return 1;
+       }
+       buf = memalign(ARCH_DMA_MINALIGN, len);
+       if (!buf) {
+               free(vbuf);
+               printf("Cannot allocate memory (%lu bytes)\n", len);
+               return 1;
+       }
+
+       from = map_sysmem(CONFIG_SYS_TEXT_BASE, 0);
+       memcpy(buf, from, len);
+       ret = spi_flash_test(flash, buf, len, offset, vbuf);
+       free(vbuf);
+       free(buf);
+       if (ret) {
+               printf("Test failed\n");
+               return 1;
+       }
+
+       return 0;
+}
+#endif /* CONFIG_CMD_SF_TEST */
+
+static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       const char *cmd;
+       int ret;
+
+       /* need at least two arguments */
+       if (argc < 2)
+               goto usage;
+
+       cmd = argv[1];
+       --argc;
+       ++argv;
+
+       if (strcmp(cmd, "probe") == 0) {
+               ret = do_spi_flash_probe(argc, argv);
+               goto done;
+       }
+
+       /* The remaining commands require a selected device */
+       if (!flash) {
+               puts("No SPI flash selected. Please run `sf probe'\n");
+               return 1;
+       }
+
+       if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0 ||
+           strcmp(cmd, "update") == 0)
+               ret = do_spi_flash_read_write(argc, argv);
+       else if (strcmp(cmd, "erase") == 0)
+               ret = do_spi_flash_erase(argc, argv);
+       else if (strcmp(cmd, "protect") == 0)
+               ret = do_spi_protect(argc, argv);
+#ifdef CONFIG_CMD_SF_TEST
+       else if (!strcmp(cmd, "test"))
+               ret = do_spi_flash_test(argc, argv);
+#endif
+       else
+               ret = -1;
+
+done:
+       if (ret != -1)
+               return ret;
+
+usage:
+       return CMD_RET_USAGE;
+}
+
+#ifdef CONFIG_CMD_SF_TEST
+#define SF_TEST_HELP "\nsf test offset len             " \
+               "- run a very basic destructive test"
+#else
+#define SF_TEST_HELP
+#endif
+
+U_BOOT_CMD(
+       sf,     5,      1,      do_spi_flash,
+       "SPI flash sub-system",
+       "probe [[bus:]cs] [hz] [mode]   - init flash device on given SPI bus\n"
+       "                                 and chip select\n"
+       "sf read addr offset|partition len      - read `len' bytes starting at\n"
+       "                                         `offset' or from start of mtd\n"
+       "                                         `partition'to memory at `addr'\n"
+       "sf write addr offset|partition len     - write `len' bytes from memory\n"
+       "                                         at `addr' to flash at `offset'\n"
+       "                                         or to start of mtd `partition'\n"
+       "sf erase offset|partition [+]len       - erase `len' bytes from `offset'\n"
+       "                                         or from start of mtd `partition'\n"
+       "                                        `+len' round up `len' to block size\n"
+       "sf update addr offset|partition len    - erase and write `len' bytes from memory\n"
+       "                                         at `addr' to flash at `offset'\n"
+       "                                         or to start of mtd `partition'\n"
+       "sf protect lock/unlock sector len      - protect/unprotect 'len' bytes starting\n"
+       "                                         at address 'sector'\n"
+       SF_TEST_HELP
+);
diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c
new file mode 100644 (file)
index 0000000..783ea2e
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <hash.h>
+#include <u-boot/sha1.h>
+
+int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int flags = HASH_FLAG_ENV;
+       int ac;
+       char * const *av;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       av = argv + 1;
+       ac = argc - 1;
+#ifdef CONFIG_SHA1SUM_VERIFY
+       if (strcmp(*av, "-v") == 0) {
+               flags |= HASH_FLAG_VERIFY;
+               av++;
+               ac--;
+       }
+#endif
+
+       return hash_command("sha1", flags, cmdtp, flag, ac, av);
+}
+
+#ifdef CONFIG_SHA1SUM_VERIFY
+U_BOOT_CMD(
+       sha1sum,        5,      1,      do_sha1sum,
+       "compute SHA1 message digest",
+       "address count [[*]sum]\n"
+               "    - compute SHA1 message digest [save to sum]\n"
+       "sha1sum -v address count [*]sum\n"
+               "    - verify sha1sum of memory area"
+);
+#else
+U_BOOT_CMD(
+       sha1sum,        4,      1,      do_sha1sum,
+       "compute SHA1 message digest",
+       "address count [[*]sum]\n"
+               "    - compute SHA1 message digest [save to sum]"
+);
+#endif
diff --git a/cmd/softswitch.c b/cmd/softswitch.c
new file mode 100644 (file)
index 0000000..f75d926
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * cmd_softswitch.c - set the softswitch for bf60x
+ *
+ * Copyright (c) 2012 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/blackfin.h>
+#include <asm/soft_switch.h>
+
+int do_softswitch(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int switchaddr, value, pin, port;
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[2], "GPA") == 0)
+               port = IO_PORT_A;
+       else if (strcmp(argv[2], "GPB") == 0)
+               port = IO_PORT_B;
+       else
+               return CMD_RET_USAGE;
+
+       switchaddr = simple_strtoul(argv[1], NULL, 16);
+       pin = simple_strtoul(argv[3], NULL, 16);
+       value = simple_strtoul(argv[4], NULL, 16);
+
+       config_switch_bit(switchaddr, port, (1 << pin), IO_PORT_OUTPUT, value);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       softswitch_output, 5, 1, do_softswitch,
+       "switchaddr GPA/GPB pin_offset value",
+       ""
+);
diff --git a/cmd/sound.c b/cmd/sound.c
new file mode 100644 (file)
index 0000000..f5dd8bc
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics
+ * Rajeshwari Shinde <rajeshwari.s@samsung.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fdtdec.h>
+#include <sound.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Initilaise sound subsystem */
+static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int ret;
+
+       ret = sound_init(gd->fdt_blob);
+       if (ret) {
+               printf("Initialise Audio driver failed\n");
+               return CMD_RET_FAILURE;
+       }
+
+       return 0;
+}
+
+/* play sound from buffer */
+static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       int ret = 0;
+       int msec = 1000;
+       int freq = 400;
+
+       if (argc > 1)
+               msec = simple_strtoul(argv[1], NULL, 10);
+       if (argc > 2)
+               freq = simple_strtoul(argv[2], NULL, 10);
+
+       ret = sound_play(msec, freq);
+       if (ret) {
+               printf("play failed");
+               return CMD_RET_FAILURE;
+       }
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_sound_sub[] = {
+       U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
+       U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
+};
+
+/* process sound command */
+static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       cmd_tbl_t *c;
+
+       if (argc < 1)
+               return CMD_RET_USAGE;
+
+       /* Strip off leading 'sound' command argument */
+       argc--;
+       argv++;
+
+       c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
+
+       if (c)
+               return c->cmd(cmdtp, flag, argc, argv);
+       else
+               return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       sound, 4, 1, do_sound,
+       "sound sub-system",
+       "init - initialise the sound driver\n"
+       "sound play [len] [freq] - play a sound for len ms at freq hz\n"
+);
diff --git a/cmd/source.c b/cmd/source.c
new file mode 100644 (file)
index 0000000..db7ab7e
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * (C) Copyright 2001
+ * Kyle Harris, kharris@nexus-tech.net
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * The "source" command allows to define "script images", i. e. files
+ * that contain command sequences that can be executed by the command
+ * interpreter. It returns the exit status of the last command
+ * executed from the script. This is very similar to running a shell
+ * script in a UNIX shell, hence the name for the command.
+ */
+
+/* #define DEBUG */
+
+#include <common.h>
+#include <command.h>
+#include <image.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <asm/byteorder.h>
+#include <asm/io.h>
+#if defined(CONFIG_8xx)
+#include <mpc8xx.h>
+#endif
+
+int
+source (ulong addr, const char *fit_uname)
+{
+       ulong           len;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       const image_header_t *hdr;
+#endif
+       u32             *data;
+       int             verify;
+       void *buf;
+#if defined(CONFIG_FIT)
+       const void*     fit_hdr;
+       int             noffset;
+       const void      *fit_data;
+       size_t          fit_len;
+#endif
+
+       verify = getenv_yesno ("verify");
+
+       buf = map_sysmem(addr, 0);
+       switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+               hdr = buf;
+
+               if (!image_check_magic (hdr)) {
+                       puts ("Bad magic number\n");
+                       return 1;
+               }
+
+               if (!image_check_hcrc (hdr)) {
+                       puts ("Bad header crc\n");
+                       return 1;
+               }
+
+               if (verify) {
+                       if (!image_check_dcrc (hdr)) {
+                               puts ("Bad data crc\n");
+                               return 1;
+                       }
+               }
+
+               if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
+                       puts ("Bad image type\n");
+                       return 1;
+               }
+
+               /* get length of script */
+               data = (u32 *)image_get_data (hdr);
+
+               if ((len = uimage_to_cpu (*data)) == 0) {
+                       puts ("Empty Script\n");
+                       return 1;
+               }
+
+               /*
+                * scripts are just multi-image files with one component, seek
+                * past the zero-terminated sequence of image lengths to get
+                * to the actual image data
+                */
+               while (*data++);
+               break;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               if (fit_uname == NULL) {
+                       puts ("No FIT subimage unit name\n");
+                       return 1;
+               }
+
+               fit_hdr = buf;
+               if (!fit_check_format (fit_hdr)) {
+                       puts ("Bad FIT image format\n");
+                       return 1;
+               }
+
+               /* get script component image node offset */
+               noffset = fit_image_get_node (fit_hdr, fit_uname);
+               if (noffset < 0) {
+                       printf ("Can't find '%s' FIT subimage\n", fit_uname);
+                       return 1;
+               }
+
+               if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) {
+                       puts ("Not a image image\n");
+                       return 1;
+               }
+
+               /* verify integrity */
+               if (verify) {
+                       if (!fit_image_verify(fit_hdr, noffset)) {
+                               puts ("Bad Data Hash\n");
+                               return 1;
+                       }
+               }
+
+               /* get script subimage data address and length */
+               if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) {
+                       puts ("Could not find script subimage data\n");
+                       return 1;
+               }
+
+               data = (u32 *)fit_data;
+               len = (ulong)fit_len;
+               break;
+#endif
+       default:
+               puts ("Wrong image format for \"source\" command\n");
+               return 1;
+       }
+
+       debug ("** Script length: %ld\n", len);
+       return run_command_list((char *)data, len, 0);
+}
+
+/**************************************************/
+#if defined(CONFIG_CMD_SOURCE)
+static int do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr;
+       int rcode;
+       const char *fit_uname = NULL;
+
+       /* Find script image */
+       if (argc < 2) {
+               addr = CONFIG_SYS_LOAD_ADDR;
+               debug ("*  source: default load address = 0x%08lx\n", addr);
+#if defined(CONFIG_FIT)
+       } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) {
+               debug ("*  source: subimage '%s' from FIT image at 0x%08lx\n",
+                               fit_uname, addr);
+#endif
+       } else {
+               addr = simple_strtoul(argv[1], NULL, 16);
+               debug ("*  source: cmdline image address = 0x%08lx\n", addr);
+       }
+
+       printf ("## Executing script at %08lx\n", addr);
+       rcode = source (addr, fit_uname);
+       return rcode;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char source_help_text[] =
+       "[addr]\n"
+       "\t- run script starting at addr\n"
+       "\t- A valid image header must be present"
+#if defined(CONFIG_FIT)
+       "\n"
+       "For FIT format uImage addr must include subimage\n"
+       "unit name in the form of addr:<subimg_uname>"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       source, 2, 0,   do_source,
+       "run script from memory", source_help_text
+);
+#endif
diff --git a/cmd/spi.c b/cmd/spi.c
new file mode 100644 (file)
index 0000000..64c3ffc
--- /dev/null
+++ b/cmd/spi.c
@@ -0,0 +1,174 @@
+/*
+ * (C) Copyright 2002
+ * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * SPI Read/Write Utilities
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <spi.h>
+
+/*-----------------------------------------------------------------------
+ * Definitions
+ */
+
+#ifndef MAX_SPI_BYTES
+#   define MAX_SPI_BYTES 32    /* Maximum number of bytes we can handle */
+#endif
+
+#ifndef CONFIG_DEFAULT_SPI_BUS
+#   define CONFIG_DEFAULT_SPI_BUS      0
+#endif
+#ifndef CONFIG_DEFAULT_SPI_MODE
+#   define CONFIG_DEFAULT_SPI_MODE     SPI_MODE_0
+#endif
+
+/*
+ * Values from last command.
+ */
+static unsigned int    bus;
+static unsigned int    cs;
+static unsigned int    mode;
+static int             bitlen;
+static uchar           dout[MAX_SPI_BYTES];
+static uchar           din[MAX_SPI_BYTES];
+
+static int do_spi_xfer(int bus, int cs)
+{
+       struct spi_slave *slave;
+       int ret = 0;
+
+#ifdef CONFIG_DM_SPI
+       char name[30], *str;
+       struct udevice *dev;
+
+       snprintf(name, sizeof(name), "generic_%d:%d", bus, cs);
+       str = strdup(name);
+       ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv",
+                                str, &dev, &slave);
+       if (ret)
+               return ret;
+#else
+       slave = spi_setup_slave(bus, cs, 1000000, mode);
+       if (!slave) {
+               printf("Invalid device %d:%d\n", bus, cs);
+               return -EINVAL;
+       }
+#endif
+
+       ret = spi_claim_bus(slave);
+       if (ret)
+               goto done;
+       ret = spi_xfer(slave, bitlen, dout, din,
+                      SPI_XFER_BEGIN | SPI_XFER_END);
+#ifndef CONFIG_DM_SPI
+       /* We don't get an error code in this case */
+       if (ret)
+               ret = -EIO;
+#endif
+       if (ret) {
+               printf("Error %d during SPI transaction\n", ret);
+       } else {
+               int j;
+
+               for (j = 0; j < ((bitlen + 7) / 8); j++)
+                       printf("%02X", din[j]);
+               printf("\n");
+       }
+done:
+       spi_release_bus(slave);
+#ifndef CONFIG_DM_SPI
+       spi_free_slave(slave);
+#endif
+
+       return ret;
+}
+
+/*
+ * SPI read/write
+ *
+ * Syntax:
+ *   spi {dev} {num_bits} {dout}
+ *     {dev} is the device number for controlling chip select (see TBD)
+ *     {num_bits} is the number of bits to send & receive (base 10)
+ *     {dout} is a hexadecimal string of data to send
+ * The command prints out the hexadecimal string received via SPI.
+ */
+
+int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char  *cp = 0;
+       uchar tmp;
+       int   j;
+
+       /*
+        * We use the last specified parameters, unless new ones are
+        * entered.
+        */
+
+       if ((flag & CMD_FLAG_REPEAT) == 0)
+       {
+               if (argc >= 2) {
+                       mode = CONFIG_DEFAULT_SPI_MODE;
+                       bus = simple_strtoul(argv[1], &cp, 10);
+                       if (*cp == ':') {
+                               cs = simple_strtoul(cp+1, &cp, 10);
+                       } else {
+                               cs = bus;
+                               bus = CONFIG_DEFAULT_SPI_BUS;
+                       }
+                       if (*cp == '.')
+                               mode = simple_strtoul(cp+1, NULL, 10);
+               }
+               if (argc >= 3)
+                       bitlen = simple_strtoul(argv[2], NULL, 10);
+               if (argc >= 4) {
+                       cp = argv[3];
+                       for(j = 0; *cp; j++, cp++) {
+                               tmp = *cp - '0';
+                               if(tmp > 9)
+                                       tmp -= ('A' - '0') - 10;
+                               if(tmp > 15)
+                                       tmp -= ('a' - 'A');
+                               if(tmp > 15) {
+                                       printf("Hex conversion error on %c\n", *cp);
+                                       return 1;
+                               }
+                               if((j % 2) == 0)
+                                       dout[j / 2] = (tmp << 4);
+                               else
+                                       dout[j / 2] |= tmp;
+                       }
+               }
+       }
+
+       if ((bitlen < 0) || (bitlen >  (MAX_SPI_BYTES * 8))) {
+               printf("Invalid bitlen %d\n", bitlen);
+               return 1;
+       }
+
+       if (do_spi_xfer(bus, cs))
+               return 1;
+
+       return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+       sspi,   5,      1,      do_spi,
+       "SPI utility command",
+       "[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
+       "<bus>     - Identifies the SPI bus\n"
+       "<cs>      - Identifies the chip select\n"
+       "<mode>    - Identifies the SPI mode to use\n"
+       "<bit_len> - Number of bits to send (base 10)\n"
+       "<dout>    - Hexadecimal string that gets sent"
+);
diff --git a/cmd/spibootldr.c b/cmd/spibootldr.c
new file mode 100644 (file)
index 0000000..ca76dde
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * U-boot - spibootldr.c
+ *
+ * Copyright (c) 2005-2008 Analog Devices Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <command.h>
+
+#include <asm/blackfin.h>
+#include <asm/mach-common/bits/bootrom.h>
+
+int do_spibootldr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       s32 addr;
+
+       /* Get the address */
+       if (argc < 2)
+               addr = 0;
+       else
+               addr = simple_strtoul(argv[1], NULL, 16);
+
+       printf("## Booting ldr image at SPI offset 0x%x ...\n", addr);
+
+       return bfrom_SpiBoot(addr, BFLAG_PERIPHERAL | 4, 0, NULL);
+}
+
+U_BOOT_CMD(
+       spibootldr, 2, 0, do_spibootldr,
+       "boot ldr image from spi",
+       "[offset]\n"
+       "    - boot ldr image stored at offset into spi\n");
diff --git a/cmd/spl.c b/cmd/spl.c
new file mode 100644 (file)
index 0000000..057764a
--- /dev/null
+++ b/cmd/spl.c
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <cmd_spl.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const char **subcmd_list[] = {
+
+       [SPL_EXPORT_FDT] = (const char * []) {
+#ifdef CONFIG_OF_LIBFDT
+               "start",
+               "loados",
+       #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
+               "ramdisk",
+       #endif
+               "fdt",
+               "cmdline",
+               "bdt",
+               "prep",
+#endif
+               NULL,
+       },
+       [SPL_EXPORT_ATAGS] = (const char * []) {
+#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
+       defined(CONFIG_CMDLINE_TAG) || \
+       defined(CONFIG_INITRD_TAG) || \
+       defined(CONFIG_SERIAL_TAG) || \
+       defined(CONFIG_REVISION_TAG)
+               "start",
+               "loados",
+#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
+               "ramdisk",
+#endif
+               "cmdline",
+               "bdt",
+               "prep",
+#endif
+               NULL,
+       },
+       NULL
+};
+
+/* Calls bootm with the parameters given */
+static int call_bootm(int argc, char * const argv[], const char *subcommand[])
+{
+       char *bootm_argv[5];
+
+       int i = 0;
+       int ret = 0;
+       int j;
+
+       /* create paramter array */
+       bootm_argv[0] = "do_bootm";
+       switch (argc) {
+       case 3:
+               bootm_argv[4] = argv[2]; /* fdt addr */
+       case 2:
+               bootm_argv[3] = argv[1]; /* initrd addr */
+       case 1:
+               bootm_argv[2] = argv[0]; /* kernel addr */
+       }
+
+
+       /*
+        * - do the work -
+        * exec subcommands of do_bootm to init the images
+        * data structure
+        */
+       while (subcommand[i] != NULL) {
+               bootm_argv[1] = (char *)subcommand[i];
+               debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
+               for (j = 0; j < argc; j++)
+                       debug("%s ", bootm_argv[j + 2]);
+               debug("\n");
+
+               ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
+                       bootm_argv);
+               debug("Subcommand retcode: %d\n", ret);
+               i++;
+       }
+
+       if (ret) {
+               printf("ERROR prep subcommand failed!\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_spl_export_sub[] = {
+       U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
+       U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
+};
+
+static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const cmd_tbl_t *c;
+
+       if (argc < 2) /* no subcommand */
+               return cmd_usage(cmdtp);
+
+       c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
+               ARRAY_SIZE(cmd_spl_export_sub));
+       if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
+               argc -= 2;
+               argv += 2;
+               if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
+                       return -1;
+               switch ((int)c->cmd) {
+#ifdef CONFIG_OF_LIBFDT
+               case SPL_EXPORT_FDT:
+                       printf("Argument image is now in RAM: 0x%p\n",
+                               (void *)images.ft_addr);
+                       break;
+#endif
+               case SPL_EXPORT_ATAGS:
+                       printf("Argument image is now in RAM at: 0x%p\n",
+                               (void *)gd->bd->bi_boot_params);
+                       break;
+               }
+       } else {
+               /* Unrecognized command */
+               return cmd_usage(cmdtp);
+       }
+
+       return 0;
+}
+
+static cmd_tbl_t cmd_spl_sub[] = {
+       U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
+};
+
+static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const cmd_tbl_t *c;
+       int cmd;
+
+       if (argc < 2) /* no subcommand */
+               return cmd_usage(cmdtp);
+
+       c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
+       if (c) {
+               cmd = (int)c->cmd;
+               switch (cmd) {
+               case SPL_EXPORT:
+                       argc--;
+                       argv++;
+                       if (spl_export(cmdtp, flag, argc, argv))
+                               printf("Subcommand failed\n");
+                       break;
+               default:
+                       /* unrecognized command */
+                       return cmd_usage(cmdtp);
+               }
+       } else {
+               /* Unrecognized command */
+               return cmd_usage(cmdtp);
+       }
+       return 0;
+}
+
+U_BOOT_CMD(
+       spl, 6 , 1, do_spl, "SPL configuration",
+       "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
+       "\timg\t\t\"atags\" or \"fdt\"\n"
+       "\tkernel_addr\taddress where a kernel image is stored.\n"
+       "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
+       "\tinitrd_addr\taddress of initial ramdisk\n"
+       "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
+       "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
+       );
diff --git a/cmd/strings.c b/cmd/strings.c
new file mode 100644 (file)
index 0000000..41b1665
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * cmd_strings.c - just like `strings` command
+ *
+ * Copyright (c) 2008 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <config.h>
+#include <common.h>
+#include <command.h>
+
+static char *start_addr, *last_addr;
+
+int do_strings(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc == 1)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               start_addr = (char *)simple_strtoul(argv[1], NULL, 16);
+               if (argc > 2)
+                       last_addr = (char *)simple_strtoul(argv[2], NULL, 16);
+               else
+                       last_addr = (char *)-1;
+       }
+
+       char *addr = start_addr;
+       do {
+               puts(addr);
+               puts("\n");
+               addr += strlen(addr) + 1;
+       } while (addr[0] && addr < last_addr);
+
+       last_addr = addr + (last_addr - start_addr);
+       start_addr = addr;
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       strings, 3, 1, do_strings,
+       "display strings",
+       "<addr> [byte count]\n"
+       "    - display strings at <addr> for at least [byte count] or first double NUL"
+);
diff --git a/cmd/terminal.c b/cmd/terminal.c
new file mode 100644 (file)
index 0000000..4b9c0b3
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * (C) Copyright 2007 OpenMoko, Inc.
+ * Written by Harald Welte <laforge@openmoko.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <stdio_dev.h>
+#include <serial.h>
+
+int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
+{
+       int last_tilde = 0;
+       struct stdio_dev *dev = NULL;
+
+       if (argc < 1)
+               return -1;
+
+       /* Scan for selected output/input device */
+       dev = stdio_get_by_name(argv[1]);
+       if (!dev)
+               return -1;
+
+       serial_reinit_all();
+       printf("Entering terminal mode for port %s\n", dev->name);
+       puts("Use '~.' to leave the terminal and get back to u-boot\n");
+
+       while (1) {
+               int c;
+
+               /* read from console and display on serial port */
+               if (stdio_devices[0]->tstc()) {
+                       c = stdio_devices[0]->getc();
+                       if (last_tilde == 1) {
+                               if (c == '.') {
+                                       putc(c);
+                                       putc('\n');
+                                       break;
+                               } else {
+                                       last_tilde = 0;
+                                       /* write the delayed tilde */
+                                       dev->putc('~');
+                                       /* fall-through to print current
+                                        * character */
+                               }
+                       }
+                       if (c == '~') {
+                               last_tilde = 1;
+                               puts("[u-boot]");
+                               putc(c);
+                       }
+                       dev->putc(c);
+               }
+
+               /* read from serial port and display on console */
+               if (dev->tstc()) {
+                       c = dev->getc();
+                       putc(c);
+               }
+       }
+       return 0;
+}
+
+
+/***************************************************/
+
+U_BOOT_CMD(
+       terminal,       3,      1,      do_terminal,
+       "start terminal emulator",
+       ""
+);
diff --git a/cmd/test.c b/cmd/test.c
new file mode 100644 (file)
index 0000000..7285f75
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+
+#define OP_INVALID     0
+#define OP_NOT         1
+#define OP_OR          2
+#define OP_AND         3
+#define OP_STR_EMPTY   4
+#define OP_STR_NEMPTY  5
+#define OP_STR_EQ      6
+#define OP_STR_NEQ     7
+#define OP_STR_LT      8
+#define OP_STR_GT      9
+#define OP_INT_EQ      10
+#define OP_INT_NEQ     11
+#define OP_INT_LT      12
+#define OP_INT_LE      13
+#define OP_INT_GT      14
+#define OP_INT_GE      15
+#define OP_FILE_EXISTS 16
+
+const struct {
+       int arg;
+       const char *str;
+       int op;
+       int adv;
+} op_adv[] = {
+       {1, "=", OP_STR_EQ, 3},
+       {1, "!=", OP_STR_NEQ, 3},
+       {1, "<", OP_STR_LT, 3},
+       {1, ">", OP_STR_GT, 3},
+       {1, "-eq", OP_INT_EQ, 3},
+       {1, "-ne", OP_INT_NEQ, 3},
+       {1, "-lt", OP_INT_LT, 3},
+       {1, "-le", OP_INT_LE, 3},
+       {1, "-gt", OP_INT_GT, 3},
+       {1, "-ge", OP_INT_GE, 3},
+       {0, "!", OP_NOT, 1},
+       {0, "-o", OP_OR, 1},
+       {0, "-a", OP_AND, 1},
+       {0, "-z", OP_STR_EMPTY, 2},
+       {0, "-n", OP_STR_NEMPTY, 2},
+       {0, "-e", OP_FILE_EXISTS, 4},
+};
+
+static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char * const *ap;
+       int i, op, left, adv, expr, last_expr, last_unop, last_binop;
+
+       /* args? */
+       if (argc < 3)
+               return 1;
+
+#ifdef DEBUG
+       {
+               debug("test(%d):", argc);
+               left = 1;
+               while (argv[left])
+                       debug(" '%s'", argv[left++]);
+       }
+#endif
+
+       left = argc - 1;
+       ap = argv + 1;
+       expr = 0;
+       last_unop = OP_INVALID;
+       last_binop = OP_INVALID;
+       last_expr = -1;
+       while (left > 0) {
+               for (i = 0; i < ARRAY_SIZE(op_adv); i++) {
+                       if (left <= op_adv[i].arg)
+                               continue;
+                       if (!strcmp(ap[op_adv[i].arg], op_adv[i].str)) {
+                               op = op_adv[i].op;
+                               adv = op_adv[i].adv;
+                               break;
+                       }
+               }
+               if (i == ARRAY_SIZE(op_adv)) {
+                       expr = 1;
+                       break;
+               }
+               if (left < adv) {
+                       expr = 1;
+                       break;
+               }
+
+               switch (op) {
+               case OP_STR_EMPTY:
+                       expr = strlen(ap[1]) == 0 ? 1 : 0;
+                       break;
+               case OP_STR_NEMPTY:
+                       expr = strlen(ap[1]) == 0 ? 0 : 1;
+                       break;
+               case OP_STR_EQ:
+                       expr = strcmp(ap[0], ap[2]) == 0;
+                       break;
+               case OP_STR_NEQ:
+                       expr = strcmp(ap[0], ap[2]) != 0;
+                       break;
+               case OP_STR_LT:
+                       expr = strcmp(ap[0], ap[2]) < 0;
+                       break;
+               case OP_STR_GT:
+                       expr = strcmp(ap[0], ap[2]) > 0;
+                       break;
+               case OP_INT_EQ:
+                       expr = simple_strtol(ap[0], NULL, 10) ==
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_INT_NEQ:
+                       expr = simple_strtol(ap[0], NULL, 10) !=
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_INT_LT:
+                       expr = simple_strtol(ap[0], NULL, 10) <
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_INT_LE:
+                       expr = simple_strtol(ap[0], NULL, 10) <=
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_INT_GT:
+                       expr = simple_strtol(ap[0], NULL, 10) >
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_INT_GE:
+                       expr = simple_strtol(ap[0], NULL, 10) >=
+                                       simple_strtol(ap[2], NULL, 10);
+                       break;
+               case OP_FILE_EXISTS:
+                       expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY);
+                       break;
+               }
+
+               switch (op) {
+               case OP_OR:
+                       last_expr = expr;
+                       last_binop = OP_OR;
+                       break;
+               case OP_AND:
+                       last_expr = expr;
+                       last_binop = OP_AND;
+                       break;
+               case OP_NOT:
+                       if (last_unop == OP_NOT)
+                               last_unop = OP_INVALID;
+                       else
+                               last_unop = OP_NOT;
+                       break;
+               default:
+                       if (last_unop == OP_NOT) {
+                               expr = !expr;
+                               last_unop = OP_INVALID;
+                       }
+
+                       if (last_binop == OP_OR)
+                               expr = last_expr || expr;
+                       else if (last_binop == OP_AND)
+                               expr = last_expr && expr;
+                       last_binop = OP_INVALID;
+
+                       break;
+               }
+
+               ap += adv; left -= adv;
+       }
+
+       expr = !expr;
+
+       debug (": returns %d\n", expr);
+
+       return expr;
+}
+
+#undef true
+#undef false
+
+U_BOOT_CMD(
+       test,   CONFIG_SYS_MAXARGS,     1,      do_test,
+       "minimal test like /bin/sh",
+       "[args..]"
+);
+
+static int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return 1;
+}
+
+U_BOOT_CMD(
+       false,  CONFIG_SYS_MAXARGS,     1,      do_false,
+       "do nothing, unsuccessfully",
+       NULL
+);
+
+static int do_true(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return 0;
+}
+
+U_BOOT_CMD(
+       true,   CONFIG_SYS_MAXARGS,     1,      do_true,
+       "do nothing, successfully",
+       NULL
+);
diff --git a/cmd/thordown.c b/cmd/thordown.c
new file mode 100644 (file)
index 0000000..436b7f5
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
+ *
+ * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <thor.h>
+#include <dfu.h>
+#include <g_dnl.h>
+#include <usb.h>
+
+int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc < 4)
+               return CMD_RET_USAGE;
+
+       char *usb_controller = argv[1];
+       char *interface = argv[2];
+       char *devstring = argv[3];
+
+       int ret;
+
+       puts("TIZEN \"THOR\" Downloader\n");
+
+       ret = dfu_init_env_entities(interface, devstring);
+       if (ret)
+               goto done;
+
+       int controller_index = simple_strtoul(usb_controller, NULL, 0);
+       ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+       if (ret) {
+               error("USB init failed: %d", ret);
+               ret = CMD_RET_FAILURE;
+               goto exit;
+       }
+
+       g_dnl_register("usb_dnl_thor");
+
+       ret = thor_init();
+       if (ret) {
+               error("THOR DOWNLOAD failed: %d", ret);
+               ret = CMD_RET_FAILURE;
+               goto exit;
+       }
+
+       ret = thor_handle();
+       if (ret) {
+               error("THOR failed: %d", ret);
+               ret = CMD_RET_FAILURE;
+               goto exit;
+       }
+
+exit:
+       g_dnl_unregister();
+       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+done:
+       dfu_free_entities();
+
+       return ret;
+}
+
+U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
+          "TIZEN \"THOR\" downloader",
+          "<USB_controller> <interface> <dev>\n"
+          "  - device software upgrade via LTHOR TIZEN dowload\n"
+          "    program via <USB_controller> on device <dev>,\n"
+          "    attached to interface <interface>\n"
+);
diff --git a/cmd/time.c b/cmd/time.c
new file mode 100644 (file)
index 0000000..de57e3b
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static void report_time(ulong cycles)
+{
+       ulong minutes, seconds, milliseconds;
+       ulong total_seconds, remainder;
+
+       total_seconds = cycles / CONFIG_SYS_HZ;
+       remainder = cycles % CONFIG_SYS_HZ;
+       minutes = total_seconds / 60;
+       seconds = total_seconds % 60;
+       /* approximate millisecond value */
+       milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
+
+       printf("\ntime:");
+       if (minutes)
+               printf(" %lu minutes,", minutes);
+       printf(" %lu.%03lu seconds\n", seconds, milliseconds);
+}
+
+static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong cycles = 0;
+       int retval = 0;
+       int repeatable;
+
+       if (argc == 1)
+               return CMD_RET_USAGE;
+
+       retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
+       report_time(cycles);
+
+       return retval;
+}
+
+U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
+               "run commands and summarize execution time",
+               "command [args...]\n");
diff --git a/cmd/tpm.c b/cmd/tpm.c
new file mode 100644 (file)
index 0000000..add6bfb
--- /dev/null
+++ b/cmd/tpm.c
@@ -0,0 +1,802 @@
+/*
+ * Copyright (c) 2013 The Chromium OS Authors.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <malloc.h>
+#include <tpm.h>
+#include <asm/unaligned.h>
+#include <linux/string.h>
+
+/* Useful constants */
+enum {
+       DIGEST_LENGTH           = 20,
+       /* max lengths, valid for RSA keys <= 2048 bits */
+       TPM_PUBKEY_MAX_LENGTH   = 288,
+};
+
+/**
+ * Print a byte string in hexdecimal format, 16-bytes per line.
+ *
+ * @param data         byte string to be printed
+ * @param count                number of bytes to be printed
+ */
+static void print_byte_string(uint8_t *data, size_t count)
+{
+       int i, print_newline = 0;
+
+       for (i = 0; i < count; i++) {
+               printf(" %02x", data[i]);
+               print_newline = (i % 16 == 15);
+               if (print_newline)
+                       putc('\n');
+       }
+       /* Avoid duplicated newline at the end */
+       if (!print_newline)
+               putc('\n');
+}
+
+/**
+ * Convert a text string of hexdecimal values into a byte string.
+ *
+ * @param bytes                text string of hexdecimal values with no space
+ *                     between them
+ * @param data         output buffer for byte string.  The caller has to make
+ *                     sure it is large enough for storing the output.  If
+ *                     NULL is passed, a large enough buffer will be allocated,
+ *                     and the caller must free it.
+ * @param count_ptr    output variable for the length of byte string
+ * @return pointer to output buffer
+ */
+static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
+{
+       char byte[3];
+       size_t count, length;
+       int i;
+
+       if (!bytes)
+               return NULL;
+       length = strlen(bytes);
+       count = length / 2;
+
+       if (!data)
+               data = malloc(count);
+       if (!data)
+               return NULL;
+
+       byte[2] = '\0';
+       for (i = 0; i < length; i += 2) {
+               byte[0] = bytes[i];
+               byte[1] = bytes[i + 1];
+               data[i / 2] = (uint8_t)simple_strtoul(byte, NULL, 16);
+       }
+
+       if (count_ptr)
+               *count_ptr = count;
+
+       return data;
+}
+
+/**
+ * report_return_code() - Report any error and return failure or success
+ *
+ * @param return_code  TPM command return code
+ * @return value of enum command_ret_t
+ */
+static int report_return_code(int return_code)
+{
+       if (return_code) {
+               printf("Error: %d\n", return_code);
+               return CMD_RET_FAILURE;
+       } else {
+               return CMD_RET_SUCCESS;
+       }
+}
+
+/**
+ * Return number of values defined by a type string.
+ *
+ * @param type_str     type string
+ * @return number of values of type string
+ */
+static int type_string_get_num_values(const char *type_str)
+{
+       return strlen(type_str);
+}
+
+/**
+ * Return total size of values defined by a type string.
+ *
+ * @param type_str     type string
+ * @return total size of values of type string, or 0 if type string
+ *  contains illegal type character.
+ */
+static size_t type_string_get_space_size(const char *type_str)
+{
+       size_t size;
+
+       for (size = 0; *type_str; type_str++) {
+               switch (*type_str) {
+               case 'b':
+                       size += 1;
+                       break;
+               case 'w':
+                       size += 2;
+                       break;
+               case 'd':
+                       size += 4;
+                       break;
+               default:
+                       return 0;
+               }
+       }
+
+       return size;
+}
+
+/**
+ * Allocate a buffer large enough to hold values defined by a type
+ * string.  The caller has to free the buffer.
+ *
+ * @param type_str     type string
+ * @param count                pointer for storing size of buffer
+ * @return pointer to buffer or NULL on error
+ */
+static void *type_string_alloc(const char *type_str, uint32_t *count)
+{
+       void *data;
+       size_t size;
+
+       size = type_string_get_space_size(type_str);
+       if (!size)
+               return NULL;
+       data = malloc(size);
+       if (data)
+               *count = size;
+
+       return data;
+}
+
+/**
+ * Pack values defined by a type string into a buffer.  The buffer must have
+ * large enough space.
+ *
+ * @param type_str     type string
+ * @param values       text strings of values to be packed
+ * @param data         output buffer of values
+ * @return 0 on success, non-0 on error
+ */
+static int type_string_pack(const char *type_str, char * const values[],
+               uint8_t *data)
+{
+       size_t offset;
+       uint32_t value;
+
+       for (offset = 0; *type_str; type_str++, values++) {
+               value = simple_strtoul(values[0], NULL, 0);
+               switch (*type_str) {
+               case 'b':
+                       data[offset] = value;
+                       offset += 1;
+                       break;
+               case 'w':
+                       put_unaligned_be16(value, data + offset);
+                       offset += 2;
+                       break;
+               case 'd':
+                       put_unaligned_be32(value, data + offset);
+                       offset += 4;
+                       break;
+               default:
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+/**
+ * Read values defined by a type string from a buffer, and write these values
+ * to environment variables.
+ *
+ * @param type_str     type string
+ * @param data         input buffer of values
+ * @param vars         names of environment variables
+ * @return 0 on success, non-0 on error
+ */
+static int type_string_write_vars(const char *type_str, uint8_t *data,
+               char * const vars[])
+{
+       size_t offset;
+       uint32_t value;
+
+       for (offset = 0; *type_str; type_str++, vars++) {
+               switch (*type_str) {
+               case 'b':
+                       value = data[offset];
+                       offset += 1;
+                       break;
+               case 'w':
+                       value = get_unaligned_be16(data + offset);
+                       offset += 2;
+                       break;
+               case 'd':
+                       value = get_unaligned_be32(data + offset);
+                       offset += 4;
+                       break;
+               default:
+                       return -1;
+               }
+               if (setenv_ulong(*vars, value))
+                       return -1;
+       }
+
+       return 0;
+}
+
+static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       enum tpm_startup_type mode;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+       if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
+               mode = TPM_ST_CLEAR;
+       } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
+               mode = TPM_ST_STATE;
+       } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
+               mode = TPM_ST_DEACTIVATED;
+       } else {
+               printf("Couldn't recognize mode string: %s\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       return report_return_code(tpm_startup(mode));
+}
+
+static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, perm, size;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[1], NULL, 0);
+       perm = simple_strtoul(argv[2], NULL, 0);
+       size = simple_strtoul(argv[3], NULL, 0);
+
+       return report_return_code(tpm_nv_define_space(index, perm, size));
+}
+
+static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, count, rc;
+       void *data;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[1], NULL, 0);
+       data = (void *)simple_strtoul(argv[2], NULL, 0);
+       count = simple_strtoul(argv[3], NULL, 0);
+
+       rc = tpm_nv_read_value(index, data, count);
+       if (!rc) {
+               puts("area content:\n");
+               print_byte_string(data, count);
+       }
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, rc;
+       size_t count;
+       void *data;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[1], NULL, 0);
+       data = parse_byte_string(argv[2], NULL, &count);
+       if (!data) {
+               printf("Couldn't parse byte string %s\n", argv[2]);
+               return CMD_RET_FAILURE;
+       }
+
+       rc = tpm_nv_write_value(index, data, count);
+       free(data);
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, rc;
+       uint8_t in_digest[20], out_digest[20];
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[1], NULL, 0);
+       if (!parse_byte_string(argv[2], in_digest, NULL)) {
+               printf("Couldn't parse byte string %s\n", argv[2]);
+               return CMD_RET_FAILURE;
+       }
+
+       rc = tpm_extend(index, in_digest, out_digest);
+       if (!rc) {
+               puts("PCR value after execution of the command:\n");
+               print_byte_string(out_digest, sizeof(out_digest));
+       }
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, count, rc;
+       void *data;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[1], NULL, 0);
+       data = (void *)simple_strtoul(argv[2], NULL, 0);
+       count = simple_strtoul(argv[3], NULL, 0);
+
+       rc = tpm_pcr_read(index, data, count);
+       if (!rc) {
+               puts("Named PCR content:\n");
+               print_byte_string(data, count);
+       }
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint16_t presence;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+       presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
+
+       return report_return_code(tpm_tsc_physical_presence(presence));
+}
+
+static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t count, rc;
+       void *data;
+
+       if (argc != 3)
+               return CMD_RET_USAGE;
+       data = (void *)simple_strtoul(argv[1], NULL, 0);
+       count = simple_strtoul(argv[2], NULL, 0);
+
+       rc = tpm_read_pubek(data, count);
+       if (!rc) {
+               puts("pubek value:\n");
+               print_byte_string(data, count);
+       }
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint8_t state;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+       state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
+
+       return report_return_code(tpm_physical_set_deactivated(state));
+}
+
+static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t cap_area, sub_cap, rc;
+       void *cap;
+       size_t count;
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+       cap_area = simple_strtoul(argv[1], NULL, 0);
+       sub_cap = simple_strtoul(argv[2], NULL, 0);
+       cap = (void *)simple_strtoul(argv[3], NULL, 0);
+       count = simple_strtoul(argv[4], NULL, 0);
+
+       rc = tpm_get_capability(cap_area, sub_cap, cap, count);
+       if (!rc) {
+               puts("capability information:\n");
+               print_byte_string(cap, count);
+       }
+
+       return report_return_code(rc);
+}
+
+#define TPM_COMMAND_NO_ARG(cmd)                                \
+static int do_##cmd(cmd_tbl_t *cmdtp, int flag,                \
+               int argc, char * const argv[])          \
+{                                                      \
+       if (argc != 1)                                  \
+               return CMD_RET_USAGE;                   \
+       return report_return_code(cmd());               \
+}
+
+TPM_COMMAND_NO_ARG(tpm_init)
+TPM_COMMAND_NO_ARG(tpm_self_test_full)
+TPM_COMMAND_NO_ARG(tpm_continue_self_test)
+TPM_COMMAND_NO_ARG(tpm_force_clear)
+TPM_COMMAND_NO_ARG(tpm_physical_enable)
+TPM_COMMAND_NO_ARG(tpm_physical_disable)
+
+static int get_tpm(struct udevice **devp)
+{
+       int rc;
+
+       rc = uclass_first_device(UCLASS_TPM, devp);
+       if (rc) {
+               printf("Could not find TPM (ret=%d)\n", rc);
+               return CMD_RET_FAILURE;
+       }
+
+       return 0;
+}
+
+static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       struct udevice *dev;
+       char buf[80];
+       int rc;
+
+       rc = get_tpm(&dev);
+       if (rc)
+               return rc;
+       rc = tpm_get_desc(dev, buf, sizeof(buf));
+       if (rc < 0) {
+               printf("Couldn't get TPM info (%d)\n", rc);
+               return CMD_RET_FAILURE;
+       }
+       printf("%s\n", buf);
+
+       return 0;
+}
+
+static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       struct udevice *dev;
+       void *command;
+       uint8_t response[1024];
+       size_t count, response_length = sizeof(response);
+       uint32_t rc;
+
+       command = parse_byte_string(argv[1], NULL, &count);
+       if (!command) {
+               printf("Couldn't parse byte string %s\n", argv[1]);
+               return CMD_RET_FAILURE;
+       }
+
+       rc = get_tpm(&dev);
+       if (rc)
+               return rc;
+
+       rc = tpm_xfer(dev, command, count, response, &response_length);
+       free(command);
+       if (!rc) {
+               puts("tpm response:\n");
+               print_byte_string(response, response_length);
+       }
+
+       return report_return_code(rc);
+}
+
+static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, perm, size;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+       size = type_string_get_space_size(argv[1]);
+       if (!size) {
+               printf("Couldn't parse arguments\n");
+               return CMD_RET_USAGE;
+       }
+       index = simple_strtoul(argv[2], NULL, 0);
+       perm = simple_strtoul(argv[3], NULL, 0);
+
+       return report_return_code(tpm_nv_define_space(index, perm, size));
+}
+
+static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, count, err;
+       void *data;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+       if (argc != 3 + type_string_get_num_values(argv[1]))
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[2], NULL, 0);
+       data = type_string_alloc(argv[1], &count);
+       if (!data) {
+               printf("Couldn't parse arguments\n");
+               return CMD_RET_USAGE;
+       }
+
+       err = tpm_nv_read_value(index, data, count);
+       if (!err) {
+               if (type_string_write_vars(argv[1], data, argv + 3)) {
+                       printf("Couldn't write to variables\n");
+                       err = ~0;
+               }
+       }
+       free(data);
+
+       return report_return_code(err);
+}
+
+static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t index, count, err;
+       void *data;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+       if (argc != 3 + type_string_get_num_values(argv[1]))
+               return CMD_RET_USAGE;
+       index = simple_strtoul(argv[2], NULL, 0);
+       data = type_string_alloc(argv[1], &count);
+       if (!data) {
+               printf("Couldn't parse arguments\n");
+               return CMD_RET_USAGE;
+       }
+       if (type_string_pack(argv[1], argv + 3, data)) {
+               printf("Couldn't parse arguments\n");
+               free(data);
+               return CMD_RET_USAGE;
+       }
+
+       err = tpm_nv_write_value(index, data, count);
+       free(data);
+
+       return report_return_code(err);
+}
+
+#ifdef CONFIG_TPM_AUTH_SESSIONS
+
+static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t auth_handle, err;
+
+       err = tpm_oiap(&auth_handle);
+
+       return report_return_code(err);
+}
+
+static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t parent_handle, key_len, key_handle, err;
+       uint8_t usage_auth[DIGEST_LENGTH];
+       void *key;
+
+       if (argc < 5)
+               return CMD_RET_USAGE;
+
+       parent_handle = simple_strtoul(argv[1], NULL, 0);
+       key = (void *)simple_strtoul(argv[2], NULL, 0);
+       key_len = simple_strtoul(argv[3], NULL, 0);
+       if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
+               return CMD_RET_FAILURE;
+       parse_byte_string(argv[4], usage_auth, NULL);
+
+       err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
+                       &key_handle);
+       if (!err)
+               printf("Key handle is 0x%x\n", key_handle);
+
+       return report_return_code(err);
+}
+
+static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
+               int argc, char * const argv[])
+{
+       uint32_t key_handle, err;
+       uint8_t usage_auth[DIGEST_LENGTH];
+       uint8_t pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
+       size_t pub_key_len = sizeof(pub_key_buffer);
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       key_handle = simple_strtoul(argv[1], NULL, 0);
+       if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
+               return CMD_RET_FAILURE;
+       parse_byte_string(argv[2], usage_auth, NULL);
+
+       err = tpm_get_pub_key_oiap(key_handle, usage_auth,
+                       pub_key_buffer, &pub_key_len);
+       if (!err) {
+               printf("dump of received pub key structure:\n");
+               print_byte_string(pub_key_buffer, pub_key_len);
+       }
+       return report_return_code(err);
+}
+
+TPM_COMMAND_NO_ARG(tpm_end_oiap)
+
+#endif /* CONFIG_TPM_AUTH_SESSIONS */
+
+#define MAKE_TPM_CMD_ENTRY(cmd) \
+       U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
+
+static cmd_tbl_t tpm_commands[] = {
+       U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
+       U_BOOT_CMD_MKENT(init, 0, 1,
+                       do_tpm_init, "", ""),
+       U_BOOT_CMD_MKENT(startup, 0, 1,
+                       do_tpm_startup, "", ""),
+       U_BOOT_CMD_MKENT(self_test_full, 0, 1,
+                       do_tpm_self_test_full, "", ""),
+       U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
+                       do_tpm_continue_self_test, "", ""),
+       U_BOOT_CMD_MKENT(force_clear, 0, 1,
+                       do_tpm_force_clear, "", ""),
+       U_BOOT_CMD_MKENT(physical_enable, 0, 1,
+                       do_tpm_physical_enable, "", ""),
+       U_BOOT_CMD_MKENT(physical_disable, 0, 1,
+                       do_tpm_physical_disable, "", ""),
+       U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
+                       do_tpm_nv_define_space, "", ""),
+       U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
+                       do_tpm_nv_read_value, "", ""),
+       U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
+                       do_tpm_nv_write_value, "", ""),
+       U_BOOT_CMD_MKENT(extend, 0, 1,
+                       do_tpm_extend, "", ""),
+       U_BOOT_CMD_MKENT(pcr_read, 0, 1,
+                       do_tpm_pcr_read, "", ""),
+       U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
+                       do_tpm_tsc_physical_presence, "", ""),
+       U_BOOT_CMD_MKENT(read_pubek, 0, 1,
+                       do_tpm_read_pubek, "", ""),
+       U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
+                       do_tpm_physical_set_deactivated, "", ""),
+       U_BOOT_CMD_MKENT(get_capability, 0, 1,
+                       do_tpm_get_capability, "", ""),
+       U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
+                       do_tpm_raw_transfer, "", ""),
+       U_BOOT_CMD_MKENT(nv_define, 0, 1,
+                       do_tpm_nv_define, "", ""),
+       U_BOOT_CMD_MKENT(nv_read, 0, 1,
+                       do_tpm_nv_read, "", ""),
+       U_BOOT_CMD_MKENT(nv_write, 0, 1,
+                       do_tpm_nv_write, "", ""),
+#ifdef CONFIG_TPM_AUTH_SESSIONS
+       U_BOOT_CMD_MKENT(oiap, 0, 1,
+                        do_tpm_oiap, "", ""),
+       U_BOOT_CMD_MKENT(end_oiap, 0, 1,
+                        do_tpm_end_oiap, "", ""),
+       U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
+                        do_tpm_load_key2_oiap, "", ""),
+       U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
+                        do_tpm_get_pub_key_oiap, "", ""),
+#endif /* CONFIG_TPM_AUTH_SESSIONS */
+};
+
+static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *tpm_cmd;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+       tpm_cmd = find_cmd_tbl(argv[1], tpm_commands, ARRAY_SIZE(tpm_commands));
+       if (!tpm_cmd)
+               return CMD_RET_USAGE;
+
+       return tpm_cmd->cmd(cmdtp, flag, argc - 1, argv + 1);
+}
+
+U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
+"Issue a TPM command",
+"cmd args...\n"
+"    - Issue TPM command <cmd> with arguments <args...>.\n"
+"Admin Startup and State Commands:\n"
+"  info - Show information about the TPM\n"
+"  init\n"
+"    - Put TPM into a state where it waits for 'startup' command.\n"
+"  startup mode\n"
+"    - Issue TPM_Starup command.  <mode> is one of TPM_ST_CLEAR,\n"
+"      TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
+"Admin Testing Commands:\n"
+"  self_test_full\n"
+"    - Test all of the TPM capabilities.\n"
+"  continue_self_test\n"
+"    - Inform TPM that it should complete the self-test.\n"
+"Admin Opt-in Commands:\n"
+"  physical_enable\n"
+"    - Set the PERMANENT disable flag to FALSE using physical presence as\n"
+"      authorization.\n"
+"  physical_disable\n"
+"    - Set the PERMANENT disable flag to TRUE using physical presence as\n"
+"      authorization.\n"
+"  physical_set_deactivated 0|1\n"
+"    - Set deactivated flag.\n"
+"Admin Ownership Commands:\n"
+"  force_clear\n"
+"    - Issue TPM_ForceClear command.\n"
+"  tsc_physical_presence flags\n"
+"    - Set TPM device's Physical Presence flags to <flags>.\n"
+"The Capability Commands:\n"
+"  get_capability cap_area sub_cap addr count\n"
+"    - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
+"      <sub_cap> to memory address <addr>.\n"
+#ifdef CONFIG_TPM_AUTH_SESSIONS
+"Storage functions\n"
+"  loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
+"    - loads a key data from memory address <key_addr>, <key_len> bytes\n"
+"      into TPM using the parent key <parent_handle> with authorization\n"
+"      <usage_auth> (20 bytes hex string).\n"
+"  get_pub_key_oiap key_handle usage_auth\n"
+"    - get the public key portion of a loaded key <key_handle> using\n"
+"      authorization <usage auth> (20 bytes hex string)\n"
+#endif /* CONFIG_TPM_AUTH_SESSIONS */
+"Endorsement Key Handling Commands:\n"
+"  read_pubek addr count\n"
+"    - Read <count> bytes of the public endorsement key to memory\n"
+"      address <addr>\n"
+"Integrity Collection and Reporting Commands:\n"
+"  extend index digest_hex_string\n"
+"    - Add a new measurement to a PCR.  Update PCR <index> with the 20-bytes\n"
+"      <digest_hex_string>\n"
+"  pcr_read index addr count\n"
+"    - Read <count> bytes from PCR <index> to memory address <addr>.\n"
+#ifdef CONFIG_TPM_AUTH_SESSIONS
+"Authorization Sessions\n"
+"  oiap\n"
+"    - setup an OIAP session\n"
+"  end_oiap\n"
+"    - terminates an active OIAP session\n"
+#endif /* CONFIG_TPM_AUTH_SESSIONS */
+"Non-volatile Storage Commands:\n"
+"  nv_define_space index permission size\n"
+"    - Establish a space at index <index> with <permission> of <size> bytes.\n"
+"  nv_read_value index addr count\n"
+"    - Read <count> bytes from space <index> to memory address <addr>.\n"
+"  nv_write_value index addr count\n"
+"    - Write <count> bytes from memory address <addr> to space <index>.\n"
+"Miscellaneous helper functions:\n"
+"  raw_transfer byte_string\n"
+"    - Send a byte string <byte_string> to TPM and print the response.\n"
+" Non-volatile storage helper functions:\n"
+"    These helper functions treat a non-volatile space as a non-padded\n"
+"    sequence of integer values.  These integer values are defined by a type\n"
+"    string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
+"    value, 'w' 16-bit value, 'd' 32-bit value.  All helper functions take\n"
+"    a type string as their first argument.\n"
+"  nv_define type_string index perm\n"
+"    - Define a space <index> with permission <perm>.\n"
+"  nv_read types_string index vars...\n"
+"    - Read from space <index> to environment variables <vars...>.\n"
+"  nv_write types_string index values...\n"
+"    - Write to space <index> from values <values...>.\n"
+);
diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
new file mode 100644 (file)
index 0000000..65332d1
--- /dev/null
@@ -0,0 +1,564 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <tpm.h>
+
+/* Prints error and returns on failure */
+#define TPM_CHECK(tpm_command) do { \
+       uint32_t result; \
+       \
+       result = (tpm_command); \
+       if (result != TPM_SUCCESS) { \
+               printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \
+                       __LINE__, result); \
+               return result; \
+       } \
+} while (0)
+
+#define INDEX0                 0xda70
+#define INDEX1                 0xda71
+#define INDEX2                 0xda72
+#define INDEX3                 0xda73
+#define INDEX_INITIALISED      0xda80
+#define PHYS_PRESENCE          4
+#define PRESENCE               8
+
+static uint32_t TlclStartupIfNeeded(void)
+{
+       uint32_t result = tpm_startup(TPM_ST_CLEAR);
+
+       return result == TPM_INVALID_POSTINIT ? TPM_SUCCESS : result;
+}
+
+static int test_timer(void)
+{
+       printf("get_timer(0) = %lu\n", get_timer(0));
+       return 0;
+}
+
+static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated,
+                             uint8_t *nvlocked)
+{
+       struct tpm_permanent_flags pflags;
+       uint32_t result;
+
+       result = tpm_get_permanent_flags(&pflags);
+       if (result)
+               return result;
+       if (disable)
+               *disable = pflags.disable;
+       if (deactivated)
+               *deactivated = pflags.deactivated;
+       if (nvlocked)
+               *nvlocked = pflags.nv_locked;
+       debug("TPM: Got flags disable=%d, deactivated=%d, nvlocked=%d\n",
+             pflags.disable, pflags.deactivated, pflags.nv_locked);
+
+       return 0;
+}
+
+static uint32_t tpm_set_global_lock(void)
+{
+       uint32_t x;
+
+       debug("TPM: Set global lock\n");
+       return tpm_nv_write_value(INDEX0, (uint8_t *)&x, 0);
+}
+
+static uint32_t tpm_nv_write_value_lock(uint32_t index)
+{
+       debug("TPM: Write lock 0x%x\n", index);
+
+       return tpm_nv_write_value(index, NULL, 0);
+}
+
+static uint32_t tpm_nv_set_locked(void)
+{
+       debug("TPM: Set NV locked\n");
+
+       return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0);
+}
+
+static int tpm_is_owned(void)
+{
+       uint8_t response[TPM_PUBEK_SIZE];
+       uint32_t result;
+
+       result = tpm_read_pubek(response, sizeof(response));
+
+       return result != TPM_SUCCESS;
+}
+
+static int test_early_extend(void)
+{
+       uint8_t value_in[20];
+       uint8_t value_out[20];
+
+       printf("Testing earlyextend ...");
+       tpm_init();
+       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
+       TPM_CHECK(tpm_continue_self_test());
+       TPM_CHECK(tpm_extend(1, value_in, value_out));
+       printf("done\n");
+       return 0;
+}
+
+static int test_early_nvram(void)
+{
+       uint32_t x;
+
+       printf("Testing earlynvram ...");
+       tpm_init();
+       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
+       TPM_CHECK(tpm_continue_self_test());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+       printf("done\n");
+       return 0;
+}
+
+static int test_early_nvram2(void)
+{
+       uint32_t x;
+
+       printf("Testing earlynvram2 ...");
+       tpm_init();
+       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
+       TPM_CHECK(tpm_continue_self_test());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+       printf("done\n");
+       return 0;
+}
+
+static int test_enable(void)
+{
+       uint8_t disable = 0, deactivated = 0;
+
+       printf("Testing enable ...\n");
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_self_test_full());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
+       TPM_CHECK(tpm_physical_enable());
+       TPM_CHECK(tpm_physical_set_deactivated(0));
+       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
+       if (disable == 1 || deactivated == 1)
+               printf("\tfailed to enable or activate\n");
+       printf("\tdone\n");
+       return 0;
+}
+
+#define reboot() do { \
+       printf("\trebooting...\n"); \
+       reset_cpu(0); \
+} while (0)
+
+static int test_fast_enable(void)
+{
+       uint8_t disable = 0, deactivated = 0;
+       int i;
+
+       printf("Testing fastenable ...\n");
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_self_test_full());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
+       for (i = 0; i < 2; i++) {
+               TPM_CHECK(tpm_force_clear());
+               TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+               printf("\tdisable is %d, deactivated is %d\n", disable,
+                      deactivated);
+               assert(disable == 1 && deactivated == 1);
+               TPM_CHECK(tpm_physical_enable());
+               TPM_CHECK(tpm_physical_set_deactivated(0));
+               TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+               printf("\tdisable is %d, deactivated is %d\n", disable,
+                      deactivated);
+               assert(disable == 0 && deactivated == 0);
+       }
+       printf("\tdone\n");
+       return 0;
+}
+
+static int test_global_lock(void)
+{
+       uint32_t zero = 0;
+       uint32_t result;
+       uint32_t x;
+
+       printf("Testing globallock ...\n");
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_self_test_full());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&zero,
+                                    sizeof(uint32_t)));
+       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+       TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&zero,
+                                    sizeof(uint32_t)));
+       TPM_CHECK(tpm_set_global_lock());
+       /* Verifies that write to index0 fails */
+       x = 1;
+       result = tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x));
+       assert(result == TPM_AREA_LOCKED);
+       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+       assert(x == 0);
+       /* Verifies that write to index1 is still possible */
+       x = 2;
+       TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+       assert(x == 2);
+       /* Turns off PP */
+       tpm_tsc_physical_presence(PHYS_PRESENCE);
+       /* Verifies that write to index1 fails */
+       x = 3;
+       result = tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x));
+       assert(result == TPM_BAD_PRESENCE);
+       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+       assert(x == 2);
+       printf("\tdone\n");
+       return 0;
+}
+
+static int test_lock(void)
+{
+       printf("Testing lock ...\n");
+       tpm_init();
+       tpm_startup(TPM_ST_CLEAR);
+       tpm_self_test_full();
+       tpm_tsc_physical_presence(PRESENCE);
+       tpm_nv_write_value_lock(INDEX0);
+       printf("\tLocked 0x%x\n", INDEX0);
+       printf("\tdone\n");
+       return 0;
+}
+
+static void initialise_spaces(void)
+{
+       uint32_t zero = 0;
+       uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE;
+
+       printf("\tInitialising spaces\n");
+       tpm_nv_set_locked();  /* useful only the first time */
+       tpm_nv_define_space(INDEX0, perm, 4);
+       tpm_nv_write_value(INDEX0, (uint8_t *)&zero, 4);
+       tpm_nv_define_space(INDEX1, perm, 4);
+       tpm_nv_write_value(INDEX1, (uint8_t *)&zero, 4);
+       tpm_nv_define_space(INDEX2, perm, 4);
+       tpm_nv_write_value(INDEX2, (uint8_t *)&zero, 4);
+       tpm_nv_define_space(INDEX3, perm, 4);
+       tpm_nv_write_value(INDEX3, (uint8_t *)&zero, 4);
+       perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
+               TPM_NV_PER_PPWRITE;
+       tpm_nv_define_space(INDEX_INITIALISED, perm, 1);
+}
+
+static int test_readonly(void)
+{
+       uint8_t c;
+       uint32_t index_0, index_1, index_2, index_3;
+       int read0, read1, read2, read3;
+
+       printf("Testing readonly ...\n");
+       tpm_init();
+       tpm_startup(TPM_ST_CLEAR);
+       tpm_self_test_full();
+       tpm_tsc_physical_presence(PRESENCE);
+       /*
+        * Checks if initialisation has completed by trying to read-lock a
+        * space that's created at the end of initialisation
+        */
+       if (tpm_nv_read_value(INDEX_INITIALISED, &c, 0) == TPM_BADINDEX) {
+               /* The initialisation did not complete */
+               initialise_spaces();
+       }
+
+       /* Checks if spaces are OK or messed up */
+       read0 = tpm_nv_read_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0));
+       read1 = tpm_nv_read_value(INDEX1, (uint8_t *)&index_1, sizeof(index_1));
+       read2 = tpm_nv_read_value(INDEX2, (uint8_t *)&index_2, sizeof(index_2));
+       read3 = tpm_nv_read_value(INDEX3, (uint8_t *)&index_3, sizeof(index_3));
+       if (read0 || read1 || read2 || read3) {
+               printf("Invalid contents\n");
+               return 0;
+       }
+
+       /*
+        * Writes space, and locks it.  Then attempts to write again.
+        * I really wish I could use the imperative.
+        */
+       index_0 += 1;
+       if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0) !=
+               TPM_SUCCESS)) {
+               error("\tcould not write index 0\n");
+       }
+       tpm_nv_write_value_lock(INDEX0);
+       if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0)) ==
+                       TPM_SUCCESS)
+               error("\tindex 0 is not locked\n");
+
+       printf("\tdone\n");
+       return 0;
+}
+
+static int test_redefine_unowned(void)
+{
+       uint32_t perm;
+       uint32_t result;
+       uint32_t x;
+
+       printf("Testing redefine_unowned ...");
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_self_test_full());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       assert(!tpm_is_owned());
+
+       /* Ensures spaces exist. */
+       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+
+       /* Redefines spaces a couple of times. */
+       perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
+       TPM_CHECK(tpm_nv_define_space(INDEX0, perm, 2 * sizeof(uint32_t)));
+       TPM_CHECK(tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t)));
+       perm = TPM_NV_PER_PPWRITE;
+       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
+       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
+
+       /* Sets the global lock */
+       tpm_set_global_lock();
+
+       /* Verifies that index0 cannot be redefined */
+       result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
+       assert(result == TPM_AREA_LOCKED);
+
+       /* Checks that index1 can */
+       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
+       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
+
+       /* Turns off PP */
+       tpm_tsc_physical_presence(PHYS_PRESENCE);
+
+       /* Verifies that neither index0 nor index1 can be redefined */
+       result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
+       assert(result == TPM_BAD_PRESENCE);
+       result = tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t));
+       assert(result == TPM_BAD_PRESENCE);
+
+       printf("done\n");
+       return 0;
+}
+
+#define PERMPPGL (TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK)
+#define PERMPP TPM_NV_PER_PPWRITE
+
+static int test_space_perm(void)
+{
+       uint32_t perm;
+
+       printf("Testing spaceperm ...");
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_continue_self_test());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_get_permissions(INDEX0, &perm));
+       assert((perm & PERMPPGL) == PERMPPGL);
+       TPM_CHECK(tpm_get_permissions(INDEX1, &perm));
+       assert((perm & PERMPP) == PERMPP);
+       printf("done\n");
+       return 0;
+}
+
+static int test_startup(void)
+{
+       uint32_t result;
+       printf("Testing startup ...\n");
+
+       tpm_init();
+       result = tpm_startup(TPM_ST_CLEAR);
+       if (result != 0 && result != TPM_INVALID_POSTINIT)
+               printf("\ttpm startup failed with 0x%x\n", result);
+       result = tpm_get_flags(NULL, NULL, NULL);
+       if (result != 0)
+               printf("\ttpm getflags failed with 0x%x\n", result);
+       printf("\texecuting SelfTestFull\n");
+       tpm_self_test_full();
+       result = tpm_get_flags(NULL, NULL, NULL);
+       if (result != 0)
+               printf("\ttpm getflags failed with 0x%x\n", result);
+       printf("\tdone\n");
+       return 0;
+}
+
+/*
+ * Runs [op] and ensures it returns success and doesn't run longer than
+ * [time_limit] in milliseconds.
+ */
+#define TTPM_CHECK(op, time_limit) do { \
+       ulong start, time; \
+       uint32_t __result; \
+       \
+       start = get_timer(0); \
+       __result = op; \
+       if (__result != TPM_SUCCESS) { \
+               printf("\t" #op ": error 0x%x\n", __result); \
+               return -1; \
+       } \
+       time = get_timer(start); \
+       printf("\t" #op ": %lu ms\n", time); \
+       if (time > (ulong)time_limit) { \
+               printf("\t" #op " exceeded " #time_limit " ms\n"); \
+       } \
+} while (0)
+
+
+static int test_timing(void)
+{
+       uint32_t x;
+       uint8_t in[20], out[20];
+
+       printf("Testing timing ...");
+       tpm_init();
+       TTPM_CHECK(TlclStartupIfNeeded(), 50);
+       TTPM_CHECK(tpm_continue_self_test(), 100);
+       TTPM_CHECK(tpm_self_test_full(), 1000);
+       TTPM_CHECK(tpm_tsc_physical_presence(PRESENCE), 100);
+       TTPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
+       TTPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
+       TTPM_CHECK(tpm_extend(0, in, out), 200);
+       TTPM_CHECK(tpm_set_global_lock(), 50);
+       TTPM_CHECK(tpm_tsc_physical_presence(PHYS_PRESENCE), 100);
+       printf("done\n");
+       return 0;
+}
+
+#define TPM_MAX_NV_WRITES_NOOWNER 64
+
+static int test_write_limit(void)
+{
+       printf("Testing writelimit ...\n");
+       int i;
+       uint32_t result;
+
+       tpm_init();
+       TPM_CHECK(TlclStartupIfNeeded());
+       TPM_CHECK(tpm_self_test_full());
+       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
+       TPM_CHECK(tpm_force_clear());
+       TPM_CHECK(tpm_physical_enable());
+       TPM_CHECK(tpm_physical_set_deactivated(0));
+
+       for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) {
+               printf("\twriting %d\n", i);
+               result = tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i));
+               switch (result) {
+               case TPM_SUCCESS:
+                       break;
+               case TPM_MAXNVWRITES:
+                       assert(i >= TPM_MAX_NV_WRITES_NOOWNER);
+               default:
+                       error("\tunexpected error code %d (0x%x)\n",
+                             result, result);
+               }
+       }
+
+       /* Reset write count */
+       TPM_CHECK(tpm_force_clear());
+       TPM_CHECK(tpm_physical_enable());
+       TPM_CHECK(tpm_physical_set_deactivated(0));
+
+       /* Try writing again. */
+       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i)));
+       printf("\tdone\n");
+       return 0;
+}
+
+#define VOIDTEST(XFUNC) \
+       int do_test_##XFUNC(cmd_tbl_t *cmd_tbl, int flag, int argc, \
+       char * const argv[]) \
+       { \
+               return test_##XFUNC(); \
+       }
+
+#define VOIDENT(XNAME) \
+       U_BOOT_CMD_MKENT(XNAME, 0, 1, do_test_##XNAME, "", ""),
+
+VOIDTEST(early_extend)
+VOIDTEST(early_nvram)
+VOIDTEST(early_nvram2)
+VOIDTEST(enable)
+VOIDTEST(fast_enable)
+VOIDTEST(global_lock)
+VOIDTEST(lock)
+VOIDTEST(readonly)
+VOIDTEST(redefine_unowned)
+VOIDTEST(space_perm)
+VOIDTEST(startup)
+VOIDTEST(timing)
+VOIDTEST(write_limit)
+VOIDTEST(timer)
+
+static cmd_tbl_t cmd_cros_tpm_sub[] = {
+       VOIDENT(early_extend)
+       VOIDENT(early_nvram)
+       VOIDENT(early_nvram2)
+       VOIDENT(enable)
+       VOIDENT(fast_enable)
+       VOIDENT(global_lock)
+       VOIDENT(lock)
+       VOIDENT(readonly)
+       VOIDENT(redefine_unowned)
+       VOIDENT(space_perm)
+       VOIDENT(startup)
+       VOIDENT(timing)
+       VOIDENT(write_limit)
+       VOIDENT(timer)
+};
+
+static int do_tpmtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       cmd_tbl_t *c;
+
+       printf("argc = %d, argv = ", argc);
+       do {
+               int i = 0;
+
+               for (i = 0; i < argc; i++)
+                       printf(" %s", argv[i]);
+                       printf("\n------\n");
+               } while (0);
+       argc--;
+       argv++;
+       c = find_cmd_tbl(argv[0], cmd_cros_tpm_sub,
+                        ARRAY_SIZE(cmd_cros_tpm_sub));
+       return c ? c->cmd(cmdtp, flag, argc, argv) : cmd_usage(cmdtp);
+}
+
+U_BOOT_CMD(tpmtest, 2, 1, do_tpmtest, "TPM tests",
+       "\n\tearly_extend\n"
+       "\tearly_nvram\n"
+       "\tearly_nvram2\n"
+       "\tenable\n"
+       "\tfast_enable\n"
+       "\tglobal_lock\n"
+       "\tlock\n"
+       "\treadonly\n"
+       "\tredefine_unowned\n"
+       "\tspace_perm\n"
+       "\tstartup\n"
+       "\ttiming\n"
+       "\twrite_limit\n");
diff --git a/cmd/trace.c b/cmd/trace.c
new file mode 100644 (file)
index 0000000..1e62a1a
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <mapmem.h>
+#include <trace.h>
+#include <asm/io.h>
+
+static int get_args(int argc, char * const argv[], char **buff,
+                   size_t *buff_ptr, size_t *buff_size)
+{
+       if (argc < 2)
+               return -1;
+       if (argc < 4) {
+               *buff_size = getenv_ulong("profsize", 16, 0);
+               *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
+                                  *buff_size);
+               *buff_ptr = getenv_ulong("profoffset", 16, 0);
+       } else {
+               *buff_size = simple_strtoul(argv[3], NULL, 16);
+               *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
+                                  *buff_size);
+               *buff_ptr = 0;
+       };
+       return 0;
+}
+
+static int create_func_list(int argc, char * const argv[])
+{
+       size_t buff_size, avail, buff_ptr, used;
+       unsigned int needed;
+       char *buff;
+       int err;
+
+       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
+               return -1;
+
+       avail = buff_size - buff_ptr;
+       err = trace_list_functions(buff + buff_ptr, avail, &needed);
+       if (err)
+               printf("Error: truncated (%#x bytes needed)\n", needed);
+       used = min(avail, needed);
+       printf("Function trace dumped to %08lx, size %#zx\n",
+              (ulong)map_to_sysmem(buff + buff_ptr), used);
+       setenv_hex("profbase", map_to_sysmem(buff));
+       setenv_hex("profsize", buff_size);
+       setenv_hex("profoffset", buff_ptr + used);
+
+       return 0;
+}
+
+static int create_call_list(int argc, char * const argv[])
+{
+       size_t buff_size, avail, buff_ptr, used;
+       unsigned int needed;
+       char *buff;
+       int err;
+
+       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
+               return -1;
+
+       avail = buff_size - buff_ptr;
+       err = trace_list_calls(buff + buff_ptr, avail, &needed);
+       if (err)
+               printf("Error: truncated (%#x bytes needed)\n", needed);
+       used = min(avail, needed);
+       printf("Call list dumped to %08lx, size %#zx\n",
+              (ulong)map_to_sysmem(buff + buff_ptr), used);
+
+       setenv_hex("profbase", map_to_sysmem(buff));
+       setenv_hex("profsize", buff_size);
+       setenv_hex("profoffset", buff_ptr + used);
+
+       return 0;
+}
+
+int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *cmd = argc < 2 ? NULL : argv[1];
+
+       if (!cmd)
+               return cmd_usage(cmdtp);
+       switch (*cmd) {
+       case 'p':
+               trace_set_enabled(0);
+               break;
+       case 'c':
+               if (create_call_list(argc, argv))
+                       return cmd_usage(cmdtp);
+               break;
+       case 'r':
+               trace_set_enabled(1);
+               break;
+       case 'f':
+               if (create_func_list(argc, argv))
+                       return cmd_usage(cmdtp);
+               break;
+       case 's':
+               trace_print_stats();
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       trace,  4,      1,      do_trace,
+       "trace utility commands",
+       "stats                        - display tracing statistics\n"
+       "trace pause                        - pause tracing\n"
+       "trace resume                       - resume tracing\n"
+       "trace funclist [<addr> <size>]     - dump function list into buffer\n"
+       "trace calls  [<addr> <size>]       "
+               "- dump function call trace into buffer"
+);
diff --git a/cmd/tsi148.c b/cmd/tsi148.c
new file mode 100644 (file)
index 0000000..ea96d0f
--- /dev/null
@@ -0,0 +1,472 @@
+/*
+ * (C) Copyright 2009 Reinhard Arlt, reinhard.arlt@esd-electronics.com
+ *
+ * base on universe.h by
+ *
+ * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <pci.h>
+
+#include <tsi148.h>
+
+#define LPCI_VENDOR PCI_VENDOR_ID_TUNDRA
+#define LPCI_DEVICE PCI_DEVICE_ID_TUNDRA_TSI148
+
+typedef struct _TSI148_DEV TSI148_DEV;
+
+struct _TSI148_DEV {
+       int           bus;
+       pci_dev_t     busdevfn;
+       TSI148       *uregs;
+       unsigned int  pci_bs;
+};
+
+static TSI148_DEV *dev;
+
+/*
+ * Most of the TSI148 register are BIGENDIAN
+ * This is the reason for the __raw_writel(htonl(x), x) usage!
+ */
+
+int tsi148_init(void)
+{
+       int j, result;
+       pci_dev_t busdevfn;
+       unsigned int val;
+
+       busdevfn = pci_find_device(LPCI_VENDOR, LPCI_DEVICE, 0);
+       if (busdevfn == -1) {
+               puts("Tsi148: No Tundra Tsi148 found!\n");
+               return -1;
+       }
+
+       /* Lets turn Latency off */
+       pci_write_config_dword(busdevfn, 0x0c, 0);
+
+       dev = malloc(sizeof(*dev));
+       if (NULL == dev) {
+               puts("Tsi148: No memory!\n");
+               return -1;
+       }
+
+       memset(dev, 0, sizeof(*dev));
+       dev->busdevfn = busdevfn;
+
+       pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
+       val &= ~0xf;
+       dev->uregs = (TSI148 *)val;
+
+       debug("Tsi148: Base    : %p\n", dev->uregs);
+
+       /* check mapping */
+       debug("Tsi148: Read via mapping, PCI_ID = %08X\n",
+             readl(&dev->uregs->pci_id));
+       if (((LPCI_DEVICE << 16) | LPCI_VENDOR) != readl(&dev->uregs->pci_id)) {
+               printf("Tsi148: Cannot read PCI-ID via Mapping: %08x\n",
+                      readl(&dev->uregs->pci_id));
+               result = -1;
+               goto break_30;
+       }
+
+       debug("Tsi148: PCI_BS = %08X\n", readl(&dev->uregs->pci_mbarl));
+
+       dev->pci_bs = readl(&dev->uregs->pci_mbarl);
+
+       /* turn off windows */
+       for (j = 0; j < 8; j++) {
+               __raw_writel(htonl(0x00000000), &dev->uregs->outbound[j].otat);
+               __raw_writel(htonl(0x00000000), &dev->uregs->inbound[j].itat);
+       }
+
+       /* Tsi148 VME timeout etc */
+       __raw_writel(htonl(0x00000084), &dev->uregs->vctrl);
+
+#ifdef DEBUG
+       if ((__raw_readl(&dev->uregs->vstat) & 0x00000100) != 0)
+               printf("Tsi148: System Controller!\n");
+       else
+               printf("Tsi148: Not System Controller!\n");
+#endif
+
+       /*
+        * Lets turn off interrupts
+        */
+       /* Disable interrupts in Tsi148 first */
+       __raw_writel(htonl(0x00000000), &dev->uregs->inten);
+       /* Disable interrupt out */
+       __raw_writel(htonl(0x00000000), &dev->uregs->inteo);
+       eieio();
+       /* Reset all IRQ's */
+       __raw_writel(htonl(0x03ff3f00), &dev->uregs->intc);
+       /* Map all ints to 0 */
+       __raw_writel(htonl(0x00000000), &dev->uregs->intm1);
+       __raw_writel(htonl(0x00000000), &dev->uregs->intm2);
+       eieio();
+
+       val = __raw_readl(&dev->uregs->vstat);
+       val &= ~(0x00004000);
+       __raw_writel(val, &dev->uregs->vstat);
+       eieio();
+
+       debug("Tsi148: register struct size %08x\n", sizeof(TSI148));
+
+       return 0;
+
+ break_30:
+       free(dev);
+       dev = NULL;
+
+       return result;
+}
+
+/*
+ * Create pci slave window (access: pci -> vme)
+ */
+int tsi148_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr,
+                           int size, int vam, int vdw)
+{
+       int result, i;
+       unsigned int ctl = 0;
+
+       if (NULL == dev) {
+               result = -1;
+               goto exit_10;
+       }
+
+       for (i = 0; i < 8; i++) {
+               if (0x00000000 == readl(&dev->uregs->outbound[i].otat))
+                       break;
+       }
+
+       if (i > 7) {
+               printf("Tsi148: No Image available\n");
+               result = -1;
+               goto exit_10;
+       }
+
+       debug("Tsi148: Using image %d\n", i);
+
+       printf("Tsi148: Pci addr %08x\n", pciAddr);
+
+       __raw_writel(htonl(pciAddr), &dev->uregs->outbound[i].otsal);
+       __raw_writel(0x00000000, &dev->uregs->outbound[i].otsau);
+       __raw_writel(htonl(pciAddr + size), &dev->uregs->outbound[i].oteal);
+       __raw_writel(0x00000000, &dev->uregs->outbound[i].oteau);
+       __raw_writel(htonl(vmeAddr - pciAddr), &dev->uregs->outbound[i].otofl);
+       __raw_writel(0x00000000, &dev->uregs->outbound[i].otofu);
+
+       switch (vam & VME_AM_Axx) {
+       case VME_AM_A16:
+               ctl = 0x00000000;
+               break;
+       case VME_AM_A24:
+               ctl = 0x00000001;
+               break;
+       case VME_AM_A32:
+               ctl = 0x00000002;
+               break;
+       }
+
+       switch (vam & VME_AM_Mxx) {
+       case VME_AM_DATA:
+               ctl |= 0x00000000;
+               break;
+       case VME_AM_PROG:
+               ctl |= 0x00000010;
+               break;
+       }
+
+       if (vam & VME_AM_SUP)
+               ctl |= 0x00000020;
+
+       switch (vdw & VME_FLAG_Dxx) {
+       case VME_FLAG_D16:
+               ctl |= 0x00000000;
+               break;
+       case VME_FLAG_D32:
+               ctl |= 0x00000040;
+               break;
+       }
+
+       ctl |= 0x80040000;      /* enable, no prefetch */
+
+       __raw_writel(htonl(ctl), &dev->uregs->outbound[i].otat);
+
+       debug("Tsi148: window-addr                =%p\n",
+             &dev->uregs->outbound[i].otsau);
+       debug("Tsi148: pci slave window[%d] attr  =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otat)));
+       debug("Tsi148: pci slave window[%d] start =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otsal)));
+       debug("Tsi148: pci slave window[%d] end   =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->outbound[i].oteal)));
+       debug("Tsi148: pci slave window[%d] offset=%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otofl)));
+
+       return 0;
+
+ exit_10:
+       return -result;
+}
+
+unsigned int tsi148_eval_vam(int vam)
+{
+       unsigned int ctl = 0;
+
+       switch (vam & VME_AM_Axx) {
+       case VME_AM_A16:
+               ctl = 0x00000000;
+               break;
+       case VME_AM_A24:
+               ctl = 0x00000010;
+               break;
+       case VME_AM_A32:
+               ctl = 0x00000020;
+               break;
+       }
+       switch (vam & VME_AM_Mxx) {
+       case VME_AM_DATA:
+               ctl |= 0x00000001;
+               break;
+       case VME_AM_PROG:
+               ctl |= 0x00000002;
+               break;
+       case (VME_AM_PROG | VME_AM_DATA):
+               ctl |= 0x00000003;
+               break;
+       }
+
+       if (vam & VME_AM_SUP)
+               ctl |= 0x00000008;
+       if (vam & VME_AM_USR)
+               ctl |= 0x00000004;
+
+       return ctl;
+}
+
+/*
+ * Create vme slave window (access: vme -> pci)
+ */
+int tsi148_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr,
+                           int size, int vam)
+{
+       int result, i;
+       unsigned int ctl = 0;
+
+       if (NULL == dev) {
+               result = -1;
+               goto exit_10;
+       }
+
+       for (i = 0; i < 8; i++) {
+               if (0x00000000 == readl(&dev->uregs->inbound[i].itat))
+                       break;
+       }
+
+       if (i > 7) {
+               printf("Tsi148: No Image available\n");
+               result = -1;
+               goto exit_10;
+       }
+
+       debug("Tsi148: Using image %d\n", i);
+
+       __raw_writel(htonl(vmeAddr), &dev->uregs->inbound[i].itsal);
+       __raw_writel(0x00000000, &dev->uregs->inbound[i].itsau);
+       __raw_writel(htonl(vmeAddr + size), &dev->uregs->inbound[i].iteal);
+       __raw_writel(0x00000000, &dev->uregs->inbound[i].iteau);
+       __raw_writel(htonl(pciAddr - vmeAddr), &dev->uregs->inbound[i].itofl);
+       if (vmeAddr > pciAddr)
+               __raw_writel(0xffffffff, &dev->uregs->inbound[i].itofu);
+       else
+               __raw_writel(0x00000000, &dev->uregs->inbound[i].itofu);
+
+       ctl = tsi148_eval_vam(vam);
+       ctl |= 0x80000000;      /* enable */
+       __raw_writel(htonl(ctl), &dev->uregs->inbound[i].itat);
+
+       debug("Tsi148: window-addr                =%p\n",
+             &dev->uregs->inbound[i].itsau);
+       debug("Tsi148: vme slave window[%d] attr  =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itat)));
+       debug("Tsi148: vme slave window[%d] start =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itsal)));
+       debug("Tsi148: vme slave window[%d] end   =%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->inbound[i].iteal)));
+       debug("Tsi148: vme slave window[%d] offset=%08x\n",
+             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itofl)));
+
+       return 0;
+
+ exit_10:
+       return -result;
+}
+
+/*
+ * Create vme slave window (access: vme -> gcsr)
+ */
+int tsi148_vme_gcsr_window(unsigned int vmeAddr, int vam)
+{
+       int result;
+       unsigned int ctl;
+
+       result = 0;
+
+       if (NULL == dev) {
+               result = 1;
+       } else {
+               __raw_writel(htonl(vmeAddr), &dev->uregs->gbal);
+               __raw_writel(0x00000000, &dev->uregs->gbau);
+
+               ctl = tsi148_eval_vam(vam);
+               ctl |= 0x00000080;      /* enable */
+               __raw_writel(htonl(ctl), &dev->uregs->gcsrat);
+       }
+
+       return result;
+}
+
+/*
+ * Create vme slave window (access: vme -> crcsr)
+ */
+int tsi148_vme_crcsr_window(unsigned int vmeAddr)
+{
+       int result;
+       unsigned int ctl;
+
+       result = 0;
+
+       if (NULL == dev) {
+               result = 1;
+       } else {
+               __raw_writel(htonl(vmeAddr), &dev->uregs->crol);
+               __raw_writel(0x00000000, &dev->uregs->crou);
+
+               ctl = 0x00000080;       /* enable */
+               __raw_writel(htonl(ctl), &dev->uregs->crat);
+       }
+
+       return result;
+}
+
+/*
+ * Create vme slave window (access: vme -> crg)
+ */
+int tsi148_vme_crg_window(unsigned int vmeAddr, int vam)
+{
+       int result;
+       unsigned int ctl;
+
+       result = 0;
+
+       if (NULL == dev) {
+               result = 1;
+       } else {
+               __raw_writel(htonl(vmeAddr), &dev->uregs->cbal);
+               __raw_writel(0x00000000, &dev->uregs->cbau);
+
+               ctl = tsi148_eval_vam(vam);
+               ctl |= 0x00000080;      /* enable */
+               __raw_writel(htonl(ctl), &dev->uregs->crgat);
+       }
+
+       return result;
+}
+
+/*
+ * Tundra Tsi148 configuration
+ */
+int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, vdw = 0;
+       char cmd = 'x';
+
+       /* get parameter */
+       if (argc > 1)
+               cmd = argv[1][0];
+       if (argc > 2)
+               addr1 = simple_strtoul(argv[2], NULL, 16);
+       if (argc > 3)
+               addr2 = simple_strtoul(argv[3], NULL, 16);
+       if (argc > 4)
+               size = simple_strtoul(argv[4], NULL, 16);
+       if (argc > 5)
+               vam = simple_strtoul(argv[5], NULL, 16);
+       if (argc > 6)
+               vdw = simple_strtoul(argv[6], NULL, 16);
+
+       switch (cmd) {
+       case 'c':
+               if (strcmp(argv[1], "crg") == 0) {
+                       vam = addr2;
+                       printf("Tsi148: Configuring VME CRG Window "
+                              "(VME->CRG):\n");
+                       printf("  vme=%08lx vam=%02lx\n", addr1, vam);
+                       tsi148_vme_crg_window(addr1, vam);
+               } else {
+                       printf("Tsi148: Configuring VME CR/CSR Window "
+                              "(VME->CR/CSR):\n");
+                       printf("  pci=%08lx\n", addr1);
+                       tsi148_vme_crcsr_window(addr1);
+               }
+               break;
+       case 'i':               /* init */
+               tsi148_init();
+               break;
+       case 'g':
+               vam = addr2;
+               printf("Tsi148: Configuring VME GCSR Window (VME->GCSR):\n");
+               printf("  vme=%08lx vam=%02lx\n", addr1, vam);
+               tsi148_vme_gcsr_window(addr1, vam);
+               break;
+       case 'v':               /* vme */
+               printf("Tsi148: Configuring VME Slave Window (VME->PCI):\n");
+               printf("  vme=%08lx pci=%08lx size=%08lx vam=%02lx\n",
+                      addr1, addr2, size, vam);
+               tsi148_vme_slave_window(addr1, addr2, size, vam);
+               break;
+       case 'p':               /* pci */
+               printf("Tsi148: Configuring PCI Slave Window (PCI->VME):\n");
+               printf("  pci=%08lx vme=%08lx size=%08lx vam=%02lx vdw=%02lx\n",
+                      addr1, addr2, size, vam, vdw);
+               tsi148_pci_slave_window(addr1, addr2, size, vam, vdw);
+               break;
+       default:
+               printf("Tsi148: Command %s not supported!\n", argv[1]);
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       tsi148, 7,      1,      do_tsi148,
+       "initialize and configure Turndra Tsi148\n",
+       "init\n"
+       "    - initialize tsi148\n"
+       "tsi148 vme   [vme_addr] [pci_addr] [size] [vam]\n"
+       "    - create vme slave window (access: vme->pci)\n"
+       "tsi148 pci   [pci_addr] [vme_addr] [size] [vam] [vdw]\n"
+       "    - create pci slave window (access: pci->vme)\n"
+       "tsi148 crg   [vme_addr] [vam]\n"
+       "    - create vme slave window: (access vme->CRG\n"
+       "tsi148 crcsr [pci_addr]\n"
+       "    - create vme slave window: (access vme->CR/CSR\n"
+       "tsi148 gcsr  [vme_addr] [vam]\n"
+       "    - create vme slave window: (access vme->GCSR\n"
+       "    [vam] = VMEbus Address-Modifier:  01 -> A16 Address Space\n"
+       "                                      02 -> A24 Address Space\n"
+       "                                      03 -> A32 Address Space\n"
+       "                                      04 -> Usr        AM Code\n"
+       "                                      08 -> Supervisor AM Code\n"
+       "                                      10 -> Data AM Code\n"
+       "                                      20 -> Program AM Code\n"
+       "    [vdw] = VMEbus Maximum Datawidth: 02 -> D16 Data Width\n"
+       "                                      03 -> D32 Data Width\n"
+);
diff --git a/cmd/ubi.c b/cmd/ubi.c
new file mode 100644 (file)
index 0000000..753a4db
--- /dev/null
+++ b/cmd/ubi.c
@@ -0,0 +1,685 @@
+/*
+ * Unsorted Block Image commands
+ *
+ *  Copyright (C) 2008 Samsung Electronics
+ *  Kyungmin Park <kyungmin.park@samsung.com>
+ *
+ * Copyright 2008-2009 Stefan Roese <sr@denx.de>, DENX Software Engineering
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <exports.h>
+#include <memalign.h>
+#include <nand.h>
+#include <onenand_uboot.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/err.h>
+#include <ubi_uboot.h>
+#include <asm/errno.h>
+#include <jffs2/load_kernel.h>
+
+#undef ubi_msg
+#define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
+
+#define DEV_TYPE_NONE          0
+#define DEV_TYPE_NAND          1
+#define DEV_TYPE_ONENAND       2
+#define DEV_TYPE_NOR           3
+
+/* Private own data */
+static struct ubi_device *ubi;
+static char buffer[80];
+static int ubi_initialized;
+
+struct selected_dev {
+       char part_name[80];
+       int selected;
+       int nr;
+       struct mtd_info *mtd_info;
+};
+
+static struct selected_dev ubi_dev;
+
+#ifdef CONFIG_CMD_UBIFS
+int ubifs_is_mounted(void);
+void cmd_ubifs_umount(void);
+#endif
+
+static void display_volume_info(struct ubi_device *ubi)
+{
+       int i;
+
+       for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+               if (!ubi->volumes[i])
+                       continue;       /* Empty record */
+               ubi_dump_vol_info(ubi->volumes[i]);
+       }
+}
+
+static void display_ubi_info(struct ubi_device *ubi)
+{
+       ubi_msg("MTD device name:            \"%s\"", ubi->mtd->name);
+       ubi_msg("MTD device size:            %llu MiB", ubi->flash_size >> 20);
+       ubi_msg("physical eraseblock size:   %d bytes (%d KiB)",
+                       ubi->peb_size, ubi->peb_size >> 10);
+       ubi_msg("logical eraseblock size:    %d bytes", ubi->leb_size);
+       ubi_msg("number of good PEBs:        %d", ubi->good_peb_count);
+       ubi_msg("number of bad PEBs:         %d", ubi->bad_peb_count);
+       ubi_msg("smallest flash I/O unit:    %d", ubi->min_io_size);
+       ubi_msg("VID header offset:          %d (aligned %d)",
+                       ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
+       ubi_msg("data offset:                %d", ubi->leb_start);
+       ubi_msg("max. allowed volumes:       %d", ubi->vtbl_slots);
+       ubi_msg("wear-leveling threshold:    %d", CONFIG_MTD_UBI_WL_THRESHOLD);
+       ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
+       ubi_msg("number of user volumes:     %d",
+                       ubi->vol_count - UBI_INT_VOL_COUNT);
+       ubi_msg("available PEBs:             %d", ubi->avail_pebs);
+       ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs);
+       ubi_msg("number of PEBs reserved for bad PEB handling: %d",
+                       ubi->beb_rsvd_pebs);
+       ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
+}
+
+static int ubi_info(int layout)
+{
+       if (layout)
+               display_volume_info(ubi);
+       else
+               display_ubi_info(ubi);
+
+       return 0;
+}
+
+static int ubi_check_volumename(const struct ubi_volume *vol, char *name)
+{
+       return strcmp(vol->name, name);
+}
+
+static int ubi_check(char *name)
+{
+       int i;
+
+       for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+               if (!ubi->volumes[i])
+                       continue;       /* Empty record */
+
+               if (!ubi_check_volumename(ubi->volumes[i], name))
+                       return 0;
+       }
+
+       return 1;
+}
+
+
+static int verify_mkvol_req(const struct ubi_device *ubi,
+                           const struct ubi_mkvol_req *req)
+{
+       int n, err = EINVAL;
+
+       if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 ||
+           req->name_len < 0)
+               goto bad;
+
+       if ((req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots) &&
+           req->vol_id != UBI_VOL_NUM_AUTO)
+               goto bad;
+
+       if (req->alignment == 0)
+               goto bad;
+
+       if (req->bytes == 0) {
+               printf("No space left in UBI device!\n");
+               err = ENOMEM;
+               goto bad;
+       }
+
+       if (req->vol_type != UBI_DYNAMIC_VOLUME &&
+           req->vol_type != UBI_STATIC_VOLUME)
+               goto bad;
+
+       if (req->alignment > ubi->leb_size)
+               goto bad;
+
+       n = req->alignment % ubi->min_io_size;
+       if (req->alignment != 1 && n)
+               goto bad;
+
+       if (req->name_len > UBI_VOL_NAME_MAX) {
+               printf("Name too long!\n");
+               err = ENAMETOOLONG;
+               goto bad;
+       }
+
+       return 0;
+bad:
+       return err;
+}
+
+static int ubi_create_vol(char *volume, int64_t size, int dynamic)
+{
+       struct ubi_mkvol_req req;
+       int err;
+
+       if (dynamic)
+               req.vol_type = UBI_DYNAMIC_VOLUME;
+       else
+               req.vol_type = UBI_STATIC_VOLUME;
+
+       req.vol_id = UBI_VOL_NUM_AUTO;
+       req.alignment = 1;
+       req.bytes = size;
+
+       strcpy(req.name, volume);
+       req.name_len = strlen(volume);
+       req.name[req.name_len] = '\0';
+       req.padding1 = 0;
+       /* It's duplicated at drivers/mtd/ubi/cdev.c */
+       err = verify_mkvol_req(ubi, &req);
+       if (err) {
+               printf("verify_mkvol_req failed %d\n", err);
+               return err;
+       }
+       printf("Creating %s volume %s of size %lld\n",
+               dynamic ? "dynamic" : "static", volume, size);
+       /* Call real ubi create volume */
+       return ubi_create_volume(ubi, &req);
+}
+
+static struct ubi_volume *ubi_find_volume(char *volume)
+{
+       struct ubi_volume *vol = NULL;
+       int i;
+
+       for (i = 0; i < ubi->vtbl_slots; i++) {
+               vol = ubi->volumes[i];
+               if (vol && !strcmp(vol->name, volume))
+                       return vol;
+       }
+
+       printf("Volume %s not found!\n", volume);
+       return NULL;
+}
+
+static int ubi_remove_vol(char *volume)
+{
+       int err, reserved_pebs, i;
+       struct ubi_volume *vol;
+
+       vol = ubi_find_volume(volume);
+       if (vol == NULL)
+               return ENODEV;
+
+       printf("Remove UBI volume %s (id %d)\n", vol->name, vol->vol_id);
+
+       if (ubi->ro_mode) {
+               printf("It's read-only mode\n");
+               err = EROFS;
+               goto out_err;
+       }
+
+       err = ubi_change_vtbl_record(ubi, vol->vol_id, NULL);
+       if (err) {
+               printf("Error changing Vol tabel record err=%x\n", err);
+               goto out_err;
+       }
+       reserved_pebs = vol->reserved_pebs;
+       for (i = 0; i < vol->reserved_pebs; i++) {
+               err = ubi_eba_unmap_leb(ubi, vol, i);
+               if (err)
+                       goto out_err;
+       }
+
+       kfree(vol->eba_tbl);
+       ubi->volumes[vol->vol_id]->eba_tbl = NULL;
+       ubi->volumes[vol->vol_id] = NULL;
+
+       ubi->rsvd_pebs -= reserved_pebs;
+       ubi->avail_pebs += reserved_pebs;
+       i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
+       if (i > 0) {
+               i = ubi->avail_pebs >= i ? i : ubi->avail_pebs;
+               ubi->avail_pebs -= i;
+               ubi->rsvd_pebs += i;
+               ubi->beb_rsvd_pebs += i;
+               if (i > 0)
+                       ubi_msg("reserve more %d PEBs", i);
+       }
+       ubi->vol_count -= 1;
+
+       return 0;
+out_err:
+       ubi_err(ubi, "cannot remove volume %s, error %d", volume, err);
+       if (err < 0)
+               err = -err;
+       return err;
+}
+
+static int ubi_volume_continue_write(char *volume, void *buf, size_t size)
+{
+       int err = 1;
+       struct ubi_volume *vol;
+
+       vol = ubi_find_volume(volume);
+       if (vol == NULL)
+               return ENODEV;
+
+       err = ubi_more_update_data(ubi, vol, buf, size);
+       if (err < 0) {
+               printf("Couldnt or partially wrote data\n");
+               return -err;
+       }
+
+       if (err) {
+               size = err;
+
+               err = ubi_check_volume(ubi, vol->vol_id);
+               if (err < 0)
+                       return -err;
+
+               if (err) {
+                       ubi_warn(ubi, "volume %d on UBI device %d is corrupt",
+                                vol->vol_id, ubi->ubi_num);
+                       vol->corrupted = 1;
+               }
+
+               vol->checked = 1;
+               ubi_gluebi_updated(vol);
+       }
+
+       return 0;
+}
+
+int ubi_volume_begin_write(char *volume, void *buf, size_t size,
+       size_t full_size)
+{
+       int err = 1;
+       int rsvd_bytes = 0;
+       struct ubi_volume *vol;
+
+       vol = ubi_find_volume(volume);
+       if (vol == NULL)
+               return ENODEV;
+
+       rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad);
+       if (size < 0 || size > rsvd_bytes) {
+               printf("size > volume size! Aborting!\n");
+               return EINVAL;
+       }
+
+       err = ubi_start_update(ubi, vol, full_size);
+       if (err < 0) {
+               printf("Cannot start volume update\n");
+               return -err;
+       }
+
+       return ubi_volume_continue_write(volume, buf, size);
+}
+
+int ubi_volume_write(char *volume, void *buf, size_t size)
+{
+       return ubi_volume_begin_write(volume, buf, size, size);
+}
+
+int ubi_volume_read(char *volume, char *buf, size_t size)
+{
+       int err, lnum, off, len, tbuf_size;
+       void *tbuf;
+       unsigned long long tmp;
+       struct ubi_volume *vol;
+       loff_t offp = 0;
+
+       vol = ubi_find_volume(volume);
+       if (vol == NULL)
+               return ENODEV;
+
+       if (vol->updating) {
+               printf("updating");
+               return EBUSY;
+       }
+       if (vol->upd_marker) {
+               printf("damaged volume, update marker is set");
+               return EBADF;
+       }
+       if (offp == vol->used_bytes)
+               return 0;
+
+       if (size == 0) {
+               printf("No size specified -> Using max size (%lld)\n", vol->used_bytes);
+               size = vol->used_bytes;
+       }
+
+       if (vol->corrupted)
+               printf("read from corrupted volume %d", vol->vol_id);
+       if (offp + size > vol->used_bytes)
+               size = vol->used_bytes - offp;
+
+       tbuf_size = vol->usable_leb_size;
+       if (size < tbuf_size)
+               tbuf_size = ALIGN(size, ubi->min_io_size);
+       tbuf = malloc_cache_aligned(tbuf_size);
+       if (!tbuf) {
+               printf("NO MEM\n");
+               return ENOMEM;
+       }
+       len = size > tbuf_size ? tbuf_size : size;
+
+       tmp = offp;
+       off = do_div(tmp, vol->usable_leb_size);
+       lnum = tmp;
+       do {
+               if (off + len >= vol->usable_leb_size)
+                       len = vol->usable_leb_size - off;
+
+               err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0);
+               if (err) {
+                       printf("read err %x\n", err);
+                       err = -err;
+                       break;
+               }
+               off += len;
+               if (off == vol->usable_leb_size) {
+                       lnum += 1;
+                       off -= vol->usable_leb_size;
+               }
+
+               size -= len;
+               offp += len;
+
+               memcpy(buf, tbuf, len);
+
+               buf += len;
+               len = size > tbuf_size ? tbuf_size : size;
+       } while (size);
+
+       free(tbuf);
+       return err;
+}
+
+static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
+               const char *vid_header_offset)
+{
+       struct mtd_device *dev;
+       struct part_info *part;
+       struct mtd_partition mtd_part;
+       char ubi_mtd_param_buffer[80];
+       u8 pnum;
+       int err;
+
+       if (find_dev_and_part(ubidev, &dev, &pnum, &part) != 0)
+               return 1;
+
+       sprintf(buffer, "mtd=%d", pnum);
+       memset(&mtd_part, 0, sizeof(mtd_part));
+       mtd_part.name = buffer;
+       mtd_part.size = part->size;
+       mtd_part.offset = part->offset;
+       add_mtd_partitions(info, &mtd_part, 1);
+
+       strcpy(ubi_mtd_param_buffer, buffer);
+       if (vid_header_offset)
+               sprintf(ubi_mtd_param_buffer, "mtd=%d,%s", pnum,
+                               vid_header_offset);
+       err = ubi_mtd_param_parse(ubi_mtd_param_buffer, NULL);
+       if (err) {
+               del_mtd_partitions(info);
+               return -err;
+       }
+
+       err = ubi_init();
+       if (err) {
+               del_mtd_partitions(info);
+               return -err;
+       }
+
+       ubi_initialized = 1;
+
+       return 0;
+}
+
+int ubi_part(char *part_name, const char *vid_header_offset)
+{
+       int err = 0;
+       char mtd_dev[16];
+       struct mtd_device *dev;
+       struct part_info *part;
+       u8 pnum;
+
+       if (mtdparts_init() != 0) {
+               printf("Error initializing mtdparts!\n");
+               return 1;
+       }
+
+#ifdef CONFIG_CMD_UBIFS
+       /*
+        * Automatically unmount UBIFS partition when user
+        * changes the UBI device. Otherwise the following
+        * UBIFS commands will crash.
+        */
+       if (ubifs_is_mounted())
+               cmd_ubifs_umount();
+#endif
+
+       /* todo: get dev number for NAND... */
+       ubi_dev.nr = 0;
+
+       /*
+        * Call ubi_exit() before re-initializing the UBI subsystem
+        */
+       if (ubi_initialized) {
+               ubi_exit();
+               del_mtd_partitions(ubi_dev.mtd_info);
+       }
+
+       /*
+        * Search the mtd device number where this partition
+        * is located
+        */
+       if (find_dev_and_part(part_name, &dev, &pnum, &part)) {
+               printf("Partition %s not found!\n", part_name);
+               return 1;
+       }
+       sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(dev->id->type), dev->id->num);
+       ubi_dev.mtd_info = get_mtd_device_nm(mtd_dev);
+       if (IS_ERR(ubi_dev.mtd_info)) {
+               printf("Partition %s not found on device %s!\n", part_name,
+                      mtd_dev);
+               return 1;
+       }
+
+       ubi_dev.selected = 1;
+
+       strcpy(ubi_dev.part_name, part_name);
+       err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name,
+                       vid_header_offset);
+       if (err) {
+               printf("UBI init error %d\n", err);
+               ubi_dev.selected = 0;
+               return err;
+       }
+
+       ubi = ubi_devices[0];
+
+       return 0;
+}
+
+static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int64_t size = 0;
+       ulong addr = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (strcmp(argv[1], "part") == 0) {
+               const char *vid_header_offset = NULL;
+
+               /* Print current partition */
+               if (argc == 2) {
+                       if (!ubi_dev.selected) {
+                               printf("Error, no UBI device/partition selected!\n");
+                               return 1;
+                       }
+
+                       printf("Device %d: %s, partition %s\n",
+                              ubi_dev.nr, ubi_dev.mtd_info->name, ubi_dev.part_name);
+                       return 0;
+               }
+
+               if (argc < 3)
+                       return CMD_RET_USAGE;
+
+               if (argc > 3)
+                       vid_header_offset = argv[3];
+
+               return ubi_part(argv[2], vid_header_offset);
+       }
+
+       if ((strcmp(argv[1], "part") != 0) && (!ubi_dev.selected)) {
+               printf("Error, no UBI device/partition selected!\n");
+               return 1;
+       }
+
+       if (strcmp(argv[1], "info") == 0) {
+               int layout = 0;
+               if (argc > 2 && !strncmp(argv[2], "l", 1))
+                       layout = 1;
+               return ubi_info(layout);
+       }
+
+       if (strcmp(argv[1], "check") == 0) {
+               if (argc > 2)
+                       return ubi_check(argv[2]);
+
+               printf("Error, no volume name passed\n");
+               return 1;
+       }
+
+       if (strncmp(argv[1], "create", 6) == 0) {
+               int dynamic = 1;        /* default: dynamic volume */
+
+               /* Use maximum available size */
+               size = 0;
+
+               /* E.g., create volume size type */
+               if (argc == 5) {
+                       if (strncmp(argv[4], "s", 1) == 0)
+                               dynamic = 0;
+                       else if (strncmp(argv[4], "d", 1) != 0) {
+                               printf("Incorrect type\n");
+                               return 1;
+                       }
+                       argc--;
+               }
+               /* E.g., create volume size */
+               if (argc == 4) {
+                       size = simple_strtoull(argv[3], NULL, 16);
+                       argc--;
+               }
+               /* Use maximum available size */
+               if (!size) {
+                       size = (int64_t)ubi->avail_pebs * ubi->leb_size;
+                       printf("No size specified -> Using max size (%lld)\n", size);
+               }
+               /* E.g., create volume */
+               if (argc == 3)
+                       return ubi_create_vol(argv[2], size, dynamic);
+       }
+
+       if (strncmp(argv[1], "remove", 6) == 0) {
+               /* E.g., remove volume */
+               if (argc == 3)
+                       return ubi_remove_vol(argv[2]);
+       }
+
+       if (strncmp(argv[1], "write", 5) == 0) {
+               int ret;
+
+               if (argc < 5) {
+                       printf("Please see usage\n");
+                       return 1;
+               }
+
+               addr = simple_strtoul(argv[2], NULL, 16);
+               size = simple_strtoul(argv[4], NULL, 16);
+
+               if (strlen(argv[1]) == 10 &&
+                   strncmp(argv[1] + 5, ".part", 5) == 0) {
+                       if (argc < 6) {
+                               ret = ubi_volume_continue_write(argv[3],
+                                               (void *)addr, size);
+                       } else {
+                               size_t full_size;
+                               full_size = simple_strtoul(argv[5], NULL, 16);
+                               ret = ubi_volume_begin_write(argv[3],
+                                               (void *)addr, size, full_size);
+                       }
+               } else {
+                       ret = ubi_volume_write(argv[3], (void *)addr, size);
+               }
+               if (!ret) {
+                       printf("%lld bytes written to volume %s\n", size,
+                              argv[3]);
+               }
+
+               return ret;
+       }
+
+       if (strncmp(argv[1], "read", 4) == 0) {
+               size = 0;
+
+               /* E.g., read volume size */
+               if (argc == 5) {
+                       size = simple_strtoul(argv[4], NULL, 16);
+                       argc--;
+               }
+
+               /* E.g., read volume */
+               if (argc == 4) {
+                       addr = simple_strtoul(argv[2], NULL, 16);
+                       argc--;
+               }
+
+               if (argc == 3) {
+                       printf("Read %lld bytes from volume %s to %lx\n", size,
+                              argv[3], addr);
+
+                       return ubi_volume_read(argv[3], (char *)addr, size);
+               }
+       }
+
+       printf("Please see usage\n");
+       return 1;
+}
+
+U_BOOT_CMD(
+       ubi, 6, 1, do_ubi,
+       "ubi commands",
+       "part [part] [offset]\n"
+               " - Show or set current partition (with optional VID"
+               " header offset)\n"
+       "ubi info [l[ayout]]"
+               " - Display volume and ubi layout information\n"
+       "ubi check volumename"
+               " - check if volumename exists\n"
+       "ubi create[vol] volume [size] [type]"
+               " - create volume name with size\n"
+       "ubi write[vol] address volume size"
+               " - Write volume from address with size\n"
+       "ubi write.part address volume size [fullsize]\n"
+               " - Write part of a volume from address\n"
+       "ubi read[vol] address volume [size]"
+               " - Read volume to address with size\n"
+       "ubi remove[vol] volume"
+               " - Remove volume\n"
+       "[Legends]\n"
+       " volume: character name\n"
+       " size: specified in bytes\n"
+       " type: s[tatic] or d[ynamic] (default=dynamic)"
+);
diff --git a/cmd/ubifs.c b/cmd/ubifs.c
new file mode 100644 (file)
index 0000000..5e9d357
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * (C) Copyright 2008
+ * Stefan Roese, DENX Software Engineering, sr@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+
+/*
+ * UBIFS command support
+ */
+
+#undef DEBUG
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <ubifs_uboot.h>
+
+static int ubifs_initialized;
+static int ubifs_mounted;
+
+static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       char *vol_name;
+       int ret;
+
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       vol_name = argv[1];
+       debug("Using volume %s\n", vol_name);
+
+       if (ubifs_initialized == 0) {
+               ubifs_init();
+               ubifs_initialized = 1;
+       }
+
+       ret = uboot_ubifs_mount(vol_name);
+       if (ret)
+               return -1;
+
+       ubifs_mounted = 1;
+
+       return 0;
+}
+
+int ubifs_is_mounted(void)
+{
+       return ubifs_mounted;
+}
+
+void cmd_ubifs_umount(void)
+{
+       uboot_ubifs_umount();
+       ubifs_mounted = 0;
+       ubifs_initialized = 0;
+}
+
+static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       if (argc != 1)
+               return CMD_RET_USAGE;
+
+       if (ubifs_initialized == 0) {
+               printf("No UBIFS volume mounted!\n");
+               return -1;
+       }
+
+       cmd_ubifs_umount();
+
+       return 0;
+}
+
+static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       char *filename = "/";
+       int ret;
+
+       if (!ubifs_mounted) {
+               printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+               return -1;
+       }
+
+       if (argc == 2)
+               filename = argv[1];
+       debug("Using filename %s\n", filename);
+
+       ret = ubifs_ls(filename);
+       if (ret) {
+               printf("** File not found %s **\n", filename);
+               ret = CMD_RET_FAILURE;
+       }
+
+       return ret;
+}
+
+static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       char *filename;
+       char *endp;
+       int ret;
+       u32 addr;
+       u32 size = 0;
+
+       if (!ubifs_mounted) {
+               printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
+               return -1;
+       }
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       addr = simple_strtoul(argv[1], &endp, 16);
+       if (endp == argv[1])
+               return CMD_RET_USAGE;
+
+       filename = argv[2];
+
+       if (argc == 4) {
+               size = simple_strtoul(argv[3], &endp, 16);
+               if (endp == argv[3])
+                       return CMD_RET_USAGE;
+       }
+       debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
+
+       ret = ubifs_load(filename, addr, size);
+       if (ret) {
+               printf("** File not found %s **\n", filename);
+               ret = CMD_RET_FAILURE;
+       }
+
+       return ret;
+}
+
+U_BOOT_CMD(
+       ubifsmount, 2, 0, do_ubifs_mount,
+       "mount UBIFS volume",
+       "<volume-name>\n"
+       "    - mount 'volume-name' volume"
+);
+
+U_BOOT_CMD(
+       ubifsumount, 1, 0, do_ubifs_umount,
+       "unmount UBIFS volume",
+       "    - unmount current volume"
+);
+
+U_BOOT_CMD(
+       ubifsls, 2, 0, do_ubifs_ls,
+       "list files in a directory",
+       "[directory]\n"
+       "    - list files in a 'directory' (default '/')"
+);
+
+U_BOOT_CMD(
+       ubifsload, 4, 0, do_ubifs_load,
+       "load file from an UBIFS filesystem",
+       "<addr> <filename> [bytes]\n"
+       "    - load file 'filename' to address 'addr'"
+);
diff --git a/cmd/universe.c b/cmd/universe.c
new file mode 100644 (file)
index 0000000..c931036
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+ * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <pci.h>
+
+#include <universe.h>
+
+#define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
+#define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
+
+
+typedef struct _UNI_DEV UNI_DEV;
+
+struct _UNI_DEV {
+       int            bus;
+       pci_dev_t      busdevfn;
+       UNIVERSE       *uregs;
+       unsigned int   pci_bs;
+};
+
+static UNI_DEV   *dev;
+
+
+int universe_init(void)
+{
+       int j, result;
+       pci_dev_t busdevfn;
+       unsigned int val;
+
+       busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
+       if (busdevfn == -1) {
+               puts("No Tundra Universe found!\n");
+               return -1;
+       }
+
+       /* Lets turn Latency off */
+       pci_write_config_dword(busdevfn, 0x0c, 0);
+
+       dev = malloc(sizeof(*dev));
+       if (NULL == dev) {
+               puts("UNIVERSE: No memory!\n");
+               result = -1;
+               goto break_20;
+       }
+
+       memset(dev, 0, sizeof(*dev));
+       dev->busdevfn = busdevfn;
+
+       pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
+       if (val & 1) {
+               pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
+       }
+       val &= ~0xf;
+       dev->uregs = (UNIVERSE *)val;
+
+       debug ("UNIVERSE-Base    : %p\n", dev->uregs);
+
+       /* check mapping  */
+       debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
+       if (((PCI_DEVICE <<16) | PCI_VENDOR) !=  readl(&dev->uregs->pci_id)) {
+               printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
+                       readl(&dev->uregs->pci_id));
+               result = -1;
+               goto break_30;
+       }
+
+       debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
+
+       dev->pci_bs = readl(&dev->uregs->pci_bs);
+
+       /* turn off windows */
+       for (j=0; j <4; j ++) {
+               writel(0x00800000, &dev->uregs->lsi[j].ctl);
+               writel(0x00800000, &dev->uregs->vsi[j].ctl);
+       }
+
+       /*
+        * Write to Misc Register
+        * Set VME Bus Time-out
+        *   Arbitration Mode
+        *   DTACK Enable
+        */
+       writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl);
+
+       if (readl(&dev->uregs->misc_ctl) & 0x00020000) {
+               debug ("System Controller!\n"); /* test-only */
+       } else {
+               debug ("Not System Controller!\n"); /* test-only */
+       }
+
+       /*
+        * Lets turn off interrupts
+        */
+       writel(0x00000000,&dev->uregs->lint_en);   /* Disable interrupts in the Universe first */
+       writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
+       eieio();
+       writel(0x0000, &dev->uregs->lint_map0);  /* Map all ints to 0 */
+       writel(0x0000, &dev->uregs->lint_map1);  /* Map all ints to 0 */
+       eieio();
+
+       return 0;
+
+ break_30:
+       free(dev);
+ break_20:
+       return result;
+}
+
+
+/*
+ * Create pci slave window (access: pci -> vme)
+ */
+int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
+{
+       int result, i;
+       unsigned int ctl = 0;
+
+       if (NULL == dev) {
+               result = -1;
+               goto exit_10;
+       }
+
+       for (i = 0; i < 4; i++) {
+               if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
+                       break;
+       }
+
+       if (i == 4) {
+               printf ("universe: No Image available\n");
+               result = -1;
+               goto exit_10;
+       }
+
+       debug ("universe: Using image %d\n", i);
+
+       writel(pciAddr , &dev->uregs->lsi[i].bs);
+       writel((pciAddr + size), &dev->uregs->lsi[i].bd);
+       writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
+
+       switch (vam & VME_AM_Axx) {
+       case VME_AM_A16:
+               ctl = 0x00000000;
+               break;
+       case VME_AM_A24:
+               ctl = 0x00010000;
+               break;
+       case VME_AM_A32:
+               ctl = 0x00020000;
+               break;
+       }
+
+       switch (vam & VME_AM_Mxx) {
+       case VME_AM_DATA:
+               ctl |= 0x00000000;
+               break;
+       case VME_AM_PROG:
+               ctl |= 0x00008000;
+               break;
+       }
+
+       if (vam & VME_AM_SUP) {
+               ctl |= 0x00001000;
+
+       }
+
+       switch (vdw & VME_FLAG_Dxx) {
+       case VME_FLAG_D8:
+               ctl |= 0x00000000;
+               break;
+       case VME_FLAG_D16:
+               ctl |= 0x00400000;
+               break;
+       case VME_FLAG_D32:
+               ctl |= 0x00800000;
+               break;
+       }
+
+       switch (pms & PCI_MS_Mxx) {
+       case PCI_MS_MEM:
+               ctl |= 0x00000000;
+               break;
+       case PCI_MS_IO:
+               ctl |= 0x00000001;
+               break;
+       case PCI_MS_CONFIG:
+               ctl |= 0x00000002;
+               break;
+       }
+
+       ctl |= 0x80000000;    /* enable */
+
+       writel(ctl, &dev->uregs->lsi[i].ctl);
+
+       debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
+       debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
+       debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
+       debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
+       debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
+
+       return 0;
+
+ exit_10:
+       return -result;
+}
+
+
+/*
+ * Create vme slave window (access: vme -> pci)
+ */
+int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
+{
+       int result, i;
+       unsigned int ctl = 0;
+
+       if (NULL == dev) {
+               result = -1;
+               goto exit_10;
+       }
+
+       for (i = 0; i < 4; i++) {
+               if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
+                       break;
+       }
+
+       if (i == 4) {
+               printf ("universe: No Image available\n");
+               result = -1;
+               goto exit_10;
+       }
+
+       debug ("universe: Using image %d\n", i);
+
+       writel(vmeAddr , &dev->uregs->vsi[i].bs);
+       writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
+       writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
+
+       switch (vam & VME_AM_Axx) {
+       case VME_AM_A16:
+               ctl = 0x00000000;
+               break;
+       case VME_AM_A24:
+               ctl = 0x00010000;
+               break;
+       case VME_AM_A32:
+               ctl = 0x00020000;
+               break;
+       }
+
+       switch (vam & VME_AM_Mxx) {
+       case VME_AM_DATA:
+               ctl |= 0x00000000;
+               break;
+       case VME_AM_PROG:
+               ctl |= 0x00800000;
+               break;
+       }
+
+       if (vam & VME_AM_SUP) {
+               ctl |= 0x00100000;
+
+       }
+
+       switch (pms & PCI_MS_Mxx) {
+       case PCI_MS_MEM:
+               ctl |= 0x00000000;
+               break;
+       case PCI_MS_IO:
+               ctl |= 0x00000001;
+               break;
+       case PCI_MS_CONFIG:
+               ctl |= 0x00000002;
+               break;
+       }
+
+       ctl |= 0x80f00000;    /* enable */
+
+       writel(ctl, &dev->uregs->vsi[i].ctl);
+
+       debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
+       debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
+       debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
+       debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
+       debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
+
+       return 0;
+
+ exit_10:
+       return -result;
+}
+
+
+/*
+ * Tundra Universe configuration
+ */
+int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
+       char cmd = 'x';
+
+       /* get parameter */
+       if (argc > 1)
+               cmd = argv[1][0];
+       if (argc > 2)
+               addr1 = simple_strtoul(argv[2], NULL, 16);
+       if (argc > 3)
+               addr2 = simple_strtoul(argv[3], NULL, 16);
+       if (argc > 4)
+               size = simple_strtoul(argv[4], NULL, 16);
+       if (argc > 5)
+               vam = simple_strtoul(argv[5], NULL, 16);
+       if (argc > 6)
+               pms = simple_strtoul(argv[6], NULL, 16);
+       if (argc > 7)
+               vdw = simple_strtoul(argv[7], NULL, 16);
+
+       switch (cmd) {
+       case 'i':               /* init */
+               universe_init();
+               break;
+       case 'v':               /* vme */
+               printf("Configuring Universe VME Slave Window (VME->PCI):\n");
+               printf("  vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
+                      addr1, addr2, size, vam, pms);
+               universe_vme_slave_window(addr1, addr2, size, vam, pms);
+               break;
+       case 'p':               /* pci */
+               printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
+               printf("  pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
+                      addr1, addr2, size, vam, pms, vdw);
+               universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
+               break;
+       default:
+               printf("Universe command %s not supported!\n", argv[1]);
+       }
+
+       return 0;
+}
+
+
+U_BOOT_CMD(
+       universe,       8,      1,      do_universe,
+       "initialize and configure Turndra Universe",
+       "init\n"
+       "    - initialize universe\n"
+       "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
+       "    - create vme slave window (access: vme->pci)\n"
+       "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
+       "    - create pci slave window (access: pci->vme)\n"
+       "    [vam] = VMEbus Address-Modifier:  01 -> A16 Address Space\n"
+       "                                      02 -> A24 Address Space\n"
+       "                                      03 -> A32 Address Space\n"
+       "                                      04 -> Supervisor AM Code\n"
+       "                                      10 -> Data AM Code\n"
+       "                                      20 -> Program AM Code\n"
+       "    [pms] = PCI Memory Space:         01 -> Memory Space\n"
+       "                                      02 -> I/O Space\n"
+       "                                      03 -> Configuration Space\n"
+       "    [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
+       "                                      02 -> D16 Data Width\n"
+       "                                      03 -> D32 Data Width"
+);
diff --git a/cmd/unzip.c b/cmd/unzip.c
new file mode 100644 (file)
index 0000000..0686be6
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long src, dst;
+       unsigned long src_len = ~0UL, dst_len = ~0UL;
+
+       switch (argc) {
+               case 4:
+                       dst_len = simple_strtoul(argv[3], NULL, 16);
+                       /* fall through */
+               case 3:
+                       src = simple_strtoul(argv[1], NULL, 16);
+                       dst = simple_strtoul(argv[2], NULL, 16);
+                       break;
+               default:
+                       return CMD_RET_USAGE;
+       }
+
+       if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
+               return 1;
+
+       printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
+       setenv_hex("filesize", src_len);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       unzip,  4,      1,      do_unzip,
+       "unzip a memory region",
+       "srcaddr dstaddr [dstsize]"
+);
+
+static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
+                     int argc, char * const argv[])
+{
+       block_dev_desc_t *bdev;
+       int ret;
+       unsigned char *addr;
+       unsigned long length;
+       unsigned long writebuf = 1<<20;
+       u64 startoffs = 0;
+       u64 szexpected = 0;
+
+       if (argc < 5)
+               return CMD_RET_USAGE;
+       ret = get_device(argv[1], argv[2], &bdev);
+       if (ret < 0)
+               return CMD_RET_FAILURE;
+
+       addr = (unsigned char *)simple_strtoul(argv[3], NULL, 16);
+       length = simple_strtoul(argv[4], NULL, 16);
+
+       if (5 < argc) {
+               writebuf = simple_strtoul(argv[5], NULL, 16);
+               if (6 < argc) {
+                       startoffs = simple_strtoull(argv[6], NULL, 16);
+                       if (7 < argc)
+                               szexpected = simple_strtoull(argv[7],
+                                                            NULL, 16);
+               }
+       }
+
+       ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
+
+       return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+       gzwrite, 8, 0, do_gzwrite,
+       "unzip and write memory to block device",
+       "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
+       "\twbuf is the size in bytes (hex) of write buffer\n"
+       "\t\tand should be padded to erase size for SSDs\n"
+       "\toffs is the output start offset in bytes (hex)\n"
+       "\toutsize is the size of the expected output (hex bytes)\n"
+       "\t\tand is required for files with uncompressed lengths\n"
+       "\t\t4 GiB or larger\n"
+);
diff --git a/cmd/usb.c b/cmd/usb.c
new file mode 100644 (file)
index 0000000..c7b642c
--- /dev/null
+++ b/cmd/usb.c
@@ -0,0 +1,853 @@
+/*
+ * (C) Copyright 2001
+ * Denis Peter, MPL AG Switzerland
+ *
+ * Adapted for U-Boot driver model
+ * (C) Copyright 2015 Google, Inc
+ *
+ * Most of this source has been derived from the Linux USB
+ * project.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <dm.h>
+#include <memalign.h>
+#include <asm/byteorder.h>
+#include <asm/unaligned.h>
+#include <part.h>
+#include <usb.h>
+
+#ifdef CONFIG_USB_STORAGE
+static int usb_stor_curr_dev = -1; /* current device */
+#endif
+#if defined(CONFIG_USB_HOST_ETHER) && !defined(CONFIG_DM_ETH)
+static int __maybe_unused usb_ether_curr_dev = -1; /* current ethernet device */
+#endif
+
+/* some display routines (info command) */
+static char *usb_get_class_desc(unsigned char dclass)
+{
+       switch (dclass) {
+       case USB_CLASS_PER_INTERFACE:
+               return "See Interface";
+       case USB_CLASS_AUDIO:
+               return "Audio";
+       case USB_CLASS_COMM:
+               return "Communication";
+       case USB_CLASS_HID:
+               return "Human Interface";
+       case USB_CLASS_PRINTER:
+               return "Printer";
+       case USB_CLASS_MASS_STORAGE:
+               return "Mass Storage";
+       case USB_CLASS_HUB:
+               return "Hub";
+       case USB_CLASS_DATA:
+               return "CDC Data";
+       case USB_CLASS_VENDOR_SPEC:
+               return "Vendor specific";
+       default:
+               return "";
+       }
+}
+
+static void usb_display_class_sub(unsigned char dclass, unsigned char subclass,
+                                 unsigned char proto)
+{
+       switch (dclass) {
+       case USB_CLASS_PER_INTERFACE:
+               printf("See Interface");
+               break;
+       case USB_CLASS_HID:
+               printf("Human Interface, Subclass: ");
+               switch (subclass) {
+               case USB_SUB_HID_NONE:
+                       printf("None");
+                       break;
+               case USB_SUB_HID_BOOT:
+                       printf("Boot ");
+                       switch (proto) {
+                       case USB_PROT_HID_NONE:
+                               printf("None");
+                               break;
+                       case USB_PROT_HID_KEYBOARD:
+                               printf("Keyboard");
+                               break;
+                       case USB_PROT_HID_MOUSE:
+                               printf("Mouse");
+                               break;
+                       default:
+                               printf("reserved");
+                               break;
+                       }
+                       break;
+               default:
+                       printf("reserved");
+                       break;
+               }
+               break;
+       case USB_CLASS_MASS_STORAGE:
+               printf("Mass Storage, ");
+               switch (subclass) {
+               case US_SC_RBC:
+                       printf("RBC ");
+                       break;
+               case US_SC_8020:
+                       printf("SFF-8020i (ATAPI)");
+                       break;
+               case US_SC_QIC:
+                       printf("QIC-157 (Tape)");
+                       break;
+               case US_SC_UFI:
+                       printf("UFI");
+                       break;
+               case US_SC_8070:
+                       printf("SFF-8070");
+                       break;
+               case US_SC_SCSI:
+                       printf("Transp. SCSI");
+                       break;
+               default:
+                       printf("reserved");
+                       break;
+               }
+               printf(", ");
+               switch (proto) {
+               case US_PR_CB:
+                       printf("Command/Bulk");
+                       break;
+               case US_PR_CBI:
+                       printf("Command/Bulk/Int");
+                       break;
+               case US_PR_BULK:
+                       printf("Bulk only");
+                       break;
+               default:
+                       printf("reserved");
+                       break;
+               }
+               break;
+       default:
+               printf("%s", usb_get_class_desc(dclass));
+               break;
+       }
+}
+
+static void usb_display_string(struct usb_device *dev, int index)
+{
+       ALLOC_CACHE_ALIGN_BUFFER(char, buffer, 256);
+
+       if (index != 0) {
+               if (usb_string(dev, index, &buffer[0], 256) > 0)
+                       printf("String: \"%s\"", buffer);
+       }
+}
+
+static void usb_display_desc(struct usb_device *dev)
+{
+       if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) {
+               printf("%d: %s,  USB Revision %x.%x\n", dev->devnum,
+               usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass),
+                                  (dev->descriptor.bcdUSB>>8) & 0xff,
+                                  dev->descriptor.bcdUSB & 0xff);
+
+               if (strlen(dev->mf) || strlen(dev->prod) ||
+                   strlen(dev->serial))
+                       printf(" - %s %s %s\n", dev->mf, dev->prod,
+                               dev->serial);
+               if (dev->descriptor.bDeviceClass) {
+                       printf(" - Class: ");
+                       usb_display_class_sub(dev->descriptor.bDeviceClass,
+                                             dev->descriptor.bDeviceSubClass,
+                                             dev->descriptor.bDeviceProtocol);
+                       printf("\n");
+               } else {
+                       printf(" - Class: (from Interface) %s\n",
+                              usb_get_class_desc(
+                               dev->config.if_desc[0].desc.bInterfaceClass));
+               }
+               printf(" - PacketSize: %d  Configurations: %d\n",
+                       dev->descriptor.bMaxPacketSize0,
+                       dev->descriptor.bNumConfigurations);
+               printf(" - Vendor: 0x%04x  Product 0x%04x Version %d.%d\n",
+                       dev->descriptor.idVendor, dev->descriptor.idProduct,
+                       (dev->descriptor.bcdDevice>>8) & 0xff,
+                       dev->descriptor.bcdDevice & 0xff);
+       }
+
+}
+
+static void usb_display_conf_desc(struct usb_config_descriptor *config,
+                                 struct usb_device *dev)
+{
+       printf("   Configuration: %d\n", config->bConfigurationValue);
+       printf("   - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
+              (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
+              (config->bmAttributes & 0x20) ? "Remote Wakeup " : "",
+               config->bMaxPower*2);
+       if (config->iConfiguration) {
+               printf("   - ");
+               usb_display_string(dev, config->iConfiguration);
+               printf("\n");
+       }
+}
+
+static void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,
+                               struct usb_device *dev)
+{
+       printf("     Interface: %d\n", ifdesc->bInterfaceNumber);
+       printf("     - Alternate Setting %d, Endpoints: %d\n",
+               ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
+       printf("     - Class ");
+       usb_display_class_sub(ifdesc->bInterfaceClass,
+               ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol);
+       printf("\n");
+       if (ifdesc->iInterface) {
+               printf("     - ");
+               usb_display_string(dev, ifdesc->iInterface);
+               printf("\n");
+       }
+}
+
+static void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
+{
+       printf("     - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf,
+               (epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
+       switch ((epdesc->bmAttributes & 0x03)) {
+       case 0:
+               printf("Control");
+               break;
+       case 1:
+               printf("Isochronous");
+               break;
+       case 2:
+               printf("Bulk");
+               break;
+       case 3:
+               printf("Interrupt");
+               break;
+       }
+       printf(" MaxPacket %d", get_unaligned(&epdesc->wMaxPacketSize));
+       if ((epdesc->bmAttributes & 0x03) == 0x3)
+               printf(" Interval %dms", epdesc->bInterval);
+       printf("\n");
+}
+
+/* main routine to diasplay the configs, interfaces and endpoints */
+static void usb_display_config(struct usb_device *dev)
+{
+       struct usb_config *config;
+       struct usb_interface *ifdesc;
+       struct usb_endpoint_descriptor *epdesc;
+       int i, ii;
+
+       config = &dev->config;
+       usb_display_conf_desc(&config->desc, dev);
+       for (i = 0; i < config->no_of_if; i++) {
+               ifdesc = &config->if_desc[i];
+               usb_display_if_desc(&ifdesc->desc, dev);
+               for (ii = 0; ii < ifdesc->no_of_ep; ii++) {
+                       epdesc = &ifdesc->ep_desc[ii];
+                       usb_display_ep_desc(epdesc);
+               }
+       }
+       printf("\n");
+}
+
+/*
+ * With driver model this isn't right since we can have multiple controllers
+ * and the device numbering starts at 1 on each bus.
+ * TODO(sjg@chromium.org): Add a way to specify the controller/bus.
+ */
+static struct usb_device *usb_find_device(int devnum)
+{
+#ifdef CONFIG_DM_USB
+       struct usb_device *udev;
+       struct udevice *hub;
+       struct uclass *uc;
+       int ret;
+
+       /* Device addresses start at 1 */
+       devnum++;
+       ret = uclass_get(UCLASS_USB_HUB, &uc);
+       if (ret)
+               return NULL;
+
+       uclass_foreach_dev(hub, uc) {
+               struct udevice *dev;
+
+               if (!device_active(hub))
+                       continue;
+               udev = dev_get_parent_priv(hub);
+               if (udev->devnum == devnum)
+                       return udev;
+
+               for (device_find_first_child(hub, &dev);
+                    dev;
+                    device_find_next_child(&dev)) {
+                       if (!device_active(hub))
+                               continue;
+
+                       udev = dev_get_parent_priv(dev);
+                       if (udev->devnum == devnum)
+                               return udev;
+               }
+       }
+#else
+       struct usb_device *udev;
+       int d;
+
+       for (d = 0; d < USB_MAX_DEVICE; d++) {
+               udev = usb_get_dev_index(d);
+               if (udev == NULL)
+                       return NULL;
+               if (udev->devnum == devnum)
+                       return udev;
+       }
+#endif
+
+       return NULL;
+}
+
+static inline char *portspeed(int speed)
+{
+       char *speed_str;
+
+       switch (speed) {
+       case USB_SPEED_SUPER:
+               speed_str = "5 Gb/s";
+               break;
+       case USB_SPEED_HIGH:
+               speed_str = "480 Mb/s";
+               break;
+       case USB_SPEED_LOW:
+               speed_str = "1.5 Mb/s";
+               break;
+       default:
+               speed_str = "12 Mb/s";
+               break;
+       }
+
+       return speed_str;
+}
+
+/* shows the device tree recursively */
+static void usb_show_tree_graph(struct usb_device *dev, char *pre)
+{
+       int index;
+       int has_child, last_child;
+
+       index = strlen(pre);
+       printf(" %s", pre);
+#ifdef CONFIG_DM_USB
+       has_child = device_has_active_children(dev->dev);
+#else
+       /* check if the device has connected children */
+       int i;
+
+       has_child = 0;
+       for (i = 0; i < dev->maxchild; i++) {
+               if (dev->children[i] != NULL)
+                       has_child = 1;
+       }
+#endif
+       /* check if we are the last one */
+#ifdef CONFIG_DM_USB
+       /* Not the root of the usb tree? */
+       if (device_get_uclass_id(dev->dev->parent) != UCLASS_USB) {
+               last_child = device_is_last_sibling(dev->dev);
+#else
+       if (dev->parent != NULL) { /* not root? */
+               last_child = 1;
+               for (i = 0; i < dev->parent->maxchild; i++) {
+                       /* search for children */
+                       if (dev->parent->children[i] == dev) {
+                               /* found our pointer, see if we have a
+                                * little sister
+                                */
+                               while (i++ < dev->parent->maxchild) {
+                                       if (dev->parent->children[i] != NULL) {
+                                               /* found a sister */
+                                               last_child = 0;
+                                               break;
+                                       } /* if */
+                               } /* while */
+                       } /* device found */
+               } /* for all children of the parent */
+#endif
+               printf("\b+-");
+               /* correct last child */
+               if (last_child && index)
+                       pre[index-1] = ' ';
+       } /* if not root hub */
+       else
+               printf(" ");
+       printf("%d ", dev->devnum);
+       pre[index++] = ' ';
+       pre[index++] = has_child ? '|' : ' ';
+       pre[index] = 0;
+       printf(" %s (%s, %dmA)\n", usb_get_class_desc(
+                                       dev->config.if_desc[0].desc.bInterfaceClass),
+                                       portspeed(dev->speed),
+                                       dev->config.desc.bMaxPower * 2);
+       if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
+               printf(" %s  %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
+       printf(" %s\n", pre);
+#ifdef CONFIG_DM_USB
+       struct udevice *child;
+
+       for (device_find_first_child(dev->dev, &child);
+            child;
+            device_find_next_child(&child)) {
+               struct usb_device *udev;
+
+               if (!device_active(child))
+                       continue;
+
+               udev = dev_get_parent_priv(child);
+
+               /* Ignore emulators, we only want real devices */
+               if (device_get_uclass_id(child) != UCLASS_USB_EMUL) {
+                       usb_show_tree_graph(udev, pre);
+                       pre[index] = 0;
+               }
+       }
+#else
+       if (dev->maxchild > 0) {
+               for (i = 0; i < dev->maxchild; i++) {
+                       if (dev->children[i] != NULL) {
+                               usb_show_tree_graph(dev->children[i], pre);
+                               pre[index] = 0;
+                       }
+               }
+       }
+#endif
+}
+
+/* main routine for the tree command */
+static void usb_show_subtree(struct usb_device *dev)
+{
+       char preamble[32];
+
+       memset(preamble, '\0', sizeof(preamble));
+       usb_show_tree_graph(dev, &preamble[0]);
+}
+
+void usb_show_tree(void)
+{
+#ifdef CONFIG_DM_USB
+       struct udevice *bus;
+
+       for (uclass_first_device(UCLASS_USB, &bus);
+               bus;
+               uclass_next_device(&bus)) {
+               struct usb_device *udev;
+               struct udevice *dev;
+
+               device_find_first_child(bus, &dev);
+               if (dev && device_active(dev)) {
+                       udev = dev_get_parent_priv(dev);
+                       usb_show_subtree(udev);
+               }
+       }
+#else
+       struct usb_device *udev;
+       int i;
+
+       for (i = 0; i < USB_MAX_DEVICE; i++) {
+               udev = usb_get_dev_index(i);
+               if (udev == NULL)
+                       break;
+               if (udev->parent == NULL)
+                       usb_show_subtree(udev);
+       }
+#endif
+}
+
+static int usb_test(struct usb_device *dev, int port, char* arg)
+{
+       int mode;
+
+       if (port > dev->maxchild) {
+               printf("Device is no hub or does not have %d ports.\n", port);
+               return 1;
+       }
+
+       switch (arg[0]) {
+       case 'J':
+       case 'j':
+               printf("Setting Test_J mode");
+               mode = USB_TEST_MODE_J;
+               break;
+       case 'K':
+       case 'k':
+               printf("Setting Test_K mode");
+               mode = USB_TEST_MODE_K;
+               break;
+       case 'S':
+       case 's':
+               printf("Setting Test_SE0_NAK mode");
+               mode = USB_TEST_MODE_SE0_NAK;
+               break;
+       case 'P':
+       case 'p':
+               printf("Setting Test_Packet mode");
+               mode = USB_TEST_MODE_PACKET;
+               break;
+       case 'F':
+       case 'f':
+               printf("Setting Test_Force_Enable mode");
+               mode = USB_TEST_MODE_FORCE_ENABLE;
+               break;
+       default:
+               printf("Unrecognized test mode: %s\nAvailable modes: "
+                      "J, K, S[E0_NAK], P[acket], F[orce_Enable]\n", arg);
+               return 1;
+       }
+
+       if (port)
+               printf(" on downstream facing port %d...\n", port);
+       else
+               printf(" on upstream facing port...\n");
+
+       if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE,
+                           port ? USB_RT_PORT : USB_RECIP_DEVICE,
+                           port ? USB_PORT_FEAT_TEST : USB_FEAT_TEST,
+                           (mode << 8) | port,
+                           NULL, 0, USB_CNTL_TIMEOUT) == -1) {
+               printf("Error during SET_FEATURE.\n");
+               return 1;
+       } else {
+               printf("Test mode successfully set. Use 'usb start' "
+                      "to return to normal operation.\n");
+               return 0;
+       }
+}
+
+
+/******************************************************************************
+ * usb boot command intepreter. Derived from diskboot
+ */
+#ifdef CONFIG_USB_STORAGE
+static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return common_diskboot(cmdtp, "usb", argc, argv);
+}
+#endif /* CONFIG_USB_STORAGE */
+
+static int do_usb_stop_keyboard(int force)
+{
+#ifdef CONFIG_USB_KEYBOARD
+       if (usb_kbd_deregister(force) != 0) {
+               printf("USB not stopped: usbkbd still using USB\n");
+               return 1;
+       }
+#endif
+       return 0;
+}
+
+static void do_usb_start(void)
+{
+       bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
+
+       if (usb_init() < 0)
+               return;
+
+       /* Driver model will probe the devices as they are found */
+#ifndef CONFIG_DM_USB
+# ifdef CONFIG_USB_STORAGE
+       /* try to recognize storage devices immediately */
+       usb_stor_curr_dev = usb_stor_scan(1);
+# endif
+# ifdef CONFIG_USB_KEYBOARD
+       drv_usb_kbd_init();
+# endif
+#endif /* !CONFIG_DM_USB */
+#ifdef CONFIG_USB_HOST_ETHER
+# ifdef CONFIG_DM_ETH
+#  ifndef CONFIG_DM_USB
+#   error "You must use CONFIG_DM_USB if you want to use CONFIG_USB_HOST_ETHER with CONFIG_DM_ETH"
+#  endif
+# else
+       /* try to recognize ethernet devices immediately */
+       usb_ether_curr_dev = usb_host_eth_scan(1);
+# endif
+#endif
+}
+
+#ifdef CONFIG_DM_USB
+static void show_info(struct udevice *dev)
+{
+       struct udevice *child;
+       struct usb_device *udev;
+
+       udev = dev_get_parent_priv(dev);
+       usb_display_desc(udev);
+       usb_display_config(udev);
+       for (device_find_first_child(dev, &child);
+            child;
+            device_find_next_child(&child)) {
+               if (device_active(child))
+                       show_info(child);
+       }
+}
+
+static int usb_device_info(void)
+{
+       struct udevice *bus;
+
+       for (uclass_first_device(UCLASS_USB, &bus);
+            bus;
+            uclass_next_device(&bus)) {
+               struct udevice *hub;
+
+               device_find_first_child(bus, &hub);
+               if (device_get_uclass_id(hub) == UCLASS_USB_HUB &&
+                   device_active(hub)) {
+                       show_info(hub);
+               }
+       }
+
+       return 0;
+}
+#endif
+
+/******************************************************************************
+ * usb command intepreter
+ */
+static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct usb_device *udev = NULL;
+       int i;
+       extern char usb_started;
+#ifdef CONFIG_USB_STORAGE
+       block_dev_desc_t *stor_dev;
+#endif
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if (strncmp(argv[1], "start", 5) == 0) {
+               if (usb_started)
+                       return 0; /* Already started */
+               printf("starting USB...\n");
+               do_usb_start();
+               return 0;
+       }
+
+       if (strncmp(argv[1], "reset", 5) == 0) {
+               printf("resetting USB...\n");
+               if (do_usb_stop_keyboard(1) != 0)
+                       return 1;
+               usb_stop();
+               do_usb_start();
+               return 0;
+       }
+       if (strncmp(argv[1], "stop", 4) == 0) {
+               if (argc != 2)
+                       console_assign(stdin, "serial");
+               if (do_usb_stop_keyboard(0) != 0)
+                       return 1;
+               printf("stopping USB..\n");
+               usb_stop();
+               return 0;
+       }
+       if (!usb_started) {
+               printf("USB is stopped. Please issue 'usb start' first.\n");
+               return 1;
+       }
+       if (strncmp(argv[1], "tree", 4) == 0) {
+               puts("USB device tree:\n");
+               usb_show_tree();
+               return 0;
+       }
+       if (strncmp(argv[1], "inf", 3) == 0) {
+               if (argc == 2) {
+#ifdef CONFIG_DM_USB
+                       usb_device_info();
+#else
+                       int d;
+                       for (d = 0; d < USB_MAX_DEVICE; d++) {
+                               udev = usb_get_dev_index(d);
+                               if (udev == NULL)
+                                       break;
+                               usb_display_desc(udev);
+                               usb_display_config(udev);
+                       }
+#endif
+                       return 0;
+               } else {
+                       /*
+                        * With driver model this isn't right since we can
+                        * have multiple controllers and the device numbering
+                        * starts at 1 on each bus.
+                        */
+                       i = simple_strtoul(argv[2], NULL, 10);
+                       printf("config for device %d\n", i);
+                       udev = usb_find_device(i);
+                       if (udev == NULL) {
+                               printf("*** No device available ***\n");
+                               return 0;
+                       } else {
+                               usb_display_desc(udev);
+                               usb_display_config(udev);
+                       }
+               }
+               return 0;
+       }
+       if (strncmp(argv[1], "test", 4) == 0) {
+               if (argc < 5)
+                       return CMD_RET_USAGE;
+               i = simple_strtoul(argv[2], NULL, 10);
+               udev = usb_find_device(i);
+               if (udev == NULL) {
+                       printf("Device %d does not exist.\n", i);
+                       return 1;
+               }
+               i = simple_strtoul(argv[3], NULL, 10);
+               return usb_test(udev, i, argv[4]);
+       }
+#ifdef CONFIG_USB_STORAGE
+       if (strncmp(argv[1], "stor", 4) == 0)
+               return usb_stor_info();
+
+       if (strncmp(argv[1], "part", 4) == 0) {
+               int devno, ok = 0;
+               if (argc == 2) {
+                       for (devno = 0; ; ++devno) {
+                               stor_dev = usb_stor_get_dev(devno);
+                               if (stor_dev == NULL)
+                                       break;
+                               if (stor_dev->type != DEV_TYPE_UNKNOWN) {
+                                       ok++;
+                                       if (devno)
+                                               printf("\n");
+                                       debug("print_part of %x\n", devno);
+                                       print_part(stor_dev);
+                               }
+                       }
+               } else {
+                       devno = simple_strtoul(argv[2], NULL, 16);
+                       stor_dev = usb_stor_get_dev(devno);
+                       if (stor_dev != NULL &&
+                           stor_dev->type != DEV_TYPE_UNKNOWN) {
+                               ok++;
+                               debug("print_part of %x\n", devno);
+                               print_part(stor_dev);
+                       }
+               }
+               if (!ok) {
+                       printf("\nno USB devices available\n");
+                       return 1;
+               }
+               return 0;
+       }
+       if (strcmp(argv[1], "read") == 0) {
+               if (usb_stor_curr_dev < 0) {
+                       printf("no current device selected\n");
+                       return 1;
+               }
+               if (argc == 5) {
+                       unsigned long addr = simple_strtoul(argv[2], NULL, 16);
+                       unsigned long blk  = simple_strtoul(argv[3], NULL, 16);
+                       unsigned long cnt  = simple_strtoul(argv[4], NULL, 16);
+                       unsigned long n;
+                       printf("\nUSB read: device %d block # %ld, count %ld"
+                               " ... ", usb_stor_curr_dev, blk, cnt);
+                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
+                       n = stor_dev->block_read(stor_dev, blk, cnt,
+                                                (ulong *)addr);
+                       printf("%ld blocks read: %s\n", n,
+                               (n == cnt) ? "OK" : "ERROR");
+                       if (n == cnt)
+                               return 0;
+                       return 1;
+               }
+       }
+       if (strcmp(argv[1], "write") == 0) {
+               if (usb_stor_curr_dev < 0) {
+                       printf("no current device selected\n");
+                       return 1;
+               }
+               if (argc == 5) {
+                       unsigned long addr = simple_strtoul(argv[2], NULL, 16);
+                       unsigned long blk  = simple_strtoul(argv[3], NULL, 16);
+                       unsigned long cnt  = simple_strtoul(argv[4], NULL, 16);
+                       unsigned long n;
+                       printf("\nUSB write: device %d block # %ld, count %ld"
+                               " ... ", usb_stor_curr_dev, blk, cnt);
+                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
+                       n = stor_dev->block_write(stor_dev, blk, cnt,
+                                               (ulong *)addr);
+                       printf("%ld blocks write: %s\n", n,
+                               (n == cnt) ? "OK" : "ERROR");
+                       if (n == cnt)
+                               return 0;
+                       return 1;
+               }
+       }
+       if (strncmp(argv[1], "dev", 3) == 0) {
+               if (argc == 3) {
+                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
+                       printf("\nUSB device %d: ", dev);
+                       stor_dev = usb_stor_get_dev(dev);
+                       if (stor_dev == NULL) {
+                               printf("unknown device\n");
+                               return 1;
+                       }
+                       printf("\n    Device %d: ", dev);
+                       dev_print(stor_dev);
+                       if (stor_dev->type == DEV_TYPE_UNKNOWN)
+                               return 1;
+                       usb_stor_curr_dev = dev;
+                       printf("... is now current device\n");
+                       return 0;
+               } else {
+                       printf("\nUSB device %d: ", usb_stor_curr_dev);
+                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
+                       dev_print(stor_dev);
+                       if (stor_dev->type == DEV_TYPE_UNKNOWN)
+                               return 1;
+                       return 0;
+               }
+               return 0;
+       }
+#endif /* CONFIG_USB_STORAGE */
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       usb,    5,      1,      do_usb,
+       "USB sub-system",
+       "start - start (scan) USB controller\n"
+       "usb reset - reset (rescan) USB controller\n"
+       "usb stop [f] - stop USB [f]=force stop\n"
+       "usb tree - show USB device tree\n"
+       "usb info [dev] - show available USB devices\n"
+       "usb test [dev] [port] [mode] - set USB 2.0 test mode\n"
+       "    (specify port 0 to indicate the device's upstream port)\n"
+       "    Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n"
+#ifdef CONFIG_USB_STORAGE
+       "usb storage - show details of USB storage devices\n"
+       "usb dev [dev] - show or set current USB storage device\n"
+       "usb part [dev] - print partition table of one or all USB storage"
+       "    devices\n"
+       "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
+       "    to memory address `addr'\n"
+       "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n"
+       "    from memory address `addr'"
+#endif /* CONFIG_USB_STORAGE */
+);
+
+
+#ifdef CONFIG_USB_STORAGE
+U_BOOT_CMD(
+       usbboot,        3,      1,      do_usbboot,
+       "boot from USB device",
+       "loadAddr dev:part"
+);
+#endif /* CONFIG_USB_STORAGE */
diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c
new file mode 100644 (file)
index 0000000..0415591
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <errno.h>
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <g_dnl.h>
+#include <part.h>
+#include <usb.h>
+#include <usb_mass_storage.h>
+
+static int ums_read_sector(struct ums *ums_dev,
+                          ulong start, lbaint_t blkcnt, void *buf)
+{
+       block_dev_desc_t *block_dev = &ums_dev->block_dev;
+       lbaint_t blkstart = start + ums_dev->start_sector;
+
+       return block_dev->block_read(block_dev, blkstart, blkcnt, buf);
+}
+
+static int ums_write_sector(struct ums *ums_dev,
+                           ulong start, lbaint_t blkcnt, const void *buf)
+{
+       block_dev_desc_t *block_dev = &ums_dev->block_dev;
+       lbaint_t blkstart = start + ums_dev->start_sector;
+
+       return block_dev->block_write(block_dev, blkstart, blkcnt, buf);
+}
+
+static struct ums *ums;
+static int ums_count;
+
+static void ums_fini(void)
+{
+       int i;
+
+       for (i = 0; i < ums_count; i++)
+               free((void *)ums[i].name);
+       free(ums);
+       ums = 0;
+       ums_count = 0;
+}
+
+#define UMS_NAME_LEN 16
+
+static int ums_init(const char *devtype, const char *devnums)
+{
+       char *s, *t, *devnum, *name;
+       block_dev_desc_t *block_dev;
+       int ret;
+       struct ums *ums_new;
+
+       s = strdup(devnums);
+       if (!s)
+               return -1;
+
+       t = s;
+       ums_count = 0;
+
+       for (;;) {
+               devnum = strsep(&t, ",");
+               if (!devnum)
+                       break;
+
+               ret = get_device(devtype, devnum, &block_dev);
+               if (ret < 0)
+                       goto cleanup;
+
+               /* f_mass_storage.c assumes SECTOR_SIZE sectors */
+               if (block_dev->blksz != SECTOR_SIZE) {
+                       ret = -1;
+                       goto cleanup;
+               }
+
+               ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums));
+               if (!ums_new) {
+                       ret = -1;
+                       goto cleanup;
+               }
+               ums = ums_new;
+
+               ums[ums_count].read_sector = ums_read_sector;
+               ums[ums_count].write_sector = ums_write_sector;
+               ums[ums_count].start_sector = 0;
+               ums[ums_count].num_sectors = block_dev->lba;
+               name = malloc(UMS_NAME_LEN);
+               if (!name) {
+                       ret = -1;
+                       goto cleanup;
+               }
+               snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count);
+               ums[ums_count].name = name;
+               ums[ums_count].block_dev = *block_dev;
+
+               printf("UMS: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n",
+                      ums_count, ums[ums_count].block_dev.dev,
+                      ums[ums_count].block_dev.hwpart,
+                      ums[ums_count].start_sector,
+                      ums[ums_count].num_sectors);
+
+               ums_count++;
+       }
+
+       if (!ums_count)
+               ret = -1;
+       else
+               ret = 0;
+
+cleanup:
+       free(s);
+
+       if (ret < 0)
+               ums_fini();
+
+       return ret;
+}
+
+int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
+                              int argc, char * const argv[])
+{
+       const char *usb_controller;
+       const char *devtype;
+       const char *devnum;
+       unsigned int controller_index;
+       int rc;
+       int cable_ready_timeout __maybe_unused;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       usb_controller = argv[1];
+       if (argc >= 4) {
+               devtype = argv[2];
+               devnum  = argv[3];
+       } else {
+               devtype = "mmc";
+               devnum  = argv[2];
+       }
+
+       rc = ums_init(devtype, devnum);
+       if (rc < 0)
+               return CMD_RET_FAILURE;
+
+       controller_index = (unsigned int)(simple_strtoul(
+                               usb_controller, NULL, 0));
+       if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
+               error("Couldn't init USB controller.");
+               rc = CMD_RET_FAILURE;
+               goto cleanup_ums_init;
+       }
+
+       rc = fsg_init(ums, ums_count);
+       if (rc) {
+               error("fsg_init failed");
+               rc = CMD_RET_FAILURE;
+               goto cleanup_board;
+       }
+
+       rc = g_dnl_register("usb_dnl_ums");
+       if (rc) {
+               error("g_dnl_register failed");
+               rc = CMD_RET_FAILURE;
+               goto cleanup_board;
+       }
+
+       /* Timeout unit: seconds */
+       cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
+
+       if (!g_dnl_board_usb_cable_connected()) {
+               /*
+                * Won't execute if we don't know whether the cable is
+                * connected.
+                */
+               puts("Please connect USB cable.\n");
+
+               while (!g_dnl_board_usb_cable_connected()) {
+                       if (ctrlc()) {
+                               puts("\rCTRL+C - Operation aborted.\n");
+                               rc = CMD_RET_SUCCESS;
+                               goto cleanup_register;
+                       }
+                       if (!cable_ready_timeout) {
+                               puts("\rUSB cable not detected.\n" \
+                                    "Command exit.\n");
+                               rc = CMD_RET_SUCCESS;
+                               goto cleanup_register;
+                       }
+
+                       printf("\rAuto exit in: %.2d s.", cable_ready_timeout);
+                       mdelay(1000);
+                       cable_ready_timeout--;
+               }
+               puts("\r\n");
+       }
+
+       while (1) {
+               usb_gadget_handle_interrupts(controller_index);
+
+               rc = fsg_main_thread(NULL);
+               if (rc) {
+                       /* Check I/O error */
+                       if (rc == -EIO)
+                               printf("\rCheck USB cable connection\n");
+
+                       /* Check CTRL+C */
+                       if (rc == -EPIPE)
+                               printf("\rCTRL+C - Operation aborted\n");
+
+                       rc = CMD_RET_SUCCESS;
+                       goto cleanup_register;
+               }
+       }
+
+cleanup_register:
+       g_dnl_unregister();
+cleanup_board:
+       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
+cleanup_ums_init:
+       ums_fini();
+
+       return rc;
+}
+
+U_BOOT_CMD(ums, 4, 1, do_usb_mass_storage,
+       "Use the UMS [USB Mass Storage]",
+       "<USB_controller> [<devtype>] <devnum>  e.g. ums 0 mmc 0\n"
+       "    devtype defaults to mmc"
+);
diff --git a/cmd/version.c b/cmd/version.c
new file mode 100644 (file)
index 0000000..1be0667
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <version.h>
+#include <linux/compiler.h>
+#ifdef CONFIG_SYS_COREBOOT
+#include <asm/arch/sysinfo.h>
+#endif
+
+const char __weak version_string[] = U_BOOT_VERSION_STRING;
+
+static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       printf("\n%s\n", version_string);
+#ifdef CC_VERSION_STRING
+       puts(CC_VERSION_STRING "\n");
+#endif
+#ifdef LD_VERSION_STRING
+       puts(LD_VERSION_STRING "\n");
+#endif
+#ifdef CONFIG_SYS_COREBOOT
+       printf("coreboot-%s (%s)\n", lib_sysinfo.version, lib_sysinfo.build);
+#endif
+       return 0;
+}
+
+U_BOOT_CMD(
+       version,        1,              1,      do_version,
+       "print monitor, compiler and linker version",
+       ""
+);
diff --git a/cmd/ximg.c b/cmd/ximg.c
new file mode 100644 (file)
index 0000000..d033c15
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2003
+ * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+
+/*
+ * Multi Image extract
+ */
+#include <common.h>
+#include <command.h>
+#include <image.h>
+#include <mapmem.h>
+#include <watchdog.h>
+#if defined(CONFIG_BZIP2)
+#include <bzlib.h>
+#endif
+#include <asm/byteorder.h>
+#include <asm/io.h>
+
+#ifndef CONFIG_SYS_XIMG_LEN
+/* use 8MByte as default max gunzip size */
+#define CONFIG_SYS_XIMG_LEN    0x800000
+#endif
+
+static int
+do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong           addr = load_addr;
+       ulong           dest = 0;
+       ulong           data, len;
+       int             verify;
+       int             part = 0;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       ulong           count;
+       image_header_t  *hdr = NULL;
+#endif
+#if defined(CONFIG_FIT)
+       const char      *uname = NULL;
+       const void*     fit_hdr;
+       int             noffset;
+       const void      *fit_data;
+       size_t          fit_len;
+#endif
+#ifdef CONFIG_GZIP
+       uint            unc_len = CONFIG_SYS_XIMG_LEN;
+#endif
+       uint8_t         comp;
+
+       verify = getenv_yesno("verify");
+
+       if (argc > 1) {
+               addr = simple_strtoul(argv[1], NULL, 16);
+       }
+       if (argc > 2) {
+               part = simple_strtoul(argv[2], NULL, 16);
+#if defined(CONFIG_FIT)
+               uname = argv[2];
+#endif
+       }
+       if (argc > 3) {
+               dest = simple_strtoul(argv[3], NULL, 16);
+       }
+
+       switch (genimg_get_format((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       case IMAGE_FORMAT_LEGACY:
+
+               printf("## Copying part %d from legacy image "
+                       "at %08lx ...\n", part, addr);
+
+               hdr = (image_header_t *)addr;
+               if (!image_check_magic(hdr)) {
+                       printf("Bad Magic Number\n");
+                       return 1;
+               }
+
+               if (!image_check_hcrc(hdr)) {
+                       printf("Bad Header Checksum\n");
+                       return 1;
+               }
+#ifdef DEBUG
+               image_print_contents(hdr);
+#endif
+
+               if (!image_check_type(hdr, IH_TYPE_MULTI) &&
+                   !image_check_type(hdr, IH_TYPE_SCRIPT)) {
+                       printf("Wrong Image Type for %s command\n",
+                                       cmdtp->name);
+                       return 1;
+               }
+
+               comp = image_get_comp(hdr);
+               if ((comp != IH_COMP_NONE) && (argc < 4)) {
+                       printf("Must specify load address for %s command "
+                                       "with compressed image\n",
+                                       cmdtp->name);
+                       return 1;
+               }
+
+               if (verify) {
+                       printf("   Verifying Checksum ... ");
+                       if (!image_check_dcrc(hdr)) {
+                               printf("Bad Data CRC\n");
+                               return 1;
+                       }
+                       printf("OK\n");
+               }
+
+               count = image_multi_count(hdr);
+               if (part >= count) {
+                       printf("Bad Image Part\n");
+                       return 1;
+               }
+
+               image_multi_getimg(hdr, part, &data, &len);
+               break;
+#endif
+#if defined(CONFIG_FIT)
+       case IMAGE_FORMAT_FIT:
+               if (uname == NULL) {
+                       puts("No FIT subimage unit name\n");
+                       return 1;
+               }
+
+               printf("## Copying '%s' subimage from FIT image "
+                       "at %08lx ...\n", uname, addr);
+
+               fit_hdr = (const void *)addr;
+               if (!fit_check_format(fit_hdr)) {
+                       puts("Bad FIT image format\n");
+                       return 1;
+               }
+
+               /* get subimage node offset */
+               noffset = fit_image_get_node(fit_hdr, uname);
+               if (noffset < 0) {
+                       printf("Can't find '%s' FIT subimage\n", uname);
+                       return 1;
+               }
+
+               if (fit_image_check_comp(fit_hdr, noffset, IH_COMP_NONE)
+                   && (argc < 4)) {
+                       printf("Must specify load address for %s command "
+                               "with compressed image\n",
+                               cmdtp->name);
+                       return 1;
+               }
+
+               /* verify integrity */
+               if (verify) {
+                       if (!fit_image_verify(fit_hdr, noffset)) {
+                               puts("Bad Data Hash\n");
+                               return 1;
+                       }
+               }
+
+               /* get subimage data address and length */
+               if (fit_image_get_data(fit_hdr, noffset,
+                                       &fit_data, &fit_len)) {
+                       puts("Could not find script subimage data\n");
+                       return 1;
+               }
+
+               if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
+                       puts("Could not find script subimage "
+                               "compression type\n");
+                       return 1;
+               }
+
+               data = (ulong)fit_data;
+               len = (ulong)fit_len;
+               break;
+#endif
+       default:
+               puts("Invalid image type for imxtract\n");
+               return 1;
+       }
+
+       if (argc > 3) {
+               switch (comp) {
+               case IH_COMP_NONE:
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+                       {
+                               size_t l = len;
+                               size_t tail;
+                               void *to = (void *) dest;
+                               void *from = (void *)data;
+
+                               printf("   Loading part %d ... ", part);
+
+                               while (l > 0) {
+                                       tail = (l > CHUNKSZ) ? CHUNKSZ : l;
+                                       WATCHDOG_RESET();
+                                       memmove(to, from, tail);
+                                       to += tail;
+                                       from += tail;
+                                       l -= tail;
+                               }
+                       }
+#else  /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
+                       printf("   Loading part %d ... ", part);
+                       memmove((char *) dest, (char *)data, len);
+#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
+                       break;
+#ifdef CONFIG_GZIP
+               case IH_COMP_GZIP:
+                       printf("   Uncompressing part %d ... ", part);
+                       if (gunzip((void *) dest, unc_len,
+                                  (uchar *) data, &len) != 0) {
+                               puts("GUNZIP ERROR - image not loaded\n");
+                               return 1;
+                       }
+                       break;
+#endif
+#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY)
+               case IH_COMP_BZIP2:
+                       {
+                               int i;
+
+                               printf("   Uncompressing part %d ... ", part);
+                               /*
+                                * If we've got less than 4 MB of malloc()
+                                * space, use slower decompression algorithm
+                                * which requires at most 2300 KB of memory.
+                                */
+                               i = BZ2_bzBuffToBuffDecompress(
+                                       map_sysmem(ntohl(hdr->ih_load), 0),
+                                       &unc_len, (char *)data, len,
+                                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024),
+                                       0);
+                               if (i != BZ_OK) {
+                                       printf("BUNZIP2 ERROR %d - "
+                                               "image not loaded\n", i);
+                                       return 1;
+                               }
+                       }
+                       break;
+#endif /* CONFIG_BZIP2 */
+               default:
+                       printf("Unimplemented compression type %d\n", comp);
+                       return 1;
+               }
+               puts("OK\n");
+       }
+
+       flush_cache(dest, len);
+
+       setenv_hex("fileaddr", data);
+       setenv_hex("filesize", len);
+
+       return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char imgextract_help_text[] =
+       "addr part [dest]\n"
+       "    - extract <part> from legacy image at <addr> and copy to <dest>"
+#if defined(CONFIG_FIT)
+       "\n"
+       "addr uname [dest]\n"
+       "    - extract <uname> subimage from FIT image at <addr> and copy to <dest>"
+#endif
+       "";
+#endif
+
+U_BOOT_CMD(
+       imxtract, 4, 1, do_imgextract,
+       "extract a part of a multi-image", imgextract_help_text
+);
diff --git a/cmd/yaffs2.c b/cmd/yaffs2.c
new file mode 100644 (file)
index 0000000..9244606
--- /dev/null
@@ -0,0 +1,326 @@
+/* Yaffs commands.
+ * Modified by Charles Manning by adding ydevconfig command.
+ *
+ * Use ydevconfig to configure a mountpoint before use.
+ * For example:
+ *  # Configure mountpt xxx using nand device 0 using blocks 100-500
+ *  ydevconfig xxx 0 100 500
+ *  # Mount it
+ *  ymount xxx
+ *  # yls, yrdm etc
+ *  yls -l xxx
+ *  yrdm xxx/boot-image 82000000
+ *  ...
+ */
+
+#include <common.h>
+
+#include <config.h>
+#include <command.h>
+
+#ifdef YAFFS2_DEBUG
+#define PRINTF(fmt, args...) printf(fmt, ##args)
+#else
+#define PRINTF(fmt, args...) do { } while (0)
+#endif
+
+extern void cmd_yaffs_dev_ls(void);
+extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
+extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
+                               int start_block, int end_block);
+extern void cmd_yaffs_mount(char *mp);
+extern void cmd_yaffs_umount(char *mp);
+extern void cmd_yaffs_read_file(char *fn);
+extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
+extern void cmd_yaffs_ls(const char *mountpt, int longlist);
+extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
+extern void cmd_yaffs_mread_file(char *fn, char *addr);
+extern void cmd_yaffs_mkdir(const char *dir);
+extern void cmd_yaffs_rmdir(const char *dir);
+extern void cmd_yaffs_rm(const char *path);
+extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
+
+extern int yaffs_dump_dev(const char *path);
+
+/* ytrace - show/set yaffs trace mask */
+int do_ytrace(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       if (argc > 1)
+               cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
+       else
+               cmd_yaffs_tracemask(0, 0);
+
+       return 0;
+}
+
+/* ydevls - lists yaffs mount points. */
+int do_ydevls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       cmd_yaffs_dev_ls();
+
+       return 0;
+}
+
+/* ydevconfig mount_pt mtd_dev_num start_block end_block */
+int do_ydevconfig(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *mtpoint;
+       int mtd_dev;
+       int start_block;
+       int end_block;
+
+       if (argc != 5) {
+               printf
+                   ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
+               return -1;
+       }
+
+       mtpoint = argv[1];
+       mtd_dev = simple_strtol(argv[2], NULL, 16);
+       start_block = simple_strtol(argv[3], NULL, 16);
+       end_block = simple_strtol(argv[4], NULL, 16);
+
+       cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
+
+       return 0;
+}
+
+int do_ymount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *mtpoint;
+
+       if (argc != 2) {
+               printf("Bad arguments: ymount mount_pt\n");
+               return -1;
+       }
+
+       mtpoint = argv[1];
+       printf("Mounting yaffs2 mount point %s\n", mtpoint);
+
+       cmd_yaffs_mount(mtpoint);
+
+       return 0;
+}
+
+int do_yumount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *mtpoint;
+
+       if (argc != 2) {
+               printf("Bad arguments: yumount mount_pt\n");
+               return -1;
+       }
+
+       mtpoint = argv[1];
+       printf("Unmounting yaffs2 mount point %s\n", mtpoint);
+       cmd_yaffs_umount(mtpoint);
+
+       return 0;
+}
+
+int do_yls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *dirname;
+
+       if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
+               printf("Bad arguments: yls [-l] dir\n");
+               return -1;
+       }
+
+       dirname = argv[argc - 1];
+
+       cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
+
+       return 0;
+}
+
+int do_yrd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *filename;
+
+       if (argc != 2) {
+               printf("Bad arguments: yrd file_name\n");
+               return -1;
+       }
+
+       filename = argv[1];
+
+       printf("Reading file %s ", filename);
+
+       cmd_yaffs_read_file(filename);
+
+       printf("done\n");
+       return 0;
+}
+
+int do_ywr(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *filename;
+       ulong value;
+       ulong numValues;
+
+       if (argc != 4) {
+               printf("Bad arguments: ywr file_name value n_values\n");
+               return -1;
+       }
+
+       filename = argv[1];
+       value = simple_strtoul(argv[2], NULL, 16);
+       numValues = simple_strtoul(argv[3], NULL, 16);
+
+       printf("Writing value (%lx) %lx times to %s... ", value, numValues,
+              filename);
+
+       cmd_yaffs_write_file(filename, value, numValues);
+
+       printf("done\n");
+       return 0;
+}
+
+int do_yrdm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *filename;
+       ulong addr;
+
+       if (argc != 3) {
+               printf("Bad arguments: yrdm file_name addr\n");
+               return -1;
+       }
+
+       filename = argv[1];
+       addr = simple_strtoul(argv[2], NULL, 16);
+
+       cmd_yaffs_mread_file(filename, (char *)addr);
+
+       return 0;
+}
+
+int do_ywrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *filename;
+       ulong addr;
+       ulong size;
+
+       if (argc != 4) {
+               printf("Bad arguments: ywrm file_name addr size\n");
+               return -1;
+       }
+
+       filename = argv[1];
+       addr = simple_strtoul(argv[2], NULL, 16);
+       size = simple_strtoul(argv[3], NULL, 16);
+
+       cmd_yaffs_mwrite_file(filename, (char *)addr, size);
+
+       return 0;
+}
+
+int do_ymkdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *dirname;
+
+       if (argc != 2) {
+               printf("Bad arguments: ymkdir dir_name\n");
+               return -1;
+       }
+
+       dirname = argv[1];
+       cmd_yaffs_mkdir(dirname);
+
+       return 0;
+}
+
+int do_yrmdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *dirname;
+
+       if (argc != 2) {
+               printf("Bad arguments: yrmdir dir_name\n");
+               return -1;
+       }
+
+       dirname = argv[1];
+       cmd_yaffs_rmdir(dirname);
+
+       return 0;
+}
+
+int do_yrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *name;
+
+       if (argc != 2) {
+               printf("Bad arguments: yrm name\n");
+               return -1;
+       }
+
+       name = argv[1];
+
+       cmd_yaffs_rm(name);
+
+       return 0;
+}
+
+int do_ymv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       char *oldPath;
+       char *newPath;
+
+       if (argc != 3) {
+               printf("Bad arguments: ymv old_path new_path\n");
+               return -1;
+       }
+
+       oldPath = argv[1];
+       newPath = argv[2];
+
+       cmd_yaffs_mv(newPath, oldPath);
+
+       return 0;
+}
+
+U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
+          "show/set yaffs trace mask",
+          "[new_mask]  show/set yaffs trace mask");
+
+U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
+          "list yaffs mount points", "list yaffs mount points");
+
+U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
+          "configure yaffs mount point",
+          "mtpoint mtd_id start_block end_block   configures a yaffs2 mount point");
+
+U_BOOT_CMD(ymount, 2, 0, do_ymount,
+          "mount yaffs", "mtpoint  mounts a yaffs2 mount point");
+
+U_BOOT_CMD(yumount, 2, 0, do_yumount,
+          "unmount yaffs", "mtpoint  unmounts a yaffs2 mount point");
+
+U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
+
+U_BOOT_CMD(yrd, 2, 0, do_yrd,
+          "read file from yaffs", "path   read file from yaffs");
+
+U_BOOT_CMD(ywr, 4, 0, do_ywr,
+          "write file to yaffs",
+          "filename value num_vlues   write values to yaffs file");
+
+U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
+          "read file to memory from yaffs",
+          "filename offset    reads yaffs file into memory");
+
+U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
+          "write file from memory to yaffs",
+          "filename offset size  writes memory to yaffs file");
+
+U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
+          "YAFFS mkdir", "dir    create a yaffs directory");
+
+U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
+          "YAFFS rmdir", "dirname   removes a yaffs directory");
+
+U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path   removes a yaffs file");
+
+U_BOOT_CMD(ymv, 4, 0, do_ymv,
+          "YAFFS mv",
+          "old_path new_path   moves/rename files within a yaffs mount point");
diff --git a/cmd/zfs.c b/cmd/zfs.c
new file mode 100644 (file)
index 0000000..0aed29e
--- /dev/null
+++ b/cmd/zfs.c
@@ -0,0 +1,171 @@
+/*
+ *
+ * ZFS filesystem porting to Uboot by
+ * Jorgen Lundman <lundman at lundman.net>
+ *
+ * zfsfs support
+ * made from existing GRUB Sources by Sun, GNU and others.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <part.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <zfs_common.h>
+#include <linux/stat.h>
+#include <malloc.h>
+
+#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
+#include <usb.h>
+#endif
+
+#if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
+#error DOS or EFI partition support must be selected
+#endif
+
+#define DOS_PART_MAGIC_OFFSET  0x1fe
+#define DOS_FS_TYPE_OFFSET     0x36
+#define DOS_FS32_TYPE_OFFSET   0x52
+
+static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char *filename = NULL;
+       int dev;
+       int part;
+       ulong addr = 0;
+       disk_partition_t info;
+       block_dev_desc_t *dev_desc;
+       char buf[12];
+       unsigned long count;
+       const char *addr_str;
+       struct zfs_file zfile;
+       struct device_s vdev;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       count = 0;
+       addr = simple_strtoul(argv[3], NULL, 16);
+       filename = getenv("bootfile");
+       switch (argc) {
+       case 3:
+               addr_str = getenv("loadaddr");
+               if (addr_str != NULL)
+                       addr = simple_strtoul(addr_str, NULL, 16);
+               else
+                       addr = CONFIG_SYS_LOAD_ADDR;
+
+               break;
+       case 4:
+               break;
+       case 5:
+               filename = argv[4];
+               break;
+       case 6:
+               filename = argv[4];
+               count = simple_strtoul(argv[5], NULL, 16);
+               break;
+
+       default:
+               return cmd_usage(cmdtp);
+       }
+
+       if (!filename) {
+               puts("** No boot file defined **\n");
+               return 1;
+       }
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       dev = dev_desc->dev;
+       printf("Loading file \"%s\" from %s device %d%c%c\n",
+               filename, argv[1], dev,
+               part ? ':' : ' ', part ? part + '0' : ' ');
+
+       zfs_set_blk_dev(dev_desc, &info);
+       vdev.part_length = info.size;
+
+       memset(&zfile, 0, sizeof(zfile));
+       zfile.device = &vdev;
+       if (zfs_open(&zfile, filename)) {
+               printf("** File not found %s **\n", filename);
+               return 1;
+       }
+
+       if ((count < zfile.size) && (count != 0))
+               zfile.size = (uint64_t)count;
+
+       if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
+               printf("** Unable to read \"%s\" from %s %d:%d **\n",
+                          filename, argv[1], dev, part);
+               zfs_close(&zfile);
+               return 1;
+       }
+
+       zfs_close(&zfile);
+
+       /* Loading ok, update default load address */
+       load_addr = addr;
+
+       printf("%llu bytes read\n", zfile.size);
+       setenv_hex("filesize", zfile.size);
+
+       return 0;
+}
+
+
+int zfs_print(const char *entry, const struct zfs_dirhook_info *data)
+{
+       printf("%s %s\n",
+                  data->dir ? "<DIR> " : "              ",
+                  entry);
+       return 0; /* 0 continue, 1 stop */
+}
+
+
+
+static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *filename = "/";
+       int part;
+       block_dev_desc_t *dev_desc;
+       disk_partition_t info;
+       struct device_s vdev;
+
+       if (argc < 2)
+               return cmd_usage(cmdtp);
+
+       if (argc == 4)
+               filename = argv[3];
+
+       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+       if (part < 0)
+               return 1;
+
+       zfs_set_blk_dev(dev_desc, &info);
+       vdev.part_length = info.size;
+
+       zfs_ls(&vdev, filename,
+                  zfs_print);
+
+       return 0;
+}
+
+
+U_BOOT_CMD(zfsls, 4, 1, do_zfs_ls,
+                  "list files in a directory (default /)",
+                  "<interface> <dev[:part]> [directory]\n"
+                  "      - list files from 'dev' on 'interface' in a '/DATASET/@/$dir/'");
+
+U_BOOT_CMD(zfsload, 6, 0, do_zfs_load,
+                  "load binary file from a ZFS filesystem",
+                  "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
+                  "      - load binary file '/DATASET/@/$dir/$file' from 'dev' on 'interface'\n"
+                  "             to address 'addr' from ZFS filesystem");
diff --git a/cmd/zip.c b/cmd/zip.c
new file mode 100644 (file)
index 0000000..7fcd9d5
--- /dev/null
+++ b/cmd/zip.c
@@ -0,0 +1,42 @@
+/*
+ * (C) Copyright 2012
+ * Lei Wen <leiwen@marvell.com>, Marvell Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long src, dst;
+       unsigned long src_len, dst_len = ~0UL;
+
+       switch (argc) {
+               case 5:
+                       dst_len = simple_strtoul(argv[4], NULL, 16);
+                       /* fall through */
+               case 4:
+                       src = simple_strtoul(argv[1], NULL, 16);
+                       src_len = simple_strtoul(argv[2], NULL, 16);
+                       dst = simple_strtoul(argv[3], NULL, 16);
+                       break;
+               default:
+                       return cmd_usage(cmdtp);
+       }
+
+       if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0)
+               return 1;
+
+       printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len);
+       setenv_hex("filesize", dst_len);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       zip,    5,      1,      do_zip,
+       "zip a memory region",
+       "srcaddr srcsize dstaddr [dstsize]"
+);
index 9d446bf86b01116956d5b612047c23be738cbc8a..067545d8a3ea24ae8cea6763d7243ae0ebddc21b 100644 (file)
@@ -1,522 +1,3 @@
-menu "Command line interface"
-
-config HUSH_PARSER
-       bool "Use hush shell"
-       select SYS_HUSH_PARSER
-       help
-         This option enables the "hush" shell (from Busybox) as command line
-         interpreter, thus enabling powerful command line syntax like
-         if...then...else...fi conditionals or `&&' and '||'
-         constructs ("shell scripts").
-
-         If disabled, you get the old, much simpler behaviour with a somewhat
-         smaller memory footprint.
-
-config SYS_HUSH_PARSER
-       bool
-       help
-         Backward compatibility.
-
-config SYS_PROMPT
-       string "Shell prompt"
-       default "=> "
-       help
-         This string is displayed in the command line to the left of the
-         cursor.
-
-menu "Autoboot options"
-
-config AUTOBOOT_KEYED
-       bool "Stop autobooting via specific input key / string"
-       default n
-       help
-         This option enables stopping (aborting) of the automatic
-         boot feature only by issuing a specific input key or
-         string. If not enabled, any input key will abort the
-         U-Boot automatic booting process and bring the device
-         to the U-Boot prompt for user input.
-
-config AUTOBOOT_PROMPT
-       string "Autoboot stop prompt"
-       depends on AUTOBOOT_KEYED
-       default "Autoboot in %d seconds\\n"
-       help
-         This string is displayed before the boot delay selected by
-         CONFIG_BOOTDELAY starts. If it is not defined there is no
-         output indicating that autoboot is in progress.
-
-         Note that this define is used as the (only) argument to a
-         printf() call, so it may contain '%' format specifications,
-         provided that it also includes, sepearated by commas exactly
-         like in a printf statement, the required arguments. It is
-         the responsibility of the user to select only such arguments
-         that are valid in the given context.
-
-config AUTOBOOT_ENCRYPTION
-       bool "Enable encryption in autoboot stopping"
-       depends on AUTOBOOT_KEYED
-       default n
-
-config AUTOBOOT_DELAY_STR
-       string "Delay autobooting via specific input key / string"
-       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
-       help
-         This option delays the automatic boot feature by issuing
-         a specific input key or string. If CONFIG_AUTOBOOT_DELAY_STR
-         or the environment variable "bootdelaykey" is specified
-         and this string is received from console input before
-         autoboot starts booting, U-Boot gives a command prompt. The
-         U-Boot prompt will time out if CONFIG_BOOT_RETRY_TIME is
-         used, otherwise it never times out.
-
-config AUTOBOOT_STOP_STR
-       string "Stop autobooting via specific input key / string"
-       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
-       help
-         This option enables stopping (aborting) of the automatic
-         boot feature only by issuing a specific input key or
-         string. If CONFIG_AUTOBOOT_STOP_STR or the environment
-         variable "bootstopkey" is specified and this string is
-         received from console input before autoboot starts booting,
-         U-Boot gives a command prompt. The U-Boot prompt never
-         times out, even if CONFIG_BOOT_RETRY_TIME is used.
-
-config AUTOBOOT_KEYED_CTRLC
-       bool "Enable Ctrl-C autoboot interruption"
-       depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
-       default n
-       help
-         This option allows for the boot sequence to be interrupted
-         by ctrl-c, in addition to the "bootdelaykey" and "bootstopkey".
-         Setting this variable provides an escape sequence from the
-         limited "password" strings.
-
-config AUTOBOOT_STOP_STR_SHA256
-       string "Stop autobooting via SHA256 encrypted password"
-       depends on AUTOBOOT_KEYED && AUTOBOOT_ENCRYPTION
-       help
-         This option adds the feature to only stop the autobooting,
-         and therefore boot into the U-Boot prompt, when the input
-         string / password matches a values that is encypted via
-         a SHA256 hash and saved in the environment.
-
-endmenu
-
-comment "Commands"
-
-menu "Info commands"
-
-config CMD_BDI
-       bool "bdinfo"
-       default y
-       help
-         Print board info
-
-config CMD_CONSOLE
-       bool "coninfo"
-       default y
-       help
-         Print console devices and information.
-
-config CMD_CPU
-       bool "cpu"
-       help
-         Print information about available CPUs. This normally shows the
-         number of CPUs, type (e.g. manufacturer, architecture, product or
-         internal name) and clock frequency. Other information may be
-         available depending on the CPU driver.
-
-config CMD_LICENSE
-       bool "license"
-       help
-         Print GPL license text
-
-endmenu
-
-menu "Boot commands"
-
-config CMD_BOOTD
-       bool "bootd"
-       default y
-       help
-         Run the command stored in the environment "bootcmd", i.e.
-         "bootd" does the same thing as "run bootcmd".
-
-config CMD_BOOTM
-       bool "bootm"
-       default y
-       help
-         Boot an application image from the memory.
-
-config CMD_ELF
-       bool "bootelf, bootvx"
-       default y
-       help
-         Boot an ELF/vxWorks image from the memory.
-
-config CMD_GO
-       bool "go"
-       default y
-       help
-         Start an application at a given address.
-
-config CMD_RUN
-       bool "run"
-       default y
-       help
-         Run the command in the given environment variable.
-
-config CMD_IMI
-       bool "iminfo"
-       default y
-       help
-         Print header information for application image.
-
-config CMD_IMLS
-       bool "imls"
-       default y
-       help
-         List all images found in flash
-
-config CMD_XIMG
-       bool "imxtract"
-       default y
-       help
-         Extract a part of a multi-image.
-
-config CMD_POWEROFF
-       bool
-
-endmenu
-
-menu "Environment commands"
-
-config CMD_EXPORTENV
-       bool "env export"
-       default y
-       help
-         Export environments.
-
-config CMD_IMPORTENV
-       bool "env import"
-       default y
-       help
-         Import environments.
-
-config CMD_EDITENV
-       bool "editenv"
-       default y
-       help
-         Edit environment variable.
-
-config CMD_SAVEENV
-       bool "saveenv"
-       default y
-       help
-         Save all environment variables into the compiled-in persistent
-         storage.
-
-config CMD_ENV_EXISTS
-       bool "env exists"
-       default y
-       help
-         Check if a variable is defined in the environment for use in
-         shell scripting.
-
-endmenu
-
-menu "Memory commands"
-
-config CMD_MEMORY
-       bool "md, mm, nm, mw, cp, cmp, base, loop"
-       default y
-       help
-         Memeory commands.
-           md - memory display
-           mm - memory modify (auto-incrementing address)
-           nm - memory modify (constant address)
-           mw - memory write (fill)
-           cp - memory copy
-           cmp - memory compare
-           base - print or set address offset
-           loop - initinite loop on address range
-
-config CMD_CRC32
-       bool "crc32"
-       default y
-       help
-         Compute CRC32.
-
-config LOOPW
-       bool "loopw"
-       help
-         Infinite write loop on address range
-
-config CMD_MEMTEST
-       bool "memtest"
-       help
-         Simple RAM read/write test.
-
-config CMD_MX_CYCLIC
-       bool "mdc, mwc"
-       help
-         mdc - memory display cyclic
-         mwc - memory write cyclic
-
-config CMD_MEMINFO
-       bool "meminfo"
-       help
-         Display memory information.
-
-endmenu
-
-menu "Device access commands"
-
-config CMD_DM
-       bool "dm - Access to driver model information"
-       depends on DM
-       default y
-       help
-         Provides access to driver model data structures and information,
-         such as a list of devices, list of uclasses and the state of each
-         device (e.g. activated). This is not required for operation, but
-         can be useful to see the state of driver model for debugging or
-         interest.
-
-config CMD_DEMO
-       bool "demo - Demonstration commands for driver model"
-       depends on DM
-       help
-         Provides a 'demo' command which can be used to play around with
-         driver model. To use this properly you will need to enable one or
-         both of the demo devices (DM_DEMO_SHAPE and DM_DEMO_SIMPLE).
-         Otherwise you will always get an empty list of devices. The demo
-         devices are defined in the sandbox device tree, so the easiest
-         option is to use sandbox and pass the -d point to sandbox's
-         u-boot.dtb file.
-
-config CMD_LOADB
-       bool "loadb"
-       default y
-       help
-         Load a binary file over serial line.
-
-config CMD_LOADS
-       bool "loads"
-       default y
-       help
-         Load an S-Record file over serial line
-
-config CMD_FLASH
-       bool "flinfo, erase, protect"
-       default y
-       help
-         NOR flash support.
-           flinfo - print FLASH memory information
-           erase - FLASH memory
-           protect - enable or disable FLASH write protection
-
-config CMD_ARMFLASH
-       depends on FLASH_CFI_DRIVER
-       bool "armflash"
-       help
-         ARM Ltd reference designs flash partition access
-
-config CMD_NAND
-       bool "nand"
-       help
-         NAND support.
-
-config CMD_SF
-       bool "sf"
-       help
-         SPI Flash support
-
-config CMD_SPI
-       bool "sspi"
-       help
-         SPI utility command.
-
-config CMD_I2C
-       bool "i2c"
-       help
-         I2C support.
-
-config CMD_USB
-       bool "usb"
-       help
-         USB support.
-
-config CMD_FPGA
-       bool "fpga"
-       default y
-       help
-         FPGA support.
-
-config CMD_REMOTEPROC
-       bool "remoteproc"
-       depends on REMOTEPROC
-       help
-         Support for Remote Processor control
-
-config CMD_GPIO
-       bool "gpio"
-       help
-         GPIO support.
-
-endmenu
-
-
-menu "Shell scripting commands"
-
-config CMD_ECHO
-       bool "echo"
-       default y
-       help
-         Echo args to console
-
-config CMD_ITEST
-       bool "itest"
-       default y
-       help
-         Return true/false on integer compare.
-
-config CMD_SOURCE
-       bool "source"
-       default y
-       help
-         Run script from memory
-
-config CMD_SETEXPR
-       bool "setexpr"
-       default y
-       help
-         Evaluate boolean and math expressions and store the result in an env
-           variable.
-         Also supports loading the value at a memory location into a variable.
-         If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
-
-endmenu
-
-menu "Network commands"
-
-config CMD_NET
-       bool "bootp, tftpboot"
-        select NET
-       default y
-       help
-         Network commands.
-         bootp - boot image via network using BOOTP/TFTP protocol
-         tftpboot - boot image via network using TFTP protocol
-
-config CMD_TFTPPUT
-       bool "tftp put"
-       help
-         TFTP put command, for uploading files to a server
-
-config CMD_TFTPSRV
-       bool "tftpsrv"
-       help
-         Act as a TFTP server and boot the first received file
-
-config CMD_RARP
-       bool "rarpboot"
-       help
-         Boot image via network using RARP/TFTP protocol
-
-config CMD_DHCP
-       bool "dhcp"
-       help
-         Boot image via network using DHCP/TFTP protocol
-
-config CMD_NFS
-       bool "nfs"
-       default y
-       help
-         Boot image via network using NFS protocol.
-
-config CMD_PING
-       bool "ping"
-       help
-         Send ICMP ECHO_REQUEST to network host
-
-config CMD_CDP
-       bool "cdp"
-       help
-         Perform CDP network configuration
-
-config CMD_SNTP
-       bool "sntp"
-       help
-         Synchronize RTC via network
-
-config CMD_DNS
-       bool "dns"
-       help
-         Lookup the IP of a hostname
-
-config CMD_LINK_LOCAL
-       bool "linklocal"
-       help
-         Acquire a network IP address using the link-local protocol
-
-endmenu
-
-menu "Misc commands"
-
-config CMD_AMBAPP
-       bool "ambapp"
-       depends on LEON3
-       default y
-       help
-         Lists AMBA Plug-n-Play information.
-
-config SYS_AMBAPP_PRINT_ON_STARTUP
-       bool "Show AMBA PnP info on startup"
-       depends on CMD_AMBAPP
-       default n
-       help
-         Show AMBA Plug-n-Play information on startup.
-
-config CMD_TIME
-       bool "time"
-       help
-         Run commands and summarize execution time.
-
-# TODO: rename to CMD_SLEEP
-config CMD_MISC
-       bool "sleep"
-       default y
-       help
-         Delay execution for some time
-
-config CMD_TIMER
-       bool "timer"
-       help
-         Access the system timer.
-
-config CMD_SETGETDCR
-       bool "getdcr, setdcr, getidcr, setidcr"
-       depends on 4xx
-       default y
-       help
-         getdcr - Get an AMCC PPC 4xx DCR's value
-         setdcr - Set an AMCC PPC 4xx DCR's value
-         getidcr - Get a register value via indirect DCR addressing
-         setidcr - Set a register value via indirect DCR addressing
-
-config CMD_SOUND
-       bool "sound"
-       depends on SOUND
-       help
-         This provides basic access to the U-Boot's sound support. The main
-         feature is to play a beep.
-
-            sound init   - set up sound system
-            sound play   - play a sound
-
-endmenu
-
 menu "Boot timing"
 
 config BOOTSTAGE
@@ -565,13 +46,6 @@ config BOOTSTAGE_USER_COUNT
          a new ID will be allocated from this stash. If you exceed
          the limit, recording will stop.
 
-config CMD_BOOTSTAGE
-       bool "Enable the 'bootstage' command"
-       depends on BOOTSTAGE
-       help
-         Add a 'bootstage' command which supports printing a report
-         and un/stashing of bootstage data.
-
 config BOOTSTAGE_FDT
        bool "Store boot timing information in the OS device tree"
        depends on BOOTSTAGE
@@ -623,66 +97,6 @@ config BOOTSTAGE_STASH_SIZE
 
 endmenu
 
-menu "Power commands"
-config CMD_PMIC
-       bool "Enable Driver Model PMIC command"
-       depends on DM_PMIC
-       help
-         This is the pmic command, based on a driver model pmic's API.
-         Command features are unchanged:
-         - list               - list pmic devices
-         - pmic dev <id>      - show or [set] operating pmic device (NEW)
-         - pmic dump          - dump registers
-         - pmic read address  - read byte of register at address
-         - pmic write address - write byte to register at address
-         The only one change for this command is 'dev' subcommand.
-
-config CMD_REGULATOR
-       bool "Enable Driver Model REGULATOR command"
-       depends on DM_REGULATOR
-       help
-         This command is based on driver model regulator's API.
-         User interface features:
-         - list               - list regulator devices
-         - regulator dev <id> - show or [set] operating regulator device
-         - regulator info     - print constraints info
-         - regulator status   - print operating status
-         - regulator value <val] <-f> - print/[set] voltage value [uV]
-         - regulator current <val>    - print/[set] current value [uA]
-         - regulator mode <id>        - print/[set] operating mode id
-         - regulator enable           - enable the regulator output
-         - regulator disable          - disable the regulator output
-
-         The '-f' (force) option can be used for set the value which exceeds
-         the limits, which are found in device-tree and are kept in regulator's
-         uclass platdata structure.
-
-endmenu
-
-menu "Security commands"
-config CMD_TPM
-       bool "Enable the 'tpm' command"
-       depends on TPM
-       help
-         This provides a means to talk to a TPM from the command line. A wide
-         range of commands if provided - see 'tpm help' for details. The
-         command requires a suitable TPM on your board and the correct driver
-         must be enabled.
-
-config CMD_TPM_TEST
-       bool "Enable the 'tpm test' command"
-       depends on CMD_TPM
-       help
-         This provides a a series of tests to confirm that the TPM is working
-         correctly. The tests cover initialisation, non-volatile RAM, extend,
-         global lock and checking that timing is within expectations. The
-         tests pass correctly on Infineon TPMs but may need to be adjusted
-         for other devices.
-
-endmenu
-
-endmenu
-
 config CONSOLE_RECORD
        bool "Console recording"
        help
index 249227597af6f0bb3254c7605a5bc8ce45e37aa3..59984111e18b4b5bc49b5cd044f9858fd5a02a02 100644 (file)
@@ -31,11 +31,7 @@ obj-$(CONFIG_SYS_GENERIC_BOARD) += board_r.o
 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
 
-# core command
-obj-y += cmd_boot.o
-obj-$(CONFIG_CMD_BOOTM) += cmd_bootm.o bootm.o bootm_os.o
-obj-y += cmd_help.o
-obj-y += cmd_version.o
+obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
 
 # environment
 obj-y += env_attr.o
@@ -58,143 +54,17 @@ obj-$(CONFIG_ENV_IS_IN_REMOTE) += env_remote.o
 obj-$(CONFIG_ENV_IS_IN_UBI) += env_ubi.o
 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
 
-# command
-obj-$(CONFIG_CMD_AES) += cmd_aes.o
-obj-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o
-obj-$(CONFIG_CMD_ARMFLASH) += cmd_armflash.o
-obj-$(CONFIG_SOURCE) += cmd_source.o
-obj-$(CONFIG_CMD_SOURCE) += cmd_source.o
-obj-$(CONFIG_CMD_BDI) += cmd_bdinfo.o
-obj-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
-obj-$(CONFIG_CMD_BMP) += cmd_bmp.o
-obj-$(CONFIG_CMD_BOOTMENU) += cmd_bootmenu.o
-obj-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
-obj-$(CONFIG_CMD_BOOTSTAGE) += cmd_bootstage.o
-obj-$(CONFIG_CMD_CACHE) += cmd_cache.o
-obj-$(CONFIG_CMD_CBFS) += cmd_cbfs.o
-obj-$(CONFIG_CMD_CLK) += cmd_clk.o
-obj-$(CONFIG_CMD_CONSOLE) += cmd_console.o
-obj-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o
-obj-$(CONFIG_CMD_CPU) += cmd_cpu.o
-obj-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o
-obj-$(CONFIG_CMD_DATE) += cmd_date.o
-obj-$(CONFIG_CMD_DEMO) += cmd_demo.o
-obj-$(CONFIG_CMD_SOUND) += cmd_sound.o
-ifdef CONFIG_4xx
-obj-$(CONFIG_CMD_SETGETDCR) += cmd_dcr.o
-endif
-ifdef CONFIG_POST
-obj-$(CONFIG_CMD_DIAG) += cmd_diag.o
-endif
-obj-$(CONFIG_CMD_DISPLAY) += cmd_display.o
-obj-$(CONFIG_CMD_DTT) += cmd_dtt.o
-obj-$(CONFIG_CMD_ECHO) += cmd_echo.o
-obj-$(CONFIG_ENV_IS_IN_EEPROM) += cmd_eeprom.o
-obj-$(CONFIG_CMD_EEPROM) += cmd_eeprom.o
-obj-$(CONFIG_EFI_STUB) += cmd_efi.o
-obj-$(CONFIG_CMD_ELF) += cmd_elf.o
-obj-$(CONFIG_SYS_HUSH_PARSER) += cmd_exit.o
-obj-$(CONFIG_CMD_EXT4) += cmd_ext4.o
-obj-$(CONFIG_CMD_EXT2) += cmd_ext2.o
-obj-$(CONFIG_CMD_FAT) += cmd_fat.o
-obj-$(CONFIG_CMD_FDC) += cmd_fdc.o
-obj-$(CONFIG_OF_LIBFDT) += cmd_fdt.o fdt_support.o
-obj-$(CONFIG_CMD_FITUPD) += cmd_fitupd.o
-obj-$(CONFIG_CMD_FLASH) += cmd_flash.o
-ifdef CONFIG_FPGA
-obj-$(CONFIG_CMD_FPGA) += cmd_fpga.o
-endif
-obj-$(CONFIG_CMD_FPGAD) += cmd_fpgad.o
-obj-$(CONFIG_CMD_FS_GENERIC) += cmd_fs.o
-obj-$(CONFIG_CMD_FUSE) += cmd_fuse.o
-obj-$(CONFIG_CMD_GETTIME) += cmd_gettime.o
-obj-$(CONFIG_CMD_GPIO) += cmd_gpio.o
-obj-$(CONFIG_CMD_I2C) += cmd_i2c.o
-obj-$(CONFIG_CMD_IOTRACE) += cmd_iotrace.o
-obj-$(CONFIG_CMD_HASH) += cmd_hash.o
-obj-$(CONFIG_CMD_IDE) += cmd_ide.o
-obj-$(CONFIG_CMD_IMMAP) += cmd_immap.o
-obj-$(CONFIG_CMD_INI) += cmd_ini.o
-obj-$(CONFIG_CMD_IRQ) += cmd_irq.o
-obj-$(CONFIG_CMD_ITEST) += cmd_itest.o
-obj-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
-obj-$(CONFIG_CMD_CRAMFS) += cmd_cramfs.o
-obj-$(CONFIG_CMD_LDRINFO) += cmd_ldrinfo.o
-obj-$(CONFIG_CMD_LED) += cmd_led.o
-obj-$(CONFIG_CMD_LICENSE) += cmd_license.o
-obj-y += cmd_load.o
-obj-$(CONFIG_LOGBUFFER) += cmd_log.o
-obj-$(CONFIG_ID_EEPROM) += cmd_mac.o
-obj-$(CONFIG_CMD_MD5SUM) += cmd_md5sum.o
-obj-$(CONFIG_CMD_MEMORY) += cmd_mem.o
-obj-$(CONFIG_CMD_IO) += cmd_io.o
-obj-$(CONFIG_CMD_MFSL) += cmd_mfsl.o
+obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
+obj-$(CONFIG_OF_LIBFDT) += fdt_support.o
+
 obj-$(CONFIG_MII) += miiphyutil.o
 obj-$(CONFIG_CMD_MII) += miiphyutil.o
 obj-$(CONFIG_PHYLIB) += miiphyutil.o
-obj-$(CONFIG_CMD_MII) += cmd_mii.o
-ifdef CONFIG_PHYLIB
-obj-$(CONFIG_CMD_MII) += cmd_mdio.o
-endif
-obj-$(CONFIG_CMD_MISC) += cmd_misc.o
-obj-$(CONFIG_CMD_MMC) += cmd_mmc.o
-obj-$(CONFIG_CMD_MMC_SPI) += cmd_mmc_spi.o
-obj-$(CONFIG_MP) += cmd_mp.o
-obj-$(CONFIG_CMD_MTDPARTS) += cmd_mtdparts.o
-obj-$(CONFIG_CMD_NAND) += cmd_nand.o
-obj-$(CONFIG_CMD_NET) += cmd_net.o
-obj-$(CONFIG_CMD_ONENAND) += cmd_onenand.o
-obj-$(CONFIG_CMD_OTP) += cmd_otp.o
-obj-$(CONFIG_CMD_PART) += cmd_part.o
-ifdef CONFIG_PCI
-obj-$(CONFIG_CMD_PCI) += cmd_pci.o
-endif
-obj-y += cmd_pcmcia.o
-obj-$(CONFIG_CMD_PORTIO) += cmd_portio.o
-obj-$(CONFIG_CMD_PXE) += cmd_pxe.o
-obj-$(CONFIG_CMD_READ) += cmd_read.o
-obj-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o
-obj-$(CONFIG_CMD_REISER) += cmd_reiser.o
-obj-$(CONFIG_CMD_REMOTEPROC) += cmd_remoteproc.o
-obj-$(CONFIG_SANDBOX) += cmd_host.o
-obj-$(CONFIG_CMD_SATA) += cmd_sata.o
-obj-$(CONFIG_CMD_SF) += cmd_sf.o
-obj-$(CONFIG_CMD_SCSI) += cmd_scsi.o
-obj-$(CONFIG_CMD_SHA1SUM) += cmd_sha1sum.o
-obj-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o
-obj-$(CONFIG_CMD_SOFTSWITCH) += cmd_softswitch.o
-obj-$(CONFIG_CMD_SPI) += cmd_spi.o
-obj-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
-obj-$(CONFIG_CMD_STRINGS) += cmd_strings.o
-obj-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
-obj-$(CONFIG_CMD_TIME) += cmd_time.o
-obj-$(CONFIG_CMD_TRACE) += cmd_trace.o
-obj-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
-obj-$(CONFIG_CMD_TPM) += cmd_tpm.o
-obj-$(CONFIG_CMD_TPM_TEST) += cmd_tpm_test.o
-obj-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
-obj-$(CONFIG_CMD_UBI) += cmd_ubi.o
-obj-$(CONFIG_CMD_UBIFS) += cmd_ubifs.o
-obj-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o
-obj-$(CONFIG_CMD_UNZIP) += cmd_unzip.o
-ifdef CONFIG_LZMA
-obj-$(CONFIG_CMD_LZMADEC) += cmd_lzmadec.o
-endif
+
 ifdef CONFIG_CMD_USB
-obj-y += cmd_usb.o
 obj-y += usb.o usb_hub.o
 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
-obj-$(CONFIG_CMD_FASTBOOT) += cmd_fastboot.o
-obj-$(CONFIG_CMD_FS_UUID) += cmd_fs_uuid.o
-
-obj-$(CONFIG_CMD_USB_MASS_STORAGE) += cmd_usb_mass_storage.o
-obj-$(CONFIG_CMD_THOR_DOWNLOAD) += cmd_thordown.o
-obj-$(CONFIG_CMD_XIMG) += cmd_ximg.o
-obj-$(CONFIG_YAFFS2) += cmd_yaffs2.o
-obj-$(CONFIG_CMD_SPL) += cmd_spl.o
-obj-$(CONFIG_CMD_ZIP) += cmd_zip.o
-obj-$(CONFIG_CMD_ZFS) += cmd_zfs.o
 
 # others
 obj-$(CONFIG_BOOTSTAGE) += bootstage.o
@@ -216,14 +86,8 @@ obj-$(CONFIG_MODEM_SUPPORT) += modem.o
 obj-$(CONFIG_UPDATE_TFTP) += update.o
 obj-$(CONFIG_DFU_TFTP) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
-obj-$(CONFIG_CMD_DFU) += cmd_dfu.o
-obj-$(CONFIG_CMD_GPT) += cmd_gpt.o
-obj-$(CONFIG_CMD_ETHSW) += cmd_ethsw.o
 
-# Power
-obj-$(CONFIG_CMD_PMIC) += cmd_pmic.o
-obj-$(CONFIG_CMD_REGULATOR) += cmd_regulator.o
-endif
+endif # !CONFIG_SPL_BUILD
 
 ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
@@ -234,9 +98,6 @@ ifdef CONFIG_SPL_USB_HOST_SUPPORT
 obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o
 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
-ifdef CONFIG_SPL_SATA_SUPPORT
-obj-$(CONFIG_CMD_SCSI) += cmd_scsi.o
-endif
 # environment
 ifdef CONFIG_SPL_ENV_SUPPORT
 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_attr.o
@@ -250,8 +111,6 @@ obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
 endif
 endif
-# core command
-obj-y += cmd_nvedit.o
 #environment
 obj-y += env_common.o
 #others
@@ -289,8 +148,6 @@ obj-y += fb_nand.o
 endif
 endif
 
-obj-$(CONFIG_CMD_BLOB) += cmd_blob.o
-
 # We always have this since drivers/ddr/fs/interactive.c needs it
 obj-y += cli_simple.o
 
@@ -299,6 +156,5 @@ obj-y += cli_readline.o
 obj-y += command.o
 obj-y += s_record.o
 obj-y += xyzModem.o
-obj-y += cmd_disk.o
 
 CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)
index 58936ca4978a9e3914abdfd415b84c133b73cfe9..99d574db2c52523f94946a01e65ca63a36521d37 100644 (file)
@@ -435,7 +435,7 @@ static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
                bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
                return err;
        }
-       flush_cache(load, (*load_end - load) * sizeof(ulong));
+       flush_cache(load, *load_end - load);
 
        debug("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
        bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
diff --git a/common/cmd_aes.c b/common/cmd_aes.c
deleted file mode 100644 (file)
index 76da3ef..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2014 Marek Vasut <marex@denx.de>
- *
- * Command for en/de-crypting block of memory with AES-128-CBC cipher.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <environment.h>
-#include <aes.h>
-#include <malloc.h>
-#include <asm/byteorder.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/**
- * do_aes() - Handle the "aes" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       uint32_t key_addr, src_addr, dst_addr, len;
-       uint8_t *key_ptr, *src_ptr, *dst_ptr;
-       uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
-       uint32_t aes_blocks;
-       int enc;
-
-       if (argc != 6)
-               return CMD_RET_USAGE;
-
-       if (!strncmp(argv[1], "enc", 3))
-               enc = 1;
-       else if (!strncmp(argv[1], "dec", 3))
-               enc = 0;
-       else
-               return CMD_RET_USAGE;
-
-       key_addr = simple_strtoul(argv[2], NULL, 16);
-       src_addr = simple_strtoul(argv[3], NULL, 16);
-       dst_addr = simple_strtoul(argv[4], NULL, 16);
-       len = simple_strtoul(argv[5], NULL, 16);
-
-       key_ptr = (uint8_t *)key_addr;
-       src_ptr = (uint8_t *)src_addr;
-       dst_ptr = (uint8_t *)dst_addr;
-
-       /* First we expand the key. */
-       aes_expand_key(key_ptr, key_exp);
-
-       /* Calculate the number of AES blocks to encrypt. */
-       aes_blocks = DIV_ROUND_UP(len, AES_KEY_LENGTH);
-
-       if (enc)
-               aes_cbc_encrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks);
-       else
-               aes_cbc_decrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks);
-
-       return 0;
-}
-
-/***************************************************/
-#ifdef CONFIG_SYS_LONGHELP
-static char aes_help_text[] =
-       "enc key src dst len - Encrypt block of data $len bytes long\n"
-       "                          at address $src using a key at address\n"
-       "                          $key and store the result at address\n"
-       "                          $dst. The $len size must be multiple of\n"
-       "                          16 bytes and $key must be 16 bytes long.\n"
-       "aes dec key src dst len - Decrypt block of data $len bytes long\n"
-       "                          at address $src using a key at address\n"
-       "                          $key and store the result at address\n"
-       "                          $dst. The $len size must be multiple of\n"
-       "                          16 bytes and $key must be 16 bytes long.";
-#endif
-
-U_BOOT_CMD(
-       aes, 6, 1, do_aes,
-       "AES 128 CBC encryption",
-       aes_help_text
-);
diff --git a/common/cmd_ambapp.c b/common/cmd_ambapp.c
deleted file mode 100644 (file)
index 4b6d174..0000000
+++ /dev/null
@@ -1,575 +0,0 @@
-/*
- * (C) Copyright 2007
- * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * AMBA Plug&Play information list command
- *
- */
-#include <common.h>
-#include <command.h>
-#include <ambapp.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-typedef struct {
-       int device_id;
-       char *name;
-       char *desc;
-} ambapp_device_name;
-
-typedef struct {
-       unsigned int vendor_id;
-       char *name;
-       char *desc;
-       ambapp_device_name *devices;
-} ambapp_vendor_devnames;
-
-/** Vendor GAISLER devices */
-static ambapp_device_name GAISLER_devices[] = {
-       {GAISLER_LEON2DSU, "LEON2DSU", "Leon2 Debug Support Unit"},
-       {GAISLER_LEON3, "LEON3", "Leon3 SPARC V8 Processor"},
-       {GAISLER_LEON3DSU, "LEON3DSU", "Leon3 Debug Support Unit"},
-       {GAISLER_ETHAHB, "ETHAHB", "OC ethernet AHB interface"},
-       {GAISLER_APBMST, "APBMST", "AHB/APB Bridge"},
-       {GAISLER_AHBUART, "AHBUART", "AHB Debug UART"},
-       {GAISLER_SRCTRL, "SRCTRL", "Simple SRAM Controller"},
-       {GAISLER_SDCTRL, "SDCTRL", "PC133 SDRAM Controller"},
-       {GAISLER_SSRCTRL, "SSRCTRL", "Synchronous SRAM Controller"},
-       {GAISLER_APBUART, "APBUART", "Generic UART"},
-       {GAISLER_IRQMP, "IRQMP", "Multi-processor Interrupt Ctrl."},
-       {GAISLER_AHBRAM, "AHBRAM", "Single-port AHB SRAM module"},
-       {GAISLER_AHBDPRAM, "AHBDPRAM", "Dual-port AHB SRAM module"},
-       {GAISLER_GPTIMER, "GPTIMER", "Modular Timer Unit"},
-       {GAISLER_PCITRG, "PCITRG", "Simple 32-bit PCI Target"},
-       {GAISLER_PCISBRG, "PCISBRG", "Simple 32-bit PCI Bridge"},
-       {GAISLER_PCIFBRG, "PCIFBRG", "Fast 32-bit PCI Bridge"},
-       {GAISLER_PCITRACE, "PCITRACE", "32-bit PCI Trace Buffer"},
-       {GAISLER_DMACTRL, "DMACTRL", "AMBA DMA controller"},
-       {GAISLER_AHBTRACE, "AHBTRACE", "AMBA Trace Buffer"},
-       {GAISLER_DSUCTRL, "DSUCTRL", "DSU/ETH controller"},
-       {GAISLER_CANAHB, "CANAHB", "OC CAN AHB interface"},
-       {GAISLER_GPIO, "GPIO", "General Purpose I/O port"},
-       {GAISLER_AHBROM, "AHBROM", "Generic AHB ROM"},
-       {GAISLER_AHBJTAG, "AHBJTAG", "JTAG Debug Link"},
-       {GAISLER_ETHMAC, "ETHMAC", "GR Ethernet MAC"},
-       {GAISLER_SWNODE, "SWNODE", "SpaceWire Node Interface"},
-       {GAISLER_SPW, "SPW", "SpaceWire Serial Link"},
-       {GAISLER_AHB2AHB, "AHB2AHB", "AHB-to-AHB Bridge"},
-       {GAISLER_USBDC, "USBDC", "GR USB 2.0 Device Controller"},
-       {GAISLER_USB_DCL, "USB_DCL", "USB Debug Communication Link"},
-       {GAISLER_DDRMP, "DDRMP", "Multi-port DDR controller"},
-       {GAISLER_ATACTRL, "ATACTRL", "ATA controller"},
-       {GAISLER_DDRSP, "DDRSP", "Single-port DDR266 controller"},
-       {GAISLER_EHCI, "EHCI", "USB Enhanced Host Controller"},
-       {GAISLER_UHCI, "UHCI", "USB Universal Host Controller"},
-       {GAISLER_I2CMST, "I2CMST", "AMBA Wrapper for OC I2C-master"},
-       {GAISLER_SPW2, "SPW2", "GRSPW2 SpaceWire Serial Link"},
-       {GAISLER_AHBDMA, "AHBDMA", ""},
-       {GAISLER_NUHOSP3, "NUHOSP3", "Nuhorizons Spartan3 IO I/F"},
-       {GAISLER_CLKGATE, "CLKGATE", "Clock gating unit"},
-       {GAISLER_SPICTRL, "SPICTRL", "SPI Controller"},
-       {GAISLER_DDR2SP, "DDR2SP", "Single-port DDR2 controller"},
-       {GAISLER_SLINK, "SLINK", "SLINK Master"},
-       {GAISLER_GRTM, "GRTM", "CCSDS Telemetry Encoder"},
-       {GAISLER_GRTC, "GRTC", "CCSDS Telecommand Decoder"},
-       {GAISLER_GRPW, "GRPW", "PacketWire to AMBA AHB I/F"},
-       {GAISLER_GRCTM, "GRCTM", "CCSDS Time Manager"},
-       {GAISLER_GRHCAN, "GRHCAN", "ESA HurriCANe CAN with DMA"},
-       {GAISLER_GRFIFO, "GRFIFO", "FIFO Controller"},
-       {GAISLER_GRADCDAC, "GRADCDAC", "ADC / DAC Interface"},
-       {GAISLER_GRPULSE, "GRPULSE", "General Purpose I/O with Pulses"},
-       {GAISLER_GRTIMER, "GRTIMER", "Timer Unit with Latches"},
-       {GAISLER_AHB2PP, "AHB2PP", "AMBA AHB to Packet Parallel I/F"},
-       {GAISLER_GRVERSION, "GRVERSION", "Version and Revision Register"},
-       {GAISLER_APB2PW, "APB2PW", "PacketWire Transmit Interface"},
-       {GAISLER_PW2APB, "PW2APB", "PacketWire Receive Interface"},
-       {GAISLER_GRCAN, "GRCAN", "CAN Controller with DMA"},
-       {GAISLER_I2CSLV, "I2CSLV", "I2C Slave"},
-       {GAISLER_U16550, "U16550", "Simple 16550 UART"},
-       {GAISLER_AHBMST_EM, "AHBMST_EM", "AMBA Master Emulator"},
-       {GAISLER_AHBSLV_EM, "AHBSLV_EM", "AMBA Slave Emulator"},
-       {GAISLER_GRTESTMOD, "GRTESTMOD", "Test report module"},
-       {GAISLER_ASCS, "ASCS", "ASCS Master"},
-       {GAISLER_IPMVBCTRL, "IPMVBCTRL", "IPM-bus/MVBC memory controller"},
-       {GAISLER_SPIMCTRL, "SPIMCTRL", "SPI Memory Controller"},
-       {GAISLER_L4STAT, "L4STAT", "Leon4 Statistics Module"},
-       {GAISLER_LEON4, "LEON4", "Leon4 SPARC V8 Processor"},
-       {GAISLER_LEON4DSU, "LEON4DSU", "Leon4 Debug Support Unit"},
-       {GAISLER_PWM, "PWM", "PWM generator"},
-       {GAISLER_L2CACHE, "L2CACHE", "L2-Cache Controller"},
-       {GAISLER_SDCTRL64, "SDCTRL64", "64-bit PC133 SDRAM Controller"},
-       {GAISLER_GR1553B, "GR1553B", "MIL-STD-1553B Interface"},
-       {GAISLER_1553TST, "1553TST", "MIL-STD-1553B Test Device"},
-       {GAISLER_GRIOMMU, "GRIOMMU", "I/O Memory Management Unit"},
-       {GAISLER_FTAHBRAM, "FTAHBRAM", "Generic FT AHB SRAM module"},
-       {GAISLER_FTSRCTRL, "FTSRCTRL", "Simple FT SRAM Controller"},
-       {GAISLER_AHBSTAT, "AHBSTAT", "AHB Status Register"},
-       {GAISLER_LEON3FT, "LEON3FT", "Leon3-FT SPARC V8 Processor"},
-       {GAISLER_FTMCTRL, "FTMCTRL", "Memory controller with EDAC"},
-       {GAISLER_FTSDCTRL, "FTSDCTRL", "FT PC133 SDRAM Controller"},
-       {GAISLER_FTSRCTRL8, "FTSRCTRL8", "FT 8-bit SRAM/16-bit IO Ctrl"},
-       {GAISLER_MEMSCRUB, "MEMSCRUB", "AHB Memory Scrubber"},
-       {GAISLER_FTSDCTRL64, "FTSDCTRL64", "64-bit FT SDRAM Controller"},
-       {GAISLER_APBPS2, "APBPS2", "PS2 interface"},
-       {GAISLER_VGACTRL, "VGACTRL", "VGA controller"},
-       {GAISLER_LOGAN, "LOGAN", "On chip Logic Analyzer"},
-       {GAISLER_SVGACTRL, "SVGACTRL", "SVGA frame buffer"},
-       {GAISLER_T1AHB, "T1AHB", "Niagara T1 PCX/AHB bridge"},
-       {GAISLER_MP7WRAP, "MP7WRAP", "CoreMP7 wrapper"},
-       {GAISLER_GRSYSMON, "GRSYSMON", "AMBA wrapper for System Monitor"},
-       {GAISLER_GRACECTRL, "GRACECTRL", "System ACE I/F Controller"},
-       {GAISLER_ATAHBSLV, "ATAHBSLV", "AMBA Test Framework AHB Slave"},
-       {GAISLER_ATAHBMST, "ATAHBMST", "AMBA Test Framework AHB Master"},
-       {GAISLER_ATAPBSLV, "ATAPBSLV", "AMBA Test Framework APB Slave"},
-       {GAISLER_B1553BC, "B1553BC", "AMBA Wrapper for Core1553BBC"},
-       {GAISLER_B1553RT, "B1553RT", "AMBA Wrapper for Core1553BRT"},
-       {GAISLER_B1553BRM, "B1553BRM", "AMBA Wrapper for Core1553BRM"},
-       {GAISLER_AES, "AES", "Advanced Encryption Standard"},
-       {GAISLER_ECC, "ECC", "Elliptic Curve Cryptography"},
-       {GAISLER_PCIF, "PCIF", "AMBA Wrapper for CorePCIF"},
-       {GAISLER_CLKMOD, "CLKMOD", "CPU Clock Switching Ctrl module"},
-       {GAISLER_HAPSTRAK, "HAPSTRAK", "HAPS HapsTrak I/O Port"},
-       {GAISLER_TEST_1X2, "TEST_1X2", "HAPS TEST_1x2 interface"},
-       {GAISLER_WILD2AHB, "WILD2AHB", "WildCard CardBus interface"},
-       {GAISLER_BIO1, "BIO1", "Basic I/O board BIO1"},
-       {GAISLER_AESDMA, "AESDMA", "AES 256 DMA"},
-       {GAISLER_SATCAN, "SATCAN", "SatCAN controller"},
-       {GAISLER_CANMUX, "CANMUX", "CAN Bus multiplexer"},
-       {GAISLER_GRTMRX, "GRTMRX", "CCSDS Telemetry Receiver"},
-       {GAISLER_GRTCTX, "GRTCTX", "CCSDS Telecommand Transmitter"},
-       {GAISLER_GRTMDESC, "GRTMDESC", "CCSDS Telemetry Descriptor"},
-       {GAISLER_GRTMVC, "GRTMVC", "CCSDS Telemetry VC Generator"},
-       {GAISLER_GEFFE, "GEFFE", "Geffe Generator"},
-       {GAISLER_GPREG, "GPREG", "General Purpose Register"},
-       {GAISLER_GRTMPAHB, "GRTMPAHB", "CCSDS Telemetry VC AHB Input"},
-       {GAISLER_SPWCUC, "SPWCUC", "CCSDS CUC / SpaceWire I/F"},
-       {GAISLER_SPW2_DMA, "SPW2_DMA", "GRSPW Router DMA interface"},
-       {GAISLER_SPWROUTER, "SPWROUTER", "GRSPW Router"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor PENDER devices */
-static ambapp_device_name PENDER_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor ESA devices */
-static ambapp_device_name ESA_devices[] = {
-       {ESA_LEON2, "LEON2", "Leon2 SPARC V8 Processor"},
-       {ESA_LEON2APB, "LEON2APB", "Leon2 Peripheral Bus"},
-       {ESA_IRQ, "IRQ", "Leon2 Interrupt Controller"},
-       {ESA_TIMER, "TIMER", "Leon2 Timer"},
-       {ESA_UART, "UART", "Leon2 UART"},
-       {ESA_CFG, "CFG", "Leon2 Configuration Register"},
-       {ESA_IO, "IO", "Leon2 Input/Output"},
-       {ESA_MCTRL, "MCTRL", "Leon2 Memory Controller"},
-       {ESA_PCIARB, "PCIARB", "PCI Arbiter"},
-       {ESA_HURRICANE, "HURRICANE", "HurriCANe/HurryAMBA CAN Ctrl"},
-       {ESA_SPW_RMAP, "SPW_RMAP", "UoD/Saab SpaceWire/RMAP link"},
-       {ESA_AHBUART, "AHBUART", "Leon2 AHB Debug UART"},
-       {ESA_SPWA, "SPWA", "ESA/ASTRIUM SpaceWire link"},
-       {ESA_BOSCHCAN, "BOSCHCAN", "SSC/BOSCH CAN Ctrl"},
-       {ESA_IRQ2, "IRQ2", "Leon2 Secondary Irq Controller"},
-       {ESA_AHBSTAT, "AHBSTAT", "Leon2 AHB Status Register"},
-       {ESA_WPROT, "WPROT", "Leon2 Write Protection"},
-       {ESA_WPROT2, "WPROT2", "Leon2 Extended Write Protection"},
-       {ESA_PDEC3AMBA, "PDEC3AMBA", "ESA CCSDS PDEC3AMBA TC Decoder"},
-       {ESA_PTME3AMBA, "PTME3AMBA", "ESA CCSDS PTME3AMBA TM Encoder"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor ASTRIUM devices */
-static ambapp_device_name ASTRIUM_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor OPENCHIP devices */
-static ambapp_device_name OPENCHIP_devices[] = {
-       {OPENCHIP_APBGPIO, "APBGPIO", "APB General Purpose IO"},
-       {OPENCHIP_APBI2C, "APBI2C", "APB I2C Interface"},
-       {OPENCHIP_APBSPI, "APBSPI", "APB SPI Interface"},
-       {OPENCHIP_APBCHARLCD, "APBCHARLCD", "APB Character LCD"},
-       {OPENCHIP_APBPWM, "APBPWM", "APB PWM"},
-       {OPENCHIP_APBPS2, "APBPS2", "APB PS/2 Interface"},
-       {OPENCHIP_APBMMCSD, "APBMMCSD", "APB MMC/SD Card Interface"},
-       {OPENCHIP_APBNAND, "APBNAND", "APB NAND(SmartMedia) Interface"},
-       {OPENCHIP_APBLPC, "APBLPC", "APB LPC Interface"},
-       {OPENCHIP_APBCF, "APBCF", "APB CompactFlash (IDE)"},
-       {OPENCHIP_APBSYSACE, "APBSYSACE", "APB SystemACE Interface"},
-       {OPENCHIP_APB1WIRE, "APB1WIRE", "APB 1-Wire Interface"},
-       {OPENCHIP_APBJTAG, "APBJTAG", "APB JTAG TAP Master"},
-       {OPENCHIP_APBSUI, "APBSUI", "APB Simple User Interface"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor OPENCORES devices */
-static ambapp_device_name OPENCORES_devices[] = {
-       {OPENCORES_PCIBR, "PCIBR", "PCI Bridge"},
-       {OPENCORES_ETHMAC, "ETHMAC", "Ethernet MAC"},
-       {0, NULL}
-};
-
-
-/** Vendor CONTRIB devices */
-static ambapp_device_name CONTRIB_devices[] = {
-       {CONTRIB_CORE1, "CORE1", "Contributed core 1"},
-       {CONTRIB_CORE2, "CORE2", "Contributed core 2"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor EONIC devices */
-static ambapp_device_name EONIC_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor RADIONOR devices */
-static ambapp_device_name RADIONOR_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor GLEICHMANN devices */
-static ambapp_device_name GLEICHMANN_devices[] = {
-       {GLEICHMANN_CUSTOM, "CUSTOM", "Custom device"},
-       {GLEICHMANN_GEOLCD01, "GEOLCD01", "GEOLCD01 graphics system"},
-       {GLEICHMANN_DAC, "DAC", "Sigma delta DAC"},
-       {GLEICHMANN_HPI, "HPI", "AHB-to-HPI bridge"},
-       {GLEICHMANN_SPI, "SPI", "SPI master"},
-       {GLEICHMANN_HIFC, "HIFC", "Human interface controller"},
-       {GLEICHMANN_ADCDAC, "ADCDAC", "Sigma delta ADC/DAC"},
-       {GLEICHMANN_SPIOC, "SPIOC", ""},
-       {GLEICHMANN_AC97, "AC97", ""},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor MENTA devices */
-static ambapp_device_name MENTA_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor SUN devices */
-static ambapp_device_name SUN_devices[] = {
-       {SUN_T1, "T1", "Niagara T1 SPARC V9 Processor"},
-       {SUN_S1, "S1", "Niagara S1 SPARC V9 Processor"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor MOVIDIA devices */
-static ambapp_device_name MOVIDIA_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor ORBITA devices */
-static ambapp_device_name ORBITA_devices[] = {
-       {ORBITA_1553B, "1553B", "MIL-STD-1553B Controller"},
-       {ORBITA_429, "429", "429 Interface"},
-       {ORBITA_SPI, "SPI", "SPI Interface"},
-       {ORBITA_I2C, "I2C", "I2C Interface"},
-       {ORBITA_SMARTCARD, "SMARTCARD", "Smart Card Reader"},
-       {ORBITA_SDCARD, "SDCARD", "SD Card Reader"},
-       {ORBITA_UART16550, "UART16550", "16550 UART"},
-       {ORBITA_CRYPTO, "CRYPTO", "Crypto Engine"},
-       {ORBITA_SYSIF, "SYSIF", "System Interface"},
-       {ORBITA_PIO, "PIO", "Programmable IO module"},
-       {ORBITA_RTC, "RTC", "Real-Time Clock"},
-       {ORBITA_COLORLCD, "COLORLCD", "Color LCD Controller"},
-       {ORBITA_PCI, "PCI", "PCI Module"},
-       {ORBITA_DSP, "DSP", "DPS Co-Processor"},
-       {ORBITA_USBHOST, "USBHOST", "USB Host"},
-       {ORBITA_USBDEV, "USBDEV", "USB Device"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor SYNOPSYS devices */
-static ambapp_device_name SYNOPSYS_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor NASA devices */
-static ambapp_device_name NASA_devices[] = {
-       {NASA_EP32, "EP32", "EP32 Forth processor"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor CAL devices */
-static ambapp_device_name CAL_devices[] = {
-       {CAL_DDRCTRL, "DDRCTRL", ""},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor EMBEDDIT devices */
-static ambapp_device_name EMBEDDIT_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor CETON devices */
-static ambapp_device_name CETON_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor S3 devices */
-static ambapp_device_name S3_devices[] = {
-       {0, NULL, NULL}
-};
-
-
-/** Vendor ACTEL devices */
-static ambapp_device_name ACTEL_devices[] = {
-       {ACTEL_COREMP7, "COREMP7", "CoreMP7 Processor"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendor APPLECORE devices */
-static ambapp_device_name APPLECORE_devices[] = {
-       {APPLECORE_UTLEON3, "UTLEON3", "AppleCore uT-LEON3 Processor"},
-       {APPLECORE_UTLEON3DSU, "UTLEON3DSU", "AppleCore uT-LEON3 DSU"},
-       {0, NULL, NULL}
-};
-
-
-/** Vendors and their devices */
-static ambapp_vendor_devnames vendors[] = {
-       {VENDOR_GAISLER, "GAISLER", "Gaisler Research", GAISLER_devices},
-       {VENDOR_PENDER, "PENDER", "", PENDER_devices},
-       {VENDOR_ESA, "ESA", "European Space Agency", ESA_devices},
-       {VENDOR_ASTRIUM, "ASTRIUM", "", ASTRIUM_devices},
-       {VENDOR_OPENCHIP, "OPENCHIP", "OpenChip", OPENCHIP_devices},
-       {VENDOR_OPENCORES, "OPENCORES", "OpenCores", OPENCORES_devices},
-       {VENDOR_CONTRIB, "CONTRIB", "Various contributions", CONTRIB_devices},
-       {VENDOR_EONIC, "EONIC", "Eonic BV", EONIC_devices},
-       {VENDOR_RADIONOR, "RADIONOR", "Radionor Communications", RADIONOR_devices},
-       {VENDOR_GLEICHMANN, "GLEICHMANN", "Gleichmann Electronics", GLEICHMANN_devices},
-       {VENDOR_MENTA, "MENTA", "Menta", MENTA_devices},
-       {VENDOR_SUN, "SUN", "Sun Microsystems", SUN_devices},
-       {VENDOR_MOVIDIA, "MOVIDIA", "", MOVIDIA_devices},
-       {VENDOR_ORBITA, "ORBITA", "Orbita", ORBITA_devices},
-       {VENDOR_SYNOPSYS, "SYNOPSYS", "Synopsys Inc.", SYNOPSYS_devices},
-       {VENDOR_NASA, "NASA", "NASA", NASA_devices},
-       {VENDOR_S3, "S3", "S3 Group", S3_devices},
-       {VENDOR_CAL, "CAL", "", CAL_devices},
-       {VENDOR_EMBEDDIT, "EMBEDDIT", "Embedd.it", EMBEDDIT_devices},
-       {VENDOR_CETON, "CETON", "Ceton Corporation", CETON_devices},
-       {VENDOR_ACTEL, "ACTEL", "Actel Corporation", ACTEL_devices},
-       {VENDOR_APPLECORE, "APPLECORE", "AppleCore", APPLECORE_devices},
-       {0, NULL, NULL, NULL}
-};
-
-static ambapp_device_name *ambapp_get_dev(ambapp_device_name *devs, int id)
-{
-       if (!devs)
-               return NULL;
-
-       while (devs->device_id > 0) {
-               if (devs->device_id == id)
-                       return devs;
-               devs++;
-       }
-       return NULL;
-}
-
-char *ambapp_device_id2str(int vendor, int id)
-{
-       ambapp_vendor_devnames *ven = &vendors[0];
-       ambapp_device_name *dev;
-
-       while (ven->vendor_id > 0) {
-               if (ven->vendor_id == vendor) {
-                       dev = ambapp_get_dev(ven->devices, id);
-                       if (!dev)
-                               return NULL;
-                       return dev->name;
-               }
-               ven++;
-       }
-       return NULL;
-}
-
-char *ambapp_device_id2desc(int vendor, int id)
-{
-       ambapp_vendor_devnames *ven = &vendors[0];
-       ambapp_device_name *dev;
-
-       while (ven->vendor_id > 0) {
-               if (ven->vendor_id == vendor) {
-                       dev = ambapp_get_dev(ven->devices, id);
-                       if (!dev)
-                               return NULL;
-                       return dev->desc;
-               }
-               ven++;
-       }
-       return NULL;
-}
-
-char *ambapp_vendor_id2str(int vendor)
-{
-       ambapp_vendor_devnames *ven = &vendors[0];
-
-       while (ven->vendor_id > 0) {
-               if (ven->vendor_id == vendor) {
-                       return ven->name;
-               }
-               ven++;
-       }
-       return NULL;
-}
-
-static char *unknown = "unknown";
-
-char *ambapp_type_names[4] = {
-       /* 0 */ "UNUSED",
-       /* 1 */ "apb",
-       /* 2 */ "ahbmem",
-       /* 3 */ "ahbio"
-};
-
-/* Print one APB device */
-void ambapp_print_apb(ambapp_apbdev *dev, int index)
-{
-       char *dev_str, *ven_str;
-       unsigned int freq;
-
-       ven_str = ambapp_vendor_id2str(dev->vendor);
-       if (!ven_str) {
-               ven_str = unknown;
-               dev_str = unknown;
-       } else {
-               dev_str = ambapp_device_id2str(dev->vendor, dev->device);
-               if (!dev_str)
-                       dev_str = unknown;
-       }
-
-       /* Get Frequency of Core */
-       freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
-
-       printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n"
-              "   apb: 0x%08x - 0x%08x\n"
-              "   irq: %-2d (ver: %-2d)\n",
-              index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000,
-              dev->address, dev->address + (dev->mask-1),
-              dev->irq, dev->ver);
-}
-
-void ambapp_print_ahb(ambapp_ahbdev *dev, int index)
-{
-       char *dev_str, *ven_str, *type_str;
-       int i;
-       unsigned int freq;
-
-       ven_str = ambapp_vendor_id2str(dev->vendor);
-       if (!ven_str) {
-               ven_str = unknown;
-               dev_str = unknown;
-       } else {
-               dev_str = ambapp_device_id2str(dev->vendor, dev->device);
-               if (!dev_str)
-                       dev_str = unknown;
-       }
-
-       /* Get Frequency of Core */
-       freq = ambapp_bus_freq(&ambapp_plb, dev->ahb_bus_index);
-
-       printf("0x%02x:0x%02x:0x%02x: %s  %s  (%dkHz)\n",
-              index, dev->vendor, dev->device, ven_str, dev_str, freq / 1000);
-
-       for (i = 0; i < 4; i++) {
-               if (dev->type[i] == 0)
-                       continue;
-               type_str = ambapp_type_names[dev->type[i]];
-               printf("   %-7s: 0x%08x - 0x%08x\n", type_str, dev->address[i],
-                       dev->address[i] + (dev->mask[i]-1));
-       }
-
-       printf("   irq: %-2d (ver: %d)\n", dev->irq, dev->ver);
-}
-
-int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       int index;
-       ambapp_apbdev apbdev;
-       ambapp_ahbdev ahbdev;
-
-       /* Print AHB Masters */
-       puts("\n--------- AHB Masters ---------\n");
-       index = 0;
-       while (ambapp_ahbmst_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
-               /* Found a AHB Master Device */
-               ambapp_print_ahb(&ahbdev, index);
-               index++;
-       }
-
-       /* Print AHB Slaves */
-       puts("\n--------- AHB Slaves  ---------\n");
-       index = 0;
-       while (ambapp_ahbslv_find(&ambapp_plb, 0, 0, index, &ahbdev) == 1) {
-               /* Found a AHB Slave Device */
-               ambapp_print_ahb(&ahbdev, index);
-               index++;
-       }
-
-       /* Print APB Slaves */
-       puts("\n--------- APB Slaves  ---------\n");
-       index = 0;
-       while (ambapp_apb_find(&ambapp_plb, 0, 0, index, &apbdev) == 1) {
-               /* Found a APB Slave Device */
-               ambapp_print_apb(&apbdev, index);
-               index++;
-       }
-
-       puts("\n");
-       return 0;
-}
-
-int ambapp_init_reloc(void)
-{
-       ambapp_vendor_devnames *vend = vendors;
-       ambapp_device_name *dev;
-
-       while (vend->vendor_id && vend->name) {
-               vend->name = (char *)((unsigned int)vend->name + gd->reloc_off);
-               vend->desc = (char *)((unsigned int)vend->desc + gd->reloc_off);
-               vend->devices = (ambapp_device_name *)
-                       ((unsigned int)vend->devices + gd->reloc_off);
-               dev = vend->devices;
-               vend++;
-               if (!dev)
-                       continue;
-               while (dev->device_id && dev->name) {
-                       dev->name =
-                           (char *)((unsigned int)dev->name + gd->reloc_off);
-                       dev->desc =
-                           (char *)((unsigned int)dev->desc + gd->reloc_off);
-                       dev++;
-               }
-       }
-       return 0;
-}
-
-U_BOOT_CMD(
-       ambapp, 1, 1, do_ambapp_print,
-       "list AMBA Plug&Play information",
-       "ambapp\n"
-       "    - lists AMBA (AHB & APB) Plug&Play devices present on the system"
-);
diff --git a/common/cmd_armflash.c b/common/cmd_armflash.c
deleted file mode 100644 (file)
index b94d128..0000000
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * (C) Copyright 2015
- * Linus Walleij, Linaro
- *
- * Support for ARM Flash Partitions
- *
- * SPDX-License-Identifier:     GPL-2.0+
- */
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <asm/io.h>
-
-#define MAX_REGIONS 4
-#define MAX_IMAGES 32
-
-struct afs_region {
-       u32 load_address;
-       u32 size;
-       u32 offset;
-};
-
-struct afs_image {
-       flash_info_t *flinfo;
-       const char *name;
-       u32 version;
-       u32 entrypoint;
-       u32 attributes;
-       u32 region_count;
-       struct afs_region regions[MAX_REGIONS];
-       ulong flash_mem_start;
-       ulong flash_mem_end;
-};
-
-static struct afs_image afs_images[MAX_IMAGES];
-static int num_afs_images;
-
-static u32 compute_crc(ulong start, u32 len)
-{
-       u32 sum = 0;
-       int i;
-
-       if (len % 4 != 0) {
-               printf("bad checksumming\n");
-               return 0;
-       }
-
-       for (i = 0; i < len; i += 4) {
-               u32 val;
-
-               val = readl((void *)start + i);
-               if (val > ~sum)
-                       sum++;
-               sum += val;
-       }
-       return ~sum;
-}
-
-static void parse_bank(ulong bank)
-{
-       int i;
-       ulong flstart, flend;
-       flash_info_t *info;
-
-       info = &flash_info[bank];
-       if (info->flash_id != FLASH_MAN_CFI) {
-               printf("Bank %lu: missing or unknown FLASH type\n", bank);
-               return;
-       }
-       if (!info->sector_count) {
-               printf("Bank %lu: no FLASH sectors\n", bank);
-               return;
-       }
-
-       flstart = info->start[0];
-       flend = flstart + info->size;
-
-       for (i = 0; i < info->sector_count; ++i) {
-               ulong secend;
-               u32 foot1, foot2;
-
-               if (ctrlc())
-                       break;
-
-               if (i == info->sector_count-1)
-                       secend = flend;
-               else
-                       secend = info->start[i+1];
-
-               /* Check for v1 header */
-               foot1 = readl((void *)secend - 0x0c);
-               if (foot1 == 0xA0FFFF9FU) {
-                       struct afs_image *afi = &afs_images[num_afs_images];
-                       ulong imginfo;
-
-                       afi->flinfo = info;
-                       afi->version = 1;
-                       afi->flash_mem_start = readl((void *)secend - 0x10);
-                       afi->flash_mem_end = readl((void *)secend - 0x14);
-                       afi->attributes = readl((void *)secend - 0x08);
-                       /* Adjust to even address */
-                       imginfo = afi->flash_mem_end + afi->flash_mem_end % 4;
-                       /* Record as a single region */
-                       afi->region_count = 1;
-                       afi->regions[0].offset = readl((void *)imginfo + 0x04);
-                       afi->regions[0].load_address =
-                               readl((void *)imginfo + 0x08);
-                       afi->regions[0].size = readl((void *)imginfo + 0x0C);
-                       afi->entrypoint = readl((void *)imginfo + 0x10);
-                       afi->name = (const char *)imginfo + 0x14;
-                       num_afs_images++;
-               }
-
-               /* Check for v2 header */
-               foot1 = readl((void *)secend - 0x04);
-               foot2 = readl((void *)secend - 0x08);
-               /* This makes up the string "HSLFTOOF" flash footer */
-               if (foot1 == 0x464F4F54U && foot2 == 0x464C5348U) {
-                       struct afs_image *afi = &afs_images[num_afs_images];
-                       ulong imginfo;
-                       u32 block_start, block_end;
-                       int j;
-
-                       afi->flinfo = info;
-                       afi->version = readl((void *)secend - 0x0c);
-                       imginfo = secend - 0x30 - readl((void *)secend - 0x10);
-                       afi->name = (const char *)secend - 0x30;
-
-                       afi->entrypoint = readl((void *)imginfo+0x08);
-                       afi->attributes = readl((void *)imginfo+0x0c);
-                       afi->region_count = readl((void *)imginfo+0x10);
-                       block_start = readl((void *)imginfo+0x54);
-                       block_end = readl((void *)imginfo+0x58);
-                       afi->flash_mem_start = afi->flinfo->start[block_start];
-                       afi->flash_mem_end = afi->flinfo->start[block_end];
-
-                       /*
-                        * Check footer CRC, the algorithm saves the inverse
-                        * checksum as part of the summed words, and thus
-                        * the result should be zero.
-                        */
-                       if (compute_crc(imginfo + 8, 0x88) != 0) {
-                               printf("BAD CRC on ARM image info\n");
-                               printf("(continuing anyway)\n");
-                       }
-
-                       /* Parse regions */
-                       for (j = 0; j < afi->region_count; j++) {
-                               afi->regions[j].load_address =
-                                       readl((void *)imginfo+0x14 + j*0x10);
-                               afi->regions[j].size =
-                                       readl((void *)imginfo+0x18 + j*0x10);
-                               afi->regions[j].offset =
-                                       readl((void *)imginfo+0x1c + j*0x10);
-                               /*
-                                * At offset 0x20 + j*0x10 there is a region
-                                * checksum which seems to be the running
-                                * sum + 3, however since we anyway checksum
-                                * the entire footer this is skipped over for
-                                * checking here.
-                                */
-                       }
-                       num_afs_images++;
-               }
-       }
-}
-
-static void parse_flash(void)
-{
-       ulong bank;
-
-       /* We have already parsed the images in flash */
-       if (num_afs_images > 0)
-               return;
-       for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank)
-               parse_bank(bank);
-}
-
-static int load_image(const char * const name, const ulong address)
-{
-       struct afs_image *afi = NULL;
-       int i;
-
-       parse_flash();
-       for (i = 0; i < num_afs_images; i++) {
-               struct afs_image *tmp = &afs_images[i];
-
-               if (!strcmp(tmp->name, name)) {
-                       afi = tmp;
-                       break;
-               }
-       }
-       if (!afi) {
-               printf("image \"%s\" not found in flash\n", name);
-               return CMD_RET_FAILURE;
-       }
-
-       for (i = 0; i < afi->region_count; i++) {
-               ulong from, to;
-
-               from = afi->flash_mem_start + afi->regions[i].offset;
-               if (address) {
-                       to = address;
-               } else if (afi->regions[i].load_address) {
-                       to = afi->regions[i].load_address;
-               } else {
-                       printf("no valid load address\n");
-                       return CMD_RET_FAILURE;
-               }
-
-               memcpy((void *)to, (void *)from, afi->regions[i].size);
-
-               printf("loaded region %d from %08lX to %08lX, %08X bytes\n",
-                      i,
-                      from,
-                      to,
-                      afi->regions[i].size);
-       }
-       return CMD_RET_SUCCESS;
-}
-
-static void print_images(void)
-{
-       int i;
-
-       parse_flash();
-       for (i = 0; i < num_afs_images; i++) {
-               struct afs_image *afi = &afs_images[i];
-               int j;
-
-               printf("Image: \"%s\" (v%d):\n", afi->name, afi->version);
-               printf("    Entry point: 0x%08X\n", afi->entrypoint);
-               printf("    Attributes: 0x%08X: ", afi->attributes);
-               if (afi->attributes == 0x01)
-                       printf("ARM executable");
-               if (afi->attributes == 0x08)
-                       printf("ARM backup");
-               printf("\n");
-               printf("    Flash mem start: 0x%08lX\n",
-                      afi->flash_mem_start);
-               printf("    Flash mem end: 0x%08lX\n",
-                      afi->flash_mem_end);
-               for (j = 0; j < afi->region_count; j++) {
-                       printf("    region %d\n"
-                              "        load address: %08X\n"
-                              "        size: %08X\n"
-                              "        offset: %08X\n",
-                              j,
-                              afi->regions[j].load_address,
-                              afi->regions[j].size,
-                              afi->regions[j].offset);
-               }
-       }
-}
-
-static int exists(const char * const name)
-{
-       int i;
-
-       parse_flash();
-       for (i = 0; i < num_afs_images; i++) {
-               struct afs_image *afi = &afs_images[i];
-
-               if (strcmp(afi->name, name) == 0)
-                       return CMD_RET_SUCCESS;
-       }
-       return CMD_RET_FAILURE;
-}
-
-static int do_afs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret = CMD_RET_SUCCESS;
-
-       if (argc == 1) {
-               print_images();
-       } else if (argc == 3 && !strcmp(argv[1], "exists")) {
-               ret = exists(argv[2]);
-       } else if (argc == 3 && !strcmp(argv[1], "load")) {
-               ret = load_image(argv[2], 0x0);
-       } else if (argc == 4 && !strcmp(argv[1], "load")) {
-               ulong load_addr;
-
-               load_addr = simple_strtoul(argv[3], NULL, 16);
-               ret = load_image(argv[2], load_addr);
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       return ret;
-}
-
-U_BOOT_CMD(afs, 4, 0, do_afs, "show AFS partitions",
-          "no arguments\n"
-          "    - list images in flash\n"
-          "exists <image>\n"
-          "    - returns 1 if an image exists, else 0\n"
-          "load <image>\n"
-          "    - load an image to the location indicated in the header\n"
-          "load <image> 0x<address>\n"
-          "    - load an image to the location specified\n");
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
deleted file mode 100644 (file)
index deed6d8..0000000
+++ /dev/null
@@ -1,574 +0,0 @@
-/*
- * (C) Copyright 2003
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <command.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-__maybe_unused
-static void print_num(const char *name, ulong value)
-{
-       printf("%-12s= 0x%08lX\n", name, value);
-}
-
-__maybe_unused
-static void print_eth(int idx)
-{
-       char name[10], *val;
-       if (idx)
-               sprintf(name, "eth%iaddr", idx);
-       else
-               strcpy(name, "ethaddr");
-       val = getenv(name);
-       if (!val)
-               val = "(not set)";
-       printf("%-12s= %s\n", name, val);
-}
-
-#ifndef CONFIG_DM_ETH
-__maybe_unused
-static void print_eths(void)
-{
-       struct eth_device *dev;
-       int i = 0;
-
-       do {
-               dev = eth_get_dev_by_index(i);
-               if (dev) {
-                       printf("eth%dname    = %s\n", i, dev->name);
-                       print_eth(i);
-                       i++;
-               }
-       } while (dev);
-
-       printf("current eth = %s\n", eth_get_name());
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-}
-#endif
-
-__maybe_unused
-static void print_lnum(const char *name, unsigned long long value)
-{
-       printf("%-12s= 0x%.8llX\n", name, value);
-}
-
-__maybe_unused
-static void print_mhz(const char *name, unsigned long hz)
-{
-       char buf[32];
-
-       printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
-}
-
-#if defined(CONFIG_PPC)
-void __weak board_detail(void)
-{
-       /* Please define boot_detail() for your platform */
-}
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-#ifdef DEBUG
-       print_num("bd address",         (ulong)bd);
-#endif
-       print_num("memstart",           bd->bi_memstart);
-       print_lnum("memsize",           bd->bi_memsize);
-       print_num("flashstart",         bd->bi_flashstart);
-       print_num("flashsize",          bd->bi_flashsize);
-       print_num("flashoffset",        bd->bi_flashoffset);
-       print_num("sramstart",          bd->bi_sramstart);
-       print_num("sramsize",           bd->bi_sramsize);
-#if    defined(CONFIG_5xx)  || defined(CONFIG_8xx) || \
-       defined(CONFIG_MPC8260) || defined(CONFIG_E500)
-       print_num("immr_base",          bd->bi_immr_base);
-#endif
-       print_num("bootflags",          bd->bi_bootflags);
-#if    defined(CONFIG_405EP) || \
-       defined(CONFIG_405GP) || \
-       defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
-       defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
-       defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
-       defined(CONFIG_XILINX_405)
-       print_mhz("procfreq",           bd->bi_procfreq);
-       print_mhz("plb_busfreq",        bd->bi_plb_busfreq);
-#if    defined(CONFIG_405EP) || defined(CONFIG_405GP) || \
-       defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
-       defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
-       defined(CONFIG_440SPE) || defined(CONFIG_XILINX_405)
-       print_mhz("pci_busfreq",        bd->bi_pci_busfreq);
-#endif
-#else  /* ! CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
-#if defined(CONFIG_CPM2)
-       print_mhz("vco",                bd->bi_vco);
-       print_mhz("sccfreq",            bd->bi_sccfreq);
-       print_mhz("brgfreq",            bd->bi_brgfreq);
-#endif
-       print_mhz("intfreq",            bd->bi_intfreq);
-#if defined(CONFIG_CPM2)
-       print_mhz("cpmfreq",            bd->bi_cpmfreq);
-#endif
-       print_mhz("busfreq",            bd->bi_busfreq);
-#endif /* CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
-
-#ifdef CONFIG_ENABLE_36BIT_PHYS
-#ifdef CONFIG_PHYS_64BIT
-       puts("addressing  = 36-bit\n");
-#else
-       puts("addressing  = 32-bit\n");
-#endif
-#endif
-
-       print_eth(0);
-#if defined(CONFIG_HAS_ETH1)
-       print_eth(1);
-#endif
-#if defined(CONFIG_HAS_ETH2)
-       print_eth(2);
-#endif
-#if defined(CONFIG_HAS_ETH3)
-       print_eth(3);
-#endif
-#if defined(CONFIG_HAS_ETH4)
-       print_eth(4);
-#endif
-#if defined(CONFIG_HAS_ETH5)
-       print_eth(5);
-#endif
-
-       printf("IP addr     = %s\n", getenv("ipaddr"));
-       printf("baudrate    = %6u bps\n", gd->baudrate);
-       print_num("relocaddr", gd->relocaddr);
-       board_detail();
-       return 0;
-}
-
-#elif defined(CONFIG_NIOS2)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       bd_t *bd = gd->bd;
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank",  i);
-               print_num("-> start",   bd->bi_dram[i].start);
-               print_num("-> size",    bd->bi_dram[i].size);
-       }
-
-       print_num("flash start",        (ulong)bd->bi_flashstart);
-       print_num("flash size",         (ulong)bd->bi_flashsize);
-       print_num("flash offset",       (ulong)bd->bi_flashoffset);
-
-#if defined(CONFIG_SYS_SRAM_BASE)
-       print_num ("sram start",        (ulong)bd->bi_sramstart);
-       print_num ("sram size",         (ulong)bd->bi_sramsize);
-#endif
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_MICROBLAZE)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-       int i;
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank",  i);
-               print_num("-> start",   bd->bi_dram[i].start);
-               print_num("-> size",    bd->bi_dram[i].size);
-       }
-
-       print_num("flash start    ",    (ulong)bd->bi_flashstart);
-       print_num("flash size     ",    (ulong)bd->bi_flashsize);
-       print_num("flash offset   ",    (ulong)bd->bi_flashoffset);
-#if defined(CONFIG_SYS_SRAM_BASE)
-       print_num("sram start     ",    (ulong)bd->bi_sramstart);
-       print_num("sram size      ",    (ulong)bd->bi_sramsize);
-#endif
-#if defined(CONFIG_CMD_NET)
-       print_eths();
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-       print_num("relocaddr", gd->relocaddr);
-       print_num("reloc off", gd->reloc_off);
-       print_num("fdt_blob", (ulong)gd->fdt_blob);
-       print_num("new_fdt", (ulong)gd->new_fdt);
-       print_num("fdt_size", (ulong)gd->fdt_size);
-
-       return 0;
-}
-
-#elif defined(CONFIG_SPARC)
-
-int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-#ifdef DEBUG
-       print_num("bd address             ", (ulong) bd);
-#endif
-       print_num("memstart               ", bd->bi_memstart);
-       print_lnum("memsize                ", bd->bi_memsize);
-       print_num("flashstart             ", bd->bi_flashstart);
-       print_num("CONFIG_SYS_MONITOR_BASE       ", CONFIG_SYS_MONITOR_BASE);
-       print_num("CONFIG_ENV_ADDR           ", CONFIG_ENV_ADDR);
-       printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%x (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
-              CONFIG_SYS_MONITOR_LEN);
-       printf("CONFIG_SYS_MALLOC_BASE        = 0x%x (%d)\n", CONFIG_SYS_MALLOC_BASE,
-              CONFIG_SYS_MALLOC_LEN);
-       printf("CONFIG_SYS_INIT_SP_OFFSET     = 0x%x (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
-              CONFIG_SYS_STACK_SIZE);
-       printf("CONFIG_SYS_PROM_OFFSET        = 0x%x (%d)\n", CONFIG_SYS_PROM_OFFSET,
-              CONFIG_SYS_PROM_SIZE);
-       printf("CONFIG_SYS_GBL_DATA_OFFSET    = 0x%x (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
-              GENERATED_GBL_DATA_SIZE);
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-       printf("baudrate               = %6u bps\n", gd->baudrate);
-       return 0;
-}
-
-#elif defined(CONFIG_M68K)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       print_num("memstart",           (ulong)bd->bi_memstart);
-       print_lnum("memsize",           (u64)bd->bi_memsize);
-       print_num("flashstart",         (ulong)bd->bi_flashstart);
-       print_num("flashsize",          (ulong)bd->bi_flashsize);
-       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
-#if defined(CONFIG_SYS_INIT_RAM_ADDR)
-       print_num("sramstart",          (ulong)bd->bi_sramstart);
-       print_num("sramsize",           (ulong)bd->bi_sramsize);
-#endif
-#if defined(CONFIG_SYS_MBAR)
-       print_num("mbar",               bd->bi_mbar_base);
-#endif
-       print_mhz("cpufreq",            bd->bi_intfreq);
-       print_mhz("busfreq",            bd->bi_busfreq);
-#ifdef CONFIG_PCI
-       print_mhz("pcifreq",            bd->bi_pcifreq);
-#endif
-#ifdef CONFIG_EXTRA_CLOCK
-       print_mhz("flbfreq",            bd->bi_flbfreq);
-       print_mhz("inpfreq",            bd->bi_inpfreq);
-       print_mhz("vcofreq",            bd->bi_vcofreq);
-#endif
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-#if defined(CONFIG_HAS_ETH1)
-       print_eth(1);
-#endif
-#if defined(CONFIG_HAS_ETH2)
-       print_eth(2);
-#endif
-#if defined(CONFIG_HAS_ETH3)
-       print_eth(3);
-#endif
-
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_BLACKFIN)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       printf("U-Boot      = %s\n", bd->bi_r_version);
-       printf("CPU         = %s\n", bd->bi_cpu);
-       printf("Board       = %s\n", bd->bi_board_name);
-       print_mhz("VCO",        bd->bi_vco);
-       print_mhz("CCLK",       bd->bi_cclk);
-       print_mhz("SCLK",       bd->bi_sclk);
-
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-       print_num("memstart",           (ulong)bd->bi_memstart);
-       print_lnum("memsize",           (u64)bd->bi_memsize);
-       print_num("flashstart",         (ulong)bd->bi_flashstart);
-       print_num("flashsize",          (ulong)bd->bi_flashsize);
-       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
-
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_MIPS)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-       print_num("memstart",           (ulong)bd->bi_memstart);
-       print_lnum("memsize",           (u64)bd->bi_memsize);
-       print_num("flashstart",         (ulong)bd->bi_flashstart);
-       print_num("flashsize",          (ulong)bd->bi_flashsize);
-       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
-
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_AVR32)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-       print_num("memstart",           (ulong)bd->bi_dram[0].start);
-       print_lnum("memsize",           (u64)bd->bi_dram[0].size);
-       print_num("flashstart",         (ulong)bd->bi_flashstart);
-       print_num("flashsize",          (ulong)bd->bi_flashsize);
-       print_num("flashoffset",        (ulong)bd->bi_flashoffset);
-
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_ARM)
-
-static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       int i;
-       bd_t *bd = gd->bd;
-
-       print_num("arch_number",        bd->bi_arch_number);
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank",  i);
-               print_num("-> start",   bd->bi_dram[i].start);
-               print_num("-> size",    bd->bi_dram[i].size);
-       }
-
-#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
-       if (gd->secure_ram & MEM_RESERVE_SECURE_SECURED) {
-               print_num("Secure ram",
-                         gd->secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
-       }
-#endif
-#if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
-       print_eths();
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
-       print_num("TLB addr", gd->arch.tlb_addr);
-#endif
-       print_num("relocaddr", gd->relocaddr);
-       print_num("reloc off", gd->reloc_off);
-       print_num("irq_sp", gd->irq_sp);        /* irq stack pointer */
-       print_num("sp start ", gd->start_addr_sp);
-#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
-       print_num("FB base  ", gd->fb_base);
-#endif
-       /*
-        * TODO: Currently only support for davinci SOC's is added.
-        * Remove this check once all the board implement this.
-        */
-#ifdef CONFIG_CLOCKS
-       printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
-       printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
-       printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
-#endif
-#ifdef CONFIG_BOARD_TYPES
-       printf("Board Type  = %ld\n", gd->board_type);
-#endif
-       return 0;
-}
-
-#elif defined(CONFIG_SH)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-       print_num("mem start      ",    (ulong)bd->bi_memstart);
-       print_lnum("mem size       ",   (u64)bd->bi_memsize);
-       print_num("flash start    ",    (ulong)bd->bi_flashstart);
-       print_num("flash size     ",    (ulong)bd->bi_flashsize);
-       print_num("flash offset   ",    (ulong)bd->bi_flashoffset);
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-       return 0;
-}
-
-#elif defined(CONFIG_X86)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       bd_t *bd = gd->bd;
-
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-       print_num("bi_memstart",        bd->bi_memstart);
-       print_num("bi_memsize",         bd->bi_memsize);
-       print_num("bi_flashstart",      bd->bi_flashstart);
-       print_num("bi_flashsize",       bd->bi_flashsize);
-       print_num("bi_flashoffset",     bd->bi_flashoffset);
-       print_num("bi_sramstart",       bd->bi_sramstart);
-       print_num("bi_sramsize",        bd->bi_sramsize);
-       print_num("bi_bootflags",       bd->bi_bootflags);
-       print_mhz("cpufreq",            bd->bi_intfreq);
-       print_mhz("busfreq",            bd->bi_busfreq);
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank",  i);
-               print_num("-> start",   bd->bi_dram[i].start);
-               print_num("-> size",    bd->bi_dram[i].size);
-       }
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-       print_mhz("ethspeed",       bd->bi_ethspeed);
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_SANDBOX)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       bd_t *bd = gd->bd;
-
-       print_num("boot_params", (ulong)bd->bi_boot_params);
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank", i);
-               print_num("-> start", bd->bi_dram[i].start);
-               print_num("-> size", bd->bi_dram[i].size);
-       }
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
-       print_num("FB base  ", gd->fb_base);
-#endif
-       return 0;
-}
-
-#elif defined(CONFIG_NDS32)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       bd_t *bd = gd->bd;
-
-       print_num("arch_number",        bd->bi_arch_number);
-       print_num("boot_params",        (ulong)bd->bi_boot_params);
-
-       for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
-               print_num("DRAM bank",  i);
-               print_num("-> start",   bd->bi_dram[i].start);
-               print_num("-> size",    bd->bi_dram[i].size);
-       }
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_OPENRISC)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       print_num("mem start",          (ulong)bd->bi_memstart);
-       print_lnum("mem size",          (u64)bd->bi_memsize);
-       print_num("flash start",        (ulong)bd->bi_flashstart);
-       print_num("flash size",         (ulong)bd->bi_flashsize);
-       print_num("flash offset",       (ulong)bd->bi_flashoffset);
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-
-       printf("baudrate    = %u bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#elif defined(CONFIG_ARC)
-
-int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bd_t *bd = gd->bd;
-
-       print_num("mem start",          bd->bi_memstart);
-       print_lnum("mem size",          bd->bi_memsize);
-
-#if defined(CONFIG_CMD_NET)
-       print_eth(0);
-       printf("ip_addr     = %s\n", getenv("ipaddr"));
-#endif
-       printf("baudrate    = %d bps\n", gd->baudrate);
-
-       return 0;
-}
-
-#else
- #error "a case for this architecture does not exist!"
-#endif
-
-/* -------------------------------------------------------------------- */
-
-U_BOOT_CMD(
-       bdinfo, 1,      1,      do_bdinfo,
-       "print Board Info structure",
-       ""
-);
diff --git a/common/cmd_bedbug.c b/common/cmd_bedbug.c
deleted file mode 100644 (file)
index 69afeaf..0000000
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * BedBug Functions
- */
-
-#include <common.h>
-#include <cli.h>
-#include <command.h>
-#include <console.h>
-#include <linux/ctype.h>
-#include <net.h>
-#include <bedbug/type.h>
-#include <bedbug/bedbug.h>
-#include <bedbug/regs.h>
-#include <bedbug/ppc.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-extern void show_regs __P ((struct pt_regs *));
-extern int run_command __P ((const char *, int));
-
-ulong dis_last_addr = 0;       /* Last address disassembled   */
-ulong dis_last_len = 20;       /* Default disassembler length */
-CPU_DEBUG_CTX bug_ctx;         /* Bedbug context structure    */
-
-
-/* ======================================================================
- * U-Boot's puts function does not append a newline, so the bedbug stuff
- * will use this for the output of the dis/assembler.
- * ====================================================================== */
-
-int bedbug_puts (const char *str)
-{
-       /* -------------------------------------------------- */
-
-       printf ("%s\r\n", str);
-       return 0;
-}                              /* bedbug_puts */
-
-
-
-/* ======================================================================
- * Initialize the bug_ctx structure used by the bedbug debugger.  This is
- * specific to the CPU since each has different debug registers and
- * settings.
- * ====================================================================== */
-
-void bedbug_init (void)
-{
-       /* -------------------------------------------------- */
-
-#if defined(CONFIG_4xx)
-       void bedbug405_init (void);
-
-       bedbug405_init ();
-#elif defined(CONFIG_8xx)
-       void bedbug860_init (void);
-
-       bedbug860_init ();
-#endif
-
-#if defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260)
-       /* Processors that are 603e core based */
-       void bedbug603e_init (void);
-
-       bedbug603e_init ();
-#endif
-
-       return;
-}                              /* bedbug_init */
-
-
-
-/* ======================================================================
- * Entry point from the interpreter to the disassembler.  Repeated calls
- * will resume from the last disassembled address.
- * ====================================================================== */
-int do_bedbug_dis (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr;             /* Address to start disassembly from    */
-       ulong len;              /* # of instructions to disassemble     */
-
-       /* -------------------------------------------------- */
-
-       /* Setup to go from the last address if none is given */
-       addr = dis_last_addr;
-       len = dis_last_len;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /* New command */
-               addr = simple_strtoul (argv[1], NULL, 16);
-
-               /* If an extra param is given then it is the length */
-               if (argc > 2)
-                       len = simple_strtoul (argv[2], NULL, 16);
-       }
-
-       /* Run the disassembler */
-       disppc ((unsigned char *) addr, 0, len, bedbug_puts, F_RADHEX);
-
-       dis_last_addr = addr + (len * 4);
-       dis_last_len = len;
-       return 0;
-}                              /* do_bedbug_dis */
-
-U_BOOT_CMD (ds, 3, 1, do_bedbug_dis,
-           "disassemble memory",
-           "ds <address> [# instructions]");
-
-/* ======================================================================
- * Entry point from the interpreter to the assembler.  Assembles
- * instructions in consecutive memory locations until a '.' (period) is
- * entered on a line by itself.
- * ====================================================================== */
-int do_bedbug_asm (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       long mem_addr;          /* Address to assemble into     */
-       unsigned long instr;    /* Machine code for text        */
-       char prompt[15];        /* Prompt string for user input */
-       int asm_err;            /* Error code from the assembler */
-
-       /* -------------------------------------------------- */
-       int rcode = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       printf ("\nEnter '.' when done\n");
-       mem_addr = simple_strtoul (argv[1], NULL, 16);
-
-       while (1) {
-               putc ('\n');
-               disppc ((unsigned char *) mem_addr, 0, 1, bedbug_puts,
-                       F_RADHEX);
-
-               sprintf (prompt, "%08lx:    ", mem_addr);
-               cli_readline(prompt);
-
-               if (console_buffer[0] && strcmp (console_buffer, ".")) {
-                       if ((instr =
-                            asmppc (mem_addr, console_buffer,
-                                    &asm_err)) != 0) {
-                               *(unsigned long *) mem_addr = instr;
-                               mem_addr += 4;
-                       } else {
-                               printf ("*** Error: %s ***\n",
-                                       asm_error_str (asm_err));
-                               rcode = 1;
-                       }
-               } else {
-                       break;
-               }
-       }
-       return rcode;
-}                              /* do_bedbug_asm */
-
-U_BOOT_CMD (as, 2, 0, do_bedbug_asm,
-           "assemble memory", "as <address>");
-
-/* ======================================================================
- * Used to set a break point from the interpreter.  Simply calls into the
- * CPU-specific break point set routine.
- * ====================================================================== */
-
-int do_bedbug_break (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       /* -------------------------------------------------- */
-       if (bug_ctx.do_break)
-               (*bug_ctx.do_break) (cmdtp, flag, argc, argv);
-       return 0;
-
-}                              /* do_bedbug_break */
-
-U_BOOT_CMD (break, 3, 0, do_bedbug_break,
-           "set or clear a breakpoint",
-           " - Set or clear a breakpoint\n"
-           "break <address> - Break at an address\n"
-           "break off <bp#> - Disable breakpoint.\n"
-           "break show      - List breakpoints.");
-
-/* ======================================================================
- * Called from the debug interrupt routine.  Simply calls the CPU-specific
- * breakpoint handling routine.
- * ====================================================================== */
-
-void do_bedbug_breakpoint (struct pt_regs *regs)
-{
-       /* -------------------------------------------------- */
-
-       if (bug_ctx.break_isr)
-               (*bug_ctx.break_isr) (regs);
-
-       return;
-}                              /* do_bedbug_breakpoint */
-
-
-
-/* ======================================================================
- * Called from the CPU-specific breakpoint handling routine.  Enter a
- * mini main loop until the stopped flag is cleared from the breakpoint
- * context.
- *
- * This handles the parts of the debugger that are common to all CPU's.
- * ====================================================================== */
-
-void bedbug_main_loop (unsigned long addr, struct pt_regs *regs)
-{
-       int len;                /* Length of command line */
-       int flag;               /* Command flags          */
-       int rc = 0;             /* Result from run_command */
-       char prompt_str[20];    /* Prompt string          */
-       static char lastcommand[CONFIG_SYS_CBSIZE] = { 0 };     /* previous command */
-       /* -------------------------------------------------- */
-
-       if (bug_ctx.clear)
-               (*bug_ctx.clear) (bug_ctx.current_bp);
-
-       printf ("Breakpoint %d: ", bug_ctx.current_bp);
-       disppc ((unsigned char *) addr, 0, 1, bedbug_puts, F_RADHEX);
-
-       bug_ctx.stopped = 1;
-       bug_ctx.regs = regs;
-
-       sprintf (prompt_str, "BEDBUG.%d =>", bug_ctx.current_bp);
-
-       /* A miniature main loop */
-       while (bug_ctx.stopped) {
-               len = cli_readline(prompt_str);
-
-               flag = 0;       /* assume no special flags for now */
-
-               if (len > 0)
-                       strcpy (lastcommand, console_buffer);
-               else if (len == 0)
-                       flag |= CMD_FLAG_REPEAT;
-
-               if (len == -1)
-                       printf ("<INTERRUPT>\n");
-               else
-                       rc = run_command_repeatable(lastcommand, flag);
-
-               if (rc <= 0) {
-                       /* invalid command or not repeatable, forget it */
-                       lastcommand[0] = 0;
-               }
-       }
-
-       bug_ctx.regs = NULL;
-       bug_ctx.current_bp = 0;
-
-       return;
-}                              /* bedbug_main_loop */
-
-
-
-/* ======================================================================
- * Interpreter command to continue from a breakpoint.  Just clears the
- * stopped flag in the context so that the breakpoint routine will
- * return.
- * ====================================================================== */
-int do_bedbug_continue (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       /* -------------------------------------------------- */
-
-       if (!bug_ctx.stopped) {
-               printf ("Not at a breakpoint\n");
-               return 1;
-       }
-
-       bug_ctx.stopped = 0;
-       return 0;
-}                              /* do_bedbug_continue */
-
-U_BOOT_CMD (continue, 1, 0, do_bedbug_continue,
-           "continue from a breakpoint",
-           "");
-
-/* ======================================================================
- * Interpreter command to continue to the next instruction, stepping into
- * subroutines.  Works by calling the find_next_addr() routine to compute
- * the address passes control to the CPU-specific set breakpoint routine
- * for the current breakpoint number.
- * ====================================================================== */
-int do_bedbug_step (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long addr;     /* Address to stop at */
-
-       /* -------------------------------------------------- */
-
-       if (!bug_ctx.stopped) {
-               printf ("Not at a breakpoint\n");
-               return 1;
-       }
-
-       if (!find_next_address((unsigned char *) &addr, false, bug_ctx.regs))
-               return 1;
-
-       if (bug_ctx.set)
-               (*bug_ctx.set) (bug_ctx.current_bp, addr);
-
-       bug_ctx.stopped = 0;
-       return 0;
-}                              /* do_bedbug_step */
-
-U_BOOT_CMD (step, 1, 1, do_bedbug_step,
-           "single step execution.",
-           "");
-
-/* ======================================================================
- * Interpreter command to continue to the next instruction, stepping over
- * subroutines.  Works by calling the find_next_addr() routine to compute
- * the address passes control to the CPU-specific set breakpoint routine
- * for the current breakpoint number.
- * ====================================================================== */
-int do_bedbug_next (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long addr;     /* Address to stop at */
-
-       /* -------------------------------------------------- */
-
-       if (!bug_ctx.stopped) {
-               printf ("Not at a breakpoint\n");
-               return 1;
-       }
-
-       if (!find_next_address((unsigned char *) &addr, true, bug_ctx.regs))
-               return 1;
-
-       if (bug_ctx.set)
-               (*bug_ctx.set) (bug_ctx.current_bp, addr);
-
-       bug_ctx.stopped = 0;
-       return 0;
-}                              /* do_bedbug_next */
-
-U_BOOT_CMD (next, 1, 1, do_bedbug_next,
-           "single step execution, stepping over subroutines.",
-           "");
-
-/* ======================================================================
- * Interpreter command to print the current stack.  This assumes an EABI
- * architecture, so it starts with GPR R1 and works back up the stack.
- * ====================================================================== */
-int do_bedbug_stack (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long sp;       /* Stack pointer                */
-       unsigned long func;     /* LR from stack                */
-       int depth;              /* Stack iteration level        */
-       int skip = 1;           /* Flag to skip the first entry */
-       unsigned long top;      /* Top of memory address        */
-
-       /* -------------------------------------------------- */
-
-       if (!bug_ctx.stopped) {
-               printf ("Not at a breakpoint\n");
-               return 1;
-       }
-
-       top = gd->bd->bi_memstart + gd->bd->bi_memsize;
-       depth = 0;
-
-       printf ("Depth     PC\n");
-       printf ("-----  --------\n");
-       printf ("%5d  %08lx\n", depth++, bug_ctx.regs->nip);
-
-       sp = bug_ctx.regs->gpr[1];
-       func = *(unsigned long *) (sp + 4);
-
-       while ((func < top) && (sp < top)) {
-               if (!skip)
-                       printf ("%5d  %08lx\n", depth++, func);
-               else
-                       --skip;
-
-               sp = *(unsigned long *) sp;
-               func = *(unsigned long *) (sp + 4);
-       }
-       return 0;
-}                              /* do_bedbug_stack */
-
-U_BOOT_CMD (where, 1, 1, do_bedbug_stack,
-           "Print the running stack.",
-           "");
-
-/* ======================================================================
- * Interpreter command to dump the registers.  Calls the CPU-specific
- * show registers routine.
- * ====================================================================== */
-int do_bedbug_rdump (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       /* -------------------------------------------------- */
-
-       if (!bug_ctx.stopped) {
-               printf ("Not at a breakpoint\n");
-               return 1;
-       }
-
-       show_regs (bug_ctx.regs);
-       return 0;
-}                              /* do_bedbug_rdump */
-
-U_BOOT_CMD (rdump, 1, 1, do_bedbug_rdump,
-           "Show registers.", "");
-/* ====================================================================== */
-
-
-/*
- * Copyright (c) 2001 William L. Pitts
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are freely
- * permitted provided that the above copyright notice and this
- * paragraph and the following disclaimer are duplicated in all
- * such forms.
- *
- * This software is provided "AS IS" and without any express or
- * implied warranties, including, without limitation, the implied
- * warranties of merchantability and fitness for a particular
- * purpose.
- */
diff --git a/common/cmd_blob.c b/common/cmd_blob.c
deleted file mode 100644 (file)
index ac8b268..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- *
- * Command for encapsulating/decapsulating blob of memory.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <environment.h>
-#include <malloc.h>
-#include <asm/byteorder.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/**
- * blob_decap() - Decapsulate the data as a blob
- * @key_mod:   - Pointer to key modifier/key
- * @src:       - Address of data to be decapsulated
- * @dst:       - Address of data to be decapsulated
- * @len:       - Size of data to be decapsulated
- *
- * Returns zero on success,and negative on error.
- */
-__weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
-{
-       return 0;
-}
-
-/**
- * blob_encap() - Encapsulate the data as a blob
- * @key_mod:   - Pointer to key modifier/key
- * @src:       - Address of data to be encapsulated
- * @dst:       - Address of data to be encapsulated
- * @len:       - Size of data to be encapsulated
- *
- * Returns zero on success,and negative on error.
- */
-__weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
-{
-       return 0;
-}
-
-/**
- * do_blob() - Handle the "blob" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       uint32_t key_addr, src_addr, dst_addr, len;
-       uint8_t *km_ptr, *src_ptr, *dst_ptr;
-       int enc, ret = 0;
-
-       if (argc != 6)
-               return CMD_RET_USAGE;
-
-       if (!strncmp(argv[1], "enc", 3))
-               enc = 1;
-       else if (!strncmp(argv[1], "dec", 3))
-               enc = 0;
-       else
-               return CMD_RET_USAGE;
-
-       src_addr = simple_strtoul(argv[2], NULL, 16);
-       dst_addr = simple_strtoul(argv[3], NULL, 16);
-       len = simple_strtoul(argv[4], NULL, 16);
-       key_addr = simple_strtoul(argv[5], NULL, 16);
-
-       km_ptr = (uint8_t *)(uintptr_t)key_addr;
-       src_ptr = (uint8_t *)(uintptr_t)src_addr;
-       dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
-
-       if (enc)
-               ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
-       else
-               ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
-
-       return ret;
-}
-
-/***************************************************/
-static char blob_help_text[] =
-       "enc src dst len km - Encapsulate and create blob of data\n"
-       "                          $len bytes long at address $src and\n"
-       "                          store the result at address $dst.\n"
-       "                          $km is the address where the key\n"
-       "                          modifier is stored.\n"
-       "                          The modifier is required for generation\n"
-       "                          /use as key for cryptographic operation.\n"
-       "                          Key modifier should be 16 byte long.\n"
-       "blob dec src dst len km - Decapsulate the  blob of data at address\n"
-       "                          $src and store result of $len byte at\n"
-       "                          addr $dst.\n"
-       "                          $km is the address where the key\n"
-       "                          modifier is stored.\n"
-       "                          The modifier is required for generation\n"
-       "                          /use as key for cryptographic operation.\n"
-       "                          Key modifier should be 16 byte long.\n";
-
-U_BOOT_CMD(
-       blob, 6, 1, do_blob,
-       "Blob encapsulation/decryption",
-       blob_help_text
-);
diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c
deleted file mode 100644 (file)
index fd5b7db..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * (C) Copyright 2002
- * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * BMP handling routines
- */
-
-#include <common.h>
-#include <dm.h>
-#include <lcd.h>
-#include <mapmem.h>
-#include <bmp_layout.h>
-#include <command.h>
-#include <asm/byteorder.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <splash.h>
-#include <video.h>
-
-static int bmp_info (ulong addr);
-
-/*
- * Allocate and decompress a BMP image using gunzip().
- *
- * Returns a pointer to the decompressed image data. This pointer is
- * aligned to 32-bit-aligned-address + 2.
- * See doc/README.displaying-bmps for explanation.
- *
- * The allocation address is passed to 'alloc_addr' and must be freed
- * by the caller after use.
- *
- * Returns NULL if decompression failed, or if the decompressed data
- * didn't contain a valid BMP signature.
- */
-#ifdef CONFIG_VIDEO_BMP_GZIP
-struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
-                            void **alloc_addr)
-{
-       void *dst;
-       unsigned long len;
-       struct bmp_image *bmp;
-
-       /*
-        * Decompress bmp image
-        */
-       len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
-       /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
-       dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3);
-       if (dst == NULL) {
-               puts("Error: malloc in gunzip failed!\n");
-               return NULL;
-       }
-
-       bmp = dst;
-
-       /* align to 32-bit-aligned-address + 2 */
-       bmp = (struct bmp_image *)((((unsigned int)dst + 1) & ~3) + 2);
-
-       if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
-                  &len) != 0) {
-               free(dst);
-               return NULL;
-       }
-       if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
-               puts("Image could be truncated"
-                               " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
-
-       /*
-        * Check for bmp mark 'BM'
-        */
-       if (!((bmp->header.signature[0] == 'B') &&
-             (bmp->header.signature[1] == 'M'))) {
-               free(dst);
-               return NULL;
-       }
-
-       debug("Gzipped BMP image detected!\n");
-
-       *alloc_addr = dst;
-       return bmp;
-}
-#else
-struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
-                            void **alloc_addr)
-{
-       return NULL;
-}
-#endif
-
-static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr;
-
-       switch (argc) {
-       case 1:         /* use load_addr as default address */
-               addr = load_addr;
-               break;
-       case 2:         /* use argument */
-               addr = simple_strtoul(argv[1], NULL, 16);
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       return (bmp_info(addr));
-}
-
-static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr;
-       int x = 0, y = 0;
-
-       splash_get_pos(&x, &y);
-
-       switch (argc) {
-       case 1:         /* use load_addr as default address */
-               addr = load_addr;
-               break;
-       case 2:         /* use argument */
-               addr = simple_strtoul(argv[1], NULL, 16);
-               break;
-       case 4:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               x = simple_strtoul(argv[2], NULL, 10);
-               y = simple_strtoul(argv[3], NULL, 10);
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-        return (bmp_display(addr, x, y));
-}
-
-static cmd_tbl_t cmd_bmp_sub[] = {
-       U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""),
-       U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
-};
-
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-void bmp_reloc(void) {
-       fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
-}
-#endif
-
-/*
- * Subroutine:  do_bmp
- *
- * Description: Handler for 'bmp' command..
- *
- * Inputs:     argv[1] contains the subcommand
- *
- * Return:      None
- *
- */
-static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *c;
-
-       /* Strip off leading 'bmp' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub));
-
-       if (c)
-               return  c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       bmp,    5,      1,      do_bmp,
-       "manipulate BMP image data",
-       "info <imageAddr>          - display image info\n"
-       "bmp display <imageAddr> [x y] - display image at x,y"
-);
-
-/*
- * Subroutine:  bmp_info
- *
- * Description: Show information about bmp file in memory
- *
- * Inputs:     addr            address of the bmp file
- *
- * Return:      None
- *
- */
-static int bmp_info(ulong addr)
-{
-       struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
-       void *bmp_alloc_addr = NULL;
-       unsigned long len;
-
-       if (!((bmp->header.signature[0]=='B') &&
-             (bmp->header.signature[1]=='M')))
-               bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
-
-       if (bmp == NULL) {
-               printf("There is no valid bmp file at the given address\n");
-               return 1;
-       }
-
-       printf("Image size    : %d x %d\n", le32_to_cpu(bmp->header.width),
-              le32_to_cpu(bmp->header.height));
-       printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
-       printf("Compression   : %d\n", le32_to_cpu(bmp->header.compression));
-
-       if (bmp_alloc_addr)
-               free(bmp_alloc_addr);
-
-       return(0);
-}
-
-/*
- * Subroutine:  bmp_display
- *
- * Description: Display bmp file located in memory
- *
- * Inputs:     addr            address of the bmp file
- *
- * Return:      None
- *
- */
-int bmp_display(ulong addr, int x, int y)
-{
-#ifdef CONFIG_DM_VIDEO
-       struct udevice *dev;
-#endif
-       int ret;
-       struct bmp_image *bmp = map_sysmem(addr, 0);
-       void *bmp_alloc_addr = NULL;
-       unsigned long len;
-
-       if (!((bmp->header.signature[0]=='B') &&
-             (bmp->header.signature[1]=='M')))
-               bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
-
-       if (!bmp) {
-               printf("There is no valid bmp file at the given address\n");
-               return 1;
-       }
-       addr = map_to_sysmem(bmp);
-
-#ifdef CONFIG_DM_VIDEO
-       ret = uclass_first_device(UCLASS_VIDEO, &dev);
-       if (!ret) {
-               if (!dev)
-                       ret = -ENODEV;
-               if (!ret) {
-                       bool align = false;
-
-# ifdef CONFIG_SPLASH_SCREEN_ALIGN
-                       align = true;
-# endif /* CONFIG_SPLASH_SCREEN_ALIGN */
-                       ret = video_bmp_display(dev, addr, x, y, align);
-               }
-       }
-       return ret ? CMD_RET_FAILURE : 0;
-#elif defined(CONFIG_LCD)
-       ret = lcd_display_bitmap(addr, x, y);
-#elif defined(CONFIG_VIDEO)
-       ret = video_display_bitmap(addr, x, y);
-#else
-# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
-#endif
-
-       if (bmp_alloc_addr)
-               free(bmp_alloc_addr);
-
-       return ret;
-}
diff --git a/common/cmd_boot.c b/common/cmd_boot.c
deleted file mode 100644 (file)
index 72f2cf3..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * (C) Copyright 2000-2003
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Misc boot support
- */
-#include <common.h>
-#include <command.h>
-#include <net.h>
-
-#ifdef CONFIG_CMD_GO
-
-/* Allow ports to override the default behavior */
-__attribute__((weak))
-unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
-                                char * const argv[])
-{
-       return entry (argc, argv);
-}
-
-static int do_go(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong   addr, rc;
-       int     rcode = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       addr = simple_strtoul(argv[1], NULL, 16);
-
-       printf ("## Starting application at 0x%08lX ...\n", addr);
-
-       /*
-        * pass address parameter as argv[0] (aka command name),
-        * and all remaining args
-        */
-       rc = do_go_exec ((void *)addr, argc - 1, argv + 1);
-       if (rc != 0) rcode = 1;
-
-       printf ("## Application terminated, rc = 0x%lX\n", rc);
-       return rcode;
-}
-
-/* -------------------------------------------------------------------- */
-
-U_BOOT_CMD(
-       go, CONFIG_SYS_MAXARGS, 1,      do_go,
-       "start application at address 'addr'",
-       "addr [arg ...]\n    - start application at address 'addr'\n"
-       "      passing 'arg' as arguments"
-);
-
-#endif
-
-U_BOOT_CMD(
-       reset, 1, 0,    do_reset,
-       "Perform RESET of the CPU",
-       ""
-);
-
-#ifdef CONFIG_CMD_POWEROFF
-U_BOOT_CMD(
-       poweroff, 1, 0, do_poweroff,
-       "Perform POWEROFF of the device",
-       ""
-);
-#endif
diff --git a/common/cmd_bootldr.c b/common/cmd_bootldr.c
deleted file mode 100644 (file)
index bc5c1f9..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * U-boot - bootldr.c
- *
- * Copyright (c) 2005-2008 Analog Devices Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <config.h>
-#include <common.h>
-#include <command.h>
-
-#include <asm/blackfin.h>
-#include <asm/mach-common/bits/bootrom.h>
-
-/* Simple sanity check on the specified address to make sure it contains
- * an LDR image of some sort.
- */
-static bool ldr_valid_signature(uint8_t *data)
-{
-#if defined(__ADSPBF561__)
-
-       /* BF56x has a 4 byte global header */
-       if (data[3] == (GFLAG_56X_SIGN_MAGIC << (GFLAG_56X_SIGN_SHIFT - 24)))
-               return true;
-
-#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
-      defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
-      defined(__ADSPBF538__) || defined(__ADSPBF539__)
-
-       /* all the BF53x should start at this address mask */
-       uint32_t addr;
-       memmove(&addr, data, sizeof(addr));
-       if ((addr & 0xFF0FFF0F) == 0xFF000000)
-               return true;
-#else
-
-       /* everything newer has a magic byte */
-       uint32_t count;
-       memmove(&count, data + 8, sizeof(count));
-       if (data[3] == 0xAD && count == 0)
-               return true;
-
-#endif
-
-       return false;
-}
-
-/* If the Blackfin is new enough, the Blackfin on-chip ROM supports loading
- * LDRs from random memory addresses.  So whenever possible, use that.  In
- * the older cases (BF53x/BF561), parse the LDR format ourselves.
- */
-static void ldr_load(uint8_t *base_addr)
-{
-#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
-  /*defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) ||*/\
-    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
-
-       uint32_t addr;
-       uint32_t count;
-       uint16_t flags;
-
-       /* the bf56x has a 4 byte global header ... but it is useless to
-        * us when booting an LDR from a memory address, so skip it
-        */
-# ifdef __ADSPBF561__
-       base_addr += 4;
-# endif
-
-       memmove(&flags, base_addr + 8, sizeof(flags));
-       bfin_write_EVT1(flags & BFLAG_53X_RESVECT ? 0xFFA00000 : 0xFFA08000);
-
-       do {
-               /* block header may not be aligned */
-               memmove(&addr, base_addr, sizeof(addr));
-               memmove(&count, base_addr+4, sizeof(count));
-               memmove(&flags, base_addr+8, sizeof(flags));
-               base_addr += sizeof(addr) + sizeof(count) + sizeof(flags);
-
-               printf("loading to 0x%08x (%#x bytes) flags: 0x%04x\n",
-                       addr, count, flags);
-
-               if (!(flags & BFLAG_53X_IGNORE)) {
-                       if (flags & BFLAG_53X_ZEROFILL)
-                               memset((void *)addr, 0x00, count);
-                       else
-                               memcpy((void *)addr, base_addr, count);
-
-                       if (flags & BFLAG_53X_INIT) {
-                               void (*init)(void) = (void *)addr;
-                               init();
-                       }
-               }
-
-               if (!(flags & BFLAG_53X_ZEROFILL))
-                       base_addr += count;
-       } while (!(flags & BFLAG_53X_FINAL));
-
-#endif
-}
-
-/* For BF537, we use the _BOOTROM_BOOT_DXE_FLASH funky ROM function.
- * For all other BF53x/BF56x, we just call the entry point.
- * For everything else (newer), we use _BOOTROM_MEMBOOT ROM function.
- */
-static void ldr_exec(void *addr)
-{
-#if defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
-
-       /* restore EVT1 to reset value as this is what the bootrom uses as
-        * the default entry point when booting the final block of LDRs
-        */
-       bfin_write_EVT1(L1_INST_SRAM);
-       __asm__("call (%0);" : : "a"(_BOOTROM_MEMBOOT), "q7"(addr) : "RETS", "memory");
-
-#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
-      defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
-
-       void (*ldr_entry)(void) = (void *)bfin_read_EVT1();
-       ldr_entry();
-
-#else
-
-       int32_t (*BOOTROM_MEM)(void *, int32_t, int32_t, void *) = (void *)_BOOTROM_MEMBOOT;
-       BOOTROM_MEM(addr, 0, 0, NULL);
-
-#endif
-}
-
-/*
- * the bootldr command loads an address, checks to see if there
- *   is a Boot stream that the on-chip BOOTROM can understand,
- *   and loads it via the BOOTROM Callback. It is possible
- *   to also add booting from SPI, or TWI, but this function does
- *   not currently support that.
- */
-int do_bootldr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       void *addr;
-
-       /* Get the address */
-       if (argc < 2)
-               addr = (void *)load_addr;
-       else
-               addr = (void *)simple_strtoul(argv[1], NULL, 16);
-
-       /* Check if it is a LDR file */
-       if (ldr_valid_signature(addr)) {
-               printf("## Booting ldr image at 0x%p ...\n", addr);
-               ldr_load(addr);
-
-               icache_disable();
-               dcache_disable();
-
-               ldr_exec(addr);
-       } else
-               printf("## No ldr image at address 0x%p\n", addr);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       bootldr, 2, 0, do_bootldr,
-       "boot ldr image from memory",
-       "[addr]\n"
-       ""
-);
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
deleted file mode 100644 (file)
index 48738ac..0000000
+++ /dev/null
@@ -1,775 +0,0 @@
-/*
- * (C) Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <bootm.h>
-#include <command.h>
-#include <environment.h>
-#include <errno.h>
-#include <image.h>
-#include <lmb.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <nand.h>
-#include <asm/byteorder.h>
-#include <linux/compiler.h>
-#include <linux/ctype.h>
-#include <linux/err.h>
-#include <u-boot/zlib.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#if defined(CONFIG_CMD_IMI)
-static int image_info(unsigned long addr);
-#endif
-
-#if defined(CONFIG_CMD_IMLS)
-#include <flash.h>
-#include <mtd/cfi_flash.h>
-extern flash_info_t flash_info[]; /* info for FLASH chips */
-#endif
-
-#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
-static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-#endif
-
-bootm_headers_t images;                /* pointers to os/initrd/fdt images */
-
-/* we overload the cmd field with our state machine info instead of a
- * function pointer */
-static cmd_tbl_t cmd_bootm_sub[] = {
-       U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
-       U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
-#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
-       U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
-#endif
-#ifdef CONFIG_OF_LIBFDT
-       U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
-       U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
-       U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
-       U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
-       U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
-};
-
-static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       int ret = 0;
-       long state;
-       cmd_tbl_t *c;
-
-       c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
-       argc--; argv++;
-
-       if (c) {
-               state = (long)c->cmd;
-               if (state == BOOTM_STATE_START)
-                       state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
-       } else {
-               /* Unrecognized command */
-               return CMD_RET_USAGE;
-       }
-
-       if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) &&
-           images.state >= state) {
-               printf("Trying to execute a command out of order\n");
-               return CMD_RET_USAGE;
-       }
-
-       ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
-
-       return ret;
-}
-
-/*******************************************************************/
-/* bootm - boot application image from image in memory */
-/*******************************************************************/
-
-int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-       static int relocated = 0;
-
-       if (!relocated) {
-               int i;
-
-               /* relocate names of sub-command table */
-               for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
-                       cmd_bootm_sub[i].name += gd->reloc_off;
-
-               relocated = 1;
-       }
-#endif
-
-       /* determine if we have a sub command */
-       argc--; argv++;
-       if (argc > 0) {
-               char *endp;
-
-               simple_strtoul(argv[0], &endp, 16);
-               /* endp pointing to NULL means that argv[0] was just a
-                * valid number, pass it along to the normal bootm processing
-                *
-                * If endp is ':' or '#' assume a FIT identifier so pass
-                * along for normal processing.
-                *
-                * Right now we assume the first arg should never be '-'
-                */
-               if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
-                       return do_bootm_subcommand(cmdtp, flag, argc, argv);
-       }
-
-       return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
-               BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
-               BOOTM_STATE_LOADOS |
-#if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
-               BOOTM_STATE_OS_CMDLINE |
-#endif
-               BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
-               BOOTM_STATE_OS_GO, &images, 1);
-}
-
-int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
-{
-       const char *ep = getenv("autostart");
-
-       if (ep && !strcmp(ep, "yes")) {
-               char *local_args[2];
-               local_args[0] = (char *)cmd;
-               local_args[1] = NULL;
-               printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
-               return do_bootm(cmdtp, 0, 1, local_args);
-       }
-
-       return 0;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char bootm_help_text[] =
-       "[addr [arg ...]]\n    - boot application image stored in memory\n"
-       "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
-       "\t'arg' can be the address of an initrd image\n"
-#if defined(CONFIG_OF_LIBFDT)
-       "\tWhen booting a Linux kernel which requires a flat device-tree\n"
-       "\ta third argument is required which is the address of the\n"
-       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
-       "\tuse a '-' for the second argument. If you do not pass a third\n"
-       "\ta bd_info struct will be passed instead\n"
-#endif
-#if defined(CONFIG_FIT)
-       "\t\nFor the new multi component uImage format (FIT) addresses\n"
-       "\tmust be extened to include component or configuration unit name:\n"
-       "\taddr:<subimg_uname> - direct component image specification\n"
-       "\taddr#<conf_uname>   - configuration specification\n"
-       "\tUse iminfo command to get the list of existing component\n"
-       "\timages and configurations.\n"
-#endif
-       "\nSub-commands to do part of the bootm sequence.  The sub-commands "
-       "must be\n"
-       "issued in the order below (it's ok to not issue all sub-commands):\n"
-       "\tstart [addr [arg ...]]\n"
-       "\tloados  - load OS image\n"
-#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
-       "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
-#endif
-#if defined(CONFIG_OF_LIBFDT)
-       "\tfdt     - relocate flat device tree\n"
-#endif
-       "\tcmdline - OS specific command line processing/setup\n"
-       "\tbdt     - OS specific bd_t processing\n"
-       "\tprep    - OS specific prep before relocation or go\n"
-#if defined(CONFIG_TRACE)
-       "\tfake    - OS specific fake start without go\n"
-#endif
-       "\tgo      - start OS";
-#endif
-
-U_BOOT_CMD(
-       bootm,  CONFIG_SYS_MAXARGS,     1,      do_bootm,
-       "boot application image from memory", bootm_help_text
-);
-
-/*******************************************************************/
-/* bootd - boot default image */
-/*******************************************************************/
-#if defined(CONFIG_CMD_BOOTD)
-int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return run_command(getenv("bootcmd"), flag);
-}
-
-U_BOOT_CMD(
-       boot,   1,      1,      do_bootd,
-       "boot default, i.e., run 'bootcmd'",
-       ""
-);
-
-/* keep old command name "bootd" for backward compatibility */
-U_BOOT_CMD(
-       bootd, 1,       1,      do_bootd,
-       "boot default, i.e., run 'bootcmd'",
-       ""
-);
-
-#endif
-
-
-/*******************************************************************/
-/* iminfo - print header info for a requested image */
-/*******************************************************************/
-#if defined(CONFIG_CMD_IMI)
-static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int     arg;
-       ulong   addr;
-       int     rcode = 0;
-
-       if (argc < 2) {
-               return image_info(load_addr);
-       }
-
-       for (arg = 1; arg < argc; ++arg) {
-               addr = simple_strtoul(argv[arg], NULL, 16);
-               if (image_info(addr) != 0)
-                       rcode = 1;
-       }
-       return rcode;
-}
-
-static int image_info(ulong addr)
-{
-       void *hdr = (void *)addr;
-
-       printf("\n## Checking Image at %08lx ...\n", addr);
-
-       switch (genimg_get_format(hdr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-               puts("   Legacy image found\n");
-               if (!image_check_magic(hdr)) {
-                       puts("   Bad Magic Number\n");
-                       return 1;
-               }
-
-               if (!image_check_hcrc(hdr)) {
-                       puts("   Bad Header Checksum\n");
-                       return 1;
-               }
-
-               image_print_contents(hdr);
-
-               puts("   Verifying Checksum ... ");
-               if (!image_check_dcrc(hdr)) {
-                       puts("   Bad Data CRC\n");
-                       return 1;
-               }
-               puts("OK\n");
-               return 0;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               puts("   FIT image found\n");
-
-               if (!fit_check_format(hdr)) {
-                       puts("Bad FIT image format!\n");
-                       return 1;
-               }
-
-               fit_print_contents(hdr);
-
-               if (!fit_all_image_verify(hdr)) {
-                       puts("Bad hash in FIT image!\n");
-                       return 1;
-               }
-
-               return 0;
-#endif
-       default:
-               puts("Unknown image format!\n");
-               break;
-       }
-
-       return 1;
-}
-
-U_BOOT_CMD(
-       iminfo, CONFIG_SYS_MAXARGS,     1,      do_iminfo,
-       "print header information for application image",
-       "addr [addr ...]\n"
-       "    - print header information for application image starting at\n"
-       "      address 'addr' in memory; this includes verification of the\n"
-       "      image contents (magic number, header and payload checksums)"
-);
-#endif
-
-
-/*******************************************************************/
-/* imls - list all images found in flash */
-/*******************************************************************/
-#if defined(CONFIG_CMD_IMLS)
-static int do_imls_nor(void)
-{
-       flash_info_t *info;
-       int i, j;
-       void *hdr;
-
-       for (i = 0, info = &flash_info[0];
-               i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
-
-               if (info->flash_id == FLASH_UNKNOWN)
-                       goto next_bank;
-               for (j = 0; j < info->sector_count; ++j) {
-
-                       hdr = (void *)info->start[j];
-                       if (!hdr)
-                               goto next_sector;
-
-                       switch (genimg_get_format(hdr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-                       case IMAGE_FORMAT_LEGACY:
-                               if (!image_check_hcrc(hdr))
-                                       goto next_sector;
-
-                               printf("Legacy Image at %08lX:\n", (ulong)hdr);
-                               image_print_contents(hdr);
-
-                               puts("   Verifying Checksum ... ");
-                               if (!image_check_dcrc(hdr)) {
-                                       puts("Bad Data CRC\n");
-                               } else {
-                                       puts("OK\n");
-                               }
-                               break;
-#endif
-#if defined(CONFIG_FIT)
-                       case IMAGE_FORMAT_FIT:
-                               if (!fit_check_format(hdr))
-                                       goto next_sector;
-
-                               printf("FIT Image at %08lX:\n", (ulong)hdr);
-                               fit_print_contents(hdr);
-                               break;
-#endif
-                       default:
-                               goto next_sector;
-                       }
-
-next_sector:           ;
-               }
-next_bank:     ;
-       }
-       return 0;
-}
-#endif
-
-#if defined(CONFIG_CMD_IMLS_NAND)
-static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
-               size_t len)
-{
-       void *imgdata;
-       int ret;
-
-       imgdata = malloc(len);
-       if (!imgdata) {
-               printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
-                               nand_dev, off);
-               printf("   Low memory(cannot allocate memory for image)\n");
-               return -ENOMEM;
-       }
-
-       ret = nand_read_skip_bad(nand, off, &len,
-                       imgdata);
-       if (ret < 0 && ret != -EUCLEAN) {
-               free(imgdata);
-               return ret;
-       }
-
-       if (!image_check_hcrc(imgdata)) {
-               free(imgdata);
-               return 0;
-       }
-
-       printf("Legacy Image at NAND device %d offset %08llX:\n",
-                       nand_dev, off);
-       image_print_contents(imgdata);
-
-       puts("   Verifying Checksum ... ");
-       if (!image_check_dcrc(imgdata))
-               puts("Bad Data CRC\n");
-       else
-               puts("OK\n");
-
-       free(imgdata);
-
-       return 0;
-}
-
-static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
-               size_t len)
-{
-       void *imgdata;
-       int ret;
-
-       imgdata = malloc(len);
-       if (!imgdata) {
-               printf("May be a FIT Image at NAND device %d offset %08llX:\n",
-                               nand_dev, off);
-               printf("   Low memory(cannot allocate memory for image)\n");
-               return -ENOMEM;
-       }
-
-       ret = nand_read_skip_bad(nand, off, &len,
-                       imgdata);
-       if (ret < 0 && ret != -EUCLEAN) {
-               free(imgdata);
-               return ret;
-       }
-
-       if (!fit_check_format(imgdata)) {
-               free(imgdata);
-               return 0;
-       }
-
-       printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
-
-       fit_print_contents(imgdata);
-       free(imgdata);
-
-       return 0;
-}
-
-static int do_imls_nand(void)
-{
-       nand_info_t *nand;
-       int nand_dev = nand_curr_device;
-       size_t len;
-       loff_t off;
-       u32 buffer[16];
-
-       if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
-               puts("\nNo NAND devices available\n");
-               return -ENODEV;
-       }
-
-       printf("\n");
-
-       for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
-               nand = &nand_info[nand_dev];
-               if (!nand->name || !nand->size)
-                       continue;
-
-               for (off = 0; off < nand->size; off += nand->erasesize) {
-                       const image_header_t *header;
-                       int ret;
-
-                       if (nand_block_isbad(nand, off))
-                               continue;
-
-                       len = sizeof(buffer);
-
-                       ret = nand_read(nand, off, &len, (u8 *)buffer);
-                       if (ret < 0 && ret != -EUCLEAN) {
-                               printf("NAND read error %d at offset %08llX\n",
-                                               ret, off);
-                               continue;
-                       }
-
-                       switch (genimg_get_format(buffer)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-                       case IMAGE_FORMAT_LEGACY:
-                               header = (const image_header_t *)buffer;
-
-                               len = image_get_image_size(header);
-                               nand_imls_legacyimage(nand, nand_dev, off, len);
-                               break;
-#endif
-#if defined(CONFIG_FIT)
-                       case IMAGE_FORMAT_FIT:
-                               len = fit_get_size(buffer);
-                               nand_imls_fitimage(nand, nand_dev, off, len);
-                               break;
-#endif
-                       }
-               }
-       }
-
-       return 0;
-}
-#endif
-
-#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
-static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret_nor = 0, ret_nand = 0;
-
-#if defined(CONFIG_CMD_IMLS)
-       ret_nor = do_imls_nor();
-#endif
-
-#if defined(CONFIG_CMD_IMLS_NAND)
-       ret_nand = do_imls_nand();
-#endif
-
-       if (ret_nor)
-               return ret_nor;
-
-       if (ret_nand)
-               return ret_nand;
-
-       return (0);
-}
-
-U_BOOT_CMD(
-       imls,   1,              1,      do_imls,
-       "list all images found in flash",
-       "\n"
-       "    - Prints information about all images found at sector/block\n"
-       "      boundaries in nor/nand flash."
-);
-#endif
-
-#ifdef CONFIG_CMD_BOOTZ
-
-int __weak bootz_setup(ulong image, ulong *start, ulong *end)
-{
-       /* Please define bootz_setup() for your platform */
-
-       puts("Your platform's zImage format isn't supported yet!\n");
-       return -1;
-}
-
-/*
- * zImage booting support
- */
-static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[], bootm_headers_t *images)
-{
-       int ret;
-       ulong zi_start, zi_end;
-
-       ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
-                             images, 1);
-
-       /* Setup Linux kernel zImage entry point */
-       if (!argc) {
-               images->ep = load_addr;
-               debug("*  kernel: default image load address = 0x%08lx\n",
-                               load_addr);
-       } else {
-               images->ep = simple_strtoul(argv[0], NULL, 16);
-               debug("*  kernel: cmdline image address = 0x%08lx\n",
-                       images->ep);
-       }
-
-       ret = bootz_setup(images->ep, &zi_start, &zi_end);
-       if (ret != 0)
-               return 1;
-
-       lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
-
-       /*
-        * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
-        * have a header that provide this informaiton.
-        */
-       if (bootm_find_images(flag, argc, argv))
-               return 1;
-
-       return 0;
-}
-
-int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret;
-
-       /* Consume 'bootz' */
-       argc--; argv++;
-
-       if (bootz_start(cmdtp, flag, argc, argv, &images))
-               return 1;
-
-       /*
-        * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
-        * disable interrupts ourselves
-        */
-       bootm_disable_interrupts();
-
-       images.os.os = IH_OS_LINUX;
-       ret = do_bootm_states(cmdtp, flag, argc, argv,
-                             BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
-                             BOOTM_STATE_OS_GO,
-                             &images, 1);
-
-       return ret;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char bootz_help_text[] =
-       "[addr [initrd[:size]] [fdt]]\n"
-       "    - boot Linux zImage stored in memory\n"
-       "\tThe argument 'initrd' is optional and specifies the address\n"
-       "\tof the initrd in memory. The optional argument ':size' allows\n"
-       "\tspecifying the size of RAW initrd.\n"
-#if defined(CONFIG_OF_LIBFDT)
-       "\tWhen booting a Linux kernel which requires a flat device-tree\n"
-       "\ta third argument is required which is the address of the\n"
-       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
-       "\tuse a '-' for the second argument. If you do not pass a third\n"
-       "\ta bd_info struct will be passed instead\n"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       bootz,  CONFIG_SYS_MAXARGS,     1,      do_bootz,
-       "boot Linux zImage image from memory", bootz_help_text
-);
-#endif /* CONFIG_CMD_BOOTZ */
-
-#ifdef CONFIG_CMD_BOOTI
-/* See Documentation/arm64/booting.txt in the Linux kernel */
-struct Image_header {
-       uint32_t        code0;          /* Executable code */
-       uint32_t        code1;          /* Executable code */
-       uint64_t        text_offset;    /* Image load offset, LE */
-       uint64_t        image_size;     /* Effective Image size, LE */
-       uint64_t        res1;           /* reserved */
-       uint64_t        res2;           /* reserved */
-       uint64_t        res3;           /* reserved */
-       uint64_t        res4;           /* reserved */
-       uint32_t        magic;          /* Magic number */
-       uint32_t        res5;
-};
-
-#define LINUX_ARM64_IMAGE_MAGIC        0x644d5241
-
-static int booti_setup(bootm_headers_t *images)
-{
-       struct Image_header *ih;
-       uint64_t dst;
-
-       ih = (struct Image_header *)map_sysmem(images->ep, 0);
-
-       if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
-               puts("Bad Linux ARM64 Image magic!\n");
-               return 1;
-       }
-       
-       if (ih->image_size == 0) {
-               puts("Image lacks image_size field, assuming 16MiB\n");
-               ih->image_size = (16 << 20);
-       }
-
-       /*
-        * If we are not at the correct run-time location, set the new
-        * correct location and then move the image there.
-        */
-       dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset);
-       if (images->ep != dst) {
-               void *src;
-
-               debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst);
-
-               src = (void *)images->ep;
-               images->ep = dst;
-               memmove((void *)dst, src, le32_to_cpu(ih->image_size));
-       }
-
-       return 0;
-}
-
-/*
- * Image booting support
- */
-static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[], bootm_headers_t *images)
-{
-       int ret;
-       struct Image_header *ih;
-
-       ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
-                             images, 1);
-
-       /* Setup Linux kernel Image entry point */
-       if (!argc) {
-               images->ep = load_addr;
-               debug("*  kernel: default image load address = 0x%08lx\n",
-                               load_addr);
-       } else {
-               images->ep = simple_strtoul(argv[0], NULL, 16);
-               debug("*  kernel: cmdline image address = 0x%08lx\n",
-                       images->ep);
-       }
-
-       ret = booti_setup(images);
-       if (ret != 0)
-               return 1;
-
-       ih = (struct Image_header *)map_sysmem(images->ep, 0);
-
-       lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size));
-
-       /*
-        * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
-        * have a header that provide this informaiton.
-        */
-       if (bootm_find_images(flag, argc, argv))
-               return 1;
-
-       return 0;
-}
-
-int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret;
-
-       /* Consume 'booti' */
-       argc--; argv++;
-
-       if (booti_start(cmdtp, flag, argc, argv, &images))
-               return 1;
-
-       /*
-        * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
-        * disable interrupts ourselves
-        */
-       bootm_disable_interrupts();
-
-       images.os.os = IH_OS_LINUX;
-       ret = do_bootm_states(cmdtp, flag, argc, argv,
-                             BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
-                             BOOTM_STATE_OS_GO,
-                             &images, 1);
-
-       return ret;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char booti_help_text[] =
-       "[addr [initrd[:size]] [fdt]]\n"
-       "    - boot Linux Image stored in memory\n"
-       "\tThe argument 'initrd' is optional and specifies the address\n"
-       "\tof the initrd in memory. The optional argument ':size' allows\n"
-       "\tspecifying the size of RAW initrd.\n"
-#if defined(CONFIG_OF_LIBFDT)
-       "\tSince booting a Linux kernelrequires a flat device-tree\n"
-       "\ta third argument is required which is the address of the\n"
-       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
-       "\tuse a '-' for the second argument.\n"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       booti,  CONFIG_SYS_MAXARGS,     1,      do_booti,
-       "boot arm64 Linux Image image from memory", booti_help_text
-);
-#endif /* CONFIG_CMD_BOOTI */
diff --git a/common/cmd_bootmenu.c b/common/cmd_bootmenu.c
deleted file mode 100644 (file)
index 5879065..0000000
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * (C) Copyright 2011-2013 Pali Rohár <pali.rohar@gmail.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <ansi.h>
-#include <menu.h>
-#include <watchdog.h>
-#include <malloc.h>
-#include <linux/string.h>
-
-/* maximum bootmenu entries */
-#define MAX_COUNT      99
-
-/* maximal size of bootmenu env
- *  9 = strlen("bootmenu_")
- *  2 = strlen(MAX_COUNT)
- *  1 = NULL term
- */
-#define MAX_ENV_SIZE   (9 + 2 + 1)
-
-struct bootmenu_entry {
-       unsigned short int num;         /* unique number 0 .. MAX_COUNT */
-       char key[3];                    /* key identifier of number */
-       char *title;                    /* title of entry */
-       char *command;                  /* hush command of entry */
-       struct bootmenu_data *menu;     /* this bootmenu */
-       struct bootmenu_entry *next;    /* next menu entry (num+1) */
-};
-
-struct bootmenu_data {
-       int delay;                      /* delay for autoboot */
-       int active;                     /* active menu entry */
-       int count;                      /* total count of menu entries */
-       struct bootmenu_entry *first;   /* first menu entry */
-};
-
-enum bootmenu_key {
-       KEY_NONE = 0,
-       KEY_UP,
-       KEY_DOWN,
-       KEY_SELECT,
-};
-
-static char *bootmenu_getoption(unsigned short int n)
-{
-       char name[MAX_ENV_SIZE];
-
-       if (n > MAX_COUNT)
-               return NULL;
-
-       sprintf(name, "bootmenu_%d", n);
-       return getenv(name);
-}
-
-static void bootmenu_print_entry(void *data)
-{
-       struct bootmenu_entry *entry = data;
-       int reverse = (entry->menu->active == entry->num);
-
-       /*
-        * Move cursor to line where the entry will be drown (entry->num)
-        * First 3 lines contain bootmenu header + 1 empty line
-        */
-       printf(ANSI_CURSOR_POSITION, entry->num + 4, 1);
-
-       puts("     ");
-
-       if (reverse)
-               puts(ANSI_COLOR_REVERSE);
-
-       puts(entry->title);
-
-       if (reverse)
-               puts(ANSI_COLOR_RESET);
-}
-
-static void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-                               enum bootmenu_key *key, int *esc)
-{
-       int i, c;
-
-       if (menu->delay > 0) {
-               printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
-               printf("  Hit any key to stop autoboot: %2d ", menu->delay);
-       }
-
-       while (menu->delay > 0) {
-               for (i = 0; i < 100; ++i) {
-                       if (!tstc()) {
-                               WATCHDOG_RESET();
-                               mdelay(10);
-                               continue;
-                       }
-
-                       menu->delay = -1;
-                       c = getc();
-
-                       switch (c) {
-                       case '\e':
-                               *esc = 1;
-                               *key = KEY_NONE;
-                               break;
-                       case '\r':
-                               *key = KEY_SELECT;
-                               break;
-                       default:
-                               *key = KEY_NONE;
-                               break;
-                       }
-
-                       break;
-               }
-
-               if (menu->delay < 0)
-                       break;
-
-               --menu->delay;
-               printf("\b\b\b%2d ", menu->delay);
-       }
-
-       printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
-       puts(ANSI_CLEAR_LINE);
-
-       if (menu->delay == 0)
-               *key = KEY_SELECT;
-}
-
-static void bootmenu_loop(struct bootmenu_data *menu,
-               enum bootmenu_key *key, int *esc)
-{
-       int c;
-
-       while (!tstc()) {
-               WATCHDOG_RESET();
-               mdelay(10);
-       }
-
-       c = getc();
-
-       switch (*esc) {
-       case 0:
-               /* First char of ANSI escape sequence '\e' */
-               if (c == '\e') {
-                       *esc = 1;
-                       *key = KEY_NONE;
-               }
-               break;
-       case 1:
-               /* Second char of ANSI '[' */
-               if (c == '[') {
-                       *esc = 2;
-                       *key = KEY_NONE;
-               } else {
-                       *esc = 0;
-               }
-               break;
-       case 2:
-       case 3:
-               /* Third char of ANSI (number '1') - optional */
-               if (*esc == 2 && c == '1') {
-                       *esc = 3;
-                       *key = KEY_NONE;
-                       break;
-               }
-
-               *esc = 0;
-
-               /* ANSI 'A' - key up was pressed */
-               if (c == 'A')
-                       *key = KEY_UP;
-               /* ANSI 'B' - key down was pressed */
-               else if (c == 'B')
-                       *key = KEY_DOWN;
-               /* other key was pressed */
-               else
-                       *key = KEY_NONE;
-
-               break;
-       }
-
-       /* enter key was pressed */
-       if (c == '\r')
-               *key = KEY_SELECT;
-}
-
-static char *bootmenu_choice_entry(void *data)
-{
-       struct bootmenu_data *menu = data;
-       struct bootmenu_entry *iter;
-       enum bootmenu_key key = KEY_NONE;
-       int esc = 0;
-       int i;
-
-       while (1) {
-               if (menu->delay >= 0) {
-                       /* Autoboot was not stopped */
-                       bootmenu_autoboot_loop(menu, &key, &esc);
-               } else {
-                       /* Some key was pressed, so autoboot was stopped */
-                       bootmenu_loop(menu, &key, &esc);
-               }
-
-               switch (key) {
-               case KEY_UP:
-                       if (menu->active > 0)
-                               --menu->active;
-                       /* no menu key selected, regenerate menu */
-                       return NULL;
-               case KEY_DOWN:
-                       if (menu->active < menu->count - 1)
-                               ++menu->active;
-                       /* no menu key selected, regenerate menu */
-                       return NULL;
-               case KEY_SELECT:
-                       iter = menu->first;
-                       for (i = 0; i < menu->active; ++i)
-                               iter = iter->next;
-                       return iter->key;
-               default:
-                       break;
-               }
-       }
-
-       /* never happens */
-       debug("bootmenu: this should not happen");
-       return NULL;
-}
-
-static void bootmenu_destroy(struct bootmenu_data *menu)
-{
-       struct bootmenu_entry *iter = menu->first;
-       struct bootmenu_entry *next;
-
-       while (iter) {
-               next = iter->next;
-               free(iter->title);
-               free(iter->command);
-               free(iter);
-               iter = next;
-       }
-       free(menu);
-}
-
-static struct bootmenu_data *bootmenu_create(int delay)
-{
-       unsigned short int i = 0;
-       const char *option;
-       struct bootmenu_data *menu;
-       struct bootmenu_entry *iter = NULL;
-
-       int len;
-       char *sep;
-       struct bootmenu_entry *entry;
-
-       menu = malloc(sizeof(struct bootmenu_data));
-       if (!menu)
-               return NULL;
-
-       menu->delay = delay;
-       menu->active = 0;
-       menu->first = NULL;
-
-       while ((option = bootmenu_getoption(i))) {
-               sep = strchr(option, '=');
-               if (!sep) {
-                       printf("Invalid bootmenu entry: %s\n", option);
-                       break;
-               }
-
-               entry = malloc(sizeof(struct bootmenu_entry));
-               if (!entry)
-                       goto cleanup;
-
-               len = sep-option;
-               entry->title = malloc(len + 1);
-               if (!entry->title) {
-                       free(entry);
-                       goto cleanup;
-               }
-               memcpy(entry->title, option, len);
-               entry->title[len] = 0;
-
-               len = strlen(sep + 1);
-               entry->command = malloc(len + 1);
-               if (!entry->command) {
-                       free(entry->title);
-                       free(entry);
-                       goto cleanup;
-               }
-               memcpy(entry->command, sep + 1, len);
-               entry->command[len] = 0;
-
-               sprintf(entry->key, "%d", i);
-
-               entry->num = i;
-               entry->menu = menu;
-               entry->next = NULL;
-
-               if (!iter)
-                       menu->first = entry;
-               else
-                       iter->next = entry;
-
-               iter = entry;
-               ++i;
-
-               if (i == MAX_COUNT - 1)
-                       break;
-       }
-
-       /* Add U-Boot console entry at the end */
-       if (i <= MAX_COUNT - 1) {
-               entry = malloc(sizeof(struct bootmenu_entry));
-               if (!entry)
-                       goto cleanup;
-
-               entry->title = strdup("U-Boot console");
-               if (!entry->title) {
-                       free(entry);
-                       goto cleanup;
-               }
-
-               entry->command = strdup("");
-               if (!entry->command) {
-                       free(entry->title);
-                       free(entry);
-                       goto cleanup;
-               }
-
-               sprintf(entry->key, "%d", i);
-
-               entry->num = i;
-               entry->menu = menu;
-               entry->next = NULL;
-
-               if (!iter)
-                       menu->first = entry;
-               else
-                       iter->next = entry;
-
-               iter = entry;
-               ++i;
-       }
-
-       menu->count = i;
-       return menu;
-
-cleanup:
-       bootmenu_destroy(menu);
-       return NULL;
-}
-
-static void bootmenu_show(int delay)
-{
-       int init = 0;
-       void *choice = NULL;
-       char *title = NULL;
-       char *command = NULL;
-       struct menu *menu;
-       struct bootmenu_data *bootmenu;
-       struct bootmenu_entry *iter;
-       char *option, *sep;
-
-       /* If delay is 0 do not create menu, just run first entry */
-       if (delay == 0) {
-               option = bootmenu_getoption(0);
-               if (!option) {
-                       puts("bootmenu option 0 was not found\n");
-                       return;
-               }
-               sep = strchr(option, '=');
-               if (!sep) {
-                       puts("bootmenu option 0 is invalid\n");
-                       return;
-               }
-               run_command(sep+1, 0);
-               return;
-       }
-
-       bootmenu = bootmenu_create(delay);
-       if (!bootmenu)
-               return;
-
-       menu = menu_create(NULL, bootmenu->delay, 1, bootmenu_print_entry,
-                          bootmenu_choice_entry, bootmenu);
-       if (!menu) {
-               bootmenu_destroy(bootmenu);
-               return;
-       }
-
-       for (iter = bootmenu->first; iter; iter = iter->next) {
-               if (!menu_item_add(menu, iter->key, iter))
-                       goto cleanup;
-       }
-
-       /* Default menu entry is always first */
-       menu_default_set(menu, "0");
-
-       puts(ANSI_CURSOR_HIDE);
-       puts(ANSI_CLEAR_CONSOLE);
-       printf(ANSI_CURSOR_POSITION, 1, 1);
-
-       init = 1;
-
-       if (menu_get_choice(menu, &choice)) {
-               iter = choice;
-               title = strdup(iter->title);
-               command = strdup(iter->command);
-       }
-
-cleanup:
-       menu_destroy(menu);
-       bootmenu_destroy(bootmenu);
-
-       if (init) {
-               puts(ANSI_CURSOR_SHOW);
-               puts(ANSI_CLEAR_CONSOLE);
-               printf(ANSI_CURSOR_POSITION, 1, 1);
-       }
-
-       if (title && command) {
-               debug("Starting entry '%s'\n", title);
-               free(title);
-               run_command(command, 0);
-               free(command);
-       }
-
-#ifdef CONFIG_POSTBOOTMENU
-       run_command(CONFIG_POSTBOOTMENU, 0);
-#endif
-}
-
-void menu_display_statusline(struct menu *m)
-{
-       struct bootmenu_entry *entry;
-       struct bootmenu_data *menu;
-
-       if (menu_default_choice(m, (void *)&entry) < 0)
-               return;
-
-       menu = entry->menu;
-
-       printf(ANSI_CURSOR_POSITION, 1, 1);
-       puts(ANSI_CLEAR_LINE);
-       printf(ANSI_CURSOR_POSITION, 2, 1);
-       puts("  *** U-Boot Boot Menu ***");
-       puts(ANSI_CLEAR_LINE_TO_END);
-       printf(ANSI_CURSOR_POSITION, 3, 1);
-       puts(ANSI_CLEAR_LINE);
-
-       /* First 3 lines are bootmenu header + 2 empty lines between entries */
-       printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
-       puts(ANSI_CLEAR_LINE);
-       printf(ANSI_CURSOR_POSITION, menu->count + 6, 1);
-       puts("  Press UP/DOWN to move, ENTER to select");
-       puts(ANSI_CLEAR_LINE_TO_END);
-       printf(ANSI_CURSOR_POSITION, menu->count + 7, 1);
-       puts(ANSI_CLEAR_LINE);
-}
-
-#ifdef CONFIG_MENU_SHOW
-int menu_show(int bootdelay)
-{
-       bootmenu_show(bootdelay);
-       return -1; /* -1 - abort boot and run monitor code */
-}
-#endif
-
-int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *delay_str = NULL;
-       int delay = 10;
-
-#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
-       delay = CONFIG_BOOTDELAY;
-#endif
-
-       if (argc >= 2)
-               delay_str = argv[1];
-
-       if (!delay_str)
-               delay_str = getenv("bootmenu_delay");
-
-       if (delay_str)
-               delay = (int)simple_strtol(delay_str, NULL, 10);
-
-       bootmenu_show(delay);
-       return 0;
-}
-
-U_BOOT_CMD(
-       bootmenu, 2, 1, do_bootmenu,
-       "ANSI terminal bootmenu",
-       "[delay]\n"
-       "    - show ANSI terminal bootmenu with autoboot delay"
-);
diff --git a/common/cmd_bootstage.c b/common/cmd_bootstage.c
deleted file mode 100644 (file)
index 788ab16..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2012, Google Inc. All rights reserved.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-
-static int do_bootstage_report(cmd_tbl_t *cmdtp, int flag, int argc,
-                              char * const argv[])
-{
-       bootstage_report();
-
-       return 0;
-}
-
-static int get_base_size(int argc, char * const argv[], ulong *basep,
-                        ulong *sizep)
-{
-       char *endp;
-
-       *basep = CONFIG_BOOTSTAGE_STASH_ADDR;
-       *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
-       if (argc < 2)
-               return 0;
-       *basep = simple_strtoul(argv[1], &endp, 16);
-       if (*argv[1] == 0 || *endp != 0)
-               return -1;
-       if (argc == 2)
-               return 0;
-       *sizep = simple_strtoul(argv[2], &endp, 16);
-       if (*argv[2] == 0 || *endp != 0)
-               return -1;
-
-       return 0;
-}
-
-static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc,
-                             char * const argv[])
-{
-       ulong base, size;
-       int ret;
-
-       if (get_base_size(argc, argv, &base, &size))
-               return CMD_RET_USAGE;
-       if (base == -1UL) {
-               printf("No bootstage stash area defined\n");
-               return 1;
-       }
-
-       if (0 == strcmp(argv[0], "stash"))
-               ret = bootstage_stash((void *)base, size);
-       else
-               ret = bootstage_unstash((void *)base, size);
-       if (ret)
-               return 1;
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_bootstage_sub[] = {
-       U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
-       U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
-       U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
-};
-
-/*
- * Process a bootstage sub-command
- */
-static int do_boostage(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       cmd_tbl_t *c;
-
-       /* Strip off leading 'bootstage' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
-                        ARRAY_SIZE(cmd_bootstage_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-
-U_BOOT_CMD(bootstage, 4, 1, do_boostage,
-       "Boot stage command",
-       " - check boot progress and timing\n"
-       "report                      - Print a report\n"
-       "stash [<start> [<size>]]    - Stash data into memory\n"
-       "unstash [<start> [<size>]]  - Unstash data from memory"
-);
diff --git a/common/cmd_cache.c b/common/cmd_cache.c
deleted file mode 100644 (file)
index 37ab345..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Cache support: switch on or off, get status
- */
-#include <common.h>
-#include <command.h>
-#include <linux/compiler.h>
-
-static int parse_argv(const char *);
-
-void __weak invalidate_icache_all(void)
-{
-       /* please define arch specific invalidate_icache_all */
-       puts("No arch specific invalidate_icache_all available!\n");
-}
-
-static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       switch (argc) {
-       case 2:                 /* on / off     */
-               switch (parse_argv(argv[1])) {
-               case 0:
-                       icache_disable();
-                       break;
-               case 1:
-                       icache_enable();
-                       break;
-               case 2:
-                       invalidate_icache_all();
-                       break;
-               }
-               break;
-       case 1:                 /* get status */
-               printf("Instruction Cache is %s\n",
-                       icache_status() ? "ON" : "OFF");
-               return 0;
-       default:
-               return CMD_RET_USAGE;
-       }
-       return 0;
-}
-
-void __weak flush_dcache_all(void)
-{
-       puts("No arch specific flush_dcache_all available!\n");
-       /* please define arch specific flush_dcache_all */
-}
-
-static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       switch (argc) {
-       case 2:                 /* on / off */
-               switch (parse_argv(argv[1])) {
-               case 0:
-                       dcache_disable();
-                       break;
-               case 1:
-                       dcache_enable();
-                       break;
-               case 2:
-                       flush_dcache_all();
-                       break;
-               }
-               break;
-       case 1:                 /* get status */
-               printf("Data (writethrough) Cache is %s\n",
-                       dcache_status() ? "ON" : "OFF");
-               return 0;
-       default:
-               return CMD_RET_USAGE;
-       }
-       return 0;
-}
-
-static int parse_argv(const char *s)
-{
-       if (strcmp(s, "flush") == 0)
-               return 2;
-       else if (strcmp(s, "on") == 0)
-               return 1;
-       else if (strcmp(s, "off") == 0)
-               return 0;
-
-       return -1;
-}
-
-
-U_BOOT_CMD(
-       icache,   2,   1,     do_icache,
-       "enable or disable instruction cache",
-       "[on, off, flush]\n"
-       "    - enable, disable, or flush instruction cache"
-);
-
-U_BOOT_CMD(
-       dcache,   2,   1,     do_dcache,
-       "enable or disable data cache",
-       "[on, off, flush]\n"
-       "    - enable, disable, or flush data (writethrough) cache"
-);
diff --git a/common/cmd_cbfs.c b/common/cmd_cbfs.c
deleted file mode 100644 (file)
index 35d8a7a..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * CBFS commands
- */
-#include <common.h>
-#include <command.h>
-#include <cbfs.h>
-
-int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       uintptr_t end_of_rom = 0xffffffff;
-       char *ep;
-
-       if (argc > 2) {
-               printf("usage: cbfsls [end of rom]>\n");
-               return 0;
-       }
-       if (argc == 2) {
-               end_of_rom = (int)simple_strtoul(argv[1], &ep, 16);
-               if (*ep) {
-                       puts("\n** Invalid end of ROM **\n");
-                       return 1;
-               }
-       }
-       file_cbfs_init(end_of_rom);
-       if (file_cbfs_result != CBFS_SUCCESS) {
-               printf("%s.\n", file_cbfs_error());
-               return 1;
-       }
-       return 0;
-}
-
-U_BOOT_CMD(
-       cbfsinit,       2,      0,      do_cbfs_init,
-       "initialize the cbfs driver",
-       "[end of rom]\n"
-       "    - Initialize the cbfs driver. The optional 'end of rom'\n"
-       "      parameter specifies where the end of the ROM is that the\n"
-       "      CBFS is in. It defaults to 0xFFFFFFFF\n"
-);
-
-int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       const struct cbfs_cachenode *file;
-       unsigned long offset;
-       unsigned long count;
-       long size;
-
-       if (argc < 3) {
-               printf("usage: cbfsload <addr> <filename> [bytes]\n");
-               return 1;
-       }
-
-       /* parse offset and count */
-       offset = simple_strtoul(argv[1], NULL, 16);
-       if (argc == 4)
-               count = simple_strtoul(argv[3], NULL, 16);
-       else
-               count = 0;
-
-       file = file_cbfs_find(argv[2]);
-       if (!file) {
-               if (file_cbfs_result == CBFS_FILE_NOT_FOUND)
-                       printf("%s: %s\n", file_cbfs_error(), argv[2]);
-               else
-                       printf("%s.\n", file_cbfs_error());
-               return 1;
-       }
-
-       printf("reading %s\n", file_cbfs_name(file));
-
-       size = file_cbfs_read(file, (void *)offset, count);
-
-       printf("\n%ld bytes read\n", size);
-
-       setenv_hex("filesize", size);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       cbfsload,       4,      0,      do_cbfs_fsload,
-       "load binary file from a cbfs filesystem",
-       "<addr> <filename> [bytes]\n"
-       "    - load binary file 'filename' from the cbfs to address 'addr'\n"
-);
-
-int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       const struct cbfs_cachenode *file = file_cbfs_get_first();
-       int files = 0;
-
-       if (!file) {
-               printf("%s.\n", file_cbfs_error());
-               return 1;
-       }
-
-       printf("     size              type  name\n");
-       printf("------------------------------------------\n");
-       while (file) {
-               u32 type = file_cbfs_type(file);
-               char *type_name = NULL;
-               const char *filename = file_cbfs_name(file);
-
-               printf(" %8d", file_cbfs_size(file));
-
-               switch (type) {
-               case CBFS_TYPE_STAGE:
-                       type_name = "stage";
-                       break;
-               case CBFS_TYPE_PAYLOAD:
-                       type_name = "payload";
-                       break;
-               case CBFS_TYPE_OPTIONROM:
-                       type_name = "option rom";
-                       break;
-               case CBFS_TYPE_BOOTSPLASH:
-                       type_name = "boot splash";
-                       break;
-               case CBFS_TYPE_RAW:
-                       type_name = "raw";
-                       break;
-               case CBFS_TYPE_VSA:
-                       type_name = "vsa";
-                       break;
-               case CBFS_TYPE_MBI:
-                       type_name = "mbi";
-                       break;
-               case CBFS_TYPE_MICROCODE:
-                       type_name = "microcode";
-                       break;
-               case CBFS_COMPONENT_CMOS_DEFAULT:
-                       type_name = "cmos default";
-                       break;
-               case CBFS_COMPONENT_CMOS_LAYOUT:
-                       type_name = "cmos layout";
-                       break;
-               case -1UL:
-                       type_name = "null";
-                       break;
-               }
-               if (type_name)
-                       printf("  %16s", type_name);
-               else
-                       printf("  %16d", type);
-
-               if (filename[0])
-                       printf("  %s\n", filename);
-               else
-                       printf("  %s\n", "(empty)");
-               file_cbfs_get_next(&file);
-               files++;
-       }
-
-       printf("\n%d file(s)\n\n", files);
-       return 0;
-}
-
-U_BOOT_CMD(
-       cbfsls, 1,      1,      do_cbfs_ls,
-       "list files",
-       "    - list the files in the cbfs\n"
-);
-
-int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       const struct cbfs_header *header = file_cbfs_get_header();
-
-       if (!header) {
-               printf("%s.\n", file_cbfs_error());
-               return 1;
-       }
-
-       printf("\n");
-       printf("CBFS version: %#x\n", header->version);
-       printf("ROM size: %#x\n", header->rom_size);
-       printf("Boot block size: %#x\n", header->boot_block_size);
-       printf("CBFS size: %#x\n",
-               header->rom_size - header->boot_block_size - header->offset);
-       printf("Alignment: %d\n", header->align);
-       printf("Offset: %#x\n", header->offset);
-       printf("\n");
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       cbfsinfo,       1,      1,      do_cbfs_fsinfo,
-       "print information about filesystem",
-       "    - print information about the cbfs filesystem\n"
-);
diff --git a/common/cmd_clk.c b/common/cmd_clk.c
deleted file mode 100644 (file)
index 6d3d46a..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2013 Xilinx, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <command.h>
-#include <clk.h>
-
-int __weak soc_clk_dump(void)
-{
-       puts("Not implemented\n");
-       return 1;
-}
-
-static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char *const argv[])
-{
-       return soc_clk_dump();
-}
-
-static cmd_tbl_t cmd_clk_sub[] = {
-       U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
-};
-
-static int do_clk(cmd_tbl_t *cmdtp, int flag, int argc,
-                 char *const argv[])
-{
-       cmd_tbl_t *c;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* Strip off leading 'clk' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char clk_help_text[] =
-       "dump - Print clock frequencies";
-#endif
-
-U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);
diff --git a/common/cmd_console.c b/common/cmd_console.c
deleted file mode 100644 (file)
index 9a356ec..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <command.h>
-#include <stdio_dev.h>
-
-extern void _do_coninfo (void);
-static int do_coninfo(cmd_tbl_t *cmd, int flag, int argc, char * const argv[])
-{
-       int l;
-       struct list_head *list = stdio_get_list();
-       struct list_head *pos;
-       struct stdio_dev *dev;
-
-       /* Scan for valid output and input devices */
-
-       puts ("List of available devices:\n");
-
-       list_for_each(pos, list) {
-               dev = list_entry(pos, struct stdio_dev, list);
-
-               printf ("%-8s %08x %c%c ",
-                       dev->name,
-                       dev->flags,
-                       (dev->flags & DEV_FLAGS_INPUT) ? 'I' : '.',
-                       (dev->flags & DEV_FLAGS_OUTPUT) ? 'O' : '.');
-
-               for (l = 0; l < MAX_FILES; l++) {
-                       if (stdio_devices[l] == dev) {
-                               printf ("%s ", stdio_names[l]);
-                       }
-               }
-               putc ('\n');
-       }
-       return 0;
-}
-
-
-/***************************************************/
-
-U_BOOT_CMD(
-       coninfo,        3,      1,      do_coninfo,
-       "print console devices and information",
-       ""
-);
diff --git a/common/cmd_cplbinfo.c b/common/cmd_cplbinfo.c
deleted file mode 100644 (file)
index ab5b3b5..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * cmd_cplbinfo.c - dump the instruction/data cplb tables
- *
- * Copyright (c) 2007-2008 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <common.h>
-#include <command.h>
-#include <asm/blackfin.h>
-#include <asm/cplb.h>
-#include <asm/mach-common/bits/mpu.h>
-
-/*
- * Translate the PAGE_SIZE bits into a human string
- */
-static const char *cplb_page_size(uint32_t data)
-{
-       static const char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
-       return page_size_string_table[(data & PAGE_SIZE_MASK) >> PAGE_SIZE_SHIFT];
-}
-
-/*
- * show a hardware cplb table
- */
-static void show_cplb_table(uint32_t *addr, uint32_t *data)
-{
-       int i;
-       printf("      Address     Data   Size  Valid  Locked\n");
-       for (i = 1; i <= 16; ++i) {
-               printf(" %2i 0x%p  0x%05X   %s     %c      %c\n",
-                       i, (void *)*addr, *data,
-                       cplb_page_size(*data),
-                       (*data & CPLB_VALID ? 'Y' : 'N'),
-                       (*data & CPLB_LOCK ? 'Y' : 'N'));
-               ++addr;
-               ++data;
-       }
-}
-
-/*
- * display current instruction and data cplb tables
- */
-int do_cplbinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       printf("%s CPLB table [%08x]:\n", "Instruction", *(uint32_t *)DMEM_CONTROL);
-       show_cplb_table((uint32_t *)ICPLB_ADDR0, (uint32_t *)ICPLB_DATA0);
-
-       printf("%s CPLB table [%08x]:\n", "Data", *(uint32_t *)IMEM_CONTROL);
-       show_cplb_table((uint32_t *)DCPLB_ADDR0, (uint32_t *)DCPLB_DATA0);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       cplbinfo, 1, 0, do_cplbinfo,
-       "display current CPLB tables",
-       ""
-);
diff --git a/common/cmd_cpu.c b/common/cmd_cpu.c
deleted file mode 100644 (file)
index b4af64f..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2015 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <cpu.h>
-#include <dm.h>
-#include <errno.h>
-
-static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
-       "L1 cache",
-       "MMU",
-};
-
-static int print_cpu_list(bool detail)
-{
-       struct udevice *dev;
-       struct uclass *uc;
-       char buf[100];
-       int ret;
-
-       ret = uclass_get(UCLASS_CPU, &uc);
-       if (ret) {
-               printf("Cannot find CPU uclass\n");
-               return ret;
-       }
-       uclass_foreach_dev(dev, uc) {
-               struct cpu_platdata *plat = dev_get_parent_platdata(dev);
-               struct cpu_info info;
-               bool first;
-               int i;
-
-               ret = cpu_get_desc(dev, buf, sizeof(buf));
-               printf("%3d: %-10s %s\n", dev->seq, dev->name,
-                      ret ? "<no description>" : buf);
-               if (!detail)
-                       continue;
-               ret = cpu_get_info(dev, &info);
-               if (ret) {
-                       printf("\t(no detail available");
-                       if (ret != -ENOSYS)
-                               printf(": err=%d\n", ret);
-                       printf(")\n");
-                       continue;
-               }
-               printf("\tID = %d, freq = ", plat->cpu_id);
-               print_freq(info.cpu_freq, "");
-               first = true;
-               for (i = 0; i < CPU_FEAT_COUNT; i++) {
-                       if (info.features & (1 << i)) {
-                               printf("%s%s", first ? ": " : ", ",
-                                      cpu_feature_name[i]);
-                               first = false;
-                       }
-               }
-               printf("\n");
-       }
-
-       return 0;
-}
-
-static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       if (print_cpu_list(false))
-               return CMD_RET_FAILURE;
-
-       return 0;
-}
-
-static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char *const argv[])
-{
-       if (print_cpu_list(true))
-               return CMD_RET_FAILURE;
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_cpu_sub[] = {
-       U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
-       U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
-};
-
-/*
- * Process a cpu sub-command
- */
-static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       cmd_tbl_t *c = NULL;
-
-       /* Strip off leading 'cpu' command argument */
-       argc--;
-       argv++;
-
-       if (argc)
-               c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       cpu, 2, 1, do_cpu,
-       "display information about CPUs",
-       "list   - list available CPUs\n"
-       "cpu detail     - show CPU detail"
-);
diff --git a/common/cmd_cramfs.c b/common/cmd_cramfs.c
deleted file mode 100644 (file)
index 1d31326..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * SPDX-License-Identifier:    GPL-2.0+
- *
- * based on: cmd_jffs2.c
- *
- *     Add support for a CRAMFS located in RAM
- */
-
-
-/*
- * CRAMFS support
- */
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <linux/list.h>
-#include <linux/ctype.h>
-#include <jffs2/jffs2.h>
-#include <jffs2/load_kernel.h>
-#include <cramfs/cramfs_fs.h>
-
-/* enable/disable debugging messages */
-#define        DEBUG_CRAMFS
-#undef DEBUG_CRAMFS
-
-#ifdef  DEBUG_CRAMFS
-# define DEBUGF(fmt, args...)  printf(fmt ,##args)
-#else
-# define DEBUGF(fmt, args...)
-#endif
-
-#ifdef CONFIG_CRAMFS_CMDLINE
-#include <flash.h>
-
-#ifdef CONFIG_SYS_NO_FLASH
-# define OFFSET_ADJUSTMENT     0
-#else
-# define OFFSET_ADJUSTMENT     (flash_info[id.num].start[0])
-#endif
-
-#ifndef CONFIG_CMD_JFFS2
-#include <linux/stat.h>
-char *mkmodestr(unsigned long mode, char *str)
-{
-       static const char *l = "xwr";
-       int mask = 1, i;
-       char c;
-
-       switch (mode & S_IFMT) {
-               case S_IFDIR:    str[0] = 'd'; break;
-               case S_IFBLK:    str[0] = 'b'; break;
-               case S_IFCHR:    str[0] = 'c'; break;
-               case S_IFIFO:    str[0] = 'f'; break;
-               case S_IFLNK:    str[0] = 'l'; break;
-               case S_IFSOCK:   str[0] = 's'; break;
-               case S_IFREG:    str[0] = '-'; break;
-               default:         str[0] = '?';
-       }
-
-       for(i = 0; i < 9; i++) {
-               c = l[i%3];
-               str[9-i] = (mode & mask)?c:'-';
-               mask = mask<<1;
-       }
-
-       if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
-       if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
-       if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
-       str[10] = '\0';
-       return str;
-}
-#endif /* CONFIG_CMD_JFFS2 */
-
-extern int cramfs_check (struct part_info *info);
-extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
-extern int cramfs_ls (struct part_info *info, char *filename);
-extern int cramfs_info (struct part_info *info);
-
-/***************************************************/
-/* U-boot commands                                */
-/***************************************************/
-
-/**
- * Routine implementing fsload u-boot command. This routine tries to load
- * a requested file from cramfs filesystem at location 'cramfsaddr'.
- * cramfsaddr is an evironment variable.
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename;
-       int size;
-       ulong offset = load_addr;
-
-       struct part_info part;
-       struct mtd_device dev;
-       struct mtdids id;
-
-       ulong addr;
-       addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
-
-       /* hack! */
-       /* cramfs_* only supports NOR flash chips */
-       /* fake the device type */
-       id.type = MTD_DEV_TYPE_NOR;
-       id.num = 0;
-       dev.id = &id;
-       part.dev = &dev;
-       /* fake the address offset */
-       part.offset = addr - OFFSET_ADJUSTMENT;
-
-       /* pre-set Boot file name */
-       if ((filename = getenv("bootfile")) == NULL) {
-               filename = "uImage";
-       }
-
-       if (argc == 2) {
-               filename = argv[1];
-       }
-       if (argc == 3) {
-               offset = simple_strtoul(argv[1], NULL, 0);
-               load_addr = offset;
-               filename = argv[2];
-       }
-
-       size = 0;
-       if (cramfs_check(&part))
-               size = cramfs_load ((char *) offset, &part, filename);
-
-       if (size > 0) {
-               printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
-                       size, offset);
-               setenv_hex("filesize", size);
-       } else {
-               printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
-       }
-
-       return !(size > 0);
-}
-
-/**
- * Routine implementing u-boot ls command which lists content of a given
- * directory at location 'cramfsaddr'.
- * cramfsaddr is an evironment variable.
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename = "/";
-       int ret;
-       struct part_info part;
-       struct mtd_device dev;
-       struct mtdids id;
-
-       ulong addr;
-       addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
-
-       /* hack! */
-       /* cramfs_* only supports NOR flash chips */
-       /* fake the device type */
-       id.type = MTD_DEV_TYPE_NOR;
-       id.num = 0;
-       dev.id = &id;
-       part.dev = &dev;
-       /* fake the address offset */
-       part.offset = addr - OFFSET_ADJUSTMENT;
-
-       if (argc == 2)
-               filename = argv[1];
-
-       ret = 0;
-       if (cramfs_check(&part))
-               ret = cramfs_ls (&part, filename);
-
-       return ret ? 0 : 1;
-}
-
-/* command line only */
-
-/***************************************************/
-U_BOOT_CMD(
-       cramfsload,     3,      0,      do_cramfs_load,
-       "load binary file from a filesystem image",
-       "[ off ] [ filename ]\n"
-       "    - load binary file from address 'cramfsaddr'\n"
-       "      with offset 'off'\n"
-);
-U_BOOT_CMD(
-       cramfsls,       2,      1,      do_cramfs_ls,
-       "list files in a directory (default /)",
-       "[ directory ]\n"
-       "    - list files in a directory.\n"
-);
-
-#endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
-
-/***************************************************/
diff --git a/common/cmd_dataflash_mmc_mux.c b/common/cmd_dataflash_mmc_mux.c
deleted file mode 100644 (file)
index 3832248..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int mmc_nspi (const char *);
-
-int do_dataflash_mmc_mux (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       switch (argc) {
-       case 2:                 /* on / off     */
-               switch (mmc_nspi (argv[1])) {
-               case 0: AT91F_SelectSPI ();
-                       break;
-               case 1: AT91F_SelectMMC ();
-                       break;
-               }
-       case 1:                 /* get status */
-               printf ("Mux is configured to be %s\n",
-                       AT91F_GetMuxStatus () ? "MMC" : "SPI");
-               return 0;
-       default:
-               return CMD_RET_USAGE;
-       }
-       return 0;
-}
-
-static int mmc_nspi (const char *s)
-{
-       if (strcmp (s, "mmc") == 0) {
-               return 1;
-       } else if (strcmp (s, "spi") == 0) {
-               return 0;
-       }
-       return -1;
-}
-
-U_BOOT_CMD(
-       dataflash_mmc_mux, 2, 1, do_dataflash_mmc_mux,
-       "enable or disable MMC or SPI\n",
-       "[mmc, spi]\n"
-       "    - enable or disable MMC or SPI"
-);
diff --git a/common/cmd_date.c b/common/cmd_date.c
deleted file mode 100644 (file)
index 8714699..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * RTC, Date & Time support: get and set date & time
- */
-#include <common.h>
-#include <command.h>
-#include <dm.h>
-#include <rtc.h>
-#include <i2c.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static const char * const weekdays[] = {
-       "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
-};
-
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-#define RELOC(a)       ((typeof(a))((unsigned long)(a) + gd->reloc_off))
-#else
-#define RELOC(a)       a
-#endif
-
-int mk_date (const char *, struct rtc_time *);
-
-static struct rtc_time default_tm = { 0, 0, 0, 1, 1, 2000, 6, 0, 0 };
-
-static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct rtc_time tm;
-       int rcode = 0;
-       int old_bus __maybe_unused;
-
-       /* switch to correct I2C bus */
-#ifdef CONFIG_DM_RTC
-       struct udevice *dev;
-
-       rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
-       if (rcode) {
-               printf("Cannot find RTC: err=%d\n", rcode);
-               return CMD_RET_FAILURE;
-       }
-#elif defined(CONFIG_SYS_I2C)
-       old_bus = i2c_get_bus_num();
-       i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
-#else
-       old_bus = I2C_GET_BUS();
-       I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM);
-#endif
-
-       switch (argc) {
-       case 2:                 /* set date & time */
-               if (strcmp(argv[1],"reset") == 0) {
-                       puts ("Reset RTC...\n");
-#ifdef CONFIG_DM_RTC
-                       rcode = dm_rtc_reset(dev);
-                       if (!rcode)
-                               rcode = dm_rtc_set(dev, &default_tm);
-#else
-                       rtc_reset();
-                       rcode = rtc_set(&default_tm);
-#endif
-                       if (rcode)
-                               puts("## Failed to set date after RTC reset\n");
-               } else {
-                       /* initialize tm with current time */
-#ifdef CONFIG_DM_RTC
-                       rcode = dm_rtc_get(dev, &tm);
-#else
-                       rcode = rtc_get(&tm);
-#endif
-                       if (!rcode) {
-                               /* insert new date & time */
-                               if (mk_date(argv[1], &tm) != 0) {
-                                       puts ("## Bad date format\n");
-                                       break;
-                               }
-                               /* and write to RTC */
-#ifdef CONFIG_DM_RTC
-                               rcode = dm_rtc_set(dev, &tm);
-#else
-                               rcode = rtc_set(&tm);
-#endif
-                               if (rcode) {
-                                       printf("## Set date failed: err=%d\n",
-                                              rcode);
-                               }
-                       } else {
-                               puts("## Get date failed\n");
-                       }
-               }
-               /* FALL TROUGH */
-       case 1:                 /* get date & time */
-#ifdef CONFIG_DM_RTC
-               rcode = dm_rtc_get(dev, &tm);
-#else
-               rcode = rtc_get(&tm);
-#endif
-               if (rcode) {
-                       puts("## Get date failed\n");
-                       break;
-               }
-
-               printf ("Date: %4d-%02d-%02d (%sday)    Time: %2d:%02d:%02d\n",
-                       tm.tm_year, tm.tm_mon, tm.tm_mday,
-                       (tm.tm_wday<0 || tm.tm_wday>6) ?
-                               "unknown " : RELOC(weekdays[tm.tm_wday]),
-                       tm.tm_hour, tm.tm_min, tm.tm_sec);
-
-               break;
-       default:
-               rcode = CMD_RET_USAGE;
-       }
-
-       /* switch back to original I2C bus */
-#ifdef CONFIG_SYS_I2C
-       i2c_set_bus_num(old_bus);
-#elif !defined(CONFIG_DM_RTC)
-       I2C_SET_BUS(old_bus);
-#endif
-
-       return rcode ? CMD_RET_FAILURE : 0;
-}
-
-/*
- * simple conversion of two-digit string with error checking
- */
-static int cnvrt2 (const char *str, int *valp)
-{
-       int val;
-
-       if ((*str < '0') || (*str > '9'))
-               return (-1);
-
-       val = *str - '0';
-
-       ++str;
-
-       if ((*str < '0') || (*str > '9'))
-               return (-1);
-
-       *valp = 10 * val + (*str - '0');
-
-       return (0);
-}
-
-/*
- * Convert date string: MMDDhhmm[[CC]YY][.ss]
- *
- * Some basic checking for valid values is done, but this will not catch
- * all possible error conditions.
- */
-int mk_date (const char *datestr, struct rtc_time *tmp)
-{
-       int len, val;
-       char *ptr;
-
-       ptr = strchr (datestr,'.');
-       len = strlen (datestr);
-
-       /* Set seconds */
-       if (ptr) {
-               int sec;
-
-               *ptr++ = '\0';
-               if ((len - (ptr - datestr)) != 2)
-                       return (-1);
-
-               len = strlen (datestr);
-
-               if (cnvrt2 (ptr, &sec))
-                       return (-1);
-
-               tmp->tm_sec = sec;
-       } else {
-               tmp->tm_sec = 0;
-       }
-
-       if (len == 12) {                /* MMDDhhmmCCYY */
-               int year, century;
-
-               if (cnvrt2 (datestr+ 8, &century) ||
-                   cnvrt2 (datestr+10, &year) ) {
-                       return (-1);
-               }
-               tmp->tm_year = 100 * century + year;
-       } else if (len == 10) {         /* MMDDhhmmYY   */
-               int year, century;
-
-               century = tmp->tm_year / 100;
-               if (cnvrt2 (datestr+ 8, &year))
-                       return (-1);
-               tmp->tm_year = 100 * century + year;
-       }
-
-       switch (len) {
-       case 8:                 /* MMDDhhmm     */
-               /* fall thru */
-       case 10:                /* MMDDhhmmYY   */
-               /* fall thru */
-       case 12:                /* MMDDhhmmCCYY */
-               if (cnvrt2 (datestr+0, &val) ||
-                   val > 12) {
-                       break;
-               }
-               tmp->tm_mon  = val;
-               if (cnvrt2 (datestr+2, &val) ||
-                   val > ((tmp->tm_mon==2) ? 29 : 31)) {
-                       break;
-               }
-               tmp->tm_mday = val;
-
-               if (cnvrt2 (datestr+4, &val) ||
-                   val > 23) {
-                       break;
-               }
-               tmp->tm_hour = val;
-
-               if (cnvrt2 (datestr+6, &val) ||
-                   val > 59) {
-                       break;
-               }
-               tmp->tm_min  = val;
-
-               /* calculate day of week */
-               rtc_calc_weekday(tmp);
-
-               return (0);
-       default:
-               break;
-       }
-
-       return (-1);
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       date,   2,      1,      do_date,
-       "get/set/reset date & time",
-       "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n"
-       "  - without arguments: print date & time\n"
-       "  - with numeric argument: set the system date & time\n"
-       "  - with 'reset' argument: reset the RTC"
-);
diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c
deleted file mode 100644 (file)
index cc77250..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * (C) Copyright 2001
- * Erik Theisen,  Wave 7 Optics, etheisen@mindspring.com.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * AMCC 4XX DCR Functions
- */
-
-#include <common.h>
-#include <cli.h>
-#include <config.h>
-#include <command.h>
-#include <console.h>
-
-unsigned long get_dcr (unsigned short);
-unsigned long set_dcr (unsigned short, unsigned long);
-
-/* =======================================================================
- * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
- * =======================================================================
- */
-int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
-{
-       unsigned short dcrn;    /* Device Control Register Num */
-       unsigned long value;    /* DCR's value */
-
-       unsigned long get_dcr (unsigned short);
-
-       /* Validate arguments */
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* Get a DCR */
-       dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
-       value = get_dcr (dcrn);
-
-       printf ("%04x: %08lx\n", dcrn, value);
-
-       return 0;
-}
-
-
-/* ======================================================================
- * Interpreter command to set an AMCC PPC 4xx Device Control Register
- * ======================================================================
-*/
-int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned short dcrn;    /* Device Control Register Num */
-       unsigned long value;
-
-       /* DCR's value */
-       int nbytes;
-
-       /* Validate arguments */
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* Set a DCR */
-       dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
-       do {
-               value = get_dcr (dcrn);
-               printf ("%04x: %08lx", dcrn, value);
-               nbytes = cli_readline(" ? ");
-               if (nbytes == 0) {
-                       /*
-                        * <CR> pressed as only input, don't modify current
-                        * location and exit command.
-                        */
-                       nbytes = 1;
-                       return 0;
-               } else {
-                       unsigned long i;
-                       char *endp;
-
-                       i = simple_strtoul (console_buffer, &endp, 16);
-                       nbytes = endp - console_buffer;
-                       if (nbytes)
-                               set_dcr (dcrn, i);
-               }
-       } while (nbytes);
-
-       return 0;
-}
-
-/* =======================================================================
- * Interpreter command to retrieve an register value through AMCC PPC 4xx
- * Device Control Register inderect addressing.
- * =======================================================================
- */
-int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned short adr_dcrn;        /* Device Control Register Num for Address */
-       unsigned short dat_dcrn;        /* Device Control Register Num for Data */
-       unsigned short offset;          /* Register's offset */
-       unsigned long value;            /* Register's value */
-       char *ptr = NULL;
-       char buf[80];
-
-       /* Validate arguments */
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       /* Find out whether ther is '.' (dot) symbol in the first parameter. */
-       strncpy (buf, argv[1], sizeof(buf)-1);
-       buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
-       ptr = strchr (buf, '.');
-
-       if (ptr != NULL) {
-               /* First parameter has format adr_dcrn.dat_dcrn */
-               *ptr++ = 0; /* erase '.', create zero-end string */
-               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
-               dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
-       } else {
-               /*
-                * First parameter has format adr_dcrn; dat_dcrn will be
-                * calculated as adr_dcrn+1.
-                */
-               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
-               dat_dcrn = adr_dcrn+1;
-       }
-
-       /* Register's offset */
-       offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
-
-       /* Disable interrupts */
-       disable_interrupts ();
-       /* Set offset */
-       set_dcr (adr_dcrn, offset);
-       /* get data */
-       value = get_dcr (dat_dcrn);
-       /* Enable interrupts */
-       enable_interrupts ();
-
-       printf ("%04x.%04x-%04x Read  %08lx\n", adr_dcrn, dat_dcrn, offset, value);
-
-       return 0;
-}
-
-/* =======================================================================
- * Interpreter command to update an register value through AMCC PPC 4xx
- * Device Control Register inderect addressing.
- * =======================================================================
- */
-int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned short adr_dcrn;        /* Device Control Register Num for Address */
-       unsigned short dat_dcrn;        /* Device Control Register Num for Data */
-       unsigned short offset;          /* Register's offset */
-       unsigned long value;            /* Register's value */
-       char *ptr = NULL;
-       char buf[80];
-
-       /* Validate arguments */
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       /* Find out whether ther is '.' (dot) symbol in the first parameter. */
-       strncpy (buf, argv[1], sizeof(buf)-1);
-       buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
-       ptr = strchr (buf, '.');
-
-       if (ptr != NULL) {
-               /* First parameter has format adr_dcrn.dat_dcrn */
-               *ptr++ = 0;     /* erase '.', create zero-end string */
-               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
-               dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
-       } else {
-               /*
-                * First parameter has format adr_dcrn; dat_dcrn will be
-                * calculated as adr_dcrn+1.
-                */
-               adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
-               dat_dcrn = adr_dcrn+1;
-       }
-
-       /* Register's offset */
-       offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
-       /* New value */
-       value  = (unsigned  long) simple_strtoul (argv[3], NULL, 16);
-
-       /* Disable interrupts */
-       disable_interrupts ();
-       /* Set offset */
-       set_dcr (adr_dcrn, offset);
-       /* set data */
-       set_dcr (dat_dcrn, value);
-       /* Enable interrupts */
-       enable_interrupts ();
-
-       printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
-
-       return 0;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       getdcr, 2,      1,      do_getdcr,
-       "Get an AMCC PPC 4xx DCR's value",
-       "dcrn - return a DCR's value."
-);
-U_BOOT_CMD(
-       setdcr, 2,      1,      do_setdcr,
-       "Set an AMCC PPC 4xx DCR's value",
-       "dcrn - set a DCR's value."
-);
-
-U_BOOT_CMD(
-       getidcr,        3,      1,      do_getidcr,
-       "Get a register value via indirect DCR addressing",
-       "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
-);
-
-U_BOOT_CMD(
-       setidcr,        4,      1,      do_setidcr,
-       "Set a register value via indirect DCR addressing",
-       "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
-);
diff --git a/common/cmd_demo.c b/common/cmd_demo.c
deleted file mode 100644 (file)
index 209dc4a..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2013 Google, Inc
- *
- * (C) Copyright 2012
- * Pavel Herrmann <morpheus.ibis@gmail.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <dm-demo.h>
-#include <mapmem.h>
-#include <asm/io.h>
-
-struct udevice *demo_dev;
-
-static int do_demo_hello(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char * const argv[])
-{
-       int ch = 0;
-
-       if (argc)
-               ch = *argv[0];
-
-       return demo_hello(demo_dev, ch);
-}
-
-static int do_demo_status(cmd_tbl_t *cmdtp, int flag, int argc,
-                         char * const argv[])
-{
-       int status;
-       int ret;
-
-       ret = demo_status(demo_dev, &status);
-       if (ret)
-               return ret;
-
-       printf("Status: %d\n", status);
-
-       return 0;
-}
-
-static int do_demo_light(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char * const argv[])
-{
-       int light;
-       int ret;
-
-       if (argc) {
-               light = simple_strtoul(argv[0], NULL, 16);
-               ret = demo_set_light(demo_dev, light);
-       } else {
-               ret = demo_get_light(demo_dev);
-               if (ret >= 0) {
-                       printf("Light: %x\n", ret);
-                       ret = 0;
-               }
-       }
-
-       return ret;
-}
-
-int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       int i, ret;
-
-       puts("Demo uclass entries:\n");
-
-       for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
-            dev;
-            ret = uclass_next_device(&dev)) {
-               printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
-                      i++, map_to_sysmem(dev),
-                      map_to_sysmem(dev->driver->ops),
-                      map_to_sysmem(dev_get_platdata(dev)));
-       }
-
-       return cmd_process_error(cmdtp, ret);
-}
-
-static cmd_tbl_t demo_commands[] = {
-       U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
-       U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
-       U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
-       U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
-};
-
-static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *demo_cmd;
-       int devnum = 0;
-       int ret;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-       demo_cmd = find_cmd_tbl(argv[1], demo_commands,
-                               ARRAY_SIZE(demo_commands));
-       argc -= 2;
-       argv += 2;
-
-       if ((!demo_cmd || argc > demo_cmd->maxargs) ||
-           ((demo_cmd->name[0] != 'l') && (argc < 1)))
-               return CMD_RET_USAGE;
-
-       if (argc) {
-               devnum = simple_strtoul(argv[0], NULL, 10);
-               ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
-               if (ret)
-                       return cmd_process_error(cmdtp, ret);
-               argc--;
-               argv++;
-       } else {
-               demo_dev = NULL;
-               if (demo_cmd->cmd != do_demo_list)
-                       return CMD_RET_USAGE;
-       }
-
-       ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
-
-       return cmd_process_error(demo_cmd, ret);
-}
-
-U_BOOT_CMD(
-       demo,   4,      1,      do_demo,
-       "Driver model (dm) demo operations",
-       "list                     List available demo devices\n"
-       "demo hello <num> [<char>]     Say hello\n"
-       "demo light [<num>]            Set or get the lights\n"
-       "demo status <num>             Get demo device status\n"
-       "demo list                     List available demo devices"
-);
diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
deleted file mode 100644 (file)
index 6d95ce9..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * cmd_dfu.c -- dfu command
- *
- * Copyright (C) 2015
- * Lukasz Majewski <l.majewski@majess.pl>
- *
- * Copyright (C) 2012 Samsung Electronics
- * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
- *         Lukasz Majewski <l.majewski@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <watchdog.h>
-#include <dfu.h>
-#include <console.h>
-#include <g_dnl.h>
-#include <usb.h>
-#include <net.h>
-
-static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       bool dfu_reset = false;
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       char *usb_controller = argv[1];
-       char *interface = argv[2];
-       char *devstring = argv[3];
-
-       int ret, i = 0;
-#ifdef CONFIG_DFU_TFTP
-       unsigned long addr = 0;
-       if (!strcmp(argv[1], "tftp")) {
-               if (argc == 5)
-                       addr = simple_strtoul(argv[4], NULL, 0);
-
-               return update_tftp(addr, interface, devstring);
-       }
-#endif
-
-       ret = dfu_init_env_entities(interface, devstring);
-       if (ret)
-               goto done;
-
-       ret = CMD_RET_SUCCESS;
-       if (argc > 4 && strcmp(argv[4], "list") == 0) {
-               dfu_show_entities();
-               goto done;
-       }
-
-       int controller_index = simple_strtoul(usb_controller, NULL, 0);
-       board_usb_init(controller_index, USB_INIT_DEVICE);
-       g_dnl_clear_detach();
-       g_dnl_register("usb_dnl_dfu");
-       while (1) {
-               if (g_dnl_detach()) {
-                       /*
-                        * Check if USB bus reset is performed after detach,
-                        * which indicates that -R switch has been passed to
-                        * dfu-util. In this case reboot the device
-                        */
-                       if (dfu_usb_get_reset()) {
-                               dfu_reset = true;
-                               goto exit;
-                       }
-
-                       /*
-                        * This extra number of usb_gadget_handle_interrupts()
-                        * calls is necessary to assure correct transmission
-                        * completion with dfu-util
-                        */
-                       if (++i == 10000)
-                               goto exit;
-               }
-
-               if (ctrlc())
-                       goto exit;
-
-               WATCHDOG_RESET();
-               usb_gadget_handle_interrupts(controller_index);
-       }
-exit:
-       g_dnl_unregister();
-       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
-done:
-       dfu_free_entities();
-
-       if (dfu_reset)
-               run_command("reset", 0);
-
-       g_dnl_clear_detach();
-
-       return ret;
-}
-
-U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
-       "Device Firmware Upgrade",
-       "<USB_controller> <interface> <dev> [list]\n"
-       "  - device firmware upgrade via <USB_controller>\n"
-       "    on device <dev>, attached to interface\n"
-       "    <interface>\n"
-       "    [list] - list available alt settings\n"
-#ifdef CONFIG_DFU_TFTP
-       "dfu tftp <interface> <dev> [<addr>]\n"
-       "  - device firmware upgrade via TFTP\n"
-       "    on device <dev>, attached to interface\n"
-       "    <interface>\n"
-       "    [<addr>] - address where FIT image has been stored\n"
-#endif
-);
diff --git a/common/cmd_diag.c b/common/cmd_diag.c
deleted file mode 100644 (file)
index 14ae04f..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * (C) Copyright 2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Diagnostics support
- */
-#include <common.h>
-#include <command.h>
-#include <post.h>
-
-int do_diag (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int i;
-
-       if (argc == 1 || strcmp (argv[1], "run") != 0) {
-               /* List test info */
-               if (argc == 1) {
-                       puts ("Available hardware tests:\n");
-                       post_info (NULL);
-                       puts ("Use 'diag [<test1> [<test2> ...]]'"
-                                       " to get more info.\n");
-                       puts ("Use 'diag run [<test1> [<test2> ...]]'"
-                                       " to run tests.\n");
-               } else {
-                       for (i = 1; i < argc; i++) {
-                           if (post_info (argv[i]) != 0)
-                               printf ("%s - no such test\n", argv[i]);
-                       }
-               }
-       } else {
-               /* Run tests */
-               if (argc == 2) {
-                       post_run (NULL, POST_RAM | POST_MANUAL);
-               } else {
-                       for (i = 2; i < argc; i++) {
-                           if (post_run (argv[i], POST_RAM | POST_MANUAL) != 0)
-                               printf ("%s - unable to execute the test\n",
-                                       argv[i]);
-                       }
-               }
-       }
-
-       return 0;
-}
-/***************************************************/
-
-U_BOOT_CMD(
-       diag,   CONFIG_SYS_MAXARGS,     0,      do_diag,
-       "perform board diagnostics",
-            "    - print list of available tests\n"
-       "diag [test1 [test2]]\n"
-       "         - print information about specified tests\n"
-       "diag run - run all available tests\n"
-       "diag run [test1 [test2]]\n"
-       "         - run specified tests"
-);
diff --git a/common/cmd_disk.c b/common/cmd_disk.c
deleted file mode 100644 (file)
index 3025225..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * (C) Copyright 2000-2011
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <command.h>
-#include <part.h>
-
-#if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
-       defined(CONFIG_USB_STORAGE)
-int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
-                   char *const argv[])
-{
-       int dev, part;
-       ulong addr = CONFIG_SYS_LOAD_ADDR;
-       ulong cnt;
-       disk_partition_t info;
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       image_header_t *hdr;
-#endif
-       block_dev_desc_t *dev_desc;
-
-#if defined(CONFIG_FIT)
-       const void *fit_hdr = NULL;
-#endif
-
-       bootstage_mark(BOOTSTAGE_ID_IDE_START);
-       if (argc > 3) {
-               bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
-               return CMD_RET_USAGE;
-       }
-       bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
-
-       if (argc > 1)
-               addr = simple_strtoul(argv[1], NULL, 16);
-
-       bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
-
-       part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
-                                       &dev_desc, &info, 1);
-       if (part < 0) {
-               bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
-               return 1;
-       }
-
-       dev = dev_desc->dev;
-       bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
-
-       printf("\nLoading from %s device %d, partition %d: "
-              "Name: %.32s  Type: %.32s\n", intf, dev, part, info.name,
-              info.type);
-
-       debug("First Block: " LBAFU ",  # of blocks: " LBAFU
-             ", Block Size: %ld\n",
-             info.start, info.size, info.blksz);
-
-       if (dev_desc->block_read(dev_desc, info.start, 1, (ulong *)addr) != 1) {
-               printf("** Read error on %d:%d\n", dev, part);
-               bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
-
-       switch (genimg_get_format((void *) addr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-               hdr = (image_header_t *) addr;
-
-               bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
-
-               if (!image_check_hcrc(hdr)) {
-                       puts("\n** Bad Header Checksum **\n");
-                       bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
-                       return 1;
-               }
-               bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
-
-               image_print_contents(hdr);
-
-               cnt = image_get_image_size(hdr);
-               break;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               fit_hdr = (const void *) addr;
-               puts("Fit image detected...\n");
-
-               cnt = fit_get_size(fit_hdr);
-               break;
-#endif
-       default:
-               bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
-               puts("** Unknown image type\n");
-               return 1;
-       }
-
-       cnt += info.blksz - 1;
-       cnt /= info.blksz;
-       cnt -= 1;
-
-       if (dev_desc->block_read(dev_desc, info.start + 1, cnt,
-                                (ulong *)(addr + info.blksz)) != cnt) {
-               printf("** Read error on %d:%d\n", dev, part);
-               bootstage_error(BOOTSTAGE_ID_IDE_READ);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_IDE_READ);
-
-#if defined(CONFIG_FIT)
-       /* This cannot be done earlier,
-        * we need complete FIT image in RAM first */
-       if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
-               if (!fit_check_format(fit_hdr)) {
-                       bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
-                       puts("** Bad FIT image format\n");
-                       return 1;
-               }
-               bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
-               fit_print_contents(fit_hdr);
-       }
-#endif
-
-       flush_cache(addr, (cnt+1)*info.blksz);
-
-       /* Loading ok, update default load address */
-       load_addr = addr;
-
-       return bootm_maybe_autostart(cmdtp, argv[0]);
-}
-#endif
diff --git a/common/cmd_display.c b/common/cmd_display.c
deleted file mode 100644 (file)
index bc1b1eb..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * (C) Copyright 2005
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <led-display.h>
-
-#undef DEBUG_DISP
-
-int do_display (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-
-       /* Clear display */
-       display_set(DISPLAY_CLEAR | DISPLAY_HOME);
-
-       if (argc < 2)
-               return (0);
-
-       for (i = 1; i < argc; i++) {
-               char *p = argv[i];
-
-               if (i > 1) { /* Insert a space between strings */
-                       display_putc(' ');
-               }
-
-               while ((*p)) {
-#ifdef DEBUG_DISP
-                       putc(*p);
-#endif
-                       display_putc(*p++);
-               }
-       }
-
-#ifdef DEBUG_DISP
-       putc('\n');
-#endif
-
-       return (0);
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       display,        CONFIG_SYS_MAXARGS,     1,      do_display,
-       "display string on dot matrix display",
-       "[<string>]\n"
-       "    - with <string> argument: display <string> on dot matrix display\n"
-       "    - without arguments: clear dot matrix display"
-);
diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c
deleted file mode 100644 (file)
index f2e750f..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * (C) Copyright 2001
- * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-
-#include <dtt.h>
-#include <i2c.h>
-#include <tmu.h>
-
-#if defined CONFIG_DTT_SENSORS
-static unsigned long sensor_initialized;
-
-static void _initialize_dtt(void)
-{
-       int i;
-       unsigned char sensors[] = CONFIG_DTT_SENSORS;
-
-       for (i = 0; i < sizeof(sensors); i++) {
-               if ((sensor_initialized & (1 << i)) == 0) {
-                       if (dtt_init_one(sensors[i]) != 0) {
-                               printf("DTT%d: Failed init!\n", i);
-                               continue;
-                       }
-                       sensor_initialized |= (1 << i);
-               }
-       }
-}
-
-void dtt_init(void)
-{
-       int old_bus;
-
-       /* switch to correct I2C bus */
-       old_bus = I2C_GET_BUS();
-       I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
-
-       _initialize_dtt();
-
-       /* switch back to original I2C bus */
-       I2C_SET_BUS(old_bus);
-}
-#endif
-
-int dtt_i2c(void)
-{
-#if defined CONFIG_DTT_SENSORS
-       int i;
-       unsigned char sensors[] = CONFIG_DTT_SENSORS;
-       int old_bus;
-
-       /* Force a compilation error, if there are more then 32 sensors */
-       BUILD_BUG_ON(sizeof(sensors) > 32);
-       /* switch to correct I2C bus */
-#ifdef CONFIG_SYS_I2C
-       old_bus = i2c_get_bus_num();
-       i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
-#else
-       old_bus = I2C_GET_BUS();
-       I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
-#endif
-
-       _initialize_dtt();
-
-       /*
-        * Loop through sensors, read
-        * temperature, and output it.
-        */
-       for (i = 0; i < sizeof(sensors); i++)
-               printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
-
-       /* switch back to original I2C bus */
-#ifdef CONFIG_SYS_I2C
-       i2c_set_bus_num(old_bus);
-#else
-       I2C_SET_BUS(old_bus);
-#endif
-#endif
-
-       return 0;
-}
-
-int dtt_tmu(void)
-{
-#if defined CONFIG_TMU_CMD_DTT
-       int cur_temp;
-
-       /* Sense and return latest thermal info */
-       if (tmu_monitor(&cur_temp) == TMU_STATUS_INIT) {
-               puts("TMU is in unknown state, temperature is invalid\n");
-               return -1;
-       }
-       printf("Current temperature: %u degrees Celsius\n", cur_temp);
-#endif
-       return 0;
-}
-
-int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int err = 0;
-
-       err |= dtt_i2c();
-       err |= dtt_tmu();
-
-       return err;
-}      /* do_dtt() */
-
-/***************************************************/
-
-U_BOOT_CMD(
-         dtt,  1,      1,      do_dtt,
-         "Read temperature from Digital Thermometer and Thermostat",
-         ""
-);
diff --git a/common/cmd_echo.c b/common/cmd_echo.c
deleted file mode 100644 (file)
index 3dc3a63..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       int putnl = 1;
-
-       for (i = 1; i < argc; i++) {
-               char *p = argv[i];
-               char *nls; /* new-line suppression */
-
-               if (i > 1)
-                       putc(' ');
-
-               nls = strstr(p, "\\c");
-               if (nls) {
-                       char *prenls = p;
-
-                       putnl = 0;
-                       /*
-                        * be paranoid and guess that someone might
-                        * say \c more than once
-                        */
-                       while (nls) {
-                               *nls = '\0';
-                               puts(prenls);
-                               *nls = '\\';
-                               prenls = nls + 2;
-                               nls = strstr(prenls, "\\c");
-                       }
-                       puts(prenls);
-               } else {
-                       puts(p);
-               }
-       }
-
-       if (putnl)
-               putc('\n');
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
-       "echo args to console",
-       "[args..]\n"
-       "    - echo args to console; \\c suppresses newline"
-);
diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c
deleted file mode 100644 (file)
index 571240a..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * (C) Copyright 2000, 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Support for read and write access to EEPROM like memory devices. This
- * includes regular EEPROM as well as  FRAM (ferroelectic nonvolaile RAM).
- * FRAM devices read and write data at bus speed. In particular, there is no
- * write delay. Also, there is no limit imposed on the number of bytes that can
- * be transferred with a single read or write.
- *
- * Use the following configuration options to ensure no unneeded performance
- * degradation (typical for EEPROM) is incured for FRAM memory:
- *
- * #define CONFIG_SYS_I2C_FRAM
- * #undef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
- *
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <i2c.h>
-
-#ifndef        CONFIG_SYS_I2C_SPEED
-#define        CONFIG_SYS_I2C_SPEED    50000
-#endif
-
-#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
-#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS  0
-#endif
-
-#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
-#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS      8
-#endif
-
-#define        EEPROM_PAGE_SIZE        (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
-#define        EEPROM_PAGE_OFFSET(x)   ((x) & (EEPROM_PAGE_SIZE - 1))
-
-/*
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
- *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
- *
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
- *   0x00000nxx for EEPROM address selectors and page number at n.
- */
-#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
-       (CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
-       (CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
-#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
-#endif
-#endif
-
-__weak int eeprom_write_enable(unsigned dev_addr, int state)
-{
-       return 0;
-}
-
-void eeprom_init(int bus)
-{
-       /* SPI EEPROM */
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-       spi_init_f();
-#endif
-
-       /* I2C EEPROM */
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
-#if defined(CONFIG_SYS_I2C)
-       if (bus >= 0)
-               i2c_set_bus_num(bus);
-#endif
-       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-#endif
-}
-
-static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
-{
-       unsigned blk_off;
-       int alen;
-
-       blk_off = offset & 0xff;        /* block offset */
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
-       addr[0] = offset >> 8;          /* block number */
-       addr[1] = blk_off;              /* block offset */
-       alen = 2;
-#else
-       addr[0] = offset >> 16;         /* block number */
-       addr[1] = offset >>  8;         /* upper address octet */
-       addr[2] = blk_off;              /* lower address octet */
-       alen = 3;
-#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
-
-       addr[0] |= dev_addr;            /* insert device address */
-
-       return alen;
-}
-
-static int eeprom_len(unsigned offset, unsigned end)
-{
-       unsigned len = end - offset;
-
-       /*
-        * For a FRAM device there is no limit on the number of the
-        * bytes that can be ccessed with the single read or write
-        * operation.
-        */
-#if !defined(CONFIG_SYS_I2C_FRAM)
-       unsigned blk_off = offset & 0xff;
-       unsigned maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
-
-       if (maxlen > I2C_RXTX_LEN)
-               maxlen = I2C_RXTX_LEN;
-
-       if (len > maxlen)
-               len = maxlen;
-#endif
-
-       return len;
-}
-
-static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
-                          uchar *buffer, unsigned len, bool read)
-{
-       int ret = 0;
-
-       /* SPI */
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-       if (read)
-               spi_read(addr, alen, buffer, len);
-       else
-               spi_write(addr, alen, buffer, len);
-#else  /* I2C */
-
-#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
-       i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
-#endif
-
-       if (read)
-               ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
-       else
-               ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
-
-       if (ret)
-               ret = 1;
-#endif
-       return ret;
-}
-
-static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
-                    unsigned cnt, bool read)
-{
-       unsigned end = offset + cnt;
-       unsigned alen, len;
-       int rcode = 0;
-       uchar addr[3];
-
-       while (offset < end) {
-               alen = eeprom_addr(dev_addr, offset, addr);
-
-               len = eeprom_len(offset, end);
-
-               rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
-
-               buffer += len;
-               offset += len;
-
-               if (!read)
-                       udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-       }
-
-       return rcode;
-}
-
-int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
-{
-       /*
-        * Read data until done or would cross a page boundary.
-        * We must write the address again when changing pages
-        * because the next page may be in a different device.
-        */
-       return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
-}
-
-int eeprom_write(unsigned dev_addr, unsigned offset,
-                uchar *buffer, unsigned cnt)
-{
-       int ret;
-
-       eeprom_write_enable(dev_addr, 1);
-
-       /*
-        * Write data until done or would cross a write page boundary.
-        * We must write the address again when changing pages
-        * because the address counter only increments within a page.
-        */
-       ret = eeprom_rw(dev_addr, offset, buffer, cnt, 0);
-
-       eeprom_write_enable(dev_addr, 0);
-       return ret;
-}
-
-static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const char *const fmt =
-               "\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
-       char * const *args = &argv[2];
-       int rcode;
-       ulong dev_addr, addr, off, cnt;
-       int bus_addr;
-
-       switch (argc) {
-#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
-       case 5:
-               bus_addr = -1;
-               dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
-               break;
-#endif
-       case 6:
-               bus_addr = -1;
-               dev_addr = simple_strtoul(*args++, NULL, 16);
-               break;
-       case 7:
-               bus_addr = simple_strtoul(*args++, NULL, 16);
-               dev_addr = simple_strtoul(*args++, NULL, 16);
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       addr = simple_strtoul(*args++, NULL, 16);
-       off = simple_strtoul(*args++, NULL, 16);
-       cnt = simple_strtoul(*args++, NULL, 16);
-
-       eeprom_init(bus_addr);
-
-       if (strcmp(argv[1], "read") == 0) {
-               printf(fmt, dev_addr, argv[1], addr, off, cnt);
-
-               rcode = eeprom_read(dev_addr, off, (uchar *)addr, cnt);
-
-               puts("done\n");
-               return rcode;
-       } else if (strcmp(argv[1], "write") == 0) {
-               printf(fmt, dev_addr, argv[1], addr, off, cnt);
-
-               rcode = eeprom_write(dev_addr, off, (uchar *)addr, cnt);
-
-               puts("done\n");
-               return rcode;
-       }
-
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       eeprom, 7,      1,      do_eeprom,
-       "EEPROM sub-system",
-       "read  <bus> <devaddr> addr off cnt\n"
-       "eeprom write <bus> <devaddr> addr off cnt\n"
-       "       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
-)
diff --git a/common/cmd_efi.c b/common/cmd_efi.c
deleted file mode 100644 (file)
index c76296e..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * (C) Copyright 2015 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <efi.h>
-#include <errno.h>
-#include <malloc.h>
-
-static const char *const type_name[] = {
-       "reserved",
-       "loader_code",
-       "loader_data",
-       "bs_code",
-       "bs_data",
-       "rt_code",
-       "rt_data",
-       "conv",
-       "unusable",
-       "acpi_reclaim",
-       "acpi_nvs",
-       "io",
-       "io_port",
-       "pal_code",
-};
-
-static struct attr_info {
-       int shift;
-       const char *name;
-} mem_attr[] = {
-       { EFI_MEMORY_UC_SHIFT, "uncached" },
-       { EFI_MEMORY_WC_SHIFT, "write-coalescing" },
-       { EFI_MEMORY_WT_SHIFT, "write-through" },
-       { EFI_MEMORY_WB_SHIFT, "write-back" },
-       { EFI_MEMORY_UCE_SHIFT, "uncached & exported" },
-       { EFI_MEMORY_WP_SHIFT, "write-protect" },
-       { EFI_MEMORY_RP_SHIFT, "read-protect" },
-       { EFI_MEMORY_XP_SHIFT, "execute-protect" },
-       { EFI_MEMORY_RUNTIME_SHIFT, "needs runtime mapping" }
-};
-
-/* Maximum different attribute values we can track */
-#define ATTR_SEEN_MAX  30
-
-static inline bool is_boot_services(int type)
-{
-       return type == EFI_LOADER_CODE || type == EFI_LOADER_DATA ||
-               type == EFI_BOOT_SERVICES_CODE ||
-               type == EFI_BOOT_SERVICES_DATA;
-}
-
-static int h_cmp_entry(const void *v1, const void *v2)
-{
-       const struct efi_mem_desc *desc1 = v1;
-       const struct efi_mem_desc *desc2 = v2;
-       int64_t diff = desc1->physical_start - desc2->physical_start;
-
-       /*
-        * Manually calculate the difference to avoid sign loss in the 64-bit
-        * to 32-bit conversion
-        */
-       return diff < 0 ? -1 : diff > 0 ? 1 : 0;
-}
-
-void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs)
-{
-       struct efi_mem_desc *desc, *end, *base, *dest, *prev;
-       int count;
-       u64 addr;
-
-       base = malloc(size + sizeof(*desc));
-       if (!base) {
-               debug("%s: Cannot allocate %#x bytes\n", __func__, size);
-               return NULL;
-       }
-       end = (struct efi_mem_desc *)((ulong)map + size);
-       count = ((ulong)end - (ulong)map->desc) / map->desc_size;
-       memcpy(base, map->desc, (ulong)end - (ulong)map->desc);
-       qsort(base, count, map->desc_size, h_cmp_entry);
-       prev = NULL;
-       addr = 0;
-       dest = base;
-       end = base + count;
-       for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
-               bool merge = true;
-               int type = desc->type;
-
-               if (skip_bs && is_boot_services(desc->type))
-                       type = EFI_CONVENTIONAL_MEMORY;
-
-               memcpy(dest, desc, map->desc_size);
-               dest->type = type;
-               if (!skip_bs || !prev)
-                       merge = false;
-               else if (desc->physical_start != addr)
-                       merge = false;
-               else if (type != EFI_CONVENTIONAL_MEMORY)
-                       merge = false;
-               else if (prev->type != EFI_CONVENTIONAL_MEMORY)
-                       merge = false;
-
-               if (merge) {
-                       prev->num_pages += desc->num_pages;
-               } else {
-                       prev = dest;
-                       dest = efi_get_next_mem_desc(map, dest);
-               }
-               addr = desc->physical_start + (desc->num_pages <<
-                               EFI_PAGE_SHIFT);
-       }
-
-       /* Mark the end */
-       dest->type = EFI_TABLE_END;
-
-       return base;
-}
-
-static void efi_print_mem_table(struct efi_entry_memmap *map,
-                               struct efi_mem_desc *desc, bool skip_bs)
-{
-       u64 attr_seen[ATTR_SEEN_MAX];
-       int attr_seen_count;
-       int upto, i;
-       u64 addr;
-
-       printf(" #  %-14s  %10s  %10s  %10s  %s\n", "Type", "Physical",
-              "Virtual", "Size", "Attributes");
-
-       /* Keep track of all the different attributes we have seen */
-       attr_seen_count = 0;
-       addr = 0;
-       for (upto = 0; desc->type != EFI_TABLE_END;
-            upto++, desc = efi_get_next_mem_desc(map, desc)) {
-               const char *name;
-               u64 size;
-
-               if (skip_bs && is_boot_services(desc->type))
-                       continue;
-               if (desc->physical_start != addr) {
-                       printf("    %-14s  %010llx  %10s  %010llx\n", "<gap>",
-                              addr, "", desc->physical_start - addr);
-               }
-               size = desc->num_pages << EFI_PAGE_SHIFT;
-
-               name = desc->type < ARRAY_SIZE(type_name) ?
-                               type_name[desc->type] : "<invalid>";
-               printf("%2d  %x:%-12s  %010llx  %010llx  %010llx  ", upto,
-                      desc->type, name, desc->physical_start,
-                      desc->virtual_start, size);
-               if (desc->attribute & EFI_MEMORY_RUNTIME)
-                       putc('r');
-               printf("%llx", desc->attribute & ~EFI_MEMORY_RUNTIME);
-               putc('\n');
-
-               for (i = 0; i < attr_seen_count; i++) {
-                       if (attr_seen[i] == desc->attribute)
-                               break;
-               }
-               if (i == attr_seen_count && i < ATTR_SEEN_MAX)
-                       attr_seen[attr_seen_count++] = desc->attribute;
-               addr = desc->physical_start + size;
-       }
-
-       printf("\nAttributes key:\n");
-       for (i = 0; i < attr_seen_count; i++) {
-               u64 attr = attr_seen[i];
-               bool first;
-               int j;
-
-               printf("%c%llx: ", attr & EFI_MEMORY_RUNTIME ? 'r' : ' ',
-                      attr & ~EFI_MEMORY_RUNTIME);
-               for (j = 0, first = true; j < ARRAY_SIZE(mem_attr); j++) {
-                       if (attr & (1ULL << mem_attr[j].shift)) {
-                               if (first)
-                                       first = false;
-                               else
-                                       printf(", ");
-                               printf("%s", mem_attr[j].name);
-                       }
-               }
-               putc('\n');
-       }
-       if (skip_bs)
-               printf("*Some areas are merged (use 'all' to see)\n");
-}
-
-static int do_efi_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct efi_mem_desc *desc;
-       struct efi_entry_memmap *map;
-       int size, ret;
-       bool skip_bs;
-
-       skip_bs = !argc || *argv[0] != 'a';
-       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
-       switch (ret) {
-       case -ENOENT:
-               printf("No EFI table available\n");
-               goto done;
-       case -EPROTONOSUPPORT:
-               printf("Incorrect EFI table version\n");
-               goto done;
-       }
-       printf("EFI table at %lx, memory map %p, size %x, version %x, descr. size %#x\n",
-              gd->arch.table, map, size, map->version, map->desc_size);
-       if (map->version != EFI_MEM_DESC_VERSION) {
-               printf("Incorrect memory map version\n");
-               ret = -EPROTONOSUPPORT;
-               goto done;
-       }
-
-       desc = efi_build_mem_table(map, size, skip_bs);
-       if (!desc) {
-               ret = -ENOMEM;
-               goto done;
-       }
-
-       efi_print_mem_table(map, desc, skip_bs);
-       free(desc);
-done:
-       if (ret)
-               printf("Error: %d\n", ret);
-
-       return ret ? CMD_RET_FAILURE : 0;
-}
-
-static cmd_tbl_t efi_commands[] = {
-       U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
-};
-
-static int do_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *efi_cmd;
-       int ret;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-       efi_cmd = find_cmd_tbl(argv[1], efi_commands, ARRAY_SIZE(efi_commands));
-       argc -= 2;
-       argv += 2;
-       if (!efi_cmd || argc > efi_cmd->maxargs)
-               return CMD_RET_USAGE;
-
-       ret = efi_cmd->cmd(efi_cmd, flag, argc, argv);
-
-       return cmd_process_error(efi_cmd, ret);
-}
-
-U_BOOT_CMD(
-       efi,     3,      1,      do_efi,
-       "EFI access",
-       "mem [all]        Dump memory information [include boot services]"
-);
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
deleted file mode 100644 (file)
index 5190cc6..0000000
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (c) 2001 William L. Pitts
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are freely
- * permitted provided that the above copyright notice and this
- * paragraph and the following disclaimer are duplicated in all
- * such forms.
- *
- * This software is provided "AS IS" and without any express or
- * implied warranties, including, without limitation, the implied
- * warranties of merchantability and fitness for a particular
- * purpose.
- */
-
-#include <common.h>
-#include <command.h>
-#include <elf.h>
-#include <net.h>
-#include <vxworks.h>
-#ifdef CONFIG_X86
-#include <asm/e820.h>
-#include <linux/linkage.h>
-#endif
-
-/*
- * A very simple elf loader, assumes the image is valid, returns the
- * entry point address.
- */
-static unsigned long load_elf_image_phdr(unsigned long addr)
-{
-       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
-       Elf32_Phdr *phdr; /* Program header structure pointer */
-       int i;
-
-       ehdr = (Elf32_Ehdr *)addr;
-       phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
-
-       /* Load each program header */
-       for (i = 0; i < ehdr->e_phnum; ++i) {
-               void *dst = (void *)(uintptr_t)phdr->p_paddr;
-               void *src = (void *)addr + phdr->p_offset;
-               debug("Loading phdr %i to 0x%p (%i bytes)\n",
-                     i, dst, phdr->p_filesz);
-               if (phdr->p_filesz)
-                       memcpy(dst, src, phdr->p_filesz);
-               if (phdr->p_filesz != phdr->p_memsz)
-                       memset(dst + phdr->p_filesz, 0x00,
-                              phdr->p_memsz - phdr->p_filesz);
-               flush_cache((unsigned long)dst, phdr->p_filesz);
-               ++phdr;
-       }
-
-       return ehdr->e_entry;
-}
-
-static unsigned long load_elf_image_shdr(unsigned long addr)
-{
-       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
-       Elf32_Shdr *shdr; /* Section header structure pointer */
-       unsigned char *strtab = 0; /* String table pointer */
-       unsigned char *image; /* Binary image pointer */
-       int i; /* Loop counter */
-
-       ehdr = (Elf32_Ehdr *)addr;
-
-       /* Find the section header string table for output info */
-       shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
-                            (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
-
-       if (shdr->sh_type == SHT_STRTAB)
-               strtab = (unsigned char *)(addr + shdr->sh_offset);
-
-       /* Load each appropriate section */
-       for (i = 0; i < ehdr->e_shnum; ++i) {
-               shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
-                                    (i * sizeof(Elf32_Shdr)));
-
-               if (!(shdr->sh_flags & SHF_ALLOC) ||
-                   shdr->sh_addr == 0 || shdr->sh_size == 0) {
-                       continue;
-               }
-
-               if (strtab) {
-                       debug("%sing %s @ 0x%08lx (%ld bytes)\n",
-                             (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
-                              &strtab[shdr->sh_name],
-                              (unsigned long)shdr->sh_addr,
-                              (long)shdr->sh_size);
-               }
-
-               if (shdr->sh_type == SHT_NOBITS) {
-                       memset((void *)(uintptr_t)shdr->sh_addr, 0,
-                              shdr->sh_size);
-               } else {
-                       image = (unsigned char *)addr + shdr->sh_offset;
-                       memcpy((void *)(uintptr_t)shdr->sh_addr,
-                              (const void *)image, shdr->sh_size);
-               }
-               flush_cache(shdr->sh_addr, shdr->sh_size);
-       }
-
-       return ehdr->e_entry;
-}
-
-/* Allow ports to override the default behavior */
-static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
-                                    int argc, char * const argv[])
-{
-       unsigned long ret;
-
-       /*
-        * QNX images require the data cache is disabled.
-        * Data cache is already flushed, so just turn it off.
-        */
-       int dcache = dcache_status();
-       if (dcache)
-               dcache_disable();
-
-       /*
-        * pass address parameter as argv[0] (aka command name),
-        * and all remaining args
-        */
-       ret = entry(argc, argv);
-
-       if (dcache)
-               dcache_enable();
-
-       return ret;
-}
-
-/*
- * Determine if a valid ELF image exists at the given memory location.
- * First look at the ELF header magic field, then make sure that it is
- * executable.
- */
-int valid_elf_image(unsigned long addr)
-{
-       Elf32_Ehdr *ehdr; /* Elf header structure pointer */
-
-       ehdr = (Elf32_Ehdr *)addr;
-
-       if (!IS_ELF(*ehdr)) {
-               printf("## No elf image at address 0x%08lx\n", addr);
-               return 0;
-       }
-
-       if (ehdr->e_type != ET_EXEC) {
-               printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
-               return 0;
-       }
-
-       return 1;
-}
-
-/* Interpreter command to boot an arbitrary ELF image from memory */
-int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long addr; /* Address of the ELF image */
-       unsigned long rc; /* Return value from user code */
-       char *sload, *saddr;
-       const char *ep = getenv("autostart");
-
-       int rcode = 0;
-
-       sload = saddr = NULL;
-       if (argc == 3) {
-               sload = argv[1];
-               saddr = argv[2];
-       } else if (argc == 2) {
-               if (argv[1][0] == '-')
-                       sload = argv[1];
-               else
-                       saddr = argv[1];
-       }
-
-       if (saddr)
-               addr = simple_strtoul(saddr, NULL, 16);
-       else
-               addr = load_addr;
-
-       if (!valid_elf_image(addr))
-               return 1;
-
-       if (sload && sload[1] == 'p')
-               addr = load_elf_image_phdr(addr);
-       else
-               addr = load_elf_image_shdr(addr);
-
-       if (ep && !strcmp(ep, "no"))
-               return rcode;
-
-       printf("## Starting application at 0x%08lx ...\n", addr);
-
-       /*
-        * pass address parameter as argv[0] (aka command name),
-        * and all remaining args
-        */
-       rc = do_bootelf_exec((void *)addr, argc - 1, argv + 1);
-       if (rc != 0)
-               rcode = 1;
-
-       printf("## Application terminated, rc = 0x%lx\n", rc);
-
-       return rcode;
-}
-
-/*
- * Interpreter command to boot VxWorks from a memory image.  The image can
- * be either an ELF image or a raw binary.  Will attempt to setup the
- * bootline and other parameters correctly.
- */
-int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long addr; /* Address of image */
-       unsigned long bootaddr; /* Address to put the bootline */
-       char *bootline; /* Text of the bootline */
-       char *tmp; /* Temporary char pointer */
-       char build_buf[128]; /* Buffer for building the bootline */
-       int ptr = 0;
-#ifdef CONFIG_X86
-       struct e820info *info;
-       struct e820entry *data;
-#endif
-
-       /*
-        * Check the loadaddr variable.
-        * If we don't know where the image is then we're done.
-        */
-       if (argc < 2)
-               addr = load_addr;
-       else
-               addr = simple_strtoul(argv[1], NULL, 16);
-
-#if defined(CONFIG_CMD_NET)
-       /*
-        * Check to see if we need to tftp the image ourselves
-        * before starting
-        */
-       if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
-               if (net_loop(TFTPGET) <= 0)
-                       return 1;
-               printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
-                       addr);
-       }
-#endif
-
-       /*
-        * This should equate to
-        * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
-        * from the VxWorks BSP header files.
-        * This will vary from board to board
-        */
-#if defined(CONFIG_WALNUT)
-       tmp = (char *)CONFIG_SYS_NVRAM_BASE_ADDR + 0x500;
-       eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
-       memcpy(tmp, &build_buf[3], 3);
-#elif defined(CONFIG_SYS_VXWORKS_MAC_PTR)
-       tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
-       eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
-       memcpy(tmp, build_buf, 6);
-#else
-       puts("## Ethernet MAC address not copied to NV RAM\n");
-#endif
-
-       /*
-        * Use bootaddr to find the location in memory that VxWorks
-        * will look for the bootline string. The default value is
-        * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
-        * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
-        */
-       tmp = getenv("bootaddr");
-       if (!tmp) {
-               printf("## VxWorks bootline address not specified\n");
-       } else {
-               bootaddr = simple_strtoul(tmp, NULL, 16);
-
-               /*
-                * Check to see if the bootline is defined in the 'bootargs'
-                * parameter. If it is not defined, we may be able to
-                * construct the info.
-                */
-               bootline = getenv("bootargs");
-               if (bootline) {
-                       memcpy((void *)bootaddr, bootline,
-                              max(strlen(bootline), (size_t)255));
-                       flush_cache(bootaddr, max(strlen(bootline),
-                                                 (size_t)255));
-               } else {
-                       tmp = getenv("bootdev");
-                       if (tmp) {
-                               strcpy(build_buf, tmp);
-                               ptr = strlen(tmp);
-                       } else
-                               printf("## VxWorks boot device not specified\n");
-
-                       tmp = getenv("bootfile");
-                       if (tmp)
-                               ptr += sprintf(build_buf + ptr,
-                                              "host:%s ", tmp);
-                       else
-                               ptr += sprintf(build_buf + ptr,
-                                              "host:vxWorks ");
-
-                       /*
-                        * The following parameters are only needed if 'bootdev'
-                        * is an ethernet device, otherwise they are optional.
-                        */
-                       tmp = getenv("ipaddr");
-                       if (tmp) {
-                               ptr += sprintf(build_buf + ptr, "e=%s", tmp);
-                               tmp = getenv("netmask");
-                               if (tmp) {
-                                       u32 mask = getenv_ip("netmask").s_addr;
-                                       ptr += sprintf(build_buf + ptr,
-                                                      ":%08x ", ntohl(mask));
-                               } else {
-                                       ptr += sprintf(build_buf + ptr, " ");
-                               }
-                       }
-
-                       tmp = getenv("serverip");
-                       if (tmp)
-                               ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
-
-                       tmp = getenv("gatewayip");
-                       if (tmp)
-                               ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
-
-                       tmp = getenv("hostname");
-                       if (tmp)
-                               ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
-
-                       tmp = getenv("othbootargs");
-                       if (tmp) {
-                               strcpy(build_buf + ptr, tmp);
-                               ptr += strlen(tmp);
-                       }
-
-                       memcpy((void *)bootaddr, build_buf,
-                              max(strlen(build_buf), (size_t)255));
-                       flush_cache(bootaddr, max(strlen(build_buf),
-                                                 (size_t)255));
-               }
-
-               printf("## Using bootline (@ 0x%lx): %s\n", bootaddr,
-                      (char *)bootaddr);
-       }
-
-#ifdef CONFIG_X86
-       /*
-        * Since E820 information is critical to the kernel, if we don't
-        * specify these in the environments, use a default one.
-        */
-       tmp = getenv("e820data");
-       if (tmp)
-               data = (struct e820entry *)simple_strtoul(tmp, NULL, 16);
-       else
-               data = (struct e820entry *)VXWORKS_E820_DATA_ADDR;
-       tmp = getenv("e820info");
-       if (tmp)
-               info = (struct e820info *)simple_strtoul(tmp, NULL, 16);
-       else
-               info = (struct e820info *)VXWORKS_E820_INFO_ADDR;
-
-       memset(info, 0, sizeof(struct e820info));
-       info->sign = E820_SIGNATURE;
-       info->entries = install_e820_map(E820MAX, data);
-       info->addr = (info->entries - 1) * sizeof(struct e820entry) +
-                    VXWORKS_E820_DATA_ADDR;
-#endif
-
-       /*
-        * If the data at the load address is an elf image, then
-        * treat it like an elf image. Otherwise, assume that it is a
-        * binary image.
-        */
-       if (valid_elf_image(addr))
-               addr = load_elf_image_shdr(addr);
-       else
-               puts("## Not an ELF image, assuming binary\n");
-
-       printf("## Starting vxWorks at 0x%08lx ...\n", addr);
-
-       dcache_disable();
-#ifdef CONFIG_X86
-       /* VxWorks on x86 uses stack to pass parameters */
-       ((asmlinkage void (*)(int))addr)(0);
-#else
-       ((void (*)(int))addr)(0);
-#endif
-
-       puts("## vxWorks terminated\n");
-
-       return 1;
-}
-
-U_BOOT_CMD(
-       bootelf, 3, 0, do_bootelf,
-       "Boot from an ELF image in memory",
-       "[-p|-s] [address]\n"
-       "\t- load ELF image at [address] via program headers (-p)\n"
-       "\t  or via section headers (-s)"
-);
-
-U_BOOT_CMD(
-       bootvx, 2, 0, do_bootvx,
-       "Boot vxWorks from an ELF image",
-       " [address] - load address of vxWorks ELF image."
-);
diff --git a/common/cmd_ethsw.c b/common/cmd_ethsw.c
deleted file mode 100644 (file)
index 8e452e9..0000000
+++ /dev/null
@@ -1,1027 +0,0 @@
-/*
- * Copyright 2015 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:      GPL-2.0+
- *
- * Ethernet Switch commands
- */
-
-#include <common.h>
-#include <command.h>
-#include <errno.h>
-#include <env_flags.h>
-#include <ethsw.h>
-
-static const char *ethsw_name;
-
-#define ETHSW_PORT_STATS_HELP "ethsw [port <port_no>] statistics " \
-"{ [help] | [clear] } - show an l2 switch port's statistics"
-
-static int ethsw_port_stats_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_PORT_STATS_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_LEARN_HELP "ethsw [port <port_no>] learning " \
-"{ [help] | show | auto | disable } " \
-"- enable/disable/show learning configuration on a port"
-
-static int ethsw_learn_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_LEARN_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
-"{ [help] | show | flush | { add | del } <mac> } " \
-"- Add/delete a mac entry in FDB; use show to see FDB entries; " \
-"if vlan <vid> is missing, VID 1 will be used"
-
-static int ethsw_fdb_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_FDB_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_PVID_HELP "ethsw [port <port_no>] " \
-"pvid { [help] | show | <pvid> } " \
-"- set/show PVID (ingress and egress VLAN tagging) for a port"
-
-static int ethsw_pvid_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_PVID_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_VLAN_HELP "ethsw [port <port_no>] vlan " \
-"{ [help] | show | add <vid> | del <vid> } " \
-"- add a VLAN to a port (VLAN members)"
-
-static int ethsw_vlan_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_VLAN_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
-"{ [help] | show | all | none | pvid } " \
-" - set egress tagging mod for a port"
-
-static int ethsw_port_untag_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_PORT_UNTAG_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
-"{ [help] | show | pvid | classified } " \
-"- Configure VID source for egress tag. " \
-"Tag's VID could be the frame's classified VID or the PVID of the port"
-
-static int ethsw_egr_tag_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_EGR_VLAN_TAG_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_VLAN_FDB_HELP "ethsw vlan fdb " \
-"{ [help] | show | shared | private } " \
-"- make VLAN learning shared or private"
-
-static int ethsw_vlan_learn_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_VLAN_FDB_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-#define ETHSW_PORT_INGR_FLTR_HELP "ethsw [port <port_no>] ingress filtering" \
-" { [help] | show | enable | disable } " \
-"- enable/disable VLAN ingress filtering on port"
-
-static int ethsw_ingr_fltr_help_key_func(struct ethsw_command_def *parsed_cmd)
-{
-       printf(ETHSW_PORT_INGR_FLTR_HELP"\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-static struct keywords_to_function {
-       enum ethsw_keyword_id cmd_keyword[ETHSW_MAX_CMD_PARAMS];
-       int cmd_func_offset;
-       int (*keyword_function)(struct ethsw_command_def *parsed_cmd);
-} ethsw_cmd_def[] = {
-               {
-                       .cmd_keyword = {
-                                       ethsw_id_enable,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_enable),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_disable,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_disable),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_statistics,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_port_stats_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_statistics,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_stats),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_statistics,
-                                       ethsw_id_clear,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_stats_clear),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_learning,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_learn_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_learning,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_learn_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_learning,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_learn_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_learning,
-                                       ethsw_id_auto,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_learn),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_learning,
-                                       ethsw_id_disable,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_learn),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_fdb_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_fdb_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   fdb_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_flush,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   fdb_flush),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_add,
-                                       ethsw_id_add_del_mac,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   fdb_entry_add),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_fdb,
-                                       ethsw_id_del,
-                                       ethsw_id_add_del_mac,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   fdb_entry_del),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_pvid,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_pvid_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_pvid,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_pvid_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_pvid,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   pvid_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_pvid,
-                                       ethsw_id_pvid_no,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   pvid_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_vlan_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_vlan_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_add,
-                                       ethsw_id_add_del_no,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_del,
-                                       ethsw_id_add_del_no,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_port_untag_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_port_untag_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_untag_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_all,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_untag_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_none,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_untag_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_untagged,
-                                       ethsw_id_pvid,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_untag_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_egress,
-                                       ethsw_id_tag,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_egr_tag_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_egress,
-                                       ethsw_id_tag,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_egr_tag_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_egress,
-                                       ethsw_id_tag,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_egr_vlan_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_egress,
-                                       ethsw_id_tag,
-                                       ethsw_id_pvid,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_egr_vlan_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_egress,
-                                       ethsw_id_tag,
-                                       ethsw_id_classified,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_egr_vlan_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_fdb,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_vlan_learn_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_fdb,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_vlan_learn_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_fdb,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_learn_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_fdb,
-                                       ethsw_id_shared,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_learn_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_vlan,
-                                       ethsw_id_fdb,
-                                       ethsw_id_private,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   vlan_learn_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_ingress,
-                                       ethsw_id_filtering,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_ingr_fltr_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_ingress,
-                                       ethsw_id_filtering,
-                                       ethsw_id_help,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = -1,
-                       .keyword_function = &ethsw_ingr_fltr_help_key_func,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_ingress,
-                                       ethsw_id_filtering,
-                                       ethsw_id_show,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_ingr_filt_show),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_ingress,
-                                       ethsw_id_filtering,
-                                       ethsw_id_enable,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_ingr_filt_set),
-                       .keyword_function = NULL,
-               }, {
-                       .cmd_keyword = {
-                                       ethsw_id_ingress,
-                                       ethsw_id_filtering,
-                                       ethsw_id_disable,
-                                       ethsw_id_key_end,
-                       },
-                       .cmd_func_offset = offsetof(struct ethsw_command_func,
-                                                   port_ingr_filt_set),
-                       .keyword_function = NULL,
-               },
-};
-
-struct keywords_optional {
-       int cmd_keyword[ETHSW_MAX_CMD_PARAMS];
-} cmd_opt_def[] = {
-               {
-                               .cmd_keyword = {
-                                               ethsw_id_port,
-                                               ethsw_id_port_no,
-                                               ethsw_id_key_end,
-                               },
-               }, {
-                               .cmd_keyword = {
-                                               ethsw_id_vlan,
-                                               ethsw_id_vlan_no,
-                                               ethsw_id_key_end,
-                               },
-               }, {
-                               .cmd_keyword = {
-                                               ethsw_id_port,
-                                               ethsw_id_port_no,
-                                               ethsw_id_vlan,
-                                               ethsw_id_vlan_no,
-                                               ethsw_id_key_end,
-                               },
-               },
-};
-
-static int keyword_match_gen(enum ethsw_keyword_id key_id, int argc, char
-                            *const argv[], int *argc_nr,
-                            struct ethsw_command_def *parsed_cmd);
-static int keyword_match_port(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd);
-static int keyword_match_vlan(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd);
-static int keyword_match_pvid(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd);
-static int keyword_match_mac_addr(enum ethsw_keyword_id key_id, int argc,
-                                 char *const argv[], int *argc_nr,
-                                 struct ethsw_command_def *parsed_cmd);
-
-/*
- * Define properties for each keyword;
- * keep the order synced with enum ethsw_keyword_id
- */
-struct keyword_def {
-       const char *keyword_name;
-       int (*match)(enum ethsw_keyword_id key_id, int argc, char *const argv[],
-                    int *argc_nr, struct ethsw_command_def *parsed_cmd);
-} keyword[] = {
-               {
-                               .keyword_name = "help",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "show",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "port",
-                               .match = &keyword_match_port
-               },  {
-                               .keyword_name = "enable",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "disable",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "statistics",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "clear",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "learning",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "auto",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "vlan",
-                               .match = &keyword_match_vlan,
-               }, {
-                               .keyword_name = "fdb",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "add",
-                               .match = &keyword_match_mac_addr,
-               }, {
-                               .keyword_name = "del",
-                               .match = &keyword_match_mac_addr,
-               }, {
-                               .keyword_name = "flush",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "pvid",
-                               .match = &keyword_match_pvid,
-               }, {
-                               .keyword_name = "untagged",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "all",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "none",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "egress",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "tag",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "classified",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "shared",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "private",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "ingress",
-                               .match = &keyword_match_gen,
-               }, {
-                               .keyword_name = "filtering",
-                               .match = &keyword_match_gen,
-               },
-};
-
-/*
- * Function used by an Ethernet Switch driver to set the functions
- * that must be called by the parser when an ethsw command is given
- */
-int ethsw_define_functions(const struct ethsw_command_func *cmd_func)
-{
-       int i;
-       void **aux_p;
-       int (*cmd_func_aux)(struct ethsw_command_def *);
-
-       if (!cmd_func->ethsw_name)
-               return -EINVAL;
-
-       ethsw_name = cmd_func->ethsw_name;
-
-       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
-               /*
-                * get the pointer to the function send by the Ethernet Switch
-                * driver that corresponds to the proper ethsw command
-                */
-               if (ethsw_cmd_def[i].keyword_function)
-                       continue;
-
-               aux_p = (void *)cmd_func + ethsw_cmd_def[i].cmd_func_offset;
-
-               cmd_func_aux = (int (*)(struct ethsw_command_def *)) *aux_p;
-               ethsw_cmd_def[i].keyword_function = cmd_func_aux;
-       }
-
-       return 0;
-}
-
-/* Generic function used to match a keyword only by a string */
-static int keyword_match_gen(enum ethsw_keyword_id key_id, int argc,
-                            char *const argv[], int *argc_nr,
-                            struct ethsw_command_def *parsed_cmd)
-{
-       if (strcmp(argv[*argc_nr], keyword[key_id].keyword_name) == 0) {
-               parsed_cmd->cmd_to_keywords[*argc_nr] = key_id;
-
-               return 1;
-       }
-       return 0;
-}
-
-/* Function used to match the command's port */
-static int keyword_match_port(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd)
-{
-       unsigned long val;
-
-       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
-               return 0;
-
-       if (*argc_nr + 1 >= argc)
-               return 0;
-
-       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
-               parsed_cmd->port = val;
-               (*argc_nr)++;
-               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_port_no;
-               return 1;
-       }
-
-       return 0;
-}
-
-/* Function used to match the command's vlan */
-static int keyword_match_vlan(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd)
-{
-       unsigned long val;
-       int aux;
-
-       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
-               return 0;
-
-       if (*argc_nr + 1 >= argc)
-               return 0;
-
-       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
-               parsed_cmd->vid = val;
-               (*argc_nr)++;
-               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_vlan_no;
-               return 1;
-       }
-
-       aux = *argc_nr + 1;
-
-       if (keyword_match_gen(ethsw_id_add, argc, argv, &aux, parsed_cmd))
-               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_add;
-       else if (keyword_match_gen(ethsw_id_del, argc, argv, &aux, parsed_cmd))
-               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_del;
-       else
-               return 0;
-
-       if (*argc_nr + 2 >= argc)
-               return 0;
-
-       if (strict_strtoul(argv[*argc_nr + 2], 10, &val) != -EINVAL) {
-               parsed_cmd->vid = val;
-               (*argc_nr) += 2;
-               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_add_del_no;
-               return 1;
-       }
-
-       return 0;
-}
-
-/* Function used to match the command's pvid */
-static int keyword_match_pvid(enum ethsw_keyword_id key_id, int argc,
-                             char *const argv[], int *argc_nr,
-                             struct ethsw_command_def *parsed_cmd)
-{
-       unsigned long val;
-
-       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
-               return 0;
-
-       if (*argc_nr + 1 >= argc)
-               return 1;
-
-       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
-               parsed_cmd->vid = val;
-               (*argc_nr)++;
-               parsed_cmd->cmd_to_keywords[*argc_nr] = ethsw_id_pvid_no;
-       }
-
-       return 1;
-}
-
-/* Function used to match the command's MAC address */
-static int keyword_match_mac_addr(enum ethsw_keyword_id key_id, int argc,
-                                    char *const argv[], int *argc_nr,
-                                    struct ethsw_command_def *parsed_cmd)
-{
-       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
-               return 0;
-
-       if ((*argc_nr + 1 >= argc) ||
-           !is_broadcast_ethaddr(parsed_cmd->ethaddr))
-               return 1;
-
-       if (eth_validate_ethaddr_str(argv[*argc_nr + 1])) {
-               printf("Invalid MAC address: %s\n", argv[*argc_nr + 1]);
-               return 0;
-       }
-
-       eth_parse_enetaddr(argv[*argc_nr + 1], parsed_cmd->ethaddr);
-
-       if (is_broadcast_ethaddr(parsed_cmd->ethaddr)) {
-               memset(parsed_cmd->ethaddr, 0xFF, sizeof(parsed_cmd->ethaddr));
-               return 0;
-       }
-
-       parsed_cmd->cmd_to_keywords[*argc_nr + 1] = ethsw_id_add_del_mac;
-
-       return 1;
-}
-
-/* Finds optional keywords and modifies *argc_va to skip them */
-static void cmd_keywords_opt_check(const struct ethsw_command_def *parsed_cmd,
-                                  int *argc_val)
-{
-       int i;
-       int keyw_opt_matched;
-       int argc_val_max;
-       int const *cmd_keyw_p;
-       int const *cmd_keyw_opt_p;
-
-       /* remember the best match */
-       argc_val_max = *argc_val;
-
-       /*
-        * check if our command's optional keywords match the optional
-        * keywords of an available command
-        */
-       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
-               keyw_opt_matched = 0;
-               cmd_keyw_p = &parsed_cmd->cmd_to_keywords[keyw_opt_matched];
-               cmd_keyw_opt_p = &cmd_opt_def[i].cmd_keyword[keyw_opt_matched];
-
-               /*
-                * increase the number of keywords that
-                * matched with a command
-                */
-               while (keyw_opt_matched + *argc_val <
-                      parsed_cmd->cmd_keywords_nr &&
-                      *cmd_keyw_opt_p != ethsw_id_key_end &&
-                      *(cmd_keyw_p + *argc_val) == *cmd_keyw_opt_p) {
-                       keyw_opt_matched++;
-                       cmd_keyw_p++;
-                       cmd_keyw_opt_p++;
-               }
-
-               /*
-                * if all our optional command's keywords perfectly match an
-                * optional pattern, then we can move to the next defined
-                * keywords in our command; remember the one that matched the
-                * greatest number of keywords
-                */
-               if (keyw_opt_matched + *argc_val <=
-                   parsed_cmd->cmd_keywords_nr &&
-                   *cmd_keyw_opt_p == ethsw_id_key_end &&
-                   *argc_val + keyw_opt_matched > argc_val_max)
-                       argc_val_max = *argc_val + keyw_opt_matched;
-       }
-
-       *argc_val = argc_val_max;
-}
-
-/*
- * Finds the function to call based on keywords and
- * modifies *argc_va to skip them
- */
-static void cmd_keywords_check(struct ethsw_command_def *parsed_cmd,
-                              int *argc_val)
-{
-       int i;
-       int keyw_matched;
-       int *cmd_keyw_p;
-       int *cmd_keyw_def_p;
-
-       /*
-        * check if our command's keywords match the
-        * keywords of an available command
-        */
-       for (i = 0; i < ARRAY_SIZE(ethsw_cmd_def); i++) {
-               keyw_matched = 0;
-               cmd_keyw_p = &parsed_cmd->cmd_to_keywords[keyw_matched];
-               cmd_keyw_def_p = &ethsw_cmd_def[i].cmd_keyword[keyw_matched];
-
-               /*
-                * increase the number of keywords that
-                * matched with a command
-                */
-               while (keyw_matched + *argc_val < parsed_cmd->cmd_keywords_nr &&
-                      *cmd_keyw_def_p != ethsw_id_key_end &&
-                      *(cmd_keyw_p + *argc_val) == *cmd_keyw_def_p) {
-                       keyw_matched++;
-                       cmd_keyw_p++;
-                       cmd_keyw_def_p++;
-               }
-
-               /*
-                * if all our command's keywords perfectly match an
-                * available command, then we get the function we need to call
-                * to configure the Ethernet Switch
-                */
-               if (keyw_matched && keyw_matched + *argc_val ==
-                   parsed_cmd->cmd_keywords_nr &&
-                   *cmd_keyw_def_p == ethsw_id_key_end) {
-                       *argc_val += keyw_matched;
-                       parsed_cmd->cmd_function =
-                                       ethsw_cmd_def[i].keyword_function;
-                       return;
-               }
-       }
-}
-
-/* find all the keywords in the command */
-static int keywords_find(int argc, char * const argv[],
-                        struct ethsw_command_def *parsed_cmd)
-{
-       int i;
-       int j;
-       int argc_val;
-       int rc = CMD_RET_SUCCESS;
-
-       for (i = 1; i < argc; i++) {
-               for (j = 0; j < ethsw_id_count; j++) {
-                       if (keyword[j].match(j, argc, argv, &i, parsed_cmd))
-                               break;
-               }
-       }
-
-       /* if there is no keyword match for a word, the command is invalid */
-       for (i = 1; i < argc; i++)
-               if (parsed_cmd->cmd_to_keywords[i] == ethsw_id_key_end)
-                       rc = CMD_RET_USAGE;
-
-       parsed_cmd->cmd_keywords_nr = argc;
-       argc_val = 1;
-
-       /* get optional parameters first */
-       cmd_keywords_opt_check(parsed_cmd, &argc_val);
-
-       if (argc_val == parsed_cmd->cmd_keywords_nr)
-               return CMD_RET_USAGE;
-
-       /*
-        * check the keywords and if a match is found,
-        * get the function to call
-        */
-       cmd_keywords_check(parsed_cmd, &argc_val);
-
-       /* error if not all commands' parameters were matched */
-       if (argc_val == parsed_cmd->cmd_keywords_nr) {
-               if (!parsed_cmd->cmd_function) {
-                       printf("Command not available for: %s\n", ethsw_name);
-                       rc = CMD_RET_FAILURE;
-               }
-       } else {
-               rc = CMD_RET_USAGE;
-       }
-
-       return rc;
-}
-
-static void command_def_init(struct ethsw_command_def *parsed_cmd)
-{
-       int i;
-
-       for (i = 0; i < ETHSW_MAX_CMD_PARAMS; i++)
-               parsed_cmd->cmd_to_keywords[i] = ethsw_id_key_end;
-
-       parsed_cmd->port = ETHSW_CMD_PORT_ALL;
-       parsed_cmd->vid = ETHSW_CMD_VLAN_ALL;
-       parsed_cmd->cmd_function = NULL;
-
-       /* We initialize the MAC address with the Broadcast address */
-       memset(parsed_cmd->ethaddr, 0xff, sizeof(parsed_cmd->ethaddr));
-}
-
-/* function to interpret commands starting with "ethsw " */
-static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct ethsw_command_def parsed_cmd;
-       int rc = CMD_RET_SUCCESS;
-
-       if (argc == 1 || argc >= ETHSW_MAX_CMD_PARAMS)
-               return CMD_RET_USAGE;
-
-       command_def_init(&parsed_cmd);
-
-       rc = keywords_find(argc, argv, &parsed_cmd);
-
-       if (rc == CMD_RET_SUCCESS)
-               rc = parsed_cmd.cmd_function(&parsed_cmd);
-
-       return rc;
-}
-
-#define ETHSW_PORT_CONF_HELP "[port <port_no>] { enable | disable | show } " \
-"- enable/disable a port; show shows a port's configuration"
-
-U_BOOT_CMD(ethsw, ETHSW_MAX_CMD_PARAMS, 0, do_ethsw,
-          "Ethernet l2 switch commands",
-          ETHSW_PORT_CONF_HELP"\n"
-          ETHSW_PORT_STATS_HELP"\n"
-          ETHSW_LEARN_HELP"\n"
-          ETHSW_FDB_HELP"\n"
-          ETHSW_PVID_HELP"\n"
-          ETHSW_VLAN_HELP"\n"
-          ETHSW_PORT_UNTAG_HELP"\n"
-          ETHSW_EGR_VLAN_TAG_HELP"\n"
-          ETHSW_VLAN_FDB_HELP"\n"
-          ETHSW_PORT_INGR_FLTR_HELP"\n"
-);
diff --git a/common/cmd_exit.c b/common/cmd_exit.c
deleted file mode 100644 (file)
index c789233..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int do_exit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int r;
-
-       r = 0;
-       if (argc > 1)
-               r = simple_strtoul(argv[1], NULL, 10);
-
-       return -r - 2;
-}
-
-U_BOOT_CMD(
-       exit,   2,      1,      do_exit,
-       "exit script",
-       ""
-);
diff --git a/common/cmd_ext2.c b/common/cmd_ext2.c
deleted file mode 100644 (file)
index 6657ef5..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * (C) Copyright 2011 - 2012 Samsung Electronics
- * EXT4 filesystem implementation in Uboot by
- * Uma Shankar <uma.shankar@samsung.com>
- * Manjunatha C Achar <a.manjunatha@samsung.com>
-
- * (C) Copyright 2004
- * esd gmbh <www.esd-electronics.com>
- * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
- *
- * made from cmd_reiserfs by
- *
- * (C) Copyright 2003 - 2004
- * Sysgo Real-Time Solutions, AG <www.elinos.com>
- * Pavel Bartusek <pba@sysgo.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Ext2fs support
- */
-#include <fs.h>
-
-static int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-/******************************************************************************
- * Ext2fs boot command intepreter. Derived from diskboot
- */
-int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-U_BOOT_CMD(
-       ext2ls, 4,      1,      do_ext2ls,
-       "list files in a directory (default /)",
-       "<interface> <dev[:part]> [directory]\n"
-       "    - list files from 'dev' on 'interface' in a 'directory'"
-)
-
-U_BOOT_CMD(
-       ext2load,       6,      0,      do_ext2load,
-       "load binary file from a Ext2 filesystem",
-       "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
-       "    - load binary file 'filename' from 'dev' on 'interface'\n"
-       "      to address 'addr' from ext2 filesystem."
-)
diff --git a/common/cmd_ext4.c b/common/cmd_ext4.c
deleted file mode 100644 (file)
index 19423d1..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * (C) Copyright 2011 - 2012 Samsung Electronics
- * EXT4 filesystem implementation in Uboot by
- * Uma Shankar <uma.shankar@samsung.com>
- * Manjunatha C Achar <a.manjunatha@samsung.com>
- *
- * Ext4fs support
- * made from existing cmd_ext2.c file of Uboot
- *
- * (C) Copyright 2004
- * esd gmbh <www.esd-electronics.com>
- * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
- *
- * made from cmd_reiserfs by
- *
- * (C) Copyright 2003 - 2004
- * Sysgo Real-Time Solutions, AG <www.elinos.com>
- * Pavel Bartusek <pba@sysgo.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Changelog:
- *     0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
- *             file in uboot. Added ext4fs ls load and write support.
- */
-
-#include <common.h>
-#include <part.h>
-#include <config.h>
-#include <command.h>
-#include <image.h>
-#include <linux/ctype.h>
-#include <asm/byteorder.h>
-#include <ext4fs.h>
-#include <linux/stat.h>
-#include <malloc.h>
-#include <fs.h>
-
-#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
-#include <usb.h>
-#endif
-
-int do_ext4_size(cmd_tbl_t *cmdtp, int flag, int argc,
-                                               char *const argv[])
-{
-       return do_size(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
-                                               char *const argv[])
-{
-       return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-#if defined(CONFIG_CMD_EXT4_WRITE)
-int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
-                 char *const argv[])
-{
-       return do_save(cmdtp, flag, argc, argv, FS_TYPE_EXT);
-}
-
-U_BOOT_CMD(ext4write, 7, 1, do_ext4_write,
-          "create a file in the root directory",
-          "<interface> <dev[:part]> <addr> <absolute filename path>\n"
-          "    [sizebytes] [file offset]\n"
-          "    - create a file in / directory");
-
-#endif
-
-U_BOOT_CMD(
-       ext4size,       4,      0,      do_ext4_size,
-       "determine a file's size",
-       "<interface> <dev[:part]> <filename>\n"
-       "    - Find file 'filename' from 'dev' on 'interface'\n"
-       "      and determine its size."
-);
-
-U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
-          "list files in a directory (default /)",
-          "<interface> <dev[:part]> [directory]\n"
-          "    - list files from 'dev' on 'interface' in a 'directory'");
-
-U_BOOT_CMD(ext4load, 7, 0, do_ext4_load,
-          "load binary file from a Ext4 filesystem",
-          "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
-          "    - load binary file 'filename' from 'dev' on 'interface'\n"
-          "      to address 'addr' from ext4 filesystem");
diff --git a/common/cmd_fastboot.c b/common/cmd_fastboot.c
deleted file mode 100644 (file)
index 488822a..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2008 - 2009 Windriver, <www.windriver.com>
- * Author: Tom Rix <Tom.Rix@windriver.com>
- *
- * (C) Copyright 2014 Linaro, Ltd.
- * Rob Herring <robh@kernel.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <g_dnl.h>
-#include <usb.h>
-
-static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int controller_index;
-       char *usb_controller;
-       int ret;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       usb_controller = argv[1];
-       controller_index = simple_strtoul(usb_controller, NULL, 0);
-
-       ret = board_usb_init(controller_index, USB_INIT_DEVICE);
-       if (ret) {
-               error("USB init failed: %d", ret);
-               return CMD_RET_FAILURE;
-       }
-
-       g_dnl_clear_detach();
-       ret = g_dnl_register("usb_dnl_fastboot");
-       if (ret)
-               return ret;
-
-       if (!g_dnl_board_usb_cable_connected()) {
-               puts("\rUSB cable not detected.\n" \
-                    "Command exit.\n");
-               ret = CMD_RET_FAILURE;
-               goto exit;
-       }
-
-       while (1) {
-               if (g_dnl_detach())
-                       break;
-               if (ctrlc())
-                       break;
-               usb_gadget_handle_interrupts(controller_index);
-       }
-
-       ret = CMD_RET_SUCCESS;
-
-exit:
-       g_dnl_unregister();
-       g_dnl_clear_detach();
-       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
-
-       return ret;
-}
-
-U_BOOT_CMD(
-       fastboot, 2, 1, do_fastboot,
-       "use USB Fastboot protocol",
-       "<USB_controller>\n"
-       "    - run as a fastboot usb device"
-);
diff --git a/common/cmd_fat.c b/common/cmd_fat.c
deleted file mode 100644 (file)
index aae993d..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * (C) Copyright 2002
- * Richard Jones, rjones@nexus-tech.net
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <command.h>
-#include <s_record.h>
-#include <net.h>
-#include <ata.h>
-#include <asm/io.h>
-#include <mapmem.h>
-#include <part.h>
-#include <fat.h>
-#include <fs.h>
-
-int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
-}
-
-U_BOOT_CMD(
-       fatsize,        4,      0,      do_fat_size,
-       "determine a file's size",
-       "<interface> <dev[:part]> <filename>\n"
-       "    - Find file 'filename' from 'dev' on 'interface'\n"
-       "      and determine its size."
-);
-
-int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
-}
-
-
-U_BOOT_CMD(
-       fatload,        7,      0,      do_fat_fsload,
-       "load binary file from a dos filesystem",
-       "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
-       "    - Load binary file 'filename' from 'dev' on 'interface'\n"
-       "      to address 'addr' from dos filesystem.\n"
-       "      'pos' gives the file position to start loading from.\n"
-       "      If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
-       "      'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
-       "      the load stops on end of file.\n"
-       "      If either 'pos' or 'bytes' are not aligned to\n"
-       "      ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
-       "      be printed and performance will suffer for the load."
-);
-
-static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
-}
-
-U_BOOT_CMD(
-       fatls,  4,      1,      do_fat_ls,
-       "list files in a directory (default /)",
-       "<interface> [<dev[:part]>] [directory]\n"
-       "    - list files from 'dev' on 'interface' in a 'directory'"
-);
-
-static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char * const argv[])
-{
-       int dev, part;
-       block_dev_desc_t *dev_desc;
-       disk_partition_t info;
-
-       if (argc < 2) {
-               printf("usage: fatinfo <interface> [<dev[:part]>]\n");
-               return 0;
-       }
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       dev = dev_desc->dev;
-       if (fat_set_blk_dev(dev_desc, &info) != 0) {
-               printf("\n** Unable to use %s %d:%d for fatinfo **\n",
-                       argv[1], dev, part);
-               return 1;
-       }
-       return file_fat_detectfs();
-}
-
-U_BOOT_CMD(
-       fatinfo,        3,      1,      do_fat_fsinfo,
-       "print information about filesystem",
-       "<interface> [<dev[:part]>]\n"
-       "    - print information about filesystem from 'dev' on 'interface'"
-);
-
-#ifdef CONFIG_FAT_WRITE
-static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       loff_t size;
-       int ret;
-       unsigned long addr;
-       unsigned long count;
-       block_dev_desc_t *dev_desc = NULL;
-       disk_partition_t info;
-       int dev = 0;
-       int part = 1;
-       void *buf;
-
-       if (argc < 5)
-               return cmd_usage(cmdtp);
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       dev = dev_desc->dev;
-
-       if (fat_set_blk_dev(dev_desc, &info) != 0) {
-               printf("\n** Unable to use %s %d:%d for fatwrite **\n",
-                       argv[1], dev, part);
-               return 1;
-       }
-       addr = simple_strtoul(argv[3], NULL, 16);
-       count = simple_strtoul(argv[5], NULL, 16);
-
-       buf = map_sysmem(addr, count);
-       ret = file_fat_write(argv[4], buf, 0, count, &size);
-       unmap_sysmem(buf);
-       if (ret < 0) {
-               printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
-                       argv[4], argv[1], dev, part);
-               return 1;
-       }
-
-       printf("%llu bytes written\n", size);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       fatwrite,       6,      0,      do_fat_fswrite,
-       "write file into a dos filesystem",
-       "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
-       "    - write file 'filename' from the address 'addr' in RAM\n"
-       "      to 'dev' on 'interface'"
-);
-#endif
diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c
deleted file mode 100644 (file)
index 5766b56..0000000
+++ /dev/null
@@ -1,752 +0,0 @@
-/*
- * (C) Copyright 2001
- * Denis Peter, MPL AG, d.peter@mpl.ch.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-/*
- * Floppy Disk support
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <image.h>
-
-
-#undef FDC_DEBUG
-
-#ifdef FDC_DEBUG
-#define        PRINTF(fmt,args...)     printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
-
-/*#if defined(CONFIG_CMD_DATE) */
-/*#include <rtc.h> */
-/*#endif */
-
-typedef struct {
-       int             flags;          /* connected drives ect */
-       unsigned long   blnr;           /* Logical block nr */
-       uchar           drive;          /* drive no */
-       uchar           cmdlen;         /* cmd length */
-       uchar           cmd[16];        /* cmd desc */
-       uchar           dma;            /* if > 0 dma enabled */
-       uchar           result[11];     /* status information */
-       uchar           resultlen;      /* lenght of result */
-} FDC_COMMAND_STRUCT;
-
-/* flags: only the lower 8bit used:
- * bit 0 if set drive 0 is present
- * bit 1 if set drive 1 is present
- * bit 2 if set drive 2 is present
- * bit 3 if set drive 3 is present
- * bit 4 if set disk in drive 0 is inserted
- * bit 5 if set disk in drive 1 is inserted
- * bit 6 if set disk in drive 2 is inserted
- * bit 7 if set disk in drive 4 is inserted
- */
-
-/* cmd indexes */
-#define COMMAND                        0
-#define DRIVE                  1
-#define CONFIG0                        1
-#define SPEC_HUTSRT            1
-#define TRACK                  2
-#define CONFIG1                        2
-#define SPEC_HLT               2
-#define HEAD                   3
-#define CONFIG2                        3
-#define SECTOR                 4
-#define SECTOR_SIZE            5
-#define LAST_TRACK             6
-#define GAP                    7
-#define DTL                    8
-/* result indexes */
-#define STATUS_0               0
-#define STATUS_PCN             1
-#define STATUS_1               1
-#define STATUS_2               2
-#define STATUS_TRACK           3
-#define STATUS_HEAD            4
-#define STATUS_SECT            5
-#define STATUS_SECT_SIZE       6
-
-
-/* Register addresses */
-#define FDC_BASE       0x3F0
-#define FDC_SRA                FDC_BASE + 0    /* Status Register A */
-#define FDC_SRB                FDC_BASE + 1    /* Status Register B */
-#define FDC_DOR                FDC_BASE + 2    /* Digital Output Register */
-#define FDC_TDR                FDC_BASE + 3    /* Tape Drive Register */
-#define FDC_DSR                FDC_BASE + 4    /* Data rate Register */
-#define FDC_MSR                FDC_BASE + 4    /* Main Status Register */
-#define FDC_FIFO       FDC_BASE + 5    /* FIFO */
-#define FDC_DIR                FDC_BASE + 6    /* Digital Input Register */
-#define FDC_CCR                FDC_BASE + 7    /* Configuration Control */
-/* Commands */
-#define FDC_CMD_SENSE_INT      0x08
-#define FDC_CMD_CONFIGURE      0x13
-#define FDC_CMD_SPECIFY                0x03
-#define FDC_CMD_RECALIBRATE    0x07
-#define FDC_CMD_READ           0x06
-#define FDC_CMD_READ_TRACK     0x02
-#define FDC_CMD_READ_ID                0x0A
-#define FDC_CMD_DUMP_REG       0x0E
-#define FDC_CMD_SEEK           0x0F
-
-#define FDC_CMD_SENSE_INT_LEN  0x01
-#define FDC_CMD_CONFIGURE_LEN  0x04
-#define FDC_CMD_SPECIFY_LEN    0x03
-#define FDC_CMD_RECALIBRATE_LEN        0x02
-#define FDC_CMD_READ_LEN       0x09
-#define FDC_CMD_READ_TRACK_LEN 0x09
-#define FDC_CMD_READ_ID_LEN    0x02
-#define FDC_CMD_DUMP_REG_LEN   0x01
-#define FDC_CMD_SEEK_LEN       0x03
-
-#define FDC_FIFO_THR           0x0C
-#define FDC_FIFO_DIS           0x00
-#define FDC_IMPLIED_SEEK       0x01
-#define FDC_POLL_DIS           0x00
-#define FDC_PRE_TRK            0x00
-#define FDC_CONFIGURE          FDC_FIFO_THR | (FDC_POLL_DIS<<4) | (FDC_FIFO_DIS<<5) | (FDC_IMPLIED_SEEK << 6)
-#define FDC_MFM_MODE           0x01 /* MFM enable */
-#define FDC_SKIP_MODE          0x00 /* skip enable */
-
-#define FDC_TIME_OUT 100000 /* time out */
-#define        FDC_RW_RETRIES          3 /* read write retries */
-#define FDC_CAL_RETRIES                3 /* calibration and seek retries */
-
-
-/* Disk structure */
-typedef struct  {
-       unsigned int size;      /* nr of sectors total */
-       unsigned int sect;      /* sectors per track */
-       unsigned int head;      /* nr of heads */
-       unsigned int track;     /* nr of tracks */
-       unsigned int stretch;   /* !=0 means double track steps */
-       unsigned char   gap;    /* gap1 size */
-       unsigned char   rate;   /* data rate. |= 0x40 for perpendicular */
-       unsigned char   spec1;  /* stepping rate, head unload time */
-       unsigned char   fmt_gap;/* gap2 size */
-       unsigned char hlt;      /* head load time */
-       unsigned char sect_code;/* Sector Size code */
-       const char      * name; /* used only for predefined formats */
-} FD_GEO_STRUCT;
-
-
-/* supported Floppy types (currently only one) */
-const static FD_GEO_STRUCT floppy_type[2] = {
-       { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,16,2,"H1440" },    /*  7 1.44MB 3.5"   */
-       {    0, 0,0, 0,0,0x00,0x00,0x00,0x00, 0,0,NULL    },    /*  end of table    */
-};
-
-static FDC_COMMAND_STRUCT cmd; /* global command struct */
-
-/* If the boot drive number is undefined, we assume it's drive 0             */
-#ifndef CONFIG_SYS_FDC_DRIVE_NUMBER
-#define CONFIG_SYS_FDC_DRIVE_NUMBER 0
-#endif
-
-/* Hardware access */
-#ifndef CONFIG_SYS_ISA_IO_STRIDE
-#define CONFIG_SYS_ISA_IO_STRIDE 1
-#endif
-
-#ifndef CONFIG_SYS_ISA_IO_OFFSET
-#define CONFIG_SYS_ISA_IO_OFFSET 0
-#endif
-
-/* Supporting Functions */
-/* reads a Register of the FDC */
-unsigned char read_fdc_reg(unsigned int addr)
-{
-       volatile unsigned char *val =
-               (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
-                                          (addr * CONFIG_SYS_ISA_IO_STRIDE) +
-                                          CONFIG_SYS_ISA_IO_OFFSET);
-
-       return val [0];
-}
-
-/* writes a Register of the FDC */
-void write_fdc_reg(unsigned int addr, unsigned char val)
-{
-       volatile unsigned char *tmp =
-               (volatile unsigned char *)(CONFIG_SYS_ISA_IO_BASE_ADDRESS +
-                                          (addr * CONFIG_SYS_ISA_IO_STRIDE) +
-                                          CONFIG_SYS_ISA_IO_OFFSET);
-       tmp[0]=val;
-}
-
-/* waits for an interrupt (polling) */
-int wait_for_fdc_int(void)
-{
-       unsigned long timeout;
-       timeout = FDC_TIME_OUT;
-       while((read_fdc_reg(FDC_SRA)&0x80)==0) {
-               timeout--;
-               udelay(10);
-               if(timeout==0) /* timeout occured */
-                       return false;
-       }
-       return true;
-}
-
-/* reads a byte from the FIFO of the FDC and checks direction and RQM bit
-   of the MSR. returns -1 if timeout, or byte if ok */
-int read_fdc_byte(void)
-{
-       unsigned long timeout;
-       timeout = FDC_TIME_OUT;
-       while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
-               /* direction out and ready */
-               udelay(10);
-               timeout--;
-               if(timeout==0) /* timeout occured */
-                       return -1;
-       }
-       return read_fdc_reg(FDC_FIFO);
-}
-
-/* if the direction of the FIFO is wrong, this routine is used to
-   empty the FIFO. Should _not_ be used */
-int fdc_need_more_output(void)
-{
-       unsigned char c;
-       while((read_fdc_reg(FDC_MSR)&0xC0)==0xC0)       {
-                       c=(unsigned char)read_fdc_byte();
-                       printf("Error: more output: %x\n",c);
-       }
-       return true;
-}
-
-
-/* writes a byte to the FIFO of the FDC and checks direction and RQM bit
-   of the MSR */
-int write_fdc_byte(unsigned char val)
-{
-       unsigned long timeout;
-       timeout = FDC_TIME_OUT;
-       while((read_fdc_reg(FDC_MSR)&0xC0)!=0x80) {
-               /* direction in and ready for byte */
-               timeout--;
-               udelay(10);
-               fdc_need_more_output();
-               if(timeout==0) /* timeout occured */
-                       return false;
-       }
-       write_fdc_reg(FDC_FIFO,val);
-       return true;
-}
-
-/* sets up all FDC commands and issues it to the FDC. If
-   the command causes direct results (no Execution Phase)
-   the result is be read as well. */
-
-int fdc_issue_cmd(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
-{
-       int i;
-       unsigned long head,track,sect,timeout;
-       track = pCMD->blnr / (pFG->sect * pFG->head); /* track nr */
-       sect =  pCMD->blnr % (pFG->sect * pFG->head); /* remaining blocks */
-       head = sect / pFG->sect; /* head nr */
-       sect =  sect % pFG->sect; /* remaining blocks */
-       sect++; /* sectors are 1 based */
-       PRINTF("Cmd 0x%02x Track %ld, Head %ld, Sector %ld, Drive %d (blnr %ld)\n",
-               pCMD->cmd[0],track,head,sect,pCMD->drive,pCMD->blnr);
-
-       if(head|=0) { /* max heads = 2 */
-               pCMD->cmd[DRIVE]=pCMD->drive | 0x04; /* head 1 */
-               pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
-       }
-       else {
-               pCMD->cmd[DRIVE]=pCMD->drive; /* head 0 */
-               pCMD->cmd[HEAD]=(unsigned char) head; /* head register */
-       }
-       pCMD->cmd[TRACK]=(unsigned char) track; /* track */
-       switch (pCMD->cmd[COMMAND]) {
-               case FDC_CMD_READ:
-                       pCMD->cmd[SECTOR]=(unsigned char) sect; /* sector */
-                       pCMD->cmd[SECTOR_SIZE]=pFG->sect_code; /* sector size code */
-                       pCMD->cmd[LAST_TRACK]=pFG->sect; /* End of track */
-                       pCMD->cmd[GAP]=pFG->gap; /* gap */
-                       pCMD->cmd[DTL]=0xFF; /* DTL */
-                       pCMD->cmdlen=FDC_CMD_READ_LEN;
-                       pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
-                       pCMD->cmd[COMMAND]|=(FDC_SKIP_MODE<<5); /* set Skip bit */
-                       pCMD->resultlen=0;  /* result only after execution */
-                       break;
-               case FDC_CMD_SEEK:
-                       pCMD->cmdlen=FDC_CMD_SEEK_LEN;
-                       pCMD->resultlen=0;  /* no result */
-                       break;
-               case FDC_CMD_CONFIGURE:
-                       pCMD->cmd[CONFIG0]=0;
-                       pCMD->cmd[CONFIG1]=FDC_CONFIGURE; /* FIFO Threshold, Poll, Enable FIFO */
-                       pCMD->cmd[CONFIG2]=FDC_PRE_TRK; /* Precompensation Track */
-                       pCMD->cmdlen=FDC_CMD_CONFIGURE_LEN;
-                       pCMD->resultlen=0;  /* no result */
-                       break;
-               case FDC_CMD_SPECIFY:
-                       pCMD->cmd[SPEC_HUTSRT]=pFG->spec1;
-                       pCMD->cmd[SPEC_HLT]=(pFG->hlt)<<1; /* head load time */
-                       if(pCMD->dma==0)
-                               pCMD->cmd[SPEC_HLT]|=0x1; /* no dma */
-                       pCMD->cmdlen=FDC_CMD_SPECIFY_LEN;
-                       pCMD->resultlen=0;  /* no result */
-                       break;
-               case FDC_CMD_DUMP_REG:
-                       pCMD->cmdlen=FDC_CMD_DUMP_REG_LEN;
-                       pCMD->resultlen=10;  /* 10 byte result */
-                       break;
-               case FDC_CMD_READ_ID:
-                       pCMD->cmd[COMMAND]|=(FDC_MFM_MODE<<6); /* set MFM bit */
-                       pCMD->cmdlen=FDC_CMD_READ_ID_LEN;
-                       pCMD->resultlen=7;  /* 7 byte result */
-                       break;
-               case FDC_CMD_RECALIBRATE:
-                       pCMD->cmd[DRIVE]&=0x03; /* don't set the head bit */
-                       pCMD->cmdlen=FDC_CMD_RECALIBRATE_LEN;
-                       pCMD->resultlen=0;  /* no result */
-                       break;
-                       break;
-               case FDC_CMD_SENSE_INT:
-                       pCMD->cmdlen=FDC_CMD_SENSE_INT_LEN;
-                       pCMD->resultlen=2;
-                       break;
-       }
-       for(i=0;i<pCMD->cmdlen;i++) {
-               /* PRINTF("write cmd%d = 0x%02X\n",i,pCMD->cmd[i]); */
-               if (write_fdc_byte(pCMD->cmd[i]) == false) {
-                       PRINTF("Error: timeout while issue cmd%d\n",i);
-                       return false;
-               }
-       }
-       timeout=FDC_TIME_OUT;
-       for(i=0;i<pCMD->resultlen;i++) {
-               while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
-                       timeout--;
-                       if(timeout==0) {
-                               PRINTF(" timeout while reading result%d MSR=0x%02X\n",i,read_fdc_reg(FDC_MSR));
-                               return false;
-                       }
-               }
-               pCMD->result[i]=(unsigned char)read_fdc_byte();
-       }
-       return true;
-}
-
-/* selects the drive assigned in the cmd structur and
-   switches on the Motor */
-void select_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
-{
-       unsigned char val;
-
-       val=(1<<(4+pCMD->drive))|pCMD->drive|0xC; /* set reset, dma gate and motor bits */
-       if((read_fdc_reg(FDC_DOR)&val)!=val) {
-               write_fdc_reg(FDC_DOR,val);
-               for(val=0;val<255;val++)
-                       udelay(500); /* wait some time to start motor */
-       }
-}
-
-/* switches off the Motor of the specified drive */
-void stop_fdc_drive(FDC_COMMAND_STRUCT *pCMD)
-{
-       unsigned char val;
-
-       val=(1<<(4+pCMD->drive))|pCMD->drive; /* sets motor bits */
-       write_fdc_reg(FDC_DOR,(read_fdc_reg(FDC_DOR)&~val));
-}
-
-/* issues a recalibrate command, waits for interrupt and
- * issues a sense_interrupt */
-int fdc_recalibrate(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
-{
-       pCMD->cmd[COMMAND]=FDC_CMD_RECALIBRATE;
-       if (fdc_issue_cmd(pCMD, pFG) == false)
-               return false;
-       while (wait_for_fdc_int() != true);
-
-       pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
-       return(fdc_issue_cmd(pCMD,pFG));
-}
-
-/* issues a recalibrate command, waits for interrupt and
- * issues a sense_interrupt */
-int fdc_seek(FDC_COMMAND_STRUCT *pCMD,FD_GEO_STRUCT *pFG)
-{
-       pCMD->cmd[COMMAND]=FDC_CMD_SEEK;
-       if (fdc_issue_cmd(pCMD, pFG) == false)
-               return false;
-       while (wait_for_fdc_int() != true);
-
-       pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
-       return(fdc_issue_cmd(pCMD,pFG));
-}
-
-/* terminates current command, by not servicing the FIFO
- * waits for interrupt and fills in the result bytes */
-int fdc_terminate(FDC_COMMAND_STRUCT *pCMD)
-{
-       int i;
-       for(i=0;i<100;i++)
-               udelay(500); /* wait 500usec for fifo overrun */
-       while((read_fdc_reg(FDC_SRA)&0x80)==0x00); /* wait as long as no int has occured */
-       for(i=0;i<7;i++) {
-               pCMD->result[i]=(unsigned char)read_fdc_byte();
-       }
-       return true;
-}
-
-/* reads data from FDC, seek commands are issued automatic */
-int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
-{
-  /* first seek to start address */
-       unsigned long len,readblk,i,timeout,ii,offset;
-       unsigned char c,retriesrw,retriescal;
-       unsigned char *bufferw; /* working buffer */
-       int sect_size;
-       int flags;
-
-       flags=disable_interrupts(); /* switch off all Interrupts */
-       select_fdc_drive(pCMD); /* switch on drive */
-       sect_size=0x080<<pFG->sect_code;
-       retriesrw=0;
-       retriescal=0;
-       offset=0;
-       if (fdc_seek(pCMD, pFG) == false) {
-               stop_fdc_drive(pCMD);
-               if (flags)
-                       enable_interrupts();
-               return false;
-       }
-       if((pCMD->result[STATUS_0]&0x20)!=0x20) {
-               printf("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
-               stop_fdc_drive(pCMD);
-               if (flags)
-                       enable_interrupts();
-               return false;
-       }
-       /* now determine the next seek point */
-       /*      lastblk=pCMD->blnr + blocks; */
-       /*      readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */
-       readblk=pFG->sect-(pCMD->blnr%pFG->sect);
-       PRINTF("1st nr of block possible read %ld start %ld\n",readblk,pCMD->blnr);
-       if(readblk>blocks) /* is end within 1st track */
-               readblk=blocks; /* yes, correct it */
-       PRINTF("we read %ld blocks start %ld\n",readblk,pCMD->blnr);
-       bufferw = &buffer[0]; /* setup working buffer */
-       do {
-retryrw:
-               len=sect_size * readblk;
-               pCMD->cmd[COMMAND]=FDC_CMD_READ;
-               if (fdc_issue_cmd(pCMD, pFG) == false) {
-                       stop_fdc_drive(pCMD);
-                       if (flags)
-                               enable_interrupts();
-                       return false;
-               }
-               for (i=0;i<len;i++) {
-                       timeout=FDC_TIME_OUT;
-                       do {
-                               c=read_fdc_reg(FDC_MSR);
-                               if((c&0xC0)==0xC0) {
-                                       bufferw[i]=read_fdc_reg(FDC_FIFO);
-                                       break;
-                               }
-                               if((c&0xC0)==0x80) { /* output */
-                                       PRINTF("Transfer error transfered: at %ld, MSR=%02X\n",i,c);
-                                       if(i>6) {
-                                               for(ii=0;ii<7;ii++) {
-                                                       pCMD->result[ii]=bufferw[(i-7+ii)];
-                                               } /* for */
-                                       }
-                                       if(retriesrw++>FDC_RW_RETRIES) {
-                                               if (retriescal++>FDC_CAL_RETRIES) {
-                                                       stop_fdc_drive(pCMD);
-                                                       if (flags)
-                                                               enable_interrupts();
-                                                       return false;
-                                               }
-                                               else {
-                                                       PRINTF(" trying to recalibrate Try %d\n",retriescal);
-                                                       if (fdc_recalibrate(pCMD, pFG) == false) {
-                                                               stop_fdc_drive(pCMD);
-                                                               if (flags)
-                                                                       enable_interrupts();
-                                                               return false;
-                                                       }
-                                                       retriesrw=0;
-                                                       goto retrycal;
-                                               } /* else >FDC_CAL_RETRIES */
-                                       }
-                                       else {
-                                               PRINTF("Read retry %d\n",retriesrw);
-                                               goto retryrw;
-                                       } /* else >FDC_RW_RETRIES */
-                               }/* if output */
-                               timeout--;
-                       } while (true);
-               } /* for len */
-               /* the last sector of a track or all data has been read,
-                * we need to get the results */
-               fdc_terminate(pCMD);
-               offset+=(sect_size*readblk); /* set up buffer pointer */
-               bufferw = &buffer[offset];
-               pCMD->blnr+=readblk; /* update current block nr */
-               blocks-=readblk; /* update blocks */
-               if(blocks==0)
-                       break; /* we are finish */
-               /* setup new read blocks */
-               /*      readblk=pFG->head*pFG->sect; */
-               readblk=pFG->sect;
-               if(readblk>blocks)
-                       readblk=blocks;
-retrycal:
-               /* a seek is necessary */
-               if (fdc_seek(pCMD, pFG) == false) {
-                       stop_fdc_drive(pCMD);
-                       if (flags)
-                               enable_interrupts();
-                       return false;
-               }
-               if((pCMD->result[STATUS_0]&0x20)!=0x20) {
-                       PRINTF("Seek error Status: %02X\n",pCMD->result[STATUS_0]);
-                       stop_fdc_drive(pCMD);
-                       return false;
-               }
-       } while (true); /* start over */
-       stop_fdc_drive(pCMD); /* switch off drive */
-       if (flags)
-               enable_interrupts();
-       return true;
-}
-
-/* Scan all drives and check if drive is present and disk is inserted */
-int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
-{
-       int i,drives,state;
-  /* OK procedure of data book is satisfied.
-        * trying to get some information over the drives */
-       state=0; /* no drives, no disks */
-       for(drives=0;drives<4;drives++) {
-               pCMD->drive=drives;
-               select_fdc_drive(pCMD);
-               pCMD->blnr=0; /* set to the 1st block */
-               if (fdc_recalibrate(pCMD, pFG) == false)
-                       continue;
-               if((pCMD->result[STATUS_0]&0x10)==0x10)
-                       continue;
-               /* ok drive connected check for disk */
-               state|=(1<<drives);
-               pCMD->blnr=pFG->size; /* set to the last block */
-               if (fdc_seek(pCMD, pFG) == false)
-                       continue;
-               pCMD->blnr=0; /* set to the 1st block */
-               if (fdc_recalibrate(pCMD, pFG) == false)
-                       continue;
-               pCMD->cmd[COMMAND]=FDC_CMD_READ_ID;
-               if (fdc_issue_cmd(pCMD, pFG) == false)
-                       continue;
-               state|=(0x10<<drives);
-       }
-       stop_fdc_drive(pCMD);
-       for(i=0;i<4;i++) {
-               PRINTF("Floppy Drive %d %sconnected %sDisk inserted %s\n",i,
-                       ((state&(1<<i))==(1<<i)) ? "":"not ",
-                       ((state&(0x10<<i))==(0x10<<i)) ? "":"no ",
-                       ((state&(0x10<<i))==(0x10<<i)) ? pFG->name : "");
-       }
-       pCMD->flags=state;
-       return true;
-}
-
-
-/**************************************************************************
-* int fdc_setup
-* setup the fdc according the datasheet
-* assuming in PS2 Mode
-*/
-int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG)
-{
-       int i;
-
-#ifdef CONFIG_SYS_FDC_HW_INIT
-       fdc_hw_init ();
-#endif
-       /* first, we reset the FDC via the DOR */
-       write_fdc_reg(FDC_DOR,0x00);
-       for(i=0; i<255; i++) /* then we wait some time */
-               udelay(500);
-       /* then, we clear the reset in the DOR */
-       pCMD->drive=drive;
-       select_fdc_drive(pCMD);
-       /* initialize the CCR */
-       write_fdc_reg(FDC_CCR,pFG->rate);
-       /* then initialize the DSR */
-       write_fdc_reg(FDC_DSR,pFG->rate);
-       if (wait_for_fdc_int() == false) {
-                       PRINTF("Time Out after writing CCR\n");
-                       return false;
-       }
-       /* now issue sense Interrupt and status command
-        * assuming only one drive present (drive 0) */
-       pCMD->dma=0; /* we don't use any dma at all */
-       for(i=0;i<4;i++) {
-               /* issue sense interrupt for all 4 possible drives */
-               pCMD->cmd[COMMAND]=FDC_CMD_SENSE_INT;
-               if (fdc_issue_cmd(pCMD, pFG) == false) {
-                       PRINTF("Sense Interrupt for drive %d failed\n",i);
-               }
-       }
-       /* issue the configure command */
-       pCMD->drive=drive;
-       select_fdc_drive(pCMD);
-       pCMD->cmd[COMMAND]=FDC_CMD_CONFIGURE;
-       if (fdc_issue_cmd(pCMD, pFG) == false) {
-               PRINTF(" configure timeout\n");
-               stop_fdc_drive(pCMD);
-               return false;
-       }
-       /* issue specify command */
-       pCMD->cmd[COMMAND]=FDC_CMD_SPECIFY;
-       if (fdc_issue_cmd(pCMD, pFG) == false) {
-               PRINTF(" specify timeout\n");
-               stop_fdc_drive(pCMD);
-               return false;
-
-       }
-       /* then, we clear the reset in the DOR */
-       /* fdc_check_drive(pCMD,pFG);   */
-       /*      write_fdc_reg(FDC_DOR,0x04); */
-
-       return true;
-}
-
-/****************************************************************************
- * main routine do_fdcboot
- */
-int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
-       FDC_COMMAND_STRUCT *pCMD = &cmd;
-       unsigned long addr,imsize;
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       image_header_t *hdr;  /* used for fdc boot */
-#endif
-       unsigned char boot_drive;
-       int i,nrofblk;
-#if defined(CONFIG_FIT)
-       const void *fit_hdr = NULL;
-#endif
-
-       switch (argc) {
-       case 1:
-               addr = CONFIG_SYS_LOAD_ADDR;
-               boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
-               break;
-       case 2:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
-               break;
-       case 3:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               boot_drive=simple_strtoul(argv[2], NULL, 10);
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-       /* setup FDC and scan for drives  */
-       if (fdc_setup(boot_drive, pCMD, pFG) == false) {
-               printf("\n** Error in setup FDC **\n");
-               return 1;
-       }
-       if (fdc_check_drive(pCMD, pFG) == false) {
-               printf("\n** Error in check_drives **\n");
-               return 1;
-       }
-       if((pCMD->flags&(1<<boot_drive))==0) {
-               /* drive not available */
-               printf("\n** Drive %d not availabe **\n",boot_drive);
-               return 1;
-       }
-       if((pCMD->flags&(0x10<<boot_drive))==0) {
-               /* no disk inserted */
-               printf("\n** No disk inserted in drive %d **\n",boot_drive);
-               return 1;
-       }
-       /* ok, we have a valid source */
-       pCMD->drive=boot_drive;
-       /* read first block */
-       pCMD->blnr=0;
-       if (fdc_read_data((unsigned char *)addr, 1, pCMD, pFG) == false) {
-               printf("\nRead error:");
-               for(i=0;i<7;i++)
-                       printf("result%d: 0x%02X\n",i,pCMD->result[i]);
-               return 1;
-       }
-
-       switch (genimg_get_format ((void *)addr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-               hdr = (image_header_t *)addr;
-               image_print_contents (hdr);
-
-               imsize = image_get_image_size (hdr);
-               break;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               fit_hdr = (const void *)addr;
-               puts ("Fit image detected...\n");
-
-               imsize = fit_get_size (fit_hdr);
-               break;
-#endif
-       default:
-               puts ("** Unknown image type\n");
-               return 1;
-       }
-
-       nrofblk=imsize/512;
-       if((imsize%512)>0)
-               nrofblk++;
-       printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr);
-       pCMD->blnr=0;
-       if (fdc_read_data((unsigned char *)addr, nrofblk, pCMD, pFG) == false) {
-               /* read image block */
-               printf("\nRead error:");
-               for(i=0;i<7;i++)
-                       printf("result%d: 0x%02X\n",i,pCMD->result[i]);
-               return 1;
-       }
-       printf("OK %ld Bytes loaded.\n",imsize);
-
-       flush_cache (addr, imsize);
-
-#if defined(CONFIG_FIT)
-       /* This cannot be done earlier, we need complete FIT image in RAM first */
-       if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
-               if (!fit_check_format (fit_hdr)) {
-                       puts ("** Bad FIT image format\n");
-                       return 1;
-               }
-               fit_print_contents (fit_hdr);
-       }
-#endif
-
-       /* Loading ok, update default load address */
-       load_addr = addr;
-
-       return bootm_maybe_autostart(cmdtp, argv[0]);
-}
-
-U_BOOT_CMD(
-       fdcboot,        3,      1,      do_fdcboot,
-       "boot from floppy device",
-       "loadAddr drive"
-);
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
deleted file mode 100644 (file)
index 4c18962..0000000
+++ /dev/null
@@ -1,1065 +0,0 @@
-/*
- * (C) Copyright 2007
- * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
- * Based on code written by:
- *   Pantelis Antoniou <pantelis.antoniou@gmail.com> and
- *   Matthew McClintock <msm@freescale.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <linux/ctype.h>
-#include <linux/types.h>
-#include <asm/global_data.h>
-#include <libfdt.h>
-#include <fdt_support.h>
-#include <mapmem.h>
-#include <asm/io.h>
-
-#define MAX_LEVEL      32              /* how deeply nested we will go */
-#define SCRATCHPAD     1024            /* bytes of scratchpad memory */
-#ifndef CONFIG_CMD_FDT_MAX_DUMP
-#define CONFIG_CMD_FDT_MAX_DUMP 64
-#endif
-
-/*
- * Global data (for the gd->bd)
- */
-DECLARE_GLOBAL_DATA_PTR;
-
-static int fdt_valid(struct fdt_header **blobp);
-static int fdt_parse_prop(char *const*newval, int count, char *data, int *len);
-static int fdt_print(const char *pathp, char *prop, int depth);
-static int is_printable_string(const void *data, int len);
-
-/*
- * The working_fdt points to our working flattened device tree.
- */
-struct fdt_header *working_fdt;
-
-void set_working_fdt_addr(ulong addr)
-{
-       void *buf;
-
-       buf = map_sysmem(addr, 0);
-       working_fdt = buf;
-       setenv_hex("fdtaddr", addr);
-}
-
-/*
- * Get a value from the fdt and format it to be set in the environment
- */
-static int fdt_value_setenv(const void *nodep, int len, const char *var)
-{
-       if (is_printable_string(nodep, len))
-               setenv(var, (void *)nodep);
-       else if (len == 4) {
-               char buf[11];
-
-               sprintf(buf, "0x%08X", *(uint32_t *)nodep);
-               setenv(var, buf);
-       } else if (len%4 == 0 && len <= 20) {
-               /* Needed to print things like sha1 hashes. */
-               char buf[41];
-               int i;
-
-               for (i = 0; i < len; i += sizeof(unsigned int))
-                       sprintf(buf + (i * 2), "%08x",
-                               *(unsigned int *)(nodep + i));
-               setenv(var, buf);
-       } else {
-               printf("error: unprintable value\n");
-               return 1;
-       }
-       return 0;
-}
-
-/*
- * Flattened Device Tree command, see the help for parameter definitions.
- */
-static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /*
-        * Set the address of the fdt
-        */
-       if (argv[1][0] == 'a') {
-               unsigned long addr;
-               int control = 0;
-               struct fdt_header *blob;
-               /*
-                * Set the address [and length] of the fdt.
-                */
-               argc -= 2;
-               argv += 2;
-/* Temporary #ifdef - some archs don't have fdt_blob yet */
-#ifdef CONFIG_OF_CONTROL
-               if (argc && !strcmp(*argv, "-c")) {
-                       control = 1;
-                       argc--;
-                       argv++;
-               }
-#endif
-               if (argc == 0) {
-                       if (control)
-                               blob = (struct fdt_header *)gd->fdt_blob;
-                       else
-                               blob = working_fdt;
-                       if (!blob || !fdt_valid(&blob))
-                               return 1;
-                       printf("The address of the fdt is %#08lx\n",
-                              control ? (ulong)map_to_sysmem(blob) :
-                                       getenv_hex("fdtaddr", 0));
-                       return 0;
-               }
-
-               addr = simple_strtoul(argv[0], NULL, 16);
-               blob = map_sysmem(addr, 0);
-               if (!fdt_valid(&blob))
-                       return 1;
-               if (control)
-                       gd->fdt_blob = blob;
-               else
-                       set_working_fdt_addr(addr);
-
-               if (argc >= 2) {
-                       int  len;
-                       int  err;
-                       /*
-                        * Optional new length
-                        */
-                       len = simple_strtoul(argv[1], NULL, 16);
-                       if (len < fdt_totalsize(blob)) {
-                               printf ("New length %d < existing length %d, "
-                                       "ignoring.\n",
-                                       len, fdt_totalsize(blob));
-                       } else {
-                               /*
-                                * Open in place with a new length.
-                                */
-                               err = fdt_open_into(blob, blob, len);
-                               if (err != 0) {
-                                       printf ("libfdt fdt_open_into(): %s\n",
-                                               fdt_strerror(err));
-                               }
-                       }
-               }
-
-               return CMD_RET_SUCCESS;
-       }
-
-       if (!working_fdt) {
-               puts(
-                       "No FDT memory address configured. Please configure\n"
-                       "the FDT address via \"fdt addr <address>\" command.\n"
-                       "Aborting!\n");
-               return CMD_RET_FAILURE;
-       }
-
-       /*
-        * Move the working_fdt
-        */
-       if (strncmp(argv[1], "mo", 2) == 0) {
-               struct fdt_header *newaddr;
-               int  len;
-               int  err;
-
-               if (argc < 4)
-                       return CMD_RET_USAGE;
-
-               /*
-                * Set the address and length of the fdt.
-                */
-               working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16);
-               if (!fdt_valid(&working_fdt))
-                       return 1;
-
-               newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16);
-
-               /*
-                * If the user specifies a length, use that.  Otherwise use the
-                * current length.
-                */
-               if (argc <= 4) {
-                       len = fdt_totalsize(working_fdt);
-               } else {
-                       len = simple_strtoul(argv[4], NULL, 16);
-                       if (len < fdt_totalsize(working_fdt)) {
-                               printf ("New length 0x%X < existing length "
-                                       "0x%X, aborting.\n",
-                                       len, fdt_totalsize(working_fdt));
-                               return 1;
-                       }
-               }
-
-               /*
-                * Copy to the new location.
-                */
-               err = fdt_open_into(working_fdt, newaddr, len);
-               if (err != 0) {
-                       printf ("libfdt fdt_open_into(): %s\n",
-                               fdt_strerror(err));
-                       return 1;
-               }
-               working_fdt = newaddr;
-
-       /*
-        * Make a new node
-        */
-       } else if (strncmp(argv[1], "mk", 2) == 0) {
-               char *pathp;            /* path */
-               char *nodep;            /* new node to add */
-               int  nodeoffset;        /* node offset from libfdt */
-               int  err;
-
-               /*
-                * Parameters: Node path, new node to be appended to the path.
-                */
-               if (argc < 4)
-                       return CMD_RET_USAGE;
-
-               pathp = argv[2];
-               nodep = argv[3];
-
-               nodeoffset = fdt_path_offset (working_fdt, pathp);
-               if (nodeoffset < 0) {
-                       /*
-                        * Not found or something else bad happened.
-                        */
-                       printf ("libfdt fdt_path_offset() returned %s\n",
-                               fdt_strerror(nodeoffset));
-                       return 1;
-               }
-               err = fdt_add_subnode(working_fdt, nodeoffset, nodep);
-               if (err < 0) {
-                       printf ("libfdt fdt_add_subnode(): %s\n",
-                               fdt_strerror(err));
-                       return 1;
-               }
-
-       /*
-        * Set the value of a property in the working_fdt.
-        */
-       } else if (argv[1][0] == 's') {
-               char *pathp;            /* path */
-               char *prop;             /* property */
-               int  nodeoffset;        /* node offset from libfdt */
-               static char data[SCRATCHPAD];   /* storage for the property */
-               int  len;               /* new length of the property */
-               int  ret;               /* return value */
-
-               /*
-                * Parameters: Node path, property, optional value.
-                */
-               if (argc < 4)
-                       return CMD_RET_USAGE;
-
-               pathp  = argv[2];
-               prop   = argv[3];
-               if (argc == 4) {
-                       len = 0;
-               } else {
-                       ret = fdt_parse_prop(&argv[4], argc - 4, data, &len);
-                       if (ret != 0)
-                               return ret;
-               }
-
-               nodeoffset = fdt_path_offset (working_fdt, pathp);
-               if (nodeoffset < 0) {
-                       /*
-                        * Not found or something else bad happened.
-                        */
-                       printf ("libfdt fdt_path_offset() returned %s\n",
-                               fdt_strerror(nodeoffset));
-                       return 1;
-               }
-
-               ret = fdt_setprop(working_fdt, nodeoffset, prop, data, len);
-               if (ret < 0) {
-                       printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret));
-                       return 1;
-               }
-
-       /********************************************************************
-        * Get the value of a property in the working_fdt.
-        ********************************************************************/
-       } else if (argv[1][0] == 'g') {
-               char *subcmd;           /* sub-command */
-               char *pathp;            /* path */
-               char *prop;             /* property */
-               char *var;              /* variable to store result */
-               int  nodeoffset;        /* node offset from libfdt */
-               const void *nodep;      /* property node pointer */
-               int  len = 0;           /* new length of the property */
-
-               /*
-                * Parameters: Node path, property, optional value.
-                */
-               if (argc < 5)
-                       return CMD_RET_USAGE;
-
-               subcmd = argv[2];
-
-               if (argc < 6 && subcmd[0] != 's')
-                       return CMD_RET_USAGE;
-
-               var    = argv[3];
-               pathp  = argv[4];
-               prop   = argv[5];
-
-               nodeoffset = fdt_path_offset(working_fdt, pathp);
-               if (nodeoffset < 0) {
-                       /*
-                        * Not found or something else bad happened.
-                        */
-                       printf("libfdt fdt_path_offset() returned %s\n",
-                               fdt_strerror(nodeoffset));
-                       return 1;
-               }
-
-               if (subcmd[0] == 'n' || (subcmd[0] == 's' && argc == 5)) {
-                       int reqIndex = -1;
-                       int startDepth = fdt_node_depth(
-                               working_fdt, nodeoffset);
-                       int curDepth = startDepth;
-                       int curIndex = -1;
-                       int nextNodeOffset = fdt_next_node(
-                               working_fdt, nodeoffset, &curDepth);
-
-                       if (subcmd[0] == 'n')
-                               reqIndex = simple_strtoul(argv[5], NULL, 16);
-
-                       while (curDepth > startDepth) {
-                               if (curDepth == startDepth + 1)
-                                       curIndex++;
-                               if (subcmd[0] == 'n' && curIndex == reqIndex) {
-                                       const char *nodeName = fdt_get_name(
-                                           working_fdt, nextNodeOffset, NULL);
-
-                                       setenv(var, (char *)nodeName);
-                                       return 0;
-                               }
-                               nextNodeOffset = fdt_next_node(
-                                       working_fdt, nextNodeOffset, &curDepth);
-                               if (nextNodeOffset < 0)
-                                       break;
-                       }
-                       if (subcmd[0] == 's') {
-                               /* get the num nodes at this level */
-                               setenv_ulong(var, curIndex + 1);
-                       } else {
-                               /* node index not found */
-                               printf("libfdt node not found\n");
-                               return 1;
-                       }
-               } else {
-                       nodep = fdt_getprop(
-                               working_fdt, nodeoffset, prop, &len);
-                       if (len == 0) {
-                               /* no property value */
-                               setenv(var, "");
-                               return 0;
-                       } else if (len > 0) {
-                               if (subcmd[0] == 'v') {
-                                       int ret;
-
-                                       ret = fdt_value_setenv(nodep, len, var);
-                                       if (ret != 0)
-                                               return ret;
-                               } else if (subcmd[0] == 'a') {
-                                       /* Get address */
-                                       char buf[11];
-
-                                       sprintf(buf, "0x%p", nodep);
-                                       setenv(var, buf);
-                               } else if (subcmd[0] == 's') {
-                                       /* Get size */
-                                       char buf[11];
-
-                                       sprintf(buf, "0x%08X", len);
-                                       setenv(var, buf);
-                               } else
-                                       return CMD_RET_USAGE;
-                               return 0;
-                       } else {
-                               printf("libfdt fdt_getprop(): %s\n",
-                                       fdt_strerror(len));
-                               return 1;
-                       }
-               }
-
-       /*
-        * Print (recursive) / List (single level)
-        */
-       } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) {
-               int depth = MAX_LEVEL;  /* how deep to print */
-               char *pathp;            /* path */
-               char *prop;             /* property */
-               int  ret;               /* return value */
-               static char root[2] = "/";
-
-               /*
-                * list is an alias for print, but limited to 1 level
-                */
-               if (argv[1][0] == 'l') {
-                       depth = 1;
-               }
-
-               /*
-                * Get the starting path.  The root node is an oddball,
-                * the offset is zero and has no name.
-                */
-               if (argc == 2)
-                       pathp = root;
-               else
-                       pathp = argv[2];
-               if (argc > 3)
-                       prop = argv[3];
-               else
-                       prop = NULL;
-
-               ret = fdt_print(pathp, prop, depth);
-               if (ret != 0)
-                       return ret;
-
-       /*
-        * Remove a property/node
-        */
-       } else if (strncmp(argv[1], "rm", 2) == 0) {
-               int  nodeoffset;        /* node offset from libfdt */
-               int  err;
-
-               /*
-                * Get the path.  The root node is an oddball, the offset
-                * is zero and has no name.
-                */
-               nodeoffset = fdt_path_offset (working_fdt, argv[2]);
-               if (nodeoffset < 0) {
-                       /*
-                        * Not found or something else bad happened.
-                        */
-                       printf ("libfdt fdt_path_offset() returned %s\n",
-                               fdt_strerror(nodeoffset));
-                       return 1;
-               }
-               /*
-                * Do the delete.  A fourth parameter means delete a property,
-                * otherwise delete the node.
-                */
-               if (argc > 3) {
-                       err = fdt_delprop(working_fdt, nodeoffset, argv[3]);
-                       if (err < 0) {
-                               printf("libfdt fdt_delprop():  %s\n",
-                                       fdt_strerror(err));
-                               return err;
-                       }
-               } else {
-                       err = fdt_del_node(working_fdt, nodeoffset);
-                       if (err < 0) {
-                               printf("libfdt fdt_del_node():  %s\n",
-                                       fdt_strerror(err));
-                               return err;
-                       }
-               }
-
-       /*
-        * Display header info
-        */
-       } else if (argv[1][0] == 'h') {
-               u32 version = fdt_version(working_fdt);
-               printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt));
-               printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt),
-                      fdt_totalsize(working_fdt));
-               printf("off_dt_struct:\t\t0x%x\n",
-                      fdt_off_dt_struct(working_fdt));
-               printf("off_dt_strings:\t\t0x%x\n",
-                      fdt_off_dt_strings(working_fdt));
-               printf("off_mem_rsvmap:\t\t0x%x\n",
-                      fdt_off_mem_rsvmap(working_fdt));
-               printf("version:\t\t%d\n", version);
-               printf("last_comp_version:\t%d\n",
-                      fdt_last_comp_version(working_fdt));
-               if (version >= 2)
-                       printf("boot_cpuid_phys:\t0x%x\n",
-                               fdt_boot_cpuid_phys(working_fdt));
-               if (version >= 3)
-                       printf("size_dt_strings:\t0x%x\n",
-                               fdt_size_dt_strings(working_fdt));
-               if (version >= 17)
-                       printf("size_dt_struct:\t\t0x%x\n",
-                               fdt_size_dt_struct(working_fdt));
-               printf("number mem_rsv:\t\t0x%x\n",
-                      fdt_num_mem_rsv(working_fdt));
-               printf("\n");
-
-       /*
-        * Set boot cpu id
-        */
-       } else if (strncmp(argv[1], "boo", 3) == 0) {
-               unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
-               fdt_set_boot_cpuid_phys(working_fdt, tmp);
-
-       /*
-        * memory command
-        */
-       } else if (strncmp(argv[1], "me", 2) == 0) {
-               uint64_t addr, size;
-               int err;
-               addr = simple_strtoull(argv[2], NULL, 16);
-               size = simple_strtoull(argv[3], NULL, 16);
-               err = fdt_fixup_memory(working_fdt, addr, size);
-               if (err < 0)
-                       return err;
-
-       /*
-        * mem reserve commands
-        */
-       } else if (strncmp(argv[1], "rs", 2) == 0) {
-               if (argv[2][0] == 'p') {
-                       uint64_t addr, size;
-                       int total = fdt_num_mem_rsv(working_fdt);
-                       int j, err;
-                       printf("index\t\t   start\t\t    size\n");
-                       printf("-------------------------------"
-                               "-----------------\n");
-                       for (j = 0; j < total; j++) {
-                               err = fdt_get_mem_rsv(working_fdt, j, &addr, &size);
-                               if (err < 0) {
-                                       printf("libfdt fdt_get_mem_rsv():  %s\n",
-                                                       fdt_strerror(err));
-                                       return err;
-                               }
-                               printf("    %x\t%08x%08x\t%08x%08x\n", j,
-                                       (u32)(addr >> 32),
-                                       (u32)(addr & 0xffffffff),
-                                       (u32)(size >> 32),
-                                       (u32)(size & 0xffffffff));
-                       }
-               } else if (argv[2][0] == 'a') {
-                       uint64_t addr, size;
-                       int err;
-                       addr = simple_strtoull(argv[3], NULL, 16);
-                       size = simple_strtoull(argv[4], NULL, 16);
-                       err = fdt_add_mem_rsv(working_fdt, addr, size);
-
-                       if (err < 0) {
-                               printf("libfdt fdt_add_mem_rsv():  %s\n",
-                                       fdt_strerror(err));
-                               return err;
-                       }
-               } else if (argv[2][0] == 'd') {
-                       unsigned long idx = simple_strtoul(argv[3], NULL, 16);
-                       int err = fdt_del_mem_rsv(working_fdt, idx);
-
-                       if (err < 0) {
-                               printf("libfdt fdt_del_mem_rsv():  %s\n",
-                                       fdt_strerror(err));
-                               return err;
-                       }
-               } else {
-                       /* Unrecognized command */
-                       return CMD_RET_USAGE;
-               }
-       }
-#ifdef CONFIG_OF_BOARD_SETUP
-       /* Call the board-specific fixup routine */
-       else if (strncmp(argv[1], "boa", 3) == 0) {
-               int err = ft_board_setup(working_fdt, gd->bd);
-
-               if (err) {
-                       printf("Failed to update board information in FDT: %s\n",
-                              fdt_strerror(err));
-                       return CMD_RET_FAILURE;
-               }
-       }
-#endif
-#ifdef CONFIG_OF_SYSTEM_SETUP
-       /* Call the board-specific fixup routine */
-       else if (strncmp(argv[1], "sys", 3) == 0) {
-               int err = ft_system_setup(working_fdt, gd->bd);
-
-               if (err) {
-                       printf("Failed to add system information to FDT: %s\n",
-                              fdt_strerror(err));
-                       return CMD_RET_FAILURE;
-               }
-       }
-#endif
-       /* Create a chosen node */
-       else if (strncmp(argv[1], "cho", 3) == 0) {
-               unsigned long initrd_start = 0, initrd_end = 0;
-
-               if ((argc != 2) && (argc != 4))
-                       return CMD_RET_USAGE;
-
-               if (argc == 4) {
-                       initrd_start = simple_strtoul(argv[2], NULL, 16);
-                       initrd_end = simple_strtoul(argv[3], NULL, 16);
-               }
-
-               fdt_chosen(working_fdt);
-               fdt_initrd(working_fdt, initrd_start, initrd_end);
-
-#if defined(CONFIG_FIT_SIGNATURE)
-       } else if (strncmp(argv[1], "che", 3) == 0) {
-               int cfg_noffset;
-               int ret;
-               unsigned long addr;
-               struct fdt_header *blob;
-
-               if (!working_fdt)
-                       return CMD_RET_FAILURE;
-
-               if (argc > 2) {
-                       addr = simple_strtoul(argv[2], NULL, 16);
-                       blob = map_sysmem(addr, 0);
-               } else {
-                       blob = (struct fdt_header *)gd->fdt_blob;
-               }
-               if (!fdt_valid(&blob))
-                       return 1;
-
-               gd->fdt_blob = blob;
-               cfg_noffset = fit_conf_get_node(working_fdt, NULL);
-               if (!cfg_noffset) {
-                       printf("Could not find configuration node: %s\n",
-                              fdt_strerror(cfg_noffset));
-                       return CMD_RET_FAILURE;
-               }
-
-               ret = fit_config_verify(working_fdt, cfg_noffset);
-               if (ret == 0)
-                       return CMD_RET_SUCCESS;
-               else
-                       return CMD_RET_FAILURE;
-#endif
-
-       }
-       /* resize the fdt */
-       else if (strncmp(argv[1], "re", 2) == 0) {
-               fdt_shrink_to_minimum(working_fdt);
-       }
-       else {
-               /* Unrecognized command */
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-/****************************************************************************/
-
-/**
- * fdt_valid() - Check if an FDT is valid. If not, change it to NULL
- *
- * @blobp: Pointer to FDT pointer
- * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL)
- */
-static int fdt_valid(struct fdt_header **blobp)
-{
-       const void *blob = *blobp;
-       int err;
-
-       if (blob == NULL) {
-               printf ("The address of the fdt is invalid (NULL).\n");
-               return 0;
-       }
-
-       err = fdt_check_header(blob);
-       if (err == 0)
-               return 1;       /* valid */
-
-       if (err < 0) {
-               printf("libfdt fdt_check_header(): %s", fdt_strerror(err));
-               /*
-                * Be more informative on bad version.
-                */
-               if (err == -FDT_ERR_BADVERSION) {
-                       if (fdt_version(blob) <
-                           FDT_FIRST_SUPPORTED_VERSION) {
-                               printf (" - too old, fdt %d < %d",
-                                       fdt_version(blob),
-                                       FDT_FIRST_SUPPORTED_VERSION);
-                       }
-                       if (fdt_last_comp_version(blob) >
-                           FDT_LAST_SUPPORTED_VERSION) {
-                               printf (" - too new, fdt %d > %d",
-                                       fdt_version(blob),
-                                       FDT_LAST_SUPPORTED_VERSION);
-                       }
-               }
-               printf("\n");
-               *blobp = NULL;
-               return 0;
-       }
-       return 1;
-}
-
-/****************************************************************************/
-
-/*
- * Parse the user's input, partially heuristic.  Valid formats:
- * <0x00112233 4 05>   - an array of cells.  Numbers follow standard
- *                     C conventions.
- * [00 11 22 .. nn] - byte stream
- * "string"    - If the the value doesn't start with "<" or "[", it is
- *                     treated as a string.  Note that the quotes are
- *                     stripped by the parser before we get the string.
- * newval: An array of strings containing the new property as specified
- *     on the command line
- * count: The number of strings in the array
- * data: A bytestream to be placed in the property
- * len: The length of the resulting bytestream
- */
-static int fdt_parse_prop(char * const *newval, int count, char *data, int *len)
-{
-       char *cp;               /* temporary char pointer */
-       char *newp;             /* temporary newval char pointer */
-       unsigned long tmp;      /* holds converted values */
-       int stridx = 0;
-
-       *len = 0;
-       newp = newval[0];
-
-       /* An array of cells */
-       if (*newp == '<') {
-               newp++;
-               while ((*newp != '>') && (stridx < count)) {
-                       /*
-                        * Keep searching until we find that last ">"
-                        * That way users don't have to escape the spaces
-                        */
-                       if (*newp == '\0') {
-                               newp = newval[++stridx];
-                               continue;
-                       }
-
-                       cp = newp;
-                       tmp = simple_strtoul(cp, &newp, 0);
-                       *(__be32 *)data = __cpu_to_be32(tmp);
-                       data  += 4;
-                       *len += 4;
-
-                       /* If the ptr didn't advance, something went wrong */
-                       if ((newp - cp) <= 0) {
-                               printf("Sorry, I could not convert \"%s\"\n",
-                                       cp);
-                               return 1;
-                       }
-
-                       while (*newp == ' ')
-                               newp++;
-               }
-
-               if (*newp != '>') {
-                       printf("Unexpected character '%c'\n", *newp);
-                       return 1;
-               }
-       } else if (*newp == '[') {
-               /*
-                * Byte stream.  Convert the values.
-                */
-               newp++;
-               while ((stridx < count) && (*newp != ']')) {
-                       while (*newp == ' ')
-                               newp++;
-                       if (*newp == '\0') {
-                               newp = newval[++stridx];
-                               continue;
-                       }
-                       if (!isxdigit(*newp))
-                               break;
-                       tmp = simple_strtoul(newp, &newp, 16);
-                       *data++ = tmp & 0xFF;
-                       *len    = *len + 1;
-               }
-               if (*newp != ']') {
-                       printf("Unexpected character '%c'\n", *newp);
-                       return 1;
-               }
-       } else {
-               /*
-                * Assume it is one or more strings.  Copy it into our
-                * data area for convenience (including the
-                * terminating '\0's).
-                */
-               while (stridx < count) {
-                       size_t length = strlen(newp) + 1;
-                       strcpy(data, newp);
-                       data += length;
-                       *len += length;
-                       newp = newval[++stridx];
-               }
-       }
-       return 0;
-}
-
-/****************************************************************************/
-
-/*
- * Heuristic to guess if this is a string or concatenated strings.
- */
-
-static int is_printable_string(const void *data, int len)
-{
-       const char *s = data;
-
-       /* zero length is not */
-       if (len == 0)
-               return 0;
-
-       /* must terminate with zero or '\n' */
-       if (s[len - 1] != '\0' && s[len - 1] != '\n')
-               return 0;
-
-       /* printable or a null byte (concatenated strings) */
-       while (((*s == '\0') || isprint(*s) || isspace(*s)) && (len > 0)) {
-               /*
-                * If we see a null, there are three possibilities:
-                * 1) If len == 1, it is the end of the string, printable
-                * 2) Next character also a null, not printable.
-                * 3) Next character not a null, continue to check.
-                */
-               if (s[0] == '\0') {
-                       if (len == 1)
-                               return 1;
-                       if (s[1] == '\0')
-                               return 0;
-               }
-               s++;
-               len--;
-       }
-
-       /* Not the null termination, or not done yet: not printable */
-       if (*s != '\0' || (len != 0))
-               return 0;
-
-       return 1;
-}
-
-
-/*
- * Print the property in the best format, a heuristic guess.  Print as
- * a string, concatenated strings, a byte, word, double word, or (if all
- * else fails) it is printed as a stream of bytes.
- */
-static void print_data(const void *data, int len)
-{
-       int j;
-
-       /* no data, don't print */
-       if (len == 0)
-               return;
-
-       /*
-        * It is a string, but it may have multiple strings (embedded '\0's).
-        */
-       if (is_printable_string(data, len)) {
-               puts("\"");
-               j = 0;
-               while (j < len) {
-                       if (j > 0)
-                               puts("\", \"");
-                       puts(data);
-                       j    += strlen(data) + 1;
-                       data += strlen(data) + 1;
-               }
-               puts("\"");
-               return;
-       }
-
-       if ((len %4) == 0) {
-               if (len > CONFIG_CMD_FDT_MAX_DUMP)
-                       printf("* 0x%p [0x%08x]", data, len);
-               else {
-                       const __be32 *p;
-
-                       printf("<");
-                       for (j = 0, p = data; j < len/4; j++)
-                               printf("0x%08x%s", fdt32_to_cpu(p[j]),
-                                       j < (len/4 - 1) ? " " : "");
-                       printf(">");
-               }
-       } else { /* anything else... hexdump */
-               if (len > CONFIG_CMD_FDT_MAX_DUMP)
-                       printf("* 0x%p [0x%08x]", data, len);
-               else {
-                       const u8 *s;
-
-                       printf("[");
-                       for (j = 0, s = data; j < len; j++)
-                               printf("%02x%s", s[j], j < len - 1 ? " " : "");
-                       printf("]");
-               }
-       }
-}
-
-/****************************************************************************/
-
-/*
- * Recursively print (a portion of) the working_fdt.  The depth parameter
- * determines how deeply nested the fdt is printed.
- */
-static int fdt_print(const char *pathp, char *prop, int depth)
-{
-       static char tabs[MAX_LEVEL+1] =
-               "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
-               "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
-       const void *nodep;      /* property node pointer */
-       int  nodeoffset;        /* node offset from libfdt */
-       int  nextoffset;        /* next node offset from libfdt */
-       uint32_t tag;           /* tag */
-       int  len;               /* length of the property */
-       int  level = 0;         /* keep track of nesting level */
-       const struct fdt_property *fdt_prop;
-
-       nodeoffset = fdt_path_offset (working_fdt, pathp);
-       if (nodeoffset < 0) {
-               /*
-                * Not found or something else bad happened.
-                */
-               printf ("libfdt fdt_path_offset() returned %s\n",
-                       fdt_strerror(nodeoffset));
-               return 1;
-       }
-       /*
-        * The user passed in a property as well as node path.
-        * Print only the given property and then return.
-        */
-       if (prop) {
-               nodep = fdt_getprop (working_fdt, nodeoffset, prop, &len);
-               if (len == 0) {
-                       /* no property value */
-                       printf("%s %s\n", pathp, prop);
-                       return 0;
-               } else if (len > 0) {
-                       printf("%s = ", prop);
-                       print_data (nodep, len);
-                       printf("\n");
-                       return 0;
-               } else {
-                       printf ("libfdt fdt_getprop(): %s\n",
-                               fdt_strerror(len));
-                       return 1;
-               }
-       }
-
-       /*
-        * The user passed in a node path and no property,
-        * print the node and all subnodes.
-        */
-       while(level >= 0) {
-               tag = fdt_next_tag(working_fdt, nodeoffset, &nextoffset);
-               switch(tag) {
-               case FDT_BEGIN_NODE:
-                       pathp = fdt_get_name(working_fdt, nodeoffset, NULL);
-                       if (level <= depth) {
-                               if (pathp == NULL)
-                                       pathp = "/* NULL pointer error */";
-                               if (*pathp == '\0')
-                                       pathp = "/";    /* root is nameless */
-                               printf("%s%s {\n",
-                                       &tabs[MAX_LEVEL - level], pathp);
-                       }
-                       level++;
-                       if (level >= MAX_LEVEL) {
-                               printf("Nested too deep, aborting.\n");
-                               return 1;
-                       }
-                       break;
-               case FDT_END_NODE:
-                       level--;
-                       if (level <= depth)
-                               printf("%s};\n", &tabs[MAX_LEVEL - level]);
-                       if (level == 0) {
-                               level = -1;             /* exit the loop */
-                       }
-                       break;
-               case FDT_PROP:
-                       fdt_prop = fdt_offset_ptr(working_fdt, nodeoffset,
-                                       sizeof(*fdt_prop));
-                       pathp    = fdt_string(working_fdt,
-                                       fdt32_to_cpu(fdt_prop->nameoff));
-                       len      = fdt32_to_cpu(fdt_prop->len);
-                       nodep    = fdt_prop->data;
-                       if (len < 0) {
-                               printf ("libfdt fdt_getprop(): %s\n",
-                                       fdt_strerror(len));
-                               return 1;
-                       } else if (len == 0) {
-                               /* the property has no value */
-                               if (level <= depth)
-                                       printf("%s%s;\n",
-                                               &tabs[MAX_LEVEL - level],
-                                               pathp);
-                       } else {
-                               if (level <= depth) {
-                                       printf("%s%s = ",
-                                               &tabs[MAX_LEVEL - level],
-                                               pathp);
-                                       print_data (nodep, len);
-                                       printf(";\n");
-                               }
-                       }
-                       break;
-               case FDT_NOP:
-                       printf("%s/* NOP */\n", &tabs[MAX_LEVEL - level]);
-                       break;
-               case FDT_END:
-                       return 1;
-               default:
-                       if (level <= depth)
-                               printf("Unknown tag 0x%08X\n", tag);
-                       return 1;
-               }
-               nodeoffset = nextoffset;
-       }
-       return 0;
-}
-
-/********************************************************************/
-#ifdef CONFIG_SYS_LONGHELP
-static char fdt_help_text[] =
-       "addr [-c]  <addr> [<length>]   - Set the [control] fdt location to <addr>\n"
-#ifdef CONFIG_OF_BOARD_SETUP
-       "fdt boardsetup                      - Do board-specific set up\n"
-#endif
-#ifdef CONFIG_OF_SYSTEM_SETUP
-       "fdt systemsetup                     - Do system-specific set up\n"
-#endif
-       "fdt move   <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n"
-       "fdt resize                          - Resize fdt to size + padding to 4k addr\n"
-       "fdt print  <path> [<prop>]          - Recursive print starting at <path>\n"
-       "fdt list   <path> [<prop>]          - Print one level starting at <path>\n"
-       "fdt get value <var> <path> <prop>   - Get <property> and store in <var>\n"
-       "fdt get name <var> <path> <index>   - Get name of node <index> and store in <var>\n"
-       "fdt get addr <var> <path> <prop>    - Get start address of <property> and store in <var>\n"
-       "fdt get size <var> <path> [<prop>]  - Get size of [<property>] or num nodes and store in <var>\n"
-       "fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
-       "fdt mknode <path> <node>            - Create a new node after <path>\n"
-       "fdt rm     <path> [<prop>]          - Delete the node or <property>\n"
-       "fdt header                          - Display header info\n"
-       "fdt bootcpu <id>                    - Set boot cpuid\n"
-       "fdt memory <addr> <size>            - Add/Update memory node\n"
-       "fdt rsvmem print                    - Show current mem reserves\n"
-       "fdt rsvmem add <addr> <size>        - Add a mem reserve\n"
-       "fdt rsvmem delete <index>           - Delete a mem reserves\n"
-       "fdt chosen [<start> <end>]          - Add/update the /chosen branch in the tree\n"
-       "                                        <start>/<end> - initrd start/end addr\n"
-#if defined(CONFIG_FIT_SIGNATURE)
-       "fdt checksign [<addr>]              - check FIT signature\n"
-       "                                        <start> - addr of key blob\n"
-       "                                                  default gd->fdt_blob\n"
-#endif
-       "NOTE: Dereference aliases by omiting the leading '/', "
-               "e.g. fdt print ethernet0.";
-#endif
-
-U_BOOT_CMD(
-       fdt,    255,    0,      do_fdt,
-       "flattened device tree utility commands", fdt_help_text
-);
diff --git a/common/cmd_fitupd.c b/common/cmd_fitupd.c
deleted file mode 100644 (file)
index 78b8747..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * (C) Copyright 2011
- * Andreas Pretzsch, carpe noctem engineering, apr@cn-eng.de
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <net.h>
-
-#if !defined(CONFIG_UPDATE_TFTP)
-#error "CONFIG_UPDATE_TFTP required"
-#endif
-
-static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr = 0UL;
-
-       if (argc > 2)
-               return CMD_RET_USAGE;
-
-       if (argc == 2)
-               addr = simple_strtoul(argv[1], NULL, 16);
-
-       return update_tftp(addr, NULL, NULL);
-}
-
-U_BOOT_CMD(fitupd, 2, 0, do_fitupd,
-       "update from FIT image",
-       "[addr]\n"
-       "\t- run update from FIT image at addr\n"
-       "\t  or from tftp 'updatefile'"
-);
diff --git a/common/cmd_flash.c b/common/cmd_flash.c
deleted file mode 100644 (file)
index 85d18bb..0000000
+++ /dev/null
@@ -1,729 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * FLASH support
- */
-#include <common.h>
-#include <command.h>
-
-#ifdef CONFIG_HAS_DATAFLASH
-#include <dataflash.h>
-#endif
-
-#if defined(CONFIG_CMD_MTDPARTS)
-#include <jffs2/jffs2.h>
-
-/* partition handling routines */
-int mtdparts_init(void);
-int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
-int find_dev_and_part(const char *id, struct mtd_device **dev,
-               u8 *part_num, struct part_info **part);
-#endif
-
-#ifndef CONFIG_SYS_NO_FLASH
-#include <flash.h>
-#include <mtd/cfi_flash.h>
-extern flash_info_t flash_info[];      /* info for FLASH chips */
-
-/*
- * The user interface starts numbering for Flash banks with 1
- * for historical reasons.
- */
-
-/*
- * this routine looks for an abbreviated flash range specification.
- * the syntax is B:SF[-SL], where B is the bank number, SF is the first
- * sector to erase, and SL is the last sector to erase (defaults to SF).
- * bank numbers start at 1 to be consistent with other specs, sector numbers
- * start at zero.
- *
- * returns:    1       - correct spec; *pinfo, *psf and *psl are
- *                       set appropriately
- *             0       - doesn't look like an abbreviated spec
- *             -1      - looks like an abbreviated spec, but got
- *                       a parsing error, a number out of range,
- *                       or an invalid flash bank.
- */
-static int
-abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
-{
-       flash_info_t *fp;
-       int bank, first, last;
-       char *p, *ep;
-
-       if ((p = strchr (str, ':')) == NULL)
-               return 0;
-       *p++ = '\0';
-
-       bank = simple_strtoul (str, &ep, 10);
-       if (ep == str || *ep != '\0' ||
-               bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS ||
-               (fp = &flash_info[bank - 1])->flash_id == FLASH_UNKNOWN)
-               return -1;
-
-       str = p;
-       if ((p = strchr (str, '-')) != NULL)
-               *p++ = '\0';
-
-       first = simple_strtoul (str, &ep, 10);
-       if (ep == str || *ep != '\0' || first >= fp->sector_count)
-               return -1;
-
-       if (p != NULL) {
-               last = simple_strtoul (p, &ep, 10);
-               if (ep == p || *ep != '\0' ||
-                       last < first || last >= fp->sector_count)
-                       return -1;
-       } else {
-               last = first;
-       }
-
-       *pinfo = fp;
-       *psf = first;
-       *psl = last;
-
-       return 1;
-}
-
-/*
- * Take *addr in Flash and adjust it to fall on the end of its sector
- */
-int flash_sect_roundb (ulong *addr)
-{
-       flash_info_t *info;
-       ulong bank, sector_end_addr;
-       char found;
-       int i;
-
-       /* find the end addr of the sector where the *addr is */
-       found = 0;
-       for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS && !found; ++bank) {
-               info = &flash_info[bank];
-               for (i = 0; i < info->sector_count && !found; ++i) {
-                       /* get the end address of the sector */
-                       if (i == info->sector_count - 1) {
-                               sector_end_addr = info->start[0] +
-                                                               info->size - 1;
-                       } else {
-                               sector_end_addr = info->start[i+1] - 1;
-                       }
-
-                       if (*addr <= sector_end_addr &&
-                                               *addr >= info->start[i]) {
-                               found = 1;
-                               /* adjust *addr if necessary */
-                               if (*addr < sector_end_addr)
-                                       *addr = sector_end_addr;
-                       } /* sector */
-               } /* bank */
-       }
-       if (!found) {
-               /* error, address not in flash */
-               printf("Error: end address (0x%08lx) not in flash!\n", *addr);
-               return 1;
-       }
-
-       return 0;
-}
-
-/*
- * This function computes the start and end addresses for both
- * erase and protect commands. The range of the addresses on which
- * either of the commands is to operate can be given in two forms:
- * 1. <cmd> start end - operate on <'start',  'end')
- * 2. <cmd> start +length - operate on <'start', start + length)
- * If the second form is used and the end address doesn't fall on the
- * sector boundary, than it will be adjusted to the next sector boundary.
- * If it isn't in the flash, the function will fail (return -1).
- * Input:
- *    arg1, arg2: address specification (i.e. both command arguments)
- * Output:
- *    addr_first, addr_last: computed address range
- * Return:
- *    1: success
- *   -1: failure (bad format, bad address).
-*/
-static int
-addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
-{
-       char *ep;
-       char len_used; /* indicates if the "start +length" form used */
-
-       *addr_first = simple_strtoul(arg1, &ep, 16);
-       if (ep == arg1 || *ep != '\0')
-               return -1;
-
-       len_used = 0;
-       if (arg2 && *arg2 == '+'){
-               len_used = 1;
-               ++arg2;
-       }
-
-       *addr_last = simple_strtoul(arg2, &ep, 16);
-       if (ep == arg2 || *ep != '\0')
-               return -1;
-
-       if (len_used){
-               /*
-                * *addr_last has the length, compute correct *addr_last
-                * XXX watch out for the integer overflow! Right now it is
-                * checked for in both the callers.
-                */
-               *addr_last = *addr_first + *addr_last - 1;
-
-               /*
-                * It may happen that *addr_last doesn't fall on the sector
-                * boundary. We want to round such an address to the next
-                * sector boundary, so that the commands don't fail later on.
-                */
-
-               if (flash_sect_roundb(addr_last) > 0)
-                       return -1;
-       } /* "start +length" from used */
-
-       return 1;
-}
-
-static int
-flash_fill_sect_ranges (ulong addr_first, ulong addr_last,
-                       int *s_first, int *s_last,
-                       int *s_count )
-{
-       flash_info_t *info;
-       ulong bank;
-       int rcode = 0;
-
-       *s_count = 0;
-
-       for (bank=0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
-               s_first[bank] = -1;     /* first sector to erase        */
-               s_last [bank] = -1;     /* last  sector to erase        */
-       }
-
-       for (bank=0,info = &flash_info[0];
-            (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (addr_first <= addr_last);
-            ++bank, ++info) {
-               ulong b_end;
-               int sect;
-               short s_end;
-
-               if (info->flash_id == FLASH_UNKNOWN) {
-                       continue;
-               }
-
-               b_end = info->start[0] + info->size - 1;        /* bank end addr */
-               s_end = info->sector_count - 1;                 /* last sector   */
-
-
-               for (sect=0; sect < info->sector_count; ++sect) {
-                       ulong end;      /* last address in current sect */
-
-                       end = (sect == s_end) ? b_end : info->start[sect + 1] - 1;
-
-                       if (addr_first > end)
-                               continue;
-                       if (addr_last < info->start[sect])
-                               continue;
-
-                       if (addr_first == info->start[sect]) {
-                               s_first[bank] = sect;
-                       }
-                       if (addr_last  == end) {
-                               s_last[bank]  = sect;
-                       }
-               }
-               if (s_first[bank] >= 0) {
-                       if (s_last[bank] < 0) {
-                               if (addr_last > b_end) {
-                                       s_last[bank] = s_end;
-                               } else {
-                                       puts ("Error: end address"
-                                               " not on sector boundary\n");
-                                       rcode = 1;
-                                       break;
-                               }
-                       }
-                       if (s_last[bank] < s_first[bank]) {
-                               puts ("Error: end sector"
-                                       " precedes start sector\n");
-                               rcode = 1;
-                               break;
-                       }
-                       sect = s_last[bank];
-                       addr_first = (sect == s_end) ? b_end + 1: info->start[sect + 1];
-                       (*s_count) += s_last[bank] - s_first[bank] + 1;
-               } else if (addr_first >= info->start[0] && addr_first < b_end) {
-                       puts ("Error: start address not on sector boundary\n");
-                       rcode = 1;
-                       break;
-               } else if (s_last[bank] >= 0) {
-                       puts ("Error: cannot span across banks when they are"
-                              " mapped in reverse order\n");
-                       rcode = 1;
-                       break;
-               }
-       }
-
-       return rcode;
-}
-#endif /* CONFIG_SYS_NO_FLASH */
-
-static int do_flinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-#ifndef CONFIG_SYS_NO_FLASH
-       ulong bank;
-#endif
-
-#ifdef CONFIG_HAS_DATAFLASH
-       dataflash_print_info();
-#endif
-
-#ifndef CONFIG_SYS_NO_FLASH
-       if (argc == 1) {        /* print info for all FLASH banks */
-               for (bank=0; bank <CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
-                       printf ("\nBank # %ld: ", bank+1);
-
-                       flash_print_info (&flash_info[bank]);
-               }
-               return 0;
-       }
-
-       bank = simple_strtoul(argv[1], NULL, 16);
-       if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
-               printf ("Only FLASH Banks # 1 ... # %d supported\n",
-                       CONFIG_SYS_MAX_FLASH_BANKS);
-               return 1;
-       }
-       printf ("\nBank # %ld: ", bank);
-       flash_print_info (&flash_info[bank-1]);
-#endif /* CONFIG_SYS_NO_FLASH */
-       return 0;
-}
-
-static int do_flerase(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-#ifndef CONFIG_SYS_NO_FLASH
-       flash_info_t *info = NULL;
-       ulong bank, addr_first, addr_last;
-       int n, sect_first = 0, sect_last = 0;
-#if defined(CONFIG_CMD_MTDPARTS)
-       struct mtd_device *dev;
-       struct part_info *part;
-       u8 dev_type, dev_num, pnum;
-#endif
-       int rcode = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[1], "all") == 0) {
-               for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
-                       printf ("Erase Flash Bank # %ld ", bank);
-                       info = &flash_info[bank-1];
-                       rcode = flash_erase (info, 0, info->sector_count-1);
-               }
-               return rcode;
-       }
-
-       if ((n = abbrev_spec(argv[1], &info, &sect_first, &sect_last)) != 0) {
-               if (n < 0) {
-                       puts ("Bad sector specification\n");
-                       return 1;
-               }
-               printf ("Erase Flash Sectors %d-%d in Bank # %zu ",
-                       sect_first, sect_last, (info-flash_info)+1);
-               rcode = flash_erase(info, sect_first, sect_last);
-               return rcode;
-       }
-
-#if defined(CONFIG_CMD_MTDPARTS)
-       /* erase <part-id> - erase partition */
-       if ((argc == 2) && (mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) {
-               mtdparts_init();
-               if (find_dev_and_part(argv[1], &dev, &pnum, &part) == 0) {
-                       if (dev->id->type == MTD_DEV_TYPE_NOR) {
-                               bank = dev->id->num;
-                               info = &flash_info[bank];
-                               addr_first = part->offset + info->start[0];
-                               addr_last = addr_first + part->size - 1;
-
-                               printf ("Erase Flash Partition %s, "
-                                               "bank %ld, 0x%08lx - 0x%08lx ",
-                                               argv[1], bank, addr_first,
-                                               addr_last);
-
-                               rcode = flash_sect_erase(addr_first, addr_last);
-                               return rcode;
-                       }
-
-                       printf("cannot erase, not a NOR device\n");
-                       return 1;
-               }
-       }
-#endif
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[1], "bank") == 0) {
-               bank = simple_strtoul(argv[2], NULL, 16);
-               if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
-                       printf ("Only FLASH Banks # 1 ... # %d supported\n",
-                               CONFIG_SYS_MAX_FLASH_BANKS);
-                       return 1;
-               }
-               printf ("Erase Flash Bank # %ld ", bank);
-               info = &flash_info[bank-1];
-               rcode = flash_erase (info, 0, info->sector_count-1);
-               return rcode;
-       }
-
-       if (addr_spec(argv[1], argv[2], &addr_first, &addr_last) < 0){
-               printf ("Bad address format\n");
-               return 1;
-       }
-
-       if (addr_first >= addr_last)
-               return CMD_RET_USAGE;
-
-       rcode = flash_sect_erase(addr_first, addr_last);
-       return rcode;
-#else
-       return 0;
-#endif /* CONFIG_SYS_NO_FLASH */
-}
-
-#ifndef CONFIG_SYS_NO_FLASH
-int flash_sect_erase (ulong addr_first, ulong addr_last)
-{
-       flash_info_t *info;
-       ulong bank;
-       int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS];
-       int erased = 0;
-       int planned;
-       int rcode = 0;
-
-       rcode = flash_fill_sect_ranges (addr_first, addr_last,
-                                       s_first, s_last, &planned );
-
-       if (planned && (rcode == 0)) {
-               for (bank=0,info = &flash_info[0];
-                    (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (rcode == 0);
-                    ++bank, ++info) {
-                       if (s_first[bank]>=0) {
-                               erased += s_last[bank] - s_first[bank] + 1;
-                               debug ("Erase Flash from 0x%08lx to 0x%08lx "
-                                       "in Bank # %ld ",
-                                       info->start[s_first[bank]],
-                                       (s_last[bank] == info->sector_count) ?
-                                               info->start[0] + info->size - 1:
-                                               info->start[s_last[bank]+1] - 1,
-                                       bank+1);
-                               rcode = flash_erase (info, s_first[bank], s_last[bank]);
-                       }
-               }
-               if (rcode == 0)
-                       printf("Erased %d sectors\n", erased);
-       } else if (rcode == 0) {
-               puts ("Error: start and/or end address"
-                       " not on sector boundary\n");
-               rcode = 1;
-       }
-       return rcode;
-}
-#endif /* CONFIG_SYS_NO_FLASH */
-
-static int do_protect(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int rcode = 0;
-#ifndef CONFIG_SYS_NO_FLASH
-       flash_info_t *info = NULL;
-       ulong bank;
-       int i, n, sect_first = 0, sect_last = 0;
-#if defined(CONFIG_CMD_MTDPARTS)
-       struct mtd_device *dev;
-       struct part_info *part;
-       u8 dev_type, dev_num, pnum;
-#endif
-#endif /* CONFIG_SYS_NO_FLASH */
-#ifdef CONFIG_HAS_DATAFLASH
-       int status;
-#endif
-#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
-       int p;
-       ulong addr_first, addr_last;
-#endif
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
-       if (strcmp(argv[1], "off") == 0)
-               p = 0;
-       else if (strcmp(argv[1], "on") == 0)
-               p = 1;
-       else
-               return CMD_RET_USAGE;
-#endif
-
-#ifdef CONFIG_HAS_DATAFLASH
-       if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) {
-               addr_first = simple_strtoul(argv[2], NULL, 16);
-               addr_last  = simple_strtoul(argv[3], NULL, 16);
-
-               if (addr_dataflash(addr_first) && addr_dataflash(addr_last)) {
-                       status = dataflash_real_protect(p,addr_first,addr_last);
-                       if (status < 0){
-                               puts ("Bad DataFlash sector specification\n");
-                               return 1;
-                       }
-                       printf("%sProtect %d DataFlash Sectors\n",
-                               p ? "" : "Un-", status);
-                       return 0;
-               }
-       }
-#endif
-
-#ifndef CONFIG_SYS_NO_FLASH
-       if (strcmp(argv[2], "all") == 0) {
-               for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
-                       info = &flash_info[bank-1];
-                       if (info->flash_id == FLASH_UNKNOWN) {
-                               continue;
-                       }
-                       printf ("%sProtect Flash Bank # %ld\n",
-                               p ? "" : "Un-", bank);
-
-                       for (i=0; i<info->sector_count; ++i) {
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-                               if (flash_real_protect(info, i, p))
-                                       rcode = 1;
-                               putc ('.');
-#else
-                               info->protect[i] = p;
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-                       }
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-                       if (!rcode) puts (" done\n");
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-               }
-               return rcode;
-       }
-
-       if ((n = abbrev_spec(argv[2], &info, &sect_first, &sect_last)) != 0) {
-               if (n < 0) {
-                       puts ("Bad sector specification\n");
-                       return 1;
-               }
-               printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n",
-                       p ? "" : "Un-", sect_first, sect_last,
-                       (info-flash_info)+1);
-               for (i = sect_first; i <= sect_last; i++) {
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-                       if (flash_real_protect(info, i, p))
-                               rcode =  1;
-                       putc ('.');
-#else
-                       info->protect[i] = p;
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-               }
-
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-               if (!rcode) puts (" done\n");
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-
-               return rcode;
-       }
-
-#if defined(CONFIG_CMD_MTDPARTS)
-       /* protect on/off <part-id> */
-       if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
-               mtdparts_init();
-               if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) {
-                       if (dev->id->type == MTD_DEV_TYPE_NOR) {
-                               bank = dev->id->num;
-                               info = &flash_info[bank];
-                               addr_first = part->offset + info->start[0];
-                               addr_last = addr_first + part->size - 1;
-
-                               printf ("%sProtect Flash Partition %s, "
-                                               "bank %ld, 0x%08lx - 0x%08lx\n",
-                                               p ? "" : "Un", argv[1],
-                                               bank, addr_first, addr_last);
-
-                               rcode = flash_sect_protect (p, addr_first, addr_last);
-                               return rcode;
-                       }
-
-                       printf("cannot %sprotect, not a NOR device\n",
-                                       p ? "" : "un");
-                       return 1;
-               }
-       }
-#endif
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[2], "bank") == 0) {
-               bank = simple_strtoul(argv[3], NULL, 16);
-               if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
-                       printf ("Only FLASH Banks # 1 ... # %d supported\n",
-                               CONFIG_SYS_MAX_FLASH_BANKS);
-                       return 1;
-               }
-               printf ("%sProtect Flash Bank # %ld\n",
-                       p ? "" : "Un-", bank);
-               info = &flash_info[bank-1];
-
-               if (info->flash_id == FLASH_UNKNOWN) {
-                       puts ("missing or unknown FLASH type\n");
-                       return 1;
-               }
-               for (i=0; i<info->sector_count; ++i) {
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-                       if (flash_real_protect(info, i, p))
-                               rcode =  1;
-                       putc ('.');
-#else
-                       info->protect[i] = p;
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-               }
-
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-               if (!rcode) puts (" done\n");
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-
-               return rcode;
-       }
-
-       if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){
-               printf("Bad address format\n");
-               return 1;
-       }
-
-       if (addr_first >= addr_last)
-               return CMD_RET_USAGE;
-
-       rcode = flash_sect_protect (p, addr_first, addr_last);
-#endif /* CONFIG_SYS_NO_FLASH */
-       return rcode;
-}
-
-#ifndef CONFIG_SYS_NO_FLASH
-int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
-{
-       flash_info_t *info;
-       ulong bank;
-       int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS];
-       int protected, i;
-       int planned;
-       int rcode;
-
-       rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned );
-
-       protected = 0;
-
-       if (planned && (rcode == 0)) {
-               for (bank=0,info = &flash_info[0]; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) {
-                       if (info->flash_id == FLASH_UNKNOWN) {
-                               continue;
-                       }
-
-                       if (s_first[bank]>=0 && s_first[bank]<=s_last[bank]) {
-                               debug ("%sProtecting sectors %d..%d in bank %ld\n",
-                                       p ? "" : "Un-",
-                                       s_first[bank], s_last[bank], bank+1);
-                               protected += s_last[bank] - s_first[bank] + 1;
-                               for (i=s_first[bank]; i<=s_last[bank]; ++i) {
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-                                       if (flash_real_protect(info, i, p))
-                                               rcode = 1;
-                                       putc ('.');
-#else
-                                       info->protect[i] = p;
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-                               }
-                       }
-               }
-#if defined(CONFIG_SYS_FLASH_PROTECTION)
-               puts (" done\n");
-#endif /* CONFIG_SYS_FLASH_PROTECTION */
-
-               printf ("%sProtected %d sectors\n",
-                       p ? "" : "Un-", protected);
-       } else if (rcode == 0) {
-               puts ("Error: start and/or end address"
-                       " not on sector boundary\n");
-               rcode = 1;
-       }
-       return rcode;
-}
-#endif /* CONFIG_SYS_NO_FLASH */
-
-
-/**************************************************/
-#if defined(CONFIG_CMD_MTDPARTS)
-# define TMP_ERASE     "erase <part-id>\n    - erase partition\n"
-# define TMP_PROT_ON   "protect on <part-id>\n    - protect partition\n"
-# define TMP_PROT_OFF  "protect off <part-id>\n    - make partition writable\n"
-#else
-# define TMP_ERASE     /* empty */
-# define TMP_PROT_ON   /* empty */
-# define TMP_PROT_OFF  /* empty */
-#endif
-
-U_BOOT_CMD(
-       flinfo,    2,    1,    do_flinfo,
-       "print FLASH memory information",
-       "\n    - print information for all FLASH memory banks\n"
-       "flinfo N\n    - print information for FLASH memory bank # N"
-);
-
-U_BOOT_CMD(
-       erase,   3,   0,  do_flerase,
-       "erase FLASH memory",
-       "start end\n"
-       "    - erase FLASH from addr 'start' to addr 'end'\n"
-       "erase start +len\n"
-       "    - erase FLASH from addr 'start' to the end of sect "
-       "w/addr 'start'+'len'-1\n"
-       "erase N:SF[-SL]\n    - erase sectors SF-SL in FLASH bank # N\n"
-       "erase bank N\n    - erase FLASH bank # N\n"
-       TMP_ERASE
-       "erase all\n    - erase all FLASH banks"
-);
-
-U_BOOT_CMD(
-       protect,  4,  0,   do_protect,
-       "enable or disable FLASH write protection",
-       "on  start end\n"
-       "    - protect FLASH from addr 'start' to addr 'end'\n"
-       "protect on start +len\n"
-       "    - protect FLASH from addr 'start' to end of sect "
-       "w/addr 'start'+'len'-1\n"
-       "protect on  N:SF[-SL]\n"
-       "    - protect sectors SF-SL in FLASH bank # N\n"
-       "protect on  bank N\n    - protect FLASH bank # N\n"
-       TMP_PROT_ON
-       "protect on  all\n    - protect all FLASH banks\n"
-       "protect off start end\n"
-       "    - make FLASH from addr 'start' to addr 'end' writable\n"
-       "protect off start +len\n"
-       "    - make FLASH from addr 'start' to end of sect "
-       "w/addr 'start'+'len'-1 wrtable\n"
-       "protect off N:SF[-SL]\n"
-       "    - make sectors SF-SL writable in FLASH bank # N\n"
-       "protect off bank N\n    - make FLASH bank # N writable\n"
-       TMP_PROT_OFF
-       "protect off all\n    - make all FLASH banks writable"
-);
-
-#undef TMP_ERASE
-#undef TMP_PROT_ON
-#undef TMP_PROT_OFF
diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c
deleted file mode 100644 (file)
index 7f99aab..0000000
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * (C) Copyright 2000, 2001
- * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- *  FPGA support
- */
-#include <common.h>
-#include <command.h>
-#include <fpga.h>
-#include <fs.h>
-#include <malloc.h>
-
-/* Local functions */
-static int fpga_get_op(char *opstr);
-
-/* Local defines */
-#define FPGA_NONE   -1
-#define FPGA_INFO   0
-#define FPGA_LOAD   1
-#define FPGA_LOADB  2
-#define FPGA_DUMP   3
-#define FPGA_LOADMK 4
-#define FPGA_LOADP  5
-#define FPGA_LOADBP 6
-#define FPGA_LOADFS 7
-
-/* ------------------------------------------------------------------------- */
-/* command form:
- *   fpga <op> <device number> <data addr> <datasize>
- * where op is 'load', 'dump', or 'info'
- * If there is no device number field, the fpga environment variable is used.
- * If there is no data addr field, the fpgadata environment variable is used.
- * The info command requires no data address field.
- */
-int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int op, dev = FPGA_INVALID_DEVICE;
-       size_t data_size = 0;
-       void *fpga_data = NULL;
-       char *devstr = getenv("fpga");
-       char *datastr = getenv("fpgadata");
-       int rc = FPGA_FAIL;
-       int wrong_parms = 0;
-#if defined(CONFIG_FIT)
-       const char *fit_uname = NULL;
-       ulong fit_addr;
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-       fpga_fs_info fpga_fsinfo;
-       fpga_fsinfo.fstype = FS_TYPE_ANY;
-#endif
-
-       if (devstr)
-               dev = (int) simple_strtoul(devstr, NULL, 16);
-       if (datastr)
-               fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
-
-       switch (argc) {
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-       case 9:
-               fpga_fsinfo.blocksize = (unsigned int)
-                                            simple_strtoul(argv[5], NULL, 16);
-               fpga_fsinfo.interface = argv[6];
-               fpga_fsinfo.dev_part = argv[7];
-               fpga_fsinfo.filename = argv[8];
-#endif
-       case 5:         /* fpga <op> <dev> <data> <datasize> */
-               data_size = simple_strtoul(argv[4], NULL, 16);
-
-       case 4:         /* fpga <op> <dev> <data> */
-#if defined(CONFIG_FIT)
-               if (fit_parse_subimage(argv[3], (ulong)fpga_data,
-                                      &fit_addr, &fit_uname)) {
-                       fpga_data = (void *)fit_addr;
-                       debug("*  fpga: subimage '%s' from FIT image ",
-                             fit_uname);
-                       debug("at 0x%08lx\n", fit_addr);
-               } else
-#endif
-               {
-                       fpga_data = (void *)simple_strtoul(argv[3], NULL, 16);
-                       debug("*  fpga: cmdline image address = 0x%08lx\n",
-                             (ulong)fpga_data);
-               }
-               debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data);
-
-       case 3:         /* fpga <op> <dev | data addr> */
-               dev = (int)simple_strtoul(argv[2], NULL, 16);
-               debug("%s: device = %d\n", __func__, dev);
-               /* FIXME - this is a really weak test */
-               if ((argc == 3) && (dev > fpga_count())) {
-                       /* must be buffer ptr */
-                       debug("%s: Assuming buffer pointer in arg 3\n",
-                             __func__);
-
-#if defined(CONFIG_FIT)
-                       if (fit_parse_subimage(argv[2], (ulong)fpga_data,
-                                              &fit_addr, &fit_uname)) {
-                               fpga_data = (void *)fit_addr;
-                               debug("*  fpga: subimage '%s' from FIT image ",
-                                     fit_uname);
-                               debug("at 0x%08lx\n", fit_addr);
-                       } else
-#endif
-                       {
-                               fpga_data = (void *)dev;
-                               debug("*  fpga: cmdline image addr = 0x%08lx\n",
-                                     (ulong)fpga_data);
-                       }
-
-                       debug("%s: fpga_data = 0x%x\n",
-                             __func__, (uint)fpga_data);
-                       dev = FPGA_INVALID_DEVICE;      /* reset device num */
-               }
-
-       case 2:         /* fpga <op> */
-               op = (int)fpga_get_op(argv[1]);
-               break;
-
-       default:
-               debug("%s: Too many or too few args (%d)\n", __func__, argc);
-               op = FPGA_NONE; /* force usage display */
-               break;
-       }
-
-       if (dev == FPGA_INVALID_DEVICE) {
-               puts("FPGA device not specified\n");
-               op = FPGA_NONE;
-       }
-
-       switch (op) {
-       case FPGA_NONE:
-       case FPGA_INFO:
-               break;
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-       case FPGA_LOADFS:
-               /* Blocksize can be zero */
-               if (!fpga_fsinfo.interface || !fpga_fsinfo.dev_part ||
-                   !fpga_fsinfo.filename)
-                       wrong_parms = 1;
-#endif
-       case FPGA_LOAD:
-       case FPGA_LOADP:
-       case FPGA_LOADB:
-       case FPGA_LOADBP:
-       case FPGA_DUMP:
-               if (!fpga_data || !data_size)
-                       wrong_parms = 1;
-               break;
-#if defined(CONFIG_CMD_FPGA_LOADMK)
-       case FPGA_LOADMK:
-               if (!fpga_data)
-                       wrong_parms = 1;
-               break;
-#endif
-       }
-
-       if (wrong_parms) {
-               puts("Wrong parameters for FPGA request\n");
-               op = FPGA_NONE;
-       }
-
-       switch (op) {
-       case FPGA_NONE:
-               return CMD_RET_USAGE;
-
-       case FPGA_INFO:
-               rc = fpga_info(dev);
-               break;
-
-       case FPGA_LOAD:
-               rc = fpga_load(dev, fpga_data, data_size, BIT_FULL);
-               break;
-
-#if defined(CONFIG_CMD_FPGA_LOADP)
-       case FPGA_LOADP:
-               rc = fpga_load(dev, fpga_data, data_size, BIT_PARTIAL);
-               break;
-#endif
-
-       case FPGA_LOADB:
-               rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_FULL);
-               break;
-
-#if defined(CONFIG_CMD_FPGA_LOADBP)
-       case FPGA_LOADBP:
-               rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_PARTIAL);
-               break;
-#endif
-
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-       case FPGA_LOADFS:
-               rc = fpga_fsload(dev, fpga_data, data_size, &fpga_fsinfo);
-               break;
-#endif
-
-#if defined(CONFIG_CMD_FPGA_LOADMK)
-       case FPGA_LOADMK:
-               switch (genimg_get_format(fpga_data)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-               case IMAGE_FORMAT_LEGACY:
-                       {
-                               image_header_t *hdr =
-                                               (image_header_t *)fpga_data;
-                               ulong data;
-                               uint8_t comp;
-
-                               comp = image_get_comp(hdr);
-                               if (comp == IH_COMP_GZIP) {
-#if defined(CONFIG_GZIP)
-                                       ulong image_buf = image_get_data(hdr);
-                                       data = image_get_load(hdr);
-                                       ulong image_size = ~0UL;
-
-                                       if (gunzip((void *)data, ~0UL,
-                                                  (void *)image_buf,
-                                                  &image_size) != 0) {
-                                               puts("GUNZIP: error\n");
-                                               return 1;
-                                       }
-                                       data_size = image_size;
-#else
-                                       puts("Gunzip image is not supported\n");
-                                       return 1;
-#endif
-                               } else {
-                                       data = (ulong)image_get_data(hdr);
-                                       data_size = image_get_data_size(hdr);
-                               }
-                               rc = fpga_load(dev, (void *)data, data_size,
-                                              BIT_FULL);
-                       }
-                       break;
-#endif
-#if defined(CONFIG_FIT)
-               case IMAGE_FORMAT_FIT:
-                       {
-                               const void *fit_hdr = (const void *)fpga_data;
-                               int noffset;
-                               const void *fit_data;
-
-                               if (fit_uname == NULL) {
-                                       puts("No FIT subimage unit name\n");
-                                       return 1;
-                               }
-
-                               if (!fit_check_format(fit_hdr)) {
-                                       puts("Bad FIT image format\n");
-                                       return 1;
-                               }
-
-                               /* get fpga component image node offset */
-                               noffset = fit_image_get_node(fit_hdr,
-                                                            fit_uname);
-                               if (noffset < 0) {
-                                       printf("Can't find '%s' FIT subimage\n",
-                                              fit_uname);
-                                       return 1;
-                               }
-
-                               /* verify integrity */
-                               if (!fit_image_verify(fit_hdr, noffset)) {
-                                       puts ("Bad Data Hash\n");
-                                       return 1;
-                               }
-
-                               /* get fpga subimage data address and length */
-                               if (fit_image_get_data(fit_hdr, noffset,
-                                                      &fit_data, &data_size)) {
-                                       puts("Fpga subimage data not found\n");
-                                       return 1;
-                               }
-
-                               rc = fpga_load(dev, fit_data, data_size,
-                                              BIT_FULL);
-                       }
-                       break;
-#endif
-               default:
-                       puts("** Unknown image type\n");
-                       rc = FPGA_FAIL;
-                       break;
-               }
-               break;
-#endif
-
-       case FPGA_DUMP:
-               rc = fpga_dump(dev, fpga_data, data_size);
-               break;
-
-       default:
-               printf("Unknown operation\n");
-               return CMD_RET_USAGE;
-       }
-       return rc;
-}
-
-/*
- * Map op to supported operations.  We don't use a table since we
- * would just have to relocate it from flash anyway.
- */
-static int fpga_get_op(char *opstr)
-{
-       int op = FPGA_NONE;
-
-       if (!strcmp("info", opstr))
-               op = FPGA_INFO;
-       else if (!strcmp("loadb", opstr))
-               op = FPGA_LOADB;
-       else if (!strcmp("load", opstr))
-               op = FPGA_LOAD;
-#if defined(CONFIG_CMD_FPGA_LOADP)
-       else if (!strcmp("loadp", opstr))
-               op = FPGA_LOADP;
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADBP)
-       else if (!strcmp("loadbp", opstr))
-               op = FPGA_LOADBP;
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-       else if (!strcmp("loadfs", opstr))
-               op = FPGA_LOADFS;
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADMK)
-       else if (!strcmp("loadmk", opstr))
-               op = FPGA_LOADMK;
-#endif
-       else if (!strcmp("dump", opstr))
-               op = FPGA_DUMP;
-
-       if (op == FPGA_NONE)
-               printf("Unknown fpga operation \"%s\"\n", opstr);
-
-       return op;
-}
-
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-U_BOOT_CMD(fpga, 9, 1, do_fpga,
-#else
-U_BOOT_CMD(fpga, 6, 1, do_fpga,
-#endif
-          "loadable FPGA image support",
-          "[operation type] [device number] [image address] [image size]\n"
-          "fpga operations:\n"
-          "  dump\t[dev] [address] [size]\tLoad device to memory buffer\n"
-          "  info\t[dev]\t\t\tlist known device information\n"
-          "  load\t[dev] [address] [size]\tLoad device from memory buffer\n"
-#if defined(CONFIG_CMD_FPGA_LOADP)
-          "  loadp\t[dev] [address] [size]\t"
-          "Load device from memory buffer with partial bitstream\n"
-#endif
-          "  loadb\t[dev] [address] [size]\t"
-          "Load device from bitstream buffer (Xilinx only)\n"
-#if defined(CONFIG_CMD_FPGA_LOADBP)
-          "  loadbp\t[dev] [address] [size]\t"
-          "Load device from bitstream buffer with partial bitstream"
-          "(Xilinx only)\n"
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADFS)
-          "Load device from filesystem (FAT by default) (Xilinx only)\n"
-          "  loadfs [dev] [address] [image size] [blocksize] <interface>\n"
-          "        [<dev[:part]>] <filename>\n"
-#endif
-#if defined(CONFIG_CMD_FPGA_LOADMK)
-          "  loadmk [dev] [address]\tLoad device generated with mkimage"
-#if defined(CONFIG_FIT)
-          "\n"
-          "\tFor loadmk operating on FIT format uImage address must include\n"
-          "\tsubimage unit name in the form of addr:<subimg_uname>"
-#endif
-#endif
-);
diff --git a/common/cmd_fpgad.c b/common/cmd_fpgad.c
deleted file mode 100644 (file)
index 5370c3e..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * (C) Copyright 2013
- * Dirk Eibach,  Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
- *
- * based on cmd_mem.c
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <console.h>
-
-#include <gdsys_fpga.h>
-
-static uint    dp_last_fpga;
-static uint    dp_last_addr;
-static uint    dp_last_length = 0x40;
-
-/*
- * FPGA Memory Display
- *
- * Syntax:
- *     fpgad {fpga} {addr} {len}
- */
-#define DISP_LINE_LEN  16
-int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int k;
-       unsigned int fpga;
-       ulong   addr, length;
-       int rc = 0;
-       u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
-       ulong nbytes;
-
-       /*
-        * We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       fpga = dp_last_fpga;
-       addr = dp_last_addr;
-       length = dp_last_length;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /*
-                * FPGA is specified since argc > 2
-                */
-               fpga = simple_strtoul(argv[1], NULL, 16);
-
-               /*
-                * Address is specified since argc > 2
-                */
-               addr = simple_strtoul(argv[2], NULL, 16);
-
-               /*
-                * If another parameter, it is the length to display.
-                * Length is the number of objects, not number of bytes.
-                */
-               if (argc > 3)
-                       length = simple_strtoul(argv[3], NULL, 16);
-       }
-
-       nbytes = length * sizeof(u16);
-       do {
-               ulong linebytes = (nbytes > DISP_LINE_LEN) ?
-                                 DISP_LINE_LEN : nbytes;
-
-               for (k = 0; k < linebytes / sizeof(u16); ++k)
-                       fpga_get_reg(fpga,
-                                    (u16 *)fpga_ptr[fpga] + addr
-                                    / sizeof(u16) + k,
-                                    addr + k * sizeof(u16),
-                                    &linebuf[k]);
-               print_buffer(addr, (void *)linebuf, sizeof(u16),
-                            linebytes / sizeof(u16),
-                            DISP_LINE_LEN / sizeof(u16));
-
-               nbytes -= linebytes;
-               addr += linebytes;
-               if (ctrlc()) {
-                       rc = 1;
-                       break;
-               }
-       } while (nbytes > 0);
-
-       dp_last_fpga = fpga;
-       dp_last_addr = addr;
-       dp_last_length = length;
-       return rc;
-}
-
-U_BOOT_CMD(
-       fpgad,  4,      1,      do_fpga_md,
-       "fpga register display",
-       "fpga address [# of objects]"
-);
diff --git a/common/cmd_fs.c b/common/cmd_fs.c
deleted file mode 100644 (file)
index 8f8f1b2..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
- *
- * Inspired by cmd_ext_common.c, cmd_fat.c.
- *
- * SPDX-License-Identifier:    GPL-2.0
- */
-
-#include <common.h>
-#include <command.h>
-#include <fs.h>
-
-static int do_size_wrapper(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return do_size(cmdtp, flag, argc, argv, FS_TYPE_ANY);
-}
-
-U_BOOT_CMD(
-       size,   4,      0,      do_size_wrapper,
-       "determine a file's size",
-       "<interface> <dev[:part]> <filename>\n"
-       "    - Find file 'filename' from 'dev' on 'interface'\n"
-       "      and determine its size."
-);
-
-static int do_load_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       return do_load(cmdtp, flag, argc, argv, FS_TYPE_ANY);
-}
-
-U_BOOT_CMD(
-       load,   7,      0,      do_load_wrapper,
-       "load binary file from a filesystem",
-       "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
-       "    - Load binary file 'filename' from partition 'part' on device\n"
-       "       type 'interface' instance 'dev' to address 'addr' in memory.\n"
-       "      'bytes' gives the size to load in bytes.\n"
-       "      If 'bytes' is 0 or omitted, the file is read until the end.\n"
-       "      'pos' gives the file byte position to start reading from.\n"
-       "      If 'pos' is 0 or omitted, the file is read from the start."
-)
-
-static int do_save_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       return do_save(cmdtp, flag, argc, argv, FS_TYPE_ANY);
-}
-
-U_BOOT_CMD(
-       save,   7,      0,      do_save_wrapper,
-       "save file to a filesystem",
-       "<interface> <dev[:part]> <addr> <filename> bytes [pos]\n"
-       "    - Save binary file 'filename' to partition 'part' on device\n"
-       "      type 'interface' instance 'dev' from addr 'addr' in memory.\n"
-       "      'bytes' gives the size to save in bytes and is mandatory.\n"
-       "      'pos' gives the file byte position to start writing to.\n"
-       "      If 'pos' is 0 or omitted, the file is written from the start."
-)
-
-static int do_ls_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_ANY);
-}
-
-U_BOOT_CMD(
-       ls,     4,      1,      do_ls_wrapper,
-       "list files in a directory (default /)",
-       "<interface> [<dev[:part]> [directory]]\n"
-       "    - List files in directory 'directory' of partition 'part' on\n"
-       "      device type 'interface' instance 'dev'."
-)
-
-static int do_fstype_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       return do_fs_type(cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(
-       fstype, 4, 1, do_fstype_wrapper,
-       "Look up a filesystem type",
-       "<interface> <dev>:<part>\n"
-       "- print filesystem type\n"
-       "fstype <interface> <dev>:<part> <varname>\n"
-       "- set environment variable to filesystem type\n"
-);
diff --git a/common/cmd_fs_uuid.c b/common/cmd_fs_uuid.c
deleted file mode 100644 (file)
index 613f3a4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * cmd_fs_uuid.c -- fsuuid command
- *
- * Copyright (C) 2014, Bachmann electronic GmbH
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <fs.h>
-
-static int do_fs_uuid_wrapper(cmd_tbl_t *cmdtp, int flag,
-       int argc, char * const argv[])
-{
-       return do_fs_uuid(cmdtp, flag, argc, argv, FS_TYPE_ANY);
-}
-
-U_BOOT_CMD(
-       fsuuid, 4, 1, do_fs_uuid_wrapper,
-       "Look up a filesystem UUID",
-       "<interface> <dev>:<part>\n"
-       "    - print filesystem UUID\n"
-       "fsuuid <interface> <dev>:<part> <varname>\n"
-       "    - set environment variable to filesystem UUID\n"
-);
diff --git a/common/cmd_fuse.c b/common/cmd_fuse.c
deleted file mode 100644 (file)
index 5998f9b..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * (C) Copyright 2009-2013 ADVANSEE
- * Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
- *
- * Based on the mpc512x iim code:
- * Copyright 2008 Silicon Turnkey Express, Inc.
- * Martha Marx <mmarx@silicontkx.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <fuse.h>
-#include <asm/errno.h>
-
-static int strtou32(const char *str, unsigned int base, u32 *result)
-{
-       char *ep;
-
-       *result = simple_strtoul(str, &ep, base);
-       if (ep == str || *ep != '\0')
-               return -EINVAL;
-
-       return 0;
-}
-
-static int confirm_prog(void)
-{
-       puts("Warning: Programming fuses is an irreversible operation!\n"
-                       "         This may brick your system.\n"
-                       "         Use this command only if you are sure of "
-                                       "what you are doing!\n"
-                       "\nReally perform this fuse programming? <y/N>\n");
-
-       if (confirm_yesno())
-               return 1;
-
-       puts("Fuse programming aborted\n");
-       return 0;
-}
-
-static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       const char *op = argc >= 2 ? argv[1] : NULL;
-       int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
-       u32 bank, word, cnt, val;
-       int ret, i;
-
-       argc -= 2 + confirmed;
-       argv += 2 + confirmed;
-
-       if (argc < 2 || strtou32(argv[0], 0, &bank) ||
-                       strtou32(argv[1], 0, &word))
-               return CMD_RET_USAGE;
-
-       if (!strcmp(op, "read")) {
-               if (argc == 2)
-                       cnt = 1;
-               else if (argc != 3 || strtou32(argv[2], 0, &cnt))
-                       return CMD_RET_USAGE;
-
-               printf("Reading bank %u:\n", bank);
-               for (i = 0; i < cnt; i++, word++) {
-                       if (!(i % 4))
-                               printf("\nWord 0x%.8x:", word);
-
-                       ret = fuse_read(bank, word, &val);
-                       if (ret)
-                               goto err;
-
-                       printf(" %.8x", val);
-               }
-               putc('\n');
-       } else if (!strcmp(op, "sense")) {
-               if (argc == 2)
-                       cnt = 1;
-               else if (argc != 3 || strtou32(argv[2], 0, &cnt))
-                       return CMD_RET_USAGE;
-
-               printf("Sensing bank %u:\n", bank);
-               for (i = 0; i < cnt; i++, word++) {
-                       if (!(i % 4))
-                               printf("\nWord 0x%.8x:", word);
-
-                       ret = fuse_sense(bank, word, &val);
-                       if (ret)
-                               goto err;
-
-                       printf(" %.8x", val);
-               }
-               putc('\n');
-       } else if (!strcmp(op, "prog")) {
-               if (argc < 3)
-                       return CMD_RET_USAGE;
-
-               for (i = 2; i < argc; i++, word++) {
-                       if (strtou32(argv[i], 16, &val))
-                               return CMD_RET_USAGE;
-
-                       printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
-                                       bank, word, val);
-                       if (!confirmed && !confirm_prog())
-                               return CMD_RET_FAILURE;
-                       ret = fuse_prog(bank, word, val);
-                       if (ret)
-                               goto err;
-               }
-       } else if (!strcmp(op, "override")) {
-               if (argc < 3)
-                       return CMD_RET_USAGE;
-
-               for (i = 2; i < argc; i++, word++) {
-                       if (strtou32(argv[i], 16, &val))
-                               return CMD_RET_USAGE;
-
-                       printf("Overriding bank %u word 0x%.8x with "
-                                       "0x%.8x...\n", bank, word, val);
-                       ret = fuse_override(bank, word, val);
-                       if (ret)
-                               goto err;
-               }
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-
-err:
-       puts("ERROR\n");
-       return CMD_RET_FAILURE;
-}
-
-U_BOOT_CMD(
-       fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
-       "Fuse sub-system",
-            "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
-       "    starting at 'word'\n"
-       "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
-       "    starting at 'word'\n"
-       "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
-       "    several fuse words, starting at 'word' (PERMANENT)\n"
-       "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
-       "    several fuse words, starting at 'word'"
-);
diff --git a/common/cmd_gettime.c b/common/cmd_gettime.c
deleted file mode 100644 (file)
index c48baad..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- *
- * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
- *
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Get Timer overflows after 2^32 / CONFIG_SYS_HZ (32Khz) = 131072 sec
- */
-#include <common.h>
-#include <command.h>
-
-static int do_gettime(cmd_tbl_t *cmdtp, int flag, int argc,
-                     char * const argv[])
-{
-       unsigned long int val = get_timer(0);
-
-#ifdef CONFIG_SYS_HZ
-       printf("Timer val: %lu\n", val);
-       printf("Seconds : %lu\n", val / CONFIG_SYS_HZ);
-       printf("Remainder : %lu\n", val % CONFIG_SYS_HZ);
-       printf("sys_hz = %lu\n", (unsigned long int)CONFIG_SYS_HZ);
-#else
-       printf("CONFIG_SYS_HZ not defined");
-       printf("Timer Val %lu", val);
-#endif
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       gettime,        1,      1,      do_gettime,
-       "get timer val elapsed",
-       "get time elapsed from uboot start"
-);
diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c
deleted file mode 100644 (file)
index 2b78b16..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Control GPIO pins on the fly
- *
- * Copyright (c) 2008-2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <common.h>
-#include <command.h>
-#include <errno.h>
-#include <dm.h>
-#include <asm/gpio.h>
-
-__weak int name_to_gpio(const char *name)
-{
-       return simple_strtoul(name, NULL, 10);
-}
-
-enum gpio_cmd {
-       GPIO_INPUT,
-       GPIO_SET,
-       GPIO_CLEAR,
-       GPIO_TOGGLE,
-};
-
-#if defined(CONFIG_DM_GPIO) && !defined(gpio_status)
-
-/* A few flags used by show_gpio() */
-enum {
-       FLAG_SHOW_ALL           = 1 << 0,
-       FLAG_SHOW_BANK          = 1 << 1,
-       FLAG_SHOW_NEWLINE       = 1 << 2,
-};
-
-static void gpio_get_description(struct udevice *dev, const char *bank_name,
-                                int offset, int *flagsp)
-{
-       char buf[80];
-       int ret;
-
-       ret = gpio_get_function(dev, offset, NULL);
-       if (ret < 0)
-               goto err;
-       if (!(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
-               return;
-       if ((*flagsp & FLAG_SHOW_BANK) && bank_name) {
-               if (*flagsp & FLAG_SHOW_NEWLINE) {
-                       putc('\n');
-                       *flagsp &= ~FLAG_SHOW_NEWLINE;
-               }
-               printf("Bank %s:\n", bank_name);
-               *flagsp &= ~FLAG_SHOW_BANK;
-       }
-
-       ret = gpio_get_status(dev, offset, buf, sizeof(buf));
-       if (ret)
-               goto err;
-
-       printf("%s\n", buf);
-       return;
-err:
-       printf("Error %d\n", ret);
-}
-
-static int do_gpio_status(bool all, const char *gpio_name)
-{
-       struct udevice *dev;
-       int banklen;
-       int flags;
-       int ret;
-
-       flags = 0;
-       if (gpio_name && !*gpio_name)
-               gpio_name = NULL;
-       for (ret = uclass_first_device(UCLASS_GPIO, &dev);
-            dev;
-            ret = uclass_next_device(&dev)) {
-               const char *bank_name;
-               int num_bits;
-
-               flags |= FLAG_SHOW_BANK;
-               if (all)
-                       flags |= FLAG_SHOW_ALL;
-               bank_name = gpio_get_bank_info(dev, &num_bits);
-               if (!num_bits) {
-                       debug("GPIO device %s has no bits\n", dev->name);
-                       continue;
-               }
-               banklen = bank_name ? strlen(bank_name) : 0;
-
-               if (!gpio_name || !bank_name ||
-                   !strncmp(gpio_name, bank_name, banklen)) {
-                       const char *p = NULL;
-                       int offset;
-
-                       p = gpio_name + banklen;
-                       if (gpio_name && *p) {
-                               offset = simple_strtoul(p, NULL, 10);
-                               gpio_get_description(dev, bank_name, offset,
-                                                    &flags);
-                       } else {
-                               for (offset = 0; offset < num_bits; offset++) {
-                                       gpio_get_description(dev, bank_name,
-                                                            offset, &flags);
-                               }
-                       }
-               }
-               /* Add a newline between bank names */
-               if (!(flags & FLAG_SHOW_BANK))
-                       flags |= FLAG_SHOW_NEWLINE;
-       }
-
-       return ret;
-}
-#endif
-
-static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int gpio;
-       enum gpio_cmd sub_cmd;
-       ulong value;
-       const char *str_cmd, *str_gpio = NULL;
-       int ret;
-#ifdef CONFIG_DM_GPIO
-       bool all = false;
-#endif
-
-       if (argc < 2)
- show_usage:
-               return CMD_RET_USAGE;
-       str_cmd = argv[1];
-       argc -= 2;
-       argv += 2;
-#ifdef CONFIG_DM_GPIO
-       if (argc > 0 && !strcmp(*argv, "-a")) {
-               all = true;
-               argc--;
-               argv++;
-       }
-#endif
-       if (argc > 0)
-               str_gpio = *argv;
-       if (!strncmp(str_cmd, "status", 1)) {
-               /* Support deprecated gpio_status() */
-#ifdef gpio_status
-               gpio_status();
-               return 0;
-#elif defined(CONFIG_DM_GPIO)
-               return cmd_process_error(cmdtp, do_gpio_status(all, str_gpio));
-#else
-               goto show_usage;
-#endif
-       }
-
-       if (!str_gpio)
-               goto show_usage;
-
-       /* parse the behavior */
-       switch (*str_cmd) {
-               case 'i': sub_cmd = GPIO_INPUT;  break;
-               case 's': sub_cmd = GPIO_SET;    break;
-               case 'c': sub_cmd = GPIO_CLEAR;  break;
-               case 't': sub_cmd = GPIO_TOGGLE; break;
-               default:  goto show_usage;
-       }
-
-#if defined(CONFIG_DM_GPIO)
-       /*
-        * TODO(sjg@chromium.org): For now we must fit into the existing GPIO
-        * framework, so we look up the name here and convert it to a GPIO number.
-        * Once all GPIO drivers are converted to driver model, we can change the
-        * code here to use the GPIO uclass interface instead of the numbered
-        * GPIO compatibility layer.
-        */
-       ret = gpio_lookup_name(str_gpio, NULL, NULL, &gpio);
-       if (ret) {
-               printf("GPIO: '%s' not found\n", str_gpio);
-               return cmd_process_error(cmdtp, ret);
-       }
-#else
-       /* turn the gpio name into a gpio number */
-       gpio = name_to_gpio(str_gpio);
-       if (gpio < 0)
-               goto show_usage;
-#endif
-       /* grab the pin before we tweak it */
-       ret = gpio_request(gpio, "cmd_gpio");
-       if (ret && ret != -EBUSY) {
-               printf("gpio: requesting pin %u failed\n", gpio);
-               return -1;
-       }
-
-       /* finally, let's do it: set direction and exec command */
-       if (sub_cmd == GPIO_INPUT) {
-               gpio_direction_input(gpio);
-               value = gpio_get_value(gpio);
-       } else {
-               switch (sub_cmd) {
-                       case GPIO_SET:    value = 1; break;
-                       case GPIO_CLEAR:  value = 0; break;
-                       case GPIO_TOGGLE: value = !gpio_get_value(gpio); break;
-                       default:          goto show_usage;
-               }
-               gpio_direction_output(gpio, value);
-       }
-       printf("gpio: pin %s (gpio %i) value is %lu\n",
-               str_gpio, gpio, value);
-
-       if (ret != -EBUSY)
-               gpio_free(gpio);
-
-       return value;
-}
-
-U_BOOT_CMD(gpio, 4, 0, do_gpio,
-          "query and control gpio pins",
-          "<input|set|clear|toggle> <pin>\n"
-          "    - input/set/clear/toggle the specified pin\n"
-          "gpio status [-a] [<bank> | <pin>]  - show [all/claimed] GPIOs");
diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
deleted file mode 100644 (file)
index d94d553..0000000
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * cmd_gpt.c -- GPT (GUID Partition Table) handling command
- *
- * Copyright (C) 2015
- * Lukasz Majewski <l.majewski@majess.pl>
- *
- * Copyright (C) 2012 Samsung Electronics
- * author: Lukasz Majewski <l.majewski@samsung.com>
- * author: Piotr Wilczek <p.wilczek@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <malloc.h>
-#include <command.h>
-#include <part_efi.h>
-#include <exports.h>
-#include <linux/ctype.h>
-#include <div64.h>
-#include <memalign.h>
-
-#ifndef CONFIG_PARTITION_UUIDS
-#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_GPT to be enabled
-#endif
-
-/**
- * extract_env(): Expand env name from string format '&{env_name}'
- *                and return pointer to the env (if the env is set)
- *
- * @param str - pointer to string
- * @param env - pointer to pointer to extracted env
- *
- * @return - zero on successful expand and env is set
- */
-static int extract_env(const char *str, char **env)
-{
-       int ret = -1;
-       char *e, *s;
-#ifdef CONFIG_RANDOM_UUID
-       char uuid_str[UUID_STR_LEN + 1];
-#endif
-
-       if (!str || strlen(str) < 4)
-               return -1;
-
-       if (!((strncmp(str, "${", 2) == 0) && (str[strlen(str) - 1] == '}')))
-               return -1;
-
-       s = strdup(str);
-       if (s == NULL)
-               return -1;
-
-       memset(s + strlen(s) - 1, '\0', 1);
-       memmove(s, s + 2, strlen(s) - 1);
-
-       e = getenv(s);
-       if (e == NULL) {
-#ifdef CONFIG_RANDOM_UUID
-               debug("%s unset. ", str);
-               gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_STD);
-               setenv(s, uuid_str);
-
-               e = getenv(s);
-               if (e) {
-                       debug("Set to random.\n");
-                       ret = 0;
-               } else {
-                       debug("Can't get random UUID.\n");
-               }
-#else
-               debug("%s unset.\n", str);
-#endif
-       } else {
-               debug("%s get from environment.\n", str);
-               ret = 0;
-       }
-
-       *env = e;
-       free(s);
-
-       return ret;
-}
-
-/**
- * extract_val(): Extract value from a key=value pair list (comma separated).
- *                Only value for the given key is returend.
- *                Function allocates memory for the value, remember to free!
- *
- * @param str - pointer to string with key=values pairs
- * @param key - pointer to the key to search for
- *
- * @return - pointer to allocated string with the value
- */
-static char *extract_val(const char *str, const char *key)
-{
-       char *v, *k;
-       char *s, *strcopy;
-       char *new = NULL;
-
-       strcopy = strdup(str);
-       if (strcopy == NULL)
-               return NULL;
-
-       s = strcopy;
-       while (s) {
-               v = strsep(&s, ",");
-               if (!v)
-                       break;
-               k = strsep(&v, "=");
-               if (!k)
-                       break;
-               if  (strcmp(k, key) == 0) {
-                       new = strdup(v);
-                       break;
-               }
-       }
-
-       free(strcopy);
-
-       return new;
-}
-
-/**
- * found_key(): Found key without value in parameter list (comma separated).
- *
- * @param str - pointer to string with key
- * @param key - pointer to the key to search for
- *
- * @return - true on found key
- */
-static bool found_key(const char *str, const char *key)
-{
-       char *k;
-       char *s, *strcopy;
-       bool result = false;
-
-       strcopy = strdup(str);
-       if (!strcopy)
-               return NULL;
-
-       s = strcopy;
-       while (s) {
-               k = strsep(&s, ",");
-               if (!k)
-                       break;
-               if  (strcmp(k, key) == 0) {
-                       result = true;
-                       break;
-               }
-       }
-
-       free(strcopy);
-
-       return result;
-}
-
-/**
- * set_gpt_info(): Fill partition information from string
- *             function allocates memory, remember to free!
- *
- * @param dev_desc - pointer block device descriptor
- * @param str_part - pointer to string with partition information
- * @param str_disk_guid - pointer to pointer to allocated string with disk guid
- * @param partitions - pointer to pointer to allocated partitions array
- * @param parts_count - number of partitions
- *
- * @return - zero on success, otherwise error
- *
- */
-static int set_gpt_info(block_dev_desc_t *dev_desc,
-                       const char *str_part,
-                       char **str_disk_guid,
-                       disk_partition_t **partitions,
-                       u8 *parts_count)
-{
-       char *tok, *str, *s;
-       int i;
-       char *val, *p;
-       int p_count;
-       disk_partition_t *parts;
-       int errno = 0;
-       uint64_t size_ll, start_ll;
-
-       debug("%s:  lba num: 0x%x %d\n", __func__,
-             (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba);
-
-       if (str_part == NULL)
-               return -1;
-
-       str = strdup(str_part);
-
-       /* extract disk guid */
-       s = str;
-       val = extract_val(str, "uuid_disk");
-       if (!val) {
-#ifdef CONFIG_RANDOM_UUID
-               *str_disk_guid = malloc(UUID_STR_LEN + 1);
-               gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
-#else
-               free(str);
-               return -2;
-#endif
-       } else {
-               val = strsep(&val, ";");
-               if (extract_env(val, &p))
-                       p = val;
-               *str_disk_guid = strdup(p);
-               free(val);
-               /* Move s to first partition */
-               strsep(&s, ";");
-       }
-       if (strlen(s) == 0)
-               return -3;
-
-       i = strlen(s) - 1;
-       if (s[i] == ';')
-               s[i] = '\0';
-
-       /* calculate expected number of partitions */
-       p_count = 1;
-       p = s;
-       while (*p) {
-               if (*p++ == ';')
-                       p_count++;
-       }
-
-       /* allocate memory for partitions */
-       parts = calloc(sizeof(disk_partition_t), p_count);
-
-       /* retrieve partitions data from string */
-       for (i = 0; i < p_count; i++) {
-               tok = strsep(&s, ";");
-
-               if (tok == NULL)
-                       break;
-
-               /* uuid */
-               val = extract_val(tok, "uuid");
-               if (!val) {
-                       /* 'uuid' is optional if random uuid's are enabled */
-#ifdef CONFIG_RANDOM_UUID
-                       gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD);
-#else
-                       errno = -4;
-                       goto err;
-#endif
-               } else {
-                       if (extract_env(val, &p))
-                               p = val;
-                       if (strlen(p) >= sizeof(parts[i].uuid)) {
-                               printf("Wrong uuid format for partition %d\n", i);
-                               errno = -4;
-                               goto err;
-                       }
-                       strcpy((char *)parts[i].uuid, p);
-                       free(val);
-               }
-#ifdef CONFIG_PARTITION_TYPE_GUID
-               /* guid */
-               val = extract_val(tok, "type");
-               if (val) {
-                       /* 'type' is optional */
-                       if (extract_env(val, &p))
-                               p = val;
-                       if (strlen(p) >= sizeof(parts[i].type_guid)) {
-                               printf("Wrong type guid format for partition %d\n",
-                                      i);
-                               errno = -4;
-                               goto err;
-                       }
-                       strcpy((char *)parts[i].type_guid, p);
-                       free(val);
-               }
-#endif
-               /* name */
-               val = extract_val(tok, "name");
-               if (!val) { /* name is mandatory */
-                       errno = -4;
-                       goto err;
-               }
-               if (extract_env(val, &p))
-                       p = val;
-               if (strlen(p) >= sizeof(parts[i].name)) {
-                       errno = -4;
-                       goto err;
-               }
-               strcpy((char *)parts[i].name, p);
-               free(val);
-
-               /* size */
-               val = extract_val(tok, "size");
-               if (!val) { /* 'size' is mandatory */
-                       errno = -4;
-                       goto err;
-               }
-               if (extract_env(val, &p))
-                       p = val;
-               size_ll = ustrtoull(p, &p, 0);
-               parts[i].size = lldiv(size_ll, dev_desc->blksz);
-               free(val);
-
-               /* start address */
-               val = extract_val(tok, "start");
-               if (val) { /* start address is optional */
-                       if (extract_env(val, &p))
-                               p = val;
-                       start_ll = ustrtoull(p, &p, 0);
-                       parts[i].start = lldiv(start_ll, dev_desc->blksz);
-                       free(val);
-               }
-
-               /* bootable */
-               if (found_key(tok, "bootable"))
-                       parts[i].bootable = 1;
-       }
-
-       *parts_count = p_count;
-       *partitions = parts;
-       free(str);
-
-       return 0;
-err:
-       free(str);
-       free(*str_disk_guid);
-       free(parts);
-
-       return errno;
-}
-
-static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
-{
-       int ret;
-       char *str_disk_guid;
-       u8 part_count = 0;
-       disk_partition_t *partitions = NULL;
-
-       /* fill partitions */
-       ret = set_gpt_info(blk_dev_desc, str_part,
-                       &str_disk_guid, &partitions, &part_count);
-       if (ret) {
-               if (ret == -1)
-                       printf("No partition list provided\n");
-               if (ret == -2)
-                       printf("Missing disk guid\n");
-               if ((ret == -3) || (ret == -4))
-                       printf("Partition list incomplete\n");
-               return -1;
-       }
-
-       /* save partitions layout to disk */
-       ret = gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
-       free(str_disk_guid);
-       free(partitions);
-
-       return ret;
-}
-
-static int gpt_verify(block_dev_desc_t *blk_dev_desc, const char *str_part)
-{
-       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
-                                    blk_dev_desc->blksz);
-       disk_partition_t *partitions = NULL;
-       gpt_entry *gpt_pte = NULL;
-       char *str_disk_guid;
-       u8 part_count = 0;
-       int ret = 0;
-
-       /* fill partitions */
-       ret = set_gpt_info(blk_dev_desc, str_part,
-                       &str_disk_guid, &partitions, &part_count);
-       if (ret) {
-               if (ret == -1) {
-                       printf("No partition list provided - only basic check\n");
-                       ret = gpt_verify_headers(blk_dev_desc, gpt_head,
-                                                &gpt_pte);
-                       goto out;
-               }
-               if (ret == -2)
-                       printf("Missing disk guid\n");
-               if ((ret == -3) || (ret == -4))
-                       printf("Partition list incomplete\n");
-               return -1;
-       }
-
-       /* Check partition layout with provided pattern */
-       ret = gpt_verify_partitions(blk_dev_desc, partitions, part_count,
-                                   gpt_head, &gpt_pte);
-       free(str_disk_guid);
-       free(partitions);
- out:
-       free(gpt_pte);
-       return ret;
-}
-
-/**
- * do_gpt(): Perform GPT operations
- *
- * @param cmdtp - command name
- * @param flag
- * @param argc
- * @param argv
- *
- * @return zero on success; otherwise error
- */
-static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret = CMD_RET_SUCCESS;
-       int dev = 0;
-       char *ep;
-       block_dev_desc_t *blk_dev_desc = NULL;
-
-       if (argc < 4 || argc > 5)
-               return CMD_RET_USAGE;
-
-       dev = (int)simple_strtoul(argv[3], &ep, 10);
-       if (!ep || ep[0] != '\0') {
-               printf("'%s' is not a number\n", argv[3]);
-               return CMD_RET_USAGE;
-       }
-       blk_dev_desc = get_dev(argv[2], dev);
-       if (!blk_dev_desc) {
-               printf("%s: %s dev %d NOT available\n",
-                      __func__, argv[2], dev);
-               return CMD_RET_FAILURE;
-       }
-
-       if ((strcmp(argv[1], "write") == 0) && (argc == 5)) {
-               printf("Writing GPT: ");
-               ret = gpt_default(blk_dev_desc, argv[4]);
-       } else if ((strcmp(argv[1], "verify") == 0)) {
-               ret = gpt_verify(blk_dev_desc, argv[4]);
-               printf("Verify GPT: ");
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       if (ret) {
-               printf("error!\n");
-               return CMD_RET_FAILURE;
-       }
-
-       printf("success!\n");
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
-       "GUID Partition Table",
-       "<command> <interface> <dev> <partitions_list>\n"
-       " - GUID partition table restoration and validity check\n"
-       " Restore or verify GPT information on a device connected\n"
-       " to interface\n"
-       " Example usage:\n"
-       " gpt write mmc 0 $partitions\n"
-       " gpt verify mmc 0 $partitions\n"
-);
diff --git a/common/cmd_hash.c b/common/cmd_hash.c
deleted file mode 100644 (file)
index 704d21e..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2012 The Chromium OS Authors.
- *
- * (C) Copyright 2011
- * Joe Hershberger, National Instruments, joe.hershberger@ni.com
- *
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <hash.h>
-#include <linux/ctype.h>
-
-static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *s;
-       int flags = HASH_FLAG_ENV;
-
-#ifdef CONFIG_HASH_VERIFY
-       if (argc < 4)
-               return CMD_RET_USAGE;
-       if (!strcmp(argv[1], "-v")) {
-               flags |= HASH_FLAG_VERIFY;
-               argc--;
-               argv++;
-       }
-#endif
-       /* Move forward to 'algorithm' parameter */
-       argc--;
-       argv++;
-       for (s = *argv; *s; s++)
-               *s = tolower(*s);
-       return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
-}
-
-#ifdef CONFIG_HASH_VERIFY
-#define HARGS 6
-#else
-#define HARGS 5
-#endif
-
-U_BOOT_CMD(
-       hash,   HARGS,  1,      do_hash,
-       "compute hash message digest",
-       "algorithm address count [[*]hash_dest]\n"
-               "    - compute message digest [save to env var / *address]"
-#ifdef CONFIG_HASH_VERIFY
-       "\nhash -v algorithm address count [*]hash\n"
-               "    - verify message digest of memory area to immediate value, \n"
-               "      env var or *address"
-#endif
-);
diff --git a/common/cmd_help.c b/common/cmd_help.c
deleted file mode 100644 (file)
index 6ff494d..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
-       const int len = ll_entry_count(cmd_tbl_t, cmd);
-       return _do_help(start, len, cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(
-       help,   CONFIG_SYS_MAXARGS,     1,      do_help,
-       "print command description/usage",
-       "\n"
-       "       - print brief description of all commands\n"
-       "help command ...\n"
-       "       - print detailed usage of 'command'"
-);
-
-/* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */
-ll_entry_declare(cmd_tbl_t, question_mark, cmd) = {
-       "?",    CONFIG_SYS_MAXARGS,     1,      do_help,
-       "alias for 'help'",
-#ifdef  CONFIG_SYS_LONGHELP
-       ""
-#endif /* CONFIG_SYS_LONGHELP */
-};
diff --git a/common/cmd_host.c b/common/cmd_host.c
deleted file mode 100644 (file)
index ba1460e..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2012, Google Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <fs.h>
-#include <part.h>
-#include <sandboxblockdev.h>
-#include <asm/errno.h>
-
-static int host_curr_device = -1;
-
-static int do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
-{
-       return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
-}
-
-static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
-{
-       return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
-}
-
-static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
-{
-       return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
-}
-
-static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
-{
-       if (argc < 2 || argc > 3)
-               return CMD_RET_USAGE;
-       char *ep;
-       char *dev_str = argv[1];
-       char *file = argc >= 3 ? argv[2] : NULL;
-       int dev = simple_strtoul(dev_str, &ep, 16);
-       if (*ep) {
-               printf("** Bad device specification %s **\n", dev_str);
-               return CMD_RET_USAGE;
-       }
-       return host_dev_bind(dev, file);
-}
-
-static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
-{
-       if (argc < 1 || argc > 2)
-               return CMD_RET_USAGE;
-       int min_dev = 0;
-       int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
-       if (argc >= 2) {
-               char *ep;
-               char *dev_str = argv[1];
-               int dev = simple_strtoul(dev_str, &ep, 16);
-               if (*ep) {
-                       printf("** Bad device specification %s **\n", dev_str);
-                       return CMD_RET_USAGE;
-               }
-               min_dev = dev;
-               max_dev = dev;
-       }
-       int dev;
-       printf("%3s %12s %s\n", "dev", "blocks", "path");
-       for (dev = min_dev; dev <= max_dev; dev++) {
-               block_dev_desc_t *blk_dev;
-               int ret;
-
-               printf("%3d ", dev);
-               ret = host_get_dev_err(dev, &blk_dev);
-               if (ret) {
-                       if (ret == -ENOENT)
-                               puts("Not bound to a backing file\n");
-                       else if (ret == -ENODEV)
-                               puts("Invalid host device number\n");
-
-                       continue;
-               }
-               struct host_block_dev *host_dev = blk_dev->priv;
-               printf("%12lu %s\n", (unsigned long)blk_dev->lba,
-                      host_dev->filename);
-       }
-       return 0;
-}
-
-static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       int dev;
-       char *ep;
-       block_dev_desc_t *blk_dev;
-       int ret;
-
-       if (argc < 1 || argc > 3)
-               return CMD_RET_USAGE;
-
-       if (argc == 1) {
-               if (host_curr_device < 0) {
-                       printf("No current host device\n");
-                       return 1;
-               }
-               printf("Current host device %d\n", host_curr_device);
-               return 0;
-       }
-
-       dev = simple_strtoul(argv[1], &ep, 16);
-       if (*ep) {
-               printf("** Bad device specification %s **\n", argv[2]);
-               return CMD_RET_USAGE;
-       }
-
-       ret = host_get_dev_err(dev, &blk_dev);
-       if (ret) {
-               if (ret == -ENOENT)
-                       puts("Not bound to a backing file\n");
-               else if (ret == -ENODEV)
-                       puts("Invalid host device number\n");
-
-               return 1;
-       }
-
-       host_curr_device = dev;
-       return 0;
-}
-
-static cmd_tbl_t cmd_host_sub[] = {
-       U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
-       U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
-       U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
-       U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
-       U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
-       U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
-};
-
-static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
-                     char * const argv[])
-{
-       cmd_tbl_t *c;
-
-       /* Skip past 'host' */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], cmd_host_sub,
-                        ARRAY_SIZE(cmd_host_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       sb,     8,      1,      do_host,
-       "Deprecated: use 'host' command instead.", ""
-);
-
-U_BOOT_CMD(
-       host, 8, 1, do_host,
-       "Miscellaneous host commands",
-       "load hostfs - <addr> <filename> [<bytes> <offset>]  - "
-               "load a file from host\n"
-       "host ls hostfs - <filename>                    - list files on host\n"
-       "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
-               "save a file to host\n"
-       "host bind <dev> [<filename>] - bind \"host\" device to file\n"
-       "host info [<dev>]            - show device binding & info\n"
-       "host dev [<dev>] - Set or retrieve the current host device\n"
-       "host commands use the \"hostfs\" device. The \"host\" device is used\n"
-       "with standard IO commands such as fatls or ext2load"
-);
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
deleted file mode 100644 (file)
index b3bb644..0000000
+++ /dev/null
@@ -1,2030 +0,0 @@
-/*
- * (C) Copyright 2009
- * Sergey Kubushyn, himself, ksi@koi8.net
- *
- * Changes for unified multibus/multiadapter I2C support.
- *
- * (C) Copyright 2001
- * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * I2C Functions similar to the standard memory functions.
- *
- * There are several parameters in many of the commands that bear further
- * explanations:
- *
- * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
- *   Each I2C chip on the bus has a unique address.  On the I2C data bus,
- *   the address is the upper seven bits and the LSB is the "read/write"
- *   bit.  Note that the {i2c_chip} address specified on the command
- *   line is not shifted up: e.g. a typical EEPROM memory chip may have
- *   an I2C address of 0x50, but the data put on the bus will be 0xA0
- *   for write and 0xA1 for read.  This "non shifted" address notation
- *   matches at least half of the data sheets :-/.
- *
- * {addr} is the address (or offset) within the chip.  Small memory
- *   chips have 8 bit addresses.  Large memory chips have 16 bit
- *   addresses.  Other memory chips have 9, 10, or 11 bit addresses.
- *   Many non-memory chips have multiple registers and {addr} is used
- *   as the register index.  Some non-memory chips have only one register
- *   and therefore don't need any {addr} parameter.
- *
- *   The default {addr} parameter is one byte (.1) which works well for
- *   memories and registers with 8 bits of address space.
- *
- *   You can specify the length of the {addr} field with the optional .0,
- *   .1, or .2 modifier (similar to the .b, .w, .l modifier).  If you are
- *   manipulating a single register device which doesn't use an address
- *   field, use "0.0" for the address and the ".0" length field will
- *   suppress the address in the I2C data stream.  This also works for
- *   successive reads using the I2C auto-incrementing memory pointer.
- *
- *   If you are manipulating a large memory with 2-byte addresses, use
- *   the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
- *
- *   Then there are the unfortunate memory chips that spill the most
- *   significant 1, 2, or 3 bits of address into the chip address byte.
- *   This effectively makes one chip (logically) look like 2, 4, or
- *   8 chips.  This is handled (awkwardly) by #defining
- *   CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
- *   {addr} field (since .1 is the default, it doesn't actually have to
- *   be specified).  Examples: given a memory chip at I2C chip address
- *   0x50, the following would happen...
- *     i2c md 50 0 10   display 16 bytes starting at 0x000
- *                      On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
- *     i2c md 50 100 10 display 16 bytes starting at 0x100
- *                      On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
- *     i2c md 50 210 10 display 16 bytes starting at 0x210
- *                      On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
- *   This is awfully ugly.  It would be nice if someone would think up
- *   a better way of handling this.
- *
- * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
- */
-
-#include <common.h>
-#include <bootretry.h>
-#include <cli.h>
-#include <command.h>
-#include <console.h>
-#include <dm.h>
-#include <edid.h>
-#include <environment.h>
-#include <errno.h>
-#include <i2c.h>
-#include <malloc.h>
-#include <asm/byteorder.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/* Display values from last command.
- * Memory modify remembered values are different from display memory.
- */
-static uint    i2c_dp_last_chip;
-static uint    i2c_dp_last_addr;
-static uint    i2c_dp_last_alen;
-static uint    i2c_dp_last_length = 0x10;
-
-static uint    i2c_mm_last_chip;
-static uint    i2c_mm_last_addr;
-static uint    i2c_mm_last_alen;
-
-/* If only one I2C bus is present, the list of devices to ignore when
- * the probe command is issued is represented by a 1D array of addresses.
- * When multiple buses are present, the list is an array of bus-address
- * pairs.  The following macros take care of this */
-
-#if defined(CONFIG_SYS_I2C_NOPROBES)
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
-static struct
-{
-       uchar   bus;
-       uchar   addr;
-} i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
-#define GET_BUS_NUM    i2c_get_bus_num()
-#define COMPARE_BUS(b,i)       (i2c_no_probes[(i)].bus == (b))
-#define COMPARE_ADDR(a,i)      (i2c_no_probes[(i)].addr == (a))
-#define NO_PROBE_ADDR(i)       i2c_no_probes[(i)].addr
-#else          /* single bus */
-static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
-#define GET_BUS_NUM    0
-#define COMPARE_BUS(b,i)       ((b) == 0)      /* Make compiler happy */
-#define COMPARE_ADDR(a,i)      (i2c_no_probes[(i)] == (a))
-#define NO_PROBE_ADDR(i)       i2c_no_probes[(i)]
-#endif /* defined(CONFIG_SYS_I2C) */
-#endif
-
-#define DISP_LINE_LEN  16
-
-/*
- * Default for driver model is to use the chip's existing address length.
- * For legacy code, this is not stored, so we need to use a suitable
- * default.
- */
-#ifdef CONFIG_DM_I2C
-#define DEFAULT_ADDR_LEN       (-1)
-#else
-#define DEFAULT_ADDR_LEN       1
-#endif
-
-#ifdef CONFIG_DM_I2C
-static struct udevice *i2c_cur_bus;
-
-static int cmd_i2c_set_bus_num(unsigned int busnum)
-{
-       struct udevice *bus;
-       int ret;
-
-       ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
-       if (ret) {
-               debug("%s: No bus %d\n", __func__, busnum);
-               return ret;
-       }
-       i2c_cur_bus = bus;
-
-       return 0;
-}
-
-static int i2c_get_cur_bus(struct udevice **busp)
-{
-       if (!i2c_cur_bus) {
-               puts("No I2C bus selected\n");
-               return -ENODEV;
-       }
-       *busp = i2c_cur_bus;
-
-       return 0;
-}
-
-static int i2c_get_cur_bus_chip(uint chip_addr, struct udevice **devp)
-{
-       struct udevice *bus;
-       int ret;
-
-       ret = i2c_get_cur_bus(&bus);
-       if (ret)
-               return ret;
-
-       return i2c_get_chip(bus, chip_addr, 1, devp);
-}
-
-#endif
-
-/**
- * i2c_init_board() - Board-specific I2C bus init
- *
- * This function is the default no-op implementation of I2C bus
- * initialization. This function can be overriden by board-specific
- * implementation if needed.
- */
-__weak
-void i2c_init_board(void)
-{
-}
-
-/* TODO: Implement architecture-specific get/set functions */
-
-/**
- * i2c_get_bus_speed() - Return I2C bus speed
- *
- * This function is the default implementation of function for retrieveing
- * the current I2C bus speed in Hz.
- *
- * A driver implementing runtime switching of I2C bus speed must override
- * this function to report the speed correctly. Simple or legacy drivers
- * can use this fallback.
- *
- * Returns I2C bus speed in Hz.
- */
-#if !defined(CONFIG_SYS_I2C) && !defined(CONFIG_DM_I2C)
-/*
- * TODO: Implement architecture-specific get/set functions
- * Should go away, if we switched completely to new multibus support
- */
-__weak
-unsigned int i2c_get_bus_speed(void)
-{
-       return CONFIG_SYS_I2C_SPEED;
-}
-
-/**
- * i2c_set_bus_speed() - Configure I2C bus speed
- * @speed:     Newly set speed of the I2C bus in Hz
- *
- * This function is the default implementation of function for setting
- * the I2C bus speed in Hz.
- *
- * A driver implementing runtime switching of I2C bus speed must override
- * this function to report the speed correctly. Simple or legacy drivers
- * can use this fallback.
- *
- * Returns zero on success, negative value on error.
- */
-__weak
-int i2c_set_bus_speed(unsigned int speed)
-{
-       if (speed != CONFIG_SYS_I2C_SPEED)
-               return -1;
-
-       return 0;
-}
-#endif
-
-/**
- * get_alen() - Small parser helper function to get address length
- *
- * Returns the address length.
- */
-static uint get_alen(char *arg, int default_len)
-{
-       int     j;
-       int     alen;
-
-       alen = default_len;
-       for (j = 0; j < 8; j++) {
-               if (arg[j] == '.') {
-                       alen = arg[j+1] - '0';
-                       break;
-               } else if (arg[j] == '\0')
-                       break;
-       }
-       return alen;
-}
-
-enum i2c_err_op {
-       I2C_ERR_READ,
-       I2C_ERR_WRITE,
-};
-
-static int i2c_report_err(int ret, enum i2c_err_op op)
-{
-       printf("Error %s the chip: %d\n",
-              op == I2C_ERR_READ ? "reading" : "writing", ret);
-
-       return CMD_RET_FAILURE;
-}
-
-/**
- * do_i2c_read() - Handle the "i2c read" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
- */
-static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       uint    devaddr, length;
-       int alen;
-       u_char  *memaddr;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-
-       /*
-        * I2C chip address
-        */
-       chip = simple_strtoul(argv[1], NULL, 16);
-
-       /*
-        * I2C data address within the chip.  This can be 1 or
-        * 2 bytes long.  Some day it might be 3 bytes long :-).
-        */
-       devaddr = simple_strtoul(argv[2], NULL, 16);
-       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-       if (alen > 3)
-               return CMD_RET_USAGE;
-
-       /*
-        * Length is the number of objects, not number of bytes.
-        */
-       length = simple_strtoul(argv[3], NULL, 16);
-
-       /*
-        * memaddr is the address where to store things in memory
-        */
-       memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (!ret)
-               ret = dm_i2c_read(dev, devaddr, memaddr, length);
-#else
-       ret = i2c_read(chip, devaddr, alen, memaddr, length);
-#endif
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       return 0;
-}
-
-static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       uint    devaddr, length;
-       int alen;
-       u_char  *memaddr;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-       struct dm_i2c_chip *i2c_chip;
-#endif
-
-       if ((argc < 5) || (argc > 6))
-               return cmd_usage(cmdtp);
-
-       /*
-        * memaddr is the address where to store things in memory
-        */
-       memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
-
-       /*
-        * I2C chip address
-        */
-       chip = simple_strtoul(argv[2], NULL, 16);
-
-       /*
-        * I2C data address within the chip.  This can be 1 or
-        * 2 bytes long.  Some day it might be 3 bytes long :-).
-        */
-       devaddr = simple_strtoul(argv[3], NULL, 16);
-       alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
-       if (alen > 3)
-               return cmd_usage(cmdtp);
-
-       /*
-        * Length is the number of bytes.
-        */
-       length = simple_strtoul(argv[4], NULL, 16);
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_WRITE);
-       i2c_chip = dev_get_parent_platdata(dev);
-       if (!i2c_chip)
-               return i2c_report_err(ret, I2C_ERR_WRITE);
-#endif
-
-       if (argc == 6 && !strcmp(argv[5], "-s")) {
-               /*
-                * Write all bytes in a single I2C transaction. If the target
-                * device is an EEPROM, it is your responsibility to not cross
-                * a page boundary. No write delay upon completion, take this
-                * into account if linking commands.
-                */
-#ifdef CONFIG_DM_I2C
-               i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS;
-               ret = dm_i2c_write(dev, devaddr, memaddr, length);
-#else
-               ret = i2c_write(chip, devaddr, alen, memaddr, length);
-#endif
-               if (ret)
-                       return i2c_report_err(ret, I2C_ERR_WRITE);
-       } else {
-               /*
-                * Repeated addressing - perform <length> separate
-                * write transactions of one byte each
-                */
-               while (length-- > 0) {
-#ifdef CONFIG_DM_I2C
-                       i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS;
-                       ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
-#else
-                       ret = i2c_write(chip, devaddr++, alen, memaddr++, 1);
-#endif
-                       if (ret)
-                               return i2c_report_err(ret, I2C_ERR_WRITE);
-/*
- * No write delay with FRAM devices.
- */
-#if !defined(CONFIG_SYS_I2C_FRAM)
-                       udelay(11000);
-#endif
-               }
-       }
-       return 0;
-}
-
-#ifdef CONFIG_DM_I2C
-static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char *const argv[])
-{
-       struct udevice *dev;
-       uint flags;
-       int chip;
-       int ret;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       chip = simple_strtoul(argv[1], NULL, 16);
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       if (argc > 2) {
-               flags = simple_strtoul(argv[2], NULL, 16);
-               ret = i2c_set_chip_flags(dev, flags);
-       } else  {
-               ret = i2c_get_chip_flags(dev, &flags);
-               if (!ret)
-                       printf("%x\n", flags);
-       }
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       return 0;
-}
-
-static int do_i2c_olen(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       struct udevice *dev;
-       uint olen;
-       int chip;
-       int ret;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       chip = simple_strtoul(argv[1], NULL, 16);
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       if (argc > 2) {
-               olen = simple_strtoul(argv[2], NULL, 16);
-               ret = i2c_set_chip_offset_len(dev, olen);
-       } else  {
-               ret = i2c_get_chip_offset_len(dev);
-               if (ret >= 0) {
-                       printf("%x\n", ret);
-                       ret = 0;
-               }
-       }
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       return 0;
-}
-#endif
-
-/**
- * do_i2c_md() - Handle the "i2c md" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
- */
-static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       uint    addr, length;
-       int alen;
-       int     j, nbytes, linebytes;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       /* We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       chip   = i2c_dp_last_chip;
-       addr   = i2c_dp_last_addr;
-       alen   = i2c_dp_last_alen;
-       length = i2c_dp_last_length;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /*
-                * New command specified.
-                */
-
-               /*
-                * I2C chip address
-                */
-               chip = simple_strtoul(argv[1], NULL, 16);
-
-               /*
-                * I2C data address within the chip.  This can be 1 or
-                * 2 bytes long.  Some day it might be 3 bytes long :-).
-                */
-               addr = simple_strtoul(argv[2], NULL, 16);
-               alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-               if (alen > 3)
-                       return CMD_RET_USAGE;
-
-               /*
-                * If another parameter, it is the length to display.
-                * Length is the number of objects, not number of bytes.
-                */
-               if (argc > 3)
-                       length = simple_strtoul(argv[3], NULL, 16);
-       }
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-#endif
-
-       /*
-        * Print the lines.
-        *
-        * We buffer all read data, so we can make sure data is read only
-        * once.
-        */
-       nbytes = length;
-       do {
-               unsigned char   linebuf[DISP_LINE_LEN];
-               unsigned char   *cp;
-
-               linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
-
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_read(dev, addr, linebuf, linebytes);
-#else
-               ret = i2c_read(chip, addr, alen, linebuf, linebytes);
-#endif
-               if (ret)
-                       return i2c_report_err(ret, I2C_ERR_READ);
-               else {
-                       printf("%04x:", addr);
-                       cp = linebuf;
-                       for (j=0; j<linebytes; j++) {
-                               printf(" %02x", *cp++);
-                               addr++;
-                       }
-                       puts ("    ");
-                       cp = linebuf;
-                       for (j=0; j<linebytes; j++) {
-                               if ((*cp < 0x20) || (*cp > 0x7e))
-                                       puts (".");
-                               else
-                                       printf("%c", *cp);
-                               cp++;
-                       }
-                       putc ('\n');
-               }
-               nbytes -= linebytes;
-       } while (nbytes > 0);
-
-       i2c_dp_last_chip   = chip;
-       i2c_dp_last_addr   = addr;
-       i2c_dp_last_alen   = alen;
-       i2c_dp_last_length = length;
-
-       return 0;
-}
-
-/**
- * do_i2c_mw() - Handle the "i2c mw" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
- */
-static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       ulong   addr;
-       int     alen;
-       uchar   byte;
-       int     count;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if ((argc < 4) || (argc > 5))
-               return CMD_RET_USAGE;
-
-       /*
-        * Chip is always specified.
-        */
-       chip = simple_strtoul(argv[1], NULL, 16);
-
-       /*
-        * Address is always specified.
-        */
-       addr = simple_strtoul(argv[2], NULL, 16);
-       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-       if (alen > 3)
-               return CMD_RET_USAGE;
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_WRITE);
-#endif
-       /*
-        * Value to write is always specified.
-        */
-       byte = simple_strtoul(argv[3], NULL, 16);
-
-       /*
-        * Optional count
-        */
-       if (argc == 5)
-               count = simple_strtoul(argv[4], NULL, 16);
-       else
-               count = 1;
-
-       while (count-- > 0) {
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_write(dev, addr++, &byte, 1);
-#else
-               ret = i2c_write(chip, addr++, alen, &byte, 1);
-#endif
-               if (ret)
-                       return i2c_report_err(ret, I2C_ERR_WRITE);
-               /*
-                * Wait for the write to complete.  The write can take
-                * up to 10mSec (we allow a little more time).
-                */
-/*
- * No write delay with FRAM devices.
- */
-#if !defined(CONFIG_SYS_I2C_FRAM)
-               udelay(11000);
-#endif
-       }
-
-       return 0;
-}
-
-/**
- * do_i2c_crc() - Handle the "i2c crc32" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Calculate a CRC on memory
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
- */
-static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       ulong   addr;
-       int     alen;
-       int     count;
-       uchar   byte;
-       ulong   crc;
-       ulong   err;
-       int ret = 0;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       /*
-        * Chip is always specified.
-        */
-       chip = simple_strtoul(argv[1], NULL, 16);
-
-       /*
-        * Address is always specified.
-        */
-       addr = simple_strtoul(argv[2], NULL, 16);
-       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-       if (alen > 3)
-               return CMD_RET_USAGE;
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-#endif
-       /*
-        * Count is always specified
-        */
-       count = simple_strtoul(argv[3], NULL, 16);
-
-       printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
-       /*
-        * CRC a byte at a time.  This is going to be slooow, but hey, the
-        * memories are small and slow too so hopefully nobody notices.
-        */
-       crc = 0;
-       err = 0;
-       while (count-- > 0) {
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_read(dev, addr, &byte, 1);
-#else
-               ret = i2c_read(chip, addr, alen, &byte, 1);
-#endif
-               if (ret)
-                       err++;
-               crc = crc32 (crc, &byte, 1);
-               addr++;
-       }
-       if (err > 0)
-               i2c_report_err(ret, I2C_ERR_READ);
-       else
-               printf ("%08lx\n", crc);
-
-       return 0;
-}
-
-/**
- * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Modify memory.
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
- *     i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
- */
-static int
-mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       ulong   addr;
-       int     alen;
-       ulong   data;
-       int     size = 1;
-       int     nbytes;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       bootretry_reset_cmd_timeout();  /* got a good command to get here */
-       /*
-        * We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       chip = i2c_mm_last_chip;
-       addr = i2c_mm_last_addr;
-       alen = i2c_mm_last_alen;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /*
-                * New command specified.  Check for a size specification.
-                * Defaults to byte if no or incorrect specification.
-                */
-               size = cmd_get_data_size(argv[0], 1);
-
-               /*
-                * Chip is always specified.
-                */
-               chip = simple_strtoul(argv[1], NULL, 16);
-
-               /*
-                * Address is always specified.
-                */
-               addr = simple_strtoul(argv[2], NULL, 16);
-               alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-               if (alen > 3)
-                       return CMD_RET_USAGE;
-       }
-
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_WRITE);
-#endif
-
-       /*
-        * Print the address, followed by value.  Then accept input for
-        * the next value.  A non-converted value exits.
-        */
-       do {
-               printf("%08lx:", addr);
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
-#else
-               ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
-#endif
-               if (ret)
-                       return i2c_report_err(ret, I2C_ERR_READ);
-
-               data = cpu_to_be32(data);
-               if (size == 1)
-                       printf(" %02lx", (data >> 24) & 0x000000FF);
-               else if (size == 2)
-                       printf(" %04lx", (data >> 16) & 0x0000FFFF);
-               else
-                       printf(" %08lx", data);
-
-               nbytes = cli_readline(" ? ");
-               if (nbytes == 0) {
-                       /*
-                        * <CR> pressed as only input, don't modify current
-                        * location and move to next.
-                        */
-                       if (incrflag)
-                               addr += size;
-                       nbytes = size;
-                       /* good enough to not time out */
-                       bootretry_reset_cmd_timeout();
-               }
-#ifdef CONFIG_BOOT_RETRY_TIME
-               else if (nbytes == -2)
-                       break;  /* timed out, exit the command  */
-#endif
-               else {
-                       char *endp;
-
-                       data = simple_strtoul(console_buffer, &endp, 16);
-                       if (size == 1)
-                               data = data << 24;
-                       else if (size == 2)
-                               data = data << 16;
-                       data = be32_to_cpu(data);
-                       nbytes = endp - console_buffer;
-                       if (nbytes) {
-                               /*
-                                * good enough to not time out
-                                */
-                               bootretry_reset_cmd_timeout();
-#ifdef CONFIG_DM_I2C
-                               ret = dm_i2c_write(dev, addr, (uchar *)&data,
-                                                  size);
-#else
-                               ret = i2c_write(chip, addr, alen,
-                                               (uchar *)&data, size);
-#endif
-                               if (ret)
-                                       return i2c_report_err(ret,
-                                                             I2C_ERR_WRITE);
-#ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
-                               udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-#endif
-                               if (incrflag)
-                                       addr += size;
-                       }
-               }
-       } while (nbytes);
-
-       i2c_mm_last_chip = chip;
-       i2c_mm_last_addr = addr;
-       i2c_mm_last_alen = alen;
-
-       return 0;
-}
-
-/**
- * do_i2c_probe() - Handle the "i2c probe" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c probe {addr}
- *
- * Returns zero (success) if one or more I2C devices was found
- */
-static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int j;
-       int addr = -1;
-       int found = 0;
-#if defined(CONFIG_SYS_I2C_NOPROBES)
-       int k, skip;
-       unsigned int bus = GET_BUS_NUM;
-#endif /* NOPROBES */
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *bus, *dev;
-
-       if (i2c_get_cur_bus(&bus))
-               return CMD_RET_FAILURE;
-#endif
-
-       if (argc == 2)
-               addr = simple_strtol(argv[1], 0, 16);
-
-       puts ("Valid chip addresses:");
-       for (j = 0; j < 128; j++) {
-               if ((0 <= addr) && (j != addr))
-                       continue;
-
-#if defined(CONFIG_SYS_I2C_NOPROBES)
-               skip = 0;
-               for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
-                       if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
-                               skip = 1;
-                               break;
-                       }
-               }
-               if (skip)
-                       continue;
-#endif
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_probe(bus, j, 0, &dev);
-#else
-               ret = i2c_probe(j);
-#endif
-               if (ret == 0) {
-                       printf(" %02X", j);
-                       found++;
-               }
-       }
-       putc ('\n');
-
-#if defined(CONFIG_SYS_I2C_NOPROBES)
-       puts ("Excluded chip addresses:");
-       for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
-               if (COMPARE_BUS(bus,k))
-                       printf(" %02X", NO_PROBE_ADDR(k));
-       }
-       putc ('\n');
-#endif
-
-       return (0 == found);
-}
-
-/**
- * do_i2c_loop() - Handle the "i2c loop" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- *
- * Syntax:
- *     i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
- *     {length} - Number of bytes to read
- *     {delay}  - A DECIMAL number and defaults to 1000 uSec
- */
-static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint    chip;
-       int alen;
-       uint    addr;
-       uint    length;
-       u_char  bytes[16];
-       int     delay;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       /*
-        * Chip is always specified.
-        */
-       chip = simple_strtoul(argv[1], NULL, 16);
-
-       /*
-        * Address is always specified.
-        */
-       addr = simple_strtoul(argv[2], NULL, 16);
-       alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
-       if (alen > 3)
-               return CMD_RET_USAGE;
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret && alen != -1)
-               ret = i2c_set_chip_offset_len(dev, alen);
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_WRITE);
-#endif
-
-       /*
-        * Length is the number of objects, not number of bytes.
-        */
-       length = 1;
-       length = simple_strtoul(argv[3], NULL, 16);
-       if (length > sizeof(bytes))
-               length = sizeof(bytes);
-
-       /*
-        * The delay time (uSec) is optional.
-        */
-       delay = 1000;
-       if (argc > 3)
-               delay = simple_strtoul(argv[4], NULL, 10);
-       /*
-        * Run the loop...
-        */
-       while (1) {
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_read(dev, addr, bytes, length);
-#else
-               ret = i2c_read(chip, addr, alen, bytes, length);
-#endif
-               if (ret)
-                       i2c_report_err(ret, I2C_ERR_READ);
-               udelay(delay);
-       }
-
-       /* NOTREACHED */
-       return 0;
-}
-
-/*
- * The SDRAM command is separately configured because many
- * (most?) embedded boards don't use SDRAM DIMMs.
- *
- * FIXME: Document and probably move elsewhere!
- */
-#if defined(CONFIG_CMD_SDRAM)
-static void print_ddr2_tcyc (u_char const b)
-{
-       printf ("%d.", (b >> 4) & 0x0F);
-       switch (b & 0x0F) {
-       case 0x0:
-       case 0x1:
-       case 0x2:
-       case 0x3:
-       case 0x4:
-       case 0x5:
-       case 0x6:
-       case 0x7:
-       case 0x8:
-       case 0x9:
-               printf ("%d ns\n", b & 0x0F);
-               break;
-       case 0xA:
-               puts ("25 ns\n");
-               break;
-       case 0xB:
-               puts ("33 ns\n");
-               break;
-       case 0xC:
-               puts ("66 ns\n");
-               break;
-       case 0xD:
-               puts ("75 ns\n");
-               break;
-       default:
-               puts ("?? ns\n");
-               break;
-       }
-}
-
-static void decode_bits (u_char const b, char const *str[], int const do_once)
-{
-       u_char mask;
-
-       for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
-               if (b & mask) {
-                       puts (*str);
-                       if (do_once)
-                               return;
-               }
-       }
-}
-
-/*
- * Syntax:
- *     i2c sdram {i2c_chip}
- */
-static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       enum { unknown, EDO, SDRAM, DDR2 } type;
-
-       uint    chip;
-       u_char  data[128];
-       u_char  cksum;
-       int     j;
-
-       static const char *decode_CAS_DDR2[] = {
-               " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
-       };
-
-       static const char *decode_CAS_default[] = {
-               " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
-       };
-
-       static const char *decode_CS_WE_default[] = {
-               " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
-       };
-
-       static const char *decode_byte21_default[] = {
-               "  TBD (bit 7)\n",
-               "  Redundant row address\n",
-               "  Differential clock input\n",
-               "  Registerd DQMB inputs\n",
-               "  Buffered DQMB inputs\n",
-               "  On-card PLL\n",
-               "  Registered address/control lines\n",
-               "  Buffered address/control lines\n"
-       };
-
-       static const char *decode_byte22_DDR2[] = {
-               "  TBD (bit 7)\n",
-               "  TBD (bit 6)\n",
-               "  TBD (bit 5)\n",
-               "  TBD (bit 4)\n",
-               "  TBD (bit 3)\n",
-               "  Supports partial array self refresh\n",
-               "  Supports 50 ohm ODT\n",
-               "  Supports weak driver\n"
-       };
-
-       static const char *decode_row_density_DDR2[] = {
-               "512 MiB", "256 MiB", "128 MiB", "16 GiB",
-               "8 GiB", "4 GiB", "2 GiB", "1 GiB"
-       };
-
-       static const char *decode_row_density_default[] = {
-               "512 MiB", "256 MiB", "128 MiB", "64 MiB",
-               "32 MiB", "16 MiB", "8 MiB", "4 MiB"
-       };
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /*
-        * Chip is always specified.
-        */
-       chip = simple_strtoul (argv[1], NULL, 16);
-
-       if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) {
-               puts ("No SDRAM Serial Presence Detect found.\n");
-               return 1;
-       }
-
-       cksum = 0;
-       for (j = 0; j < 63; j++) {
-               cksum += data[j];
-       }
-       if (cksum != data[63]) {
-               printf ("WARNING: Configuration data checksum failure:\n"
-                       "  is 0x%02x, calculated 0x%02x\n", data[63], cksum);
-       }
-       printf ("SPD data revision            %d.%d\n",
-               (data[62] >> 4) & 0x0F, data[62] & 0x0F);
-       printf ("Bytes used                   0x%02X\n", data[0]);
-       printf ("Serial memory size           0x%02X\n", 1 << data[1]);
-
-       puts ("Memory type                  ");
-       switch (data[2]) {
-       case 2:
-               type = EDO;
-               puts ("EDO\n");
-               break;
-       case 4:
-               type = SDRAM;
-               puts ("SDRAM\n");
-               break;
-       case 8:
-               type = DDR2;
-               puts ("DDR2\n");
-               break;
-       default:
-               type = unknown;
-               puts ("unknown\n");
-               break;
-       }
-
-       puts ("Row address bits             ");
-       if ((data[3] & 0x00F0) == 0)
-               printf ("%d\n", data[3] & 0x0F);
-       else
-               printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
-
-       puts ("Column address bits          ");
-       if ((data[4] & 0x00F0) == 0)
-               printf ("%d\n", data[4] & 0x0F);
-       else
-               printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
-
-       switch (type) {
-       case DDR2:
-               printf ("Number of ranks              %d\n",
-                       (data[5] & 0x07) + 1);
-               break;
-       default:
-               printf ("Module rows                  %d\n", data[5]);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("Module data width            %d bits\n", data[6]);
-               break;
-       default:
-               printf ("Module data width            %d bits\n",
-                       (data[7] << 8) | data[6]);
-               break;
-       }
-
-       puts ("Interface signal levels      ");
-       switch(data[8]) {
-               case 0:  puts ("TTL 5.0 V\n");  break;
-               case 1:  puts ("LVTTL\n");      break;
-               case 2:  puts ("HSTL 1.5 V\n"); break;
-               case 3:  puts ("SSTL 3.3 V\n"); break;
-               case 4:  puts ("SSTL 2.5 V\n"); break;
-               case 5:  puts ("SSTL 1.8 V\n"); break;
-               default: puts ("unknown\n");    break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM cycle time             ");
-               print_ddr2_tcyc (data[9]);
-               break;
-       default:
-               printf ("SDRAM cycle time             %d.%d ns\n",
-                       (data[9] >> 4) & 0x0F, data[9] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM access time            0.%d%d ns\n",
-                       (data[10] >> 4) & 0x0F, data[10] & 0x0F);
-               break;
-       default:
-               printf ("SDRAM access time            %d.%d ns\n",
-                       (data[10] >> 4) & 0x0F, data[10] & 0x0F);
-               break;
-       }
-
-       puts ("EDC configuration            ");
-       switch (data[11]) {
-               case 0:  puts ("None\n");       break;
-               case 1:  puts ("Parity\n");     break;
-               case 2:  puts ("ECC\n");        break;
-               default: puts ("unknown\n");    break;
-       }
-
-       if ((data[12] & 0x80) == 0)
-               puts ("No self refresh, rate        ");
-       else
-               puts ("Self refresh, rate           ");
-
-       switch(data[12] & 0x7F) {
-               case 0:  puts ("15.625 us\n");  break;
-               case 1:  puts ("3.9 us\n");     break;
-               case 2:  puts ("7.8 us\n");     break;
-               case 3:  puts ("31.3 us\n");    break;
-               case 4:  puts ("62.5 us\n");    break;
-               case 5:  puts ("125 us\n");     break;
-               default: puts ("unknown\n");    break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM width (primary)        %d\n", data[13]);
-               break;
-       default:
-               printf ("SDRAM width (primary)        %d\n", data[13] & 0x7F);
-               if ((data[13] & 0x80) != 0) {
-                       printf ("  (second bank)              %d\n",
-                               2 * (data[13] & 0x7F));
-               }
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               if (data[14] != 0)
-                       printf ("EDC width                    %d\n", data[14]);
-               break;
-       default:
-               if (data[14] != 0) {
-                       printf ("EDC width                    %d\n",
-                               data[14] & 0x7F);
-
-                       if ((data[14] & 0x80) != 0) {
-                               printf ("  (second bank)              %d\n",
-                                       2 * (data[14] & 0x7F));
-                       }
-               }
-               break;
-       }
-
-       if (DDR2 != type) {
-               printf ("Min clock delay, back-to-back random column addresses "
-                       "%d\n", data[15]);
-       }
-
-       puts ("Burst length(s)             ");
-       if (data[16] & 0x80) puts (" Page");
-       if (data[16] & 0x08) puts (" 8");
-       if (data[16] & 0x04) puts (" 4");
-       if (data[16] & 0x02) puts (" 2");
-       if (data[16] & 0x01) puts (" 1");
-       putc ('\n');
-       printf ("Number of banks              %d\n", data[17]);
-
-       switch (type) {
-       case DDR2:
-               puts ("CAS latency(s)              ");
-               decode_bits (data[18], decode_CAS_DDR2, 0);
-               putc ('\n');
-               break;
-       default:
-               puts ("CAS latency(s)              ");
-               decode_bits (data[18], decode_CAS_default, 0);
-               putc ('\n');
-               break;
-       }
-
-       if (DDR2 != type) {
-               puts ("CS latency(s)               ");
-               decode_bits (data[19], decode_CS_WE_default, 0);
-               putc ('\n');
-       }
-
-       if (DDR2 != type) {
-               puts ("WE latency(s)               ");
-               decode_bits (data[20], decode_CS_WE_default, 0);
-               putc ('\n');
-       }
-
-       switch (type) {
-       case DDR2:
-               puts ("Module attributes:\n");
-               if (data[21] & 0x80)
-                       puts ("  TBD (bit 7)\n");
-               if (data[21] & 0x40)
-                       puts ("  Analysis probe installed\n");
-               if (data[21] & 0x20)
-                       puts ("  TBD (bit 5)\n");
-               if (data[21] & 0x10)
-                       puts ("  FET switch external enable\n");
-               printf ("  %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
-               if (data[20] & 0x11) {
-                       printf ("  %d active registers on DIMM\n",
-                               (data[21] & 0x03) + 1);
-               }
-               break;
-       default:
-               puts ("Module attributes:\n");
-               if (!data[21])
-                       puts ("  (none)\n");
-               else
-                       decode_bits (data[21], decode_byte21_default, 0);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               decode_bits (data[22], decode_byte22_DDR2, 0);
-               break;
-       default:
-               puts ("Device attributes:\n");
-               if (data[22] & 0x80) puts ("  TBD (bit 7)\n");
-               if (data[22] & 0x40) puts ("  TBD (bit 6)\n");
-               if (data[22] & 0x20) puts ("  Upper Vcc tolerance 5%\n");
-               else                 puts ("  Upper Vcc tolerance 10%\n");
-               if (data[22] & 0x10) puts ("  Lower Vcc tolerance 5%\n");
-               else                 puts ("  Lower Vcc tolerance 10%\n");
-               if (data[22] & 0x08) puts ("  Supports write1/read burst\n");
-               if (data[22] & 0x04) puts ("  Supports precharge all\n");
-               if (data[22] & 0x02) puts ("  Supports auto precharge\n");
-               if (data[22] & 0x01) puts ("  Supports early RAS# precharge\n");
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM cycle time (2nd highest CAS latency)        ");
-               print_ddr2_tcyc (data[23]);
-               break;
-       default:
-               printf ("SDRAM cycle time (2nd highest CAS latency)        %d."
-                       "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM access from clock (2nd highest CAS latency) 0."
-                       "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
-               break;
-       default:
-               printf ("SDRAM access from clock (2nd highest CAS latency) %d."
-                       "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM cycle time (3rd highest CAS latency)        ");
-               print_ddr2_tcyc (data[25]);
-               break;
-       default:
-               printf ("SDRAM cycle time (3rd highest CAS latency)        %d."
-                       "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("SDRAM access from clock (3rd highest CAS latency) 0."
-                       "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
-               break;
-       default:
-               printf ("SDRAM access from clock (3rd highest CAS latency) %d."
-                       "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("Minimum row precharge        %d.%02d ns\n",
-                       (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
-               break;
-       default:
-               printf ("Minimum row precharge        %d ns\n", data[27]);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("Row active to row active min %d.%02d ns\n",
-                       (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
-               break;
-       default:
-               printf ("Row active to row active min %d ns\n", data[28]);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("RAS to CAS delay min         %d.%02d ns\n",
-                       (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
-               break;
-       default:
-               printf ("RAS to CAS delay min         %d ns\n", data[29]);
-               break;
-       }
-
-       printf ("Minimum RAS pulse width      %d ns\n", data[30]);
-
-       switch (type) {
-       case DDR2:
-               puts ("Density of each row          ");
-               decode_bits (data[31], decode_row_density_DDR2, 1);
-               putc ('\n');
-               break;
-       default:
-               puts ("Density of each row          ");
-               decode_bits (data[31], decode_row_density_default, 1);
-               putc ('\n');
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               puts ("Command and Address setup    ");
-               if (data[32] >= 0xA0) {
-                       printf ("1.%d%d ns\n",
-                               ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
-               } else {
-                       printf ("0.%d%d ns\n",
-                               ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
-               }
-               break;
-       default:
-               printf ("Command and Address setup    %c%d.%d ns\n",
-                       (data[32] & 0x80) ? '-' : '+',
-                       (data[32] >> 4) & 0x07, data[32] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               puts ("Command and Address hold     ");
-               if (data[33] >= 0xA0) {
-                       printf ("1.%d%d ns\n",
-                               ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
-               } else {
-                       printf ("0.%d%d ns\n",
-                               ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
-               }
-               break;
-       default:
-               printf ("Command and Address hold     %c%d.%d ns\n",
-                       (data[33] & 0x80) ? '-' : '+',
-                       (data[33] >> 4) & 0x07, data[33] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("Data signal input setup      0.%d%d ns\n",
-                       (data[34] >> 4) & 0x0F, data[34] & 0x0F);
-               break;
-       default:
-               printf ("Data signal input setup      %c%d.%d ns\n",
-                       (data[34] & 0x80) ? '-' : '+',
-                       (data[34] >> 4) & 0x07, data[34] & 0x0F);
-               break;
-       }
-
-       switch (type) {
-       case DDR2:
-               printf ("Data signal input hold       0.%d%d ns\n",
-                       (data[35] >> 4) & 0x0F, data[35] & 0x0F);
-               break;
-       default:
-               printf ("Data signal input hold       %c%d.%d ns\n",
-                       (data[35] & 0x80) ? '-' : '+',
-                       (data[35] >> 4) & 0x07, data[35] & 0x0F);
-               break;
-       }
-
-       puts ("Manufacturer's JEDEC ID      ");
-       for (j = 64; j <= 71; j++)
-               printf ("%02X ", data[j]);
-       putc ('\n');
-       printf ("Manufacturing Location       %02X\n", data[72]);
-       puts ("Manufacturer's Part Number   ");
-       for (j = 73; j <= 90; j++)
-               printf ("%02X ", data[j]);
-       putc ('\n');
-       printf ("Revision Code                %02X %02X\n", data[91], data[92]);
-       printf ("Manufacturing Date           %02X %02X\n", data[93], data[94]);
-       puts ("Assembly Serial Number       ");
-       for (j = 95; j <= 98; j++)
-               printf ("%02X ", data[j]);
-       putc ('\n');
-
-       if (DDR2 != type) {
-               printf ("Speed rating                 PC%d\n",
-                       data[126] == 0x66 ? 66 : data[126]);
-       }
-       return 0;
-}
-#endif
-
-/*
- * Syntax:
- *     i2c edid {i2c_chip}
- */
-#if defined(CONFIG_I2C_EDID)
-int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       uint chip;
-       struct edid1_info edid;
-       int ret;
-#ifdef CONFIG_DM_I2C
-       struct udevice *dev;
-#endif
-
-       if (argc < 2) {
-               cmd_usage(cmdtp);
-               return 1;
-       }
-
-       chip = simple_strtoul(argv[1], NULL, 16);
-#ifdef CONFIG_DM_I2C
-       ret = i2c_get_cur_bus_chip(chip, &dev);
-       if (!ret)
-               ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
-#else
-       ret = i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid));
-#endif
-       if (ret)
-               return i2c_report_err(ret, I2C_ERR_READ);
-
-       if (edid_check_info(&edid)) {
-               puts("Content isn't valid EDID.\n");
-               return 1;
-       }
-
-       edid_print_info(&edid);
-       return 0;
-
-}
-#endif /* CONFIG_I2C_EDID */
-
-#ifdef CONFIG_DM_I2C
-static void show_bus(struct udevice *bus)
-{
-       struct udevice *dev;
-
-       printf("Bus %d:\t%s", bus->req_seq, bus->name);
-       if (device_active(bus))
-               printf("  (active %d)", bus->seq);
-       printf("\n");
-       for (device_find_first_child(bus, &dev);
-            dev;
-            device_find_next_child(&dev)) {
-               struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
-
-               printf("   %02x: %s, offset len %x, flags %x\n",
-                      chip->chip_addr, dev->name, chip->offset_len,
-                      chip->flags);
-       }
-}
-#endif
-
-/**
- * do_i2c_show_bus() - Handle the "i2c bus" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero always.
- */
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
-static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       if (argc == 1) {
-               /* show all busses */
-#ifdef CONFIG_DM_I2C
-               struct udevice *bus;
-               struct uclass *uc;
-               int ret;
-
-               ret = uclass_get(UCLASS_I2C, &uc);
-               if (ret)
-                       return CMD_RET_FAILURE;
-               uclass_foreach_dev(bus, uc)
-                       show_bus(bus);
-#else
-               int i;
-
-               for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
-                       printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
-#ifndef CONFIG_SYS_I2C_DIRECT_BUS
-                       int j;
-
-                       for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
-                               if (i2c_bus[i].next_hop[j].chip == 0)
-                                       break;
-                               printf("->%s@0x%2x:%d",
-                                      i2c_bus[i].next_hop[j].mux.name,
-                                      i2c_bus[i].next_hop[j].chip,
-                                      i2c_bus[i].next_hop[j].channel);
-                       }
-#endif
-                       printf("\n");
-               }
-#endif
-       } else {
-               int i;
-
-               /* show specific bus */
-               i = simple_strtoul(argv[1], NULL, 10);
-#ifdef CONFIG_DM_I2C
-               struct udevice *bus;
-               int ret;
-
-               ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
-               if (ret) {
-                       printf("Invalid bus %d: err=%d\n", i, ret);
-                       return CMD_RET_FAILURE;
-               }
-               show_bus(bus);
-#else
-               if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
-                       printf("Invalid bus %d\n", i);
-                       return -1;
-               }
-               printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
-#ifndef CONFIG_SYS_I2C_DIRECT_BUS
-                       int j;
-                       for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
-                               if (i2c_bus[i].next_hop[j].chip == 0)
-                                       break;
-                               printf("->%s@0x%2x:%d",
-                                      i2c_bus[i].next_hop[j].mux.name,
-                                      i2c_bus[i].next_hop[j].chip,
-                                      i2c_bus[i].next_hop[j].channel);
-                       }
-#endif
-               printf("\n");
-#endif
-       }
-
-       return 0;
-}
-#endif
-
-/**
- * do_i2c_bus_num() - Handle the "i2c dev" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
-               defined(CONFIG_DM_I2C)
-static int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       int             ret = 0;
-       int     bus_no;
-
-       if (argc == 1) {
-               /* querying current setting */
-#ifdef CONFIG_DM_I2C
-               struct udevice *bus;
-
-               if (!i2c_get_cur_bus(&bus))
-                       bus_no = bus->seq;
-               else
-                       bus_no = -1;
-#else
-               bus_no = i2c_get_bus_num();
-#endif
-               printf("Current bus is %d\n", bus_no);
-       } else {
-               bus_no = simple_strtoul(argv[1], NULL, 10);
-#if defined(CONFIG_SYS_I2C)
-               if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
-                       printf("Invalid bus %d\n", bus_no);
-                       return -1;
-               }
-#endif
-               printf("Setting bus to %d\n", bus_no);
-#ifdef CONFIG_DM_I2C
-               ret = cmd_i2c_set_bus_num(bus_no);
-#else
-               ret = i2c_set_bus_num(bus_no);
-#endif
-               if (ret)
-                       printf("Failure changing bus number (%d)\n", ret);
-       }
-
-       return ret ? CMD_RET_FAILURE : 0;
-}
-#endif  /* defined(CONFIG_SYS_I2C) */
-
-/**
- * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       int speed, ret=0;
-
-#ifdef CONFIG_DM_I2C
-       struct udevice *bus;
-
-       if (i2c_get_cur_bus(&bus))
-               return 1;
-#endif
-       if (argc == 1) {
-#ifdef CONFIG_DM_I2C
-               speed = dm_i2c_get_bus_speed(bus);
-#else
-               speed = i2c_get_bus_speed();
-#endif
-               /* querying current speed */
-               printf("Current bus speed=%d\n", speed);
-       } else {
-               speed = simple_strtoul(argv[1], NULL, 10);
-               printf("Setting bus speed to %d Hz\n", speed);
-#ifdef CONFIG_DM_I2C
-               ret = dm_i2c_set_bus_speed(bus, speed);
-#else
-               ret = i2c_set_bus_speed(speed);
-#endif
-               if (ret)
-                       printf("Failure changing bus speed (%d)\n", ret);
-       }
-
-       return ret ? CMD_RET_FAILURE : 0;
-}
-
-/**
- * do_i2c_mm() - Handle the "i2c mm" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
-}
-
-/**
- * do_i2c_nm() - Handle the "i2c nm" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
-}
-
-/**
- * do_i2c_reset() - Handle the "i2c reset" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero always.
- */
-static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-#if defined(CONFIG_DM_I2C)
-       struct udevice *bus;
-
-       if (i2c_get_cur_bus(&bus))
-               return CMD_RET_FAILURE;
-       if (i2c_deblock(bus)) {
-               printf("Error: Not supported by the driver\n");
-               return CMD_RET_FAILURE;
-       }
-#elif defined(CONFIG_SYS_I2C)
-       i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
-#else
-       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-#endif
-       return 0;
-}
-
-static cmd_tbl_t cmd_i2c_sub[] = {
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
-       U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
-#if defined(CONFIG_SYS_I2C) || \
-       defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
-       U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
-#endif  /* CONFIG_I2C_MULTI_BUS */
-#if defined(CONFIG_I2C_EDID)
-       U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
-#endif  /* CONFIG_I2C_EDID */
-       U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
-       U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
-       U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
-       U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
-       U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
-       U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
-       U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
-       U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
-#ifdef CONFIG_DM_I2C
-       U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
-       U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
-#if defined(CONFIG_CMD_SDRAM)
-       U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
-};
-
-static __maybe_unused void i2c_reloc(void)
-{
-       static int relocated;
-
-       if (!relocated) {
-               fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
-               relocated = 1;
-       };
-}
-
-/**
- * do_i2c() - Handle the "i2c" command-line command
- * @cmdtp:     Command data struct pointer
- * @flag:      Command flag
- * @argc:      Command-line argument count
- * @argv:      Array of command-line arguments
- *
- * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
- * on error.
- */
-static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *c;
-
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-       i2c_reloc();
-#endif
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* Strip off leading 'i2c' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-/***************************************************/
-#ifdef CONFIG_SYS_LONGHELP
-static char i2c_help_text[] =
-#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
-       "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
-#endif
-       "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
-#if defined(CONFIG_SYS_I2C) || \
-       defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
-       "i2c dev [dev] - show or set current I2C bus\n"
-#endif  /* CONFIG_I2C_MULTI_BUS */
-#if defined(CONFIG_I2C_EDID)
-       "i2c edid chip - print EDID configuration information\n"
-#endif  /* CONFIG_I2C_EDID */
-       "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
-       "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
-       "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
-       "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
-       "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
-       "i2c probe [address] - test for and show device(s) on the I2C bus\n"
-       "i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
-       "i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory\n"
-       "          to I2C; the -s option selects bulk write in a single transaction\n"
-#ifdef CONFIG_DM_I2C
-       "i2c flags chip [flags] - set or get chip flags\n"
-       "i2c olen chip [offset_length] - set or get chip offset length\n"
-#endif
-       "i2c reset - re-init the I2C Controller\n"
-#if defined(CONFIG_CMD_SDRAM)
-       "i2c sdram chip - print SDRAM configuration information\n"
-#endif
-       "i2c speed [speed] - show or set I2C bus speed";
-#endif
-
-U_BOOT_CMD(
-       i2c, 7, 1, do_i2c,
-       "I2C sub-system",
-       i2c_help_text
-);
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
deleted file mode 100644 (file)
index f19a7ce..0000000
+++ /dev/null
@@ -1,1457 +0,0 @@
-/*
- * (C) Copyright 2000-2011
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * IDE support
- */
-
-#include <common.h>
-#include <config.h>
-#include <watchdog.h>
-#include <command.h>
-#include <image.h>
-#include <asm/byteorder.h>
-#include <asm/io.h>
-
-#if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
-# include <pcmcia.h>
-#endif
-
-#include <ide.h>
-#include <ata.h>
-
-#ifdef CONFIG_STATUS_LED
-# include <status_led.h>
-#endif
-
-#ifdef __PPC__
-# define EIEIO         __asm__ volatile ("eieio")
-# define SYNC          __asm__ volatile ("sync")
-#else
-# define EIEIO         /* nothing */
-# define SYNC          /* nothing */
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-/* Current I/O Device  */
-static int curr_device = -1;
-
-/* Current offset for IDE0 / IDE1 bus access   */
-ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
-#if defined(CONFIG_SYS_ATA_IDE0_OFFSET)
-       CONFIG_SYS_ATA_IDE0_OFFSET,
-#endif
-#if defined(CONFIG_SYS_ATA_IDE1_OFFSET) && (CONFIG_SYS_IDE_MAXBUS > 1)
-       CONFIG_SYS_ATA_IDE1_OFFSET,
-#endif
-};
-
-static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
-
-block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
-/* ------------------------------------------------------------------------- */
-
-#ifdef CONFIG_IDE_RESET
-static void  ide_reset (void);
-#else
-#define ide_reset()    /* dummy */
-#endif
-
-static void  ide_ident (block_dev_desc_t *dev_desc);
-static uchar ide_wait  (int dev, ulong t);
-
-#define IDE_TIME_OUT   2000    /* 2 sec timeout */
-
-#define ATAPI_TIME_OUT 7000    /* 7 sec timeout (5 sec seems to work...) */
-
-#define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
-
-static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
-
-#ifndef CONFIG_SYS_ATA_PORT_ADDR
-#define CONFIG_SYS_ATA_PORT_ADDR(port) (port)
-#endif
-
-#ifdef CONFIG_ATAPI
-static void    atapi_inquiry(block_dev_desc_t *dev_desc);
-static ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
-                       lbaint_t blkcnt, void *buffer);
-#endif
-
-
-/* ------------------------------------------------------------------------- */
-
-int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int rcode = 0;
-
-       switch (argc) {
-       case 0:
-       case 1:
-               return CMD_RET_USAGE;
-       case 2:
-               if (strncmp(argv[1], "res", 3) == 0) {
-                       puts("\nReset IDE"
-#ifdef CONFIG_IDE_8xx_DIRECT
-                            " on PCMCIA " PCMCIA_SLOT_MSG
-#endif
-                            ": ");
-
-                       ide_init();
-                       return 0;
-               } else if (strncmp(argv[1], "inf", 3) == 0) {
-                       int i;
-
-                       putc('\n');
-
-                       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
-                               if (ide_dev_desc[i].type == DEV_TYPE_UNKNOWN)
-                                       continue;  /* list only known devices */
-                               printf("IDE device %d: ", i);
-                               dev_print(&ide_dev_desc[i]);
-                       }
-                       return 0;
-
-               } else if (strncmp(argv[1], "dev", 3) == 0) {
-                       if ((curr_device < 0)
-                           || (curr_device >= CONFIG_SYS_IDE_MAXDEVICE)) {
-                               puts("\nno IDE devices available\n");
-                               return 1;
-                       }
-                       printf("\nIDE device %d: ", curr_device);
-                       dev_print(&ide_dev_desc[curr_device]);
-                       return 0;
-               } else if (strncmp(argv[1], "part", 4) == 0) {
-                       int dev, ok;
-
-                       for (ok = 0, dev = 0;
-                            dev < CONFIG_SYS_IDE_MAXDEVICE;
-                            ++dev) {
-                               if (ide_dev_desc[dev].part_type !=
-                                   PART_TYPE_UNKNOWN) {
-                                       ++ok;
-                                       if (dev)
-                                               putc('\n');
-                                       print_part(&ide_dev_desc[dev]);
-                               }
-                       }
-                       if (!ok) {
-                               puts("\nno IDE devices available\n");
-                               rcode++;
-                       }
-                       return rcode;
-               }
-               return CMD_RET_USAGE;
-       case 3:
-               if (strncmp(argv[1], "dev", 3) == 0) {
-                       int dev = (int) simple_strtoul(argv[2], NULL, 10);
-
-                       printf("\nIDE device %d: ", dev);
-                       if (dev >= CONFIG_SYS_IDE_MAXDEVICE) {
-                               puts("unknown device\n");
-                               return 1;
-                       }
-                       dev_print(&ide_dev_desc[dev]);
-                       /*ide_print (dev); */
-
-                       if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
-                               return 1;
-
-                       curr_device = dev;
-
-                       puts("... is now current device\n");
-
-                       return 0;
-               } else if (strncmp(argv[1], "part", 4) == 0) {
-                       int dev = (int) simple_strtoul(argv[2], NULL, 10);
-
-                       if (ide_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
-                               print_part(&ide_dev_desc[dev]);
-                       } else {
-                               printf("\nIDE device %d not available\n",
-                                      dev);
-                               rcode = 1;
-                       }
-                       return rcode;
-               }
-
-               return CMD_RET_USAGE;
-       default:
-               /* at least 4 args */
-
-               if (strcmp(argv[1], "read") == 0) {
-                       ulong addr = simple_strtoul(argv[2], NULL, 16);
-                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
-                       block_dev_desc_t *dev_desc;
-                       ulong n;
-
-#ifdef CONFIG_SYS_64BIT_LBA
-                       lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
-
-                       printf("\nIDE read: device %d block # %lld, count %ld ... ",
-                               curr_device, blk, cnt);
-#else
-                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
-
-                       printf("\nIDE read: device %d block # %ld, count %ld ... ",
-                               curr_device, blk, cnt);
-#endif
-
-                       dev_desc = &ide_dev_desc[curr_device];
-                       n = dev_desc->block_read(dev_desc, blk, cnt,
-                                                (ulong *)addr);
-                       /* flush cache after read */
-                       flush_cache(addr,
-                                   cnt * ide_dev_desc[curr_device].blksz);
-
-                       printf("%ld blocks read: %s\n",
-                              n, (n == cnt) ? "OK" : "ERROR");
-                       if (n == cnt)
-                               return 0;
-                       else
-                               return 1;
-               } else if (strcmp(argv[1], "write") == 0) {
-                       ulong addr = simple_strtoul(argv[2], NULL, 16);
-                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
-                       ulong n;
-
-#ifdef CONFIG_SYS_64BIT_LBA
-                       lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
-
-                       printf("\nIDE write: device %d block # %lld, count %ld ... ",
-                               curr_device, blk, cnt);
-#else
-                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
-
-                       printf("\nIDE write: device %d block # %ld, count %ld ... ",
-                               curr_device, blk, cnt);
-#endif
-                       n = ide_write(&ide_dev_desc[curr_device], blk, cnt,
-                                     (ulong *)addr);
-
-                       printf("%ld blocks written: %s\n",
-                               n, (n == cnt) ? "OK" : "ERROR");
-                       if (n == cnt)
-                               return 0;
-                       else
-                               return 1;
-               } else {
-                       return CMD_RET_USAGE;
-               }
-
-               return rcode;
-       }
-}
-
-int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       return common_diskboot(cmdtp, "ide", argc, argv);
-}
-
-/* ------------------------------------------------------------------------- */
-
-__weak void ide_led(uchar led, uchar status)
-{
-#if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */
-       static uchar led_buffer;        /* Buffer for current LED status */
-
-       uchar *led_port = LED_PORT;
-
-       if (status)             /* switch LED on        */
-               led_buffer |= led;
-       else                    /* switch LED off       */
-               led_buffer &= ~led;
-
-       *led_port = led_buffer;
-#endif
-}
-
-#ifndef CONFIG_IDE_LED /* define LED macros, they are not used anyways */
-# define DEVICE_LED(x) 0
-# define LED_IDE1 1
-# define LED_IDE2 2
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-__weak void ide_outb(int dev, int port, unsigned char val)
-{
-       debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
-             dev, port, val,
-             (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
-
-#if defined(CONFIG_IDE_AHB)
-       if (port) {
-               /* write command */
-               ide_write_register(dev, port, val);
-       } else {
-               /* write data */
-               outb(val, (ATA_CURR_BASE(dev)));
-       }
-#else
-       outb(val, (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
-#endif
-}
-
-__weak unsigned char ide_inb(int dev, int port)
-{
-       uchar val;
-
-#if defined(CONFIG_IDE_AHB)
-       val = ide_read_register(dev, port);
-#else
-       val = inb((ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)));
-#endif
-
-       debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
-             dev, port,
-             (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)), val);
-       return val;
-}
-
-void ide_init(void)
-{
-       unsigned char c;
-       int i, bus;
-
-#ifdef CONFIG_IDE_8xx_PCCARD
-       extern int ide_devices_found;   /* Initialized in check_ide_device() */
-#endif /* CONFIG_IDE_8xx_PCCARD */
-
-#ifdef CONFIG_IDE_PREINIT
-       WATCHDOG_RESET();
-
-       if (ide_preinit()) {
-               puts("ide_preinit failed\n");
-               return;
-       }
-#endif /* CONFIG_IDE_PREINIT */
-
-       WATCHDOG_RESET();
-
-       /*
-        * Reset the IDE just to be sure.
-        * Light LED's to show
-        */
-       ide_led((LED_IDE1 | LED_IDE2), 1);      /* LED's on     */
-
-       /* ATAPI Drives seems to need a proper IDE Reset */
-       ide_reset();
-
-#ifdef CONFIG_IDE_INIT_POSTRESET
-       WATCHDOG_RESET();
-
-       if (ide_init_postreset()) {
-               puts("ide_preinit_postreset failed\n");
-               return;
-       }
-#endif /* CONFIG_IDE_INIT_POSTRESET */
-
-       /*
-        * Wait for IDE to get ready.
-        * According to spec, this can take up to 31 seconds!
-        */
-       for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
-               int dev =
-                       bus * (CONFIG_SYS_IDE_MAXDEVICE /
-                              CONFIG_SYS_IDE_MAXBUS);
-
-#ifdef CONFIG_IDE_8xx_PCCARD
-               /* Skip non-ide devices from probing */
-               if ((ide_devices_found & (1 << bus)) == 0) {
-                       ide_led((LED_IDE1 | LED_IDE2), 0);      /* LED's off */
-                       continue;
-               }
-#endif
-               printf("Bus %d: ", bus);
-
-               ide_bus_ok[bus] = 0;
-
-               /* Select device
-                */
-               udelay(100000); /* 100 ms */
-               ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
-               udelay(100000); /* 100 ms */
-               i = 0;
-               do {
-                       udelay(10000);  /* 10 ms */
-
-                       c = ide_inb(dev, ATA_STATUS);
-                       i++;
-                       if (i > (ATA_RESET_TIME * 100)) {
-                               puts("** Timeout **\n");
-                               /* LED's off */
-                               ide_led((LED_IDE1 | LED_IDE2), 0);
-                               return;
-                       }
-                       if ((i >= 100) && ((i % 100) == 0))
-                               putc('.');
-
-               } while (c & ATA_STAT_BUSY);
-
-               if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
-                       puts("not available  ");
-                       debug("Status = 0x%02X ", c);
-#ifndef CONFIG_ATAPI           /* ATAPI Devices do not set DRDY */
-               } else if ((c & ATA_STAT_READY) == 0) {
-                       puts("not available  ");
-                       debug("Status = 0x%02X ", c);
-#endif
-               } else {
-                       puts("OK ");
-                       ide_bus_ok[bus] = 1;
-               }
-               WATCHDOG_RESET();
-       }
-
-       putc('\n');
-
-       ide_led((LED_IDE1 | LED_IDE2), 0);      /* LED's off    */
-
-       curr_device = -1;
-       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
-               int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;
-               ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
-               ide_dev_desc[i].if_type = IF_TYPE_IDE;
-               ide_dev_desc[i].dev = i;
-               ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
-               ide_dev_desc[i].blksz = 0;
-               ide_dev_desc[i].log2blksz =
-                       LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
-               ide_dev_desc[i].lba = 0;
-               ide_dev_desc[i].block_read = ide_read;
-               ide_dev_desc[i].block_write = ide_write;
-               if (!ide_bus_ok[IDE_BUS(i)])
-                       continue;
-               ide_led(led, 1);        /* LED on       */
-               ide_ident(&ide_dev_desc[i]);
-               ide_led(led, 0);        /* LED off      */
-               dev_print(&ide_dev_desc[i]);
-
-               if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
-                       /* initialize partition type */
-                       init_part(&ide_dev_desc[i]);
-                       if (curr_device < 0)
-                               curr_device = i;
-               }
-       }
-       WATCHDOG_RESET();
-}
-
-/* ------------------------------------------------------------------------- */
-
-#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *ide_get_dev(int dev)
-{
-       return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-/* We only need to swap data if we are running on a big endian cpu. */
-#if defined(__LITTLE_ENDIAN)
-__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
-{
-       ide_input_data(dev, sect_buf, words);
-}
-#else
-__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
-{
-       volatile ushort *pbuf =
-               (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-       ushort *dbuf = (ushort *) sect_buf;
-
-       debug("in input swap data base for read is %lx\n",
-             (unsigned long) pbuf);
-
-       while (words--) {
-#ifdef __MIPS__
-               *dbuf++ = swab16p((u16 *) pbuf);
-               *dbuf++ = swab16p((u16 *) pbuf);
-#else
-               *dbuf++ = ld_le16(pbuf);
-               *dbuf++ = ld_le16(pbuf);
-#endif /* !MIPS */
-       }
-}
-#endif /* __LITTLE_ENDIAN */
-
-
-#if defined(CONFIG_IDE_SWAP_IO)
-__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
-{
-       ushort *dbuf;
-       volatile ushort *pbuf;
-
-       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-       dbuf = (ushort *) sect_buf;
-       while (words--) {
-               EIEIO;
-               *pbuf = *dbuf++;
-               EIEIO;
-               *pbuf = *dbuf++;
-       }
-}
-#else  /* ! CONFIG_IDE_SWAP_IO */
-__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
-{
-#if defined(CONFIG_IDE_AHB)
-       ide_write_data(dev, sect_buf, words);
-#else
-       outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
-#endif
-}
-#endif /* CONFIG_IDE_SWAP_IO */
-
-#if defined(CONFIG_IDE_SWAP_IO)
-__weak void ide_input_data(int dev, ulong *sect_buf, int words)
-{
-       ushort *dbuf;
-       volatile ushort *pbuf;
-
-       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-       dbuf = (ushort *) sect_buf;
-
-       debug("in input data base for read is %lx\n", (unsigned long) pbuf);
-
-       while (words--) {
-               EIEIO;
-               *dbuf++ = *pbuf;
-               EIEIO;
-               *dbuf++ = *pbuf;
-       }
-}
-#else  /* ! CONFIG_IDE_SWAP_IO */
-__weak void ide_input_data(int dev, ulong *sect_buf, int words)
-{
-#if defined(CONFIG_IDE_AHB)
-       ide_read_data(dev, sect_buf, words);
-#else
-       insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1);
-#endif
-}
-
-#endif /* CONFIG_IDE_SWAP_IO */
-
-/* -------------------------------------------------------------------------
- */
-static void ide_ident(block_dev_desc_t *dev_desc)
-{
-       unsigned char c;
-       hd_driveid_t iop;
-
-#ifdef CONFIG_ATAPI
-       int retries = 0;
-#endif
-       int device;
-
-       device = dev_desc->dev;
-       printf("  Device %d: ", device);
-
-       ide_led(DEVICE_LED(device), 1); /* LED on       */
-       /* Select device
-        */
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-       dev_desc->if_type = IF_TYPE_IDE;
-#ifdef CONFIG_ATAPI
-
-       retries = 0;
-
-       /* Warning: This will be tricky to read */
-       while (retries <= 1) {
-               /* check signature */
-               if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
-                   (ide_inb(device, ATA_SECT_NUM) == 0x01) &&
-                   (ide_inb(device, ATA_CYL_LOW) == 0x14) &&
-                   (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) {
-                       /* ATAPI Signature found */
-                       dev_desc->if_type = IF_TYPE_ATAPI;
-                       /*
-                        * Start Ident Command
-                        */
-                       ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT);
-                       /*
-                        * Wait for completion - ATAPI devices need more time
-                        * to become ready
-                        */
-                       c = ide_wait(device, ATAPI_TIME_OUT);
-               } else
-#endif
-               {
-                       /*
-                        * Start Ident Command
-                        */
-                       ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT);
-
-                       /*
-                        * Wait for completion
-                        */
-                       c = ide_wait(device, IDE_TIME_OUT);
-               }
-               ide_led(DEVICE_LED(device), 0); /* LED off      */
-
-               if (((c & ATA_STAT_DRQ) == 0) ||
-                   ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
-#ifdef CONFIG_ATAPI
-                       {
-                               /*
-                                * Need to soft reset the device
-                                * in case it's an ATAPI...
-                                */
-                               debug("Retrying...\n");
-                               ide_outb(device, ATA_DEV_HD,
-                                        ATA_LBA | ATA_DEVICE(device));
-                               udelay(100000);
-                               ide_outb(device, ATA_COMMAND, 0x08);
-                               udelay(500000); /* 500 ms */
-                       }
-                       /*
-                        * Select device
-                        */
-                       ide_outb(device, ATA_DEV_HD,
-                                ATA_LBA | ATA_DEVICE(device));
-                       retries++;
-#else
-                       return;
-#endif
-               }
-#ifdef CONFIG_ATAPI
-               else
-                       break;
-       }                       /* see above - ugly to read */
-
-       if (retries == 2)       /* Not found */
-               return;
-#endif
-
-       ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
-
-       ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev,
-                 sizeof(dev_desc->revision));
-       ident_cpy((unsigned char *) dev_desc->vendor, iop.model,
-                 sizeof(dev_desc->vendor));
-       ident_cpy((unsigned char *) dev_desc->product, iop.serial_no,
-                 sizeof(dev_desc->product));
-#ifdef __LITTLE_ENDIAN
-       /*
-        * firmware revision, model, and serial number have Big Endian Byte
-        * order in Word. Convert all three to little endian.
-        *
-        * See CF+ and CompactFlash Specification Revision 2.0:
-        * 6.2.1.6: Identify Drive, Table 39 for more details
-        */
-
-       strswab(dev_desc->revision);
-       strswab(dev_desc->vendor);
-       strswab(dev_desc->product);
-#endif /* __LITTLE_ENDIAN */
-
-       if ((iop.config & 0x0080) == 0x0080)
-               dev_desc->removable = 1;
-       else
-               dev_desc->removable = 0;
-
-#ifdef CONFIG_ATAPI
-       if (dev_desc->if_type == IF_TYPE_ATAPI) {
-               atapi_inquiry(dev_desc);
-               return;
-       }
-#endif /* CONFIG_ATAPI */
-
-#ifdef __BIG_ENDIAN
-       /* swap shorts */
-       dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16);
-#else  /* ! __BIG_ENDIAN */
-       /*
-        * do not swap shorts on little endian
-        *
-        * See CF+ and CompactFlash Specification Revision 2.0:
-        * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details.
-        */
-       dev_desc->lba = iop.lba_capacity;
-#endif /* __BIG_ENDIAN */
-
-#ifdef CONFIG_LBA48
-       if (iop.command_set_2 & 0x0400) {       /* LBA 48 support */
-               dev_desc->lba48 = 1;
-               dev_desc->lba = (unsigned long long) iop.lba48_capacity[0] |
-                       ((unsigned long long) iop.lba48_capacity[1] << 16) |
-                       ((unsigned long long) iop.lba48_capacity[2] << 32) |
-                       ((unsigned long long) iop.lba48_capacity[3] << 48);
-       } else {
-               dev_desc->lba48 = 0;
-       }
-#endif /* CONFIG_LBA48 */
-       /* assuming HD */
-       dev_desc->type = DEV_TYPE_HARDDISK;
-       dev_desc->blksz = ATA_BLOCKSIZE;
-       dev_desc->log2blksz = LOG2(dev_desc->blksz);
-       dev_desc->lun = 0;      /* just to fill something in... */
-
-#if 0                          /* only used to test the powersaving mode,
-                                * if enabled, the drive goes after 5 sec
-                                * in standby mode */
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-       c = ide_wait(device, IDE_TIME_OUT);
-       ide_outb(device, ATA_SECT_CNT, 1);
-       ide_outb(device, ATA_LBA_LOW, 0);
-       ide_outb(device, ATA_LBA_MID, 0);
-       ide_outb(device, ATA_LBA_HIGH, 0);
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-       ide_outb(device, ATA_COMMAND, 0xe3);
-       udelay(50);
-       c = ide_wait(device, IDE_TIME_OUT);     /* can't take over 500 ms */
-#endif
-}
-
-
-/* ------------------------------------------------------------------------- */
-
-ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
-              void *buffer)
-{
-       int device = block_dev->dev;
-       ulong n = 0;
-       unsigned char c;
-       unsigned char pwrsave = 0;      /* power save */
-
-#ifdef CONFIG_LBA48
-       unsigned char lba48 = 0;
-
-       if (blknr & 0x0000fffff0000000ULL) {
-               /* more than 28 bits used, use 48bit mode */
-               lba48 = 1;
-       }
-#endif
-       debug("ide_read dev %d start " LBAF ", blocks " LBAF " buffer at %lX\n",
-             device, blknr, blkcnt, (ulong) buffer);
-
-       ide_led(DEVICE_LED(device), 1); /* LED on       */
-
-       /* Select device
-        */
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-       c = ide_wait(device, IDE_TIME_OUT);
-
-       if (c & ATA_STAT_BUSY) {
-               printf("IDE read: device %d not ready\n", device);
-               goto IDE_READ_E;
-       }
-
-       /* first check if the drive is in Powersaving mode, if yes,
-        * increase the timeout value */
-       ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR);
-       udelay(50);
-
-       c = ide_wait(device, IDE_TIME_OUT);     /* can't take over 500 ms */
-
-       if (c & ATA_STAT_BUSY) {
-               printf("IDE read: device %d not ready\n", device);
-               goto IDE_READ_E;
-       }
-       if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
-               printf("No Powersaving mode %X\n", c);
-       } else {
-               c = ide_inb(device, ATA_SECT_CNT);
-               debug("Powersaving %02X\n", c);
-               if (c == 0)
-                       pwrsave = 1;
-       }
-
-
-       while (blkcnt-- > 0) {
-
-               c = ide_wait(device, IDE_TIME_OUT);
-
-               if (c & ATA_STAT_BUSY) {
-                       printf("IDE read: device %d not ready\n", device);
-                       break;
-               }
-#ifdef CONFIG_LBA48
-               if (lba48) {
-                       /* write high bits */
-                       ide_outb(device, ATA_SECT_CNT, 0);
-                       ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
-#ifdef CONFIG_SYS_64BIT_LBA
-                       ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
-                       ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
-#else
-                       ide_outb(device, ATA_LBA_MID, 0);
-                       ide_outb(device, ATA_LBA_HIGH, 0);
-#endif
-               }
-#endif
-               ide_outb(device, ATA_SECT_CNT, 1);
-               ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
-               ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
-               ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
-
-#ifdef CONFIG_LBA48
-               if (lba48) {
-                       ide_outb(device, ATA_DEV_HD,
-                                ATA_LBA | ATA_DEVICE(device));
-                       ide_outb(device, ATA_COMMAND, ATA_CMD_READ_EXT);
-
-               } else
-#endif
-               {
-                       ide_outb(device, ATA_DEV_HD, ATA_LBA |
-                                ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
-                       ide_outb(device, ATA_COMMAND, ATA_CMD_READ);
-               }
-
-               udelay(50);
-
-               if (pwrsave) {
-                       /* may take up to 4 sec */
-                       c = ide_wait(device, IDE_SPIN_UP_TIME_OUT);
-                       pwrsave = 0;
-               } else {
-                       /* can't take over 500 ms */
-                       c = ide_wait(device, IDE_TIME_OUT);
-               }
-
-               if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
-                   ATA_STAT_DRQ) {
-                       printf("Error (no IRQ) dev %d blk " LBAF ": status "
-                              "%#02x\n", device, blknr, c);
-                       break;
-               }
-
-               ide_input_data(device, buffer, ATA_SECTORWORDS);
-               (void) ide_inb(device, ATA_STATUS);     /* clear IRQ */
-
-               ++n;
-               ++blknr;
-               buffer += ATA_BLOCKSIZE;
-       }
-IDE_READ_E:
-       ide_led(DEVICE_LED(device), 0); /* LED off      */
-       return (n);
-}
-
-/* ------------------------------------------------------------------------- */
-
-
-ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
-               const void *buffer)
-{
-       int device = block_dev->dev;
-       ulong n = 0;
-       unsigned char c;
-
-#ifdef CONFIG_LBA48
-       unsigned char lba48 = 0;
-
-       if (blknr & 0x0000fffff0000000ULL) {
-               /* more than 28 bits used, use 48bit mode */
-               lba48 = 1;
-       }
-#endif
-
-       ide_led(DEVICE_LED(device), 1); /* LED on       */
-
-       /* Select device
-        */
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-
-       while (blkcnt-- > 0) {
-
-               c = ide_wait(device, IDE_TIME_OUT);
-
-               if (c & ATA_STAT_BUSY) {
-                       printf("IDE read: device %d not ready\n", device);
-                       goto WR_OUT;
-               }
-#ifdef CONFIG_LBA48
-               if (lba48) {
-                       /* write high bits */
-                       ide_outb(device, ATA_SECT_CNT, 0);
-                       ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
-#ifdef CONFIG_SYS_64BIT_LBA
-                       ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF);
-                       ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF);
-#else
-                       ide_outb(device, ATA_LBA_MID, 0);
-                       ide_outb(device, ATA_LBA_HIGH, 0);
-#endif
-               }
-#endif
-               ide_outb(device, ATA_SECT_CNT, 1);
-               ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
-               ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
-               ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
-
-#ifdef CONFIG_LBA48
-               if (lba48) {
-                       ide_outb(device, ATA_DEV_HD,
-                                ATA_LBA | ATA_DEVICE(device));
-                       ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE_EXT);
-
-               } else
-#endif
-               {
-                       ide_outb(device, ATA_DEV_HD, ATA_LBA |
-                                ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
-                       ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE);
-               }
-
-               udelay(50);
-
-               /* can't take over 500 ms */
-               c = ide_wait(device, IDE_TIME_OUT);
-
-               if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) !=
-                   ATA_STAT_DRQ) {
-                       printf("Error (no IRQ) dev %d blk " LBAF ": status "
-                               "%#02x\n", device, blknr, c);
-                       goto WR_OUT;
-               }
-
-               ide_output_data(device, buffer, ATA_SECTORWORDS);
-               c = ide_inb(device, ATA_STATUS);        /* clear IRQ */
-               ++n;
-               ++blknr;
-               buffer += ATA_BLOCKSIZE;
-       }
-WR_OUT:
-       ide_led(DEVICE_LED(device), 0); /* LED off      */
-       return (n);
-}
-
-/* ------------------------------------------------------------------------- */
-
-/*
- * copy src to dest, skipping leading and trailing blanks and null
- * terminate the string
- * "len" is the size of available memory including the terminating '\0'
- */
-static void ident_cpy(unsigned char *dst, unsigned char *src,
-                     unsigned int len)
-{
-       unsigned char *end, *last;
-
-       last = dst;
-       end = src + len - 1;
-
-       /* reserve space for '\0' */
-       if (len < 2)
-               goto OUT;
-
-       /* skip leading white space */
-       while ((*src) && (src < end) && (*src == ' '))
-               ++src;
-
-       /* copy string, omitting trailing white space */
-       while ((*src) && (src < end)) {
-               *dst++ = *src;
-               if (*src++ != ' ')
-                       last = dst;
-       }
-OUT:
-       *last = '\0';
-}
-
-/* ------------------------------------------------------------------------- */
-
-/*
- * Wait until Busy bit is off, or timeout (in ms)
- * Return last status
- */
-static uchar ide_wait(int dev, ulong t)
-{
-       ulong delay = 10 * t;   /* poll every 100 us */
-       uchar c;
-
-       while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) {
-               udelay(100);
-               if (delay-- == 0)
-                       break;
-       }
-       return (c);
-}
-
-/* ------------------------------------------------------------------------- */
-
-#ifdef CONFIG_IDE_RESET
-extern void ide_set_reset(int idereset);
-
-static void ide_reset(void)
-{
-       int i;
-
-       curr_device = -1;
-       for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i)
-               ide_bus_ok[i] = 0;
-       for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i)
-               ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
-
-       ide_set_reset(1);       /* assert reset */
-
-       /* the reset signal shall be asserted for et least 25 us */
-       udelay(25);
-
-       WATCHDOG_RESET();
-
-       /* de-assert RESET signal */
-       ide_set_reset(0);
-
-       /* wait 250 ms */
-       for (i = 0; i < 250; ++i)
-               udelay(1000);
-}
-
-#endif /* CONFIG_IDE_RESET */
-
-/* ------------------------------------------------------------------------- */
-
-#if defined(CONFIG_OF_IDE_FIXUP)
-int ide_device_present(int dev)
-{
-       if (dev >= CONFIG_SYS_IDE_MAXBUS)
-               return 0;
-       return (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1);
-}
-#endif
-/* ------------------------------------------------------------------------- */
-
-#ifdef CONFIG_ATAPI
-/****************************************************************************
- * ATAPI Support
- */
-
-#if defined(CONFIG_IDE_SWAP_IO)
-/* since ATAPI may use commands with not 4 bytes alligned length
- * we have our own transfer functions, 2 bytes alligned */
-__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
-{
-       ushort *dbuf;
-       volatile ushort *pbuf;
-
-       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-       dbuf = (ushort *) sect_buf;
-
-       debug("in output data shorts base for read is %lx\n",
-             (unsigned long) pbuf);
-
-       while (shorts--) {
-               EIEIO;
-               *pbuf = *dbuf++;
-       }
-}
-
-__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
-{
-       ushort *dbuf;
-       volatile ushort *pbuf;
-
-       pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-       dbuf = (ushort *) sect_buf;
-
-       debug("in input data shorts base for read is %lx\n",
-             (unsigned long) pbuf);
-
-       while (shorts--) {
-               EIEIO;
-               *dbuf++ = *pbuf;
-       }
-}
-
-#else  /* ! CONFIG_IDE_SWAP_IO */
-__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
-{
-       outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
-}
-
-__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
-{
-       insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
-}
-
-#endif /* CONFIG_IDE_SWAP_IO */
-
-/*
- * Wait until (Status & mask) == res, or timeout (in ms)
- * Return last status
- * This is used since some ATAPI CD ROMs clears their Busy Bit first
- * and then they set their DRQ Bit
- */
-static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res)
-{
-       ulong delay = 10 * t;   /* poll every 100 us */
-       uchar c;
-
-       /* prevents to read the status before valid */
-       c = ide_inb(dev, ATA_DEV_CTL);
-
-       while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) {
-               /* break if error occurs (doesn't make sense to wait more) */
-               if ((c & ATA_STAT_ERR) == ATA_STAT_ERR)
-                       break;
-               udelay(100);
-               if (delay-- == 0)
-                       break;
-       }
-       return (c);
-}
-
-/*
- * issue an atapi command
- */
-unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
-                         unsigned char *buffer, int buflen)
-{
-       unsigned char c, err, mask, res;
-       int n;
-
-       ide_led(DEVICE_LED(device), 1); /* LED on       */
-
-       /* Select device
-        */
-       mask = ATA_STAT_BUSY | ATA_STAT_DRQ;
-       res = 0;
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
-       if ((c & mask) != res) {
-               printf("ATAPI_ISSUE: device %d not ready status %X\n", device,
-                      c);
-               err = 0xFF;
-               goto AI_OUT;
-       }
-       /* write taskfile */
-       ide_outb(device, ATA_ERROR_REG, 0);     /* no DMA, no overlaped */
-       ide_outb(device, ATA_SECT_CNT, 0);
-       ide_outb(device, ATA_SECT_NUM, 0);
-       ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF));
-       ide_outb(device, ATA_CYL_HIGH,
-                (unsigned char) ((buflen >> 8) & 0xFF));
-       ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-
-       ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET);
-       udelay(50);
-
-       mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
-       res = ATA_STAT_DRQ;
-       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
-
-       if ((c & mask) != res) {        /* DRQ must be 1, BSY 0 */
-               printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d status 0x%02x\n",
-                       device, c);
-               err = 0xFF;
-               goto AI_OUT;
-       }
-
-       /* write command block */
-       ide_output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
-
-       /* ATAPI Command written wait for completition */
-       udelay(5000);           /* device must set bsy */
-
-       mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
-       /*
-        * if no data wait for DRQ = 0 BSY = 0
-        * if data wait for DRQ = 1 BSY = 0
-        */
-       res = 0;
-       if (buflen)
-               res = ATA_STAT_DRQ;
-       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
-       if ((c & mask) != res) {
-               if (c & ATA_STAT_ERR) {
-                       err = (ide_inb(device, ATA_ERROR_REG)) >> 4;
-                       debug("atapi_issue 1 returned sense key %X status %02X\n",
-                               err, c);
-               } else {
-                       printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x)  status 0x%02x\n",
-                               ccb[0], c);
-                       err = 0xFF;
-               }
-               goto AI_OUT;
-       }
-       n = ide_inb(device, ATA_CYL_HIGH);
-       n <<= 8;
-       n += ide_inb(device, ATA_CYL_LOW);
-       if (n > buflen) {
-               printf("ERROR, transfer bytes %d requested only %d\n", n,
-                      buflen);
-               err = 0xff;
-               goto AI_OUT;
-       }
-       if ((n == 0) && (buflen < 0)) {
-               printf("ERROR, transfer bytes %d requested %d\n", n, buflen);
-               err = 0xff;
-               goto AI_OUT;
-       }
-       if (n != buflen) {
-               debug("WARNING, transfer bytes %d not equal with requested %d\n",
-                       n, buflen);
-       }
-       if (n != 0) {           /* data transfer */
-               debug("ATAPI_ISSUE: %d Bytes to transfer\n", n);
-               /* we transfer shorts */
-               n >>= 1;
-               /* ok now decide if it is an in or output */
-               if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
-                       debug("Write to device\n");
-                       ide_output_data_shorts(device,
-                               (unsigned short *) buffer, n);
-               } else {
-                       debug("Read from device @ %p shorts %d\n", buffer, n);
-                       ide_input_data_shorts(device,
-                               (unsigned short *) buffer, n);
-               }
-       }
-       udelay(5000);           /* seems that some CD ROMs need this... */
-       mask = ATA_STAT_BUSY | ATA_STAT_ERR;
-       res = 0;
-       c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
-       if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) {
-               err = (ide_inb(device, ATA_ERROR_REG) >> 4);
-               debug("atapi_issue 2 returned sense key %X status %X\n", err,
-                     c);
-       } else {
-               err = 0;
-       }
-AI_OUT:
-       ide_led(DEVICE_LED(device), 0); /* LED off      */
-       return (err);
-}
-
-/*
- * sending the command to atapi_issue. If an status other than good
- * returns, an request_sense will be issued
- */
-
-#define ATAPI_DRIVE_NOT_READY  100
-#define ATAPI_UNIT_ATTN                10
-
-unsigned char atapi_issue_autoreq(int device,
-                                 unsigned char *ccb,
-                                 int ccblen,
-                                 unsigned char *buffer, int buflen)
-{
-       unsigned char sense_data[18], sense_ccb[12];
-       unsigned char res, key, asc, ascq;
-       int notready, unitattn;
-
-       unitattn = ATAPI_UNIT_ATTN;
-       notready = ATAPI_DRIVE_NOT_READY;
-
-retry:
-       res = atapi_issue(device, ccb, ccblen, buffer, buflen);
-       if (res == 0)
-               return 0;       /* Ok */
-
-       if (res == 0xFF)
-               return 0xFF;    /* error */
-
-       debug("(auto_req)atapi_issue returned sense key %X\n", res);
-
-       memset(sense_ccb, 0, sizeof(sense_ccb));
-       memset(sense_data, 0, sizeof(sense_data));
-       sense_ccb[0] = ATAPI_CMD_REQ_SENSE;
-       sense_ccb[4] = 18;      /* allocation Length */
-
-       res = atapi_issue(device, sense_ccb, 12, sense_data, 18);
-       key = (sense_data[2] & 0xF);
-       asc = (sense_data[12]);
-       ascq = (sense_data[13]);
-
-       debug("ATAPI_CMD_REQ_SENSE returned %x\n", res);
-       debug(" Sense page: %02X key %02X ASC %02X ASCQ %02X\n",
-             sense_data[0], key, asc, ascq);
-
-       if ((key == 0))
-               return 0;       /* ok device ready */
-
-       if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */
-               if (unitattn-- > 0) {
-                       udelay(200 * 1000);
-                       goto retry;
-               }
-               printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN);
-               goto error;
-       }
-       if ((asc == 0x4) && (ascq == 0x1)) {
-               /* not ready, but will be ready soon */
-               if (notready-- > 0) {
-                       udelay(200 * 1000);
-                       goto retry;
-               }
-               printf("Drive not ready, tried %d times\n",
-                      ATAPI_DRIVE_NOT_READY);
-               goto error;
-       }
-       if (asc == 0x3a) {
-               debug("Media not present\n");
-               goto error;
-       }
-
-       printf("ERROR: Unknown Sense key %02X ASC %02X ASCQ %02X\n", key, asc,
-              ascq);
-error:
-       debug("ERROR Sense key %02X ASC %02X ASCQ %02X\n", key, asc, ascq);
-       return (0xFF);
-}
-
-
-static void atapi_inquiry(block_dev_desc_t *dev_desc)
-{
-       unsigned char ccb[12];  /* Command descriptor block */
-       unsigned char iobuf[64];        /* temp buf */
-       unsigned char c;
-       int device;
-
-       device = dev_desc->dev;
-       dev_desc->type = DEV_TYPE_UNKNOWN;      /* not yet valid */
-       dev_desc->block_read = atapi_read;
-
-       memset(ccb, 0, sizeof(ccb));
-       memset(iobuf, 0, sizeof(iobuf));
-
-       ccb[0] = ATAPI_CMD_INQUIRY;
-       ccb[4] = 40;            /* allocation Legnth */
-       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 40);
-
-       debug("ATAPI_CMD_INQUIRY returned %x\n", c);
-       if (c != 0)
-               return;
-
-       /* copy device ident strings */
-       ident_cpy((unsigned char *) dev_desc->vendor, &iobuf[8], 8);
-       ident_cpy((unsigned char *) dev_desc->product, &iobuf[16], 16);
-       ident_cpy((unsigned char *) dev_desc->revision, &iobuf[32], 5);
-
-       dev_desc->lun = 0;
-       dev_desc->lba = 0;
-       dev_desc->blksz = 0;
-       dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
-       dev_desc->type = iobuf[0] & 0x1f;
-
-       if ((iobuf[1] & 0x80) == 0x80)
-               dev_desc->removable = 1;
-       else
-               dev_desc->removable = 0;
-
-       memset(ccb, 0, sizeof(ccb));
-       memset(iobuf, 0, sizeof(iobuf));
-       ccb[0] = ATAPI_CMD_START_STOP;
-       ccb[4] = 0x03;          /* start */
-
-       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0);
-
-       debug("ATAPI_CMD_START_STOP returned %x\n", c);
-       if (c != 0)
-               return;
-
-       memset(ccb, 0, sizeof(ccb));
-       memset(iobuf, 0, sizeof(iobuf));
-       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0);
-
-       debug("ATAPI_CMD_UNIT_TEST_READY returned %x\n", c);
-       if (c != 0)
-               return;
-
-       memset(ccb, 0, sizeof(ccb));
-       memset(iobuf, 0, sizeof(iobuf));
-       ccb[0] = ATAPI_CMD_READ_CAP;
-       c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 8);
-       debug("ATAPI_CMD_READ_CAP returned %x\n", c);
-       if (c != 0)
-               return;
-
-       debug("Read Cap: LBA %02X%02X%02X%02X blksize %02X%02X%02X%02X\n",
-             iobuf[0], iobuf[1], iobuf[2], iobuf[3],
-             iobuf[4], iobuf[5], iobuf[6], iobuf[7]);
-
-       dev_desc->lba = ((unsigned long) iobuf[0] << 24) +
-               ((unsigned long) iobuf[1] << 16) +
-               ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]);
-       dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
-               ((unsigned long) iobuf[5] << 16) +
-               ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
-       dev_desc->log2blksz = LOG2(dev_desc->blksz);
-#ifdef CONFIG_LBA48
-       /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
-       dev_desc->lba48 = 0;
-#endif
-       return;
-}
-
-
-/*
- * atapi_read:
- * we transfer only one block per command, since the multiple DRQ per
- * command is not yet implemented
- */
-#define ATAPI_READ_MAX_BYTES   2048    /* we read max 2kbytes */
-#define ATAPI_READ_BLOCK_SIZE  2048    /* assuming CD part */
-#define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
-
-ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
-                void *buffer)
-{
-       int device = block_dev->dev;
-       ulong n = 0;
-       unsigned char ccb[12];  /* Command descriptor block */
-       ulong cnt;
-
-       debug("atapi_read dev %d start " LBAF " blocks " LBAF " buffer at %lX\n",
-             device, blknr, blkcnt, (ulong) buffer);
-
-       do {
-               if (blkcnt > ATAPI_READ_MAX_BLOCK)
-                       cnt = ATAPI_READ_MAX_BLOCK;
-               else
-                       cnt = blkcnt;
-
-               ccb[0] = ATAPI_CMD_READ_12;
-               ccb[1] = 0;     /* reserved */
-               ccb[2] = (unsigned char) (blknr >> 24) & 0xFF;  /* MSB Block */
-               ccb[3] = (unsigned char) (blknr >> 16) & 0xFF;  /*  */
-               ccb[4] = (unsigned char) (blknr >> 8) & 0xFF;
-               ccb[5] = (unsigned char) blknr & 0xFF;  /* LSB Block */
-               ccb[6] = (unsigned char) (cnt >> 24) & 0xFF; /* MSB Block cnt */
-               ccb[7] = (unsigned char) (cnt >> 16) & 0xFF;
-               ccb[8] = (unsigned char) (cnt >> 8) & 0xFF;
-               ccb[9] = (unsigned char) cnt & 0xFF;    /* LSB Block */
-               ccb[10] = 0;    /* reserved */
-               ccb[11] = 0;    /* reserved */
-
-               if (atapi_issue_autoreq(device, ccb, 12,
-                                       (unsigned char *) buffer,
-                                       cnt * ATAPI_READ_BLOCK_SIZE)
-                   == 0xFF) {
-                       return (n);
-               }
-               n += cnt;
-               blkcnt -= cnt;
-               blknr += cnt;
-               buffer += (cnt * ATAPI_READ_BLOCK_SIZE);
-       } while (blkcnt > 0);
-       return (n);
-}
-
-/* ------------------------------------------------------------------------- */
-
-#endif /* CONFIG_ATAPI */
-
-U_BOOT_CMD(ide, 5, 1, do_ide,
-          "IDE sub-system",
-          "reset - reset IDE controller\n"
-          "ide info  - show available IDE devices\n"
-          "ide device [dev] - show or set current device\n"
-          "ide part [dev] - print partition table of one or all IDE devices\n"
-          "ide read  addr blk# cnt\n"
-          "ide write addr blk# cnt - read/write `cnt'"
-          " blocks starting at block `blk#'\n"
-          "    to/from memory address `addr'");
-
-U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
-          "boot from IDE device", "loadAddr dev:part");
diff --git a/common/cmd_immap.c b/common/cmd_immap.c
deleted file mode 100644 (file)
index 1414f9a..0000000
+++ /dev/null
@@ -1,703 +0,0 @@
-/*
- * (C) Copyright 2000-2003
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * MPC8xx/MPC8260 Internal Memory Map Functions
- */
-
-#include <common.h>
-#include <command.h>
-
-#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260)
-
-#if defined(CONFIG_8xx)
-#include <asm/8xx_immap.h>
-#include <commproc.h>
-#include <asm/iopin_8xx.h>
-#elif defined(CONFIG_MPC8260)
-#include <asm/immap_8260.h>
-#include <asm/cpm_8260.h>
-#include <asm/iopin_8260.h>
-#endif
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static void
-unimplemented ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       printf ("Sorry, but the '%s' command has not been implemented\n",
-               cmdtp->name);
-}
-
-int
-do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile sysconf8xx_t *sc = &immap->im_siu_conf;
-#elif defined(CONFIG_MPC8260)
-       volatile sysconf8260_t *sc = &immap->im_siu_conf;
-#endif
-
-       printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr);
-#if defined(CONFIG_8xx)
-       printf ("SWT   = %08x\n", sc->sc_swt);
-       printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask);
-       printf ("SIEL  = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec);
-       printf ("TESR  = %08x SDCR  = %08x\n", sc->sc_tesr, sc->sc_sdcr);
-#elif defined(CONFIG_MPC8260)
-       printf ("BCR   = %08x\n", sc->sc_bcr);
-       printf ("P_ACR =       %02x P_ALRH= %08x P_ALRL= %08x\n",
-               sc->sc_ppc_acr, sc->sc_ppc_alrh, sc->sc_ppc_alrl);
-       printf ("L_ACR =       %02x L_ALRH= %08x L_ALRL= %08x\n",
-               sc->sc_lcl_acr, sc->sc_lcl_alrh, sc->sc_lcl_alrl);
-       printf ("PTESR1= %08x PTESR2= %08x\n", sc->sc_tescr1, sc->sc_tescr2);
-       printf ("LTESR1= %08x LTESR2= %08x\n", sc->sc_ltescr1, sc->sc_ltescr2);
-       printf ("PDTEA = %08x PDTEM =       %02x\n", sc->sc_pdtea, sc->sc_pdtem);
-       printf ("LDTEA = %08x LDTEM =       %02x\n", sc->sc_ldtea, sc->sc_ldtem);
-#endif
-       return 0;
-}
-
-int
-do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile memctl8xx_t *memctl = &immap->im_memctl;
-       int nbanks = 8;
-#elif defined(CONFIG_MPC8260)
-       volatile memctl8260_t *memctl = &immap->im_memctl;
-       int nbanks = 12;
-#endif
-       volatile uint *p = &memctl->memc_br0;
-       int i;
-
-       for (i = 0; i < nbanks; i++, p += 2) {
-               if (i < 10) {
-                       printf ("BR%d   = %08x OR%d   = %08x\n",
-                               i, p[0], i, p[1]);
-               } else {
-                       printf ("BR%d  = %08x OR%d  = %08x\n",
-                               i, p[0], i, p[1]);
-               }
-       }
-
-       printf ("MAR   = %08x", memctl->memc_mar);
-#if defined(CONFIG_8xx)
-       printf (" MCR   = %08x\n", memctl->memc_mcr);
-#elif defined(CONFIG_MPC8260)
-       putc ('\n');
-#endif
-       printf ("MAMR  = %08x MBMR  = %08x",
-               memctl->memc_mamr, memctl->memc_mbmr);
-#if defined(CONFIG_8xx)
-       printf ("\nMSTAT =     %04x\n", memctl->memc_mstat);
-#elif defined(CONFIG_MPC8260)
-       printf (" MCMR  = %08x\n", memctl->memc_mcmr);
-#endif
-       printf ("MPTPR =     %04x MDR   = %08x\n",
-               memctl->memc_mptpr, memctl->memc_mdr);
-#if defined(CONFIG_MPC8260)
-       printf ("PSDMR = %08x LSDMR = %08x\n",
-               memctl->memc_psdmr, memctl->memc_lsdmr);
-       printf ("PURT  =       %02x PSRT  =       %02x\n",
-               memctl->memc_purt, memctl->memc_psrt);
-       printf ("LURT  =       %02x LSRT  =       %02x\n",
-               memctl->memc_lurt, memctl->memc_lsrt);
-       printf ("IMMR  = %08x\n", memctl->memc_immr);
-#endif
-       return 0;
-}
-
-int
-do_sitinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-#ifdef CONFIG_MPC8260
-int
-do_icinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-#endif
-
-int
-do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile car8xx_t *car = &immap->im_clkrst;
-#elif defined(CONFIG_MPC8260)
-       volatile car8260_t *car = &immap->im_clkrst;
-#endif
-
-#if defined(CONFIG_8xx)
-       printf ("SCCR  = %08x\n", car->car_sccr);
-       printf ("PLPRCR= %08x\n", car->car_plprcr);
-       printf ("RSR   = %08x\n", car->car_rsr);
-#elif defined(CONFIG_MPC8260)
-       printf ("SCCR  = %08x\n", car->car_sccr);
-       printf ("SCMR  = %08x\n", car->car_scmr);
-       printf ("RSR   = %08x\n", car->car_rsr);
-       printf ("RMR   = %08x\n", car->car_rmr);
-#endif
-       return 0;
-}
-
-static int counter;
-
-static void
-header(void)
-{
-       char *data = "\
-       --------------------------------        --------------------------------\
-       00000000001111111111222222222233        00000000001111111111222222222233\
-       01234567890123456789012345678901        01234567890123456789012345678901\
-       --------------------------------        --------------------------------\
-    ";
-       int i;
-
-       if (counter % 2)
-               putc('\n');
-       counter = 0;
-
-       for (i = 0; i < 4; i++, data += 79)
-               printf("%.79s\n", data);
-}
-
-static void binary (char *label, uint value, int nbits)
-{
-       uint mask = 1 << (nbits - 1);
-       int i, second = (counter++ % 2);
-
-       if (second)
-               putc (' ');
-       puts (label);
-       for (i = 32 + 1; i != nbits; i--)
-               putc (' ');
-
-       while (mask != 0) {
-               if (value & mask)
-                       putc ('1');
-               else
-                       putc ('0');
-               mask >>= 1;
-       }
-
-       if (second)
-               putc ('\n');
-}
-
-#if defined(CONFIG_8xx)
-#define PA_NBITS       16
-#define PA_NB_ODR       8
-#define PB_NBITS       18
-#define PB_NB_ODR      16
-#define PC_NBITS       12
-#define PD_NBITS       13
-#elif defined(CONFIG_MPC8260)
-#define PA_NBITS       32
-#define PA_NB_ODR      32
-#define PB_NBITS       28
-#define PB_NB_ODR      28
-#define PC_NBITS       32
-#define PD_NBITS       28
-#endif
-
-int
-do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile iop8xx_t *iop = &immap->im_ioport;
-       volatile ushort *l, *r;
-#elif defined(CONFIG_MPC8260)
-       volatile iop8260_t *iop = &immap->im_ioport;
-       volatile uint *l, *r;
-#endif
-       volatile uint *R;
-
-       counter = 0;
-       header ();
-
-       /*
-        * Ports A & B
-        */
-
-#if defined(CONFIG_8xx)
-       l = &iop->iop_padir;
-       R = &immap->im_cpm.cp_pbdir;
-#elif defined(CONFIG_MPC8260)
-       l = &iop->iop_pdira;
-       R = &iop->iop_pdirb;
-#endif
-       binary ("PA_DIR", *l++, PA_NBITS);
-       binary ("PB_DIR", *R++, PB_NBITS);
-       binary ("PA_PAR", *l++, PA_NBITS);
-       binary ("PB_PAR", *R++, PB_NBITS);
-#if defined(CONFIG_MPC8260)
-       binary ("PA_SOR", *l++, PA_NBITS);
-       binary ("PB_SOR", *R++, PB_NBITS);
-#endif
-       binary ("PA_ODR", *l++, PA_NB_ODR);
-       binary ("PB_ODR", *R++, PB_NB_ODR);
-       binary ("PA_DAT", *l++, PA_NBITS);
-       binary ("PB_DAT", *R++, PB_NBITS);
-
-       header ();
-
-       /*
-        * Ports C & D
-        */
-
-#if defined(CONFIG_8xx)
-       l = &iop->iop_pcdir;
-       r = &iop->iop_pddir;
-#elif defined(CONFIG_MPC8260)
-       l = &iop->iop_pdirc;
-       r = &iop->iop_pdird;
-#endif
-       binary ("PC_DIR", *l++, PC_NBITS);
-       binary ("PD_DIR", *r++, PD_NBITS);
-       binary ("PC_PAR", *l++, PC_NBITS);
-       binary ("PD_PAR", *r++, PD_NBITS);
-#if defined(CONFIG_8xx)
-       binary ("PC_SO ", *l++, PC_NBITS);
-       binary ("      ", 0, 0);
-       r++;
-#elif defined(CONFIG_MPC8260)
-       binary ("PC_SOR", *l++, PC_NBITS);
-       binary ("PD_SOR", *r++, PD_NBITS);
-       binary ("PC_ODR", *l++, PC_NBITS);
-       binary ("PD_ODR", *r++, PD_NBITS);
-#endif
-       binary ("PC_DAT", *l++, PC_NBITS);
-       binary ("PD_DAT", *r++, PD_NBITS);
-#if defined(CONFIG_8xx)
-       binary ("PC_INT", *l++, PC_NBITS);
-#endif
-
-       header ();
-       return 0;
-}
-
-/*
- * set the io pins
- * this needs a clean up for smaller tighter code
- * use *uint and set the address based on cmd + port
- */
-int
-do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint rcode = 0;
-       iopin_t iopin;
-       static uint port = 0;
-       static uint pin = 0;
-       static uint value = 0;
-       static enum {
-               DIR,
-               PAR,
-               SOR,
-               ODR,
-               DAT,
-#if defined(CONFIG_8xx)
-               INT
-#endif
-       } cmd = DAT;
-
-       if (argc != 5) {
-               puts ("iopset PORT PIN CMD VALUE\n");
-               return 1;
-       }
-       port = argv[1][0] - 'A';
-       if (port > 3)
-               port -= 0x20;
-       if (port > 3)
-               rcode = 1;
-       pin = simple_strtol (argv[2], NULL, 10);
-       if (pin > 31)
-               rcode = 1;
-
-
-       switch (argv[3][0]) {
-       case 'd':
-               if (argv[3][1] == 'a')
-                       cmd = DAT;
-               else if (argv[3][1] == 'i')
-                       cmd = DIR;
-               else
-                       rcode = 1;
-               break;
-       case 'p':
-               cmd = PAR;
-               break;
-       case 'o':
-               cmd = ODR;
-               break;
-       case 's':
-               cmd = SOR;
-               break;
-#if defined(CONFIG_8xx)
-       case 'i':
-               cmd = INT;
-               break;
-#endif
-       default:
-               printf ("iopset: unknown command %s\n", argv[3]);
-               rcode = 1;
-       }
-       if (argv[4][0] == '1')
-               value = 1;
-       else if (argv[4][0] == '0')
-               value = 0;
-       else
-               rcode = 1;
-       if (rcode == 0) {
-               iopin.port = port;
-               iopin.pin = pin;
-               iopin.flag = 0;
-               switch (cmd) {
-               case DIR:
-                       if (value)
-                               iopin_set_out (&iopin);
-                       else
-                               iopin_set_in (&iopin);
-                       break;
-               case PAR:
-                       if (value)
-                               iopin_set_ded (&iopin);
-                       else
-                               iopin_set_gen (&iopin);
-                       break;
-               case SOR:
-                       if (value)
-                               iopin_set_opt2 (&iopin);
-                       else
-                               iopin_set_opt1 (&iopin);
-                       break;
-               case ODR:
-                       if (value)
-                               iopin_set_odr (&iopin);
-                       else
-                               iopin_set_act (&iopin);
-                       break;
-               case DAT:
-                       if (value)
-                               iopin_set_high (&iopin);
-                       else
-                               iopin_set_low (&iopin);
-                       break;
-#if defined(CONFIG_8xx)
-               case INT:
-                       if (value)
-                               iopin_set_falledge (&iopin);
-                       else
-                               iopin_set_anyedge (&iopin);
-                       break;
-#endif
-               }
-
-       }
-       return rcode;
-}
-
-int
-do_dmainfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_fccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-static void prbrg (int n, uint val)
-{
-       uint extc = (val >> 14) & 3;
-       uint cd = (val & CPM_BRG_CD_MASK) >> 1;
-       uint div16 = (val & CPM_BRG_DIV16) != 0;
-
-#if defined(CONFIG_8xx)
-       ulong clock = gd->cpu_clk;
-#elif defined(CONFIG_MPC8260)
-       ulong clock = gd->arch.brg_clk;
-#endif
-
-       printf ("BRG%d:", n);
-
-       if (val & CPM_BRG_RST)
-               puts (" RESET");
-       else
-               puts ("      ");
-
-       if (val & CPM_BRG_EN)
-               puts ("  ENABLED");
-       else
-               puts (" DISABLED");
-
-       printf (" EXTC=%d", extc);
-
-       if (val & CPM_BRG_ATB)
-               puts (" ATB");
-       else
-               puts ("    ");
-
-       printf (" DIVIDER=%4d", cd);
-       if (extc == 0 && cd != 0) {
-               uint baudrate;
-
-               if (div16)
-                       baudrate = (clock / 16) / (cd + 1);
-               else
-                       baudrate = clock / (cd + 1);
-
-               printf ("=%6d bps", baudrate);
-       } else {
-               puts ("           ");
-       }
-
-       if (val & CPM_BRG_DIV16)
-               puts (" DIV16");
-       else
-               puts ("      ");
-
-       putc ('\n');
-}
-
-int
-do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile cpm8xx_t *cp = &immap->im_cpm;
-       volatile uint *p = &cp->cp_brgc1;
-#elif defined(CONFIG_MPC8260)
-       volatile uint *p = &immap->im_brgc1;
-#endif
-       int i = 1;
-
-       while (i <= 4)
-               prbrg (i++, *p++);
-
-#if defined(CONFIG_MPC8260)
-       p = &immap->im_brgc5;
-       while (i <= 8)
-               prbrg (i++, *p++);
-#endif
-       return 0;
-}
-
-int
-do_i2cinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-
-#if defined(CONFIG_8xx)
-       volatile i2c8xx_t *i2c = &immap->im_i2c;
-       volatile cpm8xx_t *cp = &immap->im_cpm;
-       volatile iic_t *iip = (iic_t *) & cp->cp_dparam[PROFF_IIC];
-#elif defined(CONFIG_MPC8260)
-       volatile i2c8260_t *i2c = &immap->im_i2c;
-       volatile iic_t *iip;
-       uint dpaddr;
-
-       dpaddr = immap->im_dprambase16[PROFF_I2C_BASE / sizeof(u16)];
-       if (dpaddr == 0)
-               iip = NULL;
-       else
-               iip = (iic_t *) & immap->im_dprambase[dpaddr];
-#endif
-
-       printf ("I2MOD = %02x I2ADD = %02x\n", i2c->i2c_i2mod, i2c->i2c_i2add);
-       printf ("I2BRG = %02x I2COM = %02x\n", i2c->i2c_i2brg, i2c->i2c_i2com);
-       printf ("I2CER = %02x I2CMR = %02x\n", i2c->i2c_i2cer, i2c->i2c_i2cmr);
-
-       if (iip == NULL)
-               puts ("i2c parameter ram not allocated\n");
-       else {
-               printf ("RBASE = %08x TBASE = %08x\n",
-                       iip->iic_rbase, iip->iic_tbase);
-               printf ("RFCR  =       %02x TFCR  =       %02x\n",
-                       iip->iic_rfcr, iip->iic_tfcr);
-               printf ("MRBLR =     %04x\n", iip->iic_mrblr);
-               printf ("RSTATE= %08x RDP   = %08x\n",
-                       iip->iic_rstate, iip->iic_rdp);
-               printf ("RBPTR =     %04x RBC   =     %04x\n",
-                       iip->iic_rbptr, iip->iic_rbc);
-               printf ("RXTMP = %08x\n", iip->iic_rxtmp);
-               printf ("TSTATE= %08x TDP   = %08x\n",
-                       iip->iic_tstate, iip->iic_tdp);
-               printf ("TBPTR =     %04x TBC   =     %04x\n",
-                       iip->iic_tbptr, iip->iic_tbc);
-               printf ("TXTMP = %08x\n", iip->iic_txtmp);
-       }
-       return 0;
-}
-
-int
-do_sccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_smcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_spiinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_muxinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_siinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-int
-do_mccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unimplemented (cmdtp, flag, argc, argv);
-       return 0;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       siuinfo,        1,      1,      do_siuinfo,
-       "print System Interface Unit (SIU) registers",
-       ""
-);
-
-U_BOOT_CMD(
-       memcinfo,       1,      1,      do_memcinfo,
-       "print Memory Controller registers",
-       ""
-);
-
-U_BOOT_CMD(
-       sitinfo,        1,      1,      do_sitinfo,
-       "print System Integration Timers (SIT) registers",
-       ""
-);
-
-#ifdef CONFIG_MPC8260
-U_BOOT_CMD(
-       icinfo, 1,      1,      do_icinfo,
-       "print Interrupt Controller registers",
-       ""
-);
-#endif
-
-U_BOOT_CMD(
-       carinfo,        1,      1,      do_carinfo,
-       "print Clocks and Reset registers",
-       ""
-);
-
-U_BOOT_CMD(
-       iopinfo,        1,      1,      do_iopinfo,
-       "print I/O Port registers",
-       ""
-);
-
-U_BOOT_CMD(
-       iopset, 5,      0,      do_iopset,
-       "set I/O Port registers",
-       "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
-);
-
-U_BOOT_CMD(
-       dmainfo,        1,      1,      do_dmainfo,
-       "print SDMA/IDMA registers",
-       ""
-);
-
-U_BOOT_CMD(
-       fccinfo,        1,      1,      do_fccinfo,
-       "print FCC registers",
-       ""
-);
-
-U_BOOT_CMD(
-       brginfo,        1,      1,      do_brginfo,
-       "print Baud Rate Generator (BRG) registers",
-       ""
-);
-
-U_BOOT_CMD(
-       i2cinfo,        1,      1,      do_i2cinfo,
-       "print I2C registers",
-       ""
-);
-
-U_BOOT_CMD(
-       sccinfo,        1,      1,      do_sccinfo,
-       "print SCC registers",
-       ""
-);
-
-U_BOOT_CMD(
-       smcinfo,        1,      1,      do_smcinfo,
-       "print SMC registers",
-       ""
-);
-
-U_BOOT_CMD(
-       spiinfo,        1,      1,      do_spiinfo,
-       "print Serial Peripheral Interface (SPI) registers",
-       ""
-);
-
-U_BOOT_CMD(
-       muxinfo,        1,      1,      do_muxinfo,
-       "print CPM Multiplexing registers",
-       ""
-);
-
-U_BOOT_CMD(
-       siinfo, 1,      1,      do_siinfo,
-       "print Serial Interface (SI) registers",
-       ""
-);
-
-U_BOOT_CMD(
-       mccinfo,        1,      1,      do_mccinfo,
-       "print MCC registers",
-       ""
-);
-
-#endif
diff --git a/common/cmd_ini.c b/common/cmd_ini.c
deleted file mode 100644 (file)
index 727fd1c..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * inih -- simple .INI file parser
- *
- * Copyright (c) 2009, Brush Technology
- * Copyright (c) 2012:
- *              Joe Hershberger, National Instruments, joe.hershberger@ni.com
- * All rights reserved.
- *
- * SPDX-License-Identifier:    BSD-3-Clause
- *
- * Go to the project home page for more info:
- * http://code.google.com/p/inih/
- */
-
-#include <common.h>
-#include <command.h>
-#include <environment.h>
-#include <linux/ctype.h>
-#include <linux/string.h>
-
-#ifdef CONFIG_INI_MAX_LINE
-#define MAX_LINE CONFIG_INI_MAX_LINE
-#else
-#define MAX_LINE 200
-#endif
-
-#ifdef CONFIG_INI_MAX_SECTION
-#define MAX_SECTION CONFIG_INI_MAX_SECTION
-#else
-#define MAX_SECTION 50
-#endif
-
-#ifdef CONFIG_INI_MAX_NAME
-#define MAX_NAME CONFIG_INI_MAX_NAME
-#else
-#define MAX_NAME 50
-#endif
-
-/* Strip whitespace chars off end of given string, in place. Return s. */
-static char *rstrip(char *s)
-{
-       char *p = s + strlen(s);
-
-       while (p > s && isspace(*--p))
-               *p = '\0';
-       return s;
-}
-
-/* Return pointer to first non-whitespace char in given string. */
-static char *lskip(const char *s)
-{
-       while (*s && isspace(*s))
-               s++;
-       return (char *)s;
-}
-
-/* Return pointer to first char c or ';' comment in given string, or pointer to
-   null at end of string if neither found. ';' must be prefixed by a whitespace
-   character to register as a comment. */
-static char *find_char_or_comment(const char *s, char c)
-{
-       int was_whitespace = 0;
-
-       while (*s && *s != c && !(was_whitespace && *s == ';')) {
-               was_whitespace = isspace(*s);
-               s++;
-       }
-       return (char *)s;
-}
-
-/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
-static char *strncpy0(char *dest, const char *src, size_t size)
-{
-       strncpy(dest, src, size);
-       dest[size - 1] = '\0';
-       return dest;
-}
-
-/* Emulate the behavior of fgets but on memory */
-static char *memgets(char *str, int num, char **mem, size_t *memsize)
-{
-       char *end;
-       int len;
-       int newline = 1;
-
-       end = memchr(*mem, '\n', *memsize);
-       if (end == NULL) {
-               if (*memsize == 0)
-                       return NULL;
-               end = *mem + *memsize;
-               newline = 0;
-       }
-       len = min((end - *mem) + newline, num);
-       memcpy(str, *mem, len);
-       if (len < num)
-               str[len] = '\0';
-
-       /* prepare the mem vars for the next call */
-       *memsize -= (end - *mem) + newline;
-       *mem += (end - *mem) + newline;
-
-       return str;
-}
-
-/* Parse given INI-style file. May have [section]s, name=value pairs
-   (whitespace stripped), and comments starting with ';' (semicolon). Section
-   is "" if name=value pair parsed before any section heading. name:value
-   pairs are also supported as a concession to Python's ConfigParser.
-
-   For each name=value pair parsed, call handler function with given user
-   pointer as well as section, name, and value (data only valid for duration
-   of handler call). Handler should return nonzero on success, zero on error.
-
-   Returns 0 on success, line number of first error on parse error (doesn't
-   stop on first error).
-*/
-static int ini_parse(char *filestart, size_t filelen,
-       int (*handler)(void *, char *, char *, char *), void *user)
-{
-       /* Uses a fair bit of stack (use heap instead if you need to) */
-       char line[MAX_LINE];
-       char section[MAX_SECTION] = "";
-       char prev_name[MAX_NAME] = "";
-
-       char *curmem = filestart;
-       char *start;
-       char *end;
-       char *name;
-       char *value;
-       size_t memleft = filelen;
-       int lineno = 0;
-       int error = 0;
-
-       /* Scan through file line by line */
-       while (memgets(line, sizeof(line), &curmem, &memleft) != NULL) {
-               lineno++;
-               start = lskip(rstrip(line));
-
-               if (*start == ';' || *start == '#') {
-                       /*
-                        * Per Python ConfigParser, allow '#' comments at start
-                        * of line
-                        */
-               }
-#if CONFIG_INI_ALLOW_MULTILINE
-               else if (*prev_name && *start && start > line) {
-                       /*
-                        * Non-blank line with leading whitespace, treat as
-                        * continuation of previous name's value (as per Python
-                        * ConfigParser).
-                        */
-                       if (!handler(user, section, prev_name, start) && !error)
-                               error = lineno;
-               }
-#endif
-               else if (*start == '[') {
-                       /* A "[section]" line */
-                       end = find_char_or_comment(start + 1, ']');
-                       if (*end == ']') {
-                               *end = '\0';
-                               strncpy0(section, start + 1, sizeof(section));
-                               *prev_name = '\0';
-                       } else if (!error) {
-                               /* No ']' found on section line */
-                               error = lineno;
-                       }
-               } else if (*start && *start != ';') {
-                       /* Not a comment, must be a name[=:]value pair */
-                       end = find_char_or_comment(start, '=');
-                       if (*end != '=')
-                               end = find_char_or_comment(start, ':');
-                       if (*end == '=' || *end == ':') {
-                               *end = '\0';
-                               name = rstrip(start);
-                               value = lskip(end + 1);
-                               end = find_char_or_comment(value, '\0');
-                               if (*end == ';')
-                                       *end = '\0';
-                               rstrip(value);
-                               /* Strip double-quotes */
-                               if (value[0] == '"' &&
-                                   value[strlen(value)-1] == '"') {
-                                       value[strlen(value)-1] = '\0';
-                                       value += 1;
-                               }
-
-                               /*
-                                * Valid name[=:]value pair found, call handler
-                                */
-                               strncpy0(prev_name, name, sizeof(prev_name));
-                               if (!handler(user, section, name, value) &&
-                                    !error)
-                                       error = lineno;
-                       } else if (!error)
-                               /* No '=' or ':' found on name[=:]value line */
-                               error = lineno;
-               }
-       }
-
-       return error;
-}
-
-static int ini_handler(void *user, char *section, char *name, char *value)
-{
-       char *requested_section = (char *)user;
-#ifdef CONFIG_INI_CASE_INSENSITIVE
-       int i;
-
-       for (i = 0; i < strlen(requested_section); i++)
-               requested_section[i] = tolower(requested_section[i]);
-       for (i = 0; i < strlen(section); i++)
-               section[i] = tolower(section[i]);
-#endif
-
-       if (!strcmp(section, requested_section)) {
-#ifdef CONFIG_INI_CASE_INSENSITIVE
-               for (i = 0; i < strlen(name); i++)
-                       name[i] = tolower(name[i]);
-               for (i = 0; i < strlen(value); i++)
-                       value[i] = tolower(value[i]);
-#endif
-               setenv(name, value);
-               printf("ini: Imported %s as %s\n", name, value);
-       }
-
-       /* success */
-       return 1;
-}
-
-static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const char *section;
-       char *file_address;
-       size_t file_size;
-
-       if (argc == 1)
-               return CMD_RET_USAGE;
-
-       section = argv[1];
-       file_address = (char *)simple_strtoul(
-               argc < 3 ? getenv("loadaddr") : argv[2], NULL, 16);
-       file_size = (size_t)simple_strtoul(
-               argc < 4 ? getenv("filesize") : argv[3], NULL, 16);
-
-       return ini_parse(file_address, file_size, ini_handler, (void *)section);
-}
-
-U_BOOT_CMD(
-       ini, 4, 0, do_ini,
-       "parse an ini file in memory and merge the specified section into the env",
-       "section [[file-address] file-size]"
-);
diff --git a/common/cmd_io.c b/common/cmd_io.c
deleted file mode 100644 (file)
index c59148f..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2012 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:     GPL-2.0+
- */
-
-/*
- * IO space access commands.
- */
-
-#include <common.h>
-#include <command.h>
-#include <asm/io.h>
-
-/*
- * IO Display
- *
- * Syntax:
- *     iod{.b, .w, .l} {addr}
- */
-int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       ulong addr;
-       int size;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       size = cmd_get_data_size(argv[0], 4);
-       if (size < 0)
-               return 1;
-
-       addr = simple_strtoul(argv[1], NULL, 16);
-
-       printf("%04x: ", (u16) addr);
-
-       if (size == 4)
-               printf("%08x\n", inl(addr));
-       else if (size == 2)
-               printf("%04x\n", inw(addr));
-       else
-               printf("%02x\n", inb(addr));
-
-       return 0;
-}
-
-int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       ulong addr, size, val;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       size = cmd_get_data_size(argv[0], 4);
-       if (size < 0)
-               return 1;
-
-       addr = simple_strtoul(argv[1], NULL, 16);
-       val = simple_strtoul(argv[2], NULL, 16);
-
-       if (size == 4)
-               outl((u32) val, addr);
-       else if (size == 2)
-               outw((u16) val, addr);
-       else
-               outb((u8) val, addr);
-
-       return 0;
-}
-
-/**************************************************/
-U_BOOT_CMD(iod, 2, 0, do_io_iod,
-          "IO space display", "[.b, .w, .l] address");
-
-U_BOOT_CMD(iow, 3, 0, do_io_iow,
-          "IO space modify",
-          "[.b, .w, .l] address value");
diff --git a/common/cmd_iotrace.c b/common/cmd_iotrace.c
deleted file mode 100644 (file)
index f54276d..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2014 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <iotrace.h>
-
-static void do_print_stats(void)
-{
-       ulong start, size, offset, count;
-
-       printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
-       iotrace_get_buffer(&start, &size, &offset, &count);
-       printf("Start:  %08lx\n", start);
-       printf("Size:   %08lx\n", size);
-       printf("Offset: %08lx\n", offset);
-       printf("Output: %08lx\n", start + offset);
-       printf("Count:  %08lx\n", count);
-       printf("CRC32:  %08lx\n", (ulong)iotrace_get_checksum());
-}
-
-static int do_set_buffer(int argc, char * const argv[])
-{
-       ulong addr = 0, size = 0;
-
-       if (argc == 2) {
-               addr = simple_strtoul(*argv++, NULL, 16);
-               size = simple_strtoul(*argv++, NULL, 16);
-       } else if (argc != 0) {
-               return CMD_RET_USAGE;
-       }
-
-       iotrace_set_buffer(addr, size);
-
-       return 0;
-}
-
-int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const char *cmd = argc < 2 ? NULL : argv[1];
-
-       if (!cmd)
-               return cmd_usage(cmdtp);
-       switch (*cmd) {
-       case 'b':
-               return do_set_buffer(argc - 2, argv + 2);
-       case 'p':
-               iotrace_set_enabled(0);
-               break;
-       case 'r':
-               iotrace_set_enabled(1);
-               break;
-       case 's':
-               do_print_stats();
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       iotrace,        4,      1,      do_iotrace,
-       "iotrace utility commands",
-       "stats                        - display iotrace stats\n"
-       "iotrace buffer <address> <size>      - set iotrace buffer\n"
-       "iotrace pause                        - pause tracing\n"
-       "iotrace resume                       - resume tracing"
-);
diff --git a/common/cmd_irq.c b/common/cmd_irq.c
deleted file mode 100644 (file)
index 02da450..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2008 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-
-static int do_interrupts(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char * const argv[])
-{
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       /* on */
-       if (strncmp(argv[1], "on", 2) == 0)
-               enable_interrupts();
-       else
-               disable_interrupts();
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       interrupts, 5, 0, do_interrupts,
-       "enable or disable interrupts",
-       "[on, off]"
-);
-
-/* Implemented in $(CPU)/interrupts.c */
-int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
-U_BOOT_CMD(
-       irqinfo,    1,    1,     do_irqinfo,
-       "print information about IRQs",
-       ""
-);
diff --git a/common/cmd_itest.c b/common/cmd_itest.c
deleted file mode 100644 (file)
index 91ae5c2..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * (C) Copyright 2003
- * Tait Electronics Limited, Christchurch, New Zealand
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * This file provides a shell like 'test' function to return
- * true/false from an integer or string compare of two memory
- * locations or a location and a scalar/literal.
- * A few parts were lifted from bash 'test' command
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <mapmem.h>
-
-#include <asm/io.h>
-
-#define EQ     0
-#define NE     1
-#define LT     2
-#define GT     3
-#define LE     4
-#define GE     5
-
-struct op_tbl_s {
-       char    *op;            /* operator string */
-       int     opcode;         /* internal representation of opcode */
-};
-
-typedef struct op_tbl_s op_tbl_t;
-
-static const op_tbl_t op_table [] = {
-       { "-lt", LT },
-       { "<"  , LT },
-       { "-gt", GT },
-       { ">"  , GT },
-       { "-eq", EQ },
-       { "==" , EQ },
-       { "-ne", NE },
-       { "!=" , NE },
-       { "<>" , NE },
-       { "-ge", GE },
-       { ">=" , GE },
-       { "-le", LE },
-       { "<=" , LE },
-};
-
-static long evalexp(char *s, int w)
-{
-       long l = 0;
-       unsigned long addr;
-       void *buf;
-
-       /* if the parameter starts with a * then assume is a pointer to the value we want */
-       if (s[0] == '*') {
-               addr = simple_strtoul(&s[1], NULL, 16);
-               buf = map_physmem(addr, w, MAP_WRBACK);
-               if (!buf) {
-                       puts("Failed to map physical memory\n");
-                       return 0;
-               }
-               switch (w) {
-               case 1:
-                       l = (long)(*(unsigned char *)buf);
-                       break;
-               case 2:
-                       l = (long)(*(unsigned short *)buf);
-                       break;
-               case 4:
-                       l = (long)(*(unsigned long *)buf);
-                       break;
-               }
-               unmap_physmem(buf, w);
-               return l;
-       } else {
-               l = simple_strtoul(s, NULL, 16);
-       }
-
-       return l & ((1UL << (w * 8)) - 1);
-}
-
-static char * evalstr(char *s)
-{
-       /* if the parameter starts with a * then assume a string pointer else its a literal */
-       if (s[0] == '*') {
-               return (char *)simple_strtoul(&s[1], NULL, 16);
-       } else if (s[0] == '$') {
-               int i = 2;
-
-               if (s[1] != '{')
-                       return NULL;
-
-               while (s[i] != '}') {
-                       if (s[i] == 0)
-                               return NULL;
-                       i++;
-               }
-               s[i] = 0;
-               return  getenv((const char *)&s[2]);
-       } else {
-               return s;
-       }
-}
-
-static int stringcomp(char *s, char *t, int op)
-{
-       int p;
-       char *l, *r;
-
-       l = evalstr(s);
-       r = evalstr(t);
-
-       p = strcmp(l, r);
-       switch (op) {
-       case EQ: return (p == 0);
-       case NE: return (p != 0);
-       case LT: return (p < 0);
-       case GT: return (p > 0);
-       case LE: return (p <= 0);
-       case GE: return (p >= 0);
-       }
-       return (0);
-}
-
-static int arithcomp (char *s, char *t, int op, int w)
-{
-       long l, r;
-
-       l = evalexp (s, w);
-       r = evalexp (t, w);
-
-       switch (op) {
-       case EQ: return (l == r);
-       case NE: return (l != r);
-       case LT: return (l < r);
-       case GT: return (l > r);
-       case LE: return (l <= r);
-       case GE: return (l >= r);
-       }
-       return (0);
-}
-
-static int binary_test(char *op, char *arg1, char *arg2, int w)
-{
-       int len, i;
-       const op_tbl_t *optp;
-
-       len = strlen(op);
-
-       for (optp = (op_tbl_t *)&op_table, i = 0;
-            i < ARRAY_SIZE(op_table);
-            optp++, i++) {
-
-               if ((strncmp (op, optp->op, len) == 0) && (len == strlen (optp->op))) {
-                       if (w == 0) {
-                               return (stringcomp(arg1, arg2, optp->opcode));
-                       } else {
-                               return (arithcomp (arg1, arg2, optp->opcode, w));
-                       }
-               }
-       }
-
-       printf("Unknown operator '%s'\n", op);
-       return 0;       /* op code not found */
-}
-
-/* command line interface to the shell test */
-static int do_itest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int     value, w;
-
-       /* Validate arguments */
-       if ((argc != 4))
-               return CMD_RET_USAGE;
-
-       /* Check for a data width specification.
-        * Defaults to long (4) if no specification.
-        * Uses -2 as 'width' for .s (string) so as not to upset existing code
-        */
-       switch (w = cmd_get_data_size(argv[0], 4)) {
-       case 1:
-       case 2:
-       case 4:
-               value = binary_test (argv[2], argv[1], argv[3], w);
-               break;
-       case -2:
-               value = binary_test (argv[2], argv[1], argv[3], 0);
-               break;
-       case -1:
-       default:
-               puts("Invalid data width specifier\n");
-               value = 0;
-               break;
-       }
-
-       return !value;
-}
-
-U_BOOT_CMD(
-       itest, 4, 0, do_itest,
-       "return true/false on integer compare",
-       "[.b, .w, .l, .s] [*]value1 <op> [*]value2"
-);
diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
deleted file mode 100644 (file)
index bce0983..0000000
+++ /dev/null
@@ -1,619 +0,0 @@
-/*
- * (C) Copyright 2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * (C) Copyright 2002
- * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
- *
- * (C) Copyright 2003
- * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
- *
- * (C) Copyright 2005
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- *   Added support for reading flash partition table from environment.
- *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
- *   kernel tree.
- *
- *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
- *   Copyright 2002 SYSGO Real-Time Solutions GmbH
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Three environment variables are used by the parsing routines:
- *
- * 'partition' - keeps current partition identifier
- *
- * partition  := <part-id>
- * <part-id>  := <dev-id>,part_num
- *
- *
- * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
- *
- * mtdids=<idmap>[,<idmap>,...]
- *
- * <idmap>    := <dev-id>=<mtd-id>
- * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
- * <dev-num>  := mtd device number, 0...
- * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
- *
- *
- * 'mtdparts' - partition list
- *
- * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
- *
- * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
- * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
- * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
- * <size>     := standard linux memsize OR '-' to denote all remaining space
- * <offset>   := partition start offset within the device
- * <name>     := '(' NAME ')'
- * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
- *
- * Notes:
- * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
- * - if the above variables are not set defaults for a given target are used
- *
- * Examples:
- *
- * 1 NOR Flash, with 1 single writable partition:
- * mtdids=nor0=edb7312-nor
- * mtdparts=mtdparts=edb7312-nor:-
- *
- * 1 NOR Flash with 2 partitions, 1 NAND with one
- * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
- * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
- *
- */
-
-/*
- * JFFS2/CRAMFS support
- */
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <jffs2/jffs2.h>
-#include <linux/list.h>
-#include <linux/ctype.h>
-#include <cramfs/cramfs_fs.h>
-
-#if defined(CONFIG_CMD_NAND)
-#include <linux/mtd/nand.h>
-#include <nand.h>
-#endif
-
-#if defined(CONFIG_CMD_ONENAND)
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/onenand.h>
-#include <onenand_uboot.h>
-#endif
-
-/* enable/disable debugging messages */
-#define        DEBUG_JFFS
-#undef DEBUG_JFFS
-
-#ifdef  DEBUG_JFFS
-# define DEBUGF(fmt, args...)  printf(fmt ,##args)
-#else
-# define DEBUGF(fmt, args...)
-#endif
-
-/* special size referring to all the remaining space in a partition */
-#define SIZE_REMAINING         0xFFFFFFFF
-
-/* special offset value, it is used when not provided by user
- *
- * this value is used temporarily during parsing, later such offests
- * are recalculated */
-#define OFFSET_NOT_SPECIFIED   0xFFFFFFFF
-
-/* minimum partition size */
-#define MIN_PART_SIZE          4096
-
-/* this flag needs to be set in part_info struct mask_flags
- * field for read-only partitions */
-#define MTD_WRITEABLE_CMD              1
-
-/* current active device and partition number */
-#ifdef CONFIG_CMD_MTDPARTS
-/* Use the ones declared in cmd_mtdparts.c */
-extern struct mtd_device *current_mtd_dev;
-extern u8 current_mtd_partnum;
-#else
-/* Use local ones */
-struct mtd_device *current_mtd_dev = NULL;
-u8 current_mtd_partnum = 0;
-#endif
-
-#if defined(CONFIG_CMD_CRAMFS)
-extern int cramfs_check (struct part_info *info);
-extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
-extern int cramfs_ls (struct part_info *info, char *filename);
-extern int cramfs_info (struct part_info *info);
-#else
-/* defining empty macros for function names is ugly but avoids ifdef clutter
- * all over the code */
-#define cramfs_check(x)                (0)
-#define cramfs_load(x,y,z)     (-1)
-#define cramfs_ls(x,y)         (0)
-#define cramfs_info(x)         (0)
-#endif
-
-#ifndef CONFIG_CMD_MTDPARTS
-/**
- * Check device number to be within valid range for given device type.
- *
- * @param dev device to validate
- * @return 0 if device is valid, 1 otherwise
- */
-static int mtd_device_validate(u8 type, u8 num, u32 *size)
-{
-       if (type == MTD_DEV_TYPE_NOR) {
-#if defined(CONFIG_CMD_FLASH)
-               if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
-                       extern flash_info_t flash_info[];
-                       *size = flash_info[num].size;
-
-                       return 0;
-               }
-
-               printf("no such FLASH device: %s%d (valid range 0 ... %d\n",
-                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
-#else
-               printf("support for FLASH devices not present\n");
-#endif
-       } else if (type == MTD_DEV_TYPE_NAND) {
-#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
-               if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
-                       *size = nand_info[num].size;
-                       return 0;
-               }
-
-               printf("no such NAND device: %s%d (valid range 0 ... %d)\n",
-                               MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
-#else
-               printf("support for NAND devices not present\n");
-#endif
-       } else if (type == MTD_DEV_TYPE_ONENAND) {
-#if defined(CONFIG_CMD_ONENAND)
-               *size = onenand_mtd.size;
-               return 0;
-#else
-               printf("support for OneNAND devices not present\n");
-#endif
-       } else
-               printf("Unknown defice type %d\n", type);
-
-       return 1;
-}
-
-/**
- * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
- * return device type and number.
- *
- * @param id string describing device id
- * @param ret_id output pointer to next char after parse completes (output)
- * @param dev_type parsed device type (output)
- * @param dev_num parsed device number (output)
- * @return 0 on success, 1 otherwise
- */
-static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
-{
-       const char *p = id;
-
-       *dev_type = 0;
-       if (strncmp(p, "nand", 4) == 0) {
-               *dev_type = MTD_DEV_TYPE_NAND;
-               p += 4;
-       } else if (strncmp(p, "nor", 3) == 0) {
-               *dev_type = MTD_DEV_TYPE_NOR;
-               p += 3;
-       } else if (strncmp(p, "onenand", 7) == 0) {
-               *dev_type = MTD_DEV_TYPE_ONENAND;
-               p += 7;
-       } else {
-               printf("incorrect device type in %s\n", id);
-               return 1;
-       }
-
-       if (!isdigit(*p)) {
-               printf("incorrect device number in %s\n", id);
-               return 1;
-       }
-
-       *dev_num = simple_strtoul(p, (char **)&p, 0);
-       if (ret_id)
-               *ret_id = p;
-       return 0;
-}
-
-/*
- * 'Static' version of command line mtdparts_init() routine. Single partition on
- * a single device configuration.
- */
-
-/**
- * Calculate sector size.
- *
- * @return sector size
- */
-static inline u32 get_part_sector_size_nand(struct mtdids *id)
-{
-#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
-       nand_info_t *nand;
-
-       nand = &nand_info[id->num];
-
-       return nand->erasesize;
-#else
-       BUG();
-       return 0;
-#endif
-}
-
-static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *part)
-{
-#if defined(CONFIG_CMD_FLASH)
-       extern flash_info_t flash_info[];
-
-       u32 end_phys, start_phys, sector_size = 0, size = 0;
-       int i;
-       flash_info_t *flash;
-
-       flash = &flash_info[id->num];
-
-       start_phys = flash->start[0] + part->offset;
-       end_phys = start_phys + part->size - 1;
-
-       for (i = 0; i < flash->sector_count; i++) {
-               if (flash->start[i] >= end_phys)
-                       break;
-
-               if (flash->start[i] >= start_phys) {
-                       if (i == flash->sector_count - 1) {
-                               size = flash->start[0] + flash->size - flash->start[i];
-                       } else {
-                               size = flash->start[i+1] - flash->start[i];
-                       }
-
-                       if (sector_size < size)
-                               sector_size = size;
-               }
-       }
-
-       return sector_size;
-#else
-       BUG();
-       return 0;
-#endif
-}
-
-static inline u32 get_part_sector_size_onenand(void)
-{
-#if defined(CONFIG_CMD_ONENAND)
-       struct mtd_info *mtd;
-
-       mtd = &onenand_mtd;
-
-       return mtd->erasesize;
-#else
-       BUG();
-       return 0;
-#endif
-}
-
-static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part)
-{
-       if (id->type == MTD_DEV_TYPE_NAND)
-               return get_part_sector_size_nand(id);
-       else if (id->type == MTD_DEV_TYPE_NOR)
-               return get_part_sector_size_nor(id, part);
-       else if (id->type == MTD_DEV_TYPE_ONENAND)
-               return get_part_sector_size_onenand();
-       else
-               DEBUGF("Error: Unknown device type.\n");
-
-       return 0;
-}
-
-/**
- * Parse and initialize global mtdids mapping and create global
- * device/partition list.
- *
- * 'Static' version of command line mtdparts_init() routine. Single partition on
- * a single device configuration.
- *
- * @return 0 on success, 1 otherwise
- */
-int mtdparts_init(void)
-{
-       static int initialized = 0;
-       u32 size;
-       char *dev_name;
-
-       DEBUGF("\n---mtdparts_init---\n");
-       if (!initialized) {
-               struct mtdids *id;
-               struct part_info *part;
-
-               initialized = 1;
-               current_mtd_dev = (struct mtd_device *)
-                       malloc(sizeof(struct mtd_device) +
-                                       sizeof(struct part_info) +
-                                       sizeof(struct mtdids));
-               if (!current_mtd_dev) {
-                       printf("out of memory\n");
-                       return 1;
-               }
-               memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
-                      sizeof(struct part_info) + sizeof(struct mtdids));
-
-               id = (struct mtdids *)(current_mtd_dev + 1);
-               part = (struct part_info *)(id + 1);
-
-               /* id */
-               id->mtd_id = "single part";
-
-#if defined(CONFIG_JFFS2_DEV)
-               dev_name = CONFIG_JFFS2_DEV;
-#else
-               dev_name = "nor0";
-#endif
-
-               if ((mtd_id_parse(dev_name, NULL, &id->type, &id->num) != 0) ||
-                               (mtd_device_validate(id->type, id->num, &size) != 0)) {
-                       printf("incorrect device: %s%d\n", MTD_DEV_TYPE(id->type), id->num);
-                       free(current_mtd_dev);
-                       return 1;
-               }
-               id->size = size;
-               INIT_LIST_HEAD(&id->link);
-
-               DEBUGF("dev id: type = %d, num = %d, size = 0x%08lx, mtd_id = %s\n",
-                               id->type, id->num, id->size, id->mtd_id);
-
-               /* partition */
-               part->name = "static";
-               part->auto_name = 0;
-
-#if defined(CONFIG_JFFS2_PART_SIZE)
-               part->size = CONFIG_JFFS2_PART_SIZE;
-#else
-               part->size = SIZE_REMAINING;
-#endif
-
-#if defined(CONFIG_JFFS2_PART_OFFSET)
-               part->offset = CONFIG_JFFS2_PART_OFFSET;
-#else
-               part->offset = 0x00000000;
-#endif
-
-               part->dev = current_mtd_dev;
-               INIT_LIST_HEAD(&part->link);
-
-               /* recalculate size if needed */
-               if (part->size == SIZE_REMAINING)
-                       part->size = id->size - part->offset;
-
-               part->sector_size = get_part_sector_size(id, part);
-
-               DEBUGF("part  : name = %s, size = 0x%08lx, offset = 0x%08lx\n",
-                               part->name, part->size, part->offset);
-
-               /* device */
-               current_mtd_dev->id = id;
-               INIT_LIST_HEAD(&current_mtd_dev->link);
-               current_mtd_dev->num_parts = 1;
-               INIT_LIST_HEAD(&current_mtd_dev->parts);
-               list_add(&part->link, &current_mtd_dev->parts);
-       }
-
-       return 0;
-}
-#endif /* #ifndef CONFIG_CMD_MTDPARTS */
-
-/**
- * Return pointer to the partition of a requested number from a requested
- * device.
- *
- * @param dev device that is to be searched for a partition
- * @param part_num requested partition number
- * @return pointer to the part_info, NULL otherwise
- */
-static struct part_info* jffs2_part_info(struct mtd_device *dev, unsigned int part_num)
-{
-       struct list_head *entry;
-       struct part_info *part;
-       int num;
-
-       if (!dev)
-               return NULL;
-
-       DEBUGF("\n--- jffs2_part_info: partition number %d for device %s%d (%s)\n",
-                       part_num, MTD_DEV_TYPE(dev->id->type),
-                       dev->id->num, dev->id->mtd_id);
-
-       if (part_num >= dev->num_parts) {
-               printf("invalid partition number %d for device %s%d (%s)\n",
-                               part_num, MTD_DEV_TYPE(dev->id->type),
-                               dev->id->num, dev->id->mtd_id);
-               return NULL;
-       }
-
-       /* locate partition number, return it */
-       num = 0;
-       list_for_each(entry, &dev->parts) {
-               part = list_entry(entry, struct part_info, link);
-
-               if (part_num == num++) {
-                       return part;
-               }
-       }
-
-       return NULL;
-}
-
-/***************************************************/
-/* U-boot commands                                */
-/***************************************************/
-
-/**
- * Routine implementing fsload u-boot command. This routine tries to load
- * a requested file from jffs2/cramfs filesystem on a current partition.
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *fsname;
-       char *filename;
-       int size;
-       struct part_info *part;
-       ulong offset = load_addr;
-
-       /* pre-set Boot file name */
-       if ((filename = getenv("bootfile")) == NULL) {
-               filename = "uImage";
-       }
-
-       if (argc == 2) {
-               filename = argv[1];
-       }
-       if (argc == 3) {
-               offset = simple_strtoul(argv[1], NULL, 16);
-               load_addr = offset;
-               filename = argv[2];
-       }
-
-       /* make sure we are in sync with env variables */
-       if (mtdparts_init() !=0)
-               return 1;
-
-       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
-
-               /* check partition type for cramfs */
-               fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
-               printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
-
-               if (cramfs_check(part)) {
-                       size = cramfs_load ((char *) offset, part, filename);
-               } else {
-                       /* if this is not cramfs assume jffs2 */
-                       size = jffs2_1pass_load((char *)offset, part, filename);
-               }
-
-               if (size > 0) {
-                       printf("### %s load complete: %d bytes loaded to 0x%lx\n",
-                               fsname, size, offset);
-                       setenv_hex("filesize", size);
-               } else {
-                       printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
-               }
-
-               return !(size > 0);
-       }
-       return 1;
-}
-
-/**
- * Routine implementing u-boot ls command which lists content of a given
- * directory on a current partition.
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename = "/";
-       int ret;
-       struct part_info *part;
-
-       if (argc == 2)
-               filename = argv[1];
-
-       /* make sure we are in sync with env variables */
-       if (mtdparts_init() !=0)
-               return 1;
-
-       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
-
-               /* check partition type for cramfs */
-               if (cramfs_check(part)) {
-                       ret = cramfs_ls (part, filename);
-               } else {
-                       /* if this is not cramfs assume jffs2 */
-                       ret = jffs2_1pass_ls(part, filename);
-               }
-
-               return ret ? 0 : 1;
-       }
-       return 1;
-}
-
-/**
- * Routine implementing u-boot fsinfo command. This routine prints out
- * miscellaneous filesystem informations/statistics.
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct part_info *part;
-       char *fsname;
-       int ret;
-
-       /* make sure we are in sync with env variables */
-       if (mtdparts_init() !=0)
-               return 1;
-
-       if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
-
-               /* check partition type for cramfs */
-               fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
-               printf("### filesystem type is %s\n", fsname);
-
-               if (cramfs_check(part)) {
-                       ret = cramfs_info (part);
-               } else {
-                       /* if this is not cramfs assume jffs2 */
-                       ret = jffs2_1pass_info(part);
-               }
-
-               return ret ? 0 : 1;
-       }
-       return 1;
-}
-
-/***************************************************/
-U_BOOT_CMD(
-       fsload, 3,      0,      do_jffs2_fsload,
-       "load binary file from a filesystem image",
-       "[ off ] [ filename ]\n"
-       "    - load binary file from flash bank\n"
-       "      with offset 'off'"
-);
-U_BOOT_CMD(
-       ls,     2,      1,      do_jffs2_ls,
-       "list files in a directory (default /)",
-       "[ directory ]"
-);
-
-U_BOOT_CMD(
-       fsinfo, 1,      1,      do_jffs2_fsinfo,
-       "print information about filesystems",
-       ""
-);
-/***************************************************/
diff --git a/common/cmd_ldrinfo.c b/common/cmd_ldrinfo.c
deleted file mode 100644 (file)
index 2aa56bd..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * U-boot - ldrinfo
- *
- * Copyright (c) 2010 Analog Devices Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <config.h>
-#include <common.h>
-#include <command.h>
-
-#include <asm/blackfin.h>
-#include <asm/mach-common/bits/bootrom.h>
-
-static uint32_t ldrinfo_header(const void *addr)
-{
-       uint32_t skip = 0;
-
-#if defined(__ADSPBF561__)
-       /* BF56x has a 4 byte global header */
-       uint32_t header, sign;
-       static const char * const spi_speed[] = {
-               "500K", "1M", "2M", "??",
-       };
-
-       memcpy(&header, addr, sizeof(header));
-
-       sign = (header & GFLAG_56X_SIGN_MASK) >> GFLAG_56X_SIGN_SHIFT;
-       printf("Header: %08X ( %s-bit-flash wait:%i hold:%i spi:%s %s)\n",
-               header,
-               (header & GFLAG_56X_16BIT_FLASH) ? "16" : "8",
-               (header & GFLAG_56X_WAIT_MASK) >> GFLAG_56X_WAIT_SHIFT,
-               (header & GFLAG_56X_HOLD_MASK) >> GFLAG_56X_HOLD_SHIFT,
-               spi_speed[(header & GFLAG_56X_SPI_MASK) >> GFLAG_56X_SPI_SHIFT],
-               sign == GFLAG_56X_SIGN_MAGIC ? "" : "!!hdrsign!! ");
-
-       skip = 4;
-#endif
-
-           /* |Block @ 12345678: 12345678 12345678 12345678 12345678 | */
-#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
-    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
-    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
-       printf("                  Address  Count    Flags\n");
-#else
-       printf("                  BCode    Address  Count    Argument\n");
-#endif
-
-       return skip;
-}
-
-struct ldr_flag {
-       uint16_t flag;
-       const char *desc;
-};
-
-static uint32_t ldrinfo_block(const void *base_addr)
-{
-       uint32_t count;
-
-       printf("Block @ %08X: ", (uint32_t)base_addr);
-
-#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
-    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
-    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
-
-       uint32_t addr, pval;
-       uint16_t flags;
-       int i;
-       static const struct ldr_flag ldr_flags[] = {
-               { BFLAG_53X_ZEROFILL,    "zerofill"  },
-               { BFLAG_53X_RESVECT,     "resvect"   },
-               { BFLAG_53X_INIT,        "init"      },
-               { BFLAG_53X_IGNORE,      "ignore"    },
-               { BFLAG_53X_COMPRESSED,  "compressed"},
-               { BFLAG_53X_FINAL,       "final"     },
-       };
-
-       memcpy(&addr, base_addr, sizeof(addr));
-       memcpy(&count, base_addr+4, sizeof(count));
-       memcpy(&flags, base_addr+8, sizeof(flags));
-
-       printf("%08X %08X %04X ( ", addr, count, flags);
-
-       for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
-               if (flags & ldr_flags[i].flag)
-                       printf("%s ", ldr_flags[i].desc);
-
-       pval = (flags & BFLAG_53X_PFLAG_MASK) >> BFLAG_53X_PFLAG_SHIFT;
-       if (pval)
-               printf("gpio%i ", pval);
-       pval = (flags & BFLAG_53X_PPORT_MASK) >> BFLAG_53X_PPORT_SHIFT;
-       if (pval)
-               printf("port%c ", 'e' + pval);
-
-       if (flags & BFLAG_53X_ZEROFILL)
-               count = 0;
-       if (flags & BFLAG_53X_FINAL)
-               count = 0;
-       else
-               count += sizeof(addr) + sizeof(count) + sizeof(flags);
-
-#else
-
-       const uint8_t *raw8 = base_addr;
-       uint32_t bcode, addr, arg, sign, chk;
-       int i;
-       static const struct ldr_flag ldr_flags[] = {
-               { BFLAG_SAFE,        "safe"      },
-               { BFLAG_AUX,         "aux"       },
-               { BFLAG_FILL,        "fill"      },
-               { BFLAG_QUICKBOOT,   "quickboot" },
-               { BFLAG_CALLBACK,    "callback"  },
-               { BFLAG_INIT,        "init"      },
-               { BFLAG_IGNORE,      "ignore"    },
-               { BFLAG_INDIRECT,    "indirect"  },
-               { BFLAG_FIRST,       "first"     },
-               { BFLAG_FINAL,       "final"     },
-       };
-
-       memcpy(&bcode, base_addr, sizeof(bcode));
-       memcpy(&addr, base_addr+4, sizeof(addr));
-       memcpy(&count, base_addr+8, sizeof(count));
-       memcpy(&arg, base_addr+12, sizeof(arg));
-
-       printf("%08X %08X %08X %08X ( ", bcode, addr, count, arg);
-
-       if (addr % 4)
-               printf("!!addralgn!! ");
-       if (count % 4)
-               printf("!!cntalgn!! ");
-
-       sign = (bcode & BFLAG_HDRSIGN_MASK) >> BFLAG_HDRSIGN_SHIFT;
-       if (sign != BFLAG_HDRSIGN_MAGIC)
-               printf("!!hdrsign!! ");
-
-       chk = 0;
-       for (i = 0; i < 16; ++i)
-               chk ^= raw8[i];
-       if (chk)
-               printf("!!hdrchk!! ");
-
-       printf("dma:%i ", bcode & BFLAG_DMACODE_MASK);
-
-       for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
-               if (bcode & ldr_flags[i].flag)
-                       printf("%s ", ldr_flags[i].desc);
-
-       if (bcode & BFLAG_FILL)
-               count = 0;
-       if (bcode & BFLAG_FINAL)
-               count = 0;
-       else
-               count += sizeof(bcode) + sizeof(addr) + sizeof(count) + sizeof(arg);
-
-#endif
-
-       printf(")\n");
-
-       return count;
-}
-
-static int do_ldrinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const void *addr;
-       uint32_t skip;
-
-       /* Get the address */
-       if (argc < 2)
-               addr = (void *)load_addr;
-       else
-               addr = (void *)simple_strtoul(argv[1], NULL, 16);
-
-       /* Walk the LDR */
-       addr += ldrinfo_header(addr);
-       do {
-               skip = ldrinfo_block(addr);
-               addr += skip;
-       } while (skip);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       ldrinfo, 2, 0, do_ldrinfo,
-       "validate ldr image in memory",
-       "[addr]\n"
-);
diff --git a/common/cmd_led.c b/common/cmd_led.c
deleted file mode 100644 (file)
index b0f1a61..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * (C) Copyright 2010
- * Jason Kridner <jkridner@beagleboard.org>
- *
- * Based on cmd_led.c patch from:
- * http://www.mail-archive.com/u-boot@lists.denx.de/msg06873.html
- * (C) Copyright 2008
- * Ulf Samuelsson <ulf.samuelsson@atmel.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <status_led.h>
-
-struct led_tbl_s {
-       char            *string;        /* String for use in the command */
-       led_id_t        mask;           /* Mask used for calling __led_set() */
-       void            (*off)(void);   /* Optional function for turning LED off */
-       void            (*on)(void);    /* Optional function for turning LED on */
-       void            (*toggle)(void);/* Optional function for toggling LED */
-};
-
-typedef struct led_tbl_s led_tbl_t;
-
-static const led_tbl_t led_commands[] = {
-#ifdef CONFIG_BOARD_SPECIFIC_LED
-#ifdef STATUS_LED_BIT
-       { "0", STATUS_LED_BIT, NULL, NULL, NULL },
-#endif
-#ifdef STATUS_LED_BIT1
-       { "1", STATUS_LED_BIT1, NULL, NULL, NULL },
-#endif
-#ifdef STATUS_LED_BIT2
-       { "2", STATUS_LED_BIT2, NULL, NULL, NULL },
-#endif
-#ifdef STATUS_LED_BIT3
-       { "3", STATUS_LED_BIT3, NULL, NULL, NULL },
-#endif
-#ifdef STATUS_LED_BIT4
-       { "4", STATUS_LED_BIT4, NULL, NULL, NULL },
-#endif
-#ifdef STATUS_LED_BIT5
-       { "5", STATUS_LED_BIT5, NULL, NULL, NULL },
-#endif
-#endif
-#ifdef STATUS_LED_GREEN
-       { "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
-#endif
-#ifdef STATUS_LED_YELLOW
-       { "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
-#endif
-#ifdef STATUS_LED_RED
-       { "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
-#endif
-#ifdef STATUS_LED_BLUE
-       { "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
-#endif
-       { NULL, 0, NULL, NULL, NULL }
-};
-
-enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
-
-enum led_cmd get_led_cmd(char *var)
-{
-       if (strcmp(var, "off") == 0)
-               return LED_OFF;
-       if (strcmp(var, "on") == 0)
-               return LED_ON;
-       if (strcmp(var, "toggle") == 0)
-               return LED_TOGGLE;
-       if (strcmp(var, "blink") == 0)
-               return LED_BLINK;
-
-       return -1;
-}
-
-/*
- * LED drivers providing a blinking LED functionality, like the
- * PCA9551, can override this empty weak function
- */
-void __weak __led_blink(led_id_t mask, int freq)
-{
-}
-
-int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i, match = 0;
-       enum led_cmd cmd;
-       int freq;
-
-       /* Validate arguments */
-       if ((argc < 3) || (argc > 4))
-               return CMD_RET_USAGE;
-
-       cmd = get_led_cmd(argv[2]);
-       if (cmd < 0) {
-               return CMD_RET_USAGE;
-       }
-
-       for (i = 0; led_commands[i].string; i++) {
-               if ((strcmp("all", argv[1]) == 0) ||
-                   (strcmp(led_commands[i].string, argv[1]) == 0)) {
-                       match = 1;
-                       switch (cmd) {
-                       case LED_ON:
-                               if (led_commands[i].on)
-                                       led_commands[i].on();
-                               else
-                                       __led_set(led_commands[i].mask,
-                                                         STATUS_LED_ON);
-                               break;
-                       case LED_OFF:
-                               if (led_commands[i].off)
-                                       led_commands[i].off();
-                               else
-                                       __led_set(led_commands[i].mask,
-                                                         STATUS_LED_OFF);
-                               break;
-                       case LED_TOGGLE:
-                               if (led_commands[i].toggle)
-                                       led_commands[i].toggle();
-                               else
-                                       __led_toggle(led_commands[i].mask);
-                               break;
-                       case LED_BLINK:
-                               if (argc != 4)
-                                       return CMD_RET_USAGE;
-
-                               freq = simple_strtoul(argv[3], NULL, 10);
-                               __led_blink(led_commands[i].mask, freq);
-                       }
-                       /* Need to set only 1 led if led_name wasn't 'all' */
-                       if (strcmp("all", argv[1]) != 0)
-                               break;
-               }
-       }
-
-       /* If we ran out of matches, print Usage */
-       if (!match) {
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       led, 4, 1, do_led,
-       "["
-#ifdef CONFIG_BOARD_SPECIFIC_LED
-#ifdef STATUS_LED_BIT
-       "0|"
-#endif
-#ifdef STATUS_LED_BIT1
-       "1|"
-#endif
-#ifdef STATUS_LED_BIT2
-       "2|"
-#endif
-#ifdef STATUS_LED_BIT3
-       "3|"
-#endif
-#ifdef STATUS_LED_BIT4
-       "4|"
-#endif
-#ifdef STATUS_LED_BIT5
-       "5|"
-#endif
-#endif
-#ifdef STATUS_LED_GREEN
-       "green|"
-#endif
-#ifdef STATUS_LED_YELLOW
-       "yellow|"
-#endif
-#ifdef STATUS_LED_RED
-       "red|"
-#endif
-#ifdef STATUS_LED_BLUE
-       "blue|"
-#endif
-       "all] [on|off|toggle|blink] [blink-freq in ms]",
-       "[led_name] [on|off|toggle|blink] sets or clears led(s)"
-);
diff --git a/common/cmd_license.c b/common/cmd_license.c
deleted file mode 100644 (file)
index b07de72..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * (C) Copyright 2007 by OpenMoko, Inc.
- * Author: Harald Welte <laforge@openmoko.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-
-/* COPYING is currently 15951 bytes in size */
-#define LICENSE_MAX    20480
-
-#include <command.h>
-#include <malloc.h>
-#include <license.h>
-
-int do_license(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *tok, *dst = malloc(LICENSE_MAX);
-       unsigned long len = LICENSE_MAX;
-
-       if (!dst)
-               return -1;
-
-       if (gunzip(dst, LICENSE_MAX, license_gz, &len) != 0) {
-               printf("Error uncompressing license text\n");
-               free(dst);
-               return -1;
-       }
-       puts(dst);
-       free(dst);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       license, 1, 1, do_license,
-       "print GPL license text",
-       ""
-);
diff --git a/common/cmd_load.c b/common/cmd_load.c
deleted file mode 100644 (file)
index 0aa7937..0000000
+++ /dev/null
@@ -1,1113 +0,0 @@
-/*
- * (C) Copyright 2000-2004
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Serial up- and download support
- */
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <s_record.h>
-#include <net.h>
-#include <exports.h>
-#include <xyzModem.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#if defined(CONFIG_CMD_LOADB)
-static ulong load_serial_ymodem(ulong offset, int mode);
-#endif
-
-#if defined(CONFIG_CMD_LOADS)
-static ulong load_serial(long offset);
-static int read_record(char *buf, ulong len);
-# if defined(CONFIG_CMD_SAVES)
-static int save_serial(ulong offset, ulong size);
-static int write_record(char *buf);
-#endif
-
-static int do_echo = 1;
-#endif
-
-/* -------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_LOADS)
-static int do_load_serial(cmd_tbl_t *cmdtp, int flag, int argc,
-                         char * const argv[])
-{
-       long offset = 0;
-       ulong addr;
-       int i;
-       char *env_echo;
-       int rcode = 0;
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       int load_baudrate, current_baudrate;
-
-       load_baudrate = current_baudrate = gd->baudrate;
-#endif
-
-       if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
-               do_echo = 1;
-       } else {
-               do_echo = 0;
-       }
-
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       if (argc >= 2) {
-               offset = simple_strtol(argv[1], NULL, 16);
-       }
-       if (argc == 3) {
-               load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
-
-               /* default to current baudrate */
-               if (load_baudrate == 0)
-                       load_baudrate = current_baudrate;
-       }
-       if (load_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ENTER ...\n",
-                       load_baudrate);
-               udelay(50000);
-               gd->baudrate = load_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == '\r')
-                               break;
-               }
-       }
-#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
-       if (argc == 2) {
-               offset = simple_strtol(argv[1], NULL, 16);
-       }
-#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
-
-       printf("## Ready for S-Record download ...\n");
-
-       addr = load_serial(offset);
-
-       /*
-        * Gather any trailing characters (for instance, the ^D which
-        * is sent by 'cu' after sending a file), and give the
-        * box some time (100 * 1 ms)
-        */
-       for (i=0; i<100; ++i) {
-               if (tstc()) {
-                       (void) getc();
-               }
-               udelay(1000);
-       }
-
-       if (addr == ~0) {
-               printf("## S-Record download aborted\n");
-               rcode = 1;
-       } else {
-               printf("## Start Addr      = 0x%08lX\n", addr);
-               load_addr = addr;
-       }
-
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       if (load_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ESC ...\n",
-                       current_baudrate);
-               udelay(50000);
-               gd->baudrate = current_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == 0x1B) /* ESC */
-                               break;
-               }
-       }
-#endif
-       return rcode;
-}
-
-static ulong load_serial(long offset)
-{
-       char    record[SREC_MAXRECLEN + 1];     /* buffer for one S-Record      */
-       char    binbuf[SREC_MAXBINLEN];         /* buffer for binary data       */
-       int     binlen;                         /* no. of data bytes in S-Rec.  */
-       int     type;                           /* return code for record type  */
-       ulong   addr;                           /* load address from S-Record   */
-       ulong   size;                           /* number of bytes transferred  */
-       ulong   store_addr;
-       ulong   start_addr = ~0;
-       ulong   end_addr   =  0;
-       int     line_count =  0;
-
-       while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
-               type = srec_decode(record, &binlen, &addr, binbuf);
-
-               if (type < 0) {
-                       return (~0);            /* Invalid S-Record             */
-               }
-
-               switch (type) {
-               case SREC_DATA2:
-               case SREC_DATA3:
-               case SREC_DATA4:
-                   store_addr = addr + offset;
-#ifndef CONFIG_SYS_NO_FLASH
-                   if (addr2info(store_addr)) {
-                       int rc;
-
-                       rc = flash_write((char *)binbuf,store_addr,binlen);
-                       if (rc != 0) {
-                               flash_perror(rc);
-                               return (~0);
-                       }
-                   } else
-#endif
-                   {
-                       memcpy((char *)(store_addr), binbuf, binlen);
-                   }
-                   if ((store_addr) < start_addr)
-                       start_addr = store_addr;
-                   if ((store_addr + binlen - 1) > end_addr)
-                       end_addr = store_addr + binlen - 1;
-                   break;
-               case SREC_END2:
-               case SREC_END3:
-               case SREC_END4:
-                   udelay(10000);
-                   size = end_addr - start_addr + 1;
-                   printf("\n"
-                           "## First Load Addr = 0x%08lX\n"
-                           "## Last  Load Addr = 0x%08lX\n"
-                           "## Total Size      = 0x%08lX = %ld Bytes\n",
-                           start_addr, end_addr, size, size
-                   );
-                   flush_cache(start_addr, size);
-                   setenv_hex("filesize", size);
-                   return (addr);
-               case SREC_START:
-                   break;
-               default:
-                   break;
-               }
-               if (!do_echo) { /* print a '.' every 100 lines */
-                       if ((++line_count % 100) == 0)
-                               putc('.');
-               }
-       }
-
-       return (~0);                    /* Download aborted             */
-}
-
-static int read_record(char *buf, ulong len)
-{
-       char *p;
-       char c;
-
-       --len;  /* always leave room for terminating '\0' byte */
-
-       for (p=buf; p < buf+len; ++p) {
-               c = getc();             /* read character               */
-               if (do_echo)
-                       putc(c);        /* ... and echo it              */
-
-               switch (c) {
-               case '\r':
-               case '\n':
-                       *p = '\0';
-                       return (p - buf);
-               case '\0':
-               case 0x03:                      /* ^C - Control C               */
-                       return (-1);
-               default:
-                       *p = c;
-               }
-
-           /* Check for the console hangup (if any different from serial) */
-           if (gd->jt->getc != getc) {
-               if (ctrlc()) {
-                   return (-1);
-               }
-           }
-       }
-
-       /* line too long - truncate */
-       *p = '\0';
-       return (p - buf);
-}
-
-#if defined(CONFIG_CMD_SAVES)
-
-int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong offset = 0;
-       ulong size   = 0;
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       int save_baudrate, current_baudrate;
-
-       save_baudrate = current_baudrate = gd->baudrate;
-#endif
-
-       if (argc >= 2) {
-               offset = simple_strtoul(argv[1], NULL, 16);
-       }
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       if (argc >= 3) {
-               size = simple_strtoul(argv[2], NULL, 16);
-       }
-       if (argc == 4) {
-               save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
-
-               /* default to current baudrate */
-               if (save_baudrate == 0)
-                       save_baudrate = current_baudrate;
-       }
-       if (save_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ENTER ...\n",
-                       save_baudrate);
-               udelay(50000);
-               gd->baudrate = save_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == '\r')
-                               break;
-               }
-       }
-#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
-       if (argc == 3) {
-               size = simple_strtoul(argv[2], NULL, 16);
-       }
-#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
-
-       printf("## Ready for S-Record upload, press ENTER to proceed ...\n");
-       for (;;) {
-               if (getc() == '\r')
-                       break;
-       }
-       if (save_serial(offset, size)) {
-               printf("## S-Record upload aborted\n");
-       } else {
-               printf("## S-Record upload complete\n");
-       }
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-       if (save_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ESC ...\n",
-                       (int)current_baudrate);
-               udelay(50000);
-               gd->baudrate = current_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == 0x1B) /* ESC */
-                               break;
-               }
-       }
-#endif
-       return 0;
-}
-
-#define SREC3_START                            "S0030000FC\n"
-#define SREC3_FORMAT                   "S3%02X%08lX%s%02X\n"
-#define SREC3_END                              "S70500000000FA\n"
-#define SREC_BYTES_PER_RECORD  16
-
-static int save_serial(ulong address, ulong count)
-{
-       int i, c, reclen, checksum, length;
-       char *hex = "0123456789ABCDEF";
-       char    record[2*SREC_BYTES_PER_RECORD+16];     /* buffer for one S-Record      */
-       char    data[2*SREC_BYTES_PER_RECORD+1];        /* buffer for hex data  */
-
-       reclen = 0;
-       checksum  = 0;
-
-       if(write_record(SREC3_START))                   /* write the header */
-               return (-1);
-       do {
-               if(count) {                                             /* collect hex data in the buffer  */
-                       c = *(volatile uchar*)(address + reclen);       /* get one byte    */
-                       checksum += c;                                                  /* accumulate checksum */
-                       data[2*reclen]   = hex[(c>>4)&0x0f];
-                       data[2*reclen+1] = hex[c & 0x0f];
-                       data[2*reclen+2] = '\0';
-                       ++reclen;
-                       --count;
-               }
-               if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
-                       /* enough data collected for one record: dump it */
-                       if(reclen) {    /* build & write a data record: */
-                               /* address + data + checksum */
-                               length = 4 + reclen + 1;
-
-                               /* accumulate length bytes into checksum */
-                               for(i = 0; i < 2; i++)
-                                       checksum += (length >> (8*i)) & 0xff;
-
-                               /* accumulate address bytes into checksum: */
-                               for(i = 0; i < 4; i++)
-                                       checksum += (address >> (8*i)) & 0xff;
-
-                               /* make proper checksum byte: */
-                               checksum = ~checksum & 0xff;
-
-                               /* output one record: */
-                               sprintf(record, SREC3_FORMAT, length, address, data, checksum);
-                               if(write_record(record))
-                                       return (-1);
-                       }
-                       address  += reclen;  /* increment address */
-                       checksum  = 0;
-                       reclen    = 0;
-               }
-       }
-       while(count);
-       if(write_record(SREC3_END))     /* write the final record */
-               return (-1);
-       return(0);
-}
-
-static int write_record(char *buf)
-{
-       char c;
-
-       while((c = *buf++))
-               putc(c);
-
-       /* Check for the console hangup (if any different from serial) */
-
-       if (ctrlc()) {
-           return (-1);
-       }
-       return (0);
-}
-# endif
-
-#endif
-
-
-#if defined(CONFIG_CMD_LOADB)
-/*
- * loadb command (load binary) included
- */
-#define XON_CHAR        17
-#define XOFF_CHAR       19
-#define START_CHAR      0x01
-#define ETX_CHAR       0x03
-#define END_CHAR        0x0D
-#define SPACE           0x20
-#define K_ESCAPE        0x23
-#define SEND_TYPE       'S'
-#define DATA_TYPE       'D'
-#define ACK_TYPE        'Y'
-#define NACK_TYPE       'N'
-#define BREAK_TYPE      'B'
-#define tochar(x) ((char) (((x) + SPACE) & 0xff))
-#define untochar(x) ((int) (((x) - SPACE) & 0xff))
-
-static void set_kerm_bin_mode(unsigned long *);
-static int k_recv(void);
-static ulong load_serial_bin(ulong offset);
-
-
-static char his_eol;        /* character he needs at end of packet */
-static int  his_pad_count;  /* number of pad chars he needs */
-static char his_pad_char;   /* pad chars he needs */
-static char his_quote;      /* quote chars he'll use */
-
-static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc,
-                             char * const argv[])
-{
-       ulong offset = 0;
-       ulong addr;
-       int load_baudrate, current_baudrate;
-       int rcode = 0;
-       char *s;
-
-       /* pre-set offset from CONFIG_SYS_LOAD_ADDR */
-       offset = CONFIG_SYS_LOAD_ADDR;
-
-       /* pre-set offset from $loadaddr */
-       if ((s = getenv("loadaddr")) != NULL) {
-               offset = simple_strtoul(s, NULL, 16);
-       }
-
-       load_baudrate = current_baudrate = gd->baudrate;
-
-       if (argc >= 2) {
-               offset = simple_strtoul(argv[1], NULL, 16);
-       }
-       if (argc == 3) {
-               load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
-
-               /* default to current baudrate */
-               if (load_baudrate == 0)
-                       load_baudrate = current_baudrate;
-       }
-
-       if (load_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ENTER ...\n",
-                       load_baudrate);
-               udelay(50000);
-               gd->baudrate = load_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == '\r')
-                               break;
-               }
-       }
-
-       if (strcmp(argv[0],"loady")==0) {
-               printf("## Ready for binary (ymodem) download "
-                       "to 0x%08lX at %d bps...\n",
-                       offset,
-                       load_baudrate);
-
-               addr = load_serial_ymodem(offset, xyzModem_ymodem);
-
-       } else if (strcmp(argv[0],"loadx")==0) {
-               printf("## Ready for binary (xmodem) download "
-                       "to 0x%08lX at %d bps...\n",
-                       offset,
-                       load_baudrate);
-
-               addr = load_serial_ymodem(offset, xyzModem_xmodem);
-
-       } else {
-
-               printf("## Ready for binary (kermit) download "
-                       "to 0x%08lX at %d bps...\n",
-                       offset,
-                       load_baudrate);
-               addr = load_serial_bin(offset);
-
-               if (addr == ~0) {
-                       load_addr = 0;
-                       printf("## Binary (kermit) download aborted\n");
-                       rcode = 1;
-               } else {
-                       printf("## Start Addr      = 0x%08lX\n", addr);
-                       load_addr = addr;
-               }
-       }
-       if (load_baudrate != current_baudrate) {
-               printf("## Switch baudrate to %d bps and press ESC ...\n",
-                       current_baudrate);
-               udelay(50000);
-               gd->baudrate = current_baudrate;
-               serial_setbrg();
-               udelay(50000);
-               for (;;) {
-                       if (getc() == 0x1B) /* ESC */
-                               break;
-               }
-       }
-
-       return rcode;
-}
-
-
-static ulong load_serial_bin(ulong offset)
-{
-       int size, i;
-
-       set_kerm_bin_mode((ulong *) offset);
-       size = k_recv();
-
-       /*
-        * Gather any trailing characters (for instance, the ^D which
-        * is sent by 'cu' after sending a file), and give the
-        * box some time (100 * 1 ms)
-        */
-       for (i=0; i<100; ++i) {
-               if (tstc()) {
-                       (void) getc();
-               }
-               udelay(1000);
-       }
-
-       flush_cache(offset, size);
-
-       printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-       setenv_hex("filesize", size);
-
-       return offset;
-}
-
-static void send_pad(void)
-{
-       int count = his_pad_count;
-
-       while (count-- > 0)
-               putc(his_pad_char);
-}
-
-/* converts escaped kermit char to binary char */
-static char ktrans(char in)
-{
-       if ((in & 0x60) == 0x40) {
-               return (char) (in & ~0x40);
-       } else if ((in & 0x7f) == 0x3f) {
-               return (char) (in | 0x40);
-       } else
-               return in;
-}
-
-static int chk1(char *buffer)
-{
-       int total = 0;
-
-       while (*buffer) {
-               total += *buffer++;
-       }
-       return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
-}
-
-static void s1_sendpacket(char *packet)
-{
-       send_pad();
-       while (*packet) {
-               putc(*packet++);
-       }
-}
-
-static char a_b[24];
-static void send_ack(int n)
-{
-       a_b[0] = START_CHAR;
-       a_b[1] = tochar(3);
-       a_b[2] = tochar(n);
-       a_b[3] = ACK_TYPE;
-       a_b[4] = '\0';
-       a_b[4] = tochar(chk1(&a_b[1]));
-       a_b[5] = his_eol;
-       a_b[6] = '\0';
-       s1_sendpacket(a_b);
-}
-
-static void send_nack(int n)
-{
-       a_b[0] = START_CHAR;
-       a_b[1] = tochar(3);
-       a_b[2] = tochar(n);
-       a_b[3] = NACK_TYPE;
-       a_b[4] = '\0';
-       a_b[4] = tochar(chk1(&a_b[1]));
-       a_b[5] = his_eol;
-       a_b[6] = '\0';
-       s1_sendpacket(a_b);
-}
-
-
-static void (*os_data_init)(void);
-static void (*os_data_char)(char new_char);
-static int os_data_state, os_data_state_saved;
-static char *os_data_addr, *os_data_addr_saved;
-static char *bin_start_address;
-
-static void bin_data_init(void)
-{
-       os_data_state = 0;
-       os_data_addr = bin_start_address;
-}
-
-static void os_data_save(void)
-{
-       os_data_state_saved = os_data_state;
-       os_data_addr_saved = os_data_addr;
-}
-
-static void os_data_restore(void)
-{
-       os_data_state = os_data_state_saved;
-       os_data_addr = os_data_addr_saved;
-}
-
-static void bin_data_char(char new_char)
-{
-       switch (os_data_state) {
-       case 0:                                 /* data */
-               *os_data_addr++ = new_char;
-               break;
-       }
-}
-
-static void set_kerm_bin_mode(unsigned long *addr)
-{
-       bin_start_address = (char *) addr;
-       os_data_init = bin_data_init;
-       os_data_char = bin_data_char;
-}
-
-
-/* k_data_* simply handles the kermit escape translations */
-static int k_data_escape, k_data_escape_saved;
-static void k_data_init(void)
-{
-       k_data_escape = 0;
-       os_data_init();
-}
-
-static void k_data_save(void)
-{
-       k_data_escape_saved = k_data_escape;
-       os_data_save();
-}
-
-static void k_data_restore(void)
-{
-       k_data_escape = k_data_escape_saved;
-       os_data_restore();
-}
-
-static void k_data_char(char new_char)
-{
-       if (k_data_escape) {
-               /* last char was escape - translate this character */
-               os_data_char(ktrans(new_char));
-               k_data_escape = 0;
-       } else {
-               if (new_char == his_quote) {
-                       /* this char is escape - remember */
-                       k_data_escape = 1;
-               } else {
-                       /* otherwise send this char as-is */
-                       os_data_char(new_char);
-               }
-       }
-}
-
-#define SEND_DATA_SIZE  20
-static char send_parms[SEND_DATA_SIZE];
-static char *send_ptr;
-
-/* handle_send_packet interprits the protocol info and builds and
-   sends an appropriate ack for what we can do */
-static void handle_send_packet(int n)
-{
-       int length = 3;
-       int bytes;
-
-       /* initialize some protocol parameters */
-       his_eol = END_CHAR;             /* default end of line character */
-       his_pad_count = 0;
-       his_pad_char = '\0';
-       his_quote = K_ESCAPE;
-
-       /* ignore last character if it filled the buffer */
-       if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
-               --send_ptr;
-       bytes = send_ptr - send_parms;  /* how many bytes we'll process */
-       do {
-               if (bytes-- <= 0)
-                       break;
-               /* handle MAXL - max length */
-               /* ignore what he says - most I'll take (here) is 94 */
-               a_b[++length] = tochar(94);
-               if (bytes-- <= 0)
-                       break;
-               /* handle TIME - time you should wait for my packets */
-               /* ignore what he says - don't wait for my ack longer than 1 second */
-               a_b[++length] = tochar(1);
-               if (bytes-- <= 0)
-                       break;
-               /* handle NPAD - number of pad chars I need */
-               /* remember what he says - I need none */
-               his_pad_count = untochar(send_parms[2]);
-               a_b[++length] = tochar(0);
-               if (bytes-- <= 0)
-                       break;
-               /* handle PADC - pad chars I need */
-               /* remember what he says - I need none */
-               his_pad_char = ktrans(send_parms[3]);
-               a_b[++length] = 0x40;   /* He should ignore this */
-               if (bytes-- <= 0)
-                       break;
-               /* handle EOL - end of line he needs */
-               /* remember what he says - I need CR */
-               his_eol = untochar(send_parms[4]);
-               a_b[++length] = tochar(END_CHAR);
-               if (bytes-- <= 0)
-                       break;
-               /* handle QCTL - quote control char he'll use */
-               /* remember what he says - I'll use '#' */
-               his_quote = send_parms[5];
-               a_b[++length] = '#';
-               if (bytes-- <= 0)
-                       break;
-               /* handle QBIN - 8-th bit prefixing */
-               /* ignore what he says - I refuse */
-               a_b[++length] = 'N';
-               if (bytes-- <= 0)
-                       break;
-               /* handle CHKT - the clock check type */
-               /* ignore what he says - I do type 1 (for now) */
-               a_b[++length] = '1';
-               if (bytes-- <= 0)
-                       break;
-               /* handle REPT - the repeat prefix */
-               /* ignore what he says - I refuse (for now) */
-               a_b[++length] = 'N';
-               if (bytes-- <= 0)
-                       break;
-               /* handle CAPAS - the capabilities mask */
-               /* ignore what he says - I only do long packets - I don't do windows */
-               a_b[++length] = tochar(2);      /* only long packets */
-               a_b[++length] = tochar(0);      /* no windows */
-               a_b[++length] = tochar(94);     /* large packet msb */
-               a_b[++length] = tochar(94);     /* large packet lsb */
-       } while (0);
-
-       a_b[0] = START_CHAR;
-       a_b[1] = tochar(length);
-       a_b[2] = tochar(n);
-       a_b[3] = ACK_TYPE;
-       a_b[++length] = '\0';
-       a_b[length] = tochar(chk1(&a_b[1]));
-       a_b[++length] = his_eol;
-       a_b[++length] = '\0';
-       s1_sendpacket(a_b);
-}
-
-/* k_recv receives a OS Open image file over kermit line */
-static int k_recv(void)
-{
-       char new_char;
-       char k_state, k_state_saved;
-       int sum;
-       int done;
-       int length;
-       int n, last_n;
-       int len_lo, len_hi;
-
-       /* initialize some protocol parameters */
-       his_eol = END_CHAR;             /* default end of line character */
-       his_pad_count = 0;
-       his_pad_char = '\0';
-       his_quote = K_ESCAPE;
-
-       /* initialize the k_recv and k_data state machine */
-       done = 0;
-       k_state = 0;
-       k_data_init();
-       k_state_saved = k_state;
-       k_data_save();
-       n = 0;                          /* just to get rid of a warning */
-       last_n = -1;
-
-       /* expect this "type" sequence (but don't check):
-          S: send initiate
-          F: file header
-          D: data (multiple)
-          Z: end of file
-          B: break transmission
-        */
-
-       /* enter main loop */
-       while (!done) {
-               /* set the send packet pointer to begining of send packet parms */
-               send_ptr = send_parms;
-
-               /* With each packet, start summing the bytes starting with the length.
-                  Save the current sequence number.
-                  Note the type of the packet.
-                  If a character less than SPACE (0x20) is received - error.
-                */
-
-#if 0
-               /* OLD CODE, Prior to checking sequence numbers */
-               /* first have all state machines save current states */
-               k_state_saved = k_state;
-               k_data_save ();
-#endif
-
-               /* get a packet */
-               /* wait for the starting character or ^C */
-               for (;;) {
-                       switch (getc ()) {
-                       case START_CHAR:        /* start packet */
-                               goto START;
-                       case ETX_CHAR:          /* ^C waiting for packet */
-                               return (0);
-                       default:
-                               ;
-                       }
-               }
-START:
-               /* get length of packet */
-               sum = 0;
-               new_char = getc();
-               if ((new_char & 0xE0) == 0)
-                       goto packet_error;
-               sum += new_char & 0xff;
-               length = untochar(new_char);
-               /* get sequence number */
-               new_char = getc();
-               if ((new_char & 0xE0) == 0)
-                       goto packet_error;
-               sum += new_char & 0xff;
-               n = untochar(new_char);
-               --length;
-
-               /* NEW CODE - check sequence numbers for retried packets */
-               /* Note - this new code assumes that the sequence number is correctly
-                * received.  Handling an invalid sequence number adds another layer
-                * of complexity that may not be needed - yet!  At this time, I'm hoping
-                * that I don't need to buffer the incoming data packets and can write
-                * the data into memory in real time.
-                */
-               if (n == last_n) {
-                       /* same sequence number, restore the previous state */
-                       k_state = k_state_saved;
-                       k_data_restore();
-               } else {
-                       /* new sequence number, checkpoint the download */
-                       last_n = n;
-                       k_state_saved = k_state;
-                       k_data_save();
-               }
-               /* END NEW CODE */
-
-               /* get packet type */
-               new_char = getc();
-               if ((new_char & 0xE0) == 0)
-                       goto packet_error;
-               sum += new_char & 0xff;
-               k_state = new_char;
-               --length;
-               /* check for extended length */
-               if (length == -2) {
-                       /* (length byte was 0, decremented twice) */
-                       /* get the two length bytes */
-                       new_char = getc();
-                       if ((new_char & 0xE0) == 0)
-                               goto packet_error;
-                       sum += new_char & 0xff;
-                       len_hi = untochar(new_char);
-                       new_char = getc();
-                       if ((new_char & 0xE0) == 0)
-                               goto packet_error;
-                       sum += new_char & 0xff;
-                       len_lo = untochar(new_char);
-                       length = len_hi * 95 + len_lo;
-                       /* check header checksum */
-                       new_char = getc();
-                       if ((new_char & 0xE0) == 0)
-                               goto packet_error;
-                       if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
-                               goto packet_error;
-                       sum += new_char & 0xff;
-/* --length; */ /* new length includes only data and block check to come */
-               }
-               /* bring in rest of packet */
-               while (length > 1) {
-                       new_char = getc();
-                       if ((new_char & 0xE0) == 0)
-                               goto packet_error;
-                       sum += new_char & 0xff;
-                       --length;
-                       if (k_state == DATA_TYPE) {
-                               /* pass on the data if this is a data packet */
-                               k_data_char (new_char);
-                       } else if (k_state == SEND_TYPE) {
-                               /* save send pack in buffer as is */
-                               *send_ptr++ = new_char;
-                               /* if too much data, back off the pointer */
-                               if (send_ptr >= &send_parms[SEND_DATA_SIZE])
-                                       --send_ptr;
-                       }
-               }
-               /* get and validate checksum character */
-               new_char = getc();
-               if ((new_char & 0xE0) == 0)
-                       goto packet_error;
-               if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
-                       goto packet_error;
-               /* get END_CHAR */
-               new_char = getc();
-               if (new_char != END_CHAR) {
-                 packet_error:
-                       /* restore state machines */
-                       k_state = k_state_saved;
-                       k_data_restore();
-                       /* send a negative acknowledge packet in */
-                       send_nack(n);
-               } else if (k_state == SEND_TYPE) {
-                       /* crack the protocol parms, build an appropriate ack packet */
-                       handle_send_packet(n);
-               } else {
-                       /* send simple acknowledge packet in */
-                       send_ack(n);
-                       /* quit if end of transmission */
-                       if (k_state == BREAK_TYPE)
-                               done = 1;
-               }
-       }
-       return ((ulong) os_data_addr - (ulong) bin_start_address);
-}
-
-static int getcxmodem(void) {
-       if (tstc())
-               return (getc());
-       return -1;
-}
-static ulong load_serial_ymodem(ulong offset, int mode)
-{
-       int size;
-       int err;
-       int res;
-       connection_info_t info;
-       char ymodemBuf[1024];
-       ulong store_addr = ~0;
-       ulong addr = 0;
-
-       size = 0;
-       info.mode = mode;
-       res = xyzModem_stream_open(&info, &err);
-       if (!res) {
-
-               while ((res =
-                       xyzModem_stream_read(ymodemBuf, 1024, &err)) > 0) {
-                       store_addr = addr + offset;
-                       size += res;
-                       addr += res;
-#ifndef CONFIG_SYS_NO_FLASH
-                       if (addr2info(store_addr)) {
-                               int rc;
-
-                               rc = flash_write((char *) ymodemBuf,
-                                                 store_addr, res);
-                               if (rc != 0) {
-                                       flash_perror (rc);
-                                       return (~0);
-                               }
-                       } else
-#endif
-                       {
-                               memcpy((char *)(store_addr), ymodemBuf,
-                                       res);
-                       }
-
-               }
-       } else {
-               printf("%s\n", xyzModem_error(err));
-       }
-
-       xyzModem_stream_close(&err);
-       xyzModem_stream_terminate(false, &getcxmodem);
-
-
-       flush_cache(offset, size);
-
-       printf("## Total Size      = 0x%08x = %d Bytes\n", size, size);
-       setenv_hex("filesize", size);
-
-       return offset;
-}
-
-#endif
-
-/* -------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_LOADS)
-
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-U_BOOT_CMD(
-       loads, 3, 0,    do_load_serial,
-       "load S-Record file over serial line",
-       "[ off ] [ baud ]\n"
-       "    - load S-Record file over serial line"
-       " with offset 'off' and baudrate 'baud'"
-);
-
-#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
-U_BOOT_CMD(
-       loads, 2, 0,    do_load_serial,
-       "load S-Record file over serial line",
-       "[ off ]\n"
-       "    - load S-Record file over serial line with offset 'off'"
-);
-#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
-
-/*
- * SAVES always requires LOADS support, but not vice versa
- */
-
-
-#if defined(CONFIG_CMD_SAVES)
-#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
-U_BOOT_CMD(
-       saves, 4, 0,    do_save_serial,
-       "save S-Record file over serial line",
-       "[ off ] [size] [ baud ]\n"
-       "    - save S-Record file over serial line"
-       " with offset 'off', size 'size' and baudrate 'baud'"
-);
-#else  /* ! CONFIG_SYS_LOADS_BAUD_CHANGE */
-U_BOOT_CMD(
-       saves, 3, 0,    do_save_serial,
-       "save S-Record file over serial line",
-       "[ off ] [size]\n"
-       "    - save S-Record file over serial line with offset 'off' and size 'size'"
-);
-#endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */
-#endif /* CONFIG_CMD_SAVES */
-#endif /* CONFIG_CMD_LOADS */
-
-
-#if defined(CONFIG_CMD_LOADB)
-U_BOOT_CMD(
-       loadb, 3, 0,    do_load_serial_bin,
-       "load binary file over serial line (kermit mode)",
-       "[ off ] [ baud ]\n"
-       "    - load binary file over serial line"
-       " with offset 'off' and baudrate 'baud'"
-);
-
-U_BOOT_CMD(
-       loadx, 3, 0,    do_load_serial_bin,
-       "load binary file over serial line (xmodem mode)",
-       "[ off ] [ baud ]\n"
-       "    - load binary file over serial line"
-       " with offset 'off' and baudrate 'baud'"
-);
-
-U_BOOT_CMD(
-       loady, 3, 0,    do_load_serial_bin,
-       "load binary file over serial line (ymodem mode)",
-       "[ off ] [ baud ]\n"
-       "    - load binary file over serial line"
-       " with offset 'off' and baudrate 'baud'"
-);
-
-#endif /* CONFIG_CMD_LOADB */
-
-/* -------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_HWFLOW)
-int do_hwflow(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       extern int hwflow_onoff(int);
-
-       if (argc == 2) {
-               if (strcmp(argv[1], "off") == 0)
-                       hwflow_onoff(-1);
-               else
-                       if (strcmp(argv[1], "on") == 0)
-                               hwflow_onoff(1);
-                       else
-                               return CMD_RET_USAGE;
-       }
-       printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
-       return 0;
-}
-
-/* -------------------------------------------------------------------- */
-
-U_BOOT_CMD(
-       hwflow, 2, 0,   do_hwflow,
-       "turn RTS/CTS hardware flow control in serial line on/off",
-       "[on|off]"
-);
-
-#endif /* CONFIG_CMD_HWFLOW */
diff --git a/common/cmd_log.c b/common/cmd_log.c
deleted file mode 100644 (file)
index 873ee40..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * (C) Copyright 2002-2007
- * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
- *
- * Code used from linux/kernel/printk.c
- * Copyright (C) 1991, 1992  Linus Torvalds
- *
- * SPDX-License-Identifier:    GPL-2.0+
- *
- * Comments:
- *
- * After relocating the code, the environment variable "loglevel" is
- * copied to console_loglevel.  The functionality is similar to the
- * handling in the Linux kernel, i.e. messages logged with a priority
- * less than console_loglevel are also output to stdout.
- *
- * If you want messages with the default level (e.g. POST messages) to
- * appear on stdout also, make sure the environment variable
- * "loglevel" is set at boot time to a number higher than
- * default_message_loglevel below.
- */
-
-/*
- * Logbuffer handling routines
- */
-
-#include <common.h>
-#include <command.h>
-#include <stdio_dev.h>
-#include <post.h>
-#include <logbuff.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/* Local prototypes */
-static void logbuff_putc(struct stdio_dev *dev, const char c);
-static void logbuff_puts(struct stdio_dev *dev, const char *s);
-static int logbuff_printk(const char *line);
-
-static char buf[1024];
-
-/* This combination will not print messages with the default loglevel */
-static unsigned console_loglevel = 3;
-static unsigned default_message_loglevel = 4;
-static unsigned log_version = 1;
-#ifdef CONFIG_ALT_LB_ADDR
-static volatile logbuff_t *log;
-#else
-static logbuff_t *log;
-#endif
-static char *lbuf;
-
-unsigned long __logbuffer_base(void)
-{
-       return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
-}
-unsigned long logbuffer_base(void)
-__attribute__((weak, alias("__logbuffer_base")));
-
-void logbuff_init_ptrs(void)
-{
-       unsigned long tag, post_word;
-       char *s;
-
-#ifdef CONFIG_ALT_LB_ADDR
-       log = (logbuff_t *)CONFIG_ALT_LH_ADDR;
-       lbuf = (char *)CONFIG_ALT_LB_ADDR;
-#else
-       log = (logbuff_t *)(logbuffer_base()) - 1;
-       lbuf = (char *)log->buf;
-#endif
-
-       /* Set up log version */
-       if ((s = getenv ("logversion")) != NULL)
-               log_version = (int)simple_strtoul(s, NULL, 10);
-
-       if (log_version == 2)
-               tag = log->v2.tag;
-       else
-               tag = log->v1.tag;
-       post_word = post_word_load();
-#ifdef CONFIG_POST
-       /* The post routines have setup the word so we can simply test it */
-       if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT))
-               logbuff_reset();
-#else
-       /* No post routines, so we do our own checking                    */
-       if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) {
-               logbuff_reset ();
-               post_word_store (LOGBUFF_MAGIC);
-       }
-#endif
-       if (log_version == 2 && (long)log->v2.start > (long)log->v2.con)
-               log->v2.start = log->v2.con;
-
-       /* Initialize default loglevel if present */
-       if ((s = getenv ("loglevel")) != NULL)
-               console_loglevel = (int)simple_strtoul(s, NULL, 10);
-
-       gd->flags |= GD_FLG_LOGINIT;
-}
-
-void logbuff_reset(void)
-{
-#ifndef CONFIG_ALT_LB_ADDR
-       memset(log, 0, sizeof(logbuff_t));
-#endif
-       if (log_version == 2) {
-               log->v2.tag = LOGBUFF_MAGIC;
-#ifdef CONFIG_ALT_LB_ADDR
-               log->v2.start = 0;
-               log->v2.con = 0;
-               log->v2.end = 0;
-               log->v2.chars = 0;
-#endif
-       } else {
-               log->v1.tag = LOGBUFF_MAGIC;
-#ifdef CONFIG_ALT_LB_ADDR
-               log->v1.dummy = 0;
-               log->v1.start = 0;
-               log->v1.size = 0;
-               log->v1.chars = 0;
-#endif
-       }
-}
-
-int drv_logbuff_init(void)
-{
-       struct stdio_dev logdev;
-       int rc;
-
-       /* Device initialization */
-       memset (&logdev, 0, sizeof (logdev));
-
-       strcpy (logdev.name, "logbuff");
-       logdev.ext   = 0;                       /* No extensions */
-       logdev.flags = DEV_FLAGS_OUTPUT;        /* Output only */
-       logdev.putc  = logbuff_putc;            /* 'putc' function */
-       logdev.puts  = logbuff_puts;            /* 'puts' function */
-
-       rc = stdio_register(&logdev);
-
-       return (rc == 0) ? 1 : rc;
-}
-
-static void logbuff_putc(struct stdio_dev *dev, const char c)
-{
-       char buf[2];
-       buf[0] = c;
-       buf[1] = '\0';
-       logbuff_printk(buf);
-}
-
-static void logbuff_puts(struct stdio_dev *dev, const char *s)
-{
-       logbuff_printk (s);
-}
-
-void logbuff_log(char *msg)
-{
-       if ((gd->flags & GD_FLG_LOGINIT)) {
-               logbuff_printk(msg);
-       } else {
-               /*
-                * Can happen only for pre-relocated errors as logging
-                * at that stage should be disabled
-                */
-               puts (msg);
-       }
-}
-
-/*
- * Subroutine:  do_log
- *
- * Description: Handler for 'log' command..
- *
- * Inputs:     argv[1] contains the subcommand
- *
- * Return:      None
- *
- */
-int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct stdio_dev *sdev = NULL;
-       char *s;
-       unsigned long i, start, size;
-
-       if (strcmp(argv[1], "append") == 0) {
-               /* Log concatenation of all arguments separated by spaces */
-               for (i = 2; i < argc; i++) {
-                       logbuff_printk(argv[i]);
-                       logbuff_putc(sdev, (i < argc - 1) ? ' ' : '\n');
-               }
-               return 0;
-       }
-
-       switch (argc) {
-
-       case 2:
-               if (strcmp(argv[1], "show") == 0) {
-                       if (log_version == 2) {
-                               start = log->v2.start;
-                               size = log->v2.end - log->v2.start;
-                       } else {
-                               start = log->v1.start;
-                               size = log->v1.size;
-                       }
-                       if (size > LOGBUFF_LEN)
-                               size = LOGBUFF_LEN;
-                       for (i = 0; i < size; i++) {
-                               s = lbuf + ((start + i) & LOGBUFF_MASK);
-                               putc(*s);
-                       }
-                       return 0;
-               } else if (strcmp(argv[1], "reset") == 0) {
-                       logbuff_reset();
-                       return 0;
-               } else if (strcmp(argv[1], "info") == 0) {
-                       printf("Logbuffer   at  %08lx\n", (unsigned long)lbuf);
-                       if (log_version == 2) {
-                               printf("log_start    =  %08lx\n",
-                                       log->v2.start);
-                               printf("log_end      =  %08lx\n", log->v2.end);
-                               printf("log_con      =  %08lx\n", log->v2.con);
-                               printf("logged_chars =  %08lx\n",
-                                       log->v2.chars);
-                       }
-                       else {
-                               printf("log_start    =  %08lx\n",
-                                       log->v1.start);
-                               printf("log_size     =  %08lx\n",
-                                       log->v1.size);
-                               printf("logged_chars =  %08lx\n",
-                                       log->v1.chars);
-                       }
-                       return 0;
-               }
-               return CMD_RET_USAGE;
-
-       default:
-               return CMD_RET_USAGE;
-       }
-}
-
-U_BOOT_CMD(
-       log,     255,   1,      do_log,
-       "manipulate logbuffer",
-       "info   - show pointer details\n"
-       "log reset  - clear contents\n"
-       "log show   - show contents\n"
-       "log append <msg> - append <msg> to the logbuffer"
-);
-
-static int logbuff_printk(const char *line)
-{
-       int i;
-       char *msg, *p, *buf_end;
-       int line_feed;
-       static signed char msg_level = -1;
-
-       strcpy(buf + 3, line);
-       i = strlen(line);
-       buf_end = buf + 3 + i;
-       for (p = buf + 3; p < buf_end; p++) {
-               msg = p;
-               if (msg_level < 0) {
-                       if (
-                               p[0] != '<' ||
-                               p[1] < '0' ||
-                               p[1] > '7' ||
-                               p[2] != '>'
-                       ) {
-                               p -= 3;
-                               p[0] = '<';
-                               p[1] = default_message_loglevel + '0';
-                               p[2] = '>';
-                       } else {
-                               msg += 3;
-                       }
-                       msg_level = p[1] - '0';
-               }
-               line_feed = 0;
-               for (; p < buf_end; p++) {
-                       if (log_version == 2) {
-                               lbuf[log->v2.end & LOGBUFF_MASK] = *p;
-                               log->v2.end++;
-                               if (log->v2.end - log->v2.start > LOGBUFF_LEN)
-                                       log->v2.start++;
-                               log->v2.chars++;
-                       } else {
-                               lbuf[(log->v1.start + log->v1.size) &
-                                        LOGBUFF_MASK] = *p;
-                               if (log->v1.size < LOGBUFF_LEN)
-                                       log->v1.size++;
-                               else
-                                       log->v1.start++;
-                               log->v1.chars++;
-                       }
-                       if (*p == '\n') {
-                               line_feed = 1;
-                               break;
-                       }
-               }
-               if (msg_level < console_loglevel) {
-                       printf("%s", msg);
-               }
-               if (line_feed)
-                       msg_level = -1;
-       }
-       return i;
-}
diff --git a/common/cmd_lzmadec.c b/common/cmd_lzmadec.c
deleted file mode 100644 (file)
index 1ad9ed6..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
- * lzma uncompress command in Uboot
- *
- * made from existing cmd_unzip.c file of Uboot
- *
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <mapmem.h>
-#include <asm/io.h>
-
-#include <lzma/LzmaTools.h>
-
-static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       unsigned long src, dst;
-       unsigned long src_len = ~0UL, dst_len = ~0UL;
-       int ret;
-
-       switch (argc) {
-       case 4:
-               dst_len = simple_strtoul(argv[3], NULL, 16);
-               /* fall through */
-       case 3:
-               src = simple_strtoul(argv[1], NULL, 16);
-               dst = simple_strtoul(argv[2], NULL, 16);
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
-                                      map_sysmem(src, 0), dst_len);
-
-       if (ret != SZ_OK)
-               return 1;
-       printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
-       setenv_hex("filesize", src_len);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       lzmadec,    4,    1,    do_lzmadec,
-       "lzma uncompress a memory region",
-       "srcaddr dstaddr [dstsize]"
-);
diff --git a/common/cmd_mac.c b/common/cmd_mac.c
deleted file mode 100644 (file)
index 52d3ba0..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2006 Freescale Semiconductor
- * York Sun (yorksun@freescale.com)
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-extern int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
-U_BOOT_CMD(
-       mac, 3, 1,  do_mac,
-       "display and program the system ID and MAC addresses in EEPROM",
-       "[read|save|id|num|errata|date|ports|0|1|2|3|4|5|6|7]\n"
-       "mac read\n"
-       "    - read EEPROM content into memory\n"
-       "mac save\n"
-       "    - save to the EEPROM\n"
-       "mac id\n"
-       "    - program system id\n"
-       "mac num\n"
-       "    - program system serial number\n"
-       "mac errata\n"
-       "    - program errata data\n"
-       "mac date\n"
-       "    - program date\n"
-       "mac ports\n"
-       "    - program the number of ports\n"
-       "mac X\n"
-       "    - program the MAC address for port X [X=0...7]"
-);
diff --git a/common/cmd_md5sum.c b/common/cmd_md5sum.c
deleted file mode 100644 (file)
index 23bb81e..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * (C) Copyright 2011
- * Joe Hershberger, National Instruments, joe.hershberger@ni.com
- *
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <mapmem.h>
-#include <u-boot/md5.h>
-#include <asm/io.h>
-
-/*
- * Store the resulting sum to an address or variable
- */
-static void store_result(const u8 *sum, const char *dest)
-{
-       unsigned int i;
-
-       if (*dest == '*') {
-               u8 *ptr;
-
-               ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
-               for (i = 0; i < 16; i++)
-                       *ptr++ = sum[i];
-       } else {
-               char str_output[33];
-               char *str_ptr = str_output;
-
-               for (i = 0; i < 16; i++) {
-                       sprintf(str_ptr, "%02x", sum[i]);
-                       str_ptr += 2;
-               }
-               setenv(dest, str_output);
-       }
-}
-
-#ifdef CONFIG_MD5SUM_VERIFY
-static int parse_verify_sum(char *verify_str, u8 *vsum)
-{
-       if (*verify_str == '*') {
-               u8 *ptr;
-
-               ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
-               memcpy(vsum, ptr, 16);
-       } else {
-               unsigned int i;
-               char *vsum_str;
-
-               if (strlen(verify_str) == 32)
-                       vsum_str = verify_str;
-               else {
-                       vsum_str = getenv(verify_str);
-                       if (vsum_str == NULL || strlen(vsum_str) != 32)
-                               return 1;
-               }
-
-               for (i = 0; i < 16; i++) {
-                       char *nullp = vsum_str + (i + 1) * 2;
-                       char end = *nullp;
-
-                       *nullp = '\0';
-                       *(u8 *)(vsum + i) =
-                               simple_strtoul(vsum_str + (i * 2), NULL, 16);
-                       *nullp = end;
-               }
-       }
-       return 0;
-}
-
-int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr, len;
-       unsigned int i;
-       u8 output[16];
-       u8 vsum[16];
-       int verify = 0;
-       int ac;
-       char * const *av;
-       void *buf;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       av = argv + 1;
-       ac = argc - 1;
-       if (strcmp(*av, "-v") == 0) {
-               verify = 1;
-               av++;
-               ac--;
-               if (ac < 3)
-                       return CMD_RET_USAGE;
-       }
-
-       addr = simple_strtoul(*av++, NULL, 16);
-       len = simple_strtoul(*av++, NULL, 16);
-
-       buf = map_sysmem(addr, len);
-       md5_wd(buf, len, output, CHUNKSZ_MD5);
-       unmap_sysmem(buf);
-
-       if (!verify) {
-               printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
-               for (i = 0; i < 16; i++)
-                       printf("%02x", output[i]);
-               printf("\n");
-
-               if (ac > 2)
-                       store_result(output, *av);
-       } else {
-               char *verify_str = *av++;
-
-               if (parse_verify_sum(verify_str, vsum)) {
-                       printf("ERROR: %s does not contain a valid md5 sum\n",
-                               verify_str);
-                       return 1;
-               }
-               if (memcmp(output, vsum, 16) != 0) {
-                       printf("md5 for %08lx ... %08lx ==> ", addr,
-                               addr + len - 1);
-                       for (i = 0; i < 16; i++)
-                               printf("%02x", output[i]);
-                       printf(" != ");
-                       for (i = 0; i < 16; i++)
-                               printf("%02x", vsum[i]);
-                       printf(" ** ERROR **\n");
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-#else
-static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long addr, len;
-       unsigned int i;
-       u8 output[16];
-       void *buf;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       addr = simple_strtoul(argv[1], NULL, 16);
-       len = simple_strtoul(argv[2], NULL, 16);
-
-       buf = map_sysmem(addr, len);
-       md5_wd(buf, len, output, CHUNKSZ_MD5);
-       unmap_sysmem(buf);
-
-       printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
-       for (i = 0; i < 16; i++)
-               printf("%02x", output[i]);
-       printf("\n");
-
-       if (argc > 3)
-               store_result(output, argv[3]);
-
-       return 0;
-}
-#endif
-
-#ifdef CONFIG_MD5SUM_VERIFY
-U_BOOT_CMD(
-       md5sum, 5,      1,      do_md5sum,
-       "compute MD5 message digest",
-       "address count [[*]sum]\n"
-               "    - compute MD5 message digest [save to sum]\n"
-       "md5sum -v address count [*]sum\n"
-               "    - verify md5sum of memory area"
-);
-#else
-U_BOOT_CMD(
-       md5sum, 4,      1,      do_md5sum,
-       "compute MD5 message digest",
-       "address count [[*]sum]\n"
-               "    - compute MD5 message digest [save to sum]"
-);
-#endif
diff --git a/common/cmd_mdio.c b/common/cmd_mdio.c
deleted file mode 100644 (file)
index fb13d05..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * (C) Copyright 2011 Freescale Semiconductor, Inc
- * Andy Fleming
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * MDIO Commands
- */
-
-#include <common.h>
-#include <command.h>
-#include <miiphy.h>
-#include <phy.h>
-
-
-static char last_op[2];
-static uint last_data;
-static uint last_addr_lo;
-static uint last_addr_hi;
-static uint last_devad_lo;
-static uint last_devad_hi;
-static uint last_reg_lo;
-static uint last_reg_hi;
-
-static int extract_range(char *input, int *plo, int *phi)
-{
-       char *end;
-       *plo = simple_strtol(input, &end, 0);
-       if (end == input)
-               return -1;
-
-       if ((*end == '-') && *(++end))
-               *phi = simple_strtol(end, NULL, 0);
-       else if (*end == '\0')
-               *phi = *plo;
-       else
-               return -1;
-
-       return 0;
-}
-
-static int mdio_write_ranges(struct phy_device *phydev, struct mii_dev *bus,
-                            int addrlo,
-                            int addrhi, int devadlo, int devadhi,
-                            int reglo, int reghi, unsigned short data,
-                            int extended)
-{
-       int addr, devad, reg;
-       int err = 0;
-
-       for (addr = addrlo; addr <= addrhi; addr++) {
-               for (devad = devadlo; devad <= devadhi; devad++) {
-                       for (reg = reglo; reg <= reghi; reg++) {
-                               if (!extended)
-                                       err = bus->write(bus, addr, devad,
-                                                        reg, data);
-                               else
-                                       err = phydev->drv->writeext(phydev,
-                                                       addr, devad, reg, data);
-
-                               if (err)
-                                       goto err_out;
-                       }
-               }
-       }
-
-err_out:
-       return err;
-}
-
-static int mdio_read_ranges(struct phy_device *phydev, struct mii_dev *bus,
-                           int addrlo,
-                           int addrhi, int devadlo, int devadhi,
-                           int reglo, int reghi, int extended)
-{
-       int addr, devad, reg;
-
-       printf("Reading from bus %s\n", bus->name);
-       for (addr = addrlo; addr <= addrhi; addr++) {
-               printf("PHY at address %d:\n", addr);
-
-               for (devad = devadlo; devad <= devadhi; devad++) {
-                       for (reg = reglo; reg <= reghi; reg++) {
-                               int val;
-
-                               if (!extended)
-                                       val = bus->read(bus, addr, devad, reg);
-                               else
-                                       val = phydev->drv->readext(phydev, addr,
-                                               devad, reg);
-
-                               if (val < 0) {
-                                       printf("Error\n");
-
-                                       return val;
-                               }
-
-                               if (devad >= 0)
-                                       printf("%d.", devad);
-
-                               printf("%d - 0x%x\n", reg, val & 0xffff);
-                       }
-               }
-       }
-
-       return 0;
-}
-
-/* The register will be in the form [a[-b].]x[-y] */
-static int extract_reg_range(char *input, int *devadlo, int *devadhi,
-                            int *reglo, int *reghi)
-{
-       char *regstr;
-
-       /* use strrchr to find the last string after a '.' */
-       regstr = strrchr(input, '.');
-
-       /* If it exists, extract the devad(s) */
-       if (regstr) {
-               char devadstr[32];
-
-               strncpy(devadstr, input, regstr - input);
-               devadstr[regstr - input] = '\0';
-
-               if (extract_range(devadstr, devadlo, devadhi))
-                       return -1;
-
-               regstr++;
-       } else {
-               /* Otherwise, we have no devad, and we just got regs */
-               *devadlo = *devadhi = MDIO_DEVAD_NONE;
-
-               regstr = input;
-       }
-
-       return extract_range(regstr, reglo, reghi);
-}
-
-static int extract_phy_range(char *const argv[], int argc, struct mii_dev **bus,
-                            struct phy_device **phydev,
-                            int *addrlo, int *addrhi)
-{
-       struct phy_device *dev = *phydev;
-
-       if ((argc < 1) || (argc > 2))
-               return -1;
-
-       /* If there are two arguments, it's busname addr */
-       if (argc == 2) {
-               *bus = miiphy_get_dev_by_name(argv[0]);
-
-               if (!*bus)
-                       return -1;
-
-               return extract_range(argv[1], addrlo, addrhi);
-       }
-
-       /* It must be one argument, here */
-
-       /*
-        * This argument can be one of two things:
-        * 1) Ethernet device name
-        * 2) Just an address (use the previously-used bus)
-        *
-        * We check all buses for a PHY which is connected to an ethernet
-        * device by the given name.  If none are found, we call
-        * extract_range() on the string, and see if it's an address range.
-        */
-       dev = mdio_phydev_for_ethname(argv[0]);
-
-       if (dev) {
-               *addrlo = *addrhi = dev->addr;
-               *bus = dev->bus;
-
-               return 0;
-       }
-
-       /* It's an address or nothing useful */
-       return extract_range(argv[0], addrlo, addrhi);
-}
-
-/* ---------------------------------------------------------------- */
-static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char op[2];
-       int addrlo, addrhi, reglo, reghi, devadlo, devadhi;
-       unsigned short  data;
-       int pos = argc - 1;
-       struct mii_dev *bus;
-       struct phy_device *phydev = NULL;
-       int extended = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /*
-        * We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       op[0] = argv[1][0];
-       addrlo = last_addr_lo;
-       addrhi = last_addr_hi;
-       devadlo = last_devad_lo;
-       devadhi = last_devad_hi;
-       reglo  = last_reg_lo;
-       reghi  = last_reg_hi;
-       data   = last_data;
-
-       bus = mdio_get_current_dev();
-
-       if (flag & CMD_FLAG_REPEAT)
-               op[0] = last_op[0];
-
-       if (strlen(argv[1]) > 1) {
-               op[1] = argv[1][1];
-               if (op[1] == 'x') {
-                       phydev = mdio_phydev_for_ethname(argv[2]);
-
-                       if (phydev) {
-                               addrlo = phydev->addr;
-                               addrhi = addrlo;
-                               bus = phydev->bus;
-                               extended = 1;
-                       } else {
-                               return -1;
-                       }
-
-                       if (!phydev->drv ||
-                           (!phydev->drv->writeext && (op[0] == 'w')) ||
-                           (!phydev->drv->readext && (op[0] == 'r'))) {
-                               puts("PHY does not have extended functions\n");
-                               return -1;
-                       }
-               }
-       }
-
-       switch (op[0]) {
-       case 'w':
-               if (pos > 1)
-                       data = simple_strtoul(argv[pos--], NULL, 16);
-       case 'r':
-               if (pos > 1)
-                       if (extract_reg_range(argv[pos--], &devadlo, &devadhi,
-                                       &reglo, &reghi))
-                               return -1;
-
-       default:
-               if (pos > 1)
-                       if (extract_phy_range(&(argv[2]), pos - 1, &bus,
-                                       &phydev, &addrlo, &addrhi))
-                               return -1;
-
-               break;
-       }
-
-       if (op[0] == 'l') {
-               mdio_list_devices();
-
-               return 0;
-       }
-
-       /* Save the chosen bus */
-       miiphy_set_current_dev(bus->name);
-
-       switch (op[0]) {
-       case 'w':
-               mdio_write_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
-                                 reglo, reghi, data, extended);
-               break;
-
-       case 'r':
-               mdio_read_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
-                                reglo, reghi, extended);
-               break;
-       }
-
-       /*
-        * Save the parameters for repeats.
-        */
-       last_op[0] = op[0];
-       last_addr_lo = addrlo;
-       last_addr_hi = addrhi;
-       last_devad_lo = devadlo;
-       last_devad_hi = devadhi;
-       last_reg_lo  = reglo;
-       last_reg_hi  = reghi;
-       last_data    = data;
-
-       return 0;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       mdio,   6,      1,      do_mdio,
-       "MDIO utility commands",
-       "list                   - List MDIO buses\n"
-       "mdio read <phydev> [<devad>.]<reg> - "
-               "read PHY's register at <devad>.<reg>\n"
-       "mdio write <phydev> [<devad>.]<reg> <data> - "
-               "write PHY's register at <devad>.<reg>\n"
-       "mdio rx <phydev> [<devad>.]<reg> - "
-               "read PHY's extended register at <devad>.<reg>\n"
-       "mdio wx <phydev> [<devad>.]<reg> <data> - "
-               "write PHY's extended register at <devad>.<reg>\n"
-       "<phydev> may be:\n"
-       "   <busname>  <addr>\n"
-       "   <addr>\n"
-       "   <eth name>\n"
-       "<addr> <devad>, and <reg> may be ranges, e.g. 1-5.4-0x1f.\n"
-);
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
deleted file mode 100644 (file)
index efa3929..0000000
+++ /dev/null
@@ -1,1410 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Memory Functions
- *
- * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
- */
-
-#include <common.h>
-#include <console.h>
-#include <bootretry.h>
-#include <cli.h>
-#include <command.h>
-#include <console.h>
-#ifdef CONFIG_HAS_DATAFLASH
-#include <dataflash.h>
-#endif
-#include <hash.h>
-#include <inttypes.h>
-#include <mapmem.h>
-#include <watchdog.h>
-#include <asm/io.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#ifndef CONFIG_SYS_MEMTEST_SCRATCH
-#define CONFIG_SYS_MEMTEST_SCRATCH 0
-#endif
-
-static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
-
-/* Display values from last command.
- * Memory modify remembered values are different from display memory.
- */
-static ulong   dp_last_addr, dp_last_size;
-static ulong   dp_last_length = 0x40;
-static ulong   mm_last_addr, mm_last_size;
-
-static ulong   base_address = 0;
-
-/* Memory Display
- *
- * Syntax:
- *     md{.b, .w, .l, .q} {addr} {len}
- */
-#define DISP_LINE_LEN  16
-static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong   addr, length;
-#if defined(CONFIG_HAS_DATAFLASH)
-       ulong   nbytes, linebytes;
-#endif
-       int     size;
-       int rc = 0;
-
-       /* We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       addr = dp_last_addr;
-       size = dp_last_size;
-       length = dp_last_length;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /* New command specified.  Check for a size specification.
-                * Defaults to long if no or incorrect specification.
-                */
-               if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-                       return 1;
-
-               /* Address is specified since argc > 1
-               */
-               addr = simple_strtoul(argv[1], NULL, 16);
-               addr += base_address;
-
-               /* If another parameter, it is the length to display.
-                * Length is the number of objects, not number of bytes.
-                */
-               if (argc > 2)
-                       length = simple_strtoul(argv[2], NULL, 16);
-       }
-
-#if defined(CONFIG_HAS_DATAFLASH)
-       /* Print the lines.
-        *
-        * We buffer all read data, so we can make sure data is read only
-        * once, and all accesses are with the specified bus width.
-        */
-       nbytes = length * size;
-       do {
-               char    linebuf[DISP_LINE_LEN];
-               void* p;
-               linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
-
-               rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
-               p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
-               print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
-
-               nbytes -= linebytes;
-               addr += linebytes;
-               if (ctrlc()) {
-                       rc = 1;
-                       break;
-               }
-       } while (nbytes > 0);
-#else
-
-# if defined(CONFIG_BLACKFIN)
-       /* See if we're trying to display L1 inst */
-       if (addr_bfin_on_chip_mem(addr)) {
-               char linebuf[DISP_LINE_LEN];
-               ulong linebytes, nbytes = length * size;
-               do {
-                       linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
-                       memcpy(linebuf, (void *)addr, linebytes);
-                       print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
-
-                       nbytes -= linebytes;
-                       addr += linebytes;
-                       if (ctrlc()) {
-                               rc = 1;
-                               break;
-                       }
-               } while (nbytes > 0);
-       } else
-# endif
-
-       {
-               ulong bytes = size * length;
-               const void *buf = map_sysmem(addr, bytes);
-
-               /* Print the lines. */
-               print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
-               addr += bytes;
-               unmap_sysmem(buf);
-       }
-#endif
-
-       dp_last_addr = addr;
-       dp_last_length = length;
-       dp_last_size = size;
-       return (rc);
-}
-
-static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return mod_mem (cmdtp, 1, flag, argc, argv);
-}
-static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return mod_mem (cmdtp, 0, flag, argc, argv);
-}
-
-static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       u64 writeval;
-#else
-       ulong writeval;
-#endif
-       ulong   addr, count;
-       int     size;
-       void *buf, *start;
-       ulong bytes;
-
-       if ((argc < 3) || (argc > 4))
-               return CMD_RET_USAGE;
-
-       /* Check for size specification.
-       */
-       if ((size = cmd_get_data_size(argv[0], 4)) < 1)
-               return 1;
-
-       /* Address is specified since argc > 1
-       */
-       addr = simple_strtoul(argv[1], NULL, 16);
-       addr += base_address;
-
-       /* Get the value to write.
-       */
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       writeval = simple_strtoull(argv[2], NULL, 16);
-#else
-       writeval = simple_strtoul(argv[2], NULL, 16);
-#endif
-
-       /* Count ? */
-       if (argc == 4) {
-               count = simple_strtoul(argv[3], NULL, 16);
-       } else {
-               count = 1;
-       }
-
-       bytes = size * count;
-       start = map_sysmem(addr, bytes);
-       buf = start;
-       while (count-- > 0) {
-               if (size == 4)
-                       *((u32 *)buf) = (u32)writeval;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               else if (size == 8)
-                       *((u64 *)buf) = (u64)writeval;
-#endif
-               else if (size == 2)
-                       *((u16 *)buf) = (u16)writeval;
-               else
-                       *((u8 *)buf) = (u8)writeval;
-               buf += size;
-       }
-       unmap_sysmem(start);
-       return 0;
-}
-
-#ifdef CONFIG_MX_CYCLIC
-static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       ulong count;
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       count = simple_strtoul(argv[3], NULL, 10);
-
-       for (;;) {
-               do_mem_md (NULL, 0, 3, argv);
-
-               /* delay for <count> ms... */
-               for (i=0; i<count; i++)
-                       udelay (1000);
-
-               /* check for ctrl-c to abort... */
-               if (ctrlc()) {
-                       puts("Abort\n");
-                       return 0;
-               }
-       }
-
-       return 0;
-}
-
-static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i;
-       ulong count;
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       count = simple_strtoul(argv[3], NULL, 10);
-
-       for (;;) {
-               do_mem_mw (NULL, 0, 3, argv);
-
-               /* delay for <count> ms... */
-               for (i=0; i<count; i++)
-                       udelay (1000);
-
-               /* check for ctrl-c to abort... */
-               if (ctrlc()) {
-                       puts("Abort\n");
-                       return 0;
-               }
-       }
-
-       return 0;
-}
-#endif /* CONFIG_MX_CYCLIC */
-
-static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong   addr1, addr2, count, ngood, bytes;
-       int     size;
-       int     rcode = 0;
-       const char *type;
-       const void *buf1, *buf2, *base;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       u64 word1, word2;
-#else
-       ulong word1, word2;
-#endif
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       /* Check for size specification.
-       */
-       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-               return 1;
-       type = size == 8 ? "double word" :
-              size == 4 ? "word" :
-              size == 2 ? "halfword" : "byte";
-
-       addr1 = simple_strtoul(argv[1], NULL, 16);
-       addr1 += base_address;
-
-       addr2 = simple_strtoul(argv[2], NULL, 16);
-       addr2 += base_address;
-
-       count = simple_strtoul(argv[3], NULL, 16);
-
-#ifdef CONFIG_HAS_DATAFLASH
-       if (addr_dataflash(addr1) | addr_dataflash(addr2)){
-               puts ("Comparison with DataFlash space not supported.\n\r");
-               return 0;
-       }
-#endif
-
-#ifdef CONFIG_BLACKFIN
-       if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
-               puts ("Comparison with L1 instruction memory not supported.\n\r");
-               return 0;
-       }
-#endif
-
-       bytes = size * count;
-       base = buf1 = map_sysmem(addr1, bytes);
-       buf2 = map_sysmem(addr2, bytes);
-       for (ngood = 0; ngood < count; ++ngood) {
-               if (size == 4) {
-                       word1 = *(u32 *)buf1;
-                       word2 = *(u32 *)buf2;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               } else if (size == 8) {
-                       word1 = *(u64 *)buf1;
-                       word2 = *(u64 *)buf2;
-#endif
-               } else if (size == 2) {
-                       word1 = *(u16 *)buf1;
-                       word2 = *(u16 *)buf2;
-               } else {
-                       word1 = *(u8 *)buf1;
-                       word2 = *(u8 *)buf2;
-               }
-               if (word1 != word2) {
-                       ulong offset = buf1 - base;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-                       printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
-                              PRIx64 ")\n",
-                              type, (void *)(addr1 + offset), size, word1,
-                              type, (void *)(addr2 + offset), size, word2);
-#else
-                       printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
-                               type, (ulong)(addr1 + offset), size, word1,
-                               type, (ulong)(addr2 + offset), size, word2);
-#endif
-                       rcode = 1;
-                       break;
-               }
-
-               buf1 += size;
-               buf2 += size;
-
-               /* reset watchdog from time to time */
-               if ((ngood % (64 << 10)) == 0)
-                       WATCHDOG_RESET();
-       }
-       unmap_sysmem(buf1);
-       unmap_sysmem(buf2);
-
-       printf("Total of %ld %s(s) were the same\n", ngood, type);
-       return rcode;
-}
-
-static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong   addr, dest, count, bytes;
-       int     size;
-       const void *src;
-       void *buf;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       /* Check for size specification.
-       */
-       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-               return 1;
-
-       addr = simple_strtoul(argv[1], NULL, 16);
-       addr += base_address;
-
-       dest = simple_strtoul(argv[2], NULL, 16);
-       dest += base_address;
-
-       count = simple_strtoul(argv[3], NULL, 16);
-
-       if (count == 0) {
-               puts ("Zero length ???\n");
-               return 1;
-       }
-
-#ifndef CONFIG_SYS_NO_FLASH
-       /* check if we are copying to Flash */
-       if ( (addr2info(dest) != NULL)
-#ifdef CONFIG_HAS_DATAFLASH
-          && (!addr_dataflash(dest))
-#endif
-          ) {
-               int rc;
-
-               puts ("Copy to Flash... ");
-
-               rc = flash_write ((char *)addr, dest, count*size);
-               if (rc != 0) {
-                       flash_perror (rc);
-                       return (1);
-               }
-               puts ("done\n");
-               return 0;
-       }
-#endif
-
-#ifdef CONFIG_HAS_DATAFLASH
-       /* Check if we are copying from RAM or Flash to DataFlash */
-       if (addr_dataflash(dest) && !addr_dataflash(addr)){
-               int rc;
-
-               puts ("Copy to DataFlash... ");
-
-               rc = write_dataflash (dest, addr, count*size);
-
-               if (rc != 1) {
-                       dataflash_perror (rc);
-                       return (1);
-               }
-               puts ("done\n");
-               return 0;
-       }
-
-       /* Check if we are copying from DataFlash to RAM */
-       if (addr_dataflash(addr) && !addr_dataflash(dest)
-#ifndef CONFIG_SYS_NO_FLASH
-                                && (addr2info(dest) == NULL)
-#endif
-          ){
-               int rc;
-               rc = read_dataflash(addr, count * size, (char *) dest);
-               if (rc != 1) {
-                       dataflash_perror (rc);
-                       return (1);
-               }
-               return 0;
-       }
-
-       if (addr_dataflash(addr) && addr_dataflash(dest)){
-               puts ("Unsupported combination of source/destination.\n\r");
-               return 1;
-       }
-#endif
-
-#ifdef CONFIG_BLACKFIN
-       /* See if we're copying to/from L1 inst */
-       if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
-               memcpy((void *)dest, (void *)addr, count * size);
-               return 0;
-       }
-#endif
-
-       bytes = size * count;
-       buf = map_sysmem(dest, bytes);
-       src = map_sysmem(addr, bytes);
-       while (count-- > 0) {
-               if (size == 4)
-                       *((u32 *)buf) = *((u32  *)src);
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               else if (size == 8)
-                       *((u64 *)buf) = *((u64 *)src);
-#endif
-               else if (size == 2)
-                       *((u16 *)buf) = *((u16 *)src);
-               else
-                       *((u8 *)buf) = *((u8 *)src);
-               src += size;
-               buf += size;
-
-               /* reset watchdog from time to time */
-               if ((count % (64 << 10)) == 0)
-                       WATCHDOG_RESET();
-       }
-       unmap_sysmem(buf);
-       unmap_sysmem(src);
-
-       return 0;
-}
-
-static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       if (argc > 1) {
-               /* Set new base address.
-               */
-               base_address = simple_strtoul(argv[1], NULL, 16);
-       }
-       /* Print the current base address.
-       */
-       printf("Base Address: 0x%08lx\n", base_address);
-       return 0;
-}
-
-static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       ulong   addr, length, i, bytes;
-       int     size;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       volatile u64 *llp;
-#endif
-       volatile u32 *longp;
-       volatile u16 *shortp;
-       volatile u8 *cp;
-       const void *buf;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       /*
-        * Check for a size specification.
-        * Defaults to long if no or incorrect specification.
-        */
-       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-               return 1;
-
-       /* Address is always specified.
-       */
-       addr = simple_strtoul(argv[1], NULL, 16);
-
-       /* Length is the number of objects, not number of bytes.
-       */
-       length = simple_strtoul(argv[2], NULL, 16);
-
-       bytes = size * length;
-       buf = map_sysmem(addr, bytes);
-
-       /* We want to optimize the loops to run as fast as possible.
-        * If we have only one object, just run infinite loops.
-        */
-       if (length == 1) {
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               if (size == 8) {
-                       llp = (u64 *)buf;
-                       for (;;)
-                               i = *llp;
-               }
-#endif
-               if (size == 4) {
-                       longp = (u32 *)buf;
-                       for (;;)
-                               i = *longp;
-               }
-               if (size == 2) {
-                       shortp = (u16 *)buf;
-                       for (;;)
-                               i = *shortp;
-               }
-               cp = (u8 *)buf;
-               for (;;)
-                       i = *cp;
-       }
-
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       if (size == 8) {
-               for (;;) {
-                       llp = (u64 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *llp++;
-               }
-       }
-#endif
-       if (size == 4) {
-               for (;;) {
-                       longp = (u32 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *longp++;
-               }
-       }
-       if (size == 2) {
-               for (;;) {
-                       shortp = (u16 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *shortp++;
-               }
-       }
-       for (;;) {
-               cp = (u8 *)buf;
-               i = length;
-               while (i-- > 0)
-                       *cp++;
-       }
-       unmap_sysmem(buf);
-
-       return 0;
-}
-
-#ifdef CONFIG_LOOPW
-static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       ulong   addr, length, i, bytes;
-       int     size;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       volatile u64 *llp;
-       u64 data;
-#else
-       ulong   data;
-#endif
-       volatile u32 *longp;
-       volatile u16 *shortp;
-       volatile u8 *cp;
-       void *buf;
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       /*
-        * Check for a size specification.
-        * Defaults to long if no or incorrect specification.
-        */
-       if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-               return 1;
-
-       /* Address is always specified.
-       */
-       addr = simple_strtoul(argv[1], NULL, 16);
-
-       /* Length is the number of objects, not number of bytes.
-       */
-       length = simple_strtoul(argv[2], NULL, 16);
-
-       /* data to write */
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       data = simple_strtoull(argv[3], NULL, 16);
-#else
-       data = simple_strtoul(argv[3], NULL, 16);
-#endif
-
-       bytes = size * length;
-       buf = map_sysmem(addr, bytes);
-
-       /* We want to optimize the loops to run as fast as possible.
-        * If we have only one object, just run infinite loops.
-        */
-       if (length == 1) {
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               if (size == 8) {
-                       llp = (u64 *)buf;
-                       for (;;)
-                               *llp = data;
-               }
-#endif
-               if (size == 4) {
-                       longp = (u32 *)buf;
-                       for (;;)
-                               *longp = data;
-               }
-               if (size == 2) {
-                       shortp = (u16 *)buf;
-                       for (;;)
-                               *shortp = data;
-               }
-               cp = (u8 *)buf;
-               for (;;)
-                       *cp = data;
-       }
-
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       if (size == 8) {
-               for (;;) {
-                       llp = (u64 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *llp++ = data;
-               }
-       }
-#endif
-       if (size == 4) {
-               for (;;) {
-                       longp = (u32 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *longp++ = data;
-               }
-       }
-       if (size == 2) {
-               for (;;) {
-                       shortp = (u16 *)buf;
-                       i = length;
-                       while (i-- > 0)
-                               *shortp++ = data;
-               }
-       }
-       for (;;) {
-               cp = (u8 *)buf;
-               i = length;
-               while (i-- > 0)
-                       *cp++ = data;
-       }
-}
-#endif /* CONFIG_LOOPW */
-
-#ifdef CONFIG_CMD_MEMTEST
-static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
-                         vu_long *dummy)
-{
-       vu_long *addr;
-       ulong errs = 0;
-       ulong val, readback;
-       int j;
-       vu_long offset;
-       vu_long test_offset;
-       vu_long pattern;
-       vu_long temp;
-       vu_long anti_pattern;
-       vu_long num_words;
-       static const ulong bitpattern[] = {
-               0x00000001,     /* single bit */
-               0x00000003,     /* two adjacent bits */
-               0x00000007,     /* three adjacent bits */
-               0x0000000F,     /* four adjacent bits */
-               0x00000005,     /* two non-adjacent bits */
-               0x00000015,     /* three non-adjacent bits */
-               0x00000055,     /* four non-adjacent bits */
-               0xaaaaaaaa,     /* alternating 1/0 */
-       };
-
-       num_words = (end_addr - start_addr) / sizeof(vu_long);
-
-       /*
-        * Data line test: write a pattern to the first
-        * location, write the 1's complement to a 'parking'
-        * address (changes the state of the data bus so a
-        * floating bus doesn't give a false OK), and then
-        * read the value back. Note that we read it back
-        * into a variable because the next time we read it,
-        * it might be right (been there, tough to explain to
-        * the quality guys why it prints a failure when the
-        * "is" and "should be" are obviously the same in the
-        * error message).
-        *
-        * Rather than exhaustively testing, we test some
-        * patterns by shifting '1' bits through a field of
-        * '0's and '0' bits through a field of '1's (i.e.
-        * pattern and ~pattern).
-        */
-       addr = buf;
-       for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
-               val = bitpattern[j];
-               for (; val != 0; val <<= 1) {
-                       *addr = val;
-                       *dummy  = ~val; /* clear the test data off the bus */
-                       readback = *addr;
-                       if (readback != val) {
-                               printf("FAILURE (data line): "
-                                       "expected %08lx, actual %08lx\n",
-                                               val, readback);
-                               errs++;
-                               if (ctrlc())
-                                       return -1;
-                       }
-                       *addr  = ~val;
-                       *dummy  = val;
-                       readback = *addr;
-                       if (readback != ~val) {
-                               printf("FAILURE (data line): "
-                                       "Is %08lx, should be %08lx\n",
-                                               readback, ~val);
-                               errs++;
-                               if (ctrlc())
-                                       return -1;
-                       }
-               }
-       }
-
-       /*
-        * Based on code whose Original Author and Copyright
-        * information follows: Copyright (c) 1998 by Michael
-        * Barr. This software is placed into the public
-        * domain and may be used for any purpose. However,
-        * this notice must not be changed or removed and no
-        * warranty is either expressed or implied by its
-        * publication or distribution.
-        */
-
-       /*
-       * Address line test
-
-        * Description: Test the address bus wiring in a
-        *              memory region by performing a walking
-        *              1's test on the relevant bits of the
-        *              address and checking for aliasing.
-        *              This test will find single-bit
-        *              address failures such as stuck-high,
-        *              stuck-low, and shorted pins. The base
-        *              address and size of the region are
-        *              selected by the caller.
-
-        * Notes:       For best results, the selected base
-        *              address should have enough LSB 0's to
-        *              guarantee single address bit changes.
-        *              For example, to test a 64-Kbyte
-        *              region, select a base address on a
-        *              64-Kbyte boundary. Also, select the
-        *              region size as a power-of-two if at
-        *              all possible.
-        *
-        * Returns:     0 if the test succeeds, 1 if the test fails.
-        */
-       pattern = (vu_long) 0xaaaaaaaa;
-       anti_pattern = (vu_long) 0x55555555;
-
-       debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
-       /*
-        * Write the default pattern at each of the
-        * power-of-two offsets.
-        */
-       for (offset = 1; offset < num_words; offset <<= 1)
-               addr[offset] = pattern;
-
-       /*
-        * Check for address bits stuck high.
-        */
-       test_offset = 0;
-       addr[test_offset] = anti_pattern;
-
-       for (offset = 1; offset < num_words; offset <<= 1) {
-               temp = addr[offset];
-               if (temp != pattern) {
-                       printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
-                               " expected 0x%.8lx, actual 0x%.8lx\n",
-                               start_addr + offset*sizeof(vu_long),
-                               pattern, temp);
-                       errs++;
-                       if (ctrlc())
-                               return -1;
-               }
-       }
-       addr[test_offset] = pattern;
-       WATCHDOG_RESET();
-
-       /*
-        * Check for addr bits stuck low or shorted.
-        */
-       for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
-               addr[test_offset] = anti_pattern;
-
-               for (offset = 1; offset < num_words; offset <<= 1) {
-                       temp = addr[offset];
-                       if ((temp != pattern) && (offset != test_offset)) {
-                               printf("\nFAILURE: Address bit stuck low or"
-                                       " shorted @ 0x%.8lx: expected 0x%.8lx,"
-                                       " actual 0x%.8lx\n",
-                                       start_addr + offset*sizeof(vu_long),
-                                       pattern, temp);
-                               errs++;
-                               if (ctrlc())
-                                       return -1;
-                       }
-               }
-               addr[test_offset] = pattern;
-       }
-
-       /*
-        * Description: Test the integrity of a physical
-        *              memory device by performing an
-        *              increment/decrement test over the
-        *              entire region. In the process every
-        *              storage bit in the device is tested
-        *              as a zero and a one. The base address
-        *              and the size of the region are
-        *              selected by the caller.
-        *
-        * Returns:     0 if the test succeeds, 1 if the test fails.
-        */
-       num_words++;
-
-       /*
-        * Fill memory with a known pattern.
-        */
-       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-               WATCHDOG_RESET();
-               addr[offset] = pattern;
-       }
-
-       /*
-        * Check each location and invert it for the second pass.
-        */
-       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-               WATCHDOG_RESET();
-               temp = addr[offset];
-               if (temp != pattern) {
-                       printf("\nFAILURE (read/write) @ 0x%.8lx:"
-                               " expected 0x%.8lx, actual 0x%.8lx)\n",
-                               start_addr + offset*sizeof(vu_long),
-                               pattern, temp);
-                       errs++;
-                       if (ctrlc())
-                               return -1;
-               }
-
-               anti_pattern = ~pattern;
-               addr[offset] = anti_pattern;
-       }
-
-       /*
-        * Check each location for the inverted pattern and zero it.
-        */
-       for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-               WATCHDOG_RESET();
-               anti_pattern = ~pattern;
-               temp = addr[offset];
-               if (temp != anti_pattern) {
-                       printf("\nFAILURE (read/write): @ 0x%.8lx:"
-                               " expected 0x%.8lx, actual 0x%.8lx)\n",
-                               start_addr + offset*sizeof(vu_long),
-                               anti_pattern, temp);
-                       errs++;
-                       if (ctrlc())
-                               return -1;
-               }
-               addr[offset] = 0;
-       }
-
-       return errs;
-}
-
-static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
-                           vu_long pattern, int iteration)
-{
-       vu_long *end;
-       vu_long *addr;
-       ulong errs = 0;
-       ulong incr, length;
-       ulong val, readback;
-
-       /* Alternate the pattern */
-       incr = 1;
-       if (iteration & 1) {
-               incr = -incr;
-               /*
-                * Flip the pattern each time to make lots of zeros and
-                * then, the next time, lots of ones.  We decrement
-                * the "negative" patterns and increment the "positive"
-                * patterns to preserve this feature.
-                */
-               if (pattern & 0x80000000)
-                       pattern = -pattern;     /* complement & increment */
-               else
-                       pattern = ~pattern;
-       }
-       length = (end_addr - start_addr) / sizeof(ulong);
-       end = buf + length;
-       printf("\rPattern %08lX  Writing..."
-               "%12s"
-               "\b\b\b\b\b\b\b\b\b\b",
-               pattern, "");
-
-       for (addr = buf, val = pattern; addr < end; addr++) {
-               WATCHDOG_RESET();
-               *addr = val;
-               val += incr;
-       }
-
-       puts("Reading...");
-
-       for (addr = buf, val = pattern; addr < end; addr++) {
-               WATCHDOG_RESET();
-               readback = *addr;
-               if (readback != val) {
-                       ulong offset = addr - buf;
-
-                       printf("\nMem error @ 0x%08X: "
-                               "found %08lX, expected %08lX\n",
-                               (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
-                               readback, val);
-                       errs++;
-                       if (ctrlc())
-                               return -1;
-               }
-               val += incr;
-       }
-
-       return errs;
-}
-
-/*
- * Perform a memory test. A more complete alternative test can be
- * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
- * interrupted by ctrl-c or by a failure of one of the sub-tests.
- */
-static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       ulong start, end;
-       vu_long *buf, *dummy;
-       ulong iteration_limit = 0;
-       int ret;
-       ulong errs = 0; /* number of errors, or -1 if interrupted */
-       ulong pattern = 0;
-       int iteration;
-#if defined(CONFIG_SYS_ALT_MEMTEST)
-       const int alt_test = 1;
-#else
-       const int alt_test = 0;
-#endif
-
-       start = CONFIG_SYS_MEMTEST_START;
-       end = CONFIG_SYS_MEMTEST_END;
-
-       if (argc > 1)
-               if (strict_strtoul(argv[1], 16, &start) < 0)
-                       return CMD_RET_USAGE;
-
-       if (argc > 2)
-               if (strict_strtoul(argv[2], 16, &end) < 0)
-                       return CMD_RET_USAGE;
-
-       if (argc > 3)
-               if (strict_strtoul(argv[3], 16, &pattern) < 0)
-                       return CMD_RET_USAGE;
-
-       if (argc > 4)
-               if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
-                       return CMD_RET_USAGE;
-
-       if (end < start) {
-               printf("Refusing to do empty test\n");
-               return -1;
-       }
-
-       printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
-       debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
-             start, end);
-
-       buf = map_sysmem(start, end - start);
-       dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
-       for (iteration = 0;
-                       !iteration_limit || iteration < iteration_limit;
-                       iteration++) {
-               if (ctrlc()) {
-                       errs = -1UL;
-                       break;
-               }
-
-               printf("Iteration: %6d\r", iteration + 1);
-               debug("\n");
-               if (alt_test) {
-                       errs = mem_test_alt(buf, start, end, dummy);
-               } else {
-                       errs = mem_test_quick(buf, start, end, pattern,
-                                             iteration);
-               }
-               if (errs == -1UL)
-                       break;
-       }
-
-       /*
-        * Work-around for eldk-4.2 which gives this warning if we try to
-        * case in the unmap_sysmem() call:
-        * warning: initialization discards qualifiers from pointer target type
-        */
-       {
-               void *vbuf = (void *)buf;
-               void *vdummy = (void *)dummy;
-
-               unmap_sysmem(vbuf);
-               unmap_sysmem(vdummy);
-       }
-
-       if (errs == -1UL) {
-               /* Memory test was aborted - write a newline to finish off */
-               putc('\n');
-               ret = 1;
-       } else {
-               printf("Tested %d iteration(s) with %lu errors.\n",
-                       iteration, errs);
-               ret = errs != 0;
-       }
-
-       return ret;
-}
-#endif /* CONFIG_CMD_MEMTEST */
-
-/* Modify memory.
- *
- * Syntax:
- *     mm{.b, .w, .l, .q} {addr}
- *     nm{.b, .w, .l, .q} {addr}
- */
-static int
-mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
-{
-       ulong   addr;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       u64 i;
-#else
-       ulong i;
-#endif
-       int     nbytes, size;
-       void *ptr = NULL;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       bootretry_reset_cmd_timeout();  /* got a good command to get here */
-       /* We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       addr = mm_last_addr;
-       size = mm_last_size;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /* New command specified.  Check for a size specification.
-                * Defaults to long if no or incorrect specification.
-                */
-               if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-                       return 1;
-
-               /* Address is specified since argc > 1
-               */
-               addr = simple_strtoul(argv[1], NULL, 16);
-               addr += base_address;
-       }
-
-#ifdef CONFIG_HAS_DATAFLASH
-       if (addr_dataflash(addr)){
-               puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
-               return 0;
-       }
-#endif
-
-#ifdef CONFIG_BLACKFIN
-       if (addr_bfin_on_chip_mem(addr)) {
-               puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
-               return 0;
-       }
-#endif
-
-       /* Print the address, followed by value.  Then accept input for
-        * the next value.  A non-converted value exits.
-        */
-       do {
-               ptr = map_sysmem(addr, size);
-               printf("%08lx:", addr);
-               if (size == 4)
-                       printf(" %08x", *((u32 *)ptr));
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-               else if (size == 8)
-                       printf(" %016" PRIx64, *((u64 *)ptr));
-#endif
-               else if (size == 2)
-                       printf(" %04x", *((u16 *)ptr));
-               else
-                       printf(" %02x", *((u8 *)ptr));
-
-               nbytes = cli_readline(" ? ");
-               if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
-                       /* <CR> pressed as only input, don't modify current
-                        * location and move to next. "-" pressed will go back.
-                        */
-                       if (incrflag)
-                               addr += nbytes ? -size : size;
-                       nbytes = 1;
-                       /* good enough to not time out */
-                       bootretry_reset_cmd_timeout();
-               }
-#ifdef CONFIG_BOOT_RETRY_TIME
-               else if (nbytes == -2) {
-                       break;  /* timed out, exit the command  */
-               }
-#endif
-               else {
-                       char *endp;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-                       i = simple_strtoull(console_buffer, &endp, 16);
-#else
-                       i = simple_strtoul(console_buffer, &endp, 16);
-#endif
-                       nbytes = endp - console_buffer;
-                       if (nbytes) {
-                               /* good enough to not time out
-                                */
-                               bootretry_reset_cmd_timeout();
-                               if (size == 4)
-                                       *((u32 *)ptr) = i;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-                               else if (size == 8)
-                                       *((u64 *)ptr) = i;
-#endif
-                               else if (size == 2)
-                                       *((u16 *)ptr) = i;
-                               else
-                                       *((u8 *)ptr) = i;
-                               if (incrflag)
-                                       addr += size;
-                       }
-               }
-       } while (nbytes);
-       if (ptr)
-               unmap_sysmem(ptr);
-
-       mm_last_addr = addr;
-       mm_last_size = size;
-       return 0;
-}
-
-#ifdef CONFIG_CMD_CRC32
-
-static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int flags = 0;
-       int ac;
-       char * const *av;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       av = argv + 1;
-       ac = argc - 1;
-#ifdef CONFIG_HASH_VERIFY
-       if (strcmp(*av, "-v") == 0) {
-               flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
-               av++;
-               ac--;
-       }
-#endif
-
-       return hash_command("crc32", flags, cmdtp, flag, ac, av);
-}
-
-#endif
-
-/**************************************************/
-U_BOOT_CMD(
-       md,     3,      1,      do_mem_md,
-       "memory display",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address [# of objects]"
-#else
-       "[.b, .w, .l] address [# of objects]"
-#endif
-);
-
-
-U_BOOT_CMD(
-       mm,     2,      1,      do_mem_mm,
-       "memory modify (auto-incrementing address)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address"
-#else
-       "[.b, .w, .l] address"
-#endif
-);
-
-
-U_BOOT_CMD(
-       nm,     2,      1,      do_mem_nm,
-       "memory modify (constant address)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address"
-#else
-       "[.b, .w, .l] address"
-#endif
-);
-
-U_BOOT_CMD(
-       mw,     4,      1,      do_mem_mw,
-       "memory write (fill)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address value [count]"
-#else
-       "[.b, .w, .l] address value [count]"
-#endif
-);
-
-U_BOOT_CMD(
-       cp,     4,      1,      do_mem_cp,
-       "memory copy",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] source target count"
-#else
-       "[.b, .w, .l] source target count"
-#endif
-);
-
-U_BOOT_CMD(
-       cmp,    4,      1,      do_mem_cmp,
-       "memory compare",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] addr1 addr2 count"
-#else
-       "[.b, .w, .l] addr1 addr2 count"
-#endif
-);
-
-#ifdef CONFIG_CMD_CRC32
-
-#ifndef CONFIG_HASH_VERIFY
-
-U_BOOT_CMD(
-       crc32,  4,      1,      do_mem_crc,
-       "checksum calculation",
-       "address count [addr]\n    - compute CRC32 checksum [save at addr]"
-);
-
-#else  /* CONFIG_HASH_VERIFY */
-
-U_BOOT_CMD(
-       crc32,  5,      1,      do_mem_crc,
-       "checksum calculation",
-       "address count [addr]\n    - compute CRC32 checksum [save at addr]\n"
-       "-v address count crc\n    - verify crc of memory area"
-);
-
-#endif /* CONFIG_HASH_VERIFY */
-
-#endif
-
-#ifdef CONFIG_CMD_MEMINFO
-__weak void board_show_dram(phys_size_t size)
-{
-       puts("DRAM:  ");
-       print_size(size, "\n");
-}
-
-static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       board_show_dram(gd->ram_size);
-
-       return 0;
-}
-#endif
-
-U_BOOT_CMD(
-       base,   2,      1,      do_mem_base,
-       "print or set address offset",
-       "\n    - print address offset for memory commands\n"
-       "base off\n    - set address offset for memory commands to 'off'"
-);
-
-U_BOOT_CMD(
-       loop,   3,      1,      do_mem_loop,
-       "infinite loop on address range",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address number_of_objects"
-#else
-       "[.b, .w, .l] address number_of_objects"
-#endif
-);
-
-#ifdef CONFIG_LOOPW
-U_BOOT_CMD(
-       loopw,  4,      1,      do_mem_loopw,
-       "infinite write loop on address range",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address number_of_objects data_to_write"
-#else
-       "[.b, .w, .l] address number_of_objects data_to_write"
-#endif
-);
-#endif /* CONFIG_LOOPW */
-
-#ifdef CONFIG_CMD_MEMTEST
-U_BOOT_CMD(
-       mtest,  5,      1,      do_mem_mtest,
-       "simple RAM read/write test",
-       "[start [end [pattern [iterations]]]]"
-);
-#endif /* CONFIG_CMD_MEMTEST */
-
-#ifdef CONFIG_MX_CYCLIC
-U_BOOT_CMD(
-       mdc,    4,      1,      do_mem_mdc,
-       "memory display cyclic",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address count delay(ms)"
-#else
-       "[.b, .w, .l] address count delay(ms)"
-#endif
-);
-
-U_BOOT_CMD(
-       mwc,    4,      1,      do_mem_mwc,
-       "memory write cyclic",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-       "[.b, .w, .l, .q] address value delay(ms)"
-#else
-       "[.b, .w, .l] address value delay(ms)"
-#endif
-);
-#endif /* CONFIG_MX_CYCLIC */
-
-#ifdef CONFIG_CMD_MEMINFO
-U_BOOT_CMD(
-       meminfo,        3,      1,      do_mem_info,
-       "display memory information",
-       ""
-);
-#endif
diff --git a/common/cmd_mfsl.c b/common/cmd_mfsl.c
deleted file mode 100644 (file)
index e8e8e3c..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * (C) Copyright 2007 Michal Simek
- *
- * Michal  SIMEK <monstr@monstr.eu>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Microblaze FSL support
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <asm/asm.h>
-
-int do_frd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int fslnum;
-       unsigned int num;
-       unsigned int blocking;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
-       blocking = (unsigned int)simple_strtoul (argv[2], NULL, 16);
-       if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER) {
-               puts ("Bad number of FSL\n");
-               return CMD_RET_USAGE;
-       }
-
-       switch (fslnum) {
-#if (XILINX_FSL_NUMBER > 0)
-       case 0:
-               switch (blocking) {
-               case 0: NGET (num, 0);
-                       break;
-               case 1: NCGET (num, 0);
-                       break;
-               case 2: GET (num, 0);
-                       break;
-               case 3: CGET (num, 0);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 1)
-       case 1:
-               switch (blocking) {
-               case 0: NGET (num, 1);
-                       break;
-               case 1: NCGET (num, 1);
-                       break;
-               case 2: GET (num, 1);
-                       break;
-               case 3: CGET (num, 1);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 2)
-       case 2:
-               switch (blocking) {
-               case 0: NGET (num, 2);
-                       break;
-               case 1: NCGET (num, 2);
-                       break;
-               case 2: GET (num, 2);
-                       break;
-               case 3: CGET (num, 2);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 3)
-       case 3:
-               switch (blocking) {
-               case 0: NGET (num, 3);
-                       break;
-               case 1: NCGET (num, 3);
-                       break;
-               case 2: GET (num, 3);
-                       break;
-               case 3: CGET (num, 3);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 4)
-       case 4:
-               switch (blocking) {
-               case 0: NGET (num, 4);
-                       break;
-               case 1: NCGET (num, 4);
-                       break;
-               case 2: GET (num, 4);
-                       break;
-               case 3: CGET (num, 4);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 5)
-       case 5:
-               switch (blocking) {
-               case 0: NGET (num, 5);
-                       break;
-               case 1: NCGET (num, 5);
-                       break;
-               case 2: GET (num, 5);
-                       break;
-               case 3: CGET (num, 5);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 6)
-       case 6:
-               switch (blocking) {
-               case 0: NGET (num, 6);
-                       break;
-               case 1: NCGET (num, 6);
-                       break;
-               case 2: GET (num, 6);
-                       break;
-               case 3: CGET (num, 6);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 7)
-       case 7:
-               switch (blocking) {
-               case 0: NGET (num, 7);
-                       break;
-               case 1: NCGET (num, 7);
-                       break;
-               case 2: GET (num, 7);
-                       break;
-               case 3: CGET (num, 7);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-       default:
-               return 1;
-       }
-
-       printf ("%01x: 0x%08x - %s %s read\n", fslnum, num,
-               blocking < 2  ? "non blocking" : "blocking",
-               ((blocking == 1) || (blocking == 3)) ? "control" : "data" );
-       return 0;
-}
-
-int do_fwr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int fslnum;
-       unsigned int num;
-       unsigned int blocking;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16);
-       num = (unsigned int)simple_strtoul (argv[2], NULL, 16);
-       blocking = (unsigned int)simple_strtoul (argv[3], NULL, 16);
-       if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER)
-               return CMD_RET_USAGE;
-
-       switch (fslnum) {
-#if (XILINX_FSL_NUMBER > 0)
-       case 0:
-               switch (blocking) {
-               case 0: NPUT (num, 0);
-                       break;
-               case 1: NCPUT (num, 0);
-                       break;
-               case 2: PUT (num, 0);
-                       break;
-               case 3: CPUT (num, 0);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 1)
-       case 1:
-               switch (blocking) {
-               case 0: NPUT (num, 1);
-                       break;
-               case 1: NCPUT (num, 1);
-                       break;
-               case 2: PUT (num, 1);
-                       break;
-               case 3: CPUT (num, 1);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 2)
-       case 2:
-               switch (blocking) {
-               case 0: NPUT (num, 2);
-                       break;
-               case 1: NCPUT (num, 2);
-                       break;
-               case 2: PUT (num, 2);
-                       break;
-               case 3: CPUT (num, 2);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 3)
-       case 3:
-               switch (blocking) {
-               case 0: NPUT (num, 3);
-                       break;
-               case 1: NCPUT (num, 3);
-                       break;
-               case 2: PUT (num, 3);
-                       break;
-               case 3: CPUT (num, 3);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 4)
-       case 4:
-               switch (blocking) {
-               case 0: NPUT (num, 4);
-                       break;
-               case 1: NCPUT (num, 4);
-                       break;
-               case 2: PUT (num, 4);
-                       break;
-               case 3: CPUT (num, 4);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 5)
-       case 5:
-               switch (blocking) {
-               case 0: NPUT (num, 5);
-                       break;
-               case 1: NCPUT (num, 5);
-                       break;
-               case 2: PUT (num, 5);
-                       break;
-               case 3: CPUT (num, 5);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 6)
-       case 6:
-               switch (blocking) {
-               case 0: NPUT (num, 6);
-                       break;
-               case 1: NCPUT (num, 6);
-                       break;
-               case 2: PUT (num, 6);
-                       break;
-               case 3: CPUT (num, 6);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-#if (XILINX_FSL_NUMBER > 7)
-       case 7:
-               switch (blocking) {
-               case 0: NPUT (num, 7);
-                       break;
-               case 1: NCPUT (num, 7);
-                       break;
-               case 2: PUT (num, 7);
-                       break;
-               case 3: CPUT (num, 7);
-                       break;
-               default:
-                       return 2;
-               }
-               break;
-#endif
-       default:
-               return 1;
-       }
-
-       printf ("%01x: 0x%08x - %s %s write\n", fslnum, num,
-               blocking < 2  ? "non blocking" : "blocking",
-               ((blocking == 1) || (blocking == 3)) ? "control" : "data" );
-       return 0;
-
-}
-
-int do_rspr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned int reg = 0;
-       unsigned int val = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       reg = (unsigned int)simple_strtoul (argv[1], NULL, 16);
-       val = (unsigned int)simple_strtoul (argv[2], NULL, 16);
-       switch (reg) {
-       case 0x1:
-               if (argc > 2) {
-                       MTS (val, rmsr);
-                       NOP;
-                       MFS (val, rmsr);
-               } else {
-                       MFS (val, rmsr);
-               }
-               puts ("MSR");
-               break;
-       case 0x3:
-               MFS (val, rear);
-               puts ("EAR");
-               break;
-       case 0x5:
-               MFS (val, resr);
-               puts ("ESR");
-               break;
-       default:
-               puts ("Unsupported register\n");
-               return 1;
-       }
-       printf (": 0x%08x\n", val);
-       return 0;
-}
-
-/***************************************************/
-
-U_BOOT_CMD (frd, 3, 1, do_frd,
-               "read data from FSL",
-               "- [fslnum [0|1|2|3]]\n"
-               " 0 - non blocking data read\n"
-               " 1 - non blocking control read\n"
-               " 2 - blocking data read\n"
-               " 3 - blocking control read");
-
-U_BOOT_CMD (fwr, 4, 1, do_fwr,
-               "write data to FSL",
-               "- [fslnum [0|1|2|3]]\n"
-               " 0 - non blocking data write\n"
-               " 1 - non blocking control write\n"
-               " 2 - blocking data write\n"
-               " 3 - blocking control write");
-
-U_BOOT_CMD (rspr, 3, 1, do_rspr,
-               "read/write special purpose register",
-               "- reg_num [write value] read/write special purpose register\n"
-               " 1 - MSR - Machine status register\n"
-               " 3 - EAR - Exception address register\n"
-               " 5 - ESR - Exception status register");
diff --git a/common/cmd_mii.c b/common/cmd_mii.c
deleted file mode 100644 (file)
index 7ef7532..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * (C) Copyright 2001
- * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * MII Utilities
- */
-
-#include <common.h>
-#include <command.h>
-#include <miiphy.h>
-
-typedef struct _MII_reg_desc_t {
-       ushort regno;
-       char * name;
-} MII_reg_desc_t;
-
-static const MII_reg_desc_t reg_0_5_desc_tbl[] = {
-       { MII_BMCR,      "PHY control register" },
-       { MII_BMSR,      "PHY status register" },
-       { MII_PHYSID1,   "PHY ID 1 register" },
-       { MII_PHYSID2,   "PHY ID 2 register" },
-       { MII_ADVERTISE, "Autonegotiation advertisement register" },
-       { MII_LPA,       "Autonegotiation partner abilities register" },
-};
-
-typedef struct _MII_field_desc_t {
-       ushort hi;
-       ushort lo;
-       ushort mask;
-       char * name;
-} MII_field_desc_t;
-
-static const MII_field_desc_t reg_0_desc_tbl[] = {
-       { 15, 15, 0x01, "reset"                        },
-       { 14, 14, 0x01, "loopback"                     },
-       { 13,  6, 0x81, "speed selection"              }, /* special */
-       { 12, 12, 0x01, "A/N enable"                   },
-       { 11, 11, 0x01, "power-down"                   },
-       { 10, 10, 0x01, "isolate"                      },
-       {  9,  9, 0x01, "restart A/N"                  },
-       {  8,  8, 0x01, "duplex"                       }, /* special */
-       {  7,  7, 0x01, "collision test enable"        },
-       {  5,  0, 0x3f, "(reserved)"                   }
-};
-
-static const MII_field_desc_t reg_1_desc_tbl[] = {
-       { 15, 15, 0x01, "100BASE-T4 able"              },
-       { 14, 14, 0x01, "100BASE-X  full duplex able"  },
-       { 13, 13, 0x01, "100BASE-X  half duplex able"  },
-       { 12, 12, 0x01, "10 Mbps    full duplex able"  },
-       { 11, 11, 0x01, "10 Mbps    half duplex able"  },
-       { 10, 10, 0x01, "100BASE-T2 full duplex able"  },
-       {  9,  9, 0x01, "100BASE-T2 half duplex able"  },
-       {  8,  8, 0x01, "extended status"              },
-       {  7,  7, 0x01, "(reserved)"                   },
-       {  6,  6, 0x01, "MF preamble suppression"      },
-       {  5,  5, 0x01, "A/N complete"                 },
-       {  4,  4, 0x01, "remote fault"                 },
-       {  3,  3, 0x01, "A/N able"                     },
-       {  2,  2, 0x01, "link status"                  },
-       {  1,  1, 0x01, "jabber detect"                },
-       {  0,  0, 0x01, "extended capabilities"        },
-};
-
-static const MII_field_desc_t reg_2_desc_tbl[] = {
-       { 15,  0, 0xffff, "OUI portion"                },
-};
-
-static const MII_field_desc_t reg_3_desc_tbl[] = {
-       { 15, 10, 0x3f, "OUI portion"                },
-       {  9,  4, 0x3f, "manufacturer part number"   },
-       {  3,  0, 0x0f, "manufacturer rev. number"   },
-};
-
-static const MII_field_desc_t reg_4_desc_tbl[] = {
-       { 15, 15, 0x01, "next page able"               },
-       { 14, 14, 0x01, "(reserved)"                   },
-       { 13, 13, 0x01, "remote fault"                 },
-       { 12, 12, 0x01, "(reserved)"                   },
-       { 11, 11, 0x01, "asymmetric pause"             },
-       { 10, 10, 0x01, "pause enable"                 },
-       {  9,  9, 0x01, "100BASE-T4 able"              },
-       {  8,  8, 0x01, "100BASE-TX full duplex able"  },
-       {  7,  7, 0x01, "100BASE-TX able"              },
-       {  6,  6, 0x01, "10BASE-T   full duplex able"  },
-       {  5,  5, 0x01, "10BASE-T   able"              },
-       {  4,  0, 0x1f, "xxx to do"                    },
-};
-
-static const MII_field_desc_t reg_5_desc_tbl[] = {
-       { 15, 15, 0x01, "next page able"               },
-       { 14, 14, 0x01, "acknowledge"                  },
-       { 13, 13, 0x01, "remote fault"                 },
-       { 12, 12, 0x01, "(reserved)"                   },
-       { 11, 11, 0x01, "asymmetric pause able"        },
-       { 10, 10, 0x01, "pause able"                   },
-       {  9,  9, 0x01, "100BASE-T4 able"              },
-       {  8,  8, 0x01, "100BASE-X full duplex able"   },
-       {  7,  7, 0x01, "100BASE-TX able"              },
-       {  6,  6, 0x01, "10BASE-T full duplex able"    },
-       {  5,  5, 0x01, "10BASE-T able"                },
-       {  4,  0, 0x1f, "xxx to do"                    },
-};
-typedef struct _MII_field_desc_and_len_t {
-       const MII_field_desc_t *pdesc;
-       ushort len;
-} MII_field_desc_and_len_t;
-
-static const MII_field_desc_and_len_t desc_and_len_tbl[] = {
-       { reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl)   },
-       { reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl)   },
-       { reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl)   },
-       { reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl)   },
-       { reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl)   },
-       { reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl)   },
-};
-
-static void dump_reg(
-       ushort             regval,
-       const MII_reg_desc_t *prd,
-       const MII_field_desc_and_len_t *pdl);
-
-static int special_field(
-       ushort regno,
-       const MII_field_desc_t *pdesc,
-       ushort regval);
-
-static void MII_dump_0_to_5(
-       ushort regvals[6],
-       uchar reglo,
-       uchar reghi)
-{
-       ulong i;
-
-       for (i = 0; i < 6; i++) {
-               if ((reglo <= i) && (i <= reghi))
-                       dump_reg(regvals[i], &reg_0_5_desc_tbl[i],
-                               &desc_and_len_tbl[i]);
-       }
-}
-
-static void dump_reg(
-       ushort             regval,
-       const MII_reg_desc_t *prd,
-       const MII_field_desc_and_len_t *pdl)
-{
-       ulong i;
-       ushort mask_in_place;
-       const MII_field_desc_t *pdesc;
-
-       printf("%u.     (%04hx)                 -- %s --\n",
-               prd->regno, regval, prd->name);
-
-       for (i = 0; i < pdl->len; i++) {
-               pdesc = &pdl->pdesc[i];
-
-               mask_in_place = pdesc->mask << pdesc->lo;
-
-               printf("  (%04hx:%04x) %u.",
-                      mask_in_place,
-                      regval & mask_in_place,
-                      prd->regno);
-
-               if (special_field(prd->regno, pdesc, regval)) {
-               }
-               else {
-                       if (pdesc->hi == pdesc->lo)
-                               printf("%2u   ", pdesc->lo);
-                       else
-                               printf("%2u-%2u", pdesc->hi, pdesc->lo);
-                       printf(" = %5u    %s",
-                               (regval & mask_in_place) >> pdesc->lo,
-                               pdesc->name);
-               }
-               printf("\n");
-
-       }
-       printf("\n");
-}
-
-/* Special fields:
-** 0.6,13
-** 0.8
-** 2.15-0
-** 3.15-0
-** 4.4-0
-** 5.4-0
-*/
-
-static int special_field(
-       ushort regno,
-       const MII_field_desc_t *pdesc,
-       ushort regval)
-{
-       if ((regno == MII_BMCR) && (pdesc->lo == 6)) {
-               ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100);
-               printf("%2u,%2u =   b%u%u    speed selection = %s Mbps",
-                       6, 13,
-                       (regval >>  6) & 1,
-                       (regval >> 13) & 1,
-                       speed_bits == BMCR_SPEED1000 ? "1000" :
-                       speed_bits == BMCR_SPEED100  ? "100" :
-                       "10");
-               return 1;
-       }
-
-       else if ((regno == MII_BMCR) && (pdesc->lo == 8)) {
-               printf("%2u    = %5u    duplex = %s",
-                       pdesc->lo,
-                       (regval >>  pdesc->lo) & 1,
-                       ((regval >> pdesc->lo) & 1) ? "full" : "half");
-               return 1;
-       }
-
-       else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) {
-               ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
-               printf("%2u-%2u = %5u    selector = %s",
-                       pdesc->hi, pdesc->lo, sel_bits,
-                       sel_bits == PHY_ANLPAR_PSB_802_3 ?
-                               "IEEE 802.3" :
-                       sel_bits == PHY_ANLPAR_PSB_802_9 ?
-                               "IEEE 802.9 ISLAN-16T" :
-                       "???");
-               return 1;
-       }
-
-       else if ((regno == MII_LPA) && (pdesc->lo == 0)) {
-               ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
-               printf("%2u-%2u =     %u    selector = %s",
-                       pdesc->hi, pdesc->lo, sel_bits,
-                       sel_bits == PHY_ANLPAR_PSB_802_3 ?
-                               "IEEE 802.3" :
-                       sel_bits == PHY_ANLPAR_PSB_802_9 ?
-                               "IEEE 802.9 ISLAN-16T" :
-                       "???");
-               return 1;
-       }
-
-       return 0;
-}
-
-static char last_op[2];
-static uint last_data;
-static uint last_addr_lo;
-static uint last_addr_hi;
-static uint last_reg_lo;
-static uint last_reg_hi;
-static uint last_mask;
-
-static void extract_range(
-       char * input,
-       unsigned char * plo,
-       unsigned char * phi)
-{
-       char * end;
-       *plo = simple_strtoul(input, &end, 16);
-       if (*end == '-') {
-               end++;
-               *phi = simple_strtoul(end, NULL, 16);
-       }
-       else {
-               *phi = *plo;
-       }
-}
-
-/* ---------------------------------------------------------------- */
-static int do_mii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char            op[2];
-       unsigned char   addrlo, addrhi, reglo, reghi;
-       unsigned char   addr, reg;
-       unsigned short  data, mask;
-       int             rcode = 0;
-       const char      *devname;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-#if defined(CONFIG_MII_INIT)
-       mii_init ();
-#endif
-
-       /*
-        * We use the last specified parameters, unless new ones are
-        * entered.
-        */
-       op[0] = last_op[0];
-       op[1] = last_op[1];
-       addrlo = last_addr_lo;
-       addrhi = last_addr_hi;
-       reglo  = last_reg_lo;
-       reghi  = last_reg_hi;
-       data   = last_data;
-       mask   = last_mask;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               op[0] = argv[1][0];
-               if (strlen(argv[1]) > 1)
-                       op[1] = argv[1][1];
-               else
-                       op[1] = '\0';
-
-               if (argc >= 3)
-                       extract_range(argv[2], &addrlo, &addrhi);
-               if (argc >= 4)
-                       extract_range(argv[3], &reglo, &reghi);
-               if (argc >= 5)
-                       data = simple_strtoul(argv[4], NULL, 16);
-               if (argc >= 6)
-                       mask = simple_strtoul(argv[5], NULL, 16);
-       }
-
-       if (addrhi > 31) {
-               printf("Incorrect PHY address. Range should be 0-31\n");
-               return CMD_RET_USAGE;
-       }
-
-       /* use current device */
-       devname = miiphy_get_current_dev();
-
-       /*
-        * check info/read/write.
-        */
-       if (op[0] == 'i') {
-               unsigned char j, start, end;
-               unsigned int oui;
-               unsigned char model;
-               unsigned char rev;
-
-               /*
-                * Look for any and all PHYs.  Valid addresses are 0..31.
-                */
-               if (argc >= 3) {
-                       start = addrlo; end = addrhi;
-               } else {
-                       start = 0; end = 31;
-               }
-
-               for (j = start; j <= end; j++) {
-                       if (miiphy_info (devname, j, &oui, &model, &rev) == 0) {
-                               printf("PHY 0x%02X: "
-                                       "OUI = 0x%04X, "
-                                       "Model = 0x%02X, "
-                                       "Rev = 0x%02X, "
-                                       "%3dbase%s, %s\n",
-                                       j, oui, model, rev,
-                                       miiphy_speed (devname, j),
-                                       miiphy_is_1000base_x (devname, j)
-                                               ? "X" : "T",
-                                       (miiphy_duplex (devname, j) == FULL)
-                                               ? "FDX" : "HDX");
-                       }
-               }
-       } else if (op[0] == 'r') {
-               for (addr = addrlo; addr <= addrhi; addr++) {
-                       for (reg = reglo; reg <= reghi; reg++) {
-                               data = 0xffff;
-                               if (miiphy_read (devname, addr, reg, &data) != 0) {
-                                       printf(
-                                       "Error reading from the PHY addr=%02x reg=%02x\n",
-                                               addr, reg);
-                                       rcode = 1;
-                               } else {
-                                       if ((addrlo != addrhi) || (reglo != reghi))
-                                               printf("addr=%02x reg=%02x data=",
-                                                       (uint)addr, (uint)reg);
-                                       printf("%04X\n", data & 0x0000FFFF);
-                               }
-                       }
-                       if ((addrlo != addrhi) && (reglo != reghi))
-                               printf("\n");
-               }
-       } else if (op[0] == 'w') {
-               for (addr = addrlo; addr <= addrhi; addr++) {
-                       for (reg = reglo; reg <= reghi; reg++) {
-                               if (miiphy_write (devname, addr, reg, data) != 0) {
-                                       printf("Error writing to the PHY addr=%02x reg=%02x\n",
-                                               addr, reg);
-                                       rcode = 1;
-                               }
-                       }
-               }
-       } else if (op[0] == 'm') {
-               for (addr = addrlo; addr <= addrhi; addr++) {
-                       for (reg = reglo; reg <= reghi; reg++) {
-                               unsigned short val = 0;
-                               if (miiphy_read(devname, addr,
-                                               reg, &val)) {
-                                       printf("Error reading from the PHY");
-                                       printf(" addr=%02x", addr);
-                                       printf(" reg=%02x\n", reg);
-                                       rcode = 1;
-                               } else {
-                                       val = (val & ~mask) | (data & mask);
-                                       if (miiphy_write(devname, addr,
-                                                        reg, val)) {
-                                               printf("Error writing to the PHY");
-                                               printf(" addr=%02x", addr);
-                                               printf(" reg=%02x\n", reg);
-                                               rcode = 1;
-                                       }
-                               }
-                       }
-               }
-       } else if (strncmp(op, "du", 2) == 0) {
-               ushort regs[6];
-               int ok = 1;
-               if ((reglo > 5) || (reghi > 5)) {
-                       printf(
-                               "The MII dump command only formats the "
-                               "standard MII registers, 0-5.\n");
-                       return 1;
-               }
-               for (addr = addrlo; addr <= addrhi; addr++) {
-                       for (reg = reglo; reg < reghi + 1; reg++) {
-                               if (miiphy_read(devname, addr, reg, &regs[reg]) != 0) {
-                                       ok = 0;
-                                       printf(
-                                       "Error reading from the PHY addr=%02x reg=%02x\n",
-                                               addr, reg);
-                                       rcode = 1;
-                               }
-                       }
-                       if (ok)
-                               MII_dump_0_to_5(regs, reglo, reghi);
-                       printf("\n");
-               }
-       } else if (strncmp(op, "de", 2) == 0) {
-               if (argc == 2)
-                       miiphy_listdev ();
-               else
-                       miiphy_set_current_dev (argv[2]);
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       /*
-        * Save the parameters for repeats.
-        */
-       last_op[0] = op[0];
-       last_op[1] = op[1];
-       last_addr_lo = addrlo;
-       last_addr_hi = addrhi;
-       last_reg_lo  = reglo;
-       last_reg_hi  = reghi;
-       last_data    = data;
-       last_mask    = mask;
-
-       return rcode;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       mii, 6, 1, do_mii,
-       "MII utility commands",
-       "device                            - list available devices\n"
-       "mii device <devname>                  - set current device\n"
-       "mii info   <addr>                     - display MII PHY info\n"
-       "mii read   <addr> <reg>               - read  MII PHY <addr> register <reg>\n"
-       "mii write  <addr> <reg> <data>        - write MII PHY <addr> register <reg>\n"
-       "mii modify <addr> <reg> <data> <mask> - modify MII PHY <addr> register <reg>\n"
-       "                                        updating bits identified in <mask>\n"
-       "mii dump   <addr> <reg>               - pretty-print <addr> <reg> (0-5 only)\n"
-       "Addr and/or reg may be ranges, e.g. 2-7."
-);
diff --git a/common/cmd_misc.c b/common/cmd_misc.c
deleted file mode 100644 (file)
index 39d8683..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * (C) Copyright 2001
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Misc functions
- */
-#include <common.h>
-#include <command.h>
-#include <console.h>
-
-static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong start = get_timer(0);
-       ulong delay;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
-
-       while (get_timer(start) < delay) {
-               if (ctrlc())
-                       return (-1);
-
-               udelay(100);
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       sleep ,    2,    1,     do_sleep,
-       "delay execution for some time",
-       "N\n"
-       "    - delay execution for N seconds (N is _decimal_ !!!)"
-);
-
-#ifdef CONFIG_CMD_TIMER
-static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       static ulong start;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       if (!strcmp(argv[1], "start"))
-               start = get_timer(0);
-
-       if (!strcmp(argv[1], "get")) {
-               ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
-               printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       timer,    2,    1,     do_timer,
-       "access the system timer",
-       "start - Reset the timer reference.\n"
-       "timer get   - Print the time since 'start'."
-);
-#endif
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
deleted file mode 100644 (file)
index 1c7156f..0000000
+++ /dev/null
@@ -1,882 +0,0 @@
-/*
- * (C) Copyright 2003
- * Kyle Harris, kharris@nexus-tech.net
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <mmc.h>
-
-static int curr_device = -1;
-#ifndef CONFIG_GENERIC_MMC
-int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int dev;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[1], "init") == 0) {
-               if (argc == 2) {
-                       if (curr_device < 0)
-                               dev = 1;
-                       else
-                               dev = curr_device;
-               } else if (argc == 3) {
-                       dev = (int)simple_strtoul(argv[2], NULL, 10);
-               } else {
-                       return CMD_RET_USAGE;
-               }
-
-               if (mmc_legacy_init(dev) != 0) {
-                       puts("No MMC card found\n");
-                       return 1;
-               }
-
-               curr_device = dev;
-               printf("mmc%d is available\n", curr_device);
-       } else if (strcmp(argv[1], "device") == 0) {
-               if (argc == 2) {
-                       if (curr_device < 0) {
-                               puts("No MMC device available\n");
-                               return 1;
-                       }
-               } else if (argc == 3) {
-                       dev = (int)simple_strtoul(argv[2], NULL, 10);
-
-#ifdef CONFIG_SYS_MMC_SET_DEV
-                       if (mmc_set_dev(dev) != 0)
-                               return 1;
-#endif
-                       curr_device = dev;
-               } else {
-                       return CMD_RET_USAGE;
-               }
-
-               printf("mmc%d is current device\n", curr_device);
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       mmc, 3, 1, do_mmc,
-       "MMC sub-system",
-       "init [dev] - init MMC sub system\n"
-       "mmc device [dev] - show or set current device"
-);
-#else /* !CONFIG_GENERIC_MMC */
-
-static void print_mmcinfo(struct mmc *mmc)
-{
-       int i;
-
-       printf("Device: %s\n", mmc->cfg->name);
-       printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
-       printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
-       printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
-                       (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
-                       (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
-
-       printf("Tran Speed: %d\n", mmc->tran_speed);
-       printf("Rd Block Len: %d\n", mmc->read_bl_len);
-
-       printf("%s version %d.%d", IS_SD(mmc) ? "SD" : "MMC",
-                       EXTRACT_SDMMC_MAJOR_VERSION(mmc->version),
-                       EXTRACT_SDMMC_MINOR_VERSION(mmc->version));
-       if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0)
-               printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version));
-       printf("\n");
-
-       printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
-       puts("Capacity: ");
-       print_size(mmc->capacity, "\n");
-
-       printf("Bus Width: %d-bit%s\n", mmc->bus_width,
-                       mmc->ddr_mode ? " DDR" : "");
-
-       puts("Erase Group Size: ");
-       print_size(((u64)mmc->erase_grp_size) << 9, "\n");
-
-       if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
-               bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
-               bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
-
-               puts("HC WP Group Size: ");
-               print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
-
-               puts("User Capacity: ");
-               print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
-               if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
-                       puts(" WRREL\n");
-               else
-                       putc('\n');
-               if (usr_enh) {
-                       puts("User Enhanced Start: ");
-                       print_size(mmc->enh_user_start, "\n");
-                       puts("User Enhanced Size: ");
-                       print_size(mmc->enh_user_size, "\n");
-               }
-               puts("Boot Capacity: ");
-               print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
-               puts("RPMB Capacity: ");
-               print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
-
-               for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
-                       bool is_enh = has_enh &&
-                               (mmc->part_attr & EXT_CSD_ENH_GP(i));
-                       if (mmc->capacity_gp[i]) {
-                               printf("GP%i Capacity: ", i+1);
-                               print_size(mmc->capacity_gp[i],
-                                          is_enh ? " ENH" : "");
-                               if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
-                                       puts(" WRREL\n");
-                               else
-                                       putc('\n');
-                       }
-               }
-       }
-}
-static struct mmc *init_mmc_device(int dev, bool force_init)
-{
-       struct mmc *mmc;
-       mmc = find_mmc_device(dev);
-       if (!mmc) {
-               printf("no mmc device at slot %x\n", dev);
-               return NULL;
-       }
-       if (force_init)
-               mmc->has_init = 0;
-       if (mmc_init(mmc))
-               return NULL;
-       return mmc;
-}
-static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct mmc *mmc;
-
-       if (curr_device < 0) {
-               if (get_mmc_num() > 0)
-                       curr_device = 0;
-               else {
-                       puts("No MMC device available\n");
-                       return 1;
-               }
-       }
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       print_mmcinfo(mmc);
-       return CMD_RET_SUCCESS;
-}
-
-#ifdef CONFIG_SUPPORT_EMMC_RPMB
-static int confirm_key_prog(void)
-{
-       puts("Warning: Programming authentication key can be done only once !\n"
-            "         Use this command only if you are sure of what you are doing,\n"
-            "Really perform the key programming? <y/N> ");
-       if (confirm_yesno())
-               return 1;
-
-       puts("Authentication key programming aborted\n");
-       return 0;
-}
-static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
-                         int argc, char * const argv[])
-{
-       void *key_addr;
-       struct mmc *mmc = find_mmc_device(curr_device);
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
-       if (!confirm_key_prog())
-               return CMD_RET_FAILURE;
-       if (mmc_rpmb_set_key(mmc, key_addr)) {
-               printf("ERROR - Key already programmed ?\n");
-               return CMD_RET_FAILURE;
-       }
-       return CMD_RET_SUCCESS;
-}
-static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
-{
-       u16 blk, cnt;
-       void *addr;
-       int n;
-       void *key_addr = NULL;
-       struct mmc *mmc = find_mmc_device(curr_device);
-
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       addr = (void *)simple_strtoul(argv[1], NULL, 16);
-       blk = simple_strtoul(argv[2], NULL, 16);
-       cnt = simple_strtoul(argv[3], NULL, 16);
-
-       if (argc == 5)
-               key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
-
-       printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
-              curr_device, blk, cnt);
-       n =  mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
-
-       printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
-       if (n != cnt)
-               return CMD_RET_FAILURE;
-       return CMD_RET_SUCCESS;
-}
-static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
-                           int argc, char * const argv[])
-{
-       u16 blk, cnt;
-       void *addr;
-       int n;
-       void *key_addr;
-       struct mmc *mmc = find_mmc_device(curr_device);
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-
-       addr = (void *)simple_strtoul(argv[1], NULL, 16);
-       blk = simple_strtoul(argv[2], NULL, 16);
-       cnt = simple_strtoul(argv[3], NULL, 16);
-       key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
-
-       printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
-              curr_device, blk, cnt);
-       n =  mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
-
-       printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
-       if (n != cnt)
-               return CMD_RET_FAILURE;
-       return CMD_RET_SUCCESS;
-}
-static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
-{
-       unsigned long counter;
-       struct mmc *mmc = find_mmc_device(curr_device);
-
-       if (mmc_rpmb_get_counter(mmc, &counter))
-               return CMD_RET_FAILURE;
-       printf("RPMB Write counter= %lx\n", counter);
-       return CMD_RET_SUCCESS;
-}
-
-static cmd_tbl_t cmd_rpmb[] = {
-       U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
-       U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
-       U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
-       U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
-};
-
-static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
-                     int argc, char * const argv[])
-{
-       cmd_tbl_t *cp;
-       struct mmc *mmc;
-       char original_part;
-       int ret;
-
-       cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
-
-       /* Drop the rpmb subcommand */
-       argc--;
-       argv++;
-
-       if (cp == NULL || argc > cp->maxargs)
-               return CMD_RET_USAGE;
-       if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
-               return CMD_RET_SUCCESS;
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (!(mmc->version & MMC_VERSION_MMC)) {
-               printf("It is not a EMMC device\n");
-               return CMD_RET_FAILURE;
-       }
-       if (mmc->version < MMC_VERSION_4_41) {
-               printf("RPMB not supported before version 4.41\n");
-               return CMD_RET_FAILURE;
-       }
-       /* Switch to the RPMB partition */
-       original_part = mmc->block_dev.part_num;
-       if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0)
-               return CMD_RET_FAILURE;
-       ret = cp->cmd(cmdtp, flag, argc, argv);
-
-       /* Return to original partition */
-       if (mmc_select_hwpart(curr_device, original_part) != 0)
-               return CMD_RET_FAILURE;
-       return ret;
-}
-#endif
-
-static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
-{
-       struct mmc *mmc;
-       u32 blk, cnt, n;
-       void *addr;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       addr = (void *)simple_strtoul(argv[1], NULL, 16);
-       blk = simple_strtoul(argv[2], NULL, 16);
-       cnt = simple_strtoul(argv[3], NULL, 16);
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       printf("\nMMC read: dev # %d, block # %d, count %d ... ",
-              curr_device, blk, cnt);
-
-       n = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, addr);
-       /* flush cache after read */
-       flush_cache((ulong)addr, cnt * 512); /* FIXME */
-       printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
-
-       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
-}
-static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
-                       int argc, char * const argv[])
-{
-       struct mmc *mmc;
-       u32 blk, cnt, n;
-       void *addr;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       addr = (void *)simple_strtoul(argv[1], NULL, 16);
-       blk = simple_strtoul(argv[2], NULL, 16);
-       cnt = simple_strtoul(argv[3], NULL, 16);
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       printf("\nMMC write: dev # %d, block # %d, count %d ... ",
-              curr_device, blk, cnt);
-
-       if (mmc_getwp(mmc) == 1) {
-               printf("Error: card is write protected!\n");
-               return CMD_RET_FAILURE;
-       }
-       n = mmc->block_dev.block_write(&mmc->block_dev, blk, cnt, addr);
-       printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
-
-       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
-}
-static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
-                       int argc, char * const argv[])
-{
-       struct mmc *mmc;
-       u32 blk, cnt, n;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       blk = simple_strtoul(argv[1], NULL, 16);
-       cnt = simple_strtoul(argv[2], NULL, 16);
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
-              curr_device, blk, cnt);
-
-       if (mmc_getwp(mmc) == 1) {
-               printf("Error: card is write protected!\n");
-               return CMD_RET_FAILURE;
-       }
-       n = mmc->block_dev.block_erase(&mmc->block_dev, blk, cnt);
-       printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
-
-       return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
-}
-static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
-{
-       struct mmc *mmc;
-
-       mmc = init_mmc_device(curr_device, true);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       return CMD_RET_SUCCESS;
-}
-static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
-{
-       block_dev_desc_t *mmc_dev;
-       struct mmc *mmc;
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       mmc_dev = mmc_get_dev(curr_device);
-       if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
-               print_part(mmc_dev);
-               return CMD_RET_SUCCESS;
-       }
-
-       puts("get mmc type error!\n");
-       return CMD_RET_FAILURE;
-}
-static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
-                     int argc, char * const argv[])
-{
-       int dev, part = 0, ret;
-       struct mmc *mmc;
-
-       if (argc == 1) {
-               dev = curr_device;
-       } else if (argc == 2) {
-               dev = simple_strtoul(argv[1], NULL, 10);
-       } else if (argc == 3) {
-               dev = (int)simple_strtoul(argv[1], NULL, 10);
-               part = (int)simple_strtoul(argv[2], NULL, 10);
-               if (part > PART_ACCESS_MASK) {
-                       printf("#part_num shouldn't be larger than %d\n",
-                              PART_ACCESS_MASK);
-                       return CMD_RET_FAILURE;
-               }
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       mmc = init_mmc_device(dev, true);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       ret = mmc_select_hwpart(dev, part);
-       printf("switch to partitions #%d, %s\n",
-              part, (!ret) ? "OK" : "ERROR");
-       if (ret)
-               return 1;
-
-       curr_device = dev;
-       if (mmc->part_config == MMCPART_NOAVAILABLE)
-               printf("mmc%d is current device\n", curr_device);
-       else
-               printf("mmc%d(part %d) is current device\n",
-                      curr_device, mmc->block_dev.hwpart);
-
-       return CMD_RET_SUCCESS;
-}
-static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
-{
-       print_mmc_devices('\n');
-       return CMD_RET_SUCCESS;
-}
-
-static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
-                            int argc, char * const argv[])
-{
-       int i = 0;
-
-       memset(&pconf->user, 0, sizeof(pconf->user));
-
-       while (i < argc) {
-               if (!strcmp(argv[i], "enh")) {
-                       if (i + 2 >= argc)
-                               return -1;
-                       pconf->user.enh_start =
-                               simple_strtoul(argv[i+1], NULL, 10);
-                       pconf->user.enh_size =
-                               simple_strtoul(argv[i+2], NULL, 10);
-                       i += 3;
-               } else if (!strcmp(argv[i], "wrrel")) {
-                       if (i + 1 >= argc)
-                               return -1;
-                       pconf->user.wr_rel_change = 1;
-                       if (!strcmp(argv[i+1], "on"))
-                               pconf->user.wr_rel_set = 1;
-                       else if (!strcmp(argv[i+1], "off"))
-                               pconf->user.wr_rel_set = 0;
-                       else
-                               return -1;
-                       i += 2;
-               } else {
-                       break;
-               }
-       }
-       return i;
-}
-
-static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
-                          int argc, char * const argv[])
-{
-       int i;
-
-       memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
-
-       if (1 >= argc)
-               return -1;
-       pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
-
-       i = 1;
-       while (i < argc) {
-               if (!strcmp(argv[i], "enh")) {
-                       pconf->gp_part[pidx].enhanced = 1;
-                       i += 1;
-               } else if (!strcmp(argv[i], "wrrel")) {
-                       if (i + 1 >= argc)
-                               return -1;
-                       pconf->gp_part[pidx].wr_rel_change = 1;
-                       if (!strcmp(argv[i+1], "on"))
-                               pconf->gp_part[pidx].wr_rel_set = 1;
-                       else if (!strcmp(argv[i+1], "off"))
-                               pconf->gp_part[pidx].wr_rel_set = 0;
-                       else
-                               return -1;
-                       i += 2;
-               } else {
-                       break;
-               }
-       }
-       return i;
-}
-
-static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
-{
-       struct mmc *mmc;
-       struct mmc_hwpart_conf pconf = { };
-       enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
-       int i, r, pidx;
-
-       mmc = init_mmc_device(curr_device, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (argc < 1)
-               return CMD_RET_USAGE;
-       i = 1;
-       while (i < argc) {
-               if (!strcmp(argv[i], "user")) {
-                       i++;
-                       r = parse_hwpart_user(&pconf, argc-i, &argv[i]);
-                       if (r < 0)
-                               return CMD_RET_USAGE;
-                       i += r;
-               } else if (!strncmp(argv[i], "gp", 2) &&
-                          strlen(argv[i]) == 3 &&
-                          argv[i][2] >= '1' && argv[i][2] <= '4') {
-                       pidx = argv[i][2] - '1';
-                       i++;
-                       r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
-                       if (r < 0)
-                               return CMD_RET_USAGE;
-                       i += r;
-               } else if (!strcmp(argv[i], "check")) {
-                       mode = MMC_HWPART_CONF_CHECK;
-                       i++;
-               } else if (!strcmp(argv[i], "set")) {
-                       mode = MMC_HWPART_CONF_SET;
-                       i++;
-               } else if (!strcmp(argv[i], "complete")) {
-                       mode = MMC_HWPART_CONF_COMPLETE;
-                       i++;
-               } else {
-                       return CMD_RET_USAGE;
-               }
-       }
-
-       puts("Partition configuration:\n");
-       if (pconf.user.enh_size) {
-               puts("\tUser Enhanced Start: ");
-               print_size(((u64)pconf.user.enh_start) << 9, "\n");
-               puts("\tUser Enhanced Size: ");
-               print_size(((u64)pconf.user.enh_size) << 9, "\n");
-       } else {
-               puts("\tNo enhanced user data area\n");
-       }
-       if (pconf.user.wr_rel_change)
-               printf("\tUser partition write reliability: %s\n",
-                      pconf.user.wr_rel_set ? "on" : "off");
-       for (pidx = 0; pidx < 4; pidx++) {
-               if (pconf.gp_part[pidx].size) {
-                       printf("\tGP%i Capacity: ", pidx+1);
-                       print_size(((u64)pconf.gp_part[pidx].size) << 9,
-                                  pconf.gp_part[pidx].enhanced ?
-                                  " ENH\n" : "\n");
-               } else {
-                       printf("\tNo GP%i partition\n", pidx+1);
-               }
-               if (pconf.gp_part[pidx].wr_rel_change)
-                       printf("\tGP%i write reliability: %s\n", pidx+1,
-                              pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
-       }
-
-       if (!mmc_hwpart_config(mmc, &pconf, mode)) {
-               if (mode == MMC_HWPART_CONF_COMPLETE)
-                       puts("Partitioning successful, "
-                            "power-cycle to make effective\n");
-               return CMD_RET_SUCCESS;
-       } else {
-               puts("Failed!\n");
-               return CMD_RET_FAILURE;
-       }
-}
-
-#ifdef CONFIG_SUPPORT_EMMC_BOOT
-static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
-                         int argc, char * const argv[])
-{
-       int dev;
-       struct mmc *mmc;
-       u8 width, reset, mode;
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-       dev = simple_strtoul(argv[1], NULL, 10);
-       width = simple_strtoul(argv[2], NULL, 10);
-       reset = simple_strtoul(argv[3], NULL, 10);
-       mode = simple_strtoul(argv[4], NULL, 10);
-
-       mmc = init_mmc_device(dev, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (IS_SD(mmc)) {
-               puts("BOOT_BUS_WIDTH only exists on eMMC\n");
-               return CMD_RET_FAILURE;
-       }
-
-       /* acknowledge to be sent during boot operation */
-       return mmc_set_boot_bus_width(mmc, width, reset, mode);
-}
-static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
-{
-       int dev;
-       struct mmc *mmc;
-       u32 bootsize, rpmbsize;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-       dev = simple_strtoul(argv[1], NULL, 10);
-       bootsize = simple_strtoul(argv[2], NULL, 10);
-       rpmbsize = simple_strtoul(argv[3], NULL, 10);
-
-       mmc = init_mmc_device(dev, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (IS_SD(mmc)) {
-               printf("It is not a EMMC device\n");
-               return CMD_RET_FAILURE;
-       }
-
-       if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
-               printf("EMMC boot partition Size change Failed.\n");
-               return CMD_RET_FAILURE;
-       }
-
-       printf("EMMC boot partition Size %d MB\n", bootsize);
-       printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
-       return CMD_RET_SUCCESS;
-}
-static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
-{
-       int dev;
-       struct mmc *mmc;
-       u8 ack, part_num, access;
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-
-       dev = simple_strtoul(argv[1], NULL, 10);
-       ack = simple_strtoul(argv[2], NULL, 10);
-       part_num = simple_strtoul(argv[3], NULL, 10);
-       access = simple_strtoul(argv[4], NULL, 10);
-
-       mmc = init_mmc_device(dev, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (IS_SD(mmc)) {
-               puts("PARTITION_CONFIG only exists on eMMC\n");
-               return CMD_RET_FAILURE;
-       }
-
-       /* acknowledge to be sent during boot operation */
-       return mmc_set_part_conf(mmc, ack, part_num, access);
-}
-static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
-{
-       int dev;
-       struct mmc *mmc;
-       u8 enable;
-
-       /*
-        * Set the RST_n_ENABLE bit of RST_n_FUNCTION
-        * The only valid values are 0x0, 0x1 and 0x2 and writing
-        * a value of 0x1 or 0x2 sets the value permanently.
-        */
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       dev = simple_strtoul(argv[1], NULL, 10);
-       enable = simple_strtoul(argv[2], NULL, 10);
-
-       if (enable > 2) {
-               puts("Invalid RST_n_ENABLE value\n");
-               return CMD_RET_USAGE;
-       }
-
-       mmc = init_mmc_device(dev, false);
-       if (!mmc)
-               return CMD_RET_FAILURE;
-
-       if (IS_SD(mmc)) {
-               puts("RST_n_FUNCTION only exists on eMMC\n");
-               return CMD_RET_FAILURE;
-       }
-
-       return mmc_set_rst_n_function(mmc, enable);
-}
-#endif
-static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
-{
-       struct mmc *mmc;
-       u32 val;
-       int ret;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-       val = simple_strtoul(argv[2], NULL, 16);
-
-       mmc = find_mmc_device(curr_device);
-       if (!mmc) {
-               printf("no mmc device at slot %x\n", curr_device);
-               return CMD_RET_FAILURE;
-       }
-       ret = mmc_set_dsr(mmc, val);
-       printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
-       if (!ret) {
-               mmc->has_init = 0;
-               if (mmc_init(mmc))
-                       return CMD_RET_FAILURE;
-               else
-                       return CMD_RET_SUCCESS;
-       }
-       return ret;
-}
-
-static cmd_tbl_t cmd_mmc[] = {
-       U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
-       U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
-       U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
-       U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
-       U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
-       U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
-       U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
-       U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
-       U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
-#ifdef CONFIG_SUPPORT_EMMC_BOOT
-       U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
-       U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
-       U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
-       U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
-#endif
-#ifdef CONFIG_SUPPORT_EMMC_RPMB
-       U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
-};
-
-static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *cp;
-
-       cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
-
-       /* Drop the mmc command */
-       argc--;
-       argv++;
-
-       if (cp == NULL || argc > cp->maxargs)
-               return CMD_RET_USAGE;
-       if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
-               return CMD_RET_SUCCESS;
-
-       if (curr_device < 0) {
-               if (get_mmc_num() > 0) {
-                       curr_device = 0;
-               } else {
-                       puts("No MMC device available\n");
-                       return CMD_RET_FAILURE;
-               }
-       }
-       return cp->cmd(cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(
-       mmc, 29, 1, do_mmcops,
-       "MMC sub system",
-       "info - display info of the current MMC device\n"
-       "mmc read addr blk# cnt\n"
-       "mmc write addr blk# cnt\n"
-       "mmc erase blk# cnt\n"
-       "mmc rescan\n"
-       "mmc part - lists available partition on current mmc device\n"
-       "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
-       "mmc list - lists available devices\n"
-       "mmc hwpartition [args...] - does hardware partitioning\n"
-       "  arguments (sizes in 512-byte blocks):\n"
-       "    [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
-       "    [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
-       "    [check|set|complete] - mode, complete set partitioning completed\n"
-       "  WARNING: Partitioning is a write-once setting once it is set to complete.\n"
-       "  Power cycling is required to initialize partitions after set to complete.\n"
-#ifdef CONFIG_SUPPORT_EMMC_BOOT
-       "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
-       " - Set the BOOT_BUS_WIDTH field of the specified device\n"
-       "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
-       " - Change sizes of boot and RPMB partitions of specified device\n"
-       "mmc partconf dev boot_ack boot_partition partition_access\n"
-       " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
-       "mmc rst-function dev value\n"
-       " - Change the RST_n_FUNCTION field of the specified device\n"
-       "   WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
-#endif
-#ifdef CONFIG_SUPPORT_EMMC_RPMB
-       "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
-       "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
-       "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
-       "mmc rpmb counter - read the value of the write counter\n"
-#endif
-       "mmc setdsr <value> - set DSR register value\n"
-       );
-
-/* Old command kept for compatibility. Same as 'mmc info' */
-U_BOOT_CMD(
-       mmcinfo, 1, 0, do_mmcinfo,
-       "display MMC info",
-       "- display info of the current MMC device"
-);
-
-#endif /* !CONFIG_GENERIC_MMC */
diff --git a/common/cmd_mmc_spi.c b/common/cmd_mmc_spi.c
deleted file mode 100644 (file)
index a2138b8..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Command for mmc_spi setup.
- *
- * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
- * Licensed under the GPL-2 or later.
- */
-
-#include <common.h>
-#include <mmc.h>
-#include <spi.h>
-
-#ifndef CONFIG_MMC_SPI_BUS
-# define CONFIG_MMC_SPI_BUS 0
-#endif
-#ifndef CONFIG_MMC_SPI_CS
-# define CONFIG_MMC_SPI_CS 1
-#endif
-/* in SPI mode, MMC speed limit is 20MHz, while SD speed limit is 25MHz */
-#ifndef CONFIG_MMC_SPI_SPEED
-# define CONFIG_MMC_SPI_SPEED 25000000
-#endif
-/* MMC and SD specs only seem to care that sampling is on the
- * rising edge ... meaning SPI modes 0 or 3.  So either SPI mode
- * should be legit.  We'll use mode 0 since the steady state is 0,
- * which is appropriate for hotplugging, unless the platform data
- * specify mode 3 (if hardware is not compatible to mode 0).
- */
-#ifndef CONFIG_MMC_SPI_MODE
-# define CONFIG_MMC_SPI_MODE SPI_MODE_0
-#endif
-
-static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint bus = CONFIG_MMC_SPI_BUS;
-       uint cs = CONFIG_MMC_SPI_CS;
-       uint speed = CONFIG_MMC_SPI_SPEED;
-       uint mode = CONFIG_MMC_SPI_MODE;
-       char *endp;
-       struct mmc *mmc;
-
-       if (argc < 2)
-               goto usage;
-
-       cs = simple_strtoul(argv[1], &endp, 0);
-       if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
-               goto usage;
-       if (*endp == ':') {
-               if (endp[1] == 0)
-                       goto usage;
-               bus = cs;
-               cs = simple_strtoul(endp + 1, &endp, 0);
-               if (*endp != 0)
-                       goto usage;
-       }
-       if (argc >= 3) {
-               speed = simple_strtoul(argv[2], &endp, 0);
-               if (*argv[2] == 0 || *endp != 0)
-                       goto usage;
-       }
-       if (argc >= 4) {
-               mode = simple_strtoul(argv[3], &endp, 16);
-               if (*argv[3] == 0 || *endp != 0)
-                       goto usage;
-       }
-       if (!spi_cs_is_valid(bus, cs)) {
-               printf("Invalid SPI bus %u cs %u\n", bus, cs);
-               return 1;
-       }
-
-       mmc = mmc_spi_init(bus, cs, speed, mode);
-       if (!mmc) {
-               printf("Failed to create MMC Device\n");
-               return 1;
-       }
-       printf("%s: %d at %u:%u hz %u mode %u\n", mmc->cfg->name, mmc->block_dev.dev,
-              bus, cs, speed, mode);
-       mmc_init(mmc);
-       return 0;
-
-usage:
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       mmc_spi,        4,      0,      do_mmc_spi,
-       "mmc_spi setup",
-       "[bus:]cs [hz] [mode]   - setup mmc_spi device"
-);
diff --git a/common/cmd_mp.c b/common/cmd_mp.c
deleted file mode 100644 (file)
index a80c642..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2008-2009 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int cpu_status_all(void)
-{
-       unsigned long cpuid;
-
-       for (cpuid = 0; ; cpuid++) {
-               if (!is_core_valid(cpuid)) {
-                       if (cpuid == 0) {
-                               printf("Core num: %lu is not valid\n", cpuid);
-                               return 1;
-                       }
-                       break;
-               }
-               cpu_status(cpuid);
-       }
-
-       return 0;
-}
-
-static int
-cpu_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long cpuid;
-
-       if (argc == 2 && strncmp(argv[1], "status", 6) == 0)
-                 return cpu_status_all();
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       cpuid = simple_strtoul(argv[1], NULL, 10);
-       if (!is_core_valid(cpuid)) {
-               printf ("Core num: %lu is not valid\n", cpuid);
-               return 1;
-       }
-
-
-       if (argc == 3) {
-               if (strncmp(argv[2], "reset", 5) == 0)
-                       cpu_reset(cpuid);
-               else if (strncmp(argv[2], "status", 6) == 0)
-                       cpu_status(cpuid);
-               else if (strncmp(argv[2], "disable", 7) == 0)
-                       return cpu_disable(cpuid);
-               else
-                       return CMD_RET_USAGE;
-
-               return 0;
-       }
-
-       /* 4 or greater, make sure its release */
-       if (strncmp(argv[2], "release", 7) != 0)
-               return CMD_RET_USAGE;
-
-       if (cpu_release(cpuid, argc - 3, argv + 3))
-               return CMD_RET_USAGE;
-
-       return 0;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char cpu_help_text[] =
-           "<num> reset                 - Reset cpu <num>\n"
-       "cpu status                      - Status of all cpus\n"
-       "cpu <num> status                - Status of cpu <num>\n"
-       "cpu <num> disable               - Disable cpu <num>\n"
-       "cpu <num> release <addr> [args] - Release cpu <num> at <addr> with [args]"
-#ifdef CONFIG_PPC
-       "\n"
-       "                         [args] : <pir> <r3> <r6>\n" \
-       "                                   pir - processor id (if writeable)\n" \
-       "                                    r3 - value for gpr 3\n" \
-       "                                    r6 - value for gpr 6\n" \
-       "\n" \
-       "     Use '-' for any arg if you want the default value.\n" \
-       "     Default for r3 is <num> and r6 is 0\n" \
-       "\n" \
-       "     When cpu <num> is released r4 and r5 = 0.\n" \
-       "     r7 will contain the size of the initial mapped area"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       cpu, CONFIG_SYS_MAXARGS, 1, cpu_cmd,
-       "Multiprocessor CPU boot manipulation and release", cpu_help_text
-);
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
deleted file mode 100644 (file)
index dab1958..0000000
+++ /dev/null
@@ -1,2106 +0,0 @@
-/*
- * (C) Copyright 2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * (C) Copyright 2002
- * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
- *
- * (C) Copyright 2003
- * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
- *
- * (C) Copyright 2005
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- *   Added support for reading flash partition table from environment.
- *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
- *   kernel tree.
- *
- * (C) Copyright 2008
- * Harald Welte, OpenMoko, Inc., Harald Welte <laforge@openmoko.org>
- *
- *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
- *   Copyright 2002 SYSGO Real-Time Solutions GmbH
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Three environment variables are used by the parsing routines:
- *
- * 'partition' - keeps current partition identifier
- *
- * partition  := <part-id>
- * <part-id>  := <dev-id>,part_num
- *
- *
- * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
- *
- * mtdids=<idmap>[,<idmap>,...]
- *
- * <idmap>    := <dev-id>=<mtd-id>
- * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
- * <dev-num>  := mtd device number, 0...
- * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
- *
- *
- * 'mtdparts' - partition list
- *
- * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
- *
- * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
- * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
- * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
- * <size>     := standard linux memsize OR '-' to denote all remaining space
- * <offset>   := partition start offset within the device
- * <name>     := '(' NAME ')'
- * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
- *
- * Notes:
- * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
- * - if the above variables are not set defaults for a given target are used
- *
- * Examples:
- *
- * 1 NOR Flash, with 1 single writable partition:
- * mtdids=nor0=edb7312-nor
- * mtdparts=mtdparts=edb7312-nor:-
- *
- * 1 NOR Flash with 2 partitions, 1 NAND with one
- * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
- * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
- *
- */
-
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <jffs2/load_kernel.h>
-#include <linux/list.h>
-#include <linux/ctype.h>
-#include <linux/err.h>
-#include <linux/mtd/mtd.h>
-
-#if defined(CONFIG_CMD_NAND)
-#include <linux/mtd/nand.h>
-#include <nand.h>
-#endif
-
-#if defined(CONFIG_CMD_ONENAND)
-#include <linux/mtd/onenand.h>
-#include <onenand_uboot.h>
-#endif
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/* special size referring to all the remaining space in a partition */
-#define SIZE_REMAINING         (~0llu)
-
-/* special offset value, it is used when not provided by user
- *
- * this value is used temporarily during parsing, later such offests
- * are recalculated */
-#define OFFSET_NOT_SPECIFIED   (~0llu)
-
-/* minimum partition size */
-#define MIN_PART_SIZE          4096
-
-/* this flag needs to be set in part_info struct mask_flags
- * field for read-only partitions */
-#define MTD_WRITEABLE_CMD              1
-
-/* default values for mtdids and mtdparts variables */
-#if defined(MTDIDS_DEFAULT)
-static const char *const mtdids_default = MTDIDS_DEFAULT;
-#else
-static const char *const mtdids_default = NULL;
-#endif
-
-#if defined(MTDPARTS_DEFAULT)
-static const char *const mtdparts_default = MTDPARTS_DEFAULT;
-#else
-static const char *const mtdparts_default = NULL;
-#endif
-
-/* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
-#define MTDIDS_MAXLEN          128
-#define MTDPARTS_MAXLEN                512
-#define PARTITION_MAXLEN       16
-static char last_ids[MTDIDS_MAXLEN];
-static char last_parts[MTDPARTS_MAXLEN];
-static char last_partition[PARTITION_MAXLEN];
-
-/* low level jffs2 cache cleaning routine */
-extern void jffs2_free_cache(struct part_info *part);
-
-/* mtdids mapping list, filled by parse_ids() */
-static struct list_head mtdids;
-
-/* device/partition list, parse_cmdline() parses into here */
-static struct list_head devices;
-
-/* current active device and partition number */
-struct mtd_device *current_mtd_dev = NULL;
-u8 current_mtd_partnum = 0;
-
-static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
-
-/* command line only routines */
-static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
-static int device_del(struct mtd_device *dev);
-
-/**
- * Parses a string into a number.  The number stored at ptr is
- * potentially suffixed with K (for kilobytes, or 1024 bytes),
- * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
- * 1073741824).  If the number is suffixed with K, M, or G, then
- * the return value is the number multiplied by one kilobyte, one
- * megabyte, or one gigabyte, respectively.
- *
- * @param ptr where parse begins
- * @param retptr output pointer to next char after parse completes (output)
- * @return resulting unsigned int
- */
-static u64 memsize_parse (const char *const ptr, const char **retptr)
-{
-       u64 ret = simple_strtoull(ptr, (char **)retptr, 0);
-
-       switch (**retptr) {
-               case 'G':
-               case 'g':
-                       ret <<= 10;
-               case 'M':
-               case 'm':
-                       ret <<= 10;
-               case 'K':
-               case 'k':
-                       ret <<= 10;
-                       (*retptr)++;
-               default:
-                       break;
-       }
-
-       return ret;
-}
-
-/**
- * Format string describing supplied size. This routine does the opposite job
- * to memsize_parse(). Size in bytes is converted to string and if possible
- * shortened by using k (kilobytes), m (megabytes) or g (gigabytes) suffix.
- *
- * Note, that this routine does not check for buffer overflow, it's the caller
- * who must assure enough space.
- *
- * @param buf output buffer
- * @param size size to be converted to string
- */
-static void memsize_format(char *buf, u64 size)
-{
-#define SIZE_GB ((u32)1024*1024*1024)
-#define SIZE_MB ((u32)1024*1024)
-#define SIZE_KB ((u32)1024)
-
-       if ((size % SIZE_GB) == 0)
-               sprintf(buf, "%llug", size/SIZE_GB);
-       else if ((size % SIZE_MB) == 0)
-               sprintf(buf, "%llum", size/SIZE_MB);
-       else if (size % SIZE_KB == 0)
-               sprintf(buf, "%lluk", size/SIZE_KB);
-       else
-               sprintf(buf, "%llu", size);
-}
-
-/**
- * This routine does global indexing of all partitions. Resulting index for
- * current partition is saved in 'mtddevnum'. Current partition name in
- * 'mtddevname'.
- */
-static void index_partitions(void)
-{
-       u16 mtddevnum;
-       struct part_info *part;
-       struct list_head *dentry;
-       struct mtd_device *dev;
-
-       debug("--- index partitions ---\n");
-
-       if (current_mtd_dev) {
-               mtddevnum = 0;
-               list_for_each(dentry, &devices) {
-                       dev = list_entry(dentry, struct mtd_device, link);
-                       if (dev == current_mtd_dev) {
-                               mtddevnum += current_mtd_partnum;
-                               setenv_ulong("mtddevnum", mtddevnum);
-                               break;
-                       }
-                       mtddevnum += dev->num_parts;
-               }
-
-               part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
-               setenv("mtddevname", part->name);
-
-               debug("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
-       } else {
-               setenv("mtddevnum", NULL);
-               setenv("mtddevname", NULL);
-
-               debug("=> mtddevnum NULL\n=> mtddevname NULL\n");
-       }
-}
-
-/**
- * Save current device and partition in environment variable 'partition'.
- */
-static void current_save(void)
-{
-       char buf[16];
-
-       debug("--- current_save ---\n");
-
-       if (current_mtd_dev) {
-               sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type),
-                                       current_mtd_dev->id->num, current_mtd_partnum);
-
-               setenv("partition", buf);
-               strncpy(last_partition, buf, 16);
-
-               debug("=> partition %s\n", buf);
-       } else {
-               setenv("partition", NULL);
-               last_partition[0] = '\0';
-
-               debug("=> partition NULL\n");
-       }
-       index_partitions();
-}
-
-
-/**
- * Produce a mtd_info given a type and num.
- *
- * @param type mtd type
- * @param num mtd number
- * @param mtd a pointer to an mtd_info instance (output)
- * @return 0 if device is valid, 1 otherwise
- */
-static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
-{
-       char mtd_dev[16];
-
-       sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
-       *mtd = get_mtd_device_nm(mtd_dev);
-       if (IS_ERR(*mtd)) {
-               printf("Device %s not found!\n", mtd_dev);
-               return 1;
-       }
-       put_mtd_device(*mtd);
-
-       return 0;
-}
-
-/**
- * Performs sanity check for supplied flash partition.
- * Table of existing MTD flash devices is searched and partition device
- * is located. Alignment with the granularity of nand erasesize is verified.
- *
- * @param id of the parent device
- * @param part partition to validate
- * @return 0 if partition is valid, 1 otherwise
- */
-static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
-{
-       struct mtd_info *mtd = NULL;
-       int i, j;
-       ulong start;
-       u64 offset, size;
-
-       if (get_mtd_info(id->type, id->num, &mtd))
-               return 1;
-
-       part->sector_size = mtd->erasesize;
-
-       if (!mtd->numeraseregions) {
-               /*
-                * Only one eraseregion (NAND, OneNAND or uniform NOR),
-                * checking for alignment is easy here
-                */
-               offset = part->offset;
-               if (do_div(offset, mtd->erasesize)) {
-                       printf("%s%d: partition (%s) start offset"
-                              "alignment incorrect\n",
-                              MTD_DEV_TYPE(id->type), id->num, part->name);
-                       return 1;
-               }
-
-               size = part->size;
-               if (do_div(size, mtd->erasesize)) {
-                       printf("%s%d: partition (%s) size alignment incorrect\n",
-                              MTD_DEV_TYPE(id->type), id->num, part->name);
-                       return 1;
-               }
-       } else {
-               /*
-                * Multiple eraseregions (non-uniform NOR),
-                * checking for alignment is more complex here
-                */
-
-               /* Check start alignment */
-               for (i = 0; i < mtd->numeraseregions; i++) {
-                       start = mtd->eraseregions[i].offset;
-                       for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
-                               if (part->offset == start)
-                                       goto start_ok;
-                               start += mtd->eraseregions[i].erasesize;
-                       }
-               }
-
-               printf("%s%d: partition (%s) start offset alignment incorrect\n",
-                      MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
-
-       start_ok:
-
-               /* Check end/size alignment */
-               for (i = 0; i < mtd->numeraseregions; i++) {
-                       start = mtd->eraseregions[i].offset;
-                       for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
-                               if ((part->offset + part->size) == start)
-                                       goto end_ok;
-                               start += mtd->eraseregions[i].erasesize;
-                       }
-               }
-               /* Check last sector alignment */
-               if ((part->offset + part->size) == start)
-                       goto end_ok;
-
-               printf("%s%d: partition (%s) size alignment incorrect\n",
-                      MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
-
-       end_ok:
-               return 0;
-       }
-
-       return 0;
-}
-
-
-/**
- * Performs sanity check for supplied partition. Offset and size are
- * verified to be within valid range. Partition type is checked and
- * part_validate_eraseblock() is called with the argument of part.
- *
- * @param id of the parent device
- * @param part partition to validate
- * @return 0 if partition is valid, 1 otherwise
- */
-static int part_validate(struct mtdids *id, struct part_info *part)
-{
-       if (part->size == SIZE_REMAINING)
-               part->size = id->size - part->offset;
-
-       if (part->offset > id->size) {
-               printf("%s: offset %08llx beyond flash size %08llx\n",
-                               id->mtd_id, part->offset, id->size);
-               return 1;
-       }
-
-       if ((part->offset + part->size) <= part->offset) {
-               printf("%s%d: partition (%s) size too big\n",
-                               MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
-       }
-
-       if (part->offset + part->size > id->size) {
-               printf("%s: partitioning exceeds flash size\n", id->mtd_id);
-               return 1;
-       }
-
-       /*
-        * Now we need to check if the partition starts and ends on
-        * sector (eraseblock) regions
-        */
-       return part_validate_eraseblock(id, part);
-}
-
-/**
- * Delete selected partition from the partition list of the specified device.
- *
- * @param dev device to delete partition from
- * @param part partition to delete
- * @return 0 on success, 1 otherwise
- */
-static int part_del(struct mtd_device *dev, struct part_info *part)
-{
-       u8 current_save_needed = 0;
-
-       /* if there is only one partition, remove whole device */
-       if (dev->num_parts == 1)
-               return device_del(dev);
-
-       /* otherwise just delete this partition */
-
-       if (dev == current_mtd_dev) {
-               /* we are modyfing partitions for the current device,
-                * update current */
-               struct part_info *curr_pi;
-               curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
-
-               if (curr_pi) {
-                       if (curr_pi == part) {
-                               printf("current partition deleted, resetting current to 0\n");
-                               current_mtd_partnum = 0;
-                       } else if (part->offset <= curr_pi->offset) {
-                               current_mtd_partnum--;
-                       }
-                       current_save_needed = 1;
-               }
-       }
-
-       list_del(&part->link);
-       free(part);
-       dev->num_parts--;
-
-       if (current_save_needed > 0)
-               current_save();
-       else
-               index_partitions();
-
-       return 0;
-}
-
-/**
- * Delete all partitions from parts head list, free memory.
- *
- * @param head list of partitions to delete
- */
-static void part_delall(struct list_head *head)
-{
-       struct list_head *entry, *n;
-       struct part_info *part_tmp;
-
-       /* clean tmp_list and free allocated memory */
-       list_for_each_safe(entry, n, head) {
-               part_tmp = list_entry(entry, struct part_info, link);
-
-               list_del(entry);
-               free(part_tmp);
-       }
-}
-
-/**
- * Add new partition to the supplied partition list. Make sure partitions are
- * sorted by offset in ascending order.
- *
- * @param head list this partition is to be added to
- * @param new partition to be added
- */
-static int part_sort_add(struct mtd_device *dev, struct part_info *part)
-{
-       struct list_head *entry;
-       struct part_info *new_pi, *curr_pi;
-
-       /* link partition to parrent dev */
-       part->dev = dev;
-
-       if (list_empty(&dev->parts)) {
-               debug("part_sort_add: list empty\n");
-               list_add(&part->link, &dev->parts);
-               dev->num_parts++;
-               index_partitions();
-               return 0;
-       }
-
-       new_pi = list_entry(&part->link, struct part_info, link);
-
-       /* get current partition info if we are updating current device */
-       curr_pi = NULL;
-       if (dev == current_mtd_dev)
-               curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
-
-       list_for_each(entry, &dev->parts) {
-               struct part_info *pi;
-
-               pi = list_entry(entry, struct part_info, link);
-
-               /* be compliant with kernel cmdline, allow only one partition at offset zero */
-               if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
-                       printf("cannot add second partition at offset 0\n");
-                       return 1;
-               }
-
-               if (new_pi->offset <= pi->offset) {
-                       list_add_tail(&part->link, entry);
-                       dev->num_parts++;
-
-                       if (curr_pi && (pi->offset <= curr_pi->offset)) {
-                               /* we are modyfing partitions for the current
-                                * device, update current */
-                               current_mtd_partnum++;
-                               current_save();
-                       } else {
-                               index_partitions();
-                       }
-                       return 0;
-               }
-       }
-
-       list_add_tail(&part->link, &dev->parts);
-       dev->num_parts++;
-       index_partitions();
-       return 0;
-}
-
-/**
- * Add provided partition to the partition list of a given device.
- *
- * @param dev device to which partition is added
- * @param part partition to be added
- * @return 0 on success, 1 otherwise
- */
-static int part_add(struct mtd_device *dev, struct part_info *part)
-{
-       /* verify alignment and size */
-       if (part_validate(dev->id, part) != 0)
-               return 1;
-
-       /* partition is ok, add it to the list */
-       if (part_sort_add(dev, part) != 0)
-               return 1;
-
-       return 0;
-}
-
-/**
- * Parse one partition definition, allocate memory and return pointer to this
- * location in retpart.
- *
- * @param partdef pointer to the partition definition string i.e. <part-def>
- * @param ret output pointer to next char after parse completes (output)
- * @param retpart pointer to the allocated partition (output)
- * @return 0 on success, 1 otherwise
- */
-static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
-{
-       struct part_info *part;
-       u64 size;
-       u64 offset;
-       const char *name;
-       int name_len;
-       unsigned int mask_flags;
-       const char *p;
-
-       p = partdef;
-       *retpart = NULL;
-       *ret = NULL;
-
-       /* fetch the partition size */
-       if (*p == '-') {
-               /* assign all remaining space to this partition */
-               debug("'-': remaining size assigned\n");
-               size = SIZE_REMAINING;
-               p++;
-       } else {
-               size = memsize_parse(p, &p);
-               if (size < MIN_PART_SIZE) {
-                       printf("partition size too small (%llx)\n", size);
-                       return 1;
-               }
-       }
-
-       /* check for offset */
-       offset = OFFSET_NOT_SPECIFIED;
-       if (*p == '@') {
-               p++;
-               offset = memsize_parse(p, &p);
-       }
-
-       /* now look for the name */
-       if (*p == '(') {
-               name = ++p;
-               if ((p = strchr(name, ')')) == NULL) {
-                       printf("no closing ) found in partition name\n");
-                       return 1;
-               }
-               name_len = p - name + 1;
-               if ((name_len - 1) == 0) {
-                       printf("empty partition name\n");
-                       return 1;
-               }
-               p++;
-       } else {
-               /* 0x00000000@0x00000000 */
-               name_len = 22;
-               name = NULL;
-       }
-
-       /* test for options */
-       mask_flags = 0;
-       if (strncmp(p, "ro", 2) == 0) {
-               mask_flags |= MTD_WRITEABLE_CMD;
-               p += 2;
-       }
-
-       /* check for next partition definition */
-       if (*p == ',') {
-               if (size == SIZE_REMAINING) {
-                       *ret = NULL;
-                       printf("no partitions allowed after a fill-up partition\n");
-                       return 1;
-               }
-               *ret = ++p;
-       } else if ((*p == ';') || (*p == '\0')) {
-               *ret = p;
-       } else {
-               printf("unexpected character '%c' at the end of partition\n", *p);
-               *ret = NULL;
-               return 1;
-       }
-
-       /*  allocate memory */
-       part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
-       if (!part) {
-               printf("out of memory\n");
-               return 1;
-       }
-       memset(part, 0, sizeof(struct part_info) + name_len);
-       part->size = size;
-       part->offset = offset;
-       part->mask_flags = mask_flags;
-       part->name = (char *)(part + 1);
-
-       if (name) {
-               /* copy user provided name */
-               strncpy(part->name, name, name_len - 1);
-               part->auto_name = 0;
-       } else {
-               /* auto generated name in form of size@offset */
-               sprintf(part->name, "0x%08llx@0x%08llx", size, offset);
-               part->auto_name = 1;
-       }
-
-       part->name[name_len - 1] = '\0';
-       INIT_LIST_HEAD(&part->link);
-
-       debug("+ partition: name %-22s size 0x%08llx offset 0x%08llx mask flags %d\n",
-                       part->name, part->size,
-                       part->offset, part->mask_flags);
-
-       *retpart = part;
-       return 0;
-}
-
-/**
- * Check device number to be within valid range for given device type.
- *
- * @param type mtd type
- * @param num mtd number
- * @param size a pointer to the size of the mtd device (output)
- * @return 0 if device is valid, 1 otherwise
- */
-static int mtd_device_validate(u8 type, u8 num, u64 *size)
-{
-       struct mtd_info *mtd = NULL;
-
-       if (get_mtd_info(type, num, &mtd))
-               return 1;
-
-       *size = mtd->size;
-
-       return 0;
-}
-
-/**
- * Delete all mtd devices from a supplied devices list, free memory allocated for
- * each device and delete all device partitions.
- *
- * @return 0 on success, 1 otherwise
- */
-static int device_delall(struct list_head *head)
-{
-       struct list_head *entry, *n;
-       struct mtd_device *dev_tmp;
-
-       /* clean devices list */
-       list_for_each_safe(entry, n, head) {
-               dev_tmp = list_entry(entry, struct mtd_device, link);
-               list_del(entry);
-               part_delall(&dev_tmp->parts);
-               free(dev_tmp);
-       }
-       INIT_LIST_HEAD(&devices);
-
-       return 0;
-}
-
-/**
- * If provided device exists it's partitions are deleted, device is removed
- * from device list and device memory is freed.
- *
- * @param dev device to be deleted
- * @return 0 on success, 1 otherwise
- */
-static int device_del(struct mtd_device *dev)
-{
-       part_delall(&dev->parts);
-       list_del(&dev->link);
-       free(dev);
-
-       if (dev == current_mtd_dev) {
-               /* we just deleted current device */
-               if (list_empty(&devices)) {
-                       current_mtd_dev = NULL;
-               } else {
-                       /* reset first partition from first dev from the
-                        * devices list as current */
-                       current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
-                       current_mtd_partnum = 0;
-               }
-               current_save();
-               return 0;
-       }
-
-       index_partitions();
-       return 0;
-}
-
-/**
- * Search global device list and return pointer to the device of type and num
- * specified.
- *
- * @param type device type
- * @param num device number
- * @return NULL if requested device does not exist
- */
-struct mtd_device *device_find(u8 type, u8 num)
-{
-       struct list_head *entry;
-       struct mtd_device *dev_tmp;
-
-       list_for_each(entry, &devices) {
-               dev_tmp = list_entry(entry, struct mtd_device, link);
-
-               if ((dev_tmp->id->type == type) && (dev_tmp->id->num == num))
-                       return dev_tmp;
-       }
-
-       return NULL;
-}
-
-/**
- * Add specified device to the global device list.
- *
- * @param dev device to be added
- */
-static void device_add(struct mtd_device *dev)
-{
-       u8 current_save_needed = 0;
-
-       if (list_empty(&devices)) {
-               current_mtd_dev = dev;
-               current_mtd_partnum = 0;
-               current_save_needed = 1;
-       }
-
-       list_add_tail(&dev->link, &devices);
-
-       if (current_save_needed > 0)
-               current_save();
-       else
-               index_partitions();
-}
-
-/**
- * Parse device type, name and mtd-id. If syntax is ok allocate memory and
- * return pointer to the device structure.
- *
- * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
- * @param ret output pointer to next char after parse completes (output)
- * @param retdev pointer to the allocated device (output)
- * @return 0 on success, 1 otherwise
- */
-static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
-{
-       struct mtd_device *dev;
-       struct part_info *part;
-       struct mtdids *id;
-       const char *mtd_id;
-       unsigned int mtd_id_len;
-       const char *p;
-       const char *pend;
-       LIST_HEAD(tmp_list);
-       struct list_head *entry, *n;
-       u16 num_parts;
-       u64 offset;
-       int err = 1;
-
-       debug("===device_parse===\n");
-
-       assert(retdev);
-       *retdev = NULL;
-
-       if (ret)
-               *ret = NULL;
-
-       /* fetch <mtd-id> */
-       mtd_id = p = mtd_dev;
-       if (!(p = strchr(mtd_id, ':'))) {
-               printf("no <mtd-id> identifier\n");
-               return 1;
-       }
-       mtd_id_len = p - mtd_id + 1;
-       p++;
-
-       /* verify if we have a valid device specified */
-       if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
-               printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
-               return 1;
-       }
-
-#ifdef DEBUG
-       pend = strchr(p, ';');
-#endif
-       debug("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
-                       id->type, MTD_DEV_TYPE(id->type),
-                       id->num, id->mtd_id);
-       debug("parsing partitions %.*s\n", (int)(pend ? pend - p : strlen(p)), p);
-
-
-       /* parse partitions */
-       num_parts = 0;
-
-       offset = 0;
-       if ((dev = device_find(id->type, id->num)) != NULL) {
-               /* if device already exists start at the end of the last partition */
-               part = list_entry(dev->parts.prev, struct part_info, link);
-               offset = part->offset + part->size;
-       }
-
-       while (p && (*p != '\0') && (*p != ';')) {
-               err = 1;
-               if ((part_parse(p, &p, &part) != 0) || (!part))
-                       break;
-
-               /* calculate offset when not specified */
-               if (part->offset == OFFSET_NOT_SPECIFIED)
-                       part->offset = offset;
-               else
-                       offset = part->offset;
-
-               /* verify alignment and size */
-               if (part_validate(id, part) != 0)
-                       break;
-
-               offset += part->size;
-
-               /* partition is ok, add it to the list */
-               list_add_tail(&part->link, &tmp_list);
-               num_parts++;
-               err = 0;
-       }
-       if (err == 1) {
-               part_delall(&tmp_list);
-               return 1;
-       }
-
-       if (num_parts == 0) {
-               printf("no partitions for device %s%d (%s)\n",
-                               MTD_DEV_TYPE(id->type), id->num, id->mtd_id);
-               return 1;
-       }
-
-       debug("\ntotal partitions: %d\n", num_parts);
-
-       /* check for next device presence */
-       if (p) {
-               if (*p == ';') {
-                       if (ret)
-                               *ret = ++p;
-               } else if (*p == '\0') {
-                       if (ret)
-                               *ret = p;
-               } else {
-                       printf("unexpected character '%c' at the end of device\n", *p);
-                       if (ret)
-                               *ret = NULL;
-                       return 1;
-               }
-       }
-
-       /* allocate memory for mtd_device structure */
-       if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
-               printf("out of memory\n");
-               return 1;
-       }
-       memset(dev, 0, sizeof(struct mtd_device));
-       dev->id = id;
-       dev->num_parts = 0; /* part_sort_add increments num_parts */
-       INIT_LIST_HEAD(&dev->parts);
-       INIT_LIST_HEAD(&dev->link);
-
-       /* move partitions from tmp_list to dev->parts */
-       list_for_each_safe(entry, n, &tmp_list) {
-               part = list_entry(entry, struct part_info, link);
-               list_del(entry);
-               if (part_sort_add(dev, part) != 0) {
-                       device_del(dev);
-                       return 1;
-               }
-       }
-
-       *retdev = dev;
-
-       debug("===\n\n");
-       return 0;
-}
-
-/**
- * Initialize global device list.
- *
- * @return 0 on success, 1 otherwise
- */
-static int mtd_devices_init(void)
-{
-       last_parts[0] = '\0';
-       current_mtd_dev = NULL;
-       current_save();
-
-       return device_delall(&devices);
-}
-
-/*
- * Search global mtdids list and find id of requested type and number.
- *
- * @return pointer to the id if it exists, NULL otherwise
- */
-static struct mtdids* id_find(u8 type, u8 num)
-{
-       struct list_head *entry;
-       struct mtdids *id;
-
-       list_for_each(entry, &mtdids) {
-               id = list_entry(entry, struct mtdids, link);
-
-               if ((id->type == type) && (id->num == num))
-                       return id;
-       }
-
-       return NULL;
-}
-
-/**
- * Search global mtdids list and find id of a requested mtd_id.
- *
- * Note: first argument is not null terminated.
- *
- * @param mtd_id string containing requested mtd_id
- * @param mtd_id_len length of supplied mtd_id
- * @return pointer to the id if it exists, NULL otherwise
- */
-static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len)
-{
-       struct list_head *entry;
-       struct mtdids *id;
-
-       debug("--- id_find_by_mtd_id: '%.*s' (len = %d)\n",
-                       mtd_id_len, mtd_id, mtd_id_len);
-
-       list_for_each(entry, &mtdids) {
-               id = list_entry(entry, struct mtdids, link);
-
-               debug("entry: '%s' (len = %zu)\n",
-                               id->mtd_id, strlen(id->mtd_id));
-
-               if (mtd_id_len != strlen(id->mtd_id))
-                       continue;
-               if (strncmp(id->mtd_id, mtd_id, mtd_id_len) == 0)
-                       return id;
-       }
-
-       return NULL;
-}
-
-/**
- * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
- * return device type and number.
- *
- * @param id string describing device id
- * @param ret_id output pointer to next char after parse completes (output)
- * @param dev_type parsed device type (output)
- * @param dev_num parsed device number (output)
- * @return 0 on success, 1 otherwise
- */
-int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
-                u8 *dev_num)
-{
-       const char *p = id;
-
-       *dev_type = 0;
-       if (strncmp(p, "nand", 4) == 0) {
-               *dev_type = MTD_DEV_TYPE_NAND;
-               p += 4;
-       } else if (strncmp(p, "nor", 3) == 0) {
-               *dev_type = MTD_DEV_TYPE_NOR;
-               p += 3;
-       } else if (strncmp(p, "onenand", 7) == 0) {
-               *dev_type = MTD_DEV_TYPE_ONENAND;
-               p += 7;
-       } else {
-               printf("incorrect device type in %s\n", id);
-               return 1;
-       }
-
-       if (!isdigit(*p)) {
-               printf("incorrect device number in %s\n", id);
-               return 1;
-       }
-
-       *dev_num = simple_strtoul(p, (char **)&p, 0);
-       if (ret_id)
-               *ret_id = p;
-       return 0;
-}
-
-/**
- * Process all devices and generate corresponding mtdparts string describing
- * all partitions on all devices.
- *
- * @param buf output buffer holding generated mtdparts string (output)
- * @param buflen buffer size
- * @return 0 on success, 1 otherwise
- */
-static int generate_mtdparts(char *buf, u32 buflen)
-{
-       struct list_head *pentry, *dentry;
-       struct mtd_device *dev;
-       struct part_info *part, *prev_part;
-       char *p = buf;
-       char tmpbuf[32];
-       u64 size, offset;
-       u32 len, part_cnt;
-       u32 maxlen = buflen - 1;
-
-       debug("--- generate_mtdparts ---\n");
-
-       if (list_empty(&devices)) {
-               buf[0] = '\0';
-               return 0;
-       }
-
-       strcpy(p, "mtdparts=");
-       p += 9;
-
-       list_for_each(dentry, &devices) {
-               dev = list_entry(dentry, struct mtd_device, link);
-
-               /* copy mtd_id */
-               len = strlen(dev->id->mtd_id) + 1;
-               if (len > maxlen)
-                       goto cleanup;
-               memcpy(p, dev->id->mtd_id, len - 1);
-               p += len - 1;
-               *(p++) = ':';
-               maxlen -= len;
-
-               /* format partitions */
-               prev_part = NULL;
-               part_cnt = 0;
-               list_for_each(pentry, &dev->parts) {
-                       part = list_entry(pentry, struct part_info, link);
-                       size = part->size;
-                       offset = part->offset;
-                       part_cnt++;
-
-                       /* partition size */
-                       memsize_format(tmpbuf, size);
-                       len = strlen(tmpbuf);
-                       if (len > maxlen)
-                               goto cleanup;
-                       memcpy(p, tmpbuf, len);
-                       p += len;
-                       maxlen -= len;
-
-
-                       /* add offset only when there is a gap between
-                        * partitions */
-                       if ((!prev_part && (offset != 0)) ||
-                                       (prev_part && ((prev_part->offset + prev_part->size) != part->offset))) {
-
-                               memsize_format(tmpbuf, offset);
-                               len = strlen(tmpbuf) + 1;
-                               if (len > maxlen)
-                                       goto cleanup;
-                               *(p++) = '@';
-                               memcpy(p, tmpbuf, len - 1);
-                               p += len - 1;
-                               maxlen -= len;
-                       }
-
-                       /* copy name only if user supplied */
-                       if(!part->auto_name) {
-                               len = strlen(part->name) + 2;
-                               if (len > maxlen)
-                                       goto cleanup;
-
-                               *(p++) = '(';
-                               memcpy(p, part->name, len - 2);
-                               p += len - 2;
-                               *(p++) = ')';
-                               maxlen -= len;
-                       }
-
-                       /* ro mask flag */
-                       if (part->mask_flags && MTD_WRITEABLE_CMD) {
-                               len = 2;
-                               if (len > maxlen)
-                                       goto cleanup;
-                               *(p++) = 'r';
-                               *(p++) = 'o';
-                               maxlen -= 2;
-                       }
-
-                       /* print ',' separator if there are other partitions
-                        * following */
-                       if (dev->num_parts > part_cnt) {
-                               if (1 > maxlen)
-                                       goto cleanup;
-                               *(p++) = ',';
-                               maxlen--;
-                       }
-                       prev_part = part;
-               }
-               /* print ';' separator if there are other devices following */
-               if (dentry->next != &devices) {
-                       if (1 > maxlen)
-                               goto cleanup;
-                       *(p++) = ';';
-                       maxlen--;
-               }
-       }
-
-       /* we still have at least one char left, as we decremented maxlen at
-        * the begining */
-       *p = '\0';
-
-       return 0;
-
-cleanup:
-       last_parts[0] = '\0';
-       return 1;
-}
-
-/**
- * Call generate_mtdparts to process all devices and generate corresponding
- * mtdparts string, save it in mtdparts environment variable.
- *
- * @param buf output buffer holding generated mtdparts string (output)
- * @param buflen buffer size
- * @return 0 on success, 1 otherwise
- */
-static int generate_mtdparts_save(char *buf, u32 buflen)
-{
-       int ret;
-
-       ret = generate_mtdparts(buf, buflen);
-
-       if ((buf[0] != '\0') && (ret == 0))
-               setenv("mtdparts", buf);
-       else
-               setenv("mtdparts", NULL);
-
-       return ret;
-}
-
-#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
-/**
- * Get the net size (w/o bad blocks) of the given partition.
- *
- * @param mtd the mtd info
- * @param part the partition
- * @return the calculated net size of this partition
- */
-static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
-{
-       uint64_t i, net_size = 0;
-
-       if (!mtd->block_isbad)
-               return part->size;
-
-       for (i = 0; i < part->size; i += mtd->erasesize) {
-               if (!mtd->block_isbad(mtd, part->offset + i))
-                       net_size += mtd->erasesize;
-       }
-
-       return net_size;
-}
-#endif
-
-static void print_partition_table(void)
-{
-       struct list_head *dentry, *pentry;
-       struct part_info *part;
-       struct mtd_device *dev;
-       int part_num;
-
-       list_for_each(dentry, &devices) {
-               dev = list_entry(dentry, struct mtd_device, link);
-               /* list partitions for given device */
-               part_num = 0;
-#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
-               struct mtd_info *mtd;
-
-               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return;
-
-               printf("\ndevice %s%d <%s>, # parts = %d\n",
-                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
-                               dev->id->mtd_id, dev->num_parts);
-               printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
-
-               list_for_each(pentry, &dev->parts) {
-                       u32 net_size;
-                       char *size_note;
-
-                       part = list_entry(pentry, struct part_info, link);
-                       net_size = net_part_size(mtd, part);
-                       size_note = part->size == net_size ? " " : " (!)";
-                       printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
-                                       part_num, part->name, part->size,
-                                       net_size, size_note, part->offset,
-                                       part->mask_flags);
-#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
-               printf("\ndevice %s%d <%s>, # parts = %d\n",
-                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
-                               dev->id->mtd_id, dev->num_parts);
-               printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
-
-               list_for_each(pentry, &dev->parts) {
-                       part = list_entry(pentry, struct part_info, link);
-                       printf("%2d: %-20s0x%08llx\t0x%08llx\t%d\n",
-                                       part_num, part->name, part->size,
-                                       part->offset, part->mask_flags);
-#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
-                       part_num++;
-               }
-       }
-
-       if (list_empty(&devices))
-               printf("no partitions defined\n");
-}
-
-/**
- * Format and print out a partition list for each device from global device
- * list.
- */
-static void list_partitions(void)
-{
-       struct part_info *part;
-
-       debug("\n---list_partitions---\n");
-       print_partition_table();
-
-       /* current_mtd_dev is not NULL only when we have non empty device list */
-       if (current_mtd_dev) {
-               part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
-               if (part) {
-                       printf("\nactive partition: %s%d,%d - (%s) 0x%08llx @ 0x%08llx\n",
-                                       MTD_DEV_TYPE(current_mtd_dev->id->type),
-                                       current_mtd_dev->id->num, current_mtd_partnum,
-                                       part->name, part->size, part->offset);
-               } else {
-                       printf("could not get current partition info\n\n");
-               }
-       }
-
-       printf("\ndefaults:\n");
-       printf("mtdids  : %s\n",
-               mtdids_default ? mtdids_default : "none");
-       /*
-        * Using printf() here results in printbuffer overflow
-        * if default mtdparts string is greater than console
-        * printbuffer. Use puts() to prevent system crashes.
-        */
-       puts("mtdparts: ");
-       puts(mtdparts_default ? mtdparts_default : "none");
-       puts("\n");
-}
-
-/**
- * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
- * corresponding device and verify partition number.
- *
- * @param id string describing device and partition or partition name
- * @param dev pointer to the requested device (output)
- * @param part_num verified partition number (output)
- * @param part pointer to requested partition (output)
- * @return 0 on success, 1 otherwise
- */
-int find_dev_and_part(const char *id, struct mtd_device **dev,
-               u8 *part_num, struct part_info **part)
-{
-       struct list_head *dentry, *pentry;
-       u8 type, dnum, pnum;
-       const char *p;
-
-       debug("--- find_dev_and_part ---\nid = %s\n", id);
-
-       list_for_each(dentry, &devices) {
-               *part_num = 0;
-               *dev = list_entry(dentry, struct mtd_device, link);
-               list_for_each(pentry, &(*dev)->parts) {
-                       *part = list_entry(pentry, struct part_info, link);
-                       if (strcmp((*part)->name, id) == 0)
-                               return 0;
-                       (*part_num)++;
-               }
-       }
-
-       p = id;
-       *dev = NULL;
-       *part = NULL;
-       *part_num = 0;
-
-       if (mtd_id_parse(p, &p, &type, &dnum) != 0)
-               return 1;
-
-       if ((*p++ != ',') || (*p == '\0')) {
-               printf("no partition number specified\n");
-               return 1;
-       }
-       pnum = simple_strtoul(p, (char **)&p, 0);
-       if (*p != '\0') {
-               printf("unexpected trailing character '%c'\n", *p);
-               return 1;
-       }
-
-       if ((*dev = device_find(type, dnum)) == NULL) {
-               printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
-               return 1;
-       }
-
-       if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
-               printf("no such partition\n");
-               *dev = NULL;
-               return 1;
-       }
-
-       *part_num = pnum;
-
-       return 0;
-}
-
-/**
- * Find and delete partition. For partition id format see find_dev_and_part().
- *
- * @param id string describing device and partition
- * @return 0 on success, 1 otherwise
- */
-static int delete_partition(const char *id)
-{
-       u8 pnum;
-       struct mtd_device *dev;
-       struct part_info *part;
-
-       if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
-
-               debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08llx@0x%08llx\n",
-                               MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
-                               part->name, part->size, part->offset);
-
-               if (part_del(dev, part) != 0)
-                       return 1;
-
-               if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
-                       printf("generated mtdparts too long, resetting to null\n");
-                       return 1;
-               }
-               return 0;
-       }
-
-       printf("partition %s not found\n", id);
-       return 1;
-}
-
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-/**
- * Increase the size of the given partition so that it's net size is at least
- * as large as the size member and such that the next partition would start on a
- * good block if it were adjacent to this partition.
- *
- * @param mtd the mtd device
- * @param part the partition
- * @param next_offset pointer to the offset of the next partition after this
- *                    partition's size has been modified (output)
- */
-static void spread_partition(struct mtd_info *mtd, struct part_info *part,
-                            uint64_t *next_offset)
-{
-       uint64_t net_size, padding_size = 0;
-       int truncated;
-
-       mtd_get_len_incl_bad(mtd, part->offset, part->size, &net_size,
-                            &truncated);
-
-       /*
-        * Absorb bad blocks immediately following this
-        * partition also into the partition, such that
-        * the next partition starts with a good block.
-        */
-       if (!truncated) {
-               mtd_get_len_incl_bad(mtd, part->offset + net_size,
-                                    mtd->erasesize, &padding_size, &truncated);
-               if (truncated)
-                       padding_size = 0;
-               else
-                       padding_size -= mtd->erasesize;
-       }
-
-       if (truncated) {
-               printf("truncated partition %s to %lld bytes\n", part->name,
-                      (uint64_t) net_size + padding_size);
-       }
-
-       part->size = net_size + padding_size;
-       *next_offset = part->offset + part->size;
-}
-
-/**
- * Adjust all of the partition sizes, such that all partitions are at least
- * as big as their mtdparts environment variable sizes and they each start
- * on a good block.
- *
- * @return 0 on success, 1 otherwise
- */
-static int spread_partitions(void)
-{
-       struct list_head *dentry, *pentry;
-       struct mtd_device *dev;
-       struct part_info *part;
-       struct mtd_info *mtd;
-       int part_num;
-       uint64_t cur_offs;
-
-       list_for_each(dentry, &devices) {
-               dev = list_entry(dentry, struct mtd_device, link);
-
-               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return 1;
-
-               part_num = 0;
-               cur_offs = 0;
-               list_for_each(pentry, &dev->parts) {
-                       part = list_entry(pentry, struct part_info, link);
-
-                       debug("spread_partitions: device = %s%d, partition %d ="
-                               " (%s) 0x%08x@0x%08x\n",
-                               MTD_DEV_TYPE(dev->id->type), dev->id->num,
-                               part_num, part->name, part->size,
-                               part->offset);
-
-                       if (cur_offs > part->offset)
-                               part->offset = cur_offs;
-
-                       spread_partition(mtd, part, &cur_offs);
-
-                       part_num++;
-               }
-       }
-
-       index_partitions();
-
-       if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
-               printf("generated mtdparts too long, resetting to null\n");
-               return 1;
-       }
-       return 0;
-}
-#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
-
-/**
- * Accept character string describing mtd partitions and call device_parse()
- * for each entry. Add created devices to the global devices list.
- *
- * @param mtdparts string specifing mtd partitions
- * @return 0 on success, 1 otherwise
- */
-static int parse_mtdparts(const char *const mtdparts)
-{
-       const char *p = mtdparts;
-       struct mtd_device *dev;
-       int err = 1;
-       char tmp_parts[MTDPARTS_MAXLEN];
-
-       debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
-
-       /* delete all devices and partitions */
-       if (mtd_devices_init() != 0) {
-               printf("could not initialise device list\n");
-               return err;
-       }
-
-       /* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
-       if (gd->flags & GD_FLG_ENV_READY) {
-               p = getenv("mtdparts");
-       } else {
-               p = tmp_parts;
-               getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
-       }
-
-       if (strncmp(p, "mtdparts=", 9) != 0) {
-               printf("mtdparts variable doesn't start with 'mtdparts='\n");
-               return err;
-       }
-       p += 9;
-
-       while (p && (*p != '\0')) {
-               err = 1;
-               if ((device_parse(p, &p, &dev) != 0) || (!dev))
-                       break;
-
-               debug("+ device: %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
-                               dev->id->num, dev->id->mtd_id);
-
-               /* check if parsed device is already on the list */
-               if (device_find(dev->id->type, dev->id->num) != NULL) {
-                       printf("device %s%d redefined, please correct mtdparts variable\n",
-                                       MTD_DEV_TYPE(dev->id->type), dev->id->num);
-                       break;
-               }
-
-               list_add_tail(&dev->link, &devices);
-               err = 0;
-       }
-       if (err == 1) {
-               device_delall(&devices);
-               return 1;
-       }
-
-       return 0;
-}
-
-/**
- * Parse provided string describing mtdids mapping (see file header for mtdids
- * variable format). Allocate memory for each entry and add all found entries
- * to the global mtdids list.
- *
- * @param ids mapping string
- * @return 0 on success, 1 otherwise
- */
-static int parse_mtdids(const char *const ids)
-{
-       const char *p = ids;
-       const char *mtd_id;
-       int mtd_id_len;
-       struct mtdids *id;
-       struct list_head *entry, *n;
-       struct mtdids *id_tmp;
-       u8 type, num;
-       u64 size;
-       int ret = 1;
-
-       debug("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
-
-       /* clean global mtdids list */
-       list_for_each_safe(entry, n, &mtdids) {
-               id_tmp = list_entry(entry, struct mtdids, link);
-               debug("mtdids del: %d %d\n", id_tmp->type, id_tmp->num);
-               list_del(entry);
-               free(id_tmp);
-       }
-       last_ids[0] = '\0';
-       INIT_LIST_HEAD(&mtdids);
-
-       while(p && (*p != '\0')) {
-
-               ret = 1;
-               /* parse 'nor'|'nand'|'onenand'<dev-num> */
-               if (mtd_id_parse(p, &p, &type, &num) != 0)
-                       break;
-
-               if (*p != '=') {
-                       printf("mtdids: incorrect <dev-num>\n");
-                       break;
-               }
-               p++;
-
-               /* check if requested device exists */
-               if (mtd_device_validate(type, num, &size) != 0)
-                       return 1;
-
-               /* locate <mtd-id> */
-               mtd_id = p;
-               if ((p = strchr(mtd_id, ',')) != NULL) {
-                       mtd_id_len = p - mtd_id + 1;
-                       p++;
-               } else {
-                       mtd_id_len = strlen(mtd_id) + 1;
-               }
-               if (mtd_id_len == 0) {
-                       printf("mtdids: no <mtd-id> identifier\n");
-                       break;
-               }
-
-               /* check if this id is already on the list */
-               int double_entry = 0;
-               list_for_each(entry, &mtdids) {
-                       id_tmp = list_entry(entry, struct mtdids, link);
-                       if ((id_tmp->type == type) && (id_tmp->num == num)) {
-                               double_entry = 1;
-                               break;
-                       }
-               }
-               if (double_entry) {
-                       printf("device id %s%d redefined, please correct mtdids variable\n",
-                                       MTD_DEV_TYPE(type), num);
-                       break;
-               }
-
-               /* allocate mtdids structure */
-               if (!(id = (struct mtdids *)malloc(sizeof(struct mtdids) + mtd_id_len))) {
-                       printf("out of memory\n");
-                       break;
-               }
-               memset(id, 0, sizeof(struct mtdids) + mtd_id_len);
-               id->num = num;
-               id->type = type;
-               id->size = size;
-               id->mtd_id = (char *)(id + 1);
-               strncpy(id->mtd_id, mtd_id, mtd_id_len - 1);
-               id->mtd_id[mtd_id_len - 1] = '\0';
-               INIT_LIST_HEAD(&id->link);
-
-               debug("+ id %s%d\t%16lld bytes\t%s\n",
-                               MTD_DEV_TYPE(id->type), id->num,
-                               id->size, id->mtd_id);
-
-               list_add_tail(&id->link, &mtdids);
-               ret = 0;
-       }
-       if (ret == 1) {
-               /* clean mtdids list and free allocated memory */
-               list_for_each_safe(entry, n, &mtdids) {
-                       id_tmp = list_entry(entry, struct mtdids, link);
-                       list_del(entry);
-                       free(id_tmp);
-               }
-               return 1;
-       }
-
-       return 0;
-}
-
-/**
- * Parse and initialize global mtdids mapping and create global
- * device/partition list.
- *
- * @return 0 on success, 1 otherwise
- */
-int mtdparts_init(void)
-{
-       static int initialized = 0;
-       const char *ids, *parts;
-       const char *current_partition;
-       int ids_changed;
-       char tmp_ep[PARTITION_MAXLEN];
-       char tmp_parts[MTDPARTS_MAXLEN];
-
-       debug("\n---mtdparts_init---\n");
-       if (!initialized) {
-               INIT_LIST_HEAD(&mtdids);
-               INIT_LIST_HEAD(&devices);
-               memset(last_ids, 0, MTDIDS_MAXLEN);
-               memset(last_parts, 0, MTDPARTS_MAXLEN);
-               memset(last_partition, 0, PARTITION_MAXLEN);
-               initialized = 1;
-       }
-
-       /* get variables */
-       ids = getenv("mtdids");
-       /*
-        * The mtdparts variable tends to be long. If we need to access it
-        * before the env is relocated, then we need to use our own stack
-        * buffer.  gd->env_buf will be too small.
-        */
-       if (gd->flags & GD_FLG_ENV_READY) {
-               parts = getenv("mtdparts");
-       } else {
-               parts = tmp_parts;
-               getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
-       }
-       current_partition = getenv("partition");
-
-       /* save it for later parsing, cannot rely on current partition pointer
-        * as 'partition' variable may be updated during init */
-       tmp_ep[0] = '\0';
-       if (current_partition)
-               strncpy(tmp_ep, current_partition, PARTITION_MAXLEN);
-
-       debug("last_ids  : %s\n", last_ids);
-       debug("env_ids   : %s\n", ids);
-       debug("last_parts: %s\n", last_parts);
-       debug("env_parts : %s\n\n", parts);
-
-       debug("last_partition : %s\n", last_partition);
-       debug("env_partition  : %s\n", current_partition);
-
-       /* if mtdids varible is empty try to use defaults */
-       if (!ids) {
-               if (mtdids_default) {
-                       debug("mtdids variable not defined, using default\n");
-                       ids = mtdids_default;
-                       setenv("mtdids", (char *)ids);
-               } else {
-                       printf("mtdids not defined, no default present\n");
-                       return 1;
-               }
-       }
-       if (strlen(ids) > MTDIDS_MAXLEN - 1) {
-               printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
-               return 1;
-       }
-
-       /* do no try to use defaults when mtdparts variable is not defined,
-        * just check the length */
-       if (!parts)
-               printf("mtdparts variable not set, see 'help mtdparts'\n");
-
-       if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
-               printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
-               return 1;
-       }
-
-       /* check if we have already parsed those mtdids */
-       if ((last_ids[0] != '\0') && (strcmp(last_ids, ids) == 0)) {
-               ids_changed = 0;
-       } else {
-               ids_changed = 1;
-
-               if (parse_mtdids(ids) != 0) {
-                       mtd_devices_init();
-                       return 1;
-               }
-
-               /* ok it's good, save new ids */
-               strncpy(last_ids, ids, MTDIDS_MAXLEN);
-       }
-
-       /* parse partitions if either mtdparts or mtdids were updated */
-       if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
-               if (parse_mtdparts(parts) != 0)
-                       return 1;
-
-               if (list_empty(&devices)) {
-                       printf("mtdparts_init: no valid partitions\n");
-                       return 1;
-               }
-
-               /* ok it's good, save new parts */
-               strncpy(last_parts, parts, MTDPARTS_MAXLEN);
-
-               /* reset first partition from first dev from the list as current */
-               current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
-               current_mtd_partnum = 0;
-               current_save();
-
-               debug("mtdparts_init: current_mtd_dev  = %s%d, current_mtd_partnum = %d\n",
-                               MTD_DEV_TYPE(current_mtd_dev->id->type),
-                               current_mtd_dev->id->num, current_mtd_partnum);
-       }
-
-       /* mtdparts variable was reset to NULL, delete all devices/partitions */
-       if (!parts && (last_parts[0] != '\0'))
-               return mtd_devices_init();
-
-       /* do not process current partition if mtdparts variable is null */
-       if (!parts)
-               return 0;
-
-       /* is current partition set in environment? if so, use it */
-       if ((tmp_ep[0] != '\0') && (strcmp(tmp_ep, last_partition) != 0)) {
-               struct part_info *p;
-               struct mtd_device *cdev;
-               u8 pnum;
-
-               debug("--- getting current partition: %s\n", tmp_ep);
-
-               if (find_dev_and_part(tmp_ep, &cdev, &pnum, &p) == 0) {
-                       current_mtd_dev = cdev;
-                       current_mtd_partnum = pnum;
-                       current_save();
-               }
-       } else if (getenv("partition") == NULL) {
-               debug("no partition variable set, setting...\n");
-               current_save();
-       }
-
-       return 0;
-}
-
-/**
- * Return pointer to the partition of a requested number from a requested
- * device.
- *
- * @param dev device that is to be searched for a partition
- * @param part_num requested partition number
- * @return pointer to the part_info, NULL otherwise
- */
-static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num)
-{
-       struct list_head *entry;
-       struct part_info *part;
-       int num;
-
-       if (!dev)
-               return NULL;
-
-       debug("\n--- mtd_part_info: partition number %d for device %s%d (%s)\n",
-                       part_num, MTD_DEV_TYPE(dev->id->type),
-                       dev->id->num, dev->id->mtd_id);
-
-       if (part_num >= dev->num_parts) {
-               printf("invalid partition number %d for device %s%d (%s)\n",
-                               part_num, MTD_DEV_TYPE(dev->id->type),
-                               dev->id->num, dev->id->mtd_id);
-               return NULL;
-       }
-
-       /* locate partition number, return it */
-       num = 0;
-       list_for_each(entry, &dev->parts) {
-               part = list_entry(entry, struct part_info, link);
-
-               if (part_num == num++) {
-                       return part;
-               }
-       }
-
-       return NULL;
-}
-
-/***************************************************/
-/* U-boot commands                                */
-/***************************************************/
-/* command line only */
-/**
- * Routine implementing u-boot chpart command. Sets new current partition based
- * on the user supplied partition id. For partition id format see find_dev_and_part().
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-static int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-/* command line only */
-       struct mtd_device *dev;
-       struct part_info *part;
-       u8 pnum;
-
-       if (mtdparts_init() !=0)
-               return 1;
-
-       if (argc < 2) {
-               printf("no partition id specified\n");
-               return 1;
-       }
-
-       if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
-               return 1;
-
-       current_mtd_dev = dev;
-       current_mtd_partnum = pnum;
-       current_save();
-
-       printf("partition changed to %s%d,%d\n",
-                       MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum);
-
-       return 0;
-}
-
-/**
- * Routine implementing u-boot mtdparts command. Initialize/update default global
- * partition list and process user partition request (list, add, del).
- *
- * @param cmdtp command internal data
- * @param flag command flag
- * @param argc number of arguments supplied to the command
- * @param argv arguments list
- * @return 0 on success, 1 otherwise
- */
-static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       if (argc == 2) {
-               if (strcmp(argv[1], "default") == 0) {
-                       setenv("mtdids", (char *)mtdids_default);
-                       setenv("mtdparts", (char *)mtdparts_default);
-                       setenv("partition", NULL);
-
-                       mtdparts_init();
-                       return 0;
-               } else if (strcmp(argv[1], "delall") == 0) {
-                       /* this may be the first run, initialize lists if needed */
-                       mtdparts_init();
-
-                       setenv("mtdparts", NULL);
-
-                       /* mtd_devices_init() calls current_save() */
-                       return mtd_devices_init();
-               }
-       }
-
-       /* make sure we are in sync with env variables */
-       if (mtdparts_init() != 0)
-               return 1;
-
-       if (argc == 1) {
-               list_partitions();
-               return 0;
-       }
-
-       /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
-       if (((argc == 5) || (argc == 6)) && (strncmp(argv[1], "add", 3) == 0)) {
-#define PART_ADD_DESC_MAXLEN 64
-               char tmpbuf[PART_ADD_DESC_MAXLEN];
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-               struct mtd_info *mtd;
-               uint64_t next_offset;
-#endif
-               u8 type, num, len;
-               struct mtd_device *dev;
-               struct mtd_device *dev_tmp;
-               struct mtdids *id;
-               struct part_info *p;
-
-               if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
-                       return 1;
-
-               if ((id = id_find(type, num)) == NULL) {
-                       printf("no such device %s defined in mtdids variable\n", argv[2]);
-                       return 1;
-               }
-
-               len = strlen(id->mtd_id) + 1;   /* 'mtd_id:' */
-               len += strlen(argv[3]);         /* size@offset */
-               len += strlen(argv[4]) + 2;     /* '(' name ')' */
-               if (argv[5] && (strlen(argv[5]) == 2))
-                       len += 2;               /* 'ro' */
-
-               if (len >= PART_ADD_DESC_MAXLEN) {
-                       printf("too long partition description\n");
-                       return 1;
-               }
-               sprintf(tmpbuf, "%s:%s(%s)%s",
-                               id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
-               debug("add tmpbuf: %s\n", tmpbuf);
-
-               if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
-                       return 1;
-
-               debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
-                               dev->id->num, dev->id->mtd_id);
-
-               p = list_entry(dev->parts.next, struct part_info, link);
-
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-               if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return 1;
-
-               if (!strcmp(&argv[1][3], ".spread")) {
-                       spread_partition(mtd, p, &next_offset);
-                       debug("increased %s to %d bytes\n", p->name, p->size);
-               }
-#endif
-
-               dev_tmp = device_find(dev->id->type, dev->id->num);
-               if (dev_tmp == NULL) {
-                       device_add(dev);
-               } else if (part_add(dev_tmp, p) != 0) {
-                       /* merge new partition with existing ones*/
-                       device_del(dev);
-                       return 1;
-               }
-
-               if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
-                       printf("generated mtdparts too long, resetting to null\n");
-                       return 1;
-               }
-
-               return 0;
-       }
-
-       /* mtdparts del part-id */
-       if ((argc == 3) && (strcmp(argv[1], "del") == 0)) {
-               debug("del: part-id = %s\n", argv[2]);
-
-               return delete_partition(argv[2]);
-       }
-
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-       if ((argc == 2) && (strcmp(argv[1], "spread") == 0))
-               return spread_partitions();
-#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
-
-       return CMD_RET_USAGE;
-}
-
-/***************************************************/
-U_BOOT_CMD(
-       chpart, 2,      0,      do_chpart,
-       "change active partition",
-       "part-id\n"
-       "    - change active partition (e.g. part-id = nand0,1)"
-);
-
-#ifdef CONFIG_SYS_LONGHELP
-static char mtdparts_help_text[] =
-       "\n"
-       "    - list partition table\n"
-       "mtdparts delall\n"
-       "    - delete all partitions\n"
-       "mtdparts del part-id\n"
-       "    - delete partition (e.g. part-id = nand0,1)\n"
-       "mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
-       "    - add partition\n"
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-       "mtdparts add.spread <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
-       "    - add partition, padding size by skipping bad blocks\n"
-#endif
-       "mtdparts default\n"
-       "    - reset partition table to defaults\n"
-#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
-       "mtdparts spread\n"
-       "    - adjust the sizes of the partitions so they are\n"
-       "      at least as big as the mtdparts variable specifies\n"
-       "      and they each start on a good block\n\n"
-#else
-       "\n"
-#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
-       "-----\n\n"
-       "this command uses three environment variables:\n\n"
-       "'partition' - keeps current partition identifier\n\n"
-       "partition  := <part-id>\n"
-       "<part-id>  := <dev-id>,part_num\n\n"
-       "'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
-       "mtdids=<idmap>[,<idmap>,...]\n\n"
-       "<idmap>    := <dev-id>=<mtd-id>\n"
-       "<dev-id>   := 'nand'|'nor'|'onenand'<dev-num>\n"
-       "<dev-num>  := mtd device number, 0...\n"
-       "<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n"
-       "'mtdparts' - partition list\n\n"
-       "mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]\n\n"
-       "<mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]\n"
-       "<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)\n"
-       "<part-def> := <size>[@<offset>][<name>][<ro-flag>]\n"
-       "<size>     := standard linux memsize OR '-' to denote all remaining space\n"
-       "<offset>   := partition start offset within the device\n"
-       "<name>     := '(' NAME ')'\n"
-       "<ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)";
-#endif
-
-U_BOOT_CMD(
-       mtdparts,       6,      0,      do_mtdparts,
-       "define flash/nand partitions", mtdparts_help_text
-);
-/***************************************************/
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
deleted file mode 100644 (file)
index a6b67e2..0000000
+++ /dev/null
@@ -1,973 +0,0 @@
-/*
- * Driver for NAND support, Rick Bronson
- * borrowed heavily from:
- * (c) 1999 Machine Vision Holdings, Inc.
- * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
- *
- * Ported 'dynenv' to 'nand env.oob' command
- * (C) 2010 Nanometrics, Inc.
- * 'dynenv' -- Dynamic environment offset in NAND OOB
- * (C) Copyright 2006-2007 OpenMoko, Inc.
- * Added 16-bit nand support
- * (C) 2004 Texas Instruments
- *
- * Copyright 2010, 2012 Freescale Semiconductor
- * The portions of this file whose copyright is held by Freescale and which
- * are not considered a derived work of GPL v2-only code may be distributed
- * and/or modified under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- */
-
-#include <common.h>
-#include <linux/mtd/mtd.h>
-#include <command.h>
-#include <console.h>
-#include <watchdog.h>
-#include <malloc.h>
-#include <asm/byteorder.h>
-#include <jffs2/jffs2.h>
-#include <nand.h>
-
-#if defined(CONFIG_CMD_MTDPARTS)
-
-/* partition handling routines */
-int mtdparts_init(void);
-int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
-int find_dev_and_part(const char *id, struct mtd_device **dev,
-                     u8 *part_num, struct part_info **part);
-#endif
-
-static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
-{
-       int i;
-       u_char *datbuf, *oobbuf, *p;
-       static loff_t last;
-       int ret = 0;
-
-       if (repeat)
-               off = last + nand->writesize;
-
-       last = off;
-
-       datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize);
-       if (!datbuf) {
-               puts("No memory for page buffer\n");
-               return 1;
-       }
-
-       oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize);
-       if (!oobbuf) {
-               puts("No memory for page buffer\n");
-               ret = 1;
-               goto free_dat;
-       }
-       off &= ~(nand->writesize - 1);
-       loff_t addr = (loff_t) off;
-       struct mtd_oob_ops ops;
-       memset(&ops, 0, sizeof(ops));
-       ops.datbuf = datbuf;
-       ops.oobbuf = oobbuf;
-       ops.len = nand->writesize;
-       ops.ooblen = nand->oobsize;
-       ops.mode = MTD_OPS_RAW;
-       i = mtd_read_oob(nand, addr, &ops);
-       if (i < 0) {
-               printf("Error (%d) reading page %08lx\n", i, off);
-               ret = 1;
-               goto free_all;
-       }
-       printf("Page %08lx dump:\n", off);
-
-       if (!only_oob) {
-               i = nand->writesize >> 4;
-               p = datbuf;
-
-               while (i--) {
-                       printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
-                              "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
-                              p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
-                              p[8], p[9], p[10], p[11], p[12], p[13], p[14],
-                              p[15]);
-                       p += 16;
-               }
-       }
-
-       puts("OOB:\n");
-       i = nand->oobsize >> 3;
-       p = oobbuf;
-       while (i--) {
-               printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
-                      p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-               p += 8;
-       }
-
-free_all:
-       free(oobbuf);
-free_dat:
-       free(datbuf);
-
-       return ret;
-}
-
-/* ------------------------------------------------------------------------- */
-
-static int set_dev(int dev)
-{
-       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
-           !nand_info[dev].name) {
-               puts("No such device\n");
-               return -1;
-       }
-
-       if (nand_curr_device == dev)
-               return 0;
-
-       printf("Device %d: %s", dev, nand_info[dev].name);
-       puts("... is now current device\n");
-       nand_curr_device = dev;
-
-#ifdef CONFIG_SYS_NAND_SELECT_DEVICE
-       board_nand_select_device(nand_info[dev].priv, dev);
-#endif
-
-       return 0;
-}
-
-#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
-static void print_status(ulong start, ulong end, ulong erasesize, int status)
-{
-       /*
-        * Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is
-        * not the same as others.  Instead of bit 1 being lock, it is
-        * #lock_tight. To make the driver support either format, ignore bit 1
-        * and use only bit 0 and bit 2.
-        */
-       printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
-               start,
-               end - 1,
-               (end - start) / erasesize,
-               ((status & NAND_LOCK_STATUS_TIGHT) ?  "TIGHT " : ""),
-               (!(status & NAND_LOCK_STATUS_UNLOCK) ?  "LOCK " : ""),
-               ((status & NAND_LOCK_STATUS_UNLOCK) ?  "UNLOCK " : ""));
-}
-
-static void do_nand_status(nand_info_t *nand)
-{
-       ulong block_start = 0;
-       ulong off;
-       int last_status = -1;
-
-       struct nand_chip *nand_chip = nand->priv;
-       /* check the WP bit */
-       nand_chip->cmdfunc(nand, NAND_CMD_STATUS, -1, -1);
-       printf("device is %swrite protected\n",
-               (nand_chip->read_byte(nand) & 0x80 ?
-               "NOT " : ""));
-
-       for (off = 0; off < nand->size; off += nand->erasesize) {
-               int s = nand_get_lock_status(nand, off);
-
-               /* print message only if status has changed */
-               if (s != last_status && off != 0) {
-                       print_status(block_start, off, nand->erasesize,
-                                       last_status);
-                       block_start = off;
-               }
-               last_status = s;
-       }
-       /* Print the last block info */
-       print_status(block_start, off, nand->erasesize, last_status);
-}
-#endif
-
-#ifdef CONFIG_ENV_OFFSET_OOB
-unsigned long nand_env_oob_offset;
-
-int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
-{
-       int ret;
-       uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
-       nand_info_t *nand = &nand_info[0];
-       char *cmd = argv[1];
-
-       if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) {
-               puts("no devices available\n");
-               return 1;
-       }
-
-       set_dev(0);
-
-       if (!strcmp(cmd, "get")) {
-               ret = get_nand_env_oob(nand, &nand_env_oob_offset);
-               if (ret)
-                       return 1;
-
-               printf("0x%08lx\n", nand_env_oob_offset);
-       } else if (!strcmp(cmd, "set")) {
-               loff_t addr;
-               loff_t maxsize;
-               struct mtd_oob_ops ops;
-               int idx = 0;
-
-               if (argc < 3)
-                       goto usage;
-
-               /* We don't care about size, or maxsize. */
-               if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
-                               MTD_DEV_TYPE_NAND, nand_info[idx].size)) {
-                       puts("Offset or partition name expected\n");
-                       return 1;
-               }
-               if (set_dev(idx)) {
-                       puts("Offset or partition name expected\n");
-                       return 1;
-               }
-
-               if (idx != 0) {
-                       puts("Partition not on first NAND device\n");
-                       return 1;
-               }
-
-               if (nand->oobavail < ENV_OFFSET_SIZE) {
-                       printf("Insufficient available OOB bytes:\n"
-                              "%d OOB bytes available but %d required for "
-                              "env.oob support\n",
-                              nand->oobavail, ENV_OFFSET_SIZE);
-                       return 1;
-               }
-
-               if ((addr & (nand->erasesize - 1)) != 0) {
-                       printf("Environment offset must be block-aligned\n");
-                       return 1;
-               }
-
-               ops.datbuf = NULL;
-               ops.mode = MTD_OOB_AUTO;
-               ops.ooboffs = 0;
-               ops.ooblen = ENV_OFFSET_SIZE;
-               ops.oobbuf = (void *) oob_buf;
-
-               oob_buf[0] = ENV_OOB_MARKER;
-               oob_buf[1] = addr / nand->erasesize;
-
-               ret = nand->write_oob(nand, ENV_OFFSET_SIZE, &ops);
-               if (ret) {
-                       printf("Error writing OOB block 0\n");
-                       return ret;
-               }
-
-               ret = get_nand_env_oob(nand, &nand_env_oob_offset);
-               if (ret) {
-                       printf("Error reading env offset in OOB\n");
-                       return ret;
-               }
-
-               if (addr != nand_env_oob_offset) {
-                       printf("Verification of env offset in OOB failed: "
-                              "0x%08llx expected but got 0x%08lx\n",
-                              (unsigned long long)addr, nand_env_oob_offset);
-                       return 1;
-               }
-       } else {
-               goto usage;
-       }
-
-       return ret;
-
-usage:
-       return CMD_RET_USAGE;
-}
-
-#endif
-
-static void nand_print_and_set_info(int idx)
-{
-       nand_info_t *nand = &nand_info[idx];
-       struct nand_chip *chip = nand->priv;
-
-       printf("Device %d: ", idx);
-       if (chip->numchips > 1)
-               printf("%dx ", chip->numchips);
-       printf("%s, sector size %u KiB\n",
-              nand->name, nand->erasesize >> 10);
-       printf("  Page size   %8d b\n", nand->writesize);
-       printf("  OOB size    %8d b\n", nand->oobsize);
-       printf("  Erase size  %8d b\n", nand->erasesize);
-       printf("  subpagesize %8d b\n", chip->subpagesize);
-       printf("  options     0x%8x\n", chip->options);
-       printf("  bbt options 0x%8x\n", chip->bbt_options);
-
-       /* Set geometry info */
-       setenv_hex("nand_writesize", nand->writesize);
-       setenv_hex("nand_oobsize", nand->oobsize);
-       setenv_hex("nand_erasesize", nand->erasesize);
-}
-
-static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
-                       int read)
-{
-       int ret = 0;
-
-       while (count--) {
-               /* Raw access */
-               mtd_oob_ops_t ops = {
-                       .datbuf = (u8 *)addr,
-                       .oobbuf = ((u8 *)addr) + nand->writesize,
-                       .len = nand->writesize,
-                       .ooblen = nand->oobsize,
-                       .mode = MTD_OPS_RAW
-               };
-
-               if (read) {
-                       ret = mtd_read_oob(nand, off, &ops);
-               } else {
-                       ret = mtd_write_oob(nand, off, &ops);
-                       if (!ret)
-                               ret = nand_verify_page_oob(nand, &ops, off);
-               }
-
-               if (ret) {
-                       printf("%s: error at offset %llx, ret %d\n",
-                               __func__, (long long)off, ret);
-                       break;
-               }
-
-               addr += nand->writesize + nand->oobsize;
-               off += nand->writesize;
-       }
-
-       return ret;
-}
-
-/* Adjust a chip/partition size down for bad blocks so we don't
- * read/write past the end of a chip/partition by accident.
- */
-static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
-{
-       /* We grab the nand info object here fresh because this is usually
-        * called after arg_off_size() which can change the value of dev.
-        */
-       nand_info_t *nand = &nand_info[dev];
-       loff_t maxoffset = offset + *size;
-       int badblocks = 0;
-
-       /* count badblocks in NAND from offset to offset + size */
-       for (; offset < maxoffset; offset += nand->erasesize) {
-               if (nand_block_isbad(nand, offset))
-                       badblocks++;
-       }
-       /* adjust size if any bad blocks found */
-       if (badblocks) {
-               *size -= badblocks * nand->erasesize;
-               printf("size adjusted to 0x%llx (%d bad blocks)\n",
-                      (unsigned long long)*size, badblocks);
-       }
-}
-
-static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int i, ret = 0;
-       ulong addr;
-       loff_t off, size, maxsize;
-       char *cmd, *s;
-       nand_info_t *nand;
-#ifdef CONFIG_SYS_NAND_QUIET
-       int quiet = CONFIG_SYS_NAND_QUIET;
-#else
-       int quiet = 0;
-#endif
-       const char *quiet_str = getenv("quiet");
-       int dev = nand_curr_device;
-       int repeat = flag & CMD_FLAG_REPEAT;
-
-       /* at least two arguments please */
-       if (argc < 2)
-               goto usage;
-
-       if (quiet_str)
-               quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
-
-       cmd = argv[1];
-
-       /* Only "dump" is repeatable. */
-       if (repeat && strcmp(cmd, "dump"))
-               return 0;
-
-       if (strcmp(cmd, "info") == 0) {
-
-               putc('\n');
-               for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
-                       if (nand_info[i].name)
-                               nand_print_and_set_info(i);
-               }
-               return 0;
-       }
-
-       if (strcmp(cmd, "device") == 0) {
-               if (argc < 3) {
-                       putc('\n');
-                       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE)
-                               puts("no devices available\n");
-                       else
-                               nand_print_and_set_info(dev);
-                       return 0;
-               }
-
-               dev = (int)simple_strtoul(argv[2], NULL, 10);
-               set_dev(dev);
-
-               return 0;
-       }
-
-#ifdef CONFIG_ENV_OFFSET_OOB
-       /* this command operates only on the first nand device */
-       if (strcmp(cmd, "env.oob") == 0)
-               return do_nand_env_oob(cmdtp, argc - 1, argv + 1);
-#endif
-
-       /* The following commands operate on the current device, unless
-        * overridden by a partition specifier.  Note that if somehow the
-        * current device is invalid, it will have to be changed to a valid
-        * one before these commands can run, even if a partition specifier
-        * for another device is to be used.
-        */
-       if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
-           !nand_info[dev].name) {
-               puts("\nno devices available\n");
-               return 1;
-       }
-       nand = &nand_info[dev];
-
-       if (strcmp(cmd, "bad") == 0) {
-               printf("\nDevice %d bad blocks:\n", dev);
-               for (off = 0; off < nand->size; off += nand->erasesize)
-                       if (nand_block_isbad(nand, off))
-                               printf("  %08llx\n", (unsigned long long)off);
-               return 0;
-       }
-
-       /*
-        * Syntax is:
-        *   0    1     2       3    4
-        *   nand erase [clean] [off size]
-        */
-       if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) {
-               nand_erase_options_t opts;
-               /* "clean" at index 2 means request to write cleanmarker */
-               int clean = argc > 2 && !strcmp("clean", argv[2]);
-               int scrub_yes = argc > 2 && !strcmp("-y", argv[2]);
-               int o = (clean || scrub_yes) ? 3 : 2;
-               int scrub = !strncmp(cmd, "scrub", 5);
-               int spread = 0;
-               int args = 2;
-               const char *scrub_warn =
-                       "Warning: "
-                       "scrub option will erase all factory set bad blocks!\n"
-                       "         "
-                       "There is no reliable way to recover them.\n"
-                       "         "
-                       "Use this command only for testing purposes if you\n"
-                       "         "
-                       "are sure of what you are doing!\n"
-                       "\nReally scrub this NAND flash? <y/N>\n";
-
-               if (cmd[5] != 0) {
-                       if (!strcmp(&cmd[5], ".spread")) {
-                               spread = 1;
-                       } else if (!strcmp(&cmd[5], ".part")) {
-                               args = 1;
-                       } else if (!strcmp(&cmd[5], ".chip")) {
-                               args = 0;
-                       } else {
-                               goto usage;
-                       }
-               }
-
-               /*
-                * Don't allow missing arguments to cause full chip/partition
-                * erases -- easy to do accidentally, e.g. with a misspelled
-                * variable name.
-                */
-               if (argc != o + args)
-                       goto usage;
-
-               printf("\nNAND %s: ", cmd);
-               /* skip first two or three arguments, look for offset and size */
-               if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
-                                    &maxsize, MTD_DEV_TYPE_NAND,
-                                    nand_info[dev].size) != 0)
-                       return 1;
-
-               if (set_dev(dev))
-                       return 1;
-
-               nand = &nand_info[dev];
-
-               memset(&opts, 0, sizeof(opts));
-               opts.offset = off;
-               opts.length = size;
-               opts.jffs2  = clean;
-               opts.quiet  = quiet;
-               opts.spread = spread;
-
-               if (scrub) {
-                       if (scrub_yes) {
-                               opts.scrub = 1;
-                       } else {
-                               puts(scrub_warn);
-                               if (confirm_yesno()) {
-                                       opts.scrub = 1;
-                               } else {
-                                       puts("scrub aborted\n");
-                                       return 1;
-                               }
-                       }
-               }
-               ret = nand_erase_opts(nand, &opts);
-               printf("%s\n", ret ? "ERROR" : "OK");
-
-               return ret == 0 ? 0 : 1;
-       }
-
-       if (strncmp(cmd, "dump", 4) == 0) {
-               if (argc < 3)
-                       goto usage;
-
-               off = (int)simple_strtoul(argv[2], NULL, 16);
-               ret = nand_dump(nand, off, !strcmp(&cmd[4], ".oob"), repeat);
-
-               return ret == 0 ? 1 : 0;
-       }
-
-       if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
-               size_t rwsize;
-               ulong pagecount = 1;
-               int read;
-               int raw = 0;
-
-               if (argc < 4)
-                       goto usage;
-
-               addr = (ulong)simple_strtoul(argv[2], NULL, 16);
-
-               read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
-               printf("\nNAND %s: ", read ? "read" : "write");
-
-               s = strchr(cmd, '.');
-
-               if (s && !strcmp(s, ".raw")) {
-                       raw = 1;
-
-                       if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
-                                       MTD_DEV_TYPE_NAND,
-                                       nand_info[dev].size))
-                               return 1;
-
-                       if (set_dev(dev))
-                               return 1;
-
-                       nand = &nand_info[dev];
-
-                       if (argc > 4 && !str2long(argv[4], &pagecount)) {
-                               printf("'%s' is not a number\n", argv[4]);
-                               return 1;
-                       }
-
-                       if (pagecount * nand->writesize > size) {
-                               puts("Size exceeds partition or device limit\n");
-                               return -1;
-                       }
-
-                       rwsize = pagecount * (nand->writesize + nand->oobsize);
-               } else {
-                       if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
-                                            &size, &maxsize,
-                                            MTD_DEV_TYPE_NAND,
-                                            nand_info[dev].size) != 0)
-                               return 1;
-
-                       if (set_dev(dev))
-                               return 1;
-
-                       /* size is unspecified */
-                       if (argc < 5)
-                               adjust_size_for_badblocks(&size, off, dev);
-                       rwsize = size;
-               }
-
-               nand = &nand_info[dev];
-
-               if (!s || !strcmp(s, ".jffs2") ||
-                   !strcmp(s, ".e") || !strcmp(s, ".i")) {
-                       if (read)
-                               ret = nand_read_skip_bad(nand, off, &rwsize,
-                                                        NULL, maxsize,
-                                                        (u_char *)addr);
-                       else
-                               ret = nand_write_skip_bad(nand, off, &rwsize,
-                                                         NULL, maxsize,
-                                                         (u_char *)addr,
-                                                         WITH_WR_VERIFY);
-#ifdef CONFIG_CMD_NAND_TRIMFFS
-               } else if (!strcmp(s, ".trimffs")) {
-                       if (read) {
-                               printf("Unknown nand command suffix '%s'\n", s);
-                               return 1;
-                       }
-                       ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
-                                               maxsize, (u_char *)addr,
-                                               WITH_DROP_FFS | WITH_WR_VERIFY);
-#endif
-               } else if (!strcmp(s, ".oob")) {
-                       /* out-of-band data */
-                       mtd_oob_ops_t ops = {
-                               .oobbuf = (u8 *)addr,
-                               .ooblen = rwsize,
-                               .mode = MTD_OPS_RAW
-                       };
-
-                       if (read)
-                               ret = mtd_read_oob(nand, off, &ops);
-                       else
-                               ret = mtd_write_oob(nand, off, &ops);
-               } else if (raw) {
-                       ret = raw_access(nand, addr, off, pagecount, read);
-               } else {
-                       printf("Unknown nand command suffix '%s'.\n", s);
-                       return 1;
-               }
-
-               printf(" %zu bytes %s: %s\n", rwsize,
-                      read ? "read" : "written", ret ? "ERROR" : "OK");
-
-               return ret == 0 ? 0 : 1;
-       }
-
-#ifdef CONFIG_CMD_NAND_TORTURE
-       if (strcmp(cmd, "torture") == 0) {
-               if (argc < 3)
-                       goto usage;
-
-               if (!str2off(argv[2], &off)) {
-                       puts("Offset is not a valid number\n");
-                       return 1;
-               }
-
-               printf("\nNAND torture: device %d offset 0x%llx size 0x%x\n",
-                       dev, off, nand->erasesize);
-               ret = nand_torture(nand, off);
-               printf(" %s\n", ret ? "Failed" : "Passed");
-
-               return ret == 0 ? 0 : 1;
-       }
-#endif
-
-       if (strcmp(cmd, "markbad") == 0) {
-               argc -= 2;
-               argv += 2;
-
-               if (argc <= 0)
-                       goto usage;
-
-               while (argc > 0) {
-                       addr = simple_strtoul(*argv, NULL, 16);
-
-                       if (mtd_block_markbad(nand, addr)) {
-                               printf("block 0x%08lx NOT marked "
-                                       "as bad! ERROR %d\n",
-                                       addr, ret);
-                               ret = 1;
-                       } else {
-                               printf("block 0x%08lx successfully "
-                                       "marked as bad\n",
-                                       addr);
-                       }
-                       --argc;
-                       ++argv;
-               }
-               return ret;
-       }
-
-       if (strcmp(cmd, "biterr") == 0) {
-               /* todo */
-               return 1;
-       }
-
-#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
-       if (strcmp(cmd, "lock") == 0) {
-               int tight = 0;
-               int status = 0;
-               if (argc == 3) {
-                       if (!strcmp("tight", argv[2]))
-                               tight = 1;
-                       if (!strcmp("status", argv[2]))
-                               status = 1;
-               }
-               if (status) {
-                       do_nand_status(nand);
-               } else {
-                       if (!nand_lock(nand, tight)) {
-                               puts("NAND flash successfully locked\n");
-                       } else {
-                               puts("Error locking NAND flash\n");
-                               return 1;
-                       }
-               }
-               return 0;
-       }
-
-       if (strncmp(cmd, "unlock", 5) == 0) {
-               int allexcept = 0;
-
-               s = strchr(cmd, '.');
-
-               if (s && !strcmp(s, ".allexcept"))
-                       allexcept = 1;
-
-               if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
-                                    &maxsize, MTD_DEV_TYPE_NAND,
-                                    nand_info[dev].size) < 0)
-                       return 1;
-
-               if (set_dev(dev))
-                       return 1;
-
-               if (!nand_unlock(&nand_info[dev], off, size, allexcept)) {
-                       puts("NAND flash successfully unlocked\n");
-               } else {
-                       puts("Error unlocking NAND flash, "
-                            "write and erase will probably fail\n");
-                       return 1;
-               }
-               return 0;
-       }
-#endif
-
-usage:
-       return CMD_RET_USAGE;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char nand_help_text[] =
-       "info - show available NAND devices\n"
-       "nand device [dev] - show or set current device\n"
-       "nand read - addr off|partition size\n"
-       "nand write - addr off|partition size\n"
-       "    read/write 'size' bytes starting at offset 'off'\n"
-       "    to/from memory address 'addr', skipping bad blocks.\n"
-       "nand read.raw - addr off|partition [count]\n"
-       "nand write.raw - addr off|partition [count]\n"
-       "    Use read.raw/write.raw to avoid ECC and access the flash as-is.\n"
-#ifdef CONFIG_CMD_NAND_TRIMFFS
-       "nand write.trimffs - addr off|partition size\n"
-       "    write 'size' bytes starting at offset 'off' from memory address\n"
-       "    'addr', skipping bad blocks and dropping any pages at the end\n"
-       "    of eraseblocks that contain only 0xFF\n"
-#endif
-       "nand erase[.spread] [clean] off size - erase 'size' bytes "
-       "from offset 'off'\n"
-       "    With '.spread', erase enough for given file size, otherwise,\n"
-       "    'size' includes skipped bad blocks.\n"
-       "nand erase.part [clean] partition - erase entire mtd partition'\n"
-       "nand erase.chip [clean] - erase entire chip'\n"
-       "nand bad - show bad blocks\n"
-       "nand dump[.oob] off - dump page\n"
-#ifdef CONFIG_CMD_NAND_TORTURE
-       "nand torture off - torture block at offset\n"
-#endif
-       "nand scrub [-y] off size | scrub.part partition | scrub.chip\n"
-       "    really clean NAND erasing bad blocks (UNSAFE)\n"
-       "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
-       "nand biterr off - make a bit error at offset (UNSAFE)"
-#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
-       "\n"
-       "nand lock [tight] [status]\n"
-       "    bring nand to lock state or display locked pages\n"
-       "nand unlock[.allexcept] [offset] [size] - unlock section"
-#endif
-#ifdef CONFIG_ENV_OFFSET_OOB
-       "\n"
-       "nand env.oob - environment offset in OOB of block 0 of"
-       "    first device.\n"
-       "nand env.oob set off|partition - set enviromnent offset\n"
-       "nand env.oob get - get environment offset"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       nand, CONFIG_SYS_MAXARGS, 1, do_nand,
-       "NAND sub-system", nand_help_text
-);
-
-static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
-                          ulong offset, ulong addr, char *cmd)
-{
-       int r;
-       char *s;
-       size_t cnt;
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       image_header_t *hdr;
-#endif
-#if defined(CONFIG_FIT)
-       const void *fit_hdr = NULL;
-#endif
-
-       s = strchr(cmd, '.');
-       if (s != NULL &&
-           (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) {
-               printf("Unknown nand load suffix '%s'\n", s);
-               bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
-               return 1;
-       }
-
-       printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
-
-       cnt = nand->writesize;
-       r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
-                       (u_char *)addr);
-       if (r) {
-               puts("** Read error\n");
-               bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ);
-
-       switch (genimg_get_format ((void *)addr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-               hdr = (image_header_t *)addr;
-
-               bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
-               image_print_contents (hdr);
-
-               cnt = image_get_image_size (hdr);
-               break;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               fit_hdr = (const void *)addr;
-               puts ("Fit image detected...\n");
-
-               cnt = fit_get_size (fit_hdr);
-               break;
-#endif
-       default:
-               bootstage_error(BOOTSTAGE_ID_NAND_TYPE);
-               puts ("** Unknown image type\n");
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
-
-       r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
-                       (u_char *)addr);
-       if (r) {
-               puts("** Read error\n");
-               bootstage_error(BOOTSTAGE_ID_NAND_READ);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_READ);
-
-#if defined(CONFIG_FIT)
-       /* This cannot be done earlier, we need complete FIT image in RAM first */
-       if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
-               if (!fit_check_format (fit_hdr)) {
-                       bootstage_error(BOOTSTAGE_ID_NAND_FIT_READ);
-                       puts ("** Bad FIT image format\n");
-                       return 1;
-               }
-               bootstage_mark(BOOTSTAGE_ID_NAND_FIT_READ_OK);
-               fit_print_contents (fit_hdr);
-       }
-#endif
-
-       /* Loading ok, update default load address */
-
-       load_addr = addr;
-
-       return bootm_maybe_autostart(cmdtp, cmd);
-}
-
-static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       char *boot_device = NULL;
-       int idx;
-       ulong addr, offset = 0;
-#if defined(CONFIG_CMD_MTDPARTS)
-       struct mtd_device *dev;
-       struct part_info *part;
-       u8 pnum;
-
-       if (argc >= 2) {
-               char *p = (argc == 2) ? argv[1] : argv[2];
-               if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
-                   (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
-                       if (dev->id->type != MTD_DEV_TYPE_NAND) {
-                               puts("Not a NAND device\n");
-                               return 1;
-                       }
-                       if (argc > 3)
-                               goto usage;
-                       if (argc == 3)
-                               addr = simple_strtoul(argv[1], NULL, 16);
-                       else
-                               addr = CONFIG_SYS_LOAD_ADDR;
-                       return nand_load_image(cmdtp, &nand_info[dev->id->num],
-                                              part->offset, addr, argv[0]);
-               }
-       }
-#endif
-
-       bootstage_mark(BOOTSTAGE_ID_NAND_PART);
-       switch (argc) {
-       case 1:
-               addr = CONFIG_SYS_LOAD_ADDR;
-               boot_device = getenv("bootdevice");
-               break;
-       case 2:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               boot_device = getenv("bootdevice");
-               break;
-       case 3:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               boot_device = argv[2];
-               break;
-       case 4:
-               addr = simple_strtoul(argv[1], NULL, 16);
-               boot_device = argv[2];
-               offset = simple_strtoul(argv[3], NULL, 16);
-               break;
-       default:
-#if defined(CONFIG_CMD_MTDPARTS)
-usage:
-#endif
-               bootstage_error(BOOTSTAGE_ID_NAND_SUFFIX);
-               return CMD_RET_USAGE;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_SUFFIX);
-
-       if (!boot_device) {
-               puts("\n** No boot device **\n");
-               bootstage_error(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_BOOT_DEVICE);
-
-       idx = simple_strtoul(boot_device, NULL, 16);
-
-       if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx].name) {
-               printf("\n** Device %d not available\n", idx);
-               bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
-               return 1;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
-
-       return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
-}
-
-U_BOOT_CMD(nboot, 4, 1, do_nandboot,
-       "boot from NAND device",
-       "[partition] | [[[loadAddr] dev] offset]"
-);
diff --git a/common/cmd_net.c b/common/cmd_net.c
deleted file mode 100644 (file)
index b2f3c7b..0000000
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <command.h>
-#include <net.h>
-
-static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
-
-static int do_bootp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return netboot_common(BOOTP, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       bootp,  3,      1,      do_bootp,
-       "boot image via network using BOOTP/TFTP protocol",
-       "[loadAddress] [[hostIPaddr:]bootfilename]"
-);
-
-int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret;
-
-       bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
-       ret = netboot_common(TFTPGET, cmdtp, argc, argv);
-       bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
-       return ret;
-}
-
-U_BOOT_CMD(
-       tftpboot,       3,      1,      do_tftpb,
-       "boot image via network using TFTP protocol",
-       "[loadAddress] [[hostIPaddr:]bootfilename]"
-);
-
-#ifdef CONFIG_CMD_TFTPPUT
-int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return netboot_common(TFTPPUT, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       tftpput,        4,      1,      do_tftpput,
-       "TFTP put command, for uploading files to a server",
-       "Address Size [[hostIPaddr:]filename]"
-);
-#endif
-
-#ifdef CONFIG_CMD_TFTPSRV
-static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       return netboot_common(TFTPSRV, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       tftpsrv,        2,      1,      do_tftpsrv,
-       "act as a TFTP server and boot the first received file",
-       "[loadAddress]\n"
-       "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
-       "The transfer is aborted if a transfer has not been started after\n"
-       "about 50 seconds or if Ctrl-C is pressed."
-);
-#endif
-
-
-#ifdef CONFIG_CMD_RARP
-int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return netboot_common(RARP, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       rarpboot,       3,      1,      do_rarpb,
-       "boot image via network using RARP/TFTP protocol",
-       "[loadAddress] [[hostIPaddr:]bootfilename]"
-);
-#endif
-
-#if defined(CONFIG_CMD_DHCP)
-static int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return netboot_common(DHCP, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       dhcp,   3,      1,      do_dhcp,
-       "boot image via network using DHCP/TFTP protocol",
-       "[loadAddress] [[hostIPaddr:]bootfilename]"
-);
-#endif
-
-#if defined(CONFIG_CMD_NFS)
-static int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return netboot_common(NFS, cmdtp, argc, argv);
-}
-
-U_BOOT_CMD(
-       nfs,    3,      1,      do_nfs,
-       "boot image via network using NFS protocol",
-       "[loadAddress] [[hostIPaddr:]bootfilename]"
-);
-#endif
-
-static void netboot_update_env(void)
-{
-       char tmp[22];
-
-       if (net_gateway.s_addr) {
-               ip_to_string(net_gateway, tmp);
-               setenv("gatewayip", tmp);
-       }
-
-       if (net_netmask.s_addr) {
-               ip_to_string(net_netmask, tmp);
-               setenv("netmask", tmp);
-       }
-
-       if (net_hostname[0])
-               setenv("hostname", net_hostname);
-
-       if (net_root_path[0])
-               setenv("rootpath", net_root_path);
-
-       if (net_ip.s_addr) {
-               ip_to_string(net_ip, tmp);
-               setenv("ipaddr", tmp);
-       }
-#if !defined(CONFIG_BOOTP_SERVERIP)
-       /*
-        * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams()
-        * could have set it
-        */
-       if (net_server_ip.s_addr) {
-               ip_to_string(net_server_ip, tmp);
-               setenv("serverip", tmp);
-       }
-#endif
-       if (net_dns_server.s_addr) {
-               ip_to_string(net_dns_server, tmp);
-               setenv("dnsip", tmp);
-       }
-#if defined(CONFIG_BOOTP_DNS2)
-       if (net_dns_server2.s_addr) {
-               ip_to_string(net_dns_server2, tmp);
-               setenv("dnsip2", tmp);
-       }
-#endif
-       if (net_nis_domain[0])
-               setenv("domain", net_nis_domain);
-
-#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
-       if (net_ntp_time_offset) {
-               sprintf(tmp, "%d", net_ntp_time_offset);
-               setenv("timeoffset", tmp);
-       }
-#endif
-#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
-       if (net_ntp_server.s_addr) {
-               ip_to_string(net_ntp_server, tmp);
-               setenv("ntpserverip", tmp);
-       }
-#endif
-}
-
-static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
-               char * const argv[])
-{
-       char *s;
-       char *end;
-       int   rcode = 0;
-       int   size;
-       ulong addr;
-
-       /* pre-set load_addr */
-       s = getenv("loadaddr");
-       if (s != NULL)
-               load_addr = simple_strtoul(s, NULL, 16);
-
-       switch (argc) {
-       case 1:
-               break;
-
-       case 2: /*
-                * Only one arg - accept two forms:
-                * Just load address, or just boot file name. The latter
-                * form must be written in a format which can not be
-                * mis-interpreted as a valid number.
-                */
-               addr = simple_strtoul(argv[1], &end, 16);
-               if (end == (argv[1] + strlen(argv[1])))
-                       load_addr = addr;
-               else
-                       copy_filename(net_boot_file_name, argv[1],
-                                     sizeof(net_boot_file_name));
-               break;
-
-       case 3:
-               load_addr = simple_strtoul(argv[1], NULL, 16);
-               copy_filename(net_boot_file_name, argv[2],
-                             sizeof(net_boot_file_name));
-
-               break;
-
-#ifdef CONFIG_CMD_TFTPPUT
-       case 4:
-               if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
-                   strict_strtoul(argv[2], 16, &save_size) < 0) {
-                       printf("Invalid address/size\n");
-                       return CMD_RET_USAGE;
-               }
-               copy_filename(net_boot_file_name, argv[3],
-                             sizeof(net_boot_file_name));
-               break;
-#endif
-       default:
-               bootstage_error(BOOTSTAGE_ID_NET_START);
-               return CMD_RET_USAGE;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NET_START);
-
-       size = net_loop(proto);
-       if (size < 0) {
-               bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
-               return CMD_RET_FAILURE;
-       }
-       bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
-
-       /* net_loop ok, update environment */
-       netboot_update_env();
-
-       /* done if no file was loaded (no errors though) */
-       if (size == 0) {
-               bootstage_error(BOOTSTAGE_ID_NET_LOADED);
-               return CMD_RET_SUCCESS;
-       }
-
-       /* flush cache */
-       flush_cache(load_addr, size);
-
-       bootstage_mark(BOOTSTAGE_ID_NET_LOADED);
-
-       rcode = bootm_maybe_autostart(cmdtp, argv[0]);
-
-       if (rcode == CMD_RET_SUCCESS)
-               bootstage_mark(BOOTSTAGE_ID_NET_DONE);
-       else
-               bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
-       return rcode;
-}
-
-#if defined(CONFIG_CMD_PING)
-static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       net_ping_ip = string_to_ip(argv[1]);
-       if (net_ping_ip.s_addr == 0)
-               return CMD_RET_USAGE;
-
-       if (net_loop(PING) < 0) {
-               printf("ping failed; host %s is not alive\n", argv[1]);
-               return CMD_RET_FAILURE;
-       }
-
-       printf("host %s is alive\n", argv[1]);
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       ping,   2,      1,      do_ping,
-       "send ICMP ECHO_REQUEST to network host",
-       "pingAddress"
-);
-#endif
-
-#if defined(CONFIG_CMD_CDP)
-
-static void cdp_update_env(void)
-{
-       char tmp[16];
-
-       if (cdp_appliance_vlan != htons(-1)) {
-               printf("CDP offered appliance VLAN %d\n",
-                      ntohs(cdp_appliance_vlan));
-               vlan_to_string(cdp_appliance_vlan, tmp);
-               setenv("vlan", tmp);
-               net_our_vlan = cdp_appliance_vlan;
-       }
-
-       if (cdp_native_vlan != htons(-1)) {
-               printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
-               vlan_to_string(cdp_native_vlan, tmp);
-               setenv("nvlan", tmp);
-               net_native_vlan = cdp_native_vlan;
-       }
-}
-
-int do_cdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int r;
-
-       r = net_loop(CDP);
-       if (r < 0) {
-               printf("cdp failed; perhaps not a CISCO switch?\n");
-               return CMD_RET_FAILURE;
-       }
-
-       cdp_update_env();
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       cdp,    1,      1,      do_cdp,
-       "Perform CDP network configuration",
-       "\n"
-);
-#endif
-
-#if defined(CONFIG_CMD_SNTP)
-int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *toff;
-
-       if (argc < 2) {
-               net_ntp_server = getenv_ip("ntpserverip");
-               if (net_ntp_server.s_addr == 0) {
-                       printf("ntpserverip not set\n");
-                       return CMD_RET_FAILURE;
-               }
-       } else {
-               net_ntp_server = string_to_ip(argv[1]);
-               if (net_ntp_server.s_addr == 0) {
-                       printf("Bad NTP server IP address\n");
-                       return CMD_RET_FAILURE;
-               }
-       }
-
-       toff = getenv("timeoffset");
-       if (toff == NULL)
-               net_ntp_time_offset = 0;
-       else
-               net_ntp_time_offset = simple_strtol(toff, NULL, 10);
-
-       if (net_loop(SNTP) < 0) {
-               printf("SNTP failed: host %pI4 not responding\n",
-                      &net_ntp_server);
-               return CMD_RET_FAILURE;
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       sntp,   2,      1,      do_sntp,
-       "synchronize RTC via network",
-       "[NTP server IP]\n"
-);
-#endif
-
-#if defined(CONFIG_CMD_DNS)
-int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc == 1)
-               return CMD_RET_USAGE;
-
-       /*
-        * We should check for a valid hostname:
-        * - Each label must be between 1 and 63 characters long
-        * - the entire hostname has a maximum of 255 characters
-        * - only the ASCII letters 'a' through 'z' (case-insensitive),
-        *   the digits '0' through '9', and the hyphen
-        * - cannot begin or end with a hyphen
-        * - no other symbols, punctuation characters, or blank spaces are
-        *   permitted
-        * but hey - this is a minimalist implmentation, so only check length
-        * and let the name server deal with things.
-        */
-       if (strlen(argv[1]) >= 255) {
-               printf("dns error: hostname too long\n");
-               return CMD_RET_FAILURE;
-       }
-
-       net_dns_resolve = argv[1];
-
-       if (argc == 3)
-               net_dns_env_var = argv[2];
-       else
-               net_dns_env_var = NULL;
-
-       if (net_loop(DNS) < 0) {
-               printf("dns lookup of %s failed, check setup\n", argv[1]);
-               return CMD_RET_FAILURE;
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       dns,    3,      1,      do_dns,
-       "lookup the IP of a hostname",
-       "hostname [envvar]"
-);
-
-#endif /* CONFIG_CMD_DNS */
-
-#if defined(CONFIG_CMD_LINK_LOCAL)
-static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       char tmp[22];
-
-       if (net_loop(LINKLOCAL) < 0)
-               return CMD_RET_FAILURE;
-
-       net_gateway.s_addr = 0;
-       ip_to_string(net_gateway, tmp);
-       setenv("gatewayip", tmp);
-
-       ip_to_string(net_netmask, tmp);
-       setenv("netmask", tmp);
-
-       ip_to_string(net_ip, tmp);
-       setenv("ipaddr", tmp);
-       setenv("llipaddr", tmp); /* store this for next time */
-
-       return CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       linklocal,      1,      1,      do_link_local,
-       "acquire a network IP address using the link-local protocol",
-       ""
-);
-
-#endif  /* CONFIG_CMD_LINK_LOCAL */
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
deleted file mode 100644 (file)
index 5ae9d9d..0000000
+++ /dev/null
@@ -1,1298 +0,0 @@
-/*
- * (C) Copyright 2000-2013
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
- * Andreas Heppel <aheppel@sysgo.de>
- *
- * Copyright 2011 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Support for persistent environment data
- *
- * The "environment" is stored on external storage as a list of '\0'
- * terminated "name=value" strings. The end of the list is marked by
- * a double '\0'. The environment is preceeded by a 32 bit CRC over
- * the data part and, in case of redundant environment, a byte of
- * flags.
- *
- * This linearized representation will also be used before
- * relocation, i. e. as long as we don't have a full C runtime
- * environment. After that, we use a hash table.
- */
-
-#include <common.h>
-#include <cli.h>
-#include <command.h>
-#include <console.h>
-#include <environment.h>
-#include <search.h>
-#include <errno.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <watchdog.h>
-#include <linux/stddef.h>
-#include <asm/byteorder.h>
-#include <asm/io.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#if    !defined(CONFIG_ENV_IS_IN_EEPROM)       && \
-       !defined(CONFIG_ENV_IS_IN_FLASH)        && \
-       !defined(CONFIG_ENV_IS_IN_DATAFLASH)    && \
-       !defined(CONFIG_ENV_IS_IN_MMC)          && \
-       !defined(CONFIG_ENV_IS_IN_FAT)          && \
-       !defined(CONFIG_ENV_IS_IN_NAND)         && \
-       !defined(CONFIG_ENV_IS_IN_NVRAM)        && \
-       !defined(CONFIG_ENV_IS_IN_ONENAND)      && \
-       !defined(CONFIG_ENV_IS_IN_SPI_FLASH)    && \
-       !defined(CONFIG_ENV_IS_IN_REMOTE)       && \
-       !defined(CONFIG_ENV_IS_IN_UBI)          && \
-       !defined(CONFIG_ENV_IS_NOWHERE)
-# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
-#endif
-
-/*
- * Maximum expected input data size for import command
- */
-#define        MAX_ENV_SIZE    (1 << 20)       /* 1 MiB */
-
-/*
- * This variable is incremented on each do_env_set(), so it can
- * be used via get_env_id() as an indication, if the environment
- * has changed or not. So it is possible to reread an environment
- * variable only if the environment was changed ... done so for
- * example in NetInitLoop()
- */
-static int env_id = 1;
-
-int get_env_id(void)
-{
-       return env_id;
-}
-
-#ifndef CONFIG_SPL_BUILD
-/*
- * Command interface: print one or all environment variables
- *
- * Returns 0 in case of error, or length of printed string
- */
-static int env_print(char *name, int flag)
-{
-       char *res = NULL;
-       ssize_t len;
-
-       if (name) {             /* print a single name */
-               ENTRY e, *ep;
-
-               e.key = name;
-               e.data = NULL;
-               hsearch_r(e, FIND, &ep, &env_htab, flag);
-               if (ep == NULL)
-                       return 0;
-               len = printf("%s=%s\n", ep->key, ep->data);
-               return len;
-       }
-
-       /* print whole list */
-       len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
-
-       if (len > 0) {
-               puts(res);
-               free(res);
-               return len;
-       }
-
-       /* should never happen */
-       printf("## Error: cannot export environment\n");
-       return 0;
-}
-
-static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       int i;
-       int rcode = 0;
-       int env_flag = H_HIDE_DOT;
-
-       if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
-               argc--;
-               argv++;
-               env_flag &= ~H_HIDE_DOT;
-       }
-
-       if (argc == 1) {
-               /* print all env vars */
-               rcode = env_print(NULL, env_flag);
-               if (!rcode)
-                       return 1;
-               printf("\nEnvironment size: %d/%ld bytes\n",
-                       rcode, (ulong)ENV_SIZE);
-               return 0;
-       }
-
-       /* print selected env vars */
-       env_flag &= ~H_HIDE_DOT;
-       for (i = 1; i < argc; ++i) {
-               int rc = env_print(argv[i], env_flag);
-               if (!rc) {
-                       printf("## Error: \"%s\" not defined\n", argv[i]);
-                       ++rcode;
-               }
-       }
-
-       return rcode;
-}
-
-#ifdef CONFIG_CMD_GREPENV
-static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
-{
-       char *res = NULL;
-       int len, grep_how, grep_what;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       grep_how  = H_MATCH_SUBSTR;     /* default: substring search    */
-       grep_what = H_MATCH_BOTH;       /* default: grep names and values */
-
-       while (--argc > 0 && **++argv == '-') {
-               char *arg = *argv;
-               while (*++arg) {
-                       switch (*arg) {
-#ifdef CONFIG_REGEX
-                       case 'e':               /* use regex matching */
-                               grep_how  = H_MATCH_REGEX;
-                               break;
-#endif
-                       case 'n':               /* grep for name */
-                               grep_what = H_MATCH_KEY;
-                               break;
-                       case 'v':               /* grep for value */
-                               grep_what = H_MATCH_DATA;
-                               break;
-                       case 'b':               /* grep for both */
-                               grep_what = H_MATCH_BOTH;
-                               break;
-                       case '-':
-                               goto DONE;
-                       default:
-                               return CMD_RET_USAGE;
-                       }
-               }
-       }
-
-DONE:
-       len = hexport_r(&env_htab, '\n',
-                       flag | grep_what | grep_how,
-                       &res, 0, argc, argv);
-
-       if (len > 0) {
-               puts(res);
-               free(res);
-       }
-
-       if (len < 2)
-               return 1;
-
-       return 0;
-}
-#endif
-#endif /* CONFIG_SPL_BUILD */
-
-/*
- * Set a new environment variable,
- * or replace or delete an existing one.
- */
-static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
-{
-       int   i, len;
-       char  *name, *value, *s;
-       ENTRY e, *ep;
-
-       debug("Initial value for argc=%d\n", argc);
-       while (argc > 1 && **(argv + 1) == '-') {
-               char *arg = *++argv;
-
-               --argc;
-               while (*++arg) {
-                       switch (*arg) {
-                       case 'f':               /* force */
-                               env_flag |= H_FORCE;
-                               break;
-                       default:
-                               return CMD_RET_USAGE;
-                       }
-               }
-       }
-       debug("Final value for argc=%d\n", argc);
-       name = argv[1];
-       value = argv[2];
-
-       if (strchr(name, '=')) {
-               printf("## Error: illegal character '='"
-                      "in variable name \"%s\"\n", name);
-               return 1;
-       }
-
-       env_id++;
-
-       /* Delete only ? */
-       if (argc < 3 || argv[2] == NULL) {
-               int rc = hdelete_r(name, &env_htab, env_flag);
-               return !rc;
-       }
-
-       /*
-        * Insert / replace new value
-        */
-       for (i = 2, len = 0; i < argc; ++i)
-               len += strlen(argv[i]) + 1;
-
-       value = malloc(len);
-       if (value == NULL) {
-               printf("## Can't malloc %d bytes\n", len);
-               return 1;
-       }
-       for (i = 2, s = value; i < argc; ++i) {
-               char *v = argv[i];
-
-               while ((*s++ = *v++) != '\0')
-                       ;
-               *(s - 1) = ' ';
-       }
-       if (s != value)
-               *--s = '\0';
-
-       e.key   = name;
-       e.data  = value;
-       hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
-       free(value);
-       if (!ep) {
-               printf("## Error inserting \"%s\" variable, errno=%d\n",
-                       name, errno);
-               return 1;
-       }
-
-       return 0;
-}
-
-int setenv(const char *varname, const char *varvalue)
-{
-       const char * const argv[4] = { "setenv", varname, varvalue, NULL };
-
-       /* before import into hashtable */
-       if (!(gd->flags & GD_FLG_ENV_READY))
-               return 1;
-
-       if (varvalue == NULL || varvalue[0] == '\0')
-               return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
-       else
-               return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
-}
-
-/**
- * Set an environment variable to an integer value
- *
- * @param varname      Environment variable to set
- * @param value                Value to set it to
- * @return 0 if ok, 1 on error
- */
-int setenv_ulong(const char *varname, ulong value)
-{
-       /* TODO: this should be unsigned */
-       char *str = simple_itoa(value);
-
-       return setenv(varname, str);
-}
-
-/**
- * Set an environment variable to an value in hex
- *
- * @param varname      Environment variable to set
- * @param value                Value to set it to
- * @return 0 if ok, 1 on error
- */
-int setenv_hex(const char *varname, ulong value)
-{
-       char str[17];
-
-       sprintf(str, "%lx", value);
-       return setenv(varname, str);
-}
-
-ulong getenv_hex(const char *varname, ulong default_val)
-{
-       const char *s;
-       ulong value;
-       char *endp;
-
-       s = getenv(varname);
-       if (s)
-               value = simple_strtoul(s, &endp, 16);
-       if (!s || endp == s)
-               return default_val;
-
-       return value;
-}
-
-#ifndef CONFIG_SPL_BUILD
-static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       return _do_env_set(flag, argc, argv, H_INTERACTIVE);
-}
-
-/*
- * Prompt for environment variable
- */
-#if defined(CONFIG_CMD_ASKENV)
-int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char message[CONFIG_SYS_CBSIZE];
-       int i, len, pos, size;
-       char *local_args[4];
-       char *endptr;
-
-       local_args[0] = argv[0];
-       local_args[1] = argv[1];
-       local_args[2] = NULL;
-       local_args[3] = NULL;
-
-       /*
-        * Check the syntax:
-        *
-        * env_ask envname [message1 ...] [size]
-        */
-       if (argc == 1)
-               return CMD_RET_USAGE;
-
-       /*
-        * We test the last argument if it can be converted
-        * into a decimal number.  If yes, we assume it's
-        * the size.  Otherwise we echo it as part of the
-        * message.
-        */
-       i = simple_strtoul(argv[argc - 1], &endptr, 10);
-       if (*endptr != '\0') {                  /* no size */
-               size = CONFIG_SYS_CBSIZE - 1;
-       } else {                                /* size given */
-               size = i;
-               --argc;
-       }
-
-       if (argc <= 2) {
-               sprintf(message, "Please enter '%s': ", argv[1]);
-       } else {
-               /* env_ask envname message1 ... messagen [size] */
-               for (i = 2, pos = 0; i < argc; i++) {
-                       if (pos)
-                               message[pos++] = ' ';
-
-                       strcpy(message + pos, argv[i]);
-                       pos += strlen(argv[i]);
-               }
-               message[pos++] = ' ';
-               message[pos] = '\0';
-       }
-
-       if (size >= CONFIG_SYS_CBSIZE)
-               size = CONFIG_SYS_CBSIZE - 1;
-
-       if (size <= 0)
-               return 1;
-
-       /* prompt for input */
-       len = cli_readline(message);
-
-       if (size < len)
-               console_buffer[size] = '\0';
-
-       len = 2;
-       if (console_buffer[0] != '\0') {
-               local_args[2] = console_buffer;
-               len = 3;
-       }
-
-       /* Continue calling setenv code */
-       return _do_env_set(flag, len, local_args, H_INTERACTIVE);
-}
-#endif
-
-#if defined(CONFIG_CMD_ENV_CALLBACK)
-static int print_static_binding(const char *var_name, const char *callback_name,
-                               void *priv)
-{
-       printf("\t%-20s %-20s\n", var_name, callback_name);
-
-       return 0;
-}
-
-static int print_active_callback(ENTRY *entry)
-{
-       struct env_clbk_tbl *clbkp;
-       int i;
-       int num_callbacks;
-
-       if (entry->callback == NULL)
-               return 0;
-
-       /* look up the callback in the linker-list */
-       num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
-       for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
-            i < num_callbacks;
-            i++, clbkp++) {
-#if defined(CONFIG_NEEDS_MANUAL_RELOC)
-               if (entry->callback == clbkp->callback + gd->reloc_off)
-#else
-               if (entry->callback == clbkp->callback)
-#endif
-                       break;
-       }
-
-       if (i == num_callbacks)
-               /* this should probably never happen, but just in case... */
-               printf("\t%-20s %p\n", entry->key, entry->callback);
-       else
-               printf("\t%-20s %-20s\n", entry->key, clbkp->name);
-
-       return 0;
-}
-
-/*
- * Print the callbacks available and what they are bound to
- */
-int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct env_clbk_tbl *clbkp;
-       int i;
-       int num_callbacks;
-
-       /* Print the available callbacks */
-       puts("Available callbacks:\n");
-       puts("\tCallback Name\n");
-       puts("\t-------------\n");
-       num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
-       for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
-            i < num_callbacks;
-            i++, clbkp++)
-               printf("\t%s\n", clbkp->name);
-       puts("\n");
-
-       /* Print the static bindings that may exist */
-       puts("Static callback bindings:\n");
-       printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
-       printf("\t%-20s %-20s\n", "-------------", "-------------");
-       env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL);
-       puts("\n");
-
-       /* walk through each variable and print the callback if it has one */
-       puts("Active callback bindings:\n");
-       printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
-       printf("\t%-20s %-20s\n", "-------------", "-------------");
-       hwalk_r(&env_htab, print_active_callback);
-       return 0;
-}
-#endif
-
-#if defined(CONFIG_CMD_ENV_FLAGS)
-static int print_static_flags(const char *var_name, const char *flags,
-                             void *priv)
-{
-       enum env_flags_vartype type = env_flags_parse_vartype(flags);
-       enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
-
-       printf("\t%-20s %-20s %-20s\n", var_name,
-               env_flags_get_vartype_name(type),
-               env_flags_get_varaccess_name(access));
-
-       return 0;
-}
-
-static int print_active_flags(ENTRY *entry)
-{
-       enum env_flags_vartype type;
-       enum env_flags_varaccess access;
-
-       if (entry->flags == 0)
-               return 0;
-
-       type = (enum env_flags_vartype)
-               (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
-       access = env_flags_parse_varaccess_from_binflags(entry->flags);
-       printf("\t%-20s %-20s %-20s\n", entry->key,
-               env_flags_get_vartype_name(type),
-               env_flags_get_varaccess_name(access));
-
-       return 0;
-}
-
-/*
- * Print the flags available and what variables have flags
- */
-int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       /* Print the available variable types */
-       printf("Available variable type flags (position %d):\n",
-               ENV_FLAGS_VARTYPE_LOC);
-       puts("\tFlag\tVariable Type Name\n");
-       puts("\t----\t------------------\n");
-       env_flags_print_vartypes();
-       puts("\n");
-
-       /* Print the available variable access types */
-       printf("Available variable access flags (position %d):\n",
-               ENV_FLAGS_VARACCESS_LOC);
-       puts("\tFlag\tVariable Access Name\n");
-       puts("\t----\t--------------------\n");
-       env_flags_print_varaccess();
-       puts("\n");
-
-       /* Print the static flags that may exist */
-       puts("Static flags:\n");
-       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
-               "Variable Access");
-       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
-               "---------------");
-       env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL);
-       puts("\n");
-
-       /* walk through each variable and print the flags if non-default */
-       puts("Active flags:\n");
-       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
-               "Variable Access");
-       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
-               "---------------");
-       hwalk_r(&env_htab, print_active_flags);
-       return 0;
-}
-#endif
-
-/*
- * Interactively edit an environment variable
- */
-#if defined(CONFIG_CMD_EDITENV)
-static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       char buffer[CONFIG_SYS_CBSIZE];
-       char *init_val;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* before import into hashtable */
-       if (!(gd->flags & GD_FLG_ENV_READY))
-               return 1;
-
-       /* Set read buffer to initial value or empty sting */
-       init_val = getenv(argv[1]);
-       if (init_val)
-               snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val);
-       else
-               buffer[0] = '\0';
-
-       if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
-               return 1;
-
-       if (buffer[0] == '\0') {
-               const char * const _argv[3] = { "setenv", argv[1], NULL };
-
-               return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE);
-       } else {
-               const char * const _argv[4] = { "setenv", argv[1], buffer,
-                       NULL };
-
-               return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE);
-       }
-}
-#endif /* CONFIG_CMD_EDITENV */
-#endif /* CONFIG_SPL_BUILD */
-
-/*
- * Look up variable from environment,
- * return address of storage for that variable,
- * or NULL if not found
- */
-char *getenv(const char *name)
-{
-       if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
-               ENTRY e, *ep;
-
-               WATCHDOG_RESET();
-
-               e.key   = name;
-               e.data  = NULL;
-               hsearch_r(e, FIND, &ep, &env_htab, 0);
-
-               return ep ? ep->data : NULL;
-       }
-
-       /* restricted capabilities before import */
-       if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
-               return (char *)(gd->env_buf);
-
-       return NULL;
-}
-
-/*
- * Look up variable from environment for restricted C runtime env.
- */
-int getenv_f(const char *name, char *buf, unsigned len)
-{
-       int i, nxt;
-
-       for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
-               int val, n;
-
-               for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
-                       if (nxt >= CONFIG_ENV_SIZE)
-                               return -1;
-               }
-
-               val = envmatch((uchar *)name, i);
-               if (val < 0)
-                       continue;
-
-               /* found; copy out */
-               for (n = 0; n < len; ++n, ++buf) {
-                       *buf = env_get_char(val++);
-                       if (*buf == '\0')
-                               return n;
-               }
-
-               if (n)
-                       *--buf = '\0';
-
-               printf("env_buf [%d bytes] too small for value of \"%s\"\n",
-                       len, name);
-
-               return n;
-       }
-
-       return -1;
-}
-
-/**
- * Decode the integer value of an environment variable and return it.
- *
- * @param name         Name of environemnt variable
- * @param base         Number base to use (normally 10, or 16 for hex)
- * @param default_val  Default value to return if the variable is not
- *                     found
- * @return the decoded value, or default_val if not found
- */
-ulong getenv_ulong(const char *name, int base, ulong default_val)
-{
-       /*
-        * We can use getenv() here, even before relocation, since the
-        * environment variable value is an integer and thus short.
-        */
-       const char *str = getenv(name);
-
-       return str ? simple_strtoul(str, NULL, base) : default_val;
-}
-
-#ifndef CONFIG_SPL_BUILD
-#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       printf("Saving Environment to %s...\n", env_name_spec);
-
-       return saveenv() ? 1 : 0;
-}
-
-U_BOOT_CMD(
-       saveenv, 1, 0,  do_env_save,
-       "save environment variables to persistent storage",
-       ""
-);
-#endif
-#endif /* CONFIG_SPL_BUILD */
-
-
-/*
- * Match a name / name=value pair
- *
- * s1 is either a simple 'name', or a 'name=value' pair.
- * i2 is the environment index for a 'name2=value2' pair.
- * If the names match, return the index for the value2, else -1.
- */
-int envmatch(uchar *s1, int i2)
-{
-       if (s1 == NULL)
-               return -1;
-
-       while (*s1 == env_get_char(i2++))
-               if (*s1++ == '=')
-                       return i2;
-
-       if (*s1 == '\0' && env_get_char(i2-1) == '=')
-               return i2;
-
-       return -1;
-}
-
-#ifndef CONFIG_SPL_BUILD
-static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
-                         int argc, char * const argv[])
-{
-       int all = 0, flag = 0;
-
-       debug("Initial value for argc=%d\n", argc);
-       while (--argc > 0 && **++argv == '-') {
-               char *arg = *argv;
-
-               while (*++arg) {
-                       switch (*arg) {
-                       case 'a':               /* default all */
-                               all = 1;
-                               break;
-                       case 'f':               /* force */
-                               flag |= H_FORCE;
-                               break;
-                       default:
-                               return cmd_usage(cmdtp);
-                       }
-               }
-       }
-       debug("Final value for argc=%d\n", argc);
-       if (all && (argc == 0)) {
-               /* Reset the whole environment */
-               set_default_env("## Resetting to default environment\n");
-               return 0;
-       }
-       if (!all && (argc > 0)) {
-               /* Reset individual variables */
-               set_default_vars(argc, argv);
-               return 0;
-       }
-
-       return cmd_usage(cmdtp);
-}
-
-static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
-{
-       int env_flag = H_INTERACTIVE;
-       int ret = 0;
-
-       debug("Initial value for argc=%d\n", argc);
-       while (argc > 1 && **(argv + 1) == '-') {
-               char *arg = *++argv;
-
-               --argc;
-               while (*++arg) {
-                       switch (*arg) {
-                       case 'f':               /* force */
-                               env_flag |= H_FORCE;
-                               break;
-                       default:
-                               return CMD_RET_USAGE;
-                       }
-               }
-       }
-       debug("Final value for argc=%d\n", argc);
-
-       env_id++;
-
-       while (--argc > 0) {
-               char *name = *++argv;
-
-               if (!hdelete_r(name, &env_htab, env_flag))
-                       ret = 1;
-       }
-
-       return ret;
-}
-
-#ifdef CONFIG_CMD_EXPORTENV
-/*
- * env export [-t | -b | -c] [-s size] addr [var ...]
- *     -t:     export as text format; if size is given, data will be
- *             padded with '\0' bytes; if not, one terminating '\0'
- *             will be added (which is included in the "filesize"
- *             setting so you can for exmple copy this to flash and
- *             keep the termination).
- *     -b:     export as binary format (name=value pairs separated by
- *             '\0', list end marked by double "\0\0")
- *     -c:     export as checksum protected environment format as
- *             used for example by "saveenv" command
- *     -s size:
- *             size of output buffer
- *     addr:   memory address where environment gets stored
- *     var...  List of variable names that get included into the
- *             export. Without arguments, the whole environment gets
- *             exported.
- *
- * With "-c" and size is NOT given, then the export command will
- * format the data as currently used for the persistent storage,
- * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
- * prepend a valid CRC32 checksum and, in case of resundant
- * environment, a "current" redundancy flag. If size is given, this
- * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
- * checksum and redundancy flag will be inserted.
- *
- * With "-b" and "-t", always only the real data (including a
- * terminating '\0' byte) will be written; here the optional size
- * argument will be used to make sure not to overflow the user
- * provided buffer; the command will abort if the size is not
- * sufficient. Any remainign space will be '\0' padded.
- *
- * On successful return, the variable "filesize" will be set.
- * Note that filesize includes the trailing/terminating '\0' byte(s).
- *
- * Usage szenario:  create a text snapshot/backup of the current settings:
- *
- *     => env export -t 100000
- *     => era ${backup_addr} +${filesize}
- *     => cp.b 100000 ${backup_addr} ${filesize}
- *
- * Re-import this snapshot, deleting all other settings:
- *
- *     => env import -d -t ${backup_addr}
- */
-static int do_env_export(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
-{
-       char    buf[32];
-       ulong   addr;
-       char    *ptr, *cmd, *res;
-       size_t  size = 0;
-       ssize_t len;
-       env_t   *envp;
-       char    sep = '\n';
-       int     chk = 0;
-       int     fmt = 0;
-
-       cmd = *argv;
-
-       while (--argc > 0 && **++argv == '-') {
-               char *arg = *argv;
-               while (*++arg) {
-                       switch (*arg) {
-                       case 'b':               /* raw binary format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\0';
-                               break;
-                       case 'c':               /* external checksum format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\0';
-                               chk = 1;
-                               break;
-                       case 's':               /* size given */
-                               if (--argc <= 0)
-                                       return cmd_usage(cmdtp);
-                               size = simple_strtoul(*++argv, NULL, 16);
-                               goto NXTARG;
-                       case 't':               /* text format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\n';
-                               break;
-                       default:
-                               return CMD_RET_USAGE;
-                       }
-               }
-NXTARG:                ;
-       }
-
-       if (argc < 1)
-               return CMD_RET_USAGE;
-
-       addr = simple_strtoul(argv[0], NULL, 16);
-       ptr = map_sysmem(addr, size);
-
-       if (size)
-               memset(ptr, '\0', size);
-
-       argc--;
-       argv++;
-
-       if (sep) {              /* export as text file */
-               len = hexport_r(&env_htab, sep,
-                               H_MATCH_KEY | H_MATCH_IDENT,
-                               &ptr, size, argc, argv);
-               if (len < 0) {
-                       error("Cannot export environment: errno = %d\n", errno);
-                       return 1;
-               }
-               sprintf(buf, "%zX", (size_t)len);
-               setenv("filesize", buf);
-
-               return 0;
-       }
-
-       envp = (env_t *)ptr;
-
-       if (chk)                /* export as checksum protected block */
-               res = (char *)envp->data;
-       else                    /* export as raw binary data */
-               res = ptr;
-
-       len = hexport_r(&env_htab, '\0',
-                       H_MATCH_KEY | H_MATCH_IDENT,
-                       &res, ENV_SIZE, argc, argv);
-       if (len < 0) {
-               error("Cannot export environment: errno = %d\n", errno);
-               return 1;
-       }
-
-       if (chk) {
-               envp->crc = crc32(0, envp->data, ENV_SIZE);
-#ifdef CONFIG_ENV_ADDR_REDUND
-               envp->flags = ACTIVE_FLAG;
-#endif
-       }
-       setenv_hex("filesize", len + offsetof(env_t, data));
-
-       return 0;
-
-sep_err:
-       printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
-       return 1;
-}
-#endif
-
-#ifdef CONFIG_CMD_IMPORTENV
-/*
- * env import [-d] [-t [-r] | -b | -c] addr [size]
- *     -d:     delete existing environment before importing;
- *             otherwise overwrite / append to existion definitions
- *     -t:     assume text format; either "size" must be given or the
- *             text data must be '\0' terminated
- *     -r:     handle CRLF like LF, that means exported variables with
- *             a content which ends with \r won't get imported. Used
- *             to import text files created with editors which are using CRLF
- *             for line endings. Only effective in addition to -t.
- *     -b:     assume binary format ('\0' separated, "\0\0" terminated)
- *     -c:     assume checksum protected environment format
- *     addr:   memory address to read from
- *     size:   length of input data; if missing, proper '\0'
- *             termination is mandatory
- */
-static int do_env_import(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
-{
-       ulong   addr;
-       char    *cmd, *ptr;
-       char    sep = '\n';
-       int     chk = 0;
-       int     fmt = 0;
-       int     del = 0;
-       int     crlf_is_lf = 0;
-       size_t  size;
-
-       cmd = *argv;
-
-       while (--argc > 0 && **++argv == '-') {
-               char *arg = *argv;
-               while (*++arg) {
-                       switch (*arg) {
-                       case 'b':               /* raw binary format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\0';
-                               break;
-                       case 'c':               /* external checksum format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\0';
-                               chk = 1;
-                               break;
-                       case 't':               /* text format */
-                               if (fmt++)
-                                       goto sep_err;
-                               sep = '\n';
-                               break;
-                       case 'r':               /* handle CRLF like LF */
-                               crlf_is_lf = 1;
-                               break;
-                       case 'd':
-                               del = 1;
-                               break;
-                       default:
-                               return CMD_RET_USAGE;
-                       }
-               }
-       }
-
-       if (argc < 1)
-               return CMD_RET_USAGE;
-
-       if (!fmt)
-               printf("## Warning: defaulting to text format\n");
-
-       if (sep != '\n' && crlf_is_lf )
-               crlf_is_lf = 0;
-
-       addr = simple_strtoul(argv[0], NULL, 16);
-       ptr = map_sysmem(addr, 0);
-
-       if (argc == 2) {
-               size = simple_strtoul(argv[1], NULL, 16);
-       } else if (argc == 1 && chk) {
-               puts("## Error: external checksum format must pass size\n");
-               return CMD_RET_FAILURE;
-       } else {
-               char *s = ptr;
-
-               size = 0;
-
-               while (size < MAX_ENV_SIZE) {
-                       if ((*s == sep) && (*(s+1) == '\0'))
-                               break;
-                       ++s;
-                       ++size;
-               }
-               if (size == MAX_ENV_SIZE) {
-                       printf("## Warning: Input data exceeds %d bytes"
-                               " - truncated\n", MAX_ENV_SIZE);
-               }
-               size += 2;
-               printf("## Info: input data size = %zu = 0x%zX\n", size, size);
-       }
-
-       if (chk) {
-               uint32_t crc;
-               env_t *ep = (env_t *)ptr;
-
-               size -= offsetof(env_t, data);
-               memcpy(&crc, &ep->crc, sizeof(crc));
-
-               if (crc32(0, ep->data, size) != crc) {
-                       puts("## Error: bad CRC, import failed\n");
-                       return 1;
-               }
-               ptr = (char *)ep->data;
-       }
-
-       if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
-                       crlf_is_lf, 0, NULL) == 0) {
-               error("Environment import failed: errno = %d\n", errno);
-               return 1;
-       }
-       gd->flags |= GD_FLG_ENV_READY;
-
-       return 0;
-
-sep_err:
-       printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
-               cmd);
-       return 1;
-}
-#endif
-
-#if defined(CONFIG_CMD_ENV_EXISTS)
-static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       ENTRY e, *ep;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       e.key = argv[1];
-       e.data = NULL;
-       hsearch_r(e, FIND, &ep, &env_htab, 0);
-
-       return (ep == NULL) ? 1 : 0;
-}
-#endif
-
-/*
- * New command line interface: "env" command with subcommands
- */
-static cmd_tbl_t cmd_env_sub[] = {
-#if defined(CONFIG_CMD_ASKENV)
-       U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
-       U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
-#if defined(CONFIG_CMD_EDITENV)
-       U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
-#endif
-#if defined(CONFIG_CMD_ENV_CALLBACK)
-       U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
-#endif
-#if defined(CONFIG_CMD_ENV_FLAGS)
-       U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
-#endif
-#if defined(CONFIG_CMD_EXPORTENV)
-       U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
-#endif
-#if defined(CONFIG_CMD_GREPENV)
-       U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
-#endif
-#if defined(CONFIG_CMD_IMPORTENV)
-       U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
-#if defined(CONFIG_CMD_RUN)
-       U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
-#endif
-#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-       U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
-#endif
-       U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
-#if defined(CONFIG_CMD_ENV_EXISTS)
-       U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
-#endif
-};
-
-#if defined(CONFIG_NEEDS_MANUAL_RELOC)
-void env_reloc(void)
-{
-       fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
-}
-#endif
-
-static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *cp;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* drop initial "env" arg */
-       argc--;
-       argv++;
-
-       cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
-
-       if (cp)
-               return cp->cmd(cmdtp, flag, argc, argv);
-
-       return CMD_RET_USAGE;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char env_help_text[] =
-#if defined(CONFIG_CMD_ASKENV)
-       "ask name [message] [size] - ask for environment variable\nenv "
-#endif
-#if defined(CONFIG_CMD_ENV_CALLBACK)
-       "callbacks - print callbacks and their associated variables\nenv "
-#endif
-       "default [-f] -a - [forcibly] reset default environment\n"
-       "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
-       "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
-#if defined(CONFIG_CMD_EDITENV)
-       "env edit name - edit environment variable\n"
-#endif
-#if defined(CONFIG_CMD_ENV_EXISTS)
-       "env exists name - tests for existence of variable\n"
-#endif
-#if defined(CONFIG_CMD_EXPORTENV)
-       "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
-#endif
-#if defined(CONFIG_CMD_ENV_FLAGS)
-       "env flags - print variables that have non-default flags\n"
-#endif
-#if defined(CONFIG_CMD_GREPENV)
-#ifdef CONFIG_REGEX
-       "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
-#else
-       "env grep [-n | -v | -b] string [...] - search environment\n"
-#endif
-#endif
-#if defined(CONFIG_CMD_IMPORTENV)
-       "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
-#endif
-       "env print [-a | name ...] - print environment\n"
-#if defined(CONFIG_CMD_RUN)
-       "env run var [...] - run commands in an environment variable\n"
-#endif
-#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-       "env save - save environment\n"
-#endif
-       "env set [-f] name [arg ...]\n";
-#endif
-
-U_BOOT_CMD(
-       env, CONFIG_SYS_MAXARGS, 1, do_env,
-       "environment handling commands", env_help_text
-);
-
-/*
- * Old command line interface, kept for compatibility
- */
-
-#if defined(CONFIG_CMD_EDITENV)
-U_BOOT_CMD_COMPLETE(
-       editenv, 2, 0,  do_env_edit,
-       "edit environment variable",
-       "name\n"
-       "    - edit environment variable 'name'",
-       var_complete
-);
-#endif
-
-U_BOOT_CMD_COMPLETE(
-       printenv, CONFIG_SYS_MAXARGS, 1,        do_env_print,
-       "print environment variables",
-       "[-a]\n    - print [all] values of all environment variables\n"
-       "printenv name ...\n"
-       "    - print value of environment variable 'name'",
-       var_complete
-);
-
-#ifdef CONFIG_CMD_GREPENV
-U_BOOT_CMD_COMPLETE(
-       grepenv, CONFIG_SYS_MAXARGS, 0,  do_env_grep,
-       "search environment variables",
-#ifdef CONFIG_REGEX
-       "[-e] [-n | -v | -b] string ...\n"
-#else
-       "[-n | -v | -b] string ...\n"
-#endif
-       "    - list environment name=value pairs matching 'string'\n"
-#ifdef CONFIG_REGEX
-       "      \"-e\": enable regular expressions;\n"
-#endif
-       "      \"-n\": search variable names; \"-v\": search values;\n"
-       "      \"-b\": search both names and values (default)",
-       var_complete
-);
-#endif
-
-U_BOOT_CMD_COMPLETE(
-       setenv, CONFIG_SYS_MAXARGS, 0,  do_env_set,
-       "set environment variables",
-       "[-f] name value ...\n"
-       "    - [forcibly] set environment variable 'name' to 'value ...'\n"
-       "setenv [-f] name\n"
-       "    - [forcibly] delete environment variable 'name'",
-       var_complete
-);
-
-#if defined(CONFIG_CMD_ASKENV)
-
-U_BOOT_CMD(
-       askenv, CONFIG_SYS_MAXARGS,     1,      do_env_ask,
-       "get environment variables from stdin",
-       "name [message] [size]\n"
-       "    - get environment variable 'name' from stdin (max 'size' chars)"
-);
-#endif
-
-#if defined(CONFIG_CMD_RUN)
-U_BOOT_CMD_COMPLETE(
-       run,    CONFIG_SYS_MAXARGS,     1,      do_run,
-       "run commands in an environment variable",
-       "var [...]\n"
-       "    - run the commands in the environment variable(s) 'var'",
-       var_complete
-);
-#endif
-#endif /* CONFIG_SPL_BUILD */
diff --git a/common/cmd_onenand.c b/common/cmd_onenand.c
deleted file mode 100644 (file)
index feab01a..0000000
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- *  U-Boot command for OneNAND support
- *
- *  Copyright (C) 2005-2008 Samsung Electronics
- *  Kyungmin Park <kyungmin.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-
-#include <linux/compat.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/onenand.h>
-
-#include <asm/io.h>
-
-static struct mtd_info *mtd;
-
-static loff_t next_ofs;
-static loff_t skip_ofs;
-
-static int arg_off_size_onenand(int argc, char * const argv[], ulong *off,
-                               size_t *size)
-{
-       if (argc >= 1) {
-               if (!(str2long(argv[0], off))) {
-                       printf("'%s' is not a number\n", argv[0]);
-                       return -1;
-               }
-       } else {
-               *off = 0;
-       }
-
-       if (argc >= 2) {
-               if (!(str2long(argv[1], (ulong *)size))) {
-                       printf("'%s' is not a number\n", argv[1]);
-                       return -1;
-               }
-       } else {
-               *size = mtd->size - *off;
-       }
-
-       if ((*off + *size) > mtd->size) {
-               printf("total chip size (0x%llx) exceeded!\n", mtd->size);
-               return -1;
-       }
-
-       if (*size == mtd->size)
-               puts("whole chip\n");
-       else
-               printf("offset 0x%lx, size 0x%x\n", *off, *size);
-
-       return 0;
-}
-
-static int onenand_block_read(loff_t from, size_t len,
-                             size_t *retlen, u_char *buf, int oob)
-{
-       struct onenand_chip *this = mtd->priv;
-       int blocks = (int) len >> this->erase_shift;
-       int blocksize = (1 << this->erase_shift);
-       loff_t ofs = from;
-       struct mtd_oob_ops ops = {
-               .retlen         = 0,
-       };
-       int ret;
-
-       if (oob)
-               ops.ooblen = blocksize;
-       else
-               ops.len = blocksize;
-
-       while (blocks) {
-               ret = mtd_block_isbad(mtd, ofs);
-               if (ret) {
-                       printk("Bad blocks %d at 0x%x\n",
-                              (u32)(ofs >> this->erase_shift), (u32)ofs);
-                       ofs += blocksize;
-                       continue;
-               }
-
-               if (oob)
-                       ops.oobbuf = buf;
-               else
-                       ops.datbuf = buf;
-
-               ops.retlen = 0;
-               ret = mtd_read_oob(mtd, ofs, &ops);
-               if (ret) {
-                       printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
-                       ofs += blocksize;
-                       continue;
-               }
-               ofs += blocksize;
-               buf += blocksize;
-               blocks--;
-               *retlen += ops.retlen;
-       }
-
-       return 0;
-}
-
-static int onenand_write_oneblock_withoob(loff_t to, const u_char * buf,
-                                         size_t *retlen)
-{
-       struct mtd_oob_ops ops = {
-               .len = mtd->writesize,
-               .ooblen = mtd->oobsize,
-               .mode = MTD_OPS_AUTO_OOB,
-       };
-       int page, ret = 0;
-       for (page = 0; page < (mtd->erasesize / mtd->writesize); page ++) {
-               ops.datbuf = (u_char *)buf;
-               buf += mtd->writesize;
-               ops.oobbuf = (u_char *)buf;
-               buf += mtd->oobsize;
-               ret = mtd_write_oob(mtd, to, &ops);
-               if (ret)
-                       break;
-               to += mtd->writesize;
-       }
-
-       *retlen = (ret) ? 0 : mtd->erasesize;
-       return ret;
-}
-
-static int onenand_block_write(loff_t to, size_t len,
-                              size_t *retlen, const u_char * buf, int withoob)
-{
-       struct onenand_chip *this = mtd->priv;
-       int blocks = len >> this->erase_shift;
-       int blocksize = (1 << this->erase_shift);
-       loff_t ofs;
-       size_t _retlen = 0;
-       int ret;
-
-       if (to == next_ofs) {
-               next_ofs = to + len;
-               to += skip_ofs;
-       } else {
-               next_ofs = to + len;
-               skip_ofs = 0;
-       }
-       ofs = to;
-
-       while (blocks) {
-               ret = mtd_block_isbad(mtd, ofs);
-               if (ret) {
-                       printk("Bad blocks %d at 0x%x\n",
-                              (u32)(ofs >> this->erase_shift), (u32)ofs);
-                       skip_ofs += blocksize;
-                       goto next;
-               }
-
-               if (!withoob)
-                       ret = mtd_write(mtd, ofs, blocksize, &_retlen, buf);
-               else
-                       ret = onenand_write_oneblock_withoob(ofs, buf, &_retlen);
-               if (ret) {
-                       printk("Write failed 0x%x, %d", (u32)ofs, ret);
-                       skip_ofs += blocksize;
-                       goto next;
-               }
-
-               buf += blocksize;
-               blocks--;
-               *retlen += _retlen;
-next:
-               ofs += blocksize;
-       }
-
-       return 0;
-}
-
-static int onenand_block_erase(u32 start, u32 size, int force)
-{
-       struct onenand_chip *this = mtd->priv;
-       struct erase_info instr = {
-               .callback       = NULL,
-       };
-       loff_t ofs;
-       int ret;
-       int blocksize = 1 << this->erase_shift;
-
-       for (ofs = start; ofs < (start + size); ofs += blocksize) {
-               ret = mtd_block_isbad(mtd, ofs);
-               if (ret && !force) {
-                       printf("Skip erase bad block %d at 0x%x\n",
-                              (u32)(ofs >> this->erase_shift), (u32)ofs);
-                       continue;
-               }
-
-               instr.addr = ofs;
-               instr.len = blocksize;
-               instr.priv = force;
-               instr.mtd = mtd;
-               ret = mtd_erase(mtd, &instr);
-               if (ret) {
-                       printf("erase failed block %d at 0x%x\n",
-                              (u32)(ofs >> this->erase_shift), (u32)ofs);
-                       continue;
-               }
-       }
-
-       return 0;
-}
-
-static int onenand_block_test(u32 start, u32 size)
-{
-       struct onenand_chip *this = mtd->priv;
-       struct erase_info instr = {
-               .callback       = NULL,
-               .priv           = 0,
-       };
-
-       int blocks;
-       loff_t ofs;
-       int blocksize = 1 << this->erase_shift;
-       int start_block, end_block;
-       size_t retlen;
-       u_char *buf;
-       u_char *verify_buf;
-       int ret;
-
-       buf = malloc(blocksize);
-       if (!buf) {
-               printf("Not enough malloc space available!\n");
-               return -1;
-       }
-
-       verify_buf = malloc(blocksize);
-       if (!verify_buf) {
-               printf("Not enough malloc space available!\n");
-               return -1;
-       }
-
-       start_block = start >> this->erase_shift;
-       end_block = (start + size) >> this->erase_shift;
-
-       /* Protect boot-loader from badblock testing */
-       if (start_block < 2)
-               start_block = 2;
-
-       if (end_block > (mtd->size >> this->erase_shift))
-               end_block = mtd->size >> this->erase_shift;
-
-       blocks = start_block;
-       ofs = start;
-       while (blocks < end_block) {
-               printf("\rTesting block %d at 0x%x", (u32)(ofs >> this->erase_shift), (u32)ofs);
-
-               ret = mtd_block_isbad(mtd, ofs);
-               if (ret) {
-                       printf("Skip erase bad block %d at 0x%x\n",
-                              (u32)(ofs >> this->erase_shift), (u32)ofs);
-                       goto next;
-               }
-
-               instr.addr = ofs;
-               instr.len = blocksize;
-               ret = mtd_erase(mtd, &instr);
-               if (ret) {
-                       printk("Erase failed 0x%x, %d\n", (u32)ofs, ret);
-                       goto next;
-               }
-
-               ret = mtd_write(mtd, ofs, blocksize, &retlen, buf);
-               if (ret) {
-                       printk("Write failed 0x%x, %d\n", (u32)ofs, ret);
-                       goto next;
-               }
-
-               ret = mtd_read(mtd, ofs, blocksize, &retlen, verify_buf);
-               if (ret) {
-                       printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
-                       goto next;
-               }
-
-               if (memcmp(buf, verify_buf, blocksize))
-                       printk("\nRead/Write test failed at 0x%x\n", (u32)ofs);
-
-next:
-               ofs += blocksize;
-               blocks++;
-       }
-       printf("...Done\n");
-
-       free(buf);
-       free(verify_buf);
-
-       return 0;
-}
-
-static int onenand_dump(struct mtd_info *mtd, ulong off, int only_oob)
-{
-       int i;
-       u_char *datbuf, *oobbuf, *p;
-       struct mtd_oob_ops ops;
-       loff_t addr;
-
-       datbuf = malloc(mtd->writesize + mtd->oobsize);
-       oobbuf = malloc(mtd->oobsize);
-       if (!datbuf || !oobbuf) {
-               puts("No memory for page buffer\n");
-               return 1;
-       }
-       off &= ~(mtd->writesize - 1);
-       addr = (loff_t) off;
-       memset(&ops, 0, sizeof(ops));
-       ops.datbuf = datbuf;
-       ops.oobbuf = oobbuf;
-       ops.len = mtd->writesize;
-       ops.ooblen = mtd->oobsize;
-       ops.retlen = 0;
-       i = mtd_read_oob(mtd, addr, &ops);
-       if (i < 0) {
-               printf("Error (%d) reading page %08lx\n", i, off);
-               free(datbuf);
-               free(oobbuf);
-               return 1;
-       }
-       printf("Page %08lx dump:\n", off);
-       i = mtd->writesize >> 4;
-       p = datbuf;
-
-       while (i--) {
-               if (!only_oob)
-                       printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
-                              "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
-                              p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
-                              p[8], p[9], p[10], p[11], p[12], p[13], p[14],
-                              p[15]);
-               p += 16;
-       }
-       puts("OOB:\n");
-       i = mtd->oobsize >> 3;
-       p = oobbuf;
-
-       while (i--) {
-               printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
-                      p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-               p += 8;
-       }
-       free(datbuf);
-       free(oobbuf);
-
-       return 0;
-}
-
-static int do_onenand_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       printf("%s\n", mtd->name);
-       return 0;
-}
-
-static int do_onenand_bad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong ofs;
-
-       mtd = &onenand_mtd;
-       /* Currently only one OneNAND device is supported */
-       printf("\nDevice %d bad blocks:\n", 0);
-       for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) {
-               if (mtd_block_isbad(mtd, ofs))
-                       printf("  %08x\n", (u32)ofs);
-       }
-
-       return 0;
-}
-
-static int do_onenand_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       char *s;
-       int oob = 0;
-       ulong addr, ofs;
-       size_t len;
-       int ret = 0;
-       size_t retlen = 0;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       s = strchr(argv[0], '.');
-       if ((s != NULL) && (!strcmp(s, ".oob")))
-               oob = 1;
-
-       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
-
-       printf("\nOneNAND read: ");
-       if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0)
-               return 1;
-
-       ret = onenand_block_read(ofs, len, &retlen, (u8 *)addr, oob);
-
-       printf(" %d bytes read: %s\n", retlen, ret ? "ERROR" : "OK");
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_onenand_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr, ofs;
-       size_t len;
-       int ret = 0, withoob = 0;
-       size_t retlen = 0;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       if (strncmp(argv[0] + 6, "yaffs", 5) == 0)
-               withoob = 1;
-
-       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
-
-       printf("\nOneNAND write: ");
-       if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0)
-               return 1;
-
-       ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr, withoob);
-
-       printf(" %d bytes written: %s\n", retlen, ret ? "ERROR" : "OK");
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_onenand_erase(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong ofs;
-       int ret = 0;
-       size_t len;
-       int force;
-
-       /*
-        * Syntax is:
-        *   0       1     2       3    4
-        *   onenand erase [force] [off size]
-        */
-       argc--;
-       argv++;
-       if (argc)
-       {
-               if (!strcmp("force", argv[0]))
-               {
-                       force = 1;
-                       argc--;
-                       argv++;
-               }
-       }
-       printf("\nOneNAND erase: ");
-
-       /* skip first two or three arguments, look for offset and size */
-       if (arg_off_size_onenand(argc, argv, &ofs, &len) != 0)
-               return 1;
-
-       ret = onenand_block_erase(ofs, len, force);
-
-       printf("%s\n", ret ? "ERROR" : "OK");
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_onenand_test(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong ofs;
-       int ret = 0;
-       size_t len;
-
-       /*
-        * Syntax is:
-        *   0       1     2       3    4
-        *   onenand test [force] [off size]
-        */
-
-       printf("\nOneNAND test: ");
-
-       /* skip first two or three arguments, look for offset and size */
-       if (arg_off_size_onenand(argc - 1, argv + 1, &ofs, &len) != 0)
-               return 1;
-
-       ret = onenand_block_test(ofs, len);
-
-       printf("%s\n", ret ? "ERROR" : "OK");
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_onenand_dump(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong ofs;
-       int ret = 0;
-       char *s;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       s = strchr(argv[0], '.');
-       ofs = (int)simple_strtoul(argv[1], NULL, 16);
-
-       if (s != NULL && strcmp(s, ".oob") == 0)
-               ret = onenand_dump(mtd, ofs, 1);
-       else
-               ret = onenand_dump(mtd, ofs, 0);
-
-       return ret == 0 ? 1 : 0;
-}
-
-static int do_onenand_markbad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       int ret = 0;
-       ulong addr;
-
-       argc -= 2;
-       argv += 2;
-
-       if (argc <= 0)
-               return CMD_RET_USAGE;
-
-       while (argc > 0) {
-               addr = simple_strtoul(*argv, NULL, 16);
-
-               if (mtd_block_markbad(mtd, addr)) {
-                       printf("block 0x%08lx NOT marked "
-                               "as bad! ERROR %d\n",
-                               addr, ret);
-                       ret = 1;
-               } else {
-                       printf("block 0x%08lx successfully "
-                               "marked as bad\n",
-                               addr);
-               }
-               --argc;
-               ++argv;
-       }
-       return ret;
-}
-
-static cmd_tbl_t cmd_onenand_sub[] = {
-       U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", ""),
-       U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""),
-       U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""),
-       U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""),
-       U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", ""),
-       U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""),
-       U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""),
-       U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""),
-       U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad, "", ""),
-};
-
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-void onenand_reloc(void) {
-       fixup_cmdtable(cmd_onenand_sub, ARRAY_SIZE(cmd_onenand_sub));
-}
-#endif
-
-static int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *c;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       mtd = &onenand_mtd;
-
-       /* Strip off leading 'onenand' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], &cmd_onenand_sub[0], ARRAY_SIZE(cmd_onenand_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       onenand,        CONFIG_SYS_MAXARGS,     1,      do_onenand,
-       "OneNAND sub-system",
-       "info - show available OneNAND devices\n"
-       "onenand bad - show bad blocks\n"
-       "onenand read[.oob] addr off size\n"
-       "onenand write[.yaffs] addr off size\n"
-       "    read/write 'size' bytes starting at offset 'off'\n"
-       "    to/from memory address 'addr', skipping bad blocks.\n"
-       "onenand erase [force] [off size] - erase 'size' bytes from\n"
-       "onenand test [off size] - test 'size' bytes from\n"
-       "    offset 'off' (entire device if not specified)\n"
-       "onenand dump[.oob] off - dump page\n"
-       "onenand markbad off [...] - mark bad block(s) at offset (UNSAFE)"
-);
diff --git a/common/cmd_otp.c b/common/cmd_otp.c
deleted file mode 100644 (file)
index 10c1475..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * cmd_otp.c - interface to Blackfin on-chip One-Time-Programmable memory
- *
- * Copyright (c) 2007-2008 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-/* There are 512 128-bit "pages" (0x000 through 0x1FF).
- * The pages are accessable as 64-bit "halfpages" (an upper and lower half).
- * The pages are not part of the memory map.  There is an OTP controller which
- * handles scanning in/out of bits.  While access is done through OTP MMRs,
- * the bootrom provides C-callable helper functions to handle the interaction.
- */
-
-#include <config.h>
-#include <common.h>
-#include <command.h>
-#include <console.h>
-
-#include <asm/blackfin.h>
-#include <asm/clock.h>
-#include <asm/mach-common/bits/otp.h>
-
-static const char *otp_strerror(uint32_t err)
-{
-       switch (err) {
-       case 0:                   return "no error";
-       case OTP_WRITE_ERROR:     return "OTP fuse write error";
-       case OTP_READ_ERROR:      return "OTP fuse read error";
-       case OTP_ACC_VIO_ERROR:   return "invalid OTP address";
-       case OTP_DATA_MULT_ERROR: return "multiple bad bits detected";
-       case OTP_ECC_MULT_ERROR:  return "error in ECC bits";
-       case OTP_PREV_WR_ERROR:   return "space already written";
-       case OTP_DATA_SB_WARN:    return "single bad bit in half page";
-       case OTP_ECC_SB_WARN:     return "single bad bit in ECC";
-       default:                  return "unknown error";
-       }
-}
-
-#define lowup(x) ((x) % 2 ? "upper" : "lower")
-
-static int check_voltage(void)
-{
-       /* Make sure voltage limits are within datasheet spec */
-       uint16_t vr_ctl = bfin_read_VR_CTL();
-
-#ifdef __ADSPBF54x__
-       /* 0.9V <= VDDINT <= 1.1V */
-       if ((vr_ctl & 0xc) && (vr_ctl & 0xc0) == 0xc0)
-               return 1;
-#else
-       /* for the parts w/out qualification yet */
-       (void)vr_ctl;
-#endif
-
-       return 0;
-}
-
-static void set_otp_timing(bool write)
-{
-       static uint32_t timing;
-       if (!timing) {
-               uint32_t tp1, tp2, tp3;
-               /* OTP_TP1 = 1000 / sclk_period (in nanoseconds)
-                * OTP_TP1 = 1000 / (1 / get_sclk() * 10^9)
-                * OTP_TP1 = (1000 * get_sclk()) / 10^9
-                * OTP_TP1 = get_sclk() / 10^6
-                */
-               tp1 = get_sclk() / 1000000;
-               /* OTP_TP2 = 400 / (2 * sclk_period)
-                * OTP_TP2 = 400 / (2 * 1 / get_sclk() * 10^9)
-                * OTP_TP2 = (400 * get_sclk()) / (2 * 10^9)
-                * OTP_TP2 = (2 * get_sclk()) / 10^7
-                */
-               tp2 = (2 * get_sclk() / 10000000) << 8;
-               /* OTP_TP3 = magic constant */
-               tp3 = (0x1401) << 15;
-               timing = tp1 | tp2 | tp3;
-       }
-
-       bfrom_OtpCommand(OTP_INIT, write ? timing : timing & ~(-1 << 15));
-}
-
-int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *cmd;
-       uint32_t ret, base_flags;
-       bool prompt_user, force_read;
-       uint32_t (*otp_func)(uint32_t page, uint32_t flags, uint64_t *page_content);
-
-       if (argc < 4) {
- usage:
-               return CMD_RET_USAGE;
-       }
-
-       prompt_user = false;
-       base_flags = 0;
-       cmd = argv[1];
-       if (!strcmp(cmd, "read"))
-               otp_func = bfrom_OtpRead;
-       else if (!strcmp(cmd, "dump")) {
-               otp_func = bfrom_OtpRead;
-               force_read = true;
-       } else if (!strcmp(cmd, "write")) {
-               otp_func = bfrom_OtpWrite;
-               base_flags = OTP_CHECK_FOR_PREV_WRITE;
-               if (!strcmp(argv[2], "--force")) {
-                       argv++;
-                       --argc;
-               } else
-                       prompt_user = false;
-       } else if (!strcmp(cmd, "lock")) {
-               if (argc != 4)
-                       goto usage;
-               otp_func = bfrom_OtpWrite;
-               base_flags = OTP_LOCK;
-       } else
-               goto usage;
-
-       uint64_t *addr = (uint64_t *)simple_strtoul(argv[2], NULL, 16);
-       uint32_t page = simple_strtoul(argv[3], NULL, 16);
-       uint32_t flags;
-       size_t i, count;
-       ulong half;
-
-       if (argc > 4)
-               count = simple_strtoul(argv[4], NULL, 16);
-       else
-               count = 2;
-
-       if (argc > 5) {
-               half = simple_strtoul(argv[5], NULL, 16);
-               if (half != 0 && half != 1) {
-                       puts("Error: 'half' can only be '0' or '1'\n");
-                       goto usage;
-               }
-       } else
-               half = 0;
-
-       /* "otp lock" has slightly different semantics */
-       if (base_flags & OTP_LOCK) {
-               count = page;
-               page = (uint32_t)addr;
-               addr = NULL;
-       }
-
-       /* do to the nature of OTP, make sure users are sure */
-       if (prompt_user) {
-               printf(
-                       "Writing one time programmable memory\n"
-                       "Make sure your operating voltages and temperature are within spec\n"
-                       "   source address:  0x%p\n"
-                       "   OTP destination: %s page 0x%03X - %s page 0x%03lX\n"
-                       "   number to write: %lu halfpages\n"
-                       " type \"YES\" (no quotes) to confirm: ",
-                       addr,
-                       lowup(half), page,
-                       lowup(half + count - 1), page + (half + count - 1) / 2,
-                       half + count
-               );
-               if (!confirm_yesno()) {
-                       printf(" Aborting\n");
-                       return 1;
-               }
-       }
-
-       printf("OTP memory %s: addr 0x%p  page 0x%03X  count %zu ... ",
-               cmd, addr, page, count);
-
-       set_otp_timing(otp_func == bfrom_OtpWrite);
-       if (otp_func == bfrom_OtpWrite && check_voltage()) {
-               puts("ERROR: VDDINT voltage is out of spec for writing\n");
-               return -1;
-       }
-
-       /* Do the actual reading/writing stuff */
-       ret = 0;
-       for (i = half; i < count + half; ++i) {
-               flags = base_flags | (i % 2 ? OTP_UPPER_HALF : OTP_LOWER_HALF);
- try_again:
-               ret = otp_func(page, flags, addr);
-               if (ret & OTP_MASTER_ERROR) {
-                       if (force_read) {
-                               if (flags & OTP_NO_ECC)
-                                       break;
-                               else
-                                       flags |= OTP_NO_ECC;
-                               puts("E");
-                               goto try_again;
-                       } else
-                               break;
-               } else if (ret)
-                       puts("W");
-               else
-                       puts(".");
-               if (!(base_flags & OTP_LOCK)) {
-                       ++addr;
-                       if (i % 2)
-                               ++page;
-               } else
-                       ++page;
-       }
-       if (ret & 0x1)
-               printf("\nERROR at page 0x%03X (%s-halfpage): 0x%03X: %s\n",
-                       page, lowup(i), ret, otp_strerror(ret));
-       else
-               puts(" done\n");
-
-       /* Make sure we disable writing */
-       set_otp_timing(false);
-       bfrom_OtpCommand(OTP_CLOSE, 0);
-
-       return ret;
-}
-
-U_BOOT_CMD(
-       otp, 7, 0, do_otp,
-       "One-Time-Programmable sub-system",
-       "read <addr> <page> [count] [half]\n"
-       " - read 'count' half-pages starting at 'page' (offset 'half') to 'addr'\n"
-       "otp dump <addr> <page> [count] [half]\n"
-       " - like 'otp read', but skip read errors\n"
-       "otp write [--force] <addr> <page> [count] [half]\n"
-       " - write 'count' half-pages starting at 'page' (offset 'half') from 'addr'\n"
-       "otp lock <page> <count>\n"
-       " - lock 'count' pages starting at 'page'"
-);
diff --git a/common/cmd_part.c b/common/cmd_part.c
deleted file mode 100644 (file)
index 5599509..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
- *
- * made from cmd_ext2, which was:
- *
- * (C) Copyright 2004
- * esd gmbh <www.esd-electronics.com>
- * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
- *
- * made from cmd_reiserfs by
- *
- * (C) Copyright 2003 - 2004
- * Sysgo Real-Time Solutions, AG <www.elinos.com>
- * Pavel Bartusek <pba@sysgo.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <part.h>
-#include <vsprintf.h>
-
-#ifndef CONFIG_PARTITION_UUIDS
-#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
-#endif
-
-static int do_part_uuid(int argc, char * const argv[])
-{
-       int part;
-       block_dev_desc_t *dev_desc;
-       disk_partition_t info;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-       if (argc > 3)
-               return CMD_RET_USAGE;
-
-       part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
-       if (part < 0)
-               return 1;
-
-       if (argc > 2)
-               setenv(argv[2], info.uuid);
-       else
-               printf("%s\n", info.uuid);
-
-       return 0;
-}
-
-static int do_part_list(int argc, char * const argv[])
-{
-       int ret;
-       block_dev_desc_t *desc;
-       char *var = NULL;
-       bool bootable = false;
-       int i;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (argc > 2) {
-               for (i = 2; i < argc ; i++) {
-                       if (argv[i][0] == '-') {
-                               if (!strcmp(argv[i], "-bootable")) {
-                                       bootable = true;
-                               } else {
-                                       printf("Unknown option %s\n", argv[i]);
-                                       return CMD_RET_USAGE;
-                               }
-                       } else {
-                               var = argv[i];
-                               break;
-                       }
-               }
-
-               /* Loops should have been exited at the last argument, which
-                * as it contained the variable */
-               if (argc != i + 1)
-                       return CMD_RET_USAGE;
-       }
-
-       ret = get_device(argv[0], argv[1], &desc);
-       if (ret < 0)
-               return 1;
-
-       if (var != NULL) {
-               int p;
-               char str[512] = { '\0', };
-               disk_partition_t info;
-
-               for (p = 1; p < 128; p++) {
-                       char t[5];
-                       int r = get_partition_info(desc, p, &info);
-
-                       if (r != 0)
-                               continue;
-
-                       if (bootable && !info.bootable)
-                               continue;
-
-                       sprintf(t, "%s%x", str[0] ? " " : "", p);
-                       strcat(str, t);
-               }
-               setenv(var, str);
-               return 0;
-       }
-
-       print_part(desc);
-
-       return 0;
-}
-
-static int do_part_start(int argc, char * const argv[])
-{
-       block_dev_desc_t *desc;
-       disk_partition_t info;
-       char buf[512] = { 0 };
-       int part;
-       int err;
-       int ret;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-       if (argc > 4)
-               return CMD_RET_USAGE;
-
-       part = simple_strtoul(argv[2], NULL, 0);
-
-       ret = get_device(argv[0], argv[1], &desc);
-       if (ret < 0)
-               return 1;
-
-       err = get_partition_info(desc, part, &info);
-       if (err)
-               return 1;
-
-       snprintf(buf, sizeof(buf), LBAF, info.start);
-
-       if (argc > 3)
-               setenv(argv[3], buf);
-       else
-               printf("%s\n", buf);
-
-       return 0;
-}
-
-static int do_part_size(int argc, char * const argv[])
-{
-       block_dev_desc_t *desc;
-       disk_partition_t info;
-       char buf[512] = { 0 };
-       int part;
-       int err;
-       int ret;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-       if (argc > 4)
-               return CMD_RET_USAGE;
-
-       part = simple_strtoul(argv[2], NULL, 0);
-
-       ret = get_device(argv[0], argv[1], &desc);
-       if (ret < 0)
-               return 1;
-
-       err = get_partition_info(desc, part, &info);
-       if (err)
-               return 1;
-
-       snprintf(buf, sizeof(buf), LBAF, info.size);
-
-       if (argc > 3)
-               setenv(argv[3], buf);
-       else
-               printf("%s\n", buf);
-
-       return 0;
-}
-
-static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (!strcmp(argv[1], "uuid"))
-               return do_part_uuid(argc - 2, argv + 2);
-       else if (!strcmp(argv[1], "list"))
-               return do_part_list(argc - 2, argv + 2);
-       else if (!strcmp(argv[1], "start"))
-               return do_part_start(argc - 2, argv + 2);
-       else if (!strcmp(argv[1], "size"))
-               return do_part_size(argc - 2, argv + 2);
-
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       part,   CONFIG_SYS_MAXARGS,     1,      do_part,
-       "disk partition related commands",
-       "uuid <interface> <dev>:<part>\n"
-       "    - print partition UUID\n"
-       "part uuid <interface> <dev>:<part> <varname>\n"
-       "    - set environment variable to partition UUID\n"
-       "part list <interface> <dev>\n"
-       "    - print a device's partition table\n"
-       "part list <interface> <dev> [flags] <varname>\n"
-       "    - set environment variable to the list of partitions\n"
-       "      flags can be -bootable (list only bootable partitions)\n"
-       "part start <interface> <dev> <part> <varname>\n"
-       "    - set environment variable to the start of the partition (in blocks)\n"
-       "part size <interface> <dev> <part> <varname>\n"
-       "    - set environment variable to the size of the partition (in blocks)"
-);
diff --git a/common/cmd_pci.c b/common/cmd_pci.c
deleted file mode 100644 (file)
index 8094d33..0000000
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
- * Andreas Heppel <aheppel@sysgo.de>
- *
- * (C) Copyright 2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * PCI routines
- */
-
-#include <common.h>
-#include <bootretry.h>
-#include <cli.h>
-#include <command.h>
-#include <console.h>
-#include <dm.h>
-#include <asm/processor.h>
-#include <asm/io.h>
-#include <pci.h>
-
-struct pci_reg_info {
-       const char *name;
-       enum pci_size_t size;
-       u8 offset;
-};
-
-static int pci_byte_size(enum pci_size_t size)
-{
-       switch (size) {
-       case PCI_SIZE_8:
-               return 1;
-       case PCI_SIZE_16:
-               return 2;
-       case PCI_SIZE_32:
-       default:
-               return 4;
-       }
-}
-
-static int pci_field_width(enum pci_size_t size)
-{
-       return pci_byte_size(size) * 2;
-}
-
-#ifdef CONFIG_DM_PCI
-static void pci_show_regs(struct udevice *dev, struct pci_reg_info *regs)
-{
-       for (; regs->name; regs++) {
-               unsigned long val;
-
-               dm_pci_read_config(dev, regs->offset, &val, regs->size);
-               printf("  %s =%*s%#.*lx\n", regs->name,
-                      (int)(28 - strlen(regs->name)), "",
-                      pci_field_width(regs->size), val);
-       }
-}
-#else
-static unsigned long pci_read_config(pci_dev_t dev, int offset,
-                                    enum pci_size_t size)
-{
-       u32 val32;
-       u16 val16;
-       u8 val8;
-
-       switch (size) {
-       case PCI_SIZE_8:
-               pci_read_config_byte(dev, offset, &val8);
-               return val8;
-       case PCI_SIZE_16:
-               pci_read_config_word(dev, offset, &val16);
-               return val16;
-       case PCI_SIZE_32:
-       default:
-               pci_read_config_dword(dev, offset, &val32);
-               return val32;
-       }
-}
-
-static void pci_show_regs(pci_dev_t dev, struct pci_reg_info *regs)
-{
-       for (; regs->name; regs++) {
-               printf("  %s =%*s%#.*lx\n", regs->name,
-                      (int)(28 - strlen(regs->name)), "",
-                      pci_field_width(regs->size),
-                      pci_read_config(dev, regs->offset, regs->size));
-       }
-}
-#endif
-
-static struct pci_reg_info regs_start[] = {
-       { "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID },
-       { "device ID", PCI_SIZE_16, PCI_DEVICE_ID },
-       { "command register ID", PCI_SIZE_16, PCI_COMMAND },
-       { "status register", PCI_SIZE_16, PCI_STATUS },
-       { "revision ID", PCI_SIZE_8, PCI_REVISION_ID },
-       {},
-};
-
-static struct pci_reg_info regs_rest[] = {
-       { "sub class code", PCI_SIZE_8, PCI_CLASS_SUB_CODE },
-       { "programming interface", PCI_SIZE_8, PCI_CLASS_PROG },
-       { "cache line", PCI_SIZE_8, PCI_CACHE_LINE_SIZE },
-       { "latency time", PCI_SIZE_8, PCI_LATENCY_TIMER },
-       { "header type", PCI_SIZE_8, PCI_HEADER_TYPE },
-       { "BIST", PCI_SIZE_8, PCI_BIST },
-       { "base address 0", PCI_SIZE_32, PCI_BASE_ADDRESS_0 },
-       {},
-};
-
-static struct pci_reg_info regs_normal[] = {
-       { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
-       { "base address 2", PCI_SIZE_32, PCI_BASE_ADDRESS_2 },
-       { "base address 3", PCI_SIZE_32, PCI_BASE_ADDRESS_3 },
-       { "base address 4", PCI_SIZE_32, PCI_BASE_ADDRESS_4 },
-       { "base address 5", PCI_SIZE_32, PCI_BASE_ADDRESS_5 },
-       { "cardBus CIS pointer", PCI_SIZE_32, PCI_CARDBUS_CIS },
-       { "sub system vendor ID", PCI_SIZE_16, PCI_SUBSYSTEM_VENDOR_ID },
-       { "sub system ID", PCI_SIZE_16, PCI_SUBSYSTEM_ID },
-       { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS },
-       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
-       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
-       { "min Grant", PCI_SIZE_8, PCI_MIN_GNT },
-       { "max Latency", PCI_SIZE_8, PCI_MAX_LAT },
-       {},
-};
-
-static struct pci_reg_info regs_bridge[] = {
-       { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
-       { "primary bus number", PCI_SIZE_8, PCI_PRIMARY_BUS },
-       { "secondary bus number", PCI_SIZE_8, PCI_SECONDARY_BUS },
-       { "subordinate bus number", PCI_SIZE_8, PCI_SUBORDINATE_BUS },
-       { "secondary latency timer", PCI_SIZE_8, PCI_SEC_LATENCY_TIMER },
-       { "IO base", PCI_SIZE_8, PCI_IO_BASE },
-       { "IO limit", PCI_SIZE_8, PCI_IO_LIMIT },
-       { "secondary status", PCI_SIZE_16, PCI_SEC_STATUS },
-       { "memory base", PCI_SIZE_16, PCI_MEMORY_BASE },
-       { "memory limit", PCI_SIZE_16, PCI_MEMORY_LIMIT },
-       { "prefetch memory base", PCI_SIZE_16, PCI_PREF_MEMORY_BASE },
-       { "prefetch memory limit", PCI_SIZE_16, PCI_PREF_MEMORY_LIMIT },
-       { "prefetch memory base upper", PCI_SIZE_32, PCI_PREF_BASE_UPPER32 },
-       { "prefetch memory limit upper", PCI_SIZE_32, PCI_PREF_LIMIT_UPPER32 },
-       { "IO base upper 16 bits", PCI_SIZE_16, PCI_IO_BASE_UPPER16 },
-       { "IO limit upper 16 bits", PCI_SIZE_16, PCI_IO_LIMIT_UPPER16 },
-       { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS1 },
-       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
-       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
-       { "bridge control", PCI_SIZE_16, PCI_BRIDGE_CONTROL },
-       {},
-};
-
-static struct pci_reg_info regs_cardbus[] = {
-       { "capabilities", PCI_SIZE_8, PCI_CB_CAPABILITY_LIST },
-       { "secondary status", PCI_SIZE_16, PCI_CB_SEC_STATUS },
-       { "primary bus number", PCI_SIZE_8, PCI_CB_PRIMARY_BUS },
-       { "CardBus number", PCI_SIZE_8, PCI_CB_CARD_BUS },
-       { "subordinate bus number", PCI_SIZE_8, PCI_CB_SUBORDINATE_BUS },
-       { "CardBus latency timer", PCI_SIZE_8, PCI_CB_LATENCY_TIMER },
-       { "CardBus memory base 0", PCI_SIZE_32, PCI_CB_MEMORY_BASE_0 },
-       { "CardBus memory limit 0", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_0 },
-       { "CardBus memory base 1", PCI_SIZE_32, PCI_CB_MEMORY_BASE_1 },
-       { "CardBus memory limit 1", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_1 },
-       { "CardBus IO base 0", PCI_SIZE_16, PCI_CB_IO_BASE_0 },
-       { "CardBus IO base high 0", PCI_SIZE_16, PCI_CB_IO_BASE_0_HI },
-       { "CardBus IO limit 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0 },
-       { "CardBus IO limit high 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0_HI },
-       { "CardBus IO base 1", PCI_SIZE_16, PCI_CB_IO_BASE_1 },
-       { "CardBus IO base high 1", PCI_SIZE_16, PCI_CB_IO_BASE_1_HI },
-       { "CardBus IO limit 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1 },
-       { "CardBus IO limit high 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1_HI },
-       { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
-       { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
-       { "bridge control", PCI_SIZE_16, PCI_CB_BRIDGE_CONTROL },
-       { "subvendor ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_VENDOR_ID },
-       { "subdevice ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_ID },
-       { "PC Card 16bit base address", PCI_SIZE_32, PCI_CB_LEGACY_MODE_BASE },
-       {},
-};
-
-/**
- * pci_header_show() - Show the header of the specified PCI device.
- *
- * @dev: Bus+Device+Function number
- */
-#ifdef CONFIG_DM_PCI
-void pci_header_show(struct udevice *dev)
-#else
-void pci_header_show(pci_dev_t dev)
-#endif
-{
-#ifdef CONFIG_DM_PCI
-       unsigned long class, header_type;
-
-       dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
-       dm_pci_read_config(dev, PCI_HEADER_TYPE, &header_type, PCI_SIZE_8);
-#else
-       u8 class, header_type;
-
-       pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
-       pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
-#endif
-       pci_show_regs(dev, regs_start);
-       printf("  class code =                  0x%.2x (%s)\n", (int)class,
-              pci_class_str(class));
-       pci_show_regs(dev, regs_rest);
-
-       switch (header_type & 0x03) {
-       case PCI_HEADER_TYPE_NORMAL:    /* "normal" PCI device */
-               pci_show_regs(dev, regs_normal);
-               break;
-       case PCI_HEADER_TYPE_BRIDGE:    /* PCI-to-PCI bridge */
-               pci_show_regs(dev, regs_bridge);
-               break;
-       case PCI_HEADER_TYPE_CARDBUS:   /* PCI-to-CardBus bridge */
-               pci_show_regs(dev, regs_cardbus);
-               break;
-
-       default:
-               printf("unknown header\n");
-               break;
-    }
-}
-
-void pciinfo_header(int busnum, bool short_listing)
-{
-       printf("Scanning PCI devices on bus %d\n", busnum);
-
-       if (short_listing) {
-               printf("BusDevFun  VendorId   DeviceId   Device Class       Sub-Class\n");
-               printf("_____________________________________________________________\n");
-       }
-}
-
-#ifdef CONFIG_DM_PCI
-/**
- * pci_header_show_brief() - Show the short-form PCI device header
- *
- * Reads and prints the header of the specified PCI device in short form.
- *
- * @dev: PCI device to show
- */
-static void pci_header_show_brief(struct udevice *dev)
-{
-       ulong vendor, device;
-       ulong class, subclass;
-
-       dm_pci_read_config(dev, PCI_VENDOR_ID, &vendor, PCI_SIZE_16);
-       dm_pci_read_config(dev, PCI_DEVICE_ID, &device, PCI_SIZE_16);
-       dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
-       dm_pci_read_config(dev, PCI_CLASS_SUB_CODE, &subclass, PCI_SIZE_8);
-
-       printf("0x%.4lx     0x%.4lx     %-23s 0x%.2lx\n",
-              vendor, device,
-              pci_class_str(class), subclass);
-}
-
-static void pciinfo(struct udevice *bus, bool short_listing)
-{
-       struct udevice *dev;
-
-       pciinfo_header(bus->seq, short_listing);
-
-       for (device_find_first_child(bus, &dev);
-            dev;
-            device_find_next_child(&dev)) {
-               struct pci_child_platdata *pplat;
-
-               pplat = dev_get_parent_platdata(dev);
-               if (short_listing) {
-                       printf("%02x.%02x.%02x   ", bus->seq,
-                              PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
-                       pci_header_show_brief(dev);
-               } else {
-                       printf("\nFound PCI device %02x.%02x.%02x:\n", bus->seq,
-                              PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
-                       pci_header_show(dev);
-               }
-       }
-}
-
-#else
-
-/**
- * pci_header_show_brief() - Show the short-form PCI device header
- *
- * Reads and prints the header of the specified PCI device in short form.
- *
- * @dev: Bus+Device+Function number
- */
-void pci_header_show_brief(pci_dev_t dev)
-{
-       u16 vendor, device;
-       u8 class, subclass;
-
-       pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
-       pci_read_config_word(dev, PCI_DEVICE_ID, &device);
-       pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
-       pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass);
-
-       printf("0x%.4x     0x%.4x     %-23s 0x%.2x\n",
-              vendor, device,
-              pci_class_str(class), subclass);
-}
-
-/**
- * pciinfo() - Show a list of devices on the PCI bus
- *
- * Show information about devices on PCI bus. Depending on @short_pci_listing
- * the output will be more or less exhaustive.
- *
- * @bus_num: The number of the bus to be scanned
- * @short_pci_listing: true to use short form, showing only a brief header
- * for each device
- */
-void pciinfo(int bus_num, int short_pci_listing)
-{
-       struct pci_controller *hose = pci_bus_to_hose(bus_num);
-       int device;
-       int function;
-       unsigned char header_type;
-       unsigned short vendor_id;
-       pci_dev_t dev;
-       int ret;
-
-       if (!hose)
-               return;
-
-       pciinfo_header(bus_num, short_pci_listing);
-
-       for (device = 0; device < PCI_MAX_PCI_DEVICES; device++) {
-               header_type = 0;
-               vendor_id = 0;
-               for (function = 0; function < PCI_MAX_PCI_FUNCTIONS;
-                    function++) {
-                       /*
-                        * If this is not a multi-function device, we skip
-                        * the rest.
-                        */
-                       if (function && !(header_type & 0x80))
-                               break;
-
-                       dev = PCI_BDF(bus_num, device, function);
-
-                       if (pci_skip_dev(hose, dev))
-                               continue;
-
-                       ret = pci_read_config_word(dev, PCI_VENDOR_ID,
-                                                  &vendor_id);
-                       if (ret)
-                               goto error;
-                       if ((vendor_id == 0xFFFF) || (vendor_id == 0x0000))
-                               continue;
-
-                       if (!function) {
-                               pci_read_config_byte(dev, PCI_HEADER_TYPE,
-                                                    &header_type);
-                       }
-
-                       if (short_pci_listing) {
-                               printf("%02x.%02x.%02x   ", bus_num, device,
-                                      function);
-                               pci_header_show_brief(dev);
-                       } else {
-                               printf("\nFound PCI device %02x.%02x.%02x:\n",
-                                      bus_num, device, function);
-                               pci_header_show(dev);
-                       }
-               }
-       }
-
-       return;
-error:
-       printf("Cannot read bus configuration: %d\n", ret);
-}
-#endif
-
-/**
- * get_pci_dev() - Convert the "bus.device.function" identifier into a number
- *
- * @name: Device string in the form "bus.device.function" where each is in hex
- * @return encoded pci_dev_t or -1 if the string was invalid
- */
-static pci_dev_t get_pci_dev(char *name)
-{
-       char cnum[12];
-       int len, i, iold, n;
-       int bdfs[3] = {0,0,0};
-
-       len = strlen(name);
-       if (len > 8)
-               return -1;
-       for (i = 0, iold = 0, n = 0; i < len; i++) {
-               if (name[i] == '.') {
-                       memcpy(cnum, &name[iold], i - iold);
-                       cnum[i - iold] = '\0';
-                       bdfs[n++] = simple_strtoul(cnum, NULL, 16);
-                       iold = i + 1;
-               }
-       }
-       strcpy(cnum, &name[iold]);
-       if (n == 0)
-               n = 1;
-       bdfs[n] = simple_strtoul(cnum, NULL, 16);
-
-       return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
-}
-
-#ifdef CONFIG_DM_PCI
-static int pci_cfg_display(struct udevice *dev, ulong addr,
-                          enum pci_size_t size, ulong length)
-#else
-static int pci_cfg_display(pci_dev_t bdf, ulong addr, enum pci_size_t size,
-                          ulong length)
-#endif
-{
-#define DISP_LINE_LEN  16
-       ulong i, nbytes, linebytes;
-       int byte_size;
-       int rc = 0;
-
-       byte_size = pci_byte_size(size);
-       if (length == 0)
-               length = 0x40 / byte_size; /* Standard PCI config space */
-
-       /* Print the lines.
-        * once, and all accesses are with the specified bus width.
-        */
-       nbytes = length * byte_size;
-       do {
-               printf("%08lx:", addr);
-               linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
-               for (i = 0; i < linebytes; i += byte_size) {
-                       unsigned long val;
-
-#ifdef CONFIG_DM_PCI
-                       dm_pci_read_config(dev, addr, &val, size);
-#else
-                       val = pci_read_config(bdf, addr, size);
-#endif
-                       printf(" %0*lx", pci_field_width(size), val);
-                       addr += byte_size;
-               }
-               printf("\n");
-               nbytes -= linebytes;
-               if (ctrlc()) {
-                       rc = 1;
-                       break;
-               }
-       } while (nbytes > 0);
-
-       return (rc);
-}
-
-#ifndef CONFIG_DM_PCI
-static int pci_cfg_write (pci_dev_t bdf, ulong addr, ulong size, ulong value)
-{
-       if (size == 4) {
-               pci_write_config_dword(bdf, addr, value);
-       }
-       else if (size == 2) {
-               ushort val = value & 0xffff;
-               pci_write_config_word(bdf, addr, val);
-       }
-       else {
-               u_char val = value & 0xff;
-               pci_write_config_byte(bdf, addr, val);
-       }
-       return 0;
-}
-#endif
-
-#ifdef CONFIG_DM_PCI
-static int pci_cfg_modify(struct udevice *dev, ulong addr, ulong size,
-                         ulong value, int incrflag)
-#else
-static int pci_cfg_modify(pci_dev_t bdf, ulong addr, ulong size, ulong value,
-                         int incrflag)
-#endif
-{
-       ulong   i;
-       int     nbytes;
-       ulong val;
-
-       /* Print the address, followed by value.  Then accept input for
-        * the next value.  A non-converted value exits.
-        */
-       do {
-               printf("%08lx:", addr);
-#ifdef CONFIG_DM_PCI
-               dm_pci_read_config(dev, addr, &val, size);
-#else
-               val = pci_read_config(bdf, addr, size);
-#endif
-               printf(" %0*lx", pci_field_width(size), val);
-
-               nbytes = cli_readline(" ? ");
-               if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
-                       /* <CR> pressed as only input, don't modify current
-                        * location and move to next. "-" pressed will go back.
-                        */
-                       if (incrflag)
-                               addr += nbytes ? -size : size;
-                       nbytes = 1;
-                       /* good enough to not time out */
-                       bootretry_reset_cmd_timeout();
-               }
-#ifdef CONFIG_BOOT_RETRY_TIME
-               else if (nbytes == -2) {
-                       break;  /* timed out, exit the command  */
-               }
-#endif
-               else {
-                       char *endp;
-                       i = simple_strtoul(console_buffer, &endp, 16);
-                       nbytes = endp - console_buffer;
-                       if (nbytes) {
-                               /* good enough to not time out
-                                */
-                               bootretry_reset_cmd_timeout();
-#ifdef CONFIG_DM_PCI
-                               dm_pci_write_config(dev, addr, i, size);
-#else
-                               pci_cfg_write(bdf, addr, size, i);
-#endif
-                               if (incrflag)
-                                       addr += size;
-                       }
-               }
-       } while (nbytes);
-
-       return 0;
-}
-
-/* PCI Configuration Space access commands
- *
- * Syntax:
- *     pci display[.b, .w, .l] bus.device.function} [addr] [len]
- *     pci next[.b, .w, .l] bus.device.function [addr]
- *      pci modify[.b, .w, .l] bus.device.function [addr]
- *      pci write[.b, .w, .l] bus.device.function addr value
- */
-static int do_pci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr = 0, value = 0, cmd_size = 0;
-       enum pci_size_t size = PCI_SIZE_32;
-#ifdef CONFIG_DM_PCI
-       struct udevice *dev, *bus;
-#else
-       pci_dev_t dev;
-#endif
-       int busnum = 0;
-       pci_dev_t bdf = 0;
-       char cmd = 's';
-       int ret = 0;
-
-       if (argc > 1)
-               cmd = argv[1][0];
-
-       switch (cmd) {
-       case 'd':               /* display */
-       case 'n':               /* next */
-       case 'm':               /* modify */
-       case 'w':               /* write */
-               /* Check for a size specification. */
-               cmd_size = cmd_get_data_size(argv[1], 4);
-               size = (cmd_size == 4) ? PCI_SIZE_32 : cmd_size - 1;
-               if (argc > 3)
-                       addr = simple_strtoul(argv[3], NULL, 16);
-               if (argc > 4)
-                       value = simple_strtoul(argv[4], NULL, 16);
-       case 'h':               /* header */
-               if (argc < 3)
-                       goto usage;
-               if ((bdf = get_pci_dev(argv[2])) == -1)
-                       return 1;
-               break;
-#ifdef CONFIG_CMD_PCI_ENUM
-       case 'e':
-               break;
-#endif
-       default:                /* scan bus */
-               value = 1; /* short listing */
-               if (argc > 1) {
-                       if (argv[argc-1][0] == 'l') {
-                               value = 0;
-                               argc--;
-                       }
-                       if (argc > 1)
-                               busnum = simple_strtoul(argv[1], NULL, 16);
-               }
-#ifdef CONFIG_DM_PCI
-               ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus);
-               if (ret) {
-                       printf("No such bus\n");
-                       return CMD_RET_FAILURE;
-               }
-               pciinfo(bus, value);
-#else
-               pciinfo(busnum, value);
-#endif
-               return 0;
-       }
-
-#ifdef CONFIG_DM_PCI
-       ret = dm_pci_bus_find_bdf(bdf, &dev);
-       if (ret) {
-               printf("No such device\n");
-               return CMD_RET_FAILURE;
-       }
-#else
-       dev = bdf;
-#endif
-
-       switch (argv[1][0]) {
-       case 'h':               /* header */
-               pci_header_show(dev);
-               break;
-       case 'd':               /* display */
-               return pci_cfg_display(dev, addr, size, value);
-#ifdef CONFIG_CMD_PCI_ENUM
-       case 'e':
-# ifdef CONFIG_DM_PCI
-               printf("This command is not yet supported with driver model\n");
-# else
-               pci_init();
-# endif
-               break;
-#endif
-       case 'n':               /* next */
-               if (argc < 4)
-                       goto usage;
-               ret = pci_cfg_modify(dev, addr, size, value, 0);
-               break;
-       case 'm':               /* modify */
-               if (argc < 4)
-                       goto usage;
-               ret = pci_cfg_modify(dev, addr, size, value, 1);
-               break;
-       case 'w':               /* write */
-               if (argc < 5)
-                       goto usage;
-#ifdef CONFIG_DM_PCI
-               ret = dm_pci_write_config(dev, addr, value, size);
-#else
-               ret = pci_cfg_write(dev, addr, size, value);
-#endif
-               break;
-       default:
-               ret = CMD_RET_USAGE;
-               break;
-       }
-
-       return ret;
- usage:
-       return CMD_RET_USAGE;
-}
-
-/***************************************************/
-
-#ifdef CONFIG_SYS_LONGHELP
-static char pci_help_text[] =
-       "[bus] [long]\n"
-       "    - short or long list of PCI devices on bus 'bus'\n"
-#ifdef CONFIG_CMD_PCI_ENUM
-       "pci enum\n"
-       "    - re-enumerate PCI buses\n"
-#endif
-       "pci header b.d.f\n"
-       "    - show header of PCI device 'bus.device.function'\n"
-       "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
-       "    - display PCI configuration space (CFG)\n"
-       "pci next[.b, .w, .l] b.d.f address\n"
-       "    - modify, read and keep CFG address\n"
-       "pci modify[.b, .w, .l] b.d.f address\n"
-       "    -  modify, auto increment CFG address\n"
-       "pci write[.b, .w, .l] b.d.f address value\n"
-       "    - write to CFG address";
-#endif
-
-U_BOOT_CMD(
-       pci,    5,      1,      do_pci,
-       "list and access PCI Configuration Space", pci_help_text
-);
diff --git a/common/cmd_pcmcia.c b/common/cmd_pcmcia.c
deleted file mode 100644 (file)
index 682d18f..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * (C) Copyright 2000-2006
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- *
- ********************************************************************
- *
- * Lots of code copied from:
- *
- * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
- * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
- *
- * "The ExCA standard specifies that socket controllers should provide
- * two IO and five memory windows per socket, which can be independently
- * configured and positioned in the host address space and mapped to
- * arbitrary segments of card address space. " - David A Hinds. 1999
- *
- * This controller does _not_ meet the ExCA standard.
- *
- * m8xx pcmcia controller brief info:
- * + 8 windows (attrib, mem, i/o)
- * + up to two slots (SLOT_A and SLOT_B)
- * + inputpins, outputpins, event and mask registers.
- * - no offset register. sigh.
- *
- * Because of the lacking offset register we must map the whole card.
- * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
- * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
- * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
- * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
- * They are maximum 64KByte each...
- */
-
-/* #define DEBUG       1       */
-
-/*
- * PCMCIA support
- */
-#include <common.h>
-#include <command.h>
-#include <config.h>
-#include <pcmcia.h>
-#include <asm/io.h>
-
-/* -------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_PCMCIA)
-
-extern int pcmcia_on (void);
-extern int pcmcia_off (void);
-
-int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int rcode = 0;
-
-       if (argc != 2) {
-               printf ("Usage: pinit {on | off}\n");
-               return 1;
-       }
-       if (strcmp(argv[1],"on") == 0) {
-               rcode = pcmcia_on ();
-       } else if (strcmp(argv[1],"off") == 0) {
-               rcode = pcmcia_off ();
-       } else {
-               printf ("Usage: pinit {on | off}\n");
-               return 1;
-       }
-
-       return rcode;
-}
-
-U_BOOT_CMD(
-       pinit,  2,      0,      do_pinit,
-       "PCMCIA sub-system",
-       "on  - power on PCMCIA socket\n"
-       "pinit off - power off PCMCIA socket"
-);
-
-#endif
-
-/* -------------------------------------------------------------------- */
-
-#undef CHECK_IDE_DEVICE
-
-#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
-#define        CHECK_IDE_DEVICE
-#endif
-
-#if    defined(CONFIG_PXA_PCMCIA)
-#define        CHECK_IDE_DEVICE
-#endif
-
-#ifdef CHECK_IDE_DEVICE
-
-int            ide_devices_found;
-static uchar   *known_cards[] = {
-       (uchar *)"ARGOSY PnPIDE D5",
-       NULL
-};
-
-#define        MAX_TUPEL_SZ    512
-#define MAX_FEATURES   4
-
-#define MAX_IDENT_CHARS                64
-#define        MAX_IDENT_FIELDS        4
-
-#define        indent  "\t   "
-
-static void print_funcid (int func)
-{
-       puts (indent);
-       switch (func) {
-               case CISTPL_FUNCID_MULTI:
-                       puts (" Multi-Function");
-                       break;
-               case CISTPL_FUNCID_MEMORY:
-                       puts (" Memory");
-                       break;
-               case CISTPL_FUNCID_SERIAL:
-                       puts (" Serial Port");
-                       break;
-               case CISTPL_FUNCID_PARALLEL:
-                       puts (" Parallel Port");
-                       break;
-               case CISTPL_FUNCID_FIXED:
-                       puts (" Fixed Disk");
-                       break;
-               case CISTPL_FUNCID_VIDEO:
-                       puts (" Video Adapter");
-                       break;
-               case CISTPL_FUNCID_NETWORK:
-                       puts (" Network Adapter");
-                       break;
-               case CISTPL_FUNCID_AIMS:
-                       puts (" AIMS Card");
-                       break;
-               case CISTPL_FUNCID_SCSI:
-                       puts (" SCSI Adapter");
-                       break;
-               default:
-                       puts (" Unknown");
-                       break;
-       }
-       puts (" Card\n");
-}
-
-static void print_fixed (volatile uchar *p)
-{
-       if (p == NULL)
-               return;
-
-       puts(indent);
-
-       switch (*p) {
-               case CISTPL_FUNCE_IDE_IFACE:
-               {   uchar iface = *(p+2);
-
-               puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
-               puts (" interface ");
-               break;
-               }
-               case CISTPL_FUNCE_IDE_MASTER:
-               case CISTPL_FUNCE_IDE_SLAVE:
-               {   uchar f1 = *(p+2);
-               uchar f2 = *(p+4);
-
-               puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
-
-               if (f1 & CISTPL_IDE_UNIQUE)
-                       puts (" [unique]");
-
-               puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
-
-               if (f2 & CISTPL_IDE_HAS_SLEEP)
-                       puts (" [sleep]");
-
-               if (f2 & CISTPL_IDE_HAS_STANDBY)
-                       puts (" [standby]");
-
-               if (f2 & CISTPL_IDE_HAS_IDLE)
-                       puts (" [idle]");
-
-               if (f2 & CISTPL_IDE_LOW_POWER)
-                       puts (" [low power]");
-
-               if (f2 & CISTPL_IDE_REG_INHIBIT)
-                       puts (" [reg inhibit]");
-
-               if (f2 & CISTPL_IDE_HAS_INDEX)
-                       puts (" [index]");
-
-               if (f2 & CISTPL_IDE_IOIS16)
-                       puts (" [IOis16]");
-
-               break;
-               }
-       }
-       putc ('\n');
-}
-
-static int identify  (volatile uchar *p)
-{
-       uchar id_str[MAX_IDENT_CHARS];
-       uchar data;
-       uchar *t;
-       uchar **card;
-       int i, done;
-
-       if (p == NULL)
-               return (0);     /* Don't know */
-
-       t = id_str;
-       done =0;
-
-       for (i=0; i<=4 && !done; ++i, p+=2) {
-               while ((data = *p) != '\0') {
-                       if (data == 0xFF) {
-                               done = 1;
-                               break;
-                       }
-                       *t++ = data;
-                       if (t == &id_str[MAX_IDENT_CHARS-1]) {
-                               done = 1;
-                               break;
-                       }
-                       p += 2;
-               }
-               if (!done)
-                       *t++ = ' ';
-       }
-       *t = '\0';
-       while (--t > id_str) {
-               if (*t == ' ')
-                       *t = '\0';
-               else
-                       break;
-       }
-       puts ((char *)id_str);
-       putc ('\n');
-
-       for (card=known_cards; *card; ++card) {
-               debug ("## Compare against \"%s\"\n", *card);
-               if (strcmp((char *)*card, (char *)id_str) == 0) {       /* found! */
-                       debug ("## CARD FOUND ##\n");
-                       return (1);
-               }
-       }
-
-       return (0);     /* don't know */
-}
-
-int check_ide_device (int slot)
-{
-       volatile uchar *ident = NULL;
-       volatile uchar *feature_p[MAX_FEATURES];
-       volatile uchar *p, *start, *addr;
-       int n_features = 0;
-       uchar func_id = ~0;
-       uchar code, len;
-       ushort config_base = 0;
-       int found = 0;
-       int i;
-
-       addr = (volatile uchar *)(CONFIG_SYS_PCMCIA_MEM_ADDR +
-                                 CONFIG_SYS_PCMCIA_MEM_SIZE * (slot * 4));
-       debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
-
-       start = p = (volatile uchar *) addr;
-
-       while ((p - start) < MAX_TUPEL_SZ) {
-
-               code = *p; p += 2;
-
-               if (code == 0xFF) { /* End of chain */
-                       break;
-               }
-
-               len = *p; p += 2;
-#if defined(DEBUG) && (DEBUG > 1)
-               { volatile uchar *q = p;
-                       printf ("\nTuple code %02x  length %d\n\tData:",
-                               code, len);
-
-                       for (i = 0; i < len; ++i) {
-                               printf (" %02x", *q);
-                               q+= 2;
-                       }
-               }
-#endif /* DEBUG */
-               switch (code) {
-               case CISTPL_VERS_1:
-                       ident = p + 4;
-                       break;
-               case CISTPL_FUNCID:
-                       /* Fix for broken SanDisk which may have 0x80 bit set */
-                       func_id = *p & 0x7F;
-                       break;
-               case CISTPL_FUNCE:
-                       if (n_features < MAX_FEATURES)
-                               feature_p[n_features++] = p;
-                       break;
-               case CISTPL_CONFIG:
-                       config_base = (*(p+6) << 8) + (*(p+4));
-                       debug ("\n## Config_base = %04x ###\n", config_base);
-               default:
-                       break;
-               }
-               p += 2 * len;
-       }
-
-       found = identify (ident);
-
-       if (func_id != ((uchar)~0)) {
-               print_funcid (func_id);
-
-               if (func_id == CISTPL_FUNCID_FIXED)
-                       found = 1;
-               else
-                       return (1);     /* no disk drive */
-       }
-
-       for (i=0; i<n_features; ++i) {
-               print_fixed (feature_p[i]);
-       }
-
-       if (!found) {
-               printf ("unknown card type\n");
-               return (1);
-       }
-
-       ide_devices_found |= (1 << slot);
-
-       /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
-       *((uchar *)(addr + config_base)) = 1;
-#if 0
-       printf("\n## Config_base = %04x ###\n", config_base);
-       printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
-       printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
-       printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
-       printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
-#endif
-       return (0);
-}
-
-#endif /* CHECK_IDE_DEVICE */
diff --git a/common/cmd_pmic.c b/common/cmd_pmic.c
deleted file mode 100644 (file)
index 970767c..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (C) 2014-2015 Samsung Electronics
- * Przemyslaw Marczak <p.marczak@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <errno.h>
-#include <dm.h>
-#include <dm/uclass-internal.h>
-#include <power/pmic.h>
-
-#define LIMIT_DEV      32
-#define LIMIT_PARENT   20
-
-static struct udevice *currdev;
-
-static int failure(int ret)
-{
-       printf("Error: %d (%s)\n", ret, errno_str(ret));
-
-       return CMD_RET_FAILURE;
-}
-
-static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *name;
-       int ret = -ENODEV;
-
-       switch (argc) {
-       case 2:
-               name = argv[1];
-               ret = pmic_get(name, &currdev);
-               if (ret) {
-                       printf("Can't get PMIC: %s!\n", name);
-                       return failure(ret);
-               }
-       case 1:
-               if (!currdev) {
-                       printf("PMIC device is not set!\n\n");
-                       return CMD_RET_USAGE;
-               }
-
-               printf("dev: %d @ %s\n", currdev->seq, currdev->name);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       int ret;
-
-       printf("| %-*.*s| %-*.*s| %s @ %s\n",
-              LIMIT_DEV, LIMIT_DEV, "Name",
-              LIMIT_PARENT, LIMIT_PARENT, "Parent name",
-              "Parent uclass", "seq");
-
-       for (ret = uclass_first_device(UCLASS_PMIC, &dev); dev;
-            ret = uclass_next_device(&dev)) {
-               if (ret)
-                       continue;
-
-               printf("| %-*.*s| %-*.*s| %s @ %d\n",
-                      LIMIT_DEV, LIMIT_DEV, dev->name,
-                      LIMIT_PARENT, LIMIT_PARENT, dev->parent->name,
-                      dev_get_uclass_name(dev->parent), dev->parent->seq);
-       }
-
-       if (ret)
-               return CMD_RET_FAILURE;
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       uint8_t value;
-       uint reg;
-       int ret;
-
-       if (!currdev) {
-               printf("First, set the PMIC device!\n");
-               return CMD_RET_USAGE;
-       }
-
-       dev = currdev;
-
-       printf("Dump pmic: %s registers\n", dev->name);
-
-       for (reg = 0; reg < pmic_reg_count(dev); reg++) {
-               ret = pmic_read(dev, reg, &value, 1);
-               if (ret) {
-                       printf("Can't read register: %d\n", reg);
-                       return failure(ret);
-               }
-
-               if (!(reg % 16))
-                       printf("\n0x%02x: ", reg);
-
-               printf("%2.2x ", value);
-       }
-       printf("\n");
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       int regs, ret;
-       uint8_t value;
-       uint reg;
-
-       if (!currdev) {
-               printf("First, set the PMIC device!\n");
-               return CMD_RET_USAGE;
-       }
-
-       dev = currdev;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       reg = simple_strtoul(argv[1], NULL, 0);
-       regs = pmic_reg_count(dev);
-       if (reg > regs) {
-               printf("PMIC max reg: %d\n", regs);
-               return failure(-EFAULT);
-       }
-
-       ret = pmic_read(dev, reg, &value, 1);
-       if (ret) {
-               printf("Can't read PMIC register: %d!\n", reg);
-               return failure(ret);
-       }
-
-       printf("0x%02x: 0x%2.2x\n", reg, value);
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       int regs, ret;
-       uint8_t value;
-       uint reg;
-
-       if (!currdev) {
-               printf("First, set the PMIC device!\n");
-               return CMD_RET_USAGE;
-       }
-
-       dev = currdev;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       reg = simple_strtoul(argv[1], NULL, 0);
-       regs = pmic_reg_count(dev);
-       if (reg > regs) {
-               printf("PMIC max reg: %d\n", regs);
-               return failure(-EFAULT);
-       }
-
-       value = simple_strtoul(argv[2], NULL, 0);
-
-       ret = pmic_write(dev, reg, &value, 1);
-       if (ret) {
-               printf("Can't write PMIC register: %d!\n", reg);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static cmd_tbl_t subcmd[] = {
-       U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""),
-       U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
-       U_BOOT_CMD_MKENT(dump, 1, 1, do_dump, "", ""),
-       U_BOOT_CMD_MKENT(read, 2, 1, do_read, "", ""),
-       U_BOOT_CMD_MKENT(write, 3, 1, do_write, "", ""),
-};
-
-static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       cmd_tbl_t *cmd;
-
-       argc--;
-       argv++;
-
-       cmd = find_cmd_tbl(argv[0], subcmd, ARRAY_SIZE(subcmd));
-       if (cmd == NULL || argc > cmd->maxargs)
-               return CMD_RET_USAGE;
-
-       return cmd->cmd(cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
-       " operations",
-       "list          - list pmic devices\n"
-       "pmic dev [name]    - show or [set] operating PMIC device\n"
-       "pmic dump          - dump registers\n"
-       "pmic read address  - read byte of register at address\n"
-       "pmic write address - write byte to register at address\n"
-);
diff --git a/common/cmd_portio.c b/common/cmd_portio.c
deleted file mode 100644 (file)
index bf3a997..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * (C) Copyright 2003
- * Marc Singer, elf@buici.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Port I/O Functions
- *
- * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
- */
-
-#include <common.h>
-#include <command.h>
-
-/* Display values from last command.
- * Memory modify remembered values are different from display memory.
- */
-static uint in_last_addr, in_last_size;
-static uint out_last_addr, out_last_size, out_last_value;
-
-
-int do_portio_out (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       uint addr = out_last_addr;
-       uint size = out_last_size;
-       uint value = out_last_value;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /*
-                * New command specified.  Check for a size specification.
-                * Defaults to long if no or incorrect specification.
-                */
-               size = cmd_get_data_size (argv[0], 1);
-               addr = simple_strtoul (argv[1], NULL, 16);
-               value = simple_strtoul (argv[2], NULL, 16);
-       }
-#if defined (CONFIG_X86)
-
-       {
-               unsigned short port = addr;
-
-               switch (size) {
-               default:
-               case 1:
-                   {
-                       unsigned char ch = value;
-                       __asm__ volatile ("out %0, %%dx"::"a" (ch), "d" (port));
-                   }
-                       break;
-               case 2:
-                   {
-                       unsigned short w = value;
-                       __asm__ volatile ("out %0, %%dx"::"a" (w), "d" (port));
-                   }
-                       break;
-               case 4:
-                       __asm__ volatile ("out %0, %%dx"::"a" (value), "d" (port));
-
-                       break;
-               }
-       }
-
-#endif                                                 /* CONFIG_X86 */
-
-       out_last_addr = addr;
-       out_last_size = size;
-       out_last_value = value;
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       out,    3,      1,      do_portio_out,
-       "write datum to IO port",
-       "[.b, .w, .l] port value\n    - output to IO port"
-);
-
-int do_portio_in (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       uint addr = in_last_addr;
-       uint size = in_last_size;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               /*
-                * New command specified.  Check for a size specification.
-                * Defaults to long if no or incorrect specification.
-                */
-               size = cmd_get_data_size (argv[0], 1);
-               addr = simple_strtoul (argv[1], NULL, 16);
-       }
-#if defined (CONFIG_X86)
-
-       {
-               unsigned short port = addr;
-
-               switch (size) {
-               default:
-               case 1:
-                   {
-                       unsigned char ch;
-                       __asm__ volatile ("in %%dx, %0":"=a" (ch):"d" (port));
-
-                       printf (" %02x\n", ch);
-                   }
-                       break;
-               case 2:
-                   {
-                       unsigned short w;
-                       __asm__ volatile ("in %%dx, %0":"=a" (w):"d" (port));
-
-                       printf (" %04x\n", w);
-                   }
-                       break;
-               case 4:
-                   {
-                       unsigned long l;
-                       __asm__ volatile ("in %%dx, %0":"=a" (l):"d" (port));
-
-                       printf (" %08lx\n", l);
-                   }
-                       break;
-               }
-       }
-#endif /* CONFIG_X86 */
-
-       in_last_addr = addr;
-       in_last_size = size;
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       in,     2,      1,      do_portio_in,
-       "read data from an IO port",
-       "[.b, .w, .l] port\n"
-       "    - read datum from IO port"
-);
diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
deleted file mode 100644 (file)
index 080b376..0000000
+++ /dev/null
@@ -1,1725 +0,0 @@
-/*
- * Copyright 2010-2011 Calxeda, Inc.
- * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <linux/string.h>
-#include <linux/ctype.h>
-#include <errno.h>
-#include <linux/list.h>
-#include <fs.h>
-#include <asm/io.h>
-
-#include "menu.h"
-#include "cli.h"
-
-#define MAX_TFTP_PATH_LEN 127
-
-const char *pxe_default_paths[] = {
-#ifdef CONFIG_SYS_SOC
-       "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC,
-#endif
-       "default-" CONFIG_SYS_ARCH,
-       "default",
-       NULL
-};
-
-static bool is_pxe;
-
-/*
- * Like getenv, but prints an error if envvar isn't defined in the
- * environment.  It always returns what getenv does, so it can be used in
- * place of getenv without changing error handling otherwise.
- */
-static char *from_env(const char *envvar)
-{
-       char *ret;
-
-       ret = getenv(envvar);
-
-       if (!ret)
-               printf("missing environment variable: %s\n", envvar);
-
-       return ret;
-}
-
-#ifdef CONFIG_CMD_NET
-/*
- * Convert an ethaddr from the environment to the format used by pxelinux
- * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
- * the beginning of the ethernet address to indicate a hardware type of
- * Ethernet. Also converts uppercase hex characters into lowercase, to match
- * pxelinux's behavior.
- *
- * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
- * environment, or some other value < 0 on error.
- */
-static int format_mac_pxe(char *outbuf, size_t outbuf_len)
-{
-       uchar ethaddr[6];
-
-       if (outbuf_len < 21) {
-               printf("outbuf is too small (%zd < 21)\n", outbuf_len);
-
-               return -EINVAL;
-       }
-
-       if (!eth_getenv_enetaddr_by_index("eth", eth_get_dev_index(),
-                                         ethaddr))
-               return -ENOENT;
-
-       sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
-               ethaddr[0], ethaddr[1], ethaddr[2],
-               ethaddr[3], ethaddr[4], ethaddr[5]);
-
-       return 1;
-}
-#endif
-
-/*
- * Returns the directory the file specified in the bootfile env variable is
- * in. If bootfile isn't defined in the environment, return NULL, which should
- * be interpreted as "don't prepend anything to paths".
- */
-static int get_bootfile_path(const char *file_path, char *bootfile_path,
-                            size_t bootfile_path_size)
-{
-       char *bootfile, *last_slash;
-       size_t path_len = 0;
-
-       /* Only syslinux allows absolute paths */
-       if (file_path[0] == '/' && !is_pxe)
-               goto ret;
-
-       bootfile = from_env("bootfile");
-
-       if (!bootfile)
-               goto ret;
-
-       last_slash = strrchr(bootfile, '/');
-
-       if (last_slash == NULL)
-               goto ret;
-
-       path_len = (last_slash - bootfile) + 1;
-
-       if (bootfile_path_size < path_len) {
-               printf("bootfile_path too small. (%zd < %zd)\n",
-                               bootfile_path_size, path_len);
-
-               return -1;
-       }
-
-       strncpy(bootfile_path, bootfile, path_len);
-
- ret:
-       bootfile_path[path_len] = '\0';
-
-       return 1;
-}
-
-static int (*do_getfile)(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr);
-
-#ifdef CONFIG_CMD_NET
-static int do_get_tftp(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
-{
-       char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
-
-       tftp_argv[1] = file_addr;
-       tftp_argv[2] = (void *)file_path;
-
-       if (do_tftpb(cmdtp, 0, 3, tftp_argv))
-               return -ENOENT;
-
-       return 1;
-}
-#endif
-
-static char *fs_argv[5];
-
-static int do_get_ext2(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
-{
-#ifdef CONFIG_CMD_EXT2
-       fs_argv[0] = "ext2load";
-       fs_argv[3] = file_addr;
-       fs_argv[4] = (void *)file_path;
-
-       if (!do_ext2load(cmdtp, 0, 5, fs_argv))
-               return 1;
-#endif
-       return -ENOENT;
-}
-
-static int do_get_fat(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
-{
-#ifdef CONFIG_CMD_FAT
-       fs_argv[0] = "fatload";
-       fs_argv[3] = file_addr;
-       fs_argv[4] = (void *)file_path;
-
-       if (!do_fat_fsload(cmdtp, 0, 5, fs_argv))
-               return 1;
-#endif
-       return -ENOENT;
-}
-
-static int do_get_any(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
-{
-#ifdef CONFIG_CMD_FS_GENERIC
-       fs_argv[0] = "load";
-       fs_argv[3] = file_addr;
-       fs_argv[4] = (void *)file_path;
-
-       if (!do_load(cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
-               return 1;
-#endif
-       return -ENOENT;
-}
-
-/*
- * As in pxelinux, paths to files referenced from files we retrieve are
- * relative to the location of bootfile. get_relfile takes such a path and
- * joins it with the bootfile path to get the full path to the target file. If
- * the bootfile path is NULL, we use file_path as is.
- *
- * Returns 1 for success, or < 0 on error.
- */
-static int get_relfile(cmd_tbl_t *cmdtp, const char *file_path,
-       unsigned long file_addr)
-{
-       size_t path_len;
-       char relfile[MAX_TFTP_PATH_LEN+1];
-       char addr_buf[18];
-       int err;
-
-       err = get_bootfile_path(file_path, relfile, sizeof(relfile));
-
-       if (err < 0)
-               return err;
-
-       path_len = strlen(file_path);
-       path_len += strlen(relfile);
-
-       if (path_len > MAX_TFTP_PATH_LEN) {
-               printf("Base path too long (%s%s)\n",
-                                       relfile,
-                                       file_path);
-
-               return -ENAMETOOLONG;
-       }
-
-       strcat(relfile, file_path);
-
-       printf("Retrieving file: %s\n", relfile);
-
-       sprintf(addr_buf, "%lx", file_addr);
-
-       return do_getfile(cmdtp, relfile, addr_buf);
-}
-
-/*
- * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
- * 'bootfile' was specified in the environment, the path to bootfile will be
- * prepended to 'file_path' and the resulting path will be used.
- *
- * Returns 1 on success, or < 0 for error.
- */
-static int get_pxe_file(cmd_tbl_t *cmdtp, const char *file_path,
-       unsigned long file_addr)
-{
-       unsigned long config_file_size;
-       char *tftp_filesize;
-       int err;
-       char *buf;
-
-       err = get_relfile(cmdtp, file_path, file_addr);
-
-       if (err < 0)
-               return err;
-
-       /*
-        * the file comes without a NUL byte at the end, so find out its size
-        * and add the NUL byte.
-        */
-       tftp_filesize = from_env("filesize");
-
-       if (!tftp_filesize)
-               return -ENOENT;
-
-       if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
-               return -EINVAL;
-
-       buf = map_sysmem(file_addr + config_file_size, 1);
-       *buf = '\0';
-       unmap_sysmem(buf);
-
-       return 1;
-}
-
-#ifdef CONFIG_CMD_NET
-
-#define PXELINUX_DIR "pxelinux.cfg/"
-
-/*
- * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
- * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
- * from the bootfile path, as described above.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int get_pxelinux_path(cmd_tbl_t *cmdtp, const char *file,
-       unsigned long pxefile_addr_r)
-{
-       size_t base_len = strlen(PXELINUX_DIR);
-       char path[MAX_TFTP_PATH_LEN+1];
-
-       if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
-               printf("path (%s%s) too long, skipping\n",
-                               PXELINUX_DIR, file);
-               return -ENAMETOOLONG;
-       }
-
-       sprintf(path, PXELINUX_DIR "%s", file);
-
-       return get_pxe_file(cmdtp, path, pxefile_addr_r);
-}
-
-/*
- * Looks for a pxe file with a name based on the pxeuuid environment variable.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int pxe_uuid_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
-{
-       char *uuid_str;
-
-       uuid_str = from_env("pxeuuid");
-
-       if (!uuid_str)
-               return -ENOENT;
-
-       return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
-}
-
-/*
- * Looks for a pxe file with a name based on the 'ethaddr' environment
- * variable.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int pxe_mac_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
-{
-       char mac_str[21];
-       int err;
-
-       err = format_mac_pxe(mac_str, sizeof(mac_str));
-
-       if (err < 0)
-               return err;
-
-       return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
-}
-
-/*
- * Looks for pxe files with names based on our IP address. See pxelinux
- * documentation for details on what these file names look like.  We match
- * that exactly.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int pxe_ipaddr_paths(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r)
-{
-       char ip_addr[9];
-       int mask_pos, err;
-
-       sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
-
-       for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
-               err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
-
-               if (err > 0)
-                       return err;
-
-               ip_addr[mask_pos] = '\0';
-       }
-
-       return -ENOENT;
-}
-
-/*
- * Entry point for the 'pxe get' command.
- * This Follows pxelinux's rules to download a config file from a tftp server.
- * The file is stored at the location given by the pxefile_addr_r environment
- * variable, which must be set.
- *
- * UUID comes from pxeuuid env variable, if defined
- * MAC addr comes from ethaddr env variable, if defined
- * IP
- *
- * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
- *
- * Returns 0 on success or 1 on error.
- */
-static int
-do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *pxefile_addr_str;
-       unsigned long pxefile_addr_r;
-       int err, i = 0;
-
-       do_getfile = do_get_tftp;
-
-       if (argc != 1)
-               return CMD_RET_USAGE;
-
-       pxefile_addr_str = from_env("pxefile_addr_r");
-
-       if (!pxefile_addr_str)
-               return 1;
-
-       err = strict_strtoul(pxefile_addr_str, 16,
-                               (unsigned long *)&pxefile_addr_r);
-       if (err < 0)
-               return 1;
-
-       /*
-        * Keep trying paths until we successfully get a file we're looking
-        * for.
-        */
-       if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
-           pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
-           pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
-               printf("Config file found\n");
-
-               return 0;
-       }
-
-       while (pxe_default_paths[i]) {
-               if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
-                                     pxefile_addr_r) > 0) {
-                       printf("Config file found\n");
-                       return 0;
-               }
-               i++;
-       }
-
-       printf("Config file not found\n");
-
-       return 1;
-}
-#endif
-
-/*
- * Wrapper to make it easier to store the file at file_path in the location
- * specified by envaddr_name. file_path will be joined to the bootfile path,
- * if any is specified.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path, const char *envaddr_name)
-{
-       unsigned long file_addr;
-       char *envaddr;
-
-       envaddr = from_env(envaddr_name);
-
-       if (!envaddr)
-               return -ENOENT;
-
-       if (strict_strtoul(envaddr, 16, &file_addr) < 0)
-               return -EINVAL;
-
-       return get_relfile(cmdtp, file_path, file_addr);
-}
-
-/*
- * A note on the pxe file parser.
- *
- * We're parsing files that use syslinux grammar, which has a few quirks.
- * String literals must be recognized based on context - there is no
- * quoting or escaping support. There's also nothing to explicitly indicate
- * when a label section completes. We deal with that by ending a label
- * section whenever we see a line that doesn't include.
- *
- * As with the syslinux family, this same file format could be reused in the
- * future for non pxe purposes. The only action it takes during parsing that
- * would throw this off is handling of include files. It assumes we're using
- * pxe, and does a tftp download of a file listed as an include file in the
- * middle of the parsing operation. That could be handled by refactoring it to
- * take a 'include file getter' function.
- */
-
-/*
- * Describes a single label given in a pxe file.
- *
- * Create these with the 'label_create' function given below.
- *
- * name - the name of the menu as given on the 'menu label' line.
- * kernel - the path to the kernel file to use for this label.
- * append - kernel command line to use when booting this label
- * initrd - path to the initrd to use for this label.
- * attempted - 0 if we haven't tried to boot this label, 1 if we have.
- * localboot - 1 if this label specified 'localboot', 0 otherwise.
- * list - lets these form a list, which a pxe_menu struct will hold.
- */
-struct pxe_label {
-       char num[4];
-       char *name;
-       char *menu;
-       char *kernel;
-       char *append;
-       char *initrd;
-       char *fdt;
-       char *fdtdir;
-       int ipappend;
-       int attempted;
-       int localboot;
-       int localboot_val;
-       struct list_head list;
-};
-
-/*
- * Describes a pxe menu as given via pxe files.
- *
- * title - the name of the menu as given by a 'menu title' line.
- * default_label - the name of the default label, if any.
- * timeout - time in tenths of a second to wait for a user key-press before
- *           booting the default label.
- * prompt - if 0, don't prompt for a choice unless the timeout period is
- *          interrupted.  If 1, always prompt for a choice regardless of
- *          timeout.
- * labels - a list of labels defined for the menu.
- */
-struct pxe_menu {
-       char *title;
-       char *default_label;
-       int timeout;
-       int prompt;
-       struct list_head labels;
-};
-
-/*
- * Allocates memory for and initializes a pxe_label. This uses malloc, so the
- * result must be free()'d to reclaim the memory.
- *
- * Returns NULL if malloc fails.
- */
-static struct pxe_label *label_create(void)
-{
-       struct pxe_label *label;
-
-       label = malloc(sizeof(struct pxe_label));
-
-       if (!label)
-               return NULL;
-
-       memset(label, 0, sizeof(struct pxe_label));
-
-       return label;
-}
-
-/*
- * Free the memory used by a pxe_label, including that used by its name,
- * kernel, append and initrd members, if they're non NULL.
- *
- * So - be sure to only use dynamically allocated memory for the members of
- * the pxe_label struct, unless you want to clean it up first. These are
- * currently only created by the pxe file parsing code.
- */
-static void label_destroy(struct pxe_label *label)
-{
-       if (label->name)
-               free(label->name);
-
-       if (label->kernel)
-               free(label->kernel);
-
-       if (label->append)
-               free(label->append);
-
-       if (label->initrd)
-               free(label->initrd);
-
-       if (label->fdt)
-               free(label->fdt);
-
-       if (label->fdtdir)
-               free(label->fdtdir);
-
-       free(label);
-}
-
-/*
- * Print a label and its string members if they're defined.
- *
- * This is passed as a callback to the menu code for displaying each
- * menu entry.
- */
-static void label_print(void *data)
-{
-       struct pxe_label *label = data;
-       const char *c = label->menu ? label->menu : label->name;
-
-       printf("%s:\t%s\n", label->num, c);
-}
-
-/*
- * Boot a label that specified 'localboot'. This requires that the 'localcmd'
- * environment variable is defined. Its contents will be executed as U-boot
- * command.  If the label specified an 'append' line, its contents will be
- * used to overwrite the contents of the 'bootargs' environment variable prior
- * to running 'localcmd'.
- *
- * Returns 1 on success or < 0 on error.
- */
-static int label_localboot(struct pxe_label *label)
-{
-       char *localcmd;
-
-       localcmd = from_env("localcmd");
-
-       if (!localcmd)
-               return -ENOENT;
-
-       if (label->append) {
-               char bootargs[CONFIG_SYS_CBSIZE];
-
-               cli_simple_process_macros(label->append, bootargs);
-               setenv("bootargs", bootargs);
-       }
-
-       debug("running: %s\n", localcmd);
-
-       return run_command_list(localcmd, strlen(localcmd), 0);
-}
-
-/*
- * Boot according to the contents of a pxe_label.
- *
- * If we can't boot for any reason, we return.  A successful boot never
- * returns.
- *
- * The kernel will be stored in the location given by the 'kernel_addr_r'
- * environment variable.
- *
- * If the label specifies an initrd file, it will be stored in the location
- * given by the 'ramdisk_addr_r' environment variable.
- *
- * If the label specifies an 'append' line, its contents will overwrite that
- * of the 'bootargs' environment variable.
- */
-static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
-{
-       char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
-       char initrd_str[22];
-       char mac_str[29] = "";
-       char ip_str[68] = "";
-       int bootm_argc = 3;
-       int len = 0;
-       ulong kernel_addr;
-       void *buf;
-
-       label_print(label);
-
-       label->attempted = 1;
-
-       if (label->localboot) {
-               if (label->localboot_val >= 0)
-                       label_localboot(label);
-               return 0;
-       }
-
-       if (label->kernel == NULL) {
-               printf("No kernel given, skipping %s\n",
-                               label->name);
-               return 1;
-       }
-
-       if (label->initrd) {
-               if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
-                       printf("Skipping %s for failure retrieving initrd\n",
-                                       label->name);
-                       return 1;
-               }
-
-               bootm_argv[2] = initrd_str;
-               strcpy(bootm_argv[2], getenv("ramdisk_addr_r"));
-               strcat(bootm_argv[2], ":");
-               strcat(bootm_argv[2], getenv("filesize"));
-       } else {
-               bootm_argv[2] = "-";
-       }
-
-       if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
-               printf("Skipping %s for failure retrieving kernel\n",
-                               label->name);
-               return 1;
-       }
-
-       if (label->ipappend & 0x1) {
-               sprintf(ip_str, " ip=%s:%s:%s:%s",
-                       getenv("ipaddr"), getenv("serverip"),
-                       getenv("gatewayip"), getenv("netmask"));
-       }
-
-#ifdef CONFIG_CMD_NET
-       if (label->ipappend & 0x2) {
-               int err;
-               strcpy(mac_str, " BOOTIF=");
-               err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
-               if (err < 0)
-                       mac_str[0] = '\0';
-       }
-#endif
-
-       if ((label->ipappend & 0x3) || label->append) {
-               char bootargs[CONFIG_SYS_CBSIZE] = "";
-               char finalbootargs[CONFIG_SYS_CBSIZE];
-
-               if (strlen(label->append ?: "") +
-                   strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
-                       printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
-                              strlen(label->append ?: ""),
-                              strlen(ip_str), strlen(mac_str),
-                              sizeof(bootargs));
-                       return 1;
-               }
-
-               if (label->append)
-                       strcpy(bootargs, label->append);
-               strcat(bootargs, ip_str);
-               strcat(bootargs, mac_str);
-
-               cli_simple_process_macros(bootargs, finalbootargs);
-               setenv("bootargs", finalbootargs);
-               printf("append: %s\n", finalbootargs);
-       }
-
-       bootm_argv[1] = getenv("kernel_addr_r");
-
-       /*
-        * fdt usage is optional:
-        * It handles the following scenarios. All scenarios are exclusive
-        *
-        * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
-        * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
-        * and adjust argc appropriately.
-        *
-        * Scenario 2: If there is an fdt_addr specified, pass it along to
-        * bootm, and adjust argc appropriately.
-        *
-        * Scenario 3: fdt blob is not available.
-        */
-       bootm_argv[3] = getenv("fdt_addr_r");
-
-       /* if fdt label is defined then get fdt from server */
-       if (bootm_argv[3]) {
-               char *fdtfile = NULL;
-               char *fdtfilefree = NULL;
-
-               if (label->fdt) {
-                       fdtfile = label->fdt;
-               } else if (label->fdtdir) {
-                       char *f1, *f2, *f3, *f4, *slash;
-
-                       f1 = getenv("fdtfile");
-                       if (f1) {
-                               f2 = "";
-                               f3 = "";
-                               f4 = "";
-                       } else {
-                               /*
-                                * For complex cases where this code doesn't
-                                * generate the correct filename, the board
-                                * code should set $fdtfile during early boot,
-                                * or the boot scripts should set $fdtfile
-                                * before invoking "pxe" or "sysboot".
-                                */
-                               f1 = getenv("soc");
-                               f2 = "-";
-                               f3 = getenv("board");
-                               f4 = ".dtb";
-                       }
-
-                       len = strlen(label->fdtdir);
-                       if (!len)
-                               slash = "./";
-                       else if (label->fdtdir[len - 1] != '/')
-                               slash = "/";
-                       else
-                               slash = "";
-
-                       len = strlen(label->fdtdir) + strlen(slash) +
-                               strlen(f1) + strlen(f2) + strlen(f3) +
-                               strlen(f4) + 1;
-                       fdtfilefree = malloc(len);
-                       if (!fdtfilefree) {
-                               printf("malloc fail (FDT filename)\n");
-                               return 1;
-                       }
-
-                       snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
-                                label->fdtdir, slash, f1, f2, f3, f4);
-                       fdtfile = fdtfilefree;
-               }
-
-               if (fdtfile) {
-                       int err = get_relfile_envaddr(cmdtp, fdtfile, "fdt_addr_r");
-                       free(fdtfilefree);
-                       if (err < 0) {
-                               printf("Skipping %s for failure retrieving fdt\n",
-                                               label->name);
-                               return 1;
-                       }
-               } else {
-                       bootm_argv[3] = NULL;
-               }
-       }
-
-       if (!bootm_argv[3])
-               bootm_argv[3] = getenv("fdt_addr");
-
-       if (bootm_argv[3])
-               bootm_argc = 4;
-
-       kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
-       buf = map_sysmem(kernel_addr, 0);
-       /* Try bootm for legacy and FIT format image */
-       if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
-               do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
-#ifdef CONFIG_CMD_BOOTI
-       /* Try booting an AArch64 Linux kernel image */
-       else
-               do_booti(cmdtp, 0, bootm_argc, bootm_argv);
-#elif defined(CONFIG_CMD_BOOTZ)
-       /* Try booting a Image */
-       else
-               do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
-#endif
-       unmap_sysmem(buf);
-       return 1;
-}
-
-/*
- * Tokens for the pxe file parser.
- */
-enum token_type {
-       T_EOL,
-       T_STRING,
-       T_EOF,
-       T_MENU,
-       T_TITLE,
-       T_TIMEOUT,
-       T_LABEL,
-       T_KERNEL,
-       T_LINUX,
-       T_APPEND,
-       T_INITRD,
-       T_LOCALBOOT,
-       T_DEFAULT,
-       T_PROMPT,
-       T_INCLUDE,
-       T_FDT,
-       T_FDTDIR,
-       T_ONTIMEOUT,
-       T_IPAPPEND,
-       T_INVALID
-};
-
-/*
- * A token - given by a value and a type.
- */
-struct token {
-       char *val;
-       enum token_type type;
-};
-
-/*
- * Keywords recognized.
- */
-static const struct token keywords[] = {
-       {"menu", T_MENU},
-       {"title", T_TITLE},
-       {"timeout", T_TIMEOUT},
-       {"default", T_DEFAULT},
-       {"prompt", T_PROMPT},
-       {"label", T_LABEL},
-       {"kernel", T_KERNEL},
-       {"linux", T_LINUX},
-       {"localboot", T_LOCALBOOT},
-       {"append", T_APPEND},
-       {"initrd", T_INITRD},
-       {"include", T_INCLUDE},
-       {"devicetree", T_FDT},
-       {"fdt", T_FDT},
-       {"devicetreedir", T_FDTDIR},
-       {"fdtdir", T_FDTDIR},
-       {"ontimeout", T_ONTIMEOUT,},
-       {"ipappend", T_IPAPPEND,},
-       {NULL, T_INVALID}
-};
-
-/*
- * Since pxe(linux) files don't have a token to identify the start of a
- * literal, we have to keep track of when we're in a state where a literal is
- * expected vs when we're in a state a keyword is expected.
- */
-enum lex_state {
-       L_NORMAL = 0,
-       L_KEYWORD,
-       L_SLITERAL
-};
-
-/*
- * get_string retrieves a string from *p and stores it as a token in
- * *t.
- *
- * get_string used for scanning both string literals and keywords.
- *
- * Characters from *p are copied into t-val until a character equal to
- * delim is found, or a NUL byte is reached. If delim has the special value of
- * ' ', any whitespace character will be used as a delimiter.
- *
- * If lower is unequal to 0, uppercase characters will be converted to
- * lowercase in the result. This is useful to make keywords case
- * insensitive.
- *
- * The location of *p is updated to point to the first character after the end
- * of the token - the ending delimiter.
- *
- * On success, the new value of t->val is returned. Memory for t->val is
- * allocated using malloc and must be free()'d to reclaim it.  If insufficient
- * memory is available, NULL is returned.
- */
-static char *get_string(char **p, struct token *t, char delim, int lower)
-{
-       char *b, *e;
-       size_t len, i;
-
-       /*
-        * b and e both start at the beginning of the input stream.
-        *
-        * e is incremented until we find the ending delimiter, or a NUL byte
-        * is reached. Then, we take e - b to find the length of the token.
-        */
-       b = e = *p;
-
-       while (*e) {
-               if ((delim == ' ' && isspace(*e)) || delim == *e)
-                       break;
-               e++;
-       }
-
-       len = e - b;
-
-       /*
-        * Allocate memory to hold the string, and copy it in, converting
-        * characters to lowercase if lower is != 0.
-        */
-       t->val = malloc(len + 1);
-       if (!t->val)
-               return NULL;
-
-       for (i = 0; i < len; i++, b++) {
-               if (lower)
-                       t->val[i] = tolower(*b);
-               else
-                       t->val[i] = *b;
-       }
-
-       t->val[len] = '\0';
-
-       /*
-        * Update *p so the caller knows where to continue scanning.
-        */
-       *p = e;
-
-       t->type = T_STRING;
-
-       return t->val;
-}
-
-/*
- * Populate a keyword token with a type and value.
- */
-static void get_keyword(struct token *t)
-{
-       int i;
-
-       for (i = 0; keywords[i].val; i++) {
-               if (!strcmp(t->val, keywords[i].val)) {
-                       t->type = keywords[i].type;
-                       break;
-               }
-       }
-}
-
-/*
- * Get the next token.  We have to keep track of which state we're in to know
- * if we're looking to get a string literal or a keyword.
- *
- * *p is updated to point at the first character after the current token.
- */
-static void get_token(char **p, struct token *t, enum lex_state state)
-{
-       char *c = *p;
-
-       t->type = T_INVALID;
-
-       /* eat non EOL whitespace */
-       while (isblank(*c))
-               c++;
-
-       /*
-        * eat comments. note that string literals can't begin with #, but
-        * can contain a # after their first character.
-        */
-       if (*c == '#') {
-               while (*c && *c != '\n')
-                       c++;
-       }
-
-       if (*c == '\n') {
-               t->type = T_EOL;
-               c++;
-       } else if (*c == '\0') {
-               t->type = T_EOF;
-               c++;
-       } else if (state == L_SLITERAL) {
-               get_string(&c, t, '\n', 0);
-       } else if (state == L_KEYWORD) {
-               /*
-                * when we expect a keyword, we first get the next string
-                * token delimited by whitespace, and then check if it
-                * matches a keyword in our keyword list. if it does, it's
-                * converted to a keyword token of the appropriate type, and
-                * if not, it remains a string token.
-                */
-               get_string(&c, t, ' ', 1);
-               get_keyword(t);
-       }
-
-       *p = c;
-}
-
-/*
- * Increment *c until we get to the end of the current line, or EOF.
- */
-static void eol_or_eof(char **c)
-{
-       while (**c && **c != '\n')
-               (*c)++;
-}
-
-/*
- * All of these parse_* functions share some common behavior.
- *
- * They finish with *c pointing after the token they parse, and return 1 on
- * success, or < 0 on error.
- */
-
-/*
- * Parse a string literal and store a pointer it at *dst. String literals
- * terminate at the end of the line.
- */
-static int parse_sliteral(char **c, char **dst)
-{
-       struct token t;
-       char *s = *c;
-
-       get_token(c, &t, L_SLITERAL);
-
-       if (t.type != T_STRING) {
-               printf("Expected string literal: %.*s\n", (int)(*c - s), s);
-               return -EINVAL;
-       }
-
-       *dst = t.val;
-
-       return 1;
-}
-
-/*
- * Parse a base 10 (unsigned) integer and store it at *dst.
- */
-static int parse_integer(char **c, int *dst)
-{
-       struct token t;
-       char *s = *c;
-
-       get_token(c, &t, L_SLITERAL);
-
-       if (t.type != T_STRING) {
-               printf("Expected string: %.*s\n", (int)(*c - s), s);
-               return -EINVAL;
-       }
-
-       *dst = simple_strtol(t.val, NULL, 10);
-
-       free(t.val);
-
-       return 1;
-}
-
-static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
-       struct pxe_menu *cfg, int nest_level);
-
-/*
- * Parse an include statement, and retrieve and parse the file it mentions.
- *
- * base should point to a location where it's safe to store the file, and
- * nest_level should indicate how many nested includes have occurred. For this
- * include, nest_level has already been incremented and doesn't need to be
- * incremented here.
- */
-static int handle_include(cmd_tbl_t *cmdtp, char **c, unsigned long base,
-                               struct pxe_menu *cfg, int nest_level)
-{
-       char *include_path;
-       char *s = *c;
-       int err;
-       char *buf;
-       int ret;
-
-       err = parse_sliteral(c, &include_path);
-
-       if (err < 0) {
-               printf("Expected include path: %.*s\n",
-                                (int)(*c - s), s);
-               return err;
-       }
-
-       err = get_pxe_file(cmdtp, include_path, base);
-
-       if (err < 0) {
-               printf("Couldn't retrieve %s\n", include_path);
-               return err;
-       }
-
-       buf = map_sysmem(base, 0);
-       ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
-       unmap_sysmem(buf);
-
-       return ret;
-}
-
-/*
- * Parse lines that begin with 'menu'.
- *
- * base and nest are provided to handle the 'menu include' case.
- *
- * base should point to a location where it's safe to store the included file.
- *
- * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
- * a file it includes, 3 when parsing a file included by that file, and so on.
- */
-static int parse_menu(cmd_tbl_t *cmdtp, char **c, struct pxe_menu *cfg,
-                               unsigned long base, int nest_level)
-{
-       struct token t;
-       char *s = *c;
-       int err = 0;
-
-       get_token(c, &t, L_KEYWORD);
-
-       switch (t.type) {
-       case T_TITLE:
-               err = parse_sliteral(c, &cfg->title);
-
-               break;
-
-       case T_INCLUDE:
-               err = handle_include(cmdtp, c, base, cfg,
-                                               nest_level + 1);
-               break;
-
-       default:
-               printf("Ignoring malformed menu command: %.*s\n",
-                               (int)(*c - s), s);
-       }
-
-       if (err < 0)
-               return err;
-
-       eol_or_eof(c);
-
-       return 1;
-}
-
-/*
- * Handles parsing a 'menu line' when we're parsing a label.
- */
-static int parse_label_menu(char **c, struct pxe_menu *cfg,
-                               struct pxe_label *label)
-{
-       struct token t;
-       char *s;
-
-       s = *c;
-
-       get_token(c, &t, L_KEYWORD);
-
-       switch (t.type) {
-       case T_DEFAULT:
-               if (!cfg->default_label)
-                       cfg->default_label = strdup(label->name);
-
-               if (!cfg->default_label)
-                       return -ENOMEM;
-
-               break;
-       case T_LABEL:
-               parse_sliteral(c, &label->menu);
-               break;
-       default:
-               printf("Ignoring malformed menu command: %.*s\n",
-                               (int)(*c - s), s);
-       }
-
-       eol_or_eof(c);
-
-       return 0;
-}
-
-/*
- * Parses a label and adds it to the list of labels for a menu.
- *
- * A label ends when we either get to the end of a file, or
- * get some input we otherwise don't have a handler defined
- * for.
- *
- */
-static int parse_label(char **c, struct pxe_menu *cfg)
-{
-       struct token t;
-       int len;
-       char *s = *c;
-       struct pxe_label *label;
-       int err;
-
-       label = label_create();
-       if (!label)
-               return -ENOMEM;
-
-       err = parse_sliteral(c, &label->name);
-       if (err < 0) {
-               printf("Expected label name: %.*s\n", (int)(*c - s), s);
-               label_destroy(label);
-               return -EINVAL;
-       }
-
-       list_add_tail(&label->list, &cfg->labels);
-
-       while (1) {
-               s = *c;
-               get_token(c, &t, L_KEYWORD);
-
-               err = 0;
-               switch (t.type) {
-               case T_MENU:
-                       err = parse_label_menu(c, cfg, label);
-                       break;
-
-               case T_KERNEL:
-               case T_LINUX:
-                       err = parse_sliteral(c, &label->kernel);
-                       break;
-
-               case T_APPEND:
-                       err = parse_sliteral(c, &label->append);
-                       if (label->initrd)
-                               break;
-                       s = strstr(label->append, "initrd=");
-                       if (!s)
-                               break;
-                       s += 7;
-                       len = (int)(strchr(s, ' ') - s);
-                       label->initrd = malloc(len + 1);
-                       strncpy(label->initrd, s, len);
-                       label->initrd[len] = '\0';
-
-                       break;
-
-               case T_INITRD:
-                       if (!label->initrd)
-                               err = parse_sliteral(c, &label->initrd);
-                       break;
-
-               case T_FDT:
-                       if (!label->fdt)
-                               err = parse_sliteral(c, &label->fdt);
-                       break;
-
-               case T_FDTDIR:
-                       if (!label->fdtdir)
-                               err = parse_sliteral(c, &label->fdtdir);
-                       break;
-
-               case T_LOCALBOOT:
-                       label->localboot = 1;
-                       err = parse_integer(c, &label->localboot_val);
-                       break;
-
-               case T_IPAPPEND:
-                       err = parse_integer(c, &label->ipappend);
-                       break;
-
-               case T_EOL:
-                       break;
-
-               default:
-                       /*
-                        * put the token back! we don't want it - it's the end
-                        * of a label and whatever token this is, it's
-                        * something for the menu level context to handle.
-                        */
-                       *c = s;
-                       return 1;
-               }
-
-               if (err < 0)
-                       return err;
-       }
-}
-
-/*
- * This 16 comes from the limit pxelinux imposes on nested includes.
- *
- * There is no reason at all we couldn't do more, but some limit helps prevent
- * infinite (until crash occurs) recursion if a file tries to include itself.
- */
-#define MAX_NEST_LEVEL 16
-
-/*
- * Entry point for parsing a menu file. nest_level indicates how many times
- * we've nested in includes.  It will be 1 for the top level menu file.
- *
- * Returns 1 on success, < 0 on error.
- */
-static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
-                               struct pxe_menu *cfg, int nest_level)
-{
-       struct token t;
-       char *s, *b, *label_name;
-       int err;
-
-       b = p;
-
-       if (nest_level > MAX_NEST_LEVEL) {
-               printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
-               return -EMLINK;
-       }
-
-       while (1) {
-               s = p;
-
-               get_token(&p, &t, L_KEYWORD);
-
-               err = 0;
-               switch (t.type) {
-               case T_MENU:
-                       cfg->prompt = 1;
-                       err = parse_menu(cmdtp, &p, cfg,
-                               base + ALIGN(strlen(b) + 1, 4),
-                               nest_level);
-                       break;
-
-               case T_TIMEOUT:
-                       err = parse_integer(&p, &cfg->timeout);
-                       break;
-
-               case T_LABEL:
-                       err = parse_label(&p, cfg);
-                       break;
-
-               case T_DEFAULT:
-               case T_ONTIMEOUT:
-                       err = parse_sliteral(&p, &label_name);
-
-                       if (label_name) {
-                               if (cfg->default_label)
-                                       free(cfg->default_label);
-
-                               cfg->default_label = label_name;
-                       }
-
-                       break;
-
-               case T_INCLUDE:
-                       err = handle_include(cmdtp, &p,
-                               base + ALIGN(strlen(b), 4), cfg,
-                               nest_level + 1);
-                       break;
-
-               case T_PROMPT:
-                       eol_or_eof(&p);
-                       break;
-
-               case T_EOL:
-                       break;
-
-               case T_EOF:
-                       return 1;
-
-               default:
-                       printf("Ignoring unknown command: %.*s\n",
-                                                       (int)(p - s), s);
-                       eol_or_eof(&p);
-               }
-
-               if (err < 0)
-                       return err;
-       }
-}
-
-/*
- * Free the memory used by a pxe_menu and its labels.
- */
-static void destroy_pxe_menu(struct pxe_menu *cfg)
-{
-       struct list_head *pos, *n;
-       struct pxe_label *label;
-
-       if (cfg->title)
-               free(cfg->title);
-
-       if (cfg->default_label)
-               free(cfg->default_label);
-
-       list_for_each_safe(pos, n, &cfg->labels) {
-               label = list_entry(pos, struct pxe_label, list);
-
-               label_destroy(label);
-       }
-
-       free(cfg);
-}
-
-/*
- * Entry point for parsing a pxe file. This is only used for the top level
- * file.
- *
- * Returns NULL if there is an error, otherwise, returns a pointer to a
- * pxe_menu struct populated with the results of parsing the pxe file (and any
- * files it includes). The resulting pxe_menu struct can be free()'d by using
- * the destroy_pxe_menu() function.
- */
-static struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg)
-{
-       struct pxe_menu *cfg;
-       char *buf;
-       int r;
-
-       cfg = malloc(sizeof(struct pxe_menu));
-
-       if (!cfg)
-               return NULL;
-
-       memset(cfg, 0, sizeof(struct pxe_menu));
-
-       INIT_LIST_HEAD(&cfg->labels);
-
-       buf = map_sysmem(menucfg, 0);
-       r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
-       unmap_sysmem(buf);
-
-       if (r < 0) {
-               destroy_pxe_menu(cfg);
-               return NULL;
-       }
-
-       return cfg;
-}
-
-/*
- * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
- * menu code.
- */
-static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
-{
-       struct pxe_label *label;
-       struct list_head *pos;
-       struct menu *m;
-       int err;
-       int i = 1;
-       char *default_num = NULL;
-
-       /*
-        * Create a menu and add items for all the labels.
-        */
-       m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print,
-                       NULL, NULL);
-
-       if (!m)
-               return NULL;
-
-       list_for_each(pos, &cfg->labels) {
-               label = list_entry(pos, struct pxe_label, list);
-
-               sprintf(label->num, "%d", i++);
-               if (menu_item_add(m, label->num, label) != 1) {
-                       menu_destroy(m);
-                       return NULL;
-               }
-               if (cfg->default_label &&
-                   (strcmp(label->name, cfg->default_label) == 0))
-                       default_num = label->num;
-
-       }
-
-       /*
-        * After we've created items for each label in the menu, set the
-        * menu's default label if one was specified.
-        */
-       if (default_num) {
-               err = menu_default_set(m, default_num);
-               if (err != 1) {
-                       if (err != -ENOENT) {
-                               menu_destroy(m);
-                               return NULL;
-                       }
-
-                       printf("Missing default: %s\n", cfg->default_label);
-               }
-       }
-
-       return m;
-}
-
-/*
- * Try to boot any labels we have yet to attempt to boot.
- */
-static void boot_unattempted_labels(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
-{
-       struct list_head *pos;
-       struct pxe_label *label;
-
-       list_for_each(pos, &cfg->labels) {
-               label = list_entry(pos, struct pxe_label, list);
-
-               if (!label->attempted)
-                       label_boot(cmdtp, label);
-       }
-}
-
-/*
- * Boot the system as prescribed by a pxe_menu.
- *
- * Use the menu system to either get the user's choice or the default, based
- * on config or user input.  If there is no default or user's choice,
- * attempted to boot labels in the order they were given in pxe files.
- * If the default or user's choice fails to boot, attempt to boot other
- * labels in the order they were given in pxe files.
- *
- * If this function returns, there weren't any labels that successfully
- * booted, or the user interrupted the menu selection via ctrl+c.
- */
-static void handle_pxe_menu(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
-{
-       void *choice;
-       struct menu *m;
-       int err;
-
-       m = pxe_menu_to_menu(cfg);
-       if (!m)
-               return;
-
-       err = menu_get_choice(m, &choice);
-
-       menu_destroy(m);
-
-       /*
-        * err == 1 means we got a choice back from menu_get_choice.
-        *
-        * err == -ENOENT if the menu was setup to select the default but no
-        * default was set. in that case, we should continue trying to boot
-        * labels that haven't been attempted yet.
-        *
-        * otherwise, the user interrupted or there was some other error and
-        * we give up.
-        */
-
-       if (err == 1) {
-               err = label_boot(cmdtp, choice);
-               if (!err)
-                       return;
-       } else if (err != -ENOENT) {
-               return;
-       }
-
-       boot_unattempted_labels(cmdtp, cfg);
-}
-
-#ifdef CONFIG_CMD_NET
-/*
- * Boots a system using a pxe file
- *
- * Returns 0 on success, 1 on error.
- */
-static int
-do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long pxefile_addr_r;
-       struct pxe_menu *cfg;
-       char *pxefile_addr_str;
-
-       do_getfile = do_get_tftp;
-
-       if (argc == 1) {
-               pxefile_addr_str = from_env("pxefile_addr_r");
-               if (!pxefile_addr_str)
-                       return 1;
-
-       } else if (argc == 2) {
-               pxefile_addr_str = argv[1];
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
-               printf("Invalid pxefile address: %s\n", pxefile_addr_str);
-               return 1;
-       }
-
-       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
-
-       if (cfg == NULL) {
-               printf("Error parsing config file\n");
-               return 1;
-       }
-
-       handle_pxe_menu(cmdtp, cfg);
-
-       destroy_pxe_menu(cfg);
-
-       copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name));
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_pxe_sub[] = {
-       U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
-       U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
-};
-
-static int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *cp;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       is_pxe = true;
-
-       /* drop initial "pxe" arg */
-       argc--;
-       argv++;
-
-       cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
-
-       if (cp)
-               return cp->cmd(cmdtp, flag, argc, argv);
-
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       pxe, 3, 1, do_pxe,
-       "commands to get and boot from pxe files",
-       "get - try to retrieve a pxe file using tftp\npxe "
-       "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
-);
-#endif
-
-/*
- * Boots a system using a local disk syslinux/extlinux file
- *
- * Returns 0 on success, 1 on error.
- */
-static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long pxefile_addr_r;
-       struct pxe_menu *cfg;
-       char *pxefile_addr_str;
-       char *filename;
-       int prompt = 0;
-
-       is_pxe = false;
-
-       if (argc > 1 && strstr(argv[1], "-p")) {
-               prompt = 1;
-               argc--;
-               argv++;
-       }
-
-       if (argc < 4)
-               return cmd_usage(cmdtp);
-
-       if (argc < 5) {
-               pxefile_addr_str = from_env("pxefile_addr_r");
-               if (!pxefile_addr_str)
-                       return 1;
-       } else {
-               pxefile_addr_str = argv[4];
-       }
-
-       if (argc < 6)
-               filename = getenv("bootfile");
-       else {
-               filename = argv[5];
-               setenv("bootfile", filename);
-       }
-
-       if (strstr(argv[3], "ext2"))
-               do_getfile = do_get_ext2;
-       else if (strstr(argv[3], "fat"))
-               do_getfile = do_get_fat;
-       else if (strstr(argv[3], "any"))
-               do_getfile = do_get_any;
-       else {
-               printf("Invalid filesystem: %s\n", argv[3]);
-               return 1;
-       }
-       fs_argv[1] = argv[1];
-       fs_argv[2] = argv[2];
-
-       if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
-               printf("Invalid pxefile address: %s\n", pxefile_addr_str);
-               return 1;
-       }
-
-       if (get_pxe_file(cmdtp, filename, pxefile_addr_r) < 0) {
-               printf("Error reading config file\n");
-               return 1;
-       }
-
-       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
-
-       if (cfg == NULL) {
-               printf("Error parsing config file\n");
-               return 1;
-       }
-
-       if (prompt)
-               cfg->prompt = 1;
-
-       handle_pxe_menu(cmdtp, cfg);
-
-       destroy_pxe_menu(cfg);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       sysboot, 7, 1, do_sysboot,
-       "command to get and boot from syslinux files",
-       "[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n"
-       "    - load and parse syslinux menu file 'filename' from ext2, fat\n"
-       "      or any filesystem on 'dev' on 'interface' to address 'addr'"
-);
diff --git a/common/cmd_read.c b/common/cmd_read.c
deleted file mode 100644 (file)
index 8710288..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- */
-
-#include <common.h>
-#include <command.h>
-#include <part.h>
-
-int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *ep;
-       block_dev_desc_t *dev_desc = NULL;
-       int dev;
-       int part = 0;
-       disk_partition_t part_info;
-       ulong offset = 0u;
-       ulong limit = 0u;
-       void *addr;
-       uint blk;
-       uint cnt;
-
-       if (argc != 6) {
-               cmd_usage(cmdtp);
-               return 1;
-       }
-
-       dev = (int)simple_strtoul(argv[2], &ep, 16);
-       if (*ep) {
-               if (*ep != ':') {
-                       printf("Invalid block device %s\n", argv[2]);
-                       return 1;
-               }
-               part = (int)simple_strtoul(++ep, NULL, 16);
-       }
-
-       dev_desc = get_dev(argv[1], dev);
-       if (dev_desc == NULL) {
-               printf("Block device %s %d not supported\n", argv[1], dev);
-               return 1;
-       }
-
-       addr = (void *)simple_strtoul(argv[3], NULL, 16);
-       blk = simple_strtoul(argv[4], NULL, 16);
-       cnt = simple_strtoul(argv[5], NULL, 16);
-
-       if (part != 0) {
-               if (get_partition_info(dev_desc, part, &part_info)) {
-                       printf("Cannot find partition %d\n", part);
-                       return 1;
-               }
-               offset = part_info.start;
-               limit = part_info.size;
-       } else {
-               /* Largest address not available in block_dev_desc_t. */
-               limit = ~0;
-       }
-
-       if (cnt + blk > limit) {
-               printf("Read out of range\n");
-               return 1;
-       }
-
-       if (dev_desc->block_read(dev_desc, offset + blk, cnt, addr) < 0) {
-               printf("Error reading blocks\n");
-               return 1;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       read,   6,      0,      do_read,
-       "Load binary data from a partition",
-       "<interface> <dev[:part]> addr blk# cnt"
-);
diff --git a/common/cmd_reginfo.c b/common/cmd_reginfo.c
deleted file mode 100644 (file)
index 5f19e79..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * (C) Copyright 2000
- * Subodh Nijsure, SkyStream Networks, snijsure@skystream.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#if defined(CONFIG_8xx)
-#include <mpc8xx.h>
-#elif defined (CONFIG_4xx)
-extern void ppc4xx_reginfo(void);
-#elif defined (CONFIG_5xx)
-#include <mpc5xx.h>
-#elif defined (CONFIG_MPC5200)
-#include <mpc5xxx.h>
-#elif defined (CONFIG_MPC86xx)
-extern void mpc86xx_reginfo(void);
-#elif defined(CONFIG_MPC85xx)
-extern void mpc85xx_reginfo(void);
-#endif
-
-static int do_reginfo(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-#if defined(CONFIG_8xx)
-       volatile immap_t     *immap  = (immap_t *)CONFIG_SYS_IMMR;
-       volatile memctl8xx_t *memctl = &immap->im_memctl;
-       volatile sysconf8xx_t *sysconf = &immap->im_siu_conf;
-       volatile sit8xx_t *timers = &immap->im_sit;
-
-       /* Hopefully more PowerPC  knowledgable people will add code to display
-        * other useful registers
-        */
-
-       printf ("\nSystem Configuration registers\n"
-
-               "\tIMMR\t0x%08X\n", get_immr(0));
-
-       printf("\tSIUMCR\t0x%08X", sysconf->sc_siumcr);
-       printf("\tSYPCR\t0x%08X\n",sysconf->sc_sypcr);
-
-       printf("\tSWT\t0x%08X",    sysconf->sc_swt);
-       printf("\tSWSR\t0x%04X\n", sysconf->sc_swsr);
-
-       printf("\tSIPEND\t0x%08X\tSIMASK\t0x%08X\n",
-               sysconf->sc_sipend, sysconf->sc_simask);
-       printf("\tSIEL\t0x%08X\tSIVEC\t0x%08X\n",
-               sysconf->sc_siel, sysconf->sc_sivec);
-       printf("\tTESR\t0x%08X\tSDCR\t0x%08X\n",
-               sysconf->sc_tesr, sysconf->sc_sdcr);
-
-       printf ("Memory Controller Registers\n"
-
-               "\tBR0\t0x%08X\tOR0\t0x%08X \n", memctl->memc_br0, memctl->memc_or0);
-       printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", memctl->memc_br1, memctl->memc_or1);
-       printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", memctl->memc_br2, memctl->memc_or2);
-       printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", memctl->memc_br3, memctl->memc_or3);
-       printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", memctl->memc_br4, memctl->memc_or4);
-       printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", memctl->memc_br5, memctl->memc_or5);
-       printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", memctl->memc_br6, memctl->memc_or6);
-       printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", memctl->memc_br7, memctl->memc_or7);
-       printf ("\n"
-               "\tmamr\t0x%08X\tmbmr\t0x%08X \n",
-               memctl->memc_mamr, memctl->memc_mbmr );
-       printf("\tmstat\t0x%08X\tmptpr\t0x%08X \n",
-               memctl->memc_mstat, memctl->memc_mptpr );
-       printf("\tmdr\t0x%08X \n", memctl->memc_mdr);
-
-       printf ("\nSystem Integration Timers\n"
-               "\tTBSCR\t0x%08X\tRTCSC\t0x%08X \n",
-               timers->sit_tbscr, timers->sit_rtcsc);
-       printf("\tPISCR\t0x%08X \n", timers->sit_piscr);
-
-       /*
-        * May be some CPM info here?
-        */
-
-#elif defined (CONFIG_4xx)
-       ppc4xx_reginfo();
-#elif defined(CONFIG_5xx)
-
-       volatile immap_t        *immap  = (immap_t *)CONFIG_SYS_IMMR;
-       volatile memctl5xx_t    *memctl = &immap->im_memctl;
-       volatile sysconf5xx_t   *sysconf = &immap->im_siu_conf;
-       volatile sit5xx_t       *timers = &immap->im_sit;
-       volatile car5xx_t       *car = &immap->im_clkrst;
-       volatile uimb5xx_t      *uimb = &immap->im_uimb;
-
-       puts ("\nSystem Configuration registers\n");
-       printf("\tIMMR\t0x%08X\tSIUMCR\t0x%08X \n", get_immr(0), sysconf->sc_siumcr);
-       printf("\tSYPCR\t0x%08X\tSWSR\t0x%04X \n" ,sysconf->sc_sypcr, sysconf->sc_swsr);
-       printf("\tSIPEND\t0x%08X\tSIMASK\t0x%08X \n", sysconf->sc_sipend, sysconf->sc_simask);
-       printf("\tSIEL\t0x%08X\tSIVEC\t0x%08X \n", sysconf->sc_siel, sysconf->sc_sivec);
-       printf("\tTESR\t0x%08X\n", sysconf->sc_tesr);
-
-       puts ("\nMemory Controller Registers\n");
-       printf("\tBR0\t0x%08X\tOR0\t0x%08X \n", memctl->memc_br0, memctl->memc_or0);
-       printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", memctl->memc_br1, memctl->memc_or1);
-       printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", memctl->memc_br2, memctl->memc_or2);
-       printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", memctl->memc_br3, memctl->memc_or3);
-       printf("\tDMBR\t0x%08X\tDMOR\t0x%08X \n", memctl->memc_dmbr, memctl->memc_dmor );
-       printf("\tMSTAT\t0x%08X\n", memctl->memc_mstat);
-
-       puts ("\nSystem Integration Timers\n");
-       printf("\tTBSCR\t0x%08X\tRTCSC\t0x%08X \n", timers->sit_tbscr, timers->sit_rtcsc);
-       printf("\tPISCR\t0x%08X \n", timers->sit_piscr);
-
-       puts ("\nClocks and Reset\n");
-       printf("\tSCCR\t0x%08X\tPLPRCR\t0x%08X \n", car->car_sccr, car->car_plprcr);
-
-       puts ("\nU-Bus to IMB3 Bus Interface\n");
-       printf("\tUMCR\t0x%08X\tUIPEND\t0x%08X \n", uimb->uimb_umcr, uimb->uimb_uipend);
-       puts ("\n\n");
-
-#elif defined(CONFIG_MPC5200)
-       puts ("\nMPC5200 registers\n");
-       printf ("MBAR=%08x\n", CONFIG_SYS_MBAR);
-       puts ("Memory map registers\n");
-       printf ("\tCS0: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS0_START,
-               *(volatile ulong*)MPC5XXX_CS0_STOP,
-               *(volatile ulong*)MPC5XXX_CS0_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00010000) ? 1 : 0);
-       printf ("\tCS1: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS1_START,
-               *(volatile ulong*)MPC5XXX_CS1_STOP,
-               *(volatile ulong*)MPC5XXX_CS1_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00020000) ? 1 : 0);
-       printf ("\tCS2: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS2_START,
-               *(volatile ulong*)MPC5XXX_CS2_STOP,
-               *(volatile ulong*)MPC5XXX_CS2_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00040000) ? 1 : 0);
-       printf ("\tCS3: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS3_START,
-               *(volatile ulong*)MPC5XXX_CS3_STOP,
-               *(volatile ulong*)MPC5XXX_CS3_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00080000) ? 1 : 0);
-       printf ("\tCS4: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS4_START,
-               *(volatile ulong*)MPC5XXX_CS4_STOP,
-               *(volatile ulong*)MPC5XXX_CS4_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00100000) ? 1 : 0);
-       printf ("\tCS5: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS5_START,
-               *(volatile ulong*)MPC5XXX_CS5_STOP,
-               *(volatile ulong*)MPC5XXX_CS5_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x00200000) ? 1 : 0);
-       printf ("\tCS6: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS6_START,
-               *(volatile ulong*)MPC5XXX_CS6_STOP,
-               *(volatile ulong*)MPC5XXX_CS6_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x04000000) ? 1 : 0);
-       printf ("\tCS7: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_CS7_START,
-               *(volatile ulong*)MPC5XXX_CS7_STOP,
-               *(volatile ulong*)MPC5XXX_CS7_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x08000000) ? 1 : 0);
-       printf ("\tBOOTCS: start %08lX\tstop %08lX\tconfig %08lX\ten %d\n",
-               *(volatile ulong*)MPC5XXX_BOOTCS_START,
-               *(volatile ulong*)MPC5XXX_BOOTCS_STOP,
-               *(volatile ulong*)MPC5XXX_BOOTCS_CFG,
-               (*(volatile ulong*)MPC5XXX_ADDECR & 0x02000000) ? 1 : 0);
-       printf ("\tSDRAMCS0: %08lX\n",
-               *(volatile ulong*)MPC5XXX_SDRAM_CS0CFG);
-       printf ("\tSDRAMCS1: %08lX\n",
-               *(volatile ulong*)MPC5XXX_SDRAM_CS1CFG);
-#elif defined(CONFIG_MPC86xx)
-       mpc86xx_reginfo();
-
-#elif defined(CONFIG_MPC85xx)
-       mpc85xx_reginfo();
-
-#elif defined(CONFIG_BLACKFIN)
-       puts("\nSystem Configuration registers\n");
-#ifndef __ADSPBF60x__
-       puts("\nPLL Registers\n");
-       printf("\tPLL_DIV:   0x%04x   PLL_CTL:      0x%04x\n",
-               bfin_read_PLL_DIV(), bfin_read_PLL_CTL());
-       printf("\tPLL_STAT:  0x%04x   PLL_LOCKCNT:  0x%04x\n",
-               bfin_read_PLL_STAT(), bfin_read_PLL_LOCKCNT());
-       printf("\tVR_CTL:    0x%04x\n", bfin_read_VR_CTL());
-
-       puts("\nEBIU AMC Registers\n");
-       printf("\tEBIU_AMGCTL:   0x%04x\n", bfin_read_EBIU_AMGCTL());
-       printf("\tEBIU_AMBCTL0:  0x%08x   EBIU_AMBCTL1:  0x%08x\n",
-               bfin_read_EBIU_AMBCTL0(), bfin_read_EBIU_AMBCTL1());
-# ifdef EBIU_MODE
-       printf("\tEBIU_MBSCTL:   0x%08x   EBIU_ARBSTAT:  0x%08x\n",
-               bfin_read_EBIU_MBSCTL(), bfin_read_EBIU_ARBSTAT());
-       printf("\tEBIU_MODE:     0x%08x   EBIU_FCTL:     0x%08x\n",
-               bfin_read_EBIU_MODE(), bfin_read_EBIU_FCTL());
-# endif
-
-# ifdef EBIU_RSTCTL
-       puts("\nEBIU DDR Registers\n");
-       printf("\tEBIU_DDRCTL0:  0x%08x   EBIU_DDRCTL1:  0x%08x\n",
-               bfin_read_EBIU_DDRCTL0(), bfin_read_EBIU_DDRCTL1());
-       printf("\tEBIU_DDRCTL2:  0x%08x   EBIU_DDRCTL3:  0x%08x\n",
-               bfin_read_EBIU_DDRCTL2(), bfin_read_EBIU_DDRCTL3());
-       printf("\tEBIU_DDRQUE:   0x%08x   EBIU_RSTCTL    0x%04x\n",
-               bfin_read_EBIU_DDRQUE(), bfin_read_EBIU_RSTCTL());
-       printf("\tEBIU_ERRADD:   0x%08x   EBIU_ERRMST:   0x%04x\n",
-               bfin_read_EBIU_ERRADD(), bfin_read_EBIU_ERRMST());
-# else
-       puts("\nEBIU SDC Registers\n");
-       printf("\tEBIU_SDRRC:   0x%04x   EBIU_SDBCTL:  0x%04x\n",
-               bfin_read_EBIU_SDRRC(), bfin_read_EBIU_SDBCTL());
-       printf("\tEBIU_SDSTAT:  0x%04x   EBIU_SDGCTL:  0x%08x\n",
-               bfin_read_EBIU_SDSTAT(), bfin_read_EBIU_SDGCTL());
-# endif
-#else
-       puts("\nCGU Registers\n");
-       printf("\tCGU_DIV:   0x%08x   CGU_CTL:      0x%08x\n",
-               bfin_read_CGU_DIV(), bfin_read_CGU_CTL());
-       printf("\tCGU_STAT:  0x%08x   CGU_LOCKCNT:  0x%08x\n",
-               bfin_read_CGU_STAT(), bfin_read_CGU_CLKOUTSEL());
-
-       puts("\nSMC DDR Registers\n");
-       printf("\tDDR_CFG:   0x%08x   DDR_TR0:      0x%08x\n",
-               bfin_read_DMC0_CFG(), bfin_read_DMC0_TR0());
-       printf("\tDDR_TR1:   0x%08x   DDR_TR2:      0x%08x\n",
-               bfin_read_DMC0_TR1(), bfin_read_DMC0_TR2());
-       printf("\tDDR_MR:    0x%08x   DDR_EMR1:     0x%08x\n",
-               bfin_read_DMC0_MR(), bfin_read_DMC0_EMR1());
-       printf("\tDDR_CTL:   0x%08x   DDR_STAT:     0x%08x\n",
-               bfin_read_DMC0_CTL(), bfin_read_DMC0_STAT());
-       printf("\tDDR_DLLCTL:0x%08x\n", bfin_read_DMC0_DLLCTL());
-#endif
-#endif /* CONFIG_BLACKFIN */
-
-       return 0;
-}
-
- /**************************************************/
-
-#if defined(CONFIG_CMD_REGINFO)
-U_BOOT_CMD(
-       reginfo,        2,      1,      do_reginfo,
-       "print register information",
-       ""
-);
-#endif
diff --git a/common/cmd_regulator.c b/common/cmd_regulator.c
deleted file mode 100644 (file)
index bfea6e0..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * Copyright (C) 2014-2015 Samsung Electronics
- * Przemyslaw Marczak <p.marczak@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <errno.h>
-#include <dm.h>
-#include <dm/uclass-internal.h>
-#include <power/regulator.h>
-
-#define LIMIT_DEVNAME  20
-#define LIMIT_OFNAME   32
-#define LIMIT_INFO     18
-
-static struct udevice *currdev;
-
-static int failure(int ret)
-{
-       printf("Error: %d (%s)\n", ret, errno_str(ret));
-
-       return CMD_RET_FAILURE;
-}
-
-static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       const char *name;
-       int ret = -ENXIO;
-
-       switch (argc) {
-       case 2:
-               name = argv[1];
-               ret = regulator_get_by_platname(name, &currdev);
-               if (ret) {
-                       printf("Can't get the regulator: %s!\n", name);
-                       return failure(ret);
-               }
-       case 1:
-               if (!currdev) {
-                       printf("Regulator device is not set!\n\n");
-                       return CMD_RET_USAGE;
-               }
-
-               uc_pdata = dev_get_uclass_platdata(currdev);
-               if (!uc_pdata) {
-                       printf("%s: no regulator platform data!\n", currdev->name);
-                       return failure(ret);
-               }
-
-               printf("dev: %s @ %s\n", uc_pdata->name, currdev->name);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int curr_dev_and_platdata(struct udevice **devp,
-                                struct dm_regulator_uclass_platdata **uc_pdata,
-                                bool allow_type_fixed)
-{
-       *devp = NULL;
-       *uc_pdata = NULL;
-
-       if (!currdev) {
-               printf("First, set the regulator device!\n");
-               return CMD_RET_FAILURE;
-       }
-
-       *devp = currdev;
-
-       *uc_pdata = dev_get_uclass_platdata(*devp);
-       if (!*uc_pdata) {
-               error("Regulator: %s - missing platform data!", currdev->name);
-               return CMD_RET_FAILURE;
-       }
-
-       if (!allow_type_fixed && (*uc_pdata)->type == REGULATOR_TYPE_FIXED) {
-               printf("Operation not allowed for fixed regulator!\n");
-               return CMD_RET_FAILURE;
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       struct udevice *dev;
-       int ret;
-
-       printf("| %-*.*s| %-*.*s| %s\n",
-              LIMIT_DEVNAME, LIMIT_DEVNAME, "Device",
-              LIMIT_OFNAME, LIMIT_OFNAME, "regulator-name",
-              "Parent");
-
-       for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-            ret = uclass_find_next_device(&dev)) {
-               if (ret)
-                       continue;
-
-               uc_pdata = dev_get_uclass_platdata(dev);
-               printf("| %-*.*s| %-*.*s| %s\n",
-                      LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name,
-                      LIMIT_OFNAME, LIMIT_OFNAME, uc_pdata->name,
-                      dev->parent->name);
-       }
-
-       return ret;
-}
-
-static int constraint(const char *name, int val, const char *val_name)
-{
-       printf("%-*s", LIMIT_INFO, name);
-       if (val < 0) {
-               printf(" %s (err: %d)\n", errno_str(val), val);
-               return val;
-       }
-
-       if (val_name)
-               printf(" %d (%s)\n", val, val_name);
-       else
-               printf(" %d\n", val);
-
-       return 0;
-}
-
-static const char *get_mode_name(struct dm_regulator_mode *mode,
-                                int mode_count,
-                                int mode_id)
-{
-       while (mode_count--) {
-               if (mode->id == mode_id)
-                       return mode->name;
-               mode++;
-       }
-
-       return NULL;
-}
-
-static int do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       struct dm_regulator_mode *modes;
-       const char *parent_uc;
-       int mode_count;
-       int ret;
-       int i;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
-       if (ret)
-               return ret;
-
-       parent_uc = dev_get_uclass_name(dev->parent);
-
-       printf("%s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s %s\n%-*s\n",
-              "Regulator info:",
-              LIMIT_INFO, "* regulator-name:", uc_pdata->name,
-              LIMIT_INFO, "* device name:", dev->name,
-              LIMIT_INFO, "* parent name:", dev->parent->name,
-              LIMIT_INFO, "* parent uclass:", parent_uc,
-              LIMIT_INFO, "* constraints:");
-
-       constraint("  - min uV:", uc_pdata->min_uV, NULL);
-       constraint("  - max uV:", uc_pdata->max_uV, NULL);
-       constraint("  - min uA:", uc_pdata->min_uA, NULL);
-       constraint("  - max uA:", uc_pdata->max_uA, NULL);
-       constraint("  - always on:", uc_pdata->always_on,
-                  uc_pdata->always_on ? "true" : "false");
-       constraint("  - boot on:", uc_pdata->boot_on,
-                  uc_pdata->boot_on ? "true" : "false");
-
-       mode_count = regulator_mode(dev, &modes);
-       constraint("* op modes:", mode_count, NULL);
-
-       for (i = 0; i < mode_count; i++, modes++)
-               constraint("  - mode id:", modes->id, modes->name);
-
-       return CMD_RET_SUCCESS;
-}
-
-static void do_status_detail(struct udevice *dev,
-                            struct dm_regulator_uclass_platdata *uc_pdata)
-{
-       int current, value, mode;
-       const char *mode_name;
-       bool enabled;
-
-       printf("Regulator %s status:\n", uc_pdata->name);
-
-       enabled = regulator_get_enable(dev);
-       constraint(" * enable:", enabled, enabled ? "true" : "false");
-
-       value = regulator_get_value(dev);
-       constraint(" * value uV:", value, NULL);
-
-       current = regulator_get_current(dev);
-       constraint(" * current uA:", current, NULL);
-
-       mode = regulator_get_mode(dev);
-       mode_name = get_mode_name(uc_pdata->mode, uc_pdata->mode_count, mode);
-       constraint(" * mode id:", mode, mode_name);
-}
-
-static void do_status_line(struct udevice *dev)
-{
-       struct dm_regulator_uclass_platdata *pdata;
-       int current, value, mode;
-       const char *mode_name;
-       bool enabled;
-
-       pdata = dev_get_uclass_platdata(dev);
-       enabled = regulator_get_enable(dev);
-       value = regulator_get_value(dev);
-       current = regulator_get_current(dev);
-       mode = regulator_get_mode(dev);
-       mode_name = get_mode_name(pdata->mode, pdata->mode_count, mode);
-       printf("%-20s %-10s ", pdata->name, enabled ? "enabled" : "disabled");
-       if (value >= 0)
-               printf("%10d ", value);
-       else
-               printf("%10s ", "-");
-       if (current >= 0)
-               printf("%10d ", current);
-       else
-               printf("%10s ", "-");
-       if (mode >= 0)
-               printf("%-10s", mode_name);
-       else
-               printf("%-10s", "-");
-       printf("\n");
-}
-
-static int do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       struct udevice *dev;
-       int ret;
-
-       if (currdev && (argc < 2 || strcmp(argv[1], "-a"))) {
-               ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
-               if (ret)
-                       return CMD_RET_FAILURE;
-               do_status_detail(dev, uc_pdata);
-               return 0;
-       }
-
-       /* Show all of them in a list, probing them as needed */
-       printf("%-20s %-10s %10s %10s %-10s\n", "Name", "Enabled", "uV", "mA",
-              "Mode");
-       for (ret = uclass_first_device(UCLASS_REGULATOR, &dev); dev;
-            ret = uclass_next_device(&dev))
-               do_status_line(dev);
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       int value;
-       int force;
-       int ret;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1);
-       if (ret)
-               return ret;
-
-       if (argc == 1) {
-               ret = regulator_get_value(dev);
-               if (ret < 0) {
-                       printf("Regulator: %s - can't get the Voltage!\n",
-                              uc_pdata->name);
-                       return failure(ret);
-               }
-
-               printf("%d uV\n", ret);
-               return CMD_RET_SUCCESS;
-       }
-
-       if (argc == 3)
-               force = !strcmp("-f", argv[2]);
-       else
-               force = 0;
-
-       value = simple_strtoul(argv[1], NULL, 0);
-       if ((value < uc_pdata->min_uV || value > uc_pdata->max_uV) && !force) {
-               printf("Value exceeds regulator constraint limits %d..%d uV\n",
-                      uc_pdata->min_uV, uc_pdata->max_uV);
-               return CMD_RET_FAILURE;
-       }
-
-       ret = regulator_set_value(dev, value);
-       if (ret) {
-               printf("Regulator: %s - can't set the Voltage!\n",
-                      uc_pdata->name);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_current(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       int current;
-       int ret;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1);
-       if (ret)
-               return ret;
-
-       if (argc == 1) {
-               ret = regulator_get_current(dev);
-               if (ret < 0) {
-                       printf("Regulator: %s - can't get the Current!\n",
-                              uc_pdata->name);
-                       return failure(ret);
-               }
-
-               printf("%d uA\n", ret);
-               return CMD_RET_SUCCESS;
-       }
-
-       current = simple_strtoul(argv[1], NULL, 0);
-       if (current < uc_pdata->min_uA || current > uc_pdata->max_uA) {
-               printf("Current exceeds regulator constraint limits\n");
-               return CMD_RET_FAILURE;
-       }
-
-       ret = regulator_set_current(dev, current);
-       if (ret) {
-               printf("Regulator: %s - can't set the Current!\n",
-                      uc_pdata->name);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_mode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       int mode;
-       int ret;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, false);
-       if (ret)
-               return ret;
-
-       if (argc == 1) {
-               ret = regulator_get_mode(dev);
-               if (ret < 0) {
-                       printf("Regulator: %s - can't get the operation mode!\n",
-                              uc_pdata->name);
-                       return failure(ret);
-               }
-
-               printf("mode id: %d\n", ret);
-               return CMD_RET_SUCCESS;
-       }
-
-       mode = simple_strtoul(argv[1], NULL, 0);
-
-       ret = regulator_set_mode(dev, mode);
-       if (ret) {
-               printf("Regulator: %s - can't set the operation mode!\n",
-                      uc_pdata->name);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_enable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       int ret;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
-       if (ret)
-               return ret;
-
-       ret = regulator_set_enable(dev, true);
-       if (ret) {
-               printf("Regulator: %s - can't enable!\n", uc_pdata->name);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static int do_disable(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct udevice *dev;
-       struct dm_regulator_uclass_platdata *uc_pdata;
-       int ret;
-
-       ret = curr_dev_and_platdata(&dev, &uc_pdata, true);
-       if (ret)
-               return ret;
-
-       ret = regulator_set_enable(dev, false);
-       if (ret) {
-               printf("Regulator: %s - can't disable!\n", uc_pdata->name);
-               return failure(ret);
-       }
-
-       return CMD_RET_SUCCESS;
-}
-
-static cmd_tbl_t subcmd[] = {
-       U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""),
-       U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
-       U_BOOT_CMD_MKENT(info, 2, 1, do_info, "", ""),
-       U_BOOT_CMD_MKENT(status, 2, 1, do_status, "", ""),
-       U_BOOT_CMD_MKENT(value, 3, 1, do_value, "", ""),
-       U_BOOT_CMD_MKENT(current, 3, 1, do_current, "", ""),
-       U_BOOT_CMD_MKENT(mode, 2, 1, do_mode, "", ""),
-       U_BOOT_CMD_MKENT(enable, 1, 1, do_enable, "", ""),
-       U_BOOT_CMD_MKENT(disable, 1, 1, do_disable, "", ""),
-};
-
-static int do_regulator(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       cmd_tbl_t *cmd;
-
-       argc--;
-       argv++;
-
-       cmd = find_cmd_tbl(argv[0], subcmd, ARRAY_SIZE(subcmd));
-       if (cmd == NULL || argc > cmd->maxargs)
-               return CMD_RET_USAGE;
-
-       return cmd->cmd(cmdtp, flag, argc, argv);
-}
-
-U_BOOT_CMD(regulator, CONFIG_SYS_MAXARGS, 1, do_regulator,
-       "uclass operations",
-       "list             - list UCLASS regulator devices\n"
-       "regulator dev [regulator-name] - show/[set] operating regulator device\n"
-       "regulator info                 - print constraints info\n"
-       "regulator status [-a]          - print operating status [for all]\n"
-       "regulator value [val] [-f]     - print/[set] voltage value [uV] (force)\n"
-       "regulator current [val]        - print/[set] current value [uA]\n"
-       "regulator mode [id]            - print/[set] operating mode id\n"
-       "regulator enable               - enable the regulator output\n"
-       "regulator disable              - disable the regulator output\n"
-);
diff --git a/common/cmd_reiser.c b/common/cmd_reiser.c
deleted file mode 100644 (file)
index 8871564..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * (C) Copyright 2003 - 2004
- * Sysgo Real-Time Solutions, AG <www.elinos.com>
- * Pavel Bartusek <pba@sysgo.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Reiserfs support
- */
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <image.h>
-#include <linux/ctype.h>
-#include <asm/byteorder.h>
-#include <reiserfs.h>
-#include <part.h>
-
-#ifndef CONFIG_DOS_PARTITION
-#error DOS partition support must be selected
-#endif
-
-/* #define     REISER_DEBUG */
-
-#ifdef REISER_DEBUG
-#define        PRINTF(fmt,args...)     printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
-
-int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename = "/";
-       int dev, part;
-       block_dev_desc_t *dev_desc=NULL;
-       disk_partition_t info;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       if (argc == 4) {
-           filename = argv[3];
-       }
-
-       dev = dev_desc->dev;
-       PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
-
-       reiserfs_set_blk_dev(dev_desc, &info);
-
-       if (!reiserfs_mount(info.size)) {
-               printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
-               return 1;
-       }
-
-       if (reiserfs_ls (filename)) {
-               printf ("** Error reiserfs_ls() **\n");
-               return 1;
-       };
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       reiserls,       4,      1,      do_reiserls,
-       "list files in a directory (default /)",
-       "<interface> <dev[:part]> [directory]\n"
-       "    - list files from 'dev' on 'interface' in a 'directory'"
-);
-
-/******************************************************************************
- * Reiserfs boot command intepreter. Derived from diskboot
- */
-int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename = NULL;
-       int dev, part;
-       ulong addr = 0, filelen;
-       disk_partition_t info;
-       block_dev_desc_t *dev_desc = NULL;
-       unsigned long count;
-       char *addr_str;
-
-       switch (argc) {
-       case 3:
-               addr_str = getenv("loadaddr");
-               if (addr_str != NULL) {
-                       addr = simple_strtoul (addr_str, NULL, 16);
-               } else {
-                       addr = CONFIG_SYS_LOAD_ADDR;
-               }
-               filename = getenv ("bootfile");
-               count = 0;
-               break;
-       case 4:
-               addr = simple_strtoul (argv[3], NULL, 16);
-               filename = getenv ("bootfile");
-               count = 0;
-               break;
-       case 5:
-               addr = simple_strtoul (argv[3], NULL, 16);
-               filename = argv[4];
-               count = 0;
-               break;
-       case 6:
-               addr = simple_strtoul (argv[3], NULL, 16);
-               filename = argv[4];
-               count = simple_strtoul (argv[5], NULL, 16);
-               break;
-
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       if (!filename) {
-               puts ("\n** No boot file defined **\n");
-               return 1;
-       }
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       dev = dev_desc->dev;
-
-       printf("Loading file \"%s\" from %s device %d%c%c\n",
-               filename, argv[1], dev,
-               part ? ':' : ' ', part ? part + '0' : ' ');
-
-       reiserfs_set_blk_dev(dev_desc, &info);
-
-       if (!reiserfs_mount(info.size)) {
-               printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
-               return 1;
-       }
-
-       filelen = reiserfs_open(filename);
-       if (filelen < 0) {
-               printf("** File not found %s **\n", filename);
-               return 1;
-       }
-       if ((count < filelen) && (count != 0)) {
-           filelen = count;
-       }
-
-       if (reiserfs_read((char *)addr, filelen) != filelen) {
-               printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
-               return 1;
-       }
-
-       /* Loading ok, update default load address */
-       load_addr = addr;
-
-       printf ("\n%ld bytes read\n", filelen);
-       setenv_hex("filesize", filelen);
-
-       return filelen;
-}
-
-U_BOOT_CMD(
-       reiserload,     6,      0,      do_reiserload,
-       "load binary file from a Reiser filesystem",
-       "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
-       "    - load binary file 'filename' from 'dev' on 'interface'\n"
-       "      to address 'addr' from dos filesystem"
-);
diff --git a/common/cmd_remoteproc.c b/common/cmd_remoteproc.c
deleted file mode 100644 (file)
index 794a406..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * (C) Copyright 2015
- * Texas Instruments Incorporated - http://www.ti.com/
- * SPDX-License-Identifier:    GPL-2.0+
- */
-#include <common.h>
-#include <command.h>
-#include <dm.h>
-#include <errno.h>
-#include <malloc.h>
-#include <remoteproc.h>
-
-/**
- * print_remoteproc_list() - print all the remote processor devices
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int print_remoteproc_list(void)
-{
-       struct udevice *dev;
-       struct uclass *uc;
-       int ret;
-       char *type;
-
-       ret = uclass_get(UCLASS_REMOTEPROC, &uc);
-       if (ret) {
-               printf("Cannot find Remote processor class\n");
-               return ret;
-       }
-
-       uclass_foreach_dev(dev, uc) {
-               struct dm_rproc_uclass_pdata *uc_pdata;
-               const struct dm_rproc_ops *ops = rproc_get_ops(dev);
-
-               uc_pdata = dev_get_uclass_platdata(dev);
-
-               switch (uc_pdata->mem_type) {
-               case RPROC_INTERNAL_MEMORY_MAPPED:
-                       type = "internal memory mapped";
-                       break;
-               default:
-                       type = "unknown";
-                       break;
-               }
-               printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
-                      dev->seq,
-                      uc_pdata->name,
-                      type,
-                      ops->load ? "load " : "",
-                      ops->start ? "start " : "",
-                      ops->stop ? "stop " : "",
-                      ops->reset ? "reset " : "",
-                      ops->is_running ? "is_running " : "",
-                      ops->ping ? "ping " : "");
-       }
-       return 0;
-}
-
-/**
- * do_rproc_init() - do basic initialization
- * @cmdtp:     unused
- * @flag:      unused
- * @argc:      unused
- * @argv:      unused
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int do_rproc_init(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char *const argv[])
-{
-       if (rproc_is_initialized()) {
-               printf("\tRemote Processors are already initialized\n");
-       } else {
-               if (!rproc_init())
-                       return 0;
-               printf("Few Remote Processors failed to be initalized\n");
-       }
-
-       return CMD_RET_FAILURE;
-}
-
-/**
- * do_remoteproc_list() - print list of remote proc devices.
- * @cmdtp:     unused
- * @flag:      unused
- * @argc:      unused
- * @argv:      unused
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int do_remoteproc_list(cmd_tbl_t *cmdtp, int flag, int argc,
-                             char *const argv[])
-{
-       if (!rproc_is_initialized()) {
-               printf("\t Remote Processors is not initialized\n");
-               return CMD_RET_USAGE;
-       }
-
-       if (print_remoteproc_list())
-               return CMD_RET_FAILURE;
-
-       return 0;
-}
-
-/**
- * do_remoteproc_load() - Load a remote processor with binary image
- * @cmdtp:     unused
- * @flag:      unused
- * @argc:      argument count for the load function
- * @argv:      arguments for the load function
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int do_remoteproc_load(cmd_tbl_t *cmdtp, int flag, int argc,
-                             char *const argv[])
-{
-       ulong addr, size;
-       int id, ret;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       id = (int)simple_strtoul(argv[1], NULL, 3);
-       addr = simple_strtoul(argv[2], NULL, 16);
-
-       size = simple_strtoul(argv[3], NULL, 16);
-
-       if (!size) {
-               printf("\t Expect some size??\n");
-               return CMD_RET_USAGE;
-       }
-
-       if (!rproc_is_initialized()) {
-               printf("\tRemote Processors are not initialized\n");
-               return CMD_RET_USAGE;
-       }
-
-       ret = rproc_load(id, addr, size);
-       printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
-              id, addr, size, ret ? " Failed!" : " Success!");
-
-       return ret ? CMD_RET_FAILURE : 0;
-}
-
-/**
- * do_remoteproc_wrapper() - wrapper for various  rproc commands
- * @cmdtp:     unused
- * @flag:      unused
- * @argc:      argument count for the rproc command
- * @argv:      arguments for the rproc command
- *
- * Most of the commands just take id as a parameter andinvoke various
- * helper routines in remote processor core. by using a set of
- * common checks, we can reduce the amount of code used for this.
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int do_remoteproc_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
-                                char *const argv[])
-{
-       int id, ret = CMD_RET_USAGE;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       id = (int)simple_strtoul(argv[1], NULL, 3);
-
-       if (!rproc_is_initialized()) {
-               printf("\tRemote Processors are not initialized\n");
-               return CMD_RET_USAGE;
-       }
-
-       if (!strcmp(argv[0], "start")) {
-               ret = rproc_start(id);
-       } else if (!strcmp(argv[0], "stop")) {
-               ret = rproc_stop(id);
-       } else if (!strcmp(argv[0], "reset")) {
-               ret = rproc_reset(id);
-       } else if (!strcmp(argv[0], "is_running")) {
-               ret = rproc_is_running(id);
-               if (!ret) {
-                       printf("Remote processor is Running\n");
-               } else if (ret == 1) {
-                       printf("Remote processor is NOT Running\n");
-                       ret = 0;
-               }
-               /* Else error.. */
-       } else if (!strcmp(argv[0], "ping")) {
-               ret = rproc_ping(id);
-               if (!ret) {
-                       printf("Remote processor responds 'Pong'\n");
-               } else if (ret == 1) {
-                       printf("No response from Remote processor\n");
-                       ret = 0;
-               }
-               /* Else error.. */
-       }
-
-       if (ret < 0)
-               printf("Operation Failed with error (%d)\n", ret);
-
-       return ret ? CMD_RET_FAILURE : 0;
-}
-
-static cmd_tbl_t cmd_remoteproc_sub[] = {
-       U_BOOT_CMD_MKENT(init, 0, 1, do_rproc_init,
-                        "Enumerate and initialize all processors", ""),
-       U_BOOT_CMD_MKENT(list, 0, 1, do_remoteproc_list,
-                        "list remote processors", ""),
-       U_BOOT_CMD_MKENT(load, 5, 1, do_remoteproc_load,
-                        "Load remote processor with provided image",
-                        "<id> [addr] [size]\n"
-                        "- id: ID of the remote processor(see 'list' cmd)\n"
-                        "- addr: Address in memory of the image to loadup\n"
-                        "- size: Size of the image to loadup\n"),
-       U_BOOT_CMD_MKENT(start, 1, 1, do_remoteproc_wrapper,
-                        "Start remote processor",
-                        "id - ID of the remote processor (see 'list' cmd)\n"),
-       U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper,
-                        "Stop remote processor",
-                        "id - ID of the remote processor (see 'list' cmd)\n"),
-       U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper,
-                        "Reset remote processor",
-                        "id - ID of the remote processor (see 'list' cmd)\n"),
-       U_BOOT_CMD_MKENT(is_running, 1, 1, do_remoteproc_wrapper,
-                        "Check to see if remote processor is running\n",
-                        "id - ID of the remote processor (see 'list' cmd)\n"),
-       U_BOOT_CMD_MKENT(ping, 1, 1, do_remoteproc_wrapper,
-                        "Ping to communicate with remote processor\n",
-                        "id - ID of the remote processor (see 'list' cmd)\n"),
-};
-
-/**
- * do_remoteproc() - (replace: short desc)
- * @cmdtp:     unused
- * @flag:      unused
- * @argc:      argument count
- * @argv:      argument list
- *
- * parses up the command table to invoke the correct command.
- *
- * Return: 0 if no error, else returns appropriate error value.
- */
-static int do_remoteproc(cmd_tbl_t *cmdtp, int flag, int argc,
-                        char *const argv[])
-{
-       cmd_tbl_t *c = NULL;
-
-       /* Strip off leading 'rproc' command argument */
-       argc--;
-       argv++;
-
-       if (argc)
-               c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
-                                ARRAY_SIZE(cmd_remoteproc_sub));
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(rproc, 5, 1, do_remoteproc,
-          "Control operation of remote processors in an SoC",
-          " [init|list|load|start|stop|reset|is_running|ping]\n"
-          "\t\t Where:\n"
-          "\t\t[addr] is a memory address\n"
-          "\t\t<id> is a numerical identifier for the remote processor\n"
-          "\t\t     provided by 'list' command.\n"
-          "\t\tNote: Remote processors must be initalized prior to usage\n"
-          "\t\tNote: Services are dependent on the driver capability\n"
-          "\t\t      'list' command shows the capability of each device\n"
-          "\n\tSubcommands:\n"
-          "\tinit   - Enumerate and initalize the remote processors\n"
-          "\tlist   - list available remote processors\n"
-          "\tload <id> [addr] [size]- Load the remote processor with binary\n"
-          "\t            image stored at address [addr] in memory\n"
-          "\tstart <id>        - Start the remote processor(must be loaded)\n"
-          "\tstop <id> - Stop the remote processor\n"
-          "\treset <id>        - Reset the remote processor\n"
-          "\tis_running <id> - Reports if the remote processor is running\n"
-          "\tping <id> - Ping the remote processor for communication\n");
diff --git a/common/cmd_sata.c b/common/cmd_sata.c
deleted file mode 100644 (file)
index 76bacea..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (C) 2000-2005, DENX Software Engineering
- *             Wolfgang Denk <wd@denx.de>
- * Copyright (C) Procsys. All rights reserved.
- *             Mushtaq Khan <mushtaq_k@procsys.com>
- *                     <mushtaqk_921@yahoo.co.in>
- * Copyright (C) 2008 Freescale Semiconductor, Inc.
- *             Dave Liu <daveliu@freescale.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <part.h>
-#include <sata.h>
-
-static int sata_curr_device = -1;
-block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
-
-static unsigned long sata_bread(block_dev_desc_t *block_dev, lbaint_t start,
-                               lbaint_t blkcnt, void *dst)
-{
-       return sata_read(block_dev->dev, start, blkcnt, dst);
-}
-
-static unsigned long sata_bwrite(block_dev_desc_t *block_dev, lbaint_t start,
-                                lbaint_t blkcnt, const void *buffer)
-{
-       return sata_write(block_dev->dev, start, blkcnt, buffer);
-}
-
-int __sata_initialize(void)
-{
-       int rc;
-       int i;
-
-       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
-               memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc));
-               sata_dev_desc[i].if_type = IF_TYPE_SATA;
-               sata_dev_desc[i].dev = i;
-               sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
-               sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
-               sata_dev_desc[i].lba = 0;
-               sata_dev_desc[i].blksz = 512;
-               sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
-               sata_dev_desc[i].block_read = sata_bread;
-               sata_dev_desc[i].block_write = sata_bwrite;
-
-               rc = init_sata(i);
-               if (!rc) {
-                       rc = scan_sata(i);
-                       if (!rc && (sata_dev_desc[i].lba > 0) &&
-                               (sata_dev_desc[i].blksz > 0))
-                               init_part(&sata_dev_desc[i]);
-               }
-       }
-       sata_curr_device = 0;
-       return rc;
-}
-int sata_initialize(void) __attribute__((weak,alias("__sata_initialize")));
-
-__weak int __sata_stop(void)
-{
-       int i, err = 0;
-
-       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++)
-               err |= reset_sata(i);
-
-       if (err)
-               printf("Could not reset some SATA devices\n");
-
-       return err;
-}
-int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
-
-#ifdef CONFIG_PARTITIONS
-block_dev_desc_t *sata_get_dev(int dev)
-{
-       return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL;
-}
-#endif
-
-static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int rc = 0;
-
-       if (argc == 2 && strcmp(argv[1], "stop") == 0)
-               return sata_stop();
-
-       if (argc == 2 && strcmp(argv[1], "init") == 0) {
-               if (sata_curr_device != -1)
-                       sata_stop();
-
-               return sata_initialize();
-       }
-
-       /* If the user has not yet run `sata init`, do it now */
-       if (sata_curr_device == -1)
-               if (sata_initialize())
-                       return 1;
-
-       switch (argc) {
-       case 0:
-       case 1:
-               return CMD_RET_USAGE;
-       case 2:
-               if (strncmp(argv[1],"inf", 3) == 0) {
-                       int i;
-                       putc('\n');
-                       for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; ++i) {
-                               if (sata_dev_desc[i].type == DEV_TYPE_UNKNOWN)
-                                       continue;
-                               printf ("SATA device %d: ", i);
-                               dev_print(&sata_dev_desc[i]);
-                       }
-                       return 0;
-               } else if (strncmp(argv[1],"dev", 3) == 0) {
-                       if ((sata_curr_device < 0) || (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE)) {
-                               puts("\nno SATA devices available\n");
-                               return 1;
-                       }
-                       printf("\nSATA device %d: ", sata_curr_device);
-                       dev_print(&sata_dev_desc[sata_curr_device]);
-                       return 0;
-               } else if (strncmp(argv[1],"part",4) == 0) {
-                       int dev, ok;
-
-                       for (ok = 0, dev = 0; dev < CONFIG_SYS_SATA_MAX_DEVICE; ++dev) {
-                               if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
-                                       ++ok;
-                                       if (dev)
-                                               putc ('\n');
-                                       print_part(&sata_dev_desc[dev]);
-                               }
-                       }
-                       if (!ok) {
-                               puts("\nno SATA devices available\n");
-                               rc ++;
-                       }
-                       return rc;
-               }
-               return CMD_RET_USAGE;
-       case 3:
-               if (strncmp(argv[1], "dev", 3) == 0) {
-                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
-
-                       printf("\nSATA device %d: ", dev);
-                       if (dev >= CONFIG_SYS_SATA_MAX_DEVICE) {
-                               puts ("unknown device\n");
-                               return 1;
-                       }
-                       dev_print(&sata_dev_desc[dev]);
-
-                       if (sata_dev_desc[dev].type == DEV_TYPE_UNKNOWN)
-                               return 1;
-
-                       sata_curr_device = dev;
-
-                       puts("... is now current device\n");
-
-                       return 0;
-               } else if (strncmp(argv[1], "part", 4) == 0) {
-                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
-
-                       if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) {
-                               print_part(&sata_dev_desc[dev]);
-                       } else {
-                               printf("\nSATA device %d not available\n", dev);
-                               rc = 1;
-                       }
-                       return rc;
-               }
-               return CMD_RET_USAGE;
-
-       default: /* at least 4 args */
-               if (strcmp(argv[1], "read") == 0) {
-                       ulong addr = simple_strtoul(argv[2], NULL, 16);
-                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
-                       ulong n;
-                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
-
-                       printf("\nSATA read: device %d block # %ld, count %ld ... ",
-                               sata_curr_device, blk, cnt);
-
-                       n = sata_read(sata_curr_device, blk, cnt, (u32 *)addr);
-
-                       /* flush cache after read */
-                       flush_cache(addr, cnt * sata_dev_desc[sata_curr_device].blksz);
-
-                       printf("%ld blocks read: %s\n",
-                               n, (n==cnt) ? "OK" : "ERROR");
-                       return (n == cnt) ? 0 : 1;
-               } else if (strcmp(argv[1], "write") == 0) {
-                       ulong addr = simple_strtoul(argv[2], NULL, 16);
-                       ulong cnt = simple_strtoul(argv[4], NULL, 16);
-                       ulong n;
-
-                       lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
-
-                       printf("\nSATA write: device %d block # %ld, count %ld ... ",
-                               sata_curr_device, blk, cnt);
-
-                       n = sata_write(sata_curr_device, blk, cnt, (u32 *)addr);
-
-                       printf("%ld blocks written: %s\n",
-                               n, (n == cnt) ? "OK" : "ERROR");
-                       return (n == cnt) ? 0 : 1;
-               } else {
-                       return CMD_RET_USAGE;
-               }
-
-               return rc;
-       }
-}
-
-U_BOOT_CMD(
-       sata, 5, 1, do_sata,
-       "SATA sub system",
-       "init - init SATA sub system\n"
-       "sata stop - disable SATA sub system\n"
-       "sata info - show available SATA devices\n"
-       "sata device [dev] - show or set current device\n"
-       "sata part [dev] - print partition table\n"
-       "sata read addr blk# cnt\n"
-       "sata write addr blk# cnt"
-);
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
deleted file mode 100644 (file)
index bc7d1b6..0000000
+++ /dev/null
@@ -1,733 +0,0 @@
-/*
- * (C) Copyright 2001
- * Denis Peter, MPL AG Switzerland
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * SCSI support.
- */
-#include <common.h>
-#include <command.h>
-#include <inttypes.h>
-#include <asm/processor.h>
-#include <scsi.h>
-#include <image.h>
-#include <pci.h>
-
-#ifdef CONFIG_SCSI_DEV_LIST
-#define SCSI_DEV_LIST CONFIG_SCSI_DEV_LIST
-#else
-#ifdef CONFIG_SCSI_SYM53C8XX
-#define SCSI_VEND_ID   0x1000
-#ifndef CONFIG_SCSI_DEV_ID
-#define SCSI_DEV_ID            0x0001
-#else
-#define SCSI_DEV_ID            CONFIG_SCSI_DEV_ID
-#endif
-#elif defined CONFIG_SATA_ULI5288
-
-#define SCSI_VEND_ID 0x10b9
-#define SCSI_DEV_ID  0x5288
-
-#elif !defined(CONFIG_SCSI_AHCI_PLAT)
-#error no scsi device defined
-#endif
-#define SCSI_DEV_LIST {SCSI_VEND_ID, SCSI_DEV_ID}
-#endif
-
-#if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT)
-const struct pci_device_id scsi_device_list[] = { SCSI_DEV_LIST };
-#endif
-static ccb tempccb;    /* temporary scsi command buffer */
-
-static unsigned char tempbuff[512]; /* temporary data buffer */
-
-static int scsi_max_devs; /* number of highest available scsi device */
-
-static int scsi_curr_dev; /* current device */
-
-static block_dev_desc_t scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];
-
-/********************************************************************************
- *  forward declerations of some Setup Routines
- */
-void scsi_setup_test_unit_ready(ccb * pccb);
-void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks);
-void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks);
-void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks);
-
-static void scsi_setup_write_ext(ccb *pccb, lbaint_t start,
-                               unsigned short blocks);
-void scsi_setup_inquiry(ccb * pccb);
-void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
-
-
-static int scsi_read_capacity(ccb *pccb, lbaint_t *capacity,
-                             unsigned long *blksz);
-static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
-                      lbaint_t blkcnt, void *buffer);
-static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
-                       lbaint_t blkcnt, const void *buffer);
-
-
-/*********************************************************************************
- * (re)-scan the scsi bus and reports scsi device info
- * to the user if mode = 1
- */
-void scsi_scan(int mode)
-{
-       unsigned char i,perq,modi,lun;
-       lbaint_t capacity;
-       unsigned long blksz;
-       ccb* pccb=(ccb *)&tempccb;
-
-       if(mode==1) {
-               printf("scanning bus for devices...\n");
-       }
-       for(i=0;i<CONFIG_SYS_SCSI_MAX_DEVICE;i++) {
-               scsi_dev_desc[i].target=0xff;
-               scsi_dev_desc[i].lun=0xff;
-               scsi_dev_desc[i].lba=0;
-               scsi_dev_desc[i].blksz=0;
-               scsi_dev_desc[i].log2blksz =
-                       LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz));
-               scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
-               scsi_dev_desc[i].vendor[0]=0;
-               scsi_dev_desc[i].product[0]=0;
-               scsi_dev_desc[i].revision[0]=0;
-               scsi_dev_desc[i].removable = false;
-               scsi_dev_desc[i].if_type=IF_TYPE_SCSI;
-               scsi_dev_desc[i].dev=i;
-               scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN;
-               scsi_dev_desc[i].block_read=scsi_read;
-               scsi_dev_desc[i].block_write = scsi_write;
-       }
-       scsi_max_devs=0;
-       for(i=0;i<CONFIG_SYS_SCSI_MAX_SCSI_ID;i++) {
-               pccb->target=i;
-               for(lun=0;lun<CONFIG_SYS_SCSI_MAX_LUN;lun++) {
-                       pccb->lun=lun;
-                       pccb->pdata=(unsigned char *)&tempbuff;
-                       pccb->datalen=512;
-                       scsi_setup_inquiry(pccb);
-                       if (scsi_exec(pccb) != true) {
-                               if(pccb->contr_stat==SCSI_SEL_TIME_OUT) {
-                                       debug ("Selection timeout ID %d\n",pccb->target);
-                                       continue; /* selection timeout => assuming no device present */
-                               }
-                               scsi_print_error(pccb);
-                               continue;
-                       }
-                       perq=tempbuff[0];
-                       modi=tempbuff[1];
-                       if((perq & 0x1f)==0x1f) {
-                               continue; /* skip unknown devices */
-                       }
-                       if((modi&0x80)==0x80) /* drive is removable */
-                               scsi_dev_desc[scsi_max_devs].removable=true;
-                       /* get info for this device */
-                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].vendor[0],
-                                      &tempbuff[8], 8);
-                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].product[0],
-                                      &tempbuff[16], 16);
-                       scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].revision[0],
-                                      &tempbuff[32], 4);
-                       scsi_dev_desc[scsi_max_devs].target=pccb->target;
-                       scsi_dev_desc[scsi_max_devs].lun=pccb->lun;
-
-                       pccb->datalen=0;
-                       scsi_setup_test_unit_ready(pccb);
-                       if (scsi_exec(pccb) != true) {
-                               if (scsi_dev_desc[scsi_max_devs].removable == true) {
-                                       scsi_dev_desc[scsi_max_devs].type=perq;
-                                       goto removable;
-                               }
-                               scsi_print_error(pccb);
-                               continue;
-                       }
-                       if (scsi_read_capacity(pccb, &capacity, &blksz)) {
-                               scsi_print_error(pccb);
-                               continue;
-                       }
-                       scsi_dev_desc[scsi_max_devs].lba=capacity;
-                       scsi_dev_desc[scsi_max_devs].blksz=blksz;
-                       scsi_dev_desc[scsi_max_devs].log2blksz =
-                               LOG2(scsi_dev_desc[scsi_max_devs].blksz);
-                       scsi_dev_desc[scsi_max_devs].type=perq;
-                       init_part(&scsi_dev_desc[scsi_max_devs]);
-removable:
-                       if(mode==1) {
-                               printf ("  Device %d: ", scsi_max_devs);
-                               dev_print(&scsi_dev_desc[scsi_max_devs]);
-                       } /* if mode */
-                       scsi_max_devs++;
-               } /* next LUN */
-       }
-       if(scsi_max_devs>0)
-               scsi_curr_dev=0;
-       else
-               scsi_curr_dev = -1;
-
-       printf("Found %d device(s).\n", scsi_max_devs);
-#ifndef CONFIG_SPL_BUILD
-       setenv_ulong("scsidevs", scsi_max_devs);
-#endif
-}
-
-int scsi_get_disk_count(void)
-{
-       return scsi_max_devs;
-}
-
-#if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT)
-void scsi_init(void)
-{
-       int busdevfunc = -1;
-       int i;
-       /*
-        * Find a device from the list, this driver will support a single
-        * controller.
-        */
-       for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
-               /* get PCI Device ID */
-#ifdef CONFIG_DM_PCI
-               struct udevice *dev;
-               int ret;
-
-               ret = dm_pci_find_device(scsi_device_list[i].vendor,
-                                        scsi_device_list[i].device, 0, &dev);
-               if (!ret) {
-                       busdevfunc = dm_pci_get_bdf(dev);
-                       break;
-               }
-#else
-               busdevfunc = pci_find_device(scsi_device_list[i].vendor,
-                                            scsi_device_list[i].device,
-                                            0);
-#endif
-               if (busdevfunc != -1)
-                       break;
-       }
-
-       if (busdevfunc == -1) {
-               printf("Error: SCSI Controller(s) ");
-               for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
-                       printf("%04X:%04X ",
-                              scsi_device_list[i].vendor,
-                              scsi_device_list[i].device);
-               }
-               printf("not found\n");
-               return;
-       }
-#ifdef DEBUG
-       else {
-               printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n",
-                      scsi_device_list[i].vendor,
-                      scsi_device_list[i].device,
-                      (busdevfunc >> 16) & 0xFF,
-                      (busdevfunc >> 11) & 0x1F,
-                      (busdevfunc >> 8) & 0x7);
-       }
-#endif
-       bootstage_start(BOOTSTAGE_ID_ACCUM_SCSI, "ahci");
-       scsi_low_level_init(busdevfunc);
-       scsi_scan(1);
-       bootstage_accum(BOOTSTAGE_ID_ACCUM_SCSI);
-}
-#endif
-
-#ifdef CONFIG_PARTITIONS
-block_dev_desc_t * scsi_get_dev(int dev)
-{
-       return (dev < CONFIG_SYS_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL;
-}
-#endif
-
-/******************************************************************************
- * scsi boot command intepreter. Derived from diskboot
- */
-int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return common_diskboot(cmdtp, "scsi", argc, argv);
-}
-
-/*********************************************************************************
- * scsi command intepreter
- */
-int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       switch (argc) {
-       case 0:
-       case 1:
-               return CMD_RET_USAGE;
-
-       case 2:
-                       if (strncmp(argv[1],"res",3) == 0) {
-                               printf("\nReset SCSI\n");
-                               scsi_bus_reset();
-                               scsi_scan(1);
-                               return 0;
-                       }
-                       if (strncmp(argv[1],"inf",3) == 0) {
-                               int i;
-                               for (i=0; i<CONFIG_SYS_SCSI_MAX_DEVICE; ++i) {
-                                       if(scsi_dev_desc[i].type==DEV_TYPE_UNKNOWN)
-                                               continue; /* list only known devices */
-                                       printf ("SCSI dev. %d:  ", i);
-                                       dev_print(&scsi_dev_desc[i]);
-                               }
-                               return 0;
-                       }
-                       if (strncmp(argv[1],"dev",3) == 0) {
-                               if ((scsi_curr_dev < 0) || (scsi_curr_dev >= CONFIG_SYS_SCSI_MAX_DEVICE)) {
-                                       printf("\nno SCSI devices available\n");
-                                       return 1;
-                               }
-                               printf ("\n    Device %d: ", scsi_curr_dev);
-                               dev_print(&scsi_dev_desc[scsi_curr_dev]);
-                               return 0;
-                       }
-                       if (strncmp(argv[1],"scan",4) == 0) {
-                               scsi_scan(1);
-                               return 0;
-                       }
-                       if (strncmp(argv[1],"part",4) == 0) {
-                               int dev, ok;
-                               for (ok=0, dev=0; dev<CONFIG_SYS_SCSI_MAX_DEVICE; ++dev) {
-                                       if (scsi_dev_desc[dev].type!=DEV_TYPE_UNKNOWN) {
-                                               ok++;
-                                               if (dev)
-                                                       printf("\n");
-                                               debug ("print_part of %x\n",dev);
-                                                       print_part(&scsi_dev_desc[dev]);
-                                       }
-                               }
-                               if (!ok)
-                                       printf("\nno SCSI devices available\n");
-                               return 1;
-                       }
-                       return CMD_RET_USAGE;
-       case 3:
-                       if (strncmp(argv[1],"dev",3) == 0) {
-                               int dev = (int)simple_strtoul(argv[2], NULL, 10);
-                               printf ("\nSCSI device %d: ", dev);
-                               if (dev >= CONFIG_SYS_SCSI_MAX_DEVICE) {
-                                       printf("unknown device\n");
-                                       return 1;
-                               }
-                               printf ("\n    Device %d: ", dev);
-                               dev_print(&scsi_dev_desc[dev]);
-                               if(scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
-                                       return 1;
-                               }
-                               scsi_curr_dev = dev;
-                               printf("... is now current device\n");
-                               return 0;
-                       }
-                       if (strncmp(argv[1],"part",4) == 0) {
-                               int dev = (int)simple_strtoul(argv[2], NULL, 10);
-                               if(scsi_dev_desc[dev].type != DEV_TYPE_UNKNOWN) {
-                                       print_part(&scsi_dev_desc[dev]);
-                               }
-                               else {
-                                       printf ("\nSCSI device %d not available\n", dev);
-                               }
-                               return 1;
-                       }
-                       return CMD_RET_USAGE;
-    default:
-                       /* at least 4 args */
-                       if (strcmp(argv[1],"read") == 0) {
-                               ulong addr = simple_strtoul(argv[2], NULL, 16);
-                               ulong blk  = simple_strtoul(argv[3], NULL, 16);
-                               ulong cnt  = simple_strtoul(argv[4], NULL, 16);
-                               ulong n;
-                               printf ("\nSCSI read: device %d block # %ld, count %ld ... ",
-                                               scsi_curr_dev, blk, cnt);
-                               n = scsi_read(&scsi_dev_desc[scsi_curr_dev],
-                                             blk, cnt, (ulong *)addr);
-                               printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR");
-                               return 0;
-                       } else if (strcmp(argv[1], "write") == 0) {
-                               ulong addr = simple_strtoul(argv[2], NULL, 16);
-                               ulong blk = simple_strtoul(argv[3], NULL, 16);
-                               ulong cnt = simple_strtoul(argv[4], NULL, 16);
-                               ulong n;
-                               printf("\nSCSI write: device %d block # %ld, "
-                                      "count %ld ... ",
-                                      scsi_curr_dev, blk, cnt);
-                               n = scsi_write(&scsi_dev_desc[scsi_curr_dev],
-                                              blk, cnt, (ulong *)addr);
-                               printf("%ld blocks written: %s\n", n,
-                                      (n == cnt) ? "OK" : "ERROR");
-                               return 0;
-                       }
-       } /* switch */
-       return CMD_RET_USAGE;
-}
-
-/****************************************************************************************
- * scsi_read
- */
-
-/* almost the maximum amount of the scsi_ext command.. */
-#define SCSI_MAX_READ_BLK 0xFFFF
-#define SCSI_LBA48_READ        0xFFFFFFF
-
-static ulong scsi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
-                      lbaint_t blkcnt, void *buffer)
-{
-       int device = block_dev->dev;
-       lbaint_t start, blks;
-       uintptr_t buf_addr;
-       unsigned short smallblks = 0;
-       ccb* pccb=(ccb *)&tempccb;
-       device&=0xff;
-       /* Setup  device
-        */
-       pccb->target=scsi_dev_desc[device].target;
-       pccb->lun=scsi_dev_desc[device].lun;
-       buf_addr=(unsigned long)buffer;
-       start=blknr;
-       blks=blkcnt;
-       debug("\nscsi_read: dev %d startblk " LBAF
-             ", blccnt " LBAF " buffer %lx\n",
-             device, start, blks, (unsigned long)buffer);
-       do {
-               pccb->pdata=(unsigned char *)buf_addr;
-#ifdef CONFIG_SYS_64BIT_LBA
-               if (start > SCSI_LBA48_READ) {
-                       unsigned long blocks;
-                       blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK);
-                       pccb->datalen = scsi_dev_desc[device].blksz * blocks;
-                       scsi_setup_read16(pccb, start, blocks);
-                       start += blocks;
-                       blks -= blocks;
-               } else
-#endif
-               if (blks > SCSI_MAX_READ_BLK) {
-                       pccb->datalen=scsi_dev_desc[device].blksz * SCSI_MAX_READ_BLK;
-                       smallblks=SCSI_MAX_READ_BLK;
-                       scsi_setup_read_ext(pccb,start,smallblks);
-                       start+=SCSI_MAX_READ_BLK;
-                       blks-=SCSI_MAX_READ_BLK;
-               }
-               else {
-                       pccb->datalen=scsi_dev_desc[device].blksz * blks;
-                       smallblks=(unsigned short) blks;
-                       scsi_setup_read_ext(pccb,start,smallblks);
-                       start+=blks;
-                       blks=0;
-               }
-               debug("scsi_read_ext: startblk " LBAF
-                     ", blccnt %x buffer %" PRIXPTR "\n",
-                     start, smallblks, buf_addr);
-               if (scsi_exec(pccb) != true) {
-                       scsi_print_error(pccb);
-                       blkcnt-=blks;
-                       break;
-               }
-               buf_addr+=pccb->datalen;
-       } while(blks!=0);
-       debug("scsi_read_ext: end startblk " LBAF
-             ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr);
-       return(blkcnt);
-}
-
-/*******************************************************************************
- * scsi_write
- */
-
-/* Almost the maximum amount of the scsi_ext command.. */
-#define SCSI_MAX_WRITE_BLK 0xFFFF
-
-static ulong scsi_write(block_dev_desc_t *block_dev, lbaint_t blknr,
-                       lbaint_t blkcnt, const void *buffer)
-{
-       int device = block_dev->dev;
-       lbaint_t start, blks;
-       uintptr_t buf_addr;
-       unsigned short smallblks;
-       ccb* pccb = (ccb *)&tempccb;
-       device &= 0xff;
-       /* Setup  device
-        */
-       pccb->target = scsi_dev_desc[device].target;
-       pccb->lun = scsi_dev_desc[device].lun;
-       buf_addr = (unsigned long)buffer;
-       start = blknr;
-       blks = blkcnt;
-       debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
-             __func__, device, start, blks, (unsigned long)buffer);
-       do {
-               pccb->pdata = (unsigned char *)buf_addr;
-               if (blks > SCSI_MAX_WRITE_BLK) {
-                       pccb->datalen = (scsi_dev_desc[device].blksz *
-                                        SCSI_MAX_WRITE_BLK);
-                       smallblks = SCSI_MAX_WRITE_BLK;
-                       scsi_setup_write_ext(pccb, start, smallblks);
-                       start += SCSI_MAX_WRITE_BLK;
-                       blks -= SCSI_MAX_WRITE_BLK;
-               } else {
-                       pccb->datalen = scsi_dev_desc[device].blksz * blks;
-                       smallblks = (unsigned short)blks;
-                       scsi_setup_write_ext(pccb, start, smallblks);
-                       start += blks;
-                       blks = 0;
-               }
-               debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
-                     __func__, start, smallblks, buf_addr);
-               if (scsi_exec(pccb) != true) {
-                       scsi_print_error(pccb);
-                       blkcnt -= blks;
-                       break;
-               }
-               buf_addr += pccb->datalen;
-       } while (blks != 0);
-       debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
-             __func__, start, smallblks, buf_addr);
-       return blkcnt;
-}
-
-/* copy src to dest, skipping leading and trailing blanks
- * and null terminate the string
- */
-void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len)
-{
-       int start,end;
-
-       start=0;
-       while(start<len) {
-               if(src[start]!=' ')
-                       break;
-               start++;
-       }
-       end=len-1;
-       while(end>start) {
-               if(src[end]!=' ')
-                       break;
-               end--;
-       }
-       for( ; start<=end; start++) {
-               *dest++=src[start];
-       }
-       *dest='\0';
-}
-
-
-/* Trim trailing blanks, and NUL-terminate string
- */
-void scsi_trim_trail (unsigned char *str, unsigned int len)
-{
-       unsigned char *p = str + len - 1;
-
-       while (len-- > 0) {
-               *p-- = '\0';
-               if (*p != ' ') {
-                       return;
-               }
-       }
-}
-
-int scsi_read_capacity(ccb *pccb, lbaint_t *capacity, unsigned long *blksz)
-{
-       *capacity = 0;
-
-       memset(pccb->cmd, 0, sizeof(pccb->cmd));
-       pccb->cmd[0] = SCSI_RD_CAPAC10;
-       pccb->cmd[1] = pccb->lun << 5;
-       pccb->cmdlen = 10;
-       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
-
-       pccb->datalen = 8;
-       if (scsi_exec(pccb) != true)
-               return 1;
-
-       *capacity = ((lbaint_t)pccb->pdata[0] << 24) |
-                   ((lbaint_t)pccb->pdata[1] << 16) |
-                   ((lbaint_t)pccb->pdata[2] << 8)  |
-                   ((lbaint_t)pccb->pdata[3]);
-
-       if (*capacity != 0xffffffff) {
-               /* Read capacity (10) was sufficient for this drive. */
-               *blksz = ((unsigned long)pccb->pdata[4] << 24) |
-                        ((unsigned long)pccb->pdata[5] << 16) |
-                        ((unsigned long)pccb->pdata[6] << 8)  |
-                        ((unsigned long)pccb->pdata[7]);
-               return 0;
-       }
-
-       /* Read capacity (10) was insufficient. Use read capacity (16). */
-
-       memset(pccb->cmd, 0, sizeof(pccb->cmd));
-       pccb->cmd[0] = SCSI_RD_CAPAC16;
-       pccb->cmd[1] = 0x10;
-       pccb->cmdlen = 16;
-       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
-
-       pccb->datalen = 16;
-       if (scsi_exec(pccb) != true)
-               return 1;
-
-       *capacity = ((uint64_t)pccb->pdata[0] << 56) |
-                   ((uint64_t)pccb->pdata[1] << 48) |
-                   ((uint64_t)pccb->pdata[2] << 40) |
-                   ((uint64_t)pccb->pdata[3] << 32) |
-                   ((uint64_t)pccb->pdata[4] << 24) |
-                   ((uint64_t)pccb->pdata[5] << 16) |
-                   ((uint64_t)pccb->pdata[6] << 8)  |
-                   ((uint64_t)pccb->pdata[7]);
-
-       *blksz = ((uint64_t)pccb->pdata[8]  << 56) |
-                ((uint64_t)pccb->pdata[9]  << 48) |
-                ((uint64_t)pccb->pdata[10] << 40) |
-                ((uint64_t)pccb->pdata[11] << 32) |
-                ((uint64_t)pccb->pdata[12] << 24) |
-                ((uint64_t)pccb->pdata[13] << 16) |
-                ((uint64_t)pccb->pdata[14] << 8)  |
-                ((uint64_t)pccb->pdata[15]);
-
-       return 0;
-}
-
-
-/************************************************************************************
- * Some setup (fill-in) routines
- */
-void scsi_setup_test_unit_ready(ccb * pccb)
-{
-       pccb->cmd[0]=SCSI_TST_U_RDY;
-       pccb->cmd[1]=pccb->lun<<5;
-       pccb->cmd[2]=0;
-       pccb->cmd[3]=0;
-       pccb->cmd[4]=0;
-       pccb->cmd[5]=0;
-       pccb->cmdlen=6;
-       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-}
-
-#ifdef CONFIG_SYS_64BIT_LBA
-void scsi_setup_read16(ccb * pccb, lbaint_t start, unsigned long blocks)
-{
-       pccb->cmd[0] = SCSI_READ16;
-       pccb->cmd[1] = pccb->lun<<5;
-       pccb->cmd[2] = ((unsigned char) (start >> 56)) & 0xff;
-       pccb->cmd[3] = ((unsigned char) (start >> 48)) & 0xff;
-       pccb->cmd[4] = ((unsigned char) (start >> 40)) & 0xff;
-       pccb->cmd[5] = ((unsigned char) (start >> 32)) & 0xff;
-       pccb->cmd[6] = ((unsigned char) (start >> 24)) & 0xff;
-       pccb->cmd[7] = ((unsigned char) (start >> 16)) & 0xff;
-       pccb->cmd[8] = ((unsigned char) (start >> 8)) & 0xff;
-       pccb->cmd[9] = ((unsigned char) (start)) & 0xff;
-       pccb->cmd[10] = 0;
-       pccb->cmd[11] = ((unsigned char) (blocks >> 24)) & 0xff;
-       pccb->cmd[12] = ((unsigned char) (blocks >> 16)) & 0xff;
-       pccb->cmd[13] = ((unsigned char) (blocks >> 8)) & 0xff;
-       pccb->cmd[14] = (unsigned char) blocks & 0xff;
-       pccb->cmd[15] = 0;
-       pccb->cmdlen = 16;
-       pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
-       debug ("scsi_setup_read16: cmd: %02X %02X "
-              "startblk %02X%02X%02X%02X%02X%02X%02X%02X "
-              "blccnt %02X%02X%02X%02X\n",
-               pccb->cmd[0], pccb->cmd[1],
-               pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5],
-               pccb->cmd[6], pccb->cmd[7], pccb->cmd[8], pccb->cmd[9],
-               pccb->cmd[11], pccb->cmd[12], pccb->cmd[13], pccb->cmd[14]);
-}
-#endif
-
-void scsi_setup_read_ext(ccb * pccb, lbaint_t start, unsigned short blocks)
-{
-       pccb->cmd[0]=SCSI_READ10;
-       pccb->cmd[1]=pccb->lun<<5;
-       pccb->cmd[2]=((unsigned char) (start>>24))&0xff;
-       pccb->cmd[3]=((unsigned char) (start>>16))&0xff;
-       pccb->cmd[4]=((unsigned char) (start>>8))&0xff;
-       pccb->cmd[5]=((unsigned char) (start))&0xff;
-       pccb->cmd[6]=0;
-       pccb->cmd[7]=((unsigned char) (blocks>>8))&0xff;
-       pccb->cmd[8]=(unsigned char) blocks & 0xff;
-       pccb->cmd[6]=0;
-       pccb->cmdlen=10;
-       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-       debug ("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
-               pccb->cmd[0],pccb->cmd[1],
-               pccb->cmd[2],pccb->cmd[3],pccb->cmd[4],pccb->cmd[5],
-               pccb->cmd[7],pccb->cmd[8]);
-}
-
-void scsi_setup_write_ext(ccb *pccb, lbaint_t start, unsigned short blocks)
-{
-       pccb->cmd[0] = SCSI_WRITE10;
-       pccb->cmd[1] = pccb->lun << 5;
-       pccb->cmd[2] = ((unsigned char) (start>>24)) & 0xff;
-       pccb->cmd[3] = ((unsigned char) (start>>16)) & 0xff;
-       pccb->cmd[4] = ((unsigned char) (start>>8)) & 0xff;
-       pccb->cmd[5] = ((unsigned char) (start)) & 0xff;
-       pccb->cmd[6] = 0;
-       pccb->cmd[7] = ((unsigned char) (blocks>>8)) & 0xff;
-       pccb->cmd[8] = (unsigned char)blocks & 0xff;
-       pccb->cmd[9] = 0;
-       pccb->cmdlen = 10;
-       pccb->msgout[0] = SCSI_IDENTIFY;  /* NOT USED */
-       debug("%s: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
-             __func__,
-             pccb->cmd[0], pccb->cmd[1],
-             pccb->cmd[2], pccb->cmd[3], pccb->cmd[4], pccb->cmd[5],
-             pccb->cmd[7], pccb->cmd[8]);
-}
-
-void scsi_setup_read6(ccb * pccb, lbaint_t start, unsigned short blocks)
-{
-       pccb->cmd[0]=SCSI_READ6;
-       pccb->cmd[1]=pccb->lun<<5 | (((unsigned char)(start>>16))&0x1f);
-       pccb->cmd[2]=((unsigned char) (start>>8))&0xff;
-       pccb->cmd[3]=((unsigned char) (start))&0xff;
-       pccb->cmd[4]=(unsigned char) blocks & 0xff;
-       pccb->cmd[5]=0;
-       pccb->cmdlen=6;
-       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-       debug ("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n",
-               pccb->cmd[0],pccb->cmd[1],
-               pccb->cmd[2],pccb->cmd[3],pccb->cmd[4]);
-}
-
-
-void scsi_setup_inquiry(ccb * pccb)
-{
-       pccb->cmd[0]=SCSI_INQUIRY;
-       pccb->cmd[1]=pccb->lun<<5;
-       pccb->cmd[2]=0;
-       pccb->cmd[3]=0;
-       if(pccb->datalen>255)
-               pccb->cmd[4]=255;
-       else
-               pccb->cmd[4]=(unsigned char)pccb->datalen;
-       pccb->cmd[5]=0;
-       pccb->cmdlen=6;
-       pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-}
-
-
-U_BOOT_CMD(
-       scsi, 5, 1, do_scsi,
-       "SCSI sub-system",
-       "reset - reset SCSI controller\n"
-       "scsi info  - show available SCSI devices\n"
-       "scsi scan  - (re-)scan SCSI bus\n"
-       "scsi device [dev] - show or set current device\n"
-       "scsi part [dev] - print partition table of one or all SCSI devices\n"
-       "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
-       "     to memory address `addr'\n"
-       "scsi write addr blk# cnt - write `cnt' blocks starting at block\n"
-       "     `blk#' from memory address `addr'"
-);
-
-U_BOOT_CMD(
-       scsiboot, 3, 1, do_scsiboot,
-       "boot from SCSI device",
-       "loadAddr dev:part"
-);
diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c
deleted file mode 100644 (file)
index e7194fc..0000000
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * Copyright 2008 Freescale Semiconductor, Inc.
- * Copyright 2013 Wolfgang Denk <wd@denx.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * This file provides a shell like 'expr' function to return.
- */
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <mapmem.h>
-
-static ulong get_arg(char *s, int w)
-{
-       /*
-        * If the parameter starts with a '*' then assume it is a pointer to
-        * the value we want.
-        */
-       if (s[0] == '*') {
-               ulong *p;
-               ulong addr;
-               ulong val;
-
-               addr = simple_strtoul(&s[1], NULL, 16);
-               switch (w) {
-               case 1:
-                       p = map_sysmem(addr, sizeof(uchar));
-                       val = (ulong)*(uchar *)p;
-                       unmap_sysmem(p);
-                       return val;
-               case 2:
-                       p = map_sysmem(addr, sizeof(ushort));
-                       val = (ulong)*(ushort *)p;
-                       unmap_sysmem(p);
-                       return val;
-               case 4:
-               default:
-                       p = map_sysmem(addr, sizeof(ulong));
-                       val = *p;
-                       unmap_sysmem(p);
-                       return val;
-               }
-       } else {
-               return simple_strtoul(s, NULL, 16);
-       }
-}
-
-#ifdef CONFIG_REGEX
-
-#include <slre.h>
-
-#define SLRE_BUFSZ     16384
-#define SLRE_PATSZ     4096
-
-/*
- * memstr - Find the first substring in memory
- * @s1: The string to be searched
- * @s2: The string to search for
- *
- * Similar to and based on strstr(),
- * but strings do not need to be NUL terminated.
- */
-static char *memstr(const char *s1, int l1, const char *s2, int l2)
-{
-       if (!l2)
-               return (char *)s1;
-
-       while (l1 >= l2) {
-               l1--;
-               if (!memcmp(s1, s2, l2))
-                       return (char *)s1;
-               s1++;
-       }
-       return NULL;
-}
-
-static char *substitute(char *string,  /* string buffer */
-                       int *slen,      /* current string length */
-                       int ssize,      /* string bufer size */
-                       const char *old,/* old (replaced) string */
-                       int olen,       /* length of old string */
-                       const char *new,/* new (replacement) string */
-                       int nlen)       /* length of new string */
-{
-       char *p = memstr(string, *slen, old, olen);
-
-       if (p == NULL)
-               return NULL;
-
-       debug("## Match at pos %ld: match len %d, subst len %d\n",
-               (long)(p - string), olen, nlen);
-
-       /* make sure replacement matches */
-       if (*slen + nlen - olen > ssize) {
-               printf("## error: substitution buffer overflow\n");
-               return NULL;
-       }
-
-       /* move tail if needed */
-       if (olen != nlen) {
-               int tail, len;
-
-               len = (olen > nlen) ? olen : nlen;
-
-               tail = ssize - (p + len - string);
-
-               debug("## tail len %d\n", tail);
-
-               memmove(p + nlen, p + olen, tail);
-       }
-
-       /* insert substitue */
-       memcpy(p, new, nlen);
-
-       *slen += nlen - olen;
-
-       return p + nlen;
-}
-
-/*
- * Perform regex operations on a environment variable
- *
- * Returns 0 if OK, 1 in case of errors.
- */
-static int regex_sub(const char *name,
-       const char *r, const char *s, const char *t,
-       int global)
-{
-       struct slre slre;
-       char data[SLRE_BUFSZ];
-       char *datap = data;
-       const char *value;
-       int res, len, nlen, loop;
-
-       if (name == NULL)
-               return 1;
-
-       if (slre_compile(&slre, r) == 0) {
-               printf("Error compiling regex: %s\n", slre.err_str);
-               return 1;
-       }
-
-       if (t == NULL) {
-               value = getenv(name);
-
-               if (value == NULL) {
-                       printf("## Error: variable \"%s\" not defined\n", name);
-                       return 1;
-               }
-               t = value;
-       }
-
-       debug("REGEX on %s=%s\n", name, t);
-       debug("REGEX=\"%s\", SUBST=\"%s\", GLOBAL=%d\n",
-               r, s ? s : "<NULL>", global);
-
-       len = strlen(t);
-       if (len + 1 > SLRE_BUFSZ) {
-               printf("## error: subst buffer overflow: have %d, need %d\n",
-                       SLRE_BUFSZ, len + 1);
-               return 1;
-       }
-
-       strcpy(data, t);
-
-       if (s == NULL)
-               nlen = 0;
-       else
-               nlen = strlen(s);
-
-       for (loop = 0;; loop++) {
-               struct cap caps[slre.num_caps + 2];
-               char nbuf[SLRE_PATSZ];
-               const char *old;
-               char *np;
-               int i, olen;
-
-               (void) memset(caps, 0, sizeof(caps));
-
-               res = slre_match(&slre, datap, len, caps);
-
-               debug("Result: %d\n", res);
-
-               for (i = 0; i < slre.num_caps; i++) {
-                       if (caps[i].len > 0) {
-                               debug("Substring %d: [%.*s]\n", i,
-                                       caps[i].len, caps[i].ptr);
-                       }
-               }
-
-               if (res == 0) {
-                       if (loop == 0) {
-                               printf("%s: No match\n", t);
-                               return 1;
-                       } else {
-                               break;
-                       }
-               }
-
-               debug("## MATCH ## %s\n", data);
-
-               if (s == NULL) {
-                       printf("%s=%s\n", name, t);
-                       return 1;
-               }
-
-               old = caps[0].ptr;
-               olen = caps[0].len;
-
-               if (nlen + 1 >= SLRE_PATSZ) {
-                       printf("## error: pattern buffer overflow: have %d, need %d\n",
-                               SLRE_BUFSZ, nlen + 1);
-                       return 1;
-               }
-               strcpy(nbuf, s);
-
-               debug("## SUBST(1) ## %s\n", nbuf);
-
-               /*
-                * Handle back references
-                *
-                * Support for \0 ... \9, where \0 is the
-                * whole matched pattern (similar to &).
-                *
-                * Implementation is a bit simpleminded as
-                * backrefs are substituted sequentially, one
-                * by one.  This will lead to somewhat
-                * unexpected results if the replacement
-                * strings contain any \N strings then then
-                * may get substitued, too.  We accept this
-                * restriction for the sake of simplicity.
-                */
-               for (i = 0; i < 10; ++i) {
-                       char backref[2] = {
-                               '\\',
-                               '0',
-                       };
-
-                       if (caps[i].len == 0)
-                               break;
-
-                       backref[1] += i;
-
-                       debug("## BACKREF %d: replace \"%.*s\" by \"%.*s\" in \"%s\"\n",
-                               i,
-                               2, backref,
-                               caps[i].len, caps[i].ptr,
-                               nbuf);
-
-                       for (np = nbuf;;) {
-                               char *p = memstr(np, nlen, backref, 2);
-
-                               if (p == NULL)
-                                       break;
-
-                               np = substitute(np, &nlen,
-                                       SLRE_PATSZ,
-                                       backref, 2,
-                                       caps[i].ptr, caps[i].len);
-
-                               if (np == NULL)
-                                       return 1;
-                       }
-               }
-               debug("## SUBST(2) ## %s\n", nbuf);
-
-               datap = substitute(datap, &len, SLRE_BUFSZ,
-                               old, olen,
-                               nbuf, nlen);
-
-               if (datap == NULL)
-                       return 1;
-
-               debug("## REMAINDER: %s\n", datap);
-
-               debug("## RESULT: %s\n", data);
-
-               if (!global)
-                       break;
-       }
-       debug("## FINAL (now setenv()) :  %s\n", data);
-
-       printf("%s=%s\n", name, data);
-
-       return setenv(name, data);
-}
-#endif
-
-static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong a, b;
-       ulong value;
-       int w;
-
-       /*
-        * We take 3, 5, or 6 arguments:
-        * 3 : setexpr name value
-        * 5 : setexpr name val1 op val2
-        *     setexpr name [g]sub r s
-        * 6 : setexpr name [g]sub r s t
-        */
-
-       /* > 6 already tested by max command args */
-       if ((argc < 3) || (argc == 4))
-               return CMD_RET_USAGE;
-
-       w = cmd_get_data_size(argv[0], 4);
-
-       a = get_arg(argv[2], w);
-
-       /* plain assignment: "setexpr name value" */
-       if (argc == 3) {
-               setenv_hex(argv[1], a);
-               return 0;
-       }
-
-       /* 5 or 6 args (6 args only with [g]sub) */
-#ifdef CONFIG_REGEX
-       /*
-        * rexep handling: "setexpr name [g]sub r s [t]"
-        * with 5 args, "t" will be NULL
-        */
-       if (strcmp(argv[2], "gsub") == 0)
-               return regex_sub(argv[1], argv[3], argv[4], argv[5], 1);
-
-       if (strcmp(argv[2], "sub") == 0)
-               return regex_sub(argv[1], argv[3], argv[4], argv[5], 0);
-#endif
-
-       /* standard operators: "setexpr name val1 op val2" */
-       if (argc != 5)
-               return CMD_RET_USAGE;
-
-       if (strlen(argv[3]) != 1)
-               return CMD_RET_USAGE;
-
-       b = get_arg(argv[4], w);
-
-       switch (argv[3][0]) {
-       case '|':
-               value = a | b;
-               break;
-       case '&':
-               value = a & b;
-               break;
-       case '+':
-               value = a + b;
-               break;
-       case '^':
-               value = a ^ b;
-               break;
-       case '-':
-               value = a - b;
-               break;
-       case '*':
-               value = a * b;
-               break;
-       case '/':
-               value = a / b;
-               break;
-       case '%':
-               value = a % b;
-               break;
-       default:
-               printf("invalid op\n");
-               return 1;
-       }
-
-       setenv_hex(argv[1], value);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       setexpr, 6, 0, do_setexpr,
-       "set environment variable as the result of eval expression",
-       "[.b, .w, .l] name [*]value1 <op> [*]value2\n"
-       "    - set environment variable 'name' to the result of the evaluated\n"
-       "      expression specified by <op>.  <op> can be &, |, ^, +, -, *, /, %\n"
-       "      size argument is only meaningful if value1 and/or value2 are\n"
-       "      memory addresses (*)\n"
-       "setexpr[.b, .w, .l] name [*]value\n"
-       "    - load a value into a variable"
-#ifdef CONFIG_REGEX
-       "\n"
-       "setexpr name gsub r s [t]\n"
-       "    - For each substring matching the regular expression <r> in the\n"
-       "      string <t>, substitute the string <s>.  The result is\n"
-       "      assigned to <name>.  If <t> is not supplied, use the old\n"
-       "      value of <name>\n"
-       "setexpr name sub r s [t]\n"
-       "    - Just like gsub(), but replace only the first matching substring"
-#endif
-);
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
deleted file mode 100644 (file)
index 42862d9..0000000
+++ /dev/null
@@ -1,618 +0,0 @@
-/*
- * Command for accessing SPI flash.
- *
- * Copyright (C) 2008 Atmel Corporation
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <div64.h>
-#include <dm.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <spi.h>
-#include <spi_flash.h>
-#include <jffs2/jffs2.h>
-#include <linux/mtd/mtd.h>
-
-#include <asm/io.h>
-#include <dm/device-internal.h>
-
-static struct spi_flash *flash;
-
-/*
- * This function computes the length argument for the erase command.
- * The length on which the command is to operate can be given in two forms:
- * 1. <cmd> offset len  - operate on <'offset',  'len')
- * 2. <cmd> offset +len - operate on <'offset',  'round_up(len)')
- * If the second form is used and the length doesn't fall on the
- * sector boundary, than it will be adjusted to the next sector boundary.
- * If it isn't in the flash, the function will fail (return -1).
- * Input:
- *    arg: length specification (i.e. both command arguments)
- * Output:
- *    len: computed length for operation
- * Return:
- *    1: success
- *   -1: failure (bad format, bad address).
- */
-static int sf_parse_len_arg(char *arg, ulong *len)
-{
-       char *ep;
-       char round_up_len; /* indicates if the "+length" form used */
-       ulong len_arg;
-
-       round_up_len = 0;
-       if (*arg == '+') {
-               round_up_len = 1;
-               ++arg;
-       }
-
-       len_arg = simple_strtoul(arg, &ep, 16);
-       if (ep == arg || *ep != '\0')
-               return -1;
-
-       if (round_up_len && flash->sector_size > 0)
-               *len = ROUND(len_arg, flash->sector_size);
-       else
-               *len = len_arg;
-
-       return 1;
-}
-
-/**
- * This function takes a byte length and a delta unit of time to compute the
- * approximate bytes per second
- *
- * @param len          amount of bytes currently processed
- * @param start_ms     start time of processing in ms
- * @return bytes per second if OK, 0 on error
- */
-static ulong bytes_per_second(unsigned int len, ulong start_ms)
-{
-       /* less accurate but avoids overflow */
-       if (len >= ((unsigned int) -1) / 1024)
-               return len / (max(get_timer(start_ms) / 1024, 1UL));
-       else
-               return 1024 * len / max(get_timer(start_ms), 1UL);
-}
-
-static int do_spi_flash_probe(int argc, char * const argv[])
-{
-       unsigned int bus = CONFIG_SF_DEFAULT_BUS;
-       unsigned int cs = CONFIG_SF_DEFAULT_CS;
-       unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
-       unsigned int mode = CONFIG_SF_DEFAULT_MODE;
-       char *endp;
-#ifdef CONFIG_DM_SPI_FLASH
-       struct udevice *new, *bus_dev;
-       int ret;
-#else
-       struct spi_flash *new;
-#endif
-
-       if (argc >= 2) {
-               cs = simple_strtoul(argv[1], &endp, 0);
-               if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
-                       return -1;
-               if (*endp == ':') {
-                       if (endp[1] == 0)
-                               return -1;
-
-                       bus = cs;
-                       cs = simple_strtoul(endp + 1, &endp, 0);
-                       if (*endp != 0)
-                               return -1;
-               }
-       }
-
-       if (argc >= 3) {
-               speed = simple_strtoul(argv[2], &endp, 0);
-               if (*argv[2] == 0 || *endp != 0)
-                       return -1;
-       }
-       if (argc >= 4) {
-               mode = simple_strtoul(argv[3], &endp, 16);
-               if (*argv[3] == 0 || *endp != 0)
-                       return -1;
-       }
-
-#ifdef CONFIG_DM_SPI_FLASH
-       /* Remove the old device, otherwise probe will just be a nop */
-       ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
-       if (!ret) {
-               device_remove(new);
-               device_unbind(new);
-       }
-       flash = NULL;
-       ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
-       if (ret) {
-               printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
-                      bus, cs, ret);
-               return 1;
-       }
-
-       flash = dev_get_uclass_priv(new);
-#else
-       if (flash)
-               spi_flash_free(flash);
-
-       new = spi_flash_probe(bus, cs, speed, mode);
-       flash = new;
-
-       if (!new) {
-               printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
-               return 1;
-       }
-
-       flash = new;
-#endif
-
-       return 0;
-}
-
-/**
- * Write a block of data to SPI flash, first checking if it is different from
- * what is already there.
- *
- * If the data being written is the same, then *skipped is incremented by len.
- *
- * @param flash                flash context pointer
- * @param offset       flash offset to write
- * @param len          number of bytes to write
- * @param buf          buffer to write from
- * @param cmp_buf      read buffer to use to compare data
- * @param skipped      Count of skipped data (incremented by this function)
- * @return NULL if OK, else a string containing the stage which failed
- */
-static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
-               size_t len, const char *buf, char *cmp_buf, size_t *skipped)
-{
-       char *ptr = (char *)buf;
-
-       debug("offset=%#x, sector_size=%#x, len=%#zx\n",
-             offset, flash->sector_size, len);
-       /* Read the entire sector so to allow for rewriting */
-       if (spi_flash_read(flash, offset, flash->sector_size, cmp_buf))
-               return "read";
-       /* Compare only what is meaningful (len) */
-       if (memcmp(cmp_buf, buf, len) == 0) {
-               debug("Skip region %x size %zx: no change\n",
-                     offset, len);
-               *skipped += len;
-               return NULL;
-       }
-       /* Erase the entire sector */
-       if (spi_flash_erase(flash, offset, flash->sector_size))
-               return "erase";
-       /* If it's a partial sector, copy the data into the temp-buffer */
-       if (len != flash->sector_size) {
-               memcpy(cmp_buf, buf, len);
-               ptr = cmp_buf;
-       }
-       /* Write one complete sector */
-       if (spi_flash_write(flash, offset, flash->sector_size, ptr))
-               return "write";
-
-       return NULL;
-}
-
-/**
- * Update an area of SPI flash by erasing and writing any blocks which need
- * to change. Existing blocks with the correct data are left unchanged.
- *
- * @param flash                flash context pointer
- * @param offset       flash offset to write
- * @param len          number of bytes to write
- * @param buf          buffer to write from
- * @return 0 if ok, 1 on error
- */
-static int spi_flash_update(struct spi_flash *flash, u32 offset,
-               size_t len, const char *buf)
-{
-       const char *err_oper = NULL;
-       char *cmp_buf;
-       const char *end = buf + len;
-       size_t todo;            /* number of bytes to do in this pass */
-       size_t skipped = 0;     /* statistics */
-       const ulong start_time = get_timer(0);
-       size_t scale = 1;
-       const char *start_buf = buf;
-       ulong delta;
-
-       if (end - buf >= 200)
-               scale = (end - buf) / 100;
-       cmp_buf = memalign(ARCH_DMA_MINALIGN, flash->sector_size);
-       if (cmp_buf) {
-               ulong last_update = get_timer(0);
-
-               for (; buf < end && !err_oper; buf += todo, offset += todo) {
-                       todo = min_t(size_t, end - buf, flash->sector_size);
-                       if (get_timer(last_update) > 100) {
-                               printf("   \rUpdating, %zu%% %lu B/s",
-                                      100 - (end - buf) / scale,
-                                       bytes_per_second(buf - start_buf,
-                                                        start_time));
-                               last_update = get_timer(0);
-                       }
-                       err_oper = spi_flash_update_block(flash, offset, todo,
-                                       buf, cmp_buf, &skipped);
-               }
-       } else {
-               err_oper = "malloc";
-       }
-       free(cmp_buf);
-       putc('\r');
-       if (err_oper) {
-               printf("SPI flash failed in %s step\n", err_oper);
-               return 1;
-       }
-
-       delta = get_timer(start_time);
-       printf("%zu bytes written, %zu bytes skipped", len - skipped,
-              skipped);
-       printf(" in %ld.%lds, speed %ld B/s\n",
-              delta / 1000, delta % 1000, bytes_per_second(len, start_time));
-
-       return 0;
-}
-
-static int do_spi_flash_read_write(int argc, char * const argv[])
-{
-       unsigned long addr;
-       void *buf;
-       char *endp;
-       int ret = 1;
-       int dev = 0;
-       loff_t offset, len, maxsize;
-
-       if (argc < 3)
-               return -1;
-
-       addr = simple_strtoul(argv[1], &endp, 16);
-       if (*argv[1] == 0 || *endp != 0)
-               return -1;
-
-       if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
-                            &maxsize, MTD_DEV_TYPE_NOR, flash->size))
-               return -1;
-
-       /* Consistency checking */
-       if (offset + len > flash->size) {
-               printf("ERROR: attempting %s past flash size (%#x)\n",
-                      argv[0], flash->size);
-               return 1;
-       }
-
-       buf = map_physmem(addr, len, MAP_WRBACK);
-       if (!buf) {
-               puts("Failed to map physical memory\n");
-               return 1;
-       }
-
-       if (strcmp(argv[0], "update") == 0) {
-               ret = spi_flash_update(flash, offset, len, buf);
-       } else if (strncmp(argv[0], "read", 4) == 0 ||
-                       strncmp(argv[0], "write", 5) == 0) {
-               int read;
-
-               read = strncmp(argv[0], "read", 4) == 0;
-               if (read)
-                       ret = spi_flash_read(flash, offset, len, buf);
-               else
-                       ret = spi_flash_write(flash, offset, len, buf);
-
-               printf("SF: %zu bytes @ %#x %s: ", (size_t)len, (u32)offset,
-                      read ? "Read" : "Written");
-               if (ret)
-                       printf("ERROR %d\n", ret);
-               else
-                       printf("OK\n");
-       }
-
-       unmap_physmem(buf, len);
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_spi_flash_erase(int argc, char * const argv[])
-{
-       int ret;
-       int dev = 0;
-       loff_t offset, len, maxsize;
-       ulong size;
-
-       if (argc < 3)
-               return -1;
-
-       if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
-                       MTD_DEV_TYPE_NOR, flash->size))
-               return -1;
-
-       ret = sf_parse_len_arg(argv[2], &size);
-       if (ret != 1)
-               return -1;
-
-       /* Consistency checking */
-       if (offset + size > flash->size) {
-               printf("ERROR: attempting %s past flash size (%#x)\n",
-                      argv[0], flash->size);
-               return 1;
-       }
-
-       ret = spi_flash_erase(flash, offset, size);
-       printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)size, (u32)offset,
-              ret ? "ERROR" : "OK");
-
-       return ret == 0 ? 0 : 1;
-}
-
-static int do_spi_protect(int argc, char * const argv[])
-{
-       int ret = 0;
-       loff_t start, len;
-       bool prot = false;
-
-       if (argc != 4)
-               return -1;
-
-       if (!str2off(argv[2], &start)) {
-               puts("start sector is not a valid number\n");
-               return 1;
-       }
-
-       if (!str2off(argv[3], &len)) {
-               puts("len is not a valid number\n");
-               return 1;
-       }
-
-       if (strcmp(argv[1], "lock") == 0)
-               prot = true;
-       else if (strcmp(argv[1], "unlock") == 0)
-               prot = false;
-       else
-               return -1;  /* Unknown parameter */
-
-       ret = spi_flash_protect(flash, start, len, prot);
-
-       return ret == 0 ? 0 : 1;
-}
-
-#ifdef CONFIG_CMD_SF_TEST
-enum {
-       STAGE_ERASE,
-       STAGE_CHECK,
-       STAGE_WRITE,
-       STAGE_READ,
-
-       STAGE_COUNT,
-};
-
-static char *stage_name[STAGE_COUNT] = {
-       "erase",
-       "check",
-       "write",
-       "read",
-};
-
-struct test_info {
-       int stage;
-       int bytes;
-       unsigned base_ms;
-       unsigned time_ms[STAGE_COUNT];
-};
-
-static void show_time(struct test_info *test, int stage)
-{
-       uint64_t speed; /* KiB/s */
-       int bps;        /* Bits per second */
-
-       speed = (long long)test->bytes * 1000;
-       if (test->time_ms[stage])
-               do_div(speed, test->time_ms[stage] * 1024);
-       bps = speed * 8;
-
-       printf("%d %s: %d ticks, %d KiB/s %d.%03d Mbps\n", stage,
-              stage_name[stage], test->time_ms[stage],
-              (int)speed, bps / 1000, bps % 1000);
-}
-
-static void spi_test_next_stage(struct test_info *test)
-{
-       test->time_ms[test->stage] = get_timer(test->base_ms);
-       show_time(test, test->stage);
-       test->base_ms = get_timer(0);
-       test->stage++;
-}
-
-/**
- * Run a test on the SPI flash
- *
- * @param flash                SPI flash to use
- * @param buf          Source buffer for data to write
- * @param len          Size of data to read/write
- * @param offset       Offset within flash to check
- * @param vbuf         Verification buffer
- * @return 0 if ok, -1 on error
- */
-static int spi_flash_test(struct spi_flash *flash, uint8_t *buf, ulong len,
-                          ulong offset, uint8_t *vbuf)
-{
-       struct test_info test;
-       int i;
-
-       printf("SPI flash test:\n");
-       memset(&test, '\0', sizeof(test));
-       test.base_ms = get_timer(0);
-       test.bytes = len;
-       if (spi_flash_erase(flash, offset, len)) {
-               printf("Erase failed\n");
-               return -1;
-       }
-       spi_test_next_stage(&test);
-
-       if (spi_flash_read(flash, offset, len, vbuf)) {
-               printf("Check read failed\n");
-               return -1;
-       }
-       for (i = 0; i < len; i++) {
-               if (vbuf[i] != 0xff) {
-                       printf("Check failed at %d\n", i);
-                       print_buffer(i, vbuf + i, 1,
-                                    min_t(uint, len - i, 0x40), 0);
-                       return -1;
-               }
-       }
-       spi_test_next_stage(&test);
-
-       if (spi_flash_write(flash, offset, len, buf)) {
-               printf("Write failed\n");
-               return -1;
-       }
-       memset(vbuf, '\0', len);
-       spi_test_next_stage(&test);
-
-       if (spi_flash_read(flash, offset, len, vbuf)) {
-               printf("Read failed\n");
-               return -1;
-       }
-       spi_test_next_stage(&test);
-
-       for (i = 0; i < len; i++) {
-               if (buf[i] != vbuf[i]) {
-                       printf("Verify failed at %d, good data:\n", i);
-                       print_buffer(i, buf + i, 1,
-                                    min_t(uint, len - i, 0x40), 0);
-                       printf("Bad data:\n");
-                       print_buffer(i, vbuf + i, 1,
-                                    min_t(uint, len - i, 0x40), 0);
-                       return -1;
-               }
-       }
-       printf("Test passed\n");
-       for (i = 0; i < STAGE_COUNT; i++)
-               show_time(&test, i);
-
-       return 0;
-}
-
-static int do_spi_flash_test(int argc, char * const argv[])
-{
-       unsigned long offset;
-       unsigned long len;
-       uint8_t *buf, *from;
-       char *endp;
-       uint8_t *vbuf;
-       int ret;
-
-       if (argc < 3)
-               return -1;
-       offset = simple_strtoul(argv[1], &endp, 16);
-       if (*argv[1] == 0 || *endp != 0)
-               return -1;
-       len = simple_strtoul(argv[2], &endp, 16);
-       if (*argv[2] == 0 || *endp != 0)
-               return -1;
-
-       vbuf = memalign(ARCH_DMA_MINALIGN, len);
-       if (!vbuf) {
-               printf("Cannot allocate memory (%lu bytes)\n", len);
-               return 1;
-       }
-       buf = memalign(ARCH_DMA_MINALIGN, len);
-       if (!buf) {
-               free(vbuf);
-               printf("Cannot allocate memory (%lu bytes)\n", len);
-               return 1;
-       }
-
-       from = map_sysmem(CONFIG_SYS_TEXT_BASE, 0);
-       memcpy(buf, from, len);
-       ret = spi_flash_test(flash, buf, len, offset, vbuf);
-       free(vbuf);
-       free(buf);
-       if (ret) {
-               printf("Test failed\n");
-               return 1;
-       }
-
-       return 0;
-}
-#endif /* CONFIG_CMD_SF_TEST */
-
-static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       const char *cmd;
-       int ret;
-
-       /* need at least two arguments */
-       if (argc < 2)
-               goto usage;
-
-       cmd = argv[1];
-       --argc;
-       ++argv;
-
-       if (strcmp(cmd, "probe") == 0) {
-               ret = do_spi_flash_probe(argc, argv);
-               goto done;
-       }
-
-       /* The remaining commands require a selected device */
-       if (!flash) {
-               puts("No SPI flash selected. Please run `sf probe'\n");
-               return 1;
-       }
-
-       if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0 ||
-           strcmp(cmd, "update") == 0)
-               ret = do_spi_flash_read_write(argc, argv);
-       else if (strcmp(cmd, "erase") == 0)
-               ret = do_spi_flash_erase(argc, argv);
-       else if (strcmp(cmd, "protect") == 0)
-               ret = do_spi_protect(argc, argv);
-#ifdef CONFIG_CMD_SF_TEST
-       else if (!strcmp(cmd, "test"))
-               ret = do_spi_flash_test(argc, argv);
-#endif
-       else
-               ret = -1;
-
-done:
-       if (ret != -1)
-               return ret;
-
-usage:
-       return CMD_RET_USAGE;
-}
-
-#ifdef CONFIG_CMD_SF_TEST
-#define SF_TEST_HELP "\nsf test offset len             " \
-               "- run a very basic destructive test"
-#else
-#define SF_TEST_HELP
-#endif
-
-U_BOOT_CMD(
-       sf,     5,      1,      do_spi_flash,
-       "SPI flash sub-system",
-       "probe [[bus:]cs] [hz] [mode]   - init flash device on given SPI bus\n"
-       "                                 and chip select\n"
-       "sf read addr offset|partition len      - read `len' bytes starting at\n"
-       "                                         `offset' or from start of mtd\n"
-       "                                         `partition'to memory at `addr'\n"
-       "sf write addr offset|partition len     - write `len' bytes from memory\n"
-       "                                         at `addr' to flash at `offset'\n"
-       "                                         or to start of mtd `partition'\n"
-       "sf erase offset|partition [+]len       - erase `len' bytes from `offset'\n"
-       "                                         or from start of mtd `partition'\n"
-       "                                        `+len' round up `len' to block size\n"
-       "sf update addr offset|partition len    - erase and write `len' bytes from memory\n"
-       "                                         at `addr' to flash at `offset'\n"
-       "                                         or to start of mtd `partition'\n"
-       "sf protect lock/unlock sector len      - protect/unprotect 'len' bytes starting\n"
-       "                                         at address 'sector'\n"
-       SF_TEST_HELP
-);
diff --git a/common/cmd_sha1sum.c b/common/cmd_sha1sum.c
deleted file mode 100644 (file)
index 783ea2e..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * (C) Copyright 2011
- * Joe Hershberger, National Instruments, joe.hershberger@ni.com
- *
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <hash.h>
-#include <u-boot/sha1.h>
-
-int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int flags = HASH_FLAG_ENV;
-       int ac;
-       char * const *av;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       av = argv + 1;
-       ac = argc - 1;
-#ifdef CONFIG_SHA1SUM_VERIFY
-       if (strcmp(*av, "-v") == 0) {
-               flags |= HASH_FLAG_VERIFY;
-               av++;
-               ac--;
-       }
-#endif
-
-       return hash_command("sha1", flags, cmdtp, flag, ac, av);
-}
-
-#ifdef CONFIG_SHA1SUM_VERIFY
-U_BOOT_CMD(
-       sha1sum,        5,      1,      do_sha1sum,
-       "compute SHA1 message digest",
-       "address count [[*]sum]\n"
-               "    - compute SHA1 message digest [save to sum]\n"
-       "sha1sum -v address count [*]sum\n"
-               "    - verify sha1sum of memory area"
-);
-#else
-U_BOOT_CMD(
-       sha1sum,        4,      1,      do_sha1sum,
-       "compute SHA1 message digest",
-       "address count [[*]sum]\n"
-               "    - compute SHA1 message digest [save to sum]"
-);
-#endif
diff --git a/common/cmd_softswitch.c b/common/cmd_softswitch.c
deleted file mode 100644 (file)
index f75d926..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * cmd_softswitch.c - set the softswitch for bf60x
- *
- * Copyright (c) 2012 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <common.h>
-#include <command.h>
-#include <asm/blackfin.h>
-#include <asm/soft_switch.h>
-
-int do_softswitch(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int switchaddr, value, pin, port;
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[2], "GPA") == 0)
-               port = IO_PORT_A;
-       else if (strcmp(argv[2], "GPB") == 0)
-               port = IO_PORT_B;
-       else
-               return CMD_RET_USAGE;
-
-       switchaddr = simple_strtoul(argv[1], NULL, 16);
-       pin = simple_strtoul(argv[3], NULL, 16);
-       value = simple_strtoul(argv[4], NULL, 16);
-
-       config_switch_bit(switchaddr, port, (1 << pin), IO_PORT_OUTPUT, value);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       softswitch_output, 5, 1, do_softswitch,
-       "switchaddr GPA/GPB pin_offset value",
-       ""
-);
diff --git a/common/cmd_sound.c b/common/cmd_sound.c
deleted file mode 100644 (file)
index f5dd8bc..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2012 Samsung Electronics
- * Rajeshwari Shinde <rajeshwari.s@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <fdtdec.h>
-#include <sound.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/* Initilaise sound subsystem */
-static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int ret;
-
-       ret = sound_init(gd->fdt_blob);
-       if (ret) {
-               printf("Initialise Audio driver failed\n");
-               return CMD_RET_FAILURE;
-       }
-
-       return 0;
-}
-
-/* play sound from buffer */
-static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       int ret = 0;
-       int msec = 1000;
-       int freq = 400;
-
-       if (argc > 1)
-               msec = simple_strtoul(argv[1], NULL, 10);
-       if (argc > 2)
-               freq = simple_strtoul(argv[2], NULL, 10);
-
-       ret = sound_play(msec, freq);
-       if (ret) {
-               printf("play failed");
-               return CMD_RET_FAILURE;
-       }
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_sound_sub[] = {
-       U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
-       U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
-};
-
-/* process sound command */
-static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       cmd_tbl_t *c;
-
-       if (argc < 1)
-               return CMD_RET_USAGE;
-
-       /* Strip off leading 'sound' command argument */
-       argc--;
-       argv++;
-
-       c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       sound, 4, 1, do_sound,
-       "sound sub-system",
-       "init - initialise the sound driver\n"
-       "sound play [len] [freq] - play a sound for len ms at freq hz\n"
-);
diff --git a/common/cmd_source.c b/common/cmd_source.c
deleted file mode 100644 (file)
index db7ab7e..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * (C) Copyright 2001
- * Kyle Harris, kharris@nexus-tech.net
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * The "source" command allows to define "script images", i. e. files
- * that contain command sequences that can be executed by the command
- * interpreter. It returns the exit status of the last command
- * executed from the script. This is very similar to running a shell
- * script in a UNIX shell, hence the name for the command.
- */
-
-/* #define DEBUG */
-
-#include <common.h>
-#include <command.h>
-#include <image.h>
-#include <malloc.h>
-#include <mapmem.h>
-#include <asm/byteorder.h>
-#include <asm/io.h>
-#if defined(CONFIG_8xx)
-#include <mpc8xx.h>
-#endif
-
-int
-source (ulong addr, const char *fit_uname)
-{
-       ulong           len;
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       const image_header_t *hdr;
-#endif
-       u32             *data;
-       int             verify;
-       void *buf;
-#if defined(CONFIG_FIT)
-       const void*     fit_hdr;
-       int             noffset;
-       const void      *fit_data;
-       size_t          fit_len;
-#endif
-
-       verify = getenv_yesno ("verify");
-
-       buf = map_sysmem(addr, 0);
-       switch (genimg_get_format(buf)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-               hdr = buf;
-
-               if (!image_check_magic (hdr)) {
-                       puts ("Bad magic number\n");
-                       return 1;
-               }
-
-               if (!image_check_hcrc (hdr)) {
-                       puts ("Bad header crc\n");
-                       return 1;
-               }
-
-               if (verify) {
-                       if (!image_check_dcrc (hdr)) {
-                               puts ("Bad data crc\n");
-                               return 1;
-                       }
-               }
-
-               if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
-                       puts ("Bad image type\n");
-                       return 1;
-               }
-
-               /* get length of script */
-               data = (u32 *)image_get_data (hdr);
-
-               if ((len = uimage_to_cpu (*data)) == 0) {
-                       puts ("Empty Script\n");
-                       return 1;
-               }
-
-               /*
-                * scripts are just multi-image files with one component, seek
-                * past the zero-terminated sequence of image lengths to get
-                * to the actual image data
-                */
-               while (*data++);
-               break;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               if (fit_uname == NULL) {
-                       puts ("No FIT subimage unit name\n");
-                       return 1;
-               }
-
-               fit_hdr = buf;
-               if (!fit_check_format (fit_hdr)) {
-                       puts ("Bad FIT image format\n");
-                       return 1;
-               }
-
-               /* get script component image node offset */
-               noffset = fit_image_get_node (fit_hdr, fit_uname);
-               if (noffset < 0) {
-                       printf ("Can't find '%s' FIT subimage\n", fit_uname);
-                       return 1;
-               }
-
-               if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) {
-                       puts ("Not a image image\n");
-                       return 1;
-               }
-
-               /* verify integrity */
-               if (verify) {
-                       if (!fit_image_verify(fit_hdr, noffset)) {
-                               puts ("Bad Data Hash\n");
-                               return 1;
-                       }
-               }
-
-               /* get script subimage data address and length */
-               if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) {
-                       puts ("Could not find script subimage data\n");
-                       return 1;
-               }
-
-               data = (u32 *)fit_data;
-               len = (ulong)fit_len;
-               break;
-#endif
-       default:
-               puts ("Wrong image format for \"source\" command\n");
-               return 1;
-       }
-
-       debug ("** Script length: %ld\n", len);
-       return run_command_list((char *)data, len, 0);
-}
-
-/**************************************************/
-#if defined(CONFIG_CMD_SOURCE)
-static int do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr;
-       int rcode;
-       const char *fit_uname = NULL;
-
-       /* Find script image */
-       if (argc < 2) {
-               addr = CONFIG_SYS_LOAD_ADDR;
-               debug ("*  source: default load address = 0x%08lx\n", addr);
-#if defined(CONFIG_FIT)
-       } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) {
-               debug ("*  source: subimage '%s' from FIT image at 0x%08lx\n",
-                               fit_uname, addr);
-#endif
-       } else {
-               addr = simple_strtoul(argv[1], NULL, 16);
-               debug ("*  source: cmdline image address = 0x%08lx\n", addr);
-       }
-
-       printf ("## Executing script at %08lx\n", addr);
-       rcode = source (addr, fit_uname);
-       return rcode;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char source_help_text[] =
-       "[addr]\n"
-       "\t- run script starting at addr\n"
-       "\t- A valid image header must be present"
-#if defined(CONFIG_FIT)
-       "\n"
-       "For FIT format uImage addr must include subimage\n"
-       "unit name in the form of addr:<subimg_uname>"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       source, 2, 0,   do_source,
-       "run script from memory", source_help_text
-);
-#endif
diff --git a/common/cmd_spi.c b/common/cmd_spi.c
deleted file mode 100644 (file)
index 64c3ffc..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * (C) Copyright 2002
- * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * SPI Read/Write Utilities
- */
-
-#include <common.h>
-#include <command.h>
-#include <dm.h>
-#include <errno.h>
-#include <spi.h>
-
-/*-----------------------------------------------------------------------
- * Definitions
- */
-
-#ifndef MAX_SPI_BYTES
-#   define MAX_SPI_BYTES 32    /* Maximum number of bytes we can handle */
-#endif
-
-#ifndef CONFIG_DEFAULT_SPI_BUS
-#   define CONFIG_DEFAULT_SPI_BUS      0
-#endif
-#ifndef CONFIG_DEFAULT_SPI_MODE
-#   define CONFIG_DEFAULT_SPI_MODE     SPI_MODE_0
-#endif
-
-/*
- * Values from last command.
- */
-static unsigned int    bus;
-static unsigned int    cs;
-static unsigned int    mode;
-static int             bitlen;
-static uchar           dout[MAX_SPI_BYTES];
-static uchar           din[MAX_SPI_BYTES];
-
-static int do_spi_xfer(int bus, int cs)
-{
-       struct spi_slave *slave;
-       int ret = 0;
-
-#ifdef CONFIG_DM_SPI
-       char name[30], *str;
-       struct udevice *dev;
-
-       snprintf(name, sizeof(name), "generic_%d:%d", bus, cs);
-       str = strdup(name);
-       ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv",
-                                str, &dev, &slave);
-       if (ret)
-               return ret;
-#else
-       slave = spi_setup_slave(bus, cs, 1000000, mode);
-       if (!slave) {
-               printf("Invalid device %d:%d\n", bus, cs);
-               return -EINVAL;
-       }
-#endif
-
-       ret = spi_claim_bus(slave);
-       if (ret)
-               goto done;
-       ret = spi_xfer(slave, bitlen, dout, din,
-                      SPI_XFER_BEGIN | SPI_XFER_END);
-#ifndef CONFIG_DM_SPI
-       /* We don't get an error code in this case */
-       if (ret)
-               ret = -EIO;
-#endif
-       if (ret) {
-               printf("Error %d during SPI transaction\n", ret);
-       } else {
-               int j;
-
-               for (j = 0; j < ((bitlen + 7) / 8); j++)
-                       printf("%02X", din[j]);
-               printf("\n");
-       }
-done:
-       spi_release_bus(slave);
-#ifndef CONFIG_DM_SPI
-       spi_free_slave(slave);
-#endif
-
-       return ret;
-}
-
-/*
- * SPI read/write
- *
- * Syntax:
- *   spi {dev} {num_bits} {dout}
- *     {dev} is the device number for controlling chip select (see TBD)
- *     {num_bits} is the number of bits to send & receive (base 10)
- *     {dout} is a hexadecimal string of data to send
- * The command prints out the hexadecimal string received via SPI.
- */
-
-int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char  *cp = 0;
-       uchar tmp;
-       int   j;
-
-       /*
-        * We use the last specified parameters, unless new ones are
-        * entered.
-        */
-
-       if ((flag & CMD_FLAG_REPEAT) == 0)
-       {
-               if (argc >= 2) {
-                       mode = CONFIG_DEFAULT_SPI_MODE;
-                       bus = simple_strtoul(argv[1], &cp, 10);
-                       if (*cp == ':') {
-                               cs = simple_strtoul(cp+1, &cp, 10);
-                       } else {
-                               cs = bus;
-                               bus = CONFIG_DEFAULT_SPI_BUS;
-                       }
-                       if (*cp == '.')
-                               mode = simple_strtoul(cp+1, NULL, 10);
-               }
-               if (argc >= 3)
-                       bitlen = simple_strtoul(argv[2], NULL, 10);
-               if (argc >= 4) {
-                       cp = argv[3];
-                       for(j = 0; *cp; j++, cp++) {
-                               tmp = *cp - '0';
-                               if(tmp > 9)
-                                       tmp -= ('A' - '0') - 10;
-                               if(tmp > 15)
-                                       tmp -= ('a' - 'A');
-                               if(tmp > 15) {
-                                       printf("Hex conversion error on %c\n", *cp);
-                                       return 1;
-                               }
-                               if((j % 2) == 0)
-                                       dout[j / 2] = (tmp << 4);
-                               else
-                                       dout[j / 2] |= tmp;
-                       }
-               }
-       }
-
-       if ((bitlen < 0) || (bitlen >  (MAX_SPI_BYTES * 8))) {
-               printf("Invalid bitlen %d\n", bitlen);
-               return 1;
-       }
-
-       if (do_spi_xfer(bus, cs))
-               return 1;
-
-       return 0;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
-       sspi,   5,      1,      do_spi,
-       "SPI utility command",
-       "[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
-       "<bus>     - Identifies the SPI bus\n"
-       "<cs>      - Identifies the chip select\n"
-       "<mode>    - Identifies the SPI mode to use\n"
-       "<bit_len> - Number of bits to send (base 10)\n"
-       "<dout>    - Hexadecimal string that gets sent"
-);
diff --git a/common/cmd_spibootldr.c b/common/cmd_spibootldr.c
deleted file mode 100644 (file)
index ca76dde..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * U-boot - spibootldr.c
- *
- * Copyright (c) 2005-2008 Analog Devices Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <common.h>
-#include <command.h>
-
-#include <asm/blackfin.h>
-#include <asm/mach-common/bits/bootrom.h>
-
-int do_spibootldr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       s32 addr;
-
-       /* Get the address */
-       if (argc < 2)
-               addr = 0;
-       else
-               addr = simple_strtoul(argv[1], NULL, 16);
-
-       printf("## Booting ldr image at SPI offset 0x%x ...\n", addr);
-
-       return bfrom_SpiBoot(addr, BFLAG_PERIPHERAL | 4, 0, NULL);
-}
-
-U_BOOT_CMD(
-       spibootldr, 2, 0, do_spibootldr,
-       "boot ldr image from spi",
-       "[offset]\n"
-       "    - boot ldr image stored at offset into spi\n");
diff --git a/common/cmd_spl.c b/common/cmd_spl.c
deleted file mode 100644 (file)
index 057764a..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2011
- * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <cmd_spl.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static const char **subcmd_list[] = {
-
-       [SPL_EXPORT_FDT] = (const char * []) {
-#ifdef CONFIG_OF_LIBFDT
-               "start",
-               "loados",
-       #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
-               "ramdisk",
-       #endif
-               "fdt",
-               "cmdline",
-               "bdt",
-               "prep",
-#endif
-               NULL,
-       },
-       [SPL_EXPORT_ATAGS] = (const char * []) {
-#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
-       defined(CONFIG_CMDLINE_TAG) || \
-       defined(CONFIG_INITRD_TAG) || \
-       defined(CONFIG_SERIAL_TAG) || \
-       defined(CONFIG_REVISION_TAG)
-               "start",
-               "loados",
-#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
-               "ramdisk",
-#endif
-               "cmdline",
-               "bdt",
-               "prep",
-#endif
-               NULL,
-       },
-       NULL
-};
-
-/* Calls bootm with the parameters given */
-static int call_bootm(int argc, char * const argv[], const char *subcommand[])
-{
-       char *bootm_argv[5];
-
-       int i = 0;
-       int ret = 0;
-       int j;
-
-       /* create paramter array */
-       bootm_argv[0] = "do_bootm";
-       switch (argc) {
-       case 3:
-               bootm_argv[4] = argv[2]; /* fdt addr */
-       case 2:
-               bootm_argv[3] = argv[1]; /* initrd addr */
-       case 1:
-               bootm_argv[2] = argv[0]; /* kernel addr */
-       }
-
-
-       /*
-        * - do the work -
-        * exec subcommands of do_bootm to init the images
-        * data structure
-        */
-       while (subcommand[i] != NULL) {
-               bootm_argv[1] = (char *)subcommand[i];
-               debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
-               for (j = 0; j < argc; j++)
-                       debug("%s ", bootm_argv[j + 2]);
-               debug("\n");
-
-               ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
-                       bootm_argv);
-               debug("Subcommand retcode: %d\n", ret);
-               i++;
-       }
-
-       if (ret) {
-               printf("ERROR prep subcommand failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_spl_export_sub[] = {
-       U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
-       U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
-};
-
-static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const cmd_tbl_t *c;
-
-       if (argc < 2) /* no subcommand */
-               return cmd_usage(cmdtp);
-
-       c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
-               ARRAY_SIZE(cmd_spl_export_sub));
-       if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
-               argc -= 2;
-               argv += 2;
-               if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
-                       return -1;
-               switch ((int)c->cmd) {
-#ifdef CONFIG_OF_LIBFDT
-               case SPL_EXPORT_FDT:
-                       printf("Argument image is now in RAM: 0x%p\n",
-                               (void *)images.ft_addr);
-                       break;
-#endif
-               case SPL_EXPORT_ATAGS:
-                       printf("Argument image is now in RAM at: 0x%p\n",
-                               (void *)gd->bd->bi_boot_params);
-                       break;
-               }
-       } else {
-               /* Unrecognized command */
-               return cmd_usage(cmdtp);
-       }
-
-       return 0;
-}
-
-static cmd_tbl_t cmd_spl_sub[] = {
-       U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
-};
-
-static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const cmd_tbl_t *c;
-       int cmd;
-
-       if (argc < 2) /* no subcommand */
-               return cmd_usage(cmdtp);
-
-       c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
-       if (c) {
-               cmd = (int)c->cmd;
-               switch (cmd) {
-               case SPL_EXPORT:
-                       argc--;
-                       argv++;
-                       if (spl_export(cmdtp, flag, argc, argv))
-                               printf("Subcommand failed\n");
-                       break;
-               default:
-                       /* unrecognized command */
-                       return cmd_usage(cmdtp);
-               }
-       } else {
-               /* Unrecognized command */
-               return cmd_usage(cmdtp);
-       }
-       return 0;
-}
-
-U_BOOT_CMD(
-       spl, 6 , 1, do_spl, "SPL configuration",
-       "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
-       "\timg\t\t\"atags\" or \"fdt\"\n"
-       "\tkernel_addr\taddress where a kernel image is stored.\n"
-       "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
-       "\tinitrd_addr\taddress of initial ramdisk\n"
-       "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
-       "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
-       );
diff --git a/common/cmd_strings.c b/common/cmd_strings.c
deleted file mode 100644 (file)
index 41b1665..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * cmd_strings.c - just like `strings` command
- *
- * Copyright (c) 2008 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <config.h>
-#include <common.h>
-#include <command.h>
-
-static char *start_addr, *last_addr;
-
-int do_strings(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc == 1)
-               return CMD_RET_USAGE;
-
-       if ((flag & CMD_FLAG_REPEAT) == 0) {
-               start_addr = (char *)simple_strtoul(argv[1], NULL, 16);
-               if (argc > 2)
-                       last_addr = (char *)simple_strtoul(argv[2], NULL, 16);
-               else
-                       last_addr = (char *)-1;
-       }
-
-       char *addr = start_addr;
-       do {
-               puts(addr);
-               puts("\n");
-               addr += strlen(addr) + 1;
-       } while (addr[0] && addr < last_addr);
-
-       last_addr = addr + (last_addr - start_addr);
-       start_addr = addr;
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       strings, 3, 1, do_strings,
-       "display strings",
-       "<addr> [byte count]\n"
-       "    - display strings at <addr> for at least [byte count] or first double NUL"
-);
diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c
deleted file mode 100644 (file)
index 4b9c0b3..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * (C) Copyright 2007 OpenMoko, Inc.
- * Written by Harald Welte <laforge@openmoko.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-/*
- * Boot support
- */
-#include <common.h>
-#include <command.h>
-#include <stdio_dev.h>
-#include <serial.h>
-
-int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
-{
-       int last_tilde = 0;
-       struct stdio_dev *dev = NULL;
-
-       if (argc < 1)
-               return -1;
-
-       /* Scan for selected output/input device */
-       dev = stdio_get_by_name(argv[1]);
-       if (!dev)
-               return -1;
-
-       serial_reinit_all();
-       printf("Entering terminal mode for port %s\n", dev->name);
-       puts("Use '~.' to leave the terminal and get back to u-boot\n");
-
-       while (1) {
-               int c;
-
-               /* read from console and display on serial port */
-               if (stdio_devices[0]->tstc()) {
-                       c = stdio_devices[0]->getc();
-                       if (last_tilde == 1) {
-                               if (c == '.') {
-                                       putc(c);
-                                       putc('\n');
-                                       break;
-                               } else {
-                                       last_tilde = 0;
-                                       /* write the delayed tilde */
-                                       dev->putc('~');
-                                       /* fall-through to print current
-                                        * character */
-                               }
-                       }
-                       if (c == '~') {
-                               last_tilde = 1;
-                               puts("[u-boot]");
-                               putc(c);
-                       }
-                       dev->putc(c);
-               }
-
-               /* read from serial port and display on console */
-               if (dev->tstc()) {
-                       c = dev->getc();
-                       putc(c);
-               }
-       }
-       return 0;
-}
-
-
-/***************************************************/
-
-U_BOOT_CMD(
-       terminal,       3,      1,      do_terminal,
-       "start terminal emulator",
-       ""
-);
diff --git a/common/cmd_test.c b/common/cmd_test.c
deleted file mode 100644 (file)
index 7285f75..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <fs.h>
-
-#define OP_INVALID     0
-#define OP_NOT         1
-#define OP_OR          2
-#define OP_AND         3
-#define OP_STR_EMPTY   4
-#define OP_STR_NEMPTY  5
-#define OP_STR_EQ      6
-#define OP_STR_NEQ     7
-#define OP_STR_LT      8
-#define OP_STR_GT      9
-#define OP_INT_EQ      10
-#define OP_INT_NEQ     11
-#define OP_INT_LT      12
-#define OP_INT_LE      13
-#define OP_INT_GT      14
-#define OP_INT_GE      15
-#define OP_FILE_EXISTS 16
-
-const struct {
-       int arg;
-       const char *str;
-       int op;
-       int adv;
-} op_adv[] = {
-       {1, "=", OP_STR_EQ, 3},
-       {1, "!=", OP_STR_NEQ, 3},
-       {1, "<", OP_STR_LT, 3},
-       {1, ">", OP_STR_GT, 3},
-       {1, "-eq", OP_INT_EQ, 3},
-       {1, "-ne", OP_INT_NEQ, 3},
-       {1, "-lt", OP_INT_LT, 3},
-       {1, "-le", OP_INT_LE, 3},
-       {1, "-gt", OP_INT_GT, 3},
-       {1, "-ge", OP_INT_GE, 3},
-       {0, "!", OP_NOT, 1},
-       {0, "-o", OP_OR, 1},
-       {0, "-a", OP_AND, 1},
-       {0, "-z", OP_STR_EMPTY, 2},
-       {0, "-n", OP_STR_NEMPTY, 2},
-       {0, "-e", OP_FILE_EXISTS, 4},
-};
-
-static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char * const *ap;
-       int i, op, left, adv, expr, last_expr, last_unop, last_binop;
-
-       /* args? */
-       if (argc < 3)
-               return 1;
-
-#ifdef DEBUG
-       {
-               debug("test(%d):", argc);
-               left = 1;
-               while (argv[left])
-                       debug(" '%s'", argv[left++]);
-       }
-#endif
-
-       left = argc - 1;
-       ap = argv + 1;
-       expr = 0;
-       last_unop = OP_INVALID;
-       last_binop = OP_INVALID;
-       last_expr = -1;
-       while (left > 0) {
-               for (i = 0; i < ARRAY_SIZE(op_adv); i++) {
-                       if (left <= op_adv[i].arg)
-                               continue;
-                       if (!strcmp(ap[op_adv[i].arg], op_adv[i].str)) {
-                               op = op_adv[i].op;
-                               adv = op_adv[i].adv;
-                               break;
-                       }
-               }
-               if (i == ARRAY_SIZE(op_adv)) {
-                       expr = 1;
-                       break;
-               }
-               if (left < adv) {
-                       expr = 1;
-                       break;
-               }
-
-               switch (op) {
-               case OP_STR_EMPTY:
-                       expr = strlen(ap[1]) == 0 ? 1 : 0;
-                       break;
-               case OP_STR_NEMPTY:
-                       expr = strlen(ap[1]) == 0 ? 0 : 1;
-                       break;
-               case OP_STR_EQ:
-                       expr = strcmp(ap[0], ap[2]) == 0;
-                       break;
-               case OP_STR_NEQ:
-                       expr = strcmp(ap[0], ap[2]) != 0;
-                       break;
-               case OP_STR_LT:
-                       expr = strcmp(ap[0], ap[2]) < 0;
-                       break;
-               case OP_STR_GT:
-                       expr = strcmp(ap[0], ap[2]) > 0;
-                       break;
-               case OP_INT_EQ:
-                       expr = simple_strtol(ap[0], NULL, 10) ==
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_INT_NEQ:
-                       expr = simple_strtol(ap[0], NULL, 10) !=
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_INT_LT:
-                       expr = simple_strtol(ap[0], NULL, 10) <
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_INT_LE:
-                       expr = simple_strtol(ap[0], NULL, 10) <=
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_INT_GT:
-                       expr = simple_strtol(ap[0], NULL, 10) >
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_INT_GE:
-                       expr = simple_strtol(ap[0], NULL, 10) >=
-                                       simple_strtol(ap[2], NULL, 10);
-                       break;
-               case OP_FILE_EXISTS:
-                       expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY);
-                       break;
-               }
-
-               switch (op) {
-               case OP_OR:
-                       last_expr = expr;
-                       last_binop = OP_OR;
-                       break;
-               case OP_AND:
-                       last_expr = expr;
-                       last_binop = OP_AND;
-                       break;
-               case OP_NOT:
-                       if (last_unop == OP_NOT)
-                               last_unop = OP_INVALID;
-                       else
-                               last_unop = OP_NOT;
-                       break;
-               default:
-                       if (last_unop == OP_NOT) {
-                               expr = !expr;
-                               last_unop = OP_INVALID;
-                       }
-
-                       if (last_binop == OP_OR)
-                               expr = last_expr || expr;
-                       else if (last_binop == OP_AND)
-                               expr = last_expr && expr;
-                       last_binop = OP_INVALID;
-
-                       break;
-               }
-
-               ap += adv; left -= adv;
-       }
-
-       expr = !expr;
-
-       debug (": returns %d\n", expr);
-
-       return expr;
-}
-
-#undef true
-#undef false
-
-U_BOOT_CMD(
-       test,   CONFIG_SYS_MAXARGS,     1,      do_test,
-       "minimal test like /bin/sh",
-       "[args..]"
-);
-
-static int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return 1;
-}
-
-U_BOOT_CMD(
-       false,  CONFIG_SYS_MAXARGS,     1,      do_false,
-       "do nothing, unsuccessfully",
-       NULL
-);
-
-static int do_true(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return 0;
-}
-
-U_BOOT_CMD(
-       true,   CONFIG_SYS_MAXARGS,     1,      do_true,
-       "do nothing, successfully",
-       NULL
-);
diff --git a/common/cmd_thordown.c b/common/cmd_thordown.c
deleted file mode 100644 (file)
index 436b7f5..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
- *
- * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
- * All rights reserved.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <thor.h>
-#include <dfu.h>
-#include <g_dnl.h>
-#include <usb.h>
-
-int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       char *usb_controller = argv[1];
-       char *interface = argv[2];
-       char *devstring = argv[3];
-
-       int ret;
-
-       puts("TIZEN \"THOR\" Downloader\n");
-
-       ret = dfu_init_env_entities(interface, devstring);
-       if (ret)
-               goto done;
-
-       int controller_index = simple_strtoul(usb_controller, NULL, 0);
-       ret = board_usb_init(controller_index, USB_INIT_DEVICE);
-       if (ret) {
-               error("USB init failed: %d", ret);
-               ret = CMD_RET_FAILURE;
-               goto exit;
-       }
-
-       g_dnl_register("usb_dnl_thor");
-
-       ret = thor_init();
-       if (ret) {
-               error("THOR DOWNLOAD failed: %d", ret);
-               ret = CMD_RET_FAILURE;
-               goto exit;
-       }
-
-       ret = thor_handle();
-       if (ret) {
-               error("THOR failed: %d", ret);
-               ret = CMD_RET_FAILURE;
-               goto exit;
-       }
-
-exit:
-       g_dnl_unregister();
-       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
-done:
-       dfu_free_entities();
-
-       return ret;
-}
-
-U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
-          "TIZEN \"THOR\" downloader",
-          "<USB_controller> <interface> <dev>\n"
-          "  - device software upgrade via LTHOR TIZEN dowload\n"
-          "    program via <USB_controller> on device <dev>,\n"
-          "    attached to interface <interface>\n"
-);
diff --git a/common/cmd_time.c b/common/cmd_time.c
deleted file mode 100644 (file)
index de57e3b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static void report_time(ulong cycles)
-{
-       ulong minutes, seconds, milliseconds;
-       ulong total_seconds, remainder;
-
-       total_seconds = cycles / CONFIG_SYS_HZ;
-       remainder = cycles % CONFIG_SYS_HZ;
-       minutes = total_seconds / 60;
-       seconds = total_seconds % 60;
-       /* approximate millisecond value */
-       milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
-
-       printf("\ntime:");
-       if (minutes)
-               printf(" %lu minutes,", minutes);
-       printf(" %lu.%03lu seconds\n", seconds, milliseconds);
-}
-
-static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong cycles = 0;
-       int retval = 0;
-       int repeatable;
-
-       if (argc == 1)
-               return CMD_RET_USAGE;
-
-       retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
-       report_time(cycles);
-
-       return retval;
-}
-
-U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
-               "run commands and summarize execution time",
-               "command [args...]\n");
diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
deleted file mode 100644 (file)
index add6bfb..0000000
+++ /dev/null
@@ -1,802 +0,0 @@
-/*
- * Copyright (c) 2013 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <dm.h>
-#include <malloc.h>
-#include <tpm.h>
-#include <asm/unaligned.h>
-#include <linux/string.h>
-
-/* Useful constants */
-enum {
-       DIGEST_LENGTH           = 20,
-       /* max lengths, valid for RSA keys <= 2048 bits */
-       TPM_PUBKEY_MAX_LENGTH   = 288,
-};
-
-/**
- * Print a byte string in hexdecimal format, 16-bytes per line.
- *
- * @param data         byte string to be printed
- * @param count                number of bytes to be printed
- */
-static void print_byte_string(uint8_t *data, size_t count)
-{
-       int i, print_newline = 0;
-
-       for (i = 0; i < count; i++) {
-               printf(" %02x", data[i]);
-               print_newline = (i % 16 == 15);
-               if (print_newline)
-                       putc('\n');
-       }
-       /* Avoid duplicated newline at the end */
-       if (!print_newline)
-               putc('\n');
-}
-
-/**
- * Convert a text string of hexdecimal values into a byte string.
- *
- * @param bytes                text string of hexdecimal values with no space
- *                     between them
- * @param data         output buffer for byte string.  The caller has to make
- *                     sure it is large enough for storing the output.  If
- *                     NULL is passed, a large enough buffer will be allocated,
- *                     and the caller must free it.
- * @param count_ptr    output variable for the length of byte string
- * @return pointer to output buffer
- */
-static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
-{
-       char byte[3];
-       size_t count, length;
-       int i;
-
-       if (!bytes)
-               return NULL;
-       length = strlen(bytes);
-       count = length / 2;
-
-       if (!data)
-               data = malloc(count);
-       if (!data)
-               return NULL;
-
-       byte[2] = '\0';
-       for (i = 0; i < length; i += 2) {
-               byte[0] = bytes[i];
-               byte[1] = bytes[i + 1];
-               data[i / 2] = (uint8_t)simple_strtoul(byte, NULL, 16);
-       }
-
-       if (count_ptr)
-               *count_ptr = count;
-
-       return data;
-}
-
-/**
- * report_return_code() - Report any error and return failure or success
- *
- * @param return_code  TPM command return code
- * @return value of enum command_ret_t
- */
-static int report_return_code(int return_code)
-{
-       if (return_code) {
-               printf("Error: %d\n", return_code);
-               return CMD_RET_FAILURE;
-       } else {
-               return CMD_RET_SUCCESS;
-       }
-}
-
-/**
- * Return number of values defined by a type string.
- *
- * @param type_str     type string
- * @return number of values of type string
- */
-static int type_string_get_num_values(const char *type_str)
-{
-       return strlen(type_str);
-}
-
-/**
- * Return total size of values defined by a type string.
- *
- * @param type_str     type string
- * @return total size of values of type string, or 0 if type string
- *  contains illegal type character.
- */
-static size_t type_string_get_space_size(const char *type_str)
-{
-       size_t size;
-
-       for (size = 0; *type_str; type_str++) {
-               switch (*type_str) {
-               case 'b':
-                       size += 1;
-                       break;
-               case 'w':
-                       size += 2;
-                       break;
-               case 'd':
-                       size += 4;
-                       break;
-               default:
-                       return 0;
-               }
-       }
-
-       return size;
-}
-
-/**
- * Allocate a buffer large enough to hold values defined by a type
- * string.  The caller has to free the buffer.
- *
- * @param type_str     type string
- * @param count                pointer for storing size of buffer
- * @return pointer to buffer or NULL on error
- */
-static void *type_string_alloc(const char *type_str, uint32_t *count)
-{
-       void *data;
-       size_t size;
-
-       size = type_string_get_space_size(type_str);
-       if (!size)
-               return NULL;
-       data = malloc(size);
-       if (data)
-               *count = size;
-
-       return data;
-}
-
-/**
- * Pack values defined by a type string into a buffer.  The buffer must have
- * large enough space.
- *
- * @param type_str     type string
- * @param values       text strings of values to be packed
- * @param data         output buffer of values
- * @return 0 on success, non-0 on error
- */
-static int type_string_pack(const char *type_str, char * const values[],
-               uint8_t *data)
-{
-       size_t offset;
-       uint32_t value;
-
-       for (offset = 0; *type_str; type_str++, values++) {
-               value = simple_strtoul(values[0], NULL, 0);
-               switch (*type_str) {
-               case 'b':
-                       data[offset] = value;
-                       offset += 1;
-                       break;
-               case 'w':
-                       put_unaligned_be16(value, data + offset);
-                       offset += 2;
-                       break;
-               case 'd':
-                       put_unaligned_be32(value, data + offset);
-                       offset += 4;
-                       break;
-               default:
-                       return -1;
-               }
-       }
-
-       return 0;
-}
-
-/**
- * Read values defined by a type string from a buffer, and write these values
- * to environment variables.
- *
- * @param type_str     type string
- * @param data         input buffer of values
- * @param vars         names of environment variables
- * @return 0 on success, non-0 on error
- */
-static int type_string_write_vars(const char *type_str, uint8_t *data,
-               char * const vars[])
-{
-       size_t offset;
-       uint32_t value;
-
-       for (offset = 0; *type_str; type_str++, vars++) {
-               switch (*type_str) {
-               case 'b':
-                       value = data[offset];
-                       offset += 1;
-                       break;
-               case 'w':
-                       value = get_unaligned_be16(data + offset);
-                       offset += 2;
-                       break;
-               case 'd':
-                       value = get_unaligned_be32(data + offset);
-                       offset += 4;
-                       break;
-               default:
-                       return -1;
-               }
-               if (setenv_ulong(*vars, value))
-                       return -1;
-       }
-
-       return 0;
-}
-
-static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       enum tpm_startup_type mode;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-       if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
-               mode = TPM_ST_CLEAR;
-       } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
-               mode = TPM_ST_STATE;
-       } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
-               mode = TPM_ST_DEACTIVATED;
-       } else {
-               printf("Couldn't recognize mode string: %s\n", argv[1]);
-               return CMD_RET_FAILURE;
-       }
-
-       return report_return_code(tpm_startup(mode));
-}
-
-static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, perm, size;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[1], NULL, 0);
-       perm = simple_strtoul(argv[2], NULL, 0);
-       size = simple_strtoul(argv[3], NULL, 0);
-
-       return report_return_code(tpm_nv_define_space(index, perm, size));
-}
-
-static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, count, rc;
-       void *data;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[1], NULL, 0);
-       data = (void *)simple_strtoul(argv[2], NULL, 0);
-       count = simple_strtoul(argv[3], NULL, 0);
-
-       rc = tpm_nv_read_value(index, data, count);
-       if (!rc) {
-               puts("area content:\n");
-               print_byte_string(data, count);
-       }
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, rc;
-       size_t count;
-       void *data;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[1], NULL, 0);
-       data = parse_byte_string(argv[2], NULL, &count);
-       if (!data) {
-               printf("Couldn't parse byte string %s\n", argv[2]);
-               return CMD_RET_FAILURE;
-       }
-
-       rc = tpm_nv_write_value(index, data, count);
-       free(data);
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, rc;
-       uint8_t in_digest[20], out_digest[20];
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[1], NULL, 0);
-       if (!parse_byte_string(argv[2], in_digest, NULL)) {
-               printf("Couldn't parse byte string %s\n", argv[2]);
-               return CMD_RET_FAILURE;
-       }
-
-       rc = tpm_extend(index, in_digest, out_digest);
-       if (!rc) {
-               puts("PCR value after execution of the command:\n");
-               print_byte_string(out_digest, sizeof(out_digest));
-       }
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, count, rc;
-       void *data;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[1], NULL, 0);
-       data = (void *)simple_strtoul(argv[2], NULL, 0);
-       count = simple_strtoul(argv[3], NULL, 0);
-
-       rc = tpm_pcr_read(index, data, count);
-       if (!rc) {
-               puts("Named PCR content:\n");
-               print_byte_string(data, count);
-       }
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint16_t presence;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-       presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
-
-       return report_return_code(tpm_tsc_physical_presence(presence));
-}
-
-static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t count, rc;
-       void *data;
-
-       if (argc != 3)
-               return CMD_RET_USAGE;
-       data = (void *)simple_strtoul(argv[1], NULL, 0);
-       count = simple_strtoul(argv[2], NULL, 0);
-
-       rc = tpm_read_pubek(data, count);
-       if (!rc) {
-               puts("pubek value:\n");
-               print_byte_string(data, count);
-       }
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint8_t state;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-       state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
-
-       return report_return_code(tpm_physical_set_deactivated(state));
-}
-
-static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t cap_area, sub_cap, rc;
-       void *cap;
-       size_t count;
-
-       if (argc != 5)
-               return CMD_RET_USAGE;
-       cap_area = simple_strtoul(argv[1], NULL, 0);
-       sub_cap = simple_strtoul(argv[2], NULL, 0);
-       cap = (void *)simple_strtoul(argv[3], NULL, 0);
-       count = simple_strtoul(argv[4], NULL, 0);
-
-       rc = tpm_get_capability(cap_area, sub_cap, cap, count);
-       if (!rc) {
-               puts("capability information:\n");
-               print_byte_string(cap, count);
-       }
-
-       return report_return_code(rc);
-}
-
-#define TPM_COMMAND_NO_ARG(cmd)                                \
-static int do_##cmd(cmd_tbl_t *cmdtp, int flag,                \
-               int argc, char * const argv[])          \
-{                                                      \
-       if (argc != 1)                                  \
-               return CMD_RET_USAGE;                   \
-       return report_return_code(cmd());               \
-}
-
-TPM_COMMAND_NO_ARG(tpm_init)
-TPM_COMMAND_NO_ARG(tpm_self_test_full)
-TPM_COMMAND_NO_ARG(tpm_continue_self_test)
-TPM_COMMAND_NO_ARG(tpm_force_clear)
-TPM_COMMAND_NO_ARG(tpm_physical_enable)
-TPM_COMMAND_NO_ARG(tpm_physical_disable)
-
-static int get_tpm(struct udevice **devp)
-{
-       int rc;
-
-       rc = uclass_first_device(UCLASS_TPM, devp);
-       if (rc) {
-               printf("Could not find TPM (ret=%d)\n", rc);
-               return CMD_RET_FAILURE;
-       }
-
-       return 0;
-}
-
-static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char *const argv[])
-{
-       struct udevice *dev;
-       char buf[80];
-       int rc;
-
-       rc = get_tpm(&dev);
-       if (rc)
-               return rc;
-       rc = tpm_get_desc(dev, buf, sizeof(buf));
-       if (rc < 0) {
-               printf("Couldn't get TPM info (%d)\n", rc);
-               return CMD_RET_FAILURE;
-       }
-       printf("%s\n", buf);
-
-       return 0;
-}
-
-static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       struct udevice *dev;
-       void *command;
-       uint8_t response[1024];
-       size_t count, response_length = sizeof(response);
-       uint32_t rc;
-
-       command = parse_byte_string(argv[1], NULL, &count);
-       if (!command) {
-               printf("Couldn't parse byte string %s\n", argv[1]);
-               return CMD_RET_FAILURE;
-       }
-
-       rc = get_tpm(&dev);
-       if (rc)
-               return rc;
-
-       rc = tpm_xfer(dev, command, count, response, &response_length);
-       free(command);
-       if (!rc) {
-               puts("tpm response:\n");
-               print_byte_string(response, response_length);
-       }
-
-       return report_return_code(rc);
-}
-
-static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, perm, size;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-       size = type_string_get_space_size(argv[1]);
-       if (!size) {
-               printf("Couldn't parse arguments\n");
-               return CMD_RET_USAGE;
-       }
-       index = simple_strtoul(argv[2], NULL, 0);
-       perm = simple_strtoul(argv[3], NULL, 0);
-
-       return report_return_code(tpm_nv_define_space(index, perm, size));
-}
-
-static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, count, err;
-       void *data;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-       if (argc != 3 + type_string_get_num_values(argv[1]))
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[2], NULL, 0);
-       data = type_string_alloc(argv[1], &count);
-       if (!data) {
-               printf("Couldn't parse arguments\n");
-               return CMD_RET_USAGE;
-       }
-
-       err = tpm_nv_read_value(index, data, count);
-       if (!err) {
-               if (type_string_write_vars(argv[1], data, argv + 3)) {
-                       printf("Couldn't write to variables\n");
-                       err = ~0;
-               }
-       }
-       free(data);
-
-       return report_return_code(err);
-}
-
-static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t index, count, err;
-       void *data;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-       if (argc != 3 + type_string_get_num_values(argv[1]))
-               return CMD_RET_USAGE;
-       index = simple_strtoul(argv[2], NULL, 0);
-       data = type_string_alloc(argv[1], &count);
-       if (!data) {
-               printf("Couldn't parse arguments\n");
-               return CMD_RET_USAGE;
-       }
-       if (type_string_pack(argv[1], argv + 3, data)) {
-               printf("Couldn't parse arguments\n");
-               free(data);
-               return CMD_RET_USAGE;
-       }
-
-       err = tpm_nv_write_value(index, data, count);
-       free(data);
-
-       return report_return_code(err);
-}
-
-#ifdef CONFIG_TPM_AUTH_SESSIONS
-
-static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t auth_handle, err;
-
-       err = tpm_oiap(&auth_handle);
-
-       return report_return_code(err);
-}
-
-static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t parent_handle, key_len, key_handle, err;
-       uint8_t usage_auth[DIGEST_LENGTH];
-       void *key;
-
-       if (argc < 5)
-               return CMD_RET_USAGE;
-
-       parent_handle = simple_strtoul(argv[1], NULL, 0);
-       key = (void *)simple_strtoul(argv[2], NULL, 0);
-       key_len = simple_strtoul(argv[3], NULL, 0);
-       if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
-               return CMD_RET_FAILURE;
-       parse_byte_string(argv[4], usage_auth, NULL);
-
-       err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
-                       &key_handle);
-       if (!err)
-               printf("Key handle is 0x%x\n", key_handle);
-
-       return report_return_code(err);
-}
-
-static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
-               int argc, char * const argv[])
-{
-       uint32_t key_handle, err;
-       uint8_t usage_auth[DIGEST_LENGTH];
-       uint8_t pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
-       size_t pub_key_len = sizeof(pub_key_buffer);
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       key_handle = simple_strtoul(argv[1], NULL, 0);
-       if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
-               return CMD_RET_FAILURE;
-       parse_byte_string(argv[2], usage_auth, NULL);
-
-       err = tpm_get_pub_key_oiap(key_handle, usage_auth,
-                       pub_key_buffer, &pub_key_len);
-       if (!err) {
-               printf("dump of received pub key structure:\n");
-               print_byte_string(pub_key_buffer, pub_key_len);
-       }
-       return report_return_code(err);
-}
-
-TPM_COMMAND_NO_ARG(tpm_end_oiap)
-
-#endif /* CONFIG_TPM_AUTH_SESSIONS */
-
-#define MAKE_TPM_CMD_ENTRY(cmd) \
-       U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
-
-static cmd_tbl_t tpm_commands[] = {
-       U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
-       U_BOOT_CMD_MKENT(init, 0, 1,
-                       do_tpm_init, "", ""),
-       U_BOOT_CMD_MKENT(startup, 0, 1,
-                       do_tpm_startup, "", ""),
-       U_BOOT_CMD_MKENT(self_test_full, 0, 1,
-                       do_tpm_self_test_full, "", ""),
-       U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
-                       do_tpm_continue_self_test, "", ""),
-       U_BOOT_CMD_MKENT(force_clear, 0, 1,
-                       do_tpm_force_clear, "", ""),
-       U_BOOT_CMD_MKENT(physical_enable, 0, 1,
-                       do_tpm_physical_enable, "", ""),
-       U_BOOT_CMD_MKENT(physical_disable, 0, 1,
-                       do_tpm_physical_disable, "", ""),
-       U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
-                       do_tpm_nv_define_space, "", ""),
-       U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
-                       do_tpm_nv_read_value, "", ""),
-       U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
-                       do_tpm_nv_write_value, "", ""),
-       U_BOOT_CMD_MKENT(extend, 0, 1,
-                       do_tpm_extend, "", ""),
-       U_BOOT_CMD_MKENT(pcr_read, 0, 1,
-                       do_tpm_pcr_read, "", ""),
-       U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
-                       do_tpm_tsc_physical_presence, "", ""),
-       U_BOOT_CMD_MKENT(read_pubek, 0, 1,
-                       do_tpm_read_pubek, "", ""),
-       U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
-                       do_tpm_physical_set_deactivated, "", ""),
-       U_BOOT_CMD_MKENT(get_capability, 0, 1,
-                       do_tpm_get_capability, "", ""),
-       U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
-                       do_tpm_raw_transfer, "", ""),
-       U_BOOT_CMD_MKENT(nv_define, 0, 1,
-                       do_tpm_nv_define, "", ""),
-       U_BOOT_CMD_MKENT(nv_read, 0, 1,
-                       do_tpm_nv_read, "", ""),
-       U_BOOT_CMD_MKENT(nv_write, 0, 1,
-                       do_tpm_nv_write, "", ""),
-#ifdef CONFIG_TPM_AUTH_SESSIONS
-       U_BOOT_CMD_MKENT(oiap, 0, 1,
-                        do_tpm_oiap, "", ""),
-       U_BOOT_CMD_MKENT(end_oiap, 0, 1,
-                        do_tpm_end_oiap, "", ""),
-       U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
-                        do_tpm_load_key2_oiap, "", ""),
-       U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
-                        do_tpm_get_pub_key_oiap, "", ""),
-#endif /* CONFIG_TPM_AUTH_SESSIONS */
-};
-
-static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *tpm_cmd;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-       tpm_cmd = find_cmd_tbl(argv[1], tpm_commands, ARRAY_SIZE(tpm_commands));
-       if (!tpm_cmd)
-               return CMD_RET_USAGE;
-
-       return tpm_cmd->cmd(cmdtp, flag, argc - 1, argv + 1);
-}
-
-U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
-"Issue a TPM command",
-"cmd args...\n"
-"    - Issue TPM command <cmd> with arguments <args...>.\n"
-"Admin Startup and State Commands:\n"
-"  info - Show information about the TPM\n"
-"  init\n"
-"    - Put TPM into a state where it waits for 'startup' command.\n"
-"  startup mode\n"
-"    - Issue TPM_Starup command.  <mode> is one of TPM_ST_CLEAR,\n"
-"      TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
-"Admin Testing Commands:\n"
-"  self_test_full\n"
-"    - Test all of the TPM capabilities.\n"
-"  continue_self_test\n"
-"    - Inform TPM that it should complete the self-test.\n"
-"Admin Opt-in Commands:\n"
-"  physical_enable\n"
-"    - Set the PERMANENT disable flag to FALSE using physical presence as\n"
-"      authorization.\n"
-"  physical_disable\n"
-"    - Set the PERMANENT disable flag to TRUE using physical presence as\n"
-"      authorization.\n"
-"  physical_set_deactivated 0|1\n"
-"    - Set deactivated flag.\n"
-"Admin Ownership Commands:\n"
-"  force_clear\n"
-"    - Issue TPM_ForceClear command.\n"
-"  tsc_physical_presence flags\n"
-"    - Set TPM device's Physical Presence flags to <flags>.\n"
-"The Capability Commands:\n"
-"  get_capability cap_area sub_cap addr count\n"
-"    - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
-"      <sub_cap> to memory address <addr>.\n"
-#ifdef CONFIG_TPM_AUTH_SESSIONS
-"Storage functions\n"
-"  loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
-"    - loads a key data from memory address <key_addr>, <key_len> bytes\n"
-"      into TPM using the parent key <parent_handle> with authorization\n"
-"      <usage_auth> (20 bytes hex string).\n"
-"  get_pub_key_oiap key_handle usage_auth\n"
-"    - get the public key portion of a loaded key <key_handle> using\n"
-"      authorization <usage auth> (20 bytes hex string)\n"
-#endif /* CONFIG_TPM_AUTH_SESSIONS */
-"Endorsement Key Handling Commands:\n"
-"  read_pubek addr count\n"
-"    - Read <count> bytes of the public endorsement key to memory\n"
-"      address <addr>\n"
-"Integrity Collection and Reporting Commands:\n"
-"  extend index digest_hex_string\n"
-"    - Add a new measurement to a PCR.  Update PCR <index> with the 20-bytes\n"
-"      <digest_hex_string>\n"
-"  pcr_read index addr count\n"
-"    - Read <count> bytes from PCR <index> to memory address <addr>.\n"
-#ifdef CONFIG_TPM_AUTH_SESSIONS
-"Authorization Sessions\n"
-"  oiap\n"
-"    - setup an OIAP session\n"
-"  end_oiap\n"
-"    - terminates an active OIAP session\n"
-#endif /* CONFIG_TPM_AUTH_SESSIONS */
-"Non-volatile Storage Commands:\n"
-"  nv_define_space index permission size\n"
-"    - Establish a space at index <index> with <permission> of <size> bytes.\n"
-"  nv_read_value index addr count\n"
-"    - Read <count> bytes from space <index> to memory address <addr>.\n"
-"  nv_write_value index addr count\n"
-"    - Write <count> bytes from memory address <addr> to space <index>.\n"
-"Miscellaneous helper functions:\n"
-"  raw_transfer byte_string\n"
-"    - Send a byte string <byte_string> to TPM and print the response.\n"
-" Non-volatile storage helper functions:\n"
-"    These helper functions treat a non-volatile space as a non-padded\n"
-"    sequence of integer values.  These integer values are defined by a type\n"
-"    string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
-"    value, 'w' 16-bit value, 'd' 32-bit value.  All helper functions take\n"
-"    a type string as their first argument.\n"
-"  nv_define type_string index perm\n"
-"    - Define a space <index> with permission <perm>.\n"
-"  nv_read types_string index vars...\n"
-"    - Read from space <index> to environment variables <vars...>.\n"
-"  nv_write types_string index values...\n"
-"    - Write to space <index> from values <values...>.\n"
-);
diff --git a/common/cmd_tpm_test.c b/common/cmd_tpm_test.c
deleted file mode 100644 (file)
index 65332d1..0000000
+++ /dev/null
@@ -1,564 +0,0 @@
-/*
- * Copyright (c) 2015 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <environment.h>
-#include <tpm.h>
-
-/* Prints error and returns on failure */
-#define TPM_CHECK(tpm_command) do { \
-       uint32_t result; \
-       \
-       result = (tpm_command); \
-       if (result != TPM_SUCCESS) { \
-               printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \
-                       __LINE__, result); \
-               return result; \
-       } \
-} while (0)
-
-#define INDEX0                 0xda70
-#define INDEX1                 0xda71
-#define INDEX2                 0xda72
-#define INDEX3                 0xda73
-#define INDEX_INITIALISED      0xda80
-#define PHYS_PRESENCE          4
-#define PRESENCE               8
-
-static uint32_t TlclStartupIfNeeded(void)
-{
-       uint32_t result = tpm_startup(TPM_ST_CLEAR);
-
-       return result == TPM_INVALID_POSTINIT ? TPM_SUCCESS : result;
-}
-
-static int test_timer(void)
-{
-       printf("get_timer(0) = %lu\n", get_timer(0));
-       return 0;
-}
-
-static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated,
-                             uint8_t *nvlocked)
-{
-       struct tpm_permanent_flags pflags;
-       uint32_t result;
-
-       result = tpm_get_permanent_flags(&pflags);
-       if (result)
-               return result;
-       if (disable)
-               *disable = pflags.disable;
-       if (deactivated)
-               *deactivated = pflags.deactivated;
-       if (nvlocked)
-               *nvlocked = pflags.nv_locked;
-       debug("TPM: Got flags disable=%d, deactivated=%d, nvlocked=%d\n",
-             pflags.disable, pflags.deactivated, pflags.nv_locked);
-
-       return 0;
-}
-
-static uint32_t tpm_set_global_lock(void)
-{
-       uint32_t x;
-
-       debug("TPM: Set global lock\n");
-       return tpm_nv_write_value(INDEX0, (uint8_t *)&x, 0);
-}
-
-static uint32_t tpm_nv_write_value_lock(uint32_t index)
-{
-       debug("TPM: Write lock 0x%x\n", index);
-
-       return tpm_nv_write_value(index, NULL, 0);
-}
-
-static uint32_t tpm_nv_set_locked(void)
-{
-       debug("TPM: Set NV locked\n");
-
-       return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0);
-}
-
-static int tpm_is_owned(void)
-{
-       uint8_t response[TPM_PUBEK_SIZE];
-       uint32_t result;
-
-       result = tpm_read_pubek(response, sizeof(response));
-
-       return result != TPM_SUCCESS;
-}
-
-static int test_early_extend(void)
-{
-       uint8_t value_in[20];
-       uint8_t value_out[20];
-
-       printf("Testing earlyextend ...");
-       tpm_init();
-       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
-       TPM_CHECK(tpm_continue_self_test());
-       TPM_CHECK(tpm_extend(1, value_in, value_out));
-       printf("done\n");
-       return 0;
-}
-
-static int test_early_nvram(void)
-{
-       uint32_t x;
-
-       printf("Testing earlynvram ...");
-       tpm_init();
-       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
-       TPM_CHECK(tpm_continue_self_test());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
-       printf("done\n");
-       return 0;
-}
-
-static int test_early_nvram2(void)
-{
-       uint32_t x;
-
-       printf("Testing earlynvram2 ...");
-       tpm_init();
-       TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
-       TPM_CHECK(tpm_continue_self_test());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)));
-       printf("done\n");
-       return 0;
-}
-
-static int test_enable(void)
-{
-       uint8_t disable = 0, deactivated = 0;
-
-       printf("Testing enable ...\n");
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_self_test_full());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
-       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
-       TPM_CHECK(tpm_physical_enable());
-       TPM_CHECK(tpm_physical_set_deactivated(0));
-       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
-       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
-       if (disable == 1 || deactivated == 1)
-               printf("\tfailed to enable or activate\n");
-       printf("\tdone\n");
-       return 0;
-}
-
-#define reboot() do { \
-       printf("\trebooting...\n"); \
-       reset_cpu(0); \
-} while (0)
-
-static int test_fast_enable(void)
-{
-       uint8_t disable = 0, deactivated = 0;
-       int i;
-
-       printf("Testing fastenable ...\n");
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_self_test_full());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
-       printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
-       for (i = 0; i < 2; i++) {
-               TPM_CHECK(tpm_force_clear());
-               TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
-               printf("\tdisable is %d, deactivated is %d\n", disable,
-                      deactivated);
-               assert(disable == 1 && deactivated == 1);
-               TPM_CHECK(tpm_physical_enable());
-               TPM_CHECK(tpm_physical_set_deactivated(0));
-               TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
-               printf("\tdisable is %d, deactivated is %d\n", disable,
-                      deactivated);
-               assert(disable == 0 && deactivated == 0);
-       }
-       printf("\tdone\n");
-       return 0;
-}
-
-static int test_global_lock(void)
-{
-       uint32_t zero = 0;
-       uint32_t result;
-       uint32_t x;
-
-       printf("Testing globallock ...\n");
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_self_test_full());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
-       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&zero,
-                                    sizeof(uint32_t)));
-       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
-       TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&zero,
-                                    sizeof(uint32_t)));
-       TPM_CHECK(tpm_set_global_lock());
-       /* Verifies that write to index0 fails */
-       x = 1;
-       result = tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x));
-       assert(result == TPM_AREA_LOCKED);
-       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
-       assert(x == 0);
-       /* Verifies that write to index1 is still possible */
-       x = 2;
-       TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x)));
-       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
-       assert(x == 2);
-       /* Turns off PP */
-       tpm_tsc_physical_presence(PHYS_PRESENCE);
-       /* Verifies that write to index1 fails */
-       x = 3;
-       result = tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x));
-       assert(result == TPM_BAD_PRESENCE);
-       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
-       assert(x == 2);
-       printf("\tdone\n");
-       return 0;
-}
-
-static int test_lock(void)
-{
-       printf("Testing lock ...\n");
-       tpm_init();
-       tpm_startup(TPM_ST_CLEAR);
-       tpm_self_test_full();
-       tpm_tsc_physical_presence(PRESENCE);
-       tpm_nv_write_value_lock(INDEX0);
-       printf("\tLocked 0x%x\n", INDEX0);
-       printf("\tdone\n");
-       return 0;
-}
-
-static void initialise_spaces(void)
-{
-       uint32_t zero = 0;
-       uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE;
-
-       printf("\tInitialising spaces\n");
-       tpm_nv_set_locked();  /* useful only the first time */
-       tpm_nv_define_space(INDEX0, perm, 4);
-       tpm_nv_write_value(INDEX0, (uint8_t *)&zero, 4);
-       tpm_nv_define_space(INDEX1, perm, 4);
-       tpm_nv_write_value(INDEX1, (uint8_t *)&zero, 4);
-       tpm_nv_define_space(INDEX2, perm, 4);
-       tpm_nv_write_value(INDEX2, (uint8_t *)&zero, 4);
-       tpm_nv_define_space(INDEX3, perm, 4);
-       tpm_nv_write_value(INDEX3, (uint8_t *)&zero, 4);
-       perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
-               TPM_NV_PER_PPWRITE;
-       tpm_nv_define_space(INDEX_INITIALISED, perm, 1);
-}
-
-static int test_readonly(void)
-{
-       uint8_t c;
-       uint32_t index_0, index_1, index_2, index_3;
-       int read0, read1, read2, read3;
-
-       printf("Testing readonly ...\n");
-       tpm_init();
-       tpm_startup(TPM_ST_CLEAR);
-       tpm_self_test_full();
-       tpm_tsc_physical_presence(PRESENCE);
-       /*
-        * Checks if initialisation has completed by trying to read-lock a
-        * space that's created at the end of initialisation
-        */
-       if (tpm_nv_read_value(INDEX_INITIALISED, &c, 0) == TPM_BADINDEX) {
-               /* The initialisation did not complete */
-               initialise_spaces();
-       }
-
-       /* Checks if spaces are OK or messed up */
-       read0 = tpm_nv_read_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0));
-       read1 = tpm_nv_read_value(INDEX1, (uint8_t *)&index_1, sizeof(index_1));
-       read2 = tpm_nv_read_value(INDEX2, (uint8_t *)&index_2, sizeof(index_2));
-       read3 = tpm_nv_read_value(INDEX3, (uint8_t *)&index_3, sizeof(index_3));
-       if (read0 || read1 || read2 || read3) {
-               printf("Invalid contents\n");
-               return 0;
-       }
-
-       /*
-        * Writes space, and locks it.  Then attempts to write again.
-        * I really wish I could use the imperative.
-        */
-       index_0 += 1;
-       if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0) !=
-               TPM_SUCCESS)) {
-               error("\tcould not write index 0\n");
-       }
-       tpm_nv_write_value_lock(INDEX0);
-       if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0)) ==
-                       TPM_SUCCESS)
-               error("\tindex 0 is not locked\n");
-
-       printf("\tdone\n");
-       return 0;
-}
-
-static int test_redefine_unowned(void)
-{
-       uint32_t perm;
-       uint32_t result;
-       uint32_t x;
-
-       printf("Testing redefine_unowned ...");
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_self_test_full());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       assert(!tpm_is_owned());
-
-       /* Ensures spaces exist. */
-       TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
-       TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
-
-       /* Redefines spaces a couple of times. */
-       perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
-       TPM_CHECK(tpm_nv_define_space(INDEX0, perm, 2 * sizeof(uint32_t)));
-       TPM_CHECK(tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t)));
-       perm = TPM_NV_PER_PPWRITE;
-       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
-       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
-
-       /* Sets the global lock */
-       tpm_set_global_lock();
-
-       /* Verifies that index0 cannot be redefined */
-       result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
-       assert(result == TPM_AREA_LOCKED);
-
-       /* Checks that index1 can */
-       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
-       TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
-
-       /* Turns off PP */
-       tpm_tsc_physical_presence(PHYS_PRESENCE);
-
-       /* Verifies that neither index0 nor index1 can be redefined */
-       result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
-       assert(result == TPM_BAD_PRESENCE);
-       result = tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t));
-       assert(result == TPM_BAD_PRESENCE);
-
-       printf("done\n");
-       return 0;
-}
-
-#define PERMPPGL (TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK)
-#define PERMPP TPM_NV_PER_PPWRITE
-
-static int test_space_perm(void)
-{
-       uint32_t perm;
-
-       printf("Testing spaceperm ...");
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_continue_self_test());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_get_permissions(INDEX0, &perm));
-       assert((perm & PERMPPGL) == PERMPPGL);
-       TPM_CHECK(tpm_get_permissions(INDEX1, &perm));
-       assert((perm & PERMPP) == PERMPP);
-       printf("done\n");
-       return 0;
-}
-
-static int test_startup(void)
-{
-       uint32_t result;
-       printf("Testing startup ...\n");
-
-       tpm_init();
-       result = tpm_startup(TPM_ST_CLEAR);
-       if (result != 0 && result != TPM_INVALID_POSTINIT)
-               printf("\ttpm startup failed with 0x%x\n", result);
-       result = tpm_get_flags(NULL, NULL, NULL);
-       if (result != 0)
-               printf("\ttpm getflags failed with 0x%x\n", result);
-       printf("\texecuting SelfTestFull\n");
-       tpm_self_test_full();
-       result = tpm_get_flags(NULL, NULL, NULL);
-       if (result != 0)
-               printf("\ttpm getflags failed with 0x%x\n", result);
-       printf("\tdone\n");
-       return 0;
-}
-
-/*
- * Runs [op] and ensures it returns success and doesn't run longer than
- * [time_limit] in milliseconds.
- */
-#define TTPM_CHECK(op, time_limit) do { \
-       ulong start, time; \
-       uint32_t __result; \
-       \
-       start = get_timer(0); \
-       __result = op; \
-       if (__result != TPM_SUCCESS) { \
-               printf("\t" #op ": error 0x%x\n", __result); \
-               return -1; \
-       } \
-       time = get_timer(start); \
-       printf("\t" #op ": %lu ms\n", time); \
-       if (time > (ulong)time_limit) { \
-               printf("\t" #op " exceeded " #time_limit " ms\n"); \
-       } \
-} while (0)
-
-
-static int test_timing(void)
-{
-       uint32_t x;
-       uint8_t in[20], out[20];
-
-       printf("Testing timing ...");
-       tpm_init();
-       TTPM_CHECK(TlclStartupIfNeeded(), 50);
-       TTPM_CHECK(tpm_continue_self_test(), 100);
-       TTPM_CHECK(tpm_self_test_full(), 1000);
-       TTPM_CHECK(tpm_tsc_physical_presence(PRESENCE), 100);
-       TTPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
-       TTPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
-       TTPM_CHECK(tpm_extend(0, in, out), 200);
-       TTPM_CHECK(tpm_set_global_lock(), 50);
-       TTPM_CHECK(tpm_tsc_physical_presence(PHYS_PRESENCE), 100);
-       printf("done\n");
-       return 0;
-}
-
-#define TPM_MAX_NV_WRITES_NOOWNER 64
-
-static int test_write_limit(void)
-{
-       printf("Testing writelimit ...\n");
-       int i;
-       uint32_t result;
-
-       tpm_init();
-       TPM_CHECK(TlclStartupIfNeeded());
-       TPM_CHECK(tpm_self_test_full());
-       TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
-       TPM_CHECK(tpm_force_clear());
-       TPM_CHECK(tpm_physical_enable());
-       TPM_CHECK(tpm_physical_set_deactivated(0));
-
-       for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) {
-               printf("\twriting %d\n", i);
-               result = tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i));
-               switch (result) {
-               case TPM_SUCCESS:
-                       break;
-               case TPM_MAXNVWRITES:
-                       assert(i >= TPM_MAX_NV_WRITES_NOOWNER);
-               default:
-                       error("\tunexpected error code %d (0x%x)\n",
-                             result, result);
-               }
-       }
-
-       /* Reset write count */
-       TPM_CHECK(tpm_force_clear());
-       TPM_CHECK(tpm_physical_enable());
-       TPM_CHECK(tpm_physical_set_deactivated(0));
-
-       /* Try writing again. */
-       TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i)));
-       printf("\tdone\n");
-       return 0;
-}
-
-#define VOIDTEST(XFUNC) \
-       int do_test_##XFUNC(cmd_tbl_t *cmd_tbl, int flag, int argc, \
-       char * const argv[]) \
-       { \
-               return test_##XFUNC(); \
-       }
-
-#define VOIDENT(XNAME) \
-       U_BOOT_CMD_MKENT(XNAME, 0, 1, do_test_##XNAME, "", ""),
-
-VOIDTEST(early_extend)
-VOIDTEST(early_nvram)
-VOIDTEST(early_nvram2)
-VOIDTEST(enable)
-VOIDTEST(fast_enable)
-VOIDTEST(global_lock)
-VOIDTEST(lock)
-VOIDTEST(readonly)
-VOIDTEST(redefine_unowned)
-VOIDTEST(space_perm)
-VOIDTEST(startup)
-VOIDTEST(timing)
-VOIDTEST(write_limit)
-VOIDTEST(timer)
-
-static cmd_tbl_t cmd_cros_tpm_sub[] = {
-       VOIDENT(early_extend)
-       VOIDENT(early_nvram)
-       VOIDENT(early_nvram2)
-       VOIDENT(enable)
-       VOIDENT(fast_enable)
-       VOIDENT(global_lock)
-       VOIDENT(lock)
-       VOIDENT(readonly)
-       VOIDENT(redefine_unowned)
-       VOIDENT(space_perm)
-       VOIDENT(startup)
-       VOIDENT(timing)
-       VOIDENT(write_limit)
-       VOIDENT(timer)
-};
-
-static int do_tpmtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       cmd_tbl_t *c;
-
-       printf("argc = %d, argv = ", argc);
-       do {
-               int i = 0;
-
-               for (i = 0; i < argc; i++)
-                       printf(" %s", argv[i]);
-                       printf("\n------\n");
-               } while (0);
-       argc--;
-       argv++;
-       c = find_cmd_tbl(argv[0], cmd_cros_tpm_sub,
-                        ARRAY_SIZE(cmd_cros_tpm_sub));
-       return c ? c->cmd(cmdtp, flag, argc, argv) : cmd_usage(cmdtp);
-}
-
-U_BOOT_CMD(tpmtest, 2, 1, do_tpmtest, "TPM tests",
-       "\n\tearly_extend\n"
-       "\tearly_nvram\n"
-       "\tearly_nvram2\n"
-       "\tenable\n"
-       "\tfast_enable\n"
-       "\tglobal_lock\n"
-       "\tlock\n"
-       "\treadonly\n"
-       "\tredefine_unowned\n"
-       "\tspace_perm\n"
-       "\tstartup\n"
-       "\ttiming\n"
-       "\twrite_limit\n");
diff --git a/common/cmd_trace.c b/common/cmd_trace.c
deleted file mode 100644 (file)
index 1e62a1a..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2011 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <mapmem.h>
-#include <trace.h>
-#include <asm/io.h>
-
-static int get_args(int argc, char * const argv[], char **buff,
-                   size_t *buff_ptr, size_t *buff_size)
-{
-       if (argc < 2)
-               return -1;
-       if (argc < 4) {
-               *buff_size = getenv_ulong("profsize", 16, 0);
-               *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
-                                  *buff_size);
-               *buff_ptr = getenv_ulong("profoffset", 16, 0);
-       } else {
-               *buff_size = simple_strtoul(argv[3], NULL, 16);
-               *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
-                                  *buff_size);
-               *buff_ptr = 0;
-       };
-       return 0;
-}
-
-static int create_func_list(int argc, char * const argv[])
-{
-       size_t buff_size, avail, buff_ptr, used;
-       unsigned int needed;
-       char *buff;
-       int err;
-
-       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
-               return -1;
-
-       avail = buff_size - buff_ptr;
-       err = trace_list_functions(buff + buff_ptr, avail, &needed);
-       if (err)
-               printf("Error: truncated (%#x bytes needed)\n", needed);
-       used = min(avail, needed);
-       printf("Function trace dumped to %08lx, size %#zx\n",
-              (ulong)map_to_sysmem(buff + buff_ptr), used);
-       setenv_hex("profbase", map_to_sysmem(buff));
-       setenv_hex("profsize", buff_size);
-       setenv_hex("profoffset", buff_ptr + used);
-
-       return 0;
-}
-
-static int create_call_list(int argc, char * const argv[])
-{
-       size_t buff_size, avail, buff_ptr, used;
-       unsigned int needed;
-       char *buff;
-       int err;
-
-       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
-               return -1;
-
-       avail = buff_size - buff_ptr;
-       err = trace_list_calls(buff + buff_ptr, avail, &needed);
-       if (err)
-               printf("Error: truncated (%#x bytes needed)\n", needed);
-       used = min(avail, needed);
-       printf("Call list dumped to %08lx, size %#zx\n",
-              (ulong)map_to_sysmem(buff + buff_ptr), used);
-
-       setenv_hex("profbase", map_to_sysmem(buff));
-       setenv_hex("profsize", buff_size);
-       setenv_hex("profoffset", buff_ptr + used);
-
-       return 0;
-}
-
-int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const char *cmd = argc < 2 ? NULL : argv[1];
-
-       if (!cmd)
-               return cmd_usage(cmdtp);
-       switch (*cmd) {
-       case 'p':
-               trace_set_enabled(0);
-               break;
-       case 'c':
-               if (create_call_list(argc, argv))
-                       return cmd_usage(cmdtp);
-               break;
-       case 'r':
-               trace_set_enabled(1);
-               break;
-       case 'f':
-               if (create_func_list(argc, argv))
-                       return cmd_usage(cmdtp);
-               break;
-       case 's':
-               trace_print_stats();
-               break;
-       default:
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       trace,  4,      1,      do_trace,
-       "trace utility commands",
-       "stats                        - display tracing statistics\n"
-       "trace pause                        - pause tracing\n"
-       "trace resume                       - resume tracing\n"
-       "trace funclist [<addr> <size>]     - dump function list into buffer\n"
-       "trace calls  [<addr> <size>]       "
-               "- dump function call trace into buffer"
-);
diff --git a/common/cmd_tsi148.c b/common/cmd_tsi148.c
deleted file mode 100644 (file)
index ea96d0f..0000000
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- * (C) Copyright 2009 Reinhard Arlt, reinhard.arlt@esd-electronics.com
- *
- * base on universe.h by
- *
- * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <asm/io.h>
-#include <pci.h>
-
-#include <tsi148.h>
-
-#define LPCI_VENDOR PCI_VENDOR_ID_TUNDRA
-#define LPCI_DEVICE PCI_DEVICE_ID_TUNDRA_TSI148
-
-typedef struct _TSI148_DEV TSI148_DEV;
-
-struct _TSI148_DEV {
-       int           bus;
-       pci_dev_t     busdevfn;
-       TSI148       *uregs;
-       unsigned int  pci_bs;
-};
-
-static TSI148_DEV *dev;
-
-/*
- * Most of the TSI148 register are BIGENDIAN
- * This is the reason for the __raw_writel(htonl(x), x) usage!
- */
-
-int tsi148_init(void)
-{
-       int j, result;
-       pci_dev_t busdevfn;
-       unsigned int val;
-
-       busdevfn = pci_find_device(LPCI_VENDOR, LPCI_DEVICE, 0);
-       if (busdevfn == -1) {
-               puts("Tsi148: No Tundra Tsi148 found!\n");
-               return -1;
-       }
-
-       /* Lets turn Latency off */
-       pci_write_config_dword(busdevfn, 0x0c, 0);
-
-       dev = malloc(sizeof(*dev));
-       if (NULL == dev) {
-               puts("Tsi148: No memory!\n");
-               return -1;
-       }
-
-       memset(dev, 0, sizeof(*dev));
-       dev->busdevfn = busdevfn;
-
-       pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
-       val &= ~0xf;
-       dev->uregs = (TSI148 *)val;
-
-       debug("Tsi148: Base    : %p\n", dev->uregs);
-
-       /* check mapping */
-       debug("Tsi148: Read via mapping, PCI_ID = %08X\n",
-             readl(&dev->uregs->pci_id));
-       if (((LPCI_DEVICE << 16) | LPCI_VENDOR) != readl(&dev->uregs->pci_id)) {
-               printf("Tsi148: Cannot read PCI-ID via Mapping: %08x\n",
-                      readl(&dev->uregs->pci_id));
-               result = -1;
-               goto break_30;
-       }
-
-       debug("Tsi148: PCI_BS = %08X\n", readl(&dev->uregs->pci_mbarl));
-
-       dev->pci_bs = readl(&dev->uregs->pci_mbarl);
-
-       /* turn off windows */
-       for (j = 0; j < 8; j++) {
-               __raw_writel(htonl(0x00000000), &dev->uregs->outbound[j].otat);
-               __raw_writel(htonl(0x00000000), &dev->uregs->inbound[j].itat);
-       }
-
-       /* Tsi148 VME timeout etc */
-       __raw_writel(htonl(0x00000084), &dev->uregs->vctrl);
-
-#ifdef DEBUG
-       if ((__raw_readl(&dev->uregs->vstat) & 0x00000100) != 0)
-               printf("Tsi148: System Controller!\n");
-       else
-               printf("Tsi148: Not System Controller!\n");
-#endif
-
-       /*
-        * Lets turn off interrupts
-        */
-       /* Disable interrupts in Tsi148 first */
-       __raw_writel(htonl(0x00000000), &dev->uregs->inten);
-       /* Disable interrupt out */
-       __raw_writel(htonl(0x00000000), &dev->uregs->inteo);
-       eieio();
-       /* Reset all IRQ's */
-       __raw_writel(htonl(0x03ff3f00), &dev->uregs->intc);
-       /* Map all ints to 0 */
-       __raw_writel(htonl(0x00000000), &dev->uregs->intm1);
-       __raw_writel(htonl(0x00000000), &dev->uregs->intm2);
-       eieio();
-
-       val = __raw_readl(&dev->uregs->vstat);
-       val &= ~(0x00004000);
-       __raw_writel(val, &dev->uregs->vstat);
-       eieio();
-
-       debug("Tsi148: register struct size %08x\n", sizeof(TSI148));
-
-       return 0;
-
- break_30:
-       free(dev);
-       dev = NULL;
-
-       return result;
-}
-
-/*
- * Create pci slave window (access: pci -> vme)
- */
-int tsi148_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr,
-                           int size, int vam, int vdw)
-{
-       int result, i;
-       unsigned int ctl = 0;
-
-       if (NULL == dev) {
-               result = -1;
-               goto exit_10;
-       }
-
-       for (i = 0; i < 8; i++) {
-               if (0x00000000 == readl(&dev->uregs->outbound[i].otat))
-                       break;
-       }
-
-       if (i > 7) {
-               printf("Tsi148: No Image available\n");
-               result = -1;
-               goto exit_10;
-       }
-
-       debug("Tsi148: Using image %d\n", i);
-
-       printf("Tsi148: Pci addr %08x\n", pciAddr);
-
-       __raw_writel(htonl(pciAddr), &dev->uregs->outbound[i].otsal);
-       __raw_writel(0x00000000, &dev->uregs->outbound[i].otsau);
-       __raw_writel(htonl(pciAddr + size), &dev->uregs->outbound[i].oteal);
-       __raw_writel(0x00000000, &dev->uregs->outbound[i].oteau);
-       __raw_writel(htonl(vmeAddr - pciAddr), &dev->uregs->outbound[i].otofl);
-       __raw_writel(0x00000000, &dev->uregs->outbound[i].otofu);
-
-       switch (vam & VME_AM_Axx) {
-       case VME_AM_A16:
-               ctl = 0x00000000;
-               break;
-       case VME_AM_A24:
-               ctl = 0x00000001;
-               break;
-       case VME_AM_A32:
-               ctl = 0x00000002;
-               break;
-       }
-
-       switch (vam & VME_AM_Mxx) {
-       case VME_AM_DATA:
-               ctl |= 0x00000000;
-               break;
-       case VME_AM_PROG:
-               ctl |= 0x00000010;
-               break;
-       }
-
-       if (vam & VME_AM_SUP)
-               ctl |= 0x00000020;
-
-       switch (vdw & VME_FLAG_Dxx) {
-       case VME_FLAG_D16:
-               ctl |= 0x00000000;
-               break;
-       case VME_FLAG_D32:
-               ctl |= 0x00000040;
-               break;
-       }
-
-       ctl |= 0x80040000;      /* enable, no prefetch */
-
-       __raw_writel(htonl(ctl), &dev->uregs->outbound[i].otat);
-
-       debug("Tsi148: window-addr                =%p\n",
-             &dev->uregs->outbound[i].otsau);
-       debug("Tsi148: pci slave window[%d] attr  =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otat)));
-       debug("Tsi148: pci slave window[%d] start =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otsal)));
-       debug("Tsi148: pci slave window[%d] end   =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->outbound[i].oteal)));
-       debug("Tsi148: pci slave window[%d] offset=%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->outbound[i].otofl)));
-
-       return 0;
-
- exit_10:
-       return -result;
-}
-
-unsigned int tsi148_eval_vam(int vam)
-{
-       unsigned int ctl = 0;
-
-       switch (vam & VME_AM_Axx) {
-       case VME_AM_A16:
-               ctl = 0x00000000;
-               break;
-       case VME_AM_A24:
-               ctl = 0x00000010;
-               break;
-       case VME_AM_A32:
-               ctl = 0x00000020;
-               break;
-       }
-       switch (vam & VME_AM_Mxx) {
-       case VME_AM_DATA:
-               ctl |= 0x00000001;
-               break;
-       case VME_AM_PROG:
-               ctl |= 0x00000002;
-               break;
-       case (VME_AM_PROG | VME_AM_DATA):
-               ctl |= 0x00000003;
-               break;
-       }
-
-       if (vam & VME_AM_SUP)
-               ctl |= 0x00000008;
-       if (vam & VME_AM_USR)
-               ctl |= 0x00000004;
-
-       return ctl;
-}
-
-/*
- * Create vme slave window (access: vme -> pci)
- */
-int tsi148_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr,
-                           int size, int vam)
-{
-       int result, i;
-       unsigned int ctl = 0;
-
-       if (NULL == dev) {
-               result = -1;
-               goto exit_10;
-       }
-
-       for (i = 0; i < 8; i++) {
-               if (0x00000000 == readl(&dev->uregs->inbound[i].itat))
-                       break;
-       }
-
-       if (i > 7) {
-               printf("Tsi148: No Image available\n");
-               result = -1;
-               goto exit_10;
-       }
-
-       debug("Tsi148: Using image %d\n", i);
-
-       __raw_writel(htonl(vmeAddr), &dev->uregs->inbound[i].itsal);
-       __raw_writel(0x00000000, &dev->uregs->inbound[i].itsau);
-       __raw_writel(htonl(vmeAddr + size), &dev->uregs->inbound[i].iteal);
-       __raw_writel(0x00000000, &dev->uregs->inbound[i].iteau);
-       __raw_writel(htonl(pciAddr - vmeAddr), &dev->uregs->inbound[i].itofl);
-       if (vmeAddr > pciAddr)
-               __raw_writel(0xffffffff, &dev->uregs->inbound[i].itofu);
-       else
-               __raw_writel(0x00000000, &dev->uregs->inbound[i].itofu);
-
-       ctl = tsi148_eval_vam(vam);
-       ctl |= 0x80000000;      /* enable */
-       __raw_writel(htonl(ctl), &dev->uregs->inbound[i].itat);
-
-       debug("Tsi148: window-addr                =%p\n",
-             &dev->uregs->inbound[i].itsau);
-       debug("Tsi148: vme slave window[%d] attr  =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itat)));
-       debug("Tsi148: vme slave window[%d] start =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itsal)));
-       debug("Tsi148: vme slave window[%d] end   =%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->inbound[i].iteal)));
-       debug("Tsi148: vme slave window[%d] offset=%08x\n",
-             i, ntohl(__raw_readl(&dev->uregs->inbound[i].itofl)));
-
-       return 0;
-
- exit_10:
-       return -result;
-}
-
-/*
- * Create vme slave window (access: vme -> gcsr)
- */
-int tsi148_vme_gcsr_window(unsigned int vmeAddr, int vam)
-{
-       int result;
-       unsigned int ctl;
-
-       result = 0;
-
-       if (NULL == dev) {
-               result = 1;
-       } else {
-               __raw_writel(htonl(vmeAddr), &dev->uregs->gbal);
-               __raw_writel(0x00000000, &dev->uregs->gbau);
-
-               ctl = tsi148_eval_vam(vam);
-               ctl |= 0x00000080;      /* enable */
-               __raw_writel(htonl(ctl), &dev->uregs->gcsrat);
-       }
-
-       return result;
-}
-
-/*
- * Create vme slave window (access: vme -> crcsr)
- */
-int tsi148_vme_crcsr_window(unsigned int vmeAddr)
-{
-       int result;
-       unsigned int ctl;
-
-       result = 0;
-
-       if (NULL == dev) {
-               result = 1;
-       } else {
-               __raw_writel(htonl(vmeAddr), &dev->uregs->crol);
-               __raw_writel(0x00000000, &dev->uregs->crou);
-
-               ctl = 0x00000080;       /* enable */
-               __raw_writel(htonl(ctl), &dev->uregs->crat);
-       }
-
-       return result;
-}
-
-/*
- * Create vme slave window (access: vme -> crg)
- */
-int tsi148_vme_crg_window(unsigned int vmeAddr, int vam)
-{
-       int result;
-       unsigned int ctl;
-
-       result = 0;
-
-       if (NULL == dev) {
-               result = 1;
-       } else {
-               __raw_writel(htonl(vmeAddr), &dev->uregs->cbal);
-               __raw_writel(0x00000000, &dev->uregs->cbau);
-
-               ctl = tsi148_eval_vam(vam);
-               ctl |= 0x00000080;      /* enable */
-               __raw_writel(htonl(ctl), &dev->uregs->crgat);
-       }
-
-       return result;
-}
-
-/*
- * Tundra Tsi148 configuration
- */
-int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, vdw = 0;
-       char cmd = 'x';
-
-       /* get parameter */
-       if (argc > 1)
-               cmd = argv[1][0];
-       if (argc > 2)
-               addr1 = simple_strtoul(argv[2], NULL, 16);
-       if (argc > 3)
-               addr2 = simple_strtoul(argv[3], NULL, 16);
-       if (argc > 4)
-               size = simple_strtoul(argv[4], NULL, 16);
-       if (argc > 5)
-               vam = simple_strtoul(argv[5], NULL, 16);
-       if (argc > 6)
-               vdw = simple_strtoul(argv[6], NULL, 16);
-
-       switch (cmd) {
-       case 'c':
-               if (strcmp(argv[1], "crg") == 0) {
-                       vam = addr2;
-                       printf("Tsi148: Configuring VME CRG Window "
-                              "(VME->CRG):\n");
-                       printf("  vme=%08lx vam=%02lx\n", addr1, vam);
-                       tsi148_vme_crg_window(addr1, vam);
-               } else {
-                       printf("Tsi148: Configuring VME CR/CSR Window "
-                              "(VME->CR/CSR):\n");
-                       printf("  pci=%08lx\n", addr1);
-                       tsi148_vme_crcsr_window(addr1);
-               }
-               break;
-       case 'i':               /* init */
-               tsi148_init();
-               break;
-       case 'g':
-               vam = addr2;
-               printf("Tsi148: Configuring VME GCSR Window (VME->GCSR):\n");
-               printf("  vme=%08lx vam=%02lx\n", addr1, vam);
-               tsi148_vme_gcsr_window(addr1, vam);
-               break;
-       case 'v':               /* vme */
-               printf("Tsi148: Configuring VME Slave Window (VME->PCI):\n");
-               printf("  vme=%08lx pci=%08lx size=%08lx vam=%02lx\n",
-                      addr1, addr2, size, vam);
-               tsi148_vme_slave_window(addr1, addr2, size, vam);
-               break;
-       case 'p':               /* pci */
-               printf("Tsi148: Configuring PCI Slave Window (PCI->VME):\n");
-               printf("  pci=%08lx vme=%08lx size=%08lx vam=%02lx vdw=%02lx\n",
-                      addr1, addr2, size, vam, vdw);
-               tsi148_pci_slave_window(addr1, addr2, size, vam, vdw);
-               break;
-       default:
-               printf("Tsi148: Command %s not supported!\n", argv[1]);
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       tsi148, 7,      1,      do_tsi148,
-       "initialize and configure Turndra Tsi148\n",
-       "init\n"
-       "    - initialize tsi148\n"
-       "tsi148 vme   [vme_addr] [pci_addr] [size] [vam]\n"
-       "    - create vme slave window (access: vme->pci)\n"
-       "tsi148 pci   [pci_addr] [vme_addr] [size] [vam] [vdw]\n"
-       "    - create pci slave window (access: pci->vme)\n"
-       "tsi148 crg   [vme_addr] [vam]\n"
-       "    - create vme slave window: (access vme->CRG\n"
-       "tsi148 crcsr [pci_addr]\n"
-       "    - create vme slave window: (access vme->CR/CSR\n"
-       "tsi148 gcsr  [vme_addr] [vam]\n"
-       "    - create vme slave window: (access vme->GCSR\n"
-       "    [vam] = VMEbus Address-Modifier:  01 -> A16 Address Space\n"
-       "                                      02 -> A24 Address Space\n"
-       "                                      03 -> A32 Address Space\n"
-       "                                      04 -> Usr        AM Code\n"
-       "                                      08 -> Supervisor AM Code\n"
-       "                                      10 -> Data AM Code\n"
-       "                                      20 -> Program AM Code\n"
-       "    [vdw] = VMEbus Maximum Datawidth: 02 -> D16 Data Width\n"
-       "                                      03 -> D32 Data Width\n"
-);
diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
deleted file mode 100644 (file)
index 753a4db..0000000
+++ /dev/null
@@ -1,685 +0,0 @@
-/*
- * Unsorted Block Image commands
- *
- *  Copyright (C) 2008 Samsung Electronics
- *  Kyungmin Park <kyungmin.park@samsung.com>
- *
- * Copyright 2008-2009 Stefan Roese <sr@denx.de>, DENX Software Engineering
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <common.h>
-#include <command.h>
-#include <exports.h>
-#include <memalign.h>
-#include <nand.h>
-#include <onenand_uboot.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/partitions.h>
-#include <linux/err.h>
-#include <ubi_uboot.h>
-#include <asm/errno.h>
-#include <jffs2/load_kernel.h>
-
-#undef ubi_msg
-#define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
-
-#define DEV_TYPE_NONE          0
-#define DEV_TYPE_NAND          1
-#define DEV_TYPE_ONENAND       2
-#define DEV_TYPE_NOR           3
-
-/* Private own data */
-static struct ubi_device *ubi;
-static char buffer[80];
-static int ubi_initialized;
-
-struct selected_dev {
-       char part_name[80];
-       int selected;
-       int nr;
-       struct mtd_info *mtd_info;
-};
-
-static struct selected_dev ubi_dev;
-
-#ifdef CONFIG_CMD_UBIFS
-int ubifs_is_mounted(void);
-void cmd_ubifs_umount(void);
-#endif
-
-static void display_volume_info(struct ubi_device *ubi)
-{
-       int i;
-
-       for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
-               if (!ubi->volumes[i])
-                       continue;       /* Empty record */
-               ubi_dump_vol_info(ubi->volumes[i]);
-       }
-}
-
-static void display_ubi_info(struct ubi_device *ubi)
-{
-       ubi_msg("MTD device name:            \"%s\"", ubi->mtd->name);
-       ubi_msg("MTD device size:            %llu MiB", ubi->flash_size >> 20);
-       ubi_msg("physical eraseblock size:   %d bytes (%d KiB)",
-                       ubi->peb_size, ubi->peb_size >> 10);
-       ubi_msg("logical eraseblock size:    %d bytes", ubi->leb_size);
-       ubi_msg("number of good PEBs:        %d", ubi->good_peb_count);
-       ubi_msg("number of bad PEBs:         %d", ubi->bad_peb_count);
-       ubi_msg("smallest flash I/O unit:    %d", ubi->min_io_size);
-       ubi_msg("VID header offset:          %d (aligned %d)",
-                       ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
-       ubi_msg("data offset:                %d", ubi->leb_start);
-       ubi_msg("max. allowed volumes:       %d", ubi->vtbl_slots);
-       ubi_msg("wear-leveling threshold:    %d", CONFIG_MTD_UBI_WL_THRESHOLD);
-       ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
-       ubi_msg("number of user volumes:     %d",
-                       ubi->vol_count - UBI_INT_VOL_COUNT);
-       ubi_msg("available PEBs:             %d", ubi->avail_pebs);
-       ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs);
-       ubi_msg("number of PEBs reserved for bad PEB handling: %d",
-                       ubi->beb_rsvd_pebs);
-       ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
-}
-
-static int ubi_info(int layout)
-{
-       if (layout)
-               display_volume_info(ubi);
-       else
-               display_ubi_info(ubi);
-
-       return 0;
-}
-
-static int ubi_check_volumename(const struct ubi_volume *vol, char *name)
-{
-       return strcmp(vol->name, name);
-}
-
-static int ubi_check(char *name)
-{
-       int i;
-
-       for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
-               if (!ubi->volumes[i])
-                       continue;       /* Empty record */
-
-               if (!ubi_check_volumename(ubi->volumes[i], name))
-                       return 0;
-       }
-
-       return 1;
-}
-
-
-static int verify_mkvol_req(const struct ubi_device *ubi,
-                           const struct ubi_mkvol_req *req)
-{
-       int n, err = EINVAL;
-
-       if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 ||
-           req->name_len < 0)
-               goto bad;
-
-       if ((req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots) &&
-           req->vol_id != UBI_VOL_NUM_AUTO)
-               goto bad;
-
-       if (req->alignment == 0)
-               goto bad;
-
-       if (req->bytes == 0) {
-               printf("No space left in UBI device!\n");
-               err = ENOMEM;
-               goto bad;
-       }
-
-       if (req->vol_type != UBI_DYNAMIC_VOLUME &&
-           req->vol_type != UBI_STATIC_VOLUME)
-               goto bad;
-
-       if (req->alignment > ubi->leb_size)
-               goto bad;
-
-       n = req->alignment % ubi->min_io_size;
-       if (req->alignment != 1 && n)
-               goto bad;
-
-       if (req->name_len > UBI_VOL_NAME_MAX) {
-               printf("Name too long!\n");
-               err = ENAMETOOLONG;
-               goto bad;
-       }
-
-       return 0;
-bad:
-       return err;
-}
-
-static int ubi_create_vol(char *volume, int64_t size, int dynamic)
-{
-       struct ubi_mkvol_req req;
-       int err;
-
-       if (dynamic)
-               req.vol_type = UBI_DYNAMIC_VOLUME;
-       else
-               req.vol_type = UBI_STATIC_VOLUME;
-
-       req.vol_id = UBI_VOL_NUM_AUTO;
-       req.alignment = 1;
-       req.bytes = size;
-
-       strcpy(req.name, volume);
-       req.name_len = strlen(volume);
-       req.name[req.name_len] = '\0';
-       req.padding1 = 0;
-       /* It's duplicated at drivers/mtd/ubi/cdev.c */
-       err = verify_mkvol_req(ubi, &req);
-       if (err) {
-               printf("verify_mkvol_req failed %d\n", err);
-               return err;
-       }
-       printf("Creating %s volume %s of size %lld\n",
-               dynamic ? "dynamic" : "static", volume, size);
-       /* Call real ubi create volume */
-       return ubi_create_volume(ubi, &req);
-}
-
-static struct ubi_volume *ubi_find_volume(char *volume)
-{
-       struct ubi_volume *vol = NULL;
-       int i;
-
-       for (i = 0; i < ubi->vtbl_slots; i++) {
-               vol = ubi->volumes[i];
-               if (vol && !strcmp(vol->name, volume))
-                       return vol;
-       }
-
-       printf("Volume %s not found!\n", volume);
-       return NULL;
-}
-
-static int ubi_remove_vol(char *volume)
-{
-       int err, reserved_pebs, i;
-       struct ubi_volume *vol;
-
-       vol = ubi_find_volume(volume);
-       if (vol == NULL)
-               return ENODEV;
-
-       printf("Remove UBI volume %s (id %d)\n", vol->name, vol->vol_id);
-
-       if (ubi->ro_mode) {
-               printf("It's read-only mode\n");
-               err = EROFS;
-               goto out_err;
-       }
-
-       err = ubi_change_vtbl_record(ubi, vol->vol_id, NULL);
-       if (err) {
-               printf("Error changing Vol tabel record err=%x\n", err);
-               goto out_err;
-       }
-       reserved_pebs = vol->reserved_pebs;
-       for (i = 0; i < vol->reserved_pebs; i++) {
-               err = ubi_eba_unmap_leb(ubi, vol, i);
-               if (err)
-                       goto out_err;
-       }
-
-       kfree(vol->eba_tbl);
-       ubi->volumes[vol->vol_id]->eba_tbl = NULL;
-       ubi->volumes[vol->vol_id] = NULL;
-
-       ubi->rsvd_pebs -= reserved_pebs;
-       ubi->avail_pebs += reserved_pebs;
-       i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
-       if (i > 0) {
-               i = ubi->avail_pebs >= i ? i : ubi->avail_pebs;
-               ubi->avail_pebs -= i;
-               ubi->rsvd_pebs += i;
-               ubi->beb_rsvd_pebs += i;
-               if (i > 0)
-                       ubi_msg("reserve more %d PEBs", i);
-       }
-       ubi->vol_count -= 1;
-
-       return 0;
-out_err:
-       ubi_err(ubi, "cannot remove volume %s, error %d", volume, err);
-       if (err < 0)
-               err = -err;
-       return err;
-}
-
-static int ubi_volume_continue_write(char *volume, void *buf, size_t size)
-{
-       int err = 1;
-       struct ubi_volume *vol;
-
-       vol = ubi_find_volume(volume);
-       if (vol == NULL)
-               return ENODEV;
-
-       err = ubi_more_update_data(ubi, vol, buf, size);
-       if (err < 0) {
-               printf("Couldnt or partially wrote data\n");
-               return -err;
-       }
-
-       if (err) {
-               size = err;
-
-               err = ubi_check_volume(ubi, vol->vol_id);
-               if (err < 0)
-                       return -err;
-
-               if (err) {
-                       ubi_warn(ubi, "volume %d on UBI device %d is corrupt",
-                                vol->vol_id, ubi->ubi_num);
-                       vol->corrupted = 1;
-               }
-
-               vol->checked = 1;
-               ubi_gluebi_updated(vol);
-       }
-
-       return 0;
-}
-
-int ubi_volume_begin_write(char *volume, void *buf, size_t size,
-       size_t full_size)
-{
-       int err = 1;
-       int rsvd_bytes = 0;
-       struct ubi_volume *vol;
-
-       vol = ubi_find_volume(volume);
-       if (vol == NULL)
-               return ENODEV;
-
-       rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad);
-       if (size < 0 || size > rsvd_bytes) {
-               printf("size > volume size! Aborting!\n");
-               return EINVAL;
-       }
-
-       err = ubi_start_update(ubi, vol, full_size);
-       if (err < 0) {
-               printf("Cannot start volume update\n");
-               return -err;
-       }
-
-       return ubi_volume_continue_write(volume, buf, size);
-}
-
-int ubi_volume_write(char *volume, void *buf, size_t size)
-{
-       return ubi_volume_begin_write(volume, buf, size, size);
-}
-
-int ubi_volume_read(char *volume, char *buf, size_t size)
-{
-       int err, lnum, off, len, tbuf_size;
-       void *tbuf;
-       unsigned long long tmp;
-       struct ubi_volume *vol;
-       loff_t offp = 0;
-
-       vol = ubi_find_volume(volume);
-       if (vol == NULL)
-               return ENODEV;
-
-       if (vol->updating) {
-               printf("updating");
-               return EBUSY;
-       }
-       if (vol->upd_marker) {
-               printf("damaged volume, update marker is set");
-               return EBADF;
-       }
-       if (offp == vol->used_bytes)
-               return 0;
-
-       if (size == 0) {
-               printf("No size specified -> Using max size (%lld)\n", vol->used_bytes);
-               size = vol->used_bytes;
-       }
-
-       if (vol->corrupted)
-               printf("read from corrupted volume %d", vol->vol_id);
-       if (offp + size > vol->used_bytes)
-               size = vol->used_bytes - offp;
-
-       tbuf_size = vol->usable_leb_size;
-       if (size < tbuf_size)
-               tbuf_size = ALIGN(size, ubi->min_io_size);
-       tbuf = malloc_cache_aligned(tbuf_size);
-       if (!tbuf) {
-               printf("NO MEM\n");
-               return ENOMEM;
-       }
-       len = size > tbuf_size ? tbuf_size : size;
-
-       tmp = offp;
-       off = do_div(tmp, vol->usable_leb_size);
-       lnum = tmp;
-       do {
-               if (off + len >= vol->usable_leb_size)
-                       len = vol->usable_leb_size - off;
-
-               err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0);
-               if (err) {
-                       printf("read err %x\n", err);
-                       err = -err;
-                       break;
-               }
-               off += len;
-               if (off == vol->usable_leb_size) {
-                       lnum += 1;
-                       off -= vol->usable_leb_size;
-               }
-
-               size -= len;
-               offp += len;
-
-               memcpy(buf, tbuf, len);
-
-               buf += len;
-               len = size > tbuf_size ? tbuf_size : size;
-       } while (size);
-
-       free(tbuf);
-       return err;
-}
-
-static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
-               const char *vid_header_offset)
-{
-       struct mtd_device *dev;
-       struct part_info *part;
-       struct mtd_partition mtd_part;
-       char ubi_mtd_param_buffer[80];
-       u8 pnum;
-       int err;
-
-       if (find_dev_and_part(ubidev, &dev, &pnum, &part) != 0)
-               return 1;
-
-       sprintf(buffer, "mtd=%d", pnum);
-       memset(&mtd_part, 0, sizeof(mtd_part));
-       mtd_part.name = buffer;
-       mtd_part.size = part->size;
-       mtd_part.offset = part->offset;
-       add_mtd_partitions(info, &mtd_part, 1);
-
-       strcpy(ubi_mtd_param_buffer, buffer);
-       if (vid_header_offset)
-               sprintf(ubi_mtd_param_buffer, "mtd=%d,%s", pnum,
-                               vid_header_offset);
-       err = ubi_mtd_param_parse(ubi_mtd_param_buffer, NULL);
-       if (err) {
-               del_mtd_partitions(info);
-               return -err;
-       }
-
-       err = ubi_init();
-       if (err) {
-               del_mtd_partitions(info);
-               return -err;
-       }
-
-       ubi_initialized = 1;
-
-       return 0;
-}
-
-int ubi_part(char *part_name, const char *vid_header_offset)
-{
-       int err = 0;
-       char mtd_dev[16];
-       struct mtd_device *dev;
-       struct part_info *part;
-       u8 pnum;
-
-       if (mtdparts_init() != 0) {
-               printf("Error initializing mtdparts!\n");
-               return 1;
-       }
-
-#ifdef CONFIG_CMD_UBIFS
-       /*
-        * Automatically unmount UBIFS partition when user
-        * changes the UBI device. Otherwise the following
-        * UBIFS commands will crash.
-        */
-       if (ubifs_is_mounted())
-               cmd_ubifs_umount();
-#endif
-
-       /* todo: get dev number for NAND... */
-       ubi_dev.nr = 0;
-
-       /*
-        * Call ubi_exit() before re-initializing the UBI subsystem
-        */
-       if (ubi_initialized) {
-               ubi_exit();
-               del_mtd_partitions(ubi_dev.mtd_info);
-       }
-
-       /*
-        * Search the mtd device number where this partition
-        * is located
-        */
-       if (find_dev_and_part(part_name, &dev, &pnum, &part)) {
-               printf("Partition %s not found!\n", part_name);
-               return 1;
-       }
-       sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(dev->id->type), dev->id->num);
-       ubi_dev.mtd_info = get_mtd_device_nm(mtd_dev);
-       if (IS_ERR(ubi_dev.mtd_info)) {
-               printf("Partition %s not found on device %s!\n", part_name,
-                      mtd_dev);
-               return 1;
-       }
-
-       ubi_dev.selected = 1;
-
-       strcpy(ubi_dev.part_name, part_name);
-       err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name,
-                       vid_header_offset);
-       if (err) {
-               printf("UBI init error %d\n", err);
-               ubi_dev.selected = 0;
-               return err;
-       }
-
-       ubi = ubi_devices[0];
-
-       return 0;
-}
-
-static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       int64_t size = 0;
-       ulong addr = 0;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (strcmp(argv[1], "part") == 0) {
-               const char *vid_header_offset = NULL;
-
-               /* Print current partition */
-               if (argc == 2) {
-                       if (!ubi_dev.selected) {
-                               printf("Error, no UBI device/partition selected!\n");
-                               return 1;
-                       }
-
-                       printf("Device %d: %s, partition %s\n",
-                              ubi_dev.nr, ubi_dev.mtd_info->name, ubi_dev.part_name);
-                       return 0;
-               }
-
-               if (argc < 3)
-                       return CMD_RET_USAGE;
-
-               if (argc > 3)
-                       vid_header_offset = argv[3];
-
-               return ubi_part(argv[2], vid_header_offset);
-       }
-
-       if ((strcmp(argv[1], "part") != 0) && (!ubi_dev.selected)) {
-               printf("Error, no UBI device/partition selected!\n");
-               return 1;
-       }
-
-       if (strcmp(argv[1], "info") == 0) {
-               int layout = 0;
-               if (argc > 2 && !strncmp(argv[2], "l", 1))
-                       layout = 1;
-               return ubi_info(layout);
-       }
-
-       if (strcmp(argv[1], "check") == 0) {
-               if (argc > 2)
-                       return ubi_check(argv[2]);
-
-               printf("Error, no volume name passed\n");
-               return 1;
-       }
-
-       if (strncmp(argv[1], "create", 6) == 0) {
-               int dynamic = 1;        /* default: dynamic volume */
-
-               /* Use maximum available size */
-               size = 0;
-
-               /* E.g., create volume size type */
-               if (argc == 5) {
-                       if (strncmp(argv[4], "s", 1) == 0)
-                               dynamic = 0;
-                       else if (strncmp(argv[4], "d", 1) != 0) {
-                               printf("Incorrect type\n");
-                               return 1;
-                       }
-                       argc--;
-               }
-               /* E.g., create volume size */
-               if (argc == 4) {
-                       size = simple_strtoull(argv[3], NULL, 16);
-                       argc--;
-               }
-               /* Use maximum available size */
-               if (!size) {
-                       size = (int64_t)ubi->avail_pebs * ubi->leb_size;
-                       printf("No size specified -> Using max size (%lld)\n", size);
-               }
-               /* E.g., create volume */
-               if (argc == 3)
-                       return ubi_create_vol(argv[2], size, dynamic);
-       }
-
-       if (strncmp(argv[1], "remove", 6) == 0) {
-               /* E.g., remove volume */
-               if (argc == 3)
-                       return ubi_remove_vol(argv[2]);
-       }
-
-       if (strncmp(argv[1], "write", 5) == 0) {
-               int ret;
-
-               if (argc < 5) {
-                       printf("Please see usage\n");
-                       return 1;
-               }
-
-               addr = simple_strtoul(argv[2], NULL, 16);
-               size = simple_strtoul(argv[4], NULL, 16);
-
-               if (strlen(argv[1]) == 10 &&
-                   strncmp(argv[1] + 5, ".part", 5) == 0) {
-                       if (argc < 6) {
-                               ret = ubi_volume_continue_write(argv[3],
-                                               (void *)addr, size);
-                       } else {
-                               size_t full_size;
-                               full_size = simple_strtoul(argv[5], NULL, 16);
-                               ret = ubi_volume_begin_write(argv[3],
-                                               (void *)addr, size, full_size);
-                       }
-               } else {
-                       ret = ubi_volume_write(argv[3], (void *)addr, size);
-               }
-               if (!ret) {
-                       printf("%lld bytes written to volume %s\n", size,
-                              argv[3]);
-               }
-
-               return ret;
-       }
-
-       if (strncmp(argv[1], "read", 4) == 0) {
-               size = 0;
-
-               /* E.g., read volume size */
-               if (argc == 5) {
-                       size = simple_strtoul(argv[4], NULL, 16);
-                       argc--;
-               }
-
-               /* E.g., read volume */
-               if (argc == 4) {
-                       addr = simple_strtoul(argv[2], NULL, 16);
-                       argc--;
-               }
-
-               if (argc == 3) {
-                       printf("Read %lld bytes from volume %s to %lx\n", size,
-                              argv[3], addr);
-
-                       return ubi_volume_read(argv[3], (char *)addr, size);
-               }
-       }
-
-       printf("Please see usage\n");
-       return 1;
-}
-
-U_BOOT_CMD(
-       ubi, 6, 1, do_ubi,
-       "ubi commands",
-       "part [part] [offset]\n"
-               " - Show or set current partition (with optional VID"
-               " header offset)\n"
-       "ubi info [l[ayout]]"
-               " - Display volume and ubi layout information\n"
-       "ubi check volumename"
-               " - check if volumename exists\n"
-       "ubi create[vol] volume [size] [type]"
-               " - create volume name with size\n"
-       "ubi write[vol] address volume size"
-               " - Write volume from address with size\n"
-       "ubi write.part address volume size [fullsize]\n"
-               " - Write part of a volume from address\n"
-       "ubi read[vol] address volume [size]"
-               " - Read volume to address with size\n"
-       "ubi remove[vol] volume"
-               " - Remove volume\n"
-       "[Legends]\n"
-       " volume: character name\n"
-       " size: specified in bytes\n"
-       " type: s[tatic] or d[ynamic] (default=dynamic)"
-);
diff --git a/common/cmd_ubifs.c b/common/cmd_ubifs.c
deleted file mode 100644 (file)
index 5e9d357..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * (C) Copyright 2008
- * Stefan Roese, DENX Software Engineering, sr@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-
-/*
- * UBIFS command support
- */
-
-#undef DEBUG
-
-#include <common.h>
-#include <config.h>
-#include <command.h>
-#include <ubifs_uboot.h>
-
-static int ubifs_initialized;
-static int ubifs_mounted;
-
-static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       char *vol_name;
-       int ret;
-
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       vol_name = argv[1];
-       debug("Using volume %s\n", vol_name);
-
-       if (ubifs_initialized == 0) {
-               ubifs_init();
-               ubifs_initialized = 1;
-       }
-
-       ret = uboot_ubifs_mount(vol_name);
-       if (ret)
-               return -1;
-
-       ubifs_mounted = 1;
-
-       return 0;
-}
-
-int ubifs_is_mounted(void)
-{
-       return ubifs_mounted;
-}
-
-void cmd_ubifs_umount(void)
-{
-       uboot_ubifs_umount();
-       ubifs_mounted = 0;
-       ubifs_initialized = 0;
-}
-
-static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       if (argc != 1)
-               return CMD_RET_USAGE;
-
-       if (ubifs_initialized == 0) {
-               printf("No UBIFS volume mounted!\n");
-               return -1;
-       }
-
-       cmd_ubifs_umount();
-
-       return 0;
-}
-
-static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
-{
-       char *filename = "/";
-       int ret;
-
-       if (!ubifs_mounted) {
-               printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
-               return -1;
-       }
-
-       if (argc == 2)
-               filename = argv[1];
-       debug("Using filename %s\n", filename);
-
-       ret = ubifs_ls(filename);
-       if (ret) {
-               printf("** File not found %s **\n", filename);
-               ret = CMD_RET_FAILURE;
-       }
-
-       return ret;
-}
-
-static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
-                               char * const argv[])
-{
-       char *filename;
-       char *endp;
-       int ret;
-       u32 addr;
-       u32 size = 0;
-
-       if (!ubifs_mounted) {
-               printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
-               return -1;
-       }
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       addr = simple_strtoul(argv[1], &endp, 16);
-       if (endp == argv[1])
-               return CMD_RET_USAGE;
-
-       filename = argv[2];
-
-       if (argc == 4) {
-               size = simple_strtoul(argv[3], &endp, 16);
-               if (endp == argv[3])
-                       return CMD_RET_USAGE;
-       }
-       debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
-
-       ret = ubifs_load(filename, addr, size);
-       if (ret) {
-               printf("** File not found %s **\n", filename);
-               ret = CMD_RET_FAILURE;
-       }
-
-       return ret;
-}
-
-U_BOOT_CMD(
-       ubifsmount, 2, 0, do_ubifs_mount,
-       "mount UBIFS volume",
-       "<volume-name>\n"
-       "    - mount 'volume-name' volume"
-);
-
-U_BOOT_CMD(
-       ubifsumount, 1, 0, do_ubifs_umount,
-       "unmount UBIFS volume",
-       "    - unmount current volume"
-);
-
-U_BOOT_CMD(
-       ubifsls, 2, 0, do_ubifs_ls,
-       "list files in a directory",
-       "[directory]\n"
-       "    - list files in a 'directory' (default '/')"
-);
-
-U_BOOT_CMD(
-       ubifsload, 4, 0, do_ubifs_load,
-       "load file from an UBIFS filesystem",
-       "<addr> <filename> [bytes]\n"
-       "    - load file 'filename' to address 'addr'"
-);
diff --git a/common/cmd_universe.c b/common/cmd_universe.c
deleted file mode 100644 (file)
index c931036..0000000
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <malloc.h>
-#include <asm/io.h>
-#include <pci.h>
-
-#include <universe.h>
-
-#define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
-#define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
-
-
-typedef struct _UNI_DEV UNI_DEV;
-
-struct _UNI_DEV {
-       int            bus;
-       pci_dev_t      busdevfn;
-       UNIVERSE       *uregs;
-       unsigned int   pci_bs;
-};
-
-static UNI_DEV   *dev;
-
-
-int universe_init(void)
-{
-       int j, result;
-       pci_dev_t busdevfn;
-       unsigned int val;
-
-       busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
-       if (busdevfn == -1) {
-               puts("No Tundra Universe found!\n");
-               return -1;
-       }
-
-       /* Lets turn Latency off */
-       pci_write_config_dword(busdevfn, 0x0c, 0);
-
-       dev = malloc(sizeof(*dev));
-       if (NULL == dev) {
-               puts("UNIVERSE: No memory!\n");
-               result = -1;
-               goto break_20;
-       }
-
-       memset(dev, 0, sizeof(*dev));
-       dev->busdevfn = busdevfn;
-
-       pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
-       if (val & 1) {
-               pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val);
-       }
-       val &= ~0xf;
-       dev->uregs = (UNIVERSE *)val;
-
-       debug ("UNIVERSE-Base    : %p\n", dev->uregs);
-
-       /* check mapping  */
-       debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
-       if (((PCI_DEVICE <<16) | PCI_VENDOR) !=  readl(&dev->uregs->pci_id)) {
-               printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
-                       readl(&dev->uregs->pci_id));
-               result = -1;
-               goto break_30;
-       }
-
-       debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
-
-       dev->pci_bs = readl(&dev->uregs->pci_bs);
-
-       /* turn off windows */
-       for (j=0; j <4; j ++) {
-               writel(0x00800000, &dev->uregs->lsi[j].ctl);
-               writel(0x00800000, &dev->uregs->vsi[j].ctl);
-       }
-
-       /*
-        * Write to Misc Register
-        * Set VME Bus Time-out
-        *   Arbitration Mode
-        *   DTACK Enable
-        */
-       writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl);
-
-       if (readl(&dev->uregs->misc_ctl) & 0x00020000) {
-               debug ("System Controller!\n"); /* test-only */
-       } else {
-               debug ("Not System Controller!\n"); /* test-only */
-       }
-
-       /*
-        * Lets turn off interrupts
-        */
-       writel(0x00000000,&dev->uregs->lint_en);   /* Disable interrupts in the Universe first */
-       writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
-       eieio();
-       writel(0x0000, &dev->uregs->lint_map0);  /* Map all ints to 0 */
-       writel(0x0000, &dev->uregs->lint_map1);  /* Map all ints to 0 */
-       eieio();
-
-       return 0;
-
- break_30:
-       free(dev);
- break_20:
-       return result;
-}
-
-
-/*
- * Create pci slave window (access: pci -> vme)
- */
-int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
-{
-       int result, i;
-       unsigned int ctl = 0;
-
-       if (NULL == dev) {
-               result = -1;
-               goto exit_10;
-       }
-
-       for (i = 0; i < 4; i++) {
-               if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
-                       break;
-       }
-
-       if (i == 4) {
-               printf ("universe: No Image available\n");
-               result = -1;
-               goto exit_10;
-       }
-
-       debug ("universe: Using image %d\n", i);
-
-       writel(pciAddr , &dev->uregs->lsi[i].bs);
-       writel((pciAddr + size), &dev->uregs->lsi[i].bd);
-       writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
-
-       switch (vam & VME_AM_Axx) {
-       case VME_AM_A16:
-               ctl = 0x00000000;
-               break;
-       case VME_AM_A24:
-               ctl = 0x00010000;
-               break;
-       case VME_AM_A32:
-               ctl = 0x00020000;
-               break;
-       }
-
-       switch (vam & VME_AM_Mxx) {
-       case VME_AM_DATA:
-               ctl |= 0x00000000;
-               break;
-       case VME_AM_PROG:
-               ctl |= 0x00008000;
-               break;
-       }
-
-       if (vam & VME_AM_SUP) {
-               ctl |= 0x00001000;
-
-       }
-
-       switch (vdw & VME_FLAG_Dxx) {
-       case VME_FLAG_D8:
-               ctl |= 0x00000000;
-               break;
-       case VME_FLAG_D16:
-               ctl |= 0x00400000;
-               break;
-       case VME_FLAG_D32:
-               ctl |= 0x00800000;
-               break;
-       }
-
-       switch (pms & PCI_MS_Mxx) {
-       case PCI_MS_MEM:
-               ctl |= 0x00000000;
-               break;
-       case PCI_MS_IO:
-               ctl |= 0x00000001;
-               break;
-       case PCI_MS_CONFIG:
-               ctl |= 0x00000002;
-               break;
-       }
-
-       ctl |= 0x80000000;    /* enable */
-
-       writel(ctl, &dev->uregs->lsi[i].ctl);
-
-       debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
-       debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
-       debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
-       debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
-       debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
-
-       return 0;
-
- exit_10:
-       return -result;
-}
-
-
-/*
- * Create vme slave window (access: vme -> pci)
- */
-int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
-{
-       int result, i;
-       unsigned int ctl = 0;
-
-       if (NULL == dev) {
-               result = -1;
-               goto exit_10;
-       }
-
-       for (i = 0; i < 4; i++) {
-               if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
-                       break;
-       }
-
-       if (i == 4) {
-               printf ("universe: No Image available\n");
-               result = -1;
-               goto exit_10;
-       }
-
-       debug ("universe: Using image %d\n", i);
-
-       writel(vmeAddr , &dev->uregs->vsi[i].bs);
-       writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
-       writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
-
-       switch (vam & VME_AM_Axx) {
-       case VME_AM_A16:
-               ctl = 0x00000000;
-               break;
-       case VME_AM_A24:
-               ctl = 0x00010000;
-               break;
-       case VME_AM_A32:
-               ctl = 0x00020000;
-               break;
-       }
-
-       switch (vam & VME_AM_Mxx) {
-       case VME_AM_DATA:
-               ctl |= 0x00000000;
-               break;
-       case VME_AM_PROG:
-               ctl |= 0x00800000;
-               break;
-       }
-
-       if (vam & VME_AM_SUP) {
-               ctl |= 0x00100000;
-
-       }
-
-       switch (pms & PCI_MS_Mxx) {
-       case PCI_MS_MEM:
-               ctl |= 0x00000000;
-               break;
-       case PCI_MS_IO:
-               ctl |= 0x00000001;
-               break;
-       case PCI_MS_CONFIG:
-               ctl |= 0x00000002;
-               break;
-       }
-
-       ctl |= 0x80f00000;    /* enable */
-
-       writel(ctl, &dev->uregs->vsi[i].ctl);
-
-       debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
-       debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
-       debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
-       debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
-       debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
-
-       return 0;
-
- exit_10:
-       return -result;
-}
-
-
-/*
- * Tundra Universe configuration
- */
-int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
-       char cmd = 'x';
-
-       /* get parameter */
-       if (argc > 1)
-               cmd = argv[1][0];
-       if (argc > 2)
-               addr1 = simple_strtoul(argv[2], NULL, 16);
-       if (argc > 3)
-               addr2 = simple_strtoul(argv[3], NULL, 16);
-       if (argc > 4)
-               size = simple_strtoul(argv[4], NULL, 16);
-       if (argc > 5)
-               vam = simple_strtoul(argv[5], NULL, 16);
-       if (argc > 6)
-               pms = simple_strtoul(argv[6], NULL, 16);
-       if (argc > 7)
-               vdw = simple_strtoul(argv[7], NULL, 16);
-
-       switch (cmd) {
-       case 'i':               /* init */
-               universe_init();
-               break;
-       case 'v':               /* vme */
-               printf("Configuring Universe VME Slave Window (VME->PCI):\n");
-               printf("  vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
-                      addr1, addr2, size, vam, pms);
-               universe_vme_slave_window(addr1, addr2, size, vam, pms);
-               break;
-       case 'p':               /* pci */
-               printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
-               printf("  pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
-                      addr1, addr2, size, vam, pms, vdw);
-               universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
-               break;
-       default:
-               printf("Universe command %s not supported!\n", argv[1]);
-       }
-
-       return 0;
-}
-
-
-U_BOOT_CMD(
-       universe,       8,      1,      do_universe,
-       "initialize and configure Turndra Universe",
-       "init\n"
-       "    - initialize universe\n"
-       "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
-       "    - create vme slave window (access: vme->pci)\n"
-       "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
-       "    - create pci slave window (access: pci->vme)\n"
-       "    [vam] = VMEbus Address-Modifier:  01 -> A16 Address Space\n"
-       "                                      02 -> A24 Address Space\n"
-       "                                      03 -> A32 Address Space\n"
-       "                                      04 -> Supervisor AM Code\n"
-       "                                      10 -> Data AM Code\n"
-       "                                      20 -> Program AM Code\n"
-       "    [pms] = PCI Memory Space:         01 -> Memory Space\n"
-       "                                      02 -> I/O Space\n"
-       "                                      03 -> Configuration Space\n"
-       "    [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
-       "                                      02 -> D16 Data Width\n"
-       "                                      03 -> D32 Data Width"
-);
diff --git a/common/cmd_unzip.c b/common/cmd_unzip.c
deleted file mode 100644 (file)
index 0686be6..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long src, dst;
-       unsigned long src_len = ~0UL, dst_len = ~0UL;
-
-       switch (argc) {
-               case 4:
-                       dst_len = simple_strtoul(argv[3], NULL, 16);
-                       /* fall through */
-               case 3:
-                       src = simple_strtoul(argv[1], NULL, 16);
-                       dst = simple_strtoul(argv[2], NULL, 16);
-                       break;
-               default:
-                       return CMD_RET_USAGE;
-       }
-
-       if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
-               return 1;
-
-       printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
-       setenv_hex("filesize", src_len);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       unzip,  4,      1,      do_unzip,
-       "unzip a memory region",
-       "srcaddr dstaddr [dstsize]"
-);
-
-static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
-                     int argc, char * const argv[])
-{
-       block_dev_desc_t *bdev;
-       int ret;
-       unsigned char *addr;
-       unsigned long length;
-       unsigned long writebuf = 1<<20;
-       u64 startoffs = 0;
-       u64 szexpected = 0;
-
-       if (argc < 5)
-               return CMD_RET_USAGE;
-       ret = get_device(argv[1], argv[2], &bdev);
-       if (ret < 0)
-               return CMD_RET_FAILURE;
-
-       addr = (unsigned char *)simple_strtoul(argv[3], NULL, 16);
-       length = simple_strtoul(argv[4], NULL, 16);
-
-       if (5 < argc) {
-               writebuf = simple_strtoul(argv[5], NULL, 16);
-               if (6 < argc) {
-                       startoffs = simple_strtoull(argv[6], NULL, 16);
-                       if (7 < argc)
-                               szexpected = simple_strtoull(argv[7],
-                                                            NULL, 16);
-               }
-       }
-
-       ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
-
-       return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
-}
-
-U_BOOT_CMD(
-       gzwrite, 8, 0, do_gzwrite,
-       "unzip and write memory to block device",
-       "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
-       "\twbuf is the size in bytes (hex) of write buffer\n"
-       "\t\tand should be padded to erase size for SSDs\n"
-       "\toffs is the output start offset in bytes (hex)\n"
-       "\toutsize is the size of the expected output (hex bytes)\n"
-       "\t\tand is required for files with uncompressed lengths\n"
-       "\t\t4 GiB or larger\n"
-);
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
deleted file mode 100644 (file)
index c7b642c..0000000
+++ /dev/null
@@ -1,853 +0,0 @@
-/*
- * (C) Copyright 2001
- * Denis Peter, MPL AG Switzerland
- *
- * Adapted for U-Boot driver model
- * (C) Copyright 2015 Google, Inc
- *
- * Most of this source has been derived from the Linux USB
- * project.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <dm.h>
-#include <memalign.h>
-#include <asm/byteorder.h>
-#include <asm/unaligned.h>
-#include <part.h>
-#include <usb.h>
-
-#ifdef CONFIG_USB_STORAGE
-static int usb_stor_curr_dev = -1; /* current device */
-#endif
-#if defined(CONFIG_USB_HOST_ETHER) && !defined(CONFIG_DM_ETH)
-static int __maybe_unused usb_ether_curr_dev = -1; /* current ethernet device */
-#endif
-
-/* some display routines (info command) */
-static char *usb_get_class_desc(unsigned char dclass)
-{
-       switch (dclass) {
-       case USB_CLASS_PER_INTERFACE:
-               return "See Interface";
-       case USB_CLASS_AUDIO:
-               return "Audio";
-       case USB_CLASS_COMM:
-               return "Communication";
-       case USB_CLASS_HID:
-               return "Human Interface";
-       case USB_CLASS_PRINTER:
-               return "Printer";
-       case USB_CLASS_MASS_STORAGE:
-               return "Mass Storage";
-       case USB_CLASS_HUB:
-               return "Hub";
-       case USB_CLASS_DATA:
-               return "CDC Data";
-       case USB_CLASS_VENDOR_SPEC:
-               return "Vendor specific";
-       default:
-               return "";
-       }
-}
-
-static void usb_display_class_sub(unsigned char dclass, unsigned char subclass,
-                                 unsigned char proto)
-{
-       switch (dclass) {
-       case USB_CLASS_PER_INTERFACE:
-               printf("See Interface");
-               break;
-       case USB_CLASS_HID:
-               printf("Human Interface, Subclass: ");
-               switch (subclass) {
-               case USB_SUB_HID_NONE:
-                       printf("None");
-                       break;
-               case USB_SUB_HID_BOOT:
-                       printf("Boot ");
-                       switch (proto) {
-                       case USB_PROT_HID_NONE:
-                               printf("None");
-                               break;
-                       case USB_PROT_HID_KEYBOARD:
-                               printf("Keyboard");
-                               break;
-                       case USB_PROT_HID_MOUSE:
-                               printf("Mouse");
-                               break;
-                       default:
-                               printf("reserved");
-                               break;
-                       }
-                       break;
-               default:
-                       printf("reserved");
-                       break;
-               }
-               break;
-       case USB_CLASS_MASS_STORAGE:
-               printf("Mass Storage, ");
-               switch (subclass) {
-               case US_SC_RBC:
-                       printf("RBC ");
-                       break;
-               case US_SC_8020:
-                       printf("SFF-8020i (ATAPI)");
-                       break;
-               case US_SC_QIC:
-                       printf("QIC-157 (Tape)");
-                       break;
-               case US_SC_UFI:
-                       printf("UFI");
-                       break;
-               case US_SC_8070:
-                       printf("SFF-8070");
-                       break;
-               case US_SC_SCSI:
-                       printf("Transp. SCSI");
-                       break;
-               default:
-                       printf("reserved");
-                       break;
-               }
-               printf(", ");
-               switch (proto) {
-               case US_PR_CB:
-                       printf("Command/Bulk");
-                       break;
-               case US_PR_CBI:
-                       printf("Command/Bulk/Int");
-                       break;
-               case US_PR_BULK:
-                       printf("Bulk only");
-                       break;
-               default:
-                       printf("reserved");
-                       break;
-               }
-               break;
-       default:
-               printf("%s", usb_get_class_desc(dclass));
-               break;
-       }
-}
-
-static void usb_display_string(struct usb_device *dev, int index)
-{
-       ALLOC_CACHE_ALIGN_BUFFER(char, buffer, 256);
-
-       if (index != 0) {
-               if (usb_string(dev, index, &buffer[0], 256) > 0)
-                       printf("String: \"%s\"", buffer);
-       }
-}
-
-static void usb_display_desc(struct usb_device *dev)
-{
-       if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) {
-               printf("%d: %s,  USB Revision %x.%x\n", dev->devnum,
-               usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass),
-                                  (dev->descriptor.bcdUSB>>8) & 0xff,
-                                  dev->descriptor.bcdUSB & 0xff);
-
-               if (strlen(dev->mf) || strlen(dev->prod) ||
-                   strlen(dev->serial))
-                       printf(" - %s %s %s\n", dev->mf, dev->prod,
-                               dev->serial);
-               if (dev->descriptor.bDeviceClass) {
-                       printf(" - Class: ");
-                       usb_display_class_sub(dev->descriptor.bDeviceClass,
-                                             dev->descriptor.bDeviceSubClass,
-                                             dev->descriptor.bDeviceProtocol);
-                       printf("\n");
-               } else {
-                       printf(" - Class: (from Interface) %s\n",
-                              usb_get_class_desc(
-                               dev->config.if_desc[0].desc.bInterfaceClass));
-               }
-               printf(" - PacketSize: %d  Configurations: %d\n",
-                       dev->descriptor.bMaxPacketSize0,
-                       dev->descriptor.bNumConfigurations);
-               printf(" - Vendor: 0x%04x  Product 0x%04x Version %d.%d\n",
-                       dev->descriptor.idVendor, dev->descriptor.idProduct,
-                       (dev->descriptor.bcdDevice>>8) & 0xff,
-                       dev->descriptor.bcdDevice & 0xff);
-       }
-
-}
-
-static void usb_display_conf_desc(struct usb_config_descriptor *config,
-                                 struct usb_device *dev)
-{
-       printf("   Configuration: %d\n", config->bConfigurationValue);
-       printf("   - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
-              (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
-              (config->bmAttributes & 0x20) ? "Remote Wakeup " : "",
-               config->bMaxPower*2);
-       if (config->iConfiguration) {
-               printf("   - ");
-               usb_display_string(dev, config->iConfiguration);
-               printf("\n");
-       }
-}
-
-static void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,
-                               struct usb_device *dev)
-{
-       printf("     Interface: %d\n", ifdesc->bInterfaceNumber);
-       printf("     - Alternate Setting %d, Endpoints: %d\n",
-               ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
-       printf("     - Class ");
-       usb_display_class_sub(ifdesc->bInterfaceClass,
-               ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol);
-       printf("\n");
-       if (ifdesc->iInterface) {
-               printf("     - ");
-               usb_display_string(dev, ifdesc->iInterface);
-               printf("\n");
-       }
-}
-
-static void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
-{
-       printf("     - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf,
-               (epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
-       switch ((epdesc->bmAttributes & 0x03)) {
-       case 0:
-               printf("Control");
-               break;
-       case 1:
-               printf("Isochronous");
-               break;
-       case 2:
-               printf("Bulk");
-               break;
-       case 3:
-               printf("Interrupt");
-               break;
-       }
-       printf(" MaxPacket %d", get_unaligned(&epdesc->wMaxPacketSize));
-       if ((epdesc->bmAttributes & 0x03) == 0x3)
-               printf(" Interval %dms", epdesc->bInterval);
-       printf("\n");
-}
-
-/* main routine to diasplay the configs, interfaces and endpoints */
-static void usb_display_config(struct usb_device *dev)
-{
-       struct usb_config *config;
-       struct usb_interface *ifdesc;
-       struct usb_endpoint_descriptor *epdesc;
-       int i, ii;
-
-       config = &dev->config;
-       usb_display_conf_desc(&config->desc, dev);
-       for (i = 0; i < config->no_of_if; i++) {
-               ifdesc = &config->if_desc[i];
-               usb_display_if_desc(&ifdesc->desc, dev);
-               for (ii = 0; ii < ifdesc->no_of_ep; ii++) {
-                       epdesc = &ifdesc->ep_desc[ii];
-                       usb_display_ep_desc(epdesc);
-               }
-       }
-       printf("\n");
-}
-
-/*
- * With driver model this isn't right since we can have multiple controllers
- * and the device numbering starts at 1 on each bus.
- * TODO(sjg@chromium.org): Add a way to specify the controller/bus.
- */
-static struct usb_device *usb_find_device(int devnum)
-{
-#ifdef CONFIG_DM_USB
-       struct usb_device *udev;
-       struct udevice *hub;
-       struct uclass *uc;
-       int ret;
-
-       /* Device addresses start at 1 */
-       devnum++;
-       ret = uclass_get(UCLASS_USB_HUB, &uc);
-       if (ret)
-               return NULL;
-
-       uclass_foreach_dev(hub, uc) {
-               struct udevice *dev;
-
-               if (!device_active(hub))
-                       continue;
-               udev = dev_get_parent_priv(hub);
-               if (udev->devnum == devnum)
-                       return udev;
-
-               for (device_find_first_child(hub, &dev);
-                    dev;
-                    device_find_next_child(&dev)) {
-                       if (!device_active(hub))
-                               continue;
-
-                       udev = dev_get_parent_priv(dev);
-                       if (udev->devnum == devnum)
-                               return udev;
-               }
-       }
-#else
-       struct usb_device *udev;
-       int d;
-
-       for (d = 0; d < USB_MAX_DEVICE; d++) {
-               udev = usb_get_dev_index(d);
-               if (udev == NULL)
-                       return NULL;
-               if (udev->devnum == devnum)
-                       return udev;
-       }
-#endif
-
-       return NULL;
-}
-
-static inline char *portspeed(int speed)
-{
-       char *speed_str;
-
-       switch (speed) {
-       case USB_SPEED_SUPER:
-               speed_str = "5 Gb/s";
-               break;
-       case USB_SPEED_HIGH:
-               speed_str = "480 Mb/s";
-               break;
-       case USB_SPEED_LOW:
-               speed_str = "1.5 Mb/s";
-               break;
-       default:
-               speed_str = "12 Mb/s";
-               break;
-       }
-
-       return speed_str;
-}
-
-/* shows the device tree recursively */
-static void usb_show_tree_graph(struct usb_device *dev, char *pre)
-{
-       int index;
-       int has_child, last_child;
-
-       index = strlen(pre);
-       printf(" %s", pre);
-#ifdef CONFIG_DM_USB
-       has_child = device_has_active_children(dev->dev);
-#else
-       /* check if the device has connected children */
-       int i;
-
-       has_child = 0;
-       for (i = 0; i < dev->maxchild; i++) {
-               if (dev->children[i] != NULL)
-                       has_child = 1;
-       }
-#endif
-       /* check if we are the last one */
-#ifdef CONFIG_DM_USB
-       /* Not the root of the usb tree? */
-       if (device_get_uclass_id(dev->dev->parent) != UCLASS_USB) {
-               last_child = device_is_last_sibling(dev->dev);
-#else
-       if (dev->parent != NULL) { /* not root? */
-               last_child = 1;
-               for (i = 0; i < dev->parent->maxchild; i++) {
-                       /* search for children */
-                       if (dev->parent->children[i] == dev) {
-                               /* found our pointer, see if we have a
-                                * little sister
-                                */
-                               while (i++ < dev->parent->maxchild) {
-                                       if (dev->parent->children[i] != NULL) {
-                                               /* found a sister */
-                                               last_child = 0;
-                                               break;
-                                       } /* if */
-                               } /* while */
-                       } /* device found */
-               } /* for all children of the parent */
-#endif
-               printf("\b+-");
-               /* correct last child */
-               if (last_child && index)
-                       pre[index-1] = ' ';
-       } /* if not root hub */
-       else
-               printf(" ");
-       printf("%d ", dev->devnum);
-       pre[index++] = ' ';
-       pre[index++] = has_child ? '|' : ' ';
-       pre[index] = 0;
-       printf(" %s (%s, %dmA)\n", usb_get_class_desc(
-                                       dev->config.if_desc[0].desc.bInterfaceClass),
-                                       portspeed(dev->speed),
-                                       dev->config.desc.bMaxPower * 2);
-       if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
-               printf(" %s  %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
-       printf(" %s\n", pre);
-#ifdef CONFIG_DM_USB
-       struct udevice *child;
-
-       for (device_find_first_child(dev->dev, &child);
-            child;
-            device_find_next_child(&child)) {
-               struct usb_device *udev;
-
-               if (!device_active(child))
-                       continue;
-
-               udev = dev_get_parent_priv(child);
-
-               /* Ignore emulators, we only want real devices */
-               if (device_get_uclass_id(child) != UCLASS_USB_EMUL) {
-                       usb_show_tree_graph(udev, pre);
-                       pre[index] = 0;
-               }
-       }
-#else
-       if (dev->maxchild > 0) {
-               for (i = 0; i < dev->maxchild; i++) {
-                       if (dev->children[i] != NULL) {
-                               usb_show_tree_graph(dev->children[i], pre);
-                               pre[index] = 0;
-                       }
-               }
-       }
-#endif
-}
-
-/* main routine for the tree command */
-static void usb_show_subtree(struct usb_device *dev)
-{
-       char preamble[32];
-
-       memset(preamble, '\0', sizeof(preamble));
-       usb_show_tree_graph(dev, &preamble[0]);
-}
-
-void usb_show_tree(void)
-{
-#ifdef CONFIG_DM_USB
-       struct udevice *bus;
-
-       for (uclass_first_device(UCLASS_USB, &bus);
-               bus;
-               uclass_next_device(&bus)) {
-               struct usb_device *udev;
-               struct udevice *dev;
-
-               device_find_first_child(bus, &dev);
-               if (dev && device_active(dev)) {
-                       udev = dev_get_parent_priv(dev);
-                       usb_show_subtree(udev);
-               }
-       }
-#else
-       struct usb_device *udev;
-       int i;
-
-       for (i = 0; i < USB_MAX_DEVICE; i++) {
-               udev = usb_get_dev_index(i);
-               if (udev == NULL)
-                       break;
-               if (udev->parent == NULL)
-                       usb_show_subtree(udev);
-       }
-#endif
-}
-
-static int usb_test(struct usb_device *dev, int port, char* arg)
-{
-       int mode;
-
-       if (port > dev->maxchild) {
-               printf("Device is no hub or does not have %d ports.\n", port);
-               return 1;
-       }
-
-       switch (arg[0]) {
-       case 'J':
-       case 'j':
-               printf("Setting Test_J mode");
-               mode = USB_TEST_MODE_J;
-               break;
-       case 'K':
-       case 'k':
-               printf("Setting Test_K mode");
-               mode = USB_TEST_MODE_K;
-               break;
-       case 'S':
-       case 's':
-               printf("Setting Test_SE0_NAK mode");
-               mode = USB_TEST_MODE_SE0_NAK;
-               break;
-       case 'P':
-       case 'p':
-               printf("Setting Test_Packet mode");
-               mode = USB_TEST_MODE_PACKET;
-               break;
-       case 'F':
-       case 'f':
-               printf("Setting Test_Force_Enable mode");
-               mode = USB_TEST_MODE_FORCE_ENABLE;
-               break;
-       default:
-               printf("Unrecognized test mode: %s\nAvailable modes: "
-                      "J, K, S[E0_NAK], P[acket], F[orce_Enable]\n", arg);
-               return 1;
-       }
-
-       if (port)
-               printf(" on downstream facing port %d...\n", port);
-       else
-               printf(" on upstream facing port...\n");
-
-       if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE,
-                           port ? USB_RT_PORT : USB_RECIP_DEVICE,
-                           port ? USB_PORT_FEAT_TEST : USB_FEAT_TEST,
-                           (mode << 8) | port,
-                           NULL, 0, USB_CNTL_TIMEOUT) == -1) {
-               printf("Error during SET_FEATURE.\n");
-               return 1;
-       } else {
-               printf("Test mode successfully set. Use 'usb start' "
-                      "to return to normal operation.\n");
-               return 0;
-       }
-}
-
-
-/******************************************************************************
- * usb boot command intepreter. Derived from diskboot
- */
-#ifdef CONFIG_USB_STORAGE
-static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return common_diskboot(cmdtp, "usb", argc, argv);
-}
-#endif /* CONFIG_USB_STORAGE */
-
-static int do_usb_stop_keyboard(int force)
-{
-#ifdef CONFIG_USB_KEYBOARD
-       if (usb_kbd_deregister(force) != 0) {
-               printf("USB not stopped: usbkbd still using USB\n");
-               return 1;
-       }
-#endif
-       return 0;
-}
-
-static void do_usb_start(void)
-{
-       bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
-
-       if (usb_init() < 0)
-               return;
-
-       /* Driver model will probe the devices as they are found */
-#ifndef CONFIG_DM_USB
-# ifdef CONFIG_USB_STORAGE
-       /* try to recognize storage devices immediately */
-       usb_stor_curr_dev = usb_stor_scan(1);
-# endif
-# ifdef CONFIG_USB_KEYBOARD
-       drv_usb_kbd_init();
-# endif
-#endif /* !CONFIG_DM_USB */
-#ifdef CONFIG_USB_HOST_ETHER
-# ifdef CONFIG_DM_ETH
-#  ifndef CONFIG_DM_USB
-#   error "You must use CONFIG_DM_USB if you want to use CONFIG_USB_HOST_ETHER with CONFIG_DM_ETH"
-#  endif
-# else
-       /* try to recognize ethernet devices immediately */
-       usb_ether_curr_dev = usb_host_eth_scan(1);
-# endif
-#endif
-}
-
-#ifdef CONFIG_DM_USB
-static void show_info(struct udevice *dev)
-{
-       struct udevice *child;
-       struct usb_device *udev;
-
-       udev = dev_get_parent_priv(dev);
-       usb_display_desc(udev);
-       usb_display_config(udev);
-       for (device_find_first_child(dev, &child);
-            child;
-            device_find_next_child(&child)) {
-               if (device_active(child))
-                       show_info(child);
-       }
-}
-
-static int usb_device_info(void)
-{
-       struct udevice *bus;
-
-       for (uclass_first_device(UCLASS_USB, &bus);
-            bus;
-            uclass_next_device(&bus)) {
-               struct udevice *hub;
-
-               device_find_first_child(bus, &hub);
-               if (device_get_uclass_id(hub) == UCLASS_USB_HUB &&
-                   device_active(hub)) {
-                       show_info(hub);
-               }
-       }
-
-       return 0;
-}
-#endif
-
-/******************************************************************************
- * usb command intepreter
- */
-static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       struct usb_device *udev = NULL;
-       int i;
-       extern char usb_started;
-#ifdef CONFIG_USB_STORAGE
-       block_dev_desc_t *stor_dev;
-#endif
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       if (strncmp(argv[1], "start", 5) == 0) {
-               if (usb_started)
-                       return 0; /* Already started */
-               printf("starting USB...\n");
-               do_usb_start();
-               return 0;
-       }
-
-       if (strncmp(argv[1], "reset", 5) == 0) {
-               printf("resetting USB...\n");
-               if (do_usb_stop_keyboard(1) != 0)
-                       return 1;
-               usb_stop();
-               do_usb_start();
-               return 0;
-       }
-       if (strncmp(argv[1], "stop", 4) == 0) {
-               if (argc != 2)
-                       console_assign(stdin, "serial");
-               if (do_usb_stop_keyboard(0) != 0)
-                       return 1;
-               printf("stopping USB..\n");
-               usb_stop();
-               return 0;
-       }
-       if (!usb_started) {
-               printf("USB is stopped. Please issue 'usb start' first.\n");
-               return 1;
-       }
-       if (strncmp(argv[1], "tree", 4) == 0) {
-               puts("USB device tree:\n");
-               usb_show_tree();
-               return 0;
-       }
-       if (strncmp(argv[1], "inf", 3) == 0) {
-               if (argc == 2) {
-#ifdef CONFIG_DM_USB
-                       usb_device_info();
-#else
-                       int d;
-                       for (d = 0; d < USB_MAX_DEVICE; d++) {
-                               udev = usb_get_dev_index(d);
-                               if (udev == NULL)
-                                       break;
-                               usb_display_desc(udev);
-                               usb_display_config(udev);
-                       }
-#endif
-                       return 0;
-               } else {
-                       /*
-                        * With driver model this isn't right since we can
-                        * have multiple controllers and the device numbering
-                        * starts at 1 on each bus.
-                        */
-                       i = simple_strtoul(argv[2], NULL, 10);
-                       printf("config for device %d\n", i);
-                       udev = usb_find_device(i);
-                       if (udev == NULL) {
-                               printf("*** No device available ***\n");
-                               return 0;
-                       } else {
-                               usb_display_desc(udev);
-                               usb_display_config(udev);
-                       }
-               }
-               return 0;
-       }
-       if (strncmp(argv[1], "test", 4) == 0) {
-               if (argc < 5)
-                       return CMD_RET_USAGE;
-               i = simple_strtoul(argv[2], NULL, 10);
-               udev = usb_find_device(i);
-               if (udev == NULL) {
-                       printf("Device %d does not exist.\n", i);
-                       return 1;
-               }
-               i = simple_strtoul(argv[3], NULL, 10);
-               return usb_test(udev, i, argv[4]);
-       }
-#ifdef CONFIG_USB_STORAGE
-       if (strncmp(argv[1], "stor", 4) == 0)
-               return usb_stor_info();
-
-       if (strncmp(argv[1], "part", 4) == 0) {
-               int devno, ok = 0;
-               if (argc == 2) {
-                       for (devno = 0; ; ++devno) {
-                               stor_dev = usb_stor_get_dev(devno);
-                               if (stor_dev == NULL)
-                                       break;
-                               if (stor_dev->type != DEV_TYPE_UNKNOWN) {
-                                       ok++;
-                                       if (devno)
-                                               printf("\n");
-                                       debug("print_part of %x\n", devno);
-                                       print_part(stor_dev);
-                               }
-                       }
-               } else {
-                       devno = simple_strtoul(argv[2], NULL, 16);
-                       stor_dev = usb_stor_get_dev(devno);
-                       if (stor_dev != NULL &&
-                           stor_dev->type != DEV_TYPE_UNKNOWN) {
-                               ok++;
-                               debug("print_part of %x\n", devno);
-                               print_part(stor_dev);
-                       }
-               }
-               if (!ok) {
-                       printf("\nno USB devices available\n");
-                       return 1;
-               }
-               return 0;
-       }
-       if (strcmp(argv[1], "read") == 0) {
-               if (usb_stor_curr_dev < 0) {
-                       printf("no current device selected\n");
-                       return 1;
-               }
-               if (argc == 5) {
-                       unsigned long addr = simple_strtoul(argv[2], NULL, 16);
-                       unsigned long blk  = simple_strtoul(argv[3], NULL, 16);
-                       unsigned long cnt  = simple_strtoul(argv[4], NULL, 16);
-                       unsigned long n;
-                       printf("\nUSB read: device %d block # %ld, count %ld"
-                               " ... ", usb_stor_curr_dev, blk, cnt);
-                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
-                       n = stor_dev->block_read(stor_dev, blk, cnt,
-                                                (ulong *)addr);
-                       printf("%ld blocks read: %s\n", n,
-                               (n == cnt) ? "OK" : "ERROR");
-                       if (n == cnt)
-                               return 0;
-                       return 1;
-               }
-       }
-       if (strcmp(argv[1], "write") == 0) {
-               if (usb_stor_curr_dev < 0) {
-                       printf("no current device selected\n");
-                       return 1;
-               }
-               if (argc == 5) {
-                       unsigned long addr = simple_strtoul(argv[2], NULL, 16);
-                       unsigned long blk  = simple_strtoul(argv[3], NULL, 16);
-                       unsigned long cnt  = simple_strtoul(argv[4], NULL, 16);
-                       unsigned long n;
-                       printf("\nUSB write: device %d block # %ld, count %ld"
-                               " ... ", usb_stor_curr_dev, blk, cnt);
-                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
-                       n = stor_dev->block_write(stor_dev, blk, cnt,
-                                               (ulong *)addr);
-                       printf("%ld blocks write: %s\n", n,
-                               (n == cnt) ? "OK" : "ERROR");
-                       if (n == cnt)
-                               return 0;
-                       return 1;
-               }
-       }
-       if (strncmp(argv[1], "dev", 3) == 0) {
-               if (argc == 3) {
-                       int dev = (int)simple_strtoul(argv[2], NULL, 10);
-                       printf("\nUSB device %d: ", dev);
-                       stor_dev = usb_stor_get_dev(dev);
-                       if (stor_dev == NULL) {
-                               printf("unknown device\n");
-                               return 1;
-                       }
-                       printf("\n    Device %d: ", dev);
-                       dev_print(stor_dev);
-                       if (stor_dev->type == DEV_TYPE_UNKNOWN)
-                               return 1;
-                       usb_stor_curr_dev = dev;
-                       printf("... is now current device\n");
-                       return 0;
-               } else {
-                       printf("\nUSB device %d: ", usb_stor_curr_dev);
-                       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
-                       dev_print(stor_dev);
-                       if (stor_dev->type == DEV_TYPE_UNKNOWN)
-                               return 1;
-                       return 0;
-               }
-               return 0;
-       }
-#endif /* CONFIG_USB_STORAGE */
-       return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       usb,    5,      1,      do_usb,
-       "USB sub-system",
-       "start - start (scan) USB controller\n"
-       "usb reset - reset (rescan) USB controller\n"
-       "usb stop [f] - stop USB [f]=force stop\n"
-       "usb tree - show USB device tree\n"
-       "usb info [dev] - show available USB devices\n"
-       "usb test [dev] [port] [mode] - set USB 2.0 test mode\n"
-       "    (specify port 0 to indicate the device's upstream port)\n"
-       "    Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n"
-#ifdef CONFIG_USB_STORAGE
-       "usb storage - show details of USB storage devices\n"
-       "usb dev [dev] - show or set current USB storage device\n"
-       "usb part [dev] - print partition table of one or all USB storage"
-       "    devices\n"
-       "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
-       "    to memory address `addr'\n"
-       "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n"
-       "    from memory address `addr'"
-#endif /* CONFIG_USB_STORAGE */
-);
-
-
-#ifdef CONFIG_USB_STORAGE
-U_BOOT_CMD(
-       usbboot,        3,      1,      do_usbboot,
-       "boot from USB device",
-       "loadAddr dev:part"
-);
-#endif /* CONFIG_USB_STORAGE */
diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c
deleted file mode 100644 (file)
index 0415591..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2011 Samsung Electronics
- * Lukasz Majewski <l.majewski@samsung.com>
- *
- * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <errno.h>
-#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <g_dnl.h>
-#include <part.h>
-#include <usb.h>
-#include <usb_mass_storage.h>
-
-static int ums_read_sector(struct ums *ums_dev,
-                          ulong start, lbaint_t blkcnt, void *buf)
-{
-       block_dev_desc_t *block_dev = &ums_dev->block_dev;
-       lbaint_t blkstart = start + ums_dev->start_sector;
-
-       return block_dev->block_read(block_dev, blkstart, blkcnt, buf);
-}
-
-static int ums_write_sector(struct ums *ums_dev,
-                           ulong start, lbaint_t blkcnt, const void *buf)
-{
-       block_dev_desc_t *block_dev = &ums_dev->block_dev;
-       lbaint_t blkstart = start + ums_dev->start_sector;
-
-       return block_dev->block_write(block_dev, blkstart, blkcnt, buf);
-}
-
-static struct ums *ums;
-static int ums_count;
-
-static void ums_fini(void)
-{
-       int i;
-
-       for (i = 0; i < ums_count; i++)
-               free((void *)ums[i].name);
-       free(ums);
-       ums = 0;
-       ums_count = 0;
-}
-
-#define UMS_NAME_LEN 16
-
-static int ums_init(const char *devtype, const char *devnums)
-{
-       char *s, *t, *devnum, *name;
-       block_dev_desc_t *block_dev;
-       int ret;
-       struct ums *ums_new;
-
-       s = strdup(devnums);
-       if (!s)
-               return -1;
-
-       t = s;
-       ums_count = 0;
-
-       for (;;) {
-               devnum = strsep(&t, ",");
-               if (!devnum)
-                       break;
-
-               ret = get_device(devtype, devnum, &block_dev);
-               if (ret < 0)
-                       goto cleanup;
-
-               /* f_mass_storage.c assumes SECTOR_SIZE sectors */
-               if (block_dev->blksz != SECTOR_SIZE) {
-                       ret = -1;
-                       goto cleanup;
-               }
-
-               ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums));
-               if (!ums_new) {
-                       ret = -1;
-                       goto cleanup;
-               }
-               ums = ums_new;
-
-               ums[ums_count].read_sector = ums_read_sector;
-               ums[ums_count].write_sector = ums_write_sector;
-               ums[ums_count].start_sector = 0;
-               ums[ums_count].num_sectors = block_dev->lba;
-               name = malloc(UMS_NAME_LEN);
-               if (!name) {
-                       ret = -1;
-                       goto cleanup;
-               }
-               snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count);
-               ums[ums_count].name = name;
-               ums[ums_count].block_dev = *block_dev;
-
-               printf("UMS: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n",
-                      ums_count, ums[ums_count].block_dev.dev,
-                      ums[ums_count].block_dev.hwpart,
-                      ums[ums_count].start_sector,
-                      ums[ums_count].num_sectors);
-
-               ums_count++;
-       }
-
-       if (!ums_count)
-               ret = -1;
-       else
-               ret = 0;
-
-cleanup:
-       free(s);
-
-       if (ret < 0)
-               ums_fini();
-
-       return ret;
-}
-
-int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
-                              int argc, char * const argv[])
-{
-       const char *usb_controller;
-       const char *devtype;
-       const char *devnum;
-       unsigned int controller_index;
-       int rc;
-       int cable_ready_timeout __maybe_unused;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       usb_controller = argv[1];
-       if (argc >= 4) {
-               devtype = argv[2];
-               devnum  = argv[3];
-       } else {
-               devtype = "mmc";
-               devnum  = argv[2];
-       }
-
-       rc = ums_init(devtype, devnum);
-       if (rc < 0)
-               return CMD_RET_FAILURE;
-
-       controller_index = (unsigned int)(simple_strtoul(
-                               usb_controller, NULL, 0));
-       if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
-               error("Couldn't init USB controller.");
-               rc = CMD_RET_FAILURE;
-               goto cleanup_ums_init;
-       }
-
-       rc = fsg_init(ums, ums_count);
-       if (rc) {
-               error("fsg_init failed");
-               rc = CMD_RET_FAILURE;
-               goto cleanup_board;
-       }
-
-       rc = g_dnl_register("usb_dnl_ums");
-       if (rc) {
-               error("g_dnl_register failed");
-               rc = CMD_RET_FAILURE;
-               goto cleanup_board;
-       }
-
-       /* Timeout unit: seconds */
-       cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
-
-       if (!g_dnl_board_usb_cable_connected()) {
-               /*
-                * Won't execute if we don't know whether the cable is
-                * connected.
-                */
-               puts("Please connect USB cable.\n");
-
-               while (!g_dnl_board_usb_cable_connected()) {
-                       if (ctrlc()) {
-                               puts("\rCTRL+C - Operation aborted.\n");
-                               rc = CMD_RET_SUCCESS;
-                               goto cleanup_register;
-                       }
-                       if (!cable_ready_timeout) {
-                               puts("\rUSB cable not detected.\n" \
-                                    "Command exit.\n");
-                               rc = CMD_RET_SUCCESS;
-                               goto cleanup_register;
-                       }
-
-                       printf("\rAuto exit in: %.2d s.", cable_ready_timeout);
-                       mdelay(1000);
-                       cable_ready_timeout--;
-               }
-               puts("\r\n");
-       }
-
-       while (1) {
-               usb_gadget_handle_interrupts(controller_index);
-
-               rc = fsg_main_thread(NULL);
-               if (rc) {
-                       /* Check I/O error */
-                       if (rc == -EIO)
-                               printf("\rCheck USB cable connection\n");
-
-                       /* Check CTRL+C */
-                       if (rc == -EPIPE)
-                               printf("\rCTRL+C - Operation aborted\n");
-
-                       rc = CMD_RET_SUCCESS;
-                       goto cleanup_register;
-               }
-       }
-
-cleanup_register:
-       g_dnl_unregister();
-cleanup_board:
-       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
-cleanup_ums_init:
-       ums_fini();
-
-       return rc;
-}
-
-U_BOOT_CMD(ums, 4, 1, do_usb_mass_storage,
-       "Use the UMS [USB Mass Storage]",
-       "<USB_controller> [<devtype>] <devnum>  e.g. ums 0 mmc 0\n"
-       "    devtype defaults to mmc"
-);
diff --git a/common/cmd_version.c b/common/cmd_version.c
deleted file mode 100644 (file)
index 1be0667..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-#include <version.h>
-#include <linux/compiler.h>
-#ifdef CONFIG_SYS_COREBOOT
-#include <asm/arch/sysinfo.h>
-#endif
-
-const char __weak version_string[] = U_BOOT_VERSION_STRING;
-
-static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       printf("\n%s\n", version_string);
-#ifdef CC_VERSION_STRING
-       puts(CC_VERSION_STRING "\n");
-#endif
-#ifdef LD_VERSION_STRING
-       puts(LD_VERSION_STRING "\n");
-#endif
-#ifdef CONFIG_SYS_COREBOOT
-       printf("coreboot-%s (%s)\n", lib_sysinfo.version, lib_sysinfo.build);
-#endif
-       return 0;
-}
-
-U_BOOT_CMD(
-       version,        1,              1,      do_version,
-       "print monitor, compiler and linker version",
-       ""
-);
diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c
deleted file mode 100644 (file)
index d033c15..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * (C) Copyright 2000-2004
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * (C) Copyright 2003
- * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-
-/*
- * Multi Image extract
- */
-#include <common.h>
-#include <command.h>
-#include <image.h>
-#include <mapmem.h>
-#include <watchdog.h>
-#if defined(CONFIG_BZIP2)
-#include <bzlib.h>
-#endif
-#include <asm/byteorder.h>
-#include <asm/io.h>
-
-#ifndef CONFIG_SYS_XIMG_LEN
-/* use 8MByte as default max gunzip size */
-#define CONFIG_SYS_XIMG_LEN    0x800000
-#endif
-
-static int
-do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
-{
-       ulong           addr = load_addr;
-       ulong           dest = 0;
-       ulong           data, len;
-       int             verify;
-       int             part = 0;
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       ulong           count;
-       image_header_t  *hdr = NULL;
-#endif
-#if defined(CONFIG_FIT)
-       const char      *uname = NULL;
-       const void*     fit_hdr;
-       int             noffset;
-       const void      *fit_data;
-       size_t          fit_len;
-#endif
-#ifdef CONFIG_GZIP
-       uint            unc_len = CONFIG_SYS_XIMG_LEN;
-#endif
-       uint8_t         comp;
-
-       verify = getenv_yesno("verify");
-
-       if (argc > 1) {
-               addr = simple_strtoul(argv[1], NULL, 16);
-       }
-       if (argc > 2) {
-               part = simple_strtoul(argv[2], NULL, 16);
-#if defined(CONFIG_FIT)
-               uname = argv[2];
-#endif
-       }
-       if (argc > 3) {
-               dest = simple_strtoul(argv[3], NULL, 16);
-       }
-
-       switch (genimg_get_format((void *)addr)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
-       case IMAGE_FORMAT_LEGACY:
-
-               printf("## Copying part %d from legacy image "
-                       "at %08lx ...\n", part, addr);
-
-               hdr = (image_header_t *)addr;
-               if (!image_check_magic(hdr)) {
-                       printf("Bad Magic Number\n");
-                       return 1;
-               }
-
-               if (!image_check_hcrc(hdr)) {
-                       printf("Bad Header Checksum\n");
-                       return 1;
-               }
-#ifdef DEBUG
-               image_print_contents(hdr);
-#endif
-
-               if (!image_check_type(hdr, IH_TYPE_MULTI) &&
-                   !image_check_type(hdr, IH_TYPE_SCRIPT)) {
-                       printf("Wrong Image Type for %s command\n",
-                                       cmdtp->name);
-                       return 1;
-               }
-
-               comp = image_get_comp(hdr);
-               if ((comp != IH_COMP_NONE) && (argc < 4)) {
-                       printf("Must specify load address for %s command "
-                                       "with compressed image\n",
-                                       cmdtp->name);
-                       return 1;
-               }
-
-               if (verify) {
-                       printf("   Verifying Checksum ... ");
-                       if (!image_check_dcrc(hdr)) {
-                               printf("Bad Data CRC\n");
-                               return 1;
-                       }
-                       printf("OK\n");
-               }
-
-               count = image_multi_count(hdr);
-               if (part >= count) {
-                       printf("Bad Image Part\n");
-                       return 1;
-               }
-
-               image_multi_getimg(hdr, part, &data, &len);
-               break;
-#endif
-#if defined(CONFIG_FIT)
-       case IMAGE_FORMAT_FIT:
-               if (uname == NULL) {
-                       puts("No FIT subimage unit name\n");
-                       return 1;
-               }
-
-               printf("## Copying '%s' subimage from FIT image "
-                       "at %08lx ...\n", uname, addr);
-
-               fit_hdr = (const void *)addr;
-               if (!fit_check_format(fit_hdr)) {
-                       puts("Bad FIT image format\n");
-                       return 1;
-               }
-
-               /* get subimage node offset */
-               noffset = fit_image_get_node(fit_hdr, uname);
-               if (noffset < 0) {
-                       printf("Can't find '%s' FIT subimage\n", uname);
-                       return 1;
-               }
-
-               if (fit_image_check_comp(fit_hdr, noffset, IH_COMP_NONE)
-                   && (argc < 4)) {
-                       printf("Must specify load address for %s command "
-                               "with compressed image\n",
-                               cmdtp->name);
-                       return 1;
-               }
-
-               /* verify integrity */
-               if (verify) {
-                       if (!fit_image_verify(fit_hdr, noffset)) {
-                               puts("Bad Data Hash\n");
-                               return 1;
-                       }
-               }
-
-               /* get subimage data address and length */
-               if (fit_image_get_data(fit_hdr, noffset,
-                                       &fit_data, &fit_len)) {
-                       puts("Could not find script subimage data\n");
-                       return 1;
-               }
-
-               if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-                       puts("Could not find script subimage "
-                               "compression type\n");
-                       return 1;
-               }
-
-               data = (ulong)fit_data;
-               len = (ulong)fit_len;
-               break;
-#endif
-       default:
-               puts("Invalid image type for imxtract\n");
-               return 1;
-       }
-
-       if (argc > 3) {
-               switch (comp) {
-               case IH_COMP_NONE:
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-                       {
-                               size_t l = len;
-                               size_t tail;
-                               void *to = (void *) dest;
-                               void *from = (void *)data;
-
-                               printf("   Loading part %d ... ", part);
-
-                               while (l > 0) {
-                                       tail = (l > CHUNKSZ) ? CHUNKSZ : l;
-                                       WATCHDOG_RESET();
-                                       memmove(to, from, tail);
-                                       to += tail;
-                                       from += tail;
-                                       l -= tail;
-                               }
-                       }
-#else  /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
-                       printf("   Loading part %d ... ", part);
-                       memmove((char *) dest, (char *)data, len);
-#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
-                       break;
-#ifdef CONFIG_GZIP
-               case IH_COMP_GZIP:
-                       printf("   Uncompressing part %d ... ", part);
-                       if (gunzip((void *) dest, unc_len,
-                                  (uchar *) data, &len) != 0) {
-                               puts("GUNZIP ERROR - image not loaded\n");
-                               return 1;
-                       }
-                       break;
-#endif
-#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY)
-               case IH_COMP_BZIP2:
-                       {
-                               int i;
-
-                               printf("   Uncompressing part %d ... ", part);
-                               /*
-                                * If we've got less than 4 MB of malloc()
-                                * space, use slower decompression algorithm
-                                * which requires at most 2300 KB of memory.
-                                */
-                               i = BZ2_bzBuffToBuffDecompress(
-                                       map_sysmem(ntohl(hdr->ih_load), 0),
-                                       &unc_len, (char *)data, len,
-                                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024),
-                                       0);
-                               if (i != BZ_OK) {
-                                       printf("BUNZIP2 ERROR %d - "
-                                               "image not loaded\n", i);
-                                       return 1;
-                               }
-                       }
-                       break;
-#endif /* CONFIG_BZIP2 */
-               default:
-                       printf("Unimplemented compression type %d\n", comp);
-                       return 1;
-               }
-               puts("OK\n");
-       }
-
-       flush_cache(dest, len);
-
-       setenv_hex("fileaddr", data);
-       setenv_hex("filesize", len);
-
-       return 0;
-}
-
-#ifdef CONFIG_SYS_LONGHELP
-static char imgextract_help_text[] =
-       "addr part [dest]\n"
-       "    - extract <part> from legacy image at <addr> and copy to <dest>"
-#if defined(CONFIG_FIT)
-       "\n"
-       "addr uname [dest]\n"
-       "    - extract <uname> subimage from FIT image at <addr> and copy to <dest>"
-#endif
-       "";
-#endif
-
-U_BOOT_CMD(
-       imxtract, 4, 1, do_imgextract,
-       "extract a part of a multi-image", imgextract_help_text
-);
diff --git a/common/cmd_yaffs2.c b/common/cmd_yaffs2.c
deleted file mode 100644 (file)
index 9244606..0000000
+++ /dev/null
@@ -1,326 +0,0 @@
-/* Yaffs commands.
- * Modified by Charles Manning by adding ydevconfig command.
- *
- * Use ydevconfig to configure a mountpoint before use.
- * For example:
- *  # Configure mountpt xxx using nand device 0 using blocks 100-500
- *  ydevconfig xxx 0 100 500
- *  # Mount it
- *  ymount xxx
- *  # yls, yrdm etc
- *  yls -l xxx
- *  yrdm xxx/boot-image 82000000
- *  ...
- */
-
-#include <common.h>
-
-#include <config.h>
-#include <command.h>
-
-#ifdef YAFFS2_DEBUG
-#define PRINTF(fmt, args...) printf(fmt, ##args)
-#else
-#define PRINTF(fmt, args...) do { } while (0)
-#endif
-
-extern void cmd_yaffs_dev_ls(void);
-extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
-extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
-                               int start_block, int end_block);
-extern void cmd_yaffs_mount(char *mp);
-extern void cmd_yaffs_umount(char *mp);
-extern void cmd_yaffs_read_file(char *fn);
-extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
-extern void cmd_yaffs_ls(const char *mountpt, int longlist);
-extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
-extern void cmd_yaffs_mread_file(char *fn, char *addr);
-extern void cmd_yaffs_mkdir(const char *dir);
-extern void cmd_yaffs_rmdir(const char *dir);
-extern void cmd_yaffs_rm(const char *path);
-extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
-
-extern int yaffs_dump_dev(const char *path);
-
-/* ytrace - show/set yaffs trace mask */
-int do_ytrace(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       if (argc > 1)
-               cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
-       else
-               cmd_yaffs_tracemask(0, 0);
-
-       return 0;
-}
-
-/* ydevls - lists yaffs mount points. */
-int do_ydevls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       cmd_yaffs_dev_ls();
-
-       return 0;
-}
-
-/* ydevconfig mount_pt mtd_dev_num start_block end_block */
-int do_ydevconfig(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *mtpoint;
-       int mtd_dev;
-       int start_block;
-       int end_block;
-
-       if (argc != 5) {
-               printf
-                   ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
-               return -1;
-       }
-
-       mtpoint = argv[1];
-       mtd_dev = simple_strtol(argv[2], NULL, 16);
-       start_block = simple_strtol(argv[3], NULL, 16);
-       end_block = simple_strtol(argv[4], NULL, 16);
-
-       cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
-
-       return 0;
-}
-
-int do_ymount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *mtpoint;
-
-       if (argc != 2) {
-               printf("Bad arguments: ymount mount_pt\n");
-               return -1;
-       }
-
-       mtpoint = argv[1];
-       printf("Mounting yaffs2 mount point %s\n", mtpoint);
-
-       cmd_yaffs_mount(mtpoint);
-
-       return 0;
-}
-
-int do_yumount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *mtpoint;
-
-       if (argc != 2) {
-               printf("Bad arguments: yumount mount_pt\n");
-               return -1;
-       }
-
-       mtpoint = argv[1];
-       printf("Unmounting yaffs2 mount point %s\n", mtpoint);
-       cmd_yaffs_umount(mtpoint);
-
-       return 0;
-}
-
-int do_yls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *dirname;
-
-       if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
-               printf("Bad arguments: yls [-l] dir\n");
-               return -1;
-       }
-
-       dirname = argv[argc - 1];
-
-       cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
-
-       return 0;
-}
-
-int do_yrd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *filename;
-
-       if (argc != 2) {
-               printf("Bad arguments: yrd file_name\n");
-               return -1;
-       }
-
-       filename = argv[1];
-
-       printf("Reading file %s ", filename);
-
-       cmd_yaffs_read_file(filename);
-
-       printf("done\n");
-       return 0;
-}
-
-int do_ywr(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *filename;
-       ulong value;
-       ulong numValues;
-
-       if (argc != 4) {
-               printf("Bad arguments: ywr file_name value n_values\n");
-               return -1;
-       }
-
-       filename = argv[1];
-       value = simple_strtoul(argv[2], NULL, 16);
-       numValues = simple_strtoul(argv[3], NULL, 16);
-
-       printf("Writing value (%lx) %lx times to %s... ", value, numValues,
-              filename);
-
-       cmd_yaffs_write_file(filename, value, numValues);
-
-       printf("done\n");
-       return 0;
-}
-
-int do_yrdm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *filename;
-       ulong addr;
-
-       if (argc != 3) {
-               printf("Bad arguments: yrdm file_name addr\n");
-               return -1;
-       }
-
-       filename = argv[1];
-       addr = simple_strtoul(argv[2], NULL, 16);
-
-       cmd_yaffs_mread_file(filename, (char *)addr);
-
-       return 0;
-}
-
-int do_ywrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *filename;
-       ulong addr;
-       ulong size;
-
-       if (argc != 4) {
-               printf("Bad arguments: ywrm file_name addr size\n");
-               return -1;
-       }
-
-       filename = argv[1];
-       addr = simple_strtoul(argv[2], NULL, 16);
-       size = simple_strtoul(argv[3], NULL, 16);
-
-       cmd_yaffs_mwrite_file(filename, (char *)addr, size);
-
-       return 0;
-}
-
-int do_ymkdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *dirname;
-
-       if (argc != 2) {
-               printf("Bad arguments: ymkdir dir_name\n");
-               return -1;
-       }
-
-       dirname = argv[1];
-       cmd_yaffs_mkdir(dirname);
-
-       return 0;
-}
-
-int do_yrmdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *dirname;
-
-       if (argc != 2) {
-               printf("Bad arguments: yrmdir dir_name\n");
-               return -1;
-       }
-
-       dirname = argv[1];
-       cmd_yaffs_rmdir(dirname);
-
-       return 0;
-}
-
-int do_yrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *name;
-
-       if (argc != 2) {
-               printf("Bad arguments: yrm name\n");
-               return -1;
-       }
-
-       name = argv[1];
-
-       cmd_yaffs_rm(name);
-
-       return 0;
-}
-
-int do_ymv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
-{
-       char *oldPath;
-       char *newPath;
-
-       if (argc != 3) {
-               printf("Bad arguments: ymv old_path new_path\n");
-               return -1;
-       }
-
-       oldPath = argv[1];
-       newPath = argv[2];
-
-       cmd_yaffs_mv(newPath, oldPath);
-
-       return 0;
-}
-
-U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
-          "show/set yaffs trace mask",
-          "[new_mask]  show/set yaffs trace mask");
-
-U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
-          "list yaffs mount points", "list yaffs mount points");
-
-U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
-          "configure yaffs mount point",
-          "mtpoint mtd_id start_block end_block   configures a yaffs2 mount point");
-
-U_BOOT_CMD(ymount, 2, 0, do_ymount,
-          "mount yaffs", "mtpoint  mounts a yaffs2 mount point");
-
-U_BOOT_CMD(yumount, 2, 0, do_yumount,
-          "unmount yaffs", "mtpoint  unmounts a yaffs2 mount point");
-
-U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
-
-U_BOOT_CMD(yrd, 2, 0, do_yrd,
-          "read file from yaffs", "path   read file from yaffs");
-
-U_BOOT_CMD(ywr, 4, 0, do_ywr,
-          "write file to yaffs",
-          "filename value num_vlues   write values to yaffs file");
-
-U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
-          "read file to memory from yaffs",
-          "filename offset    reads yaffs file into memory");
-
-U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
-          "write file from memory to yaffs",
-          "filename offset size  writes memory to yaffs file");
-
-U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
-          "YAFFS mkdir", "dir    create a yaffs directory");
-
-U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
-          "YAFFS rmdir", "dirname   removes a yaffs directory");
-
-U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path   removes a yaffs file");
-
-U_BOOT_CMD(ymv, 4, 0, do_ymv,
-          "YAFFS mv",
-          "old_path new_path   moves/rename files within a yaffs mount point");
diff --git a/common/cmd_zfs.c b/common/cmd_zfs.c
deleted file mode 100644 (file)
index 0aed29e..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- *
- * ZFS filesystem porting to Uboot by
- * Jorgen Lundman <lundman at lundman.net>
- *
- * zfsfs support
- * made from existing GRUB Sources by Sun, GNU and others.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <part.h>
-#include <config.h>
-#include <command.h>
-#include <image.h>
-#include <linux/ctype.h>
-#include <asm/byteorder.h>
-#include <zfs_common.h>
-#include <linux/stat.h>
-#include <malloc.h>
-
-#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
-#include <usb.h>
-#endif
-
-#if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
-#error DOS or EFI partition support must be selected
-#endif
-
-#define DOS_PART_MAGIC_OFFSET  0x1fe
-#define DOS_FS_TYPE_OFFSET     0x36
-#define DOS_FS32_TYPE_OFFSET   0x52
-
-static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       char *filename = NULL;
-       int dev;
-       int part;
-       ulong addr = 0;
-       disk_partition_t info;
-       block_dev_desc_t *dev_desc;
-       char buf[12];
-       unsigned long count;
-       const char *addr_str;
-       struct zfs_file zfile;
-       struct device_s vdev;
-
-       if (argc < 3)
-               return CMD_RET_USAGE;
-
-       count = 0;
-       addr = simple_strtoul(argv[3], NULL, 16);
-       filename = getenv("bootfile");
-       switch (argc) {
-       case 3:
-               addr_str = getenv("loadaddr");
-               if (addr_str != NULL)
-                       addr = simple_strtoul(addr_str, NULL, 16);
-               else
-                       addr = CONFIG_SYS_LOAD_ADDR;
-
-               break;
-       case 4:
-               break;
-       case 5:
-               filename = argv[4];
-               break;
-       case 6:
-               filename = argv[4];
-               count = simple_strtoul(argv[5], NULL, 16);
-               break;
-
-       default:
-               return cmd_usage(cmdtp);
-       }
-
-       if (!filename) {
-               puts("** No boot file defined **\n");
-               return 1;
-       }
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       dev = dev_desc->dev;
-       printf("Loading file \"%s\" from %s device %d%c%c\n",
-               filename, argv[1], dev,
-               part ? ':' : ' ', part ? part + '0' : ' ');
-
-       zfs_set_blk_dev(dev_desc, &info);
-       vdev.part_length = info.size;
-
-       memset(&zfile, 0, sizeof(zfile));
-       zfile.device = &vdev;
-       if (zfs_open(&zfile, filename)) {
-               printf("** File not found %s **\n", filename);
-               return 1;
-       }
-
-       if ((count < zfile.size) && (count != 0))
-               zfile.size = (uint64_t)count;
-
-       if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
-               printf("** Unable to read \"%s\" from %s %d:%d **\n",
-                          filename, argv[1], dev, part);
-               zfs_close(&zfile);
-               return 1;
-       }
-
-       zfs_close(&zfile);
-
-       /* Loading ok, update default load address */
-       load_addr = addr;
-
-       printf("%llu bytes read\n", zfile.size);
-       setenv_hex("filesize", zfile.size);
-
-       return 0;
-}
-
-
-int zfs_print(const char *entry, const struct zfs_dirhook_info *data)
-{
-       printf("%s %s\n",
-                  data->dir ? "<DIR> " : "              ",
-                  entry);
-       return 0; /* 0 continue, 1 stop */
-}
-
-
-
-static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const char *filename = "/";
-       int part;
-       block_dev_desc_t *dev_desc;
-       disk_partition_t info;
-       struct device_s vdev;
-
-       if (argc < 2)
-               return cmd_usage(cmdtp);
-
-       if (argc == 4)
-               filename = argv[3];
-
-       part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
-       if (part < 0)
-               return 1;
-
-       zfs_set_blk_dev(dev_desc, &info);
-       vdev.part_length = info.size;
-
-       zfs_ls(&vdev, filename,
-                  zfs_print);
-
-       return 0;
-}
-
-
-U_BOOT_CMD(zfsls, 4, 1, do_zfs_ls,
-                  "list files in a directory (default /)",
-                  "<interface> <dev[:part]> [directory]\n"
-                  "      - list files from 'dev' on 'interface' in a '/DATASET/@/$dir/'");
-
-U_BOOT_CMD(zfsload, 6, 0, do_zfs_load,
-                  "load binary file from a ZFS filesystem",
-                  "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
-                  "      - load binary file '/DATASET/@/$dir/$file' from 'dev' on 'interface'\n"
-                  "             to address 'addr' from ZFS filesystem");
diff --git a/common/cmd_zip.c b/common/cmd_zip.c
deleted file mode 100644 (file)
index 7fcd9d5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * (C) Copyright 2012
- * Lei Wen <leiwen@marvell.com>, Marvell Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-#include <command.h>
-
-static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       unsigned long src, dst;
-       unsigned long src_len, dst_len = ~0UL;
-
-       switch (argc) {
-               case 5:
-                       dst_len = simple_strtoul(argv[4], NULL, 16);
-                       /* fall through */
-               case 4:
-                       src = simple_strtoul(argv[1], NULL, 16);
-                       src_len = simple_strtoul(argv[2], NULL, 16);
-                       dst = simple_strtoul(argv[3], NULL, 16);
-                       break;
-               default:
-                       return cmd_usage(cmdtp);
-       }
-
-       if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0)
-               return 1;
-
-       printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len);
-       setenv_hex("filesize", dst_len);
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       zip,    5,      1,      do_zip,
-       "zip a memory region",
-       "srcaddr srcsize dstaddr [dstsize]"
-);
index bc37b6d962b0aa9eb2032a63b5d5c2044c329cb7..b3f5fdc03a168682bb351734e2b0b897988d64fb 100644 (file)
@@ -227,11 +227,6 @@ static void console_puts(int file, const char *s)
        }
 }
 
-static inline void console_printdevs(int file)
-{
-       iomux_printdevs(file);
-}
-
 static inline void console_doenv(int file, struct stdio_dev *dev)
 {
        iomux_doenv(file, dev->name);
@@ -265,11 +260,6 @@ static inline void console_puts(int file, const char *s)
        stdio_devices[file]->puts(stdio_devices[file], s);
 }
 
-static inline void console_printdevs(int file)
-{
-       printf("%s\n", stdio_devices[file]->name);
-}
-
 static inline void console_doenv(int file, struct stdio_dev *dev)
 {
        console_setfile(file, dev);
@@ -653,44 +643,6 @@ void clear_ctrlc(void)
        ctrlc_was_pressed = 0;
 }
 
-#ifdef CONFIG_MODEM_SUPPORT_DEBUG
-char   screen[1024];
-char *cursor = screen;
-int once = 0;
-inline void dbg(const char *fmt, ...)
-{
-       va_list args;
-       uint    i;
-       char    printbuffer[CONFIG_SYS_PBSIZE];
-
-       if (!once) {
-               memset(screen, 0, sizeof(screen));
-               once++;
-       }
-
-       va_start(args, fmt);
-
-       /* For this to work, printbuffer must be larger than
-        * anything we ever want to print.
-        */
-       i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
-       va_end(args);
-
-       if ((screen + sizeof(screen) - 1 - cursor)
-           < strlen(printbuffer) + 1) {
-               memset(screen, 0, sizeof(screen));
-               cursor = screen;
-       }
-       sprintf(cursor, printbuffer);
-       cursor += strlen(printbuffer);
-
-}
-#else
-static inline void dbg(const char *fmt, ...)
-{
-}
-#endif
-
 /** U-Boot INIT FUNCTIONS *************************************************/
 
 struct stdio_dev *search_device(int flags, const char *name)
index 15aa43d5e1628bcc0ab8508c0b36922565bc06f3..bdb452e58c598731c9edc8e93d5e37f19e280919 100644 (file)
@@ -54,6 +54,11 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
        return 0;
 }
 
+__weak int mmc_get_env_dev(void)
+{
+       return CONFIG_SYS_MMC_ENV_DEV;
+}
+
 int env_init(void)
 {
        /* use default */
@@ -74,7 +79,7 @@ static unsigned char env_mmc_orig_hwpart;
 static int mmc_set_env_part(struct mmc *mmc)
 {
        uint part = mmc_get_env_part(mmc);
-       int dev = CONFIG_SYS_MMC_ENV_DEV;
+       int dev = mmc_get_env_dev();
        int ret = 0;
 
 #ifdef CONFIG_SPL_BUILD
@@ -109,7 +114,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
 static void fini_mmc_for_env(struct mmc *mmc)
 {
 #ifdef CONFIG_SYS_MMC_ENV_PART
-       int dev = CONFIG_SYS_MMC_ENV_DEV;
+       int dev = mmc_get_env_dev();
 
 #ifdef CONFIG_SPL_BUILD
        dev = 0;
@@ -140,7 +145,8 @@ static unsigned char env_flags;
 int saveenv(void)
 {
        ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
-       struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
+       int dev = mmc_get_env_dev();
+       struct mmc *mmc = find_mmc_device(dev);
        u32     offset;
        int     ret, copy = 0;
        const char *errmsg;
@@ -167,8 +173,7 @@ int saveenv(void)
                goto fini;
        }
 
-       printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "",
-              CONFIG_SYS_MMC_ENV_DEV);
+       printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev);
        if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
                puts("failed\n");
                ret = 1;
@@ -212,7 +217,7 @@ void env_relocate_spec(void)
        int crc1_ok = 0, crc2_ok = 0;
        env_t *ep;
        int ret;
-       int dev = CONFIG_SYS_MMC_ENV_DEV;
+       int dev = mmc_get_env_dev();
        const char *errmsg = NULL;
 
        ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
@@ -298,7 +303,7 @@ void env_relocate_spec(void)
        struct mmc *mmc;
        u32 offset;
        int ret;
-       int dev = CONFIG_SYS_MMC_ENV_DEV;
+       int dev = mmc_get_env_dev();
        const char *errmsg;
 
 #ifdef CONFIG_SPL_BUILD
index cbb1995de3398431878811f92f6e79551b947965..d84865fbbe26bb337d9453a86c03d8dbb06ae43d 100644 (file)
@@ -199,7 +199,7 @@ static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode,
                }
        }
 
-       if ((scancode > 0x1d) && (scancode < 0x3a)) {
+       if ((scancode > 0x1d) && (scancode < 0x39)) {
                /* Shift pressed */
                if (modifier & (LEFT_SHIFT | RIGHT_SHIFT))
                        keycode = usb_kbd_numkey_shifted[scancode - 0x1e];
index baa0ed84be874578e85d044a52a86900be19e68b..1cee7d488809db238cf6bd26780acf4979a6d435 100644 (file)
@@ -1,11 +1,14 @@
 CONFIG_X86=y
 CONFIG_SYS_MALLOC_F_LEN=0x1800
+CONFIG_DM_I2C=y
 CONFIG_VENDOR_GOOGLE=y
 CONFIG_DEFAULT_DEVICE_TREE="chromebook_link"
 CONFIG_TARGET_CHROMEBOOK_LINK=y
 CONFIG_HAVE_MRC=y
 CONFIG_ENABLE_MRC_CACHE=y
+CONFIG_SMP=y
 CONFIG_HAVE_VGA_BIOS=y
+CONFIG_CMD_CPU=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
@@ -17,6 +20,10 @@ CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
 CONFIG_OF_CONTROL=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_CPU=y
+CONFIG_SYS_I2C_INTEL=y
 CONFIG_CMD_CROS_EC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
@@ -34,6 +41,8 @@ CONFIG_SYS_NS16550=y
 CONFIG_ICH_SPI=y
 CONFIG_TIMER=y
 CONFIG_TPM_TIS_LPC=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_VIDEO_VESA=y
 CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
 CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
index c368cc06c452398b15b0cd21a67fb147e00b736a..e4a38210479b6c5f7d9ec5d7bfe6dc0984bb606d 100644 (file)
@@ -16,6 +16,8 @@ CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
 CONFIG_OF_CONTROL=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_CMD_CROS_EC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
@@ -29,6 +31,8 @@ CONFIG_SYS_NS16550=y
 CONFIG_ICH_SPI=y
 CONFIG_TIMER=y
 CONFIG_TPM_TIS_LPC=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_VIDEO_VESA=y
 CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
 CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
diff --git a/doc/device-tree-bindings/serial/8250.txt b/doc/device-tree-bindings/serial/8250.txt
new file mode 100644 (file)
index 0000000..91d5ab0
--- /dev/null
@@ -0,0 +1,66 @@
+* UART (Universal Asynchronous Receiver/Transmitter)
+
+Required properties:
+- compatible : one of:
+       - "ns8250"
+       - "ns16450"
+       - "ns16550a"
+       - "ns16550"
+       - "ns16750"
+       - "ns16850"
+       - For Tegra20, must contain "nvidia,tegra20-uart"
+       - For other Tegra, must contain '"nvidia,<chip>-uart",
+         "nvidia,tegra20-uart"' where <chip> is tegra30, tegra114, tegra124,
+         tegra132, or tegra210.
+       - "nxp,lpc3220-uart"
+       - "ralink,rt2880-uart"
+       - "ibm,qpace-nwp-serial"
+       - "altr,16550-FIFO32"
+       - "altr,16550-FIFO64"
+       - "altr,16550-FIFO128"
+       - "fsl,16550-FIFO64"
+       - "fsl,ns16550"
+       - "serial" if the port type is unknown.
+- reg : offset and length of the register set for the device.
+- interrupts : should contain uart interrupt.
+- clock-frequency : the input clock frequency for the UART
+        or
+  clocks phandle to refer to the clk used as per Documentation/devicetree
+  /bindings/clock/clock-bindings.txt
+
+Optional properties:
+- current-speed : the current active speed of the UART.
+- reg-offset : offset to apply to the mapbase from the start of the registers.
+- reg-shift : quantity to shift the register offsets by.
+- reg-io-width : the size (in bytes) of the IO accesses that should be
+  performed on the device.  There are some systems that require 32-bit
+  accesses to the UART (e.g. TI davinci).
+- used-by-rtas : set to indicate that the port is in use by the OpenFirmware
+  RTAS and should not be registered.
+- no-loopback-test: set to indicate that the port does not implements loopback
+  test mode
+- fifo-size: the fifo size of the UART.
+- auto-flow-control: one way to enable automatic flow control support. The
+  driver is allowed to detect support for the capability even without this
+  property.
+
+Note:
+* fsl,ns16550:
+  ------------
+  Freescale DUART is very similar to the PC16552D (and to a
+  pair of NS16550A), albeit with some nonstandard behavior such as
+  erratum A-004737 (relating to incorrect BRK handling).
+
+  Represents a single port that is compatible with the DUART found
+  on many Freescale chips (examples include mpc8349, mpc8548,
+  mpc8641d, p4080 and ls2085a).
+
+Example:
+
+       uart@80230000 {
+               compatible = "ns8250";
+               reg = <0x80230000 0x100>;
+               clock-frequency = <3686400>;
+               interrupts = <10>;
+               reg-shift = <2>;
+       };
diff --git a/doc/device-tree-bindings/serial/ns16550.txt b/doc/device-tree-bindings/serial/ns16550.txt
deleted file mode 100644 (file)
index ef0b9ae..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-NS16550 UART
-
-This UART driver supports many chip variants and is used in mamy SoCs.
-
-Required properties:
-- compatible: "ns16550" or "nvidia,tegra20-uart"
-- reg: start address and size of registers
-- reg-shift: shift value indicating register size: 0=byte, 1=16bit,2=32bit etc.
-- clock-frequency: input clock frequency for the UART (used to calculate the
-    baud rate divisor)
diff --git a/doc/device-tree-bindings/serial/omap_serial.txt b/doc/device-tree-bindings/serial/omap_serial.txt
new file mode 100644 (file)
index 0000000..7a71b5d
--- /dev/null
@@ -0,0 +1,33 @@
+OMAP UART controller
+
+Required properties:
+- compatible : should be "ti,omap2-uart" for OMAP2 controllers
+- compatible : should be "ti,omap3-uart" for OMAP3 controllers
+- compatible : should be "ti,omap4-uart" for OMAP4 controllers
+- compatible : should be "ti,am4372-uart" for AM437x controllers
+- compatible : should be "ti,am3352-uart" for AM335x controllers
+- compatible : should be "ti,dra742-uart" for DRA7x controllers
+- reg : address and length of the register space
+- interrupts or interrupts-extended : Should contain the uart interrupt
+                                      specifier or both the interrupt
+                                      controller phandle and interrupt
+                                      specifier.
+- ti,hwmods : Must be "uart<n>", n being the instance number (1-based)
+
+Optional properties:
+- clock-frequency : frequency of the clock input to the UART
+- dmas : DMA specifier, consisting of a phandle to the DMA controller
+         node and a DMA channel number.
+- dma-names : "rx" for receive channel, "tx" for transmit channel.
+
+Example:
+
+                uart4: serial@49042000 {
+                        compatible = "ti,omap3-uart";
+                        reg = <0x49042000 0x400>;
+                        interrupts = <80>;
+                        dmas = <&sdma 81 &sdma 82>;
+                        dma-names = "tx", "rx";
+                        ti,hwmods = "uart4";
+                        clock-frequency = <48000000>;
+                };
diff --git a/doc/device-tree-bindings/serial/snps-dw-apb-uart.txt b/doc/device-tree-bindings/serial/snps-dw-apb-uart.txt
new file mode 100644 (file)
index 0000000..12bbe9f
--- /dev/null
@@ -0,0 +1,76 @@
+* Synopsys DesignWare ABP UART
+
+Required properties:
+- compatible : "snps,dw-apb-uart"
+- reg : offset and length of the register set for the device.
+- interrupts : should contain uart interrupt.
+
+Clock handling:
+The clock rate of the input clock needs to be supplied by one of
+- clock-frequency : the input clock frequency for the UART.
+- clocks : phandle to the input clock
+
+The supplying peripheral clock can also be handled, needing a second property
+- clock-names: tuple listing input clock names.
+       Required elements: "baudclk", "apb_pclk"
+
+Optional properties:
+- snps,uart-16550-compatible : reflects the value of UART_16550_COMPATIBLE
+  configuration parameter. Define this if your UART does not implement the busy
+  functionality.
+- resets : phandle to the parent reset controller.
+- reg-shift : quantity to shift the register offsets by.  If this property is
+  not present then the register offsets are not shifted.
+- reg-io-width : the size (in bytes) of the IO accesses that should be
+  performed on the device.  If this property is not present then single byte
+  accesses are used.
+- dcd-override : Override the DCD modem status signal. This signal will always
+  be reported as active instead of being obtained from the modem status
+  register. Define this if your serial port does not use this pin.
+- dsr-override : Override the DTS modem status signal. This signal will always
+  be reported as active instead of being obtained from the modem status
+  register. Define this if your serial port does not use this pin.
+- cts-override : Override the CTS modem status signal. This signal will always
+  be reported as active instead of being obtained from the modem status
+  register. Define this if your serial port does not use this pin.
+- ri-override : Override the RI modem status signal. This signal will always be
+  reported as inactive instead of being obtained from the modem status register.
+  Define this if your serial port does not use this pin.
+
+Example:
+
+       uart@80230000 {
+               compatible = "snps,dw-apb-uart";
+               reg = <0x80230000 0x100>;
+               clock-frequency = <3686400>;
+               interrupts = <10>;
+               reg-shift = <2>;
+               reg-io-width = <4>;
+               dcd-override;
+               dsr-override;
+               cts-override;
+               ri-override;
+       };
+
+Example with one clock:
+
+       uart@80230000 {
+               compatible = "snps,dw-apb-uart";
+               reg = <0x80230000 0x100>;
+               clocks = <&baudclk>;
+               interrupts = <10>;
+               reg-shift = <2>;
+               reg-io-width = <4>;
+       };
+
+Example with two clocks:
+
+       uart@80230000 {
+               compatible = "snps,dw-apb-uart";
+               reg = <0x80230000 0x100>;
+               clocks = <&baudclk>, <&apb_pclk>;
+               clock-names = "baudclk", "apb_pclk";
+               interrupts = <10>;
+               reg-shift = <2>;
+               reg-io-width = <4>;
+       };
index 00da40b704a705c2ac4645b68b61b294f7dcddc8..6294048f2611488d30b7623a7a0a3a8321c36830 100644 (file)
@@ -51,6 +51,7 @@ obj-y += hwmon/
 obj-y += misc/
 obj-y += pcmcia/
 obj-y += dfu/
+obj-$(CONFIG_X86) += pch/
 obj-y += rtc/
 obj-y += sound/
 obj-y += timer/
index dec6230ad5cd6ca835a4d0f8b8c07906da74fa3f..77172467b2e18141c7f88b786f026ec6a084d7cf 100644 (file)
@@ -226,11 +226,19 @@ This function executes the BIOS POST code on the controller. We assume that
 at this stage the controller has its I/O and memory space enabled and
 that all other controllers are in a disabled state.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+static void PCI_doBIOSPOST(struct udevice *pcidev, BE_VGAInfo *vga_info,
+                          int vesa_mode, struct vbe_mode_info *mode_info)
+#else
 static void PCI_doBIOSPOST(pci_dev_t pcidev, BE_VGAInfo *vga_info,
                           int vesa_mode, struct vbe_mode_info *mode_info)
+#endif
 {
        RMREGS regs;
        RMSREGS sregs;
+#ifdef CONFIG_DM_PCI
+       pci_dev_t bdf;
+#endif
 
        /* Determine the value to store in AX for BIOS POST. Per the PCI specs,
         AH must contain the bus and AL must contain the devfn, encoded as
@@ -238,9 +246,14 @@ static void PCI_doBIOSPOST(pci_dev_t pcidev, BE_VGAInfo *vga_info,
         */
        memset(&regs, 0, sizeof(regs));
        memset(&sregs, 0, sizeof(sregs));
+#ifdef CONFIG_DM_PCI
+       bdf = dm_pci_get_bdf(pcidev);
+       regs.x.ax = (int)PCI_BUS(bdf) << 8 |
+                       (int)PCI_DEV(bdf) << 3 | (int)PCI_FUNC(bdf);
+#else
        regs.x.ax = ((int)PCI_BUS(pcidev) << 8) |
            ((int)PCI_DEV(pcidev) << 3) | (int)PCI_FUNC(pcidev);
-
+#endif
        /*Setup the X86 emulator for the VGA BIOS*/
        BE_setVGA(vga_info);
 
@@ -281,15 +294,28 @@ NOTE: This function leaves the original memory aperture disabled by leaving
       it programmed to all 1's. It must be restored to the correct value
       later.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+static u32 PCI_findBIOSAddr(struct udevice *pcidev, int *bar)
+#else
 static u32 PCI_findBIOSAddr(pci_dev_t pcidev, int *bar)
+#endif
 {
        u32 base, size;
 
        for (*bar = 0x10; *bar <= 0x14; (*bar) += 4) {
+#ifdef CONFIG_DM_PCI
+               dm_pci_read_config32(pcidev, *bar, &base);
+#else
                pci_read_config_dword(pcidev, *bar, &base);
+#endif
                if (!(base & 0x1)) {
+#ifdef CONFIG_DM_PCI
+                       dm_pci_write_config32(pcidev, *bar, 0xFFFFFFFF);
+                       dm_pci_read_config32(pcidev, *bar, &size);
+#else
                        pci_write_config_dword(pcidev, *bar, 0xFFFFFFFF);
                        pci_read_config_dword(pcidev, *bar, &size);
+#endif
                        size = ~(size & ~0xFF) + 1;
                        if (size >= MAX_BIOSLEN)
                                return base & ~0xFF;
@@ -312,11 +338,19 @@ necessary).
 Anyway to fix this we change all I/O mapped base registers and
 chop off the top bits.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+static void PCI_fixupIObase(struct udevice *pcidev, int reg, u32 *base)
+#else
 static void PCI_fixupIObase(pci_dev_t pcidev, int reg, u32 * base)
+#endif
 {
        if ((*base & 0x1) && (*base > 0xFFFE)) {
                *base &= 0xFFFF;
+#ifdef CONFIG_DM_PCI
+               dm_pci_write_config32(pcidev, reg, *base);
+#else
                pci_write_config_dword(pcidev, reg, *base);
+#endif
 
        }
 }
@@ -331,18 +365,30 @@ Pointers to the mapped BIOS image
 REMARKS:
 Maps a pointer to the BIOS image on the graphics card on the PCI bus.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+void *PCI_mapBIOSImage(struct udevice *pcidev)
+#else
 void *PCI_mapBIOSImage(pci_dev_t pcidev)
+#endif
 {
        u32 BIOSImageBus;
        int BIOSImageBAR;
        u8 *BIOSImage;
 
        /*Save PCI BAR registers that might get changed*/
+#ifdef CONFIG_DM_PCI
+       dm_pci_read_config32(pcidev, PCI_ROM_ADDRESS, &saveROMBaseAddress);
+       dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_0, &saveBaseAddress10);
+       dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_1, &saveBaseAddress14);
+       dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_2, &saveBaseAddress18);
+       dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_4, &saveBaseAddress20);
+#else
        pci_read_config_dword(pcidev, PCI_ROM_ADDRESS, &saveROMBaseAddress);
        pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_0, &saveBaseAddress10);
        pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_1, &saveBaseAddress14);
        pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_2, &saveBaseAddress18);
        pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_4, &saveBaseAddress20);
+#endif
 
        /*Fix up I/O base registers to less than 64K */
        if(saveBaseAddress14 != 0)
@@ -361,13 +407,21 @@ void *PCI_mapBIOSImage(pci_dev_t pcidev)
                return NULL;
        }
 
+#ifdef CONFIG_DM_PCI
+       BIOSImage = dm_pci_bus_to_virt(pcidev, BIOSImageBus,
+                                      PCI_REGION_MEM, 0, MAP_NOCACHE);
+
+       /*Change the PCI BAR registers to map it onto the bus.*/
+       dm_pci_write_config32(pcidev, BIOSImageBAR, 0);
+       dm_pci_write_config32(pcidev, PCI_ROM_ADDRESS, BIOSImageBus | 0x1);
+#else
        BIOSImage = pci_bus_to_virt(pcidev, BIOSImageBus,
                                    PCI_REGION_MEM, 0, MAP_NOCACHE);
 
        /*Change the PCI BAR registers to map it onto the bus.*/
        pci_write_config_dword(pcidev, BIOSImageBAR, 0);
        pci_write_config_dword(pcidev, PCI_ROM_ADDRESS, BIOSImageBus | 0x1);
-
+#endif
        udelay(1);
 
        /*Check that the BIOS image is valid. If not fail, or return the
@@ -387,6 +441,16 @@ pcidev     - PCI device info for the video card on the bus
 REMARKS:
 Unmaps the BIOS image for the device and restores framebuffer mappings
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+void PCI_unmapBIOSImage(struct udevice *pcidev, void *BIOSImage)
+{
+       dm_pci_write_config32(pcidev, PCI_ROM_ADDRESS, saveROMBaseAddress);
+       dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_0, saveBaseAddress10);
+       dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_1, saveBaseAddress14);
+       dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_2, saveBaseAddress18);
+       dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_4, saveBaseAddress20);
+}
+#else
 void PCI_unmapBIOSImage(pci_dev_t pcidev, void *BIOSImage)
 {
        pci_write_config_dword(pcidev, PCI_ROM_ADDRESS, saveROMBaseAddress);
@@ -395,6 +459,7 @@ void PCI_unmapBIOSImage(pci_dev_t pcidev, void *BIOSImage)
        pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_2, saveBaseAddress18);
        pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_4, saveBaseAddress20);
 }
+#endif
 
 /****************************************************************************
 PARAMETERS:
@@ -408,13 +473,22 @@ REMARKS:
 Loads and POST's the display controllers BIOS, directly from the BIOS
 image we can extract over the PCI bus.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+static int PCI_postController(struct udevice *pcidev, uchar *bios_rom,
+                             int bios_len, BE_VGAInfo *vga_info,
+                             int vesa_mode, struct vbe_mode_info *mode_info)
+#else
 static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len,
                              BE_VGAInfo *vga_info, int vesa_mode,
                              struct vbe_mode_info *mode_info)
+#endif
 {
        u32 bios_image_len;
        uchar *mapped_bios;
        uchar *copy_of_bios;
+#ifdef CONFIG_DM_PCI
+       pci_dev_t bdf;
+#endif
 
        if (bios_rom) {
                copy_of_bios = bios_rom;
@@ -442,9 +516,16 @@ static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len,
        }
 
        /*Save information in vga_info structure*/
+#ifdef CONFIG_DM_PCI
+       bdf = dm_pci_get_bdf(pcidev);
+       vga_info->function = PCI_FUNC(bdf);
+       vga_info->device = PCI_DEV(bdf);
+       vga_info->bus = PCI_BUS(bdf);
+#else
        vga_info->function = PCI_FUNC(pcidev);
        vga_info->device = PCI_DEV(pcidev);
        vga_info->bus = PCI_BUS(pcidev);
+#endif
        vga_info->pcidev = pcidev;
        vga_info->BIOSImage = copy_of_bios;
        vga_info->BIOSImageLen = bios_image_len;
@@ -462,13 +543,22 @@ static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len,
        return true;
 }
 
+#ifdef CONFIG_DM_PCI
+int biosemu_setup(struct udevice *pcidev, BE_VGAInfo **vga_infop)
+#else
 int biosemu_setup(pci_dev_t pcidev, BE_VGAInfo **vga_infop)
+#endif
 {
        BE_VGAInfo *VGAInfo;
+#ifdef CONFIG_DM_PCI
+       pci_dev_t bdf = dm_pci_get_bdf(pcidev);
 
        printf("videoboot: Booting PCI video card bus %d, function %d, device %d\n",
-            PCI_BUS(pcidev), PCI_FUNC(pcidev), PCI_DEV(pcidev));
-
+              PCI_BUS(bdf), PCI_FUNC(bdf), PCI_DEV(bdf));
+#else
+       printf("videoboot: Booting PCI video card bus %d, function %d, device %d\n",
+              PCI_BUS(pcidev), PCI_FUNC(pcidev), PCI_DEV(pcidev));
+#endif
        /*Initialise the x86 BIOS emulator*/
        if ((VGAInfo = malloc(sizeof(*VGAInfo))) == NULL) {
                printf("videoboot: Out of memory!\n");
@@ -486,9 +576,15 @@ void biosemu_set_interrupt_handler(int intnum, int (*int_func)(void))
        X86EMU_setupIntrFunc(intnum, (X86EMU_intrFuncs)int_func);
 }
 
+#ifdef CONFIG_DM_PCI
+int biosemu_run(struct udevice *pcidev, uchar *bios_rom, int bios_len,
+               BE_VGAInfo *vga_info, int clean_up, int vesa_mode,
+               struct vbe_mode_info *mode_info)
+#else
 int biosemu_run(pci_dev_t pcidev, uchar *bios_rom, int bios_len,
                BE_VGAInfo *vga_info, int clean_up, int vesa_mode,
                struct vbe_mode_info *mode_info)
+#endif
 {
        /*Post all the display controller BIOS'es*/
        if (!PCI_postController(pcidev, bios_rom, bios_len, vga_info,
@@ -522,7 +618,12 @@ REMARKS:
 Boots the PCI/AGP video card on the bus using the Video ROM BIOS image
 and the X86 BIOS emulator module.
 ****************************************************************************/
+#ifdef CONFIG_DM_PCI
+int BootVideoCardBIOS(struct udevice *pcidev, BE_VGAInfo **pVGAInfo,
+                     int clean_up)
+#else
 int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo, int clean_up)
+#endif
 {
        BE_VGAInfo *VGAInfo;
        int ret;
index dd4c0a4f322fbdf4d7d81df090084143e9bfb956..77c7f94bc63e1998f959f8c3bdf6ad6c46ef70c1 100644 (file)
@@ -185,12 +185,21 @@ static void X86API int1A(int unused)
        case 0xB103:            /* Find PCI class code */
                M.x86.R_AH = DEVICE_NOT_FOUND;
 #ifdef __KERNEL__
+#ifdef CONFIG_DM_PCI
+               dm_pci_read_config8(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG,
+                                   &interface);
+               dm_pci_read_config8(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE,
+                                   &subclass);
+               dm_pci_read_config8(_BE_env.vgaInfo.pcidev,
+                                   PCI_CLASS_DEVICE + 1, &baseclass);
+#else
                pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG,
                                     &interface);
                pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE,
                                     &subclass);
                pci_read_config_byte(_BE_env.vgaInfo.pcidev,
                                     PCI_CLASS_DEVICE + 1, &baseclass);
+#endif
                if (M.x86.R_CL == interface && M.x86.R_CH == subclass
                    && (u8) (M.x86.R_ECX >> 16) == baseclass) {
 #else
@@ -209,8 +218,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_read_config8(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
+                                           &M.x86.R_CL);
+# else
                        pci_read_config_byte(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
                                             &M.x86.R_CL);
+# endif
 #else
                        M.x86.R_CL =
                            (u8) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_BYTE,
@@ -224,8 +238,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_read_config16(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
+                                            &M.x86.R_CX);
+# else
                        pci_read_config_word(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
                                             &M.x86.R_CX);
+# endif
 #else
                        M.x86.R_CX =
                            (u16) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_WORD,
@@ -239,8 +258,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_read_config32(_BE_env.vgaInfo.pcidev,
+                                            M.x86.R_DI, &M.x86.R_ECX);
+# else
                        pci_read_config_dword(_BE_env.vgaInfo.pcidev,
                                              M.x86.R_DI, &M.x86.R_ECX);
+# endif
 #else
                        M.x86.R_ECX =
                            (u32) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_DWORD,
@@ -254,8 +278,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_write_config8(_BE_env.vgaInfo.pcidev,
+                                            M.x86.R_DI, M.x86.R_CL);
+# else
                        pci_write_config_byte(_BE_env.vgaInfo.pcidev,
                                              M.x86.R_DI, M.x86.R_CL);
+# endif
 #else
                        PCI_accessReg(M.x86.R_DI, M.x86.R_CL, PCI_WRITE_BYTE,
                                      _BE_env.vgaInfo.pciInfo);
@@ -268,8 +297,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_write_config32(_BE_env.vgaInfo.pcidev,
+                                             M.x86.R_DI, M.x86.R_CX);
+# else
                        pci_write_config_word(_BE_env.vgaInfo.pcidev,
                                              M.x86.R_DI, M.x86.R_CX);
+# endif
 #else
                        PCI_accessReg(M.x86.R_DI, M.x86.R_CX, PCI_WRITE_WORD,
                                      _BE_env.vgaInfo.pciInfo);
@@ -282,8 +316,13 @@ static void X86API int1A(int unused)
                if (M.x86.R_BX == pciSlot) {
                        M.x86.R_AH = SUCCESSFUL;
 #ifdef __KERNEL__
+# ifdef CONFIG_DM_PCI
+                       dm_pci_write_config32(_BE_env.vgaInfo.pcidev,
+                                             M.x86.R_DI, M.x86.R_ECX);
+# else
                        pci_write_config_dword(_BE_env.vgaInfo.pcidev,
                                               M.x86.R_DI, M.x86.R_ECX);
+# endif
 #else
                        PCI_accessReg(M.x86.R_DI, M.x86.R_ECX, PCI_WRITE_DWORD,
                                      _BE_env.vgaInfo.pciInfo);
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..990f768adbaffa19bf6a94f3b68570aa6c407954 100644 (file)
@@ -0,0 +1,9 @@
+config DISK
+       bool "Support disk controllers with driver model"
+       depends on DM
+       default y if DM
+       help
+         This enables a uclass for disk controllers in U-Boot. Various driver
+         types can use this, such as AHCI/SATA. It does not provide any standard
+         operations at present. The block device interface has not been converted
+         to driver model.
index eb8bda9ab2c61cf4d48a8702b747b569fa50fa94..5eb87e0b89989e8889aa562511836f6e3cd502d1 100644 (file)
@@ -5,6 +5,7 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
+obj-$(CONFIG_DISK) += disk-uclass.o
 obj-$(CONFIG_SCSI_AHCI) += ahci.o
 obj-$(CONFIG_DWC_AHSATA) += dwc_ahsata.o
 obj-$(CONFIG_FSL_SATA) += fsl_sata.o
diff --git a/drivers/block/disk-uclass.c b/drivers/block/disk-uclass.c
new file mode 100644 (file)
index 0000000..d665b35
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+
+UCLASS_DRIVER(disk) = {
+       .id             = UCLASS_DISK,
+       .name           = "disk",
+};
index a1c94780dd31d977c1823958a0539d5af261f25b..c4fc216340d8169dde8c05cdc0f9556e7ed9815b 100644 (file)
@@ -172,7 +172,8 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
                dm_dbg("   - found match at '%s'\n", entry->name);
                ret = device_bind(parent, entry, name, NULL, offset, &dev);
                if (ret) {
-                       dm_warn("Error binding driver '%s'\n", entry->name);
+                       dm_warn("Error binding driver '%s': %d\n", entry->name,
+                               ret);
                        return ret;
                } else {
                        dev->driver_data = id->data;
index 686c32056ec6e38cb26b2a355471331b26d97382..a0666d0bacd7e2d8cfcaca0f8ae13d85f7256873 100644 (file)
@@ -32,7 +32,7 @@ static int syscon_pre_probe(struct udevice *dev)
        return regmap_init_mem(dev, &priv->regmap);
 }
 
-struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
+int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp)
 {
        struct udevice *dev;
        struct uclass *uc;
@@ -40,22 +40,29 @@ struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
 
        ret = uclass_get(UCLASS_SYSCON, &uc);
        if (ret)
-               return ERR_PTR(ret);
+               return ret;
        uclass_foreach_dev(dev, uc) {
                if (dev->driver_data == driver_data) {
-                       struct syscon_uc_info *priv;
-                       int ret;
-
-                       ret = device_probe(dev);
-                       if (ret)
-                               return ERR_PTR(ret);
-                       priv = dev_get_uclass_priv(dev);
-
-                       return priv->regmap;
+                       *devp = dev;
+                       return device_probe(dev);
                }
        }
 
-       return ERR_PTR(-ENODEV);
+       return -ENODEV;
+}
+
+struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
+{
+       struct syscon_uc_info *priv;
+       struct udevice *dev;
+       int ret;
+
+       ret = syscon_get_by_driver_data(driver_data, &dev);
+       if (ret)
+               return ERR_PTR(ret);
+       priv = dev_get_uclass_priv(dev);
+
+       return priv->regmap;
 }
 
 void *syscon_get_first_range(ulong driver_data)
index 22defcd7d9223be898b18cdc8ae1236a38272671..a6dc9351148f905869012bd7f48b11be98fe63cf 100644 (file)
@@ -215,7 +215,7 @@ static int mxs_dma_reset(int channel)
 #if defined(CONFIG_MX23)
        uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_ctrl0_set);
        uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET;
-#elif (defined(CONFIG_MX28) || defined(CONFIG_MX6))
+#elif (defined(CONFIG_MX28) || defined(CONFIG_MX6) || defined(CONFIG_MX7))
        uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_channel_ctrl_set);
        uint32_t offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET;
 #endif
index 3ed4d8914c216f41dd09a2914650754d52da870a..d603b55902790abe87a6aef154bec77747de6c45 100644 (file)
@@ -10,6 +10,7 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
+#include <linux/bug.h>
 #include <linux/ctype.h>
 
 DECLARE_GLOBAL_DATA_PTR;
index 14adda2857d17dce774f87bec6254bb3fa1ba18f..46b83e78941887a6f9c9edab64d751bf5a3461b9 100644 (file)
@@ -58,6 +58,15 @@ config DM_I2C_GPIO
          bindings are supported.
          Binding info: doc/device-tree-bindings/i2c/i2c-gpio.txt
 
+config SYS_I2C_INTEL
+       bool "Intel I2C/SMBUS driver"
+       depends on DM_I2C
+       help
+         Add support for the Intel SMBUS driver. So far this driver is just
+         a stub which perhaps some basic init. There is no implementation of
+         the I2C API meaning that any I2C operations will immediately fail
+         for now.
+
 config SYS_I2C_ROCKCHIP
        bool "Rockchip I2C driver"
        depends on DM_I2C
index bbbc0dc59d6886c11e4575f0239168bd54c85ae5..c75c5793efe239a1c21c6fff1a3c8795d86748d6 100644 (file)
@@ -21,6 +21,7 @@ obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
 obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
 obj-$(CONFIG_SYS_I2C_FTI2C010) += fti2c010.o
 obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
+obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o
 obj-$(CONFIG_SYS_I2C_KONA) += kona_i2c.o
 obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o
 obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o
diff --git a/drivers/i2c/intel_i2c.c b/drivers/i2c/intel_i2c.c
new file mode 100644 (file)
index 0000000..3d777ff
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/io.h>
+#include <asm/arch/pch.h>
+
+int intel_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs)
+{
+       return -ENOSYS;
+}
+
+int intel_i2c_probe_chip(struct udevice *bus, uint chip_addr, uint chip_flags)
+{
+       return -ENOSYS;
+}
+
+int intel_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
+{
+       return 0;
+}
+
+static int intel_i2c_probe(struct udevice *dev)
+{
+       /*
+        * So far this is just setup code for ivybridge SMbus. When we have
+        * a full I2C driver this may need to be moved, generalised or made
+        * dependant on a particular compatible string.
+        *
+        * Set SMBus I/O base
+        */
+       dm_pci_write_config32(dev, SMB_BASE,
+                             SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
+
+       /* Set SMBus enable. */
+       dm_pci_write_config8(dev, HOSTC, HST_EN);
+
+       /* Set SMBus I/O space enable. */
+       dm_pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
+
+       /* Disable interrupt generation. */
+       outb(0, SMBUS_IO_BASE + SMBHSTCTL);
+
+       /* Clear any lingering errors, so transactions can run. */
+       outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
+       debug("SMBus controller enabled\n");
+
+       return 0;
+}
+
+static const struct dm_i2c_ops intel_i2c_ops = {
+       .xfer           = intel_i2c_xfer,
+       .probe_chip     = intel_i2c_probe_chip,
+       .set_bus_speed  = intel_i2c_set_bus_speed,
+};
+
+static const struct udevice_id intel_i2c_ids[] = {
+       { .compatible = "intel,ich-i2c" },
+       { }
+};
+
+U_BOOT_DRIVER(intel_i2c) = {
+       .name   = "i2c_intel",
+       .id     = UCLASS_I2C,
+       .of_match = intel_i2c_ids,
+       .per_child_auto_alloc_size = sizeof(struct dm_i2c_chip),
+       .ops    = &intel_i2c_ops,
+       .probe  = intel_i2c_probe,
+};
index f15cf36c88e713f1fd38de5648e38410f0611441..ba019a07638917c4578059057a571d04de9174fd 100644 (file)
@@ -30,7 +30,7 @@
 #define        MXS_NAND_DMA_DESCRIPTOR_COUNT           4
 
 #define        MXS_NAND_CHUNK_DATA_CHUNK_SIZE          512
-#if defined(CONFIG_MX6)
+#if (defined(CONFIG_MX6) || defined(CONFIG_MX7))
 #define        MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT    2
 #else
 #define        MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT    0
@@ -152,7 +152,7 @@ static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
        int max_ecc_strength_supported;
 
        /* Refer to Chapter 17 for i.MX6DQ, Chapter 18 for i.MX6SX */
-       if (is_cpu_type(MXC_CPU_MX6SX))
+       if (is_cpu_type(MXC_CPU_MX6SX) || is_soc_type(MXC_SOC_MX7))
                max_ecc_strength_supported = 62;
        else
                max_ecc_strength_supported = 40;
index f484e62b32c6c6695ab3af1ba0cebf2433af8e81..baf4e2d25b4c1c1f2bea6921bad905e642f2388b 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/major.h>
 #else
+#include <linux/bug.h>
 #include <linux/log2.h>
 #endif
 #include <linux/err.h>
index f2cd32c548d86fc175520b9436c55032b2aaa79f..d4a6386810b6509bcfbcc5ef90556210129287ad 100644 (file)
@@ -240,23 +240,23 @@ static void eepro100_halt (struct eth_device *dev);
 
 static inline int INW (struct eth_device *dev, u_long addr)
 {
-       return le16_to_cpu (*(volatile u16 *) (addr + dev->iobase));
+       return le16_to_cpu(*(volatile u16 *)(addr + (u_long)dev->iobase));
 }
 
 static inline void OUTW (struct eth_device *dev, int command, u_long addr)
 {
-       *(volatile u16 *) ((addr + dev->iobase)) = cpu_to_le16 (command);
+       *(volatile u16 *)((addr + (u_long)dev->iobase)) = cpu_to_le16(command);
 }
 
 static inline void OUTL (struct eth_device *dev, int command, u_long addr)
 {
-       *(volatile u32 *) ((addr + dev->iobase)) = cpu_to_le32 (command);
+       *(volatile u32 *)((addr + (u_long)dev->iobase)) = cpu_to_le32(command);
 }
 
 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
 static inline int INL (struct eth_device *dev, u_long addr)
 {
-       return le32_to_cpu (*(volatile u32 *) (addr + dev->iobase));
+       return le32_to_cpu(*(volatile u32 *)(addr + (u_long)dev->iobase));
 }
 
 static int get_phyreg (struct eth_device *dev, unsigned char addr,
index bac4610fd995d62d1f2f1d595fe91e7216626be9..4b9b3720f7440092b2c8de8e0ecb359f023ff2ad 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include <common.h>
 #include <errno.h>
+#include <linux/bug.h>
 #include <asm/io.h>
 #include <libfdt.h>
 #include <fdt_support.h>
index 7059c8432a34959a2cc5a8caba230d9ac46e72fc..97e30f3be044e0a76db6428245648d5b3251a874 100644 (file)
@@ -19,6 +19,7 @@
 #include <asm/io.h>
 #include <phy.h>
 #include <miiphy.h>
+#include <wait_bit.h>
 #include <watchdog.h>
 #include <asm/system.h>
 #include <asm/arch/hardware.h>
@@ -448,38 +449,6 @@ static int zynq_gem_init(struct udevice *dev)
        return 0;
 }
 
-static int wait_for_bit(const char *func, u32 *reg, const u32 mask,
-                       bool set, unsigned int timeout)
-{
-       u32 val;
-       unsigned long start = get_timer(0);
-
-       while (1) {
-               val = readl(reg);
-
-               if (!set)
-                       val = ~val;
-
-               if ((val & mask) == mask)
-                       return 0;
-
-               if (get_timer(start) > timeout)
-                       break;
-
-               if (ctrlc()) {
-                       puts("Abort\n");
-                       return -EINTR;
-               }
-
-               udelay(1);
-       }
-
-       debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
-             func, reg, mask, set);
-
-       return -ETIMEDOUT;
-}
-
 static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
 {
        u32 addr, size;
@@ -521,7 +490,7 @@ static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
                printf("TX buffers exhausted in mid frame\n");
 
        return wait_for_bit(__func__, &regs->txsr, ZYNQ_GEM_TSR_DONE,
-                           true, 20000);
+                           true, 20000, true);
 }
 
 /* Do not check frame_recd flag in rx_status register 0x20 - just poll BD */
diff --git a/drivers/pch/Makefile b/drivers/pch/Makefile
new file mode 100644 (file)
index 0000000..dde9e86
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+obj-y += pch-uclass.o
+obj-y += pch7.o
+obj-y += pch9.o
diff --git a/drivers/pch/pch-uclass.c b/drivers/pch/pch-uclass.c
new file mode 100644 (file)
index 0000000..4579ed1
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <pch.h>
+#include <dm/root.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int pch_get_sbase(struct udevice *dev, ulong *sbasep)
+{
+       struct pch_ops *ops = pch_get_ops(dev);
+
+       *sbasep = 0;
+       if (!ops->get_sbase)
+               return -ENOSYS;
+
+       return ops->get_sbase(dev, sbasep);
+}
+
+enum pch_version pch_get_version(struct udevice *dev)
+{
+       struct pch_ops *ops = pch_get_ops(dev);
+
+       if (!ops->get_version)
+               return -ENOSYS;
+
+       return ops->get_version(dev);
+}
+
+int pch_set_spi_protect(struct udevice *dev, bool protect)
+{
+       struct pch_ops *ops = pch_get_ops(dev);
+
+       if (!ops->set_spi_protect)
+               return -ENOSYS;
+
+       return ops->set_spi_protect(dev, protect);
+}
+
+static int pch_uclass_post_bind(struct udevice *bus)
+{
+       /*
+        * Scan the device tree for devices
+        *
+        * Before relocation, only bind devices marked for pre-relocation
+        * use.
+        */
+       return dm_scan_fdt_node(bus, gd->fdt_blob, bus->of_offset,
+                               gd->flags & GD_FLG_RELOC ? false : true);
+}
+
+UCLASS_DRIVER(pch) = {
+       .id             = UCLASS_PCH,
+       .name           = "pch",
+       .post_bind      = pch_uclass_post_bind,
+};
diff --git a/drivers/pch/pch7.c b/drivers/pch/pch7.c
new file mode 100644 (file)
index 0000000..ef72422
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <pch.h>
+
+#define BIOS_CTRL      0xd8
+
+static int pch7_get_sbase(struct udevice *dev, ulong *sbasep)
+{
+       u32 rcba;
+
+       dm_pci_read_config32(dev, PCH_RCBA, &rcba);
+       /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
+       rcba = rcba & 0xffffc000;
+       *sbasep = rcba + 0x3020;
+
+       return 0;
+}
+
+static enum pch_version pch7_get_version(struct udevice *dev)
+{
+       return PCHV_7;
+}
+
+static int pch7_set_spi_protect(struct udevice *dev, bool protect)
+{
+       uint8_t bios_cntl;
+
+       /* Adjust the BIOS write protect to dis/allow write commands */
+       dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl);
+       if (protect)
+               bios_cntl &= ~BIOS_CTRL_BIOSWE;
+       else
+               bios_cntl |= BIOS_CTRL_BIOSWE;
+       dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl);
+
+       return 0;
+}
+
+static const struct pch_ops pch7_ops = {
+       .get_sbase      = pch7_get_sbase,
+       .get_version    = pch7_get_version,
+       .set_spi_protect = pch7_set_spi_protect,
+};
+
+static const struct udevice_id pch7_ids[] = {
+       { .compatible = "intel,pch7" },
+       { }
+};
+
+U_BOOT_DRIVER(pch7_drv) = {
+       .name           = "intel-pch7",
+       .id             = UCLASS_PCH,
+       .of_match       = pch7_ids,
+       .ops            = &pch7_ops,
+};
diff --git a/drivers/pch/pch9.c b/drivers/pch/pch9.c
new file mode 100644 (file)
index 0000000..529cb02
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <pch.h>
+
+#define SBASE_ADDR     0x54
+
+static int pch9_get_sbase(struct udevice *dev, ulong *sbasep)
+{
+       uint32_t sbase_addr;
+
+       dm_pci_read_config32(dev, SBASE_ADDR, &sbase_addr);
+       *sbasep = sbase_addr & 0xfffffe00;
+
+       return 0;
+}
+
+static enum pch_version pch9_get_version(struct udevice *dev)
+{
+       return PCHV_9;
+}
+
+static const struct pch_ops pch9_ops = {
+       .get_sbase      = pch9_get_sbase,
+       .get_version    = pch9_get_version,
+};
+
+static const struct udevice_id pch9_ids[] = {
+       { .compatible = "intel,pch9" },
+       { }
+};
+
+U_BOOT_DRIVER(pch9_drv) = {
+       .name           = "intel-pch9",
+       .id             = UCLASS_PCH,
+       .of_match       = pch9_ids,
+       .ops            = &pch9_ops,
+};
index 685df9d274e4ba1c960523fad72fc2482335fdaa..61292d72bda8f1c496370ab0d72489e0b880bc42 100644 (file)
@@ -22,7 +22,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int pci_get_bus(int busnum, struct udevice **busp)
+int pci_get_bus(int busnum, struct udevice **busp)
 {
        int ret;
 
@@ -41,20 +41,6 @@ static int pci_get_bus(int busnum, struct udevice **busp)
        return ret;
 }
 
-struct pci_controller *pci_bus_to_hose(int busnum)
-{
-       struct udevice *bus;
-       int ret;
-
-       ret = pci_get_bus(busnum, &bus);
-       if (ret) {
-               debug("%s: Cannot get bus %d: ret=%d\n", __func__, busnum, ret);
-               return NULL;
-       }
-
-       return dev_get_uclass_priv(bus);
-}
-
 struct udevice *pci_get_controller(struct udevice *dev)
 {
        while (device_is_on_pci_bus(dev))
@@ -1067,6 +1053,14 @@ u32 dm_pci_read_bar32(struct udevice *dev, int barnum)
                return addr & PCI_BASE_ADDRESS_MEM_MASK;
 }
 
+void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr)
+{
+       int bar;
+
+       bar = PCI_BASE_ADDRESS_0 + barnum * 4;
+       dm_pci_write_config32(dev, bar, addr);
+}
+
 static int _dm_pci_bus_to_phys(struct udevice *ctlr,
                               pci_addr_t bus_addr, unsigned long flags,
                               unsigned long skip_mask, phys_addr_t *pa)
index 5cfa135ba6e51d93a92b31d7b6e2904b23f3b85a..88bc416c61628fd2c44042dbd22dd79eb0480729 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <pci.h>
 
@@ -167,8 +168,8 @@ void dm_pciauto_prescan_setup_bridge(struct udevice *dev, int sub_bus)
        struct pci_region *pci_prefetch;
        struct pci_region *pci_io;
        u16 cmdstat, prefechable_64;
-       /* The root controller has the region information */
-       struct pci_controller *ctlr_hose = pci_bus_to_hose(0);
+       struct udevice *ctlr = pci_get_controller(dev);
+       struct pci_controller *ctlr_hose = dev_get_uclass_priv(ctlr);
 
        pci_mem = ctlr_hose->pci_mem;
        pci_prefetch = ctlr_hose->pci_prefetch;
@@ -248,9 +249,8 @@ void dm_pciauto_postscan_setup_bridge(struct udevice *dev, int sub_bus)
        struct pci_region *pci_mem;
        struct pci_region *pci_prefetch;
        struct pci_region *pci_io;
-
-       /* The root controller has the region information */
-       struct pci_controller *ctlr_hose = pci_bus_to_hose(0);
+       struct udevice *ctlr = pci_get_controller(dev);
+       struct pci_controller *ctlr_hose = dev_get_uclass_priv(ctlr);
 
        pci_mem = ctlr_hose->pci_mem;
        pci_prefetch = ctlr_hose->pci_prefetch;
@@ -311,13 +311,13 @@ int dm_pciauto_config_device(struct udevice *dev)
        unsigned int sub_bus = PCI_BUS(dm_pci_get_bdf(dev));
        unsigned short class;
        bool enum_only = false;
+       struct udevice *ctlr = pci_get_controller(dev);
+       struct pci_controller *ctlr_hose = dev_get_uclass_priv(ctlr);
        int n;
 
 #ifdef CONFIG_PCI_ENUM_ONLY
        enum_only = true;
 #endif
-       /* The root controller has the region information */
-       struct pci_controller *ctlr_hose = pci_bus_to_hose(0);
 
        pci_mem = ctlr_hose->pci_mem;
        pci_prefetch = ctlr_hose->pci_prefetch;
index dd15eb19f85a3f13d8847e883872ffabbba52830..ddaf358e26dc5ffa24012aed736ec73ad8d31037 100644 (file)
@@ -12,6 +12,7 @@
 #include <pci.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
+#include "pci_internal.h"
 
 #define PCI_HOSE_OP(rw, name, size, type)                              \
 int pci_hose_##rw##_config_##name(struct pci_controller *hose,         \
@@ -36,3 +37,17 @@ pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
                return -1;
        return dm_pci_get_bdf(dev);
 }
+
+struct pci_controller *pci_bus_to_hose(int busnum)
+{
+       struct udevice *bus;
+       int ret;
+
+       ret = pci_get_bus(busnum, &bus);
+       if (ret) {
+               debug("%s: Cannot get bus %d: ret=%d\n", __func__, busnum, ret);
+               return NULL;
+       }
+
+       return dev_get_uclass_priv(bus);
+}
index 0867575a58f9d7cbcc97faa9e547236026686e8e..616b9c174ced3729144eba159f275bb3b70c377e 100644 (file)
@@ -47,4 +47,16 @@ void dm_pciauto_postscan_setup_bridge(struct udevice *dev, int sub_bus);
  */
 int dm_pciauto_config_device(struct udevice *dev);
 
+/**
+ * pci_get_bus() - Get a pointer to a bus, given its number
+ *
+ * This looks up a PCI bus based on its bus number. The bus is probed if
+ * necessary.
+ *
+ * @busnum:    PCI bus number to look up
+ * @busp:      Returns PCI bus on success
+ * @return 0 on success, or -ve error
+ */
+int pci_get_bus(int busnum, struct udevice **busp);
+
 #endif
index ed2f61dfc33c67d363679ddf31772034578125a5..d5bf6f4c471646018663c84cf8f7ed7f31751214 100644 (file)
@@ -328,12 +328,12 @@ int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void),
 #ifdef CONFIG_BIOSEMU
                BE_VGAInfo *info;
 
-               ret = biosemu_setup(dm_pci_get_bdf(dev), &info);
+               ret = biosemu_setup(dev, &info);
                if (ret)
                        goto err;
                biosemu_set_interrupt_handler(0x15, int15_handler);
-               ret = biosemu_run(dm_pci_get_bdf(dev), (uchar *)ram, 1 << 16,
-                                 info, true, vesa_mode, &mode_info);
+               ret = biosemu_run(dev, (uchar *)ram, 1 << 16, info,
+                                 true, vesa_mode, &mode_info);
                if (ret)
                        goto err;
 #endif
index 7eaec6a7024fbcd6912202b7fcbb394beb660115..6bdebf28cd59de02ffd7d72d56d1d6d5bd28d1a6 100644 (file)
@@ -7,9 +7,7 @@
 #ifndef __PINCTRL_UNIPHIER_H__
 #define __PINCTRL_UNIPHIER_H__
 
-/* TODO: move this to include/linux/bug.h */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-
+#include <linux/bug.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 
index 021b211ab4047c3b9c10322bf3a0b2662c18e02f..93dad338b37597aeea3303c9b395ba1f333a6207 100644 (file)
@@ -423,11 +423,15 @@ const struct dm_serial_ops ns16550_serial_ops = {
 };
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+/*
+ * Please consider existing compatible strings before adding a new
+ * one to keep this table compact. Or you may add a generic "ns16550"
+ * compatible string to your dts.
+ */
 static const struct udevice_id ns16550_serial_ids[] = {
        { .compatible = "ns16550" },
        { .compatible = "ns16550a" },
        { .compatible = "nvidia,tegra20-uart" },
-       { .compatible = "rockchip,rk3036-uart" },
        { .compatible = "snps,dw-apb-uart" },
        { .compatible = "ti,omap2-uart" },
        { .compatible = "ti,omap3-uart" },
index 799ef6a667d16a1d38427be6e642633848c9a9c4..fcb1e95e81002ab49244d4bf5f3482afe407cd81 100644 (file)
@@ -127,11 +127,6 @@ static void _serial_putc(const char c, const int port)
        NS16550_putc(PORT, c);
 }
 
-static void _serial_putc_raw(const char c, const int port)
-{
-       NS16550_putc(PORT, c);
-}
-
 static void _serial_puts(const char *s, const int port)
 {
        while (*s) {
@@ -164,12 +159,6 @@ serial_putc_dev(unsigned int dev_index,const char c)
        _serial_putc(c,dev_index);
 }
 
-static inline void
-serial_putc_raw_dev(unsigned int dev_index,const char c)
-{
-       _serial_putc_raw(c,dev_index);
-}
-
 static inline void
 serial_puts_dev(unsigned int dev_index,const char *s)
 {
index 59eaaea69396e8082ba373558d37c84f4ab8d53d..e543b8f0cf4cbe9c27f9a7dd35e4bdde67b14027 100644 (file)
@@ -5,14 +5,14 @@
  *
  * This file is derived from the flashrom project.
  */
-
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
-#include <spi.h>
+#include <pch.h>
 #include <pci.h>
 #include <pci_ids.h>
+#include <spi.h>
 #include <asm/io.h>
 
 #include "ich.h"
 #define SPI_OPCODE_WREN      0x06
 #define SPI_OPCODE_FAST_READ 0x0b
 
+#ifdef DEBUG_TRACE
+#define debug_trace(fmt, args...) debug(fmt, ##args)
+#else
+#define debug_trace(x, args...)
+#endif
+
 struct ich_spi_platdata {
-       pci_dev_t dev;          /* PCI device number */
-       int ich_version;        /* Controller version, 7 or 9 */
-       bool use_sbase;         /* Use SBASE instead of RCB */
+       enum pch_version ich_version;   /* Controller version, 7 or 9 */
 };
 
 struct ich_spi_priv {
@@ -52,7 +56,7 @@ static u8 ich_readb(struct ich_spi_priv *priv, int reg)
 {
        u8 value = readb(priv->base + reg);
 
-       debug("read %2.2x from %4.4x\n", value, reg);
+       debug_trace("read %2.2x from %4.4x\n", value, reg);
 
        return value;
 }
@@ -61,7 +65,7 @@ static u16 ich_readw(struct ich_spi_priv *priv, int reg)
 {
        u16 value = readw(priv->base + reg);
 
-       debug("read %4.4x from %4.4x\n", value, reg);
+       debug_trace("read %4.4x from %4.4x\n", value, reg);
 
        return value;
 }
@@ -70,7 +74,7 @@ static u32 ich_readl(struct ich_spi_priv *priv, int reg)
 {
        u32 value = readl(priv->base + reg);
 
-       debug("read %8.8x from %4.4x\n", value, reg);
+       debug_trace("read %8.8x from %4.4x\n", value, reg);
 
        return value;
 }
@@ -78,19 +82,19 @@ static u32 ich_readl(struct ich_spi_priv *priv, int reg)
 static void ich_writeb(struct ich_spi_priv *priv, u8 value, int reg)
 {
        writeb(value, priv->base + reg);
-       debug("wrote %2.2x to %4.4x\n", value, reg);
+       debug_trace("wrote %2.2x to %4.4x\n", value, reg);
 }
 
 static void ich_writew(struct ich_spi_priv *priv, u16 value, int reg)
 {
        writew(value, priv->base + reg);
-       debug("wrote %4.4x to %4.4x\n", value, reg);
+       debug_trace("wrote %4.4x to %4.4x\n", value, reg);
 }
 
 static void ich_writel(struct ich_spi_priv *priv, u32 value, int reg)
 {
        writel(value, priv->base + reg);
-       debug("wrote %8.8x to %4.4x\n", value, reg);
+       debug_trace("wrote %8.8x to %4.4x\n", value, reg);
 }
 
 static void write_reg(struct ich_spi_priv *priv, const void *value,
@@ -116,40 +120,16 @@ static void ich_set_bbar(struct ich_spi_priv *ctlr, uint32_t minaddr)
        ich_writel(ctlr, ichspi_bbar, ctlr->bbar);
 }
 
-/*
- * Check if this device ID matches one of supported Intel PCH devices.
- *
- * Return the ICH version if there is a match, or zero otherwise.
- */
-static int get_ich_version(uint16_t device_id)
-{
-       if (device_id == PCI_DEVICE_ID_INTEL_TGP_LPC ||
-           device_id == PCI_DEVICE_ID_INTEL_ITC_LPC ||
-           device_id == PCI_DEVICE_ID_INTEL_QRK_ILB)
-               return 7;
-
-       if ((device_id >= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN &&
-            device_id <= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX) ||
-           (device_id >= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MIN &&
-            device_id <= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MAX) ||
-           device_id == PCI_DEVICE_ID_INTEL_VALLEYVIEW_LPC ||
-           device_id == PCI_DEVICE_ID_INTEL_LYNXPOINT_LPC ||
-           device_id == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LPC)
-               return 9;
-
-       return 0;
-}
-
 /* @return 1 if the SPI flash supports the 33MHz speed */
-static int ich9_can_do_33mhz(pci_dev_t dev)
+static int ich9_can_do_33mhz(struct udevice *dev)
 {
        u32 fdod, speed;
 
        /* Observe SPI Descriptor Component Section 0 */
-       pci_write_config_dword(dev, 0xb0, 0x1000);
+       dm_pci_write_config32(dev->parent, 0xb0, 0x1000);
 
        /* Extract the Write/Erase SPI Frequency from descriptor */
-       pci_read_config_dword(dev, 0xb4, &fdod);
+       dm_pci_read_config32(dev->parent, 0xb4, &fdod);
 
        /* Bits 23:21 have the fast read clock frequency, 0=20MHz, 1=33MHz */
        speed = (fdod >> 21) & 7;
@@ -157,59 +137,22 @@ static int ich9_can_do_33mhz(pci_dev_t dev)
        return speed == 1;
 }
 
-static int ich_find_spi_controller(struct ich_spi_platdata *ich)
-{
-       int last_bus = pci_last_busno();
-       int bus;
-
-       if (last_bus == -1) {
-               debug("No PCI busses?\n");
-               return -ENODEV;
-       }
-
-       for (bus = 0; bus <= last_bus; bus++) {
-               uint16_t vendor_id, device_id;
-               uint32_t ids;
-               pci_dev_t dev;
-
-               dev = PCI_BDF(bus, 31, 0);
-               pci_read_config_dword(dev, 0, &ids);
-               vendor_id = ids;
-               device_id = ids >> 16;
-
-               if (vendor_id == PCI_VENDOR_ID_INTEL) {
-                       ich->dev = dev;
-                       ich->ich_version = get_ich_version(device_id);
-                       if (device_id == PCI_DEVICE_ID_INTEL_VALLEYVIEW_LPC)
-                               ich->use_sbase = true;
-                       return ich->ich_version == 0 ? -ENODEV : 0;
-               }
-       }
-
-       debug("ICH SPI: No ICH found.\n");
-       return -ENODEV;
-}
-
-static int ich_init_controller(struct ich_spi_platdata *plat,
+static int ich_init_controller(struct udevice *dev,
+                              struct ich_spi_platdata *plat,
                               struct ich_spi_priv *ctlr)
 {
-       uint8_t *rcrb; /* Root Complex Register Block */
-       uint32_t rcba; /* Root Complex Base Address */
-       uint32_t sbase_addr;
-       uint8_t *sbase;
-
-       pci_read_config_dword(plat->dev, 0xf0, &rcba);
-       /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable. */
-       rcrb = (uint8_t *)(rcba & 0xffffc000);
+       ulong sbase_addr;
+       void *sbase;
 
        /* SBASE is similar */
-       pci_read_config_dword(plat->dev, 0x54, &sbase_addr);
-       sbase = (uint8_t *)(sbase_addr & 0xfffffe00);
+       pch_get_sbase(dev->parent, &sbase_addr);
+       sbase = (void *)sbase_addr;
+       debug("%s: sbase=%p\n", __func__, sbase);
 
-       if (plat->ich_version == 7) {
-               struct ich7_spi_regs *ich7_spi;
+       if (plat->ich_version == PCHV_7) {
+               struct ich7_spi_regs *ich7_spi = sbase;
 
-               ich7_spi = (struct ich7_spi_regs *)(rcrb + 0x3020);
+               ich7_spi = (struct ich7_spi_regs *)sbase;
                ctlr->ichspi_lock = readw(&ich7_spi->spis) & SPIS_LOCK;
                ctlr->opmenu = offsetof(struct ich7_spi_regs, opmenu);
                ctlr->menubytes = sizeof(ich7_spi->opmenu);
@@ -222,13 +165,9 @@ static int ich_init_controller(struct ich_spi_platdata *plat,
                ctlr->bbar = offsetof(struct ich7_spi_regs, bbar);
                ctlr->preop = offsetof(struct ich7_spi_regs, preop);
                ctlr->base = ich7_spi;
-       } else if (plat->ich_version == 9) {
-               struct ich9_spi_regs *ich9_spi;
+       } else if (plat->ich_version == PCHV_9) {
+               struct ich9_spi_regs *ich9_spi = sbase;
 
-               if (plat->use_sbase)
-                       ich9_spi = (struct ich9_spi_regs *)sbase;
-               else
-                       ich9_spi = (struct ich9_spi_regs *)(rcrb + 0x3800);
                ctlr->ichspi_lock = readw(&ich9_spi->hsfs) & HSFS_FLOCKDN;
                ctlr->opmenu = offsetof(struct ich9_spi_regs, opmenu);
                ctlr->menubytes = sizeof(ich9_spi->opmenu);
@@ -252,9 +191,9 @@ static int ich_init_controller(struct ich_spi_platdata *plat,
 
        /* Work out the maximum speed we can support */
        ctlr->max_speed = 20000000;
-       if (plat->ich_version == 9 && ich9_can_do_33mhz(plat->dev))
+       if (plat->ich_version == PCHV_9 && ich9_can_do_33mhz(dev))
                ctlr->max_speed = 33000000;
-       debug("ICH SPI: Version %d detected at %p, speed %ld\n",
+       debug("ICH SPI: Version ID %d detected at %p, speed %ld\n",
              plat->ich_version, ctlr->base, ctlr->max_speed);
 
        ich_set_bbar(ctlr, 0);
@@ -447,7 +386,7 @@ static int ich_spi_xfer(struct udevice *dev, unsigned int bitlen,
                }
                memcpy(trans->cmd, dout, bytes);
                trans->cmd_len = bytes;
-               debug("ICH SPI: Saved %d bytes\n", bytes);
+               debug_trace("ICH SPI: Saved %d bytes\n", bytes);
                return 0;
        }
 
@@ -462,7 +401,7 @@ static int ich_spi_xfer(struct udevice *dev, unsigned int bitlen,
                trans->out = trans->cmd;
                trans->bytesout = trans->cmd_len;
                using_cmd = 1;
-               debug("ICH SPI: Using %d bytes\n", trans->cmd_len);
+               debug_trace("ICH SPI: Using %d bytes\n", trans->cmd_len);
        } else {
                trans->out = dout;
                trans->bytesout = dout ? bytes : 0;
@@ -481,7 +420,7 @@ static int ich_spi_xfer(struct udevice *dev, unsigned int bitlen,
        if (ret < 0)
                return ret;
 
-       if (plat->ich_version == 7)
+       if (plat->ich_version == PCHV_7)
                ich_writew(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status);
        else
                ich_writeb(ctlr, SPIS_CDS | SPIS_FCERR, ctlr->status);
@@ -520,7 +459,7 @@ static int ich_spi_xfer(struct udevice *dev, unsigned int bitlen,
        if (using_cmd && dout && bytes) {
                trans->out = dout;
                trans->bytesout = bytes;
-               debug("ICH SPI: Moving to data, %d bytes\n", bytes);
+               debug_trace("ICH SPI: Moving to data, %d bytes\n", bytes);
        }
 
        /* Preset control fields */
@@ -676,30 +615,30 @@ int spi_write_protect_region(struct udevice *dev, uint32_t lower_limit,
        return 0;
 }
 
-static int ich_spi_probe(struct udevice *bus)
+static int ich_spi_probe(struct udevice *dev)
 {
-       struct ich_spi_platdata *plat = dev_get_platdata(bus);
-       struct ich_spi_priv *priv = dev_get_priv(bus);
+       struct ich_spi_platdata *plat = dev_get_platdata(dev);
+       struct ich_spi_priv *priv = dev_get_priv(dev);
        uint8_t bios_cntl;
        int ret;
 
-       ret = ich_init_controller(plat, priv);
+       /* Check the ICH version */
+       plat->ich_version = pch_get_version(dev->parent);
+
+       ret = ich_init_controller(dev, plat, priv);
        if (ret)
                return ret;
-       /*
-        * Disable the BIOS write protect so write commands are allowed.  On
-        * v9, deassert SMM BIOS Write Protect Disable.
-        */
-       if (plat->use_sbase) {
+       /* Disable the BIOS write protect so write commands are allowed */
+       ret = pch_set_spi_protect(dev->parent, false);
+       if (ret == -ENOSYS) {
                bios_cntl = ich_readb(priv, priv->bcr);
                bios_cntl &= ~BIT(5);   /* clear Enable InSMM_STS (EISS) */
                bios_cntl |= 1;         /* Write Protect Disable (WPD) */
                ich_writeb(priv, bios_cntl, priv->bcr);
-       } else {
-               pci_read_config_byte(plat->dev, 0xdc, &bios_cntl);
-               if (plat->ich_version == 9)
-                       bios_cntl &= ~BIT(5);
-               pci_write_config_byte(plat->dev, 0xdc, bios_cntl | 0x1);
+       } else if (ret) {
+               debug("%s: Failed to disable write-protect: err=%d\n",
+                     __func__, ret);
+               return ret;
        }
 
        priv->cur_speed = priv->max_speed;
@@ -707,18 +646,6 @@ static int ich_spi_probe(struct udevice *bus)
        return 0;
 }
 
-static int ich_spi_ofdata_to_platdata(struct udevice *bus)
-{
-       struct ich_spi_platdata *plat = dev_get_platdata(bus);
-       int ret;
-
-       ret = ich_find_spi_controller(plat);
-       if (ret)
-               return ret;
-
-       return 0;
-}
-
 static int ich_spi_set_speed(struct udevice *bus, uint speed)
 {
        struct ich_spi_priv *priv = dev_get_priv(bus);
@@ -751,7 +678,7 @@ static int ich_spi_child_pre_probe(struct udevice *dev)
         * ICH 7 SPI controller only supports array read command
         * and byte program command for SST flash
         */
-       if (plat->ich_version == 7) {
+       if (plat->ich_version == PCHV_7) {
                slave->mode_rx = SPI_RX_SLOW;
                slave->mode = SPI_TX_BYTE;
        }
@@ -779,7 +706,6 @@ U_BOOT_DRIVER(ich_spi) = {
        .id     = UCLASS_SPI,
        .of_match = ich_spi_ids,
        .ops    = &ich_spi_ops,
-       .ofdata_to_platdata = ich_spi_ofdata_to_platdata,
        .platdata_auto_alloc_size = sizeof(struct ich_spi_platdata),
        .priv_auto_alloc_size = sizeof(struct ich_spi_priv),
        .child_pre_probe = ich_spi_child_pre_probe,
index 8ff949d241f6e9c13c13432d3a54db1bdfba44f2..25ccc01d1b68bbc6fb511ec8b0bc69bb6bebc6fc 100644 (file)
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <asm/dma-mapping.h>
 #include <usb/lin_gadget_compat.h>
+#include <linux/bug.h>
 #include <linux/list.h>
 
 #include <linux/usb/ch9.h>
index 6c9c2791a8bb7b413e61ba1b87e717670da232da..9e944a31be11f4edaccbfc857c493e3808ee3c53 100644 (file)
@@ -17,8 +17,6 @@
 #define dev_WARN(dev, format, arg...)  debug(format, ##arg)
 #define WARN_ON_ONCE(val)              debug("Error %d\n", val)
 
-#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
-
 static inline size_t strlcat(char *dest, const char *src, size_t n)
 {
        strcat(dest, src);
index c92d2b02d261e4254772e7e547c2874a83150815..4c44efc7a15a3aad21de336df7420e4d6a46715a 100644 (file)
@@ -9,3 +9,4 @@ obj-$(CONFIG_USB_ETHER_ASIX) += asix.o
 obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o
 obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o
 obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o
+obj-$(CONFIG_USB_ETHER_RTL8152) += r8152.o r8152_fw.o
diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c
new file mode 100644 (file)
index 0000000..325b70c
--- /dev/null
@@ -0,0 +1,1456 @@
+/*
+ * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved.
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ *
+  */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <usb.h>
+#include <usb/lin_gadget_compat.h>
+#include <linux/mii.h>
+#include <linux/bitops.h>
+#include "usb_ether.h"
+#include "r8152.h"
+
+/* local vars */
+static int curr_eth_dev; /* index for name of next device detected */
+
+struct r8152_dongle {
+       unsigned short vendor;
+       unsigned short product;
+};
+
+struct r8152_version {
+       unsigned short tcr;
+       unsigned short version;
+       bool           gmii;
+};
+
+static const struct r8152_dongle const r8152_dongles[] = {
+       /* Realtek */
+       { 0x0bda, 0x8050 },
+       { 0x0bda, 0x8152 },
+       { 0x0bda, 0x8153 },
+
+       /* Samsung */
+       { 0x04e8, 0xa101 },
+
+       /* Lenovo */
+       { 0x17ef, 0x304f },
+       { 0x17ef, 0x3052 },
+       { 0x17ef, 0x3054 },
+       { 0x17ef, 0x3057 },
+       { 0x17ef, 0x7205 },
+       { 0x17ef, 0x720a },
+       { 0x17ef, 0x720b },
+       { 0x17ef, 0x720c },
+
+       /* TP-LINK */
+       { 0x2357, 0x0601 },
+
+       /* Nvidia */
+       { 0x0955, 0x09ff },
+};
+
+static const struct r8152_version const r8152_versions[] = {
+       { 0x4c00, RTL_VER_01, 0 },
+       { 0x4c10, RTL_VER_02, 0 },
+       { 0x5c00, RTL_VER_03, 1 },
+       { 0x5c10, RTL_VER_04, 1 },
+       { 0x5c20, RTL_VER_05, 1 },
+       { 0x5c30, RTL_VER_06, 1 },
+       { 0x4800, RTL_VER_07, 0 },
+};
+
+static
+int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
+{
+       return usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
+                              RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
+                              value, index, data, size, 500);
+}
+
+static
+int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
+{
+       return usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
+                              RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE,
+                              value, index, data, size, 500);
+}
+
+int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
+                    void *data, u16 type)
+{
+       u16 burst_size = 64;
+       int ret;
+       int txsize;
+
+       /* both size and index must be 4 bytes align */
+       if ((size & 3) || !size || (index & 3) || !data)
+               return -EINVAL;
+
+       if (index + size > 0xffff)
+               return -EINVAL;
+
+       while (size) {
+               txsize = min(size, burst_size);
+               ret = get_registers(tp, index, type, txsize, data);
+               if (ret < 0)
+                       break;
+
+               index += txsize;
+               data += txsize;
+               size -= txsize;
+       }
+
+       return ret;
+}
+
+int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
+                     u16 size, void *data, u16 type)
+{
+       int ret;
+       u16 byteen_start, byteen_end, byte_en_to_hw;
+       u16 burst_size = 512;
+       int txsize;
+
+       /* both size and index must be 4 bytes align */
+       if ((size & 3) || !size || (index & 3) || !data)
+               return -EINVAL;
+
+       if (index + size > 0xffff)
+               return -EINVAL;
+
+       byteen_start = byteen & BYTE_EN_START_MASK;
+       byteen_end = byteen & BYTE_EN_END_MASK;
+
+       byte_en_to_hw = byteen_start | (byteen_start << 4);
+       ret = set_registers(tp, index, type | byte_en_to_hw, 4, data);
+       if (ret < 0)
+               return ret;
+
+       index += 4;
+       data += 4;
+       size -= 4;
+
+       if (size) {
+               size -= 4;
+
+               while (size) {
+                       txsize = min(size, burst_size);
+
+                       ret = set_registers(tp, index,
+                                           type | BYTE_EN_DWORD,
+                                           txsize, data);
+                       if (ret < 0)
+                               return ret;
+
+                       index += txsize;
+                       data += txsize;
+                       size -= txsize;
+               }
+
+               byte_en_to_hw = byteen_end | (byteen_end >> 4);
+               ret = set_registers(tp, index, type | byte_en_to_hw, 4, data);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return ret;
+}
+
+int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
+{
+       return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA);
+}
+
+int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
+{
+       return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA);
+}
+
+int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
+{
+       return generic_ocp_read(tp, index, size, data, MCU_TYPE_USB);
+}
+
+int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
+{
+       return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB);
+}
+
+u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
+{
+       __le32 data;
+
+       generic_ocp_read(tp, index, sizeof(data), &data, type);
+
+       return __le32_to_cpu(data);
+}
+
+void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
+{
+       __le32 tmp = __cpu_to_le32(data);
+
+       generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type);
+}
+
+u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
+{
+       u32 data;
+       __le32 tmp;
+       u8 shift = index & 2;
+
+       index &= ~3;
+
+       generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
+
+       data = __le32_to_cpu(tmp);
+       data >>= (shift * 8);
+       data &= 0xffff;
+
+       return data;
+}
+
+void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
+{
+       u32 mask = 0xffff;
+       __le32 tmp;
+       u16 byen = BYTE_EN_WORD;
+       u8 shift = index & 2;
+
+       data &= mask;
+
+       if (index & 2) {
+               byen <<= shift;
+               mask <<= (shift * 8);
+               data <<= (shift * 8);
+               index &= ~3;
+       }
+
+       tmp = __cpu_to_le32(data);
+
+       generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
+}
+
+u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)
+{
+       u32 data;
+       __le32 tmp;
+       u8 shift = index & 3;
+
+       index &= ~3;
+
+       generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
+
+       data = __le32_to_cpu(tmp);
+       data >>= (shift * 8);
+       data &= 0xff;
+
+       return data;
+}
+
+void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
+{
+       u32 mask = 0xff;
+       __le32 tmp;
+       u16 byen = BYTE_EN_BYTE;
+       u8 shift = index & 3;
+
+       data &= mask;
+
+       if (index & 3) {
+               byen <<= shift;
+               mask <<= (shift * 8);
+               data <<= (shift * 8);
+               index &= ~3;
+       }
+
+       tmp = __cpu_to_le32(data);
+
+       generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
+}
+
+u16 ocp_reg_read(struct r8152 *tp, u16 addr)
+{
+       u16 ocp_base, ocp_index;
+
+       ocp_base = addr & 0xf000;
+       if (ocp_base != tp->ocp_base) {
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
+               tp->ocp_base = ocp_base;
+       }
+
+       ocp_index = (addr & 0x0fff) | 0xb000;
+       return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
+}
+
+void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
+{
+       u16 ocp_base, ocp_index;
+
+       ocp_base = addr & 0xf000;
+       if (ocp_base != tp->ocp_base) {
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
+               tp->ocp_base = ocp_base;
+       }
+
+       ocp_index = (addr & 0x0fff) | 0xb000;
+       ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
+}
+
+static void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+{
+       ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+}
+
+static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+{
+       return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
+}
+
+void sram_write(struct r8152 *tp, u16 addr, u16 data)
+{
+       ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+       ocp_reg_write(tp, OCP_SRAM_DATA, data);
+}
+
+int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index,
+                      const u32 mask, bool set, unsigned int timeout)
+{
+       u32 val;
+
+       while (--timeout) {
+               if (ocp_reg)
+                       val = ocp_reg_read(tp, index);
+               else
+                       val = ocp_read_dword(tp, type, index);
+
+               if (!set)
+                       val = ~val;
+
+               if ((val & mask) == mask)
+                       return 0;
+
+               mdelay(1);
+       }
+
+       debug("%s: Timeout (index=%04x mask=%08x timeout=%d)\n",
+             __func__, index, mask, timeout);
+
+       return -ETIMEDOUT;
+}
+
+static void r8152b_reset_packet_filter(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC);
+       ocp_data &= ~FMC_FCR_MCU_EN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
+       ocp_data |= FMC_FCR_MCU_EN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
+}
+
+static void rtl8152_wait_fifo_empty(struct r8152 *tp)
+{
+       int ret;
+
+       ret = r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_PHY_PWR,
+                                PLA_PHY_PWR_TXEMP, 1, R8152_WAIT_TIMEOUT);
+       if (ret)
+               debug("Timeout waiting for FIFO empty\n");
+
+       ret = r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_TCR0,
+                                TCR0_TX_EMPTY, 1, R8152_WAIT_TIMEOUT);
+       if (ret)
+               debug("Timeout waiting for TX empty\n");
+}
+
+static void rtl8152_nic_reset(struct r8152 *tp)
+{
+       int ret;
+       u32 ocp_data;
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, BIST_CTRL);
+       ocp_data |= BIST_CTRL_SW_RESET;
+       ocp_write_dword(tp, MCU_TYPE_PLA, BIST_CTRL, ocp_data);
+
+       ret = r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, BIST_CTRL,
+                                BIST_CTRL_SW_RESET, 0, R8152_WAIT_TIMEOUT);
+       if (ret)
+               debug("Timeout waiting for NIC reset\n");
+}
+
+static u8 rtl8152_get_speed(struct r8152 *tp)
+{
+       return ocp_read_byte(tp, MCU_TYPE_PLA, PLA_PHYSTATUS);
+}
+
+static void rtl_set_eee_plus(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR);
+       ocp_data &= ~EEEP_CR_EEEP_TX;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data);
+}
+
+static void rxdy_gated_en(struct r8152 *tp, bool enable)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
+       if (enable)
+               ocp_data |= RXDY_GATED_EN;
+       else
+               ocp_data &= ~RXDY_GATED_EN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
+}
+
+static void rtl8152_set_rx_mode(struct r8152 *tp)
+{
+       u32 ocp_data;
+       __le32 tmp[2];
+
+       tmp[0] = 0xffffffff;
+       tmp[1] = 0xffffffff;
+
+       pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp);
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data |= RCR_APM | RCR_AM | RCR_AB;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+}
+
+static int rtl_enable(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       r8152b_reset_packet_filter(tp);
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR);
+       ocp_data |= PLA_CR_RE | PLA_CR_TE;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data);
+
+       rxdy_gated_en(tp, false);
+
+       rtl8152_set_rx_mode(tp);
+
+       return 0;
+}
+
+static int rtl8152_enable(struct r8152 *tp)
+{
+       rtl_set_eee_plus(tp);
+
+       return rtl_enable(tp);
+}
+
+static void r8153_set_rx_early_timeout(struct r8152 *tp)
+{
+       u32 ocp_data = tp->coalesce / 8;
+
+       ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, ocp_data);
+}
+
+static void r8153_set_rx_early_size(struct r8152 *tp)
+{
+       u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS) / 4;
+
+       ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, ocp_data);
+}
+
+static int rtl8153_enable(struct r8152 *tp)
+{
+       rtl_set_eee_plus(tp);
+       r8153_set_rx_early_timeout(tp);
+       r8153_set_rx_early_size(tp);
+
+       return rtl_enable(tp);
+}
+
+static void rtl_disable(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data &= ~RCR_ACPT_ALL;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+
+       rxdy_gated_en(tp, true);
+
+       rtl8152_wait_fifo_empty(tp);
+       rtl8152_nic_reset(tp);
+}
+
+static void r8152_power_cut_en(struct r8152 *tp, bool enable)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
+       if (enable)
+               ocp_data |= POWER_CUT;
+       else
+               ocp_data &= ~POWER_CUT;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
+       ocp_data &= ~RESUME_INDICATE;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
+}
+
+static void rtl_rx_vlan_en(struct r8152 *tp, bool enable)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
+       if (enable)
+               ocp_data |= CPCR_RX_VLAN;
+       else
+               ocp_data &= ~CPCR_RX_VLAN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
+}
+
+static void r8153_u1u2en(struct r8152 *tp, bool enable)
+{
+       u8 u1u2[8];
+
+       if (enable)
+               memset(u1u2, 0xff, sizeof(u1u2));
+       else
+               memset(u1u2, 0x00, sizeof(u1u2));
+
+       usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
+}
+
+static void r8153_u2p3en(struct r8152 *tp, bool enable)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL);
+       if (enable && tp->version != RTL_VER_03 && tp->version != RTL_VER_04)
+               ocp_data |= U2P3_ENABLE;
+       else
+               ocp_data &= ~U2P3_ENABLE;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
+}
+
+static void r8153_power_cut_en(struct r8152 *tp, bool enable)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT);
+       if (enable)
+               ocp_data |= PWR_EN | PHASE2_EN;
+       else
+               ocp_data &= ~(PWR_EN | PHASE2_EN);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
+       ocp_data &= ~PCUT_STATUS;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
+}
+
+static int r8152_read_mac(struct r8152 *tp, unsigned char *macaddr)
+{
+       int ret;
+       unsigned char enetaddr[8] = {0};
+
+       ret = pla_ocp_read(tp, PLA_IDR, 8, enetaddr);
+       if (ret < 0)
+               return ret;
+
+       memcpy(macaddr, enetaddr, ETH_ALEN);
+       return 0;
+}
+
+static void r8152b_disable_aldps(struct r8152 *tp)
+{
+       ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE);
+       mdelay(20);
+}
+
+static void r8152b_enable_aldps(struct r8152 *tp)
+{
+       ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS |
+               LINKENA | DIS_SDSAVE);
+}
+
+static void rtl8152_disable(struct r8152 *tp)
+{
+       r8152b_disable_aldps(tp);
+       rtl_disable(tp);
+       r8152b_enable_aldps(tp);
+}
+
+static void r8152b_hw_phy_cfg(struct r8152 *tp)
+{
+       u16 data;
+
+       data = r8152_mdio_read(tp, MII_BMCR);
+       if (data & BMCR_PDOWN) {
+               data &= ~BMCR_PDOWN;
+               r8152_mdio_write(tp, MII_BMCR, data);
+       }
+
+       r8152b_firmware(tp);
+}
+
+static void rtl8152_reinit_ll(struct r8152 *tp)
+{
+       u32 ocp_data;
+       int ret;
+
+       ret = r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_PHY_PWR,
+                                PLA_PHY_PWR_LLR, 1, R8152_WAIT_TIMEOUT);
+       if (ret)
+               debug("Timeout waiting for link list ready\n");
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
+       ocp_data |= RE_INIT_LL;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
+
+       ret = r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_PHY_PWR,
+                                PLA_PHY_PWR_LLR, 1, R8152_WAIT_TIMEOUT);
+       if (ret)
+               debug("Timeout waiting for link list ready\n");
+}
+
+static void r8152b_exit_oob(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data &= ~RCR_ACPT_ALL;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+
+       rxdy_gated_en(tp, true);
+       r8152b_hw_phy_cfg(tp);
+
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00);
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data &= ~NOW_IS_OOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
+       ocp_data &= ~MCU_BORW_EN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
+
+       rtl8152_reinit_ll(tp);
+       rtl8152_nic_reset(tp);
+
+       /* rx share fifo credit full threshold */
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
+
+       if (tp->udev->speed == USB_SPEED_FULL ||
+           tp->udev->speed == USB_SPEED_LOW) {
+               /* rx share fifo credit near full threshold */
+               ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
+                               RXFIFO_THR2_FULL);
+               ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
+                               RXFIFO_THR3_FULL);
+       } else {
+               /* rx share fifo credit near full threshold */
+               ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
+                               RXFIFO_THR2_HIGH);
+               ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
+                               RXFIFO_THR3_HIGH);
+       }
+
+       /* TX share fifo free credit full threshold */
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL);
+
+       ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA,
+                       TEST_MODE_DISABLE | TX_SIZE_ADJUST1);
+
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
+       ocp_data |= TCR0_AUTO_FIFO;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
+}
+
+static void r8152b_enter_oob(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data &= ~NOW_IS_OOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB);
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB);
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB);
+
+       rtl_disable(tp);
+
+       rtl8152_reinit_ll(tp);
+
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
+
+       rtl_rx_vlan_en(tp, false);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
+       ocp_data |= ALDPS_PROXY_MODE;
+       ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       rxdy_gated_en(tp, false);
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data |= RCR_APM | RCR_AM | RCR_AB;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+}
+
+static void r8153_hw_phy_cfg(struct r8152 *tp)
+{
+       u32 ocp_data;
+       u16 data;
+
+       if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 ||
+           tp->version == RTL_VER_05)
+               ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
+
+       data = r8152_mdio_read(tp, MII_BMCR);
+       if (data & BMCR_PDOWN) {
+               data &= ~BMCR_PDOWN;
+               r8152_mdio_write(tp, MII_BMCR, data);
+       }
+
+       r8153_firmware(tp);
+
+       if (tp->version == RTL_VER_03) {
+               data = ocp_reg_read(tp, OCP_EEE_CFG);
+               data &= ~CTAP_SHORT_EN;
+               ocp_reg_write(tp, OCP_EEE_CFG, data);
+       }
+
+       data = ocp_reg_read(tp, OCP_POWER_CFG);
+       data |= EEE_CLKDIV_EN;
+       ocp_reg_write(tp, OCP_POWER_CFG, data);
+
+       data = ocp_reg_read(tp, OCP_DOWN_SPEED);
+       data |= EN_10M_BGOFF;
+       ocp_reg_write(tp, OCP_DOWN_SPEED, data);
+       data = ocp_reg_read(tp, OCP_POWER_CFG);
+       data |= EN_10M_PLLOFF;
+       ocp_reg_write(tp, OCP_POWER_CFG, data);
+       sram_write(tp, SRAM_IMPEDANCE, 0x0b13);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+       ocp_data |= PFM_PWM_SWITCH;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+
+       /* Enable LPF corner auto tune */
+       sram_write(tp, SRAM_LPF_CFG, 0xf70f);
+
+       /* Adjust 10M Amplitude */
+       sram_write(tp, SRAM_10M_AMP1, 0x00af);
+       sram_write(tp, SRAM_10M_AMP2, 0x0208);
+}
+
+static void r8153_first_init(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       rxdy_gated_en(tp, true);
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data &= ~RCR_ACPT_ALL;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+
+       r8153_hw_phy_cfg(tp);
+
+       rtl8152_nic_reset(tp);
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data &= ~NOW_IS_OOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
+       ocp_data &= ~MCU_BORW_EN;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
+
+       rtl8152_reinit_ll(tp);
+
+       rtl_rx_vlan_en(tp, false);
+
+       ocp_data = RTL8153_RMS;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data);
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
+       ocp_data |= TCR0_AUTO_FIFO;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
+
+       rtl8152_nic_reset(tp);
+
+       /* rx share fifo credit full threshold */
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL);
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL);
+       /* TX share fifo free credit full threshold */
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2);
+
+       /* rx aggregation */
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
+
+       ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
+}
+
+static void r8153_enter_oob(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data &= ~NOW_IS_OOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       rtl_disable(tp);
+
+       rtl8152_reinit_ll(tp);
+
+       ocp_data = RTL8153_RMS;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
+       ocp_data &= ~TEREDO_WAKE_MASK;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
+
+       rtl_rx_vlan_en(tp, false);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
+       ocp_data |= ALDPS_PROXY_MODE;
+       ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+       ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
+
+       rxdy_gated_en(tp, false);
+
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
+       ocp_data |= RCR_APM | RCR_AM | RCR_AB;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
+}
+
+static void r8153_disable_aldps(struct r8152 *tp)
+{
+       u16 data;
+
+       data = ocp_reg_read(tp, OCP_POWER_CFG);
+       data &= ~EN_ALDPS;
+       ocp_reg_write(tp, OCP_POWER_CFG, data);
+       mdelay(20);
+}
+
+static void rtl8153_disable(struct r8152 *tp)
+{
+       r8153_disable_aldps(tp);
+       rtl_disable(tp);
+}
+
+static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
+{
+       u16 bmcr, anar, gbcr;
+
+       anar = r8152_mdio_read(tp, MII_ADVERTISE);
+       anar &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
+                 ADVERTISE_100HALF | ADVERTISE_100FULL);
+       if (tp->supports_gmii) {
+               gbcr = r8152_mdio_read(tp, MII_CTRL1000);
+               gbcr &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
+       } else {
+               gbcr = 0;
+       }
+
+       if (autoneg == AUTONEG_DISABLE) {
+               if (speed == SPEED_10) {
+                       bmcr = 0;
+                       anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
+               } else if (speed == SPEED_100) {
+                       bmcr = BMCR_SPEED100;
+                       anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
+               } else if (speed == SPEED_1000 && tp->supports_gmii) {
+                       bmcr = BMCR_SPEED1000;
+                       gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
+               } else {
+                       return -EINVAL;
+               }
+
+               if (duplex == DUPLEX_FULL)
+                       bmcr |= BMCR_FULLDPLX;
+       } else {
+               if (speed == SPEED_10) {
+                       if (duplex == DUPLEX_FULL)
+                               anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
+                       else
+                               anar |= ADVERTISE_10HALF;
+               } else if (speed == SPEED_100) {
+                       if (duplex == DUPLEX_FULL) {
+                               anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
+                               anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
+                       } else {
+                               anar |= ADVERTISE_10HALF;
+                               anar |= ADVERTISE_100HALF;
+                       }
+               } else if (speed == SPEED_1000 && tp->supports_gmii) {
+                       if (duplex == DUPLEX_FULL) {
+                               anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
+                               anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
+                               gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
+                       } else {
+                               anar |= ADVERTISE_10HALF;
+                               anar |= ADVERTISE_100HALF;
+                               gbcr |= ADVERTISE_1000HALF;
+                       }
+               } else {
+                       return -EINVAL;
+               }
+
+               bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
+       }
+
+       if (tp->supports_gmii)
+               r8152_mdio_write(tp, MII_CTRL1000, gbcr);
+
+       r8152_mdio_write(tp, MII_ADVERTISE, anar);
+       r8152_mdio_write(tp, MII_BMCR, bmcr);
+
+       return 0;
+}
+
+static void rtl8152_up(struct r8152 *tp)
+{
+       r8152b_disable_aldps(tp);
+       r8152b_exit_oob(tp);
+       r8152b_enable_aldps(tp);
+}
+
+static void rtl8152_down(struct r8152 *tp)
+{
+       r8152_power_cut_en(tp, false);
+       r8152b_disable_aldps(tp);
+       r8152b_enter_oob(tp);
+       r8152b_enable_aldps(tp);
+}
+
+static void rtl8153_up(struct r8152 *tp)
+{
+       r8153_u1u2en(tp, false);
+       r8153_disable_aldps(tp);
+       r8153_first_init(tp);
+       r8153_u2p3en(tp, false);
+}
+
+static void rtl8153_down(struct r8152 *tp)
+{
+       r8153_u1u2en(tp, false);
+       r8153_u2p3en(tp, false);
+       r8153_power_cut_en(tp, false);
+       r8153_disable_aldps(tp);
+       r8153_enter_oob(tp);
+}
+
+static void r8152b_get_version(struct r8152 *tp)
+{
+       u32 ocp_data;
+       u16 tcr;
+       int i;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1);
+       tcr = (u16)(ocp_data & VERSION_MASK);
+
+       for (i = 0; i < ARRAY_SIZE(r8152_versions); i++) {
+               if (tcr == r8152_versions[i].tcr) {
+                       /* Found a supported version */
+                       tp->version = r8152_versions[i].version;
+                       tp->supports_gmii = r8152_versions[i].gmii;
+                       break;
+               }
+       }
+
+       if (tp->version == RTL_VER_UNKNOWN)
+               debug("r8152 Unknown tcr version 0x%04x\n", tcr);
+}
+
+static void r8152b_enable_fc(struct r8152 *tp)
+{
+       u16 anar;
+       anar = r8152_mdio_read(tp, MII_ADVERTISE);
+       anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
+       r8152_mdio_write(tp, MII_ADVERTISE, anar);
+}
+
+static void rtl_tally_reset(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY);
+       ocp_data |= TALLY_RESET;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY, ocp_data);
+}
+
+static void r8152b_init(struct r8152 *tp)
+{
+       u32 ocp_data;
+
+       r8152b_disable_aldps(tp);
+
+       if (tp->version == RTL_VER_01) {
+               ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
+               ocp_data &= ~LED_MODE_MASK;
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
+       }
+
+       r8152_power_cut_en(tp, false);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+       ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+       ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL);
+       ocp_data &= ~MCU_CLK_RATIO_MASK;
+       ocp_data |= MCU_CLK_RATIO | D3_CLK_GATED_EN;
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data);
+       ocp_data = GPHY_STS_MSK | SPEED_DOWN_MSK |
+                  SPDWN_RXDV_MSK | SPDWN_LINKCHG_MSK;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_TIMER);
+       ocp_data |= BIT(15);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_USB_TIMER, ocp_data);
+       ocp_write_word(tp, MCU_TYPE_USB, 0xcbfc, 0x03e8);
+       ocp_data &= ~BIT(15);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_USB_TIMER, ocp_data);
+
+       r8152b_enable_fc(tp);
+       rtl_tally_reset(tp);
+
+       /* enable rx aggregation */
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
+
+       ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
+}
+
+static void r8153_init(struct r8152 *tp)
+{
+       int i;
+       u32 ocp_data;
+
+       r8153_disable_aldps(tp);
+       r8153_u1u2en(tp, false);
+
+       r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_BOOT_CTRL,
+                          AUTOLOAD_DONE, 1, R8152_WAIT_TIMEOUT);
+
+       for (i = 0; i < R8152_WAIT_TIMEOUT; i++) {
+               ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
+               if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
+                       break;
+
+               mdelay(1);
+       }
+
+       r8153_u2p3en(tp, false);
+
+       if (tp->version == RTL_VER_04) {
+               ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2);
+               ocp_data &= ~pwd_dn_scale_mask;
+               ocp_data |= pwd_dn_scale(96);
+               ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2, ocp_data);
+
+               ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY);
+               ocp_data |= USB2PHY_L1 | USB2PHY_SUSPEND;
+               ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data);
+       } else if (tp->version == RTL_VER_05) {
+               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0);
+               ocp_data &= ~ECM_ALDPS;
+               ocp_write_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0, ocp_data);
+
+               ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1);
+               if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0)
+                       ocp_data &= ~DYNAMIC_BURST;
+               else
+                       ocp_data |= DYNAMIC_BURST;
+               ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+       } else if (tp->version == RTL_VER_06) {
+               ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1);
+               if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0)
+                       ocp_data &= ~DYNAMIC_BURST;
+               else
+                       ocp_data |= DYNAMIC_BURST;
+               ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+       }
+
+       ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
+       ocp_data |= EP4_FULL_FC;
+       ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL);
+       ocp_data &= ~TIMER11_EN;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
+       ocp_data &= ~LED_MODE_MASK;
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
+
+       ocp_data = FIFO_EMPTY_1FB | ROK_EXIT_LPM;
+       if (tp->version == RTL_VER_04 && tp->udev->speed != USB_SPEED_SUPER)
+               ocp_data |= LPM_TIMER_500MS;
+       else
+               ocp_data |= LPM_TIMER_500US;
+       ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data);
+
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2);
+       ocp_data &= ~SEN_VAL_MASK;
+       ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data);
+
+       ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
+
+       r8153_power_cut_en(tp, false);
+
+       r8152b_enable_fc(tp);
+       rtl_tally_reset(tp);
+}
+
+static void rtl8152_unload(struct r8152 *tp)
+{
+       if (tp->version != RTL_VER_01)
+               r8152_power_cut_en(tp, true);
+}
+
+static void rtl8153_unload(struct r8152 *tp)
+{
+       r8153_power_cut_en(tp, false);
+}
+
+static int rtl_ops_init(struct r8152 *tp)
+{
+       struct rtl_ops *ops = &tp->rtl_ops;
+       int ret = 0;
+
+       switch (tp->version) {
+       case RTL_VER_01:
+       case RTL_VER_02:
+       case RTL_VER_07:
+               ops->init               = r8152b_init;
+               ops->enable             = rtl8152_enable;
+               ops->disable            = rtl8152_disable;
+               ops->up                 = rtl8152_up;
+               ops->down               = rtl8152_down;
+               ops->unload             = rtl8152_unload;
+               break;
+
+       case RTL_VER_03:
+       case RTL_VER_04:
+       case RTL_VER_05:
+       case RTL_VER_06:
+               ops->init               = r8153_init;
+               ops->enable             = rtl8153_enable;
+               ops->disable            = rtl8153_disable;
+               ops->up                 = rtl8153_up;
+               ops->down               = rtl8153_down;
+               ops->unload             = rtl8153_unload;
+               break;
+
+       default:
+               ret = -ENODEV;
+               printf("r8152 Unknown Device\n");
+               break;
+       }
+
+       return ret;
+}
+
+static int r8152_init(struct eth_device *eth, bd_t *bd)
+{
+       struct ueth_data *dev = (struct ueth_data *)eth->priv;
+       struct r8152 *tp = (struct r8152 *)dev->dev_priv;
+
+       u8 speed;
+       int timeout = 0;
+       int link_detected;
+
+       debug("** %s()\n", __func__);
+
+       do {
+               speed = rtl8152_get_speed(tp);
+
+               link_detected = speed & LINK_STATUS;
+               if (!link_detected) {
+                       if (timeout == 0)
+                               printf("Waiting for Ethernet connection... ");
+                       mdelay(TIMEOUT_RESOLUTION);
+                       timeout += TIMEOUT_RESOLUTION;
+               }
+       } while (!link_detected && timeout < PHY_CONNECT_TIMEOUT);
+       if (link_detected) {
+               tp->rtl_ops.enable(tp);
+
+               if (timeout != 0)
+                       printf("done.\n");
+       } else {
+               printf("unable to connect.\n");
+       }
+
+       return 0;
+}
+
+static int r8152_send(struct eth_device *eth, void *packet, int length)
+{
+       struct ueth_data *dev = (struct ueth_data *)eth->priv;
+
+       u32 opts1, opts2 = 0;
+
+       int err;
+
+       int actual_len;
+       unsigned char msg[PKTSIZE + sizeof(struct tx_desc)];
+       struct tx_desc *tx_desc = (struct tx_desc *)msg;
+
+       debug("** %s(), len %d\n", __func__, length);
+
+       opts1 = length | TX_FS | TX_LS;
+
+       tx_desc->opts2 = cpu_to_le32(opts2);
+       tx_desc->opts1 = cpu_to_le32(opts1);
+
+       memcpy(msg + sizeof(struct tx_desc), (void *)packet, length);
+
+       err = usb_bulk_msg(dev->pusb_dev,
+                               usb_sndbulkpipe(dev->pusb_dev, dev->ep_out),
+                               (void *)msg,
+                               length + sizeof(struct tx_desc),
+                               &actual_len,
+                               USB_BULK_SEND_TIMEOUT);
+       debug("Tx: len = %zu, actual = %u, err = %d\n",
+             length + sizeof(struct tx_desc), actual_len, err);
+
+       return err;
+}
+
+static int r8152_recv(struct eth_device *eth)
+{
+       struct ueth_data *dev = (struct ueth_data *)eth->priv;
+
+       static unsigned char  recv_buf[RTL8152_AGG_BUF_SZ];
+       unsigned char *pkt_ptr;
+       int err;
+       int actual_len;
+       u16 packet_len;
+
+       u32 bytes_process = 0;
+       struct rx_desc *rx_desc;
+
+       debug("** %s()\n", __func__);
+
+       err = usb_bulk_msg(dev->pusb_dev,
+                               usb_rcvbulkpipe(dev->pusb_dev, dev->ep_in),
+                               (void *)recv_buf,
+                               RTL8152_AGG_BUF_SZ,
+                               &actual_len,
+                               USB_BULK_RECV_TIMEOUT);
+       debug("Rx: len = %u, actual = %u, err = %d\n", RTL8152_AGG_BUF_SZ,
+             actual_len, err);
+       if (err != 0) {
+               debug("Rx: failed to receive\n");
+               return -1;
+       }
+       if (actual_len > RTL8152_AGG_BUF_SZ) {
+               debug("Rx: received too many bytes %d\n", actual_len);
+               return -1;
+       }
+
+       while (bytes_process < actual_len) {
+               rx_desc = (struct rx_desc *)(recv_buf + bytes_process);
+               pkt_ptr = recv_buf + sizeof(struct rx_desc) + bytes_process;
+
+               packet_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
+               packet_len -= CRC_SIZE;
+
+               net_process_received_packet(pkt_ptr, packet_len);
+
+               bytes_process +=
+                       (packet_len + sizeof(struct rx_desc) + CRC_SIZE);
+
+               if (bytes_process % 8)
+                       bytes_process = bytes_process + 8 - (bytes_process % 8);
+       }
+
+       return 0;
+}
+
+static void r8152_halt(struct eth_device *eth)
+{
+       struct ueth_data *dev = (struct ueth_data *)eth->priv;
+       struct r8152 *tp = (struct r8152 *)dev->dev_priv;
+
+       debug("** %s()\n", __func__);
+
+       tp->rtl_ops.disable(tp);
+}
+
+static int r8152_write_hwaddr(struct eth_device *eth)
+{
+       struct ueth_data *dev = (struct ueth_data *)eth->priv;
+       struct r8152 *tp = (struct r8152 *)dev->dev_priv;
+
+       unsigned char enetaddr[8] = {0};
+
+       memcpy(enetaddr, eth->enetaddr, ETH_ALEN);
+
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
+       pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, enetaddr);
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
+
+       debug("MAC %pM\n", eth->enetaddr);
+       return 0;
+}
+
+void r8152_eth_before_probe(void)
+{
+       curr_eth_dev = 0;
+}
+
+/* Probe to see if a new device is actually an realtek device */
+int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
+                     struct ueth_data *ss)
+{
+       struct usb_interface *iface;
+       struct usb_interface_descriptor *iface_desc;
+       int ep_in_found = 0, ep_out_found = 0;
+       int i;
+
+       struct r8152 *tp;
+
+       /* let's examine the device now */
+       iface = &dev->config.if_desc[ifnum];
+       iface_desc = &dev->config.if_desc[ifnum].desc;
+
+       for (i = 0; i < ARRAY_SIZE(r8152_dongles); i++) {
+               if (dev->descriptor.idVendor == r8152_dongles[i].vendor &&
+                   dev->descriptor.idProduct == r8152_dongles[i].product)
+                       /* Found a supported dongle */
+                       break;
+       }
+
+       if (i == ARRAY_SIZE(r8152_dongles))
+               return 0;
+
+       memset(ss, 0, sizeof(struct ueth_data));
+
+       /* At this point, we know we've got a live one */
+       debug("\n\nUSB Ethernet device detected: %#04x:%#04x\n",
+             dev->descriptor.idVendor, dev->descriptor.idProduct);
+
+       /* Initialize the ueth_data structure with some useful info */
+       ss->ifnum = ifnum;
+       ss->pusb_dev = dev;
+       ss->subclass = iface_desc->bInterfaceSubClass;
+       ss->protocol = iface_desc->bInterfaceProtocol;
+
+       /* alloc driver private */
+       ss->dev_priv = calloc(1, sizeof(struct r8152));
+
+       if (!ss->dev_priv)
+               return 0;
+
+       /*
+        * We are expecting a minimum of 3 endpoints - in, out (bulk), and
+        * int. We will ignore any others.
+        */
+       for (i = 0; i < iface_desc->bNumEndpoints; i++) {
+               /* is it an BULK endpoint? */
+               if ((iface->ep_desc[i].bmAttributes &
+                    USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
+                       u8 ep_addr = iface->ep_desc[i].bEndpointAddress;
+                       if ((ep_addr & USB_DIR_IN) && !ep_in_found) {
+                               ss->ep_in = ep_addr &
+                                       USB_ENDPOINT_NUMBER_MASK;
+                               ep_in_found = 1;
+                       } else {
+                               if (!ep_out_found) {
+                                       ss->ep_out = ep_addr &
+                                               USB_ENDPOINT_NUMBER_MASK;
+                                       ep_out_found = 1;
+                               }
+                       }
+               }
+
+               /* is it an interrupt endpoint? */
+               if ((iface->ep_desc[i].bmAttributes &
+                   USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
+                       ss->ep_int = iface->ep_desc[i].bEndpointAddress &
+                               USB_ENDPOINT_NUMBER_MASK;
+                       ss->irqinterval = iface->ep_desc[i].bInterval;
+               }
+       }
+
+       debug("Endpoints In %d Out %d Int %d\n",
+             ss->ep_in, ss->ep_out, ss->ep_int);
+
+       /* Do some basic sanity checks, and bail if we find a problem */
+       if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
+           !ss->ep_in || !ss->ep_out || !ss->ep_int) {
+               debug("Problems with device\n");
+               return 0;
+       }
+
+       dev->privptr = (void *)ss;
+
+       tp = ss->dev_priv;
+       tp->udev = dev;
+       tp->intf = iface;
+
+       r8152b_get_version(tp);
+
+       if (rtl_ops_init(tp))
+               return 0;
+
+       tp->rtl_ops.init(tp);
+       tp->rtl_ops.up(tp);
+
+       rtl8152_set_speed(tp, AUTONEG_ENABLE,
+                         tp->supports_gmii ? SPEED_1000 : SPEED_100,
+                         DUPLEX_FULL);
+
+       return 1;
+}
+
+int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
+                               struct eth_device *eth)
+{
+       if (!eth) {
+               debug("%s: missing parameter.\n", __func__);
+               return 0;
+       }
+
+       sprintf(eth->name, "%s#%d", R8152_BASE_NAME, curr_eth_dev++);
+       eth->init = r8152_init;
+       eth->send = r8152_send;
+       eth->recv = r8152_recv;
+       eth->halt = r8152_halt;
+       eth->write_hwaddr = r8152_write_hwaddr;
+       eth->priv = ss;
+
+       /* Get the MAC address */
+       if (r8152_read_mac(ss->dev_priv, eth->enetaddr) < 0)
+               return 0;
+
+       debug("MAC %pM\n", eth->enetaddr);
+       return 1;
+}
diff --git a/drivers/usb/eth/r8152.h b/drivers/usb/eth/r8152.h
new file mode 100644 (file)
index 0000000..cd44da2
--- /dev/null
@@ -0,0 +1,631 @@
+/*
+ * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved.
+ *
+ * SPDX-License-Identifier:     GPL-2.0
+ *
+  */
+
+#ifndef _RTL8152_ETH_H
+#define _RTL8152_ETH_H
+
+#define R8152_BASE_NAME                "r8152"
+
+#define PLA_IDR                        0xc000
+#define PLA_RCR                        0xc010
+#define PLA_RMS                        0xc016
+#define PLA_RXFIFO_CTRL0       0xc0a0
+#define PLA_RXFIFO_CTRL1       0xc0a4
+#define PLA_RXFIFO_CTRL2       0xc0a8
+#define PLA_DMY_REG0           0xc0b0
+#define PLA_FMC                        0xc0b4
+#define PLA_CFG_WOL            0xc0b6
+#define PLA_TEREDO_CFG         0xc0bc
+#define PLA_MAR                        0xcd00
+#define PLA_BACKUP             0xd000
+#define PAL_BDC_CR             0xd1a0
+#define PLA_TEREDO_TIMER       0xd2cc
+#define PLA_REALWOW_TIMER      0xd2e8
+#define PLA_LEDSEL             0xdd90
+#define PLA_LED_FEATURE                0xdd92
+#define PLA_PHYAR              0xde00
+#define PLA_BOOT_CTRL          0xe004
+#define PLA_GPHY_INTR_IMR      0xe022
+#define PLA_EEE_CR             0xe040
+#define PLA_EEEP_CR            0xe080
+#define PLA_MAC_PWR_CTRL       0xe0c0
+#define PLA_MAC_PWR_CTRL2      0xe0ca
+#define PLA_MAC_PWR_CTRL3      0xe0cc
+#define PLA_MAC_PWR_CTRL4      0xe0ce
+#define PLA_WDT6_CTRL          0xe428
+#define PLA_TCR0               0xe610
+#define PLA_TCR1               0xe612
+#define PLA_MTPS               0xe615
+#define PLA_TXFIFO_CTRL                0xe618
+#define PLA_RSTTALLY           0xe800
+#define BIST_CTRL              0xe810
+#define PLA_CR                 0xe813
+#define PLA_CRWECR             0xe81c
+#define PLA_CONFIG12           0xe81e  /* CONFIG1, CONFIG2 */
+#define PLA_CONFIG34           0xe820  /* CONFIG3, CONFIG4 */
+#define PLA_CONFIG5            0xe822
+#define PLA_PHY_PWR            0xe84c
+#define PLA_OOB_CTRL           0xe84f
+#define PLA_CPCR               0xe854
+#define PLA_MISC_0             0xe858
+#define PLA_MISC_1             0xe85a
+#define PLA_OCP_GPHY_BASE      0xe86c
+#define PLA_TALLYCNT           0xe890
+#define PLA_SFF_STS_7          0xe8de
+#define PLA_PHYSTATUS          0xe908
+#define PLA_BP_BA              0xfc26
+#define PLA_BP_0               0xfc28
+#define PLA_BP_1               0xfc2a
+#define PLA_BP_2               0xfc2c
+#define PLA_BP_3               0xfc2e
+#define PLA_BP_4               0xfc30
+#define PLA_BP_5               0xfc32
+#define PLA_BP_6               0xfc34
+#define PLA_BP_7               0xfc36
+#define PLA_BP_EN              0xfc38
+
+#define USB_USB2PHY            0xb41e
+#define USB_SSPHYLINK2         0xb428
+#define USB_U2P3_CTRL          0xb460
+#define USB_CSR_DUMMY1         0xb464
+#define USB_CSR_DUMMY2         0xb466
+#define USB_DEV_STAT           0xb808
+#define USB_CONNECT_TIMER      0xcbf8
+#define USB_BURST_SIZE         0xcfc0
+#define USB_USB_CTRL           0xd406
+#define USB_PHY_CTRL           0xd408
+#define USB_TX_AGG             0xd40a
+#define USB_RX_BUF_TH          0xd40c
+#define USB_USB_TIMER          0xd428
+#define USB_RX_EARLY_TIMEOUT   0xd42c
+#define USB_RX_EARLY_SIZE      0xd42e
+#define USB_PM_CTRL_STATUS     0xd432
+#define USB_TX_DMA             0xd434
+#define USB_TOLERANCE          0xd490
+#define USB_LPM_CTRL           0xd41a
+#define USB_UPS_CTRL           0xd800
+#define USB_MISC_0             0xd81a
+#define USB_POWER_CUT          0xd80a
+#define USB_AFE_CTRL2          0xd824
+#define USB_WDT11_CTRL         0xe43c
+#define USB_BP_BA              0xfc26
+#define USB_BP_0               0xfc28
+#define USB_BP_1               0xfc2a
+#define USB_BP_2               0xfc2c
+#define USB_BP_3               0xfc2e
+#define USB_BP_4               0xfc30
+#define USB_BP_5               0xfc32
+#define USB_BP_6               0xfc34
+#define USB_BP_7               0xfc36
+#define USB_BP_EN              0xfc38
+
+/* OCP Registers */
+#define OCP_ALDPS_CONFIG       0x2010
+#define OCP_EEE_CONFIG1                0x2080
+#define OCP_EEE_CONFIG2                0x2092
+#define OCP_EEE_CONFIG3                0x2094
+#define OCP_BASE_MII           0xa400
+#define OCP_EEE_AR             0xa41a
+#define OCP_EEE_DATA           0xa41c
+#define OCP_PHY_STATUS         0xa420
+#define OCP_POWER_CFG          0xa430
+#define OCP_EEE_CFG            0xa432
+#define OCP_SRAM_ADDR          0xa436
+#define OCP_SRAM_DATA          0xa438
+#define OCP_DOWN_SPEED         0xa442
+#define OCP_EEE_ABLE           0xa5c4
+#define OCP_EEE_ADV            0xa5d0
+#define OCP_EEE_LPABLE         0xa5d2
+#define OCP_PHY_STATE          0xa708          /* nway state for 8153 */
+#define OCP_ADC_CFG            0xbc06
+
+/* SRAM Register */
+#define SRAM_LPF_CFG           0x8012
+#define SRAM_10M_AMP1          0x8080
+#define SRAM_10M_AMP2          0x8082
+#define SRAM_IMPEDANCE         0x8084
+
+/* PLA_RCR */
+#define RCR_AAP                        0x00000001
+#define RCR_APM                        0x00000002
+#define RCR_AM                 0x00000004
+#define RCR_AB                 0x00000008
+#define RCR_ACPT_ALL           (RCR_AAP | RCR_APM | RCR_AM | RCR_AB)
+
+/* PLA_RXFIFO_CTRL0 */
+#define RXFIFO_THR1_NORMAL     0x00080002
+#define RXFIFO_THR1_OOB                0x01800003
+
+/* PLA_RXFIFO_CTRL1 */
+#define RXFIFO_THR2_FULL       0x00000060
+#define RXFIFO_THR2_HIGH       0x00000038
+#define RXFIFO_THR2_OOB                0x0000004a
+#define RXFIFO_THR2_NORMAL     0x00a0
+
+/* PLA_RXFIFO_CTRL2 */
+#define RXFIFO_THR3_FULL       0x00000078
+#define RXFIFO_THR3_HIGH       0x00000048
+#define RXFIFO_THR3_OOB                0x0000005a
+#define RXFIFO_THR3_NORMAL     0x0110
+
+/* PLA_TXFIFO_CTRL */
+#define TXFIFO_THR_NORMAL      0x00400008
+#define TXFIFO_THR_NORMAL2     0x01000008
+
+/* PLA_DMY_REG0 */
+#define ECM_ALDPS              0x0002
+
+/* PLA_FMC */
+#define FMC_FCR_MCU_EN         0x0001
+
+/* PLA_EEEP_CR */
+#define EEEP_CR_EEEP_TX                0x0002
+
+/* PLA_WDT6_CTRL */
+#define WDT6_SET_MODE          0x0010
+
+/* PLA_TCR0 */
+#define TCR0_TX_EMPTY          0x0800
+#define TCR0_AUTO_FIFO         0x0080
+
+/* PLA_TCR1 */
+#define VERSION_MASK           0x7cf0
+
+/* PLA_MTPS */
+#define MTPS_JUMBO             (12 * 1024 / 64)
+#define MTPS_DEFAULT           (6 * 1024 / 64)
+
+/* PLA_RSTTALLY */
+#define TALLY_RESET            0x0001
+
+/* PLA_CR */
+#define PLA_CR_RST             0x10
+#define PLA_CR_RE              0x08
+#define PLA_CR_TE              0x04
+
+/* PLA_BIST_CTRL */
+#define BIST_CTRL_SW_RESET (0x10 << 24)
+
+/* PLA_CRWECR */
+#define CRWECR_NORAML          0x00
+#define CRWECR_CONFIG          0xc0
+
+/* PLA_OOB_CTRL */
+#define NOW_IS_OOB             0x80
+#define TXFIFO_EMPTY           0x20
+#define RXFIFO_EMPTY           0x10
+#define LINK_LIST_READY                0x02
+#define DIS_MCU_CLROOB         0x01
+#define FIFO_EMPTY             (TXFIFO_EMPTY | RXFIFO_EMPTY)
+
+/* PLA_PHY_PWR */
+#define PLA_PHY_PWR_LLR        (LINK_LIST_READY << 24)
+#define PLA_PHY_PWR_TXEMP      (TXFIFO_EMPTY << 24)
+
+/* PLA_MISC_1 */
+#define RXDY_GATED_EN          0x0008
+
+/* PLA_SFF_STS_7 */
+#define RE_INIT_LL             0x8000
+#define MCU_BORW_EN            0x4000
+
+/* PLA_CPCR */
+#define CPCR_RX_VLAN           0x0040
+
+/* PLA_CFG_WOL */
+#define MAGIC_EN               0x0001
+
+/* PLA_TEREDO_CFG */
+#define TEREDO_SEL             0x8000
+#define TEREDO_WAKE_MASK       0x7f00
+#define TEREDO_RS_EVENT_MASK   0x00fe
+#define OOB_TEREDO_EN          0x0001
+
+/* PAL_BDC_CR */
+#define ALDPS_PROXY_MODE       0x0001
+
+/* PLA_CONFIG34 */
+#define LINK_ON_WAKE_EN                0x0010
+#define LINK_OFF_WAKE_EN       0x0008
+
+/* PLA_CONFIG5 */
+#define BWF_EN                 0x0040
+#define MWF_EN                 0x0020
+#define UWF_EN                 0x0010
+#define LAN_WAKE_EN            0x0002
+
+/* PLA_LED_FEATURE */
+#define LED_MODE_MASK          0x0700
+
+/* PLA_PHY_PWR */
+#define TX_10M_IDLE_EN         0x0080
+#define PFM_PWM_SWITCH         0x0040
+
+/* PLA_MAC_PWR_CTRL */
+#define D3_CLK_GATED_EN                0x00004000
+#define MCU_CLK_RATIO          0x07010f07
+#define MCU_CLK_RATIO_MASK     0x0f0f0f0f
+#define ALDPS_SPDWN_RATIO      0x0f87
+
+/* PLA_MAC_PWR_CTRL2 */
+#define EEE_SPDWN_RATIO                0x8007
+
+/* PLA_MAC_PWR_CTRL3 */
+#define PKT_AVAIL_SPDWN_EN     0x0100
+#define SUSPEND_SPDWN_EN       0x0004
+#define U1U2_SPDWN_EN          0x0002
+#define L1_SPDWN_EN            0x0001
+
+/* PLA_MAC_PWR_CTRL4 */
+#define PWRSAVE_SPDWN_EN       0x1000
+#define RXDV_SPDWN_EN          0x0800
+#define TX10MIDLE_EN           0x0100
+#define TP100_SPDWN_EN         0x0020
+#define TP500_SPDWN_EN         0x0010
+#define TP1000_SPDWN_EN                0x0008
+#define EEE_SPDWN_EN           0x0001
+
+/* PLA_GPHY_INTR_IMR */
+#define GPHY_STS_MSK           0x0001
+#define SPEED_DOWN_MSK         0x0002
+#define SPDWN_RXDV_MSK         0x0004
+#define SPDWN_LINKCHG_MSK      0x0008
+
+/* PLA_PHYAR */
+#define PHYAR_FLAG             0x80000000
+
+/* PLA_EEE_CR */
+#define EEE_RX_EN              0x0001
+#define EEE_TX_EN              0x0002
+
+/* PLA_BOOT_CTRL */
+#define AUTOLOAD_DONE          0x0002
+
+/* USB_USB2PHY */
+#define USB2PHY_SUSPEND                0x0001
+#define USB2PHY_L1             0x0002
+
+/* USB_SSPHYLINK2 */
+#define pwd_dn_scale_mask      0x3ffe
+#define pwd_dn_scale(x)                ((x) << 1)
+
+/* USB_CSR_DUMMY1 */
+#define DYNAMIC_BURST          0x0001
+
+/* USB_CSR_DUMMY2 */
+#define EP4_FULL_FC            0x0001
+
+/* USB_DEV_STAT */
+#define STAT_SPEED_MASK                0x0006
+#define STAT_SPEED_HIGH                0x0000
+#define STAT_SPEED_FULL                0x0002
+
+/* USB_TX_AGG */
+#define TX_AGG_MAX_THRESHOLD   0x03
+
+/* USB_RX_BUF_TH */
+#define RX_THR_SUPPER          0x0c350180
+#define RX_THR_HIGH            0x7a120180
+#define RX_THR_SLOW            0xffff0180
+
+/* USB_TX_DMA */
+#define TEST_MODE_DISABLE      0x00000001
+#define TX_SIZE_ADJUST1                0x00000100
+
+/* USB_UPS_CTRL */
+#define POWER_CUT              0x0100
+
+/* USB_PM_CTRL_STATUS */
+#define RESUME_INDICATE                0x0001
+
+/* USB_USB_CTRL */
+#define RX_AGG_DISABLE         0x0010
+#define RX_ZERO_EN             0x0080
+
+/* USB_U2P3_CTRL */
+#define U2P3_ENABLE            0x0001
+
+/* USB_POWER_CUT */
+#define PWR_EN                 0x0001
+#define PHASE2_EN              0x0008
+
+/* USB_MISC_0 */
+#define PCUT_STATUS            0x0001
+
+/* USB_RX_EARLY_TIMEOUT */
+#define COALESCE_SUPER          85000U
+#define COALESCE_HIGH          250000U
+#define COALESCE_SLOW          524280U
+
+/* USB_WDT11_CTRL */
+#define TIMER11_EN             0x0001
+
+/* USB_LPM_CTRL */
+/* bit 4 ~ 5: fifo empty boundary */
+#define FIFO_EMPTY_1FB         0x30    /* 0x1fb * 64 = 32448 bytes */
+/* bit 2 ~ 3: LMP timer */
+#define LPM_TIMER_MASK         0x0c
+#define LPM_TIMER_500MS                0x04    /* 500 ms */
+#define LPM_TIMER_500US                0x0c    /* 500 us */
+#define ROK_EXIT_LPM           0x02
+
+/* USB_AFE_CTRL2 */
+#define SEN_VAL_MASK           0xf800
+#define SEN_VAL_NORMAL         0xa000
+#define SEL_RXIDLE             0x0100
+
+/* OCP_ALDPS_CONFIG */
+#define ENPWRSAVE              0x8000
+#define ENPDNPS                        0x0200
+#define LINKENA                        0x0100
+#define DIS_SDSAVE             0x0010
+
+/* OCP_PHY_STATUS */
+#define PHY_STAT_MASK          0x0007
+#define PHY_STAT_LAN_ON                3
+#define PHY_STAT_PWRDN         5
+
+/* OCP_POWER_CFG */
+#define EEE_CLKDIV_EN          0x8000
+#define EN_ALDPS               0x0004
+#define EN_10M_PLLOFF          0x0001
+
+/* OCP_EEE_CONFIG1 */
+#define RG_TXLPI_MSK_HFDUP     0x8000
+#define RG_MATCLR_EN           0x4000
+#define EEE_10_CAP             0x2000
+#define EEE_NWAY_EN            0x1000
+#define TX_QUIET_EN            0x0200
+#define RX_QUIET_EN            0x0100
+#define sd_rise_time_mask      0x0070
+#define sd_rise_time(x)                (min((x), 7) << 4)      /* bit 4 ~ 6 */
+#define RG_RXLPI_MSK_HFDUP     0x0008
+#define SDFALLTIME             0x0007  /* bit 0 ~ 2 */
+
+/* OCP_EEE_CONFIG2 */
+#define RG_LPIHYS_NUM          0x7000  /* bit 12 ~ 15 */
+#define RG_DACQUIET_EN         0x0400
+#define RG_LDVQUIET_EN         0x0200
+#define RG_CKRSEL              0x0020
+#define RG_EEEPRG_EN           0x0010
+
+/* OCP_EEE_CONFIG3 */
+#define fast_snr_mask          0xff80
+#define fast_snr(x)            (min((x), 0x1ff) << 7)  /* bit 7 ~ 15 */
+#define RG_LFS_SEL             0x0060  /* bit 6 ~ 5 */
+#define MSK_PH                 0x0006  /* bit 0 ~ 3 */
+
+/* OCP_EEE_AR */
+/* bit[15:14] function */
+#define FUN_ADDR               0x0000
+#define FUN_DATA               0x4000
+/* bit[4:0] device addr */
+
+/* OCP_EEE_CFG */
+#define CTAP_SHORT_EN          0x0040
+#define EEE10_EN               0x0010
+
+/* OCP_DOWN_SPEED */
+#define EN_10M_BGOFF           0x0080
+
+/* OCP_PHY_STATE */
+#define TXDIS_STATE            0x01
+#define ABD_STATE              0x02
+
+/* OCP_ADC_CFG */
+#define CKADSEL_L              0x0100
+#define ADC_EN                 0x0080
+#define EN_EMI_L               0x0040
+
+/* SRAM_LPF_CFG */
+#define LPF_AUTO_TUNE          0x8000
+
+/* SRAM_10M_AMP1 */
+#define GDAC_IB_UPALL          0x0008
+
+/* SRAM_10M_AMP2 */
+#define AMP_DN                 0x0200
+
+/* SRAM_IMPEDANCE */
+#define RX_DRIVING_MASK                0x6000
+
+#define RTL8152_MAX_TX         4
+#define RTL8152_MAX_RX         10
+#define INTBUFSIZE             2
+#define CRC_SIZE               4
+#define TX_ALIGN               4
+#define RX_ALIGN               8
+
+#define INTR_LINK              0x0004
+
+#define RTL8152_REQT_READ      0xc0
+#define RTL8152_REQT_WRITE     0x40
+#define RTL8152_REQ_GET_REGS   0x05
+#define RTL8152_REQ_SET_REGS   0x05
+
+#define BYTE_EN_DWORD          0xff
+#define BYTE_EN_WORD           0x33
+#define BYTE_EN_BYTE           0x11
+#define BYTE_EN_SIX_BYTES      0x3f
+#define BYTE_EN_START_MASK     0x0f
+#define BYTE_EN_END_MASK       0xf0
+
+#define RTL8152_ETH_FRAME_LEN  1514
+#define RTL8152_AGG_BUF_SZ     2048
+
+#define RTL8152_RMS            (RTL8152_ETH_FRAME_LEN + CRC_SIZE)
+#define RTL8153_RMS            (RTL8152_ETH_FRAME_LEN + CRC_SIZE)
+#define RTL8152_TX_TIMEOUT     (5 * HZ)
+
+#define MCU_TYPE_PLA                   0x0100
+#define MCU_TYPE_USB                   0x0000
+
+/* The forced speed, 10Mb, 100Mb, gigabit. */
+#define SPEED_10                10
+#define SPEED_100               100
+#define SPEED_1000              1000
+
+#define SPEED_UNKNOWN           -1
+
+/* Duplex, half or full. */
+#define DUPLEX_HALF             0x00
+#define DUPLEX_FULL             0x01
+#define DUPLEX_UNKNOWN          0xff
+
+/* Enable or disable autonegotiation. */
+#define AUTONEG_DISABLE         0x00
+#define AUTONEG_ENABLE          0x01
+
+/* Generic MII registers. */
+#define MII_BMCR                0x00    /* Basic mode control register */
+#define MII_BMSR                0x01    /* Basic mode status register  */
+#define MII_PHYSID1             0x02    /* PHYS ID 1                   */
+#define MII_PHYSID2             0x03    /* PHYS ID 2                   */
+#define MII_ADVERTISE           0x04    /* Advertisement control reg   */
+#define MII_LPA                 0x05    /* Link partner ability reg    */
+#define MII_EXPANSION           0x06    /* Expansion register          */
+#define MII_CTRL1000            0x09    /* 1000BASE-T control          */
+#define MII_STAT1000            0x0a    /* 1000BASE-T status           */
+#define MII_MMD_CTRL            0x0d    /* MMD Access Control Register */
+#define MII_MMD_DATA            0x0e    /* MMD Access Data Register */
+#define MII_ESTATUS             0x0f    /* Extended Status             */
+#define MII_DCOUNTER            0x12    /* Disconnect counter          */
+#define MII_FCSCOUNTER          0x13    /* False carrier counter       */
+#define MII_NWAYTEST            0x14    /* N-way auto-neg test reg     */
+#define MII_RERRCOUNTER         0x15    /* Receive error counter       */
+#define MII_SREVISION           0x16    /* Silicon revision            */
+#define MII_RESV1               0x17    /* Reserved...                 */
+#define MII_LBRERROR            0x18    /* Lpback, rx, bypass error    */
+#define MII_PHYADDR             0x19    /* PHY address                 */
+#define MII_RESV2               0x1a    /* Reserved...                 */
+#define MII_TPISTATUS           0x1b    /* TPI status for 10mbps       */
+#define MII_NCONFIG             0x1c    /* Network interface config    */
+
+#define TIMEOUT_RESOLUTION     50
+#define PHY_CONNECT_TIMEOUT     5000
+#define USB_BULK_SEND_TIMEOUT   5000
+#define USB_BULK_RECV_TIMEOUT   5000
+#define R8152_WAIT_TIMEOUT     2000
+
+struct rx_desc {
+       __le32 opts1;
+#define RD_CRC                         BIT(15)
+#define RX_LEN_MASK                    0x7fff
+
+       __le32 opts2;
+#define RD_UDP_CS                      BIT(23)
+#define RD_TCP_CS                      BIT(22)
+#define RD_IPV6_CS                     BIT(20)
+#define RD_IPV4_CS                     BIT(19)
+
+       __le32 opts3;
+#define IPF                            BIT(23) /* IP checksum fail */
+#define UDPF                           BIT(22) /* UDP checksum fail */
+#define TCPF                           BIT(21) /* TCP checksum fail */
+#define RX_VLAN_TAG                    BIT(16)
+
+       __le32 opts4;
+       __le32 opts5;
+       __le32 opts6;
+};
+
+struct tx_desc {
+       __le32 opts1;
+#define TX_FS                  BIT(31) /* First segment of a packet */
+#define TX_LS                  BIT(30) /* Final segment of a packet */
+#define LGSEND                 BIT(29)
+#define GTSENDV4               BIT(28)
+#define GTSENDV6               BIT(27)
+#define GTTCPHO_SHIFT          18
+#define GTTCPHO_MAX            0x7fU
+#define TX_LEN_MAX             0x3ffffU
+
+       __le32 opts2;
+#define UDP_CS                 BIT(31) /* Calculate UDP/IP checksum */
+#define TCP_CS                 BIT(30) /* Calculate TCP/IP checksum */
+#define IPV4_CS                        BIT(29) /* Calculate IPv4 checksum */
+#define IPV6_CS                        BIT(28) /* Calculate IPv6 checksum */
+#define MSS_SHIFT              17
+#define MSS_MAX                        0x7ffU
+#define TCPHO_SHIFT            17
+#define TCPHO_MAX              0x7ffU
+#define TX_VLAN_TAG            BIT(16)
+};
+
+enum rtl_version {
+       RTL_VER_UNKNOWN = 0,
+       RTL_VER_01,
+       RTL_VER_02,
+       RTL_VER_03,
+       RTL_VER_04,
+       RTL_VER_05,
+       RTL_VER_06,
+       RTL_VER_07,
+       RTL_VER_MAX
+};
+
+enum rtl_register_content {
+       _1000bps        = 0x10,
+       _100bps         = 0x08,
+       _10bps          = 0x04,
+       LINK_STATUS     = 0x02,
+       FULL_DUP        = 0x01,
+};
+
+struct r8152 {
+       struct usb_device *udev;
+       struct usb_interface *intf;
+       bool supports_gmii;
+
+       struct rtl_ops {
+               void (*init)(struct r8152 *);
+               int (*enable)(struct r8152 *);
+               void (*disable)(struct r8152 *);
+               void (*up)(struct r8152 *);
+               void (*down)(struct r8152 *);
+               void (*unload)(struct r8152 *);
+       } rtl_ops;
+
+       u32 coalesce;
+       u16 ocp_base;
+
+       u8 version;
+};
+
+int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
+                     u16 size, void *data, u16 type);
+int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
+                    void *data, u16 type);
+
+int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data);
+int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
+                 u16 size, void *data);
+
+int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data);
+int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
+                 u16 size, void *data);
+
+u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index);
+void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data);
+
+u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index);
+void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data);
+
+u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index);
+void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data);
+
+u16 ocp_reg_read(struct r8152 *tp, u16 addr);
+void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data);
+
+void sram_write(struct r8152 *tp, u16 addr, u16 data);
+
+int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index,
+                      const u32 mask, bool set, unsigned int timeout);
+
+void r8152b_firmware(struct r8152 *tp);
+void r8153_firmware(struct r8152 *tp);
+#endif
diff --git a/drivers/usb/eth/r8152_fw.c b/drivers/usb/eth/r8152_fw.c
new file mode 100644 (file)
index 0000000..f820b16
--- /dev/null
@@ -0,0 +1,980 @@
+/*
+ * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved.
+ *
+ * SPDX-License-Identifier:     GPL-2.0
+ *
+  */
+#include <common.h>
+#include <errno.h>
+#include "r8152.h"
+
+static u8 r8152b_pla_patch_a[] = {
+       0x08, 0xe0, 0x40, 0xe0, 0x78, 0xe0, 0x85, 0xe0,
+       0x5d, 0xe1, 0xa1, 0xe1, 0xa3, 0xe1, 0xab, 0xe1,
+       0x31, 0xc3, 0x60, 0x72, 0xa0, 0x49, 0x10, 0xf0,
+       0xa4, 0x49, 0x0e, 0xf0, 0x2c, 0xc3, 0x62, 0x72,
+       0x26, 0x70, 0x80, 0x49, 0x05, 0xf0, 0x2f, 0x48,
+       0x62, 0x9a, 0x24, 0x70, 0x60, 0x98, 0x24, 0xc3,
+       0x60, 0x99, 0x23, 0xc3, 0x00, 0xbb, 0x2c, 0x75,
+       0xdc, 0x21, 0xbc, 0x25, 0x04, 0x13, 0x0a, 0xf0,
+       0x03, 0x13, 0x08, 0xf0, 0x02, 0x13, 0x06, 0xf0,
+       0x01, 0x13, 0x04, 0xf0, 0x08, 0x13, 0x02, 0xf0,
+       0x03, 0xe0, 0xd4, 0x49, 0x04, 0xf1, 0x14, 0xc2,
+       0x12, 0xc3, 0x00, 0xbb, 0x12, 0xc3, 0x60, 0x75,
+       0xd0, 0x49, 0x05, 0xf1, 0x50, 0x48, 0x60, 0x9d,
+       0x09, 0xc6, 0x00, 0xbe, 0xd0, 0x48, 0x60, 0x9d,
+       0xf3, 0xe7, 0xc2, 0xc0, 0x38, 0xd2, 0xc6, 0xd2,
+       0x84, 0x17, 0xa2, 0x13, 0x0c, 0x17, 0xbc, 0xc0,
+       0xa2, 0xd1, 0x33, 0xc5, 0xa0, 0x74, 0xc0, 0x49,
+       0x1f, 0xf0, 0x30, 0xc5, 0xa0, 0x73, 0x00, 0x13,
+       0x04, 0xf1, 0xa2, 0x73, 0x00, 0x13, 0x14, 0xf0,
+       0x28, 0xc5, 0xa0, 0x74, 0xc8, 0x49, 0x1b, 0xf1,
+       0x26, 0xc5, 0xa0, 0x76, 0xa2, 0x74, 0x01, 0x06,
+       0x20, 0x37, 0xa0, 0x9e, 0xa2, 0x9c, 0x1e, 0xc5,
+       0xa2, 0x73, 0x23, 0x40, 0x10, 0xf8, 0x04, 0xf3,
+       0xa0, 0x73, 0x33, 0x40, 0x0c, 0xf8, 0x15, 0xc5,
+       0xa0, 0x74, 0x41, 0x48, 0xa0, 0x9c, 0x14, 0xc5,
+       0xa0, 0x76, 0x62, 0x48, 0xe0, 0x48, 0xa0, 0x9e,
+       0x10, 0xc6, 0x00, 0xbe, 0x0a, 0xc5, 0xa0, 0x74,
+       0x48, 0x48, 0xa0, 0x9c, 0x0b, 0xc5, 0x20, 0x1e,
+       0xa0, 0x9e, 0xe5, 0x48, 0xa0, 0x9e, 0xf0, 0xe7,
+       0xbc, 0xc0, 0xc8, 0xd2, 0xcc, 0xd2, 0x28, 0xe4,
+       0x22, 0x02, 0xf0, 0xc0, 0x0b, 0xc0, 0x00, 0x71,
+       0x0a, 0xc0, 0x00, 0x72, 0xa0, 0x49, 0x04, 0xf0,
+       0xa4, 0x49, 0x02, 0xf0, 0x93, 0x48, 0x04, 0xc0,
+       0x00, 0xb8, 0x00, 0xe4, 0xc2, 0xc0, 0x8c, 0x09,
+       0x14, 0xc2, 0x40, 0x73, 0xba, 0x48, 0x40, 0x9b,
+       0x11, 0xc2, 0x40, 0x73, 0xb0, 0x49, 0x17, 0xf0,
+       0xbf, 0x49, 0x03, 0xf1, 0x09, 0xc5, 0x00, 0xbd,
+       0xb1, 0x49, 0x11, 0xf0, 0xb1, 0x48, 0x40, 0x9b,
+       0x02, 0xc2, 0x00, 0xba, 0x82, 0x18, 0x00, 0xa0,
+       0x1e, 0xfc, 0xbc, 0xc0, 0xf0, 0xc0, 0xde, 0xe8,
+       0x00, 0x80, 0x00, 0x60, 0x2c, 0x75, 0xd4, 0x49,
+       0x12, 0xf1, 0x29, 0xe0, 0xf8, 0xc2, 0x46, 0x71,
+       0xf7, 0xc2, 0x40, 0x73, 0xbe, 0x49, 0x03, 0xf1,
+       0xf5, 0xc7, 0x02, 0xe0, 0xf2, 0xc7, 0x4f, 0x30,
+       0x26, 0x62, 0xa1, 0x49, 0xf0, 0xf1, 0x22, 0x72,
+       0xa0, 0x49, 0xed, 0xf1, 0x25, 0x25, 0x18, 0x1f,
+       0x97, 0x30, 0x91, 0x30, 0x36, 0x9a, 0x2c, 0x75,
+       0x32, 0xc3, 0x60, 0x73, 0xb1, 0x49, 0x0d, 0xf1,
+       0xdc, 0x21, 0xbc, 0x25, 0x27, 0xc6, 0xc0, 0x77,
+       0x04, 0x13, 0x18, 0xf0, 0x03, 0x13, 0x19, 0xf0,
+       0x02, 0x13, 0x1a, 0xf0, 0x01, 0x13, 0x1b, 0xf0,
+       0xd4, 0x49, 0x03, 0xf1, 0x1c, 0xc5, 0x00, 0xbd,
+       0xcd, 0xc6, 0xc6, 0x67, 0x2e, 0x75, 0xd7, 0x22,
+       0xdd, 0x26, 0x05, 0x15, 0x1a, 0xf0, 0x14, 0xc6,
+       0x00, 0xbe, 0x13, 0xc5, 0x00, 0xbd, 0x12, 0xc5,
+       0x00, 0xbd, 0xf1, 0x49, 0xfb, 0xf1, 0xef, 0xe7,
+       0xf4, 0x49, 0xfa, 0xf1, 0xec, 0xe7, 0xf3, 0x49,
+       0xf7, 0xf1, 0xe9, 0xe7, 0xf2, 0x49, 0xf4, 0xf1,
+       0xe6, 0xe7, 0xb6, 0xc0, 0x6a, 0x14, 0xac, 0x13,
+       0xd6, 0x13, 0xfa, 0x14, 0xa0, 0xd1, 0x00, 0x00,
+       0xc0, 0x75, 0xd0, 0x49, 0x46, 0xf0, 0x26, 0x72,
+       0xa7, 0x49, 0x43, 0xf0, 0x22, 0x72, 0x25, 0x25,
+       0x20, 0x1f, 0x97, 0x30, 0x91, 0x30, 0x40, 0x73,
+       0xf3, 0xc4, 0x1c, 0x40, 0x04, 0xf0, 0xd7, 0x49,
+       0x05, 0xf1, 0x37, 0xe0, 0x53, 0x48, 0xc0, 0x9d,
+       0x08, 0x02, 0x40, 0x66, 0x64, 0x27, 0x06, 0x16,
+       0x30, 0xf1, 0x46, 0x63, 0x3b, 0x13, 0x2d, 0xf1,
+       0x34, 0x9b, 0x18, 0x1b, 0x93, 0x30, 0x2b, 0xc3,
+       0x10, 0x1c, 0x2b, 0xe8, 0x01, 0x14, 0x25, 0xf1,
+       0x00, 0x1d, 0x26, 0x1a, 0x8a, 0x30, 0x22, 0x73,
+       0xb5, 0x25, 0x0e, 0x0b, 0x00, 0x1c, 0x2c, 0xe8,
+       0x1f, 0xc7, 0x27, 0x40, 0x1a, 0xf1, 0x38, 0xe8,
+       0x32, 0x1f, 0x8f, 0x30, 0x08, 0x1b, 0x24, 0xe8,
+       0x36, 0x72, 0x46, 0x77, 0x00, 0x17, 0x0d, 0xf0,
+       0x13, 0xc3, 0x1f, 0x40, 0x03, 0xf1, 0x00, 0x1f,
+       0x46, 0x9f, 0x44, 0x77, 0x9f, 0x44, 0x5f, 0x44,
+       0x17, 0xe8, 0x0a, 0xc7, 0x27, 0x40, 0x05, 0xf1,
+       0x02, 0xc3, 0x00, 0xbb, 0x50, 0x1a, 0x06, 0x1a,
+       0xff, 0xc7, 0x00, 0xbf, 0xb8, 0xcd, 0xff, 0xff,
+       0x02, 0x0c, 0x54, 0xa5, 0xdc, 0xa5, 0x2f, 0x40,
+       0x05, 0xf1, 0x00, 0x14, 0xfa, 0xf1, 0x01, 0x1c,
+       0x02, 0xe0, 0x00, 0x1c, 0x80, 0xff, 0xb0, 0x49,
+       0x04, 0xf0, 0x01, 0x0b, 0xd3, 0xa1, 0x03, 0xe0,
+       0x02, 0x0b, 0xd3, 0xa5, 0x27, 0x31, 0x20, 0x37,
+       0x02, 0x0b, 0xd3, 0xa5, 0x27, 0x31, 0x20, 0x37,
+       0x00, 0x13, 0xfb, 0xf1, 0x80, 0xff, 0x22, 0x73,
+       0xb5, 0x25, 0x18, 0x1e, 0xde, 0x30, 0xd9, 0x30,
+       0x64, 0x72, 0x11, 0x1e, 0x68, 0x23, 0x16, 0x31,
+       0x80, 0xff, 0xd4, 0x49, 0x28, 0xf0, 0x02, 0xb4,
+       0x2a, 0xc4, 0x00, 0x1d, 0x2e, 0xe8, 0xe0, 0x73,
+       0xb9, 0x21, 0xbd, 0x25, 0x04, 0x13, 0x02, 0xf0,
+       0x1a, 0xe0, 0x22, 0xc4, 0x23, 0xc3, 0x2f, 0xe8,
+       0x23, 0xc3, 0x2d, 0xe8, 0x00, 0x1d, 0x21, 0xe8,
+       0xe2, 0x73, 0xbb, 0x49, 0xfc, 0xf0, 0xe0, 0x73,
+       0xb7, 0x48, 0x03, 0xb4, 0x81, 0x1d, 0x19, 0xe8,
+       0x40, 0x1a, 0x84, 0x1d, 0x16, 0xe8, 0x12, 0xc3,
+       0x1e, 0xe8, 0x03, 0xb0, 0x81, 0x1d, 0x11, 0xe8,
+       0x0e, 0xc3, 0x19, 0xe8, 0x02, 0xb0, 0x06, 0xc7,
+       0x04, 0x1e, 0xe0, 0x9e, 0x02, 0xc6, 0x00, 0xbe,
+       0x22, 0x02, 0x20, 0xe4, 0x04, 0xb8, 0x34, 0xb0,
+       0x00, 0x02, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x0c,
+       0x09, 0xc7, 0xe0, 0x9b, 0xe2, 0x9a, 0xe4, 0x9c,
+       0xe6, 0x8d, 0xe6, 0x76, 0xef, 0x49, 0xfe, 0xf1,
+       0x80, 0xff, 0x08, 0xea, 0x82, 0x1d, 0xf5, 0xef,
+       0x00, 0x1a, 0x88, 0x1d, 0xf2, 0xef, 0xed, 0xc2,
+       0xf0, 0xef, 0x80, 0xff, 0x02, 0xc6, 0x00, 0xbe,
+       0x46, 0x06, 0x08, 0xc2, 0x40, 0x73, 0x3a, 0x48,
+       0x40, 0x9b, 0x06, 0xff, 0x02, 0xc6, 0x00, 0xbe,
+       0x86, 0x17, 0x1e, 0xfc, 0x36, 0xf0, 0x08, 0x1c,
+       0xea, 0x8c, 0xe3, 0x64, 0xc7, 0x49, 0x25, 0xf1,
+       0xe0, 0x75, 0xff, 0x1b, 0xeb, 0x47, 0xff, 0x1b,
+       0x6b, 0x47, 0xe0, 0x9d, 0x15, 0xc3, 0x60, 0x75,
+       0xd8, 0x49, 0x04, 0xf0, 0x81, 0x1d, 0xe2, 0x8d,
+       0x05, 0xe0, 0xe2, 0x63, 0x81, 0x1d, 0xdd, 0x47,
+       0xe2, 0x8b, 0x0b, 0xc3, 0x00, 0x1d, 0x61, 0x8d,
+       0x3c, 0x03, 0x60, 0x75, 0xd8, 0x49, 0x06, 0xf1,
+       0xdf, 0x48, 0x61, 0x95, 0x16, 0xe0, 0x4e, 0xe8,
+       0x12, 0xe8, 0x21, 0xc5, 0xa0, 0x73, 0xb0, 0x49,
+       0x03, 0xf0, 0x31, 0x48, 0xa0, 0x9b, 0x0d, 0xe0,
+       0xc0, 0x49, 0x0b, 0xf1, 0xe2, 0x63, 0x7e, 0x1d,
+       0xdd, 0x46, 0xe2, 0x8b, 0xe0, 0x75, 0x83, 0x1b,
+       0xeb, 0x46, 0xfe, 0x1b, 0x6b, 0x46, 0xe0, 0x9d,
+       0xe4, 0x49, 0x11, 0xf0, 0x10, 0x1d, 0xea, 0x8d,
+       0xe3, 0x64, 0xc6, 0x49, 0x09, 0xf1, 0x07, 0xc5,
+       0xa0, 0x73, 0xb1, 0x48, 0xa0, 0x9b, 0x02, 0xc5,
+       0x00, 0xbd, 0xe6, 0x04, 0xa0, 0xd1, 0x02, 0xc5,
+       0x00, 0xbd, 0xfe, 0x04, 0x02, 0xc5, 0x00, 0xbd,
+       0x30, 0x05, 0x00, 0x00 };
+
+static u16 r8152b_ram_code1[] = {
+       0x9700, 0x7fe0, 0x4c00, 0x4007, 0x4400, 0x4800, 0x7c1f, 0x4c00,
+       0x5310, 0x6000, 0x7c07, 0x6800, 0x673e, 0x0000, 0x0000, 0x571f,
+       0x5ffb, 0xaa05, 0x5b58, 0x7d80, 0x6100, 0x3019, 0x5b64, 0x7d80,
+       0x6080, 0xa6f8, 0xdcdb, 0x0015, 0xb915, 0xb511, 0xd16b, 0x000f,
+       0xb40f, 0xd06b, 0x000d, 0xb206, 0x7c01, 0x5800, 0x7c04, 0x5c00,
+       0x3011, 0x7c01, 0x5801, 0x7c04, 0x5c04, 0x3019, 0x30a5, 0x3127,
+       0x31d5, 0x7fe0, 0x4c60, 0x7c07, 0x6803, 0x7d00, 0x6900, 0x65a0,
+       0x0000, 0x0000, 0xaf03, 0x6015, 0x303e, 0x6017, 0x57e0, 0x580c,
+       0x588c, 0x7fdd, 0x5fa2, 0x4827, 0x7c1f, 0x4c00, 0x7c1f, 0x4c10,
+       0x8400, 0x7c30, 0x6020, 0x48bf, 0x7c1f, 0x4c00, 0x7c1f, 0x4c01,
+       0x7c07, 0x6803, 0xb806, 0x7c08, 0x6800, 0x0000, 0x0000, 0x305c,
+       0x7c08, 0x6808, 0x0000, 0x0000, 0xae06, 0x7c02, 0x5c02, 0x0000,
+       0x0000, 0x3067, 0x8e05, 0x7c02, 0x5c00, 0x0000, 0x0000, 0xad06,
+       0x7c20, 0x5c20, 0x0000, 0x0000, 0x3072, 0x8d05, 0x7c20, 0x5c00,
+       0x0000, 0x0000, 0xa008, 0x7c07, 0x6800, 0xb8db, 0x7c07, 0x6803,
+       0xd9b3, 0x00d7, 0x7fe0, 0x4c80, 0x7c08, 0x6800, 0x0000, 0x0000,
+       0x7c23, 0x5c23, 0x481d, 0x7c1f, 0x4c00, 0x7c1f, 0x4c02, 0x5310,
+       0x81ff, 0x30f5, 0x7fe0, 0x4d00, 0x4832, 0x7c1f, 0x4c00, 0x7c1f,
+       0x4c10, 0x7c08, 0x6000, 0xa49e, 0x7c07, 0x6800, 0xb89b, 0x7c07,
+       0x6803, 0xd9b3, 0x00f9, 0x7fe0, 0x4d20, 0x7e00, 0x6200, 0x3001,
+       0x7fe0, 0x4dc0, 0xd09d, 0x0002, 0xb4fe, 0x7fe0, 0x4d80, 0x7c04,
+       0x6004, 0x7c07, 0x6802, 0x6728, 0x0000, 0x0000, 0x7c08, 0x6000,
+       0x486c, 0x7c1f, 0x4c00, 0x7c1f, 0x4c01, 0x9503, 0x7e00, 0x6200,
+       0x571f, 0x5fbb, 0xaa05, 0x5b58, 0x7d80, 0x6100, 0x30c2, 0x5b64,
+       0x7d80, 0x6080, 0xcdab, 0x0063, 0xcd8d, 0x0061, 0xd96b, 0x005f,
+       0xd0a0, 0x00d7, 0xcba0, 0x0003, 0x80ec, 0x30cf, 0x30dc, 0x7fe0,
+       0x4ce0, 0x4832, 0x7c1f, 0x4c00, 0x7c1f, 0x4c08, 0x7c08, 0x6008,
+       0x8300, 0xb902, 0x30a5, 0x308a, 0x7fe0, 0x4da0, 0x65a8, 0x0000,
+       0x0000, 0x56a0, 0x590c, 0x7ffd, 0x5fa2, 0xae06, 0x7c02, 0x5c02,
+       0x0000, 0x0000, 0x30f0, 0x8e05, 0x7c02, 0x5c00, 0x0000, 0x0000,
+       0xcba4, 0x0004, 0xcd8d, 0x0002, 0x80f1, 0x7fe0, 0x4ca0, 0x7c08,
+       0x6408, 0x0000, 0x0000, 0x7d00, 0x6800, 0xb603, 0x7c10, 0x6010,
+       0x7d1f, 0x551f, 0x5fb3, 0xaa07, 0x7c80, 0x5800, 0x5b58, 0x7d80,
+       0x6100, 0x310f, 0x7c80, 0x5800, 0x5b64, 0x7d80, 0x6080, 0x4827,
+       0x7c1f, 0x4c00, 0x7c1f, 0x4c10, 0x8400, 0x7c10, 0x6000, 0x7fe0,
+       0x4cc0, 0x5fbb, 0x4824, 0x7c1f, 0x4c00, 0x7c1f, 0x4c04, 0x8200,
+       0x7ce0, 0x5400, 0x6728, 0x0000, 0x0000, 0x30cf, 0x3001, 0x7fe0,
+       0x4e00, 0x4007, 0x4400, 0x5310, 0x7c07, 0x6800, 0x673e, 0x0000,
+       0x0000, 0x570f, 0x5fff, 0xaa05, 0x585b, 0x7d80, 0x6100, 0x313b,
+       0x5867, 0x7d80, 0x6080, 0x9403, 0x7e00, 0x6200, 0xcda3, 0x00e7,
+       0xcd85, 0x00e5, 0xd96b, 0x00e3, 0x96e3, 0x7c07, 0x6800, 0x673e,
+       0x0000, 0x0000, 0x7fe0, 0x4e20, 0x96db, 0x8b04, 0x7c08, 0x5008,
+       0xab03, 0x7c08, 0x5000, 0x7c07, 0x6801, 0x677e, 0x0000, 0x0000,
+       0xdb7c, 0x00ec, 0x0000, 0x7fe1, 0x4f40, 0x4837, 0x4418, 0x41c7,
+       0x7fe0, 0x4e40, 0x7c40, 0x5400, 0x7c1f, 0x4c01, 0x7c1f, 0x4c01,
+       0x8fbf, 0xd2a0, 0x004b, 0x9204, 0xa042, 0x3168, 0x3127, 0x7fe1,
+       0x4f60, 0x489c, 0x4628, 0x7fe0, 0x4e60, 0x7e28, 0x4628, 0x7c40,
+       0x5400, 0x7c01, 0x5800, 0x7c04, 0x5c00, 0x41e8, 0x7c1f, 0x4c01,
+       0x7c1f, 0x4c01, 0x8fa5, 0xb241, 0xa02a, 0x3182, 0x7fe0, 0x4ea0,
+       0x7c02, 0x4402, 0x4448, 0x4894, 0x7c1f, 0x4c01, 0x7c1f, 0x4c03,
+       0x4824, 0x7c1f, 0x4c07, 0x41ef, 0x41ff, 0x4891, 0x7c1f, 0x4c07,
+       0x7c1f, 0x4c17, 0x8400, 0x8ef8, 0x41c7, 0x8f8a, 0x92d5, 0xa10f,
+       0xd480, 0x0008, 0xd580, 0x00b8, 0xa202, 0x319d, 0x7c04, 0x4404,
+       0x319d, 0xd484, 0x00f3, 0xd484, 0x00f1, 0x3127, 0x7fe0, 0x4ee0,
+       0x7c40, 0x5400, 0x4488, 0x41cf, 0x3127, 0x7fe0, 0x4ec0, 0x48f3,
+       0x7c1f, 0x4c01, 0x7c1f, 0x4c09, 0x4508, 0x41c7, 0x8fb0, 0xd218,
+       0x00ae, 0xd2a4, 0x009e, 0x31be, 0x7fe0, 0x4e80, 0x4832, 0x7c1f,
+       0x4c01, 0x7c1f, 0x4c11, 0x4428, 0x7c40, 0x5440, 0x7c01, 0x5801,
+       0x7c04, 0x5c04, 0x41e8, 0xa4b3, 0x31d3, 0x7fe0, 0x4f20, 0x7c07,
+       0x6800, 0x673e, 0x0000, 0x0000, 0x570f, 0x5fff, 0xaa04, 0x585b,
+       0x6100, 0x31e4, 0x5867, 0x6080, 0xbcf1, 0x3001 };
+
+static u16 r8152b_pla_patch_a_bp[] = {
+       0xfc26, 0x8000, 0xfc28, 0x170b, 0xfc2a, 0x01e1, 0xfc2c, 0x0989,
+       0xfc2e, 0x1349, 0xfc30, 0x01b7, 0xfc32, 0x061d, 0xe422, 0x0020,
+       0xe420, 0x0018, 0xfc34, 0x1785, 0xfc36, 0x047b };
+
+static u8 r8152b_pla_patch_a2[] = {
+       0x08, 0xe0, 0x1a, 0xe0, 0xf2, 0xe0, 0xfa, 0xe0,
+       0x32, 0xe1, 0x34, 0xe1, 0x36, 0xe1, 0x38, 0xe1,
+       0x2c, 0x75, 0xdc, 0x21, 0xbc, 0x25, 0x04, 0x13,
+       0x0b, 0xf0, 0x03, 0x13, 0x09, 0xf0, 0x02, 0x13,
+       0x07, 0xf0, 0x01, 0x13, 0x05, 0xf0, 0x08, 0x13,
+       0x03, 0xf0, 0x04, 0xc3, 0x00, 0xbb, 0x03, 0xc3,
+       0x00, 0xbb, 0xd2, 0x17, 0xbc, 0x17, 0x14, 0xc2,
+       0x40, 0x73, 0xba, 0x48, 0x40, 0x9b, 0x11, 0xc2,
+       0x40, 0x73, 0xb0, 0x49, 0x17, 0xf0, 0xbf, 0x49,
+       0x03, 0xf1, 0x09, 0xc5, 0x00, 0xbd, 0xb1, 0x49,
+       0x11, 0xf0, 0xb1, 0x48, 0x40, 0x9b, 0x02, 0xc2,
+       0x00, 0xba, 0x4e, 0x19, 0x00, 0xa0, 0x1e, 0xfc,
+       0xbc, 0xc0, 0xf0, 0xc0, 0xde, 0xe8, 0x00, 0x80,
+       0x00, 0x60, 0x2c, 0x75, 0xd4, 0x49, 0x12, 0xf1,
+       0x29, 0xe0, 0xf8, 0xc2, 0x46, 0x71, 0xf7, 0xc2,
+       0x40, 0x73, 0xbe, 0x49, 0x03, 0xf1, 0xf5, 0xc7,
+       0x02, 0xe0, 0xf2, 0xc7, 0x4f, 0x30, 0x26, 0x62,
+       0xa1, 0x49, 0xf0, 0xf1, 0x22, 0x72, 0xa0, 0x49,
+       0xed, 0xf1, 0x25, 0x25, 0x18, 0x1f, 0x97, 0x30,
+       0x91, 0x30, 0x36, 0x9a, 0x2c, 0x75, 0x32, 0xc3,
+       0x60, 0x73, 0xb1, 0x49, 0x0d, 0xf1, 0xdc, 0x21,
+       0xbc, 0x25, 0x27, 0xc6, 0xc0, 0x77, 0x04, 0x13,
+       0x18, 0xf0, 0x03, 0x13, 0x19, 0xf0, 0x02, 0x13,
+       0x1a, 0xf0, 0x01, 0x13, 0x1b, 0xf0, 0xd4, 0x49,
+       0x03, 0xf1, 0x1c, 0xc5, 0x00, 0xbd, 0xcd, 0xc6,
+       0xc6, 0x67, 0x2e, 0x75, 0xd7, 0x22, 0xdd, 0x26,
+       0x05, 0x15, 0x1a, 0xf0, 0x14, 0xc6, 0x00, 0xbe,
+       0x13, 0xc5, 0x00, 0xbd, 0x12, 0xc5, 0x00, 0xbd,
+       0xf1, 0x49, 0xfb, 0xf1, 0xef, 0xe7, 0xf4, 0x49,
+       0xfa, 0xf1, 0xec, 0xe7, 0xf3, 0x49, 0xf7, 0xf1,
+       0xe9, 0xe7, 0xf2, 0x49, 0xf4, 0xf1, 0xe6, 0xe7,
+       0xb6, 0xc0, 0xf6, 0x14, 0x36, 0x14, 0x62, 0x14,
+       0x86, 0x15, 0xa0, 0xd1, 0x00, 0x00, 0xc0, 0x75,
+       0xd0, 0x49, 0x46, 0xf0, 0x26, 0x72, 0xa7, 0x49,
+       0x43, 0xf0, 0x22, 0x72, 0x25, 0x25, 0x20, 0x1f,
+       0x97, 0x30, 0x91, 0x30, 0x40, 0x73, 0xf3, 0xc4,
+       0x1c, 0x40, 0x04, 0xf0, 0xd7, 0x49, 0x05, 0xf1,
+       0x37, 0xe0, 0x53, 0x48, 0xc0, 0x9d, 0x08, 0x02,
+       0x40, 0x66, 0x64, 0x27, 0x06, 0x16, 0x30, 0xf1,
+       0x46, 0x63, 0x3b, 0x13, 0x2d, 0xf1, 0x34, 0x9b,
+       0x18, 0x1b, 0x93, 0x30, 0x2b, 0xc3, 0x10, 0x1c,
+       0x2b, 0xe8, 0x01, 0x14, 0x25, 0xf1, 0x00, 0x1d,
+       0x26, 0x1a, 0x8a, 0x30, 0x22, 0x73, 0xb5, 0x25,
+       0x0e, 0x0b, 0x00, 0x1c, 0x2c, 0xe8, 0x1f, 0xc7,
+       0x27, 0x40, 0x1a, 0xf1, 0x38, 0xe8, 0x32, 0x1f,
+       0x8f, 0x30, 0x08, 0x1b, 0x24, 0xe8, 0x36, 0x72,
+       0x46, 0x77, 0x00, 0x17, 0x0d, 0xf0, 0x13, 0xc3,
+       0x1f, 0x40, 0x03, 0xf1, 0x00, 0x1f, 0x46, 0x9f,
+       0x44, 0x77, 0x9f, 0x44, 0x5f, 0x44, 0x17, 0xe8,
+       0x0a, 0xc7, 0x27, 0x40, 0x05, 0xf1, 0x02, 0xc3,
+       0x00, 0xbb, 0x1c, 0x1b, 0xd2, 0x1a, 0xff, 0xc7,
+       0x00, 0xbf, 0xb8, 0xcd, 0xff, 0xff, 0x02, 0x0c,
+       0x54, 0xa5, 0xdc, 0xa5, 0x2f, 0x40, 0x05, 0xf1,
+       0x00, 0x14, 0xfa, 0xf1, 0x01, 0x1c, 0x02, 0xe0,
+       0x00, 0x1c, 0x80, 0xff, 0xb0, 0x49, 0x04, 0xf0,
+       0x01, 0x0b, 0xd3, 0xa1, 0x03, 0xe0, 0x02, 0x0b,
+       0xd3, 0xa5, 0x27, 0x31, 0x20, 0x37, 0x02, 0x0b,
+       0xd3, 0xa5, 0x27, 0x31, 0x20, 0x37, 0x00, 0x13,
+       0xfb, 0xf1, 0x80, 0xff, 0x22, 0x73, 0xb5, 0x25,
+       0x18, 0x1e, 0xde, 0x30, 0xd9, 0x30, 0x64, 0x72,
+       0x11, 0x1e, 0x68, 0x23, 0x16, 0x31, 0x80, 0xff,
+       0x08, 0xc2, 0x40, 0x73, 0x3a, 0x48, 0x40, 0x9b,
+       0x06, 0xff, 0x02, 0xc6, 0x00, 0xbe, 0x4e, 0x18,
+       0x1e, 0xfc, 0x33, 0xc5, 0xa0, 0x74, 0xc0, 0x49,
+       0x1f, 0xf0, 0x30, 0xc5, 0xa0, 0x73, 0x00, 0x13,
+       0x04, 0xf1, 0xa2, 0x73, 0x00, 0x13, 0x14, 0xf0,
+       0x28, 0xc5, 0xa0, 0x74, 0xc8, 0x49, 0x1b, 0xf1,
+       0x26, 0xc5, 0xa0, 0x76, 0xa2, 0x74, 0x01, 0x06,
+       0x20, 0x37, 0xa0, 0x9e, 0xa2, 0x9c, 0x1e, 0xc5,
+       0xa2, 0x73, 0x23, 0x40, 0x10, 0xf8, 0x04, 0xf3,
+       0xa0, 0x73, 0x33, 0x40, 0x0c, 0xf8, 0x15, 0xc5,
+       0xa0, 0x74, 0x41, 0x48, 0xa0, 0x9c, 0x14, 0xc5,
+       0xa0, 0x76, 0x62, 0x48, 0xe0, 0x48, 0xa0, 0x9e,
+       0x10, 0xc6, 0x00, 0xbe, 0x0a, 0xc5, 0xa0, 0x74,
+       0x48, 0x48, 0xa0, 0x9c, 0x0b, 0xc5, 0x20, 0x1e,
+       0xa0, 0x9e, 0xe5, 0x48, 0xa0, 0x9e, 0xf0, 0xe7,
+       0xbc, 0xc0, 0xc8, 0xd2, 0xcc, 0xd2, 0x28, 0xe4,
+       0x22, 0x02, 0xf0, 0xc0, 0x02, 0xc6, 0x00, 0xbe,
+       0x00, 0x00, 0x02, 0xc6, 0x00, 0xbe, 0x00, 0x00,
+       0x02, 0xc6, 0x00, 0xbe, 0x00, 0x00, 0x02, 0xc6,
+       0x00, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+static u16 r8152b_pla_patch_a2_bp[] = {
+       0xfc28, 0x8000, 0xfc28, 0x17a5, 0xfc2a, 0x13ad,
+       0xfc2c, 0x184d, 0xfc2e, 0x01e1 };
+
+static u16 r8153_ram_code_a[] = {
+       0xE86C, 0xA000, 0xB436, 0xB820, 0xB438, 0x0290, 0xB436, 0xA012,
+       0xB438, 0x0000, 0xB436, 0xA014, 0xB438, 0x2c04, 0xB438, 0x2c18,
+       0xB438, 0x2c45, 0xB438, 0x2c45, 0xB438, 0xd502, 0xB438, 0x8301,
+       0xB438, 0x8306, 0xB438, 0xd500, 0xB438, 0x8208, 0xB438, 0xd501,
+       0xB438, 0xe018, 0xB438, 0x0308, 0xB438, 0x60f2, 0xB438, 0x8404,
+       0xB438, 0x607d, 0xB438, 0xc117, 0xB438, 0x2c16, 0xB438, 0xc116,
+       0xB438, 0x2c16, 0xB438, 0x607d, 0xB438, 0xc117, 0xB438, 0xa404,
+       0xB438, 0xd500, 0xB438, 0x0800, 0xB438, 0xd501, 0xB438, 0x62d2,
+       0xB438, 0x615d, 0xB438, 0xc115, 0xB438, 0xa404, 0xB438, 0xc307,
+       0xB438, 0xd502, 0xB438, 0x8301, 0xB438, 0x8306, 0xB438, 0xd500,
+       0xB438, 0x8208, 0xB438, 0x2c42, 0xB438, 0xc114, 0xB438, 0x8404,
+       0xB438, 0xc317, 0xB438, 0xd701, 0xB438, 0x435d, 0xB438, 0xd500,
+       0xB438, 0xa208, 0xB438, 0xd502, 0xB438, 0xa306, 0xB438, 0xa301,
+       0xB438, 0x2c42, 0xB438, 0x8404, 0xB438, 0x613d, 0xB438, 0xc115,
+       0xB438, 0xc307, 0xB438, 0xd502, 0xB438, 0x8301, 0xB438, 0x8306,
+       0xB438, 0xd500, 0xB438, 0x8208, 0xB438, 0x2c42, 0xB438, 0xc114,
+       0xB438, 0xc317, 0xB438, 0xd701, 0xB438, 0x40dd, 0xB438, 0xd500,
+       0xB438, 0xa208, 0xB438, 0xd502, 0xB438, 0xa306, 0xB438, 0xa301,
+       0xB438, 0xd500, 0xB438, 0xd702, 0xB438, 0x0800, 0xB436, 0xA01A,
+       0xB438, 0x0000, 0xB436, 0xA006, 0xB438, 0x0fff, 0xB436, 0xA004,
+       0xB438, 0x0fff, 0xB436, 0xA002, 0xB438, 0x05a3, 0xB436, 0xA000,
+       0xB438, 0x3591, 0xB436, 0xB820, 0xB438, 0x0210 };
+
+static u8 r8153_usb_patch_c[] = {
+       0x08, 0xe0, 0x0a, 0xe0, 0x14, 0xe0, 0x2e, 0xe0,
+       0x37, 0xe0, 0x3e, 0xe0, 0x6d, 0xe0, 0x78, 0xe0,
+       0x02, 0xc5, 0x00, 0xbd, 0x38, 0x3b, 0xdb, 0x49,
+       0x04, 0xf1, 0x06, 0xc3, 0x00, 0xbb, 0x5a, 0x02,
+       0x05, 0xc4, 0x03, 0xc3, 0x00, 0xbb, 0xa4, 0x04,
+       0x7e, 0x02, 0x30, 0xd4, 0x30, 0x18, 0x18, 0xc1,
+       0x0c, 0xe8, 0x17, 0xc6, 0xc7, 0x65, 0xd0, 0x49,
+       0x05, 0xf0, 0x32, 0x48, 0x02, 0xc2, 0x00, 0xba,
+       0x3e, 0x16, 0x02, 0xc2, 0x00, 0xba, 0x48, 0x16,
+       0x02, 0xb4, 0x09, 0xc2, 0x40, 0x99, 0x0e, 0x48,
+       0x42, 0x98, 0x42, 0x70, 0x8e, 0x49, 0xfe, 0xf1,
+       0x02, 0xb0, 0x80, 0xff, 0xc0, 0xd4, 0xe4, 0x40,
+       0x20, 0xd4, 0xb0, 0x49, 0x04, 0xf0, 0x30, 0x18,
+       0x06, 0xc1, 0xef, 0xef, 0xfa, 0xc7, 0x02, 0xc0,
+       0x00, 0xb8, 0xd0, 0x10, 0xe4, 0x4b, 0x07, 0xc3,
+       0x70, 0x61, 0x12, 0x48, 0x70, 0x89, 0x02, 0xc3,
+       0x00, 0xbb, 0x9c, 0x15, 0x20, 0xd4, 0x2b, 0xc5,
+       0xa0, 0x77, 0x00, 0x1c, 0xa0, 0x9c, 0x28, 0xc5,
+       0xa0, 0x64, 0xc0, 0x48, 0xc1, 0x48, 0xc2, 0x48,
+       0xa0, 0x8c, 0xb1, 0x64, 0xc0, 0x48, 0xb1, 0x8c,
+       0x20, 0xc5, 0xa0, 0x64, 0x40, 0x48, 0x41, 0x48,
+       0xc2, 0x48, 0xa0, 0x8c, 0x19, 0xc5, 0xa4, 0x64,
+       0x44, 0x48, 0xa4, 0x8c, 0xb1, 0x64, 0x40, 0x48,
+       0xb1, 0x8c, 0x14, 0xc4, 0x80, 0x73, 0x13, 0xc4,
+       0x82, 0x9b, 0x11, 0x1b, 0x80, 0x9b, 0x0c, 0xc5,
+       0xa0, 0x64, 0x40, 0x48, 0x41, 0x48, 0x42, 0x48,
+       0xa0, 0x8c, 0x05, 0xc5, 0xa0, 0x9f, 0x02, 0xc5,
+       0x00, 0xbd, 0x6c, 0x3a, 0x1e, 0xfc, 0x10, 0xd8,
+       0x86, 0xd4, 0xf8, 0xcb, 0x20, 0xe4, 0x0a, 0xc0,
+       0x16, 0x61, 0x91, 0x48, 0x16, 0x89, 0x07, 0xc0,
+       0x11, 0x19, 0x0c, 0x89, 0x02, 0xc1, 0x00, 0xb9,
+       0x02, 0x06, 0x00, 0xd4, 0x40, 0xb4, 0xfe, 0xc0,
+       0x16, 0x61, 0x91, 0x48, 0x16, 0x89, 0xfb, 0xc0,
+       0x11, 0x19, 0x0c, 0x89, 0x02, 0xc1, 0x00, 0xb9,
+       0xd2, 0x05, 0x00, 0x00 };
+
+static u16 r8153_usb_patch_c_bp[] = {
+       0xfc26, 0xa000, 0xfc28, 0x3b34, 0xfc2a, 0x027c, 0xfc2c, 0x162c,
+       0xfc2e, 0x10ce, 0xfc30, 0x0000, 0xfc32, 0x3a28, 0xfc34, 0x05f8,
+       0xfc36, 0x05c8 };
+
+static u8 r8153_pla_patch_c[] = {
+       0x08, 0xe0, 0xea, 0xe0, 0xf2, 0xe0, 0x04, 0xe1,
+       0x06, 0xe1, 0x08, 0xe1, 0x40, 0xe1, 0xf1, 0xe1,
+       0x14, 0xc2, 0x40, 0x73, 0xba, 0x48, 0x40, 0x9b,
+       0x11, 0xc2, 0x40, 0x73, 0xb0, 0x49, 0x17, 0xf0,
+       0xbf, 0x49, 0x03, 0xf1, 0x09, 0xc5, 0x00, 0xbd,
+       0xb1, 0x49, 0x11, 0xf0, 0xb1, 0x48, 0x40, 0x9b,
+       0x02, 0xc2, 0x00, 0xba, 0xde, 0x18, 0x00, 0xe0,
+       0x1e, 0xfc, 0xbc, 0xc0, 0xf0, 0xc0, 0xde, 0xe8,
+       0x00, 0x80, 0x00, 0x20, 0x2c, 0x75, 0xd4, 0x49,
+       0x12, 0xf1, 0x32, 0xe0, 0xf8, 0xc2, 0x46, 0x71,
+       0xf7, 0xc2, 0x40, 0x73, 0xbe, 0x49, 0x03, 0xf1,
+       0xf5, 0xc7, 0x02, 0xe0, 0xf2, 0xc7, 0x4f, 0x30,
+       0x26, 0x62, 0xa1, 0x49, 0xf0, 0xf1, 0x22, 0x72,
+       0xa0, 0x49, 0xed, 0xf1, 0x25, 0x25, 0x18, 0x1f,
+       0x97, 0x30, 0x91, 0x30, 0x36, 0x9a, 0x2c, 0x75,
+       0x3c, 0xc3, 0x60, 0x73, 0xb1, 0x49, 0x0d, 0xf1,
+       0xdc, 0x21, 0xbc, 0x25, 0x30, 0xc6, 0xc0, 0x77,
+       0x04, 0x13, 0x21, 0xf0, 0x03, 0x13, 0x22, 0xf0,
+       0x02, 0x13, 0x23, 0xf0, 0x01, 0x13, 0x24, 0xf0,
+       0x08, 0x13, 0x08, 0xf1, 0x2e, 0x73, 0xba, 0x21,
+       0xbd, 0x25, 0x05, 0x13, 0x03, 0xf1, 0x24, 0xc5,
+       0x00, 0xbd, 0xd4, 0x49, 0x03, 0xf1, 0x1c, 0xc5,
+       0x00, 0xbd, 0xc4, 0xc6, 0xc6, 0x67, 0x2e, 0x75,
+       0xd7, 0x22, 0xdd, 0x26, 0x05, 0x15, 0x1b, 0xf0,
+       0x14, 0xc6, 0x00, 0xbe, 0x13, 0xc5, 0x00, 0xbd,
+       0x12, 0xc5, 0x00, 0xbd, 0xf1, 0x49, 0xfb, 0xf1,
+       0xef, 0xe7, 0xf4, 0x49, 0xfa, 0xf1, 0xec, 0xe7,
+       0xf3, 0x49, 0xf7, 0xf1, 0xe9, 0xe7, 0xf2, 0x49,
+       0xf4, 0xf1, 0xe6, 0xe7, 0xb6, 0xc0, 0x50, 0x14,
+       0x90, 0x13, 0xbc, 0x13, 0xf2, 0x14, 0x00, 0xa0,
+       0xa0, 0xd1, 0x00, 0x00, 0xc0, 0x75, 0xd0, 0x49,
+       0x46, 0xf0, 0x26, 0x72, 0xa7, 0x49, 0x43, 0xf0,
+       0x22, 0x72, 0x25, 0x25, 0x20, 0x1f, 0x97, 0x30,
+       0x91, 0x30, 0x40, 0x73, 0xf3, 0xc4, 0x1c, 0x40,
+       0x04, 0xf0, 0xd7, 0x49, 0x05, 0xf1, 0x37, 0xe0,
+       0x53, 0x48, 0xc0, 0x9d, 0x08, 0x02, 0x40, 0x66,
+       0x64, 0x27, 0x06, 0x16, 0x30, 0xf1, 0x46, 0x63,
+       0x3b, 0x13, 0x2d, 0xf1, 0x34, 0x9b, 0x18, 0x1b,
+       0x93, 0x30, 0x2b, 0xc3, 0x10, 0x1c, 0x2b, 0xe8,
+       0x01, 0x14, 0x25, 0xf1, 0x00, 0x1d, 0x26, 0x1a,
+       0x8a, 0x30, 0x22, 0x73, 0xb5, 0x25, 0x0e, 0x0b,
+       0x00, 0x1c, 0x2c, 0xe8, 0x1f, 0xc7, 0x27, 0x40,
+       0x1a, 0xf1, 0x38, 0xe8, 0x32, 0x1f, 0x8f, 0x30,
+       0x08, 0x1b, 0x24, 0xe8, 0x36, 0x72, 0x46, 0x77,
+       0x00, 0x17, 0x0d, 0xf0, 0x13, 0xc3, 0x1f, 0x40,
+       0x03, 0xf1, 0x00, 0x1f, 0x46, 0x9f, 0x44, 0x77,
+       0x9f, 0x44, 0x5f, 0x44, 0x17, 0xe8, 0x0a, 0xc7,
+       0x27, 0x40, 0x05, 0xf1, 0x02, 0xc3, 0x00, 0xbb,
+       0xbe, 0x1a, 0x74, 0x14, 0xff, 0xc7, 0x00, 0xbf,
+       0xb8, 0xcd, 0xff, 0xff, 0x02, 0x0c, 0x54, 0xa5,
+       0xdc, 0xa5, 0x2f, 0x40, 0x05, 0xf1, 0x00, 0x14,
+       0xfa, 0xf1, 0x01, 0x1c, 0x02, 0xe0, 0x00, 0x1c,
+       0x80, 0xff, 0xb0, 0x49, 0x04, 0xf0, 0x01, 0x0b,
+       0xd3, 0xa1, 0x03, 0xe0, 0x02, 0x0b, 0xd3, 0xa5,
+       0x27, 0x31, 0x20, 0x37, 0x02, 0x0b, 0xd3, 0xa5,
+       0x27, 0x31, 0x20, 0x37, 0x00, 0x13, 0xfb, 0xf1,
+       0x80, 0xff, 0x22, 0x73, 0xb5, 0x25, 0x18, 0x1e,
+       0xde, 0x30, 0xd9, 0x30, 0x64, 0x72, 0x11, 0x1e,
+       0x68, 0x23, 0x16, 0x31, 0x80, 0xff, 0x08, 0xc2,
+       0x40, 0x73, 0x3a, 0x48, 0x40, 0x9b, 0x06, 0xff,
+       0x02, 0xc6, 0x00, 0xbe, 0xcc, 0x17, 0x1e, 0xfc,
+       0x2c, 0x75, 0xdc, 0x21, 0xbc, 0x25, 0x04, 0x13,
+       0x0b, 0xf0, 0x03, 0x13, 0x09, 0xf0, 0x02, 0x13,
+       0x07, 0xf0, 0x01, 0x13, 0x05, 0xf0, 0x08, 0x13,
+       0x03, 0xf0, 0x04, 0xc3, 0x00, 0xbb, 0x03, 0xc3,
+       0x00, 0xbb, 0x50, 0x17, 0x3a, 0x17, 0x02, 0xc6,
+       0x00, 0xbe, 0x00, 0x00, 0x02, 0xc6, 0x00, 0xbe,
+       0x00, 0x00, 0x33, 0xc5, 0xa0, 0x74, 0xc0, 0x49,
+       0x1f, 0xf0, 0x30, 0xc5, 0xa0, 0x73, 0x00, 0x13,
+       0x04, 0xf1, 0xa2, 0x73, 0x00, 0x13, 0x14, 0xf0,
+       0x28, 0xc5, 0xa0, 0x74, 0xc8, 0x49, 0x1b, 0xf1,
+       0x26, 0xc5, 0xa0, 0x76, 0xa2, 0x74, 0x01, 0x06,
+       0x20, 0x37, 0xa0, 0x9e, 0xa2, 0x9c, 0x1e, 0xc5,
+       0xa2, 0x73, 0x23, 0x40, 0x10, 0xf8, 0x04, 0xf3,
+       0xa0, 0x73, 0x33, 0x40, 0x0c, 0xf8, 0x15, 0xc5,
+       0xa0, 0x74, 0x41, 0x48, 0xa0, 0x9c, 0x14, 0xc5,
+       0xa0, 0x76, 0x62, 0x48, 0xe0, 0x48, 0xa0, 0x9e,
+       0x10, 0xc6, 0x00, 0xbe, 0x0a, 0xc5, 0xa0, 0x74,
+       0x48, 0x48, 0xa0, 0x9c, 0x0b, 0xc5, 0x20, 0x1e,
+       0xa0, 0x9e, 0xe5, 0x48, 0xa0, 0x9e, 0xf0, 0xe7,
+       0xbc, 0xc0, 0xc8, 0xd2, 0xcc, 0xd2, 0x28, 0xe4,
+       0xfa, 0x01, 0xf0, 0xc0, 0x18, 0x89, 0x00, 0x1d,
+       0x43, 0xc3, 0x62, 0x62, 0xa0, 0x49, 0x06, 0xf0,
+       0x41, 0xc0, 0x02, 0x71, 0x60, 0x99, 0x3f, 0xc1,
+       0x03, 0xe0, 0x3c, 0xc0, 0x3d, 0xc1, 0x02, 0x99,
+       0x00, 0x61, 0x67, 0x11, 0x3d, 0xf1, 0x69, 0x33,
+       0x34, 0xc0, 0x28, 0x40, 0xf7, 0xf1, 0x35, 0xc0,
+       0x00, 0x19, 0x81, 0x1b, 0x89, 0xe8, 0x32, 0xc0,
+       0x04, 0x1a, 0x84, 0x1b, 0x85, 0xe8, 0x7a, 0xe8,
+       0xa3, 0x49, 0xfe, 0xf0, 0x2c, 0xc0, 0x76, 0xe8,
+       0xa1, 0x48, 0x29, 0xc0, 0x84, 0x1b, 0x7c, 0xe8,
+       0x00, 0x1d, 0x69, 0x33, 0x00, 0x1e, 0x01, 0x06,
+       0xff, 0x18, 0x30, 0x40, 0xfd, 0xf1, 0x7f, 0xc0,
+       0x00, 0x76, 0x2e, 0x40, 0xf7, 0xf1, 0x21, 0x48,
+       0x1a, 0xc0, 0x84, 0x1b, 0x6d, 0xe8, 0x76, 0xc0,
+       0x61, 0xe8, 0xa1, 0x49, 0xfd, 0xf0, 0x12, 0xc0,
+       0x00, 0x1a, 0x84, 0x1b, 0x65, 0xe8, 0x5a, 0xe8,
+       0xa5, 0x49, 0xfe, 0xf0, 0x0a, 0xc0, 0x01, 0x19,
+       0x81, 0x1b, 0x5e, 0xe8, 0x48, 0xe0, 0x8c, 0xd3,
+       0xb8, 0x0b, 0x50, 0xe8, 0x83, 0x00, 0x82, 0x00,
+       0x20, 0xb4, 0x10, 0xd8, 0x84, 0xd4, 0xfa, 0xc0,
+       0x00, 0x61, 0x9c, 0x20, 0x9c, 0x24, 0x06, 0x11,
+       0x06, 0xf1, 0x5d, 0xc0, 0x00, 0x61, 0x11, 0x48,
+       0x00, 0x89, 0x35, 0xe0, 0x00, 0x11, 0x02, 0xf1,
+       0x03, 0xe0, 0x04, 0x11, 0x06, 0xf1, 0x53, 0xc0,
+       0x00, 0x61, 0x92, 0x48, 0x00, 0x89, 0x2b, 0xe0,
+       0x05, 0x11, 0x08, 0xf1, 0x4c, 0xc0, 0x00, 0x61,
+       0x91, 0x49, 0x04, 0xf0, 0x91, 0x48, 0x00, 0x89,
+       0x11, 0xe0, 0xdc, 0xc0, 0x00, 0x61, 0x98, 0x20,
+       0x98, 0x24, 0x25, 0x11, 0x1c, 0xf1, 0x40, 0xc0,
+       0x25, 0xe8, 0x95, 0x49, 0x18, 0xf0, 0xd2, 0xc0,
+       0x00, 0x61, 0x98, 0x20, 0x98, 0x24, 0x25, 0x11,
+       0x12, 0xf1, 0x35, 0xc0, 0x00, 0x61, 0x92, 0x49,
+       0x0e, 0xf1, 0x12, 0x48, 0x00, 0x89, 0x2d, 0xc0,
+       0x00, 0x19, 0x00, 0x89, 0x2b, 0xc0, 0x01, 0x89,
+       0x27, 0xc0, 0x10, 0xe8, 0x25, 0xc0, 0x12, 0x48,
+       0x81, 0x1b, 0x16, 0xe8, 0xb9, 0xc3, 0x62, 0x62,
+       0xa0, 0x49, 0x05, 0xf0, 0xb5, 0xc3, 0x60, 0x71,
+       0xb5, 0xc0, 0x02, 0x99, 0x02, 0xc0, 0x00, 0xb8,
+       0xd6, 0x07, 0x13, 0xc4, 0x84, 0x98, 0x00, 0x1b,
+       0x86, 0x8b, 0x86, 0x73, 0xbf, 0x49, 0xfe, 0xf1,
+       0x80, 0x71, 0x82, 0x72, 0x80, 0xff, 0x09, 0xc4,
+       0x84, 0x98, 0x80, 0x99, 0x82, 0x9a, 0x86, 0x8b,
+       0x86, 0x73, 0xbf, 0x49, 0xfe, 0xf1, 0x80, 0xff,
+       0x08, 0xea, 0x10, 0xd4, 0x88, 0xd3, 0x30, 0xd4,
+       0x10, 0xc0, 0x12, 0xe8, 0x8a, 0xd3, 0x00, 0xd8,
+       0x02, 0xc0, 0x00, 0xb8, 0xe0, 0x08, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+static u16 r8153_pla_patch_c_bp[] = {
+       0xfc26, 0x8000, 0xfc28, 0x1306, 0xfc2a, 0x17ca, 0xfc2c, 0x171e,
+       0xfc2e, 0x0000, 0xfc30, 0x0000, 0xfc32, 0x01b4, 0xfc34, 0x07d4,
+       0xfc36, 0x0894, 0xfc38, 0x00e7 };
+
+static u16 r8153_ram_code_bc[] = {
+       0xB436, 0xB820, 0xB438, 0x0290, 0xB436, 0xA012, 0xB438, 0x0000,
+       0xB436, 0xA014, 0xB438, 0x2c04, 0xB438, 0x2c07, 0xB438, 0x2c0a,
+       0xB438, 0x2c0d, 0xB438, 0xa240, 0xB438, 0xa104, 0xB438, 0x292d,
+       0xB438, 0x8620, 0xB438, 0xa480, 0xB438, 0x2a2c, 0xB438, 0x8480,
+       0xB438, 0xa101, 0xB438, 0x2a36, 0xB438, 0xd056, 0xB438, 0x2223,
+       0xB436, 0xA01A, 0xB438, 0x0000, 0xB436, 0xA006, 0xB438, 0x0222,
+       0xB436, 0xA004, 0xB438, 0x0a35, 0xB436, 0xA002, 0xB438, 0x0a2b,
+       0xB436, 0xA000, 0xB438, 0xf92c, 0xB436, 0xB820, 0xB438, 0x0210 };
+
+static u8 r8153_usb_patch_b[] = {
+       0x08, 0xe0, 0x0f, 0xe0, 0x18, 0xe0, 0x24, 0xe0,
+       0x26, 0xe0, 0x3a, 0xe0, 0x84, 0xe0, 0x9c, 0xe0,
+       0xc2, 0x49, 0x04, 0xf0, 0x02, 0xc0, 0x00, 0xb8,
+       0x14, 0x18, 0x02, 0xc0, 0x00, 0xb8, 0x2e, 0x18,
+       0x06, 0x89, 0x08, 0xc0, 0x0c, 0x61, 0x92, 0x48,
+       0x93, 0x48, 0x0c, 0x89, 0x02, 0xc0, 0x00, 0xb8,
+       0x08, 0x05, 0x40, 0xb4, 0x16, 0x89, 0x6d, 0xc0,
+       0x00, 0x61, 0x95, 0x49, 0x06, 0xf0, 0xfa, 0xc0,
+       0x0c, 0x61, 0x92, 0x48, 0x93, 0x48, 0x0c, 0x89,
+       0x02, 0xc0, 0x00, 0xb8, 0xe2, 0x04, 0x02, 0xc2,
+       0x00, 0xba, 0xec, 0x11, 0x60, 0x60, 0x85, 0x49,
+       0x0d, 0xf1, 0x11, 0xc6, 0xd2, 0x61, 0x91, 0x49,
+       0xfd, 0xf0, 0x74, 0x60, 0x04, 0x48, 0x74, 0x88,
+       0x08, 0xc6, 0x08, 0xc0, 0xc4, 0x98, 0x01, 0x18,
+       0xc0, 0x88, 0x02, 0xc0, 0x00, 0xb8, 0x6e, 0x12,
+       0x04, 0xe4, 0x0d, 0x00, 0x00, 0xd4, 0xd1, 0x49,
+       0x3c, 0xf1, 0xd2, 0x49, 0x16, 0xf1, 0xd3, 0x49,
+       0x18, 0xf1, 0xd4, 0x49, 0x19, 0xf1, 0xd5, 0x49,
+       0x1a, 0xf1, 0xd6, 0x49, 0x1b, 0xf1, 0xd7, 0x49,
+       0x1c, 0xf1, 0xd8, 0x49, 0x1d, 0xf1, 0xd9, 0x49,
+       0x20, 0xf1, 0xda, 0x49, 0x23, 0xf1, 0xdb, 0x49,
+       0x24, 0xf1, 0x02, 0xc4, 0x00, 0xbc, 0x20, 0x04,
+       0xe5, 0x8e, 0x02, 0xc4, 0x00, 0xbc, 0x14, 0x02,
+       0x02, 0xc4, 0x00, 0xbc, 0x16, 0x02, 0x02, 0xc4,
+       0x00, 0xbc, 0x18, 0x02, 0x02, 0xc4, 0x00, 0xbc,
+       0x1a, 0x02, 0x02, 0xc4, 0x00, 0xbc, 0x1c, 0x02,
+       0x02, 0xc4, 0x00, 0xbc, 0x94, 0x02, 0x10, 0xc7,
+       0xe0, 0x8e, 0x02, 0xc4, 0x00, 0xbc, 0x8a, 0x02,
+       0x0b, 0xc7, 0xe4, 0x8e, 0x02, 0xc4, 0x00, 0xbc,
+       0x88, 0x02, 0x02, 0xc4, 0x00, 0xbc, 0x6e, 0x02,
+       0x02, 0xc4, 0x00, 0xbc, 0x5a, 0x02, 0x30, 0xe4,
+       0x0c, 0xc3, 0x60, 0x64, 0xc5, 0x49, 0x04, 0xf1,
+       0x74, 0x64, 0xc4, 0x48, 0x74, 0x8c, 0x06, 0xc3,
+       0x64, 0x8e, 0x02, 0xc4, 0x00, 0xbc, 0x20, 0x04,
+       0x00, 0xd8, 0x00, 0xe4, 0xb2, 0xc0, 0x00, 0x61,
+       0x90, 0x49, 0x09, 0xf1, 0x8b, 0xc6, 0xca, 0x61,
+       0x94, 0x49, 0x0e, 0xf1, 0xf6, 0xc6, 0xda, 0x60,
+       0x81, 0x49, 0x0a, 0xf0, 0x65, 0x60, 0x03, 0x48,
+       0x65, 0x88, 0xef, 0xc6, 0xdc, 0x60, 0x80, 0x48,
+       0xdc, 0x88, 0x05, 0xc6, 0x00, 0xbe, 0x02, 0xc6,
+       0x00, 0xbe, 0x36, 0x13, 0x4c, 0x17, 0x99, 0xc4,
+       0x80, 0x65, 0xd0, 0x49, 0x04, 0xf1, 0xfa, 0x75,
+       0x04, 0xc4, 0x00, 0xbc, 0x03, 0xc4, 0x00, 0xbc,
+       0x9a, 0x00, 0xee, 0x01 };
+
+static u16 r8153_usb_patch_b_bp[] = {
+       0xfc26, 0xa000, 0xfc28, 0x180c, 0xfc2a, 0x0506, 0xfc2c, 0x04E0,
+       0xfc2e, 0x11E4, 0xfc30, 0x125C, 0xfc32, 0x0232, 0xfc34, 0x131E,
+       0xfc36, 0x0098, 0xfc38, 0x00FF };
+
+static u8 r8153_pla_patch_b[] = {
+       0x08, 0xe0, 0xea, 0xe0, 0xf2, 0xe0, 0x04, 0xe1,
+       0x09, 0xe1, 0x0e, 0xe1, 0x46, 0xe1, 0xf3, 0xe1,
+       0x14, 0xc2, 0x40, 0x73, 0xba, 0x48, 0x40, 0x9b,
+       0x11, 0xc2, 0x40, 0x73, 0xb0, 0x49, 0x17, 0xf0,
+       0xbf, 0x49, 0x03, 0xf1, 0x09, 0xc5, 0x00, 0xbd,
+       0xb1, 0x49, 0x11, 0xf0, 0xb1, 0x48, 0x40, 0x9b,
+       0x02, 0xc2, 0x00, 0xba, 0x1a, 0x17, 0x00, 0xe0,
+       0x1e, 0xfc, 0xbc, 0xc0, 0xf0, 0xc0, 0xde, 0xe8,
+       0x00, 0x80, 0x00, 0x20, 0x2c, 0x75, 0xd4, 0x49,
+       0x12, 0xf1, 0x32, 0xe0, 0xf8, 0xc2, 0x46, 0x71,
+       0xf7, 0xc2, 0x40, 0x73, 0xbe, 0x49, 0x03, 0xf1,
+       0xf5, 0xc7, 0x02, 0xe0, 0xf2, 0xc7, 0x4f, 0x30,
+       0x26, 0x62, 0xa1, 0x49, 0xf0, 0xf1, 0x22, 0x72,
+       0xa0, 0x49, 0xed, 0xf1, 0x25, 0x25, 0x18, 0x1f,
+       0x97, 0x30, 0x91, 0x30, 0x36, 0x9a, 0x2c, 0x75,
+       0x3c, 0xc3, 0x60, 0x73, 0xb1, 0x49, 0x0d, 0xf1,
+       0xdc, 0x21, 0xbc, 0x25, 0x30, 0xc6, 0xc0, 0x77,
+       0x04, 0x13, 0x21, 0xf0, 0x03, 0x13, 0x22, 0xf0,
+       0x02, 0x13, 0x23, 0xf0, 0x01, 0x13, 0x24, 0xf0,
+       0x08, 0x13, 0x08, 0xf1, 0x2e, 0x73, 0xba, 0x21,
+       0xbd, 0x25, 0x05, 0x13, 0x03, 0xf1, 0x24, 0xc5,
+       0x00, 0xbd, 0xd4, 0x49, 0x03, 0xf1, 0x1c, 0xc5,
+       0x00, 0xbd, 0xc4, 0xc6, 0xc6, 0x67, 0x2e, 0x75,
+       0xd7, 0x22, 0xdd, 0x26, 0x05, 0x15, 0x1b, 0xf0,
+       0x14, 0xc6, 0x00, 0xbe, 0x13, 0xc5, 0x00, 0xbd,
+       0x12, 0xc5, 0x00, 0xbd, 0xf1, 0x49, 0xfb, 0xf1,
+       0xef, 0xe7, 0xf4, 0x49, 0xfa, 0xf1, 0xec, 0xe7,
+       0xf3, 0x49, 0xf7, 0xf1, 0xe9, 0xe7, 0xf2, 0x49,
+       0xf4, 0xf1, 0xe6, 0xe7, 0xb6, 0xc0, 0x9e, 0x12,
+       0xde, 0x11, 0x0a, 0x12, 0x3c, 0x13, 0x00, 0xa0,
+       0xa0, 0xd1, 0x00, 0x00, 0xc0, 0x75, 0xd0, 0x49,
+       0x46, 0xf0, 0x26, 0x72, 0xa7, 0x49, 0x43, 0xf0,
+       0x22, 0x72, 0x25, 0x25, 0x20, 0x1f, 0x97, 0x30,
+       0x91, 0x30, 0x40, 0x73, 0xf3, 0xc4, 0x1c, 0x40,
+       0x04, 0xf0, 0xd7, 0x49, 0x05, 0xf1, 0x37, 0xe0,
+       0x53, 0x48, 0xc0, 0x9d, 0x08, 0x02, 0x40, 0x66,
+       0x64, 0x27, 0x06, 0x16, 0x30, 0xf1, 0x46, 0x63,
+       0x3b, 0x13, 0x2d, 0xf1, 0x34, 0x9b, 0x18, 0x1b,
+       0x93, 0x30, 0x2b, 0xc3, 0x10, 0x1c, 0x2b, 0xe8,
+       0x01, 0x14, 0x25, 0xf1, 0x00, 0x1d, 0x26, 0x1a,
+       0x8a, 0x30, 0x22, 0x73, 0xb5, 0x25, 0x0e, 0x0b,
+       0x00, 0x1c, 0x2c, 0xe8, 0x1f, 0xc7, 0x27, 0x40,
+       0x1a, 0xf1, 0x38, 0xe8, 0x32, 0x1f, 0x8f, 0x30,
+       0x08, 0x1b, 0x24, 0xe8, 0x36, 0x72, 0x46, 0x77,
+       0x00, 0x17, 0x0d, 0xf0, 0x13, 0xc3, 0x1f, 0x40,
+       0x03, 0xf1, 0x00, 0x1f, 0x46, 0x9f, 0x44, 0x77,
+       0x9f, 0x44, 0x5f, 0x44, 0x17, 0xe8, 0x0a, 0xc7,
+       0x27, 0x40, 0x05, 0xf1, 0x02, 0xc3, 0x00, 0xbb,
+       0xfa, 0x18, 0xb0, 0x18, 0xff, 0xc7, 0x00, 0xbf,
+       0xb8, 0xcd, 0xff, 0xff, 0x02, 0x0c, 0x54, 0xa5,
+       0xdc, 0xa5, 0x2f, 0x40, 0x05, 0xf1, 0x00, 0x14,
+       0xfa, 0xf1, 0x01, 0x1c, 0x02, 0xe0, 0x00, 0x1c,
+       0x80, 0xff, 0xb0, 0x49, 0x04, 0xf0, 0x01, 0x0b,
+       0xd3, 0xa1, 0x03, 0xe0, 0x02, 0x0b, 0xd3, 0xa5,
+       0x27, 0x31, 0x20, 0x37, 0x02, 0x0b, 0xd3, 0xa5,
+       0x27, 0x31, 0x20, 0x37, 0x00, 0x13, 0xfb, 0xf1,
+       0x80, 0xff, 0x22, 0x73, 0xb5, 0x25, 0x18, 0x1e,
+       0xde, 0x30, 0xd9, 0x30, 0x64, 0x72, 0x11, 0x1e,
+       0x68, 0x23, 0x16, 0x31, 0x80, 0xff, 0x08, 0xc2,
+       0x40, 0x73, 0x3a, 0x48, 0x40, 0x9b, 0x06, 0xff,
+       0x02, 0xc6, 0x00, 0xbe, 0x08, 0x16, 0x1e, 0xfc,
+       0x2c, 0x75, 0xdc, 0x21, 0xbc, 0x25, 0x04, 0x13,
+       0x0b, 0xf0, 0x03, 0x13, 0x09, 0xf0, 0x02, 0x13,
+       0x07, 0xf0, 0x01, 0x13, 0x05, 0xf0, 0x08, 0x13,
+       0x03, 0xf0, 0x04, 0xc3, 0x00, 0xbb, 0x03, 0xc3,
+       0x00, 0xbb, 0x8c, 0x15, 0x76, 0x15, 0xa0, 0x64,
+       0x40, 0x48, 0xa0, 0x8c, 0x02, 0xc4, 0x00, 0xbc,
+       0x82, 0x00, 0xa0, 0x62, 0x21, 0x48, 0xa0, 0x8a,
+       0x02, 0xc2, 0x00, 0xba, 0x40, 0x03, 0x33, 0xc5,
+       0xa0, 0x74, 0xc0, 0x49, 0x1f, 0xf0, 0x30, 0xc5,
+       0xa0, 0x73, 0x00, 0x13, 0x04, 0xf1, 0xa2, 0x73,
+       0x00, 0x13, 0x14, 0xf0, 0x28, 0xc5, 0xa0, 0x74,
+       0xc8, 0x49, 0x1b, 0xf1, 0x26, 0xc5, 0xa0, 0x76,
+       0xa2, 0x74, 0x01, 0x06, 0x20, 0x37, 0xa0, 0x9e,
+       0xa2, 0x9c, 0x1e, 0xc5, 0xa2, 0x73, 0x23, 0x40,
+       0x10, 0xf8, 0x04, 0xf3, 0xa0, 0x73, 0x33, 0x40,
+       0x0c, 0xf8, 0x15, 0xc5, 0xa0, 0x74, 0x41, 0x48,
+       0xa0, 0x9c, 0x14, 0xc5, 0xa0, 0x76, 0x62, 0x48,
+       0xe0, 0x48, 0xa0, 0x9e, 0x10, 0xc6, 0x00, 0xbe,
+       0x0a, 0xc5, 0xa0, 0x74, 0x48, 0x48, 0xa0, 0x9c,
+       0x0b, 0xc5, 0x20, 0x1e, 0xa0, 0x9e, 0xe5, 0x48,
+       0xa0, 0x9e, 0xf0, 0xe7, 0xbc, 0xc0, 0xc8, 0xd2,
+       0xcc, 0xd2, 0x28, 0xe4, 0xe6, 0x01, 0xf0, 0xc0,
+       0x18, 0x89, 0x00, 0x1d, 0x3c, 0xc3, 0x60, 0x71,
+       0x3c, 0xc0, 0x02, 0x99, 0x00, 0x61, 0x67, 0x11,
+       0x3c, 0xf1, 0x69, 0x33, 0x35, 0xc0, 0x28, 0x40,
+       0xf6, 0xf1, 0x34, 0xc0, 0x00, 0x19, 0x81, 0x1b,
+       0x8c, 0xe8, 0x31, 0xc0, 0x04, 0x1a, 0x84, 0x1b,
+       0x88, 0xe8, 0x7d, 0xe8, 0xa3, 0x49, 0xfe, 0xf0,
+       0x2b, 0xc0, 0x79, 0xe8, 0xa1, 0x48, 0x28, 0xc0,
+       0x84, 0x1b, 0x7f, 0xe8, 0x00, 0x1d, 0x69, 0x33,
+       0x00, 0x1e, 0x01, 0x06, 0xff, 0x18, 0x30, 0x40,
+       0xfd, 0xf1, 0x18, 0xc0, 0x00, 0x76, 0x2e, 0x40,
+       0xf7, 0xf1, 0x21, 0x48, 0x19, 0xc0, 0x84, 0x1b,
+       0x70, 0xe8, 0x79, 0xc0, 0x64, 0xe8, 0xa1, 0x49,
+       0xfd, 0xf0, 0x11, 0xc0, 0x00, 0x1a, 0x84, 0x1b,
+       0x68, 0xe8, 0x5d, 0xe8, 0xa5, 0x49, 0xfe, 0xf0,
+       0x09, 0xc0, 0x01, 0x19, 0x81, 0x1b, 0x61, 0xe8,
+       0x4f, 0xe0, 0x88, 0xd3, 0x8c, 0xd3, 0xb8, 0x0b,
+       0x50, 0xe8, 0x20, 0xb4, 0x10, 0xd8, 0x84, 0xd4,
+       0xfc, 0xc0, 0x00, 0x61, 0x9c, 0x20, 0x9c, 0x24,
+       0x06, 0x11, 0x06, 0xf1, 0x60, 0xc0, 0x00, 0x61,
+       0x11, 0x48, 0x00, 0x89, 0x3d, 0xe0, 0x00, 0x11,
+       0x02, 0xf1, 0x03, 0xe0, 0x04, 0x11, 0x06, 0xf1,
+       0x56, 0xc0, 0x00, 0x61, 0x92, 0x48, 0x00, 0x89,
+       0x33, 0xe0, 0x05, 0x11, 0x08, 0xf1, 0x4f, 0xc0,
+       0x00, 0x61, 0x91, 0x49, 0x04, 0xf0, 0x91, 0x48,
+       0x00, 0x89, 0x11, 0xe0, 0xde, 0xc0, 0x00, 0x61,
+       0x98, 0x20, 0x98, 0x24, 0x25, 0x11, 0x24, 0xf1,
+       0x45, 0xc0, 0x29, 0xe8, 0x95, 0x49, 0x20, 0xf0,
+       0xd4, 0xc0, 0x00, 0x61, 0x98, 0x20, 0x98, 0x24,
+       0x25, 0x11, 0x1a, 0xf1, 0x38, 0xc0, 0x00, 0x61,
+       0x92, 0x49, 0x16, 0xf1, 0x12, 0x48, 0x00, 0x89,
+       0x30, 0xc0, 0x00, 0x19, 0x00, 0x89, 0x2e, 0xc0,
+       0x01, 0x89, 0x2e, 0xc0, 0x04, 0x19, 0x81, 0x1b,
+       0x1c, 0xe8, 0x2b, 0xc0, 0x14, 0x19, 0x81, 0x1b,
+       0x18, 0xe8, 0x22, 0xc0, 0x0c, 0xe8, 0x20, 0xc0,
+       0x12, 0x48, 0x81, 0x1b, 0x12, 0xe8, 0xb3, 0xc3,
+       0x62, 0x71, 0xb3, 0xc0, 0x02, 0x99, 0x02, 0xc0,
+       0x00, 0xb8, 0x96, 0x07, 0x13, 0xc4, 0x84, 0x98,
+       0x00, 0x1b, 0x86, 0x8b, 0x86, 0x73, 0xbf, 0x49,
+       0xfe, 0xf1, 0x80, 0x71, 0x82, 0x72, 0x80, 0xff,
+       0x09, 0xc4, 0x84, 0x98, 0x80, 0x99, 0x82, 0x9a,
+       0x86, 0x8b, 0x86, 0x73, 0xbf, 0x49, 0xfe, 0xf1,
+       0x80, 0xff, 0x08, 0xea, 0x10, 0xd4, 0x30, 0xd4,
+       0x10, 0xc0, 0x12, 0xe8, 0x8a, 0xd3, 0x28, 0xe4,
+       0x2c, 0xe4, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+static u16 r8153_pla_patch_b_bp[] = {
+       0xfc26, 0x8000, 0xfc28, 0x1154, 0xfc2a, 0x1606, 0xfc2c, 0x155a,
+       0xfc2e, 0x0080, 0xfc30, 0x033c, 0xfc32, 0x01a0, 0xfc34, 0x0794,
+       0xfc36, 0x0000, 0xfc38, 0x007f };
+
+static u16 r8153_ram_code_d[] = {
+       0xa436, 0xb820, 0xa438, 0x0290, 0xa436, 0xa012, 0xa438, 0x0000,
+       0xa436, 0xa014, 0xa438, 0x2c04, 0xb438, 0x2c07, 0xb438, 0x2c07,
+       0xb438, 0x2c07, 0xb438, 0xa240, 0xb438, 0xa104, 0xb438, 0x2944,
+       0xa436, 0xa01a, 0xa438, 0x0000, 0xa436, 0xa006, 0xa438, 0x0fff,
+       0xa436, 0xa004, 0xa438, 0x0fff, 0xa436, 0xa002, 0xa438, 0x0fff,
+       0xa436, 0xa000, 0xa438, 0x1943, 0xa436, 0xb820, 0xa438, 0x0210 };
+
+static u8 usb_patch_d[] = {
+       0x08, 0xe0, 0x0a, 0xe0, 0x0c, 0xe0, 0x1f, 0xe0,
+       0x28, 0xe0, 0x2a, 0xe0, 0x2c, 0xe0, 0x2e, 0xe0,
+       0x02, 0xc5, 0x00, 0xbd, 0x00, 0x00, 0x02, 0xc3,
+       0x00, 0xbb, 0x00, 0x00, 0x30, 0x18, 0x11, 0xc1,
+       0x05, 0xe8, 0x10, 0xc6, 0x02, 0xc2, 0x00, 0xba,
+       0x94, 0x17, 0x02, 0xb4, 0x09, 0xc2, 0x40, 0x99,
+       0x0e, 0x48, 0x42, 0x98, 0x42, 0x70, 0x8e, 0x49,
+       0xfe, 0xf1, 0x02, 0xb0, 0x80, 0xff, 0xc0, 0xd4,
+       0xe4, 0x40, 0x20, 0xd4, 0xb0, 0x49, 0x04, 0xf0,
+       0x30, 0x18, 0x06, 0xc1, 0xef, 0xef, 0xfa, 0xc7,
+       0x02, 0xc0, 0x00, 0xb8, 0x38, 0x12, 0xe4, 0x4b,
+       0x02, 0xc3, 0x00, 0xbb, 0x00, 0x00, 0x02, 0xc5,
+       0x00, 0xbd, 0x00, 0x00, 0x02, 0xc1, 0x00, 0xb9,
+       0x00, 0x00, 0x02, 0xc1, 0x00, 0xb9, 0x00, 0x00 };
+
+static u16 r8153_usb_patch_d_bp[] = {
+       0xfc26, 0xa000, 0xfc28, 0x0000, 0xfc2a, 0x0000, 0xfc2c, 0x1792,
+       0xfc2e, 0x1236, 0xfc30, 0x0000, 0xfc32, 0x0000, 0xfc34, 0x0000,
+       0xfc36, 0x0000, 0xfc38, 0x000c };
+
+static void rtl_clear_bp(struct r8152 *tp)
+{
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0);
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0);
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0);
+       ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0);
+       ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0);
+
+       mdelay(6);
+
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0);
+       ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0);
+}
+
+static void r8153_clear_bp(struct r8152 *tp)
+{
+       ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
+       ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0);
+       rtl_clear_bp(tp);
+}
+
+static void r8152b_set_dq_desc(struct r8152 *tp)
+{
+       u8 data;
+
+       data = ocp_read_byte(tp, MCU_TYPE_USB, 0xd429);
+       data |= 0x80;
+       ocp_write_byte(tp, MCU_TYPE_USB, 0xd429, data);
+       ocp_write_word(tp, MCU_TYPE_USB, 0xc0ce, 0x0210);
+       data = ocp_read_byte(tp, MCU_TYPE_USB, 0xd429);
+       data &= ~0x80;
+       ocp_write_byte(tp, MCU_TYPE_USB, 0xd429, data);
+}
+
+static int r8153_pre_ram_code(struct r8152 *tp, u16 patch_key)
+{
+       u16 data;
+       int i;
+
+       data = ocp_reg_read(tp, 0xb820);
+       data |= 0x0010;
+       ocp_reg_write(tp, 0xb820, data);
+
+       for (i = 0, data = 0; !data && i < 5000; i++) {
+               mdelay(2);
+               data = ocp_reg_read(tp, 0xb800) & 0x0040;
+       }
+
+       sram_write(tp, 0x8146, patch_key);
+       sram_write(tp, 0xb82e, 0x0001);
+
+       return -EBUSY;
+}
+
+static int r8153_post_ram_code(struct r8152 *tp)
+{
+       u16 data;
+
+       sram_write(tp, 0x0000, 0x0000);
+
+       data = ocp_reg_read(tp, 0xb82e);
+       data &= ~0x0001;
+       ocp_reg_write(tp, 0xb82e, data);
+
+       sram_write(tp, 0x8146, 0x0000);
+
+       data = ocp_reg_read(tp, 0xb820);
+       data &= ~0x0010;
+       ocp_reg_write(tp, 0xb820, data);
+
+       ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, tp->ocp_base);
+
+       return 0;
+}
+
+static void r8153_wdt1_end(struct r8152 *tp)
+{
+       int i;
+
+       for (i = 0; i < 104; i++) {
+               if (!(ocp_read_byte(tp, MCU_TYPE_USB, 0xe404) & 1))
+                       break;
+               mdelay(2);
+       }
+}
+
+void r8152b_firmware(struct r8152 *tp)
+{
+       int i;
+
+       if (tp->version == RTL_VER_01) {
+               int i;
+
+               r8152b_set_dq_desc(tp);
+               rtl_clear_bp(tp);
+
+               generic_ocp_write(tp, 0xf800, 0x3f,
+                                 sizeof(r8152b_pla_patch_a),
+                                 r8152b_pla_patch_a, MCU_TYPE_PLA);
+
+               for (i = 0; i < ARRAY_SIZE(r8152b_pla_patch_a_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8152b_pla_patch_a_bp[i],
+                                      r8152b_pla_patch_a_bp[i+1]);
+
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, 0x2000);
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xb092, 0x7070);
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xb098, 0x0600);
+               for (i = 0; i < ARRAY_SIZE(r8152b_ram_code1); i++)
+                       ocp_write_word(tp, MCU_TYPE_PLA, 0xb09a,
+                                      r8152b_ram_code1[i]);
+
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xb098, 0x0200);
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xb092, 0x7030);
+       } else if (tp->version == RTL_VER_02) {
+               rtl_clear_bp(tp);
+
+               generic_ocp_write(tp, 0xf800, 0xff,
+                                 sizeof(r8152b_pla_patch_a2),
+                                 r8152b_pla_patch_a2, MCU_TYPE_PLA);
+
+               for (i = 0; i < ARRAY_SIZE(r8152b_pla_patch_a2_bp);
+                    i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8152b_pla_patch_a2_bp[i],
+                                      r8152b_pla_patch_a2_bp[i+1]);
+       }
+}
+
+void r8153_firmware(struct r8152 *tp)
+{
+       int i;
+
+       if (tp->version == RTL_VER_03) {
+               r8153_clear_bp(tp);
+
+               r8153_pre_ram_code(tp, 0x7000);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_ram_code_a); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8153_ram_code_a[i],
+                                      r8153_ram_code_a[i+1]);
+
+               r8153_post_ram_code(tp);
+       } else if (tp->version == RTL_VER_04) {
+               r8153_pre_ram_code(tp, 0x7001);
+
+       for (i = 0; i < ARRAY_SIZE(r8153_ram_code_bc); i += 2)
+               ocp_write_word(tp, MCU_TYPE_PLA,
+                              r8153_ram_code_bc[i],
+                              r8153_ram_code_bc[i+1]);
+
+               r8153_post_ram_code(tp);
+
+               r8153_wdt1_end(tp);
+               r8153_clear_bp(tp);
+
+               ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000);
+               generic_ocp_write(tp, 0xf800, 0xff,
+                                 sizeof(r8153_usb_patch_b),
+                                 r8153_usb_patch_b, MCU_TYPE_USB);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_usb_patch_b_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_USB,
+                                      r8153_usb_patch_b_bp[i],
+                                      r8153_usb_patch_b_bp[i+1]);
+
+               if (!(ocp_read_word(tp, MCU_TYPE_PLA, 0xd38e) & BIT(0))) {
+                       ocp_write_word(tp, MCU_TYPE_PLA, 0xd38c, 0x0082);
+                       ocp_write_word(tp, MCU_TYPE_PLA, 0xd38e, 0x0082);
+               }
+
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000);
+               generic_ocp_write(tp, 0xf800, 0xff,
+                                 sizeof(r8153_pla_patch_b),
+                                 r8153_pla_patch_b, MCU_TYPE_PLA);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_pla_patch_b_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8153_pla_patch_b_bp[i],
+                                      r8153_pla_patch_b_bp[i+1]);
+
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xd388, 0x08ca);
+       } else if (tp->version == RTL_VER_05) {
+               u32 ocp_data;
+
+               ocp_data = ocp_read_word(tp, MCU_TYPE_USB, 0xcfca);
+               ocp_data &= ~0x4000;
+               ocp_write_word(tp, MCU_TYPE_USB, 0xcfca, ocp_data);
+
+               r8153_pre_ram_code(tp, 0x7001);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_ram_code_bc); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8153_ram_code_bc[i],
+                                      r8153_ram_code_bc[i+1]);
+
+               r8153_post_ram_code(tp);
+
+               r8153_wdt1_end(tp);
+               r8153_clear_bp(tp);
+
+               ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000);
+               generic_ocp_write(tp, 0xf800, 0xff,
+                                 sizeof(r8153_usb_patch_c),
+                                 r8153_usb_patch_c, MCU_TYPE_USB);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_usb_patch_c_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_USB,
+                                      r8153_usb_patch_c_bp[i],
+                                      r8153_usb_patch_c_bp[i+1]);
+
+               if (ocp_read_byte(tp, MCU_TYPE_USB, 0xcfef) & 1) {
+                       ocp_write_word(tp, MCU_TYPE_USB, 0xfc30, 0x1578);
+                       ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x00ff);
+               } else {
+                       ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x00ef);
+               }
+
+               ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000);
+               generic_ocp_write(tp, 0xf800, 0xff,
+                                 sizeof(r8153_pla_patch_c),
+                                 r8153_pla_patch_c, MCU_TYPE_PLA);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_pla_patch_c_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8153_pla_patch_c_bp[i],
+                                      r8153_pla_patch_c_bp[i+1]);
+
+               ocp_write_word(tp, MCU_TYPE_PLA, 0xd388, 0x08ca);
+
+               ocp_data = ocp_read_word(tp, MCU_TYPE_USB, 0xcfca);
+               ocp_data |= 0x4000;
+               ocp_write_word(tp, MCU_TYPE_USB, 0xcfca, ocp_data);
+       } else if (tp->version == RTL_VER_06) {
+               r8153_pre_ram_code(tp, 0x7002);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_ram_code_d); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_PLA,
+                                      r8153_ram_code_d[i],
+                                      r8153_ram_code_d[i+1]);
+
+               r8153_post_ram_code(tp);
+
+               r8153_clear_bp(tp);
+
+               ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000);
+               generic_ocp_write(tp, 0xf800, 0xff, sizeof(usb_patch_d),
+                                 usb_patch_d, MCU_TYPE_USB);
+
+               for (i = 0; i < ARRAY_SIZE(r8153_usb_patch_d_bp); i += 2)
+                       ocp_write_word(tp, MCU_TYPE_USB,
+                                      r8153_usb_patch_d_bp[i],
+                                      r8153_usb_patch_d_bp[i+1]);
+       }
+}
index 62d20f0db989664f69643765701642ea9edcbce5..b9c9a8402e3986bce3506f2fd9937f70c28e7fcf 100644 (file)
@@ -179,6 +179,13 @@ static const struct usb_eth_prob_dev prob_dev[] = {
                .probe = smsc95xx_eth_probe,
                .get_info = smsc95xx_eth_get_info,
        },
+#endif
+#ifdef CONFIG_USB_ETHER_RTL8152
+       {
+               .before_probe = r8152_eth_before_probe,
+               .probe = r8152_eth_probe,
+               .get_info = r8152_eth_get_info,
+       },
 #endif
        { },            /* END */
 };
index 5ef6debd9afd0026705cb3b9ca9972ce162f74e7..c6727c381cbc4798632c75c13cf650e621b53f4d 100644 (file)
@@ -13,6 +13,7 @@
 #include <memalign.h>
 #include <phys2bus.h>
 #include <usbroothubdes.h>
+#include <wait_bit.h>
 #include <asm/io.h>
 
 #include "dwc2.h"
@@ -34,7 +35,8 @@ struct dwc2_priv {
        uint8_t *aligned_buffer;
        uint8_t *status_buffer;
 #endif
-       int bulk_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
+       u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
+       u8 out_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
        struct dwc2_core_regs *regs;
        int root_hub_devnum;
 };
@@ -52,27 +54,6 @@ static struct dwc2_priv local;
 /*
  * DWC2 IP interface
  */
-static int wait_for_bit(void *reg, const uint32_t mask, bool set)
-{
-       unsigned int timeout = 1000000;
-       uint32_t val;
-
-       while (--timeout) {
-               val = readl(reg);
-               if (!set)
-                       val = ~val;
-
-               if ((val & mask) == mask)
-                       return 0;
-
-               udelay(1);
-       }
-
-       debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
-             __func__, reg, mask, set);
-
-       return -ETIMEDOUT;
-}
 
 /*
  * Initializes the FSLSPClkSel field of the HCFG register
@@ -117,7 +98,8 @@ static void dwc_otg_flush_tx_fifo(struct dwc2_core_regs *regs, const int num)
 
        writel(DWC2_GRSTCTL_TXFFLSH | (num << DWC2_GRSTCTL_TXFNUM_OFFSET),
               &regs->grstctl);
-       ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_TXFFLSH, 0);
+       ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_TXFFLSH,
+                          false, 1000, false);
        if (ret)
                printf("%s: Timeout!\n", __func__);
 
@@ -135,7 +117,8 @@ static void dwc_otg_flush_rx_fifo(struct dwc2_core_regs *regs)
        int ret;
 
        writel(DWC2_GRSTCTL_RXFFLSH, &regs->grstctl);
-       ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_RXFFLSH, 0);
+       ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_RXFFLSH,
+                          false, 1000, false);
        if (ret)
                printf("%s: Timeout!\n", __func__);
 
@@ -152,13 +135,15 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
        int ret;
 
        /* Wait for AHB master IDLE state. */
-       ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_AHBIDLE, 1);
+       ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_AHBIDLE,
+                          true, 1000, false);
        if (ret)
                printf("%s: Timeout!\n", __func__);
 
        /* Core Soft Reset */
        writel(DWC2_GRSTCTL_CSFTRST, &regs->grstctl);
-       ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_CSFTRST, 0);
+       ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_CSFTRST,
+                          false, 1000, false);
        if (ret)
                printf("%s: Timeout!\n", __func__);
 
@@ -243,8 +228,8 @@ static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
                clrsetbits_le32(&regs->hc_regs[i].hcchar,
                                DWC2_HCCHAR_EPDIR,
                                DWC2_HCCHAR_CHEN | DWC2_HCCHAR_CHDIS);
-               ret = wait_for_bit(&regs->hc_regs[i].hcchar,
-                                  DWC2_HCCHAR_CHEN, 0);
+               ret = wait_for_bit(__func__, &regs->hc_regs[i].hcchar,
+                                  DWC2_HCCHAR_CHEN, false, 1000, false);
                if (ret)
                        printf("%s: Timeout!\n", __func__);
        }
@@ -426,19 +411,29 @@ static void dwc_otg_hc_init(struct dwc2_core_regs *regs, uint8_t hc_num,
        if (dev->speed == USB_SPEED_LOW)
                hcchar |= DWC2_HCCHAR_LSPDDEV;
 
-       /* Clear old interrupt conditions for this host channel. */
-       writel(0x3fff, &hc_regs->hcint);
-
        /*
         * Program the HCCHARn register with the endpoint characteristics
         * for the current transfer.
         */
        writel(hcchar, &hc_regs->hcchar);
 
-       /* Program the HCSPLIT register for SPLITs */
+       /* Program the HCSPLIT register, default to no SPLIT */
        writel(0, &hc_regs->hcsplt);
 }
 
+static void dwc_otg_hc_init_split(struct dwc2_hc_regs *hc_regs,
+                                 uint8_t hub_devnum, uint8_t hub_port)
+{
+       uint32_t hcsplt = 0;
+
+       hcsplt = DWC2_HCSPLT_SPLTENA;
+       hcsplt |= hub_devnum << DWC2_HCSPLT_HUBADDR_OFFSET;
+       hcsplt |= hub_port << DWC2_HCSPLT_PRTADDR_OFFSET;
+
+       /* Program the HCSPLIT register for SPLITs */
+       writel(hcsplt, &hc_regs->hcsplt);
+}
+
 /*
  * DWC2 to USB API interface
  */
@@ -729,38 +724,33 @@ static int dwc_otg_submit_rh_msg(struct dwc2_priv *priv, struct usb_device *dev,
        return stat;
 }
 
-int wait_for_chhltd(struct dwc2_core_regs *regs, uint32_t *sub, int *toggle,
-                   bool ignore_ack)
+int wait_for_chhltd(struct dwc2_hc_regs *hc_regs, uint32_t *sub, u8 *toggle)
 {
-       uint32_t hcint_comp_hlt_ack = DWC2_HCINT_XFERCOMP | DWC2_HCINT_CHHLTD;
-       struct dwc2_hc_regs *hc_regs = &regs->hc_regs[DWC2_HC_CHANNEL];
        int ret;
        uint32_t hcint, hctsiz;
 
-       ret = wait_for_bit(&hc_regs->hcint, DWC2_HCINT_CHHLTD, true);
+       ret = wait_for_bit(__func__, &hc_regs->hcint, DWC2_HCINT_CHHLTD, true,
+                          1000, false);
        if (ret)
                return ret;
 
        hcint = readl(&hc_regs->hcint);
-       if (hcint & (DWC2_HCINT_NAK | DWC2_HCINT_FRMOVRUN))
-               return -EAGAIN;
-       if (ignore_ack)
-               hcint &= ~DWC2_HCINT_ACK;
-       else
-               hcint_comp_hlt_ack |= DWC2_HCINT_ACK;
-       if (hcint != hcint_comp_hlt_ack) {
-               debug("%s: Error (HCINT=%08x)\n", __func__, hcint);
-               return -EINVAL;
-       }
-
        hctsiz = readl(&hc_regs->hctsiz);
        *sub = (hctsiz & DWC2_HCTSIZ_XFERSIZE_MASK) >>
                DWC2_HCTSIZ_XFERSIZE_OFFSET;
        *toggle = (hctsiz & DWC2_HCTSIZ_PID_MASK) >> DWC2_HCTSIZ_PID_OFFSET;
 
-       debug("%s: sub=%u toggle=%d\n", __func__, *sub, *toggle);
+       debug("%s: HCINT=%08x sub=%u toggle=%d\n", __func__, hcint, *sub,
+             *toggle);
 
-       return 0;
+       if (hcint & DWC2_HCINT_XFERCOMP)
+               return 0;
+
+       if (hcint & (DWC2_HCINT_NAK | DWC2_HCINT_FRMOVRUN))
+               return -EAGAIN;
+
+       debug("%s: Error (HCINT=%08x)\n", __func__, hcint);
+       return -EINVAL;
 }
 
 static int dwc2_eptype[] = {
@@ -770,96 +760,176 @@ static int dwc2_eptype[] = {
        DWC2_HCCHAR_EPTYPE_BULK,
 };
 
+static int transfer_chunk(struct dwc2_hc_regs *hc_regs, void *aligned_buffer,
+                         u8 *pid, int in, void *buffer, int num_packets,
+                         int xfer_len, int *actual_len, int odd_frame)
+{
+       int ret = 0;
+       uint32_t sub;
+
+       debug("%s: chunk: pid %d xfer_len %u pkts %u\n", __func__,
+             *pid, xfer_len, num_packets);
+
+       writel((xfer_len << DWC2_HCTSIZ_XFERSIZE_OFFSET) |
+              (num_packets << DWC2_HCTSIZ_PKTCNT_OFFSET) |
+              (*pid << DWC2_HCTSIZ_PID_OFFSET),
+              &hc_regs->hctsiz);
+
+       if (!in && xfer_len) {
+               memcpy(aligned_buffer, buffer, xfer_len);
+
+               flush_dcache_range((unsigned long)aligned_buffer,
+                                  (unsigned long)aligned_buffer +
+                                  roundup(xfer_len, ARCH_DMA_MINALIGN));
+       }
+
+       writel(phys_to_bus((unsigned long)aligned_buffer), &hc_regs->hcdma);
+
+       /* Clear old interrupt conditions for this host channel. */
+       writel(0x3fff, &hc_regs->hcint);
+
+       /* Set host channel enable after all other setup is complete. */
+       clrsetbits_le32(&hc_regs->hcchar, DWC2_HCCHAR_MULTICNT_MASK |
+                       DWC2_HCCHAR_CHEN | DWC2_HCCHAR_CHDIS |
+                       DWC2_HCCHAR_ODDFRM,
+                       (1 << DWC2_HCCHAR_MULTICNT_OFFSET) |
+                       (odd_frame << DWC2_HCCHAR_ODDFRM_OFFSET) |
+                       DWC2_HCCHAR_CHEN);
+
+       ret = wait_for_chhltd(hc_regs, &sub, pid);
+       if (ret < 0)
+               return ret;
+
+       if (in) {
+               xfer_len -= sub;
+
+               invalidate_dcache_range((unsigned long)aligned_buffer,
+                                       (unsigned long)aligned_buffer +
+                                       roundup(xfer_len, ARCH_DMA_MINALIGN));
+
+               memcpy(buffer, aligned_buffer, xfer_len);
+       }
+       *actual_len = xfer_len;
+
+       return ret;
+}
+
 int chunk_msg(struct dwc2_priv *priv, struct usb_device *dev,
-             unsigned long pipe, int *pid, int in, void *buffer, int len,
-             bool ignore_ack)
+             unsigned long pipe, u8 *pid, int in, void *buffer, int len)
 {
        struct dwc2_core_regs *regs = priv->regs;
        struct dwc2_hc_regs *hc_regs = &regs->hc_regs[DWC2_HC_CHANNEL];
+       struct dwc2_host_regs *host_regs = &regs->host_regs;
        int devnum = usb_pipedevice(pipe);
        int ep = usb_pipeendpoint(pipe);
        int max = usb_maxpacket(dev, pipe);
        int eptype = dwc2_eptype[usb_pipetype(pipe)];
        int done = 0;
        int ret = 0;
-       uint32_t sub;
+       int do_split = 0;
+       int complete_split = 0;
        uint32_t xfer_len;
        uint32_t num_packets;
        int stop_transfer = 0;
+       uint32_t max_xfer_len;
+       int ssplit_frame_num = 0;
 
        debug("%s: msg: pipe %lx pid %d in %d len %d\n", __func__, pipe, *pid,
              in, len);
 
-       do {
-               /* Initialize channel */
-               dwc_otg_hc_init(regs, DWC2_HC_CHANNEL, dev, devnum, ep, in,
-                               eptype, max);
+       max_xfer_len = CONFIG_DWC2_MAX_PACKET_COUNT * max;
+       if (max_xfer_len > CONFIG_DWC2_MAX_TRANSFER_SIZE)
+               max_xfer_len = CONFIG_DWC2_MAX_TRANSFER_SIZE;
+       if (max_xfer_len > DWC2_DATA_BUF_SIZE)
+               max_xfer_len = DWC2_DATA_BUF_SIZE;
+
+       /* Make sure that max_xfer_len is a multiple of max packet size. */
+       num_packets = max_xfer_len / max;
+       max_xfer_len = num_packets * max;
+
+       /* Initialize channel */
+       dwc_otg_hc_init(regs, DWC2_HC_CHANNEL, dev, devnum, ep, in,
+                       eptype, max);
+
+       /* Check if the target is a FS/LS device behind a HS hub */
+       if (dev->speed != USB_SPEED_HIGH) {
+               uint8_t hub_addr;
+               uint8_t hub_port;
+               uint32_t hprt0 = readl(&regs->hprt0);
+               if ((hprt0 & DWC2_HPRT0_PRTSPD_MASK) ==
+                    DWC2_HPRT0_PRTSPD_HIGH) {
+                       usb_find_usb2_hub_address_port(dev, &hub_addr,
+                                                      &hub_port);
+                       dwc_otg_hc_init_split(hc_regs, hub_addr, hub_port);
+
+                       do_split = 1;
+                       num_packets = 1;
+                       max_xfer_len = max;
+               }
+       }
 
+       do {
+               int actual_len = 0;
+               uint32_t hcint;
+               int odd_frame = 0;
                xfer_len = len - done;
-               if (xfer_len > CONFIG_DWC2_MAX_TRANSFER_SIZE)
-                       xfer_len = CONFIG_DWC2_MAX_TRANSFER_SIZE - max + 1;
-               if (xfer_len > DWC2_DATA_BUF_SIZE)
-                       xfer_len = DWC2_DATA_BUF_SIZE - max + 1;
 
-               /* Make sure that xfer_len is a multiple of max packet size. */
-               if (xfer_len > 0) {
+               if (xfer_len > max_xfer_len)
+                       xfer_len = max_xfer_len;
+               else if (xfer_len > max)
                        num_packets = (xfer_len + max - 1) / max;
-                       if (num_packets > CONFIG_DWC2_MAX_PACKET_COUNT) {
-                               num_packets = CONFIG_DWC2_MAX_PACKET_COUNT;
-                               xfer_len = num_packets * max;
-                       }
-               } else {
+               else
                        num_packets = 1;
-               }
-
-               if (in)
-                       xfer_len = num_packets * max;
 
-               debug("%s: chunk: pid %d xfer_len %u pkts %u\n", __func__,
-                     *pid, xfer_len, num_packets);
+               if (complete_split)
+                       setbits_le32(&hc_regs->hcsplt, DWC2_HCSPLT_COMPSPLT);
+               else if (do_split)
+                       clrbits_le32(&hc_regs->hcsplt, DWC2_HCSPLT_COMPSPLT);
 
-               writel((xfer_len << DWC2_HCTSIZ_XFERSIZE_OFFSET) |
-                      (num_packets << DWC2_HCTSIZ_PKTCNT_OFFSET) |
-                      (*pid << DWC2_HCTSIZ_PID_OFFSET),
-                      &hc_regs->hctsiz);
-
-               if (!in && xfer_len) {
-                       memcpy(priv->aligned_buffer, (char *)buffer + done,
-                              xfer_len);
-
-                       flush_dcache_range((unsigned long)priv->aligned_buffer,
-                               (unsigned long)((void *)priv->aligned_buffer +
-                               roundup(xfer_len, ARCH_DMA_MINALIGN)));
+               if (eptype == DWC2_HCCHAR_EPTYPE_INTR) {
+                       int uframe_num = readl(&host_regs->hfnum);
+                       if (!(uframe_num & 0x1))
+                               odd_frame = 1;
                }
 
-               writel(phys_to_bus((unsigned long)priv->aligned_buffer),
-                      &hc_regs->hcdma);
-
-               /* Set host channel enable after all other setup is complete. */
-               clrsetbits_le32(&hc_regs->hcchar, DWC2_HCCHAR_MULTICNT_MASK |
-                               DWC2_HCCHAR_CHEN | DWC2_HCCHAR_CHDIS,
-                               (1 << DWC2_HCCHAR_MULTICNT_OFFSET) |
-                               DWC2_HCCHAR_CHEN);
+               ret = transfer_chunk(hc_regs, priv->aligned_buffer, pid,
+                                    in, (char *)buffer + done, num_packets,
+                                    xfer_len, &actual_len, odd_frame);
+
+               hcint = readl(&hc_regs->hcint);
+               if (complete_split) {
+                       stop_transfer = 0;
+                       if (hcint & DWC2_HCINT_NYET) {
+                               ret = 0;
+                               int frame_num = DWC2_HFNUM_MAX_FRNUM &
+                                               readl(&host_regs->hfnum);
+                               if (((frame_num - ssplit_frame_num) &
+                                   DWC2_HFNUM_MAX_FRNUM) > 4)
+                                       ret = -EAGAIN;
+                       } else
+                               complete_split = 0;
+               } else if (do_split) {
+                       if (hcint & DWC2_HCINT_ACK) {
+                               ssplit_frame_num = DWC2_HFNUM_MAX_FRNUM &
+                                                  readl(&host_regs->hfnum);
+                               ret = 0;
+                               complete_split = 1;
+                       }
+               }
 
-               ret = wait_for_chhltd(regs, &sub, pid, ignore_ack);
                if (ret)
                        break;
 
-               if (in) {
-                       xfer_len -= sub;
+               if (actual_len < xfer_len)
+                       stop_transfer = 1;
 
-                       invalidate_dcache_range((unsigned long)priv->aligned_buffer,
-                               (unsigned long)((void *)priv->aligned_buffer +
-                               roundup(xfer_len, ARCH_DMA_MINALIGN)));
+               done += actual_len;
 
-                       memcpy(buffer + done, priv->aligned_buffer, xfer_len);
-                       if (sub)
-                               stop_transfer = 1;
-               }
-
-               done += xfer_len;
-
-       } while ((done < len) && !stop_transfer);
+       /* Transactions are done when when either all data is transferred or
+        * there is a short transfer. In case of a SPLIT make sure the CSPLIT
+        * is executed.
+        */
+       } while (((done < len) && !stop_transfer) || complete_split);
 
        writel(0, &hc_regs->hcintmsk);
        writel(0xFFFFFFFF, &hc_regs->hcint);
@@ -876,14 +946,19 @@ int _submit_bulk_msg(struct dwc2_priv *priv, struct usb_device *dev,
 {
        int devnum = usb_pipedevice(pipe);
        int ep = usb_pipeendpoint(pipe);
+       u8* pid;
 
-       if (devnum == priv->root_hub_devnum) {
+       if ((devnum >= MAX_DEVICE) || (devnum == priv->root_hub_devnum)) {
                dev->status = 0;
                return -EINVAL;
        }
 
-       return chunk_msg(priv, dev, pipe, &priv->bulk_data_toggle[devnum][ep],
-                        usb_pipein(pipe), buffer, len, true);
+       if (usb_pipein(pipe))
+               pid = &priv->in_data_toggle[devnum][ep];
+       else
+               pid = &priv->out_data_toggle[devnum][ep];
+
+       return chunk_msg(priv, dev, pipe, pid, usb_pipein(pipe), buffer, len);
 }
 
 static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
@@ -891,7 +966,8 @@ static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
                               struct devrequest *setup)
 {
        int devnum = usb_pipedevice(pipe);
-       int pid, ret, act_len;
+       int ret, act_len;
+       u8 pid;
        /* For CONTROL endpoint pid should start with DATA1 */
        int status_direction;
 
@@ -902,31 +978,39 @@ static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
                                             setup);
        }
 
+       /* SETUP stage */
        pid = DWC2_HC_PID_SETUP;
-       ret = chunk_msg(priv, dev, pipe, &pid, 0, setup, 8, true);
+       do {
+               ret = chunk_msg(priv, dev, pipe, &pid, 0, setup, 8);
+       } while (ret == -EAGAIN);
        if (ret)
                return ret;
 
+       /* DATA stage */
+       act_len = 0;
        if (buffer) {
                pid = DWC2_HC_PID_DATA1;
-               ret = chunk_msg(priv, dev, pipe, &pid, usb_pipein(pipe), buffer,
-                               len, false);
+               do {
+                       ret = chunk_msg(priv, dev, pipe, &pid, usb_pipein(pipe),
+                                       buffer, len);
+                       act_len += dev->act_len;
+                       buffer += dev->act_len;
+                       len -= dev->act_len;
+               } while (ret == -EAGAIN);
                if (ret)
                        return ret;
-               act_len = dev->act_len;
-       } /* End of DATA stage */
-       else
-               act_len = 0;
-
-       /* STATUS stage */
-       if ((len == 0) || usb_pipeout(pipe))
+               status_direction = usb_pipeout(pipe);
+       } else {
+               /* No-data CONTROL always ends with an IN transaction */
                status_direction = 1;
-       else
-               status_direction = 0;
+       }
 
+       /* STATUS stage */
        pid = DWC2_HC_PID_DATA1;
-       ret = chunk_msg(priv, dev, pipe, &pid, status_direction,
-                       priv->status_buffer, 0, false);
+       do {
+               ret = chunk_msg(priv, dev, pipe, &pid, status_direction,
+                               priv->status_buffer, 0);
+       } while (ret == -EAGAIN);
        if (ret)
                return ret;
 
@@ -983,8 +1067,10 @@ static int dwc2_init_common(struct dwc2_priv *priv)
                     DWC2_HPRT0_PRTRST);
 
        for (i = 0; i < MAX_DEVICE; i++) {
-               for (j = 0; j < MAX_ENDPOINT; j++)
-                       priv->bulk_data_toggle[i][j] = DWC2_HC_PID_DATA0;
+               for (j = 0; j < MAX_ENDPOINT; j++) {
+                       priv->in_data_toggle[i][j] = DWC2_HC_PID_DATA0;
+                       priv->out_data_toggle[i][j] = DWC2_HC_PID_DATA0;
+               }
        }
 
        return 0;
index f69372e6b418fca6825dfba48560b9dad1c2e0db..594757b609a9e2138c70646cfffb9e52ba85c97a 100644 (file)
@@ -500,6 +500,7 @@ struct dwc2_core_regs {
 #define DWC2_HFNUM_FRNUM_OFFSET                                0
 #define DWC2_HFNUM_FRREM_MASK                          (0xFFFF << 16)
 #define DWC2_HFNUM_FRREM_OFFSET                                16
+#define DWC2_HFNUM_MAX_FRNUM                           0x3FFF
 #define DWC2_HPTXSTS_PTXFSPCAVAIL_MASK                 (0xFFFF << 0)
 #define DWC2_HPTXSTS_PTXFSPCAVAIL_OFFSET               0
 #define DWC2_HPTXSTS_PTXQSPCAVAIL_MASK                 (0xFF << 16)
index 1292caae4d722dc7cb15f738a02e81fe36c5a1bb..84114c5df9847e4ad0fbadc98c3d04d57f0ac08f 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include "ehci.h"
 
@@ -21,6 +22,19 @@ static int ehci_usb_probe(struct udevice *dev)
 {
        struct ehci_hccr *hccr = (struct ehci_hccr *)dev_get_addr(dev);
        struct ehci_hcor *hcor;
+       int i;
+
+       for (i = 0; ; i++) {
+               struct udevice *clk_dev;
+               int clk_id;
+
+               clk_id = clk_get_by_index(dev, i, &clk_dev);
+               if (clk_id < 0)
+                       break;
+               if (clk_enable(clk_dev, clk_id))
+                       printf("failed to enable clock (dev=%s, id=%d)\n",
+                              clk_dev->name, clk_id);
+       }
 
        hcor = (struct ehci_hcor *)((uintptr_t)hccr +
                                    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
index 2666351391431e091a761fb92f7879777bde2625..e1c67f77d72d2cd96319e13992f647dfaee73435 100644 (file)
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <usb.h>
 #include <errno.h>
+#include <wait_bit.h>
 #include <linux/compiler.h>
 #include <usb/ehci-fsl.h>
 #include <asm/io.h>
@@ -117,32 +118,6 @@ static void usb_power_config(int index)
                     pll_480_ctrl_set);
 }
 
-static int wait_for_bit(u32 *reg, const u32 mask, bool set)
-{
-       u32 val;
-       const unsigned int timeout = 10000;
-       unsigned long start = get_timer(0);
-
-       while(1) {
-               val = readl(reg);
-               if (!set)
-                       val = ~val;
-
-               if ((val & mask) == mask)
-                       return 0;
-
-               if (get_timer(start) > timeout)
-                       break;
-
-               udelay(1);
-       }
-
-       debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
-                       __func__, reg, mask, set);
-
-       return -ETIMEDOUT;
-}
-
 /* Return 0 : host node, <>0 : device mode */
 static int usb_phy_enable(int index, struct usb_ehci *ehci)
 {
@@ -160,12 +135,13 @@ static int usb_phy_enable(int index, struct usb_ehci *ehci)
 
        /* Stop then Reset */
        clrbits_le32(usb_cmd, UCMD_RUN_STOP);
-       ret = wait_for_bit(usb_cmd, UCMD_RUN_STOP, 0);
+       ret = wait_for_bit(__func__, usb_cmd, UCMD_RUN_STOP, false, 10000,
+                          false);
        if (ret)
                return ret;
 
        setbits_le32(usb_cmd, UCMD_RESET);
-       ret = wait_for_bit(usb_cmd, UCMD_RESET, 0);
+       ret = wait_for_bit(__func__, usb_cmd, UCMD_RESET, false, 10000, false);
        if (ret)
                return ret;
 
index cda1c6d5f78ce6126ccb695a9eedd86bc6361553..f21a1fa773b3ac01934a216b709dc107041d6f6f 100644 (file)
@@ -137,11 +137,17 @@ static int ehci_pci_remove(struct udevice *dev)
        return 0;
 }
 
+static const struct udevice_id ehci_pci_ids[] = {
+       { .compatible = "ehci-pci" },
+       { }
+};
+
 U_BOOT_DRIVER(ehci_pci) = {
        .name   = "ehci_pci",
        .id     = UCLASS_USB,
        .probe = ehci_pci_probe,
        .remove = ehci_pci_remove,
+       .of_match = ehci_pci_ids,
        .ops    = &ehci_usb_ops,
        .platdata_auto_alloc_size = sizeof(struct usb_platdata),
        .priv_auto_alloc_size = sizeof(struct ehci_pci_priv),
index 48d338e9fa0f7201b0aaa0229c50171b6608855f..9245126ed6922392750564903d540344fe69606a 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <wait_bit.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/clk.h>
@@ -80,30 +81,6 @@ struct otg_regs {
 static struct otg_regs *otg = (struct otg_regs *)USB_BASE;
 static struct clk_pm_regs *clk_pwr = (struct clk_pm_regs *)CLK_PM_BASE;
 
-static int wait_for_bit(void *reg, const u32 mask, bool set)
-{
-       u32 val;
-       unsigned long start = get_timer(0);
-
-       while (1) {
-               val = readl(reg);
-               if (!set)
-                       val = ~val;
-
-               if ((val & mask) == mask)
-                       return 0;
-
-               if (get_timer(start) > CONFIG_SYS_HZ)
-                       break;
-
-               udelay(1);
-       }
-
-       error("Timeout (reg=%p mask=%08x wait_set=%i)\n", reg, mask, set);
-
-       return -ETIMEDOUT;
-}
-
 static int isp1301_set_value(int reg, u8 value)
 {
        return i2c_write(ISP1301_I2C_ADDR, reg, 1, &value, 1);
@@ -158,7 +135,8 @@ static int usbpll_setup(void)
        setbits_le32(&clk_pwr->usb_ctrl, CLK_USBCTRL_POSTDIV_2POW(0x01));
        setbits_le32(&clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_PWRUP);
 
-       ret = wait_for_bit(&clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_STS, 1);
+       ret = wait_for_bit(__func__, &clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_STS,
+                          true, CONFIG_SYS_HZ, false);
        if (ret)
                return ret;
 
@@ -183,7 +161,8 @@ int usb_cpu_init(void)
 
        /* enable I2C clock */
        writel(OTG_CLK_I2C_EN, &otg->otg_clk_ctrl);
-       ret = wait_for_bit(&otg->otg_clk_sts, OTG_CLK_I2C_EN, 1);
+       ret = wait_for_bit(__func__, &otg->otg_clk_sts, OTG_CLK_I2C_EN, true,
+                          CONFIG_SYS_HZ, false);
        if (ret)
                return ret;
 
@@ -203,7 +182,8 @@ int usb_cpu_init(void)
                         OTG_CLK_I2C_EN | OTG_CLK_HOST_EN;
        writel(mask, &otg->otg_clk_ctrl);
 
-       ret = wait_for_bit(&otg->otg_clk_sts, mask, 1);
+       ret = wait_for_bit(__func__, &otg->otg_clk_sts, mask, true,
+                          CONFIG_SYS_HZ, false);
        if (ret)
                return ret;
 
index dbde7035aa556d5f3060dfe81eac13a6e8b445b8..c4ac153ef3602bf6f2a66128d3bb63a3ffbcb416 100644 (file)
@@ -45,4 +45,4 @@ dtbs: $(obj)/dt.dtb
 clean-files := dt.dtb.S
 
 # Let clean descend into dts directories
-subdir- += ../arch/*/dts
+subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/mips/dts ../arch/sandbox/dts ../arch/x86/dts
index d0fcd83058fa600228dc5db9111e0872eb8aa2a9..176125e38090e8791d19c60cb9eee3a0811a516d 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/err.h>
 #endif
 #include "ubifs.h"
+#include <linux/bug.h>
 #include <linux/list_sort.h>
 
 /**
index abe861a976a81aba4921a5c46771135f0733982c..dcf3a479479d6e786462ff9af60b807a5288117d 100644 (file)
@@ -31,6 +31,7 @@
 #include <common.h>
 #include <malloc.h>
 #include <memalign.h>
+#include <linux/bug.h>
 #include <linux/log2.h>
 #include <linux/stat.h>
 #include <linux/err.h>
index 80979edd04532ee4b89407b623cfcc11b8289c2e..75712636884eb37acc5b635d49ce3b69613c4ac3 100644 (file)
@@ -31,7 +31,11 @@ typedef struct {
        int bus;
        u32 VendorID;
        u32 DeviceID;
+#ifdef CONFIG_DM_PCI
+       struct udevice *pcidev;
+#else
        pci_dev_t pcidev;
+#endif
        void *BIOSImage;
        u32 BIOSImageLen;
        u8 LowMem[1536];
@@ -39,7 +43,12 @@ typedef struct {
 
 struct vbe_mode_info;
 
-int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo, int cleanUp);
+#ifdef CONFIG_DM_PCI
+int BootVideoCardBIOS(struct udevice *pcidev, BE_VGAInfo **pVGAInfo,
+                     int clean_up);
+#else
+int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo, int clean_up);
+#endif
 
 /* Run a BIOS ROM natively (only supported on x86 machines) */
 void bios_run_on_x86(struct udevice *dev, unsigned long addr, int vesa_mode,
@@ -57,10 +66,18 @@ void bios_set_interrupt_handler(int intnum, int (*int_handler_func)(void));
 
 void biosemu_set_interrupt_handler(int intnum, int (*int_func)(void));
 
+#ifdef CONFIG_DM_PCI
+int biosemu_setup(struct udevice *pcidev, BE_VGAInfo **pVGAInfo);
+
+int biosemu_run(struct udevice *dev, uchar *bios_rom, int bios_len,
+               BE_VGAInfo *vga_info, int clean_up, int vesa_mode,
+               struct vbe_mode_info *mode_info);
+#else
 int biosemu_setup(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo);
 
 int biosemu_run(pci_dev_t pcidev, uchar *bios_rom, int bios_len,
                BE_VGAInfo *vga_info, int clean_up, int vesa_mode,
                struct vbe_mode_info *mode_info);
+#endif
 
 #endif
index 7bed0cc0d120e5f31a51cc5af41d9195cc818621..1563d649f01cd869c35fef7f2c2a160f42ee969c 100644 (file)
@@ -146,9 +146,6 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
 #endif /* BUG */
 
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-
 typedef void (interrupt_handler_t)(void *);
 
 #include <asm/u-boot.h> /* boot information for Linux kernel */
index 73279c899e8cbc64dd5e2066ec98132697caee46..4a17f41eb33973b456fbf0b74ef94c45140dfafa 100644 (file)
@@ -606,6 +606,16 @@ unsigned long get_board_ddr_clk(void);
 #define I2C_VOL_MONITOR_BUS_V_OVF      0x1
 #define I2C_VOL_MONITOR_BUS_V_SHIFT    3
 
+#define CONFIG_VID_FLS_ENV             "t4240rdb_vdd_mv"
+#ifndef CONFIG_SPL_BUILD
+#define CONFIG_VID
+#endif
+#define CONFIG_VOL_MONITOR_IR36021_SET
+#define CONFIG_VOL_MONITOR_IR36021_READ
+/* The lowest and highest voltage allowed for T4240RDB */
+#define VDD_MV_MIN                     819
+#define VDD_MV_MAX                     1212
+
 /*
  * eSPI - Enhanced SPI
  */
index 43ce7fe25f18482a79e798e66e9e11237ded3699..68d3fd7384498b6cffdc953c6c5743c953fe49b9 100644 (file)
@@ -34,6 +34,7 @@
 #define CONFIG_SPL_SERIAL_SUPPORT
 #define CONFIG_SPL_I2C_SUPPORT
 #define CONFIG_SPL_GPIO_SUPPORT
+#define CONFIG_SPL_WATCHDOG_SUPPORT
 
 /* NAND support */
 #if defined(CONFIG_SPL_NAND_SUPPORT)
index 174ea088f3efea83415b30bf3a54057f39a682cf..179b4f9007d9bc2846ba14bd55f5e4149709111b 100644 (file)
@@ -25,6 +25,8 @@
 
 #define CONFIG_SYS_NO_FLASH
 
+#define CONFIG_SYS_BOOTM_LEN   0x1000000
+
 #include <linux/sizes.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/imx-common/gpio.h>
index c9461764165d1c31554fe47dabd98a0f690d035d..4374c3a41fe0ebebe19742a1f6547092bd5f88fb 100644 (file)
 /* Miscellaneous configurable options */
 #define CONFIG_CMD_MEMTEST
 #define CONFIG_SYS_MEMTEST_START       0x80000000
-#define CONFIG_SYS_MEMTEST_END         (CONFIG_SYS_MEMTEST_START + 0x10000000)
+#define CONFIG_SYS_MEMTEST_END         (CONFIG_SYS_MEMTEST_START + 0x8000000)
 
 #define CONFIG_SYS_LOAD_ADDR           CONFIG_LOADADDR
 #define CONFIG_SYS_HZ                  1000
 #define CONFIG_SF_DEFAULT_CS           0
 #define CONFIG_SF_DEFAULT_SPEED        40000000
 #define CONFIG_SF_DEFAULT_MODE         SPI_MODE_0
+#define CONFIG_SPI_FLASH_STMICRO
 #define FSL_QSPI_FLASH_NUM             1
 #define FSL_QSPI_FLASH_SIZE            SZ_32M
 #endif
index d507fb48daeae382a9887b187c9ac9f9d406f1f4..fac7c3f2e22909079809e4ec7a25bac6961a9457 100644 (file)
@@ -23,6 +23,8 @@
 #define CONFIG_SC_TIMER_CLK 8000000 /* 8Mhz */
 #define CONFIG_SYS_FSL_CLK
 
+#define CONFIG_SYS_BOOTM_LEN   0x1000000
+
 /* Enable iomux-lpsr support */
 #define CONFIG_IOMUX_LPSR
 #define CONFIG_IMX_FIXED_IVT_OFFSET
index 22e515cccd4f4bff95f2cfb0718c4d1af1da059a..d23e4f3c407bdb576aa9ecc53fd31c1fd3943543 100644 (file)
 #define CONFIG_SYS_NO_FLASH
 #define CONFIG_ENV_SIZE                        SZ_8K
 #define CONFIG_ENV_IS_IN_MMC
+
+/*
+ * If want to use nand, define CONFIG_NAND_MXS and rework board
+ * to support nand, since emmc has pin conflicts with nand
+ */
+#ifdef CONFIG_NAND_MXS
+#define CONFIG_CMD_NAND
+#define CONFIG_CMD_NAND_TRIMFFS
+
+/* NAND stuff */
+#define CONFIG_SYS_MAX_NAND_DEVICE     1
+#define CONFIG_SYS_NAND_BASE           0x40000000
+#define CONFIG_SYS_NAND_5_ADDR_CYCLE
+#define CONFIG_SYS_NAND_ONFI_DETECTION
+
+/* DMA stuff, needed for GPMI/MXS NAND support */
+#define CONFIG_APBH_DMA
+#define CONFIG_APBH_DMA_BURST
+#define CONFIG_APBH_DMA_BURST8
+#endif
+
 #define CONFIG_ENV_OFFSET              (8 * SZ_64K)
+#ifdef CONFIG_NAND_MXS
+#define CONFIG_SYS_FSL_USDHC_NUM       1
+#else
 #define CONFIG_SYS_FSL_USDHC_NUM       2
+#endif
 
 #define CONFIG_SYS_MMC_ENV_DEV         0   /* USDHC1 */
 #define CONFIG_SYS_MMC_ENV_PART                0       /* user area */
index 5da6cfd6f59642bc04b70a07f0f1acee8e5fc52b..5e33845da0dca9f254950edee611de44dc01c52b 100644 (file)
@@ -19,8 +19,6 @@
 #include <configs/ti_omap3_common.h>
 #include <asm/mach-types.h>
 
-#undef CONFIG_BOOTDELAY
-
 /*
  * Display CPU and Board information
  */
index 7b60f29bd27c3ad923f391742eb2ea752c27d9d1..e9ce3f6d1c761a3bd7ce65152871cd4e2cf8c42a 100644 (file)
@@ -50,6 +50,9 @@
  * Hardware drivers
  */
 
+/* GPIO banks */
+#define CONFIG_OMAP3_GPIO_6            /* GPIO160..191 is in GPIO bank 6 */
+
 /*
  * select serial console configuration
  */
index 4258dcb7f6c109ef1b65658615d9871a3cc62a57..b0d2ffe5b4c842b9086072c2463abb00d35c2eb7 100644 (file)
@@ -14,7 +14,6 @@
 #include <configs/x86-common.h>
 
 #define CONFIG_SYS_MONITOR_LEN         (1 << 20)
-#define CONFIG_ARCH_MISC_INIT
 #define CONFIG_ARCH_EARLY_INIT_R
 
 #define CONFIG_PCI_PNP
index 1b83eb36a7286889c5cbcb6c26f014688c365c7d..927bae78eb5a42d70f93f6c8bcc0a7e22af43984 100644 (file)
@@ -88,6 +88,9 @@
 #define CONFIG_USB_HOST_ETHER
 #define CONFIG_USB_ETHER_SMSC95XX
 #define CONFIG_MISC_INIT_R
+#define CONFIG_USB_KEYBOARD
+#define CONFIG_SYS_USB_EVENT_POLL
+#define CONFIG_SYS_STDIO_DEREGISTER
 #endif
 
 /* Console UART */
 #define CONFIG_SYS_LOAD_ADDR           0x1000000
 #define CONFIG_CONSOLE_MUX
 #define CONFIG_SYS_CONSOLE_IS_IN_ENV
+#define CONFIG_PREBOOT                 "usb start"
 
 /* Shell */
 #define CONFIG_SYS_MAXARGS             8
 /* Environment */
 #define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define ENV_DEVICE_SETTINGS \
-       "stdin=serial,lcd\0" \
+       "stdin=serial,usbkbd\0" \
        "stdout=serial,lcd\0" \
        "stderr=serial,lcd\0"
 
index 8391e381fa88863f7be44a400f3c6156e45de163..73cd3ac94c17b9eedcced305c7277d4eed6cac77 100644 (file)
@@ -29,6 +29,7 @@ enum uclass_id {
        UCLASS_CLK,             /* Clock source, e.g. used by peripherals */
        UCLASS_CPU,             /* CPU, typically part of an SoC */
        UCLASS_CROS_EC,         /* Chrome OS EC */
+       UCLASS_DISK,            /* Disk controller, e.g. SATA */
        UCLASS_DISPLAY,         /* Display (e.g. DisplayPort, HDMI) */
        UCLASS_RAM,             /* RAM controller */
        UCLASS_ETH,             /* Ethernet device */
@@ -37,6 +38,7 @@ enum uclass_id {
        UCLASS_I2C_EEPROM,      /* I2C EEPROM device */
        UCLASS_I2C_GENERIC,     /* Generic I2C device */
        UCLASS_I2C_MUX,         /* I2C multiplexer */
+       UCLASS_IRQ,             /* Interrupt controller */
        UCLASS_KEYBOARD,        /* Keyboard input device */
        UCLASS_LED,             /* Light-emitting diode (LED) */
        UCLASS_LPC,             /* x86 'low pin count' interface */
@@ -45,6 +47,7 @@ enum uclass_id {
        UCLASS_MMC,             /* SD / MMC card or chip */
        UCLASS_MOD_EXP,         /* RSA Mod Exp device */
        UCLASS_MTD,             /* Memory Technology Device (MTD) device */
+       UCLASS_NORTHBRIDGE,     /* Intel Northbridge / SDRAM controller */
        UCLASS_PANEL,           /* Display panel, such as an LCD */
        UCLASS_PANEL_BACKLIGHT, /* Backlight controller for panel */
        UCLASS_PCH,             /* x86 platform controller hub */
index 25e98c9c9e1ae2e3f0c73fd069c05374e8f54c3d..dd82916dc00ae711748f428acac754754102c698 100644 (file)
@@ -163,7 +163,6 @@ enum fdt_compat_id {
        COMPAT_INTEL_X86_PINCTRL,       /* Intel ICH7/9 pin control */
        COMPAT_SOCIONEXT_XHCI,          /* Socionext UniPhier xHCI */
        COMPAT_INTEL_PCH,               /* Intel PCH */
-       COMPAT_INTEL_IRQ_ROUTER,        /* Intel Interrupt Router */
        COMPAT_ALTERA_SOCFPGA_DWMAC,    /* SoCFPGA Ethernet controller */
        COMPAT_ALTERA_SOCFPGA_DWMMC,    /* SoCFPGA DWMMC controller */
        COMPAT_ALTERA_SOCFPGA_DWC2USB,  /* SoCFPGA DWC2 USB controller */
diff --git a/include/linux/bug.h b/include/linux/bug.h
new file mode 100644 (file)
index 0000000..920e379
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef _LINUX_BUG_H
+#define _LINUX_BUG_H
+
+#include <linux/compiler.h>
+
+#ifdef __CHECKER__
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
+#define BUILD_BUG_ON_ZERO(e) (0)
+#define BUILD_BUG_ON_NULL(e) ((void*)0)
+#define BUILD_BUG_ON_INVALID(e) (0)
+#define BUILD_BUG_ON(condition) (0)
+#define BUILD_BUG() (0)
+#else /* __CHECKER__ */
+
+/* Force a compilation error if a constant expression is not a power of 2 */
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n)                 \
+       BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
+
+/* Force a compilation error if condition is true, but also produce a
+   result (of value 0 and type size_t), so the expression can be used
+   e.g. in a structure initializer (or where-ever else comma expressions
+   aren't permitted). */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
+
+/*
+ * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
+ * expression but avoids the generation of any code, even if that expression
+ * has side-effects.
+ */
+#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
+
+/**
+ * BUILD_BUG_ON - break compile if a condition is true.
+ * @condition: the condition which the compiler should know is false.
+ *
+ * If you have some code which relies on certain constants being equal, or
+ * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
+ * detect if someone changes it.
+ *
+ * The implementation uses gcc's reluctance to create a negative array, but gcc
+ * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
+ * inline functions).  Luckily, in 4.3 they added the "error" function
+ * attribute just for this type of case.  Thus, we use a negative sized array
+ * (should always create an error on gcc versions older than 4.4) and then call
+ * an undefined function with the error attribute (should always create an
+ * error on gcc 4.3 and later).  If for some reason, neither creates a
+ * compile-time error, we'll still have a link-time error, which is harder to
+ * track down.
+ */
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+
+#endif /* __CHECKER__ */
+
+#endif /* _LINUX_BUG_H */
index 4d00e220e4c8867c6312044c05a497ec77aaf262..dc23949ae8c079ddf05f9e50b6ab51f5bcd7b52a 100644 (file)
@@ -10,8 +10,6 @@
 #include <ide.h>
 #include <common.h>
 
-typedef struct block_dev_desc block_dev_desc_t;
-
 struct block_dev_desc {
        int             if_type;        /* type of the interface */
        int             dev;            /* device number */
diff --git a/include/pch.h b/include/pch.h
new file mode 100644 (file)
index 0000000..79f49bd
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __pch_h
+#define __pch_h
+
+enum pch_version {
+       PCHV_UNKNOWN,
+       PCHV_7,
+       PCHV_9,
+};
+
+#define PCH_RCBA               0xf0
+
+#define BIOS_CTRL_BIOSWE       BIT(0)
+
+/* Operations for the Platform Controller Hub */
+struct pch_ops {
+       /**
+        * get_sbase() - get the address of SPI base
+        *
+        * @dev:        PCH device to check
+        * @sbasep:     Returns address of SPI base if available, else 0
+        * @return 0 if OK, -ve on error (e.g. there is no SPI base)
+        */
+       int (*get_sbase)(struct udevice *dev, ulong *sbasep);
+
+       /**
+        * get_version() - get the PCH version
+        *
+        * @return version, or -ENOSYS if unknown
+        */
+       enum pch_version (*get_version)(struct udevice *dev);
+
+       /**
+        * set_spi_protect() - set whether SPI flash is protected or not
+        *
+        * @dev:        PCH device to adjust
+        * @protect:    true to protect, false to unprotect
+        *
+        * @return 0 on success, -ENOSYS if not implemented
+        */
+       int (*set_spi_protect)(struct udevice *dev, bool protect);
+};
+
+#define pch_get_ops(dev)        ((struct pch_ops *)(dev)->driver->ops)
+
+/**
+ * pch_get_sbase() - get the address of SPI base
+ *
+ * @dev:       PCH device to check
+ * @sbasep:    Returns address of SPI base if available, else 0
+ * @return 0 if OK, -ve on error (e.g. there is no SPI base)
+ */
+int pch_get_sbase(struct udevice *dev, ulong *sbasep);
+
+/**
+ * pch_get_version() - get the PCH version
+ *
+ * @return version, or -ENOSYS if unknown
+ */
+enum pch_version pch_get_version(struct udevice *dev);
+
+/**
+ * set_spi_protect() - set whether SPI flash is protected or not
+ *
+ * @dev:       PCH device to adjust
+ * @protect:   true to protect, false to unprotect
+ *
+ * @return 0 on success, -ENOSYS if not implemented
+ */
+int pch_set_spi_protect(struct udevice *dev, bool protect);
+
+#endif
index cb2562f1098964e50fca3abdb09f1ef23d84873c..d0d152c00bf46c9ee9a1adbcdf06f0fa284b8f24 100644 (file)
@@ -757,7 +757,9 @@ extern void pci_mpc85xx_init (struct pci_controller *hose);
 /**
  * pci_write_bar32() - Write the address of a BAR including control bits
  *
- * This writes a raw address (with control bits) to a bar
+ * This writes a raw address (with control bits) to a bar. This can be used
+ * with devices which require hard-coded addresses, not part of the normal
+ * PCI enumeration process.
  *
  * @hose:      PCI hose to use
  * @dev:       PCI device to update
@@ -765,7 +767,7 @@ extern void pci_mpc85xx_init (struct pci_controller *hose);
  * @addr:      BAR address with control bits
  */
 void pci_write_bar32(struct pci_controller *hose, pci_dev_t dev, int barnum,
-                    u32 addr_and_ctrl);
+                    u32 addr);
 
 /**
  * pci_read_bar32() - read the address of a bar
@@ -1166,6 +1168,17 @@ struct udevice *pci_get_controller(struct udevice *dev);
 int pci_get_regions(struct udevice *dev, struct pci_region **iop,
                    struct pci_region **memp, struct pci_region **prefp);
 
+/**
+ * dm_pci_write_bar32() - Write the address of a BAR
+ *
+ * This writes a raw address to a bar
+ *
+ * @dev:       PCI device to update
+ * @barnum:    BAR number (0-5)
+ * @addr:      BAR address
+ */
+void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr);
+
 /**
  * dm_pci_read_bar32() - read a base address register from a device
  *
index c62ccd61b329b66461395cccd4d315e58975a972..4593b6e3ebfdb96e7869cc9cc88045eaa42cb35d 100644 (file)
@@ -32,6 +32,20 @@ struct syscon_ops {
  */
 struct regmap *syscon_get_regmap(struct udevice *dev);
 
+/**
+ * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
+ *
+ * Each system controller can be accessed by its driver data, which is
+ * assumed to be unique through the scope of all system controllers that
+ * are in use. This function looks up the controller given this driver data.
+ *
+ * @driver_data:       Driver data value to look up
+ * @devp:              Returns the controller correponding to @driver_data
+ * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
+ *        code
+ */
+int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
+
 /**
  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  *
index c6d1416048a113c37d529d503bb255f47dffa197..51fce4e95dc5c1caa410c7202cfa75bb08329011 100644 (file)
@@ -131,6 +131,12 @@ int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
                        struct ueth_data *ss);
 int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
                        struct eth_device *eth);
+
+void r8152_eth_before_probe(void);
+int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
+                   struct ueth_data *ss);
+int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
+                      struct eth_device *eth);
 #endif
 
 #endif /* __USB_ETHER_H__ */
diff --git a/include/wait_bit.h b/include/wait_bit.h
new file mode 100644 (file)
index 0000000..061a2db
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Wait for bit with timeout and ctrlc
+ *
+ * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __WAIT_BIT_H
+#define __WAIT_BIT_H
+
+#include <common.h>
+#include <console.h>
+#include <asm/errno.h>
+#include <asm/io.h>
+
+/**
+ * wait_for_bit()      waits for bit set/cleared in register
+ *
+ * Function polls register waiting for specific bit(s) change
+ * (either 0->1 or 1->0). It can fail under two conditions:
+ * - Timeout
+ * - User interaction (CTRL-C)
+ * Function succeeds only if all bits of masked register are set/cleared
+ * (depending on set option).
+ *
+ * @param prefix       Prefix added to timeout messagge (message visible only
+ *                     with debug enabled)
+ * @param reg          Register that will be read (using readl())
+ * @param mask         Bit(s) of register that must be active
+ * @param set          Selects wait condition (bit set or clear)
+ * @param timeout_ms   Timeout (in miliseconds)
+ * @param breakable    Enables CTRL-C interruption
+ * @return             0 on success, -ETIMEDOUT or -EINTR on failure
+ */
+static inline int wait_for_bit(const char *prefix, const u32 *reg,
+                              const u32 mask, const bool set,
+                              const unsigned int timeout_ms,
+                              const bool breakable)
+{
+       u32 val;
+       unsigned long start = get_timer(0);
+
+       while (1) {
+               val = readl(reg);
+
+               if (!set)
+                       val = ~val;
+
+               if ((val & mask) == mask)
+                       return 0;
+
+               if (get_timer(start) > timeout_ms)
+                       break;
+
+               if (breakable && ctrlc()) {
+                       puts("Abort\n");
+                       return -EINTR;
+               }
+
+               udelay(1);
+       }
+
+       debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix, reg, mask,
+             set);
+
+       return -ETIMEDOUT;
+}
+
+
+#endif
index d56e1b11f01d43d784be9120c7dbef14b8cd0361..0eb56af4d6d71ad99fa9f11f47fa564db7986134 100644 (file)
@@ -68,7 +68,6 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(INTEL_X86_PINCTRL, "intel,x86-pinctrl"),
        COMPAT(SOCIONEXT_XHCI, "socionext,uniphier-xhci"),
        COMPAT(COMPAT_INTEL_PCH, "intel,bd82x6x"),
-       COMPAT(COMPAT_INTEL_IRQ_ROUTER, "intel,irq-router"),
        COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"),
        COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"),
        COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"),
index 98e09ce5fbf16f03fff204d2aa11aff0e36bd463..30e6e316ac1b2565f13436f2d81a2230e1fe5bfc 100644 (file)
@@ -130,6 +130,10 @@ cc-option-align = $(subst -functions=0,,\
 cc-disable-warning = $(call try-run,\
        $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
 
+# cc-name
+# Expands to either gcc or clang
+cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
+
 # cc-version
 cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
 
index 96f414a7afd81d2c2ac25ada5dc539c9ea771fe1..dff16b9d998fde3b692fb0588e0185a4881e8599 100644 (file)
@@ -53,7 +53,7 @@ libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
 
 libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
 libs-y += common/init/
-libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/
+libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/
 libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
 libs-y += drivers/
 libs-y += dts/
index 36424816b894303faa52b22a0ec8129326af6765..c40f5fc09dd89b7bdc877fd50be9ad239dc0f7d7 100644 (file)
@@ -29,3 +29,20 @@ static int dm_test_syscon_base(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test system controller finding */
+static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
+       ut_asserteq(SYSCON0, dev->driver_data);
+
+       ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
+       ut_asserteq(SYSCON1, dev->driver_data);
+
+       ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_syscon_by_driver_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);