Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/84982?usp=email )
Change subject: Extract usbdev declarations to a separate header. ......................................................................
Extract usbdev declarations to a separate header.
This is a simple refactor that aims to simplify maintenance and to clarify file dependency inside the project. Currently, most of the declarations reside in programmer.h making it difficult to really understand file dependency.
Change-Id: I9d819ea1c5bd51289d02189c1dff367ce6d25617 Signed-off-by: Antonio Vázquez Blanco antoniovazquezblanco@gmail.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/84982 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Miklós Márton martonmiklosqdev@gmail.com Reviewed-by: Anastasia Klimchuk aklm@chromium.org --- M dediprog.c M developerbox_spi.c M include/programmer.h A include/usbdev.h M stlinkv3_spi.c M usbdev.c 6 files changed, 34 insertions(+), 11 deletions(-)
Approvals: Anastasia Klimchuk: Looks good to me, approved build bot (Jenkins): Verified Miklós Márton: Looks good to me, approved
diff --git a/dediprog.c b/dediprog.c index ba1f9d6..05031fd 100644 --- a/dediprog.c +++ b/dediprog.c @@ -26,6 +26,7 @@ #include "chipdrivers.h" #include "programmer.h" #include "spi.h" +#include "usbdev.h"
/* LIBUSB_CALL ensures the right calling conventions on libusb callbacks. * However, the macro is not defined everywhere. m( diff --git a/developerbox_spi.c b/developerbox_spi.c index 64b7e8a..67d3d68 100644 --- a/developerbox_spi.c +++ b/developerbox_spi.c @@ -35,6 +35,7 @@ #include <libusb.h> #include "programmer.h" #include "spi.h" +#include "usbdev.h"
/* Bit positions for each pin. */ #define DEVELOPERBOX_SPI_SCK 0 diff --git a/include/programmer.h b/include/programmer.h index 5ed9c8a..babb0bc 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -526,13 +526,4 @@ (flash->chip->feature_bits & (FEATURE_4BA_ENTER | FEATURE_4BA_ENTER_WREN | FEATURE_4BA_ENTER_EAR7)); }
-/* usbdev.c */ -struct libusb_device_handle; -struct libusb_context; -struct libusb_device_handle *usb_dev_get_by_vid_pid_serial( - struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno); -struct libusb_device_handle *usb_dev_get_by_vid_pid_number( - struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num); - - #endif /* !__PROGRAMMER_H__ */ diff --git a/include/usbdev.h b/include/usbdev.h new file mode 100644 index 0000000..3bd64b3 --- /dev/null +++ b/include/usbdev.h @@ -0,0 +1,27 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2024 Antonio Vázquez Blanco antoniovazquezblanco@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __USBDEV_H__ +#define __USBDEV_H__ 1 + +#include <libusb.h> + +struct libusb_device_handle *usb_dev_get_by_vid_pid_serial( + struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno); +struct libusb_device_handle *usb_dev_get_by_vid_pid_number( + struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num); + +#endif /* __USBDEV_H__ */ diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c index 29aa8d3..a5c2289 100644 --- a/stlinkv3_spi.c +++ b/stlinkv3_spi.c @@ -26,6 +26,7 @@ #include "flash.h" #include "programmer.h" #include "spi.h" +#include "usbdev.h"
#include <libusb.h> #include <limits.h> diff --git a/usbdev.c b/usbdev.c index 846ed58..02627d8 100644 --- a/usbdev.c +++ b/usbdev.c @@ -15,11 +15,13 @@ * GNU General Public License for more details. */
+ +#include "usbdev.h" + +#include "flash.h" // msg_perr, msg_pdbg... #include <inttypes.h> #include <stdbool.h> #include <string.h> -#include <libusb.h> -#include "programmer.h"
/* * Check whether we should filter the current device.