TOC Embedded TOC LDD v2.1-WithPhase1
TOC Embedded TOC LDD v2.1-WithPhase1
Module Hours
C++ Programming 54
Computer Architecture - Hardware 6
Computer Architecture - Network 6
1.5
Assignment 2: Identify a real-world application for both parallel computing and networked systems. Explain how these techno
Submission Guidelines:
1. Ensure that each answer is clear, concise, and reflects an understanding of the core concepts.
2. Diagrams can be hand-drawn and scanned or created using any digital drawing tool.
3. Provide references for any external sources used.
Submit your work in a single PDF document by end of Module
2
Understanding the Networks from a
Software Developer perspective, the
learners must understand how
computer network works, how data
1.5 is transferred across two connected
systems in a network, different
addressing schemes. What are
protocols, commonly used protocols
and their use. How does network
1 isolation and topology work, how
data traverses over internet, what is
NAT and why they must know it.
Understand network security,
0.5 firewall, VPN etc.
ked systems. Explain how these technologies are used and why they are important in that context.
Assignment 1: Text Processing and Automation - Write a bash script that uses grep, sed, and awk to list all login attemtps to a
Assignment 2: Version Control with Git - Initialize a new Git repository, simulate making changes to a project by adding text fil
Assignment 3: Collaborative Development Using Git - Fork an existing repository (this can be a simulated action if no actual re
Submission Guidelines:
1. Ensure that each answer is clear, concise, and reflects an understanding of the core concepts.
2. Diagrams can be hand-drawn and scanned or created using any digital drawing tool.
3. Provide references for any external sources used.
Submit your work in a single PDF document by end of Module.
2.5
_x000D_ Internal - General Use
#
2.5
ng changes to a project by adding text files, and commit those changes. Create a new branch, make further changes in this branch, and m
can be a simulated action if no actual repository is available), clone it locally, and demonstrate managing updates from the original reposi
ates from the original repository. Create a pull request to the original repository with changes made in the forked repository, and outline
Define variables of differnt types initialized with predefined data. The variables
should be local variables, global variables, static variables, constants. Put a break
point in gdb on main function and observe the memory layout of the variables in
memory. Understand stack and heap memory areas.
Task 1C: Using gdb, observe memory layout of string array and integer array.
Observe memory layout of single dimensional array and two dimentional array.
Task 1D: Define a pointer initialized with string constant. Observe using gdb, the
address where pointer is stored, the address contained the pointer where the string
is stored. Observe are they in different areas of data storage classes (stack, data
section etc.).
Task 1E: Operation with double pointers. Learn to modify the data using a double
pointer.
Functions
Task 1F: Observe the location of stack
Make two level function calls, with passing of parameters. Observe the address of
the stack frames, where the local variables are stored and how the SP and BP
registers are manipulated and how the return address is stored on the stack.
Define a function operation() which should take a function pointer and 2 more
arguments. Define add, subtrack, multiply and divide as functions. Pass one of these
functions to operation() with other two arguments and check correct function gets
called.
Task 1J: Use #ifdef directive in a header file to make it get included only once in a C
file.
Task 1K: Use #pragma pack directive with a structure and observe the data layout in
memory using gdb.
4.00 Learners will delve into arrays and pointers, uncovering the
essentials of single and multi-dimensional arrays, and learning
to prevent array bound overflow. They'll grasp the
fundamentals of pointers, including declaration,
dereferencing, and pointer arithmetic, and understand how
pointers intricately relate to arrays, enhancing their data
manipulation capabilities.
4.00 In the "File Input/Output " module, learners will gain the skills
to manipulate files using standard I/O functions,
understanding how to open, read, write, and close files
effectively. They'll work with both text and binary files,
learning the nuances of each format. In the "Data Structures
in C" section, learners will construct the backbone of efficient
software through the implementation of linked lists, stacks,
and queues. They will learn to build and manipulate singly and
doubly linked lists, understand the functionality of stacks and
queues, and how to implement them. This knowledge is
fundamental to solving complex problems in software
development, where efficient data handling is key to
performance and scalability.
Building on their previous experience with programming
constructs, object-oriented principles, and array algorithms,
learners will dive into the realm of data structures. They'll
start by understanding the classification of data structures
into linear and non-linear types, including static structures like
arrays and dynamic structures such as queues, stacks, and
linked lists. Further, they will explore non-linear structures like
trees, graphs, hash tables, sets, heaps, and tries. Practical
implementation in C++ will begin with linked lists, covering
various types and operations, followed by stacks and queues,
learning to perform basic operations. This knowledge is crucial
3.00 for efficient data management and algorithm design in
software development.
6.00
6.00
6.00
3.00
Learners will delve into STL Containers, crucial for C++
development, understanding their role in the Standard
Template Library. They'll examine container types like vectors
for dynamic arrays, lists for linked structures, maps for key-
value pairs, queues, stacks, and deques for specific data
handling. They'll master iterators, which are fundamental for
container traversal, and learn about the various iterator types.
The course will cover essential STL algorithms like find,
for_each, sort, and more, with real-world examples. Adaptors
and allocators will be discussed, teaching students to adapt
container interfaces and manage memory effectively in
container operations, forming a core skill set for efficient C++
5.00 programming.
In this module, learners will explore RTTI in C++,
understanding its purpose and how to use typeid and
dynamic_cast operators, while considering RTTI's limitations
and impact on performance. They'll learn how to define and
utilize namespaces to avoid name conflicts, and the best
practices for their effective use. The course will also cover the
'using' directive for simplification and aliasing in C++.
Additionally, modern C++ features like auto, nullptr, range-
based loops, and more advanced concepts like fold
expressions and transactional memory will be introduced,
alongside the practicalities of class template argument
deduction, equipping learners with contemporary C++
programming skills.
3.00
3.00
3.00
s destroyed.
rent implementations.
the vector.
nt each element.
Module
Duration (Hrs)
Sl. No.
1.0
1.1
1.2
1.3
3.0
3.1
3.2
3.3
3.4
3.5
3.5
3.6
3.11
4.00
4.10
4.20
5.0
5.1
5.2
5.3
5.4
6.0
6.1
6.2
6.3
6.4
7.0
7.1
7.2
7.3
9.00
9.10
9.10
9.20
10.30
10.40
11.0
11.1
11.2
11.3
13.0
13.1
13.2
14.0
14.1
14.2
14.2
15.0
15.1
15.2
16.0
16.1
16.2
19.0
19.1
19.2
21.0
21.1
21.2
23
Linux Device Driver Development
63
Topics
Linux Systems
Introduction to Linux System Software:
Linux as an Operating System
Components of a Linux Distribution
Linux Kernel Overview:
Role of the Kernel
Linux Kernel Versions
Kernel Architecture & Components:
Understanding the Kernel's Structure
Kernel Components and Their Functions
Task 1
Linux Systems Internals and Programming
Linux System Overview
Purpose of Understanding Linux System
Significance of Kernel vs. User Space
Privilege Levels and Rings
Concept of Privilege Levels (Rings)
Ring 0: The Kernel Mode
Ring 3: The User Mode
Intermediate Rings (Ring 1 and Ring 2)
Task 6
Protected Mode in the x86 Architecture
Introduction to Protected Mode
Transition from Real Mode to Protected Mode
Benefits of Protected Mode
Memory Protection in Protected Mode
Segmentation and Paging
Role of Segmentation
Paging Mechanisms for Memory Isolation
Address Translation by the MMU
Task 7
User-Space to Kernel-Space Transition
Transition Mechanism
Understanding User-Space to Kernel-Space Transition
Role of System Calls (Syscalls)
Privilege Escalation
How Syscalls Enable Privilege Escalation
Syscall Handling in the Kernel
Kernel Space Operations
Direct Hardware Access
Kernel Space's Direct Access to Hardware
Execution of Device Drivers in Kernel Space
Core Functions in Kernel Space
Kernel Space as the Core of the Operating System
Resource Management by the Kernel
User Space Restrictions
Security and Stability
Ensuring Security through User Space Restrictions
Maintaining System Stability
Controlled Interfaces (Syscalls)
Limitations on Direct Hardware Access
Role of Syscalls as Controlled Interfaces
Benefits of Isolation
Advantages of Isolating User Space from Kernel Space
GNU Bin Tools for Programmers
Understanding Process Layout
Memory Segmentation and Organization
Program Memory Layout
Important Bin Tools
nm (Symbol Table)
Symbol Tables in Object Files and Executables
Listing Symbols and Their Attributes
objdump (Object File Information)
Extracting Disassembly and Sections
Analyzing Object Files and Executables
readelf (ELF File Information)
Retrieving ELF Header Information
Examining Section Headers
size (Binary Size Information)
Determining Binary Size Information
Task 16
Understanding Virtual Memory
Session 4: Virtual Memory Fundamentals
Basics of Virtual Memory in Linux
Understanding Paging and Memory Management
Kernel space vs. User space memory
Hands-on: Exploring procfs to view memory mappings
Session 5: User Space and Kernel Space Interaction
Functions like copy_to_user and copy_from_user
Protecting against buffer overruns and access violations
Task 17
Hands-on: Writing a simple module using copy_to_user to send data to user space
Introduction to Device Drivers
Understanding Device Drivers in Linux
Kernel-User Space Interaction
Types of Device Drivers: Character, Block, Network
Development Environment Setup
Essential Tools: GCC, Make, Kernel Headers
Writing a Basic Kernel Module: Hello World Example
Module Loading and Unloading
module_init() and module_exit()
Module Parameters: module_param()
Kernel Data Structures and Basic APIs
Kernel Version and Compatibility
Kernel Logging with printk()
Device Registration and Initialization
Char Device Registration: register_chrdev()
Char Device Initialization: cdev_init()
Task 18
Task 19
Task 20
Task 21
Character Device Drivers
Major and Minor Numbers
Allocation of Device Numbers: alloc_chrdev_region()
Registering a Character Device: cdev_add()
File Operations
Struct file_operations: Function Signatures
open(), release(), read(), write()
Implementation of File Operations
ioctl Method
unlocked_ioctl() for Handling User Space Requests
Command Definitions and Macros
Synchronization Techniques
Mutexes: mutex_init(), mutex_lock(), mutex_unlock()
Spinlocks: spin_lock(), spin_unlock()
Strategies to Prevent Deadlocks and Race Conditions
Task 22
Task 23
Task 24
Task 25
Concurrency and Race Conditions
Concurrency in the Kernel
Process Context and Interrupt Context
Kernel Preemption and Sleeping
Semaphores and Mutexes
Semaphore Usage: sema_init(), down(), up()
Mutex API: Initialization and Usage
Deadlock Prevention Strategies
Identifying and Avoiding Deadlocks
Lock Hierarchy and Effective Locking Techniques
Task 26
Task 27
Task 28
Understanding Device Trees
Session 1: Introduction to Device Trees
Overview of Device Trees in Linux
Understanding the structure of Device Trees
Device Tree Blob (DTB), Device Tree Compiler (DTC), and Device Tree Source (DTS)
files
Hands-on: Analyzing a sample DTS file and compiling it into DTB
Session 2: Customizing Device Tree
How the Kernel uses Device Trees
Customizing Device Trees for different hardware
Overlaying Device Trees for modular hardware configurations
Task 31
Hands-on: Modifying a DTS file and creating an overlay
Session 7: Embedded Linux Boot Process and Build Systems
Bootloaders and the Linux boot process
Understanding zImage and its role in booting
The Linux memory map and linker scripts
Introduction to Buildroot and Yocto
Hands-on: Creating a custom embedded Linux build using Buildroot
Session 8: Building and Customizing Embedded Linux with Yocto
Yocto Project overview
Creating custom layers and recipes
Configuring and building a Yocto-based system
Hands-on: Customizing a Yocto project to include a new application
Direct Memory Access (DMA)
DMA API and Concepts
Understanding DMA and DMA Engine API
Buffer Allocation: dma_alloc_coherent()
Buffer Management
Managing DMA Buffers
dma_map_single(), dma_map_sg()
Handling DMA Transfers: dma_unmap_single()
Synchronization for DMA
Synchronizing DMA Buffers: dma_sync_single_for_cpu(), dma_sync_single_for_device()
Task 32
Task 33
Time, Delays, and Deferred Work
Using Kernel Timers
Timer Initialization: init_timer()
Adding and Modifying Timers: add_timer(), mod_timer()
Timekeeping in the Kernel
Tasklets and Workqueues
Tasklet Initialization: tasklet_init()
Scheduling and Handling Tasklets
Workqueue Initialization: create_workqueue()
Task 34
Task 35
Allocating Memory
Memory Allocation Functions
kmalloc(), kfree(), vmalloc()
GFP Flags and Memory Zones
Managing Noncontiguous Memory
High Memory and vmalloc() Area
Memory Pool API: kmem_cache_create()
Interrupt Handling
Understanding Interrupts and IRQs
IRQ Numbers and IRQ Descriptors
Top Half and Bottom Half Handlers
Writing an Interrupt Handler
request_irq(), free_irq()
Shared Interrupt Lines
Data Types in the Kernel
Kernel-Specific Data Types
Fixed-Width Integer Types: u8, u16, u32
List and Queue APIs: list_head, list_add(), list_for_each_entry()
Atomic Operations and Bit Manipulation
atomic_t and Atomic Functions
Bitwise Operators: set_bit(), test_and_set_bit()
Task 36
Task 37
Task 38
Task 39
Task 40
Task 41
The Linux Device Model
Understanding Sysfs
Sysfs Entries and Kobjects
Attribute Files and show()/store() Methods
Hotplug and Coldplug Mechanisms
udev Integration and uevent Handling
Hotplug Callbacks
Debugging Techniques
Debugging Device Drivers
Effective Logging with printk()
Using Kernel Debuggers: KDB, KGDB
Handling OOPS Messages and Kernel Panics
Profiling and Tracing
Profiling with ftrace and perf Tools
Kernel Probes and Tracepoints
Assignment - Device Driver Development inside QEMU
Topic:
Simple Character Device Driver Development in QEMU
Objective:
To create a basic character device driver for a virtual device in QEMU, demonstrating understanding
of device driver structure and simple read/write operations.
Steps:
1-Prepare the Environment:
-Ensure QEMU is set up with a standard virtual machine environment that includes a Linux
kernel with development tools (GCC, make, etc.).
2-Driver Specification:
-Develop a simple character device driver. The driver need only implement basic open, close,
read, and write operations. The read and write operations can perform simple
tasks, such as returning a fixed string to any read request and printing any write input to the
kernel log.
3-Code the Driver:
-Write the character device driver code in C, adhering to the Linux kernel coding style. The
driver does not need to interact with actual hardware but should successfully load and unload
within the Linux kernel running in QEMU.
4-Compile and Load the Driver:
-Compile the driver as a module and load it into the Linux kernel within the QEMU
environment. Use insmod to load the module and rmmod to remove it.
5-Test the Driver:
-Test the driver by opening a device file associated with your driver and performing read and
write operations. Use dmesg to verify that write operations log input to the kernel log.
6-Document the Process:
-Briefly document the steps you took, any challenges you faced, and how you tested the
driver.
Daily Assignments
Linux Systems
Task 1: Kernel Architecture Diagram - Draw a detailed diagram of the Linux kernel architecture. Label and
write a short description (2-3 sentences) for each major component like Scheduler, File System, Network
Stack, etc.
Shell Scripting
Task 3: Write a Bash script that:
Declares two variables, one string, and one integer.
Includes an if-else statement that prints a message based on the value of the integer.
Task 7: Segmentation and Paging Presentation: Prepare a slide presentation on segmentation and paging,
including visual diagrams and examples of address translation.
Task 17:
Virtual Memory Basics:
Summarize how virtual memory works in Linux in three sentences or less. Why is virtual memory critical in a
multitasking operating system?
Exploring procfs:
What kind of information can you find about memory mappings in the procfs? Describe how you would use
procfs to find out about the virtual memory usage of a process.
4
In this module, learners will master the art of debugging and
testing, vital skills for system programmers. They'll explore
debugging techniques tailored for kernel code and familiarize
themselves with kernel debuggers and tools. Additionally, the
module covers GNU Bin Tools for programmers, focusing on
understanding process layout, memory segmentation, and
program memory organization.
Learners will delve into important Bin Tools such as 'nm' for
symbol table analysis, 'objdump' for extracting disassembly and
3 sections, and 'readelf' for retrieving ELF header information and
examining section headers. The module concludes with 'size' for
determining binary size information. These skills are essential
for efficient debugging, testing, and analysis of Linux system
components.
6
6
4
4
4
4
4. Task: (Conceptual) Research How System Calls Enable Privilege Escalation
5. Task: (Conceptual) Research Syscall Handling in the Kernel
Task Set 4: Exploring Kernel Space Operations and Restrictions (Conceptual and Observational)
1. Task: (Conceptual) Research Kernel Space's Direct Access to Hardware
2. Task: (Conceptual) Research the Execution of Device Drivers in Kernel Space
3. Task: (Conceptual) Research Core Functions in Kernel Space
4. Task: (Conceptual) Understand the Kernel as the Core of the Operating System
5. Task: (Conceptual) Research Resource Management by the Kernel
6. Task: Observe User Space Restrictions (Hands-on)
Handson
7. Task: (Conceptual) Understand the Role of Syscalls as Controlled Interfaces
8. Task: (Conceptual) Research the Benefits of Isolating User Space from Kernel Space
Advanced and Challenge Tasks:
• Task: Analyze a Shared Library (Revisited with a Focus on Kernel Interaction): Choose a core shared library lik
libc.so.6. Use nm, objdump, and readelf to analyze its symbols, sections, and structure. Pay attention to the symb
related to system calls (e.g., syscall, __syscall). How do these symbols facilitate the transition to the kernel?
• Task: Explore Dynamic Linking and System Calls: Use ldd on a program that makes system calls. Observe whi
shared libraries are linked. Research how dynamic linking helps programs access system call wrappers provided
libraries like libc.
• Task: (Conceptual) Explore SystemTap or BPF for Dynamic Analysis (Focus on Kernel Events): Research how t
like SystemTap or BPF can be used to dynamically trace system calls and other kernel events. Understand how th
provide insights into the interaction between user space and the kernel without modifying the kernel code.
• Task: (Conceptual) Research Kernel Modules: Understand what kernel modules are and why they are used. H
do they fit into the kernel space? How are they loaded and unloaded?
Advanced and Challenge Tasks:
• Task: Write a Simple C Program that Uses a System Call Directly: Write a basic C program that uses a system
like write or read directly (instead of relying on standard library functions like printf or fread). Compile and run it
then use strace to verify that it makes the expected system call.
• Task: Research a Specific System Call in Detail: Choose a system call (e.g., fork, execve, pipe) and research its
purpose, arguments, and how it facilitates communication or process management between user space and the
kernel.
• Task: Explore the Differences Between System Calls and Library Functions: Research the relationship betwee
system calls and standard library functions, understanding when a library function might make a system call and
it might perform operations entirely in user space.
• Task: (Requires Kernel Source Code or Advanced Tools) Observe the System Call Entry Point: (Highly advance
Research how the transition from user space to kernel space happens at the assembly level, involving interrupts
trap instructions. This is a more theoretical task but can be explored by examining kernel source code or using
advanced debugging tools.
Linux Device Drivers: Deep Dive & Practical Application
Objective: This assignment aims to solidify your understanding of Linux device drivers by guiding you through the
process of creating, testing, and interacting with a basic character device driver. You will apply the concepts cove
the module to build a functional driver and understand its lifecycle.
Assignment:
We will create a simple character device driver named "ldd_assignment" that acts as a virtual, in-memory buffer
Userspace applications will be able to write data to this buffer and read data from it.
Tasks:
1. Development Environment Setup:
o Verify that you can build and load a simple "Hello World" kernel module.
4.
2. Task: Determine
Basic Kernel Binary
Module: Size Information
"Hello World" (Review with&size Refinement):
Advanced and Challenge Tasks:
o Create a kernel module named hello_ldd.c that prints "Hello, LDD Assignment!" when loaded and "Goodbye
•Assignment!"
Task: Use whena User-Space
unloaded Debugger (gdb):
using printk().
o Compile your C program with
o Include the necessary headers: <linux/module.h>, debugging symbols: gcc -g -o my_program
<linux/kernel.h>, my_program.c.
and <linux/init.h>.
o Start the debugger: gdb my_program.
o Use module_init() and module_exit() to specify your initialization and cleanup functions.
o
o Set a breakpoint
Create a Makefileattothe main
build thisfunction:
module.break main.
o Run the program: run.
o Load and unload the module using insmod and rmmod respectively, and observe the output in the kernel log
o
(dmesg). Step through the code line by line: next.
o
3. Print the values
Designing of variables: printCharacter
the "ldd_assignment" local_var,Device
print global_var.
Driver:
o
o Kernel-User Space Interaction: Think about howmemory
Examine memory: x /x &local_var (examine the userspace at applications
the address willof local_var).
interact with your driver. They w
o Continue execution: continue.
standard file operations like open(), read(), write(), and close().
o
o Explain how gdb allows
Driver Structure: Plan the interactive
structuredebugging of user-space programs,
of your ldd_assignment.c inspecting
file. You will need tovariables,
define thestepping through
necessary func
and analyzing memory.
to handle the file operations.
•o Task: BufferAnalyze a Shared Library:
Implementation: Decide Choose
how youa willshared library on
implement theyour system (e.g.,
in-memory libc.so.6)
buffer. A simpleand use nm,array
character objdump
or a
readelf to analyze its symbols, sections, and structure.
dynamically allocated buffer will suffice for this assignment. Consider its size and how to handle potential overflo
•4. Task: Explore Dynamic
Implementing Linking: Research
the "ldd_assignment" how dynamic linking works and how tools like ldd can show the sha
Driver:
libraries that a program depends on.
o Include Necessary Headers: Include headers like <linux/module.h>, <linux/kernel.h>, <linux/init.h>, <linux/fs
•<linux/cdev.h>,
Task: Understand the Purpose
<linux/slab.h>, of Different ELFand
<asm/uaccess.h>, Sections: Research common ELF sections
<linux/uaccess.h>.
(e.g., .text, .data, .bss, .rodata, .symtab, .strtab,
o Module Information: Define the module license and author .debug_info) andusing
theirMODULE_LICENSE()
role in organizing a binary.
and MODULE_AUTHO
•o Task: (Conceptual/Research) Explore SystemTap or
Device Number Allocation: Dynamically allocate a major and minor number BPF for Dynamic Analysis:forResearch dynamicdevice
your character analysis too
using
SystemTap or BPF
alloc_chrdev_region(). (Berkeley Packet Filter) which allow you to probe the kernel and user space without modifying
code, providingDevice
o Character powerful debugging
Structure: and tracing
Initialize a structcapabilities.
cdev for your device using cdev_init().
Assignment: Exploring
o File Operations: Memory Mappings
Implement the following andfile
Interacting
operation with Kernel Space
functions:
Objective: To understand how virtual memory is
ldd_assignment_open(): Called when a userspace application opens organized in Linux, how theprocesses
device map
file. memory, the distinction
between user and kernel space, and how user space interacts with
ldd_assignment_release(): Called when a userspace application closes the device file. kernel space.
Part 1: Exploring Process Memoryfile
ldd_assignment_read(struct Mappings
*filp, charwith procfs
__user *buf, size_t count, loff_t *f_pos): Reads data from the buff
1. Create a Simple C Program:
the userspace buffer. Use copy_to_user() carefully. Handle the buffer position (f_pos).
o
Write a C program named memory_explorer.c
ldd_assignment_write(struct file *filp, const char that performs
__user *buf,the following:
size_t count, loff_t *f_pos): Writes data from
Declares an integer variable on the stack.
userspace buffer to the driver's buffer. Use copy_from_user() carefully. Handle the buffer position (f_pos).
o Declares a globalStructure:
File Operations integer variable.
Populate a struct file_operations with pointers to your implemented functions.
Allocates memory
o Device Registration: onAdd
theyour
heapcharacter
using mallocdevicefor to
anthe
integer.
kernel's device list using cdev_add().
Prints the addresses
o Initialization and Cleanup: of the stack variable, the global variable, and the heap-allocated variable.
Prints
Implementthe process ID (PID) of the program
the ldd_assignment_init() usingAllocate
function: getpid().device numbers, initialize the cdev, and add the dev
Enters
Use printk()an toinfinite loop or
log success (e.g., using while(1);) so you can inspect its memory while it's running.
failure.
Implement the ldd_assignment_exit() function: Delete the character device using cdev_del() and unregister
Part 2: numbers
device SimulatingusingKernel Space Interaction
unregister_chrdev_region(). Use printk() to log cleanup.
o Module Entry and Exit Points: Use module_init() and module_exit() to point to your ldd_assignment_init() an
ldd_assignment_exit() functions.
5. Adding Module Parameters (Optional but Recommended):
o Add a module parameter named buffer_size using module_param() that allows the user to specify the size o
internal buffer when loading the module.
o Modify your driver to allocate the buffer dynamically based on the buffer_size parameter. Handle potential
memory allocation failures.
6. Building and Testing the Driver:
o Update your Makefile to build the ldd_assignment.ko module.
o Load the module using insmod ldd_assignment.ko. If you implemented the module parameter, try loading it
specific size: insmod ldd_assignment.ko buffer_size=1024.
o Check the kernel log (dmesg) for messages from your driver.
o Create a Device Node: Manually create a device node in the /dev directory corresponding to your driver's m
and minor numbers. You can find these numbers in the kernel log after loading the module. The command is typ
sudo mknod /dev/ldd_assignment c <major_number> <minor_number>.
o Userspace Testing Program: Write a simple C program that opens /dev/ldd_assignment, writes some data to
reads data back, and closes the device. Print the data read back to verify the driver's functionality.
o Update your Makefile to build the ldd_assignment.ko module.
o Load the module using insmod ldd_assignment.ko. If you implemented the module parameter, try loading it
specific size: insmod ldd_assignment.ko buffer_size=1024.
o Check the kernel log (dmesg) for messages from your driver.
o Create a Device Node: Manually create a device node in the /dev directory corresponding to your driver's m
and minor numbers. You can find these numbers in the kernel log after loading the module. The command is typ
sudo mknod /dev/ldd_assignment c <major_number> <minor_number>.
o Userspace Testing Program: Write a simple C program that opens /dev/ldd_assignment, writes some data to
reads data back, and closes the device. Print the data read back to verify the driver's functionality.
o Test Cases:
Write data that is smaller than the buffer size.
Write data that is larger than the buffer size (observe how your driver handles this).
Read data after writing.
Attempt to read more data than is currently in the buffer.
Test multiple opens and closes.
o Unload the module using rmmod ldd_assignment. Check the kernel log for cleanup messages.
7. Documentation and Reflection
Part 2: Implementing File Operations
1. Define the struct file_operations:
2. Implement pseudo_mem_open: }
3. Implement pseudo_mem_release:
4. Implement pseudo_mem_read:
5. Implement pseudo_mem_writePart
3: Implementing the ioctl Method
1. Define ioctl Commands
2. Implement pseudo_mem_ioctl (or unlocked_ioctlPart
4: Synchronization Techniques
• In a real-world scenario, multiple processes might access your device concurrently. This can lead to race con
when accessing the pseudo_mem_buffer. We need to protect access to this shared resource.
1. Implement Mutex Protection
2. Implement Spinlock Protection (Optional but good to understand
3. Strategies to Prevent Deadlocks and Race Conditions:
Part 5: Building and Testing the Driver
1. Create a Makefile
2. Build the Module
3. Load the Module
4. Test with User Space Programs
5. Compile User Space Programs
6. Run User Space Programs
7. Unload the Module
8. Remove the Device Node
Assignment 8: Deadlock Prevention Strategies
• Objective: Practice effective locking.
• Task:
o Implement retry logic using trylock() in a kernel module.
o Use lock timeouts to avoid hard deadlocks.
Assignment 9: Lock Hierarchy Enforcement
• Objective: Enforce a lock acquisition hierarchy.
• Task:
o Create three shared resources protected by mutexes.
o Document a strict lock acquisition order.
o Validate using kernel debug options like lockdep (CONFIG_DEBUG_LOCK_ALLOC).
Assignment 10: Kernel Debugging of Concurrency Issues
• Objective: Learn to identify real-world locking issues.
• Task:
o Use printk, lockdep, ftrace, or dmesg to track lock behavior in previous assignments.
o Trigger deadlocks and analyze stack traces.
1. Choose a simple peripheral (e.g., an LED or I2C device).
2. Modify an existing .dts file to include a new node for your device.
3. Set properties like GPIO number, compatible string, etc.
4. Recompile and verify using dtc.
Hands-On Assignment 3: Kernel Integration Test
• Objective: Understand how the kernel consumes Device Trees.
• Steps:
1. Boot a Linux system with a custom .dtb.
2. Verify that the kernel has recognized the device via dmesg or /proc/device-tree/.
2. Verify that the kernel has recognized the device via dmesg or /proc/device-tree/.
3. Use tools like hexdump or fdtdump to inspect .dtb contents.
Hands-On Assignment 4: Create a Device Tree Overlay
• Objective: Dynamically add hardware support using overlays.
• Steps:
1. Write a small Device Tree Overlay (.dts) for an add-on board (e.g., GPIO expansion).
DMA
2. Load Hands-On Assignment
the overlay Series or U-Boot (depends on platform).
using configfs
Assignment
3. Confirm1: DMA API Basics
functionality via /sys/firmware/devicetree/base/.
• Objective: Understand DMA setup and concepts using a basic kernel module.
3.
• Boot Task: the image in QEMU.
Hands-On
1. Write aAssignment 6: Create
simple kernel module Custom Layer and
that initializes Recipe
a DMA-capable device (can be simulated).
•2. Objective: Extend Yocto with custom content.
Print out device DMA mask capabilities (dma_get_mask()).
•Assignment
Steps: 2: Allocating Coherent DMA Buffers
1.
• Create a new
Objective: Uselayer:
dma_alloc_coherent() to allocate memory accessible by both CPU and device.
2. Write
• Task: a recipe for a custom app (e.g., a simple C "Hello World").
3.
1. Add youraapp
Allocate to IMAGE_INSTALL.
buffer in a kernel modul
Hands-On
2. Fill buffer with data7:and
Assignment Customize and Rebuild
print virtual Yoctoaddresses.
and physical Image
•Assignment
Objective: Modify and expand a Yocto image.
3: Managing DMA Buffers with dma_map_single()
• Steps:
Objective: Practice streaming DMA buffer mapping.
1.
• Add
Task:Dropbear or OpenSSH to the image.
2.
1. Include
Allocateyour custom
memory withapp in the rootfs.
kmalloc() (non-coherent).
3. Boot the image, confirm functionality
2. Map it with dma_map_single() and print via the
SSHreturned
or console.
DMA address.
3. Simulate a device write and unmap using dma_unmap_single().
Assignment 4: Scatter-Gather DMA with dma_map_sg()
• Objective: Handle non-contiguous memory.
• Task:
1. Use alloc_pages() or multiple kmalloc() to create scatter buffers.
2. Fill struct scatterlist[] and call dma_map_sg().
3. Iterate and print DMA addresses for each segment.
Assignment 5: DMA Synchronization
• Objective: Synchronize CPU and device access to DMA buffers.
• Task:
1. Allocate a streaming DMA buffer.
2. Before CPU reads, use:
dma_sync_single_for_cpu(dev, dma_handle, size, DMA_FROM_DEVICE);
3. After CPU write, use:
dma_sync_single_for_device(dev, dma_handle, size, DMA_TO_DEVICE);
Assignment 1: SDLC Overview - Create a one-page infographic that outlines the SDLC phases (Requirements, Design, Implemen
Assignment 2: Requirements Gathering - Conduct a 30-minute mock interview to gather requirements for a fictional app that
Submission Guidelines:
1. Ensure that each answer is clear, concise, and reflects an understanding of the core concepts.
2. Diagrams can be hand-drawn and scanned or created using any digital drawing tool.
3. Provide references for any external sources used.
Submit your work in a single PDF document by end of Module.
Identify at least two actors who will interact with the system (e.g., Librarian, Member).
Determine two to three main functionalities (use cases) that the actors will perform (e.g., Check Out Book, Return Book).
Draw a use-case diagram with these actors and use cases, showing the interactions between the actors and the system.
Topics
Task 1
m Elements
Application
ing Techniques
ne-page infographic that outlines the SDLC phases (Requirements, Design, Implementation, Testing, Deployment), highlighting the importa
Conduct a 30-minute mock interview to gather requirements for a fictional app that helps organize community events. Summarize the requ
nt by end of Module.
Learners will gain a solid grasp of the Software Development Life Cycle
(SDLC), covering its core phases: Requirements, Design, Implementation,
Testing, and Deployment.
s, Design, Implementation, Testing, Deployment), highlighting the importance of each phase and how they interconnect.
a fictional app that helps organize community events. Summarize the requirements and how you would document and trace them in a one
Day
Day 3
4:: Develop a log monitoring script to alert on certain conditions.
Combine scripts into a maintenance suite with a menu to execute
them.
Day 5: Test scripts and add error handling and logging functionalities.