~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/kexec/file_load.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * powerpc code to implement the kexec_file_load syscall
  4  *
  5  * Copyright (C) 2004  Adam Litke (agl@us.ibm.com)
  6  * Copyright (C) 2004  IBM Corp.
  7  * Copyright (C) 2004,2005  Milton D Miller II, IBM Corporation
  8  * Copyright (C) 2005  R Sharada (sharada@in.ibm.com)
  9  * Copyright (C) 2006  Mohan Kumar M (mohan@in.ibm.com)
 10  * Copyright (C) 2016  IBM Corporation
 11  *
 12  * Based on kexec-tools' kexec-elf-ppc64.c, fs2dt.c.
 13  * Heavily modified for the kernel by
 14  * Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>.
 15  */
 16 
 17 #include <linux/slab.h>
 18 #include <linux/kexec.h>
 19 #include <linux/of_fdt.h>
 20 #include <linux/libfdt.h>
 21 #include <asm/setup.h>
 22 
 23 #define SLAVE_CODE_SIZE         256     /* First 0x100 bytes */
 24 
 25 /**
 26  * setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line
 27  *                       of kdump kernel for exporting the core.
 28  * @image:               Kexec image
 29  * @cmdline:             Command line parameters to update.
 30  * @cmdline_len:         Length of the cmdline parameters.
 31  *
 32  * kdump segment must be setup before calling this function.
 33  *
 34  * Returns new cmdline buffer for kdump kernel on success, NULL otherwise.
 35  */
 36 char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
 37                           unsigned long cmdline_len)
 38 {
 39         int elfcorehdr_strlen;
 40         char *cmdline_ptr;
 41 
 42         cmdline_ptr = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
 43         if (!cmdline_ptr)
 44                 return NULL;
 45 
 46         elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ",
 47                                     image->elf_load_addr);
 48 
 49         if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) {
 50                 pr_err("Appending elfcorehdr=<addr> exceeds cmdline size\n");
 51                 kfree(cmdline_ptr);
 52                 return NULL;
 53         }
 54 
 55         memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
 56         // Ensure it's nul terminated
 57         cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
 58         return cmdline_ptr;
 59 }
 60 
 61 /**
 62  * setup_purgatory - initialize the purgatory's global variables
 63  * @image:              kexec image.
 64  * @slave_code:         Slave code for the purgatory.
 65  * @fdt:                Flattened device tree for the next kernel.
 66  * @kernel_load_addr:   Address where the kernel is loaded.
 67  * @fdt_load_addr:      Address where the flattened device tree is loaded.
 68  *
 69  * Return: 0 on success, or negative errno on error.
 70  */
 71 int setup_purgatory(struct kimage *image, const void *slave_code,
 72                     const void *fdt, unsigned long kernel_load_addr,
 73                     unsigned long fdt_load_addr)
 74 {
 75         unsigned int *slave_code_buf, master_entry;
 76         int ret;
 77 
 78         slave_code_buf = kmalloc(SLAVE_CODE_SIZE, GFP_KERNEL);
 79         if (!slave_code_buf)
 80                 return -ENOMEM;
 81 
 82         /* Get the slave code from the new kernel and put it in purgatory. */
 83         ret = kexec_purgatory_get_set_symbol(image, "purgatory_start",
 84                                              slave_code_buf, SLAVE_CODE_SIZE,
 85                                              true);
 86         if (ret) {
 87                 kfree(slave_code_buf);
 88                 return ret;
 89         }
 90 
 91         master_entry = slave_code_buf[0];
 92         memcpy(slave_code_buf, slave_code, SLAVE_CODE_SIZE);
 93         slave_code_buf[0] = master_entry;
 94         ret = kexec_purgatory_get_set_symbol(image, "purgatory_start",
 95                                              slave_code_buf, SLAVE_CODE_SIZE,
 96                                              false);
 97         kfree(slave_code_buf);
 98 
 99         ret = kexec_purgatory_get_set_symbol(image, "kernel", &kernel_load_addr,
100                                              sizeof(kernel_load_addr), false);
101         if (ret)
102                 return ret;
103         ret = kexec_purgatory_get_set_symbol(image, "dt_offset", &fdt_load_addr,
104                                              sizeof(fdt_load_addr), false);
105         if (ret)
106                 return ret;
107 
108         return 0;
109 }
110 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php