spl_ubi.c 2.3 KB

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