Force probing of SPI device - linux-kernel

On my custom board based on STM32MP1, I would like to arrange an expansion connector for add some feature (ex. GPIO expander, Canbus, ...)
At the moment in my DTB I've defined the SPI port as "generic,spidev":
spidev1_0: spi5#0 {
compatible = "generic,spidev";
reg = <0>;
spi-max-frequency = <1000000>;
};
But my idea is to change compatible entry at runtime, something like:
rmmod spidev
echo "mcp3204" > /sys/...../i_dont_know_were/spiXX/compatible
modprobe mcp3204
This is only an example of my idea. Is possible to do something like that?
I would like to exclude the using of device tree overlay for boottime reason, and
I would like to exclude device tree editing for some other reason.

Related

Bypass proc_dointvec_minmax in kernel to allow other values

I am looking for a way to bypass a limit that is implemented the same way as the following
kexec_load_disabled:
{
.procname = "kexec_load_disabled",
.data = &kexec_load_disabled,
.maxlen = sizeof(int),
.mode = 0644,
/* only handle a transition from default "0" to "1" */
.proc_handler = proc_dointvec_minmax,
.extra1 = &one,
.extra2 = &one,
},
I have root access and I can load kernel modules aswell. I can use /proc/kallsymsto find the address of proc_dointvec_minmax, so I suppose I can somehow manage to write a kernel module that when loaded is able to overwrite the function so it allows going back to 0 again, then set the value to 0 and restore the original instructions? I assume I need to reconfigure the MMU first to allow writes to the kernel instructions? Or can I somehow add a breakpoint in proc_dointvec_minmax so that when it's hit I grab the arguments and modify those? Once I have a starting point I should be able to continue on my own, but right now I am not sure about what approach to choose/what the easiest way to solve it would be.

optional vertexbufferobjects in directx11

I have some models (geometries) which have some vertexinformation. For example position, normal, color, texcoord each of this information has its own vertexbuffer. But some of these models have texture coordinates some not...
To manage these differences I wrote a vertexshader which is checking, if the flag inside the constantbuffer "hasTextureCoordinates" is == 1. And if so it uses the texcoord parameter or not.
But Directx does not realy like this workaround and prints out:
D3D11 INFO: ID3D11DeviceContext::Draw: Element [3] in the current Input Layout's declaration references input slot 3, but there is no Buffer bound to this slot. This is OK, as reads from an empty slot are defined to return 0. It is also possible the developer knows the data will not be used anyway. This is only a problem if the developer actually intended to bind an input Buffer here. [ EXECUTION INFO #348: DEVICE_DRAW_VERTEX_BUFFER_NOT_SET]
I'm not sure if every hardware handles this correctly, also it's not nice to see inside the output this "warnings" every frame...
I know i could write two shaders, one with and one without texcoods, but the problem is that this is not the only maybe missing parameter... some has color other not, some has color and texturecoordinates and so on. And to write a shader for each combination of vertexbuffer inputs is extremly redundant. this is extremly bad, because if we change one shader, we have to change all other too. There is also the possibility of put parts of the shader to different files and include them, but it's confusing.
Is there a way to say directx that the specific vertexbuffer is optional?
Or does someone knows a better solution for this problem?
You can suppress this specific message programmatically. As it's an INFO rather than an ERROR or CORRUPTION message, it's safe to ignore.
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
ComPtr<ID3D11Debug> d3dDebug;
if ( SUCCEEDED( device.As(&d3dDebug) ) )
{
ComPtr<ID3D11InfoQueue> d3dInfoQueue;
if ( SUCCEEDED( d3dDebug.As(&d3dInfoQueue) ) )
{
#ifdef _DEBUG
d3dInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_CORRUPTION, true );
d3dInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_ERROR, true );
#endif
D3D11_MESSAGE_ID hide[] =
{
D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS,
D3D11_MESSAGE_ID_DEVICE_DRAW_VERTEX_BUFFER_NOT_SET, // <--- Your message here!
// Add more message IDs here as needed
};
D3D11_INFO_QUEUE_FILTER filter = {};
filter.DenyList.NumIDs = _countof(hide);
filter.DenyList.pIDList = hide;
d3dInfoQueue->AddStorageFilterEntries( &filter );
}
}
In addition to suppressing 'noise' messages, in debug builds this also causes the debug layer to generate a break-point if you do hit a ERROR or CORRUPTION message as those really need to be fixed.
See Direct3D SDK Debug Layer Tricks
Note I'm using ComPtr here to simplify the QueryInterface chain, and I assume you are keeping your device as a ComPtr<ID3D11Device> device as I do in in Anatomy of Direct3D 11 Create Device
I also assume you are using VS 2013 or later so that D3D11_INFO_QUEUE_FILTER filter = {}; is sufficient to zero-fill the structure.

How to see content of look up table

