15AH, San Francisco

California, United States.

Send Your Mail At:

tianyingkejishe@sina.cn

Working Hours

Mon-Sat: 9.30am To 7.00pm

分类标题

Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait.

分类归档 MCU/MPU/GPU

【LX2160】DDR4调试

一、硬件描述

硬件配置:5颗ddr4,其中一颗作为ecc。

1、DDR问题会导致uboot无法加载运行。所以RCW配置完后最重要的就是调试DDR。首先检查ddr硬件上的设计,DQ信号设计应该是4位交叉(swap),主要原因是CW软件DQ mapping是按照4位配置的,没有8位的swap配置,如果硬件不是按照4位swizzled的,ddr的参数校准会通不过。我们的项目第一版即使因为硬件DQ信号是按照8位设计的,DQ参数无法正确配置,从而ddr校准不过,不得已最后改版成4位swpa,才成功了。DQ mapping参数由硬件提供,然后再cw上对应填写就行。DQ_MAP原理图:

Codewarrior DQ mapping配置-4位swap,根据实际电路调整:

2、在创建ddr配置工程的时候,需要填写的clk to dqs由硬件提供,要正确填写。其他的值按照ddr手册配置好就行

二、参数介绍

1、DRAM type: 颗粒的配置成NoDimm

2、使用CW做validation参数校准,这个比较费时。

3、校准完毕后,和RCW一样,点击生成代码按钮,会生成ddr_init1.c,找到ddr_raw_timing结构体,复制到自己的ddr_init.c中替代。

struct dimm_params ddr_raw_timing = {
        .n_ranks = 1,
        .rank_density = 8589934592u,
        .capacity = 8589934592u,
        .primary_sdram_width = 64,
        .ec_sdram_width = 8,
        .device_width = 8,
        .die_density = 0x08,
        .rdimm = 0,
        .mirrored_dimm = 0,
        .n_row_addr = 16,
        .n_col_addr = 10,
        .bank_addr_bits = 0,
        .bank_group_bits = 2,
        .edc_config = 2,
        .burst_lengths_bitmask = 0x0c,
        .tckmin_x_ps = 625,
        .tckmax_ps = 1600,
        .caslat_x = 0x00FFFC00,
        .taa_ps = 18800,
        .trcd_ps = 18800,
        .trp_ps = 18800,
        .tras_ps = 43800,
        .trc_ps = 37600,
        .twr_ps = 20000,
        .trfc1_ps = 350000,
        .trfc2_ps = 260000,
        .trfc4_ps = 160000,
        .tfaw_ps = 25000,
        .trrds_ps = 25000,
        .trrdl_ps = 6200,
        .tccdl_ps = 6200,
        .refresh_rate_ps = 10237500
};

4、在packages/firmware/atf/plat/nxp/soc-lx2160/lx2160ardb/platform_def.h中定义下面的宏:

#define CONFIG_DDR_NODIMM

flex-builder -c atf -m lx2160ardb_rev2 -b xspi 生成fip.bin文件,使用codewarrior tap下载到flash。建议先下载一个官方的复合固件,然后替换自己的fip.bin和fip_uboot.bin。

三、开启DDR Log

修改文件:flexbuild_lsdk2108/components/firmware/atf$ vim Makefile

修改内容:

修改文件:flexbuild_lsdk2108/components/firmware/atf/plat/nxp/soc-lx2160a/lx2160ardb/platform.mk

修改内容:增加DDR_DEBUG := yes

【NXP】NXP(Freescale) QorIQ CodeWarrior TAP使用

通讯方式有两种:

一、USB通讯

这个相对简单,但速率低。配置流程如下,配置完保存即可。

二、网口通讯

配置复杂,速率高。先连上USB,配置流程如下:

连接后,配置IP

Push enter to start console.

                  ####
               ##########
            ##########  ....          Freescale Semiconductor Inc.
               ####  ..........       Copyright (c) 2015
                  ..........  ####    All Rights Reserved
                     ....  ##########
                        ##########    Codewarrior TAP Firmware
                    ....   ####       Boot Loader Version 1.0.1
                 ..........             built Mon Aug 26 18:55:20 UTC 2013
              ..........  ####        OS Version 1.0.4
          ####   ....  ##########       built Thu Apr 23 22:28:59 UTC 2015
       ##########   ##########
    ##########  ....   ####           Main Board: CodeWarrior TAP (3.3V)
       ####  ..........               Probe Tip:  Power Architecture JTAG/COP
          ..........
      ####   ....
   ##########                         Note: This product uses open-source
##########                            components.  See "help license"
   ####                               for details.

