From 9653921eadd5d5268afbee6c928708158fc4e844 Mon Sep 17 00:00:00 2001
From: Josua Mayer <josua.mayer97@gmail.com>
Date: Tue, 22 Nov 2016 16:33:23 +0100
Subject: [PATCH 3/4] clearfog: enable distro boot code

load addresses start at 0x02000000, leaving enough space for fdt,
boot scripts and ramdisk at the end.
Only boot from mmc, the other options are not in working order.
Removed *_high variables in good faith. They can be re-added with sane
values when, and if required.

Signed-off-by: Josua Mayer <josua.mayer97@gmail.com>
---
 Kconfig                    |  1 +
 include/configs/clearfog.h | 47 +++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/Kconfig b/Kconfig
index 81b4226463..f7aec2255b 100644
--- a/Kconfig
+++ b/Kconfig
@@ -59,6 +59,7 @@ config DISTRO_DEFAULTS
 	default y if ARCH_LS2080A
 	default y if ARCH_MESON
 	default y if ARCH_ROCKCHIP
+	default y if TARGET_CLEARFOG
 	default n
 	select CMD_BOOTZ if ARM && !ARM64
 	select CMD_BOOTI if ARM64
diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h
index 0c51d2a288..890dd84b5d 100644
--- a/include/configs/clearfog.h
+++ b/include/configs/clearfog.h
@@ -79,11 +79,6 @@
 
 #define CONFIG_SYS_ALT_MEMTEST
 
-/* Keep device tree and initrd in lower memory so the kernel can access them */
-#define CONFIG_EXTRA_ENV_SETTINGS	\
-	"fdt_high=0x10000000\0"		\
-	"initrd_high=0x10000000\0"
-
 /* SPL */
 /*
  * Select the boot device here
@@ -128,6 +123,48 @@
 #endif
 #endif
 
+#ifndef CONFIG_SPL_BUILD
+/*
+ * Add standard bootenv from distro boot code:
+ * Keep device tree and initrd in lower memory so the kernel can access them
+ * Set default load addresses:
+ *  - 63MiB space for kernel
+ *  - 1MiB space for fdt
+ *  - 1MiB space for extlinux file, or boot script
+ *  - remainder for ramdisk
+ * Keep device tree and initrd in lower memory so the kernel can access them
+ * Set name of fdt file (default to Clearfog Pro)
+ * specify console device
+ */
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"kernel_addr_r=0x02000000\0" \
+	"fdt_addr_r=0x05f00000\0" \
+	"pxefile_addr_r=0x06000000\0" \
+	"scriptaddr=0x06000000\0" \
+	"ramdisk_addr_r=0x06100000\0" \
+	"fdt_high=0x10000000\0" \
+	"initrd_high=0x10000000\0" \
+	"fdtfile=armada-388-clearfog-pro.dtb\0" \
+	"console=ttyS0," __stringify(CONFIG_BAUDRATE) "\0" \
+	BOOTENV
+
+/* include distro boot code defaults */
+#include <config_distro_defaults.h>
+
+/*
+ * specify boot order
+ * sdcard or emmc -> usb -> network
+ */
+#define BOOT_TARGET_DEVICES(func) \
+	func(MMC, mmc, 0) \
+	func(USB, usb, 0) \
+	func(PXE, pxe, na) \
+	func(DHCP, dhcp, na)
+
+/* include the actual distro boot code */
+#include <config_distro_bootcmd.h>
+#endif
+
 /*
  * mv-common.h should be defined after CMD configs since it used them
  * to enable certain macros
-- 
2.12.2

