forked from Broadcom/aeolus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
141 lines (117 loc) · 3.97 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
# Aeolus - a program to boot the Zephyr MIPS
# Copyright (C) 2014 Broadcom Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# override this to use "make zephyr.img"
LINUXDIR := ../linux
ifneq ($(VIPER),1)
# pick your board from $LINUXDIR/arch/mips/boot/dts/
DEFAULT_BOARD := bcm93384wvg
MEM_START := 0x80000000
MIPS_INIT := bmips5000.o
VIPER := 0
else
# experimental Viper MIPS builds
DEFAULT_BOARD := bcm93384wvg_viper
MEM_START := 0x86000000
PHYSICAL_START := 0x86010000
MIPS_INIT := bmips4350.o
endif
# This is a slightly modified MetaROUTER OpenWRT rootfs (pretty much the
# bare minimum needed to boot the system).
# Source: http://openwrt.wk.cz/kamikaze/openwrt-mr-mips-rootfs-18961.tar.gz
# A few of the startup scripts were changed; the binaries are as-is from
# upstream.
# Leave this variable blank for no rootfs.
DEFAULT_ROOTFS := misc/mr-rootfs.cpio.xz
CROSS_COMPILE := mips-linux-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
CPP := $(CROSS_COMPILE)cpp
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
OBJCOPY := $(CROSS_COMPILE)objcopy
DTC := dtc
PROGSTORE := ProgramStore/ProgramStore
NEWLIB_BUILD := newlib/build
NEWLIB_OBJS := $(NEWLIB_BUILD)/mips-none-elf/newlib/libc.a
NEWLIB_INCDIR := newlib/newlib/libc/include
LIBFDT_OBJS := libfdt/fdt.o libfdt/fdt_ro.o libfdt/fdt_rw.o libfdt/fdt_wip.o
COMMON_FLAGS := -mno-abicalls -Wall -fno-strict-aliasing \
-DMEM_START=$(MEM_START) -DVIPER=$(VIPER)
CFLAGS := $(COMMON_FLAGS) -ffreestanding -Os \
-nostdlib -nostdinc -I$(NEWLIB_INCDIR) \
-I. -Ilibfdt
AFLAGS := $(COMMON_FLAGS)
CORE_OBJS := init.o $(MIPS_INIT) main.o dtb.o
OBJS := $(CORE_OBJS) $(LIBFDT_OBJS) $(NEWLIB_OBJS)
aeolus.bin: aeolus.elf
$(OBJCOPY) -O binary $< $@
zephyr.img: aeolus.bin $(PROGSTORE) $(LINUXDIR)/vmlinux
$(OBJCOPY) -O binary $(LINUXDIR)/vmlinux vmlinux.bin
cat aeolus.bin vmlinux.bin > concat.bin
$(PROGSTORE) -f concat.bin -o $@ -c 4 -s 0x3384 -a 0 -v 003.000 \
-f2 misc/dummy.txt
rm -f vmlinux.bin concat.bin
$(LINUXDIR)/.linux-configured:
$(MAKE) -C $(LINUXDIR) ARCH=mips bmips_be_defconfig
ifneq ($(DEFAULT_ROOTFS),)
xz -d < $(DEFAULT_ROOTFS) > $(LINUXDIR)/rootfs.cpio
cd $(LINUXDIR) && ./scripts/config \
--set-str CONFIG_INITRAMFS_SOURCE rootfs.cpio \
--set-val CONFIG_INITRAMFS_ROOT_UID 0 \
--set-val CONFIG_INITRAMFS_ROOT_GID 0
endif
ifneq ($(PHYSICAL_START),)
cd $(LINUXDIR) && ./scripts/config \
--enable CONFIG_CRASH_DUMP \
--enable CONFIG_PROC_VMCORE \
--set-val CONFIG_PHYSICAL_START $(PHYSICAL_START)
endif
touch $@
board.dtb:
$(DTC) -O dtb -o $@ $(LINUXDIR)/arch/mips/boot/dts/brcm/$(DEFAULT_BOARD).dts
.PHONY: $(LINUXDIR)/vmlinux
$(LINUXDIR)/vmlinux: $(LINUXDIR)/.linux-configured
$(MAKE) -C $(LINUXDIR) ARCH=mips vmlinux
aeolus.elf: $(OBJS) map.lds
$(LD) $^ -o $@ -T map.lds
dtb.o: board.dtb
$(OBJCOPY) -I binary -O elf32-tradbigmips --rename-section .data=.dtb \
-B mips $< $@
$(NEWLIB_BUILD)/Makefile:
mkdir -p $(NEWLIB_BUILD)
cd $(NEWLIB_BUILD) && ../configure \
--target=mips-none-elf \
CFLAGS_FOR_TARGET="-mno-abicalls -Os" \
CC_FOR_TARGET=$(CC) \
LD_FOR_TARGET=$(LD) \
AR_FOR_TARGET=$(AR) \
RANLIB_FOR_TARGET=$(RANLIB)
$(NEWLIB_OBJS): $(NEWLIB_BUILD)/Makefile
$(MAKE) -C $(NEWLIB_BUILD)
%.lds: %.lds.S
$(CPP) -DMEM_START=$(MEM_START) -P $< -o $@
%.o: %.S
$(CC) -c $(AFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(PROGSTORE):
$(MAKE) -C ProgramStore
.PHONY: clean
clean:
rm -rf $(OBJS) map.lds aeolus.bin aeolus.elf $(NEWLIB_BUILD)
$(MAKE) -C ProgramStore clean
.PHONY: distclean
distclean: clean
rm -f zephyr.img board.dtb