[U-Boot] problem detecting CFI

I have a working u-boot 2008.10 on a mips 32 board and am trying to port it over to u-boot 2009.06. So I used buildroot 2009.08 to build the tool chain for my mips32 board as well as u-boot2009.06. I also copied the previous u-boot initialization code to initialize timer, serial port, ram and etc from u-boot 2008.10 to 2009.06.
Right now the problem is the new u-boot 2009.06 does not detect cfi of the flash. I am pretty sure u-boot is running from SDRAM when the problem happens because the address is in the range of SDRAM. Please let me know if you have any suggestion - I am running out of ideas. I am attaching the printout from both the working u-boot 2008.10 and u-boot 2009.06 below.
Thanks a lot.
U-Boot 2009.06 (Sep 30 2009 - 18:41:26)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U-Boot at: 98000000 Reserving 139k for U-Boot at: 97fdc000 Reserving 4352k for malloc() at: 97b9c000 Reserving 36 Bytes for Board Info at: 97b9bfdc Reserving 36 Bytes for Global Data at: 97b9bfb8 Reserving 128k for boot params() at: 97b7bfb8 Stack Pointer at: 97b7bf98 Now running in RAM - U-Boot at: 97fdc000 flash detect cfi not found flash detect cfi not found
U-Boot 2008.10 (Sep 30 2009 - 11:37:03)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U-Boot at: 98000000 Reserving 736k for U-Boot at: 97f44000 Reserving 4352k for malloc() at: 97b04000 Reserving 44 Bytes for Board Info at: 97b03fd4 Reserving 36 Bytes for Global Data at: 97b03fb0 Reserving 128k for boot params() at: 97ae3fb0 Stack Pointer at: 97ae3f98 Now running in RAM - U-Boot at: 97f44000 flash detect cfi fwc addr b0000000 cmd f0 f0 8bit x 8 bit fwc addr b0000000 cmd ff ff 8bit x 8 bit fwc addr b0000055 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000555 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000000 cmd f0 f0f0 16bit x 8 bit fwc addr b0000000 cmd ff ffff 16bit x 8 bit fwc addr b00000aa cmd 98 9898 16bit x 8 bit is= cmd 51(Q) addr b0000020 is= 5151 5151 is= cmd 52(R) addr b0000022 is= 5252 5252 is= cmd 59(Y) addr b0000024 is= 5959 5959 device interface is 2 found port 2 chip 1 port 16 bits chip 8 bits

I just found something interesting -
In my previous email I thought the CFI detection was running from DRAM, but that assumption seems to be wrong. Previously I though it was running from DRAM because I traced the execution using BDI into mips/start">cpu/mips/start.S relocate_code, it runs to the place where it relocates itself. To be exact, here -
addi t0, s2, in_ram - start jr t0 nop
I checked and found the pc register changed to pointing to a SDRAM location, so relocation seems to be fine. I also load the symbol-file to the DRAM location at that point. But afterwards if I set breakpoint to board_init_r, the breakpoint is not triggered.
Then I realized if I keep using the same symbol-file, the breakpoint at board_init_r can be triggered, and at that point, I can see the PC is still pointing to the flash.
I don't understand how can the code, which has been relocated to SDRAM at one point, suddenly going back to run in the flash when it calls board_init_r. Can someone help me?
Thanks.
On Thu, 01 Oct 2009 16:47 -0500, wpa@fastmail.fm wrote:
I have a working u-boot 2008.10 on a mips 32 board and am trying to port it over to u-boot 2009.06. So I used buildroot 2009.08 to build the tool chain for my mips32 board as well as u-boot2009.06. I also copied the previous u-boot initialization code to initialize timer, serial port, ram and etc from u-boot 2008.10 to 2009.06.
Right now the problem is the new u-boot 2009.06 does not detect cfi of the flash. I am pretty sure u-boot is running from SDRAM when the problem happens because the address is in the range of SDRAM. Please let me know if you have any suggestion - I am running out of ideas. I am attaching the printout from both the working u-boot 2008.10 and u-boot 2009.06 below.
Thanks a lot.
U-Boot 2009.06 (Sep 30 2009 - 18:41:26)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U-Boot at: 98000000 Reserving 139k for U-Boot at: 97fdc000 Reserving 4352k for malloc() at: 97b9c000 Reserving 36 Bytes for Board Info at: 97b9bfdc Reserving 36 Bytes for Global Data at: 97b9bfb8 Reserving 128k for boot params() at: 97b7bfb8 Stack Pointer at: 97b7bf98 Now running in RAM - U-Boot at: 97fdc000 flash detect cfi not found flash detect cfi not found
U-Boot 2008.10 (Sep 30 2009 - 11:37:03)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U-Boot at: 98000000 Reserving 736k for U-Boot at: 97f44000 Reserving 4352k for malloc() at: 97b04000 Reserving 44 Bytes for Board Info at: 97b03fd4 Reserving 36 Bytes for Global Data at: 97b03fb0 Reserving 128k for boot params() at: 97ae3fb0 Stack Pointer at: 97ae3f98 Now running in RAM - U-Boot at: 97f44000 flash detect cfi fwc addr b0000000 cmd f0 f0 8bit x 8 bit fwc addr b0000000 cmd ff ff 8bit x 8 bit fwc addr b0000055 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000555 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000000 cmd f0 f0f0 16bit x 8 bit fwc addr b0000000 cmd ff ffff 16bit x 8 bit fwc addr b00000aa cmd 98 9898 16bit x 8 bit is= cmd 51(Q) addr b0000020 is= 5151 5151 is= cmd 52(R) addr b0000022 is= 5252 5252 is= cmd 59(Y) addr b0000024 is= 5959 5959 device interface is 2 found port 2 chip 1 port 16 bits chip 8 bits _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

