1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2020 Fuzhou Rockchip Electronics Co., Ltd
4 */
5
6 #include <common.h>
7 #include <linux/list.h>
8 #include <asm/arch/spl_resource_img.h>
9
spl_resource_image_check_header(const struct resource_img_hdr * hdr)10 int spl_resource_image_check_header(const struct resource_img_hdr *hdr)
11 {
12 int ret;
13
14 ret = memcmp(RESOURCE_MAGIC, hdr->magic, RESOURCE_MAGIC_SIZE);
15 if (ret) {
16 debug("bad resource image magic: %s\n",
17 hdr->magic ? hdr->magic : "none");
18 ret = -EINVAL;
19 }
20
21 debug("resource image header:\n");
22 debug("magic:%s\n", hdr->magic);
23 debug("version:%d\n", hdr->version);
24 debug("c_version:%d\n", hdr->c_version);
25 debug("blks:%d\n", hdr->blks);
26 debug("c_offset:%d\n", hdr->c_offset);
27 debug("e_blks:%d\n", hdr->e_blks);
28 debug("e_num:%d\n", hdr->e_nums);
29
30 return ret;
31 }
32
spl_resource_image_get_dtb_entry(const struct resource_img_hdr * hdr)33 struct resource_entry *spl_resource_image_get_dtb_entry(const struct
34 resource_img_hdr *hdr)
35 {
36 int i;
37 struct resource_entry *entry = NULL;
38
39 if (!hdr)
40 return NULL;
41
42 for (i = 0; i < hdr->e_nums; i++) {
43 entry = (struct resource_entry *)((char *)hdr
44 + (hdr->blks + hdr->e_blks * i) * 512);
45 if (!memcmp(entry->name, DEFAULT_DTB_FILE, strlen(DEFAULT_DTB_FILE)))
46 break;
47 }
48
49 return entry;
50 }
51