简体   繁体   English

如何使用linux i2c驱动到flash一个二进制

[英]How to use linux i2c driver to flash a binary

I was told to use this driver to flash a binary to some chip via I2C.我被告知要使用这个驱动程序来 flash 通过 I2C 到某个芯片的二进制文件。

I'm not interested in customizing the driver or modifying in any way really, I'm just hoping to learn enough to use the max77958_update_action_mtp function:我真的对自定义驱动程序或以任何方式修改不感兴趣,我只是希望能学到足够的知识来使用max77958_update_action_mtp function:

max77958_update_action_mtp(struct max77958_dev *max77958,
        const u8 *action_bin, int fw_bin_len)

to flash a binary ( action_bin ) to some i2c device ( max77958 ).到 flash 到一些 i2c 设备( max77958 action_bin

I am a complete noob to embedded development and c programming, but from what I can understand I need to manage the following:我是嵌入式开发和 c 编程的完全菜鸟,但据我所知,我需要管理以下内容:

  1. Include this driver in some other c file and resolve any missing dependencies (done)将此驱动程序包含在其他一些 c 文件中并解决任何缺少的依赖项(完成)
  2. Create some max77958_dev and pass the pointer to this function as the first argument.创建一些max77958_dev并将指向此 function 的指针作为第一个参数传递。
  3. Open the binary as a const u8 and pass the pointer as the second argument.作为const u8打开二进制文件并将指针作为第二个参数传递。

Have I misunderstood the steps I need to finish?我是否误解了我需要完成的步骤?

Assuming I have understood the steps I need to take correctly:假设我已经理解了我需要正确采取的步骤:

Step 1步骤1

I managed to find all the header files in my system under /usr/src/linux-headers-5.4.0-122-generic/ other than one called <linux/wakelock.h> which from what I can tell is some Android specific header, so I commented it out and will try to remove anything the compiler complains about as I shouldn't need anything Android related.我设法在我的系统中的/usr/src/linux-headers-5.4.0-122-generic/下找到所有 header 文件,而不是一个名为<linux/wakelock.h>的文件,据我所知,这是一些特定于 Android 的文件header,所以我将其注释掉,并将尝试删除编译器抱怨的任何内容,因为我不需要任何与 Android 相关的内容。

Step 2第2步

Does it look like there is some default max77958_dev struct that I can use?看起来我可以使用一些默认max77958_dev struct吗? Following the definition of the struct in VS Code, I can see its definition is located here but I'm too much of a noob in c to understand if something here helps me create a default max77958_dev struct with some default values or if I have to somehow know all of the correct values and create one myself.按照 VS Code 中结构的定义,我可以看到它的定义位于此处,但我在 c 中太菜鸟了,无法理解此处是否有什么东西可以帮助我创建具有一些默认值的默认max77958_dev结构,或者我是否必须这样做不知何故知道所有正确的价值观并自己创造一个。

I'm also quite oblivious as to how the Ubuntu PC would connect to this I2C device.我也完全不知道 Ubuntu PC 将如何连接到这个 I2C 设备。 I assume I can get some USB-2-I2C dongle from FTDI or the like, but how would my C code know to communicate via this dongle to the I2C slave?我假设我可以从 FTDI 或类似产品中获得一些 USB-2-I2C 加密狗,但是我的 C 代码如何知道通过这个加密狗与 I2C 从机进行通信?

Step 3第 3 步

I think I can figure out how to read in a binary file, but it seems strange that this is a const u8 .我想我可以弄清楚如何读取二进制文件,但这是一个const u8似乎很奇怪。 The binary is surely larger than 8 bits.二进制肯定大于 8 位。 Guessing this is a lack of understanding of pointers, but can someone clarify how exactly I should introduce a binary file to this function?猜测这是对指针缺乏了解,但有人可以澄清我应该如何将二进制文件引入这个 function 吗?

I was told to use this driver to flash a binary to some chip via I2C.我被告知要使用这个驱动程序来 flash 通过 I2C 到某个芯片的二进制文件。

From what I see this driver already pushes the firmware.据我所知,这个驱动程序已经推送了固件。 But if I have correctly understood you are going totally different direction.但是,如果我正确理解了您将走向完全不同的方向。 Trying to re-use some parts of the code from device driver in your user-space application is obviously not going to work.尝试在用户空间应用程序中重用设备驱动程序中的某些部分代码显然是行不通的。

Instead, build this driver as a module and load on your target machine with MAX77958 connected to one of its I2C busses.相反,将此驱动程序构建为一个模块并加载到您的目标机器上,并将 MAX77958 连接到其 I2C 总线之一。 How you can instantiate device is another question and is architecture dependent - if you are going to use Ubuntu on x86 you can do this manually from user-space .如何实例化设备是另一个问题,并且取决于架构 - 如果您要在 x86 上使用 Ubuntu 您可以从 user-space 手动执行此操作

On step 3: You pass a pointer to as many u8 as fw_bin_len says.在第 3 步:您将指针传递给fw_bin_len所说的尽可能多的u8 Such a pointer can point to a single byte, but also to the first of an array of bytes.这样的指针可以指向单个字节,也可以指向字节数组的第一个。 C cannot differentiate between such usages. C 无法区分这些用法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM