[bootlin/training-materials updates] master: serial-{get, reset}-counter: pass as argument the serial port device (43f7cdf3)

Thomas Petazzoni thomas.petazzoni at bootlin.com
Thu Jun 4 09:03:44 CEST 2020


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/43f7cdf3019c7c25eba8eb76675146c349767da2

>---------------------------------------------------------------

commit 43f7cdf3019c7c25eba8eb76675146c349767da2
Author: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Date:   Thu Jun 4 09:02:57 2020 +0200

    serial-{get,reset}-counter: pass as argument the serial port device
    
    We're not using /dev/serial, but /dev/serial-<something>, so let's not
    hardcode the serial port device path into the program, but pass it as
    argument.
    
    Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>


>---------------------------------------------------------------

43f7cdf3019c7c25eba8eb76675146c349767da2
 .../modules/nfsroot/root/serial/serial-get-counter.c          | 11 ++++++++---
 .../modules/nfsroot/root/serial/serial-reset-counter.c        | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-get-counter.c b/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-get-counter.c
index 07590dca..4b097ad2 100644
--- a/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-get-counter.c
+++ b/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-get-counter.c
@@ -8,14 +8,19 @@
 #define SERIAL_RESET_COUNTER 0
 #define SERIAL_GET_COUNTER 1
 
-int main(void)
+int main(int argc, char *argv[])
 {
     unsigned int val;
     int fd, ret;
 
-    fd = open("/dev/serial", O_RDWR);
+    if (argc != 2) {
+	fprintf(stderr, "Usage: %s /dev/UART\n", argv[0]);
+	exit (1);
+    }
+
+    fd = open(argv[1], O_RDWR);
     if (fd < 0) {
-        fprintf(stderr, "Unable to open /dev/serial\n");
+	fprintf(stderr, "Unable to open %s\n", argv[1]);
         exit (1);
     }
 
diff --git a/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-reset-counter.c b/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-reset-counter.c
index cb268dbf..951b96e5 100644
--- a/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-reset-counter.c
+++ b/lab-data/linux-kernel/modules/nfsroot/root/serial/serial-reset-counter.c
@@ -8,13 +8,18 @@
 #define SERIAL_RESET_COUNTER 0
 #define SERIAL_GET_COUNTER 1
 
-int main(void)
+int main(int argc, char *argv[])
 {
     int fd, ret;
 
-    fd = open("/dev/serial", O_RDWR);
+    if (argc != 2) {
+	fprintf(stderr, "Usage: %s /dev/UART\n", argv[0]);
+	exit (1);
+    }
+
+    fd = open(argv[1], O_RDWR);
     if (fd < 0) {
-        fprintf(stderr, "Unable to open /dev/serial\n");
+	fprintf(stderr, "Unable to open %s\n", argv[1]);
         exit (1);
     }
 




More information about the training-materials-updates mailing list