Skip to content

Commit c6b823a

Browse files
committed
update rpi-4
1 parent 93bfea5 commit c6b823a

File tree

5 files changed

+51
-49
lines changed

5 files changed

+51
-49
lines changed

rpi-4b-blink/Makefile

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1-
SWIFT_EXEC ?= swift
2-
CLANG ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f clang; else which clang; fi)
3-
LLVM_OBJCOPY ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f llvm-objcopy; else which llvm-objcopy; fi)
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
411

5-
BUILDROOT := $(shell $(SWIFT_EXEC) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector --show-bin-path)
12+
# Paths
13+
REPOROOT := $(shell git rev-parse --show-toplevel)
14+
TOOLSROOT := $(REPOROOT)/Tools
15+
TOOLSET := $(TOOLSROOT)/Toolsets/rpi-5-elf.json
16+
LLVM_OBJCOPY := llvm-objcopy
17+
SWIFT_BUILD := swift build
618

7-
.PHONY: all clean
19+
# Flags
20+
ARCH := aarch64
21+
TARGET := $(ARCH)-none-none-elf
22+
SWIFT_BUILD_ARGS := \
23+
--configuration release \
24+
--triple $(TARGET) \
25+
--toolset $(TOOLSET) \
26+
--disable-local-rpath
27+
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)
828

9-
all: kernel8.img
29+
.PHONY: build
30+
build:
31+
@echo "building..."
32+
$(SWIFT_BUILD) \
33+
$(SWIFT_BUILD_ARGS) \
34+
--verbose
1035

11-
kernel8.img: kernel8.elf
12-
@echo "💾 Converting to binary kernel image with llvm-objcopy..."
13-
$(LLVM_OBJCOPY) -O binary kernel8.elf kernel8.img
14-
@echo ""
15-
@echo "🥳 Done! kernel8.img was saved to this directory."
36+
@echo "extracting binary..."
37+
$(LLVM_OBJCOPY) \
38+
-O binary \
39+
"$(BUILDROOT)/Application" \
40+
"$(BUILDROOT)/Application.bin" \
1641

17-
kernel8.elf: $(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o link.ld
18-
@echo "🔗 Linking with clang..."
19-
$(CLANG) --target=aarch64-elf -o kernel8.elf $< $^ -fuse-ld=lld -nostdlib -Wl,--unresolved-symbols=ignore-in-object-files -Wl,-T ./link.ld -###
20-
@echo ""
21-
22-
$(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o:
23-
@echo "🛠️ Building with Swift Package Manager..."
24-
$(SWIFT_EXEC) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
25-
@echo ""
2642

43+
.PHONY: clean
2744
clean:
28-
rm -rf kernel8.elf kernel8.img .build
45+
@echo "cleaning..."
46+
@swift package clean
47+
@rm -rf .build

rpi-4b-blink/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpi-4b-blink/Package.swift

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,18 @@
33
import PackageDescription
44

55
let package = Package(
6-
name: "RPi4B-Blink",
7-
platforms: [
8-
.macOS(.v14)
9-
],
6+
name: "rpi-4b-blink",
107
products: [
11-
.library(
12-
name: "MainApp",
13-
type: .static,
14-
targets: ["MainApp"])
8+
.executable(name: "Application", targets: ["Application"])
159
],
1610
dependencies: [
17-
.package(
18-
url: "https://github.com/apple/swift-mmio.git",
19-
branch: "swift-embedded-examples")
11+
.package(url: "https://github.com/apple/swift-mmio.git", branch: "main")
2012
],
2113
targets: [
22-
.target(
23-
name: "MainApp",
14+
.executableTarget(
15+
name: "Application",
2416
dependencies: [
2517
.product(name: "MMIO", package: "swift-mmio")
26-
],
27-
swiftSettings: [
28-
.enableExperimentalFeature("Embedded"),
29-
.unsafeFlags(["-Xfrontend", "-function-sections"]),
30-
]
31-
),
18+
]),
3219
.target(name: "Support"),
33-
34-
]
35-
)
20+
])

rpi-4b-blink/Sources/MainApp/MainApp.swift renamed to rpi-4b-blink/Sources/Application/Application.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ func ledOff() {
6767
}
6868

6969
@main
70-
struct Main {
71-
70+
struct Application {
7271
static func main() {
7372
setLedOutput()
74-
7573
while true {
7674
ledOn()
7775
for _ in 1..<100000 {} // just a delay
File renamed without changes.

0 commit comments

Comments
 (0)