RISCV: image: Add booti support.
PATCH v2 1/2 RISCV: image: Add booti support.
This patch adds booti support for RISC-V Linux kernel. The existing bootm method will also continue to work as it is.
It depends on the following kernel patch which adds the header to the flat Image.
https://patchwork.kernel.org/patch/10913869/
Tested on HiFive Unleashed and QEMU.
--- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/image.c | 53 +++++++++++++++++++++++++++++++++++++++++ cmd/Kconfig | 2 +- cmd/booti.c | 8 +++++-- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/lib/image.c
arch/riscv/lib/Makefile +1 -0
@@ -7,6 +7,7 @@ # Rick Chen, Andes Technology Corporation <[email protected]> obj-$(CONFIG_CMD_BOOTM) += bootm.o +obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o obj-$(CONFIG_CMD_GO) += boot.o obj-y += cache.o obj-$(CONFIG_RISCV_RDTIME) += rdtime.o
arch/riscv/lib/image.c new file +53 -0
53 lines not on this page · raw message
cmd/Kconfig +1 -1
@@ -212,7 +212,7 @@ config CMD_BOOTZ config CMD_BOOTI bool "booti" - depends on ARM64 + depends on ARM64 || RISCV default y help Boot an AArch64 Linux Kernel image from memory.
cmd/booti.c +6 -2
@@ -77,7 +77,11 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])bootm_disable_interrupts (); images.os.os =IH_OS_LINUX ; +#ifdef CONFIG_RISCV_SMODE + images.os.arch =IH_ARCH_RISCV ; +#elif CONFIG_ARM64 images.os.arch =IH_ARCH_ARM64 ; +#endif ret = do_bootm_states(cmdtp, flag, argc, argv, #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK |
@@ -92,7 +96,7 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] ="[addr [initrd[:size]] [fdt]]\n" -" - boot arm64 Linux Image stored in memory\n" +" - boot arm64/riscv Linux Image stored in memory\n" "\tThe argument 'initrd' is optional and specifies the address\n" "\tof an initrd in memory. The optional parameter ':size' allows\n" "\tspecifying the size of a RAW initrd.\n"
@@ -107,5 +111,5 @@ static char booti_help_text[] =U_BOOT_CMD ( booti,CONFIG_SYS_MAXARGS ,1 , do_booti, -"boot arm64 Linux Image image from memory" , booti_help_text +"boot arm64/riscv Linux Image image from memory" , booti_help_text );
Signature · 1 line
2.21.0
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Add gz parsing logic so that booti can parse both Image and Image.gz.
--- arch/riscv/lib/image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
arch/riscv/lib/image.c +27 -1
@@ -9,6 +9,8 @@#include <common.h> #include <mapmem.h> #include <errno.h> +#include <bootm.h> +#include <malloc.h> #include <linux/sizes.h> #include <linux/stddef.h>
@@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR;/* ASCII version of "RISCV" defined in Linux kernel */ #define LINUX_RISCV_IMAGE_MAGIC 0x5643534952 +#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8bstruct linux_image_h {uint32_t code0;/* Executable code */
@@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) {struct linux_image_h *lhdr; +uint8_t *temp; +void *dest; +ulong dest_end; +int ret; +/* TODO: Is there a way to figure out length of compressed Image.gz ? +* Otherwise, set it to SYS_BOOTM_LEN which should be sufficient. +*/ +int len =CONFIG_SYS_BOOTM_LEN ; + + temp = (uint8_t *)map_sysmem (image,0 ); - lhdr = (struct linux_image_h *)map_sysmem (image,0 ); +if (*(temp) ==GZ_HEADER_0 && *(temp+1 ) ==GZ_HEADER_1 ) { +/* Need a temporary location to copy the uncompressed image */ + dest = (void *)map_sysmem (image +8 *CONFIG_SYS_BOOTM_LEN ,0 ); + ret =bootm_decomp_image (IH_COMP_GZIP ,0 , image,IH_TYPE_KERNEL , + dest, (void *)image, len, +CONFIG_SYS_BOOTM_LEN , &dest_end); +if (ret) +return ret; +/* dest_end contains the uncompressed Image size */ +memmove ((void *) image, dest, dest_end); +unmap_sysmem (dest); + } + lhdr = (struct linux_image_h *)temp;if (lhdr->magic !=LINUX_RISCV_IMAGE_MAGIC ) {puts ("Bad Linux RISCV Image magic!\n" );return -EINVAL ;
Signature · 1 line
2.21.0
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 31 lines · Atish Patra
Add gz parsing logic so that booti can parse both Image and Image.gz.
Signed-off-by Atish Patra <[email protected]>--- arch/riscv/lib/image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)arch/riscv/lib/image.c +4
-0@@ -9,6 +9,8 @@#include <common.h> #include <mapmem.h> #include <errno.h> +#include <bootm.h> +#include <malloc.h> #include <linux/sizes.h> #include <linux/stddef.h> @@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR;/* ASCII version of "RISCV" defined in Linux kernel */ #define LINUX_RISCV_IMAGE_MAGIC 0x5643534952 +#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8bstruct linux_image_h {uint32_t code0;/* Executable code */
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 45
Quoted 10 lines
arch/riscv/lib/image.c +7
-0@@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) {struct linux_image_h *lhdr; +uint8_t *temp; +void *dest; +ulong dest_end; +int ret; +/* TODO: Is there a way to figure out length of compressed Image.gz ? +* Otherwise, set it to SYS_BOOTM_LEN which should be sufficient. +*/
Presumably this is a RFC patch then ?
What happens if you have two (or more) gzip-ed files back-to-back ? Wouldn't you then decompress both ? That might lead to all kinds of problems.
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 48
Quoted 3 lines
arch/riscv/lib/image.c +3
-0+int len =CONFIG_SYS_BOOTM_LEN ; + + temp = (uint8_t *)map_sysmem (image,0 );
Is the type cast really needed ?
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 50
Quoted 2 lines
arch/riscv/lib/image.c +1
-1- lhdr = (struct linux_image_h *)map_sysmem (image,0 ); +if (*(temp) ==GZ_HEADER_0 && *(temp+1 ) ==GZ_HEADER_1 ) {
Wrap the image in some fitImage or so contained, mark the image as gzip compressed there and all this goes away.
Quoted 17 lines
arch/riscv/lib/image.c +12
-0+/* Need a temporary location to copy the uncompressed image */ + dest = (void *)map_sysmem (image +8 *CONFIG_SYS_BOOTM_LEN ,0 ); + ret =bootm_decomp_image (IH_COMP_GZIP ,0 , image,IH_TYPE_KERNEL , + dest, (void *)image, len, +CONFIG_SYS_BOOTM_LEN , &dest_end); +if (ret) +return ret; +/* dest_end contains the uncompressed Image size */ +memmove ((void *) image, dest, dest_end); +unmap_sysmem (dest); + } + lhdr = (struct linux_image_h *)temp;if (lhdr->magic !=LINUX_RISCV_IMAGE_MAGIC ) {puts ("Bad Linux RISCV Image magic!\n" );return -EINVAL ;
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 29 lines · Marek Vasut
Quoted 28 lines · Atish Patra
Add gz parsing logic so that booti can parse both Image and Image.gz.
Signed-off-by Atish Patra <[email protected]>--- arch/riscv/lib/image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)arch/riscv/lib/image.c +4
-0@@ -9,6 +9,8 @@#include <common.h> #include <mapmem.h> #include <errno.h> +#include <bootm.h> +#include <malloc.h> #include <linux/sizes.h> #include <linux/stddef.h> @@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR;/* ASCII version of "RISCV" defined in Linux kernel */ #define LINUX_RISCV_IMAGE_MAGIC 0x5643534952 +#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8b
Quoted 16 lines
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 45
Quoted 13 lines
arch/riscv/lib/image.c +7
-0struct linux_image_h {uint32_t code0;/* Executable code */ @@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) {struct linux_image_h *lhdr; +uint8_t *temp; +void *dest; +ulong dest_end; +int ret; +/* TODO: Is there a way to figure out length of compressed Image.gz ? +* Otherwise, set it to SYS_BOOTM_LEN which should be sufficient. +*/ Presumably this is a RFC patch then ?
Yeah. I am not very sure if there is a better way to determine the size. Hence the comment. I am hoping somebody here would suggest something ;).
Quoted 4 lines
What happens if you have two (or more) gzip-ed files back-to-back ? Wouldn't you then decompress both ? That might lead to all kinds of problems.
That will be catastrophic. But this was intended only for booti and the expectation was that only Image.gz must be loaded before this.
Having said that, if we can find a reliable way of figuring out the compressed file size here, we can get rid of this hack.
Quoted 6 lines
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 48
Quoted 3 lines
arch/riscv/lib/image.c +3
-0+int len =CONFIG_SYS_BOOTM_LEN ; + + temp = (uint8_t *)map_sysmem (image,0 );Is the type cast really needed ?
Just wanted to be explicit. Will remove it.
Quoted 6 lines
arch/riscv/lib/image.c int booti_setup(ulong image, ulong *relocated_addr, ulong *size, · line 50
Quoted 2 lines
arch/riscv/lib/image.c +1
-1- lhdr = (struct linux_image_h *)map_sysmem (image,0 ); +if (*(temp) ==GZ_HEADER_0 && *(temp+1 ) ==GZ_HEADER_1 ) {Wrap the image in some fitImage or so contained, mark the image as gzip compressed there and all this goes away.
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Regards,
Atish
Quoted 19 lines
Quoted 17 lines
arch/riscv/lib/image.c +12
-0+/* Need a temporary location to copy the uncompressed image */ + dest = (void *)map_sysmem (image +8 *CONFIG_SYS_BOOTM_LEN ,0 ); + ret =bootm_decomp_image (IH_COMP_GZIP ,0 , image,IH_TYPE_KERNEL , + dest, (void *)image, len, +CONFIG_SYS_BOOTM_LEN , &dest_end); +if (ret) +return ret; +/* dest_end contains the uncompressed Image size */ +memmove ((void *) image, dest, dest_end); +unmap_sysmem (dest); + } + lhdr = (struct linux_image_h *)temp;if (lhdr->magic !=LINUX_RISCV_IMAGE_MAGIC ) {puts ("Bad Linux RISCV Image magic!\n" );return -EINVAL ;
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 45 lines · Atish Patra
Quoted 35 lines · Marek Vasut
Quoted 34 lines · Atish Patra
Add gz parsing logic so that booti can parse both Image and Image.gz.
Signed-off-by Atish Patra <[email protected]>---
arch/riscv/lib/image.c| 28 +++++++++++++++++++++++++++-1 file changed, 27 insertions(+), 1 deletion(-)arch/riscv/lib/image.c +2
-0@@ -9,6 +9,8 @@ #include <common.h> #include <mapmem.h> #include <errno.h> +#include <bootm.h> +#include <malloc.h> #include <linux/sizes.h> #include <linux/stddef.h> @@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR;/* ASCII version of "RISCV" defined in Linux kernel */ #define
LINUX_RISCV_IMAGE_MAGIC0x5643534952arch/riscv/lib/image.c +2
-0+#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8bstruct
linux_image_h{
uint32_t code0; /* Executable code */arch/riscv/lib/image.c +2
-0@@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) { struct linux_image_h *lhdr; + uint8_t *temp; + void *dest;Quoted 9 lines
Quoted 6 lines
arch/riscv/lib/image.c +3
-0+ ulong dest_end; + int ret; + /* TODO: Is there a way to figure out length of compressedImage.gz ?
+ * Otherwise, set it toSYS_BOOTM_LENwhich should be sufficient. + */Presumably this is a RFC patch then ?
Quoted 2 lines
Yeah. I am not very sure if there is a better way to determine the size. Hence the comment. I am hoping somebody here would suggest something ;).
Mark the patch as RFC next time please.
Quoted 7 lines
Quoted 4 lines
What happens if you have two (or more) gzip-ed files back-to-back ? Wouldn't you then decompress both ? That might lead to all kinds of problems.
That will be catastrophic. But this was intended only for booti and the expectation was that only Image.gz must be loaded before this.
That also means it's horribly fragile.
Quoted 2 lines
Having said that, if we can find a reliable way of figuring out the compressed file size here, we can get rid of this hack.
See below
Quoted 12 lines
Quoted 6 lines
Quoted 3 lines
+ int len =
CONFIG_SYS_BOOTM_LEN;
+
+ temp = (uint8_t*)map_sysmem(image, 0);Is the type cast really needed ?
Just wanted to be explicit. Will remove it.
Quoted 3 lines
Quoted 2 lines
- lhdr = (struct
linux_image_h*)map_sysmem(image, 0); + if (*(temp) ==GZ_HEADER_0&& *(temp+1) ==GZ_HEADER_1) {
Quoted 7 lines
Quoted 3 lines
Wrap the image in some fitImage or so contained, mark the image as gzip compressed there and all this goes away.
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of very smart way of figuring out which exact compression method is used ?
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 46 lines · Marek Vasut
Quoted 45 lines · Atish Patra
Quoted 44 lines · Marek Vasut
Quoted 37 lines · Atish Patra
Add gz parsing logic so that booti can parse both Image and Image.gz.
Signed-off-by Atish Patra <[email protected]>--- arch/riscv/lib/image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)arch/riscv/lib/image.c +2
-0@@ -9,6 +9,8 @@ #include <common.h> #include <mapmem.h> #include <errno.h> +#include <bootm.h> +#include <malloc.h> #include <linux/sizes.h> #include <linux/stddef.h> @@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR;/* ASCII version of "RISCV" defined in Linux kernel */ #define
LINUX_RISCV_IMAGE_MAGIC0x5643534952arch/riscv/lib/image.c +7
-0+#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8b struct linux_image_h { uint32_t code0; /* Executable code */@@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) { struct linux_image_h *lhdr; + uint8_t *temp; + void *dest; + ulong dest_end; + int ret; + /* TODO: Is there a way to figure out length of compressedQuoted 3 lines
Image.gz ?
+ * Otherwise, set it toSYS_BOOTM_LENwhich should be sufficient. + */Presumably this is a RFC patch then ?
Quoted 5 lines
Quoted 2 lines
Yeah. I am not very sure if there is a better way to determine the size. Hence the comment. I am hoping somebody here would suggest something ;).
Mark the patch as RFC next time please.
Sure. Sorry for not marking RFC in the first time.
Quoted 31 lines
Quoted 7 lines
Quoted 4 lines
What happens if you have two (or more) gzip-ed files back-to-back ? Wouldn't you then decompress both ? That might lead to all kinds of problems.
That will be catastrophic. But this was intended only for booti and the expectation was that only Image.gz must be loaded before this.
That also means it's horribly fragile.
Quoted 2 lines
Having said that, if we can find a reliable way of figuring out the compressed file size here, we can get rid of this hack.
See below
Quoted 16 lines
Quoted 6 lines
Quoted 3 lines
+ int len =
CONFIG_SYS_BOOTM_LEN;
+
+ temp = (uint8_t*)map_sysmem(image, 0);Is the type cast really needed ?
Just wanted to be explicit. Will remove it.
Quoted 6 lines
Quoted 2 lines
- lhdr = (struct
linux_image_h*)map_sysmem(image, 0); + if (*(temp) ==GZ_HEADER_0&& *(temp+1) ==GZ_HEADER_1) {Wrap the image in some fitImage or so contained, mark the image as gzip compressed there and all this goes away.
Quoted 9 lines
Quoted 3 lines
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of very smart way of figuring out which exact compression method is used ?
Yes. Image.gz is always gunzip. So checking first two bytes is enough to confirm that it is a gz file.
The tricky part is length of the compressed file. I took another look at the gunzip implementation in U-Boot. It looks like to me that compressed header length just to parse the header correctly. It doesn't actually use the "length" to decompress. In fact, it updates the length with uncompressed bytes after the decompression.
Regards,
Atish
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of very smart way of figuring out which exact compression method is used ?
Yes. Image.gz is always gunzip. So checking first two bytes is enough to confirm that it is a gz file.
What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
Quoted 5 lines
The tricky part is length of the compressed file. I took another look at the gunzip implementation in U-Boot. It looks like to me that compressed header length just to parse the header correctly. It doesn't actually use the "length" to decompress. In fact, it updates the length with uncompressed bytes after the decompression.
That's possible.
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 13 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of very smart way of figuring out which exact compression method is used ?
Quoted 6 lines
Quoted 2 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to confirm that it is a gz file.
What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
booti command help will clearly state that it can only boot kernel from Image or Image.gz.
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n"
+ " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored in
memory\n"
(I will update the help text with Image.gz part)
Anything other than that, it will fail with following error.
"Bad Linux RISCV Image magic!"
Quoted 8 lines
Quoted 5 lines
The tricky part is length of the compressed file. I took another look at the gunzip implementation in U-Boot. It looks like to me that compressed header length just to parse the header correctly. It doesn't actually use the "length" to decompress. In fact, it updates the length with uncompressed bytes after the decompression.
That's possible.
David suggested a better idea.
1. User can supply kernel_size and we can store in environment variable.
2. If the size is empty or greater than CONFIG_SYS_BOOTM_LEN, booti fails with appropriate error message.
We will update the documents to add the additional step for Image.gz
I am fine with either approach. Any preference ?
Regards,
Atish
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 22 lines · Atish Patra
Quoted 14 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 6 lines
Quoted 2 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to confirm that it is a gz file.
What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
Quoted 8 lines
booti command help will clearly state that it can only boot kernel from Image or Image.gz.
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n"
+ " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored in memory\n"
Obvious question -- does this Image.gz stuff apply to arm64 ?
Quoted 6 lines
(I will update the help text with Image.gz part)
Anything other than that, it will fail with following error.
"Bad Linux RISCV Image magic!"
Right, so we're implementing file(1)-lite here to detect the format.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
The tricky part is length of the compressed file. I took another look at the gunzip implementation in U-Boot. It looks like to me that compressed header length just to parse the header correctly. It doesn't actually use the "length" to decompress. In fact, it updates the length with uncompressed bytes after the decompression.
Quoted 8 lines
Quoted 2 lines
That's possible.
David suggested a better idea.
1. User can supply
kernel_sizeand we can store in environment variable.
2. If the size is empty or greater thanCONFIG_SYS_BOOTM_LEN, booti fails with appropriate error message.
You can keep decompressing until you reach $bootm_len, sure .
Quoted 6 lines
We will update the documents to add the additional step for Image.gz
I am fine with either approach. Any preference ?
Regards,
Atish
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 26 lines · Marek Vasut
Quoted 25 lines · Atish Patra
Quoted 14 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
Yes. FIT image parsing can be done in that way. However, the idea was here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.
Sigh, and the image header is compressed as well, so there's no way to identify the image format, right ? And there's no decompressor, so the dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 6 lines
Quoted 2 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to confirm that it is a gz file.
What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
booti command help will clearly state that it can only boot kernel from Image or Image.gz.
Quoted 8 lines
Quoted 5 lines
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n"
+ " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored in memory\n"Obvious question -- does this Image.gz stuff apply to arm64 ?
arm64 builds Image.gz but booti for arm64 doesn't use it. I guess Image.gz can be used in FIT image for ARM64 but I am not sure which platform actually uses it.
This patch only enables support for RISC-V.
Quoted 18 lines
Quoted 6 lines
(I will update the help text with Image.gz part)
Anything other than that, it will fail with following error.
"Bad Linux RISCV Image magic!"
Right, so we're implementing file(1)-lite here to detect the format.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
The tricky part is length of the compressed file. I took another look at the gunzip implementation in U-Boot. It looks like to me that compressed header length just to parse the header correctly. It doesn't actually use the "length" to decompress. In fact, it updates the length with uncompressed bytes after the decompression.
That's possible.
Quoted 7 lines
Quoted 5 lines
David suggested a better idea.
1. User can supply
kernel_sizeand we can store in environment variable.
2. If the size is empty or greater thanCONFIG_SYS_BOOTM_LEN, booti fails with appropriate error message.You can keep decompressing until you reach $bootm_len, sure .
Decompression happens for actual uncompressed length which is encoded into the compressed file footer. So we don't have to worry about how much we decompress. But a correct file_size helps to avoid decompressing a possible corrupt compressed file.
I will update the patch as per David's suggestion.
Regards,
Atish
Quoted 9 lines
Quoted 7 lines
We will update the documents to add the additional step for Image.gz
I am fine with either approach. Any preference ?
Regards,
Atish
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 38 lines · Atish Patra
Quoted 37 lines · Marek Vasut
Quoted 35 lines · Atish Patra
Quoted 18 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
Yes. FIT image parsing can be done in that way. However, the idea was
here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.Sigh, and the image header is compressed as well, so there's no way to
identify the image format, right ? And there's no decompressor, so the
dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 7 lines
Quoted 3 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to
confirm that it is a gz file.What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
booti command help will clearly state that it can only boot kernel from Image or Image.gz.
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n"
+ " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored in memory\n"
Quoted 8 lines
Quoted 2 lines
Obvious question -- does this Image.gz stuff apply to arm64 ?
arm64 builds Image.gz but booti for arm64 doesn't use it. I guess Image.gz can be used in FIT image for ARM64 but I am not sure which platform actually uses it.
This patch only enables support for RISC-V.
Can't this be made generic ?
[...]
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 42 lines · Marek Vasut
Quoted 41 lines · Atish Patra
Quoted 39 lines · Marek Vasut
Quoted 27 lines · Atish Patra
Quoted 18 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
Yes. FIT image parsing can be done in that way. However, the idea was
here to load Image.gz directly. Image.gz is default compressed Linux kernel image format in RISC-V.Sigh, and the image header is compressed as well, so there's no way to
identify the image format, right ? And there's no decompressor, so the
dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 7 lines
Quoted 3 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to
confirm that it is a gz file.What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
Quoted 8 lines
booti command help will clearly state that it can only boot kernel from Image or Image.gz.
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n"
+ " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored in memory\n"Obvious question -- does this Image.gz stuff apply to arm64 ?
Quoted 8 lines
Quoted 5 lines
arm64 builds Image.gz but booti for arm64 doesn't use it. I guess Image.gz can be used in FIT image for ARM64 but I am not sure which platform actually uses it.
This patch only enables support for RISC-V.
Can't this be made generic ?
I think so if I just move the gzip detection and decompression code to cmd/booti.c.
I will update the v3 patch with this.
Regards,
Atish
Quoted 2 lines
[...]
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 52 lines · Atish Patra
Quoted 51 lines · Marek Vasut
Quoted 49 lines · Atish Patra
Quoted 33 lines · Marek Vasut
Quoted 32 lines · Atish Patra
Quoted 19 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Yes. FIT image parsing can be done in that way. However, the idea was
here to load Image.gz directly. Image.gz is default compressed Linux
kernel image format in RISC-V.Sigh, and the image header is compressed as well, so there's no way to
identify the image format, right ? And there's no decompressor, so the
dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 7 lines
Quoted 3 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to
confirm that it is a gz file.What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
booti command help will clearly state that it can only boot kernel from
Image or Image.gz.Quoted 9 lines
Quoted 6 lines
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n" + " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored
in memory\n"Obvious question -- does this Image.gz stuff apply to arm64 ?
arm64 builds Image.gz but booti for arm64 doesn't use it. I guess Image.gz can be used in FIT image for ARM64 but I am not sure which platform actually uses it.
This patch only enables support for RISC-V.
Quoted 7 lines
Quoted 2 lines
Can't this be made generic ?
I think so if I just move the gzip detection and decompression code to
cmd/booti.c.I will update the v3 patch with this.
Nice, thanks.
But since you're basically implementing file(1)-lite, I wonder whether there isn't similar code somewhere in u-boot already.
Signature · 2 lines
Best regards, Marek Vasut
PATCH v2 2/2 RISCV: image: Parse Image.gz support in booti.
Quoted 59 lines · Marek Vasut
Quoted 58 lines · Atish Patra
Quoted 45 lines · Marek Vasut
Quoted 44 lines · Atish Patra
Quoted 42 lines · Marek Vasut
Quoted 32 lines · Atish Patra
Quoted 19 lines · Marek Vasut
On 4/30/19 3:27 AM, Atish Patra wrote:
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Yes. FIT image parsing can be done in that way. However, the idea was
here to load Image.gz directly. Image.gz is default compressed Linux
kernel image format in RISC-V.Sigh, and the image header is compressed as well, so there's no way to
identify the image format, right ? And there's no decompressor, so the
dcompressing has to be done by bootloader, which would need some sort of
very smart way of figuring out which exact compression method is used ?Quoted 7 lines
Quoted 3 lines
Yes. Image.gz is always gunzip. So checking first two bytes is enough to
confirm that it is a gz file.What happens once people start feeding it more exotic compression methods, like LZ4 or LZO or LZMA for example ?
booti command help will clearly state that it can only boot kernel from
Image or Image.gz.Quoted 6 lines
static char booti_help_text[] =
"[addr [initrd[:size]] [fdt]]\n"
- " - boot arm64 Linux Image stored in memory\n" + " - boot arm64 Linux Image or riscv Linux Image/Image.gz stored
in memory\n"Obvious question -- does this Image.gz stuff apply to arm64 ?
Quoted 8 lines
Quoted 5 lines
arm64 builds Image.gz but booti for arm64 doesn't use it. I guess Image.gz can be used in FIT image for ARM64 but I am not sure which platform actually uses it.
This patch only enables support for RISC-V.
Can't this be made generic ?
I think so if I just move the gzip detection and decompression code to
cmd/booti.c.
Quoted 7 lines
Quoted 1 line
I will update the v3 patch with this.
Nice, thanks.
But since you're basically implementing file(1)-lite, I wonder whether there isn't similar code somewhere in u-boot already.
I was hoping to find one as well. But I couldn't. I can add a generic gz detection function(same file(1)-lite approach) to a lib/gunzip.c
Regards,
Atish