spl_ubi.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2016
  3. * Ladislav Michl <ladis@linux-mips.org>
  4. *
  5. * SPDX-License-Identifier: GPL 2.0+ BSD-3-Clause
  6. */
  7. #include <common.h>
  8. #include <config.h>
  9. #include <nand.h>
  10. #include <onenand_uboot.h>
  11. #include <ubispl.h>
  12. #include <spl.h>
  13. int spl_ubi_load_image(struct spl_image_info *spl_image,
  14. struct spl_boot_device *bootdev)
  15. {
  16. struct image_header *header;
  17. struct ubispl_info info;
  18. struct ubispl_load volumes[2];
  19. int ret = 1;
  20. switch (bootdev->boot_device) {
  21. #ifdef CONFIG_SPL_NAND_SUPPORT
  22. case BOOT_DEVICE_NAND:
  23. nand_init();
  24. info.read = nand_spl_read_block;
  25. info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
  26. break;
  27. #endif
  28. #ifdef CONFIG_SPL_ONENAND_SUPPORT
  29. case BOOT_DEVICE_ONENAND:
  30. info.read = onenand_spl_read_block;
  31. info.peb_size = CONFIG_SYS_ONENAND_BLOCK_SIZE;
  32. break;
  33. #endif
  34. default:
  35. goto out;
  36. }
  37. info.ubi = (struct ubi_scan_info *)CONFIG_SPL_UBI_INFO_ADDR;
  38. info.fastmap = 1;
  39. info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
  40. info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
  41. info.leb_start = CONFIG_SPL_UBI_LEB_START;
  42. info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
  43. #ifdef CONFIG_SPL_OS_BOOT
  44. if (!spl_start_uboot()) {
  45. volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
  46. volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
  47. volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
  48. volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
  49. ret = ubispl_load_volumes(&info, volumes, 2);
  50. if (!ret) {
  51. header = (struct image_header *)volumes[0].load_addr;
  52. spl_parse_image_header(spl_image, header);
  53. puts("Linux loaded.\n");
  54. goto out;
  55. }
  56. puts("Loading Linux failed, falling back to U-Boot.\n");
  57. }
  58. #endif
  59. header = (struct image_header *)
  60. (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
  61. volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
  62. volumes[0].load_addr = (void *)header;
  63. ret = ubispl_load_volumes(&info, volumes, 1);
  64. if (!ret)
  65. spl_parse_image_header(spl_image, header);
  66. out:
  67. #ifdef CONFIG_SPL_NAND_SUPPORT
  68. if (bootdev->boot_device == BOOT_DEVICE_NAND)
  69. nand_deselect();
  70. #endif
  71. return ret;
  72. }
  73. /* Use priorty 0 so that Ubi will override NAND and ONENAND methods */
  74. SPL_LOAD_IMAGE_METHOD("NAND", 0, BOOT_DEVICE_NAND, spl_ubi_load_image);
  75. SPL_LOAD_IMAGE_METHOD("OneNAND", 0, BOOT_DEVICE_ONENAND, spl_ubi_load_image);