2015年3月16日 星期一

How to mount SD card in linux


sudo mkdir /mnt/SD
sudo chown  user:group  /mnt/SD

cat  /proc/partitions 
major minor  #blocks  name

  31     0       4096 mtdblock0
  31     1     519168 mtdblock1
 179     0     995328 mmcblk0
 179     1     995274 mmcblk0p1
---------------
dmesg shows..

mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new high speed SD card at address 0007
mmcblk0: mmc0:0007 SD01G 995328KiB 
 mmcblk0: p1

mount -t vfat /dev/mmcblk0p1  /mnt/SD

sudo mount -t vfat -o rw /dev/mmcblk0p1 /mnt/SD

where is udevinfo in debian?

use udevadm instead.


udevadm info -q all -n /dev/sda1


udev rule guide line


https://wiki.debian.org/udev

http://hackaday.com/2009/09/18/how-to-write-udev-rules/

http://www.reactivated.net/writing_udev_rules.html

udev rule example

https://github.com/trapd00r/configs-n900/blob/master/etc/udev/rules.d/91-permissions.rules

2015年3月10日 星期二

Linux tty raw mode

The TTY demystified
http://www.linusakesson.net/programming/tty/

use stty set tty to raw mode
http://linux.about.com/od/commands/l/blcmdl1_stty.htm

#!/bin/bash

# Port setting
stty -F /dev/ttyS0 raw speed 1200

# Loop
while [ 1 ]; 
do
    echo 'LOADING...'
    READ=`dd if=/dev/ttyS0 count=1`
    echo $READ


echo '[PRESS Ctrl + C TO EXIT]'
done

per
http://man7.org/linux/man-pages/man3/termios.3.html

use cfmakeraw() in C program

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/syslog.h>
#include <sys/types.h>
#include <sys/un.h>

#define SERIALPORT_IS_CONSOLE

main()
{
    struct termios  tty;
    struct termios  savetty;
    speed_t     spd;
    unsigned int    sfd;
    unsigned char   buf[80];
    int     reqlen = 79;
    int     rc;
    int     rdlen;
    int     pau = 0;

#ifdef SERIALPORT_IS_CONSOLE
    sfd = STDIN_FILENO;
#else
    sfd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);
#endif
    if (sfd < 0) {
        syslog(LOG_DEBUG, "failed to open: %d, %s", sfd, strerror(errno));
        exit (-1);
    }
    syslog(LOG_DEBUG, "opened sfd=%d for reading", sfd);

    rc = tcgetattr(sfd, &tty);
    if (rc < 0) {
        syslog(LOG_DEBUG, "failed to get attr: %d, %s", rc, strerror(errno));
        exit (-2);
    }
    savetty = tty;    /* preserve original settings for restoration */

    spd = B115200;
    cfsetospeed(&tty, (speed_t)spd);
    cfsetispeed(&tty, (speed_t)spd);

    cfmakeraw(&tty);

    tty.c_cc[VMIN] = 1;
    tty.c_cc[VTIME] = 10;

    tty.c_cflag &= ~CSTOPB;
    tty.c_cflag &= ~CRTSCTS;    /* no HW flow control? */
    tty.c_cflag |= CLOCAL | CREAD;
    rc = tcsetattr(sfd, TCSANOW, &tty);
    if (rc < 0) {
        syslog(LOG_DEBUG, "failed to set attr: %d, %s", rc, strerror(errno));
        exit (-3);
    }

    do {
        unsigned char   *p = buf;

        rdlen = read(sfd, buf, reqlen);
        if (rdlen > 0) {
            if (*p == '\r')
                pau = 1;
            syslog(LOG_DEBUG, "read: %d, 0x%x 0x%x 0x%x", \
                     rdlen, *p, *(p + 1), *(p + 2));
        } else {
            syslog(LOG_DEBUG, "failed to read: %d, %s", rdlen, strerror(errno));
        }
    } while (!pau);

    tcsetattr(sfd, TCSANOW, &savetty);
    close(sfd);
    exit (0);
}
 more example
