Ruka-CFW / rk3128-cfw

*** DEPRECATED - DON'T USE *** Rockchip RK3128 Custom Firmware for Powkiddy A12/A13 & AIWO retro-consoles
Other
44 stars 14 forks source link

PS5000 factory updated -> rockchip uboot + 4.4 rockchip kernel opensource rebuild #51

Open mcerveny opened 3 years ago

mcerveny commented 3 years ago

Hello.

Update script ruka_install_ps5000.sh (ruka_cfw_3.0_beta_1_20210806.tgz) partition table does not match for userdata_ps5000_20210806.img partition (offset 0x00028800). I received updated version with different LBA offset 0x0002b000 !

$ ### different partition start (userdata) from "upgrade_tool"
$ sudo ./upgrade_tool 

...

Rockusb>pl
Partition Info(gpt):
NO  LBA        Size       Name
01  0x00002000 0x00000800 uboot
02  0x00002800 0x00001000 trust
03  0x00003800 0x00004800 boot
04  0x00008000 0x00023000 rootfs
05  0x0002b000 0x0000addf userdata

$ ### different verified from boot (serial console), factory build "Jul 8 10:53:53 CST 2021" !
$ cu -l /dev/ttyUSB0 -s 115200 -f

...

U-Boot 2017.09-gf468676-dirty (Jul 08 2021 - 10:53:40 +0800)

...

[root@root:/]# echo p | fdisk /dev/rkflash0 
Found valid GPT with protective MBR; using GPT

Command (m for help): Disk /dev/rkflash0: 220672 sectors,  107M
Logical sector size: 512
Disk identifier (GUID): 9c220000-0000-4e3b-8000-557800002e7b
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 220638

Number  Start (sector)    End (sector)  Size Name
     1            8192           10239 1024K uboot
     2           10240           14335 2048K trust
     3           14336           32767 9216K boot
     4           32768          176127 70.0M rootfs
     5          176128          220638 21.7M userdata

Command (m for help): [root@root:/]# 
[root@root:/]# uname -a
Linux root 4.4.159 #1047 SMP Thu Jul 8 10:53:53 CST 2021 armv7l GNU/Linux
[root@root:/]# cat /etc/os-release 
NAME=Buildroot
VERSION=2018.02-rc3-00808-gc9c3b18-dirty
ID=buildroot
VERSION_ID=2018.02-rc3
PRETTY_NAME="Buildroot 2018.02-rc3"
acmeplus commented 3 years ago

Thanks, that confirms what we observed from another users that there are at least two different PS5000 revisions. We need to find an easy way to identify which model is which before the flash takes place. Most likely by running a PL command with android tools to check the memory address of each partition.

Also, some users with that RevB model (the one with user data at 0x0002b000) that flashed the userdata with our install script seem to have a corrupted userdata partition that does not flash cleanly. While that can be easily solved at Linux level, it’s not so clear how to automate the recovery of the corrupted partition via command line on windows. It seems it may require the users to run rkdevtool or a similar rock chip tool.

mcerveny commented 3 years ago

