• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
2# Licensed under the Mulan PSL v2.
3# You can use this software according to the terms and conditions of the Mulan PSL v2.
4# You may obtain a copy of Mulan PSL v2 at:
5#     http://license.coscl.org.cn/MulanPSL2
6# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
7# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
8# PURPOSE.
9# See the Mulan PSL v2 for more details.
10
11# Q=@
12Q=
13
14include ../config.mk
15
16CC = $(CHCORE_COMPILER)
17# XXX: -march=armv8-a+nofp -fno-stack-protector are plat specific
18CFLAGS = -target $(CHCORE_CROSS_COMPILE) -Wall -Wno-initializer-overrides -Wno-asm-operand-widths\
19                 -fheinous-gnu-extensions -nostdinc -ffreestanding -march=armv8-a+nofp -fno-stack-protector \
20		 -fno-pic -fno-pie -mcmodel=large -O3
21CFLAGS += -Iinclude -Iinclude/arch/${CHCORE_ARCH} \
22		  -Iinclude/arch/${CHCORE_ARCH}/plat/${CHCORE_PLAT} \
23          -Iinclude/arch/${CHCORE_ARCH}/arch/trustzone/spd/${CHCORE_SPD} \
24		  -Iarch/${CHCORE_ARCH}/boot/${CHCORE_PLAT}/include
25CFLAGS += $(CONFIG_FLAGS)
26CFLAGS += -DLOG_LEVEL=1
27
28LDFLAGS =-target $(CHCORE_CROSS_COMPILE)  -no-pie -nostdlib -nostartfiles \
29		 -Wl,--build-id=none,--no-dynamic-linker -fuse-ld=lld
30
31OBJCOPY := $(CHCORE_COMPILER_DIR)/bin/llvm-objcopy
32
33ARCH_DIRS := backtrace irq machine mm sched sync trustzone
34ARCH_PATH := arch/$(CHCORE_ARCH)
35PLAT_DIRS := irq mm uart
36PLAT_PATH := arch/$(CHCORE_ARCH)/plat/$(CHCORE_PLAT)
37SPD_PATH := arch/$(CHCORE_ARCH)/trustzone/spd/$(CHCORE_SPD)
38DIRS := ipc irq lib mm object sched syscall \
39		$(ARCH_PATH) $(addprefix $(ARCH_PATH)/,$(ARCH_DIRS)) \
40        $(PLAT_PATH) $(addprefix $(PLAT_PATH)/,$(PLAT_DIRS)) \
41        $(SPD_PATH)
42C_SRCS := $(foreach dir,$(DIRS),$(wildcard $(dir)/*.c))
43C_OBJS := $(C_SRCS:%.c=%.c.o)
44ASM_SRCS += $(foreach dir,$(DIRS),$(wildcard $(dir)/*.S))
45ASM_SRCS += incbin_promgr_bin.S
46ASM_OBJS := $(ASM_SRCS:%.S=%.S.o)
47
48INIT_C_SRCS := $(wildcard arch/$(CHCORE_ARCH)/boot/$(CHCORE_PLAT)/init/*.c)
49INIT_C_OBJS := $(INIT_C_SRCS:%.c=%.c.o)
50INIT_ASM_SRCS := $(wildcard arch/$(CHCORE_ARCH)/boot/$(CHCORE_PLAT)/init/*.S) \
51                 $(wildcard arch/$(CHCORE_ARCH)/trustzone/spd/$(CHCORE_SPD)/init/*.S)
52INIT_ASM_OBJS := $(INIT_ASM_SRCS:%.S=%.S.o)
53
54ALL_OBJS := $(C_OBJS) $(ASM_OBJS) $(INIT_C_OBJS) $(INIT_ASM_OBJS)
55ALL_DEPS := $(ALL_OBJS:.o=.d)
56
57.PHONY: all clean
58all: bl32.bin
59
60# XXX: Strip off .interp since it is before init section.
61#      Not sure if other sections can also be placed here.
62bl32.bin: kernel.img
63	$(Q)$(OBJCOPY) -O binary -S $< $@
64
65kernel.img: $(ALL_OBJS) linker.ld
66	$(Q)$(CC) -Wl,-T,linker.ld $(LDFLAGS) $(ALL_OBJS) -o $@
67
68-include $(ALL_DEPS)
69
70clean:
71	$(Q)rm -f $(ALL_OBJS) $(ALL_DEPS) linker.ld linker.ld.S kernel.img bl32.bin trust.img incbin_promgr_bin.S
72
73$(C_OBJS) $(INIT_C_OBJS): %.o: %
74	$(Q)$(CC) $(CFLAGS) -c $< -o $@ -MMD
75
76$(ASM_OBJS) $(INIT_ASM_OBJS): %.o: %
77	$(Q)$(CC) $(CFLAGS) -D__ASM__ -c $< -o $@
78
79INIT_OBJS :=  $(INIT_ASM_OBJS) $(INIT_C_OBJS)
80# move start.S to the front for binary format
81INIT_OBJS := $(filter %start.S.o, $(INIT_OBJS)) $(filter-out %start.S.o, $(INIT_OBJS))
82INIT_OBJS_LIST := $(subst /,\/,$(INIT_OBJS))
83linker.ld: $(ARCH_PATH)/boot/linker.tpl.ld
84	$(Q)sed -e 's/$${init_objects}/$(INIT_OBJS_LIST)/g' -e 's/$${incbin_linker_script}/*(.incbin-procmgr_bin)\n        . = ALIGN(4K);/g' $< > linker.ld.S
85	$(Q)$(CC) -E -x c -I $(ARCH_PATH)/boot/$(CHCORE_PLAT)/include linker.ld.S | grep -v "^#"  > linker.ld
86
87incbin_promgr_bin.S: incbin.tpl.S
88	$(Q)sed 's/$${binary_name}/procmgr_bin/g;s/$${binary_path}/$(subst /,\/,$(PROCMGR))/g' $< > $@
89