Skip to content

Commit 7dd2063

Browse files
bors[bot]fgaz
andauthored
Merge #662
662: star64: init r=Mic92 a=fgaz Co-authored-by: Francesco Gazzetta <[email protected]>
2 parents 429f232 + 30f71ba commit 7dd2063

14 files changed

+695
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ See code for all available configurations.
220220
| [Panasonic Let's Note CF-LX4 ](panasonic/letsnote/cf-lx4) | `<nixos-hardware/panasonic/letsnote/cf-lx4>` |
221221
| [PC Engines APU](pcengines/apu) | `<nixos-hardware/pcengines/apu>` |
222222
| [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `<nixos-hardware/pine64/pinebook-pro>` |
223+
| [PINE64 STAR64](pine64/star64/) | `<nixos-hardware/pine64/star64>` |
223224
| [Purism Librem 13v3](purism/librem/13v3) | `<nixos-hardware/purism/librem/13v3>` |
224225
| [Purism Librem 15v3](purism/librem/13v3) | `<nixos-hardware/purism/librem/15v3>` |
225226
| [Raspberry Pi 2](raspberry-pi/2) | `<nixos-hardware/raspberry-pi/2>` |

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
onenetbook-4 = import ./onenetbook/4;
160160
pcengines-apu = import ./pcengines/apu;
161161
pine64-pinebook-pro = import ./pine64/pinebook-pro;
162+
pine64-star64 = import ./pine64/star64;
162163
purism-librem-13v3 = import ./purism/librem/13v3;
163164
purism-librem-15v3 = import ./purism/librem/15v3;
164165
raspberry-pi-2 = import ./raspberry-pi/2;

pine64/star64/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Creating a SD-Image
2+
3+
Create and configure the `flake.nix` file:
4+
5+
``` nix
6+
{
7+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
8+
inputs.nixos-hardware.url = "github:nixos/nixos-hardware";
9+
10+
11+
outputs = { self, nixpkgs, nixos-hardware, flake-utils, ... }:
12+
let
13+
supportedSystems = [
14+
"x86_64-linux"
15+
"aarch64-linux"
16+
"riscv64-linux"
17+
"x86_64-darwin"
18+
"aarch64-darwin"
19+
];
20+
forAllSupportedSystems = nixpkgs.lib.genAttrs supportedSystems;
21+
in {
22+
packages = forAllSupportedSystems (system: rec {
23+
default = sd-image;
24+
sd-image = (import "${nixpkgs}/nixos" {
25+
configuration =
26+
{ config, ... }: {
27+
imports = [
28+
"${nixos-hardware}/pine64/star64/sd-image.nix"
29+
# or, for a system like an installation media:
30+
#"${nixos-hardware}/pine64/star64/sd-image-installer.nix"
31+
];
32+
33+
system.stateVersion = "23.05";
34+
networking.useDHCP = true;
35+
services.openssh.enable = true;
36+
37+
users.users.nixos = {
38+
isNormalUser = true;
39+
extraGroups = [ "wheel" ];
40+
};
41+
security.sudo.wheelNeedsPassword = false;
42+
# Set a password
43+
users.users.nixos.initialPassword = "nixos";
44+
# OR add your public ssh key
45+
#users.users.nixos.openssh.authorizedKeys.keys = [ "ssh-rsa ..." ];
46+
47+
sdImage.compressImage = false;
48+
49+
# Set if cross compiling
50+
#nixpkgs.crossSystem = {
51+
# config = "riscv64-unknown-linux-gnu";
52+
# system = "riscv64-linux";
53+
#};
54+
55+
# Additional configuration goes here
56+
};
57+
inherit system;
58+
}).config.system.build.sdImage;
59+
});
60+
};
61+
}
62+
```
63+
64+
Build the sd image.
65+
66+
``` sh
67+
nix build .#
68+
```
69+
70+
## Additional configuration
71+
72+
### 8GB memory
73+
74+
If your board has 8GB of RAM add the following to your config:
75+
76+
``` nix
77+
hardware.deviceTree.overlays = [{
78+
name = "8GB-patch";
79+
dtsFile =
80+
"${nixos-hardware}/pine64/star64/star64-8GB.dts";
81+
}];
82+
```
83+
84+
# Updating the bootloader
85+
86+
## SD-Card
87+
88+
Install the firmware update script
89+
90+
``` nix
91+
environment.systemPackages = [
92+
(pkgs.callPackage
93+
"${nixos-hardware}/pine64/star64/firmware.nix"
94+
{ }).updater-sd
95+
];
96+
```
97+
98+
Then run as root
99+
100+
``` sh
101+
star64-firmware-update-sd
102+
```
103+
104+
## SPI Flash
105+
106+
Install the firmware update script
107+
108+
``` nix
109+
environment.systemPackages = [
110+
(pkgs.callPackage
111+
"${nixos-hardware}/pine64/star64/firmware.nix"
112+
{ }).updater-flash
113+
];
114+
```
115+
116+
Then run as root
117+
118+
``` sh
119+
star64-firmware-update-flash
120+
```

pine64/star64/default.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{ config, lib, pkgs, ... }: {
2+
nixpkgs.overlays = [(self: super: {
3+
makeModulesClosure = x: super.makeModulesClosure (x // {
4+
allowMissing = true;
5+
});
6+
})];
7+
8+
# Somehow ttyS0 doesn't get enabled by default
9+
systemd.services."serial-getty@ttyS0".enable = lib.mkDefault true;
10+
systemd.services."serial-getty@ttyS0".wantedBy = lib.mkDefault [ "getty.target" ];
11+
12+
boot = {
13+
# Force no ZFS (from nixos/modules/profiles/base.nix) until updated to kernel 6.0
14+
# TODO still valid for star64?
15+
supportedFilesystems =
16+
lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];
17+
consoleLogLevel = lib.mkDefault 7;
18+
kernelPackages = lib.mkDefault (pkgs.callPackage ./linux-5.15.nix {
19+
inherit (config.boot) kernelPatches;
20+
});
21+
22+
kernelParams =
23+
lib.mkDefault [ "console=tty0" "console=ttyS0,115200n8" "earlycon=sbi" ];
24+
25+
initrd.availableKernelModules = [ "dw_mmc_starfive" ];
26+
27+
# Ethernet. The module gets forced m due to other modules even though
28+
# it's marked y in defconfig.
29+
kernelModules = [ "dwmac-starfive-plat" ];
30+
31+
loader = {
32+
grub.enable = lib.mkDefault false;
33+
generic-extlinux-compatible.enable = lib.mkDefault true;
34+
};
35+
};
36+
37+
hardware.deviceTree.name =
38+
lib.mkDefault "starfive/jh7110-pine64-star64.dtb";
39+
}

