run_qemu.sh: Add KERNEL_ADDR & page size utils
Introduce the KERNEL_ADDR and MAX_SUPPORTED_PAGE_SIZE variables and the
align_page_size convenience function.
Change-Id: Ib71e1aed54f5d3388f5253aadaca4675b9f06c08
diff --git a/aarch64/run_qemu.sh b/aarch64/run_qemu.sh
index 88b0e6a..5145075 100755
--- a/aarch64/run_qemu.sh
+++ b/aarch64/run_qemu.sh
@@ -40,6 +40,12 @@
MiB=$((1024 * KiB))
GiB=$((1024 * MiB))
+# We assume the largest potential kernel's PAGE_SIZE (for alignment purpose):
+MAX_SUPPORTED_PAGE_SIZE=$(( 64*KiB ))
+# From QEMU's hw/arm/boot.c:
+# RAM always starts at 1GiB PA offset. The kernel is placed there.
+KERNEL_ADDR=$(( 1*GiB ))
+
function usage() {
cat <<EOF
@@ -85,6 +91,10 @@
echo $(( (val + (align - 1)) & (~(align - 1)) ))
}
+function align_page_size() {
+ echo $(align_up_pow2 "$1" ${MAX_SUPPORTED_PAGE_SIZE})
+}
+
function hex() {
printf "%${2-#}x\n" $1
}
@@ -227,13 +237,11 @@
pvmfw_overlay "${QEMU_DTB}" "${QEMU_PATCHED_DTB}" "${TMP_DTS}" 0x0 0x0
TMP_DTB_SIZE=$(file_size "${QEMU_PATCHED_DTB}")
- # From QEMU's hw/arm/boot.c:
- # RAM always starts at 1GiB PA offset. The kernel is placed there.
# 128MiB (or RAM/2 if RAM<256MiB) is left to the kernel to decompress.
# This is followed by the ramdisk and then 2MiB-aligned DTB.
- # We place the pvmfw at the following page (assume 64KiB page size).
- PVMFW_ADDR=$(( 1*GiB + 128*MiB + TMP_DTB_SIZE ))
- PVMFW_ADDR=$(hex $(align_up_pow2 ${PVMFW_ADDR} 64*KiB))
+ # We place the pvmfw at the following page.
+ PVMFW_ADDR=$(( KERNEL_ADDR + 128*MiB + TMP_DTB_SIZE ))
+ PVMFW_ADDR=$(hex $(align_page_size ${PVMFW_ADDR}))
PVMFW_SIZE=$(hex $(file_size "${PVMFW}"))
pvmfw_overlay "${QEMU_DTB}" "${QEMU_PATCHED_DTB}" "${TMP_DTS}" \