Customizing the startup program that contains your minidriver code

This is the core of the minidriver development.

To implement a minidriver, the following steps are required:

  1. Modify mdriver_max.c in libstartup.

    (On your development host, this file is located in your workspace as part of your BSP files in a directory that ends with libstartup).

    By default, this value is set to 16KB (with a standard QNX 6.3.0 Board Support Package) and is the amount of data that is copied at one time when the boot image is copied from flash to RAM. The minidriver callout will be called after each copy. For example:

    minidriver callout
    copy next 16K
    minidriver callout
    copy next 16K
    etc.
    

    It may be necessary to modify this value. For example, on a MPC5200 running at 396 MHz, the time needed to copy 16KB is around 8 milliseconds. This will vary depending on the speed of the processor and the speed of the flash. If the mdriver_max is modified to be a 1KB copy value, then the time needed to copy this 1KB drops to less than 1 millisecond. The value of mdriver_max will need to be set based on experimentation.

    If mdriver_max.c is modified, be sure to recompile the libstartup.a library. Also, relink your startup code with this new library.

  2. Modify the necessary startup files and add in your minidriver code.

    The following files are modified in your startup code. They all exist in the same directory as your BSP startup code. For example, if you are building a BSP for the Media5200b board, you will have imported the BSP into QNX Momentics IDE (in to your workspace). The following files will change:

    • main.c — to call mdriver_add() for your callout
    • cpu_mdriver.c, mdriver.c — you can find these files in $QNX_TARGET/usr/src/archives/qnx/mdriver-base.zip; copy them to your startup directory, but don't change them.
    • mini-driver.c — the rest of the code is your mini-driver code, including the main handler function.

    See the examples in the Sample Drivers for Instant Device Activation chapter of this guide.

    Here are the highlights:

    main.c
    • Set the prototype for your minidriver callout function e.g.
      extern int mini_data(int state, void *data);		
      
    • Allocate a memory area for your data e.g.
      //Global
      paddr_t	mdriver_addr; // allocate 64K of memory 
                            // for use by the minidriver
      		      
      mdriver_addr = alloc_ram(~0L, 65536, 1);
      
    • Set your minidriver callout to be called. Do this after you call init_intrinfo() e.g.
      //Code to add a sample minidriver function 
      //called "mini-data" for irq=81 
      mdriver_add("mini-data", 81, mini_data, mdrvr_addr, 65536);	
      
    cpu_mdriver.c
    • Don't modify this file unless directed by QNX Software Systems.
    • Make sure this C file is included in your startup code directory
    mdriver.c
    • Don't modify this file unless directed by QNX Software Systems.
    • Make sure this C file is included in your startup code directory.
    mini-driver.c
    • This is your minidriver code. You can name this C file anything you wish. What is required is that the minidriver function defined in the mdriver_add() function be part of your startup code.
    • You may have multiple C and header files as part of your minidriver

    Try out one of the samples that is included with this package and build the new startup program (e.g. startup-mgt5200).