Skip to content

Commit

Permalink
new environments for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsl authored and tpetazzoni committed Oct 29, 2021
1 parent 9194823 commit aacad75
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 431 deletions.
57 changes: 33 additions & 24 deletions common/labs-header.tex
Expand Up @@ -6,51 +6,60 @@
\usepackage{verbatim}
\usepackage{moreverb}
\usepackage{xcolor}
\usepackage{mdframed}

% Custom bootlin commands

% environment for long lines of code/cmd input with backslash at end of line
\lstnewenvironment{terminalinput}{\lstset{
\definecolor{mygray}{rgb}{0.8,0.8,0.8}

\lstset{
autogobble,
language=[LaTeX]TeX,
basicstyle=\ttfamily,
breaklines=true,
escapechar={\%},
prebreak=\textbackslash,
literate={-}{{-\allowbreak}}{1},
% aboveskip=0pt
belowskip=0pt,
% postbreak=\mbox{\textcolor{red}{$\rightarrow$}\space},
columns=fullflexible
}

% environment for long lines of code/cmd input with backslash at end of line
\lstnewenvironment{terminalinput}
{
\lstset{
prebreak=\textbackslash,
alsoletter={()[].=:-},
}}{}

\surroundwithmdframed[innerleftmargin=1pt,innerrightmargin=1pt,skipabove=\topskip,skipbelow=\topskip,linewidth=0pt,innertopmargin=1pt, innerbottommargin=1pt, backgroundcolor=lightgray!20]{terminalinput}

\def\clinput{\lstinline[basicstyle=\ttfamily]}

\newcommand\ubootcli[1]{\colorbox{mygray}{\lstinline[#1]}}

\def\inlinecode#1{%
\colorbox{lightgray!15}{\lstinline{#1}}%
}

\newcommand\bashcmd[1]{\begin{mdframed}[innerleftmargin=1pt,innerrightmargin=1pt,skipabove=\topskip,skipbelow=\topskip,linewidth=0pt,innertopmargin=4pt, innerbottommargin=4pt,backgroundcolor=lightgray!20]{\lstinline{#1}}\end{mdframed}}

\newcommand\ubootcmd[1]{\begin{mdframed}[innerleftmargin=1pt,innerrightmargin=1pt,skipabove=\topskip,skipbelow=\topskip,linewidth=0pt,innertopmargin=4pt, innerbottommargin=4pt,backgroundcolor=blue!5]{\lstinline[]{#1}}\end{mdframed}}

% environment for long lines of u-boot cmd input without backslash at end of line
\lstnewenvironment{ubootinput}{\lstset{
autogobble,
language=[LaTeX]TeX,
basicstyle=\ttfamily,
breaklines=true,
escapechar={\%},
prebreak={},
belowskip=0pt,
% postbreak=\mbox{\textcolor{red}{$\rightarrow$}\space},
columns=fullflexible
alsoletter={()[].=:-},
}}{}

% environment for long lines of cmd output without backslash but with
\surroundwithmdframed[innerleftmargin=1pt,innerrightmargin=1pt,skipabove=\topskip,skipbelow=\topskip,linewidth=0pt,innertopmargin=1pt, innerbottommargin=1pt, backgroundcolor=blue!5]{ubootinput}

% following lines aligned at left margin
\lstnewenvironment{terminaloutput}{\lstset{
language=[LaTeX]TeX,
basicstyle=\ttfamily,
breakautoindent=false,
alsoletter={()[].=:-},
breakindent=0pt,
breaklines=true,
escapechar={\%},
prebreak={},
belowskip=0pt,
% postbreak=\mbox{\textcolor{red}{$\rightarrow$}\space},
columns=fullflexible
}}{}

%\surroundwithmdframed[innerleftmargin=1pt,innerrightmargin=1pt,skipabove=\topskip,skipbelow=\topskip,linewidth=0pt,innertopmargin=1pt, innerbottommargin=1pt, backgroundcolor=blue!5]{terminaloutput}

\newcommand{\sourcecode}[1]{\verbatimtabinput{../#1}{\small (Source code link:
\url{https://raw.githubusercontent.com/bootlin/training-materials/master/#1})}}

Expand Down
24 changes: 16 additions & 8 deletions common/sysdev-kernel-cross-compiling-sama5d3.tex
Expand Up @@ -17,29 +17,35 @@ \section{Flashing the kernel and DTB in NAND flash}

% Verbatim doesn't seem to work in this \ifdefstring environment

\code{nand erase 0x180000 0x20000} ({\em NAND-offset size})
\begin{ubootinput}
=> nand erase 0x180000 0x20000} %\rmfamily({\em NAND-offset size})%
\end{ubootinput}

Then, let's erase the 5 MiB of NAND flash for the kernel image:

% Verbatim doesn't seem to work in this \ifdefstring environment
\code{nand erase 0x1a0000 0x500000}
\ubootcmd{=> nand erase 0x1a0000 0x500000}

Then, copy the DTB and kernel binaries from TFTP into memory, using the
same addresses as before.

Then, flash the DTB and kernel binaries:

% Verbatim doesn't seem to work in this \ifdefstring environment
\code{nand write 0x22000000 0x180000 0x20000} ({\em RAM-addr NAND-offset size})\\
\code{nand write 0x21000000 0x1a0000 0x500000}
\begin{ubootinput}
=> nand write 0x22000000 0x180000 0x20000} %\rmfamily({\em RAM-addr NAND-offset size})%
=> nand write 0x21000000 0x1a0000 0x500000
\end{ubootinput}

Power your board off and on, to clear RAM contents. We should now be
able to load the DTB and kernel image from NAND and boot with:

% Verbatim doesn't seem to work in this \ifdefstring environment
\code{nand read 0x22000000 0x180000 0x20000} ({\em RAM-addr offset size})\\
\code{nand read 0x21000000 0x1a0000 0x500000}\\
\code{bootz 0x21000000 - 0x22000000}
\begin{ubootinput}
=> nand read 0x22000000 0x180000 0x20000} %\rmfamily({\em RAM-addr offset size})%
=> nand read 0x21000000 0x1a0000 0x500000
=> bootz 0x21000000 - 0x22000000
\end{ubootinput}

Write a U-Boot script that automates the DTB + kernel download
and flashing procedure.
Expand All @@ -48,7 +54,9 @@ \section{Flashing the kernel and DTB in NAND flash}
from flash. But first, save the settings for booting from \code{tftp}:

% Verbatim doesn't seem to work in this \ifdefstring environment
\code{setenv bootcmdtftp ${bootcmd}}
\begin{ubootinput}
=> setenv bootcmdtftp ${bootcmd}
\end{ubootinput}
This will be useful to switch back to \code{tftp} booting mode
later in the labs.
Expand Down
6 changes: 3 additions & 3 deletions labs/setup/setup.tex
Expand Up @@ -8,9 +8,9 @@ \section{Install lab data}

%{\small % leaving here as a marker if font sizes are needed
\begin{terminalinput}
cd
wget %\sessionurl%/__SESSION_NAME__-labs.tar.xz
tar xvf __SESSION_NAME__-labs.tar.xz
$ cd
$ wget %\sessionurl%/__SESSION_NAME__-labs.tar.xz
$ tar xvf __SESSION_NAME__-labs.tar.xz
\end{terminalinput}
%}
Lab data are now available in an \code{__SESSION_NAME__-labs} directory in
Expand Down
40 changes: 17 additions & 23 deletions labs/sysdev-application-debugging/sysdev-application-debugging.tex
Expand Up @@ -67,10 +67,10 @@ \section{Using strace}
Update the PATH:
\footnotesize
\begin{verbatim}
export PATH=$HOME/__SESSION_NAME__-labs/debugging/buildroot-2021.02.<n>/output/host/bin:$PATH
\end{verbatim}
%\footnotesize
\begin{terminalinput}
$ export PATH=$HOME/__SESSION_NAME__-labs/debugging/buildroot-2021.02.<n>/output/host/bin:$PATH
\end{terminalinput}
\normalsize
With your cross-compiling toolchain
Expand Down Expand Up @@ -119,19 +119,13 @@ \section{Using gdbserver}
connection from \code{gdb}, and will control the execution of
\code{vista-emulator} according to the \code{gdb} commands:
\begin{verbatim}
gdbserver localhost:2345 vista-emulator
\end{verbatim}
\ubootcmd{=> gdbserver localhost:2345 vista-emulator}
On the host side, run \code{arm-linux-gdb} (also found in your toolchain):
\begin{verbatim}
arm-linux-gdb vista-emulator
\end{verbatim}
\bashcmd{$ arm-linux-gdb vista-emulator}
You can also start the debugger through the \code{ddd} interface:
\begin{verbatim}
ddd --debugger arm-linux-gdb vista-emulator
\end{verbatim}
\bashcmd{$ ddd --debugger arm-linux-gdb vista-emulator}
\code{gdb} starts and loads the debugging information from the
\code{vista-emulator} binary that has been compiled with \code{-g}.
Expand All @@ -141,31 +135,31 @@ \section{Using gdbserver}
your workstation. This is done by setting the \code{gdb} \code{sysroot}
variable (on one line):
\begin{verbatim}
(gdb) set sysroot /home/<user>/__SESSION_NAME__-labs/debugging/
buildroot-2021.02.<n>/output/staging
\end{verbatim}
\begin{terminalinput}
(gdb) set sysroot /home/<user>/__SESSION_NAME__-labs/debugging/\
buildroot-2021.02.<n>/output/staging
\end{terminalinput}
Of course, replace \code{<user>} by your actual user name.
And tell \code{gdb} to connect to the remote system:
\begin{verbatim}
\begin{terminalinput}
(gdb) target remote <target-ip-address>:2345
\end{verbatim}
\end{terminalinput}
Then, use \code{gdb} as usual to set breakpoints, look at the source
code, run the application step by step, etc. Graphical versions of
\code{gdb}, such as \code{ddd} can also be used in the same way.
In our case, we'll just start the program and wait for it to hit
the segmentation fault:
\begin{verbatim}
\begin{terminalinput}
(gdb) continue
\end{verbatim}
\end{terminalinput}
You could then ask for a backtrace to see where this happened:
\begin{verbatim}
\begin{terminalinput}
(gdb) backtrace
\end{verbatim}
\end{terminalinput}
This will tell you that the segmentation fault occurred in a function
of the C library, called by our program. This should help you in
Expand Down
Expand Up @@ -23,17 +23,14 @@ \section{Compile your own application}
Let's add this directory to our \code{PATH}:
\footnotesize
\begin{verbatim}
export PATH=$HOME/__SESSION_NAME__-labs/buildroot/buildroot-2021.02.X/output/host/usr/bin:$PATH
\end{verbatim}
\begin{terminalinput}
$ export PATH=$HOME/__SESSION_NAME__-labs/buildroot/buildroot-2021.02.X/output/host/usr/bin:$PATH
\end{terminalinput}
\normalsize

Let's try to compile the application:

\begin{verbatim}
arm-linux-gcc -o app app.c
\end{verbatim}
\bashcmd{$ arm-linux-gcc -o app app.c}
It complains about undefined references to some symbols. This is
normal, since we didn't tell the compiler to link with the necessary
Expand All @@ -45,9 +42,7 @@ \section{Compile your own application}
already knows the right paths to find \code{.pc} files and their
sysroot.}:
\begin{verbatim}
arm-linux-gcc -o app app.c $(pkg-config --libs --cflags ncurses)
\end{verbatim}
\bashcmd{$ arm-linux-gcc -o app app.c $(pkg-config --libs --cflags ncurses)}
Our application is now compiled! Copy the generated binary to the NFS
root filesystem (in the \code{root/} directory for example), start
Expand Down
26 changes: 6 additions & 20 deletions labs/sysdev-block-filesystems/sysdev-block-filesystems.tex
Expand Up @@ -60,23 +60,17 @@ \section{Prepare the SD card}
Type the \code{mount} command to check your currently mounted
partitions. If SD partitions are mounted, unmount them:
\begin{verbatim}
$ sudo umount /dev/mmcblk0p*
\end{verbatim}
\bashcmd{$ sudo umount /dev/mmcblk0p*}
Then, clear possible SD card contents remaining from previous
training sessions (only the first megabytes matter):
\begin{verbatim}
$ sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=256
\end{verbatim}
\bashcmd{$ sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=256}
Now, let's use the \code{cfdisk} command to create the partitions that
we are going to use:
\begin{verbatim}
$ sudo cfdisk /dev/mmcblk0
\end{verbatim}
\bashcmd{$ sudo cfdisk /dev/mmcblk0}
If \code{cfdisk} asks you to \code{Select a label type}, choose
\code{dos}. This corresponds to traditional partitions tables that DOS/Windows
Expand Down Expand Up @@ -119,9 +113,7 @@ \section{Data partition on the SD card}
Using the \code{mkfs.ext4} create a journaled file system on the
third partition of the SD card:
\begin{verbatim}
sudo mkfs.ext4 -L data -E nodiscard /dev/mmcblk0p3
\end{verbatim}
\bashcmd{$ sudo mkfs.ext4 -L data -E nodiscard /dev/mmcblk0p3}
\begin{itemize}
\item \code{-L} assigns a volume name to the partition
Expand Down Expand Up @@ -195,9 +187,7 @@ \section{Booting on the SquashFS partition}
\section{Store the kernel image and DTB on the SD card}
You'll first need to format the first partition, using:
\begin{verbatim}
sudo mkfs.vfat -F 32 -n boot /dev/mmcblk0p1
\end{verbatim}
\bashcmd{$ sudo mkfs.vfat -F 32 -n boot /dev/mmcblk0p1}
It will create a new FAT32 partition, called \code{boot}. Remove and
plug the SD card back in. You can now copy the kernel image and
Expand All @@ -209,11 +199,7 @@ \section{Store the kernel image and DTB on the SD card}
In U-boot, you can load a file from a FAT filesystem using a command
like

\begin{verbatim}
fatload mmc 0:1 0x21000000 filename
\end{verbatim}

\ubootcmd{=> fatload mmc 0:1 0x21000000 filename}
Which will load the file named \code{filename} from the first
partition of the device handled by the first MMC controller to the
system memory at the address \code{0x21000000}.
Expand Down
12 changes: 3 additions & 9 deletions labs/sysdev-buildroot/sysdev-buildroot.tex
Expand Up @@ -58,9 +58,7 @@ \section{Configure Buildroot}
To run the configuration utility of Buildroot, simply run:
\begin{verbatim}
make menuconfig
\end{verbatim}
\bashcmd{$ make menuconfig}
Set the following options. Don't hesitate to press the \code{Help}
button whenever you need more details about a given option:
Expand Down Expand Up @@ -141,9 +139,7 @@ \section{Generate the embedded Linux system}
Just run:
\begin{verbatim}
make
\end{verbatim}
\bashcmd{$ make}
Buildroot will first create a small environment with the external
toolchain, then download, extract, configure, compile and install each
Expand Down Expand Up @@ -190,9 +186,7 @@ \section{Run the generated system}
a new \code{nfsroot} directory that is going to hold our system,
exported over NFS. Go into this directory, and untar the rootfs using:
\begin{verbatim}
tar xvf ../buildroot-2021.02.<n>/output/images/rootfs.tar
\end{verbatim}
\bashcmd{$ tar xvf ../buildroot-2021.02.<n>/output/images/rootfs.tar}
Add our \code{nfsroot} directory to the list of directories exported
by NFS in \code{/etc/exports}, and make sure the board uses it too.
Expand Down
10 changes: 5 additions & 5 deletions labs/sysdev-flash-filesystems/sysdev-flash-filesystems.tex
Expand Up @@ -94,11 +94,11 @@ \section{Filesystem image preparation}
To do so, erase your \code{UBI} partition and let U-Boot initialize
a new UBI space on it:
\begin{verbatim}
nand erase.part UBI
ubi part UBI
ubi info
\end{verbatim}
\begin{ubootinput}
=> nand erase.part UBI
=> ubi part UBI
=> ubi info
\end{ubootinput}
This will give you plenty of information about UBI on your NAND flash,
in particular the {\em PEB} and {\em LEB} sizes.
Expand Down

0 comments on commit aacad75

Please sign in to comment.