diff --git a/amd_imc.c b/amd_imc.c index 0696732c0..3fb1f8773 100644 --- a/amd_imc.c +++ b/amd_imc.c @@ -19,6 +19,7 @@ #include "hwaccess_x86_io.h" #include "spi.h" #include "platform/pci.h" +#include "platform/udelay.h" /* same as serverengines */ static void enter_conf_mode_ec(uint16_t port) diff --git a/asm106x.c b/asm106x.c index 0c9cf111d..22a4942c7 100644 --- a/asm106x.c +++ b/asm106x.c @@ -17,6 +17,7 @@ #include #include "programmer.h" #include "platform/pci.h" +#include "platform/udelay.h" #define PCI_VENDOR_ID_ASMEDIA 0x1b21 diff --git a/atavia.c b/atavia.c index da2ab2fc3..ab63f2c89 100644 --- a/atavia.c +++ b/atavia.c @@ -21,6 +21,7 @@ #include "flash.h" #include "programmer.h" #include "platform/pci.h" +#include "platform/udelay.h" #define PCI_VENDOR_ID_VIA 0x1106 diff --git a/bitbang_spi.c b/bitbang_spi.c index ef366530d..f243fb89a 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -19,6 +19,7 @@ #include #include "programmer.h" #include "spi.h" +#include "platform/udelay.h" /* Note that CS# is active low, so val=0 means the chip is active. */ static void bitbang_spi_set_cs(const struct bitbang_spi_master * const master, int val, void *spi_data) diff --git a/buspirate_spi.c b/buspirate_spi.c index a9df8ed35..bf8d93058 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -22,6 +22,7 @@ #include #include "programmer.h" #include "spi.h" +#include "platform/udelay.h" /* Change this to #define if you want to test without a serial implementation */ #undef FAKE_COMMUNICATION diff --git a/ch341a_spi.c b/ch341a_spi.c index 8f42f09c7..f1ddc94a7 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -22,6 +22,7 @@ #include #include "flash.h" #include "programmer.h" +#include "platform/udelay.h" /* LIBUSB_CALL ensures the right calling conventions on libusb callbacks. * However, the macro is not defined everywhere. m( diff --git a/dediprog.c b/dediprog.c index 223946a70..b9848cf93 100644 --- a/dediprog.c +++ b/dediprog.c @@ -26,6 +26,7 @@ #include "programmer.h" #include "spi.h" #include "usbdev.h" +#include "platform/udelay.h" /* LIBUSB_CALL ensures the right calling conventions on libusb callbacks. * However, the macro is not defined everywhere. m( diff --git a/dummyflasher.c b/dummyflasher.c index 1cfdd8002..10f7bad1a 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -27,6 +27,7 @@ #include "flashchips.h" #include "spi.h" #include "writeprotect.h" +#include "platform/udelay.h" enum emu_chip { EMULATE_NONE, diff --git a/flashrom.c b/flashrom.c index 457df728b..ac93ea67d 100644 --- a/flashrom.c +++ b/flashrom.c @@ -35,6 +35,7 @@ #include "hwaccess_physmap.h" #include "chipdrivers.h" #include "erasure_layout.h" +#include "platform/udelay.h" const char flashrom_version[] = FLASHROM_VERSION; diff --git a/ichspi.c b/ichspi.c index 7471d1aed..d82aaf9cd 100644 --- a/ichspi.c +++ b/ichspi.c @@ -26,6 +26,7 @@ #include "hwaccess_physmap.h" #include "spi.h" #include "ich_descriptors.h" +#include "platform/udelay.h" /* Apollo Lake */ #define APL_REG_FREG12 0xe0 /* 32 Bytes Flash Region 12 */ diff --git a/include/platform/udelay.h b/include/platform/udelay.h new file mode 100644 index 000000000..4fcf7922d --- /dev/null +++ b/include/platform/udelay.h @@ -0,0 +1,23 @@ +/* + * This file is part of the flashrom project. + * + * Copyright 2025 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 __UDELAY_H__ +#define __UDELAY_H__ + +void internal_sleep(unsigned int usecs); +void default_delay(unsigned int usecs); + +#endif diff --git a/include/programmer.h b/include/programmer.h index b2c968353..b2c2dc7a9 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -217,10 +217,6 @@ extern const struct board_info boards_known[]; extern const struct board_info laptops_known[]; #endif -/* udelay.c */ -void internal_sleep(unsigned int usecs); -void default_delay(unsigned int usecs); - #if CONFIG_INTERNAL == 1 /* board_enable.c */ int selfcheck_board_enables(void); diff --git a/it87spi.c b/it87spi.c index fc008d615..c70c5c7fa 100644 --- a/it87spi.c +++ b/it87spi.c @@ -28,6 +28,7 @@ #include "hwaccess_physmap.h" #include "hwaccess_x86_io.h" #include "spi.h" +#include "platform/udelay.h" #define ITE_SUPERIO_PORT1 0x2e #define ITE_SUPERIO_PORT2 0x4e diff --git a/jlink_spi.c b/jlink_spi.c index d970cdfba..8cf40b4ae 100644 --- a/jlink_spi.c +++ b/jlink_spi.c @@ -28,6 +28,7 @@ #include "programmer.h" #include "spi.h" +#include "platform/udelay.h" /* * Maximum number of bytes that can be transferred at once via the JTAG diff --git a/meson.build b/meson.build index 734afb650..35feb33b8 100644 --- a/meson.build +++ b/meson.build @@ -105,16 +105,6 @@ srcs = files( 'writeprotect_ranges.c', ) -# Select an appropriate delay implementation for the target OS -delay_src = files('udelay.c') -if target_machine.system() == 'dos' - delay_src = files('udelay_dos.c') -endif -srcs += delay_src -cargs += ['-DCONFIG_DELAY_MINIMUM_SLEEP_US=@0@'.format( - get_option('delay_minimum_sleep_us') -)] - # check for required symbols if cc.has_function('clock_gettime') add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c') diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c index e3f2643da..50e20e2db 100644 --- a/nicintel_eeprom.c +++ b/nicintel_eeprom.c @@ -35,6 +35,7 @@ #include "programmer.h" #include "hwaccess_physmap.h" #include "platform/pci.h" +#include "platform/udelay.h" #define PCI_VENDOR_ID_INTEL 0x8086 #define MEMMAP_SIZE 0x1c /* Only EEC, EERD and EEWR are needed. */ diff --git a/platform/meson.build b/platform/meson.build index 42e85eea4..280048dd3 100644 --- a/platform/meson.build +++ b/platform/meson.build @@ -10,6 +10,16 @@ if host_machine.endian() == 'big' add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c') endif +# Select an appropriate delay implementation for the target OS +delay_src = files('udelay.c') +if target_machine.system() == 'dos' + delay_src = files('udelay_dos.c') +endif +srcs += delay_src +cargs += ['-DCONFIG_DELAY_MINIMUM_SLEEP_US=@0@'.format( + get_option('delay_minimum_sleep_us') +)] + # OpenBSD requires libi386 or libamd64 for I/O port handling if host_machine.system() == 'openbsd' if host_machine.cpu_family() == 'x86' @@ -32,7 +42,6 @@ if host_machine.system() == 'netbsd' endif endif - # SunOS requires external libraries for network sockets # they are used to support serial devices via network if host_machine.system() == 'sunos' diff --git a/udelay.c b/platform/udelay.c similarity index 98% rename from udelay.c rename to platform/udelay.c index c43b6e3a7..562df3c9c 100644 --- a/udelay.c +++ b/platform/udelay.c @@ -18,6 +18,8 @@ #ifndef __LIBPAYLOAD__ +#include "platform/udelay.h" + #include #include #include diff --git a/udelay_dos.c b/platform/udelay_dos.c similarity index 99% rename from udelay_dos.c rename to platform/udelay_dos.c index c3914eacc..596994e70 100644 --- a/udelay_dos.c +++ b/platform/udelay_dos.c @@ -15,6 +15,8 @@ * GNU General Public License for more details. */ +#include "platform/udelay.h" + #include #include #include diff --git a/pony_spi.c b/pony_spi.c index 0647f9121..05f65150e 100644 --- a/pony_spi.c +++ b/pony_spi.c @@ -43,6 +43,7 @@ #include "flash.h" #include "programmer.h" +#include "platform/udelay.h" enum pony_type { TYPE_SI_PROG, diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c index 8fd5f7464..e36f7eb9d 100644 --- a/raiden_debug_spi.c +++ b/raiden_debug_spi.c @@ -341,6 +341,7 @@ #include "programmer.h" #include "spi.h" #include "usb_device.h" +#include "platform/udelay.h" #include #include diff --git a/serial.c b/serial.c index 577ccf43c..0a2ea305e 100644 --- a/serial.c +++ b/serial.c @@ -35,6 +35,7 @@ #include "flash.h" #include "programmer.h" #include "custom_baud.h" +#include "platform/udelay.h" fdtype sp_fd = SER_INV_FD; diff --git a/serprog.c b/serprog.c index f738ef356..e67921996 100644 --- a/serprog.c +++ b/serprog.c @@ -38,6 +38,7 @@ #include "flash.h" #include "programmer.h" #include "chipdrivers.h" +#include "platform/udelay.h" /* According to Serial Flasher Protocol Specification - version 1 */ #define S_ACK 0x06 diff --git a/spidriver.c b/spidriver.c index 899946818..d6d6cdc5c 100644 --- a/spidriver.c +++ b/spidriver.c @@ -30,6 +30,7 @@ #include "flash.h" #include "programmer.h" #include "spi.h" +#include "platform/udelay.h" static int spidriver_serialport_setup(char *dev) { diff --git a/tests/udelay.c b/tests/udelay.c index 8d24b00dd..d583f58ac 100644 --- a/tests/udelay.c +++ b/tests/udelay.c @@ -17,7 +17,7 @@ #include #include -#include "programmer.h" +#include "platform/udelay.h" #include "tests.h" static uint64_t now_us(void) { diff --git a/wbsio_spi.c b/wbsio_spi.c index 1481cbaf9..7ed495119 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -21,6 +21,7 @@ #include "hwaccess_physmap.h" #include "hwaccess_x86_io.h" #include "spi.h" +#include "platform/udelay.h" #define WBSIO_PORT1 0x2e #define WBSIO_PORT2 0x4e