<?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>

<!-- 20190616 -->    <item>
      <title>FreeBSD 12 on the 51nb x210</title>
      <link>http://blog.0xpebbles.org/FreeBSD-12-on-the-51nb-x210</link>
      <pubDate>16 Jun 2019 00:00:00 +0000</pubDate>
      <content:encoded><![CDATA[

  

<p>
The x210 is a x201 thinkpad chassis with modern hardware inside, from a group of
chinese hardware modders that started out doing screen upgrades, originally.
Depending on the production batches they run and probably the chassis they have
available the hardware might differ slightly from machine to machine.
The <a href="http://www.cnmod.cn/">group's blog</a> has more info on the
batches, different devices, BIOS updates, etc.. A few notes about the hardware
first, before talking about FreeBSD on the one I got:
</p>

<h3>Hardware Notes</h3>

As said, the hardware depends on the batch, some special runs they sometimes
do, and the chassis used (one can also buy just the board alone). E.g. the
laptop I got does have a Core i5-8250U inside (there are i7 versions, too) and
was in a chassis that came with a default palmrest (no touchpad, but some
others seem to have been shipped with one). It has a WUXGA (1920x1200) display
which is physically actually slightly bigger than the chassi's screen bezel.
</p>

<p>
Since I did want a touchpad (I guess I could've asked them directly, so my bad)
I bought a used palmrest. There are two types for x201* machines that aren't
compatible with each other, grouped as 25W and 35W models with different
connectors, full list <a href="https://support.lenovo.com/es/en/solutions/migr-70510">here</a>
(I needed a 35W one and specifically replaced FRU 60Y5414 with FRU 60Y5415). Turns
out that in order to make the touchpad palmrest fit, some clipping was needed
as the mainboard's m.2 port and another part won't fit otherwise. Some plastic
and metal needs to be removed on both sides of the touchpad, so one before and
two after pictures:
</p>

<div style="clear:both;display:inline-block">
<a href="/media/60Y5415-before.jpg"><img src="/media/60Y5415-before_s.jpg" alt="FRU 60Y5415 before modification" class="thumbnail_l"/></a>
<a href="/media/60Y5415-after-l.jpg"><img src="/media/60Y5415-after-l_s.jpg" alt="FRU 60Y5415 after modification (left)" class="thumbnail_l"/></a>
<a href="/media/60Y5415-after-r.jpg"><img src="/media/60Y5415-after-r_s.jpg" alt="FRU 60Y5415 after modification (right)" class="thumbnail_l"/></a>
</div>

 

<h2>Running FreeBSD 12</h2>

<h3>Graphics and Screen</h3>

<h4>General</h4>

<p>
You'll need FreeBSD 12 for the graphics, I originally tried to make it work on
FreeBSD 11.2, but didn't manage to get it to work.
</p>

<p>
The processor has an <em>Intel UHD Graphics 620</em> integrated GPU. You'll
need to install the <b>graphics/drm-kmod</b> port. Make sure to read the post
install message! E.g. you'll need to add all users that need graphics to the
'video' group, and also put the following in /etc/rc.conf (more infos
<a href="https://wiki.freebsd.org/Graphics">here</a>):
</p>

<pre>
kld_list="/boot/modules/i915kms.ko"
</pre>

<p>
I had some initial problems with the console, but I don't fully remember what.
Either way, setting the following in /boot/loader.conf helped and also gave me
a hires console:
</p>

<pre>
kern.vty=vt
kern.vt.fb.default_mode="1920x1200"
</pre>

<h4>X11 / xorg.conf</h4>

<p>
The <a href="https://wiki.freebsd.org/Graphics">FreeBSD Graphics wiki</a>
suggests that one "should <b>not</b> have to prepare an xorg.conf configuration
file" and that "Xorg should autodetect the driver and utilize the
<a href="https://www.x.org/wiki/ModeSetting/">modesetting</a> Xorg driver and
<a href="https://www.freedesktop.org/wiki/Software/Glamor/">glamor</a> driver".
</p>

<p>
However, this <u>did not work</u> for me on this machine. The autodetection
used the <em>intel</em> driver with <em>uxa</em> as acceleration method, which
was slow and buggy. Not having read carefully the wiki that states clearly that
the autodetection "should [...] utilize the <b>modesetting</b> Xorg driver and
<b>glamor</b> driver", I did switch the acceleration from <em>uxa</em> to
<em>sna</em>, first. This improved the situation by a lot, however some
artefacts remained and X11 froze from time to time (which I was able to
unfreeze by switching to the vt console and back).<br>
Anyways, what was really needed (and works really well) was a custom xorg.conf
that sets the modesetting driver with glamor as acceleration method,
explicitly. So I let <em>X -configure</em> create an xorg.conf template for me
and then specified explicitly in <em>Section "Device"</em>:
</p>

<pre>
Driver  "modesetting"
Option  "AccelMethod" "glamor"
</pre>

<h4>Screen Size</h4>

<p>
As mentioned above, the physical screen size is a tiny bit bigger than the
chassi's bezel. I simply reduced the usable screen area a bit via the window
manager. I use <b>x11-wm/spectrwm</b> which has a <em>region</em> feature,
which allowed me to do that easily. In the end I have a usable region of
1912x1194 pixels, losing 8 pixels on the right, 3 on top and 3 on the bottom.
So the needed spectrwm config entry in this specific case would be:
</p>

<pre>
region = screen[1]:1912x1194+0+3
</pre>

<p>
If not having such support from the wm, one could register and use a new
modeline via xrandr. I did that first, and it works, but I didn't figure out
how to specifically tell it where the screen should start, it was always
anchored in the top left corner.
</p>
<p>
Alternatively, one could also file off some plastic of the bezel, to make use
of the full screen.
</p>

<h4>Screen Brightness</h4>

<p>
The brightness buttons don't work out of the box, and things like kldloading
acpi_ibm(4) won't help - this isn't actually a thinkpad after all. Using
<b>graphics/intel-backlight</b> does not help either, as the GPU doesn't
control the brightness (in contrast to for example the x201), but the embedded
controller does. Poking around the ACPI tables (<em>acpidump -dt</em>) made me quickly
find an already existing method <em>\_SB.PCI0.GFX0.DD1F._BCM</em> that can be
used to set <em>\_SB.PCI0.LPCB.EC0.BKLG</em>, which controls the brightness
levels. So using <b>sysutils/acpi_call</b> we can run (after kldloading
acpi_call first):
</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; }
-->
</style>
<pre class="sh">
acpi_call <span class="Special">-p</span> <span class="String">'\_SB.PCI0.GFX0.DD1F._BCM'</span> <span class="Special">-i</span> <span class="shShellVariables">$VAL</span>   <span class="Comment"># 0 <= $VAL <= 15</span>
</pre>

<p>
The predefined 16 brightness levels are not ideal, 0 is still way brighter than
what you would get from other laptops. The good news is that those levels can
be adjusted by apparently patching the EC firmware (more info
<a href="https://forum.thinkpads.com/viewtopic.php?t=128267">here</a>), however
I haven't done so, myself, though.
</p>

<p>
I also have not looked into hooking up the brightness buttons out of laziness,
but simply wrapped the acpi_call based control above in a convenience script.
</p>


<h3>Sound</h3>

<p>
Seems to work fine out of the box using snd_hda(4). However, in order for the
sound to automatically switch over to the headphone jack when something gets
plugged in, I needed the following in /boot/device.hints:
</p>

<pre>
hint.hdaa.0.nid31.config="as=4 seq=0 device=Speaker"
hint.hdaa.0.nid25.config="as=4 seq=15 device=Headphones"
</pre>

<p>
I looked up the nid numbers needed from the output of <em>sysctl dev.hdaa</em>.
</p>

<p>
The volume buttons I hooked up myself by making use of the XF86 multimedia keys
XF86AudioRaiseVolume and XF86AudioLowerVolume. Since I'm using
<b>x11-wm/spectrwm</b>, as mentioned above, the according spectrwm config
entries would be something along those lines (with some bonus key combinations
to control treble and bass, given we had to bind those buttons manually
anyways):
</p>

<pre>
program[raise_volume]  = mixer vol +2 pcm +2
program[lower_volume]  = mixer vol -2 pcm -2
program[raise_treble]  = mixer treble +5
program[lower_treble]  = mixer treble -5
program[raise_bass]    = mixer bass +5
program[lower_bass]    = mixer bass -5
bind[raise_volume]     = XF86AudioRaiseVolume
bind[lower_volume]     = XF86AudioLowerVolume
bind[raise_treble]     = Control+XF86AudioRaiseVolume
bind[lower_treble]     = Control+XF86AudioLowerVolume
bind[raise_bass]       = Shift+XF86AudioRaiseVolume
bind[lower_bass]       = Shift+XF86AudioLowerVolume
</pre>

<p>
The downside of making use of XF86 multimedia keycodes is that this now only
works in X, of course.
</p>


<h3>WiFi</h3>

<p>
My machine came with a Broadcom BCM4352 802.11ac Mini PCIe WiFi card, for which
there is no driver support at the time of writing. So I replaced it with
another one. Contrary to stock/regular Thinkpads (and laptops in general), the
BIOS the x210 comes with doesn't do any wifi card whitelisting, so swapping out
the card doesn't require any extra work.
</p>


<h3>Webcam</h3>

<p>
The laptop I got also had a webcam installed (from Chicony Electronics), which
shows up as a USB device and works using <b>multimedia/webcamd</b>. For
example, to test it quickly, make sure <em>cuse</em> is kldloaded, then:
</p>

<pre class="sh">
service webcamd onestart <span class="shShellVariables">$DEV</span>  <span class="Comment"># where $DEV is the camera's USB device, e.g. ugen0.2</span>
mplayer tv:// <span class="Special">-tv</span> driver=v4l:width=320:height=240:device=/dev/video0 <span class="Special">-fps</span> <span class="Constant">25</span>
</pre>

<p>
The camera supports in my case the following resolutions: QVGA (320x240), VGA
(640x480), SVGA (800x600), XGA (1024x768), WXGA (1280x800), SXGA (1280x1024)
</p>


<h3>Other</h3>

<ul>
<li>I did not test the modem, microphone jack or the external mini display port so
far.</li>
<li>I did dump the contents of the flash chip using a
<a href="http://dangerousprototypes.com/docs/Bus_Pirate">BusPirate</a>, which
worked fine. Eventually I want to try flashing coreboot, but haven't done so,
yet. No flash write protection seems to be active, so internal flashing could
be used, I guess.</li>
<li>The machine is mostly silent, the fan starts when there is some decent load,
but other than that it doesn't even spin at all and the machine also doesn't
get hot either (around 45°C for idly use).</li>
<li>Suspend to RAM or disk doesn't seem to work, the graphics driver freezes while
trying to suspend and the machine hangs at that point. Maybe a future update
will fix this.</li>
<li>Thinklight and numlock work, but those work without OS support, anyways.</li>
<li>Also, as with the brightness buttons, other Fn-buttons aren't wired up,
either.</li>
<li>I don't have any data to compare the x210's battery life with, but compared to
my x201i it improved greatly. On a 3 year old, already well degraded 9-cell
battery that didn't run the x201i for more than a good hour, this machine gets
4h out of it. I'm not sure what a new battery would yield, but given what I had
before, I'm super happy.</li>
</p>
<p>
<b>UPDATE (2019-10-09):</b> A brand new 9-cell battery with 7800mAh seems to
run this machine for nearly 10h (for light use, e.g. reading stuff, writing
mails, etc.). This is way more than what I actually hoped for.
</p>


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

<!-- 20130925 -->    <item>
      <title>Random MAC address generation with jot and ksh</title>
      <link>http://blog.0xpebbles.org/Random-MAC-address-generation-with-jot-and-ksh</link>
      <pubDate>25 Sep 2013 00:00:00 +0000</pubDate>
      <content:encoded><![CDATA[

  

<p>
Here's a snippet I use to randomize my <b>if</b>'s MAC-48 address. The script makes use of a seed, <b>$1</b>. Note that using a new random address too frequently might just fill up a DHCP server's lease table unnecessarily. Note that this is for a client machine, like a laptop. Depending on the use, modify to clear the two bits referred to in the comment, or not:
</p>

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

<span class="Comment"># $1 is seed</span>

<span class="Comment"># Generate, but clear MSBytes's 2 LSB's to specify 'globally unique' and 'unicast'.</span>
<span class="Statement">printf</span> <span class="Statement">&quot;</span><span class="String">%02x:</span><span class="Statement">&quot;</span> <span class="shShellVariables">$((</span><span class="Special">$</span><span class="shShellVariables">(</span><span class="Special">jot -</span><span class="Statement">r</span><span class="Special"> </span><span class="Constant">1</span><span class="Special"> </span><span class="Constant">0</span><span class="Special"> </span><span class="Constant">255</span><span class="Special"> </span><span class="shShellVariables">$((</span><span class="shShellVariables">$1</span><span class="Special">+</span><span class="Constant">1</span><span class="shShellVariables">)))</span><span class="Special"> </span><span class="Statement">&amp;</span><span class="Special"> </span><span class="Constant">2#11111100</span><span class="shShellVariables">))</span>
jot <span class="Special">-r</span> <span class="Special">-s</span> : <span class="Special">-w</span> %02x <span class="Constant">5</span> <span class="Constant">0</span> <span class="Constant">255</span> <span class="shShellVariables">$1</span>
</pre>

<p>
Then, on FreeBSD I can change <b>$if</b>'s MAC-48 (driver permitting, in my case <b>iwn</b>) as follows:
</p>

<pre class='sh'>ifconfig <span class="shShellVariables">$if</span> link <span class="shShellVariables">$random_mac</span>
</pre>

<p>
If you use DHCP to configure <b>$if</b> it is a good idea to clean out the lease file to avoid requesting the same IP for a different MAC address, leading to problems. On FreeBSD, the lease file for this interface would be <i>/var/db/dhclient.leases.$if</i>.
</p>

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




  </channel>
</rss>

