kexec.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (C) 2016 Imagination Technologies
  3. * Author: Marcin Nowakowski <marcin.nowakowski@mips.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/kexec.h>
  11. #include <linux/libfdt.h>
  12. #include <linux/uaccess.h>
  13. static int generic_kexec_prepare(struct kimage *image)
  14. {
  15. int i;
  16. for (i = 0; i < image->nr_segments; i++) {
  17. struct fdt_header fdt;
  18. if (image->segment[i].memsz <= sizeof(fdt))
  19. continue;
  20. if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt)))
  21. continue;
  22. if (fdt_check_header(&fdt))
  23. continue;
  24. kexec_args[0] = -2;
  25. kexec_args[1] = (unsigned long)
  26. phys_to_virt((unsigned long)image->segment[i].mem);
  27. break;
  28. }
  29. return 0;
  30. }
  31. static int __init register_generic_kexec(void)
  32. {
  33. _machine_kexec_prepare = generic_kexec_prepare;
  34. return 0;
  35. }
  36. arch_initcall(register_generic_kexec);