Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Apple M1 support #45

Draft
wants to merge 58 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9d12ac8
hmm
Jan 16, 2021
9769323
m1 support
Jan 16, 2021
c6df623
m1 support
Jan 16, 2021
3078864
Merge branch 'master' of https://github.com/checkra1n/PongoOS
Jan 16, 2021
09c13ea
Remove IMG4 parser.
woachk Jan 16, 2021
122ad0d
irq
Jan 16, 2021
78c5086
Merge branch 'm1' of https://github.com/checkra1n/PongoOS into m1
Jan 16, 2021
3a16e96
Remove img4 parser part II.
woachk Jan 17, 2021
6ac0d2f
Merge branch 'm1' of github.com:checkra1n/pongoOS into m1
woachk Jan 17, 2021
b4ceaba
Integration to build system for M1.
woachk Jan 17, 2021
b1a69f7
el1
Jan 17, 2021
dc49ffb
change some MM stuff to not horribly break on >4GB devices
Jan 17, 2021
75adb03
dart
Jan 17, 2021
b281309
mapper
Jan 17, 2021
cc6af86
use mapper more widely
Jan 17, 2021
5e4c602
mapper tlbi
Jan 17, 2021
bbbe986
derp
Jan 17, 2021
72accf5
respect io-ranges
Jan 17, 2021
f23da17
begin work on synopsys dwc3, moved AIC, PMGR, WDT to HAL model
Jan 17, 2021
366cf41
pongo license header makes sense here
Jan 17, 2021
dcdbba6
Update Makefile
woachk Jan 17, 2021
761e202
Update Makefile
woachk Jan 17, 2021
2855f24
fix pmgr aliased accesses, usb bringup
Jan 17, 2021
fbab82c
Merge branch 'm1' of https://github.com/checkra1n/PongoOS into m1
Jan 17, 2021
9175436
bring up usb phy
Jan 18, 2021
48d7ec6
fix build
Jan 18, 2021
7da8a59
drd bringup attempt
Jan 18, 2021
ea32b9a
dwc3 bringup actually working!!!
Jan 18, 2021
e253d72
Merge branch 'master' into m1
woachk Jan 18, 2021
2fc787c
Update Makefile
woachk Jan 18, 2021
fe2cb1d
drd
Jan 18, 2021
9e02c9e
Merge branch 'm1' of https://github.com/checkra1n/PongoOS into m1
Jan 18, 2021
203f79d
move copyright
Jan 18, 2021
4e9d207
ok, now drd tells me its trying to reach out for an irq
Jan 19, 2021
eca1486
improve irq handling, add dart irq handler, improve HAL probing
Jan 19, 2021
2172e59
improve drd bringup, fix dart
Jan 19, 2021
87a3ea9
tunables
Jan 19, 2021
735312e
fix irq
Jan 19, 2021
8f570b3
drd irqzzzzzz
Jan 19, 2021
060d6f0
maybe not
Jan 19, 2021
55b21ef
improve hal logic
Jan 19, 2021
92d2d5d
HABEMUS USB
Jan 19, 2021
3c14f29
Update synopsys_drd_regs.h
woachk Jan 19, 2021
71c2710
Update LICENSE.md
woachk Jan 19, 2021
c712086
linux load, osx module load
Jan 20, 2021
7292f79
Merge branch 'm1' of https://github.com/checkra1n/PongoOS into m1
Jan 20, 2021
434afb2
add crlm copyright
Jan 20, 2021
23d449e
Update entry.S
woachk Jan 20, 2021
ab70867
linux boot frfr
Jan 20, 2021
71b099a
Merge branch 'm1' of https://github.com/checkra1n/PongoOS into m1
Jan 20, 2021
46b518e
WFI power gating, I2C starting point, HAL support for virtual service…
Jan 22, 2021
8cf5e72
add 8940x I2C driver for pongo
Jan 22, 2021
b4c28e5
cleanup i2c stack
Jan 22, 2021
b950229
begin cd3217 driver
Jan 22, 2021
6429312
cleanup
Jan 22, 2021
bbc4613
try to improve i2c driver a bit
Jan 22, 2021
aeee4d2
usbc
Jan 22, 2021
5ce5f28
begin GPIO, add virtual IRQ dispatching, redesign IRQ binding, begin HPM
Jan 23, 2021
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
32 changes: 31 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**License for USB controller drivers: src/drivers/usb/synopsys**
**License for USB controller drivers: src/drivers/usb/synopsys_otg**

Apache License

Expand Down Expand Up @@ -67,6 +67,36 @@ You may add Your own copyright statement to Your modifications and may provide a

END OF TERMS AND CONDITIONS

**License for USB controller header: src/drivers/usb/synopsys_drd_regs.h**

Copyright 2016 The Fuchsia Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

**License for Apple provided components**:
(apple-include, src/lib/libDER)

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ RA1N := $(ROOT)/checkra1n/kpf

# General options
EMBEDDED_LD_FLAGS ?= -nostdlib -static -Wl,-fatal_warnings -Wl,-dead_strip -Wl,-Z $(EMBEDDED_LDFLAGS)
EMBEDDED_CC_FLAGS ?= --target=arm64-apple-ios12.0 -Wall -Wunused-label -Werror -O3 -flto -ffreestanding -U__nonnull -nostdlibinc -I$(LIB)/include $(EMBEDDED_LD_FLAGS) $(EMBEDDED_CFLAGS)
EMBEDDED_CC_FLAGS ?= --target=arm64-apple-ios12.0 -mcpu=cyclone -mtune=cyclone -Wall -Wunused-label -Werror -O3 -ffreestanding -U__nonnull -nostdlibinc -I$(LIB)/include $(EMBEDDED_LD_FLAGS) $(EMBEDDED_CFLAGS)

# Pongo options
PONGO_LDFLAGS ?= -L$(LIB)/lib -lc -lm -Wl,-preload -Wl,-no_uuid -Wl,-e,start -Wl,-order_file,$(SRC)/sym_order.txt -Wl,-image_base,0x100000000 -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x4000
PONGO_CC_FLAGS ?= -DPONGO_VERSION='"$(PONGO_VERSION)"' -DAUTOBOOT -DPONGO_PRIVATE=1 -I$(SRC)/lib -I$(INC) -Iapple-include -I$(INC)/modules/linux/ -I$(SRC)/kernel -I$(SRC)/drivers -I$(SRC)/modules/linux/libfdt $(PONGO_LDFLAGS) -DDER_TAG_SIZE=8
PONGO_CC_FLAGS ?= -DPONGO_VERSION='"$(PONGO_VERSION)"' -DAUTOBOOT -DPONGO_PRIVATE=1 -I$(SRC)/lib -I$(INC) -Iapple-include -I$(INC)/modules/linux/ -I$(SRC)/kernel -I$(SRC)/drivers -I$(SRC)/modules/linux/libfdt $(PONGO_LDFLAGS) -DDER_TAG_SIZE=8 -mcpu=cortex-a76

# KPF options
CHECKRA1N_LDFLAGS ?= -Wl,-kext
Expand Down Expand Up @@ -88,7 +88,10 @@ CHECKRA1N_CC ?= $(EMBEDDED_CC)

.PHONY: all always clean distclean

all: $(BUILD)/Pongo.bin | $(BUILD)
all: $(BUILD)/Pongo.bin $(BUILD)/pongoOS.AppleSi.macho | $(BUILD)

$(BUILD)/pongoOS.AppleSi.macho: $(BUILD)/Pongo.bin $(BUILD)/machopack | $(BUILD)
$(BUILD)/machopack $(BUILD)/Pongo.bin $@

$(BUILD)/PongoConsolidated.bin: $(BUILD)/Pongo.bin $(BUILD)/checkra1n-kpf-pongo | $(BUILD)
bash -c "echo 6175746F626F6F740000200000000000 | xxd -ps -r | cat $(BUILD)/Pongo.bin <(dd if=/dev/zero bs=1 count="$$(((8 - ($$($(STAT) $(BUILD)/Pongo.bin) % 8)) % 8))") /dev/stdin $(BUILD)/checkra1n-kpf-pongo > $@"
Expand All @@ -107,6 +110,9 @@ $(BUILD)/checkra1n-kpf-pongo: $(CHECKRA1N_C) $(LIB)/lib/libc.a | $(BUILD)
$(BUILD)/vmacho: $(AUX)/vmacho.c | $(BUILD)
$(CC) -Wall -O3 -o $@ $^ $(CFLAGS)

$(BUILD)/machopack: $(AUX)/machopack.c | $(BUILD)
$(CC) -Wall -O3 -o $@ $^ $(CFLAGS)

$(BUILD):
mkdir -p $@

Expand Down
195 changes: 195 additions & 0 deletions linuxloader-crlm/dtree-dict.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/*
*
* Copyright (C) 2017-21 Corellium LLC
* All rights reserved.
*
*/

#include <mach-o/loader.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dtree.h"

typedef struct dt_elem_s {
unsigned depth;
struct dt_elem_s *left, *right, *parent, **up;
char *str;
} dt_elem;

struct dt_dict_s {
int size;
dt_elem *root;
};

dt_dict *dt_dict_new(int size)
{
dt_dict *dict = calloc(1, sizeof(dt_dict));
if(!dict)
return dict;
dict->size = size;
return dict;
}

static int dt_dict_delta(dt_elem *elem)
{
int res = 0;
if(elem->left)
res -= elem->left->depth + 1;
if(elem->right)
res += elem->right->depth + 1;
return res;
}

static void dt_dict_update(dt_elem *elem)
{
elem->depth = 0;
if(elem->left)
elem->depth = elem->left->depth + 1;
if(elem->right && elem->depth < elem->right->depth + 1)
elem->depth = elem->right->depth + 1;
}

static void dt_dict_pivot(dt_elem *root, dt_elem *pivot)
{
pivot->parent = root->parent;
pivot->up = root->up;
*(pivot->up) = pivot;

if(pivot == root->left) {
root->left = pivot->right;
if(root->left) {
root->left->parent = root;
root->left->up = &(root->left);
}

root->parent = pivot;
root->up = &(pivot->right);
pivot->right = root;
} else {
root->right = pivot->left;
if(root->right) {
root->right->parent = root;
root->right->up = &(root->right);
}

root->parent = pivot;
root->up = &(pivot->left);
pivot->left = root;
}

dt_dict_update(root);
dt_dict_update(pivot);
}

static void dt_dict_rebalance(dt_elem *elem)
{
int delta;

dt_dict_update(elem);

for(; elem; elem=elem->parent) {
delta = dt_dict_delta(elem);
if(delta < -1 || delta > 1) {
if(delta < -2 || delta > 2)
return;

if(delta < -1) {
if(dt_dict_delta(elem->left) > 0)
dt_dict_pivot(elem->left, elem->left->right);
dt_dict_pivot(elem, elem->left);
} else {
if(dt_dict_delta(elem->right) < 0)
dt_dict_pivot(elem->right, elem->right->left);
dt_dict_pivot(elem, elem->right);
}
elem = elem->parent;
}

if(!elem || !elem->parent)
break;

dt_dict_update(elem->parent);
}
}

void *dt_dict_find(dt_dict *_dict, char *str, unsigned mode)
{
dt_dict *dict = _dict;
dt_elem **pelem = &(dict->root), *parent = NULL;
int cmp;

while(*pelem) {
cmp = strcmp(str, (*pelem)->str);
if(!cmp) {
if(!(mode & DT_DICT_FIND))
return NULL;
return (*pelem) + 1;
}

parent = *pelem;
if(cmp < 0)
pelem = &(*pelem)->left;
else
pelem = &(*pelem)->right;
}

if(!(mode & DT_DICT_ADD))
return NULL;

(*pelem) = calloc(1, sizeof(dt_elem) + dict->size);
if(!*pelem)
return NULL;

(*pelem)->str = strdup(str);
(*pelem)->up = pelem;
(*pelem)->parent = parent;

parent = *pelem;
dt_dict_rebalance(*pelem);

return parent + 1;
}

static void dt_dict_iter_recurse(dt_elem *elem, void(*func)(void *param, char *str, void *elem), void *param)
{
if(elem->left)
dt_dict_iter_recurse(elem->left, func, param);
func(param, elem->str, elem + 1);
if(elem->right)
dt_dict_iter_recurse(elem->right, func, param);
}

void dt_dict_iter(dt_dict *_dict, void(*func)(void *param, char *str, void *elem), void *param)
{
dt_dict *dict = _dict;
if(dict->root)
dt_dict_iter_recurse(dict->root, func, param);
}

char *dt_dict_str(void *_elem)
{
dt_elem *elem = _elem;
return elem[-1].str;
}

static void dt_dict_free_recurse(dt_elem *elem)
{
if(elem->left)
dt_dict_free_recurse(elem->left);
if(elem->right)
dt_dict_free_recurse(elem->right);
free(elem->str);
free(elem);
}

void dt_dict_free(dt_dict *_dict)
{
dt_dict *dict = _dict;
if(dict->root)
dt_dict_free_recurse(dict->root);
free(dict);
}
Loading