zombah

setbootmode by skrilax_cz

Oct 8th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.33 KB | None | 0 0
  1. /*
  2.     Copyright (C) 2012 Skrilax_CZ ([email protected])
  3.    
  4.     This program is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU General Public License
  6.     as published by the Free Software Foundation; either version 2
  7.     of the License, or (at your option) any later version.
  8.    
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.    
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.     */
  18.  
  19. /* This uttility sets boot partition for A500 Bootlodaer */
  20.  
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. struct msc_message
  27. {
  28.     /* Boot commands:
  29.      * FastbootMode - fastboot
  30.      * FOTA - recovery
  31.      */
  32.     char boot_command[0x0C];
  33.    
  34.     /* Debug mode:
  35.      * 00 - off
  36.      * 01 - on
  37.      */
  38.     unsigned char debug_mode;
  39.    
  40.     /* Primary boot partition:
  41.      * 00 - LNX
  42.      * 01 - AKB
  43.      */
  44.     unsigned char boot_mode;
  45. };
  46.  
  47. #define MSC_PARTITION "/dev/block/mmcblk0p5"
  48.  
  49. void print_usage()
  50. {
  51.     fprintf(stderr, "Usage: setbootmode [b1|b2]\n");
  52.     fprintf(stderr, "b1 for booting primary kernel image\n");
  53.     fprintf(stderr, "b2 for booting secondary kernel image\n");
  54. }
  55.  
  56. int main(int argc, char** argv)
  57. {
  58.     struct msc_message msg;
  59.     unsigned char boot_mode;
  60.     FILE* f;
  61.    
  62.     if (argc < 2)
  63.     {
  64.         print_usage();
  65.         return 1;
  66.     }
  67.     else if (!strcmp(argv[1], "b1"))
  68.         boot_mode = 0;
  69.     else if (!strcmp(argv[1], "b2"))
  70.         boot_mode = 1;
  71.     else
  72.     {
  73.         print_usage();
  74.         return 1;
  75.     }
  76.    
  77.     f = fopen(MSC_PARTITION, "rb+");
  78.     if (f == NULL)
  79.     {
  80.         fprintf(stderr, "MSC partition not found.\n");
  81.         return 1;
  82.     }
  83.    
  84.     /* Read current msc message */
  85.     fseek(f, 0x00, SEEK_SET);
  86.     fread(&msg, 1, sizeof(struct msc_message), f);
  87.    
  88.     /* Set boot mode */
  89.     msg.boot_mode = boot_mode;
  90.    
  91.     /* Write it back */
  92.     fseek(f, 0x00, SEEK_SET);
  93.     fwrite(&msg, 1, sizeof(struct msc_message), f);
  94.    
  95.     /* Done */
  96.     fclose(f);
  97.    
  98.     if (boot_mode == 0)
  99.         printf("Set to boot primary kernel image.\n");
  100.     else if (boot_mode == 1)
  101.         printf("Set to boot secondary kernel image.\n");
  102.    
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment