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

Add SOPINE / PINE A64-LTS bootloader #32553

Closed
wants to merge 5 commits into from

Conversation

samueldr
Copy link
Member

@samueldr samueldr commented Dec 11, 2017

Motivation for this change

Adds the necessary packages to build the bootloader for both the SOPINE and PINE A64-LTS boards.

Confusingly, the PINE A64-LTS is basically 1:1 compatible with SOPINE, but not with other PINE A64 boards. Upstream projects generally use sopine as the name for both compatible platforms.

NixOS (upstream Linux) isn't working 100% with these boards, but the upstream u-boot already has support for the boards. Leaving the configuration out isn't really helpful. Whilst Linux isn't working 100%, the stock, untouched, sd-image-aarch64 image boots, serial works, and USB ethernet makes this board workable enough that this is what I'm using for aarch64 development, preferred over the raspi 3. (The eMMC module makes a big difference in usability over even the faster SD cards.) From there, support should only get better, hopefully.

Arm Trusted Firmware

Arm Trusted Firmware is a dependency (seemingly) needed by u-boot.

I have not tested (used) the QEMU build. It does build, though. This was added mainly because otherwise I couldn't test the default build instructions, as the Allwinner ATF comes from a fork.

Now, that derivation might frighten or sicken you. I bodged this together, inspired by the u-boot configuration. Tell me what I should have done instead and I will fix it. I'm not used to derivations and overriding, this looked like the easiest way to keep everything together while the builds are mostly identical.

u-boot

There's nothing fancy in there, except for one patch. That patch is needed only to make u-boot load the right device tree (dtb). This is because in u-boot, pine64-plus is good enough for all the pine64-plus, sopine and the PINE A64-LTS. Linux, in the other hand, has different DTBs for those platforms. Since u-boot will use the name of the DTB used to build the bootloader to load the DTB for the kernel, this is the simplest way to do it. This should be upstreamed (yes, by me) to u-boot, unless an u-boot expert here tells me there's a more elegant way.

Here's the build, if needed

Things done

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Paging @dezgeg

For qemu, at 1.4 from upstream.

For Sopine / Pine A64-LTS, at 1.0 from fork.
This build is compatible with PINE A64-LTS.
@samueldr samueldr changed the title Feature/sopine boot Add SOPINE / PINE A64-LTS bootloader Dec 11, 2017
@grahamc
Copy link
Member

grahamc commented Dec 11, 2017

@GrahamcOfBorg eval

@samueldr
Copy link
Member Author

[05:32:49] <andi-> Mhmm, hardening disabled. I wonder what it would take to make that compatible with arm. Or even what options there are on ARM.

That's what I meant when I said "I bodged this together". This comes from the u-boot derivation, which has hardeningDisable, I initially assumed that outside Linux, hardening would fail (or be useless). I did not even research what it did since the build (and bootloader) worked. Now that I read a bit about hardening in nixpkgs, I see that some should work if the code is well made, and some that I do not understand entirely how and if it can affect code built for use outside Linux. e7225c3 (which I'll squash with the earlier arm-trusted-firmware commit at the end) disables only what seems to be necessary.

Do note that I have no test suite, the only test I'm doing is the "it boots!" test. I'm not even sure where this code lives and how it can be interacted with, if it can be interacted with.

@dezgeg
Copy link
Contributor

dezgeg commented Dec 11, 2017

I wonder how hard would it to have the U-Boot patch as something proper that could go upstream. If you just copy sun50i-a64-sopine-baseboard.dts and it's dependent #includes say from the latest -rc kernel, does it still work?

@samueldr
Copy link
Member Author

"Just" copying the .dts, and the includes, makes it not build anymore.

Error: arch/arm/dts/sun50i-a64-pine64.dts:75.1-6 Label or path emac not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:94.1-6 Label or path mdio not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:120.1-7 Label or path r_rsb not found
Error: arch/arm/dts/axp803.dtsi:48.1-8 Label or path axp803 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:133.1-11 Label or path reg_aldo2 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:140.1-11 Label or path reg_aldo3 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:147.1-11 Label or path reg_dc1sw not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:151.1-11 Label or path reg_dcdc1 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:158.1-11 Label or path reg_dcdc2 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:172.1-11 Label or path reg_dcdc5 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:179.1-11 Label or path reg_dcdc6 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:186.1-11 Label or path reg_dldo1 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:192.1-11 Label or path reg_dldo2 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:198.1-11 Label or path reg_dldo4 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:204.1-11 Label or path reg_eldo1 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:210.1-11 Label or path reg_fldo1 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:221.1-11 Label or path reg_fldo2 not found
Error: arch/arm/dts/sun50i-a64-pine64.dts:228.1-13 Label or path reg_rtc_ldo not found
FATAL ERROR: Syntax error parsing input tree
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:75.1-6 Label or path emac not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:94.1-6 Label or path mdio not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:120.1-7 Label or path r_rsb not found
Error: arch/arm/dts/axp803.dtsi:48.1-8 Label or path axp803 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:133.1-11 Label or path reg_aldo2 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:140.1-11 Label or path reg_aldo3 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:147.1-11 Label or path reg_dc1sw not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:151.1-11 Label or path reg_dcdc1 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:158.1-11 Label or path reg_dcdc2 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:172.1-11 Label or path reg_dcdc5 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:179.1-11 Label or path reg_dcdc6 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:186.1-11 Label or path reg_dldo1 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:192.1-11 Label or path reg_dldo2 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:198.1-11 Label or path reg_dldo4 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:204.1-11 Label or path reg_eldo1 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:210.1-11 Label or path reg_fldo1 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:221.1-11 Label or path reg_fldo2 not found
Error: arch/arm/dts/.sun50i-a64-pine64.dtb.pre.tmp:228.1-13 Label or path reg_rtc_ldo not found

Not knowing much about device trees, I really don't know what labels or paths not being found means.


I've been familiarizing myself with u-boot this evening, and have found out that I was indeed correct in assuming that it loads the file according to what CONFIG_DEFAULT_DEVICE_TREE is set to. I've looked briefly at alternatives, but it seems that fdtfile is not really overridable at build time because of the way it is handled in sunxi-common.h.

Unless you know some magic or have other tips related to u-boot, I'll be looking into contributing the minor, but impactful copied file change.

The `CONFIG_DEFAULT_DEVICE_TREE` config is used to build
the name of the device tree that is loaded by u-boot.
This makes this config config file redundant (and unused).

The generated u-boot file is the same, once built.
@dezgeg
Copy link
Contributor

dezgeg commented Mar 17, 2018

Sorry this took so long. Apparently the problem on the U-Boot side was much thornier than I expected. But, now there is a patch series from Andre Przywara posted upstream at http://patchwork.ozlabs.org/cover/880198/ which adds proper SoPine support to U-Boot. I expect that will land upstream in 2018.05 but I've picked it here as a patch series in https://github.com/dezgeg/nixpkgs/tree/uboot-aarch64 (or a prebuilt one at
http://cs.helsinki.fi/u/tmtynkky/sopine-u-boot-sunxi-with-spl.bin). Can you test if that works?

Note, U-Boot 2018.05 will also have Allwinner builds produce u-boot-sunxi-with-spl.bin on 64-bit boards just like on 32-bit boards, so I've changed the Nix expression to match. On SD cards it's installed like dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=8k seek=1 just like on the 32-bit boards. Do let me know if the split files sunxi-spl.bin and u-boot.itb files are needed for something else so I will add them back.

@samueldr
Copy link
Member Author

I can confirm, after sudo dd if=sopine-u-boot-sunxi-with-spl.bin of=/dev/mmcblk1 bs=8k seek=1 that your prebuilt u-boot for SOPINE works.

I don't see any need for split bin/itb files, though I don't know if there are any needs. When previously building u-boot, I was catting them together anyway.

Unless you tell me otherwise, I'll leave it to you to close the PR.

@dezgeg
Copy link
Contributor

dezgeg commented Mar 18, 2018

Thanks for testing. Applied to master now.

I don't see any need for split bin/itb files, though I don't know if there are any needs.

Yeah, I haven't ever needed them myself, but I haven't ever used the various other methods like DFU / sunxi-tool / NAND so I don't know what those need. But they can be always added later.

@dezgeg dezgeg closed this Mar 18, 2018
@samueldr samueldr deleted the feature/sopine_boot branch March 18, 2018 17:22
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.

None yet

5 participants