# linux/arch/mips/zboot/tc90400/Makefile : Reference No : 43PJ292-20050906-QFP_BOARD01-000
#
# Internal driver for TC90400
#
#  (c) Copyright TOSHIBA CORPORATION SEMICONDUCTOR COMPANY  2003-2005 
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
#

# arch/mips/zboot/pb1xxx/Makefile
# 
# Makefile for Alchemy Semiconductor Pb1[015]00 boards.
# All of the boot loader code was derived from the ppc
# boot code.
#
# Copyright 2001,2002 MontaVista Software Inc.
#
# Author: Mark A. Greer
#	  mgreer@mvista.com
# Ported and modified for mips support by 
# Pete Popov <ppopov@mvista.com>
#
# 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.

.c.s:
	$(CC) $(CFLAGS) -S -o $*.s $<
.s.o:
	$(AS) -o $*.o $<
.c.o:
	$(CC) $(CFLAGS) -D__BOOTER__ -c -o $*.o $<
.S.s:
	$(CPP) $(AFLAGS) -o $*.o $<
.S.o:
	$(CC) $(AFLAGS) -c -o $*.o $<

#########################################################################
# Define BOOT=1 if you want to place the kernel image in NOR FLASH
# Define BOOT=2 if you want to place the kernel image in NAND FLASH
ifdef CONFIG_MTD_NAND_TC90400_ZBOOT
BOOT=2
else
BOOT=1
endif

BNAME=tc90400

# START BOARD SPECIFIC VARIABLES
ifdef CONFIG_TOSHIBA_TC90400GDRS
# These two variables control where the zImage is 
# stored in flash and loaded in memory. 
ifeq ($(BOOT), 1)
# We're booting from NOR FLASH, use standard load addresses
FLASH_LOAD_ADDR = 0xbfc00000
ADJUST_VMA = 0x3ec00000
else
# We're booting from NAND FLASH, IPL copies everything from NAND
# to FLASH_LOAD_ADDR. From here we behave like booting from NOR
FLASH_LOAD_ADDR = 0x81400000
# ADJUST_VMA = FLASH_LOAD_ADDR - RAM_RUN_ADDR
ADJUST_VMA = 0x00400000
endif
# This one must match the LOADADDR in arch/mips/Makefile!
LOADADDR=0x81800000
# These two variables control where the zImage is stored
# in flash and loaded in memory.  It only controls how the srec
# file is generated, the code is the same.
# FLASH_LOAD_ADDR as set above
RAM_RUN_ADDR = 0x81000000
# These two variables specify the free ram region
# that can be used for temporary malloc area
AVAIL_RAM_START=0x80c00000
AVAIL_RAM_END=0x81000000
endif

ifdef CONFIG_TOSHIBA_TC90400QFP_BOARD01
# These two variables control where the zImage is 
# stored in flash and loaded in memory. 
ifeq ($(BOOT), 1)
ifdef CONFIG_TOSHIBA_TC90400_PRODUCT
# We're booting from NOR FLASH, use standard load addresses
FLASH_LOAD_ADDR = 0xbfd80000
# ADJUST_VMA = FLASH_LOAD_ADDR - RAM_RUN_ADDR
ADJUST_VMA = 0x3ed80000
else
# We're booting from NOR FLASH, use standard load addresses
FLASH_LOAD_ADDR = 0xbfc00000
# ADJUST_VMA = FLASH_LOAD_ADDR - RAM_RUN_ADDR
ADJUST_VMA = 0x3ec00000
endif
# Dual Boot Master IPL Address
MASTER_IPL_ADDR=0xbfd80000
endif
# This one must match the LOADADDR in arch/mips/Makefile!
LOADADDR=0x81400000
# These two variables control where the zImage is stored
# in flash and loaded in memory.  It only controls how the srec
# file is generated, the code is the same.
# FLASH_LOAD_ADDR as set above
RAM_RUN_ADDR = 0x81000000
# These two variables specify the free ram region
# that can be used for temporary malloc area
AVAIL_RAM_START=0x80c00000
AVAIL_RAM_END=0x81000000
endif

# END BOARD SPECIFIC VARIABLES
#########################################################################

OBJECTS := head.o ../common/misc-common.o ../common/misc-simple.o \
	../common/tc90400_uart.o ../common/string.o ../common/ctype.o
LIBS := ../lib/zlib.a

ENTRY := ../utils/entry
OFFSET := ../utils/offset
SIZE := ../utils/size

LD_ARGS := -T ../ld.script -Ttext $(RAM_RUN_ADDR) -Bstatic
ifdef CONFIG_CPU_LITTLE_ENDIAN
OBJCOPY_ARGS = -O elf32-tradlittlemips
else
OBJCOPY_ARGS = -O elf32-tradbigmips
endif

all: zImage

clean:
	rm -rf *.o vmlinux* zvmlinux.* ../images/*.srec ../images/*.bin

head.o: head.S $(TOPDIR)/vmlinux
	$(CC) $(AFLAGS) \
	-DFLASH_LOAD_ADDR=$(FLASH_LOAD_ADDR) \
	-DMASTER_IPL_ADDR=$(MASTER_IPL_ADDR) \
	-DKERNEL_ENTRY=$(shell sh $(ENTRY) $(NM) $(TOPDIR)/vmlinux ) \
	-DBOOT=$(BOOT) \
	-c -o $*.o $<

../common/misc-simple.o:
	$(CC) $(CFLAGS) -DINITRD_OFFSET=0 -DINITRD_SIZE=0 -DZIMAGE_OFFSET=0 \
		-DAVAIL_RAM_START=$(AVAIL_RAM_START) \
		-DAVAIL_RAM_END=$(AVAIL_RAM_END) \
		-DLOADADDR=$(LOADADDR) \
		-DZIMAGE_SIZE=0 -c -o $@ $*.c

zvmlinux: $(OBJECTS) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
	$(OBJCOPY) \
		--add-section=.image=../images/vmlinux.gz \
		--set-section-flags=.image=contents,alloc,load,readonly,data \
		../common/dummy.o image.o
	$(LD) $(LD_ARGS) -o $@ $(OBJECTS) image.o $(LIBS)
	$(OBJCOPY) $(OBJCOPY_ARGS) $@ $@ -R .comment -R .stab -R .stabstr \
		-R .initrd -R .sysmap

# Here we manipulate the image in order to get it the necessary
# srecord file we need.
zImage: zvmlinux
	mv zvmlinux ../images/zImage.$(BNAME)
	$(OBJCOPY) -O srec --adjust-vma $(ADJUST_VMA) \
	        ../images/zImage.$(BNAME) ../images/$(BNAME).srec
	$(OBJCOPY) -O binary ../images/zImage.$(BNAME) ../images/$(BNAME).bin
	rm -rf config
	@echo "FLASH_LOAD_ADDR = $(FLASH_LOAD_ADDR)" >> config

zImage.flash: zImage
	$(OBJCOPY) -O srec --adjust-vma $(ADJUST_VMA) \
		../images/zImage.$(BNAME) ../images/$(BNAME).flash.srec

include $(TOPDIR)/Rules.make
