Linux Kernel Programming

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linux Kernel Programming

Linux Kernel Programming

Linux Kernel Developing

U-boot and Kernel Compilation

  1. Get right toolchain for your platform.

            a. Ubuntu: sudo apt-get install gcc-arm-linux-gnueabi/gcc-arm-linux-gnueabihf

or

           b.  Get from linaro.org : wget -c https://releases.linaro.org/14.04/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2...

   2. Get U-boot code source

    1. git clone http://git.denx.de/u-boot-imx.git
    2. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- wandboard_quad_config
    3. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

   3. Get Kernel source with Wandboard support

    1. Wandboard repo:
      1. git clone https://github.com/wandboard-org/linux.git
      2. Select the right branch:
      3. git checkout wandboard_imx_3.10.17_1.0.0_beta    

                              or     

                           git checkout wandboard_imx_3.0.35_4.1.0

             b. Kernel Configuration ( load the wandboard  config )

                     make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- wandboard_defconfig

                                    or

                           make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig

             c. Kernel Compilation

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

     4. Prepare the sdcard:

            I. Copy the u-boot on the sdcard

      1. Determine the sdcard device name : sudo df -h
      2. sudo umount /dev/sdd*
      3. sudo dd if=/<path>/u-boot.imx of=/dev/sdd bs=512 seek=2

          II. Partitionating the sdcard

    • sudo fdisk /dev/sdd
      • o
      • n
      • p
      • 1
      • 2048
      • +1G
      • t
      • c
      • n
      • p
      • 2
      • 12288
      • +5G
      •   P
    • sudo mkfs.vfat -n KERNEL /dev/sdd1
    • sudo mkfs.ext3 -L RFS /dev/sdd2
    • cd /media/
    • sudo mkdir KERNEL
    • sudo mkdir RFS
    • sudo mount /dev/sdd1 KERNEL/
    • v. sudo mount /dev/sdd2 RFS/

         |||. Download a RFS and put on the sdcard

IV. Setup the u-boot:

    • run loadimage
    • run loadfdt
    • setenv bootargs console=ttymxc0,115200 root=/dev/mmcblk0p2 rootwait rw
    • bootz ${loadaddr} - ${fdt_addr}

Kernel devices

Realise a kernel device controlled from user space. The following steps will be done on the virtual machine.

NEEDED: Get the Virtual Box softwarte:  https://www.virtualbox.org/wiki/Downloads

  1. Realize a kernel device which prints “Hello World” starting from you’re the attached code.

   a . First determine the kernel version from target platform:

    • uname –a
    • Get the kernel sources or kernel headers using one of the following methods. On the current virtual machine this step is already done.
      • For kernel headers: sudo apt-get install linux-headers-$(uname -r)
      • For kernel sources:
        • sudo apt-get install linux-source

   b. Now go to the directory tasks/kernel. Create a function void hello() which prints “Hello World”.  It should be called when the device is inserted.

   c.  Compile the module : make

   d.  Insert the module on the virtual machine : insmod lec_cdev.ko

   e.  See if the module  is inserted

    • lsmod
    • dmesg

   f. Remove the kernel module :  rmmod lec_cdev.ko

   2. Create the device lec_cdev using  mknod  /dev/lec_cdev c 243 0

   3. Implement the read function of the device in order to have the following effect:

  1. cat /dev/lec_cdev =>  print to infinit “a”
  2. Modify the previous module in order to be commanded using ioctl from userspace.
    1. In function lec_cdev_ioctl  detect the command sent  from userspace and

If command is

  • MY_IOCTL_HELLO prints “HELLO WORLD”;
  • MY_IOCTL_SET_BUFFER – prints the buffer received from userspace.
  • MY_IOCTL_GET_BUFFER – prints the data from the char device driver buffer
        HINT: use functions 
* copy_to_user(user_buffer, kernel_buffer, size)
* copy_from_user(kernel_buffer, user_buffer , size)
 
Labels (1)
%3CLINGO-SUB%20id%3D%22lingo-sub-1113069%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELinux%20Kernel%20Programming%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1113069%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%20align%3D%22center%22%20style%3D%22text-align%3A%20center%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2014pt%3B%22%3E%3CSTRONG%3ELinux%20Kernel%20Developing%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EU-boot%20and%20Kernel%20Compilation%20%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3CLI%3EGet%20right%20toolchain%20for%20your%20platform.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20a.%20Ubuntu%3A%20%3CSTRONG%3Esudo%20apt-get%20install%20gcc-arm-linux-gnueabi%2F%3CSTRONG%3Egcc-arm-linux-gnueabihf%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%20style%3D%22margin-left%3A%201.0in%3B%22%3E%3CSTRONG%3Eor%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSTRONG%3E%20b.%26nbsp%3B%20Get%20from%20linaro.org%3CSTRONG%3E%20%3A%20%3C%2FSTRONG%3E%3CCODE%3E%3CSPAN%20style%3D%22font-size%3A%2010.5pt%3B%22%3E%3CSTRONG%3E%3CSPAN%3Ewget%20-c%20%3C%2FSPAN%3E%3CA%20class%3D%22jive-link-external-small%22%20href%3D%22https%3A%2F%2Freleases.linaro.org%2F14.04%2Fcomponents%2Ftoolchain%2Fbinaries%2Fgcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Freleases.linaro.org%2F14.04%2Fcomponents%2Ftoolchain%2Fbinaries%2Fgcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%202.%20Get%20U-boot%20code%20source%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3CLI%3Egit%20clone%20%3CA%20href%3D%22http%3A%2F%2Fgit.denx.de%2Fu-boot-imx.git%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20background%3A%20white%3B%22%3E%3C%2FSPAN%3E%3C%2FA%3E%3CA%20href%3D%22http%3A%2F%2Fgit.denx.de%2Fu-boot-imx.git%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22test_blank%22%3Ehttp%3A%2F%2Fgit.denx.de%2Fu-boot-imx.git%3C%2FA%3E%3C%2FLI%3E%3CLI%3Emake%20ARCH%3Darm%20CROSS_COMPILE%3Darm-linux-gnueabi-%20wandboard_quad_config%3C%2FLI%3E%3CLI%3Emake%20ARCH%3Darm%20CROSS_COMPILE%3Darm-linux-gnueabi-%3C%2FLI%3E%3C%2FOL%3E%3C%2FOL%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%203.%20Get%20Kernel%20source%20with%20Wandboard%20support%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3CLI%3EWandboard%20repo%3A%3COL%20style%3D%22list-style-type%3A%20lower-roman%3B%22%3E%3CLI%3E%3CSTRONG%3Egit%20clone%20%3C%2FSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fwandboard-org%2Flinux.git%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3E%3CSTRONG%3E%3C%2FSTRONG%3E%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fwandboard-org%2Flinux.git%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22test_blank%22%3Ehttps%3A%2F%2Fgithub.com%2Fwandboard-org%2Flinux.git%3C%2FA%3E%3C%2FLI%3E%3CLI%3ESelect%20the%20right%20branch%3A%3C%2FLI%3E%3CLI%3E%3CSTRONG%3Egit%20checkout%20wandboard_imx_3.10.17_1.0.0_beta%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20or%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20git%20checkout%20wandboard_imx_3.0.35_4.1.0%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20b.%20Kernel%20Configuration%20%3CSTRONG%3E(%20load%20the%20wandboard%26nbsp%3B%20config%20)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%20style%3D%22margin-left%3A%20.25in%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CSTRONG%3Emake%20ARCH%3Darm%20CROSS_COMPILE%3Darm-linux-gnueabi-%20wandboard_defconfig%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CSTRONG%3Eor%20%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CSTRONG%3Emake%20ARCH%3Darm%20CROSS_COMPILE%3Darm-linux-gnueabi-%20menuconfig%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20c.%20Kernel%20Compilation%3C%2FP%3E%3CP%20style%3D%22margin-left%3A%201.0in%3B%22%3E%3CSTRONG%3Emake%20ARCH%3Darm%20CROSS_COMPILE%3Darm-linux-gnueabi-%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%204.%20Prepare%20the%20sdcard%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I.%3CSTRONG%3E%20Copy%20the%20u-boot%20on%20the%20sdcard%3C%2FSTRONG%3E%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3CLI%3EDetermine%20the%20sdcard%20device%20name%20%3A%20sudo%20df%20-h%3C%2FLI%3E%3CLI%3Esudo%20umount%20%2Fdev%2Fsdd*%3C%2FLI%3E%3CLI%3Esudo%20dd%20if%3D%2F%3CPATH%3E%2Fu-boot.imx%20of%3D%2Fdev%2Fsdd%20bs%3D512%20seek%3D2%3C%2FPATH%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FOL%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20II.%20%3CSTRONG%3EPartitionating%20the%20sdcard%20%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CUL%3E%3CLI%3Esudo%20fdisk%20%2Fdev%2Fsdd%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3Eo%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3En%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3Ep%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E1%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E2048%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E%2B1G%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3Et%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3Ec%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3En%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3Ep%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E2%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E12288%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E%2B5G%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E%26nbsp%3B%20P%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3Esudo%20mkfs.vfat%20-n%20KERNEL%20%2Fdev%2Fsdd1%3C%2FLI%3E%3CLI%3Esudo%20mkfs.ext3%20-L%20RFS%20%2Fdev%2Fsdd2%3C%2FLI%3E%3CLI%3Ecd%20%2Fmedia%2F%3C%2FLI%3E%3CLI%3Esudo%20mkdir%20KERNEL%3C%2FLI%3E%3CLI%3Esudo%20mkdir%20RFS%3C%2FLI%3E%3CLI%3Esudo%20mount%20%2Fdev%2Fsdd1%20KERNEL%2F%3C%2FLI%3E%3CLI%3Ev.%20sudo%20mount%20%2Fdev%2Fsdd2%20RFS%2F%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7C%7C%7C.%20Download%20a%20RFS%20and%20put%20on%20the%20sdcard%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CUL%3E%3CLI%3E%3CSTRONG%3E%20%3CCODE%3E%3CSPAN%20style%3D%22font-size%3A%2010.5pt%3B%22%3Ewget%20-c%20%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Frcn-ee.net%2Fdeb%2Fminfs%2Fwheezy%2Fdebian-7.5-minimal-armhf-2014-07-07.tar.xz%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.5pt%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%3CSTRONG%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Frcn-ee.net%2Fdeb%2Fminfs%2Fwheezy%2Fdebian-7.5-minimal-armhf-2014-07-07.tar.xz%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22test_blank%22%3Ehttps%3A%2F%2Frcn-ee.net%2Fdeb%2Fminfs%2Fwheezy%2Fdebian-7.5-minimal-armhf-2014-07-07.tar.xz%3C%2FA%3E%3C%2FLI%3E%3CLI%3Esudo%20tar%20-xvf%20debian-7.5-minimal-armhf-2014-07-07.tar.xz%26nbsp%3B%20-C%20RFS%2F%3C%2FLI%3E%3CLI%3EPut%20the%20dtb%20file%20and%20zImage%20on%20the%20sdcard%20(%20KERNEL%20partition%20).%3C%2FLI%3E%3CLI%3Esudo%20cp%20%3CKERNEL_PATH%3E%2Farch%2Farm%2Fboot%2FuImage%20%2Fmedia%2FKERNEL%3C%2FKERNEL_PATH%3E%3C%2FLI%3E%3CLI%3Esudo%20cp%20%3CKERNEL_PATH%3E%2Farch%2Farm%2Fboot%2Fimx6q_wandboard.dtb%20%2Fmedia%2FKERNEL%3C%2FKERNEL_PATH%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSTRONG%3EIV.%20Setup%20the%20u-boot%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CUL%3E%3CLI%3Erun%20loadimage%3C%2FLI%3E%3CLI%3Erun%20loadfdt%3C%2FLI%3E%3CLI%3Esetenv%20bootargs%20console%3Dttymxc0%2C115200%20root%3D%2Fdev%2Fmmcblk0p2%20rootwait%20rw%3C%2FLI%3E%3CLI%3Ebootz%20%24%7Bloadaddr%7D%20-%20%24%7Bfdt_addr%7D%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EKernel%20device%3C%2FSTRONG%3Es%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ERealise%20a%20kernel%20device%20controlled%20from%20user%20space.%20The%20following%20steps%20will%20be%20done%20on%20the%20virtual%20machine.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CSPAN%3ENEEDED%3A%20Get%20the%20Virtual%20Box%20softwarte%3A%26nbsp%3B%20%3C%2FSPAN%3E%3CA%20class%3D%22jive-link-external-small%22%20href%3D%22https%3A%2F%2Fwww.virtualbox.org%2Fwiki%2FDownloads%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fwww.virtualbox.org%2Fwiki%2FDownloads%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%3CLI%3ERealize%20a%20kernel%20device%20which%20prints%20%E2%80%9CHello%20World%E2%80%9D%20starting%20from%20you%E2%80%99re%20the%20attached%20code.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20a%20.%20First%20determine%20the%20kernel%20version%20from%20target%20platform%3A%3C%2FP%3E%3CUL%20style%3D%22list-style-type%3A%20disc%3B%22%3E%3CUL%20style%3D%22list-style-type%3A%20circle%3B%22%3E%3CLI%3Euname%20%E2%80%93a%3C%2FLI%3E%3CLI%3EGet%20the%20kernel%20sources%20or%20kernel%20headers%20%3CSTRONG%3Eusing%20one%20of%20the%20following%20methods%3C%2FSTRONG%3E.%20%3CSPAN%20style%3D%22color%3A%20red%3B%22%3EOn%20the%20current%20virtual%20machine%20this%20step%20is%20already%20done%3C%2FSPAN%3E.%3CUL%20style%3D%22list-style-type%3A%20disc%3B%22%3E%3CLI%3EFor%20kernel%20headers%3A%20%3CSTRONG%3Esudo%20apt-get%20install%20linux-headers-%24(uname%20-r)%3C%2FSTRONG%3E%3C%2FLI%3E%3CLI%3EFor%20kernel%20sources%3A%3CUL%3E%3CLI%3E%3CSTRONG%3Esudo%20apt-get%20install%20linux-source%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20b.%20Now%20go%20to%20the%20directory%20%3CSTRONG%3Etasks%2Fkernel.%20%3C%2FSTRONG%3ECreate%20a%20function%20void%20hello()%20which%20prints%20%E2%80%9CHello%20World%E2%80%9D.%26nbsp%3B%20It%20should%20be%20called%20when%20the%20device%20is%20inserted.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20c.%26nbsp%3B%20Compile%20the%20module%20%3A%20make%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%22%3E%26nbsp%3B%26nbsp%3B%20d.%26nbsp%3B%20Insert%20the%20module%20on%20the%20virtual%20machine%20%3A%20insmod%20lec_cdev.ko%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20e.%26nbsp%3B%20See%20if%20the%20module%26nbsp%3B%20is%20inserted%3C%2FP%3E%3CUL%20style%3D%22list-style-type%3A%20disc%3B%22%3E%3CUL%3E%3CLI%3Elsmod%3C%2FLI%3E%3CLI%3Edmesg%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20f.%20Remove%20the%20kernel%20module%20%3A%26nbsp%3B%20rmmod%20lec_cdev.ko%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%202.%20Create%20the%20device%20lec_cdev%20using%26nbsp%3B%20mknod%26nbsp%3B%20%2Fdev%2Flec_cdev%20c%20243%200%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%203.%20Implement%20the%20read%20function%20of%20the%20device%20in%20order%20to%20have%20the%20following%20effect%3A%3C%2FP%3E%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3CLI%3Ecat%20%2Fdev%2Flec_cdev%20%3D%26gt%3B%26nbsp%3B%20print%20to%20infinit%20%E2%80%9Ca%E2%80%9D%3C%2FLI%3E%3CLI%3EModify%20the%20previous%20module%20in%20order%20to%20be%20commanded%20using%20ioctl%20from%20userspace.%3COL%20style%3D%22list-style-type%3A%20lower-alpha%3B%22%3E%3CLI%3EIn%20function%20%3CSTRONG%3Elec_cdev_ioctl%3C%2FSTRONG%3E%26nbsp%3B%20detect%20the%20command%20sent%26nbsp%3B%20from%20userspace%20and%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%20style%3D%22margin-left%3A%201.75in%3B%20text-align%3A%20justify%3B%22%3EIf%20command%20is%3C%2FP%3E%3CUL%20style%3D%22list-style-type%3A%20disc%3B%22%3E%3CLI%3EMY_IOCTL_HELLO%20prints%20%E2%80%9CHELLO%20WORLD%E2%80%9D%3B%3C%2FLI%3E%3CLI%3EMY_IOCTL_SET_BUFFER%20%E2%80%93%20prints%20the%20buffer%20received%20from%20userspace.%3C%2FLI%3E%3CLI%3EMY_IOCTL_GET_BUFFER%20%E2%80%93%20prints%20the%20data%20from%20the%20char%20device%20driver%20buffer%3C%2FLI%3E%3C%2FUL%3E%3CPRE%20style%3D%22text-align%3A%20justify%3B%20background%3A%20%23F7F9FA%3B%20padding%3A%206.0pt%206.0pt%206.0pt%206.0pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CSTRONG%3EHINT%3C%2FSTRONG%3E%3A%20use%20functions%20%3C%2FPRE%3E%3CPRE%20style%3D%22text-align%3A%20justify%3B%20background%3A%20%23F7F9FA%3B%20padding%3A%206.0pt%206.0pt%206.0pt%206.0pt%3B%22%3E*%20c%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3Eopy_to_user%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E(%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3Euser_buffer%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3E%20kernel_buffer%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3E%20size)%3C%2FSPAN%3E%3C%2FPRE%3E%3CPRE%20style%3D%22text-align%3A%20justify%3B%20background%3A%20%23F7F9FA%3B%20padding%3A%206.0pt%206.0pt%206.0pt%206.0pt%3B%22%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3E*%20copy_from_user%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E(%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3Ekernel_buffer%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23333333%3B%22%3E%20user_buffer%20%2C%20size%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%2366cc66%3B%22%3E)%3C%2FSPAN%3E%3C%2FPRE%3E%3CPRE%20style%3D%22text-align%3A%20justify%3B%20background%3A%20%23F7F9FA%3B%20padding%3A%206.0pt%206.0pt%206.0pt%206.0pt%3B%22%3E%20%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1113069%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3ELinux%20Embedded%20Challenge%202014%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
No ratings
Version history
Last update:
‎09-10-2020 02:20 AM
Updated by: