开发环境
1. Linux platform: ubuntu-18.04.3-desktop-amd64
官网连接:(https://www.nuvoton.com.cn/products/microprocessors/arm9-mpus/nuc970-industrial-control-series/nuc977dk61y/?group=Software&tab=2)
2. GCC 4.8.4 crLinuxs compiler with EABI suppor
3. VMware Workstation 15.5
使用文档:参考UM_NUC980_NUC970_Linux_environment_on_VMware_EN_Rev1.00.pdf
u-Boot v2016.11下载:
https://gitee.com/OpenNuvoton/NUC970_U-Boot_v2016.11
kernel下载:
https://gitee.com/OpenNuvoton/NUC970_Linux_Kernel
uboot添加单板相关的代码至SI工程:
1. 选择NUC970_U-Boot_v2016.11目录 -> ADD ALL(选中“Include top level sub-directories”和“Recursively add lower sub-directories”点击“OK)
2. 选中board目录 -> 点击Remove Tree,去掉整个目录
3. 单选board目录 -> /board/nuvoton/nuc970 -> 点击ADD ALL
4. 选中arch目录 -> 点击Remove Tree,去掉整个目录
5. 单选arch目录 -> /arch/arm/cpu/arm926ejs -> 点击ADD ALL(取消“Include top level sub-directories”和“Recursively add lower sub-directories”点击“OK)
6. 单选arch目录 -> /arch/arm/cpu/arm926ejs/nuc70 -> 点击ADD ALL
7. 单选arch目录 -> /arch/arm/dts -> 点击ADD ALL
8. 单选arch目录 -> /arch/arm/include -> 点击ADD ALL(取消“Include top level sub-directories”和“Recursively add lower sub-directories”点击“OK)只添加顶层目录
9. 单选arch目录 -> /arch/arm/include/asm/arch-nuc970 -> 点击ADD ALL
10. 单选arch目录 -> /arch/arm/include/asm/proc-armv -> 点击ADD ALL
11. 单选arch目录 -> /arch/arm/lib -> 点击ADD ALL
12. 选中include目录 -> 点击Remove Tree,去掉整个目录
13. 进入include -> 点击Add All(去掉“include top level sub-directories”和“recursively add lower sub-directories”前面的勾)表示只加顶层目录的文件
14. 选中include目录 -> /include/andestech -> ADD ALL
15. 选中include目录 -> /include/asm-generic -> ADD ALL
16. 选中include目录 -> /include/configs/ -> 选择nuc70_evb.h -> 点击ADD
17. 同步,添加完成
编译uboot:
1.make distclean
2.make nuc970_defconfig
3.make menuconfig
在配置选项下面配置支持SPI NOR FLASH启动方式:(使用的华邦spi flash)
Device Drivers --->
SPI Flash Support --->
[*] Legacy SPI Flash Interface support
[*] SPI flash Bank/Extended address register support
[*] Winbond SPI flash support
Device Drivers --->
SPI Support --->
[*] NUC970/N9H30 SPI driver
Select NUC970/N9H30 SPI in Quad mode or Normal mode (Quad mode) --->
(X) Quad mode
Command line interface --->
Device access commands --->
[*] sf
[*] sspi
//note:修改配置头文件:include/configs/nuc970_evb.h
#define CONFIG_SYS_USE_SPIFLASH
#define CONFIG_SYS_USE_NANDFLASH
/*#define CONFIG_ENV_IS_IN_NAND */
#define CONFIG_ENV_IS_IN_SPI_FLASH
/*#define CONFIG_ENV_IS_IN_MMC */
//common/board_r.c文件中的init_sequence_r[]关于nand的去掉,折腾几天uboot没有启动成功,nuvoton默认支持nand flash启动,卡在了检测
nand里面,导致一直uboot在无限重启
#ifdef CONFIG_CMD_NAND
//initr_nand,
#endif
#ifdef CONFIG_CMD_ONENAND
//initr_onenand,
#endif
4.make
会生成u-boot.bin文件
编译Kernel
建立依赖文件:
1. 在linux-3.10.x/的上一层,建立mkdir image文件夹,生成的imagem,uImage镜像文件会在此目录生成
2. 保证linux-3.10.x/同级目录下有根文件系统文件 rootfs/
1. cd linux-3.10.x/
1. make nuc976_defconfig
2. make uImage
在建立的image文件夹下会生成image,uImage烧录镜像文件
环境变量文件:env.txt
baudrate=115200
bootdelay=3
ethact=emac
ethaddr=00:00:00:11:66:88
stderr=serial
stdin=serial
stdout=serial
bootcmd=sf probe 0 18000000\; sf read 0x7FC0 0x200000 0x9206d0\; bootm 0x7FC0
watchdog=off
1.sf probe 0 18000000 : 将SPI时钟设置为18MHz
2.sf read 0x7FC0 0x200000 : 0x4D7800将一个大小为0x4D7800Bytes的Linux内核映像档(970uimage)
从SPI flash偏移量0x200000的位置读取到DDR 0x7Fc0的位置
3.bootm 0x7fc0 : 从DDR的0x7fc0这个地址启动内核
烧录uboot:地址0xE00000
烧录uImage,地址0x200000
烧录环境变量,地址0x80000
上电运行可以看到kernel启动完整log:
U-Boot 2016.11-g3bd4967-dirty (Nov 23 2021 - 16:44:27 +0800)
CPU: NUC976
Board: NUC976
DRAM: 64 MiB
SF: Detected W25Q128BV with page size 256 Bytes, erase size 4 KiB, total 16 MiB
In: serial
Out: serial
Err: serial
Net: emac
Hit any key to stop autoboot: 0
SF: Detected W25Q128BV with page size 256 Bytes, erase size 4 KiB, total 16 MiB
device 0 offset 0x200000, size 0x9206d0
SF: 9570000 bytes @ 0x200000 Read: OK
## Booting kernel from Legacy Image at 00007fc0 ...
Image Name: Linux-3.10.101
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 5072472 Bytes = 4.8 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
XIP Kernel Image ... OK
Starting kernel ...
SF: Detected W25Q128BV with page size 256 Bytes, erase size 4 KiB, total 16 MiB
SF: DeviceBooting Linux on physical CPU 0x0
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Initializing cgroup subsys cpuacct
Linux version 3.10.101 (user@ubuntu) (gcc version 4.8.5 (Buildroot 2016.11.1-g7116cea) ) #3 PREEMPT Wed Nov 24 10:28:12 CST 2021
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: NUC970
Memory policy: ECC disabled, Data cache writeback
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: root=/dev/ram0 console=ttyS0,115200n8 rdinit=/sbin/init mem=64M
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 57900k/57900k available, 7636k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
vmalloc : 0xc4800000 - 0xff000000 ( 936 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0xc0008000 - 0xc033af04 (3276 kB)
.init : 0xc033b000 - 0xc0675a54 (3307 kB)
.data : 0xc0676000 - 0xc06a95e0 ( 206 kB)
.bss : 0xc06a95e0 - 0xc06d9420 ( 192 kB)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Preemptible hierarchical RCU implementation.
NR_IRQS:625
sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 148.88 BogoMIPS (lpj=744448)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
Initializing cgroup subsys devices
Initializing cgroup subsys freezer
Initializing cgroup subsys perf_event
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0xc0291788 - 0xc02917c4
devtmpfs: initialized
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Switching to clocksource nuc970-timer1
cfg80211: Calling CRDA to update world regulatory domain
NET: Registered protocol family 2
TCP established hash table entries: 512 (order: 0, 4096 bytes)
TCP bind hash table entries: 512 (order: -1, 2048 bytes)
TCP: Hash tables configured (established 512 bind 512)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (double precision)
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 113
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
nuc970-uart.0: ttyS0 at I/O 0x0 (irq = 36) is a NUC970
brd: module loaded
libphy: nuc970_rmii0: probed
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
nuc970-ehci nuc970-ehci: Nuvoton NUC970 EHCI Host Controller
nuc970-ehci nuc970-ehci: new USB bus registered, assigned bus number 1
nuc970-ehci nuc970-ehci: irq 23, io mem 0xb0005000
nuc970-ehci nuc970-ehci: USB 2.0 started, EHCI 0.95
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
nuc970-ohci nuc970-ohci: Nuvoton NUC970 OHCI Host Controller
nuc970-ohci nuc970-ohci: new USB bus registered, assigned bus number 2
nuc970-ohci nuc970-ohci: irq 24, io mem 0xb0007000
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 2 ports detected
usbcore: registered new interface driver usb-storage
TCP: cubic registered
NET: Registered protocol family 17
Freeing unused kernel memory: 3304K (c033b000 - c0675000)
BusyBox v1.22.1 (2016-02-03 14:11:04 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
~ # ls
app.sh dev lib mnt sbin tmp var
bin etc linuxrc proc sys usr
修改rootfs,添加上电启动脚本
1. cd rootfs/
2. touch app.sh
#在app.sh添加以下内容测试:
#!/bin/bash
echo "############## Hello World ##############!"
3. chmod 777 app.sh
4. 在/etc/init.d/rcS最后,添加内容,让系统启动自动运行
source /app.sh
5. cd linux-3.10.x/
6. make uImage重新编译生成uImage烧录,开机可以看到app.sh自动运行
启动部分log:
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
nuc970-uart.0: ttyS0 at I/O 0x0 (irq = 36) is a NUC970
brd: module loaded
libphy: nuc970_rmii0: probed
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
nuc970-ehci nuc970-ehci: Nuvoton NUC970 EHCI Host Controller
nuc970-ehci nuc970-ehci: new USB bus registered, assigned bus number 1
nuc970-ehci nuc970-ehci: irq 23, io mem 0xb0005000
nuc970-ehci nuc970-ehci: USB 2.0 started, EHCI 0.95
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
nuc970-ohci nuc970-ohci: Nuvoton NUC970 OHCI Host Controller
nuc970-ohci nuc970-ohci: new USB bus registered, assigned bus number 2
nuc970-ohci nuc970-ohci: irq 24, io mem 0xb0007000
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 2 ports detected
usbcore: registered new interface driver usb-storage
TCP: cubic registered
NET: Registered protocol family 17
Freeing unused kernel memory: 3304K (c033b000 - c0675000)
############## Hello World ##############!
BusyBox v1.22.1 (2016-02-03 14:11:04 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.