0
|
1 UNAME := $(shell uname -m)
|
|
2
|
|
3 ifeq ($(UNAME), x86_64)
|
|
4 # set FVP as default on x86_64 systems
|
|
5 hw?=rpi2
|
|
6 TOOLCHAIN?=~/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-
|
|
7 else
|
|
8 # RPI reports 'uname -m' as: armv7l
|
|
9 hw?=rpi2
|
|
10 endif
|
|
11
|
|
12 # PHYSTART : start of memory (RAM)
|
|
13 # PHYSIZE : size of memory
|
|
14 # KERNBASE : address of high memory schema
|
|
15 # MMIO_PA : physical address of peripherals (MMIO)
|
|
16 # MMIO_VA : virtal address of peripherals
|
|
17 # MMIO_SIZE : size of peripherals
|
|
18 # PERIPHBASE: virtal address of PERIPHBASE[39:15]
|
|
19
|
|
20 ifeq ($(hw), fvp)
|
|
21 PHYSTART = 0x80000000
|
|
22 PHYSIZE = 0x08000000
|
|
23 KERNBASE = 0xC0000000
|
|
24 MMIO_PA = 0x1C000000
|
|
25 MMIO_VA = 0xD0000000
|
|
26 MMIO_SIZE = 0x04000000
|
|
27 PERIPHBASE= 0xDF000000
|
|
28 CFLAGS = -ffreestanding -nostdlib -nostartfiles -O0 -Wall -MD -ggdb -Wall -mcpu=cortex-a9 -mfloat-abi=hard -fno-short-enums -I include
|
|
29 #CFLAGS = -ffreestanding -nostdlib -nostartfiles -O2 -Wall -MD -ggdb -Wall -mcpu=cortex-a9 -mfloat-abi=hard -fno-short-enums -I include
|
|
30 TARGET = fvp.img
|
|
31 CC_OPTIONS = -DFVP
|
|
32 else ifeq ($(hw), rpi1)
|
|
33 PHYSTART = 0x00000000
|
|
34 # PHYSIZE set to 128mb
|
|
35 PHYSIZE = 0x08000000
|
|
36 KERNBASE = 0x80000000
|
|
37 MMIO_PA = 0x20000000
|
|
38 MMIO_VA = 0xD0000000
|
|
39 MMIO_SIZE = 0x01000000
|
|
40 PERIPHBASE= 0xDF000000
|
|
41 #CFLAGS = -fno-pic -static -Wno-packed-bitfield-compat -fno-builtin -fno-strict-aliasing -fshort-wchar -O2 -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -fno-stack-protector -Wa,-march=armv6 -Wa,-mcpu=arm1176jzf-s -mfloat-abi=hard -fno-short-enums -I include
|
|
42 CFLAGS = -ffreestanding -nostdlib -nostartfiles -O2 -Wall -MD -ggdb -Wall -mcpu=arm1176jzf-s -mfloat-abi=hard -fno-short-enums -I include
|
|
43 TARGET = kernel.img
|
|
44 CC_OPTIONS = -DRPI1
|
|
45 else ifeq ($(hw), rpi2)
|
|
46 PHYSTART = 0x00000000
|
|
47 # PHYSIZE set to 256mb
|
|
48 PHYSIZE = 0x10000000
|
|
49 KERNBASE = 0x80000000
|
|
50 MMIO_PA = 0x3F000000
|
|
51 MMIO_VA = 0xD0000000
|
|
52 MMIO_SIZE = 0x01000000
|
|
53 PERIPHBASE= 0xDF000000
|
|
54 CFLAGS = -ffreestanding -nostdlib -nostartfiles -O2 -Wall -MD -ggdb -Wall -mcpu=cortex-a7 -mfloat-abi=hard -fno-short-enums -I include
|
|
55 TARGET = kernel7.bin
|
|
56 CC_OPTIONS = -DRPI2
|
|
57 else
|
|
58 $(error Hardware (hw) should be fvp, rpi1 or rpi2, eg. make hw=rpi2)
|
|
59 endif
|
|
60
|
|
61
|
|
62 K_PDX_BASE=$(shell printf "0x%X\n" $$(( $(PHYSTART) + 0x4000 )) )
|
|
63 K_PTX_BASE=$(shell printf "0x%X\n" $$(( $(PHYSTART) + 0x3000 )) )
|
|
64 OFFSET=0x8000
|
|
65 PHYSOFFSET=$(shell printf "0x%X\n" $$(( $(PHYSTART) + $(OFFSET) )) )
|
|
66 KERNOFFSET=$(shell printf "0x%X\n" $$(( $(KERNBASE) + $(OFFSET) )) )
|
|
67
|
|
68 CC_OPTIONS += -DPHYSTART=$(PHYSTART) -DPHYSIZE=$(PHYSIZE) -DKERNBASE=$(KERNBASE) -DMMIO_PA=$(MMIO_PA) -DMMIO_VA=$(MMIO_VA) -DMMIO_SIZE=$(MMIO_SIZE) -DPERIPHBASE=$(PERIPHBASE)
|
|
69 CC_OPTIONS += -DK_PDX_BASE=$(K_PDX_BASE) -DK_PTX_BASE=$(K_PTX_BASE) -DPHYSOFFSET=$(PHYSOFFSET) -DKERNOFFSET=$(KERNOFFSET)
|
|
70
|
|
71 LD_OPTIONS = --defsym=PHYSTART=$(PHYSTART) --defsym=PHYSIZE=$(PHYSIZE) --defsym=KERNBASE=$(KERNBASE) --defsym=MMIO_PA=$(MMIO_PA) --defsym=MMIO_VA=$(MMIO_VA) --defsym=MMIO_SIZE=$(MMIO_SIZE) --defsym=PERIPHBASE=$(PERIPHBASE)
|
|
72 LD_OPTIONS += --defsym=K_PDX_BASE=$(K_PDX_BASE) --defsym=K_PTX_BASE=$(K_PTX_BASE) --defsym=PHYSOFFSET=$(PHYSOFFSET) --defsym=KERNOFFSET=$(KERNOFFSET)
|
|
73
|
|
74 # Build directory
|
|
75 BUILD=build/
|
|
76 # Sources directory.
|
|
77 SOURCE=source/
|
|
78 # Generated listing file.
|
|
79 LIBRARIES=
|
|
80
|
|
81 # The names of all object files that must be generated. Deduced from the
|
|
82 # assembly code files in source.
|
|
83 ASM_OBJECTS = $(patsubst $(SOURCE)%.S,$(BUILD)%.o,$(wildcard $(SOURCE)*.S))
|
|
84
|
|
85 C_OBJECTS = $(patsubst $(SOURCE)%.c,$(BUILD)%.o,$(wildcard $(SOURCE)*.c))
|
|
86
|
|
87 # Rule to make everything.
|
|
88 all : $(TARGET)
|
|
89
|
|
90 # Rule to make the elf file.
|
|
91 $(TARGET): $(ASM_OBJECTS) $(C_OBJECTS) kernel.ld
|
|
92 $(TOOLCHAIN)ld $(ASM_OBJECTS) $(C_OBJECTS) -L. $(patsubst %,-l %,$(LIBRARIES)) $(LD_OPTIONS) -Map kernel.map -o $(BUILD)kernel.elf -T kernel.ld
|
|
93 $(TOOLCHAIN)objdump -d $(BUILD)kernel.elf > kernel.list
|
|
94 $(TOOLCHAIN)objcopy $(BUILD)kernel.elf -O binary $(TARGET)
|
|
95
|
|
96 # Build ASM files
|
|
97 $(BUILD)%.o: $(SOURCE)%.S $(BUILD)
|
|
98 $(TOOLCHAIN)gcc -c $(CFLAGS) $(CC_OPTIONS) -I source $< -o $@
|
|
99
|
|
100 # Build C files
|
|
101 $(BUILD)%.o: $(SOURCE)%.c $(BUILD)
|
|
102 $(TOOLCHAIN)gcc -c $(CFLAGS) $(CC_OPTIONS) $< -o $@
|
|
103
|
|
104 loader: loader.S kernel7.bin
|
|
105 $(TOOLCHAIN)gcc -c loader.S -o loader.elf -fpic -ffreestanding -nostdlib -nostartfiles -O0 -Wall -ggdb -Wall -mcpu=cortex-a7 -mfloat-abi=hard -fno-short-enums -o loader.o
|
|
106 $(TOOLCHAIN)ld loader.o -o loader.elf -T loader.ld
|
|
107 #$(TOOLCHAIN)objdump -D loader.elf > loader.list
|
|
108 $(TOOLCHAIN)objcopy loader.elf -O binary kernel7.img
|
|
109 -rm loader.elf loader.o
|
|
110
|
|
111 $(BUILD):
|
|
112 mkdir $@
|
|
113
|
|
114 .PHONY: report
|
|
115 report:
|
|
116 @echo 'Hardware :' $(hw)
|
|
117 @echo 'TARGET :' $(TARGET)
|
|
118 @echo 'PHYSTART :' $(PHYSTART)
|
|
119 @echo 'PHYSIZE :' $(PHYSIZE)
|
|
120
|
|
121 @echo 'K_PDX_BASE:' $(K_PDX_BASE)
|
|
122 @echo 'K_PTX_BASE:' $(K_PTX_BASE)
|
|
123 @echo 'PHYSOFFSET:' $(PHYSOFFSET)
|
|
124
|
|
125 @echo 'KERNBASE :' $(KERNBASE)
|
|
126 @echo 'KERNOFFSET:' $(KERNOFFSET)
|
|
127
|
|
128 @echo 'MMIO_PA :' $(MMIO_PA)
|
|
129 @echo 'MMIO_SIZE :' $(MMIO_SIZE)
|
|
130 @echo 'MMIO_VA :' $(MMIO_VA)
|
|
131 @echo 'PERIPHBASE:' $(PERIPHBASE)
|
|
132
|
|
133 @echo 'CFLAGS :' $(CFLAGS)
|
|
134 @echo 'CC_OPTIONS:' $(CC_OPTIONS)
|
|
135 @echo 'LD_OPTIONS:' $(LD_OPTIONS)
|
|
136
|
|
137 .PHONY: install
|
|
138 install:
|
|
139 cp kernel*.img /media/$(USER)/boot/
|
|
140 sync
|
|
141 umount /media/$(USER)/*
|
|
142
|
|
143 # Rule to clean files.
|
|
144 clean :
|
|
145 -rm -rf $(BUILD)
|
|
146 -rm -f *.img
|
|
147 -rm -f *.bin
|
|
148 -rm -f kernel.list
|
|
149 -rm -f kernel.map
|