From 6c34c1fa23c080daaf138bfaf232ee03c4a19217 Mon Sep 17 00:00:00 2001
From: Thomas Chou <thomas@wytron.com.tw>
Date: Tue, 22 Jan 2008 12:17:11 +0800
Subject: [PATCH] nios2: build systems without cfi flash

As cfi flash and romfs are not required when we run initramfs,the
dependency of cfi flash is cleaned.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 linux-2.6.x/arch/nios2nommu/kernel/asm-offsets.c   |    2 --
 linux-2.6.x/arch/nios2nommu/kernel/setup.c         |   10 ++++++++++
 linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S   |    4 ++++
 .../arch/nios2nommu/scripts/gen_nios2_system.h.pl  |    6 +++---
 linux-2.6.x/arch/nios2nommu/scripts/hwselect.pl    |    4 ++--
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/linux-2.6.x/arch/nios2nommu/kernel/asm-offsets.c b/linux-2.6.x/arch/nios2nommu/kernel/asm-offsets.c
index 242ca9f..a563515 100644
--- a/linux-2.6.x/arch/nios2nommu/kernel/asm-offsets.c
+++ b/linux-2.6.x/arch/nios2nommu/kernel/asm-offsets.c
@@ -140,8 +140,6 @@ int main(void)
 	/* the romdisk placement in the flash */
 	DEFINE(LINUX_ROMFS_START, na_flash_kernel+0x200000);
 	DEFINE(LINUX_ROMFS_END, na_flash_kernel_end);
-#else
-#error Sorry,you dont have na_flash_kernel or na_flash_kernel_end defined in the core.
 #endif
 	
 #if defined(nasys_program_mem) && defined(nasys_program_mem_end)
diff --git a/linux-2.6.x/arch/nios2nommu/kernel/setup.c b/linux-2.6.x/arch/nios2nommu/kernel/setup.c
index 98a8008..c772f79 100644
--- a/linux-2.6.x/arch/nios2nommu/kernel/setup.c
+++ b/linux-2.6.x/arch/nios2nommu/kernel/setup.c
@@ -233,6 +233,7 @@ void setup_arch(char **cmdline_p)
 
 	/* now read the hwaddr of the ethernet --wentao*/
 
+#if defined (na_flash_kernel)
     #if 1                                                   //;dgt2;
 //    #if defined (nasys_am29lv065d_flash_0)                //;dgt;
       {                                                     //;dgt;
@@ -291,6 +292,15 @@ void setup_arch(char **cmdline_p)
 		printk("Ethernet hardware address:Clearing invalid bit #0\n");
 		excalibur_enet_hwaddr_array[0] ^= (unsigned char)1;
 	}
+#else
+	excalibur_enet_hwaddr[0] = 0x00;
+	excalibur_enet_hwaddr[1] = 0x07;
+	excalibur_enet_hwaddr[2] = 0xed;
+	excalibur_enet_hwaddr[3] = 0x0a;
+	excalibur_enet_hwaddr[4] = 0x03;
+	excalibur_enet_hwaddr[5] = 0x00;
+#endif /* defined na_flash_kernel */
+
 	excalibur_enet_hwaddr=excalibur_enet_hwaddr_array;
 #ifdef DEBUG
 	printk("Setup the hardware addr for ethernet\n\t %02x %02x %02x %02x %02x %02x\n",
diff --git a/linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S b/linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S
index e6486db..6b2a724 100644
--- a/linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S
+++ b/linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S
@@ -9,7 +9,9 @@ ENTRY(_start)	/* Defined in head.S */
 MEMORY {
 	ram	: ORIGIN = nasys_program_mem, LENGTH = nasys_program_mem_size
 	eram	: ORIGIN = nasys_program_mem_end, LENGTH = 0
+#if defined(na_flash_kernel)
 	romfs	: ORIGIN = na_flash_kernel + 0x200000, LENGTH = na_flash_kernel_size - 0x200000
+#endif
 }
 
 jiffies = jiffies_64;
@@ -168,12 +170,14 @@ SECTIONS
 		_ramend = . ;
 	} > eram
 
+#if defined(na_flash_kernel)
 	.romfs.data :
 	{
 	    _romfs = . ; 
 	    *(.romfs.data) ; 
 	    _romfs_end = . ; 
 	} > romfs
+#endif
 	
  /* Sections to be discarded */
   /DISCARD/ : {
diff --git a/linux-2.6.x/arch/nios2nommu/scripts/gen_nios2_system.h.pl b/linux-2.6.x/arch/nios2nommu/scripts/gen_nios2_system.h.pl
index 1855cbf..4394c74 100644
--- a/linux-2.6.x/arch/nios2nommu/scripts/gen_nios2_system.h.pl
+++ b/linux-2.6.x/arch/nios2nommu/scripts/gen_nios2_system.h.pl
@@ -16,7 +16,7 @@ my $target_cpu;
 my $exec_location;
 my $upload_location;
 
-if (scalar (@ARGV) != 3) {
+if (scalar (@ARGV) < 2) {
 	print STDERR "ERROR: Invalid number of parameters.\n";
 	print ("#error Invalid number of parameters.\n");
 	exit;
@@ -75,7 +75,7 @@ if (! $exec_module) {
 }
 
 my $upload_module = $system->getModule ($upload_location);
-if (! $upload_module) {
+if ($upload_location && ! $upload_module) {
 	print STDERR "ERROR: $upload_location is not a valid module in the system: " . $system->getName() . ".\n";
 	print "#error $upload_location is not a valid module in system: " . $system->getName () . ".\n";
 	exit 1;
@@ -251,7 +251,7 @@ printf ("#define %-33s %30s\n",
 	
 print "\n";
 
-if ($upload_location eq "flash_kernel") {
+if (!$upload_location || ($upload_location eq "flash_kernel")) {
 	# nothing to do
 	print ("/* Redefinition of CFI flash memory unecessary */\n");
 } else {
diff --git a/linux-2.6.x/arch/nios2nommu/scripts/hwselect.pl b/linux-2.6.x/arch/nios2nommu/scripts/hwselect.pl
index 8181bee..92cd6d4 100644
--- a/linux-2.6.x/arch/nios2nommu/scripts/hwselect.pl
+++ b/linux-2.6.x/arch/nios2nommu/scripts/hwselect.pl
@@ -125,7 +125,7 @@ foreach my $name (keys (%cfiinfo)) {
 }
 
 my @cfilist = keys (%cfiinfo);
-my $cfi_selected = $cfilist[request_answer (1, $index - 1) - 1];
+my $cfi_selected = $cfilist[($index > 1) ? (request_answer (1, $index - 1) - 1) : 0];
 
 delete $meminfo{$cfi_selected};
 
@@ -163,4 +163,4 @@ print HWMK "EXEMEM = $mem_selected\n";
 
 close (HWMK);
 
-print "\n--- Settings written to $target_filename\n\n";
\ No newline at end of file
+print "\n--- Settings written to $target_filename\n\n";
-- 
1.5.3.3

