blob: 33f3587e3b3de56f9945fec7cb731d1a655194c4 [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
14#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
15 /* check uImage header CRC */
16 if (!image_check_hcrc(header)) {
17 puts("SPL: Image header CRC check failed!\n");
18 return -EINVAL;
19 }
20#endif
21
22 if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
23 /*
24 * On some system (e.g. powerpc), the load-address and
25 * entry-point is located at address 0. We can't load
26 * to 0-0x40. So skip header in this case.
27 */
28 spl_image->load_addr = image_get_load(header);
29 spl_image->entry_point = image_get_ep(header);
30 spl_image->size = image_get_data_size(header);
31 } else {
32 spl_image->entry_point = image_get_ep(header);
33 /* Load including the header */
34 spl_image->load_addr = image_get_load(header) -
35 header_size;
36 spl_image->size = image_get_data_size(header) +
37 header_size;
38 }
39
40#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
41 /* store uImage data length and CRC to check later */
42 spl_image->dcrc_data = image_get_load(header);
43 spl_image->dcrc_length = image_get_data_size(header);
44 spl_image->dcrc = image_get_dcrc(header);
45#endif
46
47 spl_image->os = image_get_os(header);
48 spl_image->name = image_get_name(header);
49 debug(SPL_TPL_PROMPT
50 "payload image: %32s load addr: 0x%lx size: %d\n",
51 spl_image->name, spl_image->load_addr, spl_image->size);
52
53 return 0;
54}