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