再谈U-Boot的设备管理框架
再谈U-Boot的设备管理框架
一、U-Boot的设备管理框架
在《U-Boot的设备管理》一文中通过源码分析讲解了U-Boot的设备管理。本文将从宏观的角度继续讲解U-Boot的设备管理框架。设备管理框架实现了设备的高度抽象,保持框架的稳定性,允许框架下的代码实时变化,可以很好的实现U-Boot的驱动程序的移植。U-Boot的设备管理框架实现了对串口、LCD、键盘、usbtty、I2C等设备的抽象。 U-Boot源代码下载地址框架的编写不同于写代码,需要对具体设备实例进行高度抽象。对于上面提到的一些设备,U-Boot针对他们的操作方法抽象抽象为四种类型
- 设备的启动操作
- 设备的释放操作
- 数据写向设备的操作
- 数据从设备中读出的操作
- int devices_init (void)
- {
- #ifndef CONFIG_ARM /* already relocated for current ARM implementation */
- ulong relocation_offset = gd->reloc_off;
- int i;
- /* relocate device name pointers */
- for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) {
- stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
- relocation_offset);
- }
- #endif
- /* Initialize the list */
- devlist = ListCreate (sizeof (device_t));//创建设备列表
- if (devlist == NULL) {
- eputs ("Cannot initialize the list of devices!\n");
- return -1;
- }
- #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
- i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);//初始化i2c接口,i2c没有注册到devlist中去
- #endif
- #ifdef CONFIG_LCD
- drv_lcd_init (); //初始化LCD设备
- #endif
- #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
- drv_video_init (); //初始化video设备
- #endif
- #ifdef CONFIG_KEYBOARD
- drv_keyboard_init (); //初始化键盘设备
- #endif
- #ifdef CONFIG_LOGBUFFER
- drv_logbuff_init (); //初始化logbuff设备
- #endif
- drv_system_init ();//这里其实是定义了一个串口设备,并且注册到devlist中
- #ifdef CONFIG_SERIAL_MULTI
- serial_devices_init (); //初始化serial设备
- #endif
- #ifdef CONFIG_USB_TTY
- drv_usbtty_init (); //usbtty设备
- #endif
- #ifdef CONFIG_NETCONSOLE
- drv_nc_init ();
- #endif
- return (0);
- }
- /* Device information */
- typedef struct {
- int flags; /* Device flags: input/output/system */
- int ext; /* Supported extensions */
- char name[16]; /* Device name 设备名称 */
- /* GENERAL functions 启动和停止函数 */
- int (*start) (void); /* To start the device */
- int (*stop) (void); /* To stop the device */
- /* OUTPUT functions 输出函数 */
- void (*putc) (const char c); /* To put a char */
- void (*puts) (const char *s); /* To put a string (accelerator) */
- /* INPUT functions 输入函数*/
- int (*tstc) (void); /* To test if a char is ready... */
- int (*getc) (void); /* To get that char */
- /* Other functions */
- void *priv; /* Private extensions */
- } device_t;
devlist = ListCreate (sizeof (device_t));
再来看一些函数: device_register (device_t * dev) 设备注册,将结构体添加到devlist的后面
device_deregister(char *devname)
search_device (int flags, char *name) 设备搜索
device_deregister(char *devname)设备的移除
以上这些就过程了U-Boot的设别管理框架。下面来分析一个该框架下的设备实例。
|
评论暂时关闭