Linux-4.9.2内核在mini2440上的移植(三)——编译环境测试

本篇目标:获取linux-4.9.2源码,在服务器上编译,并通过tftp在开发板中试运行。

3.1 linux-4.9.2源码获取

为什么选择4.9.2移植呢?

因为太新的linux源码yaffs文件系统跟不上,编译过程会导致大量错误无法使用,所以选择比较新的源码就可以了。具体的说明到移植yaffs文件系统时再说。

 

我们的工作目录定在/root下面,进入到目录

root@ubuntu:/home/ubuntu# cd   /root

 

(1)下载linux4.9.2源码

root@ubuntu:~#  wget  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.9.2.tar.gz

 

(2)解压源码

root@ubuntu:~ #  tar  -zxvf  linux-4.9.2.tar.gz

 

(3)修改环境变量

root@ubuntu:~# cd  linux-4.9.2/

root@ubuntu:~/linux-4.9.2# vim  Makefile

 

定位到255行,原来的内容是

ARCH            ?= $(SUBARCH)

CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%)

 

如果是使用ubuntu指令安装的arm-linux-gnueabihf-gcc就改为

ARCH            ?= arm

CROSS_COMPILE   ?= arm-linux-gnueabihf-

 

手动安装的arm-linux-gcc 4.4.3就改为

ARCH            ?= arm

CROSS_COMPILE   ?= arm-linux-

 

保存退出ESC :wq

 

3.2编译测试

设置目标板型号

root@ubuntu:~/linux-4.9.2# make  mini2440_defconfig

 

这时会提示:

The program 'make' can befound in the following packages:

 * make

 * make-guile

Try: apt install

 

原因:没有安装make工具,安装一下

root@ubuntu:~/linux-4.9.2#apt  install  make

 

再重试,又出错

root@ubuntu:~/linux-4.9.2#make  mini2440_defconfig

  HOSTCC scripts/basic/fixdep

/bin/sh: 1: gcc: not found

scripts/Makefile.host:107:recipe for target 'scripts/basic/fixdep' failed

make[1]: ***[scripts/basic/fixdep] Error 127

Makefile:448: recipe fortarget 'scripts_basic' failed

make: *** [scripts_basic]Error 2

 

原因:缺少32位的库

解决方法:安装libncurses5等关键库

root@ubuntu:~/linux-4.9.2#apt  install  libncurses5-dev

root@ubuntu:~/linux-4.9.2# apt-get  install  libx11-dev:i386 libreadline6-dev:i386

root@ubuntu:~/linux-4.9.2#apt-get install build-essential

root@ubuntu:~/linux-4.9.2# apt-get  install  lib32stdc++6

root@ubuntu:~/linux-4.9.2# apt-get  install  lib32z1

 

再次运行

root@ubuntu:~/linux-4.9.2# make  mini2440_defconfig

  HOSTCC scripts/basic/fixdep

  HOSTCC scripts/kconfig/conf.o

  SHIPPED scripts/kconfig/zconf.tab.c

  SHIPPED scripts/kconfig/zconf.lex.c

  SHIPPED scripts/kconfig/zconf.hash.c

  HOSTCC scripts/kconfig/zconf.tab.o

  HOSTLD scripts/kconfig/conf

#

# configuration written to.config

#

 

OK,可以了,开始编译测试,这里使用-j8表示使用8个线程进行编译,可以大幅加快编译的速度,-j后面的数值可以根据你的虚拟机设置的实际情况进行选择,一般等于虚拟机的cpu核心数即可,我的虚拟机设置了8个CPU核心,所以-j8

root@ubuntu:~/linux-4.9.2# make  -j8

 

又报错

/bin/sh: 1: bc: not found

Kbuild:67: recipe fortarget 'include/generated/timeconst.h' failed

 

解决方法:安装bc

root@ubuntu:~/linux-4.9.2#apt  install  bc

 

再次编译,可以运行

可以看到编译过程中CPU已经满载

Linux-4.9.2内核在mini2440上的移植(三)——编译环境测试_第1张图片

 

3.3 为uImage创建脚本

查看zImage生成情况

root@ubuntu:~/linux-4.9.2# cd  arch/arm/boot/

root@ubuntu:~/linux-4.9.2/arch/arm/boot#  ls

bootp  compressed dts  Image  install.sh Makefile  zImage

 

可以看到,生成了zImage

我们的平台使用uboot作为BootLoader,所以需要转换为uImage使用。

 

(1)先安装u-boot转换uimage工具

root@ubuntu:~/linux-4.9.2/arch/arm/boot#  apt-get   install   u-boot-tools

 

(2)再到Linux源码根目录

root@ubuntu:~/linux-4.9.2/arch/arm/boot#  cd   ../../..

 

(3)创建脚本

root@ubuntu:~/linux-4.9.2 #  vim   mkuImage.sh

 

