在ZedBoard上运行linux并编写linux下的应用程序HelloWorld

2019-07-12 23:27发布

从本小节开始,讲着重介绍Zedboard上的嵌入式linux应用,包括使用SDK设计最简单的linux应用程序、linux交叉编译环境搭建、设备驱动编写等内容。 本小节使用的linux系统是Digilent官方提供的OOB设计,它是Digilent官网给出的一个完整的、Zedboard可运行的linux系统,包含了Zedboard上的几个重要的设备驱动如串口、USB、以太网、OLED、HDMI等。当linux在Zedboard上运行起来后,Zedboard就是一个小型的嵌入式系统,使用SDK及Xilinx ARM Linux工具链(arm-xilinx-linux-gnueabi)编译生成的可执行文件可以在这个系统执行。 本小节介绍的是使用SDK开发应用程序,并非在linux系统下使用arm-xilinx-linux-gnueabi。如果需要在linux系统下开发Zedboard上可执行程序,需要安装用arm-xilinx-linux-gnueabi编译环境。 更多更新请关注我的博客:@超群天晴 http://www.cnblogs.com/surpassal/
  硬件平台:Digilent ZedBoard 开发环境:Windows XP 32 bit 软件: SDK 14.2   一、获取Zedboard可运行的linux Digilent官网给出Zedboard的可运行linux设计ZedBoard_OOB_Design包,可从http://www.digilentinc.com/Data/Documents/Other/ZedBoard_OOB_Design.zip获取,下载后解压,可以看到包的结构和内容: 复制代码 boot_image目录: 
