Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mcerveny opened this issue Aug 15, 2021 · 77 comments
Labels
PS5000 PS5000 console issue label
Milestone

Comments

@mcerveny
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

mcerveny commented Aug 17, 2021

Please simply clarify (ps5000 is WX8 board):

  • yes/no - there is pcb schema for this WX8_V01/ 20200930 board.
  • 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
  • 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

Very thanks, Martin

@alpgarcia
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

Duplicate #53

@acmeplus acmeplus added the PS5000 PS5000 console issue label label Aug 23, 2021
@acmeplus acmeplus added this to the 3.0 milestone Aug 23, 2021
@mcerveny
Copy link
Author

mcerveny commented Aug 30, 2021

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:

  • display does not work in my u-boot (all setup, even some testing MIPI-DSI commands works (MIPI_DCS_GET_PIXEL_FORMAT, MIPI_DCS_GET_DIAGNOSTIC_RESULT, MIPI_DCS_GET_POWER_MODE))
    • old driver rockchip,rk3128-mipi-dphy was removed from sources
    • new driver rockchip,rk3128-video-phy is multioutput capable (MIPI, LVDS, RGB)
      -> maybe new driver is untested and/or bad, maybe some unpublished initialization in "U-Boot 2017.09-gf468676-dirty (Jul 08 2021 - 10:53:40 +0800)"
  • there are many problems when the original kernel and rootfs is booted. Display is "white" or "color stripes" and dmesg shows crash stacks and errors about IRQ:
[    2.398056] irq 35: nobody cared (try booting with the "irqpoll" option)
[    2.398065] CPU: 0 PID: 85 Comm: vendor_storage_ Not tainted 4.4.159 #1047
[    2.398067] Hardware name: Generic DT based system
[    2.398099] [<c010dabc>] (unwind_backtrace) from [<c010a86c>] (show_stack+0x10/0x14)
[    2.398111] [<c010a86c>] (show_stack) from [<c032b8a8>] (dump_stack+0x7c/0x98)
[    2.398122] [<c032b8a8>] (dump_stack) from [<c01643c8>] (__report_bad_irq+0x24/0xc0)
[    2.398132] [<c01643c8>] (__report_bad_irq) from [<c01646b8>] (note_interrupt+0x190/0x28c)
[    2.398140] [<c01646b8>] (note_interrupt) from [<c0161fe4>] (handle_irq_event_percpu+0x50/0x128)
[    2.398149] [<c0161fe4>] (handle_irq_event_percpu) from [<c01620f4>] (handle_irq_event+0x38/0x5c)
[    2.398156] [<c01620f4>] (handle_irq_event) from [<c016524c>] (handle_fasteoi_irq+0xb0/0x124)
[    2.398165] [<c016524c>] (handle_fasteoi_irq) from [<c0161754>] (generic_handle_irq+0x18/0x28)
[    2.398172] [<c0161754>] (generic_handle_irq) from [<c0161a38>] (__handle_domain_irq+0xa0/0xb4)
[    2.398180] [<c0161a38>] (__handle_domain_irq) from [<c01013f8>] (gic_handle_irq+0x50/0x94)
[    2.398188] [<c01013f8>] (gic_handle_irq) from [<c010b194>] (__irq_svc+0x54/0x70)
[    2.398191] Exception stack(0xde7e3d40 to 0xde7e3d88)
[    2.398199] 3d40: 00000000 00208040 00000000 00000000 de7e2000 00000000 00000002 c0b3d940
[    2.398207] 3d60: 0000000a 00000034 c0b3f7c8 de7e3d90 00000000 de7e3d90 c011cca8 c01014a8
[    2.398211] 3d80: 60000113 ffffffff
[    2.398218] [<c010b194>] (__irq_svc) from [<c01014a8>] (__do_softirq+0x68/0x200)
[    2.398228] [<c01014a8>] (__do_softirq) from [<c011cca8>] (irq_exit+0x88/0xf4)
[    2.398236] [<c011cca8>] (irq_exit) from [<c0161a18>] (__handle_domain_irq+0x80/0xb4)
[    2.398243] [<c0161a18>] (__handle_domain_irq) from [<c01013f8>] (gic_handle_irq+0x50/0x94)
[    2.398250] [<c01013f8>] (gic_handle_irq) from [<c010b194>] (__irq_svc+0x54/0x70)
[    2.398253] Exception stack(0xde7e3e10 to 0xde7e3e58)
[    2.398259] 3e00:                                     00000000 de6f0e80 00000000 60000013
[    2.398266] 3e20: c0b3f7c8 c0b40108 00000000 00000000 c0b4888c 00000034 c0b3f7c8 c0b0a1ec
[    2.398272] 3e40: 0000000f de7e3e60 c015efe0 c0160744 60000013 ffffffff
[    2.398283] [<c010b194>] (__irq_svc) from [<c0160744>] (console_unlock+0x330/0x3ec)
[    2.398293] [<c0160744>] (console_unlock) from [<c0160b40>] (vprintk_emit+0x340/0x48c)
[    2.398302] [<c0160b40>] (vprintk_emit) from [<c0160da0>] (vprintk_default+0x1c/0x24)
[    2.398314] [<c0160da0>] (vprintk_default) from [<c01a60f0>] (printk+0x28/0x3c)
[    2.398327] [<c01a60f0>] (printk) from [<c0382a4c>] (vendor_init_thread+0x14/0x134)
[    2.398338] [<c0382a4c>] (vendor_init_thread) from [<c0131b44>] (kthread+0xf4/0x104)
[    2.398347] [<c0131b44>] (kthread) from [<c0106c28>] (ret_from_fork+0x14/0x2c)
[    2.398349] handlers:
[    2.398360] [<c03f327c>] vop_isr
[    2.398362] Disabling IRQ #35

and

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

-> kernel original dts/dtb and rockchip drivers are buggy (some rockchip,grf nodes missing... repaired but not better) and depends on some u-boot initialization, maybe some unpublished initialization

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:

  • you must use serial console (some usb<->serial convertor with 3.3V output attached to UART0 - pins are next to battery connector, 1mm unpopulated pinheader)
  • cu -l /dev/ttyUSB0 -s 115200 -f
  • do not forget to backup original uboot, switch to "LOADER" mode (hold select key and power up) and download uboot partition from device
# ./Linux_Upgrade_Tool_v1.65/upgrade_tool pl
Program Data in /space/ps5000/Linux_Upgrade_Tool_v1.65
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
# ./Linux_Upgrade_Tool_v1.65/upgrade_tool rl 0x00002000 0x00000800 uboot_backup.img
Program Data in /space/ps5000/Linux_Upgrade_Tool_v1.65
Read LBA from file 100%)
# ### verify "LOADER" tag
# dd if=uboot_backup.img bs=1 count=8 2>/dev/null
LOADER  
  • compile u-boot
$ export CHIP="rk3128"
$ export ARCH=arm
$ export CROSS_COMPILE=arm-linux-gnueabihf-
$ make wx8-rk3128_defconfig
...
$ make -j4
...
$ ls -l ls -l u-boot-dtb.bin
-rw-rw-r-- 1 martin martin 799197 Aug 31 08:21 u-boot-dtb.bin
  • pack and upload
# UBOOT=caesar-u-boot
# RKBIN=caesar-rkbin
# ### image is ~800kB and only ONE copy can fit 1MB uboot partition
# $UBOOT/tools/loaderimage --pack --uboot $UBOOT/u-boot-dtb.bin uboot.img --size 1024 1
# ### upload if in "loader" mode, BEAWARE "loader" mode key does not work after upgrade, you must stop new uboot with "CTRL-C" and enter to loader mode with u-boot command "=> rockusb 0 spinand 0"
# ./Linux_Upgrade_Tool_v1.65/upgrade_tool wl 0x00002000 uboot.img 
# ### reset device ... (also CTRL-C and "=> reset" or start kernel with "=> boot_android spinand 0"

@acmeplus
Copy link
Collaborator

acmeplus commented Sep 1, 2021

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
Copy link
Collaborator

acmeplus commented Sep 1, 2021

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
Copy link
Author

mcerveny commented Sep 1, 2021

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
Copy link
Author

mcerveny commented Sep 2, 2021

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

@acmeplus
Copy link
Collaborator

acmeplus commented Sep 2, 2021

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
Copy link
Author

mcerveny commented Sep 3, 2021

"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
Copy link
Contributor

@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
Copy link
Author

mcerveny commented Sep 3, 2021

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
Copy link
Author

mcerveny commented Sep 5, 2021

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

  • build sources are in wx8 branch. export ARCH=arm; export CROSS_COMPILE=arm-linux-gnueabihf-; make wx8_defconfig; make -j4
  • display starts only if the previous hint* was applied
  • not all keys works (only push keys), not volume keys (missing driver compatible = "gpio-keys-volume") and not joysticks
  • audio works (hdmi audio untested)
  • hdmi output does not work well (without hint* even edid does not work)
  • battery measurement does not work (missing driver compatible = "rk30-adc-battery")
  • there is also unknown I2C chip (cleaned identification marks, I2C address 0x4c, missing driver compatible = "i2c0") that may be root cause of all problems that probably do something with power DCDC convertors.
  • I tried music/video/pic and start one GBA game (but not react to keys, probably bad configs to retroarch) after hint*
  • I rebuild sdcard to distroboot (standard ext2 partition with extlinux/extlinux.conf)

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
Copy link
Collaborator

acmeplus commented Sep 7, 2021

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

  • I have been following a similar process as your hint, basically soft-reboot but not from the console but the adb shell. End result is the same, but your steps seem to suggest you get a prompt back via UART.
  • 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
  • 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)
  • 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.
  • 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.

I'll do some additional tests this week.

@mcerveny
Copy link
Author

mcerveny commented Sep 7, 2021

* 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
Copy link
Collaborator

acmeplus commented Sep 8, 2021

* 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
Copy link
Author

mcerveny commented Sep 8, 2021

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 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

@acmeplus
Copy link
Collaborator

acmeplus commented Sep 8, 2021

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
Copy link
Author

mcerveny commented Sep 8, 2021

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
Copy link
Collaborator

acmeplus commented Sep 8, 2021

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.

@acmeplus
Copy link
Collaborator

acmeplus commented Sep 22, 2021

Update:

  • Audio "working" after adding dedicated overlay. Still no mixer controls, although volume controls work during boot (splash screen volume can be modified via volume keys)
  • Pipewire still having issues:
Starting pipewire: Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Connection failure: Connection refused
Connection failure: Connection refused
Connection failure: Connection refused
[E][00263.841696][  pulse-server.c:  539 do_set_client_name()] pulse-server 0x1fea110: failed to connect client: Host is down
[W][00263.848143][         reply.c:   72 reply_error()] client 0x1ffc7c0 [pactl]: ERROR command:9 (SET_CLIENT_NAME) tag:1 error:6 (Host is down)
  • Slow/idle boot
  • Switched to Mali wayland and did an experimental build:
    • Performance seems a bit better, mostly on video playback during the splash video boot, and during the ES video preview display.
    • Wayland build requires some additional patching due to no X11 mode. CFLAG EGL_NO_X11 needs to be added properly
  • Updated kernel board/batocera/rockchip/ps5000/linux-defconfig-fragment.config to include RTL wifi support as per Martin's previous comment

@mcerveny
Copy link
Author

I added first try of battery mgmt driver (branch https://github.com/mcerveny/rockchip-linux/tree/wip-chgr, commit mcerveny/rockchip-linux@db0a5e5). Because I lost my TP4056 during HW measurement I must replace chip to continue. So the driver is incomplete for now.
To test driver, charging:

# grep '' /sys/class/power_supply/*/*
/sys/class/power_supply/battery/capacity:60
/sys/class/power_supply/battery/charge_full:3000000
/sys/class/power_supply/battery/health:Good
/sys/class/power_supply/battery/present:1
/sys/class/power_supply/battery/status:Not charging               # <------ should be charging with TP4056
/sys/class/power_supply/battery/technology:Li-ion
/sys/class/power_supply/battery/type:Battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_NAME=battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_STATUS=Not charging
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_NOW=3860000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_PRESENT=1
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_HEALTH=Good
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CAPACITY=60
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_FULL=3000000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_MAX_DESIGN=4205000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3400000
/sys/class/power_supply/battery/voltage_max_design:4205000
/sys/class/power_supply/battery/voltage_min_design:3400000
/sys/class/power_supply/battery/voltage_now:3860000
/sys/class/power_supply/usb/online:1
/sys/class/power_supply/usb/type:USB
/sys/class/power_supply/usb/uevent:POWER_SUPPLY_NAME=usb
/sys/class/power_supply/usb/uevent:POWER_SUPPLY_ONLINE=1

Discharging:

/sys/class/power_supply/battery/capacity:51
/sys/class/power_supply/battery/charge_full:3000000
/sys/class/power_supply/battery/health:Good
/sys/class/power_supply/battery/present:1
/sys/class/power_supply/battery/status:Discharging
/sys/class/power_supply/battery/technology:Li-ion
/sys/class/power_supply/battery/type:Battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_NAME=battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_STATUS=Discharging
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_NOW=3796000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_PRESENT=1
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_HEALTH=Good
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CAPACITY=51
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_FULL=3000000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_MAX_DESIGN=4205000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3400000
/sys/class/power_supply/battery/voltage_max_design:4205000
/sys/class/power_supply/battery/voltage_min_design:3400000
/sys/class/power_supply/battery/voltage_now:3796000
/sys/class/power_supply/usb/online:0
/sys/class/power_supply/usb/type:USB
/sys/class/power_supply/usb/uevent:POWER_SUPPLY_NAME=usb
/sys/class/power_supply/usb/uevent:POWER_SUPPLY_ONLINE=0

@acmeplus
Copy link
Collaborator

To test driver, charging:

Very good, battery status is now displayed on supporting apps (e.g. EmulationStation and Retroarch).

Battery status charging shows 64 out of a total CAPACITY of 64, but applications show the actual value instead of the percentage (e.g. 64% instead of 100%). Removed power supply and status shows 99% (as opposed to 100%). I assume that's consistent since you indicate the driver is incomplete.

Let me know if you need me to test anything else.

@mcerveny
Copy link
Author

mcerveny commented Sep 28, 2021

Updated charger+battery+powerswitch mcerveny/rockchip-linux@2147595. Due to HW design faults it is not perfect.

Open questions:

  • Is it OK/tested ? If yes I will merge this sub-branch to https://github.com/mcerveny/rockchip-linux/tree/wx8.
  • Is "low-battery" handled in RetroArch or EmulationStation ... ?
  • Can anyone "calibrate" battery charge/discharge values (volts to percent) ?
  • Can powersave be hooked in RetroArch or EmulationStation ... ?
    • shutdown/startup "DCDC boosters" with GPIO 93 over /sys/class/gpio/* ?
    • or can I try to extend this driver to hook FB events (blank/unblank) ?
  • wx8-joysticks default to analog or to key emulation (echo 1 > /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type) ?
  • keys mapping as-is or should be used "GAMEPAD" buttons ?
#define BTN_GAMEPAD		0x130
#define BTN_SOUTH		0x130
#define BTN_A			BTN_SOUTH
#define BTN_EAST		0x131
#define BTN_B			BTN_EAST
#define BTN_C			0x132
#define BTN_NORTH		0x133
#define BTN_X			BTN_NORTH
#define BTN_WEST		0x134
#define BTN_Y			BTN_WEST
#define BTN_Z			0x135
#define BTN_TL			0x136
#define BTN_TR			0x137
#define BTN_TL2			0x138
#define BTN_TR2			0x139
#define BTN_SELECT		0x13a
#define BTN_START		0x13b
#define BTN_MODE		0x13c
#define BTN_THUMBL		0x13d
#define BTN_THUMBR		0x13e

#define BTN_DPAD_UP		0x220
#define BTN_DPAD_DOWN		0x221
#define BTN_DPAD_LEFT		0x222
#define BTN_DPAD_RIGHT		0x223

PS: Drivers "wx8joy" and "wx8-charger" and DTB "rk3128-wx8.dtb" (kernel and uboot) are tested with WX8 board only. I do not own Powkiddy A12/A13 or other similar rk3128 based handhelds.
WX8 board is in PS5000/Q500, LINTIAN LT-8203, Powkiddy X20, PS7000/Q900 (some versions (2021?) with 7" display) and any other similar handhelds ...

@acmeplus
Copy link
Collaborator

acmeplus commented Oct 1, 2021

Open questions:

I've done some tests and it looks good. I've not seen any regressions compared with wx8, and the additional fixes you have included improve the system.

One thing we have noticed is that there is no headphone plug event. It's probably something that can be added to the DTS but I'm not sure if that's one of those things that are missing/not available.

  • Is "low-battery" handled in RetroArch or EmulationStation ... ?

Need to leave the system running to get to a low battery state. I believe ES has a low battery warning, not sure about RetroArch.

  • Can anyone "calibrate" battery charge/discharge values (volts to percent) ?

We will try to find someone to do this task.

  • Can powersave be hooked in RetroArch or EmulationStation ... ?

Need to check that. I believe RetroPie has a power save method but it's handled at the board level, not at the Frontend/Emulator level.

  • shutdown/startup "DCDC boosters" with GPIO 93 over /sys/class/gpio/* ?
  • or can I try to extend this driver to hook FB events (blank/unblank) ?

You are the expert there. Either method seems logical, but I'm not sure about the implications in terms of performance.

  • wx8-joysticks default to analog or to key emulation (echo 1 > /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type) ?

Default analogue mode is preferred. RA passes that configuration directly to some emulators like flycast or ppsspp that can use analogue controls directly.

  • keys mapping as-is or should be used "GAMEPAD" buttons ?
#define BTN_GAMEPAD		0x130
#define BTN_SOUTH		0x130
#define BTN_A			BTN_SOUTH
#define BTN_EAST		0x131
#define BTN_B			BTN_EAST
#define BTN_C			0x132
#define BTN_NORTH		0x133
#define BTN_X			BTN_NORTH
#define BTN_WEST		0x134
#define BTN_Y			BTN_WEST
#define BTN_Z			0x135
#define BTN_TL			0x136
#define BTN_TR			0x137
#define BTN_TL2			0x138
#define BTN_TR2			0x139
#define BTN_SELECT		0x13a
#define BTN_START		0x13b
#define BTN_MODE		0x13c
#define BTN_THUMBL		0x13d
#define BTN_THUMBR		0x13e

#define BTN_DPAD_UP		0x220
#define BTN_DPAD_DOWN		0x221
#define BTN_DPAD_LEFT		0x222
#define BTN_DPAD_RIGHT		0x223

Those make sense to me. Some observations about the mappings:

  • Volume keys cannot be mapped in RA (or other emulators like PPSSPP). Not an issue since the keys are managed at system level with either input-event-daemon or thd (in batocera).
  • As I mentioned before, the OFW had an event mapped when you plugged/unplugged the headphone jack (I believe it was mapped to the codec_hp_det) . There's no suck an event here.

@acmeplus
Copy link
Collaborator

acmeplus commented Oct 1, 2021

PS: Drivers "wx8joy" and "wx8-charger" and DTB "rk3128-wx8.dtb" (kernel and uboot) are tested with WX8 board only. I do not own Powkiddy A12/A13 or other similar rk3128 based handhelds. WX8 board is in PS5000/Q500, LINTIAN LT-8203, Powkiddy X20, PS7000/Q900 (some versions (2021?) with 7" display) and any other similar handhelds ...

I've tried to modify the DTS to get the A12 to boot. Some comments in case you may give us some hints:

  • The wx8joy is not required and I have disabled it because neither the A12 or A13 have any analogue joystick, they only have digital joystick + 6 keys + FN keys. All seem to work fine.
  • I've not tested the battery/power driver yet but will give it a try.
  • Main issue is to get the display working. Screen is LVDS, it gets properly detected (after modifying the panel@0 and disaply-timings to match those of the display, but it basically stays off. I can see the backlight turning on and off depending on whether a graphical application is being launched, but there's nothing in the display. I can provide some traces and extracted DTS if you believe you can help us finding out more about that.
  • USB works fine, Wifi works, Sound works.

For the PS7000, we don't have that board but we have backups of the firmware. Probably the same as X20 and X2. There's also the Q400 that seems to be similar too.

@mcerveny
Copy link
Author

mcerveny commented Oct 2, 2021

One thing we have noticed is that there is no headphone plug event. It's probably something that can be added to the DTS but I'm not sure if that's one of those things that are missing/not available.

Headphone event is working in "rockchip,rk3128-codec" (see sound/soc/codecs/rk312x_codec.c):

  • automatically detect HP plug (dedicated pin CODEC_HPDET on rk3128)
  • internal MONO audio amplifier (ANT8108 chip, internal speakers are connected parallely) is automatically muted when SPK is not used (GPIO 35 == GPIO1-3), test it with LRMonoPhase4.wav
# ### "lo" means that amplifier is disabled (shutdown)
# grep spk-ctl /sys/kernel/debug/gpio 
 gpio-35  (                    |spk-ctl             ) out lo    
  • headphones have STEREO output
  • events can be monitored by UDEV and programmed in /etc/udev/...
# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[1021.534397] change   /devices/virtual/switch/h2w (switch)
UDEV  [1021.592263] change   /devices/virtual/switch/h2w (switch)
KERNEL[1024.800785] change   /devices/virtual/switch/h2w (switch)
UDEV  [1024.846588] change   /devices/virtual/switch/h2w (switch)
  • status can be also monitored by /sys/...
# ### state:2 -> headtset plugged - BIT_HEADSET_NO_MIC 
# grep '' /sys/devices/virtual/switch/h2w/*
/sys/devices/virtual/switch/h2w/name:Headset
/sys/devices/virtual/switch/h2w/state:2
# grep '' /sys/devices/virtual/switch/h2w/*
/sys/devices/virtual/switch/h2w/name:Headset
/sys/devices/virtual/switch/h2w/state:0
  • automatically switch ALSA subsystem to "SPK", "HP", "SPK_HP" (actual code does not mute "SPK" if "HP" is present - "SPK_HP" is used)
# amixer 
Simple mixer control 'Playback Path',0
  Capabilities: enum
  Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT' 'SPK_HP' 'RING_SPK' 'RING_HP' 'RING_HP_NO_MIC' 'RING_SPK_HP'
  Item0: 'SPK'
Simple mixer control 'Capture MIC Path',0
  Capabilities: enum
  Items: 'MIC OFF' 'Main Mic' 'Hands Free Mic' 'BT Sco Mic'
  Item0: 'MIC OFF'
Simple mixer control 'Voice Call Path',0
  Capabilities: enum
  Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT'
  Item0: 'OFF'
# ### after plug headphone ... -> HP
# amixer 
Simple mixer control 'Playback Path',0
  Capabilities: enum
  Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT' 'SPK_HP' 'RING_SPK' 'RING_HP' 'RING_HP_NO_MIC' 'RING_SPK_HP'
  Item0: 'HP'
Simple mixer control 'Capture MIC Path',0
  Capabilities: enum
  Items: 'MIC OFF' 'Main Mic' 'Hands Free Mic' 'BT Sco Mic'
  Item0: 'MIC OFF'
Simple mixer control 'Voice Call Path',0
  Capabilities: enum
  Items: 'OFF' 'RCV' 'SPK' 'HP' 'HP_NO_MIC' 'BT'
  Item0: 'OFF'

So what are you missing ?

@mcerveny
Copy link
Author

mcerveny commented Oct 2, 2021

  • wx8-joysticks default to analog or to key emulation (echo 1 > /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_type) ?

Default analogue mode is preferred. RA passes that configuration directly to some emulators like flycast or ppsspp that can use analogue controls directly.

  • keys mapping as-is or should be used "GAMEPAD" buttons ?

Those make sense to me.

Done, new branch https://github.com/mcerveny/rockchip-linux/tree/wip-wx8-keys (also updated base kernel from mirror) with commit mcerveny/rockchip-linux@569fa28.
All mappings to emulators must be redefined, also "BTN_EAST" is "BTN_B" on "original gamepad" but "BTN_A" on "cloned gamepad". Default names are east/west/north/south. Swapped button A-B-X-Y colors and positions probably due to "copyright" reason.

I will merge this to wx8 (and wx8-updates) branch after update emulators mappings. Is it even possible ? I did not decode this possibility in code only "std keyboard mapping" (like https://docs.libretro.com/guides/input-and-controls/).

Update: New configurable version of keys/joystick/keys-emulation is in new branch https://github.com/mcerveny/rockchip-linux/tree/ps7000 commit mcerveny/rockchip-linux@5d6c510.

@acmeplus
Copy link
Collaborator

acmeplus commented Oct 2, 2021

So what are you missing ?

Nevermind @mcerveny. It's just an issue with missing udev rules as well as the other arm-headphone scripts that were present in the modified ruka but not on the batocera rootfs. Sorry to waste your time.

I'll add the missing pieces to the batocera fsoverlay and it should work as it used to do on the OFW or ruka FW.

@mcerveny
Copy link
Author

mcerveny commented Oct 3, 2021

* hdmi EDID problem tracing

EDID is generally OK. EEPROM and HPD is powered (~5V) from USB or from DCDC booster (no additional GPIO switches needed). The problem is only in one situation if DSI connector is set to disconnected then HDMI lost IRQ/timeout (including I2C EDID) (HDMI works normally) and error is shown innohdmi-rockchip 20034000.hdmi: failed to get edid but EDID is already cached. So do not set disconnected but set DSI connector to DPMS off state. Problem is somewhere in rk3128 chip or in some settings (maybe dclk_vop clock). I checked HDMI code path and corresponds to datasheet steps to get EDID,
Example to generate error:

# ### off -> disable connecor
# echo off > /sys/class/drm/card0-DSI-1/status
# echo off > /sys/class/drm/card0-HDMI-A-1/status
# echo on > /sys/class/drm/card0-HDMI-A-1/status
# dmesg | grep edid 
[ 2540.495405] innohdmi-rockchip 20034000.hdmi: failed to get edid
# modetest -c | grep ^6
62	0	disconnected	DSI-1          	0x0		0	61
64	63	connected	HDMI-A-1       	340x190		13	63

HDMI audio works OK.

# cat /sys/class/drm/card0-HDMI-A-1/audioformat 
LPCM,
# ### play to HDMI
# aplay --device plughw:CARD=0,DEV=1 /sdcard/LRMonoPhase4.wav 
# ### play to internal
# aplay --device plughw:CARD=0,DEV=0 /sdcard/LRMonoPhase4.wav 

@mcerveny mcerveny changed the title PS5000 factory updated PS5000 factory updated -> 4.4 kernel opensource rebuild Oct 4, 2021
@mcerveny mcerveny changed the title PS5000 factory updated -> 4.4 kernel opensource rebuild PS5000 factory updated -> rockchip uboot + 4.4 rockchip kernel opensource rebuild Oct 4, 2021
@acmeplus
Copy link
Collaborator

acmeplus commented Oct 4, 2021

* hdmi EDID problem tracing

EDID is generally OK. EEPROM and HPD is powered (~5V) from USB or from DCDC booster (no additional GPIO switches needed). The problem is only in one situation if DSI connector is set to disconnected then HDMI lost IRQ/timeout (including I2C EDID) (HDMI works normally) and error is shown innohdmi-rockchip 20034000.hdmi: failed to get edid but EDID is already cached. So do not set disconnected but set DSI connector to DPMS off state. Problem is somewhere in rk3128 chip or in some settings (maybe dclk_vop clock). I checked HDMI code path and corresponds to datasheet steps to get EDID,
Example to generate error:

# ### off -> disable connecor
# echo off > /sys/class/drm/card0-DSI-1/status
# echo off > /sys/class/drm/card0-HDMI-A-1/status
# echo on > /sys/class/drm/card0-HDMI-A-1/status
# dmesg | grep edid 
[ 2540.495405] innohdmi-rockchip 20034000.hdmi: failed to get edid
# modetest -c | grep ^6
62	0	disconnected	DSI-1          	0x0		0	61
64	63	connected	HDMI-A-1       	340x190		13	63

I did some experiments with the batocera build with HDMI and I can confirm that behavior. HDMI behavior seems consistent and the method of turning off DSI, turning off HDMI, turning on HDMI enables the HDMI display correctly.

@mcerveny
Copy link
Author

mcerveny commented Oct 12, 2021

* Can anyone "calibrate" battery charge/discharge values (volts to percent) ?

I done time-based battery calibration. Updated to "wx8" and "wx8-updates" branches mcerveny/rockchip-linux@026c5f3 + mcerveny/rockchip-linux@95eae0f.
Maximum power draw (to empty battery):

  • < 1.3A when running & charging
  • < 0.9A charging only (poweroff by switch)

Discharge:
discharge
Discharge script:

echo performance > /sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/governor 
echo performance > /sys/devices/platform/dmc/devfreq/dmc/governor
echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor


while true; do
	weston-simple-egl > /dev/null &
	
	sleep 30

	date
	
	grep '' \
	 /sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/cur_freq \
	 /sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/load \
	 /sys/devices/platform/dmc/devfreq/dmc/cur_freq \
	 /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq \
	 /sys/class/thermal/thermal_zone0/temp \
	 /sys/class/power_supply/battery/voltage_now \
	 /sys/class/power_supply/battery/capacity \
	 /proc/loadavg

	 sleep 30
	 
	 killall weston-simple-egl
done


echo simple_ondemand > /sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/governor 
echo dmc_ondemand > /sys/devices/platform/dmc/devfreq/dmc/governor
echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor

One measure like:

Thu Jan  1 01:15:14 UTC 1970
/sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/cur_freq:480000000
/sys/devices/platform/10091000.gpu/devfreq/10091000.gpu/load:0@480000000Hz
/sys/devices/platform/dmc/devfreq/dmc/cur_freq:456000000
/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq:1200000
/sys/class/thermal/thermal_zone0/temp:65076
/sys/class/power_supply/battery/voltage_now:4144000
/sys/class/power_supply/battery/capacity:96
/proc/loadavg:2.06 1.99 1.38 3/105 382

Charge:
charge

@alpgarcia
Copy link
Contributor

@mcerveny, @acmeplus, one thing I noticed is now the sound always outputs both by the speaker and the headphones, no matter the playback path you set (either manually or via udev change event).

With the closed source kernel + uboot it works as expected. Any idea on where the problem could be?

@mcerveny
Copy link
Author

Expected - see my test #51 (comment).
ALSA and Rockchip driver is total chaos but there is possible solution (probably in udev script (https://github.com/rockchip-linux/kernel/blob/82c9666cb6fe999eb61f23c2c9d0d5dad7332fb6/sound/soc/codecs/rk312x_codec.c#L2023)):

# ### 1) test state:2 -> headtset plugged - BIT_HEADSET_NO_MIC 
# grep '' /sys/devices/virtual/switch/h2w/*
/sys/devices/virtual/switch/h2w/name:Headset
/sys/devices/virtual/switch/h2w/state:2`
# ### 2 - yes) disable speaker amplifier manually
# echo d > /sys/codec-spk-ctl/spk-ctl
# ### 2 - no) enable speaker amplifier manually
# echo e >  /sys/codec-spk-ctl/spk-ctl

Maybe another solution - rk312x_for_mid = <1>; in DTS but it does not work for me (https://github.com/rockchip-linux/kernel/blob/82c9666cb6fe999eb61f23c2c9d0d5dad7332fb6/sound/soc/codecs/rk312x_codec.c#L1561).

PS: I received PS7000 with wx8 board (manufactured >=12/2020) and begin to modify DTS, Display is RGB (24bit, mode clock 51200 kHz,H: 1024 1184 1204 1344, V: 0600 0612 0615 0635).
ps7000

@acmeplus
Copy link
Collaborator

PS: I received PS7000 with wx8 board (manufactured >=12/2020) and begin to modify DTS, Display is RGB (24bit, mode clock 51200 kHz,H: 1024 1184 1204 1344, V: 0600 0612 0615 0635).

Very nice @mcerveny. That will help us to figure out the display issues on the A12/A13. Everything else on the A12/A13 seems to be working with the same firmware.

@mcerveny
Copy link
Author

mcerveny commented Nov 2, 2021

PS7000 & PS5000 are now supported.
UBOOT is updated in ps7000 branch https://github.com/mcerveny/caesar-u-boot/tree/ps7000 - patch mcerveny/caesar-u-boot@e20e9d8. There are two configurations - ps5000-rk3128_defconfig or ps7000-rk3128_defconfig.
KERNEL is updated in ps7000 branch https://github.com/mcerveny/rockchip-linux/tree/ps7000 - patch mcerveny/rockchip-linux@75be5fa. Configuration remains wx8_defconfig but there are specific dtb for boards - rk3128-ps5000.dtb or rk3128-ps7000.dtb.

@ftirador
Copy link
Collaborator

ftirador commented Nov 3, 2021

PS7000 & PS5000 are now supported.
UBOOT is updated in ps7000 branch https://github.com/mcerveny/caesar-u-boot/tree/ps7000 - patch mcerveny/caesar-u-boot@e20e9d8. There are two configurations - ps5000-rk3128_defconfig or ps7000-rk3128_defconfig.
KERNEL is updated in ps7000 branch https://github.com/mcerveny/rockchip-linux/tree/ps7000 - patch mcerveny/rockchip-linux@75be5fa. Configuration remains wx8_defconfig but there are specific dtb for boards - rk3128-ps5000.dtb or rk3128-ps7000.dtb.

Very nice progress!!! I can wait to promote to alpha and test something!!! There are so many folks that will appreciate that :)

@mcerveny
Copy link
Author

mcerveny commented Nov 6, 2021

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).

PS7000 (parallel RGB display) backlight PWM is supported !
The default brightness is 200 - https://github.com/mcerveny/rockchip-linux/blob/ps7000/arch/arm/boot/dts/rk3128-ps7000.dts#L15

# cat /sys/devices/platform/backlight/backlight/backlight/brightness
200
# ### turn off
# echo 0 >  /sys/devices/platform/backlight/backlight/backlight/brightness
# ### full brightness (full backlight LED power)
# echo 255 > /sys/devices/platform/backlight/backlight/backlight/brightness

@mcerveny
Copy link
Author

mcerveny commented Nov 7, 2021

wx7 board (used in PS7000/Q900 <12/2020, ...) seems to be nearly same to wx8 (used in PS7000 >=12/2020, PS5000...):

  • probably MIPI/DSI missing
  • only one USB (usb-c connector) (wx8 2x micro-usb)
  • only 256MB RAM (wx8 512MB RAM)
  • GB2 == rk3128

Did someone try to replace tragic non IPS display in PS7000 with IPS display ?
One year passed expecting wx9 variant :-)

ps7000_wx7
ps7000_wx7_1

@acmeplus
Copy link
Collaborator

acmeplus commented Nov 7, 2021

Did someone try to replace tragic non IPS display in PS7000 with IPS display ?

@mcerveny according to @fakemaria a user in one of the forums replaced that screen with this IPS one:

https://a.aliexpress.com/_uQ8lOi

@mcerveny
Copy link
Author

mcerveny commented Nov 15, 2021

PS7000 & PS5000 are now supported.

I corrected keys, analog joysticks and joystick key emulation (echo 1 > /sys/devices/platform/20072000.i2c/i2c-0/0-004c/key_emulation) for different side PCBs in PS5000/PS7000. All keys/joysticks/emulated keys configurations are in DTB now. Driver was renamed to wx8-joysticks.
See commit mcerveny/rockchip-linux@5d6c510 in branch https://github.com/mcerveny/rockchip-linux/tree/ps7000.
There is also updated kernel (from jeffycn) for testing https://github.com/mcerveny/rockchip-linux/tree/ps7000-updates.

Not feedback for joystick driver:

  • need to normalize values to 0-255 (raw ADC values are ~95-~225 middle ~165, uncertainty +-5)?
  • need to assign minimum to left (or right) and top (or bottom) or it is configurable somewhere in retroarch config ?

@alpgarcia
Copy link
Contributor

Not feedback for joystick driver:

  • need to normalize values to 0-255 (raw ADC values are ~95-~225 middle ~165, uncertainty +-5)?
  • need to assign minimum to left (or right) and top (or bottom) or it is configurable somewhere in retroarch config ?

In Retroarch you can set a deadzone vía Settings -> Input -> Analog deadzone. Not sure if that's what you're looking for.

@alpgarcia
Copy link
Contributor

I've been adding support for the Powkiddy A13 console. It is worth noting a12 and a13 has different hardware revisions, including different displays with different resolutions. Mine for instance is what we called rev B (1024x600). I guess we should add a section in the wiki to describe what we know is different on each model.

Said that, this is my first time touching the device tree, so big disclaimer here, help and advice more than welcome. I forked @mcerveny's repos and added some changes to uboot on https://github.com/alpgarcia/caesar-u-boot/tree/powkiddy-a13 (alpgarcia/caesar-u-boot@9724e7a) and to the kernel on https://github.com/alpgarcia/rockchip-linux/tree/powkiddy-a13 (alpgarcia/rockchip-linux@fcacd11). Of course my intention is sending PRs to the original repos when ready and use my forks for development purposes only.

I tried to not touch the dts hierarchy to keep my changes isolated for the moment. I created separate configs and dts files with the changes. In the case of the kernel I overwrote those definitions where I found some pins that were different from the already supported boards. I don't know what is the best way to add these changes, just tried to touch the minimum number of files possible at this point.

Some things I noticed:

  • Display: apart from the basic configuration, some pins needed to be changed because in these models it seems they are not used by the LCD but by the arcade joystick.
  • Arcade stick is configured via gpio-keys-polled. Using gpio-keys didn't work because some release events were
    lost (don't know why) causing drifting.
  • I disabled the analog joysticks support as these consoles don't have them.
  • Battery driver: there are two pins I'm not sure about, the ones used in other consoles are here part of the arcade stick. I checked the stock definition and found a mention to a driver called rk30_adc_battery that I remembered @mcerveny mentioned before as unknown driver. I looked for it and found the following repos, it says it's GPL, not sure where this kernel sources actually comes from. I didn't try to add it to the caesar version because of its dependencies and because I don't have the knowledge to decide whether that driver is worth to be added as it is or re-implemented.

The boot log still needs to be reviewed to find other errors in the definitions. Nevertheless, the screen and controls are working on my Powkiddy a13 without the drifting problems I mentioned above.

Please @mcerveny and @acmeplus let me know your thoughts and advices :)

@mcerveny
Copy link
Author

mcerveny commented Nov 28, 2021

Said that, this is my first time touching the device tree...

First you must get original DTB for u-boot (usually attached at the end of u-boot.bin) and kernel blobs (usually in android resource partition) and decompile with dts command to compare with yours (some hits dtc with -s (sort), decompile also new one and compare with meld or something like that). The board https://www.aliexpress.com/item/1005002674824010.html may use different PINs to charger circuit, PINs for usb power, PINs for audio power but also different PWMs for CPU, GPU and backlight power... It may be dangerous to use different DTB for different board.

gpio-keys didn't work

Weird. All pins are mapable via PIN bank virtual IRQ https://elixir.bootlin.com/linux/v4.4.293/source/drivers/pinctrl/pinctrl-rockchip.c#L1440

Battery driver

I was aware of this code but this code is incompatible (old). There is no DTS configs ...

@alpgarcia
Copy link
Contributor

It may be dangerous to use different DTB for different board.

I was comparing stuff manually (grep and friends) from the sources, I hadn't thought of decompiling the final dtb instead, thanks a lot for the hint!

Weird. All pins are mapable via PIN bank virtual IRQ https://elixir.bootlin.com/linux/v4.4.293/source/drivers/pinctrl/pinctrl-rockchip.c#L1440

They are, and the events work, but sometimes the release event is not detected. The log of evtest is like the following:

Event: time 1129.110245, type 1 (EV_KEY), code 545 (BTN_DPAD_DOWN), value 1
Event: time 1129.110245, -------------- SYN_REPORT ------------
Event: time 1139.990214, type 1 (EV_KEY), code 545 (BTN_DPAD_DOWN), value 0
Event: time 1139.990214, -------------- SYN_REPORT ------------

The second event (0) in this log happens after a second joystick movement, not after the initial one (it is an arcade stick with push buttons). The first movement only seems to generate the press event. And of course, this occurs "randomly", sometimes the release event is there, sometimes not, causing the drifting effect. I thought I might have missed some other wrong definition of those pins somewhere, but I guess there would be a message in the logs and the controller definition would be rolled back during boot.

@mcerveny
Copy link
Author

mcerveny commented Nov 28, 2021

linux,code = <BTN_DPAD_DOWN>;
gpios = <&gpio2 0x17 GPIO_ACTIVE_LOW>;
    arcade_stick: arcade-stick {
      rockchip,pins = <
...
           RK_GPIO2 0x17 0x00 &pcfg_pull_default

There is fixed pull up/down problem in RK3128 - see https://rockchip.fr/RK312X%20TRM/chapter-01-introduction.pdf

  • table is not filled up - page 19 (==48) "pullup/down" column
  • see schema "D" vs. "E" - page 36 (== 65)

I suppose that GPIO2_C7 (and GPIO2_C6, GPIO2_D0, GPIO2_D1) is pull down but on board is explicit pull up resistor. So pulled in both direction and due to some parasitic capacity the result does not work as expected (check original kernel DTB). Try to set "&pcfg_pull_none" to this pin. I had the same problem with R3.

@acmeplus
Copy link
Collaborator

Happy new year @mcerveny ! :)

@acmeplus
Copy link
Collaborator

acmeplus commented Mar 16, 2022

@mcerveny hope you are doing well. We have been updating the build and is now getting ready to get it to merge into the main batocera repo, the main branch is here and you can follow the conversation in this issue.

However, there are few issues that I don't understand:

  • It seems like frame buffer is not initialized by some fbdev only apps. It seems to work when SDL2 based apps start, but other fb only applications like fbv or mpv fail. Do you know what may be missing?
  • In general SDL2 apps seem to work fine, but KMSDRM based one perform poorly (can be observed by setting retroarch video_driver to gl). I wonder if I may be missing something in the drm initialization that I may have missed.
  • Back in the previous build we also had a poor performance with KMSDRM only that seemed to go away when we initialized Weston before and used Wayland instead.

Anyway, let me know if you have some ideas. You can find releases for ps5000, ps7000, etc. in the releases page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PS5000 PS5000 console issue label
Projects
None yet
Development

No branches or pull requests

4 participants