From 3f2546b2ef55b661fd8dd69682b38992225e86f6 Mon Sep 17 00:00:00 2001
From: fishsoupisgood
Date: Mon, 29 Apr 2019 01:17:54 +0100
Subject: Initial import of qemu-2.4.1
---
roms/u-boot/tools/.gitignore | 22 +
roms/u-boot/tools/Makefile | 217 ++
roms/u-boot/tools/aisimage.c | 431 ++++
roms/u-boot/tools/aisimage.h | 81 +
roms/u-boot/tools/bddb/README | 116 +
roms/u-boot/tools/bddb/badsubmit.php | 23 +
roms/u-boot/tools/bddb/bddb.css | 207 ++
roms/u-boot/tools/bddb/brlog.php | 109 +
roms/u-boot/tools/bddb/browse.php | 147 ++
roms/u-boot/tools/bddb/config.php | 16 +
roms/u-boot/tools/bddb/create_tables.sql | 90 +
roms/u-boot/tools/bddb/defs.php | 710 ++++++
roms/u-boot/tools/bddb/dodelete.php | 65 +
roms/u-boot/tools/bddb/dodellog.php | 57 +
roms/u-boot/tools/bddb/doedit.php | 186 ++
roms/u-boot/tools/bddb/doedlog.php | 76 +
roms/u-boot/tools/bddb/donew.php | 230 ++
roms/u-boot/tools/bddb/donewlog.php | 86 +
roms/u-boot/tools/bddb/edit.php | 131 ++
roms/u-boot/tools/bddb/edlog.php | 86 +
roms/u-boot/tools/bddb/execute.php | 33 +
roms/u-boot/tools/bddb/index.php | 38 +
roms/u-boot/tools/bddb/new.php | 120 +
roms/u-boot/tools/bddb/newlog.php | 54 +
roms/u-boot/tools/bin2header.c | 40 +
roms/u-boot/tools/bmp_logo.c | 203 ++
roms/u-boot/tools/buildman/.gitignore | 1 +
roms/u-boot/tools/buildman/README | 690 ++++++
roms/u-boot/tools/buildman/board.py | 164 ++
roms/u-boot/tools/buildman/bsettings.py | 41 +
roms/u-boot/tools/buildman/builder.py | 1430 ++++++++++++
roms/u-boot/tools/buildman/buildman | 1 +
roms/u-boot/tools/buildman/buildman.py | 126 ++
roms/u-boot/tools/buildman/control.py | 174 ++
roms/u-boot/tools/buildman/test.py | 169 ++
roms/u-boot/tools/buildman/toolchain.py | 247 ++
roms/u-boot/tools/crc32.c | 1 +
roms/u-boot/tools/default_image.c | 194 ++
roms/u-boot/tools/dumpimage.c | 305 +++
roms/u-boot/tools/dumpimage.h | 33 +
roms/u-boot/tools/easylogo/Makefile | 3 +
roms/u-boot/tools/easylogo/easylogo.c | 610 +++++
roms/u-boot/tools/easylogo/linux_blackfin.tga | Bin 0 -> 158718 bytes
roms/u-boot/tools/easylogo/linux_logo.tga | Bin 0 -> 19244 bytes
roms/u-boot/tools/easylogo/runme.sh | 4 +
roms/u-boot/tools/env/.gitignore | 2 +
roms/u-boot/tools/env/Makefile | 34 +
roms/u-boot/tools/env/README | 60 +
roms/u-boot/tools/env/aes.c | 1 +
roms/u-boot/tools/env/crc32.c | 1 +
roms/u-boot/tools/env/ctype.c | 1 +
roms/u-boot/tools/env/env_attr.c | 1 +
roms/u-boot/tools/env/env_flags.c | 1 +
roms/u-boot/tools/env/fw_env.c | 1467 ++++++++++++
roms/u-boot/tools/env/fw_env.config | 22 +
roms/u-boot/tools/env/fw_env.h | 63 +
roms/u-boot/tools/env/fw_env_main.c | 147 ++
roms/u-boot/tools/env/linux_string.c | 1 +
roms/u-boot/tools/env_embedded.c | 1 +
roms/u-boot/tools/envcrc.c | 129 ++
roms/u-boot/tools/fdt.c | 1 +
roms/u-boot/tools/fdt_host.h | 16 +
roms/u-boot/tools/fdt_ro.c | 1 +
roms/u-boot/tools/fdt_rw.c | 1 +
roms/u-boot/tools/fdt_strerror.c | 1 +
roms/u-boot/tools/fdt_wip.c | 1 +
roms/u-boot/tools/fdtdec.c | 1 +
roms/u-boot/tools/fit_check_sign.c | 85 +
roms/u-boot/tools/fit_common.c | 86 +
roms/u-boot/tools/fit_common.h | 22 +
roms/u-boot/tools/fit_image.c | 156 ++
roms/u-boot/tools/fit_info.c | 96 +
roms/u-boot/tools/gdb/Makefile | 46 +
roms/u-boot/tools/gdb/error.c | 65 +
roms/u-boot/tools/gdb/error.h | 14 +
roms/u-boot/tools/gdb/gdbcont.c | 71 +
roms/u-boot/tools/gdb/gdbsend.c | 121 +
roms/u-boot/tools/gdb/remote.c | 916 ++++++++
roms/u-boot/tools/gdb/remote.h | 12 +
roms/u-boot/tools/gdb/serial.c | 133 ++
roms/u-boot/tools/gdb/serial.h | 18 +
roms/u-boot/tools/gen_eth_addr.c | 34 +
roms/u-boot/tools/getline.c | 90 +
roms/u-boot/tools/getline.h | 1 +
roms/u-boot/tools/gpheader.h | 40 +
roms/u-boot/tools/gpimage-common.c | 80 +
roms/u-boot/tools/gpimage.c | 77 +
roms/u-boot/tools/image-fit.c | 1 +
roms/u-boot/tools/image-host.c | 712 ++++++
roms/u-boot/tools/image-sig.c | 1 +
roms/u-boot/tools/image.c | 1 +
roms/u-boot/tools/imagetool.c | 60 +
roms/u-boot/tools/imagetool.h | 174 ++
roms/u-boot/tools/img2brec.sh | 388 ++++
roms/u-boot/tools/img2srec.c | 372 ++++
roms/u-boot/tools/imximage.c | 705 ++++++
roms/u-boot/tools/imximage.h | 175 ++
roms/u-boot/tools/jtagconsole | 39 +
roms/u-boot/tools/kermit/README | 51 +
roms/u-boot/tools/kermit/dot.kermrc | 16 +
roms/u-boot/tools/kermit/flash_param | 60 +
roms/u-boot/tools/kermit/send_cmd | 21 +
roms/u-boot/tools/kermit/send_image | 26 +
roms/u-boot/tools/kwbimage.c | 386 ++++
roms/u-boot/tools/kwbimage.h | 90 +
roms/u-boot/tools/kwboot.c | 742 +++++++
roms/u-boot/tools/logos/atmel.bmp | Bin 0 -> 15478 bytes
roms/u-boot/tools/logos/denx.bmp | Bin 0 -> 15538 bytes
roms/u-boot/tools/logos/esd.bmp | Bin 0 -> 35078 bytes
roms/u-boot/tools/logos/freescale.bmp | Bin 0 -> 46738 bytes
roms/u-boot/tools/logos/intercontrol.bmp | Bin 0 -> 4998 bytes
roms/u-boot/tools/logos/linux_logo_ttcontrol.bmp | Bin 0 -> 11830 bytes
.../tools/logos/linux_logo_ttcontrol_palfin.bmp | Bin 0 -> 20534 bytes
roms/u-boot/tools/logos/ronetix.bmp | Bin 0 -> 5638 bytes
roms/u-boot/tools/logos/siemens.bmp | Bin 0 -> 25766 bytes
roms/u-boot/tools/logos/syteco.bmp | Bin 0 -> 11414 bytes
roms/u-boot/tools/logos/wandboard.bmp | Bin 0 -> 22390 bytes
roms/u-boot/tools/md5.c | 1 +
roms/u-boot/tools/mingw_support.c | 116 +
roms/u-boot/tools/mingw_support.h | 46 +
roms/u-boot/tools/mkenvimage.c | 295 +++
roms/u-boot/tools/mkexynosspl.c | 187 ++
roms/u-boot/tools/mkimage.c | 654 ++++++
roms/u-boot/tools/mkimage.h | 49 +
roms/u-boot/tools/mpc86x_clk.c | 202 ++
roms/u-boot/tools/mxsboot.c | 673 ++++++
roms/u-boot/tools/mxsimage.c | 2348 ++++++++++++++++++++
roms/u-boot/tools/mxsimage.h | 230 ++
roms/u-boot/tools/ncb.c | 38 +
roms/u-boot/tools/netconsole | 63 +
roms/u-boot/tools/omap/clocks_get_m_n.c | 186 ++
roms/u-boot/tools/omapimage.c | 179 ++
roms/u-boot/tools/omapimage.h | 29 +
roms/u-boot/tools/os_support.c | 16 +
roms/u-boot/tools/os_support.h | 23 +
roms/u-boot/tools/palmtreo680/flash_u-boot.c | 177 ++
roms/u-boot/tools/patman/.gitignore | 1 +
roms/u-boot/tools/patman/README | 468 ++++
roms/u-boot/tools/patman/checkpatch.py | 174 ++
roms/u-boot/tools/patman/command.py | 101 +
roms/u-boot/tools/patman/commit.py | 88 +
roms/u-boot/tools/patman/cros_subprocess.py | 397 ++++
roms/u-boot/tools/patman/get_maintainer.py | 47 +
roms/u-boot/tools/patman/gitutil.py | 549 +++++
roms/u-boot/tools/patman/patchstream.py | 493 ++++
roms/u-boot/tools/patman/patman | 1 +
roms/u-boot/tools/patman/patman.py | 166 ++
roms/u-boot/tools/patman/project.py | 27 +
roms/u-boot/tools/patman/series.py | 267 +++
roms/u-boot/tools/patman/settings.py | 268 +++
roms/u-boot/tools/patman/terminal.py | 80 +
roms/u-boot/tools/patman/test.py | 242 ++
roms/u-boot/tools/pblimage.c | 331 +++
roms/u-boot/tools/pblimage.h | 20 +
roms/u-boot/tools/proftool.c | 598 +++++
roms/u-boot/tools/reformat.py | 132 ++
roms/u-boot/tools/relocate-rela.c | 189 ++
roms/u-boot/tools/rsa-checksum.c | 1 +
roms/u-boot/tools/rsa-sign.c | 1 +
roms/u-boot/tools/rsa-verify.c | 1 +
roms/u-boot/tools/scripts/define2mk.sed | 35 +
roms/u-boot/tools/sha1.c | 1 +
roms/u-boot/tools/sha256.c | 1 +
roms/u-boot/tools/ublimage.c | 261 +++
roms/u-boot/tools/ublimage.h | 84 +
roms/u-boot/tools/ubsha1.c | 84 +
roms/u-boot/tools/xway-swap-bytes.c | 38 +
167 files changed, 26561 insertions(+)
create mode 100644 roms/u-boot/tools/.gitignore
create mode 100644 roms/u-boot/tools/Makefile
create mode 100644 roms/u-boot/tools/aisimage.c
create mode 100644 roms/u-boot/tools/aisimage.h
create mode 100644 roms/u-boot/tools/bddb/README
create mode 100644 roms/u-boot/tools/bddb/badsubmit.php
create mode 100644 roms/u-boot/tools/bddb/bddb.css
create mode 100644 roms/u-boot/tools/bddb/brlog.php
create mode 100644 roms/u-boot/tools/bddb/browse.php
create mode 100644 roms/u-boot/tools/bddb/config.php
create mode 100644 roms/u-boot/tools/bddb/create_tables.sql
create mode 100644 roms/u-boot/tools/bddb/defs.php
create mode 100644 roms/u-boot/tools/bddb/dodelete.php
create mode 100644 roms/u-boot/tools/bddb/dodellog.php
create mode 100644 roms/u-boot/tools/bddb/doedit.php
create mode 100644 roms/u-boot/tools/bddb/doedlog.php
create mode 100644 roms/u-boot/tools/bddb/donew.php
create mode 100644 roms/u-boot/tools/bddb/donewlog.php
create mode 100644 roms/u-boot/tools/bddb/edit.php
create mode 100644 roms/u-boot/tools/bddb/edlog.php
create mode 100644 roms/u-boot/tools/bddb/execute.php
create mode 100644 roms/u-boot/tools/bddb/index.php
create mode 100644 roms/u-boot/tools/bddb/new.php
create mode 100644 roms/u-boot/tools/bddb/newlog.php
create mode 100644 roms/u-boot/tools/bin2header.c
create mode 100644 roms/u-boot/tools/bmp_logo.c
create mode 100644 roms/u-boot/tools/buildman/.gitignore
create mode 100644 roms/u-boot/tools/buildman/README
create mode 100644 roms/u-boot/tools/buildman/board.py
create mode 100644 roms/u-boot/tools/buildman/bsettings.py
create mode 100644 roms/u-boot/tools/buildman/builder.py
create mode 120000 roms/u-boot/tools/buildman/buildman
create mode 100755 roms/u-boot/tools/buildman/buildman.py
create mode 100644 roms/u-boot/tools/buildman/control.py
create mode 100644 roms/u-boot/tools/buildman/test.py
create mode 100644 roms/u-boot/tools/buildman/toolchain.py
create mode 100644 roms/u-boot/tools/crc32.c
create mode 100644 roms/u-boot/tools/default_image.c
create mode 100644 roms/u-boot/tools/dumpimage.c
create mode 100644 roms/u-boot/tools/dumpimage.h
create mode 100644 roms/u-boot/tools/easylogo/Makefile
create mode 100644 roms/u-boot/tools/easylogo/easylogo.c
create mode 100644 roms/u-boot/tools/easylogo/linux_blackfin.tga
create mode 100644 roms/u-boot/tools/easylogo/linux_logo.tga
create mode 100644 roms/u-boot/tools/easylogo/runme.sh
create mode 100644 roms/u-boot/tools/env/.gitignore
create mode 100644 roms/u-boot/tools/env/Makefile
create mode 100644 roms/u-boot/tools/env/README
create mode 100644 roms/u-boot/tools/env/aes.c
create mode 100644 roms/u-boot/tools/env/crc32.c
create mode 100644 roms/u-boot/tools/env/ctype.c
create mode 100644 roms/u-boot/tools/env/env_attr.c
create mode 100644 roms/u-boot/tools/env/env_flags.c
create mode 100644 roms/u-boot/tools/env/fw_env.c
create mode 100644 roms/u-boot/tools/env/fw_env.config
create mode 100644 roms/u-boot/tools/env/fw_env.h
create mode 100644 roms/u-boot/tools/env/fw_env_main.c
create mode 100644 roms/u-boot/tools/env/linux_string.c
create mode 100644 roms/u-boot/tools/env_embedded.c
create mode 100644 roms/u-boot/tools/envcrc.c
create mode 100644 roms/u-boot/tools/fdt.c
create mode 100644 roms/u-boot/tools/fdt_host.h
create mode 100644 roms/u-boot/tools/fdt_ro.c
create mode 100644 roms/u-boot/tools/fdt_rw.c
create mode 100644 roms/u-boot/tools/fdt_strerror.c
create mode 100644 roms/u-boot/tools/fdt_wip.c
create mode 100644 roms/u-boot/tools/fdtdec.c
create mode 100644 roms/u-boot/tools/fit_check_sign.c
create mode 100644 roms/u-boot/tools/fit_common.c
create mode 100644 roms/u-boot/tools/fit_common.h
create mode 100644 roms/u-boot/tools/fit_image.c
create mode 100644 roms/u-boot/tools/fit_info.c
create mode 100644 roms/u-boot/tools/gdb/Makefile
create mode 100644 roms/u-boot/tools/gdb/error.c
create mode 100644 roms/u-boot/tools/gdb/error.h
create mode 100644 roms/u-boot/tools/gdb/gdbcont.c
create mode 100644 roms/u-boot/tools/gdb/gdbsend.c
create mode 100644 roms/u-boot/tools/gdb/remote.c
create mode 100644 roms/u-boot/tools/gdb/remote.h
create mode 100644 roms/u-boot/tools/gdb/serial.c
create mode 100644 roms/u-boot/tools/gdb/serial.h
create mode 100644 roms/u-boot/tools/gen_eth_addr.c
create mode 100644 roms/u-boot/tools/getline.c
create mode 100644 roms/u-boot/tools/getline.h
create mode 100644 roms/u-boot/tools/gpheader.h
create mode 100644 roms/u-boot/tools/gpimage-common.c
create mode 100644 roms/u-boot/tools/gpimage.c
create mode 100644 roms/u-boot/tools/image-fit.c
create mode 100644 roms/u-boot/tools/image-host.c
create mode 100644 roms/u-boot/tools/image-sig.c
create mode 100644 roms/u-boot/tools/image.c
create mode 100644 roms/u-boot/tools/imagetool.c
create mode 100644 roms/u-boot/tools/imagetool.h
create mode 100755 roms/u-boot/tools/img2brec.sh
create mode 100644 roms/u-boot/tools/img2srec.c
create mode 100644 roms/u-boot/tools/imximage.c
create mode 100644 roms/u-boot/tools/imximage.h
create mode 100755 roms/u-boot/tools/jtagconsole
create mode 100644 roms/u-boot/tools/kermit/README
create mode 100644 roms/u-boot/tools/kermit/dot.kermrc
create mode 100644 roms/u-boot/tools/kermit/flash_param
create mode 100644 roms/u-boot/tools/kermit/send_cmd
create mode 100644 roms/u-boot/tools/kermit/send_image
create mode 100644 roms/u-boot/tools/kwbimage.c
create mode 100644 roms/u-boot/tools/kwbimage.h
create mode 100644 roms/u-boot/tools/kwboot.c
create mode 100644 roms/u-boot/tools/logos/atmel.bmp
create mode 100644 roms/u-boot/tools/logos/denx.bmp
create mode 100644 roms/u-boot/tools/logos/esd.bmp
create mode 100644 roms/u-boot/tools/logos/freescale.bmp
create mode 100644 roms/u-boot/tools/logos/intercontrol.bmp
create mode 100644 roms/u-boot/tools/logos/linux_logo_ttcontrol.bmp
create mode 100644 roms/u-boot/tools/logos/linux_logo_ttcontrol_palfin.bmp
create mode 100644 roms/u-boot/tools/logos/ronetix.bmp
create mode 100644 roms/u-boot/tools/logos/siemens.bmp
create mode 100644 roms/u-boot/tools/logos/syteco.bmp
create mode 100644 roms/u-boot/tools/logos/wandboard.bmp
create mode 100644 roms/u-boot/tools/md5.c
create mode 100644 roms/u-boot/tools/mingw_support.c
create mode 100644 roms/u-boot/tools/mingw_support.h
create mode 100644 roms/u-boot/tools/mkenvimage.c
create mode 100644 roms/u-boot/tools/mkexynosspl.c
create mode 100644 roms/u-boot/tools/mkimage.c
create mode 100644 roms/u-boot/tools/mkimage.h
create mode 100644 roms/u-boot/tools/mpc86x_clk.c
create mode 100644 roms/u-boot/tools/mxsboot.c
create mode 100644 roms/u-boot/tools/mxsimage.c
create mode 100644 roms/u-boot/tools/mxsimage.h
create mode 100644 roms/u-boot/tools/ncb.c
create mode 100755 roms/u-boot/tools/netconsole
create mode 100644 roms/u-boot/tools/omap/clocks_get_m_n.c
create mode 100644 roms/u-boot/tools/omapimage.c
create mode 100644 roms/u-boot/tools/omapimage.h
create mode 100644 roms/u-boot/tools/os_support.c
create mode 100644 roms/u-boot/tools/os_support.h
create mode 100644 roms/u-boot/tools/palmtreo680/flash_u-boot.c
create mode 100644 roms/u-boot/tools/patman/.gitignore
create mode 100644 roms/u-boot/tools/patman/README
create mode 100644 roms/u-boot/tools/patman/checkpatch.py
create mode 100644 roms/u-boot/tools/patman/command.py
create mode 100644 roms/u-boot/tools/patman/commit.py
create mode 100644 roms/u-boot/tools/patman/cros_subprocess.py
create mode 100644 roms/u-boot/tools/patman/get_maintainer.py
create mode 100644 roms/u-boot/tools/patman/gitutil.py
create mode 100644 roms/u-boot/tools/patman/patchstream.py
create mode 120000 roms/u-boot/tools/patman/patman
create mode 100755 roms/u-boot/tools/patman/patman.py
create mode 100644 roms/u-boot/tools/patman/project.py
create mode 100644 roms/u-boot/tools/patman/series.py
create mode 100644 roms/u-boot/tools/patman/settings.py
create mode 100644 roms/u-boot/tools/patman/terminal.py
create mode 100644 roms/u-boot/tools/patman/test.py
create mode 100644 roms/u-boot/tools/pblimage.c
create mode 100644 roms/u-boot/tools/pblimage.h
create mode 100644 roms/u-boot/tools/proftool.c
create mode 100755 roms/u-boot/tools/reformat.py
create mode 100644 roms/u-boot/tools/relocate-rela.c
create mode 100644 roms/u-boot/tools/rsa-checksum.c
create mode 100644 roms/u-boot/tools/rsa-sign.c
create mode 100644 roms/u-boot/tools/rsa-verify.c
create mode 100644 roms/u-boot/tools/scripts/define2mk.sed
create mode 100644 roms/u-boot/tools/sha1.c
create mode 100644 roms/u-boot/tools/sha256.c
create mode 100644 roms/u-boot/tools/ublimage.c
create mode 100644 roms/u-boot/tools/ublimage.h
create mode 100644 roms/u-boot/tools/ubsha1.c
create mode 100644 roms/u-boot/tools/xway-swap-bytes.c
(limited to 'roms/u-boot/tools')
diff --git a/roms/u-boot/tools/.gitignore b/roms/u-boot/tools/.gitignore
new file mode 100644
index 00000000..b1e997fc
--- /dev/null
+++ b/roms/u-boot/tools/.gitignore
@@ -0,0 +1,22 @@
+/bmp_logo
+/envcrc
+/fit_check_sign
+/fit_info
+/gen_eth_addr
+/img2srec
+/kwboot
+/dumpimage
+/mkenvimage
+/mkimage
+/mkexynosspl
+/mpc86x_clk
+/mxsboot
+/ncb
+/proftool
+/relocate-rela
+/ubsha1
+/xway-swap-bytes
+/*.exe
+/easylogo/easylogo
+/gdb/gdbcont
+/gdb/gdbsend
diff --git a/roms/u-boot/tools/Makefile b/roms/u-boot/tools/Makefile
new file mode 100644
index 00000000..6e43a015
--- /dev/null
+++ b/roms/u-boot/tools/Makefile
@@ -0,0 +1,217 @@
+#
+# (C) Copyright 2000-2006
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+#
+# toolchains targeting win32 generate .exe files
+#
+ifneq (,$(findstring WIN32 ,$(shell $(HOSTCC) -E -dM -xc /dev/null)))
+SFX = .exe
+else
+SFX =
+endif
+
+# Enable all the config-independent tools
+ifneq ($(HOST_TOOLS_ALL),)
+CONFIG_LCD_LOGO = y
+CONFIG_CMD_LOADS = y
+CONFIG_CMD_NET = y
+CONFIG_XWAY_SWAP_BYTES = y
+CONFIG_NETCONSOLE = y
+CONFIG_SHA1_CHECK_UB_IMG = y
+endif
+
+subdir-$(HOST_TOOLS_ALL) += easylogo
+subdir-$(HOST_TOOLS_ALL) += gdb
+
+# Merge all the different vars for envcrc into one
+ENVCRC-$(CONFIG_ENV_IS_EMBEDDED) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_DATAFLASH) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_EEPROM) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_FLASH) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_ONENAND) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_NAND) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
+ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
+CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
+
+# TODO: CONFIG_CMD_LICENSE does not work
+hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX)
+hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
+hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX)
+HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic
+
+hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
+envcrc$(SFX)-objs := crc32.o env_embedded.o envcrc.o sha1.o
+
+hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
+HOSTCFLAGS_gen_eth_addr$(SFX).o := -pedantic
+
+hostprogs-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
+HOSTCFLAGS_img2srec$(SFX).o := -pedantic
+
+hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
+HOSTCFLAGS_xway-swap-bytes$(SFX).o := -pedantic
+
+hostprogs-y += mkenvimage$(SFX)
+mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o
+
+hostprogs-y += dumpimage$(SFX) mkimage$(SFX)
+hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info$(SFX) fit_check_sign$(SFX)
+
+FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o
+# Flattened device tree objects
+LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o
+RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o
+
+# common objs for dumpimage and mkimage
+dumpimage-mkimage-objs := aisimage.o \
+ $(FIT_SIG_OBJS-y) \
+ crc32.o \
+ default_image.o \
+ fdtdec.o \
+ fit_common.o \
+ fit_image.o \
+ gpimage.o \
+ gpimage-common.o \
+ image-fit.o \
+ image-host.o \
+ image.o \
+ imagetool.o \
+ imximage.o \
+ kwbimage.o \
+ md5.o \
+ mxsimage.o \
+ omapimage.o \
+ os_support.o \
+ pblimage.o \
+ sha1.o \
+ sha256.o \
+ ublimage.o \
+ $(LIBFDT_OBJS) \
+ $(RSA_OBJS-y)
+
+dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o
+mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o
+fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o
+fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
+
+# TODO(sjg@chromium.org): Is this correct on Mac OS?
+
+# MXSImage needs LibSSL
+ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
+HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
+# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
+# the mxsimage support within tools/mxsimage.c .
+HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
+endif
+
+ifdef CONFIG_FIT_SIGNATURE
+HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
+HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
+
+# This affects include/image.h, but including the board config file
+# is tricky, so manually define this options here.
+HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE
+endif
+
+hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX)
+hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX)
+HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic
+
+hostprogs-$(CONFIG_MX23) += mxsboot$(SFX)
+hostprogs-$(CONFIG_MX28) += mxsboot$(SFX)
+HOSTCFLAGS_mxsboot$(SFX).o := -pedantic
+
+hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX)
+hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
+
+ubsha1$(SFX)-objs := os_support.o sha1.o ubsha1.o
+
+HOSTCFLAGS_ubsha1.o := -pedantic
+
+hostprogs-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
+hostprogs-y += proftool$(SFX)
+hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
+
+# We build some files with extra pedantic flags to try to minimize things
+# that won't build on some weird host compiler -- though there are lots of
+# exceptions for files that aren't complaint.
+HOSTCFLAGS_crc32.o := -pedantic
+HOSTCFLAGS_md5.o := -pedantic
+HOSTCFLAGS_sha1.o := -pedantic
+HOSTCFLAGS_sha256.o := -pedantic
+
+# Don't build by default
+#hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX)
+#HOSTCFLAGS_mpc86x_clk$(SFX).o := -pedantic
+
+always := $(hostprogs-y)
+
+# Generated LCD/video logo
+LOGO_H = $(objtree)/include/bmp_logo.h
+LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
+LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
+LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
+LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
+LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
+
+# Generic logo
+ifeq ($(LOGO_BMP),)
+LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
+
+# Use board logo and fallback to vendor
+ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
+LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
+else
+ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
+LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
+endif
+endif
+
+endif # !LOGO_BMP
+
+#
+# Use native tools and options
+# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
+# Define _GNU_SOURCE to obtain the getline prototype from stdio.h
+#
+HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \
+ $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \
+ -I$(srctree)/lib/libfdt \
+ -I$(srctree)/tools \
+ -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
+ -DUSE_HOSTCC \
+ -D__KERNEL_STRICT_NAMES \
+ -D_GNU_SOURCE
+
+__build: $(LOGO-y)
+
+$(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP)
+ $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
+
+$(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
+ $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
+
+# Let clean descend into subdirs
+subdir- += env
+
+ifneq ($(CROSS_BUILD_TOOLS),)
+HOSTCC = $(CC)
+
+quiet_cmd_crosstools_strip = STRIP $^
+ cmd_crosstools_strip = $(STRIP) $^; touch $@
+$(obj)/.strip: $(call objectify,$(filter $(always),$(hostprogs-y)))
+ $(call cmd,crosstools_strip)
+
+always += .strip
+endif
+clean-files += .strip
diff --git a/roms/u-boot/tools/aisimage.c b/roms/u-boot/tools/aisimage.c
new file mode 100644
index 00000000..8de370a2
--- /dev/null
+++ b/roms/u-boot/tools/aisimage.c
@@ -0,0 +1,431 @@
+/*
+ * (C) Copyright 2011
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include "aisimage.h"
+#include
+
+#define IS_FNC_EXEC(c) (cmd_table[c].AIS_cmd == AIS_CMD_FNLOAD)
+#define WORD_ALIGN0 4
+#define WORD_ALIGN(len) (((len)+WORD_ALIGN0-1) & ~(WORD_ALIGN0-1))
+#define MAX_CMD_BUFFER 4096
+
+static uint32_t ais_img_size;
+
+/*
+ * Supported commands for configuration file
+ */
+static table_entry_t aisimage_cmds[] = {
+ {CMD_DATA, "DATA", "Reg Write Data"},
+ {CMD_FILL, "FILL", "Fill range with pattern"},
+ {CMD_CRCON, "CRCON", "CRC Enable"},
+ {CMD_CRCOFF, "CRCOFF", "CRC Disable"},
+ {CMD_CRCCHECK, "CRCCHECK", "CRC Validate"},
+ {CMD_JMPCLOSE, "JMPCLOSE", "Jump & Close"},
+ {CMD_JMP, "JMP", "Jump"},
+ {CMD_SEQREAD, "SEQREAD", "Sequential read"},
+ {CMD_PLL0, "PLL0", "PLL0"},
+ {CMD_PLL1, "PLL1", "PLL1"},
+ {CMD_CLK, "CLK", "Clock configuration"},
+ {CMD_DDR2, "DDR2", "DDR2 Configuration"},
+ {CMD_EMIFA, "EMIFA", "EMIFA"},
+ {CMD_EMIFA_ASYNC, "EMIFA_ASYNC", "EMIFA Async"},
+ {CMD_PLL, "PLL", "PLL & Clock configuration"},
+ {CMD_PSC, "PSC", "PSC setup"},
+ {CMD_PINMUX, "PINMUX", "Pinmux setup"},
+ {CMD_BOOTTABLE, "BOOT_TABLE", "Boot table command"},
+ {-1, "", ""},
+};
+
+static struct ais_func_exec {
+ uint32_t index;
+ uint32_t argcnt;
+} ais_func_table[] = {
+ [CMD_PLL0] = {0, 2},
+ [CMD_PLL1] = {1, 2},
+ [CMD_CLK] = {2, 1},
+ [CMD_DDR2] = {3, 8},
+ [CMD_EMIFA] = {4, 5},
+ [CMD_EMIFA_ASYNC] = {5, 5},
+ [CMD_PLL] = {6, 3},
+ [CMD_PSC] = {7, 1},
+ [CMD_PINMUX] = {8, 3}
+};
+
+static struct cmd_table_t {
+ uint32_t nargs;
+ uint32_t AIS_cmd;
+} cmd_table[] = {
+ [CMD_FILL] = { 4, AIS_CMD_FILL},
+ [CMD_CRCON] = { 0, AIS_CMD_ENCRC},
+ [CMD_CRCOFF] = { 0, AIS_CMD_DISCRC},
+ [CMD_CRCCHECK] = { 2, AIS_CMD_ENCRC},
+ [CMD_JMPCLOSE] = { 1, AIS_CMD_JMPCLOSE},
+ [CMD_JMP] = { 1, AIS_CMD_JMP},
+ [CMD_SEQREAD] = { 0, AIS_CMD_SEQREAD},
+ [CMD_PLL0] = { 2, AIS_CMD_FNLOAD},
+ [CMD_PLL1] = { 2, AIS_CMD_FNLOAD},
+ [CMD_CLK] = { 1, AIS_CMD_FNLOAD},
+ [CMD_DDR2] = { 8, AIS_CMD_FNLOAD},
+ [CMD_EMIFA] = { 5, AIS_CMD_FNLOAD},
+ [CMD_EMIFA_ASYNC] = { 5, AIS_CMD_FNLOAD},
+ [CMD_PLL] = { 3, AIS_CMD_FNLOAD},
+ [CMD_PSC] = { 1, AIS_CMD_FNLOAD},
+ [CMD_PINMUX] = { 3, AIS_CMD_FNLOAD},
+ [CMD_BOOTTABLE] = { 4, AIS_CMD_BOOTTBL},
+};
+
+static uint32_t get_cfg_value(char *token, char *name, int linenr)
+{
+ char *endptr;
+ uint32_t value;
+
+ errno = 0;
+ value = strtoul(token, &endptr, 16);
+ if (errno || (token == endptr)) {
+ fprintf(stderr, "Error: %s[%d] - Invalid hex data(%s)\n",
+ name, linenr, token);
+ exit(EXIT_FAILURE);
+ }
+ return value;
+}
+
+static int get_ais_table_id(uint32_t *ptr)
+{
+
+ int i;
+ int func_no;
+
+ for (i = 0; i < ARRAY_SIZE(cmd_table); i++) {
+ if (*ptr == cmd_table[i].AIS_cmd) {
+ if (cmd_table[i].AIS_cmd != AIS_CMD_FNLOAD)
+ return i;
+
+ func_no = ((struct ais_cmd_func *)ptr)->func_args
+ & 0xFFFF;
+ if (func_no == ais_func_table[i].index)
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static void aisimage_print_header(const void *hdr)
+{
+ struct ais_header *ais_hdr = (struct ais_header *)hdr;
+ uint32_t *ptr;
+ struct ais_cmd_load *ais_load;
+ int id;
+
+ if (ais_hdr->magic != AIS_MAGIC_WORD) {
+ fprintf(stderr, "Error: - AIS Magic Number not found\n");
+ return;
+ }
+ fprintf(stdout, "Image Type: TI Davinci AIS Boot Image\n");
+ fprintf(stdout, "AIS magic : %08x\n", ais_hdr->magic);
+ ptr = (uint32_t *)&ais_hdr->magic;
+ ptr++;
+
+ while (*ptr != AIS_CMD_JMPCLOSE) {
+ /* Check if we find the image */
+ if (*ptr == AIS_CMD_LOAD) {
+ ais_load = (struct ais_cmd_load *)ptr;
+ fprintf(stdout, "Image at : 0x%08x size 0x%08x\n",
+ ais_load->addr,
+ ais_load->size);
+ ptr = ais_load->data + ais_load->size / sizeof(*ptr);
+ continue;
+ }
+
+ id = get_ais_table_id(ptr);
+ if (id < 0) {
+ fprintf(stderr, "Error: - AIS Image corrupted\n");
+ return;
+ }
+ fprintf(stdout, "AIS cmd : %s\n",
+ get_table_entry_name(aisimage_cmds, NULL, id));
+ ptr += cmd_table[id].nargs + IS_FNC_EXEC(id) + 1;
+ if (((void *)ptr - hdr) > ais_img_size) {
+ fprintf(stderr,
+ "AIS Image not terminated by JMPCLOSE\n");
+ return;
+ }
+ }
+}
+
+static uint32_t *ais_insert_cmd_header(uint32_t cmd, uint32_t nargs,
+ uint32_t *parms, struct image_type_params *tparams,
+ uint32_t *ptr)
+{
+ int i;
+
+ *ptr++ = cmd_table[cmd].AIS_cmd;
+ if (IS_FNC_EXEC(cmd))
+ *ptr++ = ((nargs & 0xFFFF) << 16) + ais_func_table[cmd].index;
+
+ /* Copy parameters */
+ for (i = 0; i < nargs; i++)
+ *ptr++ = cpu_to_le32(parms[i]);
+
+ return ptr;
+
+}
+
+static uint32_t *ais_alloc_buffer(struct image_tool_params *params)
+{
+ int dfd;
+ struct stat sbuf;
+ char *datafile = params->datafile;
+ uint32_t *ptr;
+
+ dfd = open(datafile, O_RDONLY|O_BINARY);
+ if (dfd < 0) {
+ fprintf(stderr, "%s: Can't open %s: %s\n",
+ params->cmdname, datafile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (fstat(dfd, &sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat %s: %s\n",
+ params->cmdname, datafile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Place for header is allocated. The size is taken from
+ * the size of the datafile, that the ais_image_generate()
+ * will copy into the header. Copying the datafile
+ * is not left to the main program, because after the datafile
+ * the header must be terminated with the Jump & Close command.
+ */
+ ais_img_size = WORD_ALIGN(sbuf.st_size) + MAX_CMD_BUFFER;
+ ptr = (uint32_t *)malloc(WORD_ALIGN(sbuf.st_size) + MAX_CMD_BUFFER);
+ if (!ptr) {
+ fprintf(stderr, "%s: malloc return failure: %s\n",
+ params->cmdname, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ close(dfd);
+
+ return ptr;
+}
+
+static uint32_t *ais_copy_image(struct image_tool_params *params,
+ uint32_t *aisptr)
+
+{
+ int dfd;
+ struct stat sbuf;
+ char *datafile = params->datafile;
+ void *ptr;
+
+ dfd = open(datafile, O_RDONLY|O_BINARY);
+ if (dfd < 0) {
+ fprintf(stderr, "%s: Can't open %s: %s\n",
+ params->cmdname, datafile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (fstat(dfd, &sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat %s: %s\n",
+ params->cmdname, datafile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0);
+ *aisptr++ = AIS_CMD_LOAD;
+ *aisptr++ = params->ep;
+ *aisptr++ = sbuf.st_size;
+ memcpy((void *)aisptr, ptr, sbuf.st_size);
+ aisptr += WORD_ALIGN(sbuf.st_size) / sizeof(uint32_t);
+
+ (void) munmap((void *)ptr, sbuf.st_size);
+ (void) close(dfd);
+
+ return aisptr;
+
+}
+
+static int aisimage_generate(struct image_tool_params *params,
+ struct image_type_params *tparams)
+{
+ FILE *fd = NULL;
+ char *line = NULL;
+ char *token, *saveptr1, *saveptr2;
+ int lineno = 0;
+ int fld;
+ size_t len;
+ int32_t cmd;
+ uint32_t nargs, cmd_parms[10];
+ uint32_t value, size;
+ char *name = params->imagename;
+ uint32_t *aishdr;
+
+ fd = fopen(name, "r");
+ if (fd == 0) {
+ fprintf(stderr,
+ "Error: %s - Can't open AIS configuration\n", name);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * the size of the header is variable and is computed
+ * scanning the configuration file.
+ */
+ tparams->header_size = 0;
+
+ /*
+ * Start allocating a buffer suitable for most command
+ * The buffer is then reallocated if it is too small
+ */
+ aishdr = ais_alloc_buffer(params);
+ tparams->hdr = aishdr;
+ *aishdr++ = AIS_MAGIC_WORD;
+
+ /* Very simple parsing, line starting with # are comments
+ * and are dropped
+ */
+ while ((getline(&line, &len, fd)) > 0) {
+ lineno++;
+
+ token = strtok_r(line, "\r\n", &saveptr1);
+ if (token == NULL)
+ continue;
+
+ /* Check inside the single line */
+ line = token;
+ fld = CFG_COMMAND;
+ cmd = CMD_INVALID;
+ nargs = 0;
+ while (token != NULL) {
+ token = strtok_r(line, " \t", &saveptr2);
+ if (token == NULL)
+ break;
+
+ /* Drop all text starting with '#' as comments */
+ if (token[0] == '#')
+ break;
+
+ switch (fld) {
+ case CFG_COMMAND:
+ cmd = get_table_entry_id(aisimage_cmds,
+ "aisimage commands", token);
+ if (cmd < 0) {
+ fprintf(stderr,
+ "Error: %s[%d] - Invalid command"
+ "(%s)\n", name, lineno, token);
+
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case CFG_VALUE:
+ value = get_cfg_value(token, name, lineno);
+ cmd_parms[nargs++] = value;
+ if (nargs > cmd_table[cmd].nargs) {
+ fprintf(stderr,
+ "Error: %s[%d] - too much arguments:"
+ "(%s) for command %s\n", name,
+ lineno, token,
+ aisimage_cmds[cmd].sname);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ }
+ line = NULL;
+ fld = CFG_VALUE;
+ }
+ if (cmd != CMD_INVALID) {
+ /* Now insert the command into the header */
+ aishdr = ais_insert_cmd_header(cmd, nargs, cmd_parms,
+ tparams, aishdr);
+ }
+
+ }
+ fclose(fd);
+
+ aishdr = ais_copy_image(params, aishdr);
+
+ /* Add Jmp & Close */
+ *aishdr++ = AIS_CMD_JMPCLOSE;
+ *aishdr++ = params->ep;
+
+ size = (aishdr - (uint32_t *)tparams->hdr) * sizeof(uint32_t);
+ tparams->header_size = size;
+
+ return 0;
+}
+
+static int aisimage_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_AISIMAGE)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static int aisimage_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ struct ais_header *ais_hdr = (struct ais_header *)ptr;
+
+ if (ais_hdr->magic != AIS_MAGIC_WORD)
+ return -FDT_ERR_BADSTRUCTURE;
+
+ /* Store the total size to remember in print_hdr */
+ ais_img_size = image_size;
+
+ return 0;
+}
+
+static void aisimage_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+}
+
+int aisimage_check_params(struct image_tool_params *params)
+{
+ if (!params)
+ return CFG_INVALID;
+ if (!strlen(params->imagename)) {
+ fprintf(stderr, "Error: %s - Configuration file not specified, "
+ "it is needed for aisimage generation\n",
+ params->cmdname);
+ return CFG_INVALID;
+ }
+ /*
+ * Check parameters:
+ * XIP is not allowed and verify that incompatible
+ * parameters are not sent at the same time
+ * For example, if list is required a data image must not be provided
+ */
+ return (params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)) ||
+ (params->xflag) || !(strlen(params->imagename));
+}
+
+/*
+ * aisimage parameters
+ */
+static struct image_type_params aisimage_params = {
+ .name = "TI Davinci AIS Boot Image support",
+ .header_size = 0,
+ .hdr = NULL,
+ .check_image_type = aisimage_check_image_types,
+ .verify_header = aisimage_verify_header,
+ .print_header = aisimage_print_header,
+ .set_header = aisimage_set_header,
+ .check_params = aisimage_check_params,
+ .vrec_header = aisimage_generate,
+};
+
+void init_ais_image_type(void)
+{
+ register_image_type(&aisimage_params);
+}
diff --git a/roms/u-boot/tools/aisimage.h b/roms/u-boot/tools/aisimage.h
new file mode 100644
index 00000000..e1aa3ef7
--- /dev/null
+++ b/roms/u-boot/tools/aisimage.h
@@ -0,0 +1,81 @@
+/*
+ * (C) Copyright 2011
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _AISIMAGE_H_
+#define _AISIMAGE_H_
+
+/* all values are for little endian systems */
+#define AIS_MAGIC_WORD 0x41504954
+#define AIS_FCN_MAX 8
+
+enum {
+ AIS_CMD_LOAD = 0x58535901,
+ AIS_CMD_VALCRC = 0x58535902,
+ AIS_CMD_ENCRC = 0x58535903,
+ AIS_CMD_DISCRC = 0x58535904,
+ AIS_CMD_JMP = 0x58535905,
+ AIS_CMD_JMPCLOSE = 0x58535906,
+ AIS_CMD_BOOTTBL = 0x58535907,
+ AIS_CMD_FILL = 0x5853590A,
+ AIS_CMD_FNLOAD = 0x5853590D,
+ AIS_CMD_SEQREAD = 0x58535963,
+};
+
+struct ais_cmd_load {
+ uint32_t cmd;
+ uint32_t addr;
+ uint32_t size;
+ uint32_t data[1];
+};
+
+struct ais_cmd_func {
+ uint32_t cmd;
+ uint32_t func_args;
+ uint32_t parms[AIS_FCN_MAX];
+};
+
+struct ais_cmd_jmpclose {
+ uint32_t cmd;
+ uint32_t addr;
+};
+
+#define CMD_DATA_STR "DATA"
+
+enum ais_file_cmd {
+ CMD_INVALID,
+ CMD_FILL,
+ CMD_CRCON,
+ CMD_CRCOFF,
+ CMD_CRCCHECK,
+ CMD_JMPCLOSE,
+ CMD_JMP,
+ CMD_SEQREAD,
+ CMD_DATA,
+ CMD_PLL0,
+ CMD_PLL1,
+ CMD_CLK,
+ CMD_DDR2,
+ CMD_EMIFA,
+ CMD_EMIFA_ASYNC,
+ CMD_PLL,
+ CMD_PSC,
+ CMD_PINMUX,
+ CMD_BOOTTABLE
+};
+
+enum aisimage_fld_types {
+ CFG_INVALID = -1,
+ CFG_COMMAND,
+ CFG_VALUE,
+};
+
+struct ais_header {
+ uint32_t magic;
+ char data[1];
+};
+
+#endif /* _AISIMAGE_H_ */
diff --git a/roms/u-boot/tools/bddb/README b/roms/u-boot/tools/bddb/README
new file mode 100644
index 00000000..9bee59a0
--- /dev/null
+++ b/roms/u-boot/tools/bddb/README
@@ -0,0 +1,116 @@
+Hymod Board Database
+
+(C) Copyright 2001
+Murray Jensen
+CSIRO Manufacturing Science and Technology, Preston Lab
+
+25-Jun-01
+
+This stuff is a set of PHP/MySQL scripts to implement a custom board
+database. It will need *extensive* hacking to modify it to keep the
+information about your custom boards that you want, however it is a good
+starting point.
+
+How it is used:
+
+ 1. a board has gone through all the hardware testing etc and is
+ ready to have the flash programmed for the first time - first you
+ go to a web page and fill in information about the board in a form
+ to register it in a database
+
+ 2. the web stuff allocates a (unique) serial number and (optionally)
+ a (locally administered) ethernet address and stores the information
+ in a database using the serial number as the key (can do whole
+ batches of boards in one go and/or use a previously registered board
+ as defaults for the new board(s))
+
+ 3. it then creates a file in the tftp area of a server somewhere
+ containing the board information in a simple text format (one
+ per serial number)
+
+ 4. all hymod boards have an i2c eeprom, and when U-Boot sees that
+ the eeprom is unitialised, it prompts for a serial number and
+ ethernet address (if not set), then transfers the file created
+ in step 3 from the server and initialises the eeprom from its
+ contents
+
+What this means is you can't boot the board until you have allocated a serial
+number, but you don't have to type it all twice - you do it once on the web
+and the board then finds the info it needs to initialise its eeprom. The
+other side of the coin is the reading of the eeprom and how it gets passed
+to Linux (or another O/S).
+
+To see how this is all done for the hymod boards look at the code in the
+"board/hymod" directory and in the file "include/asm/hymod.h". Hymod boards
+can have a mezzanine card which also have an eeprom that needs allocating,
+the same process is used for these as well - just a different i2c address.
+
+Other forms provide the following functions:
+
+ - browsing the board database
+ - editing board information (one at a time)
+ - maintaining/browsing a (simple) per board event log
+
+You will need: MySQL (I use version 3.23.7-alpha), PHP4 (with MySQL
+support enabled) and a web server (I use Apache 1.3.x).
+
+I originally started by using phpMyBuilder (http://kyber.dk/phpMyBuilder)
+but it soon got far more complicated than that could handle (but I left
+the copyright messages in there anyway). Most of the code resides in the
+common defs.php file, which shouldn't need much alteration - all the work
+will be in shaping the front-end php files to your liking.
+
+Here's a quick summary of what needs doing to use it for your boards:
+
+1. get phpMyAdmin (http://phpwizard.net/projects/phpMyAdmin/) - it's an
+ invaluable tool for this sort of stuff (this step is optional of course)
+
+2. edit "bddb.css" to your taste, if you could be bothered - I have no
+ idea what is in there or what it does - I copied it from somewhere else
+ ("user.css" from the phpMyEdit (http://phpmyedit.sourcerforge.net) package,
+ I think) - I figure one day I'll see what sort of things I can change
+ in there.
+
+3. create a mysql database - call it whatever you like
+
+4. edit "create_tables.sql" and modify the "boards" table schema to
+ reflect the information you want to keep about your boards. It may or
+ may not be easier to do this and the next step in phpMyAdmin. Check out
+ the MySQL documentation at http://www.mysql.com/doc/ in particular the
+ column types at http://www.mysql.com/doc/C/o/Column_types.html - Note
+ there is only support for a few data types:
+
+ int - presented as an html text input
+ char/text - presented as an html text input
+ date - presented as an html text input
+ enum - presented as an html radio input
+
+ I also have what I call "enum_multi" which is a set of enums with the
+ same name, but suffixed with a number e.g. fred0, fred1, fred2. These
+ are presented as a number of html select's with a single label "fred"
+ this is useful for board characteristics that have multiple items of
+ the same type e.g. multiple banks of sdram.
+
+5. use the "create_tables.sql" file to create the "boards" table in the
+ database e.g. mysql dbname < create_tables.sql
+
+6. create a user and password for the web server to log into the MySQL
+ database with; give this user select, insert and update privileges
+ to the database created in 3 (and delete, if you want the "delete"
+ functions in the edit forms to work- I have this turned off). phpMyAdmin
+ helps in this step.
+
+7. edit "config.php" and set the variables: $mysql_user, $mysql_pw, $mysql_db,
+ $bddb_cfgdir and $bddb_label - keep the contents of this file secret - it
+ contains the web servers username and password (the three $mysql_* vars
+ are set from the previous step)
+
+8. edit "defs.php" and a. adjust the various enum value arrays and b. edit
+ the function "pg_foot()" to remove my email address :-)
+
+9. do major hacking on the following files: browse.php, doedit.php, donew.php,
+ edit.php and new.php to reflect your database schema - fortunately the
+ hacking is fairly straight-forward, but it is boring and time-consuming.
+
+These notes were written rather hastily - if you find any obvious problems
+please let me know.
diff --git a/roms/u-boot/tools/bddb/badsubmit.php b/roms/u-boot/tools/bddb/badsubmit.php
new file mode 100644
index 00000000..5092a319
--- /dev/null
+++ b/roms/u-boot/tools/bddb/badsubmit.php
@@ -0,0 +1,23 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ require("defs.php");
+ pg_head("$bddb_label - Unknown Submit Type");
+?>
+
+
+
+ The form was submitted with an
+ unknown SUBMIT type .
+
+ Perhaps you typed the URL in directly? Click here to go to the
+ home page of the .
+
+
+
+
diff --git a/roms/u-boot/tools/bddb/bddb.css b/roms/u-boot/tools/bddb/bddb.css
new file mode 100644
index 00000000..dee2b2ee
--- /dev/null
+++ b/roms/u-boot/tools/bddb/bddb.css
@@ -0,0 +1,207 @@
+BODY {
+ background: #e0ffff;
+ color: #000000;
+ font-family: Arial, Verdana, Helvetica;
+}
+H1 {
+ font-family: "Copperplate Gothic Bold";
+ background: transparent;
+ color: #993300;
+ text-align: center;
+}
+H2, H3, H4, H5 {
+ background: transparent;
+ color: #993300;
+ margin-top: 4%;
+ text-align: center;
+}
+Body.Plain Div.Abstract, Body.Plain P.Abstract {
+ background: #cccc99;
+ color: #333300;
+ border: white;
+ padding: 3%;
+ font-family: Times, Verdana;
+}
+TH.Nav {
+ background: #0000cc;
+ color: #ff9900;
+}
+TH.Menu {
+ background: #3366cc;
+ color: #ff9900;
+}
+A:hover {
+ color: #ff6600;
+}
+A.Menu:hover {
+ color: #ff6600;
+}
+A.HoMe:hover {
+ color: #ff6600;
+}
+A.Menu {
+ background: transparent;
+ color: #ffcc33;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: smaller;
+ text-decoration: none;
+}
+A.Menu:visited {
+ background: transparent;
+ color: #ffcc99;
+}
+A.HoMe {
+ background: transparent;
+ color: #ffcc33;
+ font-family: Verdana, Helvetica, Arial;
+ text-decoration:none;
+}
+A.HoMe:visited {
+ background: transparent;
+ color: #ffcc99;
+}
+TH.Xmp {
+ background: #eeeeee;
+ color: #330066;
+ font-family: courier;
+ font-weight: normal;
+}
+TH.LuT {
+ background: #cccccc;
+ color: #000000;
+}
+TD.LuT {
+ background: #ffffcc;
+ color: #000000;
+ font-size: 85%;
+}
+TH.Info, TD.Info {
+ background: #ffffcc;
+ color: #660000;
+ font-family: "Comic Sans MS", Cursive, Verdana;
+ font-size: smaller;
+}
+Div.Info, P.Info {
+ background: #ffff99;
+ color: #990033;
+ text-align: left;
+ padding: 2%;
+ font-family: "Comic Sans MS", Cursive, Verdana;
+ font-size: 85%;
+ }
+Div.Info A {
+ background: transparent;
+ color: #ff6600;
+}
+.HL {
+ background: #ffff99;
+ color: #000000;
+}
+TD.HL {
+ background: #ccffff;
+ color: #000000;
+}
+Div.Margins {
+ width: 512px;
+ text-align: center;
+}
+TD.Plain {
+ background: #ffffcc;
+ color: #000033;
+}
+.Type {
+ background: #cccccc;
+ color: #660000;
+}
+.Name {
+ background: #eeeeee;
+ color: #660000;
+ vertical-align: top;
+ text-align: right;
+}
+.Value {
+ background: #ffffee;
+ color: #000066;
+}
+.Drop {
+ background: #333366;
+ color: #ffcc33;
+ font-family: "Copperplate Gothic Light", Helvetica, Verdana, Arial;
+}
+A.Button:hover {
+ color: #ff6600;
+}
+A.Button {
+ text-decoration:none;
+ color: #003366;
+ background: #ffcc66;
+}
+.Button {
+ font-size: 9pt;
+ text-align: center;
+ text-decoration:none;
+ color: #003366;
+ background: #ffcc66;
+ margin-bottom: 2pt;
+ border-top: 2px solid #ffff99;
+ border-left: 2px solid #ffff99;
+ border-right: 2px solid #cc9933;
+ border-bottom: 2px solid #cc9933;
+ font-family: Verdana, Arial, "Comic Sans MS";
+}
+.Banner {
+ width: 468;
+ font-size: 12pt;
+ text-align: center;
+ text-decoration:none;
+ color: #003366;
+ background: #ffcc66;
+ border-top: 4px solid #ffff99;
+ border-left: 4px solid #ffff99;
+ border-right: 4px solid #cc9933;
+ border-bottom: 4px solid #cc9933;
+ font-family: Verdana, Arial, "Comic Sans MS";
+}
+TD.Nova, Body.Nova {
+ background: #000000;
+ font-family: "Times New Roman";
+ font-weight: light;
+ color: #ffcc00;
+}
+Body.Nova A.Button {
+ background: gold;
+ color: #003366;
+}
+Body.Nova A.Banner {
+ background: transparent;
+ color: #003366;
+}
+Body.Nova A {
+ background: transparent;
+ text-decoration:none;
+ color: #ffd766;
+}
+Body.Nova H1, Body.Nova H2, Body.Nova H3, Body.Nova H4 {
+ background: transparent;
+ color: white;
+ margin-top: 4%;
+ text-align: center;
+ filter: Blur(Add=1, Direction=0, Strength=8);
+}
+Body.Nova Div.Abstract {
+ background: #000000;
+ color: #ffffff;
+ font-family: Times, Verdana;
+}
+Body.Nova A.Abstract {
+ background: transparent;
+ color: #ffeedd;
+}
+Body.Nova TH.LuT {
+ background: black;
+ color: #ffff99;
+}
+Body.Nova TD.LuT {
+ background: navy;
+ color: #ffff99;
+}
diff --git a/roms/u-boot/tools/bddb/brlog.php b/roms/u-boot/tools/bddb/brlog.php
new file mode 100644
index 00000000..fccfbd01
--- /dev/null
+++ b/roms/u-boot/tools/bddb/brlog.php
@@ -0,0 +1,109 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // list page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Browse Board Log");
+
+ $serno=intval($serno);
+ if ($serno == 0)
+ die("serial number not specified or invalid!");
+
+ function print_cell($str) {
+ if ($str == '')
+ $str = ' ';
+ echo "\t$str \n";
+ }
+?>
+
+
+serno / edit
+ethaddr
+date
+batch
+type
+rev
+location
+
+\n";
+ print_cell("$row[serno] ");
+ print_cell($row['ethaddr']);
+ print_cell($row['date']);
+ print_cell($row['batch']);
+ print_cell($row['type']);
+ print_cell($row['rev']);
+ print_cell($row['location']);
+ echo "\n";
+ }
+
+ mysql_free_result($r);
+?>
+
+
+
+$limit){
+ $preoffset=max(0,$offset-$limit);
+ $postoffset=$offset+$limit;
+ echo "\n\n";
+ printf("<%sa href=\"%s?submit=Log&serno=$serno&offset=%d\"> \n", $offset>0?"":"no", $PHP_SELF, $preoffset);
+ printf("<%sa href=\"%s?submit=Log&serno=$serno&offset=%d\"> \n", $postoffset<$lrow['n']?"":"no", $PHP_SELF, $postoffset);
+ echo " \n
\n";
+ }
+ mysql_free_result($lr);
+?>
+
+
+logno / edit
+date
+who
+details
+
+\n";
+ print_cell("$row[logno] ");
+ print_cell($row['date']);
+ print_cell($row['who']);
+ print_cell("" . urldecode($row['details']) . " ");
+ echo "\n";
+ }
+
+ mysql_free_result($r);
+?>
+
+
+
+
+
diff --git a/roms/u-boot/tools/bddb/browse.php b/roms/u-boot/tools/bddb/browse.php
new file mode 100644
index 00000000..675dfab7
--- /dev/null
+++ b/roms/u-boot/tools/bddb/browse.php
@@ -0,0 +1,147 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // list page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ $serno=isset($_REQUEST['serno'])?$_REQUEST['serno']:'';
+
+ $verbose=isset($_REQUEST['verbose'])?intval($_REQUEST['verbose']):0;
+
+ pg_head("$bddb_label - Browse database" . ($verbose?" (verbose)":""));
+?>
+
+$limit){
+ $preoffset=max(0,$offset-$limit);
+ $postoffset=$offset+$limit;
+ echo "\n\n";
+ printf("<%sa href=\"%s?submit=Browse&offset=%d&verbose=%d\"> \n", $offset>0?"":"no", $PHP_SELF, $preoffset, $verbose);
+ printf("<%sa href=\"%s?submit=Browse&offset=%d&verbose=%d\"> \n", $postoffset<$lrow['n']?"":"no", $PHP_SELF, $postoffset, $offset);
+ echo " \n
\n";
+ }
+
+ mysql_free_result($lr);
+ }
+?>
+
+
+
+serno / edit
+ethaddr
+date
+batch
+type
+rev
+location
+comments\n";
+ echo "sdram \n";
+ echo "flash \n";
+ echo "zbt \n";
+ echo "xlxtyp \n";
+ echo "xlxspd \n";
+ echo "xlxtmp \n";
+ echo "xlxgrd \n";
+ echo "cputyp \n";
+ echo "cpuspd \n";
+ echo "cpmspd \n";
+ echo "busspd \n";
+ echo "hstype \n";
+ echo "hschin \n";
+ echo "hschout \n";
+ }
+?>
+
+=$m[1] and serno<=$m[2])";
+ }
+ else
+ die("illegal serial number ($s)");
+ $pre = " or ";
+ }
+ }
+ $query .= " order by serno";
+ if ($serno == '')
+ $query .= " limit $offset,$limit";
+
+ $r = mysql_query($query);
+
+ function print_cell($str) {
+ if ($str == '')
+ $str = ' ';
+ echo "\t$str \n";
+ }
+
+ while($row=mysql_fetch_array($r)){
+ foreach ($columns as $key) {
+ if (!key_in_array($key, $row))
+ $row[$key] = '';
+ }
+
+ echo "\n";
+ print_cell("Log ");
+ print_cell("$row[serno] ");
+ print_cell($row['ethaddr']);
+ print_cell($row['date']);
+ print_cell($row['batch']);
+ print_cell($row['type']);
+ print_cell($row['rev']);
+ print_cell($row['location']);
+ if ($verbose) {
+ print_cell("\n" . urldecode($row['comments']) .
+ "\n\t ");
+ print_cell(gather_enum_multi_print("sdram", 4, $row));
+ print_cell(gather_enum_multi_print("flash", 4, $row));
+ print_cell(gather_enum_multi_print("zbt", 16, $row));
+ print_cell(gather_enum_multi_print("xlxtyp", 4, $row));
+ print_cell(gather_enum_multi_print("xlxspd", 4, $row));
+ print_cell(gather_enum_multi_print("xlxtmp", 4, $row));
+ print_cell(gather_enum_multi_print("xlxgrd", 4, $row));
+ print_cell($row['cputyp']);
+ print_cell($row['cpuspd']);
+ print_cell($row['cpmspd']);
+ print_cell($row['busspd']);
+ print_cell($row['hstype']);
+ print_cell($row['hschin']);
+ print_cell($row['hschout']);
+ }
+ echo " \n";
+ }
+?>
+
+
+
+
+ %s Listing\n", $PHP_SELF, $offset, $verbose?0:1, $serno!=''?"&serno=$serno":'', $verbose?"Terse":"Verbose");
+ ?>
+ Back to Start
+
+
+
diff --git a/roms/u-boot/tools/bddb/config.php b/roms/u-boot/tools/bddb/config.php
new file mode 100644
index 00000000..67257578
--- /dev/null
+++ b/roms/u-boot/tools/bddb/config.php
@@ -0,0 +1,16 @@
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // mysql database access info
+ $mysql_user="fred";
+ $mysql_pw="apassword";
+ $mysql_db="mydbname";
+
+ // where to put the eeprom config files
+ $bddb_cfgdir = '/tftpboot/bddb';
+
+ // what this database is called
+ $bddb_label = 'Hymod Board Database';
+?>
diff --git a/roms/u-boot/tools/bddb/create_tables.sql b/roms/u-boot/tools/bddb/create_tables.sql
new file mode 100644
index 00000000..a2a57886
--- /dev/null
+++ b/roms/u-boot/tools/bddb/create_tables.sql
@@ -0,0 +1,90 @@
+# phpMyAdmin MySQL-Dump
+# http://phpwizard.net/phpMyAdmin/
+#
+# Host: localhost Database : hymod_bddb
+
+# (C) Copyright 2001
+# Murray Jensen
+# CSIRO Manufacturing and Infrastructure Technology, Preston Lab
+
+# --------------------------------------------------------
+#
+# Table structure for table 'boards'
+#
+
+DROP TABLE IF EXISTS boards;
+CREATE TABLE boards (
+ serno int(10) unsigned zerofill NOT NULL auto_increment,
+ ethaddr char(17),
+ date date NOT NULL,
+ batch char(32),
+ type enum('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY') NOT NULL,
+ rev tinyint(3) unsigned zerofill NOT NULL,
+ location char(64),
+ comments text,
+ sdram0 enum('32M','64M','128M','256M','512M','1G','2G','4G'),
+ sdram1 enum('32M','64M','128M','256M','512M','1G','2G','4G'),
+ sdram2 enum('32M','64M','128M','256M','512M','1G','2G','4G'),
+ sdram3 enum('32M','64M','128M','256M','512M','1G','2G','4G'),
+ flash0 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'),
+ flash1 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'),
+ flash2 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'),
+ flash3 enum('4M','8M','16M','32M','64M','128M','256M','512M','1G'),
+ zbt0 enum('512K','1M','2M','4M','8M','16M'),
+ zbt1 enum('512K','1M','2M','4M','8M','16M'),
+ zbt2 enum('512K','1M','2M','4M','8M','16M'),
+ zbt3 enum('512K','1M','2M','4M','8M','16M'),
+ zbt4 enum('512K','1M','2M','4M','8M','16M'),
+ zbt5 enum('512K','1M','2M','4M','8M','16M'),
+ zbt6 enum('512K','1M','2M','4M','8M','16M'),
+ zbt7 enum('512K','1M','2M','4M','8M','16M'),
+ zbt8 enum('512K','1M','2M','4M','8M','16M'),
+ zbt9 enum('512K','1M','2M','4M','8M','16M'),
+ zbta enum('512K','1M','2M','4M','8M','16M'),
+ zbtb enum('512K','1M','2M','4M','8M','16M'),
+ zbtc enum('512K','1M','2M','4M','8M','16M'),
+ zbtd enum('512K','1M','2M','4M','8M','16M'),
+ zbte enum('512K','1M','2M','4M','8M','16M'),
+ zbtf enum('512K','1M','2M','4M','8M','16M'),
+ xlxtyp0 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'),
+ xlxtyp1 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'),
+ xlxtyp2 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'),
+ xlxtyp3 enum('XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140'),
+ xlxspd0 enum('6','7','8','4','5','9','10','11','12'),
+ xlxspd1 enum('6','7','8','4','5','9','10','11','12'),
+ xlxspd2 enum('6','7','8','4','5','9','10','11','12'),
+ xlxspd3 enum('6','7','8','4','5','9','10','11','12'),
+ xlxtmp0 enum('COM','IND'),
+ xlxtmp1 enum('COM','IND'),
+ xlxtmp2 enum('COM','IND'),
+ xlxtmp3 enum('COM','IND'),
+ xlxgrd0 enum('NORMAL','ENGSAMP'),
+ xlxgrd1 enum('NORMAL','ENGSAMP'),
+ xlxgrd2 enum('NORMAL','ENGSAMP'),
+ xlxgrd3 enum('NORMAL','ENGSAMP'),
+ cputyp enum('MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)','MPC8560'),
+ cpuspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ','300MHZ','333MHZ','366MHZ','400MHZ','433MHZ','466MHZ','500MHZ','533MHZ','566MHZ','600MHZ','633MHZ','666MHZ','700MHZ','733MHZ','766MHZ','800MHZ','833MHZ','866MHZ','900MHZ','933MHZ','966MHZ','1000MHZ','1033MHZ','1066MHZ','1100MHZ','1133MHZ','1166MHZ','1200MHZ','1233MHZ','1266MHZ','1300MHZ','1333MHZ'),
+ cpmspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ','300MHZ','333MHZ','366MHZ','400MHZ','433MHZ','466MHZ','500MHZ','533MHZ','566MHZ','600MHZ','633MHZ','666MHZ','700MHZ','733MHZ','766MHZ','800MHZ','833MHZ','866MHZ','900MHZ','933MHZ','966MHZ','1000MHZ','1033MHZ','1066MHZ','1100MHZ','1133MHZ','1166MHZ','1200MHZ','1233MHZ','1266MHZ','1300MHZ','1333MHZ'),
+ busspd enum('33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ','300MHZ','333MHZ','366MHZ','400MHZ','433MHZ','466MHZ','500MHZ','533MHZ','566MHZ','600MHZ','633MHZ','666MHZ','700MHZ','733MHZ','766MHZ','800MHZ','833MHZ','866MHZ','900MHZ','933MHZ','966MHZ','1000MHZ','1033MHZ','1066MHZ','1100MHZ','1133MHZ','1166MHZ','1200MHZ','1233MHZ','1266MHZ','1300MHZ','1333MHZ'),
+ hstype enum('AMCC-S2064A','Xilinx-Rockets'),
+ hschin enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'),
+ hschout enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'),
+ PRIMARY KEY (serno),
+ KEY serno (serno),
+ UNIQUE serno_2 (serno)
+);
+
+#
+# Table structure for table 'log'
+#
+
+DROP TABLE IF EXISTS log;
+CREATE TABLE log (
+ logno int(10) unsigned zerofill NOT NULL auto_increment,
+ serno int(10) unsigned zerofill NOT NULL,
+ date date NOT NULL,
+ details text NOT NULL,
+ PRIMARY KEY (logno),
+ KEY logno (logno, serno, date),
+ UNIQUE logno_2 (logno)
+);
diff --git a/roms/u-boot/tools/bddb/defs.php b/roms/u-boot/tools/bddb/defs.php
new file mode 100644
index 00000000..0b506028
--- /dev/null
+++ b/roms/u-boot/tools/bddb/defs.php
@@ -0,0 +1,710 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // contains mysql user id and password - keep secret
+ require("config.php");
+
+ if (isset($_REQUEST['logout'])) {
+ Header("status: 401 Unauthorized");
+ Header("HTTP/1.0 401 Unauthorized");
+ Header("WWW-authenticate: basic realm=\"$bddb_label\"");
+
+ echo "" .
+ "Access to '$bddb_label' Denied" .
+ " \n";
+ echo "" .
+ "You must be an Authorised User " .
+ "to access the '$bddb_label'" .
+ " \n \n";
+ exit;
+ }
+
+ // contents of the various enumerated types - if first item is
+ // empty ('') then the enum is allowed to be null (ie "not null"
+ // is not set on the column)
+
+ // all column names in the database table
+ $columns = array(
+ 'serno','ethaddr','date','batch',
+ 'type','rev','location','comments',
+ 'sdram0','sdram1','sdram2','sdram3',
+ 'flash0','flash1','flash2','flash3',
+ 'zbt0','zbt1','zbt2','zbt3','zbt4','zbt5','zbt6','zbt7',
+ 'zbt8','zbt9','zbta','zbtb','zbtc','zbtd','zbte','zbtf',
+ 'xlxtyp0','xlxtyp1','xlxtyp2','xlxtyp3',
+ 'xlxspd0','xlxspd1','xlxspd2','xlxspd3',
+ 'xlxtmp0','xlxtmp1','xlxtmp2','xlxtmp3',
+ 'xlxgrd0','xlxgrd1','xlxgrd2','xlxgrd3',
+ 'cputyp','cpuspd','cpmspd','busspd',
+ 'hstype','hschin','hschout'
+ );
+
+ // board type
+ $type_vals = array('IO','CLP','DSP','INPUT','ALT-INPUT','DISPLAY');
+
+ // Xilinx fpga types
+ $xlxtyp_vals = array('','XCV300E','XCV400E','XCV600E','XC2V2000','XC2V3000','XC2V4000','XC2V6000','XC2VP2','XC2VP4','XC2VP7','XC2VP20','XC2VP30','XC2VP50','XC4VFX20','XC4VFX40','XC4VFX60','XC4VFX100','XC4VFX140');
+
+ // Xilinx fpga speeds
+ $xlxspd_vals = array('','6','7','8','4','5','9','10','11','12');
+
+ // Xilinx fpga temperatures (commercial or industrial)
+ $xlxtmp_vals = array('','COM','IND');
+
+ // Xilinx fpga grades (normal or engineering sample)
+ $xlxgrd_vals = array('','NORMAL','ENGSAMP');
+
+ // CPU types
+ $cputyp_vals = array('','MPC8260(HIP3)','MPC8260A(HIP4)','MPC8280(HIP7)','MPC8560');
+
+ // CPU/BUS/CPM clock speeds
+ $clk_vals = array('','33MHZ','66MHZ','100MHZ','133MHZ','166MHZ','200MHZ','233MHZ','266MHZ','300MHZ','333MHZ','366MHZ','400MHZ','433MHZ','466MHZ','500MHZ','533MHZ','566MHZ','600MHZ','633MHZ','666MHZ','700MHZ','733MHZ','766MHZ','800MHZ','833MHZ','866MHZ','900MHZ','933MHZ','966MHZ','1000MHZ','1033MHZ','1066MHZ','1100MHZ','1133MHZ','1166MHZ','1200MHZ','1233MHZ','1266MHZ','1300MHZ','1333MHZ');
+
+ // sdram sizes (nbits array is for eeprom config file)
+ $sdram_vals = array('','32M','64M','128M','256M','512M','1G','2G','4G');
+ $sdram_nbits = array(0,25,26,27,28,29,30,31,32);
+
+ // flash sizes (nbits array is for eeprom config file)
+ $flash_vals = array('','4M','8M','16M','32M','64M','128M','256M','512M','1G');
+ $flash_nbits = array(0,22,23,24,25,26,27,28,29,30);
+
+ // zbt ram sizes (nbits array is for write into eeprom config file)
+ $zbt_vals = array('','512K','1M','2M','4M','8M','16M');
+ $zbt_nbits = array(0,19,20,21,22,23,24);
+
+ // high-speed serial attributes
+ $hstype_vals = array('','AMCC-S2064A','Xilinx-Rockets');
+ $hschin_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16');
+ $hschout_vals = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16');
+
+ // value filters - used when outputting html
+ function rev_filter($num) {
+ if ($num == 0)
+ return "001";
+ else
+ return sprintf("%03d", $num);
+ }
+
+ function text_filter($str) {
+ return urldecode($str);
+ }
+
+ mt_srand(time() | getmypid());
+
+ // set up MySQL connection
+ mysql_connect("", $mysql_user, $mysql_pw) || die("cannot connect");
+ mysql_select_db($mysql_db) || die("cannot select db");
+
+ // page header
+ function pg_head($title)
+ {
+ echo "\n\n";
+ echo " \n";
+ echo "$title \n";
+ echo "\n";
+ echo "\n";
+ echo "$title \n";
+ echo " \n";
+ }
+
+ // page footer
+ function pg_foot()
+ {
+ echo " \n";
+ echo "\n";
+ echo "Made with " .
+ "" .
+ "Kyber phpMyBuilder
\n";
+ echo "\n";
+ echo "\n";
+ }
+
+ // some support functions
+
+ if (!function_exists('array_search')) {
+
+ function array_search($needle, $haystack, $strict = false) {
+
+ if (is_array($haystack) && count($haystack)) {
+
+ $ntype = gettype($needle);
+
+ foreach ($haystack as $key => $value) {
+
+ if ($value == $needle && (!$strict ||
+ gettype($value) == $ntype))
+ return $key;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ if (!function_exists('in_array')) {
+
+ function in_array($needle, $haystack, $strict = false) {
+
+ if (is_array($haystack) && count($haystack)) {
+
+ $ntype = gettype($needle);
+
+ foreach ($haystack as $key => $value) {
+
+ if ($value == $needle && (!$strict ||
+ gettype($value) == $ntype))
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ function key_in_array($key, $array) {
+ return in_array($key, array_keys($array), true);
+ }
+
+ function enum_to_index($name, $vals) {
+ $index = array_search($GLOBALS[$name], $vals);
+ if ($vals[0] != '')
+ $index++;
+ return $index;
+ }
+
+ // fetch a value from an array - return empty string is not present
+ function get_key_value($key, $array) {
+ if (key_in_array($key, $array))
+ return $array[$key];
+ else
+ return '';
+ }
+
+ function fprintf() {
+ $n = func_num_args();
+ if ($n < 2)
+ return FALSE;
+ $a = func_get_args();
+ $fp = array_shift($a);
+ $x = "\$s = sprintf";
+ $sep = '(';
+ foreach ($a as $z) {
+ $x .= "$sep'$z'";
+ $sep = ',';
+ }
+ $x .= ');';
+ eval($x);
+ $l = strlen($s);
+ $r = fwrite($fp, $s, $l);
+ if ($r != $l)
+ return FALSE;
+ else
+ return TRUE;
+ }
+
+ // functions to display (print) a database table and its columns
+
+ function begin_table($ncols) {
+ global $table_ncols;
+ $table_ncols = $ncols;
+ echo "\n";
+ }
+
+ function begin_field($name, $span = 0) {
+ global $table_ncols;
+ echo "\n";
+ echo "\t$name \n";
+ if ($span <= 0)
+ $span = $table_ncols - 1;
+ if ($span > 1)
+ echo "\t\n";
+ else
+ echo "\t \n";
+ }
+
+ function cont_field($span = 1) {
+ echo "\t \n";
+ if ($span > 1)
+ echo "\t\n";
+ else
+ echo "\t \n";
+ }
+
+ function end_field() {
+ echo "\t \n";
+ echo " \n";
+ }
+
+ function end_table() {
+ echo "
\n";
+ }
+
+ function print_field($name, $array, $size = 0, $filt='') {
+
+ begin_field($name);
+
+ if (key_in_array($name, $array))
+ $value = $array[$name];
+ else
+ $value = '';
+
+ if ($filt != '')
+ $value = $filt($value);
+
+ echo "\t\t 0)
+ echo " size=$size maxlength=$size";
+ echo ">\n";
+
+ end_field();
+ }
+
+ function print_field_multiline($name, $array, $cols, $rows, $filt='') {
+
+ begin_field($name);
+
+ if (key_in_array($name, $array))
+ $value = $array[$name];
+ else
+ $value = '';
+
+ if ($filt != '')
+ $value = $filt($value);
+
+ echo "\t\t\n";
+
+ end_field();
+ }
+
+ // print a mysql ENUM as an html RADIO INPUT
+ function print_enum($name, $array, $vals, $def = -1) {
+
+ begin_field($name);
+
+ if (key_in_array($name, $array))
+ $chk = array_search($array[$name], $vals, FALSE);
+ else
+ $chk = $def;
+
+ $nval = count($vals);
+
+ for ($i = 0; $i < $nval; $i++) {
+
+ $val = $vals[$i];
+ if ($val == '')
+ $pval = "none";
+ else
+ $pval = "$val";
+
+ printf("\t\t $pval\n",
+ $i == $chk ? " checked" : "");
+ }
+
+ end_field();
+ }
+
+ // print a mysql ENUM as an html SELECT INPUT
+ function print_enum_select($name, $array, $vals, $def = -1) {
+
+ begin_field($name);
+
+ echo "\t\t\n";
+
+ if (key_in_array($name, $array))
+ $chk = array_search($array[$name], $vals, FALSE);
+ else
+ $chk = $def;
+
+ $nval = count($vals);
+
+ for ($i = 0; $i < $nval; $i++) {
+
+ $val = $vals[$i];
+ if ($val == '')
+ $pval = "none";
+ else
+ $pval = "$val";
+
+ printf("\t\t\t%s \n",
+ $val, $i == $chk ? " selected" : "", $pval);
+ }
+
+ echo "\t\t \n";
+
+ end_field();
+ }
+
+ // print a group of mysql ENUMs (e.g. name0,name1,...) as an html SELECT
+ function print_enum_multi($base, $array, $vals, $cnt, $defs, $grp = 0) {
+
+ global $table_ncols;
+
+ if ($grp <= 0)
+ $grp = $cnt;
+ $ncell = $cnt / $grp;
+ $span = ($table_ncols - 1) / $ncell;
+
+ begin_field($base, $span);
+
+ $nval = count($vals);
+
+ for ($i = 0; $i < $cnt; $i++) {
+
+ if ($i > 0 && ($i % $grp) == 0)
+ cont_field($span);
+
+ $name = sprintf("%s%x", $base, $i);
+
+ echo "\t\t\n";
+
+ if (key_in_array($name, $array))
+ $ai = array_search($array[$name], $vals, FALSE);
+ else {
+ if (key_in_array($i, $defs))
+ $ai = $defs[$i];
+ else
+ $ai = 0;
+ }
+
+ for ($j = 0; $j < $nval; $j++) {
+
+ $val = $vals[$j];
+ if ($val == '')
+ $pval = " ";
+ else
+ $pval = "$val";
+
+ printf("\t\t\t%s \n",
+ $val,
+ $j == $ai ? " selected" : "",
+ $pval);
+ }
+
+ echo "\t\t \n";
+ }
+
+ end_field();
+ }
+
+ // functions to handle the form input
+
+ // fetch all the parts of an "enum_multi" into a string suitable
+ // for a MySQL query
+ function gather_enum_multi_query($base, $cnt) {
+
+ $retval = '';
+
+ for ($i = 0; $i < $cnt; $i++) {
+
+ $name = sprintf("%s%x", $base, $i);
+
+ if (isset($_REQUEST[$name])) {
+ $retval .= sprintf(", %s='%s'",
+ $name, $_REQUEST[$name]);
+ }
+ }
+
+ return $retval;
+ }
+
+ // fetch all the parts of an "enum_multi" into a string suitable
+ // for a display e.g. in an html table cell
+ function gather_enum_multi_print($base, $cnt, $array) {
+
+ $retval = '';
+
+ for ($i = 0; $i < $cnt; $i++) {
+
+ $name = sprintf("%s%x", $base, $i);
+
+ if ($array[$name] != '') {
+ if ($retval != '')
+ $retval .= ',';
+ $retval .= $array[$name];
+ }
+ }
+
+ return $retval;
+ }
+
+ // fetch all the parts of an "enum_multi" into a string suitable
+ // for writing to the eeprom data file
+ function gather_enum_multi_write($base, $cnt, $vals, $xfrm = array()) {
+
+ $retval = '';
+
+ for ($i = 0; $i < $cnt; $i++) {
+
+ $name = sprintf("%s%x", $base, $i);
+
+ if ($GLOBALS[$name] != '') {
+ if ($retval != '')
+ $retval .= ',';
+ $index = enum_to_index($name, $vals);
+ if ($xfrm != array())
+ $retval .= $xfrm[$index];
+ else
+ $retval .= $index;
+ }
+ }
+
+ return $retval;
+ }
+
+ // count how many parts of an "enum_multi" are actually set
+ function count_enum_multi($base, $cnt) {
+
+ $retval = 0;
+
+ for ($i = 0; $i < $cnt; $i++) {
+
+ $name = sprintf("%s%x", $base, $i);
+
+ if (isset($_REQUEST[$name]))
+ $retval++;
+ }
+
+ return $retval;
+ }
+
+ // ethernet address functions
+
+ // generate a (possibly not unique) random vendor ethernet address
+ // (setting bit 6 in the ethernet address - motorola wise i.e. bit 0
+ // is the most significant bit - means it is not an assigned ethernet
+ // address - it is a "locally administered" address). Also, make sure
+ // it is NOT a multicast ethernet address (by setting bit 7 to 0).
+ // e.g. the first byte of all ethernet addresses generated here will
+ // have 2 in the bottom two bits (incidentally, these are the first
+ // two bits transmitted on the wire, since the octets in ethernet
+ // addresses are transmitted LSB first).
+
+ function gen_eth_addr($serno) {
+
+ $ethaddr_hgh = (mt_rand(0, 65535) & 0xfeff) | 0x0200;
+ $ethaddr_mid = mt_rand(0, 65535);
+ $ethaddr_low = mt_rand(0, 65535);
+
+ return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx",
+ $ethaddr_hgh >> 8, $ethaddr_hgh & 0xff,
+ $ethaddr_mid >> 8, $ethaddr_mid & 0xff,
+ $ethaddr_low >> 8, $ethaddr_low & 0xff);
+ }
+
+ // check that an ethernet address is valid
+ function eth_addr_is_valid($ethaddr) {
+
+ $ethbytes = split(':', $ethaddr);
+
+ if (count($ethbytes) != 6)
+ return FALSE;
+
+ for ($i = 0; $i < 6; $i++) {
+ $ethbyte = $ethbytes[$i];
+ if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte))
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ // write a simple eeprom configuration file
+ function write_eeprom_cfg_file() {
+
+ global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs;
+ global $date, $batch, $type_vals, $rev;
+ global $sdram_vals, $sdram_nbits;
+ global $flash_vals, $flash_nbits;
+ global $zbt_vals, $zbt_nbits;
+ global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals;
+ global $cputyp, $cputyp_vals, $clk_vals;
+ global $hstype, $hstype_vals, $hschin, $hschout;
+
+ $numerrs = 0;
+ $cfgerrs = array();
+
+ for ($i = 0; $i < $nsernos; $i++) {
+
+ $serno = sprintf("%010d", $sernos[$i]);
+
+ $wfp = @fopen($bddb_cfgdir . "/$serno.cfg", "w");
+ if (!$wfp) {
+ $cfgerrs[$i] = 'file create fail';
+ $numerrs++;
+ continue;
+ }
+ set_file_buffer($wfp, 0);
+
+ if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) {
+ $cfgerrs[$i] = 'cfg wr fail (serno)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+
+ if (!fprintf($wfp, "date=%s\n", $date)) {
+ $cfgerrs[$i] = 'cfg wr fail (date)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+
+ if ($batch != '') {
+ if (!fprintf($wfp, "batch=%s\n", $batch)) {
+ $cfgerrs[$i] = 'cfg wr fail (batch)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $typei = enum_to_index("type", $type_vals);
+ if (!fprintf($wfp, "type=%d\n", $typei)) {
+ $cfgerrs[$i] = 'cfg wr fail (type)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+
+ if (!fprintf($wfp, "rev=%d\n", $rev)) {
+ $cfgerrs[$i] = 'cfg wr fail (rev)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+
+ $s = gather_enum_multi_write("sdram", 4,
+ $sdram_vals, $sdram_nbits);
+ if ($s != '') {
+ $b = fprintf($wfp, "sdram=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (sdram)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("flash", 4,
+ $flash_vals, $flash_nbits);
+ if ($s != '') {
+ $b = fprintf($wfp, "flash=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (flash)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("zbt", 16,
+ $zbt_vals, $zbt_nbits);
+ if ($s != '') {
+ $b = fprintf($wfp, "zbt=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (zbt)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals);
+ if ($s != '') {
+ $b = fprintf($wfp, "xlxtyp=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (xlxtyp)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals);
+ if ($s != '') {
+ $b = fprintf($wfp, "xlxspd=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (xlxspd)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals);
+ if ($s != '') {
+ $b = fprintf($wfp, "xlxtmp=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (xlxtmp)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals);
+ if ($s != '') {
+ $b = fprintf($wfp, "xlxgrd=%s\n", $s);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (xlxgrd)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ if ($cputyp != '') {
+ $cputypi = enum_to_index("cputyp",$cputyp_vals);
+ $cpuspdi = enum_to_index("cpuspd", $clk_vals);
+ $busspdi = enum_to_index("busspd", $clk_vals);
+ $cpmspdi = enum_to_index("cpmspd", $clk_vals);
+ $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" .
+ "busspd=%d\ncpmspd=%d\n",
+ $cputypi, $cpuspdi, $busspdi, $cpmspdi);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (cputyp)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ if ($hstype != '') {
+ $hstypei = enum_to_index("hstype",$hstype_vals);
+ $b = fprintf($wfp, "hstype=%d\n" .
+ "hschin=%s\nhschout=%s\n",
+ $hstypei, $hschin, $hschout);
+ if (!$b) {
+ $cfgerrs[$i] = 'cfg wr fail (hstype)';
+ fclose($wfp);
+ $numerrs++;
+ continue;
+ }
+ }
+
+ if (!fclose($wfp)) {
+ $cfgerrs[$i] = 'file cls fail';
+ $numerrs++;
+ }
+ }
+
+ return $numerrs;
+ }
+?>
diff --git a/roms/u-boot/tools/bddb/dodelete.php b/roms/u-boot/tools/bddb/dodelete.php
new file mode 100644
index 00000000..4839e36e
--- /dev/null
+++ b/roms/u-boot/tools/bddb/dodelete.php
@@ -0,0 +1,65 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // dodelete page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Delete Board Results");
+
+ if (!isset($_REQUEST['serno']))
+ die("the board serial number was not specified");
+ $serno=intval($_REQUEST['serno']);
+
+ mysql_query("delete from boards where serno=$serno");
+
+ if(mysql_errno()) {
+ $errstr = mysql_error();
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $errstr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+ else {
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe board with serial number $serno was"
+ . " successfully deleted\n";
+ mysql_query("delete from log where serno=$serno");
+ if (mysql_errno()) {
+ $errstr = mysql_error();
+ echo "\t\t\t\n";
+ echo "\t\t\t\t\n";
+ echo "\t\t\t\t\tBut the following error occurred " .
+ "when deleting the log entries:\n";
+ echo "\t\t\t\t
\n";
+ echo "\t\t\t\t
\n";
+ printf("\t\t\t\t\t%s \n", $errstr);
+ echo "\t\t\t\t \n";
+ echo "\t\t\t\n";
+ }
+ echo "\t\t
\n";
+ echo "\t\n";
+ }
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/dodellog.php b/roms/u-boot/tools/bddb/dodellog.php
new file mode 100644
index 00000000..9dd78c11
--- /dev/null
+++ b/roms/u-boot/tools/bddb/dodellog.php
@@ -0,0 +1,57 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // dodelete page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Delete Log Entry Results");
+
+ if (!isset($_REQUEST['serno']))
+ die("the board serial number was not specified");
+ $serno=intval($_REQUEST['serno']);
+
+ if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == 0)
+ die("the log entry number not specified!");
+ $logno=$_REQUEST['logno'];
+
+ mysql_query("delete from log where serno=$serno and logno=$logno");
+
+ if(mysql_errno()) {
+ $errstr = mysql_error();
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $errstr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+ else {
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe log entry with log number $logno \n";
+ echo "\t\t\tand serial number $serno ";
+ echo "was successfully deleted\n";
+ echo "\t\t
\n";
+ echo "\t \n";
+ }
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/doedit.php b/roms/u-boot/tools/bddb/doedit.php
new file mode 100644
index 00000000..13fbb694
--- /dev/null
+++ b/roms/u-boot/tools/bddb/doedit.php
@@ -0,0 +1,186 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // doedit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Edit Board Results");
+
+ if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '')
+ die("the board serial number was not specified");
+ $serno=intval($_REQUEST['serno']);
+
+ $query="update boards set";
+
+ if (isset($_REQUEST['ethaddr'])) {
+ $ethaddr=$_REQUEST['ethaddr'];
+ if (!eth_addr_is_valid($ethaddr))
+ die("ethaddr is invalid ('$ethaddr')");
+ $query.=" ethaddr='$ethaddr',";
+ }
+
+ if (isset($_REQUEST['date'])) {
+ $date=$_REQUEST['date'];
+ list($y, $m, $d) = split("-", $date);
+ if (!checkdate($m, $d, $y) || $y < 1999)
+ die("date is invalid (input '$date', " .
+ "yyyy-mm-dd '$y-$m-$d')");
+ $query.=" date='$date'";
+ }
+
+ if (isset($_REQUEST['batch'])) {
+ $batch=$_REQUEST['batch'];
+ if (strlen($batch) > 32)
+ die("batch field too long (>32)");
+ $query.=", batch='$batch'";
+ }
+
+ if (isset($_REQUEST['type'])) {
+ $type=$_REQUEST['type'];
+ if (!in_array($type, $type_vals))
+ die("Invalid type ($type) specified");
+ $query.=", type='$type'";
+ }
+
+ if (isset($_REQUEST['rev'])) {
+ $rev=$_REQUEST['rev'];
+ if (($rev = intval($rev)) <= 0 || $rev > 255)
+ die("Revision number is invalid ($rev)");
+ $query.=sprintf(", rev=%d", $rev);
+ }
+
+ if (isset($_REQUEST['location'])) {
+ $location=$_REQUEST['location'];
+ if (strlen($location) > 64)
+ die("location field too long (>64)");
+ $query.=", location='$location'";
+ }
+
+ if (isset($_REQUEST['comments']))
+ $comments=$_REQUEST['comments'];
+ $query.=", comments='" . rawurlencode($comments) . "'";
+
+ $query.=gather_enum_multi_query("sdram", 4);
+
+ $query.=gather_enum_multi_query("flash", 4);
+
+ $query.=gather_enum_multi_query("zbt", 16);
+
+ $query.=gather_enum_multi_query("xlxtyp", 4);
+ $nxlx = count_enum_multi("xlxtyp", 4);
+
+ $query.=gather_enum_multi_query("xlxspd", 4);
+ if (count_enum_multi("xlxspd", 4) != $nxlx)
+ die("number of xilinx speeds not same as number of types");
+
+ $query.=gather_enum_multi_query("xlxtmp", 4);
+ if (count_enum_multi("xlxtmp", 4) != $nxlx)
+ die("number of xilinx temps. not same as number of types");
+
+ $query.=gather_enum_multi_query("xlxgrd", 4);
+ if (count_enum_multi("xlxgrd", 4) != $nxlx)
+ die("number of xilinx grades not same as number of types");
+
+ if (isset($_REQUEST['cputyp'])) {
+ $cputyp=$_REQUEST['cputyp'];
+ $query.=", cputyp='$cputyp'";
+ if (!isset($_REQUEST['cpuspd']) || $_REQUEST['cpuspd'] == '')
+ die("must specify cpu speed if cpu type is defined");
+ $cpuspd=$_REQUEST['cpuspd'];
+ $query.=", cpuspd='$cpuspd'";
+ if (!isset($_REQUEST['cpmspd']) || $_REQUEST['cpmspd'] == '')
+ die("must specify cpm speed if cpu type is defined");
+ $cpmspd=$_REQUEST['cpmspd'];
+ $query.=", cpmspd='$cpmspd'";
+ if (!isset($_REQUEST['busspd']) || $_REQUEST['busspd'] == '')
+ die("must specify bus speed if cpu type is defined");
+ $busspd=$_REQUEST['busspd'];
+ $query.=", busspd='$busspd'";
+ }
+ else {
+ if (isset($_REQUEST['cpuspd']))
+ die("can't specify cpu speed if there is no cpu");
+ if (isset($_REQUEST['cpmspd']))
+ die("can't specify cpm speed if there is no cpu");
+ if (isset($_REQUEST['busspd']))
+ die("can't specify bus speed if there is no cpu");
+ }
+
+ if (isset($_REQUEST['hschin'])) {
+ $hschin=$_REQUEST['hschin'];
+ if (($hschin = intval($hschin)) < 0 || $hschin > 4)
+ die("Invalid number of hs input chans ($hschin)");
+ }
+ else
+ $hschin = 0;
+ if (isset($_REQUEST['hschout'])) {
+ $hschout=$_REQUEST['hschout'];
+ if (($hschout = intval($hschout)) < 0 || $hschout > 4)
+ die("Invalid number of hs output chans ($hschout)");
+ }
+ else
+ $hschout = 0;
+ if (isset($_REQUEST['hstype'])) {
+ $hstype=$_REQUEST['hstype'];
+ $query.=", hstype='$hstype'";
+ }
+ else {
+ if ($_REQUEST['hschin'] != 0)
+ die("number of high-speed input channels must be zero"
+ . " if high-speed chip is not present");
+ if ($_REQUEST['hschout'] != 0)
+ die("number of high-speed output channels must be zero"
+ . " if high-speed chip is not present");
+ }
+ $query.=", hschin='$hschin'";
+ $query.=", hschout='$hschout'";
+
+ $query.=" where serno=$serno";
+
+ mysql_query($query);
+ if(mysql_errno()) {
+ $errstr = mysql_error();
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $errstr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+ else {
+ $sernos = array($serno);
+ $nsernos = 1;
+
+ write_eeprom_cfg_file();
+
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe board with serial number $serno was"
+ . " successfully updated";
+ if ($numerrs > 0) {
+ $errstr = $cfgerrs[0];
+ echo " \n\t\t\t";
+ echo "(but the cfg file update failed: $errstr)";
+ }
+ echo "\n";
+ echo "\t\t
\n";
+ echo "\t \n";
+ }
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/doedlog.php b/roms/u-boot/tools/bddb/doedlog.php
new file mode 100644
index 00000000..7009aa7d
--- /dev/null
+++ b/roms/u-boot/tools/bddb/doedlog.php
@@ -0,0 +1,76 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // doedit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Edit Log Entry Results");
+
+ if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '')
+ die("the board serial number was not specified");
+ $serno=intval($_REQUEST['serno']);
+
+ if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == '')
+ die("log number not specified!");
+ $logno=intval($_REQUEST['logno']);
+
+ $query="update log set";
+
+ if (isset($_REQUEST['date'])) {
+ $date=$_REQUEST['date'];
+ list($y, $m, $d) = split("-", $date);
+ if (!checkdate($m, $d, $y) || $y < 1999)
+ die("date is invalid (input '$date', " .
+ "yyyy-mm-dd '$y-$m-$d')");
+ $query.=" date='$date'";
+ }
+
+ if (isset($_REQUEST['who'])) {
+ $who=$_REQUEST['who'];
+ $query.=", who='" . $who . "'";
+ }
+
+ if (isset($_REQUEST['details'])) {
+ $details=$_REQUEST['details'];
+ $query.=", details='" . rawurlencode($details) . "'";
+ }
+
+ $query.=" where serno=$serno and logno=$logno";
+
+ mysql_query($query);
+ if(mysql_errno()) {
+ $errstr = mysql_error();
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $errstr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+ else {
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe log entry with log number $logno and\n";
+ echo "\t\t\tserial number $serno ";
+ echo "was successfully updated\n";
+ echo "\t\t
\n";
+ echo "\t \n";
+ }
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/donew.php b/roms/u-boot/tools/bddb/donew.php
new file mode 100644
index 00000000..39b2c78f
--- /dev/null
+++ b/roms/u-boot/tools/bddb/donew.php
@@ -0,0 +1,230 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // doedit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Board Registration Results");
+
+ if (isset($_REQUEST['serno'])) {
+ $serno=$_REQUEST['serno'];
+ die("serial number must not be set ($serno) when Creating!");
+ }
+
+ $query="update boards set";
+
+ list($y, $m, $d) = split("-", $date);
+ if (!checkdate($m, $d, $y) || $y < 1999)
+ die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')");
+ $query.=" date='$date'";
+
+ if ($batch != '') {
+ if (strlen($batch) > 32)
+ die("batch field too long (>32)");
+ $query.=", batch='$batch'";
+ }
+
+ if (!in_array($type, $type_vals))
+ die("Invalid type ($type) specified");
+ $query.=", type='$type'";
+
+ if (($rev = intval($rev)) <= 0 || $rev > 255)
+ die("Revision number is invalid ($rev)");
+ $query.=sprintf(", rev=%d", $rev);
+
+ $query.=gather_enum_multi_query("sdram", 4);
+
+ $query.=gather_enum_multi_query("flash", 4);
+
+ $query.=gather_enum_multi_query("zbt", 16);
+
+ $query.=gather_enum_multi_query("xlxtyp", 4);
+ $nxlx = count_enum_multi("xlxtyp", 4);
+
+ $query.=gather_enum_multi_query("xlxspd", 4);
+ if (count_enum_multi("xlxspd", 4) != $nxlx)
+ die("number of xilinx speeds not same as number of types");
+
+ $query.=gather_enum_multi_query("xlxtmp", 4);
+ if (count_enum_multi("xlxtmp", 4) != $nxlx)
+ die("number of xilinx temps. not same as number of types");
+
+ $query.=gather_enum_multi_query("xlxgrd", 4);
+ if (count_enum_multi("xlxgrd", 4) != $nxlx)
+ die("number of xilinx grades not same as number of types");
+
+ if ($cputyp == '') {
+ if ($cpuspd != '')
+ die("can't specify cpu speed if there is no cpu");
+ if ($cpmspd != '')
+ die("can't specify cpm speed if there is no cpu");
+ if ($busspd != '')
+ die("can't specify bus speed if there is no cpu");
+ }
+ else {
+ $query.=", cputyp='$cputyp'";
+ if ($cpuspd == '')
+ die("must specify cpu speed if cpu type is defined");
+ $query.=", cpuspd='$cpuspd'";
+ if ($cpmspd == '')
+ die("must specify cpm speed if cpu type is defined");
+ $query.=", cpmspd='$cpmspd'";
+ if ($busspd == '')
+ die("must specify bus speed if cpu type is defined");
+ $query.=", busspd='$busspd'";
+ }
+
+ if (($hschin = intval($hschin)) < 0 || $hschin > 4)
+ die("Invalid number of hs input chans ($hschin)");
+ if (($hschout = intval($hschout)) < 0 || $hschout > 4)
+ die("Invalid number of hs output chans ($hschout)");
+ if ($hstype == '') {
+ if ($hschin != 0)
+ die("number of high-speed input channels must be zero"
+ . " if high-speed chip is not present");
+ if ($hschout != 0)
+ die("number of high-speed output channels must be zero"
+ . " if high-speed chip is not present");
+ }
+ else
+ $query.=", hstype='$hstype'";
+ $query.=", hschin='$hschin'";
+ $query.=", hschout='$hschout'";
+
+ // echo "final query = '$query' \n";
+
+ $quant = intval($quant);
+ if ($quant <= 0) $quant = 1;
+
+ $sernos = array();
+ if ($geneths)
+ $ethaddrs = array();
+
+ $sqlerr = '';
+
+ while ($quant-- > 0) {
+
+ mysql_query("insert into boards (serno) values (null)");
+ if (mysql_errno()) {
+ $sqlerr = mysql_error();
+ break;
+ }
+
+ $serno = mysql_insert_id();
+ if (!$serno) {
+ $sqlerr = "couldn't allocate new serial number";
+ break;
+ }
+
+ mysql_query($query . " where serno=$serno");
+ if (mysql_errno()) {
+ $sqlerr = mysql_error();
+ break;
+ }
+
+ array_push($sernos, $serno);
+
+ if ($geneths) {
+
+ $ethaddr = gen_eth_addr($serno);
+
+ mysql_query("update boards set ethaddr='$ethaddr'" .
+ " where serno=$serno");
+ if (mysql_errno()) {
+ $sqlerr = mysql_error();
+
+ array_push($ethaddrs,
+ "" .
+ "db save fail" .
+ " ");
+ break;
+ }
+
+ array_push($ethaddrs, $ethaddr);
+ }
+ }
+
+ $nsernos = count($sernos);
+
+ if ($nsernos > 0) {
+
+ write_eeprom_cfg_file();
+
+ echo "\n";
+ echo "\t\n";
+ echo "\t\tThe following board serial numbers were"
+ . " successfully allocated";
+ if ($numerrs > 0)
+ echo " (but with $numerrs cfg file error" .
+ ($numerrs > 1 ? "s" : "") . ")";
+ echo ":\n";
+ echo "\t
\n";
+
+ echo " \n";
+
+ echo "\n";
+ echo "\n";
+ echo "\tSerial Number \n";
+ if ($numerrs > 0)
+ echo "\tCfg File Errs \n";
+ if ($geneths)
+ echo "\tEthernet Address \n";
+ echo " \n";
+
+ for ($i = 0; $i < $nsernos; $i++) {
+
+ $serno = sprintf("%010d", $sernos[$i]);
+
+ echo "\n";
+
+ echo "\t" .
+ "$serno \n";
+
+ if ($numerrs > 0) {
+ if (($errstr = $cfgerrs[$i]) == '')
+ $errstr = ' ';
+ echo "\t" .
+ "" .
+ $errstr .
+ " \n";
+ }
+
+ if ($geneths) {
+ echo "\t" .
+ "" .
+ $ethaddrs[$i] .
+ " \n";
+ }
+
+ echo " \n";
+ }
+
+ echo "
\n";
+ }
+
+ if ($sqlerr != '') {
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following SQL error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $sqlerr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/donewlog.php b/roms/u-boot/tools/bddb/donewlog.php
new file mode 100644
index 00000000..7635d299
--- /dev/null
+++ b/roms/u-boot/tools/bddb/donewlog.php
@@ -0,0 +1,86 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // doedit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Add Log Entry Results");
+
+ if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '')
+ die("serial number not specified!");
+ $serno=intval($_REQUEST['serno']);
+
+ if (isset($_REQUEST['logno'])) {
+ $logno=$_REQUEST['logno'];
+ die("log number must not be set ($logno) when Creating!");
+ }
+
+ $query="update log set serno=$serno";
+
+ list($y, $m, $d) = split("-", $date);
+ if (!checkdate($m, $d, $y) || $y < 1999)
+ die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')");
+ $query.=", date='$date'";
+
+ if (isset($_REQUEST['who'])) {
+ $who=$_REQUEST['who'];
+ $query.=", who='" . $who . "'";
+ }
+
+ if (isset($_REQUEST['details'])) {
+ $details=$_REQUEST['details'];
+ $query.=", details='" . rawurlencode($details) . "'";
+ }
+
+ // echo "final query = '$query' \n";
+
+ $sqlerr = '';
+
+ mysql_query("insert into log (logno) values (null)");
+ if (mysql_errno())
+ $sqlerr = mysql_error();
+ else {
+ $logno = mysql_insert_id();
+ if (!$logno)
+ $sqlerr = "couldn't allocate new serial number";
+ else {
+ mysql_query($query . " where logno=$logno");
+ if (mysql_errno())
+ $sqlerr = mysql_error();
+ }
+ }
+
+ if ($sqlerr == '') {
+ echo "\n";
+ echo "\t\n";
+ echo "\t\tA log entry with log number '$logno' was " .
+ "added to the board with serial number '$serno'\n";
+ echo "\t
\n";
+ echo " \n";
+ }
+ else {
+ echo "\t\n";
+ echo "\t\t\n";
+ echo "\t\t\tThe following SQL error was encountered:\n";
+ echo "\t\t
\n";
+ echo "\t\t \n";
+ printf("\t\t\t%s \n", $sqlerr);
+ echo "\t\t \n";
+ echo "\t\n";
+ }
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/edit.php b/roms/u-boot/tools/bddb/edit.php
new file mode 100644
index 00000000..dd8c26c5
--- /dev/null
+++ b/roms/u-boot/tools/bddb/edit.php
@@ -0,0 +1,131 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // edit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Edit Board Registration");
+
+ if ($serno == 0)
+ die("serial number not specified or invalid!");
+
+ $pserno = sprintf("%010d", $serno);
+
+ echo "";
+ echo "Board Serial Number: $pserno";
+ echo " \n";
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/edlog.php b/roms/u-boot/tools/bddb/edlog.php
new file mode 100644
index 00000000..8befd35b
--- /dev/null
+++ b/roms/u-boot/tools/bddb/edlog.php
@@ -0,0 +1,86 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // edit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - Edit Board Log Entry");
+
+ if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '')
+ die("serial number not specified!");
+ $serno=intval($_REQUEST['serno']);
+
+ if (!isset($_REQUEST['logno']) || $_REQUEST['logno'] == '')
+ die("log number not specified!");
+ $logno=intval($_REQUEST['logno']);
+
+ $pserno = sprintf("%010d", $serno);
+ $plogno = sprintf("%010d", $logno);
+
+ echo "";
+ echo "Board Serial Number: $pserno, Log Number: $plogno";
+ echo " \n";
+
+?>
+
+
+
diff --git a/roms/u-boot/tools/bddb/execute.php b/roms/u-boot/tools/bddb/execute.php
new file mode 100644
index 00000000..0b62882d
--- /dev/null
+++ b/roms/u-boot/tools/bddb/execute.php
@@ -0,0 +1,33 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ $serno=isset($_REQUEST['serno'])?$_REQUEST['serno']:'';
+
+ $submit=isset($_REQUEST['submit'])?$_REQUEST['submit']:"[NOT SET]";
+
+ switch ($submit) {
+
+ case "New":
+ require("new.php");
+ break;
+
+ case "Edit":
+ require("edit.php");
+ break;
+
+ case "Browse":
+ require("browse.php");
+ break;
+
+ case "Log":
+ require("brlog.php");
+ break;
+
+ default:
+ require("badsubmit.php");
+ break;
+ }
+?>
diff --git a/roms/u-boot/tools/bddb/index.php b/roms/u-boot/tools/bddb/index.php
new file mode 100644
index 00000000..842aed55
--- /dev/null
+++ b/roms/u-boot/tools/bddb/index.php
@@ -0,0 +1,38 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ require("defs.php");
+ pg_head("$bddb_label");
+?>
+
+
+
+
diff --git a/roms/u-boot/tools/bddb/new.php b/roms/u-boot/tools/bddb/new.php
new file mode 100644
index 00000000..30323ff8
--- /dev/null
+++ b/roms/u-boot/tools/bddb/new.php
@@ -0,0 +1,120 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // edit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - New Board Registration");
+?>
+
+
diff --git a/roms/u-boot/tools/bddb/newlog.php b/roms/u-boot/tools/bddb/newlog.php
new file mode 100644
index 00000000..609bb855
--- /dev/null
+++ b/roms/u-boot/tools/bddb/newlog.php
@@ -0,0 +1,54 @@
+ ?>
+
+ // CSIRO Manufacturing Science and Technology, Preston Lab
+
+ // edit page (hymod_bddb / boards)
+
+ require("defs.php");
+
+ pg_head("$bddb_label - New Log Entry");
+
+ if (!isset($_REQUEST['serno']) || $_REQUEST['serno'] == '')
+ die("serial number not specified or invalid!");
+ $serno=intval($_REQUEST['serno']);
+
+ if (isset($_REQUEST['logno'])) {
+ $logno=$_REQUEST['logno'];
+ die("log number must not be specified when adding! ($logno)");
+ }
+?>
+
+
diff --git a/roms/u-boot/tools/bin2header.c b/roms/u-boot/tools/bin2header.c
new file mode 100644
index 00000000..27a5b6aa
--- /dev/null
+++ b/roms/u-boot/tools/bin2header.c
@@ -0,0 +1,40 @@
+/* bin2header.c - program to convert binary file into a C structure
+ * definition to be included in a header file.
+ *
+ * (C) Copyright 2008 by Harald Welte
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "%s needs one argument: the structure name\n",
+ argv[0]);
+ exit(1);
+ }
+
+ printf("/* bin2header output - automatically generated */\n");
+ printf("unsigned char %s[] = {\n", argv[1]);
+
+ while (1) {
+ int i, nread;
+ unsigned char buf[10];
+ nread = read(0, buf, sizeof(buf));
+ if (nread <= 0)
+ break;
+
+ printf("\t");
+ for (i = 0; i < nread - 1; i++)
+ printf("0x%02x, ", buf[i]);
+
+ printf("0x%02x,\n", buf[nread-1]);
+ }
+
+ printf("};\n");
+
+ exit(0);
+}
diff --git a/roms/u-boot/tools/bmp_logo.c b/roms/u-boot/tools/bmp_logo.c
new file mode 100644
index 00000000..2247adcc
--- /dev/null
+++ b/roms/u-boot/tools/bmp_logo.c
@@ -0,0 +1,203 @@
+#include "compiler.h"
+
+enum {
+ MODE_GEN_INFO,
+ MODE_GEN_DATA
+};
+
+typedef struct bitmap_s { /* bitmap description */
+ uint16_t width;
+ uint16_t height;
+ uint8_t palette[256*3];
+ uint8_t *data;
+} bitmap_t;
+
+#define DEFAULT_CMAP_SIZE 16 /* size of default color map */
+
+void usage(const char *prog)
+{
+ fprintf(stderr, "Usage: %s [--gen-info|--gen-data] file\n", prog);
+}
+
+/*
+ * Neutralize little endians.
+ */
+uint16_t le_short(uint16_t x)
+{
+ uint16_t val;
+ uint8_t *p = (uint8_t *)(&x);
+
+ val = (*p++ & 0xff) << 0;
+ val |= (*p & 0xff) << 8;
+
+ return val;
+}
+
+void skip_bytes (FILE *fp, int n)
+{
+ while (n-- > 0)
+ fgetc (fp);
+}
+
+__attribute__ ((__noreturn__))
+int error (char * msg, FILE *fp)
+{
+ fprintf (stderr, "ERROR: %s\n", msg);
+
+ fclose (fp);
+
+ exit (EXIT_FAILURE);
+}
+
+void gen_info(bitmap_t *b, uint16_t n_colors)
+{
+ printf("/*\n"
+ " * Automatically generated by \"tools/bmp_logo\"\n"
+ " *\n"
+ " * DO NOT EDIT\n"
+ " *\n"
+ " */\n\n\n"
+ "#ifndef __BMP_LOGO_H__\n"
+ "#define __BMP_LOGO_H__\n\n"
+ "#define BMP_LOGO_WIDTH\t\t%d\n"
+ "#define BMP_LOGO_HEIGHT\t\t%d\n"
+ "#define BMP_LOGO_COLORS\t\t%d\n"
+ "#define BMP_LOGO_OFFSET\t\t%d\n\n"
+ "extern unsigned short bmp_logo_palette[];\n"
+ "extern unsigned char bmp_logo_bitmap[];\n\n"
+ "#endif /* __BMP_LOGO_H__ */\n",
+ b->width, b->height, n_colors,
+ DEFAULT_CMAP_SIZE);
+}
+
+int main (int argc, char *argv[])
+{
+ int mode, i, x;
+ FILE *fp;
+ bitmap_t bmp;
+ bitmap_t *b = &bmp;
+ uint16_t data_offset, n_colors;
+
+ if (argc < 3) {
+ usage(argv[0]);
+ exit (EXIT_FAILURE);
+ }
+
+ if (!strcmp(argv[1], "--gen-info"))
+ mode = MODE_GEN_INFO;
+ else if (!strcmp(argv[1], "--gen-data"))
+ mode = MODE_GEN_DATA;
+ else {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ fp = fopen(argv[2], "rb");
+ if (!fp) {
+ perror(argv[2]);
+ exit (EXIT_FAILURE);
+ }
+
+ if (fgetc (fp) != 'B' || fgetc (fp) != 'M')
+ error ("Input file is not a bitmap", fp);
+
+ /*
+ * read width and height of the image, and the number of colors used;
+ * ignore the rest
+ */
+ skip_bytes (fp, 8);
+ if (fread (&data_offset, sizeof (uint16_t), 1, fp) != 1)
+ error ("Couldn't read bitmap data offset", fp);
+ skip_bytes (fp, 6);
+ if (fread (&b->width, sizeof (uint16_t), 1, fp) != 1)
+ error ("Couldn't read bitmap width", fp);
+ skip_bytes (fp, 2);
+ if (fread (&b->height, sizeof (uint16_t), 1, fp) != 1)
+ error ("Couldn't read bitmap height", fp);
+ skip_bytes (fp, 22);
+ if (fread (&n_colors, sizeof (uint16_t), 1, fp) != 1)
+ error ("Couldn't read bitmap colors", fp);
+ skip_bytes (fp, 6);
+
+ /*
+ * Repair endianess.
+ */
+ data_offset = le_short(data_offset);
+ b->width = le_short(b->width);
+ b->height = le_short(b->height);
+ n_colors = le_short(n_colors);
+
+ /* assume we are working with an 8-bit file */
+ if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
+ /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
+ n_colors = 256 - DEFAULT_CMAP_SIZE;
+ }
+
+ if (mode == MODE_GEN_INFO) {
+ gen_info(b, n_colors);
+ goto out;
+ }
+
+ printf("/*\n"
+ " * Automatically generated by \"tools/bmp_logo\"\n"
+ " *\n"
+ " * DO NOT EDIT\n"
+ " *\n"
+ " */\n\n\n"
+ "#ifndef __BMP_LOGO_DATA_H__\n"
+ "#define __BMP_LOGO_DATA_H__\n\n");
+
+ /* allocate memory */
+ if ((b->data = (uint8_t *)malloc(b->width * b->height)) == NULL)
+ error ("Error allocating memory for file", fp);
+
+ /* read and print the palette information */
+ printf("unsigned short bmp_logo_palette[] = {\n");
+
+ for (i=0; ipalette[(int)(i*3+2)] = fgetc(fp);
+ b->palette[(int)(i*3+1)] = fgetc(fp);
+ b->palette[(int)(i*3+0)] = fgetc(fp);
+ x=fgetc(fp);
+
+ printf ("%s0x0%X%X%X,%s",
+ ((i%8) == 0) ? "\t" : " ",
+ (b->palette[(int)(i*3+0)] >> 4) & 0x0F,
+ (b->palette[(int)(i*3+1)] >> 4) & 0x0F,
+ (b->palette[(int)(i*3+2)] >> 4) & 0x0F,
+ ((i%8) == 7) ? "\n" : ""
+ );
+ }
+
+ /* seek to offset indicated by file header */
+ fseek(fp, (long)data_offset, SEEK_SET);
+
+ /* read the bitmap; leave room for default color map */
+ printf ("\n");
+ printf ("};\n");
+ printf ("\n");
+ printf("unsigned char bmp_logo_bitmap[] = {\n");
+ for (i=(b->height-1)*b->width; i>=0; i-=b->width) {
+ for (x = 0; x < b->width; x++) {
+ b->data[i + x] = (uint8_t) fgetc(fp)
+ + DEFAULT_CMAP_SIZE;
+ }
+ }
+
+ for (i=0; i<(b->height*b->width); ++i) {
+ if ((i%8) == 0)
+ putchar ('\t');
+ printf ("0x%02X,%c",
+ b->data[i],
+ ((i%8) == 7) ? '\n' : ' '
+ );
+ }
+ printf ("\n"
+ "};\n\n"
+ "#endif /* __BMP_LOGO_DATA_H__ */\n"
+ );
+
+out:
+ fclose(fp);
+ return 0;
+}
diff --git a/roms/u-boot/tools/buildman/.gitignore b/roms/u-boot/tools/buildman/.gitignore
new file mode 100644
index 00000000..0d20b648
--- /dev/null
+++ b/roms/u-boot/tools/buildman/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/roms/u-boot/tools/buildman/README b/roms/u-boot/tools/buildman/README
new file mode 100644
index 00000000..c30c1d41
--- /dev/null
+++ b/roms/u-boot/tools/buildman/README
@@ -0,0 +1,690 @@
+# Copyright (c) 2013 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+What is this?
+=============
+
+This tool handles building U-Boot to check that you have not broken it
+with your patch series. It can build each individual commit and report
+which boards fail on which commits, and which errors come up. It aims
+to make full use of multi-processor machines.
+
+A key feature of buildman is its output summary, which allows warnings,
+errors or image size increases in a particular commit or board to be
+quickly identified and the offending commit pinpointed. This can be a big
+help for anyone working with >10 patches at a time.
+
+
+Caveats
+=======
+
+Buildman is still in its infancy. It is already a very useful tool, but
+expect to find problems and send patches.
+
+Buildman can be stopped and restarted, in which case it will continue
+where it left off. This should happen cleanly and without side-effects.
+If not, it is a bug, for which a patch would be welcome.
+
+Buildman gets so tied up in its work that it can ignore the outside world.
+You may need to press Ctrl-C several times to quit it. Also it will print
+out various exceptions when stopped.
+
+
+Theory of Operation
+===================
+
+(please read this section in full twice or you will be perpetually confused)
+
+Buildman is a builder. It is not make, although it runs make. It does not
+produce any useful output on the terminal while building, except for
+progress information. All the output (errors, warnings and binaries if you
+are ask for them) is stored in output directories, which you can look at
+while the build is progressing, or when it is finished.
+
+Buildman produces a concise summary of which boards succeeded and failed.
+It shows which commit introduced which board failure using a simple
+red/green colour coding. Full error information can be requested, in which
+case it is de-duped and displayed against the commit that introduced the
+error. An example workflow is below.
+
+Buildman stores image size information and can report changes in image size
+from commit to commit. An example of this is below.
+
+Buildman starts multiple threads, and each thread builds for one board at
+a time. A thread starts at the first commit, configures the source for your
+board and builds it. Then it checks out the next commit and does an
+incremental build. Eventually the thread reaches the last commit and stops.
+If errors or warnings are found along the way, the thread will reconfigure
+after every commit, and your build will be very slow. This is because a
+file that produces just a warning would not normally be rebuilt in an
+incremental build.
+
+Buildman works in an entirely separate place from your U-Boot repository.
+It creates a separate working directory for each thread, and puts the
+output files in the working directory, organised by commit name and board
+name, in a two-level hierarchy.
+
+Buildman is invoked in your U-Boot directory, the one with the .git
+directory. It clones this repository into a copy for each thread, and the
+threads do not affect the state of your git repository. Any checkouts done
+by the thread affect only the working directory for that thread.
+
+Buildman automatically selects the correct toolchain for each board. You
+must supply suitable toolchains, but buildman takes care of selecting the
+right one.
+
+Buildman always builds a branch, and always builds the upstream commit as
+well, for comparison. It cannot build individual commits at present, unless
+(maybe) you point it at an empty branch. Put all your commits in a branch,
+set the branch's upstream to a valid value, and all will be well. Otherwise
+buildman will perform random actions. Use -n to check what the random
+actions might be.
+
+Buildman is optimised for building many commits at once, for many boards.
+On multi-core machines, Buildman is fast because it uses most of the
+available CPU power. When it gets to the end, or if you are building just
+a few commits or boards, it will be pretty slow. As a tip, if you don't
+plan to use your machine for anything else, you can use -T to increase the
+number of threads beyond the default.
+
+Buildman lets you build all boards, or a subset. Specify the subset by passing
+command-line arguments that list the desired board name, architecture name,
+SOC name, or anything else in the boards.cfg file. Multiple arguments are
+allowed. Each argument will be interpreted as a regular expression, so
+behaviour is a superset of exact or substring matching. Examples are:
+
+* 'tegra20' All boards with a Tegra20 SoC
+* 'tegra' All boards with any Tegra Soc (Tegra20, Tegra30, Tegra114...)
+* '^tegra[23]0$' All boards with either Tegra20 or Tegra30 SoC
+* 'powerpc' All PowerPC boards
+
+Buildman does not store intermediate object files. It optionally copies
+the binary output into a directory when a build is successful. Size
+information is always recorded. It needs a fair bit of disk space to work,
+typically 250MB per thread.
+
+
+Setting up
+==========
+
+1. Get the U-Boot source. You probably already have it, but if not these
+steps should get you started with a repo and some commits for testing.
+
+$ cd /path/to/u-boot
+$ git clone git://git.denx.de/u-boot.git .
+$ git checkout -b my-branch origin/master
+$ # Add some commits to the branch, reading for testing
+
+2. Create ~/.buildman to tell buildman where to find tool chains. As an
+example:
+
+# Buildman settings file
+
+[toolchain]
+root: /
+rest: /toolchains/*
+eldk: /opt/eldk-4.2
+
+[toolchain-alias]
+x86: i386
+blackfin: bfin
+sh: sh4
+nds32: nds32le
+openrisc: or32
+
+
+This selects the available toolchain paths. Add the base directory for
+each of your toolchains here. Buildman will search inside these directories
+and also in any '/usr' and '/usr/bin' subdirectories.
+
+Make sure the tags (here root: rest: and eldk:) are unique.
+
+The toolchain-alias section indicates that the i386 toolchain should be used
+to build x86 commits.
+
+
+2. Check the available toolchains
+
+Run this check to make sure that you have a toolchain for every architecture.
+
+$ ./tools/buildman/buildman --list-tool-chains
+Scanning for tool chains
+ - scanning path '/'
+ - looking in '/.'
+ - looking in '/bin'
+ - looking in '/usr/bin'
+ - found '/usr/bin/gcc'
+Tool chain test: OK
+ - found '/usr/bin/c89-gcc'
+Tool chain test: OK
+ - found '/usr/bin/c99-gcc'
+Tool chain test: OK
+ - found '/usr/bin/x86_64-linux-gnu-gcc'
+Tool chain test: OK
+ - scanning path '/toolchains/powerpc-linux'
+ - looking in '/toolchains/powerpc-linux/.'
+ - looking in '/toolchains/powerpc-linux/bin'
+ - found '/toolchains/powerpc-linux/bin/powerpc-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/powerpc-linux/usr/bin'
+ - scanning path '/toolchains/nds32le-linux-glibc-v1f'
+ - looking in '/toolchains/nds32le-linux-glibc-v1f/.'
+ - looking in '/toolchains/nds32le-linux-glibc-v1f/bin'
+ - found '/toolchains/nds32le-linux-glibc-v1f/bin/nds32le-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/nds32le-linux-glibc-v1f/usr/bin'
+ - scanning path '/toolchains/nios2'
+ - looking in '/toolchains/nios2/.'
+ - looking in '/toolchains/nios2/bin'
+ - found '/toolchains/nios2/bin/nios2-linux-gcc'
+Tool chain test: OK
+ - found '/toolchains/nios2/bin/nios2-linux-uclibc-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/nios2/usr/bin'
+ - found '/toolchains/nios2/usr/bin/nios2-linux-gcc'
+Tool chain test: OK
+ - found '/toolchains/nios2/usr/bin/nios2-linux-uclibc-gcc'
+Tool chain test: OK
+ - scanning path '/toolchains/microblaze-unknown-linux-gnu'
+ - looking in '/toolchains/microblaze-unknown-linux-gnu/.'
+ - looking in '/toolchains/microblaze-unknown-linux-gnu/bin'
+ - found '/toolchains/microblaze-unknown-linux-gnu/bin/microblaze-unknown-linux-gnu-gcc'
+Tool chain test: OK
+ - found '/toolchains/microblaze-unknown-linux-gnu/bin/mb-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/microblaze-unknown-linux-gnu/usr/bin'
+ - scanning path '/toolchains/mips-linux'
+ - looking in '/toolchains/mips-linux/.'
+ - looking in '/toolchains/mips-linux/bin'
+ - found '/toolchains/mips-linux/bin/mips-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/mips-linux/usr/bin'
+ - scanning path '/toolchains/old'
+ - looking in '/toolchains/old/.'
+ - looking in '/toolchains/old/bin'
+ - looking in '/toolchains/old/usr/bin'
+ - scanning path '/toolchains/i386-linux'
+ - looking in '/toolchains/i386-linux/.'
+ - looking in '/toolchains/i386-linux/bin'
+ - found '/toolchains/i386-linux/bin/i386-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/i386-linux/usr/bin'
+ - scanning path '/toolchains/bfin-uclinux'
+ - looking in '/toolchains/bfin-uclinux/.'
+ - looking in '/toolchains/bfin-uclinux/bin'
+ - found '/toolchains/bfin-uclinux/bin/bfin-uclinux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/bfin-uclinux/usr/bin'
+ - scanning path '/toolchains/sparc-elf'
+ - looking in '/toolchains/sparc-elf/.'
+ - looking in '/toolchains/sparc-elf/bin'
+ - found '/toolchains/sparc-elf/bin/sparc-elf-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/sparc-elf/usr/bin'
+ - scanning path '/toolchains/arm-2010q1'
+ - looking in '/toolchains/arm-2010q1/.'
+ - looking in '/toolchains/arm-2010q1/bin'
+ - found '/toolchains/arm-2010q1/bin/arm-none-linux-gnueabi-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/arm-2010q1/usr/bin'
+ - scanning path '/toolchains/from'
+ - looking in '/toolchains/from/.'
+ - looking in '/toolchains/from/bin'
+ - looking in '/toolchains/from/usr/bin'
+ - scanning path '/toolchains/sh4-gentoo-linux-gnu'
+ - looking in '/toolchains/sh4-gentoo-linux-gnu/.'
+ - looking in '/toolchains/sh4-gentoo-linux-gnu/bin'
+ - found '/toolchains/sh4-gentoo-linux-gnu/bin/sh4-gentoo-linux-gnu-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/sh4-gentoo-linux-gnu/usr/bin'
+ - scanning path '/toolchains/avr32-linux'
+ - looking in '/toolchains/avr32-linux/.'
+ - looking in '/toolchains/avr32-linux/bin'
+ - found '/toolchains/avr32-linux/bin/avr32-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/avr32-linux/usr/bin'
+ - scanning path '/toolchains/m68k-linux'
+ - looking in '/toolchains/m68k-linux/.'
+ - looking in '/toolchains/m68k-linux/bin'
+ - found '/toolchains/m68k-linux/bin/m68k-linux-gcc'
+Tool chain test: OK
+ - looking in '/toolchains/m68k-linux/usr/bin'
+List of available toolchains (17):
+arm : /toolchains/arm-2010q1/bin/arm-none-linux-gnueabi-gcc
+avr32 : /toolchains/avr32-linux/bin/avr32-gcc
+bfin : /toolchains/bfin-uclinux/bin/bfin-uclinux-gcc
+c89 : /usr/bin/c89-gcc
+c99 : /usr/bin/c99-gcc
+i386 : /toolchains/i386-linux/bin/i386-linux-gcc
+m68k : /toolchains/m68k-linux/bin/m68k-linux-gcc
+mb : /toolchains/microblaze-unknown-linux-gnu/bin/mb-linux-gcc
+microblaze: /toolchains/microblaze-unknown-linux-gnu/bin/microblaze-unknown-linux-gnu-gcc
+mips : /toolchains/mips-linux/bin/mips-linux-gcc
+nds32le : /toolchains/nds32le-linux-glibc-v1f/bin/nds32le-linux-gcc
+nios2 : /toolchains/nios2/bin/nios2-linux-gcc
+powerpc : /toolchains/powerpc-linux/bin/powerpc-linux-gcc
+sandbox : /usr/bin/gcc
+sh4 : /toolchains/sh4-gentoo-linux-gnu/bin/sh4-gentoo-linux-gnu-gcc
+sparc : /toolchains/sparc-elf/bin/sparc-elf-gcc
+x86_64 : /usr/bin/x86_64-linux-gnu-gcc
+
+
+You can see that everything is covered, even some strange ones that won't
+be used (c88 and c99). This is a feature.
+
+
+How to run it
+=============
+
+First do a dry run using the -n flag: (replace with a real, local
+branch with a valid upstream)
+
+$ ./tools/buildman/buildman -b -n
+
+If it can't detect the upstream branch, try checking out the branch, and
+doing something like 'git branch --set-upstream upstream/master'
+or something similar.
+
+As an exmmple:
+
+Dry run, so not doing much. But I would do this:
+
+Building 18 commits for 1059 boards (4 threads, 1 job per thread)
+Build directory: ../lcd9b
+ 5bb3505 Merge branch 'master' of git://git.denx.de/u-boot-arm
+ c18f1b4 tegra: Use const for pinmux_config_pingroup/table()
+ 2f043ae tegra: Add display support to funcmux
+ e349900 tegra: fdt: Add pwm binding and node
+ 424a5f0 tegra: fdt: Add LCD definitions for Tegra
+ 0636ccf tegra: Add support for PWM
+ a994fe7 tegra: Add SOC support for display/lcd
+ fcd7350 tegra: Add LCD driver
+ 4d46e9d tegra: Add LCD support to Nvidia boards
+ 991bd48 arm: Add control over cachability of memory regions
+ 54e8019 lcd: Add CONFIG_LCD_ALIGNMENT to select frame buffer alignment
+ d92aff7 lcd: Add support for flushing LCD fb from dcache after update
+ dbd0677 tegra: Align LCD frame buffer to section boundary
+ 0cff9b8 tegra: Support control of cache settings for LCD
+ 9c56900 tegra: fdt: Add LCD definitions for Seaboard
+ 5cc29db lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console
+ cac5a23 tegra: Enable display/lcd support on Seaboard
+ 49ff541 wip
+
+Total boards to build for each commit: 1059
+
+This shows that it will build all 1059 boards, using 4 threads (because
+we have a 4-core CPU). Each thread will run with -j1, meaning that each
+make job will use a single CPU. The list of commits to be built helps you
+confirm that things look about right. Notice that buildman has chosen a
+'base' directory for you, immediately above your source tree.
+
+Buildman works entirely inside the base directory, here ../lcd9b,
+creating a working directory for each thread, and creating output
+directories for each commit and board.
+
+
+Suggested Workflow
+==================
+
+To run the build for real, take off the -n:
+
+$ ./tools/buildman/buildman -b
+
+Buildman will set up some working directories, and get started. After a
+minute or so it will settle down to a steady pace, with a display like this:
+
+Building 18 commits for 1059 boards (4 threads, 1 job per thread)
+ 528 36 124 /19062 1:13:30 : SIMPC8313_SP
+
+This means that it is building 19062 board/commit combinations. So far it
+has managed to succesfully build 528. Another 36 have built with warnings,
+and 124 more didn't build at all. Buildman expects to complete the process
+in an hour and 15 minutes. Use this time to buy a faster computer.
+
+
+To find out how the build went, ask for a summary with -s. You can do this
+either before the build completes (presumably in another terminal) or or
+afterwards. Let's work through an example of how this is used:
+
+$ ./tools/buildman/buildman -b lcd9b -s
+...
+01: Merge branch 'master' of git://git.denx.de/u-boot-arm
+ powerpc: + galaxy5200_LOWBOOT
+02: tegra: Use const for pinmux_config_pingroup/table()
+03: tegra: Add display support to funcmux
+04: tegra: fdt: Add pwm binding and node
+05: tegra: fdt: Add LCD definitions for Tegra
+06: tegra: Add support for PWM
+07: tegra: Add SOC support for display/lcd
+08: tegra: Add LCD driver
+09: tegra: Add LCD support to Nvidia boards
+10: arm: Add control over cachability of memory regions
+11: lcd: Add CONFIG_LCD_ALIGNMENT to select frame buffer alignment
+12: lcd: Add support for flushing LCD fb from dcache after update
+ arm: + lubbock
+13: tegra: Align LCD frame buffer to section boundary
+14: tegra: Support control of cache settings for LCD
+15: tegra: fdt: Add LCD definitions for Seaboard
+16: lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console
+17: tegra: Enable display/lcd support on Seaboard
+18: wip
+
+This shows which commits have succeeded and which have failed. In this case
+the build is still in progress so many boards are not built yet (use -u to
+see which ones). But still we can see a few failures. The galaxy5200_LOWBOOT
+never builds correctly. This could be a problem with our toolchain, or it
+could be a bug in the upstream. The good news is that we probably don't need
+to blame our commits. The bad news is it isn't tested on that board.
+
+Commit 12 broke lubbock. That's what the '+ lubbock' means. The failure
+is never fixed by a later commit, or you would see lubbock again, in green,
+without the +.
+
+To see the actual error:
+
+$ ./tools/buildman/buildman -b -se lubbock
+...
+12: lcd: Add support for flushing LCD fb from dcache after update
+ arm: + lubbock
++common/libcommon.o: In function `lcd_sync':
++/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to `flush_dcache_range'
++arm-none-linux-gnueabi-ld: BFD (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709 assertion fail /scratch/julian/2010q1-release-linux-lite/obj/binutils-src-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/bfd/elf32-arm.c:12572
++make: *** [/u-boot/lcd9b/.bm-work/00/build/u-boot] Error 139
+13: tegra: Align LCD frame buffer to section boundary
+14: tegra: Support control of cache settings for LCD
+15: tegra: fdt: Add LCD definitions for Seaboard
+16: lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console
+-/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to `flush_dcache_range'
++/u-boot/lcd9b/.bm-work/00/common/lcd.c:125: undefined reference to `flush_dcache_range'
+17: tegra: Enable display/lcd support on Seaboard
+18: wip
+
+So the problem is in lcd.c, due to missing cache operations. This information
+should be enough to work out what that commit is doing to break these
+boards. (In this case pxa did not have cache operations defined).
+
+If you see error lines marked with - that means that the errors were fixed
+by that commit. Sometimes commits can be in the wrong order, so that a
+breakage is introduced for a few commits and fixed by later commits. This
+shows up clearly with buildman. You can then reorder the commits and try
+again.
+
+At commit 16, the error moves - you can see that the old error at line 120
+is fixed, but there is a new one at line 126. This is probably only because
+we added some code and moved the broken line futher down the file.
+
+If many boards have the same error, then -e will display the error only
+once. This makes the output as concise as possible.
+
+The full build output in this case is available in:
+
+../lcd9b/12_of_18_gd92aff7_lcd--Add-support-for/lubbock/
+
+ done: Indicates the build was done, and holds the return code from make.
+ This is 0 for a good build, typically 2 for a failure.
+
+ err: Output from stderr, if any. Errors and warnings appear here.
+
+ log: Output from stdout. Normally there isn't any since buildman runs
+ in silent mode for now.
+
+ toolchain: Shows information about the toolchain used for the build.
+
+ sizes: Shows image size information.
+
+It is possible to get the build output there also. Use the -k option for
+this. In that case you will also see some output files, like:
+
+ System.map toolchain u-boot u-boot.bin u-boot.map autoconf.mk
+ (also SPL versions u-boot-spl and u-boot-spl.bin if available)
+
+
+Checking Image Sizes
+====================
+
+A key requirement for U-Boot is that you keep code/data size to a minimum.
+Where a new feature increases this noticeably it should normally be put
+behind a CONFIG flag so that boards can leave it off and keep the image
+size more or less the same with each new release.
+
+To check the impact of your commits on image size, use -S. For example:
+
+$ ./tools/buildman/buildman -b us-x86 -sS
+Summary of 10 commits for 1066 boards (4 threads, 1 job per thread)
+01: MAKEALL: add support for per architecture toolchains
+02: x86: Add function to get top of usable ram
+ x86: (for 1/3 boards) text -272.0 rodata +41.0
+03: x86: Add basic cache operations
+04: x86: Permit bootstage and timer data to be used prior to relocation
+ x86: (for 1/3 boards) data +16.0
+05: x86: Add an __end symbol to signal the end of the U-Boot binary
+ x86: (for 1/3 boards) text +76.0
+06: x86: Rearrange the output input to remove BSS
+ x86: (for 1/3 boards) bss -2140.0
+07: x86: Support relocation of FDT on start-up
+ x86: + coreboot-x86
+08: x86: Add error checking to x86 relocation code
+09: x86: Adjust link device tree include file
+10: x86: Enable CONFIG_OF_CONTROL on coreboot
+
+
+You can see that image size only changed on x86, which is good because this
+series is not supposed to change any other board. From commit 7 onwards the
+build fails so we don't get code size numbers. The numbers are fractional
+because they are an average of all boards for that architecture. The
+intention is to allow you to quickly find image size problems introduced by
+your commits.
+
+Note that the 'text' region and 'rodata' are split out. You should add the
+two together to get the total read-only size (reported as the first column
+in the output from binutil's 'size' utility).
+
+A useful option is --step which lets you skip some commits. For example
+--step 2 will show the image sizes for only every 2nd commit (so it will
+compare the image sizes of the 1st, 3rd, 5th... commits). You can also use
+--step 0 which will compare only the first and last commits. This is useful
+for an overview of how your entire series affects code size.
+
+You can also use -d to see a detailed size breakdown for each board. This
+list is sorted in order from largest growth to largest reduction.
+
+It is possible to go a little further with the -B option (--bloat). This
+shows where U-Boot has bloted, breaking the size change down to the function
+level. Example output is below:
+
+$ ./tools/buildman/buildman -b us-mem4 -sSdB
+...
+19: Roll crc32 into hash infrastructure
+ arm: (for 10/10 boards) all -143.4 bss +1.2 data -4.8 rodata -48.2 text -91.6
+ paz00 : all +23 bss -4 rodata -29 text +56
+ u-boot: add: 1/0, grow: 3/-2 bytes: 168/-104 (64)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ ext4fs_read_file 540 568 +28
+ insert_var_value_sub 688 692 +4
+ run_list_real 1996 1992 -4
+ do_mem_crc 168 68 -100
+ trimslice : all -9 bss +16 rodata -29 text +4
+ u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ ext4fs_iterate_dir 672 668 -4
+ ext4fs_read_file 568 548 -20
+ do_mem_crc 168 68 -100
+ whistler : all -9 bss +16 rodata -29 text +4
+ u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ ext4fs_iterate_dir 672 668 -4
+ ext4fs_read_file 568 548 -20
+ do_mem_crc 168 68 -100
+ seaboard : all -9 bss -28 rodata -29 text +48
+ u-boot: add: 1/0, grow: 3/-2 bytes: 160/-104 (56)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ ext4fs_read_file 548 568 +20
+ run_list_real 1996 2000 +4
+ do_nandboot 760 756 -4
+ do_mem_crc 168 68 -100
+ colibri_t20_iris: all -9 rodata -29 text +20
+ u-boot: add: 1/0, grow: 2/-3 bytes: 140/-112 (28)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ read_abs_bbt 204 208 +4
+ do_nandboot 760 756 -4
+ ext4fs_read_file 576 568 -8
+ do_mem_crc 168 68 -100
+ ventana : all -37 bss -12 rodata -29 text +4
+ u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ ext4fs_iterate_dir 672 668 -4
+ ext4fs_read_file 568 548 -20
+ do_mem_crc 168 68 -100
+ harmony : all -37 bss -16 rodata -29 text +8
+ u-boot: add: 1/0, grow: 2/-3 bytes: 140/-124 (16)
+ function old new delta
+ hash_command 80 160 +80
+ crc32_wd_buf - 56 +56
+ nand_write_oob_syndrome 428 432 +4
+ ext4fs_iterate_dir 672 668 -4
+ ext4fs_read_file 568 548 -20
+ do_mem_crc 168 68 -100
+ medcom-wide : all -417 bss +28 data -16 rodata -93 text -336
+ u-boot: add: 1/-1, grow: 1/-2 bytes: 88/-376 (-288)
+ function old new delta
+ crc32_wd_buf - 56 +56
+ do_fat_read_at 2872 2904 +32
+ hash_algo 16 - -16
+ do_mem_crc 168 68 -100
+ hash_command 420 160 -260
+ tec : all -449 bss -4 data -16 rodata -93 text -336
+ u-boot: add: 1/-1, grow: 1/-2 bytes: 88/-376 (-288)
+ function old new delta
+ crc32_wd_buf - 56 +56
+ do_fat_read_at 2872 2904 +32
+ hash_algo 16 - -16
+ do_mem_crc 168 68 -100
+ hash_command 420 160 -260
+ plutux : all -481 bss +16 data -16 rodata -93 text -388
+ u-boot: add: 1/-1, grow: 1/-3 bytes: 68/-408 (-340)
+ function old new delta
+ crc32_wd_buf - 56 +56
+ do_load_serial_bin 1688 1700 +12
+ hash_algo 16 - -16
+ do_fat_read_at 2904 2872 -32
+ do_mem_crc 168 68 -100
+ hash_command 420 160 -260
+ powerpc: (for 5/5 boards) all +37.4 data -3.2 rodata -41.8 text +82.4
+ MPC8610HPCD : all +55 rodata -29 text +84
+ u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80)
+ function old new delta
+ hash_command - 176 +176
+ do_mem_crc 184 88 -96
+ MPC8641HPCN : all +55 rodata -29 text +84
+ u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80)
+ function old new delta
+ hash_command - 176 +176
+ do_mem_crc 184 88 -96
+ MPC8641HPCN_36BIT: all +55 rodata -29 text +84
+ u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80)
+ function old new delta
+ hash_command - 176 +176
+ do_mem_crc 184 88 -96
+ sbc8641d : all +55 rodata -29 text +84
+ u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80)
+ function old new delta
+ hash_command - 176 +176
+ do_mem_crc 184 88 -96
+ xpedite517x : all -33 data -16 rodata -93 text +76
+ u-boot: add: 1/-1, grow: 0/-1 bytes: 176/-112 (64)
+ function old new delta
+ hash_command - 176 +176
+ hash_algo 16 - -16
+ do_mem_crc 184 88 -96
+...
+
+
+This shows that commit 19 has increased text size for arm (although only one
+board was built) and by 96 bytes for powerpc. This increase was offset in both
+cases by reductions in rodata and data/bss.
+
+Shown below the summary lines is the sizes for each board. Below each board
+is the sizes for each function. This information starts with:
+
+ add - number of functions added / removed
+ grow - number of functions which grew / shrunk
+ bytes - number of bytes of code added to / removed from all functions,
+ plus the total byte change in brackets
+
+The change seems to be that hash_command() has increased by more than the
+do_mem_crc() function has decreased. The function sizes typically add up to
+roughly the text area size, but note that every read-only section except
+rodata is included in 'text', so the function total does not exactly
+correspond.
+
+It is common when refactoring code for the rodata to decrease as the text size
+increases, and vice versa.
+
+
+Providing 'make' flags
+======================
+
+U-Boot's build system supports a few flags (such as BUILD_TAG) which affect
+the build product. These flags can be specified in the buildman settings
+file. They can also be useful when building U-Boot against other open source
+software.
+
+[make-flags]
+at91-boards=ENABLE_AT91_TEST=1
+snapper9260=${at91-boards} BUILD_TAG=442
+snapper9g45=${at91-boards} BUILD_TAG=443
+
+This will use 'make ENABLE_AT91_TEST=1 BUILD_TAG=442' for snapper9260
+and 'make ENABLE_AT91_TEST=1 BUILD_TAG=443' for snapper9g45. A special
+variable ${target} is available to access the target name (snapper9260 and
+snapper9g20 in this case). Variables are resolved recursively.
+
+It is expected that any variables added are dealt with in U-Boot's
+config.mk file and documented in the README.
+
+
+Other options
+=============
+
+Buildman has various other command line options. Try --help to see them.
+
+
+TODO
+====
+
+This has mostly be written in my spare time as a response to my difficulties
+in testing large series of patches. Apart from tidying up there is quite a
+bit of scope for improvement. Things like better error diffs, easier access
+to log files, error display while building. Also it would be nice it buildman
+could 'hunt' for problems, perhaps by building a few boards for each arch,
+or checking commits for changed files and building only boards which use
+those files.
+
+
+Credits
+=======
+
+Thanks to Grant Grundler for his ideas for improving
+the build speed by building all commits for a board instead of the other
+way around.
+
+
+Simon Glass
+sjg@chromium.org
+Halloween 2012
+Updated 12-12-12
+Updated 23-02-13
diff --git a/roms/u-boot/tools/buildman/board.py b/roms/u-boot/tools/buildman/board.py
new file mode 100644
index 00000000..5172a473
--- /dev/null
+++ b/roms/u-boot/tools/buildman/board.py
@@ -0,0 +1,164 @@
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import re
+
+class Board:
+ """A particular board that we can build"""
+ def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options):
+ """Create a new board type.
+
+ Args:
+ status: define whether the board is 'Active' or 'Orphaned'
+ arch: Architecture name (e.g. arm)
+ cpu: Cpu name (e.g. arm1136)
+ soc: Name of SOC, or '' if none (e.g. mx31)
+ vendor: Name of vendor (e.g. armltd)
+ board_name: Name of board (e.g. integrator)
+ target: Target name (use make _config to configure)
+ options: board-specific options (e.g. integratorcp:CM1136)
+ """
+ self.target = target
+ self.arch = arch
+ self.cpu = cpu
+ self.board_name = board_name
+ self.vendor = vendor
+ self.soc = soc
+ self.props = [self.target, self.arch, self.cpu, self.board_name,
+ self.vendor, self.soc]
+ self.options = options
+ self.build_it = False
+
+
+class Boards:
+ """Manage a list of boards."""
+ def __init__(self):
+ # Use a simple list here, sinc OrderedDict requires Python 2.7
+ self._boards = []
+
+ def AddBoard(self, board):
+ """Add a new board to the list.
+
+ The board's target member must not already exist in the board list.
+
+ Args:
+ board: board to add
+ """
+ self._boards.append(board)
+
+ def ReadBoards(self, fname):
+ """Read a list of boards from a board file.
+
+ Create a board object for each and add it to our _boards list.
+
+ Args:
+ fname: Filename of boards.cfg file
+ """
+ with open(fname, 'r') as fd:
+ for line in fd:
+ if line[0] == '#':
+ continue
+ fields = line.split()
+ if not fields:
+ continue
+ for upto in range(len(fields)):
+ if fields[upto] == '-':
+ fields[upto] = ''
+ while len(fields) < 8:
+ fields.append('')
+ if len(fields) > 8:
+ fields = fields[:8]
+
+ board = Board(*fields)
+ self.AddBoard(board)
+
+
+ def GetList(self):
+ """Return a list of available boards.
+
+ Returns:
+ List of Board objects
+ """
+ return self._boards
+
+ def GetDict(self):
+ """Build a dictionary containing all the boards.
+
+ Returns:
+ Dictionary:
+ key is board.target
+ value is board
+ """
+ board_dict = {}
+ for board in self._boards:
+ board_dict[board.target] = board
+ return board_dict
+
+ def GetSelectedDict(self):
+ """Return a dictionary containing the selected boards
+
+ Returns:
+ List of Board objects that are marked selected
+ """
+ board_dict = {}
+ for board in self._boards:
+ if board.build_it:
+ board_dict[board.target] = board
+ return board_dict
+
+ def GetSelected(self):
+ """Return a list of selected boards
+
+ Returns:
+ List of Board objects that are marked selected
+ """
+ return [board for board in self._boards if board.build_it]
+
+ def GetSelectedNames(self):
+ """Return a list of selected boards
+
+ Returns:
+ List of board names that are marked selected
+ """
+ return [board.target for board in self._boards if board.build_it]
+
+ def SelectBoards(self, args):
+ """Mark boards selected based on args
+
+ Args:
+ List of strings specifying boards to include, either named, or
+ by their target, architecture, cpu, vendor or soc. If empty, all
+ boards are selected.
+
+ Returns:
+ Dictionary which holds the number of boards which were selected
+ due to each argument, arranged by argument.
+ """
+ result = {}
+ argres = {}
+ for arg in args:
+ result[arg] = 0
+ argres[arg] = re.compile(arg)
+ result['all'] = 0
+
+ for board in self._boards:
+ if args:
+ for arg in args:
+ argre = argres[arg]
+ match = False
+ for prop in board.props:
+ match = argre.match(prop)
+ if match:
+ break
+ if match:
+ if not board.build_it:
+ board.build_it = True
+ result[arg] += 1
+ result['all'] += 1
+ else:
+ board.build_it = True
+ result['all'] += 1
+
+ return result
diff --git a/roms/u-boot/tools/buildman/bsettings.py b/roms/u-boot/tools/buildman/bsettings.py
new file mode 100644
index 00000000..91647986
--- /dev/null
+++ b/roms/u-boot/tools/buildman/bsettings.py
@@ -0,0 +1,41 @@
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import ConfigParser
+import os
+
+
+def Setup(fname=''):
+ """Set up the buildman settings module by reading config files
+
+ Args:
+ config_fname: Config filename to read ('' for default)
+ """
+ global settings
+ global config_fname
+
+ settings = ConfigParser.SafeConfigParser()
+ config_fname = fname
+ if config_fname == '':
+ config_fname = '%s/.buildman' % os.getenv('HOME')
+ if config_fname:
+ settings.read(config_fname)
+
+def GetItems(section):
+ """Get the items from a section of the config.
+
+ Args:
+ section: name of section to retrieve
+
+ Returns:
+ List of (name, value) tuples for the section
+ """
+ try:
+ return settings.items(section)
+ except ConfigParser.NoSectionError as e:
+ print e
+ return []
+ except:
+ raise
diff --git a/roms/u-boot/tools/buildman/builder.py b/roms/u-boot/tools/buildman/builder.py
new file mode 100644
index 00000000..4a2d753c
--- /dev/null
+++ b/roms/u-boot/tools/buildman/builder.py
@@ -0,0 +1,1430 @@
+# Copyright (c) 2013 The Chromium OS Authors.
+#
+# Bloat-o-meter code used here Copyright 2004 Matt Mackall
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import collections
+import errno
+from datetime import datetime, timedelta
+import glob
+import os
+import re
+import Queue
+import shutil
+import string
+import sys
+import threading
+import time
+
+import command
+import gitutil
+import terminal
+import toolchain
+
+
+"""
+Theory of Operation
+
+Please see README for user documentation, and you should be familiar with
+that before trying to make sense of this.
+
+Buildman works by keeping the machine as busy as possible, building different
+commits for different boards on multiple CPUs at once.
+
+The source repo (self.git_dir) contains all the commits to be built. Each
+thread works on a single board at a time. It checks out the first commit,
+configures it for that board, then builds it. Then it checks out the next
+commit and builds it (typically without re-configuring). When it runs out
+of commits, it gets another job from the builder and starts again with that
+board.
+
+Clearly the builder threads could work either way - they could check out a
+commit and then built it for all boards. Using separate directories for each
+commit/board pair they could leave their build product around afterwards
+also.
+
+The intent behind building a single board for multiple commits, is to make
+use of incremental builds. Since each commit is built incrementally from
+the previous one, builds are faster. Reconfiguring for a different board
+removes all intermediate object files.
+
+Many threads can be working at once, but each has its own working directory.
+When a thread finishes a build, it puts the output files into a result
+directory.
+
+The base directory used by buildman is normally '../', i.e.
+a directory higher than the source repository and named after the branch
+being built.
+
+Within the base directory, we have one subdirectory for each commit. Within
+that is one subdirectory for each board. Within that is the build output for
+that commit/board combination.
+
+Buildman also create working directories for each thread, in a .bm-work/
+subdirectory in the base dir.
+
+As an example, say we are building branch 'us-net' for boards 'sandbox' and
+'seaboard', and say that us-net has two commits. We will have directories
+like this:
+
+us-net/ base directory
+ 01_of_02_g4ed4ebc_net--Add-tftp-speed-/
+ sandbox/
+ u-boot.bin
+ seaboard/
+ u-boot.bin
+ 02_of_02_g4ed4ebc_net--Check-tftp-comp/
+ sandbox/
+ u-boot.bin
+ seaboard/
+ u-boot.bin
+ .bm-work/
+ 00/ working directory for thread 0 (contains source checkout)
+ build/ build output
+ 01/ working directory for thread 1
+ build/ build output
+ ...
+u-boot/ source directory
+ .git/ repository
+"""
+
+# Possible build outcomes
+OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4)
+
+# Translate a commit subject into a valid filename
+trans_valid_chars = string.maketrans("/: ", "---")
+
+
+def Mkdir(dirname):
+ """Make a directory if it doesn't already exist.
+
+ Args:
+ dirname: Directory to create
+ """
+ try:
+ os.mkdir(dirname)
+ except OSError as err:
+ if err.errno == errno.EEXIST:
+ pass
+ else:
+ raise
+
+class BuilderJob:
+ """Holds information about a job to be performed by a thread
+
+ Members:
+ board: Board object to build
+ commits: List of commit options to build.
+ """
+ def __init__(self):
+ self.board = None
+ self.commits = []
+
+
+class ResultThread(threading.Thread):
+ """This thread processes results from builder threads.
+
+ It simply passes the results on to the builder. There is only one
+ result thread, and this helps to serialise the build output.
+ """
+ def __init__(self, builder):
+ """Set up a new result thread
+
+ Args:
+ builder: Builder which will be sent each result
+ """
+ threading.Thread.__init__(self)
+ self.builder = builder
+
+ def run(self):
+ """Called to start up the result thread.
+
+ We collect the next result job and pass it on to the build.
+ """
+ while True:
+ result = self.builder.out_queue.get()
+ self.builder.ProcessResult(result)
+ self.builder.out_queue.task_done()
+
+
+class BuilderThread(threading.Thread):
+ """This thread builds U-Boot for a particular board.
+
+ An input queue provides each new job. We run 'make' to build U-Boot
+ and then pass the results on to the output queue.
+
+ Members:
+ builder: The builder which contains information we might need
+ thread_num: Our thread number (0-n-1), used to decide on a
+ temporary directory
+ """
+ def __init__(self, builder, thread_num):
+ """Set up a new builder thread"""
+ threading.Thread.__init__(self)
+ self.builder = builder
+ self.thread_num = thread_num
+
+ def Make(self, commit, brd, stage, cwd, *args, **kwargs):
+ """Run 'make' on a particular commit and board.
+
+ The source code will already be checked out, so the 'commit'
+ argument is only for information.
+
+ Args:
+ commit: Commit object that is being built
+ brd: Board object that is being built
+ stage: Stage of the build. Valid stages are:
+ distclean - can be called to clean source
+ config - called to configure for a board
+ build - the main make invocation - it does the build
+ args: A list of arguments to pass to 'make'
+ kwargs: A list of keyword arguments to pass to command.RunPipe()
+
+ Returns:
+ CommandResult object
+ """
+ return self.builder.do_make(commit, brd, stage, cwd, *args,
+ **kwargs)
+
+ def RunCommit(self, commit_upto, brd, work_dir, do_config, force_build):
+ """Build a particular commit.
+
+ If the build is already done, and we are not forcing a build, we skip
+ the build and just return the previously-saved results.
+
+ Args:
+ commit_upto: Commit number to build (0...n-1)
+ brd: Board object to build
+ work_dir: Directory to which the source will be checked out
+ do_config: True to run a make _config on the source
+ force_build: Force a build even if one was previously done
+
+ Returns:
+ tuple containing:
+ - CommandResult object containing the results of the build
+ - boolean indicating whether 'make config' is still needed
+ """
+ # Create a default result - it will be overwritte by the call to
+ # self.Make() below, in the event that we do a build.
+ result = command.CommandResult()
+ result.return_code = 0
+ out_dir = os.path.join(work_dir, 'build')
+
+ # Check if the job was already completed last time
+ done_file = self.builder.GetDoneFile(commit_upto, brd.target)
+ result.already_done = os.path.exists(done_file)
+ if result.already_done and not force_build:
+ # Get the return code from that build and use it
+ with open(done_file, 'r') as fd:
+ result.return_code = int(fd.readline())
+ err_file = self.builder.GetErrFile(commit_upto, brd.target)
+ if os.path.exists(err_file) and os.stat(err_file).st_size:
+ result.stderr = 'bad'
+ else:
+ # We are going to have to build it. First, get a toolchain
+ if not self.toolchain:
+ try:
+ self.toolchain = self.builder.toolchains.Select(brd.arch)
+ except ValueError as err:
+ result.return_code = 10
+ result.stdout = ''
+ result.stderr = str(err)
+ # TODO(sjg@chromium.org): This gets swallowed, but needs
+ # to be reported.
+
+ if self.toolchain:
+ # Checkout the right commit
+ if commit_upto is not None:
+ commit = self.builder.commits[commit_upto]
+ if self.builder.checkout:
+ git_dir = os.path.join(work_dir, '.git')
+ gitutil.Checkout(commit.hash, git_dir, work_dir,
+ force=True)
+ else:
+ commit = self.builder.commit # Ick, fix this for BuildCommits()
+
+ # Set up the environment and command line
+ env = self.toolchain.MakeEnvironment()
+ Mkdir(out_dir)
+ args = ['O=build', '-s']
+ if self.builder.num_jobs is not None:
+ args.extend(['-j', str(self.builder.num_jobs)])
+ config_args = ['%s_config' % brd.target]
+ config_out = ''
+ args.extend(self.builder.toolchains.GetMakeArguments(brd))
+
+ # If we need to reconfigure, do that now
+ if do_config:
+ result = self.Make(commit, brd, 'distclean', work_dir,
+ 'distclean', *args, env=env)
+ result = self.Make(commit, brd, 'config', work_dir,
+ *(args + config_args), env=env)
+ config_out = result.combined
+ do_config = False # No need to configure next time
+ if result.return_code == 0:
+ result = self.Make(commit, brd, 'build', work_dir, *args,
+ env=env)
+ result.stdout = config_out + result.stdout
+ else:
+ result.return_code = 1
+ result.stderr = 'No tool chain for %s\n' % brd.arch
+ result.already_done = False
+
+ result.toolchain = self.toolchain
+ result.brd = brd
+ result.commit_upto = commit_upto
+ result.out_dir = out_dir
+ return result, do_config
+
+ def _WriteResult(self, result, keep_outputs):
+ """Write a built result to the output directory.
+
+ Args:
+ result: CommandResult object containing result to write
+ keep_outputs: True to store the output binaries, False
+ to delete them
+ """
+ # Fatal error
+ if result.return_code < 0:
+ return
+
+ # Aborted?
+ if result.stderr and 'No child processes' in result.stderr:
+ return
+
+ if result.already_done:
+ return
+
+ # Write the output and stderr
+ output_dir = self.builder._GetOutputDir(result.commit_upto)
+ Mkdir(output_dir)
+ build_dir = self.builder.GetBuildDir(result.commit_upto,
+ result.brd.target)
+ Mkdir(build_dir)
+
+ outfile = os.path.join(build_dir, 'log')
+ with open(outfile, 'w') as fd:
+ if result.stdout:
+ fd.write(result.stdout)
+
+ errfile = self.builder.GetErrFile(result.commit_upto,
+ result.brd.target)
+ if result.stderr:
+ with open(errfile, 'w') as fd:
+ fd.write(result.stderr)
+ elif os.path.exists(errfile):
+ os.remove(errfile)
+
+ if result.toolchain:
+ # Write the build result and toolchain information.
+ done_file = self.builder.GetDoneFile(result.commit_upto,
+ result.brd.target)
+ with open(done_file, 'w') as fd:
+ fd.write('%s' % result.return_code)
+ with open(os.path.join(build_dir, 'toolchain'), 'w') as fd:
+ print >>fd, 'gcc', result.toolchain.gcc
+ print >>fd, 'path', result.toolchain.path
+ print >>fd, 'cross', result.toolchain.cross
+ print >>fd, 'arch', result.toolchain.arch
+ fd.write('%s' % result.return_code)
+
+ with open(os.path.join(build_dir, 'toolchain'), 'w') as fd:
+ print >>fd, 'gcc', result.toolchain.gcc
+ print >>fd, 'path', result.toolchain.path
+
+ # Write out the image and function size information and an objdump
+ env = result.toolchain.MakeEnvironment()
+ lines = []
+ for fname in ['u-boot', 'spl/u-boot-spl']:
+ cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname]
+ nm_result = command.RunPipe([cmd], capture=True,
+ capture_stderr=True, cwd=result.out_dir,
+ raise_on_error=False, env=env)
+ if nm_result.stdout:
+ nm = self.builder.GetFuncSizesFile(result.commit_upto,
+ result.brd.target, fname)
+ with open(nm, 'w') as fd:
+ print >>fd, nm_result.stdout,
+
+ cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname]
+ dump_result = command.RunPipe([cmd], capture=True,
+ capture_stderr=True, cwd=result.out_dir,
+ raise_on_error=False, env=env)
+ rodata_size = ''
+ if dump_result.stdout:
+ objdump = self.builder.GetObjdumpFile(result.commit_upto,
+ result.brd.target, fname)
+ with open(objdump, 'w') as fd:
+ print >>fd, dump_result.stdout,
+ for line in dump_result.stdout.splitlines():
+ fields = line.split()
+ if len(fields) > 5 and fields[1] == '.rodata':
+ rodata_size = fields[2]
+
+ cmd = ['%ssize' % self.toolchain.cross, fname]
+ size_result = command.RunPipe([cmd], capture=True,
+ capture_stderr=True, cwd=result.out_dir,
+ raise_on_error=False, env=env)
+ if size_result.stdout:
+ lines.append(size_result.stdout.splitlines()[1] + ' ' +
+ rodata_size)
+
+ # Write out the image sizes file. This is similar to the output
+ # of binutil's 'size' utility, but it omits the header line and
+ # adds an additional hex value at the end of each line for the
+ # rodata size
+ if len(lines):
+ sizes = self.builder.GetSizesFile(result.commit_upto,
+ result.brd.target)
+ with open(sizes, 'w') as fd:
+ print >>fd, '\n'.join(lines)
+
+ # Now write the actual build output
+ if keep_outputs:
+ patterns = ['u-boot', '*.bin', 'u-boot.dtb', '*.map',
+ 'include/autoconf.mk', 'spl/u-boot-spl',
+ 'spl/u-boot-spl.bin']
+ for pattern in patterns:
+ file_list = glob.glob(os.path.join(result.out_dir, pattern))
+ for fname in file_list:
+ shutil.copy(fname, build_dir)
+
+
+ def RunJob(self, job):
+ """Run a single job
+
+ A job consists of a building a list of commits for a particular board.
+
+ Args:
+ job: Job to build
+ """
+ brd = job.board
+ work_dir = self.builder.GetThreadDir(self.thread_num)
+ self.toolchain = None
+ if job.commits:
+ # Run 'make board_config' on the first commit
+ do_config = True
+ commit_upto = 0
+ force_build = False
+ for commit_upto in range(0, len(job.commits), job.step):
+ result, request_config = self.RunCommit(commit_upto, brd,
+ work_dir, do_config,
+ force_build or self.builder.force_build)
+ failed = result.return_code or result.stderr
+ if failed and not do_config:
+ # If our incremental build failed, try building again
+ # with a reconfig.
+ if self.builder.force_config_on_failure:
+ result, request_config = self.RunCommit(commit_upto,
+ brd, work_dir, True, True)
+ do_config = request_config
+
+ # If we built that commit, then config is done. But if we got
+ # an warning, reconfig next time to force it to build the same
+ # files that created warnings this time. Otherwise an
+ # incremental build may not build the same file, and we will
+ # think that the warning has gone away.
+ # We could avoid this by using -Werror everywhere...
+ # For errors, the problem doesn't happen, since presumably
+ # the build stopped and didn't generate output, so will retry
+ # that file next time. So we could detect warnings and deal
+ # with them specially here. For now, we just reconfigure if
+ # anything goes work.
+ # Of course this is substantially slower if there are build
+ # errors/warnings (e.g. 2-3x slower even if only 10% of builds
+ # have problems).
+ if (failed and not result.already_done and not do_config and
+ self.builder.force_config_on_failure):
+ # If this build failed, try the next one with a
+ # reconfigure.
+ # Sometimes if the board_config.h file changes it can mess
+ # with dependencies, and we get:
+ # make: *** No rule to make target `include/autoconf.mk',
+ # needed by `depend'.
+ do_config = True
+ force_build = True
+ else:
+ force_build = False
+ if self.builder.force_config_on_failure:
+ if failed:
+ do_config = True
+ result.commit_upto = commit_upto
+ if result.return_code < 0:
+ raise ValueError('Interrupt')
+
+ # We have the build results, so output the result
+ self._WriteResult(result, job.keep_outputs)
+ self.builder.out_queue.put(result)
+ else:
+ # Just build the currently checked-out build
+ result = self.RunCommit(None, True)
+ result.commit_upto = self.builder.upto
+ self.builder.out_queue.put(result)
+
+ def run(self):
+ """Our thread's run function
+
+ This thread picks a job from the queue, runs it, and then goes to the
+ next job.
+ """
+ alive = True
+ while True:
+ job = self.builder.queue.get()
+ try:
+ if self.builder.active and alive:
+ self.RunJob(job)
+ except Exception as err:
+ alive = False
+ print err
+ self.builder.queue.task_done()
+
+
+class Builder:
+ """Class for building U-Boot for a particular commit.
+
+ Public members: (many should ->private)
+ active: True if the builder is active and has not been stopped
+ already_done: Number of builds already completed
+ base_dir: Base directory to use for builder
+ checkout: True to check out source, False to skip that step.
+ This is used for testing.
+ col: terminal.Color() object
+ count: Number of commits to build
+ do_make: Method to call to invoke Make
+ fail: Number of builds that failed due to error
+ force_build: Force building even if a build already exists
+ force_config_on_failure: If a commit fails for a board, disable
+ incremental building for the next commit we build for that
+ board, so that we will see all warnings/errors again.
+ git_dir: Git directory containing source repository
+ last_line_len: Length of the last line we printed (used for erasing
+ it with new progress information)
+ num_jobs: Number of jobs to run at once (passed to make as -j)
+ num_threads: Number of builder threads to run
+ out_queue: Queue of results to process
+ re_make_err: Compiled regular expression for ignore_lines
+ queue: Queue of jobs to run
+ threads: List of active threads
+ toolchains: Toolchains object to use for building
+ upto: Current commit number we are building (0.count-1)
+ warned: Number of builds that produced at least one warning
+
+ Private members:
+ _base_board_dict: Last-summarised Dict of boards
+ _base_err_lines: Last-summarised list of errors
+ _build_period_us: Time taken for a single build (float object).
+ _complete_delay: Expected delay until completion (timedelta)
+ _next_delay_update: Next time we plan to display a progress update
+ (datatime)
+ _show_unknown: Show unknown boards (those not built) in summary
+ _timestamps: List of timestamps for the completion of the last
+ last _timestamp_count builds. Each is a datetime object.
+ _timestamp_count: Number of timestamps to keep in our list.
+ _working_dir: Base working directory containing all threads
+ """
+ class Outcome:
+ """Records a build outcome for a single make invocation
+
+ Public Members:
+ rc: Outcome value (OUTCOME_...)
+ err_lines: List of error lines or [] if none
+ sizes: Dictionary of image size information, keyed by filename
+ - Each value is itself a dictionary containing
+ values for 'text', 'data' and 'bss', being the integer
+ size in bytes of each section.
+ func_sizes: Dictionary keyed by filename - e.g. 'u-boot'. Each
+ value is itself a dictionary:
+ key: function name
+ value: Size of function in bytes
+ """
+ def __init__(self, rc, err_lines, sizes, func_sizes):
+ self.rc = rc
+ self.err_lines = err_lines
+ self.sizes = sizes
+ self.func_sizes = func_sizes
+
+ def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs,
+ checkout=True, show_unknown=True, step=1):
+ """Create a new Builder object
+
+ Args:
+ toolchains: Toolchains object to use for building
+ base_dir: Base directory to use for builder
+ git_dir: Git directory containing source repository
+ num_threads: Number of builder threads to run
+ num_jobs: Number of jobs to run at once (passed to make as -j)
+ checkout: True to check out source, False to skip that step.
+ This is used for testing.
+ show_unknown: Show unknown boards (those not built) in summary
+ step: 1 to process every commit, n to process every nth commit
+ """
+ self.toolchains = toolchains
+ self.base_dir = base_dir
+ self._working_dir = os.path.join(base_dir, '.bm-work')
+ self.threads = []
+ self.active = True
+ self.do_make = self.Make
+ self.checkout = checkout
+ self.num_threads = num_threads
+ self.num_jobs = num_jobs
+ self.already_done = 0
+ self.force_build = False
+ self.git_dir = git_dir
+ self._show_unknown = show_unknown
+ self._timestamp_count = 10
+ self._build_period_us = None
+ self._complete_delay = None
+ self._next_delay_update = datetime.now()
+ self.force_config_on_failure = True
+ self._step = step
+
+ self.col = terminal.Color()
+
+ self.queue = Queue.Queue()
+ self.out_queue = Queue.Queue()
+ for i in range(self.num_threads):
+ t = BuilderThread(self, i)
+ t.setDaemon(True)
+ t.start()
+ self.threads.append(t)
+
+ self.last_line_len = 0
+ t = ResultThread(self)
+ t.setDaemon(True)
+ t.start()
+ self.threads.append(t)
+
+ ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)']
+ self.re_make_err = re.compile('|'.join(ignore_lines))
+
+ def __del__(self):
+ """Get rid of all threads created by the builder"""
+ for t in self.threads:
+ del t
+
+ def _AddTimestamp(self):
+ """Add a new timestamp to the list and record the build period.
+
+ The build period is the length of time taken to perform a single
+ build (one board, one commit).
+ """
+ now = datetime.now()
+ self._timestamps.append(now)
+ count = len(self._timestamps)
+ delta = self._timestamps[-1] - self._timestamps[0]
+ seconds = delta.total_seconds()
+
+ # If we have enough data, estimate build period (time taken for a
+ # single build) and therefore completion time.
+ if count > 1 and self._next_delay_update < now:
+ self._next_delay_update = now + timedelta(seconds=2)
+ if seconds > 0:
+ self._build_period = float(seconds) / count
+ todo = self.count - self.upto
+ self._complete_delay = timedelta(microseconds=
+ self._build_period * todo * 1000000)
+ # Round it
+ self._complete_delay -= timedelta(
+ microseconds=self._complete_delay.microseconds)
+
+ if seconds > 60:
+ self._timestamps.popleft()
+ count -= 1
+
+ def ClearLine(self, length):
+ """Clear any characters on the current line
+
+ Make way for a new line of length 'length', by outputting enough
+ spaces to clear out the old line. Then remember the new length for
+ next time.
+
+ Args:
+ length: Length of new line, in characters
+ """
+ if length < self.last_line_len:
+ print ' ' * (self.last_line_len - length),
+ print '\r',
+ self.last_line_len = length
+ sys.stdout.flush()
+
+ def SelectCommit(self, commit, checkout=True):
+ """Checkout the selected commit for this build
+ """
+ self.commit = commit
+ if checkout and self.checkout:
+ gitutil.Checkout(commit.hash)
+
+ def Make(self, commit, brd, stage, cwd, *args, **kwargs):
+ """Run make
+
+ Args:
+ commit: Commit object that is being built
+ brd: Board object that is being built
+ stage: Stage that we are at (distclean, config, build)
+ cwd: Directory where make should be run
+ args: Arguments to pass to make
+ kwargs: Arguments to pass to command.RunPipe()
+ """
+ cmd = ['make'] + list(args)
+ result = command.RunPipe([cmd], capture=True, capture_stderr=True,
+ cwd=cwd, raise_on_error=False, **kwargs)
+ return result
+
+ def ProcessResult(self, result):
+ """Process the result of a build, showing progress information
+
+ Args:
+ result: A CommandResult object
+ """
+ col = terminal.Color()
+ if result:
+ target = result.brd.target
+
+ if result.return_code < 0:
+ self.active = False
+ command.StopAll()
+ return
+
+ self.upto += 1
+ if result.return_code != 0:
+ self.fail += 1
+ elif result.stderr:
+ self.warned += 1
+ if result.already_done:
+ self.already_done += 1
+ else:
+ target = '(starting)'
+
+ # Display separate counts for ok, warned and fail
+ ok = self.upto - self.warned - self.fail
+ line = '\r' + self.col.Color(self.col.GREEN, '%5d' % ok)
+ line += self.col.Color(self.col.YELLOW, '%5d' % self.warned)
+ line += self.col.Color(self.col.RED, '%5d' % self.fail)
+
+ name = ' /%-5d ' % self.count
+
+ # Add our current completion time estimate
+ self._AddTimestamp()
+ if self._complete_delay:
+ name += '%s : ' % self._complete_delay
+ # When building all boards for a commit, we can print a commit
+ # progress message.
+ if result and result.commit_upto is None:
+ name += 'commit %2d/%-3d' % (self.commit_upto + 1,
+ self.commit_count)
+
+ name += target
+ print line + name,
+ length = 13 + len(name)
+ self.ClearLine(length)
+
+ def _GetOutputDir(self, commit_upto):
+ """Get the name of the output directory for a commit number
+
+ The output directory is typically ...//.
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ """
+ commit = self.commits[commit_upto]
+ subject = commit.subject.translate(trans_valid_chars)
+ commit_dir = ('%02d_of_%02d_g%s_%s' % (commit_upto + 1,
+ self.commit_count, commit.hash, subject[:20]))
+ output_dir = os.path.join(self.base_dir, commit_dir)
+ return output_dir
+
+ def GetBuildDir(self, commit_upto, target):
+ """Get the name of the build directory for a commit number
+
+ The build directory is typically ...///.
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ """
+ output_dir = self._GetOutputDir(commit_upto)
+ return os.path.join(output_dir, target)
+
+ def GetDoneFile(self, commit_upto, target):
+ """Get the name of the done file for a commit number
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ """
+ return os.path.join(self.GetBuildDir(commit_upto, target), 'done')
+
+ def GetSizesFile(self, commit_upto, target):
+ """Get the name of the sizes file for a commit number
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ """
+ return os.path.join(self.GetBuildDir(commit_upto, target), 'sizes')
+
+ def GetFuncSizesFile(self, commit_upto, target, elf_fname):
+ """Get the name of the funcsizes file for a commit number and ELF file
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ elf_fname: Filename of elf image
+ """
+ return os.path.join(self.GetBuildDir(commit_upto, target),
+ '%s.sizes' % elf_fname.replace('/', '-'))
+
+ def GetObjdumpFile(self, commit_upto, target, elf_fname):
+ """Get the name of the objdump file for a commit number and ELF file
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ elf_fname: Filename of elf image
+ """
+ return os.path.join(self.GetBuildDir(commit_upto, target),
+ '%s.objdump' % elf_fname.replace('/', '-'))
+
+ def GetErrFile(self, commit_upto, target):
+ """Get the name of the err file for a commit number
+
+ Args:
+ commit_upto: Commit number to use (0..self.count-1)
+ target: Target name
+ """
+ output_dir = self.GetBuildDir(commit_upto, target)
+ return os.path.join(output_dir, 'err')
+
+ def FilterErrors(self, lines):
+ """Filter out errors in which we have no interest
+
+ We should probably use map().
+
+ Args:
+ lines: List of error lines, each a string
+ Returns:
+ New list with only interesting lines included
+ """
+ out_lines = []
+ for line in lines:
+ if not self.re_make_err.search(line):
+ out_lines.append(line)
+ return out_lines
+
+ def ReadFuncSizes(self, fname, fd):
+ """Read function sizes from the output of 'nm'
+
+ Args:
+ fd: File containing data to read
+ fname: Filename we are reading from (just for errors)
+
+ Returns:
+ Dictionary containing size of each function in bytes, indexed by
+ function name.
+ """
+ sym = {}
+ for line in fd.readlines():
+ try:
+ size, type, name = line[:-1].split()
+ except:
+ print "Invalid line in file '%s': '%s'" % (fname, line[:-1])
+ continue
+ if type in 'tTdDbB':
+ # function names begin with '.' on 64-bit powerpc
+ if '.' in name[1:]:
+ name = 'static.' + name.split('.')[0]
+ sym[name] = sym.get(name, 0) + int(size, 16)
+ return sym
+
+ def GetBuildOutcome(self, commit_upto, target, read_func_sizes):
+ """Work out the outcome of a build.
+
+ Args:
+ commit_upto: Commit number to check (0..n-1)
+ target: Target board to check
+ read_func_sizes: True to read function size information
+
+ Returns:
+ Outcome object
+ """
+ done_file = self.GetDoneFile(commit_upto, target)
+ sizes_file = self.GetSizesFile(commit_upto, target)
+ sizes = {}
+ func_sizes = {}
+ if os.path.exists(done_file):
+ with open(done_file, 'r') as fd:
+ return_code = int(fd.readline())
+ err_lines = []
+ err_file = self.GetErrFile(commit_upto, target)
+ if os.path.exists(err_file):
+ with open(err_file, 'r') as fd:
+ err_lines = self.FilterErrors(fd.readlines())
+
+ # Decide whether the build was ok, failed or created warnings
+ if return_code:
+ rc = OUTCOME_ERROR
+ elif len(err_lines):
+ rc = OUTCOME_WARNING
+ else:
+ rc = OUTCOME_OK
+
+ # Convert size information to our simple format
+ if os.path.exists(sizes_file):
+ with open(sizes_file, 'r') as fd:
+ for line in fd.readlines():
+ values = line.split()
+ rodata = 0
+ if len(values) > 6:
+ rodata = int(values[6], 16)
+ size_dict = {
+ 'all' : int(values[0]) + int(values[1]) +
+ int(values[2]),
+ 'text' : int(values[0]) - rodata,
+ 'data' : int(values[1]),
+ 'bss' : int(values[2]),
+ 'rodata' : rodata,
+ }
+ sizes[values[5]] = size_dict
+
+ if read_func_sizes:
+ pattern = self.GetFuncSizesFile(commit_upto, target, '*')
+ for fname in glob.glob(pattern):
+ with open(fname, 'r') as fd:
+ dict_name = os.path.basename(fname).replace('.sizes',
+ '')
+ func_sizes[dict_name] = self.ReadFuncSizes(fname, fd)
+
+ return Builder.Outcome(rc, err_lines, sizes, func_sizes)
+
+ return Builder.Outcome(OUTCOME_UNKNOWN, [], {}, {})
+
+ def GetResultSummary(self, boards_selected, commit_upto, read_func_sizes):
+ """Calculate a summary of the results of building a commit.
+
+ Args:
+ board_selected: Dict containing boards to summarise
+ commit_upto: Commit number to summarize (0..self.count-1)
+ read_func_sizes: True to read function size information
+
+ Returns:
+ Tuple:
+ Dict containing boards which passed building this commit.
+ keyed by board.target
+ List containing a summary of error/warning lines
+ """
+ board_dict = {}
+ err_lines_summary = []
+
+ for board in boards_selected.itervalues():
+ outcome = self.GetBuildOutcome(commit_upto, board.target,
+ read_func_sizes)
+ board_dict[board.target] = outcome
+ for err in outcome.err_lines:
+ if err and not err.rstrip() in err_lines_summary:
+ err_lines_summary.append(err.rstrip())
+ return board_dict, err_lines_summary
+
+ def AddOutcome(self, board_dict, arch_list, changes, char, color):
+ """Add an output to our list of outcomes for each architecture
+
+ This simple function adds failing boards (changes) to the
+ relevant architecture string, so we can print the results out
+ sorted by architecture.
+
+ Args:
+ board_dict: Dict containing all boards
+ arch_list: Dict keyed by arch name. Value is a string containing
+ a list of board names which failed for that arch.
+ changes: List of boards to add to arch_list
+ color: terminal.Colour object
+ """
+ done_arch = {}
+ for target in changes:
+ if target in board_dict:
+ arch = board_dict[target].arch
+ else:
+ arch = 'unknown'
+ str = self.col.Color(color, ' ' + target)
+ if not arch in done_arch:
+ str = self.col.Color(color, char) + ' ' + str
+ done_arch[arch] = True
+ if not arch in arch_list:
+ arch_list[arch] = str
+ else:
+ arch_list[arch] += str
+
+
+ def ColourNum(self, num):
+ color = self.col.RED if num > 0 else self.col.GREEN
+ if num == 0:
+ return '0'
+ return self.col.Color(color, str(num))
+
+ def ResetResultSummary(self, board_selected):
+ """Reset the results summary ready for use.
+
+ Set up the base board list to be all those selected, and set the
+ error lines to empty.
+
+ Following this, calls to PrintResultSummary() will use this
+ information to work out what has changed.
+
+ Args:
+ board_selected: Dict containing boards to summarise, keyed by
+ board.target
+ """
+ self._base_board_dict = {}
+ for board in board_selected:
+ self._base_board_dict[board] = Builder.Outcome(0, [], [], {})
+ self._base_err_lines = []
+
+ def PrintFuncSizeDetail(self, fname, old, new):
+ grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
+ delta, common = [], {}
+
+ for a in old:
+ if a in new:
+ common[a] = 1
+
+ for name in old:
+ if name not in common:
+ remove += 1
+ down += old[name]
+ delta.append([-old[name], name])
+
+ for name in new:
+ if name not in common:
+ add += 1
+ up += new[name]
+ delta.append([new[name], name])
+
+ for name in common:
+ diff = new.get(name, 0) - old.get(name, 0)
+ if diff > 0:
+ grow, up = grow + 1, up + diff
+ elif diff < 0:
+ shrink, down = shrink + 1, down - diff
+ delta.append([diff, name])
+
+ delta.sort()
+ delta.reverse()
+
+ args = [add, -remove, grow, -shrink, up, -down, up - down]
+ if max(args) == 0:
+ return
+ args = [self.ColourNum(x) for x in args]
+ indent = ' ' * 15
+ print ('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' %
+ tuple([indent, self.col.Color(self.col.YELLOW, fname)] + args))
+ print '%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new',
+ 'delta')
+ for diff, name in delta:
+ if diff:
+ color = self.col.RED if diff > 0 else self.col.GREEN
+ msg = '%s %-38s %7s %7s %+7d' % (indent, name,
+ old.get(name, '-'), new.get(name,'-'), diff)
+ print self.col.Color(color, msg)
+
+
+ def PrintSizeDetail(self, target_list, show_bloat):
+ """Show details size information for each board
+
+ Args:
+ target_list: List of targets, each a dict containing:
+ 'target': Target name
+ 'total_diff': Total difference in bytes across all areas
+ : Difference for that part
+ show_bloat: Show detail for each function
+ """
+ targets_by_diff = sorted(target_list, reverse=True,
+ key=lambda x: x['_total_diff'])
+ for result in targets_by_diff:
+ printed_target = False
+ for name in sorted(result):
+ diff = result[name]
+ if name.startswith('_'):
+ continue
+ if diff != 0:
+ color = self.col.RED if diff > 0 else self.col.GREEN
+ msg = ' %s %+d' % (name, diff)
+ if not printed_target:
+ print '%10s %-15s:' % ('', result['_target']),
+ printed_target = True
+ print self.col.Color(color, msg),
+ if printed_target:
+ print
+ if show_bloat:
+ target = result['_target']
+ outcome = result['_outcome']
+ base_outcome = self._base_board_dict[target]
+ for fname in outcome.func_sizes:
+ self.PrintFuncSizeDetail(fname,
+ base_outcome.func_sizes[fname],
+ outcome.func_sizes[fname])
+
+
+ def PrintSizeSummary(self, board_selected, board_dict, show_detail,
+ show_bloat):
+ """Print a summary of image sizes broken down by section.
+
+ The summary takes the form of one line per architecture. The
+ line contains deltas for each of the sections (+ means the section
+ got bigger, - means smaller). The nunmbers are the average number
+ of bytes that a board in this section increased by.
+
+ For example:
+ powerpc: (622 boards) text -0.0
+ arm: (285 boards) text -0.0
+ nds32: (3 boards) text -8.0
+
+ Args:
+ board_selected: Dict containing boards to summarise, keyed by
+ board.target
+ board_dict: Dict containing boards for which we built this
+ commit, keyed by board.target. The value is an Outcome object.
+ show_detail: Show detail for each board
+ show_bloat: Show detail for each function
+ """
+ arch_list = {}
+ arch_count = {}
+
+ # Calculate changes in size for different image parts
+ # The previous sizes are in Board.sizes, for each board
+ for target in board_dict:
+ if target not in board_selected:
+ continue
+ base_sizes = self._base_board_dict[target].sizes
+ outcome = board_dict[target]
+ sizes = outcome.sizes
+
+ # Loop through the list of images, creating a dict of size
+ # changes for each image/part. We end up with something like
+ # {'target' : 'snapper9g45, 'data' : 5, 'u-boot-spl:text' : -4}
+ # which means that U-Boot data increased by 5 bytes and SPL
+ # text decreased by 4.
+ err = {'_target' : target}
+ for image in sizes:
+ if image in base_sizes:
+ base_image = base_sizes[image]
+ # Loop through the text, data, bss parts
+ for part in sorted(sizes[image]):
+ diff = sizes[image][part] - base_image[part]
+ col = None
+ if diff:
+ if image == 'u-boot':
+ name = part
+ else:
+ name = image + ':' + part
+ err[name] = diff
+ arch = board_selected[target].arch
+ if not arch in arch_count:
+ arch_count[arch] = 1
+ else:
+ arch_count[arch] += 1
+ if not sizes:
+ pass # Only add to our list when we have some stats
+ elif not arch in arch_list:
+ arch_list[arch] = [err]
+ else:
+ arch_list[arch].append(err)
+
+ # We now have a list of image size changes sorted by arch
+ # Print out a summary of these
+ for arch, target_list in arch_list.iteritems():
+ # Get total difference for each type
+ totals = {}
+ for result in target_list:
+ total = 0
+ for name, diff in result.iteritems():
+ if name.startswith('_'):
+ continue
+ total += diff
+ if name in totals:
+ totals[name] += diff
+ else:
+ totals[name] = diff
+ result['_total_diff'] = total
+ result['_outcome'] = board_dict[result['_target']]
+
+ count = len(target_list)
+ printed_arch = False
+ for name in sorted(totals):
+ diff = totals[name]
+ if diff:
+ # Display the average difference in this name for this
+ # architecture
+ avg_diff = float(diff) / count
+ color = self.col.RED if avg_diff > 0 else self.col.GREEN
+ msg = ' %s %+1.1f' % (name, avg_diff)
+ if not printed_arch:
+ print '%10s: (for %d/%d boards)' % (arch, count,
+ arch_count[arch]),
+ printed_arch = True
+ print self.col.Color(color, msg),
+
+ if printed_arch:
+ print
+ if show_detail:
+ self.PrintSizeDetail(target_list, show_bloat)
+
+
+ def PrintResultSummary(self, board_selected, board_dict, err_lines,
+ show_sizes, show_detail, show_bloat):
+ """Compare results with the base results and display delta.
+
+ Only boards mentioned in board_selected will be considered. This
+ function is intended to be called repeatedly with the results of
+ each commit. It therefore shows a 'diff' between what it saw in
+ the last call and what it sees now.
+
+ Args:
+ board_selected: Dict containing boards to summarise, keyed by
+ board.target
+ board_dict: Dict containing boards for which we built this
+ commit, keyed by board.target. The value is an Outcome object.
+ err_lines: A list of errors for this commit, or [] if there is
+ none, or we don't want to print errors
+ show_sizes: Show image size deltas
+ show_detail: Show detail for each board
+ show_bloat: Show detail for each function
+ """
+ better = [] # List of boards fixed since last commit
+ worse = [] # List of new broken boards since last commit
+ new = [] # List of boards that didn't exist last time
+ unknown = [] # List of boards that were not built
+
+ for target in board_dict:
+ if target not in board_selected:
+ continue
+
+ # If the board was built last time, add its outcome to a list
+ if target in self._base_board_dict:
+ base_outcome = self._base_board_dict[target].rc
+ outcome = board_dict[target]
+ if outcome.rc == OUTCOME_UNKNOWN:
+ unknown.append(target)
+ elif outcome.rc < base_outcome:
+ better.append(target)
+ elif outcome.rc > base_outcome:
+ worse.append(target)
+ else:
+ new.append(target)
+
+ # Get a list of errors that have appeared, and disappeared
+ better_err = []
+ worse_err = []
+ for line in err_lines:
+ if line not in self._base_err_lines:
+ worse_err.append('+' + line)
+ for line in self._base_err_lines:
+ if line not in err_lines:
+ better_err.append('-' + line)
+
+ # Display results by arch
+ if better or worse or unknown or new or worse_err or better_err:
+ arch_list = {}
+ self.AddOutcome(board_selected, arch_list, better, '',
+ self.col.GREEN)
+ self.AddOutcome(board_selected, arch_list, worse, '+',
+ self.col.RED)
+ self.AddOutcome(board_selected, arch_list, new, '*', self.col.BLUE)
+ if self._show_unknown:
+ self.AddOutcome(board_selected, arch_list, unknown, '?',
+ self.col.MAGENTA)
+ for arch, target_list in arch_list.iteritems():
+ print '%10s: %s' % (arch, target_list)
+ if better_err:
+ print self.col.Color(self.col.GREEN, '\n'.join(better_err))
+ if worse_err:
+ print self.col.Color(self.col.RED, '\n'.join(worse_err))
+
+ if show_sizes:
+ self.PrintSizeSummary(board_selected, board_dict, show_detail,
+ show_bloat)
+
+ # Save our updated information for the next call to this function
+ self._base_board_dict = board_dict
+ self._base_err_lines = err_lines
+
+ # Get a list of boards that did not get built, if needed
+ not_built = []
+ for board in board_selected:
+ if not board in board_dict:
+ not_built.append(board)
+ if not_built:
+ print "Boards not built (%d): %s" % (len(not_built),
+ ', '.join(not_built))
+
+
+ def ShowSummary(self, commits, board_selected, show_errors, show_sizes,
+ show_detail, show_bloat):
+ """Show a build summary for U-Boot for a given board list.
+
+ Reset the result summary, then repeatedly call GetResultSummary on
+ each commit's results, then display the differences we see.
+
+ Args:
+ commit: Commit objects to summarise
+ board_selected: Dict containing boards to summarise
+ show_errors: Show errors that occured
+ show_sizes: Show size deltas
+ show_detail: Show detail for each board
+ show_bloat: Show detail for each function
+ """
+ self.commit_count = len(commits)
+ self.commits = commits
+ self.ResetResultSummary(board_selected)
+
+ for commit_upto in range(0, self.commit_count, self._step):
+ board_dict, err_lines = self.GetResultSummary(board_selected,
+ commit_upto, read_func_sizes=show_bloat)
+ msg = '%02d: %s' % (commit_upto + 1, commits[commit_upto].subject)
+ print self.col.Color(self.col.BLUE, msg)
+ self.PrintResultSummary(board_selected, board_dict,
+ err_lines if show_errors else [], show_sizes, show_detail,
+ show_bloat)
+
+
+ def SetupBuild(self, board_selected, commits):
+ """Set up ready to start a build.
+
+ Args:
+ board_selected: Selected boards to build
+ commits: Selected commits to build
+ """
+ # First work out how many commits we will build
+ count = (len(commits) + self._step - 1) / self._step
+ self.count = len(board_selected) * count
+ self.upto = self.warned = self.fail = 0
+ self._timestamps = collections.deque()
+
+ def BuildBoardsForCommit(self, board_selected, keep_outputs):
+ """Build all boards for a single commit"""
+ self.SetupBuild(board_selected)
+ self.count = len(board_selected)
+ for brd in board_selected.itervalues():
+ job = BuilderJob()
+ job.board = brd
+ job.commits = None
+ job.keep_outputs = keep_outputs
+ self.queue.put(brd)
+
+ self.queue.join()
+ self.out_queue.join()
+ print
+ self.ClearLine(0)
+
+ def BuildCommits(self, commits, board_selected, show_errors, keep_outputs):
+ """Build all boards for all commits (non-incremental)"""
+ self.commit_count = len(commits)
+
+ self.ResetResultSummary(board_selected)
+ for self.commit_upto in range(self.commit_count):
+ self.SelectCommit(commits[self.commit_upto])
+ self.SelectOutputDir()
+ Mkdir(self.output_dir)
+
+ self.BuildBoardsForCommit(board_selected, keep_outputs)
+ board_dict, err_lines = self.GetResultSummary()
+ self.PrintResultSummary(board_selected, board_dict,
+ err_lines if show_errors else [])
+
+ if self.already_done:
+ print '%d builds already done' % self.already_done
+
+ def GetThreadDir(self, thread_num):
+ """Get the directory path to the working dir for a thread.
+
+ Args:
+ thread_num: Number of thread to check.
+ """
+ return os.path.join(self._working_dir, '%02d' % thread_num)
+
+ def _PrepareThread(self, thread_num):
+ """Prepare the working directory for a thread.
+
+ This clones or fetches the repo into the thread's work directory.
+
+ Args:
+ thread_num: Thread number (0, 1, ...)
+ """
+ thread_dir = self.GetThreadDir(thread_num)
+ Mkdir(thread_dir)
+ git_dir = os.path.join(thread_dir, '.git')
+
+ # Clone the repo if it doesn't already exist
+ # TODO(sjg@chromium): Perhaps some git hackery to symlink instead, so
+ # we have a private index but uses the origin repo's contents?
+ if self.git_dir:
+ src_dir = os.path.abspath(self.git_dir)
+ if os.path.exists(git_dir):
+ gitutil.Fetch(git_dir, thread_dir)
+ else:
+ print 'Cloning repo for thread %d' % thread_num
+ gitutil.Clone(src_dir, thread_dir)
+
+ def _PrepareWorkingSpace(self, max_threads):
+ """Prepare the working directory for use.
+
+ Set up the git repo for each thread.
+
+ Args:
+ max_threads: Maximum number of threads we expect to need.
+ """
+ Mkdir(self._working_dir)
+ for thread in range(max_threads):
+ self._PrepareThread(thread)
+
+ def _PrepareOutputSpace(self):
+ """Get the output directories ready to receive files.
+
+ We delete any output directories which look like ones we need to
+ create. Having left over directories is confusing when the user wants
+ to check the output manually.
+ """
+ dir_list = []
+ for commit_upto in range(self.commit_count):
+ dir_list.append(self._GetOutputDir(commit_upto))
+
+ for dirname in glob.glob(os.path.join(self.base_dir, '*')):
+ if dirname not in dir_list:
+ shutil.rmtree(dirname)
+
+ def BuildBoards(self, commits, board_selected, show_errors, keep_outputs):
+ """Build all commits for a list of boards
+
+ Args:
+ commits: List of commits to be build, each a Commit object
+ boards_selected: Dict of selected boards, key is target name,
+ value is Board object
+ show_errors: True to show summarised error/warning info
+ keep_outputs: True to save build output files
+ """
+ self.commit_count = len(commits)
+ self.commits = commits
+
+ self.ResetResultSummary(board_selected)
+ Mkdir(self.base_dir)
+ self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)))
+ self._PrepareOutputSpace()
+ self.SetupBuild(board_selected, commits)
+ self.ProcessResult(None)
+
+ # Create jobs to build all commits for each board
+ for brd in board_selected.itervalues():
+ job = BuilderJob()
+ job.board = brd
+ job.commits = commits
+ job.keep_outputs = keep_outputs
+ job.step = self._step
+ self.queue.put(job)
+
+ # Wait until all jobs are started
+ self.queue.join()
+
+ # Wait until we have processed all output
+ self.out_queue.join()
+ print
+ self.ClearLine(0)
diff --git a/roms/u-boot/tools/buildman/buildman b/roms/u-boot/tools/buildman/buildman
new file mode 120000
index 00000000..e4fba2d4
--- /dev/null
+++ b/roms/u-boot/tools/buildman/buildman
@@ -0,0 +1 @@
+buildman.py
\ No newline at end of file
diff --git a/roms/u-boot/tools/buildman/buildman.py b/roms/u-boot/tools/buildman/buildman.py
new file mode 100755
index 00000000..73a5483d
--- /dev/null
+++ b/roms/u-boot/tools/buildman/buildman.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+"""See README for more information"""
+
+import multiprocessing
+from optparse import OptionParser
+import os
+import re
+import sys
+import unittest
+
+# Bring in the patman libraries
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(our_path, '../patman'))
+
+# Our modules
+import board
+import builder
+import checkpatch
+import command
+import control
+import doctest
+import gitutil
+import patchstream
+import terminal
+import toolchain
+
+def RunTests():
+ import test
+ import doctest
+
+ result = unittest.TestResult()
+ for module in ['toolchain']:
+ suite = doctest.DocTestSuite(module)
+ suite.run(result)
+
+ # TODO: Surely we can just 'print' result?
+ print result
+ for test, err in result.errors:
+ print err
+ for test, err in result.failures:
+ print err
+
+ sys.argv = [sys.argv[0]]
+ suite = unittest.TestLoader().loadTestsFromTestCase(test.TestBuild)
+ result = unittest.TestResult()
+ suite.run(result)
+
+ # TODO: Surely we can just 'print' result?
+ print result
+ for test, err in result.errors:
+ print err
+ for test, err in result.failures:
+ print err
+
+
+parser = OptionParser()
+parser.add_option('-b', '--branch', type='string',
+ help='Branch name to build')
+parser.add_option('-B', '--bloat', dest='show_bloat',
+ action='store_true', default=False,
+ help='Show changes in function code size for each board')
+parser.add_option('-c', '--count', dest='count', type='int',
+ default=-1, help='Run build on the top n commits')
+parser.add_option('-e', '--show_errors', action='store_true',
+ default=False, help='Show errors and warnings')
+parser.add_option('-f', '--force-build', dest='force_build',
+ action='store_true', default=False,
+ help='Force build of boards even if already built')
+parser.add_option('-d', '--detail', dest='show_detail',
+ action='store_true', default=False,
+ help='Show detailed information for each board in summary')
+parser.add_option('-g', '--git', type='string',
+ help='Git repo containing branch to build', default='.')
+parser.add_option('-H', '--full-help', action='store_true', dest='full_help',
+ default=False, help='Display the README file')
+parser.add_option('-j', '--jobs', dest='jobs', type='int',
+ default=None, help='Number of jobs to run at once (passed to make)')
+parser.add_option('-k', '--keep-outputs', action='store_true',
+ default=False, help='Keep all build output files (e.g. binaries)')
+parser.add_option('--list-tool-chains', action='store_true', default=False,
+ help='List available tool chains')
+parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
+ default=False, help="Do a try run (describe actions, but no nothing)")
+parser.add_option('-Q', '--quick', action='store_true',
+ default=False, help='Do a rough build, with limited warning resolution')
+parser.add_option('-s', '--summary', action='store_true',
+ default=False, help='Show a build summary')
+parser.add_option('-S', '--show-sizes', action='store_true',
+ default=False, help='Show image size variation in summary')
+parser.add_option('--step', type='int',
+ default=1, help='Only build every n commits (0=just first and last)')
+parser.add_option('-t', '--test', action='store_true', dest='test',
+ default=False, help='run tests')
+parser.add_option('-T', '--threads', type='int',
+ default=None, help='Number of builder threads to use')
+parser.add_option('-u', '--show_unknown', action='store_true',
+ default=False, help='Show boards with unknown build result')
+parser.add_option('-o', '--output-dir', type='string',
+ dest='output_dir', default='..',
+ help='Directory where all builds happen and buildman has its workspace (default is ../)')
+
+parser.usage = """buildman -b [options]
+
+Build U-Boot for all commits in a branch. Use -n to do a dry run"""
+
+(options, args) = parser.parse_args()
+
+# Run our meagre tests
+if options.test:
+ RunTests()
+elif options.full_help:
+ pager = os.getenv('PAGER')
+ if not pager:
+ pager = 'more'
+ fname = os.path.join(os.path.dirname(sys.argv[0]), 'README')
+ command.Run(pager, fname)
+
+# Build selected commits for selected boards
+else:
+ control.DoBuildman(options, args)
diff --git a/roms/u-boot/tools/buildman/control.py b/roms/u-boot/tools/buildman/control.py
new file mode 100644
index 00000000..d2f4102b
--- /dev/null
+++ b/roms/u-boot/tools/buildman/control.py
@@ -0,0 +1,174 @@
+# Copyright (c) 2013 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import multiprocessing
+import os
+import sys
+
+import board
+import bsettings
+from builder import Builder
+import gitutil
+import patchstream
+import terminal
+import toolchain
+
+def GetPlural(count):
+ """Returns a plural 's' if count is not 1"""
+ return 's' if count != 1 else ''
+
+def GetActionSummary(is_summary, count, selected, options):
+ """Return a string summarising the intended action.
+
+ Returns:
+ Summary string.
+ """
+ count = (count + options.step - 1) / options.step
+ str = '%s %d commit%s for %d boards' % (
+ 'Summary of' if is_summary else 'Building', count, GetPlural(count),
+ len(selected))
+ str += ' (%d thread%s, %d job%s per thread)' % (options.threads,
+ GetPlural(options.threads), options.jobs, GetPlural(options.jobs))
+ return str
+
+def ShowActions(series, why_selected, boards_selected, builder, options):
+ """Display a list of actions that we would take, if not a dry run.
+
+ Args:
+ series: Series object
+ why_selected: Dictionary where each key is a buildman argument
+ provided by the user, and the value is the boards brought
+ in by that argument. For example, 'arm' might bring in
+ 400 boards, so in this case the key would be 'arm' and
+ the value would be a list of board names.
+ boards_selected: Dict of selected boards, key is target name,
+ value is Board object
+ builder: The builder that will be used to build the commits
+ options: Command line options object
+ """
+ col = terminal.Color()
+ print 'Dry run, so not doing much. But I would do this:'
+ print
+ print GetActionSummary(False, len(series.commits), boards_selected,
+ options)
+ print 'Build directory: %s' % builder.base_dir
+ for upto in range(0, len(series.commits), options.step):
+ commit = series.commits[upto]
+ print ' ', col.Color(col.YELLOW, commit.hash, bright=False),
+ print commit.subject
+ print
+ for arg in why_selected:
+ if arg != 'all':
+ print arg, ': %d boards' % why_selected[arg]
+ print ('Total boards to build for each commit: %d\n' %
+ why_selected['all'])
+
+def DoBuildman(options, args):
+ """The main control code for buildman
+
+ Args:
+ options: Command line options object
+ args: Command line arguments (list of strings)
+ """
+ gitutil.Setup()
+
+ bsettings.Setup()
+ options.git_dir = os.path.join(options.git, '.git')
+
+ toolchains = toolchain.Toolchains()
+ toolchains.Scan(options.list_tool_chains)
+ if options.list_tool_chains:
+ toolchains.List()
+ print
+ return
+
+ # Work out how many commits to build. We want to build everything on the
+ # branch. We also build the upstream commit as a control so we can see
+ # problems introduced by the first commit on the branch.
+ col = terminal.Color()
+ count = options.count
+ if count == -1:
+ if not options.branch:
+ str = 'Please use -b to specify a branch to build'
+ print col.Color(col.RED, str)
+ sys.exit(1)
+ count = gitutil.CountCommitsInBranch(options.git_dir, options.branch)
+ if count is None:
+ str = "Branch '%s' not found or has no upstream" % options.branch
+ print col.Color(col.RED, str)
+ sys.exit(1)
+ count += 1 # Build upstream commit also
+
+ if not count:
+ str = ("No commits found to process in branch '%s': "
+ "set branch's upstream or use -c flag" % options.branch)
+ print col.Color(col.RED, str)
+ sys.exit(1)
+
+ # Work out what subset of the boards we are building
+ boards = board.Boards()
+ boards.ReadBoards(os.path.join(options.git, 'boards.cfg'))
+ why_selected = boards.SelectBoards(args)
+ selected = boards.GetSelected()
+ if not len(selected):
+ print col.Color(col.RED, 'No matching boards found')
+ sys.exit(1)
+
+ # Read the metadata from the commits. First look at the upstream commit,
+ # then the ones in the branch. We would like to do something like
+ # upstream/master~..branch but that isn't possible if upstream/master is
+ # a merge commit (it will list all the commits that form part of the
+ # merge)
+ range_expr = gitutil.GetRangeInBranch(options.git_dir, options.branch)
+ upstream_commit = gitutil.GetUpstream(options.git_dir, options.branch)
+ series = patchstream.GetMetaDataForList(upstream_commit, options.git_dir,
+ 1)
+ # Conflicting tags are not a problem for buildman, since it does not use
+ # them. For example, Series-version is not useful for buildman. On the
+ # other hand conflicting tags will cause an error. So allow later tags
+ # to overwrite earlier ones.
+ series.allow_overwrite = True
+ series = patchstream.GetMetaDataForList(range_expr, options.git_dir, None,
+ series)
+
+ # By default we have one thread per CPU. But if there are not enough jobs
+ # we can have fewer threads and use a high '-j' value for make.
+ if not options.threads:
+ options.threads = min(multiprocessing.cpu_count(), len(selected))
+ if not options.jobs:
+ options.jobs = max(1, (multiprocessing.cpu_count() +
+ len(selected) - 1) / len(selected))
+
+ if not options.step:
+ options.step = len(series.commits) - 1
+
+ # Create a new builder with the selected options
+ output_dir = os.path.join(options.output_dir, options.branch)
+ builder = Builder(toolchains, output_dir, options.git_dir,
+ options.threads, options.jobs, checkout=True,
+ show_unknown=options.show_unknown, step=options.step)
+ builder.force_config_on_failure = not options.quick
+
+ # For a dry run, just show our actions as a sanity check
+ if options.dry_run:
+ ShowActions(series, why_selected, selected, builder, options)
+ else:
+ builder.force_build = options.force_build
+
+ # Work out which boards to build
+ board_selected = boards.GetSelectedDict()
+
+ print GetActionSummary(options.summary, count, board_selected, options)
+
+ if options.summary:
+ # We can't show function sizes without board details at present
+ if options.show_bloat:
+ options.show_detail = True
+ builder.ShowSummary(series.commits, board_selected,
+ options.show_errors, options.show_sizes,
+ options.show_detail, options.show_bloat)
+ else:
+ builder.BuildBoards(series.commits, board_selected,
+ options.show_errors, options.keep_outputs)
diff --git a/roms/u-boot/tools/buildman/test.py b/roms/u-boot/tools/buildman/test.py
new file mode 100644
index 00000000..068784a3
--- /dev/null
+++ b/roms/u-boot/tools/buildman/test.py
@@ -0,0 +1,169 @@
+#
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import os
+import shutil
+import sys
+import tempfile
+import time
+import unittest
+
+# Bring in the patman libraries
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(our_path, '../patman'))
+
+import board
+import bsettings
+import builder
+import control
+import command
+import commit
+import toolchain
+
+errors = [
+ '''main.c: In function 'main_loop':
+main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
+''',
+ '''main.c: In function 'main_loop':
+main.c:295:2: error: 'fred' undeclared (first use in this function)
+main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
+make[1]: *** [main.o] Error 1
+make: *** [common/libcommon.o] Error 2
+Make failed
+''',
+ '''main.c: In function 'main_loop':
+main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
+''',
+ '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
+powerpc-linux-ld: warning: dot moved backwards before `.bss'
+powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
+powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
+powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
+powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
+powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
+powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
+'''
+]
+
+
+# hash, subject, return code, list of errors/warnings
+commits = [
+ ['1234', 'upstream/master, ok', 0, []],
+ ['5678', 'Second commit, a warning', 0, errors[0:1]],
+ ['9012', 'Third commit, error', 1, errors[0:2]],
+ ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
+ ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
+ ['abcd', 'Sixth commit, fixes all errors', 0, []]
+]
+
+boards = [
+ ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
+ ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
+ ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
+ ['Active', 'powerpc', 'mpc5xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
+ ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
+]
+
+class Options:
+ """Class that holds build options"""
+ pass
+
+class TestBuild(unittest.TestCase):
+ """Test buildman
+
+ TODO: Write tests for the rest of the functionality
+ """
+ def setUp(self):
+ # Set up commits to build
+ self.commits = []
+ sequence = 0
+ for commit_info in commits:
+ comm = commit.Commit(commit_info[0])
+ comm.subject = commit_info[1]
+ comm.return_code = commit_info[2]
+ comm.error_list = commit_info[3]
+ comm.sequence = sequence
+ sequence += 1
+ self.commits.append(comm)
+
+ # Set up boards to build
+ self.boards = board.Boards()
+ for brd in boards:
+ self.boards.AddBoard(board.Board(*brd))
+ self.boards.SelectBoards([])
+
+ # Set up the toolchains
+ bsettings.Setup()
+ self.toolchains = toolchain.Toolchains()
+ self.toolchains.Add('arm-linux-gcc', test=False)
+ self.toolchains.Add('sparc-linux-gcc', test=False)
+ self.toolchains.Add('powerpc-linux-gcc', test=False)
+ self.toolchains.Add('gcc', test=False)
+
+ def Make(self, commit, brd, stage, *args, **kwargs):
+ result = command.CommandResult()
+ boardnum = int(brd.target[-1])
+ result.return_code = 0
+ result.stderr = ''
+ result.stdout = ('This is the test output for board %s, commit %s' %
+ (brd.target, commit.hash))
+ if boardnum >= 1 and boardnum >= commit.sequence:
+ result.return_code = commit.return_code
+ result.stderr = ''.join(commit.error_list)
+ if stage == 'build':
+ target_dir = None
+ for arg in args:
+ if arg.startswith('O='):
+ target_dir = arg[2:]
+
+ if not os.path.isdir(target_dir):
+ os.mkdir(target_dir)
+ #time.sleep(.2 + boardnum * .2)
+
+ result.combined = result.stdout + result.stderr
+ return result
+
+ def testBasic(self):
+ """Test basic builder operation"""
+ output_dir = tempfile.mkdtemp()
+ if not os.path.isdir(output_dir):
+ os.mkdir(output_dir)
+ build = builder.Builder(self.toolchains, output_dir, None, 1, 2,
+ checkout=False, show_unknown=False)
+ build.do_make = self.Make
+ board_selected = self.boards.GetSelectedDict()
+
+ #build.BuildCommits(self.commits, board_selected, False)
+ build.BuildBoards(self.commits, board_selected, False, False)
+ build.ShowSummary(self.commits, board_selected, True, False,
+ False, False)
+
+ def _testGit(self):
+ """Test basic builder operation by building a branch"""
+ base_dir = tempfile.mkdtemp()
+ if not os.path.isdir(base_dir):
+ os.mkdir(base_dir)
+ options = Options()
+ options.git = os.getcwd()
+ options.summary = False
+ options.jobs = None
+ options.dry_run = False
+ #options.git = os.path.join(base_dir, 'repo')
+ options.branch = 'test-buildman'
+ options.force_build = False
+ options.list_tool_chains = False
+ options.count = -1
+ options.git_dir = None
+ options.threads = None
+ options.show_unknown = False
+ options.quick = False
+ options.show_errors = False
+ options.keep_outputs = False
+ args = ['tegra20']
+ control.DoBuildman(options, args)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/roms/u-boot/tools/buildman/toolchain.py b/roms/u-boot/tools/buildman/toolchain.py
new file mode 100644
index 00000000..b6433868
--- /dev/null
+++ b/roms/u-boot/tools/buildman/toolchain.py
@@ -0,0 +1,247 @@
+# Copyright (c) 2012 The Chromium OS Authors.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+import re
+import glob
+import os
+
+import bsettings
+import command
+
+class Toolchain:
+ """A single toolchain
+
+ Public members:
+ gcc: Full path to C compiler
+ path: Directory path containing C compiler
+ cross: Cross compile string, e.g. 'arm-linux-'
+ arch: Architecture of toolchain as determined from the first
+ component of the filename. E.g. arm-linux-gcc becomes arm
+ """
+
+ def __init__(self, fname, test, verbose=False):
+ """Create a new toolchain object.
+
+ Args:
+ fname: Filename of the gcc component
+ test: True to run the toolchain to test it
+ """
+ self.gcc = fname
+ self.path = os.path.dirname(fname)
+ self.cross = os.path.basename(fname)[:-3]
+ pos = self.cross.find('-')
+ self.arch = self.cross[:pos] if pos != -1 else 'sandbox'
+
+ env = self.MakeEnvironment()
+
+ # As a basic sanity check, run the C compiler with --version
+ cmd = [fname, '--version']
+ if test:
+ result = command.RunPipe([cmd], capture=True, env=env,
+ raise_on_error=False)
+ self.ok = result.return_code == 0
+ if verbose:
+ print 'Tool chain test: ',
+ if self.ok:
+ print 'OK'
+ else:
+ print 'BAD'
+ print 'Command: ', cmd
+ print result.stdout
+ print result.stderr
+ else:
+ self.ok = True
+ self.priority = self.GetPriority(fname)
+
+ def GetPriority(self, fname):
+ """Return the priority of the toolchain.
+
+ Toolchains are ranked according to their suitability by their
+ filename prefix.
+
+ Args:
+ fname: Filename of toolchain
+ Returns:
+ Priority of toolchain, 0=highest, 20=lowest.
+ """
+ priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-elf',
+ '-none-linux-gnueabi', '-uclinux', '-none-eabi',
+ '-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux']
+ for prio in range(len(priority_list)):
+ if priority_list[prio] in fname:
+ return prio
+ return prio
+
+ def MakeEnvironment(self):
+ """Returns an environment for using the toolchain.
+
+ Thie takes the current environment, adds CROSS_COMPILE and
+ augments PATH so that the toolchain will operate correctly.
+ """
+ env = dict(os.environ)
+ env['CROSS_COMPILE'] = self.cross
+ env['PATH'] += (':' + self.path)
+ return env
+
+
+class Toolchains:
+ """Manage a list of toolchains for building U-Boot
+
+ We select one toolchain for each architecture type
+
+ Public members:
+ toolchains: Dict of Toolchain objects, keyed by architecture name
+ paths: List of paths to check for toolchains (may contain wildcards)
+ """
+
+ def __init__(self):
+ self.toolchains = {}
+ self.paths = []
+ toolchains = bsettings.GetItems('toolchain')
+ if not toolchains:
+ print ("Warning: No tool chains - please add a [toolchain] section"
+ " to your buildman config file %s. See README for details" %
+ config_fname)
+
+ for name, value in toolchains:
+ if '*' in value:
+ self.paths += glob.glob(value)
+ else:
+ self.paths.append(value)
+ self._make_flags = dict(bsettings.GetItems('make-flags'))
+
+ def Add(self, fname, test=True, verbose=False):
+ """Add a toolchain to our list
+
+ We select the given toolchain as our preferred one for its
+ architecture if it is a higher priority than the others.
+
+ Args:
+ fname: Filename of toolchain's gcc driver
+ test: True to run the toolchain to test it
+ """
+ toolchain = Toolchain(fname, test, verbose)
+ add_it = toolchain.ok
+ if toolchain.arch in self.toolchains:
+ add_it = (toolchain.priority <
+ self.toolchains[toolchain.arch].priority)
+ if add_it:
+ self.toolchains[toolchain.arch] = toolchain
+
+ def Scan(self, verbose):
+ """Scan for available toolchains and select the best for each arch.
+
+ We look for all the toolchains we can file, figure out the
+ architecture for each, and whether it works. Then we select the
+ highest priority toolchain for each arch.
+
+ Args:
+ verbose: True to print out progress information
+ """
+ if verbose: print 'Scanning for tool chains'
+ for path in self.paths:
+ if verbose: print " - scanning path '%s'" % path
+ for subdir in ['.', 'bin', 'usr/bin']:
+ dirname = os.path.join(path, subdir)
+ if verbose: print " - looking in '%s'" % dirname
+ for fname in glob.glob(dirname + '/*gcc'):
+ if verbose: print " - found '%s'" % fname
+ self.Add(fname, True, verbose)
+
+ def List(self):
+ """List out the selected toolchains for each architecture"""
+ print 'List of available toolchains (%d):' % len(self.toolchains)
+ if len(self.toolchains):
+ for key, value in sorted(self.toolchains.iteritems()):
+ print '%-10s: %s' % (key, value.gcc)
+ else:
+ print 'None'
+
+ def Select(self, arch):
+ """Returns the toolchain for a given architecture
+
+ Args:
+ args: Name of architecture (e.g. 'arm', 'ppc_8xx')
+
+ returns:
+ toolchain object, or None if none found
+ """
+ for name, value in bsettings.GetItems('toolchain-alias'):
+ if arch == name:
+ arch = value
+
+ if not arch in self.toolchains:
+ raise ValueError, ("No tool chain found for arch '%s'" % arch)
+ return self.toolchains[arch]
+
+ def ResolveReferences(self, var_dict, args):
+ """Resolve variable references in a string
+
+ This converts ${blah} within the string to the value of blah.
+ This function works recursively.
+
+ Args:
+ var_dict: Dictionary containing variables and their values
+ args: String containing make arguments
+ Returns:
+ Resolved string
+
+ >>> bsettings.Setup()
+ >>> tcs = Toolchains()
+ >>> tcs.Add('fred', False)
+ >>> var_dict = {'oblique' : 'OBLIQUE', 'first' : 'fi${second}rst', \
+ 'second' : '2nd'}
+ >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set')
+ 'this=OBLIQUE_set'
+ >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set${first}nd')
+ 'this=OBLIQUE_setfi2ndrstnd'
+ """
+ re_var = re.compile('(\$\{[a-z0-9A-Z]{1,}\})')
+
+ while True:
+ m = re_var.search(args)
+ if not m:
+ break
+ lookup = m.group(0)[2:-1]
+ value = var_dict.get(lookup, '')
+ args = args[:m.start(0)] + value + args[m.end(0):]
+ return args
+
+ def GetMakeArguments(self, board):
+ """Returns 'make' arguments for a given board
+
+ The flags are in a section called 'make-flags'. Flags are named
+ after the target they represent, for example snapper9260=TESTING=1
+ will pass TESTING=1 to make when building the snapper9260 board.
+
+ References to other boards can be added in the string also. For
+ example:
+
+ [make-flags]
+ at91-boards=ENABLE_AT91_TEST=1
+ snapper9260=${at91-boards} BUILD_TAG=442
+ snapper9g45=${at91-boards} BUILD_TAG=443
+
+ This will return 'ENABLE_AT91_TEST=1 BUILD_TAG=442' for snapper9260
+ and 'ENABLE_AT91_TEST=1 BUILD_TAG=443' for snapper9g45.
+
+ A special 'target' variable is set to the board target.
+
+ Args:
+ board: Board object for the board to check.
+ Returns:
+ 'make' flags for that board, or '' if none
+ """
+ self._make_flags['target'] = board.target
+ arg_str = self.ResolveReferences(self._make_flags,
+ self._make_flags.get(board.target, ''))
+ args = arg_str.split(' ')
+ i = 0
+ while i < len(args):
+ if not args[i]:
+ del args[i]
+ else:
+ i += 1
+ return args
diff --git a/roms/u-boot/tools/crc32.c b/roms/u-boot/tools/crc32.c
new file mode 100644
index 00000000..aed7112f
--- /dev/null
+++ b/roms/u-boot/tools/crc32.c
@@ -0,0 +1 @@
+#include "../lib/crc32.c"
diff --git a/roms/u-boot/tools/default_image.c b/roms/u-boot/tools/default_image.c
new file mode 100644
index 00000000..0a0792e5
--- /dev/null
+++ b/roms/u-boot/tools/default_image.c
@@ -0,0 +1,194 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd@denx.de
+ *
+ * Updated-by: Prafulla Wadaskar
+ * default_image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include
+#include
+
+static image_header_t header;
+
+static int image_check_image_types(uint8_t type)
+{
+ if (((type > IH_TYPE_INVALID) && (type < IH_TYPE_FLATDT)) ||
+ (type == IH_TYPE_KERNEL_NOLOAD))
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static int image_check_params(struct image_tool_params *params)
+{
+ return ((params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)));
+}
+
+static int image_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ uint32_t len;
+ const unsigned char *data;
+ uint32_t checksum;
+ image_header_t header;
+ image_header_t *hdr = &header;
+
+ /*
+ * create copy of header so that we can blank out the
+ * checksum field for checking - this can't be done
+ * on the PROT_READ mapped data.
+ */
+ memcpy(hdr, ptr, sizeof(image_header_t));
+
+ if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
+ fprintf(stderr,
+ "%s: Bad Magic Number: \"%s\" is no valid image\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADMAGIC;
+ }
+
+ data = (const unsigned char *)hdr;
+ len = sizeof(image_header_t);
+
+ checksum = be32_to_cpu(hdr->ih_hcrc);
+ hdr->ih_hcrc = cpu_to_be32(0); /* clear for re-calculation */
+
+ if (crc32(0, data, len) != checksum) {
+ fprintf(stderr,
+ "%s: ERROR: \"%s\" has bad header checksum!\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADSTATE;
+ }
+
+ data = (const unsigned char *)ptr + sizeof(image_header_t);
+ len = image_size - sizeof(image_header_t) ;
+
+ checksum = be32_to_cpu(hdr->ih_dcrc);
+ if (crc32(0, data, len) != checksum) {
+ fprintf(stderr,
+ "%s: ERROR: \"%s\" has corrupted data!\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADSTRUCTURE;
+ }
+ return 0;
+}
+
+static void image_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ uint32_t checksum;
+
+ image_header_t * hdr = (image_header_t *)ptr;
+
+ checksum = crc32(0,
+ (const unsigned char *)(ptr +
+ sizeof(image_header_t)),
+ sbuf->st_size - sizeof(image_header_t));
+
+ /* Build new header */
+ image_set_magic(hdr, IH_MAGIC);
+ image_set_time(hdr, sbuf->st_mtime);
+ image_set_size(hdr, sbuf->st_size - sizeof(image_header_t));
+ image_set_load(hdr, params->addr);
+ image_set_ep(hdr, params->ep);
+ image_set_dcrc(hdr, checksum);
+ image_set_os(hdr, params->os);
+ image_set_arch(hdr, params->arch);
+ image_set_type(hdr, params->type);
+ image_set_comp(hdr, params->comp);
+
+ image_set_name(hdr, params->imagename);
+
+ checksum = crc32(0, (const unsigned char *)hdr,
+ sizeof(image_header_t));
+
+ image_set_hcrc(hdr, checksum);
+}
+
+static int image_save_datafile(struct image_tool_params *params,
+ ulong file_data, ulong file_len)
+{
+ int dfd;
+ const char *datafile = params->outfile;
+
+ dfd = open(datafile, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
+ S_IRUSR | S_IWUSR);
+ if (dfd < 0) {
+ fprintf(stderr, "%s: Can't open \"%s\": %s\n",
+ params->cmdname, datafile, strerror(errno));
+ return -1;
+ }
+
+ if (write(dfd, (void *)file_data, file_len) != (ssize_t)file_len) {
+ fprintf(stderr, "%s: Write error on \"%s\": %s\n",
+ params->cmdname, datafile, strerror(errno));
+ close(dfd);
+ return -1;
+ }
+
+ close(dfd);
+
+ return 0;
+}
+
+static int image_extract_datafile(void *ptr, struct image_tool_params *params)
+{
+ const image_header_t *hdr = (const image_header_t *)ptr;
+ ulong file_data;
+ ulong file_len;
+
+ if (image_check_type(hdr, IH_TYPE_MULTI)) {
+ ulong idx = params->pflag;
+ ulong count;
+
+ /* get the number of data files present in the image */
+ count = image_multi_count(hdr);
+
+ /* retrieve the "data file" at the idx position */
+ image_multi_getimg(hdr, idx, &file_data, &file_len);
+
+ if ((file_len == 0) || (idx >= count)) {
+ fprintf(stderr, "%s: No such data file %ld in \"%s\"\n",
+ params->cmdname, idx, params->imagefile);
+ return -1;
+ }
+ } else {
+ file_data = image_get_data(hdr);
+ file_len = image_get_size(hdr);
+ }
+
+ /* save the "data file" into the file system */
+ return image_save_datafile(params, file_data, file_len);
+}
+
+/*
+ * Default image type parameters definition
+ */
+static struct image_type_params defimage_params = {
+ .name = "Default Image support",
+ .header_size = sizeof(image_header_t),
+ .hdr = (void*)&header,
+ .check_image_type = image_check_image_types,
+ .verify_header = image_verify_header,
+ .print_header = image_print_contents,
+ .set_header = image_set_header,
+ .extract_datafile = image_extract_datafile,
+ .check_params = image_check_params,
+};
+
+void init_default_image_type(void)
+{
+ register_image_type(&defimage_params);
+}
diff --git a/roms/u-boot/tools/dumpimage.c b/roms/u-boot/tools/dumpimage.c
new file mode 100644
index 00000000..542ee282
--- /dev/null
+++ b/roms/u-boot/tools/dumpimage.c
@@ -0,0 +1,305 @@
+/*
+ * Based on mkimage.c.
+ *
+ * Written by Guilherme Maciel Ferreira
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "dumpimage.h"
+#include
+#include
+
+static void usage(void);
+
+/* image_type_params linked list to maintain registered image types supports */
+static struct image_type_params *dumpimage_tparams;
+
+/* parameters initialized by core will be used by the image type code */
+static struct image_tool_params params = {
+ .type = IH_TYPE_KERNEL,
+};
+
+/**
+ * dumpimage_register() - register respective image generation/list support
+ *
+ * the input struct image_type_params is checked and appended to the link
+ * list, if the input structure is already registered, issue an error
+ *
+ * @tparams: Image type parameters
+ */
+static void dumpimage_register(struct image_type_params *tparams)
+{
+ struct image_type_params **tp;
+
+ if (!tparams) {
+ fprintf(stderr, "%s: %s: Null input\n", params.cmdname,
+ __func__);
+ exit(EXIT_FAILURE);
+ }
+
+ /* scan the linked list, check for registry and point the last one */
+ for (tp = &dumpimage_tparams; *tp != NULL; tp = &(*tp)->next) {
+ if (!strcmp((*tp)->name, tparams->name)) {
+ fprintf(stderr, "%s: %s already registered\n",
+ params.cmdname, tparams->name);
+ return;
+ }
+ }
+
+ /* add input struct entry at the end of link list */
+ *tp = tparams;
+ /* mark input entry as last entry in the link list */
+ tparams->next = NULL;
+
+ debug("Registered %s\n", tparams->name);
+}
+
+/**
+ * dumpimage_get_type() - find the image type params for a given image type
+ *
+ * Scan all registered image types and check the input type_id for each
+ * supported image type
+ *
+ * @return respective image_type_params pointer. If the input type is not
+ * supported by any of registered image types, returns NULL
+ */
+static struct image_type_params *dumpimage_get_type(int type)
+{
+ struct image_type_params *curr;
+
+ for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
+ if (curr->check_image_type) {
+ if (!curr->check_image_type(type))
+ return curr;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * dumpimage_verify_print_header() - verifies the image header
+ *
+ * Scan registered image types and verify the image_header for each
+ * supported image type. If verification is successful, this prints
+ * the respective header.
+ *
+ * @return 0 on success, negative if input image format does not match with
+ * any of supported image types
+ */
+static int dumpimage_verify_print_header(void *ptr, struct stat *sbuf)
+{
+ int retval = -1;
+ struct image_type_params *curr;
+
+ for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
+ if (curr->verify_header) {
+ retval = curr->verify_header((unsigned char *)ptr,
+ sbuf->st_size, ¶ms);
+ if (retval != 0)
+ continue;
+ /*
+ * Print the image information if verify is
+ * successful
+ */
+ if (curr->print_header) {
+ curr->print_header(ptr);
+ } else {
+ fprintf(stderr,
+ "%s: print_header undefined for %s\n",
+ params.cmdname, curr->name);
+ }
+ break;
+ }
+ }
+
+ return retval;
+}
+
+/*
+ * dumpimage_extract_datafile -
+ *
+ * It scans all registered image types,
+ * verifies image_header for each supported image type
+ * if verification is successful, it extracts the desired file,
+ * indexed by pflag, from the image
+ *
+ * returns negative if input image format does not match with any of
+ * supported image types
+ */
+static int dumpimage_extract_datafile(void *ptr, struct stat *sbuf)
+{
+ int retval = -1;
+ struct image_type_params *curr;
+
+ for (curr = dumpimage_tparams; curr != NULL; curr = curr->next) {
+ if (curr->verify_header) {
+ retval = curr->verify_header((unsigned char *)ptr,
+ sbuf->st_size, ¶ms);
+ if (retval != 0)
+ continue;
+ /*
+ * Extract the file from the image
+ * if verify is successful
+ */
+ if (curr->extract_datafile) {
+ curr->extract_datafile(ptr, ¶ms);
+ } else {
+ fprintf(stderr,
+ "%s: extract_datafile undefined for %s\n",
+ params.cmdname, curr->name);
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
+
+int main(int argc, char **argv)
+{
+ int opt;
+ int ifd = -1;
+ struct stat sbuf;
+ char *ptr;
+ int retval = 0;
+ struct image_type_params *tparams = NULL;
+
+ /* Init all image generation/list support */
+ register_image_tool(dumpimage_register);
+
+ params.cmdname = *argv;
+
+ while ((opt = getopt(argc, argv, "li:o:p:V")) != -1) {
+ switch (opt) {
+ case 'l':
+ params.lflag = 1;
+ break;
+ case 'i':
+ params.imagefile = optarg;
+ params.iflag = 1;
+ break;
+ case 'o':
+ params.outfile = optarg;
+ break;
+ case 'p':
+ params.pflag = strtoul(optarg, &ptr, 10);
+ if (*ptr) {
+ fprintf(stderr,
+ "%s: invalid file position %s\n",
+ params.cmdname, *argv);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'V':
+ printf("dumpimage version %s\n", PLAIN_VERSION);
+ exit(EXIT_SUCCESS);
+ default:
+ usage();
+ }
+ }
+
+ if (optind >= argc)
+ usage();
+
+ /* set tparams as per input type_id */
+ tparams = dumpimage_get_type(params.type);
+ if (tparams == NULL) {
+ fprintf(stderr, "%s: unsupported type %s\n",
+ params.cmdname, genimg_get_type_name(params.type));
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * check the passed arguments parameters meets the requirements
+ * as per image type to be generated/listed
+ */
+ if (tparams->check_params) {
+ if (tparams->check_params(¶ms))
+ usage();
+ }
+
+ if (params.iflag)
+ params.datafile = argv[optind];
+ else
+ params.imagefile = argv[optind];
+ if (!params.outfile)
+ params.outfile = params.datafile;
+
+ ifd = open(params.imagefile, O_RDONLY|O_BINARY);
+ if (ifd < 0) {
+ fprintf(stderr, "%s: Can't open \"%s\": %s\n",
+ params.cmdname, params.imagefile,
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (params.lflag || params.iflag) {
+ if (fstat(ifd, &sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat \"%s\": %s\n",
+ params.cmdname, params.imagefile,
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if ((unsigned)sbuf.st_size < tparams->header_size) {
+ fprintf(stderr,
+ "%s: Bad size: \"%s\" is not valid image\n",
+ params.cmdname, params.imagefile);
+ exit(EXIT_FAILURE);
+ }
+
+ ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0);
+ if (ptr == MAP_FAILED) {
+ fprintf(stderr, "%s: Can't read \"%s\": %s\n",
+ params.cmdname, params.imagefile,
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Both calls bellow scan through dumpimage registry for all
+ * supported image types and verify the input image file
+ * header for match
+ */
+ if (params.iflag) {
+ /*
+ * Extract the data files from within the matched
+ * image type. Returns the error code if not matched
+ */
+ retval = dumpimage_extract_datafile(ptr, &sbuf);
+ } else {
+ /*
+ * Print the image information for matched image type
+ * Returns the error code if not matched
+ */
+ retval = dumpimage_verify_print_header(ptr, &sbuf);
+ }
+
+ (void)munmap((void *)ptr, sbuf.st_size);
+ (void)close(ifd);
+
+ return retval;
+ }
+
+ (void)close(ifd);
+
+ return EXIT_SUCCESS;
+}
+
+static void usage(void)
+{
+ fprintf(stderr, "Usage: %s -l image\n"
+ " -l ==> list image header information\n",
+ params.cmdname);
+ fprintf(stderr,
+ " %s -i image [-p position] [-o outfile] data_file\n"
+ " -i ==> extract from the 'image' a specific 'data_file'"
+ ", indexed by 'position' (starting at 0)\n",
+ params.cmdname);
+ fprintf(stderr,
+ " %s -V ==> print version information and exit\n",
+ params.cmdname);
+
+ exit(EXIT_FAILURE);
+}
diff --git a/roms/u-boot/tools/dumpimage.h b/roms/u-boot/tools/dumpimage.h
new file mode 100644
index 00000000..d78523de
--- /dev/null
+++ b/roms/u-boot/tools/dumpimage.h
@@ -0,0 +1,33 @@
+/*
+ * Based on mkimage.c.
+ *
+ * Written by Guilherme Maciel Ferreira
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DUMPIMAGE_H_
+#define _DUMPIMAGE_H_
+
+#include "os_support.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "fdt_host.h"
+#include "imagetool.h"
+
+#undef DUMPIMAGE_DEBUG
+
+#ifdef DUMPIMAGE_DEBUG
+#define debug(fmt, args...) printf(fmt, ##args)
+#else
+#define debug(fmt, args...)
+#endif /* DUMPIMAGE_DEBUG */
+
+#endif /* _DUMPIMAGE_H_ */
diff --git a/roms/u-boot/tools/easylogo/Makefile b/roms/u-boot/tools/easylogo/Makefile
new file mode 100644
index 00000000..10aba2ba
--- /dev/null
+++ b/roms/u-boot/tools/easylogo/Makefile
@@ -0,0 +1,3 @@
+hostprogs-y := easylogo
+
+always := $(hostprogs-y)
diff --git a/roms/u-boot/tools/easylogo/easylogo.c b/roms/u-boot/tools/easylogo/easylogo.c
new file mode 100644
index 00000000..4ba86bf7
--- /dev/null
+++ b/roms/u-boot/tools/easylogo/easylogo.c
@@ -0,0 +1,610 @@
+/*
+** Easylogo TGA->header converter
+** ==============================
+** (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
+** AIRVENT SAM s.p.a - RIMINI(ITALY)
+** (C) 2007-2008 Mike Frysinger
+**
+** This is still under construction!
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#pragma pack(1)
+
+/*#define ENABLE_ASCII_BANNERS */
+
+typedef struct {
+ unsigned char id;
+ unsigned char ColorMapType;
+ unsigned char ImageTypeCode;
+ unsigned short ColorMapOrigin;
+ unsigned short ColorMapLenght;
+ unsigned char ColorMapEntrySize;
+ unsigned short ImageXOrigin;
+ unsigned short ImageYOrigin;
+ unsigned short ImageWidth;
+ unsigned short ImageHeight;
+ unsigned char ImagePixelSize;
+ unsigned char ImageDescriptorByte;
+} tga_header_t;
+
+typedef struct {
+ unsigned char r, g, b;
+} rgb_t;
+
+typedef struct {
+ unsigned char b, g, r;
+} bgr_t;
+
+typedef struct {
+ unsigned char Cb, y1, Cr, y2;
+} yuyv_t;
+
+typedef struct {
+ void *data, *palette;
+ int width, height, pixels, bpp, pixel_size, size, palette_size, yuyv;
+} image_t;
+
+void *xmalloc (size_t size)
+{
+ void *ret = malloc (size);
+ if (!ret) {
+ fprintf (stderr, "\nerror: malloc(%zu) failed: %s",
+ size, strerror(errno));
+ exit (1);
+ }
+ return ret;
+}
+
+void StringUpperCase (char *str)
+{
+ int count = strlen (str);
+ char c;
+
+ while (count--) {
+ c = *str;
+ if ((c >= 'a') && (c <= 'z'))
+ *str = 'A' + (c - 'a');
+ str++;
+ }
+}
+
+void StringLowerCase (char *str)
+{
+ int count = strlen (str);
+ char c;
+
+ while (count--) {
+ c = *str;
+ if ((c >= 'A') && (c <= 'Z'))
+ *str = 'a' + (c - 'A');
+ str++;
+ }
+}
+void pixel_rgb_to_yuyv (rgb_t * rgb_pixel, yuyv_t * yuyv_pixel)
+{
+ unsigned int pR, pG, pB;
+
+ /* Transform (0-255) components to (0-100) */
+ pR = rgb_pixel->r * 100 / 255;
+ pG = rgb_pixel->g * 100 / 255;
+ pB = rgb_pixel->b * 100 / 255;
+
+ /* Calculate YUV values (0-255) from RGB beetween 0-100 */
+ yuyv_pixel->y1 = yuyv_pixel->y2 = 209 * (pR + pG + pB) / 300 + 16;
+ yuyv_pixel->Cb = pB - (pR / 4) - (pG * 3 / 4) + 128;
+ yuyv_pixel->Cr = pR - (pG * 3 / 4) - (pB / 4) + 128;
+
+ return;
+}
+
+void printlogo_rgb (rgb_t * data, int w, int h)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, data++)
+ if ((data->r <
+ 30) /*&&(data->g == 0)&&(data->b == 0) */ )
+ printf (" ");
+ else
+ printf ("X");
+ printf ("\n");
+ }
+}
+
+void printlogo_yuyv (unsigned short *data, int w, int h)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, data++)
+ if (*data == 0x1080) /* Because of inverted on i386! */
+ printf (" ");
+ else
+ printf ("X");
+ printf ("\n");
+ }
+}
+
+static inline unsigned short le16_to_cpu (unsigned short val)
+{
+ union {
+ unsigned char pval[2];
+ unsigned short val;
+ } swapped;
+
+ swapped.val = val;
+ return (swapped.pval[1] << 8) + swapped.pval[0];
+}
+
+int image_load_tga (image_t * image, char *filename)
+{
+ FILE *file;
+ tga_header_t header;
+ int i;
+ unsigned char app;
+ rgb_t *p;
+
+ if ((file = fopen (filename, "rb")) == NULL)
+ return -1;
+
+ fread (&header, sizeof (header), 1, file);
+
+ /* byte swap: tga is little endian, host is ??? */
+ header.ColorMapOrigin = le16_to_cpu (header.ColorMapOrigin);
+ header.ColorMapLenght = le16_to_cpu (header.ColorMapLenght);
+ header.ImageXOrigin = le16_to_cpu (header.ImageXOrigin);
+ header.ImageYOrigin = le16_to_cpu (header.ImageYOrigin);
+ header.ImageWidth = le16_to_cpu (header.ImageWidth);
+ header.ImageHeight = le16_to_cpu (header.ImageHeight);
+
+ image->width = header.ImageWidth;
+ image->height = header.ImageHeight;
+
+ switch (header.ImageTypeCode) {
+ case 2: /* Uncompressed RGB */
+ image->yuyv = 0;
+ image->palette_size = 0;
+ image->palette = NULL;
+ break;
+
+ default:
+ printf ("Format not supported!\n");
+ return -1;
+ }
+
+ image->bpp = header.ImagePixelSize;
+ image->pixel_size = ((image->bpp - 1) / 8) + 1;
+ image->pixels = image->width * image->height;
+ image->size = image->pixels * image->pixel_size;
+ image->data = xmalloc (image->size);
+
+ if (image->bpp != 24) {
+ printf ("Bpp not supported: %d!\n", image->bpp);
+ return -1;
+ }
+
+ fread (image->data, image->size, 1, file);
+
+/* Swapping R and B values */
+
+ p = image->data;
+ for (i = 0; i < image->pixels; i++, p++) {
+ app = p->r;
+ p->r = p->b;
+ p->b = app;
+ }
+
+/* Swapping image */
+
+ if (!(header.ImageDescriptorByte & 0x20)) {
+ unsigned char *temp = xmalloc (image->size);
+ int linesize = image->pixel_size * image->width;
+ void *dest = image->data,
+ *source = temp + image->size - linesize;
+
+ printf ("S");
+ if (temp == NULL) {
+ printf ("Cannot alloc temp buffer!\n");
+ return -1;
+ }
+
+ memcpy (temp, image->data, image->size);
+ for (i = 0; i < image->height;
+ i++, dest += linesize, source -= linesize)
+ memcpy (dest, source, linesize);
+
+ free (temp);
+ }
+#ifdef ENABLE_ASCII_BANNERS
+ printlogo_rgb (image->data, image->width, image->height);
+#endif
+
+ fclose (file);
+ return 0;
+}
+
+void image_free (image_t * image)
+{
+ free (image->data);
+ free (image->palette);
+}
+
+int image_rgb_to_yuyv (image_t * rgb_image, image_t * yuyv_image)
+{
+ rgb_t *rgb_ptr = (rgb_t *) rgb_image->data;
+ yuyv_t yuyv;
+ unsigned short *dest;
+ int count = 0;
+
+ yuyv_image->pixel_size = 2;
+ yuyv_image->bpp = 16;
+ yuyv_image->yuyv = 1;
+ yuyv_image->width = rgb_image->width;
+ yuyv_image->height = rgb_image->height;
+ yuyv_image->pixels = yuyv_image->width * yuyv_image->height;
+ yuyv_image->size = yuyv_image->pixels * yuyv_image->pixel_size;
+ dest = (unsigned short *) (yuyv_image->data =
+ xmalloc (yuyv_image->size));
+ yuyv_image->palette = 0;
+ yuyv_image->palette_size = 0;
+
+ while ((count++) < rgb_image->pixels) {
+ pixel_rgb_to_yuyv (rgb_ptr++, &yuyv);
+
+ if ((count & 1) == 0) /* Was == 0 */
+ memcpy (dest, ((void *) &yuyv) + 2, sizeof (short));
+ else
+ memcpy (dest, (void *) &yuyv, sizeof (short));
+
+ dest++;
+ }
+
+#ifdef ENABLE_ASCII_BANNERS
+ printlogo_yuyv (yuyv_image->data, yuyv_image->width,
+ yuyv_image->height);
+#endif
+ return 0;
+}
+
+int image_rgb888_to_rgb565(image_t *rgb888_image, image_t *rgb565_image)
+{
+ rgb_t *rgb_ptr = (rgb_t *) rgb888_image->data;
+ unsigned short *dest;
+ int count = 0;
+
+ rgb565_image->pixel_size = 2;
+ rgb565_image->bpp = 16;
+ rgb565_image->yuyv = 0;
+ rgb565_image->width = rgb888_image->width;
+ rgb565_image->height = rgb888_image->height;
+ rgb565_image->pixels = rgb565_image->width * rgb565_image->height;
+ rgb565_image->size = rgb565_image->pixels * rgb565_image->pixel_size;
+ dest = (unsigned short *) (rgb565_image->data =
+ xmalloc(rgb565_image->size));
+ rgb565_image->palette = 0;
+ rgb565_image->palette_size = 0;
+
+ while ((count++) < rgb888_image->pixels) {
+
+ *dest++ = ((rgb_ptr->b & 0xF8) << 8) |
+ ((rgb_ptr->g & 0xFC) << 3) |
+ (rgb_ptr->r >> 3);
+ rgb_ptr++;
+ }
+
+ return 0;
+}
+
+enum comp_t {
+ COMP_NONE,
+ COMP_GZIP,
+ COMP_LZMA,
+};
+static enum comp_t compression = COMP_NONE;
+static bool bss_storage = false;
+
+int image_save_header (image_t * image, char *filename, char *varname)
+{
+ FILE *file = fopen (filename, "w");
+ char app[256], str[256] = "", def_name[64];
+ int count = image->size, col = 0;
+ unsigned char *dataptr = image->data;
+
+ if (file == NULL)
+ return -1;
+
+ /* Author information */
+ fprintf (file,
+ "/*\n * Generated by EasyLogo, (C) 2000 by Paolo Scaffardi\n *\n");
+ fprintf (file,
+ " * To use this, include it and call: easylogo_plot(screen,&%s, width,x,y)\n *\n",
+ varname);
+ fprintf (file,
+ " * Where:\t'screen'\tis the pointer to the frame buffer\n");
+ fprintf (file, " *\t\t'width'\tis the screen width\n");
+ fprintf (file, " *\t\t'x'\t\tis the horizontal position\n");
+ fprintf (file, " *\t\t'y'\t\tis the vertical position\n */\n\n");
+
+ /* image compress */
+ if (compression != COMP_NONE) {
+ const char *errstr = NULL;
+ unsigned char *compressed;
+ const char *comp_name;
+ struct stat st;
+ FILE *compfp;
+ size_t filename_len = strlen(filename);
+ char *compfilename = xmalloc(filename_len + 20);
+ char *compcmd = xmalloc(filename_len + 50);
+
+ sprintf(compfilename, "%s.bin", filename);
+ switch (compression) {
+ case COMP_GZIP:
+ strcpy(compcmd, "gzip");
+ comp_name = "GZIP";
+ break;
+ case COMP_LZMA:
+ strcpy(compcmd, "lzma");
+ comp_name = "LZMA";
+ break;
+ default:
+ errstr = "\nerror: unknown compression method";
+ goto done;
+ }
+ strcat(compcmd, " > ");
+ strcat(compcmd, compfilename);
+ compfp = popen(compcmd, "w");
+ if (!compfp) {
+ errstr = "\nerror: popen() failed";
+ goto done;
+ }
+ if (fwrite(image->data, image->size, 1, compfp) != 1) {
+ errstr = "\nerror: writing data to gzip failed";
+ goto done;
+ }
+ if (pclose(compfp)) {
+ errstr = "\nerror: gzip process failed";
+ goto done;
+ }
+
+ compfp = fopen(compfilename, "r");
+ if (!compfp) {
+ errstr = "\nerror: open() on gzip data failed";
+ goto done;
+ }
+ if (stat(compfilename, &st)) {
+ errstr = "\nerror: stat() on gzip file failed";
+ goto done;
+ }
+ compressed = xmalloc(st.st_size);
+ if (fread(compressed, st.st_size, 1, compfp) != 1) {
+ errstr = "\nerror: reading gzip data failed";
+ goto done;
+ }
+ fclose(compfp);
+
+ unlink(compfilename);
+
+ dataptr = compressed;
+ count = st.st_size;
+ fprintf(file, "#define EASYLOGO_ENABLE_%s %i\n\n", comp_name, count);
+ if (bss_storage)
+ fprintf (file, "static unsigned char EASYLOGO_DECOMP_BUFFER[%i];\n\n", image->size);
+
+ done:
+ free(compfilename);
+ free(compcmd);
+
+ if (errstr) {
+ perror (errstr);
+ return -1;
+ }
+ }
+
+ /* Headers */
+ fprintf (file, "#include \n\n");
+ /* Macros */
+ strcpy (def_name, varname);
+ StringUpperCase (def_name);
+ fprintf (file, "#define DEF_%s_WIDTH\t\t%d\n", def_name,
+ image->width);
+ fprintf (file, "#define DEF_%s_HEIGHT\t\t%d\n", def_name,
+ image->height);
+ fprintf (file, "#define DEF_%s_PIXELS\t\t%d\n", def_name,
+ image->pixels);
+ fprintf (file, "#define DEF_%s_BPP\t\t%d\n", def_name, image->bpp);
+ fprintf (file, "#define DEF_%s_PIXEL_SIZE\t%d\n", def_name,
+ image->pixel_size);
+ fprintf (file, "#define DEF_%s_SIZE\t\t%d\n\n", def_name,
+ image->size);
+ /* Declaration */
+ fprintf (file, "unsigned char DEF_%s_DATA[] = {\n",
+ def_name);
+
+ /* Data */
+ while (count)
+ switch (col) {
+ case 0:
+ sprintf (str, " 0x%02x", *dataptr++);
+ col++;
+ count--;
+ break;
+
+ case 16:
+ fprintf (file, "%s", str);
+ if (count > 0)
+ fprintf (file, ",");
+ fprintf (file, "\n");
+
+ col = 0;
+ break;
+
+ default:
+ strcpy (app, str);
+ sprintf (str, "%s, 0x%02x", app, *dataptr++);
+ col++;
+ count--;
+ break;
+ }
+
+ if (col)
+ fprintf (file, "%s\n", str);
+
+ /* End of declaration */
+ fprintf (file, "};\n\n");
+ /* Variable */
+ fprintf (file, "fastimage_t %s = {\n", varname);
+ fprintf (file, " DEF_%s_DATA,\n", def_name);
+ fprintf (file, " DEF_%s_WIDTH,\n", def_name);
+ fprintf (file, " DEF_%s_HEIGHT,\n", def_name);
+ fprintf (file, " DEF_%s_BPP,\n", def_name);
+ fprintf (file, " DEF_%s_PIXEL_SIZE,\n", def_name);
+ fprintf (file, " DEF_%s_SIZE\n};\n", def_name);
+
+ fclose (file);
+
+ return 0;
+}
+
+#define DEF_FILELEN 256
+
+static void usage (int exit_status)
+{
+ puts (
+ "EasyLogo 1.0 (C) 2000 by Paolo Scaffardi\n"
+ "\n"
+ "Syntax: easylogo [options] inputfile [outputvar [outputfile]]\n"
+ "\n"
+ "Options:\n"
+ " -r Output RGB888 instead of YUYV\n"
+ " -s Output RGB565 instead of YUYV\n"
+ " -g Compress with gzip\n"
+ " -l Compress with lzma\n"
+ " -b Preallocate space in bss for decompressing image\n"
+ " -h Help output\n"
+ "\n"
+ "Where: 'inputfile' is the TGA image to load\n"
+ " 'outputvar' is the variable name to create\n"
+ " 'outputfile' is the output header file (default is 'inputfile.h')"
+ );
+ exit (exit_status);
+}
+
+int main (int argc, char *argv[])
+{
+ int c;
+ bool use_rgb888 = false;
+ bool use_rgb565 = false;
+ char inputfile[DEF_FILELEN],
+ outputfile[DEF_FILELEN], varname[DEF_FILELEN];
+
+ image_t rgb888_logo, rgb565_logo, yuyv_logo;
+
+ while ((c = getopt(argc, argv, "hrsglb")) > 0) {
+ switch (c) {
+ case 'h':
+ usage (0);
+ break;
+ case 'r':
+ use_rgb888 = true;
+ puts("Using 24-bit RGB888 Output Fromat");
+ break;
+ case 's':
+ use_rgb565 = true;
+ puts("Using 16-bit RGB565 Output Fromat");
+ break;
+ case 'g':
+ compression = COMP_GZIP;
+ puts("Compressing with gzip");
+ break;
+ case 'l':
+ compression = COMP_LZMA;
+ puts("Compressing with lzma");
+ break;
+ case 'b':
+ bss_storage = true;
+ puts("Preallocating bss space for decompressing image");
+ break;
+ default:
+ usage (1);
+ break;
+ }
+ }
+
+ c = argc - optind;
+ if (c > 4 || c < 1)
+ usage (1);
+
+ strcpy (inputfile, argv[optind]);
+
+ if (c > 1)
+ strcpy (varname, argv[optind + 1]);
+ else {
+ /* transform "input.tga" to just "input" */
+ char *dot;
+ strcpy (varname, inputfile);
+ dot = strchr (varname, '.');
+ if (dot)
+ *dot = '\0';
+ }
+
+ if (c > 2)
+ strcpy (outputfile, argv[optind + 2]);
+ else {
+ /* just append ".h" to input file name */
+ strcpy (outputfile, inputfile);
+ strcat (outputfile, ".h");
+ }
+
+ /* Make sure the output is sent as soon as we printf() */
+ setbuf(stdout, NULL);
+
+ printf ("Doing '%s' (%s) from '%s'...",
+ outputfile, varname, inputfile);
+
+ /* Import TGA logo */
+
+ printf ("L");
+ if (image_load_tga(&rgb888_logo, inputfile) < 0) {
+ printf ("input file not found!\n");
+ exit (1);
+ }
+
+ /* Convert, save, and free the image */
+
+ if (!use_rgb888 && !use_rgb565) {
+ printf ("C");
+ image_rgb_to_yuyv(&rgb888_logo, &yuyv_logo);
+
+ printf("S");
+ image_save_header(&yuyv_logo, outputfile, varname);
+ image_free(&yuyv_logo);
+ } else if (use_rgb565) {
+ printf("C");
+ image_rgb888_to_rgb565(&rgb888_logo, &rgb565_logo);
+
+ printf("S");
+ image_save_header(&rgb565_logo, outputfile, varname);
+ image_free(&rgb565_logo);
+ } else {
+ printf("S");
+ image_save_header(&rgb888_logo, outputfile, varname);
+ }
+
+ /* Free original image and copy */
+
+ image_free(&rgb888_logo);
+
+ printf ("\n");
+
+ return 0;
+}
diff --git a/roms/u-boot/tools/easylogo/linux_blackfin.tga b/roms/u-boot/tools/easylogo/linux_blackfin.tga
new file mode 100644
index 00000000..e2bb17b8
Binary files /dev/null and b/roms/u-boot/tools/easylogo/linux_blackfin.tga differ
diff --git a/roms/u-boot/tools/easylogo/linux_logo.tga b/roms/u-boot/tools/easylogo/linux_logo.tga
new file mode 100644
index 00000000..ac53def0
Binary files /dev/null and b/roms/u-boot/tools/easylogo/linux_logo.tga differ
diff --git a/roms/u-boot/tools/easylogo/runme.sh b/roms/u-boot/tools/easylogo/runme.sh
new file mode 100644
index 00000000..625ebaae
--- /dev/null
+++ b/roms/u-boot/tools/easylogo/runme.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+make
+./easylogo linux_logo.tga u_boot_logo video_logo.h
+mv video_logo.h ../../include
diff --git a/roms/u-boot/tools/env/.gitignore b/roms/u-boot/tools/env/.gitignore
new file mode 100644
index 00000000..804abacc
--- /dev/null
+++ b/roms/u-boot/tools/env/.gitignore
@@ -0,0 +1,2 @@
+fw_printenv
+fw_printenv_unstripped
diff --git a/roms/u-boot/tools/env/Makefile b/roms/u-boot/tools/env/Makefile
new file mode 100644
index 00000000..f5368bc4
--- /dev/null
+++ b/roms/u-boot/tools/env/Makefile
@@ -0,0 +1,34 @@
+#
+# (C) Copyright 2002-2006
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+# fw_printenv is supposed to run on the target system, which means it should be
+# built with cross tools. Although it may look weird, we only replace "HOSTCC"
+# with "CC" here for the maximum code reuse of scripts/Makefile.host.
+HOSTCC = $(CC)
+
+# Compile for a hosted environment on the target
+HOST_EXTRACFLAGS = $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \
+ -idirafter $(srctree)/tools/env \
+ -DUSE_HOSTCC \
+ -DTEXT_BASE=$(TEXT_BASE)
+
+ifeq ($(MTD_VERSION),old)
+HOST_EXTRACFLAGS += -DMTD_OLD
+endif
+
+always := fw_printenv
+hostprogs-y := fw_printenv_unstripped
+
+fw_printenv_unstripped-objs := fw_env.o fw_env_main.o \
+ crc32.o ctype.o linux_string.o \
+ env_attr.o env_flags.o aes.o
+
+quiet_cmd_strip = STRIP $@
+ cmd_strip = $(STRIP) -o $@ $<
+
+$(obj)/fw_printenv: $(obj)/fw_printenv_unstripped FORCE
+ $(call if_changed,strip)
diff --git a/roms/u-boot/tools/env/README b/roms/u-boot/tools/env/README
new file mode 100644
index 00000000..24e31bc9
--- /dev/null
+++ b/roms/u-boot/tools/env/README
@@ -0,0 +1,60 @@
+
+This is a demo implementation of a Linux command line tool to access
+the U-Boot's environment variables.
+
+In order to cross-compile fw_printenv, run
+ make CROSS_COMPILE= env
+in the root directory of the U-Boot distribution. For example,
+ make CROSS_COMPILE=arm-linux- env
+
+For the run-time utility configuration uncomment the line
+#define CONFIG_FILE "/etc/fw_env.config"
+in fw_env.h.
+
+For building against older versions of the MTD headers (meaning before
+v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to
+make.
+
+See comments in the fw_env.config file for definitions for the
+particular board.
+
+Configuration can also be done via #defines in the fw_env.h file. The
+following lines are relevant:
+
+#define HAVE_REDUND /* For systems with 2 env sectors */
+#define DEVICE1_NAME "/dev/mtd1"
+#define DEVICE2_NAME "/dev/mtd2"
+#define DEVICE1_OFFSET 0x0000
+#define ENV1_SIZE 0x4000
+#define DEVICE1_ESIZE 0x4000
+#define DEVICE1_ENVSECTORS 2
+#define DEVICE2_OFFSET 0x0000
+#define ENV2_SIZE 0x4000
+#define DEVICE2_ESIZE 0x4000
+#define DEVICE2_ENVSECTORS 2
+
+Un-define HAVE_REDUND, if you want to use the utilities on a system
+that does not have support for redundant environment enabled.
+If HAVE_REDUND is undefined, DEVICE2_NAME is ignored,
+as is ENV2_SIZE and DEVICE2_ESIZE.
+
+The DEVICEx_NAME constants define which MTD character devices are to
+be used to access the environment.
+
+The DEVICEx_OFFSET constants define the environment offset within the
+MTD character device.
+
+ENVx_SIZE defines the size in bytes taken by the environment, which
+may be less then flash sector size, if the environment takes less
+then 1 sector.
+
+DEVICEx_ESIZE defines the size of the first sector in the flash
+partition where the environment resides.
+
+DEVICEx_ENVSECTORS defines the number of sectors that may be used for
+this environment instance. On NAND this is used to limit the range
+within which bad blocks are skipped, on NOR it is not used.
+
+To prevent losing changes to the environment and to prevent confusing the MTD
+drivers, a lock file at /var/lock/fw_printenv.lock is used to serialize access
+to the environment.
diff --git a/roms/u-boot/tools/env/aes.c b/roms/u-boot/tools/env/aes.c
new file mode 100644
index 00000000..9e42679e
--- /dev/null
+++ b/roms/u-boot/tools/env/aes.c
@@ -0,0 +1 @@
+#include "../../lib/aes.c"
diff --git a/roms/u-boot/tools/env/crc32.c b/roms/u-boot/tools/env/crc32.c
new file mode 100644
index 00000000..34f8178e
--- /dev/null
+++ b/roms/u-boot/tools/env/crc32.c
@@ -0,0 +1 @@
+#include "../../lib/crc32.c"
diff --git a/roms/u-boot/tools/env/ctype.c b/roms/u-boot/tools/env/ctype.c
new file mode 100644
index 00000000..21050e93
--- /dev/null
+++ b/roms/u-boot/tools/env/ctype.c
@@ -0,0 +1 @@
+#include "../../lib/ctype.c"
diff --git a/roms/u-boot/tools/env/env_attr.c b/roms/u-boot/tools/env/env_attr.c
new file mode 100644
index 00000000..502d4c90
--- /dev/null
+++ b/roms/u-boot/tools/env/env_attr.c
@@ -0,0 +1 @@
+#include "../../common/env_attr.c"
diff --git a/roms/u-boot/tools/env/env_flags.c b/roms/u-boot/tools/env/env_flags.c
new file mode 100644
index 00000000..b261cb8e
--- /dev/null
+++ b/roms/u-boot/tools/env/env_flags.c
@@ -0,0 +1 @@
+#include "../../common/env_flags.c"
diff --git a/roms/u-boot/tools/env/fw_env.c b/roms/u-boot/tools/env/fw_env.c
new file mode 100644
index 00000000..30d5b037
--- /dev/null
+++ b/roms/u-boot/tools/env/fw_env.c
@@ -0,0 +1,1467 @@
+/*
+ * (C) Copyright 2000-2010
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2008
+ * Guennadi Liakhovetski, DENX Software Engineering, lg@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifdef MTD_OLD
+# include
+# include
+#else
+# define __user /* nothing */
+# include
+#endif
+
+#include "fw_env.h"
+
+#include
+
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#define WHITESPACE(c) ((c == '\t') || (c == ' '))
+
+#define min(x, y) ({ \
+ typeof(x) _min1 = (x); \
+ typeof(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+
+struct envdev_s {
+ const char *devname; /* Device name */
+ ulong devoff; /* Device offset */
+ ulong env_size; /* environment size */
+ ulong erase_size; /* device erase size */
+ ulong env_sectors; /* number of environment sectors */
+ uint8_t mtd_type; /* type of the MTD device */
+};
+
+static struct envdev_s envdevices[2] =
+{
+ {
+ .mtd_type = MTD_ABSENT,
+ }, {
+ .mtd_type = MTD_ABSENT,
+ },
+};
+static int dev_current;
+
+#define DEVNAME(i) envdevices[(i)].devname
+#define DEVOFFSET(i) envdevices[(i)].devoff
+#define ENVSIZE(i) envdevices[(i)].env_size
+#define DEVESIZE(i) envdevices[(i)].erase_size
+#define ENVSECTORS(i) envdevices[(i)].env_sectors
+#define DEVTYPE(i) envdevices[(i)].mtd_type
+
+#define CUR_ENVSIZE ENVSIZE(dev_current)
+
+#define ENV_SIZE getenvsize()
+
+struct env_image_single {
+ uint32_t crc; /* CRC32 over data bytes */
+ char data[];
+};
+
+struct env_image_redundant {
+ uint32_t crc; /* CRC32 over data bytes */
+ unsigned char flags; /* active or obsolete */
+ char data[];
+};
+
+enum flag_scheme {
+ FLAG_NONE,
+ FLAG_BOOLEAN,
+ FLAG_INCREMENTAL,
+};
+
+struct environment {
+ void *image;
+ uint32_t *crc;
+ unsigned char *flags;
+ char *data;
+ enum flag_scheme flag_scheme;
+};
+
+static struct environment environment = {
+ .flag_scheme = FLAG_NONE,
+};
+
+/* Is AES encryption used? */
+static int aes_flag;
+static uint8_t aes_key[AES_KEY_LENGTH] = { 0 };
+static int env_aes_cbc_crypt(char *data, const int enc);
+
+static int HaveRedundEnv = 0;
+
+static unsigned char active_flag = 1;
+/* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
+static unsigned char obsolete_flag = 0;
+
+#define DEFAULT_ENV_INSTANCE_STATIC
+#include
+
+static int flash_io (int mode);
+static char *envmatch (char * s1, char * s2);
+static int parse_config (void);
+
+#if defined(CONFIG_FILE)
+static int get_config (char *);
+#endif
+static inline ulong getenvsize (void)
+{
+ ulong rc = CUR_ENVSIZE - sizeof(long);
+
+ if (HaveRedundEnv)
+ rc -= sizeof (char);
+
+ if (aes_flag)
+ rc &= ~(AES_KEY_LENGTH - 1);
+
+ return rc;
+}
+
+static char *fw_string_blank(char *s, int noblank)
+{
+ int i;
+ int len = strlen(s);
+
+ for (i = 0; i < len; i++, s++) {
+ if ((noblank && !WHITESPACE(*s)) ||
+ (!noblank && WHITESPACE(*s)))
+ break;
+ }
+ if (i == len)
+ return NULL;
+
+ return s;
+}
+
+/*
+ * Search the environment for a variable.
+ * Return the value, if found, or NULL, if not found.
+ */
+char *fw_getenv (char *name)
+{
+ char *env, *nxt;
+
+ for (env = environment.data; *env; env = nxt + 1) {
+ char *val;
+
+ for (nxt = env; *nxt; ++nxt) {
+ if (nxt >= &environment.data[ENV_SIZE]) {
+ fprintf (stderr, "## Error: "
+ "environment not terminated\n");
+ return NULL;
+ }
+ }
+ val = envmatch (name, env);
+ if (!val)
+ continue;
+ return val;
+ }
+ return NULL;
+}
+
+/*
+ * Search the default environment for a variable.
+ * Return the value, if found, or NULL, if not found.
+ */
+char *fw_getdefenv(char *name)
+{
+ char *env, *nxt;
+
+ for (env = default_environment; *env; env = nxt + 1) {
+ char *val;
+
+ for (nxt = env; *nxt; ++nxt) {
+ if (nxt >= &default_environment[ENV_SIZE]) {
+ fprintf(stderr, "## Error: "
+ "default environment not terminated\n");
+ return NULL;
+ }
+ }
+ val = envmatch(name, env);
+ if (!val)
+ continue;
+ return val;
+ }
+ return NULL;
+}
+
+static int parse_aes_key(char *key)
+{
+ char tmp[5] = { '0', 'x', 0, 0, 0 };
+ unsigned long ul;
+ int i;
+
+ if (strnlen(key, 64) != 32) {
+ fprintf(stderr,
+ "## Error: '-a' option requires 16-byte AES key\n");
+ return -1;
+ }
+
+ for (i = 0; i < 16; i++) {
+ tmp[2] = key[0];
+ tmp[3] = key[1];
+ errno = 0;
+ ul = strtoul(tmp, NULL, 16);
+ if (errno) {
+ fprintf(stderr,
+ "## Error: '-a' option requires valid AES key\n");
+ return -1;
+ }
+ aes_key[i] = ul & 0xff;
+ key += 2;
+ }
+ aes_flag = 1;
+
+ return 0;
+}
+
+/*
+ * Print the current definition of one, or more, or all
+ * environment variables
+ */
+int fw_printenv (int argc, char *argv[])
+{
+ char *env, *nxt;
+ int i, n_flag;
+ int rc = 0;
+
+ if (argc >= 2 && strcmp(argv[1], "-a") == 0) {
+ if (argc < 3) {
+ fprintf(stderr,
+ "## Error: '-a' option requires AES key\n");
+ return -1;
+ }
+ rc = parse_aes_key(argv[2]);
+ if (rc)
+ return rc;
+ argv += 2;
+ argc -= 2;
+ }
+
+ if (fw_env_open())
+ return -1;
+
+ if (argc == 1) { /* Print all env variables */
+ for (env = environment.data; *env; env = nxt + 1) {
+ for (nxt = env; *nxt; ++nxt) {
+ if (nxt >= &environment.data[ENV_SIZE]) {
+ fprintf (stderr, "## Error: "
+ "environment not terminated\n");
+ return -1;
+ }
+ }
+
+ printf ("%s\n", env);
+ }
+ return 0;
+ }
+
+ if (strcmp (argv[1], "-n") == 0) {
+ n_flag = 1;
+ ++argv;
+ --argc;
+ if (argc != 2) {
+ fprintf (stderr, "## Error: "
+ "`-n' option requires exactly one argument\n");
+ return -1;
+ }
+ } else {
+ n_flag = 0;
+ }
+
+ for (i = 1; i < argc; ++i) { /* print single env variables */
+ char *name = argv[i];
+ char *val = NULL;
+
+ for (env = environment.data; *env; env = nxt + 1) {
+
+ for (nxt = env; *nxt; ++nxt) {
+ if (nxt >= &environment.data[ENV_SIZE]) {
+ fprintf (stderr, "## Error: "
+ "environment not terminated\n");
+ return -1;
+ }
+ }
+ val = envmatch (name, env);
+ if (val) {
+ if (!n_flag) {
+ fputs (name, stdout);
+ putc ('=', stdout);
+ }
+ puts (val);
+ break;
+ }
+ }
+ if (!val) {
+ fprintf (stderr, "## Error: \"%s\" not defined\n", name);
+ rc = -1;
+ }
+ }
+
+ return rc;
+}
+
+int fw_env_close(void)
+{
+ int ret;
+ if (aes_flag) {
+ ret = env_aes_cbc_crypt(environment.data, 1);
+ if (ret) {
+ fprintf(stderr,
+ "Error: can't encrypt env for flash\n");
+ return ret;
+ }
+ }
+
+ /*
+ * Update CRC
+ */
+ *environment.crc = crc32(0, (uint8_t *) environment.data, ENV_SIZE);
+
+ /* write environment back to flash */
+ if (flash_io(O_RDWR)) {
+ fprintf(stderr,
+ "Error: can't write fw_env to flash\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/*
+ * Set/Clear a single variable in the environment.
+ * This is called in sequence to update the environment
+ * in RAM without updating the copy in flash after each set
+ */
+int fw_env_write(char *name, char *value)
+{
+ int len;
+ char *env, *nxt;
+ char *oldval = NULL;
+ int deleting, creating, overwriting;
+
+ /*
+ * search if variable with this name already exists
+ */
+ for (nxt = env = environment.data; *env; env = nxt + 1) {
+ for (nxt = env; *nxt; ++nxt) {
+ if (nxt >= &environment.data[ENV_SIZE]) {
+ fprintf(stderr, "## Error: "
+ "environment not terminated\n");
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ if ((oldval = envmatch (name, env)) != NULL)
+ break;
+ }
+
+ deleting = (oldval && !(value && strlen(value)));
+ creating = (!oldval && (value && strlen(value)));
+ overwriting = (oldval && (value && strlen(value)));
+
+ /* check for permission */
+ if (deleting) {
+ if (env_flags_validate_varaccess(name,
+ ENV_FLAGS_VARACCESS_PREVENT_DELETE)) {
+ printf("Can't delete \"%s\"\n", name);
+ errno = EROFS;
+ return -1;
+ }
+ } else if (overwriting) {
+ if (env_flags_validate_varaccess(name,
+ ENV_FLAGS_VARACCESS_PREVENT_OVERWR)) {
+ printf("Can't overwrite \"%s\"\n", name);
+ errno = EROFS;
+ return -1;
+ } else if (env_flags_validate_varaccess(name,
+ ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR)) {
+ const char *defval = fw_getdefenv(name);
+
+ if (defval == NULL)
+ defval = "";
+ if (strcmp(oldval, defval)
+ != 0) {
+ printf("Can't overwrite \"%s\"\n", name);
+ errno = EROFS;
+ return -1;
+ }
+ }
+ } else if (creating) {
+ if (env_flags_validate_varaccess(name,
+ ENV_FLAGS_VARACCESS_PREVENT_CREATE)) {
+ printf("Can't create \"%s\"\n", name);
+ errno = EROFS;
+ return -1;
+ }
+ } else
+ /* Nothing to do */
+ return 0;
+
+ if (deleting || overwriting) {
+ if (*++nxt == '\0') {
+ *env = '\0';
+ } else {
+ for (;;) {
+ *env = *nxt++;
+ if ((*env == '\0') && (*nxt == '\0'))
+ break;
+ ++env;
+ }
+ }
+ *++env = '\0';
+ }
+
+ /* Delete only ? */
+ if (!value || !strlen(value))
+ return 0;
+
+ /*
+ * Append new definition at the end
+ */
+ for (env = environment.data; *env || *(env + 1); ++env);
+ if (env > environment.data)
+ ++env;
+ /*
+ * Overflow when:
+ * "name" + "=" + "val" +"\0\0" > CUR_ENVSIZE - (env-environment)
+ */
+ len = strlen (name) + 2;
+ /* add '=' for first arg, ' ' for all others */
+ len += strlen(value) + 1;
+
+ if (len > (&environment.data[ENV_SIZE] - env)) {
+ fprintf (stderr,
+ "Error: environment overflow, \"%s\" deleted\n",
+ name);
+ return -1;
+ }
+
+ while ((*env = *name++) != '\0')
+ env++;
+ *env = '=';
+ while ((*++env = *value++) != '\0')
+ ;
+
+ /* end is marked with double '\0' */
+ *++env = '\0';
+
+ return 0;
+}
+
+/*
+ * Deletes or sets environment variables. Returns -1 and sets errno error codes:
+ * 0 - OK
+ * EINVAL - need at least 1 argument
+ * EROFS - certain variables ("ethaddr", "serial#") cannot be
+ * modified or deleted
+ *
+ */
+int fw_setenv(int argc, char *argv[])
+{
+ int i, rc;
+ size_t len;
+ char *name;
+ char *value = NULL;
+
+ if (argc < 2) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (strcmp(argv[1], "-a") == 0) {
+ if (argc < 3) {
+ fprintf(stderr,
+ "## Error: '-a' option requires AES key\n");
+ return -1;
+ }
+ rc = parse_aes_key(argv[2]);
+ if (rc)
+ return rc;
+ argv += 2;
+ argc -= 2;
+ }
+
+ if (argc < 2) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (fw_env_open()) {
+ fprintf(stderr, "Error: environment not initialized\n");
+ return -1;
+ }
+
+ name = argv[1];
+
+ if (env_flags_validate_env_set_params(argc, argv) < 0)
+ return 1;
+
+ len = 0;
+ for (i = 2; i < argc; ++i) {
+ char *val = argv[i];
+ size_t val_len = strlen(val);
+
+ if (value)
+ value[len - 1] = ' ';
+ value = realloc(value, len + val_len + 1);
+ if (!value) {
+ fprintf(stderr,
+ "Cannot malloc %zu bytes: %s\n",
+ len, strerror(errno));
+ return -1;
+ }
+
+ memcpy(value + len, val, val_len);
+ len += val_len;
+ value[len++] = '\0';
+ }
+
+ fw_env_write(name, value);
+
+ free(value);
+
+ return fw_env_close();
+}
+
+/*
+ * Parse a file and configure the u-boot variables.
+ * The script file has a very simple format, as follows:
+ *
+ * Each line has a couple with name, value:
+ * variable_namevariable_value
+ *
+ * Both variable_name and variable_value are interpreted as strings.
+ * Any character after and before ending \r\n is interpreted
+ * as variable's value (no comment allowed on these lines !)
+ *
+ * Comments are allowed if the first character in the line is #
+ *
+ * Returns -1 and sets errno error codes:
+ * 0 - OK
+ * -1 - Error
+ */
+int fw_parse_script(char *fname)
+{
+ FILE *fp;
+ char dump[1024]; /* Maximum line length in the file */
+ char *name;
+ char *val;
+ int lineno = 0;
+ int len;
+ int ret = 0;
+
+ if (fw_env_open()) {
+ fprintf(stderr, "Error: environment not initialized\n");
+ return -1;
+ }
+
+ if (strcmp(fname, "-") == 0)
+ fp = stdin;
+ else {
+ fp = fopen(fname, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "I cannot open %s for reading\n",
+ fname);
+ return -1;
+ }
+ }
+
+ while (fgets(dump, sizeof(dump), fp)) {
+ lineno++;
+ len = strlen(dump);
+
+ /*
+ * Read a whole line from the file. If the line is too long
+ * or is not terminated, reports an error and exit.
+ */
+ if (dump[len - 1] != '\n') {
+ fprintf(stderr,
+ "Line %d not corrected terminated or too long\n",
+ lineno);
+ ret = -1;
+ break;
+ }
+
+ /* Drop ending line feed / carriage return */
+ while (len > 0 && (dump[len - 1] == '\n' ||
+ dump[len - 1] == '\r')) {
+ dump[len - 1] = '\0';
+ len--;
+ }
+
+ /* Skip comment or empty lines */
+ if ((len == 0) || dump[0] == '#')
+ continue;
+
+ /*
+ * Search for variable's name,
+ * remove leading whitespaces
+ */
+ name = fw_string_blank(dump, 1);
+ if (!name)
+ continue;
+
+ /* The first white space is the end of variable name */
+ val = fw_string_blank(name, 0);
+ len = strlen(name);
+ if (val) {
+ *val++ = '\0';
+ if ((val - name) < len)
+ val = fw_string_blank(val, 1);
+ else
+ val = NULL;
+ }
+
+#ifdef DEBUG
+ fprintf(stderr, "Setting %s : %s\n",
+ name, val ? val : " removed");
+#endif
+
+ if (env_flags_validate_type(name, val) < 0) {
+ ret = -1;
+ break;
+ }
+
+ /*
+ * If there is an error setting a variable,
+ * try to save the environment and returns an error
+ */
+ if (fw_env_write(name, val)) {
+ fprintf(stderr,
+ "fw_env_write returns with error : %s\n",
+ strerror(errno));
+ ret = -1;
+ break;
+ }
+
+ }
+
+ /* Close file if not stdin */
+ if (strcmp(fname, "-") != 0)
+ fclose(fp);
+
+ ret |= fw_env_close();
+
+ return ret;
+
+}
+
+/*
+ * Test for bad block on NAND, just returns 0 on NOR, on NAND:
+ * 0 - block is good
+ * > 0 - block is bad
+ * < 0 - failed to test
+ */
+static int flash_bad_block (int fd, uint8_t mtd_type, loff_t *blockstart)
+{
+ if (mtd_type == MTD_NANDFLASH) {
+ int badblock = ioctl (fd, MEMGETBADBLOCK, blockstart);
+
+ if (badblock < 0) {
+ perror ("Cannot read bad block mark");
+ return badblock;
+ }
+
+ if (badblock) {
+#ifdef DEBUG
+ fprintf (stderr, "Bad block at 0x%llx, "
+ "skipping\n", *blockstart);
+#endif
+ return badblock;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Read data from flash at an offset into a provided buffer. On NAND it skips
+ * bad blocks but makes sure it stays within ENVSECTORS (dev) starting from
+ * the DEVOFFSET (dev) block. On NOR the loop is only run once.
+ */
+static int flash_read_buf (int dev, int fd, void *buf, size_t count,
+ off_t offset, uint8_t mtd_type)
+{
+ size_t blocklen; /* erase / write length - one block on NAND,
+ 0 on NOR */
+ size_t processed = 0; /* progress counter */
+ size_t readlen = count; /* current read length */
+ off_t top_of_range; /* end of the last block we may use */
+ off_t block_seek; /* offset inside the current block to the start
+ of the data */
+ loff_t blockstart; /* running start of the current block -
+ MEMGETBADBLOCK needs 64 bits */
+ int rc;
+
+ blockstart = (offset / DEVESIZE (dev)) * DEVESIZE (dev);
+
+ /* Offset inside a block */
+ block_seek = offset - blockstart;
+
+ if (mtd_type == MTD_NANDFLASH) {
+ /*
+ * NAND: calculate which blocks we are reading. We have
+ * to read one block at a time to skip bad blocks.
+ */
+ blocklen = DEVESIZE (dev);
+
+ /*
+ * To calculate the top of the range, we have to use the
+ * global DEVOFFSET (dev), which can be different from offset
+ */
+ top_of_range = ((DEVOFFSET(dev) / blocklen) +
+ ENVSECTORS (dev)) * blocklen;
+
+ /* Limit to one block for the first read */
+ if (readlen > blocklen - block_seek)
+ readlen = blocklen - block_seek;
+ } else {
+ blocklen = 0;
+ top_of_range = offset + count;
+ }
+
+ /* This only runs once on NOR flash */
+ while (processed < count) {
+ rc = flash_bad_block (fd, mtd_type, &blockstart);
+ if (rc < 0) /* block test failed */
+ return -1;
+
+ if (blockstart + block_seek + readlen > top_of_range) {
+ /* End of range is reached */
+ fprintf (stderr,
+ "Too few good blocks within range\n");
+ return -1;
+ }
+
+ if (rc) { /* block is bad */
+ blockstart += blocklen;
+ continue;
+ }
+
+ /*
+ * If a block is bad, we retry in the next block at the same
+ * offset - see common/env_nand.c::writeenv()
+ */
+ lseek (fd, blockstart + block_seek, SEEK_SET);
+
+ rc = read (fd, buf + processed, readlen);
+ if (rc != readlen) {
+ fprintf (stderr, "Read error on %s: %s\n",
+ DEVNAME (dev), strerror (errno));
+ return -1;
+ }
+#ifdef DEBUG
+ fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n",
+ rc, blockstart + block_seek, DEVNAME(dev));
+#endif
+ processed += readlen;
+ readlen = min (blocklen, count - processed);
+ block_seek = 0;
+ blockstart += blocklen;
+ }
+
+ return processed;
+}
+
+/*
+ * Write count bytes at offset, but stay within ENVSECTORS (dev) sectors of
+ * DEVOFFSET (dev). Similar to the read case above, on NOR and dataflash we
+ * erase and write the whole data at once.
+ */
+static int flash_write_buf (int dev, int fd, void *buf, size_t count,
+ off_t offset, uint8_t mtd_type)
+{
+ void *data;
+ struct erase_info_user erase;
+ size_t blocklen; /* length of NAND block / NOR erase sector */
+ size_t erase_len; /* whole area that can be erased - may include
+ bad blocks */
+ size_t erasesize; /* erase / write length - one block on NAND,
+ whole area on NOR */
+ size_t processed = 0; /* progress counter */
+ size_t write_total; /* total size to actually write - excluding
+ bad blocks */
+ off_t erase_offset; /* offset to the first erase block (aligned)
+ below offset */
+ off_t block_seek; /* offset inside the erase block to the start
+ of the data */
+ off_t top_of_range; /* end of the last block we may use */
+ loff_t blockstart; /* running start of the current block -
+ MEMGETBADBLOCK needs 64 bits */
+ int rc;
+
+ /*
+ * For mtd devices only offset and size of the environment do matter
+ */
+ if (mtd_type == MTD_ABSENT) {
+ blocklen = count;
+ top_of_range = offset + count;
+ erase_len = blocklen;
+ blockstart = offset;
+ block_seek = 0;
+ write_total = blocklen;
+ } else {
+ blocklen = DEVESIZE(dev);
+
+ top_of_range = ((DEVOFFSET(dev) / blocklen) +
+ ENVSECTORS(dev)) * blocklen;
+
+ erase_offset = (offset / blocklen) * blocklen;
+
+ /* Maximum area we may use */
+ erase_len = top_of_range - erase_offset;
+
+ blockstart = erase_offset;
+ /* Offset inside a block */
+ block_seek = offset - erase_offset;
+
+ /*
+ * Data size we actually write: from the start of the block
+ * to the start of the data, then count bytes of data, and
+ * to the end of the block
+ */
+ write_total = ((block_seek + count + blocklen - 1) /
+ blocklen) * blocklen;
+ }
+
+ /*
+ * Support data anywhere within erase sectors: read out the complete
+ * area to be erased, replace the environment image, write the whole
+ * block back again.
+ */
+ if (write_total > count) {
+ data = malloc (erase_len);
+ if (!data) {
+ fprintf (stderr,
+ "Cannot malloc %zu bytes: %s\n",
+ erase_len, strerror (errno));
+ return -1;
+ }
+
+ rc = flash_read_buf (dev, fd, data, write_total, erase_offset,
+ mtd_type);
+ if (write_total != rc)
+ return -1;
+
+#ifdef DEBUG
+ fprintf(stderr, "Preserving data ");
+ if (block_seek != 0)
+ fprintf(stderr, "0x%x - 0x%lx", 0, block_seek - 1);
+ if (block_seek + count != write_total) {
+ if (block_seek != 0)
+ fprintf(stderr, " and ");
+ fprintf(stderr, "0x%lx - 0x%x",
+ block_seek + count, write_total - 1);
+ }
+ fprintf(stderr, "\n");
+#endif
+ /* Overwrite the old environment */
+ memcpy (data + block_seek, buf, count);
+ } else {
+ /*
+ * We get here, iff offset is block-aligned and count is a
+ * multiple of blocklen - see write_total calculation above
+ */
+ data = buf;
+ }
+
+ if (mtd_type == MTD_NANDFLASH) {
+ /*
+ * NAND: calculate which blocks we are writing. We have
+ * to write one block at a time to skip bad blocks.
+ */
+ erasesize = blocklen;
+ } else {
+ erasesize = erase_len;
+ }
+
+ erase.length = erasesize;
+
+ /* This only runs once on NOR flash and SPI-dataflash */
+ while (processed < write_total) {
+ rc = flash_bad_block (fd, mtd_type, &blockstart);
+ if (rc < 0) /* block test failed */
+ return rc;
+
+ if (blockstart + erasesize > top_of_range) {
+ fprintf (stderr, "End of range reached, aborting\n");
+ return -1;
+ }
+
+ if (rc) { /* block is bad */
+ blockstart += blocklen;
+ continue;
+ }
+
+ if (mtd_type != MTD_ABSENT) {
+ erase.start = blockstart;
+ ioctl(fd, MEMUNLOCK, &erase);
+ /* These do not need an explicit erase cycle */
+ if (mtd_type != MTD_DATAFLASH)
+ if (ioctl(fd, MEMERASE, &erase) != 0) {
+ fprintf(stderr,
+ "MTD erase error on %s: %s\n",
+ DEVNAME(dev), strerror(errno));
+ return -1;
+ }
+ }
+
+ if (lseek (fd, blockstart, SEEK_SET) == -1) {
+ fprintf (stderr,
+ "Seek error on %s: %s\n",
+ DEVNAME (dev), strerror (errno));
+ return -1;
+ }
+
+#ifdef DEBUG
+ fprintf(stderr, "Write 0x%x bytes at 0x%llx\n", erasesize,
+ blockstart);
+#endif
+ if (write (fd, data + processed, erasesize) != erasesize) {
+ fprintf (stderr, "Write error on %s: %s\n",
+ DEVNAME (dev), strerror (errno));
+ return -1;
+ }
+
+ if (mtd_type != MTD_ABSENT)
+ ioctl(fd, MEMLOCK, &erase);
+
+ processed += erasesize;
+ block_seek = 0;
+ blockstart += erasesize;
+ }
+
+ if (write_total > count)
+ free (data);
+
+ return processed;
+}
+
+/*
+ * Set obsolete flag at offset - NOR flash only
+ */
+static int flash_flag_obsolete (int dev, int fd, off_t offset)
+{
+ int rc;
+ struct erase_info_user erase;
+
+ erase.start = DEVOFFSET (dev);
+ erase.length = DEVESIZE (dev);
+ /* This relies on the fact, that obsolete_flag == 0 */
+ rc = lseek (fd, offset, SEEK_SET);
+ if (rc < 0) {
+ fprintf (stderr, "Cannot seek to set the flag on %s \n",
+ DEVNAME (dev));
+ return rc;
+ }
+ ioctl (fd, MEMUNLOCK, &erase);
+ rc = write (fd, &obsolete_flag, sizeof (obsolete_flag));
+ ioctl (fd, MEMLOCK, &erase);
+ if (rc < 0)
+ perror ("Could not set obsolete flag");
+
+ return rc;
+}
+
+/* Encrypt or decrypt the environment before writing or reading it. */
+static int env_aes_cbc_crypt(char *payload, const int enc)
+{
+ uint8_t *data = (uint8_t *)payload;
+ const int len = getenvsize();
+ uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
+ uint32_t aes_blocks;
+
+ /* First we expand the key. */
+ aes_expand_key(aes_key, 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, data, data, aes_blocks);
+ else
+ aes_cbc_decrypt_blocks(key_exp, data, data, aes_blocks);
+
+ return 0;
+}
+
+static int flash_write (int fd_current, int fd_target, int dev_target)
+{
+ int rc;
+
+ switch (environment.flag_scheme) {
+ case FLAG_NONE:
+ break;
+ case FLAG_INCREMENTAL:
+ (*environment.flags)++;
+ break;
+ case FLAG_BOOLEAN:
+ *environment.flags = active_flag;
+ break;
+ default:
+ fprintf (stderr, "Unimplemented flash scheme %u \n",
+ environment.flag_scheme);
+ return -1;
+ }
+
+#ifdef DEBUG
+ fprintf(stderr, "Writing new environment at 0x%lx on %s\n",
+ DEVOFFSET (dev_target), DEVNAME (dev_target));
+#endif
+
+ rc = flash_write_buf(dev_target, fd_target, environment.image,
+ CUR_ENVSIZE, DEVOFFSET(dev_target),
+ DEVTYPE(dev_target));
+ if (rc < 0)
+ return rc;
+
+ if (environment.flag_scheme == FLAG_BOOLEAN) {
+ /* Have to set obsolete flag */
+ off_t offset = DEVOFFSET (dev_current) +
+ offsetof (struct env_image_redundant, flags);
+#ifdef DEBUG
+ fprintf(stderr,
+ "Setting obsolete flag in environment at 0x%lx on %s\n",
+ DEVOFFSET (dev_current), DEVNAME (dev_current));
+#endif
+ flash_flag_obsolete (dev_current, fd_current, offset);
+ }
+
+ return 0;
+}
+
+static int flash_read (int fd)
+{
+ struct mtd_info_user mtdinfo;
+ struct stat st;
+ int rc;
+
+ rc = fstat(fd, &st);
+ if (rc < 0) {
+ fprintf(stderr, "Cannot stat the file %s\n",
+ DEVNAME(dev_current));
+ return -1;
+ }
+
+ if (S_ISCHR(st.st_mode)) {
+ rc = ioctl(fd, MEMGETINFO, &mtdinfo);
+ if (rc < 0) {
+ fprintf(stderr, "Cannot get MTD information for %s\n",
+ DEVNAME(dev_current));
+ return -1;
+ }
+ if (mtdinfo.type != MTD_NORFLASH &&
+ mtdinfo.type != MTD_NANDFLASH &&
+ mtdinfo.type != MTD_DATAFLASH &&
+ mtdinfo.type != MTD_UBIVOLUME) {
+ fprintf (stderr, "Unsupported flash type %u on %s\n",
+ mtdinfo.type, DEVNAME(dev_current));
+ return -1;
+ }
+ } else {
+ memset(&mtdinfo, 0, sizeof(mtdinfo));
+ mtdinfo.type = MTD_ABSENT;
+ }
+
+ DEVTYPE(dev_current) = mtdinfo.type;
+
+ rc = flash_read_buf(dev_current, fd, environment.image, CUR_ENVSIZE,
+ DEVOFFSET (dev_current), mtdinfo.type);
+ if (rc != CUR_ENVSIZE)
+ return -1;
+
+ return 0;
+}
+
+static int flash_io (int mode)
+{
+ int fd_current, fd_target, rc, dev_target;
+
+ /* dev_current: fd_current, erase_current */
+ fd_current = open (DEVNAME (dev_current), mode);
+ if (fd_current < 0) {
+ fprintf (stderr,
+ "Can't open %s: %s\n",
+ DEVNAME (dev_current), strerror (errno));
+ return -1;
+ }
+
+ if (mode == O_RDWR) {
+ if (HaveRedundEnv) {
+ /* switch to next partition for writing */
+ dev_target = !dev_current;
+ /* dev_target: fd_target, erase_target */
+ fd_target = open (DEVNAME (dev_target), mode);
+ if (fd_target < 0) {
+ fprintf (stderr,
+ "Can't open %s: %s\n",
+ DEVNAME (dev_target),
+ strerror (errno));
+ rc = -1;
+ goto exit;
+ }
+ } else {
+ dev_target = dev_current;
+ fd_target = fd_current;
+ }
+
+ rc = flash_write (fd_current, fd_target, dev_target);
+
+ if (HaveRedundEnv) {
+ if (close (fd_target)) {
+ fprintf (stderr,
+ "I/O error on %s: %s\n",
+ DEVNAME (dev_target),
+ strerror (errno));
+ rc = -1;
+ }
+ }
+ } else {
+ rc = flash_read (fd_current);
+ }
+
+exit:
+ if (close (fd_current)) {
+ fprintf (stderr,
+ "I/O error on %s: %s\n",
+ DEVNAME (dev_current), strerror (errno));
+ return -1;
+ }
+
+ return rc;
+}
+
+/*
+ * s1 is either a simple 'name', or a 'name=value' pair.
+ * s2 is a 'name=value' pair.
+ * If the names match, return the value of s2, else NULL.
+ */
+
+static char *envmatch (char * s1, char * s2)
+{
+ if (s1 == NULL || s2 == NULL)
+ return NULL;
+
+ while (*s1 == *s2++)
+ if (*s1++ == '=')
+ return s2;
+ if (*s1 == '\0' && *(s2 - 1) == '=')
+ return s2;
+ return NULL;
+}
+
+/*
+ * Prevent confusion if running from erased flash memory
+ */
+int fw_env_open(void)
+{
+ int crc0, crc0_ok;
+ unsigned char flag0;
+ void *addr0;
+
+ int crc1, crc1_ok;
+ unsigned char flag1;
+ void *addr1;
+
+ int ret;
+
+ struct env_image_single *single;
+ struct env_image_redundant *redundant;
+
+ if (parse_config ()) /* should fill envdevices */
+ return -1;
+
+ addr0 = calloc(1, CUR_ENVSIZE);
+ if (addr0 == NULL) {
+ fprintf(stderr,
+ "Not enough memory for environment (%ld bytes)\n",
+ CUR_ENVSIZE);
+ return -1;
+ }
+
+ /* read environment from FLASH to local buffer */
+ environment.image = addr0;
+
+ if (HaveRedundEnv) {
+ redundant = addr0;
+ environment.crc = &redundant->crc;
+ environment.flags = &redundant->flags;
+ environment.data = redundant->data;
+ } else {
+ single = addr0;
+ environment.crc = &single->crc;
+ environment.flags = NULL;
+ environment.data = single->data;
+ }
+
+ dev_current = 0;
+ if (flash_io (O_RDONLY))
+ return -1;
+
+ crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
+
+ if (aes_flag) {
+ ret = env_aes_cbc_crypt(environment.data, 0);
+ if (ret)
+ return ret;
+ }
+
+ crc0_ok = (crc0 == *environment.crc);
+ if (!HaveRedundEnv) {
+ if (!crc0_ok) {
+ fprintf (stderr,
+ "Warning: Bad CRC, using default environment\n");
+ memcpy(environment.data, default_environment, sizeof default_environment);
+ }
+ } else {
+ flag0 = *environment.flags;
+
+ dev_current = 1;
+ addr1 = calloc(1, CUR_ENVSIZE);
+ if (addr1 == NULL) {
+ fprintf(stderr,
+ "Not enough memory for environment (%ld bytes)\n",
+ CUR_ENVSIZE);
+ return -1;
+ }
+ redundant = addr1;
+
+ /*
+ * have to set environment.image for flash_read(), careful -
+ * other pointers in environment still point inside addr0
+ */
+ environment.image = addr1;
+ if (flash_io (O_RDONLY))
+ return -1;
+
+ /* Check flag scheme compatibility */
+ if (DEVTYPE(dev_current) == MTD_NORFLASH &&
+ DEVTYPE(!dev_current) == MTD_NORFLASH) {
+ environment.flag_scheme = FLAG_BOOLEAN;
+ } else if (DEVTYPE(dev_current) == MTD_NANDFLASH &&
+ DEVTYPE(!dev_current) == MTD_NANDFLASH) {
+ environment.flag_scheme = FLAG_INCREMENTAL;
+ } else if (DEVTYPE(dev_current) == MTD_DATAFLASH &&
+ DEVTYPE(!dev_current) == MTD_DATAFLASH) {
+ environment.flag_scheme = FLAG_BOOLEAN;
+ } else if (DEVTYPE(dev_current) == MTD_UBIVOLUME &&
+ DEVTYPE(!dev_current) == MTD_UBIVOLUME) {
+ environment.flag_scheme = FLAG_INCREMENTAL;
+ } else if (DEVTYPE(dev_current) == MTD_ABSENT &&
+ DEVTYPE(!dev_current) == MTD_ABSENT) {
+ environment.flag_scheme = FLAG_INCREMENTAL;
+ } else {
+ fprintf (stderr, "Incompatible flash types!\n");
+ return -1;
+ }
+
+ crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE);
+
+ if (aes_flag) {
+ ret = env_aes_cbc_crypt(redundant->data, 0);
+ if (ret)
+ return ret;
+ }
+
+ crc1_ok = (crc1 == redundant->crc);
+ flag1 = redundant->flags;
+
+ if (crc0_ok && !crc1_ok) {
+ dev_current = 0;
+ } else if (!crc0_ok && crc1_ok) {
+ dev_current = 1;
+ } else if (!crc0_ok && !crc1_ok) {
+ fprintf (stderr,
+ "Warning: Bad CRC, using default environment\n");
+ memcpy (environment.data, default_environment,
+ sizeof default_environment);
+ dev_current = 0;
+ } else {
+ switch (environment.flag_scheme) {
+ case FLAG_BOOLEAN:
+ if (flag0 == active_flag &&
+ flag1 == obsolete_flag) {
+ dev_current = 0;
+ } else if (flag0 == obsolete_flag &&
+ flag1 == active_flag) {
+ dev_current = 1;
+ } else if (flag0 == flag1) {
+ dev_current = 0;
+ } else if (flag0 == 0xFF) {
+ dev_current = 0;
+ } else if (flag1 == 0xFF) {
+ dev_current = 1;
+ } else {
+ dev_current = 0;
+ }
+ break;
+ case FLAG_INCREMENTAL:
+ if (flag0 == 255 && flag1 == 0)
+ dev_current = 1;
+ else if ((flag1 == 255 && flag0 == 0) ||
+ flag0 >= flag1)
+ dev_current = 0;
+ else /* flag1 > flag0 */
+ dev_current = 1;
+ break;
+ default:
+ fprintf (stderr, "Unknown flag scheme %u \n",
+ environment.flag_scheme);
+ return -1;
+ }
+ }
+
+ /*
+ * If we are reading, we don't need the flag and the CRC any
+ * more, if we are writing, we will re-calculate CRC and update
+ * flags before writing out
+ */
+ if (dev_current) {
+ environment.image = addr1;
+ environment.crc = &redundant->crc;
+ environment.flags = &redundant->flags;
+ environment.data = redundant->data;
+ free (addr0);
+ } else {
+ environment.image = addr0;
+ /* Other pointers are already set */
+ free (addr1);
+ }
+#ifdef DEBUG
+ fprintf(stderr, "Selected env in %s\n", DEVNAME(dev_current));
+#endif
+ }
+ return 0;
+}
+
+
+static int parse_config ()
+{
+ struct stat st;
+
+#if defined(CONFIG_FILE)
+ /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
+ if (get_config (CONFIG_FILE)) {
+ fprintf (stderr,
+ "Cannot parse config file: %s\n", strerror (errno));
+ return -1;
+ }
+#else
+ DEVNAME (0) = DEVICE1_NAME;
+ DEVOFFSET (0) = DEVICE1_OFFSET;
+ ENVSIZE (0) = ENV1_SIZE;
+ /* Default values are: erase-size=env-size */
+ DEVESIZE (0) = ENVSIZE (0);
+ /* #sectors=env-size/erase-size (rounded up) */
+ ENVSECTORS (0) = (ENVSIZE(0) + DEVESIZE(0) - 1) / DEVESIZE(0);
+#ifdef DEVICE1_ESIZE
+ DEVESIZE (0) = DEVICE1_ESIZE;
+#endif
+#ifdef DEVICE1_ENVSECTORS
+ ENVSECTORS (0) = DEVICE1_ENVSECTORS;
+#endif
+
+#ifdef HAVE_REDUND
+ DEVNAME (1) = DEVICE2_NAME;
+ DEVOFFSET (1) = DEVICE2_OFFSET;
+ ENVSIZE (1) = ENV2_SIZE;
+ /* Default values are: erase-size=env-size */
+ DEVESIZE (1) = ENVSIZE (1);
+ /* #sectors=env-size/erase-size (rounded up) */
+ ENVSECTORS (1) = (ENVSIZE(1) + DEVESIZE(1) - 1) / DEVESIZE(1);
+#ifdef DEVICE2_ESIZE
+ DEVESIZE (1) = DEVICE2_ESIZE;
+#endif
+#ifdef DEVICE2_ENVSECTORS
+ ENVSECTORS (1) = DEVICE2_ENVSECTORS;
+#endif
+ HaveRedundEnv = 1;
+#endif
+#endif
+ if (stat (DEVNAME (0), &st)) {
+ fprintf (stderr,
+ "Cannot access MTD device %s: %s\n",
+ DEVNAME (0), strerror (errno));
+ return -1;
+ }
+
+ if (HaveRedundEnv && stat (DEVNAME (1), &st)) {
+ fprintf (stderr,
+ "Cannot access MTD device %s: %s\n",
+ DEVNAME (1), strerror (errno));
+ return -1;
+ }
+ return 0;
+}
+
+#if defined(CONFIG_FILE)
+static int get_config (char *fname)
+{
+ FILE *fp;
+ int i = 0;
+ int rc;
+ char dump[128];
+ char *devname;
+
+ fp = fopen (fname, "r");
+ if (fp == NULL)
+ return -1;
+
+ while (i < 2 && fgets (dump, sizeof (dump), fp)) {
+ /* Skip incomplete conversions and comment strings */
+ if (dump[0] == '#')
+ continue;
+
+ rc = sscanf (dump, "%ms %lx %lx %lx %lx",
+ &devname,
+ &DEVOFFSET (i),
+ &ENVSIZE (i),
+ &DEVESIZE (i),
+ &ENVSECTORS (i));
+
+ if (rc < 3)
+ continue;
+
+ DEVNAME(i) = devname;
+
+ if (rc < 4)
+ /* Assume the erase size is the same as the env-size */
+ DEVESIZE(i) = ENVSIZE(i);
+
+ if (rc < 5)
+ /* Assume enough env sectors to cover the environment */
+ ENVSECTORS (i) = (ENVSIZE(i) + DEVESIZE(i) - 1) / DEVESIZE(i);
+
+ i++;
+ }
+ fclose (fp);
+
+ HaveRedundEnv = i - 1;
+ if (!i) { /* No valid entries found */
+ errno = EINVAL;
+ return -1;
+ } else
+ return 0;
+}
+#endif
diff --git a/roms/u-boot/tools/env/fw_env.config b/roms/u-boot/tools/env/fw_env.config
new file mode 100644
index 00000000..c9b9f6a1
--- /dev/null
+++ b/roms/u-boot/tools/env/fw_env.config
@@ -0,0 +1,22 @@
+# Configuration file for fw_(printenv/setenv) utility.
+# Up to two entries are valid, in this case the redundant
+# environment sector is assumed present.
+# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash.
+# Futhermore, if the Flash sector size is ommitted, this value is assumed to
+# be the same as the Environment size, which is valid for NOR and SPI-dataflash
+
+# NOR example
+# MTD device name Device offset Env. size Flash sector size Number of sectors
+/dev/mtd1 0x0000 0x4000 0x4000
+/dev/mtd2 0x0000 0x4000 0x4000
+
+# MTD SPI-dataflash example
+# MTD device name Device offset Env. size Flash sector size Number of sectors
+#/dev/mtd5 0x4200 0x4200
+#/dev/mtd6 0x4200 0x4200
+
+# NAND example
+#/dev/mtd0 0x4000 0x4000 0x20000 2
+
+# Block device example
+#/dev/mmcblk0 0xc0000 0x20000
diff --git a/roms/u-boot/tools/env/fw_env.h b/roms/u-boot/tools/env/fw_env.h
new file mode 100644
index 00000000..aff471ba
--- /dev/null
+++ b/roms/u-boot/tools/env/fw_env.h
@@ -0,0 +1,63 @@
+/*
+ * (C) Copyright 2002-2008
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/* Pull in the current config to define the default environment */
+#ifndef __ASSEMBLY__
+#define __ASSEMBLY__ /* get only #defines from config.h */
+#include
+#undef __ASSEMBLY__
+#else
+#include
+#endif
+
+/*
+ * To build the utility with the static configuration
+ * comment out the next line.
+ * See included "fw_env.config" sample file
+ * for notes on configuration.
+ */
+#define CONFIG_FILE "/etc/fw_env.config"
+
+#ifndef CONFIG_FILE
+#define HAVE_REDUND /* For systems with 2 env sectors */
+#define DEVICE1_NAME "/dev/mtd1"
+#define DEVICE2_NAME "/dev/mtd2"
+#define DEVICE1_OFFSET 0x0000
+#define ENV1_SIZE 0x4000
+#define DEVICE1_ESIZE 0x4000
+#define DEVICE1_ENVSECTORS 2
+#define DEVICE2_OFFSET 0x0000
+#define ENV2_SIZE 0x4000
+#define DEVICE2_ESIZE 0x4000
+#define DEVICE2_ENVSECTORS 2
+#endif
+
+#ifndef CONFIG_BAUDRATE
+#define CONFIG_BAUDRATE 115200
+#endif
+
+#ifndef CONFIG_BOOTDELAY
+#define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */
+#endif
+
+#ifndef CONFIG_BOOTCOMMAND
+#define CONFIG_BOOTCOMMAND \
+ "bootp; " \
+ "setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \
+ "ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \
+ "bootm"
+#endif
+
+extern int fw_printenv(int argc, char *argv[]);
+extern char *fw_getenv (char *name);
+extern int fw_setenv (int argc, char *argv[]);
+extern int fw_parse_script(char *fname);
+extern int fw_env_open(void);
+extern int fw_env_write(char *name, char *value);
+extern int fw_env_close(void);
+
+extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned);
diff --git a/roms/u-boot/tools/env/fw_env_main.c b/roms/u-boot/tools/env/fw_env_main.c
new file mode 100644
index 00000000..ce50d58b
--- /dev/null
+++ b/roms/u-boot/tools/env/fw_env_main.c
@@ -0,0 +1,147 @@
+/*
+ * (C) Copyright 2000-2008
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * Command line user interface to firmware (=U-Boot) environment.
+ *
+ * Implements:
+ * fw_printenv [ -a key ] [[ -n name ] | [ name ... ]]
+ * - prints the value of a single environment variable
+ * "name", the ``name=value'' pairs of one or more
+ * environment variables "name", or the whole
+ * environment if no names are specified.
+ * fw_setenv [ -a key ] name [ value ... ]
+ * - If a name without any values is given, the variable
+ * with this name is deleted from the environment;
+ * otherwise, all "value" arguments are concatenated,
+ * separated by single blank characters, and the
+ * resulting string is assigned to the environment
+ * variable "name"
+ *
+ * If '-a key' is specified, the env block is encrypted with AES 128 CBC.
+ * The 'key' argument is in the format of 32 hexadecimal numbers (16 bytes
+ * of AES key), eg. '-a aabbccddeeff00112233445566778899'.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "fw_env.h"
+
+#define CMD_PRINTENV "fw_printenv"
+#define CMD_SETENV "fw_setenv"
+
+static struct option long_options[] = {
+ {"script", required_argument, NULL, 's'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+};
+
+void usage(void)
+{
+
+ fprintf(stderr, "fw_printenv/fw_setenv, "
+ "a command line interface to U-Boot environment\n\n"
+ "usage:\tfw_printenv [-a key] [-n] [variable name]\n"
+ "\tfw_setenv [-a key] [variable name] [variable value]\n"
+ "\tfw_setenv -s [ file ]\n"
+ "\tfw_setenv -s - < [ file ]\n\n"
+ "The file passed as argument contains only pairs "
+ "name / value\n"
+ "Example:\n"
+ "# Any line starting with # is treated as comment\n"
+ "\n"
+ "\t netdev eth0\n"
+ "\t kernel_addr 400000\n"
+ "\t var1\n"
+ "\t var2 The quick brown fox jumps over the "
+ "lazy dog\n"
+ "\n"
+ "A variable without value will be dropped. It is possible\n"
+ "to put any number of spaces between the fields, but any\n"
+ "space inside the value is treated as part of the value "
+ "itself.\n\n"
+ );
+}
+
+int main(int argc, char *argv[])
+{
+ char *p;
+ char *cmdname = *argv;
+ char *script_file = NULL;
+ int c;
+ const char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
+ int lockfd = -1;
+ int retval = EXIT_SUCCESS;
+
+ lockfd = open(lockname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (-1 == lockfd) {
+ fprintf(stderr, "Error opening lock file %s\n", lockname);
+ return EXIT_FAILURE;
+ }
+
+ if (-1 == flock(lockfd, LOCK_EX)) {
+ fprintf(stderr, "Error locking file %s\n", lockname);
+ close(lockfd);
+ return EXIT_FAILURE;
+ }
+
+ if ((p = strrchr (cmdname, '/')) != NULL) {
+ cmdname = p + 1;
+ }
+
+ while ((c = getopt_long (argc, argv, "a:ns:h",
+ long_options, NULL)) != EOF) {
+ switch (c) {
+ case 'a':
+ /* AES key, handled later */
+ break;
+ case 'n':
+ /* handled in fw_printenv */
+ break;
+ case 's':
+ script_file = optarg;
+ break;
+ case 'h':
+ usage();
+ goto exit;
+ default: /* '?' */
+ fprintf(stderr, "Try `%s --help' for more information."
+ "\n", cmdname);
+ retval = EXIT_FAILURE;
+ goto exit;
+ }
+ }
+
+ if (strcmp(cmdname, CMD_PRINTENV) == 0) {
+ if (fw_printenv(argc, argv) != 0)
+ retval = EXIT_FAILURE;
+ } else if (strcmp(cmdname, CMD_SETENV) == 0) {
+ if (!script_file) {
+ if (fw_setenv(argc, argv) != 0)
+ retval = EXIT_FAILURE;
+ } else {
+ if (fw_parse_script(script_file) != 0)
+ retval = EXIT_FAILURE;
+ }
+ } else {
+ fprintf(stderr,
+ "Identity crisis - may be called as `" CMD_PRINTENV
+ "' or as `" CMD_SETENV "' but not as `%s'\n",
+ cmdname);
+ retval = EXIT_FAILURE;
+ }
+
+exit:
+ flock(lockfd, LOCK_UN);
+ close(lockfd);
+ return retval;
+}
diff --git a/roms/u-boot/tools/env/linux_string.c b/roms/u-boot/tools/env/linux_string.c
new file mode 100644
index 00000000..6c01adda
--- /dev/null
+++ b/roms/u-boot/tools/env/linux_string.c
@@ -0,0 +1 @@
+#include "../../lib/linux_string.c"
diff --git a/roms/u-boot/tools/env_embedded.c b/roms/u-boot/tools/env_embedded.c
new file mode 100644
index 00000000..59a63571
--- /dev/null
+++ b/roms/u-boot/tools/env_embedded.c
@@ -0,0 +1 @@
+#include "../common/env_embedded.c"
diff --git a/roms/u-boot/tools/envcrc.c b/roms/u-boot/tools/envcrc.c
new file mode 100644
index 00000000..a9d9b48c
--- /dev/null
+++ b/roms/u-boot/tools/envcrc.c
@@ -0,0 +1,129 @@
+/*
+ * (C) Copyright 2001
+ * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifndef __ASSEMBLY__
+#define __ASSEMBLY__ /* Dirty trick to get only #defines */
+#endif
+#define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */
+#include
+#undef __ASSEMBLY__
+
+#if defined(CONFIG_ENV_IS_IN_FLASH)
+# ifndef CONFIG_ENV_ADDR
+# define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
+# endif
+# ifndef CONFIG_ENV_OFFSET
+# define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
+# endif
+# if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
+# define CONFIG_ENV_ADDR_REDUND (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
+# endif
+# ifndef CONFIG_ENV_SIZE
+# define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
+# endif
+# if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
+# define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE
+# endif
+# if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
+ ((CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN))
+# define ENV_IS_EMBEDDED
+# endif
+# if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
+# define CONFIG_SYS_REDUNDAND_ENVIRONMENT
+# endif
+#endif /* CONFIG_ENV_IS_IN_FLASH */
+
+#if defined(ENV_IS_EMBEDDED) && !defined(CONFIG_BUILD_ENVCRC)
+# define CONFIG_BUILD_ENVCRC
+#endif
+
+#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
+# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
+#else
+# define ENV_HEADER_SIZE (sizeof(uint32_t))
+#endif
+
+#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
+
+
+#ifdef CONFIG_BUILD_ENVCRC
+# include
+extern unsigned int env_size;
+extern env_t environment;
+#endif /* CONFIG_BUILD_ENVCRC */
+
+extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
+
+int main (int argc, char **argv)
+{
+#ifdef CONFIG_BUILD_ENVCRC
+ unsigned char pad = 0x00;
+ uint32_t crc;
+ unsigned char *envptr = (unsigned char *)&environment,
+ *dataptr = envptr + ENV_HEADER_SIZE;
+ unsigned int datasize = ENV_SIZE;
+ unsigned int eoe;
+
+ if (argv[1] && !strncmp(argv[1], "--binary", 8)) {
+ int ipad = 0xff;
+ if (argv[1][8] == '=')
+ sscanf(argv[1] + 9, "%i", &ipad);
+ pad = ipad;
+ }
+
+ if (pad) {
+ /* find the end of env */
+ for (eoe = 0; eoe < datasize - 1; ++eoe)
+ if (!dataptr[eoe] && !dataptr[eoe+1]) {
+ eoe += 2;
+ break;
+ }
+ if (eoe < datasize - 1)
+ memset(dataptr + eoe, pad, datasize - eoe);
+ }
+
+ crc = crc32 (0, dataptr, datasize);
+
+ /* Check if verbose mode is activated passing a parameter to the program */
+ if (argc > 1) {
+ if (!strncmp(argv[1], "--binary", 8)) {
+ int le = (argc > 2 ? !strcmp(argv[2], "le") : 1);
+ size_t i, start, end, step;
+ if (le) {
+ start = 0;
+ end = ENV_HEADER_SIZE;
+ step = 1;
+ } else {
+ start = ENV_HEADER_SIZE - 1;
+ end = -1;
+ step = -1;
+ }
+ for (i = start; i != end; i += step)
+ printf("%c", (crc & (0xFF << (i * 8))) >> (i * 8));
+ if (fwrite(dataptr, 1, datasize, stdout) != datasize)
+ fprintf(stderr, "fwrite() failed: %s\n", strerror(errno));
+ } else {
+ printf("CRC32 from offset %08X to %08X of environment = %08X\n",
+ (unsigned int) (dataptr - envptr),
+ (unsigned int) (dataptr - envptr) + datasize,
+ crc);
+ }
+ } else {
+ printf ("0x%08X\n", crc);
+ }
+#else
+ printf ("0\n");
+#endif
+ return EXIT_SUCCESS;
+}
diff --git a/roms/u-boot/tools/fdt.c b/roms/u-boot/tools/fdt.c
new file mode 100644
index 00000000..1eafc56d
--- /dev/null
+++ b/roms/u-boot/tools/fdt.c
@@ -0,0 +1 @@
+#include "../lib/libfdt/fdt.c"
diff --git a/roms/u-boot/tools/fdt_host.h b/roms/u-boot/tools/fdt_host.h
new file mode 100644
index 00000000..134d9657
--- /dev/null
+++ b/roms/u-boot/tools/fdt_host.h
@@ -0,0 +1,16 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __FDT_HOST_H__
+#define __FDT_HOST_H__
+
+/* Make sure to include u-boot version of libfdt include files */
+#include "../include/libfdt.h"
+#include "../include/fdt_support.h"
+
+int fit_check_sign(const void *working_fdt, const void *key);
+
+#endif /* __FDT_HOST_H__ */
diff --git a/roms/u-boot/tools/fdt_ro.c b/roms/u-boot/tools/fdt_ro.c
new file mode 100644
index 00000000..9005fe3c
--- /dev/null
+++ b/roms/u-boot/tools/fdt_ro.c
@@ -0,0 +1 @@
+#include "../lib/libfdt/fdt_ro.c"
diff --git a/roms/u-boot/tools/fdt_rw.c b/roms/u-boot/tools/fdt_rw.c
new file mode 100644
index 00000000..adc3fdfb
--- /dev/null
+++ b/roms/u-boot/tools/fdt_rw.c
@@ -0,0 +1 @@
+#include "../lib/libfdt/fdt_rw.c"
diff --git a/roms/u-boot/tools/fdt_strerror.c b/roms/u-boot/tools/fdt_strerror.c
new file mode 100644
index 00000000..d0b58220
--- /dev/null
+++ b/roms/u-boot/tools/fdt_strerror.c
@@ -0,0 +1 @@
+#include "../lib/libfdt/fdt_strerror.c"
diff --git a/roms/u-boot/tools/fdt_wip.c b/roms/u-boot/tools/fdt_wip.c
new file mode 100644
index 00000000..7810f070
--- /dev/null
+++ b/roms/u-boot/tools/fdt_wip.c
@@ -0,0 +1 @@
+#include "../lib/libfdt/fdt_wip.c"
diff --git a/roms/u-boot/tools/fdtdec.c b/roms/u-boot/tools/fdtdec.c
new file mode 100644
index 00000000..f1c22569
--- /dev/null
+++ b/roms/u-boot/tools/fdtdec.c
@@ -0,0 +1 @@
+#include "../lib/fdtdec.c"
diff --git a/roms/u-boot/tools/fit_check_sign.c b/roms/u-boot/tools/fit_check_sign.c
new file mode 100644
index 00000000..d6d93400
--- /dev/null
+++ b/roms/u-boot/tools/fit_check_sign.c
@@ -0,0 +1,85 @@
+/*
+ * (C) Copyright 2014
+ * DENX Software Engineering
+ * Heiko Schocher
+ *
+ * Based on:
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd@denx.de
+ *
+ * Updated-by: Prafulla Wadaskar
+ * FIT image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "mkimage.h"
+#include "fit_common.h"
+#include
+#include
+
+void usage(char *cmdname)
+{
+ fprintf(stderr, "Usage: %s -f fit file -k key file\n"
+ " -f ==> set fit file which should be checked'\n"
+ " -k ==> set key file which contains the key'\n",
+ cmdname);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+ int ffd = -1;
+ int kfd = -1;
+ struct stat fsbuf;
+ struct stat ksbuf;
+ void *fit_blob;
+ char *fdtfile = NULL;
+ char *keyfile = NULL;
+ char cmdname[50];
+ int ret;
+ void *key_blob;
+ int c;
+
+ strcpy(cmdname, *argv);
+ while ((c = getopt(argc, argv, "f:k:")) != -1)
+ switch (c) {
+ case 'f':
+ fdtfile = optarg;
+ break;
+ case 'k':
+ keyfile = optarg;
+ break;
+ default:
+ usage(cmdname);
+ break;
+ }
+
+ ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+ if (ffd < 0)
+ return EXIT_FAILURE;
+ kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, 0);
+ if (ffd < 0)
+ return EXIT_FAILURE;
+
+ image_set_host_blob(key_blob);
+ ret = fit_check_sign(fit_blob, key_blob);
+
+ if (ret)
+ ret = EXIT_SUCCESS;
+ else
+ ret = EXIT_FAILURE;
+
+ (void) munmap((void *)fit_blob, fsbuf.st_size);
+ (void) munmap((void *)key_blob, ksbuf.st_size);
+
+ close(ffd);
+ close(kfd);
+ exit(ret);
+}
diff --git a/roms/u-boot/tools/fit_common.c b/roms/u-boot/tools/fit_common.c
new file mode 100644
index 00000000..ee1767bd
--- /dev/null
+++ b/roms/u-boot/tools/fit_common.c
@@ -0,0 +1,86 @@
+/*
+ * (C) Copyright 2014
+ * DENX Software Engineering
+ * Heiko Schocher
+ *
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd@denx.de
+ *
+ * Updated-by: Prafulla Wadaskar
+ * FIT image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include "mkimage.h"
+#include "fit_common.h"
+#include
+#include
+
+int fit_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ return fdt_check_header(ptr);
+}
+
+int fit_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_FLATDT)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+int mmap_fdt(char *cmdname, const char *fname, void **blobp,
+ struct stat *sbuf, int useunlink)
+{
+ void *ptr;
+ int fd;
+
+ /* Load FIT blob into memory (we need to write hashes/signatures) */
+ fd = open(fname, O_RDWR | O_BINARY);
+
+ if (fd < 0) {
+ fprintf(stderr, "%s: Can't open %s: %s\n",
+ cmdname, fname, strerror(errno));
+ if (useunlink)
+ unlink(fname);
+ return -1;
+ }
+
+ if (fstat(fd, sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat %s: %s\n",
+ cmdname, fname, strerror(errno));
+ if (useunlink)
+ unlink(fname);
+ return -1;
+ }
+
+ errno = 0;
+ ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if ((ptr == MAP_FAILED) || (errno != 0)) {
+ fprintf(stderr, "%s: Can't read %s: %s\n",
+ cmdname, fname, strerror(errno));
+ if (useunlink)
+ unlink(fname);
+ return -1;
+ }
+
+ /* check if ptr has a valid blob */
+ if (fdt_check_header(ptr)) {
+ fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
+ if (useunlink)
+ unlink(fname);
+ return -1;
+ }
+
+ *blobp = ptr;
+ return fd;
+}
diff --git a/roms/u-boot/tools/fit_common.h b/roms/u-boot/tools/fit_common.h
new file mode 100644
index 00000000..adf44048
--- /dev/null
+++ b/roms/u-boot/tools/fit_common.h
@@ -0,0 +1,22 @@
+/*
+ * (C) Copyright 2014
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _FIT_COMMON_H_
+#define _FIT_COMMON_H_
+
+#include "imagetool.h"
+#include "mkimage.h"
+#include
+
+int fit_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params);
+
+int fit_check_image_types(uint8_t type);
+
+int mmap_fdt(char *cmdname, const char *fname, void **blobp,
+ struct stat *sbuf, int useunlink);
+
+#endif /* _FIT_COMMON_H_ */
diff --git a/roms/u-boot/tools/fit_image.c b/roms/u-boot/tools/fit_image.c
new file mode 100644
index 00000000..eeee484c
--- /dev/null
+++ b/roms/u-boot/tools/fit_image.c
@@ -0,0 +1,156 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd@denx.de
+ *
+ * Updated-by: Prafulla Wadaskar
+ * FIT image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include "fit_common.h"
+#include "mkimage.h"
+#include
+#include
+
+static image_header_t header;
+
+/**
+ * fit_handle_file - main FIT file processing function
+ *
+ * fit_handle_file() runs dtc to convert .its to .itb, includes
+ * binary data, updates timestamp property and calculates hashes.
+ *
+ * datafile - .its file
+ * imagefile - .itb file
+ *
+ * returns:
+ * only on success, otherwise calls exit (EXIT_FAILURE);
+ */
+static int fit_handle_file(struct image_tool_params *params)
+{
+ char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
+ char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
+ int tfd, destfd = 0;
+ void *dest_blob = NULL;
+ struct stat sbuf;
+ void *ptr;
+ off_t destfd_size = 0;
+
+ /* Flattened Image Tree (FIT) format handling */
+ debug ("FIT format handling\n");
+
+ /* call dtc to include binary properties into the tmp file */
+ if (strlen (params->imagefile) +
+ strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) {
+ fprintf (stderr, "%s: Image file name (%s) too long, "
+ "can't create tmpfile",
+ params->imagefile, params->cmdname);
+ return (EXIT_FAILURE);
+ }
+ sprintf (tmpfile, "%s%s", params->imagefile, MKIMAGE_TMPFILE_SUFFIX);
+
+ /* We either compile the source file, or use the existing FIT image */
+ if (params->datafile) {
+ /* dtc -I dts -O dtb -p 500 datafile > tmpfile */
+ snprintf(cmd, sizeof(cmd), "%s %s %s > %s",
+ MKIMAGE_DTC, params->dtc, params->datafile, tmpfile);
+ debug("Trying to execute \"%s\"\n", cmd);
+ } else {
+ snprintf(cmd, sizeof(cmd), "cp %s %s",
+ params->imagefile, tmpfile);
+ }
+ if (system (cmd) == -1) {
+ fprintf (stderr, "%s: system(%s) failed: %s\n",
+ params->cmdname, cmd, strerror(errno));
+ goto err_system;
+ }
+
+ if (params->keydest) {
+ destfd = mmap_fdt(params->cmdname, params->keydest,
+ &dest_blob, &sbuf, 1);
+ if (destfd < 0)
+ goto err_keydest;
+ destfd_size = sbuf.st_size;
+ }
+
+ tfd = mmap_fdt(params->cmdname, tmpfile, &ptr, &sbuf, 1);
+ if (tfd < 0)
+ goto err_mmap;
+
+ /* set hashes for images in the blob */
+ if (fit_add_verification_data(params->keydir,
+ dest_blob, ptr, params->comment,
+ params->require_keys)) {
+ fprintf(stderr, "%s Can't add hashes to FIT blob\n",
+ params->cmdname);
+ goto err_add_hashes;
+ }
+
+ /* for first image creation, add a timestamp at offset 0 i.e., root */
+ if (params->datafile && fit_set_timestamp(ptr, 0, sbuf.st_mtime)) {
+ fprintf (stderr, "%s: Can't add image timestamp\n",
+ params->cmdname);
+ goto err_add_timestamp;
+ }
+ debug ("Added timestamp successfully\n");
+
+ munmap ((void *)ptr, sbuf.st_size);
+ close (tfd);
+ if (dest_blob) {
+ munmap(dest_blob, destfd_size);
+ close(destfd);
+ }
+
+ if (rename (tmpfile, params->imagefile) == -1) {
+ fprintf (stderr, "%s: Can't rename %s to %s: %s\n",
+ params->cmdname, tmpfile, params->imagefile,
+ strerror (errno));
+ unlink (tmpfile);
+ unlink (params->imagefile);
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+
+err_add_timestamp:
+err_add_hashes:
+ munmap(ptr, sbuf.st_size);
+err_mmap:
+ if (dest_blob)
+ munmap(dest_blob, destfd_size);
+err_keydest:
+err_system:
+ unlink(tmpfile);
+ return -1;
+}
+
+static int fit_check_params(struct image_tool_params *params)
+{
+ return ((params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)));
+}
+
+static struct image_type_params fitimage_params = {
+ .name = "FIT Image support",
+ .header_size = sizeof(image_header_t),
+ .hdr = (void*)&header,
+ .verify_header = fit_verify_header,
+ .print_header = fit_print_contents,
+ .check_image_type = fit_check_image_types,
+ .fflag_handle = fit_handle_file,
+ .set_header = NULL, /* FIT images use DTB header */
+ .check_params = fit_check_params,
+};
+
+void init_fit_image_type (void)
+{
+ register_image_type(&fitimage_params);
+}
diff --git a/roms/u-boot/tools/fit_info.c b/roms/u-boot/tools/fit_info.c
new file mode 100644
index 00000000..50f3c8ed
--- /dev/null
+++ b/roms/u-boot/tools/fit_info.c
@@ -0,0 +1,96 @@
+/*
+ * (C) Copyright 2014
+ * DENX Software Engineering
+ * Heiko Schocher
+ *
+ * fit_info: print the offset and the len of a property from
+ * node in a fit file.
+ *
+ * Based on:
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd@denx.de
+ *
+ * Updated-by: Prafulla Wadaskar
+ * FIT image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "mkimage.h"
+#include "fit_common.h"
+#include
+#include
+
+void usage(char *cmdname)
+{
+ fprintf(stderr, "Usage: %s -f fit file -n node -p property\n"
+ " -f ==> set fit file which is used'\n"
+ " -n ==> set node name'\n"
+ " -p ==> set property name'\n",
+ cmdname);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+ int ffd = -1;
+ struct stat fsbuf;
+ void *fit_blob;
+ int len;
+ int nodeoffset; /* node offset from libfdt */
+ const void *nodep; /* property node pointer */
+ char *fdtfile = NULL;
+ char *nodename = NULL;
+ char *propertyname = NULL;
+ char cmdname[50];
+ int c;
+
+ strcpy(cmdname, *argv);
+ while ((c = getopt(argc, argv, "f:n:p:")) != -1)
+ switch (c) {
+ case 'f':
+ fdtfile = optarg;
+ break;
+ case 'n':
+ nodename = optarg;
+ break;
+ case 'p':
+ propertyname = optarg;
+ break;
+ default:
+ usage(cmdname);
+ break;
+ }
+
+ ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+
+ if (ffd < 0) {
+ printf("Could not open %s\n", fdtfile);
+ exit(EXIT_FAILURE);
+ }
+
+ nodeoffset = fdt_path_offset(fit_blob, nodename);
+ if (nodeoffset < 0) {
+ printf("%s not found.", nodename);
+ exit(EXIT_FAILURE);
+ }
+ nodep = fdt_getprop(fit_blob, nodeoffset, propertyname, &len);
+ if (len == 0) {
+ printf("len == 0 %s\n", propertyname);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("NAME: %s\n", fit_get_name(fit_blob, nodeoffset, NULL));
+ printf("LEN: %d\n", len);
+ printf("OFF: %d\n", (int)(nodep - fit_blob));
+ (void) munmap((void *)fit_blob, fsbuf.st_size);
+
+ close(ffd);
+ exit(EXIT_SUCCESS);
+}
diff --git a/roms/u-boot/tools/gdb/Makefile b/roms/u-boot/tools/gdb/Makefile
new file mode 100644
index 00000000..45133203
--- /dev/null
+++ b/roms/u-boot/tools/gdb/Makefile
@@ -0,0 +1,46 @@
+#
+# (C) Copyright 2006
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# (C) Copyright 2000
+# Murray Jensen
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+ifneq ($(HOSTOS),cygwin)
+
+# Location of a usable BFD library, where we define "usable" as
+# "built for ${HOST}, supports ${TARGET}". Sensible values are
+# - When cross-compiling: the root of the cross-environment
+# - Linux/ppc (native): /usr
+# - NetBSD/ppc (native): you lose ... (must extract these from the
+# binutils build directory, plus the native and U-Boot include
+# files don't like each other)
+
+ifeq ($(HOSTOS),darwin)
+BFD_ROOT_DIR = /usr/local/tools
+else
+ifeq ($(HOSTARCH),$(ARCH))
+# native
+BFD_ROOT_DIR = /usr
+else
+#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
+#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
+BFD_ROOT_DIR = /opt/powerpc
+endif
+endif
+
+#
+# Use native tools and options
+#
+HOST_EXTRACFLAGS := -I$(BFD_ROOT_DIR)/include -pedantic
+
+hostprogs-y := gdbsend gdbcont
+
+gdbsend-objs := gdbsend.o error.o remote.o serial.o
+gdbcont-objs := gdbcont.o error.o remote.o serial.o
+
+always := $(hostprogs-y)
+
+endif # cygwin
diff --git a/roms/u-boot/tools/gdb/error.c b/roms/u-boot/tools/gdb/error.c
new file mode 100644
index 00000000..4c32ce55
--- /dev/null
+++ b/roms/u-boot/tools/gdb/error.c
@@ -0,0 +1,65 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include "error.h"
+
+char *pname;
+
+void
+Warning(char *fmt, ...)
+{
+ va_list args;
+
+ fprintf(stderr, "%s: WARNING: ", pname);
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+
+ fprintf(stderr, "\n");
+}
+
+void
+Error(char *fmt, ...)
+{
+ va_list args;
+
+ fprintf(stderr, "%s: ERROR: ", pname);
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+
+ fprintf(stderr, "\n");
+
+ exit(1);
+}
+
+void
+Perror(char *fmt, ...)
+{
+ va_list args;
+ int e = errno;
+ char *p;
+
+ fprintf(stderr, "%s: ERROR: ", pname);
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+
+ if ((p = strerror(e)) == NULL || *p == '\0')
+ fprintf(stderr, ": Unknown Error (%d)\n", e);
+ else
+ fprintf(stderr, ": %s\n", p);
+
+ exit(1);
+}
diff --git a/roms/u-boot/tools/gdb/error.h b/roms/u-boot/tools/gdb/error.h
new file mode 100644
index 00000000..fdadaacc
--- /dev/null
+++ b/roms/u-boot/tools/gdb/error.h
@@ -0,0 +1,14 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+
+extern char *pname;
+
+extern void Warning(char *, ...);
+extern void Error(char *, ...);
+extern void Perror(char *, ...);
diff --git a/roms/u-boot/tools/gdb/gdbcont.c b/roms/u-boot/tools/gdb/gdbcont.c
new file mode 100644
index 00000000..761bdb0a
--- /dev/null
+++ b/roms/u-boot/tools/gdb/gdbcont.c
@@ -0,0 +1,71 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include "serial.h"
+#include "error.h"
+#include "remote.h"
+
+char *serialdev = "/dev/term/b";
+speed_t speed = B230400;
+int verbose = 0;
+
+int
+main(int ac, char **av)
+{
+ int c, sfd;
+
+ if ((pname = strrchr(av[0], '/')) == NULL)
+ pname = av[0];
+ else
+ pname++;
+
+ while ((c = getopt(ac, av, "b:p:v")) != EOF)
+ switch (c) {
+
+ case 'b':
+ if ((speed = cvtspeed(optarg)) == B0)
+ Error("can't decode baud rate specified in -b option");
+ break;
+
+ case 'p':
+ serialdev = optarg;
+ break;
+
+ case 'v':
+ verbose = 1;
+ break;
+
+ default:
+ usage:
+ fprintf(stderr, "Usage: %s [-b bps] [-p dev] [-v]\n", pname);
+ exit(1);
+ }
+ if (optind != ac)
+ goto usage;
+
+ if (verbose)
+ fprintf(stderr, "Opening serial port and sending continue...\n");
+
+ if ((sfd = serialopen(serialdev, speed)) < 0)
+ Perror("open of serial device '%s' failed", serialdev);
+
+ remote_desc = sfd;
+ remote_reset();
+ remote_continue();
+
+ if (serialclose(sfd) < 0)
+ Perror("close of serial device '%s' failed", serialdev);
+
+ if (verbose)
+ fprintf(stderr, "Done.\n");
+
+ return (0);
+}
diff --git a/roms/u-boot/tools/gdb/gdbsend.c b/roms/u-boot/tools/gdb/gdbsend.c
new file mode 100644
index 00000000..bb28c721
--- /dev/null
+++ b/roms/u-boot/tools/gdb/gdbsend.c
@@ -0,0 +1,121 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "serial.h"
+#include "error.h"
+#include "remote.h"
+
+char *serialdev = "/dev/term/b";
+speed_t speed = B230400;
+int verbose = 0, docont = 0;
+unsigned long addr = 0x10000UL;
+
+int
+main(int ac, char **av)
+{
+ int c, sfd, ifd;
+ char *ifn, *image;
+ struct stat ist;
+
+ if ((pname = strrchr(av[0], '/')) == NULL)
+ pname = av[0];
+ else
+ pname++;
+
+ while ((c = getopt(ac, av, "a:b:cp:v")) != EOF)
+ switch (c) {
+
+ case 'a': {
+ char *ep;
+
+ addr = strtol(optarg, &ep, 0);
+ if (ep == optarg || *ep != '\0')
+ Error("can't decode address specified in -a option");
+ break;
+ }
+
+ case 'b':
+ if ((speed = cvtspeed(optarg)) == B0)
+ Error("can't decode baud rate specified in -b option");
+ break;
+
+ case 'c':
+ docont = 1;
+ break;
+
+ case 'p':
+ serialdev = optarg;
+ break;
+
+ case 'v':
+ verbose = 1;
+ break;
+
+ default:
+ usage:
+ fprintf(stderr,
+ "Usage: %s [-a addr] [-b bps] [-c] [-p dev] [-v] imagefile\n",
+ pname);
+ exit(1);
+ }
+
+ if (optind != ac - 1)
+ goto usage;
+ ifn = av[optind++];
+
+ if (verbose)
+ fprintf(stderr, "Opening file and reading image...\n");
+
+ if ((ifd = open(ifn, O_RDONLY)) < 0)
+ Perror("can't open kernel image file '%s'", ifn);
+
+ if (fstat(ifd, &ist) < 0)
+ Perror("fstat '%s' failed", ifn);
+
+ if ((image = (char *)malloc(ist.st_size)) == NULL)
+ Perror("can't allocate %ld bytes for image", ist.st_size);
+
+ if ((c = read(ifd, image, ist.st_size)) < 0)
+ Perror("read of %d bytes from '%s' failed", ist.st_size, ifn);
+
+ if (c != ist.st_size)
+ Error("read of %ld bytes from '%s' failed (%d)", ist.st_size, ifn, c);
+
+ if (close(ifd) < 0)
+ Perror("close of '%s' failed", ifn);
+
+ if (verbose)
+ fprintf(stderr, "Opening serial port and sending image...\n");
+
+ if ((sfd = serialopen(serialdev, speed)) < 0)
+ Perror("open of serial device '%s' failed", serialdev);
+
+ remote_desc = sfd;
+ remote_reset();
+ remote_write_bytes(addr, image, ist.st_size);
+
+ if (docont) {
+ if (verbose)
+ fprintf(stderr, "[continue]");
+ remote_continue();
+ }
+
+ if (serialclose(sfd) < 0)
+ Perror("close of serial device '%s' failed", serialdev);
+
+ if (verbose)
+ fprintf(stderr, "Done.\n");
+
+ return (0);
+}
diff --git a/roms/u-boot/tools/gdb/remote.c b/roms/u-boot/tools/gdb/remote.c
new file mode 100644
index 00000000..f3681043
--- /dev/null
+++ b/roms/u-boot/tools/gdb/remote.c
@@ -0,0 +1,916 @@
+/*
+ * taken from gdb/remote.c
+ *
+ * I am only interested in the write to memory stuff - everything else
+ * has been ripped out
+ *
+ * all the copyright notices etc have been left in
+ */
+
+/* enough so that it will compile */
+#include
+#include
+#include
+#include
+
+/*nicked from gcc..*/
+
+#ifndef alloca
+#ifdef __GNUC__
+#define alloca __builtin_alloca
+#else /* not GNU C. */
+#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
+#include
+#else /* not sparc */
+#if defined (MSDOS) && !defined (__TURBOC__)
+#include
+#else /* not MSDOS, or __TURBOC__ */
+#if defined(_AIX)
+#include
+ #pragma alloca
+#else /* not MSDOS, __TURBOC__, or _AIX */
+#ifdef __hpux
+#endif /* __hpux */
+#endif /* not _AIX */
+#endif /* not MSDOS, or __TURBOC__ */
+#endif /* not sparc. */
+#endif /* not GNU C. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void* alloca(size_t);
+#ifdef __cplusplus
+}
+#endif
+#endif /* alloca not defined. */
+
+
+#include "serial.h"
+#include "error.h"
+#include "remote.h"
+#define REGISTER_BYTES 0
+#define fprintf_unfiltered fprintf
+#define fprintf_filtered fprintf
+#define fputs_unfiltered fputs
+#define fputs_filtered fputs
+#define fputc_unfiltered fputc
+#define fputc_filtered fputc
+#define printf_unfiltered printf
+#define printf_filtered printf
+#define puts_unfiltered puts
+#define puts_filtered puts
+#define putchar_unfiltered putchar
+#define putchar_filtered putchar
+#define fputstr_unfiltered(a,b,c) fputs((a), (c))
+#define gdb_stdlog stderr
+#define SERIAL_READCHAR(fd,timo) serialreadchar((fd), (timo))
+#define SERIAL_WRITE(fd, addr, len) serialwrite((fd), (addr), (len))
+#define error Error
+#define perror_with_name Perror
+#define gdb_flush fflush
+#define max(a,b) (((a)>(b))?(a):(b))
+#define min(a,b) (((a)<(b))?(a):(b))
+#define target_mourn_inferior() {}
+#define ULONGEST unsigned long
+#define CORE_ADDR unsigned long
+
+static int putpkt (char *);
+static int putpkt_binary(char *, int);
+static void getpkt (char *, int);
+
+static int remote_debug = 0, remote_register_buf_size = 0, watchdog = 0;
+
+int remote_desc = -1, remote_timeout = 10;
+
+static void
+fputstrn_unfiltered(char *s, int n, int x, FILE *fp)
+{
+ while (n-- > 0)
+ fputc(*s++, fp);
+}
+
+void
+remote_reset(void)
+{
+ SERIAL_WRITE(remote_desc, "+", 1);
+}
+
+void
+remote_continue(void)
+{
+ putpkt("c");
+}
+
+/* Remote target communications for serial-line targets in custom GDB protocol
+ Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+/* *INDENT-OFF* */
+/* Remote communication protocol.
+
+ A debug packet whose contents are
+ is encapsulated for transmission in the form:
+
+ $ # CSUM1 CSUM2
+
+ must be ASCII alphanumeric and cannot include characters
+ '$' or '#'. If starts with two characters followed by
+ ':', then the existing stubs interpret this as a sequence number.
+
+ CSUM1 and CSUM2 are ascii hex representation of an 8-bit
+ checksum of , the most significant nibble is sent first.
+ the hex digits 0-9,a-f are used.
+
+ Receiver responds with:
+
+ + - if CSUM is correct and ready for next packet
+ - - if CSUM is incorrect
+
+ is as follows:
+ Most values are encoded in ascii hex digits. Signal numbers are according
+ to the numbering in target.h.
+
+ Request Packet
+
+ set thread Hct... Set thread for subsequent operations.
+ c = 'c' for thread used in step and
+ continue; t... can be -1 for all
+ threads.
+ c = 'g' for thread used in other
+ operations. If zero, pick a thread,
+ any thread.
+ reply OK for success
+ ENN for an error.
+
+ read registers g
+ reply XX....X Each byte of register data
+ is described by two hex digits.
+ Registers are in the internal order
+ for GDB, and the bytes in a register
+ are in the same order the machine uses.
+ or ENN for an error.
+
+ write regs GXX..XX Each byte of register data
+ is described by two hex digits.
+ reply OK for success
+ ENN for an error
+
+ write reg Pn...=r... Write register n... with value r...,
+ which contains two hex digits for each
+ byte in the register (target byte
+ order).
+ reply OK for success
+ ENN for an error
+ (not supported by all stubs).
+
+ read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
+ reply XX..XX XX..XX is mem contents
+ Can be fewer bytes than requested
+ if able to read only part of the data.
+ or ENN NN is errno
+
+ write mem MAA..AA,LLLL:XX..XX
+ AA..AA is address,
+ LLLL is number of bytes,
+ XX..XX is data
+ reply OK for success
+ ENN for an error (this includes the case
+ where only part of the data was
+ written).
+
+ write mem XAA..AA,LLLL:XX..XX
+ (binary) AA..AA is address,
+ LLLL is number of bytes,
+ XX..XX is binary data
+ reply OK for success
+ ENN for an error
+
+ continue cAA..AA AA..AA is address to resume
+ If AA..AA is omitted,
+ resume at same address.
+
+ step sAA..AA AA..AA is address to resume
+ If AA..AA is omitted,
+ resume at same address.
+
+ continue with Csig;AA..AA Continue with signal sig (hex signal
+ signal number). If ;AA..AA is omitted,
+ resume at same address.
+
+ step with Ssig;AA..AA Like 'C' but step not continue.
+ signal
+
+ last signal ? Reply the current reason for stopping.
+ This is the same reply as is generated
+ for step or cont : SAA where AA is the
+ signal number.
+
+ detach D Reply OK.
+
+ There is no immediate reply to step or cont.
+ The reply comes when the machine stops.
+ It is SAA AA is the signal number.
+
+ or... TAAn...:r...;n...:r...;n...:r...;
+ AA = signal number
+ n... = register number (hex)
+ r... = register contents
+ n... = `thread'
+ r... = thread process ID. This is
+ a hex integer.
+ n... = other string not starting
+ with valid hex digit.
+ gdb should ignore this n,r pair
+ and go on to the next. This way
+ we can extend the protocol.
+ or... WAA The process exited, and AA is
+ the exit status. This is only
+ applicable for certains sorts of
+ targets.
+ or... XAA The process terminated with signal
+ AA.
+ or (obsolete) NAA;tttttttt;dddddddd;bbbbbbbb
+ AA = signal number
+ tttttttt = address of symbol "_start"
+ dddddddd = base of data section
+ bbbbbbbb = base of bss section.
+ Note: only used by Cisco Systems
+ targets. The difference between this
+ reply and the "qOffsets" query is that
+ the 'N' packet may arrive spontaneously
+ whereas the 'qOffsets' is a query
+ initiated by the host debugger.
+ or... OXX..XX XX..XX is hex encoding of ASCII data. This
+ can happen at any time while the
+ program is running and the debugger
+ should continue to wait for
+ 'W', 'T', etc.
+
+ thread alive TXX Find out if the thread XX is alive.
+ reply OK thread is still alive
+ ENN thread is dead
+
+ remote restart RXX Restart the remote server
+
+ extended ops ! Use the extended remote protocol.
+ Sticky -- only needs to be set once.
+
+ kill request k
+
+ toggle debug d toggle debug flag (see 386 & 68k stubs)
+ reset r reset -- see sparc stub.
+ reserved On other requests, the stub should
+ ignore the request and send an empty
+ response ($#). This way
+ we can extend the protocol and GDB
+ can tell whether the stub it is
+ talking to uses the old or the new.
+ search tAA:PP,MM Search backwards starting at address
+ AA for a match with pattern PP and
+ mask MM. PP and MM are 4 bytes.
+ Not supported by all stubs.
+
+ general query qXXXX Request info about XXXX.
+ general set QXXXX=yyyy Set value of XXXX to yyyy.
+ query sect offs qOffsets Get section offsets. Reply is
+ Text=xxx;Data=yyy;Bss=zzz
+
+ Responses can be run-length encoded to save space. A '*' means that
+ the next character is an ASCII encoding giving a repeat count which
+ stands for that many repititions of the character preceding the '*'.
+ The encoding is n+29, yielding a printable character where n >=3
+ (which is where rle starts to win). Don't use an n > 126.
+
+ So
+ "0* " means the same as "0000". */
+/* *INDENT-ON* */
+
+/* This variable (available to the user via "set remotebinarydownload")
+ dictates whether downloads are sent in binary (via the 'X' packet).
+ We assume that the stub can, and attempt to do it. This will be cleared if
+ the stub does not understand it. This switch is still needed, though
+ in cases when the packet is supported in the stub, but the connection
+ does not allow it (i.e., 7-bit serial connection only). */
+static int remote_binary_download = 1;
+
+/* Have we already checked whether binary downloads work? */
+static int remote_binary_checked;
+
+/* Maximum number of bytes to read/write at once. The value here
+ is chosen to fill up a packet (the headers account for the 32). */
+#define MAXBUFBYTES(N) (((N)-32)/2)
+
+/* Having this larger than 400 causes us to be incompatible with m68k-stub.c
+ and i386-stub.c. Normally, no one would notice because it only matters
+ for writing large chunks of memory (e.g. in downloads). Also, this needs
+ to be more than 400 if required to hold the registers (see below, where
+ we round it up based on REGISTER_BYTES). */
+/* Round up PBUFSIZ to hold all the registers, at least. */
+#define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
+ ? (REGISTER_BYTES * 2 + 32) \
+ : 400)
+
+
+/* This variable sets the number of bytes to be written to the target
+ in a single packet. Normally PBUFSIZ is satisfactory, but some
+ targets need smaller values (perhaps because the receiving end
+ is slow). */
+
+static int remote_write_size = 0x7fffffff;
+
+/* This variable sets the number of bits in an address that are to be
+ sent in a memory ("M" or "m") packet. Normally, after stripping
+ leading zeros, the entire address would be sent. This variable
+ restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
+ initial implementation of remote.c restricted the address sent in
+ memory packets to ``host::sizeof long'' bytes - (typically 32
+ bits). Consequently, for 64 bit targets, the upper 32 bits of an
+ address was never sent. Since fixing this bug may cause a break in
+ some remote targets this variable is principly provided to
+ facilitate backward compatibility. */
+
+static int remote_address_size;
+
+/* Convert hex digit A to a number. */
+
+static int
+fromhex (int a)
+{
+ if (a >= '0' && a <= '9')
+ return a - '0';
+ else if (a >= 'a' && a <= 'f')
+ return a - 'a' + 10;
+ else if (a >= 'A' && a <= 'F')
+ return a - 'A' + 10;
+ else {
+ error ("Reply contains invalid hex digit %d", a);
+ return -1;
+ }
+}
+
+/* Convert number NIB to a hex digit. */
+
+static int
+tohex (int nib)
+{
+ if (nib < 10)
+ return '0' + nib;
+ else
+ return 'a' + nib - 10;
+}
+
+/* Return the number of hex digits in num. */
+
+static int
+hexnumlen (ULONGEST num)
+{
+ int i;
+
+ for (i = 0; num != 0; i++)
+ num >>= 4;
+
+ return max (i, 1);
+}
+
+/* Set BUF to the hex digits representing NUM. */
+
+static int
+hexnumstr (char *buf, ULONGEST num)
+{
+ int i;
+ int len = hexnumlen (num);
+
+ buf[len] = '\0';
+
+ for (i = len - 1; i >= 0; i--)
+ {
+ buf[i] = "0123456789abcdef"[(num & 0xf)];
+ num >>= 4;
+ }
+
+ return len;
+}
+
+/* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
+
+static CORE_ADDR
+remote_address_masked (CORE_ADDR addr)
+{
+ if (remote_address_size > 0
+ && remote_address_size < (sizeof (ULONGEST) * 8))
+ {
+ /* Only create a mask when that mask can safely be constructed
+ in a ULONGEST variable. */
+ ULONGEST mask = 1;
+ mask = (mask << remote_address_size) - 1;
+ addr &= mask;
+ }
+ return addr;
+}
+
+/* Determine whether the remote target supports binary downloading.
+ This is accomplished by sending a no-op memory write of zero length
+ to the target at the specified address. It does not suffice to send
+ the whole packet, since many stubs strip the eighth bit and subsequently
+ compute a wrong checksum, which causes real havoc with remote_write_bytes.
+
+ NOTE: This can still lose if the serial line is not eight-bit clean. In
+ cases like this, the user should clear "remotebinarydownload". */
+static void
+check_binary_download (CORE_ADDR addr)
+{
+ if (remote_binary_download && !remote_binary_checked)
+ {
+ char *buf = alloca (PBUFSIZ);
+ char *p;
+ remote_binary_checked = 1;
+
+ p = buf;
+ *p++ = 'X';
+ p += hexnumstr (p, (ULONGEST) addr);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) 0);
+ *p++ = ':';
+ *p = '\0';
+
+ putpkt_binary (buf, (int) (p - buf));
+ getpkt (buf, 0);
+
+ if (buf[0] == '\0')
+ remote_binary_download = 0;
+ }
+
+ if (remote_debug)
+ {
+ if (remote_binary_download)
+ fprintf_unfiltered (gdb_stdlog,
+ "binary downloading suppported by target\n");
+ else
+ fprintf_unfiltered (gdb_stdlog,
+ "binary downloading NOT suppported by target\n");
+ }
+}
+
+/* Write memory data directly to the remote machine.
+ This does not inform the data cache; the data cache uses this.
+ MEMADDR is the address in the remote memory space.
+ MYADDR is the address of the buffer in our space.
+ LEN is the number of bytes.
+
+ Returns number of bytes transferred, or 0 for error. */
+
+int
+remote_write_bytes (memaddr, myaddr, len)
+ CORE_ADDR memaddr;
+ char *myaddr;
+ int len;
+{
+ unsigned char *buf = alloca (PBUFSIZ);
+ int max_buf_size; /* Max size of packet output buffer */
+ int origlen;
+ extern int verbose;
+
+ /* Verify that the target can support a binary download */
+ check_binary_download (memaddr);
+
+ /* Chop the transfer down if necessary */
+
+ max_buf_size = min (remote_write_size, PBUFSIZ);
+ if (remote_register_buf_size != 0)
+ max_buf_size = min (max_buf_size, remote_register_buf_size);
+
+ /* Subtract header overhead from max payload size - $M,:#nn */
+ max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
+
+ origlen = len;
+ while (len > 0)
+ {
+ unsigned char *p, *plen;
+ int todo;
+ int i;
+
+ /* construct "M"","":" */
+ /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
+ memaddr = remote_address_masked (memaddr);
+ p = buf;
+ if (remote_binary_download)
+ {
+ *p++ = 'X';
+ todo = min (len, max_buf_size);
+ }
+ else
+ {
+ *p++ = 'M';
+ todo = min (len, max_buf_size / 2); /* num bytes that will fit */
+ }
+
+ p += hexnumstr ((char *)p, (ULONGEST) memaddr);
+ *p++ = ',';
+
+ plen = p; /* remember where len field goes */
+ p += hexnumstr ((char *)p, (ULONGEST) todo);
+ *p++ = ':';
+ *p = '\0';
+
+ /* We send target system values byte by byte, in increasing byte
+ addresses, each byte encoded as two hex characters (or one
+ binary character). */
+ if (remote_binary_download)
+ {
+ int escaped = 0;
+ for (i = 0;
+ (i < todo) && (i + escaped) < (max_buf_size - 2);
+ i++)
+ {
+ switch (myaddr[i] & 0xff)
+ {
+ case '$':
+ case '#':
+ case 0x7d:
+ /* These must be escaped */
+ escaped++;
+ *p++ = 0x7d;
+ *p++ = (myaddr[i] & 0xff) ^ 0x20;
+ break;
+ default:
+ *p++ = myaddr[i] & 0xff;
+ break;
+ }
+ }
+
+ if (i < todo)
+ {
+ /* Escape chars have filled up the buffer prematurely,
+ and we have actually sent fewer bytes than planned.
+ Fix-up the length field of the packet. */
+
+ /* FIXME: will fail if new len is a shorter string than
+ old len. */
+
+ plen += hexnumstr ((char *)plen, (ULONGEST) i);
+ *plen++ = ':';
+ }
+ }
+ else
+ {
+ for (i = 0; i < todo; i++)
+ {
+ *p++ = tohex ((myaddr[i] >> 4) & 0xf);
+ *p++ = tohex (myaddr[i] & 0xf);
+ }
+ *p = '\0';
+ }
+
+ putpkt_binary ((char *)buf, (int) (p - buf));
+ getpkt ((char *)buf, 0);
+
+ if (buf[0] == 'E')
+ {
+ /* There is no correspondance between what the remote protocol uses
+ for errors and errno codes. We would like a cleaner way of
+ representing errors (big enough to include errno codes, bfd_error
+ codes, and others). But for now just return EIO. */
+ errno = EIO;
+ return 0;
+ }
+
+ /* Increment by i, not by todo, in case escape chars
+ caused us to send fewer bytes than we'd planned. */
+ myaddr += i;
+ memaddr += i;
+ len -= i;
+
+ if (verbose)
+ putc('.', stderr);
+ }
+ return origlen;
+}
+
+/* Stuff for dealing with the packets which are part of this protocol.
+ See comment at top of file for details. */
+
+/* Read a single character from the remote end, masking it down to 7 bits. */
+
+static int
+readchar (int timeout)
+{
+ int ch;
+
+ ch = SERIAL_READCHAR (remote_desc, timeout);
+
+ switch (ch)
+ {
+ case SERIAL_EOF:
+ error ("Remote connection closed");
+ case SERIAL_ERROR:
+ perror_with_name ("Remote communication error");
+ case SERIAL_TIMEOUT:
+ return ch;
+ default:
+ return ch & 0x7f;
+ }
+}
+
+static int
+putpkt (buf)
+ char *buf;
+{
+ return putpkt_binary (buf, strlen (buf));
+}
+
+/* Send a packet to the remote machine, with error checking. The data
+ of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
+ to account for the $, # and checksum, and for a possible /0 if we are
+ debugging (remote_debug) and want to print the sent packet as a string */
+
+static int
+putpkt_binary (buf, cnt)
+ char *buf;
+ int cnt;
+{
+ int i;
+ unsigned char csum = 0;
+ char *buf2 = alloca (PBUFSIZ);
+ char *junkbuf = alloca (PBUFSIZ);
+
+ int ch;
+ int tcount = 0;
+ char *p;
+
+ /* Copy the packet into buffer BUF2, encapsulating it
+ and giving it a checksum. */
+
+ if (cnt > BUFSIZ - 5) /* Prosanity check */
+ abort ();
+
+ p = buf2;
+ *p++ = '$';
+
+ for (i = 0; i < cnt; i++)
+ {
+ csum += buf[i];
+ *p++ = buf[i];
+ }
+ *p++ = '#';
+ *p++ = tohex ((csum >> 4) & 0xf);
+ *p++ = tohex (csum & 0xf);
+
+ /* Send it over and over until we get a positive ack. */
+
+ while (1)
+ {
+ int started_error_output = 0;
+
+ if (remote_debug)
+ {
+ *p = '\0';
+ fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
+ fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
+ fprintf_unfiltered (gdb_stdlog, "...");
+ gdb_flush (gdb_stdlog);
+ }
+ if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
+ perror_with_name ("putpkt: write failed");
+
+ /* read until either a timeout occurs (-2) or '+' is read */
+ while (1)
+ {
+ ch = readchar (remote_timeout);
+
+ if (remote_debug)
+ {
+ switch (ch)
+ {
+ case '+':
+ case SERIAL_TIMEOUT:
+ case '$':
+ if (started_error_output)
+ {
+ putchar_unfiltered ('\n');
+ started_error_output = 0;
+ }
+ }
+ }
+
+ switch (ch)
+ {
+ case '+':
+ if (remote_debug)
+ fprintf_unfiltered (gdb_stdlog, "Ack\n");
+ return 1;
+ case SERIAL_TIMEOUT:
+ tcount++;
+ if (tcount > 3)
+ return 0;
+ break; /* Retransmit buffer */
+ case '$':
+ {
+ /* It's probably an old response, and we're out of sync.
+ Just gobble up the packet and ignore it. */
+ getpkt (junkbuf, 0);
+ continue; /* Now, go look for + */
+ }
+ default:
+ if (remote_debug)
+ {
+ if (!started_error_output)
+ {
+ started_error_output = 1;
+ fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
+ }
+ fputc_unfiltered (ch & 0177, gdb_stdlog);
+ }
+ continue;
+ }
+ break; /* Here to retransmit */
+ }
+
+#if 0
+ /* This is wrong. If doing a long backtrace, the user should be
+ able to get out next time we call QUIT, without anything as
+ violent as interrupt_query. If we want to provide a way out of
+ here without getting to the next QUIT, it should be based on
+ hitting ^C twice as in remote_wait. */
+ if (quit_flag)
+ {
+ quit_flag = 0;
+ interrupt_query ();
+ }
+#endif
+ }
+}
+
+/* Come here after finding the start of the frame. Collect the rest
+ into BUF, verifying the checksum, length, and handling run-length
+ compression. Returns 0 on any error, 1 on success. */
+
+static int
+read_frame (char *buf)
+{
+ unsigned char csum;
+ char *bp;
+ int c;
+
+ csum = 0;
+ bp = buf;
+
+ while (1)
+ {
+ c = readchar (remote_timeout);
+
+ switch (c)
+ {
+ case SERIAL_TIMEOUT:
+ if (remote_debug)
+ fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
+ return 0;
+ case '$':
+ if (remote_debug)
+ fputs_filtered ("Saw new packet start in middle of old one\n",
+ gdb_stdlog);
+ return 0; /* Start a new packet, count retries */
+ case '#':
+ {
+ unsigned char pktcsum;
+
+ *bp = '\000';
+
+ pktcsum = fromhex (readchar (remote_timeout)) << 4;
+ pktcsum |= fromhex (readchar (remote_timeout));
+
+ if (csum == pktcsum)
+ {
+ return 1;
+ }
+
+ if (remote_debug)
+ {
+ fprintf_filtered (gdb_stdlog,
+ "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
+ pktcsum, csum);
+ fputs_filtered (buf, gdb_stdlog);
+ fputs_filtered ("\n", gdb_stdlog);
+ }
+ return 0;
+ }
+ case '*': /* Run length encoding */
+ csum += c;
+ c = readchar (remote_timeout);
+ csum += c;
+ c = c - ' ' + 3; /* Compute repeat count */
+
+ if (c > 0 && c < 255 && bp + c - 1 < buf + PBUFSIZ - 1)
+ {
+ memset (bp, *(bp - 1), c);
+ bp += c;
+ continue;
+ }
+
+ *bp = '\0';
+ printf_filtered ("Repeat count %d too large for buffer: ", c);
+ puts_filtered (buf);
+ puts_filtered ("\n");
+ return 0;
+ default:
+ if (bp < buf + PBUFSIZ - 1)
+ {
+ *bp++ = c;
+ csum += c;
+ continue;
+ }
+
+ *bp = '\0';
+ puts_filtered ("Remote packet too long: ");
+ puts_filtered (buf);
+ puts_filtered ("\n");
+
+ return 0;
+ }
+ }
+}
+
+/* Read a packet from the remote machine, with error checking, and
+ store it in BUF. BUF is expected to be of size PBUFSIZ. If
+ FOREVER, wait forever rather than timing out; this is used while
+ the target is executing user code. */
+
+static void
+getpkt (buf, forever)
+ char *buf;
+ int forever;
+{
+ int c;
+ int tries;
+ int timeout;
+ int val;
+
+ strcpy (buf, "timeout");
+
+ if (forever)
+ {
+ timeout = watchdog > 0 ? watchdog : -1;
+ }
+
+ else
+ timeout = remote_timeout;
+
+#define MAX_TRIES 3
+
+ for (tries = 1; tries <= MAX_TRIES; tries++)
+ {
+ /* This can loop forever if the remote side sends us characters
+ continuously, but if it pauses, we'll get a zero from readchar
+ because of timeout. Then we'll count that as a retry. */
+
+ /* Note that we will only wait forever prior to the start of a packet.
+ After that, we expect characters to arrive at a brisk pace. They
+ should show up within remote_timeout intervals. */
+
+ do
+ {
+ c = readchar (timeout);
+
+ if (c == SERIAL_TIMEOUT)
+ {
+ if (forever) /* Watchdog went off. Kill the target. */
+ {
+ target_mourn_inferior ();
+ error ("Watchdog has expired. Target detached.\n");
+ }
+ if (remote_debug)
+ fputs_filtered ("Timed out.\n", gdb_stdlog);
+ goto retry;
+ }
+ }
+ while (c != '$');
+
+ /* We've found the start of a packet, now collect the data. */
+
+ val = read_frame (buf);
+
+ if (val == 1)
+ {
+ if (remote_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog, "Packet received: ");
+ fputstr_unfiltered (buf, 0, gdb_stdlog);
+ fprintf_unfiltered (gdb_stdlog, "\n");
+ }
+ SERIAL_WRITE (remote_desc, "+", 1);
+ return;
+ }
+
+ /* Try the whole thing again. */
+ retry:
+ SERIAL_WRITE (remote_desc, "-", 1);
+ }
+
+ /* We have tried hard enough, and just can't receive the packet. Give up. */
+
+ printf_unfiltered ("Ignoring packet error, continuing...\n");
+ SERIAL_WRITE (remote_desc, "+", 1);
+}
diff --git a/roms/u-boot/tools/gdb/remote.h b/roms/u-boot/tools/gdb/remote.h
new file mode 100644
index 00000000..df6b0698
--- /dev/null
+++ b/roms/u-boot/tools/gdb/remote.h
@@ -0,0 +1,12 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+extern int remote_desc, remote_timeout;
+
+extern void remote_reset(void);
+extern void remote_continue(void);
+extern int remote_write_bytes(unsigned long, char *, int);
diff --git a/roms/u-boot/tools/gdb/serial.c b/roms/u-boot/tools/gdb/serial.c
new file mode 100644
index 00000000..709f8cef
--- /dev/null
+++ b/roms/u-boot/tools/gdb/serial.c
@@ -0,0 +1,133 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include "serial.h"
+
+#if defined(__sun__) || \
+ defined(__OpenBSD__) || \
+ defined(__FreeBSD__) || \
+ defined(__NetBSD__) || \
+ defined(__APPLE__)
+static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, { 0 } };
+#else
+static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, 0 };
+#endif
+
+static struct speedmap {
+ char *str;
+ speed_t val;
+} speedmap[] = {
+ { "50", B50 }, { "75", B75 }, { "110", B110 },
+ { "134", B134 }, { "150", B150 }, { "200", B200 },
+ { "300", B300 }, { "600", B600 }, { "1200", B1200 },
+ { "1800", B1800 }, { "2400", B2400 }, { "4800", B4800 },
+ { "9600", B9600 }, { "19200", B19200 }, { "38400", B38400 },
+ { "57600", B57600 },
+#ifdef B76800
+ { "76800", B76800 },
+#endif
+ { "115200", B115200 },
+#ifdef B153600
+ { "153600", B153600 },
+#endif
+ { "230400", B230400 },
+#ifdef B307200
+ { "307200", B307200 },
+#endif
+#ifdef B460800
+ { "460800", B460800 }
+#endif
+};
+static int nspeeds = sizeof speedmap / sizeof speedmap[0];
+
+speed_t
+cvtspeed(char *str)
+{
+ struct speedmap *smp = speedmap, *esmp = &speedmap[nspeeds];
+
+ while (smp < esmp) {
+ if (strcmp(str, smp->str) == 0)
+ return (smp->val);
+ smp++;
+ }
+ return B0;
+}
+
+int
+serialopen(char *device, speed_t speed)
+{
+ int fd;
+
+ if (cfsetospeed(&tios, speed) < 0)
+ return -1;
+
+ if ((fd = open(device, O_RDWR)) < 0)
+ return -1;
+
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
+ (void)close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+int
+serialreadchar(int fd, int timeout)
+{
+ fd_set fds;
+ struct timeval tv;
+ int n;
+ char ch;
+
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ /* this is a fucking horrible quick hack - fix this */
+
+ if ((n = select(fd + 1, &fds, 0, 0, &tv)) < 0)
+ return SERIAL_ERROR;
+
+ if (n == 0)
+ return SERIAL_TIMEOUT;
+
+ if ((n = read(fd, &ch, 1)) < 0)
+ return SERIAL_ERROR;
+
+ if (n == 0)
+ return SERIAL_EOF;
+
+ return ch;
+}
+
+int
+serialwrite(int fd, char *buf, int len)
+{
+ int n;
+
+ do {
+ n = write(fd, buf, len);
+ if (n < 0)
+ return 1;
+ len -= n;
+ buf += n;
+ } while (len > 0);
+ return 0;
+}
+
+int
+serialclose(int fd)
+{
+ return close(fd);
+}
diff --git a/roms/u-boot/tools/gdb/serial.h b/roms/u-boot/tools/gdb/serial.h
new file mode 100644
index 00000000..dc9d6b7e
--- /dev/null
+++ b/roms/u-boot/tools/gdb/serial.h
@@ -0,0 +1,18 @@
+/*
+ * (C) Copyright 2000
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+
+#define SERIAL_ERROR -1 /* General error, see errno for details */
+#define SERIAL_TIMEOUT -2
+#define SERIAL_EOF -3
+
+extern speed_t cvtspeed(char *);
+extern int serialopen(char *, speed_t);
+extern int serialreadchar(int, int);
+extern int serialwrite(int, char *, int);
+extern int serialclose(int);
diff --git a/roms/u-boot/tools/gen_eth_addr.c b/roms/u-boot/tools/gen_eth_addr.c
new file mode 100644
index 00000000..bf9d935e
--- /dev/null
+++ b/roms/u-boot/tools/gen_eth_addr.c
@@ -0,0 +1,34 @@
+/*
+ * (C) Copyright 2001
+ * Murray Jensen
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+
+int
+main(int argc, char *argv[])
+{
+ unsigned long ethaddr_low, ethaddr_high;
+
+ srand(time(0) | getpid());
+
+ /*
+ * setting the 2nd LSB in the most significant byte of
+ * the address makes it a locally administered ethernet
+ * address
+ */
+ ethaddr_high = (rand() & 0xfeff) | 0x0200;
+ ethaddr_low = rand();
+
+ printf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx\n",
+ ethaddr_high >> 8, ethaddr_high & 0xff,
+ ethaddr_low >> 24, (ethaddr_low >> 16) & 0xff,
+ (ethaddr_low >> 8) & 0xff, ethaddr_low & 0xff);
+
+ return (0);
+}
diff --git a/roms/u-boot/tools/getline.c b/roms/u-boot/tools/getline.c
new file mode 100644
index 00000000..f7dbcc9b
--- /dev/null
+++ b/roms/u-boot/tools/getline.c
@@ -0,0 +1,90 @@
+/* getline.c -- Replacement for GNU C library function getline
+ *
+ * Copyright (C) 1993, 1996, 2001, 2002 Free Software Foundation, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */
+
+#include
+#include
+
+/* Always add at least this many bytes when extending the buffer. */
+#define MIN_CHUNK 64
+
+/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+ + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
+ malloc (or NULL), pointing to *N characters of space. It is realloc'd
+ as necessary. Return the number of characters read (not including the
+ null terminator), or -1 on error or EOF.
+ NOTE: There is another getstr() function declared in . */
+static int getstr(char **lineptr, size_t *n, FILE *stream,
+ char terminator, size_t offset)
+{
+ int nchars_avail; /* Allocated but unused chars in *LINEPTR. */
+ char *read_pos; /* Where we're reading into *LINEPTR. */
+ int ret;
+
+ if (!lineptr || !n || !stream)
+ return -1;
+
+ if (!*lineptr) {
+ *n = MIN_CHUNK;
+ *lineptr = malloc(*n);
+ if (!*lineptr)
+ return -1;
+ }
+
+ nchars_avail = *n - offset;
+ read_pos = *lineptr + offset;
+
+ for (;;) {
+ register int c = getc(stream);
+
+ /* We always want at least one char left in the buffer, since we
+ always (unless we get an error while reading the first char)
+ NUL-terminate the line buffer. */
+
+ assert(*n - nchars_avail == read_pos - *lineptr);
+ if (nchars_avail < 2) {
+ if (*n > MIN_CHUNK)
+ *n *= 2;
+ else
+ *n += MIN_CHUNK;
+
+ nchars_avail = *n + *lineptr - read_pos;
+ *lineptr = realloc(*lineptr, *n);
+ if (!*lineptr)
+ return -1;
+ read_pos = *n - nchars_avail + *lineptr;
+ assert(*n - nchars_avail == read_pos - *lineptr);
+ }
+
+ if (c == EOF || ferror (stream)) {
+ /* Return partial line, if any. */
+ if (read_pos == *lineptr)
+ return -1;
+ else
+ break;
+ }
+
+ *read_pos++ = c;
+ nchars_avail--;
+
+ if (c == terminator)
+ /* Return the line. */
+ break;
+ }
+
+ /* Done - NUL terminate and return the number of chars read. */
+ *read_pos = '\0';
+
+ ret = read_pos - (*lineptr + offset);
+ return ret;
+}
+
+int getline (char **lineptr, size_t *n, FILE *stream)
+{
+ return getstr(lineptr, n, stream, '\n', 0);
+}
diff --git a/roms/u-boot/tools/getline.h b/roms/u-boot/tools/getline.h
new file mode 100644
index 00000000..a2f35b92
--- /dev/null
+++ b/roms/u-boot/tools/getline.h
@@ -0,0 +1 @@
+int getline(char **lineptr, size_t *n, FILE *stream);
diff --git a/roms/u-boot/tools/gpheader.h b/roms/u-boot/tools/gpheader.h
new file mode 100644
index 00000000..63a28a26
--- /dev/null
+++ b/roms/u-boot/tools/gpheader.h
@@ -0,0 +1,40 @@
+/*
+ * (C) Copyright 2014
+ * Texas Instruments Incorporated
+ * Refactored common functions in to gpimage-common.c. Include this common
+ * header file
+ *
+ * (C) Copyright 2010
+ * Linaro LTD, www.linaro.org
+ * Author: John Rigby
+ * Based on TI's signGP.c
+ *
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _GPIMAGE_H_
+#define _GPIMAGE_H_
+
+/* common headers for gpimage and omapimage formats */
+struct gp_header {
+ uint32_t size;
+ uint32_t load_addr;
+};
+#define GPIMAGE_HDR_SIZE (sizeof(struct gp_header))
+
+/* common functions across gpimage and omapimage handlers */
+int valid_gph_size(uint32_t size);
+int valid_gph_load_addr(uint32_t load_addr);
+int gph_verify_header(struct gp_header *gph, int be);
+void gph_print_header(const struct gp_header *gph, int be);
+void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr,
+ int be);
+int gpimage_check_params(struct image_tool_params *params);
+#endif
diff --git a/roms/u-boot/tools/gpimage-common.c b/roms/u-boot/tools/gpimage-common.c
new file mode 100644
index 00000000..b343a3aa
--- /dev/null
+++ b/roms/u-boot/tools/gpimage-common.c
@@ -0,0 +1,80 @@
+/*
+ * (C) Copyright 2014
+ * Texas Instruments Incorporated
+ * Refactored common functions in to gpimage-common.c.
+ *
+ * (C) Copyright 2010
+ * Linaro LTD, www.linaro.org
+ * Author: John Rigby
+ * Based on TI's signGP.c
+ *
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include
+#include
+#include "gpheader.h"
+
+/* Helper to convert size and load_addr to big endian */
+void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)
+{
+ *gph_size = cpu_to_be32(*gph_size);
+ *gph_load_addr = cpu_to_be32(*gph_load_addr);
+}
+
+int gph_verify_header(struct gp_header *gph, int be)
+{
+ uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
+
+ if (be)
+ to_be32(&gph_size, &gph_load_addr);
+
+ if (!gph_size || !gph_load_addr)
+ return -1;
+
+ return 0;
+}
+
+void gph_print_header(const struct gp_header *gph, int be)
+{
+ uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
+
+ if (be)
+ to_be32(&gph_size, &gph_load_addr);
+
+ if (!gph_size) {
+ fprintf(stderr, "Error: invalid image size %x\n", gph_size);
+ exit(EXIT_FAILURE);
+ }
+
+ if (!gph_load_addr) {
+ fprintf(stderr, "Error: invalid image load address %x\n",
+ gph_load_addr);
+ exit(EXIT_FAILURE);
+ }
+ printf("GP Header: Size %x LoadAddr %x\n", gph_size, gph_load_addr);
+}
+
+void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr,
+ int be)
+{
+ gph->size = size;
+ gph->load_addr = load_addr;
+ if (be)
+ to_be32(&gph->size, &gph->load_addr);
+}
+
+int gpimage_check_params(struct image_tool_params *params)
+{
+ return (params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag));
+}
diff --git a/roms/u-boot/tools/gpimage.c b/roms/u-boot/tools/gpimage.c
new file mode 100644
index 00000000..1cabb5b6
--- /dev/null
+++ b/roms/u-boot/tools/gpimage.c
@@ -0,0 +1,77 @@
+/*
+ * (C) Copyright 2014
+ * Texas Instruments Incorporated
+ * Add gpimage format for keystone devices to format spl image. This is
+ * Based on omapimage.c
+ *
+ * (C) Copyright 2010
+ * Linaro LTD, www.linaro.org
+ * Author: John Rigby
+ * Based on TI's signGP.c
+ *
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include
+#include
+#include "gpheader.h"
+
+static uint8_t gpimage_header[GPIMAGE_HDR_SIZE];
+
+/* to be in keystone gpimage */
+static int gpimage_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_GPIMAGE)
+ return EXIT_SUCCESS;
+ return EXIT_FAILURE;
+}
+
+static int gpimage_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ struct gp_header *gph = (struct gp_header *)ptr;
+
+ return gph_verify_header(gph, 1);
+}
+
+static void gpimage_print_header(const void *ptr)
+{
+ const struct gp_header *gph = (struct gp_header *)ptr;
+
+ gph_print_header(gph, 1);
+}
+
+static void gpimage_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ struct gp_header *gph = (struct gp_header *)ptr;
+
+ gph_set_header(gph, sbuf->st_size - GPIMAGE_HDR_SIZE, params->addr, 1);
+}
+
+/*
+ * gpimage parameters
+ */
+static struct image_type_params gpimage_params = {
+ .name = "TI KeyStone GP Image support",
+ .header_size = GPIMAGE_HDR_SIZE,
+ .hdr = (void *)&gpimage_header,
+ .check_image_type = gpimage_check_image_types,
+ .verify_header = gpimage_verify_header,
+ .print_header = gpimage_print_header,
+ .set_header = gpimage_set_header,
+ .check_params = gpimage_check_params,
+};
+
+void init_gpimage_type(void)
+{
+ register_image_type(&gpimage_params);
+}
diff --git a/roms/u-boot/tools/image-fit.c b/roms/u-boot/tools/image-fit.c
new file mode 100644
index 00000000..037e5cc8
--- /dev/null
+++ b/roms/u-boot/tools/image-fit.c
@@ -0,0 +1 @@
+#include "../common/image-fit.c"
diff --git a/roms/u-boot/tools/image-host.c b/roms/u-boot/tools/image-host.c
new file mode 100644
index 00000000..651f1c2f
--- /dev/null
+++ b/roms/u-boot/tools/image-host.c
@@ -0,0 +1,712 @@
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2006
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "mkimage.h"
+#include
+#include
+
+/**
+ * fit_set_hash_value - set hash value in requested has node
+ * @fit: pointer to the FIT format image header
+ * @noffset: hash node offset
+ * @value: hash value to be set
+ * @value_len: hash value length
+ *
+ * fit_set_hash_value() attempts to set hash value in a node at offset
+ * given and returns operation status to the caller.
+ *
+ * returns
+ * 0, on success
+ * -1, on failure
+ */
+static int fit_set_hash_value(void *fit, int noffset, uint8_t *value,
+ int value_len)
+{
+ int ret;
+
+ ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
+ if (ret) {
+ printf("Can't set hash '%s' property for '%s' node(%s)\n",
+ FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL),
+ fdt_strerror(ret));
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * fit_image_process_hash - Process a single subnode of the images/ node
+ *
+ * Check each subnode and process accordingly. For hash nodes we generate
+ * a hash of the supplised data and store it in the node.
+ *
+ * @fit: pointer to the FIT format image header
+ * @image_name: name of image being processes (used to display errors)
+ * @noffset: subnode offset
+ * @data: data to process
+ * @size: size of data in bytes
+ * @return 0 if ok, -1 on error
+ */
+static int fit_image_process_hash(void *fit, const char *image_name,
+ int noffset, const void *data, size_t size)
+{
+ uint8_t value[FIT_MAX_HASH_LEN];
+ const char *node_name;
+ int value_len;
+ char *algo;
+
+ node_name = fit_get_name(fit, noffset, NULL);
+
+ if (fit_image_hash_get_algo(fit, noffset, &algo)) {
+ printf("Can't get hash algo property for '%s' hash node in '%s' image node\n",
+ node_name, image_name);
+ return -1;
+ }
+
+ if (calculate_hash(data, size, algo, value, &value_len)) {
+ printf("Unsupported hash algorithm (%s) for '%s' hash node in '%s' image node\n",
+ algo, node_name, image_name);
+ return -1;
+ }
+
+ if (fit_set_hash_value(fit, noffset, value, value_len)) {
+ printf("Can't set hash value for '%s' hash node in '%s' image node\n",
+ node_name, image_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * fit_image_write_sig() - write the signature to a FIT
+ *
+ * This writes the signature and signer data to the FIT.
+ *
+ * @fit: pointer to the FIT format image header
+ * @noffset: hash node offset
+ * @value: signature value to be set
+ * @value_len: signature value length
+ * @comment: Text comment to write (NULL for none)
+ *
+ * returns
+ * 0, on success
+ * -FDT_ERR_..., on failure
+ */
+static int fit_image_write_sig(void *fit, int noffset, uint8_t *value,
+ int value_len, const char *comment, const char *region_prop,
+ int region_proplen)
+{
+ int string_size;
+ int ret;
+
+ /*
+ * Get the current string size, before we update the FIT and add
+ * more
+ */
+ string_size = fdt_size_dt_strings(fit);
+
+ ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
+ if (!ret) {
+ ret = fdt_setprop_string(fit, noffset, "signer-name",
+ "mkimage");
+ }
+ if (!ret) {
+ ret = fdt_setprop_string(fit, noffset, "signer-version",
+ PLAIN_VERSION);
+ }
+ if (comment && !ret)
+ ret = fdt_setprop_string(fit, noffset, "comment", comment);
+ if (!ret)
+ ret = fit_set_timestamp(fit, noffset, time(NULL));
+ if (region_prop && !ret) {
+ uint32_t strdata[2];
+
+ ret = fdt_setprop(fit, noffset, "hashed-nodes",
+ region_prop, region_proplen);
+ strdata[0] = 0;
+ strdata[1] = cpu_to_fdt32(string_size);
+ if (!ret) {
+ ret = fdt_setprop(fit, noffset, "hashed-strings",
+ strdata, sizeof(strdata));
+ }
+ }
+
+ return ret;
+}
+
+static int fit_image_setup_sig(struct image_sign_info *info,
+ const char *keydir, void *fit, const char *image_name,
+ int noffset, const char *require_keys)
+{
+ const char *node_name;
+ char *algo_name;
+
+ node_name = fit_get_name(fit, noffset, NULL);
+ if (fit_image_hash_get_algo(fit, noffset, &algo_name)) {
+ printf("Can't get algo property for '%s' signature node in '%s' image node\n",
+ node_name, image_name);
+ return -1;
+ }
+
+ memset(info, '\0', sizeof(*info));
+ info->keydir = keydir;
+ info->keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
+ info->fit = fit;
+ info->node_offset = noffset;
+ info->algo = image_get_sig_algo(algo_name);
+ info->require_keys = require_keys;
+ if (!info->algo) {
+ printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
+ algo_name, node_name, image_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * fit_image_process_sig- Process a single subnode of the images/ node
+ *
+ * Check each subnode and process accordingly. For signature nodes we
+ * generate a signed hash of the supplised data and store it in the node.
+ *
+ * @keydir: Directory containing keys to use for signing
+ * @keydest: Destination FDT blob to write public keys into
+ * @fit: pointer to the FIT format image header
+ * @image_name: name of image being processes (used to display errors)
+ * @noffset: subnode offset
+ * @data: data to process
+ * @size: size of data in bytes
+ * @comment: Comment to add to signature nodes
+ * @require_keys: Mark all keys as 'required'
+ * @return 0 if ok, -1 on error
+ */
+static int fit_image_process_sig(const char *keydir, void *keydest,
+ void *fit, const char *image_name,
+ int noffset, const void *data, size_t size,
+ const char *comment, int require_keys)
+{
+ struct image_sign_info info;
+ struct image_region region;
+ const char *node_name;
+ uint8_t *value;
+ uint value_len;
+ int ret;
+
+ if (fit_image_setup_sig(&info, keydir, fit, image_name, noffset,
+ require_keys ? "image" : NULL))
+ return -1;
+
+ node_name = fit_get_name(fit, noffset, NULL);
+ region.data = data;
+ region.size = size;
+ ret = info.algo->sign(&info, ®ion, 1, &value, &value_len);
+ if (ret) {
+ printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
+ node_name, image_name, ret);
+
+ /* We allow keys to be missing */
+ if (ret == -ENOENT)
+ return 0;
+ return -1;
+ }
+
+ ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
+ NULL, 0);
+ if (ret) {
+ printf("Can't write signature for '%s' signature node in '%s' image node: %s\n",
+ node_name, image_name, fdt_strerror(ret));
+ return -1;
+ }
+ free(value);
+
+ /* Get keyname again, as FDT has changed and invalidated our pointer */
+ info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
+
+ /* Write the public key into the supplied FDT file */
+ if (keydest && info.algo->add_verify_data(&info, keydest)) {
+ printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
+ node_name, image_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * fit_image_add_verification_data() - calculate/set verig. data for image node
+ *
+ * This adds hash and signature values for an component image node.
+ *
+ * All existing hash subnodes are checked, if algorithm property is set to
+ * one of the supported hash algorithms, hash value is computed and
+ * corresponding hash node property is set, for example:
+ *
+ * Input component image node structure:
+ *
+ * o image@1 (at image_noffset)
+ * | - data = [binary data]
+ * o hash@1
+ * |- algo = "sha1"
+ *
+ * Output component image node structure:
+ *
+ * o image@1 (at image_noffset)
+ * | - data = [binary data]
+ * o hash@1
+ * |- algo = "sha1"
+ * |- value = sha1(data)
+ *
+ * For signature details, please see doc/uImage.FIT/signature.txt
+ *
+ * @keydir Directory containing *.key and *.crt files (or NULL)
+ * @keydest FDT Blob to write public keys into (NULL if none)
+ * @fit: Pointer to the FIT format image header
+ * @image_noffset: Requested component image node
+ * @comment: Comment to add to signature nodes
+ * @require_keys: Mark all keys as 'required'
+ * @return: 0 on success, <0 on failure
+ */
+int fit_image_add_verification_data(const char *keydir, void *keydest,
+ void *fit, int image_noffset, const char *comment,
+ int require_keys)
+{
+ const char *image_name;
+ const void *data;
+ size_t size;
+ int noffset;
+
+ /* Get image data and data length */
+ if (fit_image_get_data(fit, image_noffset, &data, &size)) {
+ printf("Can't get image data/size\n");
+ return -1;
+ }
+
+ image_name = fit_get_name(fit, image_noffset, NULL);
+
+ /* Process all hash subnodes of the component image node */
+ for (noffset = fdt_first_subnode(fit, image_noffset);
+ noffset >= 0;
+ noffset = fdt_next_subnode(fit, noffset)) {
+ const char *node_name;
+ int ret = 0;
+
+ /*
+ * Check subnode name, must be equal to "hash" or "signature".
+ * Multiple hash nodes require unique unit node
+ * names, e.g. hash@1, hash@2, signature@1, etc.
+ */
+ node_name = fit_get_name(fit, noffset, NULL);
+ if (!strncmp(node_name, FIT_HASH_NODENAME,
+ strlen(FIT_HASH_NODENAME))) {
+ ret = fit_image_process_hash(fit, image_name, noffset,
+ data, size);
+ } else if (IMAGE_ENABLE_SIGN && keydir &&
+ !strncmp(node_name, FIT_SIG_NODENAME,
+ strlen(FIT_SIG_NODENAME))) {
+ ret = fit_image_process_sig(keydir, keydest,
+ fit, image_name, noffset, data, size,
+ comment, require_keys);
+ }
+ if (ret)
+ return -1;
+ }
+
+ return 0;
+}
+
+struct strlist {
+ int count;
+ char **strings;
+};
+
+static void strlist_init(struct strlist *list)
+{
+ memset(list, '\0', sizeof(*list));
+}
+
+static void strlist_free(struct strlist *list)
+{
+ int i;
+
+ for (i = 0; i < list->count; i++)
+ free(list->strings[i]);
+ free(list->strings);
+}
+
+static int strlist_add(struct strlist *list, const char *str)
+{
+ char *dup;
+
+ dup = strdup(str);
+ list->strings = realloc(list->strings,
+ (list->count + 1) * sizeof(char *));
+ if (!list || !str)
+ return -1;
+ list->strings[list->count++] = dup;
+
+ return 0;
+}
+
+static const char *fit_config_get_image_list(void *fit, int noffset,
+ int *lenp, int *allow_missingp)
+{
+ static const char default_list[] = FIT_KERNEL_PROP "\0"
+ FIT_FDT_PROP;
+ const char *prop;
+
+ /* If there is an "image" property, use that */
+ prop = fdt_getprop(fit, noffset, "sign-images", lenp);
+ if (prop) {
+ *allow_missingp = 0;
+ return *lenp ? prop : NULL;
+ }
+
+ /* Default image list */
+ *allow_missingp = 1;
+ *lenp = sizeof(default_list);
+
+ return default_list;
+}
+
+static int fit_config_get_hash_list(void *fit, int conf_noffset,
+ int sig_offset, struct strlist *node_inc)
+{
+ int allow_missing;
+ const char *prop, *iname, *end;
+ const char *conf_name, *sig_name;
+ char name[200], path[200];
+ int image_count;
+ int ret, len;
+
+ conf_name = fit_get_name(fit, conf_noffset, NULL);
+ sig_name = fit_get_name(fit, sig_offset, NULL);
+
+ /*
+ * Build a list of nodes we need to hash. We always need the root
+ * node and the configuration.
+ */
+ strlist_init(node_inc);
+ snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
+ if (strlist_add(node_inc, "/") ||
+ strlist_add(node_inc, name))
+ goto err_mem;
+
+ /* Get a list of images that we intend to sign */
+ prop = fit_config_get_image_list(fit, sig_offset, &len,
+ &allow_missing);
+ if (!prop)
+ return 0;
+
+ /* Locate the images */
+ end = prop + len;
+ image_count = 0;
+ for (iname = prop; iname < end; iname += strlen(iname) + 1) {
+ int noffset;
+ int image_noffset;
+ int hash_count;
+
+ image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
+ iname);
+ if (image_noffset < 0) {
+ printf("Failed to find image '%s' in configuration '%s/%s'\n",
+ iname, conf_name, sig_name);
+ if (allow_missing)
+ continue;
+
+ return -ENOENT;
+ }
+
+ ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
+ if (ret < 0)
+ goto err_path;
+ if (strlist_add(node_inc, path))
+ goto err_mem;
+
+ snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
+ conf_name);
+
+ /* Add all this image's hashes */
+ hash_count = 0;
+ for (noffset = fdt_first_subnode(fit, image_noffset);
+ noffset >= 0;
+ noffset = fdt_next_subnode(fit, noffset)) {
+ const char *name = fit_get_name(fit, noffset, NULL);
+
+ if (strncmp(name, FIT_HASH_NODENAME,
+ strlen(FIT_HASH_NODENAME)))
+ continue;
+ ret = fdt_get_path(fit, noffset, path, sizeof(path));
+ if (ret < 0)
+ goto err_path;
+ if (strlist_add(node_inc, path))
+ goto err_mem;
+ hash_count++;
+ }
+
+ if (!hash_count) {
+ printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
+ conf_name, sig_name, iname);
+ return -ENOMSG;
+ }
+
+ image_count++;
+ }
+
+ if (!image_count) {
+ printf("Failed to find any images for configuration '%s/%s'\n",
+ conf_name, sig_name);
+ return -ENOMSG;
+ }
+
+ return 0;
+
+err_mem:
+ printf("Out of memory processing configuration '%s/%s'\n", conf_name,
+ sig_name);
+ return -ENOMEM;
+
+err_path:
+ printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
+ iname, conf_name, sig_name, fdt_strerror(ret));
+ return -ENOENT;
+}
+
+static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
+ struct image_region **regionp, int *region_countp,
+ char **region_propp, int *region_proplen)
+{
+ char * const exc_prop[] = {"data"};
+ struct strlist node_inc;
+ struct image_region *region;
+ struct fdt_region fdt_regions[100];
+ const char *conf_name, *sig_name;
+ char path[200];
+ int count, i;
+ char *region_prop;
+ int ret, len;
+
+ conf_name = fit_get_name(fit, conf_noffset, NULL);
+ sig_name = fit_get_name(fit, conf_noffset, NULL);
+ debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
+
+ /* Get a list of nodes we want to hash */
+ ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
+ if (ret)
+ return ret;
+
+ /* Get a list of regions to hash */
+ count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
+ exc_prop, ARRAY_SIZE(exc_prop),
+ fdt_regions, ARRAY_SIZE(fdt_regions),
+ path, sizeof(path), 1);
+ if (count < 0) {
+ printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
+ sig_name, fdt_strerror(ret));
+ return -EIO;
+ }
+ if (count == 0) {
+ printf("No data to hash for configuration '%s/%s': %s\n",
+ conf_name, sig_name, fdt_strerror(ret));
+ return -EINVAL;
+ }
+
+ /* Build our list of data blocks */
+ region = fit_region_make_list(fit, fdt_regions, count, NULL);
+ if (!region) {
+ printf("Out of memory hashing configuration '%s/%s'\n",
+ conf_name, sig_name);
+ return -ENOMEM;
+ }
+
+ /* Create a list of all hashed properties */
+ debug("Hash nodes:\n");
+ for (i = len = 0; i < node_inc.count; i++) {
+ debug(" %s\n", node_inc.strings[i]);
+ len += strlen(node_inc.strings[i]) + 1;
+ }
+ region_prop = malloc(len);
+ if (!region_prop) {
+ printf("Out of memory setting up regions for configuration '%s/%s'\n",
+ conf_name, sig_name);
+ return -ENOMEM;
+ }
+ for (i = len = 0; i < node_inc.count;
+ len += strlen(node_inc.strings[i]) + 1, i++)
+ strcpy(region_prop + len, node_inc.strings[i]);
+ strlist_free(&node_inc);
+
+ *region_countp = count;
+ *regionp = region;
+ *region_propp = region_prop;
+ *region_proplen = len;
+
+ return 0;
+}
+
+static int fit_config_process_sig(const char *keydir, void *keydest,
+ void *fit, const char *conf_name, int conf_noffset,
+ int noffset, const char *comment, int require_keys)
+{
+ struct image_sign_info info;
+ const char *node_name;
+ struct image_region *region;
+ char *region_prop;
+ int region_proplen;
+ int region_count;
+ uint8_t *value;
+ uint value_len;
+ int ret;
+
+ node_name = fit_get_name(fit, noffset, NULL);
+ if (fit_config_get_data(fit, conf_noffset, noffset, ®ion,
+ ®ion_count, ®ion_prop, ®ion_proplen))
+ return -1;
+
+ if (fit_image_setup_sig(&info, keydir, fit, conf_name, noffset,
+ require_keys ? "conf" : NULL))
+ return -1;
+
+ ret = info.algo->sign(&info, region, region_count, &value, &value_len);
+ free(region);
+ if (ret) {
+ printf("Failed to sign '%s' signature node in '%s' conf node\n",
+ node_name, conf_name);
+
+ /* We allow keys to be missing */
+ if (ret == -ENOENT)
+ return 0;
+ return -1;
+ }
+
+ if (fit_image_write_sig(fit, noffset, value, value_len, comment,
+ region_prop, region_proplen)) {
+ printf("Can't write signature for '%s' signature node in '%s' conf node\n",
+ node_name, conf_name);
+ return -1;
+ }
+ free(value);
+ free(region_prop);
+
+ /* Get keyname again, as FDT has changed and invalidated our pointer */
+ info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
+
+ /* Write the public key into the supplied FDT file */
+ if (keydest && info.algo->add_verify_data(&info, keydest)) {
+ printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
+ node_name, conf_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int fit_config_add_verification_data(const char *keydir, void *keydest,
+ void *fit, int conf_noffset, const char *comment,
+ int require_keys)
+{
+ const char *conf_name;
+ int noffset;
+
+ conf_name = fit_get_name(fit, conf_noffset, NULL);
+
+ /* Process all hash subnodes of the configuration node */
+ for (noffset = fdt_first_subnode(fit, conf_noffset);
+ noffset >= 0;
+ noffset = fdt_next_subnode(fit, noffset)) {
+ const char *node_name;
+ int ret = 0;
+
+ node_name = fit_get_name(fit, noffset, NULL);
+ if (!strncmp(node_name, FIT_SIG_NODENAME,
+ strlen(FIT_SIG_NODENAME))) {
+ ret = fit_config_process_sig(keydir, keydest,
+ fit, conf_name, conf_noffset, noffset, comment,
+ require_keys);
+ }
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
+ const char *comment, int require_keys)
+{
+ int images_noffset, confs_noffset;
+ int noffset;
+ int ret;
+
+ /* Find images parent node offset */
+ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ if (images_noffset < 0) {
+ printf("Can't find images parent node '%s' (%s)\n",
+ FIT_IMAGES_PATH, fdt_strerror(images_noffset));
+ return images_noffset;
+ }
+
+ /* Process its subnodes, print out component images details */
+ for (noffset = fdt_first_subnode(fit, images_noffset);
+ noffset >= 0;
+ noffset = fdt_next_subnode(fit, noffset)) {
+ /*
+ * Direct child node of the images parent node,
+ * i.e. component image node.
+ */
+ ret = fit_image_add_verification_data(keydir, keydest,
+ fit, noffset, comment, require_keys);
+ if (ret)
+ return ret;
+ }
+
+ /* If there are no keys, we can't sign configurations */
+ if (!IMAGE_ENABLE_SIGN || !keydir)
+ return 0;
+
+ /* Find configurations parent node offset */
+ confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
+ if (confs_noffset < 0) {
+ printf("Can't find images parent node '%s' (%s)\n",
+ FIT_IMAGES_PATH, fdt_strerror(confs_noffset));
+ return -ENOENT;
+ }
+
+ /* Process its subnodes, print out component images details */
+ for (noffset = fdt_first_subnode(fit, confs_noffset);
+ noffset >= 0;
+ noffset = fdt_next_subnode(fit, noffset)) {
+ ret = fit_config_add_verification_data(keydir, keydest,
+ fit, noffset, comment,
+ require_keys);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_FIT_SIGNATURE
+int fit_check_sign(const void *working_fdt, const void *key)
+{
+ int cfg_noffset;
+ int ret;
+
+ cfg_noffset = fit_conf_get_node(working_fdt, NULL);
+ if (!cfg_noffset)
+ return -1;
+
+ ret = fit_config_verify(working_fdt, cfg_noffset);
+ return ret;
+}
+#endif
diff --git a/roms/u-boot/tools/image-sig.c b/roms/u-boot/tools/image-sig.c
new file mode 100644
index 00000000..e45419f3
--- /dev/null
+++ b/roms/u-boot/tools/image-sig.c
@@ -0,0 +1 @@
+#include "../common/image-sig.c"
diff --git a/roms/u-boot/tools/image.c b/roms/u-boot/tools/image.c
new file mode 100644
index 00000000..0f9bacc7
--- /dev/null
+++ b/roms/u-boot/tools/image.c
@@ -0,0 +1 @@
+#include "../common/image.c"
diff --git a/roms/u-boot/tools/imagetool.c b/roms/u-boot/tools/imagetool.c
new file mode 100644
index 00000000..da72115e
--- /dev/null
+++ b/roms/u-boot/tools/imagetool.c
@@ -0,0 +1,60 @@
+/*
+ * (C) Copyright 2013
+ *
+ * Written by Guilherme Maciel Ferreira
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+
+/*
+ * Callback function to register a image type within a tool
+ */
+static imagetool_register_t register_func;
+
+/*
+ * register_image_tool -
+ *
+ * The tool provides its own registration function in order to all image
+ * types initialize themselves.
+ */
+void register_image_tool(imagetool_register_t image_register)
+{
+ /*
+ * Save the image tool callback function. It will be used to register
+ * image types within that tool
+ */
+ register_func = image_register;
+
+ /* Init Freescale PBL Boot image generation/list support */
+ init_pbl_image_type();
+ /* Init Kirkwood Boot image generation/list support */
+ init_kwb_image_type();
+ /* Init Freescale imx Boot image generation/list support */
+ init_imx_image_type();
+ /* Init Freescale mxs Boot image generation/list support */
+ init_mxs_image_type();
+ /* Init FIT image generation/list support */
+ init_fit_image_type();
+ /* Init TI OMAP Boot image generation/list support */
+ init_omap_image_type();
+ /* Init Default image generation/list support */
+ init_default_image_type();
+ /* Init Davinci UBL support */
+ init_ubl_image_type();
+ /* Init Davinci AIS support */
+ init_ais_image_type();
+ /* Init TI Keystone boot image generation/list support */
+ init_gpimage_type();
+}
+
+/*
+ * register_image_type -
+ *
+ * Register a image type within a tool
+ */
+void register_image_type(struct image_type_params *tparams)
+{
+ register_func(tparams);
+}
diff --git a/roms/u-boot/tools/imagetool.h b/roms/u-boot/tools/imagetool.h
new file mode 100644
index 00000000..a3e9d302
--- /dev/null
+++ b/roms/u-boot/tools/imagetool.h
@@ -0,0 +1,174 @@
+/*
+ * (C) Copyright 2013
+ *
+ * Written by Guilherme Maciel Ferreira
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _IMAGETOOL_H_
+#define _IMAGETOOL_H_
+
+#include "os_support.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "fdt_host.h"
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define IH_ARCH_DEFAULT IH_ARCH_INVALID
+
+/*
+ * This structure defines all such variables those are initialized by
+ * mkimage and dumpimage main core and need to be referred by image
+ * type specific functions
+ */
+struct image_tool_params {
+ int dflag;
+ int eflag;
+ int fflag;
+ int iflag;
+ int lflag;
+ int pflag;
+ int vflag;
+ int xflag;
+ int skipcpy;
+ int os;
+ int arch;
+ int type;
+ int comp;
+ char *dtc;
+ unsigned int addr;
+ unsigned int ep;
+ char *imagename;
+ char *imagename2;
+ char *datafile;
+ char *imagefile;
+ char *cmdname;
+ const char *outfile; /* Output filename */
+ const char *keydir; /* Directory holding private keys */
+ const char *keydest; /* Destination .dtb for public key */
+ const char *comment; /* Comment to add to signature node */
+ int require_keys; /* 1 to mark signing keys as 'required' */
+};
+
+/*
+ * image type specific variables and callback functions
+ */
+struct image_type_params {
+ /* name is an identification tag string for added support */
+ char *name;
+ /*
+ * header size is local to the specific image type to be supported,
+ * mkimage core treats this as number of bytes
+ */
+ uint32_t header_size;
+ /* Image type header pointer */
+ void *hdr;
+ /*
+ * There are several arguments that are passed on the command line
+ * and are registered as flags in image_tool_params structure.
+ * This callback function can be used to check the passed arguments
+ * are in-lined with the image type to be supported
+ *
+ * Returns 1 if parameter check is successful
+ */
+ int (*check_params) (struct image_tool_params *);
+ /*
+ * This function is used by list command (i.e. mkimage -l )
+ * image type verification code must be put here
+ *
+ * Returns 0 if image header verification is successful
+ * otherwise, returns respective negative error codes
+ */
+ int (*verify_header) (unsigned char *, int, struct image_tool_params *);
+ /* Prints image information abstracting from image header */
+ void (*print_header) (const void *);
+ /*
+ * The header or image contents need to be set as per image type to
+ * be generated using this callback function.
+ * further output file post processing (for ex. checksum calculation,
+ * padding bytes etc..) can also be done in this callback function.
+ */
+ void (*set_header) (void *, struct stat *, int,
+ struct image_tool_params *);
+ /*
+ * This function is used by the command to retrieve a data file from
+ * the image (i.e. dumpimage -i -p ).
+ * Thus the code to extract a file from an image must be put here.
+ *
+ * Returns 0 if the file was successfully retrieved from the image,
+ * or a negative value on error.
+ */
+ int (*extract_datafile) (void *, struct image_tool_params *);
+ /*
+ * Some image generation support for ex (default image type) supports
+ * more than one type_ids, this callback function is used to check
+ * whether input (-T ) is supported by registered image
+ * generation/list low level code
+ */
+ int (*check_image_type) (uint8_t);
+ /* This callback function will be executed if fflag is defined */
+ int (*fflag_handle) (struct image_tool_params *);
+ /*
+ * This callback function will be executed for variable size record
+ * It is expected to build this header in memory and return its length
+ * and a pointer to it by using image_type_params.header_size and
+ * image_type_params.hdr. The return value shall indicate if an
+ * additional padding should be used when copying the data image
+ * by returning the padding length.
+ */
+ int (*vrec_header) (struct image_tool_params *,
+ struct image_type_params *);
+ /* pointer to the next registered entry in linked list */
+ struct image_type_params *next;
+};
+
+/*
+ * Tool registration function.
+ */
+typedef void (*imagetool_register_t)(struct image_type_params *);
+
+/*
+ * Initializes all image types with the given registration callback
+ * function.
+ * An image tool uses this function to initialize all image types.
+ */
+void register_image_tool(imagetool_register_t image_register);
+
+/*
+ * Register a image type within a tool.
+ * An image type uses this function to register itself within
+ * all tools.
+ */
+void register_image_type(struct image_type_params *tparams);
+
+/*
+ * There is a c file associated with supported image type low level code
+ * for ex. default_image.c, fit_image.c
+ * init_xxx_type() is the only function referred by image tool core to avoid
+ * a single lined header file, you can define them here
+ *
+ * Supported image types init functions
+ */
+void init_default_image_type(void);
+void init_pbl_image_type(void);
+void init_ais_image_type(void);
+void init_kwb_image_type(void);
+void init_imx_image_type(void);
+void init_mxs_image_type(void);
+void init_fit_image_type(void);
+void init_ubl_image_type(void);
+void init_omap_image_type(void);
+void init_gpimage_type(void);
+
+void pbl_load_uboot(int fd, struct image_tool_params *mparams);
+
+#endif /* _IMAGETOOL_H_ */
diff --git a/roms/u-boot/tools/img2brec.sh b/roms/u-boot/tools/img2brec.sh
new file mode 100755
index 00000000..0fcdba27
--- /dev/null
+++ b/roms/u-boot/tools/img2brec.sh
@@ -0,0 +1,388 @@
+#!/bin/sh
+
+# This script converts binary files (u-boot.bin) into so called
+# bootstrap records that are accepted by Motorola's MC9328MX1/L
+# (a.k.a. DragaonBall i.MX) in "Bootstrap Mode"
+#
+# The code for the SynchFlash programming routines is taken from
+# Bootloader\Bin\SyncFlash\programBoot_b.txt contained in
+# Motorolas LINUX_BSP_0_3_8.tar.gz
+#
+# The script could easily extended for AMD flash routines.
+#
+# 2004-06-23 - steven.scholz@imc-berlin.de
+
+#################################################################################
+# From the posting to the U-Boot-Users mailing list, 23 Jun 2004:
+# ===============================================================
+# I just hacked a simple script that converts u-boot.bin into a text file
+# containg processor init code, SynchFlash programming code and U-Boot data in
+# form of so called b-records.
+#
+# This can be used to programm U-Boot into (Synch)Flash using the Bootstrap
+# Mode of the MC9328MX1/L
+#
+# 0AFE1F3410202E2E2E000000002073756363656564/
+# 0AFE1F44102E0A0000206661696C656420210A0000/
+# 0AFE100000
+# ...
+# MX1ADS Sync-flash Programming Utility v0.5 2002/08/21
+#
+# Source address (stored in 0x0AFE0000): 0x0A000000
+# Target address (stored in 0x0AFE0004): 0x0C000000
+# Size (stored in 0x0AFE0008): 0x0001A320
+#
+# Press any key to start programming ...
+# Erasing ...
+# Blank checking ...
+# Programming ...
+# Verifying flash ... succeed.
+#
+# Programming finished.
+#
+# So no need for a BDI2000 anymore... ;-)
+#
+# This is working on my MX1ADS eval board. Hope this could be useful for
+# someone.
+#################################################################################
+
+if [ "$#" -lt 1 -o "$#" -gt 2 ] ; then
+ echo "Usage: $0 infile [outfile]" >&2
+ echo " $0 u-boot.bin [u-boot.brec]" >&2
+ exit 1
+fi
+
+if [ "$#" -ge 1 ] ; then
+ INFILE=$1
+fi
+
+if [ ! -f $INFILE ] ; then
+ echo "Error: file '$INFILE' does not exist." >&2
+ exit 1
+fi
+
+FILESIZE=`filesize $INFILE`
+
+output_init()
+{
+echo "\
+********************************************
+* Initialize I/O Pad Driving Strength *
+********************************************
+0021B80CC4000003AB
+********************************************
+* Initialize SDRAM *
+********************************************
+00221000C492120200 ; pre-charge command
+08200000E4 ; special read
+
+00221000C4A2120200 ; auto-refresh command
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+08000000E4 ; 8 special read
+
+00221000C4B2120200 ; set mode register
+08111800E4 ; special read
+
+00221000C482124200 ; set normal mode
+
"
+}
+
+output_uboot()
+{
+echo "\
+********************************************
+* U-Boot image as bootstrap records *
+* will be stored in SDRAM at 0x0A000000 *
+********************************************
+
"
+
+cat $INFILE | \
+hexdump -v -e "\"0A0%05.5_ax10\" 16/1 \"%02x\"\"\r\n\"" | \
+tr [:lower:] [:upper:]
+}
+
+output_flashprog()
+{
+echo "\
+********************************************
+* Address of arguments to flashProg *
+* ---------------------------------------- *
+* Source : 0x0A000000 *
+* Destination : 0x0C000000 *
"
+
+# get the real size of the U-Boot image
+printf "* Size : 0x%08X *\r\n" $FILESIZE
+printf "********************************************\r\n"
+printf "0AFE0000CC0A0000000C000000%08X\r\n" $FILESIZE
+
+#;0AFE0000CC0A0000000C00000000006000
+
+echo "\
+********************************************
+* Flash Program *
+********************************************
+0AFE10001008D09FE5AC0000EA00F0A0E1A42DFE0A
+0AFE1010100080FE0A0DC0A0E100D82DE904B04CE2
+0AFE1020109820A0E318309FE5003093E5033082E0
+0AFE103010003093E5013003E2FF3003E20300A0E1
+0AFE10401000A81BE9A01DFE0A0DC0A0E100D82DE9
+0AFE10501004B04CE204D04DE20030A0E10D304BE5
+0AFE1060109820A0E330309FE5003093E5033082E0
+0AFE107010003093E5013903E2000053E3F7FFFF0A
+0AFE1080104020A0E310309FE5003093E5032082E0
+0AFE1090100D305BE5003082E500A81BE9A01DFE0A
+0AFE10A0100DC0A0E100D82DE904B04CE20000A0E1
+0AFE10B010D7FFFFEB0030A0E1FF3003E2000053E3
+0AFE10C010FAFFFF0A10309FE5003093E5003093E5
+0AFE10D010FF3003E20300A0E100A81BE9A01DFE0A
+0AFE10E0100DC0A0E100D82DE904B04CE204D04DE2
+0AFE10F0100030A0E10D304BE50D305BE52332A0E1
+0AFE1100100E304BE50E305BE5090053E30300009A
+0AFE1110100E305BE5373083E20E304BE5020000EA
+0AFE1120100E305BE5303083E20E304BE50E305BE5
+0AFE1130100300A0E1C3FFFFEB0D305BE50F3003E2
+0AFE1140100E304BE50E305BE5090053E30300009A
+0AFE1150100E305BE5373083E20E304BE5020000EA
+0AFE1160100E305BE5303083E20E304BE50E305BE5
+0AFE1170100300A0E1B3FFFFEB00A81BE90DC0A0E1
+0AFE11801000D82DE904B04CE21CD04DE210000BE5
+0AFE11901014100BE518200BE588009FE5E50200EB
+0AFE11A01010301BE51C300BE514301BE520300BE5
+0AFE11B0100030A0E324300BE524201BE518301BE5
+0AFE11C010030052E10000003A120000EA1C004BE2
+0AFE11D010002090E520104BE2003091E500C093E5
+0AFE11E010043083E2003081E5003092E5042082E2
+0AFE11F010002080E50C0053E10200000A0030A0E3
+0AFE12001028300BE5050000EA24301BE5043083E2
+0AFE12101024300BE5E7FFFFEA0130A0E328300BE5
+0AFE12201028001BE500A81BE9E81EFE0A0DC0A0E1
+0AFE12301000D82DE904B04CE214D04DE210000BE5
+0AFE12401014100BE56C009FE5BA0200EB10301BE5
+0AFE12501018300BE50030A0E31C300BE51C201BE5
+0AFE12601014301BE5030052E10000003A0D0000EA
+0AFE12701018304BE2002093E5001092E5042082E2
+0AFE128010002083E5010071E30200000A0030A0E3
+0AFE12901020300BE5050000EA1C301BE5043083E2
+0AFE12A0101C300BE5ECFFFFEA0130A0E320300BE5
+0AFE12B01020001BE500A81BE9001FFE0A0DC0A0E1
+0AFE12C01000D82DE904B04CE224D04DE20130A0E3
+0AFE12D01024300BE5A4229FE58139A0E3023A83E2
+0AFE12E010003082E59820A0E390329FE5003093E5
+0AFE12F010033082E0003093E5023903E2000053E3
+0AFE1300100300001A74229FE58139A0E3033A83E2
+0AFE131010003082E568029FE5860200EBAF36A0E3
+0AFE1320100E3883E2003093E510300BE554029FE5
+0AFE133010800200EB10301BE5233CA0E1FF3003E2
+0AFE1340100300A0E165FFFFEB10301BE52338A0E1
+0AFE135010FF3003E20300A0E160FFFFEB10301BE5
+0AFE1360102334A0E1FF3003E20300A0E15BFFFFEB
+0AFE13701010305BE50300A0E158FFFFEB0A00A0E3
+0AFE13801030FFFFEB0D00A0E32EFFFFEBAF36A0E3
+0AFE1390100E3883E2043083E2003093E514300BE5
+0AFE13A010E4019FE5630200EB14301BE5233CA0E1
+0AFE13B010FF3003E20300A0E148FFFFEB14301BE5
+0AFE13C0102338A0E1FF3003E20300A0E143FFFFEB
+0AFE13D01014301BE52334A0E1FF3003E20300A0E1
+0AFE13E0103EFFFFEB14305BE50300A0E13BFFFFEB
+0AFE13F0100A00A0E313FFFFEB0D00A0E311FFFFEB
+0AFE140010AF36A0E30E3883E2083083E2003093E5
+0AFE14101018300BE574019FE5460200EB18301BE5
+0AFE142010233CA0E1FF3003E20300A0E12BFFFFEB
+0AFE14301018301BE52338A0E1FF3003E20300A0E1
+0AFE14401026FFFFEB18301BE52334A0E1FF3003E2
+0AFE1450100300A0E121FFFFEB18305BE50300A0E1
+0AFE1460101EFFFFEB0A00A0E3F6FEFFEB0D00A0E3
+0AFE147010F4FEFFEBE6FEFFEB0030A0E1FF3003E2
+0AFE148010000053E30000001A020000EA03FFFFEB
+0AFE1490102D004BE5F6FFFFEAF4009FE5250200EB
+0AFE14A010FEFEFFEB2D004BE5CD0000EBC00000EB
+0AFE14B010E0009FE51F0200EB18301BE528300BE5
+0AFE14C01014301BE52C300BE52C001BE5100100EB
+0AFE14D01028301BE5013643E228300BE52C301BE5
+0AFE14E010013683E22C300BE528301BE5000053E3
+0AFE14F010F4FFFFCAAE0000EB14001BE518101BE5
+0AFE15001049FFFFEB0030A0E1FF3003E2000053E3
+0AFE151010E6FFFF0A80009FE5060200EB10001BE5
+0AFE15201014101BE518201BE5D00000EB10001BE5
+0AFE15301014101BE518201BE50FFFFFEB0030A0E1
+0AFE154010FF3003E2000053E30200000A4C009FE5
+0AFE155010F80100EB010000EA44009FE5F50100EB
+0AFE156010930000EB3C009FE5F20100EB0000A0E3
+0AFE157010A4FEFFEB0030A0E30300A0E100A81BE9
+0AFE158010A01DFE0AA41DFE0AE01DFE0A0C1EFE0A
+0AFE159010381EFE0A641EFE0A181FFE0A281FFE0A
+0AFE15A0103C1FFE0A481FFE0AB41EFE0A0DC0A0E1
+0AFE15B01000D82DE904B04CE204D04DE210000BE5
+0AFE15C01010301BE5013043E210300BE5010073E3
+0AFE15D010FAFFFF1A00A81BE90DC0A0E100D82DE9
+0AFE15E01004B04CE208D04DE210000BE510301BE5
+0AFE15F01014300BE514301BE50300A0E100A81BE9
+0AFE1600100DC0A0E100D82DE904B04CE204D04DE2
+0AFE1610102228A0E3012A82E2042082E2E134A0E3
+0AFE162010023883E2033C83E2003082E50333A0E3
+0AFE163010053983E2003093E510300BE500A81BE9
+0AFE1640100DC0A0E100D82DE904B04CE204D04DE2
+0AFE1650102228A0E3012A82E2042082E29134A0E3
+0AFE166010023883E2033C83E2003082E5C136A0E3
+0AFE167010003093E510300BE52228A0E3012A82E2
+0AFE168010042082E2E134A0E3023883E2033C83E2
+0AFE169010003082E50333A0E3073983E20020A0E3
+0AFE16A010002083E52228A0E3012A82E2042082E2
+0AFE16B0108134A0E3023883E2033C83E2003082E5
+0AFE16C0100333A0E3003093E510300BE5CBFFFFEB
+0AFE16D01010301BE50300A0E100A81BE90DC0A0E1
+0AFE16E01000D82DE904B04CE208D04DE2D3FFFFEB
+0AFE16F0100030A0E110300BE510301BE5023503E2
+0AFE170010000053E30500000A10301BE5073703E2
+0AFE171010000053E30100000A10001BE5ADFFFFEB
+0AFE17201010301BE5803003E2000053E30500000A
+0AFE17301010301BE51C3003E2000053E30100000A
+0AFE17401010001BE5A3FFFFEB10201BE50235A0E3
+0AFE175010803083E2030052E10200001A0130A0E3
+0AFE17601014300BE5010000EA0030A0E314300BE5
+0AFE17701014001BE500A81BE90DC0A0E100D82DE9
+0AFE17801004B04CE204D04DE22228A0E3012A82E2
+0AFE179010042082E29134A0E3023883E2033C83E2
+0AFE17A010003082E5C136A0E3003093E510300BE5
+0AFE17B01000A81BE90DC0A0E100D82DE904B04CE2
+0AFE17C010ECFFFFEB2228A0E3012A82E2042082E2
+0AFE17D0108134A0E3023883E2033C83E2003082E5
+0AFE17E01000A81BE90DC0A0E100D82DE904B04CE2
+0AFE17F01004D04DE22228A0E3012A82E2042082E2
+0AFE1800102238A0E3013A83E2043083E2003093E5
+0AFE181010023183E3003082E52228A0E3012A82E2
+0AFE1820102238A0E3013A83E2003093E5023183E3
+0AFE183010003082E5FA0FA0E35BFFFFEB2228A0E3
+0AFE184010012A82E2042082E2B134A0E3023883E2
+0AFE185010033C83E2003082E50333A0E3233983E2
+0AFE186010033B83E2003093E510300BE500A81BE9
+0AFE1870100DC0A0E100D82DE904B04CE21CD04DE2
+0AFE18801010000BE514100BE518200BE50030A0E3
+0AFE1890101C300BE51C201BE518301BE5030052E1
+0AFE18A0100000003A190000EAB2FFFFEB2228A0E3
+0AFE18B010012A82E2042082E2F134A0E3023883E2
+0AFE18C010033C83E2003082E514201BE51C301BE5
+0AFE18D010031082E010201BE51C301BE5033082E0
+0AFE18E010003093E5003081E57BFFFFEB0030A0E1
+0AFE18F010FF3003E2000053E3FAFFFF0AACFFFFEB
+0AFE1900101C301BE5043083E21C300BE5E0FFFFEA
+0AFE19101000A81BE90DC0A0E100D82DE904B04CE2
+0AFE1920100CD04DE210000BE52228A0E3012A82E2
+0AFE193010042082E28134A0E3023883E2033C83E2
+0AFE194010003082E510301BE5003093E514300BE5
+0AFE1950102228A0E3012A82E2042082E29134A0E3
+0AFE196010023883E2033C83E2003082E510301BE5
+0AFE197010003093E518300BE52228A0E3012A82E2
+0AFE198010042082E2E134A0E3023883E2033C83E2
+0AFE199010003082E50229A0E310301BE5032082E0
+0AFE19A0100030A0E3003082E52228A0E3012A82E2
+0AFE19B010042082E28134A0E3023883E2033C83E2
+0AFE19C010003082E510201BE50D3AA0E3D03083E2
+0AFE19D010033883E1003082E53FFFFFEB0030A0E1
+0AFE19E010FF3003E2000053E3FAFFFF0A70FFFFEB
+0AFE19F01000A81BE90DC0A0E100D82DE904B04CE2
+0AFE1A00105CFFFFEB2228A0E3012A82E2042082E2
+0AFE1A1010E134A0E3023883E2033C83E2003082E5
+0AFE1A20100333A0E3033983E20020A0E3002083E5
+0AFE1A30102228A0E3012A82E2042082E28134A0E3
+0AFE1A4010023883E2033C83E2003082E50323A0E3
+0AFE1A5010032982E20339A0E3C03083E2033883E1
+0AFE1A6010003082E500A81BE90DC0A0E100D82DE9
+0AFE1A701004B04CE23FFFFFEB2228A0E3012A82E2
+0AFE1A8010042082E2E134A0E3023883E2033C83E2
+0AFE1A9010003082E50333A0E30A3983E20020A0E3
+0AFE1AA010002083E52228A0E3012A82E2042082E2
+0AFE1AB0108134A0E3023883E2033C83E2003082E5
+0AFE1AC0100323A0E30A2982E20339A0E3C03083E2
+0AFE1AD010033883E1003082E500A81BE90DC0A0E1
+0AFE1AE01000D82DE904B04CE28729A0E3222E82E2
+0AFE1AF0108739A0E3223E83E2003093E51E3CC3E3
+0AFE1B0010003082E58729A0E38E2F82E28739A0E3
+0AFE1B10108E3F83E2003093E51E3CC3E3003082E5
+0AFE1B20108139A0E3823D83E20520A0E3002083E5
+0AFE1B30108129A0E3822D82E2042082E20139A0E3
+0AFE1B4010273083E2003082E58139A0E3823D83E2
+0AFE1B50100C3083E20120A0E3002083E58129A0E3
+0AFE1B6010822D82E2102082E22A3DA0E3013083E2
+0AFE1B7010003082E58139A0E3823D83E2243083E2
+0AFE1B80100F20A0E3002083E58139A0E3823D83E2
+0AFE1B9010283083E28A20A0E3002083E58139A0E3
+0AFE1BA010823D83E22C3083E20820A0E3002083E5
+0AFE1BB01000A81BE90DC0A0E100D82DE904B04CE2
+0AFE1BC0108139A0E3823D83E2183083E2003093E5
+0AFE1BD010013003E2FF3003E20300A0E100A81BE9
+0AFE1BE0100DC0A0E100D82DE904B04CE204D04DE2
+0AFE1BF0100030A0E10D304BE58139A0E3823D83E2
+0AFE1C0010183083E2003093E5013903E2000053E3
+0AFE1C1010F8FFFF0A8139A0E3813D83E20D205BE5
+0AFE1C2010002083E50D305BE50A0053E30A00001A
+0AFE1C30108139A0E3823D83E2183083E2003093E5
+0AFE1C4010013903E2000053E3F8FFFF0A8139A0E3
+0AFE1C5010813D83E20D20A0E3002083E500A81BE9
+0AFE1C60100DC0A0E100D82DE904B04CE20000A0E1
+0AFE1C7010CFFFFFEB0030A0E1FF3003E2000053E3
+0AFE1C8010FAFFFF0A8139A0E3023A83E2003093E5
+0AFE1C9010FF3003E20300A0E100A81BE90DC0A0E1
+0AFE1CA01000D82DE904B04CE204D04DE20030A0E1
+0AFE1CB0100D304BE50D305BE52332A0E10E304BE5
+0AFE1CC0100E305BE5090053E30300009A0E305BE5
+0AFE1CD010373083E20E304BE5020000EA0E305BE5
+0AFE1CE010303083E20E304BE50E305BE50300A0E1
+0AFE1CF010BAFFFFEB0D305BE50F3003E20E304BE5
+0AFE1D00100E305BE5090053E30300009A0E305BE5
+0AFE1D1010373083E20E304BE5020000EA0E305BE5
+0AFE1D2010303083E20E304BE50E305BE50300A0E1
+0AFE1D3010AAFFFFEB00A81BE90DC0A0E100D82DE9
+0AFE1D401004B04CE204D04DE210000BE510301BE5
+0AFE1D50100030D3E5000053E30000001A080000EA
+0AFE1D601010104BE2003091E50320A0E10020D2E5
+0AFE1D7010013083E2003081E50200A0E197FFFFEB
+0AFE1D8008F1FFFFEA00A81BE9
+0AFE1DA4100A0D4D58314144532053796E632D666C
+0AFE1DB4106173682050726F6772616D6D696E6720
+0AFE1DC4105574696C6974792076302E3520323030
+0AFE1DD410322F30382F32310A0D000000536F7572
+0AFE1DE41063652061646472657373202873746F72
+0AFE1DF410656420696E2030783041464530303030
+0AFE1E0410293A2030780000005461726765742061
+0AFE1E1410646472657373202873746F7265642069
+0AFE1E24106E2030783041464530303034293A2030
+0AFE1E34107800000053697A652020202020202020
+0AFE1E44102020202873746F72656420696E203078
+0AFE1E54103041464530303038293A203078000000
+0AFE1E6410507265737320616E79206B657920746F
+0AFE1E74102073746172742070726F6772616D6D69
+0AFE1E84106E67202E2E2E00000A0D45726173696E
+0AFE1E94106720666C617368202E2E2E000A0D5072
+0AFE1EA4106F6772616D6D696E67202E2E2E000000
+0AFE1EB4100A0D50726F6772616D6D696E67206669
+0AFE1EC4106E69736865642E0A0D50726573732027
+0AFE1ED410612720746F20636F6E74696E7565202E
+0AFE1EE4102E2E2E000A0D566572696679696E6720
+0AFE1EF410666C617368202E2E2E0000000A0D426C
+0AFE1F0410616E6B20636865636B696E67202E2E2E
+0AFE1F1410000000000A45726173696E67202E2E2E
+0AFE1F2410000000000A50726F6772616D6D696E67
+0AFE1F3410202E2E2E000000002073756363656564
+0AFE1F44102E0A0000206661696C656420210A0000
+0AFE100000
+
"
+}
+
+#########################################################
+
+if [ "$#" -eq 2 ] ; then
+ output_init > $2
+ output_uboot >> $2
+ output_flashprog >> $2
+else
+ output_init;
+ output_uboot;
+ output_flashprog;
+fi
diff --git a/roms/u-boot/tools/img2srec.c b/roms/u-boot/tools/img2srec.c
new file mode 100644
index 00000000..ec769640
--- /dev/null
+++ b/roms/u-boot/tools/img2srec.c
@@ -0,0 +1,372 @@
+/*************************************************************************
+| COPYRIGHT (c) 2000 BY ABATRON AG
+|*************************************************************************
+|
+| PROJECT NAME: Linux Image to S-record Conversion Utility
+| FILENAME : img2srec.c
+|
+| COMPILER : GCC
+|
+| TARGET OS : LINUX / UNIX
+| TARGET HW : -
+|
+| PROGRAMMER : Abatron / RD
+| CREATION : 07.07.00
+|
+|*************************************************************************
+|
+| DESCRIPTION :
+|
+| Utility to convert a Linux Boot Image to S-record:
+| ==================================================
+|
+| This command line utility can be used to convert a Linux boot image
+| (zimage.initrd) to S-Record format used for flash programming.
+| This conversion takes care of the special sections "IMAGE" and INITRD".
+|
+| img2srec [-o offset] image > image.srec
+|
+|
+| Build the utility:
+| ==================
+|
+| To build the utility use GCC as follows:
+|
+| gcc img2srec.c -o img2srec
+|
+|
+|*************************************************************************
+|
+|
+| UPDATES :
+|
+| DATE NAME CHANGES
+| -----------------------------------------------------------
+| Latest update
+|
+| 07.07.00 aba Initial release
+|
+|*************************************************************************/
+
+/*************************************************************************
+| INCLUDES
+|*************************************************************************/
+
+#include "os_support.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*************************************************************************
+| FUNCTIONS
+|*************************************************************************/
+
+static char* ExtractHex (uint32_t* value, char* getPtr)
+{
+ uint32_t num;
+ uint32_t digit;
+ uint8_t c;
+
+ while (*getPtr == ' ') getPtr++;
+ num = 0;
+ for (;;) {
+ c = *getPtr;
+ if ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
+ else if ((c >= 'A') && (c <= 'F')) digit = (uint32_t)(c - 'A' + 10);
+ else if ((c >= 'a') && (c <= 'f')) digit = (uint32_t)(c - 'a' + 10);
+ else break;
+ num <<= 4;
+ num += digit;
+ getPtr++;
+ } /* for */
+ *value = num;
+ return getPtr;
+} /* ExtractHex */
+
+static char* ExtractDecimal (uint32_t* value, char* getPtr)
+{
+ uint32_t num;
+ uint32_t digit;
+ uint8_t c;
+
+ while (*getPtr == ' ') getPtr++;
+ num = 0;
+ for (;;) {
+ c = *getPtr;
+ if ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
+ else break;
+ num *= 10;
+ num += digit;
+ getPtr++;
+ } /* for */
+ *value = num;
+ return getPtr;
+} /* ExtractDecimal */
+
+
+static void ExtractNumber (uint32_t* value, char* getPtr)
+{
+ bool neg = false;;
+
+ while (*getPtr == ' ') getPtr++;
+ if (*getPtr == '-') {
+ neg = true;
+ getPtr++;
+ } /* if */
+ if ((*getPtr == '0') && ((*(getPtr+1) == 'x') || (*(getPtr+1) == 'X'))) {
+ getPtr +=2;
+ (void)ExtractHex(value, getPtr);
+ } /* if */
+ else {
+ (void)ExtractDecimal(value, getPtr);
+ } /* else */
+ if (neg) *value = -(*value);
+} /* ExtractNumber */
+
+
+static uint8_t* ExtractWord(uint16_t* value, uint8_t* buffer)
+{
+ uint16_t x;
+ x = (uint16_t)*buffer++;
+ x = (x<<8) + (uint16_t)*buffer++;
+ *value = x;
+ return buffer;
+} /* ExtractWord */
+
+
+static uint8_t* ExtractLong(uint32_t* value, uint8_t* buffer)
+{
+ uint32_t x;
+ x = (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
+ *value = x;
+ return buffer;
+} /* ExtractLong */
+
+
+static uint8_t* ExtractBlock(uint16_t count, uint8_t* data, uint8_t* buffer)
+{
+ while (count--) *data++ = *buffer++;
+ return buffer;
+} /* ExtractBlock */
+
+
+static char* WriteHex(char* pa, uint8_t value, uint16_t* pCheckSum)
+{
+ uint16_t temp;
+
+ static char ByteToHex[] = "0123456789ABCDEF";
+
+ *pCheckSum += value;
+ temp = value / 16;
+ *pa++ = ByteToHex[temp];
+ temp = value % 16;
+ *pa++ = ByteToHex[temp];
+ return pa;
+}
+
+
+static char* BuildSRecord(char* pa, uint16_t sType, uint32_t addr,
+ const uint8_t* data, int nCount)
+{
+ uint16_t addrLen;
+ uint16_t sRLen;
+ uint16_t checkSum;
+ uint16_t i;
+
+ switch (sType) {
+ case 0:
+ case 1:
+ case 9:
+ addrLen = 2;
+ break;
+ case 2:
+ case 8:
+ addrLen = 3;
+ break;
+ case 3:
+ case 7:
+ addrLen = 4;
+ break;
+ default:
+ return pa;
+ } /* switch */
+
+ *pa++ = 'S';
+ *pa++ = (char)(sType + '0');
+ sRLen = addrLen + nCount + 1;
+ checkSum = 0;
+ pa = WriteHex(pa, (uint8_t)sRLen, &checkSum);
+
+ /* Write address field */
+ for (i = 1; i <= addrLen; i++) {
+ pa = WriteHex(pa, (uint8_t)(addr >> (8 * (addrLen - i))), &checkSum);
+ } /* for */
+
+ /* Write code/data fields */
+ for (i = 0; i < nCount; i++) {
+ pa = WriteHex(pa, *data++, &checkSum);
+ } /* for */
+
+ /* Write checksum field */
+ checkSum = ~checkSum;
+ pa = WriteHex(pa, (uint8_t)checkSum, &checkSum);
+ *pa++ = '\0';
+ return pa;
+}
+
+
+static void ConvertELF(char* fileName, uint32_t loadOffset)
+{
+ FILE* file;
+ int i;
+ int rxCount;
+ uint8_t rxBlock[1024];
+ uint32_t loadSize;
+ uint32_t firstAddr;
+ uint32_t loadAddr;
+ uint32_t loadDiff = 0;
+ Elf32_Ehdr elfHeader;
+ Elf32_Shdr sectHeader[32];
+ uint8_t* getPtr;
+ char srecLine[128];
+ char *hdr_name;
+
+
+ /* open file */
+ if ((file = fopen(fileName,"rb")) == NULL) {
+ fprintf (stderr, "Can't open %s: %s\n", fileName, strerror(errno));
+ return;
+ } /* if */
+
+ /* read ELF header */
+ rxCount = fread(rxBlock, 1, sizeof elfHeader, file);
+ getPtr = ExtractBlock(sizeof elfHeader.e_ident, elfHeader.e_ident, rxBlock);
+ getPtr = ExtractWord(&elfHeader.e_type, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_machine, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_version, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_entry, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_phoff, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_shoff, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_flags, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_ehsize, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_phentsize, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_phnum, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_shentsize, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_shnum, getPtr);
+ getPtr = ExtractWord(&elfHeader.e_shstrndx, getPtr);
+ if ( (rxCount != sizeof elfHeader)
+ || (elfHeader.e_ident[0] != ELFMAG0)
+ || (elfHeader.e_ident[1] != ELFMAG1)
+ || (elfHeader.e_ident[2] != ELFMAG2)
+ || (elfHeader.e_ident[3] != ELFMAG3)
+ || (elfHeader.e_type != ET_EXEC)
+ ) {
+ fclose(file);
+ fprintf (stderr, "*** illegal file format\n");
+ return;
+ } /* if */
+
+ /* read all section headers */
+ fseek(file, elfHeader.e_shoff, SEEK_SET);
+ for (i = 0; i < elfHeader.e_shnum; i++) {
+ rxCount = fread(rxBlock, 1, sizeof sectHeader[0], file);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_name, rxBlock);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_type, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_flags, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_addr, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_offset, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_size, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_link, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_info, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_addralign, getPtr);
+ getPtr = ExtractLong((uint32_t *)§Header[i].sh_entsize, getPtr);
+ if (rxCount != sizeof sectHeader[0]) {
+ fclose(file);
+ fprintf (stderr, "*** illegal file format\n");
+ return;
+ } /* if */
+ } /* for */
+
+ if ((hdr_name = strrchr(fileName, '/')) == NULL) {
+ hdr_name = fileName;
+ } else {
+ ++hdr_name;
+ }
+ /* write start record */
+ (void)BuildSRecord(srecLine, 0, 0, (uint8_t *)hdr_name, strlen(hdr_name));
+ printf("%s\r\n",srecLine);
+
+ /* write data records */
+ firstAddr = ~0;
+ loadAddr = 0;
+ for (i = 0; i < elfHeader.e_shnum; i++) {
+ if ( (sectHeader[i].sh_type == SHT_PROGBITS)
+ && (sectHeader[i].sh_size != 0)
+ ) {
+ loadSize = sectHeader[i].sh_size;
+ if (sectHeader[i].sh_flags != 0) {
+ loadAddr = sectHeader[i].sh_addr;
+ loadDiff = loadAddr - sectHeader[i].sh_offset;
+ } /* if */
+ else {
+ loadAddr = sectHeader[i].sh_offset + loadDiff;
+ } /* else */
+
+ if (loadAddr < firstAddr)
+ firstAddr = loadAddr;
+
+ /* build s-records */
+ loadSize = sectHeader[i].sh_size;
+ fseek(file, sectHeader[i].sh_offset, SEEK_SET);
+ while (loadSize) {
+ rxCount = fread(rxBlock, 1, (loadSize > 32) ? 32 : loadSize, file);
+ if (rxCount < 0) {
+ fclose(file);
+ fprintf (stderr, "*** illegal file format\n");
+ return;
+ } /* if */
+ (void)BuildSRecord(srecLine, 3, loadAddr + loadOffset, rxBlock, rxCount);
+ loadSize -= rxCount;
+ loadAddr += rxCount;
+ printf("%s\r\n",srecLine);
+ } /* while */
+ } /* if */
+ } /* for */
+
+ /* add end record */
+ (void)BuildSRecord(srecLine, 7, firstAddr + loadOffset, 0, 0);
+ printf("%s\r\n",srecLine);
+ fclose(file);
+} /* ConvertELF */
+
+
+/*************************************************************************
+| MAIN
+|*************************************************************************/
+
+int main( int argc, char *argv[ ])
+{
+ uint32_t offset;
+
+ if (argc == 2) {
+ ConvertELF(argv[1], 0);
+ } /* if */
+ else if ((argc == 4) && (strcmp(argv[1], "-o") == 0)) {
+ ExtractNumber(&offset, argv[2]);
+ ConvertELF(argv[3], offset);
+ } /* if */
+ else {
+ fprintf (stderr, "Usage: img2srec [-o offset] \n");
+ } /* if */
+
+ return 0;
+} /* main */
diff --git a/roms/u-boot/tools/imximage.c b/roms/u-boot/tools/imximage.c
new file mode 100644
index 00000000..18dc051c
--- /dev/null
+++ b/roms/u-boot/tools/imximage.c
@@ -0,0 +1,705 @@
+/*
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include
+#include "imximage.h"
+
+#define UNDEFINED 0xFFFFFFFF
+
+/*
+ * Supported commands for configuration file
+ */
+static table_entry_t imximage_cmds[] = {
+ {CMD_BOOT_FROM, "BOOT_FROM", "boot command", },
+ {CMD_BOOT_OFFSET, "BOOT_OFFSET", "Boot offset", },
+ {CMD_DATA, "DATA", "Reg Write Data", },
+ {CMD_CSF, "CSF", "Command Sequence File", },
+ {CMD_IMAGE_VERSION, "IMAGE_VERSION", "image version", },
+ {-1, "", "", },
+};
+
+/*
+ * Supported Boot options for configuration file
+ * this is needed to set the correct flash offset
+ */
+static table_entry_t imximage_boot_offset[] = {
+ {FLASH_OFFSET_ONENAND, "onenand", "OneNAND Flash",},
+ {FLASH_OFFSET_NAND, "nand", "NAND Flash", },
+ {FLASH_OFFSET_NOR, "nor", "NOR Flash", },
+ {FLASH_OFFSET_SATA, "sata", "SATA Disk", },
+ {FLASH_OFFSET_SD, "sd", "SD Card", },
+ {FLASH_OFFSET_SPI, "spi", "SPI Flash", },
+ {-1, "", "Invalid", },
+};
+
+/*
+ * Supported Boot options for configuration file
+ * this is needed to determine the initial load size
+ */
+static table_entry_t imximage_boot_loadsize[] = {
+ {FLASH_LOADSIZE_ONENAND, "onenand", "OneNAND Flash",},
+ {FLASH_LOADSIZE_NAND, "nand", "NAND Flash", },
+ {FLASH_LOADSIZE_NOR, "nor", "NOR Flash", },
+ {FLASH_LOADSIZE_SATA, "sata", "SATA Disk", },
+ {FLASH_LOADSIZE_SD, "sd", "SD Card", },
+ {FLASH_LOADSIZE_SPI, "spi", "SPI Flash", },
+ {-1, "", "Invalid", },
+};
+
+/*
+ * IMXIMAGE version definition for i.MX chips
+ */
+static table_entry_t imximage_versions[] = {
+ {IMXIMAGE_V1, "", " (i.MX25/35/51 compatible)", },
+ {IMXIMAGE_V2, "", " (i.MX53/6 compatible)", },
+ {-1, "", " (Invalid)", },
+};
+
+static struct imx_header imximage_header;
+static uint32_t imximage_version;
+/*
+ * Image Vector Table Offset
+ * Initialized to a wrong not 4-bytes aligned address to
+ * check if it is was set by the cfg file.
+ */
+static uint32_t imximage_ivt_offset = UNDEFINED;
+static uint32_t imximage_csf_size = UNDEFINED;
+/* Initial Load Region Size */
+static uint32_t imximage_init_loadsize;
+
+static set_dcd_val_t set_dcd_val;
+static set_dcd_rst_t set_dcd_rst;
+static set_imx_hdr_t set_imx_hdr;
+static uint32_t max_dcd_entries;
+static uint32_t *header_size_ptr;
+static uint32_t *csf_ptr;
+
+static uint32_t get_cfg_value(char *token, char *name, int linenr)
+{
+ char *endptr;
+ uint32_t value;
+
+ errno = 0;
+ value = strtoul(token, &endptr, 16);
+ if (errno || (token == endptr)) {
+ fprintf(stderr, "Error: %s[%d] - Invalid hex data(%s)\n",
+ name, linenr, token);
+ exit(EXIT_FAILURE);
+ }
+ return value;
+}
+
+static uint32_t detect_imximage_version(struct imx_header *imx_hdr)
+{
+ imx_header_v1_t *hdr_v1 = &imx_hdr->header.hdr_v1;
+ imx_header_v2_t *hdr_v2 = &imx_hdr->header.hdr_v2;
+ flash_header_v1_t *fhdr_v1 = &hdr_v1->fhdr;
+ flash_header_v2_t *fhdr_v2 = &hdr_v2->fhdr;
+
+ /* Try to detect V1 */
+ if ((fhdr_v1->app_code_barker == APP_CODE_BARKER) &&
+ (hdr_v1->dcd_table.preamble.barker == DCD_BARKER))
+ return IMXIMAGE_V1;
+
+ /* Try to detect V2 */
+ if ((fhdr_v2->header.tag == IVT_HEADER_TAG) &&
+ (hdr_v2->dcd_table.header.tag == DCD_HEADER_TAG))
+ return IMXIMAGE_V2;
+
+ return IMXIMAGE_VER_INVALID;
+}
+
+static void err_imximage_version(int version)
+{
+ fprintf(stderr,
+ "Error: Unsupported imximage version:%d\n", version);
+
+ exit(EXIT_FAILURE);
+}
+
+static void set_dcd_val_v1(struct imx_header *imxhdr, char *name, int lineno,
+ int fld, uint32_t value, uint32_t off)
+{
+ dcd_v1_t *dcd_v1 = &imxhdr->header.hdr_v1.dcd_table;
+
+ switch (fld) {
+ case CFG_REG_SIZE:
+ /* Byte, halfword, word */
+ if ((value != 1) && (value != 2) && (value != 4)) {
+ fprintf(stderr, "Error: %s[%d] - "
+ "Invalid register size " "(%d)\n",
+ name, lineno, value);
+ exit(EXIT_FAILURE);
+ }
+ dcd_v1->addr_data[off].type = value;
+ break;
+ case CFG_REG_ADDRESS:
+ dcd_v1->addr_data[off].addr = value;
+ break;
+ case CFG_REG_VALUE:
+ dcd_v1->addr_data[off].value = value;
+ break;
+ default:
+ break;
+
+ }
+}
+
+static void set_dcd_val_v2(struct imx_header *imxhdr, char *name, int lineno,
+ int fld, uint32_t value, uint32_t off)
+{
+ dcd_v2_t *dcd_v2 = &imxhdr->header.hdr_v2.dcd_table;
+
+ switch (fld) {
+ case CFG_REG_ADDRESS:
+ dcd_v2->addr_data[off].addr = cpu_to_be32(value);
+ break;
+ case CFG_REG_VALUE:
+ dcd_v2->addr_data[off].value = cpu_to_be32(value);
+ break;
+ default:
+ break;
+
+ }
+}
+
+/*
+ * Complete setting up the rest field of DCD of V1
+ * such as barker code and DCD data length.
+ */
+static void set_dcd_rst_v1(struct imx_header *imxhdr, uint32_t dcd_len,
+ char *name, int lineno)
+{
+ dcd_v1_t *dcd_v1 = &imxhdr->header.hdr_v1.dcd_table;
+
+ dcd_v1->preamble.barker = DCD_BARKER;
+ dcd_v1->preamble.length = dcd_len * sizeof(dcd_type_addr_data_t);
+}
+
+/*
+ * Complete setting up the reset field of DCD of V2
+ * such as DCD tag, version, length, etc.
+ */
+static void set_dcd_rst_v2(struct imx_header *imxhdr, uint32_t dcd_len,
+ char *name, int lineno)
+{
+ dcd_v2_t *dcd_v2 = &imxhdr->header.hdr_v2.dcd_table;
+
+ dcd_v2->header.tag = DCD_HEADER_TAG;
+ dcd_v2->header.length = cpu_to_be16(
+ dcd_len * sizeof(dcd_addr_data_t) + 8);
+ dcd_v2->header.version = DCD_VERSION;
+ dcd_v2->write_dcd_command.tag = DCD_COMMAND_TAG;
+ dcd_v2->write_dcd_command.length = cpu_to_be16(
+ dcd_len * sizeof(dcd_addr_data_t) + 4);
+ dcd_v2->write_dcd_command.param = DCD_COMMAND_PARAM;
+}
+
+static void set_imx_hdr_v1(struct imx_header *imxhdr, uint32_t dcd_len,
+ uint32_t entry_point, uint32_t flash_offset)
+{
+ imx_header_v1_t *hdr_v1 = &imxhdr->header.hdr_v1;
+ flash_header_v1_t *fhdr_v1 = &hdr_v1->fhdr;
+ dcd_v1_t *dcd_v1 = &hdr_v1->dcd_table;
+ uint32_t hdr_base;
+ uint32_t header_length = (((char *)&dcd_v1->addr_data[dcd_len].addr)
+ - ((char *)imxhdr));
+
+ /* Set magic number */
+ fhdr_v1->app_code_barker = APP_CODE_BARKER;
+
+ /* TODO: check i.MX image V1 handling, for now use 'old' style */
+ hdr_base = entry_point - 4096;
+ fhdr_v1->app_dest_ptr = hdr_base - flash_offset;
+ fhdr_v1->app_code_jump_vector = entry_point;
+
+ fhdr_v1->dcd_ptr_ptr = hdr_base + offsetof(flash_header_v1_t, dcd_ptr);
+ fhdr_v1->dcd_ptr = hdr_base + offsetof(imx_header_v1_t, dcd_table);
+
+ /* Security feature are not supported */
+ fhdr_v1->app_code_csf = 0;
+ fhdr_v1->super_root_key = 0;
+ header_size_ptr = (uint32_t *)(((char *)imxhdr) + header_length - 4);
+}
+
+static void set_imx_hdr_v2(struct imx_header *imxhdr, uint32_t dcd_len,
+ uint32_t entry_point, uint32_t flash_offset)
+{
+ imx_header_v2_t *hdr_v2 = &imxhdr->header.hdr_v2;
+ flash_header_v2_t *fhdr_v2 = &hdr_v2->fhdr;
+ uint32_t hdr_base;
+
+ /* Set magic number */
+ fhdr_v2->header.tag = IVT_HEADER_TAG; /* 0xD1 */
+ fhdr_v2->header.length = cpu_to_be16(sizeof(flash_header_v2_t));
+ fhdr_v2->header.version = IVT_VERSION; /* 0x40 */
+
+ fhdr_v2->entry = entry_point;
+ fhdr_v2->reserved1 = fhdr_v2->reserved2 = 0;
+ hdr_base = entry_point - imximage_init_loadsize +
+ flash_offset;
+ fhdr_v2->self = hdr_base;
+ fhdr_v2->dcd_ptr = hdr_base + offsetof(imx_header_v2_t, dcd_table);
+ fhdr_v2->boot_data_ptr = hdr_base
+ + offsetof(imx_header_v2_t, boot_data);
+ hdr_v2->boot_data.start = entry_point - imximage_init_loadsize;
+
+ fhdr_v2->csf = 0;
+
+ header_size_ptr = &hdr_v2->boot_data.size;
+ csf_ptr = &fhdr_v2->csf;
+}
+
+static void set_hdr_func(void)
+{
+ switch (imximage_version) {
+ case IMXIMAGE_V1:
+ set_dcd_val = set_dcd_val_v1;
+ set_dcd_rst = set_dcd_rst_v1;
+ set_imx_hdr = set_imx_hdr_v1;
+ max_dcd_entries = MAX_HW_CFG_SIZE_V1;
+ break;
+ case IMXIMAGE_V2:
+ set_dcd_val = set_dcd_val_v2;
+ set_dcd_rst = set_dcd_rst_v2;
+ set_imx_hdr = set_imx_hdr_v2;
+ max_dcd_entries = MAX_HW_CFG_SIZE_V2;
+ break;
+ default:
+ err_imximage_version(imximage_version);
+ break;
+ }
+}
+
+static void print_hdr_v1(struct imx_header *imx_hdr)
+{
+ imx_header_v1_t *hdr_v1 = &imx_hdr->header.hdr_v1;
+ flash_header_v1_t *fhdr_v1 = &hdr_v1->fhdr;
+ dcd_v1_t *dcd_v1 = &hdr_v1->dcd_table;
+ uint32_t size, length, ver;
+
+ size = dcd_v1->preamble.length;
+ if (size > (MAX_HW_CFG_SIZE_V1 * sizeof(dcd_type_addr_data_t))) {
+ fprintf(stderr,
+ "Error: Image corrupt DCD size %d exceed maximum %d\n",
+ (uint32_t)(size / sizeof(dcd_type_addr_data_t)),
+ MAX_HW_CFG_SIZE_V1);
+ exit(EXIT_FAILURE);
+ }
+
+ length = dcd_v1->preamble.length / sizeof(dcd_type_addr_data_t);
+ ver = detect_imximage_version(imx_hdr);
+
+ printf("Image Type: Freescale IMX Boot Image\n");
+ printf("Image Ver: %x", ver);
+ printf("%s\n", get_table_entry_name(imximage_versions, NULL, ver));
+ printf("Data Size: ");
+ genimg_print_size(dcd_v1->addr_data[length].type);
+ printf("Load Address: %08x\n", (uint32_t)fhdr_v1->app_dest_ptr);
+ printf("Entry Point: %08x\n", (uint32_t)fhdr_v1->app_code_jump_vector);
+}
+
+static void print_hdr_v2(struct imx_header *imx_hdr)
+{
+ imx_header_v2_t *hdr_v2 = &imx_hdr->header.hdr_v2;
+ flash_header_v2_t *fhdr_v2 = &hdr_v2->fhdr;
+ dcd_v2_t *dcd_v2 = &hdr_v2->dcd_table;
+ uint32_t size, version;
+
+ size = be16_to_cpu(dcd_v2->header.length) - 8;
+ if (size > (MAX_HW_CFG_SIZE_V2 * sizeof(dcd_addr_data_t))) {
+ fprintf(stderr,
+ "Error: Image corrupt DCD size %d exceed maximum %d\n",
+ (uint32_t)(size / sizeof(dcd_addr_data_t)),
+ MAX_HW_CFG_SIZE_V2);
+ exit(EXIT_FAILURE);
+ }
+
+ version = detect_imximage_version(imx_hdr);
+
+ printf("Image Type: Freescale IMX Boot Image\n");
+ printf("Image Ver: %x", version);
+ printf("%s\n", get_table_entry_name(imximage_versions, NULL, version));
+ printf("Data Size: ");
+ genimg_print_size(hdr_v2->boot_data.size);
+ printf("Load Address: %08x\n", (uint32_t)fhdr_v2->boot_data_ptr);
+ printf("Entry Point: %08x\n", (uint32_t)fhdr_v2->entry);
+ if (fhdr_v2->csf && (imximage_ivt_offset != UNDEFINED) &&
+ (imximage_csf_size != UNDEFINED)) {
+ printf("HAB Blocks: %08x %08x %08x\n",
+ (uint32_t)fhdr_v2->self, 0,
+ hdr_v2->boot_data.size - imximage_ivt_offset -
+ imximage_csf_size);
+ }
+}
+
+static void parse_cfg_cmd(struct imx_header *imxhdr, int32_t cmd, char *token,
+ char *name, int lineno, int fld, int dcd_len)
+{
+ int value;
+ static int cmd_ver_first = ~0;
+
+ switch (cmd) {
+ case CMD_IMAGE_VERSION:
+ imximage_version = get_cfg_value(token, name, lineno);
+ if (cmd_ver_first == 0) {
+ fprintf(stderr, "Error: %s[%d] - IMAGE_VERSION "
+ "command need be the first before other "
+ "valid command in the file\n", name, lineno);
+ exit(EXIT_FAILURE);
+ }
+ cmd_ver_first = 1;
+ set_hdr_func();
+ break;
+ case CMD_BOOT_FROM:
+ imximage_ivt_offset = get_table_entry_id(imximage_boot_offset,
+ "imximage boot option", token);
+ if (imximage_ivt_offset == -1) {
+ fprintf(stderr, "Error: %s[%d] -Invalid boot device"
+ "(%s)\n", name, lineno, token);
+ exit(EXIT_FAILURE);
+ }
+
+ imximage_init_loadsize =
+ get_table_entry_id(imximage_boot_loadsize,
+ "imximage boot option", token);
+
+ if (imximage_init_loadsize == -1) {
+ fprintf(stderr,
+ "Error: %s[%d] -Invalid boot device(%s)\n",
+ name, lineno, token);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * The SOC loads from the storage starting at address 0
+ * then ensures that the load size contains the offset
+ */
+ if (imximage_init_loadsize < imximage_ivt_offset)
+ imximage_init_loadsize = imximage_ivt_offset;
+ if (unlikely(cmd_ver_first != 1))
+ cmd_ver_first = 0;
+ break;
+ case CMD_BOOT_OFFSET:
+ imximage_ivt_offset = get_cfg_value(token, name, lineno);
+ if (unlikely(cmd_ver_first != 1))
+ cmd_ver_first = 0;
+ break;
+ case CMD_DATA:
+ value = get_cfg_value(token, name, lineno);
+ (*set_dcd_val)(imxhdr, name, lineno, fld, value, dcd_len);
+ if (unlikely(cmd_ver_first != 1))
+ cmd_ver_first = 0;
+ break;
+ case CMD_CSF:
+ if (imximage_version != 2) {
+ fprintf(stderr,
+ "Error: %s[%d] - CSF only supported for VERSION 2(%s)\n",
+ name, lineno, token);
+ exit(EXIT_FAILURE);
+ }
+ imximage_csf_size = get_cfg_value(token, name, lineno);
+ if (unlikely(cmd_ver_first != 1))
+ cmd_ver_first = 0;
+ break;
+ }
+}
+
+static void parse_cfg_fld(struct imx_header *imxhdr, int32_t *cmd,
+ char *token, char *name, int lineno, int fld, int *dcd_len)
+{
+ int value;
+
+ switch (fld) {
+ case CFG_COMMAND:
+ *cmd = get_table_entry_id(imximage_cmds,
+ "imximage commands", token);
+ if (*cmd < 0) {
+ fprintf(stderr, "Error: %s[%d] - Invalid command"
+ "(%s)\n", name, lineno, token);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case CFG_REG_SIZE:
+ parse_cfg_cmd(imxhdr, *cmd, token, name, lineno, fld, *dcd_len);
+ break;
+ case CFG_REG_ADDRESS:
+ case CFG_REG_VALUE:
+ if (*cmd != CMD_DATA)
+ return;
+
+ value = get_cfg_value(token, name, lineno);
+ (*set_dcd_val)(imxhdr, name, lineno, fld, value, *dcd_len);
+
+ if (fld == CFG_REG_VALUE) {
+ (*dcd_len)++;
+ if (*dcd_len > max_dcd_entries) {
+ fprintf(stderr, "Error: %s[%d] -"
+ "DCD table exceeds maximum size(%d)\n",
+ name, lineno, max_dcd_entries);
+ exit(EXIT_FAILURE);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+static uint32_t parse_cfg_file(struct imx_header *imxhdr, char *name)
+{
+ FILE *fd = NULL;
+ char *line = NULL;
+ char *token, *saveptr1, *saveptr2;
+ int lineno = 0;
+ int fld;
+ size_t len;
+ int dcd_len = 0;
+ int32_t cmd;
+
+ fd = fopen(name, "r");
+ if (fd == 0) {
+ fprintf(stderr, "Error: %s - Can't open DCD file\n", name);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Very simple parsing, line starting with # are comments
+ * and are dropped
+ */
+ while ((getline(&line, &len, fd)) > 0) {
+ lineno++;
+
+ token = strtok_r(line, "\r\n", &saveptr1);
+ if (token == NULL)
+ continue;
+
+ /* Check inside the single line */
+ for (fld = CFG_COMMAND, cmd = CMD_INVALID,
+ line = token; ; line = NULL, fld++) {
+ token = strtok_r(line, " \t", &saveptr2);
+ if (token == NULL)
+ break;
+
+ /* Drop all text starting with '#' as comments */
+ if (token[0] == '#')
+ break;
+
+ parse_cfg_fld(imxhdr, &cmd, token, name,
+ lineno, fld, &dcd_len);
+ }
+
+ }
+
+ (*set_dcd_rst)(imxhdr, dcd_len, name, lineno);
+ fclose(fd);
+
+ /* Exit if there is no BOOT_FROM field specifying the flash_offset */
+ if (imximage_ivt_offset == FLASH_OFFSET_UNDEFINED) {
+ fprintf(stderr, "Error: No BOOT_FROM tag in %s\n", name);
+ exit(EXIT_FAILURE);
+ }
+ return dcd_len;
+}
+
+
+static int imximage_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_IMXIMAGE)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static int imximage_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ struct imx_header *imx_hdr = (struct imx_header *) ptr;
+
+ if (detect_imximage_version(imx_hdr) == IMXIMAGE_VER_INVALID)
+ return -FDT_ERR_BADSTRUCTURE;
+
+ return 0;
+}
+
+static void imximage_print_header(const void *ptr)
+{
+ struct imx_header *imx_hdr = (struct imx_header *) ptr;
+ uint32_t version = detect_imximage_version(imx_hdr);
+
+ switch (version) {
+ case IMXIMAGE_V1:
+ print_hdr_v1(imx_hdr);
+ break;
+ case IMXIMAGE_V2:
+ print_hdr_v2(imx_hdr);
+ break;
+ default:
+ err_imximage_version(version);
+ break;
+ }
+}
+
+static void imximage_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ struct imx_header *imxhdr = (struct imx_header *)ptr;
+ uint32_t dcd_len;
+
+ /*
+ * In order to not change the old imx cfg file
+ * by adding VERSION command into it, here need
+ * set up function ptr group to V1 by default.
+ */
+ imximage_version = IMXIMAGE_V1;
+ /* Be able to detect if the cfg file has no BOOT_FROM tag */
+ imximage_ivt_offset = FLASH_OFFSET_UNDEFINED;
+ imximage_csf_size = 0;
+ set_hdr_func();
+
+ /* Parse dcd configuration file */
+ dcd_len = parse_cfg_file(imxhdr, params->imagename);
+
+ /* Set the imx header */
+ (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset);
+
+ /*
+ * ROM bug alert
+ *
+ * MX53 only loads 512 byte multiples in case of SD boot.
+ * MX53 only loads NAND page multiples in case of NAND boot and
+ * supports up to 4096 byte large pages, thus align to 4096.
+ *
+ * The remaining fraction of a block bytes would not be loaded!
+ */
+ *header_size_ptr = ROUND(sbuf->st_size, 4096);
+
+ if (csf_ptr && imximage_csf_size) {
+ *csf_ptr = params->ep - imximage_init_loadsize +
+ *header_size_ptr;
+ *header_size_ptr += imximage_csf_size;
+ }
+}
+
+int imximage_check_params(struct image_tool_params *params)
+{
+ if (!params)
+ return CFG_INVALID;
+ if (!strlen(params->imagename)) {
+ fprintf(stderr, "Error: %s - Configuration file not specified, "
+ "it is needed for imximage generation\n",
+ params->cmdname);
+ return CFG_INVALID;
+ }
+ /*
+ * Check parameters:
+ * XIP is not allowed and verify that incompatible
+ * parameters are not sent at the same time
+ * For example, if list is required a data image must not be provided
+ */
+ return (params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)) ||
+ (params->xflag) || !(strlen(params->imagename));
+}
+
+static int imximage_generate(struct image_tool_params *params,
+ struct image_type_params *tparams)
+{
+ struct imx_header *imxhdr;
+ size_t alloc_len;
+ struct stat sbuf;
+ char *datafile = params->datafile;
+ uint32_t pad_len;
+
+ memset(&imximage_header, 0, sizeof(imximage_header));
+
+ /*
+ * In order to not change the old imx cfg file
+ * by adding VERSION command into it, here need
+ * set up function ptr group to V1 by default.
+ */
+ imximage_version = IMXIMAGE_V1;
+ /* Be able to detect if the cfg file has no BOOT_FROM tag */
+ imximage_ivt_offset = FLASH_OFFSET_UNDEFINED;
+ imximage_csf_size = 0;
+ set_hdr_func();
+
+ /* Parse dcd configuration file */
+ parse_cfg_file(&imximage_header, params->imagename);
+
+ /* TODO: check i.MX image V1 handling, for now use 'old' style */
+ if (imximage_version == IMXIMAGE_V1) {
+ alloc_len = 4096;
+ } else {
+ if (imximage_init_loadsize < imximage_ivt_offset +
+ sizeof(imx_header_v2_t))
+ imximage_init_loadsize = imximage_ivt_offset +
+ sizeof(imx_header_v2_t);
+ alloc_len = imximage_init_loadsize - imximage_ivt_offset;
+ }
+
+ if (alloc_len < sizeof(struct imx_header)) {
+ fprintf(stderr, "%s: header error\n",
+ params->cmdname);
+ exit(EXIT_FAILURE);
+ }
+
+ imxhdr = malloc(alloc_len);
+
+ if (!imxhdr) {
+ fprintf(stderr, "%s: malloc return failure: %s\n",
+ params->cmdname, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ memset(imxhdr, 0, alloc_len);
+
+ tparams->header_size = alloc_len;
+ tparams->hdr = imxhdr;
+
+ /* determine data image file length */
+
+ if (stat(datafile, &sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat %s: %s\n",
+ params->cmdname, datafile, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
+
+ /* TODO: check i.MX image V1 handling, for now use 'old' style */
+ if (imximage_version == IMXIMAGE_V1)
+ return 0;
+ else
+ return pad_len;
+}
+
+
+/*
+ * imximage parameters
+ */
+static struct image_type_params imximage_params = {
+ .name = "Freescale i.MX Boot Image support",
+ .header_size = 0,
+ .hdr = NULL,
+ .check_image_type = imximage_check_image_types,
+ .verify_header = imximage_verify_header,
+ .print_header = imximage_print_header,
+ .set_header = imximage_set_header,
+ .check_params = imximage_check_params,
+ .vrec_header = imximage_generate,
+};
+
+void init_imx_image_type(void)
+{
+ register_image_type(&imximage_params);
+}
diff --git a/roms/u-boot/tools/imximage.h b/roms/u-boot/tools/imximage.h
new file mode 100644
index 00000000..01f861e7
--- /dev/null
+++ b/roms/u-boot/tools/imximage.h
@@ -0,0 +1,175 @@
+/*
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _IMXIMAGE_H_
+#define _IMXIMAGE_H_
+
+#define MAX_HW_CFG_SIZE_V2 121 /* Max number of registers imx can set for v2 */
+#define MAX_HW_CFG_SIZE_V1 60 /* Max number of registers imx can set for v1 */
+#define APP_CODE_BARKER 0xB1
+#define DCD_BARKER 0xB17219E9
+
+/*
+ * NOTE: This file must be kept in sync with arch/arm/include/asm/\
+ * imx-common/imximage.cfg because tools/imximage.c can not
+ * cross-include headers from arch/arm/ and vice-versa.
+ */
+#define CMD_DATA_STR "DATA"
+
+/* Initial Vector Table Offset */
+#define FLASH_OFFSET_UNDEFINED 0xFFFFFFFF
+#define FLASH_OFFSET_STANDARD 0x400
+#define FLASH_OFFSET_NAND FLASH_OFFSET_STANDARD
+#define FLASH_OFFSET_SD FLASH_OFFSET_STANDARD
+#define FLASH_OFFSET_SPI FLASH_OFFSET_STANDARD
+#define FLASH_OFFSET_ONENAND 0x100
+#define FLASH_OFFSET_NOR 0x1000
+#define FLASH_OFFSET_SATA FLASH_OFFSET_STANDARD
+
+/* Initial Load Region Size */
+#define FLASH_LOADSIZE_UNDEFINED 0xFFFFFFFF
+#define FLASH_LOADSIZE_STANDARD 0x1000
+#define FLASH_LOADSIZE_NAND FLASH_LOADSIZE_STANDARD
+#define FLASH_LOADSIZE_SD FLASH_LOADSIZE_STANDARD
+#define FLASH_LOADSIZE_SPI FLASH_LOADSIZE_STANDARD
+#define FLASH_LOADSIZE_ONENAND 0x400
+#define FLASH_LOADSIZE_NOR 0x0 /* entire image */
+#define FLASH_LOADSIZE_SATA FLASH_LOADSIZE_STANDARD
+
+#define IVT_HEADER_TAG 0xD1
+#define IVT_VERSION 0x40
+#define DCD_HEADER_TAG 0xD2
+#define DCD_COMMAND_TAG 0xCC
+#define DCD_VERSION 0x40
+#define DCD_COMMAND_PARAM 0x4
+
+enum imximage_cmd {
+ CMD_INVALID,
+ CMD_IMAGE_VERSION,
+ CMD_BOOT_FROM,
+ CMD_BOOT_OFFSET,
+ CMD_DATA,
+ CMD_CSF,
+};
+
+enum imximage_fld_types {
+ CFG_INVALID = -1,
+ CFG_COMMAND,
+ CFG_REG_SIZE,
+ CFG_REG_ADDRESS,
+ CFG_REG_VALUE
+};
+
+enum imximage_version {
+ IMXIMAGE_VER_INVALID = -1,
+ IMXIMAGE_V1 = 1,
+ IMXIMAGE_V2
+};
+
+typedef struct {
+ uint32_t type; /* Type of pointer (byte, halfword, word, wait/read) */
+ uint32_t addr; /* Address to write to */
+ uint32_t value; /* Data to write */
+} dcd_type_addr_data_t;
+
+typedef struct {
+ uint32_t barker; /* Barker for sanity check */
+ uint32_t length; /* Device configuration length (without preamble) */
+} dcd_preamble_t;
+
+typedef struct {
+ dcd_preamble_t preamble;
+ dcd_type_addr_data_t addr_data[MAX_HW_CFG_SIZE_V1];
+} dcd_v1_t;
+
+typedef struct {
+ uint32_t app_code_jump_vector;
+ uint32_t app_code_barker;
+ uint32_t app_code_csf;
+ uint32_t dcd_ptr_ptr;
+ uint32_t super_root_key;
+ uint32_t dcd_ptr;
+ uint32_t app_dest_ptr;
+} flash_header_v1_t;
+
+typedef struct {
+ uint32_t length; /* Length of data to be read from flash */
+} flash_cfg_parms_t;
+
+typedef struct {
+ flash_header_v1_t fhdr;
+ dcd_v1_t dcd_table;
+ flash_cfg_parms_t ext_header;
+} imx_header_v1_t;
+
+typedef struct {
+ uint32_t addr;
+ uint32_t value;
+} dcd_addr_data_t;
+
+typedef struct {
+ uint8_t tag;
+ uint16_t length;
+ uint8_t version;
+} __attribute__((packed)) ivt_header_t;
+
+typedef struct {
+ uint8_t tag;
+ uint16_t length;
+ uint8_t param;
+} __attribute__((packed)) write_dcd_command_t;
+
+typedef struct {
+ ivt_header_t header;
+ write_dcd_command_t write_dcd_command;
+ dcd_addr_data_t addr_data[MAX_HW_CFG_SIZE_V2];
+} dcd_v2_t;
+
+typedef struct {
+ uint32_t start;
+ uint32_t size;
+ uint32_t plugin;
+} boot_data_t;
+
+typedef struct {
+ ivt_header_t header;
+ uint32_t entry;
+ uint32_t reserved1;
+ uint32_t dcd_ptr;
+ uint32_t boot_data_ptr;
+ uint32_t self;
+ uint32_t csf;
+ uint32_t reserved2;
+} flash_header_v2_t;
+
+typedef struct {
+ flash_header_v2_t fhdr;
+ boot_data_t boot_data;
+ dcd_v2_t dcd_table;
+} imx_header_v2_t;
+
+/* The header must be aligned to 4k on MX53 for NAND boot */
+struct imx_header {
+ union {
+ imx_header_v1_t hdr_v1;
+ imx_header_v2_t hdr_v2;
+ } header;
+};
+
+typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
+ char *name, int lineno,
+ int fld, uint32_t value,
+ uint32_t off);
+
+typedef void (*set_dcd_rst_t)(struct imx_header *imxhdr,
+ uint32_t dcd_len,
+ char *name, int lineno);
+
+typedef void (*set_imx_hdr_t)(struct imx_header *imxhdr, uint32_t dcd_len,
+ uint32_t entry_point, uint32_t flash_offset);
+
+#endif /* _IMXIMAGE_H_ */
diff --git a/roms/u-boot/tools/jtagconsole b/roms/u-boot/tools/jtagconsole
new file mode 100755
index 00000000..d404fac5
--- /dev/null
+++ b/roms/u-boot/tools/jtagconsole
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+usage() {
+ (
+ echo "Usage: $0 [board IP] [board port]"
+ echo ""
+ echo "If IP is not specified, 'localhost' will be used"
+ echo "If port is not specified, '2001' will be used"
+ [ -z "$*" ] && exit 0
+ echo ""
+ echo "ERROR: $*"
+ exit 1
+ ) 1>&2
+ exit $?
+}
+
+while [ -n "$1" ] ; do
+ case $1 in
+ -h|--help) usage;;
+ --) break;;
+ -*) usage "Invalid option $1";;
+ *) break;;
+ esac
+ shift
+done
+
+ip=${1:-localhost}
+port=${2:-2001}
+
+if [ -z "${ip}" ] || [ -n "$3" ] ; then
+ usage "Invalid number of arguments"
+fi
+
+trap "stty icanon echo opost intr ^C" 0 2 3 5 10 13 15
+echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
+
+stty -icanon -echo -opost intr ^T
+nc ${ip} ${port}
+exit 0
diff --git a/roms/u-boot/tools/kermit/README b/roms/u-boot/tools/kermit/README
new file mode 100644
index 00000000..c3b491aa
--- /dev/null
+++ b/roms/u-boot/tools/kermit/README
@@ -0,0 +1,51 @@
+#
+# (C) Copyright 2001
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+This directory contains scripts that help to perform certain actions
+that need to be done frequently when working with U-Boot.
+
+They are meant as EXAMPLE code, so it is very likely that you will
+have to modify them before use.
+
+
+Short description:
+==================
+
+dot.kermrc:
+
+ Example for "~/.kermrc" Kermit init file for use with U-Boot
+
+ by Wolfgang Denk, 24 Jun 2001
+
+flash_param:
+
+ "kermit" script to automatically initialize the environment
+ variables on your target. This is most useful during
+ development when your environment variables are stored in an
+ embedded flash sector which is erased whenever you install a
+ new U-Boot image.
+
+ by Swen Anderson, 10 May 2001
+
+send_cmd:
+
+ send_cmd U_BOOT_COMMAND
+
+ "kermit" script to send a U-Boot command and print the
+ results. When used from a shell with history (like the bash)
+ this indirectly adds kind of history to U-Boot ;-)
+
+ by Swen Anderson, 10 May 2001
+
+send_image:
+
+ send_image FILE_NAME OFFSET
+
+ "kermit" script to automatically download a file to the
+ target using the "loadb" command (kermit binary protocol)
+
+ by Swen Anderson, 10 May 2001
diff --git a/roms/u-boot/tools/kermit/dot.kermrc b/roms/u-boot/tools/kermit/dot.kermrc
new file mode 100644
index 00000000..0fc6c15d
--- /dev/null
+++ b/roms/u-boot/tools/kermit/dot.kermrc
@@ -0,0 +1,16 @@
+set line /dev/ttyS0
+set speed 115200
+set carrier-watch off
+set handshake none
+set flow-control none
+robust
+set file type bin
+set file name lit
+set rec pack 1000
+set send pack 1000
+set window 5
+set prompt Kermit>
+define sz !sz \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 \%9 < \v(line) > \v(line)
+define rz !rz \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 \%9 < \v(line) > \v(line)
+define sx !sx \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 \%9 < \v(line) > \v(line)
+define rx !rx \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 \%9 < \v(line) > \v(line)
diff --git a/roms/u-boot/tools/kermit/flash_param b/roms/u-boot/tools/kermit/flash_param
new file mode 100644
index 00000000..847f99e1
--- /dev/null
+++ b/roms/u-boot/tools/kermit/flash_param
@@ -0,0 +1,60 @@
+#!/usr/bin/kermit +
+# usage: ./flash_param parameters
+# Parameters: IP Address ETH Address ERIC Number
+# Format: xxx.xxx.xxx.xxx xx:xx:xx:xx:xx:xx xxxx
+
+set line /dev/ttyS0
+set speed 115200
+set serial 8N1
+set carrier-watch off
+set handshake none
+#set flow-control none
+set flow-control xon/xoff
+#robust
+set file type bin
+set file name lit
+set rec pack 1000
+set send pack 1000
+set window 5
+set prompt Kermit>
+#robust
+# Milliseconds to pause between each OUTPUT character
+set output pacing 1
+
+out \13
+in 10 =>
+#first erase the environment memory within NVRAM
+out mw f0000000 0 200\13
+in 10 =>
+out reset\13
+in 5 autoboot
+out \13\13
+in 10 =>
+#set additional env parameter
+out setenv ethaddr \%2\13
+in 10 =>
+out setenv serial# ERIC 1.0 \%3\13
+in 10 =>
+out setenv eric_id \%3\13
+in 10 =>
+#out setenv prec_videocard_bus unknown\13
+#in 10 =>
+#out setenv prec_bios_type unknown\13
+#in 10 =>
+out setenv eric_passwd .eRIC.\13
+in 10 =>
+#out setenv bootargs root=/dev/ram ramdisk_size=8192 init=/sbin/init ip=\%1:192.168.1.100:192.168.1.254:255.255.255.0\13
+#out setenv bootargs root=/dev/ram ramdisk_size=8192 init=/sbin/init ip=\%1:192.168.0.1\13
+#out setenv bootargs root=/dev/ram ramdisk_size=8192 init=/sbin/init ip=\%1\13
+out setenv bootargs console=/dev/ttyS0,115200 root=/dev/nfs nfsroot=192.168.1.26:/eric_root_devel ip=\%1:192.168.1.26\13
+in 10 =>
+out setenv bootcmd bootm FFC00000\13
+in 10 =>
+out saveenv\13
+in 10 =>
+out reset\13
+in 5 autoboot
+out \13\13
+in 10 =>
+quit
+exit 0
diff --git a/roms/u-boot/tools/kermit/send_cmd b/roms/u-boot/tools/kermit/send_cmd
new file mode 100644
index 00000000..4131331f
--- /dev/null
+++ b/roms/u-boot/tools/kermit/send_cmd
@@ -0,0 +1,21 @@
+#!/usr/bin/kermit +
+set line /dev/ttyS0
+set speed 115200
+set serial 8N1
+set carrier-watch off
+set handshake none
+set flow-control none
+robust
+set file type bin
+set file name lit
+set rec pack 1000
+set send pack 1000
+set window 5
+set prompt Kermit>
+
+#out \13
+#in 10 =>
+out \%1 \%2 \%3 \%4 \%5 \%6 \%7\13
+in 10 =>
+quit
+exit 0
diff --git a/roms/u-boot/tools/kermit/send_image b/roms/u-boot/tools/kermit/send_image
new file mode 100644
index 00000000..9b89d6b0
--- /dev/null
+++ b/roms/u-boot/tools/kermit/send_image
@@ -0,0 +1,26 @@
+#!/usr/bin/kermit +
+# usage: send_image FILE_NAME OFFSET
+# e.g. send_image output.bin 1F00000
+set line /dev/ttyS0
+set speed 115200
+set serial 8N1
+set carrier-watch off
+set handshake none
+set flow-control none
+robust
+set file type bin
+set file name lit
+set rec pack 1000
+set send pack 1000
+set window 5
+set prompt Kermit>
+
+out \13
+in 10 =>
+out loadb \%2 \13
+in 10 download ...
+send \%1
+out \13
+in 10 ## Start Addr
+quit
+exit 0
diff --git a/roms/u-boot/tools/kwbimage.c b/roms/u-boot/tools/kwbimage.c
new file mode 100644
index 00000000..109d6168
--- /dev/null
+++ b/roms/u-boot/tools/kwbimage.c
@@ -0,0 +1,386 @@
+/*
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include
+#include "kwbimage.h"
+
+/*
+ * Supported commands for configuration file
+ */
+static table_entry_t kwbimage_cmds[] = {
+ {CMD_BOOT_FROM, "BOOT_FROM", "boot command", },
+ {CMD_NAND_ECC_MODE, "NAND_ECC_MODE", "NAND mode", },
+ {CMD_NAND_PAGE_SIZE, "NAND_PAGE_SIZE", "NAND size", },
+ {CMD_SATA_PIO_MODE, "SATA_PIO_MODE", "SATA mode", },
+ {CMD_DDR_INIT_DELAY, "DDR_INIT_DELAY", "DDR init dly", },
+ {CMD_DATA, "DATA", "Reg Write Data", },
+ {CMD_INVALID, "", "", },
+};
+
+/*
+ * Supported Boot options for configuration file
+ */
+static table_entry_t kwbimage_bootops[] = {
+ {IBR_HDR_SPI_ID, "spi", "SPI Flash", },
+ {IBR_HDR_NAND_ID, "nand", "NAND Flash", },
+ {IBR_HDR_SATA_ID, "sata", "Sata port", },
+ {IBR_HDR_PEX_ID, "pex", "PCIe port", },
+ {IBR_HDR_UART_ID, "uart", "Serial port", },
+ {-1, "", "Invalid", },
+};
+
+/*
+ * Supported NAND ecc options configuration file
+ */
+static table_entry_t kwbimage_eccmodes[] = {
+ {IBR_HDR_ECC_DEFAULT, "default", "Default mode", },
+ {IBR_HDR_ECC_FORCED_HAMMING, "hamming", "Hamming mode", },
+ {IBR_HDR_ECC_FORCED_RS, "rs", "RS mode", },
+ {IBR_HDR_ECC_DISABLED, "disabled", "ECC Disabled", },
+ {-1, "", "", },
+};
+
+static struct kwb_header kwbimage_header;
+static int datacmd_cnt = 0;
+static char * fname = "Unknown";
+static int lineno = -1;
+
+/*
+ * Report Error if xflag is set in addition to default
+ */
+static int kwbimage_check_params(struct image_tool_params *params)
+{
+ if (!strlen (params->imagename)) {
+ printf ("Error:%s - Configuration file not specified, "
+ "it is needed for kwbimage generation\n",
+ params->cmdname);
+ return CFG_INVALID;
+ }
+ return ((params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)) ||
+ (params->xflag) || !(strlen (params->imagename)));
+}
+
+static uint32_t check_get_hexval (char *token)
+{
+ uint32_t hexval;
+
+ if (!sscanf (token, "%x", &hexval)) {
+ printf ("Error:%s[%d] - Invalid hex data(%s)\n", fname,
+ lineno, token);
+ exit (EXIT_FAILURE);
+ }
+ return hexval;
+}
+
+/*
+ * Generates 8 bit checksum
+ */
+static uint8_t kwbimage_checksum8 (void *start, uint32_t len, uint8_t csum)
+{
+ register uint8_t sum = csum;
+ volatile uint8_t *p = (volatile uint8_t *)start;
+
+ /* check len and return zero checksum if invalid */
+ if (!len)
+ return 0;
+
+ do {
+ sum += *p;
+ p++;
+ } while (--len);
+ return (sum);
+}
+
+/*
+ * Generates 32 bit checksum
+ */
+static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csum)
+{
+ register uint32_t sum = csum;
+ volatile uint32_t *p = start;
+
+ /* check len and return zero checksum if invalid */
+ if (!len)
+ return 0;
+
+ if (len % sizeof(uint32_t)) {
+ printf ("Error:%s[%d] - length is not in multiple of %zu\n",
+ __FUNCTION__, len, sizeof(uint32_t));
+ return 0;
+ }
+
+ do {
+ sum += *p;
+ p++;
+ len -= sizeof(uint32_t);
+ } while (len > 0);
+ return (sum);
+}
+
+static void kwbimage_check_cfgdata (char *token, enum kwbimage_cmd cmdsw,
+ struct kwb_header *kwbhdr)
+{
+ bhr_t *mhdr = &kwbhdr->kwb_hdr;
+ extbhr_t *exthdr = &kwbhdr->kwb_exthdr;
+ int i;
+
+ switch (cmdsw) {
+ case CMD_BOOT_FROM:
+ i = get_table_entry_id (kwbimage_bootops,
+ "Kwbimage boot option", token);
+
+ if (i < 0)
+ goto INVL_DATA;
+
+ mhdr->blockid = i;
+ printf ("Preparing kirkwood boot image to boot "
+ "from %s\n", token);
+ break;
+ case CMD_NAND_ECC_MODE:
+ i = get_table_entry_id (kwbimage_eccmodes,
+ "NAND ecc mode", token);
+
+ if (i < 0)
+ goto INVL_DATA;
+
+ mhdr->nandeccmode = i;
+ printf ("Nand ECC mode = %s\n", token);
+ break;
+ case CMD_NAND_PAGE_SIZE:
+ mhdr->nandpagesize =
+ (uint16_t) check_get_hexval (token);
+ printf ("Nand page size = 0x%x\n", mhdr->nandpagesize);
+ break;
+ case CMD_SATA_PIO_MODE:
+ mhdr->satapiomode =
+ (uint8_t) check_get_hexval (token);
+ printf ("Sata PIO mode = 0x%x\n",
+ mhdr->satapiomode);
+ break;
+ case CMD_DDR_INIT_DELAY:
+ mhdr->ddrinitdelay =
+ (uint16_t) check_get_hexval (token);
+ printf ("DDR init delay = %d msec\n", mhdr->ddrinitdelay);
+ break;
+ case CMD_DATA:
+ exthdr->rcfg[datacmd_cnt].raddr =
+ check_get_hexval (token);
+
+ break;
+ case CMD_INVALID:
+ goto INVL_DATA;
+ default:
+ goto INVL_DATA;
+ }
+ return;
+
+INVL_DATA:
+ printf ("Error:%s[%d] - Invalid data\n", fname, lineno);
+ exit (EXIT_FAILURE);
+}
+
+/*
+ * this function sets the kwbimage header by-
+ * 1. Abstracting input command line arguments data
+ * 2. parses the kwbimage configuration file and update extebded header data
+ * 3. calculates header, extended header and image checksums
+ */
+static void kwdimage_set_ext_header (struct kwb_header *kwbhdr, char* name) {
+ bhr_t *mhdr = &kwbhdr->kwb_hdr;
+ extbhr_t *exthdr = &kwbhdr->kwb_exthdr;
+ FILE *fd = NULL;
+ int j;
+ char *line = NULL;
+ char * token, *saveptr1, *saveptr2;
+ size_t len = 0;
+ enum kwbimage_cmd cmd;
+
+ fname = name;
+ /* set dram register offset */
+ exthdr->dramregsoffs = (intptr_t)&exthdr->rcfg - (intptr_t)mhdr;
+
+ if ((fd = fopen (name, "r")) == 0) {
+ printf ("Error:%s - Can't open\n", fname);
+ exit (EXIT_FAILURE);
+ }
+
+ /* Simple kwimage.cfg file parser */
+ lineno=0;
+ while ((getline (&line, &len, fd)) > 0) {
+ lineno++;
+ token = strtok_r (line, "\r\n", &saveptr1);
+ /* drop all lines with zero tokens (= empty lines) */
+ if (token == NULL)
+ continue;
+
+ for (j = 0, cmd = CMD_INVALID, line = token; ; line = NULL) {
+ token = strtok_r (line, " \t", &saveptr2);
+ if (token == NULL)
+ break;
+ /* Drop all text starting with '#' as comments */
+ if (token[0] == '#')
+ break;
+
+ /* Process rest as valid config command line */
+ switch (j) {
+ case CFG_COMMAND:
+ cmd = get_table_entry_id (kwbimage_cmds,
+ "Kwbimage command", token);
+
+ if (cmd == CMD_INVALID)
+ goto INVL_CMD;
+ break;
+
+ case CFG_DATA0:
+ kwbimage_check_cfgdata (token, cmd, kwbhdr);
+ break;
+
+ case CFG_DATA1:
+ if (cmd != CMD_DATA)
+ goto INVL_CMD;
+
+ exthdr->rcfg[datacmd_cnt].rdata =
+ check_get_hexval (token);
+
+ if (datacmd_cnt > KWBIMAGE_MAX_CONFIG ) {
+ printf ("Error:%s[%d] - Found more "
+ "than max(%zd) allowed "
+ "data configurations\n",
+ fname, lineno,
+ KWBIMAGE_MAX_CONFIG);
+ exit (EXIT_FAILURE);
+ } else
+ datacmd_cnt++;
+ break;
+
+ default:
+ goto INVL_CMD;
+ }
+ j++;
+ }
+ }
+ if (line)
+ free (line);
+
+ fclose (fd);
+ return;
+
+/*
+ * Invalid Command error reporring
+ *
+ * command CMD_DATA needs three strings on a line
+ * whereas other commands need only two.
+ *
+ * if more than two/three (as per command type) are observed,
+ * then error will be reported
+ */
+INVL_CMD:
+ printf ("Error:%s[%d] - Invalid command\n", fname, lineno);
+ exit (EXIT_FAILURE);
+}
+
+static void kwbimage_set_header (void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ struct kwb_header *hdr = (struct kwb_header *)ptr;
+ bhr_t *mhdr = &hdr->kwb_hdr;
+ extbhr_t *exthdr = &hdr->kwb_exthdr;
+ uint32_t checksum;
+ int size;
+
+ /* Build and add image checksum header */
+ checksum = kwbimage_checksum32 ((uint32_t *)ptr, sbuf->st_size, 0);
+
+ size = write (ifd, &checksum, sizeof(uint32_t));
+ if (size != sizeof(uint32_t)) {
+ printf ("Error:%s - Checksum write %d bytes %s\n",
+ params->cmdname, size, params->imagefile);
+ exit (EXIT_FAILURE);
+ }
+
+ sbuf->st_size += sizeof(uint32_t);
+
+ mhdr->blocksize = sbuf->st_size - sizeof(struct kwb_header);
+ mhdr->srcaddr = sizeof(struct kwb_header);
+ mhdr->destaddr= params->addr;
+ mhdr->execaddr =params->ep;
+ mhdr->ext = 0x1; /* header extension appended */
+
+ kwdimage_set_ext_header (hdr, params->imagename);
+ /* calculate checksums */
+ mhdr->checkSum = kwbimage_checksum8 ((void *)mhdr, sizeof(bhr_t), 0);
+ exthdr->checkSum = kwbimage_checksum8 ((void *)exthdr,
+ sizeof(extbhr_t), 0);
+}
+
+static int kwbimage_verify_header (unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ struct kwb_header *hdr = (struct kwb_header *)ptr;
+ bhr_t *mhdr = &hdr->kwb_hdr;
+ extbhr_t *exthdr = &hdr->kwb_exthdr;
+ uint8_t calc_hdrcsum;
+ uint8_t calc_exthdrcsum;
+
+ calc_hdrcsum = kwbimage_checksum8 ((void *)mhdr,
+ sizeof(bhr_t) - sizeof(uint8_t), 0);
+ if (calc_hdrcsum != mhdr->checkSum)
+ return -FDT_ERR_BADSTRUCTURE; /* mhdr csum not matched */
+
+ calc_exthdrcsum = kwbimage_checksum8 ((void *)exthdr,
+ sizeof(extbhr_t) - sizeof(uint8_t), 0);
+ if (calc_exthdrcsum != exthdr->checkSum)
+ return -FDT_ERR_BADSTRUCTURE; /* exthdr csum not matched */
+
+ return 0;
+}
+
+static void kwbimage_print_header (const void *ptr)
+{
+ struct kwb_header *hdr = (struct kwb_header *) ptr;
+ bhr_t *mhdr = &hdr->kwb_hdr;
+ char *name = get_table_entry_name (kwbimage_bootops,
+ "Kwbimage boot option",
+ (int) mhdr->blockid);
+
+ printf ("Image Type: Kirkwood Boot from %s Image\n", name);
+ printf ("Data Size: ");
+ genimg_print_size (mhdr->blocksize - sizeof(uint32_t));
+ printf ("Load Address: %08x\n", mhdr->destaddr);
+ printf ("Entry Point: %08x\n", mhdr->execaddr);
+}
+
+static int kwbimage_check_image_types (uint8_t type)
+{
+ if (type == IH_TYPE_KWBIMAGE)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+/*
+ * kwbimage type parameters definition
+ */
+static struct image_type_params kwbimage_params = {
+ .name = "Kirkwood Boot Image support",
+ .header_size = sizeof(struct kwb_header),
+ .hdr = (void*)&kwbimage_header,
+ .check_image_type = kwbimage_check_image_types,
+ .verify_header = kwbimage_verify_header,
+ .print_header = kwbimage_print_header,
+ .set_header = kwbimage_set_header,
+ .check_params = kwbimage_check_params,
+};
+
+void init_kwb_image_type (void)
+{
+ register_image_type(&kwbimage_params);
+}
diff --git a/roms/u-boot/tools/kwbimage.h b/roms/u-boot/tools/kwbimage.h
new file mode 100644
index 00000000..8e4a4e28
--- /dev/null
+++ b/roms/u-boot/tools/kwbimage.h
@@ -0,0 +1,90 @@
+/*
+ * (C) Copyright 2008
+ * Marvell Semiconductor
+ * Written-by: Prafulla Wadaskar
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _KWBIMAGE_H_
+#define _KWBIMAGE_H_
+
+#include
+
+#define KWBIMAGE_MAX_CONFIG ((0x1dc - 0x20)/sizeof(struct reg_config))
+#define MAX_TEMPBUF_LEN 32
+
+/* NAND ECC Mode */
+#define IBR_HDR_ECC_DEFAULT 0x00
+#define IBR_HDR_ECC_FORCED_HAMMING 0x01
+#define IBR_HDR_ECC_FORCED_RS 0x02
+#define IBR_HDR_ECC_DISABLED 0x03
+
+/* Boot Type - block ID */
+#define IBR_HDR_I2C_ID 0x4D
+#define IBR_HDR_SPI_ID 0x5A
+#define IBR_HDR_NAND_ID 0x8B
+#define IBR_HDR_SATA_ID 0x78
+#define IBR_HDR_PEX_ID 0x9C
+#define IBR_HDR_UART_ID 0x69
+#define IBR_DEF_ATTRIB 0x00
+
+enum kwbimage_cmd {
+ CMD_INVALID,
+ CMD_BOOT_FROM,
+ CMD_NAND_ECC_MODE,
+ CMD_NAND_PAGE_SIZE,
+ CMD_SATA_PIO_MODE,
+ CMD_DDR_INIT_DELAY,
+ CMD_DATA
+};
+
+enum kwbimage_cmd_types {
+ CFG_INVALID = -1,
+ CFG_COMMAND,
+ CFG_DATA0,
+ CFG_DATA1
+};
+
+/* typedefs */
+typedef struct bhr_t {
+ uint8_t blockid; /*0 */
+ uint8_t nandeccmode; /*1 */
+ uint16_t nandpagesize; /*2-3 */
+ uint32_t blocksize; /*4-7 */
+ uint32_t rsvd1; /*8-11 */
+ uint32_t srcaddr; /*12-15 */
+ uint32_t destaddr; /*16-19 */
+ uint32_t execaddr; /*20-23 */
+ uint8_t satapiomode; /*24 */
+ uint8_t rsvd3; /*25 */
+ uint16_t ddrinitdelay; /*26-27 */
+ uint16_t rsvd2; /*28-29 */
+ uint8_t ext; /*30 */
+ uint8_t checkSum; /*31 */
+} bhr_t, *pbhr_t;
+
+struct reg_config {
+ uint32_t raddr;
+ uint32_t rdata;
+};
+
+typedef struct extbhr_t {
+ uint32_t dramregsoffs;
+ uint8_t rsrvd1[0x20 - sizeof(uint32_t)];
+ struct reg_config rcfg[KWBIMAGE_MAX_CONFIG];
+ uint8_t rsrvd2[7];
+ uint8_t checkSum;
+} extbhr_t, *pextbhr_t;
+
+struct kwb_header {
+ bhr_t kwb_hdr;
+ extbhr_t kwb_exthdr;
+};
+
+/*
+ * functions
+ */
+void init_kwb_image_type (void);
+
+#endif /* _KWBIMAGE_H_ */
diff --git a/roms/u-boot/tools/kwboot.c b/roms/u-boot/tools/kwboot.c
new file mode 100644
index 00000000..e773f01d
--- /dev/null
+++ b/roms/u-boot/tools/kwboot.c
@@ -0,0 +1,742 @@
+/*
+ * Boot a Marvell Kirkwood SoC, with Xmodem over UART0.
+ *
+ * (c) 2012 Daniel Stodden
+ *
+ * References: marvell.com, "88F6180, 88F6190, 88F6192, and 88F6281
+ * Integrated Controller: Functional Specifications" December 2,
+ * 2008. Chapter 24.2 "BootROM Firmware".
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "kwbimage.h"
+
+#ifdef __GNUC__
+#define PACKED __attribute((packed))
+#else
+#define PACKED
+#endif
+
+/*
+ * Marvell BootROM UART Sensing
+ */
+
+static unsigned char kwboot_msg_boot[] = {
+ 0xBB, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
+};
+
+#define KWBOOT_MSG_REQ_DELAY 10 /* ms */
+#define KWBOOT_MSG_RSP_TIMEO 50 /* ms */
+
+/*
+ * Xmodem Transfers
+ */
+
+#define SOH 1 /* sender start of block header */
+#define EOT 4 /* sender end of block transfer */
+#define ACK 6 /* target block ack */
+#define NAK 21 /* target block negative ack */
+#define CAN 24 /* target/sender transfer cancellation */
+
+struct kwboot_block {
+ uint8_t soh;
+ uint8_t pnum;
+ uint8_t _pnum;
+ uint8_t data[128];
+ uint8_t csum;
+} PACKED;
+
+#define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */
+
+static int kwboot_verbose;
+
+static void
+kwboot_printv(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (kwboot_verbose) {
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ fflush(stdout);
+ }
+}
+
+static void
+__spinner(void)
+{
+ const char seq[] = { '-', '\\', '|', '/' };
+ const int div = 8;
+ static int state, bs;
+
+ if (state % div == 0) {
+ fputc(bs, stdout);
+ fputc(seq[state / div % sizeof(seq)], stdout);
+ fflush(stdout);
+ }
+
+ bs = '\b';
+ state++;
+}
+
+static void
+kwboot_spinner(void)
+{
+ if (kwboot_verbose)
+ __spinner();
+}
+
+static void
+__progress(int pct, char c)
+{
+ const int width = 70;
+ static const char *nl = "";
+ static int pos;
+
+ if (pos % width == 0)
+ printf("%s%3d %% [", nl, pct);
+
+ fputc(c, stdout);
+
+ nl = "]\n";
+ pos++;
+
+ if (pct == 100) {
+ while (pos++ < width)
+ fputc(' ', stdout);
+ fputs(nl, stdout);
+ }
+
+ fflush(stdout);
+
+}
+
+static void
+kwboot_progress(int _pct, char c)
+{
+ static int pct;
+
+ if (_pct != -1)
+ pct = _pct;
+
+ if (kwboot_verbose)
+ __progress(pct, c);
+}
+
+static int
+kwboot_tty_recv(int fd, void *buf, size_t len, int timeo)
+{
+ int rc, nfds;
+ fd_set rfds;
+ struct timeval tv;
+ ssize_t n;
+
+ rc = -1;
+
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+
+ tv.tv_sec = 0;
+ tv.tv_usec = timeo * 1000;
+ if (tv.tv_usec > 1000000) {
+ tv.tv_sec += tv.tv_usec / 1000000;
+ tv.tv_usec %= 1000000;
+ }
+
+ do {
+ nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
+ if (nfds < 0)
+ goto out;
+ if (!nfds) {
+ errno = ETIMEDOUT;
+ goto out;
+ }
+
+ n = read(fd, buf, len);
+ if (n < 0)
+ goto out;
+
+ buf = (char *)buf + n;
+ len -= n;
+ } while (len > 0);
+
+ rc = 0;
+out:
+ return rc;
+}
+
+static int
+kwboot_tty_send(int fd, const void *buf, size_t len)
+{
+ int rc;
+ ssize_t n;
+
+ rc = -1;
+
+ do {
+ n = write(fd, buf, len);
+ if (n < 0)
+ goto out;
+
+ buf = (char *)buf + n;
+ len -= n;
+ } while (len > 0);
+
+ rc = tcdrain(fd);
+out:
+ return rc;
+}
+
+static int
+kwboot_tty_send_char(int fd, unsigned char c)
+{
+ return kwboot_tty_send(fd, &c, 1);
+}
+
+static speed_t
+kwboot_tty_speed(int baudrate)
+{
+ switch (baudrate) {
+ case 115200:
+ return B115200;
+ case 57600:
+ return B57600;
+ case 38400:
+ return B38400;
+ case 19200:
+ return B19200;
+ case 9600:
+ return B9600;
+ }
+
+ return -1;
+}
+
+static int
+kwboot_open_tty(const char *path, speed_t speed)
+{
+ int rc, fd;
+ struct termios tio;
+
+ rc = -1;
+
+ fd = open(path, O_RDWR|O_NOCTTY|O_NDELAY);
+ if (fd < 0)
+ goto out;
+
+ memset(&tio, 0, sizeof(tio));
+
+ tio.c_iflag = 0;
+ tio.c_cflag = CREAD|CLOCAL|CS8;
+
+ tio.c_cc[VMIN] = 1;
+ tio.c_cc[VTIME] = 10;
+
+ cfsetospeed(&tio, speed);
+ cfsetispeed(&tio, speed);
+
+ rc = tcsetattr(fd, TCSANOW, &tio);
+ if (rc)
+ goto out;
+
+ rc = fd;
+out:
+ if (rc < 0) {
+ if (fd >= 0)
+ close(fd);
+ }
+
+ return rc;
+}
+
+static int
+kwboot_bootmsg(int tty, void *msg)
+{
+ int rc;
+ char c;
+
+ kwboot_printv("Sending boot message. Please reboot the target...");
+
+ do {
+ rc = tcflush(tty, TCIOFLUSH);
+ if (rc)
+ break;
+
+ rc = kwboot_tty_send(tty, msg, 8);
+ if (rc) {
+ usleep(KWBOOT_MSG_REQ_DELAY * 1000);
+ continue;
+ }
+
+ rc = kwboot_tty_recv(tty, &c, 1, KWBOOT_MSG_RSP_TIMEO);
+
+ kwboot_spinner();
+
+ } while (rc || c != NAK);
+
+ kwboot_printv("\n");
+
+ return rc;
+}
+
+static int
+kwboot_xm_makeblock(struct kwboot_block *block, const void *data,
+ size_t size, int pnum)
+{
+ const size_t blksz = sizeof(block->data);
+ size_t n;
+ int i;
+
+ block->pnum = pnum;
+ block->_pnum = ~block->pnum;
+
+ n = size < blksz ? size : blksz;
+ memcpy(&block->data[0], data, n);
+ memset(&block->data[n], 0, blksz - n);
+
+ block->csum = 0;
+ for (i = 0; i < n; i++)
+ block->csum += block->data[i];
+
+ return n;
+}
+
+static int
+kwboot_xm_sendblock(int fd, struct kwboot_block *block)
+{
+ int rc, retries;
+ char c;
+
+ retries = 16;
+ do {
+ rc = kwboot_tty_send(fd, block, sizeof(*block));
+ if (rc)
+ break;
+
+ rc = kwboot_tty_recv(fd, &c, 1, KWBOOT_BLK_RSP_TIMEO);
+ if (rc)
+ break;
+
+ if (c != ACK)
+ kwboot_progress(-1, '+');
+
+ } while (c == NAK && retries-- > 0);
+
+ rc = -1;
+
+ switch (c) {
+ case ACK:
+ rc = 0;
+ break;
+ case NAK:
+ errno = EBADMSG;
+ break;
+ case CAN:
+ errno = ECANCELED;
+ break;
+ default:
+ errno = EPROTO;
+ break;
+ }
+
+ return rc;
+}
+
+static int
+kwboot_xmodem(int tty, const void *_data, size_t size)
+{
+ const uint8_t *data = _data;
+ int rc, pnum, N, err;
+
+ pnum = 1;
+ N = 0;
+
+ kwboot_printv("Sending boot image...\n");
+
+ do {
+ struct kwboot_block block;
+ int n;
+
+ n = kwboot_xm_makeblock(&block,
+ data + N, size - N,
+ pnum++);
+ if (n < 0)
+ goto can;
+
+ if (!n)
+ break;
+
+ rc = kwboot_xm_sendblock(tty, &block);
+ if (rc)
+ goto out;
+
+ N += n;
+ kwboot_progress(N * 100 / size, '.');
+ } while (1);
+
+ rc = kwboot_tty_send_char(tty, EOT);
+
+out:
+ return rc;
+
+can:
+ err = errno;
+ kwboot_tty_send_char(tty, CAN);
+ errno = err;
+ goto out;
+}
+
+static int
+kwboot_term_pipe(int in, int out, char *quit, int *s)
+{
+ ssize_t nin, nout;
+ char _buf[128], *buf = _buf;
+
+ nin = read(in, buf, sizeof(buf));
+ if (nin < 0)
+ return -1;
+
+ if (quit) {
+ int i;
+
+ for (i = 0; i < nin; i++) {
+ if (*buf == quit[*s]) {
+ (*s)++;
+ if (!quit[*s])
+ return 0;
+ buf++;
+ nin--;
+ } else
+ while (*s > 0) {
+ nout = write(out, quit, *s);
+ if (nout <= 0)
+ return -1;
+ (*s) -= nout;
+ }
+ }
+ }
+
+ while (nin > 0) {
+ nout = write(out, buf, nin);
+ if (nout <= 0)
+ return -1;
+ nin -= nout;
+ }
+
+ return 0;
+}
+
+static int
+kwboot_terminal(int tty)
+{
+ int rc, in, s;
+ char *quit = "\34c";
+ struct termios otio, tio;
+
+ rc = -1;
+
+ in = STDIN_FILENO;
+ if (isatty(in)) {
+ rc = tcgetattr(in, &otio);
+ if (!rc) {
+ tio = otio;
+ cfmakeraw(&tio);
+ rc = tcsetattr(in, TCSANOW, &tio);
+ }
+ if (rc) {
+ perror("tcsetattr");
+ goto out;
+ }
+
+ kwboot_printv("[Type Ctrl-%c + %c to quit]\r\n",
+ quit[0]|0100, quit[1]);
+ } else
+ in = -1;
+
+ rc = 0;
+ s = 0;
+
+ do {
+ fd_set rfds;
+ int nfds = 0;
+
+ FD_SET(tty, &rfds);
+ nfds = nfds < tty ? tty : nfds;
+
+ if (in >= 0) {
+ FD_SET(in, &rfds);
+ nfds = nfds < in ? in : nfds;
+ }
+
+ nfds = select(nfds + 1, &rfds, NULL, NULL, NULL);
+ if (nfds < 0)
+ break;
+
+ if (FD_ISSET(tty, &rfds)) {
+ rc = kwboot_term_pipe(tty, STDOUT_FILENO, NULL, NULL);
+ if (rc)
+ break;
+ }
+
+ if (FD_ISSET(in, &rfds)) {
+ rc = kwboot_term_pipe(in, tty, quit, &s);
+ if (rc)
+ break;
+ }
+ } while (quit[s] != 0);
+
+ tcsetattr(in, TCSANOW, &otio);
+out:
+ return rc;
+}
+
+static void *
+kwboot_mmap_image(const char *path, size_t *size, int prot)
+{
+ int rc, fd, flags;
+ struct stat st;
+ void *img;
+
+ rc = -1;
+ fd = -1;
+ img = NULL;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ goto out;
+
+ rc = fstat(fd, &st);
+ if (rc)
+ goto out;
+
+ flags = (prot & PROT_WRITE) ? MAP_PRIVATE : MAP_SHARED;
+
+ img = mmap(NULL, st.st_size, prot, flags, fd, 0);
+ if (img == MAP_FAILED) {
+ img = NULL;
+ goto out;
+ }
+
+ rc = 0;
+ *size = st.st_size;
+out:
+ if (rc && img) {
+ munmap(img, st.st_size);
+ img = NULL;
+ }
+ if (fd >= 0)
+ close(fd);
+
+ return img;
+}
+
+static uint8_t
+kwboot_img_csum8(void *_data, size_t size)
+{
+ uint8_t *data = _data, csum;
+
+ for (csum = 0; size-- > 0; data++)
+ csum += *data;
+
+ return csum;
+}
+
+static int
+kwboot_img_patch_hdr(void *img, size_t size)
+{
+ int rc;
+ bhr_t *hdr;
+ uint8_t csum;
+ const size_t hdrsz = sizeof(*hdr);
+
+ rc = -1;
+ hdr = img;
+
+ if (size < hdrsz) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checkSum;
+ if (csum != hdr->checkSum) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ if (hdr->blockid == IBR_HDR_UART_ID) {
+ rc = 0;
+ goto out;
+ }
+
+ hdr->blockid = IBR_HDR_UART_ID;
+
+ hdr->nandeccmode = IBR_HDR_ECC_DISABLED;
+ hdr->nandpagesize = 0;
+
+ hdr->srcaddr = hdr->ext
+ ? sizeof(struct kwb_header)
+ : sizeof(*hdr);
+
+ hdr->checkSum = kwboot_img_csum8(hdr, hdrsz) - csum;
+
+ rc = 0;
+out:
+ return rc;
+}
+
+static void
+kwboot_usage(FILE *stream, char *progname)
+{
+ fprintf(stream,
+ "Usage: %s -b [ -p ] [ -t ] "
+ "[-B ] \n", progname);
+ fprintf(stream, "\n");
+ fprintf(stream, " -b : boot \n");
+ fprintf(stream, " -p: patch to type 0x69 (uart boot)\n");
+ fprintf(stream, "\n");
+ fprintf(stream, " -t: mini terminal\n");
+ fprintf(stream, "\n");
+ fprintf(stream, " -B : set baud rate\n");
+ fprintf(stream, "\n");
+}
+
+int
+main(int argc, char **argv)
+{
+ const char *ttypath, *imgpath;
+ int rv, rc, tty, term, prot, patch;
+ void *bootmsg;
+ void *img;
+ size_t size;
+ speed_t speed;
+
+ rv = 1;
+ tty = -1;
+ bootmsg = NULL;
+ imgpath = NULL;
+ img = NULL;
+ term = 0;
+ patch = 0;
+ size = 0;
+ speed = B115200;
+
+ kwboot_verbose = isatty(STDOUT_FILENO);
+
+ do {
+ int c = getopt(argc, argv, "hb:ptB:");
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case 'b':
+ bootmsg = kwboot_msg_boot;
+ imgpath = optarg;
+ break;
+
+ case 'p':
+ patch = 1;
+ break;
+
+ case 't':
+ term = 1;
+ break;
+
+ case 'B':
+ speed = kwboot_tty_speed(atoi(optarg));
+ if (speed == -1)
+ goto usage;
+ break;
+
+ case 'h':
+ rv = 0;
+ default:
+ goto usage;
+ }
+ } while (1);
+
+ if (!bootmsg && !term)
+ goto usage;
+
+ if (patch && !imgpath)
+ goto usage;
+
+ if (argc - optind < 1)
+ goto usage;
+
+ ttypath = argv[optind++];
+
+ tty = kwboot_open_tty(ttypath, speed);
+ if (tty < 0) {
+ perror(ttypath);
+ goto out;
+ }
+
+ if (imgpath) {
+ prot = PROT_READ | (patch ? PROT_WRITE : 0);
+
+ img = kwboot_mmap_image(imgpath, &size, prot);
+ if (!img) {
+ perror(imgpath);
+ goto out;
+ }
+ }
+
+ if (patch) {
+ rc = kwboot_img_patch_hdr(img, size);
+ if (rc) {
+ fprintf(stderr, "%s: Invalid image.\n", imgpath);
+ goto out;
+ }
+ }
+
+ if (bootmsg) {
+ rc = kwboot_bootmsg(tty, bootmsg);
+ if (rc) {
+ perror("bootmsg");
+ goto out;
+ }
+ }
+
+ if (img) {
+ rc = kwboot_xmodem(tty, img, size);
+ if (rc) {
+ perror("xmodem");
+ goto out;
+ }
+ }
+
+ if (term) {
+ rc = kwboot_terminal(tty);
+ if (rc && !(errno == EINTR)) {
+ perror("terminal");
+ goto out;
+ }
+ }
+
+ rv = 0;
+out:
+ if (tty >= 0)
+ close(tty);
+
+ if (img)
+ munmap(img, size);
+
+ return rv;
+
+usage:
+ kwboot_usage(rv ? stderr : stdout, basename(argv[0]));
+ goto out;
+}
diff --git a/roms/u-boot/tools/logos/atmel.bmp b/roms/u-boot/tools/logos/atmel.bmp
new file mode 100644
index 00000000..5c659ce8
Binary files /dev/null and b/roms/u-boot/tools/logos/atmel.bmp differ
diff --git a/roms/u-boot/tools/logos/denx.bmp b/roms/u-boot/tools/logos/denx.bmp
new file mode 100644
index 00000000..c4cde09d
Binary files /dev/null and b/roms/u-boot/tools/logos/denx.bmp differ
diff --git a/roms/u-boot/tools/logos/esd.bmp b/roms/u-boot/tools/logos/esd.bmp
new file mode 100644
index 00000000..a6b40302
Binary files /dev/null and b/roms/u-boot/tools/logos/esd.bmp differ
diff --git a/roms/u-boot/tools/logos/freescale.bmp b/roms/u-boot/tools/logos/freescale.bmp
new file mode 100644
index 00000000..1589e807
Binary files /dev/null and b/roms/u-boot/tools/logos/freescale.bmp differ
diff --git a/roms/u-boot/tools/logos/intercontrol.bmp b/roms/u-boot/tools/logos/intercontrol.bmp
new file mode 100644
index 00000000..cf2a884b
Binary files /dev/null and b/roms/u-boot/tools/logos/intercontrol.bmp differ
diff --git a/roms/u-boot/tools/logos/linux_logo_ttcontrol.bmp b/roms/u-boot/tools/logos/linux_logo_ttcontrol.bmp
new file mode 100644
index 00000000..031d3a41
Binary files /dev/null and b/roms/u-boot/tools/logos/linux_logo_ttcontrol.bmp differ
diff --git a/roms/u-boot/tools/logos/linux_logo_ttcontrol_palfin.bmp b/roms/u-boot/tools/logos/linux_logo_ttcontrol_palfin.bmp
new file mode 100644
index 00000000..e3e38d1b
Binary files /dev/null and b/roms/u-boot/tools/logos/linux_logo_ttcontrol_palfin.bmp differ
diff --git a/roms/u-boot/tools/logos/ronetix.bmp b/roms/u-boot/tools/logos/ronetix.bmp
new file mode 100644
index 00000000..f9568139
Binary files /dev/null and b/roms/u-boot/tools/logos/ronetix.bmp differ
diff --git a/roms/u-boot/tools/logos/siemens.bmp b/roms/u-boot/tools/logos/siemens.bmp
new file mode 100644
index 00000000..bff2b190
Binary files /dev/null and b/roms/u-boot/tools/logos/siemens.bmp differ
diff --git a/roms/u-boot/tools/logos/syteco.bmp b/roms/u-boot/tools/logos/syteco.bmp
new file mode 100644
index 00000000..14031f2c
Binary files /dev/null and b/roms/u-boot/tools/logos/syteco.bmp differ
diff --git a/roms/u-boot/tools/logos/wandboard.bmp b/roms/u-boot/tools/logos/wandboard.bmp
new file mode 100644
index 00000000..7f288a8e
Binary files /dev/null and b/roms/u-boot/tools/logos/wandboard.bmp differ
diff --git a/roms/u-boot/tools/md5.c b/roms/u-boot/tools/md5.c
new file mode 100644
index 00000000..befaa321
--- /dev/null
+++ b/roms/u-boot/tools/md5.c
@@ -0,0 +1 @@
+#include "../lib/md5.c"
diff --git a/roms/u-boot/tools/mingw_support.c b/roms/u-boot/tools/mingw_support.c
new file mode 100644
index 00000000..95c4db89
--- /dev/null
+++ b/roms/u-boot/tools/mingw_support.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2008 Extreme Engineering Solutions, Inc.
+ *
+ * mmap/munmap implementation derived from:
+ * Clamav Native Windows Port : mmap win32 compatibility layer
+ * Copyright (c) 2005-2006 Gianluigi Tiesi
+ * Parts by Kees Zeelenberg (LibGW32C)
+ *
+ * SPDX-License-Identifier: LGPL-2.0+
+ */
+
+#include "mingw_support.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+int fsync(int fd)
+{
+ return _commit(fd);
+}
+
+void *mmap(void *addr, size_t len, int prot, int flags, int fd, int offset)
+{
+ void *map = NULL;
+ HANDLE handle = INVALID_HANDLE_VALUE;
+ DWORD cfm_flags = 0, mvf_flags = 0;
+
+ switch (prot) {
+ case PROT_READ | PROT_WRITE:
+ cfm_flags = PAGE_READWRITE;
+ mvf_flags = FILE_MAP_ALL_ACCESS;
+ break;
+ case PROT_WRITE:
+ cfm_flags = PAGE_READWRITE;
+ mvf_flags = FILE_MAP_WRITE;
+ break;
+ case PROT_READ:
+ cfm_flags = PAGE_READONLY;
+ mvf_flags = FILE_MAP_READ;
+ break;
+ default:
+ return MAP_FAILED;
+ }
+
+ handle = CreateFileMappingA((HANDLE) _get_osfhandle(fd), NULL,
+ cfm_flags, HIDWORD(len), LODWORD(len), NULL);
+ if (!handle)
+ return MAP_FAILED;
+
+ map = MapViewOfFile(handle, mvf_flags, HIDWORD(offset),
+ LODWORD(offset), len);
+ CloseHandle(handle);
+
+ if (!map)
+ return MAP_FAILED;
+
+ return map;
+}
+
+int munmap(void *addr, size_t len)
+{
+ if (!UnmapViewOfFile(addr))
+ return -1;
+
+ return 0;
+}
+
+/* Reentrant string tokenizer. Generic version.
+ Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/* Parse S into tokens separated by characters in DELIM.
+ If S is NULL, the saved pointer in SAVE_PTR is used as
+ the next starting point. For example:
+ char s[] = "-abc-=-def";
+ char *sp;
+ x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
+ x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
+ x = strtok_r(NULL, "=", &sp); // x = NULL
+ // s = "abc\0-def\0"
+*/
+char *strtok_r(char *s, const char *delim, char **save_ptr)
+{
+ char *token;
+
+ if (s == NULL)
+ s = *save_ptr;
+
+ /* Scan leading delimiters. */
+ s += strspn(s, delim);
+ if (*s == '\0') {
+ *save_ptr = s;
+ return NULL;
+ }
+
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk (token, delim);
+ if (s == NULL) {
+ /* This token finishes the string. */
+ *save_ptr = memchr(token, '\0', strlen(token));
+ } else {
+ /* Terminate the token and make *SAVE_PTR point past it. */
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+ return token;
+}
+
+#include "getline.c"
diff --git a/roms/u-boot/tools/mingw_support.h b/roms/u-boot/tools/mingw_support.h
new file mode 100644
index 00000000..f9535b37
--- /dev/null
+++ b/roms/u-boot/tools/mingw_support.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2008 Extreme Engineering Solutions, Inc.
+ *
+ * SPDX-License-Identifier: LGPL-2.0+
+ */
+
+#ifndef __MINGW_SUPPORT_H_
+#define __WINGW_SUPPORT_H_ 1
+
+/* Defining __INSIDE_MSYS__ helps to prevent u-boot/mingw overlap */
+#define __INSIDE_MSYS__ 1
+
+#include
+
+/* mmap protections */
+#define PROT_READ 0x1 /* Page can be read */
+#define PROT_WRITE 0x2 /* Page can be written */
+#define PROT_EXEC 0x4 /* Page can be executed */
+#define PROT_NONE 0x0 /* Page can not be accessed */
+
+/* Sharing types (must choose one and only one of these) */
+#define MAP_SHARED 0x01 /* Share changes */
+#define MAP_PRIVATE 0x02 /* Changes are private */
+
+/* File perms */
+#ifndef S_IRGRP
+# define S_IRGRP 0
+#endif
+#ifndef S_IWGRP
+# define S_IWGRP 0
+#endif
+
+/* Windows 64-bit access macros */
+#define LODWORD(x) ((DWORD)((DWORDLONG)(x)))
+#define HIDWORD(x) ((DWORD)(((DWORDLONG)(x) >> 32) & 0xffffffff))
+
+typedef UINT uint;
+typedef ULONG ulong;
+
+int fsync(int fd);
+void *mmap(void *, size_t, int, int, int, int);
+int munmap(void *, size_t);
+char *strtok_r(char *s, const char *delim, char **save_ptr);
+#include "getline.h"
+
+#endif /* __MINGW_SUPPORT_H_ */
diff --git a/roms/u-boot/tools/mkenvimage.c b/roms/u-boot/tools/mkenvimage.c
new file mode 100644
index 00000000..bbd3041e
--- /dev/null
+++ b/roms/u-boot/tools/mkenvimage.c
@@ -0,0 +1,295 @@
+/*
+ * (C) Copyright 2011 Free Electrons
+ * David Wagner
+ *
+ * Inspired from envcrc.c:
+ * (C) Copyright 2001
+ * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "compiler.h"
+#include
+#include
+
+#define CRC_SIZE sizeof(uint32_t)
+
+static void usage(const char *exec_name)
+{
+ fprintf(stderr, "%s [-h] [-r] [-b] [-p ] -s -o