writing to AT91SAM9G20EK NANDFLASH and using GDB

AT91SAM9 Evaluation Boards

Moderator: nferre

garybaldi
Posts: 2
Joined: Thu Aug 11, 2016 3:31 pm

writing to AT91SAM9G20EK NANDFLASH and using GDB

Thu Aug 11, 2016 4:10 pm

Hi Everyone,

I'm Gary. I'm desperately trying to run some code on my brand new AT91SAM9G20-EK board. And I'm having so much troubles with it! So, I've successfully ran AT91Bootstrap thanks to SAM-BA but I don't understand how it works exactly.

For example, the documentation says NAND Flash is at address 0x40000000 (see http://www.atmel.com/Images/Atmel-6384- ... asheet.pdf page 26). But from SAM-BA, under the NADFlash tab, I can't send a file to that address (0x40000000). Instead, I use the default one 0x0, and it works! How come? Is there some sort of remaping?

Second, I want to be able to boot from AT91Bootstrap and then run a custom program stored in this NANDFlash memory and then loaded to SDRAM by AT91Bootstrap, but I can't figure out how to do this either. The reason why I'm trying to do that is to be able to run code bigger than 16KB. I've tried countless of combinations. Basically, I'm storing my custom program to 0x00400000 (assuming that NAND Flash starts at 0x0), and my AT91Bootstrap is compiled with this settings :

Code: Select all

                    'IMG_ADDRESS=0x00400000',
                    'IMG_SIZE=0x00080000',
                    'JUMP_ADDR=0x20000000',
The custom program is basic-nandflash-project-at91sam9g20-ek-gnu taken from at91sam9g20-revC-ek-softpack-1.8 (the program is linked with the linker script called "sdram.lds"). From what I understand, I'm expecting AT91Bootstrap to fetch the program from NANDFlash at 0x00400000 and copy it to SDRAM (0x20000000) and then execute it (just run the instruction stored at 0x200000000), but it, of course, does not work. By that I mean there is nothing printed on the console, but there should be according to main.c from basic-nandflash-project-at91sam9g20-ek-gnu.

And one more thing, when I try to use GDB for starting AT91Bootstrap (which starts well when uploaded from SAM-BA), I get a strange error on J-Link GDB Server : ERROR: Bad JTAG communication: Write to IR: Expected 0x1, got 0x0 (TAP Command : 2) @ Off 0x5.

JLink GDB Server

Code: Select all

SEGGER J-Link GDB Server V6.00e GUI Version

JLinkARM.dll V6.00e (DLL compiled Aug  4 2016 09:37:38)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     5000 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 AT91SAM9G20
Target interface:              JTAG
Target interface speed:        1000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link ARM V8 compiled Aug 26 2015 15:08:21
Hardware: V8.00
SAM-ICE found !
S/N: 28021535
OEM: SAM-ICE
Feature(s): RDI, GDB
Checking target voltage...
Target voltage: 3.25 V
Listening on TCP/IP port 2331
Connecting to target...
J-Link found 1 JTAG device, Total IRLen = 4
JTAG ID: 0x0792603F (ARM9)
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000020 (Data = 0xEAFFFFFE)
Downloading 2460 bytes @ address 0x00000000
Downloading 48 bytes @ address 0x0000099C
Downloading 36 bytes @ address 0x000009CC
Downloading 208 bytes @ address 0x000009F0
Downloading 112 bytes @ address 0x00000AC0
Downloading 196 bytes @ address 0x00000B30
Downloading 180 bytes @ address 0x00000BF4
Downloading 68 bytes @ address 0x00000CA8
Downloading 64 bytes @ address 0x00000CEC
Downloading 532 bytes @ address 0x00000D2C
Downloading 28 bytes @ address 0x00000F40
Downloading 56 bytes @ address 0x00000F5C
Downloading 52 bytes @ address 0x00000F94
Downloading 20 bytes @ address 0x00000FC8
Downloading 56 bytes @ address 0x00000FDC
Downloading 44 bytes @ address 0x00001014
Downloading 16 bytes @ address 0x00001040
Downloading 48 bytes @ address 0x00001050
Downloading 60 bytes @ address 0x00001080
Downloading 28 bytes @ address 0x000010BC
Downloading 20 bytes @ address 0x000010D8
Downloading 48 bytes @ address 0x000010EC
Downloading 64 bytes @ address 0x0000111C
Downloading 100 bytes @ address 0x0000115C
Downloading 660 bytes @ address 0x000011C0
Downloading 104 bytes @ address 0x00001454
Downloading 40 bytes @ address 0x000014BC
Downloading 140 bytes @ address 0x000014E4
Downloading 296 bytes @ address 0x00001570
Downloading 36 bytes @ address 0x00001698
Downloading 336 bytes @ address 0x000016BC
Downloading 20 bytes @ address 0x0000180C
Downloading 20 bytes @ address 0x00001820
Downloading 20 bytes @ address 0x00001834
Downloading 20 bytes @ address 0x00001848
Downloading 276 bytes @ address 0x0000185C
Downloading 72 bytes @ address 0x00001970
Downloading 1860 bytes @ address 0x000019B8
Downloading 108 bytes @ address 0x000020FC
Downloading 12 bytes @ address 0x00002168
Downloading 32 bytes @ address 0x00002174
Downloading 116 bytes @ address 0x00002194
Downloading 116 bytes @ address 0x00002208
Downloading 48 bytes @ address 0x0000227C
Downloading 52 bytes @ address 0x000022AC
Downloading 52 bytes @ address 0x000022E0
Downloading 60 bytes @ address 0x00002314
Downloading 12 bytes @ address 0x00002350
Downloading 12 bytes @ address 0x0000235C
Downloading 32 bytes @ address 0x00002368
Downloading 64 bytes @ address 0x00002388
Downloading 240 bytes @ address 0x000023C8
Downloading 20 bytes @ address 0x000024B8
Downloading 32 bytes @ address 0x000024CC
Downloading 4 bytes @ address 0x000024EC
Downloading 8 bytes @ address 0x000024F0
Downloading 64 bytes @ address 0x000024F8
Downloading 92 bytes @ address 0x00002538
Downloading 84 bytes @ address 0x00002594
Downloading 32 bytes @ address 0x000025E8
Downloading 48 bytes @ address 0x00002608
Downloading 44 bytes @ address 0x00002638
Downloading 4 bytes @ address 0x00002664
Downloading 4 bytes @ address 0x00002668
Downloading 24 bytes @ address 0x0000266C
Downloading 24 bytes @ address 0x00002684
Downloading 28 bytes @ address 0x0000269C
Downloading 16 bytes @ address 0x000026B8
Downloading 16 bytes @ address 0x000026C8
Downloading 32 bytes @ address 0x000026D8
Downloading 40 bytes @ address 0x000026F8
Downloading 44 bytes @ address 0x00002720
Downloading 28 bytes @ address 0x0000274C
Downloading 36 bytes @ address 0x00002768
Downloading 48 bytes @ address 0x0000278C
Writing register (PC = 0x00000000)
Read 4 bytes @ address 0x00000000 (Data = 0xEA00000E)
Starting target CPU...
ERROR: Bad JTAG communication: Write to IR: Expected 0x1, got 0x0 (TAP Command : 2) @ Off 0x5.
Commands run from GDB

Code: Select all

C:\opt\arm-gnu-toolchain\bin\arm-none-eabi-gdb.exe AT91Bootstrap.exe
GNU gdb (Atmel build: 487) 7.10.1.20160210-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from AT91Bootstrap.exe...done.
(gdb) target extended-remote :2331
Remote debugging using :2331
(gdb) load
Loading section .text, size 0x99c lma 0x0
Loading section .text.startup.main, size 0x30 lma 0x99c
Loading section .text.sdramc_hw_init, size 0x24 lma 0x9cc
Loading section .text.hw_init, size 0xd0 lma 0x9f0
Loading section .text.nandflash_hw_init, size 0x70 lma 0xac0
Loading section .text.pio_set_gpio_input, size 0xc4 lma 0xb30
Loading section .text.pio_set_gpio_output, size 0xb4 lma 0xbf4
Loading section .text.pio_set_value, size 0x44 lma 0xca8
Loading section .text.pio_get_value, size 0x40 lma 0xcec
Loading section .text.pio_configure, size 0x214 lma 0xd2c
Loading section .text.timer_init, size 0x1c lma 0xf40
Loading section .text.udelay, size 0x38 lma 0xf5c
Loading section .text.mdelay, size 0x34 lma 0xf94
Loading section .text.start_interval_timer, size 0x14 lma 0xfc8
Loading section .text.wait_interval_timer, size 0x38 lma 0xfdc
Loading section .text.rstc_external_reset, size 0x2c lma 0x1014
Loading section .text.cpu_reset, size 0x10 lma 0x1040
Loading section .text.usart_init, size 0x30 lma 0x1050
Loading section .text.usart_puts, size 0x3c lma 0x1080
Loading section .text.usart_getc, size 0x1c lma 0x10bc
Loading section .text.at91_disable_wdt, size 0x14 lma 0x10d8
Loading section .text.init_load_image, size 0x30 lma 0x10ec
Loading section .text.load_image_done, size 0x40 lma 0x111c
Loading section .text.fill_hex_int, size 0x64 lma 0x115c
Loading section .text.dbg_printf, size 0x294 lma 0x11c0
Loading section .text.dbg_hexdump_line, size 0x68 lma 0x1454
Loading section .text.dbg_int_hexdump_line, size 0x28 lma 0x14bc
Loading section .text.dbg_hexdump, size 0x8c lma 0x14e4
Loading section .text.Compute256, size 0x128 lma 0x1570
Loading section .text.Hamming_Compute256x, size 0x24 lma 0x1698
Loading section .text.Hamming_Verify256x, size 0x150 lma 0x16bc
Loading section .text.nand_command, size 0x14 lma 0x180c
Loading section .text.nand_address, size 0x14 lma 0x1820
Loading section .text.nand_command16, size 0x14 lma 0x1834
Loading section .text.nand_address16, size 0x14 lma 0x1848
Loading section .text.nand_read_sector, size 0x114 lma 0x185c
Loading section .text.nand_get_feature_on_die_ecc, size 0x48 lma 0x1970
Loading section .text.load_nandflash, size 0x744 lma 0x19b8
Loading section .text.lowlevel_clock_init, size 0x6c lma 0x20fc
Loading section .text.pmc_init_pll, size 0xc lma 0x2168
Loading section .text.pmc_cfg_plla, size 0x20 lma 0x2174
Loading section .text.pmc_cfg_mck, size 0x74 lma 0x2194
Loading section .text.pmc_cfg_mck_down, size 0x74 lma 0x2208
Loading section .text.pmc_cfg_pck, size 0x30 lma 0x227c
Loading section .text.pmc_enable_periph_clock, size 0x34 lma 0x22ac
Loading section .text.pmc_disable_periph_clock, size 0x34 lma 0x22e0
Loading section .text.pmc_periph_clock_enabled, size 0x3c lma 0x2314
Loading section .text.pmc_enable_system_clock, size 0xc lma 0x2350
Loading section .text.pmc_disable_system_clock, size 0xc lma 0x235c
Loading section .text.pmc_sam9x5_enable_periph_clk, size 0x20 lma 0x2368
Loading section .text.pmc_uckr_clk, size 0x40 lma 0x2388
Loading section .text.pmc_enable_periph_generated_clk, size 0xf0 lma 0x23c8
Loading section .text.pmc_sam9x5_disable_periph_clk, size 0x14 lma 0x24b8
Loading section .text.pmc_set_smd_clock_divider, size 0x20 lma 0x24cc
Loading section .text.pmc_check_mck_h32mxdiv, size 0x4 lma 0x24ec
Loading section .text.at91_get_ahb_clock, size 0x8 lma 0x24f0
Loading section .text.pmc_get_generated_clock, size 0x40 lma 0x24f8
Loading section .text.sdramc_initialize, size 0x5c lma 0x2538
Loading section .text.division.part.0, size 0x54 lma 0x2594
Loading section .text.division, size 0x20 lma 0x25e8
Loading section .text.div, size 0x30 lma 0x2608
Loading section .text.mod, size 0x2c lma 0x2638
Loading section .text.__aeabi_unwind_cpp_pr0, size 0x4 lma 0x2664
Loading section .text.__aeabi_unwind_cpp_pr1, size 0x4 lma 0x2668
Loading section .text.memcpy, size 0x18 lma 0x266c
Loading section .text.memset, size 0x18 lma 0x2684
Loading section .text.memcmp, size 0x1c lma 0x269c
Loading section .text.strlen, size 0x10 lma 0x26b8
Loading section .text.strcpy, size 0x10 lma 0x26c8
Loading section .text.strcat, size 0x20 lma 0x26d8
Loading section .text.strcmp, size 0x28 lma 0x26f8
Loading section .text.strncmp, size 0x2c lma 0x2720
Loading section .text.strchr, size 0x1c lma 0x274c
Loading section .text.memchr, size 0x24 lma 0x2768
Loading section .text.memmove, size 0x30 lma 0x278c
Start address 0x0, load size 10172
Transfer rate: 12 KB/sec, 135 bytes/write.
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
reset () at sources\at91bootstrap/crt0_gnu.S:50
50              b       reset_vector    /* reset */
(gdb)
Again, this very same program works well without GDB (when called by RomBOOT)

Please explain like I'm 5 :). Thank you, I'm losing all hope :(

Gary.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: writing to AT91SAM9G20EK NANDFLASH and using GDB

Thu Aug 11, 2016 10:50 pm

garybaldi wrote:Instead, I use the default one 0x0, and it works! How come? Is there some sort of remaping?
No, there is no remapping.
On the contrary, the NAND flash memory space is not mapped into the processor address space at all, and is kept separate.
NAND flash is accessed as a block-device peripheral.
garybaldi wrote:Basically, I'm storing my custom program to 0x00400000 (assuming that NAND Flash starts at 0x0),
Okay, that's reasonable.
garybaldi wrote:...and my AT91Bootstrap is compiled with this settings :

Code: Select all

                    'IMG_ADDRESS=0x00400000',
                    'IMG_SIZE=0x00080000',
                    'JUMP_ADDR=0x20000000',
That seems reasonable, but the image size should be much larger for future versatility.
You neglect to mention your toolchain and development environment, and any software versions involved.
garybaldi wrote:... but it, of course, does not work. By that I mean there is nothing printed on the console, but there should be according to main.c from basic-nandflash-project-at91sam9g20-ek-gnu.
Either you're really bad at reporting what happens (because you only mention what does not occur), or you have numerous issues.
On a board reboot, you should expect to see "RomBOOT" displayed on the system console (i.e. the DBGU serial port).
Then AT91Bootstrap should output its banner when it starts executing.

Instead of booting from NAND flash, you could try booting from SDcard as a first effort.
You can bypass the hassles of raw NAND, just copy files, and focus on building and booting a program.
See linux4sam/bin/view/Linux4SAM/SDCardBootNotice

Regards
garybaldi
Posts: 2
Joined: Thu Aug 11, 2016 3:31 pm

Re: writing to AT91SAM9G20EK NANDFLASH and using GDB

Thu Aug 11, 2016 11:12 pm

Hi Blue_z,

Thank you for your answer. Yes I see RomBOOT and yes AT91Bootstrap is loading, but then I don't think the program stored at NAND address 0x00400000 is being copied to SDRAM and executed. Actually, what I'm trying to achieve is to execute a "large" program (larger than the 16 KB allowed for AT91Bootstrap), and I don't know what is the best strategy to achieve that (AT91Bootstrap+MyProgram?, AT91Boostrap+U-Boot+MyProgram? Or just MyProgram linked with at91lib?).

- The tool chain I use is "Atmel ARM GNU Toolchain 5.3.1 - Windows".
- I'm using SAM-BA 2.16 for Windows
- I'm using J-Link V6.00
- My board is Atmel AT91SAM9G20-EK. There is no SD Card reader.

Anyways, I will try again and post some more details tomorrow, as I'm currently out of the office.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: writing to AT91SAM9G20EK NANDFLASH and using GDB

Fri Aug 12, 2016 1:34 am

garybaldi wrote:Yes I see RomBOOT and yes AT91Bootstrap is loading, but then I don't think the program stored at NAND address 0x00400000 is being copied to SDRAM and executed..
Then reconfigure/rebuild AT91Bootstrap for verbose mode.
What kind of file (elf or bin) did you install in NAND?
garybaldi wrote:Actually, what I'm trying to achieve is to execute a "large" program (larger than the 16 KB allowed for AT91Bootstrap), and I don't know what is the best strategy to achieve that (AT91Bootstrap+MyProgram?, AT91Boostrap+U-Boot+MyProgram? Or just MyProgram linked with at91lib?).
Either of the first two should work.
U-Boot gives you a lot of flexibility, e.g. download your binary directly to memory for test execution w/o storing in NAND.
garybaldi wrote:- The tool chain I use is "Atmel ARM GNU Toolchain 5.3.1 - Windows".
FWIW that toolchain may not have been verified for building AT91Bootstrap.
It's certainly not listed in the README.txt of the current version of AT91Bootstrap.
I've encountered enough compiler bugs and anomalies to respect such lists.

IMO not using a Linux host for development with a GNU toolchain is a mistake.
You could use a virtual machine or dual boot a lightweight Linux distribution (e.g. Lubuntu), or use an old laptop or desktop (w/ KVM switch to share monitor, keyboard, mouse).
garybaldi wrote:- My board is Atmel AT91SAM9G20-EK. There is no SD Card reader.
That board's User Guide states differently.

What version of AT91Bootstrap are you using (e.g. softpack, released tar/zip file, git pull)?

Regards

Return to “Evaluation and Development Boards”

Who is online

Users browsing this forum: No registered users and 1 guest