Skip to content

Commit

Permalink
Merge main into macho-payload
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/payload.c
  • Loading branch information
EricRabil committed Nov 6, 2022
2 parents d59c388 + de0c032 commit f3ed691
Show file tree
Hide file tree
Showing 336 changed files with 57,404 additions and 2,349 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Expand Up @@ -8,6 +8,7 @@ AlignConsecutiveMacros: true
IndentCaseLabels: true
ColumnLimit: 100
IncludeBlocks: Regroup
IncludeIsMainRegex: '(_.*)?$'

# Include block order goes like this
# - config.h style files, including ../config.h
Expand All @@ -16,6 +17,8 @@ IncludeBlocks: Regroup
# - 3rd party code headers
# - build artifact headers (stuff outside of src/)
IncludeCategories:
- Regex: '^"(\.\./)*build/build_.*\.h"$'
Priority: -3
- Regex: '^"(\.\./)*config\.h"$'
Priority: -2
- Regex: '^<'
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,43 @@
# This is a basic workflow to help you get started with Actions

name: build

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Install aarch64-linux-gnu- toolchain
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y gcc-aarch64-linux-gnu
- name: Install nightly rust
run: |
export RUSTUP_TOOLCHAIN=nightly
rustup target install aarch64-unknown-none-softfloat
- name: Build
run: make -k -j2 ARCH=aarch64-linux-gnu- CHAINLOADING=1

- uses: actions/upload-artifact@v2
with:
name: m1n1
path: |
build/m1n1.macho
build/m1n1.bin
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Expand Up @@ -21,5 +21,13 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: install nightly rust
run: |
rm -f ~/.cargo/bin/rustfmt
rm -f ~/.cargo/bin/cargo-fmt
rustup toolchain install nightly --component rustfmt --component clippy --allow-downgrade
- name: Run format-check
run: make format-check
run: |
make format-check
make rustfmt-check
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,7 @@
build/
__pycache__
*.pyc

*.macho
*.swp
*.orig
*.rej
24 changes: 24 additions & 0 deletions .gitmodules
@@ -1,3 +1,27 @@
[submodule "artwork"]
path = artwork
url = https://github.com/AsahiLinux/artwork.git
[submodule "rust/vendor/rust-fatfs"]
path = rust/vendor/rust-fatfs
url = https://github.com/rafalh/rust-fatfs
[submodule "rust/vendor/bitflags"]
path = rust/vendor/bitflags
url = https://github.com/bitflags/bitflags
[submodule "rust/vendor/cfg-if"]
path = rust/vendor/cfg-if
url = https://github.com/alexcrichton/cfg-if
[submodule "rust/vendor/cstr_core"]
path = rust/vendor/cstr_core
url = https://github.com/Amanieu/cstr_core
[submodule "rust/vendor/cty"]
path = rust/vendor/cty
url = https://github.com/japaric/cty
[submodule "rust/vendor/uuid"]
path = rust/vendor/uuid
url = https://github.com/uuid-rs/uuid
[submodule "rust/vendor/log"]
path = rust/vendor/log
url = https://github.com/rust-lang/log
[submodule "rust/vendor/memchr"]
path = rust/vendor/memchr
url = https://github.com/BurntSushi/memchr
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,7 +1,7 @@
FROM debian:buster-slim
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y build-essential bash git locales gcc-aarch64-linux-gnu libc6-dev-arm64-cross device-tree-compiler imagemagick \
RUN apt-get update && apt-get install -y build-essential bash git locales gcc-aarch64-linux-gnu libc6-dev-arm64-cross device-tree-compiler \
&& rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
Expand Down
4 changes: 3 additions & 1 deletion LICENSE
@@ -1,4 +1,6 @@
Copyright (c) 2021 The Asahi Linux contributors
MIT License

Copyright The Asahi Linux Contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
176 changes: 131 additions & 45 deletions Makefile
@@ -1,26 +1,62 @@
ARCH := aarch64-linux-gnu-
RUSTARCH ?= aarch64-unknown-none-softfloat

ifeq ($(shell uname),Darwin)
USE_CLANG ?= 1
$(info INFO: Building on Darwin)
ifeq ($(shell uname -p),arm)
TOOLCHAIN ?= /opt/homebrew/opt/llvm/bin/
else
TOOLCHAIN ?= /usr/local/opt/llvm/bin/
endif
$(info INFO: Toolchain path: $(TOOLCHAIN))
endif

ifeq ($(shell uname -m),aarch64)
ARCH ?=
else
ARCH ?= aarch64-linux-gnu-
endif

ifeq ($(USE_CLANG),1)
CC := clang --target=$(ARCH)
AS := clang --target=$(ARCH)
LD := ld.lld
OBJCOPY := llvm-objcopy
CC := $(TOOLCHAIN)clang --target=$(ARCH)
AS := $(TOOLCHAIN)clang --target=$(ARCH)
LD := $(TOOLCHAIN)ld.lld
OBJCOPY := $(TOOLCHAIN)llvm-objcopy
CLANG_FORMAT := $(TOOLCHAIN)clang-format
EXTRA_CFLAGS ?=
else
CC := $(ARCH)gcc
AS := $(ARCH)gcc
LD := $(ARCH)ld
OBJCOPY := $(ARCH)objcopy
CC := $(TOOLCHAIN)$(ARCH)gcc
AS := $(TOOLCHAIN)$(ARCH)gcc
LD := $(TOOLCHAIN)$(ARCH)ld
OBJCOPY := $(TOOLCHAIN)$(ARCH)objcopy
CLANG_FORMAT := clang-format
EXTRA_CFLAGS ?= -Wstack-usage=1024
endif

CFLAGS := -O2 -Wall -Wundef -Werror=strict-prototypes -fno-common -fno-PIE \
CFLAGS := -O2 -Wall -g -Wundef -Werror=strict-prototypes -fno-common -fno-PIE \
-Werror=implicit-function-declaration -Werror=implicit-int \
-Wsign-compare -Wunused-parameter -Wno-multichar \
-ffreestanding -fpic -ffunction-sections -fdata-sections \
-nostdinc -isystem $(shell $(CC) -print-file-name=include) -isystem sysinc \
-fno-stack-protector -mgeneral-regs-only -mstrict-align -march=armv8.2-a
-fno-stack-protector -mgeneral-regs-only -mstrict-align -march=armv8.2-a \
$(EXTRA_CFLAGS)

LDFLAGS := -T m1n1.ld -EL -maarch64elf --no-undefined -X -Bsymbolic \
-z notext --no-apply-dynamic-relocs --orphan-handling=warn --strip-debug \
CFG :=
ifeq ($(RELEASE),1)
CFG += RELEASE
endif

# Required for no_std + alloc for now
export RUSTUP_TOOLCHAIN=nightly
RUST_LIB := librust.a
RUST_LIBS :=
ifeq ($(CHAINLOADING),1)
CFG += CHAINLOADING
RUST_LIBS += $(RUST_LIB)
endif

LDFLAGS := -EL -maarch64elf --no-undefined -X -Bsymbolic \
-z notext --no-apply-dynamic-relocs --orphan-handling=warn \
-z nocopyreloc --gc-sections -pie

MINILZLIB_OBJECTS := $(patsubst %,minilzlib/%, \
Expand All @@ -37,102 +73,152 @@ LIBFDT_OBJECTS := $(patsubst %,libfdt/%, \

OBJECTS := \
adt.o \
afk.o \
aic.o \
asc.o \
bootlogo_128.o bootlogo_256.o \
chainload.o \
chainload_asm.o \
chickens.o \
chickens_avalanche.o \
chickens_blizzard.o \
chickens_firestorm.o \
chickens_icestorm.o \
clk.o \
cpufreq.o \
dapf.o \
dart.o \
dcp.o \
dcp_iboot.o \
devicetree.o \
display.o \
exception.o exception_asm.o \
fb.o font.o font_retina.o \
gxf.o gxf_asm.o \
heapblock.o \
hv.o hv_vm.o hv_exc.o hv_vuart.o hv_wdt.o hv_asm.o hv_aic.o \
i2c.o \
iodev.o \
iova.o \
kboot.o \
macho.o \
main.o \
mcc.o \
memory.o memory_asm.o \
nvme.o \
payload.o \
pcie.o \
pmgr.o \
proxy.o \
ringbuffer.o \
rtkit.o \
sart.o \
sep.o \
smp.o \
start.o \
startup.o \
string.o \
tunables.o \
tunables.o tunables_static.o \
tps6598x.o \
uart.o \
uartproxy.o \
usb.o usb_dwc3.o \
utils.o utils_asm.o \
vsprintf.o \
wdt.o \
$(MINILZLIB_OBJECTS) $(TINF_OBJECTS) $(DLMALLOC_OBJECTS) $(LIBFDT_OBJECTS)

DTS := t8103-j274.dts
$(MINILZLIB_OBJECTS) $(TINF_OBJECTS) $(DLMALLOC_OBJECTS) $(LIBFDT_OBJECTS) $(RUST_LIBS)

BUILD_OBJS := $(patsubst %,build/%,$(OBJECTS))
DTBS := $(patsubst %.dts,build/dtb/%.dtb,$(DTS))

NAME := m1n1
TARGET := m1n1.macho
TARGET_RAW := m1n1.bin

DEPDIR := build/.deps

.PHONY: all clean format
all: build/$(TARGET) $(DTBS)
.PHONY: all clean format update_tag update_cfg invoke_cc
all: update_tag update_cfg build/$(TARGET) build/$(TARGET_RAW)
clean:
rm -rf build/*
format:
clang-format -i src/*.c src/*.h sysinc/*.h
$(CLANG_FORMAT) -i src/*.c src/*.h sysinc/*.h
format-check:
clang-format --dry-run --Werror src/*.c src/*.h sysinc/*.h

build/dtb/%.dts: dts/%.dts
@echo " DTCPP $@"
@mkdir -p "$(dir $@)"
@$(CC) -E -nostdinc -I dts -x assembler-with-cpp -o $@ $<

build/dtb/%.dtb: build/dtb/%.dts
@echo " DTC $@"
$(CLANG_FORMAT) --dry-run --Werror src/*.c src/*.h sysinc/*.h
rustfmt:
cd rust && cargo fmt
rustfmt-check:
cd rust && cargo fmt --check

build/$(RUST_LIB): rust/src/* rust/*
@echo " RS $@"
@mkdir -p $(DEPDIR)
@mkdir -p "$(dir $@)"
@dtc -I dts -i dts $< -o $@
@cargo build --target $(RUSTARCH) --lib --release --manifest-path rust/Cargo.toml --target-dir build
@cp "build/$(RUSTARCH)/release/${RUST_LIB}" "$@"

build/%.o: src/%.S
@echo " AS $@"
@mkdir -p $(DEPDIR)
@mkdir -p "$(dir $@)"
@$(AS) -c $(CFLAGS) -Wp,-MMD,$(DEPDIR)/$(*F).d,-MQ,"$@",-MP -o $@ $<
@$(AS) -c $(CFLAGS) -MMD -MF $(DEPDIR)/$(*F).d -MQ "$@" -MP -o $@ $<

build/%.o: src/%.c
@echo " CC $@"
@mkdir -p $(DEPDIR)
@mkdir -p "$(dir $@)"
@$(CC) -c $(CFLAGS) -Wp,-MMD,$(DEPDIR)/$(*F).d,-MQ,"$@",-MP -o $@ $<
@$(CC) -c $(CFLAGS) -MMD -MF $(DEPDIR)/$(*F).d -MQ "$@" -MP -o $@ $<

# special target for usage by m1n1.loadobjs
invoke_cc:
@$(CC) -c $(CFLAGS) -Isrc -o $(OBJFILE) $(CFILE)

build/$(NAME).elf: $(BUILD_OBJS) m1n1.ld
@echo " LD $@"
@$(LD) $(LDFLAGS) -o $@ $(BUILD_OBJS)
@$(LD) -T m1n1.ld $(LDFLAGS) -o $@ $(BUILD_OBJS)

build/$(NAME)-raw.elf: $(BUILD_OBJS) m1n1-raw.ld
@echo " LDRAW $@"
@$(LD) -T m1n1-raw.ld $(LDFLAGS) -o $@ $(BUILD_OBJS)

build/$(NAME).macho: build/$(NAME).elf
@echo " MACHO $@"
@$(OBJCOPY) -O binary $< $@
@$(OBJCOPY) -O binary --strip-debug $< $@

build/$(NAME).bin: build/$(NAME)-raw.elf
@echo " RAW $@"
@$(OBJCOPY) -O binary --strip-debug $< $@

update_tag:
@mkdir -p build
@echo "#define BUILD_TAG \"$$(git describe --tags --always --dirty)\"" > build/build_tag.tmp
@cmp -s build/build_tag.h build/build_tag.tmp 2>/dev/null || \
( mv -f build/build_tag.tmp build/build_tag.h && echo " TAG build/build_tag.h" )

update_cfg:
@mkdir -p build
@for i in $(CFG); do echo "#define $$i"; done > build/build_cfg.tmp
@cmp -s build/build_cfg.h build/build_cfg.tmp 2>/dev/null || \
( mv -f build/build_cfg.tmp build/build_cfg.h && echo " CFG build/build_cfg.h" )

build/build_tag.h:
@echo " TAG $@"
@echo "#define BUILD_TAG \"$$(git describe --always --dirty)\"" > $@
build/build_tag.h: update_tag
build/build_cfg.h: update_cfg

build/%.bin: data/%.png
build/%.bin: data/%.bin
@echo " IMG $@"
@convert $< -background black -flatten -depth 8 rgba:$@
@mkdir -p "$(dir $@)"
@cp $< $@

build/%.o: build/%.bin
@echo " BIN $@"
@mkdir -p "$(dir $@)"
@$(OBJCOPY) -I binary -B aarch64 -O elf64-littleaarch64 $< $@

build/%.bin: font/%.bin
@echo " CP $@"
@mkdir -p "$(dir $@)"
@cp $< $@

build/main.o: build/build_tag.h src/main.c
build/main.o: build/build_tag.h build/build_cfg.h src/main.c
build/usb_dwc3.o: build/build_tag.h src/usb_dwc3.c
build/chainload.o: build/build_cfg.h src/usb_dwc3.c

-include $(DEPDIR)/*



0 comments on commit f3ed691

Please sign in to comment.