From f0f9603657911ee0373006173e0b336d2c9b751f Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 6 Aug 2019 19:47:45 +0200 Subject: [PATCH] define custom target, use with cargo-xbuild requires nixpkgs master now --- .cargo/config | 6 +++--- armv7-none-eabihf.json | 28 ++++++++++++++++++++++++++++ default.nix | 13 +++++++++---- link.x | 32 +++++++++++++++++++++----------- shell.nix | 3 +++ 5 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 armv7-none-eabihf.json diff --git a/.cargo/config b/.cargo/config index b7af52c..cd0f3a5 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,11 +1,11 @@ -[target.armv7-unknown-linux-gnueabihf] +[target.armv7-none-eabihf] runner = "./runner.sh" linker = "arm-none-eabihf-gcc" rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x,-N", + "-C", "link-arg=-Tlink.x", "-C", "target-feature=a9,armv7-a,neon", "-C", "target-cpu=cortex-a9", ] [build] -target = "armv7-unknown-linux-gnueabihf" +target = "armv7-none-eabihf.json" diff --git a/armv7-none-eabihf.json b/armv7-none-eabihf.json new file mode 100644 index 0000000..4fc452f --- /dev/null +++ b/armv7-none-eabihf.json @@ -0,0 +1,28 @@ +{ + "abi-blacklist": [ + "stdcall", + "fastcall", + "vectorcall", + "thiscall", + "win64", + "sysv64" + ], + "arch": "arm", + "data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", + "emit-debug-gdb-scripts": false, + "env": "", + "executables": true, + "features": "+v7,+vfp3,-d32,+thumb2,-neon", + "is-builtin": false, + "linker": "rust-lld", + "linker-flavor": "ld.lld", + "llvm-target": "armv7-unknown-none-eabihf", + "max-atomic-width": 32, + "os": "none", + "panic-strategy": "abort", + "relocation-model": "static", + "target-c-int-width": "32", + "target-endian": "little", + "target-pointer-width": "32", + "vendor": "" +} diff --git a/default.nix b/default.nix index c40a9ba..0703b4a 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,5 @@ { # Use master branch of the overlay by default mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz), - rustSrc ? https://github.com/rustlang/rust/archive/master.tar.gz, }: let @@ -8,15 +7,21 @@ let in with pkgs; let + rustcSrc = fetchgit { + url = https://github.com/rust-lang/rust.git; + # master of 2019-08-06 + rev = "8996328ebf34aa73e83a1db326767c11041f811d"; + sha256 = "1daz0y97dm35nfy7ip0wqvyax0g36szm25n77rcg20k6wab4fqi7"; + fetchSubmodules = true; + }; targets = [ - "armv7-unknown-linux-gnueabihf" ]; rust = rustChannelOfTargets "nightly" null targets; rustPlatform = recurseIntoAttrs (makeRustPlatform { - rustc = rust // { src = rustSrc; }; + rustc = rust // { src = rustcSrc; }; cargo = rust; }); in { - inherit pkgs rustPlatform; + inherit pkgs rustPlatform rustcSrc; } diff --git a/link.x b/link.x index ec2e260..14c4623 100644 --- a/link.x +++ b/link.x @@ -20,36 +20,45 @@ MEMORY SECTIONS { - .exceptions (0x0) : + .exceptions ORIGIN(OCM) : { KEEP(*(.text.exceptions)); } > OCM - .text (0x8000) : + + .__fill (NOLOAD) : { + . = ORIGIN(OCM) + 0x8000; + } > OCM + + .text (ORIGIN(OCM) + 0x8000) : { - KEEP(*(.text.boot)) - *(.text .text.*) + *(.text.boot); + *(.text .text.*); + . = ALIGN(4); } > OCM - .rodata ALIGN(0x1000) : + .rodata : ALIGN(4) { - *(.rodata) + *(.rodata .rodata.*); + . = ALIGN(4); } > OCM - .data ALIGN(0x1000) : + .data : ALIGN(4) { - *(.data) + *(.data .data.*); + . = ALIGN(4); } > OCM - .bss ALIGN(0x4000) (NOLOAD) : + .bss (NOLOAD) : ALIGN(0x4000) { /* Aligned to 16 kB */ KEEP(*(.bss.l1_table)); - *(.bss) + *(.bss .bss.*); + . = ALIGN(4); } > OCM __bss_start = ADDR(.bss); __bss_end = ADDR(.bss) + SIZEOF(.bss); - .stack ALIGN(0x1000) (NOLOAD) : { + .stack (NOLOAD) : ALIGN(0x1000) { . += STACK_SIZE; } > OCM __stack_end = ADDR(.stack); @@ -58,6 +67,7 @@ SECTIONS /DISCARD/ : { /* Unused exception related info that only wastes space */ + *(.ARM.exidx); *(.ARM.exidx.*); *(.ARM.extab.*); } diff --git a/shell.nix b/shell.nix index d1e0636..8488f3a 100644 --- a/shell.nix +++ b/shell.nix @@ -11,6 +11,7 @@ stdenv.mkDerivation { name = "adc2tcp-env"; buildInputs = with rustPlatform.rust; [ rustc cargo + cargo-xbuild rustcSrc pkgsCross.armhf-embedded.buildPackages.gcc #pkgsCross.armv7l-hf-multiplatform.buildPackages.gcc #pkgsCross.armhf-embedded.buildPackages.binutils @@ -18,7 +19,9 @@ stdenv.mkDerivation { # Set Environment Variables RUST_BACKTRACE = 1; + XARGO_RUST_SRC = "${rustcSrc}/src"; shellHook = '' + echo "Run 'cargo xbuild --release' to build." ''; }