[bootlin/training-materials updates] master: Boot time: kernel compiling and system boot (b7f84379)

Michael Opdenacker michael.opdenacker at bootlin.com
Thu May 16 18:10:12 CEST 2019


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/b7f84379757b9949b83374ee480aec251060cd68

>---------------------------------------------------------------

commit b7f84379757b9949b83374ee480aec251060cd68
Author: Michael Opdenacker <michael.opdenacker at bootlin.com>
Date:   Thu May 16 18:10:12 2019 +0200

    Boot time: kernel compiling and system boot
    
    Signed-off-by: Michael Opdenacker <michael.opdenacker at bootlin.com>


>---------------------------------------------------------------

b7f84379757b9949b83374ee480aec251060cd68
 .../kernel/data/am335x-boneblack-lcd4.dts          | 238 +++++++++++++++++++++
 .../boot-time-build-bootloader.tex                 |  12 +-
 .../boot-time-build-kernel-and-start-system.tex    | 193 +++++++++++++++++
 mk/boot-time.mk                                    |   1 +
 4 files changed, 443 insertions(+), 1 deletion(-)

diff --git a/lab-data/boot-time/kernel/data/am335x-boneblack-lcd4.dts b/lab-data/boot-time/kernel/data/am335x-boneblack-lcd4.dts
new file mode 100644
index 00000000..29d9a635
--- /dev/null
+++ b/lab-data/boot-time/kernel/data/am335x-boneblack-lcd4.dts
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Copyright (C) 2019 Bootlin SAS - https://bootlin.com
+ * Adapted from DT overlay sources for the LCD4 cape
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-bone-common.dtsi"
+#include "am335x-boneblack-common.dtsi"
+
+/ {
+	compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
+	serial-number = "4014BBBK0495";
+	model = "TI AM335x BeagleBone Black";
+
+			backlight {
+				compatible      = "pwm-backlight";
+				pinctrl-names   = "default";
+				pinctrl-0       = <&bb_lcd_pwm_backlight_pins>;
+
+				pwms = <&ehrpwm1 0 500000 0>;
+				pwm-names = "LCD4";
+				brightness-levels = <0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100>;
+				default-brightness-level = <100>; /* index to the array above */
+				status = "okay";
+			};
+
+			gpio-leds-cape-lcd4 {
+				compatible = "gpio-leds";
+				pinctrl-names = "default";
+
+				pinctrl-0 = <&bb_lcd_led_pins>;
+
+				lcd4-led0 {
+					label = "lcd4:green:usr0";
+					gpios = <&gpio2 28 0>;
+					linux,default-trigger = "heartbeat";
+					default-state = "off";
+				};
+
+			};
+
+			/* Settings for NHD-4.3-ATXI#-T-1 / LCD4 cape: */
+			panel {
+				compatible = "ti,tilcdc,panel";
+				pinctrl-names = "default";
+				pinctrl-0 = <&bb_lcd_lcd_pins>;
+				status = "okay";
+				panel-info {
+					ac-bias           = <255>;
+					ac-bias-intrpt    = <0>;
+					dma-burst-sz      = <16>;
+					bpp               = <16>;
+					fdd               = <0x80>;
+					sync-edge         = <0>;
+					sync-ctrl         = <1>;
+					raster-order      = <0>;
+					fifo-th           = <0>;
+				};
+				display-timings {
+					native-mode = <&timing0>;
+					timing0: 480x272 {
+						clock-frequency = <9200000>;
+						hactive = <480>;
+						vactive = <272>;
+						hfront-porch = <8>;
+						hback-porch = <47>;
+						hsync-len = <41>;
+						vback-porch = <2>;
+						vfront-porch = <3>;
+						vsync-len = <10>;
+						hsync-active = <0>;
+						vsync-active = <0>;
+						de-active = <1>;
+						pixelclk-active = <0>;
+					};
+				};
+			};
+
+			tscadc {
+				compatible = "ti,ti-tscadc";
+				reg = <0x44e0d000 0x1000>;
+
+				interrupt-parent = <&intc>;
+				interrupts = <16>;
+				ti,hwmods = "adc_tsc";
+				status = "okay";
+
+				tsc {
+					ti,wires = <4>;
+					ti,x-plate-resistance = <200>;
+					ti,coordinate-readouts = <5>;
+					ti,wire-config = <0x00 0x11 0x22 0x33>;
+				};
+
+				adc {
+					ti,adc-channels = <4 5 6 7>;
+				};
+			};
+
+			gpio_keys {
+				compatible = "gpio-keys";
+				pinctrl-names = "default";
+				pinctrl-0 = <&bb_lcd_keymap_pins>;
+
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				button at 1 {
+					debounce_interval = <50>;
+					linux,code = <105>;
+					label = "left";
+					gpios = <&gpio2 16 0x1>;
+					gpio-key,wakeup;
+					autorepeat;
+				};
+				button at 2 {
+					debounce_interval = <50>;
+					linux,code = <106>;
+					label = "right";
+					gpios = <&gpio2 17 0x1>;
+					gpio-key,wakeup;
+					autorepeat;
+				};
+				button at 3 {
+					debounce_interval = <50>;
+					linux,code = <103>;
+					label = "up";
+					gpios = <&gpio2 19 0x1>;
+					gpio-key,wakeup;
+					autorepeat;
+				};
+				/*
+				button at 4 {
+					debounce_interval = <50>;
+					linux,code = <108>;
+					label = "down";
+					gpios = <&gpio4 16 0x1>;
+					gpio-key,wakeup;
+					autorepeat;
+				};
+				*/
+				button at 5 {
+					debounce_interval = <50>;
+					linux,code = <28>;
+					label = "enter";
+					gpios = <&gpio1 15 0x1>;
+					gpio-key,wakeup;
+				};
+			};
+
+};
+
+&cpu0_opp_table {
+	/*
+	 * All PG 2.0 silicon may not support 1GHz but some of the early
+	 * BeagleBone Blacks have PG 2.0 silicon which is guaranteed
+	 * to support 1GHz OPP so enable it for PG 2.0 on this board.
+	 */
+	oppnitro-1000000000 {
+		opp-supported-hw = <0x06 0x0100>;
+	};
+};
+
+&am33xx_pinmux {
+			bb_lcd_led_pins: pinmux_bb_lcd_led_pins {
+				pinctrl-single,pins = <
+					0x078 (PIN_INPUT | MUX_MODE7)	/* P9_12: gpmc_ben1.gpio1_28, INPUT | PULLDIS | MODE7 */
+				>;
+			};
+
+			bb_lcd_pwm_backlight_pins: pinmux_bb_lcd_pwm_backlight_pins {
+				pinctrl-single,pins = <
+					0x048 (PIN_OUTPUT_PULLDOWN | MUX_MODE6)	/* P9_14: gpmc_a2.ehrpwm1a */
+				>;
+			};
+
+			bb_lcd_lcd_pins: pinmux_bb_lcd_lcd_pins {
+				pinctrl-single,pins = <
+					0x1A4 (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* P9_27: mcasp0_fsr.gpio3_19 */
+					0x0A0 (PIN_OUTPUT | MUX_MODE0)		/* P8_45: lcd_data0.lcd_data0 */
+					0x0A4 (PIN_OUTPUT | MUX_MODE0)	/* P8_46: lcd_data1.lcd_data1 */
+					0x0A8 (PIN_OUTPUT | MUX_MODE0)	/* P8_43: lcd_data2.lcd_data2 */
+					0x0AC (PIN_OUTPUT | MUX_MODE0)	/* P8_44: lcd_data3.lcd_data3 */
+					0x0B0 (PIN_OUTPUT | MUX_MODE0)	/* P8_41: lcd_data4.lcd_data4 */
+					0x0B4 (PIN_OUTPUT | MUX_MODE0)	/* P8_42: lcd_data5.lcd_data5 */
+					0x0B8 (PIN_OUTPUT | MUX_MODE0)	/* P8_39: lcd_data6.lcd_data6 */
+					0x0BC (PIN_OUTPUT | MUX_MODE0)	/* P8_40: lcd_data7.lcd_data7 */
+					0x0C0 (PIN_OUTPUT | MUX_MODE0)	/* P8_37: lcd_data8.lcd_data8 */
+					0x0C4 (PIN_OUTPUT | MUX_MODE0)	/* P8_38: lcd_data9.lcd_data9 */
+					0x0C8 (PIN_OUTPUT | MUX_MODE0)	/* P8_36: lcd_data10.lcd_data10 */
+					0x0CC (PIN_OUTPUT | MUX_MODE0)	/* P8_34: lcd_data11.lcd_data11 */
+					0x0D0 (PIN_OUTPUT | MUX_MODE0)	/* P8_35: lcd_data12.lcd_data12 */
+					0x0D4 (PIN_OUTPUT | MUX_MODE0)	/* P8_33: lcd_data13.lcd_data13 */
+					0x0D8 (PIN_OUTPUT | MUX_MODE0)	/* P8_31: lcd_data14.lcd_data14 */
+					0x0DC (PIN_OUTPUT | MUX_MODE0)	/* P8_32: lcd_data15.lcd_data15 */
+					0x0E0 (PIN_OUTPUT | MUX_MODE0)	/* P8_27: lcd_vsync.lcd_vsync */
+					0x0E4 (PIN_OUTPUT | MUX_MODE0)	/* P8_29: lcd_hsync.lcd_hsync */
+					0x0E8 (PIN_OUTPUT | MUX_MODE0)	/* P8_28: lcd_pclk.lcd_pclk */
+					0x0EC (PIN_OUTPUT | MUX_MODE0)	/* P8_30: lcd_ac_bias_en.lcd_ac_bias_en */
+
+					// Bootlin: use idle pin as custom GPIO
+					0x074 (PIN_OUTPUT | MUX_MODE7)	/* P9_13: uart4_txd_txd.gpio0_31 */
+				>;
+			};
+
+			bb_lcd_keymap_pins: pinmux_bb_lcd_keymap_pins {
+				pinctrl-single,pins = <
+					0x040 (PIN_INPUT | MUX_MODE7)	/* P9_15: gpmc_a0.gpio1_16 */
+					0x044 (PIN_INPUT | MUX_MODE7)	/* P9_23: gpmc_a1.gpio1_17 */
+					0x04C (PIN_INPUT | MUX_MODE7)	/* P9_16: gpmc_a3.gpio1_19 */
+					0x198 (PIN_INPUT | MUX_MODE7)	/* P9_30: mcasp0_axr0.gpio3_16 */
+					0x184 (PIN_INPUT | MUX_MODE7)	/* P9_24: uart1_txd.gpio0_15 */
+				>;
+			};
+
+};
+
+&epwmss1 {
+			status = "okay";
+};
+
+&ehrpwm1 {
+			status = "okay";
+			/* Don't add pin settings here, this breaks the backlight */
+			//pinctrl-0 = <&bb_lcd_pwm_backlight_pins>;
+			//pinctrl-names = "default";
+};
+
+&lcdc {
+			status = "okay";
+};
diff --git a/labs/boot-time-build-bootloader/boot-time-build-bootloader.tex b/labs/boot-time-build-bootloader/boot-time-build-bootloader.tex
index f2ed7b89..7d1f49e1 100644
--- a/labs/boot-time-build-bootloader/boot-time-build-bootloader.tex
+++ b/labs/boot-time-build-bootloader/boot-time-build-bootloader.tex
@@ -6,7 +6,7 @@ platform and run it from a micro SD card provided by your instructor.
 
 \section{Setup}
 
-Go to the /code{~/boot-time-labs/bootloader/u-boot/} directory.
+Go to the \code{~/boot-time-labs/bootloader/u-boot/} directory.
 
 Let's use the 2019.04 version:
 \begin{verbatim}
@@ -30,6 +30,16 @@ sudo apt install gcc-arm-linux-gnueabihf
 export CROSS_COMPILE=arm-linux-gnueabihf-
 \end{verbatim}
 
+You will need the same settings when you compile the kernel too, and
+when you recompiling U-Boot and the kernel to optimize them. Let's make
+such settings permanent by adding the below lines at the end of your
+\code{~/.bashrc} file:
+
+\begin{verbatim}
+export PATH=/home/<user>/boot-time-labs/rootfs/buildroot/output/host/bin:$PATH
+export CROSS_COMPILE=arm-buildroot-linux-uclibcgnueabihf-
+\end{verbatim}
+
 \section{Configuring U-Boot}
 
 Let's use the ready-made U-Boot configuration for the Beaglebone Black
diff --git a/labs/boot-time-build-kernel-and-start-system/boot-time-build-kernel-and-start-system.tex b/labs/boot-time-build-kernel-and-start-system/boot-time-build-kernel-and-start-system.tex
new file mode 100644
index 00000000..635f8264
--- /dev/null
+++ b/labs/boot-time-build-kernel-and-start-system/boot-time-build-kernel-and-start-system.tex
@@ -0,0 +1,193 @@
+\subchapter{Build the kernel and boot the system}{Objective: configure, compile and install the
+kernel, install the root file system and see the full system in action!}
+
+At the end of the lab, you'll have your system completely up and
+running.
+
+\section{Setup}
+
+Go to the \code{~/boot-time-labs/kernel/linux/} directory.
+
+First, let's get the list of branches on our \code{stable} remote tree:
+
+\begin{verbatim}
+git branch -a
+\end{verbatim}
+
+As we will do our labs with the Linux 5.1 stable branch, the remote branch
+we are interested in is \code{remotes/stable/linux-5.1.y}.
+
+First, open the \code{Makefile} file just to check the Linux kernel
+version that you currently have.
+
+Now, let's create a local branch starting from that remote branch:
+\begin{verbatim}
+git checkout -b 5.1-beaglecam stable/linux-5.1.y
+\end{verbatim}
+
+This local branch will allow us to keep our modifications to the Linux
+kernel to support the LCD4 cape that we're using.
+
+Open \code{Makefile} again and make sure you now have a 5.1.y version.
+
+\section{Compiling environment}
+
+You need the same \code{PATH} and \code{CROSS_COMPILE} environment
+variables as when you compiled U-Boot, plus the \code{ARCH} one that
+corresponds to the target archicture.
+
+So, add the below line at the end of your \code{~/.bashrc} file:
+
+\begin{verbatim}
+export ARCH=arm
+\end{verbatim}
+
+Now source this file (\code{source ~/.bashrc})  in the current terminal,
+or start a new terminal to get all needed variables.
+
+\section{Adding support for the LCD4 cape}
+
+To support using the LCD4 cape, all we need to do is declare and
+configure the devices on this cape. This is typically done by
+customizing the board's {\em Device Tree} or by adding a {\em Device
+Tree Overlay}.
+
+So, to avoid messing with the standard DTS for our board, let's use a
+such a customized device tree through a separate file:
+
+\begin{verbatim}
+cp ~/boot-time-labs/kernel/data/am335x-boneblack-lcd4.dts arch/arm/boot/dts/
+\end{verbatim}
+
+You also have to modify \code{arch/arm/boot/dts/Makefile} so that
+the new DTS file gets compiled too.
+
+\section{Configuring the Linux kernel}
+
+First, lets pick the default kernel configuration for boards with a TI
+OMAP or AMxxxx SoC:
+
+\begin{verbatim}
+make help | grep omap
+\end{verbatim}
+
+What we need is the configuration for OMAP2 and later SoCs:
+\begin{verbatim}
+make omap2plus_defconfig
+\end{verbatim}
+
+Let's run \code{make menuconfig} or \code{make xconfig} and select the
+below options. Use the search capability of such configuration
+interfaces to find the corresponding parameters (remove \code{CONFIG_}
+when you search.
+
+To enable support for the framebuffer and the PWM backlight:
+\begin{itemize}
+\item \code{CONFIG_PWM_TIEHRPWM=y}
+\item \code{CONFIG_FB_SIMPLE=y}
+\item \code{CONFIG_BACKLIGHT_PWM=y}
+\item \code{CONFIG_DRM=y}
+\item \code{CONFIG_DRM_TILCDC=y}
+\item \code{CONFIG_DRM_TI_TFP410=y}
+\end{itemize}
+
+For USB support:
+\begin{itemize}
+\item \code{CONFIG_USB=y} 
+\item \code{CONFIG_USB_MUSB_HDRC=y}
+\item \code{CONFIG_USB_MUSB_DSPS=y}
+\item \code{CONFIG_MUSB_PIO_ONLY=y}
+\item \code{CONFIG_USB_GADGET=y}
+\item \code{CONFIG_NOP_USB_XCEIV=y}
+\item \code{CONFIG_AM335X_PHY_USB=y}
+\item \code{CONFIG_USB_GPIO_VBUS=y}
+\item \code{CONFIG_USB_GADGET_VBUS_DRAW=500}
+\item \code{CONFIG_USB_CONFIGFS_F_UVC=y}
+\end{itemize}
+
+For the webcam
+\begin{itemize}
+\item \code{CONFIG_MEDIA_SUPPORT=y} 
+\item \code{CONFIG_MEDIA_USB_SUPPORT=y}
+\item \code{CONFIG_USB_VIDEO_CLASS=y}
+\end{itemize}
+
+\section{Compiling the kernel}
+
+To compile the device tree, just run:
+\begin{verbatim}
+make dtbs
+\end{verbatim}
+
+To compile the kernel, just run:
+\begin{verbatim}
+make -j 8 zImage
+\end{verbatim}
+
+Note that the default \code{make} target would have worked too, but with
+just \code{zImage}, we avoid compiling many modules that are configured
+in the default configuration. This saves quite a lot of time!
+
+At the end, copy the kernel binary and DTB to the SD card's boot
+partition:
+
+\begin{verbatim}
+cp arch/arm/boot/zImage /media/<user>/boot/
+cp arch/arm/boot/dts/am335x-boneblack-lcd4.dtb /media/<user>/boot/dtb
+\end{verbatim}
+
+\section{Installing the root filesystem}
+
+We are also ready to install the root filesystem. Still with the SD card
+connected to your workstation:
+
+\begin{verbatim}
+cd ~/boot-time-labs/rootfs
+mkdir rootfs
+cd rootfs
+tar xf ../buildroot/output/images/rootfs.tar
+sudo rsync -aH --delete ./ /media/<user>/rootfs/
+sudo umount /media/<user>/rootfs
+sudo umount /media/<user>/boot
+\end{verbatim}
+
+Then insert the SD card in the board's slot.
+
+\section{Bootloader configuration}
+
+Back to the serial console for your board, let's define the default boot
+sequence, to load the kernel and DTB from the external SD card:
+
+\begin{verbatim}
+setenv bootcmd 'fatload mmc 0:1 81000000 zImage; fatload mmc 0:1 82000000 dtb; bootz 81000000 - 82000000'
+\end{verbatim}
+
+The last thing to do is to define the kernel command line:
+\begin{verbatim}
+setenv bootcmd 'fatload mmc 0:1 81000000 zImage; fatload mmc 0:1 82000000 dtb; bootz 81000000 - 82000000'
+setenv bootargs console=ttyO0,115200n8 root=/dev/mmcblk0p2 rootwait ro
+\end{verbatim}
+
+\begin{itemize}
+\item \code{rootwait} waits for the root device to be ready before
+attempting to mount it. You may have a kernel panic otherwise.
+\item \code{ro} mounts the root filesystem read-only, which is probably
+a good thing to do, as we shouldn't have manual changes to make, and as
+we are going to reset the board countless times. This should avoid
+having to (automatically) repair the filesystem at boot time and
+potentially disturb boot time.
+\end{itemize}
+
+Last but not least, save your changes:
+\begin{verbatim}
+saveenv
+\end{verbatim}
+
+\section{Testing time!}
+
+First, connect the USB webcam provided by your instructor, and point it
+to an interesting direction ;)
+
+Then, reset your board or power it on, and see it work as expected. If
+you don't get what you expected, check your serial console for errors,
+and if you're stuck, show your system to your instructor.
diff --git a/mk/boot-time.mk b/mk/boot-time.mk
index ae7275b8..d42f8551 100644
--- a/mk/boot-time.mk
+++ b/mk/boot-time.mk
@@ -26,6 +26,7 @@ BOOT_TIME_LABS = boot-time-goals \
 		boot-time-board-setup \
 		boot-time-build-system \
 		boot-time-build-bootloader \
+		boot-time-build-kernel-and-start-system \
 		boottime-init-scripts \
 		boottime-application \
 		boottime-kernel \




More information about the training-materials-updates mailing list