Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5c16244
Create README.md
iCMDdev Oct 26, 2024
d7ee0fb
Update README.md
iCMDdev Oct 26, 2024
b82c7f1
Added Blink example code
iCMDdev Oct 26, 2024
595b02e
Update MainApp.swift
iCMDdev Oct 26, 2024
6f680c0
Delete RPi4B-blink/Makefile
iCMDdev Oct 26, 2024
b15606f
Update link.ld
iCMDdev Oct 26, 2024
555bdbd
Update boot.S
iCMDdev Oct 26, 2024
6e9cf61
Add files via upload
iCMDdev Oct 26, 2024
0fd00dd
Update build.sh
iCMDdev Oct 26, 2024
bd61e35
Update link.ld
iCMDdev Oct 26, 2024
c4ea37d
Added RPi 5 example
iCMDdev Oct 27, 2024
72347f6
Delete rpi5-blink/Package.resolved
iCMDdev Oct 27, 2024
7a9af2f
Delete RPi4B-blink directory
iCMDdev Oct 27, 2024
f8f64ae
Updated RPi 4 example
iCMDdev Oct 27, 2024
ec9afca
Simplified README.md (removed redundent chmod command)
iCMDdev Oct 27, 2024
9403cb3
Added LLVM instructions
iCMDdev Oct 27, 2024
471c4a5
Update description
iCMDdev Oct 27, 2024
b2e3601
Typo fix
iCMDdev Oct 27, 2024
f560449
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Dec 12, 2024
8f1ca70
Update pico-w-blink-sdk README.md
iCMDdev Dec 13, 2024
7451fe2
Added CI support
iCMDdev Dec 13, 2024
7426575
Merge pull request #3 from iCMDdev/RPi-4B-BCM2711
iCMDdev Dec 13, 2024
e9a3971
Update build-rpi-baremetal.yml
iCMDdev Dec 13, 2024
c60a427
Rename workflow
iCMDdev Dec 13, 2024
f768d03
Update build-rpi-baremetal.yml
iCMDdev Dec 13, 2024
669fcc8
Update build-rpi-baremetal.yml
iCMDdev Dec 13, 2024
30def4e
Update build-rpi-baremetal.yml
iCMDdev Dec 13, 2024
e7076ae
Update build-rpi-baremetal.yml
iCMDdev Dec 13, 2024
0dee67c
Makefile typo fix
iCMDdev Dec 13, 2024
290c928
Merge pull request #5 from iCMDdev/RPi-4B-BCM2711
iCMDdev Dec 13, 2024
a6e2b92
Makefile fixes
iCMDdev Dec 13, 2024
ce46d5e
Merge pull request #6 from iCMDdev/RPi-4B-BCM2711
iCMDdev Dec 13, 2024
bda28bb
Makefile fixes for Linux host
iCMDdev Dec 13, 2024
b1c238c
Merge pull request #7 from iCMDdev/RPi-4B-BCM2711
iCMDdev Dec 13, 2024
92b775c
Fix styling
iCMDdev Dec 13, 2024
b677708
Update README.md
iCMDdev Dec 13, 2024
47894c7
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Dec 15, 2024
7f99773
Update build-rpi-baremetal.yml
iCMDdev Dec 15, 2024
3e623d8
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Dec 15, 2024
c202dd5
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Dec 17, 2024
dc4024f
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Dec 23, 2024
92dd75b
Merge branch 'main' into RPi-4B-BCM2711
rauhul Jan 3, 2025
8b33b8b
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev Jan 3, 2025
dab55e1
Update build-rpi-baremetal.yml
iCMDdev Jan 3, 2025
7e539ed
Update build-rpi-baremetal.yml
iCMDdev Jan 3, 2025
6e71205
Update build-rpi-baremetal.yml
iCMDdev Jan 3, 2025
691635e
Update build-rpi-baremetal.yml
iCMDdev Jan 3, 2025
da8dc49
Update build-rpi-baremetal.yml
iCMDdev Jan 3, 2025
30c64b0
Modernize rpi-5 build
rauhul May 8, 2025
b4319e5
update linker tool
rauhul May 8, 2025
93bfea5
use main of mmio
rauhul May 8, 2025
c6b823a
update rpi-4
rauhul May 8, 2025
ad1958d
minor readme changes
rauhul May 8, 2025
ee42096
Update build-rpi-baremetal.yml
iCMDdev May 13, 2025
bf57c27
Update build-rpi-baremetal.yml
iCMDdev May 13, 2025
3501877
Update build-rpi-baremetal.yml
iCMDdev May 13, 2025
aad1df5
Merge pull request #10 from apple/rpi-swiftpm-link
iCMDdev May 13, 2025
5aa3f03
Update Package.swift
iCMDdev May 13, 2025
55d2872
Update Makefile
iCMDdev May 18, 2025
ecf9076
Update build-rpi-baremetal.yml
iCMDdev May 18, 2025
559f476
Merge branch 'main' into RPi-4B-BCM2711
iCMDdev May 18, 2025
e9250ba
Update build-rpi-baremetal.yml
iCMDdev May 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/build-rpi-baremetal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Raspberry Pi Baremetal