(4)粘贴如下内容

mkimage -A arm -O linux -Tkernel -C none -a 0x30008000 -e 0x30008040 -n mini2440 -d /root/linux-4.9.2/arch/arm/boot/zImage  /root/tftp/uImage

 

(5)赋予可执行权限

root@ubuntu:~/linux-4.9.2# chmod   a+x   mkuImage.sh

 

(6)运行

root@ubuntu:~/linux-4.9.2#  ./mkuImage.sh

 

(7)查看,确认脚本有效

root@ubuntu:~/linux-4.9.2# ls   /root/tftp/

uImage

 

可以看到,tftp文件夹下面已经存在了一个uImage

 

3.4运行测试

在本系统中,使用了uboot引导,所以要先将uboot烧写进入到nand flash中,然后打开secureCRT,设置好串口。

将开发板上电,按空格进入到uboot控制台,查看一下环境变量

[U-boot@mini2440A]#printenv

 

bootdelay=1

baudrate=115200

ethaddr=08:00:3e:26:0a:5b

gatewayip=192.168.1.1

netmask=255.255.255.0

xujun=bmp d 70000

 stdin=serial

ethact=dm9000

ipaddr=192.168.2.188

serverip=192.168.2.123

bootcmd=tftp 0x30008000uImage;bootm 0x30008000

bootargs=console=ttySAC0,115200n8root=/dev/nfs nfsroot=192.168.2.123:/home/ubuntu/NFS/myrootfs/rootfsip=192.168.2.188:192.168.2.123:192.168.2.1:255.255.255.0:SMDK2440A.arm9.net:eth0:offinit=/linuxrc

stdin=serial

stdout=serial

stderr=serial

 

Environment size:479/131068 bytes

 

我们的目的是上电之后,uboot直接从tftp文件夹内读取uImage,并启动内核,所以需要配置以下几点

1、设置开发板的ip(根据你的路由网段设置)

[U-boot@mini2440A]# setenv  ipaddr  192.168.2.188

 

2、设置服务器的ip(根据实际ip设置)

[U-boot@mini2440A]# setenv  serverip  192.168.2.104

 

3、设置uboot,tftp加载内核(tftp 是你的tftp文件夹名字)

[U-boot@mini2440A]# setenv  bootcmd  'tftp 0x30008000 uImage;bootm 0x30008000'

 

4、保存参数

[U-boot@mini2440A]# saveenv

Saving Environment toNAND...

Erasing Nand...

Erasing at 0x4000000000002--   0% complete.

Writing to Nand... done

 

启动测试

[U-boot@mini2440A]# boot

dm9000 i/o: 0x20000300, id:0x90000a46

DM9000: running in 16 bitmode

MAC: 08:00:3e:26:0a:5b

could not establish link

Using dm9000 device

TFTP from server192.168.2.104; our IP address is 192.168.2.188

Filename 'uImage'.

Load address: 0x30008000

Loading: #################################################################

        #################################################################

        #################################################################

         ##########

done

Bytes transferred = 3006872(2de198 hex)

## Booting kernel fromLegacy Image at 30008000 ...

   Image Name:  mini2440

   Created:     2017-09-27   7:06:46 UTC

   Image Type:  ARM Linux Kernel Image (uncompressed)

   Data Size:   3006808 Bytes =  2.9 MB

   Load Address: 30008000

   Entry Point: 30008040

   Verifying Checksum ... OK

   XIP Kernel Image ... OK

OK

 

Starting kernel ...

 

Booting Linux on physicalCPU 0x0

Linux version 4.9.2(root@ubuntu) (gcc version 6.3.0 20170406 (Ubuntu/Linaro 6.3.0-12ubuntu2) ) #1Tue Sep 26 23:51:32 PDT 2017

CPU: ARM920T [41129200]revision 0 (ARMv4T), cr=c000717f

CPU: VIVT data cache, VIVTinstruction cache

Machine: MINI2440

Memory policy: Data cachewriteback

CPU S3C2440A (id0x32440001)

Built 1 zonelists in Zoneorder, mobility grouping on.  Totalpages: 16256

Kernel command line:console=ttySAC0,115200n8 root=/dev/nfsnfsroot=192.168.2.123:/home/ubuntu/NFS/myrootfs/rootfsip=192.168.2.188:192.168.2.123:192.168.2.1:255.255.255.0:SMDK2440A.arm9.net:eth0:offinit=/linuxrc

PID hash table entries: 256(order: -2, 1024 bytes)

Dentry cache hash tableentries: 8192 (order: 3, 32768 bytes)

Inode-cache hash tableentries: 4096 (order: 2, 16384 bytes)

Memory: 58868K/65536Kavailable (4309K kernel code, 180K rwdata, 976K rodata, 176K init, 258K bss,6668K reserved, 0K cma-reserved)

