opaque.c 2.03 KB
Newer Older
1 2 3
/*
 * This file is part of the flashrom project.
 *
4
 * Copyright (C) 2011,2013,2014 Carl-Daniel Hailfinger
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

/*
21 22
 * Contains the opaque master framework.
 * An opaque master is a master which does not provide direct access
23
 * to the flash chip and which abstracts all flash chip properties into a
24
 * master specific interface.
25 26 27 28 29 30 31 32
 */

#include <stdint.h>
#include "flash.h"
#include "flashchips.h"
#include "chipdrivers.h"
#include "programmer.h"

33
int probe_opaque(struct flashctx *flash)
34
{
35
	return flash->mst->opaque.probe(flash);
36 37
}

38
int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
39
{
40
	return flash->mst->opaque.read(flash, buf, start, len);
41 42
}

43
int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
44
{
45
	return flash->mst->opaque.write(flash, buf, start, len);
46 47
}

48
int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
49
{
50
	return flash->mst->opaque.erase(flash, blockaddr, blocklen);
51 52
}

53
int register_opaque_master(const struct opaque_master *mst)
54
{
55
	struct registered_master rmst;
56

57 58
	if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
		msg_perr("%s called with incomplete master definition. "
59
			 "Please report a bug at flashrom@flashrom.org\n",
60
			 __func__);
61
		return ERROR_FLASHROM_BUG;
62
	}
63 64 65
	rmst.buses_supported = BUS_PROG;
	rmst.opaque = *mst;
	return register_master(&rmst);
66
}