fit: include uncompression into fit_image_load
RFC 1/1 fit: include uncompression into fit_image_load
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to 'fit_image_load()', all types of images can be compressed.
This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from bootm.c ('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...
There are, however, some more things to discuss:
- The max. size passed to gunzip() (etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (via CONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
- CONFIG_SYS_BOOTM_LEN is set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!
- CONFIG_SYS_BOOTM_LEN seemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?
- Some code paths (like the command 'fpga loadmk') directly use 'fit_image_get_data()'. These will have to be converted to use 'fit_image_load()' instead (which will do nothing if the subimage does not contain a load address.
- 'fit_image_load()' should probably check for subimages that have a compression set but no load address... Or should we try to malloc() here?
A long list of questions, hopefully someone will join me in discussing them :-)
---
common/bootm.c | 8 ++++---- common/image-fit.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-)
common/bootm.c +4 -4
@@ -361,6 +361,9 @@ int bootm_decomp_image(int comp, ulong load, ulong image_start, int type, {int ret =0 ; +if (!unc_len) + unc_len =CONFIG_SYS_BOOTM_LEN ; + *load_end = load;print_decomp_msg (comp, type, load == image_start);
@@ -373,10 +376,7 @@ int bootm_decomp_image(int comp, ulong load, ulong image_start, int type,case IH_COMP_NONE :if (load == image_start)break ; -if (image_len <= unc_len) -memmove_wd (load_buf, image_buf, image_len,CHUNKSZ ); -else - ret =1 ; +memmove_wd (load_buf, image_buf, image_len,CHUNKSZ );break ;#ifdef CONFIG_GZIP case IH_COMP_GZIP : {
common/image-fit.c +15 -2
@@ -23,6 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;#endif /* !USE_HOSTCC*/ #include <image.h> +#include <bootm.h> #include <bootstage.h> #include <u-boot/crc.h> #include <u-boot/md5.h>
@@ -1969,8 +1970,9 @@ int fit_image_load(bootm_headers_t *images, ulong addr, } }else if (load_op !=FIT_LOAD_OPTIONAL_NON_ZERO || load) {ulong image_start, image_end; -ulong load_end; +ulong load_end, uncomp_len;void *dst; +u8 image_comp;/* * move image data to the load address,
@@ -1986,11 +1988,22 @@ int fit_image_load(bootm_headers_t *images, ulong addr,return -EXDEV ; } +if (fit_image_get_comp (fit, noffset, &image_comp)) { +puts ("Can't get image compression!\n" ); +return -EINVAL ; + }printf (" Loading %s from 0x%08lx to 0x%08lx\n" , prop_name, data, load); dst =map_sysmem (load, len); -memmove (dst, buf, len); + ret =bootm_decomp_image (image_comp, load, image_start, + image_type, dst, (void *)buf, len,0 , + &load_end); +if (ret) { +bootstage_error (BOOTSTAGE_ID_DECOMP_IMAGE ); +return ret; + } + len = load_end - load; data = load; }bootstage_mark (bootstage_id +BOOTSTAGE_SUB_LOAD );
Signature · 1 line
2.17.1
Quoted 24 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
-CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!
-CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?
So I can at least give input on the memory map part :).
In efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).
Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Alex
Quoted 39 lines · Alexander Graf
Quoted 24 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
-CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!
-CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?So I can at least give input on the memory map part :).
Quoted 8 lines
In
efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.
Thanks for your thoughts!
Simon
Hi Simon,
Quoted 19 lines · Simon Goldschmidt
Quoted 18 lines · Alexander Graf
Quoted 14 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!
Ick
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)
Yes.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?
See lmb
Quoted 12 lines
Quoted 11 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Quoted 7 lines
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
Quoted 2 lines
Simon
Regards,
Simon
Quoted 26 lines · Simon Glass
Hi Simon,
Quoted 18 lines · Simon Goldschmidt
Quoted 17 lines · Alexander Graf
Quoted 14 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
Quoted 5 lines
We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'? That way, we know the uncompressed size...
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!Ick
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)Yes.
Why do we need an extra limit for uncompressed copy-only? Both load address and size are known from the FIT.
Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?See lmb
Quoted 10 lines
Quoted 10 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Quoted 8 lines
Quoted 7 lines
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
That didn't work for all overlap checks for me. I'll dig into it to see what's missing for me.
Simon
Hi Simon,
Quoted 35 lines · Simon Goldschmidt
Quoted 34 lines · Simon Glass
Hi Simon,
Quoted 21 lines · Simon Goldschmidt
Quoted 19 lines · Alexander Graf
Quoted 15 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Quoted 6 lines
Quoted 2 lines
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'? That way, we know the uncompressed size...
Yes. In fact I don't like the way it works at present. We have to compress the data before putting it in the FIT, since the .its file refers to the compressed data.
I think it would be better for the ,its to refer to the original file, and then mkimage do the compression as it generates the FIT. That way it knows the size of the original data, and it is simpler for people to build images, since they don't need to compress everything beforehand.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!Ick
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)Yes.
Why do we need an extra limit for uncompressed copy-only? Both load address and size are known from the FIT.
I'm not suggesting separate limit. We don't need that.
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?See lmb
Quoted 18 lines
Quoted 10 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
That didn't work for all overlap checks for me. I'll dig into it to see what's missing for me.
Sounds good.
Also off this stuff could do with more tests. Our current bootm tests do not check lmb as far as I know.
Regards,
Simon
Quoted 43 lines · Simon Glass
Hi Simon,
Quoted 27 lines · Simon Goldschmidt
Quoted 26 lines · Simon Glass
Hi Simon,
Quoted 22 lines · Simon Goldschmidt
Quoted 21 lines · Alexander Graf
Quoted 18 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...Quoted 8 lines
Quoted 5 lines
We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'? That way, we know the uncompressed size...
Yes. In fact I don't like the way it works at present. We have to compress the data before putting it in the FIT, since the .its file refers to the compressed data.
Quoted 5 lines
I think it would be better for the ,its to refer to the original file, and then mkimage do the compression as it generates the FIT. That way it knows the size of the original data, and it is simpler for people to build images, since they don't need to compress everything beforehand.
Hmm, OK, I think it should not be a problem to add this to mkimage. Only I don't know if this workflow change would be accepted by everyone or if the old style of using pre-compressed files would have to be somehow kept working?
But what would that mean for CONFIG_SYS_BOOTM_LEN? As I already wrote before, this constant is currently used to trim copy-only, too. Now if the FIT would embed "uncompressed size", would we limit that to CONFIG_SYS_BOOTM_LEN, too? I think it would then make more sense to dump this constant and rely on lmb allocation to detect overlapping. (That assumes the load address is within lmb, of course.)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!Ick
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)Yes.
Why do we need an extra limit for uncompressed copy-only? Both load address and size are known from the FIT.
I'm not suggesting separate limit. We don't need that.
But bootm_decomp_image() *does* use CONFIG_SYS_BOOTM_LEN already with IH_COMP_NONE to limit the size of an uncompressed kernel image. Is that a bug then?
I don't understand why we need this limit. It seems arbitrary to me given we only limit the size but don't know which address we limit...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Given correct lmb integration, wouldn't it make more sense to use lmb to allocate a block? Especially if we know the uncompressed size?
Simon
Quoted 40 lines
Quoted 28 lines
Quoted 28 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?See lmb
Quoted 17 lines
Quoted 10 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already, including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
That didn't work for all overlap checks for me. I'll dig into it to see what's missing for me.
Sounds good.
Also off this stuff could do with more tests. Our current bootm tests do not check lmb as far as I know.
Regards,
Simon
Hi,
Quoted 61 lines · Simon Goldschmidt
Quoted 53 lines · Simon Glass
Hi Simon,
Quoted 36 lines · Simon Goldschmidt
Quoted 34 lines · Simon Glass
Hi Simon,
Quoted 21 lines · Simon Goldschmidt
Quoted 19 lines · Alexander Graf
Quoted 15 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Quoted 7 lines
Quoted 2 lines
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'?
That way, we know the uncompressed size...Yes. In fact I don't like the way it works at present. We have to compress the data before putting it in the FIT, since the .its file refers to the compressed data.
Quoted 5 lines
I think it would be better for the ,its to refer to the original file, and then mkimage do the compression as it generates the FIT. That way it knows the size of the original data, and it is simpler for people to build images, since they don't need to compress everything beforehand.
Quoted 4 lines
Hmm, OK, I think it should not be a problem to add this to mkimage. Only I don't know if this workflow change would be accepted by everyone or if the old style of using pre-compressed files would have to be somehow kept working?
I suggest supporting the old way with a flag. Also is it possible to detect an already-compressed file and print an warning?
Quoted 7 lines
But what would that mean for
CONFIG_SYS_BOOTM_LEN? As I already wrote before, this constant is currently used to trim copy-only, too. Now if the FIT would embed "uncompressed size", would we limit that toCONFIG_SYS_BOOTM_LEN, too? I think it would then make more sense to dump this constant and rely on lmb allocation to detect overlapping. (That assumes the load address is within lmb, of course.)
Yes that should be the limit I think.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!Quoted 7 lines
Ick
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no
unzip)Yes.
Why do we need an extra limit for uncompressed copy-only? Both load address
and size are known from the FIT.
Quoted 6 lines
Quoted 1 line
I'm not suggesting separate limit. We don't need that.
But
bootm_decomp_image()*does* useCONFIG_SYS_BOOTM_LENalready withIH_COMP_NONEto limit the size of an uncompressed kernel image. Is that a bug then?
I suppose it is just that we have no information about the size of the kernel, so use this fixed limit?
Quoted 3 lines
I don't understand why we need this limit. It seems arbitrary to me given we only limit the size but don't know which address we limit...
Perhaps for security reasons, to avoid memory overflow?
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Given correct lmb integration, wouldn't it make more sense to use lmb to allocate a block? Especially if we know the uncompressed size?
Yes I think so.
Quoted 60 lines
Simon
Quoted 52 lines
Quoted 37 lines
Quoted 37 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates
itself
(and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and
sizes).
What's the point here to checkCONFIG_SYS_BOOTM_LEN? Maybe it
would
be better to keep a memory map of allowed and already used data
to
check if we're overwriting things or to get the maximum size
passed
to gunzip etc.?See lmb
Quoted 20 lines
Quoted 11 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already,
including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be
better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
That didn't work for all overlap checks for me. I'll dig into it to see what's missing for me.
Sounds good.
Also off this stuff could do with more tests. Our current bootm tests do not check lmb as far as I know.
Regards,
Simon
Regards,
Simon
Quoted 66 lines · Simon Glass
Hi,
Quoted 61 lines · Simon Goldschmidt
Quoted 58 lines · Simon Glass
Hi Simon,
Quoted 36 lines · Simon Goldschmidt
Quoted 34 lines · Simon Glass
Hi Simon,
Quoted 21 lines · Simon Goldschmidt
Quoted 19 lines · Alexander Graf
Quoted 15 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Quoted 7 lines
Quoted 2 lines
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'?
That way, we know the uncompressed size...Yes. In fact I don't like the way it works at present. We have to compress the data before putting it in the FIT, since the .its file refers to the compressed data.
I think it would be better for the ,its to refer to the original file, and then mkimage do the compression as it generates the FIT. That way it knows the size of the original data, and it is simpler for people to build images, since they don't need to compress everything beforehand.
Quoted 7 lines
Quoted 4 lines
Hmm, OK, I think it should not be a problem to add this to mkimage. Only I don't know if this workflow change would be accepted by everyone or if the old style of using pre-compressed files would have to be somehow kept working?
I suggest supporting the old way with a flag. Also is it possible to detect an already-compressed file and print an warning?
I'm working on this and have it partly running, but I had to add this ugly "#ifndef USE_HOSTCC" thing to many files in lib/ to get the compression algorithms to compile for the tools.
Is this acceptable? Or should we find a more generic approach, i.e. fixing the central include files (common.h, etc.) to handle USE_HOSTCC?
Simon
Quoted 121 lines
Quoted 8 lines
But what would that mean for
CONFIG_SYS_BOOTM_LEN? As I already wrote before, this constant is currently used to trim copy-only, too. Now if the FIT would embed "uncompressed size", would we limit that toCONFIG_SYS_BOOTM_LEN, too? I think it would then make more sense to dump this constant and rely on lmb allocation to detect overlapping. (That assumes the load address is within lmb, of course.)Yes that should be the limit I think.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!Quoted 7 lines
Ick
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no
unzip)Yes.
Why do we need an extra limit for uncompressed copy-only? Both load address
and size are known from the FIT.Quoted 6 lines
Quoted 1 line
I'm not suggesting separate limit. We don't need that.
But
bootm_decomp_image()*does* useCONFIG_SYS_BOOTM_LENalready withIH_COMP_NONEto limit the size of an uncompressed kernel image. Is that a bug then?I suppose it is just that we have no information about the size of the kernel, so use this fixed limit?
Quoted 3 lines
I don't understand why we need this limit. It seems arbitrary to me given we only limit the size but don't know which address we limit...
Perhaps for security reasons, to avoid memory overflow?
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Given correct lmb integration, wouldn't it make more sense to use lmb to allocate a block? Especially if we know the uncompressed size?
Yes I think so.
Quoted 60 lines
Simon
Quoted 52 lines
Quoted 37 lines
Quoted 37 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates
itself
(and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and
sizes).
What's the point here to checkCONFIG_SYS_BOOTM_LEN? Maybe it
would
be better to keep a memory map of allowed and already used data
to
check if we're overwriting things or to get the maximum size
passed
to gunzip etc.?See lmb
Quoted 20 lines
Quoted 11 lines
So I can at least give input on the memory map part :).
In
efi_loader, we actually do maintain a full system memory map already,
including allocation functions that give you "safe" allocation functionality (allocate somewhere in memory where you know nothing overlaps).Maybe we should move this into a more generic system and reuse it for big memory allocations that really don't need to be in the U-Boot preallocated regions?
Hmm, inspecting this further, it seems that there is such an allocator for bootm (using lmb_*() functions and struct lmb). Maybe this should be
better integrated into the fit loading function. I don't know if the lmb functions
correctly detect overlapping of regions allocated by known addresses though.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks for your thoughts!
Yes lmb is the right mechanism and I think it checks for overlap.
That didn't work for all overlap checks for me. I'll dig into it to see what's missing for me.
Sounds good.
Also off this stuff could do with more tests. Our current bootm tests do not check lmb as far as I know.
Regards,
SimonRegards,
Simon
Hi Simon,
Quoted 76 lines · Simon Goldschmidt
Quoted 66 lines · Simon Glass
Hi,
Quoted 61 lines · Simon Goldschmidt
Quoted 58 lines · Simon Glass
Hi Simon,
Quoted 36 lines · Simon Goldschmidt
Quoted 34 lines · Simon Glass
Hi Simon,
Quoted 21 lines · Simon Goldschmidt
Quoted 19 lines · Alexander Graf
Quoted 15 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Quoted 7 lines
Quoted 2 lines
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
OK, we could embed this information into the FIT by extracting in 'mkimage'?
That way, we know the uncompressed size...Yes. In fact I don't like the way it works at present. We have to compress the data before putting it in the FIT, since the .its file refers to the compressed data.
I think it would be better for the ,its to refer to the original file, and then mkimage do the compression as it generates the FIT. That way it knows the size of the original data, and it is simpler for people to build images, since they don't need to compress everything beforehand.
Quoted 7 lines
Quoted 4 lines
Hmm, OK, I think it should not be a problem to add this to mkimage. Only I don't know if this workflow change would be accepted by everyone or if the old style of using pre-compressed files would have to be somehow kept working?
I suggest supporting the old way with a flag. Also is it possible to detect an already-compressed file and print an warning?
Quoted 7 lines
I'm working on this and have it partly running, but I had to add this ugly "#ifndef
USE_HOSTCC" thing to many files inlib/to get the compression algorithms to compile for the tools.Is this acceptable? Or should we find a more generic approach, i.e. fixing the central include files (
common.h, etc.) to handleUSE_HOSTCC?
What sort of things don't build? It's not great, but it may be necessary.
Bonus points if the #ifdefs can be just in a header file, like mkimage.h
Regards,
Simon
Hi Simon,
Quoted 14 lines · Simon Goldschmidt
Currently, only the kernel can be compressed in a FIT image. By moving the uncompression logic to '
fit_image_load()', all types of images can be compressed.This works perfectly for me when using a gzip'ed FPGA image in a FIT image on a cyclone5 board (socrates). Also, a gzip'ed initrd being unzipped by U-Boot (not the kernel) worked.
To clean this up, the uncompression function would have to be moved from
bootm.c('bootm_decomp_image()') to a more generic location, but I decided to keep it for now to make the patch easier to read. Because of this setup, the kernel is currently uncompressed twice. which doesn't work...
Quoted 4 lines
There are, however, some more things to discuss:
- The max. size passed togunzip()(etc.) is not known before, so we currently configure this to 8 MByte in U-Boot (viaCONFIG_SYS_BOOTM_LEN), which proved too small for my initrd...
We need the uncompressed size. If the legacy header doesn't have, stop using it and use FIT?
Some compression formats include that in a header I think. But we should record it in the U-Boot header.
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENis set to 64 MByte default in SPL, so it's a different default for SPL than for U-Boot !?!
Ick
Quoted 2 lines
-
CONFIG_SYS_BOOTM_LENseemed to initially be used for kernel uncompression but is now used as a copy-only limit, too (no unzip)
Yes
Quoted 2 lines
- Uncompression only works if a load address is given, what should happen if the FIT image does not contain a load address?
Fail.
Quoted 8 lines
- The whole memory management around FIT images is a bit messed up in that memory allocation is a mix of where U-Boot relocates itself (and which address ranges it used), the load addresses of the FIT image and the load addresses of the FIT image contents (and sizes). What's the point here to check
CONFIG_SYS_BOOTM_LEN? Maybe it would be better to keep a memory map of allowed and already used data to check if we're overwriting things or to get the maximum size passed to gunzip etc.?
lmb is the mechanism for this and I think it checks for overlap.
Quoted 4 lines
- Some code paths (like the command 'fpga loadmk') directly use '
fit_image_get_data()'. These will have to be converted to use 'fit_image_load()' instead (which will do nothing if the subimage does not contain a load address.
OK
Quoted 3 lines
- '
fit_image_load()' should probably check for subimages that have a compression set but no load address... Or should we try tomalloc()here?
malloc() is generally small. Best to use lmb.
Quoted 3 lines
A long list of questions, hopefully someone will join me in discussing them :-)
I think FIT provides a better format. We should be able to do the right thing in all cases I believe.
Quoted 7 lines
Signed-off-by Simon Goldschmidt <[email protected]>---
common/bootm.c | 8 ++++---- common/image-fit.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-)
Regards,
Simon