You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/07/10 14:30:44 UTC
(nuttx) branch master updated: tools/imx9: prepare bootable bootloader image
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 80c37c7b36 tools/imx9: prepare bootable bootloader image
80c37c7b36 is described below
commit 80c37c7b368ed886fb905326292c815237594929
Author: Eero Nurkkala <ee...@offcode.fi>
AuthorDate: Tue Jul 9 14:19:12 2024 +0300
tools/imx9: prepare bootable bootloader image
This does the following:
1. Fetches mkimage_imx8 (same used with imx9) source code
2. Fetches the ELE / AHAB binary
3. Extracts the ELE / AHAB binary
4. Compiles the mkimage with hostcc
5. Utilizes the mkimage tool to create a bootable SD image,
combining the ELE / AHAB image with the NuttX bootloader
6. dd is used to prepend empty space in place of BL31
7. Outputs sdimage.img which is a bootable binary
8. Removes all binaries, sources code images that have been
downloaded
Signed-off-by: Eero Nurkkala <ee...@offcode.fi>
---
.gitignore | 1 +
.../arm64/imx9/boards/imx93-evk/README.txt | 31 +++++++++++++---
tools/imx9/Config.mk | 41 ++++++++++++++++++++++
tools/imx9/{Config.mk => Makefile.host} | 36 +++++++++++++------
4 files changed, 94 insertions(+), 15 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5f21c69b30..fd6ad6b437 100644
--- a/.gitignore
+++ b/.gitignore
@@ -65,3 +65,4 @@ tools/gdb/__pycache__
/build
.ccls-cache
compile_commands.json
+imx9-sdimage.img
diff --git a/Documentation/platforms/arm64/imx9/boards/imx93-evk/README.txt b/Documentation/platforms/arm64/imx9/boards/imx93-evk/README.txt
index 03e23579e4..412b39facc 100644
--- a/Documentation/platforms/arm64/imx9/boards/imx93-evk/README.txt
+++ b/Documentation/platforms/arm64/imx9/boards/imx93-evk/README.txt
@@ -4,8 +4,9 @@ README.txt
The kit i.MX93 Evaluation Kit has a pre-installed Linux image which contains
u-boot and the i.MX93 reference Linux installation.
-u-boot is required to boot NuttX (for now) as it initializes the hardware for
-us, i.e. DDR, clocks, I/O muxes etc.
+NuttX may work as the bootloader, replacing u-boot completely. Currently it
+doesn't initialize the DDR memory yet. In other words, DDR training is still
+missing.
==========================================
@@ -13,7 +14,9 @@ How to run nuttx on i.MX93 Evaluation Kit.
==========================================
-Below is a set of instructions on how to run NuttX on the i.MX93 EVK
+Below is a set of instructions on how to run NuttX on the i.MX93 EVK, on top
+of the u-boot. Also, instructions on running NuttX as the bootloader will
+follow.
==========================================
@@ -76,11 +79,12 @@ Loading and running the NuttX image
==========================================
-You have three options:
+You have four options:
1 - Load via u-boot from SD-card
2 - Load via gdb
3 - Load via JLink
+4 - Run from SD-card, without u-boot
==========================================
@@ -144,3 +148,22 @@ Option 3: load with JLink:
3. Load nuttx. Note that JLink expects the .elf extension, the default build output of nuttx is just "nuttx" without the extension, so it must be added to the file...
J-Link>LoadFile <path_to>/nuttx.elf
+
+==========================================
+
+Option 4: Run from SD-card, without u-boot
+
+==========================================
+
+1. Make sure CONFIG_IMX9_BOOTLOADER is set and system is configured properly for bootloader operation:
+
+ tools/configure.sh imx93-evk:bootloader
+
+2. The build outputs a file "imx9-sdimage.img". This image also contains the Ahab container. It's required to grant Trusted Resource Domain Controller (TRDC) permissions.
+ Flash it to an SD-card, where sdX may be sda or something else; verify the block device name properly (eg. /dev/sda, /dev/sdb etc):
+
+ sudo dd if=imx9-sdimage.img of=/dev/sdX bs=1k && sync
+
+3. Insert the SD-card into the imx93-evk, make sure BMODE switch is [1,2,3,4] = [Off, On, Off, Off] so that it boots from the SD-card.
+
+ This should boot into NuttShell in EL3 level.
diff --git a/tools/imx9/Config.mk b/tools/imx9/Config.mk
index af7f0ee010..70e3226203 100644
--- a/tools/imx9/Config.mk
+++ b/tools/imx9/Config.mk
@@ -25,9 +25,50 @@
# POSTBUILD -- Perform post build operations
ifeq ($(CONFIG_IMX9_BOOTLOADER),y)
+ MK_BASE_URL = https://raw.githubusercontent.com/nxp-imx/imx-mkimage/cbb99377cc2bb8f7cf213794c030e1c60423ef1f/src
+ BASE_PATH = $(TOPDIR)$(DELIM)tools$(DELIM)imx9$(DELIM)
+ FILE_1 = imx8qxb0.c
+ FILE_1_PATH = $(BASE_PATH)$(FILE_1)
+ FILE_2 = mkimage_common.h
+ FILE_2_PATH = $(BASE_PATH)$(FILE_2)
+ FILE_3 = mkimage_imx8.c
+ FILE_3_PATH = $(BASE_PATH)$(FILE_3)
+ FILE_EXE = $(BASE_PATH)mkimage_imx9
+ AHAB_BASE_URL = https://www.nxp.com/lgfiles/NMG/MAD/YOCTO
+ AHAB = firmware-ele-imx-0.1.1
+ AHAB_BINARY = $(AHAB).bin
+ AHAB_PATH = $(BASE_PATH)$(AHAB_BINARY)
+
+define DOWNLOAD_FILES
+ $(call DOWNLOAD,$(MK_BASE_URL),$(FILE_1),$(FILE_1_PATH))
+ $(call DOWNLOAD,$(MK_BASE_URL),$(FILE_2),$(FILE_2_PATH))
+ $(call DOWNLOAD,$(MK_BASE_URL),$(FILE_3),$(FILE_3_PATH))
+ $(call DOWNLOAD,$(AHAB_BASE_URL),$(AHAB_BINARY),$(AHAB_PATH))
+ $(Q) chmod a+x $(BASE_PATH)$(AHAB_BINARY)
+ $(Q) (cd $(BASE_PATH) && ./$(AHAB_BINARY) --auto-accept)
+endef
+
+ifeq ("$(wildcard $(FILE_EXE))","")
+ MKIMAGE_NOT_PRESENT = 1
+endif
+
define POSTBUILD
$(Q) echo "Removing sections"
$(Q) $(OBJCOPY) -O binary -R .bss -R .initstack $(BIN) nuttx.bin
$(Q) ([ $$? -eq 0 ] && echo "Done.")
+
+ $(Q) echo "Constructing sd image"
+ $(Q) echo "#define MKIMAGE_COMMIT 0xcbb99377" > $(BASE_PATH)build_info.h
+
+ $(if $(MKIMAGE_NOT_PRESENT),$(call DOWNLOAD_FILES))
+
+ +$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools$(DELIM)imx9 -f Makefile.host
+ $(Q) tools$(DELIM)imx9$(DELIM)mkimage_imx9$(HOSTEXEEXT) -soc IMX9 -append $(BASE_PATH)$(AHAB)$(DELIM)mx93a1-ahab-container.img -c -ap nuttx.bin a55 0x2049a000 -out flash.bin 1>/dev/null 2>&1
+ $(Q) dd if=/dev/zero of=imx9-sdimage.img bs=1k count=32 1>/dev/null 2>&1
+ $(Q) cat flash.bin >> imx9-sdimage.img
+ $(Q) rm flash.bin
+ $(Q) echo "imx9-sdimage.img" >> nuttx.manifest
+ $(Q) echo "Created imx9-sdimage.img"
+ $(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools$(DELIM)imx9 -f Makefile.host clean
endef
endif
diff --git a/tools/imx9/Config.mk b/tools/imx9/Makefile.host
similarity index 56%
copy from tools/imx9/Config.mk
copy to tools/imx9/Makefile.host
index af7f0ee010..aedbc2bcfb 100644
--- a/tools/imx9/Config.mk
+++ b/tools/imx9/Makefile.host
@@ -1,5 +1,5 @@
############################################################################
-# tools/imx9/Config.mk
+# tools/imx9/Makefile.host
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@@ -18,16 +18,30 @@
#
############################################################################
-# These are the macros that will be used in the NuttX make system to compile
-# and assembly source files and to insert the resulting object files into an
-# archive. These replace the default definitions at tools/Config.mk
+-include $(TOPDIR)/Make.defs
+all: mkimage_imx9
+default: mkimage_imx9
+.PHONY: clean
-# POSTBUILD -- Perform post build operations
+# Add CFLAGS=-g on the make command line to build debug versions
-ifeq ($(CONFIG_IMX9_BOOTLOADER),y)
-define POSTBUILD
- $(Q) echo "Removing sections"
- $(Q) $(OBJCOPY) -O binary -R .bss -R .initstack $(BIN) nuttx.bin
- $(Q) ([ $$? -eq 0 ] && echo "Done.")
-endef
+CFLAGS = -g -O2 -Wall -std=c99 -static
+
+# mkimage_imx9 - combine and sign a bootloader image for flashing
+
+mkimage_imx9: imx8qxb0.c mkimage_imx8.c
+ @gcc $(CFLAGS) -o mkimage_imx9 imx8qxb0.c mkimage_imx8.c
+
+clean:
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) rm -rf *.dSYM
endif
+ $(call DELFILE, mkimage_imx9)
+ $(call DELFILE, mkimage_imx9.exe)
+ $(call DELFILE, mkimage_imx8.c)
+ $(call DELFILE, imx8qxb0.c)
+ $(call DELFILE, mkimage_common.h)
+ $(call DELFILE, build_info.h)
+ $(call DELFILE, firmware-ele-imx-0.1.1.bin)
+ $(call DELDIR, firmware-ele-imx-0.1.1)
+ $(call CLEAN)