Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0xff optimization when reading #1732

Closed
dl8dtl opened this issue Mar 30, 2024 · 7 comments · Fixed by #1803
Closed

0xff optimization when reading #1732

dl8dtl opened this issue Mar 30, 2024 · 7 comments · Fixed by #1803
Labels
enhancement New feature or request

Comments

@dl8dtl
Copy link
Contributor

dl8dtl commented Mar 30, 2024

int avr_mem_hiaddr(const AVRMEM * mem)
{
  int i, n;
  static int disableffopt;

  /* calling once with NULL disables any future trailing-0xff optimisation */
  if(!mem) {
    disableffopt = 1;
    return 0;
  }

There is no way to turn it on again? This is not good.

@dl8dtl dl8dtl added the question Further information is requested label Mar 30, 2024
@dl8dtl
Copy link
Contributor Author

dl8dtl commented Mar 30, 2024

Also, what I don't understand, from my protocol:

2024-03-30T09:55:55 Read 8666  bytes
2024-03-30T09:56:05 Wrote 16384 bytes to /home/joerg/src/avrdude/foo.hex

It clearly optimized the trailing 0xFF when reading (through avr_read_mem(), as can be seen from the 8666 bytes. Yet, when writing the memory buffer through fileio(), the entire memory region is saved. The code suggests to me that only the "relevant" bytes ought to be written.

@dl8dtl
Copy link
Contributor Author

dl8dtl commented Mar 30, 2024

OK, I understand the latter:

  if(size < 0 || op == FIO_READ || op == FIO_READ_FOR_VERIFY)
    size = mem->size;

So the upper layer is supposed to track the size.

@stefanrueger
Copy link
Collaborator

There is no way to turn it on again? This is not good.

I agree. AVRDUDE doesn't need to switch -A off again, but a library might want to. I suggest to make the -A flag a global variable that can be accessed by the library.

-A is meant to not remove trailing 0xff sequences from avr_reads() or file input, as they could be relevant data and the programmer could see AVR flash as normal memory (as certain bootloaders do or AVR with page erase) rather than NOR memory.

@dl8dtl
Copy link
Contributor Author

dl8dtl commented Mar 31, 2024

Global variable sounds OK to me.
Other users of the library might turn -A into their own option system.
Btw. even the CLI might have a use for it: in terminal mode.

@dl8dtl
Copy link
Contributor Author

dl8dtl commented Mar 31, 2024

Rather than making the variable global, it could remain static (module-internal, not exposed in the library). That enforces the use of access functions.
A completely different option would be a kind of library context structure that holds all that kind of options (also verbose, and quell_progress). It could start out as a global, and eventually moved as a pointer into API calls – that could even make the library API reentrant. :-)

@stefanrueger
Copy link
Collaborator

even the CLI might have a use for it: in terminal mode

AVRDUDE only ever considers one part/programmer combo in each incarnation; once that's fixed -A either makes sense or not, but it wouldn't be required (or, in my understanding, make sense) to toggle that option back and forth.

@stefanrueger
Copy link
Collaborator

[global, access functions or context pointer]

As a quick shot I'd make this option global in the first instance, and then at some point change to context pointer for all global variables.

@mcuee mcuee added enhancement New feature or request and removed question Further information is requested labels Apr 7, 2024
@stefanrueger stefanrueger linked a pull request May 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants