|
楼主 |
发表于 2019-10-6 17:57:13
|
显示全部楼层
本帖最后由 brother_yan 于 2019-10-6 18:00 编辑
这个问题我也不太清楚原因。我发现把*.bin复制到U盘后U盘会自动弹出,我不清楚bootloader是如何判断的。下面是我的源码,exe文件是Dev-C++ 4.9.9.2编译的,你们有兴趣可以参考一下~
- #include <stdio.h>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- bool getVolume(char volume_name[], char path[]) // 根据卷名获取盘符
- {
- char drivers[1024];
- int len = 0;
- len = GetLogicalDriveStrings(1024, drivers);
-
- for (char *p = drivers; p - drivers < len; p += strlen(p) + 1)
- {
- char volumeName[1024] = {0};
- DWORD volumeSerialNumber = 0;
- DWORD fileSystemFlags = 0; // 文件系统标志
- DWORD maximumComponentLength; // 文件名最大长度
- char fileSystemNameBuffer[1024] = {0}; // 文件系统名称
-
- bool ret = GetVolumeInformation(p, volumeName, 1024, &volumeSerialNumber, &maximumComponentLength, &fileSystemFlags, fileSystemNameBuffer, 1024);
-
- if (ret)
- if (strcmp(volumeName, volume_name) == 0)
- {
- strcpy(path, p);
- return(true);
- }
- }
-
- return(false);
- }
- void copy(char src[], char dst[]) // 复制文件
- {
- static char buf[1024 * 1024];
- int size;
-
- FILE *f1 = fopen(src, "rb");
- FILE *f2 = fopen(dst, "wb");
- size = fread(buf, 1, 1024 * 1024, f1);
- fwrite(buf, 1, size, f2);
- fclose(f1);
- fclose(f2);
- }
- #define SetColor(x) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),(x))
- int main(int argc, char *argv[])
- {
- if (argc >= 3)
- {
- char path[1024] = "";
- bool r = getVolume(argv[2], path);
- if (r)
- {
- strcat(path, "firmware.bin");
- copy(argv[1], path);
- printf("download complete");
-
- return(1);
- }
- else
- {
- printf("fail to download");
-
- return(0);
- }
- }
- else
- {
- SetColor(0x0C);
- printf("brother_yan 出品\n");
- SetColor(0x0A);
- printf(
- "[ usage ]\n"
- "flash_download *.bin volume_name\n"
- );
- SetColor(0x07);
- }
-
- return(0);
- }
复制代码 |
|