Ticket #930: kexec-atags-

File kexec-atags-, 4.7 KB (added by mwester@…, 11 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
    Signed-off-by: Mike Westerhof <mwester at dls.net>
    diff -uprN linux- linux-
    old new  
    77        .globl relocate_new_kernel 
     10        /* Move boot params back to where the kernel expects them */ 
     12        ldr     r0,kexec_boot_params_address 
     13        teq     r0,#0 
     14        beq     8f 
     16        ldr     r1,kexec_boot_params_copy 
     17        mov     r6,#KEXEC_BOOT_PARAMS_SIZE/4 
     19        ldr     r5,[r1],#4 
     20        str     r5,[r0],#4 
     21        subs    r6,r6,#1 
     22        bne     7b 
     25        /* Boot params moved, now go on with the kernel */ 
    1027        ldr     r0,kexec_indirection_page 
    1128        ldr     r1,kexec_start_address 
    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 
    5673        .globl kexec_start_address 
    6683        .long   0x0 
     85        /* phy addr where new kernel will expect to find boot params */ 
     86        .globl kexec_boot_params_address 
     88        .long   0x0 
     90        /* phy addr where old kernel put a copy of orig boot params */ 
     91        .globl kexec_boot_params_copy 
     93        .long   0x0 
    7097        .globl relocate_new_kernel_size 
  • arch/arm/kernel/setup.c

    diff -uprN linux- linux-
    old new  
    2323#include <linux/cpu.h> 
    2424#include <linux/interrupt.h> 
    2525#include <linux/smp.h> 
     26#include <linux/kexec.h> 
    2728#include <asm/cpu.h> 
    2829#include <asm/elf.h> 
    static int __init customize_machine(void 
     771#ifdef CONFIG_KEXEC 
     773/* Physical addr of where the boot params should be for this machine */ 
     774extern unsigned long kexec_boot_params_address; 
     776/* Physical addr of the buffer into which the boot params are copied */ 
     777extern unsigned long kexec_boot_params_copy; 
     779/* Pointer to the boot params buffer, for manipulation and display */ 
     780unsigned long kexec_boot_params; 
     783/* The buffer itself - make sure it is sized correctly */ 
     784static unsigned long kexec_boot_params_buf[(KEXEC_BOOT_PARAMS_SIZE + 3) / 4]; 
    770788void __init setup_arch(char **cmdline_p) 
    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); 
     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); 
    786811        /* 
    787812         * If we have the old style parameters, convert them to 
    788813         * a tag list. 
  • include/asm-arm/kexec.h

    diff -uprN linux- linux-
    old new  
    1515#define KEXEC_ARCH KEXEC_ARCH_ARM 
     17#define KEXEC_BOOT_PARAMS_SIZE 1536 
    1719#ifndef __ASSEMBLY__ 
    1921struct kimage;