Stefan Roese | c110817 | 2020-04-21 09:28:41 +0200 | [diff] [blame] | 1 | // 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 | |
| 9 | int 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 Roese | c110817 | 2020-04-21 09:28:41 +0200 | [diff] [blame] | 14 | /* check uImage header CRC */ |
Stefan Roese | 5ae526b | 2020-04-21 09:28:42 +0200 | [diff] [blame^] | 15 | if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK) && |
| 16 | !image_check_hcrc(header)) { |
Stefan Roese | c110817 | 2020-04-21 09:28:41 +0200 | [diff] [blame] | 17 | puts("SPL: Image header CRC check failed!\n"); |
| 18 | return -EINVAL; |
| 19 | } |
Stefan Roese | c110817 | 2020-04-21 09:28:41 +0200 | [diff] [blame] | 20 | |
| 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 | } |