Re: [PATCH v3 0/7] Fixup booting with device trees and uImage/elf on ppc32

2010-07-26 Thread Maxim Uvarov
2010/7/27 Simon Horman ho...@verge.net.au

 [Cced linuxppc-dev]

 On Tue, Jul 20, 2010 at 11:42:57PM -0500, Matthew McClintock wrote:
  This patch series adds full support for booting with a flat device tree
  with either uImage or elf file formats. Kexec and Kdump should work, and
  you should also be able to use ramdisks or reuse your current ramdisk as
 well
 
  This patch series was tested on an mpc85xx system with a kernel version
  2.6.35-rc3
 
  v1: Initial version
 
  v2: Added support for fs2dt (file system to device tree)
 
  v3: Fix some misc. git problems I had and other code cleanups

 Hi Matthew,

 I'm a little concerned that these changes are non trivial and haven't had
 much review. But I am prepared to put them into my tree once 2.0.2 is
 released - perhaps that way they will get some test coverage. Does
 that work for you?

 Actually  Matthew did that did not work before. Like kdump for booke. But
because kernel patches are not already in it's not urgent to commit it right
now.

 
  Matthew McClintock (7):
Restore kexec uImage-ppc to working state
Fix case where phys_addr_t != unsigned long when reading proc entries
Update uImage to support crash kernel and misc fixes
Update Elf-ppc to support crash kernel and misc fixes
Add support for ramdisk on ppc32 for uImage-ppc and Elf-ppc
Add support for reworking flat device tree support
Add documentation/howto for mpc85xx systems
 
   doc/mpc85xx.txt   |  190 +
   kexec/arch/ppc/Makefile   |1 +
   kexec/arch/ppc/fixup_dtb.c|  298
 -
   kexec/arch/ppc/fixup_dtb.h|6 +-
   kexec/arch/ppc/include/arch/options.h |3 +
   kexec/arch/ppc/kexec-elf-ppc.c|  186 +
   kexec/arch/ppc/kexec-ppc.c|  262
 +
   kexec/arch/ppc/kexec-ppc.h|3 +
   kexec/arch/ppc/kexec-uImage-ppc.c |  136 ---
   kexec/arch/ppc/ops.h  |1 -
   purgatory/arch/ppc/purgatory-ppc.c|5 +
   11 files changed, 852 insertions(+), 239 deletions(-)
   create mode 100644 doc/mpc85xx.txt
 
 
 
  ___
  kexec mailing list
  ke...@lists.infradead.org
  http://lists.infradead.org/mailman/listinfo/kexec




-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 1/2] Fix kexec on powerpc32

2010-05-13 Thread Maxim Uvarov
2010/5/13 Christian Kujau li...@nerdbynature.de

 On Wed, 12 May 2010 at 00:22, Christian Kujau wrote:
  # kexec -e
  Starting new kernel
  Bye!
 
  but then the system just hung there, no more messages, I had to
  powercycle it.

 Are there any debug flags (or kernel options?) I can set, to find out why
 it hangs here? Or does kexec not understand zImages?


zImage should not work with kexec. Only vmlinux.


 Thanks,
 Christian.
 --
 BOFH excuse #373:

 Suspicious pointer corrupted virtual machine




-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 1/2] Fix kexec on powerpc32

2010-05-12 Thread Maxim Uvarov
2010/5/12 Christian Kujau li...@nerdbynature.de

 Maxim Uvarov wrote on 2010-05-11 10:47 :
  This patch is required in case if you are using new toolchains.

 I'm on Debian/stable (binutils 2.18, gcc 4.3.2), so I applied your patches
 to the latest -git checkout:

 First, compilation fails with:

 cc1: warnings being treated as errors
 kexec/arch/ppc/kexec-ppc.c: In function ‘get_base_ranges’:
 kexec/arch/ppc/kexec-ppc.c:258: error: value computed is not used
 make: *** [kexec/arch/ppc/kexec-ppc.o] Error 1

 Somehow a - hyphen made it into one of the functions:

  --- a/kexec/arch/ppc/kexec-ppc.c
  +++ b/kexec/arch/ppc/kexec-ppc.c
 [...]
