{"id":28721,"date":"2021-07-12T18:41:01","date_gmt":"2021-07-12T16:41:01","guid":{"rendered":"https:\/\/pi3g.com\/?p=28721"},"modified":"2021-07-12T18:41:01","modified_gmt":"2021-07-12T16:41:01","slug":"raspi-config-nonint-do_i2c-1-hangs-forever","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/raspi-config-nonint-do_i2c-1-hangs-forever\/","title":{"rendered":"raspi-config nonint do_i2c 1 h\u00e4ngt \"f\u00fcr immer\""},"content":{"rendered":"<p>While developing <a href=\"https:\/\/picockpit.com\/\">PiCockpit<\/a>, and trying to allow the user to turn I2C off from the webinterface, I have run into crashes and problems.<\/p>\n<p>I am using raspi-config <a href=\"https:\/\/pi3g.com\/2021\/05\/20\/enabling-and-checking-i2c-on-the-raspberry-pi-using-the-command-line-for-your-own-scripts\/\">in non-interactive mode (I\u2019ve written about this before)<\/a> to control I2C from the PiCockpit client. <\/p>\n<p>While debugging the issue, I noted that \u2013 if something was busy accessing the I2C bus, the command (raspi-config) would freeze.<\/p>\n<p>Investigating with ps aux, I noticed that another command had been started but did not finish to execute:<\/p>\n<blockquote>\n<p>dtparam i2c_arm=off<\/p>\n<\/blockquote>\n<p>This is a compiled binary, no script. But it has a verbose mode.<\/p>\n<p>running this manually, in verbose mode, while something else would be accessing the I2C bus:<\/p>\n<blockquote>\n<p><strong>17:32:55 root@Avalon:\/home\/pi # dtparam -v i2c_arm=off<\/strong><\/p>\n<p><em>DTOVERLAY[debug]: using platform &#8216;bcm2711&#8217;<\/em><\/p>\n<p><em>DTOVERLAY[debug]: overlay map loaded<\/em><\/p>\n<p><em>run_cmd: which dtoverlay-pre &gt;\/dev\/null 2&gt;&amp;1 &amp;&amp; dtoverlay-pre<\/em><\/p>\n<p><em>run_cmd: dtc -I fs -O dtb -o &#8216;\/tmp\/.dtoverlays\/base.dtb&#8217; \/proc\/device-tree 1&gt;\/dev\/null 2&gt;&amp;1<\/em><\/p>\n<p><em>DTOVERLAY[debug]: loading file &#8216;\/tmp\/.dtoverlays\/base.dtb&#8217;<\/em><\/p>\n<p><em>DTOVERLAY[debug]: found override i2c_arm<\/em><\/p>\n<p><em>DTOVERLAY[debug]: override i2c_arm: string target &#8216;status&#8217;<\/em><\/p>\n<p><em>DTOVERLAY[debug]: wrote 166 bytes to &#8216;\/tmp\/.dtoverlays\/69_dtparam.dtbo&#8217;<\/em><\/p>\n<p><em>DTOVERLAY[debug]: wrote 179 bytes to &#8216;\/sys\/kernel\/config\/device-tree\/overlays\/69_dtparam\/dtbo&#8217;<\/em><\/p>\n<p><font style=\"background-color: rgb(255, 255, 0);\"><em>run_cmd: which dtoverlay-post &gt;\/dev\/null 2&gt;&amp;1 &amp;&amp; dtoverlay-post<\/em><\/font><\/p>\n<\/blockquote>\n<p>would hang <strong>before <\/strong>the last command (highlighted in yellow). <\/p>\n<p>Once the other application had released the I2C bus, dtparam would finish it\u2019s job and show the last line. <\/p>\n<p><\/p>\n<p>How can you find out which applications are accessing the i2c bus?<\/p>\n<p>Easily, with lsof:<\/p>\n<blockquote>\n<p><strong>sudo lsof \/dev\/i2c-1<\/strong><\/p>\n<p><em>lsof: WARNING: can&#8217;t stat() fuse.gvfsd-fuse file system \/run\/user\/1000\/gvfs<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Output information may be incomplete.<br \/>\nCOMMAND&nbsp;&nbsp; PID USER&nbsp;&nbsp; FD&nbsp;&nbsp; TYPE DEVICE SIZE\/OFF&nbsp;&nbsp; NODE NAME<br \/>\npython3 24772 root&nbsp;&nbsp; 13u&nbsp;&nbsp; CHR&nbsp;&nbsp; 89,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0t0 285423 \/dev\/i2c-1<\/em>\n<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2021\/07\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"113\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2021\/07\/image_thumb.png\" border=\"0\"><\/a><\/p>\n<p>in my case depending on the activity of the two apps (CO2 and BME688), the file could be open two times as well:<\/p>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2021\/07\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"828\" height=\"138\" title=\"image\" style=\"display: inline; background-image: none;\" alt=\"image\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2021\/07\/image_thumb-1.png\" border=\"0\"><\/a><\/p>\n<p>My recommendation is, since there does not seem to be a workaround for dtparam hanging (and thus raspi-config hanging) when I2C is being accessed \/ open, to check the state of the file descriptors first, and show the user an error message if this is the case (that they will need to disable the applications first for this to work). <\/p>\n<p><\/p>\n<p>NB: for Python\u2019s SMBus, you can simply use <strong>bus.close()<\/strong> (if you called your SMBus instance bus)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bei der Entwicklung von PiCockpit und dem Versuch, dem Benutzer die M\u00f6glichkeit zu geben, I2C \u00fcber das Webinterface auszuschalten, bin ich auf Abst\u00fcrze und Probleme gesto\u00dfen. Ich verwende raspi-config im nicht-interaktiven Modus (dar\u00fcber habe ich schon einmal geschrieben), um I2C vom PiCockpit Client aus zu steuern. Beim Debuggen des Problems habe ich festgestellt, dass - wenn etwas mit dem Zugriff auf...<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[400],"tags":[965,955,964],"class_list":["post-28721","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi-embedded-development","tag-dtoverlay","tag-i2c","tag-raspi-config"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/28721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=28721"}],"version-history":[{"count":1,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/28721\/revisions"}],"predecessor-version":[{"id":28722,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/28721\/revisions\/28722"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=28721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=28721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=28721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}