Merge branch 'nysh_multi_boot'
[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 (EXCLUDE_SPI, $(strip $(findstring EXCLUDE_SPI, $(MAINDEFS))))
68     HAS_SPI=0
69 endif
71 ifeq (EXCLUDE_I2C, $(strip $(findstring EXCLUDE_I2C, $(MAINDEFS))))
72     HAS_I2C=0
73 else 
74    HAS_I2C=1
75 endif
77 # The I2C creation options. The I2C map file is run through the C pre-processor to generate
78 # the desired I2C mapping. There are three possible configurations - an i2c which has
79 # both endians present, or an I2C with only one of the endians
81 I2C_BE_FILE=      '"ibl_$(TARGET)/ibl.i2c.be.ccs"'
82 I2C_LE_FILE=      '"ibl_$(TARGET)/ibl.i2c.le.ccs"'
83 I2C_INIT_BE_FILE= '"ibl_$(TARGET)/ibl_init.i2c.be.ccs"'
84 I2C_INIT_LE_FILE= '"ibl_$(TARGET)/ibl_init.i2c.le.ccs"'
86 I2C_DEFS= -DI2C_BUS_ADDR=$(I2C_BUS_ADDR)
87 I2C_DEFS+= -DI2C_MAP_ADDR=$(I2C_MAP_ADDR)
89 ifeq ($(I2CROM),both) 
90  I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
91  I2C_DEFS+= -DEXE_FILE_1=$(I2C_LE_FILE) 
92  I2C_DEFS+= -DPAD_FILE_ID_1=1 
93  I2C_DEFS+= -DEXE_FILE_2=$(I2C_BE_FILE) 
94  I2C_DEFS+= -DPAD_FILE_ID_2=2 
96  SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
97  SPI_CFG+= -DEXE_FILE_1=$(I2C_LE_FILE) 
98  SPI_CFG+= -DPAD_FILE_ID_1=1 
99  SPI_CFG+= -DEXE_FILE_2=$(I2C_BE_FILE) 
100  SPI_CFG+= -DPAD_FILE_ID_2=2 
102 else 
103  I2C_DEFS+= -DPAD_FILE_ID_1=1
104  I2C_DEFS+= -DPAD_FILE_ID_2=1
106  SPI_CFG+= -DPAD_FILE_ID_1=1
107  SPI_CFG+= -DPAD_FILE_ID_2=1
109  ifeq ($(I2CROM),little_endian)
110   I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
111   I2C_DEFS+= -DEXE_FILE_1=$(I2C_LE_FILE)
112   I2C_DEFS+= -DEXE_FILE_2='""'
114   SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_LE_FILE)
115   SPI_CFG+= -DEXE_FILE_1=$(I2C_LE_FILE)
116   SPI_CFG+= -DEXE_FILE_2='""'
118  else
119   I2C_DEFS+= -DINIT_EXE_FILE=$(I2C_INIT_BE_FILE)
120   I2C_DEFS+= -DEXE_FILE_1='""'
121   I2C_DEFS+= -DEXE_FILE_2=$(I2C_BE_FILE)
123   SPI_CFG+= -DINIT_EXE_FILE=$(I2C_INIT_BE_FILE)
124   SPI_CFG+= -DEXE_FILE_1='""'
125   SPI_CFG+= -DEXE_FILE_2=$(I2C_BE_FILE)
127  endif
128 endif
131 i2crom:
132         $(CC) -ppo -I../cfg/$(TARGET) $(I2C_DEFS) ibl_$(TARGET)/$@.map.pre
133         ../util/romparse/romparse $(COMPACT) -rom_base $(I2C_BUS_ADDR) ibl_$(TARGET)/$@.map.pp
134         $(CP) i2crom.ccs ibl_$(TARGET)/$@.ccs
135         $(CP) i2crom.ccs ibl_$(TARGET)/$@.dat
136         $(RM) i2crom.ccs ibl_le.b ibl.b
138 spiRom:
139         @echo Making SPI ROM
140         $(CC) -ppo -I../cfg/$(TARGET) $(SPI_CFG) ibl_$(TARGET)/$@.map.pre
141         ../util/romparse/romparse $(COMPACT) -fill 0xff -rom_base 0 ibl_$(TARGET)/$@.map.pp
142         $(CP) i2crom.ccs ibl_$(TARGET)/$@.ccs
143         $(CP) i2crom.ccs ibl_$(TARGET)/$@.dat
149 # Target compare checks if the iblInit is compiled the same for both endians
150 compare:
151         @echo -
152         @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 '
153         @echo -
155 # For the init code a raw image is created as well as the i2c code to verify
156 # endian independent code is generated. The symbols required for linking
157 # the full application are then extracted
158 iblInit: $(CFG_MODULES) $(MODULES)
159         cat ibl_$(TARGET)/ibl_init_objs_template.inc | sed -e s/ENDIAN_TAG/$(IEXT)/g > ibl_$(TARGET)/ibl_init_objs.tmp
160         $(CC) -ppo $(MAINDEFS) -DENDIAN_TAG=$(IEXT) ibl_$(TARGET)/ibl_init_objs.tmp
161         $(CP) ibl_$(TARGET)/ibl_init_objs.pp ibl_$(TARGET)/ibl_init_objs.inc
162         $(LD) -o ibl_$(TARGET)/ibl_$(TARGET)_init.out -m ibl_$(TARGET)/ibl_$(TARGET)_init.map ibl_$(TARGET)/ibl_init.cmd $(RTLIBS)
163         $(CP) ibl_$(TARGET)/ibl_$(TARGET)_init.out ibl_$(TARGET)/ibl_$(TARGET)_init.$(IEXT).out
164         $(RM) -f ibl_$(TARGET)/ibl_init_obj.inc
166         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl_init_image.rmd ibl_$(TARGET)/ibl_$(TARGET)_init.out
167         $(CP) ibl_le.b ibl_$(TARGET)/ibl.b
168         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl_init.$(IEXT).ccs
170         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl_init.rmd ibl_$(TARGET)/ibl_$(TARGET)_init.out
171         ../util/bconvert/bconvert64x -$(IEXT) ibl_le.b ibl.b
172         $(CP) ibl.b ibl_$(TARGET)
173         ../util/btoccs/b2i2c ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl.i2c.b
174         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.i2c.b ibl_$(TARGET)/ibl_init.i2c.$(IEXT).ccs
176         sed -e 's/\\r//' ../util/symExtract/symExtract > ../util/symExtract/symExtract_unix
177         bash ../util/symExtract/symExtract_unix ibl_$(TARGET)/ibl_$(TARGET)_init.map ibl_$(TARGET)/ibl_init_symbols.inc $(COMMON_SYMBOLS)
178         rm -f ../util/symExtract/symExtract_unix
180         
181 iblMain: iblInit $(CFG_MODULES) $(MODULES)
182         cat ibl_$(TARGET)/ibl_objs_template.inc | sed -e s/ENDIAN_TAG/$(IEXT)/g > ibl_$(TARGET)/ibl_objs.tmp
183         $(CC) -ppo $(MAINDEFS) -DENDIAN_TAG=$(IEXT) ibl_$(TARGET)/ibl_objs.tmp
184         $(CP) ibl_$(TARGET)/ibl_objs.pp ibl_$(TARGET)/ibl_objs.inc
185         $(LD) -o ibl_$(TARGET)/ibl_$(TARGET).out -m ibl_$(TARGET)/ibl_$(TARGET).$(IEXT).map  ibl_$(TARGET)/ibl.cmd $(RTLIBS)
186         $(CP) ibl_$(TARGET)/ibl_$(TARGET).out ibl_$(TARGET)/ibl_$(TARGET).$(IEXT).out
187         $(RM) -f ibl_$(TARGET)/ibl_obj.inc
189         hex6x $(HEX_OPT) ibl_$(TARGET)/ibl.rmd ibl_$(TARGET)/ibl_$(TARGET).out
190         ../util/bconvert/bconvert64x -$(IEXT) ibl_le.b ibl.b
191         $(CP) ibl.b ibl_$(TARGET)
192         ../util/btoccs/b2i2c ibl_$(TARGET)/ibl.b ibl_$(TARGET)/ibl.i2c.b
193         ../util/btoccs/b2ccs ibl_$(TARGET)/ibl.i2c.b ibl_$(TARGET)/ibl.i2c.$(IEXT).ccs
196 $(MODULES):
197         @echo making $@
198         make -C $(IBL_ROOT)/$@/$(ARCH)/make $@
200 $(CFG_MODULES):
201         @echo making $@ SPI_CFG=$(SPI_CFG) CDEFS=$(CDEFS) EXCLUDES=$(EXCLUDES)
202         make -C $(IBL_ROOT)/$@/$(ARCH)/make CDEFS='$(MAINDEFS) $(SPI_CFG)' $@
204 utils:
205 ifeq ($(HAS_SPI),1)
206         make -C $(IBL_ROOT)/util/spiWrite TARGET=$(TARGET) SPI_DEFS='$(SPI_DEFS)' MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
207         make -C $(IBL_ROOT)/util/spiConfig TARGET=$(TARGET) SPI_DEFS='$(SPI_DEFS)' MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
208 endif
209         make -C $(IBL_ROOT)/util/btoccs
210         make -C $(IBL_ROOT)/util/romparse TARGET=$(TARGET)
211 ifeq ($(HAS_I2C),1)
212         make -C $(IBL_ROOT)/util/i2cRead  TARGET=$(TARGET) $(TARGET) 
213         make -C $(IBL_ROOT)/util/i2cWrite TARGET=$(TARGET) I2C_SIZE_BYTES=$(I2C_SIZE_BYTES) MAINDEFS='$(MAINDEFS) $(SPI_CFG)' $(TARGET)
214         make -C $(IBL_ROOT)/util/i2cConfig $(TARGET) MAINDEFS='$(MAINDEFS) $(SPI_CFG)' 
215 endif
216         make -C $(IBL_ROOT)/util/bconvert
218 clean: $(CLEAN_MODULES) hwClean
219         
221 $(CLEAN_MODULES):
222         @echo cleaning $(subst clean_, ,$@)
223         make -C $(IBL_ROOT)/$(subst clean_,,$@)/$(ARCH)/make clean ARCH=c64x TARGET=$(TARGET)
225 hwClean:
226         @echo cleaning hw
227         make -C $(IBL_ROOT)/hw/$(ARCH)/make cleant ARCH=$(ARCH) TARGET=$(TARGET)
228         
229 cleant:
230         rm -rf ibl_$(TARGET)/ibl_$(TARGET).be.out
231         rm -rf ibl_$(TARGET)/ibl_$(TARGET).le.out
232         rm -rf ibl_$(TARGET)/ibl_$(TARGET).be.map
233         rm -rf ibl_$(TARGET)/ibl_$(TARGET).le.map
234         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.map
235         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.out
236         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.be.map
237         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.be.out
238         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.le.map
239         rm -rf ibl_$(TARGET)/ibl_$(TARGET)_init.le.out
240         rm -rf ibl_$(TARGET)/ibl_$(TARGET).out
241         rm -rf ibl_$(TARGET)/ibl_$(TARGET).map
242         rm -rf ibl_$(TARGET)/ibl_le.b
243         rm -rf ibl_$(TARGET)/ibl.b
244         rm -rf ibl_$(TARGET)/ibl.i2c.b
245         rm -rf ibl_$(TARGET)/ibl.i2c.be.ccs
246         rm -rf ibl_$(TARGET)/ibl.i2c.le.ccs
247         rm -rf ibl_$(TARGET)/ibl_init.i2c.be.ccs
248         rm -rf ibl_$(TARGET)/ibl_init.i2c.le.ccs
249         rm -rf ibl_$(TARGET)/ibl_init.le.ccs
250         rm -rf ibl_$(TARGET)/ibl_init.be.ccs
251         rm -rf ibl_$(TARGET)/i2crom.ccs
252         rm -rf ibl_$(TARGET)/i2crom.dat
253         rm -rf ibl_$(TARGET)/i2crom_0x50.dat
254         rm -rf ibl_$(TARGET)/i2crom_0x51.dat
255         rm -rf ibl_$(TARGET)/i2crom.map.pp
256         rm -rf ibl_$(TARGET)/ibl_init_objs.inc
257         rm -rf ibl_$(TARGET)/ibl_init_objs.pp
258         rm -rf ibl_$(TARGET)/ibl_init_symbols.inc
259         rm -rf ibl_$(TARGET)/ibl_objs.inc
260         rm -rf ibl_$(TARGET)/ibl_objs.pp
261         rm -rf ibl_$(TARGET)/ibl_objs.tmp
262         rm -rf ibl_$(TARGET)/spiRom.dat
263         rm -rf ibl_$(TARGET)/spiRom.map.pp
264