# SFBBootBlock.h File Reference

Support for the SFB boot block. More...

`#include "SFBChecksum.h"`
`#include "SFBTypes.h"`
`#include "SFBEeprom.h"`
`#include "SFBPower.h"`

Include dependency graph for SFBBootBlock.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | SFBBootBlock
| The exactly-64-byte-long SFB 'boot block' contents. More...
## Defines
#define | BOOTBLOCK_MIN_VERSION 0x01
| Minimum legal boot block version; excludes 0.
#define | BOOTBLOCK_MAX_VERSION 0xfe
| Maximum legel boot block version, excludes 0xff.
#define | BOOTBLOCK_VERSION 6
| The current boot block version.
## Enumerations
enum | SFBBootBlockFlag { BOOTBLOCK_INVALID = 0x0001, BOOTBLOCK_BOOT_MODE = 0x0002, BOOTBLOCK_BLUE_NOT_RED = 0x0004, BOOTBLOCK_UNLOCKED = 0x0008, BOOTBLOCK_NO_UPDATES = 0x0010, BOOTBLOCK_KILL_SKETCH = 0x0020, BOOTBLOCK_RSRVD06 = 0x0040, BOOTBLOCK_RSRVD07 = 0x0080, BOOTBLOCK_RSRVD08 = 0x0100, BOOTBLOCK_RSRVD09 = 0x0200, BOOTBLOCK_RSRVD10 = 0x0400, BOOTBLOCK_RSRVD11 = 0x0800, BOOTBLOCK_RSRVD12 = 0x1000, BOOTBLOCK_RSRVD13 = 0x2000, BOOTBLOCK_RSRVD14 = 0x4000, BOOTBLOCK_RSRVD15 = 0x8000, BOOTBLOCK_DEFINED_FLAGS }
| Flags that can be set in the SFBBootBlock. More...
## Functions
u32 | getBootBlockVersion ()
| Get bootblock version.
u8 | getBootBlockWatchdogResets ()
| Get bootblock watchdog resets byte.
u32 | getBootBlockOwnerId ()
| Get bootblock owner id.
u32 | getBootBlockBoardId ()
| Get bootblock board id.
u32 | getBootBlockBootCount ()
| Get bootblock boot count.
u32 | getBootBlockBurnCount ()
| Get bootblock sketch burn count.
u32 | getBootBlockPowerOnHours ()
| Get bootblock total Power-On-Hours count.
u32 | getBootBlockFlags ()
| Get bootblock flags.
u32 | getBootBlockBootMode ()
| Get bootblock boot mode.
u32 | getBootBlockMergedChecksum ()
| Return the `u32` XOR (exclusive-OR) of the two halves of the bootblock checksum.
bool | getBootBlockPowerIn (u8 face)
| Return true if input power should be accepted from face at power up.
bool | getBootBlockPowerOut (u8 face)
| Return true if output power should be provided from face at power up.
void | setBootBlockPowerIn (u8 face, bool accept)
| Specify whether input power should be.
void | setBootBlockPowerOut (u8 face, bool provide)
| accepted (accept equals `true`) or blocked (accept equals `false`) on face.
const char * | bootModeColorName (u32 bootMode)
| provided (provide equals `true`) or not (provide equals `false`) on face at boot time.
u32 | getBootBlockBootLoaderLength ()
| Access the size of the tertiary bootloader.
u32 | getBootBlockBootLoaderBurnCount ()
| Access the count of how many times the tertiary bootloader itself has been burned.
void | getBootBlockBootLoaderChecksum (SFBChecksum cs)
| Access the checksum of the tertiary bootloader itself.
void | setBootBlockWatchdogResetFlag (bool bootedClean)
| Add another bit to the bottom of the watchdog reset flag byte, pushing the existing bits to the left.
void | setBootBlockOwnerId (u32 newOwnerId)
| Write the boot block owner id field.
void | setBootBlockBoardId (u32 newBoardId)
| Write the boot block board id field.
void | incrementBootBlockBootCount ()
| Increment the boot count in the boot block.
void | incrementBootBlockBurnCount ()
| Increment the burn count in the boot block.
void | incrementBootBlockPowerOnHours ()
| Increment the power on hours in the boot block.
void | setBootBlockFlags (u32 newFlags)
| Write the boot block flags.
void | setBootBlockBootMode (u32 newBootMode)
| Set the boot block boot mode.
void | getBootBlockVoltageCalibrationData (u8 data[VOLTAGE_CALIBRATION_SIZE_BYTES])
| Fill data with the voltage calibration data (returns all zeros if this board was never voltage-calibrated).
void | setBootBlockVoltageCalibrationData (u8 data[VOLTAGE_CALIBRATION_SIZE_BYTES])
| Stores voltage calibration data read from data.

## Detailed Description

Support for the SFB boot block.

Author:
  David H. Ackley.

Date:
  (C) 2009 All rights reserved.

Code License:
  The GNU Lesser General Public License

