# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved.
# This component and the accompanying materials are made available
# under the terms of "Eclipse Public License v1.0"
# which accompanies this distribution, and is available
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
#
# Initial Contributors:
# Nokia Corporation - initial contribution.
#
# Contributors:
#
# Description:
# ne1_tb_restricted_coreldr.flm
# #  NB! LINKBASE :  Code execute address also set coreldr.lnk file 
# #  MUST REFLECT CORELOADER ADDRESS RELOCATION IN BOTH FILES!!
# 
#

ifeq ($($(NAME)_ne1_tb_resricted_coreldr_flm),)
$(NAME)_ne1_tb_resricted_coreldr_flm := 1

## THESE MACROS NEED TO BE SET EXPLICITLY TO TRUE OR BLANK

## Use this macro if it is required to use the MMU
## if the MMU is not require either comment it out or set it FALSE
USE_MMU := TRUE
  
# This macro enables benchmarking code. Comment out or set FALSE if not required
WRITE_TIMINGS :=
# Timer is not implemented for Naviengine. Do not enable!

## This macro causes the page tables to be output. Comment out or set FALSE if not required
## If this option is selected then the MMU code will be enabled
DUMP_PAGE_TABLES :=
# Page tables cannot be dumped on Naviengine due to the NANDController used. Do not enable!

# This macro enables the MMU enabled version of the coreldr to call RestartAuxiliaryCores
# before it runs the core image.  This function should be defined in the variant, to 
# restart the auxiliary cores, which it should have paused on startup.
RUNS_WITH_SMP := TRUE

## Make sure all 3 macros are either TRUE or FALSE
# Enforce USE_MMU if page table is to be dumped
ifeq "$(DUMP_PAGE_TABLES)" "TRUE"
  USE_MMU := TRUE
else
  DUMP_PAGE_TABLES := FALSE
endif

ifneq "$(USE_MMU)" "TRUE"
  USE_MMU := FALSE
endif

ifneq "$(WRITE_TIMINGS)" "TRUE"
  WRITE_TIMINGS := FALSE
endif

# Set the directories; based on calling bld.inf
GENSRCDIR := $(EXTENSION_ROOT)/../../../kernelhwsrv/kerneltest/e32utils/nandboot/coreldr
# Generic drivers
BLSRCDIR := $(EXTENSION_ROOT)/../../../kernelhwsrv/kernel/eka/drivers/unistore2/srca/XSR/UTIL/ONBL2
XSRSRCDIR1 := $(EXTENSION_ROOT)/../../../kernelhwsrv/kernel/eka/drivers/unistore2/srca/XSR/OAM/OSLess
XSRSRCDIR2 := $(EXTENSION_ROOT)/../../../kernelhwsrv/kernel/eka/drivers/unistore2/srca/XSR/LLD/DNandO
# Coreloader ASM...
SPECSRCDIR := $(EXTENSION_ROOT)/../navienginebsp/ne1_tb/nandboot
# PAM - Platform specific Version
SPECXSRSRCDIR := $(EXTENSION_ROOT)/pam
SPECXSRSRCDIR1 := $(EXTENSION_ROOT)/lld

# Platform Variant includes
VARIANTINC := $(INC_PATH)/ne1_tb
VARIANTINC2 := $(EXTENSION_ROOT)/../navienginebsp/ne1_tb/bootstrap
VARIANTINC3 := $(EXTENSION_ROOT)/../navienginebsp/ne1_tb/nand  $(EXTENSION_ROOT)/../navienginebsp/naviengine_assp  $(INC_PATH)/assp/naviengine/$(MEMMODEL)

# Generic driver file includes
GENINC1 := $(INC_PATH) $(EPOCROOT)/epoc32/include
GENDRIVERINC := $(INC_PATH)/drivers
GENINC2 := $(INC_PATH)/drivers/unistore2 $(INC_PATH)/memmodel/epoc $(INC_PATH)/kernel  $(INC_PATH)/kernel/arm $(INC_PATH)/nkern $(INC_PATH)/nkern/arm
GENXSRINC := $(EXTENSION_ROOT)/../../../kernelhwsrv/kernel/eka/drivers/unistore2/srca/XSR/INC
GENINCPATH:= $(GENSRCDIR) $(SPECSRCDIR) $(XSRSRCDIR1) $(XSRSRCDIR2) $(SPECXSRSRCDIR) $(SPECXSRSRCDIR1) $(VARIANTINC) $(VARIANTINC2) $(VARIANTINC3) $(GENINC1) $(GENDRIVERINC) $(GENINC2) $(GENINC3) $(GENINC4) $(GENXSRINC)


# Set the source/include/target directories

# epoc32 folder for exported header files
EPOCINCDIR := $(INC_PATH)/ne1_tb

# Build directory
BUILDLOC := $(EPOCBLD)/ne1_tb_restricted_coreldr_flm/$(PLATFORM_PATH)

# Set the target name
TARGETDIR := $(EPOCROOT)/epoc32/release/$(PLATFORM_PATH)
BINTARGET := $(TARGETDIR)/$(NAME).bin
TMPTARGET := $(BUILDLOC)/$(NAME).elf

# Rules
vpath %.s . $(SPECSRCDIR) $(SRCDIR)
vpath %.inc . $(SPECSRCDIR) $(EPOCINCDIR)
vpath %.ginc . $(BUILDLOC)


# from base/e32/include/drivers/...
VHEADERS := nanddevice.h
# the following .inc files get built as part of the process
BUILTINCLUDES := nanddevice.inc config.inc
BUILTINCLUDES2 := nand_plat.inc

#
ASMSOURCE := coreldrasm.s
GENCPPSOURCE := inflate.cpp
BLCPPSOURCE := ONbl2.cpp
XSRCPPSOURCE1 := OSLessOAM.cpp
SPECXSRCPPSOURCE := pam.cpp
SPECXSRCPPSOURCE1 := pnl.cpp  

XSRLIB := $(EPOCROOT)/epoc32/release/armv5/$(CFG)/nbl2.lib

# Only link in the MMU stuff if required
GENASMSOURCE :=
ifeq "$(USE_MMU)" "TRUE"
  GENASMSOURCE := coreldrmmu.s
endif

HEADERS := 
SPECHEADERS := nand_plat.h

## Address at which coreloader binary is loaded and then started from
#
# On NaviEngine this number is base of ram + 208MB (permitting 208MB core images)
# this number is pretty arbitrary
# if necessary as long as the corresponding change is also made to
# KCoreLoaderAddress in variant_bootstrap.inc
#
LINKBASE := 0x8D000000

# Build up logical TRUE defines
ASM_TRUE_MACROS :=

ifeq "$(USE_MMU)" "TRUE"
  ASM_TRUE_MACROS := $(ASM_TRUE_MACROS) USE_MMU
endif 

ifeq "$(WRITE_TIMINGS)" "TRUE"
  ASM_TRUE_MACROS := $(ASM_TRUE_MACROS) WRITE_TIMINGS
endif 

ifeq "$(DUMP_PAGE_TABLES)" "TRUE"
  ASM_TRUE_MACROS := $(ASM_TRUE_MACROS) DUMP_PAGE_TABLES
endif 

ifeq "$(RUNS_WITH_SMP)" "TRUE"
  ASM_TRUE_MACROS := $(ASM_TRUE_MACROS) RUNS_WITH_SMP
endif

# Build up logical FALSE defines
ASM_FALSE_MACROS :=

ifeq "$(USE_MMU)" "FALSE"
  ASM_FALSE_MACROS := $(ASM_FALSE_MACROS) USE_MMU
endif 

ifeq "$(WRITE_TIMINGS)" "FALSE"
  ASM_FALSE_MACROS := $(ASM_FALSE_MACROS) WRITE_TIMINGS
endif

ifeq "$(DUMP_PAGE_TABLES)" "FALSE"
  ASM_FALSE_MACROS := $(ASM_FALSE_MACROS) DUMP_PAGE_TABLES
endif 


# Arm RVCT tools
ASM_TRUE_MACROS := $(ASM_TRUE_MACROS) USE_CXSF

OBJEXT := o
INCEXT := inc

