Newer
Older
int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
ulong *initrd_start, ulong *initrd_end)
{
char *s;
ulong initrd_high;
int initrd_copy_to_ram = 1;
if ((s = getenv ("initrd_high")) != NULL) {
/* a value of "no" or a similar string will act like 0,
* turning the "load high" feature off. This is intentional.
*/
initrd_high = simple_strtoul (s, NULL, 16);
if (initrd_high == ~0)
initrd_copy_to_ram = 0;
} else {
/* not set, no restrictions to load high */
initrd_high = ~0;
}
#ifdef CONFIG_LOGBUFFER
/* Prevent initrd from overwriting logbuffer */
lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
#endif
debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
initrd_high, initrd_copy_to_ram);
if (rd_data) {
if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
debug (" in-place initrd\n");
*initrd_start = rd_data;
*initrd_end = rd_data + rd_len;
lmb_reserve(lmb, rd_data, rd_len);
*initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
*initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
puts ("ramdisk - allocation error\n");
}
show_boot_progress (12);
*initrd_end = *initrd_start + rd_len;
printf (" Loading Ramdisk to %08lx, end %08lx ... ",
*initrd_start, *initrd_end);
memmove_wd ((void *)*initrd_start,
(void *)rd_data, rd_len, CHUNKSZ);
puts ("OK\n");
}
} else {
*initrd_start = 0;
*initrd_end = 0;
}
debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
*initrd_start, *initrd_end);
}
/**
* boot_get_cmdline - allocate and initialize kernel cmdline
* @lmb: pointer to lmb handle, will be used for memory mgmt
* @cmd_start: pointer to a ulong variable, will hold cmdline start
* @cmd_end: pointer to a ulong variable, will hold cmdline end
* @bootmap_base: ulong variable, holds offset in physical memory to
* base of bootmap
* boot_get_cmdline() allocates space for kernel command line below
* BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
* variable is present its contents is copied to allocated kernel
* command line.
*
* returns:
* 0 - success
* -1 - failure
int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
{
char *cmdline;
char *s;
cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
CFG_BOOTMAPSZ + bootmap_base);
if (cmdline == NULL)
return -1;
if ((s = getenv("bootargs")) == NULL)
s = "";
strcpy(cmdline, s);
*cmd_start = (ulong) & cmdline[0];
*cmd_end = *cmd_start + strlen(cmdline);
debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
}
/**
* boot_get_kbd - allocate and initialize kernel copy of board info
* @lmb: pointer to lmb handle, will be used for memory mgmt
* @kbd: double pointer to board info data
* @bootmap_base: ulong variable, holds offset in physical memory to
* base of bootmap
* boot_get_kbd() allocates space for kernel copy of board info data below
* BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
* the current u-boot board info data.
*
* returns:
* 0 - success
* -1 - failure
int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
*kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
CFG_BOOTMAPSZ + bootmap_base);
if (*kbd == NULL)
return -1;
**kbd = *(gd->bd);
debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
#if defined(DEBUG) && defined(CONFIG_CMD_BDI)
do_bdinfo(NULL, 0, 0, NULL);
#endif
}
#endif /* CONFIG_PPC || CONFIG_M68K */
#if defined(CONFIG_FIT)
/*****************************************************************************/
/* New uImage format routines */
/*****************************************************************************/
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
ulong *addr, const char **name)
{
const char *sep;
*addr = addr_curr;
*name = NULL;
sep = strchr (spec, sepc);
if (sep) {
if (sep - spec > 0)
*addr = simple_strtoul (spec, NULL, 16);
*name = sep + 1;
return 1;
}
return 0;
}
/**
* fit_parse_conf - parse FIT configuration spec
* @spec: input string, containing configuration spec
* @add_curr: current image address (to be used as a possible default)
* @addr: pointer to a ulong variable, will hold FIT image address of a given
* configuration
* @conf_name double pointer to a char, will hold pointer to a configuration
* unit name
*
* fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
* where <addr> is a FIT image address that contains configuration
* with a <conf> unit name.
*
* Address part is optional, and if omitted default add_curr will
* be used instead.
*
* returns:
* 1 if spec is a valid configuration string,
* addr and conf_name are set accordingly
* 0 otherwise
*/
inline int fit_parse_conf (const char *spec, ulong addr_curr,
ulong *addr, const char **conf_name)
{
return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
}
/**
* fit_parse_subimage - parse FIT subimage spec
* @spec: input string, containing subimage spec
* @add_curr: current image address (to be used as a possible default)
* @addr: pointer to a ulong variable, will hold FIT image address of a given
* subimage
* @image_name: double pointer to a char, will hold pointer to a subimage name
*
* fit_parse_subimage() expects subimage spec in the for of
* [<addr>]:<subimage>, where <addr> is a FIT image address that contains
* subimage with a <subimg> unit name.
*
* Address part is optional, and if omitted default add_curr will
* be used instead.
*
* returns:
* 1 if spec is a valid subimage string,
* addr and image_name are set accordingly
* 0 otherwise
*/
inline int fit_parse_subimage (const char *spec, ulong addr_curr,
ulong *addr, const char **image_name)
{
return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
}
#endif /* !USE_HOSTCC */
static void fit_get_debug (const void *fit, int noffset,
char *prop_name, int err)
{
debug ("Can't get '%s' property from FIT 0x%08lx, "
"node: offset %d, name %s (%s)\n",
prop_name, (ulong)fit, noffset,
fit_get_name (fit, noffset, NULL),
fdt_strerror (err));
}
/**
* fit_print_contents - prints out the contents of the FIT format image
* @fit: pointer to the FIT format image header
* @p: pointer to prefix string
*
* fit_print_contents() formats a multi line FIT image contents description.
* The routine prints out FIT image properties (root node level) follwed by
* the details of each component image.
*
* returns:
* no returned results
*/
void fit_print_contents (const void *fit)
{
char *desc;
char *uname;
int images_noffset;
int confs_noffset;
int noffset;
int ndepth;
int count = 0;
int ret;
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
time_t timestamp;
#endif
#ifdef USE_HOSTCC
p = "";
#else
p = " ";
#endif
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
/* Root node properties */
ret = fit_get_desc (fit, 0, &desc);
printf ("%sFIT description: ", p);
if (ret)
printf ("unavailable\n");
else
printf ("%s\n", desc);
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
ret = fit_get_timestamp (fit, 0, ×tamp);
printf ("%sCreated: ", p);
if (ret)
printf ("unavailable\n");
else
genimg_print_time (timestamp);
#endif
/* Find images parent node offset */
images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {
printf ("Can't find images parent node '%s' (%s)\n",
FIT_IMAGES_PATH, fdt_strerror (images_noffset));
return;
}
/* Process its subnodes, print out component images details */
for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node (fit, noffset, &ndepth)) {
if (ndepth == 1) {
/*
* Direct child node of the images parent node,
* i.e. component image node.
*/
printf ("%s Image %u (%s)\n", p, count++,
fit_get_name(fit, noffset, NULL));
fit_image_print (fit, noffset, p);
}
}
/* Find configurations parent node offset */
confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
if (confs_noffset < 0) {
debug ("Can't get configurations parent node '%s' (%s)\n",
FIT_CONFS_PATH, fdt_strerror (confs_noffset));
return;
}
/* get default configuration unit name from default property */
uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
if (uname)
printf ("%s Default Configuration: '%s'\n", p, uname);
/* Process its subnodes, print out configurations details */
for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node (fit, noffset, &ndepth)) {
if (ndepth == 1) {
/*
* Direct child node of the configurations parent node,
* i.e. configuration node.
*/
printf ("%s Configuration %u (%s)\n", p, count++,
fit_get_name(fit, noffset, NULL));
fit_conf_print (fit, noffset, p);
}
}
}
/**
* fit_image_print - prints out the FIT component image details
* @fit: pointer to the FIT format image header
* @image_noffset: offset of the component image node
* @p: pointer to prefix string
*
* fit_image_print() lists all mandatory properies for the processed component
* image. If present, hash nodes are printed out as well.
*
* returns:
* no returned results
*/
void fit_image_print (const void *fit, int image_noffset, const char *p)
{
char *desc;
uint8_t type, arch, os, comp;
size_t size;
ulong load, entry;
const void *data;
int noffset;
int ndepth;
int ret;
/* Mandatory properties */
ret = fit_get_desc (fit, image_noffset, &desc);
printf ("%s Description: ", p);
if (ret)
printf ("unavailable\n");
else
printf ("%s\n", desc);
fit_image_get_type (fit, image_noffset, &type);
printf ("%s Type: %s\n", p, genimg_get_type_name (type));
fit_image_get_comp (fit, image_noffset, &comp);
printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
ret = fit_image_get_data (fit, image_noffset, &data, &size);
#ifndef USE_HOSTCC
printf ("%s Data Start: ", p);
if (ret)
printf ("unavailable\n");
else
printf ("0x%08lx\n", (ulong)data);
#endif
printf ("%s Data Size: ", p);
if (ret)
printf ("unavailable\n");
else
genimg_print_size (size);
/* Remaining, type dependent properties */
if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
(type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
(type == IH_TYPE_FLATDT)) {
fit_image_get_arch (fit, image_noffset, &arch);
printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
}
if (type == IH_TYPE_KERNEL) {
fit_image_get_os (fit, image_noffset, &os);
printf ("%s OS: %s\n", p, genimg_get_os_name (os));
}
if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
ret = fit_image_get_load (fit, image_noffset, &load);
printf ("%s Load Address: ", p);
if (ret)
printf ("unavailable\n");
else
printf ("0x%08lx\n", load);
fit_image_get_entry (fit, image_noffset, &entry);
printf ("%s Entry Point: ", p);
if (ret)
printf ("unavailable\n");
else
printf ("0x%08lx\n", entry);
}
/* Process all hash subnodes of the component image node */
for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node (fit, noffset, &ndepth)) {
if (ndepth == 1) {
/* Direct child node of the component image node */
fit_image_print_hash (fit, noffset, p);
}
}
}
/**
* fit_image_print_hash - prints out the hash node details
* @fit: pointer to the FIT format image header
* @noffset: offset of the hash node
* @p: pointer to prefix string
*
* fit_image_print_hash() lists properies for the processed hash node
*
* returns:
* no returned results
*/
void fit_image_print_hash (const void *fit, int noffset, const char *p)
{
char *algo;
uint8_t *value;
int value_len;
int i, ret;
/*
* Check subnode name, must be equal to "hash".
* Multiple hash nodes require unique unit node
* names, e.g. hash@1, hash@2, etc.
*/
if (strncmp (fit_get_name(fit, noffset, NULL),
FIT_HASH_NODENAME,
strlen(FIT_HASH_NODENAME)) != 0)
return;
debug ("%s Hash node: '%s'\n", p,
fit_get_name (fit, noffset, NULL));
printf ("%s Hash algo: ", p);
if (fit_image_hash_get_algo (fit, noffset, &algo)) {
printf ("invalid/unsupported\n");
return;
}
printf ("%s\n", algo);
ret = fit_image_hash_get_value (fit, noffset, &value,
&value_len);
printf ("%s Hash value: ", p);
if (ret) {
printf ("unavailable\n");
} else {
for (i = 0; i < value_len; i++)
printf ("%02x", value[i]);
printf ("\n");
}
debug ("%s Hash len: %d\n", p, value_len);
}
/**
* fit_get_desc - get node description property
* @fit: pointer to the FIT format image header
* @noffset: node offset
* @desc: double pointer to the char, will hold pointer to the descrption
*
* fit_get_desc() reads description property from a given node, if
* description is found pointer to it is returened in third call argument.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_get_desc (const void *fit, int noffset, char **desc)
{
int len;
*desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
if (*desc == NULL) {
fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
return -1;
}
return 0;
}
/**
* fit_get_timestamp - get node timestamp property
* @fit: pointer to the FIT format image header
* @noffset: node offset
* @timestamp: pointer to the time_t, will hold read timestamp
*
* fit_get_timestamp() reads timestamp poperty from given node, if timestamp
* is found and has a correct size its value is retured in third call
* argument.
*
* returns:
* 0, on success
* -1, on property read failure
* -2, on wrong timestamp size
*/
int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
{
int len;
const void *data;
data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
return -1;
}
if (len != sizeof (uint32_t)) {
debug ("FIT timestamp with incorrect size of (%u)\n", len);
return -2;
}
*timestamp = uimage_to_cpu (*((uint32_t *)data));
return 0;
}
/**
* fit_image_get_node - get node offset for component image of a given unit name
* @fit: pointer to the FIT format image header
* @image_uname: component image node unit name
*
* fit_image_get_node() finds a component image (withing the '/images'
* node) of a provided unit name. If image is found its node offset is
* returned to the caller.
*
* returns:
* image node offset when found (>=0)
* negative number on failure (FDT_ERR_* code)
*/
int fit_image_get_node (const void *fit, const char *image_uname)
{
int noffset, images_noffset;
images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {
debug ("Can't find images parent node '%s' (%s)\n",
FIT_IMAGES_PATH, fdt_strerror (images_noffset));
return images_noffset;
}
noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
if (noffset < 0) {
debug ("Can't get node offset for image unit name: '%s' (%s)\n",
image_uname, fdt_strerror (noffset));
}
return noffset;
}
/**
* fit_image_get_os - get os id for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @os: pointer to the uint8_t, will hold os numeric id
*
* fit_image_get_os() finds os property in a given component image node.
* If the property is found, its (string) value is translated to the numeric
* id which is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
{
int len;
const void *data;
/* Get OS name from property data */
data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_OS_PROP, len);
*os = -1;
return -1;
}
/* Translate OS name to id */
*os = genimg_get_os_id (data);
return 0;
}
/**
* fit_image_get_arch - get arch id for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @arch: pointer to the uint8_t, will hold arch numeric id
*
* fit_image_get_arch() finds arch property in a given component image node.
* If the property is found, its (string) value is translated to the numeric
* id which is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
{
int len;
const void *data;
/* Get architecture name from property data */
data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
*arch = -1;
return -1;
}
/* Translate architecture name to id */
*arch = genimg_get_arch_id (data);
return 0;
}
/**
* fit_image_get_type - get type id for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @type: pointer to the uint8_t, will hold type numeric id
*
* fit_image_get_type() finds type property in a given component image node.
* If the property is found, its (string) value is translated to the numeric
* id which is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
{
int len;
const void *data;
/* Get image type name from property data */
data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
*type = -1;
return -1;
}
/* Translate image type name to id */
*type = genimg_get_type_id (data);
return 0;
}
/**
* fit_image_get_comp - get comp id for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @comp: pointer to the uint8_t, will hold comp numeric id
*
* fit_image_get_comp() finds comp property in a given component image node.
* If the property is found, its (string) value is translated to the numeric
* id which is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
{
int len;
const void *data;
/* Get compression name from property data */
data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
*comp = -1;
return -1;
}
/* Translate compression name to id */
*comp = genimg_get_comp_id (data);
return 0;
}
/**
* fit_image_get_load - get load address property for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @load: pointer to the uint32_t, will hold load address
*
* fit_image_get_load() finds load address property in a given component image node.
* If the property is found, its value is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_load (const void *fit, int noffset, ulong *load)
{
int len;
const uint32_t *data;
data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
return -1;
}
*load = uimage_to_cpu (*data);
return 0;
}
/**
* fit_image_get_entry - get entry point address property for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @entry: pointer to the uint32_t, will hold entry point address
*
* fit_image_get_entry() finds entry point address property in a given component image node.
* If the property is found, its value is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
{
int len;
const uint32_t *data;
data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
if (data == NULL) {
fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
return -1;
}
*entry = uimage_to_cpu (*data);
return 0;
}
/**
* fit_image_get_data - get data property and its size for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @data: double pointer to void, will hold data property's data address
* @size: pointer to size_t, will hold data property's data size
*
* fit_image_get_data() finds data property in a given component image node.
* If the property is found its data start address and size are returned to
* the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_get_data (const void *fit, int noffset,
const void **data, size_t *size)
{
int len;
*data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
if (*data == NULL) {
fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
*size = 0;
return -1;
}
*size = len;
return 0;
}
/**
* fit_image_hash_get_algo - get hash algorithm name
* @fit: pointer to the FIT format image header
* @noffset: hash node offset
* @algo: double pointer to char, will hold pointer to the algorithm name
*
* fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
* If the property is found its data start address is returned to the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
{
int len;
*algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
if (*algo == NULL) {
fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
return -1;
}
return 0;
}
/**
* fit_image_hash_get_value - get hash value and length
* @fit: pointer to the FIT format image header
* @noffset: hash node offset
* @value: double pointer to uint8_t, will hold address of a hash value data
* @value_len: pointer to an int, will hold hash data length
*
* fit_image_hash_get_value() finds hash value property in a given hash node.
* If the property is found its data start address and size are returned to
* the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
int *value_len)
{
int len;
*value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
if (*value == NULL) {
fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
*value_len = 0;
return -1;
}
*value_len = len;
return 0;
}
/**
* fit_set_timestamp - set node timestamp property
* @fit: pointer to the FIT format image header
* @noffset: node offset
* @timestamp: timestamp value to be set
*
* fit_set_timestamp() attempts to set timestamp property in the requested
* node and returns operation status to the caller.
*
* returns:
* 0, on success
* -1, on property read failure
*/
int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
{
uint32_t t;
int ret;
t = cpu_to_uimage (timestamp);
ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
sizeof (uint32_t));
if (ret) {
printf ("Can't set '%s' property for '%s' node (%s)\n",
FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
fdt_strerror (ret));
return -1;
}
return 0;
}
/**
* calculate_hash - calculate and return hash for provided input data
* @data: pointer to the input data
* @data_len: data length
* @algo: requested hash algorithm
* @value: pointer to the char, will hold hash value data (caller must
* allocate enough free space)
* value_len: length of the calculated hash
*
* calculate_hash() computes input data hash according to the requested algorithm.
* Resulting hash value is placed in caller provided 'value' buffer, length
* of the calculated hash is returned via value_len pointer argument.
*
* returns:
* 0, on success
* -1, when algo is unsupported
*/
static int calculate_hash (const void *data, int data_len, const char *algo,
uint8_t *value, int *value_len)
{
if (strcmp (algo, "crc32") == 0 ) {
Bartlomiej Sieka
committed
*((uint32_t *)value) = crc32_wd (0, data, data_len,
CHUNKSZ_CRC32);
*((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
*value_len = 4;
} else if (strcmp (algo, "sha1") == 0 ) {
Bartlomiej Sieka
committed
sha1_csum_wd ((unsigned char *) data, data_len,
(unsigned char *) value, CHUNKSZ_SHA1);
*value_len = 20;
} else if (strcmp (algo, "md5") == 0 ) {
Bartlomiej Sieka
committed
md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
} else {
debug ("Unsupported hash alogrithm\n");
return -1;
}
return 0;
}
#ifdef USE_HOSTCC
/**
* fit_set_hashes - process FIT component image nodes and calculate hashes
* @fit: pointer to the FIT format image header
*
* fit_set_hashes() adds hash values for all component images in the FIT blob.
* Hashes are calculated for all component images which have hash subnodes
* with algorithm property set to one of the supported hash algorithms.
*
* returns
* 0, on success
* libfdt error code, on failure
*/
int fit_set_hashes (void *fit)
{
int images_noffset;
int noffset;
int ndepth;
int ret;
/* Find images parent node offset */
images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {
printf ("Can't find images parent node '%s' (%s)\n",
FIT_IMAGES_PATH, fdt_strerror (images_noffset));
return images_noffset;
}
/* Process its subnodes, print out component images details */
for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node (fit, noffset, &ndepth)) {
if (ndepth == 1) {
/*
* Direct child node of the images parent node,
* i.e. component image node.
*/
ret = fit_image_set_hashes (fit, noffset);
if (ret)
return ret;
}
}
return 0;
}
/**
* fit_image_set_hashes - calculate/set hashes for given component image node
* @fit: pointer to the FIT format image header
* @image_noffset: requested component image node
*
* fit_image_set_hashes() adds hash values for an component image node. All
* existing hash subnodes are checked, if algorithm property is set to one of
* the supported hash algorithms, hash value is computed and corresponding
* hash node property is set, for example:
*
* Input component image node structure:
*
* o image@1 (at image_noffset)
* | - data = [binary data]
* o hash@1
* |- algo = "sha1"
*
* Output component image node structure:
*
* o image@1 (at image_noffset)
* | - data = [binary data]
* o hash@1
* |- algo = "sha1"
* |- value = sha1(data)
*
* returns:
* 0 on sucess
* <0 on failure
*/
int fit_image_set_hashes (void *fit, int image_noffset)
{
const void *data;
size_t size;
char *algo;
uint8_t value[FIT_MAX_HASH_LEN];
int value_len;