From f6a80713cf7f27bdb7e4fbbade8db3ea8bebc7d6 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Wed, 23 Apr 2025 14:23:15 +0800 Subject: [PATCH] update w25qflash to specify spidev --- modules/w25qflash.c | 63 +++++++++++++++++++++++++++++-- 1 files changed, 59 insertions(+), 4 deletions(-) diff --git a/modules/w25qflash.c b/modules/w25qflash.c index db20abd..ae54646 100644 --- a/modules/w25qflash.c +++ b/modules/w25qflash.c @@ -29,6 +29,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <libgen.h> #include <getopt.h> #include <fcntl.h> #include <time.h> @@ -57,19 +58,73 @@ void dump_buf(const char *prompt, char *buffer, size_t length); +static inline void banner(const char *progname) +{ + printf("%s program Version v1.0.0\n", progname); + printf("Copyright (C) 2023 Avnet.\n"); +} + +static void program_usage(const char *progname) +{ + + printf("Usage: %s [OPTION]...\n", progname); + printf(" %s is W25Q SPI Norflash test program. \n", progname); + + printf(" -d[device ] Specify SPI device, such as /dev/spidevX.Y\n"); + printf(" -h[help ] Display this help information\n"); + printf(" -v[version ] Display the program version\n"); + + printf("\n"); + banner(progname); + return; +} + +char *dev="/dev/spidev0.0"; /* SPI device 0 */ + int main (int argc, char **argv) { + int rv; + char *progname=NULL; + struct option long_options[] = { + {"device", required_argument, NULL, 'd'}, + {"version", no_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + progname = basename(argv[0]); + + /* Parser the command line parameters */ + while ((rv = getopt_long(argc, argv, "d:m:vh", long_options, NULL)) != -1) + { + switch (rv) + { + case 'd': /* Set SPI device path: /dev/spidev0.0 */ + dev = optarg; + break; + + case 'v': /* Get software version */ + banner(progname); + return EXIT_SUCCESS; + + case 'h': /* Get help information */ + program_usage(progname); + return 0; + + default: + break; + } + } + spinor_test(); return 0; } - /*+-----------------------+ *| SPI API Functions | *+-----------------------+*/ -#define SPI_DEV "/dev/spidev0.0" #define SPI_BITS 8 #define SPI_MODE 0//(SPI_CPHA|SPI_CPOL) #define SPI_SPEED 500000 @@ -84,10 +139,10 @@ uint32_t request; int ret; - spi->hspi = open(SPI_DEV, O_RDWR); + spi->hspi = open(dev, O_RDWR); if (spi->hspi < 0) { - spinor_print("ERROR: open device %s failure: %s\r\n", SPI_DEV, strerror(errno)); + spinor_print("ERROR: open device %s failure: %s\r\n", dev, strerror(errno)); return ; } -- Gitblit v1.9.1