http://www.cs.uleth.ca/~holzmann/C/system/ttyraw.c




2015年3月1日 星期日

AndroLua = Luajava + Luajit for android


step 1

https://github.com/mkottman/AndroLua


git clone git://github.com/mkottman/AndroLua.git
cd AndroLua
$NDK/ndk-build
$SDK/tools/android update project -p .
ant debug
ant install

step 2
http://luajit.org/download.html

use one of these
# Android/ARM, armeabi (ARMv5TE soft-float), Android 2.2+ (Froyo)
NDK=/opt/android/ndk
NDKABI=8
NDKVER=$NDK/toolchains/arm-linux-androideabi-4.6
NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"

# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS)
NDK=/opt/android/ndk
NDKABI=14
NDKVER=$NDK/toolchains/arm-linux-androideabi-4.6
NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
NDKARCH="-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8"
make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF $NDKARCH"
copy result file src/libluajit.a to androlua/jni/luajava
 copy src/lua.h, src/luajit.h,src/luaconf.h, src/lualib.h, src/lauxlib.h to androlua/jni/luajava
remove androlua/jni/lua
step 3
modify androlua/jni/luajava/android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_LDLIBS := $(LOCAL_PATH)/libluajit.a
LOCAL_ARM_MODE := arm
TARGET_PLATFORM := armeabi
#TARGET_PLATFORM := armeabi-v7a
TARGET_ABI := android-8-armeabi
LOCAL_MODULE     := luajava
LOCAL_SRC_FILES  := luajava.c

include $(BUILD_SHARED_LIBRARY)
ndk-build clean
ndk-build
ant clean
ant debug

2014年10月7日 星期二

解決 virtualbox ubuntu guest 無法存取共用資料夾

在 virtual box 建立  ubuntu guest OS,  當設定主機共用資料夾, 會出現在 ubuntu 的 /media/sf_filename

但是這個目錄的屬性為 root vboxsf
我們無法直接存取, 是很麻煩的, 又不想改成 root login

google 一下, 只要將共用資料夾設定為自動掛載, 使用者加入 vboxsf 群組既可

sudo adduser <username>  vboxsf
sudo usermod -aG  vboxsf   <username>
然後 reboot, 重新進 ubuntu



2014年6月27日 星期五

ubuntu 12.04 用 nolapic 時, 只認到 CPU 0

灌完 ubuntu 12.04, 進OS 時會當機, 有時當在 gdm login, 有時是當在 input password 之後. 然後 keyboard 燈狂閃

加 kernel 參數 nolapic 可以進OS. 但是 /proc/cpuinfo 只見到一核. SMP 失效

google 有人這樣解

I finally get both core working. I added these options to the kernel line in /boot/grub/menu.lst 

noapic pci=assign-busses apicmaintimer idle=poll reboot=cold,hard 

And two cores were brought up. 

但我只用 pci=assign-busses apicmaintimer idle=poll,  對我的OS就夠好了

2014年5月29日 星期四

undefined reference to 'WebPDecodeRGBAInto' when build SDL_image for Android

使用 Android NDK 來build  SDL2_image 時, 出現如下錯誤訊息

 SDL2_image/IMG_webp.o: in function IMG_InitWEBP:jni/SDL_image/IMG_webp.c:123: error: undefined reference to 'WebPDecodeRGBAInto'

這時在 SDL_image 的 Android.mk 最後面加上這幾行

#
# 假設環境變數 NDK_ROOT 指到 NDK
#
#  設定 NDK_MODULE_PATH
#
$(call import-add-path,$(NDK_ROOT)/sources)
$(call import-add-path,./$(LOCAL_PATH))

#  叫 ndk-build 編譯 libwebp
$(call import-module,$(WEBP_LIBRARY_PATH))

追蹤者