Luc Verhaegen has uploaded this change for review. ( https://review.coreboot.org/29080
Change subject: pci2: add read/write/mask byte/long mmio accessors
......................................................................
pci2: add read/write/mask byte/long mmio accessors
As for the mask command:
For those "embedded developers" who grew up with the awkward x86 in/out
assembly instructions with the illogical ordering it will seem alien.
As a graphics driver developer who has had to deal with thousands of
registers at a time, mostly setting a few bits at a time, i found the
increased readability and debuggability of a mask command invaluable.
Once the ati_spi code is added, it will be clear just how effective
this command is.
As for the lack of automatic rollback:
- it makes little sense to roll back every single register written.
One could imagine a scenario where this would perfectly undo the
flash being written.
- it makes little sense to roll back every mask command:
Multiple mask commands are likely to touch the same register.
- engines, even simple spi engines, are triggered by a single bit or a
single register being written. Automatic rollback would trigger engines
before the fitting registers are written.
- reading might also trigger an engine. How does one roll back those?
How, if the register is automatically read before it is written, are
we dealing with that?
Instead, by providing programmer internal save/restore functions, the
programmer gets full control over what is saved and restored, and the
order in which those happen. The fact that we automatically retain
the device match private, should make it easier to have device specific
save/restore callbacks.
Change-Id: I5c3f57e9c510337bb81be30aa6c143840a349a60
Signed-off-by: Luc Verhaegen <libv(a)skynet.be>
---
M pcidev.c
M programmer.h
2 files changed, 101 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/80/29080/1
diff --git a/pcidev.c b/pcidev.c
index 8503e78..da4e2a3 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -535,3 +535,96 @@
return device;
}
+
+/*
+ *
+ * Accessors of mmio.
+ *
+ * It is nonsensical to roll these back automatically.
+ * Programmers are responsible for their own restauration.
+ *
+ */
+uint8_t flashrom_pci_mmio_byte_read(struct flashrom_pci_device *device,
+ off_t address)
+{
+ if (address >= device->mmio_size) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ return device->mmio[address];
+}
+
+void flashrom_pci_mmio_byte_write(struct flashrom_pci_device *device,
+ off_t address, uint8_t value)
+{
+ if (address >= device->mmio_size) {
+ errno = EFAULT;
+ return;
+ }
+
+ device->mmio[address] = value;
+}
+
+void flashrom_pci_mmio_byte_mask(struct flashrom_pci_device *device,
+ off_t address, uint8_t value, uint8_t mask)
+{
+ uint8_t temp;
+
+ if (address >= device->mmio_size) {
+ errno = EFAULT;
+ return;
+ }
+
+ value &= mask;
+
+ temp = device->mmio[address] & ~mask;
+ temp |= value & mask;
+
+ device->mmio[address] = temp;
+}
+
+uint32_t flashrom_pci_mmio_long_read(struct flashrom_pci_device *device,
+ off_t address)
+{
+ volatile uint32_t *mmio = (volatile uint32_t *) &device->mmio[address];
+
+ if ((address >= device->mmio_size) || (address & 0x03)) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ return mmio[0];
+}
+
+void flashrom_pci_mmio_long_write(struct flashrom_pci_device *device,
+ off_t address, uint32_t value)
+{
+ volatile uint32_t *mmio = (volatile uint32_t *) &device->mmio[address];
+
+ if ((address >= device->mmio_size) || (address & 0x03)) {
+ errno = EFAULT;
+ return;
+ }
+
+ mmio[0] = value;
+}
+
+void flashrom_pci_mmio_long_mask(struct flashrom_pci_device *device,
+ off_t address, uint32_t value, uint32_t mask)
+{
+ volatile uint32_t *mmio = (volatile uint32_t *) &device->mmio[address];
+ uint32_t temp;
+
+ if ((address >= device->mmio_size) || (address & 0x03)) {
+ errno = EFAULT;
+ return;
+ }
+
+ value &= mask;
+
+ temp = mmio[0] & ~mask;
+ temp |= value & mask;
+
+ mmio[0] = temp;
+}
diff --git a/programmer.h b/programmer.h
index d553317..1a7af7a 100644
--- a/programmer.h
+++ b/programmer.h
@@ -877,6 +877,14 @@
struct flashrom_pci_device *flashrom_pci_init(const struct flashrom_pci_match *matches);
int flashrom_pci_mmio_map(struct flashrom_pci_device *device, int bar);
void flashrom_pci_mmio_unmap(struct flashrom_pci_device *device);
+
+uint8_t flashrom_pci_mmio_byte_read(struct flashrom_pci_device *device, off_t address);
+void flashrom_pci_mmio_byte_write(struct flashrom_pci_device *device, off_t address, uint8_t value);
+void flashrom_pci_mmio_byte_mask(struct flashrom_pci_device *device, off_t address, uint8_t value, uint8_t mask);
+
+uint32_t flashrom_pci_mmio_long_read(struct flashrom_pci_device *device, off_t address);
+void flashrom_pci_mmio_long_write(struct flashrom_pci_device *device, off_t address, uint32_t value);
+void flashrom_pci_mmio_long_mask(struct flashrom_pci_device *device, off_t address, uint32_t value, uint32_t mask);
#endif /* NEED_PCI */
#endif /* !__PROGRAMMER_H__ */
--
To view, visit https://review.coreboot.org/29080
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c3f57e9c510337bb81be30aa6c143840a349a60
Gerrit-Change-Number: 29080
Gerrit-PatchSet: 1
Gerrit-Owner: Luc Verhaegen <libv(a)skynet.be>
David Hendricks has posted comments on this change. ( https://review.coreboot.org/23203 )
Change subject: Add support to get layout from fmap (e.g. coreboot rom)
......................................................................
Patch Set 25:
(4 comments)
https://review.coreboot.org/#/c/23203/22/flashrom.8.tmpl
File flashrom.8.tmpl:
https://review.coreboot.org/#/c/23203/22/flashrom.8.tmpl@52
PS22, Line 52: .SH DESCRIPTION
> Hmmm, new gerrit UI refused to save after editing above comment... […]
Thanks for clarifying, done. As you say it prints as follows now:
flashrom [-h|-R|-L|-z|-p <programmername>[:<parameters>]
[-E|-r <file>|-w <file>|-v <file>] [-c <chipname>]
[(-l <file>|--ifd| --fmap|--fmap-file <file>) [-i <image>]]
[-n] [-N] [-f]]
[-V[V[V]]] [-o <logfile>]
https://review.coreboot.org/#/c/23203/22/fmap.c
File fmap.c:
https://review.coreboot.org/#/c/23203/22/fmap.c@203
PS22, Line 203: }
> Now the malloc error path is missing the finalize_flash_access()...
d'oh... fixed.
https://review.coreboot.org/#/c/23203/24/fmap.c
File fmap.c:
https://review.coreboot.org/#/c/23203/24/fmap.c@281
PS24, Line 281: * should be a valid, usable fmap. */
> Should we set `ret = 2` here too?
Yes, that makes sense.
https://review.coreboot.org/#/c/23203/24/fmap.c@285
PS24, Line 285:
: *fmap_out = fmap;
: ret = 0;
: _free_ret:
: if (ret)
: free(fmap);
: finalize_flash_access(flashctx);
> Now that the code is more straight forward to read. We don't need […]
Yep, done.
--
To view, visit https://review.coreboot.org/23203
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I0e7fad38ed79a84d41358e1f175c36d255786c12
Gerrit-Change-Number: 23203
Gerrit-PatchSet: 25
Gerrit-Owner: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Werner Zeh <werner.zeh(a)siemens.com>
Gerrit-Comment-Date: Thu, 11 Oct 2018 04:48:34 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No
David Hendricks has uploaded a new patch set (#25) to the change originally created by Arthur Heymans. ( https://review.coreboot.org/23203 )
Change subject: Add support to get layout from fmap (e.g. coreboot rom)
......................................................................
Add support to get layout from fmap (e.g. coreboot rom)
Flashmap, or simply fmap, is a binary data format for describing
region offsets, sizes, and certain attributes and is widely used by
coreboot. This patch adds support for the fmap data format version 1.1
and adds --fmap and --fmap-file arguments.
Using --fmap will make flashrom to search the ROM content for fmap
data. Using --fmap-file will make flashrom search a supplied file
for fmap data.
An example of how to update the COREBOOT region of a ROM:
flashrom -p programmer --fmap -w coreboot.rom -i COREBOOT
flashrom -p programmer --fmap-file coreboot.rom -w coreboot.rom -i COREBOOT
The fmap functions are mostly copied from cbfstool.
Currently it is made mutually exclusive with other layout options until
we are more clever about this input.
Change-Id: I0e7fad38ed79a84d41358e1f175c36d255786c12
Signed-off-by: Arthur Heymans <arthur(a)aheymans.xyz>
Signed-off-by: David Hendricks <dhendricks(a)fb.com>
---
M Makefile
M cli_classic.c
M flashrom.8.tmpl
A fmap.c
A fmap.h
M libflashrom.c
M libflashrom.h
7 files changed, 648 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/03/23203/25
--
To view, visit https://review.coreboot.org/23203
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0e7fad38ed79a84d41358e1f175c36d255786c12
Gerrit-Change-Number: 23203
Gerrit-PatchSet: 25
Gerrit-Owner: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Werner Zeh <werner.zeh(a)siemens.com>
Nico Huber has submitted this change and it was merged. ( https://review.coreboot.org/28911 )
Change subject: ft2232_spi: add an ability to use GPIO for chip selection
......................................................................
ft2232_spi: add an ability to use GPIO for chip selection
Change-Id: I6db05619e0d69ad18549c8556ef69225337b1532
Signed-off-by: Sergey Alirzaev <zl29ah(a)gmail.com>
Reviewed-on: https://review.coreboot.org/28911
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
---
M flashrom.8.tmpl
M ft2232_spi.c
2 files changed, 26 insertions(+), 6 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index 70af395..f882dc6 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -722,9 +722,9 @@
Multi-Protocol Adapter (TUMPA), TUMPA Lite, GOEPEL PicoTAP and Google Servo v1/v2.
.sp
An optional parameter specifies the controller
-type and channel/interface/port it should support. For that you have to use the
+type, channel/interface/port and GPIO-based chip select it should support. For that you have to use the
.sp
-.B " flashrom \-p ft2232_spi:type=model,port=interface"
+.B " flashrom \-p ft2232_spi:type=model,port=interface,csgpiol=gpio"
.sp
syntax where
.B model
@@ -733,14 +733,17 @@
arm-usb-tiny ", " arm-usb-tiny-h ", " arm-usb-ocd ", " arm-usb-ocd-h \
", " tumpa ", " tumpalite ", " picotap ", " google-servo ", " google-servo-v2 \
" or " google-servo-v2-legacy
-and
.B interface
can be
-.BR A ", " B ", " C ", or " D .
+.BR A ", " B ", " C ", or " D
+and
+.B csgpiol
+can be a number between 0 and 3, denoting GPIOL0-GPIOL3 correspondingly.
The default model is
.B 4232H
-and the default interface is
-.BR A .
+the default interface is
+.BR A
+and GPIO is not used by default.
.sp
If there is more than one ft2232_spi-compatible device connected, you can select which one should be used by
specifying its serial number with the
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 819744c..95584aa 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -327,6 +327,23 @@
}
free(arg);
+ arg = extract_programmer_param("csgpiol");
+ if (arg) {
+ char *endptr;
+ unsigned int temp = strtoul(arg, &endptr, 10);
+ if (*endptr || endptr == arg || temp > 3) {
+ msg_perr("Error: Invalid GPIOL specified: \"%s\".\n"
+ "Valid values are between 0 and 3.\n", arg);
+ free(arg);
+ return -2;
+ } else {
+ unsigned int pin = temp + 4;
+ cs_bits |= 1 << pin;
+ pindir |= 1 << pin;
+ }
+ }
+ free(arg);
+
msg_pdbg("Using device type %s %s ",
get_ft2232_vendorname(ft2232_vid, ft2232_type),
get_ft2232_devicename(ft2232_vid, ft2232_type));
--
To view, visit https://review.coreboot.org/28911
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6db05619e0d69ad18549c8556ef69225337b1532
Gerrit-Change-Number: 28911
Gerrit-PatchSet: 7
Gerrit-Owner: Sergey Alirzaev <zl29ah(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Sergey Alirzaev <zl29ah(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>