The article describes in detail, with the source code, the work carried out to transfer and launch the firmware from the SD card with the Android OS for devices based on the Amlogic S912 processor.
I love system-on-a-chip (SOC) miniature computers. For its tiny size and low power consumption compared to personal computers. Using such devices, you can solve a wide range of tasks. On minicomputers, you can install both the Android OS (as most manufacturers of these "toys" do), and various Linux or Chrome OS distributions.
My current job is developing applications for Android. In this work, tests on real devices on various versions of the system are highly desirable. I have a couple of minicomputers from Rockchip and Amlogic that I also run my tests on. Android, as an operating system, is developing rather dynamically and now its modifications from 4.4 to 10 versions are used on the market. And on the way is already Android version 11.
Many companies engaged in the development of set-top boxes based on Android have to have a short period of support for their offspring due to the rapid development of both hardware and software. One of my main working tools for tests is a KM8P box on an S912 processor with two gigabytes of RAM and a pre-installed Android 7.1 operating system. Time passes, and for a couple of years, versions 8.1, 9.0 and 10.0 of Android OS have appeared on the market.
I would very much like to test my application under these same versions. But what to do? Either you need to buy animals on new processors and versions of Android, or self-adapt new versions of Android on existing devices. The first way is easy and simple: by paying a small amount, the problem is easily solved. But we are not looking for easy ways, so we choose the second way. The second way is much more difficult, but more interesting. In addition, the S912 chip itself is an excellent 8-core processor, not much inferior in performance to the latest Amlogic processors on the S905x chip.
, , . : ? 7.1 Linux 3.14.29 NAND SK Hynix H27UCG8T2ETR, Amlogic aml_nftl_dev.ko.
4.9. . , Amlogic , SDK Android , Amlogic.
, github' 4.9 SDK Android Amlogic 2017-18 . , git- Khadas. , , , aml_nftl_dev 4.9 . ? 4.9? , . .
S912 EMMC. , ( - 2020 ) 9, ( ). EMMC. , , SD-, MMC, EMMC, SD- .
, , Amlogic SD-. , - . Amlogic SD-. Amlogic u-boot . , FAT- SD-. , , MMC SD-. .
, , -, EMMC, . SDMMC- SDIO-. , SDMMC, , EMMC?
-, , Amlogic . , , , . , .
, SDMMC, EMMC SD-, , , EMMC SD-! , , . — . , , . github', amlpt. Ubuntu. , , , Windows.
mmcparts_a9.c, , , . — 0x1, cache — 0x2, data — 0x4. 0x2800000 (40). , partitions . 9- 17.
mmcparts_a9.c, , make_amlptwrt.sh. amlptwrt, mmc_parts.bin. , MMC. make_amlptrdr.sh amlptrdr, . amlptrdr , . :
@>:~/AML/amlpt$ ./amlptrdr
[mmc_verify_partition_tbl] mmc read partition OK!
show_mmc_partitions
[disk p01] logo offset 40 Mb, size 8 Mb
[disk p02] recovery offset 48 Mb, size 24 Mb
[disk p03] misc offset 72 Mb, size 8 Mb
[disk p04] dtbo offset 80 Mb, size 8 Mb
[disk p05] cri_data offset 88 Mb, size 8 Mb
[disk p06] rsv offset 96 Mb, size 16 Mb
[disk p07] metadata offset 112 Mb, size 16 Mb
[disk p08] vbmeta offset 128 Mb, size 2 Mb
[disk p09] param offset 130 Mb, size 16 Mb
[disk p10] boot offset 146 Mb, size 16 Mb
[disk p11] tee offset 162 Mb, size 32 Mb
[disk p12] vendor offset 194 Mb, size 130 Mb
[disk p13] odm offset 324 Mb, size 128 Mb
[disk p14] system offset 452 Mb, size 1350 Mb
[disk p15] product offset 1802 Mb, size 128 Mb
[disk p16] cache offset 1930 Mb, size 1120 Mb
[disk p17] data offset 3050 Mb, size 4050 Mb
, MMC SDMMC, , drivers/amlogic/mmc/emmc_partitions.c:
) -, , EMMC. is_card_emmc :
static int is_card_emmc(struct mmc_card *card)
{
//struct mmc_host *mmc = card->host;
// emmc port, so it must be an eMMC or TSD
//if (!strcmp(mmc_hostname(mmc), "emmc"))
return 1;
//else
// return 0;
//return mmc->is_emmc_port;
}
, , , . , - .
) , . mmc_read_partition_tbl:
//start_blk = get_reserve_partition_off(card);
start_blk = MMC_BOOT_PARTITION_SIZE + MMC_BOOT_PARTITION_RESERVED;
, MMC_BOOT_PARTITION_SIZE + MMC_BOOT_PARTITION_RESERVED 36 . , , EMMC . .
, , SD- 36 . , , amlptwrt, SD- :
// 36M = 37748736 bytes = 73728 sectors
sudo dd if=mmc_parts.bin of=/dev/sdb seek=73728 bs=512
, /dev/sdb — SD-.
, boot.img initrd :
root=/dev/mmcblk0p14 rootfstype=ext4 rootwait
, u-boot Amlogic Linux c SD- FAT. SD- FAT 32 . boot.img dtb.img. dtb.img EMMC, SD- /dev/mmcblk0. , boot.img , , /dev/mmcblk0p14.
, , - SD-. SD- :
// logo
sudo dd if=logo.PARTITION of=/dev/sdb bs=1M seek=40 conv=sync,fsync status=progress
// recovery
sudo dd if=recovery.PARTITION of=/dev/sdb bs=1M seek=48 conv=sync,fsync status=progress
// misc
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=72 count=8 conv=sync,fsync status=progress
// dtbo
sudo dd if=dtbo.PARTITION of=/dev/sdb bs=1M seek=80 conv=sync,fsync status=progress
// cri_data
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=88 count=8 conv=sync,fsync status=progress
// rsv
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=96 count=16 conv=sync,fsync status=progress
// metadata
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=112 count=16 conv=sync,fsync status=progress
// vbmeta
sudo dd if=vbmeta.PARTITION of=/dev/sdb bs=1M seek=128 conv=sync,fsync status=progress
// param
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=130 count=16 conv=sync,fsync status=progress
// boot
sudo dd if=boot.PARTITION of=/dev/sdb bs=1M seek=146 conv=sync,fsync status=progress
// tee
sudo dd if=/dev/zero of=/dev/sdb bs=1M seek=162 count=32 conv=sync,fsync status=progress
// vendor
sudo dd if=vendor.img of=/dev/sdb bs=1M seek=194 conv=sync,fsync status=progress
// odm
sudo dd if=odm.img of=/dev/sdb bs=1M seek=324 conv=sync,fsync status=progress
// system
sudo dd if=system.img of=/dev/sdb bs=1M seek=452 conv=sync,fsync status=progress
// product
sudo dd if=product.img of=/dev/sdb bs=1M seek=1802 conv=sync,fsync status=progress
, , . , system vendor , sparse-. :
simg2img system.PARTITION system.img
cache data -. , amlptwrt, fdisk SD- ext4:
sudo mkfs.ext4 /dev/sdb2
sudo mkfs.ext4 /dev/sdb3
, fdisk, /dev/sdb2 /dev/sdb3.
u-boot , SD-, FAT- aml_autoscript. aml_autoscript mkimage :
if mmcinfo; then fatload mmc 0 ${loadaddr} boot.img; fatload mmc 0 ${dtb_mem_addr} dtb.img; bootm; fi;
That's all it takes to transfer firmware from Android on board to SD card.
Several firmwares that were made using this method were published in the corresponding topic on the w3bsit3-dns.com forum. If something is not clear, ask questions in the comments. What I can - I will help.
For this, let me take my leave and good luck to everyone in transferring the firmware!