Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4684caf
Add README
arzam16 Feb 24, 2021
38ac66e
change gitignore
arzam16 May 4, 2021
e7923ff
dts: add device tree for mt6577
arzam16 Jan 23, 2021
5619430
Add Kconfig entry for mt6577
arzam16 Jan 23, 2021
4c752c1
dts: add device tree for Acer Iconia B1-A71 (mt8317)
arzam16 Jan 23, 2021
f452455
dts: add device tree for Lenovo IdeaPad A1000L-F (mt8317)
arzam16 May 10, 2022
6878e71
dts: add reserved-memory
arzam16 Jan 23, 2021
7e1b0b5
dts: add PMU
arzam16 Nov 28, 2021
19501e1
dts: add SCU
arzam16 Nov 28, 2021
c154722
dts: add PL310 cache controller
arzam16 Nov 28, 2021
fea3765
dts: add TWD timer
arzam16 Jan 12, 2022
8a61b6f
add twd-timer to Kconfig
arzam16 Jan 15, 2022
31216f3
dts: add TRNG
arzam16 Jan 15, 2022
fa574cc
dts: add infracfg
arzam16 Nov 28, 2021
4ade8a8
add mt6577 code stub
arzam16 Nov 28, 2021
2f6ca76
add L2C val and mask values
arzam16 Nov 28, 2021
6ebd975
init ACP
arzam16 Nov 28, 2021
3190561
watchdog: mtk_wdt: Refactor code to support more SoCs
arzam16 Nov 29, 2021
33b2871
dt-bindings: watchdog: mediatek: add support for mt6577 SoC
arzam16 Mar 5, 2021
bf9ed4b
watchdog: mtk_wdt: add support for mt6577
arzam16 May 5, 2021
bd5aae9
dts: add watchdog
arzam16 Mar 5, 2021
79a2f36
dts: add mcusys
arzam16 Nov 29, 2021
669f140
move defines and struct to separate header file
arzam16 Nov 29, 2021
88e075a
implement basic SMP based on downstream code (power on)
arzam16 Nov 29, 2021
346e500
dts: activate SMP
arzam16 Nov 29, 2021
0c47221
move smp hw (un)mapping into separate functions
arzam16 Nov 30, 2021
dd0dfa6
implement cpu_kill smp operation (power off)
arzam16 Nov 30, 2021
1f1a93e
dts: add mtk-hardware-id
arzam16 Nov 30, 2021
3311137
add Kconfig entry for mtk-hardware-id
arzam16 Nov 30, 2021
3b4f463
add Makefile entry for mtk-hardware-id
arzam16 Nov 30, 2021
4e0a017
add mtk-hardware-id driver
arzam16 Dec 8, 2021
2f1dac4
dt-bindings: i2c: i2c-mt65xx: remove mt6577 support
arzam16 Jan 20, 2022
5bbc6db
i2c: mediatek: remove mt6577 support
arzam16 Jan 20, 2022
8baab27
clk: mediatek: Make mtk_clk_register_composite() static
wens May 10, 2022
0b8fd04
clk: mediatek: apmixed: Drop error message from clk_register() failure
wens May 10, 2022
43f7164
clk: mediatek: Convert mtk_{alloc, free}_clk_data to struct clk_hw
wens May 10, 2022
1a5826e
clk: mediatek: Replace 'struct clk' with 'struct clk_hw'
wens May 10, 2022
a61e0ce
clk: mediatek: mt27xx: Replace 'struct clk' with 'struct clk_hw'
wens May 10, 2022
2990c13
clk: mediatek: mt67xx: Replace 'struct clk' with 'struct clk_hw'
wens May 10, 2022
b965cb4
clk: mediatek: mt7xxx: Replace 'struct clk' with 'struct clk_hw'
wens May 10, 2022
47d5ff2
clk: mediatek: Switch to clk_hw provider APIs
wens May 10, 2022
8786cbc
clk: mediatek: Fix unused 'ops' field in mtk_pll_data
arzam16 May 14, 2022
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ x509.genkey

# Documentation toolchain
sphinx_*/

boot.img
bootimg.sh
*.bak
patches/
9 changes: 4 additions & 5 deletions Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ The MediaTek's I2C controller is used to interface with I2C devices.

Required properties:
- compatible: value should be either of the following.
"mediatek,mt2701-i2c", "mediatek,mt6577-i2c": for MediaTek MT2701
"mediatek,mt2701-i2c": for MediaTek MT2701
"mediatek,mt2712-i2c": for MediaTek MT2712
"mediatek,mt6577-i2c": for MediaTek MT6577
"mediatek,mt6589-i2c": for MediaTek MT6589
"mediatek,mt6797-i2c", "mediatek,mt6577-i2c": for MediaTek MT6797
"mediatek,mt6797-i2c", "mediatek,mt2701-i2c": for MediaTek MT6797
"mediatek,mt7622-i2c": for MediaTek MT7622
"mediatek,mt7623-i2c", "mediatek,mt6577-i2c": for MediaTek MT7623
"mediatek,mt7623-i2c", "mediatek,mt2701-i2c": for MediaTek MT7623
"mediatek,mt7629-i2c", "mediatek,mt2712-i2c": for MediaTek MT7629
"mediatek,mt8168-i2c": for MediaTek MT8168
"mediatek,mt8173-i2c": for MediaTek MT8173
Expand Down Expand Up @@ -40,7 +39,7 @@ Optional properties:
Example:

i2c0: i2c@1100d000 {
compatible = "mediatek,mt6577-i2c";
compatible = "mediatek,mt6589-i2c";
reg = <0x1100d000 0x70>,
<0x11000300 0x80>;
interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_LOW>;
Expand Down
1 change: 1 addition & 0 deletions Documentation/devicetree/bindings/watchdog/mtk-wdt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Required properties:
- compatible should contain:
"mediatek,mt2701-wdt", "mediatek,mt6589-wdt": for MT2701
"mediatek,mt2712-wdt": for MT2712
"mediatek,mt6577-wdt": for MT6577
"mediatek,mt6582-wdt", "mediatek,mt6589-wdt": for MT6582
"mediatek,mt6589-wdt": for MT6589
"mediatek,mt6797-wdt", "mediatek,mt6589-wdt": for MT6797
Expand Down
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 🛸 Attention 🛸 Danger zone 🛸
History is being overwritten here. **Force pushes and weird rebases happen often in this repository**. Be careful in case you will ever want to fork this.

# MT6577 Linux support
This repository contains my small work on mainlining the MT6577 Cortex-A9 CPU

| ![Acer Iconia B1-A71 demo](additional-files/img/demo-acer-b1-a71.jpg) | ![Lenovo A1000L-F demo](additional-files/img/demo-lenovo-a1000lf.jpg) |
| --- | --- |
| _Acer Iconia B1-A71 running [WOOD](https://github.com/maximevince/fbDOOM) on linux-mt6577 kernel_ | _Lenovo IdeaTab A1000L-F displaying linux-mt6577 boot log_ |

## Introduction

Back in 2011~2013, MediaTek MT6575/77 Cortex-A9 CPUs were very popular for low-end mobile phones. There are more than 100 devices utilizing these processors. Moreover, there are so-called tablet revisions (like MT8317) of MT6577 without cellular capabilities. Most of these devices run Android 4.0-4.2, and they have never received any real OS updates althrough there were reports of developers successfully porting Android 4.4. According to my research of public repositories of MediaTek kernels, vast majority of MT6575/77 devices uses Linux kernel v3.4.x. Bringing a mainline support for these processors will give devices a second life.

These chips were not performant even back in 2012, but they still can power a tiny webserver, a network file storage or some simple digital playground. I encourage everyone who has knowledge to help make it work. I started working on this without having any particular skills and knowledge, and what you see here is result of many months of work.

The code published in this repository has been tested and proved working (more on that below) on Linux v5.8~v5.18 running on Acer Iconia B1-A71 (MT8317). The device boots and communicates over UART. I also made screen work but it uses a framebuffer allocated by UBoot for showing a boot logo. The proper framebuffer+mtkfb binding still has to be made.

---

## What works

1. Multicore operating mode (SMP). Current code is able to perform full power cycle (power on, power off) for the 2nd CPU core.

2. Generic hardware such as SCU, bogus clocks, timer, sysirq, GIC.

3. 4 UARTs. On some MediaTek devices Bluetooth, and WiFi, and other radio communication hardware is controlled over UART. Working UART makes interacting with such hardware easier and provides a room for driver development.

4. Basic screen output with `simple-framebuffer` driver using framebuffer pre-configured by UBoot. However no image might show up under certain conditions, read more below.

## Important notes and TODOs

(when referring to "Current ...", I mean the latest kernel version at the time of writing this which is 5.18-rc6)

1. simple-framebuffer works when the device is turned on while on charger or connected to the PC. Screen might get stuck on vendor boot logo when booted without a charger/USB connection.

2. Need to process ATAGS passed from the bootloader to get *some* very useful values such as in-memory addresses of the kernel image and initramfs, and valid framebuffer address (it actually varies). This would completely eliminate the need to change addresses in a DTS or messing with a bogus ramdisk (more on this below), and it will solve the simple-framebuffer issue described above. On 5.16-rc2 *just* enabling the ATAGS support causes kernelpanic even before the earlyprintk is available. Most likely (but not yet confirmed) most ATAGS must be ignored in mainline kernel, probably in the `fixup` function?

3. Please help me port the **clock driver**. It'd be awesome as most device drivers depend on clocks.

4. No real I2C support for MT6577. Existing i2c-mt65xx driver was never supposed to support MT6577 because it relies on I2C DMA engine not present on this SoC. On Apr 16 19:20:48 PDT 2022, my commits (GH: [1](https://github.com/arzam16/linux-mt6577/commit/4b52288f33f4a09138f2edf786d23d27950104be) and [2](https://github.com/arzam16/linux-mt6577/commit/dace14f65a2da8e0afa66da26ead76356b355d24)) have been finally applied (LKML: [1](https://lists.infradead.org/pipermail/linux-mediatek/2022-April/039222.html) and [2](https://lists.infradead.org/pipermail/linux-mediatek/2022-April/039223.html)) by Wolfram Sang.

## Building

### Kernel config

Check the `additional-files/cfg` directory. `CONFIG_INITRAMFS_SOURCE` **must be changed** with path to your ramdisk .cpio.

### Initramfs

I went with a buildroot-2021.11 ramdisk that starts a shell on UART and supports file transfer out of the box (with `lrzsz` package). My buildroot config is in the `additional-files/cfg` directory. `BR2_CCACHE_DIR` **must be changed** with path to your cache directory.

### Headers

Keep in mind how an old Mediatek bootloader (UBoot or LK) works in terms of booting a kernel. The very simplified algorithm is:
1. Read the BOOTIMG partition from the EMMC.
2. Read the 1st part of BOOTIMG containing the kernel executable.
3. Verify if the 1st part has a valid `KERNEL` header. Abort if there's no header.
4. Read the 2nd part of BOOTIMG containing the ramdisk.
5. Verify if the 2nd part has a valid `ROOTFS` header. Abort if there's no header.
6. Load kernel executable without KERNEL header into specific memory address.
7. Load ramdisk without ROOTFS header into specific memory address.
8. Prepare ATAGS and jump into the kernel memory address.

UBoot/LK require a special mediatek header added to both kernel and initramfs. Add them every time you're making a boot.img. There's an utility for this called `mkimage`.

Such an old bootloader does not support DTS out of the box, so a DTS has to be appended to the kernel image (the corresponding kernel config option must be enabled).

Every time you make a change in initramfs (.cpio) image, you have to recalculate it's size for `linux,initrd-end` parameter in the device-specific DTS. It's very annoying, to say the least. To combat that I just pack the initramfs into the kernel executable itself. But with this trick the bootloader will refuse to boot because it won't find the initramfs in BOOTIMG. I made an ugly (but working) workaround: even when you have an initramfs already embedded into the kernel image, just add a tiny decoy (dummy) initramfs to boot.img, but don't forget to add a header.
```
# Generate 64 kB of random crap
dd if=/dev/urandom of=ramdisk-dummy bs=64k count=1

# Append a MediaTek header so UBoot will pass a check
mkimage ramdisk-dummy ROOTFS > ramdisk-dummy.mtk

# Then use it for creating a flashable boot.img:
mkbootimg --kernel ... --ramdisk ramdisk-dummy.mtk -o boot.img
```

![BOOTIMG partition image structure](additional-files/img/bootimg-diagram.png)

## Notes on MT6575

Since MT6577 is a dual-core version of MT6575, just remove the second CPU core definition from DTS and you're good to go. MT6575 also lacks 3rd I2C bus, but as of now it's not declared for MT6577 either.

It might be a great idea to use MT6575 as a base DTS, and create a small DTS for MT6577 with all necessary changes like second CPU core and third I2C bus.

## Post scriptum

I would like to thank everyone in [postmarketOS community](https://wiki.postmarketos.org/wiki/Category:Community) who helped me and expressed all kinds of support.
Loading