一、GPIO-LED
1. 首先查看电路,看看led灯接在哪个IO口,然后设置gpio口
DTS文件gpio-leds内容
gpio-leds {
compatible = "gpio-leds";
wan {
label = "deco:wan"; // 使用于01_leds文件
gpios = <&gpio2 4 1>; //使用了gpio2的第4个引脚,1 表示高电平有效,就是说电路的led阴极接地。
};
lan4 {
label = "deco:lan4";
gpios = <&gpio2 3 1>;
};
lan3 {
label = "deco:lan3";
gpios = <&gpio2 2 1>;
};
lan2 {
label = "deco:lan2";
gpios = <&gpio2 1 1>;
};
lan1 {
label = "deco:lan1";
gpios = <&gpio2 0 1>;
};
};
2. target/linux/ramips/base-files/etc/uci-defaults/01_leds 修改led使用ucidef_set_led_netdev函数。使灯对应相应功能。
在age/base-files/files/lib/functions/uci-defaults.sh查找相应的uci读取函数功能。
3.build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/linux-3.10.49/drivers/leds/leds-gpio.c
led-gpio驱动分析。
static struct platform_driver gpio_led_driver = {
.probe
= gpio_led_probe,
.remove
= gpio_led_remove,
.driver
= {
.name
= "leds-gpio",
.owner
= THIS_MODULE,
.of_match_table = of_match_ptr(of_gpio_leds_match),
},
};
当dts文件里面的compatible = "gpio-leds",匹配到驱动的name,调用驱动中的probe函数。
接着看驱动怎么去解析uci读取的dts的配置。
看到static int gpio_led_probe(struct platform_device *pdev)
里面看到gpio_leds_create_of这个函数,这个函数就是读取UCI的配置
for_each_child_of_node(np, child) {
struct gpio_led led = {};
enum of_gpio_flags flags;
const char *state;
led.gpio = of_get_gpio_flags(child, 0, &flags);
led.active_low = flags & OF_GPIO_ACTIVE_LOW;
led.name = of_get_property(child, "label", NULL) ? : child->name;
led.default_trigger =
of_get_property(child, "linux,default-trigger", NULL);
state = of_get_property(child, "default-state", NULL);
if (state) {
if (!strcmp(state, "keep"))
led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
else if (!strcmp(state, "on"))
led.default_state = LEDS_GPIO_DEFSTATE_ON;
else
led.default_state = LEDS_GPIO_DEFSTATE_OFF;
}
01_leds文件会根据dts里面的label去配置。
ucidef_set_led_netdev "wan" "wan" "deco:wan" "eth0.5"
ucidef_set_led_netdev "lan1" "lan1" "deco:lan1" "eth0.1"
ucidef_set_led_netdev "lan2" "lan2" "deco:lan2" "eth0.2"
ucidef_set_led_netdev "lan3" "lan3" "deco:lan3" "eth0.3"
ucidef_set_led_netdev "lan4" "lan4" "deco:lan4" "eth0.4"
;;
然后挂在系统中create_gpio_led(&led, &priv->leds[priv->num_leds++],
&pdev->dev, NULL);
灯的配置会生成一个文件/etc/config/system
二、Network config
首先:如果源代码中files/etc/config/network已有文件,那么不管如何配置UCI的网络部分,初始化的永远是最network文件。
先把该文件删除。
根据package/base-files/files/lib/functions/uci-defaults.sh函数对网络设备target/linux/ramips/base-files/etc/uci-defaults/02_network的设置
解析一个uci函数
ucidef_set_interface_lan() {
local ifname=$1
uci batch <<EOF
set network.lan='interface'
set network.lan.ifname='$ifname'
set network.lan.force_link=1
set network.lan.type='bridge'
set network.lan.proto='static'
set network.lan.ipaddr='192.168.1.1'
set network.lan.netmask='255.255.255.0'
set network.lan.ip6assign='60'
EOF
}
$1 表示传进来的参数,然后对该lan进行各种属性的设置。
ucidef_set_interfaces_lan "eth0.1" "eth0.2" "eth0.3" "eth0.4"
ucidef_add_switch_vlan "switch0" "1" "1 6t"
ucidef_add_switch_vlan "switch0" "2" "2 6t"
ucidef_add_switch_vlan "switch0" "3" "3 6t"
ucidef_add_switch_vlan "switch0" "4" "4 6t"
ucidef_add_switch_vlan "switch0" "15" "0 6t"