Author Archives: vonger

VoCore2: Ethernet x5 + SD card mode

MT7628AN has a weird design. Ethernet port 1,2,3,4 must be all on or all off, that means if use you only one of them, rest 15 pins you have to use as ethernet but can not work in GPIO mode or SD card mode.
So how can we have SD card mode also have more than one ethernet port.

There is a hidden register, we find in mediatek SDcard driver, and I also hacked a router to get the pins out, pins can be find at vocore.io/v2.html

Here is the patch:

--- a/drivers/mmc/host/mtk-mmc/sd.c
+++ b/drivers/mmc/host/mtk-mmc/sd.c
@@ -2739,7 +2739,7 @@
     struct msdc_host *host;
     struct msdc_hw *hw;
     int ret, irq;
-	u32 reg;
+	u32 reg, reg1;
 
     printk("MTK MSDC device init.\n");
     mtk_sd_device.dev.platform_data = &msdc0_hw;
@@ -2754,8 +2754,11 @@
 	//#elif defined (CONFIG_RALINK_MT7628)
 		/* TODO: maybe omitted when RAether already toggle AGPIO_CFG */
 		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x3c));
-		reg |= 0x1e << 16;
+		reg &= ~(0x1e << 16);
 		sdr_write32((volatile u32*)(RALINK_SYSCTL_BASE + 0x3c), reg);
+		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x60)) & ~(0x3<<0) & ~(0x3<<6) & ~(0x3<<10) & ~(0x1<<15) & ~(0x3<<20) & ~(0x3<<24) | (0x1<<0) | (0x1<<6) | (0x1<<10) | (0x1<<15) | (0x1<<20) | (0x1<<24);
+		reg1 = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x1340)) | (0x1<<11); //Normal mode(AP mode) , SDXC CLK=PAD_GPIO0=GPIO11, driving = 8mA
+		sdr_write32((volatile u32*)(RALINK_SYSCTL_BASE + 0x1340), reg1);
 
- 		reg = sdr_read32((volatile u32*)(RALINK_SYSCTL_BASE + 0x60)) & ~(0x3<<10);
 #if defined (CONFIG_MTK_MMC_EMMC_8BIT)

VoCore2: Weird Issue of Audio

Just fixed that audio record issue last week, but a new issue comes.

If we play wav before record wav, everything works; if we directly record audio, it will not work, and even worse, it will crash the kernel, cause system reboot.

First, I think it is DMA issue, but when I remove my last patch which set audio chip register 0x2B to 0x80, I can record(but data in file is not correct) and system won’t reboot. So it should not DMA issue.

Second, maybe LRCLK or MCLK or BCLK? Now I am using slave mode(master mode clock do not support FS=272, if we record in 272 it will have noise). It might be such issue, have to do more test and monitor I2S pins.

VoCore2: new firmware 20190422

Now new firmware is ready at http://vonger.cn/misc/vocore2/20190422.bin

new firmware is ready at http://vonger.cn/misc/vocore2/20190422.bin
 
New features for VoCore2 and its screen
 
– add ext4 driver to firmware.
– add librt to firmware.
– default support Qt/GDB debug.
– add framebuffer driver and fbcon for console to firmware.
– add dosbox/libsdl makefile to vocore2 github.
– new vocore2 banner in firmware.
– add vocore2 screen driver support to screen sdk.
– add keyboard support to DOOM demo in screen sdk.
 
Bug Fix:
 
– fix audio record issue in 44.1kHz.
– fix feeds source duplicated.
– fix some spell mistake on github.

VoCore2: Extend Storage and Memory

This tutorial need preinstall kmod-fs-ext4.

Extend Storage

Openwrt is using overlay file system, so we can directly attach sd disk or usb disk to overlay use it as extend storage to store more applications.

Default /etc/config/fstab

config 'global'
option	anon_swap	'0'
option	anon_mount	'0'
option	auto_swap	'1'
option	auto_mount	'1'
option	delay_root	'5'
option	check_fs	'0'

config 'mount'
option device '/dev/sda1'
option enabled '1'

config 'mount'
option device '/dev/mmcblk0p1'
option enabled '1'

This defined VoCore will mount sd disk or usb disk automatically.

If we want to attach SD disk as /overlay to enhance the application storage, we need add one line.

...

 config 'mount'
 option device '/dev/mmcblk0p1'
+option target '/overlay'
 option enabled '1'

Then we will have a much bigger system disk.(call df show list)

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 2816      2816         0 100% /rom
tmpfs                    62616       508     62108   1% /tmp
/dev/mmcblk0p1        29963132     45164  28372856   0% /overlay
overlayfs:/overlay    29963132     45164  28372856   0% /
tmpfs                      512         0       512   0% /dev
/dev/mmcblk0p1        29963132     45164  28372856   0% /mnt/mmcblk0p1

