source: rtems/bsps/aarch64/xilinx-zynqmp/jffs2_xqspipsu.c @ 09fd5dd3

Last change on this file since 09fd5dd3 was 09fd5dd3, checked in by Kinsey Moore <kinsey.moore@…>, on 05/24/23 at 19:53:58

bsps/xqspipsu: Use device information from the FCT

Instead of statically defining the device parameters, use the device
information available via the NOR device layer's Flash Configuration
Table.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2022 On-Line Applications Research Corporation (OAR)
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <string.h>
29
30#include <bsp/irq.h>
31#include <bsp/jffs2_xqspipsu.h>
32#include <rtems/jffs2.h>
33#include <rtems/libio.h>
34#include <xqspipsu-flash-helper.h>
35
36typedef struct {
37  rtems_jffs2_flash_control super;
38  XQspiPsu *qspipsu;
39} flash_control;
40
41#define FLASH_DEVICE_ID 0xbb20 /* Type: 0xbb, Capacity: 0x20 */
42
43static flash_control *get_flash_control( rtems_jffs2_flash_control *super )
44{
45  return (flash_control *) super;
46}
47
48static int do_read(
49  rtems_jffs2_flash_control *super,
50  uint32_t offset,
51  unsigned char *buffer,
52  size_t size_of_buffer
53)
54{
55  int Status;
56
57  flash_control *self = get_flash_control( super );
58  XQspiPsu *QspiPsuPtr = self->qspipsu;
59  u8* ReadBuffer = NULL;
60
61  Status = QspiPsu_NOR_Read(
62    QspiPsuPtr,
63    offset,
64    size_of_buffer,
65    &ReadBuffer
66  );
67  if ( Status != XST_SUCCESS ) {
68    return Status;
69  }
70
71  /*
72   * We have to copy since we can't be sure that buffer is properly aligned.
73   */
74  memcpy( buffer, ReadBuffer, size_of_buffer );
75
76  return 0;
77}
78
79static int do_write(
80  rtems_jffs2_flash_control *super,
81  uint32_t offset,
82  const unsigned char *buffer,
83  size_t size_of_buffer
84)
85{
86  int Status;
87
88  flash_control *self = get_flash_control( super );
89  XQspiPsu *QspiPsuPtr = self->qspipsu;
90
91  Status = QspiPsu_NOR_Write(
92    QspiPsuPtr,
93    offset,
94    size_of_buffer,
95    (unsigned char *) buffer
96  );
97  if ( Status != XST_SUCCESS ) {
98    return Status;
99  }
100
101  return 0;
102}
103
104static int do_erase(
105  rtems_jffs2_flash_control *super,
106  uint32_t offset
107)
108{
109  int Status;
110
111  flash_control *self = get_flash_control( super );
112  XQspiPsu *QspiPsuPtr = self->qspipsu;
113
114  Status = QspiPsu_NOR_Erase(
115    QspiPsuPtr,
116    offset,
117    super->block_size
118  );
119  if ( Status != XST_SUCCESS ) {
120    return Status;
121  }
122
123  return 0;
124}
125
126static void do_destroy( rtems_jffs2_flash_control *super )
127{
128  flash_control *self = get_flash_control( super );
129
130  rtems_interrupt_handler_remove(
131    ZYNQMP_IRQ_QSPI,
132    (rtems_interrupt_handler) XQspiPsu_InterruptHandler,
133    self->qspipsu
134  );
135}
136
137static flash_control flash_instance = {
138  .super = {
139    .read              = do_read,
140    .write             = do_write,
141    .erase             = do_erase,
142    .destroy           = do_destroy,
143    .device_identifier = FLASH_DEVICE_ID
144  }
145};
146
147static rtems_jffs2_mount_data mount_data = {
148  .flash_control      = &flash_instance.super,
149  .compressor_control = NULL
150};
151
152int xilinx_zynqmp_nor_jffs2_initialize(
153  const char *mount_dir,
154  XQspiPsu *qspipsu_ptr
155)
156{
157  int rv = 0;
158
159  flash_instance.qspipsu = qspipsu_ptr;
160
161  rv = QspiPsu_NOR_Initialize(
162    flash_instance.qspipsu,
163    ZYNQMP_IRQ_QSPI
164  );
165  if ( rv != 0 ) {
166    return rv;
167  }
168
169  uint32_t sect_size = QspiPsu_NOR_Get_Sector_Size(qspipsu_ptr);
170  uint32_t flash_size = QspiPsu_NOR_Get_Device_Size(qspipsu_ptr);
171  flash_instance.super.flash_size = flash_size;
172  flash_instance.super.block_size = sect_size;
173
174  rv = mount(
175    NULL,
176    mount_dir,
177    RTEMS_FILESYSTEM_TYPE_JFFS2,
178    RTEMS_FILESYSTEM_READ_WRITE,
179    &mount_data
180  );
181  if ( rv != 0 ) {
182    return rv;
183  }
184
185  return 0;
186}
Note: See TracBrowser for help on using the repository browser.