{"id":392,"date":"2018-11-28T05:41:12","date_gmt":"2018-11-28T05:41:12","guid":{"rendered":"https:\/\/www.piboxproject.com\/?p=392"},"modified":"2018-11-28T05:41:12","modified_gmt":"2018-11-28T05:41:12","slug":"the-pibox-software-stack","status":"publish","type":"post","link":"https:\/\/www.piboxproject.com\/index.php\/2018\/11\/28\/the-pibox-software-stack\/","title":{"rendered":"The PiBox Software Stack"},"content":{"rendered":"<div id=\"dslc-theme-content\"><div id=\"dslc-theme-content-inner\"><p>If you build it they will come.<\/p>\n<p>Well I built it and nobody came.\u00a0 At least not yet.\u00a0 PiBox has one developer:\u00a0 Me.\u00a0 Seriously.\u00a0 That&#8217;s it.\u00a0 Let&#8217;s face it:\u00a0 I&#8217;m far better at coding than selling.\u00a0 Not that I care that much since if I did I wouldn&#8217;t still be doing this.\u00a0 PiBox is an obsession.\u00a0 Not like gaming or tweeting or even shoes.\u00a0 More like running or The Great British Baking Show.\u00a0 You know: a healthy obsession.\u00a0 Or at least I keep telling myself that.<\/p>\n<p>It took a few years for the core development platform (re: the build system) to stabilize and become exactly what I&#8217;d hoped: easy to use.\u00a0 I can flip it around to any platform with only a little effort figuring out the toolchain requirements.\u00a0 But then PiBox needed a new direction.\u00a0 A custom distribution doesn&#8217;t do much on it&#8217;s own.\u00a0 It needs applications.\u00a0 Typically end users like to drop an AMP (Apache, MySQL and PHP) stack on a Linux distribution, or the more modern variations that provide Python and\/or NodeJS.\u00a0 That stack is a collection of software providing a set of services beyond what might be provided by the Linux distribution.\u00a0\u00a0 But even with that stack there still isn&#8217;t an actual application, only an idea with no substance.\u00a0 Kind of like Lost.\u00a0 Or Republican health care.<\/p>\n<p>Software stacks are an old idea.\u00a0 I remember discussing them with Ada Lovelace (yes, I&#8217;m older than the hills).\u00a0 They are, in fact, a core part of every electronic product consumers purchase.\u00a0 Each stack is a set of middle-tier software providing services required to make the consumer facing software perform in the most efficient and secure method possible.\u00a0 The web world calls these stacks frameworks.\u00a0 Potato, Potahto.\u00a0 It&#8217;s a bunch of software supporting your shiny new box.\u00a0 But software stacks are everywhere. Consumer products without software stacks these days are known as pet rocks.<\/p>\n<p>But back to my problem with finding a new direction for PiBox.\u00a0 When I started to implement a few consumer facing applications I quickly found that the apps shared a need for some common services.\u00a0 One of the first was the ability to configure the network. There are a bunch of network configuration tools out there already:\u00a0 <a href=\"https:\/\/projects-old.gnome.org\/NetworkManager\/\">Network Manager<\/a>, <a href=\"https:\/\/01.org\/connman\">Connman<\/a>, etc.\u00a0 These are generally UI tools tied to UI frameworks like GNOME or KDE.\u00a0 But surprisingly I was unable to find any libraries for doing the same thing.<\/p>\n<p>Since the existing tools required environments I wasn&#8217;t working with I decided to build my own network tools. Initially I implemented a C program (<a href=\"https:\/\/gitlab.com\/pibox\/pibox-network-config\">pibox-network-config<\/a>, a.k.a. <em>pnc<\/em>) that provided a series of functions to configure Debian-style networking.\u00a0 Then, as an experiment and to learn a little about Javascript, I implemented the same UI as a web application.\u00a0 This made me move the code out of <em>pnc<\/em> and into another application, <a href=\"https:\/\/gitlab.com\/pibox\/piboxd\">piboxd<\/a> which is a daemon that provides services that require root privileges.\u00a0 But before I moved it there I needed to extract it from <em>pnc<\/em>, which then turned into a library I could link to <em>piboxd<\/em>.\u00a0 The beginnings of the middleware software stack were staring me in the face.<\/p>\n<p>Once I realized these middle layers would need to be established before creating any apps I went looking for examples of how I should create a stack. The best example I found was the <a href=\"https:\/\/developer.android.com\/guide\/platform\/\">Android<\/a> <a href=\"https:\/\/en.wikipedia.org\/wiki\/Android_software_development\">stack<\/a>.\u00a0 Android splits the stack into three middle components: an application framework, support libraries and hardware abstraction.\u00a0 The framework layer builds on APIs in the support libraries which in turn build on the hardware abstraction APIs.\u00a0 This is a simplified description but the gist is that this stack provided a simple template for the PiBox stack.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"375\" data-permalink=\"https:\/\/www.piboxproject.com\/index.php\/gallery-view\/pibox\/softwarestack2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?fit=4600%2C3463&amp;ssl=1\" data-orig-size=\"4600,3463\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"SoftwareStack2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?fit=300%2C226&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?fit=1024%2C771&amp;ssl=1\" class=\"aligncenter size-large wp-image-375\" title=\"\" src=\"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?resize=1024%2C771&#038;ssl=1\" alt=\"\" width=\"1024\" height=\"771\" srcset=\"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?resize=1024%2C771&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?resize=300%2C226&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?resize=768%2C578&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?w=2340&amp;ssl=1 2340w, https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2016\/10\/SoftwareStack2.png?w=3510&amp;ssl=1 3510w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>The PiBox stack starts with a layer of 3rd party software at the OS layer, most of which comes from one GitHub repository or another.\u00a0 These provide basic support for the Raspberry Pi but could just as easily provide support for other hardware.\u00a0 It also provides the custom Linux distribution through the use of <a href=\"https:\/\/buildroot.org\/\">Buildroot<\/a> and <a href=\"https:\/\/busybox.net\/\">BusyBox<\/a>, which provide a basic set of utilities.\u00a0 This layer, plus the <em>pnc<\/em> application and <em>libpnc<\/em> (which is generated as part of the <em>pnc<\/em> build), provide the <strong>PiBox Core Distribution<\/strong>.<\/p>\n<p>Just above this layer are additional third party tools for networking.\u00a0 While these tools are included in the core distribution their configuration varies on the use case for higher layer software.\u00a0 Above this are the configuration files for various components, from hardware support to networking to the UI to a stock web server (sans content).\u00a0 Again, these are stock configurations that are often updated the specific use cases.\u00a0 One of the most interesting of these is the custom mdev device handling, specifically with respect to USB devices which is really the only expansion bus available on the Raspberry Pi.<\/p>\n<p>The next layer contains two custom libraries, <a href=\"https:\/\/gitlab.com\/pibox\/pibox-network-config\"><em>libpnc<\/em><\/a> and <a href=\"https:\/\/gitlab.com\/pibox\/libpibox\"><em>libpibox<\/em><\/a>, is also part of the core distribution.\u00a0 The former is the network configuration library mentioned earlier.\u00a0 The latter provides a set of utility functions for applications such as touch screen support, debugging and Raspberry Pi bootloader configuration.\u00a0 While libpibox is included in the core distribution, libpibox is a separate opkg installed package.\u00a0 At this point, everything higher in the stack is installed as a separate opkg package.<\/p>\n<p>A set of packages are used to customize the UI.\u00a0 The psplash package is a simple boot logo for miot, the overriding idea of &#8220;My IoT&#8221;.\u00a0 The <a href=\"https:\/\/gitlab.com\/pibox\/pmsui\"><em>pmsui<\/em><\/a> package provides a GTK+-based theme wrapping the Matchbox window stacked window manager.\u00a0 The stacked window manager implements one of the design intents for applications:\u00a0 only one application runs at a time and is the only application visible.\u00a0 This attempts (but doesn&#8217;t quite manage) to follow the principles found at <a href=\"http:\/\/suckless.org\/\"><em>suckless.org<\/em><\/a>.<\/p>\n<p>The <a href=\"https:\/\/gitlab.com\/pibox\/appmgr\"><em>appmgr<\/em><\/a> package is a daemon that handles starting and stopping apps under the X.org server.\u00a0 This app has no UI and it&#8217;s primary duty is to start and keep running the launcher.\u00a0 The <a href=\"https:\/\/gitlab.com\/pibox\/launcher\"><em>launcher<\/em><\/a> is a package that displays icons for the available apps and handles app selection through either an input device or a touchscreen.\u00a0 The launcher is modeled after launchers available on smartphones or, more accurately, the Roku interface.<\/p>\n<p>The backbone of the software stack if <a href=\"https:\/\/gitlab.com\/pibox\/piboxd\"><em>piboxd<\/em><\/a>, a daemon responsible for message passing between apps.\u00a0\u00a0 Think of this as a really bad dbus implementation, but for the sake of trying to keep the suckless philosophy as much as possible.\u00a0 It also doesn&#8217;t handle network port proxy.\u00a0 It&#8217;s just a message passing interface.\u00a0 It also happens to handle performing actions that non-privileged apps cannot such as network configuration.<\/p>\n<p>All of these layers provide the services required for applications to do something useful under PiBox.\u00a0 The top layer in the above diagram shows the many apps created using these services, including a few dependent third party packages like the Raspberry Pi <a href=\"https:\/\/github.com\/popcornmix\/omxplayer\">omxplayer<\/a>.\u00a0\u00a0 Together, these form the structures of the multiple PiBox projects:\u00a0 the media system, the kiosk, and IronMan home automation.\u00a0 And they show the potential for many new projects that are possible.<\/p>\n<p>The stack will continue to grow for PiBox, providing services that are yet unrequested.\u00a0 But the goals will remain the same:\u00a0 keep them simple, keep them small and then tie them together.\u00a0 It&#8217;s the Unix way.\u00a0 And it still makes sense.<\/p>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Software is like Legos.  You can stack and snap &#8217;em together to build spaceships and giant buildings.  As long as those things are virtual.  But the important thing is stacking software.  Without stacks. software is just a bunch of potential without any substance.<\/p>\n","protected":false},"author":1,"featured_media":430,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[2],"tags":[],"class_list":{"0":"post-392","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tech","8":"czr-hentry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2018\/10\/software-stack.png?fit=2229%2C1796&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8du2Y-6k","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":13,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":443,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/392\/revisions\/443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/media\/430"}],"wp:attachment":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}