Network not configured - defaulting to DHCP
core> help
Help is available for these commands:
  arp           ARP table commands.
  ccs           Display/manage CCS firmware
  gdbproxy      Display/manage gdbproxy firmware
  help          Get help on commands
  host          Host table commands
  license       Displays open-source license details
  netparam      Show/set nonvolatile networking parameters.
  netstat       Display network protocol statistics.
  ping          Test if host is alive.
  reset         Reboot this device.
  route         Route table commands.
  tgreset       Reset target
  tgtty         Get/set tty settings for target serial
  who           List any open connections.
core> help netparam
Usage: netparam [subcommand <subcommand options>]

This command displays or sets nonvolatile networking
parameters. If called with no subcommand, it displays all
parameters.  When called with one of the subcommands listed
below, it changes the parameters associated with that command.
Note that when changed, some parameters will not be activated
until the unit is rebooted.
Use "netparam <subcommand> --help" for help on a specific 
subcommand.

Netparam recognizes the following subcommands:
         add_host               Add static host
         add_route              Add static route
         bootconfig             Boot method selection
         delete_host            Delete static host
         delete_route           Delete static route
         static_ip_address      Specify static IP address
         static_dns_server      Specify DNS server address

设置静态IP,命令会阻塞10s,这个时候CodeWarrior TAP的RX/TX灯变为绿色,

core> netparam static_ip_address 192.168.6.223 # wait for 10s
core> netparam add_route 192.168.6.254 gateway_ip 1 # hop_cnt=1
core> netparam bootconfig static:cw-tap0
Netmask defaults to 255.255.255.0
Using dynamic IP address 192.168.6.223                                          
core> ping 192.168.6.6
PING 192.168.6.6 (192.168.6.6): 56 data bytes
64 bytes from 192.168.6.6: seq=0 ttl=128 time=0.917 ms
64 bytes from 192.168.6.6: seq=1 ttl=128 time=0.640 ms

--- 192.168.6.6 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.640/0.778/0.917 ms

跨网段设置路由,有警告但是设置成功。

core> netparam add_route 192.168.12.0 192.168.6.254 1
Netmask defaults to 255.255.255.0
gateway_ip: Unknown host
route: netmask doesn't match route address
Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables
       route [-v] [-FC] {add|del|flush} ...  Modify routing table for AF.

       route {-h|--help} [<AF>]              Detailed usage syntax for specified AF.
       route {-V|--version}                  Display version/author and exit.

        -v, --verbose            be verbose
        -n, --numeric            don't resolve names
        -e, --extend             display other/more information
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB

  <AF>=Use '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) 
    ipx (Novell IPX) ddp (Appletalk DDP) x25 (CCITT X.25) 
SIOCADDRT: File exists
core> ping 192.168.12.16
PING 192.168.12.16 (192.168.12.16): 56 data bytes
64 bytes from 192.168.12.16: seq=0 ttl=127 time=2.608 ms
64 bytes from 192.168.12.16: seq=1 ttl=127 time=0.526 ms
64 bytes from 192.168.12.16: seq=2 ttl=127 time=0.585 ms

--- 192.168.12.16 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.526/1.239/2.608 ms

查看路由表

core> netparam add_route 192.168.16.0 192.168.6.254 1
Netmask defaults to 255.255.255.0
gateway_ip: Unknown host
route: netmask doesn't match route address
Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables
       route [-v] [-FC] {add|del|flush} ...  Modify routing table for AF.

       route {-h|--help} [<AF>]              Detailed usage syntax for specified AF.
       route {-V|--version}                  Display version/author and exit.

        -v, --verbose            be verbose
        -n, --numeric            don't resolve names
        -e, --extend             display other/more information
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB

  <AF>=Use '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) 
    ipx (Novell IPX) ddp (Appletalk DDP) x25 (CCITT X.25) 
SIOCADDRT: File exists
SIOCADDRT: File exists
core> netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
127.0.0.0       *               255.0.0.0       U         0 0          0 lo
169.254.0.0     *               255.255.0.0     U         0 0          0 usb0
192.168.6.0     *               255.255.255.0   U         0 0          0 eth0
192.168.6.0     192.168.6.254   255.255.255.0   UG        0 0          0 eth0
192.168.12.0    192.168.6.254   255.255.255.0   UG        0 0          0 eth0
192.168.16.0    192.168.6.254   255.255.255.0   UG        0 0          0 eth0

重启,需要把secureCRT的串口disconnect

core> reset
Close this configuration console to reboot...
(hit Ctrl+c to abort)

再重新打开,输入回车,和之前显示不一样了