pine64/star64/firmware.nix

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{ callPackage, pkgsBuildHost, runCommand, writeText, writeShellApplication
2+
, stdenv, dtc, mtdutils, coreutils }:
3+
let
4+
uboot = callPackage ./uboot.nix { };
5+
opensbi = callPackage ./opensbi.nix {
6+
withPayload = "${uboot}/u-boot.bin";
7+
withFDT = "${uboot}/pine64_star64.dtb";
8+
};
9+
spl-tool = pkgsBuildHost.callPackage ./spl-tool.nix { };
10+
its-file = writeText "star64-uboot-fit-image.its" ''
11+
/dts-v1/;
12+
13+
/ {
14+
description = "U-boot-spl FIT image for JH7110 Star64";
15+
#address-cells = <2>;
16+
17+
images {
18+
firmware {
19+
description = "u-boot";
20+
data = /incbin/("${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin");
21+
type = "firmware";
22+
arch = "riscv";
23+
os = "u-boot";
24+
load = <0x0 0x40000000>;
25+
entry = <0x0 0x40000000>;
26+
compression = "none";
27+
};
28+
};
29+
30+
configurations {
31+
default = "config-1";
32+
33+
config-1 {
34+
description = "U-boot-spl FIT config for JH7110 Star64";
35+
firmware = "firmware";
36+
};
37+
};
38+
};
39+
'';
40+
in rec {
41+
inherit opensbi uboot;
42+
spl = stdenv.mkDerivation {
43+
name = "pine64-star64-spl";
44+
depsBuildBuild = [ spl-tool ];
45+
phases = [ "installPhase" ];
46+
installPhase = ''
47+
mkdir -p $out/share/pine64-star64/
48+
ln -s ${uboot}/u-boot-spl.bin .
49+
spl_tool -c -f ./u-boot-spl.bin
50+
cp u-boot-spl.bin.normal.out $out/share/pine64-star64/spl.bin
51+
'';
52+
};
53+
uboot-fit-image = stdenv.mkDerivation {
54+
name = "pine64-star64-uboot-fit-image";
55+
nativeBuildInputs = [ dtc ];
56+
phases = [ "installPhase" ];
57+
installPhase = ''
58+
mkdir -p $out/share/pine64-star64/
59+
${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/pine64-star64/star64_fw_payload.img
60+
'';
61+
};
62+
updater-flash = writeShellApplication {
63+
name = "star64-firmware-update-flash";
64+
runtimeInputs = [ mtdutils ];
65+
text = ''
66+
flashcp -v ${spl}/share/pine64-star64/spl.bin /dev/mtd0
67+
flashcp -v ${uboot-fit-image}/share/pine64-star64/star64_fw_payload.img /dev/mtd1
68+
'';
69+
};
70+
updater-sd = writeShellApplication {
71+
name = "star64-firmware-update-sd";
72+
runtimeInputs = [ ];
73+
text = ''
74+
dd if=${spl}/share/pine64-star64/spl.bin of=/dev/mmcblk0p1 conv=fsync
75+
dd if=${uboot-fit-image}/share/pine64-star64/star64_fw_payload.img of=/dev/mmcblk0p2 conv=fsync
76+
'';
77+
};
78+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/drivers/rtc/rtc-starfive.c b/drivers/rtc/rtc-starfive.c
2+
index 895960ff0..d567cf876 100644
3+
--- a/drivers/rtc/rtc-starfive.c
4+
+++ b/drivers/rtc/rtc-starfive.c
5+
@@ -575,7 +575,7 @@ static int sft_rtc_probe(struct platform_device *pdev)
6+
struct device *dev = &pdev->dev;
7+
struct sft_rtc *srtc;
8+
struct rtc_time tm;
9+
- struct irq_desc *desc;
10+
+ struct irq_data *data;
11+
int ret;
12+
13+
srtc = devm_kzalloc(dev, sizeof(*srtc), GFP_KERNEL);
14+
@@ -640,8 +640,8 @@ static int sft_rtc_probe(struct platform_device *pdev)
15+
srtc->rtc_dev->ops = &starfive_rtc_ops;
16+
device_init_wakeup(dev, true);
17+
18+
- desc = irq_to_desc(srtc->rtc_irq);
19+
- irq_desc_get_chip(desc)->flags = IRQCHIP_SKIP_SET_WAKE;
20+
+ data = irq_get_irq_data(srtc->rtc_irq);
21+
+ irq_data_get_irq_chip(data)->flags = IRQCHIP_SKIP_SET_WAKE;
22+
23+
/* Always use 24-hour mode and keep the RTC values */
24+
sft_rtc_set_mode(srtc, RTC_HOUR_MODE_24H);

0 commit comments

Comments
 (0)