Skip to content

Commit

Permalink
libuuu: sdp: SDPBootCmd: add barebox autodetection
Browse files Browse the repository at this point in the history
We do already support the -barebox switch, so the user can force the
barebox image handling. Add a autodetection mechanism to make it even
more user friendly. The autodetection is based on the fact, that barebox
does add an "barebox" string at offset 0x20 to the image. If this string
is found we can assume that user provided file is an barebox image.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
  • Loading branch information
Marco Felsch authored and nxpfrankli committed Oct 19, 2023
1 parent aa70f19 commit 5aebb13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion libuuu/sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ SDPBootCmd::SDPBootCmd(char *p) : SDPCmdBase(p)
insert_param_info("-barebox", &m_barebox, Param::Type::e_bool);
}

# define BAREBOX_MAGIC_OFFSET 0x20

bool SDPBootCmd::is_barebox_img(void)
{
shared_ptr<FileBuffer> fbuf= get_file_buffer(m_filename, true);
if (fbuf == nullptr)
return false;

string barebox_magic ("barebox");

shared_ptr<DataBuffer> dbuf = fbuf->request_data(0, BAREBOX_MAGIC_OFFSET + barebox_magic.length());
if (dbuf == nullptr)
return false;

string img ((const char *)&dbuf->at(BAREBOX_MAGIC_OFFSET), barebox_magic.length());

return img.compare(barebox_magic) == 0 ? true : false;
}

int SDPBootCmd::load_barebox(CmdCtx *ctx)
{
const ROM_INFO *rom = search_rom_info(ctx->m_config_item);
Expand Down Expand Up @@ -341,7 +360,7 @@ int SDPBootCmd::run(CmdCtx *ctx)
if (jmp.run(ctx)) return -1;
}

if (m_barebox)
if (m_barebox || is_barebox_img())
{
if (load_barebox(ctx)) return -1;
}
Expand Down
1 change: 1 addition & 0 deletions libuuu/sdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class SDPBootCmd : public SDPCmdBase
int run(CmdCtx *p) override;

private:
bool is_barebox_img(void);
int load_barebox(CmdCtx *ctx);

bool m_clear_dcd = false;
Expand Down

0 comments on commit 5aebb13

Please sign in to comment.