├── AUTHORS ├── Android.mk ├── COPYING ├── INSTALL ├── Makefile.in ├── News ├── TODO ├── config ├── config.guess ├── config.sub └── install-sh ├── configure ├── configure.ac ├── doc ├── Makefile ├── linux-i386-boot.txt ├── linux-i386-zero-page.txt ├── multiboot.html └── nbi-spec.txt ├── include ├── Makefile ├── boot │ ├── beoboot.h │ ├── elf_boot.h │ └── linuxbios_tables.h ├── config.h ├── config.h.in ├── elf.h ├── image.h ├── kexec-uImage.h ├── unused.h └── x86 │ ├── mb_header.h │ ├── mb_info.h │ └── x86-linux.h ├── kdump ├── Makefile ├── kdump.8 └── kdump.c ├── kexec-tools.spec ├── kexec-tools.spec.in ├── kexec ├── Makefile ├── add_buffer.c ├── add_segment.c ├── arch │ ├── alpha │ │ ├── Makefile │ │ └── include │ │ │ └── arch │ │ │ └── options.h │ ├── arm │ │ ├── Makefile │ │ ├── crashdump-arm.c │ │ ├── crashdump-arm.h │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-arm.c │ │ ├── kexec-arm.h │ │ ├── kexec-elf-rel-arm.c │ │ ├── kexec-uImage-arm.c │ │ ├── kexec-zImage-arm.c │ │ ├── mach-hammerhead.c │ │ ├── mach-m8.c │ │ ├── mach-shamu.c │ │ ├── mach.c │ │ ├── mach.h │ │ └── phys_to_virt.c │ ├── cris │ │ ├── Makefile │ │ ├── cris-setup-simple.S │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-cris.c │ │ ├── kexec-cris.h │ │ ├── kexec-elf-cris.c │ │ └── kexec-elf-rel-cris.c │ ├── i386 │ │ ├── Makefile │ │ ├── crashdump-x86.c │ │ ├── crashdump-x86.h │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-beoboot-x86.c │ │ ├── kexec-bzImage.c │ │ ├── kexec-elf-rel-x86.c │ │ ├── kexec-elf-x86.c │ │ ├── kexec-multiboot-x86.c │ │ ├── kexec-nbi.c │ │ ├── kexec-x86-common.c │ │ ├── kexec-x86.c │ │ ├── kexec-x86.h │ │ ├── x86-linux-setup.c │ │ └── x86-linux-setup.h │ ├── ia64 │ │ ├── Makefile │ │ ├── crashdump-ia64.c │ │ ├── crashdump-ia64.h │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-elf-ia64.c │ │ ├── kexec-elf-rel-ia64.c │ │ ├── kexec-ia64.c │ │ ├── kexec-ia64.h │ │ └── kexec-iomem.c │ ├── mips │ │ ├── Makefile │ │ ├── crashdump-mips.c │ │ ├── crashdump-mips.h │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-elf-mips.c │ │ ├── kexec-elf-rel-mips.c │ │ ├── kexec-mips.c │ │ └── kexec-mips.h │ ├── ppc │ │ ├── Makefile │ │ ├── crashdump-powerpc.c │ │ ├── crashdump-powerpc.h │ │ ├── fixup_dtb.c │ │ ├── fixup_dtb.h │ │ ├── fs2dt.c │ │ ├── include │ │ │ ├── arch │ │ │ │ └── options.h │ │ │ ├── page.h │ │ │ └── types.h │ │ ├── kexec-dol-ppc.c │ │ ├── kexec-elf-ppc.c │ │ ├── kexec-elf-rel-ppc.c │ │ ├── kexec-ppc.c │ │ ├── kexec-ppc.h │ │ ├── kexec-uImage-ppc.c │ │ ├── libfdt-wrapper.c │ │ ├── libfdt │ │ │ ├── Makefile.libfdt │ │ │ ├── fdt.c │ │ │ ├── fdt.h │ │ │ ├── fdt_ro.c │ │ │ ├── fdt_rw.c │ │ │ ├── fdt_strerror.c │ │ │ ├── fdt_sw.c │ │ │ ├── fdt_wip.c │ │ │ ├── libfdt.h │ │ │ ├── libfdt_env.h │ │ │ └── libfdt_internal.h │ │ ├── ops.h │ │ ├── ppc-setup-dol.S │ │ ├── ppc-setup-simple.S │ │ └── ppc_asm.h │ ├── ppc64 │ │ ├── Makefile │ │ ├── crashdump-ppc64.c │ │ ├── crashdump-ppc64.h │ │ ├── fs2dt.c │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-elf-ppc64.c │ │ ├── kexec-elf-rel-ppc64.c │ │ ├── kexec-ppc64.c │ │ ├── kexec-ppc64.h │ │ └── kexec-zImage-ppc64.c │ ├── s390 │ │ ├── Makefile │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-elf-rel-s390.c │ │ ├── kexec-image.c │ │ ├── kexec-s390.c │ │ └── kexec-s390.h │ ├── sh │ │ ├── Makefile │ │ ├── crashdump-sh.c │ │ ├── crashdump-sh.h │ │ ├── include │ │ │ └── arch │ │ │ │ └── options.h │ │ ├── kexec-elf-rel-sh.c │ │ ├── kexec-elf-sh.c │ │ ├── kexec-netbsd-sh.c │ │ ├── kexec-sh.c │ │ ├── kexec-sh.h │ │ ├── kexec-uImage-sh.c │ │ ├── kexec-zImage-sh.c │ │ └── netbsd_booter.S │ └── x86_64 │ │ ├── Makefile │ │ ├── arch_init.c │ │ ├── crashdump-x86_64.c │ │ ├── crashdump-x86_64.h │ │ ├── include │ │ └── arch │ │ │ └── options.h │ │ ├── kexec-elf-rel-x86_64.c │ │ ├── kexec-elf-x86_64.c │ │ ├── kexec-x86_64.c │ │ └── kexec-x86_64.h ├── arch_init.c ├── arch_reuse_initrd.c ├── crashdump-elf.c ├── crashdump-xen.c ├── crashdump.c ├── crashdump.h ├── firmware_memmap.c ├── firmware_memmap.h ├── ifdown.c ├── kexec-elf-boot.c ├── kexec-elf-boot.h ├── kexec-elf-core.c ├── kexec-elf-exec.c ├── kexec-elf-rel.c ├── kexec-elf.c ├── kexec-elf.h ├── kexec-iomem.c ├── kexec-lzma.h ├── kexec-sha256.h ├── kexec-syscall.h ├── kexec-uImage.c ├── kexec-zlib.h ├── kexec.8 ├── kexec.c ├── kexec.h ├── libfdt │ ├── Makefile.libfdt │ ├── TODO │ ├── fdt.c │ ├── fdt.h │ ├── fdt_ro.c │ ├── fdt_rw.c │ ├── fdt_strerror.c │ ├── fdt_sw.c │ ├── fdt_wip.c │ ├── libfdt.h │ ├── libfdt_env.h │ └── libfdt_internal.h ├── lzma.c ├── phys_arch.c ├── phys_to_virt.c ├── proc_iomem.c ├── purgatory.c ├── virt_to_phys.c └── zlib.c ├── kexec_test ├── Makefile ├── kexec_test.S ├── kexec_test16.S └── x86-setup-legacy-pic.S ├── purgatory ├── Makefile ├── arch │ ├── alpha │ │ └── Makefile │ ├── arm │ │ └── Makefile │ ├── i386 │ │ ├── Makefile │ │ ├── compat_x86_64.S │ │ ├── console-x86.c │ │ ├── crashdump_backup.c │ │ ├── entry32-16-debug.S │ │ ├── entry32-16.S │ │ ├── entry32.S │ │ ├── include │ │ │ └── arch │ │ │ │ ├── debug.h │ │ │ │ └── io.h │ │ ├── pic.c │ │ ├── purgatory-x86.c │ │ ├── purgatory-x86.h │ │ ├── setup-x86.S │ │ ├── stack.S │ │ └── vga.c │ ├── ia64 │ │ ├── Makefile │ │ ├── console-ia64.c │ │ ├── entry.S │ │ ├── io.h │ │ ├── purgatory-ia64.c │ │ ├── purgatory-ia64.h │ │ └── vga.c │ ├── mips │ │ ├── Makefile │ │ ├── console-mips.c │ │ ├── purgatory-mips.c │ │ └── purgatory-mips.h │ ├── ppc │ │ ├── Makefile │ │ ├── console-ppc.c │ │ ├── crt.S │ │ ├── misc.S │ │ ├── ppc_asm.h │ │ ├── purgatory-ppc.c │ │ ├── purgatory-ppc.h │ │ └── v2wrap_32.S │ ├── ppc64 │ │ ├── Makefile │ │ ├── console-ppc64.c │ │ ├── crashdump_backup.c │ │ ├── hvCall.S │ │ ├── hvCall.h │ │ ├── purgatory-ppc64.c │ │ ├── purgatory-ppc64.h │ │ └── v2wrap.S │ ├── s390 │ │ └── Makefile │ ├── sh │ │ └── Makefile │ └── x86_64 │ │ ├── Makefile │ │ ├── entry64-32.S │ │ ├── entry64.S │ │ ├── include │ │ └── arch │ │ │ ├── debug.h │ │ │ └── io.h │ │ ├── purgatory-x86_64.c │ │ ├── purgatory-x86_64.h │ │ ├── setup-x86_64.S │ │ └── stack.S ├── include │ ├── purgatory.h │ └── string.h ├── printf.c ├── purgatory.c └── string.c ├── util ├── Makefile └── bin-to-hex.c └── util_lib ├── Makefile ├── compute_ip_checksum.c ├── include ├── ip_checksum.h └── sha256.h └── sha256.c /AUTHORS: -------------------------------------------------------------------------------- 1 | Eric Biederman 2 | Albert Herranz 3 | Jesse Barnes 4 | Khalid Aziz 5 | Hariprasad Nellitheertha 6 | Tim Deegan 7 | And others... 8 | 9 | Currently maintained by 10 | P: Simon Horman 11 | M: horms@verge.net.au 12 | L: kexec@lists.infradead.org 13 | 14 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := mrom_kdump_static 5 | LOCAL_MODULE_TAGS := optional 6 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 7 | LOCAL_SRC_FILES := kdump/kdump.c 8 | LOCAL_FORCE_STATIC_EXECUTABLE := true 9 | LOCAL_STATIC_LIBRARIES := libc 10 | include $(BUILD_EXECUTABLE) 11 | 12 | include $(CLEAR_VARS) 13 | LOCAL_MODULE := mrom_libutil_kt 14 | LOCAL_MODULE_TAGS := optional 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/util_lib/include 16 | LOCAL_SRC_FILES := util_lib/compute_ip_checksum.c util_lib/sha256.c 17 | include $(BUILD_STATIC_LIBRARY) 18 | 19 | include $(CLEAR_VARS) 20 | LOCAL_MODULE := mrom_kexec_static 21 | LOCAL_MODULE_TAGS := optional 22 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \ 23 | $(LOCAL_PATH)/util_lib/include \ 24 | $(LOCAL_PATH)/kexec/arch/arm/include \ 25 | $(LOCAL_PATH)/kexec/libfdt \ 26 | external/zlib 27 | LOCAL_SRC_FILES := kexec/kexec.c kexec/ifdown.c \ 28 | kexec/kexec-elf.c kexec/kexec-elf-exec.c \ 29 | kexec/kexec-elf-core.c \ 30 | kexec/kexec-elf-rel.c \ 31 | kexec/kexec-elf-boot.c \ 32 | kexec/kexec-iomem.c \ 33 | kexec/firmware_memmap.c \ 34 | kexec/crashdump.c kexec/crashdump-xen.c \ 35 | kexec/phys_arch.c kexec/lzma.c \ 36 | kexec/zlib.c kexec/proc_iomem.c \ 37 | kexec/virt_to_phys.c \ 38 | kexec/arch/arm/phys_to_virt.c \ 39 | kexec/add_segment.c kexec/add_buffer.c \ 40 | kexec/arch_reuse_initrd.c \ 41 | kexec/arch_init.c \ 42 | kexec/arch/arm/kexec-elf-rel-arm.c \ 43 | kexec/arch/arm/kexec-zImage-arm.c \ 44 | kexec/arch/arm/kexec-uImage-arm.c \ 45 | kexec/arch/arm/kexec-arm.c \ 46 | kexec/arch/arm/mach.c \ 47 | kexec/arch/arm/mach-hammerhead.c \ 48 | kexec/arch/arm/mach-m8.c \ 49 | kexec/arch/arm/mach-shamu.c \ 50 | kexec/arch/arm/crashdump-arm.c \ 51 | kexec/kexec-uImage.c kexec/purgatory.c \ 52 | kexec/libfdt/fdt.c kexec/libfdt/fdt_ro.c \ 53 | kexec/libfdt/fdt_rw.c kexec/libfdt/fdt_strerror.c \ 54 | kexec/libfdt/fdt_sw.c kexec/libfdt/fdt_wip.c 55 | LOCAL_FORCE_STATIC_EXECUTABLE := true 56 | LOCAL_STATIC_LIBRARIES := mrom_libutil_kt libz libc 57 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 58 | LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_EXECUTABLES_UNSTRIPPED) 59 | include $(BUILD_EXECUTABLE) 60 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | 5 | Checkout from git 6 | ----------------- 7 | 8 | If you use the tarball, you can just skip that section. If you checked out the 9 | kexec-tools from git repository, you have to build the Autoconf-generated 10 | file yourself with running 11 | 12 | ./bootstrap 13 | 14 | You have to install "autoconf" for that. After that, you should have a file 15 | called "configure" in the top-level directory of kexec-tools, and you can 16 | continue with the next step. 17 | 18 | 19 | General 20 | ------- 21 | 22 | You should check first if your favourite Linux distribution doesn't offer a 23 | package. If that package is recent enough, you should consider using that 24 | package instead. 25 | 26 | However, if you want to install kexec-tools from sources 27 | 28 | (1) Run ./configure [--prefix=/usr/local] [options]... 29 | e.g. 30 | 31 | ./configure --prefix=/usr/local 32 | 33 | For a full list of options run 34 | 35 | ./configure --help 36 | 37 | (2) Run make 38 | 39 | make 40 | 41 | (3) To install kexec-tools 42 | After following the above instructions to build-kexec tools, run 43 | 44 | make install 45 | 46 | 47 | Static compilation 48 | ------------------ 49 | 50 | To compile kexec-tools statically (i.e., independent of libraries that are 51 | present on the system), use 52 | 53 | LDFLAGS=-static ./configure 54 | 55 | instead. 56 | 57 | 58 | Cross compilation 59 | ----------------- 60 | 61 | Because kexec is also used in the embedded world, cross-compilation is 62 | supported. You cannot only set "CC", "LD", "CCFLAGS" and "LDFLAGS" environment 63 | variables for the ./configure call as usual, you can also set 64 | 65 | TARGET_CC -- the C compiler used for files that should run on the 66 | target 67 | TARGET_CCFLAGS -- compilation flags for $TARGET_CC 68 | TARGET_LD -- linker used for files that should run on the 69 | target 70 | 71 | Because the build process also requires files that must be executed during the 72 | build, you also need a host compiler, only the target compiler is not enough. 73 | 74 | BUILD_CC -- the C compiler used for files that should run on the 75 | host (the system that builds the kexec-tools) 76 | BUILD_CFLAGS -- compilation flags for $BUILD_CC 77 | 78 | -------------------------------------------------------------------------------- /News: -------------------------------------------------------------------------------- 1 | * 2.0 2 | - In purgatory added -fno-zero-initialized-in-bss to prevent issues with 3 | recent versions of gcc 4 | - Add an option to configure to disable zlib support 5 | - Add mismatched architecture support 6 | - Updated the x86 architecture help 7 | - Updated the x86_64 architecture help 8 | - Fixed bzImage support 9 | - Added support for finding either the highest or lowest usable window. 10 | - Change the version number to 2.0 to reflect the major change in 11 | the code base. 1.99 was effectively the release canidate. 12 | * 1.99 13 | - Rearchitect so the code is maintainable. 14 | - Add multiboot support 15 | - Add ia64 support 16 | - Add beoboot image support 17 | - Create generic elf loader code. 18 | - Created the relocated shared object purgatory to hold 19 | the code that runs between kernels. 20 | - Added a configure script 21 | - Added an rpm target 22 | - Added kexec on panic support 23 | - Initial stab at adding documentation 24 | - Added loader support for ET_DYN objects 25 | * 1.98 26 | - Add mysteriously dropped changes to make x86_64 work 27 | - Update the distclean target to remove *.orig and *~ files 28 | * 1.97 29 | - Add support for cross compiling x86_64 30 | * 1.96 31 | - add x86_64 support 32 | - add support for linux style arguments to the elf32-x86 loader 33 | - disable clearing of cr4 on x86 34 | * 1.95 35 | - add kexec-zImage-ppc64.c source file 36 | - GameCube/PPC32 sync'ed to 1.94 37 | - use syscall() to call sys_kexec_load() and reboot() 38 | - add kexec-syscall.h, remove kexec-syscall.c 39 | - makefiles know about ARCH-es 40 | - add noifdown kexec option (Albert Herranz) 41 | * 1.94 42 | - revert a bad 1.92 change (not setting optind & opterr for subsequent 43 | calls to getopt_long()) 44 | * 1.93 45 | - restored "shutdown" functionality; 46 | - more help/usage text clarification; 47 | - add GPLv2 license to source files (with permission from Eric Biederman) 48 | * 1.92 49 | - my_kexec(): call kexec() only one time; 50 | - add "unload" option; 51 | - fix some compiler warnings about " might be used uninitialized"; 52 | - commented out shutdown capability since it was unreachable; 53 | * 1.91 54 | - fix "-t" option: strcmp() was inverted (Albert Herranz) 55 | - check specified kernel image file for file type (Albert Herranz) 56 | * 1.9 57 | - change reboot function to return type long (was int) 58 | - use kexec reserved syscall numbers (in Linux 2.6.6-mm3) 59 | * 1.8 60 | - Fixed bug where ramdisk wasn't loaded when specified 61 | - Memory information is now read from /proc/iomem. 62 | Information that is not needed is ignored. 63 | * 1.7 64 | - Update to new tentative syscall number.... 65 | * 1.6 66 | - Redo all of the command line arguments. 67 | - Use the 32-bit kernel entry point. 68 | - Work around a failure to clear %cr4. 69 | * 1.5 70 | - Port to a new kernel interface (Hopefully the final one). 71 | - Start working on setting up legacy hardware 72 | - Add --load and --exec options so the parts can be done at different times. 73 | ### 74 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - x86 handle x86 vmlinux parameter header allocation issues. 2 | There is a bug where it can get stomped but the current code 3 | does not allow us much flexibility in what we do with it. 4 | - Restore enough state that DOS/arbitrary BIOS calls can be run on some 5 | platforms. Currently disk-related calls are quite likely to blow up. 6 | - x86 filling in other kernel parameters. 7 | - Merge reboot via kexec functionality into /sbin/reboot 8 | - Improve the documentation 9 | - Add support for loading a boot sector 10 | - Autobuilding of initramfs 11 | ### 12 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | dist += doc/Makefile \ 2 | doc/linux-i386-boot.txt \ 3 | doc/linux-i386-zero-page.txt \ 4 | doc/multiboot.html \ 5 | doc/nbi-spec.txt 6 | -------------------------------------------------------------------------------- /doc/linux-i386-zero-page.txt: -------------------------------------------------------------------------------- 1 | Summary of boot_params layout (kernel point of view) 2 | ( collected by Hans Lermen and Martin Mares ) 3 | 4 | The contents of boot_params are used to pass parameters from the 5 | 16-bit realmode code of the kernel to the 32-bit part. References/settings 6 | to it mainly are in: 7 | 8 | arch/i386/boot/setup.S 9 | arch/i386/boot/video.S 10 | arch/i386/kernel/head.S 11 | arch/i386/kernel/setup.c 12 | 13 | 14 | Offset Type Description 15 | ------ ---- ----------- 16 | 0 32 bytes struct screen_info, SCREEN_INFO 17 | ATTENTION, overlaps the following !!! 18 | 2 unsigned short EXT_MEM_K, extended memory size in Kb (from int 0x15) 19 | 0x20 unsigned short CL_MAGIC, commandline magic number (=0xA33F) 20 | 0x22 unsigned short CL_OFFSET, commandline offset 21 | Address of commandline is calculated: 22 | 0x90000 + contents of CL_OFFSET 23 | (only taken, when CL_MAGIC = 0xA33F) 24 | 0x40 20 bytes struct apm_bios_info, APM_BIOS_INFO 25 | 0x60 16 bytes Intel SpeedStep (IST) BIOS support information 26 | 0x80 16 bytes hd0-disk-parameter from intvector 0x41 27 | 0x90 16 bytes hd1-disk-parameter from intvector 0x46 28 | 29 | 0xa0 16 bytes System description table truncated to 16 bytes. 30 | ( struct sys_desc_table_struct ) 31 | 0xb0 - 0x1c3 Free. Add more parameters here if you really need them. 32 | 33 | 0x1c4 unsigned long EFI system table pointer 34 | 0x1c8 unsigned long EFI memory descriptor size 35 | 0x1cc unsigned long EFI memory descriptor version 36 | 0x1d0 unsigned long EFI memory descriptor map pointer 37 | 0x1d4 unsigned long EFI memory descriptor map size 38 | 0x1e0 unsigned long ALT_MEM_K, alternative mem check, in Kb 39 | 0x1e8 char number of entries in E820MAP (below) 40 | 0x1e9 unsigned char number of entries in EDDBUF (below) 41 | 0x1ea unsigned char number of entries in EDD_MBR_SIG_BUFFER (below) 42 | 0x1f1 char size of setup.S, number of sectors 43 | 0x1f2 unsigned short MOUNT_ROOT_RDONLY (if !=0) 44 | 0x1f4 unsigned short size of compressed kernel-part in the 45 | (b)zImage-file (in 16 byte units, rounded up) 46 | 0x1f6 unsigned short swap_dev (unused AFAIK) 47 | 0x1f8 unsigned short RAMDISK_FLAGS 48 | 0x1fa unsigned short VGA-Mode (old one) 49 | 0x1fc unsigned short ORIG_ROOT_DEV (high=Major, low=minor) 50 | 0x1ff char AUX_DEVICE_INFO 51 | 52 | 0x200 short jump to start of setup code aka "reserved" field. 53 | 0x202 4 bytes Signature for SETUP-header, ="HdrS" 54 | 0x206 unsigned short Version number of header format 55 | Current version is 0x0201... 56 | 0x208 8 bytes (used by setup.S for communication with boot loaders, 57 | look there) 58 | 0x210 char LOADER_TYPE, = 0, old one 59 | else it is set by the loader: 60 | 0xTV: T=0 for LILO 61 | 1 for Loadlin 62 | 2 for bootsect-loader 63 | 3 for SYSLINUX 64 | 4 for ETHERBOOT 65 | V = version 66 | 0x211 char loadflags: 67 | bit0 = 1: kernel is loaded high (bzImage) 68 | bit7 = 1: Heap and pointer (see below) set by boot 69 | loader. 70 | 0x212 unsigned short (setup.S) 71 | 0x214 unsigned long KERNEL_START, where the loader started the kernel 72 | 0x218 unsigned long INITRD_START, address of loaded ramdisk image 73 | 0x21c unsigned long INITRD_SIZE, size in bytes of ramdisk image 74 | 0x220 4 bytes (setup.S) 75 | 0x224 unsigned short setup.S heap end pointer 76 | 0x290 - 0x2cf EDD_MBR_SIG_BUFFER (edd.S) 77 | 0x2d0 - 0x600 E820MAP 78 | 0xd00 - 0xeec EDDBUF (edd.S) for edd data 79 | -------------------------------------------------------------------------------- /include/Makefile: -------------------------------------------------------------------------------- 1 | dist += include/Makefile \ 2 | include/config.h \ 3 | include/config.h.in \ 4 | include/kexec-uImage.h \ 5 | include/x86/x86-linux.h \ 6 | include/x86/mb_info.h \ 7 | include/x86/mb_header.h \ 8 | include/elf.h \ 9 | include/image.h \ 10 | include/unused.h \ 11 | include/boot/linuxbios_tables.h \ 12 | include/boot/beoboot.h \ 13 | include/boot/elf_boot.h 14 | -------------------------------------------------------------------------------- /include/boot/beoboot.h: -------------------------------------------------------------------------------- 1 | 2 | /*--- Boot image definitions ---------------------------------------*/ 3 | struct beoboot_header { 4 | char magic[4]; 5 | uint8_t arch; 6 | uint8_t flags; 7 | uint16_t cmdline_size;/* length of command line (including null) */ 8 | /* The alpha chunk is a backward compatibility hack. The original 9 | * assumption was that integer sizes didn't matter because we 10 | * would never mix architectures. x86_64 + i386 broke that 11 | * assumption. It's fixed for that combination and the future. 12 | * However, alpha needs a little hack now... */ 13 | #ifdef __alpha__ 14 | unsigned long kernel_size; 15 | unsigned long initrd_size; 16 | #else 17 | uint32_t kernel_size; 18 | uint32_t initrd_size; 19 | #endif 20 | }; 21 | #define BEOBOOT_MAGIC "BeoB" 22 | #define BEOBOOT_ARCH_I386 1 23 | #define BEOBOOT_ARCH_ALPHA 2 24 | #define BEOBOOT_ARCH_PPC 3 25 | #define BEOBOOT_ARCH_PPC64 4 26 | #if defined(__i386__) || defined(__x86_64__) 27 | #define BEOBOOT_ARCH BEOBOOT_ARCH_I386 28 | #elif defined(__alpha__) 29 | #define BEOBOOT_ARCH BEOBOOT_ARCH_ALPHA 30 | #elif defined(powerpc) 31 | #define BEOBOOT_ARCH BEOBOOT_ARCH_PPC 32 | #elif defined(__powerpc64__) 33 | #define BEOBOOT_ARCH BEOBOOT_ARCH_PPC64 34 | #else 35 | #error Unsupported architecture. 36 | #endif 37 | #define BEOBOOT_INITRD_PRESENT 1 38 | /*------------------------------------------------------------------*/ 39 | 40 | -------------------------------------------------------------------------------- /include/boot/linuxbios_tables.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUXBIOS_TABLES_H 2 | #define LINUXBIOS_TABLES_H 3 | 4 | #include 5 | 6 | /* The linuxbios table information is for conveying information 7 | * from the firmware to the loaded OS image. Primarily this 8 | * is expected to be information that cannot be discovered by 9 | * other means, such as quering the hardware directly. 10 | * 11 | * All of the information should be Position Independent Data. 12 | * That is it should be safe to relocated any of the information 13 | * without it's meaning/correctnes changing. For table that 14 | * can reasonably be used on multiple architectures the data 15 | * size should be fixed. This should ease the transition between 16 | * 32 bit and 64 bit architectures etc. 17 | * 18 | * The completeness test for the information in this table is: 19 | * - Can all of the hardware be detected? 20 | * - Are the per motherboard constants available? 21 | * - Is there enough to allow a kernel to run that was written before 22 | * a particular motherboard is constructed? (Assuming the kernel 23 | * has drivers for all of the hardware but it does not have 24 | * assumptions on how the hardware is connected together). 25 | * 26 | * With this test it should be straight forward to determine if a 27 | * table entry is required or not. This should remove much of the 28 | * long term compatibility burden as table entries which are 29 | * irrelevant or have been replaced by better alternatives may be 30 | * dropped. Of course it is polite and expidite to include extra 31 | * table entries and be backwards compatible, but it is not required. 32 | */ 33 | 34 | 35 | struct lb_header 36 | { 37 | uint8_t signature[4]; /* LBIO */ 38 | uint32_t header_bytes; 39 | uint32_t header_checksum; 40 | uint32_t table_bytes; 41 | uint32_t table_checksum; 42 | uint32_t table_entries; 43 | }; 44 | 45 | /* Every entry in the boot enviroment list will correspond to a boot 46 | * info record. Encoding both type and size. The type is obviously 47 | * so you can tell what it is. The size allows you to skip that 48 | * boot enviroment record if you don't know what it easy. This allows 49 | * forward compatibility with records not yet defined. 50 | */ 51 | struct lb_record { 52 | uint32_t tag; /* tag ID */ 53 | uint32_t size; /* size of record (in bytes) */ 54 | }; 55 | 56 | #define LB_TAG_UNUSED 0x0000 57 | 58 | #define LB_TAG_MEMORY 0x0001 59 | 60 | struct lb_memory_range { 61 | uint64_t start; 62 | uint64_t size; 63 | uint32_t type; 64 | #define LB_MEM_RAM 1 65 | #define LB_MEM_RESERVED 2 66 | 67 | }; 68 | 69 | struct lb_memory { 70 | uint32_t tag; 71 | uint32_t size; 72 | struct lb_memory_range map[0]; 73 | }; 74 | 75 | #define LB_TAG_HWRPB 0x0002 76 | struct lb_hwrpb { 77 | uint32_t tag; 78 | uint32_t size; 79 | uint64_t hwrpb; 80 | }; 81 | 82 | #endif /* LINUXBIOS_TABLES_H */ 83 | -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* include/config.h. Generated from config.h.in by configure. */ 2 | /* include/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_INTTYPES_H 1 6 | 7 | /* Define to 1 if you have the `lzma' library (-llzma). */ 8 | /* #undef HAVE_LIBLZMA */ 9 | 10 | /* Define to 1 if you have the `xenctrl' library (-lxenctrl). */ 11 | /* #undef HAVE_LIBXENCTRL */ 12 | 13 | /* Define to 1 if you have the `z' library (-lz). */ 14 | #define HAVE_LIBZ 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_MEMORY_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STDINT_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STDLIB_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_STRINGS_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_STRING_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_SYS_STAT_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_SYS_TYPES_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_UNISTD_H 1 39 | 40 | /* Define to the address where bug reports for this package should be sent. */ 41 | #define PACKAGE_BUGREPORT "" 42 | 43 | /* Define to the release date of this package */ 44 | #define PACKAGE_DATE "29 July 2010" 45 | 46 | /* Define to the full name of this package. */ 47 | #define PACKAGE_NAME "kexec-tools" 48 | 49 | /* Define to the full name and version of this package. */ 50 | #define PACKAGE_STRING "kexec-tools 2.0.2" 51 | 52 | /* Define to the one symbol short name of this package. */ 53 | #define PACKAGE_TARNAME "kexec-tools" 54 | 55 | /* Define to the home page for this package. */ 56 | #define PACKAGE_URL "" 57 | 58 | /* Define to the version of this package. */ 59 | #define PACKAGE_VERSION "2.0.2" 60 | 61 | /* Define to compile with old toolchains */ 62 | /* #undef PPC_OLDTOOLCHAIN */ 63 | 64 | /* Define to 1 if you have the ANSI C header files. */ 65 | #define STDC_HEADERS 1 66 | 67 | /* Define to include gamecube support */ 68 | /* #undef WITH_GAMECUBE */ 69 | -------------------------------------------------------------------------------- /include/config.h.in: -------------------------------------------------------------------------------- 1 | /* include/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_INTTYPES_H 5 | 6 | /* Define to 1 if you have the `lzma' library (-llzma). */ 7 | #undef HAVE_LIBLZMA 8 | 9 | /* Define to 1 if you have the `xenctrl' library (-lxenctrl). */ 10 | #undef HAVE_LIBXENCTRL 11 | 12 | /* Define to 1 if you have the `z' library (-lz). */ 13 | #undef HAVE_LIBZ 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_MEMORY_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STDINT_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STDLIB_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STRINGS_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_STRING_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_SYS_STAT_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_SYS_TYPES_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_UNISTD_H 38 | 39 | /* Define to the address where bug reports for this package should be sent. */ 40 | #undef PACKAGE_BUGREPORT 41 | 42 | /* Define to the release date of this package */ 43 | #undef PACKAGE_DATE 44 | 45 | /* Define to the full name of this package. */ 46 | #undef PACKAGE_NAME 47 | 48 | /* Define to the full name and version of this package. */ 49 | #undef PACKAGE_STRING 50 | 51 | /* Define to the one symbol short name of this package. */ 52 | #undef PACKAGE_TARNAME 53 | 54 | /* Define to the home page for this package. */ 55 | #undef PACKAGE_URL 56 | 57 | /* Define to the version of this package. */ 58 | #undef PACKAGE_VERSION 59 | 60 | /* Define to compile with old toolchains */ 61 | #undef PPC_OLDTOOLCHAIN 62 | 63 | /* Define to 1 if you have the ANSI C header files. */ 64 | #undef STDC_HEADERS 65 | 66 | /* Define to include gamecube support */ 67 | #undef WITH_GAMECUBE 68 | -------------------------------------------------------------------------------- /include/kexec-uImage.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEXEC_UIMAGE_H__ 2 | #define __KEXEC_UIMAGE_H__ 3 | 4 | struct Image_info { 5 | const char *buf; 6 | off_t len; 7 | unsigned int base; 8 | unsigned int ep; 9 | }; 10 | 11 | int uImage_probe(const char *buf, off_t len, unsigned int arch); 12 | int uImage_load(const char *buf, off_t len, struct Image_info *info); 13 | #endif 14 | -------------------------------------------------------------------------------- /include/unused.h: -------------------------------------------------------------------------------- 1 | #ifndef UNUSED_H 2 | #define UNUSED_H 3 | 4 | /* http://sourcefrog.net/weblog/software/languages/C/unused.html */ 5 | 6 | #ifdef UNUSED 7 | #elif defined(__GNUC__) 8 | # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) 9 | #elif defined(__LCLINT__) 10 | # define UNUSED(x) /*@unused@*/ x 11 | #else 12 | # define UNUSED(x) x 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/x86/mb_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB -- GRand Unified Bootloader 3 | * Copyright (C) 2000 Free Software Foundation, Inc. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | /* 21 | * MultiBoot Header description 22 | */ 23 | 24 | struct multiboot_header 25 | { 26 | /* Must be MULTIBOOT_MAGIC - see below. */ 27 | uint32_t magic; 28 | 29 | /* Feature flags - see below. */ 30 | uint32_t flags; 31 | 32 | /* 33 | * Checksum 34 | * 35 | * The above fields plus this one must equal 0 mod 2^32. 36 | */ 37 | uint32_t checksum; 38 | 39 | /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ 40 | uint32_t header_addr; 41 | uint32_t load_addr; 42 | uint32_t load_end_addr; 43 | uint32_t bss_end_addr; 44 | uint32_t entry_addr; 45 | 46 | /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ 47 | uint32_t mode_type; 48 | uint32_t width; 49 | uint32_t height; 50 | uint32_t depth; 51 | }; 52 | 53 | /* 54 | * The entire multiboot_header must be contained 55 | * within the first MULTIBOOT_SEARCH bytes of the kernel image. 56 | */ 57 | #define MULTIBOOT_SEARCH 8192 58 | #define MULTIBOOT_FOUND(addr, len) \ 59 | (! ((addr) & 0x3) \ 60 | && (len) >= 12 \ 61 | && *((int *) (addr)) == MULTIBOOT_MAGIC \ 62 | && ! (*((uint32_t *) (addr)) + *((uint32_t *) (addr + 4)) \ 63 | + *((uint32_t *) (addr + 8))) \ 64 | && (! (MULTIBOOT_AOUT_KLUDGE & *((int *) (addr + 4))) || (len) >= 32) \ 65 | && (! (MULTIBOOT_VIDEO_MODE & *((int *) (addr + 4))) || (len) >= 48)) 66 | 67 | /* Magic value identifying the multiboot_header. */ 68 | #define MULTIBOOT_MAGIC 0x1BADB002 69 | 70 | /* 71 | * Features flags for 'flags'. 72 | * If a boot loader sees a flag in MULTIBOOT_MUSTKNOW set 73 | * and it doesn't understand it, it must fail. 74 | */ 75 | #define MULTIBOOT_MUSTKNOW 0x0000FFFF 76 | 77 | /* currently unsupported flags... this is a kind of version number. */ 78 | #define MULTIBOOT_UNSUPPORTED 0x0000FFF8 79 | 80 | /* Align all boot modules on i386 page (4KB) boundaries. */ 81 | #define MULTIBOOT_PAGE_ALIGN 0x00000001 82 | 83 | /* Must pass memory information to OS. */ 84 | #define MULTIBOOT_MEMORY_INFO 0x00000002 85 | 86 | /* Must pass video information to OS. */ 87 | #define MULTIBOOT_VIDEO_MODE 0x00000004 88 | 89 | /* This flag indicates the use of the address fields in the header. */ 90 | #define MULTIBOOT_AOUT_KLUDGE 0x00010000 91 | -------------------------------------------------------------------------------- /kdump/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kdump (reading a crashdump from memory) 3 | # 4 | 5 | KDUMP_SRCS:= kdump/kdump.c 6 | 7 | KDUMP_OBJS = $(call objify, $(KDUMP_SRCS)) 8 | KDUMP_DEPS = $(call depify, $(KDUMP_OBJS)) 9 | 10 | KDUMP = $(SBINDIR)/kdump 11 | KDUMP_MANPAGE = $(MANDIR)/man8/kdump.8 12 | 13 | dist += kdump/Makefile $(KDUMP_SRCS) kdump/kdump.8 14 | clean += $(KDUMP_OBJS) $(KDUMP_DEPS) $(KDUMP) $(KDUMP_MANPAGE) 15 | 16 | -include $(KDUMP_DEPS) 17 | 18 | $(KDUMP): CC=$(TARGET_CC) 19 | $(KDUMP): $(KDUMP_OBJS) 20 | @$(MKDIR) -p $(@D) 21 | $(CC) $(LDFLAGS) -o $@ $(KDUMP_OBJS) 22 | 23 | $(KDUMP_MANPAGE): kdump/kdump.8 24 | $(MKDIR) -p $(MANDIR)/man8 25 | cp kdump/kdump.8 $(KDUMP_MANPAGE) 26 | echo:: 27 | @echo "KDUMP_SRCS $(KDUMP_SRCS)" 28 | @echo "KDUMP_DEPS $(KDUMP_DEPS)" 29 | @echo "KDUMP_OBJS $(KDUMP_OBJS)" 30 | 31 | -------------------------------------------------------------------------------- /kdump/kdump.8: -------------------------------------------------------------------------------- 1 | .\" Hey, EMACS: -*- nroff -*- 2 | .\" First parameter, NAME, should be all caps 3 | .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection 4 | .\" other parameters are allowed: see man(7), man(1) 5 | .TH KDUMP 8 "Jul 27, 2005" 6 | .\" Please adjust this date whenever revising the manpage. 7 | .\" 8 | .\" Some roff macros, for reference: 9 | .\" .nh disable hyphenation 10 | .\" .hy enable hyphenation 11 | .\" .ad l left justify 12 | .\" .ad b justify to both left and right margins 13 | .\" .nf disable filling 14 | .\" .fi enable filling 15 | .\" .br insert line break 16 | .\" .sp insert n+1 empty lines 17 | .\" for manpage-specific macros, see man(7) 18 | .SH NAME 19 | kdump \- This is just a placeholder until real man page has been written 20 | .SH SYNOPSIS 21 | .B kdump 22 | .RI [ options ] " start_address" ... 23 | .SH DESCRIPTION 24 | .PP 25 | .\" TeX users may be more comfortable with the \fB\fP and 26 | .\" \fI\fP escape sequences to invode bold face and italics, 27 | .\" respectively. 28 | \fBkdump\fP does not have a man page yet. 29 | .SH OPTIONS 30 | .\"These programs follow the usual GNU command line syntax, with long 31 | .\"options starting with two dashes (`-'). 32 | .\"A summary of options is included below. 33 | .\"For a complete description, see the Info files. 34 | .SH SEE ALSO 35 | .SH AUTHOR 36 | kdump was written by Eric Biederman. 37 | .PP 38 | This manual page was written by Khalid Aziz , 39 | for the Debian project (but may be used by others). 40 | -------------------------------------------------------------------------------- /kexec-tools.spec: -------------------------------------------------------------------------------- 1 | Summary: Load one kernel from another 2 | Name: kexec-tools 3 | Version: 2.0.2 4 | Release: 0 5 | License: GPL 6 | Group: Development/Tools 7 | Source0:%{name}-%{version}.tar.gz 8 | Packager: Eric Biederman 9 | BuildRoot: %{_tmppath}/%{name} 10 | 11 | %description 12 | /sbin/kexec is a user space utility for loading another kernel 13 | and asking the currently running kernel to do something with it. 14 | A currently running kernel may be asked to start the loaded 15 | kernel on reboot, or to start the loaded kernel after it panics. 16 | 17 | The panic case is useful for having an intact kernel for writing 18 | crash dumps. But other uses may be imagined. 19 | 20 | %prep 21 | %setup -q -n %{name}-%{version} 22 | 23 | %build 24 | %configure 25 | make 26 | 27 | %install 28 | make install DESTDIR=${RPM_BUILD_ROOT} 29 | 30 | %files 31 | %defattr(-,root,root) 32 | %{_sbindir}/kexec 33 | %{_sbindir}/kdump 34 | %{_libdir}/%{name}/kexec_test 35 | %doc News 36 | %doc COPYING 37 | %doc TODO 38 | #%{_mandir}/man8/kexec.8.gz 39 | 40 | %changelog 41 | * Tue Dec 16 2004 Eric Biederman 42 | - kexec-tools initialy packaged as an rpm. 43 | -------------------------------------------------------------------------------- /kexec-tools.spec.in: -------------------------------------------------------------------------------- 1 | Summary: Load one kernel from another 2 | Name: kexec-tools 3 | Version: 4 | Release: 0 5 | License: GPL 6 | Group: Development/Tools 7 | Source0:%{name}-%{version}.tar.gz 8 | Packager: Eric Biederman 9 | BuildRoot: %{_tmppath}/%{name} 10 | 11 | %description 12 | /sbin/kexec is a user space utility for loading another kernel 13 | and asking the currently running kernel to do something with it. 14 | A currently running kernel may be asked to start the loaded 15 | kernel on reboot, or to start the loaded kernel after it panics. 16 | 17 | The panic case is useful for having an intact kernel for writing 18 | crash dumps. But other uses may be imagined. 19 | 20 | %prep 21 | %setup -q -n %{name}-%{version} 22 | 23 | %build 24 | %configure 25 | make 26 | 27 | %install 28 | make install DESTDIR=${RPM_BUILD_ROOT} 29 | 30 | %files 31 | %defattr(-,root,root) 32 | %{_sbindir}/kexec 33 | %{_sbindir}/kdump 34 | %{_libdir}/%{name}/kexec_test 35 | %doc News 36 | %doc COPYING 37 | %doc TODO 38 | #%{_mandir}/man8/kexec.8.gz 39 | 40 | %changelog 41 | * Tue Dec 16 2004 Eric Biederman 42 | - kexec-tools initialy packaged as an rpm. 43 | -------------------------------------------------------------------------------- /kexec/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec (linux booting linux) 3 | # 4 | PURGATORY_HEX_C = kexec/purgatory.c 5 | 6 | $(PURGATORY_HEX_C): $(PURGATORY) $(BIN_TO_HEX) 7 | $(MKDIR) -p $(@D) 8 | $(BIN_TO_HEX) purgatory < $(PURGATORY) > $@ 9 | 10 | KEXEC_SRCS = 11 | KEXEC_GENERATED_SRCS = 12 | 13 | KEXEC_SRCS += kexec/kexec.c 14 | KEXEC_SRCS += kexec/ifdown.c 15 | KEXEC_SRCS += kexec/kexec-elf.c 16 | KEXEC_SRCS += kexec/kexec-elf-exec.c 17 | KEXEC_SRCS += kexec/kexec-elf-core.c 18 | KEXEC_SRCS += kexec/kexec-elf-rel.c 19 | KEXEC_SRCS += kexec/kexec-elf-boot.c 20 | KEXEC_SRCS += kexec/kexec-iomem.c 21 | KEXEC_SRCS += kexec/firmware_memmap.c 22 | KEXEC_SRCS += kexec/crashdump.c 23 | KEXEC_SRCS += kexec/crashdump-xen.c 24 | KEXEC_SRCS += kexec/phys_arch.c 25 | KEXEC_SRCS += kexec/lzma.c 26 | KEXEC_SRCS += kexec/zlib.c 27 | 28 | KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C) 29 | 30 | dist += kexec/Makefile $(KEXEC_SRCS) $(KEXEC_GENERATED_SRCS) \ 31 | kexec/crashdump-elf.c \ 32 | kexec/crashdump.h kexec/firmware_memmap.h \ 33 | kexec/kexec-elf-boot.h \ 34 | kexec/kexec-elf.h kexec/kexec-sha256.h \ 35 | kexec/kexec-zlib.h kexec/kexec-lzma.h \ 36 | kexec/kexec-syscall.h kexec/kexec.h kexec/kexec.8 37 | 38 | $(ARCH)_PROC_IOMEM = kexec/proc_iomem.c 39 | KEXEC_SRCS += $($(ARCH)_PROC_IOMEM) 40 | $(ARCH)_VIRT_TO_PHYS = kexec/virt_to_phys.c 41 | KEXEC_SRCS += $($(ARCH)_VIRT_TO_PHYS) 42 | $(ARCH)_PHYS_TO_VIRT = kexec/phys_to_virt.c 43 | KEXEC_SRCS += $($(ARCH)_PHYS_TO_VIRT) 44 | $(ARCH)_ADD_SEGMENT = kexec/add_segment.c 45 | KEXEC_SRCS += $($(ARCH)_ADD_SEGMENT) 46 | $(ARCH)_ADD_BUFFER = kexec/add_buffer.c 47 | KEXEC_SRCS += $($(ARCH)_ADD_BUFFER) 48 | $(ARCH)_ARCH_REUSE_INITRD = kexec/arch_reuse_initrd.c 49 | KEXEC_SRCS += $($(ARCH)_ARCH_REUSE_INITRD) 50 | $(ARCH)_ARCH_INIT = kexec/arch_init.c 51 | KEXEC_SRCS += $($(ARCH)_ARCH_INIT) 52 | 53 | include $(srcdir)/kexec/arch/alpha/Makefile 54 | include $(srcdir)/kexec/arch/arm/Makefile 55 | include $(srcdir)/kexec/arch/i386/Makefile 56 | include $(srcdir)/kexec/arch/ia64/Makefile 57 | include $(srcdir)/kexec/arch/mips/Makefile 58 | include $(srcdir)/kexec/arch/cris/Makefile 59 | include $(srcdir)/kexec/arch/ppc/Makefile 60 | include $(srcdir)/kexec/arch/ppc64/Makefile 61 | include $(srcdir)/kexec/arch/s390/Makefile 62 | include $(srcdir)/kexec/arch/sh/Makefile 63 | include $(srcdir)/kexec/arch/x86_64/Makefile 64 | 65 | KEXEC_SRCS += $($(ARCH)_KEXEC_SRCS) 66 | 67 | KEXEC_OBJS = $(call objify, $(KEXEC_SRCS) $(KEXEC_GENERATED_SRCS)) 68 | KEXEC_DEPS = $(call depify, $(KEXEC_OBJS)) 69 | 70 | clean += $(KEXEC_OBJS) $(KEXEC_DEPS) $(KEXEC_GENERATED_SRCS) \ 71 | $(KEXEC) $(KEXEC_MANPAGE) 72 | 73 | KEXEC = $(SBINDIR)/kexec 74 | KEXEC_MANPAGE = $(MANDIR)/man8/kexec.8 75 | 76 | -include $(KEXEC_DEPS) 77 | 78 | $(KEXEC): $(KEXEC_OBJS) $(UTIL_LIB) 79 | @$(MKDIR) -p $(@D) 80 | $(LINK.o) -o $@ $^ $(LIBS) 81 | 82 | $(KEXEC): CPPFLAGS+=-I$(srcdir)/kexec/arch/$(ARCH)/include 83 | 84 | $(KEXEC_MANPAGE): kexec/kexec.8 85 | @$(MKDIR) -p $(MANDIR)/man8 86 | cp kexec/kexec.8 $(KEXEC_MANPAGE) 87 | echo:: 88 | @echo "KEXEC_SRCS $(KEXEC_SRCS)" 89 | @echo "KEXEC_DEPS $(KEXEC_DEPS)" 90 | @echo "KEXEC_OBJS $(KEXEC_OBJS)" 91 | 92 | -------------------------------------------------------------------------------- /kexec/add_buffer.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | 3 | unsigned long add_buffer(struct kexec_info *info, 4 | const void *buf, 5 | unsigned long bufsz, 6 | unsigned long memsz, 7 | unsigned long buf_align, 8 | unsigned long buf_min, 9 | unsigned long buf_max, 10 | int buf_end) 11 | { 12 | return add_buffer_virt(info, buf, bufsz, memsz, buf_align, 13 | buf_min, buf_max, buf_end); 14 | } 15 | -------------------------------------------------------------------------------- /kexec/add_segment.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | 3 | void add_segment(struct kexec_info *info, 4 | const void *buf, size_t bufsz, 5 | unsigned long base, size_t memsz) 6 | { 7 | return add_segment_phys_virt(info, buf, bufsz, base, memsz, 0); 8 | } 9 | -------------------------------------------------------------------------------- /kexec/arch/alpha/Makefile: -------------------------------------------------------------------------------- 1 | alpha_KEXEC_SRCS= 2 | dist += kexec/arch/alpha/Makefile kexec/arch/alpha/include/arch/options.h 3 | $(alpha_KEXEC_SRCS) 4 | 5 | -------------------------------------------------------------------------------- /kexec/arch/alpha/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_ALPHA_OPTIONS_H 2 | #define KEXEC_ARCH_ALPHA_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | 6 | /* Options relevant to the architecture (excluding loader-specific ones), 7 | * in this case none: 8 | */ 9 | #define KEXEC_ARCH_OPTIONS \ 10 | KEXEC_OPTIONS \ 11 | 12 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 13 | 14 | /* See the other architectures for details of these; Alpha has no 15 | * loader-specific options yet. 16 | */ 17 | #define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS 18 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 19 | 20 | #endif /* KEXEC_ARCH_ALPHA_OPTIONS_H */ 21 | -------------------------------------------------------------------------------- /kexec/arch/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec arm (linux booting linux) 3 | # 4 | arm_KEXEC_SRCS= kexec/arch/arm/kexec-elf-rel-arm.c 5 | arm_KEXEC_SRCS+= kexec/arch/arm/kexec-zImage-arm.c 6 | arm_KEXEC_SRCS+= kexec/arch/arm/kexec-uImage-arm.c 7 | arm_KEXEC_SRCS+= kexec/arch/arm/kexec-arm.c 8 | arm_KEXEC_SRCS+= kexec/arch/arm/crashdump-arm.c 9 | arm_KEXEC_SRCS+= kexec/kexec-uImage.c 10 | 11 | arm_PHYS_TO_VIRT = kexec/arch/arm/phys_to_virt.c 12 | 13 | dist += kexec/arch/arm/Makefile $(arm_KEXEC_SRCS) $(arm_PHYS_TO_VIRT) \ 14 | kexec/arch/arm/crashdump-arm.h kexec/arch/arm/kexec-arm.h \ 15 | kexec/arch/arm/include/arch/options.h 16 | -------------------------------------------------------------------------------- /kexec/arch/arm/crashdump-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_ARM_H 2 | #define CRASHDUMP_ARM_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define COMMAND_LINE_SIZE 1024 9 | #define PAGE_OFFSET 0xc0000000 10 | #define CRASH_MAX_MEMORY_RANGES 32 11 | 12 | struct memory_ranges { 13 | unsigned int size; 14 | struct memory_range *ranges; 15 | }; 16 | 17 | extern struct memory_ranges usablemem_rgns; 18 | 19 | struct kexec_info; 20 | 21 | extern unsigned long phys_offset; 22 | extern int load_crashdump_segments(struct kexec_info *, char *); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* CRASHDUMP_ARM_H */ 29 | -------------------------------------------------------------------------------- /kexec/arch/arm/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_ARM_OPTIONS_H 2 | #define KEXEC_ARCH_ARM_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | 6 | #define OPT_APPEND 'a' 7 | #define OPT_BOARDNAME 'b' 8 | #define OPT_RAMDISK 'r' 9 | #define OPT_DTB 'd' 10 | #define OPT_RD_ADDR 'i' 11 | #define OPT_ATAGS_ADDR 'g' 12 | 13 | /* Options relevant to the architecture (excluding loader-specific ones), 14 | * in this case none: 15 | */ 16 | #define KEXEC_ARCH_OPTIONS \ 17 | KEXEC_OPTIONS \ 18 | 19 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 20 | 21 | /* The following two #defines list ALL of the options added by all of the 22 | * architecture's loaders. 23 | * o main() uses this complete list to scan for its options, ignoring 24 | * arch-specific/loader-specific ones. 25 | * o Then, arch_process_options() uses this complete list to scan for its 26 | * options, ignoring general/loader-specific ones. 27 | * o Then, the file_type[n].load re-scans for options, using 28 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 29 | * Any unrecognised options cause an error here. 30 | * 31 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 32 | * don't choose a kernel filename from random arguments to options they don't 33 | * recognise -- as they now recognise (if not act upon) all possible options. 34 | */ 35 | #define KEXEC_ALL_OPTIONS \ 36 | KEXEC_ARCH_OPTIONS \ 37 | { "command-line", 1, 0, OPT_APPEND }, \ 38 | { "append", 1, 0, OPT_APPEND }, \ 39 | { "initrd", 1, 0, OPT_RAMDISK }, \ 40 | { "ramdisk", 1, 0, OPT_RAMDISK }, \ 41 | { "dtb", 2, 0, OPT_DTB }, \ 42 | { "rd-addr", 1, 0, OPT_RD_ADDR }, \ 43 | { "atags-addr", 1, 0, OPT_ATAGS_ADDR }, \ 44 | { "boardname", 1, 0, OPT_BOARDNAME }, \ 45 | 46 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR "a:r:d::i:g:b:" 47 | 48 | #endif /* KEXEC_ARCH_ARM_OPTIONS_H */ 49 | -------------------------------------------------------------------------------- /kexec/arch/arm/kexec-arm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * modified from kexec-ppc.c 5 | * 6 | */ 7 | 8 | #define _GNU_SOURCE 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "../../kexec.h" 16 | #include "../../kexec-syscall.h" 17 | #include "kexec-arm.h" 18 | #include 19 | 20 | #define MAX_MEMORY_RANGES 64 21 | #define MAX_LINE 160 22 | static struct memory_range memory_range[MAX_MEMORY_RANGES]; 23 | 24 | /* Return a sorted list of available memory ranges. */ 25 | int get_memory_ranges(struct memory_range **range, int *ranges, 26 | unsigned long UNUSED(kexec_flags)) 27 | { 28 | const char *iomem = proc_iomem(); 29 | int memory_ranges = 0; 30 | char line[MAX_LINE]; 31 | FILE *fp; 32 | fp = fopen(iomem, "r"); 33 | if (!fp) { 34 | fprintf(stderr, "Cannot open %s: %s\n", 35 | iomem, strerror(errno)); 36 | return -1; 37 | } 38 | 39 | while(fgets(line, sizeof(line), fp) != 0) { 40 | unsigned long long start, end; 41 | char *str; 42 | int type; 43 | int consumed; 44 | int count; 45 | if (memory_ranges >= MAX_MEMORY_RANGES) 46 | break; 47 | count = sscanf(line, "%llx-%llx : %n", 48 | &start, &end, &consumed); 49 | if (count != 2) 50 | continue; 51 | str = line + consumed; 52 | end = end + 1; 53 | 54 | if (memcmp(str, "System RAM\n", 11) == 0) { 55 | type = RANGE_RAM; 56 | } 57 | else if (memcmp(str, "reserved\n", 9) == 0) { 58 | type = RANGE_RESERVED; 59 | } 60 | else { 61 | continue; 62 | } 63 | 64 | memory_range[memory_ranges].start = start; 65 | memory_range[memory_ranges].end = end; 66 | memory_range[memory_ranges].type = type; 67 | memory_ranges++; 68 | } 69 | fclose(fp); 70 | *range = memory_range; 71 | *ranges = memory_ranges; 72 | return 0; 73 | } 74 | 75 | /* Supported file types and callbacks */ 76 | struct file_type file_type[] = { 77 | /* uImage is probed before zImage because the latter also accepts 78 | uncompressed images. */ 79 | {"uImage", uImage_arm_probe, uImage_arm_load, zImage_arm_usage}, 80 | {"zImage", zImage_arm_probe, zImage_arm_load, zImage_arm_usage}, 81 | }; 82 | int file_types = sizeof(file_type) / sizeof(file_type[0]); 83 | 84 | 85 | void arch_usage(void) 86 | { 87 | } 88 | 89 | int arch_process_options(int argc, char **argv) 90 | { 91 | return 0; 92 | } 93 | 94 | const struct arch_map_entry arches[] = { 95 | { "arm", KEXEC_ARCH_ARM }, 96 | { NULL, 0 }, 97 | }; 98 | 99 | int arch_compat_trampoline(struct kexec_info *UNUSED(info)) 100 | { 101 | return 0; 102 | } 103 | 104 | void arch_update_purgatory(struct kexec_info *UNUSED(info)) 105 | { 106 | } 107 | -------------------------------------------------------------------------------- /kexec/arch/arm/kexec-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARM_H 2 | #define KEXEC_ARM_H 3 | 4 | #include 5 | 6 | #define BOOT_BLOCK_VERSION 17 7 | #define BOOT_BLOCK_LAST_COMP_VERSION 16 8 | 9 | extern off_t initrd_base, initrd_size; 10 | 11 | int zImage_arm_probe(const char *buf, off_t len); 12 | int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, 13 | struct kexec_info *info); 14 | void zImage_arm_usage(void); 15 | 16 | int uImage_arm_probe(const char *buf, off_t len); 17 | int uImage_arm_load(int argc, char **argv, const char *buf, off_t len, 18 | struct kexec_info *info); 19 | 20 | #endif /* KEXEC_ARM_H */ 21 | -------------------------------------------------------------------------------- /kexec/arch/arm/kexec-elf-rel-arm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../kexec.h" 4 | #include "../../kexec-elf.h" 5 | 6 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 7 | { 8 | if (ehdr->ei_data != ELFDATA2MSB) { 9 | return 0; 10 | } 11 | if (ehdr->ei_class != ELFCLASS32) { 12 | return 0; 13 | } 14 | if (ehdr->e_machine != EM_ARM) 15 | { 16 | return 0; 17 | } 18 | return 1; 19 | } 20 | 21 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 22 | void *location, unsigned long address, unsigned long value) 23 | { 24 | switch(r_type) { 25 | case R_ARM_ABS32: 26 | *((uint32_t *)location) += value; 27 | break; 28 | case R_ARM_REL32: 29 | *((uint32_t *)location) += value - address; 30 | break; 31 | default: 32 | die("Unknown rel relocation: %lu\n", r_type); 33 | break; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /kexec/arch/arm/kexec-uImage-arm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * uImage support added by Marc Andre Tanner 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "../../kexec.h" 10 | #include "kexec-arm.h" 11 | 12 | int uImage_arm_probe(const char *buf, off_t len) 13 | { 14 | // undefined reference on Android, and I don't need uImages 15 | // return uImage_probe(buf, len, IH_ARCH_ARM); 16 | return -1; 17 | } 18 | 19 | int uImage_arm_load(int argc, char **argv, const char *buf, off_t len, 20 | struct kexec_info *info) 21 | { 22 | return zImage_arm_load(argc, argv, buf + sizeof(struct image_header), 23 | len - sizeof(struct image_header), info); 24 | } 25 | -------------------------------------------------------------------------------- /kexec/arch/arm/mach.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mach.h" 3 | 4 | extern const struct arch_mach arm_mach_hammerhead; 5 | extern const struct arch_mach arm_mach_shamu; 6 | extern const struct arch_mach arm_mach_m8; 7 | static const struct arm_mach *const arm_machs[] = { 8 | &arm_mach_hammerhead, 9 | &arm_mach_shamu, 10 | &arm_mach_m8, 11 | NULL 12 | }; 13 | // update zImage_arm_usage when modifying this. 14 | 15 | struct arm_mach *arm_mach_choose(const char *boardname) 16 | { 17 | int i, x; 18 | for(i = 0; arm_machs[i]; ++i) 19 | { 20 | struct arm_mach *m = arm_machs[i]; 21 | for(x = 0; m->boardnames[x]; ++x) 22 | { 23 | if(strcmp(m->boardnames[x], boardname) == 0) 24 | return m; 25 | } 26 | } 27 | 28 | return NULL; 29 | } 30 | -------------------------------------------------------------------------------- /kexec/arch/arm/mach.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_ARM_MACH_H 2 | #define KEXEC_ARCH_ARM_MACH_H 3 | 4 | #include 5 | 6 | 7 | struct arm_mach 8 | { 9 | int (*choose_dtb)(const char *dtb_img, off_t dtb_len, char **dtb_buf, off_t *dtb_length); 10 | int (*add_extra_regs)(void *dtb_buf); 11 | char *const boardnames[]; 12 | }; 13 | 14 | struct arm_mach *arm_mach_choose(const char *boardname); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /kexec/arch/arm/phys_to_virt.c: -------------------------------------------------------------------------------- 1 | #include "../../kexec.h" 2 | #include "../../crashdump.h" 3 | #include "crashdump-arm.h" 4 | 5 | /** 6 | * phys_to_virt() - translate physical address to virtual address 7 | * @paddr: physical address to translate 8 | * 9 | * For ARM we have following equation to translate from virtual address to 10 | * physical: 11 | * paddr = vaddr - PAGE_OFFSET + PHYS_OFFSET 12 | * 13 | * See also: 14 | * http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html 15 | */ 16 | unsigned long 17 | phys_to_virt(struct crash_elf_info *elf_info, unsigned long paddr) 18 | { 19 | return paddr + elf_info->page_offset - phys_offset; 20 | } 21 | -------------------------------------------------------------------------------- /kexec/arch/cris/Makefile: -------------------------------------------------------------------------------- 1 | cris_KEXEC_SRCS = kexec/arch/cris/kexec-cris.c 2 | cris_KEXEC_SRCS += kexec/arch/cris/kexec-elf-cris.c 3 | cris_KEXEC_SRCS += kexec/arch/cris/cris-setup-simple.S 4 | cris_KEXEC_SRCS += kexec/arch/cris/kexec-elf-rel-cris.c 5 | 6 | cris_ADD_BUFFER = 7 | cris_ADD_SEGMENT = 8 | cris_VIRT_TO_PHYS = 9 | 10 | dist += kexec/arch/cris/Makefile $(cris_KEXEC_SRCS) \ 11 | kexec/arch/cris/kexec-cris.h \ 12 | kexec/arch/cris/include/arch/options.h 13 | 14 | -------------------------------------------------------------------------------- /kexec/arch/cris/cris-setup-simple.S: -------------------------------------------------------------------------------- 1 | /* 2 | * cris-setup-simple.S - code to execute before stepping into the new kernel. 3 | * Copyright (C) 2008 AXIS Communications AB 4 | * Written by Edgar E. Iglesias 5 | * 6 | * This source code is licensed under the GNU General Public License, 7 | * Version 2. See the file COPYING for more details. 8 | */ 9 | 10 | .data 11 | .globl cris_trampoline 12 | cris_trampoline: 13 | .balign 4 14 | lapc cris_regframe, $sp 15 | moveq 0, $r0 16 | move $r0, $pid 17 | 18 | movem [$sp+], $r14 19 | jump $r0 20 | nop 21 | 22 | .globl cris_regframe 23 | cris_regframe: 24 | .balign 4 25 | .fill 16, 4, 0 26 | cris_trampoline_end: 27 | 28 | .globl cris_trampoline_size 29 | cris_trampoline_size: 30 | .long cris_trampoline_end - cris_trampoline 31 | 32 | -------------------------------------------------------------------------------- /kexec/arch/cris/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_CRIS_OPTIONS_H 2 | #define KEXEC_ARCH_CRIS_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | #define OPT_APPEND (OPT_ARCH_MAX+0) 6 | 7 | /* Options relevant to the architecture (excluding loader-specific ones), 8 | * in this case none: 9 | */ 10 | #define KEXEC_ARCH_OPTIONS \ 11 | KEXEC_OPTIONS \ 12 | 13 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 14 | 15 | /* The following two #defines list ALL of the options added by all of the 16 | * architecture's loaders. 17 | * o main() uses this complete list to scan for its options, ignoring 18 | * arch-specific/loader-specific ones. 19 | * o Then, arch_process_options() uses this complete list to scan for its 20 | * options, ignoring general/loader-specific ones. 21 | * o Then, the file_type[n].load re-scans for options, using 22 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 23 | * Any unrecognised options cause an error here. 24 | * 25 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 26 | * don't choose a kernel filename from random arguments to options they don't 27 | * recognise -- as they now recognise (if not act upon) all possible options. 28 | */ 29 | #define KEXEC_ALL_OPTIONS \ 30 | KEXEC_ARCH_OPTIONS \ 31 | {"append", 1, 0, OPT_APPEND}, 32 | 33 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 34 | 35 | #endif /* KEXEC_ARCH_CRIS_OPTIONS_H */ 36 | -------------------------------------------------------------------------------- /kexec/arch/cris/kexec-cris.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec-cris.c 3 | * Copyright (C) 2008 AXIS Communications AB 4 | * Written by Edgar E. Iglesias 5 | * 6 | * This source code is licensed under the GNU General Public License, 7 | * Version 2. See the file COPYING for more details. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "../../kexec.h" 17 | #include "../../kexec-syscall.h" 18 | #include "kexec-cris.h" 19 | #include 20 | 21 | #define MAX_MEMORY_RANGES 64 22 | #define MAX_LINE 160 23 | static struct memory_range memory_range[MAX_MEMORY_RANGES]; 24 | 25 | /* Return a sorted list of memory ranges. */ 26 | int get_memory_ranges(struct memory_range **range, int *ranges, 27 | unsigned long UNUSED(kexec_flags)) 28 | { 29 | int memory_ranges = 0; 30 | 31 | memory_range[memory_ranges].start = 0x40000000; 32 | memory_range[memory_ranges].end = 0x41000000; 33 | memory_range[memory_ranges].type = RANGE_RAM; 34 | memory_ranges++; 35 | 36 | memory_range[memory_ranges].start = 0xc0000000; 37 | memory_range[memory_ranges].end = 0xc1000000; 38 | memory_range[memory_ranges].type = RANGE_RAM; 39 | memory_ranges++; 40 | 41 | *range = memory_range; 42 | *ranges = memory_ranges; 43 | return 0; 44 | } 45 | 46 | struct file_type file_type[] = { 47 | {"elf-cris", elf_cris_probe, elf_cris_load, elf_cris_usage}, 48 | }; 49 | int file_types = sizeof(file_type) / sizeof(file_type[0]); 50 | 51 | void arch_usage(void) 52 | { 53 | } 54 | 55 | int arch_process_options(int argc, char **argv) 56 | { 57 | return 0; 58 | } 59 | 60 | const struct arch_map_entry arches[] = { 61 | { "cris", KEXEC_ARCH_CRIS }, 62 | { "crisv32", KEXEC_ARCH_CRIS }, 63 | { 0 }, 64 | }; 65 | 66 | int arch_compat_trampoline(struct kexec_info *UNUSED(info)) 67 | { 68 | return 0; 69 | } 70 | 71 | void arch_update_purgatory(struct kexec_info *UNUSED(info)) 72 | { 73 | } 74 | 75 | int is_crashkernel_mem_reserved(void) 76 | { 77 | return 1; 78 | } 79 | 80 | unsigned long virt_to_phys(unsigned long addr) 81 | { 82 | return (addr) & 0x7fffffff; 83 | } 84 | 85 | /* 86 | * add_segment() should convert base to a physical address on superh, 87 | * while the default is just to work with base as is */ 88 | void add_segment(struct kexec_info *info, const void *buf, size_t bufsz, 89 | unsigned long base, size_t memsz) 90 | { 91 | add_segment_phys_virt(info, buf, bufsz, base, memsz, 1); 92 | } 93 | 94 | /* 95 | * add_buffer() should convert base to a physical address on superh, 96 | * while the default is just to work with base as is */ 97 | unsigned long add_buffer(struct kexec_info *info, const void *buf, 98 | unsigned long bufsz, unsigned long memsz, 99 | unsigned long buf_align, unsigned long buf_min, 100 | unsigned long buf_max, int buf_end) 101 | { 102 | return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align, 103 | buf_min, buf_max, buf_end, 1); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /kexec/arch/cris/kexec-cris.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_CRIS_H 2 | #define KEXEC_CRIS_H 3 | 4 | extern unsigned char setup_simple_start[]; 5 | extern uint32_t setup_simple_size; 6 | 7 | extern struct { 8 | uint32_t spr8; 9 | uint32_t spr9; 10 | } setup_simple_regs; 11 | 12 | int elf_cris_probe(const char *buf, off_t len); 13 | int elf_cris_load(int argc, char **argv, const char *buf, off_t len, 14 | struct kexec_info *info); 15 | void elf_cris_usage(void); 16 | 17 | #endif /* KEXEC_CRIS_H */ 18 | -------------------------------------------------------------------------------- /kexec/arch/cris/kexec-elf-rel-cris.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec-elf-rel-cris.c - kexec Elf relocation routines 3 | * Copyright (C) 2008 AXIS Communications AB 4 | * Written by Edgar E. Iglesias 5 | * 6 | * derived from ../ppc/kexec-elf-rel-ppc.c 7 | * Copyright (C) 2004 Albert Herranz 8 | * 9 | * This source code is licensed under the GNU General Public License, 10 | * Version 2. See the file COPYING for more details. 11 | */ 12 | 13 | #include 14 | #include 15 | #include "../../kexec.h" 16 | #include "../../kexec-elf.h" 17 | 18 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 19 | { 20 | if (ehdr->ei_data != ELFDATA2MSB) { 21 | return 0; 22 | } 23 | if (ehdr->ei_class != ELFCLASS32) { 24 | return 0; 25 | } 26 | if (ehdr->e_machine != EM_CRIS) { 27 | return 0; 28 | } 29 | return 1; 30 | } 31 | 32 | void machine_apply_elf_rel(struct mem_ehdr *ehdr, unsigned long r_type, 33 | void *location, unsigned long address, unsigned long value) 34 | { 35 | switch(r_type) { 36 | 37 | default: 38 | die("Unknown rela relocation: %lu\n", r_type); 39 | break; 40 | } 41 | return; 42 | } 43 | -------------------------------------------------------------------------------- /kexec/arch/i386/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec i386 (linux booting linux) 3 | # 4 | i386_KEXEC_SRCS = kexec/arch/i386/kexec-x86.c 5 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-x86-common.c 6 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-x86.c 7 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-rel-x86.c 8 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-bzImage.c 9 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c 10 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c 11 | i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c 12 | i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c 13 | i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c 14 | 15 | dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS) \ 16 | kexec/arch/i386/kexec-x86.h kexec/arch/i386/crashdump-x86.h \ 17 | kexec/arch/i386/x86-linux-setup.h \ 18 | kexec/arch/i386/include/arch/options.h 19 | -------------------------------------------------------------------------------- /kexec/arch/i386/crashdump-x86.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_X86_H 2 | #define CRASHDUMP_X86_H 3 | 4 | struct kexec_info; 5 | int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline, 6 | unsigned long max_addr, unsigned long min_base); 7 | 8 | #define PAGE_OFFSET 0xc0000000 9 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 10 | 11 | #define __VMALLOC_RESERVE (128 << 20) 12 | #define MAXMEM (-PAGE_OFFSET-__VMALLOC_RESERVE) 13 | 14 | #define CRASH_MAX_MEMMAP_NR (KEXEC_MAX_SEGMENTS + 1) 15 | #define CRASH_MAX_MEMORY_RANGES (MAX_MEMORY_RANGES + 2) 16 | 17 | /* Backup Region, First 640K of System RAM. */ 18 | #define BACKUP_SRC_START 0x00000000 19 | #define BACKUP_SRC_END 0x0009ffff 20 | #define BACKUP_SRC_SIZE (BACKUP_SRC_END - BACKUP_SRC_START + 1) 21 | 22 | #endif /* CRASHDUMP_X86_H */ 23 | -------------------------------------------------------------------------------- /kexec/arch/i386/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_I386_OPTIONS_H 2 | #define KEXEC_ARCH_I386_OPTIONS_H 3 | 4 | /* 5 | ************************************************************************* 6 | * NOTE NOTE NOTE 7 | * This file is included for i386 builds *and* x86_64 builds (which build 8 | * both x86_64 and i386 loaders). 9 | * It contains the combined set of options used by i386 and x86_64. 10 | ************************************************************************* 11 | */ 12 | 13 | #define OPT_RESET_VGA (OPT_MAX+0) 14 | #define OPT_SERIAL (OPT_MAX+1) 15 | #define OPT_SERIAL_BAUD (OPT_MAX+2) 16 | #define OPT_CONSOLE_VGA (OPT_MAX+3) 17 | #define OPT_CONSOLE_SERIAL (OPT_MAX+4) 18 | #define OPT_ELF32_CORE (OPT_MAX+5) 19 | #define OPT_ELF64_CORE (OPT_MAX+6) 20 | #define OPT_ARCH_MAX (OPT_MAX+7) 21 | 22 | #define OPT_APPEND (OPT_ARCH_MAX+0) 23 | #define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) 24 | #define OPT_RAMDISK (OPT_ARCH_MAX+2) 25 | #define OPT_ARGS_ELF (OPT_ARCH_MAX+3) 26 | #define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) 27 | #define OPT_ARGS_NONE (OPT_ARCH_MAX+5) 28 | #define OPT_CL (OPT_ARCH_MAX+6) 29 | #define OPT_MOD (OPT_ARCH_MAX+7) 30 | #define OPT_VGA (OPT_ARCH_MAX+8) 31 | #define OPT_REAL_MODE (OPT_ARCH_MAX+9) 32 | 33 | /* Options relevant to the architecture (excluding loader-specific ones): */ 34 | #define KEXEC_ARCH_OPTIONS \ 35 | KEXEC_OPTIONS \ 36 | { "reset-vga", 0, 0, OPT_RESET_VGA }, \ 37 | { "serial", 1, 0, OPT_SERIAL }, \ 38 | { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ 39 | { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ 40 | { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ 41 | { "elf32-core-headers", 0, 0, OPT_ELF32_CORE }, \ 42 | { "elf64-core-headers", 0, 0, OPT_ELF64_CORE }, \ 43 | 44 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 45 | 46 | /* The following two #defines list ALL of the options added by all of the 47 | * architecture's loaders. 48 | * o main() uses this complete list to scan for its options, ignoring 49 | * arch-specific/loader-specific ones. 50 | * o Then, arch_process_options() uses this complete list to scan for its 51 | * options, ignoring general/loader-specific ones. 52 | * o Then, the file_type[n].load re-scans for options, using 53 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 54 | * Any unrecognised options cause an error here. 55 | * 56 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 57 | * don't choose a kernel filename from random arguments to options they don't 58 | * recognise -- as they now recognise (if not act upon) all possible options. 59 | */ 60 | #define KEXEC_ALL_OPTIONS \ 61 | KEXEC_ARCH_OPTIONS \ 62 | { "command-line", 1, NULL, OPT_APPEND }, \ 63 | { "append", 1, NULL, OPT_APPEND }, \ 64 | { "reuse-cmdline", 0, NULL, OPT_REUSE_CMDLINE }, \ 65 | { "initrd", 1, NULL, OPT_RAMDISK }, \ 66 | { "ramdisk", 1, NULL, OPT_RAMDISK }, \ 67 | { "args-elf", 0, NULL, OPT_ARGS_ELF }, \ 68 | { "args-linux", 0, NULL, OPT_ARGS_LINUX }, \ 69 | { "args-none", 0, NULL, OPT_ARGS_NONE }, \ 70 | { "debug", 0, NULL, OPT_DEBUG }, \ 71 | { "module", 1, 0, OPT_MOD }, \ 72 | { "real-mode", 0, NULL, OPT_REAL_MODE }, 73 | 74 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 75 | 76 | #endif /* KEXEC_ARCH_I386_OPTIONS_H */ 77 | 78 | -------------------------------------------------------------------------------- /kexec/arch/i386/kexec-elf-rel-x86.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../kexec.h" 4 | #include "../../kexec-elf.h" 5 | 6 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 7 | { 8 | if (ehdr->ei_data != ELFDATA2LSB) { 9 | return 0; 10 | } 11 | if (ehdr->ei_class != ELFCLASS32) { 12 | return 0; 13 | } 14 | if ((ehdr->e_machine != EM_386) && (ehdr->e_machine != EM_486)) 15 | { 16 | return 0; 17 | } 18 | return 1; 19 | } 20 | 21 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 22 | void *location, unsigned long address, unsigned long value) 23 | { 24 | switch(r_type) { 25 | case R_386_32: 26 | *((uint32_t *)location) += value; 27 | break; 28 | case R_386_PC32: 29 | *((uint32_t *)location) += value - address; 30 | break; 31 | default: 32 | die("Unknown rel relocation: %lu\n", r_type); 33 | break; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /kexec/arch/i386/kexec-x86.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_X86_H 2 | #define KEXEC_X86_H 3 | 4 | #define MAX_MEMORY_RANGES 1024 5 | 6 | enum coretype { 7 | CORE_TYPE_UNDEF = 0, 8 | CORE_TYPE_ELF32 = 1, 9 | CORE_TYPE_ELF64 = 2 10 | }; 11 | 12 | extern unsigned char compat_x86_64[]; 13 | extern uint32_t compat_x86_64_size, compat_x86_64_entry32; 14 | 15 | struct entry32_regs { 16 | uint32_t eax; 17 | uint32_t ebx; 18 | uint32_t ecx; 19 | uint32_t edx; 20 | uint32_t esi; 21 | uint32_t edi; 22 | uint32_t esp; 23 | uint32_t ebp; 24 | uint32_t eip; 25 | }; 26 | 27 | struct entry16_regs { 28 | uint32_t eax; 29 | uint32_t ebx; 30 | uint32_t ecx; 31 | uint32_t edx; 32 | uint32_t esi; 33 | uint32_t edi; 34 | uint32_t esp; 35 | uint32_t ebp; 36 | uint16_t ds; 37 | uint16_t es; 38 | uint16_t ss; 39 | uint16_t fs; 40 | uint16_t gs; 41 | uint16_t ip; 42 | uint16_t cs; 43 | uint16_t pad; 44 | }; 45 | 46 | struct arch_options_t { 47 | uint8_t reset_vga; 48 | uint16_t serial_base; 49 | uint32_t serial_baud; 50 | uint8_t console_vga; 51 | uint8_t console_serial; 52 | enum coretype core_header_type; 53 | }; 54 | 55 | int multiboot_x86_probe(const char *buf, off_t len); 56 | int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len, 57 | struct kexec_info *info); 58 | void multiboot_x86_usage(void); 59 | 60 | int elf_x86_probe(const char *buf, off_t len); 61 | int elf_x86_load(int argc, char **argv, const char *buf, off_t len, 62 | struct kexec_info *info); 63 | void elf_x86_usage(void); 64 | 65 | int bzImage_probe(const char *buf, off_t len); 66 | int bzImage_load(int argc, char **argv, const char *buf, off_t len, 67 | struct kexec_info *info); 68 | void bzImage_usage(void); 69 | int do_bzImage_load(struct kexec_info *info, 70 | const char *kernel, off_t kernel_len, 71 | const char *command_line, off_t command_line_len, 72 | const char *initrd, off_t initrd_len, 73 | int real_mode_entry, int debug); 74 | 75 | int beoboot_probe(const char *buf, off_t len); 76 | int beoboot_load(int argc, char **argv, const char *buf, off_t len, 77 | struct kexec_info *info); 78 | void beoboot_usage(void); 79 | 80 | int nbi_probe(const char *buf, off_t len); 81 | int nbi_load(int argc, char **argv, const char *buf, off_t len, 82 | struct kexec_info *info); 83 | void nbi_usage(void); 84 | #endif /* KEXEC_X86_H */ 85 | -------------------------------------------------------------------------------- /kexec/arch/i386/x86-linux-setup.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_LINUX_SETUP_H 2 | #define X86_LINUX_SETUP_H 3 | 4 | void init_linux_parameters(struct x86_linux_param_header *real_mode); 5 | void setup_linux_bootloader_parameters( 6 | struct kexec_info *info, struct x86_linux_param_header *real_mode, 7 | unsigned long real_mode_base, unsigned long cmdline_offset, 8 | const char *cmdline, off_t cmdline_len, 9 | const char *initrd_buf, off_t initrd_size); 10 | void setup_linux_system_parameters(struct x86_linux_param_header *real_mode, 11 | unsigned long kexec_flags); 12 | 13 | 14 | #define SETUP_BASE 0x90000 15 | #define KERN32_BASE 0x100000 /* 1MB */ 16 | #define INITRD_BASE 0x1000000 /* 16MB */ 17 | 18 | /* command line parameter may be appended by purgatory */ 19 | #define PURGATORY_CMDLINE_SIZE 64 20 | 21 | #endif /* X86_LINUX_SETUP_H */ 22 | -------------------------------------------------------------------------------- /kexec/arch/ia64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec ia64 (linux booting linux) 3 | # 4 | ia64_KEXEC_SRCS = kexec/arch/ia64/kexec-iomem.c 5 | ia64_KEXEC_SRCS += kexec/arch/ia64/kexec-ia64.c 6 | ia64_KEXEC_SRCS += kexec/arch/ia64/kexec-elf-ia64.c 7 | ia64_KEXEC_SRCS += kexec/arch/ia64/kexec-elf-rel-ia64.c 8 | ia64_KEXEC_SRCS += kexec/arch/ia64/crashdump-ia64.c 9 | 10 | ia64_PROC_IOMEM = 11 | 12 | dist += kexec/arch/ia64/Makefile $(ia64_KEXEC_SRCS) \ 13 | kexec/arch/ia64/kexec-ia64.h kexec/arch/ia64/crashdump-ia64.h \ 14 | kexec/arch/ia64/include/arch/options.h 15 | 16 | 17 | -------------------------------------------------------------------------------- /kexec/arch/ia64/crashdump-ia64.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_IA64_H 2 | #define CRASHDUMP_IA64_H 3 | 4 | #define PAGE_OFFSET 0xe000000000000000UL 5 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 6 | extern int load_crashdump_segments(struct kexec_info *info, 7 | struct mem_ehdr *ehdr, unsigned long max_addr, 8 | unsigned long min_base, const char **cmdline); 9 | 10 | #define CRASH_MAX_MEMMAP_NR (KEXEC_MAX_SEGMENTS + 1) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /kexec/arch/ia64/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_IA64_OPTIONS_H 2 | #define KEXEC_ARCH_IA64_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | #define OPT_APPEND (OPT_ARCH_MAX+0) 6 | #define OPT_RAMDISK (OPT_ARCH_MAX+1) 7 | #define OPT_NOIO (OPT_ARCH_MAX+2) 8 | #define OPT_VMM (OPT_ARCH_MAX+3) 9 | 10 | /* Options relevant to the architecture (excluding loader-specific ones), 11 | * in this case none: 12 | */ 13 | #define KEXEC_ARCH_OPTIONS \ 14 | KEXEC_OPTIONS \ 15 | 16 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 17 | 18 | /* The following two #defines list ALL of the options added by all of the 19 | * architecture's loaders. 20 | * o main() uses this complete list to scan for its options, ignoring 21 | * arch-specific/loader-specific ones. 22 | * o Then, arch_process_options() uses this complete list to scan for its 23 | * options, ignoring general/loader-specific ones. 24 | * o Then, the file_type[n].load re-scans for options, using 25 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 26 | * Any unrecognised options cause an error here. 27 | * 28 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 29 | * don't choose a kernel filename from random arguments to options they don't 30 | * recognise -- as they now recognise (if not act upon) all possible options. 31 | */ 32 | #define KEXEC_ALL_OPTIONS \ 33 | KEXEC_ARCH_OPTIONS \ 34 | {"command-line", 1, 0, OPT_APPEND}, \ 35 | {"append", 1, 0, OPT_APPEND}, \ 36 | {"initrd", 1, 0, OPT_RAMDISK}, \ 37 | {"noio", 0, 0, OPT_NOIO}, \ 38 | {"vmm", 1, 0, OPT_VMM}, \ 39 | 40 | #define KEXEC_ALL_OPT_STR KEXEC_OPT_STR 41 | 42 | #endif /* KEXEC_ARCH_IA64_OPTIONS_H */ 43 | -------------------------------------------------------------------------------- /kexec/arch/ia64/kexec-ia64.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_IA64_H 2 | #define KEXEC_IA64_H 3 | 4 | extern int max_memory_ranges; 5 | int elf_ia64_probe(const char *buf, off_t len); 6 | int elf_ia64_load(int argc, char **argv, const char *buf, off_t len, 7 | struct kexec_info *info); 8 | void elf_ia64_usage(void); 9 | int update_loaded_segments(struct mem_ehdr *ehdr); 10 | void move_loaded_segments(struct mem_ehdr *ehdr, unsigned long addr); 11 | 12 | #define EFI_PAGE_SIZE (1UL<<12) 13 | #define ELF_PAGE_SIZE (1UL<<16) 14 | #endif /* KEXEC_IA64_H */ 15 | -------------------------------------------------------------------------------- /kexec/arch/ia64/kexec-iomem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../kexec.h" 4 | #include "../../crashdump.h" 5 | 6 | static const char proc_iomem_str[]= "/proc/iomem"; 7 | static const char proc_iomem_machine_str[]= "/proc/iomem_machine"; 8 | 9 | /* 10 | * On IA64 XEN the EFI tables are virtualised. 11 | * For this reason on such systems /proc/iomem_machine is provided, 12 | * which is based on the hypervisor's (machine's) EFI tables. 13 | * If Xen is in use, then /proc/iomem is used for memory regions relating 14 | * to the currently running dom0 kernel, and /proc/iomem_machine is used 15 | * for regions relating to the machine itself or the hypervisor. 16 | * If Xen is not in used, then /proc/iomem used. 17 | */ 18 | const char *proc_iomem(void) 19 | { 20 | if (xen_present()) 21 | return proc_iomem_machine_str; 22 | return proc_iomem_str; 23 | } 24 | -------------------------------------------------------------------------------- /kexec/arch/mips/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec mips (linux booting linux) 3 | # 4 | mips_KEXEC_SRCS = kexec/arch/mips/kexec-mips.c 5 | mips_KEXEC_SRCS += kexec/arch/mips/kexec-elf-mips.c 6 | mips_KEXEC_SRCS += kexec/arch/mips/kexec-elf-rel-mips.c 7 | mips_KEXEC_SRCS += kexec/arch/mips/crashdump-mips.c 8 | 9 | mips_ADD_BUFFER = 10 | mips_ADD_SEGMENT = 11 | mips_VIRT_TO_PHYS = 12 | 13 | dist += kexec/arch/mips/Makefile $(mips_KEXEC_SRCS) \ 14 | kexec/arch/mips/kexec-mips.h \ 15 | kexec/arch/mips/crashdump-mips.h \ 16 | kexec/arch/mips/include/arch/options.h 17 | -------------------------------------------------------------------------------- /kexec/arch/mips/crashdump-mips.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_MIPS_H 2 | #define CRASHDUMP_MIPS_H 3 | 4 | struct kexec_info; 5 | int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline, 6 | unsigned long max_addr, unsigned long min_base); 7 | #ifdef __mips64 8 | #define PAGE_OFFSET 0xa800000000000000ULL 9 | #else 10 | #define PAGE_OFFSET 0x80000000 11 | #endif 12 | #define __pa(x) ((unsigned long)(X) & 0x7fffffff) 13 | 14 | #define MAXMEM 0x80000000 15 | 16 | #define CRASH_MAX_MEMMAP_NR (KEXEC_MAX_SEGMENTS + 1) 17 | #define CRASH_MAX_MEMORY_RANGES (MAX_MEMORY_RANGES + 2) 18 | 19 | #define COMMAND_LINE_SIZE 512 20 | 21 | /* Backup Region, First 1M of System RAM. */ 22 | #define BACKUP_SRC_START 0x00000000 23 | #define BACKUP_SRC_END 0x000fffff 24 | #define BACKUP_SRC_SIZE (BACKUP_SRC_END - BACKUP_SRC_START + 1) 25 | 26 | extern struct arch_options_t arch_options; 27 | #endif /* CRASHDUMP_MIPS_H */ 28 | -------------------------------------------------------------------------------- /kexec/arch/mips/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_MIPS_OPTIONS_H 2 | #define KEXEC_ARCH_MIPS_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | #define OPT_APPEND (OPT_ARCH_MAX+0) 6 | 7 | /* Options relevant to the architecture (excluding loader-specific ones), 8 | * in this case none: 9 | */ 10 | #define KEXEC_ARCH_OPTIONS \ 11 | KEXEC_OPTIONS \ 12 | 13 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 14 | 15 | /* The following two #defines list ALL of the options added by all of the 16 | * architecture's loaders. 17 | * o main() uses this complete list to scan for its options, ignoring 18 | * arch-specific/loader-specific ones. 19 | * o Then, arch_process_options() uses this complete list to scan for its 20 | * options, ignoring general/loader-specific ones. 21 | * o Then, the file_type[n].load re-scans for options, using 22 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 23 | * Any unrecognised options cause an error here. 24 | * 25 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 26 | * don't choose a kernel filename from random arguments to options they don't 27 | * recognise -- as they now recognise (if not act upon) all possible options. 28 | */ 29 | #define KEXEC_ALL_OPTIONS \ 30 | KEXEC_ARCH_OPTIONS \ 31 | {"command-line", 1, 0, OPT_APPEND}, \ 32 | {"append", 1, 0, OPT_APPEND}, 33 | 34 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 35 | 36 | #endif /* KEXEC_ARCH_MIPS_OPTIONS_H */ 37 | -------------------------------------------------------------------------------- /kexec/arch/mips/kexec-elf-rel-mips.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec-elf-rel-mips.c - kexec Elf relocation routines 3 | * Copyright (C) 2007 Francesco Chiechi, Alessandro Rubini 4 | * Copyright (C) 2007 Tvblob s.r.l. 5 | * 6 | * derived from ../ppc/kexec-elf-rel-ppc.c 7 | * Copyright (C) 2004 Albert Herranz 8 | * 9 | * This source code is licensed under the GNU General Public License, 10 | * Version 2. See the file COPYING for more details. 11 | */ 12 | 13 | #include 14 | #include 15 | #include "../../kexec.h" 16 | #include "../../kexec-elf.h" 17 | 18 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 19 | { 20 | if (ehdr->ei_data != ELFDATA2MSB) { 21 | return 0; 22 | } 23 | if (ehdr->ei_class != ELFCLASS32) { 24 | return 0; 25 | } 26 | if (ehdr->e_machine != EM_MIPS) { 27 | return 0; 28 | } 29 | return 1; 30 | } 31 | 32 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 33 | void *UNUSED(location), 34 | unsigned long UNUSED(address), 35 | unsigned long UNUSED(value)) 36 | { 37 | switch(r_type) { 38 | 39 | default: 40 | die("Unknown rela relocation: %lu\n", r_type); 41 | break; 42 | } 43 | return; 44 | } 45 | -------------------------------------------------------------------------------- /kexec/arch/mips/kexec-mips.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_MIPS_H 2 | #define KEXEC_MIPS_H 3 | 4 | #define MAX_MEMORY_RANGES 64 5 | #define MAX_LINE 160 6 | 7 | #define CORE_TYPE_ELF32 1 8 | #define CORE_TYPE_ELF64 2 9 | extern unsigned char setup_simple_start[]; 10 | extern uint32_t setup_simple_size; 11 | 12 | extern struct { 13 | uint32_t spr8; 14 | uint32_t spr9; 15 | } setup_simple_regs; 16 | 17 | int elf_mips_probe(const char *buf, off_t len); 18 | int elf_mips_load(int argc, char **argv, const char *buf, off_t len, 19 | struct kexec_info *info); 20 | void elf_mips_usage(void); 21 | 22 | struct arch_options_t { 23 | int core_header_type; 24 | }; 25 | 26 | #endif /* KEXEC_MIPS_H */ 27 | -------------------------------------------------------------------------------- /kexec/arch/ppc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec ppc (linux booting linux) 3 | # 4 | include kexec/arch/ppc/libfdt/Makefile.libfdt 5 | 6 | ppc_KEXEC_SRCS = kexec/arch/ppc/kexec-ppc.c 7 | ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-ppc.c 8 | ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-rel-ppc.c 9 | ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-dol-ppc.c 10 | ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-uImage-ppc.c 11 | ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S 12 | ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S 13 | ppc_KEXEC_SRCS += kexec/arch/ppc/fixup_dtb.c 14 | ppc_KEXEC_SRCS += kexec/arch/ppc/fs2dt.c 15 | ppc_KEXEC_SRCS += kexec/arch/ppc/crashdump-powerpc.c 16 | ppc_KEXEC_SRCS += kexec/kexec-uImage.c 17 | 18 | libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c 19 | libfdt_SRCS += $(LIBFDT_SRCS:%=kexec/arch/ppc/libfdt/%) 20 | 21 | CPPFLAGS+=-I$(srcdir)/kexec/arch/$(ARCH)/libfdt 22 | 23 | ppc_KEXEC_SRCS += $(libfdt_SRCS) 24 | 25 | dist += kexec/arch/ppc/Makefile $(ppc_KEXEC_SRCS) \ 26 | kexec/arch/ppc/crashdump-powerpc.h kexec/arch/ppc/fixup_dtb.h \ 27 | kexec/arch/ppc/kexec-ppc.h kexec/arch/ppc/ops.h \ 28 | kexec/arch/ppc/ppc_asm.h \ 29 | kexec/arch/ppc/include/page.h kexec/arch/ppc/include/types.h \ 30 | kexec/arch/ppc/include/arch/options.h 31 | -------------------------------------------------------------------------------- /kexec/arch/ppc/crashdump-powerpc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_POWERPC_H 2 | #define CRASHDUMP_POWERPC_H 3 | 4 | struct kexec_info; 5 | int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline, 6 | unsigned long max_addr, unsigned long min_base); 7 | void add_usable_mem_rgns(unsigned long long base, unsigned long long size); 8 | 9 | extern struct arch_options_t arch_options; 10 | 11 | #ifdef CONFIG_PPC64 12 | #define PAGE_OFFSET 0xC000000000000000UL 13 | #define VMALLOCBASE 0xD000000000000000UL 14 | #define MAXMEM (-KERNELBASE-VMALLOCBASE) 15 | #else 16 | #define PAGE_OFFSET 0xC0000000 17 | #define MAXMEM 0x30000000 /* Use CONFIG_LOWMEM_SIZE from kernel */ 18 | #endif 19 | 20 | #define KERNELBASE PAGE_OFFSET 21 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 22 | 23 | #define COMMAND_LINE_SIZE 512 /* from kernel */ 24 | /* Backup Region, First 64K of System RAM. */ 25 | #define BACKUP_SRC_START 0x0000 26 | #define BACKUP_SRC_END 0xffff 27 | #define BACKUP_SRC_SIZE (BACKUP_SRC_END - BACKUP_SRC_START + 1) 28 | 29 | #define KDUMP_BACKUP_LIMIT BACKUP_SRC_SIZE 30 | #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1))) 31 | #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1))) 32 | 33 | extern unsigned long long crash_base; 34 | extern unsigned long long crash_size; 35 | extern unsigned int rtas_base; 36 | extern unsigned int rtas_size; 37 | 38 | #endif /* CRASHDUMP_POWERPC_H */ 39 | -------------------------------------------------------------------------------- /kexec/arch/ppc/fixup_dtb.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../../kexec.h" 11 | #include 12 | #include "ops.h" 13 | #include "page.h" 14 | #include "fixup_dtb.h" 15 | 16 | const char proc_dts[] = "/proc/device-tree"; 17 | 18 | static void fixup_nodes(char *nodes[]) 19 | { 20 | int index = 0; 21 | char *fname; 22 | char *prop_name; 23 | char *node_name; 24 | void *node; 25 | int len; 26 | char *content; 27 | off_t content_size; 28 | int ret; 29 | 30 | while (nodes[index]) { 31 | 32 | len = asprintf(&fname, "%s%s", proc_dts, nodes[index]); 33 | if (len < 0) 34 | fatal("asprintf() failed\n"); 35 | 36 | content = slurp_file(fname, &content_size); 37 | if (!content) { 38 | fprintf(stderr, "Can't open %s: %s\n", 39 | fname, strerror(errno)); 40 | exit(1); 41 | } 42 | 43 | prop_name = fname + len; 44 | while (*prop_name != '/') 45 | prop_name--; 46 | 47 | *prop_name = '\0'; 48 | prop_name++; 49 | 50 | node_name = fname + sizeof(proc_dts) - 1; 51 | 52 | node = finddevice(node_name); 53 | if (!node) 54 | node = create_node(NULL, node_name + 1); 55 | 56 | ret = setprop(node, prop_name, content, content_size); 57 | if (ret < 0) 58 | fatal("setprop of %s/%s size: %ld failed: %s\n", 59 | node_name, prop_name, content_size, 60 | fdt_strerror(ret)); 61 | 62 | free(content); 63 | free(fname); 64 | index++; 65 | }; 66 | } 67 | 68 | /* 69 | * command line priority: 70 | * - use the supplied command line 71 | * - if none available use the command line from .dtb 72 | * - if not available use the current command line 73 | */ 74 | static void fixup_cmdline(const char *cmdline) 75 | { 76 | void *chosen; 77 | char *fixup_cmd_node[] = { 78 | "/chosen/bootargs", 79 | NULL, 80 | }; 81 | 82 | chosen = finddevice("/chosen"); 83 | 84 | if (!cmdline) { 85 | if (!chosen) 86 | fixup_nodes(fixup_cmd_node); 87 | } else { 88 | if (!chosen) 89 | chosen = create_node(NULL, "chosen"); 90 | setprop_str(chosen, "bootargs", cmdline); 91 | } 92 | return; 93 | } 94 | 95 | char *fixup_dtb_nodes(char *blob_buf, off_t *blob_size, char *nodes[], char *cmdline) 96 | { 97 | fdt_init(blob_buf); 98 | 99 | fixup_nodes(nodes); 100 | fixup_cmdline(cmdline); 101 | 102 | blob_buf = (char *)dt_ops.finalize(); 103 | *blob_size = fdt_totalsize(blob_buf); 104 | return blob_buf; 105 | } 106 | -------------------------------------------------------------------------------- /kexec/arch/ppc/fixup_dtb.h: -------------------------------------------------------------------------------- 1 | #ifndef __FIXUP_DTB_H 2 | #define __FIXUP_DTB_H 3 | 4 | char *fixup_dtb_nodes(char *blob_buf, off_t *blob_size, char *nodes[], char *cmdline); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /kexec/arch/ppc/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_PPC_OPTIONS_H 2 | #define KEXEC_ARCH_PPC_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | 6 | /* All 'local' loader options: */ 7 | #define OPT_APPEND (OPT_ARCH_MAX+0) 8 | #define OPT_GAMECUBE (OPT_ARCH_MAX+1) 9 | #define OPT_DTB (OPT_ARCH_MAX+2) 10 | #define OPT_NODES (OPT_ARCH_MAX+3) 11 | 12 | /* Options relevant to the architecture (excluding loader-specific ones), 13 | * in this case none: 14 | */ 15 | #define KEXEC_ARCH_OPTIONS \ 16 | KEXEC_OPTIONS \ 17 | 18 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 19 | 20 | /* The following two #defines list ALL of the options added by all of the 21 | * architecture's loaders. 22 | * o main() uses this complete list to scan for its options, ignoring 23 | * arch-specific/loader-specific ones. 24 | * o Then, arch_process_options() uses this complete list to scan for its 25 | * options, ignoring general/loader-specific ones. 26 | * o Then, the file_type[n].load re-scans for options, using 27 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 28 | * Any unrecognised options cause an error here. 29 | * 30 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 31 | * don't choose a kernel filename from random arguments to options they don't 32 | * recognise -- as they now recognise (if not act upon) all possible options. 33 | */ 34 | #define KEXEC_ALL_OPTIONS \ 35 | KEXEC_ARCH_OPTIONS \ 36 | {"command-line", 1, 0, OPT_APPEND},\ 37 | {"append", 1, 0, OPT_APPEND},\ 38 | {"gamecube", 1, 0, OPT_GAMECUBE},\ 39 | {"dtb", 1, 0, OPT_DTB},\ 40 | {"reuse-node", 1, 0, OPT_NODES},\ 41 | {"debug", 0, 0, OPT_DEBUG}, 42 | 43 | #define KEXEC_ALL_OPT_STR KEXEC_OPT_STR 44 | 45 | #endif /* KEXEC_ARCH_PPC_OPTIONS_H */ 46 | -------------------------------------------------------------------------------- /kexec/arch/ppc/include/page.h: -------------------------------------------------------------------------------- 1 | #ifndef _PPC_BOOT_PAGE_H 2 | #define _PPC_BOOT_PAGE_H 3 | /* 4 | * Copyright (C) 2001 PPC64 Team, IBM Corp 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 9 | * 2 of the License, or (at your option) any later version. 10 | */ 11 | 12 | #ifdef __ASSEMBLY__ 13 | #define ASM_CONST(x) x 14 | #else 15 | #define __ASM_CONST(x) x##UL 16 | #define ASM_CONST(x) __ASM_CONST(x) 17 | #endif 18 | 19 | /* PAGE_SHIFT determines the page size */ 20 | #define PAGE_SHIFT 12 21 | #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) 22 | #define PAGE_MASK (~(PAGE_SIZE-1)) 23 | 24 | /* align addr on a size boundary - adjust address up/down if needed */ 25 | #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 26 | #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1))) 27 | 28 | /* align addr on a size boundary - adjust address up if needed */ 29 | #define _ALIGN(addr,size) _ALIGN_UP(addr,size) 30 | 31 | /* to align the pointer to the (next) page boundary */ 32 | #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE) 33 | 34 | #endif /* _PPC_BOOT_PAGE_H */ 35 | -------------------------------------------------------------------------------- /kexec/arch/ppc/include/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPES_H_ 2 | #define _TYPES_H_ 3 | 4 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 5 | 6 | typedef unsigned char u8; 7 | typedef unsigned short u16; 8 | typedef unsigned int u32; 9 | typedef unsigned long long u64; 10 | typedef signed char s8; 11 | typedef short s16; 12 | typedef int s32; 13 | typedef long long s64; 14 | 15 | #define min(x,y) ({ \ 16 | typeof(x) _x = (x); \ 17 | typeof(y) _y = (y); \ 18 | (void) (&_x == &_y); \ 19 | _x < _y ? _x : _y; }) 20 | 21 | #define max(x,y) ({ \ 22 | typeof(x) _x = (x); \ 23 | typeof(y) _y = (y); \ 24 | (void) (&_x == &_y); \ 25 | _x > _y ? _x : _y; }) 26 | 27 | #endif /* _TYPES_H_ */ 28 | -------------------------------------------------------------------------------- /kexec/arch/ppc/kexec-elf-rel-ppc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../kexec.h" 4 | #include "../../kexec-elf.h" 5 | 6 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 7 | { 8 | if (ehdr->ei_data != ELFDATA2MSB) { 9 | return 0; 10 | } 11 | if (ehdr->ei_class != ELFCLASS32) { 12 | return 0; 13 | } 14 | if (ehdr->e_machine != EM_PPC) { 15 | return 0; 16 | } 17 | return 1; 18 | } 19 | 20 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 21 | void *location, unsigned long address, unsigned long value) 22 | { 23 | switch(r_type) { 24 | case R_PPC_ADDR32: 25 | /* Simply set it */ 26 | *(uint32_t *)location = value; 27 | break; 28 | 29 | case R_PPC_ADDR16_LO: 30 | /* Low half of the symbol */ 31 | *(uint16_t *)location = value; 32 | break; 33 | 34 | case R_PPC_ADDR16_HI: 35 | *(uint16_t *)location = (value>>16) & 0xffff; 36 | break; 37 | 38 | case R_PPC_ADDR16_HA: 39 | /* Sign-adjusted lower 16 bits: PPC ELF ABI says: 40 | (((x >> 16) + ((x & 0x8000) ? 1 : 0))) & 0xFFFF. 41 | This is the same, only sane. 42 | */ 43 | *(uint16_t *)location = (value + 0x8000) >> 16; 44 | break; 45 | 46 | case R_PPC_REL24: 47 | if ((int)(value - address) < -0x02000000 48 | || (int)(value - address) >= 0x02000000) 49 | { 50 | die("Symbol more than 16MiB away"); 51 | } 52 | /* Only replace bits 2 through 26 */ 53 | *(uint32_t *)location 54 | = (*(uint32_t *)location & ~0x03fffffc) 55 | | ((value - address) 56 | & 0x03fffffc); 57 | break; 58 | 59 | case R_PPC_REL32: 60 | /* 32-bit relative jump. */ 61 | *(uint32_t *)location = value - address; 62 | break; 63 | default: 64 | die("Unknown rela relocation: %lu\n", r_type); 65 | break; 66 | } 67 | return; 68 | } 69 | -------------------------------------------------------------------------------- /kexec/arch/ppc/kexec-ppc.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_PPC_H 2 | #define KEXEC_PPC_H 3 | 4 | #define MAXBYTES 128 5 | #define MAX_LINE 160 6 | #define CORE_TYPE_ELF32 1 7 | #define CORE_TYPE_ELF64 2 8 | 9 | extern unsigned char setup_simple_start[]; 10 | extern uint32_t setup_simple_size; 11 | 12 | extern struct { 13 | uint32_t spr8; 14 | } setup_simple_regs; 15 | 16 | extern unsigned char setup_dol_start[]; 17 | extern uint32_t setup_dol_size; 18 | extern uint64_t rmo_top; 19 | 20 | extern struct { 21 | uint32_t spr8; 22 | } setup_dol_regs; 23 | 24 | #define SIZE_16M (16*1024*1024UL) 25 | 26 | int elf_ppc_probe(const char *buf, off_t len); 27 | int elf_ppc_load(int argc, char **argv, const char *buf, off_t len, 28 | struct kexec_info *info); 29 | void elf_ppc_usage(void); 30 | 31 | int uImage_ppc_probe(const char *buf, off_t len); 32 | int uImage_ppc_load(int argc, char **argv, const char *buf, off_t len, 33 | struct kexec_info *info); 34 | void uImage_ppc_usage(void); 35 | 36 | int dol_ppc_probe(const char *buf, off_t len); 37 | int dol_ppc_load(int argc, char **argv, const char *buf, off_t len, 38 | struct kexec_info *info); 39 | void dol_ppc_usage(void); 40 | 41 | /* 42 | * During inital setup the kernel does not map the whole memory but a part of 43 | * it. On Book-E that is 64MiB, 601 24MiB or 256MiB (if possible). 44 | */ 45 | #define KERNEL_ACCESS_TOP (24 * 1024 * 1024) 46 | 47 | /* boot block version 17 as defined by the linux kernel */ 48 | struct bootblock { 49 | unsigned magic, 50 | totalsize, 51 | off_dt_struct, 52 | off_dt_strings, 53 | off_mem_rsvmap, 54 | version, 55 | last_comp_version, 56 | boot_physid, 57 | dt_strings_size, 58 | dt_struct_size; 59 | }; 60 | 61 | typedef struct mem_rgns { 62 | unsigned int size; 63 | struct memory_range *ranges; 64 | } mem_rgns_t; 65 | extern mem_rgns_t usablemem_rgns; 66 | extern int max_memory_ranges; 67 | extern unsigned long long initrd_base, initrd_size; 68 | extern unsigned char reuse_initrd; 69 | #define COMMAND_LINE_SIZE 512 /* from kernel */ 70 | /*fs2dt*/ 71 | void reserve(unsigned long long where, unsigned long long length); 72 | #endif /* KEXEC_PPC_H */ 73 | -------------------------------------------------------------------------------- /kexec/arch/ppc/libfdt/Makefile.libfdt: -------------------------------------------------------------------------------- 1 | # Makefile.libfdt 2 | # 3 | # This is not a complete Makefile of itself. Instead, it is designed to 4 | # be easily embeddable into other systems of Makefiles. 5 | # 6 | LIBFDT_INCLUDES = fdt.h libfdt.h 7 | LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 8 | LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 9 | 10 | dist += kexec/arch/ppc/libfdt/Makefile.libfdt \ 11 | kexec/arch/ppc/libfdt/fdt.h kexec/arch/ppc/libfdt/libfdt.h \ 12 | kexec/arch/ppc/libfdt/libfdt_env.h \ 13 | kexec/arch/ppc/libfdt/libfdt_internal.h 14 | -------------------------------------------------------------------------------- /kexec/arch/ppc/libfdt/fdt.h: -------------------------------------------------------------------------------- 1 | #ifndef _FDT_H 2 | #define _FDT_H 3 | 4 | #ifndef __ASSEMBLY__ 5 | 6 | struct fdt_header { 7 | uint32_t magic; /* magic word FDT_MAGIC */ 8 | uint32_t totalsize; /* total size of DT block */ 9 | uint32_t off_dt_struct; /* offset to structure */ 10 | uint32_t off_dt_strings; /* offset to strings */ 11 | uint32_t off_mem_rsvmap; /* offset to memory reserve map */ 12 | uint32_t version; /* format version */ 13 | uint32_t last_comp_version; /* last compatible version */ 14 | 15 | /* version 2 fields below */ 16 | uint32_t boot_cpuid_phys; /* Which physical CPU id we're 17 | booting on */ 18 | /* version 3 fields below */ 19 | uint32_t size_dt_strings; /* size of the strings block */ 20 | 21 | /* version 17 fields below */ 22 | uint32_t size_dt_struct; /* size of the structure block */ 23 | }; 24 | 25 | struct fdt_reserve_entry { 26 | uint64_t address; 27 | uint64_t size; 28 | }; 29 | 30 | struct fdt_node_header { 31 | uint32_t tag; 32 | char name[0]; 33 | }; 34 | 35 | struct fdt_property { 36 | uint32_t tag; 37 | uint32_t len; 38 | uint32_t nameoff; 39 | char data[0]; 40 | }; 41 | 42 | #endif /* !__ASSEMBLY */ 43 | 44 | #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ 45 | #define FDT_TAGSIZE sizeof(uint32_t) 46 | 47 | #define FDT_BEGIN_NODE 0x1 /* Start node: full name */ 48 | #define FDT_END_NODE 0x2 /* End node */ 49 | #define FDT_PROP 0x3 /* Property: name off, 50 | size, content */ 51 | #define FDT_NOP 0x4 /* nop */ 52 | #define FDT_END 0x9 53 | 54 | #define FDT_V1_SIZE (7*sizeof(uint32_t)) 55 | #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(uint32_t)) 56 | #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(uint32_t)) 57 | #define FDT_V16_SIZE FDT_V3_SIZE 58 | #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(uint32_t)) 59 | 60 | #endif /* _FDT_H */ 61 | -------------------------------------------------------------------------------- /kexec/arch/ppc/libfdt/libfdt_env.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBFDT_ENV_H 2 | #define _LIBFDT_ENV_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define _B(n) ((unsigned long long)((uint8_t *)&x)[n]) 9 | static inline uint32_t fdt32_to_cpu(uint32_t x) 10 | { 11 | return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3); 12 | } 13 | #define cpu_to_fdt32(x) fdt32_to_cpu(x) 14 | 15 | static inline uint64_t fdt64_to_cpu(uint64_t x) 16 | { 17 | return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32) 18 | | (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7); 19 | } 20 | #define cpu_to_fdt64(x) fdt64_to_cpu(x) 21 | #undef _B 22 | 23 | #endif /* _LIBFDT_ENV_H */ 24 | -------------------------------------------------------------------------------- /kexec/arch/ppc/ppc-setup-simple.S: -------------------------------------------------------------------------------- 1 | /* 2 | * ppc-setup-simple.S - (hopefully) setup for simple embedded platforms 3 | * Copyright (C) 2004 Albert Herranz 4 | * 5 | * This source code is licensed under the GNU General Public License, 6 | * Version 2. See the file COPYING for more details. 7 | */ 8 | 9 | /* 10 | * Only suitable for platforms booting with MMU turned off. 11 | * -- Albert Herranz 12 | */ 13 | 14 | #include "ppc_asm.h" 15 | 16 | .data 17 | .globl setup_simple_start 18 | setup_simple_start: 19 | 20 | /* should perform here any required setup */ 21 | 22 | RELOC_SYM(setup_simple_regs) 23 | mr r9, r3 24 | lwz r5, spr8 - setup_simple_regs(r9) 25 | 26 | mtlr r5 27 | blr 28 | 29 | .balign 4 30 | .globl setup_simple_regs 31 | setup_simple_regs: 32 | spr8: .long 0x00000000 33 | 34 | setup_simple_end: 35 | 36 | .globl setup_simple_size 37 | setup_simple_size: 38 | .long setup_simple_end - setup_simple_start 39 | 40 | -------------------------------------------------------------------------------- /kexec/arch/ppc64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec ppc64 (linux booting linux) 3 | # 4 | ppc64_KEXEC_SRCS = kexec/arch/ppc64/kexec-elf-rel-ppc64.c 5 | ppc64_KEXEC_SRCS += kexec/arch/ppc64/kexec-zImage-ppc64.c 6 | ppc64_KEXEC_SRCS += kexec/arch/ppc64/fs2dt.c 7 | ppc64_KEXEC_SRCS += kexec/arch/ppc64/kexec-elf-ppc64.c 8 | ppc64_KEXEC_SRCS += kexec/arch/ppc64/kexec-ppc64.c 9 | ppc64_KEXEC_SRCS += kexec/arch/ppc64/crashdump-ppc64.c 10 | 11 | ppc64_ARCH_REUSE_INITRD = 12 | 13 | dist += kexec/arch/ppc64/Makefile $(ppc64_KEXEC_SRCS) \ 14 | kexec/arch/ppc64/kexec-ppc64.h kexec/arch/ppc64/crashdump-ppc64.h \ 15 | kexec/arch/ppc64/include/arch/options.h 16 | 17 | -------------------------------------------------------------------------------- /kexec/arch/ppc64/crashdump-ppc64.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_PPC64_H 2 | #define CRASHDUMP_PPC64_H 3 | 4 | struct kexec_info; 5 | int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline, 6 | uint64_t max_addr, unsigned long min_base); 7 | void add_usable_mem_rgns(unsigned long long base, unsigned long long size); 8 | 9 | #define PAGE_OFFSET 0xC000000000000000ULL 10 | #define KERNELBASE PAGE_OFFSET 11 | #define VMALLOCBASE 0xD000000000000000ULL 12 | 13 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 14 | #define MAXMEM (-KERNELBASE-VMALLOCBASE) 15 | 16 | #define COMMAND_LINE_SIZE 512 /* from kernel */ 17 | /* Backup Region, First 64K of System RAM. */ 18 | #define BACKUP_SRC_START 0x0000 19 | #define BACKUP_SRC_END 0xffff 20 | #define BACKUP_SRC_SIZE (BACKUP_SRC_END - BACKUP_SRC_START + 1) 21 | 22 | #define KDUMP_BACKUP_LIMIT BACKUP_SRC_SIZE 23 | #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) 24 | #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1))) 25 | 26 | #define KERNEL_RUN_AT_ZERO_MAGIC 0x72756e30 /* "run0" */ 27 | 28 | extern uint64_t crash_base; 29 | extern uint64_t crash_size; 30 | extern unsigned int rtas_base; 31 | extern unsigned int rtas_size; 32 | 33 | uint64_t lmb_size; 34 | unsigned int num_of_lmbs; 35 | 36 | #define DRCONF_ADDR 0 37 | #define DRCONF_FLAGS 20 38 | 39 | #endif /* CRASHDUMP_PPC64_H */ 40 | -------------------------------------------------------------------------------- /kexec/arch/ppc64/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_PPC64_OPTIONS_H 2 | #define KEXEC_ARCH_PPC64_OPTIONS_H 3 | 4 | #define OPT_ELF64_CORE (OPT_MAX+0) 5 | #define OPT_ARCH_MAX (OPT_MAX+1) 6 | 7 | /* All 'local' loader options: */ 8 | #define OPT_APPEND (OPT_ARCH_MAX+0) 9 | #define OPT_RAMDISK (OPT_ARCH_MAX+1) 10 | #define OPT_DEVICETREEBLOB (OPT_ARCH_MAX+2) 11 | #define OPT_ARGS_IGNORE (OPT_ARCH_MAX+3) 12 | 13 | /* Options relevant to the architecture (excluding loader-specific ones): */ 14 | #define KEXEC_ARCH_OPTIONS \ 15 | KEXEC_OPTIONS \ 16 | { "elf64-core-headers", 0, 0, OPT_ELF64_CORE }, \ 17 | 18 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 19 | 20 | /* The following two #defines list ALL of the options added by all of the 21 | * architecture's loaders. 22 | * o main() uses this complete list to scan for its options, ignoring 23 | * arch-specific/loader-specific ones. 24 | * o Then, arch_process_options() uses this complete list to scan for its 25 | * options, ignoring general/loader-specific ones. 26 | * o Then, the file_type[n].load re-scans for options, using 27 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 28 | * Any unrecognised options cause an error here. 29 | * 30 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 31 | * don't choose a kernel filename from random arguments to options they don't 32 | * recognise -- as they now recognise (if not act upon) all possible options. 33 | */ 34 | #define KEXEC_ALL_OPTIONS \ 35 | KEXEC_ARCH_OPTIONS \ 36 | { "command-line", 1, NULL, OPT_APPEND }, \ 37 | { "append", 1, NULL, OPT_APPEND }, \ 38 | { "ramdisk", 1, NULL, OPT_RAMDISK }, \ 39 | { "initrd", 1, NULL, OPT_RAMDISK }, \ 40 | { "devicetreeblob", 1, NULL, OPT_DEVICETREEBLOB }, \ 41 | { "args-linux", 0, NULL, OPT_ARGS_IGNORE }, 42 | 43 | #define KEXEC_ALL_OPT_STR KEXEC_OPT_STR 44 | 45 | 46 | #endif /* KEXEC_ARCH_PPC64_OPTIONS_H */ 47 | -------------------------------------------------------------------------------- /kexec/arch/ppc64/kexec-elf-rel-ppc64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../../kexec.h" 5 | #include "../../kexec-elf.h" 6 | #include "kexec-ppc64.h" 7 | 8 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 9 | { 10 | if (ehdr->ei_data != ELFDATA2MSB) { 11 | return 0; 12 | } 13 | if (ehdr->ei_class != ELFCLASS64) { 14 | return 0; 15 | } 16 | if (ehdr->e_machine != EM_PPC64) { 17 | return 0; 18 | } 19 | return 1; 20 | } 21 | 22 | static struct mem_shdr *toc_section(const struct mem_ehdr *ehdr) 23 | { 24 | struct mem_shdr *shdr, *shdr_end; 25 | unsigned char *strtab; 26 | strtab = (unsigned char *)ehdr->e_shdr[ehdr->e_shstrndx].sh_data; 27 | shdr_end = &ehdr->e_shdr[ehdr->e_shnum]; 28 | for(shdr = ehdr->e_shdr; shdr != shdr_end; shdr++) 29 | if ( shdr->sh_size && 30 | strcmp((char *)&strtab[shdr->sh_name], 31 | ".toc") == 0) 32 | return shdr; 33 | return NULL; 34 | } 35 | 36 | /* r2 is the TOC pointer: it actually points 0x8000 into the TOC (this 37 | gives the value maximum span in an instruction which uses a signed 38 | offset) */ 39 | unsigned long my_r2(const struct mem_ehdr *ehdr) 40 | { 41 | struct mem_shdr *shdr; 42 | shdr = toc_section(ehdr); 43 | if (!shdr) { 44 | die("TOC reloc without a toc section?"); 45 | } 46 | return shdr->sh_addr + 0x8000; 47 | } 48 | 49 | 50 | void machine_apply_elf_rel(struct mem_ehdr *ehdr, unsigned long r_type, 51 | void *location, unsigned long address, unsigned long value) 52 | { 53 | switch(r_type) { 54 | case R_PPC64_ADDR32: 55 | /* Simply set it */ 56 | *(uint32_t *)location = value; 57 | break; 58 | 59 | case R_PPC64_ADDR64: 60 | case R_PPC64_REL64: 61 | /* Simply set it */ 62 | *(uint64_t *)location = value; 63 | break; 64 | 65 | case R_PPC64_REL32: 66 | *(uint32_t *)location = value - (uint32_t)(uint64_t)location; 67 | break; 68 | 69 | case R_PPC64_TOC: 70 | *(uint64_t *)location = my_r2(ehdr); 71 | break; 72 | 73 | case R_PPC64_TOC16_DS: 74 | /* Subtact TOC pointer */ 75 | value -= my_r2(ehdr); 76 | if ((value & 3) != 0 || value + 0x8000 > 0xffff) { 77 | die("bad TOC16_DS relocation (%lu)\n", value); 78 | } 79 | *((uint16_t *) location) 80 | = (*((uint16_t *) location) & ~0xfffc) 81 | | (value & 0xfffc); 82 | break; 83 | 84 | case R_PPC64_REL24: 85 | /* Convert value to relative */ 86 | value -= address; 87 | if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0){ 88 | die("REL24 %li out of range!\n", 89 | (long int)value); 90 | } 91 | 92 | /* Only replace bits 2 through 26 */ 93 | *(uint32_t *)location = (*(uint32_t *)location & ~0x03fffffc) 94 | | (value & 0x03fffffc); 95 | break; 96 | 97 | case R_PPC64_ADDR16_LO: 98 | *(uint16_t *)location = value & 0xffff; 99 | break; 100 | 101 | case R_PPC64_ADDR16_HI: 102 | *(uint16_t *)location = (value>>16) & 0xffff; 103 | break; 104 | 105 | case R_PPC64_ADDR16_HA: 106 | *(uint16_t *)location = (((value+0x8000)>>16) & 0xffff); 107 | break; 108 | 109 | case R_PPC64_ADDR16_HIGHEST: 110 | *(uint16_t *)location = (((uint64_t)value>>48) & 0xffff); 111 | break; 112 | case R_PPC64_ADDR16_HIGHER: 113 | *(uint16_t *)location = (((uint64_t)value>>32) & 0xffff); 114 | break; 115 | 116 | default: 117 | die("Unknown rela relocation: %lu\n", r_type); 118 | break; 119 | } 120 | return; 121 | } 122 | -------------------------------------------------------------------------------- /kexec/arch/ppc64/kexec-ppc64.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_PPC64_H 2 | #define KEXEC_PPC64_H 3 | 4 | #define MAXBYTES 128 5 | #define MAX_LINE 160 6 | #define CORE_TYPE_ELF32 1 7 | #define CORE_TYPE_ELF64 2 8 | 9 | int setup_memory_ranges(unsigned long kexec_flags); 10 | 11 | int elf_ppc64_probe(const char *buf, off_t len); 12 | int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len, 13 | struct kexec_info *info); 14 | void elf_ppc64_usage(void); 15 | void reserve(unsigned long long where, unsigned long long length); 16 | 17 | int create_flatten_tree(char **, off_t *, char *); 18 | unsigned long my_r2(const struct mem_ehdr *ehdr); 19 | 20 | extern uint64_t initrd_base, initrd_size; 21 | extern int max_memory_ranges; 22 | extern unsigned char reuse_initrd; 23 | 24 | /* boot block version 2 as defined by the linux kernel */ 25 | struct bootblock { 26 | unsigned magic, 27 | totalsize, 28 | off_dt_struct, 29 | off_dt_strings, 30 | off_mem_rsvmap, 31 | version, 32 | last_comp_version, 33 | boot_physid; 34 | }; 35 | 36 | struct arch_options_t { 37 | int core_header_type; 38 | }; 39 | 40 | typedef struct mem_rgns { 41 | unsigned int size; 42 | struct memory_range *ranges; 43 | } mem_rgns_t; 44 | 45 | extern mem_rgns_t usablemem_rgns; 46 | 47 | #endif /* KEXEC_PPC64_H */ 48 | -------------------------------------------------------------------------------- /kexec/arch/s390/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec s390 (linux booting linux) 3 | # 4 | s390_KEXEC_SRCS = kexec/arch/s390/kexec-s390.c 5 | s390_KEXEC_SRCS += kexec/arch/s390/kexec-image.c 6 | s390_KEXEC_SRCS += kexec/arch/s390/kexec-elf-rel-s390.c 7 | 8 | dist += kexec/arch/s390/Makefile $(s390_KEXEC_SRCS) \ 9 | kexec/arch/s390/kexec-s390.h \ 10 | kexec/arch/s390/include/arch/options.h 11 | -------------------------------------------------------------------------------- /kexec/arch/s390/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_S390_OPTIONS_H 2 | #define KEXEC_ARCH_S390_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | #define OPT_APPEND OPT_MAX+0 6 | #define OPT_RAMDISK OPT_MAX+1 7 | 8 | /* Options relevant to the architecture (excluding loader-specific ones), 9 | * in this case none: 10 | */ 11 | #define KEXEC_ARCH_OPTIONS \ 12 | KEXEC_OPTIONS \ 13 | 14 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 15 | 16 | /* The following two #defines list ALL of the options added by all of the 17 | * architecture's loaders. 18 | * o main() uses this complete list to scan for its options, ignoring 19 | * arch-specific/loader-specific ones. 20 | * o Then, arch_process_options() uses this complete list to scan for its 21 | * options, ignoring general/loader-specific ones. 22 | * o Then, the file_type[n].load re-scans for options, using 23 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 24 | * Any unrecognised options cause an error here. 25 | * 26 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 27 | * don't choose a kernel filename from random arguments to options they don't 28 | * recognise -- as they now recognise (if not act upon) all possible options. 29 | */ 30 | #define KEXEC_ALL_OPTIONS \ 31 | KEXEC_ARCH_OPTIONS \ 32 | {"command-line", 1, 0, OPT_APPEND}, \ 33 | {"initrd", 1, 0, OPT_RAMDISK}, 34 | 35 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 36 | 37 | #endif /* KEXEC_ARCH_S390_OPTIONS_H */ 38 | -------------------------------------------------------------------------------- /kexec/arch/s390/kexec-elf-rel-s390.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec/arch/s390/kexec-elf-rel-s390.c 3 | * 4 | * (C) Copyright IBM Corp. 2005 5 | * 6 | * Author(s): Heiko Carstens 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | #include "../../kexec.h" 13 | #include "../../kexec-elf.h" 14 | 15 | int machine_verify_elf_rel(struct mem_ehdr *UNUSED(ehdr)) 16 | { 17 | return 0; 18 | } 19 | 20 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), 21 | unsigned long UNUSED(r_type), 22 | void *UNUSED(location), 23 | unsigned long UNUSED(address), 24 | unsigned long UNUSED(value)) 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /kexec/arch/s390/kexec-s390.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec/arch/s390/kexec-s390.c 3 | * 4 | * (C) Copyright IBM Corp. 2005 5 | * 6 | * Author(s): Rolf Adelsberger 7 | * 8 | */ 9 | 10 | #define _GNU_SOURCE 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "../../kexec.h" 18 | #include "../../kexec-syscall.h" 19 | #include "kexec-s390.h" 20 | #include 21 | 22 | #define MAX_MEMORY_RANGES 64 23 | static struct memory_range memory_range[MAX_MEMORY_RANGES]; 24 | 25 | /* 26 | * get_memory_ranges: 27 | * Return a list of memory ranges by parsing the file returned by 28 | * proc_iomem() 29 | * 30 | * INPUT: 31 | * - Pointer to an array of memory_range structures. 32 | * - Pointer to an integer with holds the number of memory ranges. 33 | * 34 | * RETURN: 35 | * - 0 on normal execution. 36 | * - (-1) if something went wrong. 37 | */ 38 | 39 | int get_memory_ranges(struct memory_range **range, int *ranges, 40 | unsigned long UNUSED(flags)) 41 | { 42 | char sys_ram[] = "System RAM\n"; 43 | const char *iomem = proc_iomem(); 44 | FILE *fp; 45 | char line[80]; 46 | int current_range = 0; 47 | 48 | fp = fopen(iomem,"r"); 49 | if(fp == 0) { 50 | fprintf(stderr,"Unable to open %s: %s\n",iomem,strerror(errno)); 51 | return -1; 52 | } 53 | 54 | /* Setup the compare string properly. */ 55 | while(fgets(line,sizeof(line),fp) != 0) { 56 | unsigned long long start, end; 57 | int cons; 58 | char *str; 59 | 60 | if (current_range == MAX_MEMORY_RANGES) 61 | break; 62 | 63 | sscanf(line,"%Lx-%Lx : %n", &start, &end, &cons); 64 | str = line+cons; 65 | if(memcmp(str,sys_ram,strlen(sys_ram)) == 0) { 66 | memory_range[current_range].start = start; 67 | memory_range[current_range].end = end; 68 | memory_range[current_range].type = RANGE_RAM; 69 | current_range++; 70 | } 71 | else { 72 | continue; 73 | } 74 | } 75 | fclose(fp); 76 | *range = memory_range; 77 | *ranges = current_range; 78 | 79 | return 0; 80 | } 81 | 82 | /* Supported file types and callbacks */ 83 | struct file_type file_type[] = { 84 | { "image", image_s390_probe, image_s390_load, image_s390_usage}, 85 | }; 86 | int file_types = sizeof(file_type) / sizeof(file_type[0]); 87 | 88 | 89 | void arch_usage(void) 90 | { 91 | } 92 | 93 | int arch_process_options(int UNUSED(argc), char **UNUSED(argv)) 94 | { 95 | return 0; 96 | } 97 | 98 | const struct arch_map_entry arches[] = { 99 | { "s390", KEXEC_ARCH_S390 }, 100 | { "s390x", KEXEC_ARCH_S390 }, 101 | { NULL, 0 }, 102 | }; 103 | 104 | int arch_compat_trampoline(struct kexec_info *UNUSED(info)) 105 | { 106 | return 0; 107 | } 108 | 109 | void arch_update_purgatory(struct kexec_info *UNUSED(info)) 110 | { 111 | } 112 | 113 | int is_crashkernel_mem_reserved(void) 114 | { 115 | return 0; /* kdump is not supported on this platform (yet) */ 116 | } 117 | -------------------------------------------------------------------------------- /kexec/arch/s390/kexec-s390.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec/arch/s390/kexec-s390.h 3 | * 4 | * (C) Copyright IBM Corp. 2005 5 | * 6 | * Author(s): Rolf Adelsberger 7 | * 8 | */ 9 | 10 | #ifndef KEXEC_S390_H 11 | #define KEXEC_S390_H 12 | 13 | #define IMAGE_READ_OFFSET 0x10000 14 | 15 | #define RAMDISK_ORIGIN_ADDR 0x800000 16 | #define INITRD_START_OFFS 0x408 17 | #define INITRD_SIZE_OFFS 0x410 18 | #define COMMAND_LINE_OFFS 0x480 19 | #define COMMAND_LINESIZE 896 20 | 21 | extern int image_s390_load(int, char **, const char *, off_t, struct kexec_info *); 22 | extern int image_s390_probe(const char *, off_t); 23 | extern void image_s390_usage(void); 24 | 25 | #endif /* KEXEC_IA64_H */ 26 | -------------------------------------------------------------------------------- /kexec/arch/sh/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec sh (linux booting linux) 3 | # 4 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-sh.c 5 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-uImage-sh.c 6 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-zImage-sh.c 7 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-netbsd-sh.c 8 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-sh.c 9 | sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-rel-sh.c 10 | sh_KEXEC_SRCS += kexec/arch/sh/netbsd_booter.S 11 | sh_KEXEC_SRCS += kexec/arch/sh/crashdump-sh.c 12 | sh_KEXEC_SRCS += kexec/kexec-uImage.c 13 | 14 | sh_ADD_BUFFER = 15 | sh_ADD_SEGMENT = 16 | sh_VIRT_TO_PHYS = 17 | 18 | dist += kexec/arch/sh/Makefile $(sh_KEXEC_SRCS) \ 19 | kexec/arch/sh/kexec-sh.h \ 20 | kexec/arch/sh/crashdump-sh.h \ 21 | kexec/arch/sh/include/arch/options.h 22 | -------------------------------------------------------------------------------- /kexec/arch/sh/crashdump-sh.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_SH_H 2 | #define CRASHDUMP_SH_H 3 | 4 | struct kexec_info; 5 | int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline); 6 | 7 | #define PAGE_OFFSET 0x80000000 8 | 9 | #endif /* CRASHDUMP_SH_H */ 10 | -------------------------------------------------------------------------------- /kexec/arch/sh/include/arch/options.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ARCH_SH_OPTIONS_H 2 | #define KEXEC_ARCH_SH_OPTIONS_H 3 | 4 | #define OPT_ARCH_MAX (OPT_MAX+0) 5 | #define OPT_APPEND (OPT_ARCH_MAX+1) 6 | #define OPT_EMPTYZERO (OPT_ARCH_MAX+2) 7 | #define OPT_NBSD_HOWTO (OPT_ARCH_MAX+3) 8 | #define OPT_NBSD_MROOT (OPT_ARCH_MAX+4) 9 | 10 | /* Options relevant to the architecture (excluding loader-specific ones): */ 11 | #define KEXEC_ARCH_OPTIONS \ 12 | KEXEC_OPTIONS \ 13 | {"command-line", 1, 0, OPT_APPEND}, \ 14 | {"append", 1, 0, OPT_APPEND}, \ 15 | {"empty-zero", 1, 0, OPT_APPEND}, \ 16 | {"howto", 1, 0, OPT_NBSD_HOWTO}, \ 17 | {"miniroot", 1, 0, OPT_NBSD_MROOT}, 18 | /* These options seem to be loader-specific rather than cris-specific, so 19 | * ought to be moved to KEXEC_ALL_OPTIONS below and parsed in the relevant 20 | * loader, e.g. kexec-netbsd-sh.c 21 | */ 22 | 23 | #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" 24 | 25 | /* The following two #defines list ALL of the options added by all of the 26 | * architecture's loaders. 27 | * o main() uses this complete list to scan for its options, ignoring 28 | * arch-specific/loader-specific ones. 29 | * o Then, arch_process_options() uses this complete list to scan for its 30 | * options, ignoring general/loader-specific ones. 31 | * o Then, the file_type[n].load re-scans for options, using 32 | * KEXEC_ARCH_OPTIONS plus its loader-specific options subset. 33 | * Any unrecognised options cause an error here. 34 | * 35 | * This is done so that main()'s/arch_process_options()'s getopt_long() calls 36 | * don't choose a kernel filename from random arguments to options they don't 37 | * recognise -- as they now recognise (if not act upon) all possible options. 38 | */ 39 | #define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS 40 | #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR 41 | 42 | #endif /* KEXEC_ARCH_SH_OPTIONS_H */ 43 | -------------------------------------------------------------------------------- /kexec/arch/sh/kexec-elf-rel-sh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec-elf-rel-sh.c - ELF relocations for SuperH 3 | * Copyright (C) 2008 Paul Mundt 4 | * 5 | * Based on the SHcompact module loader (arch/sh/kernel/module.c) in the 6 | * Linux kernel, which is written by: 7 | * 8 | * Copyright (C) 2003 - 2008 Kaz Kojima & Paul Mundt 9 | * 10 | * This source code is licensed under the GNU General Public License, 11 | * Version 2. See the file COPYING for more details. 12 | */ 13 | #include 14 | #include 15 | #include "../../kexec.h" 16 | #include "../../kexec-elf.h" 17 | 18 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 19 | { 20 | /* Intentionally don't bother with endianness validation, it's 21 | * configurable */ 22 | 23 | if (ehdr->ei_class != ELFCLASS32) 24 | return 0; 25 | if (ehdr->e_machine != EM_SH) 26 | return 0; 27 | 28 | return 1; 29 | } 30 | 31 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 32 | void *orig_loc, unsigned long UNUSED(address), unsigned long relocation) 33 | { 34 | uint32_t *location = orig_loc; 35 | uint32_t value; 36 | 37 | switch (r_type) { 38 | case R_SH_DIR32: 39 | value = get_unaligned(location); 40 | value += relocation; 41 | put_unaligned(value, location); 42 | break; 43 | case R_SH_REL32: 44 | relocation = (relocation - (uint32_t)location); 45 | value = get_unaligned(location); 46 | value += relocation; 47 | put_unaligned(value, location); 48 | break; 49 | default: 50 | die("Unknown rela relocation: %lu\n", r_type); 51 | break; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /kexec/arch/sh/kexec-sh.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_SH_H 2 | #define KEXEC_SH_H 3 | 4 | #define COMMAND_LINE_SIZE 2048 5 | 6 | int uImage_sh_probe(const char *buf, off_t len); 7 | int uImage_sh_load(int argc, char **argv, const char *buf, off_t len, 8 | struct kexec_info *info); 9 | 10 | int zImage_sh_probe(const char *buf, off_t len); 11 | int zImage_sh_load(int argc, char **argv, const char *buf, off_t len, 12 | struct kexec_info *info); 13 | void zImage_sh_usage(void); 14 | 15 | int elf_sh_probe(const char *buf, off_t len); 16 | int elf_sh_load(int argc, char **argv, const char *buf, off_t len, 17 | struct kexec_info *info); 18 | void elf_sh_usage(void); 19 | 20 | int netbsd_sh_probe(const char *buf, off_t len); 21 | int netbsd_sh_load(int argc, char **argv, const char *buf, off_t len, 22 | struct kexec_info *info); 23 | void netbsd_sh_usage(void); 24 | 25 | char *get_append(void); 26 | void kexec_sh_setup_zero_page(char *zero_page_buf, size_t zero_page_size, 27 | char *cmd_line); 28 | 29 | #endif /* KEXEC_SH_H */ 30 | -------------------------------------------------------------------------------- /kexec/arch/sh/kexec-uImage-sh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * uImage support added by Marc Andre Tanner 3 | * 4 | * Cloned from ARM by Paul Mundt, 2009. 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "../../kexec.h" 12 | #include "kexec-sh.h" 13 | 14 | int uImage_sh_probe(const char *buf, off_t len) 15 | { 16 | return uImage_probe(buf, len, IH_ARCH_SH); 17 | } 18 | 19 | int uImage_sh_load(int argc, char **argv, const char *buf, off_t len, 20 | struct kexec_info *info) 21 | { 22 | return zImage_sh_load(argc, argv, buf + sizeof(struct image_header), 23 | len - sizeof(struct image_header), info); 24 | } 25 | -------------------------------------------------------------------------------- /kexec/arch/sh/netbsd_booter.S: -------------------------------------------------------------------------------- 1 | .globl netbsd_booter 2 | netbsd_booter: 3 | mov.l ccr,r0 4 | mov #0,r1 5 | mov.l r1,@r0 6 | nop 7 | nop 8 | nop 9 | nop 10 | nop 11 | nop 12 | nop 13 | nop 14 | nop 15 | nop 16 | mova netbsd_start,r0 17 | mov.l @r0,r1 18 | add #4,r0 19 | mov.l @r0,r4 ! howto 20 | add #4,r0 21 | mov r0,r5 ! bootinfo 22 | jmp @r1 23 | nop 24 | nop 25 | nop 26 | .align 4 27 | ccr: .long 0xff00001c 28 | 29 | .align 8 30 | netbsd_start: 31 | .long 0x8c001000 32 | .long 0x200 ! howto 33 | .long 0 ! bootinfo 34 | .long 0 ! bootinfo 35 | .long 0 ! bootinfo 36 | .long 0 ! bootinfo 37 | .long 0 ! bootinfo 38 | .long 0 ! bootinfo 39 | .long 0 ! bootinfo 40 | .long 0 ! bootinfo 41 | .long 0 ! bootinfo 42 | .long 0 ! bootinfo 43 | .long 0 ! bootinfo 44 | .long 0 ! bootinfo 45 | .long 0 ! bootinfo 46 | .long 0 ! bootinfo 47 | 48 | -------------------------------------------------------------------------------- /kexec/arch/x86_64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec x86_64 (linux booting linux) 3 | # 4 | x86_64_KEXEC_SRCS = kexec/arch/i386/kexec-elf-x86.c 5 | x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-bzImage.c 6 | x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c 7 | x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c 8 | x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c 9 | x86_64_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c 10 | x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-x86-common.c 11 | x86_64_KEXEC_SRCS += kexec/arch/x86_64/crashdump-x86_64.c 12 | x86_64_KEXEC_SRCS += kexec/arch/x86_64/kexec-x86_64.c 13 | x86_64_KEXEC_SRCS += kexec/arch/x86_64/kexec-elf-x86_64.c 14 | x86_64_KEXEC_SRCS += kexec/arch/x86_64/kexec-elf-rel-x86_64.c 15 | 16 | x86_64_ARCH_INIT = kexec/arch/x86_64/arch_init.c 17 | 18 | dist += kexec/arch/x86_64/Makefile $(x86_64_KEXEC_SRCS) $(x86_64_ARCH_INIT) \ 19 | kexec/arch/x86_64/kexec-x86_64.h kexec/arch/x86_64/crashdump-x86_64.h \ 20 | kexec/arch/x86_64/include/arch/options.h 21 | -------------------------------------------------------------------------------- /kexec/arch/x86_64/arch_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "crashdump-x86_64.h" 9 | 10 | #define KERNEL_VERSION(major, minor, patch) \ 11 | (((major) << 16) | ((minor) << 8) | patch) 12 | 13 | long kernel_version(void) 14 | { 15 | struct utsname utsname; 16 | unsigned long major, minor, patch; 17 | char *p; 18 | 19 | if (uname(&utsname) < 0) { 20 | fprintf(stderr, "uname failed: %s\n", strerror(errno)); 21 | return -1; 22 | } 23 | 24 | p = utsname.release; 25 | major = strtoul(p, &p, 10); 26 | if (major == ULONG_MAX) { 27 | fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); 28 | return -1; 29 | } 30 | 31 | if (*p++ != '.') { 32 | fprintf(stderr, "Unsupported utsname.release: %s\n", 33 | utsname.release); 34 | return -1; 35 | } 36 | 37 | minor = strtoul(p, &p, 10); 38 | if (major == ULONG_MAX) { 39 | fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); 40 | return -1; 41 | } 42 | 43 | if (*p++ != '.') { 44 | fprintf(stderr, "Unsupported utsname.release: %s\n", 45 | utsname.release); 46 | return -1; 47 | } 48 | 49 | patch = strtoul(p, &p, 10); 50 | if (major == ULONG_MAX) { 51 | fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); 52 | return -1; 53 | } 54 | 55 | if (major >= 256 || minor >= 256 || patch >= 256) { 56 | fprintf(stderr, "Unsupported utsname.release: %s\n", 57 | utsname.release); 58 | return -1; 59 | } 60 | 61 | return KERNEL_VERSION(major, minor, patch); 62 | } 63 | 64 | #define PAGE_OFFSET_PRE_2_6_27 0xffff810000000000UL 65 | #define PAGE_OFFSET 0xffff880000000000UL 66 | 67 | unsigned long page_offset; 68 | 69 | int arch_init(void) 70 | { 71 | int kv; 72 | 73 | kv = kernel_version(); 74 | if (kv < 0) 75 | return -1; 76 | 77 | if (kv < KERNEL_VERSION(2, 6, 27)) 78 | page_offset = PAGE_OFFSET_PRE_2_6_27; 79 | else 80 | page_offset = PAGE_OFFSET; 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /kexec/arch/x86_64/crashdump-x86_64.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_X86_64_H 2 | #define CRASHDUMP_X86_64_H 3 | 4 | #include "../../kexec.h" 5 | 6 | int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline, 7 | unsigned long max_addr, unsigned long min_base); 8 | 9 | #define __START_KERNEL_map 0xffffffff80000000UL 10 | 11 | extern unsigned long page_offset; 12 | 13 | #define __pa(x) (((unsigned long)(x)>=__START_KERNEL_map)?(unsigned long)(x) - (unsigned long)__START_KERNEL_map:(unsigned long)(x) - page_offset) 14 | 15 | #define MAXMEM 0x3fffffffffffUL 16 | 17 | /* Kernel text size */ 18 | #define KERNEL_TEXT_SIZE (512UL*1024*1024) 19 | 20 | #define CRASH_MAX_MEMMAP_NR (KEXEC_MAX_SEGMENTS + 1) 21 | #define CRASH_MAX_MEMORY_RANGES (MAX_MEMORY_RANGES + 2) 22 | 23 | /* Backup Region, First 640K of System RAM. */ 24 | #define BACKUP_SRC_START 0x00000000 25 | #define BACKUP_SRC_END 0x0009ffff 26 | #define BACKUP_SRC_SIZE (BACKUP_SRC_END - BACKUP_SRC_START + 1) 27 | 28 | #endif /* CRASHDUMP_X86_64_H */ 29 | -------------------------------------------------------------------------------- /kexec/arch/x86_64/include/arch/options.h: -------------------------------------------------------------------------------- 1 | ../../../i386/include/arch/options.h -------------------------------------------------------------------------------- /kexec/arch/x86_64/kexec-elf-rel-x86_64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../kexec.h" 4 | #include "../../kexec-elf.h" 5 | 6 | int machine_verify_elf_rel(struct mem_ehdr *ehdr) 7 | { 8 | if (ehdr->ei_data != ELFDATA2LSB) { 9 | return 0; 10 | } 11 | if (ehdr->ei_class != ELFCLASS64) { 12 | return 0; 13 | } 14 | if (ehdr->e_machine != EM_X86_64) { 15 | return 0; 16 | } 17 | return 1; 18 | } 19 | 20 | static const char *reloc_name(unsigned long r_type) 21 | { 22 | static const char *r_name[] = { 23 | "R_X86_64_NONE", 24 | "R_X86_64_64", 25 | "R_X86_64_PC32", 26 | "R_X86_64_GOT32", 27 | "R_X86_64_PLT32", 28 | "R_X86_64_COPY", 29 | "R_X86_64_GLOB_DAT", 30 | "R_X86_64_JUMP_SLOT", 31 | "R_X86_64_RELATIVE", 32 | "R_X86_64_GOTPCREL", 33 | "R_X86_64_32", 34 | "R_X86_64_32S", 35 | "R_X86_64_16", 36 | "R_X86_64_PC16", 37 | "R_X86_64_8", 38 | "R_X86_64_PC8", 39 | "R_X86_64_DTPMOD64", 40 | "R_X86_64_DTPOFF64", 41 | "R_X86_64_TPOFF64", 42 | "R_X86_64_TLSGD", 43 | "R_X86_64_TLSLD", 44 | "R_X86_64_DTPOFF32", 45 | "R_X86_64_GOTTPOFF", 46 | "R_X86_64_TPOFF32", 47 | }; 48 | static char buf[100]; 49 | const char *name; 50 | if (r_type < (sizeof(r_name)/sizeof(r_name[0]))){ 51 | name = r_name[r_type]; 52 | } 53 | else { 54 | sprintf(buf, "R_X86_64_%lu", r_type); 55 | name = buf; 56 | } 57 | return name; 58 | } 59 | 60 | void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, 61 | void *location, unsigned long address, unsigned long value) 62 | { 63 | #ifdef DEBUG 64 | fprintf(stderr, "%s\n", reloc_name(r_type)); 65 | #endif 66 | switch(r_type) { 67 | case R_X86_64_NONE: 68 | break; 69 | case R_X86_64_64: 70 | *(uint64_t *)location = value; 71 | break; 72 | case R_X86_64_32: 73 | *(uint32_t *)location = value; 74 | if (value != *(uint32_t *)location) 75 | goto overflow; 76 | break; 77 | case R_X86_64_32S: 78 | *(uint32_t *)location = value; 79 | if ((int64_t)value != *(int32_t *)location) 80 | goto overflow; 81 | break; 82 | case R_X86_64_PC32: 83 | *(uint32_t *)location = value - address; 84 | break; 85 | default: 86 | die("Unhandled rela relocation: %s\n", reloc_name(r_type)); 87 | break; 88 | } 89 | return; 90 | overflow: 91 | die("overflow in relocation type %s val %Lx\n", 92 | reloc_name(r_type), value); 93 | } 94 | -------------------------------------------------------------------------------- /kexec/arch/x86_64/kexec-x86_64.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_X86_64_H 2 | #define KEXEC_X86_64_H 3 | 4 | #include "../i386/kexec-x86.h" 5 | 6 | struct entry64_regs { 7 | uint64_t rax; 8 | uint64_t rbx; 9 | uint64_t rcx; 10 | uint64_t rdx; 11 | uint64_t rsi; 12 | uint64_t rdi; 13 | uint64_t rsp; 14 | uint64_t rbp; 15 | uint64_t r8; 16 | uint64_t r9; 17 | uint64_t r10; 18 | uint64_t r11; 19 | uint64_t r12; 20 | uint64_t r13; 21 | uint64_t r14; 22 | uint64_t r15; 23 | uint64_t rip; 24 | }; 25 | 26 | int elf_x86_64_probe(const char *buf, off_t len); 27 | int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len, 28 | struct kexec_info *info); 29 | void elf_x86_64_usage(void); 30 | 31 | #endif /* KEXEC_X86_64_H */ 32 | -------------------------------------------------------------------------------- /kexec/arch_init.c: -------------------------------------------------------------------------------- 1 | int arch_init(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /kexec/arch_reuse_initrd.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | 3 | void arch_reuse_initrd(void) 4 | { 5 | die("--reuseinitrd not implemented on this architecture\n"); 6 | } 7 | -------------------------------------------------------------------------------- /kexec/crashdump-xen.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "kexec.h" 14 | #include "crashdump.h" 15 | #include "kexec-syscall.h" 16 | 17 | #include "config.h" 18 | 19 | #ifdef HAVE_LIBXENCTRL 20 | #include 21 | #endif 22 | 23 | struct crash_note_info { 24 | unsigned long base; 25 | unsigned long length; 26 | }; 27 | 28 | int xen_phys_cpus = 0; 29 | struct crash_note_info *xen_phys_notes; 30 | 31 | int xen_present(void) 32 | { 33 | struct stat buf; 34 | 35 | return stat("/proc/xen", &buf) == 0; 36 | } 37 | 38 | unsigned long xen_architecture(struct crash_elf_info *elf_info) 39 | { 40 | unsigned long machine = elf_info->machine; 41 | #ifdef HAVE_LIBXENCTRL 42 | int xc, rc; 43 | xen_capabilities_info_t capabilities; 44 | 45 | if (!xen_present()) 46 | goto out; 47 | 48 | memset(capabilities, '0', XEN_CAPABILITIES_INFO_LEN); 49 | 50 | xc = xc_interface_open(); 51 | if ( xc == -1 ) { 52 | fprintf(stderr, "failed to open xen control interface.\n"); 53 | goto out; 54 | } 55 | 56 | rc = xc_version(xc, XENVER_capabilities, &capabilities[0]); 57 | if ( rc == -1 ) { 58 | fprintf(stderr, "failed to make Xen version hypercall.\n"); 59 | goto out_close; 60 | } 61 | 62 | if (strstr(capabilities, "xen-3.0-x86_64")) 63 | machine = EM_X86_64; 64 | else if (strstr(capabilities, "xen-3.0-x86_32")) 65 | machine = EM_386; 66 | 67 | out_close: 68 | xc_interface_close(xc); 69 | 70 | out: 71 | #endif 72 | return machine; 73 | } 74 | 75 | static int xen_crash_note_callback(void *UNUSED(data), int nr, 76 | char *UNUSED(str), 77 | unsigned long base, 78 | unsigned long length) 79 | { 80 | struct crash_note_info *note = xen_phys_notes + nr; 81 | 82 | note->base = base; 83 | note->length = length; 84 | 85 | return 0; 86 | } 87 | 88 | int xen_get_nr_phys_cpus(void) 89 | { 90 | char *match = "Crash note\n"; 91 | int cpus, n; 92 | 93 | if (xen_phys_cpus) 94 | return xen_phys_cpus; 95 | 96 | if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) { 97 | n = sizeof(struct crash_note_info) * cpus; 98 | xen_phys_notes = malloc(n); 99 | if (!xen_phys_notes) { 100 | fprintf(stderr, "failed to allocate xen_phys_notes.\n"); 101 | return -1; 102 | } 103 | memset(xen_phys_notes, 0, n); 104 | kexec_iomem_for_each_line(match, 105 | xen_crash_note_callback, NULL); 106 | xen_phys_cpus = cpus; 107 | } 108 | 109 | return cpus; 110 | } 111 | 112 | int xen_get_note(int cpu, uint64_t *addr, uint64_t *len) 113 | { 114 | struct crash_note_info *note; 115 | 116 | if (xen_phys_cpus <= 0) 117 | return -1; 118 | 119 | note = xen_phys_notes + cpu; 120 | 121 | *addr = note->base; 122 | *len = note->length; 123 | 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /kexec/crashdump.h: -------------------------------------------------------------------------------- 1 | #ifndef CRASHDUMP_H 2 | #define CRASHDUMP_H 3 | 4 | extern int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len); 5 | extern int get_kernel_vmcoreinfo(uint64_t *addr, uint64_t *len); 6 | extern int get_xen_vmcoreinfo(uint64_t *addr, uint64_t *len); 7 | 8 | /* Need to find a better way to determine per cpu notes section size. */ 9 | #define MAX_NOTE_BYTES 1024 10 | /* Expecting ELF headers to fit in 4K. Increase it if you need more. */ 11 | #define KCORE_ELF_HEADERS_SIZE 4096 12 | /* The address of the ELF header is passed to the secondary kernel 13 | * using the kernel command line option memmap=nnn. 14 | * The smallest unit the kernel accepts is in kilobytes, 15 | * so we need to make sure the ELF header is aligned to 1024. 16 | */ 17 | #define ELF_CORE_HEADER_ALIGN 1024 18 | 19 | /* structure passed to crash_create_elf32/64_headers() */ 20 | 21 | struct crash_elf_info { 22 | unsigned long class; 23 | unsigned long data; 24 | unsigned long machine; 25 | 26 | unsigned long backup_src_start; 27 | unsigned long backup_src_end; 28 | 29 | unsigned long long page_offset; 30 | unsigned long lowmem_limit; 31 | 32 | int (*get_note_info)(int cpu, uint64_t *addr, uint64_t *len); 33 | }; 34 | 35 | int crash_create_elf32_headers(struct kexec_info *info, 36 | struct crash_elf_info *elf_info, 37 | struct memory_range *range, int ranges, 38 | void **buf, unsigned long *size, 39 | unsigned long align); 40 | 41 | int crash_create_elf64_headers(struct kexec_info *info, 42 | struct crash_elf_info *elf_info, 43 | struct memory_range *range, int ranges, 44 | void **buf, unsigned long *size, 45 | unsigned long align); 46 | 47 | unsigned long crash_architecture(struct crash_elf_info *elf_info); 48 | 49 | unsigned long phys_to_virt(struct crash_elf_info *elf_info, 50 | unsigned long paddr); 51 | 52 | int xen_present(void); 53 | unsigned long xen_architecture(struct crash_elf_info *elf_info); 54 | int xen_get_nr_phys_cpus(void); 55 | int xen_get_note(int cpu, uint64_t *addr, uint64_t *len); 56 | 57 | #endif /* CRASHDUMP_H */ 58 | -------------------------------------------------------------------------------- /kexec/firmware_memmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * firmware_memmap.c: Read /sys/firmware/memmap 3 | * 4 | * Created by: Bernhard Walle (bernhard.walle@gmx.de) 5 | * Copyright (C) SUSE LINUX Products GmbH, 2008. All rights reserved 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation (version 2 of the License). 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | #ifndef FIRMWARE_MEMMAP_H 21 | #define FIRMWARE_MEMMAP_H 22 | 23 | #include "kexec.h" 24 | 25 | /** 26 | * Reads the /sys/firmware/memmap interface, documented in 27 | * Documentation/ABI/testing/sysfs-firmware-memmap (kernel tree). 28 | * 29 | * The difference between /proc/iomem and /sys/firmware/memmap is that 30 | * /sys/firmware/memmap provides the raw memory map, provided by the 31 | * firmware of the system. That memory map should be passed to a kexec'd 32 | * kernel because the behaviour should be the same as a normal booted kernel, 33 | * so any limitation (e.g. by the user providing the mem command line option) 34 | * should not be passed to the kexec'd kernel. 35 | * 36 | * The parsing of the code is independent of the architecture. However, the 37 | * actual architecture-specific code might postprocess the code a bit, like 38 | * x86 does. 39 | */ 40 | 41 | /** 42 | * Checks if the kernel provides the /sys/firmware/memmap interface. 43 | * It makes sense to use that function in advance before calling 44 | * get_firmware_memmap_ranges() because the latter function prints an error 45 | * if it cannot open the directory. If have_sys_firmware_memmap() returns 46 | * false, then one can use the old /proc/iomem interface (for older kernels). 47 | */ 48 | int have_sys_firmware_memmap(void); 49 | 50 | /** 51 | * Parses the /sys/firmware/memmap memory map. 52 | * 53 | * @param[out] range a pointer to an array of type struct memory_range with 54 | * at least *range entries 55 | * @param[in,out] ranges a pointer to an integer that holds the number of 56 | * entries which range contains (at least). After successful 57 | * return, the number of actual entries will be written. 58 | * @return 0 on success, -1 on failure. 59 | */ 60 | int get_firmware_memmap_ranges(struct memory_range *range, size_t *ranges); 61 | 62 | 63 | #endif /* FIRMWARE_MEMMAP_H */ 64 | -------------------------------------------------------------------------------- /kexec/ifdown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ifdown.c Find all network interfaces on the system and 3 | * shut them down. 4 | * 5 | */ 6 | char *v_ifdown = "@(#)ifdown.c 1.11 02-Jun-1998 miquels@cistron.nl"; 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #define MAX_IFS 64 23 | 24 | /* 25 | * First, we find all shaper devices and down them. Then we 26 | * down all real interfaces. This is because the comment in the 27 | * shaper driver says "if you down the shaper device before the 28 | * attached inerface your computer will follow". 29 | */ 30 | int ifdown(void) 31 | { 32 | struct ifreq ifr[MAX_IFS]; 33 | struct ifconf ifc; 34 | int i, fd; 35 | int numif; 36 | int shaper; 37 | 38 | if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 39 | fprintf(stderr, "ifdown: "); 40 | perror("socket"); 41 | return -1; 42 | } 43 | ifc.ifc_len = sizeof(ifr); 44 | ifc.ifc_req = ifr; 45 | 46 | if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) { 47 | fprintf(stderr, "ifdown: "); 48 | perror("SIOCGIFCONF"); 49 | close(fd); 50 | return -1; 51 | } 52 | numif = ifc.ifc_len / sizeof(struct ifreq); 53 | 54 | for (shaper = 1; shaper >= 0; shaper--) { 55 | for (i = 0; i < numif; i++) { 56 | 57 | if ((strncmp(ifr[i].ifr_name, "shaper", 6) == 0) 58 | != shaper) continue; 59 | 60 | if (strcmp(ifr[i].ifr_name, "lo") == 0) 61 | continue; 62 | if (strchr(ifr[i].ifr_name, ':') != NULL) 63 | continue; 64 | ifr[i].ifr_flags &= ~(IFF_UP); 65 | if (ioctl(fd, SIOCSIFFLAGS, &ifr[i]) < 0) { 66 | fprintf(stderr, "ifdown: shutdown "); 67 | perror(ifr[i].ifr_name); 68 | } 69 | } 70 | } 71 | close(fd); 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /kexec/kexec-elf-boot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003-2005 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #define _GNU_SOURCE 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "kexec.h" 30 | #include "kexec-elf.h" 31 | #include "kexec-elf-boot.h" 32 | 33 | 34 | #define UPSZ(X) ((sizeof(X) + 3) &~3) 35 | 36 | static struct boot_notes { 37 | Elf_Bhdr hdr; 38 | Elf_Nhdr bl_hdr; 39 | unsigned char bl_desc[UPSZ(BOOTLOADER)]; 40 | Elf_Nhdr blv_hdr; 41 | unsigned char blv_desc[UPSZ(BOOTLOADER_VERSION)]; 42 | Elf_Nhdr cmd_hdr; 43 | unsigned char command_line[0]; 44 | } boot_notes = { 45 | .hdr = { 46 | .b_signature = ELF_BOOT_MAGIC, 47 | .b_size = sizeof(boot_notes), 48 | .b_checksum = 0, 49 | .b_records = 3, 50 | }, 51 | .bl_hdr = { 52 | .n_namesz = 0, 53 | .n_descsz = sizeof(BOOTLOADER), 54 | .n_type = EBN_BOOTLOADER_NAME, 55 | }, 56 | .bl_desc = BOOTLOADER, 57 | .blv_hdr = { 58 | .n_namesz = 0, 59 | .n_descsz = sizeof(BOOTLOADER_VERSION), 60 | .n_type = EBN_BOOTLOADER_VERSION, 61 | }, 62 | .blv_desc = BOOTLOADER_VERSION, 63 | .cmd_hdr = { 64 | .n_namesz = 0, 65 | .n_descsz = 0, 66 | .n_type = EBN_COMMAND_LINE, 67 | }, 68 | }; 69 | 70 | static inline unsigned long align(unsigned long val, unsigned long align) 71 | { 72 | return (val + align - 1) & ~(align - 1); 73 | 74 | } 75 | 76 | unsigned long elf_boot_notes( 77 | struct kexec_info *info, unsigned long max_addr, 78 | const char *cmdline, int cmdline_len) 79 | { 80 | unsigned long note_bytes; 81 | unsigned long note_base; 82 | struct boot_notes *notes; 83 | note_bytes = sizeof(*notes) + align(cmdline_len, 4); 84 | notes = xmalloc(note_bytes); 85 | memcpy(notes, &boot_notes, sizeof(boot_notes)); 86 | memcpy(notes->command_line, cmdline, cmdline_len); 87 | notes->hdr.b_size = note_bytes; 88 | notes->cmd_hdr.n_descsz = cmdline_len; 89 | notes->hdr.b_checksum = compute_ip_checksum(notes, note_bytes); 90 | 91 | note_base = add_buffer(info, notes, note_bytes, note_bytes, 92 | 4, 0, max_addr, 1); 93 | 94 | return note_base; 95 | } 96 | -------------------------------------------------------------------------------- /kexec/kexec-elf-boot.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_ELF_BOOT_H 2 | #define KEXEC_ELF_BOOT_H 3 | 4 | unsigned long elf_boot_notes( 5 | struct kexec_info *info, unsigned long max_addr, 6 | const char *cmdline, int cmdline_len); 7 | 8 | #endif /* KEXEC_ELF_BOOT_H */ 9 | -------------------------------------------------------------------------------- /kexec/kexec-elf-core.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "elf.h" 6 | #include "kexec-elf.h" 7 | 8 | 9 | int build_elf_core_info(const char *buf, off_t len, struct mem_ehdr *ehdr, 10 | uint32_t flags) 11 | { 12 | int result; 13 | result = build_elf_info(buf, len, ehdr, flags); 14 | if (result < 0) { 15 | return result; 16 | } 17 | if ((ehdr->e_type != ET_CORE)) { 18 | /* not an ELF Core */ 19 | fprintf(stderr, "Not ELF type ET_CORE\n"); 20 | return -1; 21 | } 22 | if (!ehdr->e_phdr) { 23 | /* No program header */ 24 | fprintf(stderr, "No ELF program header\n"); 25 | return -1; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /kexec/kexec-iomem.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "kexec.h" 13 | #include "crashdump.h" 14 | 15 | /* 16 | * kexec_iomem_for_each_line() 17 | * 18 | * Iterate over each line in the file returned by proc_iomem(). If match is 19 | * NULL or if the line matches with our match-pattern then call the 20 | * callback if non-NULL. 21 | * 22 | * Return the number of lines matched. 23 | */ 24 | 25 | int kexec_iomem_for_each_line(char *match, 26 | int (*callback)(void *data, 27 | int nr, 28 | char *str, 29 | unsigned long base, 30 | unsigned long length), 31 | void *data) 32 | { 33 | const char *iomem = proc_iomem(); 34 | char line[MAX_LINE]; 35 | FILE *fp; 36 | unsigned long long start, end, size; 37 | char *str; 38 | int consumed; 39 | int count; 40 | int nr = 0; 41 | 42 | fp = fopen(iomem, "r"); 43 | if (!fp) 44 | die("Cannot open %s\n", iomem); 45 | 46 | while(fgets(line, sizeof(line), fp) != 0) { 47 | count = sscanf(line, "%llx-%llx : %n", &start, &end, &consumed); 48 | if (count != 2) 49 | continue; 50 | str = line + consumed; 51 | size = end - start + 1; 52 | if (!match || memcmp(str, match, strlen(match)) == 0) { 53 | if (callback 54 | && callback(data, nr, str, start, size) < 0) { 55 | break; 56 | } 57 | nr++; 58 | } 59 | } 60 | 61 | fclose(fp); 62 | 63 | return nr; 64 | } 65 | 66 | static int kexec_iomem_single_callback(void *data, int nr, 67 | char *UNUSED(str), 68 | unsigned long base, 69 | unsigned long length) 70 | { 71 | struct memory_range *range = data; 72 | 73 | if (nr == 0) { 74 | range->start = base; 75 | range->end = base + length - 1; 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | int parse_iomem_single(char *str, uint64_t *start, uint64_t *end) 82 | { 83 | struct memory_range range; 84 | int ret; 85 | 86 | memset(&range, 0, sizeof(range)); 87 | 88 | ret = kexec_iomem_for_each_line(str, 89 | kexec_iomem_single_callback, &range); 90 | 91 | if (ret == 1) { 92 | if (start) 93 | *start = range.start; 94 | if (end) 95 | *end = range.end; 96 | 97 | ret = 0; 98 | } 99 | else 100 | ret = -1; 101 | 102 | return ret; 103 | } 104 | -------------------------------------------------------------------------------- /kexec/kexec-lzma.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEXEC_LZMA_H 2 | #define __KEXEC_LZMA_H 3 | 4 | #include 5 | 6 | char *lzma_decompress_file(const char *filename, off_t *r_size); 7 | 8 | #endif /* __KEXEC_LZMA_H */ 9 | -------------------------------------------------------------------------------- /kexec/kexec-sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_SHA256_H 2 | #define KEXEC_SHA256_H 3 | 4 | struct sha256_region { 5 | uint64_t start; 6 | uint64_t len; 7 | }; 8 | 9 | #define SHA256_REGIONS 16 10 | 11 | #endif /* KEXEC_SHA256_H */ 12 | -------------------------------------------------------------------------------- /kexec/kexec-syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef KEXEC_SYSCALL_H 2 | #define KEXEC_SYSCALL_H 3 | 4 | #define __LIBRARY__ 5 | #include 6 | #include 7 | 8 | #define LINUX_REBOOT_MAGIC1 0xfee1dead 9 | #define LINUX_REBOOT_MAGIC2 672274793 10 | #define LINUX_REBOOT_MAGIC2A 85072278 11 | #define LINUX_REBOOT_MAGIC2B 369367448 12 | 13 | #define LINUX_REBOOT_CMD_RESTART 0x01234567 14 | #define LINUX_REBOOT_CMD_HALT 0xCDEF0123 15 | #define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF 16 | #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000 17 | #define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC 18 | #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 19 | #define LINUX_REBOOT_CMD_EXEC_KERNEL 0x18273645 20 | #define LINUX_REBOOT_CMD_KEXEC_OLD 0x81726354 21 | #define LINUX_REBOOT_CMD_KEXEC_OLD2 0x18263645 22 | #define LINUX_REBOOT_CMD_KEXEC 0x45584543 23 | 24 | #ifndef __NR_kexec_load 25 | #ifdef __i386__ 26 | #define __NR_kexec_load 283 27 | #endif 28 | #ifdef __sh__ 29 | #define __NR_kexec_load 283 30 | #endif 31 | #ifdef __cris__ 32 | #ifndef __NR_kexec_load 33 | #define __NR_kexec_load 283 34 | #endif 35 | #endif 36 | #ifdef __ia64__ 37 | #define __NR_kexec_load 1268 38 | #endif 39 | #ifdef __powerpc64__ 40 | #define __NR_kexec_load 268 41 | #endif 42 | #ifdef __powerpc__ 43 | #define __NR_kexec_load 268 44 | #endif 45 | #ifdef __x86_64__ 46 | #define __NR_kexec_load 246 47 | #endif 48 | #ifdef __s390x__ 49 | #define __NR_kexec_load 277 50 | #endif 51 | #ifdef __s390__ 52 | #define __NR_kexec_load 277 53 | #endif 54 | #ifdef __arm__ 55 | #define __NR_kexec_load __NR_SYSCALL_BASE + 347 56 | #endif 57 | #if defined(__mips__) 58 | #define __NR_kexec_load 4311 59 | #endif 60 | #ifndef __NR_kexec_load 61 | #error Unknown processor architecture. Needs a kexec_load syscall number. 62 | #endif 63 | #endif /*ifndef __NR_kexec_load*/ 64 | 65 | struct kexec_segment; 66 | 67 | static inline long kexec_load(void *entry, unsigned long nr_segments, 68 | struct kexec_segment *segments, unsigned long flags) 69 | { 70 | return (long) syscall(__NR_kexec_load, entry, nr_segments, segments, flags); 71 | } 72 | 73 | static inline long kexec_reboot(void) 74 | { 75 | return (long) syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_KEXEC, 0); 76 | } 77 | 78 | 79 | #define KEXEC_ON_CRASH 0x00000001 80 | #define KEXEC_PRESERVE_CONTEXT 0x00000002 81 | #define KEXEC_HARDBOOT 0x00000004 82 | #define KEXEC_ARCH_MASK 0xffff0000 83 | 84 | /* These values match the ELF architecture values. 85 | * Unless there is a good reason that should continue to be the case. 86 | */ 87 | #define KEXEC_ARCH_DEFAULT ( 0 << 16) 88 | #define KEXEC_ARCH_386 ( 3 << 16) 89 | #define KEXEC_ARCH_X86_64 (62 << 16) 90 | #define KEXEC_ARCH_PPC (20 << 16) 91 | #define KEXEC_ARCH_PPC64 (21 << 16) 92 | #define KEXEC_ARCH_IA_64 (50 << 16) 93 | #define KEXEC_ARCH_ARM (40 << 16) 94 | #define KEXEC_ARCH_S390 (22 << 16) 95 | #define KEXEC_ARCH_SH (42 << 16) 96 | #define KEXEC_ARCH_MIPS_LE (10 << 16) 97 | #define KEXEC_ARCH_MIPS ( 8 << 16) 98 | #define KEXEC_ARCH_CRIS (76 << 16) 99 | 100 | #define KEXEC_MAX_SEGMENTS 16 101 | 102 | #endif /* KEXEC_SYSCALL_H */ 103 | -------------------------------------------------------------------------------- /kexec/kexec-zlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEXEC_ZLIB_H 2 | #define __KEXEC_ZLIB_H 3 | 4 | #include 5 | #include 6 | 7 | #include "config.h" 8 | 9 | char *zlib_decompress_file(const char *filename, off_t *r_size); 10 | #endif /* __KEXEC_ZLIB_H */ 11 | -------------------------------------------------------------------------------- /kexec/libfdt/Makefile.libfdt: -------------------------------------------------------------------------------- 1 | # Makefile.libfdt 2 | # 3 | # This is not a complete Makefile of itself. Instead, it is designed to 4 | # be easily embeddable into other systems of Makefiles. 5 | # 6 | LIBFDT_INCLUDES = fdt.h libfdt.h 7 | LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 8 | LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 9 | 10 | dist += kexec/libfdt/Makefile.libfdt \ 11 | kexec/libfdt/fdt.h kexec/libfdt/libfdt.h \ 12 | kexec/libfdt/libfdt_env.h \ 13 | kexec/libfdt/libfdt_internal.h 14 | -------------------------------------------------------------------------------- /kexec/libfdt/TODO: -------------------------------------------------------------------------------- 1 | - Tree traversal functions 2 | - Graft function 3 | - Complete libfdt.h documenting comments 4 | -------------------------------------------------------------------------------- /kexec/libfdt/fdt.h: -------------------------------------------------------------------------------- 1 | #ifndef _FDT_H 2 | #define _FDT_H 3 | 4 | #ifndef __ASSEMBLY__ 5 | 6 | struct fdt_header { 7 | uint32_t magic; /* magic word FDT_MAGIC */ 8 | uint32_t totalsize; /* total size of DT block */ 9 | uint32_t off_dt_struct; /* offset to structure */ 10 | uint32_t off_dt_strings; /* offset to strings */ 11 | uint32_t off_mem_rsvmap; /* offset to memory reserve map */ 12 | uint32_t version; /* format version */ 13 | uint32_t last_comp_version; /* last compatible version */ 14 | 15 | /* version 2 fields below */ 16 | uint32_t boot_cpuid_phys; /* Which physical CPU id we're 17 | booting on */ 18 | /* version 3 fields below */ 19 | uint32_t size_dt_strings; /* size of the strings block */ 20 | 21 | /* version 17 fields below */ 22 | uint32_t size_dt_struct; /* size of the structure block */ 23 | }; 24 | 25 | struct fdt_reserve_entry { 26 | uint64_t address; 27 | uint64_t size; 28 | }; 29 | 30 | struct fdt_node_header { 31 | uint32_t tag; 32 | char name[0]; 33 | }; 34 | 35 | struct fdt_property { 36 | uint32_t tag; 37 | uint32_t len; 38 | uint32_t nameoff; 39 | char data[0]; 40 | }; 41 | 42 | #endif /* !__ASSEMBLY */ 43 | 44 | #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ 45 | #define FDT_TAGSIZE sizeof(uint32_t) 46 | 47 | #define FDT_BEGIN_NODE 0x1 /* Start node: full name */ 48 | #define FDT_END_NODE 0x2 /* End node */ 49 | #define FDT_PROP 0x3 /* Property: name off, 50 | size, content */ 51 | #define FDT_NOP 0x4 /* nop */ 52 | #define FDT_END 0x9 53 | 54 | #define FDT_V1_SIZE (7*sizeof(uint32_t)) 55 | #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(uint32_t)) 56 | #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(uint32_t)) 57 | #define FDT_V16_SIZE FDT_V3_SIZE 58 | #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(uint32_t)) 59 | 60 | #endif /* _FDT_H */ 61 | -------------------------------------------------------------------------------- /kexec/libfdt/libfdt_env.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBFDT_ENV_H 2 | #define _LIBFDT_ENV_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define _B(n) ((unsigned long long)((uint8_t *)&x)[n]) 9 | static inline uint32_t fdt32_to_cpu(uint32_t x) 10 | { 11 | return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3); 12 | } 13 | #define cpu_to_fdt32(x) fdt32_to_cpu(x) 14 | 15 | static inline uint64_t fdt64_to_cpu(uint64_t x) 16 | { 17 | return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32) 18 | | (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7); 19 | } 20 | #define cpu_to_fdt64(x) fdt64_to_cpu(x) 21 | #undef _B 22 | 23 | #endif /* _LIBFDT_ENV_H */ 24 | -------------------------------------------------------------------------------- /kexec/phys_arch.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | #include 3 | #include 4 | #include 5 | 6 | long physical_arch(void) 7 | { 8 | struct utsname utsname; 9 | int i, result = uname(&utsname); 10 | if (result < 0) { 11 | fprintf(stderr, "uname failed: %s\n", 12 | strerror(errno)); 13 | return -1; 14 | } 15 | 16 | for (i = 0; arches[i].machine; ++i) { 17 | if (strcmp(utsname.machine, arches[i].machine) == 0) 18 | return arches[i].arch; 19 | if ((strcmp(arches[i].machine, "arm") == 0) && 20 | (strncmp(utsname.machine, arches[i].machine, 21 | strlen(arches[i].machine)) == 0)) 22 | return arches[i].arch; 23 | } 24 | 25 | fprintf(stderr, "Unsupported machine type: %s\n", 26 | utsname.machine); 27 | return -1; 28 | } 29 | -------------------------------------------------------------------------------- /kexec/phys_to_virt.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | #include "crashdump.h" 3 | 4 | /** 5 | * phys_to_virt() - translate physical address to virtual address 6 | * @paddr: physical address to translate 7 | * 8 | * For most architectures physical address is simply virtual address minus 9 | * PAGE_OFFSET. Architectures that don't follow this convention should provide 10 | * their own implementation. 11 | */ 12 | unsigned long 13 | phys_to_virt(struct crash_elf_info *elf_info, unsigned long paddr) 14 | { 15 | return paddr + elf_info->page_offset; 16 | } 17 | -------------------------------------------------------------------------------- /kexec/proc_iomem.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | 3 | static const char proc_iomem_str[] = "/proc/iomem"; 4 | 5 | /* 6 | * Allow an architecture specific implementation of this 7 | * function to override the location of a file looking a lot 8 | * like /proc/iomem 9 | */ 10 | const char *proc_iomem(void) 11 | { 12 | return proc_iomem_str; 13 | } 14 | -------------------------------------------------------------------------------- /kexec/virt_to_phys.c: -------------------------------------------------------------------------------- 1 | #include "kexec.h" 2 | #include 3 | 4 | unsigned long virt_to_phys(unsigned long UNUSED(addr)) 5 | { 6 | abort(); 7 | } 8 | -------------------------------------------------------------------------------- /kexec/zlib.c: -------------------------------------------------------------------------------- 1 | #include "kexec-zlib.h" 2 | #include "kexec.h" 3 | 4 | #ifdef HAVE_LIBZ 5 | #define _GNU_SOURCE 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | char *zlib_decompress_file(const char *filename, off_t *r_size) 19 | { 20 | gzFile fp; 21 | int errnum; 22 | const char *msg; 23 | char *buf; 24 | off_t size, allocated; 25 | ssize_t result; 26 | 27 | if (!filename) { 28 | *r_size = 0; 29 | return 0; 30 | } 31 | fp = gzopen(filename, "rb"); 32 | if (fp == 0) { 33 | msg = gzerror(fp, &errnum); 34 | if (errnum == Z_ERRNO) { 35 | msg = strerror(errno); 36 | } 37 | fprintf(stderr, "Cannot open `%s': %s\n", filename, msg); 38 | return NULL; 39 | } 40 | size = 0; 41 | allocated = 65536; 42 | buf = xmalloc(allocated); 43 | do { 44 | if (size == allocated) { 45 | allocated <<= 1; 46 | buf = xrealloc(buf, allocated); 47 | } 48 | result = gzread(fp, buf + size, allocated - size); 49 | if (result < 0) { 50 | if ((errno == EINTR) || (errno == EAGAIN)) 51 | continue; 52 | 53 | msg = gzerror(fp, &errnum); 54 | if (errnum == Z_ERRNO) { 55 | msg = strerror(errno); 56 | } 57 | die ("read on %s of %ld bytes failed: %s\n", 58 | filename, (allocated - size) + 0UL, msg); 59 | } 60 | size += result; 61 | } while(result > 0); 62 | result = gzclose(fp); 63 | if (result != Z_OK) { 64 | msg = gzerror(fp, &errnum); 65 | if (errnum == Z_ERRNO) { 66 | msg = strerror(errno); 67 | } 68 | die ("Close of %s failed: %s\n", filename, msg); 69 | } 70 | *r_size = size; 71 | return buf; 72 | } 73 | #else 74 | char *zlib_decompress_file(const char *UNUSED(filename), off_t *UNUSED(r_size)) 75 | { 76 | return NULL; 77 | } 78 | #endif /* HAVE_ZLIB */ 79 | -------------------------------------------------------------------------------- /kexec_test/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # kexec_test Debugging payload to be certain the infrastructure works 3 | # 4 | RELOC:=0x10000 5 | KEXEC_TEST_SRCS:= kexec_test/kexec_test16.S kexec_test/kexec_test.S 6 | 7 | dist += kexec_test/Makefile $(KEXEC_TEST_SRCS) \ 8 | kexec_test/x86-setup-legacy-pic.S 9 | 10 | BUILD_KEXEC_TEST = no 11 | ifeq ($(ARCH),i386) 12 | BUILD_KEXEC_TEST = yes 13 | endif 14 | ifeq ($(ARCH),x86_64) 15 | BUILD_KEXEC_TEST = yes 16 | endif 17 | 18 | ifeq ($(BUILD_KEXEC_TEST),yes) 19 | 20 | KEXEC_TEST_OBJS = $(call objify, $(KEXEC_TEST_SRCS)) 21 | KEXEC_TEST_DEPS = $(call depify, $(KEXEC_TEST_OBJS)) 22 | 23 | KEXEC_TEST = $(PKGLIBDIR)/kexec_test 24 | 25 | clean += $(KEXEC_TEST_OBJS) $(KEXEC_TEST_DEPS) $(KEXEC_TEST) 26 | 27 | -include $(KEXEC_TEST_DEPS) 28 | 29 | $(KEXEC_TEST): CC=$(TARGET_CC) 30 | $(KEXEC_TEST): CPPFLAGS+=-DRELOC=$(RELOC) 31 | $(KEXEC_TEST): ASFLAGS+=-m32 32 | #$(KEXEC_TEST): LDFLAGS=-m32 -Wl,-e -Wl,_start -Wl,-Ttext -Wl,$(RELOC) \ 33 | # -nostartfiles 34 | $(KEXEC_TEST): LDFLAGS=-melf_i386 -e _start -Ttext $(RELOC) 35 | 36 | $(KEXEC_TEST): $(KEXEC_TEST_OBJS) 37 | mkdir -p $(@D) 38 | $(TARGET_LD) $(LDFLAGS) -o $@ $^ 39 | 40 | endif 41 | -------------------------------------------------------------------------------- /kexec_test/x86-setup-legacy-pic.S: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | .text 21 | .code32 22 | setup_legacy_pic: 23 | /* Load the legacy dos settings into the 8259A pic */ 24 | movb $0xff, %al 25 | outb %al, $0x21 /* mask all of 8259A-1 */ 26 | outb %al, $0xa1 /* mask all of 8259A-1 */ 27 | 28 | movb $0x11, %al 29 | outb %al, $0x20 /* ICW1: select 8259A-1 init */ 30 | outb %al, $0x80 /* A short delay */ 31 | movb $0x08, %al 32 | outb %al, $0x21 /* ICW2: 8259A-1 IR0-7 mappend to 0x8-0xf */ 33 | outb %al, $0x80 /* A short delay */ 34 | movb $01, %al 35 | outb %al, $0x21 /* Normal 8086 auto EOI mode */ 36 | outb %al, $0x80 /* A short delay */ 37 | 38 | 39 | movb $0x11, %al 40 | outb %al, $0xA0 /* ICW1: select 8259A-2 init */ 41 | outb %al, $0x80 /* A short delay */ 42 | movb $0x70, %al 43 | outb %al, $0xA1 /* ICW2: 8259A-2 IR0-7 mappend to 0x70-0x77 */ 44 | outb %al, $0x80 /* A short delay */ 45 | movb $01, %al 46 | outb %al, $0xA1 /* Normal 8086 auto EOI mode */ 47 | outb %al, $0x80 /* A short delay */ 48 | 49 | movb $0, %al 50 | outb %al, $0x21 /* Unmask all of 8259A-1 */ 51 | outb %al, $0xa1 /* Unmask all of 8259A-2 */ 52 | 53 | ret 54 | -------------------------------------------------------------------------------- /purgatory/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory (an uncomfortable intermediate state) 3 | # In this case the code that runs between kernels 4 | # 5 | 6 | # There is probably a cleaner way to do this but for now this 7 | # should keep us from accidentially include unsafe library functions 8 | # or headers. 9 | 10 | PURGATORY = purgatory/purgatory.ro 11 | PURGATORY_SRCS = 12 | PURGATORY_SRCS += purgatory/purgatory.c 13 | PURGATORY_SRCS += purgatory/printf.c 14 | PURGATORY_SRCS += purgatory/string.c 15 | 16 | dist += purgatory/Makefile $(PURGATORY_SRCS) \ 17 | purgatory/include/purgatory.h purgatory/include/string.h 18 | 19 | include $(srcdir)/purgatory/arch/alpha/Makefile 20 | include $(srcdir)/purgatory/arch/arm/Makefile 21 | include $(srcdir)/purgatory/arch/i386/Makefile 22 | include $(srcdir)/purgatory/arch/ia64/Makefile 23 | include $(srcdir)/purgatory/arch/mips/Makefile 24 | include $(srcdir)/purgatory/arch/ppc/Makefile 25 | include $(srcdir)/purgatory/arch/ppc64/Makefile 26 | include $(srcdir)/purgatory/arch/s390/Makefile 27 | include $(srcdir)/purgatory/arch/sh/Makefile 28 | include $(srcdir)/purgatory/arch/x86_64/Makefile 29 | 30 | PURGATORY_SRCS+=$($(ARCH)_PURGATORY_SRCS) 31 | 32 | PURGATORY_OBJS = $(call objify, $(PURGATORY_SRCS)) purgatory/sha256.o 33 | PURGATORY_DEPS = $(call depify, $(PURGATORY_OBJS)) 34 | 35 | clean += $(PURGATORY_OBJS) $(PURGATORY_DEPS) $(PURGATORY) 36 | 37 | -include $(PURGATORY_DEPS) 38 | 39 | # sha256.c needs to be compiled without optimization, else 40 | # purgatory fails to execute on ia64. 41 | purgatory/sha256.o: CFLAGS += -O0 42 | 43 | purgatory/sha256.o: $(srcdir)/util_lib/sha256.c 44 | mkdir -p $(@D) 45 | $(COMPILE.c) -o $@ $^ 46 | 47 | $(PURGATORY): CC=$(TARGET_CC) 48 | $(PURGATORY): CFLAGS+=$(PURGATORY_EXTRA_CFLAGS) \ 49 | $($(ARCH)_PURGATORY_EXTRA_CFLAGS) \ 50 | -Os -fno-builtin -ffreestanding 51 | 52 | $(PURGATORY): CPPFLAGS=$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \ 53 | -I$(srcdir)/purgatory/include \ 54 | -I$(srcdir)/purgatory/arch/$(ARCH)/include \ 55 | -I$(srcdir)/util_lib/include \ 56 | -I$(srcdir)/include \ 57 | -I$(shell $(CC) -print-file-name=include) 58 | $(PURGATORY): LDFLAGS=$($(ARCH)_PURGATORY_EXTRA_CFLAGS)\ 59 | --no-undefined -nostartfiles -nostdlib -nodefaultlibs \ 60 | -e purgatory_start -r 61 | 62 | $(PURGATORY): $(PURGATORY_OBJS) 63 | $(MKDIR) -p $(@D) 64 | $(CC) $(LDFLAGS) -o $@ $^ 65 | 66 | # $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) --no-undefined -e purgatory_start -r -o $@ $(PURGATORY_OBJS) $(UTIL_LIB) 67 | 68 | echo:: 69 | @echo "PURGATORY_SRCS $(PURGATORY_SRCS)" 70 | @echo "PURGATORY_DEPS $(PURGATORY_DEPS)" 71 | @echo "PURGATORY_OBJS $(PURGATORY_OBJS)" 72 | -------------------------------------------------------------------------------- /purgatory/arch/alpha/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory alpha 3 | # 4 | 5 | alpha_PURGATORY_SRCS = 6 | 7 | dist += purgatory/arch/alpha/Makefile $(alpha_PURGATORY_SRCS) 8 | 9 | -------------------------------------------------------------------------------- /purgatory/arch/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory arm 3 | # 4 | 5 | arm_PURGATORY_SRCS = 6 | 7 | dist += purgatory/arch/arm/Makefile $(arm_PURGATORY_SRCS) 8 | 9 | 10 | -------------------------------------------------------------------------------- /purgatory/arch/i386/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory i386 3 | # 4 | 5 | i386_PURGATORY_SRCS = purgatory/arch/i386/entry32-16.S 6 | i386_PURGATORY_SRCS += purgatory/arch/i386/entry32-16-debug.S 7 | i386_PURGATORY_SRCS += purgatory/arch/i386/entry32.S 8 | i386_PURGATORY_SRCS += purgatory/arch/i386/setup-x86.S 9 | i386_PURGATORY_SRCS += purgatory/arch/i386/stack.S 10 | i386_PURGATORY_SRCS += purgatory/arch/i386/compat_x86_64.S 11 | i386_PURGATORY_SRCS += purgatory/arch/i386/purgatory-x86.c 12 | i386_PURGATORY_SRCS += purgatory/arch/i386/console-x86.c 13 | i386_PURGATORY_SRCS += purgatory/arch/i386/vga.c 14 | i386_PURGATORY_SRCS += purgatory/arch/i386/pic.c 15 | i386_PURGATORY_SRCS += purgatory/arch/i386/crashdump_backup.c 16 | 17 | dist += purgatory/arch/i386/Makefile $(i386_PURGATORY_SRCS) \ 18 | purgatory/arch/i386/purgatory-x86.h \ 19 | purgatory/arch/i386/include/arch/io.h \ 20 | purgatory/arch/i386/include/arch/debug.h 21 | 22 | -------------------------------------------------------------------------------- /purgatory/arch/i386/compat_x86_64.S: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003,2004,2005 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | .equ MSR_K6_EFER, 0xC0000080 21 | .equ EFER_LME, 0x00000100 22 | .equ X86_CR4_PAE, 0x00000020 23 | .equ CR0_PG, 0x80000000 24 | 25 | .globl compat_x86_64, compat_x86_64_entry32 26 | .text 27 | .code64 28 | .balign 16 29 | compat_x86_64: 30 | /* Setup a temporary gdt */ 31 | /* This also acts as a serializing instruction ensuring 32 | * my self modifying code works. 33 | */ 34 | lgdt gdt(%rip) 35 | 36 | /* Switch to 32bit compatiblity mode */ 37 | ljmp *lm_exit_addr(%rip) 38 | lm_exit: 39 | .code32 40 | 41 | /* Disable paging */ 42 | movl %cr0, %eax 43 | andl $~CR0_PG, %eax 44 | movl %eax, %cr0 45 | 46 | /* Disable long mode */ 47 | movl $MSR_K6_EFER, %ecx 48 | rdmsr 49 | andl $~EFER_LME, %eax 50 | wrmsr 51 | 52 | /* Disable PAE */ 53 | xorl %eax, %eax 54 | movl %eax, %cr4 55 | 56 | /* load the data segments */ 57 | movl $0x18, %eax /* data segment */ 58 | movl %eax, %ds 59 | movl %eax, %es 60 | movl %eax, %ss 61 | movl %eax, %fs 62 | movl %eax, %gs 63 | 64 | /* set all of the registers to known values */ 65 | /* leave %esp alone */ 66 | 67 | xorl %eax, %eax 68 | xorl %ebx, %ebx 69 | xorl %ecx, %ecx 70 | xorl %edx, %edx 71 | xorl %esi, %esi 72 | xorl %edi, %edi 73 | xorl %ebp, %ebp 74 | 75 | jmp *compat_x86_64_entry32 76 | 77 | .section ".rodata" 78 | .balign 16 79 | gdt: /* 0x00 unusable segment 80 | * 0x08 unused 81 | * so use them as the gdt ptr 82 | */ 83 | .word gdt_end - gdt - 1 84 | # A quad word pointer to the gdt with the high 32bits 0 85 | .long gdt, 0 86 | .word 0, 0, 0 87 | 88 | /* 0x10 4GB flat code segment */ 89 | .word 0xFFFF, 0x0000, 0x9A00, 0x00CF 90 | /* 0x18 4GB flat data segment */ 91 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 92 | gdt_end: 93 | 94 | lm_exit_addr: 95 | .long lm_exit 96 | .long 0x10 97 | 98 | compat_x86_64_entry32: 99 | .long 0 100 | .size compat_x86_64_entry32, . - compat_x86_64_entry32 101 | -------------------------------------------------------------------------------- /purgatory/arch/i386/crashdump_backup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Created by: Vivek goyal (vgoyal@in.ibm.com) 5 | * Copyright (C) IBM Corporation, 2005. All rights reserved 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation (version 2 of the License). 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include "../../../kexec/arch/i386/crashdump-x86.h" 24 | 25 | /* Backup region start gets set after /proc/iomem has been parsed. */ 26 | /* We reuse the same code for x86_64 also so changing backup_start to 27 | unsigned long */ 28 | unsigned long backup_start = 0; 29 | 30 | /* Backup first 640K of memory to backup region as reserved by kexec. 31 | * Assuming first 640K has to be present on i386 machines and no address 32 | * validity checks have to be performed. */ 33 | 34 | void crashdump_backup_memory(void) 35 | { 36 | void *dest, *src; 37 | 38 | src = (void *) BACKUP_SRC_START; 39 | 40 | if (backup_start) { 41 | dest = (void *)(backup_start); 42 | memcpy(dest, src, BACKUP_SRC_SIZE); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /purgatory/arch/i386/entry32.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: setup code 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #undef i386 21 | 22 | .text 23 | .arch i386 24 | .globl entry32, entry32_regs 25 | entry32: 26 | .code32 27 | 28 | /* Setup a gdt that should that is generally usefully */ 29 | lgdt %cs:gdt 30 | 31 | /* load the data segments */ 32 | movl $0x18, %eax /* data segment */ 33 | movl %eax, %ds 34 | movl %eax, %es 35 | movl %eax, %ss 36 | movl %eax, %fs 37 | movl %eax, %gs 38 | 39 | /* load the code segment */ 40 | ljmp $0x10,$1f 41 | 1: 42 | 43 | /* Load the registers */ 44 | movl eax, %eax 45 | movl ecx, %ecx 46 | movl edx, %edx 47 | movl esi, %esi 48 | movl edi, %edi 49 | movl esp, %esp 50 | movl ebp, %ebp 51 | movl ebx, %ebx 52 | 53 | /* Jump to the loaded image */ 54 | jmpl *(eip) 55 | 56 | .section ".rodata" 57 | .balign 16 58 | gdt: 59 | /* 0x00 unusable segment so used as the gdt ptr */ 60 | .word gdt_end - gdt - 1 61 | .long gdt 62 | .word 0 63 | 64 | /* 0x08 dummy */ 65 | .word 0x0000, 0x0000, 0x0000, 0x000 66 | 67 | /* Documented linux kernel segments */ 68 | /* 0x10 4GB flat code segment */ 69 | .word 0xFFFF, 0x0000, 0x9A00, 0x00CF 70 | /* 0x18 4GB flat data segment */ 71 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 72 | 73 | /* 0x20 dummy */ 74 | .word 0x0000, 0x0000, 0x0000, 0x000 75 | /* 0x28 dummy */ 76 | .word 0x0000, 0x0000, 0x0000, 0x000 77 | /* 0x30 dummy */ 78 | .word 0x0000, 0x0000, 0x0000, 0x000 79 | /* 0x38 dummy */ 80 | .word 0x0000, 0x0000, 0x0000, 0x000 81 | /* 0x40 dummy */ 82 | .word 0x0000, 0x0000, 0x0000, 0x000 83 | /* 0x48 dummy */ 84 | .word 0x0000, 0x0000, 0x0000, 0x000 85 | /* 0x50 dummy */ 86 | .word 0x0000, 0x0000, 0x0000, 0x000 87 | /* 0x58 dummy */ 88 | .word 0x0000, 0x0000, 0x0000, 0x000 89 | 90 | /* Segments used by the 2.5.x kernel */ 91 | /* 0x60 4GB flat code segment */ 92 | .word 0xFFFF, 0x0000, 0x9A00, 0x00CF 93 | /* 0x68 4GB flat data segment */ 94 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 95 | gdt_end: 96 | 97 | .data 98 | .balign 4 99 | entry32_regs: 100 | eax: .long 0x00000000 101 | ebx: .long 0x00000000 102 | ecx: .long 0x00000000 103 | edx: .long 0x00000000 104 | esi: .long 0x00000000 105 | edi: .long 0x00000000 106 | esp: .long 0x00000000 107 | ebp: .long 0x00000000 108 | eip: .long entry16 109 | .size entry32_regs, . - entry32_regs 110 | 111 | -------------------------------------------------------------------------------- /purgatory/arch/i386/include/arch/io.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_I386_IO_H 2 | #define ARCH_I386_IO_H 3 | 4 | #include 5 | /* Helper functions for directly doing I/O */ 6 | 7 | static inline __attribute__((__always_inline__)) 8 | uint8_t inb(uint16_t port) 9 | { 10 | uint8_t result; 11 | 12 | __asm__ __volatile__ ( 13 | "inb %w1,%0" 14 | :"=a" (result) 15 | :"Nd" (port)); 16 | return result; 17 | } 18 | 19 | static inline __attribute__((__always_inline__)) 20 | uint16_t inw(uint16_t port) 21 | { 22 | uint16_t result; 23 | 24 | __asm__ __volatile__ ( 25 | "inw %w1,%0" 26 | :"=a" (result) 27 | :"Nd" (port)); 28 | return result; 29 | } 30 | 31 | static inline __attribute__((__always_inline__)) 32 | uint32_t inl(uint32_t port) 33 | { 34 | uint32_t result; 35 | 36 | __asm__ __volatile__ ( 37 | "inl %w1,%0" 38 | :"=a" (result) 39 | :"Nd" (port)); 40 | return result; 41 | } 42 | 43 | static inline __attribute__((__always_inline__)) 44 | void outb (uint8_t value, uint16_t port) 45 | { 46 | __asm__ __volatile__ ( 47 | "outb %b0,%w1" 48 | : 49 | :"a" (value), "Nd" (port)); 50 | } 51 | 52 | static inline __attribute__((__always_inline__)) 53 | void outw (uint16_t value, uint16_t port) 54 | { 55 | __asm__ __volatile__ ( 56 | "outw %w0,%w1" 57 | : 58 | :"a" (value), "Nd" (port)); 59 | } 60 | 61 | static inline __attribute__((__always_inline__)) 62 | void outl (uint32_t value, uint16_t port) 63 | { 64 | __asm__ __volatile__ ( 65 | "outl %0,%w1" 66 | : 67 | :"a" (value), "Nd" (port)); 68 | } 69 | 70 | 71 | /* 72 | * readX/writeX() are used to access memory mapped devices. On some 73 | * architectures the memory mapped IO stuff needs to be accessed 74 | * differently. On the x86 architecture, we just read/write the 75 | * memory location directly. 76 | */ 77 | 78 | static inline __attribute__((__always_inline__)) 79 | unsigned char readb(const volatile void *addr) 80 | { 81 | return *(volatile unsigned char *) addr; 82 | } 83 | static inline __attribute__((__always_inline__)) 84 | unsigned short readw(const volatile void *addr) 85 | { 86 | return *(volatile unsigned short *) addr; 87 | } 88 | static inline __attribute__((__always_inline__)) 89 | unsigned int readl(const volatile void *addr) 90 | { 91 | return *(volatile unsigned int *) addr; 92 | } 93 | 94 | static inline __attribute__((__always_inline__)) 95 | void writeb(unsigned char b, volatile void *addr) 96 | { 97 | *(volatile unsigned char *) addr = b; 98 | } 99 | static inline __attribute__((__always_inline__)) 100 | void writew(unsigned short b, volatile void *addr) 101 | { 102 | *(volatile unsigned short *) addr = b; 103 | } 104 | static inline __attribute__((__always_inline__)) 105 | void writel(unsigned int b, volatile void *addr) 106 | { 107 | *(volatile unsigned int *) addr = b; 108 | } 109 | 110 | #endif /* ARCH_I386_IO_H */ 111 | -------------------------------------------------------------------------------- /purgatory/arch/i386/pic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | #include 20 | #include 21 | #include "purgatory-x86.h" 22 | 23 | 24 | void x86_setup_legacy_pic(void) 25 | { 26 | /* Load the legacy dos settings into the 8259A pic */ 27 | outb(0xff, 0x21); /* mask all of 8259A-1 */ 28 | outb(0xff, 0xa1); /* mask all of 8259A-2 */ 29 | 30 | outb(0x11, 0x20); /* ICW1: select 8259A-1 init */ 31 | outb(0x11, 0x80); /* A short delay */ 32 | 33 | outb(0x08, 0x21); /* ICW2: 8259A-1 IR0-7 mappend to 0x8-0xf */ 34 | outb(0x08, 0x80); /* A short delay */ 35 | 36 | outb(0x01, 0x21); /* Normal 8086 auto EOI mode */ 37 | outb(0x01, 0x80); /* A short delay */ 38 | 39 | outb(0x11, 0xa0); /* ICW1: select 8259A-2 init */ 40 | outb(0x11, 0x80); /* A short delay */ 41 | 42 | outb(0x70, 0xa1); /* ICW2: 8259A-2 IR0-7 mappend to 0x70-0x77 */ 43 | outb(0x70, 0x80); /* A short delay */ 44 | 45 | outb(0x01, 0xa1); /* Normal 8086 auto EOI mode */ 46 | outb(0x01, 0x80); /* A short delay */ 47 | 48 | outb(0x00, 0x21); /* Unmask all of 8259A-1 */ 49 | outb(0x00, 0xa1); /* Unmask all of 8259A-2 */ 50 | } 51 | 52 | -------------------------------------------------------------------------------- /purgatory/arch/i386/purgatory-x86.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "purgatory-x86.h" 4 | 5 | /* 6 | * CPU 7 | * ============================================================================= 8 | */ 9 | 10 | void x86_setup_cpu(void) 11 | { 12 | #if 0 13 | /* This code is only needed for old versions of the kexec kernel patch. 14 | * While it is still a good idea doing this unconditionally breaks 15 | * on older cpus that did not implemented cr4. 16 | * So this code is disabled for now. If this is revisited 17 | * I first need to detect cpuid support and then use cpuid 18 | * to conditionally change newer cpu registers. 19 | */ 20 | /* clear special bits in %cr4 */ 21 | asm volatile( 22 | "movl %0, %%eax\n\t" 23 | "movl %%eax, %%cr4\n\t" 24 | : /* outputs */ 25 | : "r" (0) 26 | ); 27 | #endif 28 | } 29 | 30 | uint8_t reset_vga = 0; 31 | uint8_t legacy_timer = 0; 32 | uint8_t legacy_pic = 0; 33 | uint8_t panic_kernel = 0; 34 | unsigned long jump_back_entry = 0; 35 | char *cmdline_end = 0; 36 | 37 | void setup_arch(void) 38 | { 39 | x86_setup_cpu(); 40 | if (reset_vga) x86_reset_vga(); 41 | if (legacy_pic) x86_setup_legacy_pic(); 42 | /* if (legacy_timer) x86_setup_legacy_timer(); */ 43 | } 44 | 45 | static void x86_setup_jump_back_entry(void) 46 | { 47 | if (cmdline_end) 48 | sprintf(cmdline_end, " kexec_jump_back_entry=0x%x", 49 | jump_back_entry); 50 | } 51 | 52 | /* This function can be used to execute after the SHA256 verification. */ 53 | void post_verification_setup_arch(void) 54 | { 55 | if (panic_kernel) crashdump_backup_memory(); 56 | if (jump_back_entry) x86_setup_jump_back_entry(); 57 | } 58 | -------------------------------------------------------------------------------- /purgatory/arch/i386/purgatory-x86.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_X86_H 2 | #define PURGATORY_X86_H 3 | 4 | void x86_reset_vga(void); 5 | void x86_setup_legacy_pic(void); 6 | void x86_setup_legacy_timer(void); 7 | void crashdump_backup_memory(void); 8 | 9 | #endif /* PURGATORY_X86_H */ 10 | -------------------------------------------------------------------------------- /purgatory/arch/i386/setup-x86.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: setup code 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | #undef i386 22 | 23 | .text 24 | .arch i386 25 | .globl purgatory_start 26 | purgatory_start: 27 | .code32 28 | 29 | /* Load a gdt so I know what the segment registers are */ 30 | lgdt %cs:gdt 31 | 32 | /* load the data segments */ 33 | movl $0x08, %eax /* data segment */ 34 | movl %eax, %ds 35 | movl %eax, %es 36 | movl %eax, %ss 37 | movl %eax, %fs 38 | movl %eax, %gs 39 | 40 | /* load the code segment */ 41 | ljmp $0x10,$1f 42 | 1: 43 | 44 | movl 0(%esp), %eax 45 | movl %eax, jump_back_entry 46 | 47 | /* Setup a stack */ 48 | movl $lstack_end, %esp 49 | 50 | /* Call the C code */ 51 | call purgatory 52 | jmp entry32 53 | 54 | .section ".rodata" 55 | .balign 16 56 | gdt: 57 | /* 0x00 unusable segment so used as the gdt ptr */ 58 | .word gdt_end - gdt - 1 59 | .long gdt 60 | .word 0 61 | 62 | /* 0x8 4GB flat data segment */ 63 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 64 | 65 | /* 0x10 4GB flat code segment */ 66 | .word 0xFFFF, 0x0000, 0x9A00, 0x00CF 67 | gdt_end: 68 | 69 | /* A stack for the purgatory code */ 70 | .bss 71 | .balign 4096 72 | lstack: 73 | .skip 4096 74 | lstack_end: 75 | 76 | -------------------------------------------------------------------------------- /purgatory/arch/i386/stack.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: stack 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | /* A stack for the loaded kernel. 21 | * Seperate and in the data section so it can be prepopulated. 22 | */ 23 | .data 24 | .globl stack, stack_end 25 | .globl stack_arg32_1, stack_arg32_2, stack_arg32_3 ,stack_arg32_4 26 | .globl stack_arg32_5, stack_arg32_6, stack_arg32_7 ,stack_arg32_8 27 | .balign 4096 28 | stack: 29 | .skip 4096 - (8*4) 30 | stack_arg32_8: .long 0 ; .size stack_arg32_8, 4 31 | stack_arg32_7: .long 0 ; .size stack_arg32_7, 4 32 | stack_arg32_6: .long 0 ; .size stack_arg32_6, 4 33 | stack_arg32_5: .long 0 ; .size stack_arg32_5, 4 34 | stack_arg32_4: .long 0 ; .size stack_arg32_4, 4 35 | stack_arg32_3: .long 0 ; .size stack_arg32_3, 4 36 | stack_arg32_2: .long 0 ; .size stack_arg32_2, 4 37 | stack_arg32_1: .long 0 ; .size stack_arg32_1, 4 38 | stack_end: 39 | 40 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory ia64 3 | # 4 | ia64_PURGATORY_SRCS += purgatory/arch/ia64/entry.S 5 | ia64_PURGATORY_SRCS += purgatory/arch/ia64/purgatory-ia64.c 6 | ia64_PURGATORY_SRCS += purgatory/arch/ia64/console-ia64.c 7 | ia64_PURGATORY_SRCS += purgatory/arch/ia64/vga.c 8 | 9 | ia64_PURGATORY_EXTRA_CFLAGS = -ffixed-r28 10 | 11 | dist += purgatory/arch/ia64/Makefile $(ia64_PURGATORY_SRCS) \ 12 | purgatory/arch/ia64/io.h purgatory/arch/ia64/purgatory-ia64.h 13 | 14 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/console-ia64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "io.h" 3 | 4 | #define VGABASE UNCACHED(0xb8000) 5 | 6 | /* code based on i386 console code 7 | * TODO add serial support 8 | */ 9 | #define MAX_YPOS 25 10 | #define MAX_XPOS 80 11 | 12 | unsigned long current_ypos = 1, current_xpos = 0; 13 | 14 | static void putchar_vga(int ch) 15 | { 16 | int i, k, j; 17 | 18 | if (current_ypos >= MAX_YPOS) { 19 | /* scroll 1 line up */ 20 | for (k = 1, j = 0; k < MAX_YPOS; k++, j++) { 21 | for (i = 0; i < MAX_XPOS; i++) { 22 | writew(readw(VGABASE + 2*(MAX_XPOS*k + i)), 23 | VGABASE + 2*(MAX_XPOS*j + i)); 24 | } 25 | } 26 | for (i = 0; i < MAX_XPOS; i++) 27 | writew(0x720, VGABASE + 2*(MAX_XPOS*j + i)); 28 | current_ypos = MAX_YPOS-1; 29 | } 30 | if (ch == '\n') { 31 | current_xpos = 0; 32 | current_ypos++; 33 | } else if (ch != '\r') { 34 | writew(((0x7 << 8) | (unsigned short) ch), 35 | VGABASE + 2*(MAX_XPOS*current_ypos + 36 | current_xpos++)); 37 | if (current_xpos >= MAX_XPOS) { 38 | current_xpos = 0; 39 | current_ypos++; 40 | } 41 | } 42 | } 43 | 44 | void putchar(int ch) 45 | { 46 | putchar_vga(ch); 47 | } 48 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/entry.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: setup code 3 | * 4 | * Copyright (C) 2005-2006 Zou Nan hai (nanhai.zou@intel.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | #define DECLARE_DATA8(name) \ 20 | .global name; \ 21 | .size name, 8; \ 22 | name: data8 0x0 23 | 24 | .global __dummy_efi_function 25 | .align 32 26 | .proc __dummy_efi_function 27 | __dummy_efi_function: 28 | mov r8=r0;; 29 | br.ret.sptk.many rp;; 30 | .global __dummy_efi_function_end 31 | __dummy_efi_function_end: 32 | .endp __dummy_efi_function 33 | 34 | .global purgatory_start 35 | .align 32 36 | .proc purgatory_start 37 | purgatory_start: 38 | movl r2=__gp_value;; 39 | ld8 gp=[r2];; 40 | br.call.sptk.many b0=purgatory 41 | ;; 42 | alloc r2 = ar.pfs, 0, 0, 2, 0 43 | ;; 44 | mov out0=r28 45 | movl out1=__vmcode_base; 46 | br.call.sptk.many b0=ia64_env_setup 47 | movl r10=__kernel_entry;; 48 | ld8 r14=[r10];; 49 | movl r10=__boot_param_base;; 50 | ld8 r28=[r10];; 51 | mov b6=r14;; 52 | mov ar.lc=r0 53 | mov ar.ec=r0 54 | cover;; 55 | invala;; 56 | br.call.sptk.many b0=b6 57 | .endp purgatory_start 58 | 59 | DECLARE_DATA8(__kernel_entry) 60 | DECLARE_DATA8(__vmcode_base) 61 | DECLARE_DATA8(__vmcode_size) 62 | DECLARE_DATA8(__ramdisk_base) 63 | DECLARE_DATA8(__ramdisk_size) 64 | DECLARE_DATA8(__command_line) 65 | DECLARE_DATA8(__command_line_len) 66 | DECLARE_DATA8(__efi_memmap_base) 67 | DECLARE_DATA8(__efi_memmap_size) 68 | DECLARE_DATA8(__boot_param_base) 69 | DECLARE_DATA8(__loaded_segments) 70 | DECLARE_DATA8(__loaded_segments_num) 71 | 72 | DECLARE_DATA8(__gp_value) 73 | DECLARE_DATA8(__noio) 74 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | #define UNCACHED(x) (void *)((x)|(1UL<<63)) 4 | #define MF() asm volatile ("mf.a" ::: "memory") 5 | #define IO_SPACE_ENCODING(p) ((((p) >> 2) << 12) | (p & 0xfff)) 6 | extern long __noio; 7 | static inline void *io_addr (unsigned long port) 8 | { 9 | unsigned long offset; 10 | unsigned long io_base; 11 | asm volatile ("mov %0=ar.k0":"=r"(io_base)); 12 | offset = IO_SPACE_ENCODING(port); 13 | return UNCACHED(io_base | offset); 14 | } 15 | 16 | static inline unsigned int inb (unsigned long port) 17 | { 18 | volatile unsigned char *addr = io_addr(port); 19 | unsigned char ret = 0; 20 | if (!__noio) { 21 | ret = *addr; 22 | MF(); 23 | } 24 | return ret; 25 | } 26 | 27 | static inline unsigned int inw (unsigned long port) 28 | { 29 | volatile unsigned short *addr = io_addr(port); 30 | unsigned short ret = 0; 31 | 32 | if (!__noio) { 33 | ret = *addr; 34 | MF(); 35 | } 36 | return ret; 37 | } 38 | 39 | static inline unsigned int inl (unsigned long port) 40 | { 41 | volatile unsigned int *addr = io_addr(port); 42 | unsigned int ret ; 43 | if (!__noio) { 44 | ret = *addr; 45 | MF(); 46 | } 47 | return ret; 48 | } 49 | 50 | static inline void outb (unsigned char val, unsigned long port) 51 | { 52 | volatile unsigned char *addr = io_addr(port); 53 | 54 | if (!__noio) { 55 | *addr = val; 56 | MF(); 57 | } 58 | } 59 | 60 | static inline void outw (unsigned short val, unsigned long port) 61 | { 62 | volatile unsigned short *addr = io_addr(port); 63 | 64 | if (!__noio) { 65 | *addr = val; 66 | MF(); 67 | } 68 | } 69 | 70 | static inline void outl (unsigned int val, unsigned long port) 71 | { 72 | volatile unsigned int *addr = io_addr(port); 73 | 74 | if (!__noio) { 75 | *addr = val; 76 | MF(); 77 | } 78 | } 79 | 80 | static inline unsigned char readb(const volatile void *addr) 81 | { 82 | return __noio ? 0 :*(volatile unsigned char *) addr; 83 | } 84 | static inline unsigned short readw(const volatile void *addr) 85 | { 86 | return __noio ? 0 :*(volatile unsigned short *) addr; 87 | } 88 | static inline unsigned int readl(const volatile void *addr) 89 | { 90 | return __noio ? 0 :*(volatile unsigned int *) addr; 91 | } 92 | 93 | static inline void writeb(unsigned char b, volatile void *addr) 94 | { 95 | if (!__noio) 96 | *(volatile unsigned char *) addr = b; 97 | } 98 | static inline void writew(unsigned short b, volatile void *addr) 99 | { 100 | if (!__noio) 101 | *(volatile unsigned short *) addr = b; 102 | } 103 | static inline void writel(unsigned int b, volatile void *addr) 104 | { 105 | if (!__noio) 106 | *(volatile unsigned int *) addr = b; 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/purgatory-ia64.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_IA64_H 2 | #define PURGATORY_IA64_H 3 | 4 | void reset_vga(void); 5 | #endif /* PURGATORY_IA64_H */ 6 | -------------------------------------------------------------------------------- /purgatory/arch/ia64/vga.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | void reset_vga(void) 3 | { 4 | /* Hello */ 5 | inb(0x3da); 6 | outb(0, 0x3c0); 7 | 8 | /* Sequencer registers */ 9 | outw(0x0300, 0x3c4); 10 | outw(0x0001, 0x3c4); 11 | outw(0x0302, 0x3c4); 12 | outw(0x0003, 0x3c4); 13 | outw(0x0204, 0x3c4); 14 | 15 | /* Ensure CRTC regs 0-7 are unlocked by clearing bit 7 of CRTC[17] */ 16 | outw(0x0e11, 0x3d4); 17 | /* CRTC registers */ 18 | outw(0x5f00, 0x3d4); 19 | outw(0x4f01, 0x3d4); 20 | outw(0x5002, 0x3d4); 21 | outw(0x8203, 0x3d4); 22 | outw(0x5504, 0x3d4); 23 | outw(0x8105, 0x3d4); 24 | outw(0xbf06, 0x3d4); 25 | outw(0x1f07, 0x3d4); 26 | outw(0x0008, 0x3d4); 27 | outw(0x4f09, 0x3d4); 28 | outw(0x200a, 0x3d4); 29 | outw(0x0e0b, 0x3d4); 30 | outw(0x000c, 0x3d4); 31 | outw(0x000d, 0x3d4); 32 | outw(0x010e, 0x3d4); 33 | outw(0xe00f, 0x3d4); 34 | outw(0x9c10, 0x3d4); 35 | outw(0x8e11, 0x3d4); 36 | outw(0x8f12, 0x3d4); 37 | outw(0x2813, 0x3d4); 38 | outw(0x1f14, 0x3d4); 39 | outw(0x9615, 0x3d4); 40 | outw(0xb916, 0x3d4); 41 | outw(0xa317, 0x3d4); 42 | outw(0xff18, 0x3d4); 43 | 44 | /* Graphic registers */ 45 | outw(0x0000, 0x3ce); 46 | outw(0x0001, 0x3ce); 47 | outw(0x0002, 0x3ce); 48 | outw(0x0003, 0x3ce); 49 | outw(0x0004, 0x3ce); 50 | outw(0x1005, 0x3ce); 51 | outw(0x0e06, 0x3ce); 52 | outw(0x0007, 0x3ce); 53 | outw(0xff08, 0x3ce); 54 | 55 | /* Attribute registers */ 56 | inb(0x3da); 57 | outb(0x00, 0x3c0); 58 | outb(0x00, 0x3c0); 59 | 60 | inb(0x3da); 61 | outb(0x01, 0x3c0); 62 | outb(0x01, 0x3c0); 63 | 64 | inb(0x3da); 65 | outb(0x02, 0x3c0); 66 | outb(0x02, 0x3c0); 67 | 68 | inb(0x3da); 69 | outb(0x03, 0x3c0); 70 | outb(0x03, 0x3c0); 71 | 72 | inb(0x3da); 73 | outb(0x04, 0x3c0); 74 | outb(0x04, 0x3c0); 75 | 76 | inb(0x3da); 77 | outb(0x05, 0x3c0); 78 | outb(0x05, 0x3c0); 79 | 80 | inb(0x3da); 81 | outb(0x06, 0x3c0); 82 | outb(0x14, 0x3c0); 83 | 84 | inb(0x3da); 85 | outb(0x07, 0x3c0); 86 | outb(0x07, 0x3c0); 87 | 88 | inb(0x3da); 89 | outb(0x08, 0x3c0); 90 | outb(0x38, 0x3c0); 91 | 92 | inb(0x3da); 93 | outb(0x09, 0x3c0); 94 | outb(0x39, 0x3c0); 95 | 96 | inb(0x3da); 97 | outb(0x0a, 0x3c0); 98 | outb(0x3a, 0x3c0); 99 | 100 | inb(0x3da); 101 | outb(0x0b, 0x3c0); 102 | outb(0x3b, 0x3c0); 103 | 104 | inb(0x3da); 105 | outb(0x0c, 0x3c0); 106 | outb(0x3c, 0x3c0); 107 | 108 | inb(0x3da); 109 | outb(0x0d, 0x3c0); 110 | outb(0x3d, 0x3c0); 111 | 112 | inb(0x3da); 113 | outb(0x0e, 0x3c0); 114 | outb(0x3e, 0x3c0); 115 | 116 | inb(0x3da); 117 | outb(0x0f, 0x3c0); 118 | outb(0x3f, 0x3c0); 119 | 120 | inb(0x3da); 121 | outb(0x10, 0x3c0); 122 | outb(0x0c, 0x3c0); 123 | 124 | inb(0x3da); 125 | outb(0x11, 0x3c0); 126 | outb(0x00, 0x3c0); 127 | 128 | inb(0x3da); 129 | outb(0x12, 0x3c0); 130 | outb(0x0f, 0x3c0); 131 | 132 | inb(0x3da); 133 | outb(0x13, 0x3c0); 134 | outb(0x08, 0x3c0); 135 | 136 | inb(0x3da); 137 | outb(0x14, 0x3c0); 138 | outb(0x00, 0x3c0); 139 | 140 | /* Goodbye */ 141 | inb(0x3da); 142 | outb(0x20, 0x3c0); 143 | } 144 | -------------------------------------------------------------------------------- /purgatory/arch/mips/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory mips 3 | # 4 | 5 | mips_PURGATORY_SRCS+= purgatory/arch/mips/purgatory-mips.c 6 | mips_PURGATORY_SRCS+= purgatory/arch/mips/console-mips.c 7 | 8 | dist += purgatory/arch/mips/Makefile $(mips_PURGATORY_SRCS) \ 9 | purgatory/arch/mips/purgatory-mips.h 10 | 11 | -------------------------------------------------------------------------------- /purgatory/arch/mips/console-mips.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "unused.h" 3 | 4 | void putchar(int UNUSED(ch)) 5 | { 6 | /* Nothing for now */ 7 | } 8 | -------------------------------------------------------------------------------- /purgatory/arch/mips/purgatory-mips.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "purgatory-mips.h" 3 | 4 | void setup_arch(void) 5 | { 6 | /* Nothing for now */ 7 | } 8 | -------------------------------------------------------------------------------- /purgatory/arch/mips/purgatory-mips.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_MIPSEL_H 2 | #define PURGATORY_MIPSEL_H 3 | 4 | /* nothing yet */ 5 | 6 | #endif /* PURGATORY_MIPSEL_H */ 7 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory ppc 3 | # 4 | 5 | ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S 6 | ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S 7 | ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c 8 | ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c 9 | ppc_PURGATORY_SRCS += purgatory/arch/ppc/crt.S 10 | 11 | dist += purgatory/arch/ppc/Makefile $(ppc_PURGATORY_SRCS) \ 12 | purgatory/arch/ppc/purgatory-ppc.h purgatory/arch/ppc/ppc_asm.h 13 | 14 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/console-ppc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "unused.h" 3 | 4 | void putchar(int UNUSED(ch)) 5 | { 6 | /* Nothing for now */ 7 | } 8 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/misc.S: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains miscellaneous low-level functions. 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 4 | * 5 | * Largely rewritten by Cort Dougan (cort@cs.nmt.edu) 6 | * and Paul Mackerras. 7 | * 8 | * Rewrittten to work with /sbin/kexec 20 December 2004 Eric Biederman 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License 12 | * as published by the Free Software Foundation; either version 13 | * 2 of the License, or (at your option) any later version. 14 | * 15 | */ 16 | 17 | #include "ppc_asm.h" 18 | 19 | .text 20 | 21 | /* 22 | * Extended precision shifts. 23 | * 24 | * Updated to be valid for shift counts from 0 to 63 inclusive. 25 | * -- Gabriel 26 | * 27 | * R3/R4 has 64 bit value 28 | * R5 has shift count 29 | * result in R3/R4 30 | * 31 | * ashrdi3: arithmetic right shift (sign propagation) 32 | * lshrdi3: logical right shift 33 | * ashldi3: left shift 34 | */ 35 | .globl __ashrdi3 36 | __ashrdi3: 37 | subfic r6,r5,32 38 | srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count 39 | addi r7,r5,32 # could be xori, or addi with -32 40 | slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) 41 | rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0 42 | sraw r7,r3,r7 # t2 = MSW >> (count-32) 43 | or r4,r4,r6 # LSW |= t1 44 | slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2 45 | sraw r3,r3,r5 # MSW = MSW >> count 46 | or r4,r4,r7 # LSW |= t2 47 | blr 48 | 49 | .globl __ashldi3 50 | __ashldi3: 51 | subfic r6,r5,32 52 | slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count 53 | addi r7,r5,32 # could be xori, or addi with -32 54 | srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count) 55 | slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32) 56 | or r3,r3,r6 # MSW |= t1 57 | slw r4,r4,r5 # LSW = LSW << count 58 | or r3,r3,r7 # MSW |= t2 59 | blr 60 | 61 | .globl __lshrdi3 62 | __lshrdi3: 63 | subfic r6,r5,32 64 | srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count 65 | addi r7,r5,32 # could be xori, or addi with -32 66 | slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) 67 | srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32) 68 | or r4,r4,r6 # LSW |= t1 69 | srw r3,r3,r5 # MSW = MSW >> count 70 | or r4,r4,r7 # LSW |= t2 71 | blr 72 | 73 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/purgatory-ppc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Created by: Mohan Kumar M (mohan@in.ibm.com) 5 | * 6 | * Copyright (C) IBM Corporation, 2005. All rights reserved 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation (version 2 of the License). 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | #include "purgatory-ppc.h" 24 | 25 | unsigned int panic_kernel = 0; 26 | unsigned long backup_start = 0; 27 | unsigned long stack = 0; 28 | unsigned long dt_offset = 0; 29 | unsigned long my_toc = 0; 30 | unsigned long kernel = 0; 31 | 32 | void setup_arch(void) 33 | { 34 | return; 35 | } 36 | 37 | void post_verification_setup_arch(void) 38 | { 39 | if (panic_kernel) 40 | crashdump_backup_memory(); 41 | } 42 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/purgatory-ppc.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_PPC_H 2 | #define PURGATORY_PPC_H 3 | 4 | void crashdump_backup_memory(void); 5 | void post_verification_setup_arch(void); 6 | #endif /* PURGATORY_PPC_H */ 7 | -------------------------------------------------------------------------------- /purgatory/arch/ppc/v2wrap_32.S: -------------------------------------------------------------------------------- 1 | # 2 | # kexec: Linux boots Linux 3 | # 4 | # Copyright (C) 2004 - 2005, Milton D Miller II, IBM Corporation 5 | # Copyright (C) 2006, Mohan Kumar M (mohan@in.ibm.com), IBM Corporation 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation (version 2 of the License). 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | # 20 | 21 | # v2wrap.S 22 | # a wrapper to call purgatory code to backup first 23 | # 32kB of first kernel into the backup region 24 | # reserved by kexec-tools. 25 | # Invokes powerpc kernel with the expected arguments 26 | # of kernel(device-tree, phys-offset, 0) 27 | 28 | # 29 | # calling convention: 30 | # r3 = physical number of this cpu (all cpus) 31 | # r4 = address of this chunk (master only) 32 | # master enters at purgatory_start (aka first byte of this chunk) 33 | # slaves (additional cpus), if any, enter a copy of the 34 | # first 0x100 bytes of this code relocated to 0x0 35 | # 36 | # in other words, 37 | # a copy of the first 0x100 bytes of this code is copied to 0 38 | # and the slaves are sent to address 0x60 39 | # with r3 = their physical cpu number. 40 | 41 | .globl purgatory_start 42 | purgatory_start: b master 43 | .org purgatory_start + 0x60 # ABI: slaves start at 60 with r3=phys 44 | slave: b $ 45 | .org purgatory_start + 0x100 # ABI: end of copied region 46 | .size purgatory_start, . - purgatory_start 47 | 48 | # 49 | # The above 0x100 bytes at purgatory_start are replaced with the 50 | # code from the kernel (or next stage) by kexec/arch/powerpc/kexec-powerpc.c 51 | # 52 | 53 | master: 54 | or 1,1,1 # low priority to let other threads catchup 55 | isync 56 | mr 17,3 # save cpu id to r17 57 | mr 15,4 # save physical address in reg15 58 | 59 | lis 6,stack@h 60 | ori 6,6,stack@l 61 | lwz 1,0(6) #setup stack 62 | 63 | subi 1,1,112 64 | bl purgatory 65 | nop 66 | 67 | or 3,3,3 # ok now to high priority, lets boot 68 | lis 6,0x1 69 | mtctr 6 # delay a bit for slaves to catch up 70 | 83: bdnz 83b # before we overwrite 0-100 again 71 | 72 | lis 6,dt_offset@h 73 | ori 6,6,dt_offset@l 74 | lwz 3,0(6) # load device-tree address 75 | lwz 6,20(3) # fetch version number 76 | cmpwi 0,6,2 # v2 ? 77 | blt 80f 78 | stw 17,28(3) # save my cpu number as boot_cpu_phys 79 | 80: 80 | lis 6,kernel@h 81 | ori 6,6,kernel@l 82 | lwz 4,0(6) # load the kernel address 83 | li 5,0 # r5 will be 0 for kernel 84 | li 6,0 # clear r6 for good measure 85 | mtctr 4 # prepare branch too 86 | 87 | lwz 8,0(4) # get the first instruction that we stole 88 | stw 8,0(0) # and put it in the slave loop at 0 89 | # skip cache flush, do we care? 90 | 91 | bctr # start kernel 92 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory ppc64 3 | # 4 | 5 | ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/v2wrap.S 6 | ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/hvCall.S 7 | ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/purgatory-ppc64.c 8 | ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/console-ppc64.c 9 | ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/crashdump_backup.c 10 | 11 | ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -mcall-aixdesc 12 | ppc64_PURGATORY_EXTRA_ASFLAGS += -m64 -mcall-aixdesc 13 | ppc64_PURGATORY_EXTRA_LDFLAGS += -melf64ppc 14 | 15 | dist += purgatory/arch/ppc64/Makefile $(ppc64_PURGATORY_SRCS) \ 16 | purgatory/arch/ppc64/hvCall.h \ 17 | purgatory/arch/ppc64/purgatory-ppc64.h 18 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/console-ppc64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Created by: Mohan Kumar M (mohan@in.ibm.com) 5 | * 6 | * Copyright (C) IBM Corporation, 2005. All rights reserved 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation (version 2 of the License). 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | #include "hvCall.h" 24 | 25 | extern int debug; 26 | 27 | void putchar(int c) 28 | { 29 | char buff[16]; 30 | unsigned long *lbuf = (unsigned long *)buff; 31 | 32 | if (!debug) /* running on non pseries */ 33 | return; 34 | 35 | if (c == '\n') 36 | putchar('\r'); 37 | 38 | buff[0] = c; 39 | plpar_hcall_norets(H_PUT_TERM_CHAR, 0, 1, lbuf[0], lbuf[1]); 40 | return; 41 | } 42 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/crashdump_backup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Created by: Mohan Kumar M (mohan@in.ibm.com) 5 | * 6 | * Copyright (C) IBM Corporation, 2005. All rights reserved 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation (version 2 of the License). 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | #include 24 | #include "../../../kexec/arch/ppc64/crashdump-ppc64.h" 25 | 26 | extern unsigned long backup_start; 27 | 28 | /* Backup first 32KB of memory to backup region reserved by kexec */ 29 | void crashdump_backup_memory(void) 30 | { 31 | void *dest, *src; 32 | 33 | src = (void *)BACKUP_SRC_START; 34 | 35 | if (backup_start) { 36 | dest = (void *)(backup_start); 37 | memcpy(dest, src, BACKUP_SRC_SIZE); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/hvCall.S: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains the generic function to perform a call to the 3 | * pSeries LPAR hypervisor. 4 | * 5 | * Taken from linux/arch/powerpc/platforms/pseries/hvCall.S 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 10 | * 2 of the License, or (at your option) any later version. 11 | */ 12 | 13 | #define HVSC .long 0x44000022 14 | .text 15 | .machine ppc64 16 | .globl .plpar_hcall_norets 17 | .plpar_hcall_norets: 18 | or 6,6,6 # medium low priority 19 | mfcr 0 20 | stw 0,8(1) 21 | 22 | HVSC /* invoke the hypervisor */ 23 | 24 | lwz 0,8(1) 25 | mtcrf 0xff,0 26 | blr /* return r3 = status */ 27 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/hvCall.h: -------------------------------------------------------------------------------- 1 | #ifndef HVCALL_H 2 | #define HVCALL_H 3 | 4 | #define H_PUT_TERM_CHAR 0x58 5 | 6 | long plpar_hcall_norets(unsigned long opcode, ...); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/purgatory-ppc64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Created by: Mohan Kumar M (mohan@in.ibm.com) 5 | * 6 | * Copyright (C) IBM Corporation, 2005. All rights reserved 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation (version 2 of the License). 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | #include "purgatory-ppc64.h" 24 | 25 | unsigned int panic_kernel = 0; 26 | unsigned long backup_start = 0; 27 | unsigned long stack = 0; 28 | unsigned long dt_offset = 0; 29 | unsigned long my_toc = 0; 30 | unsigned long kernel = 0; 31 | unsigned int debug = 0; 32 | 33 | void setup_arch(void) 34 | { 35 | return; 36 | } 37 | 38 | void post_verification_setup_arch(void) 39 | { 40 | if (panic_kernel) 41 | crashdump_backup_memory(); 42 | } 43 | -------------------------------------------------------------------------------- /purgatory/arch/ppc64/purgatory-ppc64.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_PPC64_H 2 | #define PURGATORY_PPC64_H 3 | 4 | void crashdump_backup_memory(void); 5 | 6 | #endif /* PURGATORY_PPC64_H */ 7 | -------------------------------------------------------------------------------- /purgatory/arch/s390/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory s390 3 | # 4 | 5 | s390_PURGATORY_SRCS = 6 | 7 | dist += purgatory/arch/s390/Makefile $(s390_PURGATORY_SRCS) 8 | 9 | -------------------------------------------------------------------------------- /purgatory/arch/sh/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory sh 3 | # 4 | 5 | sh_PURGATORY_SRCS = 6 | 7 | dist += purgatory/arch/sh/Makefile $(sh_PURGATORY_SRCS) 8 | 9 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Purgatory x86_64 3 | # 4 | 5 | x86_64_PURGATORY_SRCS_native = purgatory/arch/x86_64/entry64-32.S 6 | x86_64_PURGATORY_SRCS_native += purgatory/arch/x86_64/entry64.S 7 | x86_64_PURGATORY_SRCS_native += purgatory/arch/x86_64/setup-x86_64.S 8 | x86_64_PURGATORY_SRCS_native += purgatory/arch/x86_64/stack.S 9 | x86_64_PURGATORY_SRCS_native += purgatory/arch/x86_64/purgatory-x86_64.c 10 | 11 | x86_64_PURGATORY_SRCS += $(x86_64_PURGATORY_SRCS_native) 12 | 13 | dist += purgatory/arch/x86_64/Makefile $(x86_64_PURGATORY_SRCS_native) \ 14 | purgatory/arch/x86_64/include/arch/io.h \ 15 | purgatory/arch/x86_64/include/arch/debug.h \ 16 | purgatory/arch/x86_64/purgatory-x86_64.h 17 | 18 | # Don't add sources in i386/ to dist, as i386/Makefile adds them 19 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/entry32-16.S 20 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/entry32-16-debug.S 21 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/crashdump_backup.c 22 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/console-x86.c 23 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/vga.c 24 | x86_64_PURGATORY_SRCS += purgatory/arch/i386/pic.c 25 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/entry64.S: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "arch/debug.h" 21 | 22 | .text 23 | .code64 24 | .balign 16 25 | .globl entry64, entry64_regs 26 | entry64: 27 | /* Don't worry about special registers... */ 28 | 29 | /* Setup a gdt that should be preserved */ 30 | lgdt gdt(%rip) 31 | 32 | /* load the data segments */ 33 | movl $0x18, %eax /* data segment */ 34 | movl %eax, %ds 35 | movl %eax, %es 36 | movl %eax, %ss 37 | movl %eax, %fs 38 | movl %eax, %gs 39 | 40 | movq $stack_init, %rsp 41 | pushq $0x10 /* CS */ 42 | pushq $new_cs_exit 43 | lretq 44 | new_cs_exit: 45 | 46 | /* Load the registers */ 47 | movq rax(%rip), %rax 48 | movq rbx(%rip), %rbx 49 | movq rcx(%rip), %rcx 50 | movq rdx(%rip), %rdx 51 | movq rsi(%rip), %rsi 52 | movq rdi(%rip), %rdi 53 | movq rsp(%rip), %rsp 54 | movq rbp(%rip), %rbp 55 | movq r8(%rip), %r8 56 | movq r9(%rip), %r9 57 | movq r10(%rip), %r10 58 | movq r11(%rip), %r11 59 | movq r12(%rip), %r12 60 | movq r13(%rip), %r13 61 | movq r14(%rip), %r14 62 | movq r15(%rip), %r15 63 | 64 | /* Jump to the new code... */ 65 | jmpq *rip(%rip) 66 | 67 | .section ".rodata" 68 | .balign 4 69 | entry64_regs: 70 | rax: .quad 0x00000000 71 | rbx: .quad 0x00000000 72 | rcx: .quad 0x00000000 73 | rdx: .quad 0x00000000 74 | rsi: .quad 0x00000000 75 | rdi: .quad 0x00000000 76 | rsp: .quad 0x00000000 77 | rbp: .quad 0x00000000 78 | r8: .quad 0x00000000 79 | r9: .quad 0x00000000 80 | r10: .quad 0x00000000 81 | r11: .quad 0x00000000 82 | r12: .quad 0x00000000 83 | r13: .quad 0x00000000 84 | r14: .quad 0x00000000 85 | r15: .quad 0x00000000 86 | rip: .quad entry32 87 | .size entry64_regs, . - entry64_regs 88 | 89 | .section ".rodata" 90 | .balign 16 91 | gdt: /* 0x00 unusable segment 92 | * 0x08 unused 93 | * so use them as the gdt ptr 94 | */ 95 | .word gdt_end - gdt - 1 96 | .quad gdt 97 | .word 0, 0, 0 98 | 99 | /* 0x10 4GB flat code segment */ 100 | .word 0xFFFF, 0x0000, 0x9A00, 0x00AF 101 | 102 | /* 0x18 4GB flat data segment */ 103 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 104 | gdt_end: 105 | stack: .quad 0, 0 106 | stack_init: 107 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/include/arch/io.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_X86_64_IO_H 2 | #define ARCH_X86_64_IO_H 3 | 4 | #include 5 | #include "../../../i386/include/arch/io.h" 6 | 7 | #endif /* ARCH_X86_64_IO_H */ 8 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/purgatory-x86_64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "purgatory-x86_64.h" 5 | 6 | uint8_t reset_vga = 0; 7 | uint8_t legacy_pic = 0; 8 | uint8_t panic_kernel = 0; 9 | unsigned long jump_back_entry = 0; 10 | char *cmdline_end = NULL; 11 | 12 | void setup_arch(void) 13 | { 14 | if (reset_vga) x86_reset_vga(); 15 | if (legacy_pic) x86_setup_legacy_pic(); 16 | } 17 | 18 | void x86_setup_jump_back_entry(void) 19 | { 20 | if (cmdline_end) 21 | sprintf(cmdline_end, " kexec_jump_back_entry=0x%lx", 22 | jump_back_entry); 23 | } 24 | 25 | /* This function can be used to execute after the SHA256 verification. */ 26 | void post_verification_setup_arch(void) 27 | { 28 | if (panic_kernel) crashdump_backup_memory(); 29 | if (jump_back_entry) x86_setup_jump_back_entry(); 30 | } 31 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/purgatory-x86_64.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_X86_64_H 2 | #define PURGATORY_X86_64_H 3 | #include "../i386/purgatory-x86.h" 4 | #endif /* PURGATORY_X86_64_H */ 5 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/setup-x86_64.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: setup code 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "arch/debug.h" 21 | 22 | 23 | #undef i386 24 | 25 | .text 26 | .globl purgatory_start 27 | .balign 16 28 | purgatory_start: 29 | .code64 30 | 31 | /* Load a gdt so I know what the segment registers are */ 32 | lgdt gdt(%rip) 33 | 34 | /* load the data segments */ 35 | movl $0x18, %eax /* data segment */ 36 | movl %eax, %ds 37 | movl %eax, %es 38 | movl %eax, %ss 39 | movl %eax, %fs 40 | movl %eax, %gs 41 | 42 | /* In 64bit mode the code segment is meaningless */ 43 | 44 | movq 0(%rsp), %rax 45 | movq %rax, jump_back_entry 46 | 47 | /* Setup a stack */ 48 | movq $lstack_end, %rsp 49 | 50 | /* Call the C code */ 51 | call purgatory 52 | jmp entry64 53 | 54 | .section ".rodata" 55 | .balign 16 56 | gdt: /* 0x00 unusable segment 57 | * 0x08 unused 58 | * so use them as the gdt ptr 59 | */ 60 | .word gdt_end - gdt - 1 61 | .quad gdt 62 | .word 0, 0, 0 63 | 64 | /* 0x10 4GB flat code segment */ 65 | .word 0xFFFF, 0x0000, 0x9A00, 0x00AF 66 | 67 | /* 0x18 4GB flat data segment */ 68 | .word 0xFFFF, 0x0000, 0x9200, 0x00CF 69 | gdt_end: 70 | 71 | .bss 72 | .balign 4096 73 | lstack: 74 | .skip 4096 75 | lstack_end: 76 | 77 | -------------------------------------------------------------------------------- /purgatory/arch/x86_64/stack.S: -------------------------------------------------------------------------------- 1 | /* 2 | * purgatory: stack 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | /* A stack for the loaded kernel. 21 | * Seperate and in the data section so it can be prepopulated. 22 | */ 23 | .data 24 | .balign 4096 25 | .globl stack, stack_end 26 | .globl stack_arg32_1, stack_arg32_2, stack_arg32_3 ,stack_arg32_4 27 | .globl stack_arg32_5, stack_arg32_6, stack_arg32_7 ,stack_arg32_8 28 | .globl stack_arg64_1, stack_arg64_2, stack_arg64_3 ,stack_arg64_4 29 | 30 | stack: 31 | .skip 4096 - (8*4) 32 | stack_arg64_4: ; .size stack_arg64_4, 8 33 | stack_arg32_8: .long 0 ; .size stack_arg32_8, 4 34 | stack_arg32_7: .long 0 ; .size stack_arg32_7, 4 35 | stack_arg64_3: ; .size stack_arg64_3, 8 36 | stack_arg32_6: .long 0 ; .size stack_arg32_6, 4 37 | stack_arg32_5: .long 0 ; .size stack_arg32_5, 4 38 | stack_arg64_2: ; .size stack_arg64_2, 8 39 | stack_arg32_4: .long 0 ; .size stack_arg32_4, 4 40 | stack_arg32_3: .long 0 ; .size stack_arg32_3, 4 41 | stack_arg64_1: ; .size stack_arg64_1, 8 42 | stack_arg32_2: .long 0 ; .size stack_arg32_2, 4 43 | stack_arg32_1: .long 0 ; .size stack_arg32_1, 4 44 | stack_end: 45 | -------------------------------------------------------------------------------- /purgatory/include/purgatory.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGATORY_H 2 | #define PURGATORY_H 3 | 4 | void putchar(int ch); 5 | void sprintf(char *buffer, const char *fmt, ...); 6 | void printf(const char *fmt, ...); 7 | void setup_arch(void); 8 | void post_verification_setup_arch(void); 9 | 10 | #endif /* PURGATORY_H */ 11 | -------------------------------------------------------------------------------- /purgatory/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | #include 5 | 6 | size_t strnlen(const char *s, size_t max); 7 | void* memset(void* s, int c, size_t n); 8 | void* memcpy(void *dest, const void *src, size_t len); 9 | int memcmp(void *src1, void *src2, size_t len); 10 | 11 | 12 | #endif /* STRING_H */ 13 | -------------------------------------------------------------------------------- /purgatory/purgatory.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../kexec/kexec-sha256.h" 8 | 9 | struct sha256_region sha256_regions[SHA256_REGIONS] = {}; 10 | sha256_digest_t sha256_digest = { }; 11 | 12 | void verify_sha256_digest(void) 13 | { 14 | struct sha256_region *ptr, *end; 15 | sha256_digest_t digest; 16 | size_t i; 17 | sha256_context ctx; 18 | sha256_starts(&ctx); 19 | end = &sha256_regions[sizeof(sha256_regions)/sizeof(sha256_regions[0])]; 20 | for(ptr = sha256_regions; ptr < end; ptr++) { 21 | sha256_update(&ctx, (uint8_t *)((uintptr_t)ptr->start), 22 | ptr->len); 23 | } 24 | sha256_finish(&ctx, digest); 25 | if (memcmp(digest, sha256_digest, sizeof(digest)) != 0) { 26 | printf("sha256 digests do not match :(\n"); 27 | printf(" digest: "); 28 | for(i = 0; i < sizeof(digest); i++) { 29 | printf("%hhx ", digest[i]); 30 | } 31 | printf("\n"); 32 | printf("sha256_digest: "); 33 | for(i = 0; i < sizeof(sha256_digest); i++) { 34 | printf("%hhx ", sha256_digest[i]); 35 | } 36 | printf("\n"); 37 | for(;;) { 38 | /* loop forever */ 39 | } 40 | } 41 | } 42 | 43 | void purgatory(void) 44 | { 45 | printf("I'm in purgatory\n"); 46 | setup_arch(); 47 | verify_sha256_digest(); 48 | post_verification_setup_arch(); 49 | } 50 | -------------------------------------------------------------------------------- /purgatory/string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t strnlen(const char *s, size_t max) 5 | { 6 | size_t len = 0; 7 | while(len < max && *s) { 8 | len++; 9 | s++; 10 | } 11 | return len; 12 | } 13 | 14 | void* memset(void* s, int c, size_t n) 15 | { 16 | size_t i; 17 | char *ss = (char*)s; 18 | 19 | for (i=0;i 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int c; 6 | int i; 7 | const char *name = argv[1]; 8 | printf("#include \n"); 9 | printf("const char %s[] = {\n", name); 10 | i = 0; 11 | while((c = getchar()) != EOF) { 12 | if ((i % 16) != 0) { 13 | putchar(' '); 14 | } 15 | printf("0x%02x,", c); 16 | i++; 17 | if ((i %16) == 0) { 18 | putchar('\n'); 19 | } 20 | } 21 | putchar('\n'); 22 | printf("};\n"); 23 | printf("size_t %s_size = sizeof(%s);\n", name, name); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /util_lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Utility function library 3 | # 4 | UTIL_LIB_SRCS += 5 | UTIL_LIB_SRCS += util_lib/compute_ip_checksum.c 6 | UTIL_LIB_SRCS += util_lib/sha256.c 7 | UTIL_LIB_OBJS =$(call objify, $(UTIL_LIB_SRCS)) 8 | UTIL_LIB_DEPS =$(call depify, $(UTIL_LIB_OBJS)) 9 | UTIL_LIB = libutil.a 10 | 11 | -include $(UTIL_LIB_DEPS) 12 | 13 | dist += util_lib/Makefile $(UTIL_LIB_SRCS) \ 14 | util_lib/include/sha256.h util_lib/include/ip_checksum.h 15 | clean += $(UTIL_LIB_OBJS) $(UTIL_LIB_DEPS) $(UTIL_LIB) 16 | 17 | $(UTIL_LIB): CPPFLAGS += -I$(srcdir)/util_lib/include 18 | 19 | $(UTIL_LIB): $(UTIL_LIB_OBJS) 20 | @$(MKDIR) -p $(@D) 21 | $(AR) rs $(UTIL_LIB) $(UTIL_LIB_OBJS) 22 | 23 | -------------------------------------------------------------------------------- /util_lib/compute_ip_checksum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kexec: Linux boots Linux 3 | * 4 | * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation (version 2 of the License). 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | unsigned long compute_ip_checksum(void *addr, unsigned long length) 25 | { 26 | uint16_t *ptr; 27 | unsigned long sum; 28 | unsigned long len; 29 | unsigned long laddr; 30 | /* compute an ip style checksum */ 31 | laddr = (unsigned long )addr; 32 | sum = 0; 33 | if (laddr & 1) { 34 | uint16_t buffer; 35 | unsigned char *ptr; 36 | /* copy the first byte into a 2 byte buffer. 37 | * This way automatically handles the endian question 38 | * of which byte (low or high) the last byte goes in. 39 | */ 40 | buffer = 0; 41 | ptr = addr; 42 | memcpy(&buffer, ptr, 1); 43 | sum += buffer; 44 | if (sum > 0xFFFF) 45 | sum -= 0xFFFF; 46 | length -= 1; 47 | addr = ptr +1; 48 | 49 | } 50 | len = length >> 1; 51 | ptr = addr; 52 | while (len--) { 53 | sum += *(ptr++); 54 | if (sum > 0xFFFF) 55 | sum -= 0xFFFF; 56 | } 57 | addr = ptr; 58 | if (length & 1) { 59 | uint16_t buffer; 60 | unsigned char *ptr; 61 | /* copy the last byte into a 2 byte buffer. 62 | * This way automatically handles the endian question 63 | * of which byte (low or high) the last byte goes in. 64 | */ 65 | buffer = 0; 66 | ptr = addr; 67 | memcpy(&buffer, ptr, 1); 68 | sum += buffer; 69 | if (sum > 0xFFFF) 70 | sum -= 0xFFFF; 71 | } 72 | return (~sum) & 0xFFFF; 73 | 74 | } 75 | 76 | unsigned long add_ip_checksums(unsigned long offset, unsigned long sum, unsigned long new) 77 | { 78 | unsigned long checksum; 79 | sum = ~sum & 0xFFFF; 80 | new = ~new & 0xFFFF; 81 | if (offset & 1) { 82 | /* byte swap the sum if it came from an odd offset 83 | * since the computation is endian independant this 84 | * works. 85 | */ 86 | new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00); 87 | } 88 | checksum = sum + new; 89 | if (checksum > 0xFFFF) { 90 | checksum -= 0xFFFF; 91 | } 92 | return (~checksum) & 0xFFFF; 93 | } 94 | 95 | unsigned long negate_ip_checksum(unsigned long sum) 96 | { 97 | sum = ~sum & 0xFFFF; 98 | 99 | sum = 0xFFFF - sum; 100 | 101 | return ~sum & 0xFFFF; 102 | } 103 | -------------------------------------------------------------------------------- /util_lib/include/ip_checksum.h: -------------------------------------------------------------------------------- 1 | #ifndef IP_CHECKSUM_H 2 | #define IP_CHECKSUM_H 3 | 4 | unsigned long compute_ip_checksum(void *addr, unsigned long length); 5 | unsigned long add_ip_checksums(unsigned long offset, unsigned long sum, unsigned long new); 6 | unsigned long negate_ip_checksum(unsigned long sum); 7 | 8 | #endif /* IP_CHECKSUM_H */ 9 | -------------------------------------------------------------------------------- /util_lib/include/sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_H 2 | #define SHA256_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct 8 | { 9 | size_t total[2]; 10 | uint32_t state[8]; 11 | uint8_t buffer[64]; 12 | } 13 | sha256_context; 14 | 15 | typedef uint8_t sha256_digest_t[32]; 16 | 17 | void sha256_starts( sha256_context *ctx ); 18 | void sha256_update( sha256_context *ctx, const uint8_t *input, size_t length ); 19 | void sha256_finish( sha256_context *ctx, sha256_digest_t digest ); 20 | 21 | 22 | #endif /* SHA256_H */ 23 | --------------------------------------------------------------------------------