aboutsummaryrefslogtreecommitdiff
path: root/src/cpu/ti/am335x/bootblock_media.c
blob: 9824fc396af89d5af21591cea0c70ae17ca23cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2013 Google Inc.
 *
 * 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; version 2 of the License.
 *
 * 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.
 */

#include <cbfs.h>
#include <console/console.h>
#include <string.h>
#include <symbols.h>

static int dummy_open(struct cbfs_media *media)
{
	return 0;
}

static int dummy_close(struct cbfs_media *media)
{
	return 0;
}

static void * on_chip_memory_map(struct cbfs_media *media, size_t offset,
				 size_t count)
{
	return _dram + offset;
}

static void * dummy_unmap(struct cbfs_media *media, const void *address)
{
	return NULL;
}

static size_t on_chip_memory_read(struct cbfs_media *media, void *dest,
				  size_t offset, size_t count)
{
	void *ptr = media->map(media, offset, count);
	memcpy(dest, ptr, count);
	media->unmap(media, ptr);
	return count;
}

int init_default_cbfs_media(struct cbfs_media *media)
{
	struct cbfs_header *header =
		(struct cbfs_header *)(_dram + CONFIG_CBFS_HEADER_ROM_OFFSET);

	if (CBFS_HEADER_MAGIC != ntohl(header->magic)) {
		printk(BIOS_ERR, "Invalid CBFS master header at %p\n", header);
		return -1;
	}

	media->open = dummy_open;
	media->close = dummy_close;
	media->map = on_chip_memory_map;
	media->unmap = dummy_unmap;
	media->read = on_chip_memory_read;

	return 0;
}