fomu-flash: add offset parameter to -p

Add an offset parameter to -p.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2018-12-17 21:40:40 +08:00
parent 09fe20efda
commit 253e82b5cb

14
fomu-flash.c Normal file → Executable file
View File

@ -78,11 +78,11 @@ enum op {
int print_help(FILE *stream, const char *progname) { int print_help(FILE *stream, const char *progname) {
fprintf(stream, "Fomu Raspberry Pi Flash Utilities\n"); fprintf(stream, "Fomu Raspberry Pi Flash Utilities\n");
fprintf(stream, "Usage:\n"); fprintf(stream, "Usage:\n");
fprintf(stream, " %s [-h] [-r] [-p] [-f bin] [-w bin] [-v bin] [-s out] [-2 pin] [-3 pin]\n", progname); fprintf(stream, " %s [-h] [-r] [-p offset] [-f bin] [-w bin] [-v bin] [-s out] [-2 pin] [-3 pin]\n", progname);
fprintf(stream, "Flags:\n"); fprintf(stream, "Flags:\n");
fprintf(stream, " -h This help page\n"); fprintf(stream, " -h This help page\n");
fprintf(stream, " -r Reset the FPGA and have it boot from SPI\n"); fprintf(stream, " -r Reset the FPGA and have it boot from SPI\n");
fprintf(stream, " -p Peek at the first 256 bytes of SPI flash\n"); fprintf(stream, " -p offset Peek at 256 bytes of SPI flash at the specified offset\n");
fprintf(stream, " -f bin Load this binary directly into the FPGA\n"); fprintf(stream, " -f bin Load this binary directly into the FPGA\n");
fprintf(stream, " -w bin Write this binary into the SPI flash chip\n"); fprintf(stream, " -w bin Write this binary into the SPI flash chip\n");
fprintf(stream, " -v bin Verify the SPI flash contains this data\n"); fprintf(stream, " -v bin Verify the SPI flash contains this data\n");
@ -98,6 +98,7 @@ int main(int argc, char **argv) {
char *op_filename = NULL; char *op_filename = NULL;
struct ff_spi *spi; struct ff_spi *spi;
struct ff_fpga *fpga; struct ff_fpga *fpga;
int peek_offset = 0;
enum op op = OP_UNKNOWN; enum op op = OP_UNKNOWN;
spi = spiAlloc(); spi = spiAlloc();
@ -123,7 +124,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
while ((opt = getopt(argc, argv, "hprf:w:s:2:3:v:")) != -1) { while ((opt = getopt(argc, argv, "hp:rf:w:s:2:3:v:")) != -1) {
switch (opt) { switch (opt) {
case '2': case '2':
spiSetPin(spi, SP_D2, strtoul(optarg, NULL, 0)); spiSetPin(spi, SP_D2, strtoul(optarg, NULL, 0));
@ -139,6 +140,7 @@ int main(int argc, char **argv) {
case 'p': case 'p':
op = OP_SPI_PEEK; op = OP_SPI_PEEK;
peek_offset = strtoul(optarg, NULL, 0);
break; break;
case 'f': case 'f':
@ -274,9 +276,9 @@ offset, file_src[offset], spi_src[offset]);
case OP_SPI_PEEK: { case OP_SPI_PEEK: {
fpgaReset(fpga); fpgaReset(fpga);
spiSetType(spi, ST_QPI); spiSetType(spi, ST_QPI);
uint8_t page0[256]; uint8_t page[256];
spiRead(spi, 0, page0, sizeof(page0)); spiRead(spi, peek_offset, page, sizeof(page));
print_hex(page0, sizeof(page0), 0); print_hex_offset(stdout, page, sizeof(page), 0, 0);
break; break;
} }