如何在uboot中添加驱动程序

如何在uboot中添加驱动程序,第1张

Author:杨正date:2016.9.21

目的

在u-boot中添加驱动程序。

详派肆细举例介绍

在uboot中 *** 作寄存器,实现对gpio及外围设备的控制有两种方法,一种是直接在arch/arm/lib/board.c中添加对寄存器的 *** 作代码,如:

#define muxctrl_reg50x200f0014#define GPIO6_DIR 0x201a0400#define GPIO6_1_DATA0x201a0008 #define GPIO6_1 (1 <<1)#define readl(addr) (*(volatile unsigned int*)(addr))#define writel(val, addr) ((*(volatile unsigned int *) (addr)) = (val)) int clear_irled(void){unsigned int reg_valreg_val = writel(0, muxctrl_reg5)// set gpio modereg_val = readl(GPIO6_DIR) reg_val |= GPIO6_1 writel(reg_val, GPIO6_DIR)reg_val = readl(GPIO6_1_DATA) reg_val &= ~GPIO6_1 writel(reg_val, GPIO6_1_DATA)return 0}void start_armboot (void){init_fnc_t **init_fnc_ptr char *s#ifdef CONFIG_HAS_SLAVEchar *e#endif#if defined(CONFIG_VFD) || defined(CONFIG_LCD)unsigned long addr#endif #ifdef CONFIG_HI3516A // defined in the include/configs/hi3516a.hclear_irled() // clear ir led, add by yangzheng 2016.9.21#endif

来尘纤轿自CODE的代码片

snippet_file_0.txt

另一种方法:

1、在driver/下新建hi_gpio目录,如:

[yangzheng@centos6 hi_gpio]$ ls

hi_gpio.c Makefile

hi_gpio.c内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

[yangzheng@centos6 hi_gpio]$ cat hi_gpio.c/********************************************************************************** Copyright: (C) 2016 Yang Zheng<竖轿[email protected]> * All rights reserved.** Filename: hi_gpio.c*Description: This file* *Version: 1.0.0(09/21/2016~)* Author: Yang Zheng [email protected]>* ChangeLog: 1, Release initial version on "09/21/2016 05:41:41 PM"* ********************************************************************************/#include<common.h>#define readl(addr) (*(volatile unsigned int *) (addr))#define writel(val, addr) (*(volatile unsigned int *) (addr) = (val)) #define muxctrl_reg5 0x200f0014#define GPIO6_DIR 0x201a0400#define GPIO6_1_DATA0x201a0008#define GPIO6_1 1 <<1#define REG_SET 1#define REG_CLR 0 #ifdef DEBUG#define DPRINTF(args...) printf(args)#else#define DPRINTF(args...)#endif int clear_irled(void){unsigned int reg_valreg_val = writel(REG_CLR, muxctrl_reg5)// set gpio modereg_val = readl(GPIO6_DIR) reg_val |= GPIO6_1 writel(reg_val, GPIO6_DIR)writel(REG_CLR, GPIO6_1_DATA) DPRINTF("clear ir led...\n")return 0}

来自CODE的代码片

snippet_file_0.txt

Makefile如下(可以拷贝driver目录下的各模块模板):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

[yangzheng@centos6 hi_gpio]$ cat Makefile## Copyright 2000-2008# Wolfgang Denk, DENX Software Engineering, [email protected].## See file CREDITS for list of people who contributed to this# project.## This program is free softwareyou can redistribute it and/or# modify it under the terms of the GNU General Public License as# published by the Free Software Foundationeither version 2 of# the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTYwithout even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this programif not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston,# MA 02111-1307 USA# include $(TOPDIR)/config.mk LIB := $(obj)libhi_gpio.a COBJS-$(CONFIG_HI3516A_GPIO)+= hi_gpio.o COBJS := $(COBJS-y)SRCS:= $(COBJS:.o=.c)OBJS:= $(addprefix $(obj),$(COBJS)) all:$(LIB) $(LIB): $(obj).depend $(OBJS)$(AR) $(ARFLAGS) $@ $(OBJS) ######################################################################### # defines $(obj).depend targetinclude $(SRCTREE)/rules.mk sinclude $(obj).depend ########################################################################

