mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
Enabled MTD partitions, successfully tested params
This commit is contained in:
@@ -75,14 +75,15 @@ then
|
|||||||
#
|
#
|
||||||
# Load microSD params
|
# Load microSD params
|
||||||
#
|
#
|
||||||
#if ramtron start
|
if mtd start
|
||||||
#then
|
then
|
||||||
# param select /ramtron/params
|
param select /fs/mtd_params
|
||||||
# if [ -f /ramtron/params ]
|
if param load /fs/mtd_params
|
||||||
# then
|
then
|
||||||
# param load /ramtron/params
|
else
|
||||||
# fi
|
echo "FAILED LOADING PARAMS"
|
||||||
#else
|
fi
|
||||||
|
else
|
||||||
param select /fs/microsd/params
|
param select /fs/microsd/params
|
||||||
if [ -f /fs/microsd/params ]
|
if [ -f /fs/microsd/params ]
|
||||||
then
|
then
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ CONFIG_MMCSD_NSLOTS=1
|
|||||||
CONFIG_MMCSD_SPI=y
|
CONFIG_MMCSD_SPI=y
|
||||||
CONFIG_MMCSD_SPICLOCK=24000000
|
CONFIG_MMCSD_SPICLOCK=24000000
|
||||||
# CONFIG_MMCSD_SDIO is not set
|
# CONFIG_MMCSD_SDIO is not set
|
||||||
# CONFIG_MTD is not set
|
CONFIG_MTD=y
|
||||||
CONFIG_PIPES=y
|
CONFIG_PIPES=y
|
||||||
# CONFIG_PM is not set
|
# CONFIG_PM is not set
|
||||||
# CONFIG_POWER is not set
|
# CONFIG_POWER is not set
|
||||||
@@ -482,6 +482,25 @@ CONFIG_USART1_SERIAL_CONSOLE=y
|
|||||||
# CONFIG_USART6_SERIAL_CONSOLE is not set
|
# CONFIG_USART6_SERIAL_CONSOLE is not set
|
||||||
# CONFIG_NO_SERIAL_CONSOLE is not set
|
# CONFIG_NO_SERIAL_CONSOLE is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# MTD Configuration
|
||||||
|
#
|
||||||
|
CONFIG_MTD_PARTITION=y
|
||||||
|
CONFIG_MTD_BYTE_WRITE=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# MTD Device Drivers
|
||||||
|
#
|
||||||
|
# CONFIG_RAMMTD is not set
|
||||||
|
# CONFIG_MTD_AT24XX is not set
|
||||||
|
# CONFIG_MTD_AT45DB is not set
|
||||||
|
# CONFIG_MTD_M25P is not set
|
||||||
|
# CONFIG_MTD_SMART is not set
|
||||||
|
# CONFIG_MTD_RAMTRON is not set
|
||||||
|
# CONFIG_MTD_SST25 is not set
|
||||||
|
# CONFIG_MTD_SST39FV is not set
|
||||||
|
# CONFIG_MTD_W25 is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# USART1 Configuration
|
# USART1 Configuration
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ CONFIG_MTD=y
|
|||||||
#
|
#
|
||||||
# MTD Configuration
|
# MTD Configuration
|
||||||
#
|
#
|
||||||
# CONFIG_MTD_PARTITION is not set
|
CONFIG_MTD_PARTITION=y
|
||||||
CONFIG_MTD_BYTE_WRITE=y
|
CONFIG_MTD_BYTE_WRITE=y
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2012-2014 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -512,6 +512,22 @@ param_save_default(void)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
const char *filename = param_get_default_file();
|
const char *filename = param_get_default_file();
|
||||||
|
|
||||||
|
/* write parameters to temp file */
|
||||||
|
fd = open(filename, O_WRONLY);
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
warn("failed to open param file: %s", filename);
|
||||||
|
res = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == OK) {
|
||||||
|
res = param_export(fd, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
#if 0
|
||||||
const char *filename_tmp = malloc(strlen(filename) + 5);
|
const char *filename_tmp = malloc(strlen(filename) + 5);
|
||||||
sprintf(filename_tmp, "%s.tmp", filename);
|
sprintf(filename_tmp, "%s.tmp", filename);
|
||||||
|
|
||||||
@@ -563,6 +579,7 @@ param_save_default(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(filename_tmp);
|
free(filename_tmp);
|
||||||
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -573,9 +590,9 @@ param_save_default(void)
|
|||||||
int
|
int
|
||||||
param_load_default(void)
|
param_load_default(void)
|
||||||
{
|
{
|
||||||
int fd = open(param_get_default_file(), O_RDONLY);
|
int fd_load = open(param_get_default_file(), O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd_load < 0) {
|
||||||
/* no parameter file is OK, otherwise this is an error */
|
/* no parameter file is OK, otherwise this is an error */
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
warn("open '%s' for reading failed", param_get_default_file());
|
warn("open '%s' for reading failed", param_get_default_file());
|
||||||
@@ -584,8 +601,8 @@ param_load_default(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = param_load(fd);
|
int result = param_load(fd_load);
|
||||||
close(fd);
|
close(fd_load);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
warn("error reading parameters from '%s'", param_get_default_file());
|
warn("error reading parameters from '%s'", param_get_default_file());
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ static void mtd_test(void);
|
|||||||
static bool attached = false;
|
static bool attached = false;
|
||||||
static bool started = false;
|
static bool started = false;
|
||||||
static struct mtd_dev_s *mtd_dev;
|
static struct mtd_dev_s *mtd_dev;
|
||||||
static const int n_partitions_default = 2;
|
|
||||||
|
|
||||||
/* note, these will be equally sized */
|
/* note, these will be equally sized */
|
||||||
static char *partition_names_default[n_partitions] = {"/dev/mtd_params", "/dev/mtd_waypoints"};
|
static char *partition_names_default[] = {"/fs/mtd_params", "/fs/mtd_waypoints"};
|
||||||
|
static const int n_partitions_default = sizeof(partition_names_default) / sizeof(partition_names_default[0]);
|
||||||
|
|
||||||
int mtd_main(int argc, char *argv[])
|
int mtd_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,8 @@ int mtd_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev);
|
struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev);
|
||||||
|
struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd,
|
||||||
|
off_t firstblock, off_t nblocks);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mtd_attach(void)
|
mtd_attach(void)
|
||||||
@@ -157,7 +158,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
mtd_attach();
|
mtd_attach();
|
||||||
|
|
||||||
if (!mtd_dev) {
|
if (!mtd_dev) {
|
||||||
warnx("ERROR: Failed to create RAMTRON FRAM MTD instance\n");
|
warnx("ERROR: Failed to create RAMTRON FRAM MTD instance");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,17 +167,17 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
|
|
||||||
FAR struct mtd_geometry_s geo;
|
FAR struct mtd_geometry_s geo;
|
||||||
|
|
||||||
ret = mtd_dev->ioctl(master, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
|
ret = mtd_dev->ioctl(mtd_dev, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fdbg("ERROR: mtd->ioctl failed: %d\n", ret);
|
warnx("ERROR: mtd->ioctl failed: %d", ret);
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
warnx("Flash Geometry:\n");
|
warnx("Flash Geometry:");
|
||||||
warnx(" blocksize: %lu\n", (unsigned long)geo.blocksize);
|
warnx(" blocksize: %lu", (unsigned long)geo.blocksize);
|
||||||
warnx(" erasesize: %lu\n", (unsigned long)geo.erasesize);
|
warnx(" erasesize: %lu", (unsigned long)geo.erasesize);
|
||||||
warnx(" neraseblocks: %lu\n", (unsigned long)geo.neraseblocks);
|
warnx(" neraseblocks: %lu", (unsigned long)geo.neraseblocks);
|
||||||
|
|
||||||
/* Determine the size of each partition. Make each partition an even
|
/* Determine the size of each partition. Make each partition an even
|
||||||
* multiple of the erase block size (perhaps not using some space at the
|
* multiple of the erase block size (perhaps not using some space at the
|
||||||
@@ -187,18 +188,21 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
unsigned nblocks = (geo.neraseblocks / n_partitions) * blkpererase;
|
unsigned nblocks = (geo.neraseblocks / n_partitions) * blkpererase;
|
||||||
unsigned partsize = nblocks * geo.blocksize;
|
unsigned partsize = nblocks * geo.blocksize;
|
||||||
|
|
||||||
warnx(" No. partitions: %u\n", n_partitions);
|
warnx(" No. partitions: %u", n_partitions);
|
||||||
warnx(" Partition size: %lu Blocks (%lu bytes)\n", nblocks, partsize);
|
warnx(" Partition size: %lu Blocks (%lu bytes)", nblocks, partsize);
|
||||||
|
|
||||||
/* Now create MTD FLASH partitions */
|
/* Now create MTD FLASH partitions */
|
||||||
|
|
||||||
warnx("Creating partitions\n");
|
warnx("Creating partitions");
|
||||||
FAR struct mtd_dev_s *part[n_partitions];
|
FAR struct mtd_dev_s *part[n_partitions];
|
||||||
char blockname[32];
|
char blockname[32];
|
||||||
|
|
||||||
for (unsigned offset = 0, unsigned i = 0; i < n_partitions; offset += nblocks, i++) {
|
unsigned offset;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
warnx(" Partition %d. Block offset=%lu, size=%lu\n",
|
for (offset = 0, i = 0; i < n_partitions; offset += nblocks, i++) {
|
||||||
|
|
||||||
|
warnx(" Partition %d. Block offset=%lu, size=%lu",
|
||||||
i, (unsigned long)offset, (unsigned long)nblocks);
|
i, (unsigned long)offset, (unsigned long)nblocks);
|
||||||
|
|
||||||
/* Create the partition */
|
/* Create the partition */
|
||||||
@@ -206,7 +210,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
part[i] = mtd_partition(mtd_dev, offset, nblocks);
|
part[i] = mtd_partition(mtd_dev, offset, nblocks);
|
||||||
|
|
||||||
if (!part[i]) {
|
if (!part[i]) {
|
||||||
warnx("ERROR: mtd_partition failed. offset=%lu nblocks=%lu\n",
|
warnx("ERROR: mtd_partition failed. offset=%lu nblocks=%lu",
|
||||||
(unsigned long)offset, (unsigned long)nblocks);
|
(unsigned long)offset, (unsigned long)nblocks);
|
||||||
fsync(stderr);
|
fsync(stderr);
|
||||||
exit(4);
|
exit(4);
|
||||||
@@ -219,7 +223,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
ret = ftl_initialize(i, part[i]);
|
ret = ftl_initialize(i, part[i]);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
warnx("ERROR: ftl_initialize %s failed: %d\n", blockname, ret);
|
warnx("ERROR: ftl_initialize %s failed: %d", blockname, ret);
|
||||||
fsync(stderr);
|
fsync(stderr);
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
@@ -229,7 +233,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
|
|||||||
ret = bchdev_register(blockname, partition_names[i], false);
|
ret = bchdev_register(blockname, partition_names[i], false);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
warnx("ERROR: bchdev_register %s failed: %d\n", charname, ret);
|
warnx("ERROR: bchdev_register %s failed: %d", partition_names[i], ret);
|
||||||
fsync(stderr);
|
fsync(stderr);
|
||||||
exit(6);
|
exit(6);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user