- 了解uboot LCD driver.
1.代码流程
common/board_r.c:
stdio_add_devices
->drv_video_init
->cfg_video_init
->video_hw_init (驱动工程师实现)
->video_logo() (显示logo)
2.配置
- CONFIG_VIDEO=y
- CONFIG_VIDEO_LOGO=y
- CONFIG_VIDEO_BMP_LOGO=y
- CONFIG_CFB_CONSOLE=y
3.代码分析
cfg_video_init
150 void *video_hw_init(void)
151 {
152 static GraphicDevice dssfb;
153 GraphicDevice *pGD = &dssfb;
154 struct dispc_regs *dispc = (struct dispc_regs *) OMAP3_DISPC_BASE;
155
156 if (board_video_init() || !readl(&dispc->gfx_ba0))
157 return NULL;
158
159 pGD->winSizeX = (readl(&dispc->size_lcd) & 0x7FF) + 1;
160 pGD->winSizeY = ((readl(&dispc->size_lcd) >> 16) & 0x7FF) + 1;
161 pGD->gdfBytesPP = 4;
162 pGD->gdfIndex = GDF_32BIT_X888RGB;
163 pGD->frameAdrs = readl(&dispc->gfx_ba0);
164
165 return pGD;
166 }
该函数功能是封装全局结构体static GraphicDevice *pGD;
然后判断video data format,格式包括如下:
20 /*
21 * Graphic Data Format (GDF) bits for VIDEO_DATA_FORMAT
22 */
23 #define GDF__8BIT_INDEX 0
24 #define GDF_15BIT_555RGB 1
25 #define GDF_16BIT_565RGB 2
26 #define GDF_32BIT_X888RGB 3
27 #define GDF_24BIT_888RGB 4
28 #define GDF__8BIT_332RGB 5
项目中采用的是GDF_24BIT_888RGB:
2090 case GDF_24BIT_888RGB:
2091 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2092 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2093 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2094 CONFIG_SYS_CONSOLE_FG_COL;
2095 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2096 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2097 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2098 CONFIG_SYS_CONSOLE_BG_COL;
2099 break;
2100 }
2101 eorx = fgx ^ bgx;
如下所示,fgx和bgx分别表示前景和背景色value。
642 config SYS_CONSOLE_BG_COL
643 hex "Background colour"
644 depends on CFB_CONSOLE
645 default 0x00
646 help
647 Defines the background colour for the console. The value is from
648 0x00 to 0xff and the meaning depends on the graphics card.
649 Typically, 0x00 means black and 0xff means white. Do not set
650 the background and foreground to the same colour or you will see
651 nothing.
652
653 config SYS_CONSOLE_FG_COL
654 hex "Foreground colour"
655 depends on CFB_CONSOLE
656 default 0xa0
657 help
658 Defines the foreground colour for the console. The value is from
659 0x00 to 0xff and the meaning depends on the graphics card.
660 Typically, 0x00 means black and 0xff means white. Do not set
661 the background and foreground to the same colour or you will see
662 nothing.
如果设置CONFIG_VIDEO_LOGO,则调用video_logo显示logo,进入该函数,分析如下:
- 如果定义CONFIG_SPLASH_SCREEN,则获取环境变量"splashimage"指定的bmp进行显示。
1861 #ifdef CONFIG_SPLASH_SCREEN
1862 s = env_get("splashimage");
1863 if (s != NULL) {
1864 ret = splash_screen_prepare();
1865 if (ret < 0)
1866 return video_fb_address;
1867 addr = simple_strtoul(s, NULL, 16);
1868
1869 if (video_display_bitmap(addr,
1870 video_logo_xpos,
1871 video_logo_ypos) == 0) {
1872 video_logo_height = 0;
1873 return ((void *) (video_fb_address));
1874 }
1875 }
1876 #endif /* CONFIG_SPLASH_SCREEN */
README:
1278 - Splash Screen Support: CONFIG_SPLASH_SCREEN
1280 If this option is set, the environment is checked for
1281 a variable "splashimage". If found, the usual display
1282 of logo, copyright and system information on the LCD
1283 is suppressed and the BMP image at the address
1284 specified in "splashimage" is loaded instead. The
1285 console is redirected to the "nulldev", too. This
1286 allows for a "silent" boot where a splash screen is
1287 loaded very quickly after power-on.
- logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
如果定义CONFIG_VIDEO_BMP_LOGO,则指定source = bmp_logo_bitmap; 该变量是一个数组,包含bmp信息。那该数组怎么来的呢?
如下所示:bmp_logo工具通过解析 LOGO_BMP指定的bmp文件(tools/logos/xxx.bmp)生成文件bmp_logo_data.h和bmp_logo.h。
tools/Makefile:
33 hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
34 hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
227 # Generated LCD/video logo
228 LOGO_H = $(objtree)/include/bmp_logo.h
229 LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
230 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
231 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
232 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
233 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
235 # Generic logo
236 ifeq ($(LOGO_BMP),)
237 LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
238
239 # Use board logo and fallback to vendor
240 ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
241 LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
242 else
243 ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
244 LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
245 endif
246 endif
266 $(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP)
267 $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
268
269 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
270 $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
生成的内容如下所示:
include/bmp_logo.h:
#define BMP_LOGO_WIDTH 364
#define BMP_LOGO_HEIGHT 128
#define BMP_LOGO_COLORS 240
#define BMP_LOGO_OFFSET 16
include/bmp_logo_data.h:
生成两个数组 bmp_logo_palette和bmp_logo_bitmap.
最后调用 flush_cache将数据flush the cache。
4.Debug
命令:
- prlogo: 显示logo
- clrlogo:清除logo
调试步骤:
1.添加宏定义
include/configs/xxx.h:
#define CONFIG_SPLASH_SCREEN_ALIGN
README:
1278 - Splash Screen Support: CONFIG_SPLASH_SCREEN
1279
1280 If this option is set, the environment is checked for
1281 a variable "splashimage". If found, the usual display
1282 of logo, copyright and system information on the LCD
1283 is suppressed and the BMP image at the address
1284 specified in "splashimage" is loaded instead. The
1285 console is redirected to the "nulldev", too. This
1286 allows for a "silent" boot where a splash screen is
1287 loaded very quickly after power-on.
1300 CONFIG_SPLASH_SCREEN_ALIGN
1301
1302 If this option is set the splash image can be freely positioned
1303 on the screen. Environment variable "splashpos" specifies the
1304 position as "x,y". If a positive number is given it is used as
1305 number of pixel from left/top. If a negative number is given it
1306 is used as number of pixel from right/bottom. You can also
1307 specify 'm' for centering the image.
1308
1309 Example:
1310 setenv splashpos m,m
1311 => image at center of screen
1312
1313 setenv splashpos 30,20
1314 => image at x = 30 and y = 20
1315
1316 setenv splashpos -10,m
1317 => vertically centered image
1318 at x = dspWidth - bmpWidth - 9
2.添加环境变量(两种方法)
第一种:静态添加
58 #define CONFIG_EXTRA_ENV_SETTINGS \
59 "bootargs_base=setenv bootargs console=ttymxc0,115200\0" \
60 "bootargs_nfs=setenv bootargs $(bootargs) root=/dev/nfs\0" \
61 “splashpos= -10,m\0”
第二种:动态设置
=> setenv splashpos 30,20
3.添加自定义函数:
drivers/video/cfb_console.c:
1710 static int do_prlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1711 {
1712 if (argc != 1)
1713 return cmd_usage(cmdtp);
1714
1859 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1715 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1716 return 0;
1717 }
调试步骤:
=> setenv splashpos 10,-10
=> prlogo
splash_get_pos,*x=10,*y=-10
do_prlogo,video_logo_xpos=10,video_logo_ypos=-10
=> setenv splashpos -10,10
=> prlogo
splash_get_pos,*x=-10,*y=10
do_prlogo,video_logo_xpos=-10,video_logo_ypos=10