-- system.bit – 配置FPGA的bit文件
-- u-boot.elf – 引导linux需要的Second-Stage boot loader
-- zynq_fsbl.elf – 配置ARM PS系统的First-Stage boot loader(FSBL) doc目录:
-- README.txt – 说明文件 hw目录:
-- EDK 14.1版本的XPS工程,用来生成硬件文件和bit文件 linux目录:
-- devicetree_ramdisk.dts – 设备树源代码
-- .config – Linux内核配置文件,用来生成zImage sd_image目录:
-- BOOT.BIN – 使用boot_images中的三个文件生成的Zynq配置文件
-- devicetree_ramdisk.dtb – 编译后的设备树文件
-- ramdisk8M.image.gz – 编译后的文件系统
-- README – 介绍如何运行OOB设计的说明文档
-- zImage – 编译后的内核 sw目录:
--硬件配置
--FSBL源代码 复制代码 其中sd_image目录中包含了ZedBoard上能够运行linux的所有文件。将SD卡格式化为Fat32,把sd_image目录文件拷贝到SD卡根目录下;然后将JP7~JP11设置为SD卡启动模式,将JP2短路,JP3断开,这样可以下一步我们可以把U盘作为USB 从设备挂载到Zedboard上。 Zedboard的连接和短路块设置 上电后,等待ARM PS的配置、FPGA的配置(蓝 {MOD}LED DONE 亮起),之后开始引导Linux系统了。可以从超级终端上看到一系列的引导信息: 复制代码 1 U-Boot 2012.04.01-00297-gc319bf9-dirty (Sep 13 2012 - 09:30:49) 2 3 DRAM: 512 MiB 4 WARNING: Caches not enabled 5 MMC: SDHCI: 0 6 Using default environment 7 8 In: serial 9 Out: serial 10 Err: serial 11 Net: zynq_gemHit any key to stop autoboot: 0 12 Copying Linux from SD to RAM... 13 Device: SDHCI 14 Manufacturer ID: 1b 15 OEM: 534d 16 Name: 00000 17 Tran Speed: 25000000 18 Rd Block Len: 512 19 SD version 1.0 20 High Capacity: Yes 21 Capacity: 3.7 GiB 22 Bus Width: 1-bit 23 reading zImage 24 25 2479640 bytes read 26 reading devicetree_ramdisk.dtb 27 28 5817 bytes read 29 reading ramdisk8M.image.gz 30 31 3694108 bytes read 32 ## Starting application at 0x00008000 ... 33 Uncompressing Linux... done, booting the kernel. 34 [ 0.000000] Booting Linux on physical CPU 0 35 [ 0.000000] Linux version 3.3.0-digilent-12.07-zed-beta (tinghui.wang@DIGILENT_LINUX) (gcc version 4.6.1 (Sourcery CodeBench Lite 2011.09-50) ) #2 SMP PREEMPT Thu Jul 12 21:01:42 PDT 2012 36 [ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d 37 [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache 38 [ 0.000000] Machine: Xilinx Zynq Platform, model: Xilinx Zynq ZED 39 [ 0.000000] bootconsole [earlycon0] enabled 40 [ 0.000000] Memory policy: ECC disabled, Data cache writealloc 41 [ 0.000000] BUG: mapping for 0xf8f00000 at 0xfe00c000 out of vmalloc space 42 [ 0.000000] BUG: mapping for 0xe0000000 at 0xfe000000 out of vmalloc space 43 [ 0.000000] BUG: mapping for 0xffff1000 at 0xfe200000 out of vmalloc space 44 [ 0.000000] PERCPU: Embedded 7 pages/cpu @c1489000 s5696 r8192 d14784 u32768 45 [ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 125824 46 [ 0.000000] Kernel command line: console=ttyPS0,115200 root=/dev/ram rw initrd=0x800000,8M earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=0 47 [ 0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes) 48 [ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes) 49 [ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes) 50 [ 0.000000] Memory: 240MB 256MB = 496MB total 51 [ 0.000000] Memory: 489856k/489856k available, 34432k reserved, 0K highmem 52 [ 0.000000] Virtual kernel memory layout: 53 [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) 54 [ 0.000000] fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) 55 [ 0.000000] vmalloc : 0xe0800000 - 0xfd000000 ( 456 MB) 56 [ 0.000000] lowmem : 0xc0000000 - 0xe0000000 ( 512 MB) 57 [ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB) 58 [ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB) 59 [ 0.000000] .text : 0xc0008000 - 0xc042f040 (4253 kB) 60 [ 0.000000] .init : 0xc0430000 - 0xc0456640 ( 154 kB) 61 [ 0.000000] .data : 0xc0458000 - 0xc0485dc0 ( 184 kB) 62 [ 0.000000] .bss : 0xc0485de4 - 0xc049d734 ( 95 kB) 63 [ 0.000000] Preemptible hierarchical RCU implementation. 64 [ 0.000000] Verbose stalled-CPUs detection is disabled. 65 [ 0.000000] NR_IRQS:128 66 [ 0.000000] xlnx,ps7-ttc-1.00.a #0 at 0xe0800000, irq=43 67 [ 0.000000] Console: colour dummy device 80x30 68 [ 0.000000] Calibrating delay loop... 1594.16 BogoMIPS (lpj=7970816) 69 [ 0.090000] pid_max: default: 32768 minimum: 301 70 [ 0.090000] Mount-cache hash table entries: 512 71 [ 0.090000] CPU: Testing write buffer coherency: ok 72 [ 0.090000] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000 73 [ 0.100000] smp_twd: clock not found: -2 74 [ 0.100000] Calibrating local timer... 399.36MHz. 75 [ 0.170000] hw perfevents: enabled with ARMv7 Cortex-A9 PMU driver, 7 counters available 76 [ 0.170000] Setting up static identity map for 0x2f8d48 - 0x2f8d7c 77 [ 0.270000] CPU1: Booted secondary processor 78 [ 0.310000] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001 79 [ 0.310000] Brought up 2 CPUs 80 [ 0.310000] SMP: Total of 2 processors activated (3188.32 BogoMIPS). 81 [ 0.320000] devtmpfs: initialized 82 [ 0.320000] ------------[ cut here ]------------ 83 [ 0.320000] WARNING: at arch/arm/mm/dma-mapping.c:198 consistent_init+0x70/0x104() 84 [ 0.330000] Modules linked in: 85 [ 0.330000] [] (unwind_backtrace+0x0/0xe0) from [] (warn_slowpath_common+0x4c/0x64) 86 [ 0.340000] [] (warn_slowpath_common+0x4c/0x64) from [] (warn_slowpath_null+0x18/0x1c) 87 [ 0.350000] [] (warn_slowpath_null+0x18/0x1c) from [] (consistent_init+0x70/0x104) 88 [ 0.360000] [] (consistent_init+0x70/0x104) from [] (do_one_initcall+0x90/0x160) 89 [ 0.360000] [] (do_one_initcall+0x90/0x160) from [] (kernel_init+0x84/0x128) 90 [ 0.370000] [] (kernel_init+0x84/0x128) from [] (kernel_thread_exit+0x0/0x8) 91 [ 0.380000] ---[ end trace 1b75b31a2719ed1c ]--- 92 [ 0.380000] ------------[ cut here ]------------ 93 [ 0.390000] WARNING: at arch/arm/mm/dma-mapping.c:198 consistent_init+0x70/0x104() 94 [ 0.390000] Modules linked in: 95 [ 0.390000] [] (unwind_backtrace+0x0/0xe0) from [] (warn_slowpath_common+0x4c/0x64) 96 [ 0.400000] [] (warn_slowpath_common+0x4c/0x64) from [] (warn_slowpath_null+0x18/0x1c) 97 [ 0.410000] [] (warn_slowpath_null+0x18/0x1c) from [] (consistent_init+0x70/0x104) 98 [ 0.420000] [] (consistent_init+0x70/0x104) from [] (do_one_initcall+0x90/0x160) 99 [ 0.430000] [] (do_one_initcall+0x90/0x160) from [] (kernel_init+0x84/0x128) 100 [ 0.430000] [] (kernel_init+0x84/0x128) from [] (kernel_thread_exit+0x0/0x8) 101 [ 0.440000] ---[ end trace 1b75b31a2719ed1d ]--- 102 [ 0.440000] NET: Registered protocol family 16 103 [ 0.460000] L310 cache controller enabled 104 [ 0.460000] l2x0: 8 ways, CACHE_ID 0x410000c8, AUX_CTRL 0x72060000, Cache size: 524288 B 105 [ 0.460000] registering platform device 'pl330' id 0 106 [ 0.470000] registering platform device 'arm-pmu' id 0 107 [ 0.470000] 108 [ 0.470000] ############################################### 109 [ 0.480000] # # 110 [ 0.480000] # Board ZED Init # 111 [ 0.480000] # # 112 [ 0.490000] ############################################### 113 [ 0.490000] 114 [ 0.500000] hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpointregisters. 115 [ 0.500000] hw-breakpoint: maximum watchpoint size is 4 bytes. 116 [ 0.530000] xslcr xslcr.0: at 0xF8000000 mapped to 0xE0808000 117 [ 0.540000] bio: create slab 0> at 0 118 [ 0.540000] gpiochip_add: registered GPIOs 0 to 245 on device: xgpiops 119 [ 0.540000] xgpiops e000a000.gpio: gpio at 0xe000a000 mapped to 0xe080a000 120 [ 0.550000] SCSI subsystem initialized 121 [ 0.550000] usbcore: registered new interface driver usbfs 122 [ 0.560000] usbcore: registered new interface driver hub 123 [ 0.560000] usbcore: registered new device driver usb 124 [ 0.570000] Advanced Linux Sound Architecture Driver Version 1.0.24. 125 [ 0.570000] Switching to clocksource xttcpss_timer1 126 [ 0.590000] NET: Registered protocol family 2 127 [ 0.590000] IP route cache hash table entries: 4096 (order: 2, 16384 bytes) 128 [ 0.590000] TCP established hash table entries: 16384 (order: 5, 131072 bytes) 129 [ 0.600000] TCP bind hash table entries: 16384 (order: 5, 196608 bytes) 130 [ 0.600000] TCP: Hash tables configured (established 16384 bind 16384) 131 [ 0.610000] TCP reno registered 132 [ 0.610000] UDP hash table entries: 256 (order: 1, 8192 bytes) 133 [ 0.620000] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes) 134 [ 0.620000] NET: Registered protocol family 1 135 [ 0.630000] Trying to unpack rootfs image as initramfs... 136 [ 0.630000] rootfs image is not initramfs (no cpio magic); looks like an initrd 137 [ 0.670000] Freeing initrd memory: 8192K 138 [ 0.670000] xscugtimer xscugtimer.0: ioremap fe00c200 to e0810200 with size 400 139 [ 0.670000] pl330 dev 0 probe success 140 [ 0.680000] msgmni has been set to 972 141 [ 0.680000] io scheduler noop registered 142 [ 0.680000] io scheduler deadline registered 143 [ 0.680000] io scheduler cfq registered (default) 144 [ 0.690000] e00 0.690000] console [ttyPS0] enabled, bootconsole disabled 145 [ 0.690000] console [ttyPS0] enabled,