Ticket #930: kexec-atags-2.6.22.5.patch

File kexec-atags-2.6.22.5.patch, 4.7 KB (added by mwester@…, 7 years ago)

Kernel kexec patch to preserve bootloader ATAGs for new kexec'd kernel

  • arch/arm/kernel/relocate_kernel.S

    This patch resolves a kexec boot failure that can occur because
    no ATAGs are passed in to the kexec'd kernel.  Currently the
    newly-kexec'd kernel may fail if it requires specific ATAGs, or
    it may fail because the fixed memory location at which it expects
    to find the ATAGs may contain random data instead of ATAGs.
    
    The patch ensures that any ATAGs passed to the current kernel
    at boot time are copied to a static buffer, and are copied back
    when kexec copies the new kernel into place.  Thus the new
    kernel sees the same ATAGs from kexec and the boot loader.
    
    The boot parameters are copied without regard to type, content,
    or length -- this patch's scope is limited soley to saving and
    restoring a fixed-size block of memory containing the kernel's
    boot parameters.  Additional functionality to examine, alter, or
    replace the ATAGs (using kexec, for example) can be implemented
    by manipulating the static buffer containing the preserved ATAGs.
    
    Note: the size of the buffer (1.5KB) is selected to comfortably
    hold one of each ATAG type, including a maximum-length command
    line and the maximum number of ATAG_MEM structures currently
    supported by the kernel.  Should an ATAG list exceed that limit,
    the list will be silently truncated to that limit (to do other-
    wise at that point in the boot process would make a simple
    problem exceedingly complicated).
    
    Kernel version 2.6.22.5
    
    Signed-off-by: Mike Westerhof <mwester at dls.net>
    ---
    
    diff -uprN linux-2.6.22.5.orig/arch/arm/kernel/relocate_kernel.S linux-2.6.22.5/arch/arm/kernel/relocate_kernel.S
    old new  
    77        .globl relocate_new_kernel 
    88relocate_new_kernel: 
    99 
     10        /* Move boot params back to where the kernel expects them */ 
     11 
     12        ldr     r0,kexec_boot_params_address 
     13        teq     r0,#0 
     14        beq     8f 
     15 
     16        ldr     r1,kexec_boot_params_copy 
     17        mov     r6,#KEXEC_BOOT_PARAMS_SIZE/4 
     187: 
     19        ldr     r5,[r1],#4 
     20        str     r5,[r0],#4 
     21        subs    r6,r6,#1 
     22        bne     7b 
     23 
     248: 
     25        /* Boot params moved, now go on with the kernel */ 
     26 
    1027        ldr     r0,kexec_indirection_page 
    1128        ldr     r1,kexec_start_address 
    1229 
    relocate_new_kernel: 
    5067        mov lr,r1 
    5168        mov r0,#0 
    5269        ldr r1,kexec_mach_type 
    53         mov r2,#0 
     70        ldr r2,kexec_boot_params_address 
    5471        mov pc,lr 
    5572 
    5673        .globl kexec_start_address 
    kexec_indirection_page: 
    6582kexec_mach_type: 
    6683        .long   0x0 
    6784 
     85        /* phy addr where new kernel will expect to find boot params */ 
     86        .globl kexec_boot_params_address 
     87kexec_boot_params_address: 
     88        .long   0x0 
     89 
     90        /* phy addr where old kernel put a copy of orig boot params */ 
     91        .globl kexec_boot_params_copy 
     92kexec_boot_params_copy: 
     93        .long   0x0 
     94 
    6895relocate_new_kernel_end: 
    6996 
    7097        .globl relocate_new_kernel_size 
  • arch/arm/kernel/setup.c

    diff -uprN linux-2.6.22.5.orig/arch/arm/kernel/setup.c linux-2.6.22.5/arch/arm/kernel/setup.c
    old new  
    2323#include <linux/cpu.h> 
    2424#include <linux/interrupt.h> 
    2525#include <linux/smp.h> 
     26#include <linux/kexec.h> 
    2627 
    2728#include <asm/cpu.h> 
    2829#include <asm/elf.h> 
    static int __init customize_machine(void 
    767768} 
    768769arch_initcall(customize_machine); 
    769770 
     771#ifdef CONFIG_KEXEC 
     772 
     773/* Physical addr of where the boot params should be for this machine */ 
     774extern unsigned long kexec_boot_params_address; 
     775 
     776/* Physical addr of the buffer into which the boot params are copied */ 
     777extern unsigned long kexec_boot_params_copy; 
     778 
     779/* Pointer to the boot params buffer, for manipulation and display */ 
     780unsigned long kexec_boot_params; 
     781EXPORT_SYMBOL(kexec_boot_params); 
     782 
     783/* The buffer itself - make sure it is sized correctly */ 
     784static unsigned long kexec_boot_params_buf[(KEXEC_BOOT_PARAMS_SIZE + 3) / 4]; 
     785 
     786#endif 
     787 
    770788void __init setup_arch(char **cmdline_p) 
    771789{ 
    772790        struct tag *tags = (struct tag *)&init_tags; 
    void __init setup_arch(char **cmdline_p) 
    783801        if (mdesc->boot_params) 
    784802                tags = phys_to_virt(mdesc->boot_params); 
    785803 
     804#ifdef CONFIG_KEXEC 
     805        kexec_boot_params_address = mdesc->boot_params; 
     806        kexec_boot_params_copy = virt_to_phys(kexec_boot_params_buf); 
     807        kexec_boot_params = (unsigned long)kexec_boot_params_buf; 
     808        if (mdesc->boot_params) 
     809                memcpy((void *)kexec_boot_params, tags, KEXEC_BOOT_PARAMS_SIZE); 
     810#endif 
    786811        /* 
    787812         * If we have the old style parameters, convert them to 
    788813         * a tag list. 
  • include/asm-arm/kexec.h

    diff -uprN linux-2.6.22.5.orig/include/asm-arm/kexec.h linux-2.6.22.5/include/asm-arm/kexec.h
    old new  
    1414 
    1515#define KEXEC_ARCH KEXEC_ARCH_ARM 
    1616 
     17#define KEXEC_BOOT_PARAMS_SIZE 1536 
     18 
    1719#ifndef __ASSEMBLY__ 
    1820 
    1921struct kimage;