Kernel compilation and transplantation (c)

In a large number of core board, using SMSC's chip card, model LAN9220. This chip can support Linux-3.0.99 kernel, so modifications come in much more convenient.
To modify the file arch / arm / mach-s3c2416 / mach-smdk2416.c, open it with vi, comprising a first header portion is added in an "#include <linux / smsc911x.h>" , the header card comprising SMSC LAN9220 Come in. Then find the structure "static struct platform_device * smdk2416_devices [] __initdata" defined in this sentence, add a few lines before the empty sentence, and then enter the following (note:! Is not inserted in the structure, the structure is inserted before) :
static struct Resource s3c_smc911x_resources [] = {
[0] = {
.start = 0x08000000,
.end = 0x08000000 SZ_16M + -. 1,
.flags = IORESOURCE_MEM,
},
[. 1] = {
.start IRQ_EINT = (. 4),
.end IRQ_EINT = (. 4),
.flags = IORESOURCE_IRQ,
},
};
struct = {platform_device s3c_device_smc911x
.name = "smc911x",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_smc911x_resources),
.resource = s3c_smc911x_resources,
};
struct smsc911x_platform_config s3c_smsc911x_config = {
.irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
.irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
.flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
.phy_interface = PHY_INTERFACE_MODE_MII,
};
struct platform_device s3c_device_smsc911x =
{
.name = "smsc911x",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_smc911x_resources),
.resource = s3c_smc911x_resources,
.dev = {
.platform_data = &s3c_smsc911x_config,
},
};
After completion of the addition, in the structure just found by adding the words "& s3c_device_smsc911x,", up to the kernel to the device card. After completion of the structure of the content as follows:
static struct platform_device smdk2416_devices * [] = {__initdata
& s3c_device_fb,
& s3c_device_wdt,
& s3c_device_ohci,
& s3c_device_i2c0,
& s3c_device_hsmmc0,
& s3c_device_hsmmc1,
& s3c_device_usb_hsudc,
& s3c_device_smsc911x,
};
save changes and exit completion. Next, modify the file drivers / net / smsc911x.c, the same open it with vi, then find "irq_flags | IRQF_SHARED, dev-> name , dev);" this sentence, turning it into "irq_flags | IRQF_SHARED | IORESOURCE_IRQ_LOWLEVEL, dev- > name, dev); ", to add a level-triggered interrupts the way the card. Save and quit when you're done.
Finally, you need to configure it in the kernel, the same execution "make menuconfig" to open the configuration dialog box, select the Device Drivers -> Network device support -> Ethernet (10 or 100Mbit) -> SMSC LAN911x / LAN921x families embedded ethernet support items. After completing the save and exit, then compile modified kernel again, execute "make clean" command to clean up, and then do "make zImage" to compile. After downloading the compiled kernel zImage generated image file to the development board, the launch kernel, startup is complete as shown below.

从上图中可以看出,网卡已经认出来了,输入命令“ifconfig”并回车,就可看到给网卡分配的IP地址了,你可以试着ping一下PC机,应该可以ping通了,这说明网卡工作是正常的。
接下来看USB口和SD卡,会发现在开发板上插入U盘或SD卡时,系统认不出来,通过执行命令“cat /proc/partitions”可以看出,分区仍然只有原来NandFlash上的三个分区,并未增加新的分区,所以USB口和SD卡并未起作用,接下来就进行修改。先看USB口,其实从启动显示的信息中可以看出,USB口其实已经是正常的了,那为何插入U盘不能用呢?其实这是由于配置问题所至。在源码根目录下执行“make menuconfig”打开配置对话框,进行以下设置:
1.进入System Type一项,找到其中的“***System MMU***”这一栏,把下面的S3C2400 Machines、S3C2410 Machines、S3C2412 Machines、S3C2440 and S3C2442 Machines、S3C2443 Machines各项下的所有子选项全部清除(不勾选),只留下S3C2400 Machines下面的SMDK2416一项勾选上。
2.进入Device Drivers -> USB support选项,这里的选项较多,注意一定按照下面的顺序操作:a、先把原来默认为“M”的选项清除(不勾选);b、勾选USB Mass Storage support一项;c、勾选USB Gadget Support一项并回车进入子选项;d、勾选Debugging messages (DEVELOPMENT)项和Debugging information files (DEVELOPMENT)项。
其他选项按默认,完成后存盘退出,再次编译内核。把编译好的内核zImage下载到开发板上启动,启动完毕后在开发板上插入一个FAT32格式的U盘,会发现U盘已经识别出来并被挂载到了/media/sda1目录下,进入该目录就可看到U盘里的内容了,如下图所示。

此时再执行命令“cat /proc/partitions”就可看到U盘上的分区了。但是到此SD卡还是不能识别,所以还要继续修改配置文件。在源码根目录下执行“make menuconfig”打开配置对话框,继续进行以下设置:
1.勾选System Type -> S3C2410 DMA support一项。
2.进入Device Drivers -> MMC/SD/SDIO card support选项,按照下面的顺序操作:a、先把原来默认为“M”的选项清除(不勾选);b、勾选Secure Digital Host Controller Interface support一项;c、勾选SDHCI Support on Samsung S3C SoC一项;d、勾选DMA support on S3C SDHCI;e、勾选Hardware support for SDIO IRQ一项。
其他选项按默认,完成后存盘退出。接下来还要修改一下arch/arm/mach-s3c2416/mach-smdk2416.c文件,参考前面,同样在*smdk2416_devices[] __initdata结构体内加入一句“&s3c_device_rtc,”和一句“&samsung_asoc_dma,”,完成后的结构内容如下:
static struct platform_device *smdk2416_devices[] __initdata = {
&s3c_device_fb,
&s3c_device_wdt,
&s3c_device_ohci,
&s3c_device_i2c0,
&s3c_device_hsmmc0,
&s3c_device_hsmmc1,
&s3c_device_usb_hsudc,
&s3c_device_smsc911x,
&s3c_device_rtc,
&samsung_asoc_dma,
};
更改完成后存盘退出。以上是向内核注册DMA设备,顺带把实时时钟RTC也注册了。随后编译内核,并把编译好的内核映像文件zImage下载到开发板上去启动,启动完毕后在开发板上插入一张FAT32格式的SD卡,会发现SD卡已经识别出来并被挂载到了/media/mmcblk0p1目录下,进入该目录就可看到SD卡里的内容了,如下图所示。

 

进一步实验会发现,虽然已经看到了SD卡上的内容,但在对其内容进行修改或在SD卡上新建文件时,会出现“Read-only file system”的错误提示,这表明SD卡设备不可写。为了让其可写,还得继续修改源码。使用vi打开drivers/mmc/card/block.c文件,找到其中的“md->read_only=mmc_blk_readonly(card);”这一句,把它改成“md->read_only=0”即可。改完后保存退出,然后重新编译内核,再次把编译好的zImage文件下载到开发板上并启动,完毕再次插入SD卡并进入挂载目录/media/mmcblk0p1,尝试执行“touch abc”命令,会发现文件abc被成功创建,表明SD卡已经可以写入了。
至此,在硕数S3C2416核心板上移植Linux-3.0.99的工作就全部完成了。当然,我们只是让新内核在开发板上跑起来,其他的并没有进行优化,其实应该通过详细的内核配置来精简内核(比如上面内核中的DM9000网卡就可不要),这取决于你开发板上的资源以及你的应用需求,这里就不做讨论了,有兴趣的可自己慢慢研究。

Guess you like

Origin www.cnblogs.com/fxzq/p/12285952.html