diff --git a/README.md b/README.md index 2313e55..ae55282 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,8 @@ GlobalLogic Kharkiv, 2020 This repository is aimed for sharing our exercises and your solutions in scope of the course. +Homeworks: +- hwdetect - detect attached hardware using user level script file + + Please refer to wiki for details. diff --git a/device_tree/i2c0.dts b/device_tree/i2c0.dts new file mode 100644 index 0000000..6173423 --- /dev/null +++ b/device_tree/i2c0.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c0 = "/soc/i2c@01c2ac00"; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + status = "okay"; + }; + }; +}; \ No newline at end of file diff --git a/hwdetect/README.md b/hwdetect/README.md new file mode 100644 index 0000000..7f93fd6 --- /dev/null +++ b/hwdetect/README.md @@ -0,0 +1,10 @@ +# Home work hot plugged hardware detector + +Create the script 'hwdetect.sh' which detects connected hardware. +For monitor hardware from user level please use /dev folder, +output from lsusb and i2detect (optional). +Most interesting devices are: + - USB to TTL convertors, + - flash drives, + - SD cards, + - i2c devices. diff --git a/hwdetect/example.md b/hwdetect/example.md new file mode 100644 index 0000000..c2e77bc --- /dev/null +++ b/hwdetect/example.md @@ -0,0 +1,37 @@ +Hardware that is detected from start + +USB to ttl: +ttyUSB0 + +USB flash drives: +/dev/sda + +I2C devices: +i2c-3 unknown i915 gmbus dpd N/A +i2c-1 unknown i915 gmbus dpc N/A +i2c-4 unknown DPDDC-A N/A +i2c-2 unknown i915 gmbus dpb N/A +i2c-0 unknown SMBus I801 adapter at f040 N/A +i2c-5 unknown DPDDC-C N/A + +SD cards: +mmcblk0 + +Active detector +connected> +ttyUSB0 + +connected> +mmcblk0 + +>connected> +/dev/sdb + + $usb0 +if [[ -n $(cat $usb0) ]]; then + cat $usb0 +else + echo "none" +fi +echo + +echo "USB flash drives:" +ls /dev/sd[a-z] > $flash0 +if [[ -n $(cat $flash0) ]]; then + cat $flash0 +else + echo "none" +fi +echo + +echo "I2C devices: " +i2cdetect -l > $i2c0 +if [[ -n $(cat $i2c0) ]]; then + cat $i2c0 +else + echo "none" +fi +echo + +echo "SD cards: " +ls /dev | grep -E "mmcblk[0-9]+$" > $sd0 +if [[ -n $(cat $sd0) ]]; then + cat $sd0 +else + echo "none" +fi +echo + +trap 'rm -f $ALL_TMP_FILES && echo -e "\n$END_MSG" && exit' 2 3 15 + +echo "Active detector" +while true; do + ls /dev | grep ttyUSB* > $usb1 + usb_to_ttl=$(diff --new-line-format=$"$CON_MSG" --old-line-format=$"$DISCON_MSG" --unchanged-group-format='' $usb0 $usb1 ) + + ls /dev/sd[a-z] > $flash1 + flash_drives=$(diff --new-line-format=$"$CON_MSG" --old-line-format=$"$DISCON_MSG" --unchanged-group-format='' $flash0 $flash1) + + i2cdetect -l > $i2c1 + i2c_devices=$(diff --new-line-format=$"$CON_MSG" --old-line-format=$"$DISCON_MSG" --unchanged-group-format='' $i2c0 $i2c1) + + ls /dev | grep -E "mmcblk[0-9]+$" > $sd1 + sd_cards=$(diff --new-line-format=$"$CON_MSG" --old-line-format=$"$DISCON_MSG" --unchanged-group-format='' $sd0 $sd1) + + if [[ -n "$usb_to_ttl" ]]; then + for i in $(echo "$usb_to_ttl"); do + echo "$i" + done + echo + cat $usb1 > $usb0 + fi + + if [[ -n "$flash_drives" ]]; then + for j in $(echo "$flash_drives"); do + echo "$j" + done + echo + cat $flash1 > $flash0 | 2>/dev/null + fi + + if [[ -n "$i2c_devices" ]]; then + for k in $(echo "$i2c_devices"); do + echo "$k" + done + echo + cat $i2c1 > $i2c0 + fi + + if [[ -n "$sd_cards" ]]; then + for l in $(echo "$sd_cards"); do + echo "$l" + done + echo + cat $sd1 > $sd0 + fi + + sleep 1 +done \ No newline at end of file