sifive / freedom-u540-c000-bootloader

Freedom U540-C000 Bootloader Code
Other
85 stars 38 forks source link

a memcpy bug(possibly) #31

Closed 0xWilliamWang closed 3 years ago

0xWilliamWang commented 3 years ago

https://github.com/sifive/freedom-u540-c000-bootloader/blob/24f612fe7ab54f213214e0e7e1f56bf839cb3bb8/lib/memcpy.c#L23

aa,bb are restricted pointer and it's value cannot be modified by other pointers. but in BODY by https://github.com/sifive/freedom-u540-c000-bootloader/blob/24f612fe7ab54f213214e0e7e1f56bf839cb3bb8/lib/memcpy.c#L28 the value of aa is modified.

I may be wrong, but this solves the problem of infinite loops in memcpy functions in some cases.

memcpy(void * aa, const void * bb, size_t n)
jim-wilson commented 3 years ago

The variable A is a copy of the variable AA, so modifying A doesn't modify AA. This looks OK to me.

This code incidentally is dead and no longer maintained as far as I know. The u540 support was upstreamed to u-boot and is now maintained there.

It isn't clear if you ran into a problem or not. You mention infinite loops. Did you run into one?

0xWilliamWang commented 3 years ago

@jim-wilson I am vary, vary sorry that i sent my issue in the wrong place.

  1. The program I was running was keystone's code, they forked this project, but they didn't modify memcpy, so I open the issue.
  2. I used the latest commit and it worked well

      SiFive FSBL:       2021-08-27-24f612f
      Using FSBL DTB
      HiFive-U serial #: 0000032e
      Loading boot payload................................
    
      OpenSBI v0.8
      ____                    _____ ____ _____
      / __ \                  / ____|  _ \_   _|
      | |  | |_ __   ___ _ __ | (___ | |_) || |
      | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
      | |__| | |_) |  __/ | | |____) | |_) || |_
      \____/| .__/ \___|_| |_|_____/|____/_____|
            | |
            |_|
    
      Platform Name             : sifive,hifive-unleashed-a00
      Platform Features         : timer,mfdeleg
      ....
  3. See this PR for more info if you are interested.
  4. Thank you vary much for your reply and I am very sorry to disturb you.