Hardware Reference
In-Depth Information
Discussion
The
beagleboneblack-save-emmc.zip
file contains just enough of a Linux operating system
to know how to copy an image from the onboard flash to a file. The code that does the
work is in
autorun.sh
, which is shown in
Example 1-1
.
Example 1-1. Code for copying from onboard flash to microSD card
#!/bin/sh
echo timer
>
/sys/class/leds/beaglebone\:green\:usr0/trigger
dd
if
=
/dev/mmcblk1 of=/mnt/BeagleBoneBlack-eMMC-image-$RANDOM.img bs=10M
sync
echo
default
-
on
>
/sys/class/leds/beaglebone\:green\:usr0/trigger
The first
echo
changes the
USER0
LED to flash a different pattern to show the copy is be-
ing made. The
dd
command then copies the onboard flash image from input file (
if
)
/dev/
mmcblk1
to an output file (
of
) on the microSD card called
/mnt/BeagleBoneBlack-eMMC-
image-$RANDOM.img
.
/dev/mmcblk1
is where the entire onboard flash appears as a raw
image and
dd
just copies it.
The final
echo
turns the
USER0
LED on to notify you that the copying is over.
You can use the same microSD card to copy an
.img
file back to the onboard flash. Just edit
the
autorun.sh
file to include
Example 1-2
.
This code is largely the same as
Example 1-1
,
except it reverses the direction of the
dd
command.
Example 1-2. Restore .img file back to the onboard flash
#!/bin/sh
echo timer
>
/sys/class/leds/beaglebone\:green\:usr0/trigger
dd
if
=
/mnt/BeagleBoneBlack-eMMC-image-XXXXX.img of=/dev/mmcblk1 bs=10M
sync
echo
default
-
on
>
/sys/class/leds/beaglebone\:green\:usr0/trigger
To copy the saved image back, eject the microSD card from your computer, insert it into
the powered-off Bone, and apply power. Remember, because you are programming the on-
board flash, you will need to use an external 5 V power supply. The Bone will boot up from
the microSD card and write the backup files to the onboard flash.