60#if OPENMRN_FEATURE_REBOOT
62void reboot() __attribute__ ((weak));
73static constexpr unsigned FACTORY_RESET_REBOOT_DELAY_MSEC = 50;
75static constexpr unsigned FACTORY_RESET_REBOOT_DELAY_MSEC = 500;
78uint16_t __attribute__((weak, noinline))
81 return Defs::ERROR_UNIMPLEMENTED;
86 if (target == dg_service()->iface()->get_default_node_id())
129 fd_ = open(name_, opts);
132 LOG(
WARNING,
"Error opening file %s : %s", name_, strerror(errno));
137 if (fileSize_ == AUTO_LEN)
140 HASSERT(fstat(fd_, &buf) >= 0);
141 fileSize_ = buf.st_size;
146 size_t len, errorcode_t *error,
Notifiable *again)
151 *error = Defs::ERROR_PERMANENT;
154 off_t actual_position = lseek(fd_, destination, SEEK_SET);
155 if ((address_t)actual_position != destination)
157 *error = MemoryConfigDefs::ERROR_OUT_OF_BOUNDS;
160 ssize_t ret =
::write(fd_, data, len);
163 LOG(
INFO,
"Error writing to fd %d: %s", fd_, strerror(errno));
164 *error = Defs::ERROR_PERMANENT;
167 else if ((
size_t)ret < len)
187 *error = Defs::ERROR_PERMANENT;
190 off_t actual_position = lseek(fd_, destination, SEEK_SET);
191 if ((address_t)actual_position != destination)
193 *error = Defs::ERROR_PERMANENT;
196 if (destination >= fileSize_)
198 *error = MemoryConfigDefs::ERROR_OUT_OF_BOUNDS;
201 if (destination + len > fileSize_)
203 len = fileSize_ - destination;
205 ssize_t ret =
::read(fd_, dst, len);
208 LOG(
INFO,
"Error reading from fd %d: %s", fd_, strerror(errno));
209 *error = Defs::ERROR_PERMANENT;
215 *error = MemoryConfigDefs::ERROR_OUT_OF_BOUNDS;
218 else if ((
size_t)ret < len)
int ioctl(int fd, unsigned long int key,...)
Request and ioctl transaction.
void enter_bootloader()
Implement this function (usually in HwInit.cxx) to enter the bootloader.
An object that can schedule itself on an executor to run.
static ConfigUpdateService * instance()
Service * service()
Return a pointer to the service I am bound to.
Implementation of the ConfigUpdateService: state flow issuing all the calls to the registered ConfigU...
void ensure_file_open()
Makes fd a valid parameter, and ensures fileSize is filled in.
bool read_only() OVERRIDE
size_t write(address_t destination, const uint8_t *data, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
size_t read(address_t source, uint8_t *dst, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
FileMemorySpace(int fd, address_t len=AUTO_LEN)
Creates a memory space based on an fd.
Used internally by the factory_reset implementation to reboot the binary asynchronously.
Implementation of the Memory Access Configuration Protocol for OpenLCB.
uint16_t handle_factory_reset(NodeID target)
Invokes the openlcb config handler to do a factory reset.
uint16_t app_handle_factory_reset(NodeID target)
Weak definition for invoking a factory reset on virtual nodes.
static const errorcode_t ERROR_AGAIN
This error code signals that the operation was only partially completed, the again notify was used an...
#define CAN_IOC_READ_ACTIVE
read active ioctl.
#define CAN_IOC_WRITE_ACTIVE
write active ioctl.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int WARNING
Loglevel that is always printed, reporting a warning or a retryable error.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
uint64_t NodeID
48-bit NMRAnet Node ID type
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.