ShadowSocks on DigitalOcean

Mainly recorded the steps for installation:

# apt-get install python-pip
# pip install shadowsocks
# vim /etc/shadowsocks.json
{
    "server":"1xx.xxx.xxx.xxx",
    "server_port":xxxx,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"Pass!Pass!Pass",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false,
    "workers": 1
}
# apt-get install supervisor
# vim /etc/supervisor/conf.d/shadowsocks.conf
[program:shadowsocks]
command=ssserver -c /etc/shadowsocks.json
autorestart=true
user=nobody
# vim /etc/default/supervisor
ulimit -n 51200
# service supervisor start

Then in client you could use a shadownsocks client for connecting to remote servers and enjoy the free internet.

System Trouble Shooting

SSHD Timeout

Trouble

When you login to some remote ssh machine, after 1 or 2 minutes, the server will hint you:
Connection closed by foreign host.

Solution

This trouble happens on Ubuntu14.04, because we don’t set the timeout intervals. So we could add following 2 lines into the /etc/ssh/sshd_config

ClientAliveInterval 60
ClientAliveCountMax 3

AliveInterval means we could keep the client alive for 60 minutes. AliveCountMax means when server send 3 times request to ssh client, if client didn’t send back reply message, then the ssh connection will be lost.
Restart the ssh via service ssh restart and now you won’t got this annoying trouble.

DNS

Since I use dnsencrypt at home, so once it enabled, all of the query goes to the 127.0.0.1, I have to turn it back at company.

[Trusty@~]$ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 10.0.0.1
search lan
alias disdns='sudo systemctl stop dnscrypt-proxy.service'
$ disdns

By doing this you could reach the internet.

Linux2.6.32 for Utu2440(5)

In this chapter we will continue to migrate driver on LCD, first we want to get the LCD information.

LCD Info

From the LCD we could see “LTV350QV-F0E”, Search it on google and we know it’s SAMSUNG TFT 3.5-inch 320*240 LTV350QV-F0E lcd panel.
Its datasheet could be downloaded from:
http://www.datasheet-pdf.com/datasheet-html/L/T/V/LTV350QV-F0E_Samsung.pdf.html

TFT means (Thin Film Transistor).
Beware, the kernel we should choose is uImage_T1_F0E_320x240_ts, because we bought the Package 1 of the development board, they shipped us with Samsung screen .

Code Modification

Kernel configuration modification:

Device Drivers --->
	Graphics support --->
		<*> Support for frame buffer devices
			Support for buffer devices --->
				<*> S3C2410 LCD framebuffer support
		Backlight & LCD device sipport --->
			<*>Lowlevel LCD controls
		Display device support --->
			<*> Display panel/monitor support
		Console display driver support --->
			<*> Framebuffer Console support
			[*] Framebuffer Console Rotation
			[*] Select compiled-in fonts
			[*] VGA 8x8 font
			[*] VGA 8x16 font
			[*] Mini 4x6 font
			[*] Sparc console 8x16 font
		[*] Bootup logo --->
			--- Bootup logo
			[*] Standard 224-color Linux logo

arch/arm/mach-s3c2440/mach-smdk2440.c:

static struct s3c2410fb_display smdk2440_lcd_cfg __initdata = {
 
        .lcdcon5        = S3C2410_LCDCON5_FRM565 |
                          S3C2410_LCDCON5_INVVCLK |
                          S3C2410_LCDCON5_INVVLINE |
                          S3C2410_LCDCON5_INVVFRAME |
                        // S3C2410_LCDCON5_PWREN |
                          S3C2410_LCDCON5_HWSWP,
 
        .type           = S3C2410_LCDCON1_TFT,
 
        .width          = 320,    // 240,
        .height         = 240,    //320,
 
