blob: 712b7c49d46f84be01ac31767f2730a80cc623af [file] [log] [blame]
Ronald G. Minniche0e784a2014-11-26 19:25:47 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 The Chromium OS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21#include <cbfs.h>
22#include <string.h>
23
24#ifdef LIBPAYLOAD
25# define printk(x...)
26# define init_default_cbfs_media libpayload_init_default_cbfs_media
27 extern int libpayload_init_default_cbfs_media(struct cbfs_media *media);
28#else
29# include <console/console.h>
30#endif
31
32// Implementation of memory-mapped ROM media source on X86.
33
34static int rom_media_open(struct cbfs_media *media) {
35 return 0;
36}
37
38static void *rom_media_map(struct cbfs_media *media, size_t offset, size_t count) {
39 void *ptr;
40 printk(BIOS_INFO, "%s: media %p, offset %lx, size %ld.\n", __func__, media, offset, count);
41
42 ptr = (void*)offset;
43 return ptr;
44}
45
46static void *rom_media_unmap(struct cbfs_media *media, const void *address) {
47 return NULL;
48}
49
50static size_t rom_media_read(struct cbfs_media *media, void *dest, size_t offset,
51 size_t count) {
52 void *ptr = rom_media_map(media, offset, count);
53 memcpy(dest, ptr, count);
54 rom_media_unmap(media, ptr);
55 return count;
56}
57
58static int rom_media_close(struct cbfs_media *media) {
59 return 0;
60}
61
62static int init_rom_media_cbfs(struct cbfs_media *media) {
63 //extern unsigned long _cbfs_master_header;
64 // On X86, we always keep a reference of pointer to CBFS header in
65 // 0xfffffffc, and the pointer is still a memory-mapped address.
66 // Since the CBFS core always use ROM offset, we need to figure out
67 // header->romsize even before media is initialized.
68 struct cbfs_header *header = (struct cbfs_header*) CONFIG_CBFS_HEADER_ROM_OFFSET; //&_cbfs_master_header;
69 if (CBFS_HEADER_MAGIC != ntohl(header->magic)) {
70 printk(BIOS_ERR, "Invalid CBFS master header at %p\n", header);
71 printk(BIOS_ERR, "Expected %08lx and got %08lx\n", (unsigned long) CBFS_HEADER_MAGIC, (unsigned long) ntohl(header->magic));
72 return -1;
73 } else {
74 uint32_t romsize = ntohl(header->romsize);
75 media->context = (void*)(uintptr_t)romsize;
76#if defined(CONFIG_ROM_SIZE)
77 if (CONFIG_ROM_SIZE != romsize)
78 printk(BIOS_INFO, "Warning: rom size unmatch (%d/%d)\n",
79 CONFIG_ROM_SIZE, romsize);
80#endif
81 }
82 media->open = rom_media_open;
83 media->close = rom_media_close;
84 media->map = rom_media_map;
85 media->unmap = rom_media_unmap;
86 media->read = rom_media_read;
87 return 0;
88}
89
90int init_default_cbfs_media(struct cbfs_media *media) {
91 return init_rom_media_cbfs(media);
92}
93// bug in coreboot. Fix me.
94// even if you have no use for lzma cbfs demands it.
95// and the ulzma code is terrible -- full of bad 32/64 bad things.
96unsigned long ulzma(unsigned char *src, unsigned char *dst);
97unsigned long ulzma(unsigned char *src, unsigned char *dst)
98{
99 return 0;
100}