Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:arch\x86\kernel\kexec-bzimage64.c Create Date:2022-07-28 08:37:47
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:bzImage64_load

Proto:static void *bzImage64_load(struct kimage *image, char *kernel, unsigned long kernel_len, char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len)

Type:void

Parameter:

TypeParameterName
struct kimage *image
char *kernel
unsigned longkernel_len
char *initrd
unsigned longinitrd_len
char *cmdline
unsigned longcmdline_len
342  ret = 0
349  setup_hdr_offset = offsetof(structboot_params, hdr)
351  struct kexec_buf kbuf = {image = image, buf_max = ULONG_MAX, top_down = true}
353  struct kexec_buf pbuf = {image = image, buf_min = Defines lowest physical address for various segments. Not sure where* exactly these limits came from. Current bzimage64 loader in kexec-tools* uses these so I am retaining it. It can be changed over time as we gain* more insight., buf_max = ULONG_MAX, top_down = true}
356  header = kernel + setup_hdr_offset
357  setup_sects = setup_sects
358  If setup_sects == 0 Then setup_sects = 4
361  kern16_size = (setup_sects + 1) * 512
362  If kernel_len < kern16_size Then
363  pr_err("bzImage truncated\n")
364  Return ERR_PTR( - ENOEXEC)
367  If cmdline_len > cmdline_size Then
368  pr_err("Kernel command line too long\n")
369  Return ERR_PTR( - EINVAL)
376  If cmdline_len + lfcorehdr=0x<64bit-value> > cmdline_size Then
377  pr_debug("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n")
378  Return ERR_PTR( - EINVAL)
382  If Flags to indicate special processing == KEXEC_TYPE_CRASH Then
383  ret = crash_load_segments(image)
384  If ret Then Return ERR_PTR(ret)
392  ret = kexec_load_purgatory(image, & pbuf)
393  If ret Then
394  pr_err("Loading purgatory failed\n")
395  Return ERR_PTR(ret)
398  pr_debug("Loaded purgatory at 0x%lx\n", mem)
409  efi_map_sz = efi_get_runtime_map_size()
410  params_cmdline_sz = size of boot_params + cmdline_len + lfcorehdr=0x<64bit-value>
412  params_cmdline_sz = @a is a power of 2 value (params_cmdline_sz, 16)
413  bufsz = params_cmdline_sz + @a is a power of 2 value (efi_map_sz, 16) + sizeof(structsetup_data) + sizeof(structefi_setup_data)
417  params = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
418  If Not params Then Return ERR_PTR( - ENOMEM)
420  efi_map_offset = params_cmdline_sz
421  efi_setup_data_offset = efi_map_offset + @a is a power of 2 value (efi_map_sz, 16)
424  setup_header_size = 0x0202 + kernel[0x0201] - setup_hdr_offset
427  memcpy( & setup header , (kernel + setup_hdr_offset), setup_header_size)
429  buffer = params
430  memsz = bufsz
431  buf_align = 16
432  buf_min = MIN_BOOTPARAM_ADDR
433  ret = kexec_add_buffer( & kbuf)
434  If ret Then Go to out_free_params
436  bootparam_load_addr = mem
437  pr_debug("Loaded boot_param, command line and misc at 0x%lx bufsz=0x%lx memsz=0x%lx\n", bootparam_load_addr, bufsz, bufsz)
441  buffer = kernel + kern16_size
442  bufsz = kernel_len - kern16_size
443  memsz = align the pointer to the (next) page boundary (init_size)
444  buf_align = kernel_alignment
445  buf_min = MIN_KERNEL_LOAD_ADDR
446  mem = If kexec_buf.mem is set to this value, kexec_locate_mem_hole()* will try to allocate free memory. Arch may overwrite it.
447  ret = kexec_add_buffer( & kbuf)
448  If ret Then Go to out_free_params
450  kernel_load_addr = mem
452  pr_debug("Loaded 64bit kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", kernel_load_addr, bufsz, memsz)
456  If initrd Then
457  buffer = initrd
458  bufsz = memsz = initrd_len
459  buf_align = PAGE_SIZE
460  buf_min = MIN_INITRD_LOAD_ADDR
461  mem = If kexec_buf.mem is set to this value, kexec_locate_mem_hole()* will try to allocate free memory. Arch may overwrite it.
462  ret = kexec_add_buffer( & kbuf)
463  If ret Then Go to out_free_params
465  initrd_load_addr = mem
467  pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", initrd_load_addr, initrd_len, initrd_len)
470  setup_initrd(params, initrd_load_addr, initrd_len)
473  setup_cmdline(image, params, bootparam_load_addr, size of boot_params , cmdline, cmdline_len)
477  type_of_loader = 0x0D << 4
478  loadflags = 0
481  ret = kexec_purgatory_get_set_symbol(image, "entry64_regs", & regs64, size of regs64 , 1)
483  If ret Then Go to out_free_params
486  rbx = 0
487  rsi = bootparam_load_addr
488  rip = kernel_load_addr + 0x200
489  stack = kexec_purgatory_get_symbol_addr(image, "stack_end")
490  If IS_ERR(stack) Then
491  pr_err("Could not find address of symbol stack_end\n")
492  ret = -EINVAL
493  Go to out_free_params
496  rsp = stack
497  ret = kexec_purgatory_get_set_symbol(image, "entry64_regs", & regs64, size of regs64 , 0)
499  If ret Then Go to out_free_params
502  ret = setup_boot_parameters(image, params, bootparam_load_addr, efi_map_offset, efi_map_sz, efi_setup_data_offset)
505  If ret Then Go to out_free_params
509  ldata = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
510  If Not ldata Then
511  ret = -ENOMEM
512  Go to out_free_params
520  Temporary buffer to hold bootparams buffer. This should be* freed once the bootparam segment has been loaded. = params
521  Return ldata
523  out_free_params :
524  free previously allocated memory
525  Return ERR_PTR(ret)