hello.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <linux/init.h> // Macros used to mark up functions e.g., __init __exit
  2. #include <linux/module.h> // Core header for loading LKMs into the kernel
  3. #include <linux/kernel.h> // Contains types, macros, functions for the kernel
  4. MODULE_LICENSE("GPL"); ///< The license type -- this affects runtime behavior
  5. MODULE_AUTHOR("Derek Molloy"); ///< The author -- visible when you use modinfo
  6. MODULE_DESCRIPTION("A simple Linux driver for the BBB."); ///< The description -- see modinfo
  7. MODULE_VERSION("0.1"); ///< The version of the module
  8. static char *name = "world"; ///< An example LKM argument -- default value is "world"
  9. module_param(name, charp, S_IRUGO); ///< Param desc. charp = char ptr, S_IRUGO can be read/not changed
  10. MODULE_PARM_DESC(name, "The name to display in /var/log/kern.log"); ///< parameter description
  11. /** @brief The LKM initialization function
  12. * The static keyword restricts the visibility of the function to within this C file. The __init
  13. * macro means that for a built-in driver (not a LKM) the function is only used at initialization
  14. * time and that it can be discarded and its memory freed up after that point.
  15. * @return returns 0 if successful
  16. */
  17. static int __init helloBBB_init(void){
  18. printk(KERN_INFO "EBB: Hello %s from the BBB LKM!\n", name);
  19. return 0;
  20. }
  21. /** @brief The LKM cleanup function
  22. * Similar to the initialization function, it is static. The __exit macro notifies that if this
  23. * code is used for a built-in driver (not a LKM) that this function is not required.
  24. */
  25. static void __exit helloBBB_exit(void){
  26. printk(KERN_INFO "EBB: Goodbye %s from the BBB LKM!\n", name);
  27. }
  28. /** @brief A module must use the module_init() module_exit() macros from linux/init.h, which
  29. * identify the initialization function at insertion time and the cleanup function (as
  30. * listed above)
  31. */
  32. module_init(helloBBB_init);
  33. module_exit(helloBBB_exit);