if (local_memory_ranges = max_memory_ranges) {
  - fclose(file);
  - break;
  + if (realloc_memory_ranges()  0){
  + -   fclose(file);

 Oh, I sent this patch twice with stg -a by mistake. And second version has
-. I will fix and resend patches.


 Removing this, gets me further, until:


 purgatory/arch/ppc/crt.o: In function `__lshrdi3':
 (.text+0xf0): multiple definition of `__lshrdi3'
 purgatory/arch/ppc/misc.o:(.text+0x50): first defined here
 collect2: ld returned 1 exit status
 make: *** [purgatory/purgatory.ro] Error 1

 And has been defined in purgatory/arch/ppc/crt.S and
 ./purgatory/arch/ppc/misc.S. Removing it from e.g. crt.S
 makes it compile, I have not tested it yet, though :-)


Yes, that is expected result for old tool chains. New tool chains (from code
sourcery )  need this crt.S.
I think we can have --with-oldtoolchain option to configure to point to old
tool chains. (or even rename it to --with-crts,
I don't know what is better.)


 Thanks,
 Christian.

 PS: Where is -Werror defined? I could not find it anywhere in the kexec
source (execpt in arch/mips)...
 --


This -Werror came from mips. kexec/arch/mips/Makefile. It is already removed
in the git. We already saw this problem.




 make bzImage, not war




-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v2 1/2] Fix kexec on powerpc32

2010-05-12 Thread Maxim Uvarov

Hello everybody,

  Changes from previous version:
  - removed bogus hyphen from the patch;
  - move ifdefs to crt.S instead of Makefile


  Please find here patch for user land kexec-tools application. Following
  patch makes kexec-tools work for both kexec and kdump. I tested it with 
  git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with 
  mpc83xx_defconfig kernel config.

  kexec:
  kexec -l vmlinux --command-line=console= ... etc
  kexec -e

  kdump:
  kexec -p vmlinux_dump --command-line=console=... etc
  echo c  /proc/sysrq-trigger

  I also think that is is reasonable:
  - put GAME_CUBE specific code to separate files;
  - combine  ppc and ppc64 to powerpc directory (I'm planning to do it.
And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Signed-off-by: Maxim Uvarov muva...@gmail.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 kexec/arch/ppc/Makefile|2 
 kexec/arch/ppc/crashdump-powerpc.c |  439 ++
 kexec/arch/ppc/crashdump-powerpc.h |   38 +++
 kexec/arch/ppc/fs2dt.c |  460 
 kexec/arch/ppc/kexec-elf-ppc.c |  186 +--
 kexec/arch/ppc/kexec-ppc.c |  275 --
 kexec/arch/ppc/kexec-ppc.h |   32 +++
 purgatory/arch/ppc/Makefile|2 
 purgatory/arch/ppc/purgatory-ppc.c |   38 ++-
 purgatory/arch/ppc/purgatory-ppc.h |4 
 purgatory/arch/ppc/v2wrap.S|   66 -
 purgatory/arch/ppc/v2wrap_32.S |   91 +++
 12 files changed, 1524 insertions(+), 109 deletions(-)
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.c
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.h
 create mode 100644 kexec/arch/ppc/fs2dt.c
 delete mode 100644 purgatory/arch/ppc/v2wrap.S
 create mode 100644 purgatory/arch/ppc/v2wrap_32.S

diff --git a/kexec/arch/ppc/Makefile b/kexec/arch/ppc/Makefile
index 1c7441c..5988213 100644
--- a/kexec/arch/ppc/Makefile
+++ b/kexec/arch/ppc/Makefile
@@ -11,6 +11,8 @@ ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-uImage-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/fixup_dtb.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/fs2dt.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/crashdump-powerpc.c
 ppc_KEXEC_SRCS += kexec/kexec-uImage.c
 
 libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c
diff --git a/kexec/arch/ppc/crashdump-powerpc.c 
b/kexec/arch/ppc/crashdump-powerpc.c
new file mode 100644
index 000..7bfad20
--- /dev/null
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -0,0 +1,439 @@
+#include stdio.h
+#include string.h
+#include stdlib.h
+#include unistd.h
+#include errno.h
+#include limits.h
+#include elf.h
+#include dirent.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ../../kexec.h
+#include ../../kexec-elf.h
+#include ../../kexec-syscall.h
+#include ../../crashdump.h
+#include kexec-ppc.h
+#include crashdump-powerpc.h
+
+#ifdef CONFIG_PPC64
+static struct crash_elf_info elf_info64 = {
+class: ELFCLASS64,
+data: ELFDATA2MSB,
+machine: EM_PPC64,
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+#endif
+static struct crash_elf_info elf_info32 = {
+class: ELFCLASS32,
+data: ELFDATA2MSB,
+#ifdef CONFIG_PPC64
+machine: EM_PPC64,
+#else
+machine: EM_PPC,
+#endif
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+
+/* Stores a sorted list of RAM memory ranges for which to create elf headers.
+ * A separate program header is created for backup region
+ */
+static struct memory_range *crash_memory_range;
+
+/* Define a variable to replace the CRASH_MAX_MEMORY_RANGES macro */
+static int crash_max_memory_ranges;
+
+/*
+ * Used to save various memory ranges/regions needed for the captured
+ * kernel to boot. (lime memmap= option in other archs)
+ */
+mem_rgns_t usablemem_rgns = {0, NULL};
+
+/*
+ * To store the memory size of the first kernel and this value will be
+ * passed to the second kernel as command line (savemaxmem=xM).
+ * The second kernel will be calculated saved_max_pfn based on this
+ * variable.
+ * Since we are creating/using usable-memory property, there is no way
+ * we can determine the RAM size unless parsing the device-tree/memoy@/reg
+ * property in the kernel.
+ */
+unsigned long long saved_max_mem;
+
+/* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to
+ * create Elf headers. Keeping it separate from get_memory_ranges() as
+ * requirements are different in the case of normal kexec and crashdumps.
+ *
+ * Normal kexec needs to look at all of available physical memory irrespective
+ * of the fact how much of it is being used by currently running kernel.
+ * Crashdumps need

[PATCH v2 2/2] powerpc new toolchains fix (crt.S)

2010-05-12 Thread Maxim Uvarov

Hello everybody,

  Changes from previous version:
  - removed bogus hyphen from the patch;
  - move ifdefs to crt.S instead of Makefile


  Please find here patch for user land kexec-tools application. Following
  patch makes kexec-tools work for both kexec and kdump. I tested it with 
  git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with 
  mpc83xx_defconfig kernel config.

  kexec:
  kexec -l vmlinux --command-line=console= ... etc
  kexec -e

  kdump:
  kexec -p vmlinux_dump --command-line=console=... etc
  echo c  /proc/sysrq-trigger

  I also think that is is reasonable:
  - put GAME_CUBE specific code to separate files;
  - combine  ppc and ppc64 to powerpc directory (I'm planning to do it.
And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Linker does not provide some vital functions when building freestanding
applications with a new toolchain, so we have to provide our own CRT.

p.s.
Without the CRT we won't see any build errors (since the purgatory is
linked with --no-undefined), but the purgatory code won't work,
'kexec -e' will just hang the board.


I added option to configure to keep code buildable for old toolchais.
But there should be way to do this automatically.

Author: Anton Vorontsov avoront...@ru.mvista.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 configure.ac|9 +
 purgatory/arch/ppc/Makefile |1 
 purgatory/arch/ppc/crt.S|  263 +++
 3 files changed, 273 insertions(+), 0 deletions(-)
 create mode 100644 purgatory/arch/ppc/crt.S

diff --git a/configure.ac b/configure.ac
index fcf50e4..63606bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,15 @@ if test $with_xen = yes ; then
AC_MSG_NOTICE([Xen support disabled])))
 fi
 
+dnl new toolchains
+if test $ARCH = ppc; then
+AC_ARG_WITH([oldtoolchain],
+   AC_HELP_STRING([--with-oldtoolchain],[compile without crt.S
+   required for new toolchains]),
+   AC_DEFINE(PPC_OLDTOOLCHAIN, 1,
+   [Define to compile with old toolchains]))
+fi
+
 dnl ---Sanity checks
 if test $CC  = no; then AC_MSG_ERROR([cc not found]); fi
 if test $CPP = no; then AC_MSG_ERROR([cpp not found]); fi
diff --git a/purgatory/arch/ppc/Makefile b/purgatory/arch/ppc/Makefile
index 72289a0..4020778 100644
--- a/purgatory/arch/ppc/Makefile
+++ b/purgatory/arch/ppc/Makefile
@@ -6,6 +6,7 @@ ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c
+ppc_PURGATORY_SRCS += purgatory/arch/ppc/crt.S
 
 dist += purgatory/arch/ppc/Makefile $(ppc_PURGATORY_SRCS)  \
purgatory/arch/ppc/purgatory-ppc.h purgatory/arch/ppc/ppc_asm.h
diff --git a/purgatory/arch/ppc/crt.S b/purgatory/arch/ppc/crt.S
new file mode 100644
index 000..70f4d61
--- /dev/null
+++ b/purgatory/arch/ppc/crt.S
@@ -0,0 +1,263 @@
+/* This is from linux-2.6/arch/powerpc/lib/crtsavres.S:
+ *
+ * Special support for eabi and SVR4
+ *
+ *   Copyright (C) 1995, 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
+ *   Copyright 2008 Freescale Semiconductor, Inc.
+ *   Written By Michael Meissner
+ *
+ * Based on gcc/config/rs6000/crtsavres.asm from gcc
+ *
+ * This file 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, or (at your option) any
+ * later version.
+ *
+ * In addition to the permissions in the GNU General Public License, the
+ * Free Software Foundation gives you unlimited permission to link the
+ * compiled version of this file with other programs, and to distribute
+ * those programs without any restriction coming from the use of this
+ * file.  (The General Public License restrictions do apply in other
+ * respects; for example, they cover modification of the file, and
+ * distribution when not linked into another program.)
+ *
+ * This file 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ *As a special exception, if you link this library with files
+ *compiled with GCC to produce an executable, this does not cause
+ *the resulting executable to be covered by the GNU General Public

Re: [PATCH 1/2] Fix kexec on powerpc32

2010-05-12 Thread Maxim Uvarov
2010/5/12 Christian Kujau li...@nerdbynature.de

 On Tue, 11 May 2010 at 21:47, Maxim Uvarov wrote:
  This patch is required in case if you are using new toolchains.

 After kexec-tools compiled, I actually tried it:

 # kexec -l /boot/2.6/zImage --command-line=root=/dev/hda6 ro
 # echo $?
 0
 # kexec -e
 Starting new kernel
 Bye!

 but then the system just hung there, no more messages, I had to
 powercycle it.

 The --debug options is listed for dol-ppc systems (I have a PowerBook
 G4, not sure if this falls into this category), when I use it the help
 screen of kexec is displayed again and at the bottom:

   Cannot load /boot/2.6/zImage


 This is with 2.6.34-rc7 (today's git):

 # file /boot/2.6/zImage
 /boot/2.6/zImage: ELF 32-bit MSB executable, PowerPC or cisco 4500,
 version 1 (SYSV), statically linked, with unknown capability 0x4100
 = 0x11676e75, with unknown capability 0x1 = 0x90402, not stripped


 .config and dmesg: http://nerdbynature.de/bits/2.6.34-rc7/kexec/

 Christian.
 --
 make bzImage, not war



Can you try vmlinux? I tested only with vmlinux.

-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] Fix kexec on powerpc32

2010-05-11 Thread Maxim Uvarov

Hello everybody,

  Please find here patch for user land kexec-tools application. Following
  patch makes kexec-tools work for both kexec and kdump. I tested it with 
  git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with 
  mpc83xx_defconfig kernel config.

  kexec:
  kexec -l vmlinux --command-line=console= ... etc
  kexec -e

  kdump:
  kexec -p vmlinux_dump --command-line=console=... etc
  echo c  /proc/sysrq-trigger

  I also think that is is reasonable:
  - put GAME_CUBE specific code to separate files;
  - combine  ppc and ppc64 to powerpc directory (I'm planning to do it.
And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Signed-off-by: Maxim Uvarov muva...@gmail.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 kexec/arch/ppc/Makefile|2 
 kexec/arch/ppc/crashdump-powerpc.c |  439 ++
 kexec/arch/ppc/crashdump-powerpc.h |   38 +++
 kexec/arch/ppc/fs2dt.c |  460 
 kexec/arch/ppc/kexec-elf-ppc.c |  186 +--
 kexec/arch/ppc/kexec-ppc.c |  276 --
 kexec/arch/ppc/kexec-ppc.h |   32 +++
 purgatory/arch/ppc/Makefile|2 
 purgatory/arch/ppc/purgatory-ppc.c |   38 ++-
 purgatory/arch/ppc/purgatory-ppc.h |4 
 purgatory/arch/ppc/v2wrap.S|   66 -
 purgatory/arch/ppc/v2wrap_32.S |   91 +++
 12 files changed, 1524 insertions(+), 110 deletions(-)
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.c
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.h
 create mode 100644 kexec/arch/ppc/fs2dt.c
 delete mode 100644 purgatory/arch/ppc/v2wrap.S
 create mode 100644 purgatory/arch/ppc/v2wrap_32.S

diff --git a/kexec/arch/ppc/Makefile b/kexec/arch/ppc/Makefile
index 1c7441c..5988213 100644
--- a/kexec/arch/ppc/Makefile
+++ b/kexec/arch/ppc/Makefile
@@ -11,6 +11,8 @@ ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-uImage-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/fixup_dtb.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/fs2dt.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/crashdump-powerpc.c
 ppc_KEXEC_SRCS += kexec/kexec-uImage.c
 
 libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c
diff --git a/kexec/arch/ppc/crashdump-powerpc.c 
b/kexec/arch/ppc/crashdump-powerpc.c
new file mode 100644
index 000..7bfad20
--- /dev/null
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -0,0 +1,439 @@
+#include stdio.h
+#include string.h
+#include stdlib.h
+#include unistd.h
+#include errno.h
+#include limits.h
+#include elf.h
+#include dirent.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ../../kexec.h
+#include ../../kexec-elf.h
+#include ../../kexec-syscall.h
+#include ../../crashdump.h
+#include kexec-ppc.h
+#include crashdump-powerpc.h
+
+#ifdef CONFIG_PPC64
+static struct crash_elf_info elf_info64 = {
+class: ELFCLASS64,
+data: ELFDATA2MSB,
+machine: EM_PPC64,
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+#endif
+static struct crash_elf_info elf_info32 = {
+class: ELFCLASS32,
+data: ELFDATA2MSB,
+#ifdef CONFIG_PPC64
+machine: EM_PPC64,
+#else
+machine: EM_PPC,
+#endif
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+
+/* Stores a sorted list of RAM memory ranges for which to create elf headers.
+ * A separate program header is created for backup region
+ */
+static struct memory_range *crash_memory_range;
+
+/* Define a variable to replace the CRASH_MAX_MEMORY_RANGES macro */
+static int crash_max_memory_ranges;
+
+/*
+ * Used to save various memory ranges/regions needed for the captured
+ * kernel to boot. (lime memmap= option in other archs)
+ */
+mem_rgns_t usablemem_rgns = {0, NULL};
+
+/*
+ * To store the memory size of the first kernel and this value will be
+ * passed to the second kernel as command line (savemaxmem=xM).
+ * The second kernel will be calculated saved_max_pfn based on this
+ * variable.
+ * Since we are creating/using usable-memory property, there is no way
+ * we can determine the RAM size unless parsing the device-tree/memoy@/reg
+ * property in the kernel.
+ */
+unsigned long long saved_max_mem;
+
+/* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to
+ * create Elf headers. Keeping it separate from get_memory_ranges() as
+ * requirements are different in the case of normal kexec and crashdumps.
+ *
+ * Normal kexec needs to look at all of available physical memory irrespective
+ * of the fact how much of it is being used by currently running kernel.
+ * Crashdumps need to have access to memory regions actually being used by
+ * running  kernel. Expecting a different file/data structure than /proc/iomem

[PATCH] [POWEPC] crashdump: do not fail on null pointer dereferencing

2010-05-11 Thread Maxim Uvarov
Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 arch/powerpc/kernel/crash.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/crash.c b/arch/powerpc/kernel/crash.c
index 6f4613d..341d8af 100644
--- a/arch/powerpc/kernel/crash.c
+++ b/arch/powerpc/kernel/crash.c
@@ -375,6 +375,9 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
for_each_irq(i) {
struct irq_desc *desc = irq_to_desc(i);
 
+   if (!desc || !desc-chip || !desc-chip-eoi)
+   continue;
+
if (desc-status  IRQ_INPROGRESS)
desc-chip-eoi(i);
 



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 1/2] Fix kexec on powerpc32

2010-05-11 Thread Maxim Uvarov

This patch is required in case if you are using new toolchains.

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 kexec/arch/ppc/Makefile|2 
 kexec/arch/ppc/crashdump-powerpc.c |  439 ++
 kexec/arch/ppc/crashdump-powerpc.h |   38 +++
 kexec/arch/ppc/fs2dt.c |  460 
 kexec/arch/ppc/kexec-elf-ppc.c |  186 +--
 kexec/arch/ppc/kexec-ppc.c |  276 --
 kexec/arch/ppc/kexec-ppc.h |   32 +++
 purgatory/arch/ppc/Makefile|2 
 purgatory/arch/ppc/purgatory-ppc.c |   38 ++-
 purgatory/arch/ppc/purgatory-ppc.h |4 
 purgatory/arch/ppc/v2wrap.S|   66 -
 purgatory/arch/ppc/v2wrap_32.S |   91 +++
 12 files changed, 1524 insertions(+), 110 deletions(-)
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.c
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.h
 create mode 100644 kexec/arch/ppc/fs2dt.c
 delete mode 100644 purgatory/arch/ppc/v2wrap.S
 create mode 100644 purgatory/arch/ppc/v2wrap_32.S

diff --git a/kexec/arch/ppc/Makefile b/kexec/arch/ppc/Makefile
index 1c7441c..5988213 100644
--- a/kexec/arch/ppc/Makefile
+++ b/kexec/arch/ppc/Makefile
@@ -11,6 +11,8 @@ ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-uImage-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/fixup_dtb.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/fs2dt.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/crashdump-powerpc.c
 ppc_KEXEC_SRCS += kexec/kexec-uImage.c
 
 libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c
diff --git a/kexec/arch/ppc/crashdump-powerpc.c 
b/kexec/arch/ppc/crashdump-powerpc.c
new file mode 100644
index 000..7bfad20
--- /dev/null
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -0,0 +1,439 @@
+#include stdio.h
+#include string.h
+#include stdlib.h
+#include unistd.h
+#include errno.h
+#include limits.h
+#include elf.h
+#include dirent.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ../../kexec.h
+#include ../../kexec-elf.h
+#include ../../kexec-syscall.h
+#include ../../crashdump.h
+#include kexec-ppc.h
+#include crashdump-powerpc.h
+
+#ifdef CONFIG_PPC64
+static struct crash_elf_info elf_info64 = {
+class: ELFCLASS64,
+data: ELFDATA2MSB,
+machine: EM_PPC64,
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+#endif
+static struct crash_elf_info elf_info32 = {
+class: ELFCLASS32,
+data: ELFDATA2MSB,
+#ifdef CONFIG_PPC64
+machine: EM_PPC64,
+#else
+machine: EM_PPC,
+#endif
+backup_src_start: BACKUP_SRC_START,
+backup_src_end: BACKUP_SRC_END,
+page_offset: PAGE_OFFSET,
+lowmem_limit: MAXMEM,
+};
+
+/* Stores a sorted list of RAM memory ranges for which to create elf headers.
+ * A separate program header is created for backup region
+ */
+static struct memory_range *crash_memory_range;
+
+/* Define a variable to replace the CRASH_MAX_MEMORY_RANGES macro */
+static int crash_max_memory_ranges;
+
+/*
+ * Used to save various memory ranges/regions needed for the captured
+ * kernel to boot. (lime memmap= option in other archs)
+ */
+mem_rgns_t usablemem_rgns = {0, NULL};
+
+/*
+ * To store the memory size of the first kernel and this value will be
+ * passed to the second kernel as command line (savemaxmem=xM).
+ * The second kernel will be calculated saved_max_pfn based on this
+ * variable.
+ * Since we are creating/using usable-memory property, there is no way
+ * we can determine the RAM size unless parsing the device-tree/memoy@/reg
+ * property in the kernel.
+ */
+unsigned long long saved_max_mem;
+
+/* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to
+ * create Elf headers. Keeping it separate from get_memory_ranges() as
+ * requirements are different in the case of normal kexec and crashdumps.
+ *
+ * Normal kexec needs to look at all of available physical memory irrespective
+ * of the fact how much of it is being used by currently running kernel.
+ * Crashdumps need to have access to memory regions actually being used by
+ * running  kernel. Expecting a different file/data structure than /proc/iomem
+ * to look into down the line. May be something like /proc/kernelmem or may
+ * be zone data structures exported from kernel.
+ */
+static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
+{
+
+   int memory_ranges = 0;
+   char device_tree[256] = /proc/device-tree/;
+   char fname[256];
+   char buf[MAXBYTES-1];
+   DIR *dir, *dmem;
+   FILE *file;
+   struct dirent *dentry, *mentry;
+   int i, n, crash_rng_len = 0;
+   unsigned long long start, end, cstart, cend;
+
+   crash_max_memory_ranges = max_memory_ranges + 6;
+   crash_rng_len = sizeof(struct memory_range) * crash_max_memory_ranges;
+
+   crash_memory_range = (struct

[PATCH 2/2] powerpc new toolchains fix (crt.S)

2010-05-11 Thread Maxim Uvarov

This patch is required in case if you are using new toolchains.

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Linker does not provide some vital functions when building freestanding
applications with a new toolchain, so we have to provide our own CRT.

p.s.
Without the CRT we won't see any build errors (since the purgatory is
linked with --no-undefined), but the purgatory code won't work,
'kexec -e' will just hang the board.


I added option to configure to keep code buildable for old toolchais.
But there should be way to do this automatically.

Author: Anton Vorontsov avoront...@ru.mvista.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 configure.ac|9 +
 purgatory/arch/ppc/Makefile |3 +++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index fcf50e4..63606bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,15 @@ if test $with_xen = yes ; then
AC_MSG_NOTICE([Xen support disabled])))
 fi
 
+dnl new toolchains
+if test $ARCH = ppc; then
+AC_ARG_WITH([oldtoolchain],
+   AC_HELP_STRING([--with-oldtoolchain],[compile without crt.S
+   required for new toolchains]),
+   AC_DEFINE(PPC_OLDTOOLCHAIN, 1,
+   [Define to compile with old toolchains]))
+fi
+
 dnl ---Sanity checks
 if test $CC  = no; then AC_MSG_ERROR([cc not found]); fi
 if test $CPP = no; then AC_MSG_ERROR([cpp not found]); fi
diff --git a/purgatory/arch/ppc/Makefile b/purgatory/arch/ppc/Makefile
index 72289a0..d11ec3e 100644
--- a/purgatory/arch/ppc/Makefile
+++ b/purgatory/arch/ppc/Makefile
@@ -6,6 +6,9 @@ ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c
+ifndef PPC_OLDTOOLCHAIN
+   ppc_PURGATORY_SRCS += purgatory/arch/ppc/crt.S
+endif
 
 dist += purgatory/arch/ppc/Makefile $(ppc_PURGATORY_SRCS)  \
purgatory/arch/ppc/purgatory-ppc.h purgatory/arch/ppc/ppc_asm.h



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] powerpc new toolchains fix (crt.S)

2010-05-11 Thread Maxim Uvarov
Forgot to add purgatory/arch/ppc/crt.S to the patch. Resending...

--
This patch is required in case if you are using new toolchains.

Best regards,
Maxim Uvarov.

From: Maxim Uvarov muva...@gmail.com

Linker does not provide some vital functions when building freestanding
applications with a new toolchain, so we have to provide our own CRT.

p.s.
Without the CRT we won't see any build errors (since the purgatory is
linked with --no-undefined), but the purgatory code won't work,
'kexec -e' will just hang the board.


I added option to configure to keep code buildable for old toolchais.
But there should be way to do this automatically.

Author: Anton Vorontsov avoront...@ru.mvista.com
Signed-off-by: Maxim Uvarov muva...@gmail.com
---

 configure.ac|9 +
 purgatory/arch/ppc/Makefile |3 
 purgatory/arch/ppc/crt.S|  262 +++
 3 files changed, 274 insertions(+), 0 deletions(-)
 create mode 100644 purgatory/arch/ppc/crt.S

diff --git a/configure.ac b/configure.ac
index fcf50e4..63606bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,15 @@ if test $with_xen = yes ; then
AC_MSG_NOTICE([Xen support disabled])))
 fi
 
