Check out the new blog at http://linuxehacking.ovh , this one will no longer be updated

mercoledì 22 luglio 2015

How to easily test an N-CHANNEL or P-CHANNEL MOSFET using just a multimeter

You should have noticed that most multimeters come with a function to test BJT transistors, but none has a function to test the today's more common MOSFETs

Here are the steps to test an N-CHANNEL mosfet with just a multimeter ( applies to P-CHANNEL too, just swap + and - ), of course the MOSFET has to be disconnected completely.


  1. Make sure you are not wearing shoes and so that you don't have any electrostatic charge, FETs are very delicate to ESD.
  2. Now touch with your finger both Gate and Source terminals, this will make sure that the gate is uncharged
  3. Put your multimeter in diode/continuity test mode ( beep mode )
  4. Touch with the negative lead the source pin, and with positive lead the drain, it should not beep and show > 999 ohm, if there's current flowing, after making sure again that gate is discharged, the MOSFET is damaged.
  5. Touch with the negative lead the source pin and with positive lead the gate pin, no current should flow, if current flows it means that the oxide layer between gate and substrate or N junctions has been broken by a gate-source overvoltage or ESD, trash the mosfet if that is the case.
  6. Now WITHOUT touching the gate terminal at all, touch the drain pin with positive lead and source pin with negative lead, you should get the multimeter to beep and a very low resistance reading
Finally, before trashing any mosfets, make sure that the method works with most of them using your multimeter ( there may be some multimeters that use too low voltage in continuity test mode and thus not reaching Vt threshold of the mosfet ).
To avoid ESD damage always store your MOSFETS with all pins joined together using aluminum foil or copper strands.

mercoledì 15 luglio 2015

Installing OpenWRT on SITECOM WL-326

The SITECOM WL-326 is an ethernet+3g router featuring 300 Mbps wireless and an usb port to connect a 3G modem.

This device is not officially supported by OpenWRT and not very common, so there's basically zero info on it at the moment.



First thing is to find out which SoC it uses, since it is covered by an heat spreader, best idea that does not involve the risk of destroying the board is connecting an USB-TTL adapter to the serial port which is visible on the photos.



Luckly contrary to most cases, the PCB has already written on it which pins are RX,TX,GND, so it's just matter of soldering a female o male strip header, and connect it to the adapter.

Serial port settings are 57600 8N1, and when connecting the power to the device, it's immediately visible that it is a rebrand of another device, the ESR-6670 http://wiki.openwrt.org/toh/engenius/esr6670.
Still no luck, it's not supported either, but at least now we know what SoC it uses, which is Ralink 3052.



Now the tricky part, bootloader only shows one option, contrary to most supported routers

Board: Ralink APSoC DRAM:  32 MB  1*32 MB
============================================ 
ASIC 3052_MP2 (Port5<->None)
Product Name: ESR-6670
SDRAM CAS = 3(d1835272) 
============================================ 

Please choose the operation: 
   1: Load system code to SDRAM via TFTP. 

So the only option is just to try it, worst case scenario if it goes wrong we'll have to reverse engineer the (likely) jtag connector visible on the photo.

This command will ask you some parameters, first one is the router IP, just hit enter ( leaving it as it is )
second one is the TFTP server IP, a default one will be shown.

Board: Ralink APSoC DRAM:  32 MB  1*32 MB
============================================
ASIC 3052_MP2 (Port5<->None)
Product Name: ESR-6670
SDRAM CAS = 3(d1835272)
============================================

Please choose the operation:
   1: Load system code to SDRAM via TFTP.

1: System Load Linux to SDRAM via TFTP.
 Please Input new ones /or Ctrl-C to discard
        Input device IP (192.168.99.9) ==:

        Input server IP (192.168.99.8) ==:

        Input Linux Kernel filename (40.7z) ==:rd.bin
Using Eth0  device
TFTP from server 192.168.99.8; our IP address is 192.168.99.9
Filename 'a.dlf'.
Loading: *
ArpTimeoutCheck
Got ARP REPLY, set server/gtwy eth addr (54:42:49:5f:d3:1b)
Got it
T #
 first block received

Now connect an ethernet cable between a LAN port and your machine and ifconfig it to the router ip address

ifconfig eth0 up 192.168.99.8

or something like that.

Now you can hit enter, and then it will ask the linux kernel filename, which is WRONG, that's not the linux kernel filename but the uImage filename.

Now the hard choice, finding a similiar enough device to flash this one with, and cross finger that it does not blow up, i've choosen the wr512 because it has too an usb port and an ethernet so, it's worth trying.

So download http://downloads.openwrt.org/chaos_calmer/15.05-rc2/ramips/rt305x/openwrt-15.05-rc2-ramips-rt305x-wr512-3ng-4M-initramfs-uImage.bin and rename it to something sane, like /home/dev/rd.bin

Now, start a tftp server, quickiest way without spending 15 mins configuring with xinetd or crap like that is


dnsmasq --enable-tftp --tftp-root=/home/dev -d

If it fails because of port already in use, append -p 3244

If it started succesfully, enter the choosen filename ( rd.bin or whatever it is ) on the serial console and hit enter, now it should flash it and reboot, but you are not done yet, because this is an image designed to work only on RAM , so any config change will NOT be saved.

But since you should have an openwrt console now and the LAN ports configured to 192.168.1.1, ifconfig your machine's interface to 192.168.1.2.

Download http://downloads.openwrt.org/chaos_calmer/15.05-rc2/ramips/rt305x/openwrt-15.05-rc2-ramips-rt305x-wr512-3ng-4M-squashfs-sysupgrade.bin


Notice that now the downloaded file has "sysupgrade" in it and not initramfs-uImage.

Now from the serial console do

scp yourmachineuser@192.168.1.2:/home/youruser/openwrt-15.05-rc2-ramips-rt305x-wr512-3ng-4M-squashfs-sysupgrade.bin /tmp/

Once done ( and completed succesfully of course ), do

sysupgrade -v /tmp/openwrt-15.05-rc2-ramips-rt305x-wr512-3ng-4M-squashfs-sysupgrade.bin

It will take like a min or two and then reboot automatically, after the reboot you will have the router at 192.168.1.1 again.

Now login to LuCI interface, go to Network->Switch and you should see two vlans configured , vlan1 which is lan configured with the first port untagged and vlan2 which is wan configured to some other port untagged.

Now change on vlan1 the first port ( left to right ) , to off , and on vlan2 the first port ( same as vlan1 ) to untagged, and click save & apply.
That's because the router of which we flashed the firmware has the switch connected differently.



That's it now you are done , you can configure wireless and other stuff, just forget about 3G unless you replace flash memory, because it is likely that there's not enough space on flash ( unless you build a version without LuCI and with 3g and then configure with CLI ).

Update: It's possible to install 3g packages and still have 52 kbytes free, not tested because i don't have an USB 3g modem handy