From 84169e2e691183594d0ba3b2acd85024c65b7370 Mon Sep 17 00:00:00 2001
From: Anup Patel <anup.patel@wdc.com>
Date: Fri, 8 Feb 2019 10:13:07 +0530
Subject: platform: qemu: Set FW_JUMP_ADDR and FW_PAYLOAD_OFFSET as-per XLEN

The current 4MB aligned FW_JUMP_ADDR and FW_PAYLOAD_OFFSET breaks
U-Boot on QEMU virt and sifive_u machines.

Instead of using 4MB aligned for both 32bit and 64bit systems, we
use different values based compiler XLEN. Another advantage of this
approach will be that our fw_payload.bin will smaller for 64bit
systems.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
---
 platform/qemu/sifive_u/config.mk | 16 ++++++++++++++--
 platform/qemu/virt/config.mk     | 18 ++++++++++++++----
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/platform/qemu/sifive_u/config.mk b/platform/qemu/sifive_u/config.mk
index 6e2c193..fe51024 100644
--- a/platform/qemu/sifive_u/config.mk
+++ b/platform/qemu/sifive_u/config.mk
@@ -21,10 +21,22 @@ PLATFORM_SYS_CLINT=y
 # Blobs to build
 FW_TEXT_START=0x80000000
 FW_JUMP=y
-FW_JUMP_ADDR=0x80200000
+ifeq ($(OPENSBI_CC_XLEN), 32)
+  # This needs to be 4MB alligned for 32-bit system
+  FW_JUMP_ADDR=0x80400000
+else
+  # This needs to be 2MB alligned for 64-bit system
+  FW_JUMP_ADDR=0x80200000
+endif
 FW_JUMP_FDT_ADDR=0x82200000
 FW_PAYLOAD=y
-FW_PAYLOAD_OFFSET=0x200000
+ifeq ($(OPENSBI_CC_XLEN), 32)
+  # This needs to be 4MB alligned for 32-bit system
+  FW_PAYLOAD_OFFSET=0x400000
+else
+  # This needs to be 2MB alligned for 64-bit system
+  FW_PAYLOAD_OFFSET=0x200000
+endif
 FW_PAYLOAD_FDT_ADDR=0x82200000
 
 # External Libraries to include
diff --git a/platform/qemu/virt/config.mk b/platform/qemu/virt/config.mk
index fcd25c8..cd87745 100644
--- a/platform/qemu/virt/config.mk
+++ b/platform/qemu/virt/config.mk
@@ -30,12 +30,22 @@ PLATFORM_SYS_CLINT=y
 # Blobs to build
 FW_TEXT_START=0x80000000
 FW_JUMP=y
-# This needs to be 4MB alligned for 32-bit support
-FW_JUMP_ADDR=0x80400000
+ifeq ($(OPENSBI_CC_XLEN), 32)
+  # This needs to be 4MB alligned for 32-bit system
+  FW_JUMP_ADDR=0x80400000
+else
+  # This needs to be 2MB alligned for 64-bit system
+  FW_JUMP_ADDR=0x80200000
+endif
 FW_JUMP_FDT_ADDR=0x82200000
 FW_PAYLOAD=y
-# This needs to be 4MB alligned for 32-bit support
-FW_PAYLOAD_OFFSET=0x400000
+ifeq ($(OPENSBI_CC_XLEN), 32)
+  # This needs to be 4MB alligned for 32-bit system
+  FW_PAYLOAD_OFFSET=0x400000
+else
+  # This needs to be 2MB alligned for 64-bit system
+  FW_PAYLOAD_OFFSET=0x200000
+endif
 FW_PAYLOAD_FDT_ADDR=0x82200000
 
 # External Libraries to include
-- 
cgit v1.2.3