root/lib/armutil/reboot.c

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

DEFINITIONS

This source file includes following definitions.
  1. reboot

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

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