Push enter to start console.

                  ####
               ##########
            ##########  ....          Freescale Semiconductor Inc.
               ####  ..........       Copyright (c) 2015
                  ..........  ####    All Rights Reserved
                     ....  ##########
                        ##########    Codewarrior TAP Firmware
                    ....   ####       Boot Loader Version 1.0.1
                 ..........             built Mon Aug 26 18:55:20 UTC 2013
              ..........  ####        OS Version 1.0.4
          ####   ....  ##########       built Thu Apr 23 22:28:59 UTC 2015
       ##########   ##########
    ##########  ....   ####           Main Board: CodeWarrior TAP (3.3V)
       ####  ..........               Probe Tip:  Power Architecture JTAG/COP
          ..........
      ####   ....
   ##########                         Note: This product uses open-source
##########                            components.  See "help license"
   ####                               for details.

Network configuration is static:cw-tap0
Using static IP address 192.168.6.223

这个时候,断开USB,采用USB供电,方可使用网络来连接,下载器自带了一个串口,设置串口参数,查看串口设置

core> help tgtty
Usage: tgtty [<options>]

Use this command to get and set target serial settings.  Without
options, this command displays current settings.  The following
options are accepted:
[reset]                                       -- terminates any open connections
[default]                                     -- set default settings
[<9600 | 19200 | 38400 | 57600 | 115200>]     -- baud rate
[<data5 | data6 | data7 | data8>]             -- data bits
[<stop1 | stop2>]                             -- stop bits
[<noparity | oddparity | evenparity>]         -- parity
[<rtscts | nortscts | rxtx>]                  -- hardware flow control
[<noxon | xon>]                               -- XON/XOFF flow control
[<echo | noecho>]                             -- whether the target echos

The default settings are:
9600 data8 stop1 noparity nortscts noxon echo
core> tgtty
115200 data8 stop1 noparity nortscts noxon echo

设置参数,会自动保存

core> tgtty 115200 data8 stop1 noparity nortscts noxon echo

恢复默认

core> tgtty default

使用这个串口,telnet登录下载器的1082端口。

【NXP】Lx2160的uart1口不好使

查看板卡设备存在

root@localhost:~# ls /dev/ttyAMA*
ttyAMA0  ttyAMA1 。

官方哪里又要了一个内和设备树补丁。这个补丁很重要,应该是更改了pl011的驱动匹配。

diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
index 2fe86aca32da..e316bb09f7a1 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
@@ -894,26 +894,29 @@
 		};
 
 		uart1: serial@21d0000 {
-			compatible = "arm,sbsa-uart","arm,pl011";
+			compatible = "arm,pl011", "arm,primecell";
 			reg = <0x0 0x21d0000 0x0 0x1000>;
 			interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
-			current-speed = <115200>;
+			clocks = <&clockgen 4 7>, <&clockgen 4 7>;
+			clock-names = "uart", "apb_pclk";
 			status = "disabled";
 		};
 
 		uart2: serial@21e0000 {
-			compatible = "arm,sbsa-uart","arm,pl011";
+			compatible = "arm,pl011", "arm,primecell";
 			reg = <0x0 0x21e0000 0x0 0x1000>;
 			interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
-			current-speed = <115200>;
+			clocks = <&clockgen 4 7>, <&clockgen 4 7>;
+			clock-names = "uart", "apb_pclk";
 			status = "disabled";
 		};
 
 		uart3: serial@21f0000 {
-			compatible = "arm,sbsa-uart","arm,pl011";
+			compatible = "arm,pl011", "arm,primecell";
 			reg = <0x0 0x21f0000 0x0 0x1000>;
 			interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
-			current-speed = <115200>;
+			clocks = <&clockgen 4 7>, <&clockgen 4 7>;
+			clock-names = "uart", "apb_pclk";
 			status = "disabled";
 		};
 
-- 

【Nxp】flexbuild_lsdk2108固件编译方法

一、通用指令

一、SD卡分区格式化
flex-installer -i pf -p 5P=200M:1536M:6G:-1 -d /dev/sdx

二、需要的下载包
firmware_ls1046afrwy_uboot_sdboot.img already exists ...
bootpartition_LS_arm64_lts_4.19.tgz already exists ...
rootfs_lsdk1909_LS_arm64_main.tgz already exists ...

三、下载包清楚指令
 flex-builder clean                          # clean all obsolete firmware/linux/apps image except distro rootfs
 flex-builder clean-rfs                      # clean distro rootfs, '-r ubuntu:main -a arm64' by default
 flex-builder clean-firmware                 # clean obsolete firmware image
 flex-builder clean-apps                     # clean obsolete apps component binary image
 flex-builder clean-linux 

二、ls1046 系统定制

1、下载包生成指令

$ flex-builder -i mkfw -m ls1046afrwy -b sd

