Skip to contentSkip to conversation

genimage raw partition from multiple files

Buildroot Michał Łyszczek 2 participants 5 messages Aug 2, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

I've been trying to figure out, how to create raw partition, without filesystem, from 2 or more files. Here is a general idea

partition uboot {
    partition-type = 0xa2
    size = 1M

    image spl {
        image = "u-boot-spl.bin.crc"
	size = 64k
        offset = 0
    }

    image uboot-real {
        image = "u-boot.bin"
        offset = 256k
    }
}

Note that spl is 64k big, and uboot-real must be at offset 256k. Also this *MUST* be a partition of type 0xa2. Can such thing be done fully in genimage without post-install script?

Signature · 10 lines
Best Regards
?yszczek Micha?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170802/a449bafb/attachment.asc>
#1 lore raw

W dniu 02.08.2017 o 15:55, Micha? ?yszczek pisze:

Quoted 23 lines

Hi,

I've been trying to figure out, how to create raw partition, without filesystem, from 2 or more files. Here is a general idea

partition uboot {
    partition-type = 0xa2
    size = 1M

    image spl {
        image = "u-boot-spl.bin.crc"
	size = 64k
        offset = 0
    }

    image uboot-real {
        image = "u-boot.bin"
        offset = 256k
    }
}
Quoted 4 lines

Note that spl is 64k big, and uboot-real must be at offset 256k. Also this *MUST* be a partition of type 0xa2. Can such thing be done fully in genimage without post-install script?

Ok, after messing with source code a little bit a found a way to do what I want. Let's say want to create partition of type 0xA2 for uboot. That partition should contain spl image and full uboot. First create image of that partition - this image will be built from "subpartitions"

image uboot.img {
        hdimage {
                partition-table = "no"
        }

        partition spl {
                in-partition-table = "no"
                image = "u-boot-spl.bin.crc"
                offset = 0
                size = 64k
        }

        partition uboot-full {
                in-partition-table = "no"
                image = "u-boot.img"
                offset = 256k
        }

        size = 1M
}

2 things are very important here, first is "partition-table = "no"" in hdimage, this will tell hdimage not add ANYTHING from itself, so no partition table, no dos magic (55 aa), no mbr at all. All partitions should also have "in-partition-table = "no"" to prevent any additional bytes from genimage.

When image is created like that it can be normally added into partition table

image sdcard.img {
        hdimage {
        }

        partition uboot-env {
                in-partition-table = "no"
                image = "uboot-env.bin"
                offset = 17408 # 512 * 34 -> just after gpt
        }

        partition uboot {
                partition-type = 0xa2
                image = "uboot.img"
        }
 	partition rootfs {
                partition-type = 0x83
                image = "rootfs.ext2"
                size = 500M
        }
}

And that's all, image will generate as expected. This may look like hack, but it is quite clean solution I think. We can avoid any scripts to create such partition for bootloader, and everything is in one place.

Signature · 10 lines
Best Regards
?yszczek Micha?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170802/7d79a146/attachment.asc>
#2 lore raw

Hello,

Quoted 65 lines · Micha? ?yszczek
Quoted 4 lines

Note that spl is 64k big, and uboot-real must be at offset 256k. Also this *MUST* be a partition of type 0xa2. Can such thing be done fully in genimage without post-install script?

Ok, after messing with source code a little bit a found a way to do what I want. Let's say want to create partition of type 0xA2 for uboot. That partition should contain spl image and full uboot. First create image of that partition - this image will be built from "subpartitions"

image uboot.img {
        hdimage {
                partition-table = "no"
        }

        partition spl {
                in-partition-table = "no"
                image = "u-boot-spl.bin.crc"
                offset = 0
                size = 64k
        }

        partition uboot-full {
                in-partition-table = "no"
                image = "u-boot.img"
                offset = 256k
        }

        size = 1M
}

2 things are very important here, first is "partition-table = "no"" in hdimage, this will tell hdimage not add ANYTHING from itself, so no partition table, no dos magic (55 aa), no mbr at all. All partitions should also have "in-partition-table = "no"" to prevent any additional bytes from genimage.

When image is created like that it can be normally added into partition table

image sdcard.img {
        hdimage {
        }

        partition uboot-env {
                in-partition-table = "no"
                image = "uboot-env.bin"
                offset = 17408 # 512 * 34 -> just after gpt
        }

        partition uboot {
                partition-type = 0xa2
                image = "uboot.img"
        }
 	partition rootfs {
                partition-type = 0x83
                image = "rootfs.ext2"
                size = 500M
        }
}
Quoted 3 lines

And that's all, image will generate as expected. This may look like hack, but it is quite clean solution I think. We can avoid any scripts to create such partition for bootloader, and everything is in one place.

