First, the transplant environment
- Host: Vmware--fedora 9
- Development Board: MINI2440--64MB Nand, kernel:2.6.30.4
- Compiler: arm-linux-gcc-4.3.2.tgz
- U-boot: u-boot-2009.08.tar.bz2
Second, the transplant procedure
In this article, we first let the board support the CS8900 or dm9000x NIC, and then analyze the implementation u-boot how to boot the Linux kernel. Because the test u-boot boot kernel We need to use the network download function.
7) U-boot support for CS8900 or dm9000x NIC.
The u-boot-2009.08 version has more sophisticated code support for CS8900 and dm9000x NICs (code is in the drivers/net/directory), and the S3C24XX network card is configured by default in the CS8900 series. Just in a few places in accordance with the Development Board specific network card selection to set up, you can use the S3C24XX series of CS8900 network card support. The code is as follows:
Now modify the support for the dm9000x NIC on our development board.
First, let's look at the code for DM9000 in the drivers/net/directory, find out the dependencies on config_driver_dm9000 macros in dm9000x.h, DM9000X.C config_dm9000_base macros, dm9000_ IO macro, Dm9000_data and other macro dependencies, so we modify the code as follows:
#gedit include/configs/my2440.h
|
/* * Hardware Drivers * * Shield off U-boot default support for CS8900 NIC #define CONFIG_DRIVER_CS8900 1/* We have a CS8900 on-board */ #define Cs8900_base 0x19000300 #define CS8900_BUS16 1/* The Linux driver does accesses as shorts */ Add u-boot support for dm9000x NIC #define CONFIG_DRIVER_DM9000 1 #define CONFIG_NET_MULTI 1 #define CONFIG_DM9000_NO_SROM 1 #define CONFIG_DM9000_BASE 0x20000300 //Net card selected address #define DM9000_IO Config_dm9000_base #define DM9000_DATA (Config_dm9000_base + 4) //network card data address #define CONFIG_DM9000_USE_16BIT 1 Attention: u-boot-2009.08 can automatically detect the number of bits of the DM9000 network card, according to the board schematic diagram shows that the data bits of the network card is 16 bits, and the network card is located on the CPU BANK4, so only in the board/samsung/my2440/lowlevel_init. Set #define B4_BWSCON (DW16) in S, do not need #define here Config_dm9000_use_16bit 1 Ping the u-boot to test that the network does not pass through #define Config_cmd_ping Recover the commented out MAC address of the NIC and modify your appropriate Development Board IP address #define CONFIG_ETHADDR 08:00:3e:26:0a:5b //Development Board MAC address #define Config_netmask 255.255.255.0 #define CONFIG_IPADDR 192.168.1.105 //Development Board IP address #define CONFIG_SERVERIP 192.168.1.103 //linux host IP address |
Add the onboard DM9000 NIC initialization code, as follows:
#gedit board/samsung/my2440/my2440.c
|
#include <net.h> #include <netdev.h> #ifdef config_driver_dm9000 int Board_eth_init (bd_t *bis) { Return dm9000_initialize (bis); } #endif |
Modify the MD9000 NIC driver code as follows:
#gedit drivers/net/dm9000x.c
|
#if 0///block out this part of the Dm9000_init function, otherwise the use of the NIC will report "Could not establish link" error i = 0; while (!) ( Phy_read (1) & 0x20)) {/* autonegation complete bit */ Udelay (1000); i++; if (i = = 10000) { printf ("Could not establish link"); return 0; } } #EndIf
|
Then recompile the u-boot, download the NAND boot from the NAND, view the boot information and environment variables and use the ping command to test the NIC, as follows:
As you can see, the boot information shows the environment variables that are net:dm9000,printenv viewed andconsistent in Include/configs/my2440.h settings. But now there is a problem that ping can't pass. after a period of time on the Internet search, there are many people have encountered this situation. The problem may be in the DM9000 network card driver to shut down the network card in the place, if you try to modify the code as follows:As a result, only the first ping does not pass, after all can be ping pass (according to Netizens said this is normal), such as: OK, now there is only one problem, is to use TFTP to download. About the TFTP server installation and configuration in Linux, here I do not speak, search on the internet a lot of. However, in the TFTP download and encountered a problem, there is always a transmission is incomplete and re-transmission phenomenon, continuous cycle, such as: confusion for a long time TFTP problem now finally settled, the mood is really cool!! First of all, the phenomenon in the above diagram, in the download process is intermittent to be able to download, but for some reason the network has a time-out to re-download, then I think there are two possibilities for this situation: 1, u-boot in the network delay settings, 2, is my physical network structure. First of all, I modified the net/net.c in the network delay settings, the result is not. Then try the second situation, because my network is through the router to manage, the host and the Development Board is also through the router to connect, so now I use a crossover cable directly to the host and the Development Board to connect, a try, sure enough, haha haha ..... At this point, the network part of the transplant is finally complete.
8) Implement U-boot boot Linux kernel boot. In the previous sections, we talked about U-boot launch support for NOR Flash and NAND flash, so let's talk about how u-boot can boot the Linux kernel.
①,Determination of machine codeusually, in u-boot and kernel there will be a machine code (ie: mach_type), only the two machine code is consistent to boot the kernel, otherwise the following MACH error message appears:first, determine the Mach_type in the U-boot. In the U-boot include/asm-arm/mach-types.h file, a very wide range of mach_type are defined for different CPUs, which can be found in the following definition:
②,prepare a kernel that can be directly booted by U-boot UimageTypically, the boot of kernel requires U-boot to provide some parameter information, such as the RAMDisk address in RAM. After compiling the u-boot in the Tools directory under the root directory, there will be a tool called mkimage, he can add a header to Zimage, which means that the kernel we compiled usually zimage add a header information section, We put the image after adding the head is usually called uimage,uimage is a kernel image that can be directly booted by U-boot. the use of the Mkimage tool is described below:
使用: 中括号括起来的是可选的
mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
Options: -a:set architecture to ' arch '//For specifying the CPU type, such as Arm -o:set operating system to ' OS '//For the specified operating system, such as Linux -t:set image type to ' type '//used to specify the image type, such as kernel -c:set compression type ' comp '//Specify compression type -a:set load address to ' addr ' (hex)//Specify the load address of the image -e:set entry point to ' EP ' (hex)//The ingress address of the kernel, typically the load address of image +0x40 (the size of the information header) -n:set image name to ' name '//image naming in the header structure -d:use image data from ' datafile '//image filename with headless information -x:set XIP (execute in place)//Set execution position
|
The mkimage in Tools under U-boot are copied to the/usr/local/bin directory of the host, so that the tool can be used in any directory on the host. Now we enter the kernel build directory (typically the Arch/arm/boot directory), and then execute the following command, we will generate a uimage.img image file in that directory, copy him to the TFTP directory, this is what we call uimage.
mkimage -n ‘linux-2.6.30.4‘ -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage uImage.img
|
③,the partition of the Nand Flash. We look at the partitioning of the kernel in ARCH/ARM/PLAT-S3C24XX/COMMON-SMDK.C as follows :
起始地址 结束地址
uboot : 0x00000000 0x00030000 param : 0x00030000 0x00040000 //注意这个环境变量的地址范围要与上一节补充内容中配置的CONFIG_ENV_OFFSET一致 kernel: 0x00050000 0x00200000 root : 0x00250000 0x03dac000
|
④,set the startup parameters to modify U-boot, and enter them under the U-boot command line:
//设置启动参数,意思是将nand中0x50000-0x00200000(和kernel分区一致)的内容读到内存0x31000000中,然后用bootm命令来执行
set bootcmd ‘nand read 0x31000000 0x50000 0x00200000;bootm 0x31000000‘
saveenv //保存设置
|
⑤,Download the uimage.img to memory with TFTP and then solidify it into NAND flash, and the operation and execution diagram is as follows:
tftp 0x30000000 uImage.img //将uImage.img下载到内存0x30000000处
nand erase 0x50000 0x200000 //擦除nand的0x50000-0x200000的内容
nand write 0x30000000 0x50000 0x200000 //将内存0x30000000处的内容写入到nand的0x50000处
|
Finally, we restart the Development Board, we can see that the kernel was u-boot successfully booted up,
#define MACH_TYPE_SMDK2440 1008 //针对2440的MACH_TYPE码的值定义为1008
|
Then we'll modify the U-boot Mach_type Code Reference section to determine the Mach_type of u-boot. As follows:
#gedit board/samsung/my2440/my2440.c //修改board_init函数
|
/* arch number of SMDK2410-Board */ //gd->bd->bi_arch_number = MACH_TYPE_SMDK2410; 改为: gd->bd->bi_arch_number = MACH_TYPE_SMDK2440;
|
Second, determine the mach_type in kernel. The kernel Arch/arm/tools/mach-types file also defines a lot of mach_type for different CPUs, and you can find the following definition:
smdk2440 MACH_SMDK2440 SMDK2440 1008
|
Then we'll modify the kernel Mach_type Code Reference section to determine the mach_type of kernel. As follows:
#gedit arch/arm/mach-s3c2440/mach-smdk2440.c //修改文件最后面
|
//MACHINE_START(S3C2440, "SMDK2440") 改为: MACHINE_START(SMDK2440, "SMDK2440")
|
| Span style= "Font-family:nsimsun;" > #gedit Arch/arm/kernel/head. S //Add the following code (Red section) under Entry (stext) |
ENTRY(stext)
mov r0, #0 mov r1, #0x3f0 //上面的MACH_TYPE值1008换成十六进制就是0x3f0 ldr r2, =0x30000100 msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
.......
|
Recompile u-boot and kernel, respectively. U-boot download, remember to saveenv;kernel with TFTP downloaded to memory using the GO command to test the boot kernel, the results can be guided, as follows:
#gedit drivers/net/dm9000x.c //屏蔽掉dm9000_halt函数中的内容
|
/* Stop the interface. The interface is stopped while it is brought. */ static void Dm9000_halt (struct eth_device *netdev) { //dm9000_dbg ("%sn", __func__);
///* RESET Devie */ //phy_write (0, 0x8000); /* PHY RESET */ Dm9000_iow (DM9000_GPR, 0x01); /* Power-down PHY */ //dm9000_iow (DM9000_IMR, 0x80); /* Disable all Interrupt */ //dm9000_iow (DM9000_RCR, 0x00); /* Disable RX */ }
|
#gedit include/configs/my2440.h
|
/* * Hardware drivers */ #define CONFIG_DRIVER_CS8900 1 /* we have a CS8900 on-board */ #define CS8900_BASE 0x19000300 //注意:对不同的开发板就是要修改这个片选地址参数,这个参数值就看开发板上网卡的片选引脚是接到ARM芯片存储控制器的哪个Bank上 #define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */
|
Transplantation of Uboot on s3c2440 (4)