1 // SPDX-License-Identifier: GPL-2.0+
3 * Image code used by boards (and not host tools)
5 * (C) Copyright 2008 Semihalf
7 * (C) Copyright 2000-2006
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 #include <bootstage.h>
20 #include <asm/cache.h>
21 #include <asm/global_data.h>
23 #ifndef CONFIG_SYS_BARGSIZE
24 #define CONFIG_SYS_BARGSIZE 512
27 DECLARE_GLOBAL_DATA_PTR;
29 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
31 * image_get_ramdisk - get and verify ramdisk image
32 * @rd_addr: ramdisk image start address
33 * @arch: expected ramdisk architecture
34 * @verify: checksum verification flag
36 * image_get_ramdisk() returns a pointer to the verified ramdisk image
37 * header. Routine receives image start address and expected architecture
38 * flag. Verification done covers data and header integrity and os/type/arch
42 * pointer to a ramdisk image header, if image was found and valid
43 * otherwise, return NULL
45 static const image_header_t *image_get_ramdisk(ulong rd_addr, u8 arch,
48 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
50 if (!image_check_magic(rd_hdr)) {
51 puts("Bad Magic Number\n");
52 bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
56 if (!image_check_hcrc(rd_hdr)) {
57 puts("Bad Header Checksum\n");
58 bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
62 bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
63 image_print_contents(rd_hdr);
66 puts(" Verifying Checksum ... ");
67 if (!image_check_dcrc(rd_hdr)) {
68 puts("Bad Data CRC\n");
69 bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
75 bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
77 if (!image_check_os(rd_hdr, IH_OS_LINUX) ||
78 !image_check_arch(rd_hdr, arch) ||
79 !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
80 printf("No Linux %s Ramdisk Image\n",
81 genimg_get_arch_name(arch));
82 bootstage_error(BOOTSTAGE_ID_RAMDISK);
90 /*****************************************************************************/
91 /* Shared dual-format routines */
92 /*****************************************************************************/
93 ulong image_load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
94 ulong image_save_addr; /* Default Save Address */
95 ulong image_save_size; /* Default Save Size (in bytes) */
97 static int on_loadaddr(const char *name, const char *value, enum env_op op,
102 case env_op_overwrite:
103 image_load_addr = hextoul(value, NULL);
111 U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
113 ulong env_get_bootm_low(void)
115 char *s = env_get("bootm_low");
118 ulong tmp = hextoul(s, NULL);
122 #if defined(CONFIG_SYS_SDRAM_BASE)
123 return CONFIG_SYS_SDRAM_BASE;
124 #elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_RISCV)
125 return gd->bd->bi_dram[0].start;
131 phys_size_t env_get_bootm_size(void)
133 phys_size_t tmp, size;
135 char *s = env_get("bootm_size");
138 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
142 start = gd->ram_base;
145 if (start + size > gd->ram_top)
146 size = gd->ram_top - start;
148 s = env_get("bootm_low");
150 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
154 return size - (tmp - start);
157 phys_size_t env_get_bootm_mapsize(void)
160 char *s = env_get("bootm_mapsize");
163 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
167 #if defined(CONFIG_SYS_BOOTMAPSZ)
168 return CONFIG_SYS_BOOTMAPSZ;
170 return env_get_bootm_size();
174 void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
179 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
185 size_t tail = (len > chunksz) ? chunksz : len;
192 memmove(to, from, tail);
199 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
200 memmove(to, from, len);
201 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
205 * genimg_get_kernel_addr_fit - get the real kernel address and return 2
207 * @img_addr: a string might contain real image address
208 * @fit_uname_config: double pointer to a char, will hold pointer to a
209 * configuration unit name
210 * @fit_uname_kernel: double pointer to a char, will hold pointer to a subimage
213 * genimg_get_kernel_addr_fit get the real kernel start address from a string
214 * which is normally the first argv of bootm/bootz
217 * kernel start address
219 ulong genimg_get_kernel_addr_fit(char * const img_addr,
220 const char **fit_uname_config,
221 const char **fit_uname_kernel)
225 /* find out kernel image address */
227 kernel_addr = image_load_addr;
228 debug("* kernel: default image load address = 0x%08lx\n",
230 } else if (CONFIG_IS_ENABLED(FIT) &&
231 fit_parse_conf(img_addr, image_load_addr, &kernel_addr,
233 debug("* kernel: config '%s' from image at 0x%08lx\n",
234 *fit_uname_config, kernel_addr);
235 } else if (CONFIG_IS_ENABLED(FIT) &&
236 fit_parse_subimage(img_addr, image_load_addr, &kernel_addr,
238 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
239 *fit_uname_kernel, kernel_addr);
241 kernel_addr = hextoul(img_addr, NULL);
242 debug("* kernel: cmdline image address = 0x%08lx\n",
250 * genimg_get_kernel_addr() is the simple version of
251 * genimg_get_kernel_addr_fit(). It ignores those return FIT strings
253 ulong genimg_get_kernel_addr(char * const img_addr)
255 const char *fit_uname_config = NULL;
256 const char *fit_uname_kernel = NULL;
258 return genimg_get_kernel_addr_fit(img_addr, &fit_uname_config,
263 * genimg_get_format - get image format type
264 * @img_addr: image start address
266 * genimg_get_format() checks whether provided address points to a valid
267 * legacy or FIT image.
269 * New uImage format and FDT blob are based on a libfdt. FDT blob
270 * may be passed directly or embedded in a FIT image. In both situations
271 * genimg_get_format() must be able to dectect libfdt header.
274 * image format type or IMAGE_FORMAT_INVALID if no image is present
276 int genimg_get_format(const void *img_addr)
278 if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
279 const image_header_t *hdr;
281 hdr = (const image_header_t *)img_addr;
282 if (image_check_magic(hdr))
283 return IMAGE_FORMAT_LEGACY;
285 if (CONFIG_IS_ENABLED(FIT) || CONFIG_IS_ENABLED(OF_LIBFDT)) {
286 if (!fdt_check_header(img_addr))
287 return IMAGE_FORMAT_FIT;
289 if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) &&
290 !android_image_check_header(img_addr))
291 return IMAGE_FORMAT_ANDROID;
293 return IMAGE_FORMAT_INVALID;
297 * fit_has_config - check if there is a valid FIT configuration
298 * @images: pointer to the bootm command headers structure
300 * fit_has_config() checks if there is a FIT configuration in use
301 * (if FTI support is present).
304 * 0, no FIT support or no configuration found
305 * 1, configuration found
307 int genimg_has_config(bootm_headers_t *images)
309 if (CONFIG_IS_ENABLED(FIT) && images->fit_uname_cfg)
316 * boot_get_ramdisk - main ramdisk handling routine
317 * @argc: command argument count
318 * @argv: command argument list
319 * @images: pointer to the bootm images structure
320 * @arch: expected ramdisk architecture
321 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
322 * @rd_end: pointer to a ulong variable, will hold ramdisk end
324 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
325 * Currently supported are the following ramdisk sources:
326 * - multicomponent kernel/ramdisk image,
327 * - commandline provided address of decicated ramdisk image.
330 * 0, if ramdisk image was found and valid, or skiped
331 * rd_start and rd_end are set to ramdisk start/end addresses if
332 * ramdisk image is found and valid
334 * 1, if ramdisk image is found but corrupted, or invalid
335 * rd_start and rd_end are set to 0 if no ramdisk exists
337 int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
338 u8 arch, ulong *rd_start, ulong *rd_end)
340 ulong rd_addr, rd_load;
341 ulong rd_data, rd_len;
342 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
343 const image_header_t *rd_hdr;
346 #if CONFIG_IS_ENABLED(FIT)
347 const char *fit_uname_config = images->fit_uname_cfg;
348 const char *fit_uname_ramdisk = NULL;
352 const char *select = NULL;
357 if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
358 /* Look for an Android boot image */
359 buf = map_sysmem(images->os.start, 0);
360 if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
361 select = (argc == 0) ? env_get("loadaddr") : argv[0];
368 * Look for a '-' which indicates to ignore the
371 if (select && strcmp(select, "-") == 0) {
372 debug("## Skipping init Ramdisk\n");
375 } else if (select || genimg_has_config(images)) {
376 #if CONFIG_IS_ENABLED(FIT)
379 * If the init ramdisk comes from the FIT image and
380 * the FIT image address is omitted in the command
381 * line argument, try to use os FIT image address or
382 * default load address.
384 if (images->fit_uname_os)
385 default_addr = (ulong)images->fit_hdr_os;
387 default_addr = image_load_addr;
389 if (fit_parse_conf(select, default_addr,
390 &rd_addr, &fit_uname_config)) {
391 debug("* ramdisk: config '%s' from image at 0x%08lx\n",
392 fit_uname_config, rd_addr);
393 } else if (fit_parse_subimage(select, default_addr,
395 &fit_uname_ramdisk)) {
396 debug("* ramdisk: subimage '%s' from image at 0x%08lx\n",
397 fit_uname_ramdisk, rd_addr);
401 rd_addr = hextoul(select, NULL);
402 debug("* ramdisk: cmdline image address = 0x%08lx\n",
405 #if CONFIG_IS_ENABLED(FIT)
407 /* use FIT configuration provided in first bootm
408 * command argument. If the property is not defined,
411 rd_addr = map_to_sysmem(images->fit_hdr_os);
412 rd_noffset = fit_get_node_from_config(images,
415 if (rd_noffset == -ENOENT)
417 else if (rd_noffset < 0)
423 * Check if there is an initrd image at the
424 * address provided in the second bootm argument
425 * check image type, for FIT images get FIT node.
427 buf = map_sysmem(rd_addr, 0);
428 switch (genimg_get_format(buf)) {
429 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
430 case IMAGE_FORMAT_LEGACY:
431 printf("## Loading init Ramdisk from Legacy Image at %08lx ...\n",
434 bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
435 rd_hdr = image_get_ramdisk(rd_addr, arch,
441 rd_data = image_get_data(rd_hdr);
442 rd_len = image_get_data_size(rd_hdr);
443 rd_load = image_get_load(rd_hdr);
446 #if CONFIG_IS_ENABLED(FIT)
447 case IMAGE_FORMAT_FIT:
448 rd_noffset = fit_image_load(images,
449 rd_addr, &fit_uname_ramdisk,
450 &fit_uname_config, arch,
452 BOOTSTAGE_ID_FIT_RD_START,
453 FIT_LOAD_OPTIONAL_NON_ZERO,
458 images->fit_hdr_rd = map_sysmem(rd_addr, 0);
459 images->fit_uname_rd = fit_uname_ramdisk;
460 images->fit_noffset_rd = rd_noffset;
463 #ifdef CONFIG_ANDROID_BOOT_IMAGE
464 case IMAGE_FORMAT_ANDROID:
465 android_image_get_ramdisk((void *)images->os.start,
470 if (IS_ENABLED(CONFIG_SUPPORT_RAW_INITRD)) {
474 end = strchr(select, ':');
476 rd_len = hextoul(++end, NULL);
481 puts("Wrong Ramdisk Image Format\n");
487 } else if (images->legacy_hdr_valid &&
488 image_check_type(&images->legacy_hdr_os_copy,
491 * Now check if we have a legacy mult-component image,
492 * get second entry data start address and len.
494 bootstage_mark(BOOTSTAGE_ID_RAMDISK);
495 printf("## Loading init Ramdisk from multi component Legacy Image at %08lx ...\n",
496 (ulong)images->legacy_hdr_os);
498 image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len);
503 bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);
509 debug("## No init Ramdisk\n");
512 *rd_end = rd_data + rd_len;
514 debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
521 * boot_ramdisk_high - relocate init ramdisk
522 * @lmb: pointer to lmb handle, will be used for memory mgmt
523 * @rd_data: ramdisk data start address
524 * @rd_len: ramdisk data length
525 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
526 * start address (after possible relocation)
527 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
528 * end address (after possible relocation)
530 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environment
531 * variable and if requested ramdisk data is moved to a specified location.
533 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
534 * start/end addresses if ramdisk image start and len were provided,
535 * otherwise set initrd_start and initrd_end set to zeros.
541 int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
542 ulong *initrd_start, ulong *initrd_end)
546 int initrd_copy_to_ram = 1;
548 s = env_get("initrd_high");
550 /* a value of "no" or a similar string will act like 0,
551 * turning the "load high" feature off. This is intentional.
553 initrd_high = hextoul(s, NULL);
554 if (initrd_high == ~0)
555 initrd_copy_to_ram = 0;
557 initrd_high = env_get_bootm_mapsize() + env_get_bootm_low();
560 debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
561 initrd_high, initrd_copy_to_ram);
564 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
565 debug(" in-place initrd\n");
566 *initrd_start = rd_data;
567 *initrd_end = rd_data + rd_len;
568 lmb_reserve(lmb, rd_data, rd_len);
571 *initrd_start = (ulong)lmb_alloc_base(lmb,
572 rd_len, 0x1000, initrd_high);
574 *initrd_start = (ulong)lmb_alloc(lmb, rd_len,
577 if (*initrd_start == 0) {
578 puts("ramdisk - allocation error\n");
581 bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
583 *initrd_end = *initrd_start + rd_len;
584 printf(" Loading Ramdisk to %08lx, end %08lx ... ",
585 *initrd_start, *initrd_end);
587 memmove_wd((void *)*initrd_start,
588 (void *)rd_data, rd_len, CHUNKSZ);
591 * Ensure the image is flushed to memory to handle
592 * AMP boot scenarios in which we might not be
595 if (IS_ENABLED(CONFIG_MP)) {
596 flush_cache((unsigned long)*initrd_start,
597 ALIGN(rd_len, ARCH_DMA_MINALIGN));
605 debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
606 *initrd_start, *initrd_end);
614 int boot_get_setup(bootm_headers_t *images, u8 arch,
615 ulong *setup_start, ulong *setup_len)
617 if (!CONFIG_IS_ENABLED(FIT))
620 return boot_get_setup_fit(images, arch, setup_start, setup_len);
623 int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
624 u8 arch, const ulong *ld_start, ulong * const ld_len)
626 ulong tmp_img_addr, img_data, img_len;
630 const char *uname, *name;
632 int devnum = 0; /* TODO support multi fpga platforms */
634 if (!IS_ENABLED(CONFIG_FPGA))
637 /* Check to see if the images struct has a FIT configuration */
638 if (!genimg_has_config(images)) {
639 debug("## FIT configuration was not specified\n");
644 * Obtain the os FIT header from the images struct
646 tmp_img_addr = map_to_sysmem(images->fit_hdr_os);
647 buf = map_sysmem(tmp_img_addr, 0);
649 * Check image type. For FIT images get FIT node
650 * and attempt to locate a generic binary.
652 switch (genimg_get_format(buf)) {
653 case IMAGE_FORMAT_FIT:
654 conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
656 uname = fdt_stringlist_get(buf, conf_noffset, FIT_FPGA_PROP, 0,
659 debug("## FPGA image is not specified\n");
662 fit_img_result = fit_image_load(images,
664 (const char **)&uname,
665 &images->fit_uname_cfg,
668 BOOTSTAGE_ID_FPGA_INIT,
669 FIT_LOAD_OPTIONAL_NON_ZERO,
670 &img_data, &img_len);
672 debug("FPGA image (%s) loaded to 0x%lx/size 0x%lx\n",
673 uname, img_data, img_len);
675 if (fit_img_result < 0) {
676 /* Something went wrong! */
677 return fit_img_result;
680 if (!fpga_is_partial_data(devnum, img_len)) {
682 err = fpga_loadbitstream(devnum, (char *)img_data,
685 err = fpga_load(devnum, (const void *)img_data,
689 err = fpga_loadbitstream(devnum, (char *)img_data,
690 img_len, BIT_PARTIAL);
692 err = fpga_load(devnum, (const void *)img_data,
693 img_len, BIT_PARTIAL);
699 printf(" Programming %s bitstream... OK\n", name);
702 printf("The given image format is not supported (corrupt?)\n");
709 static void fit_loadable_process(u8 img_type,
714 const unsigned int count =
715 ll_entry_count(struct fit_loadable_tbl, fit_loadable);
716 struct fit_loadable_tbl *fit_loadable_handler =
717 ll_entry_start(struct fit_loadable_tbl, fit_loadable);
718 /* For each loadable handler */
719 for (i = 0; i < count; i++, fit_loadable_handler++)
720 /* matching this type */
721 if (fit_loadable_handler->type == img_type)
722 /* call that handler with this image data */
723 fit_loadable_handler->handler(img_data, img_len);
726 int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
727 u8 arch, const ulong *ld_start, ulong * const ld_len)
730 * These variables are used to hold the current image location
735 * These two variables are requirements for fit_image_load, but
736 * their values are not used
738 ulong img_data, img_len;
746 /* Check to see if the images struct has a FIT configuration */
747 if (!genimg_has_config(images)) {
748 debug("## FIT configuration was not specified\n");
753 * Obtain the os FIT header from the images struct
755 tmp_img_addr = map_to_sysmem(images->fit_hdr_os);
756 buf = map_sysmem(tmp_img_addr, 0);
758 * Check image type. For FIT images get FIT node
759 * and attempt to locate a generic binary.
761 switch (genimg_get_format(buf)) {
762 case IMAGE_FORMAT_FIT:
763 conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
765 for (loadables_index = 0;
766 uname = fdt_stringlist_get(buf, conf_noffset,
768 loadables_index, NULL), uname;
770 fit_img_result = fit_image_load(images, tmp_img_addr,
772 &images->fit_uname_cfg,
773 arch, IH_TYPE_LOADABLE,
774 BOOTSTAGE_ID_FIT_LOADABLE_START,
775 FIT_LOAD_OPTIONAL_NON_ZERO,
776 &img_data, &img_len);
777 if (fit_img_result < 0) {
778 /* Something went wrong! */
779 return fit_img_result;
782 fit_img_result = fit_image_get_node(buf, uname);
783 if (fit_img_result < 0) {
784 /* Something went wrong! */
785 return fit_img_result;
787 fit_img_result = fit_image_get_type(buf,
790 if (fit_img_result < 0) {
791 /* Something went wrong! */
792 return fit_img_result;
795 fit_loadable_process(img_type, img_data, img_len);
799 printf("The given image format is not supported (corrupt?)\n");
807 * boot_get_cmdline - allocate and initialize kernel cmdline
808 * @lmb: pointer to lmb handle, will be used for memory mgmt
809 * @cmd_start: pointer to a ulong variable, will hold cmdline start
810 * @cmd_end: pointer to a ulong variable, will hold cmdline end
812 * boot_get_cmdline() allocates space for kernel command line below
813 * BOOTMAPSZ + env_get_bootm_low() address. If "bootargs" U-Boot environment
814 * variable is present its contents is copied to allocated kernel
821 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
826 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
827 env_get_bootm_mapsize() + env_get_bootm_low());
831 s = env_get("bootargs");
837 *cmd_start = (ulong)cmdline;
838 *cmd_end = *cmd_start + strlen(cmdline);
840 debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
846 * boot_get_kbd - allocate and initialize kernel copy of board info
847 * @lmb: pointer to lmb handle, will be used for memory mgmt
848 * @kbd: double pointer to board info data
850 * boot_get_kbd() allocates space for kernel copy of board info data below
851 * BOOTMAPSZ + env_get_bootm_low() address and kernel board info is initialized
852 * with the current u-boot board info data.
858 int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
860 *kbd = (struct bd_info *)(ulong)lmb_alloc_base(lmb,
861 sizeof(struct bd_info),
863 env_get_bootm_mapsize() +
864 env_get_bootm_low());
870 debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
873 if (IS_ENABLED(CONFIG_CMD_BDI)
874 do_bdinfo(NULL, 0, 0, NULL);
880 int image_setup_linux(bootm_headers_t *images)
882 ulong of_size = images->ft_len;
883 char **of_flat_tree = &images->ft_addr;
884 struct lmb *lmb = &images->lmb;
887 if (CONFIG_IS_ENABLED(OF_LIBFDT))
888 boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
890 if (IS_ENABLED(CONFIG_SYS_BOOT_GET_CMDLINE)) {
891 ret = boot_get_cmdline(lmb, &images->cmdline_start,
892 &images->cmdline_end);
894 puts("ERROR with allocation of cmdline\n");
899 if (CONFIG_IS_ENABLED(OF_LIBFDT)) {
900 ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
905 if (CONFIG_IS_ENABLED(OF_LIBFDT) && of_size) {
906 ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb);
914 void genimg_print_size(uint32_t size)
916 printf("%d Bytes = ", size);
917 print_size(size, "\n");
920 void genimg_print_time(time_t timestamp)
924 rtc_to_tm(timestamp, &tm);
925 printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
926 tm.tm_year, tm.tm_mon, tm.tm_mday,
927 tm.tm_hour, tm.tm_min, tm.tm_sec);