mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 18:34:57 +02:00
nvmutil: explain a few parts in nvmalloc
the current code is optimised for speed, but it's a bit esoteric, so make it easier to understand. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -197,19 +197,24 @@ openFiles(const char *path)
|
|||||||
void
|
void
|
||||||
nvmalloc(void)
|
nvmalloc(void)
|
||||||
{
|
{
|
||||||
|
/* same operations need the full block, others only 128 bytes */
|
||||||
if ((cmd == cmd_swap) || (cmd == cmd_copy))
|
if ((cmd == cmd_swap) || (cmd == cmd_copy))
|
||||||
nf = SIZE_4KB;
|
nf = SIZE_4KB;
|
||||||
else
|
else
|
||||||
nf = NVM_SIZE;
|
nf = NVM_SIZE;
|
||||||
|
|
||||||
|
/* only read the part specified, for copy/setchecksum/brick */
|
||||||
if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick))
|
if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick))
|
||||||
do_read[part ^ 1] = 0;
|
do_read[part ^ 1] = 0;
|
||||||
|
|
||||||
|
/* only allocate one block if only one part being read */
|
||||||
char *buf = malloc(nf << (do_read[0] & do_read[1]));
|
char *buf = malloc(nf << (do_read[0] & do_read[1]));
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
err(errno, NULL);
|
err(errno, NULL);
|
||||||
|
|
||||||
gbe[0] = (size_t) buf;
|
gbe[0] = (size_t) buf;
|
||||||
|
|
||||||
|
/* speedhack: for cmd copy, both pointers are set the same */
|
||||||
gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1]));
|
gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user