Lakka image for Banana Pi M1

Hello,

I wanted to share my build of Lakka for the Banana Pi M1.

The last version of Lakka to support the Banana Pi was 2.1-rc5. It is not available for download on Lakka’s website anymore, which is a shame because it ran great on the Banana Pi.

I fixed some of the packages so they can be compiled on a modern Ubuntu system, also updated Retroarch and the libretro cores to the current development version of Lakka.

Here is the image file:

Lakka 2.1 Banana Pi – Google Drive

If you need composite TV output, download the script.bin file from my folder and replace the one on the SD card with it.

If you need analog audio output:

cp /etc/asound.conf /storage/.config/asound.conf

now open this file and replace sunxisndhdmi with sunxicodec, then reboot.

I have also uploaded the updated Lakka source to the Google drive folder. This will allow you to create your own builds for the available devices in Lakka 2.1.

In case you’re wondering, why Lakka 2.1, isn’t that horribly outdated? Why not Lakka 2.3 or the newest dev version?

Lakka is currently in the process of switching from the outdated vendor-provided linux kernels to a modern generic linux kernel. The problem is that there is no sufficient driver support yet. There is no HDMI audio driver, and the graphics driver has changed to a new API (from fbdev to KMS/DRM) which runs horribly slow on many older devices. So while it is possible to build newer versions of Lakka for the Banana Pi, it makes very little sense at this point. Until the driver problems are solved, the best solution is to add legacy kernel support on top of the current Lakka version. I will soon upload a new build with that.

All credit goes to the original creators of Lakka - I am just making the build available for download again.

Suggested cores for best performance

  • SNES: Snes9x 2005 Plus
  • N64: Mupen64Plus-Next
  • NES: Nestopia

Overclocking

You can overclock the Banana Pi for much better performance. Some of the more demanding cores such as Snes9x2010 and Genesis Plus GX do have some minor dips here and there (from 60 to 55 FPS), especially in more demanding games. With overclocking they should be running at full speed. N64 performance is also greatly improved.

Connect to the BPi over SSH and issue the following commands:

echo 1152000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo 1152000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq

1152000 means 1152 MHz. This usually works well. The default clock is 960 MHz. If the system freezes at any point, try a lower clock value.

These changes will be reset after a reboot. To make it permanent, you can add these commands to the autostart.sh script:

echo "echo 1152000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >> ~/.config/autostart.sh
echo "echo 1152000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq" >> ~/.config/autostart.sh 

You could also create the autostart.sh file on another computer and copy it over using Samba (put it into the folder named Configfiles). This will also work if you cannot access the command line for some reason.

2 Likes

Thanks you very much for this !

Thank you for your work! I was wondering if you could have some insight about Banana Pro. Could I use the sources you modified and just add/replace the fex file by using lemaker_banana_pro.fex file? Also I found that there is a way to boot from the SDCard and load data from the SATA drive connected to the board. Is there a way to trick Lakka into doing that? I tested the last part on a Lamobo-R1 using images from this site: https://sd-card-images.johang.se/boards/lamobo_r1.html

Yes, this should work. The Banana Pro has an Allwinner A20 like the Banana Pi, so it should be compatible with the Allwinner 3.4 kernel. You just need to generate a new script.bin from your board’s fex file (lemaker_banana_pro.fex) with fexc and copy it to the first SD card partition.

About the SATA drive, yes, this should also work. You would need to modify the following file:

Lakka-LibreELEC/uEnv.txt at v2.1-rc5 · libretro/Lakka-LibreELEC (github.com)

“boot” is the first SD card partition with the KERNEL and SYSTEM files. “disk” is the second SD card partition with user data and roms.

If you want to boot Lakka from HDD, you could try to replace “boot” with your HDD partition (/dev/sda1, FAT32) and copy the KERNEL and SYSTEM files to it.

The “disk” partition would be /dev/sda2 and needs to be formatted as EXT4. You need to disable METADATA_CSUM on the data partition (the old kernel does not support that and will fail to mount):

sudo tune2fs -O ^metadata_csum /dev/sda2

If it helps, you can also have a look at the init script:

Lakka-LibreELEC/init at v2.1-rc5 · libretro/Lakka-LibreELEC (github.com)

This is the first program that is called by the linux kernel after it boots. This script is responsible for mounting all the partition stuff.

Also, it should not be necessary to download and compile the source for this. You could just create an SD card using the Banana Pi image, and then on the first SD card partition, edit the uEnv.txt and replace the script.bin file.

I have almost finished the process of adding support for the legacy Allwinner kernel (Banana Pi, etc.) to the current Lakka version. The source code needs a bit of cleanup, I hope I’ll be able to upload it here soon. This would have the advantage of automatically keeping Retroarch and all the cores up to date according to the current Lakka version.

2 Likes

Before getting to the end of your post, while tinkering with/analysing the SYSTEM file (using unsquashfs), I figured the same thing you said last… just using the compiled image and modifying the sdcard/hdd configuration should do the trick… and then I was at the end… so now I was in my head saying: DUH, dummy!
Amazing work… Maybe I’ll get the time to try it this weekend… work always gets in the way of fun…
Also, you say you’re adding support for the legacy Allwinner kernel to the current Lakka version. Does that mean that METADATA_CSUM will still have to be disabled on your upcoming release?

Hello!
I finally got to boot the Banana Pro in the discussed configuration (boot from 1GB sdcard - one partition - and a 64GB ssd - two partitions). Also I had to modify uEnv.txt to bypass EDID because it kept losing the HDMI signal.
Tested a SNES rom and all works as it should on the emulation part.
Now here is the not so good part: module ap6210 is not loaded/present. So WiFi is not working. I did manage to ssh with the Ethernet port.
I will try a debian image just to make sure that the onboard WiFi module is working and will come back with a reply.

So… I tested the wifi using the sd-card image provided on this page: https://sd-card-images.johang.se/boards/bananapro.html . The ap6210 WiFi is working as it should after installing firmware-brcm80211. Had to jump some hoops by using the Ethernet port before I got at that point.
So, me thinks it is something with the Banana Pi M1 image. I think that I may need to recompile it after all…?
For me it’s definitely some progress after this board has been sitting on the shelves for a couple of years. And I was just reminded that the Ethernet port supports Gigabit.

Found https://github.com/libretro/Lakka-LibreELEC/issues/144
Will test and come back with results.
Any way to debug this? I’ll check if I can find some boot logs…

I managed to find some instructions on ap6210 and I took a look at the ap6210_module.patch in the source, searched string “_para,” and found some pointers on what it expects from the script.bin
After that I tried some settings in the fex file and issued the command modprobe for some modules found here. Wifi or bluetooth are still a no go :pensive:

modprobe hci_uart
modprobe gpio_sunxi
modprobe rfcomm
modprobe hidp
modprobe sunxi-ir
modprobe bcmdhd
    modprobe: ERROR: could not insert 'bcmdhd': No such device
modprobe ap6210
    Segmentation fault

------------------------------------------------------------------------------

dmesg
[   34.952922] Bluetooth: Core ver 2.16
[   34.956512] NET: Registered protocol family 31
[   34.961841] Bluetooth: HCI device and connection manager initialized
[   34.965686] Bluetooth: HCI socket layer initialized
[   34.969720] Bluetooth: L2CAP socket layer initialized
[   34.973865] Bluetooth: SCO socket layer initialized
[   34.984571] Bluetooth: HCI UART driver ver 2.2
[   34.988395] Bluetooth: HCI H4 protocol initialized
[   34.992319] Bluetooth: HCI BCSP protocol initialized
[   34.995977] Bluetooth: HCILL protocol initialized
[   34.999939] Bluetooth: HCIATH3K protocol initialized
[   73.655042] Bluetooth: RFCOMM TTY layer initialized
[   73.659271] Bluetooth: RFCOMM socket layer initialized
[   73.661989] Bluetooth: RFCOMM ver 1.11
[   81.444788] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[   88.411666] input: sunxi-ir as /devices/virtual/input/input3
[   88.415920] IR Initial OK
[  113.058859] 
[  113.058864] failed to power up wifi chip, retry again (4 left) **
[  113.058869] 
[  115.058945] 
[  115.058949] failed to power up wifi chip, retry again (3 left) **
[  115.058954] 
[  117.058970] 
[  117.058974] failed to power up wifi chip, retry again (2 left) **
[  117.058979] 
[  119.058998] 
[  119.059002] failed to power up wifi chip, retry again (1 left) **
[  119.059007] 
[  119.066411] 
[  119.066420] failed to power up wifi chip, max retry reached, exits **
[  119.066425] 
[  159.539602] [ap6210] select wifi ap6210
[  159.544890] [ap6210] Initializing ap6210.
[  159.553813] [ap6210] platform device registered successfully.
[  159.561352] [ap6210] Using ap6210 configuration.
[  159.672105] [mmc-msg] sdc3 set ios: clk 0Hz bm PP pm UP vdd 3.3V width 1 timing LEGACY(SDR12) dt B
[  159.675710] [mmc-msg] sdc3 power on
[  159.702632] [mmc-msg] sdc3 set ios: clk 400000Hz bm PP pm ON vdd 3.3V width 1 timing LEGACY(SDR12) dt B
[  159.707730] [mmc-msg] sdc3 set round clock 400000, src 24000000
[  159.767524] [ap6210] WLAN placed in POWER ON
[  159.790014] [mmc-err] smc 3 err, cmd 52,  RTO
[  159.794158] [mmc-err] smc 3 err, cmd 52,  RTO
[  159.802514] [mmc-msg] sdc3 set ios: clk 400000Hz bm PP pm ON vdd 3.3V width 1 timing LEGACY(SDR12) dt B
[  159.813529] [mmc-msg] sdc3 set ios: clk 400000Hz bm PP pm ON vdd 3.3V width 1 timing LEGACY(SDR12) dt B
[  159.818591] [mmc-err] smc 3 err, cmd 8,  RTO
[  159.827259] [mmc-msg] sdc3 set ios: clk 400000Hz bm PP pm ON vdd 3.3V width 1 timing LEGACY(SDR12) dt B
[  159.840883] mmc1: queuing unknown CIS tuple 0x80 (2 bytes)
[  159.849657] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[  159.855915] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[  159.863152] mmc1: queuing unknown CIS tuple 0x80 (7 bytes)
[  159.884884] [mmc-msg] sdc3 set ios: clk 400000Hz bm PP pm ON vdd 3.3V width 1 timing SD-HS(SDR25) dt B
[  159.893339] [mmc-msg] sdc3 set ios: clk 50000000Hz bm PP pm ON vdd 3.3V width 1 timing SD-HS(SDR25) dt B
[  159.898558] [mmc-msg] sdc3 set round clock 42857143, src 600000000
[  159.962131] [mmc-msg] sdc3 set ios: clk 50000000Hz bm PP pm ON vdd 3.3V width 4 timing SD-HS(SDR25) dt B
[  159.971591] mmc1: new high speed SDIO card at address 0001
[  159.978707] [ap6210] Linux Kernel SDIO/MMC Driver
[  159.986405] [ap6210] bcmsdh_probe: Host irq is not defined
[  159.991602] bcmsdh_sdmmc: probe of mmc1:0001:2 failed with error 1
[  160.015615] bcmdhd: exports duplicate symbol bcmsdh_probe (owned by ap6210)
[  160.021599] bcmdhd: exports duplicate symbol bcmsdh_probe (owned by ap6210)
[  160.050088] bcm4330: exports duplicate symbol bcmsdh_probe (owned by ap6210)
[  160.057748] bcm4330: exports duplicate symbol bcmsdh_probe (owned by ap6210)
[  171.990595] [ap6210] dhd_module_init: sdio_register_driver timeout or error 
[  171.997719] Unable to handle kernel NULL pointer dereference at virtual address 00000014

------------------------------------------------------------------------------

lsmod
    Module                  Size  Used by
    ap6210                623291  1
    sunxi_ir                4084  0
    hidp                   17795  0
    rfcomm                 58901  0
    hci_uart               24920  0
    bluetooth             263514  5 hidp,hci_uart,rfcomm
    8021q                  18691  0
    garp                    5645  1 8021q
    stp                     1890  1 garp
    llc                     4764  2 stp,garp
    mali                  113597  2
    ump                    56474  3 mali

Hello, sadly I cannot help to debug this right now, as I’m not at home until the end of next week and do not have access to my dev machine.

However, my suggestion would be to find a fex file for your Banana Pro that is known to work with the Wifi chip. Where did you get your current fex file from? I would suggest not using the one for the Banana Pi, try to use one that’s made for the Banana Pro. Usually, these are provided somewhere on the manufacturer’s website.

It’s a good idea to compare another working image to this one, but make sure that it’s using the same 3.4 Allwinner kernel, as this will make debugging much easier. If it’s using a newer mainline kernel, too many things have changed. In that case, it would be better to use an older image that’s using the Allwinner vendor kernel. For example, I could find some old Banana Pro images here:

Banana Pro Images, Documents,Quick start Download | LeMaker single board computers Community

Do any of these images have working Wifi for you?

Then, compare the dmesg of the working image with the dmesg from this image, especially if the following error message is still there:

failed to power up wifi chip, retry again

Does this ap6210 module ship with the Allwinner kernel or does it come from a patch?

Lastly, could it be that the firmware is missing? I don’t know if Lakka 2.1 included the firmware for this driver. Check the driver source if there are any paths where it expects the firmware to be, then check if the files are present.

So… I tested Raspbian_For_BananaPro_v1412.img (kernel 3.4.103) provided by Lemaker and after adding ap6210 into /etc/modules, the wifi works as it should. I tried to find patches/sources for their compiled ap6210.ko driver but could not find any.
The /usr/lib/firmware/ap6210 contents are the same in both images (mounted SYSTEM squash partition from Lakka and the root partition of Raspbian_For_BananaPro_v1412.img and did a file compare)
In the process, I found https://linux-sunxi.org/Cubietruck/AP6210 witch has the same ap6210_module.patch used for Lakka 2.1-rc5 (kernel 3.4.104). What Lakka 2.1-rc5 does not seem to have is the ap6210_defconfig.patch.
They say that “the second patch (ap6210_defconfig.patch) disables the BCMDHD driver and configures the AP6210 driver instead”… witch I think it may trigger the ap6210 module to load as it should (with the fex mods adaptation of [wifi_para] instead of [sdio_wifi_pro_para] in the Lemaker Banana Pro fex).
For now I’ll pause from going further (got other things to attend to) but I’ll resume and try to add that second patch to the Lakka 2.1-rc5 source and try to recompile… we will see how that goes.