Virtual kernel memorylayout:

    vector : 0xffff0000 - 0xffff1000   (   4 kB)

    fixmap : 0xffc00000 - 0xfff00000   (3072kB)

    vmalloc : 0xc4800000 - 0xff800000   ( 944 MB)

    lowmem : 0xc0000000 - 0xc4000000   (  64 MB)

    modules : 0xbf000000 - 0xc0000000   (  16MB)

      .text : 0xc0008000 - 0xc043d660   (4310 kB)

      .init : 0xc0552000 - 0xc057e000   ( 176 kB)

      .data : 0xc057e000 - 0xc05ab320   ( 181 kB)

       .bss : 0xc05ab320 - 0xc05ebf00   ( 259 kB)

SLUB: HWalign=32,Order=0-3, MinObjects=0, CPUs=1, Nodes=1

NR_IRQS:103

S3C2440: IRQ Support

irq: clearing pendingstatus 00000003

irq: clearing pendingstatus 00000002

sched_clock: 16 bits at1012kHz, resolution 987ns, wraps every 32362962ns

clocksource:samsung_clocksource_timer: mask: 0xffff max_cycles: 0xffff, max_idle_ns:28803037 ns

Console: colour dummydevice 80x30

Calibrating delay loop...201.52 BogoMIPS (lpj=503808)

pid_max: default: 32768minimum: 301

Mount-cache hash tableentries: 1024 (order: 0, 4096 bytes)

Mountpoint-cache hash tableentries: 1024 (order: 0, 4096 bytes)

CPU: Testing write buffercoherency: ok

Setting up static identitymap for 0x300081e0 - 0x30008238

clocksource: jiffies: mask:0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9556302231375000 ns

NET: Registered protocolfamily 16

DMA: preallocated 256 KiBpool for atomic coherent allocations

cpuidle: using governorladder

MINI2440: Option stringmini2440=0tb

MINI2440: 't' ignored,touchscreen not compiled in

MINI2440: LCD

 [0:240x320]

 1:800x480

 2:1024x768

 3:320x240

 

S3C2440: Initialisingarchitecture

usbcore: registered newinterface driver usbfs

usbcore: registered newinterface driver hub

usbcore: registered newdevice driver usb

s3c-i2c s3c2440-i2c.0:slave address 0x10

s3c-i2c s3c2440-i2c.0: busfrequency set to 98 KHz

s3c-i2c s3c2440-i2c.0:i2c-0: S3C I2C adapter

Advanced Linux SoundArchitecture Driver Initialized.

clocksource: Switched toclocksource samsung_clocksource_timer

NET: Registered protocolfamily 2

TCP established hash tableentries: 1024 (order: 0, 4096 bytes)

TCP bind hash tableentries: 1024 (order: 0, 4096 bytes)

TCP: Hash tables configured(established 1024 bind 1024)

UDP hash table entries: 256(order: 0, 4096 bytes)

UDP-Lite hash tableentries: 256 (order: 0, 4096 bytes)

NET: Registered protocolfamily 1

RPC: Registered named UNIXsocket transport module.

RPC: Registered udptransport module.

RPC: Registered tcptransport module.

RPC: Registered tcp NFSv4.1backchannel transport module.

futex hash table entries:256 (order: -1, 3072 bytes)

workingset:timestamp_bits=30 max_order=14 bucket_order=0

NFS: Registering theid_resolver key type

Key type id_resolverregistered

Key type id_legacyregistered

jffs2: version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.

romfs: ROMFS MTD (C) 2007Red Hat, Inc.

io scheduler noopregistered

io scheduler deadlineregistered

io scheduler cfq registered(default)

Console: switching tocolour frame buffer device 60x53

s3c2410-lcd s3c2410-lcd:fb0: s3c2410fb frame buffer device

s3c2440-uart.0: ttySAC0 atMMIO 0x50000000 (irq = 74, base_baud = 0) is a S3C2440

console [ttySAC0] enabled

s3c2440-uart.1: ttySAC1 atMMIO 0x50004000 (irq = 77, base_baud = 0) is a S3C2440

s3c2440-uart.2: ttySAC2 atMMIO 0x50008000 (irq = 80, base_baud = 0) is a S3C2440

brd: module loaded

at24 0-0050: 1024 byte24c08 EEPROM, writable, 16 bytes/write

s3c24xx-nand s3c2440-nand:Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns

s3c24xx-nand s3c2440-nand:NAND soft ECC

nand: device found,Manufacturer ID: 0xec, Chip ID: 0xda

nand: Samsung NAND 256MiB3,3V 8-bit

nand: 256 MiB, SLC, erasesize: 128 KiB, page size: 2048, OOB size: 64

Creating 4 MTD partitionson "nand":

0x000000000000-0x000000040000: "u-boot"

ftl_cs: FTL header notfound.

