Como instalar Linux num Positivo ZX3040 ou ZX3020 em dual boot com Windows e Android. These steps explain how to install Linux and Android alongside Windows on a Positivo ZX3040 or ZX3020.

System

product: WCBT1013 (3600937)
vendor: Positivo Informatica SA
serial: 1AG01YX6O
BIOS: UEFI 32 bit, American Megatrends Inc., version 1.7, date 06/09/2015, size: 64KiB, Specification Revision: 2.31, Revision: 5.8
Intel Bay Trail SoC
Intel(R) Atom(TM) CPU Z3735G @ 1.33GHz x86_64 model 55 stepping 8 microcode 0x829
System Memory DIMM DDR3 1GiB, width 64 bits, clock 1333MHz (0.8ns)

Intel Corporation Atom Processor Z36xxx/Z37xxx Series Graphics & Display (rev 0f)
Intel Corporation USB xHCI (rev 0f)
Encryption controller Trusted Execution Engine (rev 0f)
ISA bridge: Intel Corporation Atom Processor Z36xxx/Z37xxx Series Power Control Unit (rev 0f)
wireless RTL8723BS via sdio

Disk /dev/mmcblk0: 15.6 GB (internal flash)
Disk /dev/mmcblk2 (microSD)

Output of udevadm info --export-db.

Creating a bootable Pendrive

Pendrive Image

Download a complete compressed image (partition table, boot partition and linux partition). On Windows use pkzip to unzip the file and Win32 Disk Imager to write it to a pen drive.

The pendrive capacity must be at least 4GB. Any data on the pendrive will be lost.

If You want to create the pendrive image yourself, follow the steps in the following subsections.

Distribution

Using another PC, install CentOS 7 Minimal ISO on a bootable pendrive. The partition table should be GPT and the first partition on the pendrive must be VFAT. The size of the VFAT partition can be minimal (35MB). Before You can boot on the ZX3040, the following kernel must be installed.

Kernel

Installing alternative kernel

Boot the pendrive on another PC. As user root do:

yum install -y "http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm"

yum install -y kernel-ml-4.12.0-1.el7.elrepo.x86_64
e2label $(mount |grep " / " |cut -d' ' -f1) CentOS7

Boot Partition

The pendrive must contain a VFAT partition that contains the file /EFI/BOOT/bootia32.efi, along with an appropriate /boot/grub/grub.cfg like this:
terminal_output console
set timeout_style=menu
set timeout=5
set tuned_params=""
set default=0

insmod part_gpt
insmod fat
insmod ext2

