lecture 2. modifying linux kernel - skku eslab |...

23
23 1 Embedded Software Lab. Sungkyunkwan University Embedded Software Lab. Dongkun Shin 전공핵심실습1:운영체제론 Lecture 2. Modifying Linux Kernel

Upload: vuque

Post on 10-Mar-2018

220 views

Category:

Documents


2 download

TRANSCRIPT

23

1

Embedded Software Lab.

Sungkyunkwan University

Embedded Software Lab.

Dongkun Shin

전공핵심실습1:운영체제론 Lecture 2. Modifying Linux Kernel

23

2

Embedded Software Lab.

Sungkyunkwan University

Embedded Software Lab.

Dongkun Shin

Ubuntu (Linux) Installation

23

3

Embedded Software Lab.

• Visit the VirtualBox official web site (https://www.virtualbox.org/)

VirtualBox Download (1)

Click to move to download page

23

4

Embedded Software Lab.

• Download virtualBox 5.0.16 for Windows hosts

VirtualBox Download (2)

23

5

Embedded Software Lab.

• Via web ( http://nyx.skku.ac.kr ) or USB memory

Virtual System Image Download

os_practice.ova

23

6

Embedded Software Lab.

• Import virtual system

Import Virtual System Image (1)

23

7

Embedded Software Lab.

• Adjust system configuration

Import Virtual System Image (2)

1

2 3

4

5

23

8

Embedded Software Lab.

Start Ubuntu

Password : 1q2w3e4r

23

9

Embedded Software Lab.

Sungkyunkwan University

Embedded Software Lab.

Dongkun Shin

Linux Kernel Build

23

10

Embedded Software Lab.

• Contents 1. build_z3.sh

2. Cross Compile for ARM architecture

3. Makefile Build System

4. Kernel Configuration

5. Fusing Kernel Image to Z3 Phone

6. Practice or Homework

Build the Kernel for Tizen Z3

23

11

Embedded Software Lab.

build_z3.sh

#!/bin/bash export CROSS_COMPILE=arm-linux-gnueabi- make ARCH=arm tizen_tm1_defconfig make ARCH=arm zImage –j2 make ARCH=arm dtbs ./dtbtool –o ./arch/arm/boot/merged-dtb –p scripts/dtc/ -v ./arch/arm/boot/dts/ ./mkdzimage –o ./arch/arm/boot/dzImage –k ./arch/arm/boot/zImage –d ./arch/arm/boot/merged-dtb tar –cvf ./tizen-recovery.tar ./arch/arm/boot/dzImage

• It is hard to build the kernel in first trying – Too complex source codes

– A lot of configuration of kernel is possible

• Linux kernel source code includes the build system – Makefile, menuconfig, xconfig

23

12

Embedded Software Lab.

• Compile for multiple platforms from one machine – In this lecture, we compile the linux kernel source code to ARM

architecture binary in Intel X86 environment.

Cross Compile

23

13

Embedded Software Lab.

• Makefiles are special format files that together with the make utility will help you to automatically build and manage your projects.

Makefile Build System

Just type $make

23

14

Embedded Software Lab.

• Linux Kernel prepares the codes for multiple environments. – No need to compile and build the whole source code

– Linux kernel supports configuration system

• Select the driver used in the target device

• Select the file system used in the target platform

• Select the assembly codes for the target architecture

• … etc.

– Kernel configuration is written to .config

– Tizen kernel prepares the pre-defined configuration files for multiple tizen devices at arch/ARCHITECTURE/*_defconfig

Kernel Configuration

23

15

Embedded Software Lab.

• $ls

– List directory contents

– option –a : show hidden file , -l : show the file information in detail

• $cd – Change directory

• $mkdir – Make new directory

– option –p : Make all parent directories as well as the target directory

• $pwd

– Print working directory

Default Unix Command (1)

23

16

Embedded Software Lab.

• $cat – Read files sequentially, and write them to standard output

– Combination with > [file_name] (redirection)

• Read files sequentially, and write them to [file_name]

• $grep

– Searching plain-text data sets for lines matching a regular expression

• $A | B

– Pipe operation A command’s standard output into B command’s standard input

– e.g. cat /proc/cpuinfo |grep cpu

Default Unix Command (2)

23

17

Embedded Software Lab.

• $cp A B – Copy A file to B file

• $mv A B

– Move A file to B file

• $sudo [program]

– Execute the program as a super user (root) # prevent the permission denied

• $chmod

– Change the file permission

• $chown

– Change the file owner

Default Unix Command (2)

23

18

Embedded Software Lab.

1. $./build_z3.sh – Build / Image compression / Attach device tree

2. $ls -l – Check if build is successfully done

3. $cp arch/arm/boot/dzImage ./dzImage – Copy dzImage file to current directory

Fusing Kernel Image to Z3 (1)

23

19

Embedded Software Lab.

3. Plug the SD card into virtual machine

4. Mount the filesystem on the USB memory – $dmesg

• Check what memory device plugged

– $sudo mkfs.ext4 /dev/sdb , $sudo mount /dev/sdb mnt_test

• format & mount ext4 filesystem on the device

Fusing Kernel Image to Z3 (2)

23

20

Embedded Software Lab.

5. Copy the compressed kernel image into the sdcard – $sudo cp ./dzImage ./mnt_test/dzImage

6. Sync operation to guarantee the durability – $sudo sync

7. Unplug the USB memory and plug sdcard into Z3

8. Connect the sdb shell

Fusing Kernel Image to Z3 (3)

$su #cat /sdcard/dzImage > /dev/disk/by-partlabel/kernel #sync #reboot

23

21

Embedded Software Lab.

• printk()

– The kernel print function to print the messages to the console .

– We may check the messages via dmesg utility.

• Modify void start_kernel(void) – Put the printk code into start_kernel() function invoked at the

booting process

1. Modify start_kernel() ( init/main.c ) as below

2. Build the kernel

3. Fuse the image to Z3 as we’ve learnt in the lecture.

Practice

23

22

Embedded Software Lab.

• The kernel print function

• Behaves almost identically to the C library printf() function

• Callable from just about anywhere in the kernel at any time

• Unusable before a certain point in the kernel boot process – early_printk()

printk()

23

23

Embedded Software Lab.

• printk("<4>This is a warning!\n");

• printk("<7>This is a debug notice!\n");

• printk("<4>did not specify a loglevel!\n");

• printk(KERN_WARNING "This is a warning!\n");

• printk(KERN_DEBUG "This is a debug notice!\n");

• printk("I did not specify a loglevel!\n");

printk-Loglevels