From: Andy Spencer Date: Sun, 5 Jan 2020 06:57:27 +0000 (+0000) Subject: Add kernel talk. X-Git-Url: http://pileus.org/git/?p=~andy%2Fsfvlug;a=commitdiff_plain;h=1d75287a9e79ab734e549ec8486fda2fecb4d5aa Add kernel talk. --- diff --git a/kernel/.gitignore b/kernel/.gitignore new file mode 100644 index 0000000..a52cbb0 --- /dev/null +++ b/kernel/.gitignore @@ -0,0 +1 @@ +old/ diff --git a/kernel/kernel.pdf b/kernel/kernel.pdf new file mode 100644 index 0000000..1ab89c0 Binary files /dev/null and b/kernel/kernel.pdf differ diff --git a/kernel/kernel.tex b/kernel/kernel.tex new file mode 100644 index 0000000..8720dc4 --- /dev/null +++ b/kernel/kernel.tex @@ -0,0 +1,392 @@ +\documentclass{beamer} + +%%%%%%%%%%%%%%%%%%% +% Commands/macros % +%%%%%%%%%%%%%%%%%%% +\newcommand{\link}[1]{ + \begin{flushright} + \scriptsize{#1} + \end{flushright} +} + +\newcommand{\hdrs}[1]{\large{\textit{\insertsection}}\\\Large{\textbf{#1}}} +\newcommand{\hdrss}[1]{\large{\textit{\insertsubsection}}\\\large{\textbf{#1}}} + +%%%%%%%%%%%%%%%% +% Header/theme % +%%%%%%%%%%%%%%%% +%\usetheme[ +% pageofpages=of, +% alternativetitlepage=true, +%]{Torino} +%\setbeamertemplate{footline}{} +\setbeamersize{text margin left=10mm} +\setbeamersize{text margin right=5mm} + +% Import packages +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage{times} +\usepackage[T1]{fontenc} +\usepackage{graphics} +\usepackage{hyperref} +\usepackage{ulem} +\usepackage{color} +\usepackage{listings} +\usepackage{xcolor} + +% Diff syntax +\definecolor{diffcommit}{rgb}{.50, .50, .00} +\definecolor{diffauthor}{rgb}{.50, .50, .00} +\definecolor{diffdate} {rgb}{.50, .50, .00} +\definecolor{diffdiff} {rgb}{.30, .30, .90} +\definecolor{diffindex} {rgb}{.50, .00, .50} +\definecolor{diffstart} {rgb}{.00, .50, .50} +\definecolor{diffadd} {rgb}{.00, .60, .00} +\definecolor{diffdel} {rgb}{.80, .00, .00} + +\lstdefinelanguage{diff}{ + basicstyle=\ttfamily\small, + morecomment=[f][\color{diffcommit}]{commit}, + morecomment=[f][\color{diffauthor}]{Author}, + morecomment=[f][\color{diffdate}]{Date}, + morecomment=[f][\color{diffdiff}]{diff}, + morecomment=[f][\color{diffindex}]{index}, + morecomment=[f][\color{diffstart}]{@@}, + morecomment=[f][\color{diffadd}]{+}, + morecomment=[f][\color{diffdel}]{-}, + morecomment=[f][\color{diffindex}]{+++}, + morecomment=[f][\color{diffindex}]{---}, +} + +\lstset{language=diff, + basicstyle=\ttfamily, + keywordstyle=\color{blue}\ttfamily, + stringstyle=\color{red}\ttfamily, + commentstyle=\color{green}\ttfamily, + morecomment=[l][\color{magenta}]{\#} } + +%%%%%%%%%%%%%%%%%%%% +% Title page setup % +%%%%%%%%%%%%%%%%%%%% +\subject{% + kernel, + programming +} + +\keywords{% + linux, + kernel +} + +\title[Kernel Programming]{% + Introduction to Linux Kernel Programming +} + +\author[Spencer]{% + Andy Spencer +} + +\date[2020-01-04]{% + Jan. 4, 2020 \\ + \small{San Fernando Valley Linux Users Group} +} + +%%%%%%%%%%%%%%%%% +% Content pages % +%%%%%%%%%%%%%%%%% +% Structure: +% - Examples +% - The typo fix +% - The hardware id +% - The driver debug +% - The new driver +% - The new protocol +% - The new board +% - Development +% - Kernel compiling +% - Booting the kernel +% - Kernel source tree +% - Sending patches +% - Kernel modules +% - Hello, World +% - User Interfaces +% - printk / dmesg +% - /dev, proc, sysfs +% - syscalls, ioctls +% - Devices and Drivers +\begin{document} + +%%%%%%%%%%%%%%%% +% Introduction % +%%%%%%%%%%%%%%%% +\begin{frame}[plain] + \titlepage +\end{frame} + +% Examples +% - The typo fix +% - The hardware id +% - The driver debug +% - The new driver +% - The new protocol +% - The new board + +\section{Examples Patches} + +\begin{frame}[fragile]{\hdrs{The Typo Fix}} + \begin{lstlisting}[language=diff,basicstyle=\tiny] +commit 9eac0ae1683575375de8c63166b3596b11d3b56a +Author: Krzysztof Kozlowski +Date: 2019-01-08 13:11:40 +0100 + + dt-bindings: soc: qcom: Fix trivial language typos + + Fix few trivial language typos in bindings. + + Signed-off-by: Krzysztof Kozlowski + Signed-off-by: Rob Herring + +diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt b/Docume... +index 0b8cc533ca83..cf759e5f9b10 100644 +--- a/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt ++++ b/Documentation/devicetree/bindings/soc/qcom/qcom,glink.txt +@@ -55,7 +55,7 @@ of these nodes are defined by the individual bindings for the... + = EXAMPLE + The following example represents the GLINK RPM node on a MSM8996 device, with + the function for the "rpm_request" channel defined, which is used for +-regualtors and root clocks. ++regulators and root clocks. + + apcs_glb: mailbox@9820000 { + compatible = "qcom,msm8996-apcs-hmss-global"; + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile]{\hdrs{The Hardware ID}} + \begin{lstlisting}[language=diff,basicstyle=\tiny] +commit 7ab21a8692094872298df172f54d55cba72fd308 +Author: Andy Spencer +Date: 2009-01-02 16:19:13 +0000 + + i8k: Enable i8k on Dell Precision Systems + + Patch to enable i8k on Dell Precisions. + + Signed-off-by: Andy Spencer + Signed-off-by: Alan Cox + Signed-off-by: Linus Torvalds + +diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c +index b60d425ce8d1..099fc89a5bdd 100644 +--- a/drivers/char/i8k.c ++++ b/drivers/char/i8k.c +@@ -485,6 +485,13 @@ static struct dmi_system_id __initdata i8k_dmi_table[] = { + DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), + }, + }, ++ { ++ .ident = "Dell Precision", ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), ++ DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), ++ }, ++ }, + { } + }; + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile]{\hdrs{The Driver Debug}} + \begin{lstlisting}[language=diff,basicstyle=\tiny] +commit ab1796ebdad3017965754d86db64d3cba5c416b9 +Author: Andy Spencer +Date: 2014-05-02 06:48:13 +0000 + + RTL8192CU: Increase max APFM_ONMAC polling count + + With certain hardware combinations the poll interval is exceeded before + initialization completes. + + Tested on a MacBookPro10,1 using a Sabrent USB-A11N USB adapter. + + Signed-off-by: Andy Spencer + Acked-by: Larry Finger + Signed-off-by: John W. Linville + +diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/rtlw... +index 68b5c7e92cfb..31b79e78c63c 100644 +--- a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c ++++ b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c +@@ -511,7 +511,7 @@ static int _rtl92cu_init_power_on(struct ieee80211_hw *hw) + pr_info("MAC auto ON okay!\n"); + break; + } +- if (pollingCount++ > 100) { ++ if (pollingCount++ > 1000) { + RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, + "Failed to polling REG_APS_FSMCO[APFM_ONMAC] done!\n"); + return -ENODEV; + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile]{\hdrs{The New Protocol}} + \begin{itemize} + \item New network protocols, filesystems, security modules, etc. + \item Software only improvmenets to the kernel. + \item No hardware required, can be tested in a VM. + \item Typocally done in net/, fs/, security/, etc. + \end{itemize} +\end{frame} + +\begin{frame}[fragile]{\hdrs{The New Driver}} + \begin{itemize} + \item Add support for a new hardware device. + \item Cononical example: I2C/SPI thermal sensors. (lm70.c) + \item Find the data sheet + \item Typocally use an existing driver as an example. + \item Requires hardware to test on. + \item Typocally done in drivers/. + \end{itemize} +\end{frame} + +\begin{frame}[fragile]{\hdrs{The New Board}} + \begin{itemize} + \item Simmilar new drivers but focuse on boot. + \item Typocally for embedded Linux. + \item May require bootloader changes. + \item Typocally done in arch/. + \end{itemize} +\end{frame} + +% Development +% - Kernel compiling +% - Booting the kernel +% - Kernel source tree +% - Sending patches + +\section{Development} + +\begin{frame}{\hdrs{Kernel compiling}} + Could be an entire talk on it's own... + + \begin{itemize} + \item \$ make menuconfig + \item \$ make -j32 + \item \$ make install + \begin{itemize} + \item invokes \$HOME/bin/installkernel + \end{itemize} + \item \$ make modules\_install + \end{itemize} + + Output files: + \begin{itemize} + \item vmlinux: Main build output, ELF file with debug symbols. + \item bzImage: Bootable kernel image (wraps vmlinux). + \item uImage, etc: Like bzImage for other architctures. + \end{itemize} + +\end{frame} + +\begin{frame}{\hdrs{Booting the kernel}} + How to test? + + \begin{enumerate} + \item Compile, reboot, compile, reboot.. + \begin{itemize} + \item Least efficient, but often needed for debugging. + \end{itemize} + \item Run the kenrel it in a VM. + \begin{itemize} + \item Great for experimenting. + \item Won't work for for driver. + \end{itemize} + \item Dynamic kernel module loading. + \begin{itemize} + \item Good for most driver work. + \item Easy to crash your PC. + \end{itemize} + \item Boot it on a dedicated machine. + \begin{itemize} + \item Generally used for embedded Linux. + \item Prevents crashing your workstation. + \end{itemize} + \end{enumerate} +\end{frame} + +\begin{frame}{\hdrs{Kernel source tree}} + \begin{itemize} + \item arch/: architecture specific code + \item drivers/: well... drivers + \item fs/: file systems + \item kernel/: core kernel code (process management, etc) + \item lib/: utility code, C library type stuff + \item mm/: memroy management + \item include/: shared include files + \end{itemize} +\end{frame} + +\begin{frame}{\hdrs{Sending patches}} + \url{https://www.kernel.org/doc/html/latest/process/submitting-patches.html} + \begin{itemize} + \item Linux uses mailing lists patches and code review. + \item Maintainers tend to use pull requests and merges, but general + contributors usually do not. + \item Different subsystem (netdev) have slightly different rules. + \item Patchwork is useful for tracking and reviewing patches: + \url{https://patchwork.kernel.org} + \end{itemize} +\end{frame} + +% Kernel modules +% - Hello, World +% - User Interfaces +% - printk / dmesg +% - /dev, proc, sysfs +% - syscalls, ioctls +% - Devices and Drivers + +\section{Kernel Modules} + +\begin{frame}[fragile]{\hdrs{Hello, World}} + \begin{lstlisting}[language=C,basicstyle=\scriptsize] +#include +#include +#include + +static int __init hello_init(void) +{ + pr_info("Hello SFVLUG.\n"); + return 0; +} + +static void __exit hello_exit(void) +{ + pr_info("Goodbye SFVLUG.\n"); +} + +module_init(hello_init); +module_exit(hello_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Andy Spencer "); +MODULE_DESCRIPTION("SFVLUG!"); + \end{lstlisting} +\end{frame} + +%\begin{frame}[fragile]{\hdrs{Makefile / Kconfig}} +% \begin{lstlisting}[Building it] +% \end{lstlisting} +%\end{frame} +% +%\begin{frame}{\hdrs{User Interfaces}} +%- printk / dmesg +%- /dev, proc, sysfs +%- syscalls, ioctls +%\end{frame} +% +%\begin{frame}{\hdrs{Devices and Drivers}} +%\end{frame} + +\end{document}