How can I fill an S-record with two byte values st

2019-06-21 03:11发布

When I compile my code I eventually get Motorola S records (a.mot) with gaps (the whole address range is not covered by code and data).

I want to fill those gaps with the pattern 0x01 0x80. However, it is important that all of the two-byte pairs must start at even addresses. 0x0180 is an opcode from my micro that I want to be executed if the PC reaches an address of unused flash area.

Before you start answering I'd like to tell you that -repeat-data in srec_cat has an issue:

  • Given two sections e.g. C and D put one after another (D after C) in address space.
  • Given that last byte of section C ends on address 0x76 and first byte of section D is on address 0x78. In other words there is 1 byte long gap at address 0x77 between them.

Under such conditions, if I use -repeat-data 0x01 0x80 option, srec cat will fill that one byte with 0x01 and start filling following gap from 0x80.

I do not know sizes of those sections because linker handles it.

2条回答
祖国的老花朵
2楼-- · 2019-06-21 03:41

I would write a simple parser in Windows working like this:

  • The program creates a new s-record file based on the one you got from the compiler.
  • Loop through the generated file and read two s-record lines at a time.
  • If the line is an information line, S0, S9, S5 etc, just write it to the new file.
  • If line 1 has an address + size smaller than the address on line 2, you have found a gap. (address1 + size1) < address2.
  • Write line 1 to the new file.
  • If you found a gap, write a line with your gap constants S1xx01800180 and so on. Calculate the checksum as you go.
  • Write line 2 to the new file.
查看更多
干净又极端
3楼-- · 2019-06-21 04:03

Use srec_cat to create a file covering your required address range filled entirely with the 0x01 0x80 sequence aligned as required.

Then use srec_cat with the -multiple and −disable-sequence-warning options to "merge" the "filler" file with your application image file. You should specify the filler file as the first file so that it is overwritten by the application data specified second.

It will issue many warnings, but it should work.

查看更多
登录 后发表回答