+dnl new toolchains
+if test $ARCH = ppc; then
+AC_ARG_WITH([oldtoolchain],
+   AC_HELP_STRING([--with-oldtoolchain],[compile without crt.S
+   required for new toolchains]),
+   AC_DEFINE(PPC_OLDTOOLCHAIN, 1,
+   [Define to compile with old toolchains]))
+fi
+
 dnl ---Sanity checks
 if test $CC  = no; then AC_MSG_ERROR([cc not found]); fi
 if test $CPP = no; then AC_MSG_ERROR([cpp not found]); fi
diff --git a/purgatory/arch/ppc/Makefile b/purgatory/arch/ppc/Makefile
index 72289a0..d11ec3e 100644
--- a/purgatory/arch/ppc/Makefile
+++ b/purgatory/arch/ppc/Makefile
@@ -6,6 +6,9 @@ ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c
+ifndef PPC_OLDTOOLCHAIN
+   ppc_PURGATORY_SRCS += purgatory/arch/ppc/crt.S
+endif
 
 dist += purgatory/arch/ppc/Makefile $(ppc_PURGATORY_SRCS)  \
purgatory/arch/ppc/purgatory-ppc.h purgatory/arch/ppc/ppc_asm.h
diff --git a/purgatory/arch/ppc/crt.S b/purgatory/arch/ppc/crt.S
new file mode 100644
index 000..d7a44bd
--- /dev/null
+++ b/purgatory/arch/ppc/crt.S
@@ -0,0 +1,262 @@
+/* This is from linux-2.6/arch/powerpc/lib/crtsavres.S:
+ *
+ * Special support for eabi and SVR4
+ *
+ *   Copyright (C) 1995, 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
+ *   Copyright 2008 Freescale Semiconductor, Inc.
+ *   Written By Michael Meissner
+ *
+ * Based on gcc/config/rs6000/crtsavres.asm from gcc
+ *
+ * This file 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, or (at your option) any
+ * later version.
+ *
+ * In addition to the permissions in the GNU General Public License, the
+ * Free Software Foundation gives you unlimited permission to link the
+ * compiled version of this file with other programs, and to distribute
+ * those programs without any restriction coming from the use of this
+ * file.  (The General Public License restrictions do apply in other
+ * respects; for example, they cover modification of the file, and
+ * distribution when not linked into another program.)
+ *
+ * This file 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ *As a special exception, if you link this library with files
+ *compiled with GCC to produce an executable, this does not cause
+ *the resulting executable to be covered by the GNU General Public License.
+ *This exception does not however invalidate any other reasons why
+ *the executable file might be covered by the GNU General Public License.
+ */
+
+/* On PowerPC64 Linux, these functions are provided by the linker.  */
+#ifndef __powerpc64__
+
+#define _GLOBAL(name) \
+   .type name,@function; \
+   .globl name; \
+name:
+
+/* Routines for saving integer registers, called by the compiler.  */
+/* Called with r11 pointing to the stack header word of the caller of the */
+/* function, just beyond the end of the integer save area.  */
+
+_GLOBAL(_savegpr_14)
+_GLOBAL(_save32gpr_14)
+   stw 14,-72(11)  /* save gp registers */
+_GLOBAL(_savegpr_15)
+_GLOBAL(_save32gpr_15)
+   stw 15

