mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 03:01:36 +01:00
This commit is contained in:
@@ -470,6 +470,7 @@ pre{ white-space:pre }
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>sudo apt-get install docker
|
||||
./setup
|
||||
./run-docker create && \
|
||||
./run-docker sh -- ./build --download-dependencies qemu-buildroot
|
||||
./run-docker</pre>
|
||||
|
||||
@@ -462,7 +462,7 @@ pre{ white-space:pre }
|
||||
<p>glibc has a check for kernel version, likely obtained from the <code>uname</code> syscall, and if the kernel is not new enough, it quits.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Both gem5 and QEMU however allow setting the reported <code>uname</code> version from the command line, which we do to always match our toolchain.</p>
|
||||
<p>Both gem5 and QEMU however allow setting the reported <code>uname</code> version from the command line for <a href="user-mode-simulation.html">User mode simulation</a>, which we do to always match our toolchain.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>QEMU by default copies the host <code>uname</code> value, but we always override it in our scripts.</p>
|
||||
@@ -479,7 +479,7 @@ pre{ white-space:pre }
|
||||
<p>Source: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/posix/uname.c">userland/posix/uname.c</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The QEMU source that does this is at: <a href="https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931" class="bare">https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931</a></p>
|
||||
<p>The QEMU source that does this is at: <a href="https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931" class="bare">https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931</a> The default ID is just hardcoded on the source.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Bibliography:</p>
|
||||
@@ -497,9 +497,6 @@ pre{ white-space:pre }
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The ID is just hardcoded on the source:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
</ul>
|
||||
|
||||
121
index.html
121
index.html
@@ -3386,6 +3386,7 @@ j = 0</pre>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>sudo apt-get install docker
|
||||
./setup
|
||||
./run-docker create && \
|
||||
./run-docker sh -- ./build --download-dependencies qemu-buildroot
|
||||
./run-docker</pre>
|
||||
@@ -7017,6 +7018,14 @@ cr3 = 0xFFFFF0DCDC000</pre>
|
||||
<p>This just counts every second forever and does not give you a shell.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And to pass command line arguments to the program, you can use <code>--kernel-cli-after-dash</code>:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./run --kernel-cli 'init=/bin/sh' --kernel-cli-after-dash '-c "echo asdf; pwd; ls"'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This method is not very flexible however, as it is hard to reliably pass multiple commands and command line arguments to the init with it, as explained at: <a href="#init-environment">Section 7.4, “Init environment”</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
@@ -7274,29 +7283,31 @@ vim rootfs_overlay/etc/init.d/S99.gitignore
|
||||
<div class="sect2">
|
||||
<h3 id="init-environment"><a class="anchor" href="#init-environment"></a><a class="link" href="#init-environment">7.4. Init environment</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>Documented at <a href="https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html</a>:</p>
|
||||
<p>Documented at <a href="https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html</a>:</p>
|
||||
</div>
|
||||
<div class="quoteblock">
|
||||
<blockquote>
|
||||
<div class="paragraph">
|
||||
<p>The kernel parses parameters from the kernel command line up to "-"; if it doesn’t recognize a parameter and it doesn’t contain a '.', the parameter gets passed to init: parameters with '=' go into init’s environment, others are passed as command line arguments to init. Everything after "-" is passed as an argument to init.</p>
|
||||
<p>The kernel parses parameters from the kernel command line up to "--"; if it doesn’t recognize a parameter and it doesn’t contain a '.', the parameter gets passed to init: parameters with '=' go into init’s environment, others are passed as command line arguments to init. Everything after "--" is passed as an argument to init.</p>
|
||||
</div>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And you can try it out with:</p>
|
||||
<p>And you can try it out with our <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/linux/init_env_poweroff.c">userland/linux/init_env_poweroff.c</a> program:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./run --kernel-cli 'init=/lkmc/linux/init_env_poweroff.out' --kernel-cli-after-dash 'asdf=qwer zxcv'</pre>
|
||||
<pre>./run --kernel-cli 'init=/lkmc/linux/init_env_poweroff.out loglevel=8 go_in_env=val1 with_dot.before=val2' \
|
||||
--kernel-cli-after-dash 'go_in_arg=val3 with_dot.after=val4 zxcv'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>From the <a href="#dry-run">generated QEMU command</a>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains:</p>
|
||||
<p>From the <a href="#dry-run">generated QEMU command</a>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains (or at least would if it weren’t for <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/issues/110" class="bare">https://github.com/cirosantilli/linux-kernel-module-cheat/issues/110</a> oh God), manually indented for readability:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>init=/lkmc/linux/init_env_poweroff.out console=ttyS0 - lkmc_home=/lkmc asdf=qwer zxcv</pre>
|
||||
<pre><6>[ 0.000000] Command line: root=/dev/vda nopat console_msg_format=syslog nokaslr norandmaps panic=-1 printk.devkmsg=on printk.time=y rw
|
||||
init=/lkmc/linux/init_env_poweroff.out loglevel=8 go_in_env=val1 with_dot.before=val2 -- go_in_arg=val3 with_dot.after=val4 zxcv</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
@@ -7304,38 +7315,55 @@ vim rootfs_overlay/etc/init.d/S99.gitignore
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>args:
|
||||
/lkmc/linux/init_env_poweroff.out
|
||||
-
|
||||
zxcv
|
||||
|
||||
env:
|
||||
HOME=/
|
||||
TERM=linux
|
||||
lkmc_home=/lkmc
|
||||
asdf=qwer</pre>
|
||||
<pre><6>[ 2.728992] Run /lkmc/linux/init_env_poweroff.out as init process
|
||||
<7>[ 2.729587] with arguments:
|
||||
<7>[ 2.729820] /lkmc/linux/init_env_poweroff.out
|
||||
<7>[ 2.730085] lkmc_home=/lkmc
|
||||
<7>[ 2.730259] go_in_arg=val3
|
||||
<7>[ 2.730432] with_dot.after=val4
|
||||
<7>[ 2.730623] zxcv
|
||||
<7>[ 2.730767] with environment:
|
||||
<7>[ 2.730960] HOME=/
|
||||
<7>[ 2.731115] TERM=linux
|
||||
<7>[ 2.731267] go_in_env=val</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Source: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/linux/init_env_poweroff.c">userland/linux/init_env_poweroff.c</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>As of the Linux kernel v5.7 (possibly earlier, I’ve skipped a few releases), boot also shows the init arguments and environment very clearly, which is a great addition:</p>
|
||||
<p>Tested as of the Linux kernel v5.7 and possibly earlier, boot also shows the init arguments and environment very clearly when using <a href="#printk">printk</a> at <code>loglevel=8</code>, which is a great addition:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre><6>[ 0.309984] Run /sbin/init as init process
|
||||
<7>[ 0.309991] with arguments:
|
||||
<7>[ 0.309997] /sbin/init
|
||||
<7>[ 0.310004] nokaslr
|
||||
<7>[ 0.310010] -
|
||||
<7>[ 0.310016] with environment:
|
||||
<7>[ 0.310022] HOME=/
|
||||
<7>[ 0.310028] TERM=linux
|
||||
<7>[ 0.310035] earlyprintk=pl011,0x1c090000
|
||||
<7>[ 0.310041] lkmc_home=/lkmc</pre>
|
||||
<pre><6>[ 2.777265] Run /lkmc/linux/init_env_poweroff.out as init process
|
||||
<7>[ 2.777729] with arguments:
|
||||
<7>[ 2.777953] /lkmc/linux/init_env_poweroff.out
|
||||
<7>[ 2.778212] lkmc_home=/lkmc
|
||||
<7>[ 2.778391] go_in_arg=val2
|
||||
<7>[ 2.778554] zxcv
|
||||
<7>[ 2.778705] with environment:
|
||||
<7>[ 2.778901] HOME=/
|
||||
<7>[ 2.779065] TERM=linux
|
||||
<7>[ 2.779223] go_in_env=val1</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>As we can see, the passing of environment variables to init is a bit wonky:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>init</code> and <code>loglevel</code> didn’t go because they were recognized</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>go_in_env</code> went because it wasn’t</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>so things can always break in future kernel releases…​ The only way to guard from this a bit is to use some unique prefix and hope the kernel never decides to use it. We of course use <code>lkmc_*</code> for our variables.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And it is also impossible to pass environment variables that contain dots in them: our <code>with_dot.before</code> is simply gone. Not a common use case, but still, quite insane.</p>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="init-arguments"><a class="anchor" href="#init-arguments"></a><a class="link" href="#init-arguments">7.4.1. init arguments</a></h4>
|
||||
<div class="paragraph">
|
||||
@@ -8381,7 +8409,7 @@ qw er</pre>
|
||||
<p>glibc has a check for kernel version, likely obtained from the <code>uname</code> syscall, and if the kernel is not new enough, it quits.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Both gem5 and QEMU however allow setting the reported <code>uname</code> version from the command line, which we do to always match our toolchain.</p>
|
||||
<p>Both gem5 and QEMU however allow setting the reported <code>uname</code> version from the command line for <a href="#user-mode-simulation">User mode simulation</a>, which we do to always match our toolchain.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>QEMU by default copies the host <code>uname</code> value, but we always override it in our scripts.</p>
|
||||
@@ -8398,7 +8426,7 @@ qw er</pre>
|
||||
<p>Source: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/posix/uname.c">userland/posix/uname.c</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The QEMU source that does this is at: <a href="https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931" class="bare">https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931</a></p>
|
||||
<p>The QEMU source that does this is at: <a href="https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931" class="bare">https://github.com/qemu/qemu/blob/v3.1.0/linux-user/syscall.c#L8931</a> The default ID is just hardcoded on the source.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Bibliography:</p>
|
||||
@@ -8416,9 +8444,6 @@ qw er</pre>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The ID is just hardcoded on the source:</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="stack-smashing-detected-when-using-glibc"><a class="anchor" href="#stack-smashing-detected-when-using-glibc"></a><a class="link" href="#stack-smashing-detected-when-using-glibc">11.4.2. stack smashing detected when using glibc</a></h4>
|
||||
@@ -11244,7 +11269,7 @@ git log | grep -E ' Linux [0-9]+\.' | head</pre>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The arguments are documented in the kernel documentation: <a href="https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html</a></p>
|
||||
<p>The arguments are documented in the kernel documentation: <a href="https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html</a></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>When dealing with real boards, extra command line options are provided on some magic bootloader configuration file, e.g.:</p>
|
||||
@@ -13553,6 +13578,27 @@ echo $?</pre>
|
||||
<div class="sect3">
|
||||
<h4 id="seq-file"><a class="anchor" href="#seq-file"></a><a class="link" href="#seq-file">17.8.2. seq_file</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>TODO these examples broke in kernel 5.0 and we didn’t notice because they just added a flimsy warning and nothing else:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/25399112/how-to-use-a-seq-file-in-linux-kernel-modules/45100058" class="bare">https://stackoverflow.com/questions/25399112/how-to-use-a-seq-file-in-linux-kernel-modules/45100058</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/60570242/seq-file-not-working-properly-after-next-returns-null" class="bare">https://stackoverflow.com/questions/60570242/seq-file-not-working-properly-after-next-returns-null</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Fix with ifdef for kernel 4/5. The error message is:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>seq_file: buggy .next function next [module-name] did not update position index</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Writing trivial read <a href="#file-operations">File operations</a> is repetitive and error prone. The <code>seq_file</code> API makes the process much easier for those trivial cases:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
@@ -30203,6 +30249,9 @@ gensim/models/armv8/isa.ac
|
||||
<li>
|
||||
<p>it is written in Make and Bash rather than Python like LKMC</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>it downloads packages from upstream mirrors rather than having its own copy of them. Therefore, whenever <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/issues/165">some random French research institute decides to break links, your build also breaks</a>. This is not acceptable. There are some mirroring options: <a href="https://risc-a-day.blogspot.com/2015/10/creating-local-mirror-for-buildroot.html" class="bare">https://risc-a-day.blogspot.com/2015/10/creating-local-mirror-for-buildroot.html</a> but it’s not on by default it seems, Buildroot has to have their own official and default mirror of everything.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
|
||||
@@ -459,29 +459,31 @@ pre{ white-space:pre }
|
||||
<div class="sect2">
|
||||
<h3 id="init-environment"><a class="anchor" href="#init-environment"></a><a class="link" href="#init-environment">7.4. Init environment</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>Documented at <a href="https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html</a>:</p>
|
||||
<p>Documented at <a href="https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html</a>:</p>
|
||||
</div>
|
||||
<div class="quoteblock">
|
||||
<blockquote>
|
||||
<div class="paragraph">
|
||||
<p>The kernel parses parameters from the kernel command line up to "-"; if it doesn’t recognize a parameter and it doesn’t contain a '.', the parameter gets passed to init: parameters with '=' go into init’s environment, others are passed as command line arguments to init. Everything after "-" is passed as an argument to init.</p>
|
||||
<p>The kernel parses parameters from the kernel command line up to "--"; if it doesn’t recognize a parameter and it doesn’t contain a '.', the parameter gets passed to init: parameters with '=' go into init’s environment, others are passed as command line arguments to init. Everything after "--" is passed as an argument to init.</p>
|
||||
</div>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And you can try it out with:</p>
|
||||
<p>And you can try it out with our <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/linux/init_env_poweroff.c">userland/linux/init_env_poweroff.c</a> program:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./run --kernel-cli 'init=/lkmc/linux/init_env_poweroff.out' --kernel-cli-after-dash 'asdf=qwer zxcv'</pre>
|
||||
<pre>./run --kernel-cli 'init=/lkmc/linux/init_env_poweroff.out loglevel=8 go_in_env=val1 with_dot.before=val2' \
|
||||
--kernel-cli-after-dash 'go_in_arg=val3 with_dot.after=val4 zxcv'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>From the <a href="dry-run.html">generated QEMU command</a>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains:</p>
|
||||
<p>From the <a href="dry-run.html">generated QEMU command</a>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains (or at least would if it weren’t for <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/issues/110" class="bare">https://github.com/cirosantilli/linux-kernel-module-cheat/issues/110</a> oh God), manually indented for readability:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>init=/lkmc/linux/init_env_poweroff.out console=ttyS0 - lkmc_home=/lkmc asdf=qwer zxcv</pre>
|
||||
<pre><6>[ 0.000000] Command line: root=/dev/vda nopat console_msg_format=syslog nokaslr norandmaps panic=-1 printk.devkmsg=on printk.time=y rw
|
||||
init=/lkmc/linux/init_env_poweroff.out loglevel=8 go_in_env=val1 with_dot.before=val2 -- go_in_arg=val3 with_dot.after=val4 zxcv</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
@@ -489,38 +491,55 @@ pre{ white-space:pre }
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>args:
|
||||
/lkmc/linux/init_env_poweroff.out
|
||||
-
|
||||
zxcv
|
||||
|
||||
env:
|
||||
HOME=/
|
||||
TERM=linux
|
||||
lkmc_home=/lkmc
|
||||
asdf=qwer</pre>
|
||||
<pre><6>[ 2.728992] Run /lkmc/linux/init_env_poweroff.out as init process
|
||||
<7>[ 2.729587] with arguments:
|
||||
<7>[ 2.729820] /lkmc/linux/init_env_poweroff.out
|
||||
<7>[ 2.730085] lkmc_home=/lkmc
|
||||
<7>[ 2.730259] go_in_arg=val3
|
||||
<7>[ 2.730432] with_dot.after=val4
|
||||
<7>[ 2.730623] zxcv
|
||||
<7>[ 2.730767] with environment:
|
||||
<7>[ 2.730960] HOME=/
|
||||
<7>[ 2.731115] TERM=linux
|
||||
<7>[ 2.731267] go_in_env=val</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Source: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/linux/init_env_poweroff.c">userland/linux/init_env_poweroff.c</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>As of the Linux kernel v5.7 (possibly earlier, I’ve skipped a few releases), boot also shows the init arguments and environment very clearly, which is a great addition:</p>
|
||||
<p>Tested as of the Linux kernel v5.7 and possibly earlier, boot also shows the init arguments and environment very clearly when using <a href="printk.html">printk</a> at <code>loglevel=8</code>, which is a great addition:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre><6>[ 0.309984] Run /sbin/init as init process
|
||||
<7>[ 0.309991] with arguments:
|
||||
<7>[ 0.309997] /sbin/init
|
||||
<7>[ 0.310004] nokaslr
|
||||
<7>[ 0.310010] -
|
||||
<7>[ 0.310016] with environment:
|
||||
<7>[ 0.310022] HOME=/
|
||||
<7>[ 0.310028] TERM=linux
|
||||
<7>[ 0.310035] earlyprintk=pl011,0x1c090000
|
||||
<7>[ 0.310041] lkmc_home=/lkmc</pre>
|
||||
<pre><6>[ 2.777265] Run /lkmc/linux/init_env_poweroff.out as init process
|
||||
<7>[ 2.777729] with arguments:
|
||||
<7>[ 2.777953] /lkmc/linux/init_env_poweroff.out
|
||||
<7>[ 2.778212] lkmc_home=/lkmc
|
||||
<7>[ 2.778391] go_in_arg=val2
|
||||
<7>[ 2.778554] zxcv
|
||||
<7>[ 2.778705] with environment:
|
||||
<7>[ 2.778901] HOME=/
|
||||
<7>[ 2.779065] TERM=linux
|
||||
<7>[ 2.779223] go_in_env=val1</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>As we can see, the passing of environment variables to init is a bit wonky:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>init</code> and <code>loglevel</code> didn’t go because they were recognized</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>go_in_env</code> went because it wasn’t</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>so things can always break in future kernel releases…​ The only way to guard from this a bit is to use some unique prefix and hope the kernel never decides to use it. We of course use <code>lkmc_*</code> for our variables.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And it is also impossible to pass environment variables that contain dots in them: our <code>with_dot.before</code> is simply gone. Not a common use case, but still, quite insane.</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -503,6 +503,9 @@ pre{ white-space:pre }
|
||||
<li>
|
||||
<p>it is written in Make and Bash rather than Python like LKMC</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>it downloads packages from upstream mirrors rather than having its own copy of them. Therefore, whenever <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/issues/165">some random French research institute decides to break links, your build also breaks</a>. This is not acceptable. There are some mirroring options: <a href="https://risc-a-day.blogspot.com/2015/10/creating-local-mirror-for-buildroot.html" class="bare">https://risc-a-day.blogspot.com/2015/10/creating-local-mirror-for-buildroot.html</a> but it’s not on by default it seems, Buildroot has to have their own official and default mirror of everything.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
|
||||
@@ -502,7 +502,7 @@ pre{ white-space:pre }
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The arguments are documented in the kernel documentation: <a href="https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html</a></p>
|
||||
<p>The arguments are documented in the kernel documentation: <a href="https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html" class="bare">https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html</a></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>When dealing with real boards, extra command line options are provided on some magic bootloader configuration file, e.g.:</p>
|
||||
|
||||
@@ -473,6 +473,14 @@ pre{ white-space:pre }
|
||||
<p>This just counts every second forever and does not give you a shell.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>And to pass command line arguments to the program, you can use <code>--kernel-cli-after-dash</code>:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./run --kernel-cli 'init=/bin/sh' --kernel-cli-after-dash '-c "echo asdf; pwd; ls"'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This method is not very flexible however, as it is hard to reliably pass multiple commands and command line arguments to the init with it, as explained at: <a href="init-environment.html">Section 7.4, “Init environment”</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
|
||||
@@ -459,6 +459,27 @@ pre{ white-space:pre }
|
||||
<div class="sect3">
|
||||
<h4 id="seq-file"><a class="anchor" href="#seq-file"></a><a class="link" href="#seq-file">17.8.2. seq_file</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>TODO these examples broke in kernel 5.0 and we didn’t notice because they just added a flimsy warning and nothing else:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/25399112/how-to-use-a-seq-file-in-linux-kernel-modules/45100058" class="bare">https://stackoverflow.com/questions/25399112/how-to-use-a-seq-file-in-linux-kernel-modules/45100058</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/60570242/seq-file-not-working-properly-after-next-returns-null" class="bare">https://stackoverflow.com/questions/60570242/seq-file-not-working-properly-after-next-returns-null</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Fix with ifdef for kernel 4/5. The error message is:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>seq_file: buggy .next function next [module-name] did not update position index</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Writing trivial read <a href="file-operations.html">File operations</a> is repetitive and error prone. The <code>seq_file</code> API makes the process much easier for those trivial cases:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
|
||||
Submodule submodules/buildroot updated: b8c14b5bca...ccebc33040
Reference in New Issue
Block a user