]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - board/compulab/common/splash.c
compulab: splash: refactor splash.c
[karo-tx-uboot.git] / board / compulab / common / splash.c
1 /*
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 <errno.h>
12 #include <bmp_layout.h>
13 #include "common.h"
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 #ifdef CONFIG_CMD_NAND
18 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
19 {
20         return nand_read_skip_bad(&nand_info[nand_curr_device], offset,
21                                   &read_size, NULL,
22                                   nand_info[nand_curr_device].size,
23                                   (u_char *)bmp_load_addr);
24 }
25 #else
26 static int splash_nand_read(u32 bmp_load_addr, int offset, size_t read_size)
27 {
28         debug("%s: nand support not available\n", __func__);
29         return -ENOSYS;
30 }
31 #endif
32
33 static int splash_storage_read(u32 bmp_load_addr, int offset, size_t read_size)
34 {
35         return splash_nand_read(bmp_load_addr, offset, read_size);
36 }
37
38 static int splash_load_raw(u32 bmp_load_addr, int offset)
39 {
40         struct bmp_header *bmp_hdr;
41         int res;
42         size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
43
44         if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
45                 goto splash_address_too_high;
46
47         res = splash_storage_read(bmp_load_addr, offset, bmp_header_size);
48         if (res < 0)
49                 return res;
50
51         bmp_hdr = (struct bmp_header *)bmp_load_addr;
52         bmp_size = le32_to_cpu(bmp_hdr->file_size);
53
54         if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
55                 goto splash_address_too_high;
56
57         return splash_storage_read(bmp_load_addr, offset, bmp_size);
58
59 splash_address_too_high:
60         printf("Error: splashimage address too high. Data overwrites U-Boot "
61                 "and/or placed beyond DRAM boundaries.\n");
62
63         return -EFAULT;
64 }
65
66 int cl_splash_screen_prepare(int offset)
67 {
68         char *env_splashimage_value;
69         u32 bmp_load_addr;
70
71         env_splashimage_value = getenv("splashimage");
72         if (env_splashimage_value == NULL)
73                 return -ENOENT;
74
75         bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16);
76         if (bmp_load_addr == 0) {
77                 printf("Error: bad splashimage address specified\n");
78                 return -EFAULT;
79         }
80
81         return splash_load_raw(bmp_load_addr, offset);
82 }