1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 07:23:43 +02:00

Random whitespace and coding-style fixes

Also, indentation fixes, e.g. due to conversion to msg_*, use ARRAY_SIZE
where possible, wrap overly long line, etc.

Compile-tested. There should be no functional changes.

Corresponding to flashrom svn r1397.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
This commit is contained in:
Uwe Hermann 2011-07-28 08:13:25 +00:00
parent 1a227954f2
commit 91f4afa110
20 changed files with 523 additions and 523 deletions

View File

@ -29,7 +29,6 @@
#include "flash.h" #include "flash.h"
#include "chipdrivers.h" #include "chipdrivers.h"
// I need that Berkeley bit-map printer
void print_status_82802ab(uint8_t status) void print_status_82802ab(uint8_t status)
{ {
msg_cdbg("%s", status & 0x80 ? "Ready:" : "Busy:"); msg_cdbg("%s", status & 0x80 ? "Ready:" : "Busy:");
@ -44,8 +43,7 @@ void print_status_82802ab(uint8_t status)
int probe_82802ab(struct flashchip *flash) int probe_82802ab(struct flashchip *flash)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
uint8_t id1, id2; uint8_t id1, id2, flashcontent1, flashcontent2;
uint8_t flashcontent1, flashcontent2;
int shifted = (flash->feature_bits & FEATURE_ADDR_SHIFTED) != 0; int shifted = (flash->feature_bits & FEATURE_ADDR_SHIFTED) != 0;
/* Reset to get a clean state */ /* Reset to get a clean state */
@ -69,7 +67,10 @@ int probe_82802ab(struct flashchip *flash)
if (!oddparity(id1)) if (!oddparity(id1))
msg_cdbg(", id1 parity violation"); msg_cdbg(", id1 parity violation");
/* Read the product ID location again. We should now see normal flash contents. */ /*
* Read the product ID location again. We should now see normal
* flash contents.
*/
flashcontent1 = chip_readb(bios + (0x00 << shifted)); flashcontent1 = chip_readb(bios + (0x00 << shifted));
flashcontent2 = chip_readb(bios + (0x01 << shifted)); flashcontent2 = chip_readb(bios + (0x01 << shifted));
@ -112,14 +113,13 @@ int unlock_82802ab(struct flashchip *flash)
//chipaddr wrprotect = flash->virtual_registers + page + 2; //chipaddr wrprotect = flash->virtual_registers + page + 2;
for (i = 0; i < flash->total_size * 1024; i+= flash->page_size) for (i = 0; i < flash->total_size * 1024; i+= flash->page_size)
{
chip_writeb(0, flash->virtual_registers + i + 2); chip_writeb(0, flash->virtual_registers + i + 2);
}
return 0; return 0;
} }
int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize) int erase_block_82802ab(struct flashchip *flash, unsigned int page,
unsigned int pagesize)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
uint8_t status; uint8_t status;

View File

