如何在uboot中添加驱动程序

16 篇文章 0 订阅
6 篇文章 0 订阅


Author:杨正date2016.9.21

目的

u-boot中添加驱动程序。

 

详细举例介绍

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

#define muxctrl_reg5    0x200f0014
#define GPIO6_DIR       0x201a0400
#define GPIO6_1_DATA    0x201a0008                                                                                                   
#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_val;
 
    reg_val = writel(0, muxctrl_reg5); // set gpio mode
    
    reg_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_SLAVE
    char *e;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
    unsigned long addr;
#endif
       
#ifdef CONFIG_HI3516A // defined in the include/configs/hi3516a.h
    clear_irled();  // clear ir led, add by yangzheng 2016.9.21
#endif


另一种方法

1、driver/下新建hi_gpio目录,如:
[yangzheng@centos6 hi_gpio]$ ls

hi_gpio.c  Makefile


hi_gpio.c内容如下:

[yangzheng@centos6 hi_gpio]$ cat hi_gpio.c
/*********************************************************************************
*      Copyright:  (C) 2016 Yang Zheng
   
   
    
      
*                  All rights reserved.
*
*       Filename:  hi_gpio.c
*    Description:  This file
*                 
*        Version:  1.0.0(09/21/2016~)
*         Author:  Yang Zheng 
    
    
     
     
*      ChangeLog:  1, Release initial version on "09/21/2016 05:41:41 PM"
*                 
********************************************************************************/
#include
     
     
      
      
 
#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_DATA            0x201a0008
#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_val;
 
    reg_val = writel(REG_CLR, muxctrl_reg5); // set gpio mode
    
    reg_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;
}
     
     
    
    
   
   

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

[yangzheng@centos6 hi_gpio]$ cat Makefile
#
# Copyright 2000-2008
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
# project.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either 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 WARRANTY; without 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 program; if 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 target
include $(SRCTREE)/rules.mk
 
sinclude $(obj).depend
 
########################################################################


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

LIBS += drivers/hi_gpio/libhi_gpio.a

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

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

[yangzheng@centos6 u-boot-2010.06]$ cat include/hi_gpio.h
/********************************************************************************
 *      Copyright:  (C) 2016 Yang Zheng
   
   
    
    
 *                  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 
    
    
     
     
 *      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
    
    
   
   

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

[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_SLAVE
    char *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
……

重新编译即可,调试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

 

 

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
U-Boot是一种开源的引导加载程序,通常用于嵌入式系统启动时加载操作系统。MT25QU是一种串行闪存芯片型号,常用于嵌入式系统的存储介质。驱动是指用于控制和管理硬件设备的软件模块。 要在U-Boot实现MT25QU驱动,首先需要了解MT25QU芯片的规格和通信协议。MT25QU芯片采用SPI接口进行通信,因此需要在U-Boot配置相应的SPI控制器,并设置正确的时钟速度、数据传输模式和接口引脚。 然后,在U-Boot的源码添加MT25QU的驱动代码。该驱动代码主要包含对MT25QU芯片的初始化、读写操作和擦除操作等。初始化部分需要设置芯片的工作模式、写保护状态和块大小等参数。读写操作则需要通过SPI接口进行数据传输,读取或写入相应的数据。擦除操作通常是以块或扇区为单位进行的。 驱动代码还需要处理错误处理和异常情况。例如,当MT25QU芯片返回错误码或出现通信故障时,驱动代码应该根据情况进行相应的处理,例如打印错误信息或进行重试操作。 最后,将编写好的驱动代码编译U-Boot的可执行程序,并烧录到嵌入式系统的存储介质。在系统启动时,U-Boot程序将加载并执行MT25QU的驱动代码,从而实现对MT25QU芯片的控制和管理。 总的来说,编写MT25QU驱动需要了解该芯片的规格和通信协议,并在U-Boot添加相应的驱动代码。通过驱动代码,能够控制和管理MT25QU芯片,实现对其存储介质的读写和擦除操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值