Giter Site home page Giter Site logo

pengutronix / genimage Goto Github PK

View Code? Open in Web Editor NEW
291.0 17.0 107.0 566 KB

tool to generate multiple filesystem and flash images from a tree

License: GNU General Public License v2.0

Shell 17.87% C 74.00% Makefile 1.51% M4 6.62%
filesystems disk-image embedded-linux

genimage's Introduction

Genimage - The Image Creation Tool

genimage is a tool to generate multiple filesystem and flash/disk images from a given root filesystem tree. genimage is intended to be run in a fakeroot environment. It also supports creating flash/disk images out of different file-system images and files.

Configuration is done in a config file parsed by libconfuse. Options like the path to tools can be given via environment variables, the config file or from commandline switches.

The Configuration File

The config file of genimage uses a simple configuration language, provided by libconfuse. This supports nested sections, as well as simple key-value pairs.

Single-line comments can be introduced with # or //, multi-line comments look like /* … */ (as in C).

The config file is separated into the main sections image, flash and config, and provides an include primitive.

The image section

An image section describes a single filesystem or disk image to be built. It can be given multiple times to generate multiple images. An image can also have multiple partitions which refer to images themselves. Each image must have a type which can have different suboptions depending on the type.

Let's have a look at an example:

image nand-pcm038.img {
    flash {
    }
    flashtype = "nand-64M-512"
    partition barebox {
        image = "barebox-pcm038.bin"
        size = 512K
    }
    partition root {
        image = "root-nand.jffs2"
        size = 24M
    }
}

This would generate a nand-pcm038.img which is a flash of type "nand-64M-512" The image contains two partitions, "barebox-pcm038.bin" and "root-nand.jffs2" which must refer to images described elsewhere in the config file. For example "root-nand.jffs2" partition could be described like this:

image root-nand.jffs2 {
    name = "root"
    jffs2 {}
    size = 24M
    mountpoint = "/"
}

In this case a single jffs2 image is generated from the root mountpoint.

Here are all options for images:

name

The name of this image. This is used for some image types to set the name of the image.

size

Size of this image in bytes. 'k', 'M' or 'G' can be used as suffix to specify the size in multiple of 1024 etc. The suffix 's' specifies a multiple of the (traditional) sector size of 512. If the image if filled from a mountpoint then '%' as suffix indicates a percentage. '200%' means the resulting filesystem should be about 50% filled. Note that is is only a rough estimate based on the original size of the content.

mountpoint

mountpoint if image refers to a filesystem image. The default is "/". The content of "${rootpath}${mountpoint}" will be used to fill the filesystem.

srcpath

If this is set, specified path will be directly used to fill the filesystem. Ignoring rootpath/mountpoint logic. Path might be absolute or relative to current working directory.

empty

If this is set to true, then the specified rootpath and mountpoint are ignored for this image and an empty filesystem is created. This option is only used for writeable filesystem types, such as extX, vfat, ubifs and jffs2. This defaults to false.

temporary

If this is set to true, the image is created in tmppath rather than outputpath. This can be useful for intermediate images defined in the configuration file which are not needed by themselves after the main image is created. This defaults to false.

exec-pre

Custom command to run before generating the image.

exec-post

Custom command to run after generating the image.

flashtype

refers to a flash section. Optional for non flash like images like hd images

partition

can be given multiple times and refers to a partition described below

Additionally each image can have one of the following sections describing the type of the image:

cpio, cramfs, ext2, ext3, ext4, file, flash, hdimage, iso, jffs2, qemu, squashfs, tar, ubi, ubifs, vfat.

Partition options:

offset

The offset of this partition as a total offset to the beginning of the device.

size

The size of this partition in bytes. If the size and autoresize are both not set then the size of the partition image is used.

align

Alignment value to use for automatic computation of offset and size. Defaults to 1 for partitions not in the partition table, otherwise to the image's align value.

partition-type

Used by dos partition tables to specify the partition type.

image

The image file this partition shall be filled with

fill

Boolean specifying that all bytes of the partition should be explicitly initialized. Any bytes beyond the size of the specified image will be set to 0.

autoresize

Boolean specifying that the partition should be resized automatically. For UBI volumes this means that the autoresize flag is set. Only one volume can have this flag. For hd images this can be used for the last partition. If set the partition will fill the remaining space of the image.

bootable

Boolean specifying whether to set the bootable flag.

in-partition-table

Boolean specifying whether to include this partition in the partition table. Defaults to true.

partition-uuid

UUID string used by GPT partition tables to specify the partition id. Defaults to a random value.

partition-type-uuid

String used by GPT partition tables to specify the partition type. Either a UUID or a shortcut:

  • L, linux, linux-generic: Linux filesystem (0fc63daf-8483-4772-8e79-3d69d8477de4)
  • S, swap: Swap (0657fd6d-a4ab-43c4-84e5-0933c84b4f4f)
  • H, home: Home (933ac7e1-2eb4-4f13-b844-0e14e2aef915)
  • U, esp, uefi: EFI System Partition (c12a7328-f81f-11d2-ba4b-00a0c93ec93b)
  • R, raid: Linux RAID (a19d880f-05fc-4d3b-a006-743f0f84911e)
  • V, lvm: Linux LVM (e6d6d379-f507-44c2-a23c-238f2a3df928)
  • F, fat32: FAT32 / Basic Data Partition (ebd0a0a2-b9e5-4433-87c0-68b6b72699c7)
  • barebox-state (previously B): Barebox State (4778ed65-bf42-45fa-9c5b-287a1dc4aab1)
  • barebox-env: Barebox Environment (6c3737f2-07f8-45d1-ad45-15d260aab24d)

    Furthermore, for {arch} being one of alpha, arc, arm, arm64, ia64, loongarch64, mips, mips64, mips-le, mips64-le, parisc, ppc, ppc64, ppc64-le, riscv32, riscv64, s390, s390x, tilegx, x86, x86-64, the following shortcuts from the Discoverable Partitions Specification are accepted (see the spec for the respective UUIDs):

    • root-{arch}: Root Partition
    • usr-{arch}: /usr Partition
    • root-{arch}-verity: Root Verity Partition
    • usr-{arch}-verity: /usr Verity Partition
    • root-{arch}-verity-sig: Root Verity Signature Partition
    • usr-{arch}-verity-sig: /usr Verity Signature Partition
    • xbootldr: Extended Boot Loader Partition
    • srv: Server Data Partition
    • var: Variable Data Partition
    • tmp: Temporary Data Partition
    • user-home: Per-user Home Partition

Defaults to L.

For each partition, its final alignment, offset and size are determined as follows:

  • If the align option is not present, it defaults to the value of the image's align option if the partition is in the partition table, otherwise to 1.
  • If the offset option is absent or zero, and in-partition-table is true, the partition is placed after the end of all previously defined partitions, with the final offset rounded up to the partition's align value.
  • Otherwise, the offset option is used as-is. Note that if absent, that option defaults to 0, so in practice one must specify an offset for any partition that is not in the partition table (with at most one exception, e.g. a bootloader).
  • If the partition has the autoresize flag set, its size is computed as the space remaining in the image from its offset (for a GPT image, space is reserved at the end for the backup GPT table), rounded down to the partition's align value. If the partition also has a size option, it is ensured that the computed value is not less than that size.
  • Otherwise, if the size option is present and non-zero, its value is used as-is.
  • Otherwise, if the partition has an image option, the size of that image, rounded up to the partition's align value, is used to determine the size of the partition.

The following sanity checks are done on these final values (in many cases, these will automatically be satisfied when the value has been determined via one of the above rules rather than given explicitly):

  • For a partition in the partition table, the partition's align value must be greater than or equal to the image's align value.
  • The partition's offset and size must both be multiples of its align.
  • The size must not be 0.
  • The partition must not overlap any other partition, or the areas occupied by the partition table.

The image configuration options

android-sparse

Generate android sparse images. They are typically used by fastboot. Sparse images encode "don't care" areas and areas that are filled with a single 32 bit value. As a result, they are often much smaller than raw disk images. Genimage assumes that all 'holes' in the input file are "don't care" areas. This is a reasonable assumption: Tools to generate filesystems typically operate on devices. So they only create holes in areas they don't care about. Genimage itself operates the same way when generating HD images.

Options:

image

The source image that will be converted.

block-size

The granularity that the sparse image uses to find "don't care" or "fill" blocks. The supported block sizes depend on the user. The default is 4k.

cpio

Generates cpio images.

Options:

format

archive format. Passed to the -H option to the cpio command. Valid options are bin, odc, newc, crc, tar, ustar, hpbin and hpodc

extraargs

Extra arguments passed to the cpio tool

compress

If given, pipe image through compression tool. Valid options are for example gzip, lzop or any other tool that compresses from stdin to stdout.

cramfs

Generates cramfs images.

Options:

extraargs

Extra arguments passed to mkcramfs

ext2, ext3, ext4

Generates ext* images.

Options:

use-mke2fs

If set to true, then mke2fs is used to create the image. Otherwise, genext2fs is used. Defaults to false.

mke2fs-conf

mke2fs.conf that should be used. If unspecified, the system default is used.

extraargs

Extra arguments passed to genext2fs or mke2fs.

features

Filesystem features. Passed to the -O option of tune2fs. This is a comma separated list of enabled or disabled features. See man ext4 for features. For genext2fs all feature are specified. Default for ext3 images is has_journal. Default for ext4 images is extents,uninit_bg,dir_index,has_journal. For mke2fs these features are added in addition to the default features of the ext type. Already enabled features can be disabled by prefixing the feature with ^.

label

Specify the volume-label. Passed to the -L option of tune2fs

fs-timestamp

Sets different timestamps in the image. Sets the given timestamp using the debugfs commands set_current_time, set_super_value mkfs_time and set_super_value lastcheck

root-owner

User and group IDs for the root directory. Defaults to 0:0. Only valid with mke2fs.

usage-type

Specify the usage type for the filesystem. Only valid with mke2fs. More details can be found in the mke2fs man-page.

file

This represents a pre-existing image which will be used as-is. When a partition section references an image that is not defined elsewhere in the configuration file, a file rule is implicitly generated. It is up to the user to ensure that the image exists in the input directory, or to use an absolute path to the image.

It is possible to add a file image explicitly, which allows one to provide genimage with some information about the image which can not be deduced automatically. Currently, one such option exists:

holes

A list of "(<start>;<end>)" pairs specifying ranges of the file that do not contain meaningful data, and which can therefore be allowed to overlap other partitions or image metadata.

For example:

image foo {
    hdimage {
        partition-table-type = "gpt"
        gpt-location = 64K
    }

    partition bootloader {
        in-partition-table = false
        offset = 0
        image = "/path/to/bootloader.img"
    }

    partition rootfs {
        offset = 1M
        image = "rootfs.ext4"
    }
}

image /path/to/bootloader.img {
    file {
        holes = {"(440; 1K)", "(64K; 80K)"}
    }
}

This tells genimage that despite the bootloader partition overlapping both the last 72 bytes of the MBR (where the DOS partition table is located) and the GPT header occupying the sector starting at offset 512, this is all OK because bootloader.img does not contain useful data in that range. Further, in this example, the bootloader image has been carefully crafted to also allow placing the GPT array at offset 64K (the GPT header is always at offset 512).

If the bootloader image is not declared explicitly and only used once then the holes can also be configured in the partition. This simplifies the config file for simple use-cases.

For example:

image bar {
    hdimage {}

    partition bootloader {
        in-partition-table = false
        offset = 0
        image = "/path/to/bootloader.img"
        holes = {"(440; 512)"}
    }

    partition rootfs {
        offset = 1M
        image = "rootfs.ext4"
    }
}

FIT

Generates U-Boot FIT images.

Options:

its

String option holding the path of the input its file

keydir

String option holding the directory containing the keys used for signing.

flash

Generates flash images. These are basically the partition contents padded to the partition sizes concatenated together. There is no partition table. Needs a valid flashtype where the flash parameters are read from.

hdimage

Generates DOS partition images.

Options:

align

Partition alignment. Defaults to 512 bytes

partition-table

Boolean. If true, writes a partition table. If false, no partition table is generated. Defaults to true. Deprecated: use partition-table-type instead.

partition-table-type

Define what kind of partition table should be used. Valid options are: * none: No partition table at all. In this case, the in-partition-table option for each partition is ignored. * mbr: Legacy DOS/MBR partition table * gpt: GUID Partition Table * hybrid: A hybrid MBR/GPT partition table. Partitions with an explicit partition-type will be placed in in the MBR table. At most 3 such partitions are allowed. This limit does not effect the maximum number of GPT partition entries in the same image.

extended-partition

Number of the extended partition. Contains the number of the extended partition between 1 and 4 or 0 for automatic. Defaults to 0.

disk-signature

32 bit integer used as disk signature (offset 440 in the MBR). Using a special value random will result in using random 32 bit number.

gpt

Boolean. If true, a GPT type partition table is written. If false a DOS type partition table is written. Defaults to false. Deprecated: use partition-table-type instead.

gpt-location

Location of the GPT table. Occasionally useful for moving the GPT table away from where a bootloader is placed due to hardware requirements. All partitions in the table must begin after this table. Regardless of this setting, the GPT header will still be placed at 512 bytes (sector 1). Defaults to 1024 bytes (sector 2).

gpt-no-backup

Boolean. If true, then the backup partition table at the end of the image is not written.

disk-uuid

UUID string used as disk id in GPT partitioning. Defaults to a random value.

fill

If this is set to true, then the image file will be filled up to the end of the last partition. This might make the file bigger. This is necessary if the image will be processed by such tools as libvirt, libguestfs or parted.

iso

Generates an ISO image.

Options:

boot-image

Path to the El Torito boot image. Passed to the -b option of genisofs

bootargs

Bootargs for the El Torito boot image. Defaults to -no-emul-boot -boot-load-size 4 -boot-info-table -c boot.cat -hide boot.cat

extraargs

Extra arguments passed to genisofs

input-charset

The input charset. Passed to the -input-charset option of genisofs. Defaults to default

volume-id

Volume ID. Passed to the -V option of genisofs

jffs2

Generates a JFFS image. Needs a valid flashtype where the flash parameters are read from.

Options:

extraargs

Extra arguments passed to mkfs.jffs2

qemu

Generates a QEMU image. Needs at least one valid partition.

Options:

format

A valid qemu-img like qcow, qcow2, parallels, vdi, vhdx or vmdk. Check qemu-img convert --help for the complete list of possible values. Defaults to qcow2.

extraargs

Extra arguments passed to qemu-img convert

squashfs

Generates a squashfs image.

Options:

extraargs

Extra arguments passed to mksquashfs

compression

compression type for the image. Possible values are gzip (default), lzo, xz or none

block-size

Block size. Passed to the -b option of mksquashfs. Defaults to 4096.

rauc

Generates a RAUC update bundle.

Options:

extraargs

Extra arguments passed to RAUC

file

Specify a file to be added into the RAUC bundle. Usage is: file foo { image = "bar" } which adds a file "foo" in the RAUC bundle from then input file "bar"

files

A list of filenames added into the RAUC bundle. Like file above, but without the ability to add the files under different name.

key

Path to the key file or PKCS#11 URI. Passed to the --key option of RAUC

cert

Path to the certificate file or PKCS#11 URI. Passed to the --cert option of RAUC

keyring

Optional path to the keyring file. Passed to the --keyring option of RAUC

manifest

content of the manifest file

tar

Generates a tar image. The image will be compressed as defined by the filename suffix.

ubi

Generates an UBI image. Needs a valid flashtype where the flash parameters are read from.

Options:

extraargs

Extra arguments passed to ubinize

ubifs

Generates a UBIFS image. Needs a valid flashtype where the flash parameters are read from.

Options:

extraargs

Extra arguments passed to mkubifs

max-size

Maximum size of the UBIFS image

space-fixup

Instructs the file-system free space to be freed up on first mount.

vfat

Generates a VFAT image.

Options:

extraargs

Extra arguments passed to mkdosfs

label

Specify the volume-label. Passed to the -n option of mkdosfs

file

Specify a file to be added into the filesystem image. Usage is: file foo { image = "bar" } which adds a file "foo" in the filesystem image from the input file "bar"

files

A list of filenames added into the filesystem image. Like file above, but without the ability to add the files under different name.

Note: If no content is specified with file or files then rootpath and mountpoint are used to provide the content.

fip

Generates a Firmware Image Package (FIP). A format used to bundle firmware to be loaded by ARM Trusted Firmware.

Options:

extraargs

Extra arguments passed to fiptool

fw-config

Firmware Configuration (device tree), usually provided by BL2 (Trusted Firmware)

nt-fw

Non-Trusted Firmware (BL33)

hw-config

Hardware Configuration (device tree), passed to BL33

tos-fw

Trusted OS (BL32) binaries. Second and third binary are used as extra1 and extra2 binaries if specified. Example: tos-fw = {"tee-header_v2.bin", "tee-pager_v2.bin", "tee-pageable_v2.bin"}

scp-fwu-cfg

SCP Firmware Updater Configuration FWU SCP_BL2U

ap-fwu-cfg

AP Firmware Updater Configuration BL2U

fwu

Firmware Updater NS_BL2U

fwu-cert

Non-Trusted Firmware Updater certificate

tb-fw

Trusted Boot Firmware BL2

scp-fw

SCP Firmware SCP_BL2

soc-fw

EL3 Runtime Firmware BL31

tb-fw-config

TB_FW_CONFIG

soc-fw-config

SOC_FW_CONFIG

tos-fw-config

TOS_FW_CONFIG

nt-fw-config

NT_FW_CONFIG

rot-cert

Root Of Trust key certificate

trusted-key-cert

Trusted key certificate

scp-fw-key-cert

SCP Firmware key certificate

soc-fw-key-cert

SoC Firmware key certificate

tos-fw-key-cert

Trusted OS Firmware key certificate

nt-fw-key-cert

Non-Trusted Firmware key certificate

tb-fw-cert

Trusted Boot Firmware BL2 certificate

scp-fw-cert

SCP Firmware content certificate

soc-fw-cert

SoC Firmware content certificate

tos-fw-cert

Trusted OS Firmware content certificate

nt-fw-cert

Non-Trusted Firmware content certificate

sip-sp-cert

SiP owned Secure Partition content certificate

plat-sp-cert

Platform owned Secure Partition content certificate

The Flash Section

The flash section can be given multiple times and each section describes a flash chip. The option names are mostly derived from the UBI terminology. There are the following options:

pebsize

The size of a physical eraseblock in bytes

lebsize

The size of a logical eraseblock in bytes (for ubifs)

numpebs

Number of physical eraseblocks on this device. The total size of the device is determined by pebsize * numpebs

minimum-io-unit-size

The minimum size in bytes accessible on this device

vid-header-offset

offset of the volume identifier header

sub-page-size

The size of a sub page in bytes.

Several flash related image types need a valid flash section. From the image types the flash type section is referred to using the flashtype option which contains the name of the flash type to be used.

For more information of the meaning of these values see the ubi(fs) and mtd FAQs:

http://www.linux-mtd.infradead.org/faq/general.html

Example flash section:

flash nand-64M-512 {
    pebsize = 16384
    lebsize = 15360
    numpebs = 4096
    minimum-io-unit-size = 512
    vid-header-offset = 512
    sub-page-size = 512
}
...
image jffs2 {
    flashtype = "nand-64M-512"
}

The config section

In this section the global behaviour of the program is described. Except as noted below, all options here can be given from either environment variables, the config file or command line switches. For instance, a config option foo can be passed as a --foo command line switch or as a GENIMAGE_FOO environment variable.

config

default: genimage.cfg Path to the genimage config file.

loglevel

default: 1 genimage log level.

outputpath

default: images Mandatory path where all images are written to (must exist).

inputpath

default: input This mandatory path is searched for input images, for example bootloader binaries, kernel images (must exist).

rootpath

default: root Mandatory path to the root filesystem (must exist).

tmppath

default: tmp Optional path to a temporary directory. There must be enough space available here to hold a copy of the root filesystem.

includepath

Colon-separated list of directories to search for files included via the include function. The current directory is searched after these. Thus, if this option is not given, only the current directory is searched. This has no effect when given in the config file.

configdump

File to write the final configuration to. This includes the results of all include directives, expansions of environment variables and application of default values - think gcc -E. Use - for stdout.

cpio

path to the cpio program (default cpio)

dd

path to the dd program (default dd)

e2fsck

path to the e2fsck program (default e2fsck)

genext2fs

path to the genext2fs program (default genext2fs)

genisoimage

path to the genisoimage program (default genisoimage)

mcopy

path to the mcopy program (default mcopy)

mmd

path to the mmd program (default mmd)

mkcramfs

path to the mkcramfs program (default mkcramfs)

mkdosfs

path to the mkdosfs program (default mkdosfs)

mkfsjffs2

path to the mkfs.jffs2 program (default mkfs.jffs2)

mkfsubifs

path to the mkfs.ubifs program (default mkfs.ubifs)

mksquashfs

path to the mksquashfs program (default mksquashfs)

qemu-img

path to the qemu-img program (default qemu-img)

tar

path to the tar program (default tar)

tune2fs

path to the tune2fs program (default tune2fs)

ubinize

path to the ubinize program (default ubinize)

fiptool

path to the fiptool utility (default fiptool)

Include Configurations Fragments

To include a "foo.cfg" config file, use the following statement:

include("foo.cfg")

This allows to re-use, for example flash configuration files, across different image configurations.

License and Developing

To contribute to genimage please prepare a pull request on Github. To make it possible to include your modifications it's required that your code additions are licensed under the same terms as genimage itself. So you are required to agree to the following document:

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

  1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
  2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
  3. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
  4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

Your agreement is expressed by adding a sign-off line to each of your commits (e.g. using git commit -s) looking as follows:

Signed-off-by: Random J Developer <[email protected]>

with your identity and email address matching the commit meta data.

genimage's People

Contributors

a3f avatar bastian-krause avatar ee-smuxel avatar ejoerns avatar gportay avatar harvie avatar jacmet avatar jbeptx avatar jetomit avatar jluebbe avatar kimonhoffmann avatar leojrfs avatar lynxeye-dev avatar marckleinebudde avatar mgrzeschik avatar michaelolbrich avatar mniestroj avatar onkelulla avatar osterlad avatar pasrom avatar pseiderer avatar rohieb avatar saschahauer avatar ssorensen avatar sudipm-mukherjee avatar texierp avatar thirtythreeforty avatar tobleminer avatar tpetazzoni avatar vivien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

genimage's Issues

"size = 0" gives error "hdimage(sdcard.img) part data size must not be zero"

I'm trying to create an empty FAT partition in the remaining space on an SD card.

My config file:

image boot.vfat {
  vfat {
    files = {
      "bcm2708-rpi-b-plus.dtb",
      "bcm2708-rpi-0-w.dtb",
      "rpi-firmware/bootcode.bin",
      "rpi-firmware/cmdline.txt",
      "rpi-firmware/config.txt",
      "rpi-firmware/fixup.dat",
      "rpi-firmware/start.elf",
      "zImage"
    }

    file overlays/hifiberry-dac.dtbo {
      image = "rpi-firmware/overlays/hifiberry-dac.dtbo"
    }

  }
  size = 32M
}

image sdcard.img {
  hdimage {
  }

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

  partition rootfs {
    partition-type = 0x83
    image = "rootfs.ext4"
  }

  partition data {
    partition-type = 0xC
    size = 0
  }

}

I cannot get it to accept 0 in order to use up the remaining space, giving me the error:
hdimage(sdcard.img) part data size must not be zero

I am creating this using Buildroot on an 8GB SD card, with the rootfs set to 1GB in the buildroot config.

mcopy fails with "Disk full"

Background

I'm using Buildroot to create a custom image for a Raspberry Pi Zero W. I'd like to add an extra VFAT partition that can be mounted on the root filesystem. I've run into a problem trying to do this and I suspect that it's with genimage.

Any help would be greatly appreciated!

Changes to .cfg

The following is the only change I made to the board/raspberrypi/genimage-raspberrypi0w.cfg file. I intentionally have not yet defined the partition on image sdcard.img so that I can narrow down the source of the failure.

Removing these lines allows the make command to complete successfully.

image eric.vfat {
  vfat {}
  size = 1M
}

make error: Disk full

The following shows the relevant output from running the make command. Note the Disk full error after the mcopy command.

INFO: vfat(eric.vfat): cmd: "dd if=/dev/zero of="/home/vagrant/buildroot-2019.08/output/images/eric.vfat" seek=1048576 count=0 bs=1 2>/dev/null" (stderr):
INFO: vfat(eric.vfat): cmd: "mkdosfs  '/home/vagrant/buildroot-2019.08/output/images/eric.vfat'" (stderr):
INFO: vfat(eric.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/vagrant/buildroot-2019.08/output/images/eric.vfat' '/home/vagrant/buildroot-2019.08/output/build/genimage.tmp/root'/* ::" (stderr):
Disk full
INFO: vfat(eric.vfat): cmd: "rm -f "/home/vagrant/buildroot-2019.08/output/images/eric.vfat"" (stderr):
ERROR: vfat(eric.vfat): failed to generate eric.vfat
Makefile:812: recipe for target 'target-post-image' failed
make[1]: *** [target-post-image] Error 1

Usage example for existing partition image + second partition contents

Maybe I'm missing something, but it's not clear to me how to use genimage in cases in which the image file for one partition is given and the image for a second partition should be created by genimage. In my case, I have an image file (rootfs.ext2) containing the ext3 file system for / (generated by Buildroot), and a directory containing the files that should go into /home in a separate partition.

From the documentation and examples I have read so far, I imagine it should look similar to this:

image compactflash.img {
  hdimage {
  }

  partition root {
    partition-type = 0x83
    bootable = true
    # An existing image of the partition's file system.
    image = "rootfs.ext2"
  }

  partition home {
    partition-type = 0x83
    image = "home.ext3"
    size = 1500M
  }
}

image home.ext3 {
  ext3 {
    label = "home"
  }

  name = "home"
  size = 1500M
  mountpoint = "/home"
}

Is this the proper way to do it? I understand mountpoint is relative to the configured rootpath. Where does genimage expect the file rootfs.ext2, though?

New release ?

There's at least the cool feature of GPT support in the last release, so it would be really nice to cut a new release so that GPT support is in a tagged release of genimage. Thanks!

Files and folders in ext2 partition

In vfat partition you can create folders and files in the following way:
image boot.vfat {
vfat {
files = {
"bcm2708-rpi-b-plus.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"kernel-marked/zImage"
}

file overlays/dwc2.dtbo {
  image = "rpi-firmware/overlays/dwc2.dtbo"
}

}
size = 32M
}

I want to create files and folders in ext2 partitions. How can I do it? This way is not working:
image home.ext2 {
name = "home"
ext2 {
files = {
"bcm2708-rpi-b-plus.dtb",
"rpi-firmware/bootcode.bin"
}
}
size = 128M
mountpoint = "/home"
}

How to auto fill sd card without expanding the image

I want to make the image and burn it into my sd card.
Suppose the size of the image is 20M, and of sd card is 32G.
I want to know how to make the image automatically fill the rest of the sd card without generate a 32G image.

fat filesystem not clean

I'm using genimage v14 to generate harddisk image for an embedded system.
While testing something else I notet that if I flash on my device and run fsck.fat on the fat partitions it reliably reports errors.

Here is a mininal genimage.cfg and test-script to reproduce the issue:

image uboot.img {
    size = 64M
    vfat {
        label = "uboot"
    }
    mountpoint = "uboot"
}


image broken.img {
    hdimage {
        align = 1M
        extended-partition = 2
    }

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

}
#!/bin/sh

set -x

mkdir -p root/uboot/test1
mkdir -p root/uboot/test2
echo foo > root/uboot/test2/bar

genimage

LO_DEV=$(sudo losetup --partscan --show --find images/broken.img)
sudo fsck.fat -n ${LO_DEV}p1
sudo losetup -d $LO_DEV

If I run it on my machine I get:

$ ./test.sh
+ mkdir -p root/uboot/test1
+ mkdir -p root/uboot/test2
+ echo foo
+ genimage
INFO: cmd: "mkdir -p "/home/schumb/misc/genimage_test/tmp"" (stderr):
INFO: cmd: "rm -rf "/home/schumb/misc/genimage_test/tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/schumb/misc/genimage_test/tmp"" (stderr):
INFO: cmd: "cp -a "/home/schumb/misc/genimage_test/root" "/home/schumb/misc/genimage_test/tmp/root"" (stderr):
INFO: cmd: "mv "/home/schumb/misc/genimage_test/tmp/root/uboot" "/home/schumb/misc/genimage_test/tmp/mp-uboot"" (stderr):
INFO: cmd: "mkdir "/home/schumb/misc/genimage_test/tmp/root/uboot"" (stderr):
INFO: cmd: "chmod --reference="/home/schumb/misc/genimage_test/tmp/mp-uboot" "/home/schumb/misc/genimage_test/tmp/root/uboot"" (stderr):
INFO: cmd: "chown --reference="/home/schumb/misc/genimage_test/tmp/mp-uboot" "/home/schumb/misc/genimage_test/tmp/root/uboot"" (stderr):
INFO: cmd: "find '/home/schumb/misc/genimage_test/tmp/root' -depth -type d -printf '%P\0' | xargs -0 -I {} touch -r '/home/schumb/misc/genimage_test/root/{}' '/home/schumb/misc/genimage_test/tmp/root/{}'" (stderr):
INFO: cmd: "mkdir -p "/home/schumb/misc/genimage_test/images"" (stderr):
INFO: vfat(uboot.img): cmd: "dd if=/dev/zero of="/home/schumb/misc/genimage_test/images/uboot.img" seek=67108864 count=0 bs=1 2>/dev/null" (stderr):
INFO: vfat(uboot.img): cmd: "mkdosfs  -n 'uboot' '/home/schumb/misc/genimage_test/images/uboot.img'" (stderr):
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
INFO: vfat(uboot.img): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/schumb/misc/genimage_test/images/uboot.img' '/home/schumb/misc/genimage_test/tmp/mp-uboot'/* ::" (stderr):
INFO: hdimage(broken.img): adding partition 'uboot' (in MBR) from 'uboot.img' ...
INFO: hdimage(broken.img): writing MBR
+ sudo losetup --partscan --show --find images/broken.img
+ LO_DEV=/dev/loop23
+ sudo fsck.fat -n /dev/loop23p1
fsck.fat 4.1 (2017-01-24)
/TEST1/.
  Start (0) does not point to parent (2)
/TEST2/.
  Start (0) does not point to parent (4)
Leaving filesystem unchanged.
/dev/loop23p1: 4 files, 3/32695 clusters
+ sudo losetup -d /dev/loop23

Note the fsck output:

fsck.fat 4.1 (2017-01-24)
/TEST1/.
  Start (0) does not point to parent (2)
/TEST2/.
  Start (0) does not point to parent (4)
Leaving filesystem unchanged.

It does not seem to be an actual problem in this instance.
If I mount the partition and look at the files they seem fine.

Am I doing something wrong here?
Or is it safe to ignore the errors reported by fsck?

additional infos:

  • Ubuntu 18.04.5
  • mcopy (GNU mtools) 4.0.18

VFAT: support for file names in cyrilic encoding

Hello,

I'm trying to add file to fat partition with Cyrillic latters and spaces in the file name (oh, I wouldn't do it by my customer asks )

here is the config

image boot.vfat {
	vfat {
		files = {
			"uImage",
			"boot.bin",
			"u-boot.bin"
		}

		file uboot.env {
			image = "uboot-env.bin"
		}
	}
	size = 30M
}

image update.vfat {
	vfat {
                files = {
                        "Файл с длинным русским именем.txt"
                }
	}
	size = 512M
}

image sdcard.img {
	hdimage {
	}

	partition boot {
		partition-type = 0xC
		bootable = "true"
		image = "boot.vfat"
		offset = 1M
	}

	partition update {
		partition-type = 0xC
		image = "update.vfat"
		size = 512M
	}
}

and here is what I get in the output

>>>   Executing post-image script board/econ/ikv3/post-image.sh
Config name genimage-2.6.36
--rootpath /home/rucoder/heat-meter/new_clean/buildroot/output/target
--tmppath /home/rucoder/heat-meter/new_clean/buildroot/output/build/genimage-2.6.36.tmp
--inputpath /home/rucoder/heat-meter/new_clean/buildroot/output/images
--outputpath /home/rucoder/heat-meter/new_clean/buildroot/output/images
--config board/econ/ikv3/genimage-2.6.36.cfg
file(Файл с длинным русским именем.txt): stat(/home/rucoder/heat-meter/new_clean/buildroot/output/images/Прошивка и проверка ИК 3.txt) failed: No such file or directory
vfat(update.vfat): could not setup Файл с длинным русским именем.txt
Makefile:736: recipe for target 'target-post-image' failed

New release

There are a lot of cool things sience last release. Is it possible to have a new release? So I can push this into buildroot soon. Actual I handle a lot of patches for this to run it in my own project.

Thanks for this amazing work 👍

#143 leftovers and followups

Some things off the top of my head that should/could be done at some point after #143 is merged, but which I'd rather not include in that already-way-too-long series.

  • check that no partition in the partition table lives before the GPT array (essentially redoing #125)
  • extend insert_image so it can be used as a full replacement for the few remaining uses of pad_file
  • perhaps add a check that when hd->gpt and image size is given that it's a multiple of 4K, to be consistent with the case where the image size is auto-computed to place the end of the gpt backup at a 4K boundary.
  • some code cleanups might be in order - I ended up introducing helpers like partition_end and min_ull/max_ull, and some existing code might benefit from using those.

Missing rauc keys cause segfault

Using this sample configuration:

image rauc.upd8 {
  rauc {
    files = {
      u-boot.imx,
      rootfs.ubifs,
    }

    key = private.pem
    cert = public.pem
  }
}

(note the missing manifest), genimage dereferences a null pointer on line 42 of image-rauc.c:

genimage/image-rauc.c

Lines 34 to 42 in 67a2441

char *manifest = cfg_getstr(image->imagesec, "manifest");
char *cert = cfg_getstr(image->imagesec, "cert");
char *key = cfg_getstr(image->imagesec, "key");
char *manifest_file;
image_debug(image, "manifest = '%s'\n", manifest);
xasprintf(&manifest_file, "%s/manifest.raucm", mountpath(image));
ret = insert_data(image, manifest, manifest_file, strlen(manifest), 0);

...leaving only a very confusing "Segmentation fault" error message in its wake.

make check: FAIL: test/basic-images.test 7 - mke2fs

https://github.com/pengutronix/genimage/archive/v14.tar.gz

tar xf v14.tar.gz

cd genimage-14

autoreconf --version

autoreconf (GNU Autoconf) 2.71
...
./autogen.sh
configure.ac:10: warning: The macro `AC_PROG_CC_STDC' is obsolete.
configure.ac:10: You should run autoupdate.
./lib/autoconf/c.m4:1666: AC_PROG_CC_STDC is expanded from...
configure.ac:10: the top level
configure.ac:78: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
./lib/autoconf/lang.m4:199: AC_LANG_CONFTEST is expanded from...
./lib/autoconf/general.m4:2894: _AC_LINK_IFELSE is expanded from...
./lib/autoconf/general.m4:2911: AC_LINK_IFELSE is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
m4/attributes.m4:87: CC_CHECK_LDFLAGS is expanded from...
configure.ac:78: the top level
configure.ac:79: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
./lib/autoconf/lang.m4:199: AC_LANG_CONFTEST is expanded from...
./lib/autoconf/general.m4:2894: _AC_LINK_IFELSE is expanded from...
./lib/autoconf/general.m4:2911: AC_LINK_IFELSE is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
m4/attributes.m4:87: CC_CHECK_LDFLAGS is expanded from...
configure.ac:79: the top level
configure.ac:10: installing 'build-aux/compile'
configure.ac:29: installing 'build-aux/config.guess'
configure.ac:29: installing 'build-aux/config.sub'
configure.ac:9: installing 'build-aux/install-sh'
configure.ac:9: installing 'build-aux/missing'
configure.ac:111: installing 'build-aux/tap-driver.sh'
Makefile.am: installing 'build-aux/depcomp'

----------------------------------------------------------------
Initialized build system. For a common configuration please run:
----------------------------------------------------------------

./configure CFLAGS='-g -O0' --prefix=/usr
./configure CFLAGS='-g -O0' --prefix=/usr
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to create a pax tar archive... gnutar
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for wchar.h... yes
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking whether make supports nested variables... (cached) yes
checking for memset... yes
checking for setenv... yes
checking for strdup... yes
checking for strcasecmp... yes
checking for strerror... yes
checking for strstr... yes
checking for strtoull... yes
checking for inline... inline
checking for error_at_line... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for GNU libc compatible malloc... yes
checking for size_t... yes
checking for uint32_t... yes
checking whether to enable debugging... no
checking whether to hide internal symbols... yes
checking if gcc supports -Wl,--as-needed flag... yes
checking if gcc supports -Wl,--gc-sections flag... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for CONFUSE... yes
checking whether the compiler supports -fvisibility=hidden... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands

        genimage 14
        =====

        prefix:                 /usr

        compiler:               gcc
        cflags:                 -g -O0  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden
        ldflags:                  -Wl,--as-needed -Wl,--gc-sections

        debug:                  no
        hide symbols:           yes
        libconfuse:             -lconfuse
make V=1
make --no-print-directory all-am
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-genimage.o -MD -MP -MF .deps/genimage-genimage.Tpo -c -o genimage-genimage.o `test -f 'genimage.c' || echo './'`genimage.c
mv -f .deps/genimage-genimage.Tpo .deps/genimage-genimage.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-config.o -MD -MP -MF .deps/genimage-config.Tpo -c -o genimage-config.o `test -f 'config.c' || echo './'`config.c
mv -f .deps/genimage-config.Tpo .deps/genimage-config.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-util.o -MD -MP -MF .deps/genimage-util.Tpo -c -o genimage-util.o `test -f 'util.c' || echo './'`util.c
mv -f .deps/genimage-util.Tpo .deps/genimage-util.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-crc32.o -MD -MP -MF .deps/genimage-crc32.Tpo -c -o genimage-crc32.o `test -f 'crc32.c' || echo './'`crc32.c
mv -f .deps/genimage-crc32.Tpo .deps/genimage-crc32.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-android-sparse.o -MD -MP -MF .deps/genimage-image-android-sparse.Tpo -c -o genimage-image-android-sparse.o `test -f 'image-android-sparse.c' || echo './'`image-android-sparse.c
mv -f .deps/genimage-image-android-sparse.Tpo .deps/genimage-image-android-sparse.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-cpio.o -MD -MP -MF .deps/genimage-image-cpio.Tpo -c -o genimage-image-cpio.o `test -f 'image-cpio.c' || echo './'`image-cpio.c
mv -f .deps/genimage-image-cpio.Tpo .deps/genimage-image-cpio.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-cramfs.o -MD -MP -MF .deps/genimage-image-cramfs.Tpo -c -o genimage-image-cramfs.o `test -f 'image-cramfs.c' || echo './'`image-cramfs.c
mv -f .deps/genimage-image-cramfs.Tpo .deps/genimage-image-cramfs.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-ext2.o -MD -MP -MF .deps/genimage-image-ext2.Tpo -c -o genimage-image-ext2.o `test -f 'image-ext2.c' || echo './'`image-ext2.c
mv -f .deps/genimage-image-ext2.Tpo .deps/genimage-image-ext2.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-file.o -MD -MP -MF .deps/genimage-image-file.Tpo -c -o genimage-image-file.o `test -f 'image-file.c' || echo './'`image-file.c
mv -f .deps/genimage-image-file.Tpo .deps/genimage-image-file.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-fit.o -MD -MP -MF .deps/genimage-image-fit.Tpo -c -o genimage-image-fit.o `test -f 'image-fit.c' || echo './'`image-fit.c
mv -f .deps/genimage-image-fit.Tpo .deps/genimage-image-fit.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-flash.o -MD -MP -MF .deps/genimage-image-flash.Tpo -c -o genimage-image-flash.o `test -f 'image-flash.c' || echo './'`image-flash.c
mv -f .deps/genimage-image-flash.Tpo .deps/genimage-image-flash.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-hd.o -MD -MP -MF .deps/genimage-image-hd.Tpo -c -o genimage-image-hd.o `test -f 'image-hd.c' || echo './'`image-hd.c
mv -f .deps/genimage-image-hd.Tpo .deps/genimage-image-hd.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-iso.o -MD -MP -MF .deps/genimage-image-iso.Tpo -c -o genimage-image-iso.o `test -f 'image-iso.c' || echo './'`image-iso.c
mv -f .deps/genimage-image-iso.Tpo .deps/genimage-image-iso.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-jffs2.o -MD -MP -MF .deps/genimage-image-jffs2.Tpo -c -o genimage-image-jffs2.o `test -f 'image-jffs2.c' || echo './'`image-jffs2.c
mv -f .deps/genimage-image-jffs2.Tpo .deps/genimage-image-jffs2.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-qemu.o -MD -MP -MF .deps/genimage-image-qemu.Tpo -c -o genimage-image-qemu.o `test -f 'image-qemu.c' || echo './'`image-qemu.c
mv -f .deps/genimage-image-qemu.Tpo .deps/genimage-image-qemu.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-rauc.o -MD -MP -MF .deps/genimage-image-rauc.Tpo -c -o genimage-image-rauc.o `test -f 'image-rauc.c' || echo './'`image-rauc.c
mv -f .deps/genimage-image-rauc.Tpo .deps/genimage-image-rauc.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-squashfs.o -MD -MP -MF .deps/genimage-image-squashfs.Tpo -c -o genimage-image-squashfs.o `test -f 'image-squashfs.c' || echo './'`image-squashfs.c
mv -f .deps/genimage-image-squashfs.Tpo .deps/genimage-image-squashfs.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-tar.o -MD -MP -MF .deps/genimage-image-tar.Tpo -c -o genimage-image-tar.o `test -f 'image-tar.c' || echo './'`image-tar.c
mv -f .deps/genimage-image-tar.Tpo .deps/genimage-image-tar.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-ubi.o -MD -MP -MF .deps/genimage-image-ubi.Tpo -c -o genimage-image-ubi.o `test -f 'image-ubi.c' || echo './'`image-ubi.c
mv -f .deps/genimage-image-ubi.Tpo .deps/genimage-image-ubi.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-ubifs.o -MD -MP -MF .deps/genimage-image-ubifs.Tpo -c -o genimage-image-ubifs.o `test -f 'image-ubifs.c' || echo './'`image-ubifs.c
mv -f .deps/genimage-image-ubifs.Tpo .deps/genimage-image-ubifs.Po
gcc -DHAVE_CONFIG_H -I.  -include ./config.h  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0 -MT genimage-image-vfat.o -MD -MP -MF .deps/genimage-image-vfat.Tpo -c -o genimage-image-vfat.o `test -f 'image-vfat.c' || echo './'`image-vfat.c
mv -f .deps/genimage-image-vfat.Tpo .deps/genimage-image-vfat.Po
gcc -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden  -g -O0   -o genimage genimage-genimage.o genimage-config.o genimage-util.o genimage-crc32.o genimage-image-android-sparse.o genimage-image-cpio.o genimage-image-cramfs.o genimage-image-ext2.o genimage-image-file.o genimage-image-fit.o genimage-image-flash.o genimage-image-hd.o genimage-image-iso.o genimage-image-jffs2.o genimage-image-qemu.o genimage-image-rauc.o genimage-image-squashfs.o genimage-image-tar.o genimage-image-ubi.o genimage-image-ubifs.o genimage-image-vfat.o -lconfuse

mke2fs -V

mke2fs 1.46.2 (28-Feb-2021)
  Using EXT2FS Library version 1.46.2

make V=1 check

make --no-print-directory check-TESTS
PASS: test/basic-images.test 1 - cpio
SKIP: test/basic-images.test 2 # SKIP cramfs (missing mkcramfs)
SKIP: test/basic-images.test 3 # SKIP ext2 (missing genext2fs of genext2fs,e2fsck)
SKIP: test/basic-images.test 4 # SKIP ext2percent (missing genext2fs of genext2fs,e2fsck)
SKIP: test/basic-images.test 5 # SKIP ext3 (missing genext2fs of genext2fs,e2fsck)
SKIP: test/basic-images.test 6 # SKIP ext4 (missing genext2fs of genext2fs,e2fsck)
FAIL: test/basic-images.test 7 - mke2fs
PASS: test/basic-images.test 8 - flash
PASS: test/basic-images.test 9 - hdimage
PASS: test/basic-images.test 10 - hdimage2
PASS: test/basic-images.test 11 - hdimage4
PASS: test/basic-images.test 12 - hdimage5
PASS: test/basic-images.test 13 - iso
SKIP: test/basic-images.test 14 # SKIP jffs2 (missing mkfs_jffs2)
SKIP: test/basic-images.test 15 # SKIP qemu (missing qemu-img of dd,diff,qemu-img)
PASS: test/basic-images.test 16 - squashfs
PASS: test/basic-images.test 17 - tar
SKIP: test/basic-images.test 18 # SKIP ubifs (missing mkfs_ubifs)
SKIP: test/basic-images.test 19 # SKIP ubi (missing ubinize)
PASS: test/basic-images.test 20 - vfat
SKIP: test/basic-images.test 21 # SKIP fit (missing dtc,mkimage of mkimage,dtc)
SKIP: test/basic-images.test 22 # SKIP rauc (missing rauc)
SKIP: test/basic-images.test 23 # SKIP android-sparse (missing simg2img)
PASS: test/basic-images.test 24 - exec
PASS: test/basic-images.test 25 - exec-fail
ERROR: test/basic-images.test - exited with status 1
============================================================================
Testsuite summary for genimage 14
============================================================================
# TOTAL: 26
# PASS:  12
# SKIP:  12
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 1
============================================================================
See ./test-suite.log
Please report to [email protected]
============================================================================
make[2]: *** [Makefile:1148: test-suite.log] Error 1
make[1]: *** [Makefile:1256: check-TESTS] Error 2
make: *** [Makefile:1460: check-am] Error 2

test-suite.log

Add BTRFS Support

Hi,

I want to build a project on BTRFS.
But genimage only support ext2, ext3, ext4...
Can you have possibility to add btrfs support.

Best Regards.

Fakeroot and SUID

Hi,
When I execute genimage with fakeroot the suid bits are not preserved ,but with sudo it works fine. Am I missing something here? Cause I thought fakeroot was the safest way to go. And needless to say. the root filesystem is extracted from a tar.bz2 archive (with -p and --same-owner tar options) under fakeroot . I also checked the files after exiting the fakeroot, the suid bits are all there (although with my normal user as the owner).

With fakeroot:

ls -l /bin/su
-rwxr-xr-x 1 root root 43924 May 28 14:47 /bin/su

With sudo:

ls -l /bin/su
-rwsr-xr-x 1 root root 43924 May 28 15:12 /bin/su

On the other hand ,when using the Yocto project as a normal user we get images containing files with suid bits set. So that's possible to set suid as a normal user under a fakeroot(ish?) environment.

ext4 e2fsck failed

I got this error:
UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. (i.e., without -a or -p options)
I use genimage to generate root file system. I used chroot into the file system and use apt to install some softwares. There's some softwares would cause this error.
Here's the cfg:

image boot.vfat {
  name = "boot"
	vfat {
		files = {
			"linux/zImage"
		}
	}
	size = 16M
}

image root.ext4 {
  name = "root"
	ext4 {
	  features = metadata_csum
	  #features = "extents,uninit_bg,dir_index,has_journal"
	}
	size = 600M
}


image sdcard.img {
	hdimage {
	}

	partition u-boot {
		in-partition-table = "no"
		image = "uboot/u-boot-sunxi-with-spl.bin"
		offset = 8192
		size = 2088960 # 512KB - 8192
	}

	partition boot {
		partition-type = 0xC
		bootable = "true"
		image = "boot.vfat"
	}
	
	partition rootfs {
		partition-type = 0x83
		image = "root.ext4"
		size = 0
	}
}

ERROR: hdimage(disk.img): part root size (366951937) too small for rootfs.ext2 (367001600)

I found that this tool supports the "autoresize" parameter in the configuration, and it seems that that is perfect for what I want to achieve, however, I am unable to compile an image successfully while using it.

image efi-part.vfat {
  vfat {
    file startup.nsh {
      image = "efi-part/startup.nsh"
    }
    file EFI {
      image = "efi-part/EFI"
    }
    file bzImage {
      image = "bzImage"
    }
  }
  size = 16777216
}

image disk.img {
  hdimage {
    gpt = true
  }

  partition boot {
    image = "efi-part.vfat"
    partition-type-uuid = c12a7328-f81f-11d2-ba4b-00a0c93ec93b
    offset = 32768
    size = 16777216
    bootable = true
  }

  partition root {
    partition-type-uuid = 44479540-f297-41b2-9af7-d131d5f0458a
    partition-uuid = UUID_TMP
    image = "rootfs.ext2"
    offset = 16809984

    autoresize = true
  }
size = 383778817
}

Using this configuration, I recieve the following error:
ERROR: hdimage(disk.img): part root size (366951937) too small for rootfs.ext2 (367001600)
It seems that using the autoresize option is a few MB off, am I misiterpreting it? What does the autoresize option actually do? Is it responsible for expanding the last partition when flashed?

Not generating correct output image

test.sh

#!/bin/bash
mkdir root input
mkfs.ext4 input/part1.ext4 1M
genimage genimage.cfg
du -sh --apparent-size images/*

genimage.cfg

image disk.img {

  hdimage {
  }

  partition part1 {
    bootable = "true"
    partition-type = 0x83
    image = "part1.ext4"
    size = 10M
  }

  partition part2 {
    partition-type = 0x83
    size = 20M
  }
}

Output:

mke2fs 1.44.3 (10-July-2018)
Creating regular file input/part1.ext4

Filesystem too small for a journal
Creating filesystem with 1024 1k blocks and 128 inodes

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

INFO: cmd: "mkdir -p "/home/kuldeep/Desktop/test-genimage/tmp"" (stderr):
INFO: cmd: "rm -rf "/home/kuldeep/Desktop/test-genimage/tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/kuldeep/Desktop/test-genimage/images"" (stderr):
INFO: cmd: "mkdir -p "/home/kuldeep/Desktop/test-genimage/tmp"" (stderr):
INFO: cmd: "cp -a "/home/kuldeep/Desktop/test-genimage/root" "/home/kuldeep/Desktop/test-genimage/tmp/root"" (stderr):
INFO: hdimage(disk.img): adding partition 'part1' (in MBR) from 'part1.ext4' ...
INFO: hdimage(disk.img): adding partition 'part2' (in MBR) ...
INFO: hdimage(disk.img): writing MBR
1.1M	images/disk.img

1.1M images/disk.img Shouldn't images/disk.img be 30M+?

Also, i dont think images/disk.img is a sparse file as du is given --apparent-size.

man du:

      --apparent-size
              print apparent sizes,  rather  than  disk  usage;  although  the
              apparent  size is usually smaller, it may be larger due to holes
              in ('sparse') files, internal  fragmentation,  indirect  blocks,
              and the like

Add all subfolder's files to the root of the image

Hello,

I've been trying to add everything from a folder to the root of a vfat image without success. How can I achieve this ? I'm thinking about something as simple as files { "folder/" } or files { "folder/*" } The first syntaxe creates folder in the image, the second one gives an error. This does work for subfolders (files { "folder/subfolder" } is added as subfolder).

Please note that syntax files { "folder/subfolder" } produces output adding file 'folder/subfolder' as 'folder/subfolder' ... whereas it means adding file 'folder/subfolder' as 'subfolder' ...

Using v9 genimage from Buildroot.

msdos partition table extended partitions

I'm trying to create a .img for copying to an SD card using genimage, I've included the relevant contents of my genimage.cfg file below.

The issue I'm having is that I cannot configure extended partitions properly, partition Extended should be the extended partition and config and log should be logical partitions inside that.

If I set Extended's size to 0 genimage complains about it needing to have a size > 0
If I set Extended's size to 1 it fills up the remainder of the image with an extended partition but doesn't create the config or log partitions
If I set Extended's size to anything else it complains about config overlapping with a previous partition.

Is there a correct way to deal with Extended partions in genimage or am I just going to have to work this out myself?

Thanks,

// Skutov

image sdcard.img {
  hdimage {
  }

  size = 3G

  partition boot {
    partition-type = 0x06
    in-partition-table = "yes"
    image = "boot.vfat"
    bootable = TRUE
    size = 32M
    offset = 0
  }

  partition rootfsA {
    partition-type = 0x83
    image = "rootfs.squashfs"
    size = 64M
    offset = 33M
  }

  partition rootfsB {
    partition-type = 0x83
    size = 64M
    offset = 98M
  }

  partition Extended {
    partition-type = 0x05
    offset = 163M
    size = 
  }

  partition config {
    partition-type = 0x85
    size = 32M
    offset = 165M
  }

  partition log {
    partition-type = 0x85
    size = 32M
    offset = 198M
  }
}

New Release ?

I imported in buildroot the 0001-image-vfat-Add-label-option-to-set-volume-name.patch patch (commit 516f371) from your repository.
The patch was accepted but I learned that normally they don't take feature patches.
It is a feature that someone needs, so it would be really nice to cut a new release so that this feature is in a tagged release of genimage.
Thanks

How to compile genimage on Ubuntu 18.04

Hi there and excuse me for creating a new issue for my problem as this is a question, not an issue, but just because I did not find any mailing list here to ask my question I created this.
I'm intending to use genimage on Ubuntu 18.04 but I got genimage: not found.
I tried to install it on my OS but, there was not any candidate, even I tried to compile the last release( V13) But there is no build tutorial. I tried ./configure to config the build and seems everything is OK but when I use make I got make: *** No targets specified and no makefile found. Stop.

Forgetting to specify lebsize causes div-by-zero crash in ubifs build

I mistakenly specified my flash without a lebsize:

flash w25q64 {
	pebsize = 4096
	numpebs = 2048
	minimum-io-unit-size = 1
	sub-page-size = 1
	vid-header-offset = 64
}

and tried to build an ubifs image using this definition. I get a crash:

support/scripts/genimage.sh: line 40:  6959 Floating point exception(core dumped) genimage --rootpath "${TARGET_DIR}" --tmppath "${GENIMAGE_TMP}" --inputpath "${BINARIES_DIR}" --outputpath "${BINARIES_DIR}" --config "${GENIMAGE_CFG}"

Analyzing the coredump suggests a div-by-zero problem:

Program terminated with signal SIGFPE, Arithmetic exception.
#0  0x000055f0b21195f2 in ubifs_generate (image=0x55f0b2ab4b30) at image-ubifs.c:33
33          max_leb_cnt = max_size / image->flash_type->lebsize;
(gdb) bt
#0  0x000055f0b21195f2 in ubifs_generate (image=0x55f0b2ab4b30) at image-ubifs.c:33
#1  0x000055f0b2110bb4 in image_generate (image=0x55f0b2ab4b30) at genimage.c:233
#2  0x000055f0b2110a9e in image_generate (image=0x55f0b2ab4c50) at genimage.c:219
#3  0x000055f0b2110a9e in image_generate (image=0x55f0b2ab46d0) at genimage.c:219
#4  0x000055f0b211235f in main (argc=11, argv=0x7fffccf1d1e8) at genimage.c:749

Probably, genimage should check that lebsize is specified if ubifs is expecting to use it (and give an error if not).

For what it's worth, a plain ubi image worked fine without lebsize.

rauc files {} directive does not exclude files from rootpath

When using a vfat image, I can add a files { ... } directive that overrides the mountpoint setting and only includes the specified files:

image boot.vfat {
  vfat {
    files = {
      zImage
    }
  }
}

But when I try the same thing with a rauc image, the generated bundle does not exclude rootpath files; rootfs.squashfs is alongside /bin, /etc, etc. This effectively doubles the size of the image.

image update.raucb {
  rauc {
    files = {
      rootfs.squashfs,
      boot.vfat,
    }
    manifest = "(snip)"
    key = "(snip)"
    cert = "(snip)"
  }
}

I can work around this behavior by running this configuration separate from all my other ones, and specifying an empty rootpath. But I expected files to work the same as in vfat. Is this intended behavior or a bug?

genimage 13 unable to create a disk image with more than 3 partitions with type defined

As the title suggests, it seems that genimage 13 is unable to create a valid disk image and errors out when there are more than 3 partitions with their type defined, with hdimage being gpt.

ERROR: hdimage(sdcard.img): hybrid MBR partitions (5) exceeds maximum of 3.

I have 5 partitions of type linux filesystem in my gpt partition table:

  • ssbl
  • 2x rootfs
  • rauc slot storage
  • overlayfs

For what its worth this seems to have appeared only in version 13, because with version 12 it worked fine...

Aren't there ways of making protective mbr instead of hybrid ?

Either way this sounds like either genimage is right and this is not something valid, but should be possible with protective instead of hybrid, or that genimage has now a bug when the type of the partition is defined.

Issue generating filesystem image

Hello,

I'm compiling a Linux OS via 2021.05 Buildroot and using 5.10.57 version Linux Kernel.
When it's executing post-image script board/raspberrypi4-64/post-image.sh, i have an error :
Disk full
INFO: vfat(boot.vfat): cmd: "rm -f "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat"" (stderr):
ERROR: vfat(boot.vfat): failed to generate boot.vfat
make[1]: *** [Makefile:838 : target-post-image] Erreur 1
make: *** [Makefile:23 : _all] Erreur 2

Does anybody know how to solve the problem ?

Thanks for help, have a nice day !!!

Alexandre

Executing post-image script board/raspberrypi4-64/post-image.sh
board/raspberrypi4-64/genimage-raspberrypi4-64.cfg:31: no sub-section title/index for 'config'
INFO: cmd: "mkdir -p "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp"" (stderr):
INFO: cmd: "rm -rf "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp"" (stderr):
INFO: cmd: "cp -a "/tmp/tmp.GJN41vc0Bx" "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp/root"" (stderr):
INFO: cmd: "find '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp/root' -depth -type d -printf '%P\0' | xargs -0 -I {} touch -r '/tmp/tmp.GJN41vc0Bx/{}' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/build/genimage.tmp/root/{}'" (stderr):
INFO: cmd: "mkdir -p "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images"" (stderr):
INFO: vfat(boot.vfat): cmd: "dd if=/dev/zero of="/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat" seek=33554432 count=0 bs=1 2>/dev/null" (stderr):
INFO: vfat(boot.vfat): cmd: "mkdosfs '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat'" (stderr):
INFO: vfat(boot.vfat): adding file 'bcm2711-rpi-4-b.dtb' as 'bcm2711-rpi-4-b.dtb' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/bcm2711-rpi-4-b.dtb' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'rpi-firmware/cmdline.txt' as 'rpi-firmware/cmdline.txt' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/rpi-firmware/cmdline.txt' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'rpi-firmware/config.txt' as 'rpi-firmware/config.txt' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/rpi-firmware/config.txt' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'rpi-firmware/fixup.dat' as 'rpi-firmware/fixup.dat' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/rpi-firmware/fixup.dat' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'rpi-firmware/start.elf' as 'rpi-firmware/start.elf' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/rpi-firmware/start.elf' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'rpi-firmware/overlays' as 'rpi-firmware/overlays' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/rpi-firmware/overlays' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'Image' as 'Image' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat' '/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/Image' '::'" (stderr):
Disk full
INFO: vfat(boot.vfat): cmd: "rm -f "/home/heol/stage_heol/br-lab/64bit/systemctl/build-pi4-64/images/boot.vfat"" (stderr):
ERROR: vfat(boot.vfat): failed to generate boot.vfat
make[1]: *** [Makefile:838 : target-post-image] Erreur 1
make: *** [Makefile:23 : _all] Erreur 2

add glob support

For instance, this will allow us to build images using one generic config:

image boot.vfat {
        vfat {
                files = {
                        "zImage",
                        "*.dtb",
                        "boot.scr"
                }
        }
        size = 6M
}

Also if none *.dtb were found, that should be not an error.

genimage-10: Test failure in mke2fs

We're trying to package genimage for the Guix distribution.

When we run automated tests, we get a test failure in mke2fs (using genimage-10):

INFO: ext4(mke2fs.ext4): cmd: "MKE2FS_CONFIG="mke2fs.conf" mke2fs -t ext4 -E 'root_owner=0:0,lazy_itable_init=0,lazy_journal_init=0' -O '^large_file' -O '^huge_file' -d '/tmp/guix-build-genim
age-10.drv-0/genimage-10/trash directory.basic-images.test/tmp/root' -U 12345678-1234-1234-1234-1234567890ab -L mke2fs '/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-ima
ges.test/images/mke2fs.ext4' 32768" (stderr+stdout):
mke2fs 1.43.6 (29-Aug-2017)
ext2fs_check_if_mount: Can't check if filesystem is mounted due to missing mtab file while determining whether /tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/
images/mke2fs.ext4 is mounted.
Discarding device blocks: done                            
Creating filesystem with 32768 1k blocks and 8192 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks: 
        8193, 24577

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Copying files into the device: done
Writing superblocks and filesystem accounting information: done

INFO: ext4(mke2fs.ext4): cmd: "e2fsck -pvfD '/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/images/mke2fs.ext4'" (stderr+stdout):
ext2fs_check_if_mount: Can't check if filesystem is mounted due to missing mtab file while determining whether /tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/
images/mke2fs.ext4 is mounted.

          51 inodes used (0.62%, out of 8192)
           0 non-contiguous files (0.0%)
           0 non-contiguous directories (0.0%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 43
        5970 blocks used (18.22%, out of 32768)
           0 bad blocks
           0 large files

          24 regular files
          18 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
           0 symbolic links (0 fast symbolic links)
           0 sockets
------------
          42 files
INFO: ext4(mke2fs.ext4): cmd: "echo 'set_current_time 20000101000000
set_super_value mkfs_time 20000101000000
set_super_value lastcheck 20000101000000
set_super_value mtime 00000000' | debugfs -w '/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/images/mke2fs.ext4'" (stderr+stdout):
debugfs 1.43.6 (29-Aug-2017)
debugfs:  Setting current time to Sat Jan  1 00:00:00 2000

debugfs:  debugfs:  debugfs:  debugfs:  ++ uuid='Filesystem UUID'
++ seed='Directory Hash Seed:'
++ csum1='Checksum: \|Group 0: (Blocks 1-4095) csum'
++ csum2='Group 0: (Blocks 1-4095) \[ITABLE_ZEROED\]\|  Checksum .*, unused inodes 205'
++ dumpe2fs images/mke2fs.ext4
++ grep -v '^\(Filesystem UUID\|Directory Hash Seed:\|Checksum: \|Group 0: (Blocks 1-4095) csum\|Group 0: (Blocks 1-4095) \[ITABLE_ZEROED\]\|  Checksum .*, unused inodes 205\)'
dumpe2fs 1.43.6 (29-Aug-2017)
++ sed -i 's/^\(Journal size:             \)1029k$/\11024k/' dump
++ sed -i 's/^\(  Block bitmap at .*\),\( Inode bitmap.*\)$/\1\n \2/' dump
++ test_cmp /tmp/guix-build-genimage-10.drv-0/genimage-10/test/mke2fs.dump dump
++ diff -u /tmp/guix-build-genimage-10.drv-0/genimage-10/test/mke2fs.dump dump

--- /tmp/guix-build-genimage-10.drv-0/genimage-10/test/mke2fs.dump      2018-03-29 11:02:02.585752634 +0000
+++ dump        2018-05-18 19:19:03.337721421 +0000
@@ -11,7 +11,7 @@
 Inode count:              8192
 Block count:              32768
 Reserved block count:     1638
-Free blocks:              26838
+Free blocks:              26798
 Free inodes:              8141
 First block:              1
 Block size:               1024
@@ -30,9 +30,9 @@
 Maximum mount count:      -1
 Last checked:             Sat Jan  1 00:00:00 2000
++ func_check
 Check interval:           0 (<none>)
-Lifetime writes:          343 kB
-Reserved blocks uid:      0 (user root)
-Reserved blocks gid:      0 (group root)
++ local ret=1
+Lifetime writes:          389 kB
+Reserved blocks uid:      0 (user unknown)
+Reserved blocks gid:      0 (group unknown)
 First inode:              11
++ set +x
 Inode size:              128
 Journal inode:            8
@@ -46,14 +46,14 @@
 Journal start:            0
 
 
-Group 0: (Blocks 1-8192) csum 0xcb99 [ITABLE_ZEROED]
+Group 0: (Blocks 1-8192) csum 0xe916 [ITABLE_ZEROED]
   Primary superblock at 1, Group descriptors at 2-2
Failed to execute 'check_ext'!
   Reserved GDT blocks at 3-257
-  Block bitmap at 258 (+257), csum 0x064f6fdd
+  Block bitmap at 258 (+257), csum 0x22f720dc
   Inode bitmap at 262 (+261), csum 0xb1052088
   Inode table at 266-521 (+265)
-  6873 free blocks, 1997 free inodes, 18 directories, 1997 unused inodes
-  Free blocks: 1320-8192
+  6833 free blocks, 1997 free inodes, 18 directories, 1997 unused inodes
+  Free blocks: 1360-8192
   Free inodes: 52-2048
 Group 1: (Blocks 8193-16384) csum 0xfabf [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
   Backup superblock at 8193, Group descriptors at 8194-8194
not ok 6 - mke2fs
FAIL: test/basic-images.test 6 - mke2fs

Add support for exfat

I was a bit surprised to see that the exfat file system was not supported by genimage. Would it be possible to add it? Since genimage is used by buildroot (and others), which frequently target embedded systems running on flash drives, it seems like a natural fit.

Thanks for all your hard work on genimage!

Multi-component directory names in genimage.cfg fail

I'm using a genimage.cfg file that looks like this:

image ad_emmc.img {
        hdimage {}
        partition rootfsA {
                in-partition-table = "yes"
                partition-type = 0x83
                image = "rootfs.ext4"
                bootable = "yes"
                size = 1000M
        }
        partition rootfsB {
                in-partition-table = "yes"
                partition-type = 0x83
                image = "rootfs.ext4"
                bootable = "yes"
                size = 1000M
        }
        partition services {
                in-partition-table = "yes"
                partition-type = 0x83
                image = "services.ext4"
                size = 2000M
        }
        partition var {
                in-partition-table = "yes"
                partition-type = 0x83
                image = "var.ext4"
                size = 500M
        }
        partition skills {
                in-partition-table = "yes"
                partition-type = 0x83
                image = "skills.ext4"
                size = 10000M
        }
}

image rootfs.ext4 {
        name = "rootfs"
        ext4 {
                label = "rootfs"
        }
        size = 1000M
        mountpoint = "/"
}

image var.ext4 {
        name = "var"
        ext4 {
                label = "var"
        }
        size = 500M
        mountpoint = "/var"
}

image services.ext4 {
        name = "services"
        ext4 {
                label = "services"
        }
        size = 2000M
        mountpoint = "/usr/local"
}

image skills.ext4 {
        name = "skills"
        ext4 {
                label = "skills"
        }
        size = 100M
        mountpoint = "/opt"
}

And the post-image.sh looks like this:

#!/bin/sh

GENIMAGE_CFG="board/nvidia/avionic/genimage.cfg"
GENIMAGE_ROOT="${BUILD_DIR}/genimage.root"
GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
# Cleanup leftovers

rm -rf ${GENIMAGE_ROOT}
rm -rf ${GENIMAGE_TMP}
# Provide rootfs

mkdir -p ${GENIMAGE_ROOT}
fakeroot tar -C ${GENIMAGE_ROOT} -xf ${BINARIES_DIR}/rootfs.tar

fakeroot genimage \
        --rootpath "${GENIMAGE_ROOT}" \
    --tmppath "${GENIMAGE_TMP}" \
    --inputpath "${BASE_DIR}" \
    --outputpath "${BINARIES_DIR}" \
    --loglevel=10 \
    --config "${GENIMAGE_CFG}"

RET=${?}

IMAGES="${1}"
exit ${RET}

When post-image.sh runs, I get the following output:

cmd: mkdir -p /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp
cmd: rm -rf /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/*
cmd: mkdir -p /home/blair/work/testing/buildroot.jibo/output/images
cmd: mkdir -p /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp
cmd: cp -a /home/blair/work/testing/buildroot.jibo/output/build/genimage.root /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root
cmd: mv /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/var /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp
cmd: mkdir /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/var
cmd: chmod --reference=/home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/var /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/var
cmd: chown --reference=/home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/var /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/var
cmd: mv /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/usr/local /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp
cmd: mkdir /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/usr/local
cmd: chmod --reference=/home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/usr/local /home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/root/usr/local
chmod: failed to get attributes of ‘/home/blair/work/testing/buildroot.jibo/output/build/genimage.tmp/usr/local’: No such file or directory

So the mv command does what it's supposed to do, but the script was expecting it to move the directory tree when it just move the last directory.

When faced with /usr/local the mv command will just recreate the local directory.

board/ci20/genimage.cfg:29: no sub-section title/index for 'config'

INFO: cmd: "mkdir -p "/home/nirajtummala/buildroot/output/build/genimage.tmp"" (stderr):
INFO: cmd: "rm -rf "/home/nirajtummala/buildroot/output/build/genimage.tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/nirajtummala/buildroot/output/build/genimage.tmp"" (stderr):
INFO: cmd: "cp -a "/tmp/tmp.tU65pvVkfR" "/home/nirajtummala/buildroot/output/build/genimage.tmp/root"" (stderr):
INFO: cmd: "find '/home/nirajtummala/buildroot/output/build/genimage.tmp/root' -depth -type d -printf '%P\0' | xargs -0 -I {} touch -r '/tmp/tmp.tU65pvVkfR/{}' '/home/nirajtummala/buildroot/output/build/genimage.tmp/root/{}'" (stderr):
INFO: cmd: "mkdir -p "/home/nirajtummala/buildroot/output/images"" (stderr):
INFO: hdimage(sdcard.img): adding partition 'uboot-spl' from 'u-boot-spl.bin' ...
INFO: hdimage(sdcard.img): adding partition 'uboot' from 'u-boot.img' ...
INFO: hdimage(sdcard.img): adding partition 'uboot-env' from 'uboot-env.bin' ...
INFO: hdimage(sdcard.img): adding partition 'rootfs' (in MBR) from 'rootfs.ext4' ...
INFO: hdimage(sdcard.img): writing MBR

genimage-10: Test failure in jffs2

expecting success: 
        run_genimage jffs2.config test.jffs2 &&
        md5sum -c '/tmp/guix-build-genimage-10.drv-0/genimage-10/test/jffs2.md5'
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00075539 s, 1.4 GB/s
INFO: cmd: "mkdir -p "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/tmp"" (stderr+stdout):
INFO: cmd: "rm -rf "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/tmp"/*" (stderr+stdout):
INFO: cmd: "mkdir -p "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/images"" (stderr+stdout):
INFO: cmd: "mkdir -p "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/tmp"" (stderr+stdout):
INFO: cmd: "cp -a "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/root" "/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/tmp/root"" (stderr+stdout):
INFO: jffs2(test.jffs2): cmd: "mkfs.jffs2 --eraseblock=131072 -d '/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/tmp/root' -o '/tmp/guix-build-genimage-10.drv-0/genimage-10/trash directory.basic-images.test/images/test.jffs2' " (stderr+stdout):
md5sum: WARNING: 1 computed checksum did NOT match

images/test.jffs2: FAILED
not ok 10 - jffs2
FAIL: test/basic-images.test 10 - jffs2
#       
#               run_genimage jffs2.config test.jffs2 &&
#               md5sum -c '/tmp/guix-build-genimage-10.drv-0/genimage-10/test/jffs2.md5'
#       

Could genimage be used to partition an eMMC device?

As currently defined, could genimage be used instead of fdisk to partition an eMMC device?

If not, would this be a consistent feature to add to genimage? (I'm in no way expecting this to be done for my benefit; I'm just curious...)

error: ‘AT_NO_AUTOMOUNT’ undeclared

Hi All,
I am not sure if this is the right place to post this , apologies in advance if it's not.

I am using buildroot to build a linux environment for an FPGA platform.
It gets to the point where it attempts to build genimage which is where it's failing at:

 

        genimage 11
        =====

        prefix:                 /nobackup/user_g/tmp_build/host

        compiler:               /cad/apps/gnu/linux/x86_64/6/local/gcc/9.1.0/bin/gcc
        cflags:                 -O2 -I/nobackup/user_g/tmp_build/host/include  -pipe -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wsign-compare -Wchar-subscripts -Wstrict-prototypes -Wshadow -Wformat-security -Wtype-limits -Wno-unused-parameter -ffunction-sections -fdata-sections -fvisibility=hidden
        ldflags:                -L/nobackup/user_g/tmp_build/host/lib -Wl,-rpath,/nobackup/user_g/tmp_build/host/lib  -Wl,--as-needed -Wl,--gc-sections

        debug:                  no
        hide symbols:           yes
        libconfuse:             -L/nobackup/user_g/tmp_build/host/lib -lconfuse

>>> host-genimage 11 Building
PATH="/nobackup/user_g/tmp_build/host/bin:/nobackup/user_g/tmp_build/host/sbin:/cad/apps/gnu/linux/x86_64/6/local/gcc/9.1.0/bin:/home/rs/lintel:/cad/local/bin:/cad/div/bin:/usr/cadtools/local/bin:/usr/cadtools/bin:/cad/bin:/cad/apps/gnu/linux/x86_64/6/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin" PKG_CONFIG="/nobackup/user_g/tmp_build/host/bin/pkg-config" PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_LIBDIR="/nobackup/user_g/tmp_build/host/lib/pkgconfig:/nobackup/user_g/tmp_build/host/share/pkgconfig"  /usr/bin/make   -C /nobackup/user_g/tmp_build/build/host-genimage-11/
/usr/bin/make --no-print-directory all-am
  CC       genimage-genimage.o
  CC       genimage-config.o
  CC       genimage-util.o
  CC       genimage-crc32.o
  CC       genimage-image-cpio.o
util.c: In function ‘dir_size’:
util.c:648:36: error: ‘AT_NO_AUTOMOUNT’ undeclared (first use in this function); did you mean ‘S_AUTOMOUNT’?
  648 |   if (fstatat(fd,  d->d_name, &st, AT_NO_AUTOMOUNT) < 0) {
      |                                    ^~~~~~~~~~~~~~~
      |                                    S_AUTOMOUNT
util.c:648:36: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [genimage-util.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [all] Error 2
make[1]: *** [/nobackup/user_g/tmp_build/build/host-genimage-11/.stamp_built] Error 2
make: *** [_all] Error 2

I am using v11 apparently.

Any suggestions welcome.
I probably don't have enough environment information here so please let me know and I'll add it.

How to use compressed rootfs with this tool?

I am using the PC x86_64 Buildroot defconfig, with the following CFG configuration for genimage:

image efi-part.vfat {
  vfat {
    file startup.nsh {
      image = "efi-part/startup.nsh"
    }
    file EFI {
      image = "efi-part/EFI"
    }
    file bzImage {
      image = "bzImage"
    }
  }
  size = 16777216
}

image disk.img {
  hdimage {
    gpt = true
  }

  partition boot {
    image = "efi-part.vfat"
    partition-type-uuid = c12a7328-f81f-11d2-ba4b-00a0c93ec93b
    offset = 32768
    size = 16777216
    bootable = true
  }

  partition root {
    partition-type-uuid = 44479540-f297-41b2-9af7-d131d5f0458a
    partition-uuid = UUID_TMP
    image = "rootfs.ext2"
    offset = 16809984
  }
}

the file in question, rootfs.ext2 is set to a size of 500mb (I would love to decrease the size somehow)
However, I either want to compress the image or find some way of decreasing the size automatically. I attempted to use rootfs.ext2.xz, however it went into a kernel panic immediately.

hdimage(disk.img): fwrite 4096: Invalid argument

I'm getting the above error message using genimage with the config file shown below. I'm baffled. Any ideas?

image disk.img {

hdimage {
}

partition boot {
in-partition-table = "no"
image = "boot.img"
offset = 0
size = 512
size = 1048576
}

partition grub {
image = "grub.img"
offset = 1048576
size = 33554432
bootable = "yes"
}

}

Below is the directory with the source files in it - as you can see I'm using it with buildroot.

drwxr-xr-x 2 nicole nicole 4.0K Apr 25 20:25 ./
drwxr-xr-x 6 nicole nicole 4.0K Apr 25 17:24 ../
lrwxrwxrwx 1 nicole nicole 88 Apr 25 20:24 boot.img -> /home/nicole/projects/router-builder/buildroot/output/host/usr/lib/grub/i386-pc/boot.img
-rw-r--r-- 1 nicole nicole 4.6M Apr 25 17:59 bzImage
-rw-r--r-- 1 nicole nicole 1.2M Apr 25 20:25 disk.img
-rw-r--r-- 1 nicole nicole 114K Apr 25 18:01 grub-eltorito.img
-rw-r--r-- 1 nicole nicole 114K Apr 25 18:01 grub.img
-rw-r--r-- 1 nicole nicole 16G Apr 25 20:25 rootfs.ext2
lrwxrwxrwx 1 nicole nicole 11 Apr 25 20:25 rootfs.ext4 -> rootfs.ext2

How to create cpio image?

How do I define the contents of the cpio image?

I have genimage.cfg file on buildroot and trying to generate a cpio image with a few of the artifacts, but I don't see a way to define the contents of the cpio image.

Thanks

after creating an Image the file systems are corrupt

genimage.config
`
image PRODUCT-emmc-dev.img {
hdimage {
disk-signature = 0x741ac374
}

partition firmware-slot-0 {
	image = "PRODUCT-rootfs-dev-board.ext4"
	partition-type = 0x83
	size = 6700M
}

partition firmware-slot-1 {
	image = "PRODUCT-rootfs-dev-board.ext4"
	partition-type = 0x83
	size = 6700M
}

}`

After the file PRODUCT-emmc-dev.img is written to the eMMC the system doesn't start. See attached Log.
crash.txt

The whole workflow is working with the partition size of 1808M. Also if I write the file PRODUCT-rootfs-dev-board.ext4 separately to the partitions the system start correctly.

What am I doing wrong ? Thank you for any suggestion.

Documentation missing for some ext2 image options

With d2cb2f9 new options "use-mke2fs" and "usage-type" were introduced for image ext*. Those are not documented in README.rst.

(As far as I can see there also was an option "tool", but that one was remove in favor of "use-mke2fs"?)

With dd12f10 another option "root-owner" was introduced, also missing in the documentation.

Attempting to specify /root as a mountpoint fails

I have tried to add a separate partition mounted at /root:

image roothome.ubifs {
	ubifs {
		max-size = 2M
	}
	flashtype = w25q64
	mountpoint = /root
}

This produces an error:

INFO: cmd: "mkdir -p "/.../buildroot/output/build/genimage.tmp"" (stderr):
INFO: cmd: "rm -rf "/.../buildroot/output/build/genimage.tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/.../buildroot/output/images"" (stderr):
INFO: cmd: "mkdir -p "/.../buildroot/output/build/genimage.tmp"" (stderr):
INFO: cmd: "cp -a "/.../buildroot/output/target" "/.../buildroot/output/build/genimage.tmp/root"" (stderr):
INFO: cmd: "mv "/.../buildroot/output/build/genimage.tmp/root/root" "/.../buildroot/output/build/genimage.tmp/root"" (stderr):
mv: '/.../buildroot/output/build/genimage.tmp/root/root' and '/.../buildroot/output/build/genimage.tmp/root/root' are the same file
make: *** [Makefile:815: target-post-image] Error 1

It appears genimage is copying the various partitions into the same folder as the root filesystem, which is contained in a folder named "root." This conflicts with the mountpoint name.

I think the best way to fix this (and not just kick the can to some other more obscure name) is to add another directory alongside:

genimage.tmp/
    root/ <-- the existing root directory
    mountpoints/ <-- new
        root/ <-- the overlay

Multiple rauc images in a config file fails after generating first

If I have a config file that specifies multiple rauc images (say, update.raucb and update-developer.raucb), then generating all but the first fails.

This is because rauc_generate improperly uses insert_data to write data to a file:

genimage/image-rauc.c

Lines 41 to 44 in a58a53b

xasprintf(&manifest_file, "%s/manifest.raucm", mountpath(image));
ret = insert_data(image, manifest, manifest_file, strlen(manifest), 0);
if (ret)
return ret;

This manifest file is presumed not to exist, but if previous RAUC runs have been done, it does exist and the file is not replaced/truncated, but simply pasted into, leaving garbage at the end from the previous RAUC run. (In other words, insert_data is not the appropriate function to use here.)

This creates bizarre errors when RAUC runs again and encounters the garbage data, like:

Failed to update manifest: Key file contains line ?      dff3f29ff09360b59513? which is not a key-value pair, group, or comment

As a workaround, I'm deleting the file before continuing:

diff --git a/image-rauc.c b/image-rauc.c
index c4195a3..8ee5550 100644
--- a/image-rauc.c
+++ b/image-rauc.c
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include "genimage.h"
 
@@ -39,6 +40,7 @@ static int rauc_generate(struct image *image)
    image_debug(image, "manifest = '%s'\n", manifest);
 
    xasprintf(&manifest_file, "%s/manifest.raucm", mountpath(image));
+   ret = unlink(manifest_file);
    ret = insert_data(image, manifest, manifest_file, strlen(manifest), 0);
    if (ret)
        return ret;

Feel free to steal this patch for a quick fix, or if you want to make more sweeping changes, you won't hurt my feelings.

Regression in PR #102

PR #102 causes a regression in image-flash.c

Problem is that pad_file behaves differently depending on whether it is called with infile == NULL or infile != NULL.

If called with infile == NULL size is assumed to be an absolute offset in the output file.
Else size is assumed to be the size of infile + padding.

Since https://github.com/pengutronix/genimage/pull/102/files#diff-088cb03e9ae7e9e2f4755d4ccf535699L63 handles those cases the same, output images are no longer created correctly.

Unfortunately I did not discover this during testing because none of my testcases had an empty partition that was preceded by another partition.

#103 contains a suggestion on how to fix the regression

create folder on fat partition?

I want to create a image for my sdcard/usb-stick. Some files on the first boot partition should be at a subfolder. Is it possible to create a vfat partition and add the files to a subfolder instead of the root path?

ext4: option "features" ignored when "use-mke2fs" is true

After migrating a ptxdist based BSP from ptxdist-2019.09.0 to ptxdist-2019.10.0 our target board complained when booting with U-Boot 2016.09.x from SD-Card with ext4 partitions:

Unsupported feature found (64bit, possibly metadata_csum), not mounting
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **

Comparing the ext4 flags of the created root.ext2 images revealed this:

-Filesystem features:      has_journal dir_index extent uninit_bg
+Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super dir_nlink extra_isize metadata_csum

The reason was ptxdist switched on use-mke2fs = true in the default genimage config for ext* images, so the old image was build with genext2fs and the new one with mke2fs which is the intend of this option. However, the latter ignores the option features as can be seen when you compare output of genimage (stripped to the necessary lines):

INFO: ext4(root.ext2): cmd: "genext2fs -d '/tmp/ptxdist.Llj64K/genimage.M7vSVP/root' --size-in-blocks=76800 -i 16384 '/home/adahl/Work/bsp/***/platform-v7a/images/root.ext2' " (stderr):
INFO: ext4(root.ext2): cmd: "tune2fs -O 'extents,uninit_bg,dir_index,has_journal' '/home/adahl/Work/bsp/***platform-v7a/images/root.ext2'" (stderr):

vs. just

INFO: ext4(root.ext2): cmd: "mke2fs -t ext4 -E 'root_owner=0:0,lazy_itable_init=0,lazy_journal_init=0' -O '^large_file' -O '^huge_file' -d '/tmp/ptxdist.T2Gf50/genimage.sJEXH6/root'   '/home/adahl/Work/bsp/***/platform-v7a/images/root.ext2' 60416" (stderr):

Without use-mke2fs = true genimage passes the options from "features" to a separate tune2fs run, which is not done in the case where mke2fs is called.

I could confirm this adding the following line to the genimage config:

features = "uninit_bg"

When checking the resulting image with tune2fs that option is not shown.

Maybe one could just pass "features" to the -O option of "mke2fs"?

Have partition be sized to minimum to fit specified files

As I expect a number of buildroot users are these days, we use genimage to generate the output file image. Problem: we must explicitly set a size value large enough to fit the built system. Too large, and we're making unwieldy images; too small and the build fails. Even worse, we'll have to tune this again and again as we add features to our product, increasing the size of the contained files.

Would it be possible for genimage to measure the size of the files that will go into the partition (specified using the rootpath property) and then make a partition that can contain those files with little waste?

Syntax error on configure

When I try to compile genimage on my Ubuntu 16.04 LTS with libconfuse-dev installed, I get this:

$ ./autogen.sh
configure.ac:78: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/attributes.m4:87: CC_CHECK_LDFLAGS is expanded from...
configure.ac:78: the top level
configure.ac:79: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from.
........
configure.ac:79: the top level
configure.ac:9: installing `build-aux/install-sh'
configure.ac:9: installing `build-aux/missing'
Makefile.am: installing `build-aux/depcomp'

----------------------------------------------------------------
Initialized build system. For a common configuration please run:
----------------------------------------------------------------

./configure CFLAGS='-g -O0' --prefix=/usr

root@a2be79f92dca:/buildpid/genimage/genimage-master# ./configure CFLAGS='-g -O0' --prefix=/usr
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
.......
checking whether to enable debugging... no
checking whether to hide internal symbols... yes
checking if gcc -std=gnu99 supports -Wl,--as-needed flag... yes
checking if gcc -std=gnu99 supports -Wl,--gc-sections flag... yes
./configure: line 5531: syntax error near unexpected token `CONFUSE,'
./configure: line 5531: `PKG_CHECK_MODULES(CONFUSE, libconfuse)'
$ 

This is with autoconf 2.68

Is there something I'm missing?

config examples/docs

looking for an example configuration to install grub2 in a gpt image with a bios boot partition. So far none of my attempts have been bootable.

thanks

Offset in first extended partition not handled correctly

I was writing this unusual config, and it brought up an issue in genimage.
Part4 is at the correct location, but the ERB of part3 does not point correctly to part4.
Tested on 207ce8d

image test.hdimage {
	hdimage {
		extended-partition = 3
	}
	partition part1 {
		offset = 128K
		size =  256K
		partition-type = 0x83
	}
	partition part2 {
		size = 3072K
		partition-type = 0x83
	}
	partition part3 {
		offset = 3686400
		size = 8126464
		partition-type = 0x83
	}
	partition part4 {
		offset = 11821056
		size = 16252928
		partition-type = 0x83
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.