📄 main.cpp
字号:
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
FILE *fp;
int fd;
int file_size;
int flash_block;
if(argc < 3)
{
printf("Usage:\nFlash_Writter image_to_written num_Flash_block\n");
return 0;
}
// Check whether the image file exists...
fd = open(argv[1], _O_RDONLY);
if(fd < 0)
{
printf("Open image file error !!\n");
return 0;
}
file_size = filelength(fd);
printf("Image size:%d\n\n", file_size);
close(fd);
// Check whether the flash block number legal...
flash_block = atoi(argv[2]);
if(flash_block < 0 || flash_block > 4096)
{
printf("Invalid flash block number !!\n");
printf("Legal range is 0 ~ 4096\n");
return 0;
}
// Generate script...
printf("Begin to generate script file...\n");
fp = fopen("script.txt", "w");
if(fp == NULL)
{
printf("Open file error !!\n");
return 0;
}
// reset the CPU, using software reset instead of hardware reset
// which could let CPU halt precisely in 0x00000000
fprintf(fp, "rsettype 6\n");
fprintf(fp, "r\n");
// set CPU @ max speed
fprintf(fp, "speed 12000\n\n");
// Write Flash_Writter program into CPU
fprintf(fp, "loadbin Flash_Writter.bin 0x00000000\n\n");
// Write image to SDRAM
fprintf(fp, "loadbin %s 0x30000000\n", argv[1]);
// Write "1" to let the flash_writter go
fprintf(fp, "w4 0x00000FF4 0x%x\n", 1);
// Write destination Flash block number...
fprintf(fp, "w4 0x00000FF8 0x%X\n", flash_block);
// Write file size...
fprintf(fp, "w4 0x00000FFC 0x%X\n\n", file_size);
// Show the memory content...
fprintf(fp, "mem 0xFF8 8\n");
// Set PC to desired position...
fprintf(fp, "setpc 0x00000000\n");
// Let the program run....
fprintf(fp, "go\n");
// Exit J-Link command shell
fprintf(fp, "exit\n");
fclose(fp);
// Call J-link command shell to exec the script...
system("JLink script.txt\n");
//system("pause\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -