Jump to content

Amlogic S905: Difference between revisions

From postmarketOS Wiki
No edit summary
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Infobox soc
{{Infobox soc
| name = S905/S905-H
| name = S905
| image = File:Amlogic-s905.webp
| image = File:Amlogic_S905.png
| imagecaption = Amlogic S905
| imagecaption = Amlogic S905
| manufacturer = Amlogic
| manufacturer = Amlogic
| codenames=GXBB
| arch = aarch64
| arch = aarch64
| year = 2015
| year = 2015
Line 30: Line 31:
}}
}}
The Amlogic S905, also known as Meson GXBB, is a fairly capable high-end media player SoC mainly used in Android set-top boxes.
The Amlogic S905, also known as Meson GXBB, is a fairly capable high-end media player SoC mainly used in Android set-top boxes.
It's capable of hardware decoding up to 4K@60fps, for multiple formats including H.264, AVS+, and 10-bit, and part of the  
It's the first 64-bit Amlogic SoC, and
S9 family of Amlogic chipsets. It has great U-Boot and mainline Linux support, making it a great candidate for building a  
is capable of hardware decoding up to 4K@60fps, for multiple formats including H.264, AVS+, and 10-bit. It's part of the  
GXBB family of Amlogic SoCs. It has great U-Boot and mainline Linux support, making it a great candidate for building a  
set-top box or single-board computer powered by postmarketOS.
set-top box or single-board computer powered by postmarketOS.
There's also the Amlogic S905-H SoC, which merely just includes Dolby licenses.


== Devices ==
== Devices ==
Line 54: Line 54:
* On an SD card: offset 512 (512 bytes completly ignored by BL1), header and checksum from offset 528 to 623, payload at offset 4608 onwards
* On an SD card: offset 512 (512 bytes completly ignored by BL1), header and checksum from offset 528 to 623, payload at offset 4608 onwards
* On eMMC: offset 0, header and checksum from offset 16 to 111, payload at offset 4096 onwards
* On eMMC: offset 0, header and checksum from offset 16 to 111, payload at offset 4096 onwards
The header roughly looks like this:
<source lang=c>
/*
* Hex dump:
* 00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
* 00000010: 4041 4d4c f0bf 0000 4000 0100 0000 0000  @AML....@.......
* 00000020: 0000 0000 4000 0000 0002 0000 6000 0000  ....@.......`...
* 00000030: 0000 0000 4002 0000 b00d 0000 90bf 0000  ....@...........
* 00000040: 0000 0000 f00f 0000 00b0 0000 0000 0000  ................
* 00000050: efe0 c669 d471 d507 27c2 9e5d d0ec 1b2b  ...i.q..'..]...+
* 00000060: 1cdd f482 9acd 3606 ef35 301a ac48 0d7d  ......6..50..H.}
*/
/*
* C struct
*/
struct aml_hdr {
    /* before magic word: random bytes ignored by BL1 */
uint32_t magic; /* "@AML" */
uint32_t total_size;
uint8_t header_size;
uint8_t root_key_index;
uint8_t version_major;
uint8_t version_minor;
uint32_t padding1;
uint32_t digest_type;
uint32_t digest_offset;
uint32_t digest_size;
uint32_t data_offset;
uint32_t key_type;
uint32_t key_offset;
uint32_t key_size;
uint32_t data_size;
uint32_t payload_type;
uint32_t payload_offset;
uint32_t payload_size;
uint32_t padding2;
} __packed;
</source>


There's a bug where, because of the zero-offset requirement on eMMC, MBR structures cannot coexist, requiring tweaks to  
There's a bug where, because of the zero-offset requirement on eMMC, MBR structures cannot coexist, requiring tweaks to  
Line 100: Line 59:


