| |
uclinux中nios的flashprogrammer |
[ 2007-4-8 11:59:00 | By: caopengly ] |
0
FlashProgrammerVersion 39, changed by hippo5329@yahoo.com.tw. 04/04/2007. Show version history During development, we use nios2-config-sof and nios2-download to config the FPGA and run Nios II program from SDRAM. But the content of FPGA and SDRAM will lose when power off. To enable the system to start from power on, we need to write sof and program to flash. But flash have limited write life and the write speed is slow, so you should not program the flash until you have your system mostly tested. Though we can use JTAG UART as console with nios2-terminal during development. You should not use it as console device if you want your system to start automatically when power on. Because the JTAG UART will hang without a nios2-terminal connected. You should use Serial UART with a RS232C cable instead. You can keep both the JTAG UART and serial UART in SOPC builder, but you must disable "Support for console on Altera JTAG UART" in kernel config and rebuild the kernel image. Please check LinuxConfig about how to select the other console device instead of JTAG UART. You have to test the new kernel image with nios2-download. Don't run nios2-terminal, use minicom on Linux or Hyper-terminal on Windows. Make sure it runs correctly over the RS-232C COM port. Only after you have tested the program from sdram, you may try to write the flash. You will write the sof and program image seperately. You must find out what kind of flash you will use. There may be CFI flash, or EPCS flash, or both of them. First, you must decide where to configure FPGA, from CFI or EPCS. This will mostly depend on the hardware, config mode pins or CPLD. You need to check the manual if it is a dev board. For DE2, DE1, some eval and starter boards, the sof is loaded in EPCS flash. For most other Altera dev boards, you can select one either CFI or EPCS with the CPLD. The CPLD will control the config offset on CFI, eg, 0xc00000. Next, you must decide where to store the program. Most dev boards have a CFI flash, and you can use it by default. If your board have space on EPCS, you may use it but EPCS is usually slower than CFI during read. You must tell which component to use for reset vector, CFI flash or EPCS controller, in SOPC builder. If you change it, you regenerate the sof. You don't need to rebuild the kernel image. The Altera flash conversion utility can add a Altera supplied boot loader, which will load the image to SDRAM and execute. The kernel image is compiled to start from SDRAM, (sdram base + boot link offset of the uncompress loader). So the start up procedures will be 1. power on reset Check your kernel dir, linux-2.6.x/include/nios2_system.h or check in SOPC builder , to find out the EPCS controller, or CFI flash 's base address. You will need these address for flash programming. So we might have at least four alternatives, 1. sof in EPCS, program in CFIUsing DE2_NET v1.5 as example (see TryOutuClinux ), find out and change the sof path, cfi base and epcs base below.Open a Linux shell terminal, (or a Nios2 command shell on Windows) # config the fpga 2. sof in CFI, program in CFIUsing Altera Nios Dev board, Cyclone II 2C35 , standard example, find out and change the sof path, and cfi base below.# config the fpga 3. sof in EPCS, program in EPCSUsing Altera Nios Dev board, Cyclone II 2C35 , standard example, find out and change the sof path, and epcs base below. # config the fpga Convert .flash file to binary, remote updateWhen we want to write FPGA config data, program image or file system image to CFI flash or EPCS on Nios2 uClinux, we need1. create MTD device using MTD map driver and rebuild kernel, see following sections. eg, we have 3 mtd dev, with mtd 0,1 on CFI for jffs2,kernel and mtd 2 on EPCS for fpga config. 2. convert the .flash file (which is srec format), to binary format on Linux PC, eg. nios2-linux-uclibc-objcopy -I srec -O binary standard.flash standard.bin 3. find out the MTD devices on Nios2 uClinux, cat /proc/mtd 4. (transfer the file to Nios2..) write the binary file to MTD device on Nios2 uClinux, eg. copy config data to EPCS on mtd 2, cp standard.bin /dev/mtdblock2 sync # flush write cache to dev Or you can use the flash utility included in uClinux-dist. Note, you must use --epcs flag to sof2flash if and only if you want to generate for EPCS. The EPCS config data is different from that of CFI flash. 8. If you use EPCS, you can use jffs2 to provide a nonvolatile filesystem. Or if you use cfi flash, in kernel menuconfig, You may have to edit/customize the map file for different flash size and part size, in drivers/mtd/maps/ You have to enable zlib for mkfs.jffs2 . In uClinux-dist user config, Then rebuild and boot nios2 uclinux. mount –t jffs2 /dev/mtdblock0 /mnt The DE2 's fpga configs from EPCS16 (not CFI), is 2MB. The sof is not written directly to EPCS, it will be converted to RBF (raw binary file). First, resize your cfi flash to 4M base addr 0 ,in sopc builder, and regenerate sof. static const char *part_probes[] __initdata = {NULL}; edit altera.c static struct mtd_partition alteramap_partitions[] = { { .name = "romfs/jffs2", .size = 0x400000, .offset = 0x000000, } }; Rebuild kernel image from the start "make clean", "make linux_hwselect....".... If you want to update flash in your (user space) apps, you can use "dd" to mtdblock device or look in user/flashw of uClinux-dist. You may use it to update the fpga configuration data and linux image. If you want to root fs on the jffs2 drive, you should use mkfs.jffs2 to build the rootfs image. |