Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    请教各位大佬,D1的start.s __start部分是参考哪里怎么实现的? 还有dram.c又是从那里得到的这些数据,最后的mksunxi 也是搞不懂依据在哪

    MR Series
    2
    2
    1269
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • baiwen
      100ask LV 6 last edited by

      最近在使用D1s录制RISC-V体系架构与C编程的课程,参考xboot作者的裸机实验(一直联系不到作者本人),目前可以直接烧录在DongshanPI-D1s spinor上运行,但是有几个问题 不明所以,不知道到底是怎么得来的,有懂的大佬能帮忙解析一下么?

      https://github.com/DongshanPI/DongshanPI-D1s_BareMetal/tree/master/source/start.S

      fab41273-30a9-40b7-9ecd-35e77d8b0640-image.png
      c6993bf7-2462-47a4-88b2-2bc0885b5ea1-image.png

      https://github.com/DongshanPI/DongshanPI-D1s_BareMetal/tree/master/source/sys-dram.c

      bf4c1d6b-8f25-4170-8980-2fa17bf8fdef-image.png

      https://github.com/DongshanPI/DongshanPI-D1s_BareMetal/blob/master/source/tools/mksunxi.c

      #include <stdio.h>
      #include <string.h>
      #include <stdint.h>
      #include <stdlib.h>
      
      #if 0
      static inline uint32_t __swab32(uint32_t x)
      {
      	return ( (x<<24) | (x>>24) | \
      		((x & (uint32_t)0x0000ff00UL)<<8) | \
      		((x & (uint32_t)0x00ff0000UL)>>8) );
      }
      #define cpu_to_le32(x)	(__swab32((uint32_t)(x)))
      #define le32_to_cpu(x)	(__swab32((uint32_t)(x)))
      #else
      #define cpu_to_le32(x)	(x)
      #define le32_to_cpu(x)	(x)
      #endif
      
      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];
      };
      
      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 = (filelen + 0x2000) & ~(0x2000 - 1);
      	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;
      	l = le32_to_cpu(h->length);
      	h->checksum = cpu_to_le32(0x5F0A6C39);
      	loop = l >> 2;
      	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;
      }
      
      1 Reply Last reply Reply Quote Share 0
      • YuzukiTsuru
        柚木 鉉 LV 9 last edited by YuzukiTsuru

        D1的start.s __start部分是参考哪里怎么实现的?

        首先是 eGON.BT0,这个Magic是BROM读取的,所以要在头部插入eGON.BT0

        还有dram.c又是从那里得到的这些数据

        这是使用mctl_hal.S和自己写的一个小裸机编译出的bin,mctl_hal.S全志的sdk里开源了,这个小裸机源码如下 6ee6e31c-72ef-47f5-b69f-0976197bb46a-d1-ddr.zip

        最后的mksunxi 也是搞不懂依据在哪

        这个是对齐后重新计算校验码的,然后填充在固定的位置让BROM读取,全志系列的老传统了,你看_start那里的checksum只是一个占位符0x12345678,mksunxi就是会对齐块设备然后计算校验填入然后修改长度

        https://github.com/YuzukiHD/TinyKasKit/blob/master/sunxiboot/src/bootpack.cpp

        1 Reply Last reply Reply Quote Share 1
        • 1 / 1
        • First post
          Last post

        Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

        行为准则 | 用户协议 | 隐私权政策