In LuCI it is looks like this:

Note: SD/USB storage file system better to be ext4. Other system should work too but might have some issues.

Extend Memory

This “extend memory” is not real memory, it is a swap buffer in SD disk or USB disk. To use it is very simple, just like we use swap in Linux.

Default firmware we already have necessary tools for swap.

  1. make an empty file(for example 128MB) as swap: dd if=/dev/zero of=/mnt/mmcblk0p1/swap bs=1M count=128
  2. setup it as swap file: mkswap /mnt/mmcblk0p1/swap
  3. add this swap to system: swapon /mnt/mmcblk0p1/swap
  4. check the swap: free
             total       used       free     shared    buffers     cached
Mem:        125232      98940      26292        888       3836      76424
-/+ buffers/cache:      18680     106552
Swap:       131068          0     131068

 

 

Screen: Framebuffer Driver Usage

New SDK comes(download at http://vonger.cn/misc/screen/v2screen.tar.xz). Also new port of DOOM, this time, it reaches its max speed, the app is not laggy anymore.

Now we have two versions. One is VoCore version which is big endian, other is DJN version which is little endian.

Big endian is hardware optimized for 24bit bitmap, so you can display 24bit bitmap directly by memory copy.

Little endian is mainly for 16bit bitmap, we use it for frame buffer, so Qt and SDL such library are easily run on it without modify any code.

The two versions are using same driver board.

How to use fbusb.ko

  1. first your firmware must support frame buffer driver, currently firmware after 20190301 support it already.  If you want to use it in your own firmware, you need to select in openwrt source code “make kernel_menuconfig” > Device Drivers > 

    Graphics support > Frame buffer Devices > Support for frame buffer devices.

  2. now your firmware is ready, use scp copy fbusb driver to your vocore2 /root folder. The driver is in screen SDK(http://vonger.cn/misc/screen/v2screen.tar.xz), lib/vocore2/ folder, its name is fbusb.xxxx.ko (xxxx is your screen type)
  3. final step is insert the ko file to your kernel. Call command insmod /root/fbusb.* , if everything works, after this you will find a frame buffer device at /dev/fb0.
  4. now we can test framebuffer, dd if=/dev/urandom of=/dev/fb0 bs=1000 count=768, then you can find random picture on the screen.

Beginner: OpenWrt 18.06.02 stable version

    1. Download from github,

      git clone https://github.com/openwrt/openwrt.git

    2. Checkout stable version 18.06.02, go to new openwrt folder then

      git checkout v18.06.2

    3. Install and  update LuCI, in openwrt folder,
      1. ./scripts/feeds update luci
      2. ./scripts/feeds install -a -p luci
    4. Install vocore2 patch to package, cd openwrt/package, 

      git clone https://github.com/vonger/vocore2.git

    5. Patch openwrt with VoCore2 addition feature support. in openwrt folder,

      patch -p1 < ./package/vocore2/mt7628/openwrt/000-vocore2-compatible.patch

    6. Patch LuCI with VoCore2 addition feature support. patch -p1 < ./package/vocore2/mt7628/openwrt/luci/*.patch

    7. Copy iwinfo patch to iwinfo folder

      1. mkdir ./package/network/utils/iwinfo/patches
      2. cp ./package/vocore2/mt7628/openwrt/080-iwinfo-compatible-ralink.patch ./package/network/utils/iwinfo/patches/
    8. Patch openwrt with VoCore2 es8388 patch for sound.
      1. patch -p1 < ./package/vocore2/es8388/openwrt/000-openwrt-compatible-sound.patch
      2. cp ./package/vocore2/es8388/openwrt/810-es8388-support.patch ./target/linux/ramips/patches-4.14/
    9. Follow the README.md in ./package/vocore2/README.md: 3. config mt7628 in make menuconfig

VoCore2: Develop on Qt Creator

For the people who do not like Java, now we can use Qt creator to make and debug our application remotely instead of Eclipse.

First, better to use 20190127.bin or later version as your firmware, after the tutorial, once you connect VoCore2 to internet, it is easy for you to download applications from openwrt.

We need to install some packages on VoCore2:

opkg install openssh-sftp-server
opkg install libstdcpp
opkg install gdbserver

Now VoCore has setup.

Let’s setup Qt and openwrt on your PC.

  1. We need to patch gdb, I have submitted the patch to github.com/vonger/vocore2, just do all the compile as Beginner Tutorial, it will be ready.
  2. Install gdb. Ye, it is right, if we do not install gdb there will missing some package.
    1. goto path/to/openwrt/build_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/gdb-8.0.1
    2. call “make install”
  3. Make and install Qt.
    1. in make menuconfig -> Library -> Qt5, you can select qt5-core, and ‘M’ is OK, it is pretty big, so do not select as ‘*’
    2. make everything, takes pretty long time.
    3. goto path/to/build_dir/target-mipsel_24kc_musl/qt-everywhere-opensource-src-5.9.7
    4. call “make install”

Final step, setup Qt creator on your PC(path is just example, use your path of openwrt).

    1. Qt Creator -> Preferences -> Devices -> Devices -> Add -> Generic Linux Device
      • Name: VoCore2
      • Authentcation Type: Password
      • Host name: 192.168.61.1
      • SSH port: 22
      • Username: root
      • Password: vocore
    2. Qt Creator -> Preferences -> Kits -> Compilers -> Add -> GCC -> for both C/C++
      • Name: VoCore2 GCC and VoCore2 G++
      • Compiler path (GCC): openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-gcc
      • Compiler path (G++): openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-g++
    3. Qt Creator -> Preferences -> Kits -> Compilers -> Debuggers -> Add
      • Name: VoCore2 GDB
      • Path: path/to/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/mipsel-openwrt-linux-musl-gdb
    4. Qt Creator -> Preferences -> Kits -> Qt Versions -> Add.
      • Version Name: Qt 5.9.7 for VoCore2 mips
      • qmake location: path/to/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/bin/qmake
    5.  Qt Creator -> Preferences -> Kits -> Kits -> Add.
      • Name: VoCore2 Qt 5.9.7 (gcc OpenWrt mips)
      • Device Type: Generic Linux Device
      • Device: Generic Linux Device (default for Generic Linux)
      • Compiler: C, VoCore2 GCC; C++, VoCore2 G++
      • Debugger: VoCore2 GDB
      • Qt version: Qt 5.9.7 for VoCore2 mips

Then create a project, in .pro file, add this lines:

target.path = /tmp
INSTALLS += target

Then you can debug it as your other Qt application.

note: for macos, you need to install texinfo, or gdb will fail to install.

Beginner: OpenWrt 18.06 stable version 6(final)

Now we already have the firmware, I also upload it to http://vonger.cn/misc/vocore2/20190127.bin

How to use upgrade to this firmware?

  1. Connect to VoCore2 by network: ethernet or wifi both is good.
  2. Open browser by 192.168.61.1, username root, password vocore.
  3. In the top menu, select System -> Backup/Flash firmware -> Uncheck ‘Keep settings’ -> Click ‘choose file’ under that checkbox, select 20190127.bin in your local folder -> Click on button ‘Flash Image…’
  4. In next page, md5 should be f4d08cca2b944abd4e4bedd273f1d3d8, then click ‘Process’.
  5. Upgrade is in process now, wait around five minutes, it will be done, do not power off your VoCore.

How to connect to other wireless network?

Normally I call it ‘AP+STA mode’, AP means VoCore2 will broadcast itself, so you can find its SSID “VoCore2-xxxx” in your computer or smart phone wifi list. STA means station mode, it is used to connect to other wireless router. For example, my home wireless router SSID is ‘KOKO’, so I can connect to it and cross internet through its network. AP + STA mode means I can broadcast VoCore2 SSID but same time we can connect to my home router, in another word, it is a bridge between computer and home router, so we call it bridge mode too.

In LuCI, it is pretty simple to setup:

  1. If you bootup VoCore2 for first time, you need to wait 5 minutes, first boot up VoCore2 need time to create rsa keys for ssh and initialize the on board flash.
  2. Connect to VoCore2 by network: ethernet or wifi both is good.
  3. Open browser by 192.168.61.1, username root, password vocore.
  4. In the top menu, select Network -> Wireless, in ‘Wireless Overview’ you can find three units: Generic WEXT 802.11,  SSID: VoCore2-xxxx, SSID:(empty).
    1. First one is ra0 setting, which is our wireless network card, do not modify it, I do not know what it is used to yet 🙂
    2. second one is AP setting, we can change VoCore2 broadcast SSID name and enable password WPA2 or other mode.
    3. Third one is STA setting, we can use it connect to other wireless router.
  5. Let’s connect to other wireless router for internet. Click the button ‘Edit’ in that line, in submenu ‘General Setup’, set ESSID to other wireless name, for me it is YOURSSID;then select submenu ‘Wireless Security’, select correct encryption and key for your router. Now, setting is ready, do not click on the ‘Save & Apple’ or ‘Save’ or ‘Reset’ at bottom, click on the ‘Enable’  button after ‘Wireless network is disabled’, once click it will have a thirty seconds count down.
    1. if you connect to VoCore2 by ethernet, it will be done automatically.
    2. If you connect to VoCore2 by wireless, you need to connect your computer back to VoCore2 before count down end! Or your setting will be rollback, because once you click on the ‘Enable’ button, VoCore2 wireless network is restarted and you are disconnected.
    3. because of point 2, better to use ssh login and directly use vi modify /etc/config/wireless in VoCore2. remove ‘disable’ line in sta section and add ‘option ssid YOURSSID’ and add ‘option key yourpassword’ to sta section. Then reboot wifi it will work.
  6. Now all setting done, in top menu, select Network -> Interface, you can find in WWAN line, there is your alloc ip address. (If no such address, connect might fail, you need to reboot VoCore2 or check your password for your local router)

How to install package in VoCore2?

We are using openwrt 18.06.01, the benefit is it can directly download openwrt compiled packages from openwrt official website.

In LuCI it is pretty simple:

  1. make sure you have finished AP+STA mode, and VoCore2 is able to connect to internet.
  2. select top menu ‘System’ -> Software.
  3. You will find ‘No package lists available’ with a button ‘Update lists’
  4. click on ‘Update lists’, wait a few seconds, you have a completed package list which is used to install packages. (Make sure every feeds source passed its checking)
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_pack
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/packages/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/routing/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_rout
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/routing/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/telephony/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_tele
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/telephony/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/18.06.1/targets/ramips/mt76x8/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_core
Downloading http://downloads.openwrt.org/releases/18.06.1/targets/ramips/mt76x8/packages/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/base/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_base
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/base/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/luci/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_luci
Downloading http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/luci/Packages.sig
Signature check passed.

How to play music on VoCore2?

For play mp3 music, we need to install madplay-alsa.

  1. in System->Software page, type madplay in ‘Filter’ box, then click on ‘Find package’
  2. You can find madplay-alsa in the package list, click on ‘Install’ to install it to your VoCore2.
  3. Insert a SD card or USB disk to your VoCore2, make sure it contains mp3.
  4. login to VoCore2 by ssh or serial port, run madplay [path to your mp3 file], then you will hear sound from the device who connected to 3.5mm the jack.

How can I access to VoCore2 (already setup STA mode) through my local network?

  1. Find your VoCore2 IP first, for example, mine is 192.168.31.71, it is in Network -> Interface.
  2. We need to enable wan network access in firewall, it is in Network -> Firewall -> Zones, set wan Input/Forward from reject to accept.
  3. Now we can access VoCore2 through my local network by IP address 192.168.31.71.

Beginner: OpenWrt 18.06 stable version 5

Final puzzle piece for the firmware, the sound.

I spend some time to clean up my last patch, its works perfect now.

It is still all in http://github.com/vonger/vocore2.

patch openwrt first to enable sound setting in DTS(default it is off), and 810 patch is for linux kernel sound driver.

patch -p1 < ./package/kernel/es8388/openwrt/000-*.patch
cp ./package/kernel/es8388/openwrt/810*.patch ./target/linux/ramips/patches-4.14

note: this patch require patch ./package/kernel/mt7628/openwrt/000-vocore2-compatible.patch first.

In make menuconfig, Kernel modules -> Sound Support -> select kmod-sound-corec then kmod-sound-mt7628.
After you make again, now you have a perfect firmware for VoCore2 Ultimate, also very tiny, around 4096KB.

Beginner: OpenWrt 18.06 stable version 4

1,2,3 is enough for VoCore2, for VoCore2 Ultimate, we still missing a lot of drivers and app.

  1. sound driver, such as madplay, asound, arecord can be download from openwrt by opkg, so we do not imply them.
  2. camera driver, we include it this time.
  3. sdcard drive, this is necessary.
  4. file system driver, support vfat.
  5. tools such as lsusb, iperf3, do not imply, because it is easy to download by opk.
  6. mount-block for automatically mount usb or sd card.

For point 2, select Kernel modules => Video Support => select kmod-video-core, select kmod-video-uvc, it will be automatically supported, and we need mjpeg-stream, that can be easily download from openwrt, so we do not imply it this time.

For point 4, select Kernel modules => Filesystems => select kmod-fs-vfat, that’s all, all necessary depends package will be selected.

For point 3 and 6, select Kernel modules => Other modules => select kmod-sdhci-mt7620, also need to select Base system => select block-mount, it is not end, mmc and usb will not mount automatically, we still need one more file fstab to /etc/config/fstab. I have already include it into mt7628 patch 000, so once you install mt7628 patch everything will be ready already.

fstab should like this:

config 'global'
	option	anon_swap	'0'
	option	anon_mount	'0'
	option	auto_swap	'1'
	option	auto_mount	'1'
	option	delay_root	'5'
	option	check_fs	'0'

config 'mount'
	option	device	'/mnt/sda1'
	option	enabled	'1'

config 'mount'
	option  device  '/mnt/mmcblk0p1'
	option  enabled '1'

Now final point 1, I did not have a prefect patch yet, because it require a lot of patch and fix… Let me try tomorrow.