Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from samueldr/feature/2021-05-upgrades
Browse files Browse the repository at this point in the history
Early 2021 upgrades
  • Loading branch information
samueldr authored May 20, 2021
2 parents 497b7f7 + c75cfa3 commit 201c9ef
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 12,668 deletions.
100 changes: 53 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,51 @@ Clone this repository somwhere, and in your configuration.nix
That entry point will try to stay unopinionated, while maximizing the hardware
compatibility.

## Compatibility

### Tested
## Current state

* X11 with modesetting
* Wi-Fi
* Brightness controls
* Speaker output
*A whole lot of untested*.

### Untested
You can look at the previous state to see that the basic stuff works. But I
find listing everything as working is hard.

* Bluetooth
What's untested and not working will be listed here at some point. Maybe.

### Known issues

* Suspend (or resume) fails.
#### `rockchipdrm` and `efifb`

### Tips
`CONFIG_FB_EFI` has been disabled in the customized kernel as `rockchipdrm`
will not render the VT if `efifb` is present.

Be careful if using the mainline kernel instead, as it will have
`CONFIG_FB_EFI` set to `y`.

#### *EFI* and poweroff

When booted using EFI, the system will not power off. It will stay seemingly
stuck with the LED and display turned off.

Power it off by holding the power button for a while (10-15 seconds).

Otherwise you might have a surprise and find the battery is flat!

The backlight can be controlled using `light` (`programs.light.enable`).

## Image build

```
$ ./build.sh
$ lsblk /dev/mmcblk0 && sudo dd if=$(echo result/sd-image/*.img) of=/dev/mmcblk0 bs=8M oflag=direct status=progress
```
> **NOTE**: These images will be built without an *Initial Boot Firmware*.
The `build.sh` script transmits parameters to `nix-build`, so e.g. `-j0` can
be used.
### SD image

Once built, this image is self-sufficient, meaning that it should already be
booting, no need burn u-boot to it.
```
$ nix-build -A sdImage
```

The required modules (and maybe a bit more) are present in stage-1 so the
display should start early enough in the boot process.
### ISO image

The LED should start up with the amber colour ASAP with this u-boot
configuration, as a way to show activity early. The kernel should set it to
green as soon as it can.
```
$ nix-build -A isoImage
```

## Note about cross-compilation

Expand All @@ -64,41 +69,42 @@ When cross-compiled, all caveats apply. Here this mainly means that the kernel
will need to be re-compiled on the device on the first nixos-rebuild switch,
while most other packages can be fetched from the cache.

## `u-boot`

Assuming `/dev/mmcblk0` is an SD card.
For cross-compilation, you might have to provide a path to a known-good Nixpkgs
checkout. *(Left as an exercis to the reader.)*

```
$ nix-build -A pkgs.uBootPinebookPro
$ lsblk /dev/mmcblk0 && sudo dd if=result/idbloader.img of=/dev/mmcblk0 bs=512 seek=64 oflag=direct,sync && sudo dd if=result/u-boot.itb of=/dev/mmcblk0 bs=512 seek=16384 oflag=direct,sync
$ NIX_PATH=nixpkgs=/path/to/known/working/cross-compilation-friendly/nixpkgs
```

The eMMC has to be zeroed (in the relevant sectors) or else the RK3399 will use
the eMMC as a boot device first.
## *Initial Boot Firmware*

Alternatively, this u-boot can be installed to the eMMC.
> **NOTE**: The previously available customized *U-Boot* from this repository
> are not available anymore.
Installing to SPI has yet to be investigated.
### *Tow-Boot*

### Updating eMMC u-boot from NixOS
I highly suggest installing *Tow-Boot* to the SPI Flash.

**Caution:** this could render your system unbootable. Do this when you are in
a situation where you can debug and fix the system if this happens. With this
said, it should be safe enough.
- https://github.com/Tow-Boot/Tow-Boot

```
$ nix-build -A pkgs.uBootPinebookPro
$ lsblk /dev/disk/by-path/platform-fe330000.sdhci && sudo dd if=result/idbloader.img of=/dev/disk/by-path/platform-fe330000.sdhci bs=512 seek=64 oflag=direct,sync && sudo dd if=result/u-boot.itb of=/dev/disk/by-path/platform-fe330000.sdhci bs=512 seek=16384 oflag=direct,sync
```
Having the firmware installed to SPI makes the device act basically like a
normal computer. No need for weird incantations to setup the initial boot
firmware.

Alternatively, starting from the *Tow-Boot* disk image on eMMC is easier to
deal with and understand than having to deal with *U-Boot* manually.

### Alternative boot order

If you rather USB and SD card is tried before the eMMC, `pkgs.uBootPinebookProExternalFirst`
can be installed, which has an alternative patch set added on top that will
change the boot order.
### Mainline *U-Boot*

Mainline U-Boot has full support for graphics since 2021.04. The current
unstable relases of Nixpkgs are at 2021.04 at least.

```
$ nix-build -A pkgs.ubootPinebookPro
```

The SD image is built using the "alternative boot order" u-boot. Thus, flashing
the image to your eMMC keeps external devices bootable.
Note that the default U-Boot build does not do anything with LED on startup.


## Keyboard firmware
Expand Down
16 changes: 0 additions & 16 deletions build.sh

This file was deleted.

24 changes: 0 additions & 24 deletions configuration.nix

This file was deleted.

46 changes: 35 additions & 11 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
{
pkgs ? import <nixpkgs> {
overlays = [
(import ./overlay.nix)
];
}
}:
{ pkgs ? import <nixpkgs> {} }:

let pkgs' = pkgs; in
let
pkgs' = if builtins.currentSystem == "aarch64-linux"
then pkgs
else pkgs.pkgsCross.aarch64-multiplatform
pkgs = if !isCross then pkgs' else pkgs'.pkgsCross.aarch64-multiplatform;
inherit (pkgs) lib;
isCross = builtins.currentSystem != "aarch64-linux";

fromPkgs = path: pkgs.path + "/${path}";
evalConfig = import (fromPkgs "nixos/lib/eval-config.nix");

buildConfig = { system ? "aarch64-linux", configuration ? {} }:
evalConfig {
modules = (lib.optional isCross ./cross-hacks.nix)
++ [
"${./.}/pinebook_pro.nix"
configuration
(lib.mkIf isCross {
nixpkgs.crossSystem = {
system = "aarch64-linux";
};
})
];
}
;
base = buildConfig {};
in
{
pkgs = pkgs';
inherit (base) pkgs;

kernel_latest = base.pkgs.linuxPackages_pinebookpro_latest.kernel;
kernel_lts = base.pkgs.linuxPackages_pinebookpro_lts.kernel;

isoImage = (buildConfig {
configuration = (fromPkgs "nixos/modules/installer/cd-dvd/installation-cd-minimal.nix");
}).config.system.build.isoImage;

sdImage = (buildConfig {
configuration = (fromPkgs "nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix");
}).config.system.build.sdImage;
}
41 changes: 41 additions & 0 deletions firmware/ap6256-firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ lib
, fetchFromGitLab
, fetchurl
, runCommandNoCC
}:

let
nhp = patch: sha256: let rev = "c74b23b8766e4cfc50d1197e6dcd08cc1625866f"; in fetchurl {
url = "https://raw.githubusercontent.com/nadiaholmquist/pbp-packages/${rev}/ap6256-firmware/${patch}";
inherit sha256;
};
in
runCommandNoCC "pinebookpro-ap6256-firmware" {
meta = with lib; {
license = licenses.unfreeRedistributable;
};
} ''
(PS4=" $ "; set -x
cp ${(nhp "BCM4345C5.hcd" "1vl3gkgdqdlhyg9dyflqi6icglr2pll6zr82147g69pfvp6ckv96")} "BCM4345C5.hcd"
cp ${(nhp "fw_bcm43456c5_ag.bin" "03qqgzjz152zaj9y0ppqqsqs03yzi8sb71rfvr29zc1xg1x74y3r")} "fw_bcm43456c5_ag.bin"
cp ${(nhp "brcmfmac43456-sdio.clm_blob" "0bi5y3qkqx95c6bb872slw0kig14c453r33j14qyb2f7id8m08lf")} "brcmfmac43456-sdio.clm_blob"
cp ${(nhp "nvram_ap6256.txt" "1zsnswiiwx50pbwl8574xa7z07v9iyfajxccbfrnc8ap99gzpvj3")} "nvram_ap6256.txt"
mkdir -p $out/lib/firmware/brcm
# https://github.com/nadiaholmquist/pbp-packages/blob/ded66e50064c55a56a958558ab35bc6bae444e72/ap6256-firmware/PKGBUILD#L22
# Bluetooth firmware
install -Dm644 "BCM4345C5.hcd" -t "$out/lib/firmware/"
install -Dm644 "BCM4345C5.hcd" "$out/lib/firmware/brcm/BCM.hcd"
install -Dm644 "BCM4345C5.hcd" -t "$out/lib/firmware/brcm/"
# Wifi firmware
install -Dm644 "nvram_ap6256.txt" -t "$out/lib/firmware/"
install -Dm644 "fw_bcm43456c5_ag.bin" "$out/lib/firmware/brcm/brcmfmac43456-sdio.bin"
install -Dm644 "brcmfmac43456-sdio.clm_blob" "$out/lib/firmware/brcm/brcmfmac43456-sdio.clm_blob"
install -Dm644 "nvram_ap6256.txt" "$out/lib/firmware/brcm/brcmfmac43456-sdio.radxa,rockpi4b.txt"
install -Dm644 "nvram_ap6256.txt" "$out/lib/firmware/brcm/brcmfmac43456-sdio.radxa,rockpi4c.txt"
install -Dm644 "nvram_ap6256.txt" "$out/lib/firmware/brcm/brcmfmac43456-sdio.pine64,pinebook-pro.txt"
install -Dm644 "nvram_ap6256.txt" "$out/lib/firmware/brcm/brcmfmac43456-sdio.pine64,rockpro64-v2.1.txt"
)
''
35 changes: 0 additions & 35 deletions firmware/default.nix

This file was deleted.

Loading

0 comments on commit 201c9ef

Please sign in to comment.