@ -179,7 +179,7 @@ static const struct winbond_mux w83627hf_port2_mux[8] = {
static const struct winbond_port w83627hf[3] = { static const struct winbond_port w83627hf[3] = {
UNIMPLEMENTED_PORT, UNIMPLEMENTED_PORT,
{w83627hf_port2_mux, 0x08, 0, 0xF0}, {w83627hf_port2_mux, 0x08, 0, 0xF0},
UNIMPLEMENTED_PORT UNIMPLEMENTED_PORT,
}; };
static const struct winbond_mux w83627ehf_port2_mux[8] = { static const struct winbond_mux w83627ehf_port2_mux[8] = {
@ -190,7 +190,7 @@ static const struct winbond_mux w83627ehf_port2_mux[8] = {
{0x2A, 0x01, 0x01}, /* or keyboard/mouse interface */ {0x2A, 0x01, 0x01}, /* or keyboard/mouse interface */
{0x2A, 0x01, 0x01}, {0x2A, 0x01, 0x01},
{0x2A, 0x01, 0x01}, {0x2A, 0x01, 0x01},
{0x2A, 0x01, 0x01} {0x2A, 0x01, 0x01},
}; };
static const struct winbond_port w83627ehf[6] = { static const struct winbond_port w83627ehf[6] = {
@ -199,7 +199,7 @@ static const struct winbond_port w83627ehf[6] = {
UNIMPLEMENTED_PORT, UNIMPLEMENTED_PORT,
UNIMPLEMENTED_PORT, UNIMPLEMENTED_PORT,
UNIMPLEMENTED_PORT, UNIMPLEMENTED_PORT,
UNIMPLEMENTED_PORT UNIMPLEMENTED_PORT,
}; };
static const struct winbond_mux w83627thf_port4_mux[8] = { static const struct winbond_mux w83627thf_port4_mux[8] = {
@ -210,7 +210,7 @@ static const struct winbond_mux w83627thf_port4_mux[8] = {
{0x2D, 0x10, 0x10}, /* or PWROK */ {0x2D, 0x10, 0x10}, /* or PWROK */
{0x2D, 0x20, 0x20}, /* or suspend LED */ {0x2D, 0x20, 0x20}, /* or suspend LED */
{0x2D, 0x40, 0x40}, /* or panel switch input */ {0x2D, 0x40, 0x40}, /* or panel switch input */
{0x2D, 0x80, 0x80} /* or panel switch output */ {0x2D, 0x80, 0x80}, /* or panel switch output */
}; };
static const struct winbond_port w83627thf[5] = { static const struct winbond_port w83627thf[5] = {
@ -218,7 +218,7 @@ static const struct winbond_port w83627thf[5] = {
UNIMPLEMENTED_PORT, /* GPIO2 */ UNIMPLEMENTED_PORT, /* GPIO2 */
UNIMPLEMENTED_PORT, /* GPIO3 */ UNIMPLEMENTED_PORT, /* GPIO3 */
{w83627thf_port4_mux, 0x09, 1, 0xF4}, {w83627thf_port4_mux, 0x09, 1, 0xF4},
UNIMPLEMENTED_PORT /* GPIO5 */ UNIMPLEMENTED_PORT, /* GPIO5 */
}; };
static const struct winbond_chip winbond_chips[] = { static const struct winbond_chip winbond_chips[] = {
@ -561,7 +561,8 @@ static int pc8736x_gpio_set(uint8_t chipid, uint8_t gpio, int raise)
id = sio_read(0x2E, 0x20); id = sio_read(0x2E, 0x20);
if (id != chipid) { if (id != chipid) {
msg_perr("PC8736x: unexpected ID %02x (expected %02x)\n", id, chipid); msg_perr("PC8736x: unexpected ID %02x (expected %02x)\n",
id, chipid);
return -1; return -1;
} }
@ -811,13 +812,13 @@ static int board_shuttle_fn25(void)
{ {
struct pci_dev *dev; struct pci_dev *dev;
dev = pci_dev_find(0x10DE, 0x0050); /* NVIDIA CK804 ISA Bridge. */ dev = pci_dev_find(0x10DE, 0x0050); /* NVIDIA CK804 ISA bridge. */
if (!dev) { if (!dev) {
msg_perr("\nERROR: NVIDIA nForce4 ISA bridge not found.\n"); msg_perr("\nERROR: NVIDIA nForce4 ISA bridge not found.\n");
return -1; return -1;
} }
/* one of those bits seems to be connected to TBL#, but -ENOINFO. */ /* One of those bits seems to be connected to TBL#, but -ENOINFO. */
pci_write_byte(dev, 0x92, 0); pci_write_byte(dev, 0x92, 0);
return 0; return 0;
@ -851,8 +852,7 @@ static int board_ecs_geforce6100sm_m(void)
static int nvidia_mcp_gpio_set(int gpio, int raise) static int nvidia_mcp_gpio_set(int gpio, int raise)
{ {
struct pci_dev *dev; struct pci_dev *dev;
uint16_t base; uint16_t base, devclass;
uint16_t devclass;
uint8_t tmp; uint8_t tmp;
if ((gpio < 0) || (gpio >= 0x40)) { if ((gpio < 0) || (gpio >= 0x40)) {
@ -860,7 +860,7 @@ static int nvidia_mcp_gpio_set(int gpio, int raise)
return -1; return -1;
} }
/* First, check the ISA Bridge */ /* First, check the ISA bridge */
dev = pci_dev_find_vendorclass(0x10DE, 0x0601); dev = pci_dev_find_vendorclass(0x10DE, 0x0601);
switch (dev->device_id) { switch (dev->device_id) {
case 0x0030: /* CK804 */ case 0x0030: /* CK804 */
@ -1092,7 +1092,7 @@ static int board_artecgroup_dbe6x(void)
/* /*
* Suited for: * Suited for:
* - Asus A8AE-LE (Codename AmberineM; used in Compaq Presario 061) * - ASUS A8AE-LE (Codename AmberineM; used in Compaq Presario 061)
* Datasheet(s) used: * Datasheet(s) used:
* - AMD document 43009 "AMD SB700/710/750 Register Reference Guide" rev. 1.00 * - AMD document 43009 "AMD SB700/710/750 Register Reference Guide" rev. 1.00
*/ */
@ -1101,7 +1101,7 @@ static int amd_sbxxx_gpio9_raise(void)
struct pci_dev *dev; struct pci_dev *dev;
uint32_t reg; uint32_t reg;
dev = pci_dev_find(0x1002, 0x4372); /* AMD SMBus Controller */ dev = pci_dev_find(0x1002, 0x4372); /* AMD SMBus controller */
if (!dev) { if (!dev) {
msg_perr("\nERROR: AMD SMBus Controller (0x4372) not found.\n"); msg_perr("\nERROR: AMD SMBus Controller (0x4372) not found.\n");
return -1; return -1;
@ -1128,7 +1128,8 @@ static int intel_piix4_gpo_set(unsigned int gpo, int raise)
struct pci_dev *dev; struct pci_dev *dev;
uint32_t tmp, base; uint32_t tmp, base;
static const uint32_t nonmuxed_gpos = 0x58000101; /* GPPO {0,8,27,28,30} are always available */ /* GPPO {0,8,27,28,30} are always available */
static const uint32_t nonmuxed_gpos = 0x58000101;
static const struct {unsigned int reg, mask, value; } piix4_gpo[] = { static const struct {unsigned int reg, mask, value; } piix4_gpo[] = {
{0}, {0},
@ -1164,7 +1165,6 @@ static int intel_piix4_gpo_set(unsigned int gpo, int raise)
{0} {0}
}; };
dev = pci_dev_find(0x8086, 0x7110); /* Intel PIIX4 ISA bridge */ dev = pci_dev_find(0x8086, 0x7110); /* Intel PIIX4 ISA bridge */
if (!dev) { if (!dev) {
msg_perr("\nERROR: Intel PIIX4 ISA bridge not found.\n"); msg_perr("\nERROR: Intel PIIX4 ISA bridge not found.\n");
@ -1178,8 +1178,10 @@ static int intel_piix4_gpo_set(unsigned int gpo, int raise)
} }
if ((((1 << gpo) & nonmuxed_gpos) == 0) && if ((((1 << gpo) & nonmuxed_gpos) == 0) &&
(pci_read_word(dev, piix4_gpo[gpo].reg) & piix4_gpo[gpo].mask) != piix4_gpo[gpo].value ) { (pci_read_word(dev, piix4_gpo[gpo].reg)
msg_perr("\nERROR: PIIX4 GPO%d not programmed for output.\n", gpo); & piix4_gpo[gpo].mask) != piix4_gpo[gpo].value) {
msg_perr("\nERROR: PIIX4 GPO%d not programmed for output.\n",
gpo);
return -1; return -1;
} }
@ -1315,7 +1317,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
/* libpci before version 2.2.4 does not store class info. */ /* libpci before version 2.2.4 does not store class info. */
device_class = pci_read_word(dev, PCI_CLASS_DEVICE); device_class = pci_read_word(dev, PCI_CLASS_DEVICE);
if ((dev->vendor_id == 0x8086) && if ((dev->vendor_id == 0x8086) &&
(device_class == 0x0601)) { /* ISA Bridge */ (device_class == 0x0601)) { /* ISA bridge */
/* Is this device in our list? */ /* Is this device in our list? */
for (i = 0; intel_ich_gpio_table[i].id; i++) for (i = 0; intel_ich_gpio_table[i].id; i++)
if (dev->device_id == intel_ich_gpio_table[i].id) if (dev->device_id == intel_ich_gpio_table[i].id)
@ -1327,7 +1329,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
} }
if (!dev) { if (!dev) {
msg_perr("\nERROR: No Known Intel LPC Bridge found.\n"); msg_perr("\nERROR: No known Intel LPC bridge found.\n");
return -1; return -1;
} }
@ -1347,12 +1349,12 @@ static int intel_ich_gpio_set(int gpio, int raise)
allowed = (intel_ich_gpio_table[i].bank2 >> (gpio - 64)) & 0x01; allowed = (intel_ich_gpio_table[i].bank2 >> (gpio - 64)) & 0x01;
if (!allowed) { if (!allowed) {
msg_perr("\nERROR: This Intel LPC Bridge does not allow" msg_perr("\nERROR: This Intel LPC bridge does not allow"
" setting GPIO%02d\n", gpio); " setting GPIO%02d\n", gpio);
return -1; return -1;
} }
msg_pdbg("\nIntel ICH LPC Bridge: %sing GPIO%02d.\n", msg_pdbg("\nIntel ICH LPC bridge: %sing GPIO%02d.\n",
raise ? "Rais" : "Dropp", gpio); raise ? "Rais" : "Dropp", gpio);
if (gpio < 32) { if (gpio < 32) {
@ -1371,7 +1373,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
if (dev->device_id > 0x2800) { if (dev->device_id > 0x2800) {
tmp = INL(base); tmp = INL(base);
if (!(tmp & (1 << gpio))) { if (!(tmp & (1 << gpio))) {
msg_perr("\nERROR: This Intel LPC Bridge" msg_perr("\nERROR: This Intel LPC bridge"
" does not allow setting GPIO%02d\n", " does not allow setting GPIO%02d\n",
gpio); gpio);
return -1; return -1;
@ -1403,7 +1405,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
if (dev->device_id > 0x2800) { if (dev->device_id > 0x2800) {
tmp = INL(base + 30); tmp = INL(base + 30);
if (!(tmp & (1 << gpio))) { if (!(tmp & (1 << gpio))) {
msg_perr("\nERROR: This Intel LPC Bridge" msg_perr("\nERROR: This Intel LPC bridge"
" does not allow setting GPIO%02d\n", " does not allow setting GPIO%02d\n",
gpio + 32); gpio + 32);
return -1; return -1;
@ -1432,7 +1434,7 @@ static int intel_ich_gpio_set(int gpio, int raise)
tmp = INL(base + 40); tmp = INL(base + 40);
if (!(tmp & (1 << gpio))) { if (!(tmp & (1 << gpio))) {
msg_perr("\nERROR: This Intel LPC Bridge does " msg_perr("\nERROR: This Intel LPC bridge does "
"not allow setting GPIO%02d\n", gpio + 64); "not allow setting GPIO%02d\n", gpio + 64);
return -1; return -1;
} }
@ -1607,10 +1609,10 @@ static int board_aopen_i975xa_ydg(void)
{ {
int ret; int ret;
/* vendor BIOS ends up in LDN6... maybe the board enable is wrong, /* Vendor BIOS ends up in LDN6... maybe the board enable is wrong,
* or perhaps it's not needed at all? * or perhaps it's not needed at all?
* the regs it tries to touch are 0xF0, 0xF1, 0xF2 which means if it * The regs it tries to touch are 0xF0, 0xF1, 0xF2 which means if it
* were in the right LDN, it would have to be GPIO1 or GPIO3 * were in the right LDN, it would have to be GPIO1 or GPIO3.
*/ */
/* /*
ret = winbond_gpio_set(0x2e, WINBOND_W83627EHF_ID, x, 0) ret = winbond_gpio_set(0x2e, WINBOND_W83627EHF_ID, x, 0)
@ -1659,10 +1661,9 @@ static int board_kontron_986lcd_m(void)
static int via_apollo_gpo_set(int gpio, int raise) static int via_apollo_gpo_set(int gpio, int raise)
{ {
struct pci_dev *dev; struct pci_dev *dev;
uint32_t base; uint32_t base, tmp;
uint32_t tmp;
/* VT82C686 Power management */ /* VT82C686 power management */
dev = pci_dev_find(0x1106, 0x3057); dev = pci_dev_find(0x1106, 0x3057);
if (!dev) { if (!dev) {
msg_perr("\nERROR: VT82C686 PM device not found.\n"); msg_perr("\nERROR: VT82C686 PM device not found.\n");
@ -1672,10 +1673,9 @@ static int via_apollo_gpo_set(int gpio, int raise)
msg_pdbg("\nVIA Apollo ACPI: %sing GPIO%02d.\n", msg_pdbg("\nVIA Apollo ACPI: %sing GPIO%02d.\n",
raise ? "Rais" : "Dropp", gpio); raise ? "Rais" : "Dropp", gpio);
/* select GPO function on multiplexed pins */ /* Select GPO function on multiplexed pins. */
tmp = pci_read_byte(dev, 0x54); tmp = pci_read_byte(dev, 0x54);
switch(gpio) switch (gpio) {
{
case 0: case 0:
tmp &= ~0x03; tmp &= ~0x03;
break; break;
@ -1906,7 +1906,7 @@ static int it8712f_gpio_set(unsigned int line, int raise)
return -1; return -1;
} }
/* set GPIO. */ /* Set GPIO. */
tmp = INB(base + port); tmp = INB(base + port);
if (raise) if (raise)
tmp |= 1 << line; tmp |= 1 << line;
@ -2091,8 +2091,8 @@ const struct board_pciid_enable board_pciid_enables[] = {
* Match boards on coreboot table gathered vendor and part name. * Match boards on coreboot table gathered vendor and part name.
* Require main PCI IDs to match too as extra safety. * Require main PCI IDs to match too as extra safety.
*/ */
static const struct board_pciid_enable *board_match_coreboot_name(const char *vendor, static const struct board_pciid_enable *board_match_coreboot_name(
const char *part) const char *vendor, const char *part)
{ {
const struct board_pciid_enable *board = board_pciid_enables; const struct board_pciid_enable *board = board_pciid_enables;
const struct board_pciid_enable *partmatch = NULL; const struct board_pciid_enable *partmatch = NULL;
@ -2144,7 +2144,8 @@ static const struct board_pciid_enable *board_match_coreboot_name(const char *ve
* Match boards on PCI IDs and subsystem IDs. * Match boards on PCI IDs and subsystem IDs.
* Second set of IDs can be main only or missing completely. * Second set of IDs can be main only or missing completely.
*/ */
const static struct board_pciid_enable *board_match_pci_card_ids(enum board_match_phase phase) const static struct board_pciid_enable *board_match_pci_card_ids(
enum board_match_phase phase)
{ {
const struct board_pciid_enable *board = board_pciid_enables; const struct board_pciid_enable *board = board_pciid_enables;

View File

@ -50,7 +50,8 @@ static int buspirate_serialport_setup(char *dev)
#define sp_flush_incoming(...) 0 #define sp_flush_incoming(...) 0
#endif #endif
static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int readcnt) static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt,
unsigned int readcnt)
{ {
int i, ret = 0; int i, ret = 0;
@ -108,7 +109,7 @@ static const struct buspirate_spispeeds spispeeds[] = {
{"2.6M", 0x5}, {"2.6M", 0x5},
{"4M", 0x6}, {"4M", 0x6},
{"8M", 0x7}, {"8M", 0x7},
{NULL, 0x0} {NULL, 0x0},
}; };
static int buspirate_spi_shutdown(void *data) static int buspirate_spi_shutdown(void *data)
@ -149,11 +150,9 @@ static int buspirate_spi_shutdown(void *data)
int buspirate_spi_init(void) int buspirate_spi_init(void)
{ {
unsigned char buf[512]; unsigned char buf[512];
int ret = 0; int ret = 0, i, spispeed = 0x7;
int i;
char *dev = NULL; char *dev = NULL;
char *speed = NULL; char *speed = NULL;
int spispeed = 0x7;
dev = extract_programmer_param("dev"); dev = extract_programmer_param("dev");
if (!dev || !strlen(dev)) { if (!dev || !strlen(dev)) {

View File

@ -77,7 +77,8 @@ static int enable_flash_sis_mapping(struct pci_dev *dev, const char *name)
rpci_write_byte(dev, 0x40, new); rpci_write_byte(dev, 0x40, new);
newer = pci_read_byte(dev, 0x40); newer = pci_read_byte(dev, 0x40);
if (newer != new) { if (newer != new) {
msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); msg_pinfo("tried to set register 0x%x to 0x%x on %s "
"failed (WARNING ONLY)\n", 0x40, new, name);
msg_pinfo("Stuck at 0x%x\n", newer); msg_pinfo("Stuck at 0x%x\n", newer);
return -1; return -1;
} }
@ -165,7 +166,8 @@ static int enable_flash_sis530(struct pci_dev *dev, const char *name)
rpci_write_byte(sbdev, 0x45, new); rpci_write_byte(sbdev, 0x45, new);
newer = pci_read_byte(sbdev, 0x45); newer = pci_read_byte(sbdev, 0x45);
if (newer != new) { if (newer != new) {
msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); msg_pinfo("tried to set register 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x45, new, name);
msg_pinfo("Stuck at 0x%x\n", newer); msg_pinfo("Stuck at 0x%x\n", newer);
ret = -1; ret = -1;
} }
@ -191,7 +193,8 @@ static int enable_flash_sis540(struct pci_dev *dev, const char *name)
rpci_write_byte(sbdev, 0x45, new); rpci_write_byte(sbdev, 0x45, new);
newer = pci_read_byte(sbdev, 0x45); newer = pci_read_byte(sbdev, 0x45);
if (newer != new) { if (newer != new) {
msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); msg_pinfo("tried to set register 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x45, new, name);
msg_pinfo("Stuck at 0x%x\n", newer); msg_pinfo("Stuck at 0x%x\n", newer);
ret = -1; ret = -1;
} }
@ -238,7 +241,8 @@ static int enable_flash_piix4(struct pci_dev *dev, const char *name)
rpci_write_word(dev, xbcs, new); rpci_write_word(dev, xbcs, new);
if (pci_read_word(dev, xbcs) != new) { if (pci_read_word(dev, xbcs) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", xbcs, new, name);
return -1; return -1;
} }
@ -271,10 +275,10 @@ static int enable_flash_ich(struct pci_dev *dev, const char *name,
* "Bit 5: SMM BIOS Write Protect Disable (SMM_BWP) * "Bit 5: SMM BIOS Write Protect Disable (SMM_BWP)
* 1 = BIOS region SMM protection is enabled. * 1 = BIOS region SMM protection is enabled.
* The BIOS Region is not writable unless all processors are in SMM." * The BIOS Region is not writable unless all processors are in SMM."
* In earlier chipsets this bit is reserved. */ * In earlier chipsets this bit is reserved.
if (old & (1 << 5)) { */
if (old & (1 << 5))
msg_pinfo("WARNING: BIOS region SMM protection is enabled!\n"); msg_pinfo("WARNING: BIOS region SMM protection is enabled!\n");
}
new = old | 1; new = old | 1;
if (new == old) if (new == old)
@ -283,7 +287,8 @@ static int enable_flash_ich(struct pci_dev *dev, const char *name,
rpci_write_byte(dev, bios_cntl, new); rpci_write_byte(dev, bios_cntl, new);
if (pci_read_byte(dev, bios_cntl) != new) { if (pci_read_byte(dev, bios_cntl) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", bios_cntl, new, name);
return -1; return -1;
} }
@ -304,17 +309,13 @@ static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
static int enable_flash_ich_dc(struct pci_dev *dev, const char *name) static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
{ {
uint32_t fwh_conf; uint32_t fwh_conf;
int i;
char *idsel = NULL; char *idsel = NULL;
int tmp; int i, tmp, max_decode_fwh_idsel = 0, max_decode_fwh_decode = 0;
int max_decode_fwh_idsel = 0;
int max_decode_fwh_decode = 0;
int contiguous = 1; int contiguous = 1;
idsel = extract_programmer_param("fwh_idsel"); idsel = extract_programmer_param("fwh_idsel");
if (idsel && strlen(idsel)) { if (idsel && strlen(idsel)) {
uint64_t fwh_idsel_old; uint64_t fwh_idsel_old, fwh_idsel;
uint64_t fwh_idsel;
errno = 0; errno = 0;
/* Base 16, nothing else makes sense. */ /* Base 16, nothing else makes sense. */
fwh_idsel = (uint64_t)strtoull(idsel, NULL, 16); fwh_idsel = (uint64_t)strtoull(idsel, NULL, 16);
@ -438,7 +439,6 @@ static int enable_flash_poulsbo(struct pci_dev *dev, const char *name)
return 0; return 0;
} }
#define ICH_STRAP_RSVD 0x00 #define ICH_STRAP_RSVD 0x00
#define ICH_STRAP_SPI 0x01 #define ICH_STRAP_SPI 0x01
#define ICH_STRAP_PCI 0x02 #define ICH_STRAP_PCI 0x02
@ -457,7 +457,11 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
uint8_t bbs, buc; uint8_t bbs, buc;
uint32_t tmp, gcs; uint32_t tmp, gcs;
void *rcrb; void *rcrb;
//TODO: These names are incorrect for EP80579. For that, the solution would look like the commented line
/*
* TODO: These names are incorrect for EP80579. For that, the solution
* would look like the commented line below.
*/
// static const char *straps_names[] = {"SPI", "reserved", "reserved", "LPC" }; // static const char *straps_names[] = {"SPI", "reserved", "reserved", "LPC" };
static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" }; static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" };
@ -492,13 +496,13 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
if (bbs == ICH_STRAP_LPC) { if (bbs == ICH_STRAP_LPC) {
/* No further SPI initialization required */ /* No further SPI initialization required */
return ret; return ret;
} } else {
else
/* Disable LPC/FWH if strapped to PCI or SPI */ /* Disable LPC/FWH if strapped to PCI or SPI */
buses_supported = 0; buses_supported = 0;
} }
}
/* this adds BUS_SPI */ /* This adds BUS_SPI */
if (ich_init_spi(dev, tmp, rcrb, ich_generation) != 0) { if (ich_init_spi(dev, tmp, rcrb, ich_generation) != 0) {
if (!ret) if (!ret)
ret = ERROR_NONFATAL; ret = ERROR_NONFATAL;
@ -532,8 +536,7 @@ static int via_no_byte_merge(struct pci_dev *dev, const char *name)
uint8_t val; uint8_t val;
val = pci_read_byte(dev, 0x71); val = pci_read_byte(dev, 0x71);
if (val & 0x40) if (val & 0x40) {
{
msg_pdbg("Disabling byte merging\n"); msg_pdbg("Disabling byte merging\n");
val &= ~0x40; val &= ~0x40;
rpci_write_byte(dev, 0x71, val); rpci_write_byte(dev, 0x71, val);
@ -545,7 +548,7 @@ static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
{ {
uint8_t val; uint8_t val;
/* enable ROM decode range (1MB) FFC00000 - FFFFFFFF */ /* Enable ROM decode range (1MB) FFC00000 - FFFFFFFF. */
rpci_write_byte(dev, 0x41, 0x7f); rpci_write_byte(dev, 0x41, 0x7f);
/* ROM write enable */ /* ROM write enable */
@ -671,7 +674,8 @@ static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
new = pci_read_byte(dev, 0x52); new = pci_read_byte(dev, 0x52);
if (new != 0xee) { if (new != 0xee) {
msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name); msg_pinfo("tried to set register 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x52, new, name);
return -1; return -1;
} }
@ -689,7 +693,8 @@ static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
if (new != old) { if (new != old) {
rpci_write_byte(dev, 0x43, new); rpci_write_byte(dev, 0x43, new);
if (pci_read_byte(dev, 0x43) != new) { if (pci_read_byte(dev, 0x43) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x43, new, name);
} }
} }
@ -701,7 +706,8 @@ static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
rpci_write_byte(dev, 0x40, new); rpci_write_byte(dev, 0x40, new);
if (pci_read_byte(dev, 0x40) != new) { if (pci_read_byte(dev, 0x40) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x40, new, name);
return -1; return -1;
} }
@ -800,7 +806,8 @@ static int enable_flash_ck804(struct pci_dev *dev, const char *name)
if (new != old) { if (new != old) {
rpci_write_byte(dev, 0x88, new); rpci_write_byte(dev, 0x88, new);
if (pci_read_byte(dev, 0x88) != new) { if (pci_read_byte(dev, 0x88) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x88, new, name);
} }
} }
@ -811,7 +818,8 @@ static int enable_flash_ck804(struct pci_dev *dev, const char *name)
rpci_write_byte(dev, 0x6d, new); rpci_write_byte(dev, 0x6d, new);
if (pci_read_byte(dev, 0x6d) != new) { if (pci_read_byte(dev, 0x6d) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x6d, new, name);
return -1; return -1;
} }
@ -894,7 +902,8 @@ static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
rpci_write_byte(dev, 0x6d, new); rpci_write_byte(dev, 0x6d, new);
if (pci_read_byte(dev, 0x6d) != new) { if (pci_read_byte(dev, 0x6d) != new) {
msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); msg_pinfo("tried to set 0x%x to 0x%x on %s failed "
"(WARNING ONLY)\n", 0x6d, new, name);
return -1; return -1;
} }
@ -908,8 +917,7 @@ static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
*/ */
static int enable_flash_mcp6x_7x(struct pci_dev *dev, const char *name) static int enable_flash_mcp6x_7x(struct pci_dev *dev, const char *name)
{ {
int ret = 0; int ret = 0, want_spi = 0;
int want_spi = 0;
uint8_t val; uint8_t val;
msg_pinfo("This chipset is not really supported yet. Guesswork...\n"); msg_pinfo("This chipset is not really supported yet. Guesswork...\n");
@ -952,9 +960,9 @@ static int enable_flash_mcp6x_7x(struct pci_dev *dev, const char *name)
rpci_write_byte(dev, 0x8a, val); rpci_write_byte(dev, 0x8a, val);
#endif #endif
if (mcp6x_spi_init(want_spi)) { if (mcp6x_spi_init(want_spi))
ret = 1; ret = 1;
}
out_msg: out_msg:
msg_pinfo("Please send the output of \"flashrom -V\" to " msg_pinfo("Please send the output of \"flashrom -V\" to "
"flashrom@flashrom.org with\n" "flashrom@flashrom.org with\n"
@ -1020,7 +1028,8 @@ static int get_flashbase_sc520(struct pci_dev *dev, const char *name)
flashbase = parx << 12; flashbase = parx << 12;
} }
} else { } else {
msg_pinfo("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n"); msg_pinfo("AMD Elan SC520 detected, but no BOOTCS. "
"Assuming flash at 4G\n");
} }
/* 4. Clean up */ /* 4. Clean up */

View File

@ -103,21 +103,14 @@ int cli_classic(int argc, char *argv[])
const struct flashchip *flash; const struct flashchip *flash;
struct flashchip flashes[3]; struct flashchip flashes[3];
struct flashchip *fill_flash; struct flashchip *fill_flash;
int startchip = 0;
int chipcount = 0;
const char *name; const char *name;
int namelen; int startchip = 0, chipcount = 0, namelen, opt, option_index = 0;
int opt;
int option_index = 0;
int force = 0;
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
int dont_verify_it = 0, list_supported = 0; int dont_verify_it = 0, list_supported = 0, force = 0;
#if CONFIG_PRINT_WIKI == 1 #if CONFIG_PRINT_WIKI == 1
int list_supported_wiki = 0; int list_supported_wiki = 0;
#endif #endif
int operation_specified = 0; int operation_specified = 0, i, ret = 0;
int i;
int ret = 0;
static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh"; static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
static const struct option long_options[] = { static const struct option long_options[] = {
@ -137,11 +130,10 @@ int cli_classic(int argc, char *argv[])
{"programmer", 1, NULL, 'p'}, {"programmer", 1, NULL, 'p'},
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"version", 0, NULL, 'R'}, {"version", 0, NULL, 'R'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0},
}; };
char *filename = NULL; char *filename = NULL;
char *tempstr = NULL; char *tempstr = NULL;
char *pparam = NULL; char *pparam = NULL;
@ -384,23 +376,28 @@ int cli_classic(int argc, char *argv[])
flashes[0].name); flashes[0].name);
for (i = 1; i < chipcount; i++) for (i = 1; i < chipcount; i++)
printf(", \"%s\"", flashes[i].name); printf(", \"%s\"", flashes[i].name);
printf("\nPlease specify which chip to use with the -c <chipname> option.\n"); printf("\nPlease specify which chip to use with the "
"-c <chipname> option.\n");
ret = 1; ret = 1;
goto out_shutdown; goto out_shutdown;
} else if (!chipcount) { } else if (!chipcount) {
printf("No EEPROM/flash device found.\n"); printf("No EEPROM/flash device found.\n");
if (!force || !chip_to_probe) { if (!force || !chip_to_probe) {
printf("Note: flashrom can never write if the flash chip isn't found automatically.\n"); printf("Note: flashrom can never write if the flash "
"chip isn't found automatically.\n");
} }
if (force && read_it && chip_to_probe) { if (force && read_it && chip_to_probe) {
printf("Force read (-f -r -c) requested, pretending the chip is there:\n"); printf("Force read (-f -r -c) requested, pretending "
"the chip is there:\n");
startchip = probe_flash(0, &flashes[0], 1); startchip = probe_flash(0, &flashes[0], 1);
if (startchip == -1) { if (startchip == -1) {
printf("Probing for flash chip '%s' failed.\n", chip_to_probe); printf("Probing for flash chip '%s' failed.\n",
chip_to_probe);
ret = 1; ret = 1;
goto out_shutdown; goto out_shutdown;
} }
printf("Please note that forced reads most likely contain garbage.\n"); printf("Please note that forced reads most likely "
"contain garbage.\n");
return read_flash_to_file(&flashes[0], filename); return read_flash_to_file(&flashes[0], filename);
} }
ret = 1; ret = 1;

View File

@ -92,9 +92,11 @@ static int dediprog_set_leds(int leds)
target_leds = leds; target_leds = leds;
} }
ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, target_leds, NULL, 0x0, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, target_leds,
NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) { if (ret != 0x0) {
msg_perr("Command Set LED 0x%x failed (%s)!\n", leds, usb_strerror()); msg_perr("Command Set LED 0x%x failed (%s)!\n",
leds, usb_strerror());
return 1; return 1;
} }
@ -129,9 +131,11 @@ static int dediprog_set_spi_voltage(int millivolt)
msg_pdbg("Setting SPI voltage to %u.%03u V\n", millivolt / 1000, msg_pdbg("Setting SPI voltage to %u.%03u V\n", millivolt / 1000,
millivolt % 1000); millivolt % 1000);
ret = usb_control_msg(dediprog_handle, 0x42, 0x9, voltage_selector, 0xff, NULL, 0x0, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0x42, 0x9, voltage_selector,
0xff, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) { if (ret != 0x0) {
msg_perr("Command Set SPI Voltage 0x%x failed!\n", voltage_selector); msg_perr("Command Set SPI Voltage 0x%x failed!\n",
voltage_selector);
return 1; return 1;
} }
return 0; return 0;
@ -186,7 +190,8 @@ static int dediprog_set_spi_speed(uint16_t speed)
} }
msg_pdbg("Setting SPI speed to %u kHz\n", khz); msg_pdbg("Setting SPI speed to %u kHz\n", khz);
ret = usb_control_msg(dediprog_handle, 0x42, 0x61, speed, 0xff, NULL, 0x0, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0x42, 0x61, speed, 0xff, NULL,
0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) { if (ret != 0x0) {
msg_perr("Command Set SPI Speed 0x%x failed!\n", speed); msg_perr("Command Set SPI Speed 0x%x failed!\n", speed);
return 1; return 1;
@ -248,7 +253,8 @@ static int dediprog_spi_bulk_read(struct flashchip *flash, uint8_t *buf,
return 0; return 0;
} }
static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start,
int len)
{ {
int ret; int ret;
/* chunksize must be 512, other sizes will NOT work at all. */ /* chunksize must be 512, other sizes will NOT work at all. */
@ -293,7 +299,8 @@ static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, i
return 0; return 0;
} }
static int dediprog_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) static int dediprog_spi_write_256(struct flashchip *flash, uint8_t *buf,
int start, int len)
{ {
int ret; int ret;
@ -327,7 +334,9 @@ static int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt
return 1; return 1;
} }
ret = usb_control_msg(dediprog_handle, 0x42, 0x1, 0xff, readcnt ? 0x1 : 0x0, (char *)writearr, writecnt, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0x42, 0x1, 0xff,
readcnt ? 0x1 : 0x0, (char *)writearr, writecnt,
DEFAULT_TIMEOUT);
if (ret != writecnt) { if (ret != writecnt) {
msg_perr("Send SPI failed, expected %i, got %i %s!\n", msg_perr("Send SPI failed, expected %i, got %i %s!\n",
writecnt, ret, usb_strerror()); writecnt, ret, usb_strerror());
@ -336,7 +345,8 @@ static int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt
if (!readcnt) if (!readcnt)
return 0; return 0;
memset(readarr, 0, readcnt); memset(readarr, 0, readcnt);
ret = usb_control_msg(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000, (char *)readarr, readcnt, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000,
(char *)readarr, readcnt, DEFAULT_TIMEOUT);
if (ret != readcnt) { if (ret != readcnt) {
msg_perr("Receive SPI failed, expected %i, got %i %s!\n", msg_perr("Receive SPI failed, expected %i, got %i %s!\n",
readcnt, ret, usb_strerror()); readcnt, ret, usb_strerror());
@ -353,7 +363,8 @@ static int dediprog_check_devicestring(void)
/* Command Prepare Receive Device String. */ /* Command Prepare Receive Device String. */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef03, buf, 0x1, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef03, buf,
0x1, DEFAULT_TIMEOUT);
/* The char casting is needed to stop gcc complaining about an always true comparison. */ /* The char casting is needed to stop gcc complaining about an always true comparison. */
if ((ret != 0x1) || (buf[0] != (char)0xff)) { if ((ret != 0x1) || (buf[0] != (char)0xff)) {
msg_perr("Unexpected response to Command Prepare Receive Device" msg_perr("Unexpected response to Command Prepare Receive Device"
@ -362,7 +373,8 @@ static int dediprog_check_devicestring(void)
} }
/* Command Receive Device String. */ /* Command Receive Device String. */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf, 0x10, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf,
0x10, DEFAULT_TIMEOUT);
if (ret != 0x10) { if (ret != 0x10) {
msg_perr("Incomplete/failed Command Receive Device String!\n"); msg_perr("Incomplete/failed Command Receive Device String!\n");
return 1; return 1;
@ -397,7 +409,8 @@ static int dediprog_command_a(void)
char buf[0x1]; char buf[0x1];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf, 0x1, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf,
0x1, DEFAULT_TIMEOUT);
if (ret < 0) { if (ret < 0) {
msg_perr("Command A failed (%s)!\n", usb_strerror()); msg_perr("Command A failed (%s)!\n", usb_strerror());
return 1; return 1;
@ -420,7 +433,8 @@ static int dediprog_command_b(void)
char buf[0x3]; char buf[0x3];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf, 0x3, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf,
0x3, DEFAULT_TIMEOUT);
if (ret < 0) { if (ret < 0) {
msg_perr("Command B failed (%s)!\n", usb_strerror()); msg_perr("Command B failed (%s)!\n", usb_strerror());
return 1; return 1;
@ -444,7 +458,8 @@ static int dediprog_command_c(void)
{ {
int ret; int ret;
ret = usb_control_msg(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL, 0x0, DEFAULT_TIMEOUT); ret = usb_control_msg(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL,
0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) { if (ret != 0x0) {
msg_perr("Command C failed (%s)!\n", usb_strerror()); msg_perr("Command C failed (%s)!\n", usb_strerror());
return 1; return 1;
@ -464,7 +479,8 @@ static int dediprog_command_f(int timeout)
char buf[0x1]; char buf[0x1];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf, 0x1, timeout); ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf,
0x1, timeout);
/* This check is most probably wrong. Command F always causes a timeout /* This check is most probably wrong. Command F always causes a timeout
* in the logs, so we should check for timeout instead of checking for * in the logs, so we should check for timeout instead of checking for
* success. * success.
@ -480,9 +496,7 @@ static int dediprog_command_f(int timeout)
static int parse_voltage(char *voltage) static int parse_voltage(char *voltage)
{ {
char *tmp = NULL; char *tmp = NULL;
int i; int i, millivolt, fraction = 0;
int millivolt;
int fraction = 0;
if (!voltage || !strlen(voltage)) { if (!voltage || !strlen(voltage)) {
msg_perr("Empty voltage= specified.\n"); msg_perr("Empty voltage= specified.\n");
@ -560,8 +574,7 @@ int dediprog_init(void)
{ {
struct usb_device *dev; struct usb_device *dev;
char *voltage; char *voltage;
int millivolt = 3500; int millivolt = 3500, ret;
int ret;
msg_pspew("%s\n", __func__); msg_pspew("%s\n", __func__);
@ -569,9 +582,8 @@ int dediprog_init(void)
if (voltage) { if (voltage) {
millivolt = parse_voltage(voltage); millivolt = parse_voltage(voltage);
free(voltage); free(voltage);
if (millivolt < 0) { if (millivolt < 0)
return 1; return 1;
}
msg_pinfo("Setting voltage to %i mV\n", millivolt); msg_pinfo("Setting voltage to %i mV\n", millivolt);
} }
@ -585,8 +597,7 @@ int dediprog_init(void)
return 1; return 1;
} }
msg_pdbg("Found USB device (%04x:%04x).\n", msg_pdbg("Found USB device (%04x:%04x).\n",
dev->descriptor.idVendor, dev->descriptor.idVendor, dev->descriptor.idProduct);
dev->descriptor.idProduct);
dediprog_handle = usb_open(dev); dediprog_handle = usb_open(dev);
ret = usb_set_configuration(dediprog_handle, 1); ret = usb_set_configuration(dediprog_handle, 1);
if (ret < 0) { if (ret < 0) {
@ -666,7 +677,8 @@ static int dediprog_do_stuff(void)
/* JEDEC RDID */ /* JEDEC RDID */
msg_pdbg("Sending RDID\n"); msg_pdbg("Sending RDID\n");
buf[0] = JEDEC_RDID; buf[0] = JEDEC_RDID;
if (dediprog_spi_send_command(JEDEC_RDID_OUTSIZE, JEDEC_RDID_INSIZE, (unsigned char *)buf, (unsigned char *)buf)) if (dediprog_spi_send_command(JEDEC_RDID_OUTSIZE, JEDEC_RDID_INSIZE,
(unsigned char *)buf, (unsigned char *)buf))
return 1; return 1;
msg_pdbg("Receiving response: "); msg_pdbg("Receiving response: ");
print_hex(buf, JEDEC_RDID_INSIZE); print_hex(buf, JEDEC_RDID_INSIZE);

15
dmi.c
View File

@ -107,10 +107,11 @@ static char *get_dmi_string(const char *string_name)
} }
/* Kill lines starting with '#', as recent dmidecode versions /* Kill lines starting with '#', as recent dmidecode versions
have the quirk to emit a "# SMBIOS implementations newer..." * have the quirk to emit a "# SMBIOS implementations newer..."
message even on "-s" if the SMBIOS declares a * message even on "-s" if the SMBIOS declares a
newer-than-supported version number, while it *should* only print * newer-than-supported version number, while it *should* only print
the requested string. */ * the requested string.
*/
do { do {
if (!fgets(answerbuf, DMI_MAX_ANSWER_LEN, dmidecode_pipe)) { if (!fgets(answerbuf, DMI_MAX_ANSWER_LEN, dmidecode_pipe)) {
if (ferror(dmidecode_pipe)) { if (ferror(dmidecode_pipe)) {
@ -134,8 +135,7 @@ static char *get_dmi_string(const char *string_name)
} }
/* Chomp trailing newline. */ /* Chomp trailing newline. */
if (answerbuf[0] != 0 && if (answerbuf[0] != 0 && answerbuf[strlen(answerbuf) - 1] == '\n')
answerbuf[strlen(answerbuf) - 1] == '\n')
answerbuf[strlen(answerbuf) - 1] = 0; answerbuf[strlen(answerbuf) - 1] = 0;
msg_pdbg("DMI string %s: \"%s\"\n", string_name, answerbuf); msg_pdbg("DMI string %s: \"%s\"\n", string_name, answerbuf);
@ -196,8 +196,7 @@ void dmi_init(void)
*/ */
static int dmi_compare(const char *value, const char *pattern) static int dmi_compare(const char *value, const char *pattern)
{ {
int anchored = 0; int anchored = 0, patternlen;
int patternlen;
msg_pspew("matching %s against %s\n", value, pattern); msg_pspew("matching %s against %s\n", value, pattern);
/* The empty string is part of all strings! */ /* The empty string is part of all strings! */

View File

@ -62,7 +62,8 @@ static int spi_write_256_chunksize = 256;
static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr); const unsigned char *writearr, unsigned char *readarr);
static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf,
int start, int len);
static const struct spi_programmer spi_programmer_dummyflasher = { static const struct spi_programmer spi_programmer_dummyflasher = {
.type = SPI_CONTROLLER_DUMMY, .type = SPI_CONTROLLER_DUMMY,
@ -520,14 +521,14 @@ static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
} }
#endif #endif
msg_pspew(" reading %u bytes:", readcnt); msg_pspew(" reading %u bytes:", readcnt);
for (i = 0; i < readcnt; i++) { for (i = 0; i < readcnt; i++)
msg_pspew(" 0x%02x", readarr[i]); msg_pspew(" 0x%02x", readarr[i]);
}
msg_pspew("\n"); msg_pspew("\n");
return 0; return 0;
} }
static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf,
int start, int len)
{ {
return spi_write_chunked(flash, buf, start, len, return spi_write_chunked(flash, buf, start, len,
spi_write_256_chunksize); spi_write_256_chunksize);

View File

@ -503,7 +503,7 @@ int programmer_init(char *param)
.parallel = 0xffffffff, .parallel = 0xffffffff,
.lpc = 0xffffffff, .lpc = 0xffffffff,
.fwh = 0xffffffff, .fwh = 0xffffffff,
.spi = 0xffffffff .spi = 0xffffffff,
}; };
buses_supported = BUS_NONE; buses_supported = BUS_NONE;
/* Default to top aligned flash at 4 GB. */ /* Default to top aligned flash at 4 GB. */
@ -600,7 +600,8 @@ void map_flash_registers(struct flashchip *flash)
size_t size = flash->total_size * 1024; size_t size = flash->total_size * 1024;
/* Flash registers live 4 MByte below the flash. */ /* Flash registers live 4 MByte below the flash. */
/* FIXME: This is incorrect for nonstandard flashbase. */ /* FIXME: This is incorrect for nonstandard flashbase. */
flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size); flash->virtual_registers = (chipaddr)programmer_map_flash_region(
"flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
} }
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len) int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len)
@ -743,17 +744,17 @@ int check_erased_range(struct flashchip *flash, int start, int len)
/* /*
* @cmpbuf buffer to compare against, cmpbuf[0] is expected to match the * @cmpbuf buffer to compare against, cmpbuf[0] is expected to match the
flash content at location start * flash content at location start
* @start offset to the base address of the flash chip * @start offset to the base address of the flash chip
* @len length of the verified area * @len length of the verified area
* @message string to print in the "FAILED" message * @message string to print in the "FAILED" message
* @return 0 for success, -1 for failure * @return 0 for success, -1 for failure
*/ */
int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, const char *message) int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len,
const char *message)
{ {
int i, ret = 0; int i, ret = 0, failcount = 0;
uint8_t *readbuf = malloc(len); uint8_t *readbuf = malloc(len);
int failcount = 0;
if (!len) if (!len)
goto out_free; goto out_free;
@ -831,8 +832,7 @@ out_free:
*/ */
int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran) int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran)
{ {
int result = 0; int result = 0, i, j, limit;
int i, j, limit;
switch (gran) { switch (gran) {
case write_gran_1bit: case write_gran_1bit:
@ -898,8 +898,7 @@ int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gra
static int get_next_write(uint8_t *have, uint8_t *want, int len, static int get_next_write(uint8_t *have, uint8_t *want, int len,
int *first_start, enum write_granularity gran) int *first_start, enum write_granularity gran)
{ {
int need_write = 0, rel_start = 0, first_len = 0; int need_write = 0, rel_start = 0, first_len = 0, i, limit, stride;
int i, limit, stride;
switch (gran) { switch (gran) {
case write_gran_1bit: case write_gran_1bit:
@ -1080,8 +1079,8 @@ int generate_testpattern(uint8_t *buf, uint32_t size, int variant)
int check_max_decode(enum chipbustype buses, uint32_t size) int check_max_decode(enum chipbustype buses, uint32_t size)
{ {
int limitexceeded = 0; int limitexceeded = 0;
if ((buses & BUS_PARALLEL) &&
(max_rom_decode.parallel < size)) { if ((buses & BUS_PARALLEL) && (max_rom_decode.parallel < size)) {
limitexceeded++; limitexceeded++;
msg_pdbg("Chip size %u kB is bigger than supported " msg_pdbg("Chip size %u kB is bigger than supported "
"size %u kB of chipset/board/programmer " "size %u kB of chipset/board/programmer "
@ -1232,7 +1231,8 @@ int verify_flash(struct flashchip *flash, uint8_t *buf)
return ret; return ret;
} }
int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename) int read_buf_from_file(unsigned char *buf, unsigned long size,
const char *filename)
{ {
unsigned long numbytes; unsigned long numbytes;
FILE *image; FILE *image;
@ -1265,7 +1265,8 @@ int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filen
return 0; return 0;
} }
int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename) int write_buf_to_file(unsigned char *buf, unsigned long size,
const char *filename)
{ {
unsigned long numbytes; unsigned long numbytes;
FILE *image; FILE *image;
@ -1325,8 +1326,7 @@ out_free:
*/ */
static int selfcheck_eraseblocks(const struct flashchip *flash) static int selfcheck_eraseblocks(const struct flashchip *flash)
{ {
int i, j, k; int i, j, k, ret = 0;
int ret = 0;
for (k = 0; k < NUM_ERASEFUNCTIONS; k++) { for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
unsigned int done = 0; unsigned int done = 0;
@ -1396,11 +1396,7 @@ static int erase_and_write_block_helper(struct flashchip *flash,
unsigned int addr, unsigned int addr,
unsigned int len)) unsigned int len))
{ {
int starthere = 0; int starthere = 0, lenhere = 0, ret = 0, skip = 1, writecount = 0;
int lenhere = 0;
int ret = 0;
int skip = 1;
int writecount = 0;
enum write_granularity gran = write_gran_256bytes; /* FIXME */ enum write_granularity gran = write_gran_256bytes; /* FIXME */
/* curcontents and newcontents are opaque to walk_eraseregions, and /* curcontents and newcontents are opaque to walk_eraseregions, and
@ -1455,9 +1451,9 @@ static int walk_eraseregions(struct flashchip *flash, int erasefunction,
void *param1, void *param2) void *param1, void *param2)
{ {
int i, j; int i, j;
unsigned int start = 0; unsigned int start = 0, len;
unsigned int len;
struct block_eraser eraser = flash->block_erasers[erasefunction]; struct block_eraser eraser = flash->block_erasers[erasefunction];
for (i = 0; i < NUM_ERASEREGIONS; i++) { for (i = 0; i < NUM_ERASEREGIONS; i++) {
/* count==0 for all automatically initialized array /* count==0 for all automatically initialized array
* members so the loop below won't be executed for them. * members so the loop below won't be executed for them.
@ -1504,7 +1500,8 @@ static int check_block_eraser(const struct flashchip *flash, int k, int log)
return 0; return 0;
} }
int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t *newcontents) int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents,
uint8_t *newcontents)
{ {
int k, ret = 1; int k, ret = 1;
uint8_t *curcontents; uint8_t *curcontents;
@ -1606,11 +1603,8 @@ void list_programmers(const char *delim)
void list_programmers_linebreak(int startcol, int cols, int paren) void list_programmers_linebreak(int startcol, int cols, int paren)
{ {
const char *pname; const char *pname;
int pnamelen; int pnamelen, remaining = 0, firstline = 1, i;
int remaining = 0;
int firstline = 1;
enum programmer p; enum programmer p;
int i;
for (p = 0; p < PROGRAMMER_INVALID; p++) { for (p = 0; p < PROGRAMMER_INVALID; p++) {
pname = programmer_table[p].name; pname = programmer_table[p].name;
@ -1743,7 +1737,7 @@ int selfcheck(void)
msg_gerr("Known laptops table does not exist!\n"); msg_gerr("Known laptops table does not exist!\n");
ret = 1; ret = 1;
} }
#endif // CONFIG_INTERNAL == 1 #endif
return ret; return ret;
} }

View File

@ -246,21 +246,17 @@ int ft2232_spi_init(void)
ftdic->error_str); ftdic->error_str);
} }
if (ftdi_usb_reset(ftdic) < 0) { if (ftdi_usb_reset(ftdic) < 0)
msg_perr("Unable to reset FTDI device\n"); msg_perr("Unable to reset FTDI device\n");
}
if (ftdi_set_latency_timer(ftdic, 2) < 0) { if (ftdi_set_latency_timer(ftdic, 2) < 0)
msg_perr("Unable to set latency timer\n"); msg_perr("Unable to set latency timer\n");
}
if (ftdi_write_data_set_chunksize(ftdic, 256)) { if (ftdi_write_data_set_chunksize(ftdic, 256))
msg_perr("Unable to set chunk size\n"); msg_perr("Unable to set chunk size\n");
}
if (ftdi_set_bitmode(ftdic, 0x00, BITMODE_BITBANG_SPI) < 0) { if (ftdi_set_bitmode(ftdic, 0x00, BITMODE_BITBANG_SPI) < 0)
msg_perr("Unable to set bitmode to SPI\n"); msg_perr("Unable to set bitmode to SPI\n");
}
if (clock_5x) { if (clock_5x) {
msg_pdbg("Disable divide-by-5 front stage\n"); msg_pdbg("Disable divide-by-5 front stage\n");
@ -285,8 +281,7 @@ int ft2232_spi_init(void)
} }
msg_pdbg("MPSSE clock: %f MHz divisor: %d " msg_pdbg("MPSSE clock: %f MHz divisor: %d "
"SPI clock: %f MHz\n", "SPI clock: %f MHz\n", mpsse_clk, DIVIDE_BY,
mpsse_clk, DIVIDE_BY,
(double)(mpsse_clk / (((DIVIDE_BY - 1) + 1) * 2))); (double)(mpsse_clk / (((DIVIDE_BY - 1) + 1) * 2)));
/* Disconnect TDI/DO to TDO/DI for loopback. */ /* Disconnect TDI/DO to TDO/DI for loopback. */
@ -328,8 +323,7 @@ static int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt,
struct ftdi_context *ftdic = &ftdic_context; struct ftdi_context *ftdic = &ftdic_context;
static unsigned char *buf = NULL; static unsigned char *buf = NULL;
/* failed is special. We use bitwise ops, but it is essentially bool. */ /* failed is special. We use bitwise ops, but it is essentially bool. */
int i = 0, ret = 0, failed = 0; int i = 0, ret = 0, failed = 0, bufsize;
int bufsize;
static int oldbufsize = 0; static int oldbufsize = 0;
if (writecnt > 65536 || readcnt > 65536) if (writecnt > 65536 || readcnt > 65536)
@ -379,8 +373,7 @@ static int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt,
failed = ret; failed = ret;
/* We can't abort here, we still have to deassert CS#. */ /* We can't abort here, we still have to deassert CS#. */
if (ret) if (ret)
msg_perr("send_buf failed before read: %i\n", msg_perr("send_buf failed before read: %i\n", ret);
ret);
i = 0; i = 0;
if (ret == 0) { if (ret == 0) {
/* /*

View File

@ -85,7 +85,7 @@ int gfxnvidia_init(void)
nvidia_bar = physmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE); nvidia_bar = physmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE);
/* must be done before rpci calls */ /* Must be done before rpci calls. */
if (register_shutdown(gfxnvidia_shutdown, NULL)) if (register_shutdown(gfxnvidia_shutdown, NULL))
return 1; return 1;

View File

@ -362,7 +362,7 @@ static uint8_t lookup_spi_type(uint8_t opcode)
{ {
int a; int a;
for (a = 0; a < sizeof(POSSIBLE_OPCODES)/sizeof(POSSIBLE_OPCODES[0]); a++) { for (a = 0; a < ARRAY_SIZE(POSSIBLE_OPCODES); a++) {
if (POSSIBLE_OPCODES[a].opcode == opcode) if (POSSIBLE_OPCODES[a].opcode == opcode)
return POSSIBLE_OPCODES[a].spi_type; return POSSIBLE_OPCODES[a].spi_type;
} }

View File

@ -90,14 +90,10 @@ static int it85xx_scratch_rom_reenter = 0;
* Returns: 0 -- the expected value has shown. * Returns: 0 -- the expected value has shown.
* 1 -- timeout reached. * 1 -- timeout reached.
*/ */
static int wait_for( static int wait_for(const unsigned int mask, const unsigned int expected_value,
const unsigned int mask, const int timeout /* in usec */, const char *error_message,
const unsigned int expected_value, const char *function_name, const int lineno)
const int timeout, /* in usec */ {
const char* error_message,
const char* function_name,
const int lineno
) {
int time_passed; int time_passed;
for (time_passed = 0;; ++time_passed) { for (time_passed = 0;; ++time_passed) {
@ -112,24 +108,23 @@ static int wait_for(
return 1; return 1;
} }
/* IT8502 employs a scratch ram when flash is being updated. Call the following /* IT8502 employs a scratch RAM when flash is being updated. Call the following
* two functions before/after flash erase/program. */ * two functions before/after flash erase/program. */
void it85xx_enter_scratch_rom() void it85xx_enter_scratch_rom(void)
{ {
int ret; int ret, tries;
int tries;
msg_pdbg("%s():%d was called ...\n", __FUNCTION__, __LINE__); msg_pdbg("%s():%d was called ...\n", __FUNCTION__, __LINE__);
if (it85xx_scratch_rom_reenter > 0) return; if (it85xx_scratch_rom_reenter > 0)
return;
#if 0 #if 0
/* FIXME: this a workaround for the bug that SMBus signal would /* FIXME: this a workaround for the bug that SMBus signal would
* interfere the EC firmware update. Should be removed if * interfere the EC firmware update. Should be removed if
* we find out the root cause. */ * we find out the root cause. */
ret = system("stop powerd >&2"); ret = system("stop powerd >&2");
if (ret) { if (ret)
msg_perr("Cannot stop powerd.\n"); msg_perr("Cannot stop powerd.\n");
}
#endif #endif
for (tries = 0; tries < MAX_TRY; ++tries) { for (tries = 0; tries < MAX_TRY; ++tries) {
@ -173,7 +168,7 @@ void it85xx_enter_scratch_rom()
} }
} }
void it85xx_exit_scratch_rom() void it85xx_exit_scratch_rom(void)
{ {
#if 0 #if 0
int ret; int ret;
@ -181,7 +176,8 @@ void it85xx_exit_scratch_rom()
int tries; int tries;
msg_pdbg("%s():%d was called ...\n", __FUNCTION__, __LINE__); msg_pdbg("%s():%d was called ...\n", __FUNCTION__, __LINE__);
if (it85xx_scratch_rom_reenter <= 0) return; if (it85xx_scratch_rom_reenter <= 0)
return;
for (tries = 0; tries < MAX_TRY; ++tries) { for (tries = 0; tries < MAX_TRY; ++tries) {
/* Wait until IBF (input buffer) is not full. */ /* Wait until IBF (input buffer) is not full. */
@ -220,9 +216,8 @@ void it85xx_exit_scratch_rom()
* interfere the EC firmware update. Should be removed if * interfere the EC firmware update. Should be removed if
* we find out the root cause. */ * we find out the root cause. */
ret = system("start powerd >&2"); ret = system("start powerd >&2");
if (ret) { if (ret)
msg_perr("Cannot start powerd again.\n"); msg_perr("Cannot start powerd again.\n");
}
#endif #endif
} }
@ -245,7 +240,7 @@ static int it85xx_spi_common_init(struct superio s)
return 1; return 1;
#ifdef LPC_IO #ifdef LPC_IO
/* Get LPCPNP of SHM. That's big-endian */ /* Get LPCPNP of SHM. That's big-endian. */
sio_write(s.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */ sio_write(s.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */
shm_io_base = (sio_read(s.port, SHM_IO_BAR0) << 8) + shm_io_base = (sio_read(s.port, SHM_IO_BAR0) << 8) +
sio_read(s.port, SHM_IO_BAR1); sio_read(s.port, SHM_IO_BAR1);
@ -305,7 +300,7 @@ int it85xx_spi_init(struct superio s)
if (buses_supported & BUS_FWH) if (buses_supported & BUS_FWH)
msg_pdbg("Overriding chipset SPI with IT85 FWH|SPI.\n"); msg_pdbg("Overriding chipset SPI with IT85 FWH|SPI.\n");
/* Really leave FWH enabled? */ /* Really leave FWH enabled? */
/* Set this as spi controller. */ /* Set this as SPI controller. */
register_spi_programmer(&spi_programmer_it85xx); register_spi_programmer(&spi_programmer_it85xx);
} }
return ret; return ret;
@ -324,7 +319,7 @@ static int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt,
int i; int i;
it85xx_enter_scratch_rom(); it85xx_enter_scratch_rom();
/* exit scratch rom ONLY when programmer shuts down. Otherwise, the /* exit scratch ROM ONLY when programmer shuts down. Otherwise, the
* temporary flash state may halt EC. */ * temporary flash state may halt EC. */
#ifdef LPC_IO #ifdef LPC_IO

View File

@ -93,8 +93,7 @@ void probe_superio_ite(void)
case 0x85: case 0x85:
msg_pdbg("Found ITE EC, ID 0x%04hx," msg_pdbg("Found ITE EC, ID 0x%04hx,"
"Rev 0x%02x on port 0x%x.\n", "Rev 0x%02x on port 0x%x.\n",
s.model, s.model, sio_read(s.port, CHIP_VER_REG),
sio_read(s.port, CHIP_VER_REG),
s.port); s.port);
register_superio(s); register_superio(s);
break; break;
@ -106,8 +105,10 @@ void probe_superio_ite(void)
static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt, static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr); const unsigned char *writearr, unsigned char *readarr);
static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len); static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf,
static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); int start, int len);
static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf,
int start, int len);
static const struct spi_programmer spi_programmer_it87xx = { static const struct spi_programmer spi_programmer_it87xx = {
.type = SPI_CONTROLLER_IT87XX, .type = SPI_CONTROLLER_IT87XX,
@ -202,8 +203,7 @@ static uint16_t it87spi_probe(uint16_t port)
int init_superio_ite(void) int init_superio_ite(void)
{ {
int i; int i, ret = 0;
int ret = 0;
for (i = 0; i < superio_count; i++) { for (i = 0; i < superio_count; i++) {
if (superios[i].vendor != SUPERIO_VENDOR_ITE) if (superios[i].vendor != SUPERIO_VENDOR_ITE)
@ -313,10 +313,10 @@ static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
} }
/* Page size is usually 256 bytes */ /* Page size is usually 256 bytes */
static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, int start) static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf,
int start)
{ {
int i; int i, result;
int result;
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
result = spi_write_enable(); result = spi_write_enable();
@ -325,9 +325,8 @@ static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, int s
/* FIXME: The command below seems to be redundant or wrong. */ /* FIXME: The command below seems to be redundant or wrong. */
OUTB(0x06, it8716f_flashport + 1); OUTB(0x06, it8716f_flashport + 1);
OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport); OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport);
for (i = 0; i < flash->page_size; i++) { for (i = 0; i < flash->page_size; i++)
chip_writeb(buf[i], bios + start + i); chip_writeb(buf[i], bios + start + i);
}
OUTB(0, it8716f_flashport); OUTB(0, it8716f_flashport);
/* Wait until the Write-In-Progress bit is cleared. /* Wait until the Write-In-Progress bit is cleared.
* This usually takes 1-10 ms, so wait in 1 ms steps. * This usually takes 1-10 ms, so wait in 1 ms steps.
@ -341,7 +340,8 @@ static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, int s
* IT8716F only allows maximum of 512 kb SPI mapped to LPC memory cycles * IT8716F only allows maximum of 512 kb SPI mapped to LPC memory cycles
* Need to read this big flash using firmware cycles 3 byte at a time. * Need to read this big flash using firmware cycles 3 byte at a time.
*/ */
static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len) static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf,
int start, int len)
{ {
fast_spi = 0; fast_spi = 0;
@ -358,7 +358,8 @@ static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int star
return 0; return 0;
} }
static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf,
int start, int len)
{ {
/* /*
* IT8716F only allows maximum of 512 kb SPI chip size for memory * IT8716F only allows maximum of 512 kb SPI chip size for memory

View File

@ -43,16 +43,13 @@ static void *realmem_map;
static void *map_first_meg(unsigned long phys_addr, size_t len) static void *map_first_meg(unsigned long phys_addr, size_t len)
{ {
if (realmem_map)
if (realmem_map) {
return realmem_map + phys_addr; return realmem_map + phys_addr;
}
realmem_map = valloc(1024 * 1024); realmem_map = valloc(1024 * 1024);
if (!realmem_map) { if (!realmem_map)
return ERROR_PTR; return ERROR_PTR;
}
if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) { if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) {
free(realmem_map); free(realmem_map);
@ -68,13 +65,12 @@ static void *sys_physmap(unsigned long phys_addr, size_t len)
int ret; int ret;
__dpmi_meminfo mi; __dpmi_meminfo mi;
/* enable 4GB limit on DS descriptor */ /* Enable 4GB limit on DS descriptor. */
if (!__djgpp_nearptr_enable()) { if (!__djgpp_nearptr_enable())
return ERROR_PTR; return ERROR_PTR;
}
if ((phys_addr + len - 1) < (1024 * 1024)) { if ((phys_addr + len - 1) < (1024 * 1024)) {
/* we need to use another method to map first 1MB */ /* We need to use another method to map first 1MB. */
return map_first_meg(phys_addr, len); return map_first_meg(phys_addr, len);
} }
@ -82,9 +78,8 @@ static void *sys_physmap(unsigned long phys_addr, size_t len)
mi.size = len; mi.size = len;
ret = __dpmi_physical_address_mapping (&mi); ret = __dpmi_physical_address_mapping (&mi);
if (ret != 0) { if (ret != 0)
return ERROR_PTR; return ERROR_PTR;
}
return (void *) mi.address + __djgpp_conventional_base; return (void *) mi.address + __djgpp_conventional_base;
} }
@ -99,7 +94,8 @@ void physunmap(void *virt_addr, size_t len)
/* There is no known way to unmap the first 1 MB. The DPMI server will /* There is no known way to unmap the first 1 MB. The DPMI server will
* do this for us on exit. * do this for us on exit.
*/ */
if ((virt_addr >= realmem_map) && ((virt_addr + len) <= (realmem_map + (1024 * 1024)))) { if ((virt_addr >= realmem_map) &&
((virt_addr + len) <= (realmem_map + (1024 * 1024)))) {
return; return;
} }
@ -195,7 +191,8 @@ static void *sys_physmap_ro_cached(unsigned long phys_addr, size_t len)
if (-1 == fd_mem_cached) { if (-1 == fd_mem_cached) {
/* Open the memory device CACHED. */ /* Open the memory device CACHED. */
if (-1 == (fd_mem_cached = open(MEM_DEV, O_RDWR))) { if (-1 == (fd_mem_cached = open(MEM_DEV, O_RDWR))) {
msg_perr("Critical error: open(" MEM_DEV "): %s", strerror(errno)); msg_perr("Critical error: open(" MEM_DEV "): %s",
strerror(errno));
exit(2); exit(2);
} }
} }
@ -221,7 +218,8 @@ void physunmap(void *virt_addr, size_t len)
#define PHYSMAP_RW 0 #define PHYSMAP_RW 0
#define PHYSMAP_RO 1 #define PHYSMAP_RO 1
static void *physmap_common(const char *descr, unsigned long phys_addr, size_t len, int mayfail, int readonly) static void *physmap_common(const char *descr, unsigned long phys_addr,
size_t len, int mayfail, int readonly)
{ {
void *virt_addr; void *virt_addr;
@ -241,16 +239,16 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, size_t l
descr, (unsigned long)len, phys_addr); descr, (unsigned long)len, phys_addr);
} }
if (readonly) { if (readonly)
virt_addr = sys_physmap_ro_cached(phys_addr, len); virt_addr = sys_physmap_ro_cached(phys_addr, len);
} else { else
virt_addr = sys_physmap_rw_uncached(phys_addr, len); virt_addr = sys_physmap_rw_uncached(phys_addr, len);
}
if (ERROR_PTR == virt_addr) { if (ERROR_PTR == virt_addr) {
if (NULL == descr) if (NULL == descr)
descr = "memory"; descr = "memory";
msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, (unsigned long)len, phys_addr); msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr,
(unsigned long)len, phys_addr);
perror(MEM_DEV " mmap failed"); perror(MEM_DEV " mmap failed");
#ifdef __linux__ #ifdef __linux__
if (EINVAL == errno) { if (EINVAL == errno) {
@ -262,8 +260,8 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, size_t l
} }
#elif defined (__OpenBSD__) #elif defined (__OpenBSD__)
msg_perr("Please set securelevel=-1 in /etc/rc.securelevel " msg_perr("Please set securelevel=-1 in /etc/rc.securelevel "
"and reboot, or reboot into \n"); "and reboot, or reboot into\n"
msg_perr("single user mode.\n"); "single user mode.\n");
#endif #endif
if (!mayfail) if (!mayfail)
exit(3); exit(3);
@ -274,12 +272,14 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, size_t l
void *physmap(const char *descr, unsigned long phys_addr, size_t len) void *physmap(const char *descr, unsigned long phys_addr, size_t len)
{ {
return physmap_common(descr, phys_addr, len, PHYSMAP_NOFAIL, PHYSMAP_RW); return physmap_common(descr, phys_addr, len, PHYSMAP_NOFAIL,
PHYSMAP_RW);
} }
void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len) void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len)
{ {
return physmap_common(descr, phys_addr, len, PHYSMAP_MAYFAIL, PHYSMAP_RO); return physmap_common(descr, phys_addr, len, PHYSMAP_MAYFAIL,
PHYSMAP_RO);
} }
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
@ -309,7 +309,6 @@ msr_t rdmsr(int addr)
if (read(fd_msr, buf, 8) == 8) { if (read(fd_msr, buf, 8) == 8) {
msr.lo = buf[0]; msr.lo = buf[0];
msr.hi = buf[1]; msr.hi = buf[1];
return msr; return msr;
} }
@ -341,7 +340,7 @@ int wrmsr(int addr, msr_t msr)
exit(1); exit(1);
} }
/* some MSRs must not be written */ /* Some MSRs must not be written. */
if (errno == EIO) if (errno == EIO)
return -1; return -1;
@ -379,7 +378,7 @@ void cleanup_cpu_msr(void)
close(fd_msr); close(fd_msr);
/* Clear MSR file descriptor */ /* Clear MSR file descriptor. */
fd_msr = -1; fd_msr = -1;
} }
#else #else
@ -462,7 +461,7 @@ void cleanup_cpu_msr(void)
close(fd_msr); close(fd_msr);
/* Clear MSR file descriptor */ /* Clear MSR file descriptor. */
fd_msr = -1; fd_msr = -1;
} }