blob: 49ed49b81e97999c81c095b0c12f765eb23fe532 [file] [log] [blame]
Igor Grinbergf4a40f02014-11-03 11:32:20 +02001/*
2 * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il>
3 *
4 * Authors: Igor Grinberg <grinberg@compulab.co.il>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <nand.h>
11#include <bmp_layout.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15#ifdef CONFIG_CMD_NAND
16static int splash_load_from_nand(u32 bmp_load_addr, int nand_offset)
17{
18 struct bmp_header *bmp_hdr;
19 int res;
20 size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
21
22 if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
23 goto splash_address_too_high;
24
25 res = nand_read_skip_bad(&nand_info[nand_curr_device],
26 nand_offset, &bmp_header_size,
27 NULL, nand_info[nand_curr_device].size,
28 (u_char *)bmp_load_addr);
29 if (res < 0)
30 return res;
31
32 bmp_hdr = (struct bmp_header *)bmp_load_addr;
33 bmp_size = le32_to_cpu(bmp_hdr->file_size);
34
35 if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
36 goto splash_address_too_high;
37
38 return nand_read_skip_bad(&nand_info[nand_curr_device],
39 nand_offset, &bmp_size,
40 NULL, nand_info[nand_curr_device].size,
41 (u_char *)bmp_load_addr);
42
43splash_address_too_high:
44 printf("Error: splashimage address too high. Data overwrites U-Boot "
45 "and/or placed beyond DRAM boundaries.\n");
46
47 return -1;
48}
49#else
50static inline int splash_load_from_nand(u32 bmp_load_addr, int nand_offset)
51{
52 return -1;
53}
54#endif /* CONFIG_CMD_NAND */
55
56int cl_splash_screen_prepare(int nand_offset)
57{
58 char *env_splashimage_value;
59 u32 bmp_load_addr;
60
61 env_splashimage_value = getenv("splashimage");
62 if (env_splashimage_value == NULL)
63 return -1;
64
65 bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16);
66 if (bmp_load_addr == 0) {
67 printf("Error: bad splashimage address specified\n");
68 return -1;
69 }
70
71 return splash_load_from_nand(bmp_load_addr, nand_offset);
72}