【问题标题】:How to append a number of bytes to the end of file如何将多个字节附加到文件末尾
【发布时间】:2019-09-17 19:15:58
【问题描述】:

NAND 闪存设备的块大小为 16384,页面大小为 512,OOB 大小为 16 字节。 分区转储(从 OOB 数据中清除)的大小为 13548080 字节,因此它不是 512 的倍数。由于所有写入必须是 512 字节对齐,并且 blob 大小必须是 512 字节的倍数,我应该添加 二进制末尾的 'n' 个字节(用 'FF' 填充)。 13548080 字节不完整 26462 页。完整的 26462 页是 26462 x 512 = 13548544 字节。不同的是我需要添加 464 字节。

我尝试了两步方法:首先,我创建了 464 字节的 padded.bin 文件dd if=/dev/zero bs=1 count=464 | tr '\000' '\377' >padded.bin,然后将原始文件附加到填充文件:dd if=padded.bin bs=1 count=464 >>original.bin

也许还有另一种方法可以在文件末尾附加 n 个字节使用 shell 命令?

【问题讨论】:

    标签: arrays linux shell hex flash-memory


    【解决方案1】:

    由于页数已知,可以使用ddcount=操作数; tr 可以提供所需的“FF”字节。

    (cat inputfile; tr </dev/zero \\0 \\377) | dd count=26462 iflag=fullblock >outputfile
    

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 2011-09-06
      相关资源
      最近更新 更多