blob: 99edb67eed0002e87e94739afce8b4aae3e66e45 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Compile-Time Configuration and Initialization &mdash; Apache Mynewt latest documentation</title>
<link rel="shortcut icon" href="../../../_static/mynewt-logo-only-newt32x32.png"/>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/sphinx_theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/bootstrap-3.0.3.min.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/v2.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/restructuredtext.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/overrides.css" type="text/css" />
<link rel="index" title="Index"
href="../../../genindex.html"/>
<link rel="search" title="Search" href="../../../search.html"/>
<link rel="top" title="Apache Mynewt latest documentation" href="../../../index.html"/>
<link rel="up" title="OS User Guide" href="../../os_user_guide.html"/>
<link rel="next" title="Validation and Error Messages" href="sysconfig_error.html"/>
<link rel="prev" title="Porting Mynewt to a new CPU Architecture" href="../../core_os/porting/port_cpu.html"/>
<script src="../../../_static/js/modernizr.min.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-72162311-1", "auto");
ga("send", "pageview");
</script>
</head>
<body class="not-front page-documentation" role="document" >
<div id="wrapper">
<div class="container">
<div id="banner" class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="../../../_static/img/logo.png">
</a>
<div class="tagline-cell">
<h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
</div>
<div class="news-cell">
<div class="well">
<h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.11.0, Apache NimBLE 1.6.0 </a> released September 7, 2023)
</div>
</div>
</div>
</div>
<header>
<nav id="navbar" class="navbar navbar-inverse" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
</li>
<li class="important">
<a href="/quick-start/">Quick Start</a>
</li>
<li>
<a href="/about/">About</a>
</li>
<li>
<a href="/talks/">Talks</a>
</li>
<li class="active">
<a href="/documentation/">Documentation</a>
</li>
<li>
<a href="/download/">Download</a>
</li>
<li>
<a href="/community/">Community</a>
</li>
<li>
<a href="/events/">Events</a>
</li>
</ul>
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</header>
<!-- STARTS MAIN CONTENT -->
<div id="main-content">
<div id="breadcrumb">
<div class="container">
<a href="/documentation/">Docs</a> /
<a href="../../os_user_guide.html">OS User Guide</a> /
Compile-Time Configuration and Initialization
<div class="sourcelink">
<a href="https://github.com/apache/mynewt-core/edit/master/docs/os/modules/sysinitconfig/sysinitconfig.rst" class="icon icon-github"
rel="nofollow"> Edit on GitHub</a>
</div>
</div>
</div>
<!-- STARTS CONTAINER -->
<div class="container">
<!-- STARTS .content -->
<div id="content" class="row">
<!-- STARTS .container-sidebar -->
<div class="container-sidebar col-xs-12 col-sm-3">
<div id="docSidebar" class="sticky-container">
<div role="search" class="sphinx-search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search documentation" class="search-documentation" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<!-- Note: only works when deployed -->
<select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest" selected>
Version: latest
</option>
<option value="/v1_11_0" >
Version: 1.11.0
</option>
<option value="/v1_10_0" >
Version: 1.10.0
</option>
<option value="/v1_9_0" >
Version: 1.9.0
</option>
<option value="/v1_8_0" >
Version: 1.8.0
</option>
<option value="/v1_7_0" >
Version: 1.7.0
</option>
<option value="/v1_6_0" >
Version: 1.6.0
</option>
<option value="/v1_5_0" >
Version: 1.5.0
</option>
<option value="/v1_4_0" selected="selected" >
Version: 1.4.0
</option>
<option value="/v1_3_0/os/introduction" >
Version: 1.3.0
</option>
<option value="/v1_2_0/os/introduction" >
Version: 1.2.0
</option>
<option value="/v1_1_0/os/introduction" >
Version: 1.1.0
</option>
<option value="/v1_0_0/os/introduction" >
Version: 1.0.0
</option>
<option value="/v0_9_0/os/introduction" >
Version: 0.9.0
</option>
</select>
<div class="region region-sidebar">
<div class="docs-menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../get_started/index.html">Setup &amp; Get Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../concepts.html">Concepts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../external_links.html">Third-party Resources</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../os_user_guide.html">OS User Guide</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../core_os/mynewt_os.html">Kernel</a></li>
<li class="toctree-l2"><a class="reference internal" href="../system_modules.html">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../hal/hal.html">Hardware Abstraction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../bootloader/bootloader.html">Secure Bootloader</a></li>
<li class="toctree-l2"><a class="reference internal" href="../split/split.html">Split Images</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../core_os/porting/port_os.html">Porting Guide</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Compile-Time Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="sysconfig_error.html">Validation and Error Messages</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../console/console.html">Console</a></li>
<li class="toctree-l2"><a class="reference internal" href="../shell/shell.html">Shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="../testutil/testutil.html">Test Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../json/json.html">JSON</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stats/stats.html">Statistics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../logs/logs.html">Logs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../network/index.html">BLE User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../newt/index.html">Newt Tool Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../newtmgr/index.html">Newt Manager Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mynewt_faq/index.html">Mynewt FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../misc/index.html">Appendix</a></li>
</ul>
</div>
</div>
</div>
<!-- ENDS STICKY CONTAINER -->
</div>
<!-- ENDS .container-sidebar -->
<div class="col-xs-12 col-sm-9">
<div class="alert alert-warning">
<p>
Version 1.4.0 is not the most recent version of the
Apache Mynewt documentation. Click <a href="/latest">here</a> to
read the latest version.
</p>
</div>
<div class="">
<div class="rst-content">
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="compile-time-configuration-and-initialization">
<h1>Compile-Time Configuration and Initialization<a class="headerlink" href="#compile-time-configuration-and-initialization" title="Permalink to this headline">ΒΆ</a></h1>
<div class="toctree-wrapper compound">
</div>
<p>This guide describes how Mynewt manages system configuration and
initialization. It shows you how to tell Mynewt to use default or
customized values to initialize packages that you develop or use to
build a target. This guide:</p>
<ul class="simple">
<li><p>Assumes you have read the
<a class="reference internal" href="../../../concepts.html#concepts"><span class="std std-ref">Concepts</span></a> section that describes
the Mynewt package hierarchy and its use of the <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> and
<code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files.</p></li>
<li><p>Assumes you have read the Mynewt <a class="reference internal" href="../../../newt/newt_operation.html"><span class="doc">Theory of Operations</span></a> and are familiar with how newt
determines package dependencies for your target build.</p></li>
<li><p>Covers only the system initialization for hardware independent
packages. It does not cover the Board Support Package (BSP) and other
hardware dependent system initialization.</p></li>
</ul>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#system-configuration-setting-definitions-and-values" id="id1">System Configuration Setting Definitions and Values</a></p>
<ul>
<li><p><a class="reference internal" href="#examples-of-configuration-settings" id="id2">Examples of Configuration Settings</a></p>
<ul>
<li><p><a class="reference internal" href="#example-1" id="id3">Example 1</a></p></li>
<li><p><a class="reference internal" href="#example-2" id="id4">Example 2</a></p></li>
<li><p><a class="reference internal" href="#example-3" id="id5">Example 3</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#overriding-system-configuration-setting-values" id="id6">Overriding System Configuration Setting Values</a></p>
<ul>
<li><p><a class="reference internal" href="#resolving-override-conflicts" id="id7">Resolving Override Conflicts</a></p></li>
<li><p><a class="reference internal" href="#examples-of-overrides" id="id8">Examples of Overrides</a></p>
<ul>
<li><p><a class="reference internal" href="#example-4" id="id9">Example 4</a></p></li>
<li><p><a class="reference internal" href="#example-5" id="id10">Example 5</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#generated-syscfg-h-and-referencing-system-configuration-settings" id="id11">Generated syscfg.h and Referencing System Configuration Settings</a></p>
<ul>
<li><p><a class="reference internal" href="#example-of-syscfg-h-and-how-to-reference-a-setting-name" id="id12">Example of syscfg.h and How to Reference a Setting Name</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#system-initialization" id="id13">System Initialization</a></p>
<ul>
<li><p><a class="reference internal" href="#specifying-package-initialization-functions" id="id14">Specifying Package Initialization Functions</a></p></li>
<li><p><a class="reference internal" href="#generated-sysinit-app-function" id="id15">Generated sysinit_app() Function</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#conditional-configurations" id="id16">Conditional Configurations</a></p></li>
</ul>
</div>
<p>Mynewt defines several configuration parameters in the <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> and
<code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files. The newt tool uses this information to:</p>
<ul class="simple">
<li><p>Generate a system initialization function that calls all the
package-specific system initialization functions.</p></li>
<li><p>Generate a system configuration header file that contains all the
package configuration settings and values.</p></li>
<li><p>Display the system configuration settings and values in the
<code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">target</span> <span class="pre">config</span></code> command.</p></li>
</ul>
<p>The benefits with this approach include:</p>
<ul class="simple">
<li><p>Allows Mynewt developers to reuse other packages and easily change
their configuration settings without updating source or header files
when implementing new packages.</p></li>
<li><p>Allows application developers to easily view the system configuration
settings and values and determine the values to override for a target
build.</p></li>
</ul>
<div class="section" id="system-configuration-setting-definitions-and-values">
<h2><a class="toc-backref" href="#id1">System Configuration Setting Definitions and Values</a><a class="headerlink" href="#system-configuration-setting-definitions-and-values" title="Permalink to this headline">ΒΆ</a></h2>
<p>A package can optionally:</p>
<ul class="simple">
<li><p>Define and expose the system configuration settings to allow other
packages to override the default setting values.</p></li>
<li><p>Override the system configuration setting values defined by the
packages that it depends on.</p></li>
</ul>
<p>You use the <code class="docutils literal notranslate"><span class="pre">defs</span></code> parameter in a <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file to define the
system configuration settings for a package. <code class="docutils literal notranslate"><span class="pre">defs</span></code> is a mapping (or
associative array) of system configuration setting definitions. It has
the following syntax:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.defs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">PKGA_SYSCFG_NAME1</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span>
<span class="w"> </span><span class="nt">restrictions</span><span class="p">:</span>
<span class="w"> </span><span class="nt">PKGA_SYSCFG_NAME2</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span>
<span class="w"> </span><span class="nt">restrictions</span><span class="p">:</span>
</pre></div>
</div>
<p>Each setting definition consists of the following key-value mapping:</p>
<ul>
<li><p>A setting name for the key, such as <code class="docutils literal notranslate"><span class="pre">PKGA_SYSCFG_NAME1</span></code> in the
syntax example above. <strong>Note:</strong> A system configuration setting name
must be unique. The newt tool aborts the build when multiple packages
define the same setting.</p></li>
<li><p>A mapping of fields for the value. Each field itself is a key-value
pair of attributes. The field keys are <code class="docutils literal notranslate"><span class="pre">description</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>,
<code class="docutils literal notranslate"><span class="pre">type</span></code>, and <code class="docutils literal notranslate"><span class="pre">restrictions</span></code>. They are described in following
table:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 13%" />
<col style="width: 87%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Field</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>description</p></td>
<td><p>Describes the usage for the setting. This field is optional.</p></td>
</tr>
<tr class="row-odd"><td><p>value</p></td>
<td><p>Specifies the default value for the setting. This field is required. The
value depends on the type that you specify and can be an empty string.</p></td>
</tr>
<tr class="row-even"><td><p>type</p></td>
<td><p>Specifies the data type for the value field. This field is optional. You
can specify one of three types:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">raw</span></code>:</dt><dd><p>The <code class="docutils literal notranslate"><span class="pre">value</span></code> data is uninterpreted. This is the default <code class="docutils literal notranslate"><span class="pre">type</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">task_priority</span></code>:</dt><dd><p>Specifies a Mynewt task priority number. The task
priority number assigned to each setting must be unique and between 0
and 239. value can be one of the following:</p>
<p>A number between 0 and 239 - The task priority number to use for the
setting.</p>
<p><code class="docutils literal notranslate"><span class="pre">any</span></code> - Specify <code class="docutils literal notranslate"><span class="pre">any</span></code> to have newt automatically assign a priority for the
setting.
newt alphabetically orders all system configuration settings of this
type and assigns the next highest available task priority number to each
setting.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">flash_owner</span></code>:</dt><dd><p>Specifies a flash area. The value should be the name of a
flash area defined in the BSP flash map for your target board.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>restrictions</p></td>
<td><p>Specifies a list of restrictions on the setting value. <strong>This field is
optional</strong>. You can specify two formats:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">$notnull</span></code>:</dt><dd><p>Specifies that the setting cannot have the empty string for a
value. It essentially means that an empty string is not a sensible value
and a package must override it with an appropriate value.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">expression</span></code>:</dt><dd><p>Specifies a boolean expression of the form
<code class="docutils literal notranslate"><span class="pre">[!]&amp;ltrequired-setting&gt;[if</span> <span class="pre">&amp;ltbase-value&gt;]</span></code></p>
</dd>
</dl>
<p>Examples:</p>
<p><code class="docutils literal notranslate"><span class="pre">restrictions:</span> <span class="pre">!LOG_FCB</span></code> - When this setting is enabled, <code class="docutils literal notranslate"><span class="pre">LOG_FCB</span></code> must be
disabled.</p>
<p><code class="docutils literal notranslate"><span class="pre">restrictions:</span> <span class="pre">LOG_FCB</span> <span class="pre">if</span> <span class="pre">0</span></code> - When this setting is disabled, <code class="docutils literal notranslate"><span class="pre">LOG_FCB</span></code>
must be enabled.</p>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<div class="section" id="examples-of-configuration-settings">
<h3><a class="toc-backref" href="#id2">Examples of Configuration Settings</a><a class="headerlink" href="#examples-of-configuration-settings" title="Permalink to this headline">ΒΆ</a></h3>
<div class="section" id="example-1">
<h4><a class="toc-backref" href="#id3">Example 1</a><a class="headerlink" href="#example-1" title="Permalink to this headline">ΒΆ</a></h4>
<p>The following example is an excerpt from the
<code class="docutils literal notranslate"><span class="pre">sys/log/full</span></code> package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file. It defines the
<code class="docutils literal notranslate"><span class="pre">LOG_LEVEL</span></code> configuration setting to specify the log level and the
<code class="docutils literal notranslate"><span class="pre">LOG_NEWTMGR</span></code> configuration setting to specify whether to enable or
disable the newtmgr logging feature.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.defs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">LOG_LEVEL</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;Log</span><span class="nv"> </span><span class="s">Level&#39;</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">raw</span>
<span class="w"> </span><span class="w w-Error"> </span><span class="l l-Scalar l-Scalar-Plain">...</span>
<span class="w"> </span><span class="nt">LOG_NEWTMGR</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;Enables</span><span class="nv"> </span><span class="s">or</span><span class="nv"> </span><span class="s">disables</span><span class="nv"> </span><span class="s">newtmgr</span><span class="nv"> </span><span class="s">command</span><span class="nv"> </span><span class="s">tool</span><span class="nv"> </span><span class="s">logging&#39;</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
</pre></div>
</div>
</div>
<div class="section" id="example-2">
<h4><a class="toc-backref" href="#id4">Example 2</a><a class="headerlink" href="#example-2" title="Permalink to this headline">ΒΆ</a></h4>
<p>The following example is an excerpt from the
<code class="docutils literal notranslate"><span class="pre">net/nimble/controller</span></code> package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file. It defines the
<code class="docutils literal notranslate"><span class="pre">BLE_LL_PRIO</span></code> configuration setting with a <code class="docutils literal notranslate"><span class="pre">task_priority</span></code> type and
assigns task priority 0 to the BLE link layer task.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.defs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">BLE_LL_PRIO</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;BLE</span><span class="nv"> </span><span class="s">link</span><span class="nv"> </span><span class="s">layer</span><span class="nv"> </span><span class="s">task</span><span class="nv"> </span><span class="s">priority&#39;</span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;task_priority&#39;</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
</pre></div>
</div>
</div>
<div class="section" id="example-3">
<h4><a class="toc-backref" href="#id5">Example 3</a><a class="headerlink" href="#example-3" title="Permalink to this headline">ΒΆ</a></h4>
<p>The following example is an excerpt from the <code class="docutils literal notranslate"><span class="pre">fs/nffs</span></code>
package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.defs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">NFFS_FLASH_AREA</span><span class="p">:</span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;The</span><span class="nv"> </span><span class="s">flash</span><span class="nv"> </span><span class="s">area</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">use</span><span class="nv"> </span><span class="s">for</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">Newtron</span><span class="nv"> </span><span class="s">Flash</span><span class="nv"> </span><span class="s">File</span><span class="nv"> </span><span class="s">System&#39;</span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">flash_owner</span>
<span class="w"> </span><span class="nt">value</span><span class="p">:</span>
<span class="w"> </span><span class="nt">restrictions</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">$notnull</span>
</pre></div>
</div>
<p>It defines the <code class="docutils literal notranslate"><span class="pre">NFFS_FLASH_AREA</span></code> configuration setting with a
<code class="docutils literal notranslate"><span class="pre">flash_owner</span></code> type indicating that a flash area needs to be specified
for the Newtron Flash File System. The flash areas are typically defined
by the BSP in its <code class="docutils literal notranslate"><span class="pre">bsp.yml</span></code> file. For example, the <code class="docutils literal notranslate"><span class="pre">bsp.yml</span></code> for
nrf52dk board (<code class="docutils literal notranslate"><span class="pre">hw/bsp/nrf52dk/bsp.yml</span></code>) defines an area named
<code class="docutils literal notranslate"><span class="pre">FLASH_AREA_NFFS</span></code>:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">FLASH_AREA_NFFS</span><span class="p">:</span>
<span class="w"> </span><span class="nt">user_id</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span>
<span class="w"> </span><span class="nt">device</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">offset</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0x0007d000</span>
<span class="w"> </span><span class="nt">size</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">12kB</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file for the same board
(<code class="docutils literal notranslate"><span class="pre">hw/bsp/nrf52dk/syscfg.yml</span></code>) specifies that the above area be used
for <code class="docutils literal notranslate"><span class="pre">NFFS_FLASH_AREA</span></code>.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.vals</span><span class="p">:</span>
<span class="w"> </span><span class="nt">CONFIG_FCB_FLASH_AREA</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">FLASH_AREA_NFFS</span>
<span class="w"> </span><span class="nt">REBOOT_LOG_FLASH_AREA</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">FLASH_AREA_REBOOT_LOG</span>
<span class="w"> </span><span class="nt">NFFS_FLASH_AREA</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">FLASH_AREA_NFFS</span>
<span class="w"> </span><span class="nt">COREDUMP_FLASH_AREA</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">FLASH_AREA_IMAGE_1</span>
</pre></div>
</div>
<p>Note that the <code class="docutils literal notranslate"><span class="pre">fs/nffs/syscfg.yml</span></code> file indicates that the
<code class="docutils literal notranslate"><span class="pre">NFFS_FLASH_AREA</span></code> setting cannot be a null string; so a higher
priority package must set a non-null value to it. That is exactly what
the BSP package does. For more on priority of packages in setting
values, see the next section.</p>
</div>
</div>
</div>
<div class="section" id="overriding-system-configuration-setting-values">
<h2><a class="toc-backref" href="#id6">Overriding System Configuration Setting Values</a><a class="headerlink" href="#overriding-system-configuration-setting-values" title="Permalink to this headline">ΒΆ</a></h2>
<p>A package may use the <code class="docutils literal notranslate"><span class="pre">vals</span></code> parameter in its <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file to
override the configuration values defined by other packages. This
mechanism allows:</p>
<ul class="simple">
<li><p>Mynewt developers to implement a package and easily override the
system configuration setting values that are defined by the packages
it depends on.</p></li>
<li><p>Application developers to easily and cleanly override default
configuration settings in a single place and build a customized
target. You can use the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">target</span> <span class="pre">config</span> <span class="pre">show</span> <span class="pre">&lt;target-name&gt;</span></code>
command to check all the system configuration setting definitions and
values in your target to determine the setting values to override.
See <a class="reference external" href="/newt/command_list/newt_target.html">newt target</a>.</p></li>
</ul>
<p><code class="docutils literal notranslate"><span class="pre">vals</span></code> specifies the mappings of system configuration setting
name-value pairs as follows:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.vals</span><span class="p">:</span>
<span class="w"> </span><span class="nt">PKGA_SYSCFG_NAME1</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">VALUE1</span>
<span class="w"> </span><span class="nt">PKGA_SYSCFG_NAME2</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">VALUE2</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span>
<span class="w"> </span><span class="nt">PKGN_SYSCFG_NAME1</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">VALUEN</span>
</pre></div>
</div>
<p><strong>Note</strong>: The newt tool ignores overrides of undefined system
configuration settings.</p>
<div class="section" id="resolving-override-conflicts">
<h3><a class="toc-backref" href="#id7">Resolving Override Conflicts</a><a class="headerlink" href="#resolving-override-conflicts" title="Permalink to this headline">ΒΆ</a></h3>
<p>The newt tool uses package priorities to determine whether a package can
override a value and resolve conflicts when multiple packages override
the same system configuration setting. The following rules apply:</p>
<ul class="simple">
<li><p>A package can only override the default values of system
configuration settings that are defined by lower priority packages.</p></li>
<li><p>When packages with different priorities override the same system
configuration setting value, newt uses the value from the highest
priority package.</p></li>
<li><p>Packages of equal priority cannot override the same system
configuration setting with different values. newt aborts the build
unless a higher priority package also overrides the value.</p></li>
</ul>
<p>The following package types are listed from highest to lowest priority:</p>
<ul class="simple">
<li><p>Target</p></li>
<li><p>App</p></li>
<li><p>unittest - A target can include either an app or unit test package,
but not both.</p></li>
<li><p>BSP</p></li>
<li><p>Lib - Includes all other system level packages such as os, lib, sdk,
and compiler. (Note that a Lib package cannot override other Lib
package settings.)</p></li>
</ul>
<p>It is recommended that you override defaults at the target level instead
of updating individual package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files.</p>
</div>
<div class="section" id="examples-of-overrides">
<h3><a class="toc-backref" href="#id8">Examples of Overrides</a><a class="headerlink" href="#examples-of-overrides" title="Permalink to this headline">ΒΆ</a></h3>
<div class="section" id="example-4">
<h4><a class="toc-backref" href="#id9">Example 4</a><a class="headerlink" href="#example-4" title="Permalink to this headline">ΒΆ</a></h4>
<p>The following example is an excerpt from the
<code class="docutils literal notranslate"><span class="pre">apps/slinky</span></code> package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file. The application package
overrides, in addition to other packages, the <code class="docutils literal notranslate"><span class="pre">sys/log/full</span></code> package
system configuration settings defined in <a class="reference internal" href="#example-1">Example 1</a>. It changes the
LOG_NEWTMGR system configuration setting value from <code class="docutils literal notranslate"><span class="pre">0</span></code> to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">syscfg.vals</span><span class="p">:</span>
<span class="w"> </span><span class="c1"># Enable the shell task.</span>
<span class="w"> </span><span class="nt">SHELL_TASK</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span>
<span class="w"> </span><span class="c1"># Enable newtmgr commands.</span>
<span class="w"> </span><span class="nt">STATS_NEWTMGR</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span>
<span class="w"> </span><span class="nt">LOG_NEWTMGR</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span>
</pre></div>
</div>
</div>
<div class="section" id="example-5">
<h4><a class="toc-backref" href="#id10">Example 5</a><a class="headerlink" href="#example-5" title="Permalink to this headline">ΒΆ</a></h4>
<p>The following example are excerpts from the
<code class="docutils literal notranslate"><span class="pre">hw/bsp/native</span></code> package <code class="docutils literal notranslate"><span class="pre">bsp.yml</span></code> and <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files. The
package defines the flash areas for the BSP flash map in the <code class="docutils literal notranslate"><span class="pre">bsp.yml</span></code>
file, and sets the <code class="docutils literal notranslate"><span class="pre">NFFS_FLASH_AREA</span></code> configuration setting value to
use the flash area named <code class="docutils literal notranslate"><span class="pre">FLASH_AREA_NFFS</span></code> in the <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">bsp.flash_map</span><span class="p">:</span>
<span class="w"> </span><span class="nt">areas</span><span class="p">:</span>
<span class="w"> </span><span class="c1"># System areas.</span>
<span class="w"> </span><span class="nt">FLASH_AREA_BOOTLOADER</span><span class="p">:</span>
<span class="w"> </span><span class="nt">device</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">offset</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0x00000000</span>
<span class="w"> </span><span class="nt">size</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">16kB</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span>
<span class="w"> </span><span class="c1"># User areas.</span>
<span class="w"> </span><span class="nt">FLASH_AREA_REBOOT_LOG</span><span class="p">:</span>
<span class="w"> </span><span class="nt">user_id</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">device</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">offset</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0x00004000</span>
<span class="w"> </span><span class="nt">size</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">16kB</span>
<span class="w"> </span><span class="nt">FLASH_AREA_NFFS</span><span class="p">:</span>
<span class="w"> </span><span class="nt">user_id</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span>
<span class="w"> </span><span class="nt">device</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span>
<span class="w"> </span><span class="nt">offset</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0x00008000</span>
<span class="w"> </span><span class="nt">size</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">32kB</span>
<span class="nt">syscfg.vals</span><span class="p">:</span>
<span class="w"> </span><span class="nt">NFFS_FLASH_AREA</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">FLASH_AREA_NFFS</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="generated-syscfg-h-and-referencing-system-configuration-settings">
<h2><a class="toc-backref" href="#id11">Generated syscfg.h and Referencing System Configuration Settings</a><a class="headerlink" href="#generated-syscfg-h-and-referencing-system-configuration-settings" title="Permalink to this headline">ΒΆ</a></h2>
<p>The newt tool processes all the package <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files and
generates the <code class="docutils literal notranslate"><span class="pre">bin/&lt;target-path&gt;/generated/include/syscfg/syscfg.h</span></code>
include file with <code class="docutils literal notranslate"><span class="pre">#define</span></code> statements for each system configuration
setting defined. Newt creates a <code class="docutils literal notranslate"><span class="pre">#define</span></code> for a setting name as
follows:</p>
<ul class="simple">
<li><p>Adds the prefix <code class="docutils literal notranslate"><span class="pre">MYNEWT_VAL_</span></code>.</p></li>
<li><p>Replaces all occurrences of β€œ/”, β€œ-β€œ, and ” ” in the setting name
with β€œ_”.</p></li>
<li><p>Converts all characters to upper case.</p></li>
</ul>
<p>For example, the #define for my-config-name setting name is
MYNEWT_VAL_MY_CONFIG_NAME.</p>
<p>Newt groups the settings in <code class="docutils literal notranslate"><span class="pre">syscfg.h</span></code> by the packages that defined
them. It also indicates the package that changed a system configuration
setting value.</p>
<p>You must use the <code class="docutils literal notranslate"><span class="pre">MYNEWT_VAL()</span></code> macro to reference a #define of a
setting name in your header and source files. For example, to reference
the <code class="docutils literal notranslate"><span class="pre">my-config-name</span></code> setting name, you use
<code class="docutils literal notranslate"><span class="pre">MYNEWT_VAL(MY_CONFIG_NAME)</span></code>.</p>
<p><strong>Note:</strong> You only need to include <code class="docutils literal notranslate"><span class="pre">syscfg/syscfg.h</span></code> in your source
files to access the <code class="docutils literal notranslate"><span class="pre">syscfg.h</span></code> file. The newt tool sets the correct
include path to build your target.</p>
<div class="section" id="example-of-syscfg-h-and-how-to-reference-a-setting-name">
<h3><a class="toc-backref" href="#id12">Example of syscfg.h and How to Reference a Setting Name</a><a class="headerlink" href="#example-of-syscfg-h-and-how-to-reference-a-setting-name" title="Permalink to this headline">ΒΆ</a></h3>
<p><strong>Example 6</strong>: The following example are excerpts from a sample
<code class="docutils literal notranslate"><span class="pre">syscfg.h</span></code> file generated for an app/slinky target and from the
<code class="docutils literal notranslate"><span class="pre">sys/log/full</span></code> package <code class="docutils literal notranslate"><span class="pre">log.c</span></code> file that shows how to reference a
setting name.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">syscfg.h</span></code> file shows the <code class="docutils literal notranslate"><span class="pre">sys/log/full</span></code> package definitions and
also indicates that <code class="docutils literal notranslate"><span class="pre">app/slinky</span></code> changed the value for the
<code class="docutils literal notranslate"><span class="pre">LOG_NEWTMGR</span></code> settings.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span>
<span class="cm"> * This file was generated by Apache Newt version: 1.0.0-dev</span>
<span class="cm"> */</span>
<span class="cp">#ifndef H_MYNEWT_SYSCFG_</span>
<span class="cp">#define H_MYNEWT_SYSCFG_</span>
<span class="cm">/**</span>
<span class="cm"> * This macro exists to ensure code includes this header when needed. If code</span>
<span class="cm"> * checks the existence of a setting directly via ifdef without including this</span>
<span class="cm"> * header, the setting macro will silently evaluate to 0. In contrast, an</span>
<span class="cm"> * attempt to use these macros without including this header will result in a</span>
<span class="cm"> * compiler error.</span>
<span class="cm"> */</span>
<span class="cp">#define MYNEWT_VAL(x) MYNEWT_VAL_ ## x</span>
<span class="cm">/* ... */</span>
<span class="cm">/*** kernel/os */</span>
<span class="cp">#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT</span>
<span class="cp">#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (12)</span>
<span class="cp">#endif</span>
<span class="cp">#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE</span>
<span class="cp">#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (292)</span>
<span class="cp">#endif</span>
<span class="cm">/* ... */</span>
<span class="cm">/*** sys/log/full */</span>
<span class="cp">#ifndef MYNEWT_VAL_LOG_LEVEL</span>
<span class="cp">#define MYNEWT_VAL_LOG_LEVEL (0)</span>
<span class="cp">#endif</span>
<span class="cm">/* ... */</span>
<span class="cm">/* Overridden by apps/slinky (defined by sys/log/full) */</span>
<span class="cp">#ifndef MYNEWT_VAL_LOG_NEWTMGR</span>
<span class="cp">#define MYNEWT_VAL_LOG_NEWTMGR (1)</span>
<span class="cp">#endif</span>
<span class="cp">#endif</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">log_init()</span></code> function in the <code class="docutils literal notranslate"><span class="pre">sys/log/full/src/log.c</span></code> file
initializes the <code class="docutils literal notranslate"><span class="pre">sys/log/full</span></code> package. It checks the <code class="docutils literal notranslate"><span class="pre">LOG_NEWTMGR</span></code>
setting value, using <code class="docutils literal notranslate"><span class="pre">MYNEWT_VAL(LOG_NEWTMGR)</span></code>, to determine whether
the target application has enabled the <code class="docutils literal notranslate"><span class="pre">newtmgr</span> <span class="pre">log</span></code> functionality. It
only registers the the callbacks to process the <code class="docutils literal notranslate"><span class="pre">newtmgr</span> <span class="pre">log</span></code> commands
when the setting value is non-zero.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span>
<span class="nf">log_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">rc</span><span class="p">;</span>
<span class="w"> </span><span class="cm">/* Ensure this function only gets called by sysinit. */</span>
<span class="w"> </span><span class="n">SYSINIT_ASSERT_ACTIVE</span><span class="p">();</span>
<span class="w"> </span><span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">rc</span><span class="p">;</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">log_inited</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="n">log_inited</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<span class="w"> </span><span class="cm">/* ... */</span>
<span class="cp">#if MYNEWT_VAL(LOG_NEWTMGR)</span>
<span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">log_nmgr_register_group</span><span class="p">();</span>
<span class="w"> </span><span class="n">SYSINIT_PANIC_ASSERT</span><span class="p">(</span><span class="n">rc</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>
<span class="cp">#endif</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="system-initialization">
<h2><a class="toc-backref" href="#id13">System Initialization</a><a class="headerlink" href="#system-initialization" title="Permalink to this headline">ΒΆ</a></h2>
<p>During system startup, Mynewt creates a default event queue and a main
task to process events from this queue. You can override the
<code class="docutils literal notranslate"><span class="pre">OS_MAIN_TASK_PRIO</span></code> and <code class="docutils literal notranslate"><span class="pre">OS_MAIN_TASK_STACK_SIZE</span></code> setting values
defined by the <code class="docutils literal notranslate"><span class="pre">kernel/os</span></code> package to specify different task priority
and stack size values.</p>
<p>Your application’s <code class="docutils literal notranslate"><span class="pre">main()</span></code> function executes in the context of the
main task and must perform the following:</p>
<ul class="simple">
<li><p>At the start of <code class="docutils literal notranslate"><span class="pre">main()</span></code>, call the Mynewt <code class="docutils literal notranslate"><span class="pre">sysinit()</span></code> function to
initialize the packages before performing any other processing.</p></li>
<li><p>At the end of <code class="docutils literal notranslate"><span class="pre">main()</span></code>, wait for and dispatch events from the
default event queue in an infinite loop.</p></li>
</ul>
<p><strong>Note:</strong> You must include the <code class="docutils literal notranslate"><span class="pre">sysinit/sysinit.h</span></code> header file to
access the <code class="docutils literal notranslate"><span class="pre">sysinit()</span></code> function.</p>
<p>Here is an example of a <code class="docutils literal notranslate"><span class="pre">main()</span></code> function:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span>
<span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="cm">/* First, call sysinit() to perform the system and package initialization */</span>
<span class="w"> </span><span class="n">sysinit</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* ... other application initialization processing ... */</span>
<span class="w"> </span><span class="cm">/* Last, process events from the default event queue. */</span>
<span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">os_eventq_run</span><span class="p">(</span><span class="n">os_eventq_dflt_get</span><span class="p">());</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="cm">/* main never returns */</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="section" id="specifying-package-initialization-functions">
<h3><a class="toc-backref" href="#id14">Specifying Package Initialization Functions</a><a class="headerlink" href="#specifying-package-initialization-functions" title="Permalink to this headline">ΒΆ</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">sysinit()</span></code> function calls the <code class="docutils literal notranslate"><span class="pre">sysinit_app()</span></code> function to
perform system initialization for the packages in the target. You can,
optionally, specify one or more package initialization functions that
<code class="docutils literal notranslate"><span class="pre">sysinit_app()</span></code> calls to initialize a package.</p>
<p>A package initialization function must have the following prototype:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="n">init_func_name</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
</pre></div>
</div>
<p>Package initialization functions are called in stages to ensure that
lower priority packages are initialized before higher priority packages.
A stage is an integer value, 0 or higher, that specifies when an
initialization function is called. Mynewt calls the package
initialization functions in increasing stage number order. The call
order for initialization functions with the same stage number depends on
the order the packages are processed, and you cannot rely on a specific
call order for these functions.</p>
<p>You use the <code class="docutils literal notranslate"><span class="pre">pkg.init</span></code> parameter in the <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> file to specify an
initialization function and the stage number to call the function. You
can specify multiple initialization functions, with a different stage
number for each function, for the parameter values. This feature allows
packages with interdependencies to perform initialization in multiple
stages.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">pkg.init</span></code> parameter has the following syntax in the <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code>
file:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">pkg.init</span><span class="p">:</span>
<span class="w"> </span><span class="nt">pkg_init_func1_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">pkg_init_func1_stage</span>
<span class="w"> </span><span class="nt">pkg_init_func2_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">pkg_init_func2_stage</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span>
<span class="w"> </span><span class="nt">pkg_init_funcN_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">pkg_init_funcN_stage</span>
</pre></div>
</div>
<p>where <code class="docutils literal notranslate"><span class="pre">pkg_init_func#_name</span></code> is the C function name of an
initialization function, and <code class="docutils literal notranslate"><span class="pre">pkg_init_func#_stage</span></code> is an integer
value, 0 or higher, that indicates the stage when the
<code class="docutils literal notranslate"><span class="pre">pkg_init_func#_name</span></code> function is called.</p>
<p><strong>Note:</strong> The <code class="docutils literal notranslate"><span class="pre">pkg.init_function</span></code> and <code class="docutils literal notranslate"><span class="pre">pkg.init_stage</span></code> parameters
introduced in a previous release for specifying a package initialization
function and a stage number are deprecated and have been retained to
support the legacy format. They will not be maintained for future
releases and we recommend that you migrate to use the <code class="docutils literal notranslate"><span class="pre">pkg.init</span></code>
parameter.</p>
</div>
<div class="section" id="generated-sysinit-app-function">
<h3><a class="toc-backref" href="#id15">Generated sysinit_app() Function</a><a class="headerlink" href="#generated-sysinit-app-function" title="Permalink to this headline">ΒΆ</a></h3>
<p>The newt tool processes the <code class="docutils literal notranslate"><span class="pre">pkg.init</span></code> parameters in all the
<code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> files for a target, generates the <code class="docutils literal notranslate"><span class="pre">sysinit_app()</span></code> function
in the <code class="docutils literal notranslate"><span class="pre">&lt;target-path&gt;/generated/src/&lt;target-name&gt;-sysinit_app.c</span></code> file,
and includes the file in the build. Here is an example <code class="docutils literal notranslate"><span class="pre">sysinit_app()</span></code>
function:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span>
<span class="cm"> * This file was generated by Apache Newt (incubating) version: 1.0.0-dev</span>
<span class="cm"> */</span>
<span class="cp">#if !SPLIT_LOADER</span>
<span class="kt">void</span><span class="w"> </span><span class="nf">split_app_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
<span class="kt">void</span><span class="w"> </span><span class="nf">os_pkg_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
<span class="kt">void</span><span class="w"> </span><span class="nf">imgmgr_module_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
<span class="cm">/* ... */</span>
<span class="kt">void</span><span class="w"> </span><span class="nf">stats_module_init</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
<span class="kt">void</span>
<span class="nf">sysinit_app</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="cm">/*** Stage 0 */</span>
<span class="w"> </span><span class="cm">/* 0.0: kernel/os */</span>
<span class="w"> </span><span class="n">os_pkg_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 2 */</span>
<span class="w"> </span><span class="cm">/* 2.0: sys/flash_map */</span>
<span class="w"> </span><span class="n">flash_map_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 10 */</span>
<span class="w"> </span><span class="cm">/* 10.0: sys/stats/full */</span>
<span class="w"> </span><span class="n">stats_module_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 20 */</span>
<span class="w"> </span><span class="cm">/* 20.0: sys/console/full */</span>
<span class="w"> </span><span class="n">console_pkg_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 100 */</span>
<span class="w"> </span><span class="cm">/* 100.0: sys/log/full */</span>
<span class="w"> </span><span class="n">log_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* 100.1: sys/mfg */</span>
<span class="w"> </span><span class="n">mfg_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* ... */</span>
<span class="w"> </span><span class="cm">/*** Stage 300 */</span>
<span class="w"> </span><span class="cm">/* 300.0: sys/config */</span>
<span class="w"> </span><span class="n">config_pkg_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 500 */</span>
<span class="w"> </span><span class="cm">/* 500.0: sys/id */</span>
<span class="w"> </span><span class="n">id_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* 500.1: sys/shell */</span>
<span class="w"> </span><span class="n">shell_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* ... */</span>
<span class="w"> </span><span class="cm">/* 500.4: mgmt/imgmgr */</span>
<span class="w"> </span><span class="n">imgmgr_module_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*** Stage 501 */</span>
<span class="w"> </span><span class="cm">/* 501.0: mgmt/newtmgr/transport/nmgr_shell */</span>
<span class="w"> </span><span class="n">nmgr_shell_pkg_init</span><span class="p">();</span>
<span class="p">}</span>
<span class="cp">#endif</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="conditional-configurations">
<h2><a class="toc-backref" href="#id16">Conditional Configurations</a><a class="headerlink" href="#conditional-configurations" title="Permalink to this headline">ΒΆ</a></h2>
<p>You can use the system configuration setting values to conditionally
specify parameter values in <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> and <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> files. The
syntax is:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">parameter_name.PKGA_SYSCFG_NAME</span><span class="p">:</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">parameter_value</span>
</pre></div>
</div>
<p>This specifies that <code class="docutils literal notranslate"><span class="pre">parameter_value</span></code> is only set for
<code class="docutils literal notranslate"><span class="pre">parameter_name</span></code> if the <code class="docutils literal notranslate"><span class="pre">PKGA_SYSCFG_NAME</span></code> configuration setting
value is non-zero. Here is an example from the <code class="docutils literal notranslate"><span class="pre">libs/os</span></code> package
<code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> file:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">pkg.deps</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">sys/sysinit</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">util/mem</span>
<span class="l l-Scalar l-Scalar-Plain">pkg.deps.OS_CLI</span>
<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">- sys/shell</span>
</pre></div>
</div>
<p>This example specifies that the <code class="docutils literal notranslate"><span class="pre">os</span></code> package depends on the
<code class="docutils literal notranslate"><span class="pre">sysinit</span></code> and <code class="docutils literal notranslate"><span class="pre">mem</span></code> packages, and also depends on the <code class="docutils literal notranslate"><span class="pre">shell</span></code>
package when <code class="docutils literal notranslate"><span class="pre">OS_CLI</span></code> is enabled.</p>
<p>The newt tool aborts the build when it detects circular conditional
dependencies.</p>
</div>
</div>
</div>
</div>
<div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation">
<a href="sysconfig_error.html" class="btn btn-neutral float-right" title="Validation and Error Messages" accesskey="n">Next: Validation and Error Messages <span class="fa fa-arrow-circle-right"></span></a>
<a href="../../core_os/porting/port_cpu.html" class="btn btn-neutral" title="Porting Mynewt to a new CPU Architecture" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: Porting Mynewt to a new CPU Architecture</a>
</div>
</div>
</div>
</div>
<!-- ENDS CONTENT SECTION -->
</div>
<!-- ENDS .content -->
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-xs-12">
<p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p>
</div>
<div class="col-xs-12">
<div class="logos">
<img src="../../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
<small class="footnote">
Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either
registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries.
</small>
<a href="">
<img src="../../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
</div>
</div>
</footer>
</div>
<!-- ENDS #wrapper -->
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../../',
VERSION:'latest',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt',
LINK_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/underscore.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<script type="text/javascript" src="../../../_static/js/bootstrap-3.0.3.min.js"></script>
<script type="text/javascript" src="../../../_static/js/affix.js"></script>
<script type="text/javascript" src="../../../_static/js/main.js"></script>
</body>
</html>