Re: [PATCH] kexec-tools, ppc64: fix build error on ppc64

2010-05-05 Thread Maxim Uvarov
2010/5/5 Simon Horman ho...@verge.net.au

 On Wed, May 05, 2010 at 01:35:21PM +1000, Michael Neuling wrote:
 
 
  In message 20100505023316.gf13...@verge.net.au you wrote:
   On Wed, May 05, 2010 at 11:48:53AM +1000, Michael Neuling wrote:
6adc05c6e3fdbc8b9f5d915af78ca05d0a09cb17 some kexec MIPS
improvements broke pp64 as it turned on -Werror for all archs.
   
This fixes the warning and hence ppc64 building.
  
   Thanks.
  
   While I'm very much in favour of using -Werror for testing
   and these kind of patches are great, I think that -Werror
   by default is rather silly. We can't control what will be
   a warning in the future and sometimes fixing warnings isn't
   appropriate - for instance there are warnings in fs2dt.c at
   the moment, that is currently considered an upstream problem.
  
   In short, this patch is great. But I plan to also remove -Werror
   as the default now that its been brought to my attention.
 
  Cool.  My second patch should do this for all but MIPS.

 Unfortunately the second patch breaks make tarball.
 For now I have committed the following:

 From 76beff0507360f3001e23c9b4c765ef56384d5d5 Mon Sep 17 00:00:00 2001
 From: Simon Horman ho...@verge.net.au
 Date: Wed, 5 May 2010 13:33:21 +1000
 Subject: [PATCH] build: Don't modify CFLAGS in kexec/arch/mips/Makefile

 Revert this portion of recent MIPS changes as it actually effects the
 CFLAGS for all architectures.  Moreover I'm somewhat dubious about
 defaulting to -Werror for any architecture.

 Signed-off-by: Simon Horman ho...@verge.net.au
 ---
  kexec/arch/mips/Makefile |2 --
  1 files changed, 0 insertions(+), 2 deletions(-)

 diff --git a/kexec/arch/mips/Makefile b/kexec/arch/mips/Makefile
 index 831b263..03bdb9a 100644
 --- a/kexec/arch/mips/Makefile
 +++ b/kexec/arch/mips/Makefile
 @@ -14,5 +14,3 @@ dist += kexec/arch/mips/Makefile $(mips_KEXEC_SRCS)
 \
