blob: 458c2695cebee1e92de48709f963f1d42700f269 [file] [log] [blame]
hailfingerfe7cd9e2011-11-04 21:35:26 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2011 Carl-Daniel Hailfinger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20/*
21 * Contains the opaque programmer framework.
22 * An opaque programmer is a programmer which does not provide direct access
23 * to the flash chip and which abstracts all flash chip properties into a
24 * programmer specific interface.
25 */
26
27#include <stdint.h>
28#include "flash.h"
29#include "flashchips.h"
30#include "chipdrivers.h"
31#include "programmer.h"
32
Souvik Ghoshd75cd672016-06-17 14:21:39 -070033int probe_opaque(struct flashctx *flash)
hailfingerfe7cd9e2011-11-04 21:35:26 +000034{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070035 return flash->pgm->opaque.probe(flash);
hailfingerfe7cd9e2011-11-04 21:35:26 +000036}
37
Souvik Ghoshd75cd672016-06-17 14:21:39 -070038int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
hailfingerfe7cd9e2011-11-04 21:35:26 +000039{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070040 return flash->pgm->opaque.read(flash, buf, start, len);
hailfingerfe7cd9e2011-11-04 21:35:26 +000041}
42
Souvik Ghoshd75cd672016-06-17 14:21:39 -070043int write_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
hailfingerfe7cd9e2011-11-04 21:35:26 +000044{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070045 return flash->pgm->opaque.write(flash, buf, start, len);
hailfingerfe7cd9e2011-11-04 21:35:26 +000046}
47
Souvik Ghoshd75cd672016-06-17 14:21:39 -070048int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
hailfingerfe7cd9e2011-11-04 21:35:26 +000049{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070050 return flash->pgm->opaque.erase(flash, blockaddr, blocklen);
hailfingerfe7cd9e2011-11-04 21:35:26 +000051}
52
Souvik Ghoshd75cd672016-06-17 14:21:39 -070053uint8_t read_status_opaque(const struct flashctx *flash)
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053054{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070055 return flash->pgm->opaque.read_status(flash);
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053056}
57
Souvik Ghoshd75cd672016-06-17 14:21:39 -070058int write_status_opaque(const struct flashctx *flash, int status)
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053059{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070060 return flash->pgm->opaque.write_status(flash, status);
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053061}
62
Souvik Ghosh63b92f92016-06-29 18:45:52 -070063int register_opaque_programmer(const struct opaque_programmer *pgm)
hailfingerfe7cd9e2011-11-04 21:35:26 +000064{
Souvik Ghosh63b92f92016-06-29 18:45:52 -070065 struct registered_programmer rpgm;
66
hailfingerfe7cd9e2011-11-04 21:35:26 +000067 if (!pgm->probe || !pgm->read || !pgm->write || !pgm->erase) {
Souvik Ghosh63b92f92016-06-29 18:45:52 -070068 msg_perr("%s called with incomplete programmer definition. "
69 "Please report a bug at flashrom@flashrom.org\n",
hailfingerfe7cd9e2011-11-04 21:35:26 +000070 __func__);
Souvik Ghosh63b92f92016-06-29 18:45:52 -070071 return ERROR_FLASHROM_BUG;
hailfingerfe7cd9e2011-11-04 21:35:26 +000072 }
Souvik Ghosh63b92f92016-06-29 18:45:52 -070073 rpgm.buses_supported = BUS_PROG;
74 rpgm.opaque = *pgm;
75 return register_programmer(&rpgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +000076}