<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3967833943307388322</id><updated>2011-07-29T01:46:14.984-07:00</updated><title type='text'>EMBEDDED SYSTEMS</title><subtitle type='html'>Knowledge Base</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://embeddeddevice.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967833943307388322/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://embeddeddevice.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Embedded Systems</name><uri>http://www.blogger.com/profile/17186927998026659014</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://1.bp.blogspot.com/_vP8ipj7irpU/Sy-3pxBUyRI/AAAAAAAAAAM/mpSJqJI8db0/S220/mcb2100.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3967833943307388322.post-4665958995042124593</id><published>2009-12-22T21:06:00.000-08:00</published><updated>2009-12-22T21:13:18.553-08:00</updated><title type='text'>Writing Linux Device Driver</title><content type='html'>&lt;br /&gt;&lt;h1&gt;User space and kernel space&lt;/h1&gt;  &lt;p&gt;When you write device drivers, it’s important to make the distinction between “user space” and “kernel space”.&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;strong&gt;Kernel space&lt;/strong&gt;. Linux (which is a kernel) manages the machine’s hardware in a simple and efficient manner, offering the user a simple and uniform programming interface. In the same way, the kernel, and in particular its device drivers, form a bridge or interface between the end-user/programmer and the hardware. Any subroutines or functions forming part of the kernel (modules and device drivers, for example) are considered to be part of kernel space.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;User space&lt;/strong&gt;. End-user programs, like the UNIX &lt;code&gt;shell&lt;/code&gt; or other GUI based applications (&lt;code&gt;kpresenter&lt;/code&gt; for example), are part of the user space. Obviously, these applications need to interact with the system’s hardware . However, they don’t do so directly, but through the kernel supported functions.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;All of this is shown in figure 1.&lt;/p&gt;  &lt;dl class="image"&gt;&lt;dt&gt;&lt;a href="http://www.freesoftwaremagazine.com/files/www.freesoftwaremagazine.com/nodes/1238/spaces.jpg"&gt;&lt;img src="http://www.freesoftwaremagazine.com/files/www.freesoftwaremagazine.com/nodes/1238/ss/spaces.jpg" alt="Figure 1: User space where applications reside, and kernel space where modules or device drivers reside" title="Figure 1: User space where applications reside, and kernel space where modules or device drivers reside"&gt;&lt;/a&gt;&lt;/dt&gt;&lt;dd&gt;Figure 1: User space where applications reside, and kernel space where modules or device drivers reside&lt;/dd&gt;&lt;/dl&gt;  &lt;h1&gt;Interfacing functions between user space and kernel space&lt;/h1&gt;  &lt;p&gt;The kernel offers several subroutines or functions in user space, which allow the end-user application programmer to interact with the hardware. Usually, in UNIX or Linux systems, this dialogue is performed through functions or subroutines in order to read and write files. The reason for this is that in Unix devices are seen, from the point of view of the user, as files.&lt;/p&gt;  &lt;p&gt;On the other hand, in kernel space Linux also offers several functions or subroutines to perform the low level interactions directly with the hardware, and allow the transfer of information from kernel to user space.&lt;/p&gt;  &lt;p&gt;Usually, for each function in user space (allowing the use of devices or files), there exists an equivalent in kernel space (allowing the transfer of information from the kernel to the user and vice-versa). This is shown in Table 1, which is, at this point, empty. It will be filled when the different device drivers concepts are introduced.&lt;/p&gt;  &lt;table&gt; &lt;thead&gt; &lt;tr&gt;   &lt;th&gt;&lt;br /&gt;&lt;/th&gt;   &lt;th&gt;&lt;br /&gt;&lt;/th&gt;   &lt;th&gt;&lt;br /&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt;   &lt;td&gt;Events&lt;/td&gt;   &lt;td&gt;User functions&lt;/td&gt;   &lt;td&gt;Kernel functions&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Load module&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Open device&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Read device&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Write device&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Close device&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td&gt;Remove module&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;  &lt;p class="caption"&gt;  &lt;b&gt;Table 1. Device driver events and their associated interfacing functions in kernel space and user space.&lt;/b&gt;  &lt;/p&gt;  &lt;h1&gt;Interfacing functions between kernel space and the hardware device&lt;/h1&gt;  &lt;p&gt;There are also functions in kernel space which control the device or exchange information between the kernel and the hardware. Table 2 illustrates these concepts. This table will also be filled as the concepts are introduced.&lt;/p&gt; &lt;span class="pager-message"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967833943307388322-4665958995042124593?l=embeddeddevice.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embeddeddevice.blogspot.com/feeds/4665958995042124593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddeddevice.blogspot.com/2009/12/writing-linux-device-driver.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967833943307388322/posts/default/4665958995042124593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967833943307388322/posts/default/4665958995042124593'/><link rel='alternate' type='text/html' href='http://embeddeddevice.blogspot.com/2009/12/writing-linux-device-driver.html' title='Writing Linux Device Driver'/><author><name>Embedded Systems</name><uri>http://www.blogger.com/profile/17186927998026659014</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://1.bp.blogspot.com/_vP8ipj7irpU/Sy-3pxBUyRI/AAAAAAAAAAM/mpSJqJI8db0/S220/mcb2100.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967833943307388322.post-4958803585312773154</id><published>2009-12-22T09:22:00.001-08:00</published><updated>2009-12-22T20:55:33.187-08:00</updated><title type='text'>Overview of Embedded Linux Booting Sequence</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://milindchoudhary.files.wordpress.com/2009/03/boot2.png?w=398&amp;h=349"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 398px; height: 349px;" src="http://milindchoudhary.files.wordpress.com/2009/03/boot2.png?w=398&amp;h=349" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This Text provides an insight in to the Embedded Linux Boot Process. Reader should have a basic Knowledge of Boot Process in general and should be familiar with Embedded Linux Boot Process.&lt;br /&gt;&lt;br /&gt;.................&lt;br /&gt;PART-A&lt;br /&gt;................&lt;br /&gt;&lt;br /&gt;(1) Software components Involved in Embedded Linux Boot Process&lt;br /&gt;    (a) Bootloader&lt;br /&gt;    (b) kernel Image&lt;br /&gt;    (c) root file system - either an initrd image or a NFS location&lt;br /&gt;&lt;br /&gt;(2) Steps during Booting process of a conventional PC&lt;br /&gt;    (a) System Startup - PC-BIOS/BootMonitor&lt;br /&gt;    (b) Stage1 bootloader - MBR&lt;br /&gt;    (c) stage2 bootloader - LILO,GRUB etc&lt;br /&gt;    (d) kernel - Linux&lt;br /&gt;    (e) init - The User Space&lt;br /&gt;&lt;br /&gt;(3) Booting process for an Emebedded Systems&lt;br /&gt;    (a) Instead of BIOS you will run program from a fixed location in Flash&lt;br /&gt;    (b) The components involved in the first steps of PC boot process are combined in to a single "boot strap firmware", called "boot loader".&lt;br /&gt;    (c) Bootloader also provides additional features useful for development &amp; debugging.&lt;br /&gt;&lt;br /&gt;(4) What is System Startup?&lt;br /&gt;    [ Exact process depends on the Target Hardware ]&lt;br /&gt;    (a) CPU starts exectuing BIOS at address 0xFFFF0   &lt;br /&gt;    (b) POST (Power On Self Test) - is the first step of BIOS.&lt;br /&gt;    (c) run time services - involve local device enumeration and&lt;br /&gt;initialization&lt;br /&gt;    (d) After the POST is complete, POST related code is flushed out of&lt;br /&gt;memory. But BIOS runtime services remain in memory and are available to&lt;br /&gt;the target OS.&lt;br /&gt;    (e) The runtime searches for devices that are both active and&lt;br /&gt;bootable in order of preference defined in CMOS settings&lt;br /&gt;    (f) The primary boot loader is loaded and BIOS returns control to it&lt;br /&gt;&lt;br /&gt;(5) The Primary boot loader&lt;br /&gt;    (a) Performs  few optional initializations&lt;br /&gt;    (b) Its main job is to Load the secondary boot loader&lt;br /&gt;&lt;br /&gt;(6) Secondary boot loader&lt;br /&gt;    (a) The Second Stage boot loader loads the Linux &amp; an optional&lt;br /&gt;initial RAM disk in to the memory&lt;br /&gt;    (b) on PC, the initrd is used as a temporary root files&lt;br /&gt;system, before final root file system gets mounted. However, on embedded&lt;br /&gt;systems, the initrd is generally the final root file system.&lt;br /&gt;    (c) The secondary loader passes control to the kernel image - kernel is&lt;br /&gt;decompressed &amp; initialized&lt;br /&gt;    (d) So, the secondary boot loaderis the kernel Loader, can also load optional initial RAM disk (initrd), and then invokes the kernel image&lt;br /&gt;&lt;br /&gt;(7) Kernel Invocation&lt;br /&gt;    (a) As the kernel is invoked, it performs the checks on system hardware, enumerates the attached hardware devices, mounts the root device&lt;br /&gt;    (b) Next it loads the necessary kernel modules&lt;br /&gt;    (c) First user-space program (init) now starts and high-level system initialization is performed&lt;br /&gt;    (d) The Kernel Invocation Process is similar on Embedded Linux Systems as well as on PC. We will discuss this in detail in following text.&lt;br /&gt;&lt;br /&gt;(8) Kernel Image&lt;br /&gt;    (a) Is typically a compressed image [zlib compression]&lt;br /&gt;    (b) Typical named a zImage (&lt;512 KB) or bzImage (&gt; 512 KB)&lt;br /&gt;    (c) At the head of this image (in file head.S) is a routine that does some minimal amount of hardware set up and then decompresses the kernel contained in the kernel image and places in to high memory (high memory &amp; low memory)&lt;br /&gt;&lt;br /&gt;.................&lt;br /&gt;PART-B&lt;br /&gt;..................&lt;br /&gt;&lt;br /&gt;(1) Kernel Invocation Process - A Summary&lt;br /&gt;&lt;br /&gt;    (a) zImage Entry Point   &lt;br /&gt;    (b) PERFORM BASIC HARDWARE SET UP&lt;br /&gt;    (c) PERFORM BASIC ENVIRONMENT SET UP (stack etc)&lt;br /&gt;    (d) CLEAR BSS&lt;br /&gt;&lt;br /&gt;    [Now We have set up the run time environment for the code to be&lt;br /&gt;executed next]&lt;br /&gt;&lt;br /&gt;    (e) DECOMPRESS THE KERNEL IMAGE&lt;br /&gt;    (f) Execute the decompressed Kernel Image&lt;br /&gt;        - INITIALIZE PAGE TABLES&lt;br /&gt;        - ENABLE MMU&lt;br /&gt;        - DETECT CPU (&amp; optoinal FPU) TYPE &amp; SAVE THIS INFO&lt;br /&gt;&lt;br /&gt;    [With above set up, we are now ready to execute a general C&lt;br /&gt;Code. Till now we only executed asm routines.]&lt;br /&gt;&lt;br /&gt;    (g) The First Kernel C function&lt;br /&gt;        - DO FURTHER INITIALIZATIONS&lt;br /&gt;        - LOAD INITRD&lt;br /&gt;&lt;br /&gt;    [ The above code is being executed by swapper process, the one&lt;br /&gt;with pid 0]&lt;br /&gt;&lt;br /&gt;    (h) The Init Process&lt;br /&gt;        - FORK INIT PROCESS&lt;br /&gt;        - Init process is with pid 1&lt;br /&gt;        - Invoke Scheduler&lt;br /&gt;        - RELINQUISH CONTROL TO SCHEDULER&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(2) zImage Entry point&lt;br /&gt;    (a) This is a call to the absolute physical address by boot loader&lt;br /&gt;&lt;br /&gt;    - Refer to file arch/***/boot/compressed/head.S: start() in kernel source.&lt;br /&gt;    - For the ARM process this is "arch/arm/boot/compressed/head.S: start()"&lt;br /&gt;&lt;br /&gt;    (b) start() performs&lt;br /&gt;        - basic hardware set up&lt;br /&gt;        - basic environment set up&lt;br /&gt;        - clears bss&lt;br /&gt;        - calls the decompress_kernel()&lt;br /&gt;&lt;br /&gt;(3) Decompressing Kernel Image&lt;br /&gt;    (a) This is a call to arch/***/boot/compressed/misc.c: decompress_kernel()&lt;br /&gt;        - This function decompresses the kernel image, stores it in to the RAM &amp; returns the address of decompressed image in RAM.&lt;br /&gt;    (b) on ARM processor this maps to "arch/arm/boot/compressed/misc.c: decompress_kernel()" routine.&lt;br /&gt;&lt;br /&gt;(4) Execute the decompressed Kernel Image&lt;br /&gt;    (a) After we have got the (uncompressed) kernel image in RAM, we execute it.&lt;br /&gt;    (b) Execution starts with call_kernel() function call [from start()].&lt;br /&gt;    (c) call_kernel() will start executing the kernel code, from Kernel&lt;br /&gt;entry point.&lt;br /&gt;    (d) arch/***/kernel/head.S contains the kernel entry point.&lt;br /&gt;        - separate entry points for Master CPU and Secondary CPUs (for SMP&lt;br /&gt;systems).&lt;br /&gt;        - This code is in asm&lt;br /&gt;        - Page Tables are Initialized &amp; MMU is enabled.&lt;br /&gt;        - type of CPU alongwith optional FPU is detected and stored&lt;br /&gt;        - For Master CPU; start_kernel(), which is the first C function to&lt;br /&gt;be executed in kernel, is called.&lt;br /&gt;        - For secondary CPUs (on an SMP system); secondary_start_kernel()&lt;br /&gt;is the first C function to be called.&lt;br /&gt;    (e) On ARM process it maps to "arch/arm/kernel/head.S&lt;br /&gt;        - Contains kernel ENTRY points for master and secondary CPU.&lt;br /&gt;        - For Master CPU "mmap_switched()" is called as soon as mmu gets enabled. The mmap_switched() saves the CPU info makes a call to start_kernel()&lt;br /&gt;        - For Secondary CPU "secondary_start_kernel()" is called as soon as MMU gets enabled.&lt;br /&gt;&lt;br /&gt;(5) The first kernel C function&lt;br /&gt;    (a) The start_kernel() function is being executed by the swapper process.&lt;br /&gt;    (b) Refer to init/main.c: start_kernel() in the kernel source.&lt;br /&gt;    (c) start_kernel():&lt;br /&gt;        - a long list of initialization functions are called: this sets up interrupts, performs further memory configuration &amp; loads the initrd.&lt;br /&gt;        - calls rest_init() in the End.&lt;br /&gt;    (d) econdary_start_kernel() for secondary CPUs (on SMP systems).&lt;br /&gt;        - arch/***/kernel/smp.c: secondary_start_kernel()&lt;br /&gt;        - for ARM, arch/arm/kernel/smp.c&lt;br /&gt;        - there is not rest_init() call for secondary CPUs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(6) Init process&lt;br /&gt;    (a) Refer to init/main.c: rest_init() in kernel source.&lt;br /&gt;    (b) Executed only on the Master CPU&lt;br /&gt;    (c) rest_init() forks new process by calling kernel_thread() function&lt;br /&gt;    (d) kernel_thread(kern_init,*,*); kern_init has PID-1&lt;br /&gt;    (e) kern_init() will call the initialization scripts.&lt;br /&gt;    (f) kernel_thread() defined in "arch/***/kernel/process.c: kernel_thread()".&lt;br /&gt;    (g) on ARM, arch/arm/kernel/process.c&lt;br /&gt;&lt;br /&gt;(7) Invoke scheduler&lt;br /&gt;    (a) The rest_init() calls cpu_idle() in end [after it is done creating the init process]&lt;br /&gt;    (b) For the Secondary CPUs (on SMP systems), cpu_idle is directly&lt;br /&gt;called from secondary_start_kernel [no step-5 &amp; hence no init process].&lt;br /&gt;    (c) cpu_idle() defined in "arch/***/kernel/process.c: cpu_idle()".&lt;br /&gt;    (d) on ARM, arch/arm/kernel/process.c&lt;br /&gt;&lt;br /&gt;(8) initrd image&lt;br /&gt;    (a) The initrd serves as a temporary root file system in RAM &amp; allows the kernel to fully boot without having to mount and physical disks. Since the necessary modules needed to interface with peripherals&lt;br /&gt;can be part of initrd the kernel can be very small.&lt;br /&gt;    (b) pivot_root() routine: the root files system is pivoted where the initrd root file system is unmounted &amp; the real root file system is mounted.&lt;br /&gt;    (c) In any embedded system, the initrd could be the root file system.&lt;br /&gt;&lt;br /&gt;........................&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;http://www.ibm.com/developerworks/linux/library/l-linuxboot/&lt;br /&gt;http://duartes.org/gustavo/blog/post/how-computers-boot-up&lt;br /&gt;http://duartes.org/gustavo/blog/post/kernel-boot-process&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967833943307388322-4958803585312773154?l=embeddeddevice.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embeddeddevice.blogspot.com/feeds/4958803585312773154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddeddevice.blogspot.com/2009/12/overview-of-embedded-linux-booting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967833943307388322/posts/default/4958803585312773154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967833943307388322/posts/default/4958803585312773154'/><link rel='alternate' type='text/html' href='http://embeddeddevice.blogspot.com/2009/12/overview-of-embedded-linux-booting.html' title='Overview of Embedded Linux Booting Sequence'/><author><name>Embedded Systems</name><uri>http://www.blogger.com/profile/17186927998026659014</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://1.bp.blogspot.com/_vP8ipj7irpU/Sy-3pxBUyRI/AAAAAAAAAAM/mpSJqJI8db0/S220/mcb2100.gif'/></author><thr:total>0</thr:total></entry></feed>