kexec/arch/mips/kexec-mips.h\
kexec/arch/mips/crashdump-mips.h\
kexec/arch/mips/include/arch/options.h
 -
 -CFLAGS +=-Wall -Werror
 --
 1.7.1


Plan was to have -Werror only for mips. Thanks for fixes.

-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: kexec for powerpc32

2010-04-01 Thread Maxim Uvarov

Christian Kujau wrote:

On Wed, 31 Mar 2010 at 17:23, Anton Vorontsov wrote:
  

Kernel has all needed for kexec, but kexec-tools are broken for
powerpc32.

http://www.mail-archive.com/linuxppc-dev@lists.ozlabs.org/msg22498.html



Oh :-\

  

I've just asked around, and it seems that Maxim (Cc'ed) will start
working on reviving ppc32 support real soon.



Well, in my case the powerpc32 machine is far from being a production 
system, but I'm glad to hear that he's working on it!


Thanks for the response,
Christian.
  

Yes,  the plan was to push upstream all MontaVista's powerpc kexec patches.
But also some work here is required in understanding how far community 
code from our,
port, cleanup and test patches. I hope that I will get to that task in 
this month.


Best regards,
Maxim Uvarov.



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH] kexec memory ranges dynamic allocation

2008-11-01 Thread Maxim Uvarov
2008/11/1 Simon Horman [EMAIL PROTECTED]

 On Fri, Oct 31, 2008 at 09:53:23AM +0300, Maxim Uvarov wrote:
  2008/10/31 Simon Horman [EMAIL PROTECTED]
 
   Hi,
  
   Could someone please comment on the satus of this patch?
  
  Hello,  Simon
 
  I can not reproduce  error which you wrote before on my target. So it is
 a
  little bit
  difficult to say what  was wrong exactly.

 Hi,

 the version of the patch below (which I think is the latest)
 compiles fine for me. I wanted to confirm that you
 and Chandru are happy for it to be merged.

 If so, could you please provide a short descripton for the change-log
 and a Signed-off-by line.

