The goal of the document is to illustrate how to build SP7021 Linux image for booting from SPI-NOR flash on SP7021 boards. SP7021 build (make) system supports two types of root file-system for SPI-NOR flash. One is initramfs file-system and other is jffs2 file-system. If you choose initramfs file-system, build system merges root file-system into Linux kernel. The whole kernel (kernel + root file-system) is loaded into and operates in DRAM directly. The advantage of initramfs file-system is that accessing speed is very fast. But since it is stored in DRAM, all changes disappear when power off. If you choose jffs2 file-system, root file-system is compressed and is stored in rootfs partition of SPI-NOR flash. The drawback of jffs2 file-system is that accessing speed is slow. But all changes are kept in SPI-NOR flash when power off.
To build image of SPI-NOR flash, first, you need to get source files of SP7021 from git server of SP7021. Second, you need to run make to build all images of SP7021. After make processes complete successfully, it will create a binary file named spi_all.bin. Third, you need to use flash programmer to write the spi_all.bin to SPI NOR flash. Finally, plug the written SPI-NOR flash into socket of SPI-NOR (SOC-8) on your SP7021 board, set DIP-SW to “boot from SPI-NOR flash”. You are ready to turn on SP7021 power to boot Linux from SPI-NOR flash. For details, please follow the following steps.
1. Download source files
Get latest source files from git server of SP7021 (2. HOW TO GET SOURCE FILE AND PACKAGE). Refer to report of ll command for the contents of top folder of source of SP7021:
wellslu@scdiu3:~/q628/nor$ ll total 52 drwxr-xr-x 12 wellslu sp 4096 Oct 15 12:01 ./ drwxr-xr-x 19 wellslu sp 4096 Oct 15 11:53 ../ drwxr-xr-x 8 wellslu sp 4096 Apr 27 18:51 boot/ drwxr-xr-x 4 wellslu sp 4096 Aug 25 12:05 build/ drwxr-xr-x 7 wellslu sp 4096 Jul 27 12:23 crossgcc/ drwxr-xr-x 6 wellslu sp 4096 Apr 27 18:51 eCos/ drwxr-xr-x 9 wellslu sp 4096 Jun 5 09:30 freertos/ drwxr-xr-x 8 wellslu sp 4096 Aug 11 16:40 ipack/ drwxr-xr-x 7 wellslu sp 4096 Apr 27 18:51 linux/ -r--r--r-- 1 wellslu sp 23 Apr 27 18:51 Makefile drwxr-xr-x 4 wellslu sp 4096 Apr 27 18:51 nonos/ drwxr-xr-x 7 wellslu sp 4096 Apr 27 18:51 .repo/ drwxr-xr-x 3 wellslu sp 4096 Jun 29 09:44 yocto/
2. Configure environment
Run make config command on top folder. After configuration menu pops up, first, choose a board you want to build image for. For example, press 1 to choose “SP7021 Ev Board”. Second, press 1 to choose to use C chip (quad core CA7). Finally, press 3 (jffs2) or 4 (initramfs) to choose to boot from SPI-NOR flash and then enter to start to configure building environment. Refer to screenshot below,
make config starts to build compiler environment. It may take a few minutes. Please wait for make config completing the processes.
3. Modify device-tree source file
This step is for jffs2 (3) root file-system. Please skip this step if you are using initramfs (4) root file-system.
Modify device-tree node sp_spinor0 in device-tree source file linux/kernel/arch/arm/boot/dts/sp7021-ev.dts to setup operating frequency SPI-NOR flash and pins as shown below:
&sp_spinor0 { spi-max-frequency = <50000000>; spi-chip-selection = <0>; pinctrl-names = "default"; pinctrl-0 = <&spi_flash2_mux &spi_fla4b2_mux>; }
where operating frequency of SPI-NOR flash is 50 MHz and SPI-NOR flash is installed in pin-group: spi_flash2_mux and spi_fla4b2_mux. Set them base on your real hardware installation.
4. Remove SECT_4K flag of NOR flash
This step is for jffs2 (3) root file-system. Please skip this step if you are using initramfs (4) root file-system.
Some SPI-NOR flashes support 4 kB sector-erase, but mkfs.jffs2 -e option does not support 4 kB size of erase. Please remove SECT_4K flag in C file “driver/mtd/spi-nor/spi-nor.c” if your NOR flash support 4 KB sector-erase . Refer to screenshot of diff report, SECT_4K flag of Winbond w25q128 flashes are removed.
5. Build NOR image
Run make all command to start to create all images of SP7021. It may take several minutes to complete. At almost final stage of building processes, make will ask you to select the use of iBoot,
Please press x and enter to continue the processes. After make all completes, you will see screenshot like:
The final binary spi_all.bin is built and copied to folder out. Refer to screenshot of output of ll out command:
6. Write your SPI NOR flash
Put your SPI-NOR flash chip into socket of flash programmer. Be careful about the pin 1 position of the chip. It should be at the same corner of pin 1 of socket. Refer to picture below, an SPI NOR flash is placed at socket of a GZUT USB flash programmer.
Run flash programmer application, for example, run GZUT_OnePro in Windows. After application window pops up, then load binary file, spi_all.bin. Press “Auto” to start to write processes automatically (including erase, write and verify). Refer to screenshot below, a WINBOND 128 Mibit (16 MiB) flash chip (W25Q128) has been programmed and verified successfully.
Remove the SPI NOR flash chip from socket. Note that the size of 'spi_all.bin' is about 14.2 MiB. So, size of SPI NOR flash chip should be 16 MiB (or 128 Mibit) or greater.
7. Set DIP-SW to “boot from SPI-NOR flash”
Plug the written SPI-NOR flash into socket of SPI NOR flash of SP7021 board. Set DIP-SW (boot-select switch) to “boot from SPI-NOR flash”. For example, if you are using SP7021 Ev Board, please set DIP-SW to OFF-OFF-ON-OFF-ON-OFF (1-1-0-1-0-1) for booting from SPI-NOR flash. Refer to picture below, DIP-SW is set to OFF-OFF-ON-OFF-ON-OFF.
Now, you are ready to boot SP7021 Linux from SPI-NOR flash. Turn on power of SP7021 board to boot system.
Appendix. Layout of partitions of SPI-NOR flash
Refer to layout of partitions of a 16 MiB SPI-NOR flash. There are 6 partitions in SPI-NOR flash. The figures in parenthesis of each partition is the size of the partition. Note that root file-system of Linux is built into kernel.
0 Comments