summaryrefslogtreecommitdiff
path: root/udelay.c
Commit message (Collapse)AuthorAgeFilesLines
* Use nanosleep() instead of usleep() where available.stefanct2015-11-141-1/+4
| | | | | | | | | | usleep() has been obsolete for quite a while. The only target that uses it without alternative is DOS. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1899 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Unify target OS and CPU architecture checks.stefanct2015-01-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | We do CPU architecture checks once for the makefile in arch.h and once for HW access abstraction in hwaccess.c. This patch unifies related files so that they can share the checks to improve maintainability and reduce the chance of inconsistencies. Furthermore, it refines some of the definitions, which - adds "support" for AARCH64 and PPC64, - adds big-endian handling on arm as well as LE handling on PPC64, - fixes compilation of internal.c on AARCH64 and PPC64. Additionally, this patch continues to unify all OS checks in flashrom by adding a new helper macro IS_WINDOWS. The old header file for architecture checking is renamed to platform.h to reflect its broader scope and all new macros are add in there. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1864 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Make delay values unsigned.stefanct2014-05-021-5/+5
| | | | | | | | | | | | | | | There is no reason for negative delays in our use cases: - We don't need it (to work around any quirks). - sleep() (POSIX) uses an unsigned argument. - usleep() (POSIX) uses an unsigned argument. - Sleep() (Windows) uses an unsigned argument. Change all callees as well (without any complications). Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1782 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* usleep() is not found in all versions of MinGW, use Sleep() on Windows.hailfinger2013-04-051-4/+14
| | | | | | | | | | | Handle long sleeps on non-Windows correctly. Signed-off-by: Maksim Kuleshov <mmcx@mail.ru> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1667 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Some ISO C fixes.stefanct2012-08-271-1/+1
| | | | | | | | | | | | | | | | | This patch just fixes a limited number of bits not conforming to c99 by using - __asm__ instead of just asm - {0} instead of {} for struct initialization - h_addr_list[0] instead of h_addr to access the host address in struct hostent - #include <strings.h> where needed (for ffs and strcasecmp) Based on a previous patch by Carl-Daniel. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1585 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Fix and improve libpayload platform supportoxygene2011-03-081-0/+1
| | | | | | | | | | | | | | | - Fix various minor compile issues (eg. include necessary standard headers) - Fix compilation of libpayload code paths - Provide libpayload support in Makefile - Add make target "libflashrom.a" which links non-CLI code to static library Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Tested-with-DOS-crosscompiler-by: Idwer Vollering <vidwer@gmail.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1280 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* flashrom: fix sparse warning: Using plain integer as NULL pointerstepan2011-01-241-4/+4
| | | | | | | | | | | | | This patch fixes the "using plain integer as NULL pointer" warnings generated by running sparse on the flashrom source. Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Acked-by: Mathias Krause <mathias.krause@secunet.com> Acked-by: Stefan Reinauer <stepan@coreboot.org> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1255 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Add support for building flashrom against libpayload.oxygene2010-09-301-0/+14
| | | | | | | | | | | | This doesn't include changes to the frontend which must be done separately, so this won't work out of the box. This code was tested on hardware. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1184 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Kill global variables, constants and functions if local scope suffices.hailfinger2010-07-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Constify variables where possible. Initialize programmer-related variables explicitly in programmer_init to allow running programmer_init from a clean state after programmer_shutdown. Prohibit registering programmer shutdown functions before init or after shutdown. Kill some dead code. Rename global variables with namespace-polluting names. Use a previously unused locking helper function in sst49lfxxxc.c. This is needed for libflashrom. Effects on the binary size of flashrom are minimal (300 bytes shrinkage), but the data section shrinks by 4384 bytes, and that's a good thing if flashrom is operating in constrained envionments. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1068 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* gcc and clang can check format strings of printf-like functions. Sincehailfinger2010-06-041-1/+1
| | | | | | | | | | | | | we don't support any other compilers right now, enable that extension unconditionally. Fix the bugs found by format string checking. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1032 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Do not trust the OS at all and measure timer precision beforehailfinger2010-06-031-4/+54
| | | | | | | | | | | | | | | | | | | calibrating the delay loop and use that measurement to get reasonable precision for our own delay code. Print a measurement for a delay of 4x the OS timer resolution. Be precise about how bad the deviation was if we had to recalculate. Tested on Windows XP, 32 bit, built using MinGW by Uwe. Tested on FreeDOS v1.0 Final, 32bit, built using DJGPP 4.3.2 by Idwer. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Idwer Vollering <vidwer+lists.flashrom@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1028 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Remove unneeded #include statements completely.hailfinger2010-05-301-2/+3
| | | | | | | | | | | | | | | | unistd.h was only used to get a definition of NULL in all files. Add our own NULL #define and remove unistd.h from flash.h stdio.h has no place in flash.h, it should be included only in files which really need it. Add #include statements in individual .c files where needed. Replace a few printf with msg_* to eliminate the need for stdio.h. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1021 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Reinitialize the delay loop upon recalibration.hailfinger2010-04-091-1/+2
| | | | | | | | | | Fix an unescaped % in a format specifier. Signed-off-by: Urja Rannikko <urjaman@gmail.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@992 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* The current delay loop calculation is still from revision 1 of flashrom,hailfinger2010-03-311-13/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and since then it had a logic bug which caused all delays to be twice as long as intended. Fix the delay duration. Protect against delay loop overflows. Detect a non-working delay loop. Change the delay loop itself to ensure clever compiler optimizers won't eliminate it (as happens with clang/llvm in the current code). Some people suggested machine-specific asm, but the empty asm statement with the loop counter as register/memory input has the benefit of being perfectly cross-platform and working in gcc and clang. If time goes backwards (catastrophical NTP time difference, manual time change), timing measurements were shot because the new-old time subtraction yielded negative numbers which weren't handled correctly because the variable is unsigned. Work around that issue (a fix is mathematically impossible). If time goes forward too fast, pick the biggest possible timing measurement with a guaranteed overflow avoidance for all timing calculations. Check four times if the calculated timing is at most 10% too fast. This addresses OS scheduler interactions, e.g. being scheduled out during measurement which inflates measurements. If the timing looks like garbage, recalculate the timer values up to four times before giving up. Avoid division by zero in rare cases where timing measurements for a 250 ms delay returned 0 us elapsed. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Maciej Pijanka <maciej.pijanka@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@990 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* The delay loop is probably one of the oldest pieces of code in flashrom.hailfinger2010-03-271-13/+29
| | | | | | | | | | | Clean up code duplication and measure timing of 10/100/1000/10000 us delays. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Maciej Pijanka <maciej.pijanka@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@986 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* internal.c was always compiled in because it hosted the functionhailfinger2009-12-241-0/+13
| | | | | | | | | | | | | internal_delay(). Move that function to udelay.c and compile internal.c only if really needed. physmap.c is only needed if the programmer is internal or a PCI card. Make its compilation conditional. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Idwer Vollering <vidwer@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@822 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Add external programmer delay functions so external programmers canhailfinger2009-06-051-2/+2
| | | | | | | | | | | handle the delay on their own if needed. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Urja Rannikko <urjaman@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@578 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Drop unused/duplicated #includes and some dead code (trivial).uwe2009-05-161-1/+0
| | | | | | | | | | | Build-tested on 32bit x86. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@521 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 4117uwe2009-04-151-1/+1
| | | | | | | | | | | Some coding style and consistency fixes (trivial). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@429 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 3669uwe2008-10-181-1/+1
| | | | | | | | | | | Coding-style fixes for flashrom, partly indent-aided (trivial). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@326 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 3569stuge2008-09-071-1/+7
| | | | | | | | | | flashrom: Debug print actual time base calculated by myusec_calibrate_delay() Signed-off-by: Peter Stuge <peter@stuge.se> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@314 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2873uwe2007-10-171-1/+1
| | | | | | | | | | | Some cosmetic cleanups in the flashrom code and output. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@151 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2847uwe2007-10-101-1/+1
| | | | | | | | | | | Revert my last cleanup patch. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@143 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2846uwe2007-10-101-1/+1
| | | | | | | | | | | Cosmetic changes to make the flashrom output more consistent (trivial). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@142 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2768uwe2007-09-091-1/+1
| | | | | | | | | | | Add '(C)' where it's missing (for consistency reasons). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@136 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2767uwe2007-09-091-0/+20
| | | | | | | | | | | | | | | | | | | Add missing license header to udelay.c. I'm self-ack'ing this, as the origin of the code in udelay.c (and thus the license and copyright owner) is pretty clear. The code which is now in udelay.c was split out from flash_rom.c in r1428, and flash_rom.c, in turn, has been around since the beginning and had a 'Copyright 2000 Silicon Integrated System Corporation' line as well as the usual GPLv2-or-later license header. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@135 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2746uwe2007-08-231-1/+1
| | | | | | | | | | | Drop a bunch of useless header files, merge them into flash.h. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@128 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2585stepan2007-04-061-2/+4
| | | | | | | | | | | | | | | | Trivial (cosmetic) cleanup: * Only open /dev/mem once and do it early. * Drop extern for function prototypes. * Minimize ts5300 impact in probe_flash() This cleanup will making ICH7 SPI support quite some easier. Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@100 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2577uwe2007-04-011-2/+2
| | | | | | | | | | | Coding style fixes (trivial). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@97 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 2111ollie2005-11-261-2/+3
| | | | | | flasrom update from Stefan, resovle issue 21 git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@34 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 1457ollie2004-03-201-6/+5
| | | | | | | consolidate more jedec standard code git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@15 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 1434ollie2004-03-181-3/+0
| | | | | | | fixed 32bit v.s. 64bit long int arithematics git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@8 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 1433ollie2004-03-171-3/+1
| | | | | | | | | removed spd_dump.c, it has nothing to do with flashing flash parts. use standard product ID exit method for w49f002u move udelay stuff into its own file git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@7 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Original v2 revision: 1428ollie2004-03-171-0/+43
move utility functions into new source files git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@6 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1