Changeset 1546
- Timestamp:
- Jun 19, 2012 2:06:53 PM (11 months ago)
- File:
-
- 1 edited
-
trunk/dediprog.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dediprog.c
r1544 r1546 32 32 static int dediprog_endpoint; 33 33 34 #define DEDI_SPI_CMD_PAGEWRITE 0x1 35 #define DEDI_SPI_CMD_AAIWRITE 0x4 36 34 37 #if 0 35 38 /* Might be useful for other pieces of code as well. */ … … 308 311 } 309 312 310 /* Bulk write interface, will write multiple page_size byte chunks aligned to page_size bytes. 311 * @start start address 312 * @len length 313 * @return 0 on success, 1 on failure 314 */ 315 static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, 316 unsigned int start, unsigned int len) 313 /* Bulk write interface, will write multiple chunksize byte chunks aligned to chunksize bytes. 314 * @chunksize length of data chunks, only 256 supported by now 315 * @start start address 316 * @len length 317 * @dedi_spi_cmd dediprog specific write command for spi bus 318 * @return 0 on success, 1 on failure 319 */ 320 static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigned int chunksize, 321 unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) 317 322 { 318 323 int ret; … … 322 327 * space in a USB bulk transfer must be filled with 0xff padding. 323 328 */ 324 const unsigned int chunksize = flash->page_size;325 329 const unsigned int count = len / chunksize; 326 const char count_and_chunk[] = {count & 0xff, 327 (count >> 8) & 0xff, 328 chunksize & 0xff, 329 (chunksize >> 8) & 0xff}; 330 const char count_and_cmd[] = {count & 0xff, (count >> 8) & 0xff, 0x00, dedi_spi_cmd}; 330 331 char usbbuf[512]; 332 333 /* 334 * We should change this check to 335 * chunksize > 512 336 * once we know how to handle different chunk sizes. 337 */ 338 if (chunksize != 256) { 339 msg_perr("%s: Chunk sizes other than 256 bytes are unsupported, chunksize=%u!\n" 340 "Please report a bug at flashrom@flashrom.org\n", __func__, chunksize); 341 return 1; 342 } 331 343 332 344 if ((start % chunksize) || (len % chunksize)) { … … 342 354 * SPI side. 343 355 */ 344 ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, 345 start / 0x10000, (char *)count_and_chunk, 346 sizeof(count_and_chunk), DEFAULT_TIMEOUT); 347 if (ret != sizeof(count_and_chunk)) { 356 ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, start / 0x10000, 357 (char *)count_and_cmd, sizeof(count_and_cmd), DEFAULT_TIMEOUT); 358 if (ret != sizeof(count_and_cmd)) { 348 359 msg_perr("Command Write SPI Bulk failed, %i %s!\n", ret, 349 360 usb_strerror()); … … 367 378 } 368 379 369 static int dediprog_spi_write _256(struct flashctx *flash, uint8_t *buf,370 unsigned int start, unsigned int len)380 static int dediprog_spi_write(struct flashctx *flash, uint8_t *buf, 381 unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) 371 382 { 372 383 int ret; … … 376 387 377 388 dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); 389 390 if (chunksize != 256) { 391 msg_pdbg("Page sizes other than 256 bytes are unsupported as " 392 "we don't know how dediprog\nhandles them.\n"); 393 /* Write everything like it was residue. */ 394 residue = len; 395 } 378 396 379 397 if (residue) { … … 390 408 /* Round down. */ 391 409 bulklen = (len - residue) / chunksize * chunksize; 392 ret = dediprog_spi_bulk_write(flash, buf + residue, start + residue, 393 bulklen); 410 ret = dediprog_spi_bulk_write(flash, buf + residue, chunksize, start + residue, bulklen, dedi_spi_cmd); 394 411 if (ret) { 395 412 dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); … … 411 428 dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); 412 429 return 0; 430 } 431 432 static int dediprog_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 433 { 434 return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_PAGEWRITE); 435 } 436 437 static int dediprog_spi_write_aai(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 438 { 439 return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_AAIWRITE); 413 440 } 414 441 … … 718 745 .read = dediprog_spi_read, 719 746 .write_256 = dediprog_spi_write_256, 720 .write_aai = de fault_spi_write_aai,747 .write_aai = dediprog_spi_write_aai, 721 748 }; 722 749
Note: See TracChangeset
for help on using the changeset viewer.
