Add ODroid M1

Based on @KhashayarDanesh's work in #1269, which is also based on the
work of @sstent and @povik.

Closes #1269
This commit is contained in:
Josh Buker 2026-01-26 15:32:14 -08:00
parent a351494b0e
commit cb8f383995
No known key found for this signature in database
GPG key ID: E077B96C5EFF10F2
5 changed files with 182 additions and 0 deletions

View file

@ -400,6 +400,7 @@ See code for all available configurations.
| [Hardkernel Odroid HC4](hardkernel/odroid-hc4/default.nix) | `<nixos-hardware/hardkernel/odroid-hc4>` | `hardkernel-odroid-hc4` |
| [Hardkernel Odroid H3](hardkernel/odroid-h3/default.nix) | `<nixos-hardware/hardkernel/odroid-h3>` | `hardkernel-odroid-h3` |
| [Hardkernel Odroid H4](hardkernel/odroid-h4/default.nix) | `<nixos-hardware/hardkernel/odroid-h4>` | `hardkernel-odroid-h4` |
| [Hardkernel Odroid M1](hardkernel/odroid-m1/default.nix) | `<nixos-hardware/hardkernel/odroid-m1>` | `hardkernel-odroid-m1` |
| [Olimex TERES-I](olimex/teres_i) | `<nixos-hardware/olimex/teres_i>` | `olimex-teres_i` |
| [Omen 14-fb0798ng](omen/14-fb0798ng) | `<nixos-hardware/omen/14-fb0798ng>` | `omen-14-fb0798ng` |
| [Omen 15-ce002ns](omen/15-ce002ns) | `<nixos-hardware/omen/15-ce002ns>` | `omen-15-ce002ns` |

View file

@ -374,6 +374,7 @@
hardkernel-odroid-hc4 = import ./hardkernel/odroid-hc4;
hardkernel-odroid-h3 = import ./hardkernel/odroid-h3;
hardkernel-odroid-h4 = import ./hardkernel/odroid-h4;
hardkernel-odroid-m1 = import ./hardkernel/odroid-m1;
omen-14-fb0798ng = import ./omen/14-fb0798ng;
omen-15-ce002ns = import ./omen/15-ce002ns;
omen-15-en0010ca = import ./omen/15-en0010ca;

View file

@ -0,0 +1,31 @@
# Based on kboot-conf by original authors povik and sstent.
# I'm just porting things over. the original work can be viewed at:
# https://github.com/sstent/nixos-on-odroid-m1
# https://github.com/povik/nixos-on-odroid-n2
{ config, pkgs, lib, ... }:
{
imports = [
./kboot-conf
];
#boot.loader.grub.enable = false;
boot.loader.kboot-conf.enable = true;
# Use kernel >6.6 The devicetree is missing from kernel versions older than this.
boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "6.6") (lib.mkDefault pkgs.linuxPackages_latest);
boot.supportedFilesystems = lib.mkForce ["btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs"];
# I'm not completely sure if some of these could be omitted,
# but want to make sure disk access works
boot.initrd.availableKernelModules = [
"nvme"
"nvme-core"
"phy-rockchip-naneng-combphy"
"phy-rockchip-snps-pcie3"
];
# Petitboot uses this port and baud rate on the boards serial port,
# it's probably good to keep the options same for the running
# kernel for serial console access to work well
boot.kernelParams = ["console=ttyS2,1500000"];
hardware.deviceTree.name = "rockchip/rk3568-odroid-m1.dtb";
}

View file

@ -0,0 +1,73 @@
{ config, lib, pkgs, ... }:
let
cfg = config.boot.loader.kboot-conf;
# The builder used to write during system activation
builder = pkgs.replaceVarsWith {
src = ./generate-kboot-conf.sh;
replacements = {
bash = pkgs.bash;
path = lib.makeBinPath [
pkgs.coreutils
pkgs.gnused
pkgs.gnugrep
];
};
name = "system-activation-generate-kboot-conf";
isExecutable = true;
};
# The builder exposed in populateCmd, which runs when building the sdImage
populateBuilder = pkgs.buildPackages.replaceVarsWith {
src = ./generate-kboot-conf.sh;
replacements = {
bash = pkgs.buildPackages.bash;
path = lib.makeBinPath [
pkgs.buildPackages.coreutils
pkgs.buildPackages.gnused
pkgs.buildPackages.gnugrep
];
};
name = "build-image-generate-kboot-conf";
isExecutable = true;
};
in
{
options = {
boot.loader.kboot-conf = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to create petitboot-compatible /kboot.conf
'';
};
configurationLimit = lib.mkOption {
default = 10;
example = 5;
type = lib.types.int;
description = ''
Maximum number of configurations in the generated kboot.conf.
'';
};
populateCmd = lib.mkOption {
type = lib.types.str;
readOnly = true;
description = ''
Contains the builder command used to populate an image,
honoring all options except the <literal>-c &lt;path-to-default-configuration&gt;</literal>
argument.
Useful to have for sdImage.populateRootCommands
'';
};
};
};
config = let
args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}";
in
lib.mkIf cfg.enable {
system.build.installBootLoader = lib.mkForce "${builder} ${args} -c";
system.boot.loader.id = "kboot-conf";
boot.loader.kboot-conf.populateCmd = "${populateBuilder} ${args}";
};
}

View file

@ -0,0 +1,76 @@
#! @bash@/bin/bash -e
shopt -s nullglob
export PATH="/empty:@path@"
usage() {
echo "usage: $0 -c <path-to-default-configuration> -n <dtbName> [-g <num-generations>] [-d <target>]" >&2
exit 1
}
target=/kboot.conf
default= # Default configuration
numGenerations=0 # Number of other generations to include in the menu
while getopts "t:c:d:g:n:" opt; do
case "$opt" in
c) default="$OPTARG" ;;
g) numGenerations="$OPTARG" ;;
d) target="$OPTARG" ;;
n) dtbName="$OPTARG" ;;
\?) usage ;;
esac
done
[ "$default" = "" -o "$dtbName" = "" ] && usage
tmp=$target.tmp
# Echo out an kboot.conf menu entry
addEntry() {
local path=$(readlink -f "$1")
local tag="$2" # Generation number or 'default'
if ! test -e $path/kernel -a -e $path/initrd; then
return
fi
timestampEpoch=$(stat -L -c '%Z' $path)
timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch)
nixosLabel="$(cat $path/nixos-version)"
extraParams="$(cat $path/kernel-params)"
local kernel=$(readlink -f "$path/kernel")
local initrd=$(readlink -f "$path/initrd")
local dtbs=$(readlink -f "$path/dtbs")
local id="nixos-$tag--$nixosLabel"
if [ "$tag" = "default" ]; then
echo "default=$id"
fi
echo -n "$id='"
echo -n "$kernel initrd=$initrd dtb=$dtbs/$dtbName "
echo -n "systemConfig=$path init=$path/init $extraParams"
echo "'"
}
echo "# Auto-generated by generate-kboot-conf.sh, do not edit" > $tmp
addEntry $default default >> $tmp
if [ "$numGenerations" -gt 0 ]; then
# Add up to $numGenerations generations of the system profile to the menu,
# in reverse (most recent to least recent) order.
for generation in $(
(cd /nix/var/nix/profiles && ls -d system-*-link) \
| sed 's/system-\([0-9]\+\)-link/\1/' \
| sort -n -r \
| head -n $numGenerations); do
link=/nix/var/nix/profiles/system-$generation-link
addEntry $link $generation
done >> $tmp
fi
mv -f $tmp $target