Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for Miscellany

Gigabeat S bootloader: untar a tar file then remove it.

Miscellany
Sunday, February 17th, 2008 at 4:33:11pm UTC 

  1. Index: bootloader/gigabeat-s.c
  2. ===================================================================
  3. --- bootloader/gigabeat-s.c     (rĂ©vision 16326)
  4. +++ bootloader/gigabeat-s.c     (copie de travail)
  5. @@ -51,6 +51,7 @@
  6.  char buf[MAX_PATH];
  7.  char basedir[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */
  8.  char model[5];
  9. +char tarstring[6];
  10.  int (*kernel_entry)(void);
  11.  extern void reference_system_c(void);
  12.  
  13. @@ -61,11 +62,78 @@
  14.      reference_system_c();
  15.  }
  16.  
  17. +void untar(int tar_fd)
  18. +{
  19. +    char buffer[157];
  20. +    char path[102];
  21. +    char copybuf[512];
  22. +    int n, size = 0, i, pos = 0;
  23. +    int fd;
  24. +
  25. +    while (1)
  26. +    {
  27. +        n = read(tar_fd, buffer, 157);
  28. +
  29. +        /* Parse the size field */
  30. +        size = 0;
  31. +        for (i = 124 ; i < 124 + 11 ; i++) {
  32. +            size = (8 * size) + buffer[i] - '0';
  33. +        }
  34. +        /* Round length up to next multiple of 512 */
  35. +        //len = (size + 511) & (~511);
  36. +
  37. +        /* Skip rest of header */
  38. +        pos = lseek(tar_fd, 512 - 157, SEEK_CUR);
  39. +
  40. +        if (pos + size > filesize(tar_fd))
  41. +            break;
  42. +
  43. +        strcpy(path, "/");
  44. +        strcat(path, buffer);
  45. +
  46. +        //printf("%s (%d)", path, size);
  47. +
  48. +        if (buffer[156] == '0')  /* file */
  49. +        {
  50. +            int rc, total = 0;
  51. +            fd = creat(path);
  52. +            if (fd < 0)
  53. +                printf("failed to create file (%d)", fd);
  54. +            else
  55. +            {
  56. +                while (total < size)
  57. +                {
  58. +                    rc = read(tar_fd, copybuf, sizeof(copybuf));
  59. +                    pos += rc;
  60. +                    n = write(fd, copybuf, MIN(rc, size - total));
  61. +                    if (n < 0)
  62. +                    {
  63. +                        printf("write failed (%d)", n);
  64. +                        break;
  65. +                    }
  66. +                    total += n;
  67. +                }
  68. +                close(fd);
  69. +            }
  70. +        }
  71. +        else if (buffer[156] == '5')  /* directory */
  72. +        {
  73. +            if (path[strlen(path) - 1] == '/')
  74. +                path[strlen(path) - 1] = '\0';
  75. +
  76. +            int ret = mkdir(path);
  77. +            if (ret < 0 && ret != -4)
  78. +                printf("failed to create dir (%d)", ret);
  79. +            pos = lseek(tar_fd, (size + 511) & (~511), SEEK_CUR);
  80. +        }
  81. +    }
  82. +}
  83. +
  84.  void main(void)
  85.  {
  86.      lcd_clear_display();
  87.      printf("Hello world!");
  88. -    printf("Gigabeat S Rockbox Bootloader v.00000003");
  89. +    printf("Gigabeat S Rockbox Bootloader v.00000004");
  90.      system_init();
  91.      kernel_init();
  92.      printf("kernel init done");
  93. @@ -103,6 +171,7 @@
  94.              fd = open(buf, O_RDONLY);
  95.              if (fd >= 0)
  96.              {
  97. +#if 0
  98.                  lseek(fd, 4, SEEK_SET);
  99.                  rc = read(fd, model, 4);
  100.                  close(fd);
  101. @@ -112,6 +181,25 @@
  102.                      if (strcmp(model, "gigs") == 0)
  103.                          break;
  104.                  }
  105. +#endif
  106. +
  107. +                lseek(fd, 257, SEEK_SET);
  108. +                rc = read(fd, tarstring, 5);
  109. +                if (rc == 5)
  110. +                {
  111. +                    tarstring[5] = 0;
  112. +                    if (strcmp(tarstring, "ustar") == 0)
  113. +                    {
  114. +                        printf("Found tar file. Unarchiving");
  115. +                        lseek(fd, 0, SEEK_SET);
  116. +                        untar(fd);
  117. +                        close(fd);
  118. +                        printf("Removing tar file");
  119. +                        remove(buf);
  120. +                        break;
  121. +                    }
  122. +                }
  123. +                close(fd);
  124.              }
  125.          }
  126.      }
  127. @@ -122,7 +210,7 @@
  128.      unsigned char *loadbuffer = (unsigned char *)0x0;
  129.      int buffer_size = 31*1024*1024;
  130.  
  131. -    rc = load_firmware(loadbuffer, buf, buffer_size);
  132. +    rc = load_firmware(loadbuffer, "/.rockbox/rockbox.gigabeat", buffer_size);
  133.      if(rc < 0)
  134.          error((int)buf, rc);
  135.  

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right