Re: [docs] [PATCH] ref-manual/variables.rst: document the INITRAMFS_MAXSIZE variable

Antonin Godard
2025-04-25T07:34:26Z

Hi Christos,

On Thu Apr 24, 2025 at 5:18 PM CEST, Christos Gavros via lists.yoctoproject.org wrote:
> hi Antonin
>
> my plan was to include text for all the comments from you and Quentin.
> I didnt mention the others because are small changes.
>
> Regarding the 2 variables. The values are:
> IMAGE_OVERHEAD_FACTOR = 1.3
> IMAGE_ROOTFS_ALIGNMENT = 1
> size (initial size of IMAGE_ROOTFS) = 120840kb
> size (after applying IMAGE_OVERHEAD_FACTOR ) = 157092kb
> size (after applying IMAGE_ROOTFS_ALIGNMENT ) = 157092kb
>
> There are more variables involved in the final calculation like 'IMAGE_ROOTFS_SIZE', 'IMAGE_ROOTFS_EXTRA_SPACE' (calc of base_size2).
>
> My suggestion related to variables is to add a sentence like " The variables IMAGE_OVERHEAD_FACTOR, IMAGE_ROOTFS_ALIGNMENT , IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_EXTRA_SPACE
> are applied in the final calculation of initramfs size."

Right, so it would be great if your v2 includes these details. I would even go
further and detail every calculation steps, before `base_size` is compared
against INITRAMFS_MAXSIZE.

I am talking about this part of the code:

size_kb = oe.utils.directory_size(d.getVar("IMAGE_ROOTFS")) / 1024

base_size = size_kb * overhead_factor
bb.debug(1, '%f = %d * %f' % (base_size, size_kb, overhead_factor))
base_size2 = max(base_size, rootfs_req_size) + rootfs_extra_space
bb.debug(1, '%f = max(%f, %d)[%f] + %d' % (base_size2, base_size, rootfs_req_size, max(base_size, rootfs_req_size), rootfs_extra_space))

base_size = base_size2
if base_size != int(base_size):
base_size = int(base_size + 1)
else:
base_size = int(base_size)
bb.debug(1, '%f = int(%f)' % (base_size, base_size2))

base_size_saved = base_size
base_size += rootfs_alignment - 1
base_size -= base_size % rootfs_alignment
bb.debug(1, '%d = aligned(%d)' % (base_size, base_size_saved))

That way, a user knows exactly what to expect when they fill in the
INITRAMFS_MAXSIZE variable for their need.

And as you can see, IMAGE_ROOTFS_MAXSIZE and INITRAMFS_MAXSIZE follow the same
rules:

if base_size > rootfs_maxsize_int:
bb.fatal("The rootfs size %d(K) exceeds IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
(base_size, rootfs_maxsize_int))

and

if base_size > initramfs_maxsize_int:
bb.error("The initramfs size %d(K) exceeds INITRAMFS_MAXSIZE: %d(K)" % \
(base_size, initramfs_maxsize_int))

So that means that your patch could also be applied to the definition of
IMAGE_ROOTFS_MAXSIZE, which currently lacks any of these details.

Thanks!
Antonin

--
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering