From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001
From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru --- udelay.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/udelay.c b/udelay.c index 9f5e562..e589afb 100644 --- a/udelay.c +++ b/udelay.c @@ -175,7 +175,11 @@ void internal_delay(int usecs) * be so precise. */ if (usecs > 1000000) { +#ifdef _WIN32 + Sleep((usecs + 999) / 1000); +#else usleep(usecs); +#endif } else { myusec_delay(usecs); }
On Mon, 1 Apr 2013 19:08:30 +0400 Maksim Kuleshov mmcx@ucs.ru wrote:
From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001 From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru
I don't think that we ever had a problem with that. (Please correct me... Idwer?). What version of MinGW are you using? What's your make command and what does it print as error?
I use i586-mingw32msvc-gcc on Debian.
$ make CC=i586-mingw32msvc-gcc cc1: warnings being treated as errors buspirate_spi.c: In function ‘buspirate_spi_init’: buspirate_spi.c:289: warning: implicit declaration of function ‘usleep’
$ i586-mingw32msvc-gcc --v Using built-in specs. Target: i586-mingw32msvc Configured with: /home/ron/devel/debian/mingw32/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs Thread model: win32 gcc version 4.2.1-sjlj (mingw32-2)
$ dpkg -l 'mingw*' ii mingw32 4.2.1.dfsg-2 amd64 Minimalist GNU win32 (cross) compiler ii mingw32-binutils 2.20-0.2 amd64 Minimalist GNU win32 (cross) binutils ii mingw32-runtime 3.13-1 all Minimalist GNU win32 (cross) runtime
-----Original Message----- Date: Tue, 2 Apr 2013 22:58:34 +0200 From: Stefan Tauner stefan.tauner@student.tuwien.ac.at To: Maksim Kuleshov mmcx@ucs.ru Cc: flashrom@flashrom.org Subject: Re: [flashrom] [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
On Mon, 1 Apr 2013 19:08:30 +0400 Maksim Kuleshov mmcx@ucs.ru wrote:
From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001 From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru
I don't think that we ever had a problem with that. (Please correct me... Idwer?). What version of MinGW are you using? What's your make command and what does it print as error?
-- Kind regards/Mit freundlichen Grüßen, Stefan Tauner
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
2013/4/2 Stefan Tauner stefan.tauner@student.tuwien.ac.at
On Mon, 1 Apr 2013 19:08:30 +0400 Maksim Kuleshov mmcx@ucs.ru wrote:
From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001 From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru
I don't think that we ever had a problem with that. (Please correct me... Idwer?). What version of MinGW are you using? What's your make command and what does it print as error?
The gcc I have installed is i486-mingw32-gcc: https://www.archlinux.org/packages/community/i686/mingw32-gcc/ My local Makefile changes include libusb-win32-bin-1.2.4.0 and libftdi_0.20git_win32
However, no usleep() problems here: flashrom.c: In function 'read_buf_from_file': flashrom.c:1170:3: error: unknown conversion type character 'j' in format [-Werror=format] flashrom.c:1170:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'long long int' [-Werror=format] flashrom.c:1170:3: error: too many arguments for format [-Werror=format-extra-args]
-- Kind regards/Mit freundlichen Grüßen, Stefan Tauner
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
Am 02.04.2013 22:58 schrieb Stefan Tauner:
On Mon, 1 Apr 2013 19:08:30 +0400 Maksim Kuleshov mmcx@ucs.ru wrote:
From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001 From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru
I don't think that we ever had a problem with that. (Please correct me... Idwer?). What version of MinGW are you using? What's your make command and what does it print as error?
If it fixes a real problem (I didn't need the patch in my cross-compile-for-mingw environment), this looks sane. Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Regards, Carl-Daniel
Am 03.04.2013 00:27 schrieb Carl-Daniel Hailfinger:
Am 02.04.2013 22:58 schrieb Stefan Tauner:
On Mon, 1 Apr 2013 19:08:30 +0400 Maksim Kuleshov mmcx@ucs.ru wrote:
From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001 From: Maksim Kuleshov mmcx@mail.ru Date: Mon, 1 Apr 2013 19:03:43 +0400 Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
Signed-off-by: Maksim Kuleshov mmcx@mail.ru
I don't think that we ever had a problem with that. (Please correct me... Idwer?). What version of MinGW are you using? What's your make command and what does it print as error?
If it fixes a real problem (I didn't need the patch in my cross-compile-for-mingw environment), this looks sane. Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
I now see that the patch is correct. However, the code for non-Windows was broken as well (too big values for udelay), so I extended your patch a bit.
usleep() is not found in all versions of MinGW, use Sleep() on Windows. 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
Index: flashrom-long_delay_fix/buspirate_spi.c =================================================================== --- flashrom-long_delay_fix/buspirate_spi.c (Revision 1666) +++ flashrom-long_delay_fix/buspirate_spi.c (Arbeitskopie) @@ -286,7 +286,7 @@ /* The Bus Pirate can't handle UART input buffer overflow in BBIO mode, and sending a sequence * of 0x00 too fast apparently triggers such an UART input buffer overflow. */ - usleep(10000); + internal_sleep(10000); } /* We know that 20 commands of \0 should elicit at least one BBIO1 response. */ if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO"))) Index: flashrom-long_delay_fix/programmer.h =================================================================== --- flashrom-long_delay_fix/programmer.h (Revision 1666) +++ flashrom-long_delay_fix/programmer.h (Arbeitskopie) @@ -250,6 +250,7 @@ /* udelay.c */ void myusec_delay(int usecs); void myusec_calibrate_delay(void); +void internal_sleep(int usecs); void internal_delay(int usecs);
#if CONFIG_INTERNAL == 1 Index: flashrom-long_delay_fix/udelay.c =================================================================== --- flashrom-long_delay_fix/udelay.c (Revision 1666) +++ flashrom-long_delay_fix/udelay.c (Arbeitskopie) @@ -169,13 +169,23 @@ msg_pinfo("OK.\n"); }
+/* Not very precise sleep. */ +void internal_sleep(int usecs) +{ +#ifdef _WIN32 + Sleep((usecs + 999) / 1000); +#else + sleep(usecs / 1000000); + usleep(usecs % 1000000); +#endif +} + +/* Precise delay. */ void internal_delay(int usecs) { - /* If the delay is >1 s, use usleep because timing does not need to - * be so precise. - */ + /* If the delay is >1 s, use internal_sleep because timing does not need to be so precise. */ if (usecs > 1000000) { - usleep(usecs); + internal_sleep(usecs); } else { myusec_delay(usecs); }
On Wed, 03 Apr 2013 01:21:11 +0200 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
I now see that the patch is correct. However, the code for non-Windows was broken as well (too big values for udelay), so I extended your patch a bit.
usleep() is not found in all versions of MinGW, use Sleep() on Windows. 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
Looks good to me. Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Everybody is invited to work on the following when the patch has been merged: http://www.flashrom.org/Easy_projects#Replace_programmer_delay.28.29_with_in...
Am 04.04.2013 02:20 schrieb Stefan Tauner:
On Wed, 03 Apr 2013 01:21:11 +0200 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
I now see that the patch is correct. However, the code for non-Windows was broken as well (too big values for udelay), so I extended your patch a bit.
usleep() is not found in all versions of MinGW, use Sleep() on Windows. 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
Looks good to me. Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Thanks, committed in r1667.
Everybody is invited to work on the following when the patch has been merged: http://www.flashrom.org/Easy_projects#Replace_programmer_delay.28.29_with_in...
Indeed.
Regards, Carl-Daniel