1#
2# Builds test programs. This is launched from elf_test.BuildElfTestFiles()
3#
4# Copyright (C) 2017 Google, Inc
5# Written by Simon Glass <sjg@chromium.org>
6#
7# SPDX-License-Identifier:      GPL-2.0+
8#
9
10HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ )
11ifeq ($(findstring $(HOSTARCH),"x86" "x86_64"),)
12ifeq ($(findstring $(MAKECMDGOALS),"help" "clean"),)
13ifndef CROSS_COMPILE
14$(error Binman tests need to compile to x86, but the CPU arch of your \
15	machine is $(HOSTARCH). Set CROSS_COMPILE to a suitable cross compiler)
16endif
17endif
18endif
19
20CC		= $(CROSS_COMPILE)gcc
21OBJCOPY		= $(CROSS_COMPILE)objcopy
22
23VPATH := $(SRC)
24CFLAGS := -march=i386 -m32 -nostdlib -I $(SRC)../../../include -I $(SRC) \
25	-Wl,--no-dynamic-linker
26
27LDS_UCODE := -T $(SRC)u_boot_ucode_ptr.lds
28LDS_BINMAN := -T $(SRC)u_boot_binman_syms.lds
29LDS_BINMAN_BAD := -T $(SRC)u_boot_binman_syms_bad.lds
30LDS_BINMAN_X86 := -T $(SRC)u_boot_binman_syms_x86.lds
31LDS_BINMAN_EMBED := -T $(SRC)u_boot_binman_embed.lds
32LDS_EFL_SECTIONS := -T $(SRC)elf_sections.lds
33LDS_BLOB := -T $(SRC)blob_syms.lds
34
35TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr bss_data bss_data_zero \
36	u_boot_binman_syms u_boot_binman_syms.bin u_boot_binman_syms_bad \
37	u_boot_binman_syms_size u_boot_binman_syms_x86 embed_data \
38	u_boot_binman_embed u_boot_binman_embed_sm elf_sections blob_syms.bin
39
40all: $(TARGETS)
41
42u_boot_no_ucode_ptr: CFLAGS += $(LDS_UCODE)
43u_boot_no_ucode_ptr: u_boot_no_ucode_ptr.c
44
45u_boot_ucode_ptr: CFLAGS += $(LDS_UCODE)
46u_boot_ucode_ptr: u_boot_ucode_ptr.c
47
48bss_data: CFLAGS += $(SRC)bss_data.lds
49bss_data: bss_data.c
50
51bss_data_zero: CFLAGS += $(SRC)bss_data_zero.lds
52bss_data_zero: bss_data_zero.c
53
54embed_data: CFLAGS += $(SRC)embed_data.lds
55embed_data: embed_data.c
56
57u_boot_binman_syms.bin: u_boot_binman_syms
58	$(OBJCOPY) -O binary $< -R .note.gnu.build-id $@
59
60u_boot_binman_syms: CFLAGS += $(LDS_BINMAN)
61u_boot_binman_syms: u_boot_binman_syms.c
62
63u_boot_binman_syms_x86: CFLAGS += $(LDS_BINMAN_X86)
64u_boot_binman_syms_x86: u_boot_binman_syms_x86.c
65
66u_boot_binman_syms_bad: CFLAGS += $(LDS_BINMAN_BAD)
67u_boot_binman_syms_bad: u_boot_binman_syms_bad.c
68
69u_boot_binman_syms_size: CFLAGS += $(LDS_BINMAN)
70u_boot_binman_syms_size: u_boot_binman_syms_size.c
71
72u_boot_binman_embed: CFLAGS += $(LDS_BINMAN_EMBED)
73u_boot_binman_embed: u_boot_binman_embed.c
74
75u_boot_binman_embed_sm: CFLAGS += $(LDS_BINMAN_EMBED)
76u_boot_binman_embed_sm: u_boot_binman_embed_sm.c
77
78blob_syms.bin: blob_syms
79	$(OBJCOPY) -O binary $< -R .note.gnu.build-id $@
80
81blob_syms: CFLAGS += $(LDS_BLOB)
82blob_syms: blob_syms.c
83
84elf_sections: CFLAGS += $(LDS_EFL_SECTIONS)
85elf_sections: elf_sections.c
86
87clean:
88	rm -f $(TARGETS)
89
90help:
91	@echo "Makefile for binman test programs"
92	@echo
93	@echo "Intended for use on x86 hosts"
94	@echo
95	@echo "Targets:"
96	@echo
97	@echo -e "\thelp	- Print help (this is it!)"
98	@echo -e "\tall	- Builds test programs (default targget)"
99	@echo -e "\tclean	- Delete output files"
100