80/100/132 column line width policy
by Carl-Daniel Hailfinger
Hi,
we're hitting the 80 column limit in our code in ways which actually
reduce readability for the code. Examples are various multiline messages
and complicated nested code where refactoring to a separate function
doesn't make sense.
Keeping the old 80 column limit is not really an option anymore.
Standard terminal sizes have one of 80, 100 or 132 columns.
Given the monitor resolutions many people have nowadays, I think it is
safe to say that you can fit two xterms with 100 columns horizonally
next to each other. 100 columns should also be sufficient for a msg_p*
of roughly 80 columns of text.
132 columns provide more leeway, but IMHO that would be too wide for
good readability (and my screen can't fit two xterms side-by-side anymore).
Of course some files have sections where any column limit is not
acceptable (board lists etc.), but the column limit violations should be
limited to the affected file sections, not whole files.
Comments?
I'd like to get this decided today or tomorrow so we know where we need
line breaks in Stefan Tauner's new struct flashchip patch.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
11 months, 4 weeks
Spansion S25FL128P......X
by The Raven
I have a spansion S25FL128P......X chip and can do some tests.
The "problem" is that i don't know if its an 0 or an 1.
On the chip i see only "FL128PIF" and one line lower i see "00299012 C".
Probing works (id1 0x01, id2 0x2018):
Calibrating delay loop... OK.
serprog: Programmer name is "serprog-duino"
Found Spansion flash chip "S25FL128P......0" (16384 kB, SPI) on serprog.
Found Spansion flash chip "S25FL128P......1" (16384 kB, SPI) on serprog.
Found Spansion flash chip "S25FL128S......0" (16384 kB, SPI) on serprog.
Found Spansion flash chip "S25FL128S......1" (16384 kB, SPI) on serprog.
Found Spansion flash chip "S25FL129P......0" (16384 kB, SPI) on serprog.
Found Spansion flash chip "S25FL129P......1" (16384 kB, SPI) on serprog.
Multiple flash chip definitions match the detected chip(s):
"S25FL128P......0", "S25FL128P......1", "S25FL128S......0",
"S25FL128S......1", "S25FL129P......0", "S25FL129P......1"
Please specify which chip definition to use with the -c <chipname> option.
BTW: Chip was fund on a Dell-Systemboard.
2 years, 7 months
[PATCH] Support device lists for programmers without PCI/USB IDs
by Carl-Daniel Hailfinger
Based on an idea by Kyösti Mälkki.
Issues:
print_wiki is broken right now. Don't compile it in.
The internal programmer is listed twice in -L output.
Some programmers have stupid indentation in -L output.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Index: flashrom-noid_programmers_support_device_list/ogp_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/ogp_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/ogp_spi.c (Arbeitskopie)
@@ -47,7 +47,7 @@
static uint32_t ogp_reg__ce;
static uint32_t ogp_reg_sck;
-const struct dev_entry ogp_spi[] = {
+const struct id_dev_entry ogp_spi[] = {
{PCI_VENDOR_ID_OGP, 0x0000, OK, "Open Graphics Project", "Development Board OGD1"},
{0},
Index: flashrom-noid_programmers_support_device_list/drkaiser.c
===================================================================
--- flashrom-noid_programmers_support_device_list/drkaiser.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/drkaiser.c (Arbeitskopie)
@@ -33,7 +33,7 @@
/* Mask to restrict flash accesses to the 128kB memory window. */
#define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
-const struct dev_entry drkaiser_pcidev[] = {
+const struct id_dev_entry drkaiser_pcidev[] = {
{0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
{0},
Index: flashrom-noid_programmers_support_device_list/pcidev.c
===================================================================
--- flashrom-noid_programmers_support_device_list/pcidev.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/pcidev.c (Arbeitskopie)
@@ -184,7 +184,7 @@
* also matches the specified bus:device.function.
* For convenience, this function also registers its own undo handlers.
*/
-struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar)
+struct pci_dev *pcidev_init(const struct id_dev_entry *devs, int bar)
{
struct pci_dev *dev;
struct pci_dev *found_dev = NULL;
Index: flashrom-noid_programmers_support_device_list/gfxnvidia.c
===================================================================
--- flashrom-noid_programmers_support_device_list/gfxnvidia.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/gfxnvidia.c (Arbeitskopie)
@@ -34,7 +34,7 @@
uint8_t *nvidia_bar;
-const struct dev_entry gfx_nvidia[] = {
+const struct id_dev_entry gfx_nvidia[] = {
{0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" },
{0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" },
{0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" },
Index: flashrom-noid_programmers_support_device_list/serprog.c
===================================================================
--- flashrom-noid_programmers_support_device_list/serprog.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/serprog.c (Arbeitskopie)
@@ -44,6 +44,11 @@
#define MSGHEADER "serprog: "
+const struct noid_dev_entry serprog_devs[] = {
+ {"", OK, "All programmer devices speaking the serprog protocol"},
+ {0},
+};
+
/*
* FIXME: This prototype was added to help reduce diffs for the shutdown
* registration patch, which shifted many lines of code to place
Index: flashrom-noid_programmers_support_device_list/nicrealtek.c
===================================================================
--- flashrom-noid_programmers_support_device_list/nicrealtek.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/nicrealtek.c (Arbeitskopie)
@@ -30,7 +30,7 @@
static int bios_rom_addr, bios_rom_data;
-const struct dev_entry nics_realtek[] = {
+const struct id_dev_entry nics_realtek[] = {
{0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
{0x10ec, 0x8169, NT, "Realtek", "RTL8169"},
{0x1113, 0x1211, OK, "SMC", "1211TX"}, /* RTL8139 clone */
Index: flashrom-noid_programmers_support_device_list/satamv.c
===================================================================
--- flashrom-noid_programmers_support_device_list/satamv.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/satamv.c (Arbeitskopie)
@@ -29,7 +29,7 @@
uint8_t *mv_bar;
uint16_t mv_iobar;
-const struct dev_entry satas_mv[] = {
+const struct id_dev_entry satas_mv[] = {
/* 88SX6041 and 88SX6042 are the same according to the datasheet. */
{0x11ab, 0x7042, OK, "Marvell", "88SX7042 PCI-e 4-port SATA-II"},
Index: flashrom-noid_programmers_support_device_list/dummyflasher.c
===================================================================
--- flashrom-noid_programmers_support_device_list/dummyflasher.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/dummyflasher.c (Arbeitskopie)
@@ -39,6 +39,11 @@
#include <sys/stat.h>
#endif
+const struct noid_dev_entry dummy_devs[] = {
+ {"dummy", OK, "Dummy device, does nothing and logs all accesses"},
+ {0},
+};
+
#if EMULATE_CHIP
static uint8_t *flashchip_contents = NULL;
enum emu_chip {
Index: flashrom-noid_programmers_support_device_list/internal.c
===================================================================
--- flashrom-noid_programmers_support_device_list/internal.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/internal.c (Arbeitskopie)
@@ -97,6 +97,11 @@
#endif
#if CONFIG_INTERNAL == 1
+const struct noid_dev_entry internal_devs[] = {
+ {"", OK, "Insert witty remark here and/or reference the board/chipset list\n"},
+ {0},
+};
+
int force_boardenable = 0;
int force_boardmismatch = 0;
Index: flashrom-noid_programmers_support_device_list/print_wiki.c
===================================================================
--- flashrom-noid_programmers_support_device_list/print_wiki.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/print_wiki.c (Arbeitskopie)
@@ -301,7 +301,7 @@
/* Following functions are not needed when no PCI/USB programmers are compiled in,
* but since print_wiki code has no size constraints we include it unconditionally. */
-static int count_supported_devs_wiki(const struct dev_entry *devs)
+static int count_supported_devs_wiki(const struct id_dev_entry *devs)
{
unsigned int count = 0;
unsigned int i = 0;
@@ -309,12 +309,13 @@
count++;
return count;
}
+#warning Handle noid_dev_entry devices
static void print_supported_devs_wiki_helper(const struct programmer_entry prog)
{
int i = 0;
static int c = 0;
- const struct dev_entry *devs = prog.devs.dev;
+ const struct id_dev_entry *devs = prog.devs.dev;
const unsigned int count = count_supported_devs_wiki(devs);
/* Alternate colors if the vendor changes. */
Index: flashrom-noid_programmers_support_device_list/nicintel_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/nicintel_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/nicintel_spi.c (Arbeitskopie)
@@ -67,7 +67,7 @@
uint8_t *nicintel_spibar;
-const struct dev_entry nics_intel_spi[] = {
+const struct id_dev_entry nics_intel_spi[] = {
{PCI_VENDOR_ID_INTEL, 0x105e, OK, "Intel", "82571EB Gigabit Ethernet Controller"},
{PCI_VENDOR_ID_INTEL, 0x1076, OK, "Intel", "82541GI Gigabit Ethernet Controller"},
{PCI_VENDOR_ID_INTEL, 0x107c, OK, "Intel", "82541PI Gigabit Ethernet Controller"},
Index: flashrom-noid_programmers_support_device_list/usbblaster_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/usbblaster_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/usbblaster_spi.c (Arbeitskopie)
@@ -49,7 +49,7 @@
#define ALTERA_VID 0x09fb
#define ALTERA_USBBLASTER_PID 0x6001
-const struct dev_entry devs_usbblasterspi[] = {
+const struct id_dev_entry devs_usbblasterspi[] = {
{ALTERA_VID, ALTERA_USBBLASTER_PID, OK, "Altera", "USB-Blaster"},
{}
Index: flashrom-noid_programmers_support_device_list/nicnatsemi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/nicnatsemi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/nicnatsemi.c (Arbeitskopie)
@@ -30,7 +30,7 @@
#define BOOT_ROM_ADDR 0x50
#define BOOT_ROM_DATA 0x54
-const struct dev_entry nics_natsemi[] = {
+const struct id_dev_entry nics_natsemi[] = {
{0x100b, 0x0020, NT, "National Semiconductor", "DP83815/DP83816"},
{0x100b, 0x0022, NT, "National Semiconductor", "DP83820"},
Index: flashrom-noid_programmers_support_device_list/rayer_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/rayer_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/rayer_spi.c (Arbeitskopie)
@@ -37,6 +37,12 @@
#include "programmer.h"
#include "hwaccess.h"
+const struct noid_dev_entry rayer_spi_devs[] = {
+ {"rayer", OK, "RayeR parallel port programmer"},
+ {"xilinx", OK, "Xilinx Parallel Cable III (DLC 5)"},
+ {0},
+};
+
enum rayer_type {
TYPE_RAYER,
TYPE_XILINX_DLC5,
Index: flashrom-noid_programmers_support_device_list/dediprog.c
===================================================================
--- flashrom-noid_programmers_support_device_list/dediprog.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/dediprog.c (Arbeitskopie)
@@ -27,6 +27,11 @@
#include "programmer.h"
#include "spi.h"
+const struct noid_dev_entry dediprog_devs[] = {
+ {"", OK, "Dediprog SF100"},
+ {0},
+};
+
#define FIRMWARE_VERSION(x,y,z) ((x << 16) | (y << 8) | z)
#define DEFAULT_TIMEOUT 3000
static usb_dev_handle *dediprog_handle;
Index: flashrom-noid_programmers_support_device_list/buspirate_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/buspirate_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/buspirate_spi.c (Arbeitskopie)
@@ -27,6 +27,11 @@
#include "programmer.h"
#include "spi.h"
+const struct noid_dev_entry buspirate_spi_devs[] = {
+ {"", OK, "Dangerous Prototypes Bus Pirate"},
+ {0},
+};
+
/* Change this to #define if you want to test without a serial implementation */
#undef FAKE_COMMUNICATION
Index: flashrom-noid_programmers_support_device_list/linux_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/linux_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/linux_spi.c (Arbeitskopie)
@@ -34,6 +34,11 @@
#include "programmer.h"
#include "spi.h"
+const struct noid_dev_entry linux_spi_devs[] = {
+ {"", OK, "Device files /dev/spidev*.*"},
+ {0},
+};
+
static int fd = -1;
static int linux_spi_shutdown(void *data);
Index: flashrom-noid_programmers_support_device_list/atahpt.c
===================================================================
--- flashrom-noid_programmers_support_device_list/atahpt.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/atahpt.c (Arbeitskopie)
@@ -33,7 +33,7 @@
#define PCI_VENDOR_ID_HPT 0x1103
-const struct dev_entry ata_hpt[] = {
+const struct id_dev_entry ata_hpt[] = {
{0x1103, 0x0004, NT, "Highpoint", "HPT366/368/370/370A/372/372N"},
{0x1103, 0x0005, NT, "Highpoint", "HPT372A/372N"},
{0x1103, 0x0006, NT, "Highpoint", "HPT302/302N"},
Index: flashrom-noid_programmers_support_device_list/nic3com.c
===================================================================
--- flashrom-noid_programmers_support_device_list/nic3com.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/nic3com.c (Arbeitskopie)
@@ -36,7 +36,7 @@
static uint32_t internal_conf;
static uint16_t id;
-const struct dev_entry nics_3com[] = {
+const struct id_dev_entry nics_3com[] = {
/* 3C90xB */
{0x10b7, 0x9055, OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
{0x10b7, 0x9001, NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
Index: flashrom-noid_programmers_support_device_list/satasii.c
===================================================================
--- flashrom-noid_programmers_support_device_list/satasii.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/satasii.c (Arbeitskopie)
@@ -30,7 +30,7 @@
static uint8_t *sii_bar;
static uint16_t id;
-const struct dev_entry satas_sii[] = {
+const struct id_dev_entry satas_sii[] = {
{0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"},
{0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"},
{0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"},
Index: flashrom-noid_programmers_support_device_list/ft2232_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/ft2232_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/ft2232_spi.c (Arbeitskopie)
@@ -57,7 +57,7 @@
#define OLIMEX_ARM_OCD_H_PID 0x002B
#define OLIMEX_ARM_TINY_H_PID 0x002A
-const struct dev_entry devs_ft2232spi[] = {
+const struct id_dev_entry devs_ft2232spi[] = {
{FTDI_VID, FTDI_FT2232H_PID, OK, "FTDI", "FT2232H"},
{FTDI_VID, FTDI_FT4232H_PID, OK, "FTDI", "FT4232H"},
{FTDI_VID, FTDI_FT232H_PID, OK, "FTDI", "FT232H"},
Index: flashrom-noid_programmers_support_device_list/pony_spi.c
===================================================================
--- flashrom-noid_programmers_support_device_list/pony_spi.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/pony_spi.c (Arbeitskopie)
@@ -47,6 +47,13 @@
#include "flash.h"
#include "programmer.h"
+const struct noid_dev_entry pony_spi_devs[] = {
+ {"serbang", OK, "Programmers compatible with serbang"},
+ {"si_prog", OK, "Programmers compatible with SI-Prog"},
+ {"ajawe", OK, "Programmers compatible with AJAWe"},
+ {0},
+};
+
enum pony_type {
TYPE_SI_PROG,
TYPE_SERBANG,
Index: flashrom-noid_programmers_support_device_list/nicintel.c
===================================================================
--- flashrom-noid_programmers_support_device_list/nicintel.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/nicintel.c (Arbeitskopie)
@@ -27,7 +27,7 @@
uint8_t *nicintel_bar;
uint8_t *nicintel_control_bar;
-const struct dev_entry nics_intel[] = {
+const struct id_dev_entry nics_intel[] = {
{PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
{PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
Index: flashrom-noid_programmers_support_device_list/flashrom.c
===================================================================
--- flashrom-noid_programmers_support_device_list/flashrom.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/flashrom.c (Arbeitskopie)
@@ -65,7 +65,7 @@
{
.name = "internal",
.type = OTHER,
- .devs.note = NULL,
+ .devs.noid_dev = internal_devs,
.init = internal_init,
.map_flash_region = physmap,
.unmap_flash_region = physunmap,
@@ -77,8 +77,7 @@
{
.name = "dummy",
.type = OTHER,
- /* FIXME */
- .devs.note = "Dummy device, does nothing and logs all accesses\n",
+ .devs.noid_dev = dummy_devs,
.init = dummy_init,
.map_flash_region = dummy_map,
.unmap_flash_region = dummy_unmap,
@@ -90,7 +89,7 @@
{
.name = "nic3com",
.type = PCI,
- .devs.dev = nics_3com,
+ .devs.id_dev = nics_3com,
.init = nic3com_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -103,7 +102,7 @@
/* This programmer works for Realtek RTL8139 and SMC 1211. */
.name = "nicrealtek",
.type = PCI,
- .devs.dev = nics_realtek,
+ .devs.id_dev = nics_realtek,
.init = nicrealtek_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -115,7 +114,7 @@
{
.name = "nicnatsemi",
.type = PCI,
- .devs.dev = nics_natsemi,
+ .devs.id_dev = nics_natsemi,
.init = nicnatsemi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -127,7 +126,7 @@
{
.name = "gfxnvidia",
.type = PCI,
- .devs.dev = gfx_nvidia,
+ .devs.id_dev = gfx_nvidia,
.init = gfxnvidia_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -139,7 +138,7 @@
{
.name = "drkaiser",
.type = PCI,
- .devs.dev = drkaiser_pcidev,
+ .devs.id_dev = drkaiser_pcidev,
.init = drkaiser_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -151,7 +150,7 @@
{
.name = "satasii",
.type = PCI,
- .devs.dev = satas_sii,
+ .devs.id_dev = satas_sii,
.init = satasii_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -163,7 +162,7 @@
{
.name = "atahpt",
.type = PCI,
- .devs.dev = ata_hpt,
+ .devs.id_dev = ata_hpt,
.init = atahpt_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -175,7 +174,7 @@
{
.name = "ft2232_spi",
.type = USB,
- .devs.dev = devs_ft2232spi,
+ .devs.id_dev = devs_ft2232spi,
.init = ft2232_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -187,8 +186,7 @@
{
.name = "serprog",
.type = OTHER,
- /* FIXME */
- .devs.note = "All programmer devices speaking the serprog protocol\n",
+ .devs.noid_dev = serprog_devs,
.init = serprog_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -200,8 +198,7 @@
{
.name = "buspirate_spi",
.type = OTHER,
- /* FIXME */
- .devs.note = "Dangerous Prototypes Bus Pirate\n",
+ .devs.noid_dev = buspirate_spi_devs,
.init = buspirate_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -213,8 +210,7 @@
{
.name = "dediprog",
.type = OTHER,
- /* FIXME */
- .devs.note = "Dediprog SF100\n",
+ .devs.noid_dev = dediprog_devs,
.init = dediprog_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -226,8 +222,7 @@
{
.name = "rayer_spi",
.type = OTHER,
- /* FIXME */
- .devs.note = "RayeR parallel port programmer\n",
+ .devs.noid_dev = rayer_spi_devs,
.init = rayer_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -239,8 +234,7 @@
{
.name = "pony_spi",
.type = OTHER,
- /* FIXME */
- .devs.note = "Programmers compatible with SI-Prog, serbang or AJAWe\n",
+ .devs.noid_dev = pony_spi_devs,
.init = pony_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -252,7 +246,7 @@
{
.name = "nicintel",
.type = PCI,
- .devs.dev = nics_intel,
+ .devs.id_dev = nics_intel,
.init = nicintel_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -264,7 +258,7 @@
{
.name = "nicintel_spi",
.type = PCI,
- .devs.dev = nics_intel_spi,
+ .devs.id_dev = nics_intel_spi,
.init = nicintel_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -276,7 +270,7 @@
{
.name = "ogp_spi",
.type = PCI,
- .devs.dev = ogp_spi,
+ .devs.id_dev = ogp_spi,
.init = ogp_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -288,7 +282,7 @@
{
.name = "satamv",
.type = PCI,
- .devs.dev = satas_mv,
+ .devs.id_dev = satas_mv,
.init = satamv_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -300,7 +294,7 @@
{
.name = "linux_spi",
.type = OTHER,
- .devs.note = "Device files /dev/spidev*.*\n",
+ .devs.noid_dev = linux_spi_devs,
.init = linux_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -312,7 +306,7 @@
{
.name = "usbblaster_spi",
.type = USB,
- .devs.dev = devs_usbblasterspi,
+ .devs.id_dev = devs_usbblasterspi,
.init = usbblaster_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -1675,10 +1669,9 @@
case USB:
case PCI:
case OTHER:
- if (p.devs.note == NULL) {
- if (strcmp("internal", p.name) == 0)
- break; /* This one has its device list stored separately. */
- msg_gerr("Programmer %s has neither a device list nor a textual description!\n",
+ /* Either id_dev or noid_dev should be non-NULL. */
+ if (p.devs.id_dev == NULL) {
+ msg_gerr("Programmer %s doesn't have a device list!\n",
p.name);
ret = 1;
}
Index: flashrom-noid_programmers_support_device_list/programmer.h
===================================================================
--- flashrom-noid_programmers_support_device_list/programmer.h (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/programmer.h (Arbeitskopie)
@@ -99,7 +99,13 @@
OTHER,
};
-struct dev_entry {
+struct noid_dev_entry {
+ const char *type;
+ const enum test_state status;
+ const char *description;
+};
+
+struct id_dev_entry {
uint16_t vendor_id;
uint16_t device_id;
const enum test_state status;
@@ -111,8 +117,8 @@
const char *name;
const enum programmer_type type;
union {
- const struct dev_entry *const dev;
- const char *const note;
+ const struct noid_dev_entry *const noid_dev;
+ const struct id_dev_entry *const id_dev;
} devs;
int (*init) (void);
@@ -172,7 +178,7 @@
extern struct pci_access *pacc;
int pci_init_common(void);
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
-struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
+struct pci_dev *pcidev_init(const struct id_dev_entry *devs, int bar);
/* rpci_write_* are reversible writes. The original PCI config space register
* contents will be restored on shutdown.
*/
@@ -320,6 +326,7 @@
int register_superio(struct superio s);
extern enum chipbustype internal_buses_supported;
int internal_init(void);
+extern const struct noid_dev_entry internal_devs[];
#endif
/* hwaccess.c */
@@ -360,94 +367,97 @@
int dummy_init(void);
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
void dummy_unmap(void *virt_addr, size_t len);
+extern const struct noid_dev_entry dummy_devs[];
#endif
/* nic3com.c */
#if CONFIG_NIC3COM == 1
int nic3com_init(void);
-extern const struct dev_entry nics_3com[];
+extern const struct id_dev_entry nics_3com[];
#endif
/* gfxnvidia.c */
#if CONFIG_GFXNVIDIA == 1
int gfxnvidia_init(void);
-extern const struct dev_entry gfx_nvidia[];
+extern const struct id_dev_entry gfx_nvidia[];
#endif
/* drkaiser.c */
#if CONFIG_DRKAISER == 1
int drkaiser_init(void);
-extern const struct dev_entry drkaiser_pcidev[];
+extern const struct id_dev_entry drkaiser_pcidev[];
#endif
/* nicrealtek.c */
#if CONFIG_NICREALTEK == 1
int nicrealtek_init(void);
-extern const struct dev_entry nics_realtek[];
+extern const struct id_dev_entry nics_realtek[];
#endif
/* nicnatsemi.c */
#if CONFIG_NICNATSEMI == 1
int nicnatsemi_init(void);
-extern const struct dev_entry nics_natsemi[];
+extern const struct id_dev_entry nics_natsemi[];
#endif
/* nicintel.c */
#if CONFIG_NICINTEL == 1
int nicintel_init(void);
-extern const struct dev_entry nics_intel[];
+extern const struct id_dev_entry nics_intel[];
#endif
/* nicintel_spi.c */
#if CONFIG_NICINTEL_SPI == 1
int nicintel_spi_init(void);
-extern const struct dev_entry nics_intel_spi[];
+extern const struct id_dev_entry nics_intel_spi[];
#endif
/* ogp_spi.c */
#if CONFIG_OGP_SPI == 1
int ogp_spi_init(void);
-extern const struct dev_entry ogp_spi[];
+extern const struct id_dev_entry ogp_spi[];
#endif
/* satamv.c */
#if CONFIG_SATAMV == 1
int satamv_init(void);
-extern const struct dev_entry satas_mv[];
+extern const struct id_dev_entry satas_mv[];
#endif
/* satasii.c */
#if CONFIG_SATASII == 1
int satasii_init(void);
-extern const struct dev_entry satas_sii[];
+extern const struct id_dev_entry satas_sii[];
#endif
/* atahpt.c */
#if CONFIG_ATAHPT == 1
int atahpt_init(void);
-extern const struct dev_entry ata_hpt[];
+extern const struct id_dev_entry ata_hpt[];
#endif
/* ft2232_spi.c */
#if CONFIG_FT2232_SPI == 1
int ft2232_spi_init(void);
-extern const struct dev_entry devs_ft2232spi[];
+extern const struct id_dev_entry devs_ft2232spi[];
#endif
/* usbblaster_spi.c */
#if CONFIG_USBBLASTER_SPI == 1
int usbblaster_spi_init(void);
-extern const struct dev_entry devs_usbblasterspi[];
+extern const struct id_dev_entry devs_usbblasterspi[];
#endif
/* rayer_spi.c */
#if CONFIG_RAYER_SPI == 1
int rayer_spi_init(void);
+extern const struct noid_dev_entry rayer_spi_devs[];
#endif
/* pony_spi.c */
#if CONFIG_PONY_SPI == 1
int pony_spi_init(void);
+extern const struct noid_dev_entry pony_spi_devs[];
#endif
/* bitbang_spi.c */
@@ -456,16 +466,19 @@
/* buspirate_spi.c */
#if CONFIG_BUSPIRATE_SPI == 1
int buspirate_spi_init(void);
+extern const struct noid_dev_entry buspirate_spi_devs[];
#endif
/* linux_spi.c */
#if CONFIG_LINUX_SPI == 1
int linux_spi_init(void);
+extern const struct noid_dev_entry linux_spi_devs[];
#endif
/* dediprog.c */
#if CONFIG_DEDIPROG == 1
int dediprog_init(void);
+extern const struct noid_dev_entry dediprog_devs[];
#endif
/* flashrom.c */
@@ -642,6 +655,7 @@
#if CONFIG_SERPROG == 1
int serprog_init(void);
void serprog_delay(int usecs);
+extern const struct noid_dev_entry serprog_devs[];
#endif
/* serial.c */
Index: flashrom-noid_programmers_support_device_list/print.c
===================================================================
--- flashrom-noid_programmers_support_device_list/print.c (Revision 1666)
+++ flashrom-noid_programmers_support_device_list/print.c (Arbeitskopie)
@@ -433,11 +433,11 @@
}
#endif
-void print_supported_devs(const struct programmer_entry prog, const char *const type)
+void print_supported_id_devs(const struct programmer_entry prog, const char *const type)
{
int i;
- const struct dev_entry *const devs = prog.devs.dev;
+ const struct id_dev_entry *const devs = prog.devs.id_dev;
msg_ginfo("\nSupported %s devices for the %s programmer:\n", type, prog.name);
for (i = 0; devs[i].vendor_name != NULL; i++) {
msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id,
@@ -445,6 +445,18 @@
}
}
+void print_supported_noid_devs(const struct programmer_entry prog, const char *const type)
+{
+ int i;
+
+ const struct noid_dev_entry *const devs = prog.devs.noid_dev;
+ msg_ginfo("\nSupported models for the %s programmer:\n", prog.name);
+ for (i = 0; devs[i].type != NULL; i++) {
+ msg_pinfo("%-20s %s %s\n", devs[i].type, devs[i].description,
+ (devs[i].status == NT) ? " (untested)" : "");
+ }
+}
+
int print_supported(void)
{
unsigned int i;
@@ -467,18 +479,15 @@
const struct programmer_entry prog = programmer_table[i];
switch (prog.type) {
case USB:
- print_supported_devs(prog, "USB");
+ print_supported_id_devs(prog, "USB");
break;
#if NEED_PCI == 1
case PCI:
- print_supported_devs(prog, "PCI");
+ print_supported_id_devs(prog, "PCI");
break;
#endif
case OTHER:
- if (prog.devs.note != NULL) {
- msg_ginfo("\nSupported devices for the %s programmer:\n", prog.name);
- msg_ginfo("%s", prog.devs.note);
- }
+ print_supported_noid_devs(prog, "(generic)");
break;
default:
msg_gerr("\n%s: %s: Uninitialized programmer type! Please report a bug at "
--
http://www.hailfinger.org/
3 years, 9 months
[PATCH 1/4] Bump dediprog driver to use libusb-1.0
by Kyösti Mälkki
From: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Am 21.02.2013 01:46 schrieb Carl-Daniel Hailfinger:
> Hi Nico,
>
> thanks for your patch.
>
> Am 16.11.2012 11:28 schrieb Nico Huber:
>> > This patch tracks the changes in the libusb interface. Nothing changed
>> > in the behaviour of the driver, so far.
>> >
>> > It will be used by a follow-up patch. It's based on "Enable spi clock
>> > setting in dediprog driver".
>> >
>> > Signed-off-by: Nico Huber <nico.huber(a)secunet.com>
> Review follows.
> The Makefile part checked for libusb 0.1, but it set the linker
> parameter for libusb 1.0.
> The code assumed that libusb_error_name() is always available, but that
> function was only introduced in libusb 1.0.9.
> There was a conflict between the added device parameter for multiple
> Dedipro SF100 devices on one PC (r1628) and the removal of
> get_device_by_vid_pid().
>
> I have fixed and forward ported the code, please check that it works and
> looks sane.
>
> This patch is completely untested, I only checked whether it compiles.
> If it works for you and looks sane, please tell me so I can commit.
>
> Signed-off-by: Nico Huber <nico.huber(a)secunet.com>
New version. Fixed error messages and incomplete cleanup in the error case.
libusb header file location is still something I have to fix in another
iteration.
Signed-off-by: Nico Huber <nico.huber(a)secunet.com>
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
---
Makefile | 58 +++++++++-----
dediprog.c | 258 +++++++++++++++++++++++++++++++++----------------------------
2 files changed, 178 insertions(+), 138 deletions(-)
diff --git a/Makefile b/Makefile
index 07fefc0..96a7987 100644
--- a/Makefile
+++ b/Makefile
@@ -117,7 +117,7 @@ UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes
else
override CONFIG_PONY_SPI = no
endif
-# Dediprog and FT2232 are not supported under DOS (missing USB support).
+# Dediprog and FT2232 are not supported under DOS (missing libusb support).
ifeq ($(CONFIG_DEDIPROG), yes)
UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes
else
@@ -504,8 +504,9 @@ ifeq ($(NEED_FTDI), yes)
FTDILIBS := $(shell pkg-config --libs libftdi 2>/dev/null || printf "%s" "-lftdi -lusb")
FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FT232H := yes" .features && printf "%s" "-D'HAVE_FT232H=1'")
FEATURE_LIBS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "$(FTDILIBS)")
-# We can't set NEED_USB here because that would transform libftdi auto-enabling
+# We can't set NEED_LIBUSB1 here because that would transform libftdi auto-enabling
# into a hard requirement for libusb, defeating the purpose of auto-enabling.
+# Besides that, the old libftdi requires libusb 0.1, not libusb 1.0.
endif
ifeq ($(CONFIG_DUMMY), yes)
@@ -558,7 +559,7 @@ endif
ifeq ($(CONFIG_DEDIPROG), yes)
FEATURE_CFLAGS += -D'CONFIG_DEDIPROG=1'
PROGRAMMER_OBJS += dediprog.o
-NEED_USB := yes
+NEED_LIBUSB1 := yes
endif
ifeq ($(CONFIG_SATAMV), yes)
@@ -613,10 +614,12 @@ endif
endif
endif
-ifeq ($(NEED_USB), yes)
-CHECK_LIBUSB0 = yes
-FEATURE_CFLAGS += -D'NEED_USB=1'
-USBLIBS := $(shell pkg-config --libs libusb 2>/dev/null || printf "%s" "-lusb")
+ifeq ($(NEED_LIBUSB1), yes)
+CHECK_LIBUSB1 = yes
+FEATURE_CFLAGS += -D'NEED_LIBUSB1=1'
+FEATURE_CFLAGS += $(shell pkg-config --cflags libusb-1.0 2>/dev/null)
+USBLIBS := $(shell pkg-config --libs libusb-1.0 2>/dev/null || printf "%s" "-lusb-1.0")
+FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "LIBUSB1_ERROR_NAME := yes" .features && printf "%s" "-D'LIBUSB_HAVE_ERROR_NAME=1'")
endif
ifeq ($(CONFIG_PRINT_WIKI), yes)
@@ -711,17 +714,17 @@ int main(int argc, char **argv)
endef
export LIBPCI_TEST
-define LIBUSB0_TEST
-#include <usb.h>
+define LIBUSB1_TEST
+#include <libusb.h>
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
- usb_init();
+ libusb_init(NULL);
return 0;
}
endef
-export LIBUSB0_TEST
+export LIBUSB1_TEST
hwlibs: compiler
@printf "" > .libdeps
@@ -744,18 +747,18 @@ ifeq ($(CHECK_LIBPCI), yes)
rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1) )
@rm -f .test.c .test.o .test$(EXEC_SUFFIX)
endif
-ifeq ($(CHECK_LIBUSB0), yes)
- @printf "Checking for libusb-0.1/libusb-compat headers... "
- @echo "$$LIBUSB0_TEST" > .test.c
- @$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null && \
+ifeq ($(CHECK_LIBUSB1), yes)
+ @printf "Checking for libusb-1.0 headers... "
+ @echo "$$LIBUSB1_TEST" > .test.c
+ @$(CC) -c $(CPPFLAGS) $(FEATURE_CFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null && \
echo "found." || ( echo "not found."; echo; \
- echo "Please install libusb-0.1 headers or libusb-compat headers."; \
+ echo "Please install libusb-1.0 headers."; \
echo "See README for more information."; echo; \
rm -f .test.c .test.o; exit 1)
- @printf "Checking if libusb-0.1 is usable... "
+ @printf "Checking if libusb-1.0 is usable... "
@$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(USBLIBS) >/dev/null && \
echo "yes." || ( echo "no."; \
- echo "Please install libusb-0.1 or libusb-compat."; \
+ echo "Please install libusb-1.0."; \
echo "See README for more information."; echo; \
rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1)
@rm -f .test.c .test.o .test$(EXEC_SUFFIX)
@@ -777,6 +780,18 @@ ifneq ($(UNSUPPORTED_FEATURES), )
@false
endif
+define LIBUSB1_ERROR_NAME_TEST
+#include <libusb.h>
+int main(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+ libusb_error_name(0);
+ return 0;
+}
+endef
+export LIBUSB1_ERROR_NAME_TEST
+
define FTDI_TEST
#include <ftdi.h>
struct ftdi_context *ftdic = NULL;
@@ -823,6 +838,13 @@ export LINUX_SPI_TEST
features: compiler
@echo "FEATURES := yes" > .features.tmp
+ifeq ($(CHECK_LIBUSB1), yes)
+ @printf "Checking for libusb_error_name support in libusb-1.0... "
+ @echo "$$LIBUSB1_ERROR_NAME_TEST" >> .featuretest.c
+ @$(CC) $(CPPFLAGS) $(FEATURE_CFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(USBLIBS) $(LIBS) >/dev/null 2>&1 && \
+ ( echo "found."; echo "LIBUSB1_ERROR_NAME := yes" >> .features.tmp ) || \
+ ( echo "not found." )
+endif
ifeq ($(NEED_FTDI), yes)
@printf "Checking for FTDI support... "
@echo "$$FTDI_TEST" > .featuretest.c
diff --git a/dediprog.c b/dediprog.c
index ae86810..c33dc10 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -2,6 +2,7 @@
* This file is part of the flashrom project.
*
* Copyright (C) 2010 Carl-Daniel Hailfinger
+ * 2012 secunet Security Networks AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +22,8 @@
#include <string.h>
#include <limits.h>
#include <errno.h>
-#include <usb.h>
+#include <stdlib.h>
+#include <libusb.h>
#include "flash.h"
#include "chipdrivers.h"
#include "programmer.h"
@@ -29,7 +31,8 @@
#define FIRMWARE_VERSION(x,y,z) ((x << 16) | (y << 8) | z)
#define DEFAULT_TIMEOUT 3000
-static usb_dev_handle *dediprog_handle;
+static libusb_context *usb_ctx;
+static libusb_device_handle *dediprog_handle;
static int dediprog_firmwareversion;
static int dediprog_endpoint;
@@ -47,27 +50,63 @@ static void print_hex(void *buf, size_t len)
}
#endif
+#ifndef LIBUSB_HAVE_ERROR_NAME
+/* Quick and dirty replacement for missing libusb_error_name in older libusb 1.0. */
+const char *libusb_error_name(int error_code)
+{
+ /* 18 chars for text, rest for number, sign, nullbyte. */
+ static char my_libusb_error[18 + 3 * sizeof(int) + 2];
+
+ sprintf(my_libusb_error, "libusb error code %i", error_code);
+ return my_libusb_error;
+}
+#endif
+
/* Might be useful for other USB devices as well. static for now. */
/* device parameter allows user to specify one device of multiple installed */
-static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid, unsigned int device)
+static struct libusb_device_handle *get_device_by_vid_pid_number(uint16_t vid, uint16_t pid, unsigned int num)
{
- struct usb_bus *bus;
- struct usb_device *dev;
-
- for (bus = usb_get_busses(); bus; bus = bus->next)
- for (dev = bus->devices; dev; dev = dev->next)
- if ((dev->descriptor.idVendor == vid) &&
- (dev->descriptor.idProduct == pid)) {
- if (device == 0)
- return dev;
- device--;
+ struct libusb_device **list;
+ ssize_t i = 0;
+ int err = 0;
+ struct libusb_device_handle *handle = NULL;
+ struct libusb_device_descriptor desc = {};
+ ssize_t count = libusb_get_device_list(usb_ctx, &list);
+
+ if (count < 0) {
+ msg_perr("Getting the USB device list failed (%s)!\n", libusb_error_name(count));
+ return NULL;
+ }
+
+ for (i = 0; i < count; i++) {
+ struct libusb_device *dev = list[i];
+ err = libusb_get_device_descriptor(dev, &desc);
+ if (err != 0) {
+ msg_perr("Reading the USB device descriptor failed (%s)!\n", libusb_error_name(err));
+ libusb_free_device_list(list, 1);
+ return NULL;
+ }
+ if ((desc.idVendor == vid) && (desc.idProduct == pid)) {
+ msg_pdbg("Found USB device %04hx:%04hx at address %hhx-%hhx.\n", desc.idVendor,
+ desc.idProduct, libusb_get_bus_number(dev), libusb_get_device_address(dev));
+ if (num == 0) {
+ err = libusb_open(dev, &handle);
+ if (err != 0) {
+ msg_perr("Opening the USB device failed (%s)!\n",
+ libusb_error_name(err));
+ libusb_free_device_list(list, 1);
+ return NULL;
+ }
+ break;
}
+ num--;
+ }
+ }
+ libusb_free_device_list(list, 1);
- return NULL;
+ return handle;
}
-//int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);
-
/* Set/clear LEDs on dediprog */
#define PASS_ON (0 << 0)
#define PASS_OFF (1 << 0)
@@ -101,11 +140,10 @@ static int dediprog_set_leds(int leds)
target_leds = leds;
}
- ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, target_leds,
- NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x07, 0x09, target_leds,
+ NULL, 0x0, DEFAULT_TIMEOUT);
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, libusb_error_name(ret));
return 1;
}
@@ -144,8 +182,8 @@ static int dediprog_set_spi_voltage(int millivolt)
/* Wait some time as the original driver does. */
programmer_delay(200 * 1000);
}
- ret = usb_control_msg(dediprog_handle, 0x42, 0x9, voltage_selector,
- 0xff, NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x9, voltage_selector,
+ 0xff, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
msg_perr("Command Set SPI Voltage 0x%x failed!\n",
voltage_selector);
@@ -188,8 +226,8 @@ static int dediprog_set_spi_speed(unsigned int spispeed_idx)
msg_pdbg("SPI speed is %sHz\n", spispeeds[spispeed_idx].name);
- ret = usb_control_msg(dediprog_handle, 0x42, 0x61, spispeeds[spispeed_idx].speed, 0xff,
- NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x61, spispeeds[spispeed_idx].speed, 0xff,
+ NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
msg_perr("Command Set SPI Speed 0x%x failed!\n", spispeeds[spispeed_idx].speed);
return 1;
@@ -205,15 +243,15 @@ static int dediprog_set_spi_speed(unsigned int spispeed_idx)
static int dediprog_spi_bulk_read(struct flashctx *flash, uint8_t *buf,
unsigned int start, unsigned int len)
{
- int ret;
+ int ret, transferred;
unsigned int i;
/* chunksize must be 512, other sizes will NOT work at all. */
const unsigned int chunksize = 0x200;
const unsigned int count = len / chunksize;
- const char count_and_chunk[] = {count & 0xff,
- (count >> 8) & 0xff,
- chunksize & 0xff,
- (chunksize >> 8) & 0xff};
+ const unsigned char count_and_chunk[] = {
+ count & 0xff, (count >> 8) & 0xff,
+ chunksize & 0xff, (chunksize >> 8) & 0xff
+ };
if ((start % chunksize) || (len % chunksize)) {
msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug "
@@ -227,22 +265,20 @@ static int dediprog_spi_bulk_read(struct flashctx *flash, uint8_t *buf,
/* Command Read SPI Bulk. No idea which read command is used on the
* SPI side.
*/
- ret = usb_control_msg(dediprog_handle, 0x42, 0x20, start % 0x10000,
- start / 0x10000, (char *)count_and_chunk,
- sizeof(count_and_chunk), DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x20, start % 0x10000, start / 0x10000,
+ (unsigned char *)count_and_chunk, sizeof(count_and_chunk),
+ DEFAULT_TIMEOUT);
if (ret != sizeof(count_and_chunk)) {
- msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret,
- usb_strerror());
+ msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, libusb_error_name(ret));
return 1;
}
for (i = 0; i < count; i++) {
- ret = usb_bulk_read(dediprog_handle, 0x80 | dediprog_endpoint,
- (char *)buf + i * chunksize, chunksize,
- DEFAULT_TIMEOUT);
- if (ret != chunksize) {
- msg_perr("SPI bulk read %i failed, expected %i, got %i "
- "%s!\n", i, chunksize, ret, usb_strerror());
+ ret = libusb_bulk_transfer(dediprog_handle, 0x80 | dediprog_endpoint,
+ buf + i * chunksize, chunksize, &transferred, DEFAULT_TIMEOUT);
+ if ((ret < 0) || (transferred != chunksize)) {
+ msg_perr("SPI bulk read %i failed, expected %i, got %i %s!\n",
+ i, chunksize, ret, libusb_error_name(ret));
return 1;
}
}
@@ -306,7 +342,7 @@ static int dediprog_spi_read(struct flashctx *flash, uint8_t *buf,
static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigned int chunksize,
unsigned int start, unsigned int len, uint8_t dedi_spi_cmd)
{
- int ret;
+ int ret, transferred;
unsigned int i;
/* USB transfer size must be 512, other sizes will NOT work at all.
* chunksize is the real data size per USB bulk transfer. The remaining
@@ -314,7 +350,7 @@ static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigne
*/
const unsigned int count = len / chunksize;
const char count_and_cmd[] = {count & 0xff, (count >> 8) & 0xff, 0x00, dedi_spi_cmd};
- char usbbuf[512];
+ unsigned char usbbuf[512];
/*
* We should change this check to
@@ -339,23 +375,21 @@ static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigne
/* Command Write SPI Bulk. No idea which write command is used on the
* SPI side.
*/
- ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, start / 0x10000,
- (char *)count_and_cmd, sizeof(count_and_cmd), DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x30, start % 0x10000, start / 0x10000,
+ (unsigned char *)count_and_cmd, sizeof(count_and_cmd), DEFAULT_TIMEOUT);
if (ret != sizeof(count_and_cmd)) {
- msg_perr("Command Write SPI Bulk failed, %i %s!\n", ret,
- usb_strerror());
+ msg_perr("Command Write SPI Bulk failed, %i %s!\n", ret, libusb_error_name(ret));
return 1;
}
for (i = 0; i < count; i++) {
memset(usbbuf, 0xff, sizeof(usbbuf));
memcpy(usbbuf, buf + i * chunksize, chunksize);
- ret = usb_bulk_write(dediprog_handle, dediprog_endpoint,
- usbbuf, 512,
- DEFAULT_TIMEOUT);
- if (ret != 512) {
- msg_perr("SPI bulk write failed, expected %i, got %i "
- "%s!\n", 512, ret, usb_strerror());
+ ret = libusb_bulk_transfer(dediprog_handle, dediprog_endpoint,
+ usbbuf, 512, &transferred, DEFAULT_TIMEOUT);
+ if ((ret < 0) || (transferred != 512)) {
+ msg_perr("SPI bulk write failed, expected %i, got %i %s!\n",
+ 512, ret, libusb_error_name(ret));
return 1;
}
}
@@ -444,23 +478,20 @@ static int dediprog_spi_send_command(struct flashctx *flash,
msg_perr("Untested readcnt=%i, aborting.\n", readcnt);
return 1;
}
-
- ret = usb_control_msg(dediprog_handle, 0x42, 0x1, 0xff,
- readcnt ? 0x1 : 0x0, (char *)writearr, writecnt,
- DEFAULT_TIMEOUT);
+
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x1, 0xff, readcnt ? 0x1 : 0x0,
+ (unsigned char *)writearr, writecnt, DEFAULT_TIMEOUT);
if (ret != writecnt) {
- msg_perr("Send SPI failed, expected %i, got %i %s!\n",
- writecnt, ret, usb_strerror());
+ msg_perr("Send SPI failed, expected %i, got %i %s!\n", writecnt, ret, libusb_error_name(ret));
return 1;
}
if (!readcnt)
return 0;
memset(readarr, 0, readcnt);
- ret = usb_control_msg(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000,
- (char *)readarr, readcnt, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000,
+ readarr, readcnt, DEFAULT_TIMEOUT);
if (ret != readcnt) {
- msg_perr("Receive SPI failed, expected %i, got %i %s!\n",
- readcnt, ret, usb_strerror());
+ msg_perr("Receive SPI failed, expected %i, got %i %s!\n", readcnt, ret, libusb_error_name(ret));
return 1;
}
return 0;
@@ -470,22 +501,18 @@ static int dediprog_check_devicestring(void)
{
int ret;
int fw[3];
- char buf[0x11];
+ unsigned char buf[0x11];
/* Command Prepare Receive Device String. */
memset(buf, 0, sizeof(buf));
- 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. */
- if ((ret != 0x1) || (buf[0] != (char)0xff)) {
- msg_perr("Unexpected response to Command Prepare Receive Device"
- " String!\n");
+ ret = libusb_control_transfer(dediprog_handle, 0xc3, 0x7, 0x0, 0xef03, buf, 0x1, DEFAULT_TIMEOUT);
+ if ((ret != 0x1) || (buf[0] != 0xff)) {
+ msg_perr("Unexpected response to Command Prepare Receive Device String!\n");
return 1;
}
/* Command Receive Device String. */
memset(buf, 0, sizeof(buf));
- ret = usb_control_msg(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf,
- 0x10, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf, 0x10, DEFAULT_TIMEOUT);
if (ret != 0x10) {
msg_perr("Incomplete/failed Command Receive Device String!\n");
return 1;
@@ -496,7 +523,7 @@ static int dediprog_check_devicestring(void)
msg_perr("Device not a SF100!\n");
return 1;
}
- if (sscanf(buf, "SF100 V:%d.%d.%d ", &fw[0], &fw[1], &fw[2]) != 3) {
+ if (sscanf((const char *)buf, "SF100 V:%d.%d.%d ", &fw[0], &fw[1], &fw[2]) != 3) {
msg_perr("Unexpected firmware version string!\n");
return 1;
}
@@ -517,13 +544,12 @@ static int dediprog_check_devicestring(void)
static int dediprog_command_a(void)
{
int ret;
- char buf[0x1];
+ unsigned char buf[0x1];
memset(buf, 0, sizeof(buf));
- ret = usb_control_msg(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf,
- 0x1, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf, 0x1, DEFAULT_TIMEOUT);
if (ret < 0) {
- msg_perr("Command A failed (%s)!\n", usb_strerror());
+ msg_perr("Command A failed (%s)!\n", libusb_error_name(ret));
return 1;
}
if ((ret != 0x1) || (buf[0] != 0x6f)) {
@@ -541,13 +567,12 @@ static int dediprog_command_a(void)
static int dediprog_command_b(void)
{
int ret;
- char buf[0x3];
+ unsigned char buf[0x3];
memset(buf, 0, sizeof(buf));
- ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf,
- 0x3, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf, 0x3, DEFAULT_TIMEOUT);
if (ret < 0) {
- msg_perr("Command B failed (%s)!\n", usb_strerror());
+ msg_perr("Command B failed (%s)!\n", libusb_error_name(ret));
return 1;
}
if ((ret != 0x3) || (buf[0] != 0xff) || (buf[1] != 0xff) ||
@@ -569,10 +594,9 @@ static int dediprog_command_c(void)
{
int ret;
- ret = usb_control_msg(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL,
- 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Command C failed (%s)!\n", usb_strerror());
+ msg_perr("Command C failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -587,17 +611,16 @@ static int dediprog_command_c(void)
static int dediprog_command_f(int timeout)
{
int ret;
- char buf[0x1];
+ unsigned char buf[0x1];
memset(buf, 0, sizeof(buf));
- ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf,
- 0x1, timeout);
+ ret = libusb_control_transfer(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf, 0x1, 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
* success.
*/
if (ret != 0x1) {
- msg_perr("Command F failed (%s)!\n", usb_strerror());
+ msg_perr("Command F failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -611,9 +634,9 @@ static int dediprog_command_g(void)
{
int ret;
- ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x03, NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x07, 0x09, 0x03, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Command G failed (%s)!\n", usb_strerror());
+ msg_perr("Command G failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -628,9 +651,9 @@ static int dediprog_command_h(void)
{
int ret;
- ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x05, NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x07, 0x09, 0x05, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Command H failed (%s)!\n", usb_strerror());
+ msg_perr("Command H failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -645,9 +668,9 @@ static int dediprog_command_i(void)
{
int ret;
- ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x06, NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x07, 0x09, 0x06, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Command I failed (%s)!\n", usb_strerror());
+ msg_perr("Command I failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -665,9 +688,9 @@ static int dediprog_command_j(void)
{
int ret;
- ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x07, NULL, 0x0, DEFAULT_TIMEOUT);
+ ret = libusb_control_transfer(dediprog_handle, 0x42, 0x07, 0x09, 0x07, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Command J failed (%s)!\n", usb_strerror());
+ msg_perr("Command J failed (%s)!\n", libusb_error_name(ret));
return 1;
}
return 0;
@@ -770,21 +793,18 @@ static int dediprog_shutdown(void *data)
if (dediprog_set_spi_voltage(0x0))
return 1;
- if (usb_release_interface(dediprog_handle, 0)) {
+ if (libusb_release_interface(dediprog_handle, 0)) {
msg_perr("Could not release USB interface!\n");
return 1;
}
- if (usb_close(dediprog_handle)) {
- msg_perr("Could not close USB device!\n");
- return 1;
- }
+ libusb_close(dediprog_handle);
+ libusb_exit(usb_ctx);
return 0;
}
/* URB numbers refer to the first log ever captured. */
int dediprog_init(void)
{
- struct usb_device *dev;
char *voltage, *device, *spispeed;
int spispeed_idx = 2;
int millivolt = 3500;
@@ -842,31 +862,29 @@ int dediprog_init(void)
free(device);
/* Here comes the USB stuff. */
- usb_init();
- usb_find_busses();
- usb_find_devices();
- dev = get_device_by_vid_pid(0x0483, 0xdada, (unsigned int) usedevice);
- if (!dev) {
+ libusb_init(&usb_ctx);
+ if (!usb_ctx) {
+ msg_perr("Could not initialize libusb!\n");
+ return 1;
+ }
+ dediprog_handle = get_device_by_vid_pid_number(0x0483, 0xdada, (unsigned int) usedevice);
+ if (!dediprog_handle) {
msg_perr("Could not find a Dediprog SF100 on USB!\n");
+ libusb_exit(usb_ctx);
return 1;
}
- msg_pdbg("Found USB device (%04x:%04x).\n",
- dev->descriptor.idVendor, dev->descriptor.idProduct);
- dediprog_handle = usb_open(dev);
- ret = usb_set_configuration(dediprog_handle, 1);
- if (ret < 0) {
- msg_perr("Could not set USB device configuration: %i %s\n",
- ret, usb_strerror());
- if (usb_close(dediprog_handle))
- msg_perr("Could not close USB device!\n");
+ ret = libusb_set_configuration(dediprog_handle, 1);
+ if (ret != 0) {
+ msg_perr("Could not set USB device configuration: %i %s\n", ret, libusb_error_name(ret));
+ libusb_close(dediprog_handle);
+ libusb_exit(usb_ctx);
return 1;
}
- ret = usb_claim_interface(dediprog_handle, 0);
+ ret = libusb_claim_interface(dediprog_handle, 0);
if (ret < 0) {
- msg_perr("Could not claim USB device interface %i: %i %s\n",
- 0, ret, usb_strerror());
- if (usb_close(dediprog_handle))
- msg_perr("Could not close USB device!\n");
+ msg_perr("Could not claim USB device interface %i: %i %s\n", 0, ret, libusb_error_name(ret));
+ libusb_close(dediprog_handle);
+ libusb_exit(usb_ctx);
return 1;
}
dediprog_endpoint = 2;
--
1.8.1.1
3 years, 10 months
External programmers
by Carl-Daniel Hailfinger
Hi,
I'm trying to find out which external programmers should be supported next.
1. There was talk of an AVR-based new programmer using the serprog
protocol on IRC by someone with the nick "coldelectrons", but I have no
idea if he/she is reading this mail. IMHO more hardware using the
serprog protocol is always a good idea.
2. All those Willem/Sivava variants. People regularly request those, but
I don't think anyone in here owns the hardware.
3. RayeR's SPIPGM. I have a preliminary patch which could work, but I
don't have the hardware. Will send the patch to the list soon.
4. LPC^2, Milksop, CheapLPC and other programmers from the Xbox modding
community.
5. Dozens of SPI programmer hardware projects scattered over the net.
Too many to count, and I'm not sure which of them has more than one user.
In general, it seems creating a new programmer hardware design is like
writing IRC clients: A nice way to get started in the field. I have no
problems merging flashrom support for all of them, but I won't implement
support for all of them myself.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
3 years, 11 months
Re: [flashrom] flashrom on PowerPC
by Stefan Tauner
On Wed, 27 Jul 2011 18:20:19 +0200
Mattias Mattsson <vitplister(a)gmail.com> wrote:
> Hi all,
>
> I was able to run flashrom under Linux on PPC (big endian) hardware
> with two small modifications in internal.c and processor_enable.c (see
> attached patch). Not sure if this is the right way to do it but it
> seems to work for me.
>
i am resending this patch (unchanged) because patchwork did not pick it
up correctly. please do send one patch per mail only in the future
until we have something really working. :)
--
Kind regards/Mit freundlichen Grüßen, Stefan Tauner
4 years
Write-Test for "M25P10-A"
by The Raven
Hello,
this chip is marked as "untested" in write mode.
So here are my test-results:
Erase in d8-Mode is not working (see log).
But i think it's the already known "serprog bug".
Erase in c7-mode is ok.
Write is working in both modes.
But i don't know why in c7-mode the log shows:
0x000000-0x007fff:W, 0x008000-0x00ffff:S, 0x010000-0x017fff:S,
0x018000-0x01ffff:S
I have created the test-file with dd and urandom. The file (131072 byte)
is full with data.
So it should write (W) not only to 0x007fff. Strange!
If you need more logs or infos, let me know.
BTW: The chip is labeled "25P10VP". I see nothing with "-A".
And the chip was found on a "Maxtor" hard disk drive.
4 years, 5 months
Intel Bay Trail read report
by Antonio Ospite
Hi,
I've got a Bay Trail tablet[1] and I tested flashrom on it, see the
attached report.
As reported in [1] I compiled flashrom statically on my host and then
executed it under Android on the target.
Reading the SPI flash works fine, is it safe enough to test writing too?
I ask because accessing the SPI flash physically for external
programming can be a little more inconvenient for a tablet.
Another question: would it be possible to use flashrom to only reset the
firmware _settings_, while leaving the code untouched?
Thanks,
Antonio
[1] http://ao2.it/110
--
Antonio Ospite
http://ao2.it
A: Because it messes up the order in which people normally read text.
See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
4 years, 9 months
[PATCH] Add programmer for the MSTAR I2C ISP protocol
by Alexandre Boeglin
Hi,
Here is a patch, that provides support for the MSTAR ISP protocol.
Basically, among other chips, MSTAR manufactures SoCs that equip TV sets
and computer screens, and it seems that all of their products use the
same in-system programming protocol. Basically, they use the DDC channel
of VGA or DVI connectors, which is actually an I2C bus, to encapsulate
SPI frames (the flash chip is connected to the SoC through an SPI bus).
I wrote this patch since the screen I bought had a software bug, and the
manufacturer only released a new firmware binary, but no tool or
instructions on flashing it.
More details can be found here:
http://boeglin.org/blog/index.php?entry=Flashing-a-BenQ-Z-series-for-free...
I only read code from Linux kernel archives published by Acer to figure
out the protocol (for a touchscreen controller and a NFC chip, both by
MSTAR, that shared the same ISP protocol), so I don't think there are
any legal problems with it.
Please let me know what you think about this patch, and whether you're
interested in including it.
Best regards,
Alex
--
Alexandre Boeglin
email: alex (at) boeglin (dot) org
jabber: alex (at) im (dot) boeglin (dot) org
website: http://boeglin.org/
4 years, 10 months