Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package kexec-tools for openSUSE:Factory 
checked in at 2023-02-04 14:10:54
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/kexec-tools (Old)
 and      /work/SRC/openSUSE:Factory/.kexec-tools.new.4462 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "kexec-tools"

Sat Feb  4 14:10:54 2023 rev:146 rq:1062651 version:2.0.26

Changes:
--------
--- /work/SRC/openSUSE:Factory/kexec-tools/kexec-tools.changes  2023-01-08 
21:25:16.547153099 +0100
+++ /work/SRC/openSUSE:Factory/.kexec-tools.new.4462/kexec-tools.changes        
2023-02-04 14:18:04.754430042 +0100
@@ -1,0 +2,14 @@
+Thu Feb  2 13:45:39 UTC 2023 - Petr Tesařík <p...@tesarici.cz>
+
+- update to 2.0.26:
+  * m68k: pass rng seed via BI_RNG_SEED
+  * workflow: update to checkout@v3
+  * LoongArch: Remove redundant cmdline parameters when using --reuse-cmdline 
option
+  * LoongArch: Add purgatory framework code
+  * LoongArch: PE format image loading support
+  * LoongArch: Add kexec/kdump support
+  * config: Add LoongArch architecture support in config.guess and config.sub 
files
+  * ppc64: remove rma_top limit
+- refresh kexec-tools-riscv64.patch.
+
+-------------------------------------------------------------------

Old:
----
  kexec-tools-2.0.25.tar.sign
  kexec-tools-2.0.25.tar.xz

New:
----
  kexec-tools-2.0.26.tar.sign
  kexec-tools-2.0.26.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ kexec-tools.spec ++++++
--- /var/tmp/diff_new_pack.8E6IOX/_old  2023-02-04 14:18:05.334433200 +0100
+++ /var/tmp/diff_new_pack.8E6IOX/_new  2023-02-04 14:18:05.342433244 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package kexec-tools
 #
-# Copyright (c) 2022 SUSE LLC
+# Copyright (c) 2023 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
 
 
 Name:           kexec-tools
-Version:        2.0.25
+Version:        2.0.26
 Release:        0
 Summary:        Tools for loading replacement kernels into memory
 License:        GPL-2.0-or-later

++++++ kexec-tools-2.0.25.tar.xz -> kexec-tools-2.0.26.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/config/config.guess 
new/kexec-tools-2.0.26/config/config.guess
--- old/kexec-tools-2.0.25/config/config.guess  2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/config/config.guess  2022-11-18 16:11:40.000000000 
+0100
@@ -983,6 +983,9 @@
     k1om:Linux:*:*)
        echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
        exit ;;
+    loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*)
+       echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
+       exit ;;
     m32r*:Linux:*:*)
        echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
        exit ;;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/config/config.sub 
new/kexec-tools-2.0.26/config/config.sub
--- old/kexec-tools-2.0.25/config/config.sub    2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/config/config.sub    2022-11-18 16:11:40.000000000 
+0100
@@ -1185,6 +1185,7 @@
                        | k1om \
                        | le32 | le64 \
                        | lm32 \
+                       | loongarch32 | loongarch64 | loongarchx32 \
                        | m32c | m32r | m32rle \
                        | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | 
m68k \
                        | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/configure 
new/kexec-tools-2.0.26/configure
--- old/kexec-tools-2.0.25/configure    2022-07-31 08:40:15.000000000 +0200
+++ new/kexec-tools-2.0.26/configure    2022-12-21 16:28:43.000000000 +0100
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for kexec-tools 2.0.25.
+# Generated by GNU Autoconf 2.69 for kexec-tools 2.0.26.
 #
 #
 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@
 # Identity of this package.
 PACKAGE_NAME='kexec-tools'
 PACKAGE_TARNAME='kexec-tools'
-PACKAGE_VERSION='2.0.25'
-PACKAGE_STRING='kexec-tools 2.0.25'
+PACKAGE_VERSION='2.0.26'
+PACKAGE_STRING='kexec-tools 2.0.26'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL=''
 
@@ -1280,7 +1280,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures kexec-tools 2.0.25 to adapt to many kinds of systems.
+\`configure' configures kexec-tools 2.0.26 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1347,7 +1347,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of kexec-tools 2.0.25:";;
+     short | recursive ) echo "Configuration of kexec-tools 2.0.26:";;
    esac
   cat <<\_ACEOF
 
@@ -1437,7 +1437,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-kexec-tools configure 2.0.25
+kexec-tools configure 2.0.26
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1735,7 +1735,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by kexec-tools $as_me 2.0.25, which was
+It was created by kexec-tools $as_me 2.0.26, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -3062,6 +3062,9 @@
        hppa*)
                ARCH="hppa"
                ;;
+       loongarch*)
+               ARCH="loongarch"
+               ;;
        * )
                as_fn_error $? "unsupported architecture $target_cpu" "$LINENO" 
5
                ;;
@@ -5551,7 +5554,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by kexec-tools $as_me 2.0.25, which was
+This file was extended by kexec-tools $as_me 2.0.26, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5613,7 +5616,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; 
s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-kexec-tools config.status 2.0.25
+kexec-tools config.status 2.0.26
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/configure.ac 
new/kexec-tools-2.0.26/configure.ac
--- old/kexec-tools-2.0.25/configure.ac 2022-07-31 08:38:53.000000000 +0200
+++ new/kexec-tools-2.0.26/configure.ac 2022-12-21 16:28:33.000000000 +0100
@@ -4,7 +4,7 @@
 dnl 
 
 dnl ---Required
-AC_INIT(kexec-tools, 2.0.25)
+AC_INIT(kexec-tools, 2.0.26)
 AC_CONFIG_AUX_DIR(./config)
 AC_CONFIG_HEADERS([include/config.h])
 AC_LANG(C)
@@ -58,6 +58,9 @@
        hppa*)
                ARCH="hppa"
                ;;
+       loongarch*)
+               ARCH="loongarch"
+               ;;
        * )
                AC_MSG_ERROR([unsupported architecture $target_cpu])
                ;;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/include/config.h 
new/kexec-tools-2.0.26/include/config.h
--- old/kexec-tools-2.0.25/include/config.h     2022-07-31 08:40:16.000000000 
+0200
+++ new/kexec-tools-2.0.26/include/config.h     2022-12-21 16:29:24.000000000 
+0100
@@ -11,7 +11,7 @@
 #define HAVE_INTTYPES_H 1
 
 /* The kexec_status call is available */
-/* #undef HAVE_KEXEC_CMD_STATUS */
+#define HAVE_KEXEC_CMD_STATUS 1
 
 /* Define to 1 if you have the `dl' library (-ldl). */
 /* #undef HAVE_LIBDL */
@@ -20,7 +20,7 @@
 /* #undef HAVE_LIBLZMA */
 
 /* Define to 1 if you have the `xenctrl' library (-lxenctrl). */
-/* #undef HAVE_LIBXENCTRL */
+#define HAVE_LIBXENCTRL 1
 
 /* Define to 1 if you have the `z' library (-lz). */
 #define HAVE_LIBZ 1
@@ -56,7 +56,7 @@
 #define PACKAGE_NAME "kexec-tools"
 
 /* Define to the full name and version of this package. */
-#define PACKAGE_STRING "kexec-tools 2.0.25"
+#define PACKAGE_STRING "kexec-tools 2.0.26"
 
 /* Define to the one symbol short name of this package. */
 #define PACKAGE_TARNAME "kexec-tools"