BL2 is signed by using a proprietary utility from Amlogic called <code>aml_encrypt_gxb</code>, for example:
BL2 is signed by using a proprietary utility from Amlogic called <code>aml_encrypt_gxb</code>, for example:
<source lang=shell-session>
<syntaxhighlight lang="shell-session">
$ aml_encrypt_gxb --bootsig --input boot_new.bin --output u-boot.img
$ aml_encrypt_gxb --bootsig --input boot_new.bin --output u-boot.img
</source>
</syntaxhighlight>


There's a replacement for <code>aml_encrypt_gxb</code> called <code>amlbootsig</code>. See https://github.com/afaerber/meson-tools. For example, one could use:
There's a replacement for <code>aml_encrypt_gxb</code> called <code>amlbootsig</code>. See https://github.com/afaerber/meson-tools. For example, one could use:
<source lang=shell-session>
<syntaxhighlight lang="shell-session">
$ amlbootsig boot_new.bin u-boot.img
$ amlbootsig boot_new.bin u-boot.img
</source>
</syntaxhighlight>
It has been confirmed to work on ODROID-C2 and [[Videostrong KII Pro (videostrong-kii-pro)]].
It has been confirmed to work on ODROID-C2 and [[Videostrong KII Pro (videostrong-kii-pro)]].


Then BL2 loads the following:
* BL30/SCP_BL2: System control processor firmware
* BL31: EL3 Runtime Software
* BL32: OPTEE (optional)
* BL33: U-Boot
All bootloader stages except U-Boot are proprietary. BL31 can be replaced with upstream [https://github.com/ARM-software/arm-trusted-firmware Arm Trusted Firmware-A].
There's also an ongoing effort led by [[User:FerassElHafidi]] to [https://moin.vitali64.duckdns.org/AmlogicBL2 reverse-engineer BL2 and port U-Boot SPL].


== Status ==
== Status ==
Line 120: Line 88:


=== Audio ===
=== Audio ===
Works. Requires a device tree patch on the [[Videostrong KII Pro (videostrong-kii-pro)]], that adds the appropriate nodes (else the card is never pobed) which is slowly making its way upstream. HDMI audio works, but S/PDIF is untested.
HDMI audio works, but S/PDIF is untested. Needs a UCM config.
 
=== X11 ===
Works fine. A custom configuration file is needed else it crashes (included).
 
=== HDMI-CEC ===
Sort of works. The TV detects a CEC device, but you cannot use the TV's remote to control the set-top box (at least, on Plasma Bigscreen).
Seems like <code>libcec</code> does detect which button in the remote is pressed.


=== Hardware decoding and encoding ===
=== Hardware decoding and encoding ===
Line 129: Line 104:
kernel (to their defense Amlogic did successfully enable 4K playback on 3.x kernels).
kernel (to their defense Amlogic did successfully enable 4K playback on 3.x kernels).


To get hardware encoding to work, refer to [https://gitlab.com/postmarketOS/pmaports/-/merge_requests/4071?commit_id=1904830a206a2e886b547cfd9f7fdde61221c52f#note_1386135438 this issue comment]. It boils down to:
To get hardware encoding to work, refer to [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/4071?commit_id=1904830a206a2e886b547cfd9f7fdde61221c52f#note_1386135438 this issue comment]. It boils down to:
* Making sure CONFIG_VIDEO_MESON_VDEC is set: <code>zcat /proc/config.gz | grep CONFIG_VIDEO_MESON_VDEC</code> (See {{MR|4071|pmaports}})
* Making sure CONFIG_VIDEO_MESON_VDEC is set: <code>zcat /proc/config.gz | grep CONFIG_VIDEO_MESON_VDEC</code> (See {{MR|4071|pmaports}})
* Build FFmpeg from https://github.com/jc-kynesim/rpi-ffmpeg/commits/dev/4.4/rpi_import_1
* Build FFmpeg from https://github.com/jc-kynesim/rpi-ffmpeg/commits/dev/4.4/rpi_import_1
Line 143: Line 118:


=== Suspend ===
=== Suspend ===
{{Note|Does the S905(-H) have the ability to sleep?}}
Broken


=== DVB ===
=== DVB ===
Line 152: Line 127:


=== U-Boot ===
=== U-Boot ===
Most (all?) set-top boxes based on this SoC use U-Boot as their primary bootloader, but mainline U-Boot has great support for this  
All set-top boxes based on this SoC use U-Boot as their primary bootloader, but mainline U-Boot has great support for this  
SoC. Running mainline U-Boot as the primary bootloader and as the secondary bootloader works fine. If you want to use U-Boot as the  
SoC. Running mainline U-Boot as the primary bootloader and as the secondary bootloader works fine. If you want to use U-Boot as the  
primary bootloader, refer to [[Videostrong KII Pro (videostrong-kii-pro)/U-Boot as primary bootloader]], replacing mentions of <code>wetek-play2</code>
primary bootloader, refer to [[Videostrong KII Pro (videostrong-kii-pro)/U-Boot as primary bootloader]], replacing mentions of <code>wetek-play2</code>
with your device or one close enough (which have RAM timings that work on your device). Please note that BL2 and BL30 are proprietary; there's an on-going  
with your device or one close enough (which have RAM timings that work on your device). Please note that BL2 and BL30 are proprietary; there's an on-going  
effort on porting mainline Arm Trusted Firmware-A to [[Videostrong KII Pro (videostrong-kii-pro)]].
effort on reverse-engineering BL2 on [[Videostrong KII Pro (videostrong-kii-pro)]] and other devices.


== See also ==
== See also ==
Line 162: Line 137:
* [[Amlogic]]
* [[Amlogic]]
* [[Amlogic/Porting_set_top_boxes|Port STBs to postmarketOS]]
* [[Amlogic/Porting_set_top_boxes|Port STBs to postmarketOS]]
* [https://git.vitali64.duckdns.org/misc/trustedfirmware-a.git/ Bare-bones WIP BL2 port (DON'T USE IT IF YOU'RE A REGULAR USER)]
* [https://git.vitali64.duckdns.org/misc/u-boot-kii-pro.git/log/?h=wip/spl WIP U-Boot SPL port (DON'T USE IT IF YOU'RE A REGULAR USER)]
* [https://moin.vitali64.duckdns.org/AmlogicBL2 Reverse-engineering notes on BL2]
* [https://github.com/hardkernel/u-boot/tree/be63a06fa3d50dd2410e2e722d1f8bafe7370abd/arch/arm/cpu/armv8/common/firmware Old BL2 sources from before Amlogic made it proprietary (based on TF-A code)]
* [https://github.com/hardkernel/u-boot/tree/be63a06fa3d50dd2410e2e722d1f8bafe7370abd/arch/arm/cpu/armv8/common/firmware Old BL2 sources from before Amlogic made it proprietary (based on TF-A code)]
** [https://git.vitali64.duckdns.org/archive/amlogic-bl2.git/ Mirror]
** [https://git.vitali64.duckdns.org/archive/amlogic-bl2.git/ Mirror]

Latest revision as of 12:25, 29 January 2025

Amlogic S905
Amlogic S905
Amlogic S905
Manufacturer Amlogic
Name S905
Codenames GXBB
Architecture aarch64
CPU 4x 2 GHz Cortex-A53
GPU Mali-450
Year 2015
Process 28nm
Mainline yes
Community Page https://linux-meson.com/
Components
CPU
Works
UART
Works
Storage
Partial
USB
Works
Display
Works
GPU
Works
Pinctrl
Works
I²C
Works
SPI
No data
Audio
Works
Video
Partial
Thermal
Works
NPU
No data
Suspend
Broken
Ethernet
No data
SATA
No data

The Amlogic S905, also known as Meson GXBB, is a fairly capable high-end media player SoC mainly used in Android set-top boxes. It's the first 64-bit Amlogic SoC, and is capable of hardware decoding up to 4K@60fps, for multiple formats including H.264, AVS+, and 10-bit. It's part of the GXBB family of Amlogic SoCs. It has great U-Boot and mainline Linux support, making it a great candidate for building a set-top box or single-board computer powered by postmarketOS.

Devices

Device Codename Chipset Mainline booting
Videostrong KII Pro videostrong-kii-pro Amlogic S905 Y Yes

Boot process

See: Amlogic#Boot process

BL1 looks for a header (named @AML header) at different offsets depending on the storage media:

  • On an SD card: offset 512 (512 bytes completly ignored by BL1), header and checksum from offset 528 to 623, payload at offset 4608 onwards
  • On eMMC: offset 0, header and checksum from offset 16 to 111, payload at offset 4096 onwards

There's a bug where, because of the zero-offset requirement on eMMC, MBR structures cannot coexist, requiring tweaks to allow an MBR parition table to coexist. Further reading: https://github.com/LibreELEC/amlogic-boot-fip/pull/8

BL2 is signed by using a proprietary utility from Amlogic called aml_encrypt_gxb, for example:

$ aml_encrypt_gxb --bootsig --input boot_new.bin --output u-boot.img

There's a replacement for aml_encrypt_gxb called amlbootsig. See https://github.com/afaerber/meson-tools. For example, one could use:

$ amlbootsig boot_new.bin u-boot.img

It has been confirmed to work on ODROID-C2 and Videostrong KII Pro (videostrong-kii-pro).

Then BL2 loads the following:

  • BL30/SCP_BL2: System control processor firmware
  • BL31: EL3 Runtime Software
  • BL32: OPTEE (optional)
  • BL33: U-Boot

All bootloader stages except U-Boot are proprietary. BL31 can be replaced with upstream Arm Trusted Firmware-A. There's also an ongoing effort led by User:FerassElHafidi to reverse-engineer BL2 and port U-Boot SPL.

Status

GPU and hardware acceleration

Works. Lima is used for hardware acceleration.

IR RX

Works. Aftermarket and original IR remotes are expected to work out of the box (as seen on Videostrong KII Pro (videostrong-kii-pro)). Doesn't require much configuration.

Audio

HDMI audio works, but S/PDIF is untested. Needs a UCM config.

X11

Works fine. A custom configuration file is needed else it crashes (included).

HDMI-CEC

Sort of works. The TV detects a CEC device, but you cannot use the TV's remote to control the set-top box (at least, on Plasma Bigscreen). Seems like libcec does detect which button in the remote is pressed.

Hardware decoding and encoding

See: https://libera.irclog.whitequark.org/linux-amlogic/2023-02-10

The Amlogic S905(-H) supports hardware decoding up to 4K@60fps, but in the mainline kernel it's limited to 1080p. Downstream kernels relied on lengthy hacks to get it working up to 4K, and thus they were not included in the mainline kernel (to their defense Amlogic did successfully enable 4K playback on 3.x kernels).

To get hardware encoding to work, refer to this issue comment. It boils down to:

There are some issues, however:

  • Needs non-free firmware
  • 10-bit media (e.g. 4K) won't work
  • MPEG1/2/4 support is broken

So sometimes you may want to resort to using software decoding.

Hardware encoding doesn't work yet.

Suspend

Broken

DVB

Needs a demux driver.

OTG

Untested. Broken according to linux-meson.com

U-Boot

All set-top boxes based on this SoC use U-Boot as their primary bootloader, but mainline U-Boot has great support for this SoC. Running mainline U-Boot as the primary bootloader and as the secondary bootloader works fine. If you want to use U-Boot as the primary bootloader, refer to Videostrong KII Pro (videostrong-kii-pro)/U-Boot as primary bootloader, replacing mentions of wetek-play2 with your device or one close enough (which have RAM timings that work on your device). Please note that BL2 and BL30 are proprietary; there's an on-going effort on reverse-engineering BL2 on Videostrong KII Pro (videostrong-kii-pro) and other devices.

See also