changeset 95:a378bf95c26c

cp2102-read-eeprom: write the Intel HEX image into a file
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 28 Sep 2023 02:19:39 +0000
parents dd35206a5159
children c6d04771bf6a
files cp2102/read_eeprom_main.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cp2102/read_eeprom_main.c	Thu Sep 28 02:04:36 2023 +0000
+++ b/cp2102/read_eeprom_main.c	Thu Sep 28 02:19:39 2023 +0000
@@ -1,6 +1,6 @@
 /*
  * This program locates a CP2102 device via libusb, reads its internal
- * 1024-byte EEPROM and emits (on stdout) an image of this EEPROM
+ * 1024-byte EEPROM and writes (into a file) an image of this EEPROM
  * in the same Intel HEX format as used by cp210x-program-1.0,
  * the Python-language tool from 2014.
  */
@@ -22,9 +22,11 @@
 {
 	struct usb_device *dev;
 	usb_dev_handle *usbh;
+	FILE *outf;
 
-	if (argc != 2) {
-		fprintf(stderr, "usage: %s device-selector\n", argv[0]);
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s device-selector output-hex-file\n",
+			argv[0]);
 		exit(1);
 	}
 	dev = find_usbdev_by_desc_string(argv[1]);
@@ -39,6 +41,12 @@
 	}
 	read_eeprom(usbh);
 	usb_close(usbh);
-	intel_hex_out(eeprom, stdout);
+	outf = fopen(argv[2], "w");
+	if (!outf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	intel_hex_out(eeprom, outf);
+	fclose(outf);
 	exit(0);
 }