Thanks again for your very helpful suggestions, CptTitanic!
After some investigation, I strongly believe that the NAND flash is operating normally, and the bad checks are failing because the AT91lib (on which SAM-BA is based) does not support this type of flash with large pages. There is a possibility that SAM-BA needs to be modified. The modification could be done along the lines of another thread (
viewtopic.php/f,9/t,19290/). At this time, I am uncertain with respect to what I need to change in the code to be able to get this up and running.
However, all is not lost, since I loaded At91bootstrap to an external Atmel SPI Dataflash (AT45DB021D). The At91bootstrap was then used to load U-Boot, which was also loaded to the Dataflash. I will then be able to copy the Linux kernel to the NAND flash using U-Boot. Consequently, U-Boot should be able to boot the kernel from the NAND flash.
To add support for the AT45DB021D on my custom board, I had to un-comment a section of code in the /Bootstrap-v1.16/driver/dataflash.c file. This section of code had possibly been commented out by a programmer at Atmel, who found that adding it would cause the size of the binary to be larger than 4k. However, without including this code, At91bootstrap refuses to copy the U-Boot binary from Dataflash to SDRAM.
I modified the Makefile of At91bootstrap to use the CodeSourcery arm-none-linux-gnueabi-gcc toolchain. I then compiled At91bootstrap using this toolchain. On Windows 7 (64-bit), I had to use the MSYS compilation environment from the MinGW toolchain.
I also modified the crt0_gnu.S assembler file to bypass the main crystal oscillator, since my custom circuit board uses an external clock instead of a crystal. This entailed commenting out and changing the following line of code in the _enable_mosc function:
/*ldr r2,=AT91C_CKGR_MOSCEN*/
/*This code modified to bypass the main oscillator*/
ldr r2,=AT91C_CKGR_OSCBYPASS
I then used SAM-BA to send the boot file to Dataflash using the SAM-ICE. To ensure that the file was transferred correctly, I had to use the "Send boot file" option in the SAM-BA GUI. I believe that this is required since the SAM-BA boot ROM program looks for ARM interrupt vectors at the beginning of the flash memory, and one of these vectors is automatically modified by the SAM-BA scripts.
I then modified the U-Boot 2010.09 sources for my custom board. Most importantly, I updated this definition for my custom board (found in the header file /include/configs/at91sam9rlek.h):
#define CONFIG_SYS_NAND_READY_PIN AT91_PIN_PD9
I couldn't use the most recent version of U-Boot since various changes have been implemented that prevents code for the AT91SAM9RL-EK evaluation board from compiling without errors. Searching the mailing lists, it appears that the AT91 evaluation board code is slowly being fixed. However, the U-Boot 2010.09 sources works well for me. I used the arm-none-linux-gnueabi-gcc toolchain running on Ubuntu Linux 10.10 to compile U-Boot.
Using the SAM-BA GUI and the SAM-ICE on Windows XP, I loaded the U-Boot .bin file to address 0x8400 on Dataflash.
Correspondingly, I had to update the AT91bootstrap code with the appropriate image address and image size:
#define IMG_ADDRESS 0x8400 /* Image Address in DataFlash */
#define IMG_SIZE 0x1AE34
I then replaced the NAND flash chip select jumper to NCS3-NANDCS (port pin PB6).
Booting the processor, I was then able to load U-Boot and examine NAND flash. As U-Boot shows, there appears to be nothing wrong with NAND flash, and I can examine the bad blocks. Note that I've added some additional debug messages to the AT91bootstrap code:
RomBOOT
>Start AT91Bootstrap...
Loading from dataflash
Jumping to address
Serial hardware up
U-Boot 2010.09 (Mar 27 2011 - 18:04:56)
DRAM: 64 MiB
NAND: 2048 MiB
DataFlash:AT45DB021
Nb pages: 1024
Page Size: 264
Size= 270336 bytes
Logical address: 0xC0000000
Area 0: C0000000 to C00041FF (RO) Bootstrap
Area 1: C0004200 to C00083FF Environment
Area 2: C0008400 to C0041FFF (RO) U-Boot
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
Outside available DataFlash
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot> nand info
Device 0: NAND 2GiB 3,3V 8-bit, sector size 256 KiB
U-Boot> nand device
Device 0: NAND 2GiB 3,3V 8-bit, sector size 256 KiB
U-Boot> nand bad
Device 0 bad blocks:
01040000
0fd80000
121c0000
20600000
27a00000
27b00000
30740000
343c0000
3b080000
46900000
49a00000
4b1c0000
52180000
52200000
7f540000
U-Boot>
Also from U-Boot, I was able to fully erase NAND flash.
So in closing, although I am still uncertain as to what I should change in the SAM-BA code to be able to support this particular NAND flash, I know that I can indeed access it through U-Boot.
Moreover, to boot with SPI Dataflash is perhaps more reliable. To completely boot from NAND flash requires an error-free page 0, and this may make the part more difficult to obtain.
For me, this solution works well, but I am now more certain that the inability to read this NAND flash is associated with the AT91lib.
(Switching between various operating systems was made much easier by the VirtualBox software.)