Переглянути джерело

[nvs] Allow for non-volatile storage devices without block boundaries

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 роки тому
джерело
коміт
8f8b55f187
2 змінених файлів з 32 додано та 17 видалено
  1. 32
    16
      src/drivers/nvs/nvs.c
  2. 0
    1
      src/drivers/nvs/nvsvpd.c

+ 32
- 16
src/drivers/nvs/nvs.c Переглянути файл

30
  *
30
  *
31
  */
31
  */
32
 
32
 
33
+/**
34
+ * Calculate length up to next block boundary
35
+ *
36
+ * @v nvs		NVS device
37
+ * @v address		Starting address
38
+ * @v max_len		Maximum length
39
+ * @ret len		Length to use, stopping at block boundaries
40
+ */
41
+static size_t nvs_frag_len ( struct nvs_device *nvs, unsigned int address,
42
+			     size_t max_len ) {
43
+	size_t frag_len;
44
+
45
+	/* If there are no block boundaries, return the maximum length */
46
+	if ( ! nvs->block_size )
47
+		return max_len;
48
+
49
+	/* Calculate space remaining up to next block boundary */
50
+	frag_len = ( ( nvs->block_size -
51
+		       ( address & ( nvs->block_size - 1 ) ) )
52
+		     << nvs->word_len_log2 );
53
+
54
+	/* Limit to maximum length */
55
+	if ( max_len < frag_len )
56
+		return max_len;
57
+
58
+	return frag_len;
59
+}
60
+
33
 /**
61
 /**
34
  * Read from non-volatile storage device
62
  * Read from non-volatile storage device
35
  *
63
  *
51
 
79
 
52
 	while ( len ) {
80
 	while ( len ) {
53
 
81
 
54
-		/* Calculate space remaining up to next block boundary */
55
-		frag_len = ( ( nvs->block_size -
56
-			       ( address & ( nvs->block_size - 1 ) ) )
57
-			     << nvs->word_len_log2 );
58
-
59
-		/* Limit to space remaining in buffer */
60
-		if ( frag_len > len )
61
-			frag_len = len;
82
+		/* Calculate length to read, stopping at block boundaries */
83
+		frag_len = nvs_frag_len ( nvs, address, len );
62
 
84
 
63
 		/* Read this portion of the buffer from the device */
85
 		/* Read this portion of the buffer from the device */
64
 		if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
86
 		if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
122
 
144
 
123
 	while ( len ) {
145
 	while ( len ) {
124
 
146
 
125
-		/* Calculate space remaining up to next block boundary */
126
-		frag_len = ( ( nvs->block_size -
127
-			       ( address & ( nvs->block_size - 1 ) ) )
128
-			     << nvs->word_len_log2 );
129
-
130
-		/* Limit to space remaining in buffer */
131
-		if ( frag_len > len )
132
-			frag_len = len;
147
+		/* Calculate length to write, stopping at block boundaries */
148
+		frag_len = nvs_frag_len ( nvs, address, len );
133
 
149
 
134
 		/* Write this portion of the buffer to the device */
150
 		/* Write this portion of the buffer to the device */
135
 		if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)
151
 		if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)

+ 0
- 1
src/drivers/nvs/nvsvpd.c Переглянути файл

111
 	}
111
 	}
112
 
112
 
113
 	/* Initialise NVS device */
113
 	/* Initialise NVS device */
114
-	nvsvpd->nvs.block_size = 1;
115
 	nvsvpd->nvs.size = len;
114
 	nvsvpd->nvs.size = len;
116
 	nvsvpd->nvs.read = nvs_vpd_read;
115
 	nvsvpd->nvs.read = nvs_vpd_read;
117
 	nvsvpd->nvs.write = nvs_vpd_write;
116
 	nvsvpd->nvs.write = nvs_vpd_write;

Завантаження…
Відмінити
Зберегти