Skip to content

Commit

Permalink
Merge pull request #12 from tock/update-to-tock-master
Browse files Browse the repository at this point in the history
Update to tock master and add nrf52840dk bootloader
  • Loading branch information
bradjc authored Nov 29, 2018
2 parents ebd5fec + 55d3c80 commit 2041c08
Show file tree
Hide file tree
Showing 22 changed files with 879 additions and 235 deletions.
13 changes: 2 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ language: rust

cache:
cargo: true
directories:
- $HOME/gcc-arm-none-eabi-6_2-2016q4
- $HOME/local_cargo

os:
- linux

# If you change this, you must also change Getting_Started.md, Makefile.common,
# and Vagrantfile.
rust:
- nightly-2018-04-19

before_install:
- tools/travis-install-gcc.sh
- export PATH="$PATH:$HOME/gcc-arm-none-eabi-6_2-2016q4/bin"

before_script:
- tools/install_cargo_fmt.sh
- nightly-2018-08-16

script:
- export PATH=$HOME/.cargo/bin:$PATH
- tools/run_cargo_fmt.sh diff
- make -C boards/hail-bootloader
- make -C boards/nrf52-bootloader

146 changes: 95 additions & 51 deletions boards/Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ MAKEFLAGS += -R

MAKEFILE_COMMON_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

TOOLCHAIN ?= arm-none-eabi
TOOLCHAIN ?= llvm

CARGO ?= cargo
# This will hopefully move into Cargo.toml (or Cargo.toml.local) eventually
RUSTFLAGS_FOR_CARGO_LINKING := "-C link-arg=-nostartfiles -C link-arg=-Tlayout.ld"

CC := $(TOOLCHAIN)-gcc
SIZE ?= $(TOOLCHAIN)-size
OBJCOPY ?= $(TOOLCHAIN)-objcopy
OBJDUMP ?= $(TOOLCHAIN)-objdump
OBJDUMP_FLAGS += --disassemble-all --source --disassembler-options=force-thumb -C --section-headers
# This will hopefully move into Cargo.toml (or Cargo.toml.local) eventually.
# lld uses the page size to align program sections. It defaults to 4096 and this
# puts a gap between before the .relocate section. `zmax-page-size=512` tells
# lld the actual page size so it doesn't have to be conservative.
RUSTFLAGS_FOR_CARGO_LINKING := -C link-arg=-Tlayout.ld -C linker=rust-lld \
-Z linker-flavor=ld.lld -C relocation-model=dynamic-no-pic \
-C link-arg=-zmax-page-size=512

# Disallow warnings for continuous integration builds. Disallowing them here
# ensures that warnings during testing won't prevent compilation from succeeding.
# We are OK with warnings in bootloader land!
# ifeq ($(CI),true)
# RUSTFLAGS_FOR_CARGO_LINKING += -D warnings
# endif

# http://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set
# Check that given variables are set and all have non-empty values,
Expand All @@ -33,6 +40,7 @@ __check_defined = \


$(call check_defined, PLATFORM)
$(call check_defined, TARGET)

# If environment variable V is non-empty, be verbose
ifneq ($(V),)
Expand All @@ -43,33 +51,41 @@ Q=@
VERBOSE =
endif

# Check that gcc version is new enough (> 5.1) - used during linking
CC_VERSION_MAJOR := $(shell $(TOOLCHAIN)-gcc -dumpversion | cut -d '.' -f1)
ifeq (1,$(shell expr $(CC_VERSION_MAJOR) \>= 6))
# no-op
else
ifneq (5,$(CC_VERSION_MAJOR))
$(info CC=$(CC))
$(info $$(CC) -dumpversion: $(shell $(CC) -dumpversion))
$(error Your compiler is too old. Need gcc version > 5.1)
endif
CC_VERSION_MINOR := $(shell $(CC) -dumpversion | cut -d '.' -f2)
ifneq (1,$(shell expr $(CC_VERSION_MINOR) \> 1))
$(info CC=$(CC))
$(info $$(CC) -dumpversion: $(shell $(CC) -dumpversion))
$(error Your compiler is too old. Need gcc version > 5.1)
endif
export TOCK_KERNEL_VERSION := $(shell git describe --always || echo notgit)


# Validate that rustup is new enough
MINIMUM_RUSTUP_VERSION := 1.11.0
RUSTUP_VERSION := $(strip $(word 2, $(shell rustup --version)))
ifeq ($(shell $(MAKEFILE_COMMON_PATH)../tools/semver.sh $(RUSTUP_VERSION) \< $(MINIMUM_RUSTUP_VERSION)), true)
$(warning Required tool `rustup` is out-of-date.)
$(warning Running `rustup update` in 3 seconds (ctrl-c to cancel))
$(shell sleep 3s)
DUMMY := $(shell rustup update)
endif

LLVM_TOOLS_INSTALLED := $(shell rustup component list | grep 'llvm-tools-preview.*(installed)' -q; echo $$?)
ifeq ($(LLVM_TOOLS_INSTALLED),1)
$(shell rustup component add llvm-tools-preview)
endif
ifneq ($(shell rustup component list | grep rust-src),rust-src (installed))
$(shell rustup component add rust-src)
endif
ifneq ($(shell rustup target list | grep "$(TARGET) (installed)"),$(TARGET) (installed))
$(shell rustup target add $(TARGET))
endif

# Need some dummy value here
export TOCK_KERNEL_VERSION=5
ifeq ($(TOOLCHAIN),llvm)
# If the user is using the standard toolchain we need to get the full path.
# rustup should take care of this for us by putting in a proxy in .cargo/bin,
# but until that is setup we workaround it.
TOOLCHAIN = "$(shell dirname $(shell find `rustc --print sysroot` -name llvm-size))/llvm"
endif

