在 Linux 上为 FatFS 和 FreeRTOS + FAT 创建 FAT 磁盘映像

问题描述 投票:0回答:1

我一直在使用带有 FreeRTOS + FAT 库的 CVA6 RISCV 核心来创建 RAMDisk,其中包含在裸机上运行 San Diego Vision Benchmark 所需的一些文件。

我正在寻找一种在我的 PC 上的 Linux 上创建磁盘映像的方法,我可以通过 JTAG 将其加载到我的 DRAM 中,并能够挂载准备好的文件系统。我在互联网上没有找到关于如何执行此操作的一致信息,因此这是我的步骤:

  1. 我在linux中使用dd创建了一个我所需大小5MB(5 * 1M)的.img文件:

    dd if=/dev/zero of=test.img count=5 bs=1M

  2. 然后我使用 fdisk 创建 MBR 分区表并用一个分区填充我的磁盘:

    fdisk test.img
    在 fdisk 中:

1. o: Write a new disk identifier
2. n: create a new partition
3. p: primary Partition and default values for partition number, first sector and last sector
4. t: and then c. This is to change partition type to Win95 FAT32(LBA)
5. w: write changes and exit
  1. 然后我安装了第一个分区并格式化了它。这是棘手的部分。我必须将偏移量计算为:offset=starting_sector(从fdisk -l test.img获取)*sector_size(FAT32的默认值为512) 我使用lostup在Ubuntu上创建了一个环回设备。就我而言,loop10 是免费的:

    sudo losetup -o offset /dev/loop10 test.img
    然后我使用 mkfs.vfat 格式化分区:
    sudo mkfs.vfat -F 32 -n RV64 /dev/loop10
    最后使用以下方法安装:
    sudo mount /dev/loop10 /home/my_user/fatfs_img/

  2. 然后我将文件从我的电脑复制到安装的驱动器。然后使用 umount 命令卸载。

  3. 因为我必须将文件与最终的 elf 文件(GNU 工具链)一起打包: 我在链接器脚本中创建了一个 .my_image 部分:

.my_image : 
    {
              *(.my_image)
        }
  1. 最后,我将 .img 文件添加到我的启动汇编代码中,并添加了一些用于图像起始位置、大小等的符号:
.section .my_image, "a"
.global my_fat_image_start
.global my_fat_image_size

my_fat_image_start:
.incbin "test.img"

my_fat_image_end:
my_fat_image_size:
    .int my_fat_image_end - my_fat_image_start

希望这有帮助!

embedded filesystems elf freertos fatfs
1个回答
0
投票

hexdump工具可用于进一步调试生成的镜像文件。 FAT 文件系统规范的详细概述如下: http://elm-chan.org/docs/fat_e.html

© www.soinside.com 2019 - 2024. All rights reserved.