Patch looks good.

Description is:
   Do not count  max_memory_range for allocation. Increase allocation
buffers
   when it is needed. This actually allows us to avoid a lot of troubles
with
   various device-tree files.

Signed-off-by: Maxim Uvarov [EMAIL PROTECTED]



 Thanks

   On Wed, Oct 15, 2008 at 12:46:24PM +0400, Maxim Uvarov wrote:
Patch corrected. ( git_kexec_powerpc_v2.patch is attached.)
   
I tested it on ppc64 pasemi electra board. Both kexec -l and kexec -p
   works.
   
Maxim.
  
diff --git a/kexec/arch/ppc64/kexec-ppc64.c
   b/kexec/arch/ppc64/kexec-ppc64.c
index 069a9fc..0ad40fa 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -96,96 +96,46 @@ err1:
   
 }
   
-static int count_dyn_reconf_memory_ranges(void)
+static int realloc_memory_ranges()
 {
- char device_tree[] = /proc/device-tree/;
- char fname[128];
- char buf[32];
- FILE *file;
-
- strcpy(fname, device_tree);
- strcat(fname,
 ibm,dynamic-reconfiguration-memory/ibm,lmb-size);
- if ((file = fopen(fname, r)) == NULL) {
- perror(fname);
- return -1;
- }
+ size_t memory_range_len;
   
- if (fread(buf, 1, 8, file)  0) {
- perror(fname);
- fclose(file);
- return -1;
- }
-
- lmb_size = ((uint64_t *)buf)[0];
- fclose(file);
+ max_memory_ranges++;
+ memory_range_len = sizeof(struct memory_range) *
 max_memory_ranges;
   
- /* Get number of lmbs from ibm,dynamic-memory */
- strcpy(fname, device_tree);
- strcat(fname,
   ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory);
- if ((file = fopen(fname, r)) == NULL) {
- perror(fname);
- return -1;
- }
- /*
-  * first 4 bytes provide number of entries(lmbs)
-  */
- if (fread(buf, 1, 4, file)  0) {
- perror(fname);
- fclose(file);
- return -1;
- }
- num_of_lmbs = ((unsigned int *)buf)[0];
- max_memory_ranges += num_of_lmbs;
- fclose(file);
+ memory_range = (struct memory_range *) realloc(memory_range,
   memory_range_len);
+ if (!memory_range)
+ goto err;
   
- return 0;
-}
+ base_memory_range = (struct memory_range *)
 realloc(memory_range,
   memory_range_len);
+ if (!base_memory_range)
+ goto err;
   
