/* In case of 0xff erased flash this does not modify data that is written to flash; in case of other flash devices, e.g. that erase to 0x00, it allows to correctly use the first bit of byte to figure out how many bytes are there and if there is any data at all or both bytes are equal to erase value.  */
int fcb_put_len(const struct fcb *fcb, uint8_t *buf, uint16_t len)
/* In case of 0xff erased flash this does not modify data that is written to flash; in case of other flash devices, e.g. that erase to 0x00, it allows to correctly use the first bit of byte to figure out how many bytes are there and if there is any data at all or both bytes are equal to erase value.  */
int fcb_put_len(const struct fcb *fcb, uint8_t *buf, uint16_t len)
{
	if (len < 0x80) {
		buf[0] = len ^ ~fcb->f_erase_value;
		return 1;
	} else if (len < FCB_MAX_LEN) {
		buf[0] = (len | 0x80) ^ ~fcb->f_erase_value;
		buf[1] = (len >> 7) ^ ~fcb->f_erase_value;
		return 2;
	} else {
		return -EINVAL;
	}
}