Still figuring things out… so the ap6210_defconfig.patch did not work… Of course it didn’t … the patch was not for the intended sun7i_defconfig file.
I did find the Lemaker’s modifications for the Banana Pro’s ap6210 wifi module here. All I need to do now is try some patches on the specified files and then recompile… this will be fun.

Back again: I made a duplicate of the Bananapi folder as Bananapro and used the original script.fex. Then I modified the ap6210_module.patch and included the patches made by Lemaker for the ap6210. Also made some patches accordingly to the linux.arm.conf and linux-noump-drm-3.4-test.arm.conf.
With those done I tried to compile (using the command for Bananapro) but got stuck at this step:

a - src/debugfs.o
a - src/util.o
a - src/linklist.o
a - src/mod_file.o
a - src/mod_path.o
a - src/log.o
ranlib src/libpopulatefs.a
/home/user/Downloads/lakka-2.1-source/build.Lakka-Bananapro.arm-8.2-devel/toolchain/bin/host-gcc src/main.o -o src/populatefs -L./src -Wl,-rpath,/home/user/Downloads/lakka-2.1-source/build.Lakka-Bananapro.arm-8.2-devel/toolchain/lib -L/home/user/Downloads/lakka-2.1-source/build.Lakka-Bananapro.arm-8.2-devel/toolchain/lib -Wl,-Bstatic -lpopulatefs -Wl,-Bdynamic -lext2fs -lm -lcom_err -lpthread
make[1]: Leaving directory ‘/home/user/Downloads/lakka-2.1-source/build.Lakka-Bananapro.arm-8.2-devel/populatefs-95cc98b’
fatal: not a git repository (or any of the parent directories): .git
make: *** [Makefile:12: image] Error 128

I installed Ubuntu Ubuntu 20.04.3 LTS to compile
Linux ubuntu 5.11.0-37-generic #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Any ideas?

What package was it trying to build? Sorry, the log is too short. Please post a longer version into a pastebin (the last 1000 lines should be enough). If you’re able to determine the package that can’t be built, trigger a manual build of it (Lakka/scripts/build packagename instead of make image) and post the full log here.

You can also go into the build folder and sort by modified date, then go into the last package it was trying to build and examine the sources. If they’re empty or unusually small, this can sometimes mean that the download location for a package is broken or has moved.

It’s a little late and I have work tomorrow but till I can get to it again, I pasted the output here

First, in lakka-2.1-source/packages/tools/populatefs/package.mk there is this:

PKG_URL=“https://github.com/lipnitsk/$PKG_NAME/archive/v${PKG_VERSION}.tar.gz

instead of what maybe should be

PKG_URL=“https://github.com/lipnitsk/$PKG_NAME/archive/${PKG_VERSION}.tar.gz

Regardless, I think that populatefs builds just fine.
Second, I went in the image script and added some echo commands and it seems that the problem is at this line:

GIT_HASH=$(git rev-parse HEAD)

What is “git rev-parse HEAD” suppose to do?
A few lines in the script that follow look like this:

$SCRIPTS/build populatefs:host

BUILD_DATE=`date +%Y%m%d%H%M%S`

GIT_HASH=$(git rev-parse HEAD)

if [ "$LIBREELEC_VERSION" = "devel" ]; then
  if ! GIT_BUILD=$(git rev-list --count HEAD 2>/dev/null)
  then
    GIT_BUILD=$(git rev-list HEAD | wc -l)
  fi
  GIT_ABBREV=$(git log -1 --pretty=format:%h)
  DEVEL_VERSION=$LIBREELEC_VERSION
  LIBREELEC_VERSION=$LIBREELEC_VERSION-$BUILD_DATE-r$GIT_BUILD-g$GIT_ABBREV
  echo "$LIBREELEC_VERSION" > $BUILD/BUILD_FILENAME
fi

Hello, could we please discuss build problems at another place, please open an issue on my GitHub page: Issues · asdf288/Lakka-LibreELEC (github.com)

Here is another hint: Change the first line of the Lakka scripts you want to debug to #!/bin/bash -x (in this case, the script is probably scripts/image). This is very helpful because it will show the command that it tries to execute before it errors out. Further reading: bash - How to echo shell commands as they are executed - Stack Overflow