on:
push:
branches: ["main"]
branches: ["main", "RPi-4B-BCM2711"]
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

Expand All @@ -29,3 +29,11 @@ jobs:
- name: Build ${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: make

- name: Upload build files artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.example }}-binary
path: |
${{ matrix.example }}/kernel8*
retention-days: 30
19 changes: 19 additions & 0 deletions Tools/Toolsets/rpi-5-elf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"schemaVersion": "1.0",
"swiftCompiler": {
"extraCLIOptions": [
"-Xfrontend", "-disable-stack-protector",
"-Xfrontend", "-function-sections",
"-enable-experimental-feature", "Embedded",
"-Xfrontend", "-mergeable-symbols",
"-Xclang-linker", "-fuse-ld=lld",
"-Xclang-linker", "-nostdlib"
]
},
"linker": {
"extraCLIOptions": [
"-T", "Sources/Support/linkerscript.ld",
"--unresolved-symbols=ignore-in-object-files"
]
}
}
61 changes: 40 additions & 21 deletions rpi-4b-blink/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
SWIFT_EXEC ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f swift; else which swift; fi)
CLANG ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f clang; else which clang; fi)
LLVM_OBJCOPY ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f llvm-objcopy; else which llvm-objcopy; fi)
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

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

.PHONY: all clean
# Flags
ARCH := aarch64
TARGET := $(ARCH)-none-none-elf
SWIFT_BUILD_ARGS := \
--configuration release \
--triple $(TARGET) \
--toolset $(TOOLSET) \
--disable-local-rpath
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)

all: kernel8.img
.PHONY: build
build:
@echo "building..."
$(SWIFT_BUILD) \
$(SWIFT_BUILD_ARGS) \
--verbose

kernel8.img: kernel8.elf
@echo "💾 Converting to binary kernel image with llvm-objcopy..."
$(LLVM_OBJCOPY) -O binary kernel8.elf kernel8.img
@echo ""
@echo "🥳 Done! kernel8.img was saved to this directory."
@echo "extracting binary..."
$(LLVM_OBJCOPY) \
-O binary \
"$(BUILDROOT)/Application" \
"$(BUILDROOT)/Application.bin" \

kernel8.elf: $(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o link.ld
@echo "🔗 Linking with clang..."
$(CLANG) --target=aarch64-elf -o kernel8.elf $< $^ -fuse-ld=lld -nostdlib -Wl,--unresolved-symbols=ignore-in-object-files -Wl,-T ./link.ld
@echo ""

$(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o:
@echo "🛠️ Building with Swift Package Manager..."
$(SWIFT_EXEC) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
@echo ""

.PHONY: clean
clean:
rm -rf kernel8.elf kernel8.img .build
@echo "cleaning..."
@swift package clean
@rm -rf .build
6 changes: 3 additions & 3 deletions rpi-4b-blink/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 7 additions & 22 deletions rpi-4b-blink/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,18 @@
import PackageDescription

let package = Package(
name: "RPi4B-Blink",
platforms: [
.macOS(.v14)
],
name: "rpi-4b-blink",
products: [
.library(
name: "MainApp",
type: .static,
targets: ["MainApp"])
.executable(name: "Application", targets: ["Application"])
],
dependencies: [
.package(
url: "https://github.com/apple/swift-mmio.git",
branch: "swift-embedded-examples")
.package(url: "https://github.com/apple/swift-mmio.git", branch: "main")
],
targets: [
.target(
name: "MainApp",
.executableTarget(
name: "Application",
dependencies: [
.product(name: "MMIO", package: "swift-mmio")
],
swiftSettings: [
.enableExperimentalFeature("Embedded"),
.unsafeFlags(["-Xfrontend", "-function-sections"]),
]
),
]),
.target(name: "Support"),

]
)
])
2 changes: 0 additions & 2 deletions rpi-4b-blink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
- Build the program, then copy the kernel image to the SD card.
``` console
$ cd rpi-4b-blink
$ export TOOLCHAINS='<toolchain-identifier>' # Your Swift nightly toolchain identifier
$ make
$ cp kernel8.img /Volumes/bootfs
```
- If your original OS is not 64-bit, make sure to set `arm_64bit=1` in `config.txt`.
- Place the SD card in your Raspberry Pi 4B, and connect it to power.
- After the boot sequence, the green (ACT) led will start blinking in a regular pattern.

80 changes: 80 additions & 0 deletions rpi-4b-blink/Sources/Application/Application.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors.
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import MMIO

