Skip to content

Commit

Permalink
Merge pull request #75 from woa-msmnile/sunflower/test
Browse files Browse the repository at this point in the history
Separate Linux DTB/Android DTB & Added some devices.
  • Loading branch information
sunflower2333 authored Feb 12, 2023
2 parents aa08240 + b500191 commit 314bd9c
Show file tree
Hide file tree
Showing 1,145 changed files with 32,339 additions and 119 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ tags/
*.bak
BuildConfig.conf
ACPI.inc
build_uefi.sh
DXEupdate.sh
uefi_*.img
android-boot.img

/Conf/
/SurfaceDuo/
Expand Down
29 changes: 14 additions & 15 deletions BootShim/BootShim.S
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
_Head:
/* Set _Entry address */
adr x1, _Payload //Kernel Addr
adr x1, _Payload // 保存Payload地址到x1
/* Jump to the real code */
b _Start
b _Start // 跳转到_Start处运行
/* Fake Linux kernel header */

_StackBase:
/* Text Offset */
.quad UEFI_BASE
.quad UEFI_BASE // UEFI FD 基地址

_StackSize:
/* Image Size */
.quad UEFI_SIZE
.quad UEFI_SIZE // UEFI FD 大小

/* Flags */
.quad 0
Expand All @@ -33,16 +33,16 @@ _StackSize:

// Alignment Patch Start
_PaddingSize:
.quad PADDING_SIZE
.quad PADDING_SIZE // 2MB对齐 空白文件大小
// Alignment Patch End

_Start:
adr x7, _Head // 保存abl头地址到x7
mov x4, x1 // 将Payload的起始地址保存到x4之中
ldr x5, _StackBase // 将StackBase保存到x5
cmp x4, x5 // 判断 StackBase是否为UEFI FD地址
beq _Entry // 如果是,那么就直接跳转到Entry
ldr x6, _StackSize // 将StackSize 保存到 x6
adr x7, _Head // 保存abl头地址到x7
mov x4, x1 // 将Payload的起始地址保存到x4之中
ldr x5, _StackBase // 将StackBase保存到x5
cmp x4, x5 // 判断 StackBase是否为UEFI FD地址
beq _Entry // 如果是,那么就直接跳转到Entry
ldr x6, _StackSize // 将StackSize 保存到 x6

// 拷贝UEFI FD 到Stack Base, 拷贝的大小为Stack Size
_CopyLoop:
Expand All @@ -54,20 +54,19 @@ _CopyLoop:

// Alignment Patch Start
_PatchPayLoadAddr:
// Save PaddingSize to reg
// x1: Payload Addr
// x1 + FD Size + Padding Size = Linux Kernel
// Linux Utils will add FD Size later.
ldr x2, _PaddingSize
add x1, x1, x2
ldr x2, _PaddingSize // 将_PaddingSize中的内容加载到x2中
add x1, x1, x2 // 计算x1与x2的和
// Alignment Patch End

_Entry:
br x5 // 跳向 x5指向的内存地址去执行,也就是StackBase指向的地方(UEFI FD)

_Dead:
/* We should never get here */
b _Dead
b _Dead // 死循环

.text
.align 4
Expand Down
29 changes: 29 additions & 0 deletions Documentation/DefinesGuidance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## This Doc will indroduce some Defines you may need in Defines.dsc.inc
___
> **HAS_MLVM**
* Type
- Boolean
* Why define it ?
- Some devices have MLVM region, some do not.
- If the device has MLVM enabled, MLVM regions will be protected, and they'll be un-readable and un-writeable.
* What happened when **TRUE**?
- If `HAS_MLVM = TRUE`, the MLVM regions will be reserved, so HLOS will not use this region.
- Total RAM size will decrease about 400MB.
* Where used it ?
- `HAS_MLVM` is used in Platforms/SurfaceDuoFamilyPkg/Driver/RamPartitionDxe/ExtendedMemoryMap.h.

> **CUST_PLATFORM_PRE_PI_LIB**
* Type
- Boolean
* Why define it ?
- Some device may want to customized `IsLinuxBootRequested()` function in Library/PlatformPrePiLib/PlatformUtils.c
- The `IsLinuxBootRequested()` function is used to judge the direction where to boot.
+ return `TRUE`
* boot to Android
+ return `FALSE`
* boot to UEFI
* What happened when **TRUE**?
- The build-system will try to find PlatformPrePiLib under Device/$(brand-codename)/Library/PlatformPrePiLib/
* Where used it ?
- `CUST_PLATFORM_PRE_PI_LIB` is used in Platforms/SurfaceDuoFamilyPkg/SurfaceDuoFamily.dsc.inc
- Line: 395
65 changes: 36 additions & 29 deletions Documentation/SimpleGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ___
`-- PythonLibs
```
- **AcpiTables/**
* *Stores ACPI tables except DSDT table.*
* *Stores ACPI tables.*
- **Device/**
* *Stores each device's specific binaries and configurations.*
* *The subfolder's name should be `brand-codename`.*
Expand All @@ -73,27 +73,44 @@ ___
- Let's take a closer look at `Device/nubia-tp1803`.
```
~/mu-msmnile/Platforms/SurfaceDuo1Pkg/Device$ tree -L 1 nubia-tp1803/
|-- ACPI
|-- Binaries
|-- DXE_Spec.inc
|-- Defines.dsc.inc
|-- PatchedBinaries
|-- PcdsFixedAtBuild.dsc.inc
`-- tp1803.dtb
├── ACPI
├── APRIORI.inc
├── Binaries
├── Defines.dsc.inc
├── DeviceTreeBlob
├── DXE.dsc.inc
├── DXE.inc
├── Library
├── PatchedBinaries
└── PcdsFixedAtBuild.dsc.inc
```
- **ACPI/**
* *Stores device's dsdt table.*
- **Binaries/**
* *Stores device's firmware binaries.*
- **Defines.dsc.inc**
* *Config of special flags.*
- **PatchedBinaries/**
* *As its name, it stores patched binaries for the device.*
- **Library/**
* *Put device specific Library*
- **DeviceTreeBlob/**
* *Put device tree blob*
- *In subdir `Linux` stores mainline linux dtb, file name must be `linux-codename.dtb`*
- *In subdir `Android` store Android dtb, file name must be `android-codename.dtb`*
- **APRIORI.inc**
* *Load Order of Dxe*
* *Included by SurfaceDuo1.fdf*
- **DXE.dsc**
* *Declare Drivers*
* *Included by SurfaceDuo1.fdf*
- **DXE.dsc.inc**
* *Declare Drivers*
* *Included by SurfaceDuo1.dsc*
- **Defines.dsc.inc**
* *Macros for special use.*
* *For detailed about Macros, please read [DefinesGuidance.md](DefinesGuidance.md)*
- **PcdsFixedAtBuild.dsc.inc**
* *Included by SurfaceDuo1.dsc.*
* *Stores device specific pcds. (e.g Screen resolution)*
- **tp1803.dtb**
* *must be `codename.dtb`.*
___
## **Part 1.** Early porting and tests.
- For example, porting uefi for meizu 16T.
Expand Down Expand Up @@ -127,9 +144,10 @@ ___
6. Enable MLVM in `Defines.dsc.inc` (FALSE -> TRUE)
7. Edit resolution in `PcdFixedAtBuild.dsc.inc`.
8. Patch your device's dxe and put them under `PatchedBinaries/`.
9. Replace `guacamole.dtb` with `m928q.dtb` (you can find your device's dtb in `/sys/firmware/fdt`, or see [Additions](#additions))
10. Build it.
11. Test it.
9. Replace `android-guacamole.dtb` with `android-m928q.dtb` (you can find your device's dtb in `/sys/firmware/fdt`, or see [Additions](#additions))
10. Replace `linux-guacamole.dtb` with `linux-m928q.dtb`.(if you do not have, create a dummy one by `touch linux-m928q.dtb`)
11. Build it.
12. Test it.
+ *Connect your phone to your computer and execute it on your computer.*
```
adb reboot bootloader
Expand Down Expand Up @@ -190,27 +208,16 @@ ___
___
## **Additions**
- How to get dtb of my device? *assume in termux environment*
* Clone and compile [split-appended-dtb](https://github.com/MoetaYuko/split-appended-dtb)
```
git clone https://github.com/MoetaYuko/split-appended-dtb.git ~/split-appended-dtb
cd ~/split-appended-dtb
gcc split-appended-dtb.c -o split-appended-dtb
```
* Download Magiskboot. ([Prebuilt](https://github.com/TeamWin/external_magisk-prebuilt/blob/android-11/prebuilt/))
* Get boot image from your phone.
```
sudo cp /dev/block/by-name/boot ~/split-appended-dtb/myboot.img
```
* Split dtbs from you phone's boot.
```
./split-appended-dtb myboot.img
```
* Choose the `SM8150 V2` one. *or V1? It depends on what your phone has.*
```
$ grep -rn "SM8150 V2"
dtbdump_8.dtb: binary file matches
./magiskboot_arm unpack myboot.img
```
* So the dtbdump_8.dtb is your phone's basic dtb.
* Renamed it to `codename.dtb` and put it into Device/*brand-codename*/.
* Renamed `kernel_dtb` to android-`codename`.dtb and put it into Device/*\<brand-codename\>*/DeviceTreeBlob/Android/.
- Should MLVM always be `TRUE`?
* In early test you can set it to `TRUE` to avoid MLVM issue.
* If you can boot windows, turn it to `FALSE` and have a try.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static ARM_MEMORY_REGION_DESCRIPTOR_EX gDeviceMemoryDescriptorEx[] = {
{"DBI Dump", 0x82A00000, 0x00D22000, NoHob, MMAP_IO, INITIALIZED, Reserv, UNCACHED_UNBUFFERED_XN},
{"HLOS 1", 0x83722000, 0x01FDE000, AddMem, SYS_MEM, SYS_MEM_CAP, BsData, WRITE_BACK_XN},
{"Hypervisor", 0x85700000, 0x00600000, AddMem, SYS_MEM, SYS_MEM_CAP, Reserv, NS_DEVICE}, /* Added */
{"MPSS_EFS", 0x85D00000, 0x00200000, AddMem, SYS_MEM, SYS_MEM_CAP, Reserv, UNCACHED_UNBUFFERED_XN},
{"Reserved", 0x85D00000, 0x00200000, AddMem, SYS_MEM, SYS_MEM_CAP, Reserv, UNCACHED_UNBUFFERED_XN},
{"AOP", 0x85F00000, 0x00020000, AddMem, MEM_RES, WRITE_COMBINEABLE, Reserv, UNCACHED_UNBUFFERED_XN}, /* Added */
{"AOP CMD DB", 0x85F20000, 0x00020000, AddMem, MEM_RES, WRITE_COMBINEABLE, Reserv, UNCACHED_UNBUFFERED_XN},
{"GPU PRR", 0x85F40000, 0x00010000, AddMem, MEM_RES, WRITE_COMBINEABLE, Reserv, UNCACHED_UNBUFFERED_XN},
Expand Down Expand Up @@ -66,7 +66,7 @@ static ARM_MEMORY_REGION_DESCRIPTOR_EX gDeviceMemoryDescriptorEx[] = {
// Memory hole: 0xB9900000 - 0xBFFFFFFF
// Size: 0x66FFFFF

{"RAM Partition", 0x0C0000000, 0x00300000, AddMem, SYS_MEM, SYS_MEM_CAP, Conv, WRITE_BACK_XN},
{"MPSS_EFS", 0x0C0000000, 0x00300000, AddMem, SYS_MEM, SYS_MEM_CAP, Reserv, UNCACHED_UNBUFFERED_XN},
{"DXE Heap", 0x0C0300000, 0x7FD00000, AddMem, SYS_MEM, SYS_MEM_CAP, Conv, WRITE_BACK_XN},

#if USE_MEMORY_FOR_SERIAL_OUTPUT == 1
Expand Down
Binary file not shown.
Loading

0 comments on commit 314bd9c

Please sign in to comment.