Skip to content

Commit 521c432

Browse files
author
hailfinger
committed
Rename programmer registration functions
register_programmer suggests that we register a programmer. However, that function registers a master for a given bus type, and a programmer may support multiple masters (e.g. SPI, FWH). Rename a few other functions to be more consistent. Signed-off-by: Carl-Daniel Hailfinger <[email protected]> Acked-by: Stefan Tauner <[email protected]>
1 parent 0d4f561 commit 521c432

39 files changed

+194
-197
lines changed

at45db.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int spi_read_at45db(struct flashctx *flash, uint8_t *buf, unsigned int addr, uns
241241

242242
/* We have to split this up into chunks to fit within the programmer's read size limit, but those
243243
* chunks can cross page boundaries. */
244-
const unsigned int max_data_read = flash->pgm->spi.max_data_read;
244+
const unsigned int max_data_read = flash->mst->spi.max_data_read;
245245
const unsigned int max_chunk = (max_data_read > 0) ? max_data_read : page_size;
246246
while (len > 0) {
247247
unsigned int chunk = min(max_chunk, len);
@@ -272,7 +272,7 @@ int spi_read_at45db_e8(struct flashctx *flash, uint8_t *buf, unsigned int addr,
272272

273273
/* We have to split this up into chunks to fit within the programmer's read size limit, but those
274274
* chunks can cross page boundaries. */
275-
const unsigned int max_data_read = flash->pgm->spi.max_data_read;
275+
const unsigned int max_data_read = flash->mst->spi.max_data_read;
276276
const unsigned int max_chunk = (max_data_read > 0) ? max_data_read : page_size;
277277
while (len > 0) {
278278
const unsigned int addr_at45 = at45db_convert_addr(addr, page_size);
@@ -463,7 +463,7 @@ static int at45db_fill_buffer1(struct flashctx *flash, const uint8_t *bytes, uns
463463
}
464464

465465
/* Create a suitable buffer to store opcode, address and data chunks for buffer1. */
466-
const unsigned int max_data_write = flash->pgm->spi.max_data_write;
466+
const unsigned int max_data_write = flash->mst->spi.max_data_write;
467467
const unsigned int max_chunk = (max_data_write > 0 && max_data_write <= page_size) ?
468468
max_data_write : page_size;
469469
uint8_t buf[4 + max_chunk];

atahpt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
4747
chipaddr addr);
4848
static uint8_t atahpt_chip_readb(const struct flashctx *flash,
4949
const chipaddr addr);
50-
static const struct par_programmer par_programmer_atahpt = {
50+
static const struct par_master par_master_atahpt = {
5151
.chip_readb = atahpt_chip_readb,
5252
.chip_readw = fallback_chip_readw,
5353
.chip_readl = fallback_chip_readl,
@@ -79,7 +79,7 @@ int atahpt_init(void)
7979
reg32 |= (1 << 24);
8080
rpci_write_long(dev, REG_FLASH_ACCESS, reg32);
8181

82-
register_par_programmer(&par_programmer_atahpt, BUS_PARALLEL);
82+
register_par_master(&par_master_atahpt, BUS_PARALLEL);
8383

8484
return 0;
8585
}

atavia.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const struct dev_entry ata_via[] = {
6060

6161
static void atavia_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
6262
static uint8_t atavia_chip_readb(const struct flashctx *flash, const chipaddr addr);
63-
static const struct par_programmer lpc_programmer_atavia = {
63+
static const struct par_master lpc_master_atavia = {
6464
.chip_readb = atavia_chip_readb,
6565
.chip_readw = fallback_chip_readw,
6666
.chip_readl = fallback_chip_readl,
@@ -164,7 +164,7 @@ int atavia_init(void)
164164
return 1;
165165
}
166166

167-
register_par_programmer(&lpc_programmer_atavia, BUS_LPC);
167+
register_par_master(&lpc_master_atavia, BUS_LPC);
168168

169169
return 0;
170170
}

bitbang_spi.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int bitbang_spi_send_command(struct flashctx *flash,
6363
const unsigned char *writearr,
6464
unsigned char *readarr);
6565

66-
static const struct spi_programmer spi_programmer_bitbang = {
66+
static const struct spi_master spi_master_bitbang = {
6767
.type = SPI_CONTROLLER_BITBANG,
6868
.max_data_read = MAX_DATA_READ_UNLIMITED,
6969
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
@@ -82,9 +82,9 @@ static int bitbang_spi_shutdown(const struct bitbang_spi_master *master)
8282
}
8383
#endif
8484

85-
int bitbang_spi_init(const struct bitbang_spi_master *master)
85+
int register_spi_bitbang_master(const struct bitbang_spi_master *master)
8686
{
87-
struct spi_programmer pgm = spi_programmer_bitbang;
87+
struct spi_master mst = spi_master_bitbang;
8888
/* BITBANG_SPI_INVALID is 0, so if someone forgot to initialize ->type,
8989
* we catch it here. Same goes for missing initialization of bitbanging
9090
* functions.
@@ -98,8 +98,8 @@ int bitbang_spi_init(const struct bitbang_spi_master *master)
9898
return ERROR_FLASHROM_BUG;
9999
}
100100

101-
pgm.data = master;
102-
register_spi_programmer(&pgm);
101+
mst.data = master;
102+
register_spi_master(&mst);
103103

104104
/* Only mess with the bus if we're sure nobody else uses it. */
105105
bitbang_spi_request_bus(master);
@@ -137,7 +137,7 @@ static int bitbang_spi_send_command(struct flashctx *flash,
137137
unsigned char *readarr)
138138
{
139139
int i;
140-
const struct bitbang_spi_master *master = flash->pgm->spi.data;
140+
const struct bitbang_spi_master *master = flash->mst->spi.data;
141141

142142
/* FIXME: Run bitbang_spi_request_bus here or in programmer init?
143143
* Requesting and releasing the SPI bus is handled in here to allow the

buspirate_spi.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int buspirate_spi_send_command_v1(struct flashctx *flash, unsigned int wr
134134
static int buspirate_spi_send_command_v2(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
135135
const unsigned char *writearr, unsigned char *readarr);
136136

137-
static struct spi_programmer spi_programmer_buspirate = {
137+
static struct spi_master spi_master_buspirate = {
138138
.type = SPI_CONTROLLER_BUSPIRATE,
139139
.max_data_read = MAX_DATA_UNSPECIFIED,
140140
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -355,19 +355,19 @@ int buspirate_spi_init(void)
355355
/* Sensible default buffer size. */
356356
if (buspirate_commbuf_grow(260 + 5))
357357
return ERROR_OOM;
358-
spi_programmer_buspirate.max_data_read = 2048;
359-
spi_programmer_buspirate.max_data_write = 256;
360-
spi_programmer_buspirate.command = buspirate_spi_send_command_v2;
358+
spi_master_buspirate.max_data_read = 2048;
359+
spi_master_buspirate.max_data_write = 256;
360+
spi_master_buspirate.command = buspirate_spi_send_command_v2;
361361
} else {
362362
msg_pinfo("Bus Pirate firmware 5.4 and older does not support fast SPI access.\n");
363363
msg_pinfo("Reading/writing a flash chip may take hours.\n");
364364
msg_pinfo("It is recommended to upgrade to firmware 5.5 or newer.\n");
365365
/* Sensible default buffer size. */
366366
if (buspirate_commbuf_grow(16 + 3))
367367
return ERROR_OOM;
368-
spi_programmer_buspirate.max_data_read = 12;
369-
spi_programmer_buspirate.max_data_write = 12;
370-
spi_programmer_buspirate.command = buspirate_spi_send_command_v1;
368+
spi_master_buspirate.max_data_read = 12;
369+
spi_master_buspirate.max_data_write = 12;
370+
spi_master_buspirate.command = buspirate_spi_send_command_v1;
371371
}
372372

373373
/* Workaround for broken speed settings in firmware 6.1 and older. */
@@ -454,7 +454,7 @@ int buspirate_spi_init(void)
454454
return 1;
455455
}
456456

457-
register_spi_programmer(&spi_programmer_buspirate);
457+
register_spi_master(&spi_master_buspirate);
458458

459459
return 0;
460460
}

cli_classic.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ int main(int argc, char *argv[])
426426
msg_pdbg("The following protocols are supported: %s.\n", tempstr);
427427
free(tempstr);
428428

429-
for (j = 0; j < registered_programmer_count; j++) {
429+
for (j = 0; j < registered_master_count; j++) {
430430
startchip = 0;
431431
while (chipcount < ARRAY_SIZE(flashes)) {
432-
startchip = probe_flash(&registered_programmers[j], startchip, &flashes[chipcount], 0);
432+
startchip = probe_flash(&registered_masters[j], startchip, &flashes[chipcount], 0);
433433
if (startchip == -1)
434434
break;
435435
chipcount++;
@@ -452,27 +452,27 @@ int main(int argc, char *argv[])
452452
"automatically.\n");
453453
}
454454
if (force && read_it && chip_to_probe) {
455-
struct registered_programmer *pgm;
456-
int compatible_programmers = 0;
455+
struct registered_master *mst;
456+
int compatible_masters = 0;
457457
msg_cinfo("Force read (-f -r -c) requested, pretending the chip is there:\n");
458458
/* This loop just counts compatible controllers. */
459-
for (j = 0; j < registered_programmer_count; j++) {
460-
pgm = &registered_programmers[j];
459+
for (j = 0; j < registered_master_count; j++) {
460+
mst = &registered_masters[j];
461461
/* chip is still set from the chip_to_probe earlier in this function. */
462-
if (pgm->buses_supported & chip->bustype)
463-
compatible_programmers++;
462+
if (mst->buses_supported & chip->bustype)
463+
compatible_masters++;
464464
}
465-
if (!compatible_programmers) {
465+
if (!compatible_masters) {
466466
msg_cinfo("No compatible controller found for the requested flash chip.\n");
467467
ret = 1;
468468
goto out_shutdown;
469469
}
470-
if (compatible_programmers > 1)
470+
if (compatible_masters > 1)
471471
msg_cinfo("More than one compatible controller found for the requested flash "
472472
"chip, using the first one.\n");
473-
for (j = 0; j < registered_programmer_count; j++) {
474-
pgm = &registered_programmers[j];
475-
startchip = probe_flash(pgm, 0, &flashes[0], 1);
473+
for (j = 0; j < registered_master_count; j++) {
474+
mst = &registered_masters[j];
475+
startchip = probe_flash(mst, 0, &flashes[0], 1);
476476
if (startchip != -1)
477477
break;
478478
}
@@ -502,7 +502,7 @@ int main(int argc, char *argv[])
502502
check_chip_supported(fill_flash->chip);
503503

504504
size = fill_flash->chip->total_size * 1024;
505-
if (check_max_decode(fill_flash->pgm->buses_supported & fill_flash->chip->bustype, size) && (!force)) {
505+
if (check_max_decode(fill_flash->mst->buses_supported & fill_flash->chip->bustype, size) && (!force)) {
506506
msg_cerr("Chip is too big for this programmer (-V gives details). Use --force to override.\n");
507507
ret = 1;
508508
goto out_shutdown;

dediprog.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static int dediprog_setup(long target)
750750
return 0;
751751
}
752752

753-
static const struct spi_programmer spi_programmer_dediprog = {
753+
static const struct spi_master spi_master_dediprog = {
754754
.type = SPI_CONTROLLER_DEDIPROG,
755755
.max_data_read = MAX_DATA_UNSPECIFIED,
756756
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -929,7 +929,7 @@ int dediprog_init(void)
929929
return 1;
930930
}
931931

932-
register_spi_programmer(&spi_programmer_dediprog);
932+
register_spi_master(&spi_master_dediprog);
933933

934934
/* RE leftover, leave in until the driver is complete. */
935935
#if 0

drkaiser.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
4545
chipaddr addr);
4646
static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
4747
const chipaddr addr);
48-
static const struct par_programmer par_programmer_drkaiser = {
48+
static const struct par_master par_master_drkaiser = {
4949
.chip_readb = drkaiser_chip_readb,
5050
.chip_readw = fallback_chip_readw,
5151
.chip_readl = fallback_chip_readl,
@@ -81,7 +81,7 @@ int drkaiser_init(void)
8181
return 1;
8282

8383
max_rom_decode.parallel = 128 * 1024;
84-
register_par_programmer(&par_programmer_drkaiser, BUS_PARALLEL);
84+
register_par_master(&par_master_drkaiser, BUS_PARALLEL);
8585

8686
return 0;
8787
}

dummyflasher.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr ad
109109
static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr);
110110
static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
111111

112-
static const struct spi_programmer spi_programmer_dummyflasher = {
112+
static const struct spi_master spi_master_dummyflasher = {
113113
.type = SPI_CONTROLLER_DUMMY,
114114
.max_data_read = MAX_DATA_READ_UNLIMITED,
115115
.max_data_write = MAX_DATA_UNSPECIFIED,
@@ -120,7 +120,7 @@ static const struct spi_programmer spi_programmer_dummyflasher = {
120120
.write_aai = default_spi_write_aai,
121121
};
122122

123-
static const struct par_programmer par_programmer_dummy = {
123+
static const struct par_master par_master_dummy = {
124124
.chip_readb = dummy_chip_readb,
125125
.chip_readw = dummy_chip_readw,
126126
.chip_readl = dummy_chip_readl,
@@ -395,12 +395,10 @@ int dummy_init(void)
395395
return 1;
396396
}
397397
if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
398-
register_par_programmer(&par_programmer_dummy,
399-
dummy_buses_supported &
400-
(BUS_PARALLEL | BUS_LPC |
401-
BUS_FWH));
398+
register_par_master(&par_master_dummy,
399+
dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
402400
if (dummy_buses_supported & BUS_SPI)
403-
register_spi_programmer(&spi_programmer_dummyflasher);
401+
register_spi_master(&spi_master_dummyflasher);
404402

405403
return 0;
406404
}

flash.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ struct flashctx {
212212
chipaddr virtual_memory;
213213
/* Some flash devices have an additional register space. */
214214
chipaddr virtual_registers;
215-
struct registered_programmer *pgm;
215+
struct registered_master *mst;
216216
};
217217

218218
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
@@ -258,7 +258,7 @@ extern const char *chip_to_probe;
258258
void map_flash_registers(struct flashctx *flash);
259259
int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
260260
int erase_flash(struct flashctx *flash);
261-
int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *fill_flash, int force);
261+
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
262262
int read_flash_to_file(struct flashctx *flash, const char *filename);
263263
char *extract_param(const char *const *haystack, const char *needle, const char *delim);
264264
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);

flashrom.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ int programmer_shutdown(void)
454454
}
455455

456456
programmer_param = NULL;
457-
registered_programmer_count = 0;
457+
registered_master_count = 0;
458458

459459
return ret;
460460
}
@@ -474,43 +474,43 @@ void programmer_unmap_flash_region(void *virt_addr, size_t len)
474474

475475
void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
476476
{
477-
flash->pgm->par.chip_writeb(flash, val, addr);
477+
flash->mst->par.chip_writeb(flash, val, addr);
478478
}
479479

480480
void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
481481
{
482-
flash->pgm->par.chip_writew(flash, val, addr);
482+
flash->mst->par.chip_writew(flash, val, addr);
483483
}
484484

485485
void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
486486
{
487-
flash->pgm->par.chip_writel(flash, val, addr);
487+
flash->mst->par.chip_writel(flash, val, addr);
488488
}
489489

490490
void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
491491
{
492-
flash->pgm->par.chip_writen(flash, buf, addr, len);
492+
flash->mst->par.chip_writen(flash, buf, addr, len);
493493
}
494494

495495
uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr)
496496
{
497-
return flash->pgm->par.chip_readb(flash, addr);
497+
return flash->mst->par.chip_readb(flash, addr);
498498
}
499499

500500
uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr)
501501
{
502-
return flash->pgm->par.chip_readw(flash, addr);
502+
return flash->mst->par.chip_readw(flash, addr);
503503
}
504504

505505
uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr)
506506
{
507-
return flash->pgm->par.chip_readl(flash, addr);
507+
return flash->mst->par.chip_readl(flash, addr);
508508
}
509509

510510
void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr,
511511
size_t len)
512512
{
513-
flash->pgm->par.chip_readn(flash, buf, addr, len);
513+
flash->mst->par.chip_readn(flash, buf, addr, len);
514514
}
515515

516516
void programmer_delay(unsigned int usecs)
@@ -1049,7 +1049,7 @@ int check_max_decode(enum chipbustype buses, uint32_t size)
10491049
return 1;
10501050
}
10511051

1052-
int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *flash, int force)
1052+
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force)
10531053
{
10541054
const struct flashchip *chip;
10551055
unsigned long base = 0;
@@ -1061,7 +1061,7 @@ int probe_flash(struct registered_programmer *pgm, int startchip, struct flashct
10611061
for (chip = flashchips + startchip; chip && chip->name; chip++) {
10621062
if (chip_to_probe && strcmp(chip->name, chip_to_probe) != 0)
10631063
continue;
1064-
buses_common = pgm->buses_supported & chip->bustype;
1064+
buses_common = mst->buses_supported & chip->bustype;
10651065
if (!buses_common)
10661066
continue;
10671067
msg_gdbg("Probing for %s %s, %d kB: ", chip->vendor, chip->name, chip->total_size);
@@ -1080,7 +1080,7 @@ int probe_flash(struct registered_programmer *pgm, int startchip, struct flashct
10801080
exit(1);
10811081
}
10821082
memcpy(flash->chip, chip, sizeof(struct flashchip));
1083-
flash->pgm = pgm;
1083+
flash->mst = mst;
10841084

10851085
base = flashbase ? flashbase : (0xffffffff - size + 1);
10861086
flash->virtual_memory = (chipaddr)programmer_map_flash_region("flash chip", base, size);
@@ -1098,7 +1098,7 @@ int probe_flash(struct registered_programmer *pgm, int startchip, struct flashct
10981098
* If this is not the first chip found, accept it only if it is
10991099
* a non-generic match. SFDP and CFI are generic matches.
11001100
* startchip==0 means this call to probe_flash() is the first
1101-
* one for this programmer interface and thus no other chip has
1101+
* one for this programmer interface (master) and thus no other chip has
11021102
* been found on this interface.
11031103
*/
11041104
if (startchip == 0 && flash->chip->model_id == SFDP_DEVICE_ID) {

0 commit comments

Comments
 (0)