Commit 5fd13d973613d308663f97b51059ecd9179baf09

Authored by York Sun
1 parent 7264f2928b

spl: fit: Support both external and embedded data

SPL supports U-Boot image in FIT format which has data outside of
FIT structure. This adds support for embedded data for normal FIT
images.

Signed-off-by: York Sun <york.sun@nxp.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 37 additions and 19 deletions Side-by-side Diff

common/spl/spl_fit.c
... ... @@ -132,14 +132,16 @@
132 132 void *fit, ulong base_offset, int node,
133 133 struct spl_image_info *image_info)
134 134 {
135   - ulong offset;
  135 + int offset;
136 136 size_t length;
  137 + int len;
137 138 ulong load_addr, load_ptr;
138 139 void *src;
139 140 ulong overhead;
140 141 int nr_sectors;
141 142 int align_len = ARCH_DMA_MINALIGN - 1;
142 143 uint8_t image_comp = -1, type = -1;
  144 + const void *data;
143 145  
144 146 if (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP)) {
145 147 if (fit_image_get_comp(fit, node, &image_comp))
146 148  
147 149  
148 150  
149 151  
... ... @@ -153,28 +155,40 @@
153 155 debug("%s ", genimg_get_type_name(type));
154 156 }
155 157  
156   - offset = fdt_getprop_u32(fit, node, "data-offset");
157   - if (offset == FDT_ERROR)
158   - return -ENOENT;
159   - offset += base_offset;
160   - length = fdt_getprop_u32(fit, node, "data-size");
161   - if (length == FDT_ERROR)
162   - return -ENOENT;
163   - load_addr = fdt_getprop_u32(fit, node, "load");
164   - if (load_addr == FDT_ERROR && image_info)
  158 + if (fit_image_get_load(fit, node, &load_addr))
165 159 load_addr = image_info->load_addr;
166   - load_ptr = (load_addr + align_len) & ~align_len;
167 160  
168   - overhead = get_aligned_image_overhead(info, offset);
169   - nr_sectors = get_aligned_image_size(info, length, offset);
  161 + if (!fit_image_get_data_offset(fit, node, &offset)) {
  162 + /* External data */
  163 + offset += base_offset;
  164 + if (fit_image_get_data_size(fit, node, &len))
  165 + return -ENOENT;
170 166  
171   - if (info->read(info, sector + get_aligned_image_offset(info, offset),
172   - nr_sectors, (void*)load_ptr) != nr_sectors)
173   - return -EIO;
174   - debug("image dst=%lx, offset=%lx, size=%lx\n", load_ptr, offset,
175   - (unsigned long)length);
  167 + load_ptr = (load_addr + align_len) & ~align_len;
  168 + length = len;
176 169  
177   - src = (void *)load_ptr + overhead;
  170 + overhead = get_aligned_image_overhead(info, offset);
  171 + nr_sectors = get_aligned_image_size(info, length, offset);
  172 +
  173 + if (info->read(info,
  174 + sector + get_aligned_image_offset(info, offset),
  175 + nr_sectors, (void *)load_ptr) != nr_sectors)
  176 + return -EIO;
  177 +
  178 + debug("External data: dst=%lx, offset=%x, size=%lx\n",
  179 + load_ptr, offset, (unsigned long)length);
  180 + src = (void *)load_ptr + overhead;
  181 + } else {
  182 + /* Embedded data */
  183 + if (fit_image_get_data(fit, node, &data, &length)) {
  184 + puts("Cannot get image data/size\n");
  185 + return -ENOENT;
  186 + }
  187 + debug("Embedded data: dst=%lx, size=%lx\n", load_addr,
  188 + (unsigned long)length);
  189 + src = (void *)data;
  190 + }
  191 +
178 192 #ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
179 193 board_fit_image_post_process(&src, &length);
180 194 #endif
doc/uImage.FIT/source_file_format.txt
... ... @@ -288,6 +288,10 @@
288 288 defines an absolute position or address as the offset. This is helpful when
289 289 booting U-Boot proper before performing relocation.
290 290  
  291 +Normal kernel FIT image has data embedded within FIT structure. U-Boot image
  292 +for SPL boot has external data. Existence of 'data-offset' can be used to
  293 +identify which format is used.
  294 +
291 295 9) Examples
292 296 -----------
293 297