|
U-Boot使用DTS共享配置应用实例
发表于 2014-10-15 15:12:38
浏览:37150
|
回复:11
打印
只看该作者
[复制链接]
楼主
本帖最后由 zhansb 于 2014-10-15 15:25 编辑
设备树(DTS)的引入减少了内核为支持新硬件而需要的改变,提高代码重用,使得单个内核镜像能支持多个系统。
DTS作为U-Boot 和Linux 内核之间的动态接口,能够有效减少重复配置,共享于U-Boot 和Linux之间。本文将简单介绍U-Boot使用DTS控制LED的例子:
1.在kernel/arch/arm/boot/dts/rk3288-box.dts中添加LED配置:
- ------------------- kernel/arch/arm/boot/dts/rk3288-box.dts -------------------
- index e102714..80928ba 100755
- @@ -137,6 +136,16 @@
- rockchip,remote_wakeup;
- rockchip,usb_irq_wakeup;
- };
- +
- + leds {
- + compatible = "gpio-leds";
- + power {
- + label = "tchip:blue:power";
- + default-state = "on";
- + gpios = <&gpio8 GPIO_A3 GPIO_ACTIVE_LOW>;
- + };
- + };
- };
-
- &gmac {
复制代码 以上是linux标准的GPIO-LED配置,直接配置上内核就可使用LED。
2.修改U-Boot,以支持读取DTS配置并操作LED灯,修改u-boot/board/rockchip/rk32xx/rk32xx.c:
- -------------------- u-boot/board/rockchip/rk32xx/rk32xx.c --------------------
- index bfdcf0e..29fff0f 100755
- @@ -61,12 +61,34 @@ void board_lmb_reserve(struct lmb *lmb) {
- //reserve 48M for kernel & 8M for nand api.
- lmb_reserve(lmb, gd->bd->bi_dram[0].start, CONFIG_LMB_RESERVE_SIZE);
- }
- +
- +static struct fdt_gpio_state power_led_gpio;
- +int power_led_parse_dt(const void *blob)
- +{
- + int led_node = 0;
- + int node = 0;
- +
- + node = fdt_node_offset_by_compatible(blob,
- + 0, "gpio-leds");
- + if (node < 0) {
- + printf("can't find dts node for led\n");
- + return -ENODEV;
- + }
- + led_node = fdt_subnode_offset(blob, node, "power");
- + fdtdec_decode_gpio(blob, led_node, "gpios", &power_led_gpio);
- + power_led_gpio.gpio = rk_gpio_base_to_bank(power_led_gpio.gpio & RK_GPIO_BANK_MASK) | (power_led_gpio.gpio & RK_GPIO_PIN_MASK);
- + power_led_gpio.flags = !(power_led_gpio.flags & OF_GPIO_ACTIVE_LOW);
- + debug("power_led_gpio: %s,%d-%d\n", power_led_gpio.name, power_led_gpio.gpio, power_led_gpio.flags);
- +
- + return 0;
- +}
- #endif /* CONFIG_OF_LIBFDT */
-
-
- #ifdef CONFIG_RK_FB
-
- #ifdef CONFIG_OF_LIBFDT
- +
- static struct fdt_gpio_state lcd_en_gpio, lcd_cs_gpio;
- static int lcd_en_delay, lcd_cs_delay;
- static int lcd_node = 0;
- @@ -114,7 +136,6 @@ void rk_backlight_ctrl(int brightness)
-
- void rk_fb_init(unsigned int onoff)
- {
- -
- #ifdef CONFIG_OF_LIBFDT
- if (lcd_node == 0) rk_lcd_parse_dt(gd->fdt_blob);
-
- @@ -178,6 +199,17 @@ void init_panel_info(vidinfo_t *vid)
- vid->logo_rgb_mode = RGB565;
- }
-
- +void power_led_init(void)
- +{
- + printf("Enter power_led_init\n");
- +#ifdef CONFIG_OF_LIBFDT
- + power_led_parse_dt(gd->fdt_blob);
- + if (power_led_gpio.name!=NULL)
- + {
- + gpio_direction_output(power_led_gpio.gpio, power_led_gpio.flags);
- + }
- +#endif
- +}
-
- #ifdef CONFIG_RK616
- int rk616_power_on(void)
- @@ -259,6 +291,9 @@ int board_late_init(void)
- load_disk_partitions();
- prepare_fdt();
- key_init();
- +
- + power_led_init();
- +
- #ifdef CONFIG_POWER_RK
- pmic_init(0);
- fg_init(0); /*fuel gauge init*/
复制代码
3.编译内核,参考Wiki<http://wiki.t-firefly.com/index.php/Firefly-RK3288/Build_kernel>中的编译内核映像部分
4.编译U-Boot,参考SDK下的“RKDocs/common/uboot/RockChip_Uboot开发文档V1.0.pdf”文档,编译生成RK3288Loader_uboot_V2.15.bin
5.烧写resource.img和RK3288Loader_uboot_V2.15.bin,开机。有没有发现LED灯比原来的快差不多两秒点亮呢{:3_48:}
|
|