linux-loongson/community (社区版龙芯Linux)

contact project's owner by <wuzhangjin [AT] gmail [DOT] com> Or <r0bertz [AT] gentoo [DOT] org>

If you have any issues, login and create a newticket

Introduction (项目简介)

This project is launched to maintain the latest linux[1] for Loongson, the objective is making the loongson machines be friendly supported.

linux-loongson/community here means it is a community project and welcome everybody's contribution. any questions, suggestions, bug reports and patches are welcome TO the related mailing list and CC to the maintainers.

  • The relationship between this project and the mainline linux kernel(maintained by Linus)
    • this project mainly focus on MIPS(exactly, Loongson), but the mainline linux focus on lots of architectures(X86, PowerPC, MIPS, ARM, Sh, Sparc...).
    • most of the stable patchset in this project will be pushed into linux-MIPS(linux for MIPS, maintained by Ralf) firstly and at last go into the mainline linux.
    • So, if you need the newest or the full loongson specific support, please come here.
  • The relationship between this project and the one maintained by Lemote
    • This project is developed & maintained by the people from community and therefore can get/apply more support from the community, such as bug report, bug fixes and so forth.
    • This project try to update with the mainline linux as soon as possible and try to upstream the stable patchsets in this project to the mainline, then people can get the mostly stable support from mainline.
    • Most of the basic BSP in this project is originally contributed by Lemote and some latest patchsets from the Lemote will also be applied into this project.

So, this project will function as a bridge between the Loongson companies and the community.

---
[1] kernel version >= 2.6.31 are maintained in this project.
for kernel version (>= 2.6.29 & <= 2.6.30) and the real time extension for Loongson, please access http://dev.lemote.com/code/rt4ls
for kernel version = 2.6.27 (from Lemote), please access http://dev.lemote.com/code/linux_loongson

Mailing list (邮件列表)

loongson-dev [AT] googlegroups [DOT] com

Maintainers (维护人员)

Zhang Le <r0bertz [AT] gentoo [DOT] org>
Wu Zhangjin <wuzhangjin [AT] gmail [DOT] com>

Source (内核源代码)

Git repository (Git仓库)

  • Git repo of this project
    • git://dev.lemote.com/linux-loongson-community.git (git protocol, anonymous)
    • http://dev.lemote.com/http_git/linux-loongson-community.git (http protocol, if the git protocol is blocked by firewall)
    • git@dev.lemote.com:linux-loongson-community.git (ssh protocol, if you are this project's owner)
  • Related git repo
    • git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git (linus' git tree, mainline linux)
    • git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6.xx.y.git (greg's git tree series, stable linux)
    • git://www.linux-mips.org/pub/scm/linux.git (Ralf's git tree, linux-mips)

Download (下载)

To get the source code, there are two methods:

  • Clone, pull or fetch one branch of the git repository (user master branch as an example)
$ git clone git://dev.lemote.com/linux-loongson-community.git  // Clone the whole git repository
$ git pull git://dev.lemote.com/linux-loongson-community.git master // Fetch one branch and merge it into your current branch
$ git fetch git://dev.lemote.com/linux-loongson-community.git master // Fetch one branch, not merge it, you can handle the result via the FETCH_HEAD

To get more information about git, please goto the Git part of the Doc Section

Bugs & Workarounds (已知bug和解决办法)

  • RTL8187B Wifi Driver for YeeLoong netbook

The rtl8187b wifi driver can not survive from hibernation, currently, there is no good method to workaround it.

Supported Machines (支持的机器型号)

Compile (内核编译)

Config (配置)

  • default config files
    • FuLoong-2E Box: arch/mips/configs/fuloong2e_defconfig
    • Lemote 2F family of machines: arch/mips/configs/lemote2f_defconfig
  • Config Options
    • CONFIG_LEMOTE_YEELOONG2F: YeeLoong platform specific drivers (backlight, suspend, battery, sensors, hotkey/input...)
    • CONFIG_LEMOTE_LYNLOONG2F: LynLoong platform specific drivers (backlight, suspend drivers)
    • CONFIG_LOONGSON2_CPUFREQ: Loongson-2F cpu frequency scaling driver
    • CONFIG_CS5536_MFGPT: external CS5536 MFGPT Timer (used in Lemote 2F family of machines)
    • CONFIG_FB_SM7XX: SM712 Video Card Driver used in YeeLoong netbook
    • CONFIG_RTL8187B: RTL8187B Wifi Driver used in YeeLoong netbook
    • CONFIG_LOONGSON_SUSPEND, CONFIG_SUSPEND: Suspend support of Lemote-2F machines
    • CONFIG_HIBERNATION, CONFIG_PM_STD_PARTITION="/dev/hda3", Hibernation support, /dev/hda3 is the swap partition of your machine, you can pass "resume=/dev/hdaX" to override it.

Local-Compile (本地编译)

  • Local-Compiler

For a distribution which did not explicitly say they have compiled the toolchains with the patch (This patch have been merged into cvs repository of binutils), Please download the fix-nop.c from Heihaier, and fix your toolchains as following:

$ make fix-nop
$ ./fix-nop $(which ld)
$ ./fix-nop $(which as)
  • Compile
$ make menuconfig
$ make -j2
$ make modules_install
$ make install

Cross-Compile (交叉编译)

  • Exisiting cross-compiler

Gcc 4.4.1 + Binutils 2.20 on X86

(!Note: you need to config the PATH and LIBRARY_PATH environment in /etc/profile or .bashrc for the cross-compiler)

  • Build Cross-Compiler for Loongson from scratch

English Version 32bit 64bit, Chinese Version

(!Note: A patch for binutils 2.20 is needed, but for the version in cvs repository, the patch is already in.)

  • Compile
  $ make menuconfig ARCH=mips
  $ make CROSS_COMPILE=<prefix>- ARCH=mips -j<N>
  $ make modules_install INSTALL_MOD_PATH=/path/to/modules_install_directory
  $ make install INSTALL_PATH=/path/to/kernel_image_install_directory

Boot (引导)

You need to edit the config file(/boot/boot.cfg) of PMON to boot the new kernel, here is an example:

# /boot/boot.cfg
default 0
showmenu 1

title Fedora MIPS/N32
        kernel (wd0,1)/boot/vmlinuz-2.6.31-0.167.rc5.fc11.mips64el
        args console=tty root=/dev/sda2

The above configuration means:

"default 0" means if there are lots of config entries in the boot.cfg, the default entry is the first one.
"showmenu 1" menas the menu will be shown.
"title" indicates the Title of the entry shown in the menu, here is "Fedora MIPS/N32".
"kernel" indicates the path to the kernel image file, (wd0, 1) here indicates the /dev/sda2, so, it means vmlinuz-2.6.31-0.167.rc5.fc11.mips64el is stored in the /dev/sda2 partition and put into the /boot directory. If you have stored the kernel image in /dev/sda4, please use (wd0,3) instead.
"args" indicates the kernel command line arguments. root=/dev/sda2 means the partition stored the root file system is /dev/sda2.

Please get more information from the PMON document(in Chinese).

BIOS & Bootloader (BIOS和引导器)

PMON

PMON is the current BIOS & Bootloader pre-installed on the loongson family of machines. its homepage: http://dev.lemote.com/code/pmon. The PMON for gdium has a different repository tree. http://dev.lemote.com/code/pmon-gdium

Grub

Grub itself is only a bootloader, which have been ported to YeeLoong for the Gnewsense project. but perhaps you can make it work in the other distributions.

Grub 1.98 is available for YeeLoong, but currently, it can only be loaded from PMON.

U-boot

A primary version for YeeLoong is available here: http://dev.lemote.com/code/U-boot

U-EFI

Not usable yet, homepage: http://dev.lemote.com/code/EFI-MIPS

GNU/Linux distribution (龙芯Linux发行版)

Rescue & Recovery system (急救与还原系统)

Rescue system is always needed when you have broken the whole system, you can load it via tftp protocol or from a u-disk to get a basic system ;)

Recovery system(support all of Loongson-2F machines made by Lemote) will help to _format_ your broken system and re-install a basic system there(be careful!).

You just need to download all of the files from http://dev.lemote.com/update/recovery/latest/ to your u-disk, and then boot your machine from u-disk via pressing the u key when booting(please ensure the boot.cfg is okay or load and boot the kernel from the u-disk manually on the PMON command line), at last, you will get a recovery interface.

Gnewsense (Recommend)

Gnewsense is a 100% free/libre GNU/Linux distribution developed by FSF. Installation guide is available here:

http://wiki.gnewsense.org/Projects/GNewSenseToMIPS

Loonux

Loonux is based on the GNU/Debian developed by Lemote, and it is a distribution pre-installed in the loongson machines, but the software repository of this distribution is _too_ old!

Installtation guide: English Version Chinese Version

Debian 6.0 (Recommend)

This Debian 6.0 is not that one from the official debian, but improved from it, which is developed by Liu Shiwei. Why this one? it is newer and better than the one from Lemote and also from the official debian, which provides feature-rich kernel, accelerated video driver...

please get it here: http://www.anheng.com.cn/loongson/install/
Install: download the latest compressed system, decompress it to one of the partitions and config /boot/boot.cfg then boot it.

Gentoo n32

Gentoo now provides experimental stage3 on its official mirrors. It is located under experimental/mips/stages/loongson/ of each mirror, like http://mirrors.xmu.edu.cn/gentoo/experimental/mips/stages/loongson. This is maintained by Zhang Le. It will be updated regularly. You should use Gentoo Loongson Overlay which is also maintained by Zhang Le.

An older stage4 could be get here: http://www.bjlx.org.cn/loongson/gentoo/, the root user's password is loongson. This one is provided by zenglanmu, based on Zhang Le's previous work http://tinyurl/loongson-gentoo. Thanks to Liu Shiwei for hosting it.

Fedora n32

This should be like the Gentoo n32, but softwares are packaged in RPM format, the root user's password is redhat, this is maintained by lazyfai.
please get it here: http://lazyfai.dyndns.org/loongson/fedora-n32-rootfs-20091017.tar.gz

A new project of porting Fedora to the MIPS architecture was launched at https://fedoraproject.org/wiki/Architectures/MIPS

Virtual Machines (虚拟机)

Gxemul

There is an existing gxemul for Loongson-2E, user guide(in Chinese)

Qemu

There is an exisiting Qemu patch for loongson-2E(user manual in chinese), the version for Loongson-2F is in the progress of development and maintained in this git repo by Zhou Yajin(Not active).

Note: 'Cause Loongson is a MIPS-III compatible processor, most of the instructions are the same as the other MIPS-III processors, you can use the Qemu/Malta or the above Qemu/Loongson-2E to emulate the Loongson family of machines.

Doc (开发文档)

Loongson Developers Manual (龙芯开发者手册)

Git Documentation (Git使用文档)

Loongson User Manual (龙芯处理器用户手册)

CS5536 Datasheet (南桥cs5536规格书)

SM712 Specification (显卡SM712规格书)

SM502 Specification (显卡SM502规格书)

TODO (待做工作)

Linux-Mainline

http://kernelnewbies.org/KernelProjects

Linux-MIPS

http://www.linux-mips.org/wiki/Todo_List

More:

  • Maintain the Hibernation support for MIPS
    arch/mips/power/
  • Maintain the Ftrace support for MIPS
    arch/mips/kernel/{ftrace.c, mcount.S}
    The latest development status: [v6] MIPS: tracing: adds misc cleanups and fixups, http://patchwork.linux-mips.org/patch/1128/
  • Maintain the Compressed-kernel support for MIPS
    arch/mips/boot/compressed/
  • Adds MIPS specific dma_mmap_coherent()
    This is necessary for ALSA audio output, without it, the audio output will be broken.
    // ok
    $ mplayer -ao oss file.mp3
    // broken without dma_mmap_coherent()
    $ mplayer -ao alsa file.mp3
    
    please learn more here: http://www.linux-mips.org/archives/linux-mips/2008-08/msg00178.html

Note!: A workaround have been added in sound/core/pcm_native.c, please refer to snd_pcm_default_page_ops().

Linux-Loongson

  • Fix the NOP issue of Loongson2F in kernel space
    Heihaier have contributed the primary patch, please get more information from loongson-dev google group: Dynamic fix loongson2f nop in kernel
  • Maintain the latest linux(>=2.6.34) for Loongson
    arch/mips/oprofile/ (loongson2 oprofile support)
    arch/mips/kernel/cpufreq/ (loongson2 cpu freqency scaling support)
    arch/mips/loongson/common/pm.c (loongson2 Suspend support)
    arch/mips/pci/{fixup-fuloong2e.c, fixup-lemote2f.c, ops-loongson2.c} (Loongson2 pci support)
    arch/mips/loongson/{fuloong-2e, lemote-2f}/ (loongson family of machines support)
    arch/mips/include/asm/mach-loongson/ (loongson platform specific header files)
  • Upstream the left YeeLoong platform specific drivers
    drivers/platform/mips/ or http://patchwork.linux-mips.org/project/linux-mips/list/?q=YeeLoong
  • Add Genirq threading support for the platform drivers
    Convert the irq handlers under drivers/platform/mips to irq threads. please refer to:
    genirq: add threaded interrupt handler support
    USB genirq infrastructure for threaded interrupt handlers V2
  • Maintain the Silicon Motion Driver (SM712 video card driver)
    drivers/staging/sm7xx/, please refer to the TODO file
  • Maintain/Upstream the RTL8187B wifi driver
    drivers/net/wireless/rtl8187b/, to ensure it work with the potential new APIs or make the mainline similar drivers support rtl8187b.
  • Merge all of the loongson machines' support
    Merge the fuloong-2e, lemote-2f and gdium support, then all of the loongson machines can use the same kernel if not enable the 2e, 2f specific instructions.
  • Power Management stuff
    Move the loongson2_wait() out of the cpufreq driver to the common source code to make the cpu_wait() always be set and optimize the cpufreq support.
    Some works have been contributed by Gang Liang: http://www.spinics.net/lists/mips/msg37905.html
  • Clean up the CS5536 support
    based on arch/mips/loongson/common/cs5536/ and include/linux/cs5535.h, drivers/*/*5535*
  • Add new Gdium machine support
    The latest support is available here: http://repo.or.cz/w/linux-2.6/linux-mips/linux-gdium.git
    A basic gdium support have been pushed into the dev/gdium branch of linux-loongson/community.
  • Add new LynLoong machine support
  • Add new Loongson-2G, Loongson-3A family of machines support

FAQ (常见问题)

Although this project only care about the linux kernel for loongson machines, but without a good X Window and related driver, people will get a bad experience of the machine, the same to the network support, so, we will give you the latest information of them too.

Translation (文档翻译)

  • How to translate a web page from Chinese to English, and reversely.

'Cause most of the documenations are not written in our familiar language, so, how to get a translation of it, please go to Translate a web page section of the translation support of google, paste the url, select the langauage you want to translate from and to then get what you want.

X window

  • How to make the X window work on my YeeLoong netbook?

You need to install a suitable Xorg-server and the related silicon motion driver or the generic fbdev driver. in the default official debian 6.0, that Xrog-server and the fbdev module works on YeeLoong netbook, but don't have a good performance, If you need the fastest X window for your YeeLoong, the debian 6.0 maintained by LiuShiwei? are recommended.

If you want to get the latest source code and patches of the fastest X window on YeeLoong, please refer to:

All about X support for YeeLoong netbook

  • How to make the external vga output of YeeLoong netbook work?

You can do it via installing xserver-xorg-video-fbdev and using "fbdev" as the "Driver" in the "Device" Section of /etc/X11/xorg.conf, or recompile the xserver-xorg-video-siliconmotion package in the following debian repo:

deb http://www.bjlx.org.cn/loongson2f/squeeze ./
deb-src http://www.bjlx.org.cn/loongson2f/squeeze ./

To recompile it, you need to remove the "//" before the ".set arch=loongson2f" in the file: src/smi_video.c, the steps to recompile it:

0. add the deb repo of Liu Shiwei

add the following lines into /etc/apt/sources.list

deb http://www.bjlx.org.cn/loongson2f/squeeze ./
deb-src http://www.bjlx.org.cn/loongson2f/squeeze ./

1. download the source code

$ apt-get source xserver-xorg-video-siliconmotion

2. fix a problem

The ".set arch=loongson2f" was commented in the patch, but it is needed,
so, please find out the files who include loongson2f, and please remove
the prefix "//".

$ cd xserver-xorg-video-siliconmotion-1.7.3
$ grep loongson2f -ur ./
$ ...

3. compile it

$ dpkg-buildpackage -b -uc

4. install it

$ dpkg -i ../xserver-xorg-vidio-siliconmotion_1.7.3-2.0.loongson_mipsel.deb 

5. please ensure the "Driver" field of the "Device" Section
in /etc/X11/xorg.conf is siliconmotion.

Please refer to the Email thread "Getting the external VGA on Yeeloong to work" in the loongson-dev google group.

Network (网络支持)

To get a better network support, please install the latest NetworkManager? tool into your system.

  • My RTL8187B wifi can not survive from hibernation, how to fix it?

Please refer to the Bug & Workarounds part of the Source section.

  • How to enable my RTL8187 Wifi when booting?

You can append the following line into /etc/rc.local:

echo 1 > /sys/class/rfkill/rfkill0/state
  • How to make a 3G card work on my YeeLoong netbook?

Please refer to how to use 3G card on !YeeLoong netbook(in Chinese).

Audio (音频支持)

  • does YeeLoong? support audio mixing (混音,同时播放多首歌曲)?

Yes, but it only support software audio mixing and need an extra config(attached as cs5535audio.conf) for the ALSA audio output of cs5535audio card.

Install the config:
$ cp /path/to/cs5535audio.conf /usr/share/alsa/cards/
Test:
// on one terminal
$ mplayer -ao alsa file1.mp3
// on another
$ mplayer -ao alsa fil2.mp3
// You may get two different songs
  • does Loongson support ALSA audio output?

Yes, but please install the kernel >= 2.6.33.3, or 2.6.32, 2.6.31

Video (视频支持)

  • Is there Loongson specific optimization for mplayer?

Yes, it is available here: http://dev.lemote.com/code/mplayer

Hibernation & Suspend (休眠与挂起)

All of the Lemote machines support Hibernation if with the suitable kernel(>=2.6.31) and the right config, but only Loongson (>=2F) family of machines(Currently, Only YeeLoong) support Suspend.

  • Kernel config
    • Hibernation support
      Please enable CONFIG_HIBERNATION and config CONFIG_PM_STD_PARTITION="/dev/hdaX"
      /dev/hdaX is the swap partition of your machine, you can pass "resume=/dev/hdaY" to override it.
    • Suspend support of Lemote-2F machines
      Please enable CONFIG_LOONGSON_SUSPEND, CONFIG_SUSPEND
  • Usage
    • Command line interface
      $ cat /sys/power/state
      mem disk suspend
      $ echo disk > /sys/power/state  # Hibernation will power off your machine, resume it via powering on it
      $ echo suspend > /sys/power/state  # Suspend will suspend most of your machines, resume it via pressing any key(except the Fn) on your keyboard
      
    • GUI tools You can install gnome-power-manager or kpowersave to manage Hibernation & Suspend.

Hotkey (热键支持)

  • How to make the hotkey(Function key) work on YeeLoong netbook.

You need to ensure the yeeloong platform driver(CONFIG_LEMOTE_YEELOONG2F) is enabled and also the related user-space applications are installed. for the official debian system, if the yeeloong platform driver is enabled, it should work.

  • Which hotkey does YeeLoong netbook support?
    • Fn+ESC Turn on/off camera input
    • Fn+F1 Sleep buttion, report the SLEEP event to user-space, you can configure the action of the sleep button via kpowersave, gnome-power-manager or the other power manager.
    • Fn+F2 Turn on/off LCD output
    • Fn+F3 Swith CRT/LCD output
    • Fn+F4 Turn on/off Mute
    • Fn+F5 Turn on/off Wifi
    • Fn+F6 Turn on/off touchpad (Supported by the EC ROM directly)
    • Fn+Up/Down Increase/decrease the brightness of the backlight of the LCD
    • Fn+Left/Right Increse/decrease the volume of sound output
  • Is there a tool to test the hotkey support of kernel?

Yes, there is. I have written a simple python script to check the hotkey support of kernel and attached it as hotkey.py. (This script can be used as a simple hotkey daemon).

Usage:

$ sudo apt-get install python-pyosd
$ python hotkey.py  // You can press Fn+{ESC,F1~F5, ^/V, </>} and take a look at the command line output

Sensors (传感器支持)

  • How to get the information of the fan, battery, cpu of YeeLoong netbook?

You also need to enable the yeeloong platform driver(CONFIG_LEMOTE_YEELOONG2F) and install the lm-sensors(or the other related tools, for example, sensors-applet) in your system, then you can get the information via the following command.

$ sensors

Serial Port (串口)

  • Is there a serial port on YeeLoong netbook?

Yes, but there is no existing J2 header, you need to solder one yourself, here is the HOWTO.

Develop (开发)

  • Is there a document about kernel debugging on Loongson platform?

There is no full document currently, but I have written a short document in Chinese, I will translate it later and put it here.

  • Which tools are needed to do basic c programming on Loongson machines?

'Cause Loongson machines use the standard GNU/Linux systems, so, you can use almost all of the tools you can used in the linux system of the other machines, the most important tools include GNU toolchains: gcc, gdb, binutils ...., and the latest gcc 4.4 are recommended for the loongson specific support are only available in this version, to enable the loongson specific support, for loongson2f, please use the option -march=loongson2f, for loongson2e, please use -march=loongson2e.

And again, please remember to use the latest binutils (in the cvs repository) for it provides two new options to workaround the the bug of loongson2f, to get more information about it, please access this page.

  • does loongson support oprofile?

Yes, but you need to get a suitable kernel(>=2.6.33 with CONFIG_OPROFILE=y) which support oprofile and also the user-space oprofile >= 0.9.7 is needed, currently, oprofile >= 0.9.7 is only available in its cvs repository:

$ export CVSROOT=":pserver:anonymous@oprofile.cvs.sourceforge.net:/cvsroot/oprofile"
$ cvs login
$ cvs -z3 co oprofile

// no password is needed, please just press Enter.

Please install build-essential, libpopt-dev and binutils-dev before compiling it, compile:

$ ./autogen.sh
$ ./configure --with-kernel-support
$ make; make install

Usage:

// load the oprofile.ko module
$ opcontrol --init
// set the events, --session-dir= indicate the directory for storing the result, by default it is /var/lib/oprofile
// If you need more events, please try --list-events
$ opcontrol --setup --event=CPU_CLK_UNHALTED:10000:0:1 --no-vmlinux --session-dir=./
// start the oprofiled daemon
$ opcontrol --start 
// do something for profiling
$ ...
// dump the profiling result
$ opcontrol --dump
// stop the profiled
$ opcontrol --stop
// get the profiling report
$ opreport --session-dir=./
// unload the oprofile.ko module
$ opcontrol --deinit

Attachments