NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.38k stars 14.33k forks source link

MCUXpresso package #161928

Open lonesomebyte537 opened 2 years ago

lonesomebyte537 commented 2 years ago

mcuxpresso ide Embedded firmware development suite for NXP mcu's

dominikstraessle commented 1 year ago

I got it working (quick and dirty) with the following derivations. The MCUXpresso IDE and MCEXpresso Config Tools are just custom eclipse builds with specialized plugins and some additional binary files.

Additionally, I also added the pkgs.segger-jlink package. In order to work with peripheral devices I had to add the mcuxpresso.ide and segger-jlink to services.udev.packages:

How to add the udev rules:

    services = {
      udev = { packages = with pkgs; [ segger-jlink mcuxpresso.ide ]; };
    };

Default

{ pkgs }: {
  ide = pkgs.callPackage ./ide.nix { inherit (pkgs.eclipses) buildEclipse; };
  tools =
    pkgs.callPackage ./tools.nix { inherit (pkgs.eclipses) buildEclipse; };
}

IDE

{ buildEclipse, stdenv, requireFile, ... }:
let
  name = "mcuxpressoide";
  version = "11.7.0_9198";
  description = "MCUXpresso IDE";
  filename = "${name}-${version}.x86_64.deb";

  src = stdenv.mkDerivation {
    inherit version description;
    name = "${name}-src";
    src = requireFile {
      url =
        "https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE";
      name = "${filename}.bin";
      sha256 =
        "27969d236fd337262768f2d35fa19e5552ed566728827ef9b7c0f28d1da5644a";
    };

    buildCommand = ''
      # Unpack tarball.
      mkdir -p deb
      sh $src --target deb || true
      ar -xv deb/${filename}
      tar xfvz data.tar.gz -C .

      mkdir -p ./final/eclipse
      mv ./usr/local/${name}-${version}/ide/* ./usr/local/${name}-${version}/ide/.* final/eclipse
      mv final/eclipse/mcuxpressoide final/eclipse/eclipse
      mv final/eclipse/mcuxpressoide.ini final/eclipse/eclipse.ini

      # Create custom .eclipseproduct file
      rm final/eclipse/.eclipseproduct
      echo "name=${name}
      id=com.nxp.${name}
      version=${version}
      " > final/eclipse/.eclipseproduct

      # Install udev rules
      mkdir -p final/lib/udev/rules.d
      mv ./lib/udev/rules.d/56-pemicro.rules ./lib/udev/rules.d/85-mcuxpresso.rules final/lib/udev/rules.d/

      # Additional files
      mv ./usr/local/${name}-${version}/mcu_data final/mcu_data

      cd ./final
      tar -czf $out ./
    '';
  };
in buildEclipse { inherit description name src; }

Config Tools

{ buildEclipse, stdenv, requireFile, ... }:
let
  name = "mcuxpressotools";
  version = "v13-1";
  description = "MCUXpresso Config Tools";
  filename = "mcuxpresso-config-tools-${version}_amd64.deb";

  src = stdenv.mkDerivation {
    inherit version description;
    name = "${name}-src";
    src = requireFile {
      url =
        "https://www.nxp.com/design/software/development-software/mcuxpresso-config-tools-pins-clocks-and-peripherals:MCUXpresso-Config-Tools";
      name = "${filename}.bin";
      sha256 = "1fccxzzzmcanqfw15glpva6xn0c39vvv4cqznwkwb49yc4x2gm4w";
    };

    buildCommand = ''
      # Unpack tarball.
      mkdir -p deb
      sh $src --target deb || true
      ar -xv deb/${filename}
      tar xfvz data.tar.gz -C .

      mkdir -p ./final/eclipse
      mv ./opt/nxp/MCUX_CFG_v13/bin/* ./opt/nxp/MCUX_CFG_v13/bin/.* final/eclipse
      mv ./usr final/
      mv final/eclipse/tools final/eclipse/eclipse
      mv final/eclipse/tools.ini final/eclipse/eclipse.ini

      # Create custom .eclipseproduct file
      echo "name=${name}
      id=com.nxp.${name}
      version=${version}
      " > final/eclipse/.eclipseproduct

      # Additional files
      mkdir -p final/usr/share/mime
      mv ./opt/nxp/MCUX_CFG_v13/mcu_data final/mcu_data

      cd ./final
      tar -czf $out ./
    '';
  };
in buildEclipse { inherit description name src; }