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

ubootOdroidN2: init #245100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions pkgs/by-name/me/meson64-tools/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
lib,
stdenv,
fetchFromGitHub,
buildPackages,
}:

stdenv.mkDerivation rec {
pname = "meson64-tools";
version = "unstable-2023-07-25";

src = fetchFromGitHub {
owner = "angerman";
repo = pname;
rev = "b09cefd1e001dbba14036857bf6e167bf1833f26";
hash = "sha256-/koIsslDNpaFHf1TV/0Xt0TiyhjL6tCz2oHQraYNhPA=";
};

nativeBuildInputs = with buildPackages; [
openssl
bison
flex
bc
python3
];

preBuild = ''
patchShebangs --build .
patchShebangs --build ./mbedtls/scripts/generate_psa_constants.py
substituteInPlace mbedtls/programs/fuzz/Makefile --replace "python2" "python"
substituteInPlace mbedtls/tests/Makefile --replace "python2" "python"
'';

# Also prefix tool names since some names are really generic (e.g. `pkg`).
# Otherwise something could shadow those generic names in other builds.
postInstall = ''
(cd $out/bin
for bin in *; do
ln -s $bin meson64-g12-$bin
done
)
'';

makeFlags = [ "PREFIX=$(out)/bin" ];

meta = with lib; {
homepage = "https://github.com/angerman/meson64-tools";
description = "Tools for Amlogic G12 platforms";
license = licenses.mit;
maintainers = with maintainers; [ oddlama ];
};
}
60 changes: 49 additions & 11 deletions pkgs/misc/uboot/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
, gnutls
, installShellFiles
, libuuid
, meson64-tools
, meson-tools
, ncurses
, openssl
Expand Down Expand Up @@ -136,6 +137,48 @@ let
maintainers = with maintainers; [ bartsch dezgeg lopsided98 ];
} // extraMeta;
} // removeAttrs args [ "extraMeta" "pythonScriptsToInstall" ]));

amlogic-boot-fip = fetchFromGitHub {
owner = "LibreELEC";
repo = "amlogic-boot-fip";
rev = "4369a138ca24c5ab932b8cbd1af4504570b709df";
sha256 = "sha256-mGRUwdh3nW4gBwWIYHJGjzkezHxABwcwk/1gVRis7Tc=";
meta.license = lib.licenses.unfreeRedistributableFirmware;
};

# Flashing instructions:
# dd if=${drv}/u-boot.bin.sd.bin of=$DEV conv=fsync,notrunc bs=512 skip=1 seek=1
# dd if=${drv}/u-boot.bin.sd.bin of=$DEV conv=fsync,notrunc bs=1 count=440
Copy link
Member

Choose a reason for hiding this comment

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

If you have an expression for building SD image which uses this, you can put these into sdImage.postBuildCommands, check out https://github.com/novena-next/nixos-novena/blob/master/configuration.nix#L62-L64

The comment is fine of course, it's just something you might find interesting. 😄