And those two snippets of genimage configuration can be in a single genimage.cfg, and both uboot.img and then sdcard.img will be produced by a single genimage invocation ? Or do we need a first genimage invocation to generate uboot.img, and then a second genimage invocation to generate sdcard.img (which requires uboot.img) ?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

W dniu 02.08.2017 o 19:55, Thomas Petazzoni pisze:

Quoted 79 lines

Hello,

Quoted 65 lines · Micha? ?yszczek
Quoted 4 lines

Note that spl is 64k big, and uboot-real must be at offset 256k. Also this *MUST* be a partition of type 0xa2. Can such thing be done fully in genimage without post-install script?

Ok, after messing with source code a little bit a found a way to do what I want. Let's say want to create partition of type 0xA2 for uboot. That partition should contain spl image and full uboot. First create image of that partition - this image will be built from "subpartitions"

image uboot.img {
        hdimage {
                partition-table = "no"
        }

        partition spl {
                in-partition-table = "no"
                image = "u-boot-spl.bin.crc"
                offset = 0
                size = 64k
        }

        partition uboot-full {
                in-partition-table = "no"
                image = "u-boot.img"
                offset = 256k
        }

        size = 1M
}

2 things are very important here, first is "partition-table = "no"" in hdimage, this will tell hdimage not add ANYTHING from itself, so no partition table, no dos magic (55 aa), no mbr at all. All partitions should also have "in-partition-table = "no"" to prevent any additional bytes from genimage.

When image is created like that it can be normally added into partition table

image sdcard.img {
        hdimage {
        }

        partition uboot-env {
                in-partition-table = "no"
                image = "uboot-env.bin"
                offset = 17408 # 512 * 34 -> just after gpt
        }

        partition uboot {
                partition-type = 0xa2
                image = "uboot.img"
        }
 	partition rootfs {
                partition-type = 0x83
                image = "rootfs.ext2"
                size = 500M
        }
}
Quoted 3 lines

And that's all, image will generate as expected. This may look like hack, but it is quite clean solution I think. We can avoid any scripts to create such partition for bootloader, and everything is in one place.

And those two snippets of genimage configuration can be in a single genimage.cfg, and both uboot.img and then sdcard.img will be produced by a single genimage invocation ? Or do we need a first genimage invocation to generate uboot.img, and then a second genimage invocation to generate sdcard.img (which requires uboot.img) ?

Quoted 4 lines

Thanks!

Thomas

Only one invocation of genimage.sh is needed to generate working sdcard.img. Yes! It's that simple! I attach full genimage.cfg I created for my port for cyclone5. This genimage.cfg creates fully working sdcard.img (including uboot.img), and only external script used is support/script/genimage.sh -c genimage.cfg.

Signature · 68 lines
Best Regards
?yszczek Micha?
-------------- next part --------------
image boot.vfat {
	vfat {
		files = {
			"zImage",
			"socfpga_cyclone5_socrates.dtb"
		}
	}
	size = 8M
}

image uboot.img {
	hdimage {
		partition-table = "no"
	}

	partition spl {
		in-partition-table = "no"
		image = "u-boot-spl.bin.crc"
		offset = 0
		size = 64k
	}

	partition uboot-full {
		in-partition-table = "no"
		image = "u-boot.img"
		offset = 256k
	}

	size = 1M
}

image sdcard.img {
	hdimage {
	}

	partition uboot-env {
		in-partition-table = "no"
		image = "uboot-env.bin"
		offset = 17408 # 512 * 34 -> just after gpt
	}

	partition boot {
		partition-type = 0xc
		bootable = "true"
		image = "boot.vfat"
	}

	partition uboot {
		partition-type = 0xa2
		image = "uboot.img"
	}

	partition rootfs {
		partition-type = 0x83
		image = "rootfs.ext2"
		size = 500M
	}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170802/616f0fc6/attachment.asc>
#4 lore raw

Hello,

Quoted 11 lines · Micha? ?yszczek
Quoted 5 lines

And those two snippets of genimage configuration can be in a single genimage.cfg, and both uboot.img and then sdcard.img will be produced by a single genimage invocation ? Or do we need a first genimage invocation to generate uboot.img, and then a second genimage invocation to generate sdcard.img (which requires uboot.img) ?

Only one invocation of genimage.sh is needed to generate working sdcard.img. Yes! It's that simple! I attach full genimage.cfg I created for my port for cyclone5. This genimage.cfg creates fully working sdcard.img (including uboot.img), and only external script used is support/script/genimage.sh -c genimage.cfg.

Excellent! So I guess you can send a new version of your patch!

Also, don't hesitate to contribute to genimage to improve its documentation.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com