$ flex-builder -i mkrfs -r ubuntu:main -m ls1046afrwy
$ flex-builder -c apps -r ubuntu:main -m ls1046afrwy

$ flex-builder -i mkboot -m ls1046afrwy -b sd

$ flex-builder -i merge-component -r ubuntu:main -m ls1046afrwy
$ flex-builder -i packrfs -r ubuntu:main -m ls1046afrwy

$ cd build/images
$ flex-installer -r rootfs_<sdk_version>_ubuntu_desktop_arm64.tgz -b boot_LS_arm64_lts_5.10.tgz -d /dev/sdx


$ flex-installer -i pf -d /dev/sdx   (partition and format the target storage device)
$ flex-installer -b boot_LS_arm64_lts_5.10.tgz -r rootfs_lsdk2108_ubuntu_main_arm64.tgz -f firmware_ls1046ardb_sdboot.img -d /dev/sdx

2、定制内核

 flex-builder -c linux:custom -a arm64  -m ls1046afrwy -b sd
 flex-builder -c linux -a arm64 -m ls1046afrwy -b sd

 flex-builder -i mkbootpartition -a arm64 -m ls1046afrwy -b sd

3、网络配置

auto fm1-mac1
iface fm1-mac1 inet dhcp

auto fm1-mac5
iface fm1-mac5 inet dhcp

auto fm1-mac6
iface fm1-mac6 inet dhcp

auto fm1-mac10
iface fm1-mac10 inet dhcp

4、SCTP协议栈支持

需要在内核选择确定。

三、LX2160 系统定制

1、编译内核

 flex-builder -c linux:custom -a arm64  -m lx2160ardb -b sd
 flex-builder -c linux -a arm64 -m lx2160ardb -b sd

 flex-builder -i mkbootpartition -a arm64 -m lx2160ardb -b sd

2、编译文件系统

 flex-builder -i mkrfs -r ubuntu:main -m lx2160ardb
 flex-builder -i packrfs -r ubuntu:main -m lx2160ardb

3、构建BOOTLOADER

 flex-builder -c atf -m lx2160ardb -b sd
 flex-builder -i mkfw -m lx2160ardb -b sd

 flex-builder -i mkfw -m lx2160ardb_rev2 -b sd

4、下载更新

 cd build/images
 flex-installer -r rootfs_<sdk_version>_ubuntu_desktop_arm64.tgz -b boot_LS_arm64_lts_5.10.tgz -d /dev/sdx

5、网络配置

dhclient 是网卡获取IP,可以上网。
安装network-manager

四、LX2160 REV2系统定制

1、编译内核

flex-builder -c linux:custom -a arm64 -m lx2160ardb_rev2 -b sd
flex-builder -c linux -a arm64 -m lx2160ardb_rev2 -b sd
flex-builder -i mkbootpartition -a arm64 -m lx2160ardb_rev2 -b sd

2、编译文件系统

flex-builder -i mkrfs -r ubuntu:main -m lx2160ardb_rev2
flex-builder -i packrfs -r ubuntu:main -m lx2160ardb_rev2

3、构建BOOTLOADER

flex-builder -c atf -m lx2160ardb_rev2 -b sd
flex-builder -i mkfw -m lx2160ardb_rev2 -b sd

flex-builder -c atf -m lx2160ardb_rev2 -b emmc
flex-builder -i mkfw -m lx2160ardb_rev2 -b emmc

4、下载更新

cd build/images
flex-installer -r rootfs__ubuntu_desktop_arm64.tgz -b boot_LS_arm64_lts_5.10.tgz -d /dev/sdx

5、网络配置

dhclient 是网卡获取IP,可以上网。
安装network-manager

6、实时补丁

 flex-builder -c linux:custom -a arm64  -m lx2160ardb_rev2 -b sd
 flex-builder -c linux:linux:LSDK-21.08-RT -a arm64 -m  lx2160ardb_rev2 -b sd
 flex-builder -i mkbootpartition -a arm64 -m lx2160ardb_rev2 -b sd

五、ARM DPDK Kmods编译

#KSRC ?= ./../../../flexbuild_lsdk2108/components/linux/linux/
KSRC ?= ./../../../flexbuild_lsdk2108/build/linux/linux/arm64/LS/output/LSDK-21.08/
ENV:=ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

all:
	        make $(ENV) -C $(KSRC)/ M=$(PWD)

clean:
	        make $(ENV) -C $(KSRC)/ M=$(PWD) clean

六、ARM DPDK 编译

flex-builder -c openssl -a arm64 # to resolve the dependency on OpenSSL package
flex-builder -c linux -a arm64 # to resolve the dependency of KNI module
flex-builder -c dpdk -a arm64 # build dpdk application
flex-builder -c pktgen_dpdk -a arm64 # to generate dpdk pktgen application
flex-builder -c ovs_dpdk # to generate ovs-dpdk binaries
flex-builder -i merge-component -a arm64 # merge app components into target rootfs

