root/lib/armutil/reboot.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. reboot

   1 #include "stdlib.h"
   2 #include "stddef.h"
   3 #include "stdio.h"
   4 #include "string.h"
   5 #define LOW_LEVEL
   6 #include "lolevel.h"
   7 /*
   8  shut down the display and reboot the camera. 
   9  bootfile is the name of the file to boot.
  10   If the filename ends in .FI*, load with _reboot_fw_update if implemented
  11   Otherwise must be an unencoded ARM binary, will be loaded at 0x1900
  12   For cameras which use encoded diskboot, loader/<camera>/main.bin may be used
  13   For cameras which do not use encoded diskboot, DISKBOOT.BIN may be used
  14   No sanity checking is performed on the binary, except that the size is >= 4 bytes
  15  If bootfile is NULL, camera firmware is rebooted. DISKBOOT.BIN will be loaded or not according to normal rules
  16  returns 0 on failure, does not return on success
  17  does NOT save camera settings to flash
  18  does NOT retract lens before rebooting
  19  calling from playback mode is recommended
  20  
  21  DIGIC 6: reboot not supported yet, unsuitable code #ifdef'd out
  22 */
  23 int reboot(const char *bootfile) {
  24 #ifndef THUMB_FW
  25     if(bootfile == NULL)
  26 #endif
  27     {
  28         _TurnOffDisplay();
  29         _Restart(0);
  30     }
  31 #ifndef THUMB_FW
  32         int namelen=strlen(bootfile);
  33         if(namelen > 3 && (strncmp(bootfile + namelen - 4,".FI",3) == 0)) {
  34                 _reboot_fw_update(bootfile);
  35                 // if _reboot_fw_update returns, it failed or is not implemented
  36                 return 0;
  37         }
  38 
  39         int fd;
  40         int size;
  41         int rcnt;
  42         char *buf;
  43         unsigned data_tcm;
  44     void __attribute__((noreturn)) (*canon_copy_and_restart)(char *dst, char *src, unsigned length,char *start);
  45 
  46         // use open/read etc since it takes less mem, boot image might be large
  47         fd = open(bootfile,O_RDONLY,0);
  48         if(fd == -1) {
  49                 return 0;
  50         }
  51         size = lseek(fd,0,SEEK_END);
  52         // error or less than 1 instruction
  53         if(size < 4) {
  54                 return 0;
  55         }
  56         buf = umalloc(size);
  57         if(!buf) {
  58                 close(fd);
  59                 return 0;
  60         }
  61         lseek(fd,0,SEEK_SET);
  62         rcnt = read(fd, buf, size);
  63         close(fd);
  64         if(rcnt != size) {
  65                 ufree(buf);
  66                 return 0;
  67         }
  68         asm volatile(
  69                 "MRC            p15, 0, %0, c9, c1, 0\n"
  70                 : "=r" (data_tcm)
  71         ); 
  72         data_tcm &= 0xFFFFF000;
  73         canon_copy_and_restart = (void *)(*(unsigned *)data_tcm);
  74         if( ((unsigned)canon_copy_and_restart & 0xFFFF0000) != 0xFFFF0000) {
  75                 ufree(buf);
  76                 return 0;
  77         }
  78     _TurnOffDisplay();
  79         _Restart(7);
  80         canon_copy_and_restart((void *)0x1900,buf,size,(void *)0x1900);
  81 #else
  82     (void)bootfile;
  83     return 0;
  84 #endif // THUMB_FW
  85 }
  86 
  87 

/* [<][>][^][v][top][bottom][index][help] */