-
-
Notifications
You must be signed in to change notification settings - Fork 604
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 support for Purism Librem 5 #698
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a018670
Add config for Librem 5
balsoft 1b90b22
Apply suggestions from @louib
balsoft 482f525
purism librem5r4: update kernel to 6.4.5
999eagle 64a53fe
purism librem5r4: update uboot
999eagle add6fa5
purism librem5r4: add configuration option for audio
999eagle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Purism Librem 5 revision 4 | ||
|
||
Purism's [Librem 5] is a privacy-oriented Linux-friendly smartphone. | ||
|
||
[Librem 5]: https://puri.sm/products/librem-5/ | ||
|
||
## Installation procedure | ||
|
||
> *Note* | ||
> | ||
> TODO: build a uuu-compatible installer. | ||
|
||
Until there's a native installer, the easiest way to install NixOS on Librem 5 seems to be using [Jumpdrive]. | ||
|
||
[Jumpdrive]: https://github.com/dreemurrs-embedded/Jumpdrive | ||
|
||
### Jumpdrive | ||
|
||
Jumpdrive is a tiny Linux distribution which presents device's internal storage as USB mass storage when you connect it to a PC. | ||
It also provides a shell session over telnet. | ||
|
||
Follow the instructions in the repo to boot into Jumpdrive. | ||
Note that `uuu` is part of `nxpmicro-mfgtools` package in nixpkgs. | ||
|
||
Now, plug the device into your PC. A new block device representing Librem 5's internal MMC should appear in `/dev`. | ||
Note down this device path. | ||
|
||
### U-Boot | ||
|
||
> **Note** | ||
> | ||
> While upstream u-boot does support Librem 5, it can only boot using `boot.scr`, for which NixOS has no native support. | ||
> | ||
> There's work on extlinux support in Librem 5's U-Boot here: https://source.puri.sm/a-wai/uboot-imx/-/tree/allow-compressed-kernel | ||
> | ||
> This U-Boot version is packaged in the [`u-boot`] directory. | ||
|
||
|
||
[`u-boot`]: ./u-boot | ||
|
||
Provided you have a way to build Nix derivations for `aarch64-linux` (like a remote builder, [binfmt emulation], or you're building it on the phone itself), just run `nix-build u-boot/build.nix`. | ||
|
||
[binfmt emulation]: https://search.nixos.org/options?channel=22.11&show=boot.binfmt.emulatedSystems&from=0&size=50&sort=relevance&type=packages&query=binfmt | ||
|
||
> **Warning** | ||
> | ||
> Even though I've tested this myself, I can't guarantee that this will not render your device unbootable. | ||
> Proceed with caution. | ||
> | ||
> If it does not work, your best bet is to follow the advice here, which will flash U-Boot build by upstream: https://forums.puri.sm/t/can-someone-with-serial-console-access-try-nixos-kernel-on-librem-5/19121/27 | ||
|
||
To flash the device, run | ||
|
||
```console | ||
$ sudo u-boot-install-librem5 <path to librem 5's MMC> | ||
``` | ||
|
||
At this point, if you have an OS installed on your Librem 5, it's best to reboot into it to check that the U-Boot was flashed correctly. | ||
If that's the case, reboot back into Jumpdrive. | ||
|
||
### Partitioning | ||
|
||
Now, from your host system, partition the MMC. | ||
|
||
> **Warning** | ||
> | ||
> Doing this wipes all data off the phone | ||
|
||
I went with 1 bootable `ext2` partition for `/boot`, and one `ext4` partition for `/`. | ||
It ended up looking like this (your device names will be different): | ||
|
||
```console | ||
$ sudo fdisk -l /dev/mmcblk0 | ||
Disk /dev/mmcblk0: 29.12 GiB, 31268536320 bytes, 61071360 sectors | ||
Units: sectors of 1 * 512 = 512 bytes | ||
Sector size (logical/physical): 512 bytes / 512 bytes | ||
I/O size (minimum/optimal): 512 bytes / 512 bytes | ||
Disklabel type: dos | ||
Disk identifier: 0xcec26c32 | ||
|
||
Device Boot Start End Sectors Size Id Type | ||
/dev/mmcblk0p1 * 4096 499711 495616 242M 83 Linux | ||
/dev/mmcblk0p2 499712 61071359 60571648 28.9G 83 Linux | ||
``` | ||
|
||
Note 2MiB of free space before the first partition. | ||
This is where U-Boot lives. | ||
|
||
Mount the partitions on your host system, e.g. to `/mnt` and `/mnt/boot`. | ||
Remember that `/mnt` is the second partition, and `/mnt/boot` is the first. | ||
|
||
### Installation | ||
|
||
Now, write your NixOS config. | ||
Use `/dev/mmcblk0p1` as `fileSystems."/boot"` and `/dev/mmcblk0p2` as `fileSystems."/"`. | ||
Don't forget to import the [module from this directory](./default.nix). | ||
If you plan to use the device as a smartphone, you have a choice of two "desktop" (?) environments packaged in nixpkgs: [phosh] and [Plasma Mobile]. | ||
|
||
[phosh]: https://search.nixos.org/options?channel=22.11&show=services.xserver.desktopManager.phosh.enable&from=0&size=50&sort=relevance&type=packages&query=phosh | ||
[Plasma Mobile]: https://search.nixos.org/options?channel=22.11&show=services.xserver.desktopManager.plasma5.mobile.enable&from=0&size=50&sort=relevance&type=packages | ||
|
||
Build the configuration (`nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel` if you're using flakes). | ||
|
||
Running `nixos-install --system ./result --root /mnt` will copy the system to the MMC. | ||
Unless you're running on an aarch64 system, it will fail to activate or install the bootloader, however. | ||
You must do this manually. | ||
Get a shell on Jumpdrive, mount partitions there, and activate the system: | ||
|
||
```console | ||
$ nc 172.16.42.1 23 | ||
# mkdir /mnt | ||
# mount /dev/mmcblk0p2 /mnt | ||
# mkdir -p /mnt/boot | ||
# mount /dev/mmcblk0p1 /mnt/boot | ||
# chroot /mnt /nix/var/nix/profiles/system/activate | ||
# chroot /mnt /nix/var/nix/profiles/system/bin/switch-to-configuration boot | ||
``` | ||
|
||
Provided the last command succeeds, you now should have a bootable device. | ||
|
||
Unmount: | ||
|
||
```console | ||
# sync | ||
# umount /mnt/boot | ||
# umount -l /mnt | ||
# echo u > /proc/sysrq-trigger | ||
# echo s > /proc/sysrq-trigger | ||
``` | ||
|
||
And shut the phone down by holding the power key. | ||
|
||
Start it up and you should be booting straight into your NixOS installation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ config, lib, pkgs, ... }: | ||
{ | ||
config = lib.mkIf config.hardware.librem5.audio { | ||
assertions = [{ | ||
assertion = config.hardware.pulseaudio.enable; | ||
message = "Call audio on Librem5 requires pulse audio to be enabled through `hardware.pulseaudio.enable`."; | ||
}]; | ||
hardware.pulseaudio = { | ||
enable = true; | ||
# this is required to correctly configure the modem as PA source/sink | ||
extraConfig = '' | ||
.include ${pkgs.librem5-base}/etc/pulse/librem5.pa | ||
''; | ||
}; | ||
|
||
services.dbus.packages = [ pkgs.callaudiod ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ config, pkgs, lib, ... }: | ||
let cfg = config.hardware.librem5; | ||
in { | ||
options = { | ||
hardware.librem5 = { | ||
wifiCard = lib.mkOption { | ||
type = lib.types.enum [ "redpine" "sparklan" "none" ]; | ||
description = lib.mdDoc '' | ||
Which wi-fi card is installed in your phone. | ||
|
||
Phones shipped before January 2023 have redpine, newer phones have sparklan. | ||
''; | ||
default = "redpine"; | ||
}; | ||
customInitrdModules = lib.mkEnableOption (lib.mdDoc "use of custom kernel modules in the initrd."); | ||
installUdevPackages = lib.mkEnableOption (lib.mdDoc "installation of udev packages from librem5-base."); | ||
lockdownFix = lib.mkEnableOption (lib.mdDoc "fix for orientation and proximity sensors not working after lockdown."); | ||
audio = lib.mkOption { | ||
description = lib.mdDoc '' | ||
Whether to enable and configure PulseAudio for the Librem5 modem. | ||
|
||
This is required for audio during calls to work at all. | ||
''; | ||
type = lib.types.bool; | ||
default = true; | ||
example = false; | ||
}; | ||
}; | ||
}; | ||
|
||
imports = [ | ||
./audio.nix | ||
./initrd.nix | ||
./wifi.nix | ||
./lockdown-fix.nix | ||
]; | ||
|
||
config = { | ||
hardware.librem5 = { | ||
customInitrdModules = lib.mkDefault true; | ||
installUdevPackages = lib.mkDefault true; | ||
lockdownFix = lib.mkDefault true; | ||
}; | ||
|
||
nixpkgs.overlays = [ | ||
(import ./kernel) | ||
(final: prev: { | ||
ubootLibrem5 = final.callPackage ./u-boot { }; | ||
|
||
librem5-base = final.callPackage ./librem5-base { }; | ||
}) | ||
]; | ||
|
||
boot = { | ||
kernelParams = [ "rootwait" ]; | ||
|
||
loader = { | ||
generic-extlinux-compatible.enable = lib.mkDefault true; | ||
grub.enable = false; | ||
}; | ||
|
||
kernelPackages = lib.mkDefault pkgs.linuxPackages_librem5; | ||
}; | ||
|
||
services.udev.packages = lib.mkIf cfg.installUdevPackages [ pkgs.librem5-base ]; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ config, pkgs, lib, ... }: | ||
lib.mkIf config.hardware.librem5.customInitrdModules { | ||
boot.initrd = { | ||
kernelModules = [ | ||
"bq25890_charger" | ||
"dwc3" | ||
"imx_dcss" | ||
"imx_sdma" | ||
"mtdblock" | ||
"ofpart" | ||
"phy_fsl_imx8mq_usb" | ||
"snvs_pwrkey" | ||
"spi_nor" | ||
"tps6598x" | ||
"xhci_hcd" | ||
"usbcore" | ||
"usb_storage" | ||
"uas" | ||
"xhci_plat_hcd" | ||
]; | ||
# Not all default modules (e.g. SATA ones) are present in Librem 5 kernel fork | ||
includeDefaultModules = false; | ||
availableKernelModules = [ | ||
"ahci" | ||
|
||
"sd_mod" | ||
"sr_mod" | ||
|
||
"mmc_block" | ||
|
||
"uhci_hcd" | ||
"ehci_hcd" | ||
"ehci_pci" | ||
"ohci_hcd" | ||
"ohci_pci" | ||
"xhci_pci" | ||
"usbhid" | ||
"hid_generic" | ||
"hid_lenovo" | ||
"hid_apple" | ||
"hid_roccat" | ||
"hid_logitech_hidpp" | ||
"hid_logitech_dj" | ||
"hid_microsoft" | ||
"hid_cherry" | ||
|
||
"bq25890_charger" | ||
"dwc3" | ||
"imx_dcss" | ||
"imx_sdma" | ||
"mtdblock" | ||
"ofpart" | ||
"phy_fsl_imx8mq_usb" | ||
"snvs_pwrkey" | ||
"spi_nor" | ||
"tps6598x" | ||
"xhci_hcd" | ||
"usbcore" | ||
"usb_storage" | ||
"uas" | ||
"xhci_plat_hcd" | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ lib | ||
, buildLinux | ||
, fetchFromGitLab | ||
, ... | ||
} @ args: | ||
buildLinux (args | ||
// rec { | ||
defconfig = "librem5_defconfig"; | ||
version = "6.4.5-librem5"; | ||
modDirVersion = version; | ||
src = fetchFromGitLab { | ||
domain = "source.puri.sm"; | ||
owner = "Librem5"; | ||
repo = "linux"; | ||
rev = "pureos/6.4.5pureos1"; | ||
hash = "sha256-xg/qZ3Lig8oAAa3I+yn4tKPbftBy9Y6fnk8IvB+rm4E="; | ||
}; | ||
kernelPatches = [ ]; | ||
structuredExtraConfig = with lib.kernel; { | ||
# buildLinux overrides this and defaults to 32, so go back to the value defined librem5_defconfig | ||
# this is required for millipixels to take photos, otherwise the VIDIOC_REQ_BUFS ioctl returns ENOMEM | ||
CMA_SIZE_MBYTES = lib.mkForce (freeform "320"); | ||
}; | ||
} | ||
// args.argsOverride or { }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
final: prev: { | ||
linuxPackages_librem5_6_4_5 = final.linuxPackagesFor (final.callPackage ./6.4.5.nix { }); | ||
linuxPackages_librem5 = final.linuxPackages_librem5_6_4_5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ stdenv, fetchFromGitLab, shellcheck, kmod, lib }: | ||
stdenv.mkDerivation { | ||
pname = "librem5-base"; | ||
version = "unstable"; | ||
src = fetchFromGitLab { | ||
domain = "source.puri.sm"; | ||
owner = "Librem5"; | ||
repo = "librem5-base"; | ||
rev = "96b0f920cde9157332b0c16ba1135ee60a3f3259"; | ||
hash = "sha256-nR42dk3g0/IkVFygZ7K1SZ2KoQJeDzuMOumKdOOQS5k="; | ||
}; | ||
|
||
buildPhase = ":"; | ||
|
||
checkInputs = [ shellcheck ]; | ||
doCheck = true; | ||
checkPhase = "make"; | ||
|
||
installPhase = '' | ||
mkdir -p "$out/bin" "$out/lib/udev/rules.d" | ||
cp -v default/lockdown-support/lockdown-support.sh "$out/bin" | ||
chmod +x "$out/bin/lockdown-support.sh" | ||
cp -v default/gpsd/99-gnss.rules "$out/lib/udev/rules.d" | ||
|
||
pushd debian | ||
for rule in librem5-base-defaults.*.udev; do | ||
cp -v "$rule" "$out/lib/udev/rules.d/''${rule#*.}.rules" | ||
done | ||
popd | ||
|
||
mkdir -p "$out/etc/pulse" | ||
cp -v "default/audio/pulse/librem5.pa" "$out/etc/pulse/librem5.pa" | ||
substituteInPlace "$out/etc/pulse/librem5.pa" \ | ||
--replace ".include /etc/pulse/default.pa" "" | ||
''; | ||
|
||
postFixup = '' | ||
sed -i \ | ||
-e "s@/usr/sbin/lockdown-support.sh@$out/bin/lockdown-support.sh@g" \ | ||
-e "s@/usr/sbin/modprobe@${kmod}/bin/modprobe@g" \ | ||
-e "s@/usr/sbin/rmmod@${kmod}/bin/rmmod@g" \ | ||
"$out"/lib/udev/rules.d/*.udev.rules | ||
''; | ||
|
||
# https://source.puri.sm/Librem5/librem5-base/-/issues/68 | ||
# President@Purism promised it's under a free license: https://matrix.to/#/%23community-librem-5%3Atalk.puri.sm/%24hNCtZr7Escmr56uz1eEiaHpakteEXig7b5G8t2W6tWs | ||
meta.license = lib.licenses.free; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if useful but I'm running an u-boot that supports
/boot/extlinux/extlinux.conf
: https://forums.puri.sm/t/can-someone-with-serial-console-access-try-nixos-kernel-on-librem-5/19121/27There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why there's a custom u-boot packages in this repository. This note is still here from the previous PR I'm continuing and I haven't cleaned up everything yet.