- Timestamp:
- Dec 5, 2013, 12:45:34 PM (11 years ago)
- Location:
- soft/giet_vm
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/Makefile
r258 r259 290 290 $(CC) $(CFLAGS) $(USER_INCLUDE) -c -o $@ $< 291 291 292 build/libs/stdlib.o: giet_libs/stdlib.c \ 293 giet_libs/stdlib.h \ 294 giet_config.h 295 $(CC) $(CFLAGS) $(USER_INCLUDE) -c -o $@ $< 296 292 297 build/libs/string.o: giet_libs/string.c \ 293 298 giet_libs/string.h \ -
soft/giet_vm/create_dmg
r258 r259 8 8 reserved_sectors=32 9 9 10 # FAT32 SPEC: The first two clusters are not present in the data region but 11 # they are used in the computation of the FAT sectors 12 data_region_clusters=$clusters-2 10 13 11 let "data_sectors = (clusters - 2) * sectors_per_cluster" 12 let "fat_sectors = (clusters * 4) / 512" 13 let "sectors=data_sectors + fat_sectors + reserved_sectors" 14 let "data_sectors = data_region_clusters * sectors_per_cluster" 15 let "fat_sectors = (clusters * 4) / 512" 16 17 # The disk image contains: 18 # - MBR sector : this sector is removed by this script as it will be copied 19 # after) 20 # - Reserved region sectors (usually 32) 21 # - FAT region sectors 22 # - DATA region sectors 23 let "sectors = data_sectors + fat_sectors + reserved_sectors + 1" 14 24 15 25 platform=`uname` … … 43 53 # RAW DISK IMAGE READ-ONLY 44 54 # The not used space is not considered (smaller disk image) 45 #format="UDRO"55 format="UDRO" 46 56 47 57 # RAW DISK IMAGE READ-WRITE 48 58 # None compression is made 49 format="UDRW"59 # format="UDRW" 50 60 51 61 echo "Creating partition file $3 from $2 directory" … … 59 69 -format $format \ 60 70 $3; 61 # 71 # -verbose \ 62 72 63 73 echo "Removing first sector of diskimage" … … 106 116 107 117 elif [[ $platform == "Linux" ]]; then 108 echo "Creating partion file: partition.dmg" 109 mkfs.vfat -C -F32 -S $sector_size -s $sectors_per_cluster \ 110 partition.dmg $sectors 118 case $1 in 119 create ) 120 if [[ -z $2 ]]; then 121 echo "Create action need second argument: <srcdir_path>" 122 exit 1; 123 fi; 111 124 112 echo "Copying files into the partition" 113 mcopy -s -i partition.dmg build ::// 114 mcopy -i partition.dmg map.bin ::// 125 if [[ -z $3 ]]; then 126 echo "Create action need third argument: <disk_image>" 127 exit 1; 128 fi; 115 129 116 echo "Copying MBR on the first sector" 117 dd if=mbr.dmg of=disk.dmg count=1 bs=$sector_size 130 echo "Creating partition file: $3" 118 131 119 echo "Copying partition file on the sector 200 of the disk" 120 dd if=partition.dmg of=disk.dmg seek=200 bs=$sector_size 132 let "sectors = (sectors - 1) / 2" 133 mkfs.vfat \ 134 -C \ 135 -F32 \ 136 -f 1 \ 137 -R $reserved_sectors \ 138 -S $sector_size \ 139 -s $sectors_per_cluster \ 140 -v \ 141 $3.dmg $sectors 142 143 if [[ -e $2 ]]; then 144 echo "Copying files from $2 into partition" 145 mcopy -s -i $3.dmg $2/* ::// 146 fi;; 147 148 * ) 149 echo "Pass the command as the first parameter: " 150 echo " - create: create disk image" 151 echo " First parameter after create action is the path" 152 echo " of the directory to copy in the created " 153 echo " partition" 154 echo "" 155 echo "EXAMPLES:" 156 echo " ./create_diskimage.sh create /path/to/source_dir disk_image" 157 esac; 121 158 122 159 else -
soft/giet_vm/giet_fat32/fat32.c
r258 r259 1163 1163 unsigned int offset ) // nuber of sectors to skip in file 1164 1164 { 1165 _tty_get_lock( 0 ); 1166 _puts("\n[FAT ERROR] _fat_write() function not implemented\n"); 1167 _tty_release_lock( 0 ); 1168 return -1; 1165 1166 unsigned int spc = fat.sectors_per_cluster; 1167 1168 unsigned int file_size; // number of bytes in file 1169 unsigned int file_sectors; // number of sectors in file 1170 unsigned int cluster; // cluster index 1171 unsigned int clusters_to_skip; // number of clusters to skip because offset 1172 unsigned int sectors_to_skip; // number of sectors to skip in first iteration 1173 unsigned int allocate; // need allocate or not 1174 1175 // compute file size as a number of sectors 1176 file_size = fat.fd[fd_id].file_size; 1177 if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1; 1178 else file_sectors = (file_size >> 9); 1179 1180 allocate = ( ((count + offset) / spc) > (file_sectors / spc) ); 1181 1182 #if GIET_DEBUG_FAT 1183 _tty_get_lock( 0 ); 1184 _puts("\n[FAT DEBUG] Enter _fat_write() for file "); 1185 _puts( fat.fd[fd_id].name ); 1186 _puts("\n - buffer base = "); 1187 _putx( (unsigned int)buffer ); 1188 _puts("\n - skipped sectors = "); 1189 _putd( offset ); 1190 _puts("\n - write sectors = "); 1191 _putd( count ); 1192 _puts("\n - file size (sectors) = "); 1193 _putd( file_sectors ); 1194 _puts("\n - need allocate = "); 1195 allocate ? _puts( "True" ) : _puts( "False"); 1196 _tty_release_lock( 0 ); 1197 #endif 1198 1199 if ( allocate ) 1200 { 1201 _tty_get_lock( 0 ); 1202 _puts("\n[FAT ERROR] in _fat_write() : \n"); 1203 _puts("we need to allocate more cluster... But this function is not implemented\n"); 1204 _tty_release_lock( 0 ); 1205 return -1; 1206 } 1207 // arguments checking 1208 if ( fd_id >= GIET_OPEN_FILES_MAX ) 1209 { 1210 _tty_get_lock( 0 ); 1211 _puts("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n"); 1212 _tty_release_lock( 0 ); 1213 return -1; 1214 } 1215 if ( fat.fd[fd_id].used != 1 ) 1216 { 1217 _tty_get_lock( 0 ); 1218 _puts("\n[FAT ERROR] in _fat_write() : file not open\n"); 1219 _tty_release_lock( 0 ); 1220 return -1; 1221 } 1222 if ( ((unsigned int)buffer & 0x1FF) != 0 ) 1223 { 1224 _tty_get_lock( 0 ); 1225 _puts("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n"); 1226 _tty_release_lock( 0 ); 1227 return -1; 1228 } 1229 1230 // compute clusters and sectors to be skipped 1231 clusters_to_skip = offset / spc; 1232 sectors_to_skip = offset % spc; 1233 1234 // get first cluster index 1235 cluster = fat.fd[fd_id].first_cluster; 1236 1237 #if GIET_DEBUG_FAT 1238 _tty_get_lock( 0 ); 1239 _puts("\n - first cluster = "); 1240 _putd( cluster ); 1241 _puts("\n - skiped clusters = "); 1242 _putd( clusters_to_skip ); 1243 _puts("\n"); 1244 _tty_release_lock( 0 ); 1245 #endif 1246 1247 // compute index of first cluster to be loaded 1248 // as we may need to scan the FAT, we use the kernel mode 1249 while ( clusters_to_skip ) 1250 { 1251 cluster = get_next_cluster_id( IOC_KERNEL_MODE, cluster ); 1252 clusters_to_skip--; 1253 } 1254 1255 // variables used in the loop on clusters 1256 int todo_sectors; // number of sectors still to be loaded 1257 unsigned int lba; // first sector index on device 1258 unsigned int iter_sectors; // number of sectors to load in iteration 1259 char* src; // pointer on target buffer 1260 1261 // initialize these variables for the first iteration 1262 todo_sectors = count; 1263 src = (char*)buffer; 1264 lba = cluster_to_lba(cluster) + sectors_to_skip; 1265 if( count < (spc - sectors_to_skip) ) iter_sectors = count; 1266 else iter_sectors = spc - sectors_to_skip; 1267 1268 // loop on the clusters 1269 while ( todo_sectors > 0 ) 1270 { 1271 1272 #if GIET_DEBUG_FAT 1273 _tty_get_lock( 0 ); 1274 _puts("\n[FAT DEBUG] _fat_write() IOC request : buf = "); 1275 _putx( (unsigned int)src ); 1276 _puts(" / lba = "); 1277 _putd( lba ); 1278 _puts(" / sectors = "); 1279 _putd( iter_sectors ); 1280 _puts("\n"); 1281 _tty_release_lock( 0 ); 1282 #endif 1283 1284 if( _ioc_write( mode, // mode for IOC driver 1285 lba, // first sector index 1286 src, // buffer address 1287 iter_sectors ) ) // number of sectors 1288 { 1289 _tty_get_lock( 0 ); 1290 _puts("\n[FAT ERROR] in _fat_write() cannot write block "); 1291 _putd( lba ); 1292 _puts("\n"); 1293 _tty_release_lock( 0 ); 1294 return -1; 1295 } 1296 1297 // update variables for next iteration 1298 cluster = get_next_cluster_id( mode, cluster ); 1299 todo_sectors = todo_sectors - iter_sectors; 1300 src = src + (iter_sectors << 9); 1301 lba = cluster_to_lba(cluster); 1302 if ( todo_sectors > spc ) iter_sectors = spc; 1303 else iter_sectors = todo_sectors; 1304 } 1305 1306 // returns number of sectors actually transfered 1307 return count; 1169 1308 } 1170 1309 -
soft/giet_vm/giet_libs/stdio.h
r258 r259 48 48 #define SYSCALL_FAT_OPEN 0x20 49 49 #define SYSCALL_FAT_READ 0x21 50 #define SYSCALL_FAT_WRITE 0x2 151 #define SYSCALL_FAT_LSEEK 0x2 152 #define SYSCALL_FAT_CLOSE 0x2 150 #define SYSCALL_FAT_WRITE 0x22 51 #define SYSCALL_FAT_LSEEK 0x23 52 #define SYSCALL_FAT_CLOSE 0x24 53 53 54 54 //////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.