######################################################################################################################################### # # File: uEnv.txt # Description: Controls which partition Linux will boot from # Instructions: Place this file in the root of the boot paritition. It will automatically be processed by the standard Beaglebone uBoot startup # # ---------------------------- flag files used ---------------------------------- # # NOTE: Content is arbitrary, but flag files MUST have non-zero length! (from Linux do not use "touch "; suggested mechanism is "echo 1 > ") # # Exactly one of the following two flag files should always present: # "PART_A" : requested boot is from partion A # "PART_B" : requested boot is from partion B # Software upgrade related flag files (these are not "normally" present): # "newpart_request" : created by Linux to tell uboot that its next boot is the first attempt of booting into "new" partition # "newpart_attempt" : created by uboot after seeing "newpart_request" and just prior to actually attempting booting into the "new" partition # # NOTE: except for the creation of "newpart_attempt" noted above, all flag file deleteions and creations are handled by Linux. See doc for details # # --------------------------------------------------------------------------------- # # ---------------------------- uBoot logic implemented by these commands ---------------------------- # # 1. Check for file "newpart_attempt". If it exists, prev boot attempt must have failed, so boot to the "opposite" partition (using "setpart_reversed") # **ELSE** # 2 a. Check for file "newpart_request". If it exists, create file "newpart_attempt" indicating a new "first attempt" about to be tried # b. Regardless of result in 2a, boot normally using "setpart_normal" # # --------------------------------------------------------------------------------------------------------- ######################################################################################################################################### # # code: # # strings for various messages appear below msg_booting_from_a="INFO: Booting from partition A (mmcblk0p2)" msg_booting_from_b="INFO: Booting from partition B (mmcblk0p3)" msg_newpart_attempt="INFO: Booting into new partition (first time attempt)" msg_newpart_fail="WARNING: Previous boot failed, reverting to alternate partition" msg_file_missing="WARNING: Could not find either flag file (PART_A or PART_B). Will boot from PART_A by default" # setpart_a: run this to set up booting from partition A by setting "mmcroot" to "/dev/mmcblk0p2" and to setting "bootpart" to "0:2" setpart_a=echo ${msg_booting_from_a}; setenv mmcroot /dev/mmcblk0p2 ro; setenv bootpart 0:2; # setpart_b: run this to set up booting from partition B by setting "mmcroot" to "/dev/mmcblk0p3" and to setting "bootpart" to "0:3" setpart_b=echo ${msg_booting_from_b}; setenv mmcroot /dev/mmcblk0p3 ro; setenv bootpart 0:3; # setpart_normal: run this to check for existence of non-empty file "PART_A" or "PART_B" and set up to boot from corresponding partition setpart_normal=if fatload mmc 0:1 ${loadaddr} PART_A; then run setpart_a; elif fatload mmc 0:1 ${loadaddr} PART_B; then run setpart_b; else echo ${msg_file_missing}; run setpart_a; fi; # setpart_reverse: run this to check for existence of non-empty file "PART_A" or "PART_B" and set up to boot from OPPOSITE partition setpart_reversed=if fatload mmc 0:1 ${loadaddr} PART_A; then run setpart_b; elif fatload mmc 0:1 ${loadaddr} PART_B; then run setpart_a; else echo ${msg_file_missing}; run setpart_a; fi; # newcheck: run this to check for the existing flag file "newpart_request". If it is, create a new flagfile named "newpart_attempt". newcheck=if fatload mmc 0:1 ${loadaddr} newpart_request; then echo ${msg_newpart_attempt}; fatwrite mmc 0:1 ${loadaddr} newpart_attempt 2; fi # uenvcmd: uenvcmd is a special variable that is automatically run by beaglebone's bootcmd just prior to actually booting # - running this command implements the entirety or the required partition boot logic by using the various other commands above uenvcmd=if fatload mmc 0:1 ${loadaddr} newpart_attempt; then echo ${msg_newpart_fail}; run setpart_reversed; else run newcheck; run setpart_normal; fi # ######################################################################################################################################### # end-of-file