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 <eero.nurkkala@offcode.fi>
This commit is contained in:
Eero Nurkkala 2024-07-09 14:19:12 +03:00 committed by Xiang Xiao
parent 23b7dc0651
commit 80c37c7b36
4 changed files with 116 additions and 4 deletions

1
.gitignore vendored
View File

@ -65,3 +65,4 @@ tools/gdb/__pycache__
/build /build
.ccls-cache .ccls-cache
compile_commands.json compile_commands.json
imx9-sdimage.img

View File

@ -4,8 +4,9 @@ README.txt
The kit i.MX93 Evaluation Kit has a pre-installed Linux image which contains 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 and the i.MX93 reference Linux installation.
u-boot is required to boot NuttX (for now) as it initializes the hardware for NuttX may work as the bootloader, replacing u-boot completely. Currently it
us, i.e. DDR, clocks, I/O muxes etc. 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 1 - Load via u-boot from SD-card
2 - Load via gdb 2 - Load via gdb
3 - Load via JLink 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... 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 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.

View File

@ -25,9 +25,50 @@
# POSTBUILD -- Perform post build operations # POSTBUILD -- Perform post build operations
ifeq ($(CONFIG_IMX9_BOOTLOADER),y) 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 define POSTBUILD
$(Q) echo "Removing sections" $(Q) echo "Removing sections"
$(Q) $(OBJCOPY) -O binary -R .bss -R .initstack $(BIN) nuttx.bin $(Q) $(OBJCOPY) -O binary -R .bss -R .initstack $(BIN) nuttx.bin
$(Q) ([ $$? -eq 0 ] && echo "Done.") $(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 endef
endif endif

47
tools/imx9/Makefile.host Normal file
View File

@ -0,0 +1,47 @@
############################################################################
# tools/imx9/Makefile.host
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
-include $(TOPDIR)/Make.defs
all: mkimage_imx9
default: mkimage_imx9
.PHONY: clean
# Add CFLAGS=-g on the make command line to build debug versions
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)