License Note:
  All code samples shown in documentation are placed into the public domain.

## Define Documentation

#define BOOTBLOCK_MAX_VERSION 0xfe

Maximum legel boot block version, excludes 0xff.

#define BOOTBLOCK_MIN_VERSION 0x01

Minimum legal boot block version; excludes 0.

#define BOOTBLOCK_VERSION 6

The current boot block version.

This value can never decrease, during any and all future evolution of the SFB code.

## Enumeration Type Documentation

enum SFBBootBlockFlag

Flags that can be set in the SFBBootBlock.

Enumerator:

  BOOTBLOCK_INVALID | entire block invalid if set
  BOOTBLOCK_BOOT_MODE | if 0 then GREEN_BOOT - newest code wins
  BOOTBLOCK_BLUE_NOT_RED | if BOOT_MODE set, then if this then BLUE_BOOT else RED_BOOT
  BOOTBLOCK_UNLOCKED | if 0 then ownerId,boardId cannot be modified
  BOOTBLOCK_NO_UPDATES | go direct to valid sketch; don't even try to update
  BOOTBLOCK_KILL_SKETCH | treat sketch as invalid even if checksum looks good
  BOOTBLOCK_RSRVD06 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD07 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD08 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD09 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD10 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD11 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD12 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD13 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD14 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_RSRVD15 | Reserved, value should be zero and must be ignored.
  BOOTBLOCK_DEFINED_FLAGS | Currently defined flags.

## Function Documentation

const char* bootModeColorName | ( | u32 | bootMode | ) |

provided (provide equals `true`) or not (provide equals `false`) on face at boot time.

u32 getBootBlockBootLoaderBurnCount | ( |  | ) |

Access the count of how many times the tertiary bootloader itself has been burned.

Even though strictly speaking that's not 'boot block business'. Also note that it is possible for this count to get reset if various errors occur during reflashing, so it should be treated as likely lower bound on the count.

void getBootBlockBootLoaderChecksum | ( | SFBChecksum | cs | ) |

Access the checksum of the tertiary bootloader itself.

Even though strictly speaking that's not 'boot block business'.

Side Effects:

cs is updated.

u32 getBootBlockBootLoaderLength | ( |  | ) |

Access the size of the tertiary bootloader.

Even though strictly speaking that's not 'boot block business'.

u32 getBootBlockBootMode | ( |  | ) |

Get bootblock boot mode.

Returns:
  RED_BOOT_MODE, GREEN_BOOT_MODE, or BLUE_BOOT_MODE, based on the values of the flags BOOTBLOCK_BOOT_MODE and BOOTBLOCK_BLUE_NOT_RED extracted from getBootBlockFlags.

u32 getBootBlockMergedChecksum | ( |  | ) |

Return the `u32` XOR (exclusive-OR) of the two halves of the bootblock checksum.

This value is used by the library startup code to generate the random number seed.

bool getBootBlockPowerIn | ( | u8 | face | ) |

Return true if input power should be accepted from face at power up.

The return value when output equals `false` is meaningful only on boards with power input controls; is a noop otherwise. Note this value reflects only the boot time setting; even if power input is subsequently manipulated via powerIn, this value does not change. See setBootBlockPowerIn to change this value.

u32 getBootBlockPowerOnHours | ( |  | ) |

Get bootblock total Power-On-Hours count.

Note this counts only full consecutive uptime hours; all fractions are dropped no matter what their cumulative time. Note also that this value can be affected by RF_LESS_EEPROM.

bool getBootBlockPowerOut | ( | u8 | face | ) |

Return true if output power should be provided from face at power up.

Note this value reflects only the boot time setting; even if power output is subsequently manipulated via powerOut, this value does not change. See setBootBlockPowerOut to change this value.

u32 getBootBlockVersion | ( |  | ) |

Get bootblock version.

Returns:
  value from BOOTBLOCK_MIN_VERSION to BOOTBLOCK_MAX_VERSION

void setBootBlockBoardId | ( | u32 | newBoardId | ) |

Write the boot block board id field.

Fails silently unless the boot block is unlocked.

void setBootBlockOwnerId | ( | u32 | newOwnerId | ) |

Write the boot block owner id field.

Fails silently unless the boot block is unlocked.

void setBootBlockPowerOut | ( | u8 | face,
|  | bool | provide |
| ) |  |  |

accepted (accept equals `true`) or blocked (accept equals `false`) on face.

The value set is meaningful only on boards with power input controls; this method is a noop otherwise. Specify whether output power should be

void setBootBlockVoltageCalibrationData | ( | u8 | data[VOLTAGE_CALIBRATION_SIZE_BYTES] | ) |

Stores voltage calibration data read from data.

Storing all zeros implies 'no calibration data available', which will cause faceVoltage and railVoltage to fall back on approximate 'datasheet defaults'.

void setBootBlockWatchdogResetFlag | ( | bool | bootedClean | ) |

Add another bit to the bottom of the watchdog reset flag byte, pushing the existing bits to the left.