forked from xuos/xiuos
support hc32 irq and spi and spi flash
This commit is contained in:
@@ -11,4 +11,27 @@ config HC32F4A0_BOARD
|
||||
---help---
|
||||
Select if you are using the HC32F4A0 base board with the HC32F4A0.
|
||||
|
||||
config HC32_ROMFS
|
||||
bool "Automount baked-in ROMFS image"
|
||||
default n
|
||||
depends on FS_ROMFS
|
||||
---help---
|
||||
Select HC32_ROMFS_IMAGEFILE, HC32_ROMFS_DEV_MINOR, HC32_ROMFS_MOUNTPOINT
|
||||
|
||||
config HC32_ROMFS_DEV_MINOR
|
||||
int "Minor for the block device backing the data"
|
||||
depends on HC32_ROMFS
|
||||
default 64
|
||||
|
||||
config HC32_ROMFS_MOUNTPOINT
|
||||
string "Mountpoint of the custom romfs image"
|
||||
depends on HC32_ROMFS
|
||||
default "/rom"
|
||||
|
||||
config HC32_ROMFS_IMAGEFILE
|
||||
string "ROMFS image file to include into build"
|
||||
depends on HC32_ROMFS
|
||||
default "../../../../../rom.img"
|
||||
|
||||
|
||||
endif
|
||||
|
||||
@@ -57,38 +57,42 @@
|
||||
/* for lowputc device output */
|
||||
|
||||
/* UART RX/TX Port/Pin definition */
|
||||
#define LP_RX_PORT (GPIO_PORT_H) /* PH6: USART6_RX */
|
||||
#define LP_RX_PIN (GPIO_PIN_06)
|
||||
#define LP_RX_GPIO_FUNC (GPIO_FUNC_37_USART6_RX)
|
||||
#define DBG_RX_PORT (GPIO_PORT_H) /* PH6: USART6_RX */
|
||||
#define DBG_RX_PIN (GPIO_PIN_06)
|
||||
#define DBG_RX_GPIO_FUNC (GPIO_FUNC_37_USART6_RX)
|
||||
|
||||
#define LP_TX_PORT (GPIO_PORT_E) /* PE6: USART6_TX */
|
||||
#define LP_TX_PIN (GPIO_PIN_06)
|
||||
#define LP_TX_GPIO_FUNC (GPIO_FUNC_36_USART6_TX)
|
||||
#define DBG_TX_PORT (GPIO_PORT_E) /* PE6: USART6_TX */
|
||||
#define DBG_TX_PIN (GPIO_PIN_06)
|
||||
#define DBG_TX_GPIO_FUNC (GPIO_FUNC_36_USART6_TX)
|
||||
|
||||
/* UART unit definition */
|
||||
#define LP_UNIT (M4_USART6)
|
||||
#define LP_FUNCTION_CLK_GATE (PWC_FCG3_USART6)
|
||||
#define DBG_UNIT (M4_USART6)
|
||||
#define DBG_BAUDRATE (115200UL)
|
||||
#define DBG_FUNCTION_CLK_GATE (PWC_FCG3_USART6)
|
||||
|
||||
/* UART unit interrupt definition */
|
||||
#define LP_UNIT_ERR_INT_SRC (INT_USART6_EI)
|
||||
#define LP_UNIT_ERR_INT_IRQn (Int015_IRQn + HC32_IRQ_FIRST)
|
||||
#define DBG_UNIT_ERR_INT_SRC (INT_USART6_EI)
|
||||
#define DBG_UNIT_ERR_INT_IRQn (Int010_IRQn)
|
||||
|
||||
#define LP_UNIT_RX_INT_SRC (INT_USART6_RI)
|
||||
#define LP_UNIT_RX_INT_IRQn (Int103_IRQn + HC32_IRQ_FIRST)
|
||||
#define DBG_UNIT_RX_INT_SRC (INT_USART6_RI)
|
||||
#define DBG_UNIT_RX_INT_IRQn (Int011_IRQn)
|
||||
|
||||
#define LP_UNIT_TX_INT_SRC (INT_USART6_TI)
|
||||
#define LP_UNIT_TX_INT_IRQn (Int102_IRQn + HC32_IRQ_FIRST)
|
||||
#define DBG_RXTO_INT_SRC (INT_USART6_RTO)
|
||||
#define DBG_RXTO_INT_IRQn (Int012_IRQn)
|
||||
|
||||
#define LP_UNIT_TCI_INT_SRC (INT_USART6_TCI)
|
||||
#define LP_UNIT_TCI_INT_IRQn (Int099_IRQn + HC32_IRQ_FIRST)
|
||||
#define DBG_UNIT_TX_INT_SRC (INT_USART6_TI)
|
||||
#define DBG_UNIT_TX_INT_IRQn (Int013_IRQn)
|
||||
|
||||
#define DBG_UNIT_TCI_INT_SRC (INT_USART6_TCI)
|
||||
#define DBG_UNIT_TCI_INT_IRQn (Int014_IRQn)
|
||||
|
||||
/* printf device s*/
|
||||
#define BSP_PRINTF_DEVICE LP_UNIT
|
||||
#define BSP_PRINTF_BAUDRATE (115200)
|
||||
#define BSP_PRINTF_DEVICE DBG_UNIT
|
||||
#define BSP_PRINTF_BAUDRATE DBG_BAUDRATE
|
||||
|
||||
#define BSP_PRINTF_PORT LP_TX_PORT
|
||||
#define BSP_PRINTF_PORT DBG_TX_PORT
|
||||
|
||||
#define BSP_PRINTF_PIN LP_TX_PIN
|
||||
#define BSP_PRINTF_PORT_FUNC LP_TX_GPIO_FUNC
|
||||
#define BSP_PRINTF_PIN DBG_TX_PIN
|
||||
#define BSP_PRINTF_PORT_FUNC DBG_TX_GPIO_FUNC
|
||||
|
||||
#endif /* __BOARDS_ARM_HC32_HC32F4A0_INCLUDE_BOARD_H */
|
||||
|
||||
@@ -41,7 +41,7 @@ USER_LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"
|
||||
|
||||
# Source files
|
||||
|
||||
CSRCS = stm32_userspace.c
|
||||
CSRCS = hc32_userspace.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
OBJS = $(COBJS)
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
# error "CONFIG_NUTTX_USERSPACE not defined"
|
||||
#endif
|
||||
|
||||
#if CONFIG_NUTTX_USERSPACE != 0x20060000
|
||||
#if CONFIG_NUTTX_USERSPACE != 0x20062000
|
||||
# error "CONFIG_NUTTX_USERSPACE must be 0x20060000 to match memory.ld"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/aiit-arm32-board/scripts/gnu-elf.ld
|
||||
* boards/arm/hc32/hc32f4a0/scripts/gnu-elf.ld
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/aiit-arm32-board/scripts/kernel-space.ld
|
||||
* boards/arm/hc32/hc32f4a0/scripts/kernel-space.ld
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* For MPU support, the kernel-mode NuttX section is assumed to be 128Kb of
|
||||
* FLASH and 4Kb of SRAM. That is an excessive amount for the kernel which
|
||||
* should fit into 64KB and, of course, can be optimized as needed (See
|
||||
* also boards/arm/stm32/aiit-arm32-board/scripts/kernel-space.ld). Allowing the
|
||||
* also boards/arm/hc32/hc32f4a0/scripts/kernel-space.ld). Allowing the
|
||||
* additional does permit addition debug instrumentation to be added to the
|
||||
* kernel space without overflowing the partition.
|
||||
*
|
||||
@@ -73,13 +73,13 @@ MEMORY
|
||||
{
|
||||
/* 2Mb FLASH */
|
||||
|
||||
kflash (rx) : ORIGIN = 0x00000000, LENGTH = 2M
|
||||
uflash (rx) : ORIGIN = 0x00200000, LENGTH = 128K
|
||||
xflash (rx) : ORIGIN = 0x00220000, LENGTH = 768K
|
||||
kflash (rx) : ORIGIN = 0x00000000, LENGTH = 64K
|
||||
uflash (rx) : ORIGIN = 0x00010000, LENGTH = 1M
|
||||
xflash (rx) : ORIGIN = 0x00110000, LENGTH = 128K
|
||||
|
||||
/* 512Kb of contiguous SRAM */
|
||||
|
||||
ksram (rwx) : ORIGIN = 0x1FFE0000, LENGTH = 512K
|
||||
usram (rwx) : ORIGIN = 0x20060000, LENGTH = 4K
|
||||
xsram (rwx) : ORIGIN = 0x20062000, LENGTH = 4K
|
||||
ksram (rwx) : ORIGIN = 0x1FFE0000, LENGTH = 64K
|
||||
usram (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 448K
|
||||
xsram (rwx) : ORIGIN = 0x20070000, LENGTH = 4K
|
||||
}
|
||||
|
||||
@@ -48,16 +48,16 @@ SECTIONS
|
||||
_sinit = ABSOLUTE(.);
|
||||
*(.init_array .init_array.*)
|
||||
_einit = ABSOLUTE(.);
|
||||
} > kflash
|
||||
} > uflash
|
||||
|
||||
.ARM.extab : {
|
||||
*(.ARM.extab*)
|
||||
} > kflash
|
||||
} > uflash
|
||||
|
||||
__exidx_start = ABSOLUTE(.);
|
||||
.ARM.exidx : {
|
||||
*(.ARM.exidx*)
|
||||
} > kflash
|
||||
} > uflash
|
||||
|
||||
__exidx_end = ABSOLUTE(.);
|
||||
|
||||
@@ -70,7 +70,7 @@ SECTIONS
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(4);
|
||||
_edata = ABSOLUTE(.);
|
||||
} > ksram AT > kflash
|
||||
} > usram AT > uflash
|
||||
|
||||
.bss : {
|
||||
_sbss = ABSOLUTE(.);
|
||||
@@ -79,7 +79,7 @@ SECTIONS
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = ABSOLUTE(.);
|
||||
} > ksram
|
||||
} > usram
|
||||
|
||||
/* Stabs debugging sections */
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ ifeq ($(CONFIG_ARCH_LEDS),y)
|
||||
CSRCS +=
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32_ROMFS),y)
|
||||
CSRCS += hc32_romfs_initialize.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path board
|
||||
VPATH += :board
|
||||
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
extern int hc32_bringup(void);
|
||||
extern int hc32_spidev_initialized;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hc32_boardinitialize
|
||||
@@ -52,57 +53,57 @@ extern int hc32_bringup(void);
|
||||
|
||||
void hc32_boardinitialize(void)
|
||||
{
|
||||
//#ifdef CONFIG_SCHED_CRITMONITOR
|
||||
// /* Enable ITM and DWT resources, if not left enabled by debugger. */
|
||||
//
|
||||
// modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
|
||||
//
|
||||
// /* Make sure the high speed cycle counter is running. It will be started
|
||||
// * automatically only if a debugger is connected.
|
||||
// */
|
||||
//
|
||||
// putreg32(0xc5acce55, ITM_LAR);
|
||||
// modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
|
||||
//#endif
|
||||
//
|
||||
//#if defined(CONFIG_HC32_SPI1) || defined(CONFIG_HC32_SPI2) || defined(CONFIG_HC32_SPI3)
|
||||
// /* Configure SPI chip selects if 1) SPI is not disabled, and 2) the weak
|
||||
// * function hc32_spidev_initialize() has been brought into the link.
|
||||
// */
|
||||
//
|
||||
// if (hc32_spidev_initialize)
|
||||
// {
|
||||
// hc32_spidev_initialize();
|
||||
// }
|
||||
//#endif
|
||||
//
|
||||
//#ifdef CONFIG_HC32_OTGFS
|
||||
// /* Initialize USB if the 1) OTG FS controller is in the configuration and
|
||||
// * 2) disabled, and 3) the weak function hc32_usbinitialize() has been
|
||||
// * brought into the build. Presumably either CONFIG_USBDEV or
|
||||
// * CONFIG_USBHOST is also selected.
|
||||
// */
|
||||
//
|
||||
// if (hc32_usbinitialize)
|
||||
// {
|
||||
// hc32_usbinitialize();
|
||||
// }
|
||||
//#endif
|
||||
//
|
||||
//#ifdef HAVE_NETMONITOR
|
||||
// /* Configure board resources to support networking. */
|
||||
//
|
||||
// if (hc32_netinitialize)
|
||||
// {
|
||||
// hc32_netinitialize();
|
||||
// }
|
||||
//#endif
|
||||
//
|
||||
//#ifdef CONFIG_ARCH_LEDS
|
||||
// /* Configure on-board LEDs if LED support has been selected. */
|
||||
//
|
||||
// board_autoled_initialize();
|
||||
//#endif
|
||||
#ifdef CONFIG_SCHED_CRITMONITOR
|
||||
/* Enable ITM and DWT resources, if not left enabled by debugger. */
|
||||
|
||||
modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
|
||||
|
||||
/* Make sure the high speed cycle counter is running. It will be started
|
||||
* automatically only if a debugger is connected.
|
||||
*/
|
||||
|
||||
putreg32(0xc5acce55, ITM_LAR);
|
||||
modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_HC32_SPI1) || defined(CONFIG_HC32_SPI2) || defined(CONFIG_HC32_SPI3)
|
||||
/* Configure SPI chip selects if 1) SPI is not disabled, and 2) the weak
|
||||
* function hc32_spidev_initialize() has been brought into the link.
|
||||
*/
|
||||
|
||||
if (hc32_spidev_initialized)
|
||||
{
|
||||
hc32_spidev_initialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HC32_OTGFS
|
||||
/* Initialize USB if the 1) OTG FS controller is in the configuration and
|
||||
* 2) disabled, and 3) the weak function hc32_usbinitialize() has been
|
||||
* brought into the build. Presumably either CONFIG_USBDEV or
|
||||
* CONFIG_USBHOST is also selected.
|
||||
*/
|
||||
|
||||
if (hc32_usbinitialize)
|
||||
{
|
||||
hc32_usbinitialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETMONITOR
|
||||
/* Configure board resources to support networking. */
|
||||
|
||||
if (hc32_netinitialize)
|
||||
{
|
||||
hc32_netinitialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
/* Configure on-board LEDs if LED support has been selected. */
|
||||
|
||||
board_autoled_initialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include <hc32_common.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hc32_bringup
|
||||
*
|
||||
@@ -48,6 +50,27 @@
|
||||
int hc32_bringup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#ifdef CONFIG_FS_PROCFS
|
||||
/* Mount the procfs file system */
|
||||
|
||||
ret = nx_mount(NULL, HC32_PROCFS_MOUNTPOINT, "procfs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to mount procfs at %s: %d\n",
|
||||
HC32_PROCFS_MOUNTPOINT, ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HC32_ROMFS
|
||||
ret = hc32_romfs_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("ERROR: Failed to mount romfs at %s: %d\n",
|
||||
CONFIG_HC32_ROMFS_MOUNTPOINT, ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("start %s\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/hc32/hc32f4a0/src/hc32_romfs.h
|
||||
*
|
||||
* Copyright (C) 2017 Tomasz Wozniak. All rights reserved.
|
||||
* Author: Tomasz Wozniak <t.wozniak@samsung.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BOARDS_ARM_HC32_HC32F4A0_SRC_HC32_ROMFS_H
|
||||
#define __BOARDS_ARM_HC32_HC32F4A0_SRC_HC32_ROMFS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_HC32_ROMFS
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ROMFS_SECTOR_SIZE 64
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_romfs_initialize
|
||||
*
|
||||
* Description:
|
||||
* Registers built-in ROMFS image as block device and mounts it.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success, a negated errno value on error.
|
||||
*
|
||||
* Assumptions/Limitations:
|
||||
* Memory addresses [&romfs_data_begin .. &romfs_data_begin) should contain
|
||||
* ROMFS volume data, as included in the assembly snippet above (l. 84).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int hc32_romfs_initialize(void);
|
||||
|
||||
#endif /* CONFIG_STM32_ROMFS */
|
||||
|
||||
#endif /* __BOARDS_ARM_HC32_HC32F4A0_SRC_HC32_ROMFS_H */
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/hc32/hc32f4a0/src/hc32_romfs_initialize.c
|
||||
* This file provides contents of an optional ROMFS volume, mounted at boot.
|
||||
*
|
||||
* Copyright (C) 2017 Tomasz Wozniak. All rights reserved.
|
||||
* Author: Tomasz Wozniak <t.wozniak@samsung.com>
|
||||
*
|
||||
* 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 <sys/mount.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include "hc32_romfs.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_HC32_ROMFS
|
||||
# error "CONFIG_HC32_ROMFS must be defined"
|
||||
#else
|
||||
|
||||
#ifndef CONFIG_HC32_ROMFS_IMAGEFILE
|
||||
# error "CONFIG_HC32_ROMFS_IMAGEFILE must be defined"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_HC32_ROMFS_DEV_MINOR
|
||||
# error "CONFIG_HC32_ROMFS_DEV_MINOR must be defined"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_HC32_ROMFS_MOUNTPOINT
|
||||
# error "CONFIG_HC32_ROMFS_MOUNTPOINT must be defined"
|
||||
#endif
|
||||
|
||||
#define NSECTORS(size) (((size) + ROMFS_SECTOR_SIZE - 1)/ROMFS_SECTOR_SIZE)
|
||||
|
||||
#define STR2(m) #m
|
||||
#define STR(m) STR2(m)
|
||||
|
||||
#define MKMOUNT_DEVNAME(m) "/dev/ram" STR(m)
|
||||
#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_HC32_ROMFS_DEV_MINOR)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
__asm__ (
|
||||
".section .rodata\n"
|
||||
".balign 16\n"
|
||||
".globl romfs_data_begin\n"
|
||||
"romfs_data_begin:\n"
|
||||
".incbin " STR(CONFIG_HC32_ROMFS_IMAGEFILE) "\n"\
|
||||
\
|
||||
".balign " STR(ROMFS_SECTOR_SIZE) "\n"
|
||||
".globl romfs_data_end\n"
|
||||
"romfs_data_end:\n"
|
||||
".globl romfs_data_size\n"
|
||||
"romfs_data_size:\n"
|
||||
".word romfs_data_end - romfs_data_begin\n"
|
||||
".previous\n");
|
||||
|
||||
extern const char romfs_data_begin;
|
||||
extern const char romfs_data_end;
|
||||
extern const int romfs_data_size;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hc32_romfs_initialize
|
||||
*
|
||||
* Description:
|
||||
* Registers the aboveincluded binary file as block device.
|
||||
* Then mounts the block device as ROMFS filesystems.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success, a negated errno value on error.
|
||||
*
|
||||
* Assumptions/Limitations:
|
||||
* Memory addresses [&romfs_data_begin .. &romfs_data_begin) should contain
|
||||
* ROMFS volume data, as included in the assembly snippet above (l. 84).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int hc32_romfs_initialize(void)
|
||||
{
|
||||
uintptr_t romfs_data_len;
|
||||
int ret;
|
||||
|
||||
/* Create a ROM disk for the /etc filesystem */
|
||||
|
||||
romfs_data_len = (uintptr_t)&romfs_data_end - (uintptr_t)&romfs_data_begin;
|
||||
|
||||
ret = romdisk_register(CONFIG_HC32_ROMFS_DEV_MINOR, &romfs_data_begin,
|
||||
NSECTORS(romfs_data_len), ROMFS_SECTOR_SIZE);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: romdisk_register failed: %d\n", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Mount the file system */
|
||||
|
||||
finfo("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
||||
CONFIG_HC32_ROMFS_MOUNTPOINT, MOUNT_DEVNAME);
|
||||
|
||||
ret = nx_mount(MOUNT_DEVNAME, CONFIG_HC32_ROMFS_MOUNTPOINT,
|
||||
"romfs", MS_RDONLY, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: nx_mount(%s,%s,romfs) failed: %d\n",
|
||||
MOUNT_DEVNAME, CONFIG_HC32_ROMFS_MOUNTPOINT, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_HC32_ROMFS */
|
||||
Reference in New Issue
Block a user