Author: stefanct
Date: Fri Jul 1 02:39:09 2011
New Revision: 1360
URL: http://flashrom.org/trac/flashrom/changeset/1360
Log:
ichspi.c: simplify ich_set_bbar
Less code, documenting better what the differences are (i.e. offset of BBAR only).
Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Modified:
trunk/ichspi.c
Modified: trunk/ichspi.c
==============================================================================
--- trunk/ichspi.c Fri Jul 1 02:39:01 2011 (r1359)
+++ trunk/ichspi.c Fri Jul 1 02:39:09 2011 (r1360)
@@ -555,43 +555,37 @@
* Try to set BBAR (BIOS Base Address Register), but read back the value in case
* it didn't stick.
*/
-void ich_set_bbar(uint32_t minaddr)
+static void ich_set_bbar(uint32_t min_addr)
{
- minaddr &= BBAR_MASK;
+ int bbar_off;
switch (spi_programmer->type) {
case SPI_CONTROLLER_ICH7:
case SPI_CONTROLLER_VIA:
- ichspi_bbar = mmio_readl(ich_spibar + 0x50) & ~BBAR_MASK;
- if (ichspi_bbar)
- msg_pdbg("Reserved bits in BBAR not zero: 0x%04x",
- ichspi_bbar);
- ichspi_bbar |= minaddr;
- rmmio_writel(ichspi_bbar, ich_spibar + 0x50);
- ichspi_bbar = mmio_readl(ich_spibar + 0x50);
- /* We don't have any option except complaining. And if the write
- * failed, the restore will fail as well, so no problem there.
- */
- if (ichspi_bbar != minaddr)
- msg_perr("Setting BBAR failed!\n");
+ bbar_off = 0x50;
break;
case SPI_CONTROLLER_ICH9:
- ichspi_bbar = mmio_readl(ich_spibar + ICH9_REG_BBAR) & ~BBAR_MASK;
- if (ichspi_bbar)
- msg_pdbg("Reserved bits in BBAR not zero: 0x%04x",
- ichspi_bbar);
- ichspi_bbar |= minaddr;
- rmmio_writel(ichspi_bbar, ich_spibar + ICH9_REG_BBAR);
- ichspi_bbar = mmio_readl(ich_spibar + ICH9_REG_BBAR);
- /* We don't have any option except complaining. And if the write
- * failed, the restore will fail as well, so no problem there.
- */
- if (ichspi_bbar != minaddr)
- msg_perr("Setting BBAR failed!\n");
+ bbar_off = ICH9_REG_BBAR;
break;
default:
msg_perr("Unknown chipset for BBAR setting!\n");
- break;
+ return;
+ }
+
+ ichspi_bbar = mmio_readl(ich_spibar + bbar_off) & ~BBAR_MASK;
+ if (ichspi_bbar) {
+ msg_pdbg("Reserved bits in BBAR not zero: 0x%08x\n",
+ ichspi_bbar);
}
+ min_addr &= BBAR_MASK;
+ ichspi_bbar |= min_addr;
+ rmmio_writel(ichspi_bbar, ich_spibar + bbar_off);
+ ichspi_bbar = mmio_readl(ich_spibar + bbar_off) & BBAR_MASK;
+
+ /* We don't have any option except complaining. And if the write
+ * failed, the restore will fail as well, so no problem there.
+ */
+ if (ichspi_bbar != min_addr)
+ msg_perr("Setting BBAR failed!\n");
}
/* This function generates OPCODES from or programs OPCODES to ICH according to
Am 24.06.2011 16:53 schrieb Stefan Tauner:
> This can be used in various situations (including one in the upcoming SFDP patch) and
> removes one FIXME in current HEAD. Needed to move check_block_eraser (which checks a
> single eraser) up to avoid (upcoming) forward declaration(s).
>
Since nobody objected to the "forward declarations" RFC, I think we can
safely say that moving code around inside a file is a bad idea. Please
kill that part.
> Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
> ---
> flashrom.c | 70 ++++++++++++++++++++++++++++++++++-------------------------
> 1 files changed, 40 insertions(+), 30 deletions(-)
>
> diff --git a/flashrom.c b/flashrom.c
> index 6979d84..aed10aa 100644
> --- a/flashrom.c
> +++ b/flashrom.c
> @@ @@
> +/* Returns the number of well-defined erasers for a chip.
> + * The log parameter controls output. */
> +static int check_block_erasers(const struct flashchip *flash, int log)
>
Hm. Can you call it count_usable_erasers or count_usable_block_erasers
instead?
> +{
> + int usable_erasefunctions = 0;
> + int k;
> + for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
> + if (!check_block_eraser(flash, k, 0))
> + usable_erasefunctions++;
> + }
> + return usable_erasefunctions;
> +}
> +
>
Rest looks good to me.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
Author: stefanct
Date: Fri Jul 1 02:19:12 2011
New Revision: 1358
URL: http://flashrom.org/trac/flashrom/changeset/1358
Log:
add count_usable_erasers which returns the number of well-defined erasers for a chip
It solves one FIXME and consequentially allows to remove a later check
right now, and is used in the upcoming SFDP patch.
Adds a forward declaration of check_block_eraser.
Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Modified:
trunk/flashrom.c
Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c Sun Jun 26 22:45:35 2011 (r1357)
+++ trunk/flashrom.c Fri Jul 1 02:19:12 2011 (r1358)
@@ -465,6 +465,8 @@
*/
static int may_register_shutdown = 0;
+static int check_block_eraser(const struct flashchip *flash, int k, int log);
+
/* Register a function to be executed on programmer shutdown.
* The advantage over atexit() is that you can supply a void pointer which will
* be used as parameter to the registered function upon programmer shutdown.
@@ -711,6 +713,19 @@
return extract_param(&programmer_param, param_name, ",");
}
+/* Returns the number of well-defined erasers for a chip.
+ * The log parameter controls output. */
+static unsigned int count_usable_erasers(const struct flashchip *flash, int log)
+{
+ unsigned int usable_erasefunctions = 0;
+ int k;
+ for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
+ if (!check_block_eraser(flash, k, 0))
+ usable_erasefunctions++;
+ }
+ return usable_erasefunctions;
+}
+
/* start is an offset to the base address of the flash chip */
int check_erased_range(struct flashchip *flash, int start, int len)
{
@@ -1467,7 +1482,7 @@
return 0;
}
-static int check_block_eraser(struct flashchip *flash, int k, int log)
+static int check_block_eraser(const struct flashchip *flash, int k, int log)
{
struct block_eraser eraser = flash->block_erasers[k];
@@ -1496,18 +1511,9 @@
int k, ret = 0;
uint8_t *curcontents;
unsigned long size = flash->total_size * 1024;
- int usable_erasefunctions = 0;
+ unsigned int usable_erasefunctions = count_usable_erasers(flash, 0);
- for (k = 0; k < NUM_ERASEFUNCTIONS; k++)
- if (!check_block_eraser(flash, k, 0))
- usable_erasefunctions++;
msg_cinfo("Erasing and writing flash chip... ");
- if (!usable_erasefunctions) {
- msg_cerr("ERROR: flashrom has no erase function for this flash "
- "chip.\n");
- return 1;
- }
-
curcontents = (uint8_t *) malloc(size);
/* Copy oldcontents to curcontents to avoid clobbering oldcontents. */
memcpy(curcontents, oldcontents, size);
@@ -1825,7 +1831,11 @@
return 1;
msg_cerr("Continuing anyway.\n");
}
- /* FIXME: Check if at least one erase function exists. */
+ if(count_usable_erasers(flash, 0) == 0) {
+ msg_cerr("flashrom has no erase function for this "
+ "flash chip.\n");
+ return 1;
+ }
}
if (write_it) {
if (flash->tested & TEST_BAD_WRITE) {