新手,做了一个boot裸机程序,使用keil编译器,编译了一个boot.bin文件,想烧录到spi flash中运行,步骤如下:
1.用gcc 将mksunxi.c生成mksunxi.exe
mksunxi.c代码如下:
struct boot_head_t {
uint32_t instruction;
uint8_t magic[8];
uint32_t checksum;
uint32_t length;
uint8_t spl_signature[4];
uint32_t fel_script_address;
uint32_t fel_uenv_length;
uint32_t dt_name_offset;
uint32_t reserved1;
uint32_t boot_media;
uint32_t string_pool[13];
};
#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
#define SUN4I_SRAM_SIZE (24 * 1024)
#define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(boot_file_head_t))
#define BLOCK_SIZE 2048
int main (int argc, char *argv[])
{
struct boot_head_t * h;
FILE * fp;
char * buffer;
int buflen, filelen;
uint32_t * p;
uint32_t sum;
int i, l, loop;
if(argc != 2)
{
printf("Usage: mksunxi <bootloader>\n");
return -1;
}
fp = fopen(argv[1], "r+b");
if(fp == NULL)
{
printf("Open bootloader error\n");
return -1;
}
fseek(fp, 0L, SEEK_END);
filelen = ftell(fp);
fseek(fp, 0L, SEEK_SET);
if(filelen <= sizeof(struct boot_head_t))
{
fclose(fp);
printf("The size of bootloader too small\n");
return -1;
}
buflen = ALIGN(filelen, BLOCK_SIZE);
buffer = malloc(buflen);
memset(buffer, 0, buflen);
if(fread(buffer, 1, filelen, fp) != filelen)
{
printf("Can't read bootloader\n");
free(buffer);
fclose(fp);
return -1;
}
h = (struct boot_head_t *)buffer;
p = (uint32_t *)h;
h->length = ALIGN(h->length, BLOCK_SIZE);//align block size
l = le32_to_cpu(h->length);
h->checksum = cpu_to_le32(0x5F0A6C39);
loop = l >> 2;
printf("bootloader size= %x\n", h->length);
for(i = 0, sum = 0; i < loop; i++)
sum += le32_to_cpu(p[i]);
h->checksum = cpu_to_le32(sum);
fseek(fp, 0L, SEEK_SET);
if(fwrite(buffer, 1, buflen, fp) != buflen)
{
printf("Write bootloader error\n");
free(buffer);
fclose(fp);
return -1;
}
fclose(fp);
printf("The bootloader head has been fixed\n");
return 0;
}
其中#define BLOCK_SIZE 2048 //原来是512,我改成了2048,因为我使用的flash 页读写是2048bytes,不知道是不是这个地方没改对?
2.使用mksunxi.exe 修改boot.bin文件
3.使用 sunxi-fel.exe -p spiflash-write 0x0 boot.bin烧录到spi flash中,不能运行,还是在fel模式。
4.使用sunxi-fel.exe spl boot.bin加载到dram中,可以运行,debug串口正常打印。
不知道问题出在哪里了?
离线
V3s SPI NAND u-boot @openwrt
https://whycan.com/t_3123.html#p26419
谢谢,原因找到了,是flash的问题,原来的flash是GD5F1GQ4UCYIG,换w25q128就可以了,但是还是没找到解决的办法,等我找到再发帖分享
离线
大神,你的问题解决了没有?我的开发板用的也是GD5F1GQ4UCYIG,下载裸机程序也不运行,
离线