Skip to content

Commit

Permalink
Compile bootcode.bin and start.elf into rpiboot
Browse files Browse the repository at this point in the history
This helps avoid picking up the wrong files when msd files have already
been installed as a debian package
  • Loading branch information
ghollingworth committed Apr 12, 2018
1 parent c3ee230 commit 1bb4c2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
rpiboot: main.c
rpiboot: main.c msd/bootcode.h msd/start.h
$(CC) -Wall -Wextra -g -o $@ $< -lusb-1.0

%.h: %.bin
xxd -i $< > $@

This comment has been minimized.

Copy link
@simonvanderveldt

simonvanderveldt Apr 14, 2018

@ghollingworth Small question: this change makes building rpiboot depend on vim, since xxd is part of vim.
Is there no other way to do this?

This comment has been minimized.

Copy link
@ghollingworth

ghollingworth via email Apr 14, 2018

Author Contributor

This comment has been minimized.

Copy link
@simonvanderveldt

simonvanderveldt Apr 14, 2018

I'm not using a Debian based distro, so apt-get probably isn't going to work ;)

xdd is provided by the the basic/core vim package in my distro (Gentoo) and the same goes for other distro's like Arch and Fedora.

This comment has been minimized.

Copy link
@pelwell

pelwell Apr 14, 2018

Contributor

We could use objcopy instead to skip the c/h file step.


%.h: %.elf
xxd -i $< > $@

uninstall:
rm -f /usr/bin/rpiboot
rm -f /usr/share/rpiboot/usbbootcode.bin
Expand Down
15 changes: 8 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <unistd.h>

#include "msd/bootcode.h"
#include "msd/start.h"

int signed_boot = 0;
int verbose = 0;
int loop = 0;
Expand Down Expand Up @@ -410,9 +413,11 @@ FILE * check_file(char * dir, char *fname)

if(fp == NULL)
{
strcpy(path, "/usr/share/rpiboot/msd/");
strcat(path, fname);
fp = fopen(path, "rb");
if(strcmp(fname, "bootcode.bin") == 0)
fp = fmemopen(msd_bootcode_bin, msd_bootcode_bin_len, "r");
else
if(strcmp(fname, "start.elf") == 0)
fp = fmemopen(msd_start_elf, msd_start_elf_len, "r");
}

return fp;
Expand Down Expand Up @@ -563,10 +568,6 @@ int main(int argc, char *argv[])
#endif


// Default to standard msd directory
if(directory == NULL)
directory = "msd";

second_stage = check_file(directory, "bootcode.bin");
if(second_stage == NULL)
{
Expand Down

4 comments on commit 1bb4c2d

@ED6E0F17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have forgotten to "git add msd/bootcode.h msd/start.h", as these appear to be missing.

@ghollingworth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the makefile has a rule to generate them from the binary files

@ED6E0F17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry yes, I worked that out too late. - very useful trick

@ghollingworth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, realised that you could use xxd to convert a binary to an include file and use fmemopen to create a file pointer from an array...

Please sign in to comment.