I can fix this problem not but I really don't understand how the problem happens in the first place. I found gp got changed in relocate_code in file start.S.
In relocate_code "function", the $gp is adjusted to point to the new location, but somehow before program jumps to the relocated place, $gp was changed. But I don't know where it is changed. So I used t8 register to save the adjusted gp, and put it back before it jump to DRAM. But I don't know why $gp was changed in the between. Can someone give me some idea? I did not touch any thing else in this file.
/* * Fix $gp: * * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address */ move t6, gp sub gp, CONFIG_SYS_MONITOR_BASE add gp, a2 /* gp now adjusted */ move t8, gp /* add here <=== save gp */
...
/* Jump to where we've relocated ourselves. */ move gp, t8 /* add here <=== copy gp back */ addi t0, s2, in_ram - _start jr t0 nop
On Thu, 01 Oct 2009 18:25 -0500, wpa@fastmail.fm wrote:
I just found something interesting -
In my previous email I thought the CFI detection was running from DRAM, but that assumption seems to be wrong. Previously I though it was running from DRAM because I traced the execution using BDI into mips/start">cpu/mips/start.S relocate_code, it runs to the place where it relocates itself. To be exact, here -
addi t0, s2, in_ram - start jr t0 nop
I checked and found the pc register changed to pointing to a SDRAM location, so relocation seems to be fine. I also load the symbol-file to the DRAM location at that point. But afterwards if I set breakpoint to board_init_r, the breakpoint is not triggered.
Then I realized if I keep using the same symbol-file, the breakpoint at board_init_r can be triggered, and at that point, I can see the PC is still pointing to the flash.
I don't understand how can the code, which has been relocated to SDRAM at one point, suddenly going back to run in the flash when it calls board_init_r. Can someone help me?
Thanks.
On Thu, 01 Oct 2009 16:47 -0500, wpa@fastmail.fm wrote:
I have a working u-boot 2008.10 on a mips 32 board and am trying to port it over to u-boot 2009.06. So I used buildroot 2009.08 to build the tool chain for my mips32 board as well as u-boot2009.06. I also copied the previous u-boot initialization code to initialize timer, serial port, ram and etc from u-boot 2008.10 to 2009.06.
Right now the problem is the new u-boot 2009.06 does not detect cfi of the flash. I am pretty sure u-boot is running from SDRAM when the problem happens because the address is in the range of SDRAM. Please let me know if you have any suggestion - I am running out of ideas. I am attaching the printout from both the working u-boot 2008.10 and u-boot 2009.06 below.
Thanks a lot.
U-Boot 2009.06 (Sep 30 2009 - 18:41:26)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U- Boot at: 98000000 Reserving 139k for U-Boot at: 97fdc000 Reserving 4352k for malloc() at: 97b9c000 Reserving 36 Bytes for Board Info at: 97b9bfdc Reserving 36 Bytes for Global Data at: 97b9bfb8 Reserving 128k for boot params() at: 97b7bfb8 Stack Pointer at: 97b7bf98 Now running in RAM - U-Boot at: 97fdc000 flash detect cfi not found flash detect cfi not found
U-Boot 2008.10 (Sep 30 2009 - 11:37:03)
Reset Cause: Hardware Reset DRAM: 64 MB Top of RAM usable for U- Boot at: 98000000 Reserving 736k for U-Boot at: 97f44000 Reserving 4352k for malloc() at: 97b04000 Reserving 44 Bytes for Board Info at: 97b03fd4 Reserving 36 Bytes for Global Data at: 97b03fb0 Reserving 128k for boot params() at: 97ae3fb0 Stack Pointer at: 97ae3f98 Now running in RAM - U-Boot at: 97f44000 flash detect cfi fwc addr b0000000 cmd f0 f0 8bit x 8 bit fwc addr b0000000 cmd ff ff 8bit x 8 bit fwc addr b0000055 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000555 cmd 98 98 8bit x 8 bit is= cmd 51(Q) addr b0000010 is= 4f 51 fwc addr b0000000 cmd f0 f0f0 16bit x 8 bit fwc addr b0000000 cmd ff ffff 16bit x 8 bit fwc addr b00000aa cmd 98 9898 16bit x 8 bit is= cmd 51(Q) addr b0000020 is= 5151 5151 is= cmd 52(R) addr b0000022 is= 5252 5252 is= cmd 59(Y) addr b0000024 is= 5959 5959 device interface is 2 found port 2 chip 1 port 16 bits chip 8 bits _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

I think I found a problem in cpu/mips/start.S.
gp register is used to point to the SDRAM. But after gp is adjusted to proper location, a C function flush_cache is called. But this function actually changes gp register before gp is used to jump to SDRAM. That makes the u-boot run from flash and fails to detect CFI.
Here is the assembler code for flush_cache.c (gdb) disassem 0xb0000798 Dump of assembler code for function flush_cache: 0xb000078c <flush_cache+0>: lui gp,0x3 0xb0000790 <flush_cache+4>: addiu gp,gp,-32300 0xb0000794 <flush_cache+8>: addu gp,gp,t9
And here is how I fixed the issue -
diff --git a/u-boot-2009.08/cpu/mips/start.S b/u-boot-2009.08/cpu/mips/start.S index 57db589..0e8f8ed 100644 --- a/u-boot-2009.08/cpu/mips/start.S +++ b/u-boot-2009.08/cpu/mips/start.S @@ -321,6 +321,7 @@ relocate_code: move t6, gp sub gp, CONFIG_SYS_MONITOR_BASE add gp, a2 /* gp now adjusted */ + move t8, gp sub s1, gp, t6 /* s1 <-- relocation offset */
/* @@ -358,6 +359,7 @@ relocate_code:
/* Jump to where we've relocated ourselves. */ + move gp, t8 addi t0, s2, in_ram - _start jr t0 nop
participants (2)
-
myuboot@fastmail.fm
-
wpa@fastmail.fm