diff options
Diffstat (limited to 'nix')
-rw-r--r-- | nix/overlay.nix | 1 | ||||
-rw-r--r-- | nix/rootfs-bootstrap-cross/default.nix | 17 | ||||
-rw-r--r-- | nix/rootfs-bootstrap-cross/ext4-image.nix | 81 | ||||
-rw-r--r-- | nix/rootfs-bootstrap-cross/installer-configuration.nix | 89 | ||||
-rw-r--r-- | nix/rootfs-bootstrap-cross/sample-configuration.nix | 107 | ||||
-rw-r--r-- | nix/u-boot/0001-add-extlinux-vars.patch | 100 | ||||
-rw-r--r-- | nix/u-boot/0001-m1n1-fdt-compat.patch | 401 | ||||
-rw-r--r-- | nix/u-boot/default.nix | 6 |
8 files changed, 2 insertions, 800 deletions
diff --git a/nix/overlay.nix b/nix/overlay.nix index cfdab3945a78..63e8df7e87a4 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -21,7 +21,6 @@ in { u-boot = lib.genAttrs compatibleDTs ( name: callPackage ./u-boot { withDeviceTree = name; } ); - rootfs-bootstrap-cross = callPackage ./rootfs-bootstrap-cross {}; installer-bootstrap-cross = callPackage ./installer-bootstrap-cross {}; }); } diff --git a/nix/rootfs-bootstrap-cross/default.nix b/nix/rootfs-bootstrap-cross/default.nix deleted file mode 100644 index 15e1aabe324c..000000000000 --- a/nix/rootfs-bootstrap-cross/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -# mod of https://github.com/samueldr/cross-system/blob/master/default.nix - -{ pkgs }: - -let - nixpkgsPath = pkgs.path; - fromPkgs = path: pkgs.path + "/${path}"; - evalConfig = import (fromPkgs "nixos/lib/eval-config.nix"); -in (evalConfig { - specialArgs = { - inherit nixpkgsPath; - }; - modules = [ - ./installer-configuration.nix - ./ext4-image.nix - ]; -}).config.system.build.ext4Image diff --git a/nix/rootfs-bootstrap-cross/ext4-image.nix b/nix/rootfs-bootstrap-cross/ext4-image.nix deleted file mode 100644 index 9e322a8e8b52..000000000000 --- a/nix/rootfs-bootstrap-cross/ext4-image.nix +++ /dev/null @@ -1,81 +0,0 @@ -# mod of https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/sd-card/sd-image.nix - -{ config, lib, pkgs, ... }: - -with lib; - -let - rootfsImage = pkgs.callPackage "${pkgs.path}/nixos/lib/make-ext4-fs.nix" ({ - inherit (config.sdImage) storePaths; - compressImage = false; - populateImageCommands = config.sdImage.populateRootCommands; - volumeLabel = "NIXOS_SD"; - } // optionalAttrs (config.sdImage.rootPartitionUUID != null) { - uuid = config.sdImage.rootPartitionUUID; - }); - - # we use tar and gzip to compress the image instead of the default zstd so - # that it can be transferred and decompressed in recoveryOS (which doesn't - # even have bare gzip, only tar!!!) - compressedImage = if !config.sdImage.compressImage then rootfsImage else ( - pkgs.callPackage ({ pigz }: rootfsImage.overrideAttrs (o: { - name = o.name + ".tar.gz"; - nativeBuildInputs = o.nativeBuildInputs ++ [ pigz ]; - buildCommand = '' - imgout=$out - out=nixos_root.img - '' + o.buildCommand + '' - out=$imgout - echo "Compressing image" - tar c nixos_root.img | pigz -p $NIX_BUILD_CORES -c > $out - ''; - }) - )) {}; -in -{ - config = { - system.build.ext4Image = let - ext4Name = replaceStrings ["sd"] ["ext4"] config.sdImage.imageName; - in pkgs.callPackage ({ stdenv }: stdenv.mkDerivation { - name = ext4Name; - - inherit (config.sdImage) compressImage; - - buildCommand = '' - mkdir -p $out/nix-support $out/ext4-image - export img=$out/ext4-image/nixos_root.img - if test -n "$compressImage"; then - export img=$img.tar.gz - fi - - echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system - echo "file ext4-image $img" >> $out/nix-support/hydra-build-products - - ln -s ${compressedImage} $img - ''; - }) {}; - - sdImage.expandOnBoot = lib.mkForce false; - - boot.postBootCommands = '' - # On the first boot do some maintenance tasks - if [ -f /nix-path-registration ]; then - set -euo pipefail - set -x - # Figure out device names for the boot device and root filesystem. - rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /) - bootDevice=$(lsblk -npo PKNAME $rootPart) - partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}') - # Resize the filesystem to fit the disk - ${pkgs.e2fsprogs}/bin/resize2fs $rootPart - # Register the contents of the initial Nix store - ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration - # nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag. - touch /etc/NIXOS - ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system - # Prevents this from running on later boots. - rm -f /nix-path-registration - fi - ''; - }; -} diff --git a/nix/rootfs-bootstrap-cross/installer-configuration.nix b/nix/rootfs-bootstrap-cross/installer-configuration.nix deleted file mode 100644 index f5c2d9c57c42..000000000000 --- a/nix/rootfs-bootstrap-cross/installer-configuration.nix +++ /dev/null @@ -1,89 +0,0 @@ -# this configuration is intended to have just enough stuff to get the disk, -# display, USB input, and network up so the user can build a real config. - -# based on https://github.com/samueldr/cross-system/blob/master/configuration.nix - -{ config, pkgs, lib, nixpkgsPath, ... }: - -{ - imports = [ - (nixpkgsPath + "/nixos/modules/profiles/minimal.nix") - (nixpkgsPath + "/nixos/modules/profiles/installation-device.nix") - (nixpkgsPath + "/nixos/modules/installer/sd-card/sd-image.nix") - ]; - - sdImage.populateRootCommands = '' - mkdir -p ./files/boot - ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot - - mkdir -p ./files/etc/nixos/kernel - cp -r ${../kernel}/* ./files/etc/nixos/kernel - cp ${./sample-configuration.nix} ./files/etc/nixos/configuration.nix - chmod +w -R ./files/etc/nixos/ - ''; - - installer.cloneConfig = false; - - boot.loader.grub.enable = false; - boot.loader.generic-extlinux-compatible.enable = true; - - boot.consoleLogLevel = 7; - - boot.kernelParams = [ - "earlycon" - "console=ttySAC0,1500000" - "console=tty0" - "debug" - "boot.shell_on_fail" - ]; - - boot.kernelPackages = pkgs.callPackage ../kernel { nativeBuild = false; }; - - # our kernel config is weird and doesn't have these modules as modules - boot.initrd.availableKernelModules = lib.mkForce []; - - # save space and compilation time. might revise? - hardware.enableAllFirmware = lib.mkForce false; - hardware.enableRedistributableFirmware = lib.mkForce false; - sound.enable = false; - networking.wireless.enable = false; - documentation.nixos.enable = lib.mkOverride 49 false; - system.extraDependencies = lib.mkForce [ ]; - - hardware.wirelessRegulatoryDatabase = true; - hardware.firmware = [ - # all the firmware is big, but including the tigon one avoids an awkward - # minute long hang on mac mini - (pkgs.stdenv.mkDerivation { - name = "tigon-firmware"; - buildCommand = '' - mkdir -p $out/lib/firmware - cp -r ${pkgs.firmwareLinuxNonfree}/lib/firmware/tigon $out/lib/firmware - ''; - }) - ]; - - # (Failing build in a dep to be investigated) - security.polkit.enable = false; - - # cifs-utils fails to cross-compile - # Let's simplify this by removing all unneeded filesystems from the image. - boot.supportedFilesystems = lib.mkForce [ "vfat" ]; - - # texinfoInteractive has trouble cross-compiling - documentation.info.enable = lib.mkForce false; - - # `xterm` is being included even though this is GUI-less. - # → https://github.com/NixOS/nixpkgs/pull/62852 - services.xserver.desktopManager.xterm.enable = lib.mkForce false; - - # ec6224b6cd147943eee685ef671811b3683cb2ce re-introduced udisks in the installer - # udisks fails due to gobject-introspection being not cross-compilation friendly. - services.udisks2.enable = lib.mkForce false; - - networking.firewall.enable = false; - - nixpkgs.crossSystem = { - system = "aarch64-linux"; - }; -} diff --git a/nix/rootfs-bootstrap-cross/sample-configuration.nix b/nix/rootfs-bootstrap-cross/sample-configuration.nix deleted file mode 100644 index 99c3272f01ef..000000000000 --- a/nix/rootfs-bootstrap-cross/sample-configuration.nix +++ /dev/null @@ -1,107 +0,0 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible online at -# https://nixos.org/manual/nixos/stable/index.html#sec-installation). - -{ config, pkgs, lib, ... }: - -{ - # Enables the generation of /boot/extlinux/extlinux.conf - # GRUB cannot correctly load device trees, so do not change this. - boot.loader.grub.enable = false; - boot.loader.generic-extlinux-compatible.enable = true; - - # Use the customized Asahi Linux kernel. - # If you wish to modify the kernel, see /etc/nixos/kernel/default.nix. - - # IMPORTANT: if you have to build the kernel on the Mac itself, set - # nativeBuild here to `true`. If you don't, Nix will complain that it - # cannot find an x86_64-linux builder. - boot.kernelPackages = pkgs.callPackage ./kernel { nativeBuild = false; }; - - boot.consoleLogLevel = 7; - boot.kernelParams = lib.mkForce [ - "earlycon" - "console=ttySAC0,1500000" - "console=tty0" - "debug" - "boot.shell_on_fail" - ]; - - # networking.hostName = "nixos"; # Define your hostname. - - # Set your time zone. - # time.timeZone = "Europe/Amsterdam"; - - # Change this to the name of your interface, available via `ip addr`. - # `enp3s0` is the internal interface on the Mac mini. - networking.interfaces.enp3s0.useDHCP = true; - - # Configure network proxy if necessary - # networking.proxy.default = "http://user:password@proxy:port/"; - # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - - # Select internationalisation properties. - # i18n.defaultLocale = "en_US.UTF-8"; - # console = { - # font = "Lat2-Terminus16"; - # keyMap = "us"; - # }; - - # Enable the X11 windowing system and at least one desktop manager. - # services.xserver.enable = true; - # services.xserver.desktopManager.xfce.enable = true; - - # Configure keymap in X11 - # services.xserver.layout = "us"; - # services.xserver.xkbOptions = "eurosign:e"; - - # Enable touchpad support (enabled default in most desktopManager). - # services.xserver.libinput.enable = true; - - # List packages installed in system profile. To search, run: - # $ nix search wget - environment.systemPackages = with pkgs; [ - # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. - # wget - # firefox - ]; - - # Some programs need SUID wrappers, can be configured further or are - # started in user sessions. - # programs.mtr.enable = true; - # programs.gnupg.agent = { - # enable = true; - # enableSSHSupport = true; - # }; - - # List services that you want to enable: - - # Enable the OpenSSH daemon. - # services.openssh.enable = true; - - # nftables support is not yet in the kernel config, so enabling the firewall - # does not work yet - networking.firewall.enable = false; - - # our kernel config is weird so don't try to include any modules - boot.initrd.availableKernelModules = lib.mkForce [ ]; - - # do not change these, they match the built root FS and partition layout - fileSystems."/" = - { device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888"; - fsType = "ext4"; - }; - swapDevices = [ ]; - - hardware.firmware = [ pkgs.firmwareLinuxNonfree ]; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "22.05"; # Did you read the comment? - -} diff --git a/nix/u-boot/0001-add-extlinux-vars.patch b/nix/u-boot/0001-add-extlinux-vars.patch deleted file mode 100644 index 81a5054164d8..000000000000 --- a/nix/u-boot/0001-add-extlinux-vars.patch +++ /dev/null @@ -1,100 +0,0 @@ -diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c -index d61ab1ee1e..8e4b00293c 100644 ---- a/arch/arm/mach-apple/board.c -+++ b/arch/arm/mach-apple/board.c -@@ -73,11 +73,58 @@ static struct mm_region apple_mem_map[] = { - - struct mm_region *mem_map = apple_mem_map; - -+static void apple_set_env_fdt_file(void) -+{ -+ char dtb_name[64]; -+ -+ if (env_get("fdtfile")) -+ return; -+ -+ const char *soc = NULL; -+ const char *product = NULL; -+ -+ int num_compats = fdt_stringlist_count(gd->fdt_blob, 0, "compatible"); -+ if (num_compats < 0) -+ return; -+ -+ for (int i=0; i<num_compats; i++) -+ { -+ const char *compat = fdt_stringlist_get( -+ gd->fdt_blob, 0, "compatible", i, NULL); -+ -+ compat = strchr(compat, ','); -+ if (!compat) -+ continue; -+ compat++; -+ -+ if (*compat == 't') { -+ soc = compat; -+ } else if (*compat == 'j') { -+ product = compat; -+ } -+ } -+ -+ if (!soc || !product) -+ return; -+ -+ snprintf(dtb_name, sizeof(dtb_name), "apple/%s-%s.dtb", soc, product); -+ dtb_name[sizeof(dtb_name)-1] = '\0'; -+ -+ env_set("fdtfile", dtb_name); -+} -+ - int board_init(void) - { - return 0; - } - -+int board_late_init(void) -+{ -+ apple_set_env_fdt_file(); -+ -+ return 0; -+} -+ - int dram_init(void) - { - ofnode node; -diff --git a/configs/apple_m1_defconfig b/configs/apple_m1_defconfig -index 85687fe234..afb89202f6 100644 ---- a/configs/apple_m1_defconfig -+++ b/configs/apple_m1_defconfig -@@ -1,5 +1,6 @@ - CONFIG_ARM=y - CONFIG_ARCH_APPLE=y -+CONFIG_BOARD_LATE_INIT=y - # CONFIG_DISPLAY_CPUINFO is not set - # CONFIG_MMC is not set - # CONFIG_NET is not set -diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h -index 2627c2a6a5..29fe28e882 100644 ---- a/include/config_distro_bootcmd.h -+++ b/include/config_distro_bootcmd.h -@@ -476,7 +476,7 @@ - "\0" \ - \ - "scan_dev_for_boot_part=" \ -- "part list ${devtype} ${devnum} -bootable devplist; " \ -+ "part list ${devtype} ${devnum} devplist; " /* M1 note: try to boot all partitions in case user DD'd an image as it's difficult to make bootable from recoveryOS */ \ - "env exists devplist || setenv devplist 1; " \ - "for distro_bootpart in ${devplist}; do " \ - "if fstype ${devtype} " \ -diff --git a/include/configs/apple.h b/include/configs/apple.h -index 3c0365b49e..b5632a7866 100644 ---- a/include/configs/apple.h -+++ b/include/configs/apple.h -@@ -19,6 +19,8 @@ - "stderr=serial,vidconsole\0" - - #define ENV_MEM_LAYOUT_SETTINGS \ -+ "ramdisk_addr_r=0x950000000\0" \ -+ "scriptaddr=0x960000000\0" \ - "fdt_addr_r=0x960100000\0" \ - "kernel_addr_r=0x960200000\0" - diff --git a/nix/u-boot/0001-m1n1-fdt-compat.patch b/nix/u-boot/0001-m1n1-fdt-compat.patch deleted file mode 100644 index bb58ceb36f02..000000000000 --- a/nix/u-boot/0001-m1n1-fdt-compat.patch +++ /dev/null @@ -1,401 +0,0 @@ -diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig -index e9d5627290..a25b9bc397 100644 ---- a/arch/arm/Kconfig -+++ b/arch/arm/Kconfig -@@ -937,6 +937,7 @@ config ARCH_APPLE - select MISC - select OF_CONTROL - select OF_BOARD -+ select OF_BOARD_SETUP - select PCI - select PINCTRL - select USB -diff --git a/arch/arm/include/asm/arch-apple/m1n1_compat.h b/arch/arm/include/asm/arch-apple/m1n1_compat.h -new file mode 100644 -index 0000000000..27ce468f99 ---- /dev/null -+++ b/arch/arm/include/asm/arch-apple/m1n1_compat.h -@@ -0,0 +1,6 @@ -+// SPDX-License-Identifier: GPL-2.0+ -+/* -+ * (C) Copyright 2021 Thomas Watson <twatson52@icloud.com> -+ */ -+ -+int apple_m1n1_update_fdt(void *, void*); -diff --git a/arch/arm/mach-apple/Makefile b/arch/arm/mach-apple/Makefile -index 52f30a777b..b4008844a0 100644 ---- a/arch/arm/mach-apple/Makefile -+++ b/arch/arm/mach-apple/Makefile -@@ -3,3 +3,4 @@ - obj-y += board.o - obj-y += lowlevel_init.o - obj-y += rtkit.o -+obj-y += m1n1_compat.o -\ No newline at end of file -diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c -index b4a7a51dc2..8d2eeb8edb 100644 ---- a/arch/arm/mach-apple/board.c -+++ b/arch/arm/mach-apple/board.c -@@ -11,6 +11,7 @@ - #include <asm/global_data.h> - #include <asm/io.h> - #include <asm/system.h> -+#include <asm/arch-apple/m1n1_compat.h> - - DECLARE_GLOBAL_DATA_PTR; - -@@ -163,3 +164,11 @@ unsigned long get_uart_clk(int dev_index) - { - return 24000000; - } -+ -+int ft_board_setup(void *blob, struct bd_info *bd) -+{ -+ if (apple_m1n1_update_fdt(blob, (void *)fw_dtb_pointer)) -+ return -1; -+ -+ return 0; -+} -diff --git a/arch/arm/mach-apple/m1n1_compat.c b/arch/arm/mach-apple/m1n1_compat.c -new file mode 100644 -index 0000000000..4688e54d6f ---- /dev/null -+++ b/arch/arm/mach-apple/m1n1_compat.c -@@ -0,0 +1,337 @@ -+// SPDX-License-Identifier: GPL-2.0+ -+/* -+ * (C) Copyright 2021 Thomas Watson <twatson52@icloud.com> -+ */ -+ -+#include <common.h> -+#include <fdt_support.h> -+ -+#define problem(...) \ -+ do { \ -+ printf(__VA_ARGS__); \ -+ return -1; \ -+ } while (0) -+ -+static int copy_mem(void *fdt, void *fw_fdt) -+{ -+ int fw_node = fdt_path_offset(fw_fdt, "/memory"); -+ if (fw_node < 0) -+ problem("memory node missing from firmware\n"); -+ -+ int node = fdt_path_offset(fdt, "/memory"); -+ if (node < 0) -+ problem("memory node missing\n"); -+ -+ int len; -+ const void *memreg = fdt_getprop(fw_fdt, fw_node, "reg", &len); -+ if (!memreg) -+ problem("could not get reg property of /memory\n"); -+ -+ if (fdt_setprop(fdt, node, "reg", memreg, len)) -+ problem("could not set reg property of /memory\n"); -+ -+ return 0; -+} -+ -+static int copy_mem_rsv(void *fdt, void *fw_fdt) -+{ -+ int num_rsvs = fdt_num_mem_rsv(fw_fdt); -+ for (int rsv = 0; rsv < num_rsvs; rsv++) -+ { -+ u64 address, size; -+ if (fdt_get_mem_rsv(fw_fdt, rsv, &address, &size)) -+ problem("could not get mem rsv %d\n", rsv); -+ -+ if (fdt_add_mem_rsv(fdt, address, size)) -+ problem("could not add mem rsv %d\n", rsv); -+ } -+ -+ return 0; -+} -+ -+static int copy_rng_seed(void *fdt, void *fw_fdt) -+{ -+ int fw_node = fdt_path_offset(fw_fdt, "/chosen"); -+ if (fw_node < 0) -+ problem("chosen node missing from firmware\n"); -+ -+ int node = fdt_path_offset(fdt, "/chosen"); -+ if (node < 0) -+ problem("chosen node missing\n"); -+ -+ int len; -+ const void *seed = fdt_getprop(fw_fdt, fw_node, "rng-seed", &len); -+ if (!seed) /* might not be present if m1n1 did not get enough entropy */ -+ return 0; -+ -+ if (fdt_setprop(fdt, node, "rng-seed", seed, len)) -+ problem("could not set rng-seed property of /chosen\n"); -+ -+ seed = fdt_getprop(fw_fdt, fw_node, "kaslr-seed", &len); -+ if (!seed) /* might not be present if m1n1 did not get enough entropy */ -+ return 0; -+ -+ if (fdt_setprop(fdt, node, "kaslr-seed", seed, len)) -+ problem("could not set kaslr-seed property of /chosen\n"); -+ -+ return 0; -+} -+ -+static int copy_framebuffer(void *fdt, void *fw_fdt) -+{ -+ int fw_node = fdt_path_offset(fw_fdt, "/chosen/framebuffer"); -+ if (fw_node < 0) /* might not be present if m1n1 did not set it up */ -+ return 0; -+ -+ int node = fdt_path_offset(fdt, "/chosen/framebuffer"); -+ if (node < 0) -+ return 0; -+ -+ const char *name = fdt_get_name(fw_fdt, fw_node, NULL); -+ if (!name) -+ problem("could not get framebuffer name\n"); -+ -+ if (fdt_set_name(fdt, node, name)) -+ problem("could not set framebuffer name\n"); -+ -+ int len; -+ const void *reg = fdt_getprop(fw_fdt, fw_node, "reg", &len); -+ if (!reg) -+ problem("could not get framebuffer reg property\n"); -+ -+ if (fdt_setprop(fdt, node, "reg", reg, len)) -+ problem("could not set framebuffer reg property\n"); -+ -+ const void *width = fdt_getprop(fw_fdt, fw_node, "width", &len); -+ if (!width) -+ problem("could not get framebuffer width property\n"); -+ -+ if (fdt_setprop(fdt, node, "width", width, len)) -+ problem("could not set framebuffer width property\n"); -+ -+ const void *height = fdt_getprop(fw_fdt, fw_node, "height", &len); -+ if (!height) -+ problem("could not get framebuffer height property\n"); -+ -+ if (fdt_setprop(fdt, node, "height", height, len)) -+ problem("could not set framebuffer height property\n"); -+ -+ const void *stride = fdt_getprop(fw_fdt, fw_node, "stride", &len); -+ if (!stride) -+ problem("could not get framebuffer stride property\n"); -+ -+ if (fdt_setprop(fdt, node, "stride", stride, len)) -+ problem("could not set framebuffer stride property\n"); -+ -+ const void *format = fdt_getprop(fw_fdt, fw_node, "format", &len); -+ if (!format) -+ problem("could not get framebuffer format property\n"); -+ -+ if (fdt_setprop(fdt, node, "format", format, len)) -+ problem("could not set framebuffer format property\n"); -+ -+ fdt_delprop(fdt, node, "status"); /* un-disable if disabled */ -+ -+ return 0; -+} -+ -+static int copy_mac_addresses(void *fdt, void *fw_fdt) -+{ -+ int aliases = fdt_path_offset(fdt, "/aliases"); -+ if (aliases < 0) -+ problem("aliases node missing\n"); -+ -+ int property; -+ fdt_for_each_property_offset(property, fdt, aliases) -+ { -+ const char *if_name = (const char *)fdt_getprop_by_offset( -+ fdt, property, NULL, NULL); -+ -+ int node = fdt_path_offset(fdt, if_name); -+ if (!fdt_getprop(fdt, node, "local-mac-address", NULL)) -+ continue; /* probably not a network interface */ -+ -+ int fw_node = fdt_path_offset(fw_fdt, if_name); -+ if (fw_node < 0) -+ problem("corresponding node for %s missing\n", if_name); -+ -+ int len; -+ const void *mac = fdt_getprop(fw_fdt, fw_node, "local-mac-address", &len); -+ if (!mac) -+ problem("could not get local-mac-address of %s\n", if_name); -+ -+ if (fdt_setprop(fdt, node, "local-mac-address", mac, len)) -+ problem("could not set local-mac-address of %s\n", if_name); -+ } -+ -+ return 0; -+} -+ -+static int copy_disabled_status(void *fdt, void *fw_fdt) -+{ -+ const char *soc_path = "/soc/"; -+ int fw_soc_node = fdt_path_offset(fw_fdt, soc_path); -+ if (fw_soc_node < 0) -+ problem("soc node missing from firmware\n"); -+ -+ char dev_path[64]; -+ strcpy(dev_path, soc_path); -+ char *dev_name = dev_path + strlen(soc_path); -+ -+ /* each time we do fdt_setprop, existing offsets could be invalidated, so -+ we need to start over. this turns this function into O(n^3) probably, but -+ there's only a few devices so it should be okay */ -+again: ; -+ -+ int soc_node = fdt_path_offset(fdt, soc_path); -+ if (soc_node < 0) -+ problem("soc node missing\n"); -+ -+ int node; -+ fdt_for_each_subnode(node, fdt, soc_node) -+ { -+ const char *name = fdt_get_name(fdt, node, NULL); -+ if (strncmp(name, "i2c@", 4) && strncmp(name, "usb@", 4)) -+ continue; -+ -+ const char *status = fdt_getprop(fdt, node, "status", NULL); -+ if (status && !strcmp(status, "disabled")) -+ continue; -+ -+ strncpy(dev_name, name, dev_path+64-dev_name); -+ dev_path[63] = '\0'; -+ int fw_node = fdt_path_offset(fw_fdt, dev_path); -+ if (fw_node < 0) -+ problem("corresponding node for %s missing\n", dev_path); -+ -+ const char *fw_status = fdt_getprop(fw_fdt, fw_node, "status", NULL); -+ if (!fw_status || strcmp(fw_status, "disabled")) -+ continue; -+ -+ int iommus_size; -+ const char *iommus = fdt_getprop(fdt, node, "iommus", &iommus_size); -+ if (iommus) { -+ if (iommus_size & 7) -+ problem("invalid iommus size for %s\n", dev_path); -+ -+ for (int i = 0; i < iommus_size/8; i++) { -+ u32 phandle = 0; -+ phandle |= (iommus[i*8 + 0] << 24); -+ phandle |= (iommus[i*8 + 1] << 16); -+ phandle |= (iommus[i*8 + 2] << 8); -+ phandle |= iommus[i*8 + 3]; -+ -+ int io_node; -+ fdt_for_each_subnode(io_node, fdt, soc_node) -+ { -+ if (fdt_get_phandle(fdt, io_node) != phandle) -+ continue; -+ -+ const char *status = fdt_getprop(fdt, io_node, "status", NULL); -+ if (status && !strcmp(status, "disabled")) -+ continue; -+ -+ if (fdt_setprop_string(fdt, io_node, "status", "disabled") < 0) -+ problem("could not disable iommu %u\n", phandle); -+ -+ goto again; -+ } -+ } -+ } -+ -+ if (fdt_setprop_string(fdt, node, "status", "disabled") < 0) -+ problem("could not disable device %s\n", dev_path); -+ -+ goto again; -+ } -+ -+ return 0; -+} -+ -+static int copy_cpu(void *fdt, void *fw_fdt) -+{ -+ const char *cpus_path = "/cpus/"; -+ int fw_cpus_node = fdt_path_offset(fw_fdt, cpus_path); -+ if (fw_cpus_node < 0) -+ problem("cpus node missing from firmware\n"); -+ -+ char cpu_path[64]; -+ strcpy(cpu_path, cpus_path); -+ char *cpu_name = cpu_path + strlen(cpus_path); -+ -+ int cpus_node = fdt_path_offset(fdt, cpus_path); -+ if (cpus_node < 0) -+ problem("cpus node missing\n"); -+ -+ int node; -+ fdt_for_each_subnode(node, fdt, cpus_node) -+ { -+ const char *name = fdt_get_name(fdt, node, NULL); -+ if (strncmp(name, "cpu@", 4)) -+ continue; -+ -+ strncpy(cpu_name, name, cpu_path+64-cpu_name); -+ cpu_path[63] = '\0'; -+ int fw_node = fdt_path_offset(fw_fdt, cpu_path); -+ if (fw_node < 0) -+ problem("corresponding node for %s missing\n", cpu_path); -+ -+ int len; -+ const char *release_addr = fdt_getprop( -+ fw_fdt, fw_node, "cpu-release-addr", &len); -+ if (!release_addr) -+ problem("could not get release addr of %s\n", cpu_path); -+ -+ if (fdt_setprop(fdt, node, "cpu-release-addr", release_addr, len)) -+ problem("could not set release addr of %s\n", cpu_path); -+ } -+ -+ return 0; -+} -+ -+int apple_m1n1_update_fdt(void *fdt, void *fw_fdt) -+{ -+ if (fdt == fw_fdt) -+ return 0; -+ -+ fdt_shrink_to_minimum(fdt, 4096); -+ -+ int problems = 0; -+ if (copy_mem(fdt, fw_fdt)) { -+ printf("Could not copy memory information!\n"); -+ problems = 1; -+ } -+ if (copy_mem_rsv(fdt, fw_fdt)) { -+ printf("Could not copy memory reservation information!\n"); -+ problems = 1; -+ } -+ if (copy_rng_seed(fdt, fw_fdt)) { -+ printf("Could not copy RNG seed information!\n"); -+ problems = 1; -+ } -+ if (copy_framebuffer(fdt, fw_fdt)) { -+ printf("Could not copy framebuffer information!\n"); -+ problems = 1; -+ } -+ if (copy_mac_addresses(fdt, fw_fdt)) { -+ printf("Could not copy MAC address information!\n"); -+ problems = 1; -+ } -+ if (copy_disabled_status(fdt, fw_fdt)) { -+ printf("Could not copy device disabled status information!\n"); -+ problems = 1; -+ } -+ if (copy_cpu(fdt, fw_fdt)) { -+ printf("Could not copy CPU information!\n"); -+ problems = 1; -+ } -+ -+ if (problems) -+ { -+ printf("Something went wrong updating the loaded device tree.\n" -+ "This might be cured by updating U-Boot's device tree, " -+ "or m1n1 itself.\n"); -+ } -+ -+ return 0; -+} diff --git a/nix/u-boot/default.nix b/nix/u-boot/default.nix index 787c87a0b621..ba3c7fe57aab 100644 --- a/nix/u-boot/default.nix +++ b/nix/u-boot/default.nix @@ -20,10 +20,8 @@ CONFIG_IDENT_STRING=" ${version} ${withDeviceTree}" ''; }).overrideAttrs (o: { - patches = [ - ./0001-m1n1-fdt-compat.patch - ./0001-add-extlinux-vars.patch - ]; + # upstream patches are not applicable + patches = [ ]; preInstall = '' cat ${m1n1}/build/m1n1.macho u-boot.dtb u-boot-nodtb.bin > u-boot.macho |