-/*
- * Count the memory nodes under /proc/device-tree and populate the
- * max_memory_ranges variable. This variable replaces
 MAX_MEMORY_RANGES
- * macro used earlier.
- */
-static int count_memory_ranges(void)
-{
- char device_tree[256] = /proc/device-tree/;
- struct dirent *dentry;
- DIR *dir;
+ exclude_range = (struct memory_range *) realloc(exclude_range,
   memory_range_len);
+ if (!exclude_range)
+ goto err;
   
- if ((dir = opendir(device_tree)) == NULL) {
- perror(device_tree);
- return -1;
- }
+ usablemem_rgns.ranges = (struct memory_range *)
+ realloc(usablemem_rgns.ranges,
   memory_range_len);
+ if (!(usablemem_rgns.ranges))
+ goto err;
   
- while ((dentry = readdir(dir)) != NULL) {
- if (!strncmp(dentry-d_name,
- ibm,dynamic-reconfiguration-memory,
 35)){
- if (count_dyn_reconf_memory_ranges() != 0)
- return -1;
- continue;
- }
+ return 0;
   
- if (strncmp(dentry-d_name, memory@, 7) 
- strcmp(dentry-d_name, memory) 
- strncmp(dentry-d_name, pci@, 4))
- continue;
- max_memory_ranges++;
- }
- /* need to add extra region for retained initrd */
- if (reuse_initrd) {
- max_memory_ranges++;
- }
+err:
+ fprintf(stderr, memory range structure re-allocation
 failure\n);
+ return -1

Re: [PATCH] kexec memory ranges dynamic allocation

2008-10-31 Thread Maxim Uvarov
2008/10/31 Simon Horman [EMAIL PROTECTED]

 Hi,

 Could someone please comment on the satus of this patch?

Hello,  Simon

I can not reproduce  error which you wrote before on my target. So it is a
little bit
difficult to say what  was wrong exactly.


 On Wed, Oct 15, 2008 at 12:46:24PM +0400, Maxim Uvarov wrote:
  Patch corrected. ( git_kexec_powerpc_v2.patch is attached.)
 
  I tested it on ppc64 pasemi electra board. Both kexec -l and kexec -p
 works.
 
  Maxim.
 
 
 
  2008/10/15 Simon Horman [EMAIL PROTECTED]
 
   On Tue, Oct 14, 2008 at 07:11:19PM +0400, Maxim Uvarov wrote:
Hello all,
   
As you all know it is not easy to count exact value of memory ranges
 from
device tree on powerpc.
It very depends on how dts file was written. What do you think about
   really
dynamic allocation buffers
for this buffers?
  
   Conceptually I have no objections to the change,
   though I would like to get some review from ppc people.
   (linuxppc-dev@ozlabs.org CCed)
  
Patch is attached.
  
   This patch doesn't seem to compile for me.
  
   # powerpc64-unknown-linux-gnu-gcc --version
   powerpc64-unknown-linux-gnu-gcc (GCC) 4.1.1
   Copyright (C) 2006 Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.  There is
 NO
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.
  
   #make
   [snip]
   kexec/arch/ppc64/kexec-ppc64.c:100: warning: function declaration isn't
 a
   prototype
   kexec/arch/ppc64/kexec-ppc64.c: In function 'realloc_memory_ranges':
   kexec/arch/ppc64/kexec-ppc64.c:107: warning: passing argument 1 of
   'realloc' makes pointer from integer without a cast
   kexec/arch/ppc64/kexec-ppc64.c:107: error: too few arguments to
 function
   'realloc'
   kexec/arch/ppc64/kexec-ppc64.c:102: warning: unused variable 'tmp'
  
   --
   Simon Horman
VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
H: www.vergenet.net/~horms/ http://www.vergenet.net/%7Ehorms/ 
 http://www.vergenet.net/%7Ehorms/
 W: www.valinux.co.jp/en
  
  
 
 
  --
  Best regards,
  Maxim Uvarov

  diff --git a/kexec/arch/ppc64/kexec-ppc64.c
 b/kexec/arch/ppc64/kexec-ppc64.c
  index 069a9fc..0ad40fa 100644
  --- a/kexec/arch/ppc64/kexec-ppc64.c
  +++ b/kexec/arch/ppc64/kexec-ppc64.c
  @@ -96,96 +96,46 @@ err1:
 
   }
 
  -static int count_dyn_reconf_memory_ranges(void)
  +static int realloc_memory_ranges()
   {
  - char device_tree[] = /proc/device-tree/;
  - char fname[128];
  - char buf[32];
  - FILE *file;
  -
  - strcpy(fname, device_tree);
  - strcat(fname, ibm,dynamic-reconfiguration-memory/ibm,lmb-size);
  - if ((file = fopen(fname, r)) == NULL) {
  - perror(fname);
  - return -1;
  - }
  + size_t memory_range_len;
 
  - if (fread(buf, 1, 8, file)  0) {
  - perror(fname);
  - fclose(file);
  - return -1;
  - }
  -
  - lmb_size = ((uint64_t *)buf)[0];
  - fclose(file);
  + max_memory_ranges++;
  + memory_range_len = sizeof(struct memory_range) * max_memory_ranges;
 
  - /* Get number of lmbs from ibm,dynamic-memory */
  - strcpy(fname, device_tree);
  - strcat(fname,
 ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory);
  - if ((file = fopen(fname, r)) == NULL) {
  - perror(fname);
  - return -1;
  - }
  - /*
  -  * first 4 bytes provide number of entries(lmbs)
  -  */
  - if (fread(buf, 1, 4, file)  0) {
  - perror(fname);
  - fclose(file);
  - return -1;
  - }
  - num_of_lmbs = ((unsigned int *)buf)[0];
  - max_memory_ranges += num_of_lmbs;
  - fclose(file);
  + memory_range = (struct memory_range *) realloc(memory_range,
 memory_range_len);
  + if (!memory_range)
  + goto err;
 
  - return 0;
  -}
  + base_memory_range = (struct memory_range *) realloc(memory_range,
 memory_range_len);
  + if (!base_memory_range)
  + goto err;
 
  -/*
  - * Count the memory nodes under /proc/device-tree and populate the
  - * max_memory_ranges variable. This variable replaces MAX_MEMORY_RANGES
  - * macro used earlier.
  - */
  -static int count_memory_ranges(void)
  -{
  - char device_tree[256] = /proc/device-tree/;
  - struct dirent *dentry;
  - DIR *dir;
  + exclude_range = (struct memory_range *) realloc(exclude_range,
 memory_range_len);
  + if (!exclude_range)
  + goto err;
 
  - if ((dir = opendir(device_tree)) == NULL) {
  - perror(device_tree);
  - return -1;
  - }
  + usablemem_rgns.ranges = (struct memory_range *)
  + realloc(usablemem_rgns.ranges,
 memory_range_len);
  + if (!(usablemem_rgns.ranges))
  + goto err;
 
  - while ((dentry = readdir(dir)) != NULL) {
  - if (!strncmp(dentry-d_name

Re: [PATCH] kexec memory ranges dynamic allocation

2008-10-15 Thread Maxim Uvarov
2008/10/15 Simon Horman [EMAIL PROTECTED]

 On Tue, Oct 14, 2008 at 07:11:19PM +0400, Maxim Uvarov wrote:
  Hello all,
 
  As you all know it is not easy to count exact value of memory ranges from
  device tree on powerpc.
  It very depends on how dts file was written. What do you think about
 really
  dynamic allocation buffers
  for this buffers?

 Conceptually I have no objections to the change,
 though I would like to get some review from ppc people.
 (linuxppc-dev@ozlabs.org CCed)

  Patch is attached.

 This patch doesn't seem to compile for me.

 # powerpc64-unknown-linux-gnu-gcc --version
 powerpc64-unknown-linux-gnu-gcc (GCC) 4.1.1
 Copyright (C) 2006 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 #make
 [snip]
 kexec/arch/ppc64/kexec-ppc64.c:100: warning: function declaration isn't a
 prototype
 kexec/arch/ppc64/kexec-ppc64.c: In function 'realloc_memory_ranges':
 kexec/arch/ppc64/kexec-ppc64.c:107: warning: passing argument 1 of
 'realloc' makes pointer from integer without a cast
 kexec/arch/ppc64/kexec-ppc64.c:107: error: too few arguments to function
 'realloc'
 kexec/arch/ppc64/kexec-ppc64.c:102: warning: unused variable 'tmp'

Sorry  I edited manually formated patch before sending and lost first
argument to realloc. I will resend it.


 --
 Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/ http://www.vergenet.net/%7Ehorms/
   W: www.valinux.co.jp/en




-- 
Best regards,
Maxim Uvarov
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Re: [PATCH] kexec memory ranges dynamic allocation

2008-10-15 Thread Maxim Uvarov
Patch corrected. ( git_kexec_powerpc_v2.patch is attached.)

I tested it on ppc64 pasemi electra board. Both kexec -l and kexec -p works.

Maxim.



2008/10/15 Simon Horman [EMAIL PROTECTED]

 On Tue, Oct 14, 2008 at 07:11:19PM +0400, Maxim Uvarov wrote:
  Hello all,
 
  As you all know it is not easy to count exact value of memory ranges from
  device tree on powerpc.
  It very depends on how dts file was written. What do you think about
 really
  dynamic allocation buffers
  for this buffers?

 Conceptually I have no objections to the change,
 though I would like to get some review from ppc people.
 (linuxppc-dev@ozlabs.org CCed)

  Patch is attached.

 This patch doesn't seem to compile for me.

 # powerpc64-unknown-linux-gnu-gcc --version
 powerpc64-unknown-linux-gnu-gcc (GCC) 4.1.1
 Copyright (C) 2006 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 #make
 [snip]
 kexec/arch/ppc64/kexec-ppc64.c:100: warning: function declaration isn't a
 prototype
 kexec/arch/ppc64/kexec-ppc64.c: In function 'realloc_memory_ranges':
 kexec/arch/ppc64/kexec-ppc64.c:107: warning: passing argument 1 of
 'realloc' makes pointer from integer without a cast
 kexec/arch/ppc64/kexec-ppc64.c:107: error: too few arguments to function
 'realloc'
 kexec/arch/ppc64/kexec-ppc64.c:102: warning: unused variable 'tmp'

 --
 Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/ http://www.vergenet.net/%7Ehorms/
   W: www.valinux.co.jp/en




-- 
Best regards,
Maxim Uvarov
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index 069a9fc..0ad40fa 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -96,96 +96,46 @@ err1:
 
 }
 
-static int count_dyn_reconf_memory_ranges(void)
+static int realloc_memory_ranges()
 {
-	char device_tree[] = /proc/device-tree/;
-	char fname[128];
-	char buf[32];
-	FILE *file;
-
-	strcpy(fname, device_tree);
-	strcat(fname, ibm,dynamic-reconfiguration-memory/ibm,lmb-size);
-	if ((file = fopen(fname, r)) == NULL) {
-		perror(fname);
-		return -1;
-	}
+	size_t memory_range_len;
 
-	if (fread(buf, 1, 8, file)  0) {
-		perror(fname);
-		fclose(file);
-		return -1;
-	}
-
-	lmb_size = ((uint64_t *)buf)[0];
-	fclose(file);
+	max_memory_ranges++;
+	memory_range_len = sizeof(struct memory_range) * max_memory_ranges;
 
-	/* Get number of lmbs from ibm,dynamic-memory */
-	strcpy(fname, device_tree);
-	strcat(fname, ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory);
-	if ((file = fopen(fname, r)) == NULL) {
-		perror(fname);
-		return -1;
-	}
-	/*
-	 * first 4 bytes provide number of entries(lmbs)
-	 */
-	if (fread(buf, 1, 4, file)  0) {
-		perror(fname);
-		fclose(file);
-		return -1;
-	}
-	num_of_lmbs = ((unsigned int *)buf)[0];
-	max_memory_ranges += num_of_lmbs;
-	fclose(file);
+	memory_range = (struct memory_range *) realloc(memory_range, memory_range_len);
+	if (!memory_range)
+		goto err;
 
-	return 0;
-}
+	base_memory_range = (struct memory_range *) realloc(memory_range, memory_range_len);
+	if (!base_memory_range)
+		goto err;
 
-/*
- * Count the memory nodes under /proc/device-tree and populate the
- * max_memory_ranges variable. This variable replaces MAX_MEMORY_RANGES
- * macro used earlier.
- */
-static int count_memory_ranges(void)
-{
-	char device_tree[256] = /proc/device-tree/;
-	struct dirent *dentry;
-	DIR *dir;
+	exclude_range = (struct memory_range *) realloc(exclude_range, memory_range_len);
+	if (!exclude_range)
+		goto err;
 
-	if ((dir = opendir(device_tree)) == NULL) {
-		perror(device_tree);
-		return -1;
-	}
+	usablemem_rgns.ranges = (struct memory_range *)
+realloc(usablemem_rgns.ranges, memory_range_len);
+	if (!(usablemem_rgns.ranges))
+		goto err;
 
-	while ((dentry = readdir(dir)) != NULL) {
-		if (!strncmp(dentry-d_name,
-ibm,dynamic-reconfiguration-memory, 35)){
-			if (count_dyn_reconf_memory_ranges() != 0)
-return -1;
-			continue;
-		}
+	return 0;
 
-		if (strncmp(dentry-d_name, memory@, 7) 
-			strcmp(dentry-d_name, memory) 
-			strncmp(dentry-d_name, pci@, 4))
-			continue;
-		max_memory_ranges++;
-	}
-	/* need to add extra region for retained initrd */
-	if (reuse_initrd) {
-		max_memory_ranges++;
-	}
+err:
+	fprintf(stderr, memory range structure re-allocation failure\n);
+	return -1;
+}
 
-	closedir(dir);
 
-	return 0;
-}
 static void add_base_memory_range(uint64_t start, uint64_t end)
 {
 	base_memory_range[nr_memory_ranges].start = start;
 	base_memory_range[nr_memory_ranges].end  = end;
 	base_memory_range[nr_memory_ranges].type = RANGE_RAM;
 	nr_memory_ranges++;
+	if (nr_memory_ranges = max_memory_ranges) 
+		realloc_memory_ranges(); 
 
 	dbgprintf(%016llx-%016llx : %x\n,
 		base_memory_range[nr_memory_ranges-1].start,
@@ -300,8 +250,8 @@ static int get_base_ranges(void)
 return -1