From 857568009ef88ea7177f8441b661b3f5a9378196 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Sat, 7 Apr 2018 12:33:36 +0200 Subject: [PATCH] Lazily generate dockcross runscript --- .gitignore | 1 + 01_bareminimum/Makefile | 8 +- 01_bareminimum/dockcross-linux-aarch64 | 246 ---------------------- 02_multicore_rust/Makefile | 8 +- 02_multicore_rust/dockcross-linux-aarch64 | 246 ---------------------- 03_uart1/Makefile | 8 +- 03_uart1/dockcross-linux-aarch64 | 246 ---------------------- 04_mailboxes/Makefile | 8 +- 04_mailboxes/dockcross-linux-aarch64 | 246 ---------------------- 05_uart0/Makefile | 8 +- 05_uart0/dockcross-linux-aarch64 | 246 ---------------------- 06_random/Makefile | 8 +- 06_random/dockcross-linux-aarch64 | 246 ---------------------- 13 files changed, 43 insertions(+), 1482 deletions(-) create mode 100644 .gitignore delete mode 100755 01_bareminimum/dockcross-linux-aarch64 delete mode 100755 02_multicore_rust/dockcross-linux-aarch64 delete mode 100755 03_uart1/dockcross-linux-aarch64 delete mode 100755 04_mailboxes/dockcross-linux-aarch64 delete mode 100755 05_uart0/dockcross-linux-aarch64 delete mode 100755 06_random/dockcross-linux-aarch64 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9611428d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/dockcross-linux-aarch64 \ No newline at end of file diff --git a/01_bareminimum/Makefile b/01_bareminimum/Makefile index ea74c4da..f0e75cd2 100644 --- a/01_bareminimum/Makefile +++ b/01_bareminimum/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/01_bareminimum/dockcross-linux-aarch64 b/01_bareminimum/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/01_bareminimum/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################ diff --git a/02_multicore_rust/Makefile b/02_multicore_rust/Makefile index dc5a6d56..94bb0ad3 100644 --- a/02_multicore_rust/Makefile +++ b/02_multicore_rust/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/02_multicore_rust/dockcross-linux-aarch64 b/02_multicore_rust/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/02_multicore_rust/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################ diff --git a/03_uart1/Makefile b/03_uart1/Makefile index dc5a6d56..94bb0ad3 100644 --- a/03_uart1/Makefile +++ b/03_uart1/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/03_uart1/dockcross-linux-aarch64 b/03_uart1/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/03_uart1/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################ diff --git a/04_mailboxes/Makefile b/04_mailboxes/Makefile index fb7767f3..a136e894 100644 --- a/04_mailboxes/Makefile +++ b/04_mailboxes/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/04_mailboxes/dockcross-linux-aarch64 b/04_mailboxes/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/04_mailboxes/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################ diff --git a/05_uart0/Makefile b/05_uart0/Makefile index fb7767f3..a136e894 100644 --- a/05_uart0/Makefile +++ b/05_uart0/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/05_uart0/dockcross-linux-aarch64 b/05_uart0/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/05_uart0/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################ diff --git a/06_random/Makefile b/06_random/Makefile index fb7767f3..a136e894 100644 --- a/06_random/Makefile +++ b/06_random/Makefile @@ -31,7 +31,13 @@ QEMU_CONTAINER = andrerichter/raspi3-qemu DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work -w /work QEMU_CMD = qemu-system-aarch64 -M raspi3 -kernel kernel8.img -all: clean kernel8.img +all: clean cross_cont_download kernel8.img + +cross_cont_download: +ifeq (,$(wildcard $(CROSS_CONTAINER))) + docker run --rm dockcross/linux-arm64 > $(CROSS_CONTAINER) + chmod +x $(CROSS_CONTAINER) +endif target/$(TARGET)/debug/kernel8: src/main.rs RUST_TARGET_PATH=$(shell pwd) xargo build --target=$(TARGET) diff --git a/06_random/dockcross-linux-aarch64 b/06_random/dockcross-linux-aarch64 deleted file mode 100755 index 3c7481d2..00000000 --- a/06_random/dockcross-linux-aarch64 +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64 - -#------------------------------------------------------------------------------ -# Helpers -# -err() { - echo -e >&2 ERROR: $@\\n -} - -die() { - err $@ - exit 1 -} - -has() { - # eg. has command update - local kind=$1 - local name=$2 - - type -t $kind:$name | grep -q function -} - -#------------------------------------------------------------------------------ -# Command handlers -# -command:update-image() { - docker pull $FINAL_IMAGE -} - -help:update-image() { - echo Pull the latest $FINAL_IMAGE . -} - -command:update-script() { - if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then - echo $0 is up to date - else - echo -n Updating $0 '... ' - docker run --rm $FINAL_IMAGE > $0 && echo ok - fi -} - -help:update-image() { - echo Update $0 from $FINAL_IMAGE . -} - -command:update() { - command:update-image - command:update-script -} - -help:update() { - echo Pull the latest $FINAL_IMAGE, and then update $0 from that. -} - -command:help() { - if [[ $# != 0 ]]; then - if ! has command $1; then - err \"$1\" is not an dockcross command - command:help - elif ! has help $1; then - err No help found for \"$1\" - else - help:$1 - fi - else - cat >&2 < -ENDHELP - exit 1 - fi -} - -#------------------------------------------------------------------------------ -# Option processing -# -special_update_command='' -while [[ $# != 0 ]]; do - case $1 in - - --) - shift - break - ;; - - --args|-a) - ARG_ARGS="$2" - shift 2 - ;; - - --config|-c) - ARG_CONFIG="$2" - shift 2 - ;; - - --image|-i) - ARG_IMAGE="$2" - shift 2 - ;; - update|update-image|update-script) - special_update_command=$1 - break - ;; - -*) - err Unknown option \"$1\" - command:help - exit - ;; - - *) - break - ;; - - esac -done - -# The precedence for options is: -# 1. command-line arguments -# 2. environment variables -# 3. defaults - -# Source the config file if it exists -DEFAULT_DOCKCROSS_CONFIG=~/.dockcross -FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} - -[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" - -# Set the docker image -FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} - -# Handle special update command -if [ "$special_update_command" != "" ]; then - case $special_update_command in - - update) - command:update - exit $? - ;; - - update-image) - command:update-image - exit $? - ;; - - update-script) - command:update-script - exit $? - ;; - - esac -fi - -# Set the docker run extra args (if any) -FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} - -# Bash on Ubuntu on Windows -UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") -# MSYS, Git Bash, etc. -MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") - -if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then - USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" -fi - -# Change the PWD when working in Docker on Windows -if [ -n "$UBUNTU_ON_WINDOWS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\/mnt\//} - HOST_PWD=${HOST_PWD/\//:\/} -elif [ -n "$MSYS" ]; then - HOST_PWD=$PWD - HOST_PWD=${HOST_PWD/\//} - HOST_PWD=${HOST_PWD/\//:\/} -else - HOST_PWD=$PWD -fi - -# Mount Additional Volumes -if [ -z "$SSH_DIR" ]; then - SSH_DIR="$HOME/.ssh" -fi - -HOST_VOLUMES= -if [ -e "$SSH_DIR" ]; then - HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" -fi - -#------------------------------------------------------------------------------ -# Now, finally, run the command in a container -# -tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$RANDOM -docker run $TTY_ARGS --name $CONTAINER_NAME \ - -v "$HOST_PWD":/work \ - $HOST_VOLUMES \ - $USER_IDS \ - $FINAL_ARGS \ - $FINAL_IMAGE "$@" -run_exit_code=$? - -# Attempt to delete container -rm_output=$(docker rm -f $CONTAINER_NAME 2>&1) -rm_exit_code=$? -if [[ $rm_exit_code != 0 ]]; then - if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then - : # Ignore error because of https://circleci.com/docs/docker-btrfs-error/ - else - echo "$rm_output" - exit $rm_exit_code - fi -fi - -exit $run_exit_code - -################################################################################ -# -# This image is not intended to be run manually. -# -# To create a dockcross helper script for the -# dockcross/linux-armv7 image, run: -# -# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7 -# chmod +x dockcross-linux-armv7 -# -# You may then wish to move the dockcross script to your PATH. -# -################################################################################