在uboot中添加开机LOGO,基本上可以归纳为以下四个步骤:
一:初始化LCD控制器相应的寄存器;
二:初始化LCD控制器对应的时钟源;
三:填充framebuffer;
四:打开背光。
在uboot\board\samsung\x4412\x4412.c中,我们在函数board_late_init中添加显示开机LOGO的函数x4412_framebuffer_init(),该函数内嵌了多个函数,他们完成了以上所有步骤。其源码如下:
void x4412_framebuffer_init(void) { exynos4412_clk_initial(); //初始化时钟 exynos4412_fb_initial(); //初始化LCD寄存器 }
这里前两个函数用于设置时钟相关寄存器:
void exynos4412_clk_initial(void) { /* Modify LCD clk */ writel(EXYNOS4412_CLK_SRC_LCD, (readl(EXYNOS4412_CLK_SRC_LCD) & ~(0xf<<0)) | (0x6<<0)); writel(EXYNOS4412_CLK_DIV_LCD, (readl(EXYNOS4412_CLK_DIV_LCD) & ~(0xf<<0)) | (0x0<<0)); exynos4412_setup_clocks(24 * 1000 * 1000); }整个时钟的配置,在exynos4412-clk.c中。时钟配置完后,我们再来看LCD寄存器初始化函数exynos4412_fb_initial()。
void exynos4412_fb_initial() { struct exynos4412_fb_data_t * dat; dat = &vs070cxn; if( (dat->bits_per_pixel != 16) && (dat->bits_per_pixel != 24) && (dat->bits_per_pixel != 32) ) return; exynos4412_fb.dat = dat; exynos4412_fb.surface.info.bits_per_pixel = dat->bits_per_pixel; exynos4412_fb.surface.info.bytes_per_pixel = dat->bytes_per_pixel; exynos4412_fb.surface.info.red_mask_size = dat->rgba.r_mask; exynos4412_fb.surface.info.red_field_pos = dat->rgba.r_field; exynos4412_fb.surface.info.green_mask_size = dat->rgba.g_mask; exynos4412_fb.surface.info.green_field_pos = dat->rgba.g_field; exynos4412_fb.surface.info.blue_mask_size = dat->rgba.b_mask; exynos4412_fb.surface.info.blue_field_pos = dat->rgba.b_field; exynos4412_fb.surface.info.alpha_mask_size = dat->rgba.a_mask; exynos4412_fb.surface.info.alpha_field_pos = dat->rgba.a_field; exynos4412_fb.surface.info.fmt = get_pixel_format(&(exynos4412_fb.surface.info)); exynos4412_fb.surface.w = dat->width; exynos4412_fb.surface.h = dat->height; exynos4412_fb.surface.pitch = dat->width * dat->bytes_per_pixel; exynos4412_fb.surface.flag = SURFACE_PIXELS_DONTFREE; exynos4412_fb.surface.pixels = dat->vram_front; exynos4412_fb.surface.clip.x = 0; exynos4412_fb.surface.clip.y = 0; exynos4412_fb.surface.clip.w = dat->width; exynos4412_fb.surface.clip.h = dat->height; memset(&exynos4412_fb.surface.maps, 0, sizeof(struct surface_maps)); surface_set_maps(&exynos4412_fb.surface.maps); fb_init(&exynos4412_fb); exynos4412_display_logo(); if(dat->backlight) dat->backlight(255); }以上函数基本上都在填充结构体,这里vs070cxn结构体描述了LCD屏的前后肩等相关参数,不同的屏参数不一样。通常,更换不同的屏,主要也就是修改这个结构体的相关参数。
static struct exynos4412_fb_data_t vs070cxn = { .regbase = EXYNOS4412_LCD_BASE, .width = 1024, .height = 600, .bits_per_pixel = 32, .bytes_per_pixel = 4, .freq = 60, .output = EXYNOS4412_FB_OUTPUT_RGB, .rgb_mode = EXYNOS4412_FB_MODE_BGR_P, .bpp_mode = EXYNOS4412_FB_BPP_MODE_32BPP, .swap = EXYNOS4412_FB_SWAP_WORD, .rgba = { .r_mask = 8, .r_field = 0, .g_mask = 8, .g_field = 8, .b_mask = 8, .b_field = 16, .a_mask = 8, .a_field = 24, }, .timing = { .h_fp = 160, .h_bp = 140, .h_sw = 20, .v_fp = 12, .v_fpe = 1, .v_bp = 20, .v_bpe = 1, .v_sw = 3, }, .polarity = { .rise_vclk = 0, .inv_hsync = 1, .inv_vsync = 1, .inv_vden = 0, }, .vram_front = &vram[0][0], .vram_back = &vram[1][0], .init = lcd_init, .backlight = lcd_backlight, };
在fb_init()函数中,初始化了一堆LCD相关寄存器:
static void fb_init(struct fb_t * fb) { struct exynos4412_fb_data_t * dat = (struct exynos4412_fb_data_t *)(fb->dat); /* * Initial lcd port */ writel(EXYNOS4412_GPF0_BASE + EXYNOS4412_GPIO_CON, 0x22222222); writel(EXYNOS4412_GPF0_BASE + EXYNOS4412_GPIO_DRV, 0xffffffff); writel(EXYNOS4412_GPF0_BASE + EXYNOS4412_GPIO_PUD, 0x0); writel(EXYNOS4412_GPF1_BASE + EXYNOS4412_GPIO_CON, 0x22222222); writel(EXYNOS4412_GPF1_BASE + EXYNOS4412_GPIO_DRV, 0xffffffff); writel(EXYNOS4412_GPF1_BASE + EXYNOS4412_GPIO_PUD, 0x0); writel(EXYNOS4412_GPF2_BASE + EXYNOS4412_GPIO_CON, 0x22222222); writel(EXYNOS4412_GPF2_BASE + EXYNOS4412_GPIO_DRV, 0xffffffff); writel(EXYNOS4412_GPF2_BASE + EXYNOS4412_GPIO_PUD, 0x0); writel(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_CON, (readl(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_CON) & ~(0xffff<<0)) | (0x2222<<0)); writel(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_DRV, (readl(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_DRV) & ~(0xff<<0)) | (0xff<<0)); writel(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_PUD, (readl(EXYNOS4412_GPF3_BASE + EXYNOS4412_GPIO_PUD) & ~(0xff<<0)) | (0x00<<0)); /* * Lcd init function */ if(dat->init) dat->init(); /* * Display path selection */ writel(EXYNOS4412_LCDBLK_CFG, (readl(EXYNOS4412_LCDBLK_CFG) & ~(0x3<<0)) | (0x2<<0)); writel(EXYNOS4412_LCDBLK_CFG2, (readl(EXYNOS4412_LCDBLK_CFG2) & ~(0x1<<0)) | (0x1<<0)); /* * Turn off all windows */ writel(dat->regbase + WINCON0, (readl(dat->regbase + WINCON0) & ~0x1)); writel(dat->regbase + WINCON1, (readl(dat->regbase + WINCON1) & ~0x1)); writel(dat->regbase + WINCON2, (readl(dat->regbase + WINCON2) & ~0x1)); writel(dat->regbase + WINCON3, (readl(dat->regbase + WINCON3) & ~0x1)); writel(dat->regbase + WINCON4, (readl(dat->regbase + WINCON4) & ~0x1)); /* * Turn off all windows color map */ writel(dat->regbase + WIN0MAP, (readl(dat->regbase + WIN0MAP) & ~(1<<24))); writel(dat->regbase + WIN1MAP, (readl(dat->regbase + WIN1MAP) & ~(1<<24))); writel(dat->regbase + WIN2MAP, (readl(dat->regbase + WIN2MAP) & ~(1<<24))); writel(dat->regbase + WIN3MAP, (readl(dat->regbase + WIN3MAP) & ~(1<<24))); writel(dat->regbase + WIN4MAP, (readl(dat->regbase + WIN4MAP) & ~(1<<24))); /* * Turn off all windows color key and blending */ writel(dat->regbase + W1KEYCON0, (readl(dat->regbase + W1KEYCON0) & ~(3<<25))); writel(dat->regbase + W2KEYCON0, (readl(dat->regbase + W2KEYCON0) & ~(3<<25))); writel(dat->regbase + W3KEYCON0, (readl(dat->regbase + W3KEYCON0) & ~(3<<25))); writel(dat->regbase + W4KEYCON0, (readl(dat->regbase + W4KEYCON0) & ~(3<<25))); /* * Initial lcd controller */ exynos4412_fb_set_output(dat); exynos4412_fb_set_display_mode(dat); exynos4412_fb_display_off(dat); exynos4412_fb_set_polarity(dat); exynos4412_fb_set_timing(dat); exynos4412_fb_set_lcd_size(dat); exynos4412_fb_set_clock(dat); /* * Set lcd video buffer */ exynos4412_fb_set_buffer_size(dat, 0); exynos4412_fb_set_window_position(dat, 0); exynos4412_fb_set_window_size(dat, 0); /* * Enable window 0 for main display area */ exynos4412_fb_window0_enable(dat); /* * Display on */ exynos4412_fb_display_on(dat); /* * Wait a moment */ // mdelay(100); }紧接着,调用exynos4412_display_logo函数填充framebuffer。
static void exynos4412_display_logo(void) { struct surface_t * screen = exynos4412_screen_surface(); struct surface_t * logo; struct rect_t rect; u32_t c; exynos4412_screen_flush(); c = surface_map_color(screen, get_named_color("greenyellow")); surface_fill(screen, &screen->clip, c, BLEND_MODE_REPLACE); disp_hanzi(); lcd_print(450, 350, 0x00000000, c, "www.9tripod.com"); }
这里填充framebuffer,引用了x4412开发板配套的裸机源码,里面引用了一套绘图机制,我们利用它可以很方便的在LCD上打印字符,输出图片等。这里我们同样引用了裸机里面的汉字显示实验,调用了disp_hanzi函数,在LCD屏上显示几个楷体汉字,同时调用lcd_print函数在汉字下面打印了一串字符串。
到这里,其实图形已经显示在LCD上了,我们只需打开背光即可看到界面了。在exynos4412_fb_initial函数中,通过回调函数调用了lcd_backlight函数:
static void lcd_backlight(u8_t brightness) { if(brightness) { writel(EXYNOS4412_GPD0_BASE + EXYNOS4412_GPIO_DAT, (readl(EXYNOS4412_GPD0_BASE + EXYNOS4412_GPIO_DAT) & ~(0x1<<0)) | (0x0<<0)); writel(EXYNOS4412_GPX3_BASE + EXYNOS4412_GPIO_DAT, (readl(EXYNOS4412_GPX3_BASE + EXYNOS4412_GPIO_DAT) & ~(0x1<<5)) | (0x1<<5)); } else { writel(EXYNOS4412_GPD0_BASE + EXYNOS4412_GPIO_DAT, (readl(EXYNOS4412_GPD0_BASE + EXYNOS4412_GPIO_DAT) & ~(0x1<<0)) | (0x1<<0)); writel(EXYNOS4412_GPX3_BASE + EXYNOS4412_GPIO_DAT, (readl(EXYNOS4412_GPX3_BASE + EXYNOS4412_GPIO_DAT) & ~(0x1<<5)) | (0x0<<5)); } }
这里通过GPIO口打开背光驱动IC,从而点亮背光。到此,uboot的开机LOGO真实的呈现在我们面前了。
附:编译好的可在x4412&ibox开发板上运行的uboot映像:
http://xboot.org/thread-27358-1-1.html