]> Pileus Git - ~andy/sfvlug/blob - kernel/kernel.tex
Add kernel talk.
[~andy/sfvlug] / kernel / kernel.tex
1 \documentclass{beamer}
2
3 %%%%%%%%%%%%%%%%%%%
4 % Commands/macros %
5 %%%%%%%%%%%%%%%%%%%
6 \newcommand{\link}[1]{
7   \begin{flushright}
8     \scriptsize{#1}
9   \end{flushright}
10 }
11
12 \newcommand{\hdrs}[1]{\large{\textit{\insertsection}}\\\Large{\textbf{#1}}}
13 \newcommand{\hdrss}[1]{\large{\textit{\insertsubsection}}\\\large{\textbf{#1}}}
14
15 %%%%%%%%%%%%%%%%
16 % Header/theme %
17 %%%%%%%%%%%%%%%%
18 %\usetheme[
19 %  pageofpages=of,
20 %  alternativetitlepage=true,
21 %]{Torino}
22 %\setbeamertemplate{footline}{}
23 \setbeamersize{text margin left=10mm} 
24 \setbeamersize{text margin right=5mm} 
25
26 % Import packages
27 \usepackage[english]{babel}
28 \usepackage[latin1]{inputenc}
29 \usepackage{times}
30 \usepackage[T1]{fontenc}
31 \usepackage{graphics}
32 \usepackage{hyperref}
33 \usepackage{ulem}
34 \usepackage{color}
35 \usepackage{listings}
36 \usepackage{xcolor}
37
38 % Diff syntax
39 \definecolor{diffcommit}{rgb}{.50, .50, .00}
40 \definecolor{diffauthor}{rgb}{.50, .50, .00}
41 \definecolor{diffdate}  {rgb}{.50, .50, .00}
42 \definecolor{diffdiff}  {rgb}{.30, .30, .90}
43 \definecolor{diffindex} {rgb}{.50, .00, .50}
44 \definecolor{diffstart} {rgb}{.00, .50, .50}
45 \definecolor{diffadd}   {rgb}{.00, .60, .00}
46 \definecolor{diffdel}   {rgb}{.80, .00, .00}
47
48 \lstdefinelanguage{diff}{
49   basicstyle=\ttfamily\small,
50   morecomment=[f][\color{diffcommit}]{commit},
51   morecomment=[f][\color{diffauthor}]{Author},
52   morecomment=[f][\color{diffdate}]{Date},
53   morecomment=[f][\color{diffdiff}]{diff},
54   morecomment=[f][\color{diffindex}]{index},
55   morecomment=[f][\color{diffstart}]{@@},
56   morecomment=[f][\color{diffadd}]{+},
57   morecomment=[f][\color{diffdel}]{-},
58   morecomment=[f][\color{diffindex}]{+++},
59   morecomment=[f][\color{diffindex}]{---},
60 }
61
62 \lstset{language=diff,
63         basicstyle=\ttfamily,
64         keywordstyle=\color{blue}\ttfamily,
65         stringstyle=\color{red}\ttfamily,
66         commentstyle=\color{green}\ttfamily,
67         morecomment=[l][\color{magenta}]{\#} }
68
69 %%%%%%%%%%%%%%%%%%%%
70 % Title page setup %
71 %%%%%%%%%%%%%%%%%%%%
72 \subject{%
73   kernel,
74   programming
75 }
76
77 \keywords{%
78   linux,
79   kernel
80 }
81
82 \title[Kernel Programming]{%
83   Introduction to Linux Kernel Programming
84 }
85
86 \author[Spencer]{%
87   Andy Spencer
88 }
89
90 \date[2020-01-04]{%
91   Jan. 4, 2020 \\
92   \small{San Fernando Valley Linux Users Group}
93 }
94
95 %%%%%%%%%%%%%%%%%
96 % Content pages %
97 %%%%%%%%%%%%%%%%%
98 % Structure:
99 %   - Examples
100 %     - The typo fix
101 %     - The hardware id
102 %     - The driver debug
103 %     - The new driver
104 %     - The new protocol
105 %     - The new board
106 %   - Development
107 %     - Kernel compiling
108 %     - Booting the kernel
109 %     - Kernel source tree
110 %     - Sending patches
111 %   - Kernel modules
112 %     - Hello, World
113 %     - User Interfaces
114 %       - printk / dmesg
115 %       - /dev, proc, sysfs
116 %       - syscalls, ioctls
117 %     - Devices and Drivers
118 \begin{document}
119
120 %%%%%%%%%%%%%%%%
121 % Introduction %
122 %%%%%%%%%%%%%%%%
123 \begin{frame}[plain]
124   \titlepage
125 \end{frame}
126
127 % Examples
128 % - The typo fix
129 % - The hardware id
130 % - The driver debug
131 % - The new driver
132 % - The new protocol
133 % - The new board
134
135 \section{Examples Patches}
136
137 \begin{frame}[fragile]{\hdrs{The Typo Fix}}
138   \begin{lstlisting}[language=diff,basicstyle=\tiny]
139 commit 9eac0ae1683575375de8c63166b3596b11d3b56a
140 Author: Krzysztof Kozlowski <krzk@kernel.org>
141 Date:   2019-01-08 13:11:40 +0100
142
143     dt-bindings: soc: qcom: Fix trivial language typos
144     
145     Fix few trivial language typos in bindings.
146     
147     Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
148     Signed-off-by: Rob Herring <robh@kernel.org>
149
150 diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt b/Docume...
151 index 0b8cc533ca83..cf759e5f9b10 100644
152 --- a/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt
153 +++ b/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt
154 @@ -55,7 +55,7 @@ of these nodes are defined by the individual bindings for the...
155  = EXAMPLE
156  The following example represents the GLINK RPM node on a MSM8996 device, with
157  the function for the "rpm_request" channel defined, which is used for
158 -regualtors and root clocks.
159 +regulators and root clocks.
160  
161         apcs_glb: mailbox@9820000 {
162                 compatible = "qcom,msm8996-apcs-hmss-global";
163   \end{lstlisting}
164 \end{frame}
165
166 \begin{frame}[fragile]{\hdrs{The Hardware ID}}
167   \begin{lstlisting}[language=diff,basicstyle=\tiny]
168 commit 7ab21a8692094872298df172f54d55cba72fd308
169 Author: Andy Spencer <spenceal@rose-hulman.edu>
170 Date:   2009-01-02 16:19:13 +0000
171
172     i8k: Enable i8k on Dell Precision Systems
173     
174     Patch to enable i8k on Dell Precisions.
175     
176     Signed-off-by: Andy Spencer <spenceal@rose-hulman.edu>
177     Signed-off-by: Alan Cox <alan@redhat.com>
178     Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
179
180 diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
181 index b60d425ce8d1..099fc89a5bdd 100644
182 --- a/drivers/char/i8k.c
183 +++ b/drivers/char/i8k.c
184 @@ -485,6 +485,13 @@ static struct dmi_system_id __initdata i8k_dmi_table[] = {
185                         DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
186                 },
187         },
188 +       {
189 +               .ident = "Dell Precision",
190 +               .matches = {
191 +                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
192 +                       DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
193 +               },
194 +       },
195         { }
196  };
197   \end{lstlisting}
198 \end{frame}
199
200 \begin{frame}[fragile]{\hdrs{The Driver Debug}}
201   \begin{lstlisting}[language=diff,basicstyle=\tiny]
202 commit ab1796ebdad3017965754d86db64d3cba5c416b9
203 Author: Andy Spencer <andy753421@ucla.edu>
204 Date:   2014-05-02 06:48:13 +0000
205
206     RTL8192CU: Increase max APFM_ONMAC polling count
207     
208     With certain hardware combinations the poll interval is exceeded before
209     initialization completes.
210     
211     Tested on a MacBookPro10,1 using a Sabrent USB-A11N USB adapter.
212     
213     Signed-off-by: Andy Spencer <andy753421@ucla.edu>
214     Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
215     Signed-off-by: John W. Linville <linville@tuxdriver.com>
216
217 diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/rtlw...
218 index 68b5c7e92cfb..31b79e78c63c 100644
219 --- a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
220 +++ b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
221 @@ -511,7 +511,7 @@ static int _rtl92cu_init_power_on(struct ieee80211_hw *hw)
222                         pr_info("MAC auto ON okay!\n");
223                         break;
224                 }
225 -               if (pollingCount++ > 100) {
226 +               if (pollingCount++ > 1000) {
227                         RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
228                                  "Failed to polling REG_APS_FSMCO[APFM_ONMAC] done!\n");
229                         return -ENODEV;
230   \end{lstlisting}
231 \end{frame}
232
233 \begin{frame}[fragile]{\hdrs{The New Protocol}}
234   \begin{itemize}
235     \item New network protocols, filesystems, security modules, etc.
236     \item Software only improvmenets to the kernel.
237     \item No hardware required, can be tested in a VM.
238     \item Typocally done in net/, fs/, security/, etc.
239   \end{itemize}
240 \end{frame}
241
242 \begin{frame}[fragile]{\hdrs{The New Driver}}
243   \begin{itemize}
244     \item Add support for a new hardware device. 
245     \item Cononical example: I2C/SPI thermal sensors. (lm70.c)
246     \item Find the data sheet
247     \item Typocally use an existing driver as an example.
248     \item Requires hardware to test on.
249     \item Typocally done in drivers/.
250   \end{itemize}
251 \end{frame}
252
253 \begin{frame}[fragile]{\hdrs{The New Board}}
254   \begin{itemize}
255     \item Simmilar new drivers but focuse on boot.
256     \item Typocally for embedded Linux.
257     \item May require bootloader changes.
258     \item Typocally done in arch/.
259   \end{itemize}
260 \end{frame}
261
262 % Development
263 % - Kernel compiling
264 % - Booting the kernel
265 % - Kernel source tree
266 % - Sending patches
267
268 \section{Development}
269
270 \begin{frame}{\hdrs{Kernel compiling}}
271   Could be an entire talk on it's own...
272
273   \begin{itemize}
274     \item \$ make menuconfig
275     \item \$ make -j32
276     \item \$ make install
277       \begin{itemize}
278         \item invokes \$HOME/bin/installkernel
279       \end{itemize}
280     \item \$ make modules\_install
281   \end{itemize}
282
283   Output files:
284   \begin{itemize}
285     \item vmlinux: Main build output, ELF file with debug symbols.
286     \item bzImage: Bootable kernel image (wraps vmlinux).
287     \item uImage, etc: Like bzImage for other architctures.
288   \end{itemize}
289
290 \end{frame}
291
292 \begin{frame}{\hdrs{Booting the kernel}}
293   How to test?
294
295   \begin{enumerate}
296     \item Compile, reboot, compile, reboot..
297       \begin{itemize}
298         \item Least efficient, but often needed for debugging.
299       \end{itemize}
300     \item Run the kenrel it in a VM.
301       \begin{itemize}
302         \item Great for experimenting.
303         \item Won't work for for driver.
304       \end{itemize}
305     \item Dynamic kernel module loading.
306       \begin{itemize}
307         \item Good for most driver work.
308         \item Easy to crash your PC.
309       \end{itemize}
310     \item Boot it on a dedicated machine.
311       \begin{itemize}
312         \item Generally used for embedded Linux.
313         \item Prevents crashing your workstation.
314       \end{itemize}
315   \end{enumerate}
316 \end{frame}
317
318 \begin{frame}{\hdrs{Kernel source tree}}
319   \begin{itemize}
320     \item arch/: architecture specific code
321     \item drivers/: well... drivers
322     \item fs/: file systems
323     \item kernel/: core kernel code (process management, etc)
324     \item lib/: utility code, C library type stuff
325     \item mm/: memroy management
326     \item include/: shared include files 
327   \end{itemize}
328 \end{frame}
329
330 \begin{frame}{\hdrs{Sending patches}}
331   \url{https://www.kernel.org/doc/html/latest/process/submitting-patches.html}
332   \begin{itemize}
333     \item Linux uses mailing lists patches and code review.
334     \item Maintainers tend to use pull requests and merges, but general
335       contributors usually do not.
336     \item Different subsystem (netdev) have slightly different rules.
337     \item Patchwork is useful for tracking and reviewing patches:
338       \url{https://patchwork.kernel.org}
339   \end{itemize}
340 \end{frame}
341
342 % Kernel modules
343 % - Hello, World
344 % - User Interfaces
345 %   - printk / dmesg
346 %   - /dev, proc, sysfs
347 %   - syscalls, ioctls
348 % - Devices and Drivers
349
350 \section{Kernel Modules}
351
352 \begin{frame}[fragile]{\hdrs{Hello, World}}
353   \begin{lstlisting}[language=C,basicstyle=\scriptsize]
354 #include <linux/module.h>
355 #include <linux/kernel.h>
356 #include <linux/init.h>
357
358 static int __init hello_init(void)
359 {
360         pr_info("Hello SFVLUG.\n");
361         return 0;
362 }
363
364 static void __exit hello_exit(void)
365 {
366         pr_info("Goodbye SFVLUG.\n");
367 }
368
369 module_init(hello_init);
370 module_exit(hello_exit);
371
372 MODULE_LICENSE("GPL");
373 MODULE_AUTHOR("Andy Spencer <andy753421@gmail.com>");
374 MODULE_DESCRIPTION("SFVLUG!");
375   \end{lstlisting}
376 \end{frame}
377
378 %\begin{frame}[fragile]{\hdrs{Makefile / Kconfig}}
379 %  \begin{lstlisting}[Building it]
380 %  \end{lstlisting}
381 %\end{frame}
382 %
383 %\begin{frame}{\hdrs{User Interfaces}}
384 %- printk / dmesg
385 %- /dev, proc, sysfs
386 %- syscalls, ioctls
387 %\end{frame}
388 %
389 %\begin{frame}{\hdrs{Devices and Drivers}}
390 %\end{frame}
391
392 \end{document}