@@ -408,7 +408,7 @@ static FAR struct romfs_sparenode_s *
408
408
romfs_alloc_sparenode (uint32_t start , uint32_t end )
409
409
{
410
410
FAR struct romfs_sparenode_s * node ;
411
- node = kmm_malloc (sizeof (struct romfs_sparenode_s ));
411
+ node = fs_heap_malloc (sizeof (struct romfs_sparenode_s ));
412
412
if (node == NULL )
413
413
{
414
414
ferr ("romfs_alloc_sparenode: no memory\n" );
@@ -474,7 +474,7 @@ static int romfs_alloc_spareregion(FAR struct list_node *list,
474
474
/* Delete the node */
475
475
476
476
list_delete (& node -> node );
477
- kmm_free (node );
477
+ fs_heap_free (node );
478
478
return 0 ;
479
479
}
480
480
else if (start == node -> start )
@@ -514,6 +514,78 @@ static int romfs_alloc_spareregion(FAR struct list_node *list,
514
514
end );
515
515
return - ENOENT ;
516
516
}
517
+
518
+ /****************************************************************************
519
+ * Name: romfs_devwrite32
520
+ *
521
+ * Description:
522
+ * Write the big-endian 32-bit value to the mount device buffer
523
+ *
524
+ ****************************************************************************/
525
+
526
+ static void romfs_devwrite32 (FAR struct romfs_mountpt_s * rm ,
527
+ int ndx , uint32_t value )
528
+ {
529
+ /* Write the 32-bit value to the specified index in the buffer */
530
+
531
+ rm -> rm_devbuffer [ndx ] = (uint8_t )(value >> 24 ) & 0xff ;
532
+ rm -> rm_devbuffer [ndx + 1 ] = (uint8_t )(value >> 16 ) & 0xff ;
533
+ rm -> rm_devbuffer [ndx + 2 ] = (uint8_t )(value >> 8 ) & 0xff ;
534
+ rm -> rm_devbuffer [ndx + 3 ] = (uint8_t )(value & 0xff );
535
+ }
536
+
537
+ /****************************************************************************
538
+ * Name: romfs_hwwrite
539
+ *
540
+ * Description:
541
+ * Write the specified number of sectors to the block device
542
+ *
543
+ ****************************************************************************/
544
+
545
+ static int romfs_hwwrite (FAR struct romfs_mountpt_s * rm , FAR uint8_t * buffer ,
546
+ uint32_t sector , unsigned int nsectors )
547
+ {
548
+ FAR struct inode * inode = rm -> rm_blkdriver ;
549
+ ssize_t ret = - ENODEV ;
550
+
551
+ if (inode -> u .i_bops -> write )
552
+ {
553
+ ret = inode -> u .i_bops -> write (inode , buffer , sector , nsectors );
554
+ }
555
+
556
+ if (ret == (ssize_t )nsectors )
557
+ {
558
+ ret = OK ;
559
+ }
560
+
561
+ return ret ;
562
+ }
563
+
564
+ /****************************************************************************
565
+ * Name: romfs_devcachewrite
566
+ *
567
+ * Description:
568
+ * Write the specified sector for specified offset into the sector cache.
569
+ *
570
+ ****************************************************************************/
571
+
572
+ static int romfs_devcachewrite (FAR struct romfs_mountpt_s * rm ,
573
+ uint32_t sector )
574
+ {
575
+ int ret ;
576
+
577
+ ret = romfs_hwwrite (rm , rm -> rm_devbuffer , sector , 1 );
578
+ if (ret == OK )
579
+ {
580
+ rm -> rm_cachesector = sector ;
581
+ }
582
+ else
583
+ {
584
+ rm -> rm_cachesector = (uint32_t )-1 ;
585
+ }
586
+
587
+ return ret ;
588
+ }
517
589
#endif
518
590
519
591
/****************************************************************************
@@ -800,6 +872,14 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
800
872
801
873
rm -> rm_cachesector = (uint32_t )-1 ;
802
874
875
+ /* Allocate the device cache buffer for normal sector accesses */
876
+
877
+ rm -> rm_devbuffer = fs_heap_malloc (rm -> rm_hwsectorsize );
878
+ if (!rm -> rm_devbuffer )
879
+ {
880
+ return - ENOMEM ;
881
+ }
882
+
803
883
if (inode -> u .i_bops -> ioctl )
804
884
{
805
885
ret = inode -> u .i_bops -> ioctl (inode , BIOC_XIPBASE ,
@@ -816,14 +896,9 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
816
896
}
817
897
}
818
898
819
- /* Allocate the device cache buffer for normal sector accesses */
820
-
821
- rm -> rm_buffer = fs_heap_malloc (rm -> rm_hwsectorsize );
822
- if (!rm -> rm_buffer )
823
- {
824
- return - ENOMEM ;
825
- }
899
+ /* The device cache buffer for normal sector accesses */
826
900
901
+ rm -> rm_buffer = rm -> rm_devbuffer ;
827
902
return OK ;
828
903
}
829
904
@@ -843,7 +918,7 @@ void romfs_free_sparelist(FAR struct list_node *list)
843
918
list_for_every_entry_safe (list , node , tmp , struct romfs_sparenode_s , node )
844
919
{
845
920
list_delete (& node -> node );
846
- kmm_free (node );
921
+ fs_heap_free (node );
847
922
}
848
923
}
849
924
#endif
@@ -1343,3 +1418,50 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm,
1343
1418
return - EINVAL ; /* Won't get here */
1344
1419
#endif
1345
1420
}
1421
+
1422
+ #ifdef CONFIG_FS_ROMFS_WRITEABLE
1423
+
1424
+ /****************************************************************************
1425
+ * Name: romfs_mkfs
1426
+ *
1427
+ * Description:
1428
+ * Format the romfs filesystem
1429
+ *
1430
+ ****************************************************************************/
1431
+
1432
+ int romfs_mkfs (FAR struct romfs_mountpt_s * rm )
1433
+ {
1434
+ /* Write the magic number at that identifies this as a ROMFS filesystem */
1435
+
1436
+ memcpy (rm -> rm_devbuffer + ROMFS_VHDR_ROM1FS , ROMFS_VHDR_MAGIC ,
1437
+ ROMFS_VHDR_SIZE );
1438
+
1439
+ /* Init the ROMFS volume to zero */
1440
+
1441
+ romfs_devwrite32 (rm , ROMFS_VHDR_SIZE , 0 );
1442
+
1443
+ /* Write the volume name */
1444
+
1445
+ memcpy (rm -> rm_devbuffer + ROMFS_VHDR_VOLNAME , "romfs" , 6 );
1446
+
1447
+ /* Write the root node . */
1448
+
1449
+ romfs_devwrite32 (rm , 0x20 + ROMFS_FHDR_NEXT , 0x40 | RFNEXT_DIRECTORY );
1450
+ romfs_devwrite32 (rm , 0x20 + ROMFS_FHDR_INFO , 0x20 );
1451
+ romfs_devwrite32 (rm , 0x20 + ROMFS_FHDR_SIZE , 0 );
1452
+ romfs_devwrite32 (rm , 0x20 + ROMFS_FHDR_CHKSUM , 0 );
1453
+ memcpy (rm -> rm_devbuffer + 0x20 + ROMFS_FHDR_NAME , "." , 2 );
1454
+
1455
+ /* Write the root node .. */
1456
+
1457
+ romfs_devwrite32 (rm , 0x40 + ROMFS_FHDR_NEXT , RFNEXT_HARDLINK );
1458
+ romfs_devwrite32 (rm , 0x40 + ROMFS_FHDR_INFO , 0x20 );
1459
+ romfs_devwrite32 (rm , 0x40 + ROMFS_FHDR_SIZE , 0 );
1460
+ romfs_devwrite32 (rm , 0x40 + ROMFS_FHDR_CHKSUM , 0 );
1461
+ memcpy (rm -> rm_devbuffer + 0x40 + ROMFS_FHDR_NAME , ".." , 3 );
1462
+
1463
+ /* Write the buffer to sector zero */
1464
+
1465
+ return romfs_devcachewrite (rm , 0 );
1466
+ }
1467
+ #endif
0 commit comments