buildUBootOdroidN2 = fipDirectory: buildUBoot {
defconfig = "odroid-n2_defconfig";
extraMeta.platforms = ["aarch64-linux"];
filesToInstall = ["u-boot.bin"];
postBuild = ''
mkdir $out

FIPDIR=${amlogic-boot-fip}/${fipDirectory}
${buildPackages.meson64-tools}/bin/meson64-g12-pkg --type bl30 --output bl30.pkg $FIPDIR/bl30.bin $FIPDIR/bl301.bin
${buildPackages.meson64-tools}/bin/meson64-g12-pkg --type bl2 --output bl2.pkg $FIPDIR/bl2.bin $FIPDIR/acs.bin
${buildPackages.meson64-tools}/bin/meson64-g12-bl30sig --input bl30.pkg --output bl30.30sig
${buildPackages.meson64-tools}/bin/meson64-g12-bl3sig --input bl30.30sig --output bl30.3sig
${buildPackages.meson64-tools}/bin/meson64-g12-bl3sig --input $FIPDIR/bl31.img --output bl31.3sig
${buildPackages.meson64-tools}/bin/meson64-g12-bl3sig --input u-boot.bin --output bl33.3sig
${buildPackages.meson64-tools}/bin/meson64-g12-bl2sig --input bl2.pkg --output bl2.2sig
${buildPackages.meson64-tools}/bin/meson64-g12-bootmk --output $out/u-boot.bin \
--bl2 bl2.2sig \
--bl30 bl30.3sig \
--bl31 bl31.3sig \
--bl33 bl33.3sig \
--ddrfw1 $FIPDIR/ddr4_1d.fw \
--ddrfw2 $FIPDIR/ddr4_2d.fw \
--ddrfw3 $FIPDIR/ddr3_1d.fw \
--ddrfw4 $FIPDIR/piei.fw \
--ddrfw5 $FIPDIR/lpddr4_1d.fw \
--ddrfw6 $FIPDIR/lpddr4_2d.fw \
--ddrfw7 $FIPDIR/diag_lpddr4.fw \
--ddrfw8 $FIPDIR/aml_ddr.fw
'';
};
in {
inherit buildUBoot;

Expand Down Expand Up @@ -246,15 +289,7 @@ in {
# Flashing instructions:
# dd if=u-boot.gxl.sd.bin of=<sdcard> conv=fsync,notrunc bs=512 skip=1 seek=1
# dd if=u-boot.gxl.sd.bin of=<sdcard> conv=fsync,notrunc bs=1 count=444
ubootLibreTechCC = let
firmwareImagePkg = fetchFromGitHub {
owner = "LibreELEC";
repo = "amlogic-boot-fip";
rev = "4369a138ca24c5ab932b8cbd1af4504570b709df";
sha256 = "sha256-mGRUwdh3nW4gBwWIYHJGjzkezHxABwcwk/1gVRis7Tc=";
meta.license = lib.licenses.unfreeRedistributableFirmware;
};
in
ubootLibreTechCC =
assert stdenv.buildPlatform.system == "x86_64-linux"; # aml_encrypt_gxl is a x86_64 binary
buildUBoot {
defconfig = "libretech-cc_defconfig";
Expand All @@ -263,8 +298,8 @@ in {
postBuild = ''
# Copy binary files & tools from LibreELEC/amlogic-boot-fip, and u-boot build to working dir
mkdir $out tmp
cp ${firmwareImagePkg}/lepotato/{acs.bin,bl2.bin,bl21.bin,bl30.bin,bl301.bin,bl31.img} \
${firmwareImagePkg}/lepotato/{acs_tool.py,aml_encrypt_gxl,blx_fix.sh} \
cp ${amlogic-boot-fip}/lepotato/{acs.bin,bl2.bin,bl21.bin,bl30.bin,bl301.bin,bl31.img} \
${amlogic-boot-fip}/lepotato/{acs_tool.py,aml_encrypt_gxl,blx_fix.sh} \
u-boot.bin tmp/
cd tmp
python3 acs_tool.py bl2.bin bl2_acs.bin acs.bin 0
Expand Down Expand Up @@ -366,6 +401,9 @@ in {
'';
};

ubootOdroidN2 = buildUBootOdroidN2 "odroid-n2";
ubootOdroidN2Plus = buildUBootOdroidN2 "odroid-n2-plus";

ubootOdroidXU3 = buildUBoot {
defconfig = "odroid-xu3_defconfig";
extraMeta.platforms = ["armv7l-linux"];
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26501,6 +26501,8 @@ with pkgs;
ubootNanoPCT6
ubootNovena
ubootOdroidC2
ubootOdroidN2
ubootOdroidN2Plus
ubootOdroidXU3
ubootOlimexA64Olinuxino
ubootOlimexA64Teres1
Expand Down