SIZE ?= $(TOOLCHAIN)-size
OBJCOPY ?= $(TOOLCHAIN)-objcopy
OBJDUMP ?= $(TOOLCHAIN)-objdump
OBJDUMP_FLAGS += --disassemble-all --source --arch-name=thumb --section-headers

# Dump configuration for verbose builds
ifneq ($(V),)
Expand All @@ -82,6 +98,7 @@ ifneq ($(V),)
$(info OBJCOPY=$(OBJCOPY))
$(info PLATFORM=$(PLATFORM))
$(info TARGET=$(TARGET))
$(info TOCK_KERNEL_VERSION=$(TOCK_KERNEL_VERSION))
$(info TOOLCHAIN=$(TOOLCHAIN))
$(info )
$(info $(OBJCOPY) --version = $(shell $(OBJCOPY) --version))
Expand All @@ -90,42 +107,69 @@ ifneq ($(V),)
$(info )
endif

.PRECIOUS: %.elf
# Support rules

# User-facing targets
.PHONY: all
all: target/$(TARGET)/release/$(PLATFORM).bin
all: release

.PHONY: lst
lst: target/$(TARGET)/release/$(PLATFORM).lst
# `make check` runs the Rust compiler but does not actually output the final
# binary. This makes checking for Rust errors much faster.
.PHONY: check
check:
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO_LINKING)" $(CARGO) check --target=$(TARGET) $(VERBOSE) --release

target:
@mkdir -p target
.PHONY: clean
clean::
$(Q)$(CARGO) clean $(VERBOSE)

.PHONY: release
release: target/$(TARGET)/release/$(PLATFORM).bin

.PHONY: debug
debug: target/$(TARGET)/debug/$(PLATFORM).bin

.PHONY: debug-lst
debug-lst: target/$(TARGET)/debug/$(PLATFORM).lst

.PHONY: doc
doc: | target
$(Q)RUSTDOCFLAGS=--document-private-items $(CARGO) doc $(VERBOSE) --release --target=$(TARGET)

target/$(TARGET)/release/$(PLATFORM).elf: target/$(TARGET)/release/$(PLATFORM)
$(Q)cp target/$(TARGET)/release/$(PLATFORM) target/$(TARGET)/release/$(PLATFORM).elf
.PHONY: lst
lst: target/$(TARGET)/release/$(PLATFORM).lst

target/$(TARGET)/release/$(PLATFORM).lst: target/$(TARGET)/release/$(PLATFORM).elf
$(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > target/$(TARGET)/release/$(PLATFORM).lst
.PHONY: release
release: target/$(TARGET)/release/$(PLATFORM).bin

.PHONY: target/$(TARGET)/release/$(PLATFORM)
target/$(TARGET)/release/$(PLATFORM):
$(Q)RUSTFLAGS=$(RUSTFLAGS_FOR_CARGO_LINKING) $(CARGO) build --target=$(TARGET) $(VERBOSE) --release
$(Q)$(SIZE) $@

target/$(TARGET)/release/$(PLATFORM).hex: target/$(TARGET)/release/$(PLATFORM).elf
$(Q)$(OBJCOPY) -Oihex $^ $@
# Support rules

target/$(TARGET)/release/$(PLATFORM).bin: target/$(TARGET)/release/$(PLATFORM).elf
$(Q)$(OBJCOPY) -Obinary $^ $@
target:
@mkdir -p target

# `make check` runs the Rust compiler but does not actually output the final
# binary. This makes checking for Rust errors much faster.
.PHONY: check
check:
$(Q)RUSTFLAGS=$(RUSTFLAGS_FOR_CARGO_LINKING) $(CARGO) check --target=$(TARGET) $(VERBOSE) --release
# Cargo outputs an elf file (just without a file extension)
%.elf: %
$(Q)cp $< $@

.PHONY: clean
clean::
$(Q)$(CARGO) clean $(VERBOSE)
%.bin: %.elf
$(Q)$(OBJCOPY) --output-target=binary $^ $@

%.lst: %.elf
$(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@


# Cargo-drivers
# We want to always invoke cargo (yay nested build systems), so these need to
# be phony, which means they can't be pattern rules.

.PHONY: target/$(TARGET)/release/$(PLATFORM)
target/$(TARGET)/release/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO_LINKING)" $(CARGO) build --target=$(TARGET) $(VERBOSE) --release
$(Q)$(SIZE) $@

.PHONY: target/$(TARGET)/debug/$(PLATFORM)
target/$(TARGET)/debug/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO_LINKING)" $(CARGO) build $(VERBOSE) --target=$(TARGET)
$(Q)$(SIZE) $@
53 changes: 43 additions & 10 deletions boards/hail-bootloader/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boards/hail-bootloader/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
println!("cargo:rerun-if-changed=../kernel_layout.ld");

let mut f = bootloader_attributes::get_file();
bootloader_attributes::write_flags(&mut f, 512, "1.0.0");
bootloader_attributes::write_flags(&mut f, 512, "1.0.1");
bootloader_attributes::write_attribute(&mut f, "board", "hail");
bootloader_attributes::write_attribute(&mut f, "arch", "cortex-m4");
bootloader_attributes::write_attribute(&mut f, "jldevice", "ATSAM4LC8C");
Expand Down
11 changes: 5 additions & 6 deletions boards/hail-bootloader/layout.ld
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* Memory Spaces Definitions, 448K flash, 64K ram */
ROM_ORIGIN = 0x00000000;
ROM_LENGTH = 0x00010000;
RAM_ORIGIN = 0x20000000;
RAM_LENGTH = 0x00020000;

MPU_MIN_ALIGN = 8K;
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
}

INCLUDE ../kernel_layout.ld
Loading

0 comments on commit 2041c08

Please sign in to comment.