Skip to contentSkip to conversation

imx/genimage: Place the rootfs at a proper offset when BR2_LINUX_KERNEL_INSTALL_TARGET=y

PATCH RESEND Superseded Fabio Estevam 3 participants 5 messages Nov 13, 2021 Arm i.MX and Layerscape

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH RESEND 1/1 imx/genimage: Place the rootfs at a proper offset when BR2_LINUX_KERNEL_INSTALL_TARGET=y

Currently, when BR2_LINUX_KERNEL_INSTALL_TARGET=y is selected, issuing a "saveenv" command in the U-Boot prompt may lead to rootfs corruption.

Avoid this problem by placing the rootfs at an 8MB offset, just like it is done in genimage.cfg.template.

Tested on a imx6qp-wandboard and also on a custom imx6ull based board.

"saveenv" does not corrupt the rootfs anymore after this change.

---
 board/freescale/common/imx/genimage.cfg.template_no_boot_part    | 1 +
 .../freescale/common/imx/genimage.cfg.template_no_boot_part_spl  | 1 +
 2 files changed, 2 insertions(+)
board/freescale/common/imx/genimage.cfg.template_no_boot_part +1 -0
index edc34d0fcd12..b8fa43210b91 100644
@@ -11,5 +11,6 @@ image sdcard.img {
   partition rootfs {
     partition-type = 0x83
     image = "rootfs.ext2"
+    offset = 8M
   }
 }
board/freescale/common/imx/genimage.cfg.template_no_boot_part_spl +1 -0
index c29032572aef..ef015918a5b2 100644
@@ -26,5 +26,6 @@ image sdcard.img {
   partition rootfs {
     partition-type = 0x83
     image = "rootfs.ext2"
+    offset = 8M
   }
 }
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 2 lines · On Sat, 13 Nov 2021 11:38:57 -0300 Fabio Estevam <[email protected]> wrote:

Currently, when BR2_LINUX_KERNEL_INSTALL_TARGET=y is selected, issuing a "saveenv" command in the U-Boot prompt may lead to rootfs corruption.

I don't see the relationship between BR2_LINUX_KERNEL_INSTALL_TARGET=y and changing the offset of the rootfs to avoid rootfs corruption.

All what BR2_LINUX_KERNEL_INSTALL_TARGET=y does it add the kernel image into the /boot directory of the rootfs. It makes the rootfs larger for sure, but it would still start at the same place.

Are you sure there's any relationship with
BR2_LINUX_KERNEL_INSTALL_TARGET=y here?

Best regards,

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author reviewer
#2 lore raw

Hi Thomas,

Quoted 9 lines · Thomas Petazzoni

I don't see the relationship between BR2_LINUX_KERNEL_INSTALL_TARGET=y and changing the offset of the rootfs to avoid rootfs corruption.

All what BR2_LINUX_KERNEL_INSTALL_TARGET=y does it add the kernel image into the /boot directory of the rootfs. It makes the rootfs larger for sure, but it would still start at the same place.

Are you sure there's any relationship with
BR2_LINUX_KERNEL_INSTALL_TARGET=y here?

Yes, this problem only happens with BR2_LINUX_KERNEL_INSTALL_TARGET=y.

When BR2_LINUX_KERNEL_INSTALL_TARGET is not selected, then board/freescale/common/imx/genimage.cfg.template is used as per the logic inside board/freescale/common/imx/post-image.sh.

board/freescale/common/imx/genimage.cfg.template correctly puts the rootfs at a safe offset.

With BR2_LINUX_KERNEL_INSTALL_TARGET=y, then board/freescale/common/imx/genimage.cfg.template_no_boot_part is used and no offset to the rootfs is given, which may cause U-Boot environment area to write into the rootfs
area, causing the rootfs corruption.

Please let me know if you need more information as this problem is easy to reproduce.

Regards,

Fabio Estevam
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Fabio, All,

On 2021-11-13 15:11 -0300, Fabio Estevam spake thusly:

Quoted 21 lines

Hi Thomas,

Quoted 9 lines · Thomas Petazzoni

I don't see the relationship between BR2_LINUX_KERNEL_INSTALL_TARGET=y and changing the offset of the rootfs to avoid rootfs corruption.

All what BR2_LINUX_KERNEL_INSTALL_TARGET=y does it add the kernel image into the /boot directory of the rootfs. It makes the rootfs larger for sure, but it would still start at the same place.

Are you sure there's any relationship with
BR2_LINUX_KERNEL_INSTALL_TARGET=y here?

Yes, this problem only happens with BR2_LINUX_KERNEL_INSTALL_TARGET=y.

When BR2_LINUX_KERNEL_INSTALL_TARGET is not selected, then board/freescale/common/imx/genimage.cfg.template is used as per the logic inside board/freescale/common/imx/post-image.sh.

Quoted 8 lines

board/freescale/common/imx/genimage.cfg.template correctly puts the rootfs at a safe offset.

With BR2_LINUX_KERNEL_INSTALL_TARGET=y, then board/freescale/common/imx/genimage.cfg.template_no_boot_part is used and no offset to the rootfs is given, which may cause U-Boot environment area to write into the rootfs
area, causing the rootfs corruption.

Ah, that indeed explains the case. This type of exp[lanations definitely should be in the commit log.

However, please not that there are two cases for
BR2_LINUX_KERNEL_INSTALL_TARGET=y:

    if grep -Eq "^BR2_TARGET_UBOOT_SPL=y$" ${BR2_CONFIG}; then
        echo "genimage.cfg.template_no_boot_part_spl"
    else
        echo "genimage.cfg.template_no_boot_part"
    fi

And this patch only addresses the second one.

Could you respin, fixing the second template, and including these extended explanations in the commit log, please?

Regards,
Yann E. MORIN.

Quoted 10 lines

Please let me know if you need more information as this problem is easy to reproduce.

Regards,

Fabio Estevam
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Fabio, All,

On 2021-11-13 22:02 +0100, Yann E. MORIN spake thusly:

Quoted 18 lines

On 2021-11-13 15:11 -0300, Fabio Estevam spake thusly:

Quoted 8 lines
Quoted 2 lines · Thomas Petazzoni

I don't see the relationship between BR2_LINUX_KERNEL_INSTALL_TARGET=y and changing the offset of the rootfs to avoid rootfs corruption.

When BR2_LINUX_KERNEL_INSTALL_TARGET is not selected, then board/freescale/common/imx/genimage.cfg.template is used as per the logic inside board/freescale/common/imx/post-image.sh.

Quoted 8 lines

board/freescale/common/imx/genimage.cfg.template correctly puts the rootfs at a safe offset.

With BR2_LINUX_KERNEL_INSTALL_TARGET=y, then board/freescale/common/imx/genimage.cfg.template_no_boot_part is used and no offset to the rootfs is given, which may cause U-Boot environment area to write into the rootfs
area, causing the rootfs corruption.

Quoted 4 lines

Ah, that indeed explains the case. This type of exp[lanations definitely should be in the commit log.

However, please not that there are two cases for

s/not/note/

Quoted 9 lines

BR2_LINUX_KERNEL_INSTALL_TARGET=y:

    if grep -Eq "^BR2_TARGET_UBOOT_SPL=y$" ${BR2_CONFIG}; then
        echo "genimage.cfg.template_no_boot_part_spl"
    else
        echo "genimage.cfg.template_no_boot_part"
    fi

And this patch only addresses the second one.

Of course, I checked the case where we do not put the kernel in target/, and both the SPL and non-SPL cases do have an 8MiB offset for the 'boot' partition...

Regards,
Yann E. MORIN.

Quoted 5 lines

Could you respin, fixing the second template, and including these extended explanations in the commit log, please?

Regards,
Yann E. MORIN.

Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot