Commit dffc800f authored by Qiang Du's avatar Qiang Du

Remove trailing spaces in eb-*.c

parent 360ce693
/** @file eb-info.c /** @file eb-info.c
* @brief Report the contents of an FPGA using Etherbone. * @brief Report the contents of an FPGA using Etherbone.
* *
* Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH * Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH
* *
* A complete skeleton of an application using the Etherbone library. * A complete skeleton of an application using the Etherbone library.
* *
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************* *******************************************************************************
...@@ -69,12 +69,12 @@ int main(int argc, char** argv) { ...@@ -69,12 +69,12 @@ int main(int argc, char** argv) {
eb_data_t rx_data[BATCH_SIZE], tx_data, done; eb_data_t rx_data[BATCH_SIZE], tx_data, done;
eb_cycle_t cycle; eb_cycle_t cycle;
char byte; char byte;
/* Default arguments */ /* Default arguments */
program = argv[0]; program = argv[0];
error = 0; error = 0;
i = -1; i = -1;
/* Process the command-line arguments */ /* Process the command-line arguments */
error = 0; error = 0;
while ((opt = getopt(argc, argv, "i:h")) != -1) { while ((opt = getopt(argc, argv, "i:h")) != -1) {
...@@ -98,24 +98,24 @@ int main(int argc, char** argv) { ...@@ -98,24 +98,24 @@ int main(int argc, char** argv) {
error = 1; error = 1;
} }
} }
if (error) return 1; if (error) return 1;
if (optind + 1 != argc) { if (optind + 1 != argc) {
fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port>\n", program); fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port>\n", program);
return 1; return 1;
} }
if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK) if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK)
die("eb_socket_open", status); die("eb_socket_open", status);
if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK) if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK)
die(argv[optind], status); die(argv[optind], status);
c = sizeof(sdb)/sizeof(struct sdb_device); c = sizeof(sdb)/sizeof(struct sdb_device);
if ((status = eb_sdb_find_by_identity(device, CERN_ID, UART_ID, &sdb[0], &c)) != EB_OK) if ((status = eb_sdb_find_by_identity(device, CERN_ID, UART_ID, &sdb[0], &c)) != EB_OK)
die("eb_sdb_find_by_identity", status); die("eb_sdb_find_by_identity", status);
if (i == -1) { if (i == -1) {
if (c != 1) { if (c != 1) {
fprintf(stderr, "%s: found %d UARTs on that device; pick one with -i #\n", program, c); fprintf(stderr, "%s: found %d UARTs on that device; pick one with -i #\n", program, c);
...@@ -128,11 +128,11 @@ int main(int argc, char** argv) { ...@@ -128,11 +128,11 @@ int main(int argc, char** argv) {
fprintf(stderr, "%s: could not find UART #%d on that device (%d total)\n", program, i, c); fprintf(stderr, "%s: could not find UART #%d on that device (%d total)\n", program, i, c);
exit(1); exit(1);
} }
printf("Connected to uart at address %"PRIx64"\n", sdb[i].sdb_component.addr_first); printf("Connected to uart at address %"PRIx64"\n", sdb[i].sdb_component.addr_first);
tx = sdb[i].sdb_component.addr_first + VUART_TX; tx = sdb[i].sdb_component.addr_first + VUART_TX;
rx = sdb[i].sdb_component.addr_first + VUART_RX; rx = sdb[i].sdb_component.addr_first + VUART_RX;
/* disable input buffering and echo */ /* disable input buffering and echo */
tcgetattr(STDIN_FD, &old); tcgetattr(STDIN_FD, &old);
tcgetattr(STDIN_FD, &tc); tcgetattr(STDIN_FD, &tc);
...@@ -144,29 +144,29 @@ int main(int argc, char** argv) { ...@@ -144,29 +144,29 @@ int main(int argc, char** argv) {
tc.c_cc[VTIME]=0; tc.c_cc[VTIME]=0;
tcflush(STDIN_FD, TCIFLUSH); tcflush(STDIN_FD, TCIFLUSH);
tcsetattr(STDIN_FD, TCSANOW, &tc); tcsetattr(STDIN_FD, TCSANOW, &tc);
flags = fcntl(STDIN_FD, F_GETFL, 0); flags = fcntl(STDIN_FD, F_GETFL, 0);
flags |= O_NONBLOCK; flags |= O_NONBLOCK;
fcntl(STDIN_FD, F_SETFL, flags); fcntl(STDIN_FD, F_SETFL, flags);
/* be lazy and just poll for now */ /* be lazy and just poll for now */
busy = 0; busy = 0;
while (1) { while (1) {
if (!busy) usleep(10000); /* 10ms */ if (!busy) usleep(10000); /* 10ms */
/* Poll for status */ /* Poll for status */
eb_cycle_open(device, 0, eb_block, &cycle); eb_cycle_open(device, 0, eb_block, &cycle);
eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[0]); eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[0]);
eb_cycle_read(cycle, tx, EB_BIG_ENDIAN|EB_DATA32, &done); eb_cycle_read(cycle, tx, EB_BIG_ENDIAN|EB_DATA32, &done);
eb_cycle_close(cycle); eb_cycle_close(cycle);
/* Bulk read anything extra */ /* Bulk read anything extra */
if ((rx_data[0] & 0x100) != 0) { if ((rx_data[0] & 0x100) != 0) {
eb_cycle_open(device, 0, eb_block, &cycle); eb_cycle_open(device, 0, eb_block, &cycle);
for (i = 1; i < BATCH_SIZE; ++i) for (i = 1; i < BATCH_SIZE; ++i)
eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[i]); eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[i]);
eb_cycle_close(cycle); eb_cycle_close(cycle);
for (i = 0; i < BATCH_SIZE; ++i) { for (i = 0; i < BATCH_SIZE; ++i) {
if ((rx_data[i] & 0x100) == 0) continue; if ((rx_data[i] & 0x100) == 0) continue;
byte = rx_data[i] & 0xFF; byte = rx_data[i] & 0xFF;
...@@ -174,9 +174,9 @@ int main(int argc, char** argv) { ...@@ -174,9 +174,9 @@ int main(int argc, char** argv) {
} }
fflush(stdout); fflush(stdout);
} }
busy = busy && (done & 0x100) == 0; busy = busy && (done & 0x100) == 0;
if (!busy && read(STDIN_FD, &byte, 1) == 1) { if (!busy && read(STDIN_FD, &byte, 1) == 1) {
if (byte == 3) { /* control-C */ if (byte == 3) { /* control-C */
tcsetattr(STDIN_FD, TCSANOW, &old); tcsetattr(STDIN_FD, TCSANOW, &old);
...@@ -187,6 +187,6 @@ int main(int argc, char** argv) { ...@@ -187,6 +187,6 @@ int main(int argc, char** argv) {
busy = 1; busy = 1;
} }
} }
return 0; return 0;
} }
/** @file eb-flash.c /** @file eb-flash.c
* @brief Program a flash device using Etherbone. * @brief Program a flash device using Etherbone.
* *
* Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH * Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH
* *
* A complete skeleton of an application using the Etherbone library. * A complete skeleton of an application using the Etherbone library.
* *
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************* *******************************************************************************
...@@ -107,19 +107,19 @@ static void bitmask_set(int offset, int value) { ...@@ -107,19 +107,19 @@ static void bitmask_set(int offset, int value) {
static eb_data_t flip_bits(eb_data_t x) { static eb_data_t flip_bits(eb_data_t x) {
eb_data_t mask; eb_data_t mask;
if (!invert) return x; if (!invert) return x;
/* 0x0F0F */ /* 0x0F0F */
mask = mask_0f;; mask = mask_0f;;
x = ((x >> 4) & mask) | ((x & mask) << 4); x = ((x >> 4) & mask) | ((x & mask) << 4);
/* 0x0F0F -> 0x3333 */ /* 0x0F0F -> 0x3333 */
mask ^= (mask << 2); mask ^= (mask << 2);
x = ((x >> 2) & mask) | ((x & mask) << 2); x = ((x >> 2) & mask) | ((x & mask) << 2);
/* 0x3333 -> 0x5555 */ /* 0x3333 -> 0x5555 */
mask ^= (mask << 1); mask ^= (mask << 1);
x = ((x >> 1) & mask) | ((x & mask) << 1); x = ((x >> 1) & mask) | ((x & mask) << 1);
return x; return x;
} }
...@@ -127,17 +127,17 @@ static eb_status_t erase_sector(eb_device_t device, eb_address_t sector) { ...@@ -127,17 +127,17 @@ static eb_status_t erase_sector(eb_device_t device, eb_address_t sector) {
eb_cycle_t cycle; eb_cycle_t cycle;
eb_format_t control; eb_format_t control;
eb_status_t status; eb_status_t status;
control = (format&EB_ENDIAN_MASK) | EB_DATA32; control = (format&EB_ENDIAN_MASK) | EB_DATA32;
if (old_erase) if (old_erase)
return eb_device_write(device, erase_address, control, sector, 0, eb_block); return eb_device_write(device, erase_address, control, sector, 0, eb_block);
if ((status = eb_cycle_open(device, 0, eb_block, &cycle)) != EB_OK) return status; if ((status = eb_cycle_open(device, 0, eb_block, &cycle)) != EB_OK) return status;
eb_cycle_write(cycle, erase_address, control, 0x6); /* write enable */ eb_cycle_write(cycle, erase_address, control, 0x6); /* write enable */
eb_cycle_write(cycle, erase_address, control, 0x80000000); /* execute */ eb_cycle_write(cycle, erase_address, control, 0x80000000); /* execute */
eb_cycle_write(cycle, erase_address, control, 0xD8); /* sector erase */ eb_cycle_write(cycle, erase_address, control, 0xD8); /* sector erase */
if (((erase_address-address) >> 24) != 0) if (((erase_address-address) >> 24) != 0)
eb_cycle_write(cycle, erase_address, control, (sector >> 24) & 0xFF); eb_cycle_write(cycle, erase_address, control, (sector >> 24) & 0xFF);
eb_cycle_write(cycle, erase_address, control, (sector >> 16) & 0xFF); eb_cycle_write(cycle, erase_address, control, (sector >> 16) & 0xFF);
eb_cycle_write(cycle, erase_address, control, (sector >> 8) & 0xFF); eb_cycle_write(cycle, erase_address, control, (sector >> 8) & 0xFF);
...@@ -150,13 +150,13 @@ static void wait_for_busy(eb_device_t device, long interval) { ...@@ -150,13 +150,13 @@ static void wait_for_busy(eb_device_t device, long interval) {
long delay, used; long delay, used;
eb_status_t status; eb_status_t status;
eb_data_t result; eb_data_t result;
do { do {
/* Sleep as requested */ /* Sleep as requested */
for (delay = interval; delay > 0; delay -= used) { for (delay = interval; delay > 0; delay -= used) {
used = eb_socket_run(eb_device_socket(device), delay); used = eb_socket_run(eb_device_socket(device), delay);
} }
result = 0; result = 0;
status = eb_device_read(device, erase_address, (format&EB_ENDIAN_MASK)|EB_DATA32, &result, 0, eb_block); status = eb_device_read(device, erase_address, (format&EB_ENDIAN_MASK)|EB_DATA32, &result, 0, eb_block);
if (status != EB_OK && status != EB_SEGFAULT) { if (status != EB_OK && status != EB_SEGFAULT) {
...@@ -169,23 +169,23 @@ static void wait_for_busy(eb_device_t device, long interval) { ...@@ -169,23 +169,23 @@ static void wait_for_busy(eb_device_t device, long interval) {
static void find_sector_size(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) { static void find_sector_size(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) {
eb_address_t* sector_size = (eb_address_t*)user; eb_address_t* sector_size = (eb_address_t*)user;
eb_address_t result; eb_address_t result;
if (status != EB_OK) { if (status != EB_OK) {
fprintf(stderr, "%s: pattern read failed: %s\n", program, eb_status(status)); fprintf(stderr, "%s: pattern read failed: %s\n", program, eb_status(status));
exit(1); exit(1);
} }
result = page_size; result = page_size;
for (; op != EB_NULL; op = eb_operation_next(op)) { for (; op != EB_NULL; op = eb_operation_next(op)) {
if (eb_operation_had_error(op)) { if (eb_operation_had_error(op)) {
fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n", fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n",
program, program,
eb_width_data(eb_operation_format(op)), eb_width_data(eb_operation_format(op)),
eb_format_endian(eb_operation_format(op)), eb_format_endian(eb_operation_format(op)),
eb_operation_address(op)); eb_operation_address(op));
exit(1); exit(1);
} }
/* If the data is 0, then it was erased */ /* If the data is 0, then it was erased */
if (eb_operation_data(op) != 0) { if (eb_operation_data(op) != 0) {
result <<= 1; result <<= 1;
...@@ -193,7 +193,7 @@ static void find_sector_size(eb_user_data_t user, eb_device_t dev, eb_operation_ ...@@ -193,7 +193,7 @@ static void find_sector_size(eb_user_data_t user, eb_device_t dev, eb_operation_
break; break;
} }
} }
*sector_size = result; *sector_size = result;
} }
...@@ -204,7 +204,7 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -204,7 +204,7 @@ static eb_address_t detect_sector_size(eb_device_t device) {
eb_address_t end; eb_address_t end;
eb_status_t status; eb_status_t status;
eb_cycle_t cycle; eb_cycle_t cycle;
/* Plan: /* Plan:
* 0- Find largest possible sector that fits between start and end * 0- Find largest possible sector that fits between start and end
* 1- Write 0s at positions 2^x-1 inside that sector * 1- Write 0s at positions 2^x-1 inside that sector
...@@ -212,16 +212,16 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -212,16 +212,16 @@ static eb_address_t detect_sector_size(eb_device_t device) {
* 3- Read the values at all the addresses that were zeroed. * 3- Read the values at all the addresses that were zeroed.
* 4- The last non-zero seen determines the sector size * 4- The last non-zero seen determines the sector size
*/ */
if (!quiet) { if (!quiet) {
printf("Autodetecting sector size ... "); printf("Autodetecting sector size ... ");
fflush(stdout); fflush(stdout);
} }
/* Find largest sector that fits by aligning target */ /* Find largest sector that fits by aligning target */
end = address + firmware_length-1; end = address + firmware_length-1;
target = address + firmware_length/2; target = address + firmware_length/2;
sector_size = page_size; sector_size = page_size;
target &= ~(sector_size-1); target &= ~(sector_size-1);
while (address <= target && target+sector_size-1 <= end) { while (address <= target && target+sector_size-1 <= end) {
...@@ -229,10 +229,10 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -229,10 +229,10 @@ static eb_address_t detect_sector_size(eb_device_t device) {
target &= ~(sector_size-1); target &= ~(sector_size-1);
if (sector_size >= MAX_SECTOR_SIZE) break; /* faster */ if (sector_size >= MAX_SECTOR_SIZE) break; /* faster */
} }
max_size = sector_size >> 1; max_size = sector_size >> 1;
target = (address + firmware_length/2) & ~(max_size-1); target = (address + firmware_length/2) & ~(max_size-1);
/* Start writing test pattern */ /* Start writing test pattern */
for (sector_size = page_size; sector_size < max_size; sector_size <<= 1) { for (sector_size = page_size; sector_size < max_size; sector_size <<= 1) {
if (!quiet) { if (!quiet) {
...@@ -246,7 +246,7 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -246,7 +246,7 @@ static eb_address_t detect_sector_size(eb_device_t device) {
} }
wait_for_busy(device, 0); wait_for_busy(device, 0);
} }
if (!quiet) { if (!quiet) {
printf("\rAutodetecting sector size: erasing 0x%"EB_ADDR_FMT" ... ", target); printf("\rAutodetecting sector size: erasing 0x%"EB_ADDR_FMT" ... ", target);
fflush(stdout); fflush(stdout);
...@@ -255,9 +255,9 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -255,9 +255,9 @@ static eb_address_t detect_sector_size(eb_device_t device) {
fprintf(stderr, "\r%s: failed to erase test sector 0x%"EB_ADDR_FMT": %s\n", program, target, eb_status(status)); fprintf(stderr, "\r%s: failed to erase test sector 0x%"EB_ADDR_FMT": %s\n", program, target, eb_status(status));
exit(1); exit(1);
} }
wait_for_busy(device, wait_us); wait_for_busy(device, wait_us);
if (!quiet) { if (!quiet) {
printf("\rAutodetecting sector size: scanning ... "); printf("\rAutodetecting sector size: scanning ... ");
fflush(stdout); fflush(stdout);
...@@ -266,43 +266,43 @@ static eb_address_t detect_sector_size(eb_device_t device) { ...@@ -266,43 +266,43 @@ static eb_address_t detect_sector_size(eb_device_t device) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
exit(1); exit(1);
} }
for (sector_size = page_size; sector_size < max_size; sector_size <<= 1) { for (sector_size = page_size; sector_size < max_size; sector_size <<= 1) {
eb_cycle_read(cycle, target+sector_size, format, 0); eb_cycle_read(cycle, target+sector_size, format, 0);
} }
sector_size = 0; sector_size = 0;
eb_cycle_close(cycle); eb_cycle_close(cycle);
while (sector_size == 0) { while (sector_size == 0) {
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
if (!quiet) { if (!quiet) {
printf("\rAutodetecting sector size: found = 0x%"EB_ADDR_FMT"\n", sector_size); printf("\rAutodetecting sector size: found = 0x%"EB_ADDR_FMT"\n", sector_size);
} }
return sector_size; return sector_size;
} }
static void detect_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) { static void detect_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) {
int* counter = (int*)user; int* counter = (int*)user;
--*counter; --*counter;
if (status != EB_OK) { if (status != EB_OK) {
fprintf(stderr, "%s: scan operation failed: %s\n", program, eb_status(status)); fprintf(stderr, "%s: scan operation failed: %s\n", program, eb_status(status));
exit(1); exit(1);
} }
for (; op != EB_NULL; op = eb_operation_next(op)) { for (; op != EB_NULL; op = eb_operation_next(op)) {
if (eb_operation_had_error(op)) { if (eb_operation_had_error(op)) {
fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n", fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n",
program, program,
eb_width_data(eb_operation_format(op)), eb_width_data(eb_operation_format(op)),
eb_format_endian(eb_operation_format(op)), eb_format_endian(eb_operation_format(op)),
eb_operation_address(op)); eb_operation_address(op));
exit(1); exit(1);
} }
/* If the data is not FFFFFF, then set the bit indicating we must erase it */ /* If the data is not FFFFFF, then set the bit indicating we must erase it */
if (eb_operation_data(op) != ffs) { if (eb_operation_data(op) != ffs) {
bitmask_set((eb_operation_address(op) - address) / sector_size, 1); bitmask_set((eb_operation_address(op) - address) / sector_size, 1);
...@@ -323,55 +323,55 @@ static void quick_scan_gap(eb_device_t device, eb_address_t offset, eb_address_t ...@@ -323,55 +323,55 @@ static void quick_scan_gap(eb_device_t device, eb_address_t offset, eb_address_t
int size; int size;
int ops; int ops;
int inflight; int inflight;
size = format & EB_DATAX; size = format & EB_DATAX;
ops = 0; ops = 0;
inflight = 0; inflight = 0;
if ((status = eb_cycle_open(device, &inflight, detect_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, detect_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
first_sector = (address/sector_size) * sector_size; first_sector = (address/sector_size) * sector_size;
last_sector = ((address+firmware_length+sector_size-1)/sector_size)*sector_size; last_sector = ((address+firmware_length+sector_size-1)/sector_size)*sector_size;
i = 0; i = 0;
for (sector = first_sector; sector != last_sector; sector += sector_size) { for (sector = first_sector; sector != last_sector; sector += sector_size) {
if (bitmask_get(i++)) continue; if (bitmask_get(i++)) continue;
last_position = sector+offset+len; last_position = sector+offset+len;
for (position = sector+offset; position != last_position; position += size) { for (position = sector+offset; position != last_position; position += size) {
eb_cycle_read(cycle, position, format, 0); eb_cycle_read(cycle, position, format, 0);
if (!quiet && (++scan_count % 65536) == 0) { if (!quiet && (++scan_count % 65536) == 0) {
scan_count = 0; scan_count = 0;
printf("\rScanning offset 0x%"EB_ADDR_FMT" ... ", position); printf("\rScanning offset 0x%"EB_ADDR_FMT" ... ", position);
fflush(stdout); fflush(stdout);
} }
/* use the same number of operations per cycle as programming/verifying */ /* use the same number of operations per cycle as programming/verifying */
if (++ops == (page_size/size)) { if (++ops == (page_size/size)) {
ops = 0; ops = 0;
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
if ((status = eb_cycle_open(device, &inflight, detect_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, detect_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
while (inflight >= cycles_per_poll) while (inflight >= cycles_per_poll)
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
} }
} }
if (ops > 0) { if (ops > 0) {
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
} else { } else {
eb_cycle_abort(cycle); eb_cycle_abort(cycle);
} }
while (inflight > 0) { while (inflight > 0) {
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
...@@ -379,20 +379,20 @@ static void quick_scan_gap(eb_device_t device, eb_address_t offset, eb_address_t ...@@ -379,20 +379,20 @@ static void quick_scan_gap(eb_device_t device, eb_address_t offset, eb_address_t
static void quick_scan(eb_device_t device) { static void quick_scan(eb_device_t device) {
eb_address_t offset, gap; eb_address_t offset, gap;
if (!quiet) { if (!quiet) {
printf("Scanning flash ... "); printf("Scanning flash ... ");
fflush(stdout); fflush(stdout);
} }
gap = 8; gap = 8;
scan_count = 0; scan_count = 0;
quick_scan_gap(device, 0, gap); quick_scan_gap(device, 0, gap);
for (offset = gap; offset != sector_size; offset += gap, gap += gap) { for (offset = gap; offset != sector_size; offset += gap, gap += gap) {
quick_scan_gap(device, offset, gap); quick_scan_gap(device, offset, gap);
} }
if (!quiet) printf("done!\n"); if (!quiet) printf("done!\n");
} }
...@@ -404,45 +404,45 @@ static void erase_flash(eb_device_t device) { ...@@ -404,45 +404,45 @@ static void erase_flash(eb_device_t device) {
int i; int i;
first_sector = (address/sector_size) * sector_size; first_sector = (address/sector_size) * sector_size;
last_sector = ((address+firmware_length+sector_size-1)/sector_size)*sector_size; last_sector = ((address+firmware_length+sector_size-1)/sector_size)*sector_size;
if (!quiet) if (!quiet)
printf("Erasing flash ... "); printf("Erasing flash ... ");
i = 0; i = 0;
for (sector = first_sector; sector != last_sector; sector += sector_size) { for (sector = first_sector; sector != last_sector; sector += sector_size) {
if (!quiet) { if (!quiet) {
printf("\rErasing 0x%"EB_ADDR_FMT" ... ", sector); printf("\rErasing 0x%"EB_ADDR_FMT" ... ", sector);
fflush(stdout); fflush(stdout);
} }
if (!bitmask_get(i++)) continue; if (!bitmask_get(i++)) continue;
if ((status = erase_sector(device, sector)) != EB_OK) { if ((status = erase_sector(device, sector)) != EB_OK) {
fprintf(stderr, "\r%s: failed to erase 0x%"EB_ADDR_FMT": %s\n", program, sector, eb_status(status)); fprintf(stderr, "\r%s: failed to erase 0x%"EB_ADDR_FMT": %s\n", program, sector, eb_status(status));
exit(1); exit(1);
} }
wait_for_busy(device, wait_us); wait_for_busy(device, wait_us);
} }
if (!quiet) printf("done!\n"); if (!quiet) printf("done!\n");
} }
static void program_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) { static void program_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_t op, eb_status_t status) {
int* counter = (int*)user; int* counter = (int*)user;
--*counter; --*counter;
if (status != EB_OK) { if (status != EB_OK) {
fprintf(stderr, "%s: program operation failed: %s\n", program, eb_status(status)); fprintf(stderr, "%s: program operation failed: %s\n", program, eb_status(status));
exit(1); exit(1);
} }
for (; op != EB_NULL; op = eb_operation_next(op)) { for (; op != EB_NULL; op = eb_operation_next(op)) {
if (eb_operation_had_error(op)) { if (eb_operation_had_error(op)) {
fprintf(stderr, "%s: wishbone segfault writing %s %s bits to address 0x%"EB_ADDR_FMT"\n", fprintf(stderr, "%s: wishbone segfault writing %s %s bits to address 0x%"EB_ADDR_FMT"\n",
program, program,
eb_width_data(eb_operation_format(op)), eb_width_data(eb_operation_format(op)),
eb_format_endian(eb_operation_format(op)), eb_format_endian(eb_operation_format(op)),
eb_operation_address(op)); eb_operation_address(op));
exit(1); exit(1);
} }
...@@ -466,20 +466,20 @@ static void program_flash(eb_device_t device) { ...@@ -466,20 +466,20 @@ static void program_flash(eb_device_t device) {
ops = 0; ops = 0;
inflight = 0; inflight = 0;
may_skip_ffs = 1; may_skip_ffs = 1;
if (!quiet) printf("Programming flash ... "); if (!quiet) printf("Programming flash ... ");
if ((status = eb_cycle_open(device, &inflight, program_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, program_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
stop_offset = address + firmware_length; stop_offset = address + firmware_length;
for (offset = address; offset != stop_offset; offset += size) { for (offset = address; offset != stop_offset; offset += size) {
if (fread(buf, 1, size, firmware_f) != size) { if (fread(buf, 1, size, firmware_f) != size) {
fprintf(stderr, "\r%s: short read from '%s'\n", program, firmware); fprintf(stderr, "\r%s: short read from '%s'\n", program, firmware);
exit(1); exit(1);
} }
data = 0; data = 0;
if ((format & EB_ENDIAN_MASK) == EB_BIG_ENDIAN) { if ((format & EB_ENDIAN_MASK) == EB_BIG_ENDIAN) {
for (byte = 0; byte < size; ++byte) { for (byte = 0; byte < size; ++byte) {
...@@ -492,58 +492,58 @@ static void program_flash(eb_device_t device) { ...@@ -492,58 +492,58 @@ static void program_flash(eb_device_t device) {
data |= buf[byte]; data |= buf[byte];
} }
} }
if (!quiet && offset % 65536 == 0) { if (!quiet && offset % 65536 == 0) {
printf("\rProgramming 0x%"EB_ADDR_FMT"... ", offset); printf("\rProgramming 0x%"EB_ADDR_FMT"... ", offset);
fflush(stdout); fflush(stdout);
} }
/* Don't write pages of FFs; skip them */ /* Don't write pages of FFs; skip them */
if (may_skip_ffs && data == ffs) { if (may_skip_ffs && data == ffs) {
continue; continue;
} }
if (offset == erase_address) { if (offset == erase_address) {
if (!quiet) if (!quiet)
fprintf(stderr, "\r%s: warning: firmware tried to write to erase address!\n", program); fprintf(stderr, "\r%s: warning: firmware tried to write to erase address!\n", program);
continue; continue;
} }
/* Flip bits in the bytes? */ /* Flip bits in the bytes? */
data = flip_bits(data); data = flip_bits(data);
eb_cycle_write(cycle, offset, format, data); eb_cycle_write(cycle, offset, format, data);
may_skip_ffs = 0; may_skip_ffs = 0;
++ops; ++ops;
/* Align cycles to page boundaries */ /* Align cycles to page boundaries */
if ((offset+size) % page_size == 0) { if ((offset+size) % page_size == 0) {
ops = 0; ops = 0;
may_skip_ffs = 1; may_skip_ffs = 1;
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
if ((status = eb_cycle_open(device, &inflight, program_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, program_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
while (inflight >= cycles_per_poll) while (inflight >= cycles_per_poll)
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
} }
if (ops > 0) { if (ops > 0) {
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
} else { } else {
eb_cycle_abort(cycle); eb_cycle_abort(cycle);
} }
while (inflight > 0) { while (inflight > 0) {
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
if (!quiet) printf("done!\n"); if (!quiet) printf("done!\n");
} }
...@@ -554,35 +554,35 @@ static void verify_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_ ...@@ -554,35 +554,35 @@ static void verify_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_
int byte, size; int byte, size;
int* counter = (int*)user; int* counter = (int*)user;
--*counter; --*counter;
if (status != EB_OK) { if (status != EB_OK) {
fprintf(stderr, "%s: verify operation failed: %s\n", program, eb_status(status)); fprintf(stderr, "%s: verify operation failed: %s\n", program, eb_status(status));
exit(1); exit(1);
} }
for (; op != EB_NULL; op = eb_operation_next(op)) { for (; op != EB_NULL; op = eb_operation_next(op)) {
if (eb_operation_had_error(op)) { if (eb_operation_had_error(op)) {
fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n", fprintf(stderr, "%s: wishbone segfault reading %s %s bits from address 0x%"EB_ADDR_FMT"\n",
program, program,
eb_width_data(eb_operation_format(op)), eb_width_data(eb_operation_format(op)),
eb_format_endian(eb_operation_format(op)), eb_format_endian(eb_operation_format(op)),
eb_operation_address(op)); eb_operation_address(op));
exit(1); exit(1);
} }
if (last_offset != eb_operation_address(op)) { if (last_offset != eb_operation_address(op)) {
last_offset = eb_operation_address(op); last_offset = eb_operation_address(op);
fseeko(firmware_f, last_offset-address, SEEK_SET); fseeko(firmware_f, last_offset-address, SEEK_SET);
} }
size = eb_operation_format(op) & EB_DATAX; size = eb_operation_format(op) & EB_DATAX;
if (fread(buf, 1, size, firmware_f) != size) { if (fread(buf, 1, size, firmware_f) != size) {
fprintf(stderr, "\r%s: short verify read from '%s'\n", program, firmware); fprintf(stderr, "\r%s: short verify read from '%s'\n", program, firmware);
exit(1); exit(1);
} }
last_offset += size; last_offset += size;
data = 0; data = 0;
if ((format & EB_ENDIAN_MASK) == EB_BIG_ENDIAN) { if ((format & EB_ENDIAN_MASK) == EB_BIG_ENDIAN) {
for (byte = 0; byte < size; ++byte) { for (byte = 0; byte < size; ++byte) {
...@@ -595,9 +595,9 @@ static void verify_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_ ...@@ -595,9 +595,9 @@ static void verify_decrement(eb_user_data_t user, eb_device_t dev, eb_operation_
data |= buf[byte]; data |= buf[byte];
} }
} }
data = flip_bits(data); data = flip_bits(data);
if (eb_operation_data(op) != data) { if (eb_operation_data(op) != data) {
fprintf(stderr, "%s: verify failed at address 0x%"EB_ADDR_FMT" (0x%"EB_DATA_FMT" != 0x%"EB_DATA_FMT")\n", fprintf(stderr, "%s: verify failed at address 0x%"EB_ADDR_FMT" (0x%"EB_DATA_FMT" != 0x%"EB_DATA_FMT")\n",
program, eb_operation_address(op), eb_operation_data(op), data); program, eb_operation_address(op), eb_operation_data(op), data);
...@@ -618,48 +618,48 @@ static void verify_flash(eb_device_t device) { ...@@ -618,48 +618,48 @@ static void verify_flash(eb_device_t device) {
size = format & EB_DATAX; size = format & EB_DATAX;
ops = 0; ops = 0;
inflight = 0; inflight = 0;
if (!quiet) printf("Verifying flash ... "); if (!quiet) printf("Verifying flash ... ");
if ((status = eb_cycle_open(device, &inflight, verify_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, verify_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
stop_offset = address + firmware_length; stop_offset = address + firmware_length;
for (offset = address; offset != stop_offset; offset += size) { for (offset = address; offset != stop_offset; offset += size) {
if (offset % 65536 == 0) { if (offset % 65536 == 0) {
if (!quiet) printf("\rVerifying 0x%"EB_ADDR_FMT"... ", offset); if (!quiet) printf("\rVerifying 0x%"EB_ADDR_FMT"... ", offset);
fflush(stdout); fflush(stdout);
} }
eb_cycle_read(cycle, offset, format, 0); eb_cycle_read(cycle, offset, format, 0);
++ops; ++ops;
if ((offset+size) % page_size == 0) { if ((offset+size) % page_size == 0) {
ops = 0; ops = 0;
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
if ((status = eb_cycle_open(device, &inflight, verify_decrement, &cycle)) != EB_OK) { if ((status = eb_cycle_open(device, &inflight, verify_decrement, &cycle)) != EB_OK) {
fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status)); fprintf(stderr, "\r%s: could not create cycle: %s\n", program, eb_status(status));
} }
while (inflight >= cycles_per_poll) while (inflight >= cycles_per_poll)
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
} }
if (ops > 0) { if (ops > 0) {
++inflight; ++inflight;
eb_cycle_close(cycle); eb_cycle_close(cycle);
} else { } else {
eb_cycle_abort(cycle); eb_cycle_abort(cycle);
} }
while (inflight > 0) { while (inflight > 0) {
eb_socket_run(eb_device_socket(device), -1); eb_socket_run(eb_device_socket(device), -1);
} }
if (!quiet) printf("done!\n"); if (!quiet) printf("done!\n");
} }
...@@ -667,13 +667,13 @@ int main(int argc, char** argv) { ...@@ -667,13 +667,13 @@ int main(int argc, char** argv) {
long value; long value;
char* value_end; char* value_end;
int opt, error, i; int opt, error, i;
eb_socket_t socket; eb_socket_t socket;
eb_status_t status; eb_status_t status;
eb_device_t device; eb_device_t device;
eb_width_t line_width; eb_width_t line_width;
eb_width_t device_support; eb_width_t device_support;
/* Default arguments */ /* Default arguments */
program = argv[0]; program = argv[0];
address = 0; address = 0;
...@@ -694,7 +694,7 @@ int main(int argc, char** argv) { ...@@ -694,7 +694,7 @@ int main(int argc, char** argv) {
invert = -1; /* auto */ invert = -1; /* auto */
verbose = 0; verbose = 0;
quiet = 0; quiet = 0;
/* Process the command-line arguments */ /* Process the command-line arguments */
error = 0; error = 0;
while ((opt = getopt(argc, argv, "t:e:a:d:bli:s:w:c:r:fpnvqh")) != -1) { while ((opt = getopt(argc, argv, "t:e:a:d:bli:s:w:c:r:fpnvqh")) != -1) {
...@@ -804,50 +804,50 @@ int main(int argc, char** argv) { ...@@ -804,50 +804,50 @@ int main(int argc, char** argv) {
error = 1; error = 1;
} }
} }
if (error) return 1; if (error) return 1;
if (optind + 2 != argc) { if (optind + 2 != argc) {
fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port> <firmware>\n", program); fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port> <firmware>\n", program);
return 1; return 1;
} }
device_address = argv[optind]; device_address = argv[optind];
firmware = argv[optind+1]; firmware = argv[optind+1];
if ((firmware_f = fopen(firmware, "r")) == 0) { if ((firmware_f = fopen(firmware, "r")) == 0) {
fprintf(stderr, "%s: fopen, %s -- '%s'\n", fprintf(stderr, "%s: fopen, %s -- '%s'\n",
program, strerror(errno), firmware); program, strerror(errno), firmware);
return 1; return 1;
} }
if (fseeko(firmware_f, 0, SEEK_END) != 0) { if (fseeko(firmware_f, 0, SEEK_END) != 0) {
fprintf(stderr, "%s: fseeko, %s -- '%s'\n", fprintf(stderr, "%s: fseeko, %s -- '%s'\n",
program, strerror(errno), firmware); program, strerror(errno), firmware);
return 1; return 1;
} }
firmware_length = ftello(firmware_f); firmware_length = ftello(firmware_f);
fseeko(firmware_f, 0, SEEK_SET); fseeko(firmware_f, 0, SEEK_SET);
if (firmware_length % page_size != 0) { if (firmware_length % page_size != 0) {
fprintf(stderr, "%s: invalid firmware image -- '%s'; must be aligned to a %d-byte page\n", fprintf(stderr, "%s: invalid firmware image -- '%s'; must be aligned to a %d-byte page\n",
program, firmware, (int)page_size); program, firmware, (int)page_size);
return 1; return 1;
} }
erase_bitmap_size = firmware_length / page_size / 8; erase_bitmap_size = firmware_length / page_size / 8;
erase_bitmap = (uint8_t*)calloc(erase_bitmap_size, 1); erase_bitmap = (uint8_t*)calloc(erase_bitmap_size, 1);
if (!erase_bitmap) { if (!erase_bitmap) {
fprintf(stderr, "%s: could not allocate erase bitmap (%d bytes)\n", fprintf(stderr, "%s: could not allocate erase bitmap (%d bytes)\n",
program, erase_bitmap_size); program, erase_bitmap_size);
return 1; return 1;
} }
if (verbose) if (verbose)
printf("Opened '%s' with 0x%"EB_ADDR_FMT" bytes of data\n", firmware, firmware_length); printf("Opened '%s' with 0x%"EB_ADDR_FMT" bytes of data\n", firmware, firmware_length);
if (invert == -1) { if (invert == -1) {
if (strlen(firmware) > 4 && !strcmp(firmware+strlen(firmware)-4, ".rpd")) { if (strlen(firmware) > 4 && !strcmp(firmware+strlen(firmware)-4, ".rpd")) {
invert = 1; invert = 1;
...@@ -857,33 +857,33 @@ int main(int argc, char** argv) { ...@@ -857,33 +857,33 @@ int main(int argc, char** argv) {
if (verbose) if (verbose)
printf(" based on filename, WILL%s invert bits within bytes\n", invert?"":" NOT"); printf(" based on filename, WILL%s invert bits within bytes\n", invert?"":" NOT");
} }
if (verbose) if (verbose)
fprintf(stdout, "Opening socket with %s-bit address and %s-bit data widths\n", fprintf(stdout, "Opening socket with %s-bit address and %s-bit data widths\n",
eb_width_address(address_width), eb_width_data(data_width)); eb_width_address(address_width), eb_width_data(data_width));
if ((status = eb_socket_open(EB_ABI_CODE, 0, address_width|data_width, &socket)) != EB_OK) { if ((status = eb_socket_open(EB_ABI_CODE, 0, address_width|data_width, &socket)) != EB_OK) {
fprintf(stderr, "%s: failed to open Etherbone socket: %s\n", program, eb_status(status)); fprintf(stderr, "%s: failed to open Etherbone socket: %s\n", program, eb_status(status));
return 1; return 1;
} }
if (verbose) if (verbose)
fprintf(stdout, "Connecting to '%s' with %d retry attempts...\n", device_address, retries); fprintf(stdout, "Connecting to '%s' with %d retry attempts...\n", device_address, retries);
if ((status = eb_device_open(socket, device_address, EB_ADDRX|EB_DATAX, retries, &device)) != EB_OK) { if ((status = eb_device_open(socket, device_address, EB_ADDRX|EB_DATAX, retries, &device)) != EB_OK) {
fprintf(stderr, "%s: failed to open Etherbone device: %s\n", program, eb_status(status)); fprintf(stderr, "%s: failed to open Etherbone device: %s\n", program, eb_status(status));
return 1; return 1;
} }
line_width = eb_device_width(device); line_width = eb_device_width(device);
if (verbose) if (verbose)
fprintf(stdout, " negotiated %s-bit address and %s-bit data session.\n", fprintf(stdout, " negotiated %s-bit address and %s-bit data session.\n",
eb_width_address(line_width), eb_width_data(line_width)); eb_width_address(line_width), eb_width_data(line_width));
if (probe) { if (probe) {
struct sdb_device info; struct sdb_device info;
int num; int num;
if (verbose) if (verbose)
fprintf(stdout, "Scanning remote bus for Wishbone devices...\n"); fprintf(stdout, "Scanning remote bus for Wishbone devices...\n");
...@@ -901,7 +901,7 @@ int main(int argc, char** argv) { ...@@ -901,7 +901,7 @@ int main(int argc, char** argv) {
fprintf(stderr, "%s: found %d flash devices -- choose one with '-t'.\n", program, num); fprintf(stderr, "%s: found %d flash devices -- choose one with '-t'.\n", program, num);
return 1; return 1;
} }
address = info.sdb_component.addr_first; address = info.sdb_component.addr_first;
address_set = 1; address_set = 1;
if (verbose) if (verbose)
...@@ -912,20 +912,20 @@ int main(int argc, char** argv) { ...@@ -912,20 +912,20 @@ int main(int argc, char** argv) {
return 1; return 1;
} }
} }
if ((info.bus_specific & SDB_WISHBONE_LITTLE_ENDIAN) != 0) if ((info.bus_specific & SDB_WISHBONE_LITTLE_ENDIAN) != 0)
device_support = EB_LITTLE_ENDIAN; device_support = EB_LITTLE_ENDIAN;
else else
device_support = EB_BIG_ENDIAN; device_support = EB_BIG_ENDIAN;
device_support |= info.bus_specific & EB_DATAX; device_support |= info.bus_specific & EB_DATAX;
if (!erase_address_set) { if (!erase_address_set) {
erase_address = info.sdb_component.addr_last-3; erase_address = info.sdb_component.addr_last-3;
erase_address_set = 1; erase_address_set = 1;
if (verbose) if (verbose)
fprintf(stdout, " using 0x%"EB_ADDR_FMT" as erase register\n", erase_address); fprintf(stdout, " using 0x%"EB_ADDR_FMT" as erase register\n", erase_address);
} }
if (info.abi_ver_major == 1 && info.abi_ver_minor == 0) { if (info.abi_ver_major == 1 && info.abi_ver_minor == 0) {
if (!quiet) fprintf(stderr, "warning: old flash firmware detected! (falling back to slow erase)\n"); if (!quiet) fprintf(stderr, "warning: old flash firmware detected! (falling back to slow erase)\n");
if (wait_us < 4000000) { if (wait_us < 4000000) {
...@@ -941,43 +941,43 @@ int main(int argc, char** argv) { ...@@ -941,43 +941,43 @@ int main(int argc, char** argv) {
} else { } else {
device_support = endian | EB_DATAX; device_support = endian | EB_DATAX;
} }
/* If unset by user and SDB */ /* If unset by user and SDB */
if (!address_set) { if (!address_set) {
fprintf(stderr, "%s: could not auto-detect target flash address\n", program); fprintf(stderr, "%s: could not auto-detect target flash address\n", program);
return 1; return 1;
} }
if (!erase_address_set) { if (!erase_address_set) {
fprintf(stderr, "%s: could not auto-detect erase register address\n", program); fprintf(stderr, "%s: could not auto-detect erase register address\n", program);
return 1; return 1;
} }
if (address % page_size != 0) { if (address % page_size != 0) {
fprintf(stderr, "%s: invalid target address -- 0x%"EB_ADDR_FMT"; must be aligned to a %d-byte page\n", fprintf(stderr, "%s: invalid target address -- 0x%"EB_ADDR_FMT"; must be aligned to a %d-byte page\n",
program, address, (int)page_size); program, address, (int)page_size);
return 1; return 1;
} }
/* Did the user request a bad endian? We use it anyway, but issue warning. */ /* Did the user request a bad endian? We use it anyway, but issue warning. */
if (endian != 0 && (device_support & EB_ENDIAN_MASK) != endian) { if (endian != 0 && (device_support & EB_ENDIAN_MASK) != endian) {
if (!quiet) if (!quiet)
fprintf(stderr, "%s: warning: target device is %s (writing as %s).\n", fprintf(stderr, "%s: warning: target device is %s (writing as %s).\n",
program, eb_format_endian(device_support), eb_format_endian(endian)); program, eb_format_endian(device_support), eb_format_endian(endian));
} }
if (endian == 0) { if (endian == 0) {
/* Select the probed endian. May still be 0 if device not found. */ /* Select the probed endian. May still be 0 if device not found. */
endian = device_support & EB_ENDIAN_MASK; endian = device_support & EB_ENDIAN_MASK;
} }
/* We need to know the endian */ /* We need to know the endian */
if (endian == 0) { if (endian == 0) {
fprintf(stderr, "%s: error: must know endian to program firmware\n", fprintf(stderr, "%s: error: must know endian to program firmware\n",
program); program);
return 1; return 1;
} }
/* What widths does the connection support? */ /* What widths does the connection support? */
line_width &= EB_DATAX; line_width &= EB_DATAX;
line_width |= line_width-1; line_width |= line_width-1;
...@@ -987,13 +987,13 @@ int main(int argc, char** argv) { ...@@ -987,13 +987,13 @@ int main(int argc, char** argv) {
format |= format >> 1; format |= format >> 1;
format |= format >> 2; format |= format >> 2;
format = (format+1) >> 1; format = (format+1) >> 1;
if (format == 0) { if (format == 0) {
fprintf(stderr, "%s: device widths %s do not fit this connection (widths %s)\n", fprintf(stderr, "%s: device widths %s do not fit this connection (widths %s)\n",
program, eb_width_data(device_support), eb_width_data(line_width)); program, eb_width_data(device_support), eb_width_data(line_width));
return 1; return 1;
} }
/* If the page size is smaller than the write format... wtf? */ /* If the page size is smaller than the write format... wtf? */
if (page_size < format) { if (page_size < format) {
fprintf(stderr, "%s: page size %d is smaller than device write size %d!\n", fprintf(stderr, "%s: page size %d is smaller than device write size %d!\n",
...@@ -1005,38 +1005,38 @@ int main(int argc, char** argv) { ...@@ -1005,38 +1005,38 @@ int main(int argc, char** argv) {
if (verbose) if (verbose)
printf("Will operate using %s bit %s operations\n", printf("Will operate using %s bit %s operations\n",
eb_format_data(format), eb_format_endian(format)); eb_format_data(format), eb_format_endian(format));
if (!sector_size) { if (!sector_size) {
sector_size = detect_sector_size(device); sector_size = detect_sector_size(device);
} }
ffs = 0; ffs = 0;
ffs = ~ffs; ffs = ~ffs;
ffs >>= (sizeof(eb_data_t) - (format&EB_DATAX))*8; ffs >>= (sizeof(eb_data_t) - (format&EB_DATAX))*8;
mask_0f = 0x0f; mask_0f = 0x0f;
for (i = 0; i < sizeof(eb_data_t); ++i) for (i = 0; i < sizeof(eb_data_t); ++i)
mask_0f |= mask_0f << 8; mask_0f |= mask_0f << 8;
if (full) { if (full) {
memset(erase_bitmap, 0xFF, erase_bitmap_size); memset(erase_bitmap, 0xFF, erase_bitmap_size);
} else { } else {
quick_scan(device); quick_scan(device);
} }
erase_flash(device); erase_flash(device);
program_flash(device); program_flash(device);
if (verify) verify_flash(device); if (verify) verify_flash(device);
if ((status = eb_device_close(device)) != EB_OK) { if ((status = eb_device_close(device)) != EB_OK) {
fprintf(stderr, "%s: failed to close Etherbone device: %s\n", program, eb_status(status)); fprintf(stderr, "%s: failed to close Etherbone device: %s\n", program, eb_status(status));
return 1; return 1;
} }
if ((status = eb_socket_close(socket)) != EB_OK) { if ((status = eb_socket_close(socket)) != EB_OK) {
fprintf(stderr, "%s: failed to close Etherbone socket: %s\n", program, eb_status(status)); fprintf(stderr, "%s: failed to close Etherbone socket: %s\n", program, eb_status(status));
return 1; return 1;
} }
return 0; return 0;
} }
/** @file eb-info.c /** @file eb-info.c
* @brief Report the contents of an FPGA using Etherbone. * @brief Report the contents of an FPGA using Etherbone.
* *
* Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH * Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH
* *
* A complete skeleton of an application using the Etherbone library. * A complete skeleton of an application using the Etherbone library.
* *
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************* *******************************************************************************
...@@ -58,11 +58,11 @@ int main(int argc, char** argv) { ...@@ -58,11 +58,11 @@ int main(int argc, char** argv) {
eb_device_t device; eb_device_t device;
eb_cycle_t cycle; eb_cycle_t cycle;
eb_data_t *data; eb_data_t *data;
/* Default arguments */ /* Default arguments */
program = argv[0]; program = argv[0];
error = 0; error = 0;
/* Process the command-line arguments */ /* Process the command-line arguments */
error = 0; error = 0;
while ((opt = getopt(argc, argv, "h")) != -1) { while ((opt = getopt(argc, argv, "h")) != -1) {
...@@ -79,20 +79,20 @@ int main(int argc, char** argv) { ...@@ -79,20 +79,20 @@ int main(int argc, char** argv) {
error = 1; error = 1;
} }
} }
if (error) return 1; if (error) return 1;
if (optind + 1 != argc) { if (optind + 1 != argc) {
fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port>\n", program); fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port>\n", program);
return 1; return 1;
} }
if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK) if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK)
die("eb_socket_open", status); die("eb_socket_open", status);
if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK) if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK)
die(argv[optind], status); die(argv[optind], status);
c = 1; c = 1;
if ((status = eb_sdb_find_by_identity(device, GSI_ID, ROM_ID, &sdb, &c)) != EB_OK) if ((status = eb_sdb_find_by_identity(device, GSI_ID, ROM_ID, &sdb, &c)) != EB_OK)
die("eb_sdb_find_by_identity", status); die("eb_sdb_find_by_identity", status);
...@@ -100,27 +100,27 @@ int main(int argc, char** argv) { ...@@ -100,27 +100,27 @@ int main(int argc, char** argv) {
fprintf(stderr, "Found %d ROM identifiers on that device\n", c); fprintf(stderr, "Found %d ROM identifiers on that device\n", c);
exit(1); exit(1);
} }
if ((status = eb_cycle_open(device, 0, 0, &cycle)) != EB_OK) if ((status = eb_cycle_open(device, 0, 0, &cycle)) != EB_OK)
die("eb_cycle_open", status); die("eb_cycle_open", status);
len = ((sdb.sdb_component.addr_last - sdb.sdb_component.addr_first) + 1) / 4; len = ((sdb.sdb_component.addr_last - sdb.sdb_component.addr_first) + 1) / 4;
if ((data = malloc(len * sizeof(eb_data_t))) == 0) if ((data = malloc(len * sizeof(eb_data_t))) == 0)
die("malloc", EB_OOM); die("malloc", EB_OOM);
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
eb_cycle_read(cycle, sdb.sdb_component.addr_first + i*4, EB_DATA32|EB_BIG_ENDIAN, &data[i]); eb_cycle_read(cycle, sdb.sdb_component.addr_first + i*4, EB_DATA32|EB_BIG_ENDIAN, &data[i]);
if ((status = eb_cycle_close(cycle)) != EB_OK) if ((status = eb_cycle_close(cycle)) != EB_OK)
die("eb_cycle_close", status); die("eb_cycle_close", status);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
printf("%c%c%c%c", printf("%c%c%c%c",
(char)(data[i] >> 24) & 0xff, (char)(data[i] >> 24) & 0xff,
(char)(data[i] >> 16) & 0xff, (char)(data[i] >> 16) & 0xff,
(char)(data[i] >> 8) & 0xff, (char)(data[i] >> 8) & 0xff,
(char)(data[i] ) & 0xff); (char)(data[i] ) & 0xff);
} }
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment