Re: [PATCH] Fix implicit declaration of inb/outb

2008-06-02 Thread Jamey Sharp
On Mon, Jun 2, 2008 at 4:20 PM, Bernhard Walle [EMAIL PROTECTED] wrote:
 --- a/purgatory/arch/i386/console-x86.c
 +++ b/purgatory/arch/i386/console-x86.c
 @@ -1,5 +1,5 @@
  #include stdint.h
 -#include arch/io.h
 +#include sys/io.h
  #include purgatory.h

Oh, dear--that doesn't work. I just submitted the opposite patch a few
weeks ago, because readw and writew are in arch/io.h but not sys/io.h.
Undoing that would break i386 again; details are in the commit
message.

Jamey

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH] Use 'long long' for printf() format string and ELF64 numbers.

2008-05-27 Thread Jamey Sharp
On Sun, May 25, 2008 at 1:11 PM, Bernhard Walle [EMAIL PROTECTED] wrote:
  kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 4 has type 'Elf64_Off'

This is what inttypes.h is for, right?

 dbgprintf(%s: p_type = %u, p_offset = 0x%llx p_paddr = 0x%llx  ...

Perhaps (... p_offset = 0x PRIx64  p_paddr = 0x PRIx64 ...)?

Jamey

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH] Cross compile?

2008-05-27 Thread Jamey Sharp
On Tue, May 27, 2008 at 7:40 AM, Lombard, David N
[EMAIL PROTECTED] wrote:
 ./configure --build=`uname -m`-linux-uclibc \
  --host=`uname -m` --prefix=/home/dnl/kboot-11/root \
  CC=uclibc-gcc BUILD_CC=host-gcc

Isn't this backwards? BUILD_CC ought to match --build, and CC ought to
match --host. If you wanted a kexec binary to put in a uClibc initramfs,
you should set --host for that, not --build. Right?

I've just been looking at `git grep -F -w CC` to decide which configure
flag to use for what, if that helps.

Jamey

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [RFC] Win32 port of the userspace tools using MinGW.

2008-05-23 Thread Jamey Sharp
On Fri, May 23, 2008 at 4:12 PM, Simon Horman [EMAIL PROTECTED] wrote:
 Firstly, thanks for your work in not only getting this port up and going,
 but methodically posted patches relating to it. You have made my job
 very easy :-)

I tried. I'm happy to hear I succeeded. :-)

 The patch looks a little invasive, but I guess that is to be expected
 given the nature of what you re doing. I wonder if there will be other
 equally different ports (by which I mean its the first time the code has
 been made to work outside of some Linux environment) and thus whether it
 is worth abstracting some of these things somehow. Just a thought.

Someone contacted me off-list about doing the same thing for MacOS X,
which my employer wants as well. And I could imagine interest in similar
work for various BSDs and others. So yes, making the code base more
portable would make some people happy.

There were a few cases where I added #ifdefs and Makefile conditionals
that might affect other porters. Here are some suggestions for improving
the kexec-tools' portability; I hope somebody else can pick them up...

The largest affected pieces of code were for crashdump kernel loading. I
have no idea how to hook the BSOD in Windows. :-) Other platforms will
probably have the same problem. Allowing all crashdump support to be
disabled at compile time would be an independent helpful patch.

Some code is architecture-specific on Linux but may be platform-generic
elsewhere. The get_memory_ranges function is an example: I think the
copy in win32.c will work on all architectures that Windows supports,
but /proc/iomem apparently is formatted a little differently on
different Linux architectures. The physical_arch function I recently
introduced should be another example, though its implementation is
presently a bit kludged. I don't know how best to structure the code
when some implementations should be in arch/ and some shouldn't.

I think get_memory_ranges could stand to be completely refactored.
First, the kexec-tools only require RANGE_RAM, AFAICT, so parsing more
information out of /proc/iomem is wasted effort and extra maintenance
cost. Then, most implementations are very similar. Looking over all the
implementations and seeing how they can be unified would help.

Finally, there are a handful of features that are not very portable and
may not be so useful on other platforms anyway:
- shutdown/reboot
- current video mode detection
- reusing kernel command line or initrd
- bringing down network interfaces
Making it easier to omit those features at compile-time would help with
porting. I chose minimal-patch approaches for all of these, rather than
clean fixes.

 I'm not opposed to the patch as it is.

Awesome! I have very little time left to clean it up further, though
like you I wish I were offering a less-invasive patch.

 Can you advise if there is any way to cross compile this code on a Linux
 (i686) box?

Oh, I meant to mention that. I did all this development on a Debian
x86-64 box; I cross-compiled everything for 32-bit targets as that's all
I cared about. So my configure command is:

./configure --host=i586-mingw32msvc --target=i486-linux-gnu \
--build=x86_64-linux-gnu TARGET_CC=gcc -m32

(I overrode TARGET_CC because I don't have an i486-linux-gnu-gcc, just
the 64-bit GCC with -m32.)

 The licence in include/byteswap.h.  How does that effect the licencing
 of the rest of the code?  Is it going to cause any distributions - I am
 thinking about Debian - to have a cow?

I meant to mention that too. :-) Apparently the Cygwin license mentioned
there can be found here:
http://cygwin.com/license.html

It's GPLv2, with a special exception for linking with code that meets
the OSI's Open Source definition.

If anyone is concerned, byteswap.h can be rewritten from scratch in a
few minutes. :-) Last I checked, GCC on x86 generates the special x86
byte-swap instructions when fed the naive shift/or C implementation, so
byteswap.h doesn't need to be anything fancy.

 Lastly, I'm a big fan of = 80 character wide lines.

OK. I'll resubmit with 80-column line limits and the kernel brace style.

Jamey

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[RFC] Win32 port of the userspace tools using MinGW.

2008-05-16 Thread Jamey Sharp
OK, I haven't quite gotten around to posting the Windows kernel driver
source that goes with this. So I'm not asking that this patch be merged,
since nobody else can use it yet. :-) I'd love to get review, though:
Does this look like it's in a mergeable state? I'm happy with it, but do
I need to change anything to make it acceptable to you folks?

This patch requires basically all the other patches I've posted.


 Makefile.in   |1 +
 include/byteswap.h|   39 +++
 kexec/Makefile|6 +
 kexec/arch/i386/Makefile  |2 +
 kexec/arch/i386/kexec-x86.c   |2 +
 kexec/arch/i386/x86-linux-setup.c |4 +
 kexec/kexec-syscall.h |7 ++
 kexec/kexec.c |4 +
 kexec/kexec.h |   10 ++
 kexec/win32.c |  214 +
 10 files changed, 289 insertions(+), 0 deletions(-)
 create mode 100644 include/byteswap.h
 create mode 100644 kexec/win32.c

diff --git a/Makefile.in b/Makefile.in
index b51c3a1..bdd6ba7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,6 +24,7 @@ ARCH  = @ARCH@
 OBJDIR = @OBJDIR@
 target = @target@
 host   = @host@
+host_os= @host_os@
 
 # Compiler for building kexec
 CC = @CC@
diff --git a/include/byteswap.h b/include/byteswap.h
new file mode 100644
index 000..cd5a726
--- /dev/null
+++ b/include/byteswap.h
@@ -0,0 +1,39 @@
+/* byteswap.h
+
+Copyright 2005 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file CYGWIN_LICENSE for
+details. */
+
+#ifndef _BYTESWAP_H
+#define _BYTESWAP_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+static __inline unsigned short
+bswap_16 (unsigned short __x)
+{
+  return (__x  8) | (__x  8);
+}
+
+static __inline unsigned int
+bswap_32 (unsigned int __x)
+{
+  return (bswap_16 (__x  0x)  16) | (bswap_16 (__x  16));
+}
+
+static __inline unsigned long long
+bswap_64 (unsigned long long __x)
+{
+  return (((unsigned long long) bswap_32 (__x  0xull))  32) | 
(bswap_32 (__x  32));
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _BYTESWAP_H */
diff --git a/kexec/Makefile b/kexec/Makefile
index a80b940..fe05340 100644
--- a/kexec/Makefile
+++ b/kexec/Makefile
@@ -11,16 +11,22 @@ KEXEC_SRCS =
 KEXEC_GENERATED_SRCS =
 
 KEXEC_SRCS += kexec/kexec.c
+ifneq ($(host_os),mingw32msvc)
 KEXEC_SRCS += kexec/ifdown.c
+endif
 KEXEC_SRCS += kexec/kexec-elf.c
 KEXEC_SRCS += kexec/kexec-elf-exec.c
 KEXEC_SRCS += kexec/kexec-elf-core.c
 KEXEC_SRCS += kexec/kexec-elf-rel.c
 KEXEC_SRCS += kexec/kexec-elf-boot.c
 KEXEC_SRCS += kexec/kexec-iomem.c
+ifneq ($(host_os),mingw32msvc)
 KEXEC_SRCS += kexec/crashdump.c
 KEXEC_SRCS += kexec/crashdump-xen.c
 KEXEC_SRCS += kexec/phys_arch.c
+else
+KEXEC_SRCS += kexec/win32.c
+endif
 
 KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C)
 
diff --git a/kexec/arch/i386/Makefile b/kexec/arch/i386/Makefile
index f2d9636..f9dbb7b 100644
--- a/kexec/arch/i386/Makefile
+++ b/kexec/arch/i386/Makefile
@@ -9,7 +9,9 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c
 i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c
 i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c
 i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c
+ifneq ($(host_os),mingw32msvc)
 i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c
+endif
 
 dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS)\
kexec/arch/i386/kexec-x86.h kexec/arch/i386/crashdump-x86.h \
diff --git a/kexec/arch/i386/kexec-x86.c b/kexec/arch/i386/kexec-x86.c
index 89ccb0b..f937856 100644
--- a/kexec/arch/i386/kexec-x86.c
+++ b/kexec/arch/i386/kexec-x86.c
@@ -32,6 +32,7 @@
 #include crashdump-x86.h
 #include arch/options.h
 
+#ifndef __MINGW32__
 static struct memory_range memory_range[MAX_MEMORY_RANGES];
 
 /* Return a sorted list of memory ranges. */
@@ -113,6 +114,7 @@ int get_memory_ranges(struct memory_range **range, int 
*ranges,
*ranges = memory_ranges;
return 0;
 }
+#endif /* !defined(__MINGW32__) */
 
 struct file_type file_type[] = {
{ multiboot-x86, multiboot_x86_probe, multiboot_x86_load, 
diff --git a/kexec/arch/i386/x86-linux-setup.c 
b/kexec/arch/i386/x86-linux-setup.c
index 4b9a5e5..e750d82 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -23,8 +23,10 @@
 #include sys/types.h
 #include sys/stat.h
 #include fcntl.h
+#ifndef __MINGW32__
 #include sys/ioctl.h
 #include linux/fb.h
+#endif
 #include unistd.h
 #include x86/x86-linux.h
 #include ../../kexec.h
@@ -101,6 +103,7 @@ void setup_linux_bootloader_parameters(
 
 int setup_linux_vesafb(struct x86_linux_param_header *real_mode)
 {
+#ifndef __MINGW32__
struct fb_fix_screeninfo fix;
struct fb_var_screeninfo var;
int fd;
@@ -153,6 +156,7 @@ int setup_linux_vesafb(struct x86_linux_param_header 

[PATCH] Update KEXEC_ARCH_* constants from Linux kernel headers.

2008-05-16 Thread Jamey Sharp
Signed-off-by: Jamey Sharp [EMAIL PROTECTED]
---
I thought I'd need this, but it turned out not to matter. I'm submitting
it anyway because keeping kexec-tools in sync with the kernel kexec
headers seems like a good idea.

 kexec/kexec-syscall.h |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h
index d12a11c..2b9345f 100644
--- a/kexec/kexec-syscall.h
+++ b/kexec/kexec-syscall.h
@@ -82,8 +82,11 @@ static inline long kexec_reboot(void)
 #define KEXEC_ARCH_PPC (20  16)
 #define KEXEC_ARCH_PPC64   (21  16)
 #define KEXEC_ARCH_IA_64   (50  16)
-#define KEXEC_ARCH_S390(22  16)
 #define KEXEC_ARCH_ARM (40  16)
+#define KEXEC_ARCH_S390(22  16)
+#define KEXEC_ARCH_SH  (42  16)
+#define KEXEC_ARCH_MIPS_LE (10  16)
+#define KEXEC_ARCH_MIPS( 8  16)
 
 #define KEXEC_MAX_SEGMENTS 16
 
-- 
1.5.4.1


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH] Prototype ifdown() in kexec.h, not nested in main().

2008-05-15 Thread Jamey Sharp
Signed-off-by: Jamey Sharp [EMAIL PROTECTED]
---
Another generic patch extracted from my Windows porting work.

 kexec/kexec.c |3 +--
 kexec/kexec.h |2 ++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index f898428..de9765e 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -956,8 +956,7 @@ int main(int argc, char *argv[])
sync();
}
if ((result == 0)  do_ifdown) {
-   extern int ifdown(void);
-   (void)ifdown();
+   ifdown();
}
if ((result == 0)  do_exec) {
result = my_exec();
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 2d3a748..9b45476 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -209,6 +209,8 @@ extern unsigned long add_buffer_phys_virt(struct kexec_info 
*info,
int buf_end, int phys);
 extern void arch_reuse_initrd(void);
 
+extern int ifdown(void);
+
 extern unsigned char purgatory[];
 extern size_t purgatory_size;
 
-- 
1.5.4.1


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH] Open slurped files in binary mode, on systems where that matters.

2008-05-15 Thread Jamey Sharp
Signed-off-by: Jamey Sharp [EMAIL PROTECTED]
---
This patch shouldn't hurt any system that doesn't distinguish between
binary and text files, and helps when running on Windows.

 kexec/kexec.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index de9765e..1da6c1e 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -30,6 +30,9 @@
 #include sys/stat.h
 #include unistd.h
 #include fcntl.h
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
 #include getopt.h
 
 #include config.h
@@ -386,7 +389,7 @@ char *slurp_file(const char *filename, off_t *r_size)
*r_size = 0;
return 0;
}
-   fd = open(filename, O_RDONLY);
+   fd = open(filename, O_RDONLY | _O_BINARY);
if (fd  0) {
die(Cannot open `%s': %s\n,
filename, strerror(errno));
@@ -431,7 +434,7 @@ char *slurp_file_len(const char *filename, off_t size)
 
if (!filename)
return 0;
-   fd = open(filename, O_RDONLY);
+   fd = open(filename, O_RDONLY | _O_BINARY);
if (fd  0) {
fprintf(stderr, Cannot open %s: %s\n, filename,
strerror(errno));
-- 
1.5.4.1


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: kexec --real-mode

2008-04-30 Thread Jamey Sharp
On Wed, Apr 30, 2008 at 12:35:05PM -0700, Eric W. Biederman wrote:
 ... if we could ever figure out what we are doing that confuses the
 hardware the other path could be used.

In principle, purgatory could load GDB stubs and keep them around at
least long enough to debug code running in 16-bit mode, right? It would
be nice if somebody would do that. :-)

For a lot of my recent kexec work, I found it very helpful to use the
gdbserver in qemu, though I had to abandon it eventually due to
emulation bugs.

 For video mode changing it might be possible to just run the vga
 BIOS calls and make them work.

I was relying on vesafb in the kernel I wanted to boot. It turns out
that --real-mode works great on every machine I have handy, but doesn't
work for one of my co-workers. So I'm going to see if uvesafb works
better, in the next day or two hopefully.

http://dev.gentoo.org/~spock/projects/uvesafb/

I'm hoping that running the video BIOS in an x86 emulator works
reliably, and that that's the only boot failure I encounter. :-)

Jamey

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH 0/9] kexec userspace and purgatory cleanups

2008-04-22 Thread Jamey Sharp
GIT: Please enter your email below.
GIT: Lines beginning in GIT:  will be removed.
GIT: Consider including an overall diffstat or table of contents
GIT: for the patch you are writing.

This patch series fixes issues I encountered while porting kexec to run
on Windows. (I'll be happy to say more about that insane, but
surprisingly successful, plan on another occasion.) These patches,
however, are only the ones that affect the kexec userspace tools on
Linux. They fall into three categories.

Bug fixes, primarily in the i386 purgatory source:
- [1/9] Fix undefined symbol errors on readw/writew.
- [2/9] Fix copy-paste bug: entry16 does not start at entry16_debug.
- [3/9] Conform more closely to Documentation/i386/boot.txt.
- [9/9] Die on early EOF in slurp_file, instead of infinite-looping.

Compiler and assembler warning fixes:
- [4/9] Fix Warning: indirect jmp without `*'.
- [5/9] Fix all gcc warnings for ARCH=i386 builds.

Cleanups or simplifications:
- [6/9] sys/mman.h is not needed by any i386 kexec/ source.
- [7/9] Replace weak definitions with source filename overriding.
- [8/9] Simplify initialization of argument list for `shutdown`.

I believe each of these patches stands pretty well on its own, both in
independence from each other, and in being fairly self-explanatory.

These patches are against 9e959db12a671a71934a765d15aaf082f0a4f886 in
git://git.kernel.org/pub/scm/linux/kernel/git/horms/kexec-tools-testing.
Although, as they touch only code that hasn't seen much change recently,
they should apply cleanly to other versions.

I hope you'll consider including these patches in your next release of
the kexec userspace tools. If you would have preferred the patches in
some other form, please let me know, since I'll have some more patches
for your consideration later.

Thanks,
Jamey Sharp

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH 3/9] Conform more closely to Documentation/i386/boot.txt for bzImages.

2008-04-22 Thread Jamey Sharp
DS, ES, FS, and GS were all initialized to 0, but according to boot.txt
they need to point to setup_base. Recent kernel versions apparently rely
on this point of the spec, though earlier versions didn't.

Signed-off-by: Jamey Sharp [EMAIL PROTECTED]
---
This patch is arguably incomplete, since SS and SP are also not being
set as specified by boot.txt. However, it seems that nobody cares at
present, and I had other issues I wanted to address.

 kexec/arch/i386/kexec-bzImage.c |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index 93e37a4..abb094c 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
@@ -284,9 +284,12 @@ int do_bzImage_load(struct kexec_info *info,
/*
 * Initialize the 16bit start information.
 */
-   regs16.cs = (setup_base4) + 0x20;
+   regs16.ds = regs16.es = regs16.fs = regs16.gs = setup_base  4;
+   regs16.cs = regs16.ds + 0x20;
regs16.ip = 0;
+   /* XXX: Documentation/i386/boot.txt says 'ss' must equal 'ds' */
regs16.ss = (elf_rel_get_addr(info-rhdr, stack_end) - 64*1024)  4;
+   /* XXX: Documentation/i386/boot.txt says 'sp' must equal heap_end */
regs16.esp = 0xFFFC;
if (real_mode_entry) {
printf(Starting the kernel in real mode\n);
-- 
1.5.4.1


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec