Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sd-image: FAT free /boot #62462

Merged
merged 7 commits into from
Jun 24, 2019
Merged

sd-image: FAT free /boot #62462

merged 7 commits into from
Jun 24, 2019

Conversation

samueldr
Copy link
Member

@samueldr samueldr commented Jun 2, 2019

Motivation for this change

A. Booting from ext4

Fixes #51924

This fixes one annoyance and allows recovering a bit of space.

The annoyance is that there is about 100MiB free for the generations on the
/boot partition in the current state of the SD images. This is not much when
playing around with kernels and this limit is often hit.

By using the FAT32 partition as a "firmware-only" partition for the Raspberry
Pi, we can reduce its size to a minimum required to hold the firmware-esque
bits required for boot. This allows us to cut ~100MiB of space.

B. Review "firmware" setup

By treating the FAT32 partition exactly as if it was a firmware bit, we can:

  1. Skip mounting it in the installed system.

This is not entirely useful, but this makes it easier to allow bigger firmwares
to be fused to the SD image as a user only has to remove the FAT32
partition to gain more space if needed (e.g. with some Rockchip firmwares).

The initial PR also removed the 8MiB gap and assumed a user would
remove the FAT32 partition before fusing a firmware to the SD image,
but this is way too inconvenient compared to just dumping the data to
the right location on the disk. 8MiB is not a significant enough size to
warrant the headaches.

Things done

  • ☑️ Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • ☑️ NixOS
    • 🔲 other Linux distributions
  • 🔲 Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • ☑️ Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • ☑️ Tested on hardware
  • ☑️ Determined the impact on package closure size (by running nix path-info -S nix path-info -s before and after)
  • 🔲 Assured whether relevant documentation is up to date
  • ☑️ Fits CONTRIBUTING.md.

Here's the diff of the size of the image; the closure itself doesn't really change more.

[samueldr@aarch64:~/nixpkgs]$ nix path-info -s ./fat-free
/nix/store/pl1nvnm7g71j0hvbhjhd9xjxfy3ry7kg-nixos-sd-image-19.09pre130979.gfedcba-aarch64-linux.img      2007622888

[samueldr@aarch64:~/nixpkgs]$ nix path-info -s ./image--nixos-unstable
/nix/store/vlkb2zv9cyw95zhqpfz0cxxg1ibbr77j-nixos-sd-image-19.09pre130979.gfedcba-aarch64-linux.img      2081703144

All commits in the series should be independently good and able to build and boot. I verified boot at each step.

This was verified on:

  • Raspberry Pi 3B (the usual sd card boot, firmware from FAT32 partition as-built)
  • Pine A64-LTS (firmware from SPI nor flash, FAT32 partition still on)
  • Orange Pi Zero Plus 2 H5 (FAT32 partition deleted, no partition added, firmware fused as usual with dd)

fusing: I am using "fusing" as the term for the usual sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8 for SoCs that read the firmware off the storage at a specific offset.

@samueldr
Copy link
Member Author

samueldr commented Jun 5, 2019

I removed the only controversial change from the PR, it wasn't worth it in the end. Furthermore, the only advantage that it brought still is present by moving /boot off the FAT32 partition. It is possible to just remove the FAT32 partition to gain the couple MiB needed for the Rockchip blobby firmware that needs space up to 16MiB at the start of the disk.

@lheckemann
Copy link
Member

or non-blobby firmware 🎉

Copy link
Member

@lheckemann lheckemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to test this yet, but it looks good 👍

The current FAT32 partition is kept as it is required for the Raspberry
Pi family of hardware. It is where the firmware is kept.

The partition is kept bootable, and the boot files kept in there until
the following commits, to keep all commits of this series individually
bootable.
This will allow adding /boot files to the rootfs.
The slack, seemingly, accounted for more than the minimum required for
slack plus the two partitions.

This change makes the gap a somewhat abstracted amount, but is not
configurable within the derivation.
This will keep configuration configuring the size of the /boot partition
still build, while showing the deprecation warning.

In 99.9% of cases I assume ignoring the configuration is better, as the
sd-image builder already is pretty opinionated in that matter.
@samueldr
Copy link
Member Author

Added mkRemovedOptionModule so users of the now removed options will get a warning, and builds that are most likely right.

@samueldr samueldr merged commit 6bc2d30 into NixOS:master Jun 24, 2019
@samueldr samueldr deleted the sd-image/fat-free branch June 24, 2019 18:53
@Thra11
Copy link
Member

Thra11 commented Jul 2, 2019

I wonder whether it would be possible (/ worthwhile) to remove the firmware partition from the generic sd-image but make it so that the raspberry pi derivation could override the necessary parts.

@samueldr
Copy link
Member Author

samueldr commented Jul 3, 2019

@Thra11 it should be possible, though in the interest of ease of use, not worthwhile, we end up putting that partition as "a" default firmware, which is for the most popular aarch64 platform.

We would still need to reserve the same amount of space in front of the system. So there would be no gain, other than removing a partition that isn't used by the system anymore.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/raspberry-pi-3b-doesnt-boot-without-a-screen/6802/9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Put kernel and initrd on ext4 in ARM images
4 participants