ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/tools/mkimage/Makefile b/tools/mkimage/Makefile
new file mode 100644
index 0000000..0a1712b
--- /dev/null
+++ b/tools/mkimage/Makefile
@@ -0,0 +1,53 @@
+#
+# Copyright (C) 2006-2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=mkimage
+PKG_VERSION:=2024.07
+
+PKG_SOURCE:=u-boot-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_URL:= \
+ https://mirror.cyberbits.eu/u-boot \
+ https://ftp.denx.de/pub/u-boot \
+ ftp://ftp.denx.de/pub/u-boot
+PKG_HASH:=f591da9ab90ef3d6b3d173766d0ddff90c4ed7330680897486117df390d83c8f
+
+HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/u-boot-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/host-build.mk
+
+define Host/Configure
+ $(MAKE) -C $(HOST_BUILD_DIR) \
+ HOSTCFLAGS="$(HOST_CFLAGS)" \
+ HOSTLDFLAGS="$(HOST_LDFLAGS)" \
+ PKG_CONFIG_EXTRAARGS="--static" \
+ V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1) \
+ tools-only_config
+
+ sed -i 's/CONFIG_TOOLS_MKEFICAPSULE=y/# CONFIG_TOOLS_MKEFICAPSULE is not set/' $(HOST_BUILD_DIR)/.config
+endef
+
+define Host/Compile
+ $(MAKE) -C $(HOST_BUILD_DIR) \
+ HOSTCFLAGS="$(HOST_CFLAGS)" \
+ HOSTLDFLAGS="$(HOST_LDFLAGS)" \
+ PKG_CONFIG_EXTRAARGS="--static" \
+ V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1) \
+ tools-only
+endef
+
+define Host/Install
+ $(CP) $(HOST_BUILD_DIR)/tools/mkimage $(STAGING_DIR_HOST)/bin/
+ $(CP) $(HOST_BUILD_DIR)/tools/mkenvimage $(STAGING_DIR_HOST)/bin/
+endef
+
+define Host/Clean
+ rm -f $(STAGING_DIR_HOST)/bin/mkimage
+ rm -f $(STAGING_DIR_HOST)/bin/mkenvimage
+endef
+
+$(eval $(call HostBuild))
diff --git a/tools/mkimage/patches/030-allow-to-use-different-magic.patch b/tools/mkimage/patches/030-allow-to-use-different-magic.patch
new file mode 100644
index 0000000..bcbdc4d
--- /dev/null
+++ b/tools/mkimage/patches/030-allow-to-use-different-magic.patch
@@ -0,0 +1,80 @@
+This patch makes it possible to set a custom image magic.
+
+--- a/tools/mkimage.c
++++ b/tools/mkimage.c
+@@ -26,6 +26,7 @@ static struct image_tool_params params =
+ .arch = IH_ARCH_PPC,
+ .type = IH_TYPE_KERNEL,
+ .comp = IH_COMP_GZIP,
++ .magic = IH_MAGIC,
+ .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
+ .imagename = "",
+ .imagename2 = "",
+@@ -89,11 +90,12 @@ static void usage(const char *msg)
+ " -q ==> quiet\n",
+ params.cmdname);
+ fprintf(stderr,
+- " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
++ " %s [-x] -A arch -O os -T type -C comp -M magic -a addr -e ep -n name -d data_file[:data_file...] image\n"
+ " -A ==> set architecture to 'arch'\n"
+ " -O ==> set operating system to 'os'\n"
+ " -T ==> set image type to 'type'\n"
+ " -C ==> set compression type 'comp'\n"
++ " -M ==> set image magic to 'magic'\n"
+ " -a ==> set load address to 'addr' (hex)\n"
+ " -e ==> set entry point to 'ep' (hex)\n"
+ " -n ==> set image name to 'name'\n"
+@@ -160,7 +162,7 @@ static int add_content(int type, const c
+ }
+
+ static const char optstring[] =
+- "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVx";
++ "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:lM:n:N:o:O:p:qrR:stT:vVx";
+
+ static const struct option longopts[] = {
+ { "load-address", required_argument, NULL, 'a' },
+@@ -303,6 +305,14 @@ static void process_args(int argc, char
+ case 'l':
+ params.lflag = 1;
+ break;
++ case 'M':
++ params.magic = strtoull(optarg, &ptr, 16);
++ if (*ptr) {
++ fprintf(stderr, "%s: invalid magic %s\n",
++ params.cmdname, optarg);
++ exit(EXIT_FAILURE);
++ }
++ break;
+ case 'n':
+ params.imagename = optarg;
+ break;
+--- a/tools/default_image.c
++++ b/tools/default_image.c
+@@ -67,7 +67,7 @@ static int image_verify_header(unsigned
+ */
+ memcpy(hdr, ptr, sizeof(struct legacy_img_hdr));
+
+- if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
++ if (be32_to_cpu(hdr->ih_magic) != params->magic) {
+ debug("%s: Bad Magic Number: \"%s\" is no valid image\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADMAGIC;
+@@ -146,7 +146,7 @@ static void image_set_header(void *ptr,
+ }
+
+ /* Build new header */
+- image_set_magic(hdr, IH_MAGIC);
++ image_set_magic(hdr, params->magic);
+ image_set_time(hdr, time);
+ image_set_size(hdr, imagesize);
+ image_set_load(hdr, addr);
+--- a/tools/imagetool.h
++++ b/tools/imagetool.h
+@@ -67,6 +67,7 @@ struct image_tool_params {
+ int arch;
+ int type;
+ int comp;
++ unsigned int magic;
+ char *dtc;
+ unsigned int addr;
+ unsigned int ep;
diff --git a/tools/mkimage/patches/050-Add-compatibility-with-non-Linux-hosts.patch b/tools/mkimage/patches/050-Add-compatibility-with-non-Linux-hosts.patch
new file mode 100644
index 0000000..7b71dce
--- /dev/null
+++ b/tools/mkimage/patches/050-Add-compatibility-with-non-Linux-hosts.patch
@@ -0,0 +1,65 @@
+From 590b23a46b7ae0f5ec5e8f57a85c0e7578c71141 Mon Sep 17 00:00:00 2001
+From: Hauke Mehrtens <hauke@hauke-m.de>
+Date: Sun, 26 Apr 2020 17:15:17 +0200
+Subject: [PATCH 1/2] Add compatibility with non Linux hosts
+
+This adds some changes to the u-boot tools to make it possible to build
+them on non Linux hosts like MacOS or FreeBSD.
+
+asm/byteorder.h, asm/posix_types.h, asm/types.h and linux/kernel.h are
+not available on such systems. Remove the include and add the necessary
+parts for these header files manually or remove the usage too.
+
+__u64 is not available on FreeBSD, remove its usage.
+
+Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
+---
+ include/image.h | 2 ++
+ include/linux/posix_types.h | 2 ++
+ include/linux/types.h | 4 +++-
+ 3 files changed, 7 insertions(+), 1 deletion(-)
+
+--- a/include/image.h
++++ b/include/image.h
+@@ -16,7 +16,9 @@
+ #define __IMAGE_H__
+
+ #include "compiler.h"
++#ifdef linux
+ #include <asm/byteorder.h>
++#endif
+ #include <stdbool.h>
+
+ /* Define this to avoid #ifdefs later on */
+--- a/include/linux/posix_types.h
++++ b/include/linux/posix_types.h
+@@ -43,6 +43,8 @@ typedef void (*__kernel_sighandler_t)(in
+ /* Type of a SYSV IPC key. */
+ typedef int __kernel_key_t;
+
++#ifdef linux
+ #include <asm/posix_types.h>
++#endif
+
+ #endif /* _LINUX_POSIX_TYPES_H */
+--- a/include/linux/types.h
++++ b/include/linux/types.h
+@@ -2,7 +2,9 @@
+ #define _LINUX_TYPES_H
+
+ #include <linux/posix_types.h>
++#ifdef linux
+ #include <asm/types.h>
++#endif
+ #include <stdbool.h>
+
+ #ifndef __KERNEL_STRICT_NAMES
+@@ -142,7 +144,7 @@ typedef __u16 __bitwise __le16;
+ typedef __u16 __bitwise __be16;
+ typedef __u32 __bitwise __le32;
+ typedef __u32 __bitwise __be32;
+-#if defined(__GNUC__)
++#if defined(__GNUC__) && defined(linux)
+ typedef __u64 __bitwise __le64;
+ typedef __u64 __bitwise __be64;
+ #endif
diff --git a/tools/mkimage/patches/095-tools-disable-TOOLS_FIT_FULL_CHECK.patch b/tools/mkimage/patches/095-tools-disable-TOOLS_FIT_FULL_CHECK.patch
new file mode 100644
index 0000000..ed6824b
--- /dev/null
+++ b/tools/mkimage/patches/095-tools-disable-TOOLS_FIT_FULL_CHECK.patch
@@ -0,0 +1,25 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Huangbin Zhan <zhanhb88@gmail.com>
+Date: Fri, 18 Feb 2022 14:19:23 +0800
+Subject: [PATCH] tools: disable TOOLS_FIT_FULL_CHECK
+
+ U-Boot disallows unit addresses by default. Disable TOOLS_FIT_FULL_CHECK
+ to allow at symbol in node names.
+
+https://github.com/openwrt/openwrt/commits/master/scripts/mkits.sh
+https://github.com/u-boot/u-boot/commit/3f04db891a353f4b127ed57279279f851c6b4917
+---
+ tools/Kconfig | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/Kconfig
++++ b/tools/Kconfig
+@@ -36,7 +36,7 @@ config TOOLS_FIT
+ Enable FIT support in the tools builds.
+
+ config TOOLS_FIT_FULL_CHECK
+- def_bool y
++ bool "Do a full check of the FIT"
+ help
+ Do a full check of the FIT before using it in the tools builds
+