More questions: Updated PS5000 uses (unknown) kernel 4.4.159 (I tested, that works with your rootfs image - rootfs_ps5000_20210806.img). I tried to use this buildroot repo, but I have two problems: 1) where are the sources to your modified kernel - configs/ps5000_defconfig: BR2_LINUX_KERNEL_CUSTOM_REPO_URL="file://$(TOPDIR)/../kernel" (including dts/dtsi to enable serial console in your dtb) ? 2) where are the scripts to compose boot_ps5000_20210806.img ? 3) where are the scripts to split/build userdata_ps5000_20210806.img and sdcard/* ?

acmeplus commented 3 years ago

For the kernel you only need the standard Linux kernel sources for 4.4.159. Just uncompress and create a symbolic link named kernel (one level above buildroot).

The boot is just a reconstituted boot from a dump of the internal firmware. It just includes the kernel image and the associated dtd’s. We will document how to do it in the future but it’s not relevant for this device.

The userdata does not need to contain anything other than a run and system folder. Run is mount binded to the chroot system upon boot. This is needed to obtain read/write permissions for udev population. System is basically a link to /mnt/sdcard so the default home is set to /userdata/system. We have not documented this but will do in the future. There are no scripts to roll do this currently but it’s just two folders to be added to an otherwise empty partition.

mcerveny commented 3 years ago

standard Linux kernel sources for 4.4.159

Nope. Standard Linux sources does not contain drivers "mali", "rkflash", "hevc_service", "vpu_service" ... Only https://github.com/rockchip-linux/kernel (synchronized to 4.4.194 now) and other forks. So if you distribute kernel binaries you should also disclosure your equivalent kernel sources. Do you known to HW/SW author (maybe somewhere https://github.com/rockchip-linux/kernel/network/members ) ?

acmeplus commented 3 years ago

Yes and no. For the kernel link that you need to build just rootfs you don’t need the modified kernel sources with rockchip specific patches.

However, you are correct that to get those rockchip specific kernel modifications you need to compile the kernel you need those modified sources from rockchip Linux, same repo as you point out (https://github.com/rockchip-linux/kernel). Our rootfs only requires a loop module to be compiled from the kernel, and that’s a general Linux module that does not require any of the rockchip modifications.

Same applies to rkscript, Linux-rga, Mali (specific rockchip flavor), etc. You can find a more up to date repo of all those in the Caesar Wang repo (https://github.com/Caesar-github), he’s one of the main rockchip contributors. The origin of the buildroot that we use comes from a blend between Caesars buildroot modifications to the main rockchip Linux buildroot, plus additional modifications based on batocera.Linux buildroot.

In any case, our current goal is to document everything, but time is limited. You are welcomed to create any pull requests and contribute to the project.

mcerveny commented 3 years ago

Please simply clarify (ps5000 is WX8 board):

Very thanks, Martin

alpgarcia commented 3 years ago

Please simply clarify (ps5000 is WX8 board):

  • yes/no - there is pcb schema for this WX8_V01/ 20200930 board.

No, at least I don’t have it.

  • yes/no - u-boot (based on rockchip-linux||caesar-github 2017-09 or upstream) build is done. There are sources of u-boot that are applicable to this board:

    • configs/rk3128_ps5000_defconfig
    • board/rockchip/ps5000_rk3128/*
    • arch/arm/dts/rk3128-ps5000.dts

No. There is a defconfig for building the rootfs and a hierarchy of overlays for the specific consoles supported: a12/a13 and ps5000. The dts for ps5000 is not modified by the cfw, should be the same provided by the seller.

  • yes/no - linux (based on rockchip-linux||caesar-github 4.4 or 4.16 or upstream) build is done. There are sources of linux that are applicable to this board:

    • arch/arm/configs/rockchip_ps5000_defconfig
    • arch/arm/boot/dts/rk3128-ps5000.dts

No. As above, for the time being we only build the rootfs for ps5000.

Very thanks, Martin

Thanks for your interest!

And now the long story: we want to move to batocera to get a cleaner and more compatible environment. We are in the process. Another goal is building the whole system from scratch.

Regarding documentation, we want to add instructions to unpack (and repack) the boot partition so anyone is able to extract the dts. The sources of the official firmware are not being distributed by the seller, at least not to us, so the most we can provide are the steps to get the dts from the original partition. The only modification we do over the original boot partition for ps5000 is the splash screen to add version information and easily identify what the user flashed in case they are not skilled enough.

And now the longer story: we made the decision of distributing the boot image even though we didn’t get access to the sources because the seller of powkiddy a12/a13 devices introduced a modification in the dts to reset the device if you try to boot with a different rootfs. Thus, in those devices you need a modified dts to "free" the device.

Until we get stuff documented, the tools you can use to unpack/repack the boot partition are 7z and imageRePackerRK.

Best, Alberto.

alpgarcia commented 3 years ago

Of course if you are able to compile a working full system for the ps5000 we will be more than happy to get rid of the OFW boot. We are focused on moving to batocera to ease the compilation process, so the full system build is still a later step for us, definitely something we want to achieve.

mcerveny commented 3 years ago

Thanks for clarification.

I am capable to work with lowlevel RK tools (ASUS Tinker, PINE ROCK64 ...) like u-boot/tools/, rkbin/, build/mk_uboot.sh|mk_image.sh. But I have serious problems to replicate working u-boot (with SDcard support) (dtb/dtc already extracted from vendor image and manually created some initial dts). Get many errors from close-sourced loader (Boot1 Release Time: Nov 6 2018 21:30:48, version: 2.54) and hung recompiled u-boot :-(

acmeplus commented 3 years ago

I've not tried on this device yet, but I got a working u-boot for the A12 before. The issue there was not the u-boot but the kernel, even with the extracted KCONFIG from the OFW kernel the kernel was not working and something failed (probably display init).

There's another developer trying to get the PS5000 to boot off an SDCARD, I'll post an update if I hear back.

mcerveny commented 3 years ago

Duplicate #53

mcerveny commented 3 years ago

I tried to rebuild u-boot with SDCARD support but I failed. I used caesar-u-boot. I cleaned and enabled all needed stuff (see my WIP branch).

Problems:

Please publish yours success / progress.

funny note: after reboot from running linux back to u-boot it starts display and show splash image (but with some corruption, same with testing images with u-boot rockchip_show_bmp logo_kernel.bmp or rockchip_show_bmp logo_lowpower.bmp ...)

sad note: Aliexperess distributor refused to publish GPL sources and original designer ?"Shenzhen Sunchip Technology Co., Ltd."? did not respond. So there are candidates to report GPL violations.

some build notes:

acmeplus commented 3 years ago

Thanks for the update @mcerveny , very good and detailed notes.

Not much progress here, actually the opposite, I tried to compile u-boot again yesterday and after a couple of tests and flashing different combinations I ended up with a (hopefully) soft-bricked PS5000. It's currently in MSC mode (as opposed to the normal MASKROM & LOADER modes).

Note: just re-read your updated notes, about the LOADER mode and using CTRL-C. I tried to do that, for some reason it's not working for me, I don't seem to be able to send any key codes to the screen session. will try again tomorrow

I'll get back to try once I figure out a way to switch back from MSC to LOADER/MASKROM. I've been focused on trying to get the system to boot from the SD card. The closest I got to something in that direction is this:

DDR Version 2.09 20181106 dbg uart0
In
ID:0xFFF
1A1A1B1A   3
DDR3
282C1B1A   3
39391B1A   3
Bus Width=16 Col=10 Bank=8 Row=15 CS=1 Die Bus-Width=16 Size=512MB
mach:9
OUT
Boot1 Release Time: Nov  6 2018 21:30:48, version: 2.54
ChipType = 0xa, 348
sfc_nand_init
sfc_nand id: ef aa 21
sfc_nand A0 = 0x0
sfc_nand B0 = 0x18
sfc_nand C0 = 0x2
read_lines = 2
prog_lines = 2
page_read_cmd = 6b
page_prog_cmd = 32
SFTL version: 5.0.48 20181009
mmc0:cmd5,20
SdmmcInit=0 0
BootCapSize=0
UserCapSize=29818MB
FwPartOffset=2000 , 0
run on sd0
StorageInit ok = 263130
GPT 0x632d7e00 signature is wrong
recovery gpt...
GPT: header_lba incorrect: 3A3CFFF
recovery gpt fail!
tag:LOADER error,addr:0x2000
hdr 632d77e0 + 0x0:0xfbf2e44d,0x895ef6d0,0x1feaa17d,0x1c01be61,
tag:LOADER error,addr:0x4000
hdr 632d77e0 + 0x0:0x50,0xfa,0x11,0xb4,0x5f,0x78,0x09,0xe8,0x42,0x9e,0x9b,0x5c,0xcb,0xe4,0x31,0x78,

Note the "run on sd0" mention. However all my efforts have resulted on what the system considers a GPT corrupted partition, and none of the actual SD card partitions are being read.

Some additional resource that may be helpful for your efforts: https://github.com/hyperkin-game/hyperkin-gb

The repo includes all the required elements to build a full sd image from scratch.

acmeplus commented 3 years ago

Additional update: Managed to recover the PS5000 from the MSC mode after flashing a SDcard with the correct partitions:

sudo dd if=idbloader-sdcard.img of=/dev/sdb seek=64 conv=sync,fsync 
sudo dd if=uboot.img of=/dev/sdb seek=16384 conv=sync,fsync
sudo dd if=trust.img of=/dev/sdb seek=24576 conv=sync,fsync
sudo dd if=boot.img of=/dev/sdb seek=32768 conv=sync,fsync
sudo dd if=rootfs.img of=/dev/sdb seek=262144 conv=sync,fsync

Using the uboot compiled from @mcerveny sources, I was able to get to the autoboot prompt, press CTRL+C to stop and then enter rockusb 0 spinand 0 as Martin described above to get back to LOADER mode and flash my full backup image with upgrade_tool wl 0x0 backup.img

The most important thing si that the SD card that I created seems to work to get the system to boot directly. Still the partitions are not pointing to the right place and after loading the uboot the system looks for the rest of the partitions from the internal memory.

Note: idbloader_sdcard was generated with: u-boot/tools/mkimage -n rk3128 -T rksd -d rk3128_ddr_300MHz_v2.09_uart0_20181106.bin ./idbloader-sdcard.img The script to generate it can be found on the hyperkin-gb repo

mcerveny commented 3 years ago

Yes. SDcard is u-boot bootable. My script (for .img or direct to /dev/sdc):

#!/bin/bash -exv

LOCALPATH=$(pwd)
UBOOT=caesar-u-boot
RKBIN=caesar-rkbin
CHIP="rk3128"

LOADER1_START=64
UBOOT_START=16384   
TRUST_START=$(($UBOOT_START + 8192))
BOOT_START=$(($TRUST_START + 8192))
ROOTFS_START=$(($BOOT_START + 18432))
USERDATA_START=$(($ROOTFS_START + 143360))

if [ x"$1" = "x" ]; then
SIZE=220672
SYSTEM=system.img
dd if=/dev/zero of=${SYSTEM} count=0 seek=$SIZE
else
SYSTEM=/dev/sdc
for i in ${SYSTEM}[1-9]; do umount $i || true; done
dd if=/dev/zero of=${SYSTEM} bs=1M count=$(( $ROOTFS_START / 2 / 1024 + 1)) conv=sync
partprobe
fi

echo "Generate System image : ${SYSTEM} !"

parted -s ${SYSTEM} mklabel gpt
parted -s ${SYSTEM} unit s mkpart uboot ${UBOOT_START} $(( ${TRUST_START} - 1))
parted -s ${SYSTEM} unit s mkpart trust ${TRUST_START} $(( ${BOOT_START} - 1))
parted -s ${SYSTEM} unit s mkpart boot ${BOOT_START} $(( ${ROOTFS_START} - 1))
parted -s ${SYSTEM} set 3 boot on
parted -s ${SYSTEM} unit s mkpart rootfs ${ROOTFS_START} $(( ${USERDATA_START} - 1))
parted -s ${SYSTEM} -- unit s mkpart userdata ${USERDATA_START} -64s
partprobe

ROOT_UUID="614e0000-0000-4b53-8000-1d28000054a9"

gdisk ${SYSTEM} <<EOF
x
c
4
${ROOT_UUID}
w
y
EOF

# OMG, in some rockchip scripts, what is this:
#dd if=$RKBIN/bin/rk31/rk3128_ddr_300MHz_v2.12.bin of=DDRTEMP bs=4 skip=1
#$UBOOT/tools/mkimage -n rk3128 -T rksd -d DDRTEMP idbloader.img

$UBOOT/tools/mkimage -n rk3128 -T rksd -d $RKBIN/bin/rk31/rk3128_ddr_300MHz_v2.12.bin idbloader.img
cat $RKBIN/bin/rk31/rk3128x_miniloader_v2.57.bin >> idbloader.img

# 8192s -> 4MB -> 4 copies

$UBOOT/tools/loaderimage --pack --uboot $UBOOT/u-boot-dtb.bin uboot.img --size 1024 4
$UBOOT/tools/loaderimage --pack --trustos $RKBIN/bin/rk31/rk3126_tee_ta_v2.01.bin trust.img --size 1024 4

dd if=idbloader.img of=${SYSTEM} seek=${LOADER1_START} conv=notrunc,sync
dd if=uboot.img of=${SYSTEM} seek=${UBOOT_START} conv=notrunc,sync
dd if=trust.img of=${SYSTEM} seek=${TRUST_START} conv=notrunc,sync

dd if=boot.img of=${SYSTEM} conv=notrunc,sync seek=${BOOT_START}

dd if=rootfs.img of=${SYSTEM} conv=notrunc,sync seek=${ROOTFS_START}

But the problems persist. Not able to boot from sdcard (mmc dev 1):

=> mmc dev 1
MMC error: The cmd index is 13, ret is -22
MMC error: The cmd index is 13, ret is -110
MMC error: The cmd index is 13, ret is -110
MMC error: The cmd index is 13, ret is -110
mmc_init: -110, time 27

I used spinand boot and rebooted from linux (not power on/off):

=> boot_android spinand 0
Could not find misc partition
ANDROID: reboot reason: "(none)"
Not AVB images, AVB skip
Kernel image @ 0x7be0d768 [ 0x000000 - 0x3dadf8 ]
DTB: rk-kernel.dtb
HASH(s): OK
Booting ZIMAGE kernel at 0x62008000(Uncompress to 0x60000000) with fdt at 0x68300000...

Fdt Ramdisk skip relocation
## Booting Android Image at 0x62007800 ...
Kernel load addr 0x62008000 size 3948 KiB
## Flattened Device Tree blob at 0x68300000
   Booting using the fdt blob at 0x68300000
   XIP Kernel Image from 0x62008000 to 0x62008000 ... OK
   Using Device Tree in place at 68300000, end 6830e2a2
failed to reserve drm-cubic-lut memory
Adding bank: 0x60000000 - 0x68400000 (size: 0x08400000)
Adding bank: 0x69210000 - 0x80000000 (size: 0x16df0000)
Total: 182390.686 ms

Starting kernel ...

..............

[root@root:/]# reboot

Interrupt rebooted u-boot and the sdcard works:

.........
 <debug_uart> MMC:   dwmmc@10214000: 1
Using default environment

switch to partitions #0, OK
mmc1 is current device
Found IDB in SDcard
Boot from SDCARD
Bootdev: mmc 1
MMC1: Legacy, 26Mhz
PartType: EFI
........
Hit key to stop autoboot('CTRL+C'):  0 
=> mmc dev 1
switch to partitions #0, OK
mmc1 is current device
=> mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part    Start LBA   End LBA     Name
    Attributes
    Type GUID
    Partition GUID
  1 0x00004000  0x00005fff  "uboot"
    attrs:  0x0000000000000000
    type:   0fc63daf-8483-4772-8e79-3d69d8477de4
    guid:   a9ea64f2-f71b-4c98-998e-81b8d3a160f1
  2 0x00006000  0x00007fff  "trust"
    attrs:  0x0000000000000000
    type:   0fc63daf-8483-4772-8e79-3d69d8477de4
    guid:   92c1a295-e156-4fcb-aacd-02bfdf94dfd3
  3 0x00008000  0x0000c7ff  "boot"
    attrs:  0x0000000000000000
    type:   c12a7328-f81f-11d2-ba4b-00a0c93ec93b
    guid:   6df3c492-bb6a-447a-8e48-249923b478a6
  4 0x0000c800  0x0002f7ff  "rootfs"
    attrs:  0x0000000000000000
    type:   0fc63daf-8483-4772-8e79-3d69d8477de4
    guid:   614e0000-0000-4b53-8000-1d28000054a9
  5 0x0002f800  0x01d2dfc0  "userdata"
    attrs:  0x0000000000000000
    type:   0fc63daf-8483-4772-8e79-3d69d8477de4
    guid:   5b9ba82c-e10a-4028-99d5-1f8f5398b978
=> boot_android mmc 1
Could not find misc partition
ANDROID: reboot reason: "(none)"
Not AVB images, AVB skip
Kernel image @ 0x7bddfba8 [ 0x000000 - 0x3dadf8 ]
DTB: rk-kernel.dtb
Booting ZIMAGE kernel at 0x62008000(Uncompress to 0x60000000) with fdt at 0x68300000...

Fdt Ramdisk skip relocation
## Booting Android Image at 0x62007800 ...
Kernel load addr 0x62008000 size 3948 KiB
## Flattened Device Tree blob at 0x68300000
   Booting using the fdt blob at 0x68300000
   XIP Kernel Image from 0x62008000 to 0x62008000 ... OK
   Using Device Tree in place at 68300000, end 6830e292
failed to reserve drm-cubic-lut memory
Adding bank: 0x60000000 - 0x68400000 (size: 0x08400000)
Adding bank: 0x69210000 - 0x80000000 (size: 0x16df0000)
Total: 67896.479 ms

Starting kernel ...

Something is bad in u-boot. Maybe PWM powers, interrupts, dmas ...

additional hint: I did many tests and I destroyed protected bootloader in spinand :-). so MASKROM mode must be forced by GND to DI or CLK on W25N01GV and upload testing u-boot (with NONSEC support) directly to RAM over USB:

# openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 < rk3128_ddr_300MHz_v2.09_uart0_20181106.bin | rkflashtool/rkflashtool l
# openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 < caesar-u-boot/u-boot-dtb.bin  | rkflashtool/rkflashtool L
# ### or other loader like rk3128_usbplug_v2.63.bin, rk3128_loader_v2.12.263.bin ...
mcerveny commented 3 years ago

Ok, "repaired" SDcard boot, use only 1-bit (not 4-bit) mode (see https://github.com/mcerveny/caesar-u-boot/commit/7f2236ec5a587577416a774e470b409bec33845c) with actual code :-( .

acmeplus commented 3 years ago

Ok, "repaired" SDcard boot, use only 1-bit (not 4-bit) mode (see mcerveny/caesar-u-boot@7f2236e) with actual code :-( .

Very nice, I tried a different route by plugin a USB card to rule out whether there was a different issue, the USB booted "correctly":

Scanning usb 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
165 bytes read in 108 ms (1000 Bytes/s)
1:      linux
Retrieving file: /extlinux/zImage
4042920 bytes read in 294 ms (13.1 MiB/s)
append: earlyprintk console=ttyS0,115200n8 rw root=/dev/mmcblk1p7 rootwait rootfstype=ext4 init=/sbin/init
Retrieving file: /extlinux/rk-kernel.dtb
45719 bytes read in 155 ms (287.1 KiB/s)
Fdt Ramdisk skip relocation
Kernel image @ 0x62008000 [ 0x000000 - 0x3db0a8 ]
## Flattened Device Tree blob at 0x68300000
   Booting using the fdt blob at 0x68300000
   Using Device Tree in place at 68300000, end 6830e296
No resource partition
No file: logo.bmp
Adding bank: 0x60000000 - 0x61000000 (size: 0x01000000)
Adding bank: 0x61200000 - 0x80000000 (size: 0x1ee00000)
Total: 8888.208 ms

Starting kernel ...

Just tried your uboot patch and I can confirm that fixes the SDMMC errors.

However the display is not properly initialized, the UART does not show anything (I need to change the kernel console to output to the same one) but the syslog shows the problem:

[   63.286218] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.386221] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.486245] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.586191] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms

Full dmesg log: dmesg.log

Note that this is booting via spinand, since I needed the MMC.

In any case, impressive work @mcerveny !

mcerveny commented 3 years ago

"caesar" removed kernel git (https://github.com/Caesar-github/rockchip.git) :-( (I have local copy :-). Not all patches are in rockchip kernel git (https://github.com/rockchip-linux/kernel.git):

# git log --format=short HEAD...ada467d2718ff0f929d5512053a28b9238b57b4c > /tmp/additional_patches.txt

additional_patches.txt

alpgarcia commented 3 years ago

@mcerveny, @acmeplus, --Big disclaimer: I don't have any idea about how all this stuff works--

[   63.286218] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.386221] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.486245] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms
[   63.586191] rockchip-vop 1010e000.vop: [drm:vop_wait_for_irq_handler] *ERROR* VOP vblank IRQ stuck for 10 ms

I found this patch and I wonder whether the error above may be related to something similar.

mcerveny commented 3 years ago

I found this patch and I wonder whether the error above may be related to something similar.

Nope.

Rockchip repo (uboot and kernel) have lot of proprietary code and WX8 authors add some additional code and does not expose it to public thus violating GPL. As I wrote @ beginning I suppose that "original kernel" heavily depends on "original u-boot" initialization of HW that is awful. This messages arise when I used Rockchip (caesar) opensource u-boot with "original kernel".

Now I try to rebuild kernel from Rockchip opensources but I found many proprietary drivers/code in kernel config:

CONFIG_KEYBOARD_GPIO_VOLUME
CONFIG_KEYBOARD_GPIO_WX8
CONFIG_SCREEN_OFF
CONFIG_WX8_OTG_HOST
CONFIG_DRM_PANEL_SIMPLE_WX8OLED
CONFIG_DRM_PANEL_SIMPLE_LCD_RESET
CONFIG_EXFAT_FS # backported from kernel >=5.4
CONFIG_EXFAT_DISCARD # backported from kernel >=5.4
CONFIG_EXFAT_DEFAULT_CODEPAGE # backported from kernel >=5.4
CONFIG_EXFAT_DEFAULT_IOCHARSET # backported from kernel >=5.4

I queried Shenzhen Sunchip Technology Co., Ltd. over Alibaba chat (or direct) to get access to GPL licensed code and build script (uboot,kernel,buildroot...). Sunchip say, that they are the developer of PS5000 or here ... and 10% off in September. No answer, try it too.

mcerveny commented 3 years ago

I was partially successful to rebuild linux kernel (based on rockchipl-linux). As I wrote in previous post many "close source" mods exists.

hint*: boot from original uboot/kernel and then "reboot" by command to sdcard.

example of sdcard build script:

#!/bin/bash

LOCALPATH=$(pwd)
UBOOT=caesar-u-boot
RKBIN=caesar-rkbin
LINUX=rockchip-linux

LOADER1_START=64
UBOOT_START=16384   
TRUST_START=$(($UBOOT_START + 8192))
BOOT_START=$(($TRUST_START + 8192))
ROOTFS_START=$(($BOOT_START + 18432))
USERDATA_START=$(($ROOTFS_START + 143360))
SDCARD_START=$(($USERDATA_START + 65536))

SYSTEM=/dev/sdc

echo DESTOROY ${SYSTEM} ?!?!?
read

for i in ${SYSTEM}[1-9]; do umount $i || true; done
dd if=/dev/zero of=${SYSTEM} bs=1M count=$(( $ROOTFS_START / 2 / 1024 + 1)) conv=sync
partprobe

echo PARTITIONS

parted -s ${SYSTEM} mklabel gpt
parted -s ${SYSTEM} unit s mkpart uboot ${UBOOT_START} $(( ${TRUST_START} - 1))
parted -s ${SYSTEM} unit s mkpart trust ${TRUST_START} $(( ${BOOT_START} - 1))
parted -s ${SYSTEM} unit s mkpart boot ${BOOT_START} $(( ${ROOTFS_START} - 1))
parted -s ${SYSTEM} set 3 boot on
parted -s ${SYSTEM} unit s mkpart rootfs ${ROOTFS_START} $(( ${USERDATA_START} - 1))
parted -s ${SYSTEM} unit s mkpart userdata ${USERDATA_START} $(( ${SDCARD_START} - 1))
parted -s ${SYSTEM} -- unit s mkpart sdcard ${SDCARD_START} -64s
partprobe

gdisk ${SYSTEM} <<EOF
x
c
4
${ROOT_UUID}
w
y
EOF

echo IMAGES

# OMG, in some rockchip scripts, what is this:
#dd if=$RKBIN/bin/rk31/rk3128_ddr_300MHz_v2.12.bin of=DDRTEMP bs=4 skip=1
#$UBOOT/tools/mkimage -n rk3128 -T rksd -d DDRTEMP idbloader.img

$UBOOT/tools/mkimage -n rk3128 -T rksd -d $RKBIN/bin/rk31/rk3128_ddr_300MHz_v2.12.bin idbloader.img
cat $RKBIN/bin/rk31/rk3128x_miniloader_v2.57.bin >> idbloader.img

# 8192s -> 4MB -> 4 copies

$UBOOT/tools/loaderimage --pack --uboot $UBOOT/u-boot-dtb.bin uboot.img --size 1024 4
$UBOOT/tools/loaderimage --pack --trustos $RKBIN/bin/rk31/rk3126_tee_ta_v2.01.bin trust.img --size 1024 4

echo COPY

dd if=idbloader.img of=${SYSTEM} seek=${LOADER1_START} conv=notrunc,sync
dd if=uboot.img of=${SYSTEM} seek=${UBOOT_START} conv=notrunc,sync
dd if=trust.img of=${SYSTEM} seek=${TRUST_START} conv=notrunc,sync

mkfs.ext2 -F ${SYSTEM}3
mount ${SYSTEM}3 /mnt
mkdir /mnt/extlinux
cp extlinux.conf /mnt/extlinux/
cp ${LINUX}/arch/arm/boot/zImage /mnt/extlinux/
cp ${LINUX}/arch/arm/boot/dts/rk3128-wx8.dtb /mnt/extlinux/kernel.dtb
umount /mnt

dd if=rootfs.img of=${SYSTEM} conv=notrunc,sync seek=${ROOTFS_START}

mkfs.ext2 -F ${SYSTEM}5

mkfs.vfat ${SYSTEM}6
mount ${SYSTEM}6 /mnt
tar xf sdcard.tar -C /mnt --no-same-owner
umount /mnt

echo DONE

example of extlinux.conf:

DEFAULT linux
LABEL linux
  KERNEL zImage
  FDT kernel.dtb
  APPEND earlycon=uart8250,mmio32,0x20060000 rootwait console=ttyFIQ0,115200n8 loglevel=7 swiotlb=1 root=PARTUUID=614e0000-0000-4b53-8000-1d28000054a9

sdcard.tar:

# tar tf sdcard.tar 
./
./game/
./game/gba/
./game/gba/1823 - Pac-Man World(EU).gba
./music/
./music/test music (1).mp3
./video/
./video/one piece.mp4
./pic/
./pic/01.jpg
acmeplus commented 3 years ago

@mcerveny just to confirm that I can mostly reproduce your findings. Some minor differences/observations:

I'll do some additional tests this week.

mcerveny commented 3 years ago
* Direct boot from the sdcard (without the hint) and with HDMI connected basically gets me the expected HDMI EDID errors, so anything DRM based does not work, however SDL applications do work via HDMI. Tested SDLPoP and worked fine

DRM works, but display is not on, attach HDMI that is capable 960x544/59HZ.

* I can confirm only zpio core controls work, adc-pot ones don't respond (/dev/input only registers event0, no event2-5 or js0/js1)

I will try to read internal register settings and others in /sys/kernel/debug/... to decode used pins :-)

* Not really sure if I may have just overwritten something on my sdcard, but it looks like the boot from the sdcard still keeps the internal/spinand rootfs and not the one from the sdcard. I need to doublecheck that my extlinux append line is correct, it may just be a typo.

Try to change UUID (partition UUID and extlinux.conf reference)

* Finally, I've done the same tests with the Powkiddy A12, same SOC, different specs. SDcard works the same as with PS5K/WX8, although the display is initialized (incorrectly but is on) during boot.

This is weird. As I see A13 board display is connected with parallel RGB and not MIPI DSI.

acmeplus commented 3 years ago
* Direct boot from the sdcard (without the hint) and with HDMI connected basically gets me the expected HDMI EDID errors, so anything DRM based does not work, however SDL applications do work via HDMI. Tested SDLPoP and worked fine

DRM works, but display is not on, attach HDMI that is capable 960x544/59HZ.

Ok, will try a different monitor.

* I can confirm only zpio core controls work, adc-pot ones don't respond (/dev/input only registers event0, no event2-5 or js0/js1)

I will try to read internal register settings and others in /sys/kernel/debug/... to decode used pins :-)

I may be able to help there. Will give it a try.

* Not really sure if I may have just overwritten something on my sdcard, but it looks like the boot from the sdcard still keeps the internal/spinand rootfs and not the one from the sdcard. I need to doublecheck that my extlinux append line is correct, it may just be a typo.

Try to change UUID (partition UUID and extlinux.conf reference)

Yeah, I haven't had time but it's most likely that.

* Finally, I've done the same tests with the Powkiddy A12, same SOC, different specs. SDcard works the same as with PS5K/WX8, although the display is initialized (incorrectly but is on) during boot.

This is weird. As I see A13 board display is connected with parallel RGB and not MIPI DSI.

Yes, I noticed that, so it's probably something else that is activating that. It's only initialization, haven't tried to actually use the display. Update: just tested and initialization lights the display up with white background. After boot finishes display stays up but with black background. HDMI works as before, SDLPoP works on the HDMI, DRM does not. This is without the re-boot trick.

Busy the last few days, will try to find some time this week.

BTW, you can find @alpgarcia or @acmeplus on telegram or discord.

mcerveny commented 3 years ago

Resolved hint problem. Found master "enable" GPIO (part of closed source driver "gpio-keys-volume") so I moved last two keys VOL+/VOL- to generic GPIO keys (but volume control does not work due to need of direct scaling in PCM engine) see https://github.com/mcerveny/rockchip-linux/commit/432d410d98f580fac3c5835c4f45c8bfeaa8e1a1 . Master "enable" GPIO can be used over `/sys/class/gpio/`:

echo 93 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio93/direction
echo 1 > /sys/class/gpio/gpio93/value
acmeplus commented 3 years ago

Resolved hint* problem.

The display init issue? or the GPIO?

Found master "enable" GPIO (part of closed source driver "gpio-keys-volume") so I moved last two keys VOL+/VOL- to generic GPIO keys (but volume control does not work due to need of direct scaling in PCM engine) see mcerveny/rockchip-linux@432d410 . Master "enable" GPIO can be used over /sys/class/gpio/*:

echo 93 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio93/direction
echo 1 > /sys/class/gpio/gpio93/value

Good, running /etc/init.d/S49alsa stop/start adds the master mixer too. Also changing the /etc/input-even-daemon to listen to /dev/input/event0 event links the volume control to the master. The way it was done on these device was via that listener. Other devices have proper mapping of volume to PCM.

I've tested what I have running internally+external sdcard working via external SDCard only, of course viaHDMI only.

mcerveny commented 3 years ago

Resolved hint* problem. The display init issue? or the GPIO?

MIPI DSI display. As I wrote, the MIPI DSI display was always initialized properly (in kernel, unknown in u-boot) only nothing shows due to this powersaving GPIO switch. The closed sourced driver exposes /sys/devices/platform/adc-pot/screen_off to drive this GPIO and for audio volume /sys/devices/platform/adc-pot/scaled....

acmeplus commented 3 years ago

Resolved hint* problem. The display init issue? or the GPIO?

MIPI DSI display. As I wrote, the MIPI DSI display was always initialized properly (in kernel, unknown in u-boot) only nothing shows due to this powersaving GPIO switch. The closed sourced driver exposes /sys/devices/platform/adc-pot/screen_off to drive this GPIO and for audio volume /sys/devices/platform/adc-pot/scaled....

Yeah, I get it now... just checked and it's working both internally/externally. It's interesting because the adc-pot is misconfigured in the A12 console, and the volume control always complains about the adc-pot.

I'm going to try to consolidate the batocera test firmware I have with this setup.

mcerveny commented 3 years ago

Example of audio volume control (hdmi not tested):

# cat /sdcard/input-event-daemon.conf
[Global]
listen = /dev/input/by-path/platform-keys-event

[Keys]
VOLUMEUP        = /bin/bash /sdcard/volctrl.sh up
VOLUMEDOWN  = /bin/bash /sdcard/volctrl.sh down
# cat /sdcard/volctrl.sh
#!/bin/bash

if [ `cat /sys/class/drm/card0-HDMI-A-1/status` == "disconnected" ]; then
    name='Master Playback Volume'
else
    name='HDMI Playback Volume'
fi

value=$(amixer cget name="$name" | sed -n 's/^  :.*values=\([[0-9]*\).*/\1/p')

if [[ "$1" == "up" ]]; then
    let value=value+9
    if [[ $value -gt 99 ]]; then value=99; fi
else
    let value=value-9
    if [[ $value -lt 0 ]]; then value=0; fi
fi

amixer cset name="$name" $value
# input-event-daemon -c /sdcard/input-event-daemon.conf -v
# ### press V+/V-
key_event:
  code     : VOLUMEUP
  source   : /dev/input/by-path/platform-keys-event
  exec     : "/bin/bash /sdcard/volctrl.sh up"

numid=6,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0
  : values=63,63
  | dBscale-min=-40.00dB,step=0.34dB,mute=0

key_event:
  code     : VOLUMEUP
  source   : /dev/input/by-path/platform-keys-event
  exec     : "/bin/bash /sdcard/volctrl.sh up"

numid=6,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0
  : values=72,72
  | dBscale-min=-40.00dB,step=0.34dB,mute=0

key_event:
  code     : VOLUMEDOWN
  source   : /dev/input/by-path/platform-keys-event
  exec     : "/bin/bash /sdcard/volctrl.sh down"

numid=6,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0
  : values=63,63
  | dBscale-min=-40.00dB,step=0.34dB,mute=0

key_event:
  code     : VOLUMEDOWN
  source   : /dev/input/by-path/platform-keys-event
  exec     : "/bin/bash /sdcard/volctrl.sh down"

