Add binaries for models, generate README.md from README.md.in

This commit is contained in:
Jeremy Soller
2019-03-18 12:19:30 -06:00
parent 73e4fedd68
commit d5ab76f9db
50 changed files with 418 additions and 56 deletions

18
scripts/models.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
cargo build --manifest-path "scripts/modeltool/Cargo.toml" --release
MODELTOOL="$(realpath "scripts/modeltool/target/release/modeltool")"
for dir in models/*/
do
pushd "$dir" > /dev/null
model="$(basename "$dir")"
echo -e "\x1B[1m$model\x1B[0m"
cp README.md.in README.md
echo "## Firmware Versions" >> README.md
"$MODELTOOL" . | tee -a README.md
popd > /dev/null
done

1
scripts/modeltool/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
target

44
scripts/modeltool/Cargo.lock generated Normal file
View File

@@ -0,0 +1,44 @@
[[package]]
name = "bitflags"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "modeltool"
version = "0.1.0"
dependencies = [
"redox_intelflash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"system76_ecflash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_intelflash"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_uefi 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_uefi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "system76_ecflash"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
"checksum redox_intelflash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49e6f45d8c070090589005869e0b776f52c735f9b5411fca369229135fa1dbd8"
"checksum redox_uefi 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dafc50645c27c55ca19d27645a6d91e2a8cbc7aabb2ed024ce914512c75e1217"
"checksum system76_ecflash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2a81b23cd826ce944029420978cce3be94363188ed87ff8cc0778f80adac547"

View File

@@ -0,0 +1,9 @@
[package]
name = "modeltool"
version = "0.1.0"
authors = ["Jeremy Soller <jeremy@system76.com>"]
edition = "2018"
[dependencies]
redox_intelflash = "0.1.0"
system76_ecflash = "0.1.0"

View File

@@ -0,0 +1,86 @@
use ecflash::{Ec, EcFile};
use intelflash::{Me, Rom};
use std::{env, fs, process};
use std::path::Path;
fn ec(path: &Path) {
println!("- [EC]({})", path.display());
match fs::read(path) {
Ok(data) => {
println!(" - Size: {} KB", data.len() / 1024);
{
let mut ec = EcFile::new(data);
println!(" - Model: {}", ec.project());
println!(" - Version: {}", ec.version());
}
},
Err(err) => {
println!(" - *Read Error: {}*", err);
}
}
}
fn fd(path: &Path) {
println!("- [FD]({})", path.display());
match fs::read(path) {
Ok(data) => {
println!(" - Size: {} KB", data.len() / 1024);
match Rom::new(&data) {
Ok(rom) => {
match rom.high_assurance_platform() {
Ok(hap) => {
println!(" - HAP: {}", hap);
},
Err(err) => {
println!(" - *HAP Error: {}*", err);
}
}
},
Err(err) => {
println!(" - *Parse Error: {}*", err);
}
}
},
Err(err) => {
println!(" - *Read Error: {}*", err);
}
}
}
fn me(path: &Path) {
println!("- [ME]({})", path.display());
match fs::read(path) {
Ok(data) => {
println!(" - Size: {} KB", data.len() / 1024);
match Me::new(&data) {
Ok(me) => {
if let Some(version) = me.version() {
println!(" - Version: {}", version);
}
},
Err(err) => {
println!(" - *Parse Error: {}*", err);
}
}
},
Err(err) => {
println!(" - *Read Error: {}*", err);
}
}
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if args.is_empty() {
println!("modeltool [model directory]...");
process::exit(1);
}
for arg in args {
let path = Path::new(&arg);
ec(&path.join("ec.rom"));
fd(&path.join("fd.rom"));
me(&path.join("me.rom"));
}
}

76
scripts/readmes.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
README_DIRS=(
apps
libs
models
tools
.
)
set -e
cargo build --manifest-path "scripts/modeltool/Cargo.toml" --release
MODELTOOL="$(realpath "scripts/modeltool/target/release/modeltool")"
function readme_model {
echo -e "\x1B[1m$1\x1B[0m" >&2
pushd "$1" > /dev/null
cp README.md.in README.md
echo >> README.md
echo "## Contents" >> README.md
"$MODELTOOL" . >> README.md
popd > /dev/null
}
for dir in models/*/
do
readme_model "${dir%/}"
done
function readme_line {
echo -e " \x1B[1m$1\x1B[0m" >&2
if [ -f "$1/README.md" ]
then
# Get first line, removing the trailing pounds and spaces
description="$(head -n 1 "$1/README.md" | sed -e 's/^[#[:space:]]*//')"
else
# Use the directory name as the description
description="$(basename "$1")"
fi
submodule="$(git submodule status "$1" 2> /dev/null | cut -d ' ' -f 3 || true)"
if [ "$submodule" == "$dir" ]
then
# Link to submodule URL
origin="$(git -C "$dir" remote get-url origin)"
echo "- [$description]($origin)"
else
# Link to directory
echo "- [$description](./$dir)"
fi
}
function readme_dir {
echo -e "\x1B[1m$1\x1B[0m" >&2
pushd "$1" > /dev/null
cp README.md.in README.md
echo >> README.md
echo "## Contents" >> README.md
for dir in */
do
readme_line "${dir%/}" >> README.md
done
popd > /dev/null
}
for dir in "${README_DIRS[@]}"
do
readme_dir "$dir"
done

27
scripts/remotes.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
REMOTES=(
"coreboot upstream https://github.com/coreboot/coreboot.git"
"edk2 upstream https://github.com/tianocore/edk2.git"
"edk2-platforms upstream https://github.com/tianocore/edk2-platforms.git"
)
set -e
function git_remote {
echo -e "\x1B[1m$1\x1B[0m"
cd "$1"
if git remote | grep "^$2\$"
then
git remote set-url "$2" "$3"
else
git remote add "$2" "$3"
fi
git fetch "$2"
cd ..
}
for remote in "${REMOTES[@]}"
do
git_remote $remote
done