General

[Ubuntu 20.04] Latest Linux Distributions on LattePanda V1 and Kernel Customization (English)

userHead LattePanda 2020-08-06 17:49:53 23613 Views0 Replies

Hello, fellow panda owners!

We are happy to announce that it appears that LattePanda owners can install Ubuntu operating systems using Linuxium and some associated programs which make it possible to actually use these operating systems and fix any problems which you may encounter!

This post is originally from DFRobot Community User pATAq's forum post, and serves only as an English translation of what he wrote. When reposting or referencing, please give credit to the original author~
 

Latest Linux Distributions on LattePanda and Kernel Customization

Preface

For original articles and reprinted references, please be sure to indicate the link....

Sometimes, when I buy something I like, I especially look forward to an early arrival, so I take a moment to open a mobile client to refresh and check the express delivery information. After a long enough time, though, I felt like I was wasting my time, so I wanted to use the computer to help me check for updates.

Software and Hardware Environment
LattePanda, Python3.8, Arduino 18.12, Lubuntu 20.04

This project is divided into three parts:

Latest Linux Distributions on LattePanda and Kernel CustomizationCore Code to Track the PackagesAdditional Features like Tracking People with Wifi Using Kismet

This project is expected to achieve the following functions and features:

Add information to be monitored regarding deliveries on the front end of the web pageShow a record of all deliveries being trackedA feature to customize the search frequencySend notifications to WeChat in the event of a change in the delivery's informationUse extra LED's, speakers, or Dashboards to send out reminders when people are at home

After this projects' completion, preparation will be underway to add the following functions and features:

Add intofmation to be monitored or small programs that report delivery information on WeChat or other appsAdd Chinese voice broadcastIntegrate all information into the Home Assistant Dashboard

The knowledge that will be gained after undertaking this project includes:

Install and setup latest Ubuntu for LattePandaInteraction between MPU and MCU on LattePanda with Firmata protocolPython GUI Programming with remiUsage of TinyDB——a lightweight databaseWechat notification via ServerChanTracking people with wifi using kismetUsing Kismet REST-like APIText To Speech with PythonHome Assistant

This article is the first part. Seeing the community activities, I found them very interesting, and there was also an event jointly organized by Intel and DFRobot which had use of an Intel CPU listed as one of the requirements. Mine is an AMD CPU, and I don’t have a nerve development or nerve computation stick. Then, I took out the LattePanda (hereafter referred to as "fatty") and used it as my feasibility test. The LattePanda v1 board was prepared for use as the basis [for determining whether these functions work or not], and the system was ready to be converted to Linux for easier development. However, some problems were found in the process of installing Linux. This article shares relevant experience related to this issue. In addition, the LattePanda Alpha / Delta's architecture is similar, so some of this content is also of value as reference material for these products.

1. Preparation
 

Why do we prefer to use Linux?
Linux operating systems' customizability is greater, and offers a greater feeling of familiarity to people who use it for developing purposes.

Ubuntu of Mint: which one to choose?
The latest version of Mint is based on Ubuntu 18.04, which passes the test of meeting most people's standards. And yet, I don't like Ubuntu's Unity desktop, and the performance of the LattePanda is overburdened when using it, so we chose to use the relatively lightweight LXQt desktop's (previously LXDE, now rewritten as Qt) Lubuntu. This operating system is based on openbox, and we can see the legacy. Those who are interested can also check out some introductions from the developer of LXQt, Dr. Hong Renyu: particularly parts one and two.

1.1 Current Situation

When surfing the internet, we can discover the following information about running Linux on the LattePanda:

Linux Ubuntu 16.04 LTSOpenSUSE Leap 15.0, an instructional guide by J.S. Evanslattepanda-mainline-4.11

Caution:

The official document says "Official Supported Version: S70CR200 Version," but actually my S70CR110 can also use this versionMop talks about changing the settings in the South Bridge in BIOS, but there's no real need to change it in the new version of ubuntu

The above three have a common feature: they are all OUTDATED. We need better software and hardware compatibility and mainstream Linux versions and kernel support. Of course, some valuable information can be obtained from the above, and holds the very problem we need to solve.

1.2 The Problems We Are Facing

rtl8723bs wifi & bluetooth driverHDMI audio output issueGoodix touch panel dirverPWM? (At this moment, I still don't know what problems it has)

1.3 Exploration
Why does the LattePanda have the aforementioned problems that need to be solved? It is mainly related to the Intel Atom x5 z8350 CPU orocessor used by fatty. The specifications of this processor are as follows:
 

Intel Atom x5 z8350, (Code Name: Cherry Tail, Original Target: Lightweight tablets / High-end Smartphones. Microarchitectures: Airmont——the 14 nm die shrink of Silvermont, more info, Source), remember that there is no avx instruction set supported, therefore, recompile is need to run newer version of Tensorflow.

Intel CPU Series Introduction, Atom x5-z8350 Specifications and Performance | Japanese

Originally, the z8350 was designed for Windows tablets and mobile phones, and did not consider Linux compatibility, so there are many problems, especially with the drivers. To summarize [the likely problems you'll run into and the solutions found], the following are:

Wireless and Bluetooth functions: used the RTL8723BS module, SDIO interface, 2.4GHz 802.11bgn, bt4.0, RealTek official website only provides Windows driversTouch screen: used a Goodix gt911 solution

Even though the default maximum only supports 2GB of memory, [units bought in this country can be changed to ones that] support 4GB, but it is said that the memory bandwidth is also halved
When using Linux Kernel versions preceding v4.12, you need to manually install the driver of the RTL8723BS module, but since Linux 4.12, rtl8723bs has been merged, this is very similar to using the Xiaomi portable wifi (mt7601u chip) on the Raspberry Pi a few years ago. Initially, you needed to compile and install it yourself, but this was later incorporated into the kernel and could be used right out of the box, instead. You can see that the mop kernel is still 4.11.
 

Caution:

The Intel Celeron N4100 used by the LattePanda Delta also does not support the avx instruction set, so if you want to run the new version of Tensorflow, you need to compile it yourself. Refer to "Tensorflow-Intel-Atom-CPU"

There are many devices using the z8350 Intel Atom processor, such as the Lenovo Miix 310 and Chuwi Hi10 Pro, among which Lenovo's miix310 is a notebook, which is closer to the scenario that fatty might be used for.
 

Reference Links:

intel-atom-iso | *ImportantFix-Intel-Z8350-for-ubuntu-kubuntumiix310 | *Importanttuxbletlubuntu_in_chuwi_Hi10Prolinux-on-hi10

1.4 Discovery
 

Between the lines, we found two things of import: Ian Morrison's isorespin.sh and kernel_gcc_patch

1.4.1 isorespin.sh

The project's main page and the project's introduction
 

In short, devices using Intel Bay Trail and Cherry Trail processors will encounter some compatibility problems when installing Linux on devices, especially when using the HDMI output, system suspension and wireless drivers. Linux 4.11 solves the problem of HDMI audio output and system suspension, and Linux 4.12 solves the problem with the wireless driver. Additionally, Ian Morrison (Linuxium) went a step further and developed the isorespin.sh tool, which can make a new version of an Ubuntu ISO installation disc image file with the Linux Mainline kernel suitable for the above CPU. In addition, Ian is also one of the authors of the cnx-software website. --Source

We used this guide to customize the Linux system, and the author has some of the latest system disc image files ready for download. Currently there is support for custom versions of 64bit Ubuntu, Ubuntu Flavoured, LinuxMint, etc.


This very script has made the following improvements for Intel Atom processors:

Add a GRUB 32-bit bootloader to allow ISOs to boot on the many Intel Atom devices limited by their BIOS.Add functionality to boot ISOs on any Intel Apollo device regardless of the BIOS settings.Upgrade the kernel to the latest mainline version or to a specific version to benefit from recent patch functionality e.g. for audio and wifi/bluetooth or to use a rolling (HWE) kernel.Add (or remove) repositories, software packages, scripts and files to allow the installation of firmware and favourite programs.Preseed or perform set-up commands and scripts and also change system defaults and kernel boot parameters.Add persistence so that the ISO can retain data, installed software packages and settings across reboots.Create a server ISO that works on both 32-bit and 64-bit bootloaders found on various low cost Intel Atom mini PCs or one that works on the more recent Apollo and Gemini Lake mini PCs.

--atom include the flags, packages, scripts and commands that I recommend when respinning an ISO for a device with an Intel Atom (Bay Trail or Cherry Trail) processor and mirrors the manual invocations of '-l rtl8723bX_4.12.0_amd64.deb -f linuxium-install-UCM-files.sh -f wrapper-linuxium-install-UCM-files.sh -f linuxium-install-broadcom-drivers.sh -f wrapper-linuxium-install-broadcom-drivers.sh -c wrapper-linuxium-install-UCM-files.sh -c wrapper-linuxium-install-broadcom-drivers.sh'.

Concerning the HWE kernel, please refer to "Installing HWE for Ubuntu LTS to get updated kernel and graphics support"

After encountering this treasure, it seems that our problems can be solved in one package. Can we really sit back and relax? Download Lunbutu 20.04 LTS Atom here

1.4.2 kernel_gcc_patch
Project Main Page | Kernel patch enables gcc optimizations for additional CPUs.

Due to the relatively low performance of the Atom x5-8350 and Celeron N4100, the operating system will use the generic kernel by default, focusing on compatibility and universality. That is, most of the hardware can be run after installation. So, we can recompile the kernel in a targeted manner in order to obtain higher performance. In addition, this project also supports Celeron N4100 (Intel Goldmont Plus family of low-power Atom processors-Gemini Lake).

 

Please understand that I have mistakenly understood this part. "Generic" is a real-time thing. Please see the reference link for more details.
 

2. Reorganize

2.1 Install Lubuntu Customized for Cherry Trail CPU

Customize Installation Media USB

I used balenaEtcher to burn the author’s ISO installation disc image file to a USB flash drive, and then plugged in the newly-made USB flash drive (as booting up from an mSD card is not supported). *Make sure to continuously* press the ESC or Del button when booting to enter the bios, where you can change the boot settings. Here, I forgot to see if the default USB disk boot sequence is the highest *in boot priority*, but you can try it *and see if you can boot from the live USB installer withouth changing any settings*.You can download the original mirror's disc image file from the Tsinghua mirror site for customization.

Hard Disk Partition

esp partition | Must have, 100MB is fine, flag: bootroot partition, xfs file system, but ext4 is not the best solution for emmc, and the default scheduling mode will be changed laterSwap, according to the memory size, such as selecting 1:1 for 2-4G. Here, I am using 4G

Plug it in! Start it up!

I connected the monitor via HDMI instead of the MIPI interface display (hereinafter referred to as "IGD", built-In Graphics Display), which only led to wallpapers on the monitor without icons and taskbars, because, as it turns out, the main output went to the unconnected IGD. It really was just. . . blindly turning on the terminal, then entering sudo poweroff to turn off the machine first, and then plugging in the display and touch panel, and then finding out that the touch panel does not respond.

 

2.2 Post-Installation Setup
Okay, we need to test ways to solve the problems mentioned above and solve the problems with the HDMI output and touch panel. First plug in the dedicated IPS screen, set the HDMI as the main output, and then install OpenSSH. We'll connect to the LP through the MobaXterm program. For more details, please refer to my article "Forget VNC/RDP--Pick up MobaXterm and easily use its remote desktop!".

 

The Openbox desktop is one choice for the graphical interface, but please note that MobaXterm currently does not support the default LXQt, and only LXDE is supported.The Interactive shell is the traditional choice for the terminal interface.


Install the necessary software:
 

Code: Select all

sudo apt install openssh-server tmux 2.2.1 Test the wireless connection, Bluetooth, and audio output settings

What we download is the disc image file made by the author for the atom processor, and made in accordance with the introduction of isorespin.sh instructions:
 

--atom include the flags, packages, scripts and commands that I recommend when respinning an ISO for a device with an Intel Atom (Bay Trail or Cherry Trail) processor and mirrors the manual invocations of '-l rtl8723bX_4.12.0_amd64.deb -f linuxium-install-UCM-files.sh -f wrapper-linuxium-install-UCM-files.sh -f linuxium-install-broadcom-drivers.sh -f wrapper-linuxium-install-broadcom-drivers.sh -c wrapper-linuxium-install-UCM-files.sh -c wrapper-linuxium-install-broadcom-drivers.sh'.
 

That is, the wireless Bluetooth firmware of rtl8723bs is installed. Note that some of these are systems equipped with drivers but without the correct firmware, which cannot be used properly. I added a UCM file for audio output.

Now let's test it:

 

The Bluetooth part uses bluetoothctl. Please refer to https://wiki.archlinux.org/index.php/Bluetooth#Console for more information. Successfully connected to my mobile phone *using this Bluetooth connection*.


For the wireless part, you can use commands such as iwconfig, iw list, etc. to see that the wireless network card supports the ``monitor mode, which provides a hardware basis for us to use kismet for sniffing out wireless signals below. For the introduction of wireless network cards, please refer to my article: UP Board USB wireless network card purchase guide.

Connect to wireless network CLI
 

After some understanding, I found that the networkmanager is used, which is easy to use graphically. The CLI is nmcli:

The above command is enough. Make sure to change the wireless network name SSID and password in the above command to your computer's SSID and password, respectively. For more details, please refer to the nm operation guide.


For sound output, the lower right corner of the task bar that comes with the LXQt desktop does not support the adjustment widget, so Pavucontrol was used to control the settings, and the graphics menu bar also has Pavucontrol. The measured HDMI audio output and 3.5mm jack output are normal.

Other related commands:
 

Code: Select all

dmesg | grep XXX lsmod | grep XXX lshw lsusb lspci 2.2.2 Setting the Default Output to HDMI
 

This was a headache to set up. I first used a dedicated screen to connect to the wireless network and install the ssh server, and then temporarily use it from SSH. Although it can be used normally after entering the desktop and manually changing the primary/secondary output, it then returns to the same situation after restarting, so I simply turned off the IGD output.
 

Check out How to Disable Internal Display from BIOS? The means that the official site prescribed: BIOS->"Chipset"->"North Bridge"->"IGD-LCD Control"->"Force Lid Status"->"Off" did not work, so I finally had to resort to the last reference: K3dAR's reply to the solution: add kernel parameter: video=DSI-1:d
 

How did it do it? Check out the Kernel parameters page of archwiki:
 

Code: Select all

sudo nano /etc/default/grub # Add video=DSI-1:d before "GRUB_CMDLINE_LINUX_DEFAULT" # For example GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=cb38daad-4618-4b36-98de-1915abb168cf video=DSI-1:d" # Regenerate the grub.cfg file sudo grub-mkconfig -o /boot/grub/grub.cfg # TODO: Use sed to make changes This becomes effective after restarting. If you want to enable IGD, follow the same steps as above and delete the sentence you added. If we want to generate an image with IGD disabled by default, refer to the introduction of isorespin.sh, add grub content, and generate iso image parameters as isorespin.sh -i xxx.iso --atom -g "video=DSI-1:d"
 

2.2.3 Solve the touch panel drive problem
 

After the installation, the main functions worked as normal, but the touch screen was not working. I thought it was because I didn't plug it in. I tried it several times and it was always the same. I didn't see it when I used the xinput list command. Using dmesg | grep Goodix, I could see that a device was, in fact, recognized, but did not have the proper drivers; It is also loaded when using lsmod goodix into the system. It is suspected that the problem is an incorrect driver.


You can see that the main control chip of the touch panel is Goodix GT911

Code: Select all

dmesg | grep goodix # The device can be identified, but an error is reported lsmod # I don’t remember what the output is, you can take a look at it yourself xinput list # Cannot recognize Goodix Capacitive TouchScreen Refer to the following content, you can find that the Goodix driver does have a problem. And I can see GT911 related content in the Linux kernel, which is very confusing.

Beta Ubuntu Image for LattePanda - Official versionGoodix Touchscreen and Stylus share deviceShowing posts sorted by relevance for query goodix

*I used Google to search it*, and found this: Goodix Touchscreen Linux Driver, *and when used it appears to work*.

Code: Select all

# Compile the driver git clone https://gitlab.com/AdyaAdya/goodix-touchscreen-linux-driver cd goodix-touchscreen-linux-driver make # Test drive (delete the original driver and load the newly compiled driver), I am successful here sudo su rmmod goodix insmod goodix.ko # install driver xz goodix.ko mv goodix.ko.xz /lib/modules/$(uname -r)/kernel/drivers/input/touchscreen/goodix.ko.xz You can use this after restarting your computer.
 

Complete set of debug commands:

Code: Select all

$ dmesg | grep -i goodix $ cat /proc/bus/input/devices | grep -B 1 -A 8 -i goodix # libinput list-devices | grep -A 17 -i goodix # libinput debug-events $ xinput list 2.3 Recompile kernel to increase performance
 

As mentioned earlier, recompiling the kernel for Atom X5 z8350 can improve performance a bit, so let’s do it now.

Code: Select all

sjqlwy@LattePanda:~$ uname -a Linux LattePanda 5.6.8 #1 SMP Sat May 2 23:36:54 CST 2020 x86_64 x86_64 x86_64 GNU/Linux sjqlwy@LattePanda:~$ cat /proc/version Linux version 5.6.8 (sjqlwy@LattePanda) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #1 SMP Sat May 2 23:36:54 CST 2020
This is the kernel I compiled for the LattePanda itself, *and does not carry the genetic type*. It took more than an hour to compile? It is recommended to compile on other computers with higher performance.
 

2.3.1 Download the source code and apply the patch
 

Open the Linux Kernel website and you can see that the latest Stable version is 5.6.x. *Download it for later use.* It is recommended to read Linux Kernels Versions' Introduction and Queries. The kernel that comes with Ubuntu emphasizes versatility, so we will use the patch to recompile the kernel for z8350 in order to get better performance. Fortunately, someone has already done it and performed daily maintenance on it, *and can be found here*: kernel_gcc_patch.
This tutorial uses silvermont. Why don't we see the Cherry Trail we need? What do these codes mean? Find the answers in the related Wiki for the Intel Atom and learn the following.

Cherry Trail, Apollo Lake, Gemini Lake, etc. are Code Name development codesSilvermont, Goldmont, Airmont, etc. are CPU microarchitecturesThere are sub-sets under these micro-architectures, for example, Airmont is a subset of Silvermont, and Goldmont Plus is a subsetGoldmont Plus--Gemini Lake--Celeron N4100 (Mobile processors)Airmont——Cherry Trail——Atom X5 z8350(consumer SoCs aimed at tablets)Airmont is the 14 nm die shrink of Silvermont(22 nm)

2.3.2 Compile the kernel
 

Here we download enable_additional_cpu_optimizations_for_gcc_v9.1+_kernel_v5.5+.patch (5.6) and put it in the folder where the Linux source code is located.This patch works with gcc versions 9.1+ and with kernel version 5.5+ and should
NOT be applied when compiling on older versions of gcc due to key name changes
of the march flags introduced with the version 4.9 release of gccIf you use Ubuntu 20.04, the gcc version and kernel version of the compilation environment are both satisfied, otherwise you need to enter the settingspatch -p1 <PATCH_NAME.patch will report an error

Code: Select all

sudo apt-get install gcc make libncurses5-dev libssl-dev bison flex libelf-dev patch -Np1 -i /path/to/patch make menuconfig At this point, you can select "Intel Silvermont family of low-power Atom processors (Silvermont)" in "Processor type and features -> Processor family".

 

Code: Select all

make -j4 bindeb-pkg # Compile the kernel, it takes about 20m-2h depending on the machine performance sudo dpkg -i linux*.deb # Install the compiled kernel, and the grub will be set automatically Restart to see that the new kernel has been enabled.
 

References:

Difference between Make oldconfig and olddefconfighttp://www.linuxfromscratch.org/

2.3.3 Extra Topic 1: Upgrade the gcc
 

As mentioned above, gcc 9.1 or above is required to use this patch, but I can see that gcc 7.5 is installed by default on my other machines (Ubuntu 18.04 LTS), which will cause the installation to fail.

Code: Select all

ubuntu@VM-126-41-ubuntu:~$ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 After trying ubuntu-make, backports *sources* and other methods, I referred to the PPA source methods for how to install multiple versions of the GCC compiler on the Ubuntu 18.04 LTS operating system, which was just what I needed.
 

You're likely running the stable version of Debian because you prefer to choose the stable branch of Debian. It works very well, but there is only one problem: its software is a bit outdated compared to other distributions. This is why backports appeared.

Code: Select all

root@build-server:~# gcc --version gcc (Ubuntu 9.3.0-11ubuntu0~18.04.1) 9.3.0 # Ubuntu 20.04 does not have this problem sjqlwy@LattePanda:~$ gcc --version gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0 2.3.4 Extra Topic 2: Prevent apt from changing the kernel
 

It will remind you to install the generic kernel when we run apt upgrade. We use the apt-mark command to prevent this behavior from occurring.

Code: Select all

apt list --installed dpkg-query -l # The output is clearer apt-mark hold <pkg> # Change <pkg> to all kernel-related packages suggested in apt upgrade apt-mark unhold <pkg> apt-mark showhold References:

Several different ways to upgrade the Ubuntu Linux kernelapt-mark usage

2.3.5 docker support
 

Refer to the DIY NAS Project (2) Docker and ownCloud, as well as the settings of Miix 310 above to configure the kernel compilation parameters
 

2.3.6 TODO

Refer to Compiling your own kernel using isorespin.sh, where you can use Ubuntu's kernel source code and patches and have them integrated into our performance patchesChange the default IO scheduling, increase file system support, and improve emmc performance and lifespan

3. Summary
 

In the end, we installed Lunbutu 20.04 perfectly on the LattePanda, which solved the problems of the BT/Wifi/Audio Output/Touch Panel and IGD, and used the optimized kernel to improve the performance of the LP. If you have time, you can customize the ISO disc image file to be suitable for the LP, including:

Turning off the defauult built-in output, and utilizing the HDMI output signal insteadGive Docker support to and get better performance out of our optimized kernelMake a pre-installed touch screen driverChange io scheduling and add more file system supportPre-install the SSH Server

4. Reference

Usage of the English dash, and Usage of the English comma *ChineseRTL8723BS Wifi and BT firmware package for Ubuntu mainline v4.12 kernels | sudo systemctl start rtl8723bsbt.serviceNew features in isorespin.sh--debug | show more information--interactive | Enter root shell, customize changes. For example, modify the mirrorlist--dist-upgrade | More thorough upgrade, can be used with --debugWhy choose a low latency kernel over a generic or realtime one?If you do not require low latency for your system then please use the -generic kernel.If you need a low latency system (e.g. for recording audio) then please use the -preempt kernel as a first choice. This reduces latency but doesn't sacrifice power saving features. It is available only for 64 bit systems (also called amd64).If the -preempt kernel does not provide enough low latency for your needs (or you have an 32 bit system) then you should try the -lowlatency kernel.If the -lowlatency kernel isn't enough then you should try the -rt kernelIf the -rt kernel isn't enough stable for you then you should try the -realtime kernel-generic——>preempt——>lowlatency——>rt——>realtime, [the fewer the delays, the higher the power consumption]Introducing 'isorespin.sh' templates | ImportantResize EFI partitionLatest improvements to isorespin.sh | rclone copy GDrive:rclone/ ~/downloadsFixing broken HDMI audio (again)Fixing broken HDMI audioRespinning ISOs with rEFIndISO respin script now handles SourceForge outagesAdding and deleting kernel boot parameters with isorespin.sh | ImportantCompiling your own kernel using isorespin.sh | Important