<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title><![CDATA[0xpebbles.org]]></title>
    <link><![CDATA[http://blog.0xpebbles.org]]></link>
    <description><![CDATA[0xpebbles blog]]></description>
    <lastBuildDate>Fri, 09 Apr 2021 08:37:23 +0200</lastBuildDate>
    <pubDate>Fri, 09 Apr 2021 08:37:23 +0200</pubDate>
    <language>en</language>

<!-- 20190817 -->    <item>
      <title>PowerVR SGX on the BeagleBone Black in 2019</title>
      <link>http://blog.0xpebbles.org/PowerVR-SGX-on-the-beaglebone-black-in-2019</link>
      <pubDate>17 Aug 2019 00:00:00 +0000</pubDate>
      <content:encoded><![CDATA[

  

<p>
Since I spent way too much time on figuring this out, confused by plenty of old and outdated online
sources, here is how one would get the PowerVR SGX driver running on a current
Linux in 2019 - in this case a debian 9.6 with a 4.4 kernel. Other combinations
might/should work also, but I have not tested them.
</p>

<p>
To summarize briefly, the difference to the previous ways of getting the SGX
stuff running, is that the old <em>GFX_SDK_*</em> based setups are outdated. This
includes <em>omaplfb.ko</em> kernel module based instructions, which also come from the
<em>GFX_SDK_*</em> times.
Last but not least, it looks like one has to run a <em>TI kernel</em> (updated
to with flag --ti-kernel, see below), as the <em>bone kernel</em>s (--bone-kernel)
don't seem to have the new SGX driver stack.
</p>

<p>
I used <a href="https://rcn-ee.com/rootfs/2018-12-10/microsd/bone-debian-9.6-console-armhf-2018-12-10-2gb.img.xz">bone-debian-9.6-console-armhf-2018-12-10-2gb.img.xz</a> from RobertCNelson's
site at <a href="https://rcn-ee.com/rootfs/2018-12-10/microsd/">https://rcn-ee.com/rootfs/2018-12-10/microsd/</a>, as I wanted a leaner
base system than what's available on <a href="https://beagleboard.org/latest-images">https://beagleboard.org/latest-images</a>.
</p>

<p>
To put it in a nutshell, we need to run a TI kernel, and install the matching
SGX DDK, and ideally initialize it on startup. So on your system on the BBB
the following should install the TI kernel (v4.4, which worked for me) - the below assumes
that the default user <em>debian</em> of the image is used, so some sudo is needed occasionally:
</p>

<style type="text/css">
<!--
pre.sh { font-family: monospace; color: #dadada; background-color: #000000; }
.shShellVariables { color: #87afff; }
.Comment { color: #626262; }
.Constant { color: #87afff; font-weight: bold; }
.Special { color: #00d700; font-weight: bold; }
.String { color: #8787ff; }
.Statement { color: #ff8700; font-weight: bold; }
-->
</style>

<pre class="sh">
<span class="Statement">cd</span> /opt/scripts/tools

<span class="Comment"># install TI kernel, this also installs the matching SGX drivers</span>
git pull                                       <span class="Comment"># fetch latest revisions of kernels to upgrade to</span>
sudo ./update_kernel.sh <span class="Special">--ti-kernel</span> <span class="Special">--lts-4_4</span>  <span class="Comment"># if branch not there anymore, make sure whatever branch is used contains a working pvrsrvkm.ko</span>
sudo reboot
</pre>

<p>
Now the SGX DDK, which we'll build from source:
</p>

<pre class="sh">
<span class="Comment"># some libs for later</span>
sudo apt install <span class="Special">-y</span> libdrm-omap1 libgbm1

<span class="Comment"># get the SGX DDK for userland libraries, demos and tools needed to initialize PowerVR</span>
<span class="Comment"># NOTE: the branch used below has to match kernel version, change if using different kernel above</span>
<span class="Statement">cd</span> ~
git clone <span class="Special">-b</span> ti-img-sgx/<span class="Constant">1</span>.<span class="Constant">14</span>.3699939_k4.<span class="Constant">4</span> git://git.ti.com/graphics/omap5-sgx-ddk-um-linux.git <span class="Special">--depth=1</span>
<span class="Statement">cd</span> omap5-sgx-ddk-um-linux/
sudo env <span class="Identifier">DISCIMAGE</span>=/ <span class="Identifier">TARGET_PRODUCT</span>=ti335x make install
<span class="Statement">cd</span> ~
<span class="Statement">rm</span> <span class="Special">-rf</span> ./omap5-sgx-ddk-um-linux

<span class="Comment"># hackfix needed missing reference to libgbm.so.2</span>
sudo ln <span class="Special">-s</span> /usr/lib/arm-linux-gnueabihf/libgbm.so.<span class="Constant">1</span> /usr/lib/arm-linux-gnueabihf/libgbm.so.<span class="Constant">2</span>

<span class="Comment"># verify driver loaded - should show pvrsrvkm</span>
lsmod | <span class="Statement">grep</span> pvr

<span class="Comment"># verify, there should be some info like &quot;[drm] Initialized&quot; and &quot;PVR_K: UM DDK...&quot; infos</span>
dmesg | <span class="Statement">grep</span> <span class="Special">-i</span> <span class="Special">-C</span>1 <span class="Statement">'</span><span class="String">drm\|sgx\|pvr</span><span class="Statement">'</span>

<span class="Comment"># set mode SGX should work in - at this point there are three installed, but</span>
<span class="Comment"># only one that works, as the libpvrws_WAYLAND.so and libpvrGBMWSEGL.so are</span>
<span class="Comment"># both for DRM/WAYLAND based multi-window systems and weston isn't installed.</span>
<span class="Comment"># According to the docs there also should be libpvrDRMWSEGL_FRONT.so, a no-vsync</span>
<span class="Comment"># and thus faster version of libpvrDRMWSEGL.so.</span>
<span class="Comment"># Other options like pixel format can also be set to RGB565, RGB888 or ARGB8888,</span>
<span class="Comment"># select the one that works for you (colors might be swapped for 565 or 888, depending</span>
<span class="Comment"># on LCD wiring, see TI's AM335x silicon errata.</span>
sudo <span class="Statement">rm</span> /etc/powervr.ini
sudo tee <span class="Special">-a</span> /etc/powervr.ini <span class="Statement">&lt;&lt;EOF</span>
<span class="String">[default]</span>
<span class="String">WindowSystem=libpvrDRMWSEGL.so</span>
<span class="String">DefaultPixelFormat=RGB888</span>
<span class="Statement">EOF</span>

<span class="Comment"># init powervr for testing, will be automated later, below</span>
sudo /usr/bin/pvrsrvctl <span class="Special">--start</span> <span class="Special">--no-module</span>

<span class="Comment"># verify via tools shipped in the omap5-sgx-ddk:</span>
<span class="Statement">cd</span> /usr/bin   <span class="Comment"># b/c gles2test1 depending on that pwd for shader files in /usr/bin/</span>
eglinfo       <span class="Comment"># should spit out a lot of things</span>
gles1test1 x  <span class="Comment"># shows some spinning triangles on green background (arg is num_frames it should run I guess, non-integer args make it run forever)</span>
gles2test1 x  <span class="Comment"># similar but on purple backgroun (see above for dummy arg x) - if red background check powervr.ini's pixel format we set above</span>
<span class="Statement">cd</span> -

<span class="Comment"># more info about SGX chip if needed</span>
<span class="Statement">cat</span> /proc/pvr/version
</pre>

<p>
If the above installed fine, and all the test steps in the above block also
worked, let's automate the SGX initialization at startup via systemd:
</p>

<pre class="sh">
<span class="Comment"># service script starting PowerVR environment</span>
sudo tee <span class="Special">-a</span> /etc/systemd/system/pvr-init.service <span class="Statement">&lt;&lt;&quot;TTT&quot;</span>
<span class="String">[Unit]</span>
<span class="String">Description=PowerVR</span>
<span class="String">After=multi-user.target</span>
<span class="String">[Service]</span>
<span class="String">Type=oneshot</span>
<span class="String">RemainAfterExit=yes</span>
<span class="String"># startup fails sometimes (too early?), retry in loop - this paired with TimeoutStartSec is a</span>
<span class="String"># workaround to oneshot services refusing decent Restart= settings (at least for systemd &lt;= 232)</span>
<span class="String">ExecStart=/bin/sh -c 'while ! /etc/init.d/rc.pvr start; do sleep 5; done'</span>
<span class="String">ExecStop=/etc/init.d/rc.pvr stop</span>
<span class="String">TimeoutStartSec=60sec</span>
<span class="String">User=root</span>
<span class="String">[Install]</span>
<span class="String">WantedBy=multi-user.target</span>
<span class="Statement">TTT</span>

sudo systemctl enable pvr-init

<span class="Comment"># done</span>
sudo reboot
</pre>

]]></content:encoded>
    </item>




  </channel>
</rss>