Imagine we have a simple code for fpga, I want to know if there is any way to watch content of specific lookUp table after synthesis, actually that data that will be written in SRAM
module test8(a,b,c
);
input a ;
input b ;
output c;
assign c = a&b;
endmodule
Simple AND gate
The possibility depends on the FPGA vendors tool.
Some tools has a GUI floor-plan view where the used LUTs can be found, and these LUTs can then have associated code attached for the memory contents of the LUT. In Altera Queatus Chip Planner it may look like:
Another option is to generate a netlist of the complete design, usually writable from the FPGA tool, and this netlist will then contain the LUTs together with code for the LUT contents. In Altera Quartus generated Verilog netlist it may look like:
...
// Location: LABCELL_X10_Y34_N0
cyclonev_lcell_comb \c~0 (
// Equation(s):
// \c~0_combout = ( \a~input0 & ( \b~input0 ) )
.dataa(gnd),
.datab(gnd),
.datac(!\b~input0 ),
.datad(gnd),
.datae(gnd),
.dataf(!\a~input0 ),
.datag(gnd),
.cin(gnd),
.sharein(gnd),
.combout(\c~0_combout ),
.sumout(),
.cout(),
.shareout());
// synopsys translate_off
defparam \c~0 .extended_lut = "off";
defparam \c~0 .lut_mask = 64'h000000000F0F0F0F;
defparam \c~0 .shared_arith = "off";
// synopsys translate_on
...
Note that the GUI view shows that the AND gate is not implemented using just a single simple LUT, since the tools has the freedom to implement it as it seems fit, as long as any timing and other requirements are observed.
But in the end, the specific implementation and considerations about LUT coding is usually ignored by the designer... except in special debugging cases.
I found vivado GUI for this Lookuptable

Write data to sdcard zedboard

I want to write data to zedboard's sdcard. I am able to write data to DRAM. Now I want to read DRAM's data and write it Sdcard. I have followed this (http://elm-chan.org/fsw/ff/00index_e.html) but it does not fulfill my requirement. I am not able to find any tutorial any example etc for this.
Please any tutorial link or any example. Thanks.
If you're using Vivado SDK, which I assume you are, it is really straightforward to use the SD Card.
To include the Fat File System, inside Xilinx SDK, open your Board Support Package (system.mss file) an select Modify this BSP's Settings. Under Overview, you can select xilffs.
Next, you must write the software to access the SD Card. This library offers a wide variety of functions. You can either look at here_1, in here_2 or in here_3. In this second reference is provided a wide variety of complex functions.
Aside from this, in order to use the SD Card, what you should basically do is written below. Note that this is just an overview, and you should refer to the references I gave you.
# Flush the cache
Xil_DCacheFlush();
Xil_DCacheDisable();
# Initialize the SD Card
f_mount(0, 0);
f_mount(0, <FATFS *>)
# Open a file using f_open
# Read and Write Operations
# Either use f_write or f_read
# Close your file with f_close
# Unmount the SD with f_mount(0,0)
Note that experience teaches me that you need to write to the file in blocks that are multiples of the block size of the file system, which for the FAT files syste, is typically 512 bytes. Writing less that 512 bytes and closing the file will make it zero bytes in length.
In new version of Xilffs (Fatfs) lib syntax is little changed.
New syntax is:
static FATFS FS_instance; // File System instance
const char *path = "0:/"; // string pointer to the logical drive number
static FIL file1; // File instance
FRESULT result; // FRESULT variable
static char fileName[24] = "FIL"; // name of the log
result = f_mount(&FS_instance, path, 0); //f_mount
result = f_open(&file1, (char *)fileName, FA_OPEN_ALWAYS | FA_WRITE); //f_open
May be this can help you.

IOServiceMatching on AppleUSBCDCACMData IOClass: Anomaly?

I am trying to extract a list of all AppleUSBCDCACMData IOClass devices in my mac using the following code snippet (just some small scale modifications in apple sample code). The device is a usb modem which creates some 7 /dev/cu.usbmodemx device nodes.
error = IOMasterPort(MACH_PORT_NULL, &masterPort);
if(error){
return ;
}
else{
matchingDict = IOServiceMatching("AppleUSBCDCACMData");
IOServiceGetMatchingServices(masterPort,matchingDict,&modem_iterator);
while(usbDevice = IOIteratorNext(modem_iterator))
{
}
My observation is, the iterator returned by IOServiceGetMatchingServices is empty (ie nothing to iterate on). But if i pass "AppleUSBCDCACMControl" as the parameter to IOServiceMatching, i get a iterator of a list of 7 elements - which is in conformance with the IORegistryExplorer view. See a screenshot of IORegistryExplorer here, http://tumblr.deepak.dk/post/1666218968/ioregistryexplorer
It appears that it is not possible to query IORegistry with arbitrary IOClass name strings? Since i faced the same issues with some non-standard proprietary IOClasses as well.
This can be reproduced using any USB modem (3g/HSDPA) which loads AppleUSBCDC driver.
What am i doing wrong?
IOService objects can only be matched once registerService() has been called for them. AppleUSBCDCACMControl does this, but AppleUSBCDCACMData does not.

Resources