Do not set the stack size outside prod (#415)

* Add support for multiple modules

* Add macos fix

* Update setup-submodules script
This commit is contained in:
Julien Cretin
2021-11-30 18:11:42 +01:00
committed by GitHub
parent 522e6079e3
commit 37e9d6d64d
4 changed files with 93 additions and 82 deletions

View File

@@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash
set -e set -e
shopt -s nullglob
PROGRAM="$0" PROGRAM="$0"
MODULES=(tock libtock-rs)
success() { success() {
echo -e "\e[1;32mDone:\e[m $1" echo -e "\e[1;32mDone:\e[m $1"
@@ -20,7 +23,8 @@ commit() {
} }
get_root() { get_root() {
git ls-tree HEAD:third_party | sed -En 's/^.* ([^ ]+)\ttock$/\1/p' local module="$1"
git ls-tree HEAD:third_party | sed -En 's/^.* ([^ ]+)\t'"${module}"'$/\1/p'
} }
get_head() { get_head() {
@@ -32,17 +36,17 @@ help() {
cat <<EOF cat <<EOF
Usage: ${PROGRAM} {apply|save} Usage: ${PROGRAM} {apply|save}
apply Applies the patches to the Tock submodule regardless of its state. apply Applies the patches to the submodules regardless of their state.
As a consequence this can always be called to get to a clean state As a consequence this can always be called to get to a clean state
but may result in data loss if there are unsaved changes. but may result in data loss if there are unsaved changes.
save Saves the Tock submodule to the patches. save Saves the submodules to the patches.
This should only be called after apply and when all changes have This should only be called after apply and when all changes have
been added to a commit. After saving, you can run ./setup.sh to been added to a commit. After saving, you can run ./setup.sh to
return to normal state. Otherwise you can continue editing Tock return to normal state. Otherwise you can continue editing the
and calling save. submodules and calling save.
restore Restores the Tock submodule to its normal state regardless of its restore Restores the submodules to its normal state regardless of their
state. As a consequence this can always be called to get to a state. As a consequence this can always be called to get to a
clean state but may result in data loss if there are unsaved clean state but may result in data loss if there are unsaved
changes. changes.
@@ -53,19 +57,19 @@ Example:
${PROGRAM} apply ${PROGRAM} apply
2. Edit files in the Tock submodule: 2. Edit files in the submodules:
cd third_party/tock cd third_party/<submodule>
edit <files> edit <files>
3. Create a fix commit per affected patch by repeating the following commands 3. For each edited submodule, create a fix commit per affected patch by
until there are no more files to add: repeating the following commands until there are no more files to add:
git add -p git add -p
git commit -m'fix <patch#>' git commit -m'fix <patch#>'
4. Merge the fixes into their patches by moving their line below their patch 4. For each edited submodule, merge the fixes into their patches by moving
and changing their "edit" into "fixup": their line below their patch and changing their "edit" into "fixup":
git rebase -i ${root} git rebase -i ${root}
@@ -82,43 +86,53 @@ EOF
} }
apply() { apply() {
local root="$(get_root)" for module in "${MODULES[@]}"; do
( set -e local root="$(get_root "${module}")"
cd third_party/tock ( set -e
git reset -q --hard cd third_party/"${module}"
git clean -qfxd git reset -q --hard
git checkout -q "${root}" git clean -qfxd
cp -a ../../boards . git checkout -q "${root}"
commit '00-boards' if [[ "${module}" == tock ]]; then
for file in ../../patches/tock/*; do cp -a ../../boards .
git apply "${file}" commit '00-boards'
commit "$(basename "${file}" .patch)" fi
done for file in ../../patches/"${module}"/*; do
) git apply "${file}"
commit "$(basename "${file}" .patch)"
done
)
done
} }
save() { save() {
local root="$(get_root)" for module in "${MODULES[@]}"; do
( set -e local root="$(get_root "${module}")"
cd third_party/tock ( set -e
[[ -z "$(git status -s)" ]] || fail 'The Tock submodule is not clean.' cd third_party/"${module}"
rm ../../patches/tock/*.patch [[ -z "$(git status -s)" ]] \
for file in $(git format-patch "${root}"); do || fail "The ${module} submodule is not clean."
sed -n '/^diff/,$p' "${file}" \ rm -rf ../../patches/"${module}"
| sed '/^-- $/,$d' > "../../patches/tock/${file#*-}" mkdir ../../patches/"${module}"
done for file in $(git format-patch "${root}"); do
git clean -qfxd sed -n '/^diff/,$p' "${file}" \
top="$(get_head)" | sed '/^-- $/,$d' > "../../patches/${module}/${file#*-}"
git checkout -q "${root}" done
rm -r boards git clean -qfxd
git apply --whitespace=nowarn ../../patches/tock/00-boards.patch top="$(get_head)"
rm ../../patches/tock/00-boards.patch git checkout -q "${root}"
rm -r ../../boards if [[ "${module}" == tock ]]; then
cp -a boards ../.. rm -r boards
git reset -q --hard git apply --whitespace=nowarn ../../patches/"${module}"/00-boards.patch
git clean -qfxd rm ../../patches/tock/00-boards.patch
git checkout -q "${top}" rm -r ../../boards
) cp -a boards ../..
fi
git reset -q --hard
git clean -qfxd
git checkout -q "${top}"
)
done
} }
grep -q third_party/tock .gitmodules 2>/dev/null \ grep -q third_party/tock .gitmodules 2>/dev/null \
@@ -127,17 +141,17 @@ grep -q third_party/tock .gitmodules 2>/dev/null \
case $1 in case $1 in
apply) apply)
apply apply
success 'Applied the patches to the Tock submodule.' success 'Applied the patches to the submodules.'
;; ;;
save) save)
save save
success 'Saved the Tock submodule to the patches.' success 'Saved the submodules to the patches.'
;; ;;
restore) restore)
# Ovewrite the commit function to do nothing. # Ovewrite the commit function to do nothing.
commit() { true; } commit() { true; }
apply apply
success 'Restored the Tock submodule.' success 'Restored the submodules.'
;; ;;
*) fail 'Unexpected argument. Run without argument for help.' ;; *) fail 'Unexpected argument. Run without argument for help.' ;;
esac esac

View File

@@ -0,0 +1,12 @@
diff --git a/core/src/stack_size.rs b/core/src/stack_size.rs
index 9145393..ef55383 100644
--- a/core/src/stack_size.rs
+++ b/core/src/stack_size.rs
@@ -14,6 +14,7 @@ macro_rules! stack_size {
{$size:expr} => {
#[no_mangle]
#[link_section = ".stack_buffer"]
+ #[cfg(not(target_os = "macos"))]
pub static mut STACK_MEMORY: [u8; $size] = [0; $size];
}
}

View File

@@ -1,5 +1,5 @@
diff --git a/Cargo.toml b/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml
index 06acc26d2..e5db0740b 100644 index 06acc26d2..bd1bbd58f 100644
--- a/Cargo.toml --- a/Cargo.toml
+++ b/Cargo.toml +++ b/Cargo.toml
@@ -20,7 +20,13 @@ members = [ @@ -20,7 +20,13 @@ members = [

View File

@@ -18,6 +18,7 @@ export TERM=${TERM:-vt100}
done_text="$(tput bold)DONE.$(tput sgr0)" done_text="$(tput bold)DONE.$(tput sgr0)"
set -e set -e
shopt -s nullglob
# Ensure the submodules are pulled and up-to-date # Ensure the submodules are pulled and up-to-date
git submodule update --init git submodule update --init
@@ -40,35 +41,19 @@ echo -n '[-] Copying additional boards to Tock... '
cp -r boards/* third_party/tock/boards cp -r boards/* third_party/tock/boards
echo $done_text echo $done_text
# Apply patches to kernel. Do that in a sub-shell. for module in tock libtock-rs; do
( # Apply patches to the submodule. Do that in a sub-shell.
cd third_party/tock/ && \ (
for p in ../../patches/tock/*.patch cd third_party/"${module}"/ && \
do for p in ../../patches/"${module}"/*.patch
echo -n '[-] Applying patch "'$(basename $p)'"... ' do
if git apply "$p" echo -n '[-] Applying patch "'$(basename $p)'"... '
then if git apply "$p"
echo $done_text then
else echo $done_text
patch_conflict_detected else
fi patch_conflict_detected
done fi
) done
)
# Now apply patches to libtock-rs. Do that in a sub-shell. done
#
# Commented out as there are not patches at the moment, and the pattern fails in
# that case.
#(
# cd third_party/libtock-rs/ && \
# for p in ../../patches/libtock-rs/*.patch
# do
# echo -n '[-] Applying patch "'$(basename $p)'"... '
# if git apply "$p"
# then
# echo $done_text
# else
# patch_conflict_detected
# fi
# done
#)