来自CODE的代码片

snippet_file_0.txt

2、在顶层Makefile添加如下代码:

LIBS += drivers/hi_gpio/libhi_gpio.a

3、在include/configs/hi3516a.h中添加如下代码:

#define CONFIG_HI3516A_GPIO

在include下增加hi_gpio.h文件,内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[yangzheng@centos6 u-boot-2010.06]$ cat include/hi_gpio.h/******************************************************************************** * Copyright: (C) 2016 Yang [email protected]>* All rights reserved. * * Filename: hi_gpio.h *Description: This head file is control hisi gpio * *Version: 1.0.0(09/21/2016~) * Author: Yang Zheng [email protected]>* ChangeLog: 1, Release initial version on "09/21/2016 06:09:49 PM" * ********************************************************************************/#ifndef __HI_GPIO_H__#define __HI_GPIO_H__ extern int clear_irled(void)#endif

来自CODE的代码片

snippet_file_0.txt

4、在arch/arm/lib/board.c 里面调用即可,如:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

[yangzheng@centos6 u-boot-2010.06]$ vim arch/arm/lib/board.c void start_armboot (void){init_fnc_t **init_fnc_ptr char *s#ifdef CONFIG_HAS_SLAVEchar *e#endif#if defined(CONFIG_VFD) || defined(CONFIG_LCD)unsigned long addr#endif #ifdef CONFIG_HI3516A_GPIO clear_irled() // clear ir led, add by yangzheng 2016.9.21#endif……

来自CODE的代码片

snippet_file_0.txt

重新编译即可,调试uboot的方法:

如果设备有网口,可用tftp服务下载:

sf probe 0

mw.b 82000000 ff 0x80000

tftp 82000000 u-boot.bin

Go 82000000

如果没有网口,可用串口下载:

sf probe 0

mw.b 82000000 ff 0x80000

loady 82000000 u-boot.bin

go 82000000

U-Boot,全称 Universal Boot Loader,是遵循GPL条款的开放源码项目。U-Boot的作用是系统引导。U-Boot从FADSROM、8xxROM、PPCBOOT逐步发展演化而来。其源码目录、编译形式与Linux内核很相似,事实上,不少U-Boot源码就是根据相应的Linux内核源程序进行简化而形成的,尤其是一些设备的驱动程序,这从U-Boot源码的注释中能体现这一点。

拓展资料:

选择U-Boot的理由:

① 开放源码

② 支持多种嵌入式 *** 好塌作系统内核,如Linux、NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS, android

③ 支持多个处理器系列,如PowerPC、ARM、x86、MIPS

④ 较高的可靠性和稳定性

⑤ 高度灵活的功哪禅能设置,适合U-Boot调试、 *** 作系统不同引导要求、产品发布等

⑥ 丰富的设备驱动源码,如串口、以太网、SDRAM、FLASH、LCD、NVRAM、EEPROM、RTC、键盘等

⑦ 较为丰富的李袜尘开发调试文档与强大的网络技术支持。

uboot是个引导启动程序。BIOS自检完成后就把电脑控制权交给uboot,由uboot来加载并引导 *** 作系统运行。

内核就是最最最核心的那部份。 *** 作系统内核就是 *** 作系统的最最最最核心的那些程序。新安装的 *** 作系统中,一些自带的小工具啊,小游戏啊,甚至连键盘鼠标控制功能,这些都不属于内核。内核是不包括硬件驱动程序的。

*** 作系统就是控制计算机硬运游前件的旁清软件系统。它与内核的区别是它包含硬件驱动和一些基本的实用功能。

文件系统这个名词很少出现在windows中。在计算机存储中,目录结构都是以树形结构表示的,根就是指这棵树的根部。其他所有目录都是在这个“根”上面逐级分配而来。“根文件系统”因为你加了“系统”二字,所以可以解释为是指“整棵树”,整个“树形结构磨燃的文件系统”

它们之间的关系是:BIOS自检---uboot引导----加载内核---- *** 作系统启动---启动完成,系统待机。这几个步骤所需要用到的文件与程序什么的全部存贮在文件系统中。在这几个名词来说,文件系统可以独立存在,但其他几样则无法脱离文件系统而存在。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8284105.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存