ARMCCFLAGS := --arm -c -Otime --cpp --enum_is_int
ARMCCFLAGS := $(ARMCCFLAGS) $(foreach dir,$(GENINCPATH),$(join -I, $(dir)))
ARMCCFLAGS := $(ARMCCFLAGS) -DEKA2
ARMCCFLAGS := $(ARMCCFLAGS) -DXSR_NBL2 -DREAL_TARGET -DDEFERED_CHK -DSYMBIAN_SUPPORT_UNISTORE2

ARMCCFLAGS := $(ARMCCFLAGS) --preinclude $(EPOCROOT)/epoc32/include/rvct/rvct.h

ifeq "$(CFG)" "UDEB"
ARMCCFLAGS := $(ARMCCFLAGS) -D_DEBUG
endif

ASM_TRUE_MACRO_CMD := $(foreach macro,$(ASM_TRUE_MACROS),--predefine "$(macro) SETL {TRUE}")
ASM_FALSE_MACRO_CMD := $(foreach macro,$(ASM_FALSE_MACROS),--predefine "$(macro) SETL {FALSE}")
ASM_LINKBASE_MACRO := --predefine "_LINKBASE_ SETA $(LINKBASE)"

AFLAGS := -g --keep $(ASM_TRUE_MACRO_CMD) $(ASM_FALSE_MACRO_CMD) $(ASM_LINKBASE_MACRO) -I$(BUILDLOC) $(foreach dir,$(GENINCPATH),$(join -I, $(dir)))
LFLAGS := --entry BootEntry --ro-base $(LINKBASE) --FIRST BootEntry --map
SYMOPT := --symdefs
ASMTYP := ARMASM
LINKFILE :=

# include base commonly used functions
include $(EPOCROOT)/epoc32/tools/makefile_templates/base/base_rvct_common.mk


# Header processing
FULLHEADERS := $(addprefix $(GENSRCDIR)/,$(HEADERS))
FULLSPECHEADERS := $(addprefix $(VARIANTINC)/,$(SPECHEADERS))

FULLVHEADERS := $(addprefix $(GENDRIVERINC)/,$(VHEADERS))
FULLBUILTINCLUDES := $(addprefix $(BUILDLOC)/,$(BUILTINCLUDES))
# do h2inc
$(eval $(call base__h2inc,$(FULLBUILTINCLUDES),$(FULLVHEADERS)))

FULLVHEADERS2 := $(addprefix $(VARIANTINC)/,$(SPECHEADERS))
FULLBUILTINCLUDES2 := $(addprefix $(BUILDLOC)/,$(BUILTINCLUDES2))
# do h2inc
$(eval $(call base__h2inc,$(FULLBUILTINCLUDES2),$(FULLVHEADERS2)))

# object names
GENCPPOBJECTS := $(foreach f,$(GENCPPSOURCE),$(basename $(f)).$(OBJEXT))
FULLGENCPPOBJECTS := $(addprefix $(BUILDLOC)/,$(GENCPPOBJECTS))

BLCPPOBJECTS := $(foreach f,$(BLCPPSOURCE),$(basename $(f)).$(OBJEXT))
FULLBLCPPOBJECTS := $(addprefix $(BUILDLOC)/,$(BLCPPOBJECTS))

XSRCPPOBJECTS1 := $(foreach f,$(XSRCPPSOURCE1),$(basename $(f)).$(OBJEXT))
FULLXSRCPPOBJECTS1 := $(addprefix $(BUILDLOC)/,$(XSRCPPOBJECTS1))

SPECXSRCPPOBJECTS := $(foreach f,$(SPECXSRCPPSOURCE),$(basename $(f)).$(OBJEXT))
FULLSPECXSRCPPOBJECTS := $(addprefix $(BUILDLOC)/,$(SPECXSRCPPOBJECTS))

SPECXSRCPPOBJECTS1 := $(foreach f,$(SPECXSRCPPSOURCE1),$(basename $(f)).$(OBJEXT))
FULLSPECXSRCPPOBJECTS1 := $(addprefix $(BUILDLOC)/,$(SPECXSRCPPOBJECTS1))

