spl_mmc_load.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <common.h>
  19. #include <mmc.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. static void mmc_load_image(struct mmc *mmc)
  22. {
  23. s32 err;
  24. void (*uboot)(void) __noreturn;
  25. err = mmc->block_dev.block_read(0, CONFIG_SYS_MMC_U_BOOT_OFFS,
  26. CONFIG_SYS_MMC_U_BOOT_SIZE/512,
  27. (u32 *)CONFIG_SYS_TEXT_BASE);
  28. if (err <= 0) {
  29. printf("spl: error reading image %s, err - %d\n",
  30. "u-boot.img", err);
  31. hang();
  32. }
  33. uboot = (void *) CONFIG_SYS_TEXT_BASE;
  34. (*uboot)();
  35. }
  36. void spl_mmc_load(void)
  37. {
  38. struct mmc *mmc;
  39. int err;
  40. void (mmc_load_image)(struct mmc *mmc) __noreturn;
  41. mmc_initialize(gd->bd);
  42. mmc = find_mmc_device(0);
  43. if (!mmc) {
  44. puts("spl: mmc device not found!!\n");
  45. hang();
  46. } else {
  47. puts("spl: mmc device found\n");
  48. }
  49. err = mmc_init(mmc);
  50. if (err) {
  51. printf("spl: mmc init failed: err - %d\n", err);
  52. hang();
  53. }
  54. mmc_load_image(mmc);
  55. }