lib/fw.c
/**
 * @brief Retrieve information about a firmware image file
 * @param[in]  fd	File descriptor for the image file to inspect
 * @param[out] info	Structure populated with information about the file
 * @return 0 on success, error code on failure
 */
@brief Retrieve information about a firmware image file
@param[in]  fd       File descriptor for the image file to inspect
@param[out] info     Structure populated with information about the file
@return 0 on success, error code on failure
@brief Retrieve information about a firmware image file @param [ in ] fd File descriptor for the image file to inspect @param [ out ] info Structure populated with information about the file @return 0 on success error code on failure
int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info)
{
	int ret;
	struct fw_image_header hdr = {};
	ret = read(fd, &hdr, sizeof(hdr));
	lseek(fd, 0, SEEK_SET);
	if (ret != sizeof(hdr))
		goto invalid_file;
	if (strcmp(hdr.magic, "PMC") != 0)
		goto invalid_file;
	if (info == NULL)
		return 0;
	info->type = hdr.type;
	info->crc = le32toh(hdr.image_crc);
	version_to_string(hdr.version, info->version, sizeof(info->version));
	info->image_addr = le32toh(hdr.load_addr);
	info->image_len = le32toh(hdr.image_len);
	return 0;
invalid_file:
	errno = ENOEXEC;
	return -errno;
}
int switchtec_fw_file_info ( int fd , struct switchtec_fw_image_info * info ) { int ret ; struct fw_image_header hdr = { } ; ret = read ( fd , & hdr , sizeof ( hdr ) ) ; lseek ( fd , 0 , SEEK_SET ) ; if ( ret != sizeof ( hdr ) ) goto invalid_file ; if ( strcmp ( hdr . magic , " " ) != 0 ) goto invalid_file ; if ( info == NULL ) return 0 ; info -> type = hdr . type ; info -> crc = le32toh ( hdr . image_crc ) ; version_to_string ( hdr . version , info -> version , sizeof ( info -> version ) ) ; info -> image_addr = le32toh ( hdr . load_addr ) ; info -> image_len = le32toh ( hdr . image_len ) ; return 0 ; invalid_file : errno = ENOEXEC ; return - errno ; }
@brief Retrieve information about a firmware image file
 @param[in]  fd       File descriptor for the image file to inspect
 @param[out] info     Structure populated with information about the file
 @return 0 on success, error code on failure
@brief Retrieve information about a firmware image file @param [ in ] fd File descriptor for the image file to inspect @param [ out ] info Structure populated with information about the file @return 0 on success error code on failure