numid=6,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0
  : values=54,54
  | dBscale-min=-40.00dB,step=0.34dB,mute=0
# ### test it (aplay does not work without `-v` or other audio client must be started)
# aplay -v /usr/local/share/minigui/res/music/chord.wav
mcerveny commented 3 years ago

Resolved unknown I2C chip (address 0x4c):

int main() { int addr = 0x4c; int file; uint8_t buf[15];

    assert((file = open("/dev/i2c-0", O_RDWR)) >= 0);
    assert(!ioctl(file, I2C_SLAVE, addr));
    assert(read(file,buf,sizeof(buf)) == sizeof(buf));

    //for(int i=0;i<sizeof(buf)/sizeof(buf[0]); i++) {
    //        printf("%2d %3d\n", i, buf[i]);
    //}
    printf("LV %3d\nLH %3d\nRV %3d\nRH %3d", buf[9], buf[7], buf[1], buf[3]);

}

cross compile:

arm-linux-gnueabihf-gcc i2c_joy.c -o i2c_joy

cp i2c_joy /...to_sdcard../

use:

cp /sdcard/i2c_joy /tmp

chmod 555 /tmp/i2c_joy

watch -n 1 /tmp/i2c_joy

output like (range ~100-220)

LV 169 LH 164 RV 166 RH 164

mcerveny commented 3 years ago

Created +-compatible joystick driver see https://github.com/mcerveny/rockchip-linux/commit/cdb8bee370ff1cf42ad2bc5bc7187f9ecaf86b50. Driver with keys emulation (directions,ABXY) enabled by default. To switch between keys emulation and joysticks put 0 or 1 to "/sys/.../key_type". Key emulation (default):

[root@root:/]# evtest /dev/input/event0 
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "Driver for WX8 joysticks"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 21 (KEY_Y)
    Event code 30 (KEY_A)
    Event code 45 (KEY_X)
    Event code 48 (KEY_B)
    Event code 103 (KEY_UP)
    Event code 105 (KEY_LEFT)
    Event code 106 (KEY_RIGHT)
    Event code 108 (KEY_DOWN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value    163
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 1 (ABS_Y)
      Value    167
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 2 (ABS_Z)
      Value    162
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 5 (ABS_RZ)
      Value    163
      Min       95
      Max      225
      Fuzz       2
      Flat       4
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1213.870982, type 1 (EV_KEY), code 30 (KEY_A), value 1
Event: time 1213.870982, -------------- SYN_REPORT ------------
Event: time 1213.930827, type 1 (EV_KEY), code 30 (KEY_A), value 0
Event: time 1213.930827, -------------- SYN_REPORT ------------
Event: time 1216.070963, type 1 (EV_KEY), code 105 (KEY_LEFT), value 1
Event: time 1216.070963, -------------- SYN_REPORT ------------
Event: time 1216.191000, type 1 (EV_KEY), code 105 (KEY_LEFT), value 0
Event: time 1216.191000, -------------- SYN_REPORT ------------

Switch to joysticks ("1"):

[root@root:/]# find /sys -name key_type
/sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type
[root@root:/]# cat /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type
0
[root@root:/]# echo 1 > /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type
[root@root:/]# cat /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type
1
[root@root:/]# evtest /dev/input/event0 
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "Driver for WX8 joysticks"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 21 (KEY_Y)
    Event code 30 (KEY_A)
    Event code 45 (KEY_X)
    Event code 48 (KEY_B)
    Event code 103 (KEY_UP)
    Event code 105 (KEY_LEFT)
    Event code 106 (KEY_RIGHT)
    Event code 108 (KEY_DOWN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value    163
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 1 (ABS_Y)
      Value    167
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 2 (ABS_Z)
      Value    161
      Min       95
      Max      225
      Fuzz       2
      Flat       4
    Event code 5 (ABS_RZ)
      Value    167
      Min       95
      Max      225
      Fuzz       2
      Flat       4
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1312.891016, type 3 (EV_ABS), code 2 (ABS_Z), value 162
Event: time 1312.891016, -------------- SYN_REPORT ------------
Event: time 1312.901030, type 3 (EV_ABS), code 2 (ABS_Z), value 163
Event: time 1312.901030, -------------- SYN_REPORT ------------
Event: time 1312.920820, type 3 (EV_ABS), code 5 (ABS_RZ), value 166
Event: time 1312.920820, -------------- SYN_REPORT ------------
Event: time 1312.951078, type 3 (EV_ABS), code 5 (ABS_RZ), value 165
Event: time 1312.951078, -------------- SYN_REPORT ------------
Event: time 1313.751213, type 3 (EV_ABS), code 2 (ABS_Z), value 162
Event: time 1313.751213, -------------- SYN_REPORT ------------
Event: time 1313.770868, type 3 (EV_ABS), code 5 (ABS_RZ), value 166
Event: time 1313.770868, -------------- SYN_REPORT ------------
Event: time 1313.780876, type 3 (EV_ABS), code 2 (ABS_Z), value 161
Event: time 1313.780876, -------------- SYN_REPORT ------------
Event: time 1313.791052, type 3 (EV_ABS), code 2 (ABS_Z), value 160
Event: time 1313.791052, -------------- SYN_REPORT ------------
Event: time 1313.810824, type 3 (EV_ABS), code 2 (ABS_Z), value 156
Event: time 1313.810824, -------------- SYN_REPORT ------------
Event: time 1313.840822, type 3 (EV_ABS), code 2 (ABS_Z), value 134
Event: time 1313.840822, -------------- SYN_REPORT ------------
Event: time 1313.871064, type 3 (EV_ABS), code 2 (ABS_Z), value 112
Event: time 1313.871064, -------------- SYN_REPORT ------------
Event: time 1313.900894, type 3 (EV_ABS), code 2 (ABS_Z), value 108
Event: time 1313.900894, -------------- SYN_REPORT ------------
Event: time 1313.930830, type 3 (EV_ABS), code 2 (ABS_Z), value 117
Event: time 1313.930830, -------------- SYN_REPORT ------------
Event: time 1313.960905, type 3 (EV_ABS), code 2 (ABS_Z), value 162
Event: time 1313.960905, -------------- SYN_REPORT ------------
Event: time 1316.041041, type 3 (EV_ABS), code 1 (ABS_Y), value 168
Event: time 1316.041041, -------------- SYN_REPORT ------------
Event: time 1316.051030, type 3 (EV_ABS), code 1 (ABS_Y), value 169
Event: time 1316.051030, -------------- SYN_REPORT ------------
Event: time 1316.071243, type 3 (EV_ABS), code 0 (ABS_X), value 171
Event: time 1316.071243, -------------- SYN_REPORT ------------
Event: time 1316.100814, type 3 (EV_ABS), code 0 (ABS_X), value 194
Event: time 1316.100814, -------------- SYN_REPORT ------------
mcerveny commented 3 years ago

I try to connect both (keys + joys (emulated EV_KEY or joystick EV_ABS)) to retroarch but mostly unsuccessful. Keys does not work for me. I found the retroarch accept only ENV "ID_INPUT_JOYSTICK=1" udevs :-( Is there anyone capable to debug this (problem with original "china-version" retroarch?) ? So I do this to set ENV for keys:

cp -r /etc/udev/rules.d/ /tmp/
cat > /tmp/rules.d/99-keys.rules << EOT  
KERNEL=="event1", ENV{ID_INPUT_JOYSTICK}="1"
EOT
mount --binding /tmp/rules.d/ /etc/udev/rules.d/
udevadm control --reload-rules
sleep 1
udevadm trigger /dev/input/event1
sleep 1
udevadm info /dev/input/event1 
### see ID_INPUT_JOYSTICK
# testing # evtest /dev/input/event1
# testing # evtest /dev/input/event0
mcerveny commented 3 years ago

Update to HDMI with original rootfs:

cat /sys/devices/platform/display-subsystem/drm/card0/card0-HDMI-A-1/modes

1920x1080p60 1280x720p60 1920x1080p120 1920x1080p100 1920x1080p60 1920x1080p60 1400x1050p60 1280x1024p60 1440x900p60 1280x960p60 1280x720p60 1024x768p60 800x600p60

cat /sys/devices/platform/display-subsystem/drm/card0/card0-HDMI-A-1/mode

1280x720p60

- HDMI automatically switched over /etc/udev/rules.d/60-drm.rules -> /usr/bin/drm-hotplug.sh
- HDMI audio works and volume can be modified by hotkeys `input-event-daemon -c /sdcard/input-event-daemon.conf -v` (see previous posts)

input-event-daemon: Start listening on 1 devices... key_event: code : VOLUMEDOWN source : /dev/input/by-path/platform-keys-event exec : "/bin/bash /sdcard/volctrl.sh down"

numid=7,iface=MIXER,name='HDMI Playback Volume' ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0 : values=85,85 | dBscale-min=-40.00dB,step=0.40dB,mute=0

key_event: code : VOLUMEDOWN source : /dev/input/by-path/platform-keys-event exec : "/bin/bash /sdcard/volctrl.sh down"

numid=7,iface=MIXER,name='HDMI Playback Volume' ; type=INTEGER,access=rw---RW-,values=2,min=0,max=99,step=0 : values=76,76 | dBscale-min=-40.00dB,step=0.40dB,mute=0

acmeplus commented 3 years ago

I try to connect both (keys + joys (emulated EV_KEY or joystick EV_ABS)) to retroarch but mostly unsuccessful. Keys does not work for me. I found the retroarch accept only ENV "ID_INPUT_JOYSTICK=1" udevs :-( Is there anyone capable to debug this (problem with original "china-version" retroarch?) ?

With the lastest change that you have done I have all keys and joysticks working under retroarch.

Not sure if this helpful, note that the retroarch version is 1.9.7 compiled with udev + sdl2, the one from the Chinese firmware is 1.7.4 or something like that.

mcerveny commented 3 years ago

With the lastest change that you have done I have all keys and joysticks working under retroarch.

Good news :-)

  * L3/R3 don't work (I believe that's expected)

I HW traced R3 button (push joystick):

alpgarcia commented 3 years ago

Awesome work @mcerveny and @acmeplus!

I've been able to create a bootable SD that runs into RetroArch. For completeness, I'm detailing the sources and small tweaks I applied so anyone else can reproduce them. I didn't test HDMI and headphones output yet.

Repositories to compile

Tweaks

I added the following snippet to Martin's script to create the extlinux.conf file.

PARTUUID=`blkid -o export ${SYSTEM}4 | grep PARTUUID`
echo "Create extlinux.conf"

cat > extlinux.conf << EOF
DEFAULT linux
LABEL linux
  KERNEL zImage
  FDT kernel.dtb
  APPEND earlycon=uart8250,mmio32,0x20060000 rootwait console=ttyFIQ0,115200n8 loglevel=7 swiotlb=1 root=${PARTUUID}
EOF

echo "---- extlinux.conf ----"
cat extlinux.conf
echo "-----------------------"

The rootfs needs some modifications:

Volume buttons are not being recognized in Retroarch (VOLUMEUP and VOLUMEDOWN), however volume can still be set by configuring the RetroArch hotkeys.

mcerveny commented 3 years ago

I tried to enable u-boot display/DSI support to show "logo" (splash screens). It partially works:

LOCALPATH=$(pwd) UBOOT=caesar-u-boot RKBIN=caesar-rkbin LINUX=rockchip-linux

LOADER1_START=64 UBOOT_START=16384
TRUST_START=$(($UBOOT_START + 8192)) BOOT_START=$(($TRUST_START + 8192)) ROOTFS_START=$(($BOOT_START + 18432)) USERDATA_START=$(($ROOTFS_START + 143360)) SDCARD_START=$(($USERDATA_START + 65536))

ROOT_UUID=fd800c6c-2fdb-4502-82cb-e61f66b9a221

SYSTEM=/dev/sdc

echo DESTOROY ${SYSTEM} ?!?!? read

for i in ${SYSTEM}[1-9]; do umount $i || true; done dd if=/dev/zero of=${SYSTEM} bs=1M count=$(( $ROOTFS_START / 2 / 1024 + 1)) conv=sync partprobe

echo PARTITIONS

parted -s ${SYSTEM} mklabel gpt parted -s ${SYSTEM} unit s mkpart uboot ${UBOOT_START} $(( ${TRUST_START} - 1)) parted -s ${SYSTEM} unit s mkpart trust ${TRUST_START} $(( ${BOOT_START} - 1)) parted -s ${SYSTEM} unit s mkpart boot ${BOOT_START} $(( ${ROOTFS_START} - 1)) parted -s ${SYSTEM} set 3 boot on parted -s ${SYSTEM} unit s mkpart rootfs ${ROOTFS_START} $(( ${USERDATA_START} - 1)) parted -s ${SYSTEM} unit s mkpart userdata ${USERDATA_START} $(( ${SDCARD_START} - 1)) parted -s ${SYSTEM} -- unit s mkpart sdcard ${SDCARD_START} -64s partprobe

gdisk ${SYSTEM} <<EOF x c 4 ${ROOT_UUID} w y EOF

echo IMAGES

OMG, in some rockchip scripts, what is this:

dd if=${RKBIN}/bin/rk31/rk3128_ddr_300MHz_v2.12.bin of=DDRTEMP bs=4 skip=1

${UBOOT}/tools/mkimage -n rk3128 -T rksd -d DDRTEMP idbloader.img

${UBOOT}/tools/mkimage -n rk3128 -T rksd -d ${RKBIN}/bin/rk31/rk3128_ddr_300MHz_v2.12.bin idbloader.img cat ${RKBIN}/bin/rk31/rk3128x_miniloader_v2.57.bin >> idbloader.img

8192s -> 4MB -> 4 copies

${UBOOT}/tools/loaderimage --pack --uboot ${UBOOT}/u-boot-dtb.bin uboot.img --size 1024 4 ${UBOOT}/tools/loaderimage --pack --trustos ${RKBIN}/bin/rk31/rk3126_tee_ta_v2.01.bin trust.img --size 1024 4

echo COPY

dd if=idbloader.img of=${SYSTEM} seek=${LOADER1_START} conv=notrunc,sync dd if=uboot.img of=${SYSTEM} seek=${UBOOT_START} conv=notrunc,sync dd if=trust.img of=${SYSTEM} seek=${TRUST_START} conv=notrunc,sync

${LINUX}/scripts/bmpconvert logo_uboot.bmp ${LINUX}/scripts/bmpconvert logo_kernel.bmp cp ${LINUX}/arch/arm/boot/dts/rk3128-wx8.dtb rk-kernel.dtb ${UBOOT}/tools/resource_tool rk-kernel.dtb logo_kernel.bmp logo_uboot.bmp logo_lowpower.bmp ${UBOOT}/scripts/mkbootimg --kernel ${LINUX}/arch/arm/boot/zImage --second resource.img --out boot.img dd if=boot.img of=${SYSTEM} conv=notrunc,sync seek=${BOOT_START}

dd if=rootfs.img of=${SYSTEM} conv=notrunc,sync seek=${ROOTFS_START}

mkfs.ext2 -F ${SYSTEM}5

mkfs.vfat ${SYSTEM}6 mount ${SYSTEM}6 /mnt tar xf sdcard.tar -C /mnt --no-same-owner umount /mnt

echo DONE


- bmp images must be "specially optimized" for rockchip - `${LINUX}/scripts/bmpconvert ...`
- packed with `rk-kernel.dtb` to ANDROID resource blob - `${UBOOT}/tools/resource_tool ...`
- and finally combined with zImage `${UBOOT}/scripts/mkbootimg ...`
- simply replaces EXT2FS
- bootargs can be placed to DTS/DTB - https://github.com/mcerveny/rockchip-linux/commit/f970198d335e96aba016abbd7d3835b9fbcb557c
- I also use different `PARTUUID` - `uuidgen` generated
- example of images - [bmp.zip](https://github.com/Ruka-CFW/rk3128-cfw/files/7157022/bmp.zip)
acmeplus commented 3 years ago
  • bmp images must be "specially optimized" for rockchip - ${LINUX}/scripts/bmpconvert ...
    • packed with rk-kernel.dtb to ANDROID resource blob - ${UBOOT}/tools/resource_tool ...
    • and finally combined with zImage ${UBOOT}/scripts/mkbootimg ...
    • simply replaces EXT2FS
    • bootargs can be placed to DTS/DTB - mcerveny/rockchip-linux@f970198
    • I also use different PARTUUID - uuidgen generated
    • example of images - bmp.zip

Excellent progress @mcerveny . I've seen the bootargs commit, and the comments there. I observe a similar thing:

mcerveny commented 3 years ago
* Display starts with about 20% displaced to the right

I found and resolve problem with logo corruption (but not in random error of IRQ). Resolved with undocumented setting to "1" - see https://github.com/mcerveny/rockchip-linux/commit/29624eeea5bb2b1463331b17b7c33f0605ca706c .

You can remove&free drm-logo and test&reset display also with modetest -M rockchip -s 62@59:960x544-59 (also with Waylant/Weston start ...). Test your images with fbv -i /usr/local/share/ruka/img/no_sdcard_ps5k.png ? Does not work without allocated FB before ?

acmeplus commented 3 years ago
* Display starts with about 20% displaced to the right

I found and resolve problem with logo corruption (but not in random error of IRQ). Resolved with undocumented setting to "1" - see mcerveny/rockchip-linux@29624ee .

Looking good. I have full sd image that boots almost the same as the original internal flashed image.

Some notes:

Questions:

mcerveny commented 3 years ago
* Do you think we could move to a higher kernel version? or are the RockChip changes too specific into version 4.4 and will they require tons of porting to get to a higher version?

Probably not (actual kernel versions for reference) :

I do not known why Rockckip stoped to support its old chips. Rockchip is supporting only new chips including rk3326 (handhelds Odroid-Go, RGB10, RGB20, RG351 ... but 2x price increase and no HDMI output). I try to switch/use/prefer Allwinner chips/bords in all other projects with much better support from community.

* Main reason to move to a higher version would be to try to use the open source mesa-LIMA drivers instead of the closed source MALI blobs

Lima was upstreamed in Mesa 19.1 and Linux kernel 5.2. So impossible.

mcerveny commented 3 years ago

More findings with PCB measurment: 'enable' enables 3x DC/DC boost supply from battery voltage (~3-4V) to 5V and also -3.2V and 4.8V. It is required for backlight (see earlier posts) and now preenabled in u-boot.

echo 93 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio93/direction
# boosters 5V,-3.2V,4.8V on
echo 1 > /sys/class/gpio/gpio93/value
# boosters off
echo 0 > /sys/class/gpio/gpio93/value

Backlight PWM0 does not have any impact (probably totally irrelevant for DSI/MIPI display (probably running at maximum backlight power) but maybe relevant for unconnected/unpopulated RGB display).

# ### test irrelevant changes
# cat /sys/devices/platform/backlight/backlight/backlight/brightness
# echo 0 >  /sys/devices/platform/backlight/backlight/backlight/brightness
# echo 255 > /sys/devices/platform/backlight/backlight/backlight/brightness
# ### see also "platform/20050000.pwm"
# cat /sys/kernel/debug/pwm

If you have connected USB power (OTG connector), the host USB connector works. If you disconnect USB power, the 5V voltage must be provided from 5V DC/DC boost and enabled with GPIO 41 ("1" to enable) and disable loop back to vcc_sys with GPIO 117 ("1" to disable). (My buildroot is extended by BR2_PACKAGE_IW, BR2_PACKAGE_WPA_SUPPLICANT, BR2_PACKAGE_DHCPCD, BR2_PACKAGE_FPING ..., my kernel has CONFIG_RTL8XXXU, CONFIG_RTL8XXXU_UNTESTED ... and firmware is added to rootfs /lib/firmware/rtlwifi/rtl8192cufw_TMSC.bin..)

# ### disconnect USB power
# ### enable boosters
# echo 93 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio93/direction
# echo 1 > /sys/class/gpio/gpio93/value
# ### disable from USB to VCC_SYS
# echo 117 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio117/direction
# echo 1 > /sys/class/gpio/gpio117/value
# ### enable 5V to both USB connectors
# echo 41 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio41/direction
# echo 1 > /sys/class/gpio/gpio41/value
# ### now have USB devices - RTL8188CUS 802.11n WLAN Adapter over USB-micro-B-plug - USB-A-receptacle converter
# lsusb
Bus 002 Device 002: ID 0bda:8176
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 003 Device 001: ID 1d6b:0001
# iw dev
phy#0
    Interface wlan0
        ifindex 2
        wdev 0x1
        addr 00:13:ef:f5:1e:b6
        type managed
        txpower 20.00 dBm
# ip link set wlan0 up
# iw dev wlan0 scan
# wpa_supplicant -B -D nl80211 -i wlan0 -c /sdcard/wpa_supplicant.conf
# ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq qlen 1000
    link/ether 00:13:ef:f5:1e:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.245/24 brd 192.168.2.255 scope global wlan0
       valid_lft forever preferred_lft forever
# ping -c2 www.github.com
PING www.github.com (140.82.121.3): 56 data bytes
64 bytes from 140.82.121.3: seq=0 ttl=52 time=18.058 ms
64 bytes from 140.82.121.3: seq=1 ttl=52 time=17.877 ms

--- www.github.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 17.877/17.967/18.058 ms
mcerveny commented 3 years ago

L3/R3 buttons are HW unconnected as expected (updates issue #55). I corrected both L3/R3 PCB paths (2x solder bridges and one 56kΩ pull-up) and now I have working L3/R3 - https://github.com/mcerveny/rockchip-linux/commit/a343afcf5cf8e3f3547cef99cdc40086272bc6e0.

# evtest /dev/input/event1 
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 19 (KEY_R)
    Event code 21 (KEY_Y)
    Event code 28 (KEY_ENTER)
    Event code 30 (KEY_A)
    Event code 32 (KEY_D)
    Event code 33 (KEY_F)
    Event code 38 (KEY_L)
    Event code 44 (KEY_Z)
    Event code 45 (KEY_X)
    Event code 46 (KEY_C)
    Event code 48 (KEY_B)
    Event code 54 (KEY_RIGHTSHIFT)
    Event code 103 (KEY_UP)
    Event code 105 (KEY_LEFT)
    Event code 106 (KEY_RIGHT)
    Event code 108 (KEY_DOWN)
    Event code 114 (KEY_VOLUMEDOWN)
    Event code 115 (KEY_VOLUMEUP)
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 49.130261, type 1 (EV_KEY), code 32 (KEY_D), value 1
Event: time 49.130261, -------------- SYN_REPORT ------------
Event: time 49.270342, type 1 (EV_KEY), code 32 (KEY_D), value 0
Event: time 49.270342, -------------- SYN_REPORT ------------
Event: time 50.210223, type 1 (EV_KEY), code 33 (KEY_F), value 1
Event: time 50.210223, -------------- SYN_REPORT ------------
Event: time 50.390233, type 1 (EV_KEY), code 33 (KEY_F), value 0
Event: time 50.390233, -------------- SYN_REPORT ------------

HW mods (need external pullup 56kΩ resistor for R3 because GPIO0_D6 has only pulldown resistor): L3-R3-hwmod R3 L3

How to teardown PS5000 - https://www.youtube.com/watch?v=DVia_eR4l8k

acmeplus commented 3 years ago

@alpgarcia @mcerveny some updates:

WIP is in my branch

acmeplus commented 3 years ago

@mcerveny I forgot about this. While compiling your latest version of caesar-u-boot I see this problem:

common/built-in.o:(.data.init_sequence_r+0x48): undefined reference to `board_early_init_r'

Renaming that int rockchip_dnl_key_pressed(void) back to int board_early_init_r seems to fix compilation. I know you mentioned that you were working on the download but it was not working via sdcard.

mcerveny commented 3 years ago

@mcerveny I forgot about this. While compiling your latest version of caesar-u-boot I see this problem: common/built-in.o:(.data.init_sequence_r+0x48): undefined reference to `board_early_init_r'

Forget to update configs/wx8-rk3128_defconfig - https://github.com/mcerveny/caesar-u-boot/commit/634b85f106c0eb3d5167c989729b564253d60816

mcerveny commented 3 years ago

I found "mirrors" with updated rockchip kernels https://github.com/JeffyCN/mirrors/tree/kernel and https://github.com/JeffyCN/rockchip_mirrors/tree/kernel (check also other branches :-) ). There are +366 patches. So I make new kernel develop-4.4-updates branch (https://github.com/mcerveny/rockchip-linux/tree/develop-4.4-updates) and new branch wx8-updates with applied WIP (https://github.com/mcerveny/rockchip-linux/tree/wx8-updates) so you can try it too.

mcerveny commented 3 years ago
* Updated the buildroot uboot and kernel packages to use @mcerveny repos directly (@mcerveny let me know if you are ok with this or you would rather have us forking those)

Ok. I will make more WIP/testing in subbranch to avoid instability. Still missing some features and persists some problems:

acmeplus commented 3 years ago

@mcerveny @alpgarcia some updates regarding batocera build:

Notes:

After the build is complete, the full SD image is generated in the output/ps5000/images/batocera/images/ps5000 folder. Burn the image with dd or any other tool and test it.

Additional notes:

acmeplus commented 3 years ago

Update: