Skip to content

Commit baa7cbd

Browse files
committed
0.1
1 parent 14e2c1c commit baa7cbd

19 files changed

+1092
-0
lines changed

.github/workflows/main.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: install software
13+
run: |
14+
sudo apt-get -qq install llvm
15+
ls -lt /usr/bin/llvm-objcopy*
16+
17+
wget --quiet --output-document=- https://github.com/github/hub/releases/download/v2.12.3/hub-linux-amd64-2.12.3.tgz | tar zx
18+
mv hub-linux-* hub
19+
./hub/bin/hub --version
20+
21+
ZIG=$(wget --quiet --output-document=- https://ziglang.org/download/index.json | jq --raw-output '.master."x86_64-linux".tarball')
22+
wget --quiet --output-document=- $ZIG | tar Jx
23+
mv zig-linux-x86_64-* zig
24+
echo zig version $(./zig/zig version)
25+
- name: build
26+
run: |
27+
REPO=$(basename $GITHUB_REPOSITORY)
28+
./zig/zig build -Darmv6
29+
cp -a $REPO-armv6.img boot/
30+
./zig/zig build -Darmv7
31+
cp -a $REPO-armv7.img boot/
32+
- name: release draft
33+
env:
34+
GITHUB_USER: $GITHUB_ACTOR
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
REPO=$(basename $GITHUB_REPOSITORY)
38+
RELEASE_TAG=$(grep '^const release_tag =' src/main.zig | sed 's/";//' | sed 's/^.*"//')
39+
RELEASE_ASSET=$REPO-$RELEASE_TAG.zip
40+
pushd boot
41+
echo $RELEASE_TAG > RELEASE.md
42+
echo >> RELEASE.md
43+
cat ../release-message.md >> RELEASE.md
44+
zip -r $RELEASE_ASSET .
45+
../hub/bin/hub release create --draft --prerelease --file RELEASE.md --attach $RELEASE_ASSET $RELEASE_TAG
46+
popd

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.bin
2+
*.dat
3+
*.elf
4+
*.img
5+
*.zip
6+
zig-cache/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
zig logo is displayed
2+
3+
Successfully tested on rpi3b, rpi3b+
4+
5+
Not yet working on armv6 raspberry pi models

assets/zig-logo.bmp

120 KB
Binary file not shown.

assets/zig-logo.svg

Lines changed: 33 additions & 0 deletions
Loading

boot/bootcode.bin

51.1 KB
Binary file not shown.

boot/config.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://www.raspberrypi.org/documentation/configuration/config-txt/
2+
3+
disable_commandline_tags=1
4+
kernel_old=1
5+
dtparam=audio=on
6+
disable_splash=1
7+
boot_delay=0
8+
cec_osd_name=Zig!
9+
10+
[rpi0]
11+
kernel=zig-bare-metal-raspberry-pi-armv6.img
12+
[rpi1]
13+
kernel=zig-bare-metal-raspberry-pi-armv6.img
14+
[rpi2]
15+
kernel=zig-bare-metal-raspberry-pi-armv7.img
16+
[rpi3]
17+
kernel=zig-bare-metal-raspberry-pi-armv7.img
18+
[rpi4]
19+
kernel=zig-bare-metal-raspberry-pi-armv7.img

boot/fixup.dat

6.58 KB
Binary file not shown.

boot/start.elf

2.74 MB
Binary file not shown.

build.zig

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const std = @import("std");
2+
const Builder = std.build.Builder;
3+
const builtin = @import("builtin");
4+
5+
pub fn build(b: *Builder) void {
6+
const mode = b.standardReleaseOptions();
7+
const want_armv6 = b.option(bool, "armv6", "Build armv6 instead of armv7 (armv7 is default)") orelse false;
8+
const want_armv7 = b.option(bool, "armv7", "Build armv7 instead of armv6 (armv7 is default)") orelse false;
9+
10+
const exec_name = "zig-bare-metal-raspberry-pi";
11+
const exe = b.addExecutable(exec_name, "src/main.zig");
12+
exe.setOutputDir("zig-cache");
13+
exe.setBuildMode(mode);
14+
15+
var arch: builtin.Arch = undefined;
16+
var subarch: u32 = undefined;
17+
var kernel_name: []const u8 = undefined;
18+
if (want_armv6) {
19+
arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v6 };
20+
subarch = 6;
21+
kernel_name = exec_name ++ "-armv6.img";
22+
} else {
23+
arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v7 };
24+
subarch = 7;
25+
kernel_name = exec_name ++ "-armv7.img";
26+
}
27+
const os = builtin.Os.freestanding;
28+
const environ = builtin.Abi.eabihf;
29+
exe.setTarget(arch, builtin.Os.freestanding, environ);
30+
exe.addBuildOption(u32, "subarch", subarch);
31+
32+
const linker_script = "src/linker.ld";
33+
exe.setLinkerScriptPath(linker_script);
34+
35+
const run_objcopy = b.addSystemCommand([_][]const u8{
36+
"llvm-objcopy-6.0", exe.getOutputPath(),
37+
"-O", "binary",
38+
kernel_name,
39+
});
40+
run_objcopy.step.dependOn(&exe.step);
41+
42+
b.default_step.dependOn(&run_objcopy.step);
43+
}

0 commit comments

Comments
 (0)