Skip to content

Commit

Permalink
feat: experimental support for Pi 1, Pi 2, and Pi Zero (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Nov 29, 2023
1 parent 3306eec commit 9b4917e
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ xtask = "run --package xtask --"
[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"

[target.armv7-unknown-linux-musleabihf]
[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-musl]
Expand Down
2 changes: 2 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"version": "0.2",
"words": [
"armhf",
"Armhf",
"ascii",
"avahi",
"blkid",
Expand Down
2 changes: 1 addition & 1 deletion boot/u-boot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN ./00-prepare.sh

# Build U-Boot binaries.
WORKDIR /home/uboot/u-boot-2023.10
COPY ./configs/* configs
COPY ./configs/* configs/
COPY ./steps/01-build.sh .
RUN ./01-build.sh

Expand Down
18 changes: 18 additions & 0 deletions boot/u-boot/armhf_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dtparam=audio=on
camera_auto_detect=1
display_auto_detect=1
dtoverlay=vc4-kms-v3d
max_framebuffers=2

disable_overscan=1

enable_uart=1

[pi0w]
kernel=u-boot-armhf-zerow.bin

[pi1]
kernel=u-boot-armhf-pi1.bin

[pi2]
kernel=u-boot-armhf-pi2.bin
3 changes: 3 additions & 0 deletions boot/u-boot/bin/u-boot-armhf-pi1.bin
Git LFS file not shown
3 changes: 3 additions & 0 deletions boot/u-boot/bin/u-boot-armhf-pi2.bin
Git LFS file not shown
3 changes: 3 additions & 0 deletions boot/u-boot/bin/u-boot-armhf-zerow.bin
Git LFS file not shown
61 changes: 61 additions & 0 deletions boot/u-boot/configs/rpi_armhf_pi1_rugpi_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CONFIG_ARM=y
CONFIG_ARCH_CPU_INIT=y
CONFIG_ARCH_BCM283X=y
CONFIG_TEXT_BASE=0x00008000
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_TARGET_RPI=y
CONFIG_NR_DRAM_BANKS=1
CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x7ffff00
CONFIG_ENV_SIZE=0x4000
CONFIG_DEFAULT_DEVICE_TREE="bcm2835-rpi-b"
CONFIG_OF_LIBFDT_OVERLAY=y
CONFIG_SYS_LOAD_ADDR=0x1000000
CONFIG_BOOTSTD_DEFAULTS=y
CONFIG_OF_BOARD_SETUP=y
CONFIG_FDT_SIMPLEFB=y
CONFIG_USE_PREBOOT=y
CONFIG_PREBOOT="pci enum; usb start; setenv kernel_file kernel.img;"
# CONFIG_DISPLAY_CPUINFO is not set
# CONFIG_DISPLAY_BOARDINFO is not set
CONFIG_MISC_INIT_R=y
CONFIG_SYS_PROMPT="U-Boot> "
CONFIG_SYS_PBSIZE=1049
CONFIG_CMD_GPIO=y
CONFIG_CMD_MMC=y
CONFIG_CMD_USB=y
CONFIG_CMD_FS_UUID=y
CONFIG_OF_EMBED=y
CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
CONFIG_TFTP_TSIZE=y
CONFIG_BCM2835_GPIO=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_BCM2835=y
CONFIG_PINCTRL=y
# CONFIG_PINCTRL_GENERIC is not set
# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
CONFIG_SYSINFO=y
CONFIG_SYSINFO_SMBIOS=y
CONFIG_USB=y
CONFIG_USB_DWC2=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_HOST_ETHER=y
CONFIG_USB_ETHER_SMSC95XX=y
CONFIG_VIDEO=y
# CONFIG_VIDEO_BPP8 is not set
# CONFIG_VIDEO_BPP16 is not set
CONFIG_SYS_WHITE_ON_BLACK=y
CONFIG_VIDEO_BCM2835=y
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_EFI_LOADER=y
CONFIG_CMD_BOOTZ=y
CONFIG_CMD_BOOTI=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_USE_BOOTARGS=y
CONFIG_CMD_BOOTZ=y
CONFIG_CMD_BOOTI=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_USE_BOOTARGS=y
57 changes: 57 additions & 0 deletions boot/u-boot/configs/rpi_armhf_pi2_rugpi_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CONFIG_ARM=y
CONFIG_SKIP_LOWLEVEL_INIT=y
CONFIG_ARCH_CPU_INIT=y
CONFIG_ARCH_BCM283X=y
CONFIG_TEXT_BASE=0x00008000
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_TARGET_RPI_2=y
CONFIG_NR_DRAM_BANKS=1
CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x7ffff00
CONFIG_ENV_SIZE=0x4000
CONFIG_DEFAULT_DEVICE_TREE="bcm2836-rpi-2-b"
CONFIG_OF_LIBFDT_OVERLAY=y
CONFIG_SYS_LOAD_ADDR=0x1000000
CONFIG_BOOTSTD_DEFAULTS=y
CONFIG_OF_BOARD_SETUP=y
CONFIG_FDT_SIMPLEFB=y
CONFIG_USE_PREBOOT=y
CONFIG_PREBOOT="pci enum; usb start; setenv kernel_file kernel7.img;"
# CONFIG_DISPLAY_CPUINFO is not set
# CONFIG_DISPLAY_BOARDINFO is not set
CONFIG_MISC_INIT_R=y
CONFIG_SYS_PROMPT="U-Boot> "
CONFIG_SYS_PBSIZE=1049
CONFIG_CMD_GPIO=y
CONFIG_CMD_MMC=y
CONFIG_CMD_USB=y
CONFIG_CMD_FS_UUID=y
CONFIG_OF_EMBED=y
CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
CONFIG_TFTP_TSIZE=y
CONFIG_BCM2835_GPIO=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_BCM2835=y
CONFIG_PINCTRL=y
# CONFIG_PINCTRL_GENERIC is not set
# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
CONFIG_SYSINFO=y
CONFIG_SYSINFO_SMBIOS=y
CONFIG_USB=y
CONFIG_USB_DWC2=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_HOST_ETHER=y
CONFIG_USB_ETHER_SMSC95XX=y
CONFIG_VIDEO=y
# CONFIG_VIDEO_BPP8 is not set
# CONFIG_VIDEO_BPP16 is not set
CONFIG_SYS_WHITE_ON_BLACK=y
CONFIG_VIDEO_BCM2835=y
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_CMD_BOOTZ=y
CONFIG_CMD_BOOTI=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_USE_BOOTARGS=y
57 changes: 57 additions & 0 deletions boot/u-boot/configs/rpi_armhf_zerow_rugpi_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CONFIG_ARM=y
CONFIG_ARCH_CPU_INIT=y
CONFIG_ARCH_BCM283X=y
CONFIG_TEXT_BASE=0x00008000
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_TARGET_RPI_0_W=y
CONFIG_NR_DRAM_BANKS=1
CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x7ffff00
CONFIG_ENV_SIZE=0x4000
CONFIG_DEFAULT_DEVICE_TREE="bcm2835-rpi-zero-w"
CONFIG_OF_LIBFDT_OVERLAY=y
CONFIG_SYS_LOAD_ADDR=0x1000000
CONFIG_BOOTSTD_DEFAULTS=y
CONFIG_OF_BOARD_SETUP=y
CONFIG_FDT_SIMPLEFB=y
CONFIG_USE_PREBOOT=y
CONFIG_PREBOOT="pci enum; usb start; setenv kernel_file kernel.img;"
# CONFIG_DISPLAY_CPUINFO is not set
# CONFIG_DISPLAY_BOARDINFO is not set
CONFIG_MISC_INIT_R=y
CONFIG_SYS_PROMPT="U-Boot> "
CONFIG_SYS_PBSIZE=1049
CONFIG_CMD_GPIO=y
CONFIG_CMD_MMC=y
CONFIG_CMD_USB=y
CONFIG_CMD_FS_UUID=y
CONFIG_OF_EMBED=y
CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
CONFIG_TFTP_TSIZE=y
CONFIG_BCM2835_GPIO=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_BCM2835=y
CONFIG_PINCTRL=y
# CONFIG_PINCTRL_GENERIC is not set
# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
CONFIG_SYSINFO=y
CONFIG_SYSINFO_SMBIOS=y
CONFIG_USB=y
CONFIG_USB_DWC2=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_HOST_ETHER=y
CONFIG_USB_ETHER_SMSC95XX=y
CONFIG_VIDEO=y
# CONFIG_VIDEO_BPP8 is not set
# CONFIG_VIDEO_BPP16 is not set
CONFIG_SYS_WHITE_ON_BLACK=y
CONFIG_VIDEO_BCM2835=y
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_EFI_LOADER=y
CONFIG_CMD_BOOTZ=y
CONFIG_CMD_BOOTI=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_USE_BOOTARGS=y
3 changes: 3 additions & 0 deletions boot/u-boot/steps/01-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ function build_uboot() {
}

build_uboot arm64 64 rpi_arm64_rugpi_defconfig
build_uboot armhf-zerow 32 rpi_armhf_zerow_rugpi_defconfig
build_uboot armhf-pi1 32 rpi_armhf_pi1_rugpi_defconfig
build_uboot armhf-pi2 32 rpi_armhf_pi2_rugpi_defconfig
20 changes: 20 additions & 0 deletions crates/rugpi-bakery/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct BakeryConfig {
/// Indicates whether to include firmware files in the image.
#[serde(default)]
pub include_firmware: IncludeFirmware,
/// The target architecture to build an image for.
#[serde(default)]
pub architecture: Architecture,
/// Indicates which boot flow to use for the image.
#[serde(default)]
pub boot_flow: BootFlow,
Expand All @@ -43,6 +46,23 @@ pub enum IncludeFirmware {
Pi5,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum Architecture {
#[default]
Arm64,
Armhf,
}

impl Architecture {
pub fn as_str(self) -> &'static str {
match self {
Architecture::Arm64 => "arm64",
Architecture::Armhf => "armhf",
}
}
}

/// Load the configuration file from the current directory.
pub fn load_config(args: &Args) -> Anyhow<BakeryConfig> {
let current_dir = PathBuf::try_from(env::current_dir()?)?;
Expand Down
37 changes: 28 additions & 9 deletions crates/rugpi-bakery/src/tasks/bake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tempdir::TempDir;
use xscript::{run, Run};

use crate::{
config::{load_config, BakeryConfig, IncludeFirmware},
config::{load_config, Architecture, BakeryConfig, IncludeFirmware},
Args,
};

Expand Down Expand Up @@ -121,14 +121,33 @@ fn setup_uboot_boot_flow(ctx: &BakeCtx) -> Anyhow<()> {
ctx.mounted_config.path()
])?;
std::fs::remove_file(&ctx.mounted_config.path().join("kernel8.img"))?;
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/arm64_config.txt",
ctx.mounted_config.path().join("config.txt"),
)?;
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/bin/u-boot-arm64.bin",
ctx.mounted_config.path().join("u-boot-arm64.bin"),
)?;
match ctx.config.architecture {
Architecture::Arm64 => {
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/arm64_config.txt",
ctx.mounted_config.path().join("config.txt"),
)?;
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/bin/u-boot-arm64.bin",
ctx.mounted_config.path().join("u-boot-arm64.bin"),
)?;
}
Architecture::Armhf => {
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/armhf_config.txt",
ctx.mounted_config.path().join("config.txt"),
)?;
for model in ["zerow", "pi1", "pi2"] {
std::fs::copy(
format!("/usr/share/rugpi/boot/u-boot/bin/u-boot-armhf-{model}.bin"),
ctx.mounted_config
.path()
.join(format!("u-boot-armhf-{model}.bin")),
)?;
}
}
}

std::fs::copy(
"/usr/share/rugpi/boot/u-boot/bin/boot.scr",
ctx.mounted_config.path().join("boot.scr"),
Expand Down
10 changes: 8 additions & 2 deletions crates/rugpi-bakery/src/tasks/customize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn run(args: &Args, task: &CustomizeTask) -> Anyhow<()> {
let root_dir_path = Utf8Path::from_path(root_dir.path()).unwrap();
println!("Extracting system files...");
run!(["tar", "-x", "-f", &task.src, "-C", root_dir_path])?;
apply_recipes(&jobs, root_dir_path)?;
apply_recipes(&config, &jobs, root_dir_path)?;
println!("Packing system files...");
run!(["tar", "-c", "-f", &task.dest, "-C", root_dir_path, "."])?;
Ok(())
Expand Down Expand Up @@ -127,7 +127,11 @@ fn recipe_schedule(config: &BakeryConfig) -> Anyhow<Vec<RecipeJob>> {
Ok(recipes)
}

fn apply_recipes(jobs: &Vec<RecipeJob>, root_dir_path: &Utf8Path) -> Anyhow<()> {
fn apply_recipes(
config: &BakeryConfig,
jobs: &Vec<RecipeJob>,
root_dir_path: &Utf8Path,
) -> Anyhow<()> {
let _mounted_dev = Mounted::bind("/dev", root_dir_path.join("dev"))?;
let _mounted_dev_pts = Mounted::bind("/dev/pts", root_dir_path.join("dev/pts"))?;
let _mounted_sys = Mounted::bind("/sys", root_dir_path.join("sys"))?;
Expand Down Expand Up @@ -168,6 +172,7 @@ fn apply_recipes(jobs: &Vec<RecipeJob>, root_dir_path: &Utf8Path) -> Anyhow<()>
let mut vars = vars! {
DEBIAN_FRONTEND = "noninteractive",
RUGPI_ROOT_DIR = "/",
RUGPI_ARCH = config.architecture.as_str(),
RECIPE_DIR = "/run/rugpi/bakery/recipe/",
RECIPE_STEP_PATH = &script,
};
Expand All @@ -181,6 +186,7 @@ fn apply_recipes(jobs: &Vec<RecipeJob>, root_dir_path: &Utf8Path) -> Anyhow<()>
let mut vars = vars! {
DEBIAN_FRONTEND = "noninteractive",
RUGPI_ROOT_DIR = root_dir_path,
RUGPI_ARCH = config.architecture.as_str(),
RECIPE_DIR = &recipe.path,
RECIPE_STEP_PATH = &script,
};
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.rugpi-bakery
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ RUN /tmp/rugpi-docker/10-setup.sh
RUN mkdir -p /usr/share/rugpi/binaries/{arm64,armhf}
COPY --from=builder /project/target/aarch64-unknown-linux-musl/release/rugpi-ctrl /usr/share/rugpi/binaries/arm64/
COPY --from=builder /project/target/aarch64-unknown-linux-musl/release/rugpi-admin /usr/share/rugpi/binaries/arm64/
COPY --from=builder /project/target/armv7-unknown-linux-musleabihf/release/rugpi-ctrl /usr/share/rugpi/binaries/armhf/
COPY --from=builder /project/target/armv7-unknown-linux-musleabihf/release/rugpi-admin /usr/share/rugpi/binaries/armhf/
COPY --from=builder /project/target/arm-unknown-linux-musleabihf/release/rugpi-ctrl /usr/share/rugpi/binaries/armhf/
COPY --from=builder /project/target/arm-unknown-linux-musleabihf/release/rugpi-admin /usr/share/rugpi/binaries/armhf/

WORKDIR /project

Expand Down
2 changes: 1 addition & 1 deletion docker/layers/build-env/10-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ apt-get -y clean && rm -rf /var/lib/apt/lists/*
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --no-modify-path --default-toolchain "${RUST_VERSION}"

rustup target add armv7-unknown-linux-musleabihf # Raspberry Pi (32-bit)
rustup target add arm-unknown-linux-musleabihf # Raspberry Pi (32-bit)
rustup target add aarch64-unknown-linux-musl # Raspberry Pi (64-bit)

cargo install cargo-chef --locked
2 changes: 1 addition & 1 deletion docker/layers/builder/00-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -euo pipefail
cargo chef cook --release --bin rugpi-bakery --recipe-path recipe.json

# Prepare to build binaries for both, 32-bit and 64-bit Raspberry Pi.
cargo chef cook --release --target armv7-unknown-linux-musleabihf --recipe-path recipe.json
cargo chef cook --release --target arm-unknown-linux-musleabihf --recipe-path recipe.json
cargo chef cook --release --target aarch64-unknown-linux-musl --recipe-path recipe.json
Loading

0 comments on commit 9b4917e

Please sign in to comment.