libpayload/corebootfb: Fix character buffer relocation

The `chars` pointer references the heap which is part of the payload
and relocated along with it. So calling phys_to_virt() on it was
always wrong; and the virt_to_phys() at its initialization was a
no-op anyway, when the console was brought up before relocation.

While we are at it, add a null-pointer check.

Change-Id: Ic03150f0bcd14a6ec6bf514dffe2b9153d5a6d2a
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/38536
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Nico Huber 2020-01-23 12:48:03 +01:00 committed by Patrick Georgi
parent 96f18a01da
commit 16043d6742
1 changed files with 6 additions and 5 deletions

View File

@ -64,11 +64,11 @@ static const u32 vga_colors[] = {
/* Addresses for the various components */
static unsigned long fbinfo;
static unsigned long fbaddr;
static unsigned long chars;
static unsigned short *chars;
#define FI ((struct cb_framebuffer *) phys_to_virt(fbinfo))
#define FB ((unsigned char *) phys_to_virt(fbaddr))
#define CHARS ((unsigned short *) phys_to_virt(chars))
#define CHARS (chars)
static void corebootfb_scroll_up(void)
{
@ -243,9 +243,10 @@ static int corebootfb_init(void)
coreboot_video_console.columns = FI->x_resolution / font_width;
coreboot_video_console.rows = FI->y_resolution / font_height;
/* See setting of fbinfo above. */
chars = virt_to_phys(malloc(coreboot_video_console.rows *
coreboot_video_console.columns * 2));
chars = malloc(coreboot_video_console.rows *
coreboot_video_console.columns * 2);
if (!chars)
return -1;
// clear boot splash screen if there is one.
corebootfb_clear();