Added support for NOR/EMAC boot for C6670
[keystone-rtos/ibl.git] / src / make / makestg2
1 #*****************************************************************************
2 #* FILE PURPOSE: 2nd stage makefile for the intermediate boot loader
3 #*****************************************************************************
4 #* FILE NAME: makestg2
5 #*
6 #* DESCRIPTION: This makefile is invoked with build specific options
7 #*
8 #******************************************************************************
10 ifndef IBL_ROOT
11         IBL_ROOT=..
12 endif
14 CFG_MODULES= main device
15 MODULES= ethboot nandboot driver hw interp ecc norboot
17 # Note that the Hw module is a two stage clean and handled seperately
18 CLEAN_MODULES=$(addprefix clean_,$(subst hw,,$(MODULES)))
19 CLEAN_MODULES+=$(addprefix clean_,$(CFG_MODULES))
22 TARGETS= c6472 c6474 c6474l c6455 c6457 c661x
24 # The main module needs to know the device address of the i2c where the image map resides
25 MAINDEFS=-DIBL_CFG_I2C_MAP_TABLE_DATA_BUS_ADDR=$(I2C_BUS_ADDR)
27 # Add build time exclusion definitions
28 MAINDEFS+=$(addprefix -DEXCLUDE_,$(EXCLUDES))
30 # Add SPI definitions
31 SPI_CFG= $(addprefix -D,$(SPI_DEFS))
34 # Common symbols are functions which are loaded with the stage load of the IBL, and
35 # also referenced from the second stage
36 #COMMON_SYMBOLS= hwI2Cinit hwI2cMasterRead iblBootBtbl iblMalloc iblFree iblMemset iblMemcpy
37 COMMON_SYMBOLS= iblBootBtbl iblMalloc iblFree iblMemset iblMemcpy
39 ifeq ($(ENDIAN),little)
40         HEX_OPT= -order L
41         IEXT=     le
42 else
43         HEX_OPT= -order M
44         IEXT=     be
45 endif
47 ifeq ($(COMPACT_I2C),yes)
48   COMPACT= -compact
49 endif
51 include $(IBL_ROOT)/make/$(ARCH)/makedefs.mk
53 export ARCH
54 export TARGET
56 .PHONY:  $(TARGETS) i2crom spiRom compare iblInit iblMain $(MODULES) $(CFG_MODULES)
57 .PHONY:  utils clean clean_modules hwClean cleant
59 $(TARGETS): iblMain
61 ifeq ($(TARGET),c661x)
62     HAS_SPI=1
63 else
64     HAS_SPI=0
65 endif
67 ifeq ($(INTERNAL_UTILS), no)
68     HAS_INTERNAL_UTILS = 0
69 else
70     HAS_INTERNAL_UTILS = 1
71 endif
73 ifeq (EXCLUDE_SPI, $(strip $(findstring EXCLUDE_SPI, $(MAINDEFS))))
74     HAS_SPI=0
75 endif
77 ifeq (EXCLUDE_I2C, $(strip $(findstring EXCLUDE_I2C, $(MAINDEFS))))
78     HAS_I2C=0
79 else 
80    HAS_I2C=1
81 endif
83 # The I2C creation options. The I2C map file is run through the C pre-processor to generate
84 # the desired I2C mapping. There are three possible configurations - an i2c which has
85 # both endians present, or an I2C with only one of the endians
87 I2C_BE_FILE=      '"ibl_$(TARGET)/ibl.i2c.be.ccs"'
88 I2C_LE_FILE=      '"ibl_$(TARGET)/ibl.i2c.le.ccs"'
89 I2C_INIT_BE_FILE= '"ibl_$(TARGET)/ibl_init.i2c.be.ccs"'
90 I2C_INIT_LE_FILE= '"ibl_$(TARGET)/ibl_init.i2c.le.ccs"'
92 I2C_DEFS= -DI2C_BUS_ADDR=$(I2C_BUS_ADDR)
93 I2C_DEFS+= -DI2C_MAP_ADDR=$(I2C_MAP_ADDR)
95 ifeq ($(I2CROM),both) 
96  I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
97  I2C_DEFS+= -DEXE_FILE_1=$(I2C_LE_FILE) 
98  I2C_DEFS+= -DPAD_FILE_ID_1=1 
99  I2C_DEFS+= -DEXE_FILE_2=$(I2C_BE_FILE) 
100  I2C_DEFS+= -DPAD_FILE_ID_2=2 
102  SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
103  SPI_CFG+= -DEXE_FILE_1=$(I2C_LE_FILE) 
104  SPI_CFG+= -DPAD_FILE_ID_1=1 
105  SPI_CFG+= -DEXE_FILE_2=$(I2C_BE_FILE) 
106  SPI_CFG+= -DPAD_FILE_ID_2=2 
108 else 
109  I2C_DEFS+= -DPAD_FILE_ID_1=1
110  I2C_DEFS+= -DPAD_FILE_ID_2=1
112  SPI_CFG+= -DPAD_FILE_ID_1=1
113  SPI_CFG+= -DPAD_FILE_ID_2=1
115  ifeq ($(I2CROM),little_endian)
116   I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
117   I2C_DEFS+= -DEXE_FILE_1=$(I2C_LE_FILE)
118   I2C_DEFS+= -DEXE_FILE_2='""'
120   SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
121   SPI_CFG+= -DEXE_FILE_1=$(I2C_LE_FILE)
122   SPI_CFG+= -DEXE_FILE_2='""'
124  else
125   I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_BE_FILE)
126   I2C_DEFS+= -DEXE_FILE_1='""'
127   I2C_DEFS+= -DEXE_FILE_2=$(I2C_BE_FILE)
129   SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_BE_FILE)
130   SPI_CFG+= -DEXE_FILE_1='""'
131   SPI_CFG+= -DEXE_FILE_2=$(I2C_BE_FILE)
133  endif
134 endif
136 ifeq ($(HAS_SPI),0)
137     SPI_CFG=    
138 endif
140 i2crom:
141         $(CC) -ppo -I../cfg/$(TARGET) $(I2C_DEFS) ibl_$(TARGET)/$@.map.pre
142         ../util/romparse/romparse $(COMPACT) -rom_base $(I2C_BUS_ADDR) ibl_$(TARGET)/$@.map.pp
143         $(CP) i2crom.ccs ibl_$(TARGET)/$@.ccs
144         $(CP) i2crom.ccs ibl_$(TARGET)/$@.dat
145         ../util/btoccs/ccs2bin -swap ibl_$(TARGET)/$@.ccs ibl_$(TARGET)/$@.bin
146         $(RM) i2crom.ccs ibl_le.b ibl.b
148 spiRom:
149         @echo Making SPI ROM
150         $(CC) -ppo -I../cfg/$(TARGET) $(SPI_CFG) ibl_$(TARGET)/$@.map.pre
151         ../util/romparse/romparse $(COMPACT) -fill 0xff -rom_base 0 ibl_$(TARGET)/$@.map.pp
152         $(CP) i2crom.ccs ibl_$(TARGET)/$@.ccs
153         $(CP) i2crom.ccs ibl_$(TARGET)/$@.dat
159 # Target compare checks if the iblInit is compiled the same for both endians
160 compare:
161         @echo -
162         @sh -c 'if diff -q ibl_$(TARGET)/ibl_init.le.ccs ibl_$(TARGET)/ibl_init.be.ccs ; then echo IBL init endian neutral ; else echo !!! WARNING !!!! IBL ini NOT endian neutral !!! ; fi '
163         @echo -
165 # For the init code a raw image is created as well as the i2c code to verify
166 # endian independent code is generated. The symbols required for linking
167 # the full application are then extracted
168 iblInit: $(CFG_MODULES) $(MODULES)
169         cat ibl_$(TARGET)/ibl_init_objs_template.inc | sed -e s/ENDIAN_TAG/$(IEXT)/g > ibl_$(TARGET)/ibl_init_objs.tmp
170         $(CC) -ppo $(MAINDEFS) -DENDIAN_TAG=$(IEXT) ibl_$(TARGET)/ibl_init_objs.tmp
171         $(CP) ibl_$(TARGET)/ibl_init_objs.pp ibl_$(TARGET)/ibl_init_objs.inc
172         $(LD) -o ibl_$(TARGET)/ibl_$(TARGET)_init.out -m ibl_$(TARGET)/ibl_$(TARGET)_init.map ibl_$(TARGET)/ibl_init.cmd $(RTLIBS)
173         $(CP) ibl_$(TARGET)/ibl_$(TARGET)_init.out ibl_$(TARGET)/ibl_$(TARGET)_init.$(IEXT).out
174         $(RM) -f ibl_$(TARGET)/ibl_init_obj.inc
176         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl_init_image.rmd ibl_$(TARGET)/ibl_$(TARGET)_init.out
177         $(CP) ibl_le.b ibl_$(TARGET)/ibl.b
178         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl_init.$(IEXT).ccs
180         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl_init.rmd ibl_$(TARGET)/ibl_$(TARGET)_init.out
181         ../util/bconvert/bconvert64x -$(IEXT) ibl_le.b ibl.b
182         $(CP) ibl.b ibl_$(TARGET)
183         ../util/btoccs/b2i2c ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl.i2c.b
184         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.i2c.b ibl_$(TARGET)/ibl_init.i2c.$(IEXT).ccs
186         sed -e 's/\\r//' ../util/symExtract/symExtract > ../util/symExtract/symExtract_unix
187         bash ../util/symExtract/symExtract_unix ibl_$(TARGET)/ibl_$(TARGET)_init.map ibl_$(TARGET)/ibl_init_symbols.inc $(COMMON_SYMBOLS)
188         rm -f ../util/symExtract/symExtract_unix
190         
191 iblMain: iblInit $(CFG_MODULES) $(MODULES)
192         cat ibl_$(TARGET)/ibl_objs_template.inc | sed -e s/ENDIAN_TAG/$(IEXT)/g > ibl_$(TARGET)/ibl_objs.tmp
193         $(CC) -ppo $(MAINDEFS) -DENDIAN_TAG=$(IEXT) ibl_$(TARGET)/ibl_objs.tmp
194         $(CP) ibl_$(TARGET)/ibl_objs.pp ibl_$(TARGET)/ibl_objs.inc
195         $(LD) -o ibl_$(TARGET)/ibl_$(TARGET).out -m ibl_$(TARGET)/ibl_$(TARGET).$(IEXT).map  ibl_$(TARGET)/ibl.cmd $(RTLIBS)
196         $(CP) ibl_$(TARGET)/ibl_$(TARGET).out ibl_$(TARGET)/ibl_$(TARGET).$(IEXT).out
197         $(RM) -f ibl_$(TARGET)/ibl_obj.inc
199         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl.rmd ibl_$(TARGET)/ibl_$(TARGET).out
200         ../util/bconvert/bconvert64x -$(IEXT) ibl_le.b ibl.b
201         $(CP) ibl.b ibl_$(TARGET)
202         ../util/btoccs/b2i2c ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl.i2c.b
203         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.i2c.b ibl_$(TARGET)/ibl.i2c.$(IEXT).ccs
206 $(MODULES):
207         @echo making $@
208         make -C $(IBL_ROOT)/$@/$(ARCH)/make $@
210 $(CFG_MODULES):
211         @echo making $@ SPI_CFG=$(SPI_CFG) CDEFS=$(CDEFS) EXCLUDES=$(EXCLUDES)
212         make -C $(IBL_ROOT)/$@/$(ARCH)/make CDEFS='$(MAINDEFS) $(SPI_CFG)' $@
214 utils:
215 ifeq ($(HAS_SPI),1)
216 ifeq ($(HAS_INTERNAL_UTILS),1)
217         make -C $(IBL_ROOT)/util/spiWrite TARGET=$(TARGET) SPI_DEFS='$(SPI_DEFS)' MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
218         make -C $(IBL_ROOT)/util/spiConfig TARGET=$(TARGET) SPI_DEFS='$(SPI_DEFS)' MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
219 endif
220 endif
221         make -C $(IBL_ROOT)/util/btoccs
222         make -C $(IBL_ROOT)/util/romparse TARGET=$(TARGET)
223 ifeq ($(HAS_I2C),1)
224 ifeq ($(HAS_INTERNAL_UTILS),1)
225         make -C $(IBL_ROOT)/util/i2cRead  TARGET=$(TARGET) $(TARGET) 
226         make -C $(IBL_ROOT)/util/i2cWrite TARGET=$(TARGET) I2C_SIZE_BYTES=$(I2C_SIZE_BYTES) MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
227 endif
228         make -C $(IBL_ROOT)/util/i2cConfig $(TARGET) MAINDEFS='$(MAINDEFS) $(SPI_CFG)' 
229 endif
230         make -C $(IBL_ROOT)/util/bconvert
232 clean: $(CLEAN_MODULES) hwClean
233         
235 $(CLEAN_MODULES):
236         @echo cleaning $(subst clean_, ,$@)
237         make -C $(IBL_ROOT)/$(subst clean_,,$@)/$(ARCH)/make clean ARCH=c64x TARGET=$(TARGET)
239 hwClean:
240         @echo cleaning hw
241         make -C $(IBL_ROOT)/hw/$(ARCH)/make cleant ARCH=$(ARCH) TARGET=$(TARGET)
242         
243 cleant:
244         rm -rf ibl_$(TARGET)/ibl_$(TARGET).be.out
245         rm -rf ibl_$(TARGET)/ibl_$(TARGET).le.out
246         rm -rf ibl_$(TARGET)/ibl_$(TARGET).be.map
247         rm -rf ibl_$(TARGET)/ibl_$(TARGET).le.map
248         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.map
249         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.out
250         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.be.map
251         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.be.out
252         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.le.map
253         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.le.out
254         rm -rf ibl_$(TARGET)/ibl_$(TARGET).out
255         rm -rf ibl_$(TARGET)/ibl_$(TARGET).map
256         rm -rf ibl_$(TARGET)/ibl_le.b
257         rm -rf ibl_$(TARGET)/ibl.b
258         rm -rf ibl_$(TARGET)/ibl.i2c.b
259         rm -rf ibl_$(TARGET)/ibl.i2c.be.ccs
260         rm -rf ibl_$(TARGET)/ibl.i2c.le.ccs
261         rm -rf ibl_$(TARGET)/ibl_init.i2c.be.ccs
262         rm -rf ibl_$(TARGET)/ibl_init.i2c.le.ccs
263         rm -rf ibl_$(TARGET)/ibl_init.le.ccs
264         rm -rf ibl_$(TARGET)/ibl_init.be.ccs
265         rm -rf ibl_$(TARGET)/i2crom*.ccs
266         rm -rf ibl_$(TARGET)/i2crom*.dat
267         rm -rf ibl_$(TARGET)/i2crom*.bin
268         rm -rf ibl_$(TARGET)/i2crom*.map.pp
269         rm -rf ibl_$(TARGET)/ibl_init_objs.inc
270         rm -rf ibl_$(TARGET)/ibl_init_objs.pp
271         rm -rf ibl_$(TARGET)/ibl_init_symbols.inc
272         rm -rf ibl_$(TARGET)/ibl_objs.inc
273         rm -rf ibl_$(TARGET)/ibl_objs.pp
274         rm -rf ibl_$(TARGET)/ibl_objs.tmp
275         rm -rf ibl_$(TARGET)/spiRom*.dat
276         rm -rf ibl_$(TARGET)/spiRom*.map.pp
277