@@ -65,7 +65,7 @@
 #define PACKAGE_URL ""
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "2.0.25"
+#define PACKAGE_VERSION "2.0.26"
 
 /* Define to 1 if you have the ANSI C header files. */
 #define STDC_HEADERS 1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/include/elf.h 
new/kexec-tools-2.0.26/include/elf.h
--- old/kexec-tools-2.0.25/include/elf.h        2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/include/elf.h        2022-11-18 16:11:40.000000000 
+0100
@@ -259,6 +259,7 @@
 #define EM_ARC_A5      93              /* ARC Cores Tangent-A5 */
 #define EM_XTENSA      94              /* Tensilica Xtensa Architecture */
 #define EM_AARCH64     183             /* ARM AARCH64 */
+#define EM_LOONGARCH   258             /* Loongson Loongarch*/
 #define EM_NUM         184
 
 /* If it is necessary to assign new unofficial EM_* values, please
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/include/image.h 
new/kexec-tools-2.0.26/include/image.h
--- old/kexec-tools-2.0.25/include/image.h      2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/include/image.h      2022-11-18 16:11:40.000000000 
+0100
@@ -86,6 +86,7 @@
 #define IH_ARCH_ARC            23      /* Synopsys DesignWare ARC */
 #define IH_ARCH_X86_64         24      /* AMD x86_64, Intel and Via */
 #define IH_ARCH_XTENSA         25      /* Xtensa       */
+#define IH_ARCH_LOONGARCH      26      /* LoongArch Loongson */
 
 /*
  * Image Types
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/Makefile 
new/kexec-tools-2.0.26/kexec/Makefile
--- old/kexec-tools-2.0.25/kexec/Makefile       2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/kexec/Makefile       2022-11-18 16:11:40.000000000 
+0100
@@ -92,6 +92,7 @@
 include $(srcdir)/kexec/arch/sh/Makefile
 include $(srcdir)/kexec/arch/x86_64/Makefile
 include $(srcdir)/kexec/arch/hppa/Makefile
+include $(srcdir)/kexec/arch/loongarch/Makefile
 
 KEXEC_SRCS += $($(ARCH)_KEXEC_SRCS)
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/arch/loongarch/Makefile 
new/kexec-tools-2.0.26/kexec/arch/loongarch/Makefile
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/Makefile        1970-01-01 
01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/Makefile        2022-11-18 
16:11:40.000000000 +0100
@@ -0,0 +1,22 @@
+#
+# kexec loongarch (linux booting linux)
+#
+loongarch_KEXEC_SRCS =  kexec/arch/loongarch/kexec-loongarch.c
+loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-loongarch.c
+loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-pei-loongarch.c
+loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-rel-loongarch.c
+loongarch_KEXEC_SRCS += kexec/arch/loongarch/crashdump-loongarch.c
+
+loongarch_MEM_REGIONS = kexec/mem_regions.c
+
+loongarch_CPPFLAGS += -I $(srcdir)/kexec/
+
+loongarch_ADD_BUFFER =
+loongarch_ADD_SEGMENT =
+loongarch_VIRT_TO_PHYS =
+
+dist += kexec/arch/loongarch/Makefile $(loongarch_KEXEC_SRCS)                  
\
+       kexec/arch/loongarch/kexec-loongarch.h                                  
\
+       kexec/arch/loongarch/image-header.h                                     
\
+       kexec/arch/loongarch/crashdump-loongarch.h                              
\
+       kexec/arch/loongarch/include/arch/options.h
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/crashdump-loongarch.c 
new/kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.c
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/crashdump-loongarch.c   
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.c   
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,198 @@
+/*
+ * LoongArch crashdump.
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited.
+ *   Youling Tang <tangyoul...@loongson.cn>
+ *
+ * derived from crashdump-arm64.c
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <linux/elf.h>
+
+#include "kexec.h"
+#include "crashdump.h"
+#include "crashdump-loongarch.h"
+#include "iomem.h"
+#include "kexec-loongarch.h"
+#include "kexec-elf.h"
+#include "mem_regions.h"
+
+/* memory ranges of crashed kernel */
+static struct memory_ranges system_memory_rgns;
+
+/* memory range reserved for crashkernel */
+struct memory_range crash_reserved_mem[CRASH_MAX_RESERVED_RANGES];
+struct memory_ranges usablemem_rgns = {
+       .size = 0,
+       .max_size = CRASH_MAX_RESERVED_RANGES,
+       .ranges = crash_reserved_mem,
+};
+
+struct memory_range elfcorehdr_mem;
+
+static struct crash_elf_info elf_info64 = {
+       .class          = ELFCLASS64,
+       .data           = ELFDATA2LSB,
+       .machine        = EM_LOONGARCH,
+       .page_offset    = PAGE_OFFSET,
+};
+
+/*
+ * iomem_range_callback() - callback called for each iomem region
+ * @data: not used
+ * @nr: not used
+ * @str: name of the memory region
+ * @base: start address of the memory region
+ * @length: size of the memory region
+ *
+ * This function is called once for each memory region found in /proc/iomem.
+ * It locates system RAM and crashkernel reserved memory and places these to
+ * variables, respectively, system_memory_rgns and usablemem_rgns.
+ */
+
+static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr),
+                               char *str, unsigned long long base,
+                               unsigned long long length)
+{
+       if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0)
+               return mem_regions_alloc_and_add(&usablemem_rgns,
+                                               base, length, RANGE_RAM);
+       else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0)
+               return mem_regions_alloc_and_add(&system_memory_rgns,
+                                               base, length, RANGE_RAM);
+       else if (strncmp(str, KERNEL_CODE, strlen(KERNEL_CODE)) == 0)
+               elf_info64.kern_paddr_start = base;
+       else if (strncmp(str, KERNEL_DATA, strlen(KERNEL_DATA)) == 0)
+               elf_info64.kern_size = base + length - 
elf_info64.kern_paddr_start;
+
+       return 0;
+}
+
+int is_crashkernel_mem_reserved(void)
+{
+       if (!usablemem_rgns.size)
+               kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL);
+
+       return usablemem_rgns.size;
+}
+
+/*
+ * crash_get_memory_ranges() - read system physical memory
+ *
+ * Function reads through system physical memory and stores found memory
+ * regions in system_memory_ranges.
+ * Regions are sorted in ascending order.
+ *
+ * Returns 0 in case of success and a negative value otherwise.
+ */
+static int crash_get_memory_ranges(void)
+{
+       int i;
+
+       /*
+        * First read all memory regions that can be considered as
+        * system memory including the crash area.
+        */
+       if (!usablemem_rgns.size)
+               kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL);
+
+       /* allow one or two regions for crash dump kernel */
+       if (!usablemem_rgns.size)
+               return -EINVAL;
+
+       dbgprint_mem_range("Reserved memory range",
+                       usablemem_rgns.ranges, usablemem_rgns.size);
+
+       for (i = 0; i < usablemem_rgns.size; i++) {
+               if (mem_regions_alloc_and_exclude(&system_memory_rgns,
+                                       &crash_reserved_mem[i])) {
+                       fprintf(stderr, "Cannot allocate memory for ranges\n");
+                       return -ENOMEM;
+               }
+       }
+
+       /*
+        * Make sure that the memory regions are sorted.
+        */
+       mem_regions_sort(&system_memory_rgns);
+
+       dbgprint_mem_range("Coredump memory ranges",
+                          system_memory_rgns.ranges, system_memory_rgns.size);
+
+       /*
+        * For additional kernel code/data segment.
+        * kern_paddr_start/kern_size are determined in iomem_range_callback
+        */
+       elf_info64.kern_vaddr_start = get_kernel_sym("_text");
+       if (!elf_info64.kern_vaddr_start)
+               elf_info64.kern_vaddr_start = UINT64_MAX;
+
+       return 0;
+}
+
+/*
+ * load_crashdump_segments() - load the elf core header
+ * @info: kexec info structure
+ *
+ * This function creates and loads an additional segment of elf core header
+ : which is used to construct /proc/vmcore on crash dump kernel.
+ *
+ * Return 0 in case of success and -1 in case of error.
+ */
+
+int load_crashdump_segments(struct kexec_info *info)
+{
+       unsigned long elfcorehdr;
+       unsigned long bufsz;
+       void *buf;
+       int err;
+
+       /*
+        * First fetch all the memory (RAM) ranges that we are going to
+        * pass to the crash dump kernel during panic.
+        */
+
+       err = crash_get_memory_ranges();
+
+       if (err)
+               return EFAILED;
+
+       err = crash_create_elf64_headers(info, &elf_info64,
+                       system_memory_rgns.ranges, system_memory_rgns.size,
+                       &buf, &bufsz, ELF_CORE_HEADER_ALIGN);
+
+       if (err)
+               return EFAILED;
+
+       elfcorehdr = add_buffer(info, buf, bufsz, bufsz, 1024,
+               crash_reserved_mem[usablemem_rgns.size - 1].start,
+               crash_reserved_mem[usablemem_rgns.size - 1].end, -1);
+
+       elfcorehdr_mem.start = elfcorehdr;
+       elfcorehdr_mem.end = elfcorehdr + bufsz - 1;
+
+       dbgprintf("%s: elfcorehdr 0x%llx-0x%llx\n", __func__,
+                       elfcorehdr_mem.start, elfcorehdr_mem.end);
+
+       return 0;
+}
+
+int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
+{
+       if (!usablemem_rgns.size)
+               kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL);
+
+       if (!usablemem_rgns.size)
+               return -1;
+
+       *start = crash_reserved_mem[usablemem_rgns.size - 1].start;
+       *end = crash_reserved_mem[usablemem_rgns.size - 1].end;
+
+       return 0;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/crashdump-loongarch.h 
new/kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.h
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/crashdump-loongarch.h   
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.h   
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,25 @@
+#ifndef CRASHDUMP_LOONGARCH_H
+#define CRASHDUMP_LOONGARCH_H
+
+struct kexec_info;
+extern struct memory_ranges usablemem_rgns;
+extern struct memory_range crash_reserved_mem[];
+extern struct memory_range elfcorehdr_mem;
+
+int load_crashdump_segments(struct kexec_info *info);
+int is_crashkernel_mem_reserved(void);
+int get_crash_kernel_load_range(uint64_t *start, uint64_t *end);
+
+#define PAGE_OFFSET    0x9000000000000000ULL
+#define MAXMEM         0
+
+#define CRASH_MAX_MEMMAP_NR    (KEXEC_MAX_SEGMENTS + 1)
+#define CRASH_MAX_MEMORY_RANGES        (MAX_MEMORY_RANGES + 2)
+
+/* crash dump kernel support at most two regions, low_region and high region. 
*/
+#define CRASH_MAX_RESERVED_RANGES      2
+
+#define COMMAND_LINE_SIZE      512
+
+extern struct arch_options_t arch_options;
+#endif /* CRASHDUMP_LOONGARCH_H */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/image-header.h 
new/kexec-tools-2.0.26/kexec/arch/loongarch/image-header.h
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/image-header.h  1970-01-01 
01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/image-header.h  2022-11-18 
16:11:40.000000000 +0100
@@ -0,0 +1,79 @@
+/*
+ * LoongArch binary image header.
+ */
+
+#if !defined(__LOONGARCH_IMAGE_HEADER_H)
+#define __LOONGARCH_IMAGE_HEADER_H
+
+#include <endian.h>
+#include <stdint.h>
+
+/**
+ * struct loongarch_image_header
+ *
+ * @pe_sig: Optional PE format 'MZ' signature.
+ * @reserved_1: Reserved.
+ * @kernel_entry: Kernel image entry pointer.
+ * @image_size: An estimated size of the memory image size in LSB byte order.
+ * @text_offset: The image load offset in LSB byte order.
+ * @reserved_2: Reserved.
+ * @reserved_3: Reserved.
+ * @pe_header: Optional offset to a PE format header.
+ **/
+
+struct loongarch_image_header {
+       uint8_t pe_sig[2];
+       uint16_t reserved_1[3];
+       uint64_t kernel_entry;
+       uint64_t image_size;
+       uint64_t text_offset;
+       uint64_t reserved_2[3];
+       uint32_t reserved_3;
+       uint32_t pe_header;
+};
+
+static const uint8_t loongarch_image_pe_sig[2] = {'M', 'Z'};
+
+/**
+ * loongarch_header_check_pe_sig - Helper to check the loongarch image header.
+ *
+ * Returns non-zero if 'MZ' signature is found.
+ */
+
+static inline int loongarch_header_check_pe_sig(const struct 
loongarch_image_header *h)
+{
+       if (!h)
+               return 0;
+
+       return (h->pe_sig[0] == loongarch_image_pe_sig[0]
+               && h->pe_sig[1] == loongarch_image_pe_sig[1]);
+}
+
+static inline uint64_t loongarch_header_text_offset(
+       const struct loongarch_image_header *h)
+{
+       if (!h)
+               return 0;
+
+       return le64toh(h->text_offset);
+}
+
+static inline uint64_t loongarch_header_image_size(
+       const struct loongarch_image_header *h)
+{
+       if (!h)
+               return 0;
+
+       return le64toh(h->image_size);
+}
+
+static inline uint64_t loongarch_header_kernel_entry(
+       const struct loongarch_image_header *h)
+{
+       if (!h)
+               return 0;
+
+       return le64toh(h->kernel_entry);
+}
+
+#endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/include/arch/options.h 
new/kexec-tools-2.0.26/kexec/arch/loongarch/include/arch/options.h
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/include/arch/options.h  
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/include/arch/options.h  
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,28 @@
+#ifndef KEXEC_ARCH_LOONGARCH_OPTIONS_H
+#define KEXEC_ARCH_LOONGARCH_OPTIONS_H
+
+#define OPT_APPEND             ((OPT_MAX)+0)
+#define OPT_INITRD             ((OPT_MAX)+1)
+#define OPT_REUSE_CMDLINE      ((OPT_MAX)+2)
+#define OPT_ARCH_MAX           ((OPT_MAX)+3)
+
+#define KEXEC_ARCH_OPTIONS \
+       KEXEC_OPTIONS \
+       { "append",        1, NULL, OPT_APPEND }, \
+       { "command-line",  1, NULL, OPT_APPEND }, \
+       { "initrd",        1, NULL, OPT_INITRD }, \
+       { "ramdisk",       1, NULL, OPT_INITRD }, \
+       { "reuse-cmdline", 0, NULL, OPT_REUSE_CMDLINE }, \
+
+#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR /* Only accept long arch options. */
+#define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS
+#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR
+
+static const char loongarch_opts_usage[] __attribute__ ((unused)) =
+"     --append=STRING       Set the kernel command line to STRING.\n"
+"     --command-line=STRING Set the kernel command line to STRING.\n"
+"     --initrd=FILE         Use FILE as the kernel initial ramdisk.\n"
+"     --ramdisk=FILE        Use FILE as the kernel initial ramdisk.\n"
+"     --reuse-cmdline       Use kernel command line from running system.\n";
+
+#endif /* KEXEC_ARCH_LOONGARCH_OPTIONS_H */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-elf-loongarch.c 
new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-elf-loongarch.c   
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c   
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,117 @@
+/*
+ * kexec-elf-loongarch.c - kexec Elf loader for loongarch
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited.
+ *   Youling Tang <tangyoul...@loongson.cn>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+*/
+
+#define _GNU_SOURCE
+
+#include <limits.h>
+#include <errno.h>
+#include <elf.h>
+
+#include "kexec.h"
+#include "kexec-elf.h"
+#include "kexec-syscall.h"
+#include "crashdump-loongarch.h"
+#include "kexec-loongarch.h"
+#include "arch/options.h"
+
+off_t initrd_base, initrd_size;
+
+int elf_loongarch_probe(const char *kernel_buf, off_t kernel_size)
+{
+       struct mem_ehdr ehdr;
+       int result;
+
+       result = build_elf_exec_info(kernel_buf, kernel_size, &ehdr, 0);
+       if (result < 0) {
+               dbgprintf("%s: Not an ELF executable.\n", __func__);
+               goto out;
+       }
+
+       /* Verify the architecuture specific bits. */
+       if (ehdr.e_machine != EM_LOONGARCH) {
+               dbgprintf("%s: Not an LoongArch ELF executable.\n", __func__);
+               result = -1;
+               goto out;
+       }
+
+       result = 0;
+out:
+       free_elf_info(&ehdr);
+       return result;
+}
+
+int elf_loongarch_load(int argc, char **argv, const char *kernel_buf,
+       off_t kernel_size, struct kexec_info *info)
+{
+       const struct loongarch_image_header *header = NULL;
+       unsigned long kernel_segment;
+       struct mem_ehdr ehdr;
+       int result;
+
+       result = build_elf_exec_info(kernel_buf, kernel_size, &ehdr, 0);
+
+       if (result < 0) {
+               dbgprintf("%s: build_elf_exec_info failed\n", __func__);
+               goto exit;
+       }
+
+       kernel_segment = loongarch_locate_kernel_segment(info);
+
+       if (kernel_segment == ULONG_MAX) {
+               dbgprintf("%s: Kernel segment is not allocated\n", __func__);
+               result = EFAILED;
+               goto exit;
+       }
+
+       dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment);
+       dbgprintf("%s: image_size:     %016lx\n", __func__,
+               kernel_size);
+       dbgprintf("%s: text_offset:    %016lx\n", __func__,
+               loongarch_mem.text_offset);
+       dbgprintf("%s: phys_offset:    %016lx\n", __func__,
+               loongarch_mem.phys_offset);
+       dbgprintf("%s: PE format:      %s\n", __func__,
+               (loongarch_header_check_pe_sig(header) ? "yes" : "no"));
+
+       /* create and initialize elf core header segment */
+       if (info->kexec_flags & KEXEC_ON_CRASH) {
+               result = load_crashdump_segments(info);
+               if (result) {
+                       dbgprintf("%s: Creating eflcorehdr failed.\n",
+                                                               __func__);
+                       goto exit;
+               }
+       }
+
+       info->entry = (void *)virt_to_phys(ehdr.e_entry);
+
+       result = elf_exec_load(&ehdr, info);
+
+       if (result) {
+               dbgprintf("%s: elf_exec_load failed\n", __func__);
+               goto exit;
+       }
+
+       /* load additional data */
+       result = loongarch_load_other_segments(info, kernel_segment + 
kernel_size);
+
+exit:
+       free_elf_info(&ehdr);
+       if (result)
+               fprintf(stderr, "kexec: Bad elf image file, load failed.\n");
+       return result;
+}
+
+void elf_loongarch_usage(void)
+{
+       printf(
+"     An LoongArch ELF image, little endian.\n"
+"     Typically vmlinux or a stripped version of vmlinux.\n\n");
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-elf-rel-loongarch.c 
new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-rel-loongarch.c
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-elf-rel-loongarch.c       
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-rel-loongarch.c       
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,42 @@
+/*
+ * kexec-elf-rel-loongarch.c - kexec Elf relocation routines
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited.
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+*/
+
+#include <stdio.h>
+#include <elf.h>
+#include "../../kexec.h"
+#include "../../kexec-elf.h"
+
+int machine_verify_elf_rel(struct mem_ehdr *ehdr)
+{
+       if (ehdr->ei_data != ELFDATA2MSB)
+               return 0;
+
+       if (ehdr->ei_class != ELFCLASS32)
+               return 0;
+
+       if (ehdr->e_machine != EM_LOONGARCH)
+               return 0;
+
+       return 1;
+}
+
+void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr),
+                          struct mem_sym *UNUSED(sym),
+                          unsigned long r_type,
+                          void *UNUSED(location),
+                          unsigned long UNUSED(address),
+                          unsigned long UNUSED(value))
+{
+       switch (r_type) {
+
+       default:
+               die("Unknown rela relocation: %lu\n", r_type);
+               break;
+       }
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-loongarch.c 
new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-loongarch.c       
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c       
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,374 @@
+/*
+ * kexec-loongarch.c - kexec for loongarch
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited.
+ *   Youling Tang <tangyoul...@loongson.cn>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <getopt.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <linux/elf-em.h>
+#include <elf.h>
+#include <elf_info.h>
+
+#include "kexec.h"
+#include "kexec-loongarch.h"
+#include "crashdump-loongarch.h"
+#include "iomem.h"
+#include "kexec-syscall.h"
+#include "mem_regions.h"
+#include "arch/options.h"
+
+#define CMDLINE_PREFIX "kexec "
+static char cmdline[COMMAND_LINE_SIZE] = CMDLINE_PREFIX;
+
+/* Adds "initrd=start,size" parameters to command line. */
+static int cmdline_add_initrd(char *cmdline, unsigned long addr,
+               unsigned long size)
+{
+       int cmdlen, len;
+       char str[50], *ptr;
+
+       ptr = str;
+       strcpy(str, " initrd=");
+       ptr += strlen(str);
+       ultoa(addr, ptr);
+       strcat(str, ",");
+       ptr = str + strlen(str);
+       ultoa(size, ptr);
+       len = strlen(str);
+       cmdlen = strlen(cmdline) + len;
+       if (cmdlen > (COMMAND_LINE_SIZE - 1))
+               die("Command line overflow\n");
+       strcat(cmdline, str);
+
+       return 0;
+}
+
+/* Adds the appropriate "mem=size@start" options to command line, indicating 
the
+ * memory region the new kernel can use to boot into. */
+static int cmdline_add_mem(char *cmdline, unsigned long addr,
+               unsigned long size)
+{
+       int cmdlen, len;
+       char str[50], *ptr;
+
+       addr = addr/1024;
+       size = size/1024;
+       ptr = str;
+       strcpy(str, " mem=");
+       ptr += strlen(str);
+       ultoa(size, ptr);
+       strcat(str, "K@");
+       ptr = str + strlen(str);
+       ultoa(addr, ptr);
+       strcat(str, "K");
+       len = strlen(str);
+       cmdlen = strlen(cmdline) + len;
+       if (cmdlen > (COMMAND_LINE_SIZE - 1))
+               die("Command line overflow\n");
+       strcat(cmdline, str);
+
+       return 0;
+}
+
+/* Adds the "elfcorehdr=size@start" command line parameter to command line. */
+static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr,
+                       unsigned long size)
+{
+       int cmdlen, len;
+       char str[50], *ptr;
+
+       addr = addr/1024;
+       size = size/1024;
+       ptr = str;
+       strcpy(str, " elfcorehdr=");
+       ptr += strlen(str);
+       ultoa(size, ptr);
+       strcat(str, "K@");
+       ptr = str + strlen(str);
+       ultoa(addr, ptr);
+       strcat(str, "K");
+       len = strlen(str);
+       cmdlen = strlen(cmdline) + len;
+       if (cmdlen > (COMMAND_LINE_SIZE - 1))
+               die("Command line overflow\n");
+       strcat(cmdline, str);
+
+       return 0;
+}
+
+/* Return a sorted list of memory ranges. */
+static struct memory_range memory_range[MAX_MEMORY_RANGES];
+
+int get_memory_ranges(struct memory_range **range, int *ranges,
+                     unsigned long UNUSED(kexec_flags))
+{
+       int memory_ranges = 0;
+
+       const char *iomem = proc_iomem();
+       char line[MAX_LINE];
+       FILE *fp;
+       unsigned long long start, end;
+       char *str;
+       int type, consumed, count;
+
+       fp = fopen(iomem, "r");
+       if (!fp) {
+               fprintf(stderr, "Cannot open %s: %s\n", iomem, strerror(errno));
+               return -1;
+       }
+
+       while (fgets(line, sizeof(line), fp) != 0) {
+               if (memory_ranges >= MAX_MEMORY_RANGES)
+                       break;
+               count = sscanf(line, "%llx-%llx : %n", &start, &end, &consumed);
+               if (count != 2)
+                       continue;
+               str = line + consumed;
+               end = end + 1;
+               if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)))
+                       type = RANGE_RAM;
+               else if (!strncmp(str, IOMEM_RESERVED, strlen(IOMEM_RESERVED)))
+                       type = RANGE_RESERVED;
+               else
+                       continue;
+
+               if (memory_ranges > 0 &&
+                   memory_range[memory_ranges - 1].end == start &&
+                   memory_range[memory_ranges - 1].type == type) {
+                       memory_range[memory_ranges - 1].end = end;
+               } else {
+                       memory_range[memory_ranges].start = start;
+                       memory_range[memory_ranges].end = end;
+                       memory_range[memory_ranges].type = type;
+                       memory_ranges++;
+               }
+       }
+       fclose(fp);
+       *range = memory_range;
+       *ranges = memory_ranges;
+
+       dbgprint_mem_range("MEMORY RANGES:", *range, *ranges);
+       return 0;
+}
+
+struct file_type file_type[] = {
+       {"elf-loongarch", elf_loongarch_probe, elf_loongarch_load, 
elf_loongarch_usage},
+       {"pei-loongarch", pei_loongarch_probe, pei_loongarch_load, 
pei_loongarch_usage},
+};
+int file_types = sizeof(file_type) / sizeof(file_type[0]);
+
+/* loongarch global varables. */
+
+struct loongarch_mem loongarch_mem;
+
+/**
+ * loongarch_process_image_header - Process the loongarch image header.
+ */
+
+int loongarch_process_image_header(const struct loongarch_image_header *h)
+{
+
+       if (!loongarch_header_check_pe_sig(h))
+               return EFAILED;
+
+       if (h->image_size) {
+               loongarch_mem.text_offset = loongarch_header_text_offset(h);
+               loongarch_mem.image_size = loongarch_header_image_size(h);
+       }
+
+       return 0;
+}
+
+void arch_usage(void)
+{
+       printf(loongarch_opts_usage);
+}
+
+struct arch_options_t arch_options = {
+       .core_header_type = CORE_TYPE_ELF64,
+};
+
+int arch_process_options(int argc, char **argv)
+{
+       static const char short_options[] = KEXEC_ARCH_OPT_STR "";
+       static const struct option options[] = {
+               KEXEC_ARCH_OPTIONS
+               { 0 },
+       };
+       int opt;
+       char *cmdline = NULL;
+       const char *append = NULL;
+
+       while ((opt = getopt_long(argc, argv, short_options,
+                                 options, 0)) != -1) {
+               switch (opt) {
+               case OPT_APPEND:
+                       append = optarg;
+                       break;
+               case OPT_REUSE_CMDLINE:
+                       cmdline = get_command_line();
+                       remove_parameter(cmdline, "kexec");
+                       remove_parameter(cmdline, "initrd");
+                       break;
+               case OPT_INITRD:
+                       arch_options.initrd_file = optarg;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       arch_options.command_line = concat_cmdline(cmdline, append);
+
+       dbgprintf("%s:%d: command_line: %s\n", __func__, __LINE__,
+               arch_options.command_line);
+       dbgprintf("%s:%d: initrd: %s\n", __func__, __LINE__,
+               arch_options.initrd_file);
+
+       return 0;
+}
+
+const struct arch_map_entry arches[] = {
+       { "loongarch64", KEXEC_ARCH_LOONGARCH },
+       { NULL, 0 },
+};
+
+unsigned long loongarch_locate_kernel_segment(struct kexec_info *info)
+{
+       unsigned long hole;
+
+       if (info->kexec_flags & KEXEC_ON_CRASH) {
+               unsigned long hole_end;
+
+               hole = (crash_reserved_mem[usablemem_rgns.size - 1].start < 
mem_min ?
+                               mem_min : 
crash_reserved_mem[usablemem_rgns.size - 1].start);
+               hole = _ALIGN_UP(hole, MiB(1));
+               hole_end = hole + loongarch_mem.text_offset + 
loongarch_mem.image_size;
+
+               if ((hole_end > mem_max) ||
+                   (hole_end > crash_reserved_mem[usablemem_rgns.size - 
1].end)) {
+                       dbgprintf("%s: Crash kernel out of range\n", __func__);
+                       hole = ULONG_MAX;
+               }
+       } else {
+               hole = locate_hole(info,
+                       loongarch_mem.text_offset + loongarch_mem.image_size,
+                       MiB(1), 0, ULONG_MAX, 1);
+
+               if (hole == ULONG_MAX)
+                       dbgprintf("%s: locate_hole failed\n", __func__);
+       }
+
+       return hole;
+}
+
+/*
+ * loongarch_load_other_segments - Prepare the initrd and cmdline segments.
+ */
+
+int loongarch_load_other_segments(struct kexec_info *info, unsigned long 
hole_min)
+{
+       unsigned long initrd_min, hole_max;
+       char *initrd_buf = NULL;
+       unsigned long pagesize = getpagesize();
+
+       if (arch_options.command_line) {
+               if (strlen(arch_options.command_line) >
+                   sizeof(cmdline) - 1) {
+                       fprintf(stderr,
+                               "Kernel command line too long for kernel!\n");
+                       return EFAILED;
+               }
+
+               strncat(cmdline, arch_options.command_line, sizeof(cmdline) - 
1);
+       }
+
+       /* Put the other segments after the image. */
+
+       initrd_min = hole_min;
+       if (info->kexec_flags & KEXEC_ON_CRASH)
+               hole_max = crash_reserved_mem[usablemem_rgns.size - 1].end;
+       else
+               hole_max = ULONG_MAX;
+
+       if (arch_options.initrd_file) {
+
+               initrd_buf = slurp_decompress_file(arch_options.initrd_file, 
&initrd_size);
+
+               initrd_base = add_buffer(info, initrd_buf, initrd_size,
+                                       initrd_size, sizeof(void *),
+                                       _ALIGN_UP(initrd_min,
+                                               pagesize), hole_max, 1);
+               dbgprintf("initrd_base: %lx, initrd_size: %lx\n", initrd_base, 
initrd_size);
+
+               cmdline_add_initrd(cmdline, initrd_base, initrd_size);
+       }
+
+       if (info->kexec_flags & KEXEC_ON_CRASH) {
+               cmdline_add_elfcorehdr(cmdline, elfcorehdr_mem.start,
+                               elfcorehdr_mem.end - elfcorehdr_mem.start + 1);
+
+               cmdline_add_mem(cmdline, crash_reserved_mem[usablemem_rgns.size 
- 1].start,
+                       crash_reserved_mem[usablemem_rgns.size - 1].end -
+                       crash_reserved_mem[usablemem_rgns.size - 1].start + 1);
+       }
+
+       cmdline[sizeof(cmdline) - 1] = 0;
+       add_buffer(info, cmdline, sizeof(cmdline), sizeof(cmdline),
+               sizeof(void *), _ALIGN_UP(hole_min, getpagesize()),
+               0xffffffff, 1);
+
+       dbgprintf("%s:%d: command_line: %s\n", __func__, __LINE__, cmdline);
+
+       return 0;
+
+}
+
+int arch_compat_trampoline(struct kexec_info *UNUSED(info))
+{
+       return 0;
+}
+
+void arch_update_purgatory(struct kexec_info *UNUSED(info))
+{
+}
+
+unsigned long virt_to_phys(unsigned long addr)
+{
+       return addr & ((1ULL << 48) - 1);
+}
+
+/*
+ * add_segment() should convert base to a physical address on loongarch,
+ * while the default is just to work with base as is
+ */
+void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,
+                unsigned long base, size_t memsz)
+{
+       add_segment_phys_virt(info, buf, bufsz, virt_to_phys(base), memsz, 1);
+}
+
+/*
+ * add_buffer() should convert base to a physical address on loongarch,
+ * while the default is just to work with base as is
+ */
+unsigned long add_buffer(struct kexec_info *info, const void *buf,
+                        unsigned long bufsz, unsigned long memsz,
+                        unsigned long buf_align, unsigned long buf_min,
+                        unsigned long buf_max, int buf_end)
+{
+       return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
+                                   buf_min, buf_max, buf_end, 1);
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-loongarch.h 
new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.h
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-loongarch.h       
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.h       
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,60 @@
+#ifndef KEXEC_LOONGARCH_H
+#define KEXEC_LOONGARCH_H
+
+#include <sys/types.h>
+
+#include "image-header.h"
+
+#define BOOT_BLOCK_VERSION 17
+#define BOOT_BLOCK_LAST_COMP_VERSION 16
+
+#define MAX_MEMORY_RANGES 64
+#define MAX_LINE 160
+
+#define CORE_TYPE_ELF64 1
+
+#define COMMAND_LINE_SIZE 512
+
+#define KiB(x) ((x) * 1024UL)
+#define MiB(x) (KiB(x) * 1024UL)
+
+int elf_loongarch_probe(const char *kernel_buf, off_t kernel_size);
+int elf_loongarch_load(int argc, char **argv, const char *buf, off_t len,
+       struct kexec_info *info);
+void elf_loongarch_usage(void);
+
+int pei_loongarch_probe(const char *buf, off_t len);
+int pei_loongarch_load(int argc, char **argv, const char *buf, off_t len,
+       struct kexec_info *info);
+void pei_loongarch_usage(void);
+
+int loongarch_process_image_header(const struct loongarch_image_header *h);
+
+unsigned long loongarch_locate_kernel_segment(struct kexec_info *info);
+int loongarch_load_other_segments(struct kexec_info *info,
+       unsigned long hole_min);
+
+struct arch_options_t {
+       char *command_line;
+       char *initrd_file;
+       char *dtb;
+       int core_header_type;
+};
+
+/**
+ * struct loongarch_mem - Memory layout info.
+ */
+
+struct loongarch_mem {
+       uint64_t phys_offset;
+       uint64_t text_offset;
+       uint64_t image_size;
+};
+
+extern struct loongarch_mem loongarch_mem;
+
+extern struct memory_ranges usablemem_rgns;
+extern struct arch_options_t arch_options;
+extern off_t initrd_base, initrd_size;
+
+#endif /* KEXEC_LOONGARCH_H */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-pei-loongarch.c 
new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-pei-loongarch.c
--- old/kexec-tools-2.0.25/kexec/arch/loongarch/kexec-pei-loongarch.c   
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/kexec/arch/loongarch/kexec-pei-loongarch.c   
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,117 @@
+/*
+ * LoongArch kexec PE format binary image support.
+ *
+ * Copyright (C) 2022 Loongson Technology Corporation Limited.
+ *   Youling Tang <tangyoul...@loongson.cn>
+ *
+ * derived from kexec-image-arm64.c
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+
+#define _GNU_SOURCE
+
+#include <limits.h>
+#include <errno.h>
+#include <elf.h>
+
+#include "kexec.h"
+#include "kexec-elf.h"
+#include "image-header.h"
+#include "kexec-syscall.h"
+#include "crashdump-loongarch.h"
+#include "kexec-loongarch.h"
+#include "arch/options.h"
+
+int pei_loongarch_probe(const char *kernel_buf, off_t kernel_size)
+{
+       const struct loongarch_image_header *h;
+
+       if (kernel_size < sizeof(struct loongarch_image_header)) {
+               dbgprintf("%s: No loongarch image header.\n", __func__);
+               return -1;
+       }
+
+       h = (const struct loongarch_image_header *)(kernel_buf);
+
+       if (!loongarch_header_check_pe_sig(h)) {
+               dbgprintf("%s: Bad loongarch PE image header.\n", __func__);
+               return -1;
+       }
+
+       return 0;
+}
+
+int pei_loongarch_load(int argc, char **argv, const char *buf,
+       off_t len, struct kexec_info *info)
+{
+       int result;
+       unsigned long hole_min = 0;
+       unsigned long kernel_segment, kernel_entry;
+       const struct loongarch_image_header *header;
+
+       header = (const struct loongarch_image_header *)(buf);
+
+       if (loongarch_process_image_header(header))
+               return EFAILED;
+
+       kernel_segment = loongarch_locate_kernel_segment(info);
+
+       if (kernel_segment == ULONG_MAX) {
+               dbgprintf("%s: Kernel segment is not allocated\n", __func__);
+               result = EFAILED;
+               goto exit;
+       }
+
+       kernel_entry = virt_to_phys(loongarch_header_kernel_entry(header));
+
+       dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment);
+       dbgprintf("%s: kernel_entry:   %016lx\n", __func__, kernel_entry);
+       dbgprintf("%s: image_size:     %016lx\n", __func__,
+               loongarch_mem.image_size);
+       dbgprintf("%s: text_offset:    %016lx\n", __func__,
+               loongarch_mem.text_offset);
+       dbgprintf("%s: phys_offset:    %016lx\n", __func__,
+               loongarch_mem.phys_offset);
+       dbgprintf("%s: PE format:      %s\n", __func__,
+               (loongarch_header_check_pe_sig(header) ? "yes" : "no"));
+
+       /* Get kernel entry point */
+       info->entry = (void *)kernel_entry;
+
+       hole_min = kernel_segment + loongarch_mem.image_size;
+
+       /* Create and initialize elf core header segment */
+       if (info->kexec_flags & KEXEC_ON_CRASH) {
+               result = load_crashdump_segments(info);
+               if (result) {
+                       dbgprintf("%s: Creating eflcorehdr failed.\n",
+                                                               __func__);
+                       goto exit;
+               }
+       }
+
+       /* Load the kernel */
+       add_segment(info, buf, len, kernel_segment, loongarch_mem.image_size);
+
+       /* Prepare and load dtb and initrd data */
+       result = loongarch_load_other_segments(info, hole_min);
+       if (result) {
+               fprintf(stderr, "kexec: Load dtb and initrd segments 
failed.\n");
+               goto exit;
+       }
+
+exit:
+       if (result)
+               fprintf(stderr, "kexec: load failed.\n");
+
+       return result;
+}
+
+void pei_loongarch_usage(void)
+{
+       printf(
+"     An LoongArch PE format binary image, uncompressed, little endian.\n"
+"     Typically a vmlinux.efi file.\n\n");
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/arch/m68k/bootinfo.c 
new/kexec-tools-2.0.26/kexec/arch/m68k/bootinfo.c
--- old/kexec-tools-2.0.25/kexec/arch/m68k/bootinfo.c   2022-06-26 
09:19:20.000000000 +0200
+++ new/kexec-tools-2.0.26/kexec/arch/m68k/bootinfo.c   2022-11-18 
16:15:08.000000000 +0100
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/random.h>
 
 #include "../../kexec.h"
 
@@ -152,6 +153,11 @@
                        printf("BI_COMMAND_LINE: %s\n", bi->string);
                        break;
 
+               case BI_RNG_SEED:
+                       /* These are secret, so never print them to the console 
*/
+                       printf("BI_RNG_SEED: 0x%08x bytes\n", 
be16_to_cpu(bi->rng_seed.len));
+                       break;
+
                default:
                        printf("BI tag 0x%04x size %u\n", tag, size);
                        break;
@@ -212,6 +218,23 @@
        bi->mem_info.size = ramdisk_size;
 }
 
+void bootinfo_add_rng_seed(void)
+{
+       enum { RNG_SEED_LEN = 32 };
+       struct bi_rec *bi;
+
+       /* Remove existing rng seed records */
+       bi_remove(BI_RNG_SEED);
+
+       /* Add new rng seed record */
+       bi = bi_add(BI_RNG_SEED, sizeof(bi->rng_seed) + RNG_SEED_LEN);
+       if (getrandom(bi->rng_seed.data, RNG_SEED_LEN, GRND_NONBLOCK) != 
RNG_SEED_LEN) {
+               bi_remove(BI_RNG_SEED);
+               return;
+       }
+       bi->rng_seed.len = cpu_to_be16(RNG_SEED_LEN);
+}
+
 
     /*
      * Check the bootinfo version in the kernel image
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/arch/m68k/bootinfo.h 
new/kexec-tools-2.0.26/kexec/arch/m68k/bootinfo.h
--- old/kexec-tools-2.0.25/kexec/arch/m68k/bootinfo.h   2022-06-26 
09:19:20.000000000 +0200
+++ new/kexec-tools-2.0.26/kexec/arch/m68k/bootinfo.h   2022-11-18 
16:15:08.000000000 +0100
@@ -3,6 +3,11 @@
 #define DEFAULT_BOOTINFO_FILE  "/proc/bootinfo"
 #define MAX_BOOTINFO_SIZE      1536
 
+/* New in 6.2's <asm/bootinfo.h>. Remove once 6.2 is baseline version. */
+#ifndef BI_RNG_SEED
+#define BI_RNG_SEED             0x0008
+#endif
+
 
     /*
      *  Convenience overlay of several struct bi_record variants
@@ -20,6 +25,10 @@
                        __be32 size;
                } mem_info;
                char string[0];
+               struct {
+                       __be16 len;
+                       __u8 data[0];
+               } rng_seed;
        };
 };
 
@@ -39,5 +48,6 @@
 extern void bootinfo_set_cmdline(const char *cmdline);
 extern void bootinfo_set_ramdisk(unsigned long ramdisk_addr,
                                 unsigned long ramdisk_size);
+extern void bootinfo_add_rng_seed(void);
 extern void bootinfo_check_bootversion(const struct kexec_info *info);
 extern void add_bootinfo(struct kexec_info *info, unsigned long addr);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/arch/m68k/kexec-elf-m68k.c 
new/kexec-tools-2.0.26/kexec/arch/m68k/kexec-elf-m68k.c
--- old/kexec-tools-2.0.25/kexec/arch/m68k/kexec-elf-m68k.c     2022-06-26 
09:19:20.000000000 +0200
+++ new/kexec-tools-2.0.26/kexec/arch/m68k/kexec-elf-m68k.c     2022-11-18 
16:15:08.000000000 +0100
@@ -162,6 +162,7 @@
        /* Update and add bootinfo */
        bootinfo_set_cmdline(cmdline);
        bootinfo_set_ramdisk(ramdisk_addr, ramdisk_size);
+       bootinfo_add_rng_seed();
        if (kexec_debug)
                bootinfo_print();
        add_bootinfo(info, bootinfo_addr);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/arch/ppc64/kexec-ppc64.c 
new/kexec-tools-2.0.26/kexec/arch/ppc64/kexec-ppc64.c
--- old/kexec-tools-2.0.25/kexec/arch/ppc64/kexec-ppc64.c       2022-06-26 
09:19:20.000000000 +0200
+++ new/kexec-tools-2.0.26/kexec/arch/ppc64/kexec-ppc64.c       2022-11-18 
16:11:40.000000000 +0100
@@ -717,8 +717,6 @@
                        if (base < rma_base) {
                                rma_base = base;
                                rma_top = base + be64_to_cpu(((uint64_t 
*)buf)[1]);
-                               if (rma_top > 0x30000000UL)
-                                       rma_top = 0x30000000UL;
                        }
 
                        fclose(file);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/kexec-syscall.h 
new/kexec-tools-2.0.26/kexec/kexec-syscall.h
--- old/kexec-tools-2.0.25/kexec/kexec-syscall.h        2022-06-26 
09:19:20.000000000 +0200
+++ new/kexec-tools-2.0.26/kexec/kexec-syscall.h        2022-11-18 
16:11:40.000000000 +0100
@@ -39,6 +39,9 @@
 #ifdef __s390__
 #define __NR_kexec_load                277
 #endif
+#ifdef __loongarch__
+#define __NR_kexec_load                104
+#endif
 #if defined(__arm__) || defined(__arm64__)
 #define __NR_kexec_load                __NR_SYSCALL_BASE + 347
 #endif
@@ -134,6 +137,7 @@
 #define KEXEC_ARCH_MIPS_LE (10 << 16)
 #define KEXEC_ARCH_MIPS    ( 8 << 16)
 #define KEXEC_ARCH_CRIS    (76 << 16)
+#define KEXEC_ARCH_LOONGARCH   (258 << 16)
 
 #define KEXEC_MAX_SEGMENTS 16
 
@@ -177,5 +181,8 @@
 #if defined(__arm64__)
 #define KEXEC_ARCH_NATIVE      KEXEC_ARCH_ARM64
 #endif
+#if defined(__loongarch__)
+#define KEXEC_ARCH_NATIVE      KEXEC_ARCH_LOONGARCH
+#endif
 
 #endif /* KEXEC_SYSCALL_H */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/kexec.c 
new/kexec-tools-2.0.26/kexec/kexec.c
--- old/kexec-tools-2.0.25/kexec/kexec.c        2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/kexec/kexec.c        2022-11-18 16:11:40.000000000 
+0100
@@ -1095,7 +1095,7 @@
 /*
  * Remove parameter from a kernel command line. Helper function by 
get_command_line().
  */
-static void remove_parameter(char *line, const char *param_name)
+void remove_parameter(char *line, const char *param_name)
 {
        char *start, *end;
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec/kexec.h 
new/kexec-tools-2.0.26/kexec/kexec.h
--- old/kexec-tools-2.0.25/kexec/kexec.h        2022-07-19 14:27:46.000000000 
+0200
+++ new/kexec-tools-2.0.26/kexec/kexec.h        2022-11-18 16:11:40.000000000 
+0100
@@ -304,6 +304,7 @@
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
 int get_crash_kernel_load_range(uint64_t *start, uint64_t *end);
+void remove_parameter(char *line, const char *param_name);
 char *get_command_line(void);
 
 int kexec_iomem_for_each_line(char *match,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/kexec-tools.spec 
new/kexec-tools-2.0.26/kexec-tools.spec
--- old/kexec-tools-2.0.25/kexec-tools.spec     2022-07-31 08:40:16.000000000 
+0200
+++ new/kexec-tools-2.0.26/kexec-tools.spec     2022-12-21 16:30:24.000000000 
+0100
@@ -1,6 +1,6 @@
 Summary: Load one kernel from another
 Name: kexec-tools
-Version: 2.0.25
+Version: 2.0.26
 Release: 0
 License: GPL
 Group: Development/Tools
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/purgatory/Makefile 
new/kexec-tools-2.0.26/purgatory/Makefile
--- old/kexec-tools-2.0.25/purgatory/Makefile   2022-06-26 09:19:20.000000000 
+0200
+++ new/kexec-tools-2.0.26/purgatory/Makefile   2022-11-18 16:11:40.000000000 
+0100
@@ -28,6 +28,7 @@
 include $(srcdir)/purgatory/arch/s390/Makefile
 include $(srcdir)/purgatory/arch/sh/Makefile
 include $(srcdir)/purgatory/arch/x86_64/Makefile
+include $(srcdir)/purgatory/arch/loongarch/Makefile
 
 PURGATORY_SRCS+=$($(ARCH)_PURGATORY_SRCS)
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/kexec-tools-2.0.25/purgatory/arch/loongarch/Makefile 
new/kexec-tools-2.0.26/purgatory/arch/loongarch/Makefile
--- old/kexec-tools-2.0.25/purgatory/arch/loongarch/Makefile    1970-01-01 
01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/purgatory/arch/loongarch/Makefile    2022-11-18 
16:11:40.000000000 +0100
@@ -0,0 +1,10 @@
+#
+# Purgatory loongarch
+#
+
+loongarch_PURGATORY_SRCS+= purgatory/arch/loongarch/purgatory-loongarch.c
+loongarch_PURGATORY_SRCS+= purgatory/arch/loongarch/console-loongarch.c
+
+dist += purgatory/arch/loongarch/Makefile $(loongarch_PURGATORY_SRCS)          
\
+       purgatory/arch/loongarch/purgatory-loongarch.h
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/purgatory/arch/loongarch/console-loongarch.c 
new/kexec-tools-2.0.26/purgatory/arch/loongarch/console-loongarch.c
--- old/kexec-tools-2.0.25/purgatory/arch/loongarch/console-loongarch.c 
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/purgatory/arch/loongarch/console-loongarch.c 
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,7 @@
+#include <purgatory.h>
+#include "unused.h"
+
+void putchar(int UNUSED(ch))
+{
+       /* Nothing for now */
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/purgatory/arch/loongarch/purgatory-loongarch.c 
new/kexec-tools-2.0.26/purgatory/arch/loongarch/purgatory-loongarch.c
--- old/kexec-tools-2.0.25/purgatory/arch/loongarch/purgatory-loongarch.c       
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/purgatory/arch/loongarch/purgatory-loongarch.c       
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,7 @@
+#include <purgatory.h>
+#include "purgatory-loongarch.h"
+
+void setup_arch(void)
+{
+       /* Nothing for now */
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/kexec-tools-2.0.25/purgatory/arch/loongarch/purgatory-loongarch.h 
new/kexec-tools-2.0.26/purgatory/arch/loongarch/purgatory-loongarch.h
--- old/kexec-tools-2.0.25/purgatory/arch/loongarch/purgatory-loongarch.h       
1970-01-01 01:00:00.000000000 +0100
+++ new/kexec-tools-2.0.26/purgatory/arch/loongarch/purgatory-loongarch.h       
2022-11-18 16:11:40.000000000 +0100
@@ -0,0 +1,6 @@
+#ifndef PURGATORY_LOONGARCH_H
+#define PURGATORY_LOONGARCH_H
+
+/* nothing yet */
+
+#endif /* PURGATORY_LOONGARCH_H */

++++++ kexec-tools-riscv64.patch ++++++
--- /var/tmp/diff_new_pack.8E6IOX/_old  2023-02-04 14:18:05.674435051 +0100
+++ /var/tmp/diff_new_pack.8E6IOX/_new  2023-02-04 14:18:05.678435073 +0100
@@ -39,8 +39,8 @@
 --- a/configure.ac
 +++ b/configure.ac
 @@ -58,6 +58,9 @@ case $target_cpu in
-       hppa*)
-               ARCH="hppa"
+       loongarch*)
+               ARCH="loongarch"
                ;;
 +      riscv32|riscv64 )
 +              ARCH="riscv"
@@ -52,16 +52,14 @@
 index b7677a2..123f167 100644
 --- a/include/elf.h
 +++ b/include/elf.h
-@@ -259,7 +259,8 @@ typedef struct
+@@ -259,6 +259,7 @@ typedef struct
  #define EM_ARC_A5     93              /* ARC Cores Tangent-A5 */
  #define EM_XTENSA     94              /* Tensilica Xtensa Architecture */
  #define EM_AARCH64    183             /* ARM AARCH64 */
--#define EM_NUM                184
 +#define EM_RISCV      243             /* RISC-V */
-+#define EM_NUM                244
+ #define EM_LOONGARCH  258             /* Loongson Loongarch*/
+ #define EM_NUM                184
  
- /* If it is necessary to assign new unofficial EM_* values, please
-    pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
 diff --git a/kexec/Makefile b/kexec/Makefile
 index e69e309..ca17831 100644
 --- a/kexec/Makefile
@@ -1471,18 +1469,19 @@
  #define KEXEC_ARCH_MIPS    ( 8 << 16)
  #define KEXEC_ARCH_CRIS    (76 << 16)
 +#define KEXEC_ARCH_RISCV   (243 << 16)
+ #define KEXEC_ARCH_LOONGARCH  (258 << 16)
  
  #define KEXEC_MAX_SEGMENTS 16
- 
-@@ -177,5 +178,8 @@ static inline long kexec_file_load(int kernel_fd, int 
initrd_fd,
+@@ -177,6 +178,9 @@ static inline long kexec_file_load(int kernel_fd, int 
initrd_fd,
  #if defined(__arm64__)
  #define KEXEC_ARCH_NATIVE     KEXEC_ARCH_ARM64
  #endif
 +#if defined(__riscv__) || defined(__riscv)
 +#define KEXEC_ARCH_NATIVE     KEXEC_ARCH_RISCV
 +#endif
- 
- #endif /* KEXEC_SYSCALL_H */
+ #if defined(__loongarch__)
+ #define KEXEC_ARCH_NATIVE     KEXEC_ARCH_LOONGARCH
+ #endif
 diff --git a/purgatory/Makefile b/purgatory/Makefile
 index 2dd6c47..0a9d1c1 100644
 --- a/purgatory/Makefile

Reply via email to