Wednesday, October 15, 2014

error: C compiler cannot create executables in buildozer

Run this command:
cp -r ~/.buildozer/android/platform/android-ndk-r9d/platforms/android-19 ~/.buildozer/android/platform/android-ndk-r9d/platforms/android-20

From here: https://groups.google.com/forum/#!msg/kivy-dev/iyPOwoN9wHY/dajh0kfUClcJ

Error message: 


Run prebuild
Call prebuild_hostpython
Call prebuild_python
Call prebuild_sdl
Call prebuild_zope
Call prebuild_pygame
Call prebuild_pyjnius
Call prebuild_twisted
missing header for unified diff at line 3 of patch
patching file twisted/python/compat.py
Call prebuild_android
Call prebuild_kivy
Run build
Skipped build_hostpython
Call build_python
Entering in ARM environment
Compiler found at /Users/fengwei/.buildozer/android/platform/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin//arm-linux-androideabi-gcc
configure: WARNING: if you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... darwin
checking EXTRAPLATDIR... $(PLATMACDIRS)
checking machine type as reported by uname -m... x86_64
checking for --without-gcc... no
checking for arm-eabi-gcc... arm-linux-androideabi-gcc -DANDROID -mandroid  -fomit-frame-pointer --sysroot /Users/fengwei/.buildozer/android/platform/android-ndk-r9d/platforms/android-20/arch-arm
checking whether the C compiler works... no
configure: error: in `/Users/fengwei/Documents/paper/icas/trunk/code/ICAS-AndroidNetclientTester/src/.buildozer/android/platform/python-for-android/build/python/Python-2.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details

# Command failed: ./distribute.sh -m "kivy twisted" -d "chordclient"

Tuesday, October 14, 2014

Makefile: how it woks

http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html


Thursday, October 9, 2014

Access the redirection table entry in IO APIC

http://wiki.osdev.org/IOAPIC
http://wiki.osdev.org/APIC

These two URLs provides detailed the explanation about IOAPIC, but the read/write code do not work on my CentOS machine. The IO APIC base is 0xfec00000 on my machine (index 0xfec00000; port 0xfec00010). It is a memory maped IO memory.

I use the code in both user-level program and a kernel module. The code raises an segmentation fault. After looking at the dmesg, I notice that it is because page table does not know how to translate the virtual address (i.e., 0xfec00000).

Then I use the ioremap() in the kernel module, it works.

#include <linux/module.h>
#include <linux/init.h>

#include <asm/io.h>


MODULE_LICENSE("Dual BSD/GPL");



static int hello_init(void)
{
    // IO APIC base is 0xfec00000
    // IO APIC index: 0xfec00000
    // IO APIC data: 0xfec00010
    // The redicection table of the keyboard is at index 0x12
    // please see southbridge manual for redirection table
    // the original value of the redirection table entry is 0x939
    // We change it to 0xa39, which enables SMI triggering
    //
    // if you want to compile this kernel moudule,
    // please also change the Makefile to hello6.o
    //
    // just run the script enable_kb_SMI.sh to enable the SMI
    // triggering
    //
    unsigned int IRQ1_entry;
    void * IOAPIC_BASE = ioremap(0xfec00000, 32);
    iowrite8(0x12, IOAPIC_BASE);
    IRQ1_entry = ioread32((unsigned char*)IOAPIC_BASE + 0x10);
    printk("IRQ1 Entry Value is: %x\n", IRQ1_entry);
     
    iowrite8(0x12, IOAPIC_BASE);
    iowrite32(0xA39, (unsigned char*)IOAPIC_BASE + 0x10);
  
    printk("Successfully enable keyboard SMI triggering\n");
    return 0;
}

static void hello_exit(void)
{
    printk("Goodbye, crule world\n");
}

module_init(hello_init);
module_exit(hello_exit);

Monday, October 6, 2014

Create OpenVZ Cotainers

1. Download the template

echo 'Now downloading CentOS6 x86_64 template....'
cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz


2. $vzctl create 101 centos-6-x86_64

It uses the default conf from /etc/vz/conf

Templates:
http://wiki.openvz.org/Download/template/precreated


Install OpenVZ on Amazon EC2 Instance

1. Create an CentOS 6 Amazon Instance from the MarketPlace. 

Click on launch instance, then click on AWS marketpalce
I choose:
Rating
Sold by CentOS.org
$0.00/hr for software


2. Download this script into instance and run it. 

https://raw.githubusercontent.com/H2so4/CentOS-6-Quick-Install-Scripts/master/installOpenVZ-with-WebPanel.sh

#!/bin/bash
# run: source <(curl -s https://raw.github.com/qrpike/CentOS6---OpenVZ-Installer/master/installOpenVZ.sh)


clear
echo 'Going to install OpenVZ for you..'

echo 'installing wget..'
yum install -y wget

echo 'now adding openvz Repo'
cd /etc/yum.repos.d
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ

echo 'Installing OpenVZ Kernel'
yum install -y vzkernel.x86_64

echo 'Installing additional tools'
yum install -y vzctl vzquota

echo 'Changing around some config files..'
sed -i 's/kernel.sysrq = 0/kernel.sysrq = 1/g' /etc/sysctl.conf
sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

echo 'net.ipv4.conf.default.proxy_arp = 0' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.rp_filter = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.send_redirects = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.send_redirects = 0' >> /etc/sysctl.conf
echo 'net.ipv4.icmp_echo_ignore_broadcasts=1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.forwarding=1' >> /etc/sysctl.conf

echo 'Done with that, purging your sys configs'
sysctl -p

sed -i 's/NEIGHBOUR_DEVS=detect/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf
sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/sysconfig/selinux

echo 'Now downloading CentOS6 x86_64 template....'
cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz

/bin/cp /etc/rc.local /tmp/rc.local
cat > /etc/rc.local << EOF
#!/bin/bash
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh 
modprobe vzcpt
modprobe nf_conntrack_ftp
modprobe ip_nat_ftp
/bin/cp -f /tmp/rc.local /etc/rc.local
EOF

# BARE MINIMUM OpenVZ iptables config - CENTOS 6.4
cat > /etc/sysconfig/iptables << EOF
*nat
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth+ -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -m icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -o eth+ -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
reboot


echo ' - - - - - - - - - - - - - - - - - - - - - - '
echo ' The server will reboot now and install OpenVZ Web panel'
echo ' '
echo 'When the server boots, it will run the OpenVZ Web panel installation which can take up to 10 minutes'
echo 'This script is executed by backing up/replacing /etc/rc.local with a new file containing the installation script.'
echo 'Once complete, the original /etc/rc.local file is replaced'
echo ' - - - - - - - - - - - - - - - - - - - - - - '

echo '..... well.... that should do it.'
echo 'oh, and ur welcome...'

More info
http://scaleup.us/2014/01/01/centos-one-liner-installation-openvz-and-openvz-web-panel/




Wednesday, October 1, 2014

BASH related

Because of the serious bug, BashShock, released recently, I played with bash a little bit. Here are some notes:

/bin/sh
/bin/bash
/usr/local/bin/bash

/bin/sh is the shell, and you can the shell scirpts are starting with #!/bin/sh.
Most of the default shell is bash. You can change the default shell using $chsh command

If you install the bash from source code, the bash maybe installed under /usr/local/bin directory.
After you installation, if you type $which bash, it should show /usr/local/bin/bash.

What if you want to change the bash back to /bin/bash:
You can do $ export PATH=/bin/:$PATH. This command will put the /bin/ in the beginning of the PAHT. If you type $which bash, it should show /bin/bash. This is because the searching is from the beginning of the $PATH.