Posts by permheaddamage

    I got a hint from apritzel of adding earlycon to bootargs.

    Now I get this output:

    I called disable_nonboot_cpus() in stock kernel to shutdown all other core before jumping into new uboot.

    ATF has reserved 16M secure memory at 0x48000000~0x49000000 which is not accessible by EL1. For convenience I configured CFG_SYS_SDRAM_BASE 0x80000000 and memory size 1GB. I also add /memreserve/ in dts file to leave this hole alone.

    permheaddamage as I said, secure boot is totally out of my league, but there are people on IRC (#linux-sunxi at OFTC) who researched it and are probably able to help you.

    Thanks Jernej,

    After I enabled CONFIG_POSITION_INDEPENDENT in uboot config and added a function to disable icache/mmu:

    Code
    ENTRY(save_boot_params)
        mrs    x0, sctlr_el1
        bic    x0, x0, #1 << 2       // clear SCTLR.C
        bic    x0, x0, #1            // clear mmu
        msr    sctlr_el1, x0
        isb
        b    save_boot_params_ret    /* back to my caller */
    ENDPROC(save_boot_params)

    I am able to boot this modified LE uboot. It has some problem to get information from the incompatible sunxi SPL.

    At least it can load the kernel file from sd card and boot it. But it stopped at that "Starting Kernel". Now it's time to see what's wrong with Kernel.

    Basicall I am using the stock firmware as a giant bootloader.. Now the sequence is:

    BL31: Stock SPL(zidoo signed)

    BL33: Stock Uboot(zidoo signed)

    Stock Kernel(zidoo signed), Now it's like BL34?

    LE Uboot(non secure), maybe BL35...

    LE Kernel(non secure)

    all right, at least the uart0 helloworld bin works

    sunxi-tools/uart0-helloworld-sdboot.c at master · linux-sunxi/sunxi-tools
    A collection of command line tools for ARM devices with Allwinner SoCs. - sunxi-tools/uart0-helloworld-sdboot.c at master · linux-sunxi/sunxi-tools
    github.com

    So at least I can make this ko load vmlinux into multiple pages of physical memory, then make a bootloader to assemble those page to 0x40008000...

    But first I will see whether I can make it jump to mainline uboot. (NOPE, mainline uboot is designed to start from EL3, but now I only have EL1)

    Update: I am able to use a ko to trigger EL3 firmware's boot from another address.

    This is my code:

    invoke_smc_fn is defined at:

    It sends an interrupt to EL3 and make the handler erase EL1 state and boot a new EL1 system.

    EL3 Handler is at:

    H6-BSP4.9-brandy/arm-trusted-firmware-1.0/services/arm/arm_svc_setup.c at ceec41bced9047a61df5caa6322376dd278aac6f · Allwinner-Homlet/H6-BSP4.9-brandy
    beta version, not final release. Contribute to Allwinner-Homlet/H6-BSP4.9-brandy development by creating an account on GitHub.
    github.com

    I use the LE u-boot-spl.bin as boot image, but it seems not working..

    Do not know whether it is wrong image format or wrong memory operation. Perhaps spl is built non-relocatable and must be put to a fixed address to start?

    Or I should try vmlinux binary directly? vmlinux is so big, I must find a contigus 22mb memory in physical memory.. kernel virtual address is killing me...

    After a lot of reading on Allwinner's secure boot documents and source code, I find something interesting:


    1. An old thread

    H3-Soc boot rom security & E-Fuse
    Hi, I bought nanopi_neo boards (for my hobby projects). I am learning about security. I am able to dump e-Fuse area at uboot stage. But i can't modify it (i…
    forum.armbian.com

    Spitfire says after he flashes all 0xff to H3's rotpk efuse, it boots. Efuse is OTP, I can not revert my efuse to 0, but I should be able to flash it again to all 0xff. Hope it also works for H6.

    2. There is a kernel driver sunxi-sysinfo in the 3.10 kernel source code which matches my board:

    https://gitee.com/nnxr/H6-BSP3.1…r/sunxi-sysinfo
    This driver exposes a file device /dev/sunxi_soc_info and 2 chararcter classes /sys/class/sys_info + /sys/class/key_info

    I tested on my board, all 3 works fine. I can get all information it is designed to give. Write function is not exposed.

    This driver uses standard arm instruction "smc #0" to switch from EL1(Kernel) to EL3(TEE).

    3. I find a EL3 smc handler source code of Allwinner
    https://github.com/Allwinner-Homl…vc_setup.c#L221

    If my board's EL3 firmware is compiled from this source code, that means I should be able to invoke smc command ARM_SVC_EFUSE_WRITE to write efuse.

    4. My board does not check Kmod's signature. So I can modify this sunxi-sysinfo driver, add some new API to invoke a smc call to write all 0xff to rotpk, compile and insmod to run it..

    5. If I succeeded, stock fw would be dead because sunxi spl only ignores rotpk if it is all 0 when it switches to uboot:

    https://github.com/Allwinner-Homl…rom_main.c#L591
    Mainline uboot-with-spl should be OK because it uses other security design.

    Of course if the chip planted sbrom is doing the same thing as this spl sbrom, the board would be a brick..

    Hi, usually the e-fuse is OTP type ("Electrical Fuse, A one-time programmable memory"), can be write only once. I don't have the documentation of that Allwinner SOC, is not impossible to be in this case is something different, but usually this is the way how the e-fuse works.

    Tried it. I am not able to access SID in Linux even when I am root. devmem always return 0 for the registers.

    Guess this is expected because OPTEE is designed to act like this..

    There is a key file in root folder but it is a public key and purpose is unknown.

    Code
    petrel-p1:/ $ cat /rsa.pk
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnmf9BzIu+lpk5Kmo3yzh
    ZuGGP1pBRmZS1112Q2nEESsdcLlXGKNcAdbWsH+ZAKSXnDecUFJ+kuPvnXUsWNev
    QT7vuxEgxBX20wch+CL66RTzMSgtqWy6eO79y2uMVrmv4Kz0tSpzTZs8tVfRvKp4
    3wpiofNMxzYjj3X3hWPfSoFpKKWZepbyutla1lveySwhey2Xv6aB7PSXg5xKXGsp
    AhE+fuUvBqCfUiit84AGbno5B/oYtgm0/R/7viOeQoooIpBJO3IqRxM1HqVrPepK
    OFxA99iybTmJkqatWm8na7ZqTz6/vLYVHVLMNl8/b88KOeLPyVIt3qeM9m7TU8IS
    nQIDAQAB
    -----END PUBLIC KEY-----

    Last try:

    Built a beelink gs1 image with one line "CONFIG_SPL_IMAGE_TYPE_SUNXI_TOC0=y" attached to uboot config:

    LibreELEC.tv/projects/Allwinner/bootloader/config at master · LibreELEC/LibreELEC.tv
    Just enough OS for KODI. Contribute to LibreELEC/LibreELEC.tv development by creating an account on GitHub.
    github.com

    Plus a patch file to make the TOC0 key item has the same vendor id I extracted from stock fw upgrade tf card.

    Diff
    --- /tools/sunxi_toc0.c    2023-06-26 13:28:52.150080327 +0000
    +++ /tools/sunxi_toc0.c    2023-06-26 13:28:25.507170419 +0000
    @@ -207,6 +207,7 @@
                     RSA *root_key, RSA *fw_key)
     {
         struct toc0_key_item *key_item = (void *)buf;
    +    key_item->vendor_id = 0x00EFE800;
         uint8_t digest[SHA256_DIGEST_LENGTH];
         int ret = EXIT_FAILURE;
         unsigned int sig_len;

    During building it asks for a private key file

    build.LibreELEC-H6.arm-11.0-devel/build/u-boot-2022.10/root_key.pem

    I have to manually generate a RSA key and hope Zidoo left public key empty in efuse.

    The generated image is correctly packed with TOC0 header, and makes the board go into FEL mode...

    So this is a secured board and I give up. Damn.. :cry:

    Thank you jernej

    What I find today:

    1. sunxi-fel can get this information by "version" command:

    AWUSBFEX soc=00001728(H6) 00000001 ver=0001 44 08 scratchpad=00027e00 00000000 00000000

    "version" command only works once after power on, then board is dead and do not accept any next command. Replug usb will get error saying device is not reporting its id.

    Any other command will put it into same state even when 1st time I run it. Wondering whether this is because I am using windows 11.

    2. Stock firmware TF card has TOC0 header uboot. I built a H6 LE 11.0.1 image and find the u-boot-sunxi-with-spl.bin in build folder(It seems to be tanix tx6 bin because it is compiled last and has overwritten all previous ones). I tried to convert it to TOC0 header using scripts at:

    TOC0 - linux-sunxi.org

    With this Sd card, it stopped booting from emmc and went into fel mode...

    Does this mean zidoo has enabled secure boot in efuse and it is not worthy to dig deeper...

    There is a usb2.0 type a port marked by "USB/OTG" on the box shell.

    By pressing “2” in serial console or pressing the hardware button on the board next to flash chip while power on, it can enter the fel mode.

    With a usb a-c cable to my computer, Windows device manager shows an unknown device "USB\VID_1F3A&PID_EFE8&REV_02;3"

    Studying how to install sunxi-tools to windows..

    maybe I can use my nanopc-t4 with armbian to run sunxi-tools

    It turns out Zidoo changed design in 2018...

    Those 2017 pictures are with DDR4 ram, but my "China Version" has DDR3 ram, exactly same chip as Beelink GS1.

    UART is already popped out so I saved some soldering work. BTW, TX/RX are actually reversed.

    This is the uart log:

    Insert LE tf card will get me same uart output and still boot into Android on internal emmc at /dev/block/mmcblk0.

    The LE card is recognized by the stock firmware at /dev/block/mmcblk1. It is not mounted in the console display printed by "df -h", but can be seen in Android file manager.

    I am going to create a card with phoenixcard and see what's the magic there..


    stock firmware image tf card written by phoenixcard will get this boot message:

    It gives "sdc0 spd mode error, 2", then turn to boot from mmc0(tf card) instead of mmc2(emmc).

    @jernej Any clue?

    Thanks Jernej, I see your post of TX6.

    Since Tanix TX6 can boot from the SD card
    Tanix TX6 is H6 based Android TV Box and it can boot from SD cards prepared with PhoenixCard. It should be possible to make it work with Armbian too, right? I…
    forum.armbian.com

    I think maybe I am facing the same problem. Zidoo H6 is equipped with DDR4 RAM.

    I will have a try to see whether these 4 pads are uart pins when I have time. It looks there is no other test points possible to be uart on this board.

    Here is picture of circuit board:

    ZIDOO H6 PRO Android 7.0 Allwinner H6 2/16GB AC WiFi Gig Lan BT4 L1 Widevine
    Today something new and little different ZIDOO H6 PRO Android 7.0 Allwinner H6 2/16GB AC WiFi Gig Lan BT4 Has been a long while since we have had a Allwinner…
    forum.xda-developers.com

    The stock firmware update guide indicates it is able to boot from tf card.

    https://www.zidoo.tv/Support/support_guide/guide_target/JT4n%2Bv0V3qHeq7k9e%5Bld%5D3ulg%3D%3D.html

    Zidoo h6 is probably the first allwinner h6 tv box on market. Zidoo abandoned it just half a year later and left many blocking issues in the stock firmware.

    HW is: Allwinner H6 soc, 2gb ram, 16gb emmc, axp805 pmic, ap6255 wifi+bt, rtl8211e gigalan

    Product link: https://www.zidoo.tv/Product/spec/m…FMcQ%3D%3D.html

    Latest stock firmware: http://forum.zidoo.tv/index.php?thre…-release.45219/

    The HW spec looks very much like Beelink GS1, except for the wifi chip.