2015年1月23日 星期五
gcc object file linking
gcc -c xxx.c --> automatically generate xxx.o
gcc yyy.c xxx.o --> automatically generate a.out
You can use functions defined in xxx.c without including any header files in yyy.c
2014年12月8日 星期一
cpu smbus access
B:X|D:15|F:0
config 0x188 and then 0x184
0x188 -> 31:28 1010 specifies EEPROM’s.
0x188 -> 27 1’ = Clock signal is released high, allowing normal operation of CMD.
0x184 -> 23:16 Offset.
0x184 -> 31 SMB_CMD_TRIGGERCMD trigger
0x184 -> 29 SMB_WORD_ACCESS (0:byte, 1:word)
0x184 -> 28:27 SMB_WRT_PNTR (00:read. 01:write)
0x184 -> 26:24 SMB_SA. slave address
struct mapping
__attribute__((packed)); need to be added otherwise it may cause memory alignment issue
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct test {
uint8_t sig[4];
uint8_t len;
uint8_t mic_sig[5];
uint32_t vid;
uint16_t did;
uint16_t idxx;
} __attribute__((packed));
int main(){
uint8_t test_string[]={'K','I','D','O',0x40,'M','i','T','A','C',0x86,0x80,0x02,0x3c,0x86,0x81,0x01,0x3c};
struct test *info=(struct test *)test_string;
printf("sig=%.4s len=0x%x mic_sig=%.5s vid=0x%04x did=0x%04x idxx=0x%04x\n" ,info->sig, info->len, info->mic_sig, info->vid, info->did, info->idxx);
return 0;
}
2014年12月7日 星期日
map pci configure space to memory
1: seek for RSDP (SIG: "RSD PTR ") -- main BIOS area below 1 MB
2: seek for RSDT (SIG: "RSDT")
3: determine table amount. -- (RSDT len -header)/ sizeof(table type: 32/64bits)
4: find MCFG table and check 0x24 - 0x28 <-- address="" configuration="" nbsp="" p="">
http://wiki.osdev.org/PCI_Express
http://wiki.osdev.org/RSDP
http://wiki.osdev.org/RSDT
After determining the MMIO base address and the total number of busses in the address space, you can read from the extended configuration address space. To access a specific register, you must use the following formula: Address = MMIO_BASE + { bus number[27:20], device number[19:15], function number[14:12], extended register number[11:8], register number[7:2], offset [1:0] }.-->
2: seek for RSDT (SIG: "RSDT")
3: determine table amount. -- (RSDT len -header)/ sizeof(table type: 32/64bits)
4: find MCFG table and check 0x24 - 0x28 <-- address="" configuration="" nbsp="" p="">
http://wiki.osdev.org/PCI_Express
http://wiki.osdev.org/RSDP
http://wiki.osdev.org/RSDT
After determining the MMIO base address and the total number of busses in the address space, you can read from the extended configuration address space. To access a specific register, you must use the following formula: Address = MMIO_BASE + { bus number[27:20], device number[19:15], function number[14:12], extended register number[11:8], register number[7:2], offset [1:0] }.-->
2014年8月5日 星期二
DD-WRT PPTP client redirect gateway
administration --> commands --> commands text area --> save startup
sleep 90
OLDGW=$(nvram get wan_gateway)
VPNSRV=$(nvram get pptpd_client_srvip)
VPNSRVSUB=$(nvram get pptpd_client_srvsub)
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
VPNGW=$(ifconfig $PPTPDEV | grep -Eo "P-t-P:([0-9.]+)" | cut -d: -f2)
route add -host $VPNSRV gw $OLDGW
route del default gw $OLDGW
route add default gw $VPNGW
routing table
root@DD-WRT:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.240.1 0.0.0.0 UG 0 0 0 ppp0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
169.254.0.0 * 255.255.0.0 U 0 0 0 br0
192.168.0.0 * 255.255.0.0 U 0 0 0 vlan1
192.168.1.0 * 255.255.255.0 U 0 0 0 br0
192.168.240.0 * 255.255.255.0 U 0 0 0 ppp0
192.168.240.1 * 255.255.255.255 UH 0 0 0 ppp0
220.135.10.98 192.168.179.1 255.255.255.255 UGH 0 0 0 vlan1
enhanced script
#!/bin/sh
OLDGW=$(nvram get wan_gateway)
VPNSRV=$(nvram get pptpd_client_srvip)
VPNSRVSUB=$(nvram get pptpd_client_srvsub)
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
while [ ${#PPTPDEV} -eq 0 ]; do
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
echo "Retry"
sleep 5
done
VPNGW=$(ifconfig $PPTPDEV | grep -Eo "P-t-P:([0-9.]+)" | cut -d: -f2)
route add -host $VPNSRV gw $OLDGW
route del default gw $OLDGW
route add default gw $VPNGW
ref: http://junan.name/1544.html
sleep 90
OLDGW=$(nvram get wan_gateway)
VPNSRV=$(nvram get pptpd_client_srvip)
VPNSRVSUB=$(nvram get pptpd_client_srvsub)
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
VPNGW=$(ifconfig $PPTPDEV | grep -Eo "P-t-P:([0-9.]+)" | cut -d: -f2)
route add -host $VPNSRV gw $OLDGW
route del default gw $OLDGW
route add default gw $VPNGW
routing table
root@DD-WRT:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.240.1 0.0.0.0 UG 0 0 0 ppp0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
169.254.0.0 * 255.255.0.0 U 0 0 0 br0
192.168.0.0 * 255.255.0.0 U 0 0 0 vlan1
192.168.1.0 * 255.255.255.0 U 0 0 0 br0
192.168.240.0 * 255.255.255.0 U 0 0 0 ppp0
192.168.240.1 * 255.255.255.255 UH 0 0 0 ppp0
220.135.10.98 192.168.179.1 255.255.255.255 UGH 0 0 0 vlan1
enhanced script
#!/bin/sh
OLDGW=$(nvram get wan_gateway)
VPNSRV=$(nvram get pptpd_client_srvip)
VPNSRVSUB=$(nvram get pptpd_client_srvsub)
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
while [ ${#PPTPDEV} -eq 0 ]; do
PPTPDEV=$(route -n | grep ^${VPNSRVSUB%.[0-9]*} | awk '{print $NF}' | head -n 1)
echo "Retry"
sleep 5
done
VPNGW=$(ifconfig $PPTPDEV | grep -Eo "P-t-P:([0-9.]+)" | cut -d: -f2)
route add -host $VPNSRV gw $OLDGW
route del default gw $OLDGW
route add default gw $VPNGW
ref: http://junan.name/1544.html
訂閱:
文章 (Atom)