blob: 7f00fc88850998ead78b91e8b82e87d1906ef8c9 [file] [log] [blame]
Stefan Roesec1108172020-04-21 09:28:41 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Stefan Roese <sr@denx.de>
4 */
5
6#include <common.h>
7#include <spl.h>
8
9int spl_parse_legacy_header(struct spl_image_info *spl_image,
10 const struct image_header *header)
11{
12 u32 header_size = sizeof(struct image_header);
13
Stefan Roesec1108172020-04-21 09:28:41 +020014 /* check uImage header CRC */
Stefan Roese5ae526b2020-04-21 09:28:42 +020015 if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK) &&
16 !image_check_hcrc(header)) {
Stefan Roesec1108172020-04-21 09:28:41 +020017 puts("SPL: Image header CRC check failed!\n");
18 return -EINVAL;
19 }
Stefan Roesec1108172020-04-21 09:28:41 +020020
21 if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
22 /*
23 * On some system (e.g. powerpc), the load-address and
24 * entry-point is located at address 0. We can't load
25 * to 0-0x40. So skip header in this case.
26 */
27 spl_image->load_addr = image_get_load(header);
28 spl_image->entry_point = image_get_ep(header);
29 spl_image->size = image_get_data_size(header);
30 } else {
31 spl_image->entry_point = image_get_ep(header);
32 /* Load including the header */
33 spl_image->load_addr = image_get_load(header) -
34 header_size;
35 spl_image->size = image_get_data_size(header) +
36 header_size;
37 }
38
39#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
40 /* store uImage data length and CRC to check later */
41 spl_image->dcrc_data = image_get_load(header);
42 spl_image->dcrc_length = image_get_data_size(header);
43 spl_image->dcrc = image_get_dcrc(header);
44#endif
45
46 spl_image->os = image_get_os(header);
47 spl_image->name = image_get_name(header);
48 debug(SPL_TPL_PROMPT
49 "payload image: %32s load addr: 0x%lx size: %d\n",
50 spl_image->name, spl_image->load_addr, spl_image->size);
51
52 return 0;
53}
Stefan Roese2fc91ed2020-04-21 09:28:43 +020054
55int spl_load_legacy_img(struct spl_image_info *spl_image,
56 struct spl_load_info *load, ulong header)
57{
58 struct image_header hdr;
59 int ret;
60
61 /* Read header into local struct */
62 load->read(load, header, sizeof(hdr), &hdr);
63
64 ret = spl_parse_image_header(spl_image, &hdr);
65 if (ret)
66 return ret;
67
68 /* Read image */
69 load->read(load, header + sizeof(hdr), spl_image->size,
70 (void *)(unsigned long)spl_image->load_addr);
71
72 return 0;
73}