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.

Author Archive by stormwind

【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

【Ubuntu】Ubuntu20.04 rc-local 配置开机自启动脚本

1. rc-local服务简介

Linux中的rc-local服务是一个开机自动启动的,调用开发人员或系统管理员编写的可执行脚本或命令的,它的启动顺序是在系统所有服务加载完成之后执行。

ubuntu20.04系统已经默认安装了rc-local.service服务,但是不知什么原因系统把这个服务给“隐蔽”了,所以如果不做一番操作是无法使用的。

2. 配置

rc-local服务设置为开机自启动(本文操作都在root用户下,或使用sudo)。

首先将rc-local.service文件复制到system目录下

cp /usr/lib/systemd/system/rc-local.service /etc/systemd/system/

新建rc.local文件

大家不用奇怪,ubuntu20.04/etc/目录下是没有rc.local文件的,需要我们手动建立一个。

touch /etc/rc.local
chmod 755 /etc/rc.local
echo '''#!/bin/bash''' >> /etc/rc.local

设置开机启动rc-local

systemctl start rc-local
systemctl enable rc-local
init 6

重启系统后,通过命令systemctl status rc-local查看服务已经正常开启了。

3.在rc.local中添加你开机需要自动执行的脚本

至此,你就可以在rc.local文件中添加你想添加的开机自启动脚本了。

【文件系统】ramFs

一、简介:

     ramfs是Linux下一种基于RAM做存储的文件系统。在使用过程中你就可以把ramfs理解为在普通的HDD上建立了一个文件系统,而现在HDD被替换成了RAM,因为是RAM做存储所以会有很高的存储效率。由于ramfs的实现就相当于把RAM作为最后一层的存储,所以在ramfs中不会使用swap。你什么时候听过会把HDD上的文件swap到哪里去吗?平常说的swap都是针对内存来说的,而ramfs底层的存储是RAM,虽然不是HDD,但是在Linux看来它就跟HDD一样。但是ramfs有一个很大的缺陷就是它会吃光系统所有的内存,即使你mount的时候指定了大小,同时它也只能被root用户访问。测试方法很简单:

sudo mount -t ramfs -o size=10M ramfs ./ramfs/

sudo dd if=/dev/zero of=./ramfs/test.file bs=1M count=20

测试时你会发现上面这个操作是能成功的,或者你再自己虚拟机上干脆做狠点,直接写一个比内存更大的文件,你会发现瞬间系统就卡主了。另外在dd命令如果不以root用户执行就会权限不够:

dd: opening `./ramfs/test.file’: Permission denied

二、测试:

    使用工具

    (1)  树莓派 官方镜像 

  (2)putty 进行 登录, 并操作

    Note: 本实验直接采用的是 root 用户进行登录实验
  1. 登录 Linux 系统;
  2. 准备 一个10M的文件;

3. 创建一个测试目录并将测试目录挂载到虚拟内存

  1. 将10M的文件多次传入, 观察内存变化

(1) 未操作前的内存 free 的大小、buff/cache 的大小

(2) 三次拷贝10M的文件进挂载的目录时 free 的大小变化,buff/cache 的大小变化

(3) 删除掉之前拷贝的三个10M文件之后 free 的大小变化, buff/cache 的大小变化

三、综上:

 ramfs 使用时, 无论设置的大小为多大, 在内存充足的情况下, 是可以无限放置文件的, 本例中设置大小为1M, 放置文件总大小为30M, 以此可见, 使用大小的管理需要自行控制...

Note:

 另外本人还试过

  (1)  输入大于内存的文件, 结果系统无响应了, 但是IP还是能够扫描到

  (2) 当使用过程中 available 还可以被 应用程序 使用的物理内存大小 一直没变化过, 当free降为0时available开始发生变化, 并且逐步降为0时系统无响应

【NMEA】校验和计算

uint8_t GPS_Check(uint8_t *p)
{
        uint8_t checksum=0;
        uint8_t i=0;


        while(p[i] !=0)
        {
                checksum ^=p[i];
                i++;
        }
        return checksum;
}

【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端口。

【OPENWRT】 RT5350 SPI I2C驱动简单说明

openwrt中已经支持 RT5350 的SPI I2C等驱动。

一、选择SPI、I2C 功能

-> Kernel modules
  -> SPI Support
  -> I2C support

二、修改设备树

vi target/linux/ramips/dts/rt5350.dtsi

 i2c@900 {
                        compatible = "link,rt5350-i2c", "ralink,rt2880-i2c";
                        reg = <0x900 0x100>;

                        resets = <&rstctrl 16>;
                        reset-names = "i2c";

                        #address-cells = <1>;
                        #size-cells = <0>;

                        pinctrl-names = "default";
                        pinctrl-0 = <&i2c_pins>;

                        status = "disabled";
                };

                spi@b00 {
                        compatible = "ralink,rt5350-spi";
                        reg = <0xb00 0x100>;

                        resets = <&rstctrl 18>;
                        reset-names = "spi";

                        #address-cells = <1>;
                        #size-cells = <1>;

                        pinctrl-names = "default";
                        pinctrl-0 = <&spi_pins &spi_cs1>;

                        status = "disabled";
                };

配置文件默认是不启用 SPI I2C 的。我们需要把 status = “disabled”; 改为 status = “okay”;对于 I2C,我们还要修改模板设备树文件:

pinctrl {
                state_default: pinctrl0 {
                        gpio {
                                ralink,group = "i2c", "jtag", "rgmii", "mdio", "uartf";
                                ralink,function = "gpio";
                        };
                };
        };

复用功能”i2c”,”jtag”, “rgmii”, “mdio”, “uartf” 等默认都复用为 gpio 口,要启用 I2C,需要去掉 i2c。同样,我们还需要启用 uartf。所有,修改为:

pinctrl {
                state_default: pinctrl0 {
                        gpio {
                                ralink,group =  "jtag", "rgmii", "mdio";
                                ralink,function = "gpio";
                        };
                };
        };

【GOLang】golang cgo交叉编译 linux arm64

一、交叉编译工具链安装

二、设置环境变量

CGO_ENABLED=1: 因为我们的程序使用到了Cgo,因此编译打开Cgo标志,默认情况是关闭的。
CC=aarch64-linux-gnu-gcc:指定CC也就是gcc编译命令使用交叉编译工具 aarch64-linux-gnu-gcc,也就是我们之前安装的交叉编译工具。
GOOS=linux:编译目标系统为Linux
GOARCH=arm64:编译目标的指令集架构为 64位 arm 架构
-ldflags ‘-s -w’:这个选项是为了移除编译后的程序的编译调试信息,减少可执行文件的体积。
–extldflags “-static -fpic”:静态编译,也就是会把使用到的动态库,静态链接到程序中,该指令存在时候可能会有warning提示,这是因为有些库文件是不能被静态链接的,gcc 编译器不支持 参考 [6]。

【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";
 		};
 
--