KernelDriverProgrammingCourse2015/OutlineDay1

From RevSpace
Revision as of 11:43, 23 August 2015 by Luteijn (talk | contribs) (→‎Kernel Driver Programming Course Day 1: added username/password for logins)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Kernel Driver Programming Course Day 1

  1. Intro
    1. Welcome
    2. End goal of this course is to have you all working on projects like these
    3. I'm going to dump a lot of information on you, don't worry you do not need to remember it all :)
    4. Quickly explain of different Axx models
    5. A10 Datasheet Block diagram (page 12), give a quick overview of the A10
  2. A10 SoC dtsi file (example)
    1. sun4i-a10.dtsi
    2. For a list of addresses see the A10 user manual, section 3.2 "Memory mapping", and 11.2 "Interrupt Source"
    3. For clock tree info see: A10 Datasheet Clock tree diagram (pages 51 - 54)
  3. dts file example for a simple board
    1. sun4i-a10-mini-xplus.dts
    2. fex file for the mini-x board
  4. Hands on 1: Build and install u-boot and a dts file and boot the board
    1. Everyone gets a board, a usb to serial convertor and a sdcard
    2. Build and install u-boot:
      1. Figure out the config to use for your board, do:
        cd u-boot
        grep -l SUNXI configs/*_defconfig
      2. Build u-boot for your board, do:
        make -j4 CROSS_COMPILE=arm-linux-gnu- $foo_defconfig
        make -j4 CROSS_COMPILE=arm-linux-gnu-
      3. Insert the provided sdcard into your laptop
      4. Figure out which blockdev it has been given, do:
        dmesg | tail
      5. Install u-boot by dd-ing it to the whole device (not a partition) blockdev, e.g.:
        sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdc bs=1024 seek=8
      6. Flush buffers: sync
      7. Move sdcard to the target board
    3. Boot the board:
      1. Plug a usb to serial convertor into your laptop
      2. Figure out which ttyUSB# it has been given, do:
        dmesg | tail
      3. Start screen on the ttyUSB# in question, e.g.:
        screen /dev/ttyUSB0 115200
      4. Power up the board, and check that it boots properly in the screen session
    4. Build and install your own dts file:
      1. Edit the dts file for your board:
        cd linux
        $editor arch/arm/boot/dts/sun?i-a??-$board.dts
      2. At the top of the file you will see e.g. "model = "PineRiver Mini X-Plus"; This is a free format string, change the model string to something else, e.g. "Hans' test board" and then save the file
      3. Now build a dtb file from the dts file:
        make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnu- dtbs
      4. Then install the dtb file, insert the sdcard into your laptop, mount the first partition of it, and copy arch/arm/boot/dts/sun?i-a*-*.dtb to the dtb directory, e.g.:
        sudo cp -pr arch/arm/boot/dts/sun?i-*.dtb /run/media/hans/__boot/dtb/
      5. Boot the board again, login and do:
        cat /sys/firmware/devicetree/base/model
        to verify that your modified dtb file is being used (root/fedora user/user)
  5. Adding support for the musb otg controller to a sunxi dts file
    1. See the commit enabling it on the A20 OLinuxino Lime as an example of the necessary changes
    2. See the A20 OLinuxino Lime schematic as an example how to figure out which gpios to use for vbus_det / id_det. Or alternatively look at the usbc0 section of the fex file for the board.
    3. Some boards are special and use the pmic instead of a gpio for vbus-det, see e.g. the bananapi fex file. For an example of how to deal with this in the dts file see the commit enabling the otg controller on the bananapi.
      1. These special boards need to use axp209.dtsi, so as to have the usb_power_supply node defined. This also means that they must enable the regulators which they need because including axp209.dtsi without enabling regulators explicitly will cause all axp209 regulators to get disabled leading to a non booting board. See this commit for an example of how to include axp209.dtsi and enable the minimum set of needed regulators. Please do an lsusb before and after doing this and make sure that if a wifi chip is listed in the before lsusb output, that it does not disappear after including axp209.dtsi. If the wifi chip does disappear it is connected to another regulator, see e.g. this dts file.
    4. Quick demo of how to test otg on a sunxi board
  6. Hands on 2: Enable the otg controller on the board you've
    1. Modify the dts file for your board in the same way as done in the provided examples
    2. Build and install the dts file as before
    3. Test the otg controller as demoed
  7. Hands on 3: Digging deeper
    1. For those of you who are done with handson 2, and would like to dig deeper here are some more features which need people to write patches to enable them in dts.
    2. Easy tasks:
      1. Use axp209.dtsi + enable the necessary regulators as described above under "Some boards are special and use the pmic ..." This will enable voltage scaling for the CPU core on these boards, after making the dts changes look for a regulator with name "DCDC2" under /sys/class/regulators, and check that when idle its voltage is aprox 1.0V and when you load the system by e.g. "md5sum /dev/urandom&" it goes up to 1.4V (as the cpu will scale up to its maximum frequency of 1GHz).
      2. Add and configure an lradc node to sun6i-a31-hummingbird.dts, to enable use of the home / back / menu keys of the development kit, see sun4i-a10-chuwi-v7-cw0825.dts (look for lradc) for an example.
      3. Add "codec" nodes to boards with an analog sound output, use mpg123 on the files under /root/Music to test, note the audio support is still in a bit of flux, so this may not work reliably while testing. See sun7i-a20-cubietruck.dts (look for codec) for an example.
    3. More challenging tasks:
      1. Modify u-boot to enable the lcd display of the A31 humminbird development kit
      2. Create u-boot configs for boards which do not have a u-boot config yet. I've several of these boards with me ask and I'll give you one and I'll also give a quick intro on what needs to be done
      3. Create kernel dts files for boards for which you've just created a u-boot config. If you do not want to create a u-boot config I've one board which already has a u-boot config, but lacks a kernel dts file.