0x000000040000-0x000000060000: "u-boot-env"

ftl_cs: FTL header notfound.

0x000000060000-0x000000560000: "kernel"

ftl_cs: FTL header notfound.

0x000000560000-0x000010000000: "root"

ftl_cs: FTL header notfound.

eth0: dm9000e at c4a5b300,c4a5d304IRQ 55 MAC: 08:00:3e:26:0a:5b (chip)

ohci_hcd: USB 1.1 'Open'Host Controller (OHCI) Driver

ohci-s3c2410: OHCI S3C2410driver

s3c2410-ohci s3c2410-ohci:OHCI Host Controller

s3c2410-ohci s3c2410-ohci:new USB bus registered, assigned bus number 1

s3c2410-ohci s3c2410-ohci:irq 42, io mem 0x49000000

random: fast init done

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 portsdetected

mousedev: PS/2 mouse devicecommon for all mice

i2c /dev entries driver

s3c2410-wdt s3c2410-wdt:watchdog inactive, reset disabled, irq disabled

sdhci: Secure Digital HostController Interface driver

sdhci: Copyright(c) PierreOssman

hidraw: raw HID eventsdriver (C) Jiri Kosina

usbcore: registered newinterface driver usbhid

usbhid: USB HID core driver

NET: Registered protocolfamily 17

Key type dns_resolverregistered

input: gpio-keys as/devices/platform/gpio-keys/input/input0

hctosys: unable to open rtcdevice (rtc0)

dm9000 dm9000 eth0: linkdown

IP-Config: Complete:

     device=eth0, hwaddr=08:00:3e:26:0a:5b,ipaddr=192.168.2.188, mask=255.255.255.0, gw=192.168.2.1

     host=SMDK2440A, domain=,nis-domain=arm9.net

     bootserver=192.168.2.123,rootserver=192.168.2.123, rootpath=

ALSA device list:

  No soundcards found.

dm9000 dm9000 eth0: linkup, 100Mbps, full-duplex, lpa 0x45E1

可以看到,内核已经运行起来了。

 

3.5 移植目标板文件

在上述编译过程中,使用了系统自带的mini2440开发板移植文件,这里我们重新移植,不使用这个移植的文件。

(1)先备份

root@ubuntu:~/linux-4.9.2# cd  arch/arm/mach-s3c24xx/

root@ubuntu:~/linux-4.9.2/arch/arm/mach-s3c24xx# cp  mach-mini2440.c  mach-mini2440_backup.c

 

(2)替换

root@ubuntu:~/linux-4.9.2/arch/arm/mach-s3c24xx# cp  mach-smdk2440.c  mach-mini2440.c

 

(3)修改

root@ubuntu:~/linux-4.9.2/arch/arm/mach-s3c24xx# vim  mach-mini2440.c

 

定位到末尾处,找到180行MACHINE_START(S3C2440,"SMDK2440") , 将其修改为

MACHINE_START(MINI2440, "Mini2440 developmentboard")

 

定位到167行附近,把其中的16934400(代表原SMDK2440 目标板的晶振是16.9344MHz)改为mini2440 开发板上实际使用的12000000(代表mini2440 开发板上的晶振12MHz,元器件标号为X2),如下所示:

static void __initsmdk2440_init_time(void)

{

        s3c2440_init_clocks(12000000);

        samsung_timer_init();

}

 

把mach-mini2440.c 中所有的smdk2440 字样改为mini2440,可以使用批处理命令修改,在vim 的命令模式下输入:(先按ESC,在输入一个“:”,粘贴下面的命令,回车)

%s/smdk2440/mini2440/g

上面这句的意思是:把所有和“smdk2440”匹配的字符串全部替换为“mini2440”,前面的“%s“代表字符串匹配,最后的“g”代表global,是全局的意思

 

在mini2440_machine_init(void)函数中,把smdk_machine_init()函数调用注释掉,因为我们后面会编写自己的初始化函数,不需要调用smdk2440 原来的,定位到177行,修改如下:

static void __initmini2440_machine_init(void)

{

       s3c24xx_fb_set_platdata(&mini2440_fb_info);

        s3c_i2c0_set_platdata(NULL);

 

        platform_add_devices(mini2440_devices,ARRAY_SIZE(mini2440_devices));

//     smdk_machine_init();

}

 

保存,可以再打开一个putty,登录后进入/root/linux-4.9.2文件夹内,专门用于编译内核。

root@ubuntu:~/linux-4.9.2# make  mini2440_defconfig

root@ubuntu:~/linux-4.9.2# make  -j8

 

编译成功,生成uImage

root@ubuntu:~/linux-4.9.2#./mkuImage.sh

 

按一下开发板复位键,进入内核测试

可以看到内核启动成功。

你可能感兴趣的:(Linux-4.9.2内核在mini2440上的移植(三)——编译环境测试)