ASMOBJECTS := $(foreach f,$(ASMSOURCE),$(basename $(f)).$(OBJEXT))
FULLASMOBJECTS := $(addprefix $(BUILDLOC)/,$(ASMOBJECTS))

GENASMOBJECTS := $(foreach f,$(GENASMSOURCE),$(basename $(f)).$(OBJEXT))
FULLGENASMOBJECTS := $(addprefix $(BUILDLOC)/,$(GENASMOBJECTS))

FULLOBJECTS := $(FULLASMOBJECTS) $(FULLGENASMOBJECTS) $(FULLGENCPPOBJECTS) $(FULLBLCPPOBJECTS) $(FULLXSRCPPOBJECTS1) $(FULLSPECXSRCPPOBJECTS) $(FULLSPECXSRCPPOBJECTS1) $(XSRLIB)


FULLINCLUDES:= $(addprefix $(SPECSRCDIR)/,$(INCLUDES))
FULLPLATINCLUDES:= $(addprefix $(PLATSRCDIR)/,$(PLATINCLUDES))
FULLGENINCLUDES:= $(addprefix $(GENSRCDIR)/,$(GENINCLUDES))
FULLBLDINCLUDES:= $(addprefix $(H2BLDDIR)/,$(BLDINCLUDES))


# Link
$(eval $(call base__link,$(TMPTARGET),$(FULLOBJECTS)))

# Strip
$(eval $(call base__strip,$(BINTARGET),$(TMPTARGET)))

# CPP objects
$(eval $(call base__compile,$(FULLGENCPPOBJECTS),$(BUILDLOC)/%.$(OBJEXT),$(GENSRCDIR)/%.cpp $(FULLHEADERS) $(FULLSPECHEADERS)))

$(eval $(call base__compile,$(FULLBLCPPOBJECTS),$(BUILDLOC)/%.$(OBJEXT),$(BLSRCDIR)/%.cpp $(FULLHEADERS) $(FULLSPECHEADERS)))

$(eval $(call base__compile,$(FULLXSRCPPOBJECTS1),$(BUILDLOC)/%.$(OBJEXT),$(XSRSRCDIR1)/%.cpp $(FULLHEADERS) $(FULLSPECHEADERS)))

$(eval $(call base__compile,$(FULLSPECXSRCPPOBJECTS),$(BUILDLOC)/%.$(OBJEXT),$(SPECXSRSRCDIR)/%.cpp $(FULLHEADERS) $(FULLSPECHEADERS)))

$(eval $(call base__compile,$(FULLSPECXSRCPPOBJECTS1),$(BUILDLOC)/%.$(OBJEXT),$(SPECXSRSRCDIR1)/%.cpp $(FULLHEADERS) $(FULLSPECHEADERS)))

# Asm objects
$(eval $(call base__asm,$(FULLGENASMOBJECTS),$(BUILDLOC)/%.$(OBJEXT),$(GENSRCDIR)/$(GENASMSOURCE) $(FULLINCLUDES) $(FULLBUILTINCLUDES) $(FULLBUILTINCLUDES2) $(FULLBUILTINCLUDES3) $(FULLDRIVERINCLUDES) $(FULLARMINCLUDES) $(FULLBLDINCLUDES) $(FULLGENINCLUDES) $(FULLPLATINCLUDES)))

$(eval $(call base__asm,$(FULLASMOBJECTS),$(BUILDLOC)/%.$(OBJEXT),$(SPECSRCDIR)/$(ASMSOURCE) $(FULLINCLUDES) $(FULLBUILTINCLUDES) $(FULLBUILTINCLUDES2) $(FULLBLDINCLUDES) $(FULLGENINCLUDES) $(FULLPLATINCLUDES)))

#
TARGET :: $(TARGETDIR) $(BUILDLOC) $(BINTARGET)

# --what to show releasables
$(eval $(call whatmacro,$(BINTARGET),USERFLM))
# Create directory
CREATABLEPATHS := $(TARGETDIR) $(BUILDLOC)
$(call makepath,$(CREATABLEPATHS))
# Clean up
$(eval $(call GenerateStandardCleanTarget,$(CLEANTARGETS),$(BUILDLOC)))

endif
