From 5372743bab931e0f31e37c3767077abd504eca2b Mon Sep 17 00:00:00 2001
From: Damodar Santhapuri <damodar.santhapuri@arm.com>
Date: Thu, 5 Nov 2020 22:40:48 +0530
Subject: [PATCH] arm: juno: add custom bootcmd to autoboot from uEnv.txt file

enable autoboot support with custom bootcmd loads uEnv.txt
from NOR to DRAM and import.

Signed-off-by: Damodar Santhapuri <damodar.santhapuri@arm.com>
Upstream-Status: Pending
---
 include/configs/vexpress_aemv8a.h | 40 ++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/include/configs/vexpress_aemv8a.h b/include/configs/vexpress_aemv8a.h
index 09cdd3dab5..9c9f8dfd16 100644
--- a/include/configs/vexpress_aemv8a.h
+++ b/include/configs/vexpress_aemv8a.h
@@ -131,11 +131,39 @@
 				"kernel_name=norkern\0"	\
 				"kernel_alt_name=Image\0"	\
 				"kernel_addr_r=0x80080000\0" \
-				"ramdisk_name=ramdisk.img\0"	\
-				"ramdisk_addr_r=0x88000000\0"	\
+				"initrd_name=ramdisk.img\0"	\
+				"initrd_addr_r=0x88000000\0"	\
 				"fdtfile=board.dtb\0" \
 				"fdt_alt_name=juno\0" \
 				"fdt_addr_r=0x80000000\0" \
+				"fdt_high=0xffffffffffffffff\0" \
+				"initrd_high=0xffffffffffffffff\0" \
+                                "bootenvfile=uEnv.txt\0" \
+                                "bootcmd=run envboot\0" \
+                                "envboot=if run loadbootenv; then echo Loading env from ${bootenvfile}; run importbootenv; else run default_bootcmd; fi; if test -n $uenvcmd; then echo Running uenvcmd ...; run uenvcmd;fi;\0" \
+                                "importbootenv=echo Importing environment from memory, size ${filesize}; env import -t ${loadaddr} ${filesize}\0" \
+                                "loadaddr=0x84000000\0" \
+                                "filesize=0x4000\0" \
+                                "loadbootenv=mw.l ${loadaddr} 0 0x1000; afs load ${bootenvfile} ${loadaddr}\0" \
+                                "default_bootcmd=echo running default boot command; afs load ${kernel_name} ${kernel_addr_r} ; " \
+                                                "if test $? -eq 1; then "\
+                                                "  echo Loading ${kernel_alt_name} instead of "\
+                                                "${kernel_name}; "\
+                                                "  afs load ${kernel_alt_name} ${kernel_addr_r};"\
+                                                "fi ; "\
+		                                "afs load  ${fdtfile} ${fdt_addr_r} ; " \
+                                                "if test $? -eq 1; then "\
+                                                "  echo Loading ${fdt_alt_name} instead of "\
+                                                "${fdtfile}; "\
+		                                "  afs load ${fdt_alt_name} ${fdt_addr_r}; "\
+		                                "fi ; "\
+                                                "fdt addr ${fdt_addr_r}; fdt resize; " \
+		                                "if afs load  ${initrd_name} ${initrd_addr_r} ; "\
+		                                "then "\
+		                                "  setenv initrd_param ${initrd_addr_r}; "\
+		                                "  else setenv initrd_param -; "\
+		                                "fi ; " \
+		                                "booti ${kernel_addr_r} ${initrd_param} ${fdt_addr_r}\0"
 
 /* Copy the kernel and FDT to DRAM memory and boot */
 #define CONFIG_BOOTCOMMAND	"afs load ${kernel_name} ${kernel_addr_r} ;"\
@@ -151,12 +179,12 @@
 				"  afs load ${fdt_alt_name} ${fdt_addr_r}; "\
 				"fi ; "\
 				"fdt addr ${fdt_addr_r}; fdt resize; " \
-				"if afs load  ${ramdisk_name} ${ramdisk_addr_r} ; "\
+				"if afs load  ${initrd_name} ${initrd_addr_r} ; "\
 				"then "\
-				"  setenv ramdisk_param ${ramdisk_addr_r}; "\
-				"  else setenv ramdisk_param -; "\
+				"  setenv initrd_param ${initrd_addr_r}; "\
+				"  else setenv initrd_param -; "\
 				"fi ; " \
-				"booti ${kernel_addr_r} ${ramdisk_param} ${fdt_addr_r}"
+				"booti ${kernel_addr_r} ${initrd_param} ${fdt_addr_r}"
 
 
 #elif CONFIG_TARGET_VEXPRESS64_BASE_FVP
-- 
2.17.1

