Commit 61024180 authored by Grant Likely's avatar Grant Likely
Browse files

Refactor into a single makefile for core build



This patch adopts the Linux & U-boot kbuild style top level Makefile
that includes the generated config so that decisions can be made from
the specific config. The core of this change is to pull in the %config
parsing rules for u-boot/Makefile and process them separately from the
main build rules. This allows *config rules to change the U-Boot
configuration, and the import the CONFIG_* values into make so that
TFA_PLAT and other variables can be automatically determined.

Signed-off-by: Grant Likely's avatarGrant Likely <grant.likely@arm.com>
parent 766307c8
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) Arm Limited, 2020
#
# Build config for RockPro64
# Inspired by https://stikonas.eu/wordpress/2019/09/15/blobless-boot-with-rockpro64/
TFA_EXTRA += SCP_BL2=${CURDIR}/binaries-marvell/mrvl_scp_bl2.img
TFA_EXTRA += MV_DDR_PATH=${CURDIR}/mv-ddr
TFA_EXTRA += USE_COHERENT_MEM=0
$(SD_IMG): u-boot esp.img scripts/*.mk
dd if=/dev/zero of=$(SD_IMG) count=$$((128*1024*1024>>9))
#echo "label: dos" | /sbin/sfdisk $(SD_IMG)
echo "label: dos\n$$(($(ESP_OFFSET)>>9)) - 0xef -" | /sbin/sfdisk $(SD_IMG)
dd if=${FLASH_IMAGE} of=$(SD_IMG) seek=1 conv=notrunc
dd if=esp.img of=$(SD_IMG) seek=$$(($(ESP_OFFSET)>>9)) conv=notrunc
sdimage: $(FLASH_IMAGE)
dd if=/dev/zero of=$(SD_IMAGE) count=$$((128*1024*1024>>9))
echo "label: dos\n$$(($(ESP_OFFSET)>>9)) - 0xef -" | /sbin/sfdisk $(SD_IMAGE)
dd if=${FLASH_IMAGE} of=$(SD_IMAGE) seek=1 conv=notrunc
#dd if=esp.img of=$(SD_IMAGE) seek=$$(($(ESP_OFFSET)>>9)) conv=notrunc
......@@ -5,11 +5,11 @@
# Build config for RockPro64
# Inspired by https://stikonas.eu/wordpress/2019/09/15/blobless-boot-with-rockpro64/
$(SD_IMG): u-boot
dd if=/dev/zero of=$(SD_IMG) seek=32M count=0
/sbin/sgdisk -g $(SD_IMG)
/sbin/sgdisk -n 1:: $(SD_IMG)
dd if=${UBOOT_OUTPUT}/idbloader.img of=$(SD_IMG) seek=64
dd if=${UBOOT_OUTPUT}/u-boot.itb of=$(SD_IMG) seek=16384
FLASH_IMAGE_DEPS := u-boot/all
sdimage:
dd if=/dev/zero of=$(SD_IMAGE) seek=32M count=0
/sbin/sgdisk -g $(SD_IMAGE)
/sbin/sgdisk -n 1:: $(SD_IMAGE)
dd if=${UBOOT_OUTPUT}/idbloader.IMAGE of=$(SD_IMG) seek=64
dd if=${UBOOT_OUTPUT}/u-boot.itb of=$(SD_IMAGE) seek=16384
......@@ -34,16 +34,58 @@ else
export UBOOT_OUTPUT := $(UBOOT_PATH)
endif
all: tfa-fip
# ===========================================================================
# Rules shared between *config targets and build targets
clean:
$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) mrproper
cd $(TFA_PATH) && git clean -fdx
cd $(CURDIR)/mv-ddr && git clean -fdx
# To make sure we do not include .config for any of the *config targets
# catch them early
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'.
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).
no-dot-config-targets := clean
config-targets := 0
mixed-targets := 0
dot-config := 1
ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
dot-config := 0
endif
endif
ifneq ($(filter %config,$(MAKECMDGOALS)),)
config-targets := 1
ifneq ($(words $(MAKECMDGOALS)),1)
mixed-targets := 1
endif
endif
ifeq ($(mixed-targets),1)
# ===========================================================================
# We're called with mixed targets (*config and build targets).
# Handle them one by one.
PHONY += $(MAKECMDGOALS) __build_one_by_one
$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
@:
$(UBOOT_OUTPUT)/.config:
mkdir -p $(UBOOT_OUTPUT)
$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) $(TARGET)_defconfig
__build_one_by_one:
$(Q)set -e; \
for i in $(MAKECMDGOALS); do \
$(MAKE) $$i; \
done
else
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
# in scripts/kconfig to make the *config target
%config: u-boot/%config
echo CONFIG_CMD_BOOTEFI_HELLO=y >> $(UBOOT_OUTPUT)/.config
echo CONFIG_CMD_BOOTEFI_SELFTEST=y >> $(UBOOT_OUTPUT)/.config
echo CONFIG_CMD_NVEDIT_EFI=y >> $(UBOOT_OUTPUT)/.config
......@@ -51,7 +93,94 @@ $(UBOOT_OUTPUT)/.config:
echo CONFIG_CMD_GPT=y >> $(UBOOT_OUTPUT)/.config
$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) olddefconfig
%: $(UBOOT_OUTPUT)/.config
$(MAKE) -f scripts/main.mk TARGET=$(TARGET) $@
PHONY += defconfig
defconfig: ${TARGET}_defconfig ;
else
# ===========================================================================
# Build targets only
# In general all targets that make use of the selected configuration
ifeq ($(dot-config),1)
# Read in config
-include $(UBOOT_OUTPUT)/.config
# ===================================
# Platform/SOC specific configuration
ifdef CONFIG_ROCKCHIP_RK3399
TFA_PLAT := rk3399
UBOOT_EXTRA += BL31=$(TFA_PATH)/build/$(TFA_PLAT)/release/bl31/bl31.elf
FLASH_IMAGE := $(UBOOT_OUTPUT)/flash_image.bin
DTB_TARGET := src/arm64/$(CONFIG_DEFAULT_FDT_FILE)
u-boot: tfa-bl31
include $(CURDIR)/scripts/rk3399.mk
endif # CONFIG_ROCKCHIP_RK3399
ifdef CONFIG_ARMADA_8K
include scripts/mvebu-armada-8k.mk
DTB_TARGET := src/arm64/marvell/$(CONFIG_DEFAULT_DEVICE_TREE).dtb
ifeq ($(CONFIG_DEFAULT_DEVICE_TREE),"armada-8040-mcbin")
TFA_PLAT := a80x0_mcbin
endif
endif # CONFIG_ARMADA_8K
ifndef TFA_PLAT
$(warning TFA_PLAT is not set. Either TARGET=$(TARGET) is not yet supported)
$(error by this tool, or there is a bug)
endif
TFA_EXTRA += PLAT=$(TFA_PLAT)
TFA_EXTRA += LOG_LEVEL=20
TFA_EXTRA += BL33=$(UBOOT_OUTPUT)/u-boot.bin
FLASH_IMAGE ?= $(TFA_OUTPUT)/$(TFA_PLAT)/release/flash-image.bin
FLASH_IMAGE_DEPS ?= tfa/all tfa/fip
SD_IMAGE := $(TARGET)-sdcard.img
ESP_SIZE ?= $$((64*1024*1024))
ESP_OFFSET ?= $$((4*1024*1024))
endif # ifeq ($(dot-config),1)
PHONY += dtb
dtb: ${DTB_TARGET}
fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / u-boot-ver `cd ${UBOOT_PATH} && git describe`
fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / tfa-ver `cd ${TFA_PATH} && git describe`
fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / dt-ver `cd ${DT_PATH} && git describe`
PHONY += flashimage sdimage
flashimage ${FLASH_IMAGE}: ${FLASH_IMAGE_DEPS}
sdimage: flashimage
PHONY += clean
clean: u-boot/mrproper
cd $(TFA_PATH) && git clean -fdx
cd $(DT_PATH) && git clean -fdx
cd $(CURDIR)/mv-ddr && git clean -fdx
endif #ifeq ($(config-targets),1)
# ===========================================================================
# Common targets - Mostly delegates to the individual project build systems
# ================================================
# Delegate to devicetree-rebasing build
devicetree-rebasing/%.dtb:
${MAKE} -C ${DT_PATH} $*.dtb
# ================================================
# Delegate to trusted-firmware-a build
tfa/%:
${MAKE} -C ${TFA_PATH} ${TFA_EXTRA} $*
tfa/fip: u-boot/all
# ================================================
# Delegate to u-boot build
u-boot/%:
$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) $*
endif #ifeq ($(mixed-targets),1)
.PHONY: $(UBOOT_OUTPUT)/.config
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment