static void start_ptbl(struct ptable *ptbl, unsigned blocks) { struct efi_header *hdr = &ptbl->header; memset(ptbl, 0, sizeof(*ptbl)); init_mbr(ptbl->mbr, blocks - 1); memcpy(hdr->magic, "EFI PART", 8); hdr->version = EFI_VERSION; hdr->header_sz = sizeof(struct efi_header); hdr->header_lba = 1; hdr->backup_lba = blocks - 1; hdr->first_lba = 34; hdr->last_lba = blocks - 1; memcpy(hdr->volume_uuid, random_uuid, 16); hdr->entries_lba = 2; hdr->entries_count = EFI_ENTRIES; hdr->entries_size = sizeof(struct efi_entry); }
int init_system(void){ if (SD_card_init() != 0) { perror("SD card initialization failed."); return(-1); } if (init_mbr() != 0) { perror("MBR initialization failed."); return(-1); } if (init_bs() != 0) { perror("Boot sector initialization failed."); return(-1); } init_audio_codec(); LCD_Init(); return(0); }
static void start_ptbl(struct ptable *ptbl, u64 blocks) { struct efi_header *hdr = &ptbl->header; DBG("start_ptbl\n"); memset(ptbl, 0, sizeof(*ptbl)); init_mbr(ptbl->mbr, blocks - 1); memcpy(hdr->magic, "EFI PART", 8); hdr->version = EFI_VERSION; hdr->header_sz = sizeof(struct efi_header); hdr->crc32 = 0; hdr->reserved = 0; hdr->header_lba = 1; hdr->backup_lba = blocks - 1; hdr->first_lba = 34; hdr->last_lba = blocks - 1; memcpy(hdr->volume_uuid, random_uuid, 16); hdr->entries_lba = 2; hdr->entries_count = EFI_ENTRIES; hdr->entries_size = sizeof(struct efi_entry); hdr->entries_crc32 = 0; DBG("magic = %s \n", hdr->magic); DBG("version = %u \n", hdr->version); DBG("header_sz = %u \n", hdr->header_sz); DBG("crc32 = %u \n", hdr->crc32); DBG("reserved = %u \n", hdr->reserved); DBG("header_lba = %u \n", hdr->header_lba); DBG("backup_lba = %u \n", hdr->backup_lba); DBG("first_lba = %u \n", hdr->first_lba); DBG("last_lba = %u \n", hdr->last_lba); DBG("entries_lba = %u \n", hdr->entries_lba); DBG("entries_count = %u \n", hdr->entries_count); DBG("entries_size = %u \n", hdr->entries_size); DBG("entries_crc32 = %u \n", hdr->entries_crc32); }
int main(int argc, char **argv) { struct ptable ptbl; struct efi_entry *entry; struct efi_header *hdr = &ptbl.header; struct stat s; u32 n; u64 sz, blk; int fd; const char *device; int real_disk = 0; if (argc < 2) return usage(); if (!strcmp(argv[1], "write")) { if (argc < 3) return usage(); device = argv[2]; argc -= 2; argv += 2; real_disk = 1; } else if (!strcmp(argv[1], "test")) { argc -= 1; argv += 1; real_disk = 0; sz = 2097152 * 16; fprintf(stderr,"< simulating 16GB disk >\n\n"); } else { return usage(); } if (real_disk) { if (!strcmp(device, "/dev/sda") || !strcmp(device, "/dev/sdb")) { fprintf(stderr,"error: refusing to partition sda or sdb\n"); return -1; } fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr,"error: cannot open '%s'\n", device); return -1; } if (ioctl(fd, BLKGETSIZE64, &sz)) { fprintf(stderr,"error: cannot query block device size\n"); return -1; } sz /= 512; fprintf(stderr,"blocks %lld\n", sz); } memset(&ptbl, 0, sizeof(ptbl)); init_mbr(ptbl.mbr, sz - 1); memcpy(hdr->magic, EFI_MAGIC, sizeof(hdr->magic)); hdr->version = EFI_VERSION; hdr->header_sz = sizeof(struct efi_header); hdr->header_lba = 1; hdr->backup_lba = sz - 1; hdr->first_lba = 34; hdr->last_lba = sz - 1; get_uuid(hdr->volume_uuid); hdr->entries_lba = 2; hdr->entries_count = 128; hdr->entries_size = sizeof(struct efi_entry); while (argc > 1) { if (argv[1][0] == '@') { char line[256], *p; FILE *f; f = fopen(argv[1] + 1, "r"); if (!f) { fprintf(stderr,"cannot read partitions from '%s\n", argv[1]); return -1; } while (fgets(line, sizeof(line), f)) { p = line + strlen(line); while (p > line) { p--; if (*p > ' ') break; *p = 0; } p = line; while (*p && (*p <= ' ')) p++; if (*p == '#') continue; if (*p == 0) continue; if (parse_ptn(&ptbl, p)) return -1; } fclose(f); } else { if (parse_ptn(&ptbl, argv[1])) return -1; } argc--; argv++; } n = crc32(0, Z_NULL, 0); n = crc32(n, (void*) ptbl.entry, sizeof(ptbl.entry)); hdr->entries_crc32 = n; n = crc32(0, Z_NULL, 0); n = crc32(n, (void*) &ptbl.header, sizeof(ptbl.header)); hdr->crc32 = n; show(&ptbl); if (real_disk) { write(fd, &ptbl, sizeof(ptbl)); fsync(fd); if (ioctl(fd, BLKRRPART, 0)) { fprintf(stderr,"could not re-read partition table\n"); } close(fd); } return 0; }
int main() { //Initialize Functions SD_card_init(); init_mbr(); init_bs(); init_audio_codec(); //Setup Push Buttons init_button_pio(); // Initialize Variables bytePerCluster = BPB_BytsPerSec * BPB_SecPerClus; //play_music(0 , 1); //play_music(0 , 2); //play_music(0 , 3); //play_music(5 , 4); stop_flag = 1; file_number = 0; init_music(); delay_cnt = 0; delay_flag = 0; while(1){ if(stop_flag == 0){ if(edge_capture == 0x01){ //stop music stop_flag = 1; } else if(edge_capture == 0x02){ // play music delay_cnt = 0; delay_flag = 0; play_type = IORD(SWITCH_PIO_BASE, 0) & 0x07; LCD_Display(returnData.Name, play_type); play_music(play_type); } else if(edge_capture == 0x04){ printf("File Number is %d\n",file_number); init_music(); usleep(250000); } else if(edge_capture == 0x08){ if(file_number < 2 ) file_number = 0; else file_number -= 2; init_music(); } } } return 0; }
int main (int argc, char **argv) { int vol = VOL_DFLT, nsectors = NSECTORS_DFLT, firstcylinder = FIRST_CYLINDER_DFLT, firstsector = FIRST_SECTOR_DFLT; int i, c; cmdname = argv[0]; opterr = 0; init_mbr(); while ((c = getopt(argc, argv, "l:c:s:v:")) != -1) { switch (c) { case 'l': nsectors = atol(optarg); break; case 'c': firstcylinder = atol(optarg); break; case 's': firstsector = atol(optarg); break; case 'v': vol = atol(optarg); break; case '?': /* missing option argument */ if (optopt == 'l' || optopt == 'c' || optopt == 's') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); usage(); } else unknown_opt(optopt); default: unknown_opt(c); } } printf("b\n"); struct vol_descr_s vol_desc; for(i=0;i<vol;i++){ vol_desc.vol_cylinder=firstcylinder; vol_desc.vol_sector=firstsector; vol_desc.vol_nsector=nsectors; vol_desc.vol_voltype=VT_BASE; mbr.mbr_vols[i]= vol_desc; } mbr.mbr_magic=0xA5E; mbr.mbr_nbvol=vol; if (optind != argc) { fprintf(stderr, "Argument(s): "); for (i = optind; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "ignored.\n"); usage(); } save_mbr(); save_mbr(); printf("mkvol(vol=%d, nsectors=%d, firstcylinder=%d, firstsector=%d)\n", vol, nsectors, firstcylinder, firstsector); exit(EXIT_SUCCESS); }