@Register(bitWidth: 32)
struct GPSET1 {
@ReadWrite(bits: 10..<11, as: Bool.self)
var set: SET
}

@Register(bitWidth: 32)
struct GPCLR1 {
@ReadWrite(bits: 10..<11, as: Bool.self)
var clear: CLEAR
}

@Register(bitWidth: 32)
struct GPFSEL4 {
@ReadWrite(bits: 6..<7, as: Bool.self)
var fsel42b1: FSEL42b1
@ReadWrite(bits: 7..<8, as: Bool.self)
var fsel42b2: FSEL42b2
@ReadWrite(bits: 8..<9, as: Bool.self)
var fsel42b3: FSEL42b3
}

@RegisterBlock
struct GPIO {
@RegisterBlock(offset: 0x200020)
var gpset1: Register<GPSET1>
@RegisterBlock(offset: 0x20002c)
var gpclr1: Register<GPCLR1>
@RegisterBlock(offset: 0x200010)
var gpfsel4: Register<GPFSEL4>
}

let gpio = GPIO(unsafeAddress: 0xFE00_0000)

func setLedOutput() {
gpio.gpfsel4.modify {
// setFunction Select 42 (fsel42) to 001
$0.fsel42b1 = true
$0.fsel42b2 = false
$0.fsel42b3 = false
}
}

func ledOn() {
gpio.gpset1.modify {
$0.set = true
}
}

func ledOff() {
gpio.gpclr1.modify {
$0.clear = true
}
}

@main
struct Application {
static func main() {
setLedOutput()
while true {
ledOn()
for _ in 1..<100000 {} // just a delay
ledOff()
for _ in 1..<100000 {} // just a delay
}
}
}
File renamed without changes.
61 changes: 40 additions & 21 deletions rpi-5-blink/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
SWIFT_EXEC ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f swift; else which swift; fi)
CLANG ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f clang; else which clang; fi)
LLVM_OBJCOPY ?= $(shell if [ "$(shell uname)" = "Darwin" ]; then xcrun -f llvm-objcopy; else which llvm-objcopy; fi)
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

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

.PHONY: all clean
# Flags
ARCH := aarch64
TARGET := $(ARCH)-none-none-elf
SWIFT_BUILD_ARGS := \
--configuration release \
--triple $(TARGET) \
--toolset $(TOOLSET) \
--disable-local-rpath
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)

all: kernel8.img
.PHONY: build
build:
@echo "building..."
$(SWIFT_BUILD) \
$(SWIFT_BUILD_ARGS) \
--verbose

kernel8.img: kernel8.elf
@echo "💾 Converting to binary kernel image with llvm-objcopy..."
$(LLVM_OBJCOPY) -O binary kernel8.elf kernel8.img
@echo ""
@echo "🥳 Done! kernel8.img was saved to this directory."
@echo "extracting binary..."
$(LLVM_OBJCOPY) \
-O binary \
"$(BUILDROOT)/Application" \
"$(BUILDROOT)/Application.bin" \

kernel8.elf: $(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o link.ld
@echo "🔗 Linking with clang..."
$(CLANG) --target=aarch64-elf -o kernel8.elf $< $^ -fuse-ld=lld -nostdlib -Wl,--unresolved-symbols=ignore-in-object-files -Wl,-T ./link.ld
@echo ""

$(BUILDROOT)/libMainApp.a $(BUILDROOT)/Support.build/boot.S.o:
@echo "🛠️ Building with Swift Package Manager..."
$(SWIFT_EXEC) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
@echo ""

.PHONY: clean
clean:
rm -rf kernel8.elf kernel8.img .build
@echo "cleaning..."
@swift package clean
@rm -rf .build
6 changes: 3 additions & 3 deletions rpi-5-blink/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 9 additions & 23 deletions rpi-5-blink/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,19 @@
import PackageDescription

let package = Package(
name: "RPi5-Blink",
platforms: [
.macOS(.v14)
],
name: "rpi-5-blink",
products: [
.library(
name: "MainApp",
type: .static,
targets: ["MainApp"])
.executable(name: "Application", targets: ["Application"])
],
dependencies: [
.package(
url: "https://github.com/apple/swift-mmio.git",
branch: "swift-embedded-examples")
.package(url: "https://github.com/apple/swift-mmio.git", branch: "main")
],
targets: [
.target(
name: "MainApp",
.executableTarget(
name: "Application",
dependencies: [
.product(name: "MMIO", package: "swift-mmio")
],
swiftSettings: [
.enableExperimentalFeature("Embedded"),
.unsafeFlags(["-Xfrontend", "-function-sections"]),
]
),
.product(name: "MMIO", package: "swift-mmio"),
"Support"
]),
.target(name: "Support"),

]
)
])
Loading
Loading