Blame view

common/boot_fit.c 1.54 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
2
3
4
5
6
  /*
   * (C) Copyright 2017
   * Texas Instruments, <www.ti.com>
   *
   * Franklin S Cooper Jr. <fcooper@ti.com>
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
7
8
9
10
11
12
   */
  
  #include <boot_fit.h>
  #include <common.h>
  #include <errno.h>
  #include <image.h>
b08c8c487   Masahiro Yamada   libfdt: move head...
13
  #include <linux/libfdt.h>
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
14

906a9dbbc   Jean-Jacques Hiblot   fit: use 'const' ...
15
  static int fdt_offset(const void *fit)
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
16
17
18
19
20
21
22
23
24
25
26
27
  {
  	int images, node, fdt_len, fdt_node, fdt_offset;
  	const char *fdt_name;
  
  	node = fit_find_config_node(fit);
  	if (node < 0)
  		return node;
  
  	images = fdt_path_offset(fit, FIT_IMAGES_PATH);
  	if (images < 0) {
  		debug("%s: Cannot find /images node: %d
  ", __func__, images);
160cfc4b5   Nobuhiro Iwamatsu   boot_fit: Change ...
28
  		return -EINVAL;
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  	}
  
  	fdt_name = fdt_getprop(fit, node, FIT_FDT_PROP, &fdt_len);
  	if (!fdt_name) {
  		debug("%s: Cannot find fdt name property: %d
  ",
  		      __func__, fdt_len);
  		return -EINVAL;
  	}
  
  	fdt_node = fdt_subnode_offset(fit, images, fdt_name);
  	if (fdt_node < 0) {
  		debug("%s: Cannot find fdt node '%s': %d
  ",
  		      __func__, fdt_name, fdt_node);
  		return -EINVAL;
  	}
  
  	fdt_offset = fdt_getprop_u32(fit, fdt_node, "data-offset");
  
  	if (fdt_offset == FDT_ERROR)
  		return -ENOENT;
  
  	fdt_len = fdt_getprop_u32(fit, fdt_node, "data-size");
  
  	if (fdt_len < 0)
  		return fdt_len;
  
  	return fdt_offset;
  }
906a9dbbc   Jean-Jacques Hiblot   fit: use 'const' ...
59
  void *locate_dtb_in_fit(const void *fit)
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  {
  	struct image_header *header;
  	int size;
  	int ret;
  
  	size = fdt_totalsize(fit);
  	size = (size + 3) & ~3;
  
  	header = (struct image_header *)fit;
  
  	if (image_get_magic(header) != FDT_MAGIC) {
  		debug("No FIT image appended to U-boot
  ");
  		return NULL;
  	}
  
  	ret = fdt_offset(fit);
d56b86eec   Jean-Jacques Hiblot   fit: fixed bug in...
77
  	if (ret < 0)
92926bc80   Cooper Jr., Franklin   boot_fit: Create ...
78
79
80
81
  		return NULL;
  	else
  		return (void *)fit+size+ret;
  }