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.

月度归档 12月 25, 2019

[f1c100s/f1c200s]u-boot 添加LED驱动

UBOOT版本:2018.01

实验目标:u-boot启动后点亮3个led灯
u-boot启动过程中会调用crt0.S汇编代码,在该汇编代码中点亮LED.

LED对于引脚如下:
REG –GPE4
GREEN – GPE5
YELLOW – GPE6

1、GPIO驱动实现
u-boot的驱动程序都放在drivers目录下。
LED驱动属于GPIO驱动。
所以led驱动应该写在drivers\gpio目录下,下面是已经实现的sunxi_gpio.c驱动。

详细代码可查阅:u-boot-nano-v2018.01\drivers\gpio\sunxi_gpio.c

sunxi_gpio.c里的函数在u-boot-nano-v2018.01/include/asm-generic/gpio.h头文件中被声明。

2、LED驱动实现,这部前需要先实现上面的GPIO驱动

在board目录下添加led.c,代码如下

#include <common.h>
#include <asm/io.h>
#include <asm/arch/gpio.h>
#include <status_led.h>
#include <asm-generic/gpio.h>  /*下面函数在这个头文件中声明*/
//int gpio_direction_output(unsigned gpio, int value);
//初始化 LED(PE4、PE5、PE6)
void coloured_LED_init(void)
{
	/* Clock is enabled in board_early_init_f() */
	//gpio_direction_output函数在u-boot-nano-v2018.01\drivers\gpio\sunxi_gpio.c中实现,这里直接调用就可以了
	gpio_direction_output(CONFIG_RED_LED, 0);
	gpio_direction_output(CONFIG_GREEN_LED, 0);
	gpio_direction_output(CONFIG_YELLOW_LED, 0);


}


#ifdef CONFIG_RED_LED
void red_led_on(void)
{
	gpio_set_value(CONFIG_RED_LED, 1);
}

void red_led_off(void)
{
	gpio_set_value(CONFIG_RED_LED, 0);
}
#endif

#ifdef CONFIG_GREEN_LED
void green_led_on(void)
{
	gpio_set_value(CONFIG_GREEN_LED, 1);
}

void green_led_off(void)
{
	gpio_set_value(CONFIG_GREEN_LED, 0);
}
#endif

#ifdef CONFIG_YELLOW_LED
void yellow_led_on(void)
{
	gpio_set_value(CONFIG_YELLOW_LED,1);
}

void yellow_led_off(void)
{
	gpio_set_value(CONFIG_YELLOW_LED, 0);
}
#endif

注意:#include <asm-generic/gpio.h> 头文件不能少。

然后编辑led.c同目录下的Makefile文件,把led.o编译进去。
Makefile中添加如下一行:

obj-$(CONFIG_SUNXI_LED )  += led.o

3、配置声明
在include/configs/suniv.h中添加如下声明。

#define CONFIG_SUNXI_LED 1		/*开启LED支持*/
#define CONFIG_RED_LED  132	    /*PGE4*/
#define CONFIG_GREEN_LED  133	/*PGE5*/
#define CONFIG_YELLOW_LED  134	/*PGE6*/

4、在crt0.S汇编代码中点亮LED
在crt0.S中调用以下函数点亮3个led灯:

bl coloured_LED_init
bl red_led_on
bl green_led_on
bl yellow_led_on

5、编译下载:

cd “你的uboot目录”
# 编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j8
# usb下载u-boot目标板
sunxi-fel uboot ./u-boot-sunxi-with-spl.bin  

[f1c100s/f1c200s]uboot编译 sh: 1: python: not found ,cripts/dtc/pylibfdt/_libfdt.so’ failed解决

1、问题分析

根据报错打印提示可以很容易定位python not found,也就是说找不到python软件或者库。用下面指令查看下到底是不是python安装问题:

ls -l /usr/bin/python*

-rwxr-xr-x 1 root root 3637096 Nov  7 18:07 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Oct 25  2018 /usr/bin/python3 -> python3.6
-rwxr-xr-x 2 root root 4526456 Nov  7 18:44 /usr/bin/python3.6
lrwxrwxrwx 1 root root      33 Nov  7 18:44 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4526456 Nov  7 18:44 /usr/bin/python3.6m
lrwxrwxrwx 1 root root      34 Nov  7 18:44 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
-rwxr-xr-x 1 root root    1018 Oct 29  2017 /usr/bin/python3-jsondiff
-rwxr-xr-x 1 root root    3661 Oct 29  2017 /usr/bin/python3-jsonpatch
-rwxr-xr-x 1 root root    1342 May  2  2016 /usr/bin/python3-jsonpointer
-rwxr-xr-x 1 root root     398 Nov 16  2017 /usr/bin/python3-jsonschema
lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config

这也太奇怪了,明明是安装了python,并且是python2和python3都安装了,大家有没有注意到提示名字的不带数字,那可能是连接名字问题。

2、解决方式

sudo ln -s /usr/bin/python2.7 /usr/bin/python

[Openwrt]自启动python脚本

1、安装nohup软件

opkg -d usb install coreutils-nohup

2、编写启动脚本

vim /etc/init.d/mystart

#!/bin/sh /etc/rc.common
START=99
start(){
       nohup python3 -u /mnt/TFCard/opkg/uart.py >/mnt/TFCard/opkg/output.txt 2>&1 &
}
stop(){
       nohup python3 -u /mnt/TFCard/opkg/uart.py -s >/mnt/TFCard/opkg/output.txt 2>&1 &
}
restart(){
       nohup python3 -u /mnt/TFCard/opkg/uart.py >/mnt/TFCard/opkg/output.txt 2>&1 &
}

chmod -R 777 init.d/mystart #设置权限,否则无法激活开机启动,提示权限不足

/etc/init.d/mystart enable #激活开机启动
/etc/init.d/mystart start #运行start函数启动程序

[Openwrt]主机名修改

/package/base-files/files/bin下的config_generate中修改     hostname

set system.@system[-1].hostname='QingLink'
set system.@system[-1].timezone='CST-8'
set system.@system[-1].ttylogin='0'
set system.@system[-1].log_size='64'
set system.@system[-1].urandom_seed='0'

set system.ntp='timeserver'
set system.ntp.enabled='1'
set system.ntp.enable_server='1'
add_list system.ntp.server='0.cn.pool.ntp.org'
add_list system.ntp.server='1.pool.ntp.org'
add_list system.ntp.server='2.cn.pool.ntp.org'
add_list system.ntp.server='3.cn.ntp.org.cn'

option hostname Openwrt 设定主机名
option timezone Asia/Shanghai 时区设置为亚洲/上海
option timezone CST-8 正8区
list server 就是ntp服务器了。