Newer
Older
/****************************************************************************
*
* Copyright (C) 2012, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Copyright (C) 2018 Sebastien Lorquet. All rights reserved.
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/kmalloc.h>
#include "stm32.h"
#include "hn70ap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_MTD_PARTITION
#error MTD partition support is required
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
struct mtd_partition_info_s
{
const char *name;
size_t blocks; //number of blocks (for sst26 this is 256 bytes)
};
static const struct mtd_partition_info_s parts[] =
{
{"firmware", 8192}, // 2MB
{"storage" , 24576} // 6MB
#define PARTCOUNT (sizeof(parts)/sizeof(parts[0]))
FAR struct mtd_dev_s *mtdparts[PARTCOUNT];
{
FAR struct spi_dev_s *spi2;
FAR struct mtd_dev_s *mtd;
struct mtd_geometry_s geo;
int ret;
/* Get the SPI port */
spi2 = stm32_spibus_initialize(2);
if (!spi2)
{
return -ENODEV;
}
/* Now bind the SPI interface to the SST25F064 SPI FLASH driver. */
if (!mtd)
{
_err("ERROR: Failed to bind SPI port 2 to the SPI FLASH driver\n");
}
syslog(
LOG_INFO,
"SST26: %d erase blocks each %d bytes (total %d kB), blocksize %d\n",
geo.neraseblocks,
geo.erasesize,
(geo.neraseblocks * geo.erasesize) >> 10,
geo.blocksize
);
/* Now create partitions on the FLASH device */
partoffset = 0;
for(partno = 0; partno<PARTCOUNT; partno++)
{
mtdparts[partno] = mtd_partition(mtd, partoffset, parts[partno].blocks);
partoffset += parts[partno].blocks;
_err("ERROR: failed to create partition %s\n", parts[partno].name);
/* Now initialize a SMART Flash block device and bind it
* to the MTD device.
*/
#if defined(CONFIG_MTD_PARTITION_NAMES)
#endif
syslog(LOG_INFO, "SST26: Created partition %s (%d blocks)\n", parts[partno].name, parts[partno].blocks);
/* Create char device for firmware update partition */
mtdchar_register(mtdparts[0], "/dev/firmware");
_info("Registered /dev/firmware\n");
#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
smart_initialize(0, mtdparts[1], "p1");
#endif