Kategoria: internet

Internet, webmajsterka i inne pierdoły

trim fucked up my data on Crucial SSD

As always after upgrade Windows 10 it won’t boot. So as always I recreate the boot partitions by deleting them and create new one.

This time I have deleted by mistake my system partition, don’t worry just repair partition table. Then I have restored it. All files was OK.

First boot take a lot of time but finally I saw my desktop. After minute icons on my dekstop started disappearing. I shut down my system because i thought it is ransomware or something.

Recovery software shows all files is OK. MFT looks fine so i have restored them all.

Every restored file is full of null! That has to be trim fault.

SSD did not notice that I restored my partition and trim rewrite it with zero.

There is Crucial BX300 240GB SSD stats:

Cannot install MTP Device and cannot find wpdmtp.inf

On Windows versions N and KN there is no Media Feature Pack. MTP and PTP dirvers (wpdmtp.inf) is included in this pack.

Without it you cant send files to and from the Android phone.

Media Feature Pack for N and KN versions of Windows 10 (choose your language)

Unrecognized device in PTP mode:

Unrecognized device in MTP mode:

Arduino Nano with ATmega 328PB and Arduino IDE support

I did not notice that i bought Arduino clone with ATmega328PB not with the ATmega328P, there is CH340C USB-UART chip. 328PB version is newer chip, some kind better than old.

Main disadvantage that chip is not supported by Arduino IDE and it came with unsupported bootloader to load sketches via Arduino IDE (even with added support to 328PB).

I tried to flash new bootloader via USBasp but i can’t change fuse bits. Fuses stays as it was!
avrdude: verification error, first mismatch at byte 0x0000
0x00 != 0xff
avrdude: verification error; content mismatch

Somehow i have disabled SPIEN (it enable serial programming and data downloading) and i could not program it via ICSP anymore. I got error but 328pb will be alive:
avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.

Recover atmega 328 fuse bits

I have MiniPro Tl866 programmer that support atmega 328p programming. It not support 328PB, it has difference timings for programing but it works if you choose 328P.

But i could set fuse bits! You have to connect all pins like on scheme down below.

Then before you click program you have to connect XTAL1(PIN9) to pin 7 and XTAL2(PIN10) to pin 8 of 328PB (you have to touch it with small wires for 100ms of programming, do not need to solder).

Uncheck check ID. Set Config an click Programm with checked Config fuse bits and Lock bits:

Now we have to flash bootloader.

328pb Arduino IDE support and bootloader

We will use MiniCore that supports 328PB chip. On Arduino IDE 1.8.7 we can add support for this board in easy way. Open File > Preferences and add extra url for Board Manager:
Then go to Tools > Board > Board Manager and install MiniCore by MCUdude.

Now we can choose our board in tools:
Board: Atmega328
Bootloader: Yes
Clock: 16MHz external
BOD: 2.7v
Compiler LTO: Disabled (you can enable it if you need)
Variant: 328PB

Connect your programmer (i’m using usbasp) and choose Burn Bootloader.

Done, now you can write sketches via usb!

If something is still wrong you should set fuse by tl866 again or try this: For example open boards.txt from “C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1”
Save & close the file.

You can use minicore for all 328p boards as well!

Done. Now we have fully functional 328PB with Arduino IDE.

Entware and pyLoad on Android 7.1 TV Box

Entware is repository full of apps for embeded linux like android on tv box. I have prepared installation script to install it from scratch because android is different. You have to rebuild folders in root on every reboot. Root partition is rebuilt on every boot from the image. I will use /data partition to store files (path /data/opt) and mount –bind on /opt.

Continue reading

Simultaneous dual wan access and bind app (pyload, transmission) on interface to ip on Asus Router

Asus routers has builtin DualWan in two modes. First one, Failover disables second WAN until first one stop works so you cannot use it. Loadbalancing – no one know what it is doing, it has closed sources and you do not know when do you connect which interface. First disable builtin DualWAN and leave as main WAN.

I will describe dual wan with dual default gateways: First cable WAN and second USB hilink modem. We want use main WAN but some apps just bind to second WAN. It is called Source Based Routing. We will use iproute2 and routing tables. Basically we will set rule: if source address is from app using second wan interface use other table rule with other default gateway/router. You can create much more than two.

Check that you have routing tables, if not create one:

cat /etc/iproute2/rt_tables

100 wan0
111 ovpnc1
112 ovpnc2
113 ovpnc3
114 ovpnc4
115 ovpnc5
200 wan1

We will use wan1, if it is empty:

ip route list table wan1

My second WAN is USB Modem HiLink so I have to manually turn on the modem on Asus Router via command line. Router has preinstalled drivers. So just look in dmesg which interface it brings:

dmesg | grep usb
dmesg | grep USB

cdc_ether 2-2:1.0: eth3: register 'cdc_ether' at usb-0000:00:0a.1-2, CDC Ethernet Device
My interface for 3G usb modem is eth3. Bring it up:

ifconfig eth3 up

We have to assign ip address, mask and subnet to this interface. Asus has dhcp client called: udhcpc. It works but you have to create script:

touch /jffs/scripts/udh.sh
chmod +x /jffs/scripts/udh.sh
nano /jffs/scripts/udh.sh

Content of udh.sh

#set route table for second wan
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
IFS=. read -r i1 i2 i3 i4 <<EOF
IFS=. read -r m1 m2 m3 m4 <<EOF
SUBIP=$(printf "%d.%d.%d.%d" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
lip=`ip addr show br0 | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"`
lsubnet=`ifconfig br0 | grep Mask | cut -d":" -f4`
IFS=. read -r i1 i2 i3 i4 <<EOF
IFS=. read -r m1 m2 m3 m4 <<EOF
LOCSUBIP=$(printf "%d.%d.%d.%d" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
mask2cidr() {
    for dec in $1 ; do
case $dec in
    255) let nbits+=8;;
    254) let nbits+=7;;
    252) let nbits+=6;;
    248) let nbits+=5;;
    240) let nbits+=4;;
    224) let nbits+=3;;
    192) let nbits+=2;;
    128) let nbits+=1;;
    *) echo "Error: $dec is not recognised"; exit 1
    printf "$nbits"
CIDR=$(mask2cidr $subnet)
case "$1" in
        echo "Clear existing config"
        ifconfig $interface
        ip addr flush dev $interface
        echo "Setting interface IP $interface $ip $BROADCAST $NETMASK"
        #ip addr add $ip/$CIDR broadcast $BROADCAST dev $interface
        ifconfig $interface $ip $BROADCAST $NETMASK
        echo "Route adding for $SUBIP/$CIDR"
		#route in table
		ip route add $SUBIP/$CIDR dev $interface table $TABLE
		#LAN br0
		ip route add $LOCSUBIP/$CIDR dev br0 table $TABLE
		#route in default
		ip route add $SUBIP/$CIDR dev $interface
		#route localhost
		ip route add dev lo table $TABLE
        echo "Setting default gateway"
        if [ -n "$router" ] ; then
            echo "Deleting routers"
            while ip route del default dev $interface table $TABLE  ; do
            while ip route del default dev $interface ; do
            for i in $router ; do
                echo "Adding gateway $i"
				ip route add $i dev $interface metric $metric table $TABLE
				ip route add default via $i dev $interface metric $metric table $TABLE
				ip route add $i dev $interface metric $metric
                : $(( metric += 1 ))
        #from and to
        echo "IP Rule"
		ip rule add from $SUBIP/$CIDR lookup $TABLE
		ip rule add from all to $SUBIP/$CIDR lookup $TABLE
        #set firewall
        echo "Firewall set"
		iptables -t nat -A POSTROUTING ! -s $SUBIP/$CIDR -o $interface -j MASQUERADE
exit 0

Now run test of udhcpc:

udhcpc -i eth3 -s /jffs/scripts/udh.sh

If everything works and interface has IP address you can add it to autostart. But do not forget add -b switch for udhcpc to work in background for renew the dhcp leases. I will add autostart to post-mount because i has USB modem so i have to wait until it is initialized. Edit post-mount

nano /jffs/scripts/post-mount

add :
ifconfig eth3 up
udhcpc -i eth3 -b -s /jffs/scripts/udh.sh

Now you can bind pyload to second wan interface. Open Config > Menu > General > Download > Download interface to bind (ip or Name)
Enter your interface name for example eth3:

Now check it is works. Add download job with URL to html web page which shows your ip (it cannot be js/html5) for example http://www.whatismyip.net. Open downloaded html file and check it is second wan ip adress.

List of commands without script:
MASK: or /24
SUBNET: 192.168.0

ifconfig eth3 up
ifconfig eth3
ifconfig eth3
ip route add 192.168.0/24 dev eth3 src table wan1
ip route add 192.168.0/24 dev eth3
ip route del default dev eth3 table wan1
ip route del default dev eth3
ip route add default via dev eth3 metric 0 table wan1
ip rule add from table wan1
ip rule add to table wan1
iptables -t nat -A POSTROUTING -o eth3 -j MASQUERADE

There is much more routes because i want to access second gateway config page on 192.168.1 from local subnet.
Use MASQUERADE on last step only if you enabled firewall in router settings. If you disabled you have to create forward rule. You can check iptables for correct one:

iptables -t nat -vL
iptables -vL

You can change DNS servers by adding in script:

echo "Recreating $RESOLV_CONF"
# If the file is a symlink somewhere (like /etc/resolv.conf
# pointing to /run/resolv.conf), make sure things work.
realconf=$(readlink -f "$RESOLV_CONF" 2&gt;/dev/null || echo "$RESOLV_CONF")
&gt; "$tmpfile"
[ -n "$domain" ] &amp;&amp; echo "search $domain" &gt;&gt; "$tmpfile"
for i in $dns ; do
	echo " Adding DNS server $i"
	echo "nameserver $i" &gt;&gt; "$tmpfile"
mv "$tmpfile" "$realconf"

Of course you can built your own dual wan script and switch to second wan in failover:

ip route change default via dev eth3 metric 0

LoadBalancing is much more complicated.

mask2cidr – https://www.linuxquestions.org/questions/programming-9/bash-cidr-calculator-646701/#post3173472
subnet ip from ip and mask: https://stackoverflow.com/questions/15429420/given-the-ip-and-netmask-how-can-i-calculate-the-network-address-using-bash
script for udhcpc simple.script – https://github.com/brgl/busybox/tree/master/examples/udhcp