Skip to content

Commit

Permalink
pongoOS 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
woachk committed Oct 25, 2020
1 parent f906090 commit 9783d5d
Show file tree
Hide file tree
Showing 180 changed files with 28,581 additions and 1,052 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ RUN apt -y update; apt -y upgrade
RUN apt -y install automake make autoconf git wget tar xz-utils lzma libtinfo5 xxd

RUN mkdir -p /opt

RUN cd /opt; wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf.tar.xz; xz -d gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf.tar.xz; tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf.tar
RUN cd /opt; wget https://github.com/sbingner/llvm-project/releases/download/v10.0.0-1/linux-ios-arm64e-clang-toolchain.tar.lzma; mv linux-ios-arm64e-clang-toolchain.tar.lzma linux-ios-arm64e-clang-toolchain.tar.xz; xz -d linux-ios-arm64e-clang-toolchain.tar.xz; tar xvf linux-ios-arm64e-clang-toolchain.tar

ENV PATH="/opt/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin:/opt/ios-arm64e-clang-toolchain/bin:${PATH}"
ENV PATH="/opt/ios-arm64e-clang-toolchain/bin:${PATH}"

RUN mkdir -p /opt/sdks; cd /opt/sdks; \
git clone https://github.com/xybp888/iOS-SDKs.git; \
Expand Down
50 changes: 33 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,53 @@ ifndef $(HOST_OS)
endif
endif

PONGO_VERSION := 1.2.0-$(shell git log -1 --pretty=format:"%H" | cut -c1-8)
ifeq ($(HOST_OS),Darwin)
EMBEDDED_CC ?= xcrun -sdk iphoneos clang -arch arm64
STRIP ?= strip
STAT ?= stat -L -f %z
else
ifeq ($(HOST_OS),Linux)
EMBEDDED_CC ?= arm64-apple-ios12.0.0-clang -arch arm64
STRIP ?= cctools-strip
STAT ?= stat -L -c %s
endif
endif

PONGO_VERSION := 1.3.0-$(shell git log -1 --pretty=format:"%H" | cut -c1-8)
ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SRC := $(ROOT)/src
LIB := $(ROOT)/aarch64-none-darwin
INC := $(ROOT)/include
BUILD := $(ROOT)/build
RA1N := $(ROOT)/checkra1n-kpf

# General options
EMBEDDED_LDFLAGS ?= -nostdlib -static -Wl,-fatal_warnings -Wl,-dead_strip -Wl,-Z
EMBEDDED_CC_FLAGS ?= -Wall -Wunused-label -Werror -O3 -flto -ffreestanding -U__nonnull -nostdlibinc -I$(LIB)/include $(EMBEDDED_LDFLAGS)

# Pongo options
PONGO_LDFLAGS ?= -L$(LIB)/lib -lc -lm -lg -Wl,-preload -Wl,-no_uuid -Wl,-e,start -Wl,-order_file,$(SRC)/sym_order.txt -Wl,-image_base,0x418000000 -Wl,-sectalign,__DATA,__common,0x8
PONGO_CC_FLAGS ?= -DPONGO_VERSION='"$(PONGO_VERSION)"' -DAUTOBOOT -Djit_alloc=calloc -Djit_free=free -D'OBFUSCATE_C_FUNC(F)'='F' -I$(INC) -Iapple-include -I$(INC)/linux/ -I$(SRC)/kernel -I$(SRC)/drivers -I$(SRC)/linux/libfdt $(PONGO_LDFLAGS) $(CFLAGS)

EMBEDDED_CC ?= aarch64-none-elf-gcc
EMBEDDED_OBJCOPY ?= aarch64-none-elf-objcopy
EMBEDDED_LDFLAGS ?= -static -lc -lm -lg -Xlinker -T -Xlinker Pongo.ld -Wl,--gc-sections -Wl,--build-id=none
EMBEDDED_CC_FLAGS ?= -Wunused-label -D'OBFUSCATE_C_FUNC(F)'='F' -DDEV_BUILD=1 -DPONGO_VERSION='"$(PONGO_VERSION)"' $(EMBEDDED_LDFLAGS) -pie -O2 -flto -ffunction-sections -fdata-sections -mcpu=cortex-a57 -mtune=cortex-a57 -DAUTOBOOT
STAGE3_ENTRY_C := $(patsubst %, $(SRC)/boot/%, stage3.c clearhook.S patches.S demote_patch.S jump_to_image.S main.c)
PONGO_C := $(wildcard $(SRC)/kernel/*.c) $(wildcard $(SRC)/dynamic/*.c) $(wildcard $(SRC)/kernel/*.S) $(wildcard $(SRC)/shell/*.c)
PONGO_DRIVERS_C := $(wildcard $(SRC)/drivers/usb/*.c) $(wildcard $(SRC)/drivers/framebuffer/*.c) $(wildcard $(SRC)/drivers/uart/*.c) $(wildcard $(SRC)/drivers/timer/*.c) $(wildcard $(SRC)/drivers/gpio/*.c) $(wildcard $(SRC)/linux/lzma/*.c) $(wildcard $(SRC)/linux/libfdt/*.c) $(wildcard $(SRC)/linux/*.c) $(wildcard $(SRC)/drivers/xnu/*.c) $(wildcard $(SRC)/drivers/xnu/*.S)

STAGE3_ENTRY_C := $(patsubst %, $(SRC)/boot/%, stage3.c clearhook.s patches.s demote_patch.s jump_to_image.s main.c)
PONGO_C := $(wildcard $(SRC)/kernel/*.c) $(wildcard $(SRC)/dynamic/*.c) $(wildcard $(SRC)/kernel/*.s) $(wildcard $(SRC)/shell/*.c)
PONGO_DRIVERS_C := $(wildcard $(SRC)/drivers/usb/*.c) $(wildcard $(SRC)/drivers/framebuffer/*.c) $(wildcard $(SRC)/drivers/uart/*.c) $(wildcard $(SRC)/drivers/timer/*.c) $(wildcard $(SRC)/drivers/gpio/*.c) $(wildcard $(SRC)/linux/lzma/*.c) $(wildcard $(SRC)/linux/libfdt/*.c) $(wildcard $(SRC)/linux/*.c) $(wildcard $(SRC)/drivers/xnu/*.c) $(wildcard $(SRC)/drivers/xnu/*.s)
PONGO_FLAGS := -ffreestanding -Iinclude -Iapple-include -Iinclude/linux/ -I$(SRC)/kernel -I$(SRC)/drivers -Wl,-e,_main -I$(SRC)/linux/libfdt
CHECKRA1N_CC ?= $(EMBEDDED_CC)

# CLANG_SPECIFIC should be $(BUILD)/entry.o, because of LLD builds.
# Note that we do not officially support building pongoOS with Clang for this early release.

.PHONY: all clean

all: $(BUILD)/Pongo.bin | $(BUILD)

$(BUILD)/Pongo.bin: $(BUILD)/Pongo.elf | $(BUILD)
$(EMBEDDED_OBJCOPY) -O binary $(BUILD)/Pongo.elf $@
$(BUILD)/Pongo.bin: $(BUILD)/vmacho $(BUILD)/Pongo | $(BUILD)
$(BUILD)/vmacho -f $(BUILD)/Pongo $@

$(BUILD)/Pongo.elf: $(STAGE3_ENTRY_C) $(PONGO_C) $(PONGO_DRIVERS_C) $(BUILD)/entry.o | $(BUILD)
$(EMBEDDED_CC) -o $@ $(EMBEDDED_CC_FLAGS) $(PONGO_FLAGS) $(STAGE3_ENTRY_C) $(PONGO_C) $(PONGO_DRIVERS_C) $(CLANG_SPECIFIC)
$(BUILD)/Pongo: $(SRC)/boot/entry.S $(STAGE3_ENTRY_C) $(PONGO_C) $(PONGO_DRIVERS_C) | $(BUILD)
$(EMBEDDED_CC) -o $@ $(EMBEDDED_CC_FLAGS) $(PONGO_CC_FLAGS) $(SRC)/boot/entry.S $(STAGE3_ENTRY_C) $(PONGO_C) $(PONGO_DRIVERS_C)

$(BUILD)/entry.o: $(SRC)/boot/entry.s | $(BUILD)
$(EMBEDDED_CC) -c -o $@ $(SRC)/boot/entry.s -pie -flto
$(BUILD)/vmacho: $(SRC)/vmacho.c | $(BUILD)
$(CC) -Wall -O3 -o $@ $^ $(CFLAGS)

$(BUILD):
mkdir -p $@
Expand Down
157 changes: 0 additions & 157 deletions Pongo.ld

This file was deleted.

22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
pongoOS
=======
![Docker](https://github.com/checkra1n/pongoOS/workflows/Docker/badge.svg)
![CI](https://github.com/checkra1n/pongoOS/workflows/CI/badge.svg)

An experimental pre-boot execution environment for Apple boards built on top of checkra1n.
A pre-boot execution environment for Apple boards built on top of checkra1n.

Building pongoOS via Docker
Building on macOS
-----------
* Install Docker
* Either build or pull the builder image
+ `docker build --tag checkra1n/build-pongo .`
+ `docker pull docker.pkg.github.com/checkra1n/pongoos/build-pongo:latest`
* Perform a build inside the container with `./build.sh`

- Install Xcode + command-line utilities
- `make clean all`

Building on Linux
-----------

- Download [Sam Bingner's iOS Toolchain](https://github.com/sbingner/llvm-project/releases/download/v10.0.0-1/linux-ios-arm64e-clang-toolchain.tar.lzma)
- Copy `scripts/arm64-apple-ios12.0.0-clang` to a directory in `$PATH`
- Adjust the `TOOLCHAIN` variable to point to the downloaded toolchain
- `make clean all`

Contributions
-------------
Expand Down
18 changes: 18 additions & 0 deletions aarch64-none-darwin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Newlib

This folder contains [Newlib](https://sourceware.org/newlib/) headers and static libraries built for arm64 with the Darwin ABI. This provides the runtime standard library for PongoOS.

### Building

The current build is based on Newlib 3.3.0 and requires a [custom patch](darwin.patch) to work with Apple's toolchain / the Darwin ABI.
It can be built as follows (where `/path/to/PongoOS` should be replaced with the path to this repository):

curl -O -J ftp:https://sourceware.org/pub/newlib/newlib-3.3.0.tar.gz
tar -xf newlib-3.3.0.tar.gz
cd newlib-3.3.0/newlib
git apply /path/to/PongoOS/aarch64-none-darwin/darwin.patch
./configure --prefix=/tmp/build --host=aarch64-none-darwin --enable-newlib-io-c99-formats --enable-newlib-io-long-long --disable-newlib-io-float --disable-newlib-supplied-syscalls --disable-shared --enable-static CC='xcrun -sdk iphoneos clang' CFLAGS='-arch arm64 -Wall -O3 -nostdlib -nostdlibinc -fno-blocks -U__nonnull' LDFLAGS='-Wl,-preload,-e,_main'
make
make install

The headers and static libraries will be placed in `/tmp/build/aarch64-none-darwin`. If you'd like to use them with PongoOS, simply move them from there to this directory.
Loading

0 comments on commit 9783d5d

Please sign in to comment.