aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-01-12 16:33:23 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-01-12 16:33:23 +0100
commit3387aa64d40dc7be2900b0368293d9997b97005a (patch)
tree894d644613fa642f617af09bdc4252340a0b580f
parent17a478a190d1349b74f34933a6d300a04fdb229d (diff)
downloadpx4-firmware-3387aa64d40dc7be2900b0368293d9997b97005a.tar.gz
px4-firmware-3387aa64d40dc7be2900b0368293d9997b97005a.tar.bz2
px4-firmware-3387aa64d40dc7be2900b0368293d9997b97005a.zip
Enabled MTD partitions, successfully tested params
-rw-r--r--ROMFS/px4fmu_common/init.d/rcS17
-rw-r--r--nuttx-configs/px4fmu-v1/nsh/defconfig21
-rw-r--r--nuttx-configs/px4fmu-v2/nsh/defconfig2
-rw-r--r--src/modules/systemlib/param/param.c27
-rw-r--r--src/systemcmds/mtd/mtd.c40
5 files changed, 74 insertions, 33 deletions
diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS
index 66cb3f237..8de615746 100644
--- a/ROMFS/px4fmu_common/init.d/rcS
+++ b/ROMFS/px4fmu_common/init.d/rcS
@@ -75,14 +75,15 @@ then
#
# Load microSD params
#
- #if ramtron start
- #then
- # param select /ramtron/params
- # if [ -f /ramtron/params ]
- # then
- # param load /ramtron/params
- # fi
- #else
+ if mtd start
+ then
+ param select /fs/mtd_params
+ if param load /fs/mtd_params
+ then
+ else
+ echo "FAILED LOADING PARAMS"
+ fi
+ else
param select /fs/microsd/params
if [ -f /fs/microsd/params ]
then
diff --git a/nuttx-configs/px4fmu-v1/nsh/defconfig b/nuttx-configs/px4fmu-v1/nsh/defconfig
index e60120b49..1dc96b3c3 100644
--- a/nuttx-configs/px4fmu-v1/nsh/defconfig
+++ b/nuttx-configs/px4fmu-v1/nsh/defconfig
@@ -460,7 +460,7 @@ CONFIG_MMCSD_NSLOTS=1
CONFIG_MMCSD_SPI=y
CONFIG_MMCSD_SPICLOCK=24000000
# CONFIG_MMCSD_SDIO is not set
-# CONFIG_MTD is not set
+CONFIG_MTD=y
CONFIG_PIPES=y
# CONFIG_PM is not set
# CONFIG_POWER is not set
@@ -483,6 +483,25 @@ CONFIG_USART1_SERIAL_CONSOLE=y
# 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
#
CONFIG_USART1_RXBUFSIZE=512
diff --git a/nuttx-configs/px4fmu-v2/nsh/defconfig b/nuttx-configs/px4fmu-v2/nsh/defconfig
index ad845e095..2a734c27e 100644
--- a/nuttx-configs/px4fmu-v2/nsh/defconfig
+++ b/nuttx-configs/px4fmu-v2/nsh/defconfig
@@ -500,7 +500,7 @@ CONFIG_MTD=y
#
# MTD Configuration
#
-# CONFIG_MTD_PARTITION is not set
+CONFIG_MTD_PARTITION=y
CONFIG_MTD_BYTE_WRITE=y
#
diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c
index 398657dd7..b12ba2919 100644
--- a/src/modules/systemlib/param/param.c
+++ b/src/modules/systemlib/param/param.c
@@ -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
* modification, are permitted provided that the following conditions
@@ -512,6 +512,22 @@ param_save_default(void)
int fd;
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);
sprintf(filename_tmp, "%s.tmp", filename);
@@ -563,6 +579,7 @@ param_save_default(void)
}
free(filename_tmp);
+#endif
return res;
}
@@ -573,9 +590,9 @@ param_save_default(void)
int
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 */
if (errno != ENOENT) {
warn("open '%s' for reading failed", param_get_default_file());
@@ -584,8 +601,8 @@ param_load_default(void)
return 1;
}
- int result = param_load(fd);
- close(fd);
+ int result = param_load(fd_load);
+ close(fd_load);
if (result != 0) {
warn("error reading parameters from '%s'", param_get_default_file());
diff --git a/src/systemcmds/mtd/mtd.c b/src/systemcmds/mtd/mtd.c
index 36ff7e262..5104df09e 100644
--- a/src/systemcmds/mtd/mtd.c
+++ b/src/systemcmds/mtd/mtd.c
@@ -81,10 +81,10 @@ static void mtd_test(void);
static bool attached = false;
static bool started = false;
static struct mtd_dev_s *mtd_dev;
-static const int n_partitions_default = 2;
/* 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[])
{
@@ -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 *mtd_partition(FAR struct mtd_dev_s *mtd,
+ off_t firstblock, off_t nblocks);
static void
mtd_attach(void)
@@ -157,7 +158,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
mtd_attach();
if (!mtd_dev) {
- warnx("ERROR: Failed to create RAMTRON FRAM MTD instance\n");
+ warnx("ERROR: Failed to create RAMTRON FRAM MTD instance");
exit(1);
}
@@ -166,17 +167,17 @@ mtd_start(char *partition_names[], unsigned n_partitions)
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) {
- fdbg("ERROR: mtd->ioctl failed: %d\n", ret);
+ warnx("ERROR: mtd->ioctl failed: %d", ret);
exit(3);
}
- warnx("Flash Geometry:\n");
- warnx(" blocksize: %lu\n", (unsigned long)geo.blocksize);
- warnx(" erasesize: %lu\n", (unsigned long)geo.erasesize);
- warnx(" neraseblocks: %lu\n", (unsigned long)geo.neraseblocks);
+ warnx("Flash Geometry:");
+ warnx(" blocksize: %lu", (unsigned long)geo.blocksize);
+ warnx(" erasesize: %lu", (unsigned long)geo.erasesize);
+ warnx(" neraseblocks: %lu", (unsigned long)geo.neraseblocks);
/* Determine the size of each partition. Make each partition an even
* 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 partsize = nblocks * geo.blocksize;
- warnx(" No. partitions: %u\n", n_partitions);
- warnx(" Partition size: %lu Blocks (%lu bytes)\n", nblocks, partsize);
+ warnx(" No. partitions: %u", n_partitions);
+ warnx(" Partition size: %lu Blocks (%lu bytes)", nblocks, partsize);
/* Now create MTD FLASH partitions */
- warnx("Creating partitions\n");
+ warnx("Creating partitions");
FAR struct mtd_dev_s *part[n_partitions];
char blockname[32];
- for (unsigned offset = 0, unsigned i = 0; i < n_partitions; offset += nblocks, i++) {
+ unsigned offset;
+ unsigned i;
+
+ for (offset = 0, i = 0; i < n_partitions; offset += nblocks, i++) {
- warnx(" Partition %d. Block offset=%lu, size=%lu\n",
+ warnx(" Partition %d. Block offset=%lu, size=%lu",
i, (unsigned long)offset, (unsigned long)nblocks);
/* Create the partition */
@@ -206,7 +210,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
part[i] = mtd_partition(mtd_dev, offset, nblocks);
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);
fsync(stderr);
exit(4);
@@ -219,7 +223,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
ret = ftl_initialize(i, part[i]);
if (ret < 0) {
- warnx("ERROR: ftl_initialize %s failed: %d\n", blockname, ret);
+ warnx("ERROR: ftl_initialize %s failed: %d", blockname, ret);
fsync(stderr);
exit(5);
}
@@ -229,7 +233,7 @@ mtd_start(char *partition_names[], unsigned n_partitions)
ret = bchdev_register(blockname, partition_names[i], false);
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);
exit(6);
}