# HG changeset patch # User Mychaela Falconia # Date 1695867579 0 # Node ID a378bf95c26c60ab69feec3d109c5b82c7724145 # Parent dd35206a5159c3df13342dae24b75193ed3ba78f cp2102-read-eeprom: write the Intel HEX image into a file diff -r dd35206a5159 -r a378bf95c26c cp2102/read_eeprom_main.c --- 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); }