3737#define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024)
3838
3939#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00
40- #define OOPS_PAGE_SIZE 4096
40+
41+ static unsigned long record_size = 4096 ;
42+ module_param (record_size , ulong , 0400 );
43+ MODULE_PARM_DESC (record_size ,
44+ "record size for MTD OOPS pages in bytes (default 4096)" );
4145
4246static struct mtdoops_context {
4347 int mtd_index ;
@@ -83,8 +87,8 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset)
8387{
8488 struct mtd_info * mtd = cxt -> mtd ;
8589 u32 start_page_offset = mtd_div_by_eb (offset , mtd ) * mtd -> erasesize ;
86- u32 start_page = start_page_offset / OOPS_PAGE_SIZE ;
87- u32 erase_pages = mtd -> erasesize / OOPS_PAGE_SIZE ;
90+ u32 start_page = start_page_offset / record_size ;
91+ u32 erase_pages = mtd -> erasesize / record_size ;
8892 struct erase_info erase ;
8993 DECLARE_WAITQUEUE (wait , current );
9094 wait_queue_head_t wait_q ;
@@ -152,36 +156,36 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
152156 if (!mtd )
153157 return ;
154158
155- mod = (cxt -> nextpage * OOPS_PAGE_SIZE ) % mtd -> erasesize ;
159+ mod = (cxt -> nextpage * record_size ) % mtd -> erasesize ;
156160 if (mod != 0 ) {
157- cxt -> nextpage = cxt -> nextpage + ((mtd -> erasesize - mod ) / OOPS_PAGE_SIZE );
161+ cxt -> nextpage = cxt -> nextpage + ((mtd -> erasesize - mod ) / record_size );
158162 if (cxt -> nextpage >= cxt -> oops_pages )
159163 cxt -> nextpage = 0 ;
160164 }
161165
162166 while (mtd -> block_isbad ) {
163- ret = mtd -> block_isbad (mtd , cxt -> nextpage * OOPS_PAGE_SIZE );
167+ ret = mtd -> block_isbad (mtd , cxt -> nextpage * record_size );
164168 if (!ret )
165169 break ;
166170 if (ret < 0 ) {
167171 printk (KERN_ERR "mtdoops: block_isbad failed, aborting\n" );
168172 return ;
169173 }
170174badblock :
171- printk (KERN_WARNING "mtdoops: bad block at %08x \n" ,
172- cxt -> nextpage * OOPS_PAGE_SIZE );
175+ printk (KERN_WARNING "mtdoops: bad block at %08lx \n" ,
176+ cxt -> nextpage * record_size );
173177 i ++ ;
174- cxt -> nextpage = cxt -> nextpage + (mtd -> erasesize / OOPS_PAGE_SIZE );
178+ cxt -> nextpage = cxt -> nextpage + (mtd -> erasesize / record_size );
175179 if (cxt -> nextpage >= cxt -> oops_pages )
176180 cxt -> nextpage = 0 ;
177- if (i == cxt -> oops_pages / (mtd -> erasesize / OOPS_PAGE_SIZE )) {
181+ if (i == cxt -> oops_pages / (mtd -> erasesize / record_size )) {
178182 printk (KERN_ERR "mtdoops: all blocks bad!\n" );
179183 return ;
180184 }
181185 }
182186
183187 for (j = 0 , ret = -1 ; (j < 3 ) && (ret < 0 ); j ++ )
184- ret = mtdoops_erase_block (cxt , cxt -> nextpage * OOPS_PAGE_SIZE );
188+ ret = mtdoops_erase_block (cxt , cxt -> nextpage * record_size );
185189
186190 if (ret >= 0 ) {
187191 printk (KERN_DEBUG "mtdoops: ready %d, %d\n" ,
@@ -191,7 +195,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
191195 }
192196
193197 if (mtd -> block_markbad && ret == - EIO ) {
194- ret = mtd -> block_markbad (mtd , cxt -> nextpage * OOPS_PAGE_SIZE );
198+ ret = mtd -> block_markbad (mtd , cxt -> nextpage * record_size );
195199 if (ret < 0 ) {
196200 printk (KERN_ERR "mtdoops: block_markbad failed, aborting\n" );
197201 return ;
@@ -206,22 +210,22 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)
206210 size_t retlen ;
207211 int ret ;
208212
209- if (cxt -> writecount < OOPS_PAGE_SIZE )
213+ if (cxt -> writecount < record_size )
210214 memset (cxt -> oops_buf + cxt -> writecount , 0xff ,
211- OOPS_PAGE_SIZE - cxt -> writecount );
215+ record_size - cxt -> writecount );
212216
213217 if (panic )
214- ret = mtd -> panic_write (mtd , cxt -> nextpage * OOPS_PAGE_SIZE ,
215- OOPS_PAGE_SIZE , & retlen , cxt -> oops_buf );
218+ ret = mtd -> panic_write (mtd , cxt -> nextpage * record_size ,
219+ record_size , & retlen , cxt -> oops_buf );
216220 else
217- ret = mtd -> write (mtd , cxt -> nextpage * OOPS_PAGE_SIZE ,
218- OOPS_PAGE_SIZE , & retlen , cxt -> oops_buf );
221+ ret = mtd -> write (mtd , cxt -> nextpage * record_size ,
222+ record_size , & retlen , cxt -> oops_buf );
219223
220224 cxt -> writecount = 0 ;
221225
222- if (retlen != OOPS_PAGE_SIZE || ret < 0 )
223- printk (KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n" ,
224- cxt -> nextpage * OOPS_PAGE_SIZE , retlen , OOPS_PAGE_SIZE , ret );
226+ if (retlen != record_size || ret < 0 )
227+ printk (KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n" ,
228+ cxt -> nextpage * record_size , retlen , record_size , ret );
225229 mark_page_used (cxt , cxt -> nextpage );
226230
227231 mtdoops_inc_counter (cxt );
@@ -246,10 +250,10 @@ static void find_next_position(struct mtdoops_context *cxt)
246250 for (page = 0 ; page < cxt -> oops_pages ; page ++ ) {
247251 /* Assume the page is used */
248252 mark_page_used (cxt , page );
249- ret = mtd -> read (mtd , page * OOPS_PAGE_SIZE , 8 , & retlen , (u_char * ) & count [0 ]);
253+ ret = mtd -> read (mtd , page * record_size , 8 , & retlen , (u_char * ) & count [0 ]);
250254 if (retlen != 8 || (ret < 0 && ret != - EUCLEAN )) {
251- printk (KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n" ,
252- page * OOPS_PAGE_SIZE , retlen , ret );
255+ printk (KERN_ERR "mtdoops: read failure at %ld (%td of 8 read), err %d\n" ,
256+ page * record_size , retlen , ret );
253257 continue ;
254258 }
255259
@@ -293,7 +297,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
293297 struct mtdoops_context * cxt = & oops_cxt ;
294298 u64 mtdoops_pages = mtd -> size ;
295299
296- do_div (mtdoops_pages , OOPS_PAGE_SIZE );
300+ do_div (mtdoops_pages , record_size );
297301
298302 if (cxt -> name && !strcmp (mtd -> name , cxt -> name ))
299303 cxt -> mtd_index = mtd -> index ;
@@ -307,7 +311,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
307311 return ;
308312 }
309313
310- if (mtd -> erasesize < OOPS_PAGE_SIZE ) {
314+ if (mtd -> erasesize < record_size ) {
311315 printk (KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n" ,
312316 mtd -> index );
313317 return ;
@@ -328,7 +332,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
328332 }
329333
330334 cxt -> mtd = mtd ;
331- cxt -> oops_pages = (int )mtd -> size / OOPS_PAGE_SIZE ;
335+ cxt -> oops_pages = (int )mtd -> size / record_size ;
332336 find_next_position (cxt );
333337 printk (KERN_INFO "mtdoops: Attached to MTD device %d\n" , mtd -> index );
334338}
@@ -403,15 +407,15 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
403407 cxt -> writecount = 8 ;
404408 }
405409
406- if (count + cxt -> writecount > OOPS_PAGE_SIZE )
407- count = OOPS_PAGE_SIZE - cxt -> writecount ;
410+ if (count + cxt -> writecount > record_size )
411+ count = record_size - cxt -> writecount ;
408412
409413 memcpy (cxt -> oops_buf + cxt -> writecount , s , count );
410414 cxt -> writecount += count ;
411415
412416 spin_unlock_irqrestore (& cxt -> writecount_lock , flags );
413417
414- if (cxt -> writecount == OOPS_PAGE_SIZE )
418+ if (cxt -> writecount == record_size )
415419 mtdoops_console_sync ();
416420}
417421
@@ -450,8 +454,16 @@ static int __init mtdoops_console_init(void)
450454{
451455 struct mtdoops_context * cxt = & oops_cxt ;
452456
457+ if ((record_size & 4095 ) != 0 ) {
458+ printk (KERN_ERR "mtdoops: record_size must be a multiple of 4096\n" );
459+ return - EINVAL ;
460+ }
461+ if (record_size < 4096 ) {
462+ printk (KERN_ERR "mtdoops: record_size must be over 4096 bytes\n" );
463+ return - EINVAL ;
464+ }
453465 cxt -> mtd_index = -1 ;
454- cxt -> oops_buf = vmalloc (OOPS_PAGE_SIZE );
466+ cxt -> oops_buf = vmalloc (record_size );
455467 if (!cxt -> oops_buf ) {
456468 printk (KERN_ERR "mtdoops: failed to allocate buffer workspace\n" );
457469 return - ENOMEM ;
0 commit comments