hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 4 | * Copyright (C) 2011,2013,2014 Carl-Daniel Hailfinger |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 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. |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 17 | * Contains the opaque master framework. |
| 18 | * An opaque master is a master which does not provide direct access |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 19 | * to the flash chip and which abstracts all flash chip properties into a |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 20 | * master specific interface. |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include "flash.h" |
| 25 | #include "flashchips.h" |
| 26 | #include "chipdrivers.h" |
| 27 | #include "programmer.h" |
| 28 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 29 | int probe_opaque(struct flashctx *flash) |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 30 | { |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 31 | return flash->mst->opaque.probe(flash); |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 34 | int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 35 | { |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 36 | return flash->mst->opaque.read(flash, buf, start, len); |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 39 | int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 40 | { |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 41 | return flash->mst->opaque.write(flash, buf, start, len); |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 44 | int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 45 | { |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 46 | return flash->mst->opaque.erase(flash, blockaddr, blocklen); |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 49 | int register_opaque_master(const struct opaque_master *mst) |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 50 | { |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 51 | struct registered_master rmst; |
| 52 | |
| 53 | if (!mst->probe || !mst->read || !mst->write || !mst->erase) { |
| 54 | msg_perr("%s called with incomplete master definition. " |
| 55 | "Please report a bug at flashrom@flashrom.org\n", |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 56 | __func__); |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 57 | return ERROR_FLASHROM_BUG; |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 58 | } |
Edward O'Callaghan | c66827e | 2020-10-09 12:22:04 +1100 | [diff] [blame] | 59 | rmst.buses_supported = BUS_PROG; |
| 60 | rmst.opaque = *mst; |
| 61 | return register_master(&rmst); |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 62 | } |