blob: 33b2f9f570bab1a4fe021be18b69009a43100972 [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>
Nikita Kiryanov6947e3f2015-01-14 10:42:49 +020011#include <errno.h>
Igor Grinbergf4a40f02014-11-03 11:32:20 +020012#include <bmp_layout.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16#ifdef CONFIG_CMD_NAND
17static int splash_load_from_nand(u32 bmp_load_addr, int nand_offset)
18{
19 struct bmp_header *bmp_hdr;
20 int res;
21 size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
22
23 if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
24 goto splash_address_too_high;
25
26 res = nand_read_skip_bad(&nand_info[nand_curr_device],
27 nand_offset, &bmp_header_size,
28 NULL, nand_info[nand_curr_device].size,
29 (u_char *)bmp_load_addr);
30 if (res < 0)
31 return res;
32
33 bmp_hdr = (struct bmp_header *)bmp_load_addr;
34 bmp_size = le32_to_cpu(bmp_hdr->file_size);
35
36 if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
37 goto splash_address_too_high;
38
39 return nand_read_skip_bad(&nand_info[nand_curr_device],
40 nand_offset, &bmp_size,
41 NULL, nand_info[nand_curr_device].size,
42 (u_char *)bmp_load_addr);
43
44splash_address_too_high:
45 printf("Error: splashimage address too high. Data overwrites U-Boot "
46 "and/or placed beyond DRAM boundaries.\n");
47
Nikita Kiryanov6947e3f2015-01-14 10:42:49 +020048 return -EFAULT;
Igor Grinbergf4a40f02014-11-03 11:32:20 +020049}
50#else
51static inline int splash_load_from_nand(u32 bmp_load_addr, int nand_offset)
52{
Nikita Kiryanov6947e3f2015-01-14 10:42:49 +020053 return -ENOSYS;
Igor Grinbergf4a40f02014-11-03 11:32:20 +020054}
55#endif /* CONFIG_CMD_NAND */
56
57int cl_splash_screen_prepare(int nand_offset)
58{
59 char *env_splashimage_value;
60 u32 bmp_load_addr;
61
62 env_splashimage_value = getenv("splashimage");
63 if (env_splashimage_value == NULL)
Nikita Kiryanov6947e3f2015-01-14 10:42:49 +020064 return -ENOENT;
Igor Grinbergf4a40f02014-11-03 11:32:20 +020065
66 bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16);
67 if (bmp_load_addr == 0) {
68 printf("Error: bad splashimage address specified\n");
Nikita Kiryanov6947e3f2015-01-14 10:42:49 +020069 return -EFAULT;
Igor Grinbergf4a40f02014-11-03 11:32:20 +020070 }
71
72 return splash_load_from_nand(bmp_load_addr, nand_offset);
73}