blob: 98dc26643fe0924900256b6398526c093fdc624d [file] [log] [blame]
/*
* Copyright 2016 Google Inc.
*
* 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 <stdint.h>
#include <stdio.h>
#include <string.h>
#include "base/fwdb.h"
#include "drivers/framebuffer/framebuffer.h"
static const char framebuffer_fwdb_name[] = "framebuffer_info";
int framebuffer_read_from_fwdb(FrameBuffer *buf)
{
FwdbEntry entry;
if (fwdb_access(framebuffer_fwdb_name, &entry, NULL))
return 1;
if (entry.size < sizeof(FrameBufferHeader)) {
printf("FWDB framebuffer too small.\n");
return 1;
}
FrameBufferHeader *header = entry.ptr;
if (header->version > FrameBufferCurrentVersion) {
printf("Frame buffer version too new.\n");
return 1;
}
if (entry.size != sizeof(FrameBuffer)) {
printf("Frame buffer size mismatch.\n");
return 1;
}
memcpy(buf, entry.ptr, sizeof(*buf));
return 0;
}
int framebuffer_write_to_fwdb(FrameBuffer *buf)
{
FwdbEntry entry = {
.ptr = buf,
.size = sizeof(*buf),
};
return fwdb_access(framebuffer_fwdb_name, NULL, &entry);
}