1*773b5940SDan Murphy /* 2*773b5940SDan Murphy * (C) Copyright 2014 3*773b5940SDan Murphy * Texas Instruments, <www.ti.com> 4*773b5940SDan Murphy * 5*773b5940SDan Murphy * Dan Murphy <dmurphy@ti.com> 6*773b5940SDan Murphy * 7*773b5940SDan Murphy * SPDX-License-Identifier: GPL-2.0+ 8*773b5940SDan Murphy * 9*773b5940SDan Murphy * FAT Image Functions copied from spl_mmc.c 10*773b5940SDan Murphy */ 11*773b5940SDan Murphy 12*773b5940SDan Murphy #include <common.h> 13*773b5940SDan Murphy #include <spl.h> 14*773b5940SDan Murphy #include <asm/u-boot.h> 15*773b5940SDan Murphy #include <fat.h> 16*773b5940SDan Murphy #include <image.h> 17*773b5940SDan Murphy 18*773b5940SDan Murphy static int fat_registered; 19*773b5940SDan Murphy 20*773b5940SDan Murphy #ifdef CONFIG_SPL_FAT_SUPPORT 21*773b5940SDan Murphy static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) 22*773b5940SDan Murphy { 23*773b5940SDan Murphy int err = 0; 24*773b5940SDan Murphy 25*773b5940SDan Murphy if (fat_registered) 26*773b5940SDan Murphy return err; 27*773b5940SDan Murphy 28*773b5940SDan Murphy err = fat_register_device(block_dev, partition); 29*773b5940SDan Murphy if (err) { 30*773b5940SDan Murphy #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 31*773b5940SDan Murphy printf("spl: fat register err - %d\n", err); 32*773b5940SDan Murphy #endif 33*773b5940SDan Murphy hang(); 34*773b5940SDan Murphy } 35*773b5940SDan Murphy 36*773b5940SDan Murphy fat_registered = 1; 37*773b5940SDan Murphy 38*773b5940SDan Murphy return err; 39*773b5940SDan Murphy } 40*773b5940SDan Murphy 41*773b5940SDan Murphy int spl_load_image_fat(block_dev_desc_t *block_dev, 42*773b5940SDan Murphy int partition, 43*773b5940SDan Murphy const char *filename) 44*773b5940SDan Murphy { 45*773b5940SDan Murphy int err; 46*773b5940SDan Murphy struct image_header *header; 47*773b5940SDan Murphy 48*773b5940SDan Murphy err = spl_register_fat_device(block_dev, partition); 49*773b5940SDan Murphy if (err <= 0) 50*773b5940SDan Murphy goto end; 51*773b5940SDan Murphy 52*773b5940SDan Murphy header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - 53*773b5940SDan Murphy sizeof(struct image_header)); 54*773b5940SDan Murphy 55*773b5940SDan Murphy err = file_fat_read(filename, header, sizeof(struct image_header)); 56*773b5940SDan Murphy if (err <= 0) 57*773b5940SDan Murphy goto end; 58*773b5940SDan Murphy 59*773b5940SDan Murphy spl_parse_image_header(header); 60*773b5940SDan Murphy 61*773b5940SDan Murphy err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0); 62*773b5940SDan Murphy 63*773b5940SDan Murphy end: 64*773b5940SDan Murphy #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 65*773b5940SDan Murphy if (err <= 0) 66*773b5940SDan Murphy printf("spl: error reading image %s, err - %d\n", 67*773b5940SDan Murphy filename, err); 68*773b5940SDan Murphy #endif 69*773b5940SDan Murphy 70*773b5940SDan Murphy return (err <= 0); 71*773b5940SDan Murphy } 72*773b5940SDan Murphy 73*773b5940SDan Murphy #ifdef CONFIG_SPL_OS_BOOT 74*773b5940SDan Murphy int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) 75*773b5940SDan Murphy { 76*773b5940SDan Murphy int err; 77*773b5940SDan Murphy 78*773b5940SDan Murphy err = spl_register_fat_device(block_dev, partition); 79*773b5940SDan Murphy if (err <= 0) 80*773b5940SDan Murphy return -1; 81*773b5940SDan Murphy 82*773b5940SDan Murphy err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, 83*773b5940SDan Murphy (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); 84*773b5940SDan Murphy if (err <= 0) { 85*773b5940SDan Murphy #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 86*773b5940SDan Murphy printf("spl: error reading image %s, err - %d\n", 87*773b5940SDan Murphy CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); 88*773b5940SDan Murphy #endif 89*773b5940SDan Murphy return -1; 90*773b5940SDan Murphy } 91*773b5940SDan Murphy 92*773b5940SDan Murphy return spl_load_image_fat(block_dev, partition, 93*773b5940SDan Murphy CONFIG_SPL_FAT_LOAD_KERNEL_NAME); 94*773b5940SDan Murphy } 95*773b5940SDan Murphy #endif 96*773b5940SDan Murphy #endif 97