From 69a03a3ab197491f206f68f37371c6d6f02ca015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20V=C3=A1zquez=20Blanco?= Date: Sun, 3 Nov 2024 18:18:43 +0100 Subject: [PATCH] Extract usbdev declarations to a separate header. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/84982 Tested-by: build bot (Jenkins) Reviewed-by: Miklós Márton Reviewed-by: Anastasia Klimchuk --- dediprog.c | 1 + developerbox_spi.c | 1 + include/programmer.h | 9 --------- include/usbdev.h | 27 +++++++++++++++++++++++++++ stlinkv3_spi.c | 1 + usbdev.c | 6 ++++-- 6 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 include/usbdev.h diff --git a/dediprog.c b/dediprog.c index ba1f9d637..05031fdee 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 64b7e8a1b..67d3d687d 100644 --- a/developerbox_spi.c +++ b/developerbox_spi.c @@ -35,6 +35,7 @@ #include #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 5ed9c8af6..babb0bcf5 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -526,13 +526,4 @@ static inline bool spi_chip_4ba(const struct flashctx *const flash) (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 000000000..3bd64b397 --- /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 + * + * 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 + +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 29aa8d3cf..a5c228937 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 #include diff --git a/usbdev.c b/usbdev.c index 846ed58be..02627d8d2 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 #include #include -#include -#include "programmer.h" /* * Check whether we should filter the current device.