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] }.

display scsi device type


sg_map -x

 -x     after  each  active  sg  device  name  is  displayed  there  are  five digits:
http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type

cat /proc/scsi/scsi

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

2014年5月16日 星期五

acpid study

all configuration files will be placed underneath /etc/acpi/
all events will be placed underneath /etc/acpi/events
all actions will be placed underneath /etc/acpi/actions
run acpi_listen command to monitor ACPI events
specify log file for all acpi events --> acpid -l /var/log/acpid
when an acpi event occurred, acpid will check configuration files underneath /etc/acpi/events and go into any events that match the event definition.

sample
# anything.conf
# Pass all events to our one handler script
event=.*
action=/etc/acpi/handler.sh %e

# handler.sh
logger "acpi event: $1 / $2 / $3 /$4"
exit 0

2014年5月5日 星期一

wsf tag

package
job id
script language="VBScript" src="1.vbs"
example
named--> name|helpstring|type|required
WScript.Arguments.Named.Exists("name")
WScript.Arguments.ShowUsage

1 package can contain multiple job id.

CScript //job:"donein vbs" 4.wsf

include in vbscript

1: use filesystemobject to read all contents of external script
2: ExecuteGlobal objfso.ReadAll

2014年4月19日 星期六

Linux System fast clone

RHEL 6.5 EFI fs structure
/dev/sdx1 vfat --> t(6)   /boot/efi (10MB should be okay)
/dev/sdx2 ext4 --> t(83)  /boot (50MB should be okay)
/dev/sdx3 ext4 --> t(83)  /

boot menu for EFI boot option
efibootmgr -c -d /dev/sda -p 1 -w -L "Redhat Enterprise Linux 6.5" -l '\EFI\redhat\grub.efi'


RHEL 6.5 legacy fs structure
/dev/sdx1 ext4 --> t(83)  /boot
/dev/sdx2 ext4 --> t(83)  /
grub need to be installed

fstab/grub.conf need to be updated according to the UUID of target disk

kernel option of current boot can be found at /proc/cmdline

2014年4月10日 星期四

option rom dump from Linux

http://www.coreboot.org/VGA_support

cat /proc/iomem |head -n 3|tail -n 1|(read m; m=${m/ :*}; s=${m/-*}; e=${m/*-}; dd if=/dev/mem of=vgabios.bin bs=1c skip=$[0x$s] count=$[$[0x$e]-$[0x$s]+1])

will dump the 3rd option rom.