8f34c2760d
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
118 lines
3.0 KiB
C
118 lines
3.0 KiB
C
/*
|
|
* Copyright (c) 2022 rockchip
|
|
*
|
|
*/
|
|
|
|
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include "iio.h"
|
|
#include "rk_sysfs.h"
|
|
|
|
static int calc_digits(int num)
|
|
{
|
|
int count = 0;
|
|
|
|
while (num != 0) {
|
|
num /= 10;
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
int iio_find_type_by_name(const char *name, const char *type)
|
|
{
|
|
const struct dirent *ent;
|
|
int number, numstrlen, ret;
|
|
|
|
FILE *namefp;
|
|
DIR *dp;
|
|
char thisname[IIO_MAX_NAME_LENGTH];
|
|
char *filename;
|
|
|
|
dp = opendir(IIO_SYSFS_PATH);
|
|
if (!dp) {
|
|
fprintf(stderr, "No industrialio devices available\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
while (ent = readdir(dp), ent) {
|
|
if (strcmp(ent->d_name, ".") != 0 &&
|
|
strcmp(ent->d_name, "..") != 0 &&
|
|
strlen(ent->d_name) > strlen(type) &&
|
|
strncmp(ent->d_name, type, strlen(type)) == 0) {
|
|
errno = 0;
|
|
ret = sscanf(ent->d_name + strlen(type), "%d", &number);
|
|
if (ret < 0) {
|
|
ret = -errno;
|
|
fprintf(stderr,
|
|
"failed to read element number\n");
|
|
goto error_close_dir;
|
|
} else if (ret != 1) {
|
|
ret = -EIO;
|
|
fprintf(stderr,
|
|
"failed to match element number\n");
|
|
goto error_close_dir;
|
|
}
|
|
|
|
numstrlen = calc_digits(number);
|
|
/* verify the next character is not a colon */
|
|
if (strncmp(ent->d_name + strlen(type) + numstrlen,
|
|
":", 1) != 0) {
|
|
filename = (char *)malloc(strlen(IIO_SYSFS_PATH)
|
|
+ strlen(type) + numstrlen + 6);
|
|
if (!filename) {
|
|
ret = -ENOMEM;
|
|
goto error_close_dir;
|
|
}
|
|
|
|
ret = sprintf(filename, "%s%s%d/name",
|
|
IIO_SYSFS_PATH, type, number);
|
|
if (ret < 0) {
|
|
free(filename);
|
|
goto error_close_dir;
|
|
}
|
|
|
|
namefp = fopen(filename, "r");
|
|
if (!namefp) {
|
|
free(filename);
|
|
continue;
|
|
}
|
|
|
|
free(filename);
|
|
errno = 0;
|
|
if (fscanf(namefp, "%s", thisname) != 1) {
|
|
ret = errno ? -errno : -ENODATA;
|
|
goto error_close_dir;
|
|
}
|
|
|
|
if (fclose(namefp)) {
|
|
ret = -errno;
|
|
goto error_close_dir;
|
|
}
|
|
|
|
if (strcmp(name, thisname) == 0) {
|
|
if (closedir(dp) == -1)
|
|
return -errno;
|
|
|
|
return number;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (closedir(dp) == -1)
|
|
return -errno;
|
|
|
|
return -ENODEV;
|
|
|
|
error_close_dir:
|
|
if (closedir(dp) == -1)
|
|
perror("find_type_by_name(): Failed to close directory");
|
|
|
|
return ret;
|
|
}
|