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

Pine64 PinePhone Pro #1073

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ See code for all available configurations.
| [Panasonic Let's Note CF-LX4](panasonic/letsnote/cf-lx4) | `<nixos-hardware/panasonic/letsnote/cf-lx4>` |
| [PC Engines APU](pcengines/apu) | `<nixos-hardware/pcengines/apu>` |
| [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `<nixos-hardware/pine64/pinebook-pro>` |
| [PINE64 Pinephone Pro](pine64/pinephone-pro/) | `<nixos-hardware/pine64/pinephone-pro>` |
| [PINE64 RockPro64](pine64/rockpro64/) | `<nixos-hardware/pine64/rockpro64>` |
| [PINE64 STAR64](pine64/star64/) | `<nixos-hardware/pine64/star64>` |
| [Protectli VP4670](protectli/vp4670/) | `<nixos-hardware/protectli/vp4670>` |
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
olimex-teres_i = import ./olimex/teres_i;
pcengines-apu = import ./pcengines/apu;
pine64-pinebook-pro = import ./pine64/pinebook-pro;
pine64-pinephone-pro = import ./pine64/pinephone-pro;
pine64-rockpro64 = import ./pine64/rockpro64;
pine64-star64 = import ./pine64/star64;
protectli-vp4670 = import ./protectli/vp4670;
Expand Down
13 changes: 13 additions & 0 deletions pine64/pinephone-pro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Pine64 PinePhone Pro
## Bootloader
Either [Tow-Boot](https://github.com/Tow-Boot/Tow-Boot) or Megi's [rk2aw](https://xnux.eu/rk2aw/) are recommended to
allow boot via `boot.loader.generic-extlinux-compatible`. rk2aw features a touch-based boot selection which should
provide the ability to choose the NixOS generation.

## Known Issues
- Audio is currently broken
- The `brcmfmac` driver regularly spews the following error `brcmf_set_channel: set chanspec 0x???? fail, reason -52`
this has been somewhat alleviated by [disabling SAE](./wifi.nix#L7) to the point of allowing WiFi to function
but the issue still remains.
- The cameras are curretly broken, patches exist but need to be rebased to be applicable
- panfrost crashes sometimes
41 changes: 41 additions & 0 deletions pine64/pinephone-pro/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
pkgs,
lib,
config,
...
}:
let
cfg = config.hardware.pinephone-pro;
in
{
imports = [ ./wifi.nix ];
options.hardware.pinephone-pro = {
install-ucm2-rules = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to install PinePhone Pro specific UCM2 rules.
These provide audio usecaseses for HiFi audio and Voice calls.
'';
};
};
config = {
nixpkgs.overlays = [
(final: _prev: {
pine64-alsa-ucm = final.callPackage ./pine64-alsa-ucm { };
firmware_pinephone-pro = pkgs.callPackage ./firmware.nix { };
linuxPackages_pinephone-pro = pkgs.callPackage ./kernel { inherit (config.boot) kernelPatches; };
})
];
hardware.firmware = [ pkgs.firmware_pinephone-pro ];
environment.systemPackages = lib.optionals cfg.install-ucm2-rules [ pkgs.pine64-alsa-ucm ];

boot = {
kernelPackages = pkgs.linuxPackagesFor pkgs.linuxPackages_pinephone-pro;
loader = {
generic-extlinux-compatible.enable = true;
grub.enable = false;
};
};
};
}
70 changes: 70 additions & 0 deletions pine64/pinephone-pro/firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# MIT License

# Copyright (c) 2018-2020 Samuel Dionne-Riel and the Mobile NixOS contributors

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

{
runCommand,
firmwareLinuxNonfree,
fetchgit,
fetchFromGitLab,
}:

let
pinephonepro-firmware = fetchFromGitLab {
domain = "gitlab.manjaro.org";
owner = "tsys";
repo = "pinebook-firmware";
rev = "937f0d52d27d7712da6a008d35fd7c2819e2b077";
sha256 = "sha256-Ij5u4IF55kPFs1BGq/sLlI3fjufwSjqrf8OZ2WnvjWI=";
};
ap6256-firmware = fetchFromGitLab {
domain = "gitlab.manjaro.org";
owner = "manjaro-arm";
repo = "packages%2Fcommunity%2Fap6256-firmware";
rev = "a30bf312b268eab42d38fab0cc3ed3177895ff5d";
sha256 = "sha256-i2OEkn7RtEMbJd0sYEE2Hpkvw6KRppz5AbwXJFNa/pE=";
};
brcm-firmware = fetchgit {
url = "https://megous.com/git/linux-firmware";
rev = "6e8e591e17e207644dfe747e51026967bb1edab5";
sha256 = "sha256-TaGwT0XvbxrfqEzUAdg18Yxr32oS+RffN+yzSXebtac=";
};
in

# The minimum set of firmware files required for the device.
runCommand "pine64-pinephonepro-firmware" { src = firmwareLinuxNonfree; } ''
for firmware in \
rockchip/dptx.bin \
; do
mkdir -p "$(dirname $out/lib/firmware/$firmware)"
cp -vrf "$src/lib/firmware/$firmware" $out/lib/firmware/$firmware
done

(PS4=" $ "; set -x
mkdir -p $out/lib/firmware/{brcm,rockchip}
(cd ${ap6256-firmware}
cp -fv *.hcd *blob *.bin *.txt $out/lib/firmware/brcm/
)
cp -fv ${pinephonepro-firmware}/brcm/* $out/lib/firmware/brcm/
cp -fv ${pinephonepro-firmware}/rockchip/* $out/lib/firmware/rockchip/
cp -fv ${brcm-firmware}/brcm/*43455* $out/lib/firmware/brcm/
)
''
3 changes: 3 additions & 0 deletions pine64/pinephone-pro/kernel/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source $stdenv/setup
cat $patches | unxz | patch -p1 -N -r -||true
cp -r $src $out
121 changes: 121 additions & 0 deletions pine64/pinephone-pro/kernel/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{ lib, version }:
with lib.kernel;
with (lib.kernel.whenHelpers version);
{

ARCH_ROCKCHIP = yes;

#charger, should always be included
CHARGER_RK818 = yes;

#needed for networking via modem as it is connected via usb
USB_USBNET = module;
USB_NET_QMI_WWAN = module;

DRM_ROCKCHIP = yes;

#gpu
DRM_PANFROST = module;

TOUCHSCREEN_GOODIX = module;

#display
DRM_PANEL_HIMAX_HX8394 = module;

#WiFi
BRCMFMAC = module;

#bluetooth
BT_HCIBTSDIO = module;

#adc
ROCKCHIP_SARADC = module;

#IMU (also covers the MPU6500)
INV_MPU6050_IIO = module;

#magnetometer
AF8133J = whenAtLeast "6.9" module;

#ambient light sensor
STK3310 = module;

#cameras
VIDEO_OV8858 = module;
VIDEO_IMX258 = module;

#flash
LEDS_SGM3140 = module;

#notification LED
LEDS_GPIO = module;

#vibrator
INPUT_GPIO_VIBRA = module;

#audio
SND_SOC_RT5616 = module;
SND_SOC_RT5640 = module;
SND_SOC_RK3399_GRU_SOUND = module;
SND_SOC_ROCKCHIP = module;

#rk video decoder
VIDEO_ROCKCHIP_VDEC = module;

#buttons
KEYBOARD_ADC = module;

KEYBOARD_PINEPHONE = module;

#Uneeded Platforms
ARCH_ACTIONS = no;
ARCH_SUNXI = no;
ARCH_ALPINE = no;
ARCH_APPLE = no;
ARCH_BCM = no;
ARCH_BERLIN = no;
ARCH_BITMAN = no;
ARCH_EXYNOS = no;
ARCH_SPARX5 = no;
ARCH_K3 = no;
ARCH_LG1k = no;
ARCH_HISI = no;
ARCH_KEEMBAY = no;
ARCH_MEDIATEK = no;
ARCH_MESON = no;
ARCH_MVEBU = no;
ARCH_NXP = no;
ARCH_MA35 = no;
ARCH_NPCM = no;
ARCH_QCOM = no;
ARCH_REALTEK = no;
ARCH_RENESAS = no;
ARCH_SEATTLE = no;
ARCH_SOCFPGA = no;
ARCH_STM32 = no;
ARCH_SYNQUACER = no;
ARCH_TEGRA = no;
ARCH_SPRD = no;
ARCH_THUNDER = no;
ARCH_THUNDER2 = no;
ARCH_UNIPHIER = no;
ARCH_VEXPRESS = no;
ARCH_VISCONTI = no;
ARCH_XGENE = no;
ARCH_ZYNQMP = no;

#Modules that are probably not needed by anyone
DRM_NOUVEAU = no;
DRM_AMDGPU = no;

#pahole causes OOM(6GiB> including zram) during build, disabling it as a mitigation
CONFIG_BPF = lib.mkForce no;
BPF_SYSCALL = lib.mkForce no;
BPF_JIT = lib.mkForce no;
BPF_JIT_ALWAYS_ON = lib.mkForce no;
BPF_JIT_DEFAULT_ON = lib.mkForce no;
PAHOLE_HAS_BTF_TAG = lib.mkForce no;
DEBUG_INFO_BTF = lib.mkForce no;
DEBUG_INFO_BTF_MODULES = lib.mkForce no;

}
58 changes: 58 additions & 0 deletions pine64/pinephone-pro/kernel/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
lib,
fetchFromGitLab,
fetchurl,
kernelPatches,
callPackage,
buildLinux,
...
}@args:
let
pver = "6.6.44";

src_pine64 = fetchFromGitLab {
owner = "pine64-org";
repo = "linux";
rev = "ppp-6.6-20231104-22589";
sha256 = "sha256-wz2g+wE1DmhQQoldeiWEju3PaxSTIcqLSwamjzry+nc=";
};
#apply mainline fixver patches
upstream_patch = fetchurl {
url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/patch-${pver}.xz";
hash = "sha256-SSDqB/mqUmEWcf7fhZ3RRvGc2wvauORBuVl2ovJjX5M=";
};

ksrc = import ./source.nix;

apply_patch = (
path: {
name = builtins.baseNameOf path;
patch = path;
}
);
patches = [ ];
in
buildLinux (
args
// {
version = pver;
# todo: find out why builder complains about patch-version
modDirVersion = "${lib.versions.majorMinor pver}.0";
src = callPackage ksrc {
inherit pver upstream_patch;
src = src_pine64;
};
features = { };

Choose a reason for hiding this comment

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

This line confuses me. features is empty by default and is not passed in on line 27 of pine64/pinephone-pro/default.nix. args.argsOverride comes later, so will override this. Could you explain what this line does?

Copy link
Author

Choose a reason for hiding this comment

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

you are right. i was testing some features and forgot to completely remove it, as it is not present in my current development branch.

structuredExtraConfig = import ./config.nix {
inherit lib;
version = pver;
};

kernelPatches = kernelPatches ++ map apply_patch patches;
extraMeta = {
platforms = lib.platforms.aarch64;
hydraPlatforms = [ "aarch64-linux" ];
};
}
// args.argsOverride or { }
)
21 changes: 21 additions & 0 deletions pine64/pinephone-pro/kernel/source.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
pkgs,
stdenv,
pver,
src,
upstream_patch,
...
}@args:
# Applies the full patch since last mainline which contains some previous patches causing it to fail
# which will work here as the builder doesn't use "set -e"
stdenv.mkDerivation {
name = "kernel-source";
version = pver;
src = src;
patches = upstream_patch;
buildInputs = [
pkgs.patch
pkgs.xz
];
builder = ./builder.sh;
}
46 changes: 46 additions & 0 deletions pine64/pinephone-pro/pine64-alsa-ucm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# MIT License

# Copyright (c) 2018-2020 Samuel Dionne-Riel and the Mobile NixOS contributors

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

{ stdenv, pkgs, ... }:

stdenv.mkDerivation rec {
name = "pine64-alsa-ucm";
Copy link
Member

Choose a reason for hiding this comment

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

Nixpkgs maintainer are a bit uneasy to have all these kernel forks in nixpkgs, but I think it would be fine to have this package and the firmware also being part of nixpkgs.

version = "ec0ef36b8b897ed1ae6bb0d0de13d5776f5d3659";

src = pkgs.fetchFromGitLab {
owner = "pine64-org";
repo = "pine64-alsa-ucm";
rev = version;
sha256 = "sha256-nsZXBB5VpF0YpfIS+/SSHMlPXSyIGLZSOkovjag8ifU=";
};

patches = [ ./repoint-pinephone-pro.patch ];

installPhase = ''
ucm_path=$out/share/alsa/ucm2/

mkdir -p $ucm_path/PinePhone $ucm_path/PinePhonePro $ucm_path/conf.d/simple-card
ln -s ../../PinePhonePro/PinePhonePro.conf $ucm_path/conf.d/simple-card/PinePhonePro.conf

cp -r ucm2/* $ucm_path/
'';
}
Loading
Loading