menuentry 'CentOS Linux (4.12.0) 7 (Core)' --class centos --class gnu-linux --class gnu --class os {
        set gfxpayload=1280x800
        insmod gzio
        search --no-floppy --label --set=root CentOS7
	linux /boot/vmlinuz-4.12.0-1.el7.elrepo.x86_64 root=LABEL=CentOS7 ro crashkernel=auto nomodeset LANG=en_US.UTF-8
	initrd /boot/initramfs-4.12.0-1.el7.elrepo.x86_64.img
}
menuentry "Microsoft Windows" {
        echo "Loading Microsoft Windows 10 ..."
        insmod chain
        chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

The files vmlinuz-4.12.0-1.el7.elrepo.x86_64 and initramfs-4.12.0-1.el7.elrepo.x86_64.img must be copied from the /boot directory of the linux root directory to the /boot directory of the boot partition.

In case more space is needed on the boot partition, depending on your boot language, the files cht_boot.ttf, jpn_boot.ttf, kor_boot.ttf can be removed from the directory EFI/Microsoft/Boot/Fonts.

Boot Linux on the ZX3040

UEFI Setup

After pressing the power button, when POSITIVO appears on the screen, hit F11 to Enter Setup. Disable Secure Boot in the Security Tab. Disable Quiet Boot in the Boot Tab.

Only the internal flash disk and a pendrive plugged into the detachable keyboard can be used for booting.

At power on press F11 to choose boot from pendrive.

Boot from internal flash to microSD

Afaik, there is no means to access the Windows boot partition from Windows, so Linux is needed to set up boot from internal flash, which means that booting from pendrive needs to be done first.

Copy Linux to microSD

Using another PC, copy the Linux partition from the pendrive on a microSD card. The VFAT partition is not needed on the microSD card.

"Copy the partition" means creating a partition table with a partition of appropriate size and then doing something like dd if=/dev/sda2 of=/dev/sdb1

Depending on the capacity of the microSD, one can increase the partition size using a tool like gparted and/or create additional partitions on the microSD.

Set up dual boot

On the ZX3040, boot from pendrive and log in as root to be able to set up boot from microSD.

Mount USB pendrive boot partition and Windows boot partition:
cd /mnt
mkdir pd
mount /dev/sda1 pd
mkdir wb
mount /dev/mmcblk0p2 wb 

The newest version of Windows 10 uses /dev/mmcblk0p2 as boot partition, an older version that came preinstalled used /dev/mmcblk0p1

Move away Windows files and copy files from pendrive to Windows boot partition:
mv wb/EFI/BOOT/Microsoft wb/EFI/BOOT/Microsaft
mv wb/EFI/BOOT/bootia32.efi wb/EFI/BOOT/bootia32_win.efi
cp pd/EFI/BOOT/bootia32.efi wb/EFI/BOOT/
cp -r pd/boot wb/
cp /boot/vmlinuz-4.12.0-1.el7.elrepo.x86_64 wb/boot
cp /boot/initramfs-4.12.0-1.el7.elrepo.x86_64.img wb/boot

If the Windows boot partition is at /dev/mmcblk0p1, You need to edit the file grub.cfg accordingly (set root='hd0,gpt1').

Shut down:
systemctl poweroff

Remove the pendrive and insert the microSD card into its slot in the ZX3040. Power on and when the word "POSITIVO" appears hit F11 and option "UEFI OS" will appear on the menu. This option leads to grub. The option "UEFI OS" will not appear if You omitted the mv .../Microsoft .../Microsaft.

In BIOS setup one can set UEFI OS as the default.

After the first successful boot, you should do
mv wb/EFI/BOOT/Microsaft wb/EFI/BOOT/Microsoft 

for Windows updates to work correctly.

WiFi

Works out of the box.

To connect to an access point named LAD use the command:
nmcli dev wifi connect LAD password ....
and replace .... by the password.

Bluetooth

Patch

https://github.com/burzumishi/linux-baytrail-flexx10/raw/master/kernel/patches/v4.8/0008-rtl8723bs_rfill_bluetooth.patch

This patch adds { "OBDA8723", RFKILL_TYPE_BLUETOOTH } in rfkill-gpio.c

Kernel .config

Set CONFIG_SERIAL_8250_DW=m and CONFIG_RFKILL_GPIO=m.

Command to compile kernel: make INSTALL_MOD_STRIP=1 rpm

Driver

https://github.com/lwfinger/rtl8723bs_bt

as root:
make
make install
./start_bt.sh 
systemctl restart bluetooth
sleep <??>
hciconfig -a
hciconfig hci0 up
hciconfig hci0 piscan
hcitool scan

Start the Bluez command line client:
bluetoothctl

list available devices (you can also search for new ones separately):
devices

Note the MAC address of the devices that you wish to pair. E.g.:
90:7F:61:11:0E:52

Pair with the device:
pair 90:7F:61:11:0E:52

Trust the device (skip the laborious code entering step for keyboards):
trust 90:7F:61:11:0E:52
send a file as user:
bluetooth-sendto <filename>

3G Modem

ZTE K3565-Z, Vendor 19d2, Product 0063

Installation

yum install usb_modeswitch ModemManager libqmi-utils
cat ->/etc/qmi-network.conf 
APN=gprs.oi.com.br for Brazil
APN=event.vodafone.de for Europe

^D

Connect

Needs to be done every time after the USB dongle is inserted:

qmicli -d /dev/cdc-wdm0 --dms-uim-verify-pin=PIN,XXXX only for Europe
qmi-network /dev/cdc-wdm0 start && dhclient wwp0s20u2u2i4

Disconnect

should be done before disconnecting USB dongle or to restart dongle without disconnecting it:
qmi-network /dev/cdc-wdm0 stop && killall dhclient

Sound

Kernel .config

Set CONFIG_SND_SOC_INTEL_BYTCR_RT5640_MACH.

Copy firmware from https://github.com/Asus-T100/firmware/tree/master/intel to /usr/lib/firmware/intel.

Follow instructions in https://github.com/plbossart/UCM/tree/master/bytcr-rt5640

Backup here.

No working mic input. Use USB headset.

X

The Linux system partition should be at least 10 GB to use X.

yum groupinstall "X Window System"
yum install gnome-classic-session

Use lightweight:

FLWM Window Manager - copy it to /usr/local/bin
copy flwm.desktop to /usr/share/xsessions/

Touch Screen

Works out of the box.

Recommended virtual keyboard: xvkbd

Battery Monitor

Kernel .config

CONFIG_I2C_DESIGNWARE_BAYTRAIL=y
CONFIG_MFD_AXP20X=y
CONFIG_MFD_AXP20X_I2C=y
CONFIG_AXP288_FUEL_GAUGE=m
CONFIG_AXP288_ADC=m
CONFIG_EXTCON_AXP288=m
CONFIG_AXP288_CHARGER=m

Output

battery level in %:
cat /sys/class/power_supply/axp288_fuel_gauge/capacity
charger connected:
cat /sys/class/power_supply/axp288_charger/online
current from (or into) battery:
cat /sys/class/power_supply/axp288_fuel_gauge/current_now

Backlight

Todo

Acelerometer

https://github.com/hadess/iio-sensor-proxy

monitor-sensor works, but display does not tilt because Gnome too old (is 3.14, should be >= 3.18)

Lid Switch

/dev/input/event0

Test protocol for c-state bug

https://bugzilla.kernel.org/show_bug.cgi?id=109051

Boot with USB-serial adapter and kernel parameter console=ttyUSB0,230400 clocksource=refined-jiffies.

During up to 2 shifts of 12 hours (up to 24 hours) run

4 instances of https://bugzilla.kernel.org/attachment.cgi?id=248841

and

in a directory containing 10 full HD videos of duration between 45 seconds and 2 minutes run this code:
#!/bin/bash
for s in {1..1000}; do
  for f in *; do
    ffplay -loglevel panic -autoexit "$f"
    sleep 60
  done
done

and

with internet connection via ethernet run
glances -s

and

in another PC run
glances -c @zx3040 -t 10

where zx3040 is the IP adress of the computer under test

and

via ssh run
powertop

with tab Idle stats

If no freeze is observed, the kernel is called good for the computer under test.

If a freeze is observed, the test must be repeated with intel_idle.max_cstate=1. If no freeze is observed the kernel is called bad for he computer under test. If a freeze is observed, there is a different bug, not a c-state bug 109051.

Blind Test

kernel-4.4.0 froze after 12h30m, up 2x13h with cstate=1.

Android

Install repo utility

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo 

Compile android-x86

nougat-x86 does not compile

mkdir android-x86
cd android-x86
export PATH=/usr/java/jdk1.7.0_80/bin:$PATH
repo init -u http://scm.osdn.net/gitroot/android-x86/manifest -b marshmallow-x86
repo sync --no-tags --no-clone-bundle
. build/envsetup.sh
lunch android_x86_64-user
m -j4 iso_img 
mount out/target/product/x86_64/android_x86_64.iso /mnt/x
cd /mnt/x
cp *.img system.sfs kernel /
cp boot/grub/grub.cfg /boot/efi/boot/grub 

booting, but no touch screen, etc.

trying to use kernel 4.12

mkdir android-x86
cd android-x86
repo init -u http://scm.osdn.net/gitroot/android-x86/manifest -b marshmallow-x86
repo sync --no-tags --no-clone-bundle
cd  kernel
git remote add maurossi https://github.com/maurossi/linux
git fetch maurossi kernel-4.12
git checkout FETCH_HEAD
cd ..
export PATH=/usr/java/jdk1.7.0_80/bin:$PATH
. build/envsetup.sh
lunch android_x86_64-user
m -j6 iso_img
... 

booting debug mode, restart after second exit.