七、启动IEEE1588

1、IEEE1588开关配置

由于硬件设置问题,需要增加启动变量bootcmd。

修改RCW,增加如下代码:
EC2_PMUX=2

获取EC2状态(最高位有效):
i2cget -y 0 0x66 0x54

设置EC2状态(最高位有效):
i2cset -y 0 0x66 0x54 0xA0

Boot获取EC2状态(最高位有效):
i2c md.0 66 54

Boot设置EC2状态(最高位有效):
i2c mw.0 66 54 a0

2、寄存器配置1pps

tmr-ctl		        devmem2 0x8b95080 w 0xA0004	
tmr-add		        devmem2 0x8b950a0 w 0xcccccccd
tmr-prsc		devmem2 0x8b950a8 w 50000
tmr-fiper1		devmem2 0x8b950d0 w 0x3B9AC9F6
tmr-fiper2		devmem2 0x8b950d4 w 0x989676
tmr-fiper3		devmem2 0x8b950d8 w 0x7A116

八、FLASH更新固件

把固件从SD卡导入内存:
load mmc $load_addr firmware_lx2160ardb_rev2_xspiboot.img
load mmc 0:4 $load_addr firmware_lx2160ardb_xspiboot.img

格式化flash:
sf probe 0:0

写入FLASH:
sf erase 0 +$filesize && sf write $load_addr 0 $filesize

复位重启:
reset
qixis_reset
qixis_reset altbank

九、ARM OpenSSL

1、编译:

$ cd flexbuild
$ source setup.env
Build cryptodev-linux:
$ flex-builder -c cryptodev_linux -a arm64 # automatically setup cross-toolchain and fetch 
cryptodev-linux repository to build
Build OpenSSL:
$ flex-builder -c openssl -a arm64
Merge OpenSSL and cryptodev-linux components into target rootfs:
$ flex-builder -i merge-component -a arm64
Generate bootpartition tarball:
$ flex-builder -i mkbootpartition -a arm64
   flex-builder -i mkbootpartition -a arm64 -m lx2160ardb_rev2 -b sd

2、配置:

cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
修改为:
#include /etc/ld.so.conf.d/*.conf
# libc default configuration
/usr/local/lib
# Multiarch support
/usr/local/lib/aarch64-linux-gnu
/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu/libfakeroot

ldconfig

3、加载模块


modprobe caamalg_desc
modprobe caamhash_desc
modprobe dpaa2_caam
modprobe cryptodev
modprobe caamalg_qi
sudo modprobe caam
user@localhost:~$ sudo modprobe cryptodev
[sudo] password for user:

user@localhost:~$ ls /dev/crypto
/dev/crypto

user@localhost:~$ openssl engine
(devcrypto) /dev/crypto engine
(dynamic) Dynamic engine loading support

4、Verify the CAAM offloading

Hardware operations can be monitored with the interrupt counters for CAAM JR and QI (DPAA1 and DPAA2) interfaces.

user@localhost:~$ cat /proc/interrupts | grep jr
78: 20 0 0 0 GICv2 103 Level 1710000.jr
79: 0 0 0 0 GICv2 104 Level 1720000.jr
80: 0 0 0 0 GICv2 105 Level fsl-jr0

user@localhost:~$ openssl enc -aes-256-cfb -k secret -P -md sha1
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
salt=233157F098D1B0E8
key=D2B0C0C088AA7DAA6CF37CC856E283E3B0C3DD2BE155688DE18593EB3F997776
iv =A4E2C86E0DBA1211B5A4B02EBEFF6DC4

user@localhost:~$ cat /proc/interrupts | grep jr
78: 54 0 0 0 GICv2 103 Level 1710000.jr
79: 69 0 0 0 GICv2 104 Level 1720000.jr
80: 0 0 0 0 GICv2 105 Level fsl-jr0

fatal error: linux/compiler-gcc7.h: No such file or directory

 HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
*** Default configuration is based on 'sandbox_defconfig'
make[4]: Leaving directory '/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10'
make -C /opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10 tools-only  HOSTCFLAGS="-I/opt/Tina_rel/tina/out/host/include -I/opt/Tina_rel/tina/out/host/usr/include  -O2 -I/opt/Tina_rel/tina/out/host/include -I/opt/Tina_rel/tina/out/host/usr/include " HOSTLDFLAGS="-L/opt/Tina_rel/tina/out/host/lib -L/opt/Tina_rel/tina/out/host/usr/lib "
make[4]: Entering directory '/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10'
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/config.h
  UPD     include/config.h
  GEN     include/autoconf.mk
In file included from include/linux/compiler.h:54:0,
                 from /opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/arch/sandbox/include/asm/bitops.h:20,
                 from include/linux/bitops.h:110,
                 from /opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/include/common.h:20:
include/linux/compiler-gcc.h:114:1: fatal error: linux/compiler-gcc7.h: No such file or directory
 #include gcc_header(__GNUC__)
 ^~~~
compilation terminated.
/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/scripts/Makefile.autoconf:64: recipe for target 'include/autoconf.mk' failed
make[6]: *** [include/autoconf.mk] Error 1
/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/Makefile:464: recipe for target 'silentoldconfig' failed
make[5]: *** [silentoldconfig] Error 1
make[4]: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/uboot.release'.  Stop.
make[4]: Leaving directory '/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10'
Makefile:46: recipe for target '/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/.built' failed
make[3]: *** [/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/u-boot-2014.10/.built] Error 2
make[3]: Leaving directory '/opt/Tina_rel/tina/tools/mkimage'
tools/Makefile:138: recipe for target 'tools/mkimage/compile' failed
make[2]: *** [tools/mkimage/compile] Error 2
make[2]: Leaving directory '/opt/Tina_rel/tina'
tools/Makefile:137: recipe for target '/opt/Tina_rel/tina/out/violin-F1C200s/staging_dir/target/stamp/.tools_install_yyyynyyynyyyyyynnnyyyyyyyyyynnyyyyyyynynyyynnyyyy' failed
make[1]: *** [/opt/Tina_rel/tina/out/violin-F1C200s/staging_dir/target/stamp/.tools_install_yyyynyyynyyyyyynnnyyyyyyyyyynnyyyyyyynynyyynnyyyy] Error 2
make[1]: Leaving directory '/opt/Tina_rel/tina'
/opt/Tina_rel/tina/build/toplevel.mk:275: recipe for target 'world' failed
make: *** [world] Error 2

#### make failed to build some targets (03:04 (mm:ss)) ####
cp ./out/violin-F1C200s/compile_dir/host/u-boot-2014.10/include/linux/compiler-gcc5.h ./out/violin-F1C200s/compile_dir/host/u-boot-2014.10/include/linux/compiler-gcc7.h

compile_dir/host/automake-1.15/.configured’ failed

make[3]: Entering directory '/opt/Tina_rel/tina/tools/automake'
(cd /opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/automake-1.15; AUTOM4TE=/opt/Tina_rel/tina/out/host/bin/autom4te AUTOCONF=/opt/Tina_rel/tina/out/host/bin/autoconf AUTOMAKE=/opt/Tina_rel/tina/out/host/bin/automake ACLOCAL=/opt/Tina_rel/tina/out/host/bin/aclocal AUTOHEADER=/opt/Tina_rel/tina/out/host/bin/autoheader LIBTOOLIZE=/opt/Tina_rel/tina/out/host/bin/libtoolize LIBTOOL=/opt/Tina_rel/tina/out/host/bin/libtool M4=/opt/Tina_rel/tina/out/host/bin/m4 AUTOPOINT=true STAGING_DIR_HOST="" ./bootstrap.sh)
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at ./bin/automake.tmp line 3938.
Makefile:50: recipe for target '/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/automake-1.15/.configured' failed
make[3]: *** [/opt/Tina_rel/tina/out/violin-F1C200s/compile_dir/host/automake-1.15/.configured] Error 255
make[3]: Leaving directory '/opt/Tina_rel/tina/tools/automake'
tools/Makefile:138: recipe for target 'tools/automake/compile' failed
make[2]: *** [tools/automake/compile] Error 2
make[2]: Leaving directory '/opt/Tina_rel/tina'
tools/Makefile:137: recipe for target '/opt/Tina_rel/tina/out/violin-F1C200s/staging_dir/target/stamp/.tools_install_yyyynyyynyyyyyynnnyyyyyyyyyynnyyyyyyynynyyynnyyyy' failed
make[1]: *** [/opt/Tina_rel/tina/out/violin-F1C200s/staging_dir/target/stamp/.tools_install_yyyynyyynyyyyyynnnyyyyyyyyyynnyyyyyyynynyyynnyyyy] Error 2
make[1]: Leaving directory '/opt/Tina_rel/tina'
/opt/Tina_rel/tina/build/toplevel.mk:275: recipe for target 'world' failed
make: *** [world] Error 2

#### make failed to build some targets (32 seconds) ####
修改 ./out/violin-F1C200s/compile_dir/host/automake-1.15/bin/automake.in 3883 行

  $text =~ s/\${([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;

改为:

  $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;

[F1c100s/F1c200s]automake failed with exit status: 255

Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /home/recologypower/f1c200s/C200S_Linux_V0.1/out/sunivw1p1/linux/common/buildroot/host/usr/bin/automake line 4113.
autoreconf: /home/recologypower/f1c200s/C200S_Linux_V0.1/out/sunivw1p1/linux/common/buildroot/host/usr/bin/automake failed with exit status: 255

staging_dir/host/bin/automake的4113行报错
因为新版的perl不在支持左大括号的使用,
进入这个文件删掉大括号,问题解决。

[f1c100s/f1c200s]spi-flash系统制作

spi-flash系统生成需要进行四部曲: “uboot” 、 “dtb” 、“kernel” 和 “rootfs” 。以16M flash举例, 介绍 spi flash 的适配过程。 分区表如下:

分区序号 分区大小 分区作用 地址空间及分区名
mtd0 1MB (0x100000) spl+uboot 0x0000000-0x0100000 : “uboot”
mtd1 64KB (0x10000) dtb文件 0x0100000-0x0110000 : “dtb”
mtd2 4MB (0x400000) linux内核 0x0110000-0x0510000 : “kernel”
mtd3 剩余 (0xAF0000) 根文件系统 0x0510000-0x1000000 : “rootfs”

一、安装交叉编译环境

# 此处为获取7.2.1版本,您可获取其他版本或者通过链接直接下载
wget http://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabi/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz

tar -vxJf gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz
sudo cp -r ./gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi /opt/

sudo vim /etc/bash.bashrc

# 在文件末尾 添加以下内容
PATH="$PATH:/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin"
# 添加完毕

# 使路径生效
source /etc/bash.bashrc

此时可用 arm-linux-gnueabi-gcc -v 进行测试;若普通用户状态下没有成功,通过 sudo su 切换到root用户再尝试;

二、uboot配置及编译

1、从GitHub下载uboot源码

sudo apt-get install git
git clone https://github.com/Lichee-Pi/u-boot.git
cd u-boot

# 查看分支
git branch -a
# 切换到 Nano 分支
git checkout nano-v2018.01

2、uboot源码结构

.
├── api             //封装一些平台无关的操作,如字符串打印,显示,网络,内存
├── arch            //以平台架构区分
│   ├──arm
│   │   └──cpu
│   │   │   └──arm926ejs
│   │   │   │   └──sunxi   //cpu相关的一些操作,如定时器读取
│   │   │   │   │   └──u-boot-spl.lds  //spl的放置方法
│   │   └──dts
│   │   │   └──suniv-f1c100s-licheepi-nano.dts   // f1c100s芯片的一些配置
│   │   │   └──suniv-f1c100s-licheepi-nano.dtb
│   │   │   └──suniv-f1c100s.dtsi
│   │   │   └──suniv.dtsi
│   │   └──lib      //一些库文件
│   │   └──mach-sunxi
│   │   │   └──board.c          //board_init_f
│   │   │   └──dram_sun4i.c     //ddr的操作,复位,时钟,延时,odt,etc.
│   │   │   └──dram_helpers.c   //ddr的设置及读写测试
├── board
│   ├──sunxi
│   │   └──board.c              //sunxi_board_init 入口
│   │   └──dram_suniv.c        //DRAM的一些默认参数
├── cmd             //Uboot命令行的一些命令
├── common          //含spl
├── configs         //menuconfig里的默认配置,比如各类驱动适配
│   ├── licheepi_nano_defconfig
│   ├── licheepi_nano_spiflash_defconfig
├── disk            //硬盘分区的驱动
├── doc
├── drivers         //外设驱动
├── dts
├── examples
├── fs              //多种文件系统
├── include
│   ├──configs
│   │   └──sunxi_common.h   //预配置的参数,如串口号等
│   │   └──suniv.h
├── lib             //加密压缩等算法
├── net             //nfs,tftp等网络协议
├── post
├── scripts

3、uboot配置

# 此处告知make采用arm-linux-gnueabi下的所有交叉编译工具,目标架构为Arm,设定各项默认配置为 nano 的spiflash支持版
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- licheepi_nano_spiflash_defconfig

# 若不带spi-flash的板子,请换成 licheepi_nano_defconfig

修改文件uboot源码目录下 进入 ./include/configs/suniv.h
#define CONFIG_BOOTCOMMAND   "sf probe 0:50000000; "                 \
                             "sf read 0x80C00000 0x100000 0x4000; "  \
                             "sf read 0x80008000 0x110000 0x400000; " \
                             "bootz 0x80008000 - 0x80C00000"

# 进行可视化配置
make ARCH=arm menuconfig

#取消勾选 [ ] Enable a default value for bootcmd
#勾选 [*] Enable boot arguments;
#在下方一项中填入 bootargs 参数:
console=ttyS0,115200 panic=5 rootwait root=/dev/mtdblock3 rw rootfstype=jffs2
#(root=/dev/mtdblock3 指的是mtd设备第三分区,分区指定在dts中声明)

4、添加LCD支持

ARM architecture ‣ Enable graphical uboot console on HDMI, LCD or VGA 为 Y
#接着配置同级的 LCD panel timing details 为:
#分辨率800*480
x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0
#分辨率480*272
x:480,y:272,depth:18,pclk_khz:10000,le:42,ri:8,up:11,lo:4,hs:1,vs:1,sync:3,vmode:0
并将 LCD panel backlight pwm pin 设为:PE6 (管脚参照原理图)

5、uboot编译

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4

编译完成后,可一看到目录下多了一堆以u-boot带头的文件,我们只需取 u-boot-sunxi-with-spl.bin 即可。

三、Linux配置及编译

1、从GitHub下载Linux源码

#下载代码
git clone --depth=1 -b f1c100s-480272lcd-test https://github.com/Icenowy/linux.git

下载配置文件:

下载 .config 文件,放入源码主目录进行替换 (若下载时文件名有变,请重命名回 .config );

2、DTS修改

修改内核源码目录下的 ./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dts

&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_a>;
    status = "okay";
    spi-max-frequency = <50000000>;
    flash: w25q128@0 {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "winbond,w25q128", "jedec,spi-nor";
        reg = <0>;
        spi-max-frequency = <50000000>;
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;

            partition@0 {
                label = "u-boot";
                reg = <0x000000 0x100000>;
                read-only;
            };

            partition@100000 {
                label = "dtb";
                reg = <0x100000 0x10000>;
                read-only;
            };

            partition@110000 {
                label = "kernel";
                reg = <0x110000 0x400000>;
                read-only;
            };

            partition@510000 {
                label = "rootfs";
                reg = <0x510000 0xAF0000>;
            };
        };
    };
};

此处在dts中为mtd设备预先划分好了分区内容,内核将会自动解析 。

3、内核配置修改

#打开可视化配置窗口
make ARCH=arm menuconfig

勾选 File systems ‣ Miscellaneous filesystems ‣ Journalling Flash File System v2 (JFFS2) support 。

勾选 Device Drivers -> Memory Technology Device (MTD) support ,及下面子项:

  • Caching block device access to MTD devices  #为了生成/dev/mtdblock*设备,不选会报错

勾选 Device Drivers -> SPI support ,及下面子项:

Allwinner A31 SPI Controller  (勾选)
Allwinner A10 SoCs SPI controller   (不勾选)

修改源码下的 ./drivers/mtd/ spi-nor/ spi-nor.c

修改对应spi-flash;如 w25q128 :

{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
// 修改为 (不使用sector,使用块擦除):
{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, 0) },

4、内核编译

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4    #请自行修改编译线程数

生成的 zImage 在 arch ‣ arm ‣ boot 目录下

编译工具链为 arm-linux-gnueabi,工具链的安装请参考 uboot 编译部分 。

四、DTB文件编译

进入Linux目录,执行如下代码:

设备树在源码的 linux ‣ arch ‣ arm ‣ boot ‣ dts ‣ suniv-f1c100s-licheepi-nano.dts;

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs -j4

生成的 dtb文件 在 dts同级目录下 。

五、根文件系统编译

1、下载依赖包

apt-get install linux-headers-$(uname -r)

2、buildroot下载配置

wget https://buildroot.org/downloads/buildroot-2017.08.tar.gz
tar xvf buildroot-2017.08.tar.gz
cd buildroot-2017.08/
make menuconfig
Target options  --->

    Target Architecture Variant (arm926t)  --->   // arm926ejs架构
[ ] Enable VFP extension support                  // Nano 没有 VFP单元,勾选会导致某些应用无法运行
    Target ABI (EABI)  --->
    Floating point strategy (Soft float)  --->    // 软浮点

System configuration  --->

    (Lichee Pi) System hostname                   // hostname
    (licheepi) Root password                      // 默认账户为root 密码为licheepi
    [*] remount root filesystem read-write during boot  // 启动时重新挂在文件系统使其可读写

3、编译

若编译时,buildroot下载软件包速度太慢,请下载 dl.zip ,将其中的软件包解压至 buildroot ‣ dl 下;

#编译命令:
make

编译完成的镜像包,是在 buildroot-2017.08 ‣ output ‣images ‣ rootfs.tar 中找到 。

六、一键打包生成SPIflash固件脚本

脚本下载:

把.txt改成.sh。