ramdump: Fix long and short reads with elf ramdumps

The ramdump read function is made up of two parts. The first part
handles reading the elf headers and the second part handles
reading the physical memory. The elf header reading part has two
problems and both of these problems cause the file to be corrupt
depending on what values sys_read() is called with.

First, if the sys_read() call passes a 'count' value that is
less than the length of the elf headers, the second read will
overwrite the buffer with earlier parts of the elf header because
we don't seek into the elf header buffer we're copying from. Fix
that by adding the *pos offset.

Second, we'll return the wrong value for how much was read if a
long read is made that would read all of the elf headers plus the
physical memory. Instead of returning the sum of both the elf
headers and the amount of physical memory read, we only return
the amount of physical memory read. Fix that by taking the
difference between the pos pointer at the beginning and end of
the read.

CRs-fixed: 449322
Change-Id: I4598def4bbeb9feea2b7a55605bd2bc8b80140cf
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
1 file changed