Ulrich Mohr
c0e896b371
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
533 lines
14 KiB
C
533 lines
14 KiB
C
#ifndef __LIBXIPHOS_H__
|
|
#define __LIBXIPHOS_H__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <inttypes.h> /* required by libmtd.h */
|
|
#include <libmtd.h> /* required for libmtd_t */
|
|
#include <stddef.h>
|
|
|
|
/* String identifying this library's version */
|
|
extern const char *xsc_libxiphos_version;
|
|
|
|
/** Type for boolean values */
|
|
typedef int xsc_bool_t;
|
|
|
|
/** Type for the LibNOR instance descriptor */
|
|
typedef void * xsc_libnor_t;
|
|
|
|
/** Type for identifying the nominal or the gold (redundant) flash copy */
|
|
typedef enum {
|
|
XSC_LIBNOR_COPY_NOMINAL,
|
|
XSC_LIBNOR_COPY_GOLD,
|
|
XSC_LIBNOR_COPY_TOTAL_NUMBER
|
|
} xsc_libnor_copy_t;
|
|
|
|
/** Type for identifying one of the two NOR flash chips */
|
|
typedef enum {
|
|
XSC_LIBNOR_CHIP_0, /* First NOR flash chip */
|
|
#if (!defined(CONFIG_Q7AE))
|
|
XSC_LIBNOR_CHIP_1, /* Second NOR flash chip */
|
|
#endif
|
|
XSC_LIBNOR_CHIP_TOTAL_NUMBER
|
|
} xsc_libnor_chip_t;
|
|
|
|
/* Type for identifying the boot stage */
|
|
typedef enum {
|
|
XSC_BOOT_STAGE_INITRAMFS, /* Booted from initramfs */
|
|
XSC_BOOT_STAGE_ROOTFS, /* Booted from rootfs flash partition */
|
|
XSC_BOOT_STAGE_TOTAL_NUMBER
|
|
} xsc_boot_stage_t;
|
|
|
|
typedef enum {
|
|
XSC_POWER_OFF, /* Power disabled */
|
|
XSC_POWER_ON /* Power enabled */
|
|
} xsc_power_t;
|
|
|
|
/** Type for identifying the partitions of a NOR flash copy */
|
|
typedef enum {
|
|
XSC_LIBNOR_PART_NA = 0,
|
|
XSC_LIBNOR_PART_FW,
|
|
XSC_LIBNOR_PART_XSCINFO,
|
|
XSC_LIBNOR_PART_ROOTFS,
|
|
XSC_LIBNOR_PART_UENV,
|
|
XSC_LIBNOR_PART_DTB,
|
|
XSC_LIBNOR_PART_KERNEL,
|
|
XSC_LIBNOR_PART_INITRAMFS,
|
|
XSC_LIBNOR_PART_BCH,
|
|
XSC_LIBNOR_PART_RWINFO,
|
|
XSC_LIBNOR_PART_ROINFO,
|
|
XSC_LIBNOR_PART_SYSTEM,
|
|
XSC_LIBNOR_PART_ALL
|
|
} xsc_libnor_partitions_t;
|
|
|
|
typedef enum {
|
|
XSC_LIBNOR_SYSFILE_NA = 0,
|
|
XSC_LIBNOR_SYSFILE_KERNEL,
|
|
XSC_LIBNOR_SYSFILE_DTB,
|
|
XSC_LIBNOR_SYSFILE_LOGIC,
|
|
} xsc_libnor_system_files_t;
|
|
|
|
/** Type for identifying the action on the scratch buffer */
|
|
typedef enum {
|
|
SCRATCH_READ = 0,
|
|
SCRATCH_WRITE,
|
|
SCRATCH_CLEAR
|
|
} xsc_scratch_action_t;
|
|
|
|
struct xsc_scratch_op {
|
|
xsc_scratch_action_t action;
|
|
char *var_name;
|
|
char *var_value;
|
|
};
|
|
|
|
/** Type for specifying an error or status code */
|
|
typedef int xsc_status_t;
|
|
#define XSC_SUCCESS (0) /* No Error */
|
|
#define XSC_ERROR (-1) /* Error */
|
|
#define XSC_EINVAL (-2) /* Invalid inputs */
|
|
#define XSC_EBUSY (-3) /* Device is busy */
|
|
|
|
/** Returns the copy name */
|
|
const char *get_copy_name(xsc_libnor_t desc);
|
|
|
|
/** Returns the chip and copy for the given partition name */
|
|
xsc_status_t parse_copy_name(const char* name, xsc_libnor_chip_t *chip,
|
|
xsc_libnor_copy_t *copy);
|
|
|
|
/* In the following structure, sizes of the memory and swap fields
|
|
* are given as multiples of mem_unit bytes. */
|
|
struct xsc_proc_info {
|
|
long uptime; /* Seconds since boot */
|
|
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
|
|
unsigned long totalram; /* Total usable main memory size */
|
|
unsigned long freeram; /* Available memory size */
|
|
unsigned long sharedram; /* Amount of shared memory */
|
|
unsigned long bufferram; /* Memory used by buffers */
|
|
unsigned short procs; /* Number of current processes */
|
|
unsigned long totalhigh; /* Total high memory size */
|
|
unsigned long freehigh; /* Available high memory size */
|
|
unsigned int mem_unit; /* Memory unit size in bytes */
|
|
};
|
|
|
|
/* Retrieve the system information */
|
|
xsc_status_t xsc_info_proc(struct xsc_proc_info *info);
|
|
|
|
/**
|
|
* xsc_info_pa3_status
|
|
*
|
|
* Returns the ProASIC3 Logic status register.
|
|
*/
|
|
xsc_status_t xsc_info_pa3_status(uint32_t *status);
|
|
|
|
/** Libsensors */
|
|
|
|
/** The user application is expected to use libsensors for reading ADCs
|
|
* Refer to libsensor documentation.
|
|
* */
|
|
|
|
xsc_status_t xsc_ubi_get_mountinfo(int ubi_dev, int *mounted, int *rw, char
|
|
*tgt, char *src, size_t bufsize);
|
|
|
|
xsc_status_t xsc_get_mountinfo(const char *source, int *mounted, char
|
|
*target, size_t bufsize);
|
|
|
|
/**
|
|
* xsc_info_pa3_logicrev
|
|
*/
|
|
xsc_status_t xsc_info_pa3_logicrev(uint32_t *status);
|
|
|
|
/**
|
|
* xsc_boot_get_chip_copy
|
|
*
|
|
* Gets the currently booted NOR flash chip and copy
|
|
*
|
|
*/
|
|
xsc_status_t xsc_boot_get_chip_copy(xsc_libnor_chip_t *boot_chip, xsc_libnor_copy_t *boot_copy);
|
|
|
|
/**
|
|
* xsc_boot_copy
|
|
*
|
|
* Reboot on the chip copy specified
|
|
*
|
|
*/
|
|
void xsc_boot_copy(xsc_libnor_chip_t boot_chip, xsc_libnor_copy_t boot_copy);
|
|
|
|
#if (defined(CONFIG_Q8_REVA) || defined(CONFIG_Q8S_REVA) || defined(CONFIG_Q8_REVB) || defined(CONFIG_Q8S_REVB))
|
|
/**
|
|
* xsc_get_cur_lim_pwm
|
|
*
|
|
* Get the current limit PWM
|
|
* Restricted to Q8 devices
|
|
*
|
|
*/
|
|
xsc_status_t xsc_get_cur_lim_pwm(uint32_t *pwm);
|
|
|
|
/**
|
|
* xsc_set_cur_lim_pwm
|
|
*
|
|
* Set the current limit PWM (range:0..15)
|
|
* Restricted to Q8 devices
|
|
*
|
|
*/
|
|
xsc_status_t xsc_set_cur_lim_pwm(uint32_t pwm);
|
|
#endif
|
|
|
|
/* # LibNOR: Q-card NOR flash management */
|
|
|
|
/**
|
|
* xsc_libnor_open - open the Xiphos NOR library to use the given copy and chip
|
|
*
|
|
**/
|
|
xsc_status_t xsc_libnor_open(xsc_libnor_t *desc, xsc_libnor_chip_t chip, xsc_libnor_copy_t copy);
|
|
|
|
/**
|
|
* xsc_libnor_open - open the Xiphos NOR library
|
|
*
|
|
**/
|
|
xsc_status_t xsc_libnor_open_any(xsc_libnor_t *desc);
|
|
|
|
/**
|
|
* xsc_libnor_close - close the Xiphos NOR library
|
|
*
|
|
**/
|
|
void xsc_libnor_close(xsc_libnor_t desc);
|
|
|
|
/**
|
|
* xsc_libnor_getmtd
|
|
*
|
|
* Return the MTD number for the specified name
|
|
* */
|
|
xsc_status_t xsc_libnor_getmtd(xsc_libnor_t desc, const char *name,
|
|
int *mtd_num);
|
|
|
|
/**
|
|
* xsc_libnor_mtd_getsize
|
|
*
|
|
* Return the size of the specified MTD partition
|
|
*/
|
|
xsc_status_t xsc_libnor_mtd_getsize(xsc_libnor_t desc, const int mtd_num,
|
|
size_t *mtd_size);
|
|
|
|
/**
|
|
* xsc_libnor_copy_getmtd
|
|
*
|
|
* Return the MTD number for the specified copy (nom0, nom1, gold0, gold1)
|
|
* */
|
|
xsc_status_t xsc_libnor_copy_getmtd(xsc_libnor_t desc, int *mtd_num);
|
|
|
|
/**
|
|
* xsc_libnor_part_getmtd
|
|
*
|
|
* Return the MTD number for the specified partition (e.g. rootfs)
|
|
* */
|
|
xsc_status_t xsc_libnor_part_getmtd(xsc_libnor_t desc, const char *part_name, int *mtd_num);
|
|
|
|
/**
|
|
* xsc_erase_mtdn
|
|
*
|
|
* Erase the MTD blocks of the specified partition
|
|
*
|
|
* progress(int block_num, int erase_block_cnt, void* user_data): prototype for
|
|
* the user function that is called before each block erasure.
|
|
* If NULL the MTD section is wiped in one operation.
|
|
* user_data: pointer to the data that will be feed to the progress function.
|
|
*
|
|
* */
|
|
xsc_status_t xsc_erase_mtdn(xsc_libnor_t desc, int mtdn, void (*progress)(int, int, void *), void *user_data);
|
|
|
|
|
|
/**
|
|
* xsc_libnor_mtd_write
|
|
*
|
|
* Erase the MTD blocks of the specified partition then write the content of
|
|
* the buffer to the partition
|
|
*
|
|
* bufsize should equal MTD size
|
|
*/
|
|
xsc_status_t xsc_libnor_mtd_write(xsc_libnor_t desc, int mtdn, int fd,
|
|
char* buf, size_t bufsize);
|
|
|
|
/**
|
|
* xsc_remount_rw
|
|
*
|
|
* Remount specified filesystem
|
|
* */
|
|
xsc_status_t xsc_remount_rw(const char *name);
|
|
|
|
/**
|
|
* xsc_umount
|
|
*
|
|
* Umount specified filesystem
|
|
* */
|
|
xsc_status_t xsc_umount(const char *name);
|
|
|
|
/**
|
|
* xsc_mtd_is_attached
|
|
*
|
|
* Check wether MTD section is attached to the current UBI filesystem
|
|
*
|
|
* mtdn: MTD number
|
|
* Return the UBI device number
|
|
* */
|
|
int xsc_mtd_is_attached(int mtdn, int *dev_num);
|
|
|
|
/**
|
|
* xsc_mtd_ubi_attach
|
|
*
|
|
* Attach MTD section to a new UBI filesystem. If the MTD section is
|
|
* already attached to a UBI filesystem, do nothing.
|
|
*
|
|
* mtdn: MTD number
|
|
* Return UBI device number
|
|
* */
|
|
xsc_status_t xsc_mtd_ubi_attach(int mtdn, int *dev_num);
|
|
|
|
/**
|
|
* xsc_mtd_ubi_detach
|
|
*
|
|
* Remove specified UBI filesystem.
|
|
*
|
|
* dev_num: UBI device number
|
|
* */
|
|
xsc_status_t xsc_mtd_ubi_detach(int dev_num);
|
|
|
|
/**
|
|
* xsc_libnor_set_writeprotect
|
|
*
|
|
* Lock or unlock a whole (all partitions) NOR chip copy, resets hashes on lock
|
|
* User can provide a callback function for the long operation of reading
|
|
* the whole partition and computing the MD5SUM: md5progress
|
|
* */
|
|
typedef void (*cb_md5_progress_t)(size_t n, size_t total_size, void *user_data);
|
|
|
|
xsc_status_t xsc_libnor_set_writeprotect(xsc_libnor_t desc,
|
|
xsc_bool_t lock, xsc_bool_t auto_lock,
|
|
cb_md5_progress_t md5progress, void *md5progress_user_data);
|
|
|
|
/**
|
|
* xsc_libnor_get_writeprotect
|
|
*
|
|
* Returns the state of the writeprotection on a NOR chip copy.
|
|
*
|
|
* lock: set to 'True' if completely locked, 'False' otherwise
|
|
*
|
|
* */
|
|
xsc_status_t xsc_libnor_get_writeprotect(xsc_libnor_t desc,
|
|
xsc_bool_t *lock);
|
|
|
|
|
|
int xsc_mtd_lock_copy(xsc_libnor_t desc, int mtdn, int lock, int check);
|
|
|
|
/*
|
|
* xsc_mtd_lock_copy_q7ae - Get the locked status of a copy on the Q7AE.
|
|
*
|
|
* On Q7AE, one copy is on 2 chips. This function sets status to TRUE only if both chips are locked.
|
|
*/
|
|
|
|
xsc_status_t xsc_mtd_lock_copy_q7ae(xsc_libnor_t desc, int lock, int check, xsc_bool_t *status);
|
|
|
|
/**
|
|
* xsc_part_getinfo
|
|
*
|
|
* Return the MTD number, the size and the lock status of the specified partition
|
|
*/
|
|
xsc_status_t xsc_part_getinfo(xsc_libnor_t libnor, const char *part,
|
|
int *mtdn, size_t *size, xsc_bool_t *lock);
|
|
|
|
/**
|
|
*
|
|
* To further manipulate the nor flash, one can use the libmtd_t descriptor
|
|
* along with the mtd_num of a partition and <libmtd.h>. See documentation
|
|
* of libmtd.
|
|
*
|
|
* */
|
|
|
|
/* ## Watchdog */
|
|
struct watchdog_s;
|
|
|
|
/**
|
|
* \brief Take control of the watchdog and activate it
|
|
* \param handle Returned handle
|
|
* \return 0 on success, != 0 on failure
|
|
* */
|
|
int xsc_watchdog_init(struct watchdog_s **handle);
|
|
|
|
/**
|
|
* \brief Release the watchdog handle: only stops the watchdog if
|
|
* magic close is set to 1
|
|
*
|
|
* \param handle The handle to release
|
|
* \param magic_close set to 1 to also stop the watchdog
|
|
* \return 0 on success, -1 otherwise
|
|
**/
|
|
int xsc_watchdog_close(struct watchdog_s *handle, int magic_close);
|
|
|
|
/**
|
|
* \brief Keep the watchdog alive
|
|
*
|
|
* \param handle The handle to the initialized watchdog
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_keepalive(struct watchdog_s *handle);
|
|
|
|
/**
|
|
* \brief Disable the watchdog
|
|
*
|
|
* \param handle The handle to the initialized watchdog
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_disable(struct watchdog_s *handle);
|
|
|
|
/**
|
|
* \brief Enable the watchdog
|
|
*
|
|
* \param handle The handle to the initialized watchdog
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_enable(struct watchdog_s *handle);
|
|
|
|
/**
|
|
* \brief Set watchdog timeout after which the ProASIC will
|
|
* reset the SoC
|
|
*
|
|
* \param handle The handle to the initialized watchdog
|
|
* \param timeout_seconds The number of seconds after which the
|
|
* watchdog will reset
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_set_timeout(struct watchdog_s *handle, int timeout_seconds);
|
|
|
|
/**
|
|
* \brief Get watchdog timeout after which the ProASIC will
|
|
* reset the SoC
|
|
*
|
|
* \param handle The handle to the initialized watchdog
|
|
* \param timeout_seconds The number of seconds after which the
|
|
* watchdog will reset
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_get_timeout(struct watchdog_s *handle, int *timeout_seconds);
|
|
|
|
/**
|
|
* \brief Set the no-way-out flag which will prohibit disabling the
|
|
* watchdog
|
|
*
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_set_nowayout();
|
|
|
|
/**
|
|
* \brief Get the status (enabled or disabled) and nowayout flag (set or not)
|
|
*
|
|
* \param nowayout The nowayout flag status (0 = not set, 1 = set)
|
|
* \param status The status flag (0 = watchdog disabled, 1 = watchdog active)
|
|
* \return 0 on success, -1 otherwise
|
|
* */
|
|
int xsc_watchdog_get_status(int *nowayout, int *status);
|
|
|
|
/** Devices management */
|
|
typedef enum {
|
|
XSC_DEV_MMC0 = 0,
|
|
XSC_DEV_MMC1,
|
|
XSC_DEV_MMC_BOTH,
|
|
XSC_DEV_USB,
|
|
} xsc_device_t;
|
|
|
|
/**
|
|
* xsc_device_get_paths - scans the /dev directory, recognize the device entries
|
|
* and return the corresponding devices paths.
|
|
* Paths are stored in strings allocated via malloc() and shall be freed by
|
|
* xsc_device_free_paths.
|
|
*
|
|
* return count
|
|
* */
|
|
int xsc_device_get_paths(xsc_device_t dev, char ***list);
|
|
|
|
void xsc_device_free_paths(int count, char **list);
|
|
|
|
/** USB external storage */
|
|
|
|
xsc_status_t xsc_usb_enable_power(xsc_power_t power);
|
|
|
|
xsc_status_t xsc_usb_get_power_status(xsc_power_t *power);
|
|
|
|
/**
|
|
* xsc_usb_remove_all - disconnect and lock-down all USB devices
|
|
* */
|
|
void xsc_usb_remove_all(void);
|
|
|
|
/**
|
|
* xsc_usb_authorize_all - authorize the USB devices to connect to the system
|
|
* */
|
|
void xsc_usb_authorize_all(void);
|
|
|
|
/** SD external storage */
|
|
|
|
/**
|
|
* Check if any partition of the given slot is mounted.
|
|
*/
|
|
xsc_status_t xsc_sd_ismounted(xsc_device_t slot, int *mounted);
|
|
/**
|
|
* xsc_sd_umount - umount all partitions of the given sd
|
|
* supports XSC_DEV_MMC0, XSC_DEV_MMC1 and XSC_DEV_MMC_BOTH
|
|
*/
|
|
xsc_status_t xsc_sd_umount(xsc_device_t slot);
|
|
|
|
/**
|
|
* xsc_sd_enable_power - enable power on selected devices
|
|
* If force is true, the power off will be done even if partitions are mounted
|
|
* supports XSC_DEV_MMC0, XSC_DEV_MMC1 and XSC_DEV_MMC_BOTH
|
|
*/
|
|
xsc_status_t xsc_sd_set_power(xsc_device_t slot, xsc_power_t power, int force);
|
|
|
|
/**
|
|
* xsc_sd_get_power_status - Get the power status
|
|
* supports XSC_DEV_MMC0 and XSC_DEV_MMC1 only
|
|
*/
|
|
xsc_status_t xsc_sd_get_power_status(xsc_device_t slot, xsc_power_t *power);
|
|
|
|
/**
|
|
* xsc_nor_status - get the current status of the NOR chips.
|
|
* copy is the current selected copy and power is the current power state.
|
|
* If power is OFF, copy is undefined.
|
|
*/
|
|
xsc_status_t xsc_nor_status(xsc_libnor_copy_t *copy, xsc_power_t *power);
|
|
|
|
/**
|
|
* xsc_nor_select - Select the given NOR copy
|
|
*/
|
|
xsc_status_t xsc_nor_select(xsc_libnor_copy_t copy);
|
|
|
|
/**
|
|
* xsc_nor_set_power - Set the NOR power to ON or OFF
|
|
*/
|
|
xsc_status_t xsc_nor_set_power(xsc_power_t power);
|
|
|
|
/**
|
|
* Print the environment.
|
|
*/
|
|
void *xsc_fw_printenv(char *flashbuf, size_t flash_bufsize);
|
|
|
|
/**
|
|
* Search the environment for a variable.
|
|
* Return the value, if found, or NULL, if not found.
|
|
*/
|
|
char *xsc_fw_getenv(const char *name, char *flashbuf, size_t flash_bufsize);
|
|
|
|
/*
|
|
* Set/Clear a single variable in the environment.
|
|
* This is called in sequence to update the environment
|
|
* in RAM without updating the copy in flash after each set
|
|
*/
|
|
int xsc_fw_env_write(const char *name, const char *value, char *flashbuf, size_t flash_bufsize);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // __LIBXIPHOS_H__
|
|
|