Deleted Added
full compact
cfi_dev.c (233553) cfi_dev.c (255207)
1/*-
2 * Copyright (c) 2007, Juniper Networks, Inc.
1/*-
2 * Copyright (c) 2007, Juniper Networks, Inc.
3 * Copyright (c) 2012-2013, SRI International
3 * All rights reserved.
4 *
4 * All rights reserved.
5 *
6 * Portions of this software were developed by SRI International and the
7 * University of Cambridge Computer Laboratory under DARPA/AFRL contract
8 * (FA8750-10-C-0237) ("CTSRD"), as part of the DARPA CRASH research
9 * programme.
10 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.

--- 10 unchanged lines hidden (view full) ---

23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.

--- 10 unchanged lines hidden (view full) ---

29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/cfi/cfi_dev.c 233553 2012-03-27 15:13:12Z jchandra $");
37__FBSDID("$FreeBSD: head/sys/dev/cfi/cfi_dev.c 255207 2013-09-04 17:19:21Z brooks $");
32
33#include "opt_cfi.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/bus.h>
38#include <sys/conf.h>
39#include <sys/ioccom.h>

--- 27 unchanged lines hidden (view full) ---

67 .d_write = cfi_devwrite,
68 .d_ioctl = cfi_devioctl,
69};
70
71/*
72 * Begin writing into a new block/sector. We read the sector into
73 * memory and keep updating that, until we move into another sector
74 * or the process stops writing. At that time we write the whole
38
39#include "opt_cfi.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/bus.h>
44#include <sys/conf.h>
45#include <sys/ioccom.h>

--- 27 unchanged lines hidden (view full) ---

73 .d_write = cfi_devwrite,
74 .d_ioctl = cfi_devioctl,
75};
76
77/*
78 * Begin writing into a new block/sector. We read the sector into
79 * memory and keep updating that, until we move into another sector
80 * or the process stops writing. At that time we write the whole
75 * sector to flash (see cfi_block_finish).
81 * sector to flash (see cfi_block_finish). To avoid unneeded erase
82 * cycles, keep a pristine copy of the sector on hand.
76 */
77int
78cfi_block_start(struct cfi_softc *sc, u_int ofs)
79{
80 union {
81 uint8_t *x8;
82 uint16_t *x16;
83 uint32_t *x32;

--- 27 unchanged lines hidden (view full) ---

111 case 2:
112 *(ptr.x16)++ = val;
113 break;
114 case 4:
115 *(ptr.x32)++ = val;
116 break;
117 }
118 }
83 */
84int
85cfi_block_start(struct cfi_softc *sc, u_int ofs)
86{
87 union {
88 uint8_t *x8;
89 uint16_t *x16;
90 uint32_t *x32;

--- 27 unchanged lines hidden (view full) ---

118 case 2:
119 *(ptr.x16)++ = val;
120 break;
121 case 4:
122 *(ptr.x32)++ = val;
123 break;
124 }
125 }
126 sc->sc_wrbufcpy = malloc(sc->sc_wrbufsz, M_TEMP, M_WAITOK);
127 memcpy(sc->sc_wrbufcpy, sc->sc_wrbuf, sc->sc_wrbufsz);
119 sc->sc_writing = 1;
120 return (0);
121}
122
123/*
124 * Finish updating the current block/sector by writing the compound
125 * set of changes to the flash.
126 */
127int
128cfi_block_finish(struct cfi_softc *sc)
129{
130 int error;
131
132 error = cfi_write_block(sc);
133 free(sc->sc_wrbuf, M_TEMP);
128 sc->sc_writing = 1;
129 return (0);
130}
131
132/*
133 * Finish updating the current block/sector by writing the compound
134 * set of changes to the flash.
135 */
136int
137cfi_block_finish(struct cfi_softc *sc)
138{
139 int error;
140
141 error = cfi_write_block(sc);
142 free(sc->sc_wrbuf, M_TEMP);
143 free(sc->sc_wrbufcpy, M_TEMP);
134 sc->sc_wrbuf = NULL;
135 sc->sc_wrbufsz = 0;
136 sc->sc_wrofs = 0;
137 sc->sc_writing = 0;
138 return (error);
139}
140
141static int

--- 160 unchanged lines hidden ---
144 sc->sc_wrbuf = NULL;
145 sc->sc_wrbufsz = 0;
146 sc->sc_wrofs = 0;
147 sc->sc_writing = 0;
148 return (error);
149}
150
151static int

--- 160 unchanged lines hidden ---