I am trying to come up to speed on writing device drivers for embedded Linux, specifically a V4L2 Media Controller driver for a video interface.
I can write the device driver using the typical V4L2 model for a non-builtin driver, that is, a module controlled by modprobe. When the module is loaded the __init function for this driver is called, and this then creates a node in the /dev directory showing up as /dev/video0. I can then write user-side programs which starts by opening /dev/video0 and I can now exercise all the driver code I've written. I understand this model and so I have a nice development environment where I can modify the driver code, reload the .ko driver, modify my user-side test code, and basically exercise all my driver functionality.
However, I am still confused about the builtin drivers when using the Media Controller and platform_device model for drivers. (These don't have a specific __init routine and are not loaded dynamically). I can configure my kernel to build my driver as a builtin Media Controller-based driver. I have all of the Kconfig files correct so I can now include my new driver in a kernel build. I know my driver is builtin correctly, because when my kernel boots, I can see my driver in the /sys/bus/platform/drivers directory. This directory has 3 write-only nodes for bind, uevent and unbind.
This is my confusion: How do I open this builtin device driver from user-side code so I can exercise my driver interface?
Since the driver is a builtin Media Controller-based driver, a new device node is not created in /dev when the kernel boots, or at least, I do not know WHAT device to open like I did for the module-based driver.
Do I have to write some udev rules to cause the kernel to create the device node in /dev directory so I can use a user-side open()? or is this driver accessed in a different way?
Thanks,
-Andres
If your driver based on media controller framework, there should be a pipeline (refer) have you implemented that in your driver refer media controller api. Even if your driver is builtin and is based on media controller framework it should still create /dev/video0. The reason I can think of video0 node not being created is missing subdev driver.
Related
I've just started to study UEFI development, as a playground I've got a custom AARCH64 platform with EDK2-based sources provided for building full firmware image (to be burned into flash).
"Hello world" in DXE driver is already done, so I've selected a practical task: to include iPXE into firmware to avoid chain loading.
The idea is to build iPXE EFI application and put it into firmware volume.
Then I hope to be able to call it from UEFI shell, the final step is to add it to boot manager.
And here I stuck: I can't find any information on how to add EFI application to FV.
Please advise if it possible at all and where to read about it.
Thank you!
Okay, the solution was close in this inf file: https://github.com/tianocore/edk2-non-osi/blob/master/Drivers/Realtek/Bus/Usb/UsbNetworking/RtkUsbUndiDxe.inf
I've put pre-compiled ipxe.efi and now it's included in firmware volume.
I am attempting to upload my written program for the STM32F411RE from my TrueStudio for STM32 IDE to the board itself. The board is connected via the mini USB b cable and the intent is to program it via SWD.
Setup
Atollic provides a nice tutorial on how to perform this programming via it's TrueStudio IDE and the ST-Link_CLI (Command Line Interface), as described in the document at this link. This requires the following steps, which I have followed and checked multiple times:
First and foremost the output (binary) file needs to be an intel .HEX and
not the TrueStudio .elf default. To change this go to Project properties -> c/c++ build -> settings -> tool settings tab -> other -> Output format
and tick the option 'Convert build output', ensure that the Intel Hex
option is selected in the dropdown.
To call the ST-Link_CLI from inside the IDE requires making an external
tools configuration. To make this config I go to Run -> External Tools ->
External Tools Configurations .... and create a new configuration, lets
call it ST-Link_CLI. For the Working Directory I specify the directory of my ST-LINK_CLI
(C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility)
whilst for the Location I specify this directory and the file name
(C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK
Utility\ST-LINK_CLI.exe).
Lastly, I add the following parameters to
identify the STM32 board, have it connect via SWD and under reset, whilst
telling it to upload the .HEX file built by TrueStudio
(-c ID=0 SWD UR LPM -P ${project_loc}\Debug\${project_name}.hex -v).
Output
When I then call this external tool configuration via the Run -> External Tools -> ST-Link_CLI link just created I get the output listed below:
STM32 ST-LINK CLI v3.4.0.0
STM32 ST-LINK Command Line Interface
ST-LINK SN: 066EFF525750877267092042
ST-LINK Firmware version: V2J33M25
Connected via SWD.
SWD Frequency = 4000K.
Target voltage = 3.3 V
Connection mode: Connect Under Reset
Reset mode: Hardware reset
Debug in Low Power mode enabled
Device ID: 0x431
Device flash Size: 512 Kbytes
Device family: STM32F411xC/E
Loading file...
Unable to open file!
Clearly the ST-Link_CLI is succesfully called from inside the IDE, but it somehow cannot digest the .hex file (inside the debug folder) and upload it to the STM32 board.
Even flashing a completely new generated project from CubeMX and setting the options above (including setting it to a .hex file) will not let this toolchain upload it to the board.
Manual code flashing
I have been able to succesfully upload the .HEX file built by TrueStudio via manually uploading it to the STM32 Board with the use of the ST-Link GUI, so I do not think the problem is in the ST-Link itself. I cannot however debug it in this manner, since I need the TrueStudio IDE tools for that and thus need the external tool configuration to work succesfully.
Instead I suspect the issue lies with my own setup, where is somehow is missing a call or has an option set incorrectly. It could also be that the GUI and CLI clients operate in a completely different fashion allowing one to read and upload the file whilst the other cannot, but that seems unreasonable to me.
I am kind of at a loss here however, as I cannot seem to figure out why others can make this work via the provided Atollic documentation and mine is throwing up these errors.
You try to reinvent the wheel using the triangle.
Everything is configured in the TrueStudio:
Just in add the debug configuration and you are done.
What benefits would OpenOCD offer at this point
One essencial : debugging
given how much I have already learned about TrueStudio?
This knowledge (how to configure external tools etc) is rather useless in 99.9999% of circumstances. It is only the configuration of the Eclipse. Not too complex actually needed here.
In regards to my own code, I have not been able to get the ST-Link_CLI to work as an external tool the way I intended, [but I have been able to get the STCubeProgrammer (CLI) to work in the same respective manner as I was attempting to do with the ST-Link].(http://gotland.atollic.com/resources/applicationnotes/AN1801_cubeprogrammer_in_truestudio.pdf).
Seeing as I literally used the same procedure as before but instead specifying the location and executable for the STCubeProgrammer (rather than the ST-Link), I suspect the issue may indeed be the ST-Link CLI (connection to TrueStudio).
It now uploads successfully and immediately after boots me into the debug environment of TrueStudio :)
I simply commented "load" command in the startup script and debugging worked. I only had to load the hex using the st link first.
/# Load the program executable
#load <---//added "#"
I am using Petalinux, built with Yocto SDK. I want to automatically install my kernel module and make the devices available in /dev/*.
With KERNEL_MODULE_AUTOLOAD+="modulename" I can see the appropriate entries in /etc/modules-load.d/ as well as entries in /sys/class/misc/** , but not in /dev/*. Is there something I am missing?
Well, the structure of Yocto has nothing to do with the creation of device nodes. Either your driver does that for you (upon loading / probing), or you had some script that made them earlier. As long as your module has been loaded upon boot, you've got KERNEL_MODULE_AUTOLOAD correctly. If the module gets loaded, but you're not getting any device nodes automatically (and you got that before) you'll need to investigate what has changed in your system. (Versions of kernel and eg mdev/udev etc)
Can an EFI application be automatically loaded and executed before BDS phase, just after all the DXE drivers have been loaded?
If I include the application in .fdf file just after the DXE drivers, will it be automatically loaded and executed ?
This question is very board and I will only scratch the surface with my answer. Please read documentation that I mentioned to get more information.
If you have full source code of UEFI firmware for your hardware then you can add UEFI module to be executed before BDS phase. Otherwise you can affect only boot order (which is right before calling ExitBootServices) by adding UEFI Application using bcfg shell command, pleas check this question.
If you want to execute code before BDS it have to be DXE module (ie. DRIVER, RUNTIME_DRIVER). There are many module types that can be used and exact depend on your use case. More about module types you can find in Appendix G of INF file specification.
Adding to FDF file is not enough for code to be executed. FDF file describe only flash layout: how and where each binary would be placed in final flash image. To add DXE driver you also have to add your INF file to platform DSC file. Next thing is to have correct [Depex] section in INF, which can be as simple as:
[Depex]
TRUE
Last thing that you have to understand is DXE Dispatcher. Each boot DXE Dispatcher iterate over know image list and and call EFI_DRIVER_BINDING_SUPPORTED function (defined by EFI_DRIVER_BINDING_PROTOCOL). This method should check if supported hardware is available in platform. If EFI_DRIVER_BINDING_SUPPORTED return success then other driver binding method will be called (EFI_DRIVER_BINDING_START), which starts device. Entry point should be used only for protocol registration, starting device in entry point is not recommended.
Useful resources:
EDK II Specifications - specs for various file types (INF, FDF, DSC, DEC, etc.)
Developer Resources - Drivers Writers Guide and Drivers Wizard.
EDK2 sourceforge - repository of very useful resources about EDK2
I have an STM3220g-EVAL board. It doesn't seem to have a preloaded image in it now, as it was used for other purposes.
When I power it on, the display is shown blank.
I dont have a STLINK/V2 hardware. I am using Trace32 and Lauterbach for flashing and debugging the code.
I created a simple C program, created an elf file by using arm-none-eabi-gcc toolchain, and was able to flash it into the STM3220g-EVAL board using a cmm script for stm32 provided in demo folder of Trace32.
What I require is to flash default image for STM3220g-eval using Trace32.
Can someone provide me the link to get the boot image and cmm script to flash the same.
I tried the demonstration builder platform and demonstration firmware provided in the following link
http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/PF250374
As they are providing hex file, I used Trace 32 command data.load.asciihex to load the hex file. When I press go, am getting error( emulation poer fail).
Can somesome provide me the correct cmm script to flash the .hex file to the board.
If I understand you correctly you are trying to flash the "STM3220G-EVAL demonstration firmware" on your STM3220G-EVAL board.
So the hex-file you are talking about is "STM322xG_EVAL_FW_V1.2.0.hex", right?
This hex-file is in Intel HEX file format. (See https://en.wikipedia.org/wiki/Intel_HEX)
To load a file in Intel HEX format, you should use Data.LOAD.IntelHex
So this is how to flash the file in your CPU:
Select your CPU with SYStem.CPU STM32F207IG
Connect to your CPU with SYStem.Up
Prepare flash-programming with DO ~~/demo/arm/flash/stm32f2xx.cmm PREPAREONLY
Arm flash programming with FLASH.ReProgram ALL
Load your Intel Hex file with Data.LOAD.IntelHex STM322xG_EVAL_FW_V1.2.0.hex
Finalize flash programming with FLASH.ReProgram OFF (This will start the actual programming.)
The STM3220 comes with the STLink hardware built in via the USB port. See section 2.20 from here
Version 2 of the ST-LINK, called ST-LINK/V2, is embedded on the board.
This tool allows onboard program loading and debugging of the STM32F
using the JTAG or SWD interface. Third-party debug tools are also
supported by the JTAG (CN14) or Trace (CN13) connectors. To
communicate with the embedded ST-LINK/V2, a specific driver needs to
be installed on your PC. To download and install this driver, refer
to the software and development tools page for the STM32F family
available on www.st.com (the install shield is called
ST-LINK_V2_USBdriver.exe).