        .pixclock       = 100000,   //HCLK/10   166667,
        .xres           = 320,    //240,
        .yres           = 240,    //320,
        .bpp            = 16,
        .left_margin    = 17,     //HFPD+1     20,
        .right_margin   = 17,     //HBPD+1     8,
        .hsync_len      = 13,     //HSPW+1     4,
        .upper_margin   = 5,      //VBPD+1     8,
        .lower_margin   = 5,      //VFPD+1     7,
        .vsync_len      = 9,      //VSPW+1     4,
};

static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {
        .displays       = &smdk2440_lcd_cfg,
        .num_displays   =  1, 
        .default_display = 0,
 //#if 0
       
        .gpccon         = 0xaaaa56a9,    //0xaa940659,
        .gpccon_mask    = 0xffffffff,
        .gpcup          = 0xffffffff,    //0x0000ffff,
        .gpcup_mask     = 0xffffffff,
        .gpdcon         = 0xaaaaaaaa,    //0xaa84aaa0,
        .gpdcon_mask    = 0xffffffff,
        .gpdup          = 0xffffffff,    //0x0000faff,
        .gpdup_mask     = 0xffffffff,
//#endif 
        .lpcsel         = 0,     //((0xCE6) & ~7) | 1<<4,
};

Enable the lcd:

static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd, 

arch/arm/mach-s3c2410/include/mach/regs-lcd.h:

#define S3C2410_LCDCON1_MMODE (0<<7)

drivers/video/s3c2410fb.c, after around line 52:

//LTV350QV_FOE_V0.0
 static void LTV350QV_Short_Delay(u_char time)
 {
  ndelay(150);
 }


#define LTV350QV_FOE 0x1d //device ID
typedef struct _LTV350qv_spi_data_{
unsigned char Device_ID; //ID of the device
unsigned int Index; //index of register
unsigned long Structure; //structure to be writed
}LTV350QV_SPI_Data;
//micro for LTV350QV_FOE
#define CS_H __raw_writel(__raw_readl(S3C2410_GPCDAT) |(1<< 8),S3C2410_GPCDAT)//MAKE_HIGH(LTV350QV_CS)
#define CS_L __raw_writel(__raw_readl(S3C2410_GPCDAT)&~(1<< 8),S3C2410_GPCDAT)//MAKE_LOW(LTV350QV_CS)
#define SCLK_H __raw_writel(__raw_readl(S3C2410_GPCDAT) |(1<< 9),S3C2410_GPCDAT)//MAKE_HIGH(LTV350QV_SCL)
#define SCLK_L __raw_writel(__raw_readl(S3C2410_GPCDAT)&~(1<< 9),S3C2410_GPCDAT)//MAKE_LOW(LTV350QV_SCL)
#define SDI_H __raw_writel(__raw_readl(S3C2410_GPCDAT) |(1<<10),S3C2410_GPCDAT)//MAKE_HIGH(LTV350QV_SDI)
#define SDI_L __raw_writel(__raw_readl(S3C2410_GPCDAT)&~(1<<10),S3C2410_GPCDAT)//MAKE_LOW(LTV350QV_SDI)
#define RST_H __raw_writel(__raw_readl(S3C2410_GPDDAT) |(1<< 0),S3C2410_GPDDAT)//MAKE_HIGH(LTV350QV_RST)
#define RST_L __raw_writel(__raw_readl(S3C2410_GPDDAT)&~(1<< 0),S3C2410_GPDDAT)//MAKE_LOW(LTV350QV_RST)
//
static void LTV350QV_Register_Write(LTV350QV_SPI_Data regdata)
{
u_char i,temp1;
u_int temp2;
u_long temp3;
unsigned long flags;
//write index
temp1=regdata.Device_ID<<2 | 0<<1 | 0<<0; //register index
temp2=regdata.Index;
temp3=(temp1<<24) | (temp2<<8);
local_irq_save(flags);
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<24;i++)
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1); //setup time
SCLK_H;
LTV350QV_Short_Delay(1); //hold time
}
CS_H;
LTV350QV_Short_Delay(5);
//write instruction
temp1=regdata.Device_ID<<2 | 1<<1 | 0<<0; //instruction
temp2=regdata.Structure;
temp3=(temp1<<24) | (temp2<<8);
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<24;i++)
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1);
SCLK_H;
LTV350QV_Short_Delay(1);
}
CS_H;
local_irq_restore(flags);
}
 
static void LTV350QV_Write(u_int index, u_int regdata)
{
LTV350QV_SPI_Data WriteData;
WriteData.Device_ID = LTV350QV_FOE;
WriteData.Index = index;
WriteData.Structure = regdata;
LTV350QV_Register_Write(WriteData);
}
 
static void LTV350QV_Power_ON(void)
{
LTV350QV_Write( 9, 0x0000);
mdelay(150);
LTV350QV_Write( 9, 0x4000);
LTV350QV_Write(10, 0x2000);
LTV350QV_Write( 9, 0x4055);
mdelay(550);
LTV350QV_Write( 1, 0x409d);
LTV350QV_Write( 2, 0x0204);
LTV350QV_Write( 3, 0x0100);
LTV350QV_Write( 4, 0x3000);
LTV350QV_Write( 5, 0x4003);
LTV350QV_Write( 6, 0x000a);
LTV350QV_Write( 7, 0x0021);
LTV350QV_Write( 8, 0x0c00);
LTV350QV_Write(10, 0x0103);
LTV350QV_Write(11, 0x0301);
LTV350QV_Write(12, 0x1f0f);
LTV350QV_Write(13, 0x1f0f);
LTV350QV_Write(14, 0x0707);
LTV350QV_Write(15, 0x0307);
LTV350QV_Write(16, 0x0707);
LTV350QV_Write(17, 0x0000);
LTV350QV_Write(18, 0x0004);
LTV350QV_Write(19, 0x0000);
mdelay(200);
LTV350QV_Write( 9, 0x4a55);
LTV350QV_Write( 5, 0x5003);
}
 
 
static void s3c2440fb_init_ltv350qv(void)
{
__raw_writel(0xaa9556a9, S3C2410_GPCCON); //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
//LCDVF[0],[1],[2]---output;VD[0],[1],[2]----output.
__raw_writel(0xffffffff, S3C2410_GPCUP); // Disable Pull-up register
LTV350QV_Power_ON() ; //init LCD model
__raw_writel(0xaaaaaaaa, S3C2410_GPDCON);
__raw_writel(0xffffffff, S3C2410_GPDUP);
// __raw_writel(3, S3C2410_LCDINTMSK); // MASK LCD Sub Interrupt
// __raw_writel(0, S3C2410_TPAL); // Disable Temp Palette
// __raw_writel(0, S3C2410_LPCSEL); // Disable LPC3600
}

Then add following sentense before the “return 0” of static int s3c2410fb_init_registers(struct fb_info *info):

s3c2440fb_init_ltv350qv();

Now recompile the kernel, you will see framebuffer OK.

Comment all of the function content of drivers/char/vt.c blank_screen_t(unsigned long dummy), this will disable the LCD’s display from closing.

Directly boot from tftp

Avoiding flash into the nand.


>tftp 30000000 uImage
dm9000 i/o: 0x18000300, id: 0x90000a46 
> bootm

Linux2.6.39 for Utu2440(2)

Serial Port Support

Enable the Device Driver—-> Character deivces —-> Serial drivers —-> Samsung related settings, My setting is listed as following:
/images/serialport.jpg
Then you will see serial output during kernel boot.

DM9000 Support

Add following code into the linux/arch/arm/mach-s3c2440/mach-smdk2440.c:

#include <linux/serial_core.h>
+ /* Added dm9000 support for utu2400 */
+ #include <linux/dm9000.h>
#include <linux/platform_device.h>

#include <plat/common-smdk.h>

+ /* DM9000 Base address for SMDK2440 */
+ #define MACH_SMDK2440_DM9K_BASE (S3C2410_CS3 + 0x300)

static struct map_desc smdk2440_iodesc[] __initdata = {

+ /* Added for dm9000 */
+ static struct resource smdk2440_dm9k_resource[] = 
+ {
+     [0] = 
+      {
+           .start = MACH_SMDK2440_DM9K_BASE,
+           .end   = MACH_SMDK2440_DM9K_BASE + 3,
+           .flags = IORESOURCE_MEM
+      },
+     [1] = 
+      {
+           .start = MACH_SMDK2440_DM9K_BASE + 4,
+           .end   = MACH_SMDK2440_DM9K_BASE + 7,
+           .flags = IORESOURCE_MEM
+      },
+     [2] = 
+     {
+         .start = IRQ_EINT9,
+         .end   = IRQ_EINT9,
+         .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
+     }
+ };
+ 
+ /*
+  * The DM9000 has no eeprom, and it's MAC address is set by
+  * the bootloader before starting the kernel.
+  */
+ static struct dm9000_plat_data smdk2440_dm9k_pdata = 
+ {
+ 	.flags        = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
+ };
+ 
+ static struct platform_device smdk2440_device_eth = 
+ {
+ 	.name        = "dm9000",
+ 	.id      = -1,
+ 	.num_resources = ARRAY_SIZE(smdk2440_dm9k_resource),
+ 	.resource  = smdk2440_dm9k_resource,
+ 	.dev       = {
+ 		.platform_data   = &smdk2440_dm9k_pdata,
+ 	},
+ };

static struct platform_device *smdk2440_devices[] __initdata = {
	&s3c_device_ohci,
	&s3c_device_lcd,
	&s3c_device_wdt,
	&s3c_device_i2c0,
	&s3c_device_iis,
+  	&smdk2440_device_eth,
};

Then select the dm9000 support from:
Device Driver—-> Network device support -> Ethernet(10 or 100Mbit) —-> DM9000 support
Now testing the kernel, you will see the kernel starts with dm9000 support, thus we could use NFS for booting the system.

Linux2.6.39 for Utu2440(3)

Building Filesystems

Use following script for building the basic filesystem:

$ cat mkrootfs 
#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs
echo "--------Create root,dev....----------"
mkdir bin boot dev etc home lib mnt proc root sbin sys tmp usr var  www
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
mknod -m 666 dev/console c 5 1
mknod -m 666 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 1777 tmp
chmod 1777 var/tmp
echo "-------make direction done---------"

Run it and you will get an folder which contains the newly created directory structure.

$ sudo ./mkrootfs 
------Create rootfs directons start...--------
--------Create root,dev....----------
make node in dev/console dev/null
-------make direction done---------
$ ls rootfs 
bin  boot  dev  etc  home  lib  mnt  proc  root  sbin  sys  tmp  usr  var  www

After making the filesystem, you should install all of the kernel modules into your fs:

$ make modules_install ARCH=arm INSTALL_MOD_PATH=The_PATH_TO_YOUR_ROOTFS

BusyBox

Busybox provides almost all of the tools used in system, first we should download and cross-compile it.

$ wget http://www.busybox.net/downloads/busybox-1.22.1.tar.bz2
$ tar xjvf busybox-1.22.1.tar.bz2
$ cd busybox-1.22.1
$ vim Makefile
+ CROSS_COMPILE ?= arm-linux-
# bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
$ make menuconfig

Parameters:

Build Options---> Build BusyBox as a static binary(no shared libs)
Installation Options--> Busybox installation prefix(See following pictures)
Linux Module Utilities-->  Default directory containing modules(/lib/modules)
Linux System Utilities --->
[*]Support /etc/mdev.conf
[*]Support command execution at device addition/removal
Init Utilities --->
"Support reading an inittab file"
"Support running commands with a controlling-tty"


/images/busyboxinstall.jpg
Then Make and make install:

$ make && make install

Now list the rootfs you have created you could see a new file named linuxrc is located under the / directory. Also you will see lots of executable files under the /bin which links to the /bin/busybox.

Startup Configuration

Create the /etc/group file:

$ cat etc/group
root:*:0:
daemon:*:1:
bin:*:2:
sys:*:3:
adm:*:4:
tty:*:5:
disk:*:6:
lp:*:7:lp
mail:*:8:
news:*:9:
u p:*:10:
proxy:*:13:
kmem:*:15:
dialout:*:20:
fax:*:21:
voice:*:22:
cdrom:*:24:
floppy:*:25:
tape:*:26:
s o:*:27:
a io:*:29:
sshd:*:74:
ppp:x:99:
500:x:500:plg
501:x:501:fa

Edit the /etc/passwd file:

$ cat etc/passwd
root::0:0:root:/:/bin/sh
ftp::14:50:FTP User:/var/ftp:
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
nobody:*:99:99:Nobody:/:
sky::502:502:Linux User,,,:/home/sky:/bin/sh

Add the hostname:

$ cat etc/sysconfig/HOSTNAME 
utu2440

Edit the inittab file:

$ cat etc/inittab
#etc/inittab
::sysinit:/etc/init.d/rcS

# Start an "askfirst" shell on /dev/tty2-4
console::askfirst:-/bin/sh
tty2::askfirst:-/bin/sh
tty3::askfirst:-/bin/sh
tty4::askfirst:-/bin/sh

# /sbin/getty invocations for selected ttys
tty4::respawn:/sbin/getty 38400 tty5
tty5::respawn:/sbin/getty 38400 tty6


::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
$ chmod 777 etc/init.d/rcS

Edit etc/init.d/rcS, this file will be executed everytime we bootup the linux system:

$ cat etc/init.d/rcS
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S 
prevlevel=N
umask 022 
export PATH runlevel prevlevel
echo "----------mount all----------------"
mount -a 
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
### Added from utu2440

trap ":" INT QUIT TSTP
##################################
#/bin/mount -t tmpfs tmpfs /dev
#/bin/mount -t sysfs sysfs /sys

################################## 
mkdir /dev/pts
/bin/mknod /dev/pts/0 c 136 0
/bin/mknod /dev/pts/1 c 136 1
/bin/mknod /dev/pts/2 c 136 2
/bin/mknod /dev/pts/3 c 136 3
/bin/mknod /dev/pts/4 c 136 4
/bin/mknod /dev/pts/5 c 136 5


/bin/mount -t devpts devpts /dev/pts
#/bin/mount -t proc none /proc
ln -s /dev/ts0 /dev/h3600_tsraw
/sbin/ifconfig eth0 10.0.0.15
/usr/sbin/telnetd -l /bin/login
echo "After telnetd"
/usr/bin/tty>/root/tty.txt

Create a new fstab file:

$ cat etc/fstab 
#device mount-point  type       option      dump  fsck  order
proc      /proc             proc      defaults        0      0
none     /tmp              ramfs     defaults       0       0
sysfs     /sys              sysfs      defaults        0      0
mdev    /dev              ramfs     defaults        0       0

Testing filesystem

Set the nfs boot options:

utu-bootloader=>>>setenv bootargs 'console=ttySAC0 init=/linuxrc root=/dev/nfs nfsroot=10.0.0.11:/media/nfs/rootfs,proto=tcp,nolock ip=10.0.0.15:10.0.0.1:10.0.0.1:255.255.255.0:www.yctek.com:eth0:off'
utu-bootloader=>>>setenv bootargs 'console=ttySAC0 init=/linuxrc root=/dev/nfs nfsroot=10.0.0.11:/media/nfs/rootfs,proto=tcp,nolock ip=10.0.0.15'

then we could boot into the nfs based filesystem.

Please press Enter to activate this console. NET: Registered protocol family 10

[root@www ~]# 
[root@www ~]# uname -a
Linux www 2.6.39 #6 Mon Oct 20 16:12:43 CST 2014 armv4tl GNU/Linux